]> git.tdb.fi Git - libs/game.git/commitdiff
Load the various setups through resources
authorMikko Rasa <tdb@tdb.fi>
Sun, 8 Jan 2023 22:33:29 +0000 (00:33 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 8 Jan 2023 22:33:29 +0000 (00:33 +0200)
12 files changed:
examples/bassteroids/data/asteroid1.roid.setup [new file with mode: 0644]
examples/bassteroids/data/main.camera.setup [new file with mode: 0644]
examples/bassteroids/data/player.ship.setup [new file with mode: 0644]
examples/bassteroids/data/quaver.bullet.setup [new file with mode: 0644]
examples/bassteroids/source/bassteroids.cpp
examples/bassteroids/source/bassteroids.h
examples/bassteroids/source/gamecontroller.cpp
examples/bassteroids/source/gamecontroller.h
examples/bassteroids/source/playercontroller.cpp
examples/bassteroids/source/playercontroller.h
source/game/resources.cpp
source/game/resources.h

diff --git a/examples/bassteroids/data/asteroid1.roid.setup b/examples/bassteroids/data/asteroid1.roid.setup
new file mode 100644 (file)
index 0000000..a43f9f7
--- /dev/null
@@ -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 (file)
index 0000000..b8020f2
--- /dev/null
@@ -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 (file)
index 0000000..2b0785f
--- /dev/null
@@ -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 (file)
index 0000000..10981dc
--- /dev/null
@@ -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";
+};
index d6f255609c9f06e188886a4bba6ac2b03aaf3a03..5e9d929dea217acd12bf87950919849ce3c0bbbc 100644 (file)
@@ -8,17 +8,25 @@
 #include "gamecontroller.h"
 #include "physics.h"
 #include "playercontroller.h"
+#include "setups.h"
 
 using namespace Msp;
 
+BassteroidsResources::BassteroidsResources()
+{
+       add_type<AsteroidSetup>().suffix(".roid.setup");
+       add_type<BulletSetup>().suffix(".bullet.setup");
+       add_type<ShipSetup>().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<float>::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<const Game::Owned<Game::Entity> &>(cam_entity), cam_setup)
+       camera(cam_entity, resources.get<Game::CameraSetup>("main.camera.setup"))
 {
        game_stage.add_system<GameController>();
        game_stage.add_system<Physics>();
index 779092e1039ff835cce66a59f3196e1516e27b13..f3eabdd0858fc39a9f2cbdfa7b6ae70e33d09ed5 100644 (file)
 class PlayerController;
 
 class BassteroidsResources: public Msp::Game::ApplicationResources, public Msp::GameView::Resources
-{ };
+{
+public:
+       BassteroidsResources();
+};
 
 class Bassteroids: public Msp::GameView::Application<Bassteroids, BassteroidsResources>
 {
@@ -23,7 +26,6 @@ private:
        Msp::Game::Owned<Playfield> playfield;
        PlayerController *player_controller = nullptr;
 
-       Msp::Game::CameraSetup cam_setup;
        Msp::Game::Owned<Msp::Game::Entity> cam_entity;
        Msp::Game::Owned<Msp::Game::Camera> camera;
 
index 97701e379fa603d9bc6ad265351bc0ffa48f845f..d4b232db4d897ff28d698064b41bc97b04d09d2b 100644 (file)
@@ -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<AsteroidSetup>("asteroid1.roid.setup"))
 { }
 
 void GameController::tick(Time::TimeDelta)
index 121544429b08114115aea9c91418e8ec2914ae1a..cebdff32f85a4076189bda516a0d2b6283c224f8 100644 (file)
@@ -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<Msp::Game::Owned<Asteroid>> asteroids;
index b90992ed6239b191645476f48414e63ec7785b3e..54f7520a1a4f7bf93a1056addfa20c6df1f51fa8 100644 (file)
@@ -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<ShipSetup>("player.ship.setup")),
+       bullet_setup(stage.get_resources().get<BulletSetup>("quaver.bullet.setup"))
 {
        declare_dependency<Game::Transform>(READ_OLD);
        declare_dependency<RigidBody>(UPDATE);
index a4e35d4cc4adbe6a4c7dc384f6da61bb9c0aeba9..be5007102aeccc2883ce23ef426cd84cc52e92b4 100644 (file)
@@ -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<Ship> player_ship;
        std::vector<Msp::Game::Owned<Bullet>> bullets;
 
index 2b186de952049cb5ef504267775a6e0df191f96c..a4f9e76e7d1e9ee3a3bd63a9ad4b9c48eb9cc144 100644 (file)
@@ -2,11 +2,18 @@
 #include <msp/fs/dir.h>
 #include <msp/fs/stat.h>
 #include "resources.h"
+#include "setups.h"
 
 using namespace std;
 
 namespace Msp::Game {
 
+Resources::Resources()
+{
+       add_type<CameraSetup>().suffix(".camera.setup");
+}
+
+
 ApplicationResources::ApplicationResources()
 {
        FS::Path data_dir = FS::get_sys_data_dir()/"data";
index 62084337ac136d77ba163dde7a656c1b78da83e2..695d52c21c86668fc75b1d34d00ff3e2a92e72ce 100644 (file)
@@ -12,6 +12,7 @@ namespace Msp::Game {
 class MSPGAME_API Resources: virtual public DataFile::Collection
 {
 public:
+       Resources();
 };
 
 class MSPGAME_API ApplicationResources: public Resources