Converted to ECS, physics fix

This commit is contained in:
2025-09-02 16:07:03 +03:00
parent b434e516f0
commit 847aab6ed0
12 changed files with 766 additions and 639 deletions

View File

@@ -12,8 +12,9 @@
#include "src/terrain/terrain.h"
#include "water/water.h"
#include "src/characters/controller.h"
#include "GameData.h"
#include "Components.h"
#include "CharacterModule.h"
#include "sound.h"
class App;
class SkyRenderer : public Ogre::SceneManager::Listener {
@@ -246,13 +247,12 @@ public:
float panel_width;
void initGui();
};
#define WATER
#undef WATER
class App : public OgreBites::ApplicationContext {
std::unique_ptr<Ogre::Bullet::DynamicsWorld> mDynWorld;
std::unique_ptr<Ogre::Bullet::DebugDrawer> mDbgDraw;
Ogre::SceneNode *mCameraNode, *mCameraPivot, *mCameraGoal;
Ogre::Camera *mCamera;
CharacterController *mCharacterController;
Ogre::Real mPivotPitch;
Ogre::SceneManager *mScnMgr;
OgreBites::InputListenerChain mInput;
@@ -284,6 +284,7 @@ class App : public OgreBites::ApplicationContext {
, mApp(app)
, gui_active(false)
, fast(false)
, control(0)
{
}
bool keyPressed(const OgreBites::KeyboardEvent &evt) override
@@ -391,8 +392,7 @@ class App : public OgreBites::ApplicationContext {
fps_timer.reset();
}
update(evt.timeSinceLastFrame);
if (mApp->getCharacterController() && !gui_active &&
mApp->isTerrainReady()) {
if (!gui_active && mApp->isTerrainReady()) {
OgreAssert(mApp->isTerrainReady(),
"terrain is not ready");
}
@@ -424,7 +424,6 @@ public:
, mDynWorld(new Ogre::Bullet::DynamicsWorld(
Ogre::Vector3(0, -9.8, 0)))
, m_terrain(mDynWorld->getBtWorld())
, mCharacterController(nullptr)
, mTerrainReady(false)
{
}
@@ -529,9 +528,6 @@ public:
void setupPlayer()
{
OgreAssert(mDynWorld.get(), "No physics world controller");
mCharacterController = new CharacterController(
mCameraNode, mCamera, mScnMgr, mDynWorld.get());
OgreAssert(mCharacterController, "No character controller");
}
Ogre::SceneManager *getSceneManager()
{
@@ -632,9 +628,10 @@ public:
}
void setupInput()
{
mInput = OgreBites::InputListenerChain(
{ getImGuiInputListener(), &mKbd,
mCharacterController });
mInput = OgreBites::InputListenerChain({
getImGuiInputListener(),
&mKbd,
});
addInputListener(&mInput);
}
void createContent()
@@ -698,10 +695,6 @@ public:
m_terrain.setupTerrain(mCamera, mSun, mDynWorld.get(),
mDbgDraw.get());
}
CharacterController *getCharacterController()
{
return mCharacterController;
}
flecs::entity getPlayer() const
{
flecs::entity player =