Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fixes and improvements #5968

Merged
merged 4 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-fsanitize=address?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I overlooked that - this originally also had -fsanitize=thread as an option until I realized our codebase uses too many non-pthread synchronization primitives.

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)
Expand Down
17 changes: 13 additions & 4 deletions data/meta/Input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Beam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "lua/LuaEvent.h"
#include "lua/LuaUtils.h"

#include "profiler/Profiler.h"

namespace {
static float lifetime = 0.1f;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "core/Log.h"
#include "lua/LuaEvent.h"

#include "profiler/Profiler.h"

Body::Body() :
PropertiedObject(),
m_interpPos(0.0),
Expand Down
5 changes: 4 additions & 1 deletion src/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions src/DeathView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "graphics/Graphics.h"
#include "graphics/Renderer.h"

#include "profiler/Profiler.h"

DeathView::DeathView(Game *game) :
View(),
m_game(game)
Expand Down
2 changes: 2 additions & 0 deletions src/HudTrail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions src/Projectile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "lua/LuaEvent.h"
#include "lua/LuaUtils.h"

#include "profiler/Profiler.h"

std::unique_ptr<Graphics::MeshObject> Projectile::s_sideMesh;
std::unique_ptr<Graphics::MeshObject> Projectile::s_glowMesh;
std::unique_ptr<Graphics::Material> Projectile::s_sideMat;
Expand Down
7 changes: 4 additions & 3 deletions src/SectorView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
#include "lua/LuaRef.h"
#include "lua/LuaTable.h"
#include "matrix4x4.h"
#include <assert.h>
#include <cmath>
#include <sstream>

#include "profiler/Profiler.h"

#include <cassert>
#include <cmath>
#include <unordered_set>

SectorView::~SectorView() {}
Expand Down
4 changes: 3 additions & 1 deletion src/Sensors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "Ship.h"
#include "Space.h"

#include "profiler/Profiler.h"

Sensors::RadarContact::RadarContact() :
body(0),
trail(0),
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions src/Sfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions src/Shields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "scenegraph/StaticGeometry.h"
#include "scenegraph/Node.h"

#include "profiler/Profiler.h"

#include <SDL_timer.h>

REGISTER_COMPONENT_TYPE(Shields) {
Expand Down
10 changes: 3 additions & 7 deletions src/Ship-AI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions src/Space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <algorithm>
#include <functional>

//#define DEBUG_CACHE

Expand Down
1 change: 1 addition & 0 deletions src/SpeedLines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/SystemView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "graphics/Types.h"

#include "imgui/imgui.h"
#include "profiler/Profiler.h"
#include "SDL_keycode.h"

using namespace Graphics;
Expand Down
1 change: 1 addition & 0 deletions src/core/Property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "Json.h"
#include "JsonUtils.h"
#include "StringHash.h"

PropertyMapWrapper::PropertyMapWrapper(PropertyMap *m) :
m_map(m)
Expand Down
2 changes: 2 additions & 0 deletions src/core/Property.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "vector2.h"
#include "vector3.h"

#include "FNV1a.h"

#include <string>
#include <string_view>
#include <type_traits>
Expand Down
20 changes: 17 additions & 3 deletions src/core/StringName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#include "core/StringName.h"

#include "FNV1a.h"
#include "profiler/Profiler.h"

#include <cassert>
#include <cstdint>
#include <cstdlib>
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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];

Expand Down
12 changes: 2 additions & 10 deletions src/core/StringName.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@

#pragma once

#include "StringHash.h"
#include "profiler/Profiler.h"

#include <atomic>
#include <string_view>
#include <type_traits>
#include <vector>

/*
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -123,7 +115,7 @@ class StringTable {
std::vector<uint8_t> dist;
std::vector<Data> 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)); }
1 change: 1 addition & 0 deletions src/editor/UndoSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/editor/system/GalaxyEditAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/galaxy/GalaxyGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#ifndef GALAXYGENERATOR_H
#define GALAXYGENERATOR_H

#include "Galaxy.h"
#include "RefCounted.h"
#include "Sector.h"
#include "StarSystem.h"
Expand Down
4 changes: 2 additions & 2 deletions src/lua/Lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "Pi.h"

#include "LuaColor.h"
#include "LuaConsole.h"
#include "LuaConstants.h"
#include "LuaDev.h"
#include "LuaEconomy.h"
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/lua/LuaRand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ static int l_rand_new(lua_State *l)
std::unique_ptr<Random> 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<std::string>(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;
}
Expand Down
Loading