feat: Build optimizations
This commit is contained in:
5
makefile
5
makefile
@@ -1,5 +1,5 @@
|
|||||||
CC=g++
|
CC=g++
|
||||||
C_FLAGS=-g -Wall -Wextra -O0 -Wno-unused-function
|
C_FLAGS=-g -Wall -Wextra -O0 -Wno-unused-function -MMD -MP
|
||||||
VAL_FLAGS=--leak-check=full --show-leak-kinds=all --track-origins=yes -s
|
VAL_FLAGS=--leak-check=full --show-leak-kinds=all --track-origins=yes -s
|
||||||
|
|
||||||
DIR_SRC=src
|
DIR_SRC=src
|
||||||
@@ -11,6 +11,7 @@ OUTBIN=$(DIR_BUILD)/bin/main
|
|||||||
|
|
||||||
SRCS=$(shell find $(DIR_SRC)/ -type f -name '*.cpp')
|
SRCS=$(shell find $(DIR_SRC)/ -type f -name '*.cpp')
|
||||||
OBJS=$(patsubst $(DIR_SRC)/%.cpp,$(DIR_BUILD)/obj/%.o,$(SRCS))
|
OBJS=$(patsubst $(DIR_SRC)/%.cpp,$(DIR_BUILD)/obj/%.o,$(SRCS))
|
||||||
|
DEPMF=$(patsubst $(DIR_SRC)/%.cpp,$(DIR_BUILD)/obj/%.d,$(SRCS))
|
||||||
|
|
||||||
DEPS_EXT=$(patsubst %,-l%,$(DEPS))
|
DEPS_EXT=$(patsubst %,-l%,$(DEPS))
|
||||||
INCS_EXT=$(patsubst %,-I%,$(DIR_INC))
|
INCS_EXT=$(patsubst %,-I%,$(DIR_INC))
|
||||||
@@ -38,6 +39,8 @@ $(DIR_BUILD)/obj/%.o: $(DIR_SRC)/%.cpp
|
|||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
$(CC) $(C_FLAGS) $(INCS_EXT) -c $< -o $@
|
$(CC) $(C_FLAGS) $(INCS_EXT) -c $< -o $@
|
||||||
|
|
||||||
|
-include $(DEPMF)
|
||||||
|
|
||||||
dbg: $(DBG_BIN)
|
dbg: $(DBG_BIN)
|
||||||
gdb $(GDB_FLAGS) ./$(OUTBIN)
|
gdb $(GDB_FLAGS) ./$(OUTBIN)
|
||||||
|
|
||||||
|
|||||||
106
src/dxd_math.cpp
Normal file
106
src/dxd_math.cpp
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
#include "dxd_math.hpp"
|
||||||
|
|
||||||
|
vec2 operator+(vec2 const &v)
|
||||||
|
{
|
||||||
|
return { .x = v.x, .y = v.y };
|
||||||
|
}
|
||||||
|
|
||||||
|
vec2 operator-(vec2 const &v)
|
||||||
|
{
|
||||||
|
return { .x = -v.x, .y = -v.y };
|
||||||
|
}
|
||||||
|
|
||||||
|
vec2 operator+(vec2 const &a, vec2 const &b)
|
||||||
|
{
|
||||||
|
return { .x = a.x + b.x, .y = a.y + b.y };
|
||||||
|
}
|
||||||
|
|
||||||
|
vec2 operator-(vec2 const &a, vec2 const &b)
|
||||||
|
{
|
||||||
|
return { .x = a.x - b.x, .y = a.y - b.y };
|
||||||
|
}
|
||||||
|
|
||||||
|
vec2 operator*(vec2 const &a, float const &b)
|
||||||
|
{
|
||||||
|
return { .x = a.x * b, .y = a.y * b };
|
||||||
|
}
|
||||||
|
|
||||||
|
vec2 operator/(vec2 const &a, float const &b)
|
||||||
|
{
|
||||||
|
return { .x = a.x / b, .y = a.y / b };
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator<(vec2 const &a, vec2 const &b)
|
||||||
|
{
|
||||||
|
return a.x < b.x && a.y < b.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator>(vec2 const &a, vec2 const &b)
|
||||||
|
{
|
||||||
|
return a.x > b.x && a.y > b.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
float dot(vec2 const &a, vec2 const &b)
|
||||||
|
{
|
||||||
|
return a.x * b.x + a.y * b.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
float norm2(vec2 const &v)
|
||||||
|
{
|
||||||
|
return v.x * v.x + v.y * v.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
float norm(vec2 const &v)
|
||||||
|
{
|
||||||
|
return std::sqrtf(v.x * v.x + v.y * v.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec2 normalize(vec2 const &v)
|
||||||
|
{
|
||||||
|
return v / std::sqrt(v.x * v.x + v.y * v.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec2 min2(vec2 const &a, vec2 const &b)
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
.x = a.x < b.x ? a.x : b.x,
|
||||||
|
.y = a.y < b.y ? a.y : b.y,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
vec2 max2(vec2 const &a, vec2 const &b)
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
.x = a.x > b.x ? a.x : b.x,
|
||||||
|
.y = a.y > b.y ? a.y : b.y,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
vec2 polar_to_vec2(const float angle, const float len)
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
.x = len * sinf(angle),
|
||||||
|
.y = len * cosf(angle)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
float vec2_angle(const vec2 v)
|
||||||
|
{
|
||||||
|
return atan2f(v.x, v.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
float normalize_angle(const float angle)
|
||||||
|
{
|
||||||
|
float a = angle;
|
||||||
|
while (a > 2*M_PIf) a -= 2*M_PIf;
|
||||||
|
while (a < 0) a += 2*M_PIf;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
float normalize_angle_diff(const float diff)
|
||||||
|
{
|
||||||
|
float d = diff;
|
||||||
|
while (d > M_PIf) d -= 2*M_PIf;
|
||||||
|
while (d < -M_PIf) d += 2*M_PIf;
|
||||||
|
return d;
|
||||||
|
}
|
||||||
40
src/dxd_math.hpp
Normal file
40
src/dxd_math.hpp
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <float.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct vec2 { float x, y; } vec2;
|
||||||
|
typedef struct vec2i { int x, y; } vec2i;
|
||||||
|
|
||||||
|
static const vec2 vec2_zero = { 0, 0 };
|
||||||
|
static const vec2 vec2_one = { 1, 1 };
|
||||||
|
static const vec2 vec2_unitx = { 1, 0 };
|
||||||
|
static const vec2 vec2_unity = { 0, 1 };
|
||||||
|
static const vec2 vec2_max = { FLT_MAX, FLT_MAX };
|
||||||
|
static const vec2 vec2_min = { -FLT_MAX, -FLT_MAX };
|
||||||
|
static const vec2i vec2i_zero = { 0, 0 };
|
||||||
|
static const vec2i vec2i_one = { 1, 1 };
|
||||||
|
|
||||||
|
vec2 operator+(vec2 const &v);
|
||||||
|
vec2 operator-(vec2 const &v);
|
||||||
|
vec2 operator+(vec2 const &a, vec2 const &b);
|
||||||
|
vec2 operator-(vec2 const &a, vec2 const &b);
|
||||||
|
vec2 operator*(vec2 const &a, float const &b);
|
||||||
|
vec2 operator/(vec2 const &a, float const &b);
|
||||||
|
bool operator<(vec2 const &a, vec2 const &b);
|
||||||
|
bool operator>(vec2 const &a, vec2 const &b);
|
||||||
|
|
||||||
|
float dot(vec2 const &a, vec2 const &b);
|
||||||
|
float norm2(vec2 const &v);
|
||||||
|
float norm(vec2 const &v);
|
||||||
|
vec2 normalize(vec2 const &v);
|
||||||
|
vec2 min2(vec2 const &a, vec2 const &b);
|
||||||
|
vec2 max2(vec2 const &a, vec2 const &b);
|
||||||
|
|
||||||
|
vec2 polar_to_vec2(const float angle, const float len);
|
||||||
|
float vec2_angle(const vec2 v);
|
||||||
|
|
||||||
|
float normalize_angle(const float angle);
|
||||||
|
float normalize_angle_diff(const float diff);
|
||||||
131
src/math.hpp
131
src/math.hpp
@@ -1,131 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <float.h>
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
//#define epsilon 0.0000001
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct vec2 { float x, y; } vec2;
|
|
||||||
typedef struct vec2i { int x, y; } vec2i;
|
|
||||||
|
|
||||||
static const vec2 vec2_zero = { 0, 0 };
|
|
||||||
static const vec2 vec2_one = { 1, 1 };
|
|
||||||
static const vec2 vec2_unitx = { 1, 0 };
|
|
||||||
static const vec2 vec2_unity = { 0, 1 };
|
|
||||||
static const vec2 vec2_max = { FLT_MAX, FLT_MAX };
|
|
||||||
static const vec2 vec2_min = { -FLT_MAX, -FLT_MAX };
|
|
||||||
static const vec2i vec2i_zero = { 0, 0 };
|
|
||||||
static const vec2i vec2i_one = { 1, 1 };
|
|
||||||
|
|
||||||
static vec2 operator+(vec2 const &v)
|
|
||||||
{
|
|
||||||
return { .x = v.x, .y = v.y };
|
|
||||||
}
|
|
||||||
|
|
||||||
static vec2 operator-(vec2 const &v)
|
|
||||||
{
|
|
||||||
return { .x = -v.x, .y = -v.y };
|
|
||||||
}
|
|
||||||
|
|
||||||
static vec2 operator+(vec2 const &a, vec2 const &b)
|
|
||||||
{
|
|
||||||
return { .x = a.x + b.x, .y = a.y + b.y };
|
|
||||||
}
|
|
||||||
|
|
||||||
static vec2 operator-(vec2 const &a, vec2 const &b)
|
|
||||||
{
|
|
||||||
return { .x = a.x - b.x, .y = a.y - b.y };
|
|
||||||
}
|
|
||||||
|
|
||||||
static vec2 operator*(vec2 const &a, float const &b)
|
|
||||||
{
|
|
||||||
return { .x = a.x * b, .y = a.y * b };
|
|
||||||
}
|
|
||||||
|
|
||||||
static vec2 operator/(vec2 const &a, float const &b)
|
|
||||||
{
|
|
||||||
return { .x = a.x / b, .y = a.y / b };
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool operator<(vec2 const &a, vec2 const &b)
|
|
||||||
{
|
|
||||||
return a.x < b.x && a.y < b.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool operator>(vec2 const &a, vec2 const &b)
|
|
||||||
{
|
|
||||||
return a.x > b.x && a.y > b.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
static float dot(vec2 const &a, vec2 const &b)
|
|
||||||
{
|
|
||||||
return a.x * b.x + a.y * b.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
static float norm2(vec2 const &v)
|
|
||||||
{
|
|
||||||
return v.x * v.x + v.y * v.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
static float norm(vec2 const &v)
|
|
||||||
{
|
|
||||||
return std::sqrtf(v.x * v.x + v.y * v.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
static vec2 normalize(vec2 const &v)
|
|
||||||
{
|
|
||||||
return v / norm(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline vec2 normalize_h(vec2 const &v)
|
|
||||||
{
|
|
||||||
return v / std::sqrt(v.x * v.x + v.y * v.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
static vec2 min2(vec2 const &a, vec2 const &b)
|
|
||||||
{
|
|
||||||
return {
|
|
||||||
.x = a.x < b.x ? a.x : b.x,
|
|
||||||
.y = a.y < b.y ? a.y : b.y,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
static vec2 max2(vec2 const &a, vec2 const &b)
|
|
||||||
{
|
|
||||||
return {
|
|
||||||
.x = a.x > b.x ? a.x : b.x,
|
|
||||||
.y = a.y > b.y ? a.y : b.y,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
static vec2 polar_to_vec2(const float angle, const float len)
|
|
||||||
{
|
|
||||||
// 0 (north) up, PI/2 (east) right
|
|
||||||
return {
|
|
||||||
.x = len * sinf(angle),
|
|
||||||
.y = len * cosf(angle)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
static float vec2_angle(const vec2 v)
|
|
||||||
{
|
|
||||||
return atan2f(v.x, v.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
static float normalize_angle(const float angle)
|
|
||||||
{
|
|
||||||
float a = angle;
|
|
||||||
while (a > 2*M_PIf) a -= 2*M_PIf;
|
|
||||||
while (a < 0) a += 2*M_PIf;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
static float normalize_angle_diff(const float diff)
|
|
||||||
{
|
|
||||||
float d = diff;
|
|
||||||
while (d > M_PIf) d -= 2*M_PIf;
|
|
||||||
while (d < -M_PIf) d += 2*M_PIf;
|
|
||||||
return d;
|
|
||||||
}
|
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
#include "math.hpp"
|
#include "dxd_math.hpp"
|
||||||
|
|
||||||
namespace dxd
|
namespace dxd
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "../math.hpp"
|
#include "../dxd_math.hpp"
|
||||||
#include "world_object.hpp"
|
#include "world_object.hpp"
|
||||||
#include "airfield.hpp"
|
#include "airfield.hpp"
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../math.hpp"
|
#include "../dxd_math.hpp"
|
||||||
#include "world_object.hpp"
|
#include "world_object.hpp"
|
||||||
|
|
||||||
namespace dxd::sim
|
namespace dxd::sim
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../math.hpp"
|
#include "../dxd_math.hpp"
|
||||||
#include "world_object.hpp"
|
#include "world_object.hpp"
|
||||||
|
|
||||||
namespace dxd::sim
|
namespace dxd::sim
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "../math.hpp"
|
#include "../dxd_math.hpp"
|
||||||
#include "world_object.hpp"
|
#include "world_object.hpp"
|
||||||
|
|
||||||
namespace dxd::sim
|
namespace dxd::sim
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "../math.hpp"
|
#include "../dxd_math.hpp"
|
||||||
#include "world_object.hpp"
|
#include "world_object.hpp"
|
||||||
|
|
||||||
namespace dxd::sim
|
namespace dxd::sim
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../math.hpp"
|
#include "../dxd_math.hpp"
|
||||||
#include "../renderer.hpp"
|
#include "../renderer.hpp"
|
||||||
#include "world.hpp"
|
#include "world.hpp"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user