Browse Source

Fix fullscreen toggling

master
C. J. Howard 1 year ago
parent
commit
7e8aeac971
9 changed files with 84 additions and 64 deletions
  1. +0
    -1
      CMakeLists.txt
  2. +5
    -1
      src/application.cpp
  3. +18
    -15
      src/game/bootloader.cpp
  4. +28
    -16
      src/game/entity-commands.cpp
  5. +9
    -7
      src/game/entity-commands.hpp
  6. +0
    -1
      src/game/game-context.hpp
  7. +7
    -7
      src/game/states/play-state.cpp
  8. +9
    -10
      src/game/systems/control-system.cpp
  9. +8
    -6
      src/game/systems/control-system.hpp

+ 0
- 1
CMakeLists.txt View File

@ -14,7 +14,6 @@ find_package(SDL2 REQUIRED COMPONENTS SDL2::SDL2-static SDL2::SDL2main CONFIG)
find_package(OpenAL REQUIRED CONFIG)
find_library(physfs REQUIRED NAMES physfs-static PATHS "${CMAKE_PREFIX_PATH}/lib")
# Determine dependencies
set(STATIC_LIBS
dr_wav

+ 5
- 1
src/application.cpp View File

@ -121,7 +121,7 @@ application::application():
"",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
display_dimensions[0], display_dimensions[1],
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_HIDDEN
SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_HIDDEN
);
if (!sdl_window)
@ -363,10 +363,12 @@ void application::set_fullscreen(bool fullscreen)
{
SDL_SetWindowBordered(sdl_window, SDL_FALSE);
SDL_SetWindowResizable(sdl_window, SDL_FALSE);
SDL_SetWindowFullscreen(sdl_window, SDL_WINDOW_FULLSCREEN_DESKTOP);
resize_window(display_dimensions[0], display_dimensions[1]);
}
else
{
SDL_SetWindowFullscreen(sdl_window, 0);
SDL_SetWindowBordered(sdl_window, SDL_TRUE);
SDL_SetWindowResizable(sdl_window, SDL_TRUE);
}
@ -580,6 +582,8 @@ void application::window_resized()
SDL_GetWindowSize(sdl_window, &window_dimensions[0], &window_dimensions[1]);
SDL_GL_GetDrawableSize(sdl_window, &viewport_dimensions[0], &viewport_dimensions[1]);
rasterizer->context_resized(viewport_dimensions[0], viewport_dimensions[1]);
window_resized_event event;
event.w = window_dimensions[0];
event.h = window_dimensions[1];

+ 18
- 15
src/game/bootloader.cpp View File

