]> git.tdb.fi Git - libs/game.git/commitdiff
Use the setup generator to create setup structs
authorMikko Rasa <tdb@tdb.fi>
Sun, 8 Jan 2023 13:08:08 +0000 (15:08 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 8 Jan 2023 13:09:08 +0000 (15:09 +0200)
15 files changed:
examples/bassteroids/source/asteroid.h
examples/bassteroids/source/bullet.h
examples/bassteroids/source/collider.h
examples/bassteroids/source/damagesource.h
examples/bassteroids/source/hitpoints.h
examples/bassteroids/source/hittable.h
examples/bassteroids/source/physicalentity.h
examples/bassteroids/source/playfield.h
examples/bassteroids/source/rigidbody.h
examples/bassteroids/source/setups.mgs [new file with mode: 0644]
examples/bassteroids/source/ship.h
source/game/camera.h
source/game/meshsource.cpp
source/game/meshsource.h
source/game/setups.mgs [new file with mode: 0644]

index b80cc65a3437dbe2d532417ef6b432f0902f86b0..c5743eae1b8492d1d313ab9a74cbd55b042355f8 100644 (file)
@@ -4,13 +4,7 @@
 #include <msp/game/entity.h>
 #include <msp/game/meshsource.h>
 #include "hittable.h"
-
-struct AsteroidSetup
-{
-       PhysicalSetup physical;
-       HittableSetup hittable;
-       Msp::Game::MeshSourceSetup mesh;
-};
+#include "setups.h"
 
 class Asteroid: public Hittable
 {
index de0804a83974826a8681f511c29d44fe48c96bff..28b8ea846fc5019f7600c28673d1deab754ba178 100644 (file)
@@ -3,13 +3,7 @@
 
 #include <msp/game/meshsource.h>
 #include "hittable.h"
-
-struct BulletSetup
-{
-       PhysicalSetup physical;
-       HittableSetup hittable;
-       Msp::Game::MeshSourceSetup mesh;
-};
+#include "setups.h"
 
 class Bullet: public Hittable
 {
index cd5cffe6cf6e753398dc46d0a9d394264cb1e872..06577032e34f060a02cdf24cb60c336eec01f210 100644 (file)
@@ -3,23 +3,7 @@
 
 #include <msp/game/component.h>
 #include <msp/linal/vector.h>
-
-enum class ColliderType
-{
-       CIRCLE,
-       BOX
-};
-
-struct ColliderSetup
-{
-       ColliderType type = ColliderType::CIRCLE;
-       union
-       {
-               float radius = 1.0f;
-               Msp::LinAl::Vector<float, 2> size;
-       };
-};
-
+#include "setups.h"
 
 class Collider: public Msp::Game::Component
 {
index 41a27550b192901c80ee4d67e1a9b68ea6c01981..cf5e0728eaa94da31abf0d5c5f6567242b7381d6 100644 (file)
@@ -2,12 +2,7 @@
 #define DAMAGESOURCE_H_
 
 #include <msp/game/component.h>
-
-struct DamageSourceSetup
-{
-       unsigned amount = 1;
-       unsigned type = 0;
-};
+#include "setups.h"
 
 class DamageSource: public Msp::Game::Component
 {
index f6000d7abab3c6dc54782d4fc2c413817c8263e8..49fb920d2d1aa5a50919d53f7b06c8e63d04d8ca 100644 (file)
@@ -2,16 +2,7 @@
 #define HITPOINTS_H_
 
 #include <msp/game/component.h>
-
-struct HitPointsSetup
-{
-       /*class Loader: public Msp::DataFile::ObjectLoader<HitPointsSetup>
-       {
-       };*/
-
-       unsigned max_hits = 1;
-       unsigned vulnerable_to = ~0U;
-};
+#include "setups.h"
 
 struct HitPointsData
 {
index b548a38bbddff6b1628da4c7ff4a94a05702e286..bdbc43eac483b33831a48e13028924b0f599f484 100644 (file)
@@ -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
 {
index 8f2a57fa07fae65308947a12908fbfc50eb38f1b..0708d42ae46249a2b978739db02f55cbcf7c0749 100644 (file)
@@ -3,15 +3,9 @@
 
 #include <msp/game/entity.h>
 #include <msp/game/transform.h>
-#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
 {
index 10596e98a1ad5c3d145c383341ce431190d1fec0..6efba664f551f28442e4f075e2edfa9243e945f3 100644 (file)
@@ -3,11 +3,7 @@
 
 #include <msp/game/entity.h>
 #include "physicalentity.h"
-
-struct PlayfieldSetup
-{
-       Msp::LinAl::Vector<float, 2> size;
-};
+#include "setups.h"
 
 class Playfield: public Msp::Game::Entity
 {
index b75d034ab98e03b42a4beb81cb08d21532d1f4b4..cd5063d953c8422481965b2c7ea354c09296400e 100644 (file)
@@ -4,12 +4,7 @@
 #include <msp/game/component.h>
 #include <msp/geometry/angle.h>
 #include <msp/linal/vector.h>
-
-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 (file)
index 0000000..66ba9e3
--- /dev/null
@@ -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;
+};
index 52236cc6d86adbdef509104ff45fac17adcc2873..038be1d5f14d3dcdda62bca79be825a308933f7f 100644 (file)
@@ -3,14 +3,7 @@
 
 #include <msp/game/meshsource.h>
 #include "physicalentity.h"
-
-struct ShipSetup
-{
-       PhysicalSetup physical;
-       Msp::Game::MeshSourceSetup mesh;
-       float speed;
-       float turn_rate;
-};
+#include "setups.h"
 
 class Ship: public PhysicalEntity
 {
index 57f7395f33c85cdf6125e638f48b20561d8166a2..e981afcd3b2e85dfaf4d34d8d5f6ce65413e27b8 100644 (file)
@@ -5,27 +5,10 @@
 #include <msp/linal/vector.h>
 #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<float> field_of_view_y = Geometry::Angle<float>::from_degrees(60);
-       LinAl::Vector<float, 2> 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<float> fov_y;
index f26fa982fd98b469ec50387e23351a600c316ad6..a59343ed45fa587b323801cf0265e69a7b3011bf 100644 (file)
@@ -2,17 +2,4 @@
 
 namespace Msp::Game {
 
-DataFile::Loader::ActionMap MeshSourceSetup::Loader::shared_actions;
-
-MeshSourceSetup::Loader::Loader(MeshSourceSetup &s):
-       ObjectLoader<MeshSourceSetup>(s)
-{
-       set_actions(shared_actions);
-}
-
-void MeshSourceSetup::Loader::init_actions()
-{
-       add("object", &MeshSourceSetup::object_name);
-}
-
 } // namespace Msp::Game
index dfc6509844c4f749dcfa4600487bf08d5b5cbd32..15b8d20f522985891ccfae8d24c3c691a2376ef7 100644 (file)
@@ -2,28 +2,12 @@
 #define MSP_GAME_MESHSOURCE_H_
 
 #include <msp/datafile/objectloader.h>
+#include <msp/game/setups.h>
 #include "component.h"
 #include "mspgame_api.h"
 
 namespace Msp::Game {
 
-struct MeshSourceSetup
-{
-       class Loader: public DataFile::ObjectLoader<MeshSourceSetup>
-       {
-       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 (file)
index 0000000..3c36d37
--- /dev/null
@@ -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;
+};