Browse Source

Make runnable again after multiple data module updates

master
C. J. Howard 3 years ago
parent
commit
288012a4ef
13 changed files with 249 additions and 221 deletions
  1. +6
    -7
      src/ecs/components/ephemeris-component.hpp
  2. +40
    -0
      src/ecs/components/light-component.hpp
  3. +4
    -28
      src/ecs/systems/astronomy-system.cpp
  4. +5
    -11
      src/ecs/systems/astronomy-system.hpp
  5. +2
    -2
      src/ecs/systems/camera-system.cpp
  6. +127
    -7
      src/ecs/systems/render-system.cpp
  7. +8
    -4
      src/ecs/systems/render-system.hpp
  8. +0
    -12
      src/ecs/systems/ui-system.cpp
  9. +0
    -2
      src/ecs/systems/ui-system.hpp
  10. +20
    -32
      src/game/bootloader.cpp
  11. +0
    -2
      src/game/game-context.hpp
  12. +31
    -113
      src/game/states/play-state.cpp
  13. +6
    -1
      src/resources/model-loader.cpp

src/ecs/components/render-component.hpp → src/ecs/components/ephemeris-component.hpp View File

@ -17,19 +17,18 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_RENDER_COMPONENT_HPP
#define ANTKEEPER_ECS_RENDER_COMPONENT_HPP
#ifndef ANTKEEPER_ECS_EPHEMERIS_COMPONENT_HPP
#define ANTKEEPER_ECS_EPHEMERIS_COMPONENT_HPP
#include "scene/object.hpp"
#include "astro/orbit.hpp"
namespace ecs {
struct render_component
struct ephemeris_component
{
scene::object_base* object;
unsigned int layers;
ecs::entity body;
};
} // namespace ecs
#endif // ANTKEEPER_ECS_RENDER_COMPONENT_HPP
#endif // ANTKEEPER_ECS_EPHEMERIS_COMPONENT_HPP

+ 40
- 0
src/ecs/components/light-component.hpp View File

@ -0,0 +1,40 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_ECS_LIGHT_COMPONENT_HPP
#define ANTKEEPER_ECS_LIGHT_COMPONENT_HPP
#include "utility/fundamental-types.hpp"
#include "scene/light.hpp"
namespace ecs {
struct light_component
{
scene::light_type type;
float3 color;
float intensity;
float3 attenuation;
float2 cutoff;
};
} // namespace ecs
#endif // ANTKEEPER_ECS_LIGHT_COMPONENT_HPP

+ 4
- 28
src/ecs/systems/astronomy-system.cpp View File

