]> git.tdb.fi Git - libs/game.git/commitdiff
Ensure that a Shape's setup actually has a shape
authorMikko Rasa <tdb@tdb.fi>
Sat, 15 Mar 2025 10:46:25 +0000 (12:46 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 15 Mar 2025 12:55:38 +0000 (14:55 +0200)
source/game/shape.cpp
source/game/shape.h
source/gameview/renderer.cpp

index ba177215207e1542e1448545ce871d68b80e4f69..05d3db41ef0f41f8578d43a4e12b954e667e0473 100644 (file)
@@ -1,8 +1,18 @@
 #include "shape.h"
 #include <msp/geometry/loader.h>
 
+using namespace std;
+
 namespace Msp::Game {
 
+Shape::Shape(Handle<Entity> e, const Setup &s):
+       Component(e),
+       setup(s)
+{
+       if(!setup.shape)
+               throw invalid_argument("Shape::Shape");
+}
+
 ShapeSetup::Loader::Loader(ShapeSetup &s):
        ObjectLoader(s)
 {
index 692cf0c1970acaf4becb8a50bbe0034aba96b647..8ebec84009ab9f642e4a6b658c31494a44f2ab4f 100644 (file)
@@ -37,9 +37,9 @@ private:
        const Setup &setup;
 
 public:
-       Shape(Handle<Entity> p, const Setup &s): Component(p), setup(s) { }
+       Shape(Handle<Entity>, const Setup &);
 
-       const Geometry::Shape<float, 3> *get_shape() const { return setup.shape.get(); }
+       const Geometry::Shape<float, 3> &get_shape() const { return *setup.shape; }
        const std::string &get_technique_name() const { return setup.technique_name; }
        unsigned get_render_detail() const { return setup.render_detail; }
 };
index 45b2e55195b8bf1acfe7bf983e3683fe08374de8..58e6454f3c6b04908a239aa05822e551ecdc9da1 100644 (file)
@@ -126,7 +126,7 @@ void Renderer::component_created(const Game::Events::ComponentCreated &event)
                {
                        const GL::Technique &tech = stage.get_resources().get<GL::Technique>(shape->get_technique_name());
                        re.generated_mesh = Game::Owned<DynamicMeshSource>(re.entity, (GL::VERTEX3, GL::NORMAL3), tech);
-                       GL::ShapeBuilder(*shape->get_shape(), shape->get_render_detail()).build(re.generated_mesh->get_mesh());
+                       GL::ShapeBuilder(shape->get_shape(), shape->get_render_detail()).build(re.generated_mesh->get_mesh());
                }
        }