From: Mikko Rasa Date: Sun, 8 Jan 2023 22:33:29 +0000 (+0200) Subject: Load the various setups through resources X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=41a17ae9a2baa2cafacfc467acc87463d790c09b;p=libs%2Fgame.git Load the various setups through resources --- diff --git a/examples/bassteroids/data/asteroid1.roid.setup b/examples/bassteroids/data/asteroid1.roid.setup new file mode 100644 index 0000000..a43f9f7 --- /dev/null +++ b/examples/bassteroids/data/asteroid1.roid.setup @@ -0,0 +1,31 @@ +physical +{ + body + { + mass 200; + moment_of_inertia 2160; + }; + collider + { + type CIRCLE; + radius 3; + }; +}; +hittable +{ + damaging true; + hits + { + max_hits 3; + vulnerable_to 1; + }; + damage + { + amount 10; + type 1; + }; +}; +mesh +{ + object_name "Asteroid 1.object"; +}; diff --git a/examples/bassteroids/data/main.camera.setup b/examples/bassteroids/data/main.camera.setup new file mode 100644 index 0000000..b8020f2 --- /dev/null +++ b/examples/bassteroids/data/main.camera.setup @@ -0,0 +1,5 @@ +field_of_view_y 0; +size 80 45; +near_clip -30; +far_clip 30; +sequence_name "space.seq"; diff --git a/examples/bassteroids/data/player.ship.setup b/examples/bassteroids/data/player.ship.setup new file mode 100644 index 0000000..2b0785f --- /dev/null +++ b/examples/bassteroids/data/player.ship.setup @@ -0,0 +1,19 @@ +physical +{ + body + { + mass 1; + moment_of_inertia 0.8; + }; + collider + { + type CIRCLE; + radius 0.8; + }; +}; +mesh +{ + object_name "Bass guitar.object"; +}; +speed 12; +turn_rate 4.71; diff --git a/examples/bassteroids/data/quaver.bullet.setup b/examples/bassteroids/data/quaver.bullet.setup new file mode 100644 index 0000000..10981dc --- /dev/null +++ b/examples/bassteroids/data/quaver.bullet.setup @@ -0,0 +1,30 @@ +physical +{ + body + { + mass 0.05; + moment_of_inertia 0.04; + }; + collider + { + type CIRCLE; + radius 0.2; + }; +}; +hittable +{ + damaging true; + hits + { + max_hits 1; + }; + damage + { + amount 1; + type 0; + }; +}; +mesh +{ + object_name "Quaver.object"; +}; diff --git a/examples/bassteroids/source/bassteroids.cpp b/examples/bassteroids/source/bassteroids.cpp index d6f2556..5e9d929 100644 --- a/examples/bassteroids/source/bassteroids.cpp +++ b/examples/bassteroids/source/bassteroids.cpp @@ -8,17 +8,25 @@ #include "gamecontroller.h" #include "physics.h" #include "playercontroller.h" +#include "setups.h" using namespace Msp; +BassteroidsResources::BassteroidsResources() +{ + add_type().suffix(".roid.setup"); + add_type().suffix(".bullet.setup"); + add_type().suffix(".ship.setup"); +} + + Bassteroids::Bassteroids(int, char **): event_observer(director.get_event_bus()), game_stage(director.create_stage()), pf_setup({ .size={ 80, 45 }}), playfield(game_stage.get_root(), pf_setup), - cam_setup({ .field_of_view_y=Geometry::Angle::zero(), .size={ 80, 45 }, .near_clip=-30, .far_clip=30, .sequence_name="space.seq" }), cam_entity(game_stage.get_root(), Game::TransformValues()), - camera(const_cast &>(cam_entity), cam_setup) + camera(cam_entity, resources.get("main.camera.setup")) { game_stage.add_system(); game_stage.add_system(); diff --git a/examples/bassteroids/source/bassteroids.h b/examples/bassteroids/source/bassteroids.h index 779092e..f3eabdd 100644 --- a/examples/bassteroids/source/bassteroids.h +++ b/examples/bassteroids/source/bassteroids.h @@ -11,7 +11,10 @@ class PlayerController; class BassteroidsResources: public Msp::Game::ApplicationResources, public Msp::GameView::Resources -{ }; +{ +public: + BassteroidsResources(); +}; class Bassteroids: public Msp::GameView::Application { @@ -23,7 +26,6 @@ private: Msp::Game::Owned playfield; PlayerController *player_controller = nullptr; - Msp::Game::CameraSetup cam_setup; Msp::Game::Owned cam_entity; Msp::Game::Owned camera; diff --git a/examples/bassteroids/source/gamecontroller.cpp b/examples/bassteroids/source/gamecontroller.cpp index 97701e3..d4b232d 100644 --- a/examples/bassteroids/source/gamecontroller.cpp +++ b/examples/bassteroids/source/gamecontroller.cpp @@ -8,9 +8,7 @@ using namespace Msp; GameController::GameController(Game::Stage &s): System(s), - asteroid_setup{ .physical={ .body={ .mass=200, .moment_of_inertia=2160 }, .collider={ .type=ColliderType::CIRCLE, .radius=3.0f } }, - .hittable={ .damaging=true, .hits={ .max_hits=3, .vulnerable_to=1 }, .damage={ .amount=10, .type=1 }}, - .mesh={ .object_name="Asteroid 1.object" }} + asteroid_setup(stage.get_resources().get("asteroid1.roid.setup")) { } void GameController::tick(Time::TimeDelta) diff --git a/examples/bassteroids/source/gamecontroller.h b/examples/bassteroids/source/gamecontroller.h index 1215444..cebdff3 100644 --- a/examples/bassteroids/source/gamecontroller.h +++ b/examples/bassteroids/source/gamecontroller.h @@ -15,7 +15,7 @@ private: }; std::minstd_rand rng; - AsteroidSetup asteroid_setup; + const AsteroidSetup &asteroid_setup; State state = LEVEL_START; unsigned level = 1; std::vector> asteroids; diff --git a/examples/bassteroids/source/playercontroller.cpp b/examples/bassteroids/source/playercontroller.cpp index b90992e..54f7520 100644 --- a/examples/bassteroids/source/playercontroller.cpp +++ b/examples/bassteroids/source/playercontroller.cpp @@ -8,12 +8,8 @@ using namespace Msp; PlayerController::PlayerController(Game::Stage &s): System(s), - player_setup{ .physical={ .body={ .mass=1, .moment_of_inertia=0.8f }, .collider={ .type=ColliderType::CIRCLE, .radius=0.8f }}, - .mesh={ .object_name="Bass guitar.object" }, - .speed=12.0f, .turn_rate=4.71f }, - bullet_setup{ .physical={ .body={ .mass=0.05f, .moment_of_inertia=0.04f }, .collider={ .type=ColliderType::CIRCLE, .radius=0.2f }}, - .hittable={ .damaging=true, .hits={ .max_hits=1 }, .damage={ .amount=1, .type=0 }}, - .mesh={ .object_name="Quaver.object" }} + player_setup(stage.get_resources().get("player.ship.setup")), + bullet_setup(stage.get_resources().get("quaver.bullet.setup")) { declare_dependency(READ_OLD); declare_dependency(UPDATE); diff --git a/examples/bassteroids/source/playercontroller.h b/examples/bassteroids/source/playercontroller.h index a4e35d4..be50071 100644 --- a/examples/bassteroids/source/playercontroller.h +++ b/examples/bassteroids/source/playercontroller.h @@ -13,8 +13,8 @@ class PlayerController: public Msp::Game::System { private: Controls *controls = nullptr; - ShipSetup player_setup; - BulletSetup bullet_setup; + const ShipSetup &player_setup; + const BulletSetup &bullet_setup; Msp::Game::Owned player_ship; std::vector> bullets; diff --git a/source/game/resources.cpp b/source/game/resources.cpp index 2b186de..a4f9e76 100644 --- a/source/game/resources.cpp +++ b/source/game/resources.cpp @@ -2,11 +2,18 @@ #include #include #include "resources.h" +#include "setups.h" using namespace std; namespace Msp::Game { +Resources::Resources() +{ + add_type().suffix(".camera.setup"); +} + + ApplicationResources::ApplicationResources() { FS::Path data_dir = FS::get_sys_data_dir()/"data"; diff --git a/source/game/resources.h b/source/game/resources.h index 6208433..695d52c 100644 --- a/source/game/resources.h +++ b/source/game/resources.h @@ -12,6 +12,7 @@ namespace Msp::Game { class MSPGAME_API Resources: virtual public DataFile::Collection { public: + Resources(); }; class MSPGAME_API ApplicationResources: public Resources