diff --git a/source/glest_game/game/game.h b/source/glest_game/game/game.h index ca3090c2c..1c6f8845d 100644 --- a/source/glest_game/game/game.h +++ b/source/glest_game/game/game.h @@ -124,6 +124,7 @@ public: virtual void mouseMove(int x, int y, const MouseState *mouseState); void quitGame(); + virtual bool isInSpecialKeyCaptureEvent() { return chatManager.getEditEnabled(); } private: //render diff --git a/source/glest_game/game/game_camera.cpp b/source/glest_game/game/game_camera.cpp index 4850e41c6..376305bae 100644 --- a/source/glest_game/game/game_camera.cpp +++ b/source/glest_game/game/game_camera.cpp @@ -16,12 +16,13 @@ #include "config.h" #include "game_constants.h" #include "xml_parser.h" - +#include "conversion.h" #include "leak_dumper.h" using namespace Shared::Graphics; using Shared::Xml::XmlNode; +using namespace Shared::Util; namespace Glest { namespace Game { @@ -29,9 +30,9 @@ namespace Glest { namespace Game { // class GameCamera // ===================================================== -// ================== PUBLIC ===================== +static std::map > > cacheVisibleQuad; -static std::map cacheVisibleQuad; +// ================== PUBLIC ===================== const float GameCamera::startingVAng= -60.f; const float GameCamera::startingHAng= 0.f; @@ -42,31 +43,13 @@ const float GameCamera::centerOffsetZ= 8.0f; // ================= Constructor ================= -class quadCacheLookup { - public: - quadCacheLookup(float fov,float hAng,Vec3f pos) { - this->fov = fov; - this->hAng = hAng; - this->pos = pos; - } - std::string getString() const { - std::ostringstream streamOut; - streamOut << fov << "_" << hAng << "_" << pos.getString(); - return streamOut.str(); - } - - float fov; - float hAng; - Vec3f pos; - -}; - GameCamera::GameCamera() : pos(0.f, defaultHeight, 0.f), destPos(0.f, defaultHeight, 0.f), destAng(startingVAng, startingHAng) { Config &config = Config::getInstance(); state= sGame; cacheVisibleQuad.clear(); + MaxVisibleQuadItemCache = config.getInt("MaxVisibleQuadItemCache",intToStr(-1).c_str()); //config speed= 15.f / GameConstants::cameraFps; @@ -89,6 +72,10 @@ GameCamera::GameCamera() : pos(0.f, defaultHeight, 0.f), fov = Config::getInstance().getFloat("CameraFov","45"); } +GameCamera::~GameCamera() { + cacheVisibleQuad.clear(); +} + void GameCamera::init(int limitX, int limitY){ this->limitX= limitX; this->limitY= limitY; @@ -165,14 +152,19 @@ void GameCamera::update(){ } Quad2i GameCamera::computeVisibleQuad() const { - // - //quadCacheLookup lookup(fov, hAng, pos); - //string lookupKey = lookup.getString(); - //std::map::const_iterator iterFind = cacheVisibleQuad.find(lookupKey); - //if(iterFind != cacheVisibleQuad.end()) { - // return iterFind->second; - //} - // + + if(MaxVisibleQuadItemCache != 0) { + std::map > >::const_iterator iterFind = cacheVisibleQuad.find(fov); + if(iterFind != cacheVisibleQuad.end()) { + std::map >::const_iterator iterFind2 = iterFind->second.find(hAng); + if(iterFind2 != iterFind->second.end()) { + std::map::const_iterator iterFind3 = iterFind2->second.find(pos); + if(iterFind3 != iterFind2->second.end()) { + return iterFind3->second; + } + } + } + } float nearDist = 20.f; float dist = pos.y > 20.f ? pos.y * 1.2f : 20.f; @@ -199,18 +191,31 @@ Quad2i GameCamera::computeVisibleQuad() const { Vec2i p4(static_cast(p.x + v2.x * farDist), static_cast(p.y + v2.y * farDist)); if (hAng >= 135 && hAng <= 225) { + if(MaxVisibleQuadItemCache != 0 && + (MaxVisibleQuadItemCache < 0 || cacheVisibleQuad[fov][hAng].size() <= MaxVisibleQuadItemCache)) { + cacheVisibleQuad[fov][hAng][pos] = Quad2i(p1, p2, p3, p4); + } return Quad2i(p1, p2, p3, p4); } if (hAng >= 45 && hAng <= 135) { + if(MaxVisibleQuadItemCache != 0 && + (MaxVisibleQuadItemCache < 0 || cacheVisibleQuad[fov][hAng].size() <= MaxVisibleQuadItemCache)) { + cacheVisibleQuad[fov][hAng][pos] = Quad2i(p3, p1, p4, p2); + } return Quad2i(p3, p1, p4, p2); } if (hAng >= 225 && hAng <= 315) { + if(MaxVisibleQuadItemCache != 0 && + (MaxVisibleQuadItemCache < 0 || cacheVisibleQuad[fov][hAng].size() <= MaxVisibleQuadItemCache)) { + cacheVisibleQuad[fov][hAng][pos] = Quad2i(p2, p4, p1, p3); + } return Quad2i(p2, p4, p1, p3); } - //cacheVisibleQuad[lookupKey] = Quad2i(p4, p3, p2, p1); - //cacheVisibleQuad.insert(std::make_pair(lookupKey,Quad2i(p4, p3, p2, p1))); - //return cacheVisibleQuad[lookupKey]; + if(MaxVisibleQuadItemCache != 0 && + (MaxVisibleQuadItemCache < 0 || cacheVisibleQuad[fov][hAng].size() <= MaxVisibleQuadItemCache)) { + cacheVisibleQuad[fov][hAng][pos] = Quad2i(p4, p3, p2, p1); + } return Quad2i(p4, p3, p2, p1); } diff --git a/source/glest_game/game/game_camera.h b/source/glest_game/game/game_camera.h index 2fbb3d1f2..d07350345 100644 --- a/source/glest_game/game/game_camera.h +++ b/source/glest_game/game/game_camera.h @@ -37,7 +37,7 @@ class Config; /// A basic camera that holds information about the game view // ===================================================== -class GameCamera{ +class GameCamera { public: static const float startingVAng; static const float startingHAng; @@ -83,8 +83,11 @@ private: float maxVAng; float fov; + int MaxVisibleQuadItemCache; + public: GameCamera(); + ~GameCamera(); void init(int limitX, int limitY); diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 2d1f3b3b9..898ba24fd 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -23,7 +23,6 @@ #include "platform_util.h" #include "platform_main.h" #include "network_interface.h" -//#include "sound_renderer.h" #include "ImageReaders.h" #include "renderer.h" #include "simple_threads.h" @@ -290,11 +289,15 @@ void MainWindow::eventKeyDown(char key){ } } - Config &configKeys = Config::getInstance(std::pair(cfgMainKeys,cfgUserKeys)); - if(key == configKeys.getCharKey("HotKeyShowDebug")) { - Renderer &renderer= Renderer::getInstance(); - bool showDebugUI = renderer.getShowDebugUI(); - renderer.setShowDebugUI(!showDebugUI); + if(program != NULL && program->isInSpecialKeyCaptureEvent() == false) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + Config &configKeys = Config::getInstance(std::pair(cfgMainKeys,cfgUserKeys)); + if(key == configKeys.getCharKey("HotKeyShowDebug")) { + Renderer &renderer= Renderer::getInstance(); + bool showDebugUI = renderer.getShowDebugUI(); + renderer.setShowDebugUI(!showDebugUI); + } } SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); diff --git a/source/glest_game/main/program.h b/source/glest_game/main/program.h index d1c0c414a..f257b16e3 100644 --- a/source/glest_game/main/program.h +++ b/source/glest_game/main/program.h @@ -75,6 +75,7 @@ public: virtual void keyPress(char c){}; virtual void setStartXY(int X,int Y) { startX=X; startY=Y; } virtual void restoreToStartXY() { SDL_WarpMouse(startX, startY); } + virtual bool isInSpecialKeyCaptureEvent() { return false; } }; // =============================== @@ -151,6 +152,7 @@ public: void eventMouseMove(int x, int y, const MouseState *ms); void renderProgramMsgBox(); + bool isInSpecialKeyCaptureEvent() { return (programState != NULL ? programState->isInSpecialKeyCaptureEvent() : false); } private: diff --git a/source/glest_game/menu/menu_state_connected_game.h b/source/glest_game/menu/menu_state_connected_game.h index 76512e522..11af675bc 100644 --- a/source/glest_game/menu/menu_state_connected_game.h +++ b/source/glest_game/menu/menu_state_connected_game.h @@ -87,6 +87,8 @@ public: virtual void keyPress(char c); virtual void keyUp(char key); + virtual bool isInSpecialKeyCaptureEvent() { return chatManager.getEditEnabled(); } + private: bool hasNetworkGameSettings(); diff --git a/source/glest_game/menu/menu_state_custom_game.h b/source/glest_game/menu/menu_state_custom_game.h index c54c878b8..d8e96ea50 100644 --- a/source/glest_game/menu/menu_state_custom_game.h +++ b/source/glest_game/menu/menu_state_custom_game.h @@ -115,6 +115,7 @@ public: virtual void simpleTask(); + virtual bool isInSpecialKeyCaptureEvent() { return chatManager.getEditEnabled(); } private: diff --git a/source/glest_game/menu/menu_state_join_game.h b/source/glest_game/menu/menu_state_join_game.h index de9bea0b6..186ae4509 100644 --- a/source/glest_game/menu/menu_state_join_game.h +++ b/source/glest_game/menu/menu_state_join_game.h @@ -73,6 +73,8 @@ public: virtual void keyDown(char key); virtual void keyPress(char c); + virtual bool isInSpecialKeyCaptureEvent() { return chatManager.getEditEnabled(); } + private: void connectToServer(); virtual void DiscoveredServers(std::vector serverList); diff --git a/source/shared_lib/include/graphics/math_util.h b/source/shared_lib/include/graphics/math_util.h index dd0ba92dc..fa7fedb53 100644 --- a/source/shared_lib/include/graphics/math_util.h +++ b/source/shared_lib/include/graphics/math_util.h @@ -138,6 +138,22 @@ public: p[3]/scalar); } + bool operator <(const Quad2 &v) const { + if(p[0] < v.p[0]) { + return true; + } + if(p[1] < v.p[1]) { + return true; + } + if(p[2] < v.p[2]) { + return true; + } + if(p[3] < v.p[3]) { + return true; + } + return false; + } + Rect2 computeBoundingRect() const{ return Rect2i( min(p[0].x, p[1].x), diff --git a/source/shared_lib/include/graphics/vec.h b/source/shared_lib/include/graphics/vec.h index f6d16a64e..76047610e 100644 --- a/source/shared_lib/include/graphics/vec.h +++ b/source/shared_lib/include/graphics/vec.h @@ -261,12 +261,16 @@ public: } Vec3 operator -=(const Vec3 &v){ - x-=v.x; + x-=v.x; y-=v.y; z-=v.z; return *this; } + bool operator <(const Vec3 &v) const { + return x < v.x || (x == v.x && y < v.y) || (x == v.x && y == v.y && z < v.z); + } + Vec3 lerp(T t, const Vec3 &v) const{ return *this + (v - *this) * t; } @@ -455,6 +459,9 @@ public: w-=w.z; return *this; } + bool operator <(const Vec4 &v) const { + return x < v.x || (x == v.x && y < v.y) || (x == v.x && y == v.y && z < v.z) || (x == v.x && y == v.y && z == v.z && w < v.w); + } Vec4 lerp(T t, const Vec4 &v) const{ return *this + (v - *this) *t;