sdl_runtime_compiler git · main
SDL3 game for running and compiling code at runtime
C++ 72.3% C 26.2%git clone https://git.christianimmanuel.de/sdl-graphics/sdl_runtime_compiler.gitwget https://git.christianimmanuel.de/sdl-graphics/sdl_runtime_compiler/archive/sdl_runtime_compiler.tar.gzRemove dead code AND Use config worldscale
src/entities/world.cpp | 70 ++--------------------------------------------- src/entities/world.hpp | 27 ++---------------- src/states/game_state.cpp | 54 ++++++++++++++++++------------------ 3 files changed, 32 insertions(+), 119 deletions(-) diff --git a/src/entities/world.cpp b/src/entities/world.cpp index 9d7adda..4107446 100644 --- a/src/entities/world.cpp +++ b/src/entities/world.cpp @@ -2,56 +2,11 @@ World::World() { - initEdges(); + // initEdges(); _wall_surfaces.generate(_world_scale); } -void -World::initEdges() -{ - const float r = _world_scale; - - const int map[24] = { - 0,1 , 1,3 , 3,2 , 2,0 , - 7,6 , 6,4 , 4,5 , 5,7 , - 6,2 , 3,7 , 0,4 , 5,1 - }; - - for (size_t i = 0; i < 12; i++) { - Vec3 a, b; - - for (int j = 0; j < 3; j++) { - float va = (map[i*2+0] & (1 << j)) ? r : -r; - float vb = (map[i*2+1] & (1 << j)) ? r : -r; - - if (j == 0) { a.x = va; b.x = vb; } - if (j == 1) { a.y = va; b.y = vb; } - if (j == 2) { a.z = va; b.z = vb; } - } - - _edges[i] = { a, b }; - } - - size_t scale = static_cast<size_t>(_world_scale); - for (size_t i = 0; i < scale; i++) { - float d = static_cast<float>(i * 2) - _world_scale; - - // line z axis - _edges[12 + i] = { - { -r, -r, d }, - { r, -r, d } - }; - - // line x axis - _edges[12 + scale + i] = { - { d, -r, -r }, - { d, -r, r } - }; - } -} - - static double sweepAxis(double end, double min, double max, bool& hit) { @@ -71,7 +26,7 @@ sweepAxis(double end, double min, double max, bool& hit) } PlayerCollision -World::resolvePlayer(const Player& player) const +World::resolve_Player(const Player& player) const { PlayerCollision out; out.vel = player.vel; @@ -102,20 +57,6 @@ World::draw(GlRenderer& gl, const Camera& camera, const Light& light) const Mat4 model = Mat4::identity(); Mat4 mvp = Mat4::mul(proj, Mat4::mul(view, model)); - // Box _edges: dark grey - if (show_wireframe) { - DynArray<float> pts; - pts.reserve(_map_box_edges_len * 6); - for (size_t k = 0; k < _map_box_edges_len; k++) { - const Edge& e = _edges[k]; - pts.push_back((float)e.a.x); pts.push_back((float)e.a.y); pts.push_back((float)e.a.z); - pts.push_back((float)e.b.x); pts.push_back((float)e.b.y); pts.push_back((float)e.b.z); - } - gl.set_MVP(model, mvp); - gl.set_Color(0.25f, 0.25f, 0.25f); - gl.draw_Lines(pts.data(), (int)pts.size() / 3); - } - // Crosshair: 2D overlay in NDC. Uses identity MVP, then restores the // world MVP so subsequent draws (_wall_surfaces) aren't affected. { @@ -142,10 +83,5 @@ World::draw(GlRenderer& gl, const Camera& camera, const Light& light) const Vec3 -World::spawnPoint() const +World::get_SpawnPoint() const { return {0.0, 2.0, 0.0}; } - - -float -World::scale() const -{ return _world_scale; } diff --git a/src/entities/world.hpp b/src/entities/world.hpp index 4cb62be..639b1f7 100644 --- a/src/entities/world.hpp +++ b/src/entities/world.hpp @@ -6,10 +6,6 @@ #include "rendering/gl_renderer.hpp" #include "wall/wall_surfaces.hpp" -struct Edge { - Vec3 a; - Vec3 b; -}; struct SweepResult { Vec3 pos; @@ -21,39 +17,20 @@ struct SweepResult { class World { - static inline constexpr int - _map_box_scale {static_cast<int>(ConfigGame::world_box_scale)}; - - static inline constexpr int - _map_box_edges_len {12 + _map_box_scale * 2}; - float _world_scale {ConfigGame::world_box_scale}; WallSurfaces _wall_surfaces; - - std::array<Edge, _map_box_edges_len> - _edges {}; - - void - initEdges(); public: - bool - show_wireframe { false }; - World(); PlayerCollision - resolvePlayer(const Player& player) const; + resolve_Player(const Player& player) const; void draw(GlRenderer& gl, const Camera& camera, const Light& light) const; Vec3 - spawnPoint() const; - - float - scale() const; - + get_SpawnPoint() const; }; diff --git a/src/states/game_state.cpp b/src/states/game_state.cpp index a305665..5b34ec4 100644 --- a/src/states/game_state.cpp +++ b/src/states/game_state.cpp @@ -45,15 +45,15 @@ GameState::GameState(size_t starting_level) _celebration_sys = cpputils::make_unique<CelebrationSystem>(); _floor_sys = cpputils::make_unique<FloorMandelbrot> (); - _floor_sys->generate(_ctx.world->scale(), -_ctx.world->scale()); + _floor_sys->generate(ConfigGame::world_box_scale, -ConfigGame::world_box_scale); - _wall_labels = WallLabel::generate_All(_ctx.world->scale()); + _wall_labels = WallLabel::generate_All(ConfigGame::world_box_scale); _word_ai_sys = cpputils::make_unique<WordAiSystem>(); - _word_ai_sys->set_WorldScale(_ctx.world->scale()); + _word_ai_sys->set_WorldScale(ConfigGame::world_box_scale); _pult_sys = cpputils::make_unique<PultSystem> (); - _pult_sys->init(_ctx.scenery, _ctx.buttons, _ctx.world->scale()); + _pult_sys->init(_ctx.scenery, _ctx.buttons, ConfigGame::world_box_scale); if (starting_level >= Level::level_Count()) starting_level = 0; _level_runner_sys = cpputils::make_unique<LevelRunner>(Level::get_Level(starting_level)); @@ -178,7 +178,7 @@ GameState::pult_DispatchAction(PultAction act) { _step_ledger.buttons_pressed.push_back(act); - const double floor_y = -static_cast<double>(_ctx.world->scale()); + const double floor_y = -static_cast<double>(ConfigGame::world_box_scale); switch (act) { case PultAction::ScrollEditorUp: @@ -233,7 +233,7 @@ GameState::on_Pick() if (base->type == ObjectType::Text) { _step_ledger.picked_up.push_back(base->text); base->set_Look(ConfigColor::keep, Text3d::depth_floor); - TextWall::show_TokenInfo(_ctx.wall_texts, base->text, _ctx.world->scale()); + TextWall::show_TokenInfo(_ctx.wall_texts, base->text, ConfigGame::world_box_scale); } carry_BeginAnim(std::move(base), /*with_pitch=*/true); return true; @@ -247,7 +247,7 @@ GameState::on_Pick() _step_ledger.picked_up.push_back(word->text); word->set_Look(ConfigColor::keep, Text3d::depth_floor); - TextWall::show_TokenInfo(_ctx.wall_texts, word->text, _ctx.world->scale()); + TextWall::show_TokenInfo(_ctx.wall_texts, word->text, ConfigGame::world_box_scale); carry_BeginAnim(std::move(word), /*with_pitch=*/false); return true; @@ -274,7 +274,7 @@ GameState::on_DropLast() _anims_drop.push_back(std::move(drop)); if (!_carried.empty()) - TextWall::show_TokenInfo(_ctx.wall_texts, _carried.last->word->text, _ctx.world->scale()); + TextWall::show_TokenInfo(_ctx.wall_texts, _carried.last->word->text, ConfigGame::world_box_scale); else infowall_StepdetailsShow(); @@ -299,14 +299,14 @@ GameState::on_ShootOne() single.push_back(std::move(word)); Aim::Result aim = Aim::crosshair_Target(*_ctx.camera, _ctx.words, _ctx.scenery, - _ctx.wall_texts, _ctx.world->scale()); + _ctx.wall_texts, ConfigGame::world_box_scale); _projectiles_sys->launch(_projectiles, std::move(single /* or all_words */), _ctx.camera->fwd, _ctx.camera->pos, aim); if (!_carried.empty() && _carried.last && _carried.last->word) TextWall::show_TokenInfo(_ctx.wall_texts, _carried.last->word->text, - _ctx.world->scale()); + ConfigGame::world_box_scale); else infowall_StepdetailsShow(); _step_ledger.shot = true; @@ -332,7 +332,7 @@ GameState::on_ShootAll() _carried = CarriedLine(); if (!all_words.empty()) { Aim::Result aim = Aim::crosshair_Target(*_ctx.camera, _ctx.words, _ctx.scenery, - _ctx.wall_texts, _ctx.world->scale()); + _ctx.wall_texts, ConfigGame::world_box_scale); _projectiles_sys->launch(_projectiles, std::move(all_words), _ctx.camera->fwd, _ctx.camera->pos, aim); } @@ -353,7 +353,7 @@ void GameState::on_Compile() { if (!path.empty() && !stripped.empty()) SourceTokens::write_File(path, src); - _mod_loader_sys->build(_ctx.wall_texts, src, _ctx.world->scale(), true); + _mod_loader_sys->build(_ctx.wall_texts, src, ConfigGame::world_box_scale, true); } else { _compiler_sys->compile(_ctx.wall_texts, src); } @@ -363,7 +363,7 @@ void GameState::on_Compile() { void GameState::on_Run() { - _program_sys->run(_ctx.wall_texts, _ctx.world->scale()); + _program_sys->run(_ctx.wall_texts, ConfigGame::world_box_scale); } @@ -463,7 +463,7 @@ GameState::projectile_FeedProgramInput(ProjectileResult& result) if (!line.empty()) _program_sys->feed_Input(line); - _program_sys->echo_Words(_ctx.wall_texts, result.words, _ctx.world->scale()); + _program_sys->echo_Words(_ctx.wall_texts, result.words, ConfigGame::world_box_scale); } @@ -474,7 +474,7 @@ GameState::step_Spawn(const DynArray<std::string>& tokens) static constexpr int per_row = 8; static constexpr float row_gap = 3.0f; - const double floor_y = -static_cast<double>(_ctx.world->scale()); + const double floor_y = -static_cast<double>(ConfigGame::world_box_scale); const double hover_y = floor_y + 1.5; for (size_t i = 0; i < tokens.size(); ++i) { @@ -523,7 +523,7 @@ GameState::projectile_LandOnWall(ProjectileResult& result) w->body.mode = PhysicsMode::Static; w->body.vel = Vec3{0, 0, 0}; - TextWallPtr wt = TextWall::from_Drop(std::move(w), _ctx.world->scale()); + TextWallPtr wt = TextWall::from_Drop(std::move(w), ConfigGame::world_box_scale); if (wt && wt->text3d && wt->role == Wall::Role::Editor) editor_group.push_back(wt->text3d.get()); // collect, don't place yet placed.push_back(std::move(wt)); @@ -578,7 +578,7 @@ GameState::walltext_HandleShootDown(ProjectileResult& result, Text3dPtr orphan = std::move(wt->text3d); orphan->body.mode = PhysicsMode::Dynamic; orphan->body.vel = { 0.0, 1.5, 0.0 }; - orphan->body.hover_height = -static_cast<double>(_ctx.world->scale()) + 1.5; + orphan->body.hover_height = -static_cast<double>(ConfigGame::world_box_scale) + 1.5; orphan->yaw = 0.0f; orphan->set_Look(ConfigColor::keep, Text3d::depth_floor); _ctx.words.push_back(std::move(orphan)); @@ -686,7 +686,7 @@ GameState::update(double dt) carriedline_Update(); - const double floor_y = -static_cast<double>(_ctx.world->scale()); + const double floor_y = -static_cast<double>(ConfigGame::world_box_scale); _word_anim_sys->update(_anims_add, _anims_drop, _carried, _ctx.words, dt, floor_y); _pult_sys->update(dt, *_ctx.camera); @@ -702,17 +702,17 @@ GameState::update(double dt) particle_colliders.reserve(_ctx.scenery.size()); for (const GameObjectPtr& s : _ctx.scenery) if (s) particle_colliders.push_back(s.get()); - _particle_sys->update(dt, particle_colliders, _ctx.world->scale()); + _particle_sys->update(dt, particle_colliders, ConfigGame::world_box_scale); } { FP_ZONE("update._compiler_sys"); - _compiler_sys->update(_ctx.wall_texts, _ctx.world->scale()); + _compiler_sys->update(_ctx.wall_texts, ConfigGame::world_box_scale); if (_compiler_sys->last_compile_ok) { _compiler_sys->last_compile_ok = false; _step_ledger.compile_ok = true; } - _mod_loader_sys->update(_ctx.wall_texts, _ctx.world->scale()); + _mod_loader_sys->update(_ctx.wall_texts, ConfigGame::world_box_scale); if (_mod_loader_sys->last_build_ok) { _mod_loader_sys->last_build_ok = false; mod_Apply(_mod_loader_sys->load_Objects()); @@ -721,7 +721,7 @@ GameState::update(double dt) } { FP_ZONE("update._program_sys"); - _program_sys->update(_ctx.wall_texts, _ctx.world->scale()); + _program_sys->update(_ctx.wall_texts, ConfigGame::world_box_scale); } { FP_ZONE("update.goals"); @@ -851,7 +851,7 @@ GameState::infowall_StepdetailsShow() const std::string& details = _level_runner_sys->current().details; if (details.empty()) return; - const float world_scale = _ctx.world->scale(); + const float world_scale = ConfigGame::world_box_scale; Wall::Transform wall_transform = Wall::get_Transform(Wall::Role::Info, world_scale); constexpr size_t MAX_INFO_LINE_CHARS = 92; @@ -972,7 +972,7 @@ GameState::substep(double dt) } { FP_ZONE("subst.phys_objects"); - _physics_sys->update_Objects(colliders, dt, 25.0, _ctx.world->scale()); + _physics_sys->update_Objects(colliders, dt, 25.0, ConfigGame::world_box_scale); } { FP_ZONE("subst.word_ai"); @@ -1042,7 +1042,7 @@ GameState::substep(double dt) DynArray<ProjectileResult> proj_results; { FP_ZONE("subst.projectile_sys"); _projectiles_sys->update(_projectiles, proj_results, - wall_text_hits, dt, _ctx.world->scale(), + wall_text_hits, dt, ConfigGame::world_box_scale, _program_sys->is_Running()); } @@ -1088,7 +1088,7 @@ GameState::substep(double dt) } { FP_ZONE("subst.player_collision"); - PlayerCollision col = _ctx.world->resolvePlayer(*_ctx.player); + PlayerCollision col = _ctx.world->resolve_Player(*_ctx.player); _ctx.player->apply_Collision(col); _physics_sys->resolve_PlayerVsObjects(*_ctx.player, _carried, colliders); @@ -1254,7 +1254,7 @@ GameState::sandbox_LoadFileToWall() [](const TextWallPtr& wt){ return wt->role == Wall::Role::Editor; }), _ctx.wall_texts.end()); - const float ws = _ctx.world->scale(); + const float ws = ConfigGame::world_box_scale; const double x_wall = -static_cast<double>(ws) + 0.05; // NegX wall surface Wall::Transform tf = Wall::get_Transform(Wall::Role::Editor, ws);