@ -22,7 +22,6 @@
#include "astro/apparent-size.hpp"
#include "ecs/components/celestial-body-component.hpp"
#include "ecs/components/transform-component.hpp"
#include "renderer/passes/sky-pass.hpp"
namespace ecs {
@ -35,9 +34,9 @@ astronomy_system::astronomy_system(ecs::registry& registry):
observer_location{0.0, 0.0, 0.0},
lst(0.0),
obliquity(0.0),
sky_pass(nullptr),
sun(entt::null),
moon(entt::null)
axial_rotation(0.0),
axial_rotation_at_epoch(0.0),
axial_rotation_speed(0.0)
{}
void astronomy_system::update(double t, double dt)
@ -71,15 +70,6 @@ void astronomy_system::update(double t, double dt)
transform.local.rotation = math::type_cast<float>(math::quaternion_cast(rotation));
transform.local.scale = math::type_cast<float>(double3{body.radius, body.radius, body.radius});
});
if (sky_pass)
{
sky_pass->set_horizon_color({0, 0, 0});
sky_pass->set_zenith_color({1, 1, 1});
sky_pass->set_time_of_day(static_cast<float>(universal_time * 60.0 * 60.0));
//sky_pass->set_observer_location(location[0], location[1], location[2]);
sky_pass->set_julian_day(static_cast<float>(universal_time));
}
}
void astronomy_system::set_universal_time(double time)
@ -108,6 +98,7 @@ void astronomy_system::set_obliquity(double angle)
void astronomy_system::set_axial_rotation_speed(double speed)
{
axial_rotation_speed = speed;
update_axial_rotation();
}
void astronomy_system::set_axial_rotation_at_epoch(double angle)
@ -116,21 +107,6 @@ void astronomy_system::set_axial_rotation_at_epoch(double angle)
update_axial_rotation();
}
void astronomy_system::set_sky_pass(::sky_pass* pass)
{
this->sky_pass = pass;
}
void astronomy_system::set_sun(ecs::entity entity)
{
sun = entity;
}
void astronomy_system::set_moon(ecs::entity entity)
{
moon = entity;
}
void astronomy_system::update_axial_rotation()
{
axial_rotation = math::wrap_radians<double>(axial_rotation_at_epoch + universal_time * axial_rotation_speed);

+ 5
- 11
src/ecs/systems/astronomy-system.hpp View File

@ -24,8 +24,6 @@
#include "ecs/entity.hpp"
#include "utility/fundamental-types.hpp"
class sky_pass;
namespace ecs {
/**
@ -80,13 +78,13 @@ public:
*/
void set_axial_rotation_speed(double speed);
/**
* Sets the axial rotation of the observer's planet when the universal time is `0.0`.
*
* @param angle Axial rotation angle, in radians.
*/
void set_axial_rotation_at_epoch(double angle);
void set_sky_pass(::sky_pass* pass);
void set_sun(ecs::entity entity);
void set_moon(ecs::entity entity);
private:
/// Updates the axial rotation angle
void update_axial_rotation();
@ -106,10 +104,6 @@ private:
double3 observer_location;
double obliquity;
double3x3 ecliptic_to_horizontal;
sky_pass* sky_pass;
entity sun;
entity moon;
};
} // namespace ecs

+ 2
- 2
src/ecs/systems/camera-system.cpp View File

@ -33,8 +33,8 @@ camera_system::camera_system(ecs::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});

+ 127
- 7
src/ecs/systems/render-system.cpp View File

