Removed separate controller class

This commit is contained in:
2025-09-01 12:32:34 +03:00
parent e0045ffeb1
commit b434e516f0
5 changed files with 128 additions and 269 deletions

View File

@@ -269,6 +269,11 @@ class App : public OgreBites::ApplicationContext {
public Ogre::FrameListener {
App *mApp;
uint32_t control;
ECS::Vector2 mouse{ 0, 0 };
float wheel_y;
bool mouse_moved = false, wheel_moved = false;
public:
bool gui_active;
Ogre::Timer fps_timer;
@@ -293,26 +298,71 @@ class App : public OgreBites::ApplicationContext {
mApp->setWindowGrab(false);
return true;
}
OgreBites::Keycode key = evt.keysym.sym;
if (key == 'w')
control |= 1;
else if (key == 'a')
control |= 2;
else if (key == 's')
control |= 4;
else if (key == 'd')
control |= 8;
else if (key == OgreBites::SDLK_LSHIFT)
control |= 16;
if (key == 'w' || key == 'a' || key == 's' ||
key == 'd' || key == OgreBites::SDLK_LSHIFT)
return true;
return false;
}
bool keyReleased(const OgreBites::KeyboardEvent &evt) override
{
OgreBites::Keycode key = evt.keysym.sym;
if (gui_active)
return false;
if (key == 'w')
control &= ~1;
else if (key == 'a')
control &= ~2;
else if (key == 's')
control &= ~4;
else if (key == 'd')
control &= ~8;
else if (key == OgreBites::SDLK_LSHIFT)
control &= ~16;
if (key == 'w' || key == 'a' || key == 's' ||
key == 'd' || key == OgreBites::SDLK_LSHIFT)
return true;
return false;
}
bool mouseMoved(const OgreBites::MouseMotionEvent &evt)
bool mouseMoved(const OgreBites::MouseMotionEvent &evt) override
{
if (gui_active)
return false;
mouse.x = evt.xrel;
mouse.y = evt.yrel;
mouse_moved = true;
/* no special mouse handling */
return false;
return true;
}
bool mouseWheelRolled(const OgreBites::MouseWheelEvent &evt)
bool
mouseWheelRolled(const OgreBites::MouseWheelEvent &evt) override
{
if (gui_active)
return false;
/* no special mouse wheel handling */
wheel_y = evt.y;
wheel_moved = true;
return true;
}
bool
mousePressed(const OgreBites::MouseButtonEvent &evt) override
{
std::cout << "Mouse press " << (int)evt.button << " "
<< (int)evt.clicks << "\n";
if ((int)evt.button == 1)
control |= 256;
else
control &= ~256;
return false;
}
void update(float delta)
@@ -341,19 +391,26 @@ class App : public OgreBites::ApplicationContext {
fps_timer.reset();
}
update(evt.timeSinceLastFrame);
if (mApp->getCharacterController() && gui_active)
mApp->getCharacterController()->disableUpdates();
else if (mApp->getCharacterController() &&
!gui_active && mApp->isTerrainReady()) {
if (mApp->getCharacterController() && !gui_active &&
mApp->isTerrainReady()) {
OgreAssert(mApp->isTerrainReady(),
"terrain is not ready");
mApp->getCharacterController()->enableUpdates();
}
if (!gui_active) {
mApp->updateSun(evt.timeSinceLastFrame);
mApp->updateTerrain(evt.timeSinceLastFrame);
mApp->updateWater(evt.timeSinceLastFrame);
mApp->updateWorld(evt.timeSinceLastFrame);
ECS::Input &input =
ECS::get().get_mut<ECS::Input>();
input.control = control;
input.mouse = mouse;
mouse.x = 0;
mouse.y = 0;
input.wheel_y = wheel_y;
wheel_y = 0;
input.mouse_moved = mouse_moved;
input.wheel_moved = wheel_moved;
}
}
};
@@ -533,9 +590,19 @@ public:
void updateTerrain(float delta)
{
// Ogre::Vector3 pos = mCharacterController->getPosition();
Ogre::Vector3 pos(0, 0, 0);
const ECS::CharacterBase &ch =
getPlayer().get<ECS::CharacterBase>();
ECS::CharacterBody &body =
getPlayer().get_mut<ECS::CharacterBody>();
if (!body.checkGround) {
body.checkGround = true;
getPlayer().modified<ECS::CharacterBody>();
}
if (!ch.mBodyNode)
return;
Ogre::Vector3 pos = ch.mBodyNode->getPosition();
if (!mTerrainReady && m_terrain.isLoadedAt(pos) &&
mCharacterController->checkGround()) {
body.checkGroundResult) {
std::cout << "terrain ready\n";
mTerrainReady = true;
}
@@ -635,6 +702,12 @@ public:
{
return mCharacterController;
}
flecs::entity getPlayer() const
{
flecs::entity player =
ECS::get().lookup("ECS::CharacterModule::player");
return player;
}
};
void EditUI::buildings_editor()