Browse Source

Revise entity naming

master
C. J. Howard 3 years ago
parent
commit
a535639e40
7 changed files with 52 additions and 162 deletions
  1. +0
    -39
      src/entity/commands.cpp
  2. +0
    -6
      src/entity/commands.hpp
  3. +0
    -37
      src/entity/components/name.hpp
  4. +25
    -46
      src/game/states/brood.cpp
  5. +2
    -2
      src/game/states/forage.cpp
  6. +23
    -30
      src/game/states/loading.cpp
  7. +2
    -2
      src/game/states/nuptial-flight.cpp

+ 0
- 39
src/entity/commands.cpp View File

@ -24,7 +24,6 @@
#include "entity/components/parent.hpp"
#include "entity/components/celestial-body.hpp"
#include "entity/components/terrain.hpp"
#include "entity/components/name.hpp"
#include <limits>
namespace entity {
@ -165,43 +164,5 @@ void parent(entity::registry& registry, entity::id child, entity::id parent)
registry.assign_or_replace<component::parent>(child, component);
}
void rename(entity::registry& registry, entity::id eid, const std::string& name)
{
registry.assign_or_replace<component::name>(eid, name);
}
entity::id find(entity::registry& registry, const std::string& name)
{
auto view = registry.view<component::name>();
for (auto eid: view)
{
if (view.get(eid).id == name)
return eid;
}
return entt::null;
}
entity::id create(entity::registry& registry)
{
return registry.create();
}
entity::id create(entity::registry& registry, const std::string& name)
{
auto eid = registry.create();
rename(registry, eid, name);
return eid;
}
entity::id find_or_create(entity::registry& registry, const std::string& name)
{
entity::id eid = find(registry, name);
if (eid == entt::null)
eid = create(registry, name);
return eid;
}
} // namespace command
} // namespace entity

+ 0
- 6
src/entity/commands.hpp View File

@ -42,12 +42,6 @@ math::transform get_local_transform(entity::registry& registry, entity::i
math::transform<float> get_world_transform(entity::registry& registry, entity::id eid);
void parent(entity::registry& registry, entity::id child, entity::id parent);
void rename(entity::registry& registry, entity::id eid, const std::string& name);
entity::id find(entity::registry& registry, const std::string& name);
entity::id create(entity::registry& registry);
entity::id create(entity::registry& registry, const std::string& name);
entity::id find_or_create(entity::registry& registry, const std::string& name);
} // namespace command
} // namespace entity

+ 0
- 37
src/entity/components/name.hpp View File

