]> git.tdb.fi Git - libs/game.git/commitdiff
Use the auto type to hold the result of dynamic_handle_cast
authorMikko Rasa <tdb@tdb.fi>
Thu, 6 Mar 2025 13:10:07 +0000 (15:10 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 6 Mar 2025 13:11:13 +0000 (15:11 +0200)
It's clear enough what the type will be so no need to repeat it.

source/game/entity.h
source/game/landscape.cpp
source/game/remotecall.h
source/game/replicator.cpp
source/game/stage.cpp
source/gameview/renderer.cpp
source/gameview/terrainmeshcreator.cpp

index a8daba8ec602129a6f2b7455e9f29f4c6ea52605..2362a64b9237e39ac88dab9c08c1635b63219cfd 100644 (file)
@@ -59,7 +59,7 @@ template<typename T>
 inline Handle<T> Entity::get_component()
 {
        for(Handle<Component> c: components)
-               if(Handle<T> tc = dynamic_handle_cast<T>(c))
+               if(auto tc = dynamic_handle_cast<T>(c))
                        return tc;
        return nullptr;
 }
index 2f39c6dfb4d3deaef4f7c6258710d00c46a0c7bd..564443fa9851d2df4b32dff199ff6b84f26746ff 100644 (file)
@@ -91,7 +91,7 @@ void Landscape::spawned(Owned<Entity> entity)
 
 void Landscape::spawn_sent(Handle<Entity> entity, unsigned target)
 {
-       if(Handle<TerrainBlock> block = dynamic_handle_cast<TerrainBlock>(entity))
+       if(auto block = dynamic_handle_cast<TerrainBlock>(entity))
        {
                Messages::LandscapeData message;
                block->terrain->send_data(message.heightmap);
index 21e51de1c354a9f8ad5487994b48b311086c4e57..9ad70aee1499f304600d6191b51f0641a413cf85 100644 (file)
@@ -182,7 +182,7 @@ void RemoteCall<P, E, D>::receive(P &&packet)
                if(!entity)
                        return;  // TODO report the error somehow
 
-               Handle<E> cast_entity = dynamic_handle_cast<E>(entity);
+               auto cast_entity = dynamic_handle_cast<E>(entity);
                if(!cast_entity)
                        return;
 
index eae3e52f67e17bea96c3141d530f575caf0a0012..d704c50ddf8d6732ca63fecc522465d25614caeb 100644 (file)
@@ -115,7 +115,7 @@ void Replicator::deferred_tick()
 
 void Replicator::component_created(const Events::ComponentCreated &event)
 {
-       if(Handle<Zygote> zygote = dynamic_handle_cast<Zygote>(event.component))
+       if(auto zygote = dynamic_handle_cast<Zygote>(event.component))
        {
                Handle<Entity> entity = zygote->get_entity();
                Handle<Transform> transform = entity->get_transform();
@@ -128,7 +128,7 @@ void Replicator::component_created(const Events::ComponentCreated &event)
                else if(received_entity_id!=Zygote::NO_ID)
                        zygote->set_entity_id(received_entity_id);
        }
-       else if(Handle<Possessed> possessed = dynamic_handle_cast<Possessed>(event.component))
+       else if(auto possessed = dynamic_handle_cast<Possessed>(event.component))
        {
                Handle<Transform> transform = possessed->get_entity()->get_transform();
                auto i = lower_bound_member(entities, transform, &ReplicatedEntity::transform);
index d3ca0cbafadd5f9e8b76c3baaf69ee05a58f2612..889000bfcd8d43d11b0e445bdca7eb305e7998ea 100644 (file)
@@ -22,7 +22,7 @@ Stage::Stage(const string &n, Reflection::Reflector &f, DataFile::Collection &r)
 {
        event_observer.observe<Events::ComponentCreated>([this](auto &e){
                if(!active_camera)
-                       if(Handle<Camera> camera = dynamic_handle_cast<Camera>(e.component))
+                       if(auto camera = dynamic_handle_cast<Camera>(e.component))
                                set_active_camera(camera);
        });
 }
index 8173d1dcf781232429162f0677869f0373786639..45b2e55195b8bf1acfe7bf983e3683fe08374de8 100644 (file)
@@ -119,8 +119,7 @@ void Renderer::create_sequence()
 
 void Renderer::component_created(const Game::Events::ComponentCreated &event)
 {
-       Game::Handle<Game::Shape> shape = dynamic_handle_cast<Game::Shape>(event.component);
-       if(shape)
+       if(auto shape = dynamic_handle_cast<Game::Shape>(event.component))
        {
                RenderedEntity &re = get_rendered_entity(event.component->get_entity());
                if(!re.generated_mesh)
@@ -131,8 +130,8 @@ void Renderer::component_created(const Game::Events::ComponentCreated &event)
                }
        }
 
-       Game::Handle<Game::MeshSource> mesh_source = dynamic_handle_cast<Game::MeshSource>(event.component);
-       Game::Handle<DynamicMeshSource> dyn_mesh_src = dynamic_handle_cast<DynamicMeshSource>(event.component);
+       auto mesh_source = dynamic_handle_cast<Game::MeshSource>(event.component);
+       auto dyn_mesh_src = dynamic_handle_cast<DynamicMeshSource>(event.component);
        if(mesh_source || dyn_mesh_src)
        {
                RenderedEntity &re = get_rendered_entity(event.component->get_entity());
@@ -145,7 +144,7 @@ void Renderer::component_created(const Game::Events::ComponentCreated &event)
                }
        }
 
-       Game::Handle<Game::Light> light = dynamic_handle_cast<Game::Light>(event.component);
+       auto light = dynamic_handle_cast<Game::Light>(event.component);
        if(light)
        {
                RenderedEntity &re = get_rendered_entity(event.component->get_entity());
index b70cded712db3f35094ffeb503e13bad05142f46..d9b151fb38a2178936604d0957e9015a7a407ebd 100644 (file)
@@ -46,7 +46,7 @@ TerrainMeshCreator::~TerrainMeshCreator()
 
 void TerrainMeshCreator::component_created(const Game::Events::ComponentCreated &event)
 {
-       if(Game::Handle<Game::HeightmapTerrain> terrain = dynamic_handle_cast<Game::HeightmapTerrain>(event.component))
+       if(auto terrain = dynamic_handle_cast<Game::HeightmapTerrain>(event.component))
        {
                const GL::Technique &tech = stage.get_resources().get<GL::Technique>(terrain->get_technique_name());
                GL::VertexFormat fmt = (GL::VERTEX3, GL::TEXCOORD2, GL::NORMAL3,GL::UNSIGNED_BYTE,