diff --git a/CMakeLists.txt b/CMakeLists.txt index d4aa351..af368e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,6 @@ cmake_minimum_required(VERSION 3.7) + option(VERSION_STRING "Project version string" "0.0.0") project(antkeeper VERSION ${VERSION_STRING} LANGUAGES CXX) diff --git a/src/application.cpp b/src/application.cpp index 88f4a64..f1848f9 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -630,7 +630,9 @@ void application::translate_sdl_events() { input::gamepad_axis axis = input::sdl_axis_table[sdl_event.caxis.axis]; float value = sdl_event.caxis.value; - value /= (value < 0.0f) ? 32768.0f : 32767.0f; + static const float min = static_cast(std::numeric_limits::min()); + static const float max = static_cast(std::numeric_limits::max()); + value /= (value < 0.0f) ? -min : max; it->second->move(axis, value); } } diff --git a/src/entity/systems/tracking.cpp b/src/entity/systems/tracking.cpp deleted file mode 100644 index 149f043..0000000 --- a/src/entity/systems/tracking.cpp +++ /dev/null @@ -1,161 +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 . - */ - -#include "tracking.hpp" -#include "entity/components/transform.hpp" -#include "entity/components/marker.hpp" -#include "event/event-dispatcher.hpp" -#include "resources/resource-manager.hpp" -#include "scene/collection.hpp" -#include "scene/model-instance.hpp" -#include "math/math.hpp" -#include "renderer/material.hpp" -#include "renderer/model.hpp" -#include "utility/fundamental-types.hpp" -#include "entity/commands.hpp" - -namespace entity { -namespace system { - -tracking::tracking(entity::registry& registry, ::event_dispatcher* event_dispatcher, ::resource_manager* resource_manager): - updatable(registry), - event_dispatcher(event_dispatcher), - resource_manager(resource_manager), - scene_collection(nullptr) -{ - registry.on_construct().connect<&tracking::on_component_construct>(this); - registry.on_destroy().connect<&tracking::on_component_destroy>(this); - - // Load paint ball model - paint_ball_model = resource_manager->load("paint-ball.mdl"); - - // Load tracker model - tracker_model = resource_manager->load("tracker.mdl"); - - // Load paint ball materials - paint_ball_materials = new material*[7]; - paint_ball_materials[0] = resource_manager->load("paint-ball-yellow.mtl"); - paint_ball_materials[1] = resource_manager->load("paint-ball-green.mtl"); - paint_ball_materials[2] = resource_manager->load("paint-ball-blue.mtl"); - paint_ball_materials[3] = resource_manager->load("paint-ball-purple.mtl"); - paint_ball_materials[4] = resource_manager->load("paint-ball-pink.mtl"); - paint_ball_materials[5] = resource_manager->load("paint-ball-red.mtl"); - paint_ball_materials[6] = resource_manager->load("paint-ball-orange.mtl"); - - event_dispatcher->subscribe(this); - event_dispatcher->subscribe(this); -} - -tracking::~tracking() -{ - event_dispatcher->unsubscribe(this); - event_dispatcher->unsubscribe(this); - - for (auto it = trackers.begin(); it != trackers.end(); ++it) - { - delete it->second; - } - - delete[] paint_ball_materials; -} - - -void tracking::update(double t, double dt) -{ - for (auto it = trackers.begin(); it != trackers.end(); ++it) - { - const component::transform& transform = registry.get(it->first); - - // Project world coordinates to screen coordinates - - // Update billboard position - it->second->set_translation(transform.world.translation); - if (transform.warp) - { - it->second->update_tweens(); - } - } -} - -void tracking::set_scene(scene::collection* collection) -{ - this->scene_collection = collection; -} - -void tracking::on_component_construct(entity::registry& registry, entity::id entity_id, component::trackable& component) -{ - -} - -void tracking::on_component_destroy(entity::registry& registry, entity::id entity_id) -{ - if (auto it = trackers.find(entity_id); it != trackers.end()) - { - // Remove model instance from all layers - /* - for (std::size_t i = 0; i < layers.size(); ++i) - { - layers[i]->remove_object(it->second); - } - */ - - delete it->second; - trackers.erase(it); - } -} - -void tracking::handle_event(const tool_pressed_event& event) -{ - if (registry.has(event.entity_id)) - { - math::transform transform = command::get_world_transform(registry, event.entity_id); - - int marker_index = registry.get(event.entity_id).color; - - if (marker_index > 0) - { - const float tracker_scale = 1.0f; - - // Create tracker model instance - scene::model_instance* instance = new scene::model_instance(); - instance->set_model(tracker_model); - instance->set_translation(transform.translation); - instance->set_scale(float3{tracker_scale, tracker_scale, tracker_scale}); - - // Set tracker paint ball material - const model_group* paint_ball_model_group = tracker_model->get_group("paint-ball"); - if (paint_ball_model_group != nullptr) - { - instance->set_material(paint_ball_model_group->get_index(), paint_ball_materials[marker_index - 1]); - } - - instance->update_tweens(); - - scene_collection->add_object(instance); - } - } -} - -void tracking::handle_event(const tool_released_event& event) -{ - -} - -} // namespace system -} // namespace entity diff --git a/src/entity/systems/tracking.hpp b/src/entity/systems/tracking.hpp deleted file mode 100644 index 7da9f61..0000000 --- a/src/entity/systems/tracking.hpp +++ /dev/null @@ -1,70 +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 . - */ - -#ifndef ANTKEEPER_ENTITY_SYSTEM_TRACKING_HPP -#define ANTKEEPER_ENTITY_SYSTEM_TRACKING_HPP - -#include "entity/systems/updatable.hpp" -#include "entity/components/trackable.hpp" -#include "entity/id.hpp" -#include "event/event-handler.hpp" -#include "game/events/tool-events.hpp" -#include -#include "scene/collection.hpp" -#include "scene/model-instance.hpp" - -class material; -class event_dispatcher; -class resource_manager; -class model; - -namespace entity { -namespace system { - -class tracking: public updatable, - public event_handler, - public event_handler -{ -public: - tracking(entity::registry& registry, event_dispatcher* event_dispatcher, resource_manager* resource_manager); - virtual ~tracking(); - virtual void update(double t, double dt); - - void set_scene(scene::collection* collection); - void set_viewport(const float4& viewport); - -private: - void on_component_construct(entity::registry& registry, entity::id entity_id, entity::component::trackable& component); - void on_component_destroy(entity::registry& registry, entity::id entity_id); - virtual void handle_event(const tool_pressed_event& event); - virtual void handle_event(const tool_released_event& event); - - event_dispatcher* event_dispatcher; - resource_manager* resource_manager; - scene::collection* scene_collection; - model* tracker_model; - model* paint_ball_model; - material** paint_ball_materials; - std::unordered_map trackers; -}; - -} // namespace system -} // namespace entity - -#endif // ANTKEEPER_ENTITY_SYSTEM_TRACKING_HPP diff --git a/src/game/bootloader.cpp b/src/game/bootloader.cpp index 346e0d3..760a63c 100644 --- a/src/game/bootloader.cpp +++ b/src/game/bootloader.cpp @@ -67,14 +67,12 @@ #include "entity/systems/ui.hpp" #include "entity/systems/vegetation.hpp" #include "entity/systems/spatial.hpp" -#include "entity/systems/tracking.hpp" #include "entity/systems/painting.hpp" #include "entity/systems/astronomy.hpp" #include "entity/systems/blackbody.hpp" #include "entity/systems/atmosphere.hpp" #include "entity/systems/orbit.hpp" #include "entity/systems/proteome.hpp" -#include "entity/components/marker.hpp" #include "entity/commands.hpp" #include "utility/paths.hpp" #include "event/event-dispatcher.hpp" @@ -249,7 +247,7 @@ void setup_resources(game::context* ctx) ctx->config_path = get_config_path(application_name); ctx->mods_path = ctx->config_path + "mods/"; ctx->saves_path = ctx->config_path + "saves/"; - ctx->screenshots_path = ctx->config_path + "screenshots/"; + ctx->screenshots_path = ctx->config_path + "gallery/"; ctx->controls_path = ctx->config_path + "controls/"; // Log resource paths @@ -337,8 +335,7 @@ void setup_resources(game::context* ctx) // Mount data package ctx->resource_manager->mount(ctx->data_package_path); - - + // Include resource search paths in order of priority ctx->resource_manager->include("/shaders/"); ctx->resource_manager->include("/models/"); @@ -607,17 +604,6 @@ void setup_rendering(game::context* ctx) ctx->billboard_vao->bind_attribute(VERTEX_BARYCENTRIC_LOCATION, *ctx->billboard_vbo, 3, gl::vertex_attribute_type::float_32, billboard_vertex_stride, sizeof(float) * 5); } - // Load marker albedo textures - ctx->marker_albedo_textures = new gl::texture_2d*[8]; - ctx->marker_albedo_textures[0] = ctx->resource_manager->load("marker-clear-albedo.tex"); - ctx->marker_albedo_textures[1] = ctx->resource_manager->load("marker-yellow-albedo.tex"); - ctx->marker_albedo_textures[2] = ctx->resource_manager->load("marker-green-albedo.tex"); - ctx->marker_albedo_textures[3] = ctx->resource_manager->load("marker-blue-albedo.tex"); - ctx->marker_albedo_textures[4] = ctx->resource_manager->load("marker-purple-albedo.tex"); - ctx->marker_albedo_textures[5] = ctx->resource_manager->load("marker-pink-albedo.tex"); - ctx->marker_albedo_textures[6] = ctx->resource_manager->load("marker-red-albedo.tex"); - ctx->marker_albedo_textures[7] = ctx->resource_manager->load("marker-orange-albedo.tex"); - // Create renderer ctx->renderer = new renderer(); ctx->renderer->set_billboard_vao(ctx->billboard_vao); @@ -850,10 +836,6 @@ void setup_systems(game::context* ctx) // Setup constraint system ctx->constraint_system = new entity::system::constraint(*ctx->entity_registry); - // Setup tracking system - ctx->tracking_system = new entity::system::tracking(*ctx->entity_registry, event_dispatcher, ctx->resource_manager); - ctx->tracking_system->set_scene(ctx->surface_scene); - // Setup painting system ctx->painting_system = new entity::system::painting(*ctx->entity_registry, event_dispatcher, ctx->resource_manager); ctx->painting_system->set_scene(ctx->surface_scene); @@ -917,88 +899,6 @@ void setup_controls(game::context* ctx) // Setup input listener ctx->input_listener = new input::listener(); ctx->input_listener->set_event_dispatcher(event_dispatcher); - - /* - // Add menu control mappings - - ctx->input_event_router->add_mapping(input::gamepad_button_mapping(ctx->menu_back_control, nullptr, input::gamepad_button::b)); - //ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_tool_menu_control(), nullptr, input::scancode::left_shift)); - ctx->input_event_router->add_mapping(input::gamepad_button_mapping(ctx->control_system->get_tool_menu_control(), nullptr, input::gamepad_button::x)); - ctx->input_event_router->add_mapping(input::key_mapping(ctx->menu_select_control, nullptr, input::scancode::enter)); - ctx->input_event_router->add_mapping(input::key_mapping(ctx->menu_select_control, nullptr, input::scancode::space)); - - - - ctx->input_event_router->add_mapping(input::key_mapping(ctx->control_system->get_toggle_view_control(), nullptr, input::scancode::tab)); - ctx->control_system->get_toggle_view_control()->set_activated_callback( - [ctx]() - { - if (ctx->active_scene == ctx->surface_scene) - { - ctx->active_scene = ctx->underground_scene; - ctx->radial_transition_inner->transition(0.5f, false, ease::in_quad); - - auto switch_cameras = [ctx]() - { - ctx->surface_camera->set_active(false); - ctx->underground_camera->set_active(true); - ctx->fade_transition->transition(0.25f, true, ease::out_quad); - }; - - float t = ctx->timeline->get_position(); - ctx->timeline->add_cue({t + 0.5f, switch_cameras}); - } - else - { - ctx->active_scene = ctx->surface_scene; - ctx->fade_transition->transition(0.25f, false, ease::out_quad); - - auto switch_cameras = [ctx]() - { - ctx->surface_camera->set_active(true); - ctx->underground_camera->set_active(false); - ctx->radial_transition_inner->transition(0.5f, true, ease::out_quad); - }; - - float t = ctx->timeline->get_position(); - ctx->timeline->add_cue({t + 0.25f, switch_cameras}); - } - }); - - float time_scale = ctx->config->get("time_scale"); - ctx->control_system->get_fast_forward_control()->set_activated_callback - ( - [ctx, time_scale]() - { - ctx->orbit_system->set_time_scale(time_scale * 100.0f / seconds_per_day); - ctx->astronomy_system->set_time_scale(time_scale * 100.0f / seconds_per_day); - } - ); - ctx->control_system->get_fast_forward_control()->set_deactivated_callback - ( - [ctx, time_scale]() - { - ctx->orbit_system->set_time_scale(time_scale / seconds_per_day); - ctx->astronomy_system->set_time_scale(time_scale / seconds_per_day); - } - ); - ctx->control_system->get_rewind_control()->set_activated_callback - ( - [ctx, time_scale]() - { - ctx->orbit_system->set_time_scale(time_scale * -100.0f / seconds_per_day); - ctx->astronomy_system->set_time_scale(time_scale * -100.0f / seconds_per_day); - } - ); - ctx->control_system->get_rewind_control()->set_deactivated_callback - ( - [ctx, time_scale]() - { - ctx->orbit_system->set_time_scale(time_scale / seconds_per_day); - ctx->astronomy_system->set_time_scale(time_scale / seconds_per_day); - } - ); - */ } void setup_cli(game::context* ctx) @@ -1068,7 +968,6 @@ void setup_callbacks(game::context* ctx) ctx->astronomy_system->update(t, dt); ctx->spatial_system->update(t, dt); ctx->constraint_system->update(t, dt); - ctx->tracking_system->update(t, dt); ctx->painting_system->update(t, dt); ctx->proteome_system->update(t, dt); diff --git a/src/game/context.hpp b/src/game/context.hpp index e32637a..c31f4cf 100644 --- a/src/game/context.hpp +++ b/src/game/context.hpp @@ -81,7 +81,6 @@ namespace entity class vegetation; class ui; class spatial; - class tracking; class painting; class astronomy; class blackbody; @@ -157,7 +156,6 @@ struct context gl::vertex_array* billboard_vao; material* fallback_material; material* splash_billboard_material; - gl::texture_2d** marker_albedo_textures; // Compositing clear_pass* ui_clear_pass; @@ -241,7 +239,6 @@ struct context entity::system::ui* ui_system; entity::system::vegetation* vegetation_system; entity::system::spatial* spatial_system; - entity::system::tracking* tracking_system; entity::system::painting* painting_system; entity::system::blackbody* blackbody_system; entity::system::atmosphere* atmosphere_system; diff --git a/src/entity/components/marker.hpp b/src/game/save.cpp similarity index 75% rename from src/entity/components/marker.hpp rename to src/game/save.cpp index bcf8a00..269a282 100644 --- a/src/entity/components/marker.hpp +++ b/src/game/save.cpp @@ -17,18 +17,14 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_ENTITY_COMPONENT_MARKER_HPP -#define ANTKEEPER_ENTITY_COMPONENT_MARKER_HPP +#include "game/save.hpp" +#include "application.hpp" -namespace entity { -namespace component { +namespace game { -struct marker +bool save(game::context* ctx) { - int color; -}; + return false; +} -} // namespace component -} // namespace entity - -#endif // ANTKEEPER_ENTITY_COMPONENT_MARKER_HPP +} // namespace game diff --git a/src/game/save.hpp b/src/game/save.hpp new file mode 100644 index 0000000..bc7f227 --- /dev/null +++ b/src/game/save.hpp @@ -0,0 +1,31 @@ +/* + * 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 . + */ + +#ifndef ANTKEEPER_GAME_SAVE_HPP +#define ANTKEEPER_GAME_SAVE_HPP + +#include "game/context.hpp" + +namespace game { + +bool save(game::context* ctx); + +} // namespace game + +#endif // ANTKEEPER_GAME_SAVE_HPP