Browse Source

Attempt to fix potential compatibility issues, and re-enabled some previously disable functionality

master
C. J. Howard 4 years ago
parent
commit
82fe0eee40
8 changed files with 54 additions and 44 deletions
  1. +1
    -1
      src/game/astronomy/celestial-mechanics.cpp
  2. +3
    -0
      src/game/astronomy/celestial-mechanics.hpp
  3. +12
    -7
      src/game/bootloader.cpp
  4. +5
    -5
      src/game/states/play-state.cpp
  5. +3
    -3
      src/game/systems/camera-system.cpp
  6. +1
    -1
      src/game/systems/solar-system.cpp
  7. +5
    -7
      src/game/systems/vegetation-system.cpp
  8. +24
    -20
      src/game/systems/weather-system.cpp

+ 1
- 1
src/game/astronomy/celestial-mechanics.cpp View File

@ -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);

+ 3
- 0
src/game/astronomy/celestial-mechanics.hpp View File

@ -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.

+ 12
- 7
src/game/bootloader.cpp View File

@ -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<int>("shadow_map_resolution");
int shadow_map_resolution = 4096;
if (ctx->config->has("shadow_map_resolution"))
{
shadow_map_resolution = ctx->config->get<int>("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<float>("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<float>("time_scale"));
time_scale = ctx->config->get<float>("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);

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

@ -83,7 +83,7 @@ void play_state_enter(game_context* ctx)
sky_pass->set_moon_model(ctx->resource_manager->load<model>("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)

+ 3
- 3
src/game/systems/camera-system.cpp View File

@ -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);

+ 1
- 1
src/game/systems/solar-system.cpp View File

@ -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<double>, 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<orbit_component, transform_component>().each(

+ 5
- 7
src/game/systems/vegetation-system.cpp View File

@ -39,8 +39,8 @@ vegetation_system::vegetation_system(entt::registry& registry):
vegetation_density(1.0f),
vegetation_model(nullptr)
{
//registry.on_construct<terrain_component>().connect<&vegetation_system::on_terrain_construct>(this);
//registry.on_destroy<terrain_component>().connect<&vegetation_system::on_terrain_destroy>(this);
registry.on_construct<terrain_component>().connect<&vegetation_system::on_terrain_construct>(this);
registry.on_destroy<terrain_component>().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<float>;
transform.transform.translation = float3{vegetation_patch_x, 0.0f, vegetation_patch_z};
transform.local = math::identity_transform<float>;
transform.local.translation = float3{vegetation_patch_x, 0.0f, vegetation_patch_z};
transform.warp = true;
registry.assign_or_replace<transform_component>(vegetation_patch_entity, transform);

+ 24
- 20
src/game/systems/weather-system.cpp View File

@ -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<float>(moon_spherical.z) - math::pi<float>, static_cast<float>(moon_spherical.y)};
float3 moon_position = math::normalize(math::type_cast<float>(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<double> moon_rotationd = math::normalize(math::quaternion_cast(moon_rotation_matrix) * math::angle_axis(math::half_pi<double>, double3{0, 1, 0}) * math::angle_axis(-math::half_pi<double>, double3{0, 0, -1}));
math::quaternion<float> 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<float>(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<float3>& gradient, float position)
{
if (gradient.empty())
return float3{0.0f, 0.0f, 0.0f};
position *= static_cast<float>(gradient.size() - 1);
int index0 = static_cast<int>(position) % gradient.size();
int index1 = (index0 + 1) % gradient.size();

Loading…
Cancel
Save