...
 
Commits (3)
......@@ -24,8 +24,8 @@ void scene_model::setup_data(std::map<std::string,GLuint>& shaders, scene_struct
createResources();
setupCamera(scene);
setupSystems();
buildEntities(shaders);
setupSystems();
m_ecs.update<CollisionGridInitializer>(m_resources.collisionGrid);
auto& pointDrawer = PointDrawer::get();
......@@ -70,12 +70,14 @@ void scene_model::buildEntities(std::map<std::string,GLuint>& shaders)
{
EntityBuilder builder { m_ecs, m_resources };
builder.buildTerrain(shaders);
m_ground = builder.buildTerrain(shaders);
constexpr auto num_trees { 30 };
constexpr auto num_trees { 100 };
constexpr auto num_mushrooms { 100 };
constexpr auto num_billboards { 80 };
auto tree_positions = getForest(m_resources.terrainGeometry, num_trees, trunk_radius * 7.f);
auto mushroom_positions = getForest(m_resources.terrainGeometry, 70, mushroom_base_radius * 7.f);
auto billboard_grass_positions = getForest(m_resources.terrainGeometry, 40, 0.5f);
auto mushroom_positions = getForest(m_resources.terrainGeometry, num_mushrooms, mushroom_base_radius * 7.f);
auto billboard_grass_positions = getForest(m_resources.terrainGeometry, num_billboards, 0.5f);
const vec3 referencePlantationOffset { 0, 0, -0.1f };
for (auto const& position : tree_positions)
......@@ -124,20 +126,19 @@ void scene_model::logicLoop(std::map<std::string,GLuint>& shaders, scene_structu
handleKeyboardInput(m_resources.keyboardMapping, gui.window, m_ecs.get<PlayerControlComponent>(m_player));
handleMouseInput(m_lastMouseState, m_resources.mouseMapping, gui.window, m_ecs.get<PlayerControlComponent>(m_player));
m_ecs.update<ControlHandlingSystem>(dt, m_ecs, m_player);
m_ecs.update<GravitySystem>();
m_ecs.update<PhysicsSystem>(dt);
m_ecs.update<AnimationChooser>(m_resources.animations);
m_ecs.update<AnimationInterpolator>(dt);
m_ecs.update<AnimationApplier>();
//m_ecs.update<PositionUpdater::Transform2Collision>();
m_ecs.update<HierarchyPositionUpdater::Transform2Collision>();
m_ecs.update<GroundCollisionDetector>();
m_ecs.update<GroundCollisionResolver>(m_resources.collisionRates);
m_ecs.update<CollisionGridUpdater>(m_resources.collisionGrid);
m_ecs.update<CollisionDetector>(m_resources.collisionGrid);
m_ecs.update<CollisionResolver>(m_resources.collisionRates, m_ecs.getSystem<CollisionDetector>().collisions);
//m_ecs.update<PositionUpdater::Collision2Transform>();
m_ecs.update<HierarchyPositionUpdater::Collision2Transform>();
m_ecs.update<AIHandlingSystem>(m_ecs, timerEvent);
......@@ -191,8 +192,8 @@ void scene_model::renderLoop(std::map<std::string,GLuint>& shaders, scene_struct
void scene_model::setupTerrainGeometry()
{
auto xWidth = 20.f;
auto yWidth = 20.f;
auto xWidth = 60.f;
auto yWidth = 60.f;
std::vector<Hole> holes {
Hole { { 0., 0. }, 3, 0.5 }
, Hole { { 0.5, 0.5 }, -1.5, 0.15 }
......@@ -333,6 +334,10 @@ void scene_model::setupCamera(scene_structure& scene)
void scene_model::setupSystems()
{
m_ecs.getSystem<DeadEntityCollector>().terrainGeometry = &m_resources.terrainGeometry;
auto& farEntitiesDeactivator = m_ecs.getSystem<FarEntitiesDeactivator>();
farEntitiesDeactivator.m_ecs = &m_ecs;
farEntitiesDeactivator.sightRadius = 15.f;
farEntitiesDeactivator.m_ground = m_ground;
m_ecs.getSystem<GroundCollisionDetector>().terrainGeometry = &m_resources.terrainGeometry;
auto& groundCollisionResolver = m_ecs.getSystem<GroundCollisionResolver>();
......
......@@ -79,6 +79,7 @@ private:
Skybox m_skybox;
ecs::Entity m_player;
ecs::Entity m_aimCursor;
ecs::Entity m_ground;
static constexpr std::size_t gridResolution = 5;
......
......@@ -8,7 +8,7 @@
struct MyEcs : ecs::ecs<ecs::Components<HierarchyCollisionBoxComponent, TransformComponent, DerivedTransformComponent, RenderComponent, ArticulatedHierarchyComponent, CollisionComponent, ForceComponent, PhysicsComponent, PlayerControlComponent, RayComponent, AnimationComponent, AIPlayerComponent, PlayerComponent, CharacterDesignComponent>
, ecs::Systems<RayRender, RayTrajectory,
GravitySystem, PhysicsSystem, DeadEntityCollector,
GravitySystem, PhysicsSystem, DeadEntityCollector, FarEntitiesDeactivator,
PositionUpdater::Collision2Transform, PositionUpdater::Transform2Collision, HierarchyPositionUpdater::Collision2Transform, HierarchyPositionUpdater::Transform2Collision,
GroundCollisionDetector, GroundCollisionResolver, CollisionGridInitializer, CollisionGridUpdater, CollisionDetector, CollisionResolver,
BillboardOrientationSystem, RenderSystem, HierarchyRenderSystem, CollisionBoxesRenderer,
......
......@@ -28,5 +28,6 @@
#include "systems/ai_handling.hpp"
#include "systems/lockdown_system.hpp"
#include "systems/health_system.hpp"
#include "systems/far_entities_deactivator.hpp"
#endif // !SYSTEMS_HPP_INCLUDED
#include "far_entities_deactivator.hpp"
#include "../my_ecs.hpp"
using namespace vcl;
void FarEntitiesDeactivator::update(vec3 const& reference, TransformComponent const& transform)
{
assert(m_ecs);
if(transform.entity() == m_ground)
return;
auto projectZ = [](vcl::vec3 const& v) -> vec2 { return { v.x, v.y }; };
if(norm(projectZ(transform.position) - projectZ(reference)) > sightRadius)
m_ecs->deactivate(transform.entity());
else
m_ecs->activate(transform.entity());
}
#ifndef SYSTEMS_FAR_ENTITIES_DEACTIVATOR_HPP_INCLUDED
#define SYSTEMS_FAR_ENTITIES_DEACTIVATOR_HPP_INCLUDED
#include "vcl/vcl.hpp"
#include "ECS.hpp"
#include "../components.hpp"
struct MyEcs;
struct FarEntitiesDeactivator
{
public:
void update(vcl::vec3 const& reference, TransformComponent const& transform);
using Requirements = ecs::Requirements<ecs::Auto>;
using UpdatePolicy = ecs::OncePerEntity;
float sightRadius;
MyEcs* m_ecs;
ecs::Entity m_ground;
};
#endif // !SYSTEMS_FAR_ENTITIES_DEACTIVATOR_HPP_INCLUDED
\ No newline at end of file
Subproject commit 96bb59de97e5fbb60e55411791bdab27e9e0d7c7
Subproject commit 561cce1422d48bb177f5d1a909f4b1798c1faa93