@ -20,6 +20,11 @@
#include "render-system.hpp"
#include "ecs/components/transform-component.hpp"
#include "renderer/renderer.hpp"
#include "scene/point-light.hpp"
#include "scene/directional-light.hpp"
#include "scene/ambient-light.hpp"
#include "scene/spotlight.hpp"
#include <iostream>
namespace ecs {
@ -30,10 +35,15 @@ render_system::render_system(ecs::registry& registry):
registry.on_construct<model_component>().connect<&render_system::on_model_construct>(this);
registry.on_replace<model_component>().connect<&render_system::on_model_replace>(this);
registry.on_destroy<model_component>().connect<&render_system::on_model_destroy>(this);
registry.on_construct<light_component>().connect<&render_system::on_light_construct>(this);
registry.on_replace<light_component>().connect<&render_system::on_light_replace>(this);
registry.on_destroy<light_component>().connect<&render_system::on_light_destroy>(this);
}
void render_system::update(double t, double dt)
{
// Update model instance transforms
registry.view<transform_component, model_component>().each
(
[this](ecs::entity entity, auto& transform, auto& model)
@ -41,7 +51,6 @@ void render_system::update(double t, double dt)
scene::model_instance* instance = model_instances[entity];
instance->set_transform(transform.world);
if (transform.warp)
{
instance->get_transform_tween().update();
@ -50,6 +59,23 @@ void render_system::update(double t, double dt)
}
}
);
// Update light transforms
registry.view<transform_component, light_component>().each
(
[this](ecs::entity entity, auto& transform, auto& light)
{
scene::light* light_object = lights[entity];
light_object->set_transform(transform.world);
if (transform.warp)
{
light_object->get_transform_tween().update();
light_object->update_tweens();
transform.warp = false;
}
}
);
}
void render_system::render(double alpha)
@ -85,6 +111,13 @@ scene::model_instance* render_system::get_model_instance(ecs::entity entity)
return nullptr;
}
scene::light* render_system::get_light(ecs::entity entity)
{
if (auto it = lights.find(entity); it != lights.end())
return it->second;
return nullptr;
}
void render_system::update_model_and_materials(ecs::entity entity, model_component& model)
{
if (auto model_it = model_instances.find(entity); model_it != model_instances.end())
@ -110,6 +143,38 @@ void render_system::update_model_and_materials(ecs::entity entity, model_compone
}
}
void render_system::update_light(ecs::entity entity, ecs::light_component& component)
{
if (auto light_it = lights.find(entity); light_it != lights.end())
{
scene::light* light = light_it->second;
light->set_color(component.color);
light->set_intensity(component.intensity);
switch (light->get_light_type())
{
case scene::light_type::point:
{
scene::point_light* point = static_cast<scene::point_light*>(light);
point->set_attenuation(component.attenuation);
break;
}
case scene::light_type::spot:
{
scene::spotlight* spot = static_cast<scene::spotlight*>(light);
spot->set_attenuation(component.attenuation);
spot->set_cutoff(component.cutoff);
break;
}
default:
break;
}
}
}
void render_system::on_model_construct(ecs::registry& registry, ecs::entity entity, model_component& model)
{
scene::model_instance* model_instance = new scene::model_instance();
@ -126,14 +191,69 @@ void render_system::on_model_destroy(ecs::registry& registry, ecs::entity entity
{
if (auto it = model_instances.find(entity); it != model_instances.end())
{
// Remove model instance from all layers
for (std::size_t i = 0; i < layers.size(); ++i)
{
layers[i]->remove_object(it->second);
}
scene::model_instance* model_instance = it->second;
delete it->second;
// Remove model instance from all layers
for (scene::collection* layer: layers)
layer->remove_object(model_instance);
model_instances.erase(it);
delete model_instance;
}
}
void render_system::on_light_construct(ecs::registry& registry, ecs::entity entity, light_component& component)
{
scene::light* light = nullptr;
switch (component.type)
{
case scene::light_type::ambient:
light = new scene::ambient_light();
break;
case scene::light_type::directional:
light = new scene::directional_light();
break;
case scene::light_type::point:
light = new scene::point_light();
break;
case scene::light_type::spot:
light = new scene::spotlight();
break;
default:
break;
}
if (light)
{
lights[entity] = light;
for (scene::collection* layer: layers)
layer->add_object(light);
update_light(entity, component);
}
}
void render_system::on_light_replace(ecs::registry& registry, ecs::entity entity, light_component& light)
{
update_light(entity, light);
}
void render_system::on_light_destroy(ecs::registry& registry, ecs::entity entity)
{
if (auto it = lights.find(entity); it != lights.end())
{
scene::light* light = it->second;
for (scene::collection* layer: layers)
layer->remove_object(light);
lights.erase(it);
delete light;
}
}

+ 8
- 4
src/ecs/systems/render-system.hpp View File

@ -23,8 +23,9 @@
#include "entity-system.hpp"
#include "scene/collection.hpp"
#include "scene/model-instance.hpp"
#include "scene/light.hpp"
#include "ecs/components/model-component.hpp"
#include "ecs/components/render-component.hpp"
#include "ecs/components/light-component.hpp"
#include "ecs/entity.hpp"
#include <unordered_map>
#include <vector>
@ -48,21 +49,24 @@ public:
void set_renderer(::renderer* renderer);
scene::model_instance* get_model_instance(ecs::entity entity);
scene::light* get_light(ecs::entity entity);
private:
void update_model_and_materials(ecs::entity entity, ecs::model_component& model);
void update_light(ecs::entity entity, ecs::light_component& component);
void on_model_construct(ecs::registry& registry, ecs::entity entity, ecs::model_component& model);
void on_model_replace(ecs::registry& registry, ecs::entity entity, ecs::model_component& model);
void on_model_destroy(ecs::registry& registry, ecs::entity entity);
void on_component_construct(ecs::registry& registry, ecs::entity entity, ecs::render_component& component);
void on_component_replace(ecs::registry& registry, ecs::entity entity, ecs::render_component& component);
void on_component_destroy(ecs::registry& registry, ecs::entity entity);
void on_light_construct(ecs::registry& registry, ecs::entity entity, ecs::light_component& light);
void on_light_replace(ecs::registry& registry, ecs::entity entity, ecs::light_component& light);
void on_light_destroy(ecs::registry& registry, ecs::entity entity);
renderer* renderer;
std::vector<scene::collection*> layers;
std::unordered_map<entity, scene::model_instance*> model_instances;
std::unordered_map<entity, scene::light*> lights;
};
} // namespace ecs

