From 82fe0eee406bbdb03037bc969d6ce58280e5624f Mon Sep 17 00:00:00 2001 From: "C. J. Howard" Date: Fri, 16 Oct 2020 14:49:10 -0700 Subject: [PATCH] Attempt to fix potential compatibility issues, and re-enabled some previously disable functionality --- src/game/astronomy/celestial-mechanics.cpp | 2 +- src/game/astronomy/celestial-mechanics.hpp | 3 ++ src/game/bootloader.cpp | 19 ++++++---- src/game/states/play-state.cpp | 10 ++--- src/game/systems/camera-system.cpp | 6 +-- src/game/systems/solar-system.cpp | 2 +- src/game/systems/vegetation-system.cpp | 12 +++--- src/game/systems/weather-system.cpp | 44 ++++++++++++---------- 8 files changed, 54 insertions(+), 44 deletions(-) diff --git a/src/game/astronomy/celestial-mechanics.cpp b/src/game/astronomy/celestial-mechanics.cpp index a18a7fc..f6232b7 100644 --- a/src/game/astronomy/celestial-mechanics.cpp +++ b/src/game/astronomy/celestial-mechanics.cpp @@ -156,7 +156,7 @@ orbital_state orbital_elements_to_state(const orbital_elements& elements, double // Solve Kepler's equation for eccentric anomaly, E double ea = solve_kepler(elements.ec, elements.ma, ke_tolerance, ke_iterations); - // Radial distance (r) and true anomaly (v) + // Calculate radial distance (r) and true anomaly (v) double x = elements.a * (std::cos(ea) - elements.ec); double y = b * std::sin(ea); double r = std::sqrt(x * x + y * y); diff --git a/src/game/astronomy/celestial-mechanics.hpp b/src/game/astronomy/celestial-mechanics.hpp index 9ef4617..fb7f656 100644 --- a/src/game/astronomy/celestial-mechanics.hpp +++ b/src/game/astronomy/celestial-mechanics.hpp @@ -93,6 +93,9 @@ double solve_kepler(double ec, double ma, double tolerance, std::size_t iteratio /** * Calculates orbital state vectors from Keplerian orbital elements. * + * @note Only works for elliptic orbits. + * @todo Calculate orbital state velocity. + * * @param elements Orbital elements. * @param ke_tolerance Kepler's equation tolerance. * @param ke_iterations Kepler's equation iterations. diff --git a/src/game/bootloader.cpp b/src/game/bootloader.cpp index f7159e7..02abb3e 100644 --- a/src/game/bootloader.cpp +++ b/src/game/bootloader.cpp @@ -465,7 +465,11 @@ void setup_rendering(game_context* ctx) ctx->framebuffer_hdr->attach(framebuffer_attachment_type::stencil, ctx->framebuffer_hdr_depth); // Create shadow map framebuffer - int shadow_map_resolution = ctx->config->get("shadow_map_resolution"); + int shadow_map_resolution = 4096; + if (ctx->config->has("shadow_map_resolution")) + { + shadow_map_resolution = ctx->config->get("shadow_map_resolution"); + } ctx->shadow_map_depth_texture = new texture_2d(shadow_map_resolution, shadow_map_resolution, pixel_type::float_32, pixel_format::d); ctx->shadow_map_depth_texture->set_wrapping(texture_wrapping::clamp, texture_wrapping::clamp); ctx->shadow_map_depth_texture->set_filters(texture_min_filter::linear, texture_mag_filter::linear); @@ -518,7 +522,7 @@ void setup_rendering(game_context* ctx) ctx->overworld_bloom_pass->set_source_texture(ctx->framebuffer_hdr_color); ctx->overworld_bloom_pass->set_brightness_threshold(1.0f); ctx->overworld_bloom_pass->set_blur_iterations(5); - ctx->overworld_bloom_pass->set_enabled(false); + ctx->overworld_bloom_pass->set_enabled(true); ctx->overworld_final_pass = new ::final_pass(ctx->rasterizer, &ctx->rasterizer->get_default_framebuffer(), ctx->resource_manager); ctx->overworld_final_pass->set_color_texture(ctx->framebuffer_hdr_color); ctx->overworld_final_pass->set_bloom_texture(ctx->bloom_texture); @@ -882,17 +886,18 @@ void setup_systems(game_context* ctx) ctx->weather_system->set_sky_pass(ctx->overworld_sky_pass); ctx->weather_system->set_shadow_map_pass(ctx->overworld_shadow_map_pass); ctx->weather_system->set_material_pass(ctx->overworld_material_pass); - if (ctx->config->has("time_scale")) - { - ctx->weather_system->set_time_scale(ctx->config->get("time_scale")); - } // Setup solar system ctx->solar_system = new solar_system(*ctx->ecs_registry); + + // Set time scale + float time_scale = 60.0f; if (ctx->config->has("time_scale")) { - ctx->solar_system->set_time_scale(ctx->config->get("time_scale")); + time_scale = ctx->config->get("time_scale"); } + ctx->weather_system->set_time_scale(time_scale); + ctx->solar_system->set_time_scale(time_scale); // Setup render system ctx->render_system = new ::render_system(*ctx->ecs_registry); diff --git a/src/game/states/play-state.cpp b/src/game/states/play-state.cpp index 2ccfb6f..b1b7370 100644 --- a/src/game/states/play-state.cpp +++ b/src/game/states/play-state.cpp @@ -83,7 +83,7 @@ void play_state_enter(game_context* ctx) sky_pass->set_moon_model(ctx->resource_manager->load("moon.mdl")); ctx->weather_system->set_location(ctx->biome->location[0], ctx->biome->location[1], ctx->biome->location[2]); - ctx->weather_system->set_time(2017, 6, 1, 5, 0, 0.0, -7.0); + ctx->weather_system->set_time(2017, 6, 1, 5, 0, 0.0, -5.0); ctx->weather_system->set_sky_palette(ctx->biome->sky_palette); ctx->weather_system->set_sun_palette(ctx->biome->sun_palette); ctx->weather_system->set_ambient_palette(ctx->biome->ambient_palette); @@ -91,7 +91,7 @@ void play_state_enter(game_context* ctx) ctx->weather_system->set_shadow_palette(ctx->biome->shadow_palette); ctx->solar_system->set_observer_location(ctx->biome->location[0], ctx->biome->location[1], ctx->biome->location[2]); - double jd = ast::ut_to_jd(2017, 6, 1, 5, 0, 0.0) - -7.0 / 24.0; + double jd = ast::ut_to_jd(2017, 6, 1, 5, 0, 0.0) - -5.0 / 24.0; ctx->solar_system->set_julian_date(jd); resource_manager* resource_manager = ctx->resource_manager; @@ -193,14 +193,14 @@ void play_state_enter(game_context* ctx) } // Create maple tree - auto maple_tree_entity = maple_tree_archetype->create(ecs_registry); - ec::place(ecs_registry, maple_tree_entity, {300, 200}); + //auto maple_tree_entity = maple_tree_archetype->create(ecs_registry); + //ec::place(ecs_registry, maple_tree_entity, {300, 200}); // Creat nest auto nest_entity = nest_archetype->create(ecs_registry); // Create terrain - int terrain_radius = 8; + int terrain_radius = 6; for (int x = -terrain_radius; x <= terrain_radius; ++x) { for (int z = -terrain_radius; z <= terrain_radius; ++z) diff --git a/src/game/systems/camera-system.cpp b/src/game/systems/camera-system.cpp index d83fde7..d3e126c 100644 --- a/src/game/systems/camera-system.cpp +++ b/src/game/systems/camera-system.cpp @@ -34,12 +34,12 @@ camera_system::camera_system(entt::registry& registry): viewport{0, 0, 0, 0}, mouse_position{0, 0} { - //orbit_cam.set_elevation_limits({math::radians(5.0f), math::radians(89.0f)}); - orbit_cam.set_elevation_limits({math::radians(-89.0f), math::radians(89.0f)}); + orbit_cam.set_elevation_limits({math::radians(5.0f), math::radians(89.0f)}); + //orbit_cam.set_elevation_limits({math::radians(-89.0f), math::radians(89.0f)}); orbit_cam.set_focal_distance_limits({2.0f, 200.0f}); orbit_cam.set_fov_limits({math::radians(80.0f), math::radians(35.0f)}); orbit_cam.set_clip_near_limits({0.1f, 5.0f}); - orbit_cam.set_clip_far_limits({5000.0f, 5000.0f}); + orbit_cam.set_clip_far_limits({100.0f, 5000.0f}); orbit_cam.set_target_focal_point({0.0f, 0.0f, 0.0f}); orbit_cam.set_target_azimuth(0.0f); diff --git a/src/game/systems/solar-system.cpp b/src/game/systems/solar-system.cpp index 691f862..b9463ae 100644 --- a/src/game/systems/solar-system.cpp +++ b/src/game/systems/solar-system.cpp @@ -69,7 +69,7 @@ void solar_system::update(double t, double dt) double3 sun_spherical = ast::rectangular_to_spherical(sun_horizontal); double2 sun_az_el = {sun_spherical.z - math::pi, sun_spherical.y}; - std::cout << "new azel: " << math::degrees(sun_az_el.x) << ", " << math::degrees(sun_az_el.y) << std::endl; + //std::cout << "new azel: " << math::degrees(sun_az_el.x) << ", " << math::degrees(sun_az_el.y) << std::endl; // Update horizontal (topocentric) positions of orbiting bodies registry.view().each( diff --git a/src/game/systems/vegetation-system.cpp b/src/game/systems/vegetation-system.cpp index 8727761..7b2ea5c 100644 --- a/src/game/systems/vegetation-system.cpp +++ b/src/game/systems/vegetation-system.cpp @@ -39,8 +39,8 @@ vegetation_system::vegetation_system(entt::registry& registry): vegetation_density(1.0f), vegetation_model(nullptr) { - //registry.on_construct().connect<&vegetation_system::on_terrain_construct>(this); - //registry.on_destroy().connect<&vegetation_system::on_terrain_destroy>(this); + registry.on_construct().connect<&vegetation_system::on_terrain_construct>(this); + registry.on_destroy().connect<&vegetation_system::on_terrain_destroy>(this); } vegetation_system::~vegetation_system() @@ -88,17 +88,15 @@ void vegetation_system::on_terrain_construct(entt::registry& registry, entt::ent for (int column = 0; column < vegetation_patch_columns; ++column) { for (int row = 0; row < vegetation_patch_rows; ++row) - { - // Calculate center of vegetation patch - + { /* // Create vegetation patch entity auto vegetation_patch_entity = registry.create(); // Assign a transform component transform_component transform; - transform.transform = math::identity_transform; - transform.transform.translation = float3{vegetation_patch_x, 0.0f, vegetation_patch_z}; + transform.local = math::identity_transform; + transform.local.translation = float3{vegetation_patch_x, 0.0f, vegetation_patch_z}; transform.warp = true; registry.assign_or_replace(vegetation_patch_entity, transform); diff --git a/src/game/systems/weather-system.cpp b/src/game/systems/weather-system.cpp index 0e6a6dc..07a6104 100644 --- a/src/game/systems/weather-system.cpp +++ b/src/game/systems/weather-system.cpp @@ -62,11 +62,6 @@ void weather_system::update(double t, double dt) double local_jd = jd + time_correction / 24.0 - 0.5; double local_time = (local_jd - std::floor(local_jd)) * 24.0; - // Solar distance in AU - //double sr = ... - // Apparent radius in degrees - //double sradius = 0.2666 / sr; - double lmst = ast::jd_to_lmst(jd, longitude); double ecl = ast::approx_ecliptic_obliquity(jd); double3x3 ecliptic_to_horizontal = ast::ecliptic_to_horizontal(ecl, latitude, lmst); @@ -89,10 +84,6 @@ void weather_system::update(double t, double dt) float2 moon_az_el = {static_cast(moon_spherical.z) - math::pi, static_cast(moon_spherical.y)}; float3 moon_position = math::normalize(math::type_cast(moon_positiond)); - //double3 moon_sphericald = ast::rectangular_to_spherical(moon_positiond); - std::cout << "old azel: " << math::degrees(sun_az_el.x) << ", " << math::degrees(sun_az_el.y) << std::endl; - //std::cout << "new azel: " << math::degrees(moon_sphericald.z) << ", " << math::degrees(moon_sphericald.y) << std::endl; - double3x3 moon_rotation_matrix = ast::horizontal_to_right_handed * ecliptic_to_horizontal; math::quaternion moon_rotationd = math::normalize(math::quaternion_cast(moon_rotation_matrix) * math::angle_axis(math::half_pi, double3{0, 1, 0}) * math::angle_axis(-math::half_pi, double3{0, 0, -1})); math::quaternion moon_rotation = @@ -126,19 +117,29 @@ void weather_system::update(double t, double dt) if (sky_pass) { - float3 horizon_color = interpolate_gradient(horizon_colors, sun_gradient_position); - float3 zenith_color = interpolate_gradient(zenith_colors, sun_gradient_position); - float3 sun_color = interpolate_gradient(sun_colors, sun_gradient_position); - float3 moon_color = interpolate_gradient(moon_colors, moon_gradient_position); - float3 ambient_color = interpolate_gradient(ambient_colors, ambient_gradient_position); + if (sun_light) + { + float3 sun_color = interpolate_gradient(sun_colors, sun_gradient_position); + sun_light->set_color(sun_color); + sun_light->set_intensity(1.0f); + } + + if (moon_light) + { + float3 moon_color = interpolate_gradient(moon_colors, moon_gradient_position); + moon_light->set_color(moon_color); + moon_light->set_intensity(1.0f); + } - sun_light->set_color(sun_color); - sun_light->set_intensity(1.0f); - moon_light->set_color(moon_color); - moon_light->set_intensity(1.0f); - ambient_light->set_color(ambient_color); - ambient_light->set_intensity(0.5f); + if (ambient_light) + { + float3 ambient_color = interpolate_gradient(ambient_colors, ambient_gradient_position); + ambient_light->set_color(ambient_color); + ambient_light->set_intensity(0.5f); + } + float3 horizon_color = interpolate_gradient(horizon_colors, sun_gradient_position); + float3 zenith_color = interpolate_gradient(zenith_colors, sun_gradient_position); sky_pass->set_horizon_color(horizon_color); sky_pass->set_zenith_color(zenith_color); sky_pass->set_time_of_day(static_cast(local_time * 60.0 * 60.0)); @@ -294,6 +295,9 @@ void weather_system::load_palette(std::vector* palette, const ::image* i float3 weather_system::interpolate_gradient(const std::vector& gradient, float position) { + if (gradient.empty()) + return float3{0.0f, 0.0f, 0.0f}; + position *= static_cast(gradient.size() - 1); int index0 = static_cast(position) % gradient.size(); int index1 = (index0 + 1) % gradient.size();