120 lines
3.1 KiB
C++
120 lines
3.1 KiB
C++
#include <iostream>
|
|
#include <Ogre.h>
|
|
#include "GameData.h"
|
|
#include "Components.h"
|
|
#include "CharacterModule.h"
|
|
#include "WaterModule.h"
|
|
#include "TerrainModule.h"
|
|
#include "SunModule.h"
|
|
#include "GUIModule.h"
|
|
#include "LuaData.h"
|
|
#include "WorldMapModule.h"
|
|
#include "BoatModule.h"
|
|
#include "EventTriggerModule.h"
|
|
|
|
namespace ECS
|
|
{
|
|
static flecs::world ecs;
|
|
flecs::entity player;
|
|
void setup(Ogre::SceneManager *scnMgr, Ogre::Bullet::DynamicsWorld *world,
|
|
Ogre::SceneNode *cameraNode, Ogre::Camera *camera,
|
|
Ogre::RenderWindow *window)
|
|
{
|
|
std::cout << "Setup GameData\n";
|
|
ecs.component<EngineData>().add(flecs::Singleton);
|
|
ecs.component<GameData>().add(flecs::Singleton);
|
|
ecs.component<Input>().add(flecs::Singleton);
|
|
ecs.component<Camera>().add(flecs::Singleton);
|
|
ecs.component<InWater>();
|
|
ecs.component<WaterReady>().add(flecs::Singleton);
|
|
ecs.component<GroundCheckReady>().add(flecs::Singleton);
|
|
ecs.component<App>()
|
|
.on_add([](App &app) {
|
|
app.mInput = nullptr;
|
|
app.mGuiOverlay = nullptr;
|
|
app.listeners.clear();
|
|
})
|
|
.add(flecs::Singleton);
|
|
/* lots of things depend on it */
|
|
ecs.component<TerrainReady>().add(flecs::Singleton);
|
|
ecs.import <WaterModule>();
|
|
ecs.import <CharacterModule>();
|
|
ecs.import <TerrainModule>();
|
|
ecs.import <SunModule>();
|
|
ecs.import <GUIModule>();
|
|
ecs.import <LuaModule>();
|
|
ecs.import <WorldMapModule>();
|
|
ecs.import <LuaModule>();
|
|
ecs.import <BoatModule>();
|
|
ecs.import <EventTriggerModule>();
|
|
|
|
ecs.system<EngineData>("UpdateDelta")
|
|
.kind(flecs::OnUpdate)
|
|
.each([](EngineData &eng) {
|
|
eng.delta = ECS::get().delta_time();
|
|
});
|
|
ecs.system<EngineData>("UpdateDelay")
|
|
.kind(flecs::OnUpdate)
|
|
.with<TerrainReady>()
|
|
.with<WaterReady>()
|
|
.with<GroundCheckReady>()
|
|
.each([](EngineData &eng) {
|
|
if (eng.startupDelay >= 0.0f)
|
|
eng.startupDelay -= eng.delta;
|
|
#ifdef VDEBUG
|
|
if (ECS::get().has<GroundCheckReady>())
|
|
std::cout << "ground check ready\n";
|
|
#endif
|
|
});
|
|
ecs.system<EngineData>("CheckStatus")
|
|
.kind(flecs::OnUpdate)
|
|
.run([](flecs::iter &it) {
|
|
#ifdef VDEBUG
|
|
if (ECS::get().has<WaterReady>())
|
|
std::cout << "water ready\n";
|
|
if (ECS::get().has<TerrainReady>())
|
|
std::cout << "terrain ready\n";
|
|
if (ECS::get().has<GroundCheckReady>())
|
|
std::cout << "ground check ready\n";
|
|
#endif
|
|
});
|
|
ecs.set<EngineData>({ scnMgr, world, 0.0f, 5.0f,
|
|
(int)window->getWidth(),
|
|
(int)window->getHeight() });
|
|
ecs.set<Camera>({ cameraNode, camera, false });
|
|
ecs.add<GameData>();
|
|
ecs.add<Input>();
|
|
ecs.add<WaterSurface>();
|
|
ecs.set<Sun>({ nullptr, nullptr, nullptr, nullptr });
|
|
ecs.set<Terrain>({ nullptr,
|
|
nullptr,
|
|
nullptr,
|
|
nullptr,
|
|
nullptr,
|
|
nullptr,
|
|
false,
|
|
{ 0, 0, 0 } });
|
|
std::cout << "Setup GameData done\n";
|
|
|
|
/* Create player */
|
|
player = ecs.entity("player");
|
|
Ogre::Vector3 playerPos(0, 0, 4);
|
|
player.set<CharacterLocation>({ { 0, 0, 0, 1 }, playerPos });
|
|
player.set<CharacterConf>({ "normal-male.glb" });
|
|
player.add<Character>();
|
|
player.add<Player>();
|
|
}
|
|
void update(float delta)
|
|
{
|
|
ecs.progress(delta);
|
|
}
|
|
flecs::world get()
|
|
{
|
|
return ecs;
|
|
}
|
|
bool Vector3::zeroLength() const
|
|
{
|
|
float l = x * x + y * y + z * z;
|
|
return (l < 1e-06 * 1e-06);
|
|
}
|
|
} |