@ -1,37 +0,0 @@
/*
* Copyright (C) 2021 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ENTITY_COMPONENT_NAME_HPP
#define ANTKEEPER_ENTITY_COMPONENT_NAME_HPP
#include <string>
namespace entity {
namespace component {
struct name
{
std::string id;
};
} // namespace component
} // namespace entity
#endif // ANTKEEPER_ENTITY_COMPONENT_NAME_HPP

+ 25
- 46
src/game/states/brood.cpp View File

@ -59,7 +59,6 @@ void enter(game::context* ctx)
auto larva_eid = larva_archetype->create(*ctx->entity_registry);
entity::command::warp_to(*ctx->entity_registry, larva_eid, {0.0f, 0.0f, 0.0f});
entity::command::assign_render_layers(*ctx->entity_registry, larva_eid, 0b1);
entity::command::rename(*ctx->entity_registry, larva_eid, "larva");
}
// Create cocoon
@ -68,7 +67,6 @@ void enter(game::context* ctx)
auto cocoon_eid = cocoon_archetype->create(*ctx->entity_registry);
entity::command::warp_to(*ctx->entity_registry, cocoon_eid, {-50, 0.1935f, 0});
entity::command::assign_render_layers(*ctx->entity_registry, cocoon_eid, 0b1);
entity::command::rename(*ctx->entity_registry, cocoon_eid, "cocoon");
}
// Reset tweening
@ -83,11 +81,11 @@ void exit(game::context* ctx)
void setup_nest(game::context* ctx)
{
// Find or create nest central shaft entity
entity::id shaft_eid = entity::command::find(*ctx->entity_registry, "shaft");
if (shaft_eid == entt::null)
// Create nest central shaft entity
if (!ctx->entities.count("shaft"))
{
shaft_eid = entity::command::create(*ctx->entity_registry, "shaft");
entity::id shaft_eid = ctx->entity_registry->create();
ctx->entities["shaft"] = shaft_eid;
entity::component::transform transform;
transform.local = math::identity_transform<float>;
@ -97,47 +95,27 @@ void setup_nest(game::context* ctx)
ctx->entity_registry->assign<entity::component::transform>(shaft_eid, transform);
}
// Find or create nest lobby chamber entity
entity::id lobby_eid = entity::command::find(*ctx->entity_registry, "lobby");
if (lobby_eid == entt::null)
// Create nest lobby chamber entity
if (!ctx->entities.count("lobby"))
{
lobby_eid = entity::command::create(*ctx->entity_registry, "lobby");
entity::id lobby_eid = ctx->entity_registry->create();
ctx->entities["lobby"] = lobby_eid;
entity::component::chamber chamber;
chamber.shaft_eid = shaft_eid;
chamber.shaft_eid = ctx->entities["shaft"];
chamber.distance = 10.0f;
chamber.previous_chamber_eid = entt::null;
chamber.next_chamber_eid = entt::null;
}
// Find or create nest shaft elevator entity
entity::id elevator_eid = entity::command::find(*ctx->entity_registry, "elevator");
if (elevator_eid == entt::null)
{
elevator_eid = entity::command::create(*ctx->entity_registry, "elevator");
// Create transform component
entity::component::transform transform;
transform.local = math::identity_transform<float>;
transform.world = transform.local;
transform.warp = true;
ctx->entity_registry->assign<entity::component::transform>(elevator_eid, transform);
/*
entity::component::constraint::follow_curve follow_curve;
follow_curve.target_eid = shaft_eid;
follow_curve.offset = 10.0f;
*/
}
}
void setup_ants(game::context* ctx)
{
// Find or create queen ant entity
entity::id queen_eid = entity::command::find(*ctx->entity_registry, "queen");
if (queen_eid == entt::null)
// Create queen ant entity
if (!ctx->entities.count("queen"))
{
queen_eid = entity::command::create(*ctx->entity_registry, "queen");
entity::id queen_eid = ctx->entity_registry->create();
ctx->entities["queen"] = queen_eid;
}
}
@ -147,13 +125,12 @@ void setup_camera(game::context* ctx)
ctx->surface_camera->set_active(false);
ctx->underground_camera->set_active(true);
// Get underground camera entity
entity::id camera_eid = entity::command::find(*ctx->entity_registry, "underground_cam");
if (camera_eid == entt::null)
// Create underground camera entity
if (!ctx->entities.count("underground_cam"))
{
// Create camera target entity
entity::id target_eid = entity::command::create(*ctx->entity_registry, "underground_cam_target");
entity::id target_eid = ctx->entity_registry->create();
ctx->entities["underground_cam_target"] = target_eid;
{
// Transform
entity::component::transform target_transform;
@ -164,7 +141,8 @@ void setup_camera(game::context* ctx)
}
// Create camera entity
camera_eid = entity::command::create(*ctx->entity_registry, "underground_cam");
entity::id camera_eid = ctx->entity_registry->create();
ctx->entities["underground_cam"] = camera_eid;
// Create camera transform component
entity::component::transform transform;
@ -179,7 +157,8 @@ void setup_camera(game::context* ctx)
ctx->entity_registry->assign<entity::component::camera>(camera_eid, camera);
// Create camera 3DOF constraint entity
entity::id three_dof_constraint_eid = entity::command::create(*ctx->entity_registry, "underground_cam_3dof");
entity::id three_dof_constraint_eid = ctx->entity_registry->create();
ctx->entities["underground_cam_3dof"] = three_dof_constraint_eid;
{
// Create 3DOF to constraint
entity::component::constraint::three_dof three_dof;
@ -197,7 +176,7 @@ void setup_camera(game::context* ctx)
}
// Create camera spring to constraint entity
entity::id spring_constraint_eid = entity::command::create(*ctx->entity_registry);
entity::id spring_constraint_eid = ctx->entity_registry->create();
{
// Create spring to constraint
entity::component::constraint::spring_to spring;
@ -229,9 +208,9 @@ void setup_camera(game::context* ctx)
void setup_controls(game::context* ctx)
{
// Get underground camera entity
entity::id camera_eid = entity::command::find(*ctx->entity_registry, "underground_cam");
entity::id target_eid = entity::command::find(*ctx->entity_registry, "underground_cam_target");
entity::id three_dof_eid = entity::command::find(*ctx->entity_registry, "underground_cam_3dof");
entity::id camera_eid = ctx->entities["underground_cam"];
entity::id target_eid = ctx->entities["underground_cam_target"];
entity::id three_dof_eid = ctx->entities["underground_cam_3dof"];
const float dolly_speed = 20.0f;
const float truck_speed = dolly_speed;

+ 2
- 2
src/game/states/forage.cpp View File

@ -39,7 +39,7 @@ void enter(game::context* ctx)
ctx->surface_camera->set_active(true);
// Find planet EID by name
auto planet_eid = entity::command::find(*ctx->entity_registry, "planet");
entity::id planet_eid = ctx->entities["planet"];
// Create biome terrain component
entity::component::terrain biome_terrain;
@ -54,7 +54,7 @@ void enter(game::context* ctx)
ctx->entity_registry->replace<entity::component::terrain>(planet_eid, biome_terrain);
// Create observer
auto observer_eid = ctx->entity_registry->create();
entity::id observer_eid = ctx->entity_registry->create();
{
entity::component::observer observer;
observer.reference_body_eid = planet_eid;

+ 23
- 30
src/game/states/loading.cpp View File

@ -126,7 +126,7 @@ void exit(game::context* ctx)
void load_controls(game::context* ctx)
{
// Toggle fullscreen
if (ctx->controls.find("toggle_fullscreen") == ctx->controls.end())
if (!ctx->controls.count("toggle_fullscreen"))
{
input::control* control = new input::control();
ctx->input_event_router->add_mapping(input::key_mapping(control, nullptr, input::scancode::f11));
@ -151,7 +151,7 @@ void load_controls(game::context* ctx)
);
// Screenshot
if (ctx->controls.find("screenshot") == ctx->controls.end())
if (!ctx->controls.count("screenshot"))
{
input::control* control = new input::control();
ctx->input_event_router->add_mapping(input::key_mapping(control, nullptr, input::scancode::f12));
@ -167,7 +167,7 @@ void load_controls(game::context* ctx)
);
// Menu back
if (ctx->controls.find("menu_back") == ctx->controls.end())
if (!ctx->controls.count("menu_back"))
{
input::control* control = new input::control();
ctx->input_event_router->add_mapping(input::key_mapping(control, nullptr, input::scancode::escape));
@ -180,7 +180,7 @@ void load_controls(game::context* ctx)
);
// Dolly forward
if (ctx->controls.find("dolly_forward") == ctx->controls.end())
if (!ctx->controls.count("dolly_forward"))
{
input::control* control = new input::control();
ctx->input_event_router->add_mapping(input::key_mapping(control, nullptr, input::scancode::w));
@ -189,7 +189,7 @@ void load_controls(game::context* ctx)
}
// Dolly backward
if (ctx->controls.find("dolly_backward") == ctx->controls.end())
if (!ctx->controls.count("dolly_backward"))
{
input::control* control = new input::control();
ctx->input_event_router->add_mapping(input::key_mapping(control, nullptr, input::scancode::s));
@ -198,7 +198,7 @@ void load_controls(game::context* ctx)
}
// Truck left
if (ctx->controls.find("truck_left") == ctx->controls.end())
if (!ctx->controls.count("truck_left"))
{
input::control* control = new input::control();
ctx->input_event_router->add_mapping(input::key_mapping(control, nullptr, input::scancode::a));
@ -207,7 +207,7 @@ void load_controls(game::context* ctx)
}
// Truck right
if (ctx->controls.find("truck_right") == ctx->controls.end())
if (!ctx->controls.count("truck_right"))
{
input::control* control = new input::control();
ctx->input_event_router->add_mapping(input::key_mapping(control, nullptr, input::scancode::d));
@ -216,7 +216,7 @@ void load_controls(game::context* ctx)
}
// Pedestal up
if (ctx->controls.find("pedestal_up") == ctx->controls.end())
if (!ctx->controls.count("pedestal_up"))
{
input::control* control = new input::control();
ctx->input_event_router->add_mapping(input::mouse_wheel_mapping(control, nullptr, input::mouse_wheel_axis::positive_y));
@ -224,7 +224,7 @@ void load_controls(game::context* ctx)
}
// Pedestal down
if (ctx->controls.find("pedestal_down") == ctx->controls.end())
if (!ctx->controls.count("pedestal_down"))
{
input::control* control = new input::control();
ctx->input_event_router->add_mapping(input::mouse_wheel_mapping(control, nullptr, input::mouse_wheel_axis::negative_y));
@ -232,7 +232,7 @@ void load_controls(game::context* ctx)
}
// Move slow
if (ctx->controls.find("move_slow") == ctx->controls.end())
if (!ctx->controls.count("move_slow"))
{
input::control* control = new input::control();
ctx->input_event_router->add_mapping(input::key_mapping(control, nullptr, input::scancode::left_ctrl));
@ -240,7 +240,7 @@ void load_controls(game::context* ctx)
}
// Move fast
if (ctx->controls.find("move_fast") == ctx->controls.end())
if (!ctx->controls.count("move_fast"))
{
input::control* control = new input::control();
ctx->input_event_router->add_mapping(input::key_mapping(control, nullptr, input::scancode::left_shift));
@ -248,7 +248,7 @@ void load_controls(game::context* ctx)
}
// Mouse rotate
if (ctx->controls.find("mouse_rotate") == ctx->controls.end())
if (!ctx->controls.count("mouse_rotate"))
{
input::control* control = new input::control();
ctx->input_event_router->add_mapping(input::mouse_button_mapping(control, nullptr, 3));
@ -257,7 +257,7 @@ void load_controls(game::context* ctx)
}
// Mouse left
if (ctx->controls.find("mouse_left") == ctx->controls.end())
if (!ctx->controls.count("mouse_left"))
{
input::control* control = new input::control();
ctx->input_event_router->add_mapping(input::mouse_motion_mapping(control, nullptr, input::mouse_motion_axis::negative_x));
@ -265,7 +265,7 @@ void load_controls(game::context* ctx)
}
// Mouse right
if (ctx->controls.find("mouse_right") == ctx->controls.end())
if (!ctx->controls.count("mouse_right"))
{
input::control* control = new input::control();
ctx->input_event_router->add_mapping(input::mouse_motion_mapping(control, nullptr, input::mouse_motion_axis::positive_x));
@ -273,7 +273,7 @@ void load_controls(game::context* ctx)
}
// Mouse up
if (ctx->controls.find("mouse_up") == ctx->controls.end())
if (!ctx->controls.count("mouse_up"))
{
input::control* control = new input::control();
ctx->input_event_router->add_mapping(input::mouse_motion_mapping(control, nullptr, input::mouse_motion_axis::negative_y));
@ -281,7 +281,7 @@ void load_controls(game::context* ctx)
}
// Mouse down
if (ctx->controls.find("mouse_down") == ctx->controls.end())
if (!ctx->controls.count("mouse_down"))
{
input::control* control = new input::control();
ctx->input_event_router->add_mapping(input::mouse_motion_mapping(control, nullptr, input::mouse_motion_axis::positive_y));
@ -365,7 +365,8 @@ void cosmogenesis(game::context* ctx)
void heliogenesis(game::context* ctx)
{
// Create solar entity
auto sun_eid = entity::command::create(*ctx->entity_registry, "sun");
entity::id sun_eid = ctx->entity_registry->create();
ctx->entities["sun"] = sun_eid;
// Assign solar celestial body component
entity::component::celestial_body body;
@ -417,7 +418,8 @@ void heliogenesis(game::context* ctx)
void planetogenesis(game::context* ctx)
{
// Create planetary entity
auto planet_eid = entity::command::create(*ctx->entity_registry, "planet");
entity::id planet_eid = ctx->entity_registry->create();
ctx->entities["planet"] = planet_eid;
// Assign planetary celestial body component
entity::component::celestial_body body;
@ -476,7 +478,8 @@ void planetogenesis(game::context* ctx)
void selenogenesis(game::context* ctx)
{
// Create lunar entity
auto moon_eid = entity::command::create(*ctx->entity_registry, "moon");
entity::id moon_eid = ctx->entity_registry->create();
ctx->entities["moon"] = moon_eid;
// Pass moon model to sky pass
ctx->surface_sky_pass->set_moon_model(ctx->resource_manager->load<model>("moon.mdl"));
@ -592,17 +595,7 @@ void extrasolar_heliogenesis(game::context* ctx)
}
void colonigenesis(game::context* ctx)
{
// Create queen entity
auto queen_eid = entity::command::create(*ctx->entity_registry, "queen");
// Create central shaft entity
auto shaft_eid = entity::command::create(*ctx->entity_registry, "shaft");
// Create entrance "lobby" chamber entity
auto lobby_eid = entity::command::create(*ctx->entity_registry, "lobby");
}
{}
} // namespace loading
} // namespace state

+ 2
- 2
src/game/states/nuptial-flight.cpp View File

@ -43,7 +43,7 @@ void enter(game::context* ctx)
ctx->surface_camera->set_active(true);
// Find planet EID by name
auto planet_eid = entity::command::find(*ctx->entity_registry, "planet");
entity::id planet_eid = ctx->entities["planet"];
// Remove terrain component from planet (if any)
if (ctx->entity_registry->has<entity::component::terrain>(planet_eid))
@ -53,7 +53,7 @@ void enter(game::context* ctx)
ctx->surface_sky_pass->set_clouds_model(ctx->resource_manager->load<model>("cloud-plane.mdl"));
// Create observer
auto observer_eid = ctx->entity_registry->create();
entity::id observer_eid = ctx->entity_registry->create();
{
entity::component::observer observer;
observer.reference_body_eid = planet_eid;

Loading…
Cancel
Save