Browse Source

Get spiral navigation working and statically link to SDL2 and OpenAL

master
C. J. Howard 4 years ago
parent
commit
b8ea878292
9 changed files with 134 additions and 48 deletions
  1. +18
    -18
      CMakeLists.txt
  2. +22
    -19
      src/application.cpp
  3. +0
    -1
      src/application.hpp
  4. +6
    -1
      src/nest.cpp
  5. +2
    -0
      src/nest.hpp
  6. +0
    -1
      src/scene/scene-object.cpp
  7. +9
    -7
      src/state/play-state.cpp
  8. +64
    -1
      src/systems/control-system.cpp
  9. +13
    -0
      src/systems/control-system.hpp

+ 18
- 18
CMakeLists.txt View File

@ -10,7 +10,7 @@ if(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3")
elseif(MSVC) elseif(MSVC)
set(CMAKE_CXX_FLAGS "/W3 /MP /MD")
set(CMAKE_CXX_FLAGS "/W3 /MP /MT")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS}") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} /Ox") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} /Ox")
endif() endif()
@ -25,7 +25,6 @@ find_package(OpenGL REQUIRED)
find_package(SDL2 REQUIRED COMPONENTS SDL2::SDL2-static SDL2::SDL2main CONFIG) find_package(SDL2 REQUIRED COMPONENTS SDL2::SDL2-static SDL2::SDL2main CONFIG)
find_package(OpenAL REQUIRED CONFIG) find_package(OpenAL REQUIRED CONFIG)
# Determine dependencies # Determine dependencies
set(STATIC_LIBS set(STATIC_LIBS
vmq vmq
@ -33,11 +32,11 @@ set(STATIC_LIBS
stb stb
glad glad
EnTT EnTT
SDL2::SDL2main)
set(SHARED_LIBS
${OPENGL_gl_LIBRARY}
SDL2::SDL2
SDL2::SDL2-static
SDL2::SDL2main
OpenAL::OpenAL) OpenAL::OpenAL)
set(SHARED_LIBS
${OPENGL_gl_LIBRARY})
# Generate configuration header file # Generate configuration header file
configure_file(${PROJECT_SOURCE_DIR}/src/configuration.hpp.in configure_file(${PROJECT_SOURCE_DIR}/src/configuration.hpp.in
@ -84,6 +83,7 @@ endif()
# Set link flags to show console window on debug builds and hide it on release builds # Set link flags to show console window on debug builds and hide it on release builds
if(MSVC) if(MSVC)
#set_target_properties(${EXECUTABLE_TARGET} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:libvcruntime.lib")
set_target_properties(${EXECUTABLE_TARGET} PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE") set_target_properties(${EXECUTABLE_TARGET} PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE")
set_target_properties(${EXECUTABLE_TARGET} PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS /ENTRY:\"mainCRTStartup\"") set_target_properties(${EXECUTABLE_TARGET} PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS /ENTRY:\"mainCRTStartup\"")
endif(MSVC) endif(MSVC)
@ -105,19 +105,19 @@ elseif(PACKAGE_PLATFORM MATCHES "win")
install(TARGETS ${EXECUTABLE_TARGET} DESTINATION .) install(TARGETS ${EXECUTABLE_TARGET} DESTINATION .)
# Install SDL2 DLLs # Install SDL2 DLLs
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
get_target_property(SDL2_DLL SDL2::SDL2 IMPORTED_LOCATION_DEBUG)
else()
get_target_property(SDL2_DLL SDL2::SDL2 IMPORTED_LOCATION_RELEASE)
endif()
install(FILES ${SDL2_DLL} DESTINATION .)
#if(CMAKE_BUILD_TYPE STREQUAL "Debug")
# get_target_property(SDL2_DLL SDL2::SDL2 IMPORTED_LOCATION_DEBUG)
#else()
# get_target_property(SDL2_DLL SDL2::SDL2 IMPORTED_LOCATION_RELEASE)
#endif()
#install(FILES ${SDL2_DLL} DESTINATION .)
# Install OpenAL DLL # Install OpenAL DLL
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
get_target_property(OPENAL_DLL OpenAL::OpenAL IMPORTED_LOCATION_DEBUG)
else()
get_target_property(OPENAL_DLL OpenAL::OpenAL IMPORTED_LOCATION_RELEASE)
endif()
install(FILES ${OPENAL_DLL} DESTINATION .)
#if(CMAKE_BUILD_TYPE STREQUAL "Debug")
# get_target_property(OPENAL_DLL OpenAL::OpenAL IMPORTED_LOCATION_DEBUG)
#else()
# get_target_property(OPENAL_DLL OpenAL::OpenAL IMPORTED_LOCATION_RELEASE)
#endif()
#install(FILES ${OPENAL_DLL} DESTINATION .)
endif() endif()

+ 22
- 19
src/application.cpp View File

@ -109,6 +109,19 @@ application::application(int argc, char** argv):
closed(false), closed(false),
exit_status(EXIT_SUCCESS) exit_status(EXIT_SUCCESS)
{ {
// Determine application name
std::string application_name;
#if defined(_WIN32)
application_name = "Antkeeper";
#else
application_name = "antkeeper";
#endif
// Detect resource paths
data_path = get_data_path(application_name) + "data/";
config_path = get_config_path(application_name);
screenshots_path = config_path + "screenshots/";
// Format log messages // Format log messages
logger.set_warning_prefix("Warning: "); logger.set_warning_prefix("Warning: ");
logger.set_error_prefix(std::string()); logger.set_error_prefix(std::string());
@ -118,27 +131,15 @@ application::application(int argc, char** argv):
#if defined(DEBUG) #if defined(DEBUG)
logger.redirect(&std::cout); logger.redirect(&std::cout);
#else #else
std::string log_filename = "log.txt";
std::string log_filename = config_path + "log.txt";
log_filestream.open(log_filename.c_str()); log_filestream.open(log_filename.c_str());
logger.redirect(&log_filestream); logger.redirect(&log_filestream);
#endif #endif
// Determine application name
std::string application_name;
#if defined(_WIN32)
application_name = "Antkeeper";
#else
application_name = "antkeeper";
#endif
// Form resource paths
data_path = get_data_path(application_name) + "data/";
config_path = get_config_path(application_name);
// Log paths
logger.log("Detected data path as \"" + data_path + "\""); logger.log("Detected data path as \"" + data_path + "\"");
logger.log("Detected config path as \"" + config_path + "\""); logger.log("Detected config path as \"" + config_path + "\"");
screenshots_path = config_path + "screenshots/";
// Create nonexistent config directories // Create nonexistent config directories
std::vector<std::string> config_paths; std::vector<std::string> config_paths;
config_paths.push_back(config_path); config_paths.push_back(config_path);
@ -241,10 +242,12 @@ application::application(int argc, char** argv):
int window_height = 1080; int window_height = 1080;
fullscreen = true; fullscreen = true;
window_width = 1280; window_width = 1280;
window_height = 720; window_height = 720;
fullscreen = false; fullscreen = false;
viewport = {0.0f, 0.0f, static_cast<float>(window_width), static_cast<float>(window_height)}; viewport = {0.0f, 0.0f, static_cast<float>(window_width), static_cast<float>(window_height)};
int window_flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN; int window_flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN;
@ -320,7 +323,7 @@ application::application(int argc, char** argv):
SDL_GL_SwapWindow(window); SDL_GL_SwapWindow(window);
// Hide cursor // Hide cursor
SDL_ShowCursor(SDL_DISABLE);
//SDL_ShowCursor(SDL_DISABLE);
// Init SDL joystick and game controller subsystems // Init SDL joystick and game controller subsystems
logger.push_task("Initializing SDL Joystick and Game Controller subsystems"); logger.push_task("Initializing SDL Joystick and Game Controller subsystems");
@ -608,6 +611,7 @@ application::application(int argc, char** argv):
control_system = new ::control_system(); control_system = new ::control_system();
control_system->set_orbit_cam(&orbit_cam); control_system->set_orbit_cam(&orbit_cam);
control_system->set_viewport(viewport); control_system->set_viewport(viewport);
control_system->set_underworld_camera(&underworld_camera);
event_dispatcher.subscribe<mouse_moved_event>(control_system); event_dispatcher.subscribe<mouse_moved_event>(control_system);
event_dispatcher.subscribe<mouse_moved_event>(camera_system); event_dispatcher.subscribe<mouse_moved_event>(camera_system);
event_dispatcher.subscribe<mouse_moved_event>(tool_system); event_dispatcher.subscribe<mouse_moved_event>(tool_system);
@ -758,8 +762,6 @@ application::application(int argc, char** argv):
underworld_ambient_light.set_intensity(0.15f); underworld_ambient_light.set_intensity(0.15f);
underworld_ambient_light.update_tweens(); underworld_ambient_light.update_tweens();
// Darkness
darkness_volume.set_model(resource_manager->load<model>("darkness-volume.obj"));
lantern.set_model(resource_manager->load<model>("lantern.obj")); lantern.set_model(resource_manager->load<model>("lantern.obj"));
// Cloud // Cloud
@ -821,8 +823,7 @@ application::application(int argc, char** argv):
// Setup underworld scene // Setup underworld scene
underworld_scene.add_object(&underworld_camera); underworld_scene.add_object(&underworld_camera);
underworld_scene.add_object(&underworld_ambient_light); underworld_scene.add_object(&underworld_ambient_light);
//underworld_scene.add_object(&darkness_volume);
underworld_scene.add_object(&lantern);
//underworld_scene.add_object(&lantern);
underworld_scene.add_object(&subterrain_light); underworld_scene.add_object(&subterrain_light);
underworld_scene.add_object(portal_billboard); underworld_scene.add_object(portal_billboard);
//model_instance* larva = new model_instance(resource_manager->load<model>("larva.obj")); //model_instance* larva = new model_instance(resource_manager->load<model>("larva.obj"));
@ -835,6 +836,8 @@ application::application(int argc, char** argv):
model_instance* flashlight_light_cone = new model_instance(resource_manager->load<model>("flashlight-light-cone.obj")); model_instance* flashlight_light_cone = new model_instance(resource_manager->load<model>("flashlight-light-cone.obj"));
flashlight_light_cone->set_rotation(flashlight_rotation); flashlight_light_cone->set_rotation(flashlight_rotation);
underworld_scene.add_object(flashlight_light_cone); underworld_scene.add_object(flashlight_light_cone);
control_system->set_flashlight(flashlight, flashlight_light_cone);
// Set overworld as active scene // Set overworld as active scene
active_scene = &overworld_scene; active_scene = &overworld_scene;

+ 0
- 1
src/application.hpp View File

@ -246,7 +246,6 @@ private:
directional_light sun_direct; directional_light sun_direct;
point_light subterrain_light; point_light subterrain_light;
ambient_light underworld_ambient_light; ambient_light underworld_ambient_light;
model_instance darkness_volume;
model_instance lantern; model_instance lantern;
model_instance cloud; model_instance cloud;
model_instance* grass_patches; model_instance* grass_patches;

+ 6
- 1
src/nest.cpp View File

@ -42,7 +42,7 @@ float3 nest::extend_shaft(shaft& shaft)
float dr = frand(dig_radius * 0.75f, dig_radius * 1.25f); float dr = frand(dig_radius * 0.75f, dig_radius * 1.25f);
shaft.current_depth += dr * 0.5f;
shaft.current_depth += dr * 0.1f;
return dig_position; return dig_position;
} }
@ -77,6 +77,11 @@ float nest::get_shaft_angle(const shaft& shaft, float depth) const
return shaft.rotation + (depth / pitch) * shaft.chirality * vmq::two_pi<float>; return shaft.rotation + (depth / pitch) * shaft.chirality * vmq::two_pi<float>;
} }
float nest::get_shaft_depth(const shaft& shaft, float turns) const
{
return shaft.pitch[0] * turns;
}
float3 nest::get_shaft_position(const shaft& shaft, float depth) const float3 nest::get_shaft_position(const shaft& shaft, float depth) const
{ {
float shaft_length = shaft.depth[1] - shaft.depth[0]; float shaft_length = shaft.depth[1] - shaft.depth[0];

+ 2
- 0
src/nest.hpp View File

@ -76,6 +76,8 @@ public:
float get_shaft_angle(const shaft& shaft, float depth) const; float get_shaft_angle(const shaft& shaft, float depth) const;
float get_shaft_depth(const shaft& shaft, float turns) const;
private: private:
float tunnel_radius; float tunnel_radius;
shaft central_shaft; shaft central_shaft;

+ 0
- 1
src/scene/scene-object.cpp View File

@ -60,4 +60,3 @@ void scene_object_base::look_at(const float3& position, const float3& target, co
void scene_object_base::transformed() void scene_object_base::transformed()
{} {}

+ 9
- 7
src/state/play-state.cpp View File

@ -58,7 +58,6 @@ void enter_play_state(application* app)
// Load entity archetypes // Load entity archetypes
ecs::archetype* ant_hill_archetype = resource_manager->load<ecs::archetype>("ant-hill.ent"); ecs::archetype* ant_hill_archetype = resource_manager->load<ecs::archetype>("ant-hill.ent");
ecs::archetype* maple_tree_archetype = resource_manager->load<ecs::archetype>("maple-tree.ent"); ecs::archetype* maple_tree_archetype = resource_manager->load<ecs::archetype>("maple-tree.ent");
ecs::archetype* darkness_volume_archetype = resource_manager->load<ecs::archetype>("darkness-volume.ent");
ecs::archetype* nest_archetype = resource_manager->load<ecs::archetype>("harvester-nest.ent"); ecs::archetype* nest_archetype = resource_manager->load<ecs::archetype>("harvester-nest.ent");
ecs::archetype* samara_archetype = resource_manager->load<ecs::archetype>("samara.ent"); ecs::archetype* samara_archetype = resource_manager->load<ecs::archetype>("samara.ent");
ecs::archetype* forceps_archetype = resource_manager->load<ecs::archetype>("forceps.ent"); ecs::archetype* forceps_archetype = resource_manager->load<ecs::archetype>("forceps.ent");
@ -100,7 +99,6 @@ void enter_play_state(application* app)
placement.ray.direction = {0, -1, 0}; placement.ray.direction = {0, -1, 0};
ecs_registry.assign<ecs::placement_component>(maple_tree_entity, placement); ecs_registry.assign<ecs::placement_component>(maple_tree_entity, placement);
//auto darkness_volume_entity = darkness_volume_archetype->create(ecs_registry);
auto nest_entity = nest_archetype->create(ecs_registry); auto nest_entity = nest_archetype->create(ecs_registry);
int terrain_radius = 2; int terrain_radius = 2;
@ -174,12 +172,12 @@ void enter_play_state(application* app)
float tunnel_radius = 1.15f; float tunnel_radius = 1.15f;
nest->set_tunnel_radius(tunnel_radius); nest->set_tunnel_radius(tunnel_radius);
nest::shaft* central_shaft = nest->get_central_shaft(); nest::shaft* central_shaft = nest->get_central_shaft();
central_shaft->chirality = -1.0f;
central_shaft->chirality = 1.0f;
central_shaft->rotation = vmq::radians(0.0f); central_shaft->rotation = vmq::radians(0.0f);
central_shaft->depth = {0.0f, 200.0f}; central_shaft->depth = {0.0f, 200.0f};
central_shaft->radius = {0.0f, 5.0f};
central_shaft->pitch = {4.0f, 8.0f};
central_shaft->translation = {{{0.0f, 0.0f}, {40.0f, 26.0f}}};
central_shaft->radius = {15.0f, 15.0f};
central_shaft->pitch = {40.0f, 40.0f};
central_shaft->translation = {{{0.0f, 0.0f}, {0.0f, 0.0f}}};
central_shaft->current_depth = 0.0f; central_shaft->current_depth = 0.0f;
for (std::size_t i = 0; i < 4; ++i) for (std::size_t i = 0; i < 4; ++i)
{ {
@ -194,7 +192,7 @@ void enter_play_state(application* app)
// Dig nest shafts // Dig nest shafts
float shift = 0.1f; float shift = 0.1f;
for (int i = 0; i < 400; ++i)
for (int i = 0; i < 800; ++i)
{ {
ecs::cavity_component cavity; ecs::cavity_component cavity;
cavity.position = nest->extend_shaft(*nest->get_central_shaft()); cavity.position = nest->extend_shaft(*nest->get_central_shaft());
@ -205,6 +203,7 @@ void enter_play_state(application* app)
} }
// Dig nest chambers // Dig nest chambers
/*
for (int i = 0; i < central_shaft->chambers.size(); ++i) for (int i = 0; i < central_shaft->chambers.size(); ++i)
{ {
for (int j = 0; j < 150; ++j) for (int j = 0; j < 150; ++j)
@ -217,8 +216,10 @@ void enter_play_state(application* app)
ecs_registry.assign<ecs::cavity_component>(ecs_registry.create(), cavity); ecs_registry.assign<ecs::cavity_component>(ecs_registry.create(), cavity);
} }
} }
*/
// Place larva in chamber // Place larva in chamber
/*
{ {
auto larva_entity = larva_archetype->create(ecs_registry); auto larva_entity = larva_archetype->create(ecs_registry);
auto& transform = ecs_registry.get<ecs::transform_component>(larva_entity); auto& transform = ecs_registry.get<ecs::transform_component>(larva_entity);
@ -226,6 +227,7 @@ void enter_play_state(application* app)
transform.transform.translation = nest->get_shaft_position(*central_shaft, central_shaft->depth[1]); transform.transform.translation = nest->get_shaft_position(*central_shaft, central_shaft->depth[1]);
//transform.transform.translation.y -= 1.0f; //transform.transform.translation.y -= 1.0f;
} }
*/
control_system* control_system = app->get_control_system(); control_system* control_system = app->get_control_system();
control_system->update(0.0f); control_system->update(0.0f);

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

@ -44,7 +44,11 @@ static inline T log_lerp(const T& x, const T& y, float a)
control_system::control_system(): control_system::control_system():
timestep(0.0f), timestep(0.0f),
zoom(0.0f)
zoom(0.0f),
tool(nullptr),
flashlight(nullptr),
flashlight_light_cone(nullptr),
underworld_camera(nullptr)
{ {
control_set.add_control(&move_forward_control); control_set.add_control(&move_forward_control);
control_set.add_control(&move_back_control); control_set.add_control(&move_back_control);
@ -85,6 +89,12 @@ control_system::control_system():
nest = nullptr; nest = nullptr;
orbit_cam = nullptr; orbit_cam = nullptr;
mouse_angle = 0.0f;
old_mouse_angle = mouse_angle;
flashlight_turns = 0.0f;
flashlight_turns_i = 0;
flashlight_turns_f = 0.0f;
} }
void control_system::update(float dt) void control_system::update(float dt)
@ -208,6 +218,48 @@ void control_system::update(float dt)
if (toggle_view_control.is_active() && !toggle_view_control.was_active()) if (toggle_view_control.is_active() && !toggle_view_control.was_active())
{ {
} }
// Turn flashlight
float2 viewport_center = {(viewport[0] + viewport[2]) * 0.5f, (viewport[1] + viewport[3]) * 0.5f};
float2 mouse_direction = vmq::normalize(mouse_position - viewport_center);
old_mouse_angle = mouse_angle;
mouse_angle = std::atan2(-mouse_direction.y, mouse_direction.x);
if (mouse_angle - old_mouse_angle != 0.0f)
{
if (mouse_angle - old_mouse_angle <= -vmq::pi<float>)
flashlight_turns_i -= 1;
else if (mouse_angle - old_mouse_angle >= vmq::pi<float>)
flashlight_turns_i += 1;
flashlight_turns_f = (mouse_angle) / vmq::two_pi<float>;
flashlight_turns = flashlight_turns_i - flashlight_turns_f;
if (flashlight && nest)
{
transform<float> flashlight_transform = vmq::identity_transform<float>;
float flashlight_depth = nest->get_shaft_depth(*nest->get_central_shaft(), flashlight_turns);
flashlight_transform.translation = {0.0f, -flashlight_depth, 0.0f};
flashlight_transform.rotation = vmq::angle_axis(-flashlight_turns * vmq::two_pi<float> + vmq::half_pi<float>, {0, 1, 0});
flashlight->set_transform(flashlight_transform);
flashlight_light_cone->set_transform(flashlight_transform);
if (underworld_camera)
{
underworld_camera->look_at({0, -flashlight_depth + 50.0f, 0}, {0, -flashlight_depth, 0}, {0, 0, -1});
}
}
}
} }
void control_system::set_orbit_cam(::orbit_cam* orbit_cam) void control_system::set_orbit_cam(::orbit_cam* orbit_cam)
@ -225,11 +277,22 @@ void control_system::set_tool(model_instance* tool)
this->tool = tool; this->tool = tool;
} }
void control_system::set_flashlight(model_instance* flashlight, model_instance* light_cone)
{
this->flashlight = flashlight;
this->flashlight_light_cone = light_cone;
}
void control_system::set_viewport(const float4& viewport) void control_system::set_viewport(const float4& viewport)
{ {
this->viewport = viewport; this->viewport = viewport;
} }
void control_system::set_underworld_camera(::camera* camera)
{
this->underworld_camera = camera;
}
void control_system::handle_event(const mouse_moved_event& event) void control_system::handle_event(const mouse_moved_event& event)
{ {
if (adjust_camera_control.is_active()) if (adjust_camera_control.is_active())

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

@ -28,6 +28,7 @@
class orbit_cam; class orbit_cam;
class nest; class nest;
class camera;
class control_system: class control_system:
public event_handler<mouse_moved_event> public event_handler<mouse_moved_event>
@ -40,7 +41,9 @@ public:
void set_orbit_cam(orbit_cam* orbit_cam); void set_orbit_cam(orbit_cam* orbit_cam);
void set_nest(::nest* nest); void set_nest(::nest* nest);
void set_tool(model_instance* tool); void set_tool(model_instance* tool);
void set_flashlight(model_instance* flashlight, model_instance* light_cone);
void set_viewport(const float4& viewport); void set_viewport(const float4& viewport);
void set_underworld_camera(::camera* camera);
control_set* get_control_set(); control_set* get_control_set();
control* get_move_forward_control(); control* get_move_forward_control();
@ -100,6 +103,16 @@ private:
model_instance* tool; model_instance* tool;
float2 mouse_position; float2 mouse_position;
float4 viewport; float4 viewport;
model_instance* flashlight;
model_instance* flashlight_light_cone;
camera* underworld_camera;
float mouse_angle;
float old_mouse_angle;
float flashlight_turns;
float flashlight_turns_i;
float flashlight_turns_f;
}; };
inline control_set* control_system::get_control_set() inline control_set* control_system::get_control_set()

Loading…
Cancel
Save