Updates
This commit is contained in:
692
Game.cpp
692
Game.cpp
@@ -10,11 +10,12 @@
|
||||
#include <OgreTimer.h>
|
||||
#include <OgreMeshLodGenerator.h>
|
||||
|
||||
#include "src/terrain/terrain.h"
|
||||
#include "water/water.h"
|
||||
// #include "water/water.h"
|
||||
#include "GameData.h"
|
||||
#include "Components.h"
|
||||
#include "CharacterModule.h"
|
||||
#include "TerrainModule.h"
|
||||
#include "GUIModule.h"
|
||||
#include "sound.h"
|
||||
class App;
|
||||
class SkyRenderer : public Ogre::SceneManager::Listener {
|
||||
@@ -166,88 +167,6 @@ public:
|
||||
mSkyBoxGenParameters.skyBoxDistance = distance;
|
||||
}
|
||||
};
|
||||
|
||||
class EditUI : public Ogre::RenderTargetListener {
|
||||
App *m_app;
|
||||
Ogre::SceneManager *mScnMgr;
|
||||
Ogre::ImGuiOverlay *mGuiOverlay;
|
||||
OgreBites::ImGuiInputListener *mGuiListener;
|
||||
void
|
||||
preViewportUpdate(const Ogre::RenderTargetViewportEvent &evt) override
|
||||
{
|
||||
preview(evt);
|
||||
}
|
||||
|
||||
public:
|
||||
EditUI(App *app)
|
||||
: Ogre::RenderTargetListener()
|
||||
, m_app(app)
|
||||
{
|
||||
}
|
||||
|
||||
void position_editor(Ogre::SceneNode *node)
|
||||
{
|
||||
Ogre::Vector3 position = node->getPosition();
|
||||
float v[3] = { position.x, position.y, position.z };
|
||||
ImGui::InputFloat3("position", v);
|
||||
position.x = v[0];
|
||||
position.y = v[1];
|
||||
position.z = v[2];
|
||||
node->setPosition(position);
|
||||
}
|
||||
void orientation_editor(Ogre::SceneNode *node)
|
||||
{
|
||||
Ogre::Quaternion q = node->getOrientation();
|
||||
float yaw = Ogre::Radian(q.getYaw()).valueDegrees();
|
||||
float pitch = Ogre::Radian(q.getPitch()).valueDegrees();
|
||||
float roll = Ogre::Radian(q.getRoll()).valueDegrees();
|
||||
bool m1 = ImGui::InputFloat("yaw", &yaw);
|
||||
bool m2 = ImGui::InputFloat("pitch", &pitch);
|
||||
bool m3 = ImGui::InputFloat("roll", &roll);
|
||||
if (m1 || m2 || m3) {
|
||||
Ogre::Quaternion q1(Ogre::Radian(Ogre::Degree(yaw)),
|
||||
Ogre::Vector3::UNIT_Y);
|
||||
Ogre::Quaternion q2(Ogre::Degree(pitch),
|
||||
Ogre::Vector3::UNIT_X);
|
||||
Ogre::Quaternion q3(Ogre::Degree(roll),
|
||||
Ogre::Vector3::UNIT_Z);
|
||||
node->setOrientation(q1 * q2 * q3);
|
||||
}
|
||||
}
|
||||
void attachments_editor(Ogre::SceneNode *node)
|
||||
{
|
||||
const Ogre::SceneNode::ObjectMap &pmap =
|
||||
node->getAttachedObjects();
|
||||
int i;
|
||||
for (i = 0; i < pmap.size(); i++) {
|
||||
const Ogre::MovableObject *mobj = pmap[i];
|
||||
const Ogre::String &pname = mobj->getName();
|
||||
ImGui::Text("Name: %s", pname.c_str());
|
||||
}
|
||||
}
|
||||
std::vector<Ogre::String> glb_names;
|
||||
void init_glb_list()
|
||||
{
|
||||
int i;
|
||||
|
||||
const std::vector<Ogre::String> &groups =
|
||||
Ogre::ResourceGroupManager::getSingleton()
|
||||
.getResourceGroups();
|
||||
for (i = 0; i < groups.size(); i++) {
|
||||
std::vector<Ogre::String> names =
|
||||
*Ogre::ResourceGroupManager::getSingleton()
|
||||
.findResourceNames(groups[i], "*.glb");
|
||||
glb_names.insert(glb_names.end(), names.begin(),
|
||||
names.end());
|
||||
}
|
||||
}
|
||||
void buildings_editor();
|
||||
void buttons_panel();
|
||||
void preview(const Ogre::RenderTargetViewportEvent &evt);
|
||||
float panel_width;
|
||||
void initGui();
|
||||
};
|
||||
#undef WATER
|
||||
class App : public OgreBites::ApplicationContext {
|
||||
std::unique_ptr<Ogre::Bullet::DynamicsWorld> mDynWorld;
|
||||
std::unique_ptr<Ogre::Bullet::DebugDrawer> mDbgDraw;
|
||||
@@ -255,16 +174,9 @@ class App : public OgreBites::ApplicationContext {
|
||||
Ogre::Camera *mCamera;
|
||||
Ogre::Real mPivotPitch;
|
||||
Ogre::SceneManager *mScnMgr;
|
||||
OgreBites::InputListenerChain mInput;
|
||||
Ogre::Viewport *mViewport;
|
||||
EditUI m_edit_ui;
|
||||
TerrainSetup m_terrain;
|
||||
Ogre::Light *mSun;
|
||||
SkyBoxRenderer *sky;
|
||||
#ifdef WATER
|
||||
Water m_water;
|
||||
#endif
|
||||
bool mTerrainReady;
|
||||
bool mGrab;
|
||||
class KeyboardListener : public OgreBites::InputListener,
|
||||
public Ogre::FrameListener {
|
||||
App *mApp;
|
||||
@@ -275,28 +187,40 @@ class App : public OgreBites::ApplicationContext {
|
||||
bool mouse_moved = false, wheel_moved = false;
|
||||
|
||||
public:
|
||||
bool gui_active;
|
||||
Ogre::Timer fps_timer;
|
||||
bool fast;
|
||||
KeyboardListener(App *app)
|
||||
: OgreBites::InputListener()
|
||||
, Ogre::FrameListener()
|
||||
, mApp(app)
|
||||
, gui_active(false)
|
||||
, fast(false)
|
||||
, control(0)
|
||||
{
|
||||
}
|
||||
bool isGuiEnabled()
|
||||
{
|
||||
if (!ECS::get().has<ECS::GUI>())
|
||||
return false;
|
||||
return (ECS::get().get<ECS::GUI>().enabled);
|
||||
}
|
||||
void setGuiEnabled(bool value)
|
||||
{
|
||||
if (!ECS::get().has<ECS::GUI>())
|
||||
return;
|
||||
ECS::get().get_mut<ECS::GUI>().enabled = value;
|
||||
ECS::get().modified<ECS::GUI>();
|
||||
}
|
||||
bool keyPressed(const OgreBites::KeyboardEvent &evt) override
|
||||
{
|
||||
bool updated = false;
|
||||
if (gui_active)
|
||||
if (isGuiEnabled())
|
||||
return false;
|
||||
if (evt.keysym.sym == OgreBites::SDLK_ESCAPE) {
|
||||
gui_active = true;
|
||||
// std::cout << "Escape!\n";
|
||||
// Ogre::Root::getSingleton().queueEndRendering();
|
||||
mApp->setWindowGrab(false);
|
||||
OgreAssert(ECS::get().has<ECS::GUI>(), "");
|
||||
setGuiEnabled(true);
|
||||
if (ECS::get().has<ECS::GUI>())
|
||||
ECS::get<ECS::GUI>().setWindowGrab(
|
||||
false);
|
||||
return true;
|
||||
}
|
||||
OgreBites::Keycode key = evt.keysym.sym;
|
||||
@@ -318,7 +242,7 @@ class App : public OgreBites::ApplicationContext {
|
||||
bool keyReleased(const OgreBites::KeyboardEvent &evt) override
|
||||
{
|
||||
OgreBites::Keycode key = evt.keysym.sym;
|
||||
if (gui_active)
|
||||
if (isGuiEnabled())
|
||||
return false;
|
||||
if (key == 'w')
|
||||
control &= ~1;
|
||||
@@ -337,7 +261,7 @@ class App : public OgreBites::ApplicationContext {
|
||||
}
|
||||
bool mouseMoved(const OgreBites::MouseMotionEvent &evt) override
|
||||
{
|
||||
if (gui_active)
|
||||
if (isGuiEnabled())
|
||||
return false;
|
||||
mouse.x = evt.xrel;
|
||||
mouse.y = evt.yrel;
|
||||
@@ -348,7 +272,7 @@ class App : public OgreBites::ApplicationContext {
|
||||
bool
|
||||
mouseWheelRolled(const OgreBites::MouseWheelEvent &evt) override
|
||||
{
|
||||
if (gui_active)
|
||||
if (isGuiEnabled())
|
||||
return false;
|
||||
/* no special mouse wheel handling */
|
||||
wheel_y = evt.y;
|
||||
@@ -392,15 +316,14 @@ class App : public OgreBites::ApplicationContext {
|
||||
fps_timer.reset();
|
||||
}
|
||||
update(evt.timeSinceLastFrame);
|
||||
if (!gui_active && mApp->isTerrainReady()) {
|
||||
if (!isGuiEnabled() && mApp->isTerrainReady()) {
|
||||
OgreAssert(mApp->isTerrainReady(),
|
||||
"terrain is not ready");
|
||||
}
|
||||
if (!gui_active) {
|
||||
mApp->updateSun(evt.timeSinceLastFrame);
|
||||
mApp->updateTerrain(evt.timeSinceLastFrame);
|
||||
mApp->updateWater(evt.timeSinceLastFrame);
|
||||
if (!isGuiEnabled()) {
|
||||
mApp->updateWorld(evt.timeSinceLastFrame);
|
||||
}
|
||||
if (!isGuiEnabled() && ECS::get().has<ECS::Input>()) {
|
||||
ECS::Input &input =
|
||||
ECS::get().get_mut<ECS::Input>();
|
||||
input.control = control;
|
||||
@@ -420,11 +343,9 @@ public:
|
||||
App()
|
||||
: OgreBites::ApplicationContext("ChoroGame")
|
||||
, mKbd(this)
|
||||
, m_edit_ui(this)
|
||||
, mDynWorld(new Ogre::Bullet::DynamicsWorld(
|
||||
Ogre::Vector3(0, -9.8, 0)))
|
||||
, m_terrain(mDynWorld->getBtWorld())
|
||||
, mTerrainReady(false)
|
||||
, mGrab(false)
|
||||
{
|
||||
}
|
||||
virtual ~App()
|
||||
@@ -443,6 +364,10 @@ public:
|
||||
mDbgDraw.reset(new Ogre::Bullet::DebugDrawer(
|
||||
mScnMgr->getRootSceneNode(), mDynWorld->getBtWorld()));
|
||||
}
|
||||
bool isWindowGrab()
|
||||
{
|
||||
return mGrab;
|
||||
}
|
||||
void locateResources() override
|
||||
{
|
||||
Ogre::ResourceGroupManager::getSingleton().createResourceGroup(
|
||||
@@ -452,13 +377,10 @@ public:
|
||||
void loadResources() override
|
||||
{
|
||||
}
|
||||
void dump_water()
|
||||
void setWindowGrab(bool grab = true)
|
||||
{
|
||||
#if 0
|
||||
#ifdef WATER
|
||||
m_water.dump_textures();
|
||||
#endif
|
||||
#endif
|
||||
mGrab = grab;
|
||||
ApplicationContextBase::setWindowGrab(grab);
|
||||
}
|
||||
|
||||
void initCamera()
|
||||
@@ -508,10 +430,6 @@ public:
|
||||
std::cout << "Init camera" << "\n";
|
||||
initCamera();
|
||||
std::cout << "Set up water" << "\n";
|
||||
#ifdef WATER
|
||||
m_water.createWater(getRenderWindow(), mCamera,
|
||||
mDynWorld.get());
|
||||
#endif
|
||||
std::cout << "Set up cursor" << "\n";
|
||||
Ogre::ResourceGroupManager::getSingleton()
|
||||
.initialiseAllResourceGroups();
|
||||
@@ -519,95 +437,20 @@ public:
|
||||
// setupCursor();
|
||||
std::cout << "Create content" << "\n";
|
||||
createContent();
|
||||
std::cout << "Setup terrain" << "\n";
|
||||
setupTerrain();
|
||||
#ifdef WATER
|
||||
m_water.init();
|
||||
#endif
|
||||
setupPlayer();
|
||||
std::cout << "Setup input" << "\n";
|
||||
setupInput();
|
||||
}
|
||||
void setupPlayer()
|
||||
{
|
||||
OgreAssert(mDynWorld.get(), "No physics world controller");
|
||||
std::cout << "Setup done" << "\n";
|
||||
}
|
||||
Ogre::SceneManager *getSceneManager()
|
||||
{
|
||||
return mScnMgr;
|
||||
}
|
||||
Ogre::SceneNode *mSunGoal;
|
||||
Ogre::SceneNode *mSunNode;
|
||||
Ogre::SceneNode *mSunTarget;
|
||||
Ogre::Timer mSunUpdate;
|
||||
void createSun()
|
||||
{
|
||||
Ogre::Light *light = mScnMgr->createLight("Sun");
|
||||
mSunNode = mScnMgr->getRootSceneNode()->createChildSceneNode(
|
||||
"SunPivot");
|
||||
mSunGoal = mScnMgr->getRootSceneNode()->createChildSceneNode(
|
||||
"SunGoal");
|
||||
mSunTarget = mSunGoal->createChildSceneNode(
|
||||
"SunGoalTarget",
|
||||
Ogre::Vector3(100.0f, -400.0f, -400.0f),
|
||||
Ogre::Quaternion::IDENTITY);
|
||||
mSunNode->attachObject(light);
|
||||
light->setType(Ogre::Light::LT_DIRECTIONAL);
|
||||
light->setDiffuseColour(Ogre::ColourValue::White);
|
||||
light->setSpecularColour(Ogre::ColourValue(0.4, 0.4, 0.4));
|
||||
mSunNode->setDirection(Ogre::Vector3(100.0f, -400.0f, -400.f));
|
||||
mSun = light;
|
||||
}
|
||||
void updateSun(float delta)
|
||||
{
|
||||
static const float sun_speed = 1.0f;
|
||||
float uangle = M_PI * 2.0f / 24.0f / 60.0f;
|
||||
mSunNode->pitch(Ogre::Radian(uangle) * sun_speed * delta);
|
||||
if (mSunUpdate.getMilliseconds() > 1000) {
|
||||
Ogre::TerrainGlobalOptions::getSingleton()
|
||||
.setCompositeMapAmbient(
|
||||
mScnMgr->getAmbientLight());
|
||||
Ogre::TerrainGlobalOptions::getSingleton()
|
||||
.setCompositeMapDiffuse(
|
||||
mSun->getDiffuseColour());
|
||||
Ogre::TerrainGlobalOptions::getSingleton()
|
||||
.setLightMapDirection(
|
||||
mSun->getDerivedDirection());
|
||||
std::cout << "sun pitch: "
|
||||
<< mSunNode->getOrientation().getPitch()
|
||||
<< "\n";
|
||||
mSunUpdate.reset();
|
||||
}
|
||||
if (mSunNode->getOrientation().getPitch().valueRadians() > 0)
|
||||
mScnMgr->setAmbientLight(
|
||||
Ogre::ColourValue(0.1f, 0.1f, 0.4f, 1.0f));
|
||||
else
|
||||
mScnMgr->setAmbientLight(
|
||||
Ogre::ColourValue(0.2f, 0.2f, 0.2f, 1.0f));
|
||||
}
|
||||
Ogre::Timer mTerrainUpd;
|
||||
void updateTerrain(float delta)
|
||||
{
|
||||
// Ogre::Vector3 pos = mCharacterController->getPosition();
|
||||
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) &&
|
||||
body.checkGroundResult) {
|
||||
std::cout << "terrain ready\n";
|
||||
mTerrainReady = true;
|
||||
}
|
||||
}
|
||||
bool isTerrainReady()
|
||||
{
|
||||
return mTerrainReady;
|
||||
if (ECS::get().has<ECS::Terrain>())
|
||||
return ECS::get().get<ECS::Terrain>().mTerrainReady;
|
||||
return false;
|
||||
}
|
||||
// TODO: implement rough water level calculation
|
||||
float getWaterLevel(const Ogre::Vector3 &position)
|
||||
@@ -620,30 +463,255 @@ public:
|
||||
void updateWorld(float delta)
|
||||
{
|
||||
mDynWorld->getBtWorld()->stepSimulation(delta, 4);
|
||||
mDbgDraw->update();
|
||||
/* Update window grab */
|
||||
if (ECS::get().has<ECS::GUI>() &&
|
||||
ECS::get().get<ECS::GUI>().grabChanged) {
|
||||
setWindowGrab(ECS::get().get<ECS::GUI>().grab);
|
||||
ECS::get().get_mut<ECS::GUI>().grabChanged = false;
|
||||
ECS::get().modified<ECS::GUI>();
|
||||
}
|
||||
|
||||
ECS::update(delta);
|
||||
// mDbgDraw->update();
|
||||
}
|
||||
void updateWater(float delta)
|
||||
{
|
||||
#ifdef WATER
|
||||
m_water.updateWater(delta);
|
||||
#endif
|
||||
}
|
||||
class InputListenerChainFlexible : public OgreBites::InputListener {
|
||||
protected:
|
||||
std::vector<OgreBites::InputListener *> mListenerChain;
|
||||
|
||||
public:
|
||||
InputListenerChainFlexible()
|
||||
{
|
||||
}
|
||||
InputListenerChainFlexible(std::vector<InputListener *> chain)
|
||||
: mListenerChain(chain)
|
||||
{
|
||||
}
|
||||
|
||||
void add(OgreBites::InputListener *listener)
|
||||
{
|
||||
mListenerChain.push_back(listener);
|
||||
}
|
||||
void erase(OgreBites::InputListener *listener)
|
||||
{
|
||||
mListenerChain.erase(std::find(mListenerChain.begin(),
|
||||
mListenerChain.end(),
|
||||
listener));
|
||||
}
|
||||
bool empty() const
|
||||
{
|
||||
return mListenerChain.empty();
|
||||
}
|
||||
|
||||
InputListenerChainFlexible &
|
||||
operator=(const InputListenerChainFlexible &o)
|
||||
{
|
||||
mListenerChain = o.mListenerChain;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void frameRendered(const Ogre::FrameEvent &evt) override
|
||||
{
|
||||
for (auto listener : mListenerChain)
|
||||
listener->frameRendered(evt);
|
||||
}
|
||||
|
||||
bool keyPressed(const OgreBites::KeyboardEvent &evt) override
|
||||
{
|
||||
for (auto listner : mListenerChain) {
|
||||
if (listner->keyPressed(evt))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool keyReleased(const OgreBites::KeyboardEvent &evt) override
|
||||
{
|
||||
for (auto listner : mListenerChain) {
|
||||
if (listner->keyReleased(evt))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool touchMoved(const OgreBites::TouchFingerEvent &evt) override
|
||||
{
|
||||
for (auto listner : mListenerChain) {
|
||||
if (listner->touchMoved(evt))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool
|
||||
touchPressed(const OgreBites::TouchFingerEvent &evt) override
|
||||
{
|
||||
for (auto listner : mListenerChain) {
|
||||
if (listner->touchPressed(evt))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool
|
||||
touchReleased(const OgreBites::TouchFingerEvent &evt) override
|
||||
{
|
||||
for (auto listner : mListenerChain) {
|
||||
if (listner->touchReleased(evt))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool mouseMoved(const OgreBites::MouseMotionEvent &evt) override
|
||||
{
|
||||
for (auto listner : mListenerChain) {
|
||||
if (listner->mouseMoved(evt))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool
|
||||
mouseWheelRolled(const OgreBites::MouseWheelEvent &evt) override
|
||||
{
|
||||
for (auto listner : mListenerChain) {
|
||||
if (listner->mouseWheelRolled(evt))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool
|
||||
mousePressed(const OgreBites::MouseButtonEvent &evt) override
|
||||
{
|
||||
for (auto listner : mListenerChain) {
|
||||
if (listner->mousePressed(evt))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool
|
||||
mouseReleased(const OgreBites::MouseButtonEvent &evt) override
|
||||
{
|
||||
for (auto listner : mListenerChain) {
|
||||
if (listner->mouseReleased(evt))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool textInput(const OgreBites::TextInputEvent &evt) override
|
||||
{
|
||||
for (auto listner : mListenerChain) {
|
||||
if (listner->textInput(evt))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
flecs::entity input_update;
|
||||
flecs::entity find_wait_gui;
|
||||
void setupInput()
|
||||
{
|
||||
mInput = OgreBites::InputListenerChain({
|
||||
getImGuiInputListener(),
|
||||
&mKbd,
|
||||
});
|
||||
addInputListener(&mInput);
|
||||
ECS::App &p = ECS::get().get_mut<ECS::App>();
|
||||
ECS::get()
|
||||
.observer<ECS::GUI>("UpdateGrab")
|
||||
.event(flecs::OnSet)
|
||||
.each([this](flecs::entity e, ECS::GUI &gui) {
|
||||
if (gui.grabChanged)
|
||||
setWindowGrab(gui.grab);
|
||||
std::cout << "grab: " << gui.grab << "\n";
|
||||
std::cout << "GUI enabled: " << gui.enabled
|
||||
<< "\n";
|
||||
std::cout << "grabbed: " << isWindowGrab()
|
||||
<< "\n";
|
||||
std::cout
|
||||
<< "UI active: " << mKbd.isGuiEnabled()
|
||||
<< "\n";
|
||||
});
|
||||
ECS::get()
|
||||
.observer<ECS::App>("UpdateInputListener")
|
||||
.event(flecs::OnSet)
|
||||
.each([this](flecs::entity e, ECS::App &app) {
|
||||
if (app.mInput)
|
||||
removeInputListener(app.mInput);
|
||||
delete app.mInput;
|
||||
app.mInput = new OgreBites::InputListenerChain(
|
||||
app.listeners);
|
||||
addInputListener(app.mInput);
|
||||
std::cout << "Update listeners\n";
|
||||
});
|
||||
#if 0
|
||||
ECS::get()
|
||||
.observer<ECS::GUI, ECS::App>("SetInputListener2")
|
||||
.event(flecs::OnSet)
|
||||
.each([this](ECS::GUI &gui, ECS::App &app) {
|
||||
if (gui.mGuiInpitListener &&
|
||||
app.listeners.size() == 1) {
|
||||
app.listeners.clear();
|
||||
app.listeners.push_back(
|
||||
gui.mGuiInpitListener);
|
||||
app.listeners.push_back(&mKbd);
|
||||
ECS::modified<ECS::App>();
|
||||
}
|
||||
});
|
||||
#endif
|
||||
#if 0
|
||||
input_update =
|
||||
ECS::get()
|
||||
.system<ECS::GUI, ECS::App>("SetInputListener")
|
||||
.kind(flecs::OnUpdate)
|
||||
.each([this](ECS::GUI &gui, ECS::App &app) {
|
||||
if (app.listeners.size() < 2 &&
|
||||
gui.mGuiInpitListener) {
|
||||
OgreBites::InputListener *guiListener =
|
||||
gui.mGuiInpitListener;
|
||||
if (guiListener) {
|
||||
app.listeners.clear();
|
||||
app.listeners.push_back(
|
||||
guiListener);
|
||||
app.listeners.push_back(
|
||||
&mKbd);
|
||||
std::cout
|
||||
<< "input update complete\n";
|
||||
gui.mGuiInpitListener =
|
||||
guiListener;
|
||||
if (app.mInput)
|
||||
removeInputListener(
|
||||
app.mInput);
|
||||
delete app.mInput;
|
||||
app.mInput = new OgreBites::
|
||||
InputListenerChain(
|
||||
app.listeners);
|
||||
addInputListener(
|
||||
app.mInput);
|
||||
std::cout
|
||||
<< "update listeners: "
|
||||
<< app.listeners
|
||||
.size()
|
||||
<< "\n";
|
||||
if (app.listeners
|
||||
.size() ==
|
||||
2)
|
||||
OgreAssert(
|
||||
app.listeners.size() ==
|
||||
2,
|
||||
"");
|
||||
input_update.disable();
|
||||
OgreAssert(false, "");
|
||||
} else {
|
||||
app.listeners.clear();
|
||||
app.listeners.push_back(
|
||||
&mKbd);
|
||||
}
|
||||
} else
|
||||
input_update.disable();
|
||||
std::cout << "input update "
|
||||
<< app.listeners.size()
|
||||
<< "\n";
|
||||
});
|
||||
#endif
|
||||
|
||||
p.listeners.clear();
|
||||
p.listeners.push_back(&mKbd);
|
||||
ECS::get().modified<ECS::App>();
|
||||
}
|
||||
void createContent()
|
||||
{
|
||||
int i;
|
||||
m_edit_ui.init_glb_list();
|
||||
m_edit_ui.initGui();
|
||||
createSun();
|
||||
std::cout << "addFrameListener\n";
|
||||
getRoot()->addFrameListener(&mKbd);
|
||||
sky = new SkyBoxRenderer(getSceneManager());
|
||||
bool drawFirst = true;
|
||||
@@ -662,6 +730,25 @@ public:
|
||||
OgreAssert(m, "Sky box material not found.");
|
||||
m->load();
|
||||
ECS::setup(mScnMgr, mDynWorld.get(), mCameraNode, mCamera);
|
||||
ECS::get()
|
||||
.system<const ECS::GUI, ECS::App>("SetInputListener")
|
||||
.kind(flecs::OnUpdate)
|
||||
.each([this](const ECS::GUI &gui, ECS::App &app) {
|
||||
if (gui.mGuiInpitListener &&
|
||||
app.listeners.size() == 1) {
|
||||
app.listeners.clear();
|
||||
app.listeners.push_back(
|
||||
gui.mGuiInpitListener);
|
||||
app.listeners.push_back(&mKbd);
|
||||
ECS::modified<ECS::App>();
|
||||
}
|
||||
});
|
||||
ECS::get().set<ECS::RenderWindow>(
|
||||
{ getRenderWindow(), getDisplayDPI() });
|
||||
ECS::get().set<ECS::App>(
|
||||
{ static_cast<OgreBites::ApplicationContext *>(this),
|
||||
nullptr,
|
||||
{} });
|
||||
Sound::setup();
|
||||
Sound::ding();
|
||||
}
|
||||
@@ -679,26 +766,22 @@ public:
|
||||
Ogre::Radian yaw = q.getYaw();
|
||||
Ogre::Quaternion nq(yaw, Ogre::Vector3(0, 1, 0));
|
||||
pnode->setOrientation(nq);
|
||||
mKbd.gui_active = false;
|
||||
setWindowGrab(true);
|
||||
set_gui_active(false);
|
||||
ECS::get<ECS::GUI>().setWindowGrab(true);
|
||||
}
|
||||
bool get_gui_active()
|
||||
{
|
||||
return mKbd.gui_active;
|
||||
return ECS::get().get<ECS::GUI>().enabled;
|
||||
}
|
||||
void set_gui_active(bool active)
|
||||
{
|
||||
mKbd.gui_active = active;
|
||||
ECS::get().get_mut<ECS::GUI>().enabled = active;
|
||||
ECS::get().modified<ECS::GUI>();
|
||||
}
|
||||
Ogre::Camera *getCamera()
|
||||
{
|
||||
return mCamera;
|
||||
}
|
||||
void setupTerrain()
|
||||
{
|
||||
m_terrain.setupTerrain(mCamera, mSun, mDynWorld.get(),
|
||||
mDbgDraw.get());
|
||||
}
|
||||
flecs::entity getPlayer() const
|
||||
{
|
||||
flecs::entity player =
|
||||
@@ -707,167 +790,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
void EditUI::buildings_editor()
|
||||
{
|
||||
int i;
|
||||
ImVec2 size = ImGui::GetMainViewport()->Size;
|
||||
float window_width = size.x * 0.2f;
|
||||
if (window_width > panel_width)
|
||||
window_width = panel_width;
|
||||
float window_height = size.y * 0.5 - 20;
|
||||
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always);
|
||||
ImGui::SetNextWindowSize(ImVec2(window_width, window_height),
|
||||
ImGuiCond_Always);
|
||||
ImGui::Begin("Droppings...");
|
||||
for (i = 0; i < glb_names.size(); i++) {
|
||||
Ogre::String id_button = "Create entity: " + glb_names[i] +
|
||||
"##ent:" + glb_names[i];
|
||||
if (ImGui::Button(id_button.c_str())) {
|
||||
m_app->create_entity_node(glb_names[i], i);
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
void EditUI::buttons_panel()
|
||||
{
|
||||
ImVec2 size = ImGui::GetMainViewport()->Size;
|
||||
float window_width = size.x * 0.2f;
|
||||
if (window_width > panel_width)
|
||||
window_width = panel_width;
|
||||
float window_height = size.y * 0.5f - 20;
|
||||
ImGui::SetNextWindowPos(ImVec2(0, size.y * 0.5f + 20),
|
||||
ImGuiCond_Always);
|
||||
ImGui::SetNextWindowSize(ImVec2(window_width, window_height),
|
||||
ImGuiCond_Always);
|
||||
ImGui::Begin("Dumb and Stupid");
|
||||
if (!m_app->get_gui_active())
|
||||
m_app->setWindowGrab(true);
|
||||
if (ImGui::Button("Shitty Quit button"))
|
||||
Ogre::Root::getSingleton().queueEndRendering();
|
||||
if (ImGui::Button("Chick-chick")) {
|
||||
m_app->set_gui_active(false);
|
||||
m_app->setWindowGrab(true);
|
||||
}
|
||||
ImGui::Text("We do stoopid...");
|
||||
ImGui::End();
|
||||
}
|
||||
void EditUI::preview(const Ogre::RenderTargetViewportEvent &evt)
|
||||
{
|
||||
int i;
|
||||
Ogre::ImGuiOverlay::NewFrame();
|
||||
if (m_app->get_gui_active()) {
|
||||
buttons_panel();
|
||||
buildings_editor();
|
||||
ImVec2 size = ImGui::GetMainViewport()->Size;
|
||||
float window_width = size.x * 0.2f;
|
||||
if (window_width > panel_width)
|
||||
window_width = panel_width;
|
||||
float window_height = size.y * 0.5f - 20;
|
||||
ImGui::SetNextWindowPos(ImVec2(size.x - window_width,
|
||||
size.y * 0.5f + 20),
|
||||
ImGuiCond_Always);
|
||||
ImGui::SetNextWindowSize(ImVec2(window_width, window_height),
|
||||
ImGuiCond_Always);
|
||||
// ImGui::Begin("Dumb and Stupid", &mKbd.gui_active);
|
||||
ImGui::Begin("Panel...");
|
||||
std::deque<Ogre::SceneNode *> tree_input_queue,
|
||||
tree_output_queue;
|
||||
std::vector<Ogre::SceneNode *> tree_list;
|
||||
tree_input_queue.push_back(mScnMgr->getRootSceneNode());
|
||||
tree_input_queue.push_back(nullptr);
|
||||
std::set<Ogre::SceneNode *> visited;
|
||||
while (true) {
|
||||
int new_nodes_count = 0;
|
||||
while (!tree_input_queue.empty()) {
|
||||
int child;
|
||||
Ogre::SceneNode *item =
|
||||
tree_input_queue.front();
|
||||
tree_input_queue.pop_front();
|
||||
if (item && visited.find(item) ==
|
||||
visited.end()) { // new node
|
||||
new_nodes_count++;
|
||||
tree_output_queue.push_back(item);
|
||||
visited.insert(item);
|
||||
const Ogre::Node::ChildNodeMap
|
||||
&children = item->getChildren();
|
||||
for (child = 0; child < children.size();
|
||||
child++) {
|
||||
tree_output_queue.push_back(
|
||||
static_cast<Ogre::SceneNode
|
||||
*>(
|
||||
children[child]));
|
||||
tree_output_queue.push_back(
|
||||
nullptr);
|
||||
}
|
||||
} else
|
||||
tree_output_queue.push_back(item);
|
||||
}
|
||||
if (new_nodes_count == 0)
|
||||
break;
|
||||
tree_input_queue = tree_output_queue;
|
||||
tree_output_queue.clear();
|
||||
}
|
||||
tree_list.insert(tree_list.begin(), tree_output_queue.begin(),
|
||||
tree_output_queue.end());
|
||||
int count = 0;
|
||||
int depth = 0;
|
||||
std::vector<int> check_depth;
|
||||
int max_depth = 0;
|
||||
check_depth.push_back(0);
|
||||
for (count = 0; count < tree_list.size(); count++) {
|
||||
int t;
|
||||
|
||||
Ogre::SceneNode *node = tree_list[count];
|
||||
if (node && max_depth >= depth) {
|
||||
Ogre::String name = node->getName();
|
||||
if (name.length() == 0) {
|
||||
name = "Node #" +
|
||||
Ogre::StringConverter::toString(
|
||||
count);
|
||||
}
|
||||
if (ImGui::TreeNode(name.c_str())) {
|
||||
check_depth.push_back(max_depth);
|
||||
max_depth++;
|
||||
ImGui::Text(
|
||||
"%s",
|
||||
(name + "##caption").c_str());
|
||||
position_editor(node);
|
||||
ImGui::Separator();
|
||||
orientation_editor(node);
|
||||
ImGui::Separator();
|
||||
ImGui::Text("Attachments");
|
||||
attachments_editor(node);
|
||||
}
|
||||
} else if (!node && max_depth >= depth) {
|
||||
max_depth = check_depth.back();
|
||||
check_depth.pop_back();
|
||||
ImGui::TreePop();
|
||||
}
|
||||
if (tree_list[count])
|
||||
depth++;
|
||||
else
|
||||
depth--;
|
||||
}
|
||||
ImGui::Spacing();
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
void EditUI::initGui()
|
||||
{
|
||||
mScnMgr = m_app->getSceneManager();
|
||||
float vpScale = m_app->getDisplayDPI() / 96 *
|
||||
(float)m_app->getRenderWindow()->getWidth() / 1600.0f;
|
||||
panel_width =
|
||||
380.0f * (float)m_app->getRenderWindow()->getWidth() / 1600.0f;
|
||||
Ogre::OverlayManager::getSingleton().setPixelRatio(vpScale);
|
||||
mGuiOverlay = m_app->initialiseImGui();
|
||||
// float vpScale =
|
||||
// Ogre::OverlayManager::getSingleton().getPixelRatio();
|
||||
ImGui::GetIO().FontGlobalScale = std::round(vpScale);
|
||||
mGuiOverlay->setZOrder(300);
|
||||
mGuiOverlay->show();
|
||||
m_app->getRenderWindow()->addListener(this);
|
||||
}
|
||||
int main()
|
||||
{
|
||||
App ctx;
|
||||
|
||||
Reference in New Issue
Block a user