From cd0c08dc7ce754473178ad3f32f7740a1dddc1eb Mon Sep 17 00:00:00 2001 From: Vaino Kauppila Date: Thu, 2 Jul 2026 22:58:25 +0300 Subject: Initial import: LibreForts (M0-M5 in progress) Open-source Forts clone: custom C++20 engine + data-driven (Lua) 2D physics artillery RTS. - Building: node/strut graph on a stiff mass-spring solver (canon Forts model), triangulation rigidity, axial + 30-degree angle-stress breaking, cascading collapse, fire (DoT + spread), ground destroys debris. - Weapons (M4): cannon (ballistic) + laser (beam/ignite) with select-and-aim-in- arc UX; splash / beam damage; bg-brace passthrough. - Devices + economy (M5): reactors + win/loss + restart, mines/turbines/battery, metal deposits, storage caps, per-shot energy cost. - Data-driven via Lua/sol2 with a layered mod loader; enemy-fort scenario mod. - Renderer: SDL3 + textures + ImGui dev UI. stb_image + ImGui vendored. - Assets: CC0 placeholders only; real game art loaded at runtime from the user's own install via forts: paths (bring-your-own; nothing copyrighted committed). See README.md / CLAUDE.md and research/ + requirements/ for detail. --- src/engine/physics.hpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/engine/physics.hpp (limited to 'src/engine/physics.hpp') diff --git a/src/engine/physics.hpp b/src/engine/physics.hpp new file mode 100644 index 0000000..6a8abda --- /dev/null +++ b/src/engine/physics.hpp @@ -0,0 +1,41 @@ +#pragma once + +#include +#include + +// Box2D rigid-body world. The building structure runs on the custom Verlet +// solver (see build_graph / verlet); this exists as the foundation for M4 +// projectiles and any terrain collision they need. +struct PhysicsBody { + b2BodyId id; + b2Vec2 size; // half-width, half-height for box shapes + float red, green, blue, alpha; + bool is_static; +}; + +class PhysicsWorld { +public: + PhysicsWorld(); + ~PhysicsWorld(); + + PhysicsWorld(const PhysicsWorld&) = delete; + PhysicsWorld& operator=(const PhysicsWorld&) = delete; + + void step(float dt); + + // Create a static box (terrain, walls). + PhysicsBody* add_static_box(b2Vec2 center, float half_w, float half_h, + float r = 0.3f, float g = 0.3f, float b = 0.3f); + + // Create a dynamic box (projectiles, debris). + PhysicsBody* add_dynamic_box(b2Vec2 center, float half_w, float half_h, + float r = 0.8f, float g = 0.6f, float b = 0.2f); + + const std::vector& bodies() const { return bodies_; } + + b2WorldId world_id() const { return world_id_; } + +private: + b2WorldId world_id_; + std::vector bodies_; +}; -- cgit v1.3