diff --git a/CMakeLists.txt b/CMakeLists.txt index c4c0392..55db635 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/src/application.cpp b/src/application.cpp index 42ff21a..fa6b5d3 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -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]; diff --git a/src/game/bootloader.cpp b/src/game/bootloader.cpp index 52433d2..8cee67e 100644 --- a/src/game/bootloader.cpp +++ b/src/game/bootloader.cpp @@ -362,6 +362,7 @@ void setup_window(game_context* ctx) fullscreen = false; else if (config->has("fullscreen")) fullscreen = (config->get("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("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("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("flashlight.obj")); - model_instance* flashlight_light_cone = new model_instance(ctx->resource_manager->load("flashlight-light-cone.obj")); - const texture_2d* splash_texture = ctx->resource_manager->load("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("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("windowed_resolution"); + ctx->app->resize_window(resolution.x, resolution.y); + } + + ctx->config->set("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); diff --git a/src/entity/entity-commands.cpp b/src/game/entity-commands.cpp similarity index 53% rename from src/entity/entity-commands.cpp rename to src/game/entity-commands.cpp index fe69598..7c112f1 100644 --- a/src/entity/entity-commands.cpp +++ b/src/game/entity-commands.cpp @@ -17,45 +17,57 @@ * along with Antkeeper source code. If not, see . */ -#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(entity)) + if (registry.has(eid)) { - transform_component& transform = registry.get(entity); + transform_component& transform = registry.get(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(entity)) + if (registry.has(eid)) { - transform_component& transform = registry.get(entity); + transform_component& transform = registry.get(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& transform, bool warp) { - if (registry.has(entity)) + if (registry.has(eid)) { - model_component model = registry.get(entity); + transform_component& component = registry.get(eid); + component.transform = transform; + component.warp = warp; + } +} + +void assign_render_layers(entt::registry& registry, entt::entity eid, unsigned int layers) +{ + if (registry.has(eid)) + { + model_component model = registry.get(eid); model.layers = layers; - registry.replace(entity, model); + registry.replace(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(entity, copy_transform); + copy_transform_component copy_transform = {target_eid}; + registry.assign_or_replace(source_eid, copy_transform); } -} // namespace ecs +} // namespace ec diff --git a/src/entity/entity-commands.hpp b/src/game/entity-commands.hpp similarity index 68% rename from src/entity/entity-commands.hpp rename to src/game/entity-commands.hpp index 7240f46..2faf99a 100644 --- a/src/entity/entity-commands.hpp +++ b/src/game/entity-commands.hpp @@ -21,16 +21,18 @@ #define ANTKEEPER_ECS_ENTITY_COMMANDS_HPP #include "utility/fundamental-types.hpp" +#include "math/transform-type.hpp" #include -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& 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 diff --git a/src/game/game-context.hpp b/src/game/game-context.hpp index 577d828..7858a6a 100644 --- a/src/game/game-context.hpp +++ b/src/game/game-context.hpp @@ -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; diff --git a/src/game/states/play-state.cpp b/src/game/states/play-state.cpp index a1bb956..7cecf25 100644 --- a/src/game/states/play-state.cpp +++ b/src/game/states/play-state.cpp @@ -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("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(larva_entity); //transform.transform = math::identity_transform; @@ -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); diff --git a/src/game/systems/control-system.cpp b/src/game/systems/control-system.cpp index 196623e..21699cb 100644 --- a/src/game/systems/control-system.cpp +++ b/src/game/systems/control-system.cpp @@ -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; flashlight_turns = flashlight_turns_i - flashlight_turns_f; - if (flashlight && nest) + if (flashlight_eid != entt::null && nest) { math::transform flashlight_transform = math::identity_transform; @@ -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 + math::half_pi, {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) diff --git a/src/game/systems/control-system.hpp b/src/game/systems/control-system.hpp index 1b97113..28fb8cb 100644 --- a/src/game/systems/control-system.hpp +++ b/src/game/systems/control-system.hpp @@ -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 { 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;