+ 0
- 12
src/ecs/systems/ui-system.cpp View File

@ -47,17 +47,10 @@ ui_system::ui_system(::resource_manager* resource_manager):
tool_selector_bg.set_translation({0, 0, -4.0f});
tool_selector_bg.set_scale({270, 270, 270});
// Setup energy symbol
energy_symbol.set_model(resource_manager->load<model>("energy.mdl"));
energy_symbol.set_scale({30, 30, 30});
energy_symbol.update_tweens();
energy_symbol.set_active(false);
// Setup scene
//scene.add_object(&camera);
//scene.add_object(&indirect_light);
//scene.add_object(&direct_light);
//scene.add_object(&energy_symbol);
}
void ui_system::update(float dt)
@ -72,11 +65,6 @@ void ui_system::set_viewport(const float4& viewport)
viewport_center[1] = (viewport[3] - viewport[1]) * 0.5f;
energy_symbol.set_translation({viewport[2] * 0.25f, 0.0f, 0.0f});
energy_symbol.update_tweens();
// Resize modal BG
modal_bg.set_scale({viewport[2] * 0.5f, viewport[3] * 0.5f, 1.0f});
modal_bg.update_tweens();

+ 0
- 2
src/ecs/systems/ui-system.hpp View File

@ -75,8 +75,6 @@ private:
scene::billboard underground_bg;
scene::model_instance energy_symbol;
float2 mouse_position;
float4 viewport;
float2 viewport_center;

+ 20
- 32
src/game/bootloader.cpp View File