@ -362,6 +362,7 @@ void setup_window(game_context* ctx)
fullscreen = false;
else if (config->has("fullscreen"))
fullscreen = (config->get<int>("fullscreen") != 0);
app->set_fullscreen(fullscreen);
logger->pop_task(EXIT_SUCCESS);
@ -380,6 +381,7 @@ void setup_window(game_context* ctx)
if (config->has("windowed_resolution"))
resolution = config->get<int2>("windowed_resolution");
}
app->resize_window(resolution.x, resolution.y);
logger->pop_task(EXIT_SUCCESS);
@ -586,15 +588,6 @@ void setup_scenes(game_context* ctx)
ctx->underworld_ambient_light->set_intensity(0.1f);
ctx->underworld_ambient_light->update_tweens();
// Cloud
ctx->cloud = new model_instance();
ctx->cloud->set_model(ctx->resource_manager->load<model>("cloud.obj"));
ctx->cloud->set_translation({0, 0, 4500});
ctx->cloud->set_scale(float3{1, 1, 1} * 100.0f);
model_instance* flashlight = new model_instance(ctx->resource_manager->load<model>("flashlight.obj"));
model_instance* flashlight_light_cone = new model_instance(ctx->resource_manager->load<model>("flashlight-light-cone.obj"));
const texture_2d* splash_texture = ctx->resource_manager->load<texture_2d>("splash.png");
auto splash_dimensions = splash_texture->get_dimensions();
ctx->splash_billboard_material = new material();
@ -654,7 +647,6 @@ void setup_scenes(game_context* ctx)
ctx->overworld_scene->add_object(ctx->sun_indirect);
ctx->overworld_scene->add_object(ctx->sun_direct);
//ctx->overworld_scene->add_object(ctx->spotlight);
//ctx->overworld_scene->add_object(ctx->cloud);
ctx->overworld_scene->add_object(arrow_billboard);
// Setup underworld scene
@ -666,8 +658,6 @@ void setup_scenes(game_context* ctx)
//ctx->underworld_scene->add_object(ctx->portal_billboard);
//model_instance* larva = new model_instance(ctx->resource_manager->load<model>("larva.obj"));
//ctx->underworld_scene->add_object(larva);
ctx->underworld_scene->add_object(flashlight_light_cone);
ctx->underworld_scene->add_object(flashlight);
// Setup UI scene
ctx->ui_scene = new scene();
@ -808,7 +798,7 @@ void setup_systems(game_context* ctx)
ctx->render_system->set_renderer(ctx->renderer);
// Setup control system
ctx->control_system = new ::control_system();
ctx->control_system = new ::control_system(*ctx->ecs_registry);
ctx->control_system->set_orbit_cam(ctx->orbit_cam);
ctx->control_system->set_viewport(viewport);
ctx->control_system->set_underworld_camera(ctx->underworld_camera);
@ -816,6 +806,7 @@ void setup_systems(game_context* ctx)
//ctx->control_system->set_flashlight(flashlight, flashlight_light_cone);
ctx->control_system->get_adjust_camera_control()->set_activated_callback([ctx](){ ctx->app->set_relative_mouse_mode(true); ctx->tool_system->set_pick(false); });
ctx->control_system->get_adjust_camera_control()->set_deactivated_callback([ctx](){ ctx->app->set_relative_mouse_mode(false); ctx->tool_system->set_pick(true); });
ctx->control_system->set_flashlight(ctx->flashlight_entity);
// Setup UI system
ctx->ui_system = new ui_system(ctx->resource_manager);
@ -846,10 +837,22 @@ void setup_controls(game_context* ctx)
(
[ctx]()
{
ctx->app->set_fullscreen(!ctx->app->is_fullscreen());
bool fullscreen = !ctx->app->is_fullscreen();
ctx->app->set_fullscreen(fullscreen);
if (!fullscreen)
{
int2 resolution = ctx->config->get<int2>("windowed_resolution");
ctx->app->resize_window(resolution.x, resolution.y);
}
ctx->config->set<int>("fullscreen", (fullscreen) ? 1 : 0);
}
);
// Create screenshot control
ctx->screenshot_control = new control();
/*ctx->screenshot_control.set_activated_callback([this]()
@ -1001,7 +1004,7 @@ void setup_callbacks(game_context* ctx)
ctx->camera_system->update(t, dt);
ctx->behavior_system->update(t, dt);
ctx->locomotion_system->update(t, dt);
ctx->control_system->update(dt);
ctx->control_system->update(t, dt);
ctx->tool_system->update(t, dt);
ctx->constraint_system->update(t, dt);

src/entity/entity-commands.cpp → src/game/entity-commands.cpp View File

@ -17,45 +17,57 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#include "entity-commands.hpp"
#include "game/entity-commands.hpp"
#include "game/components/model-component.hpp"
#include "game/components/transform-component.hpp"
#include "game/components/copy-transform-component.hpp"
namespace ecs {
namespace ec {
using namespace ecs;
void move_to(entt::registry& registry, entt::entity entity, const float3& position)
void move_to(entt::registry& registry, entt::entity eid, const float3& position)
{
if (registry.has<transform_component>(entity))
if (registry.has<transform_component>(eid))
{
transform_component& transform = registry.get<transform_component>(entity);
transform_component& transform = registry.get<transform_component>(eid);
transform.transform.translation = position;
}
}
void warp_to(entt::registry& registry, entt::entity entity, const float3& position)
void warp_to(entt::registry& registry, entt::entity eid, const float3& position)
{
if (registry.has<transform_component>(entity))
if (registry.has<transform_component>(eid))
{
transform_component& transform = registry.get<transform_component>(entity);
transform_component& transform = registry.get<transform_component>(eid);
transform.warp = true;
}
}
void assign_render_layers(entt::registry& registry, entt::entity entity, unsigned int layers)
void set_transform(entt::registry& registry, entt::entity eid, const math::transform<float>& transform, bool warp)
{
if (registry.has<model_component>(entity))
if (registry.has<transform_component>(eid))
{
model_component model = registry.get<model_component>(entity);
transform_component& component = registry.get<transform_component>(eid);
component.transform = transform;
component.warp = warp;
}
}
void assign_render_layers(entt::registry& registry, entt::entity eid, unsigned int layers)
{
if (registry.has<model_component>(eid))
{
model_component model = registry.get<model_component>(eid);
model.layers = layers;
registry.replace<model_component>(entity, model);
registry.replace<model_component>(eid, model);
}
}
void bind_transform(entt::registry& registry, entt::entity entity, entt::entity target)
void bind_transform(entt::registry& registry, entt::entity source_eid, entt::entity target_eid)
{
copy_transform_component copy_transform = {target};
registry.assign_or_replace<copy_transform_component>(entity, copy_transform);
copy_transform_component copy_transform = {target_eid};
registry.assign_or_replace<copy_transform_component>(source_eid, copy_transform);
}
} // namespace ecs
} // namespace ec

src/entity/entity-commands.hpp → src/game/entity-commands.hpp View File

@ -21,16 +21,18 @@
#define ANTKEEPER_ECS_ENTITY_COMMANDS_HPP
#include "utility/fundamental-types.hpp"
#include "math/transform-type.hpp"
#include <entt/entt.hpp>
namespace ecs {
void move_to(entt::registry& registry, entt::entity entity, const float3& position);
void warp_to(entt::registry& registry, entt::entity entity, const float3& position);
void assign_render_layers(entt::registry& registry, entt::entity entity, unsigned int layers);
void bind_transform(entt::registry& registry, entt::entity entity, entt::entity target);
namespace ec {
} // namespace ecs
void move_to(entt::registry& registry, entt::entity eid, const float3& position);
void warp_to(entt::registry& registry, entt::entity eid, const float3& position);
void set_transform(entt::registry& registry, entt::entity eid, const math::transform<float>& transform, bool warp = false);
void assign_render_layers(entt::registry& registry, entt::entity eid, unsigned int layers);
void bind_transform(entt::registry& registry, entt::entity source_eid, entt::entity target_eid);
} // namespace ec
#endif // ANTKEEPER_ECS_ENTITY_COMMANDS_HPP

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

@ -163,7 +163,6 @@ struct game_context
directional_light* sun_direct;
point_light* subterrain_light;
ambient_light* underworld_ambient_light;
model_instance* cloud;
spotlight* spotlight;
billboard* splash_billboard;

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

@ -31,7 +31,7 @@
#include "game/components/terrain-component.hpp"
#include "game/components/tool-component.hpp"
#include "game/components/transform-component.hpp"
#include "entity/entity-commands.hpp"
#include "game/entity-commands.hpp"
#include "game/game-context.hpp"
#include "game/states/game-states.hpp"
#include "math/math.hpp"
@ -70,11 +70,11 @@ void play_state_enter(game_context* ctx)
ecs::archetype* flashlight_light_cone_archetype = resource_manager->load<ecs::archetype>("flashlight-light-cone.ent");
// Create flashlight + light cone compund entity
auto flashlight = flashlight_archetype->create(ecs_registry);
flashlight_archetype->assign(ecs_registry, ctx->flashlight_entity);
auto flashlight_light_cone = flashlight_light_cone_archetype->create(ecs_registry);
ecs::bind_transform(ecs_registry, flashlight_light_cone, flashlight);
ecs::assign_render_layers(ecs_registry, flashlight, 2);
ecs::assign_render_layers(ecs_registry, flashlight_light_cone, 2);
ec::bind_transform(ecs_registry, flashlight_light_cone, ctx->flashlight_entity);
ec::assign_render_layers(ecs_registry, ctx->flashlight_entity, 2);
ec::assign_render_layers(ecs_registry, flashlight_light_cone, 2);
ecs::placement_component placement;
@ -232,7 +232,7 @@ void play_state_enter(game_context* ctx)
// Place larva in chamber
{
auto larva = larva_archetype->create(ecs_registry);
ecs::assign_render_layers(ecs_registry, larva, 1);
ec::assign_render_layers(ecs_registry, larva, 1);
//ecs::warp_to(ecs_registry, larva, {0, -20, 0});
//auto& transform = ecs_registry.get<ecs::transform_component>(larva_entity);
//transform.transform = math::identity_transform<float>;
@ -241,7 +241,7 @@ void play_state_enter(game_context* ctx)
}
control_system* control_system = ctx->control_system;
control_system->update(0.0f);
control_system->update(0.0, 0.0);
control_system->set_nest(nest);
orbit_cam->update(0.0f);

+ 9
- 10
src/game/systems/control-system.cpp View File

@ -25,13 +25,14 @@
#include "animation/ease.hpp"
#include "nest.hpp"
#include "math/math.hpp"
#include "game/entity-commands.hpp"
control_system::control_system():
control_system::control_system(entt::registry& registry):
entity_system(registry),
timestep(0.0f),
zoom(0.0f),
tool(nullptr),
flashlight(nullptr),
flashlight_light_cone(nullptr),
flashlight_eid(entt::null),
underworld_camera(nullptr)
{
control_set.add_control(&move_forward_control);
@ -81,7 +82,7 @@ control_system::control_system():
flashlight_turns_f = 0.0f;
}
void control_system::update(float dt)
void control_system::update(double t, double dt)
{
this->timestep = dt;
@ -224,7 +225,7 @@ void control_system::update(float dt)
flashlight_turns_f = (mouse_angle) / math::two_pi<float>;
flashlight_turns = flashlight_turns_i - flashlight_turns_f;
if (flashlight && nest)
if (flashlight_eid != entt::null && nest)
{
math::transform<float> flashlight_transform = math::identity_transform<float>;
@ -233,8 +234,7 @@ void control_system::update(float dt)
flashlight_transform.translation = {0.0f, -flashlight_depth, 0.0f};
flashlight_transform.rotation = math::angle_axis(-flashlight_turns * math::two_pi<float> + math::half_pi<float>, {0, 1, 0});
flashlight->set_transform(flashlight_transform);
flashlight_light_cone->set_transform(flashlight_transform);
ec::set_transform(registry, flashlight_eid, flashlight_transform, false);
if (underworld_camera)
{
@ -261,10 +261,9 @@ void control_system::set_tool(model_instance* tool)
this->tool = tool;
}
void control_system::set_flashlight(model_instance* flashlight, model_instance* light_cone)
void control_system::set_flashlight(entt::entity eid)
{
this->flashlight = flashlight;
this->flashlight_light_cone = light_cone;
flashlight_eid = eid;
}
void control_system::set_viewport(const float4& viewport)

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

@ -20,6 +20,7 @@
#ifndef ANTKEEPER_CONTROL_SYSTEM_HPP
#define ANTKEEPER_CONTROL_SYSTEM_HPP
#include "game/systems/entity-system.hpp"
#include "event/event-handler.hpp"
#include "event/input-events.hpp"
#include "input/control.hpp"
@ -32,17 +33,19 @@ class nest;
class camera;
class control_system:
public entity_system,
public event_handler<mouse_moved_event>
{
public:
control_system();
void update(float dt);
control_system(entt::registry& registry);
virtual void update(double t, double dt);
void set_orbit_cam(orbit_cam* orbit_cam);
void set_nest(::nest* nest);
void set_tool(model_instance* tool);
void set_flashlight(model_instance* flashlight, model_instance* light_cone);
void set_flashlight(entt::entity eid);
void set_viewport(const float4& viewport);
void set_underworld_camera(::camera* camera);
@ -105,8 +108,7 @@ private:
float2 mouse_position;
float4 viewport;
model_instance* flashlight;
model_instance* flashlight_light_cone;
entt::entity flashlight_eid;
camera* underworld_camera;
float mouse_angle;

Loading…
Cancel
Save