Browse Source

Add container tool

master
C. J. Howard 4 years ago
parent
commit
280c3f1c0c
6 changed files with 36 additions and 1 deletions
  1. +14
    -1
      src/application.cpp
  2. +9
    -0
      src/game/bootloader.cpp
  3. +1
    -0
      src/game/game-context.hpp
  4. +3
    -0
      src/game/states/play-state.cpp
  5. +1
    -0
      src/game/systems/control-system.cpp
  6. +8
    -0
      src/game/systems/control-system.hpp

+ 14
- 1
src/application.cpp View File

@ -38,6 +38,8 @@
#include <utility>
#include <thread>
#include <stb/stb_image_write.h>
#include <iostream>
#include <iomanip>
application::application():
closed(false),
@ -440,6 +442,17 @@ void application::update(double t, double dt)
{
update_callback(t, dt);
}
/*
static int frame = 0;
if (frame % 60 == 0)
{
std::cout << std::fixed;
std::cout << std::setprecision(2);
std::cout << performance_sampler->mean_frame_duration() * 1000.0 << "\n";
}
++frame;
*/
}
void application::render(double alpha)
@ -447,7 +460,7 @@ void application::render(double alpha)
/*
std::cout << std::fixed;
std::cout << std::setprecision(2);
std::cout << performance_sampler.mean_frame_duration() * 1000.0 << std::endl;
std::cout << performance_sampler->mean_frame_duration() * 1000.0 << std::endl;
*/
if (render_callback)

+ 9
- 0
src/game/bootloader.cpp View File

@ -769,6 +769,7 @@ void setup_entities(game_context* ctx)
ctx->forceps_entity = ctx->ecs_registry->create();
ctx->lens_entity = ctx->ecs_registry->create();
ctx->marker_entity = ctx->ecs_registry->create();
ctx->container_entity = ctx->ecs_registry->create();
ctx->focal_point_entity = ctx->ecs_registry->create();
}
@ -1013,6 +1014,7 @@ void setup_controls(game_context* ctx)
ctx->input_event_router->add_mapping(key_mapping(ctx->control_system->get_equip_brush_control(), nullptr, scancode::two));
ctx->input_event_router->add_mapping(key_mapping(ctx->control_system->get_equip_lens_control(), nullptr, scancode::three));
ctx->input_event_router->add_mapping(key_mapping(ctx->control_system->get_equip_marker_control(), nullptr, scancode::four));
ctx->input_event_router->add_mapping(key_mapping(ctx->control_system->get_equip_container_control(), nullptr, scancode::five));
ctx->input_event_router->add_mapping(mouse_button_mapping(ctx->control_system->get_use_tool_control(), nullptr, 1));
ctx->control_system->get_use_tool_control()->set_activated_callback
@ -1058,6 +1060,13 @@ void setup_controls(game_context* ctx)
ctx->tool_system->set_active_tool(ctx->marker_entity);
}
);
ctx->control_system->get_equip_container_control()->set_activated_callback
(
[ctx]()
{
ctx->tool_system->set_active_tool(ctx->container_entity);
}
);
event_dispatcher->subscribe<mouse_moved_event>(ctx->control_system);
event_dispatcher->subscribe<mouse_moved_event>(ctx->camera_system);

+ 1
- 0
src/game/game-context.hpp View File

@ -213,6 +213,7 @@ struct game_context
entt::entity forceps_entity;
entt::entity lens_entity;
entt::entity marker_entity;
entt::entity container_entity;
entt::entity focal_point_entity;
// Systems

+ 3
- 0
src/game/states/play-state.cpp View File

@ -81,6 +81,7 @@ void play_state_enter(game_context* ctx)
ecs::archetype* lens_archetype = resource_manager->load<ecs::archetype>("lens.ent");
ecs::archetype* brush_archetype = resource_manager->load<ecs::archetype>("brush.ent");
ecs::archetype* marker_archetype = resource_manager->load<ecs::archetype>("marker.ent");
ecs::archetype* container_archetype = resource_manager->load<ecs::archetype>("container.ent");
ecs::archetype* larva_archetype = resource_manager->load<ecs::archetype>("larva.ent");
ecs::archetype* pebble_archetype = resource_manager->load<ecs::archetype>("pebble.ent");
ecs::archetype* flashlight_archetype = resource_manager->load<ecs::archetype>("flashlight.ent");
@ -92,6 +93,7 @@ void play_state_enter(game_context* ctx)
lens_archetype->assign(ecs_registry, ctx->lens_entity);
brush_archetype->assign(ecs_registry, ctx->brush_entity);
marker_archetype->assign(ecs_registry, ctx->marker_entity);
container_archetype->assign(ecs_registry, ctx->container_entity);
// Create flashlight and light cone, set light cone parent to flashlight, and move both to underworld scene
flashlight_archetype->assign(ecs_registry, ctx->flashlight_entity);
@ -118,6 +120,7 @@ void play_state_enter(game_context* ctx)
ec::assign_render_layers(ecs_registry, ctx->brush_entity, 0);
ec::assign_render_layers(ecs_registry, ctx->lens_entity, 0);
ec::assign_render_layers(ecs_registry, ctx->marker_entity, 0);
ec::assign_render_layers(ecs_registry, ctx->container_entity, 0);
// Activate lens tool
ctx->tool_system->set_active_tool(ctx->lens_entity);

+ 1
- 0
src/game/systems/control-system.cpp View File

@ -55,6 +55,7 @@ control_system::control_system(entt::registry& registry):
control_set.add_control(&equip_brush_control);
control_set.add_control(&equip_forceps_control);
control_set.add_control(&equip_marker_control);
control_set.add_control(&equip_container_control);
control_set.add_control(&use_tool_control);
// Set deadzone at 15% for all controls

+ 8
- 0
src/game/systems/control-system.hpp View File

@ -75,6 +75,7 @@ public:
control* get_equip_brush_control();
control* get_equip_forceps_control();
control* get_equip_marker_control();
control* get_equip_container_control();
control* get_use_tool_control();
private:
@ -101,6 +102,7 @@ private:
control equip_brush_control;
control equip_forceps_control;
control equip_marker_control;
control equip_container_control;
control use_tool_control;
float zoom_speed;
@ -236,6 +238,12 @@ inline control* control_system::get_equip_marker_control()
return &equip_marker_control;
}
inline control* control_system::get_equip_container_control()
{
return &equip_container_control;
}
inline control* control_system::get_use_tool_control()
{
return &use_tool_control;

Loading…
Cancel
Save