@ -609,7 +609,7 @@ void setup_rendering(game_context* ctx)
void setup_scenes(game_context* ctx)
{
debug::logger* logger = ctx->logger;
logger->push_task("Setting up rendering");
logger->push_task("Setting up scenes");
// Get default framebuffer
const auto& viewport_dimensions = ctx->rasterizer->get_default_framebuffer().get_dimensions();
@ -639,14 +639,6 @@ void setup_scenes(game_context* ctx)
ctx->ui_camera->set_compositor(ctx->ui_compositor);
// Setup lights
ctx->sun_indirect = new scene::ambient_light();
ctx->sun_indirect->set_intensity(0.0f);
ctx->sun_indirect->update_tweens();
ctx->sun_direct = new scene::directional_light();
ctx->sun_direct->set_intensity(0.0f);
ctx->sun_direct->update_tweens();
ctx->moon_light = new scene::directional_light();
ctx->moon_light->set_intensity(0.0f);
ctx->moon_light->update_tweens();
@ -707,9 +699,7 @@ void setup_scenes(game_context* ctx)
// Setup overworld scene
ctx->overworld_scene = new scene::collection();
ctx->overworld_scene->add_object(ctx->overworld_camera);
ctx->overworld_scene->add_object(ctx->sun_indirect);
ctx->overworld_scene->add_object(ctx->sun_direct);
ctx->overworld_scene->add_object(ctx->moon_light);
//ctx->overworld_scene->add_object(ctx->moon_light);
//ctx->overworld_scene->add_object(ctx->spotlight);
// Setup underworld scene
@ -726,7 +716,7 @@ void setup_scenes(game_context* ctx)
ctx->ui_scene = new scene::collection();
ctx->ui_scene->add_object(ctx->ui_camera);
ctx->overworld_scene->add_object(ctx->lens_spotlight);
//ctx->overworld_scene->add_object(ctx->lens_spotlight);
ctx->underworld_scene->add_object(ctx->flashlight_spotlight);
// Set overworld as active scene
@ -809,12 +799,12 @@ void setup_systems(game_context* ctx)
ctx->terrain_system->set_patch_size(TERRAIN_PATCH_SIZE);
// Setup vegetation system
ctx->vegetation_system = new ecs::vegetation_system(*ctx->ecs_registry);
ctx->vegetation_system->set_terrain_patch_size(TERRAIN_PATCH_SIZE);
ctx->vegetation_system->set_vegetation_patch_resolution(VEGETATION_PATCH_RESOLUTION);
ctx->vegetation_system->set_vegetation_density(1.0f);
ctx->vegetation_system->set_vegetation_model(ctx->resource_manager->load<model>("grass-tuft.mdl"));
ctx->vegetation_system->set_scene(ctx->overworld_scene);
//ctx->vegetation_system = new ecs::vegetation_system(*ctx->ecs_registry);
//ctx->vegetation_system->set_terrain_patch_size(TERRAIN_PATCH_SIZE);
//ctx->vegetation_system->set_vegetation_patch_resolution(VEGETATION_PATCH_RESOLUTION);
//ctx->vegetation_system->set_vegetation_density(1.0f);
//ctx->vegetation_system->set_vegetation_model(ctx->resource_manager->load<model>("grass-tuft.mdl"));
//ctx->vegetation_system->set_scene(ctx->overworld_scene);
// Setup camera system
ctx->camera_system = new ecs::camera_system(*ctx->ecs_registry);
@ -885,7 +875,6 @@ void setup_systems(game_context* ctx)
// Setup astronomy system
ctx->astronomy_system = new ecs::astronomy_system(*ctx->ecs_registry);
ctx->astronomy_system->set_sky_pass(ctx->overworld_sky_pass);
// Set time scale
float time_scale = 60.0f;
@ -1145,8 +1134,6 @@ void setup_controls(game_context* ctx)
}
);
ctx->control_system->get_next_marker_control()->set_activated_callback
(
[ctx]()
@ -1193,9 +1180,9 @@ void setup_controls(game_context* ctx)
(
[ctx, time_scale]()
{
ctx->weather_system->set_time_scale(time_scale * 50.0f);
ctx->solar_system->set_time_scale(time_scale * 50.0f);
ctx->astronomy_system->set_time_scale(time_scale * 50.0f);
ctx->weather_system->set_time_scale(time_scale * 500.0f);
ctx->solar_system->set_time_scale(time_scale * 500.0f);
ctx->astronomy_system->set_time_scale(time_scale * 500.0f);
}
);
ctx->control_system->get_fast_forward_control()->set_deactivated_callback
@ -1211,9 +1198,9 @@ void setup_controls(game_context* ctx)
(
[ctx, time_scale]()
{
ctx->weather_system->set_time_scale(time_scale * -50.0f);
ctx->solar_system->set_time_scale(time_scale * -50.0f);
ctx->astronomy_system->set_time_scale(time_scale * -50.0f);
ctx->weather_system->set_time_scale(time_scale * -500.0f);
ctx->solar_system->set_time_scale(time_scale * -500.0f);
ctx->astronomy_system->set_time_scale(time_scale * -500.0f);
}
);
ctx->control_system->get_rewind_control()->set_deactivated_callback
@ -1267,7 +1254,7 @@ void setup_callbacks(game_context* ctx)
ctx->control_system->update(t, dt);
ctx->terrain_system->update(t, dt);
ctx->vegetation_system->update(t, dt);
//ctx->vegetation_system->update(t, dt);
ctx->snapping_system->update(t, dt);
ctx->nest_system->update(t, dt);
ctx->subterrain_system->update(t, dt);
@ -1278,18 +1265,19 @@ void setup_callbacks(game_context* ctx)
ctx->camera_system->update(t, dt);
ctx->tool_system->update(t, dt);
ctx->solar_system->update(t, dt);
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->weather_system->update(t, dt);
ctx->solar_system->update(t, dt);
ctx->astronomy_system->update(t, dt);
//(*ctx->focal_point_tween)[1] = ctx->orbit_cam->get_focal_point();
auto xf = ecs::command::get_world_transform(*ctx->ecs_registry, ctx->lens_entity);
ctx->lens_spotlight->look_at(xf.translation, xf.translation + ctx->sun_direct->get_direction(), {0, 1, 0});
//ctx->lens_spotlight->look_at(xf.translation, xf.translation + ctx->sun_direct->get_direction(), {0, 1, 0});
xf = ecs::command::get_world_transform(*ctx->ecs_registry, ctx->flashlight_entity);
//ctx->flashlight_spotlight->set_transform(xf);

+ 0
- 2
src/game/game-context.hpp View File

@ -185,8 +185,6 @@ struct game_context
scene::camera* overworld_camera;
scene::camera* underworld_camera;
scene::camera* ui_camera;
scene::ambient_light* sun_indirect;
scene::directional_light* sun_direct;
scene::directional_light* moon_light;
scene::point_light* subterrain_light;
scene::ambient_light* underworld_ambient_light;

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

@ -33,6 +33,8 @@
#include "ecs/components/transform-component.hpp"
#include "ecs/components/camera-follow-component.hpp"
#include "ecs/components/orbit-component.hpp"
#include "ecs/components/celestial-body-component.hpp"
#include "ecs/components/light-component.hpp"
#include "ecs/commands.hpp"
#include "game/game-context.hpp"
#include "game/states/game-states.hpp"
@ -44,13 +46,13 @@
#include "gl/texture-wrapping.hpp"
#include "renderer/model.hpp"
#include "renderer/passes/sky-pass.hpp"
#include "renderer/passes/shadow-map-pass.hpp"
#include "resources/resource-manager.hpp"
#include "scene/model-instance.hpp"
#include "scene/collection.hpp"
#include "scene/camera.hpp"
#include "scene/ambient-light.hpp"
#include "scene/directional-light.hpp"
#include "scene/directional-light.hpp"
#include "ecs/systems/control-system.hpp"
#include "ecs/systems/camera-system.hpp"
#include "ecs/systems/render-system.hpp"
@ -81,7 +83,7 @@ void play_state_enter(game_context* ctx)
}
else
{
ctx->biome = ctx->resource_manager->load<biome>("grassland.bio");
ctx->biome = ctx->resource_manager->load<biome>("forest.bio");
}
// Apply biome parameters to scene
@ -90,6 +92,31 @@ void play_state_enter(game_context* ctx)
sky_pass->set_sky_model(ctx->resource_manager->load<model>("sky-dome.mdl"));
sky_pass->set_moon_model(ctx->resource_manager->load<model>("moon.mdl"));
sky_pass->set_horizon_color({1.0f, 1.0f, 1.0f});
sky_pass->set_zenith_color({0.0f, 0.0f, 0.0f});
sky_pass->set_time_of_day(0.0f);
sky_pass->set_julian_day(0.0f);
sky_pass->set_observer_location(ctx->biome->location[0], ctx->biome->location[1], 0.0f);
sky_pass->set_moon_angular_radius(math::radians(1.0f));
sky_pass->set_sun_angular_radius(math::radians(1.0f));
scene::ambient_light* ambient = new scene::ambient_light();
ambient->set_color({1, 1, 1});
ambient->set_intensity(0.1f);
ambient->update_tweens();
ctx->overworld_scene->add_object(ambient);
scene::directional_light* sun = new scene::directional_light();
sun->set_color({1, 1, 1});
sun->set_intensity(4.0f);
sun->look_at({0, 1, 1}, {0, 0, 0}, {0, 1, 0});
sun->update_tweens();
ctx->overworld_scene->add_object(sun);
ctx->overworld_shadow_map_pass->set_light(sun);
ctx->weather_system->set_universal_time(0.0);
ctx->solar_system->set_universal_time(0.0);
@ -103,71 +130,9 @@ void play_state_enter(game_context* ctx)
resource_manager* resource_manager = ctx->resource_manager;
entt::registry& ecs_registry = *ctx->ecs_registry;
ctx->sun_direct->set_intensity(1.0f);
ctx->sun_direct->set_color({1, 1, 1});
// Create sun
{
ecs::orbit_component sun_orbit;
sun_orbit.elements.a = 1.0;
sun_orbit.elements.ec = 0.016709;
sun_orbit.elements.w = math::radians(282.9404);
sun_orbit.elements.ma = math::radians(356.0470);
sun_orbit.elements.i = 0.0;
sun_orbit.elements.om = 0.0;
sun_orbit.rate.a = 0.0;
sun_orbit.rate.ec = -1.151e-9;
sun_orbit.rate.w = math::radians(4.70935e-5);
sun_orbit.rate.ma = math::radians(0.9856002585);
sun_orbit.rate.i = 0.0;
sun_orbit.rate.om = 0.0;
ecs::transform_component sun_transform;
sun_transform.local = math::identity_transform<float>;
sun_transform.warp = true;
auto sun_entity = ecs_registry.create();
ecs_registry.assign<ecs::transform_component>(sun_entity, sun_transform);
ecs_registry.assign<ecs::orbit_component>(sun_entity, sun_orbit);
ctx->astronomy_system->set_sun(sun_entity);
}
// Create moon
{
ecs::orbit_component moon_orbit;
moon_orbit.elements.a = 0.00256955529;
moon_orbit.elements.ec = 0.0554;
moon_orbit.elements.w = math::radians(318.15);
moon_orbit.elements.ma = math::radians(135.27);
moon_orbit.elements.i = math::radians(5.16);
moon_orbit.elements.om = math::radians(125.08);
moon_orbit.rate.a = 0.0;
moon_orbit.rate.ec = 0.0;
moon_orbit.rate.w = math::radians(0.1643573223); // Argument of periapsis precession period, P_w
moon_orbit.rate.ma = math::radians(13.176358); // Longitude rate, n
moon_orbit.rate.i = 0.0;
moon_orbit.rate.om = math::radians(-18.6 / 365.2422); // Longitude of the ascending node precession period, P_node
ecs::transform_component moon_transform;
moon_transform.local = math::identity_transform<float>;
moon_transform.warp = true;
auto moon_entity = ecs_registry.create();
ecs_registry.assign<ecs::transform_component>(moon_entity, moon_transform);
ecs_registry.assign<ecs::orbit_component>(moon_entity, moon_orbit);
ctx->astronomy_system->set_moon(moon_entity);
}
// Load entity archetypes
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* nest_archetype = resource_manager->load<ecs::archetype>("harvester-nest.ent");
ecs::archetype* samara_archetype = resource_manager->load<ecs::archetype>("samara.ent");
ecs::archetype* forceps_archetype = resource_manager->load<ecs::archetype>("forceps.ent");
@ -176,14 +141,10 @@ void play_state_enter(game_context* ctx)
ecs::archetype* marker_archetype = resource_manager->load<ecs::archetype>("marker.ent");
ecs::archetype* container_archetype = resource_manager->load<ecs::archetype>("container.ent");
ecs::archetype* twig_archetype = resource_manager->load<ecs::archetype>("twig.ent");
ecs::archetype* larva_archetype = resource_manager->load<ecs::archetype>("larva.ent");
ecs::archetype* pebble_archetype = resource_manager->load<ecs::archetype>("pebble.ent");
ecs::archetype* larva_archetype = resource_manager->load<ecs::archetype>("ant-larva.ent");
ecs::archetype* flashlight_archetype = resource_manager->load<ecs::archetype>("flashlight.ent");
ecs::archetype* flashlight_light_cone_archetype = resource_manager->load<ecs::archetype>("flashlight-light-cone.ent");
ecs::archetype* lens_light_cone_archetype = resource_manager->load<ecs::archetype>("lens-light-cone.ent");
ecs::archetype* ant_head_archetype = resource_manager->load<ecs::archetype>("ant-head.ent");
ecs::archetype* dandelion_plant_archetype = resource_manager->load<ecs::archetype>("dandelion-plant.ent");
ecs::archetype* grassland_road_archetype = resource_manager->load<ecs::archetype>("grassland-road.ent");
// Create tools
forceps_archetype->assign(ecs_registry, ctx->forceps_entity);
@ -198,6 +159,7 @@ void play_state_enter(game_context* ctx)
auto flashlight_light_cone = flashlight_light_cone_archetype->create(ecs_registry);
ecs::command::parent(ecs_registry, flashlight_light_cone, ctx->flashlight_entity);
ecs::command::assign_render_layers(ecs_registry, ctx->flashlight_entity, 2);
ecs::command::assign_render_layers(ecs_registry, flashlight_light_cone, 2);
// Make lens tool's model instance unculled, so its shadow is always visible.
scene::model_instance* lens_model_instance = ctx->render_system->get_model_instance(ctx->lens_entity);
@ -211,8 +173,6 @@ void play_state_enter(game_context* ctx)
//ecs::command::bind_transform(ecs_registry, lens_light_cone, ctx->lens_entity);
ecs::command::parent(ecs_registry, lens_light_cone, ctx->lens_entity);
// Hide inactive tools
ecs::command::assign_render_layers(ecs_registry, ctx->forceps_entity, 0);
ecs::command::assign_render_layers(ecs_registry, ctx->brush_entity, 0);
@ -223,46 +183,10 @@ void play_state_enter(game_context* ctx)
// Activate brush tool
ctx->tool_system->set_active_tool(ctx->brush_entity);
// Create background
for (int i = 0; i < 4; ++i)
{
auto road_entity = grassland_road_archetype->create(ecs_registry);
auto& transform = ecs_registry.get<ecs::transform_component>(road_entity);
math::quaternion<float> rotation = math::angle_axis(math::half_pi<float> * static_cast<float>(i), float3{0, 1, 0});
float3 translation = rotation * float3{0, 0, 1600.0f};
transform.local = math::identity_transform<float>;
transform.local.rotation = rotation;
transform.local.translation = translation;
}
// Create ant-hill
auto ant_hill_entity = ant_hill_archetype->create(ecs_registry);
ecs::command::place(ecs_registry, ant_hill_entity, {0, 0});
// Generate pebbles
float pebble_radius = 300.0f;
int pebble_count = 20;
for (int i = 0; i < pebble_count; ++i)
{
float x = math::random(-pebble_radius, pebble_radius);
float z = math::random(-pebble_radius, pebble_radius);
auto pebble_entity = ant_head_archetype->create(ecs_registry);
auto& transform = ecs_registry.get<ecs::transform_component>(pebble_entity);
transform.local = math::identity_transform<float>;
transform.local.rotation = math::angle_axis(math::random(0.0f, math::two_pi<float>), {0, 1, 0});
transform.local.scale = float3{1, 1, 1} * math::random(0.75f, 1.25f);
ecs::command::place(ecs_registry, pebble_entity, {x, z});
}
// Create maple tree
//auto maple_tree_entity = maple_tree_archetype->create(ecs_registry);
//ecs::command::place(ecs_registry, maple_tree_entity, {300, 200});
// Creat nest
auto nest_entity = nest_archetype->create(ecs_registry);
@ -320,9 +244,6 @@ void play_state_enter(game_context* ctx)
ctx->overworld_camera->look_at({0, 0, 1}, {0, 0, 0}, {0, 1, 0});
ctx->camera_system->set_camera(ctx->overworld_camera);
auto ant_head = ant_head_archetype->create(ecs_registry);
ecs::command::place(ecs_registry, ant_head, {50, 0});
ctx->overworld_scene->update_tweens();
// Allocate a nest
@ -389,9 +310,6 @@ void play_state_enter(game_context* ctx)
//transform.transform.translation.y -= 1.0f;
}
auto dandelion_plant = dandelion_plant_archetype->create(ecs_registry);
ecs::command::place(ecs_registry, dandelion_plant, {55, -30});
ecs::control_system* control_system = ctx->control_system;
control_system->update(0.0, 0.0);
control_system->set_nest(nest);

+ 6
- 1
src/resources/model-loader.cpp View File

@ -512,7 +512,12 @@ model* resource_loader::load(resource_manager* resource_manager, PHYSFS_F
if (auto size_node = material_node.value().find("size"); size_node != material_node.value().end())
group_size = size_node.value().get<std::size_t>();
group_material = resource_manager->load<material>(group_name + ".mtl");
// Slugify material filename
std::string material_filename = group_name + ".mtl";
std::replace(material_filename.begin(), material_filename.end(), '_', '-');
// Load material from file
group_material = resource_manager->load<material>(material_filename);
model_group* model_group = model->add_group(group_name);
model_group->set_drawing_mode(gl::drawing_mode::triangles);

Loading…
Cancel
Save