Water works!
This commit is contained in:
@@ -237,11 +237,14 @@ public:
|
||||
float maxH = terrain->getMaxHeight();
|
||||
int size = terrain->getSize();
|
||||
float worldSize = terrain->getWorldSize();
|
||||
if (!created || true) {
|
||||
if (true) {
|
||||
btRigidBody *body =
|
||||
mWorld->addTerrainRigidBody(
|
||||
group, x, y, 2,
|
||||
0x7ffffffd & (~16));
|
||||
OgreAssert(
|
||||
body,
|
||||
"Could not create RigidBody");
|
||||
Ogre::LogManager::getSingleton().logError(
|
||||
"created rigid body " +
|
||||
Ogre::StringConverter::toString(
|
||||
@@ -278,6 +281,11 @@ public:
|
||||
output.push_back(collider_queue.front());
|
||||
collider_queue.pop_front();
|
||||
}
|
||||
if (collider_queue.empty() &&
|
||||
!ECS::get<Terrain>().mTerrainReady) {
|
||||
ECS::get_mut<Terrain>().mTerrainReady = true;
|
||||
ECS::modified<Terrain>();
|
||||
}
|
||||
}
|
||||
collider_queue = output;
|
||||
}
|
||||
@@ -328,7 +336,7 @@ TerrainModule::TerrainModule(flecs::world &ecs)
|
||||
.each([](const EngineData &eng, const Camera &camera,
|
||||
const Sun &sun, Terrain &terrain,
|
||||
TerrainPrivate &priv) {
|
||||
if (!terrain.mTerrainGroup) {
|
||||
if (!terrain.mTerrainGroup && sun.mSun && eng.mScnMgr) {
|
||||
std::cout << "Terrain setup\n";
|
||||
if (!priv.mDummyPageProvider)
|
||||
priv.mDummyPageProvider =
|
||||
@@ -338,6 +346,9 @@ TerrainModule::TerrainModule(flecs::world &ecs)
|
||||
terrain.mTerrainGlobals =
|
||||
OGRE_NEW Ogre::TerrainGlobalOptions();
|
||||
|
||||
OgreAssert(terrain.mTerrainGlobals,
|
||||
"Failed to allocate global options");
|
||||
|
||||
Ogre::LogManager::getSingleton().setMinLogLevel(
|
||||
Ogre::LML_TRIVIAL);
|
||||
|
||||
@@ -423,47 +434,14 @@ TerrainModule::TerrainModule(flecs::world &ecs)
|
||||
terrain.mTerrainGroup->freeTemporaryResources();
|
||||
std::cout << "Terrain setup done\n";
|
||||
}
|
||||
bool playerCheck = false;
|
||||
ECS::get()
|
||||
.query_builder<CharacterBase, CharacterBody>()
|
||||
.with<Character>()
|
||||
.with<Player>()
|
||||
.each([&playerCheck,
|
||||
terrain](flecs::entity e,
|
||||
CharacterBase &ch,
|
||||
CharacterBody &body) {
|
||||
if (!body.checkGround)
|
||||
body.checkGround = true;
|
||||
if (ch.mBodyNode &&
|
||||
body.checkGroundResult) {
|
||||
long x, y;
|
||||
Ogre::Vector3 pos =
|
||||
ch.mBodyNode
|
||||
->getPosition();
|
||||
terrain.mTerrainGroup
|
||||
->convertWorldPositionToTerrainSlot(
|
||||
pos, &x, &y);
|
||||
if (terrain.mTerrainGroup
|
||||
->getTerrain(x,
|
||||
y) &&
|
||||
terrain.mTerrainGroup
|
||||
->getTerrain(x, y)
|
||||
->isLoaded())
|
||||
playerCheck = true;
|
||||
}
|
||||
});
|
||||
if (playerCheck)
|
||||
terrain.mTerrainReady = true;
|
||||
if (priv.mSunUpdate.getMilliseconds() > 1000) {
|
||||
Ogre::TerrainGlobalOptions::getSingleton()
|
||||
.setCompositeMapAmbient(
|
||||
eng.mScnMgr->getAmbientLight());
|
||||
Ogre::TerrainGlobalOptions::getSingleton()
|
||||
.setCompositeMapDiffuse(
|
||||
sun.mSun->getDiffuseColour());
|
||||
Ogre::TerrainGlobalOptions::getSingleton()
|
||||
.setLightMapDirection(
|
||||
sun.mSun->getDerivedDirection());
|
||||
if (sun.mSun &&
|
||||
priv.mSunUpdate.getMilliseconds() > 1000) {
|
||||
terrain.mTerrainGlobals->setCompositeMapAmbient(
|
||||
eng.mScnMgr->getAmbientLight());
|
||||
terrain.mTerrainGlobals->setCompositeMapDiffuse(
|
||||
sun.mSun->getDiffuseColour());
|
||||
terrain.mTerrainGlobals->setLightMapDirection(
|
||||
sun.mSun->getDerivedDirection());
|
||||
std::cout << "sun pitch: "
|
||||
<< sun.mSunNode->getOrientation()
|
||||
.getPitch()
|
||||
@@ -471,5 +449,24 @@ TerrainModule::TerrainModule(flecs::world &ecs)
|
||||
priv.mSunUpdate.reset();
|
||||
}
|
||||
});
|
||||
ecs.system<const CharacterBase, const Terrain>("UpdateTerrainStatus")
|
||||
.kind(flecs::OnUpdate)
|
||||
.without<TerrainReady>()
|
||||
.each([](const CharacterBase &ch, const Terrain &terrain) {
|
||||
std::cout << "mTerrainReady: " << terrain.mTerrainReady
|
||||
<< "\n";
|
||||
std::cout << "mBodyNode: " << ch.mBodyNode << "\n";
|
||||
if (ch.mBodyNode && terrain.mTerrainReady) {
|
||||
long x, y;
|
||||
Ogre::Vector3 pos = ch.mBodyNode->getPosition();
|
||||
terrain.mTerrainGroup
|
||||
->convertWorldPositionToTerrainSlot(
|
||||
pos, &x, &y);
|
||||
if (terrain.mTerrainGroup->getTerrain(x, y) &&
|
||||
terrain.mTerrainGroup->getTerrain(x, y)
|
||||
->isLoaded())
|
||||
ECS::get().add<TerrainReady>();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user