diff --git a/Game.cpp b/Game.cpp index bc2fb67..41fc7fc 100644 --- a/Game.cpp +++ b/Game.cpp @@ -185,6 +185,7 @@ class App : public OgreBites::ApplicationContext { ECS::Vector2 mouse{ 0, 0 }; float wheel_y; bool mouse_moved = false, wheel_moved = false; + float mInitDelay; public: Ogre::Timer fps_timer; @@ -195,6 +196,7 @@ class App : public OgreBites::ApplicationContext { , mApp(app) , fast(false) , control(0) + , mInitDelay(1.0) { } bool isGuiEnabled() @@ -322,6 +324,8 @@ class App : public OgreBites::ApplicationContext { } if (!isGuiEnabled()) { mApp->updateWorld(evt.timeSinceLastFrame); + if (mInitDelay >= 0.0f) + mInitDelay -= evt.timeSinceLastFrame; } if (!isGuiEnabled() && ECS::get().has()) { ECS::Input &input = diff --git a/src/gamedata/CharacterModule.cpp b/src/gamedata/CharacterModule.cpp index 101d286..aac9492 100644 --- a/src/gamedata/CharacterModule.cpp +++ b/src/gamedata/CharacterModule.cpp @@ -24,6 +24,8 @@ CharacterModule::CharacterModule(flecs::world &ecs) .kind(flecs::OnUpdate) .each([this](EngineData &eng, CharacterBase &ch) { ch.mTimer += eng.delta; + if (eng.startupDelay >= 0.0f) + eng.startupDelay -= eng.delta; }); ecs.system("HandleInput") .kind(flecs::OnUpdate) @@ -179,11 +181,12 @@ CharacterModule::CharacterModule(flecs::world &ecs) return; ch.mBoneMotion = ch.mRootBone->getPosition(); }); - ecs.system( - "HandleRootMotion") + ecs.system("HandleRootMotion") .kind(flecs::OnUpdate) - .each([this](flecs::entity e, CharacterBase &ch, - CharacterBody &body, AnimationControl &anim) { + .each([this](flecs::entity e, const EngineData &eng, + CharacterBase &ch, CharacterBody &body, + AnimationControl &anim) { float delta = e.world().delta_time(); if (!ch.mBodyNode) return; @@ -218,26 +221,29 @@ CharacterModule::CharacterModule(flecs::world &ecs) body.gvelocity.y, -2.5f, 2.5f); } else body.gvelocity += gravity * delta; - body.gvelocity *= 0.99; - velocity += body.gvelocity; - Ogre::Vector3 rotMotion = velocity * delta; - btVector3 currentPosition = - body.mGhostObject->getWorldTransform() - .getOrigin(); - is_on_floor = body.mController->isOnFloor(); - penetration = body.mController->isPenetrating(); - if (is_on_floor) - body.gvelocity = - Ogre::Vector3(0.0f, 0.0f, 0.0f); + if (eng.startupDelay < 0.0f) { + body.gvelocity *= 0.99; + velocity += body.gvelocity; + Ogre::Vector3 rotMotion = velocity * delta; + btVector3 currentPosition = + body.mGhostObject->getWorldTransform() + .getOrigin(); + is_on_floor = body.mController->isOnFloor(); + penetration = body.mController->isPenetrating(); + if (is_on_floor) + body.gvelocity = + Ogre::Vector3(0.0f, 0.0f, 0.0f); - btTransform from( - Ogre::Bullet::convert( - ch.mBodyNode->getOrientation()), - Ogre::Bullet::convert( - ch.mBodyNode->getPosition())); - ch.mBodyNode->setPosition(ch.mBodyNode->getPosition() + - rotMotion); - ch.mBoneMotion = Ogre::Vector3(0, 0, 0); + btTransform from( + Ogre::Bullet::convert( + ch.mBodyNode->getOrientation()), + Ogre::Bullet::convert( + ch.mBodyNode->getPosition())); + ch.mBodyNode->setPosition( + ch.mBodyNode->getPosition() + + rotMotion); + ch.mBoneMotion = Ogre::Vector3(0, 0, 0); + } }); ecs.system("HandlePlayerAnimations") .kind(flecs::OnUpdate) diff --git a/src/gamedata/Components.h b/src/gamedata/Components.h index 2350b8a..17d1105 100644 --- a/src/gamedata/Components.h +++ b/src/gamedata/Components.h @@ -17,6 +17,7 @@ struct EngineData { Ogre::SceneManager *mScnMgr; Ogre::Bullet::DynamicsWorld *mWorld; float delta; + float startupDelay; }; struct Vector3 { float x; diff --git a/src/gamedata/GameData.cpp b/src/gamedata/GameData.cpp index e21840b..23dc6d2 100644 --- a/src/gamedata/GameData.cpp +++ b/src/gamedata/GameData.cpp @@ -31,7 +31,7 @@ void setup(Ogre::SceneManager *scnMgr, Ogre::Bullet::DynamicsWorld *world, .each([](EngineData &eng) { eng.delta = ECS::get().delta_time(); }); - ecs.set({ scnMgr, world, 0.0f }); + ecs.set({ scnMgr, world, 0.0f, 0.0f }); ecs.set({ cameraNode, camera, false }); ecs.add(); ecs.add();