From f12315a4509e326dce5a0b3daca1f314699333ad Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 6 Mar 2025 15:10:07 +0200 Subject: [PATCH] Use the auto type to hold the result of dynamic_handle_cast It's clear enough what the type will be so no need to repeat it. --- source/game/entity.h | 2 +- source/game/landscape.cpp | 2 +- source/game/remotecall.h | 2 +- source/game/replicator.cpp | 4 ++-- source/game/stage.cpp | 2 +- source/gameview/renderer.cpp | 9 ++++----- source/gameview/terrainmeshcreator.cpp | 2 +- 7 files changed, 11 insertions(+), 12 deletions(-) diff --git a/source/game/entity.h b/source/game/entity.h index a8daba8..2362a64 100644 --- a/source/game/entity.h +++ b/source/game/entity.h @@ -59,7 +59,7 @@ template inline Handle Entity::get_component() { for(Handle c: components) - if(Handle tc = dynamic_handle_cast(c)) + if(auto tc = dynamic_handle_cast(c)) return tc; return nullptr; } diff --git a/source/game/landscape.cpp b/source/game/landscape.cpp index 2f39c6d..564443f 100644 --- a/source/game/landscape.cpp +++ b/source/game/landscape.cpp @@ -91,7 +91,7 @@ void Landscape::spawned(Owned entity) void Landscape::spawn_sent(Handle entity, unsigned target) { - if(Handle block = dynamic_handle_cast(entity)) + if(auto block = dynamic_handle_cast(entity)) { Messages::LandscapeData message; block->terrain->send_data(message.heightmap); diff --git a/source/game/remotecall.h b/source/game/remotecall.h index 21e51de..9ad70ae 100644 --- a/source/game/remotecall.h +++ b/source/game/remotecall.h @@ -182,7 +182,7 @@ void RemoteCall::receive(P &&packet) if(!entity) return; // TODO report the error somehow - Handle cast_entity = dynamic_handle_cast(entity); + auto cast_entity = dynamic_handle_cast(entity); if(!cast_entity) return; diff --git a/source/game/replicator.cpp b/source/game/replicator.cpp index eae3e52..d704c50 100644 --- a/source/game/replicator.cpp +++ b/source/game/replicator.cpp @@ -115,7 +115,7 @@ void Replicator::deferred_tick() void Replicator::component_created(const Events::ComponentCreated &event) { - if(Handle zygote = dynamic_handle_cast(event.component)) + if(auto zygote = dynamic_handle_cast(event.component)) { Handle entity = zygote->get_entity(); Handle 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 = dynamic_handle_cast(event.component)) + else if(auto possessed = dynamic_handle_cast(event.component)) { Handle transform = possessed->get_entity()->get_transform(); auto i = lower_bound_member(entities, transform, &ReplicatedEntity::transform); diff --git a/source/game/stage.cpp b/source/game/stage.cpp index d3ca0cb..889000b 100644 --- a/source/game/stage.cpp +++ b/source/game/stage.cpp @@ -22,7 +22,7 @@ Stage::Stage(const string &n, Reflection::Reflector &f, DataFile::Collection &r) { event_observer.observe([this](auto &e){ if(!active_camera) - if(Handle camera = dynamic_handle_cast(e.component)) + if(auto camera = dynamic_handle_cast(e.component)) set_active_camera(camera); }); } diff --git a/source/gameview/renderer.cpp b/source/gameview/renderer.cpp index 8173d1d..45b2e55 100644 --- a/source/gameview/renderer.cpp +++ b/source/gameview/renderer.cpp @@ -119,8 +119,7 @@ void Renderer::create_sequence() void Renderer::component_created(const Game::Events::ComponentCreated &event) { - Game::Handle shape = dynamic_handle_cast(event.component); - if(shape) + if(auto shape = dynamic_handle_cast(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 mesh_source = dynamic_handle_cast(event.component); - Game::Handle dyn_mesh_src = dynamic_handle_cast(event.component); + auto mesh_source = dynamic_handle_cast(event.component); + auto dyn_mesh_src = dynamic_handle_cast(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 light = dynamic_handle_cast(event.component); + auto light = dynamic_handle_cast(event.component); if(light) { RenderedEntity &re = get_rendered_entity(event.component->get_entity()); diff --git a/source/gameview/terrainmeshcreator.cpp b/source/gameview/terrainmeshcreator.cpp index b70cded..d9b151f 100644 --- a/source/gameview/terrainmeshcreator.cpp +++ b/source/gameview/terrainmeshcreator.cpp @@ -46,7 +46,7 @@ TerrainMeshCreator::~TerrainMeshCreator() void TerrainMeshCreator::component_created(const Game::Events::ComponentCreated &event) { - if(Game::Handle terrain = dynamic_handle_cast(event.component)) + if(auto terrain = dynamic_handle_cast(event.component)) { const GL::Technique &tech = stage.get_resources().get(terrain->get_technique_name()); GL::VertexFormat fmt = (GL::VERTEX3, GL::TEXCOORD2, GL::NORMAL3,GL::UNSIGNED_BYTE, -- 2.45.2