From: Mikko Rasa Date: Sun, 8 Jan 2023 13:08:08 +0000 (+0200) Subject: Use the setup generator to create setup structs X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=239cd38de0ddbb5931151523530a5e7272e16f7f;p=libs%2Fgame.git Use the setup generator to create setup structs --- diff --git a/examples/bassteroids/source/asteroid.h b/examples/bassteroids/source/asteroid.h index b80cc65..c5743ea 100644 --- a/examples/bassteroids/source/asteroid.h +++ b/examples/bassteroids/source/asteroid.h @@ -4,13 +4,7 @@ #include #include #include "hittable.h" - -struct AsteroidSetup -{ - PhysicalSetup physical; - HittableSetup hittable; - Msp::Game::MeshSourceSetup mesh; -}; +#include "setups.h" class Asteroid: public Hittable { diff --git a/examples/bassteroids/source/bullet.h b/examples/bassteroids/source/bullet.h index de0804a..28b8ea8 100644 --- a/examples/bassteroids/source/bullet.h +++ b/examples/bassteroids/source/bullet.h @@ -3,13 +3,7 @@ #include #include "hittable.h" - -struct BulletSetup -{ - PhysicalSetup physical; - HittableSetup hittable; - Msp::Game::MeshSourceSetup mesh; -}; +#include "setups.h" class Bullet: public Hittable { diff --git a/examples/bassteroids/source/collider.h b/examples/bassteroids/source/collider.h index cd5cffe..0657703 100644 --- a/examples/bassteroids/source/collider.h +++ b/examples/bassteroids/source/collider.h @@ -3,23 +3,7 @@ #include #include - -enum class ColliderType -{ - CIRCLE, - BOX -}; - -struct ColliderSetup -{ - ColliderType type = ColliderType::CIRCLE; - union - { - float radius = 1.0f; - Msp::LinAl::Vector size; - }; -}; - +#include "setups.h" class Collider: public Msp::Game::Component { diff --git a/examples/bassteroids/source/damagesource.h b/examples/bassteroids/source/damagesource.h index 41a2755..cf5e072 100644 --- a/examples/bassteroids/source/damagesource.h +++ b/examples/bassteroids/source/damagesource.h @@ -2,12 +2,7 @@ #define DAMAGESOURCE_H_ #include - -struct DamageSourceSetup -{ - unsigned amount = 1; - unsigned type = 0; -}; +#include "setups.h" class DamageSource: public Msp::Game::Component { diff --git a/examples/bassteroids/source/hitpoints.h b/examples/bassteroids/source/hitpoints.h index f6000d7..49fb920 100644 --- a/examples/bassteroids/source/hitpoints.h +++ b/examples/bassteroids/source/hitpoints.h @@ -2,16 +2,7 @@ #define HITPOINTS_H_ #include - -struct HitPointsSetup -{ - /*class Loader: public Msp::DataFile::ObjectLoader - { - };*/ - - unsigned max_hits = 1; - unsigned vulnerable_to = ~0U; -}; +#include "setups.h" struct HitPointsData { diff --git a/examples/bassteroids/source/hittable.h b/examples/bassteroids/source/hittable.h index b548a38..bdbc43e 100644 --- a/examples/bassteroids/source/hittable.h +++ b/examples/bassteroids/source/hittable.h @@ -5,14 +5,7 @@ #include "damagesource.h" #include "hitpoints.h" #include "physicalentity.h" - -struct HittableSetup -{ - bool immortal = false; - bool damaging = false; - HitPointsSetup hits; - DamageSourceSetup damage; -}; +#include "setups.h" class Hittable: public PhysicalEntity { diff --git a/examples/bassteroids/source/physicalentity.h b/examples/bassteroids/source/physicalentity.h index 8f2a57f..0708d42 100644 --- a/examples/bassteroids/source/physicalentity.h +++ b/examples/bassteroids/source/physicalentity.h @@ -3,15 +3,9 @@ #include #include -#include "rigidbody.h" #include "collider.h" - -struct PhysicalSetup -{ - bool fixture = false; - RigidBodySetup body; - ColliderSetup collider; -}; +#include "rigidbody.h" +#include "setups.h" class PhysicalEntity: public Msp::Game::Entity { diff --git a/examples/bassteroids/source/playfield.h b/examples/bassteroids/source/playfield.h index 10596e9..6efba66 100644 --- a/examples/bassteroids/source/playfield.h +++ b/examples/bassteroids/source/playfield.h @@ -3,11 +3,7 @@ #include #include "physicalentity.h" - -struct PlayfieldSetup -{ - Msp::LinAl::Vector size; -}; +#include "setups.h" class Playfield: public Msp::Game::Entity { diff --git a/examples/bassteroids/source/rigidbody.h b/examples/bassteroids/source/rigidbody.h index b75d034..cd5063d 100644 --- a/examples/bassteroids/source/rigidbody.h +++ b/examples/bassteroids/source/rigidbody.h @@ -4,12 +4,7 @@ #include #include #include - -struct RigidBodySetup -{ - float mass = 1.0f; - float moment_of_inertia = 0.5f; -}; +#include "setups.h" struct RigidBodyData { diff --git a/examples/bassteroids/source/setups.mgs b/examples/bassteroids/source/setups.mgs new file mode 100644 index 0000000..66ba9e3 --- /dev/null +++ b/examples/bassteroids/source/setups.mgs @@ -0,0 +1,74 @@ +import "msp/game/setups"; + +enum ColliderType +{ + value CIRCLE; + value BOX; +}; + +component Collider +{ + field type ColliderType { default "CIRCLE"; }; + field radius float { default "1.0f"; }; + field size vector2 { default "1.0f, 1.0f"; }; +}; + +component RigidBody +{ + field mass float { default "1.0f"; }; + field moment_of_inertia float { default "0.5f"; }; +}; + +entity Physical +{ + field fixture bool { default "false"; }; + field body RigidBody; + field collider Collider; +}; + +component HitPoints +{ + field max_hits uint { default "1"; }; + field vulnerable_to uint { default "~0U"; }; +}; + +component DamageSource +{ + field amount uint { default "1"; }; + field type uint { default "0"; }; +}; + +entity Hittable +{ + field immortal bool { default "false"; }; + field damaging bool { default "false"; }; + field hits HitPoints; + field damage DamageSource; +}; + +entity Playfield +{ + field size vector2; +}; + +entity Ship +{ + field physical Physical; + field mesh MeshSource; + field speed float; + field turn_rate float; +}; + +entity Bullet +{ + field physical Physical; + field hittable Hittable; + field mesh MeshSource; +}; + +entity Asteroid +{ + field physical Physical; + field hittable Hittable; + field mesh MeshSource; +}; diff --git a/examples/bassteroids/source/ship.h b/examples/bassteroids/source/ship.h index 52236cc..038be1d 100644 --- a/examples/bassteroids/source/ship.h +++ b/examples/bassteroids/source/ship.h @@ -3,14 +3,7 @@ #include #include "physicalentity.h" - -struct ShipSetup -{ - PhysicalSetup physical; - Msp::Game::MeshSourceSetup mesh; - float speed; - float turn_rate; -}; +#include "setups.h" class Ship: public PhysicalEntity { diff --git a/source/game/camera.h b/source/game/camera.h index 57f7395..e981afc 100644 --- a/source/game/camera.h +++ b/source/game/camera.h @@ -5,27 +5,10 @@ #include #include "component.h" #include "mspgame_api.h" +#include "setups.h" namespace Msp::Game { -enum class CameraScaling -{ - ORIGINAL_SIZE, - SCALE_TO_FIT, - SCALE_TO_COVER, - STRETCH_TO_FIT -}; - -struct CameraSetup -{ - Geometry::Angle field_of_view_y = Geometry::Angle::from_degrees(60); - LinAl::Vector size = { 16.0f/9.0f, 1.0f }; - float near_clip = 0.1f; - float far_clip = 100.0f; - CameraScaling scaling = CameraScaling::SCALE_TO_FIT; - std::string sequence_name; -}; - struct CameraData { Geometry::Angle fov_y; diff --git a/source/game/meshsource.cpp b/source/game/meshsource.cpp index f26fa98..a59343e 100644 --- a/source/game/meshsource.cpp +++ b/source/game/meshsource.cpp @@ -2,17 +2,4 @@ namespace Msp::Game { -DataFile::Loader::ActionMap MeshSourceSetup::Loader::shared_actions; - -MeshSourceSetup::Loader::Loader(MeshSourceSetup &s): - ObjectLoader(s) -{ - set_actions(shared_actions); -} - -void MeshSourceSetup::Loader::init_actions() -{ - add("object", &MeshSourceSetup::object_name); -} - } // namespace Msp::Game diff --git a/source/game/meshsource.h b/source/game/meshsource.h index dfc6509..15b8d20 100644 --- a/source/game/meshsource.h +++ b/source/game/meshsource.h @@ -2,28 +2,12 @@ #define MSP_GAME_MESHSOURCE_H_ #include +#include #include "component.h" #include "mspgame_api.h" namespace Msp::Game { -struct MeshSourceSetup -{ - class Loader: public DataFile::ObjectLoader - { - private: - static Loader::ActionMap shared_actions; - - public: - Loader(MeshSourceSetup &); - - protected: - void init_actions() override; - }; - - std::string object_name; -}; - class MSPGAME_API MeshSource: public Component { public: diff --git a/source/game/setups.mgs b/source/game/setups.mgs new file mode 100644 index 0000000..3c36d37 --- /dev/null +++ b/source/game/setups.mgs @@ -0,0 +1,25 @@ +namespace "Msp::Game"; +api "MSPGAME_API" "msp/game/mspgame_api.h"; + +enum CameraScaling +{ + value ORIGINAL_SIZE; + value SCALE_TO_FIT; + value SCALE_TO_COVER; + value STRETCH_TO_FIT; +}; + +component Camera +{ + field field_of_view_y angle { default "60"; }; + field size vector2 { default "16.0f/9.0f, 1.0f"; }; + field near_clip float { default "0.1f"; }; + field far_clip float { default "100.0f"; }; + field scaling CameraScaling { default "SCALE_TO_FIT"; }; + field sequence_name string; +}; + +component MeshSource +{ + field object_name string; +};