diff --git a/CMakeLists.txt b/CMakeLists.txt index ec000976a48..3c31c609aab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,6 +99,16 @@ if (USE_TIME_TRACE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftime-trace") endif() +option(USE_ASAN "Use -fsanitize=asan when compiling (requires Clang)" OFF) +if (USE_ASAN) + add_compile_options( + -g + -fsanitize=address + -fno-omit-frame-pointer) + add_link_options( + -fsanitize=address) +endif() + include(CheckSymbolExists) check_symbol_exists(feclearexcept "fenv.h" HAS_FECLEAREXCEPT) check_symbol_exists(feenableexcept "fenv.h" HAS_FEENABLEEXCEPT) diff --git a/data/meta/Input.lua b/data/meta/Input.lua index 73896a6e9ab..e0ab033fe32 100644 --- a/data/meta/Input.lua +++ b/data/meta/Input.lua @@ -17,6 +17,15 @@ Input.keys = {} --================================== +---@alias Input.KeyBinding { key: integer } | { mouse: integer } | { joystick: integer, button: integer } | { joystick: integer, hat: integer, dir: integer } + +---@class Input.KeyChord +---@field activator Input.KeyBinding +---@field modifier1 Input.KeyBinding? +---@field modifier2 Input.KeyBinding? + +--================================== + ---@class Input.ActionBinding ---@field id string ---@field type string @@ -184,16 +193,16 @@ function Input.CreateInputFrame(id, modal) end -- Register an ActionBinding from Lua with the given default key associations ---@param id string The identifier of the action binding. Must be globally unique. ---@param groupId string The page and group this action binding is organized into, in the form "page.group" ----@param b1 table? The primary keychord for this binding ----@param b2 table? The secondary keychord for this binding +---@param b1 Input.KeyChord? The primary keychord for this binding +---@param b2 Input.KeyChord? The secondary keychord for this binding ---@return Input.ActionBinding function Input.RegisterActionBinding(id, groupId, b1, b2) end -- Register an AxisBinding from Lua with the given default key associations ---@param id string The identifier of the axis binding. Must be globally unique. ---@param groupId string The page and group this axis binding is organized into, in the form "page.group" ----@param pos table? The positive-direction keychord for this axis binding ----@param neg table? The negative-direction keychord for this axis binding +---@param pos Input.KeyChord? The positive-direction keychord for this axis binding +---@param neg Input.KeyChord? The negative-direction keychord for this axis binding ---@param axis table? The joystick axis to associate with this axis binding ---@return Input.AxisBinding function Input.RegisterAxisBinding(id, groupId, pos, neg, axis) end diff --git a/src/Beam.cpp b/src/Beam.cpp index c9577cb1872..3ab956376b8 100644 --- a/src/Beam.cpp +++ b/src/Beam.cpp @@ -26,6 +26,8 @@ #include "lua/LuaEvent.h" #include "lua/LuaUtils.h" +#include "profiler/Profiler.h" + namespace { static float lifetime = 0.1f; } diff --git a/src/Body.cpp b/src/Body.cpp index ab9a0d341ac..4de1bf98e30 100644 --- a/src/Body.cpp +++ b/src/Body.cpp @@ -20,6 +20,8 @@ #include "core/Log.h" #include "lua/LuaEvent.h" +#include "profiler/Profiler.h" + Body::Body() : PropertiedObject(), m_interpPos(0.0), diff --git a/src/Camera.cpp b/src/Camera.cpp index dcbe5e1c4ff..10242ee5fcd 100644 --- a/src/Camera.cpp +++ b/src/Camera.cpp @@ -11,11 +11,14 @@ #include "Player.h" #include "Sfx.h" #include "Space.h" +#include "SpaceStation.h" + #include "galaxy/StarSystem.h" #include "graphics/TextureBuilder.h" #include "graphics/Types.h" #include "graphics/RenderState.h" -#include "SpaceStation.h" + +#include "profiler/Profiler.h" using namespace Graphics; diff --git a/src/DeathView.cpp b/src/DeathView.cpp index 1f3add4f174..602bb93aaef 100644 --- a/src/DeathView.cpp +++ b/src/DeathView.cpp @@ -11,6 +11,8 @@ #include "graphics/Graphics.h" #include "graphics/Renderer.h" +#include "profiler/Profiler.h" + DeathView::DeathView(Game *game) : View(), m_game(game) diff --git a/src/HudTrail.cpp b/src/HudTrail.cpp index 3b0e78594a0..cdf5d1dd14c 100644 --- a/src/HudTrail.cpp +++ b/src/HudTrail.cpp @@ -11,6 +11,8 @@ #include "graphics/Renderer.h" #include "graphics/Types.h" +#include "profiler/Profiler.h" + const float UPDATE_INTERVAL = 0.1f; const Uint16 MAX_POINTS = 100; diff --git a/src/Projectile.cpp b/src/Projectile.cpp index fb5c5aeb1f4..a9790129d99 100644 --- a/src/Projectile.cpp +++ b/src/Projectile.cpp @@ -26,6 +26,8 @@ #include "lua/LuaEvent.h" #include "lua/LuaUtils.h" +#include "profiler/Profiler.h" + std::unique_ptr Projectile::s_sideMesh; std::unique_ptr Projectile::s_glowMesh; std::unique_ptr Projectile::s_sideMat; diff --git a/src/SectorView.cpp b/src/SectorView.cpp index 74c21860303..3ed524e1610 100644 --- a/src/SectorView.cpp +++ b/src/SectorView.cpp @@ -24,10 +24,11 @@ #include "lua/LuaRef.h" #include "lua/LuaTable.h" #include "matrix4x4.h" -#include -#include -#include +#include "profiler/Profiler.h" + +#include +#include #include SectorView::~SectorView() {} diff --git a/src/Sensors.cpp b/src/Sensors.cpp index f23d9647a84..8db2cc61f97 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -10,6 +10,8 @@ #include "Ship.h" #include "Space.h" +#include "profiler/Profiler.h" + Sensors::RadarContact::RadarContact() : body(0), trail(0), @@ -62,7 +64,7 @@ Body* Sensors::ChooseTarget(TargetingCriteria crit, const Body* oldTarget ) if(!m_owner->IsType(ObjectType::PLAYER)) return nullptr; - + const Body* currTarget = oldTarget; m_radarContacts.sort(ContactDistanceSort); diff --git a/src/Sfx.cpp b/src/Sfx.cpp index b90d05620c2..9a8abc2ca6f 100644 --- a/src/Sfx.cpp +++ b/src/Sfx.cpp @@ -11,7 +11,8 @@ #include "JsonUtils.h" #include "ModelBody.h" #include "Pi.h" -#include "StringF.h" +#include "matrix4x4.h" + #include "core/IniConfig.h" #include "graphics/Drawables.h" #include "graphics/Graphics.h" @@ -21,7 +22,8 @@ #include "graphics/TextureBuilder.h" #include "graphics/Types.h" #include "graphics/VertexArray.h" -#include "matrix4x4.h" + +#include "profiler/Profiler.h" using namespace Graphics; diff --git a/src/Shields.cpp b/src/Shields.cpp index 52d8f1fbe56..1ad64b50e37 100644 --- a/src/Shields.cpp +++ b/src/Shields.cpp @@ -15,6 +15,8 @@ #include "scenegraph/StaticGeometry.h" #include "scenegraph/Node.h" +#include "profiler/Profiler.h" + #include REGISTER_COMPONENT_TYPE(Shields) { diff --git a/src/Ship-AI.cpp b/src/Ship-AI.cpp index 8e26766629c..cdc8838a07b 100644 --- a/src/Ship-AI.cpp +++ b/src/Ship-AI.cpp @@ -3,17 +3,13 @@ #include "EnumStrings.h" #include "Frame.h" -#include "Pi.h" -#include "Planet.h" -#include "Player.h" #include "Ship.h" #include "ShipAICmd.h" #include "Space.h" #include "SpaceStation.h" -#include "lua/LuaConstants.h" #include "lua/LuaEvent.h" -#include "perlin.h" -#include "ship/Propulsion.h" + +#include "profiler/Profiler.h" // returns true if command is complete bool Ship::AITimeStep(float timeStep) @@ -24,7 +20,7 @@ bool Ship::AITimeStep(float timeStep) m_decelerating = false; if (!m_curAICmd) { - if (this == Pi::player) return true; + if (this->IsType(ObjectType::PLAYER)) return true; // just in case the AI left it on ClearThrusterState(); diff --git a/src/Space.cpp b/src/Space.cpp index d26a8bf87da..90b67b40d0f 100644 --- a/src/Space.cpp +++ b/src/Space.cpp @@ -22,11 +22,12 @@ #include "collider/CollisionSpace.h" #include "core/Log.h" #include "galaxy/Galaxy.h" -#include "graphics/Graphics.h" #include "lua/LuaEvent.h" #include "lua/LuaTimer.h" + +#include "profiler/Profiler.h" + #include -#include //#define DEBUG_CACHE diff --git a/src/SpeedLines.cpp b/src/SpeedLines.cpp index a4bbeb38ff6..0633419b259 100644 --- a/src/SpeedLines.cpp +++ b/src/SpeedLines.cpp @@ -10,6 +10,7 @@ #include "core/IniConfig.h" #include "graphics/RenderState.h" #include "graphics/Renderer.h" +#include "profiler/Profiler.h" // default values float SpeedLines::BOUNDS = 2000.f; diff --git a/src/SystemView.cpp b/src/SystemView.cpp index c2b37140522..aa423dccec2 100644 --- a/src/SystemView.cpp +++ b/src/SystemView.cpp @@ -29,6 +29,7 @@ #include "graphics/Types.h" #include "imgui/imgui.h" +#include "profiler/Profiler.h" #include "SDL_keycode.h" using namespace Graphics; diff --git a/src/core/Property.cpp b/src/core/Property.cpp index aadcb2568e2..37a18a2998d 100644 --- a/src/core/Property.cpp +++ b/src/core/Property.cpp @@ -5,6 +5,7 @@ #include "Json.h" #include "JsonUtils.h" +#include "StringHash.h" PropertyMapWrapper::PropertyMapWrapper(PropertyMap *m) : m_map(m) diff --git a/src/core/Property.h b/src/core/Property.h index 7cff3e71a87..68372709fa0 100644 --- a/src/core/Property.h +++ b/src/core/Property.h @@ -11,6 +11,8 @@ #include "vector2.h" #include "vector3.h" +#include "FNV1a.h" + #include #include #include diff --git a/src/core/StringName.cpp b/src/core/StringName.cpp index a269e5715b4..16c9ae2524e 100644 --- a/src/core/StringName.cpp +++ b/src/core/StringName.cpp @@ -3,6 +3,9 @@ #include "core/StringName.h" +#include "FNV1a.h" +#include "profiler/Profiler.h" + #include #include #include @@ -68,6 +71,15 @@ StringName::StringData *StringName::make_data(const char *c, uint32_t s, uint32_ // ============================================================================= +StringTable::StringTable(uint32_t size) : + keys(size), + dist(size), + values(size), + entries(0) +{ + m_lastReclaim = Profiler::Clock::getticks(); +} + StringTable::Data *StringTable::Find(uint32_t key) { if (!key) @@ -160,11 +172,13 @@ void StringTable::Erase(uint32_t key) void StringTable::Reclaim(bool force) { - m_reclaimClock.SoftStop(); - if (m_reclaimClock.seconds() < 15.0 && !force) + uint64_t ticks = Profiler::Clock::getticks(); + double seconds = Profiler::Clock::ms(ticks - m_lastReclaim) * 1000.0; + + if (seconds < 15.0 && !force) return; - m_reclaimClock.SoftReset(); + m_lastReclaim = ticks; for (uint32_t idx = 0; idx < keys.size(); idx++) { uint32_t probed_key = keys[idx]; diff --git a/src/core/StringName.h b/src/core/StringName.h index 2a935b3c8af..95fbe7fba46 100644 --- a/src/core/StringName.h +++ b/src/core/StringName.h @@ -3,12 +3,8 @@ #pragma once -#include "StringHash.h" -#include "profiler/Profiler.h" - #include #include -#include #include /* @@ -88,11 +84,7 @@ class StringTable { public: using Data = StringName::StringData *; - StringTable(uint32_t size) : - keys(size), - dist(size), - values(size), - entries(0) {} + StringTable(uint32_t size); static StringTable *Get(); @@ -123,7 +115,7 @@ class StringTable { std::vector dist; std::vector values; uint32_t entries; - Profiler::Clock m_reclaimClock; + uint64_t m_lastReclaim; }; inline StringName operator""_name(const char *c, size_t l) { return StringName(std::string_view(c, l)); } diff --git a/src/editor/UndoSystem.cpp b/src/editor/UndoSystem.cpp index 517c09c31c6..12c0ee8f123 100644 --- a/src/editor/UndoSystem.cpp +++ b/src/editor/UndoSystem.cpp @@ -2,6 +2,7 @@ // Licensed under the terms of the GPL v3. See licenses/GPL-3.txt #include "UndoSystem.h" +#include "core/StringHash.h" #include "utils.h" #define XXH_INLINE_ALL diff --git a/src/editor/system/GalaxyEditAPI.cpp b/src/editor/system/GalaxyEditAPI.cpp index 72a1ae214d2..12b1594be1e 100644 --- a/src/editor/system/GalaxyEditAPI.cpp +++ b/src/editor/system/GalaxyEditAPI.cpp @@ -7,12 +7,12 @@ #include "SystemEditorHelpers.h" #include "core/Log.h" +#include "core/StringHash.h" #include "core/macros.h" #include "editor/UndoStepType.h" #include "editor/EditorDraw.h" #include "galaxy/Factions.h" -#include "galaxy/Galaxy.h" #include "galaxy/NameGenerator.h" #include "galaxy/Sector.h" #include "galaxy/StarSystemGenerator.h" diff --git a/src/galaxy/GalaxyGenerator.h b/src/galaxy/GalaxyGenerator.h index 8044b9ad41f..f0e2e2d32cd 100644 --- a/src/galaxy/GalaxyGenerator.h +++ b/src/galaxy/GalaxyGenerator.h @@ -4,6 +4,7 @@ #ifndef GALAXYGENERATOR_H #define GALAXYGENERATOR_H +#include "Galaxy.h" #include "RefCounted.h" #include "Sector.h" #include "StarSystem.h" diff --git a/src/lua/Lua.cpp b/src/lua/Lua.cpp index 92f297901c7..8647337a35c 100644 --- a/src/lua/Lua.cpp +++ b/src/lua/Lua.cpp @@ -5,7 +5,6 @@ #include "Pi.h" #include "LuaColor.h" -#include "LuaConsole.h" #include "LuaConstants.h" #include "LuaDev.h" #include "LuaEconomy.h" @@ -35,9 +34,10 @@ #include "SystemView.h" #include "galaxy/StarSystem.h" -#include "pigui/LuaPiGui.h" #include "scenegraph/Lua.h" +#include "profiler/Profiler.h" + namespace Lua { LuaManager *manager = 0; diff --git a/src/lua/LuaRand.cpp b/src/lua/LuaRand.cpp index 558581b076f..9c40131fcb8 100644 --- a/src/lua/LuaRand.cpp +++ b/src/lua/LuaRand.cpp @@ -44,12 +44,13 @@ static int l_rand_new(lua_State *l) std::unique_ptr rng(new Random()); switch (lua_type(l, 1)) { case LUA_TSTRING: { - size_t sz; - const char *str = lua_tolstring(l, 1, &sz); + std::string str = LuaPull(l, 1); + // lookup3_hashlittle2 reads 2 bytes past the end of the string + str += "\0\0"; // Note, these are inputs as well as outputs! They must be initialised. Uint32 hashes[2] = { 0u, 0u }; - lookup3_hashlittle2(str, sz, hashes + 0, hashes + 1); + lookup3_hashlittle2(str.data(), str.size() - 2, hashes + 0, hashes + 1); rng->seed(hashes, 2); break; } diff --git a/src/lua/LuaStarSystem.cpp b/src/lua/LuaStarSystem.cpp index 7e83e2e0188..7c709e7ee02 100644 --- a/src/lua/LuaStarSystem.cpp +++ b/src/lua/LuaStarSystem.cpp @@ -5,12 +5,10 @@ #include "FileSystem.h" #include "Game.h" #include "GameSaveError.h" -#include "LuaConstants.h" #include "LuaObject.h" #include "LuaTable.h" #include "LuaUtils.h" #include "Pi.h" -#include "Planet.h" #include "Space.h" #include "SpaceStation.h" #include "Star.h" @@ -21,6 +19,8 @@ #include "galaxy/Sector.h" #include "galaxy/StarSystem.h" +#include "profiler/Profiler.h" + /* * Class: StarSystem * diff --git a/src/test/TestProperty.cpp b/src/test/TestProperty.cpp index 428221905e7..9a6b1fc91a3 100644 --- a/src/test/TestProperty.cpp +++ b/src/test/TestProperty.cpp @@ -5,10 +5,11 @@ #include "Quaternion.h" #include "core/Log.h" #include "core/Property.h" +#include "profiler/Profiler.h" #include -#include #include +#include #include "doctest.h" static constexpr uint32_t ITERATIONS = 10000; diff --git a/src/test/TestStringName.cpp b/src/test/TestStringName.cpp index b82c12b0cbf..478624d53f0 100644 --- a/src/test/TestStringName.cpp +++ b/src/test/TestStringName.cpp @@ -3,6 +3,7 @@ #include "core/FNV1a.h" #include "core/Log.h" +#include "core/StringHash.h" #include "core/StringName.h" #include "profiler/Profiler.h"