From ff97de547799a60a2121008e9da5793d2ab1581f Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 31 Mar 2013 13:06:38 +0200 Subject: Fixed graphics objects after reset Should fix #120 and perhaps some other bugs as well --- src/graphics/engine/engine.cpp | 21 +++++++++++++++++++++ src/graphics/engine/modelmanager.cpp | 12 ++++++++++++ src/graphics/engine/modelmanager.h | 4 ++++ 3 files changed, 37 insertions(+) (limited to 'src/graphics/engine') diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index e2ef569..274e179 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -591,6 +591,27 @@ void CEngine::CopyBaseObject(int sourceBaseObjRank, int destBaseObjRank) assert(destBaseObjRank >= 0 && destBaseObjRank < static_cast( m_baseObjects.size() )); m_baseObjects[destBaseObjRank] = m_baseObjects[sourceBaseObjRank]; + + EngineBaseObject& p1 = m_baseObjects[destBaseObjRank]; + + if (! p1.used) + return; + + for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) + { + EngineBaseObjTexTier& p2 = p1.next[l2]; + + for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) + { + EngineBaseObjLODTier& p3 = p2.next[l3]; + + for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) + { + EngineBaseObjDataTier& p4 = p3.next[l4]; + p4.staticBufferId = 0; + } + } + } } void CEngine::AddBaseObjTriangles(int baseObjRank, const std::vector& vertices, diff --git a/src/graphics/engine/modelmanager.cpp b/src/graphics/engine/modelmanager.cpp index c23b79d..35b7e7a 100644 --- a/src/graphics/engine/modelmanager.cpp +++ b/src/graphics/engine/modelmanager.cpp @@ -111,6 +111,8 @@ bool CModelManager::AddModelCopy(const std::string& fileName, bool mirrored, int m_engine->CopyBaseObject((*it).second.baseObjRank, copyBaseObjRank); m_engine->SetObjectBaseRank(objRank, copyBaseObjRank); + m_copiesBaseRanks.push_back(copyBaseObjRank); + return true; } @@ -128,6 +130,16 @@ int CModelManager::GetModelBaseObjRank(const std::string& fileName, bool mirrore return (*it).second.baseObjRank; } +void CModelManager::DeleteAllModelCopies() +{ + for (int baseObjRank : m_copiesBaseRanks) + { + m_engine->DeleteBaseObject(baseObjRank); + } + + m_copiesBaseRanks.clear(); +} + void CModelManager::UnloadModel(const std::string& fileName, bool mirrored) { auto it = m_models.find(FileInfo(fileName, mirrored)); diff --git a/src/graphics/engine/modelmanager.h b/src/graphics/engine/modelmanager.h index 601d636..a7f9805 100644 --- a/src/graphics/engine/modelmanager.h +++ b/src/graphics/engine/modelmanager.h @@ -53,6 +53,9 @@ public: //! Returns the rank of base engine object of given loaded model int GetModelBaseObjRank(const std::string& fileName, bool mirrored); + //! Deletes all copied objects + void DeleteAllModelCopies(); + //! Unloads the given model void UnloadModel(const std::string& fileName, bool mirrored); //! Unloads all models @@ -91,6 +94,7 @@ private: } }; std::map m_models; + std::vector m_copiesBaseRanks; CEngine* m_engine; }; -- cgit v1.2.3-1-g7c22 From 9485e1a95fc264beb121bc2fc92dd3303b80ce5e Mon Sep 17 00:00:00 2001 From: krzys-h Date: Mon, 1 Apr 2013 12:57:31 +0200 Subject: Improved log levels --- src/graphics/engine/modelmanager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/graphics/engine') diff --git a/src/graphics/engine/modelmanager.cpp b/src/graphics/engine/modelmanager.cpp index 35b7e7a..238a7d9 100644 --- a/src/graphics/engine/modelmanager.cpp +++ b/src/graphics/engine/modelmanager.cpp @@ -23,7 +23,7 @@ CModelManager::~CModelManager() bool CModelManager::LoadModel(const std::string& fileName, bool mirrored) { - GetLogger()->Info("Loading model '%s'\n", fileName.c_str()); + GetLogger()->Debug("Loading model '%s'\n", fileName.c_str()); CModelFile modelFile; -- cgit v1.2.3-1-g7c22 From 5669053de08bac9726902e96f89aa85b99909399 Mon Sep 17 00:00:00 2001 From: erihel Date: Sat, 27 Apr 2013 17:50:30 +0200 Subject: Some code refactoring Changed vehicule (french) to vehicle (english) in enums and variables --- src/graphics/engine/engine.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/graphics/engine') diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index f9dfd45..671924f 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -171,7 +171,7 @@ enum EngineObjectType //! Fixed object ENG_OBJTYPE_FIX = 2, //! Moving object - ENG_OBJTYPE_VEHICULE = 3, + ENG_OBJTYPE_VEHICLE = 3, //! Part of a moving object ENG_OBJTYPE_DESCENDANT = 4, //! Fixed object type quartz -- cgit v1.2.3-1-g7c22 From 658ebe015f98b8f11f8d46110b5e089323f7d8cb Mon Sep 17 00:00:00 2001 From: XienDev Date: Mon, 29 Apr 2013 13:51:37 +0300 Subject: Fix for shadows (bugs #176 and #132) --- src/graphics/engine/engine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/graphics/engine') diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 274e179..5d77e29 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -3651,7 +3651,7 @@ void CEngine::DrawShadow() float lastIntensity = -1.0f; for (int i = 0; i < static_cast( m_shadows.size() ); i++) { - if (m_shadows[i].hide) + if (m_shadows[i].hide || !m_shadows[i].used) continue; Math::Vector pos = m_shadows[i].pos; // pos = center of the shadow on the ground -- cgit v1.2.3-1-g7c22 From 2ba146cd63cefd58f5ff464b5b94e43740cf0700 Mon Sep 17 00:00:00 2001 From: erihel Date: Mon, 29 Apr 2013 14:29:12 +0200 Subject: Fixed problem with test compilation Altered test cmake files to fix linker problem. Changed tga to png in pyro. Changed enum in CMotionDummy. --- src/graphics/engine/pyro.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/graphics/engine') diff --git a/src/graphics/engine/pyro.cpp b/src/graphics/engine/pyro.cpp index cab28b6..0a82408 100644 --- a/src/graphics/engine/pyro.cpp +++ b/src/graphics/engine/pyro.cpp @@ -1555,7 +1555,7 @@ void CPyro::ExploStart() { int objRank = m_object->GetObjectRank(i); if ( objRank == -1 ) continue; - m_engine->ChangeSecondTexture(objRank, "dirty04.tga"); + m_engine->ChangeSecondTexture(objRank, "dirty04.png"); Math::Vector pos = m_object->GetPosition(i); -- cgit v1.2.3-1-g7c22 From cec406ea31c3ccb22ab676ce3fd52d4cd0dfcb0d Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sat, 11 May 2013 23:05:20 +0200 Subject: Non-power-of-2 padding for background images * added padding options * removed old hardcoded image sizes --- src/graphics/engine/engine.cpp | 29 ++++++++++++++++++----------- src/graphics/engine/engine.h | 5 ++--- 2 files changed, 20 insertions(+), 14 deletions(-) (limited to 'src/graphics/engine') diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 5d77e29..806cb5f 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -94,7 +94,6 @@ CEngine::CEngine(CApplication *app) m_backgroundCloudUp = Color(); m_backgroundCloudDown = Color(); m_backgroundFull = false; - m_backgroundScale = Math::Point(1.0f, 1.0f); m_overFront = true; m_overColor = Color(); m_overMode = ENG_RSTATE_TCOLOR_BLACK; @@ -2188,7 +2187,11 @@ bool CEngine::LoadAllTextures() LoadTexture("map.png"); if (! m_backgroundName.empty()) - m_backgroundTex = LoadTexture(m_backgroundName); + { + TextureCreateParams params = m_defaultTexParams; + params.padToNearestPowerOfTwo = true; + m_backgroundTex = LoadTexture(m_backgroundName, params); + } else m_backgroundTex.SetInvalid(); @@ -2609,8 +2612,7 @@ float CEngine::GetFogStart(int rank) } void CEngine::SetBackground(const std::string& name, Color up, Color down, - Color cloudUp, Color cloudDown, - bool full, Math::Point scale) + Color cloudUp, Color cloudDown, bool full) { if (m_backgroundTex.Valid()) { @@ -2624,15 +2626,17 @@ void CEngine::SetBackground(const std::string& name, Color up, Color down, m_backgroundCloudUp = cloudUp; m_backgroundCloudDown = cloudDown; m_backgroundFull = full; - m_backgroundScale = scale; if (! m_backgroundName.empty()) - m_backgroundTex = LoadTexture(m_backgroundName); + { + TextureCreateParams params = m_defaultTexParams; + params.padToNearestPowerOfTwo = true; + m_backgroundTex = LoadTexture(m_backgroundName, params); + } } void CEngine::GetBackground(std::string& name, Color& up, Color& down, - Color& cloudUp, Color& cloudDown, - bool &full, Math::Point& scale) + Color& cloudUp, Color& cloudDown, bool &full) { name = m_backgroundName; up = m_backgroundColorUp; @@ -2640,7 +2644,6 @@ void CEngine::GetBackground(std::string& name, Color& up, Color& down, cloudUp = m_backgroundCloudUp; cloudDown = m_backgroundCloudDown; full = m_backgroundFull; - scale = m_backgroundScale; } void CEngine::SetForegroundName(const std::string& name) @@ -3900,8 +3903,12 @@ void CEngine::DrawBackgroundImage() v2 = v1+h; } - u2 *= m_backgroundScale.x; - v2 *= m_backgroundScale.y; + Math::Point backgroundScale; + backgroundScale.x = static_cast(m_backgroundTex.originalSize.x) / static_cast(m_backgroundTex.size.x); + backgroundScale.y = static_cast(m_backgroundTex.originalSize.y) / static_cast(m_backgroundTex.size.y); + + u2 *= backgroundScale.x; + v2 *= backgroundScale.y; SetTexture(m_backgroundTex); SetState(ENG_RSTATE_OPAQUE_TEXTURE | ENG_RSTATE_WRAP); diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index 671924f..16fb4e6 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -1050,10 +1050,10 @@ public: //! Management of the background image to use void SetBackground(const std::string& name, Color up = Color(), Color down = Color(), Color cloudUp = Color(), Color cloudDown = Color(), - bool full = false, Math::Point scale = Math::Point(1.0f, 1.0f)); + bool full = false); void GetBackground(std::string& name, Color& up, Color& down, Color& cloudUp, Color& cloudDown, - bool& full, Math::Point& scale); + bool& full); //@} //! Specifies the name of foreground texture @@ -1346,7 +1346,6 @@ protected: bool m_firstGroundSpot; int m_secondTexNum; bool m_backgroundFull; - Math::Point m_backgroundScale; std::string m_backgroundName; Texture m_backgroundTex; Color m_backgroundColorUp; -- cgit v1.2.3-1-g7c22 From 04f747b00b95ebbd32457eae8a397695dc6981af Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 12 May 2013 14:55:41 +0200 Subject: Added simple texturepack support (#208) --- src/graphics/engine/engine.cpp | 35 +++++++++++++++++++++++++++++------ src/graphics/engine/engine.h | 9 ++++++++- 2 files changed, 37 insertions(+), 7 deletions(-) (limited to 'src/graphics/engine') diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 806cb5f..5bd51fe 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -62,6 +62,8 @@ CEngine::CEngine(CApplication *app) m_sound = nullptr; m_terrain = nullptr; + m_texPack = ""; + m_showStats = false; m_focus = 0.75f; @@ -236,6 +238,11 @@ void CEngine::SetTerrain(CTerrain* terrain) m_terrain = terrain; } +void CEngine::SetTexturePack(const std::string& texpackName) +{ + m_texPack = texpackName; +} + bool CEngine::Create() { @@ -2109,7 +2116,7 @@ void CEngine::SetViewParams(const Math::Vector& eyePt, const Math::Vector& looka m_sound->SetListener(eyePt, lookatPt); } -Texture CEngine::CreateTexture(const std::string& texName, const TextureCreateParams& params, CImage* image) +Texture CEngine::CreateTexture(const std::string& texName, const TextureCreateParams& params, CImage* image, std::string orginalName) { if (texName.empty()) return Texture(); // invalid texture @@ -2125,7 +2132,7 @@ Texture CEngine::CreateTexture(const std::string& texName, const TextureCreatePa if (! img.Load(m_app->GetDataFilePath(DIR_TEXTURE, texName))) { std::string error = img.GetError(); - GetLogger()->Error("Couldn't load texture '%s': %s, blacklisting\n", texName.c_str(), error.c_str()); + if(orginalName == "") GetLogger()->Error("Couldn't load texture '%s': %s, blacklisting\n", texName.c_str(), error.c_str()); m_texBlacklist.insert(texName); return Texture(); // invalid texture } @@ -2139,13 +2146,18 @@ Texture CEngine::CreateTexture(const std::string& texName, const TextureCreatePa if (! tex.Valid()) { - GetLogger()->Error("Couldn't load texture '%s', blacklisting\n", texName.c_str()); + if(orginalName == "") GetLogger()->Error("Couldn't load texture '%s', blacklisting\n", texName.c_str()); m_texBlacklist.insert(texName); return tex; } - m_texNameMap[texName] = tex; - m_revTexNameMap[tex] = texName; + if(orginalName == "") { + m_texNameMap[texName] = tex; + m_revTexNameMap[tex] = texName; + } else { + m_texNameMap[orginalName] = tex; + m_revTexNameMap[tex] = orginalName; + } return tex; } @@ -2170,7 +2182,18 @@ Texture CEngine::LoadTexture(const std::string& name, const TextureCreateParams& if (it != m_texNameMap.end()) return (*it).second; - Texture tex = CreateTexture(name, params); + Texture tex; + if (m_texPack != "") { + std::string name_texpack = m_texPack + "/" + name; + + if (m_texBlacklist.find(name_texpack) == m_texBlacklist.end()) { + tex = CreateTexture(name_texpack, params, nullptr, name); + if (tex.Valid()) + return tex; + } + } + + tex = CreateTexture(name, params); return tex; } diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index 16fb4e6..8df912e 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -726,6 +726,10 @@ public: //! Writes a screenshot containing the current frame bool WriteScreenShot(const std::string& fileName, int width, int height); + //! Set texture pack + void SetTexturePack(const std::string& texpackName); + + //@{ //! Management of game pause mode void SetPause(bool pause); @@ -1229,7 +1233,7 @@ protected: const Material& mat, int state); //! Create texture and add it to cache - Texture CreateTexture(const std::string &texName, const TextureCreateParams ¶ms, CImage* image = nullptr); + Texture CreateTexture(const std::string &texName, const TextureCreateParams ¶ms, CImage* image = nullptr, std::string orginalName = ""); //! Tests whether the given object is visible bool IsVisible(int objRank); @@ -1403,6 +1407,9 @@ protected: * so are disabled for subsequent load calls. */ std::set m_texBlacklist; + //! Texture pack + std::string m_texPack; + //! Mouse cursor definitions EngineMouse m_mice[ENG_MOUSE_COUNT]; //! Texture with mouse cursors -- cgit v1.2.3-1-g7c22 From 07839a561fa876539484fdc44e68d3f17e20a89b Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 12 May 2013 18:38:01 +0200 Subject: Unicode symbols for special characters * added support for special characters from original text bitmaps --- src/graphics/engine/text.cpp | 122 ++++++++++++++++++++++++++++++++++++------- src/graphics/engine/text.h | 31 +++++++++-- 2 files changed, 131 insertions(+), 22 deletions(-) (limited to 'src/graphics/engine') diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index 308c813..0f0122d 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -56,6 +56,7 @@ CText::CText(CEngine* engine) m_engine = engine; m_defaultSize = 12.0f; + m_tabSize = 4; m_lastFontType = FONT_COLOBOT; m_lastFontSize = 0; @@ -148,6 +149,16 @@ void CText::FlushCache() m_lastCachedFont = nullptr; } +int CText::GetTabSize() +{ + return m_tabSize; +} + +void CText::SetTabSize(int tabSize) +{ + m_tabSize = tabSize; +} + void CText::DrawText(const std::string &text, std::vector::iterator format, std::vector::iterator end, float size, Math::Point pos, float width, TextAlign align, @@ -309,11 +320,16 @@ float CText::GetStringWidth(const std::string &text, return width; } -float CText::GetStringWidth(const std::string &text, FontType font, float size) +float CText::GetStringWidth(std::string text, FontType font, float size) { assert(font != FONT_BUTTON); - // TODO: special chars? + // Skip special chars + for (char& c : text) + { + if (c < 32) + c = ':'; + } CachedFont* cf = GetOrOpenFont(font, size); assert(cf != nullptr); @@ -328,8 +344,16 @@ float CText::GetCharWidth(UTF8Char ch, FontType font, float size, float offset) // TODO: if (font == FONT_BUTTON) if (font == FONT_BUTTON) return 0.0f; - // TODO: special chars? - // TODO: tab sizing + int width = 1; + if (ch.c1 < 32) + { + if (ch.c1 == '\t') + width = m_tabSize; + + // TODO: tab sizing at intervals? + + ch.c1 = ':'; + } CachedFont* cf = GetOrOpenFont(font, size); assert(cf != nullptr); @@ -341,7 +365,7 @@ float CText::GetCharWidth(UTF8Char ch, FontType font, float size, float offset) else tex = CreateCharTexture(ch, cf); - return tex.charSize.x; + return tex.charSize.x * width; } @@ -505,6 +529,63 @@ int CText::Detect(const std::string &text, FontType font, float size, float offs return index; } +UTF8Char CText::TranslateSpecialChar(int specialChar) +{ + UTF8Char ch; + + switch (specialChar) + { + case CHAR_TAB: + ch.c1 = ':'; + ch.c2 = 0; + ch.c3 = 0; + break; + + case CHAR_NEWLINE: + // Unicode: U+21B2 + ch.c1 = 0xE2; + ch.c2 = 0x86; + ch.c3 = 0xB2; + break; + + case CHAR_DOT: + // Unicode: U+23C5 + ch.c1 = 0xE2; + ch.c2 = 0x8F; + ch.c3 = 0x85; + break; + + case CHAR_SQUARE: + // Unicode: U+25FD + ch.c1 = 0xE2; + ch.c2 = 0x97; + ch.c3 = 0xBD; + break; + + case CHAR_SKIP_RIGHT: + // Unicode: U+25B6 + ch.c1 = 0xE2; + ch.c2 = 0x96; + ch.c3 = 0xB6; + break; + + case CHAR_SKIP_LEFT: + // Unicode: U+25C0 + ch.c1 = 0xE2; + ch.c2 = 0x97; + ch.c3 = 0x80; + break; + + default: + ch.c1 = '?'; + ch.c2 = 0; + ch.c3 = 0; + break; + } + + return ch; +} + void CText::DrawString(const std::string &text, std::vector::iterator format, std::vector::iterator end, float size, Math::Point pos, float width, int eol, Color color) @@ -532,7 +613,11 @@ void CText::DrawString(const std::string &text, std::vector::itera float cw = GetCharWidth(ch, font, size, offset); if (offset + cw > width) // exceeds the maximum width? { - // TODO: special end-of-line char + UTF8Char ch = TranslateSpecialChar(CHAR_SKIP_RIGHT); + cw = GetCharWidth(ch, font, size, offset); + pos.x = start + width - cw; + color = Color(1.0f, 0.0f, 0.0f); + DrawCharAndAdjustPos(ch, font, size, pos, color); break; } @@ -550,7 +635,13 @@ void CText::DrawString(const std::string &text, std::vector::itera fmtIndex++; } - // TODO: eol + if (eol != 0) + { + FontType font = FONT_COLOBOT; + UTF8Char ch = TranslateSpecialChar(eol); + color = Color(1.0f, 0.0f, 0.0f); + DrawCharAndAdjustPos(ch, font, size, pos, color); + } } void CText::StringToUTFCharList(const std::string &text, std::vector &chars) @@ -675,23 +766,18 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::P // TODO: if (font == FONT_BUTTON) if (font == FONT_BUTTON) return; - // TODO: special chars? - CachedFont* cf = GetOrOpenFont(font, size); if (cf == nullptr) return; int width = 1; - if (ch.c1 > 0 && ch.c1 < 32) { // FIXME add support for chars with code 9 10 23 - if (ch.c1 == '\t') { - ch.c1 = ':'; - width = 4; - } else { - ch.c1 = ' '; - } - ch.c2 = 0; - ch.c3 = 0; + if (ch.c1 > 0 && ch.c1 < 32) + { + if (ch.c1 == '\t') + width = m_tabSize; + + ch = TranslateSpecialChar(ch.c1); } auto it = cf->cache.find(ch); diff --git a/src/graphics/engine/text.h b/src/graphics/engine/text.h index 6bcc59b..b19a224 100644 --- a/src/graphics/engine/text.h +++ b/src/graphics/engine/text.h @@ -205,6 +205,20 @@ struct MultisizeFont : fileName(fn) {} }; +/** + * \enum SpecialChar + * \brief Special codes for certain characters + */ +enum SpecialChar +{ + CHAR_TAB = '\t', //! Tab character - : + CHAR_NEWLINE = '\n', //! Newline character - arrow pointing down and left + CHAR_DOT = 1, //! Single dot in the middle + CHAR_SQUARE = 2, //! Square + CHAR_SKIP_RIGHT = 5, //! Filled triangle pointing right + CHAR_SKIP_LEFT = 6 //! Filled triangle pointing left +}; + /** * \class CText * \brief Text rendering engine @@ -240,6 +254,12 @@ public: //! Flushes cached textures void FlushCache(); + //@{ + //! Tab size management + void SetTabSize(int tabSize); + int GetTabSize(); + //@} + //! Draws text (multi-format) void DrawText(const std::string &text, std::vector::iterator format, std::vector::iterator end, @@ -268,11 +288,11 @@ public: float GetHeight(FontType font, float size); //! Returns width of string (multi-format) - TEST_VIRTUAL float GetStringWidth(const std::string &text, - std::vector::iterator format, - std::vector::iterator end, float size); + TEST_VIRTUAL float GetStringWidth(const std::string& text, + std::vector::iterator format, + std::vector::iterator end, float size); //! Returns width of string (single font) - TEST_VIRTUAL float GetStringWidth(const std::string &text, FontType font, float size); + TEST_VIRTUAL float GetStringWidth(std::string text, FontType font, float size); //! Returns width of single character TEST_VIRTUAL float GetCharWidth(UTF8Char ch, FontType font, float size, float offset); @@ -290,6 +310,8 @@ public: //! Returns the most suitable position to a given offset (one font) int Detect(const std::string &text, FontType font, float size, float offset); + UTF8Char TranslateSpecialChar(int specialChar); + protected: CachedFont* GetOrOpenFont(FontType type, float size); CharTexture CreateCharTexture(UTF8Char ch, CachedFont* font); @@ -309,6 +331,7 @@ protected: std::string m_error; float m_defaultSize; + int m_tabSize; std::map m_fonts; -- cgit v1.2.3-1-g7c22 From b41957f2f95d8f62817705a1c82322d9463d28a2 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 26 May 2013 11:34:53 +0200 Subject: Corrected some valgrind issues * fixed several uninitialized variable issues * fixed possible memory corruption in CEngine --- src/graphics/engine/engine.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/graphics/engine') diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 5bd51fe..b697a37 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -998,7 +998,8 @@ void CEngine::ChangeSecondTexture(int objRank, const std::string& tex2Name) continue; // already new EngineBaseObjTexTier& newP2 = AddLevel2(p1, p2.tex1Name, tex2Name); - newP2.next.swap(p2.next); + newP2.next.insert(newP2.next.end(), p2.next.begin(), p2.next.end()); + p2.next.clear(); } } -- cgit v1.2.3-1-g7c22 From 8f6fd2a1316432970f1d86515819e7bbe15ddab3 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 26 May 2013 14:50:23 +0200 Subject: Changes in texture code & refactoring * refactored and altered slightly the texture pack code * added flushing of texture cache * some refactoring and const-correctness in CApplication methods --- src/graphics/engine/engine.cpp | 85 +++++++++++++++++++++--------------------- src/graphics/engine/engine.h | 11 ++---- 2 files changed, 47 insertions(+), 49 deletions(-) (limited to 'src/graphics/engine') diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index b697a37..3959c02 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -62,8 +62,6 @@ CEngine::CEngine(CApplication *app) m_sound = nullptr; m_terrain = nullptr; - m_texPack = ""; - m_showStats = false; m_focus = 0.75f; @@ -238,12 +236,6 @@ void CEngine::SetTerrain(CTerrain* terrain) m_terrain = terrain; } -void CEngine::SetTexturePack(const std::string& texpackName) -{ - m_texPack = texpackName; -} - - bool CEngine::Create() { m_size = m_app->GetVideoConfig().size; @@ -323,7 +315,7 @@ void CEngine::ResetAfterDeviceChanged() m_text->FlushCache(); - // TODO reload textures, reset device state, etc. + FlushTextureCache(); } bool CEngine::ProcessEvent(const Event &event) @@ -2117,7 +2109,7 @@ void CEngine::SetViewParams(const Math::Vector& eyePt, const Math::Vector& looka m_sound->SetListener(eyePt, lookatPt); } -Texture CEngine::CreateTexture(const std::string& texName, const TextureCreateParams& params, CImage* image, std::string orginalName) +Texture CEngine::CreateTexture(const std::string& texName, const TextureCreateParams& params, CImage* image) { if (texName.empty()) return Texture(); // invalid texture @@ -2126,39 +2118,53 @@ Texture CEngine::CreateTexture(const std::string& texName, const TextureCreatePa return Texture(); // invalid texture Texture tex; + CImage img; if (image == nullptr) { - CImage img; - if (! img.Load(m_app->GetDataFilePath(DIR_TEXTURE, texName))) + bool loadedFromTexPack = false; + + std::string texPackName = m_app->GetTexPackFilePath(texName); + if (! texPackName.empty()) { - std::string error = img.GetError(); - if(orginalName == "") GetLogger()->Error("Couldn't load texture '%s': %s, blacklisting\n", texName.c_str(), error.c_str()); - m_texBlacklist.insert(texName); - return Texture(); // invalid texture + if (img.Load(texPackName)) + { + loadedFromTexPack = true; + } + else + { + std::string error = img.GetError(); + GetLogger()->Error("Couldn't load texture '%s' from texpack: %s, blacklisting the texpack path\n", + texName.c_str(), error.c_str()); + m_texBlacklist.insert(texPackName); + } } - tex = m_device->CreateTexture(&img, params); - } - else - { - tex = m_device->CreateTexture(image, params); + if (!loadedFromTexPack) + { + if (! img.Load(m_app->GetDataFilePath(DIR_TEXTURE, texName))) + { + std::string error = img.GetError(); + GetLogger()->Error("Couldn't load texture '%s': %s, blacklisting\n", texName.c_str(), error.c_str()); + m_texBlacklist.insert(texName); + return Texture(); // invalid texture + } + } + + image = &img; } + tex = m_device->CreateTexture(&img, params); + if (! tex.Valid()) { - if(orginalName == "") GetLogger()->Error("Couldn't load texture '%s', blacklisting\n", texName.c_str()); + GetLogger()->Error("Couldn't load texture '%s', blacklisting\n", texName.c_str()); m_texBlacklist.insert(texName); return tex; } - if(orginalName == "") { - m_texNameMap[texName] = tex; - m_revTexNameMap[tex] = texName; - } else { - m_texNameMap[orginalName] = tex; - m_revTexNameMap[tex] = orginalName; - } + m_texNameMap[texName] = tex; + m_revTexNameMap[tex] = texName; return tex; } @@ -2183,19 +2189,7 @@ Texture CEngine::LoadTexture(const std::string& name, const TextureCreateParams& if (it != m_texNameMap.end()) return (*it).second; - Texture tex; - if (m_texPack != "") { - std::string name_texpack = m_texPack + "/" + name; - - if (m_texBlacklist.find(name_texpack) == m_texBlacklist.end()) { - tex = CreateTexture(name_texpack, params, nullptr, name); - if (tex.Valid()) - return tex; - } - } - - tex = CreateTexture(name, params); - return tex; + return CreateTexture(name, params); } bool CEngine::LoadAllTextures() @@ -2453,6 +2447,13 @@ void CEngine::DeleteTexture(const Texture& tex) m_texNameMap.erase(it); } +void CEngine::FlushTextureCache() +{ + m_texNameMap.clear(); + m_revTexNameMap.clear(); + m_texBlacklist.clear(); +} + bool CEngine::SetTexture(const std::string& name, int stage) { auto it = m_texNameMap.find(name); diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index 8df912e..af8cf6a 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -726,9 +726,6 @@ public: //! Writes a screenshot containing the current frame bool WriteScreenShot(const std::string& fileName, int width, int height); - //! Set texture pack - void SetTexturePack(const std::string& texpackName); - //@{ //! Management of game pause mode @@ -961,6 +958,9 @@ public: //! Deletes the given texture, unloading it and removing from cache void DeleteTexture(const Texture& tex); + //! Empties the texture cache + void FlushTextureCache(); + //! Defines of the distance field of vision void SetTerrainVision(float vision); @@ -1233,7 +1233,7 @@ protected: const Material& mat, int state); //! Create texture and add it to cache - Texture CreateTexture(const std::string &texName, const TextureCreateParams ¶ms, CImage* image = nullptr, std::string orginalName = ""); + Texture CreateTexture(const std::string &texName, const TextureCreateParams ¶ms, CImage* image = nullptr); //! Tests whether the given object is visible bool IsVisible(int objRank); @@ -1407,9 +1407,6 @@ protected: * so are disabled for subsequent load calls. */ std::set m_texBlacklist; - //! Texture pack - std::string m_texPack; - //! Mouse cursor definitions EngineMouse m_mice[ENG_MOUSE_COUNT]; //! Texture with mouse cursors -- cgit v1.2.3-1-g7c22 From 8765d58b02c9afd00186bae4a0045dff32f7d102 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 26 May 2013 17:47:54 +0200 Subject: Fixed code formatting * moved braces to new lines * fixed some function/variable names * fixed whitespace issues --- src/graphics/engine/README.txt | 1 + src/graphics/engine/camera.cpp | 1 + src/graphics/engine/camera.h | 4 ++-- src/graphics/engine/cloud.cpp | 1 + src/graphics/engine/cloud.h | 1 + src/graphics/engine/engine.cpp | 1 + src/graphics/engine/engine.h | 1 + src/graphics/engine/lightman.cpp | 1 + src/graphics/engine/lightman.h | 1 + src/graphics/engine/lightning.cpp | 1 + src/graphics/engine/lightning.h | 1 + src/graphics/engine/modelfile.cpp | 1 + src/graphics/engine/modelfile.h | 1 + src/graphics/engine/modelmanager.cpp | 1 + src/graphics/engine/modelmanager.h | 1 + src/graphics/engine/particle.cpp | 1 + src/graphics/engine/particle.h | 1 + src/graphics/engine/planet.cpp | 1 + src/graphics/engine/planet.h | 1 + src/graphics/engine/pyro.cpp | 1 + src/graphics/engine/pyro.h | 1 + src/graphics/engine/terrain.cpp | 1 + src/graphics/engine/terrain.h | 1 + src/graphics/engine/test/CMakeLists.txt | 1 + src/graphics/engine/test/modelfile_test.cpp | 1 + src/graphics/engine/text.cpp | 1 + src/graphics/engine/text.h | 1 + src/graphics/engine/water.cpp | 1 + src/graphics/engine/water.h | 1 + 29 files changed, 30 insertions(+), 2 deletions(-) (limited to 'src/graphics/engine') diff --git a/src/graphics/engine/README.txt b/src/graphics/engine/README.txt index 05d2d76..fbf45fd 100644 --- a/src/graphics/engine/README.txt +++ b/src/graphics/engine/README.txt @@ -7,3 +7,4 @@ * * Graphics operations are done on abstract interface from src/graphics/core */ + diff --git a/src/graphics/engine/camera.cpp b/src/graphics/engine/camera.cpp index f65a59a..f0c379c 100644 --- a/src/graphics/engine/camera.cpp +++ b/src/graphics/engine/camera.cpp @@ -1676,3 +1676,4 @@ Math::Vector CCamera::ExcludeObject(Math::Vector eye, Math::Vector lookat, } + diff --git a/src/graphics/engine/camera.h b/src/graphics/engine/camera.h index 0ffc2c2..6d94dad 100644 --- a/src/graphics/engine/camera.h +++ b/src/graphics/engine/camera.h @@ -128,8 +128,7 @@ enum CameraOverEffect ... */ class CCamera { - - public: +public: CCamera(); ~CCamera(); @@ -391,3 +390,4 @@ protected: } // namespace Gfx + diff --git a/src/graphics/engine/cloud.cpp b/src/graphics/engine/cloud.cpp index d9ebf5a..74083af 100644 --- a/src/graphics/engine/cloud.cpp +++ b/src/graphics/engine/cloud.cpp @@ -270,3 +270,4 @@ bool CCloud::GetEnabled() } // namespace Gfx + diff --git a/src/graphics/engine/cloud.h b/src/graphics/engine/cloud.h index 8f644f0..8e820c7 100644 --- a/src/graphics/engine/cloud.h +++ b/src/graphics/engine/cloud.h @@ -140,3 +140,4 @@ protected: } // namespace Gfx + diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 3959c02..0faddbb 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -4332,3 +4332,4 @@ void CEngine::DrawStats() } // namespace Gfx + diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index af8cf6a..8763a4e 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -1431,3 +1431,4 @@ protected: } // namespace Gfx + diff --git a/src/graphics/engine/lightman.cpp b/src/graphics/engine/lightman.cpp index 16c84ea..cbb8509 100644 --- a/src/graphics/engine/lightman.cpp +++ b/src/graphics/engine/lightman.cpp @@ -465,3 +465,4 @@ bool CLightManager::LightsComparator::operator()(const DynamicLight& left, const } } // namespace Gfx + diff --git a/src/graphics/engine/lightman.h b/src/graphics/engine/lightman.h index ab66524..171299c 100644 --- a/src/graphics/engine/lightman.h +++ b/src/graphics/engine/lightman.h @@ -216,3 +216,4 @@ protected: }; }; // namespace Gfx + diff --git a/src/graphics/engine/lightning.cpp b/src/graphics/engine/lightning.cpp index 5fdae51..4395eec 100644 --- a/src/graphics/engine/lightning.cpp +++ b/src/graphics/engine/lightning.cpp @@ -418,3 +418,4 @@ CObject* CLightning::SearchObject(Math::Vector pos) } // namespace Gfx + diff --git a/src/graphics/engine/lightning.h b/src/graphics/engine/lightning.h index 7809a6c..1b1d339 100644 --- a/src/graphics/engine/lightning.h +++ b/src/graphics/engine/lightning.h @@ -107,3 +107,4 @@ protected: } // namespace Gfx + diff --git a/src/graphics/engine/modelfile.cpp b/src/graphics/engine/modelfile.cpp index f6d7a7b..8383b15 100644 --- a/src/graphics/engine/modelfile.cpp +++ b/src/graphics/engine/modelfile.cpp @@ -1199,3 +1199,4 @@ int CModelFile::GetTriangleCount() } // namespace Gfx + diff --git a/src/graphics/engine/modelfile.h b/src/graphics/engine/modelfile.h index 3a702cb..9a01f78 100644 --- a/src/graphics/engine/modelfile.h +++ b/src/graphics/engine/modelfile.h @@ -150,3 +150,4 @@ protected: }; }; // namespace Gfx + diff --git a/src/graphics/engine/modelmanager.cpp b/src/graphics/engine/modelmanager.cpp index 238a7d9..8397e15 100644 --- a/src/graphics/engine/modelmanager.cpp +++ b/src/graphics/engine/modelmanager.cpp @@ -201,3 +201,4 @@ float CModelManager::GetHeight(std::vector& triangles, Math::Vect } + diff --git a/src/graphics/engine/modelmanager.h b/src/graphics/engine/modelmanager.h index a7f9805..26ee130 100644 --- a/src/graphics/engine/modelmanager.h +++ b/src/graphics/engine/modelmanager.h @@ -99,3 +99,4 @@ private: }; } // namespace Gfx + diff --git a/src/graphics/engine/particle.cpp b/src/graphics/engine/particle.cpp index d15ee3b..10b945e 100644 --- a/src/graphics/engine/particle.cpp +++ b/src/graphics/engine/particle.cpp @@ -3917,3 +3917,4 @@ bool CParticle::WriteWheelTrace(const char *filename, int width, int height, } } // namespace Gfx + diff --git a/src/graphics/engine/particle.h b/src/graphics/engine/particle.h index 708a04d..7fb24a1 100644 --- a/src/graphics/engine/particle.h +++ b/src/graphics/engine/particle.h @@ -395,3 +395,4 @@ protected: } // namespace Gfx + diff --git a/src/graphics/engine/planet.cpp b/src/graphics/engine/planet.cpp index 49bcb4c..0c96f63 100644 --- a/src/graphics/engine/planet.cpp +++ b/src/graphics/engine/planet.cpp @@ -185,3 +185,4 @@ int CPlanet::GetMode() } // namespace Gfx + diff --git a/src/graphics/engine/planet.h b/src/graphics/engine/planet.h index 3762e1d..58d3aeb 100644 --- a/src/graphics/engine/planet.h +++ b/src/graphics/engine/planet.h @@ -118,3 +118,4 @@ protected: } // namespace Gfx + diff --git a/src/graphics/engine/pyro.cpp b/src/graphics/engine/pyro.cpp index 0a82408..975a211 100644 --- a/src/graphics/engine/pyro.cpp +++ b/src/graphics/engine/pyro.cpp @@ -2399,3 +2399,4 @@ void CPyro::LightOperFrame(float rTime) } // namespace Gfx + diff --git a/src/graphics/engine/pyro.h b/src/graphics/engine/pyro.h index 9548a07..98b9a1b 100644 --- a/src/graphics/engine/pyro.h +++ b/src/graphics/engine/pyro.h @@ -219,3 +219,4 @@ protected: } // namespace Gfx + diff --git a/src/graphics/engine/terrain.cpp b/src/graphics/engine/terrain.cpp index c2a7855..4fe3057 100644 --- a/src/graphics/engine/terrain.cpp +++ b/src/graphics/engine/terrain.cpp @@ -1801,3 +1801,4 @@ float CTerrain::GetFlyingLimit(Math::Vector pos, bool noLimit) } // namespace Gfx + diff --git a/src/graphics/engine/terrain.h b/src/graphics/engine/terrain.h index 1fa8dec..e2317c4 100644 --- a/src/graphics/engine/terrain.h +++ b/src/graphics/engine/terrain.h @@ -418,3 +418,4 @@ protected: } // namespace Gfx + diff --git a/src/graphics/engine/test/CMakeLists.txt b/src/graphics/engine/test/CMakeLists.txt index afaa86a..134ed2a 100644 --- a/src/graphics/engine/test/CMakeLists.txt +++ b/src/graphics/engine/test/CMakeLists.txt @@ -25,3 +25,4 @@ add_executable(modelfile_test ${MODELFILE_TEST_SOURCES}) target_link_libraries(modelfile_test gtest) add_test(modelfile_test modelfile_test) + diff --git a/src/graphics/engine/test/modelfile_test.cpp b/src/graphics/engine/test/modelfile_test.cpp index e7078a9..1ca7f0a 100644 --- a/src/graphics/engine/test/modelfile_test.cpp +++ b/src/graphics/engine/test/modelfile_test.cpp @@ -260,3 +260,4 @@ int main(int argc, char **argv) ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } + diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index 0f0122d..9bc8bd0 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -913,3 +913,4 @@ CharTexture CText::CreateCharTexture(UTF8Char ch, CachedFont* font) } // namespace Gfx + diff --git a/src/graphics/engine/text.h b/src/graphics/engine/text.h index b19a224..3abb8b7 100644 --- a/src/graphics/engine/text.h +++ b/src/graphics/engine/text.h @@ -342,3 +342,4 @@ protected: } // namespace Gfx + diff --git a/src/graphics/engine/water.cpp b/src/graphics/engine/water.cpp index d90652b..d1f8d29 100644 --- a/src/graphics/engine/water.cpp +++ b/src/graphics/engine/water.cpp @@ -628,3 +628,4 @@ void CWater::AdjustEye(Math::Vector &eye) } // namespace Gfx + diff --git a/src/graphics/engine/water.h b/src/graphics/engine/water.h index bb113e0..5e9f4b2 100644 --- a/src/graphics/engine/water.h +++ b/src/graphics/engine/water.h @@ -204,3 +204,4 @@ protected: } // namespace Gfx + -- cgit v1.2.3-1-g7c22 From 950a3474d561c48b70a13fb638f169b7e8b34d60 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 26 May 2013 19:34:05 +0200 Subject: Refactored sound code * fixed formatting and naming to be uniform with rest of code * moved default implementation of CSound to cpp module --- src/graphics/engine/engine.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/graphics/engine') diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 0faddbb..4d0687a 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -42,6 +42,8 @@ #include "ui/interface.h" +#include + template<> Gfx::CEngine* CSingleton::m_instance = nullptr; // Graphics module namespace -- cgit v1.2.3-1-g7c22 From b22d852b4c4aa89e0394397a703ecfa442b0a928 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Mon, 27 May 2013 22:26:44 +0200 Subject: Fixed variable shadowing warnings * fixed -Wshadow warnings * refactored some constructors --- src/graphics/engine/engine.h | 47 ++++++++++++++++++++++---------------- src/graphics/engine/modelmanager.h | 6 +++-- src/graphics/engine/particle.cpp | 6 ++--- src/graphics/engine/pyro.cpp | 12 ++++++---- src/graphics/engine/text.cpp | 2 +- 5 files changed, 42 insertions(+), 31 deletions(-) (limited to 'src/graphics/engine') diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index 8763a4e..27aa5dc 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -194,10 +194,15 @@ struct EngineBaseObjDataTier unsigned int staticBufferId; bool updateStaticBuffer; - inline EngineBaseObjDataTier(EngineTriangleType type = ENG_TRIANGLE_TYPE_TRIANGLES, - const Material& material = Material(), - int state = ENG_RSTATE_NORMAL) - : type(type), material(material), state(state), staticBufferId(0), updateStaticBuffer(false) {} + inline EngineBaseObjDataTier(EngineTriangleType _type = ENG_TRIANGLE_TYPE_TRIANGLES, + const Material& _material = Material(), + int _state = ENG_RSTATE_NORMAL) + : type(_type) + , material(_material) + , state(_state) + , staticBufferId(0) + , updateStaticBuffer(false) + {} }; /** @@ -209,8 +214,9 @@ struct EngineBaseObjLODTier LODLevel lodLevel; std::vector next; - inline EngineBaseObjLODTier(LODLevel lodLevel = LOD_Constant) - : lodLevel(lodLevel) {} + inline EngineBaseObjLODTier(LODLevel _lodLevel = LOD_Constant) + : lodLevel(_lodLevel) + {} }; /** @@ -225,8 +231,10 @@ struct EngineBaseObjTexTier Texture tex2; std::vector next; - inline EngineBaseObjTexTier(const std::string& tex1Name = "", const std::string& tex2Name = "") - : tex1Name(tex1Name), tex2Name(tex2Name) {} + inline EngineBaseObjTexTier(const std::string& _tex1Name = "", const std::string& _tex2Name = "") + : tex1Name(_tex1Name) + , tex2Name(_tex2Name) + {} }; /** @@ -556,18 +564,17 @@ struct EngineMouse //! Hot point Math::Point hotPoint; - inline EngineMouse(int icon1 = -1, int icon2 = -1, int iconShadow = -1, - EngineRenderState mode1 = ENG_RSTATE_NORMAL, - EngineRenderState mode2 = ENG_RSTATE_NORMAL, - Math::Point hotPoint = Math::Point()) - { - this->icon1 = icon1; - this->icon2 = icon2; - this->iconShadow = iconShadow; - this->mode1 = mode1; - this->mode2 = mode2; - this->hotPoint = hotPoint; - } + inline EngineMouse(int _icon1 = -1, int _icon2 = -1, int _iconShadow = -1, + EngineRenderState _mode1 = ENG_RSTATE_NORMAL, + EngineRenderState _mode2 = ENG_RSTATE_NORMAL, + Math::Point _hotPoint = Math::Point()) + : icon1(_icon1) + , icon2(_icon2) + , iconShadow(_iconShadow) + , mode1(_mode1) + , mode2(_mode2) + , hotPoint(_hotPoint) + {} }; diff --git a/src/graphics/engine/modelmanager.h b/src/graphics/engine/modelmanager.h index 26ee130..9d50b97 100644 --- a/src/graphics/engine/modelmanager.h +++ b/src/graphics/engine/modelmanager.h @@ -79,8 +79,10 @@ private: std::string fileName; bool mirrored; - inline FileInfo(const std::string& fileName, bool mirrored) - : fileName(fileName), mirrored(mirrored) {} + inline FileInfo(const std::string& _fileName, bool _mirrored) + : fileName(_fileName) + , mirrored(_mirrored) + {} inline bool operator<(const FileInfo& other) const { diff --git a/src/graphics/engine/particle.cpp b/src/graphics/engine/particle.cpp index 10b945e..abee2e2 100644 --- a/src/graphics/engine/particle.cpp +++ b/src/graphics/engine/particle.cpp @@ -3553,9 +3553,9 @@ void CParticle::DrawParticle(int sheet) { m_engine->SetTexture("text.png"); m_engine->SetState(ENG_RSTATE_TTEXTURE_WHITE); - Math::Matrix mat; - mat.LoadIdentity(); - m_device->SetTransform(TRANSFORM_WORLD, mat); + Math::Matrix matrix; + matrix.LoadIdentity(); + m_device->SetTransform(TRANSFORM_WORLD, matrix); for (int i = 0; i < m_wheelTraceTotal; i++) DrawParticleWheel(i); diff --git a/src/graphics/engine/pyro.cpp b/src/graphics/engine/pyro.cpp index 975a211..0a85beb 100644 --- a/src/graphics/engine/pyro.cpp +++ b/src/graphics/engine/pyro.cpp @@ -89,13 +89,15 @@ bool CPyro::Create(PyroType type, CObject* obj, float force) DisplayError(type, obj); // displays eventual messages - int i = 0; - // Copies all spheres of the object. - for (; i < 50; i++) { - if ( !obj->GetCrashSphere(i, m_crashSpherePos[i], m_crashSphereRadius[i]) ) break; + int i = 0; + // Copies all spheres of the object. + for (; i < 50; i++) + { + if ( !obj->GetCrashSphere(i, m_crashSpherePos[i], m_crashSphereRadius[i]) ) break; + } + m_crashSphereUsed = i; } - m_crashSphereUsed = i; // Calculates the size of the effect. if ( oType == OBJECT_ANT || diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index 9bc8bd0..610bfcf 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -613,7 +613,7 @@ void CText::DrawString(const std::string &text, std::vector::itera float cw = GetCharWidth(ch, font, size, offset); if (offset + cw > width) // exceeds the maximum width? { - UTF8Char ch = TranslateSpecialChar(CHAR_SKIP_RIGHT); + ch = TranslateSpecialChar(CHAR_SKIP_RIGHT); cw = GetCharWidth(ch, font, size, offset); pos.x = start + width - cw; color = Color(1.0f, 0.0f, 0.0f); -- cgit v1.2.3-1-g7c22 From 18b27d258efa59a08406c061190d8ea1d70f314c Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 8 Jun 2013 17:51:31 +0200 Subject: Fixed bug with white map I'm not sure when it was introduced, probably in 8f6fd2a1316432970f1d86515819e7bbe15ddab3. It was showing errors like "Couldn't load texture 'map.png'" and "Invalid texture data" --- src/graphics/engine/engine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/graphics/engine') diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 4d0687a..785383a 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -2156,7 +2156,7 @@ Texture CEngine::CreateTexture(const std::string& texName, const TextureCreatePa image = &img; } - tex = m_device->CreateTexture(&img, params); + tex = m_device->CreateTexture(image, params); if (! tex.Valid()) { -- cgit v1.2.3-1-g7c22 From 7874aca10ce6da823f88e8aabe4a0ea6431cc480 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 16 Jun 2013 21:39:21 +0200 Subject: Enhanced logging, option to auto-start mission * added logging of application events * changed debug mode flag to independent debug modes * added option to auto-start mission (load a mission immediately after startup) * removed "enum value out of range" prints * some refactoring --- src/graphics/engine/modelfile.cpp | 79 ++++++++++++++++++++---------------- src/graphics/engine/modelfile.h | 4 ++ src/graphics/engine/modelmanager.cpp | 3 ++ 3 files changed, 52 insertions(+), 34 deletions(-) (limited to 'src/graphics/engine') diff --git a/src/graphics/engine/modelfile.cpp b/src/graphics/engine/modelfile.cpp index 8383b15..99496aa 100644 --- a/src/graphics/engine/modelfile.cpp +++ b/src/graphics/engine/modelfile.cpp @@ -310,6 +310,7 @@ bool ReadLineString(std::istream& stream, const std::string& prefix, std::string CModelFile::CModelFile() + : m_printDebugInfo(false) { } @@ -615,23 +616,26 @@ bool CModelFile::ReadModel(std::istream& stream) if (m_triangles[i].tex1Name == "plant.png") m_triangles[i].state |= ENG_RSTATE_ALPHA; - GetLogger()->Trace("ModelTriangle %d\n", i+1); - std::string s1 = m_triangles[i].p1.ToString(); - GetLogger()->Trace(" p1: %s\n", s1.c_str()); - std::string s2 = m_triangles[i].p2.ToString(); - GetLogger()->Trace(" p2: %s\n", s2.c_str()); - std::string s3 = m_triangles[i].p3.ToString(); - GetLogger()->Trace(" p3: %s\n", s3.c_str()); - - std::string d = m_triangles[i].material.diffuse.ToString(); - std::string a = m_triangles[i].material.ambient.ToString(); - std::string s = m_triangles[i].material.specular.ToString(); - GetLogger()->Trace(" mat: d: %s a: %s s: %s\n", d.c_str(), a.c_str(), s.c_str()); - - GetLogger()->Trace(" tex1: %s tex2: %s\n", m_triangles[i].tex1Name.c_str(), - m_triangles[i].variableTex2 ? "(variable)" : m_triangles[i].tex2Name.c_str()); - GetLogger()->Trace(" lod level: %d\n", m_triangles[i].lodLevel); - GetLogger()->Trace(" state: %ld\n", m_triangles[i].state); + if (m_printDebugInfo) + { + GetLogger()->Trace("ModelTriangle %d\n", i+1); + std::string s1 = m_triangles[i].p1.ToString(); + GetLogger()->Trace(" p1: %s\n", s1.c_str()); + std::string s2 = m_triangles[i].p2.ToString(); + GetLogger()->Trace(" p2: %s\n", s2.c_str()); + std::string s3 = m_triangles[i].p3.ToString(); + GetLogger()->Trace(" p3: %s\n", s3.c_str()); + + std::string d = m_triangles[i].material.diffuse.ToString(); + std::string a = m_triangles[i].material.ambient.ToString(); + std::string s = m_triangles[i].material.specular.ToString(); + GetLogger()->Trace(" mat: d: %s a: %s s: %s\n", d.c_str(), a.c_str(), s.c_str()); + + GetLogger()->Trace(" tex1: %s tex2: %s\n", m_triangles[i].tex1Name.c_str(), + m_triangles[i].variableTex2 ? "(variable)" : m_triangles[i].tex2Name.c_str()); + GetLogger()->Trace(" lod level: %d\n", m_triangles[i].lodLevel); + GetLogger()->Trace(" state: %ld\n", m_triangles[i].state); + } } return true; @@ -1093,24 +1097,27 @@ bool CModelFile::ReadBinaryModel(std::istream& stream) return false; } - for (int i = 0; i < static_cast( m_triangles.size() ); ++i) + if (m_printDebugInfo) { - GetLogger()->Trace("ModelTriangle %d\n", i+1); - std::string s1 = m_triangles[i].p1.ToString(); - GetLogger()->Trace(" p1: %s\n", s1.c_str()); - std::string s2 = m_triangles[i].p2.ToString(); - GetLogger()->Trace(" p2: %s\n", s2.c_str()); - std::string s3 = m_triangles[i].p3.ToString(); - GetLogger()->Trace(" p3: %s\n", s3.c_str()); - - std::string d = m_triangles[i].material.diffuse.ToString(); - std::string a = m_triangles[i].material.ambient.ToString(); - std::string s = m_triangles[i].material.specular.ToString(); - GetLogger()->Trace(" mat: d: %s a: %s s: %s\n", d.c_str(), a.c_str(), s.c_str()); - - GetLogger()->Trace(" tex1: %s tex2: %s\n", m_triangles[i].tex1Name.c_str(), m_triangles[i].tex2Name.c_str()); - GetLogger()->Trace(" lod level: %d\n", m_triangles[i].lodLevel); - GetLogger()->Trace(" state: %ld\n", m_triangles[i].state); + for (int i = 0; i < static_cast( m_triangles.size() ); ++i) + { + GetLogger()->Trace("ModelTriangle %d\n", i+1); + std::string s1 = m_triangles[i].p1.ToString(); + GetLogger()->Trace(" p1: %s\n", s1.c_str()); + std::string s2 = m_triangles[i].p2.ToString(); + GetLogger()->Trace(" p2: %s\n", s2.c_str()); + std::string s3 = m_triangles[i].p3.ToString(); + GetLogger()->Trace(" p3: %s\n", s3.c_str()); + + std::string d = m_triangles[i].material.diffuse.ToString(); + std::string a = m_triangles[i].material.ambient.ToString(); + std::string s = m_triangles[i].material.specular.ToString(); + GetLogger()->Trace(" mat: d: %s a: %s s: %s\n", d.c_str(), a.c_str(), s.c_str()); + + GetLogger()->Trace(" tex1: %s tex2: %s\n", m_triangles[i].tex1Name.c_str(), m_triangles[i].tex2Name.c_str()); + GetLogger()->Trace(" lod level: %d\n", m_triangles[i].lodLevel); + GetLogger()->Trace(" state: %ld\n", m_triangles[i].state); + } } return true; @@ -1197,6 +1204,10 @@ int CModelFile::GetTriangleCount() return m_triangles.size(); } +void CModelFile::SetPrintDebugInfo(bool printDebugInfo) +{ + m_printDebugInfo = printDebugInfo; +} } // namespace Gfx diff --git a/src/graphics/engine/modelfile.h b/src/graphics/engine/modelfile.h index 9a01f78..3b4019b 100644 --- a/src/graphics/engine/modelfile.h +++ b/src/graphics/engine/modelfile.h @@ -137,6 +137,9 @@ public: //! Returns the triangle vector const std::vector& GetTriangles(); + //! Controls printing of debug information + void SetPrintDebugInfo(bool printDebugInfo); + protected: //@{ //! @deprecated min, max conversions @@ -147,6 +150,7 @@ protected: protected: //! Model triangles std::vector m_triangles; + bool m_printDebugInfo; }; }; // namespace Gfx diff --git a/src/graphics/engine/modelmanager.cpp b/src/graphics/engine/modelmanager.cpp index 8397e15..abc8c6c 100644 --- a/src/graphics/engine/modelmanager.cpp +++ b/src/graphics/engine/modelmanager.cpp @@ -27,6 +27,9 @@ bool CModelManager::LoadModel(const std::string& fileName, bool mirrored) CModelFile modelFile; + if (CApplication::GetInstance().IsDebugModeActive(DEBUG_MODELS)) + modelFile.SetPrintDebugInfo(true); + std::string filePath = CApplication::GetInstance().GetDataFilePath(DIR_MODEL, fileName); if (!modelFile.ReadModel(filePath)) -- cgit v1.2.3-1-g7c22 From b4700e3bedc52f9fc7b5008ae06c4e6f9e3fe130 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Mon, 17 Jun 2013 11:48:57 +0200 Subject: Fix for #133 * objects are now copied and textures are updated correctly * also added function to debug objects --- src/graphics/engine/engine.cpp | 93 +++++++++++++++++++++++++++++++++++++++--- src/graphics/engine/engine.h | 5 ++- src/graphics/engine/pyro.cpp | 16 +++++++- 3 files changed, 106 insertions(+), 8 deletions(-) (limited to 'src/graphics/engine') diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 785383a..3423864 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -698,6 +698,82 @@ void CEngine::AddBaseObjQuick(int baseObjRank, const EngineBaseObjDataTier& buff p1.totalTriangles += p4.vertices.size() - 2; } +void CEngine::DebugObject(int objRank) +{ + assert(objRank >= 0 && objRank < static_cast( m_objects.size() )); + + CLogger* l = GetLogger(); + + l->Debug("Debug object: %d\n", objRank); + if (! m_objects[objRank].used) + { + l->Debug(" not used\n"); + return; + } + + l->Debug(" baseObjRank = %d\n", m_objects[objRank].baseObjRank); + l->Debug(" visible = %s\n", m_objects[objRank].visible ? "true" : "false"); + l->Debug(" drawWorld = %s\n", m_objects[objRank].drawWorld ? "true" : "false"); + l->Debug(" drawFront = %s\n", m_objects[objRank].drawFront ? "true" : "false"); + l->Debug(" type = %d\n", m_objects[objRank].type); + l->Debug(" distance = %f\n", m_objects[objRank].distance); + l->Debug(" shadowRank = %d\n", m_objects[objRank].shadowRank); + l->Debug(" transparency = %f\n", m_objects[objRank].transparency); + + l->Debug(" baseObj:\n"); + int baseObjRank = m_objects[objRank].baseObjRank; + if (baseObjRank == -1) + { + l->Debug(" null\n"); + return; + } + + assert(baseObjRank >= 0 && baseObjRank < static_cast( m_baseObjects.size() )); + + EngineBaseObject& p1 = m_baseObjects[baseObjRank]; + if (!p1.used) + { + l->Debug(" not used\n"); + return; + } + + std::string vecStr; + + vecStr = p1.bboxMin.ToString(); + l->Debug(" bboxMin: %s\n", vecStr.c_str()); + vecStr = p1.bboxMax.ToString(); + l->Debug(" bboxMax: %s\n", vecStr.c_str()); + l->Debug(" totalTriangles: %d\n", p1.totalTriangles); + l->Debug(" radius: %f\n", p1.radius); + + for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) + { + EngineBaseObjTexTier& p2 = p1.next[l2]; + l->Debug(" l2:\n"); + + l->Debug(" tex1: %s (id: %u)\n", p2.tex1Name.c_str(), p2.tex1.id); + l->Debug(" tex2: %s (id: %u)\n", p2.tex2Name.c_str(), p2.tex2.id); + + for (int l3 = 0; l3 < static_cast( p2.next.size() ); l3++) + { + EngineBaseObjLODTier& p3 = p2.next[l3]; + + l->Debug(" l3:\n"); + l->Debug(" lodLevel: %d\n", p3.lodLevel); + + for (int l4 = 0; l4 < static_cast( p3.next.size() ); l4++) + { + EngineBaseObjDataTier& p4 = p3.next[l4]; + + l->Debug(" l4:\n"); + l->Debug(" type: %d\n", p4.type); + l->Debug(" state: %d\n", p4.state); + l->Debug(" staticBufferId: %u\n", p4.staticBufferId); + l->Debug(" updateStaticBuffer: %s\n", p4.updateStaticBuffer ? "true" : "false"); + } + } + } +} int CEngine::CreateObject() { @@ -986,14 +1062,19 @@ void CEngine::ChangeSecondTexture(int objRank, const std::string& tex2Name) for (int l2 = 0; l2 < static_cast( p1.next.size() ); l2++) { - EngineBaseObjTexTier& p2 = p1.next[l2]; - - if (p2.tex2Name == tex2Name) + if (p1.next[l2].tex2Name == tex2Name) continue; // already new - EngineBaseObjTexTier& newP2 = AddLevel2(p1, p2.tex1Name, tex2Name); - newP2.next.insert(newP2.next.end(), p2.next.begin(), p2.next.end()); - p2.next.clear(); + std::string tex1Name = p1.next[l2].tex1Name; + EngineBaseObjTexTier& newP2 = AddLevel2(p1, tex1Name, tex2Name); + newP2.next.insert(newP2.next.end(), p1.next[l2].next.begin(), p1.next[l2].next.end()); + p1.next[l2].next.clear(); + + if (!newP2.tex1.Valid()) + newP2.tex1 = LoadTexture(newP2.tex1Name); + + if (!newP2.tex2.Valid()) + newP2.tex2 = LoadTexture(newP2.tex2Name); } } diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index 27aa5dc..207ae27 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -118,7 +118,7 @@ enum EngineRenderState //! Mode for rendering text ENG_RSTATE_TEXT = (1<<18), //! Only opaque texture, no blending, etc. - ENG_RSTATE_OPAQUE_TEXTURE = (1<<19), + ENG_RSTATE_OPAQUE_TEXTURE = (1<<19), //! Only opaque color, no texture, blending, etc. ENG_RSTATE_OPAQUE_COLOR = (1<<20) }; @@ -807,6 +807,9 @@ public: // Objects + //! Print debug info about an object + void DebugObject(int rank); + //! Creates a new object and returns its rank int CreateObject(); //! Deletes all objects, shadows and ground spots diff --git a/src/graphics/engine/pyro.cpp b/src/graphics/engine/pyro.cpp index 0a85beb..93198ec 100644 --- a/src/graphics/engine/pyro.cpp +++ b/src/graphics/engine/pyro.cpp @@ -1556,7 +1556,14 @@ void CPyro::ExploStart() for (int i = 0; i < OBJECTMAXPART; i++) { int objRank = m_object->GetObjectRank(i); - if ( objRank == -1 ) continue; + if (objRank == -1) continue; + + // TODO: refactor later to material change + int oldBaseObjRank = m_engine->GetObjectBaseRank(objRank); + int newBaseObjRank = m_engine->CreateBaseObject(); + m_engine->CopyBaseObject(oldBaseObjRank, newBaseObjRank); + m_engine->SetObjectBaseRank(objRank, newBaseObjRank); + m_engine->ChangeSecondTexture(objRank, "dirty04.png"); Math::Vector pos = m_object->GetPosition(i); @@ -1618,6 +1625,13 @@ void CPyro::BurnStart() { int objRank = m_object->GetObjectRank(i); if (objRank == -1) continue; + + // TODO: refactor later to material change + int oldBaseObjRank = m_engine->GetObjectBaseRank(objRank); + int newBaseObjRank = m_engine->CreateBaseObject(); + m_engine->CopyBaseObject(oldBaseObjRank, newBaseObjRank); + m_engine->SetObjectBaseRank(objRank, newBaseObjRank); + m_engine->ChangeSecondTexture(objRank, "dirty04.png"); } m_engine->LoadTexture("dirty04.png"); -- cgit v1.2.3-1-g7c22 From 366d3a551ef3541f6eeb226f80a16b8de8fdd2e9 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Mon, 17 Jun 2013 18:06:39 +0200 Subject: Added debug aids for lighting * displaying positions of current lights (F11) * dumping info to console (F10) * added assert() in suspicious place in CPyro --- src/graphics/engine/engine.cpp | 27 +++++++++++++++++ src/graphics/engine/engine.h | 3 ++ src/graphics/engine/lightman.cpp | 64 ++++++++++++++++++++++++++++++++++++++-- src/graphics/engine/lightman.h | 6 ++++ src/graphics/engine/pyro.cpp | 1 + 5 files changed, 98 insertions(+), 3 deletions(-) (limited to 'src/graphics/engine') diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 3423864..669ea42 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -128,6 +128,9 @@ CEngine::CEngine(CApplication *app) m_interfaceMode = false; + m_debugLights = false; + m_debugDumpLights = false; + m_mice[ENG_MOUSE_NORM] = EngineMouse( 0, 1, 32, ENG_RSTATE_TTEXTURE_WHITE, ENG_RSTATE_TTEXTURE_BLACK, Math::Point( 1.0f, 1.0f)); m_mice[ENG_MOUSE_WAIT] = EngineMouse( 2, 3, 33, ENG_RSTATE_TTEXTURE_WHITE, ENG_RSTATE_TTEXTURE_BLACK, Math::Point( 8.0f, 12.0f)); m_mice[ENG_MOUSE_HAND] = EngineMouse( 4, 5, 34, ENG_RSTATE_TTEXTURE_WHITE, ENG_RSTATE_TTEXTURE_BLACK, Math::Point( 7.0f, 2.0f)); @@ -325,7 +328,22 @@ bool CEngine::ProcessEvent(const Event &event) if (event.type == EVENT_KEY_DOWN) { if (event.key.key == KEY(F12)) + { m_showStats = !m_showStats; + return false; + } + + if (event.key.key == KEY(F11)) + { + m_debugLights = !m_debugLights; + return false; + } + + if (event.key.key == KEY(F10)) + { + m_debugDumpLights = true; + return false; + } } // By default, pass on all events @@ -3293,6 +3311,15 @@ void CEngine::Draw3DScene() m_lightMan->UpdateDeviceLights(ENG_OBJTYPE_TERRAIN); + if (m_debugLights) + m_device->DebugLights(); + + if (m_debugDumpLights) + { + m_debugDumpLights = false; + m_lightMan->DebugDumpLights(); + } + if (m_waterMode) { m_app->StartPerformanceCounter(PCNT_RENDER_WATER); diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index 207ae27..5ecde8f 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -1437,6 +1437,9 @@ protected: //! True when drawing 2D UI bool m_interfaceMode; + + bool m_debugLights; + bool m_debugDumpLights; }; diff --git a/src/graphics/engine/lightman.cpp b/src/graphics/engine/lightman.cpp index cbb8509..3e512d8 100644 --- a/src/graphics/engine/lightman.cpp +++ b/src/graphics/engine/lightman.cpp @@ -71,6 +71,7 @@ void LightProgression::SetTarget(float value) DynamicLight::DynamicLight() { + rank = 0; used = enabled = false; priority = LIGHT_PRI_LOW; includeType = excludeType = ENG_OBJTYPE_NULL; @@ -98,6 +99,61 @@ void CLightManager::SetDevice(CDevice* device) m_lightMap = std::vector(m_device->GetMaxLightCount(), -1); } +void CLightManager::DebugDumpLights() +{ + CLogger* l = GetLogger(); + + l->Debug("Dynamic lights:\n"); + + for (int i = 0; i < static_cast( m_dynLights.size() ); ++i) + { + const DynamicLight& dynLight = m_dynLights[i]; + if (!dynLight.used) + continue; + + int deviceLight = -1; + for (int j = 0; j < m_lightMap.size(); ++j) + { + if (m_lightMap[j] == i) + { + deviceLight = j; + break; + } + } + + l->Debug(" light %d\n", i); + l->Debug(" enabled = %s\n", dynLight.enabled ? "true" : "false"); + l->Debug(" priority = %d\n", dynLight.priority); + l->Debug(" device light = %d\n", deviceLight); + l->Debug(" light:\n"); + + const Light& light = dynLight.light; + std::string str; + + l->Debug(" type = %d\n", light.type); + str = light.ambient.ToString(); + l->Debug(" ambient = %s\n", str.c_str()); + str = light.diffuse.ToString(); + l->Debug(" diffuse = %s\n", str.c_str()); + str = light.specular.ToString(); + l->Debug(" specular = %s\n", str.c_str()); + str = light.position.ToString(); + l->Debug(" position = %s\n", str.c_str()); + str = light.direction.ToString(); + l->Debug(" direction = %s\n", str.c_str()); + l->Debug(" attenuation0 = %s\n", light.attenuation0); + l->Debug(" attenuation1 = %s\n", light.attenuation1); + l->Debug(" attenuation2 = %s\n", light.attenuation2); + l->Debug(" spotAngle = %s\n", light.spotAngle); + l->Debug(" spotIntensity = %s\n", light.spotIntensity); + + l->Debug(" intensity: %f\n", dynLight.intensity.current); + l->Debug(" color: %f %f %f\n", dynLight.colorRed.current, dynLight.colorGreen.current, dynLight.colorBlue.current); + l->Debug(" includeType: %d\n", dynLight.includeType); + l->Debug(" excludeType: %d\n", dynLight.excludeType); + } +} + void CLightManager::FlushLights() { m_dynLights.clear(); @@ -117,6 +173,7 @@ int CLightManager::CreateLight(LightPriority priority) m_dynLights.push_back(DynamicLight()); m_dynLights[index] = DynamicLight(); + m_dynLights[index].rank = index; m_dynLights[index].used = true; m_dynLights[index].enabled = true; m_dynLights[index].priority = priority; @@ -411,7 +468,7 @@ void CLightManager::UpdateDeviceLights(EngineObjectType type) if (enabled) { - m_lightMap[lightMapIndex] = i; + m_lightMap[lightMapIndex] = sortedLights[i].rank; ++lightMapIndex; } @@ -424,8 +481,9 @@ void CLightManager::UpdateDeviceLights(EngineObjectType type) int rank = m_lightMap[i]; if (rank != -1) { - sortedLights[rank].light.ambient = Gfx::Color(0.2f, 0.2f, 0.2f); - m_device->SetLight(i, sortedLights[rank].light); + Light light = m_dynLights[rank].light; + light.ambient = Gfx::Color(0.2f, 0.2f, 0.2f); + m_device->SetLight(i, light); m_device->SetLightEnabled(i, true); } else diff --git a/src/graphics/engine/lightman.h b/src/graphics/engine/lightman.h index 171299c..d0ac338 100644 --- a/src/graphics/engine/lightman.h +++ b/src/graphics/engine/lightman.h @@ -84,6 +84,9 @@ enum LightPriority */ struct DynamicLight { + //! Rank (index) + int rank; + //! Whether the light is used bool used; //! Whether the light is turned on @@ -136,6 +139,9 @@ public: //! Sets the device to be used void SetDevice(CDevice* device); + //! Prints debug info + void DebugDumpLights(); + //! Clears and disables all lights void FlushLights(); //! Creates a new dynamic light and returns its index (lightRank) diff --git a/src/graphics/engine/pyro.cpp b/src/graphics/engine/pyro.cpp index 93198ec..7c51829 100644 --- a/src/graphics/engine/pyro.cpp +++ b/src/graphics/engine/pyro.cpp @@ -2398,6 +2398,7 @@ void CPyro::LightOperFrame(float rTime) { if ( m_progress < m_lightOper[i].progress ) { + assert(i > 0); // TODO: if assert fails, fix the code float progress = (m_progress-m_lightOper[i-1].progress) / (m_lightOper[i].progress-m_lightOper[i-1].progress); float intensity = m_lightOper[i-1].intensity + (m_lightOper[i].intensity-m_lightOper[i-1].intensity)*progress; -- cgit v1.2.3-1-g7c22 From 4c33172e173b8f815a367f1e1c0fae06d9051df5 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Mon, 17 Jun 2013 20:52:56 +0200 Subject: Fixed string formats in light debug prints --- src/graphics/engine/lightman.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/graphics/engine') diff --git a/src/graphics/engine/lightman.cpp b/src/graphics/engine/lightman.cpp index 3e512d8..cd743a5 100644 --- a/src/graphics/engine/lightman.cpp +++ b/src/graphics/engine/lightman.cpp @@ -141,11 +141,11 @@ void CLightManager::DebugDumpLights() l->Debug(" position = %s\n", str.c_str()); str = light.direction.ToString(); l->Debug(" direction = %s\n", str.c_str()); - l->Debug(" attenuation0 = %s\n", light.attenuation0); - l->Debug(" attenuation1 = %s\n", light.attenuation1); - l->Debug(" attenuation2 = %s\n", light.attenuation2); - l->Debug(" spotAngle = %s\n", light.spotAngle); - l->Debug(" spotIntensity = %s\n", light.spotIntensity); + l->Debug(" attenuation0 = %f\n", light.attenuation0); + l->Debug(" attenuation1 = %f\n", light.attenuation1); + l->Debug(" attenuation2 = %f\n", light.attenuation2); + l->Debug(" spotAngle = %f\n", light.spotAngle); + l->Debug(" spotIntensity = %f\n", light.spotIntensity); l->Debug(" intensity: %f\n", dynLight.intensity.current); l->Debug(" color: %f %f %f\n", dynLight.colorRed.current, dynLight.colorGreen.current, dynLight.colorBlue.current); -- cgit v1.2.3-1-g7c22 From 28b4e9a63450110978d60de80a9af2e901d49a97 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Thu, 20 Jun 2013 23:14:37 +0200 Subject: Fixed terrain light priorities (fix for #139) * lights illuminating the terrain specified in scene file are now always moved to front of light ordering --- src/graphics/engine/lightman.cpp | 12 ++++++++++++ src/graphics/engine/lightman.h | 7 +++++-- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'src/graphics/engine') diff --git a/src/graphics/engine/lightman.cpp b/src/graphics/engine/lightman.cpp index cd743a5..295b3da 100644 --- a/src/graphics/engine/lightman.cpp +++ b/src/graphics/engine/lightman.cpp @@ -236,6 +236,15 @@ bool CLightManager::SetLightEnabled(int lightRank, bool enabled) return true; } +bool CLightManager::SetLightPriority(int lightRank, LightPriority priority) +{ + if ( (lightRank < 0) || (lightRank >= static_cast( m_dynLights.size() )) ) + return false; + + m_dynLights[lightRank].priority = priority; + return true; +} + bool CLightManager::SetLightIncludeType(int lightRank, EngineObjectType type) { if ( (lightRank < 0) || (lightRank >= static_cast( m_dynLights.size() )) ) @@ -503,6 +512,9 @@ CLightManager::LightsComparator::LightsComparator(Math::Vector eyePos, EngineObj float CLightManager::LightsComparator::GetLightWeight(const DynamicLight& dynLight) { + if (dynLight.priority == LIGHT_PRI_HIGHEST) + return -1.0f; + bool enabled = true; if (!dynLight.used || !dynLight.enabled || dynLight.intensity.current == 0.0f) enabled = false; diff --git a/src/graphics/engine/lightman.h b/src/graphics/engine/lightman.h index d0ac338..9677555 100644 --- a/src/graphics/engine/lightman.h +++ b/src/graphics/engine/lightman.h @@ -71,8 +71,9 @@ struct LightProgression */ enum LightPriority { - LIGHT_PRI_HIGH = 1, - LIGHT_PRI_LOW = 2 + LIGHT_PRI_HIGHEST = 1, //!< always highest weight (always picked) + LIGHT_PRI_HIGH = 2, //!< high weight + LIGHT_PRI_LOW = 3 //!< low weight }; /** @@ -154,6 +155,8 @@ public: bool GetLight(int lightRank, Light &light); //! Enables/disables the given dynamic light bool SetLightEnabled(int lightRank, bool enable); + //! Changes the light priority + bool SetLightPriority(int lightRank, LightPriority priority); //! Sets what objects are included in given dynamic light bool SetLightIncludeType(int lightRank, EngineObjectType type); -- cgit v1.2.3-1-g7c22 From 1377e48910c1bef1829c67740360b0a8309239a1 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sat, 22 Jun 2013 01:16:40 +0200 Subject: Reverted enum values to fix UT regression --- src/graphics/engine/lightman.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/graphics/engine') diff --git a/src/graphics/engine/lightman.h b/src/graphics/engine/lightman.h index 9677555..a2f6044 100644 --- a/src/graphics/engine/lightman.h +++ b/src/graphics/engine/lightman.h @@ -71,9 +71,9 @@ struct LightProgression */ enum LightPriority { - LIGHT_PRI_HIGHEST = 1, //!< always highest weight (always picked) - LIGHT_PRI_HIGH = 2, //!< high weight - LIGHT_PRI_LOW = 3 //!< low weight + LIGHT_PRI_HIGHEST = 0, //!< always highest weight (always picked) + LIGHT_PRI_HIGH = 1, //!< high weight + LIGHT_PRI_LOW = 2 //!< low weight }; /** -- cgit v1.2.3-1-g7c22 From bfcce26f8949f4ba42cc1bd8203dff51884aa0da Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sat, 22 Jun 2013 01:11:37 +0200 Subject: Changes in build organization * targets are now created in top-level build directory * more things are now configured through CMake options * changed debug build detection from NDEBUG to DEV_BUILD * moved po and desktop directories * moved last unit test out of src directory --- src/graphics/engine/lightman.cpp | 2 +- src/graphics/engine/test/CMakeLists.txt | 28 --- src/graphics/engine/test/modelfile_test.cpp | 263 ---------------------------- 3 files changed, 1 insertion(+), 292 deletions(-) delete mode 100644 src/graphics/engine/test/CMakeLists.txt delete mode 100644 src/graphics/engine/test/modelfile_test.cpp (limited to 'src/graphics/engine') diff --git a/src/graphics/engine/lightman.cpp b/src/graphics/engine/lightman.cpp index 295b3da..8694c7a 100644 --- a/src/graphics/engine/lightman.cpp +++ b/src/graphics/engine/lightman.cpp @@ -112,7 +112,7 @@ void CLightManager::DebugDumpLights() continue; int deviceLight = -1; - for (int j = 0; j < m_lightMap.size(); ++j) + for (int j = 0; j < static_cast( m_lightMap.size() ); ++j) { if (m_lightMap[j] == i) { diff --git a/src/graphics/engine/test/CMakeLists.txt b/src/graphics/engine/test/CMakeLists.txt deleted file mode 100644 index 134ed2a..0000000 --- a/src/graphics/engine/test/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ -cmake_minimum_required(VERSION 2.8) - -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE debug) -endif(NOT CMAKE_BUILD_TYPE) -set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") - -set(MODELFILE_TEST_SOURCES -modelfile_test.cpp -../modelfile.cpp -../../../common/logger.cpp -../../../common/stringutils.cpp -) - -add_definitions(-DMODELFILE_NO_ENGINE) - -include_directories( -. -../../.. -${GTEST_INCLUDE_DIR} -) - -add_executable(modelfile_test ${MODELFILE_TEST_SOURCES}) - -target_link_libraries(modelfile_test gtest) - -add_test(modelfile_test modelfile_test) - diff --git a/src/graphics/engine/test/modelfile_test.cpp b/src/graphics/engine/test/modelfile_test.cpp deleted file mode 100644 index 1ca7f0a..0000000 --- a/src/graphics/engine/test/modelfile_test.cpp +++ /dev/null @@ -1,263 +0,0 @@ -// * This file is part of the COLOBOT source code -// * Copyright (C) 2012, Polish Portal of Colobot (PPC) -// * -// * This program is free software: you can redistribute it and/or modify -// * it under the terms of the GNU General Public License as published by -// * the Free Software Foundation, either version 3 of the License, or -// * (at your option) any later version. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program. If not, see http://www.gnu.org/licenses/. - - -#include "common/logger.h" -#include "graphics/engine/modelfile.h" -#include "math/func.h" - -#include - -#include -#include - -/* Test model file (new text format) */ -const char* const TEXT_MODEL = -"# Colobot text model\n" -"\n" -"### HEAD\n" -"version 1\n" -"total_triangles 2\n" -"\n" -"### TRIANGLES\n" -"p1 c -12.4099 10.0016 -2.54558 n 1 -0 1.87319e-07 t1 0.970703 0.751953 t2 0 0\n" -"p2 c -12.4099 10.0016 2.54558 n 1 -0 1.87319e-07 t1 0.998047 0.751953 t2 0 0\n" -"p3 c -12.4099 4.00165 -2.54558 n 1 -0 1.87319e-07 t1 0.970703 0.998047 t2 0 0\n" -"mat dif 1 1 1 0 amb 0.5 0.5 0.5 0 spc 0 0 0 0\n" -"tex1 lemt.png\n" -"tex2\n" -"var_tex2 N\n" -"lod_level 0\n" -"state 1024\n" -"\n" -"p1 c -19 -1 4 n -1 0 0 t1 0.248047 0.123047 t2 0.905224 0.52067\n" -"p2 c -19 4 4 n -1 0 0 t1 0.248047 0.00195312 t2 0.905224 0.614223\n" -"p3 c -19 4 -4 n -1 0 0 t1 0.00195312 0.00195312 t2 0.0947756 0.614223\n" -"mat dif 1 1 1 0 amb 0.5 0.5 0.5 0 spc 0 0 0 0\n" -"tex1 derrick.png\n" -"tex2\n" -"var_tex2 Y\n" -"lod_level 1\n" -"state 0\n" -""; - -// Triangles as defined in model file -Gfx::ModelTriangle TRIANGLE_1; -Gfx::ModelTriangle TRIANGLE_2; - -// Sets triangle data -void Init() -{ - - TRIANGLE_1.p1 = Gfx::VertexTex2(Math::Vector(-12.4099, 10.0016, -2.54558), - Math::Vector(1, 0, 1.87319e-07), - Math::Point(0.970703, 0.751953), - Math::Point(0, 0)); - TRIANGLE_1.p2 = Gfx::VertexTex2(Math::Vector(-12.4099, 10.0016, 2.54558), - Math::Vector(1, 0, 1.87319e-07), - Math::Point(0.998047, 0.751953), - Math::Point(0, 0)); - TRIANGLE_1.p3 = Gfx::VertexTex2(Math::Vector(-12.4099, 4.00165, -2.54558), - Math::Vector(1, 0, 1.87319e-07), - Math::Point(0.970703, 0.998047), - Math::Point(0, 0)); - TRIANGLE_1.material.diffuse = Gfx::Color(1, 1, 1, 0); - TRIANGLE_1.material.ambient = Gfx::Color(0.5, 0.5, 0.5, 0); - TRIANGLE_1.material.specular = Gfx::Color(0, 0, 0, 0); - TRIANGLE_1.tex1Name = "lemt.png"; - TRIANGLE_1.variableTex2 = false; - TRIANGLE_1.lodLevel = Gfx::LOD_Constant; - TRIANGLE_1.state = 1024; - - TRIANGLE_2.p1 = Gfx::VertexTex2(Math::Vector(-19, -1, 4), - Math::Vector(-1, 0, 0), - Math::Point(0.248047, 0.123047), - Math::Point(0.905224, 0.52067)); - TRIANGLE_2.p2 = Gfx::VertexTex2(Math::Vector(-19, 4, 4), - Math::Vector(-1, 0, 0), - Math::Point(0.248047, 0.00195312), - Math::Point(0.905224, 0.614223)); - TRIANGLE_2.p3 = Gfx::VertexTex2(Math::Vector(-19, 4, -4), - Math::Vector(-1, 0, 0), - Math::Point(0.00195312, 0.00195312), - Math::Point(0.0947756, 0.614223)); - TRIANGLE_2.material.diffuse = Gfx::Color(1, 1, 1, 0); - TRIANGLE_2.material.ambient = Gfx::Color(0.5, 0.5, 0.5, 0); - TRIANGLE_2.material.specular = Gfx::Color(0, 0, 0, 0); - TRIANGLE_2.tex1Name = "derrick.png"; - TRIANGLE_2.variableTex2 = true; - TRIANGLE_2.lodLevel = Gfx::LOD_Low; - TRIANGLE_2.state = 0; -} - - -// Compares vertices (within Math::TOLERANCE) -bool CompareVertices(const Gfx::VertexTex2& v1, const Gfx::VertexTex2& v2) -{ - if ( !( Math::IsEqual(v1.coord.x, v2.coord.x) && - Math::IsEqual(v1.coord.y, v2.coord.y) && - Math::IsEqual(v1.coord.z, v2.coord.z) ) ) - return false; - - if ( !( Math::IsEqual(v1.normal.x, v2.normal.x) && - Math::IsEqual(v1.normal.y, v2.normal.y) && - Math::IsEqual(v1.normal.z, v2.normal.z) ) ) - return false; - - if ( !( Math::IsEqual(v1.texCoord.x, v2.texCoord.x) && - Math::IsEqual(v1.texCoord.y, v2.texCoord.y) ) ) - return false; - - if ( !( Math::IsEqual(v1.texCoord2.x, v2.texCoord2.x) && - Math::IsEqual(v1.texCoord2.y, v2.texCoord2.y) ) ) - return false; - - return true; -} - -// Compares colors (within Math::TOLERANCE) -bool CompareColors(const Gfx::Color& c1, const Gfx::Color& c2) -{ - return Math::IsEqual(c1.r, c2.r) && - Math::IsEqual(c1.g, c2.g) && - Math::IsEqual(c1.b, c2.b) && - Math::IsEqual(c1.a, c2.a); -} - -// Compares model triangles (within Math::TOLERANCE) -bool CompareTriangles(const Gfx::ModelTriangle& t1, const Gfx::ModelTriangle& t2) -{ - if (! CompareVertices(t1.p1, t2.p1)) - return false; - - if (! CompareVertices(t1.p2, t2.p2)) - return false; - - if (! CompareVertices(t1.p3, t2.p3)) - return false; - - if (! CompareColors(t1.material.diffuse, t2.material.diffuse)) - return false; - - if (! CompareColors(t1.material.ambient, t2.material.ambient)) - return false; - - if (! CompareColors(t1.material.specular, t2.material.specular)) - return false; - - if (t1.tex1Name != t2.tex1Name) - return false; - - if (t1.tex2Name != t2.tex2Name) - return false; - - if (t1.variableTex2 != t2.variableTex2) - return false; - - if (t1.lodLevel != t2.lodLevel) - return false; - - if (t1.state != t2.state) - return false; - - return true; -} - -// Tests reading/writing new text model file -TEST(ModelFileTest, RWTxtModel) -{ - std::stringstream str; - str.str(TEXT_MODEL); - - Gfx::CModelFile modelFile; - - EXPECT_TRUE(modelFile.ReadTextModel(str)); - - EXPECT_EQ(modelFile.GetTriangleCount(), 2); - EXPECT_TRUE(CompareTriangles(modelFile.GetTriangles()[0], TRIANGLE_1)); - EXPECT_TRUE(CompareTriangles(modelFile.GetTriangles()[1], TRIANGLE_2)); - - str.str(""); - - EXPECT_TRUE(modelFile.WriteTextModel(str)); - str.seekg(0); - EXPECT_TRUE(modelFile.ReadTextModel(str)); - - EXPECT_EQ(modelFile.GetTriangleCount(), 2); - EXPECT_TRUE(CompareTriangles(modelFile.GetTriangles()[0], TRIANGLE_1)); - EXPECT_TRUE(CompareTriangles(modelFile.GetTriangles()[1], TRIANGLE_2)); -} - -// Tests reading/writing new binary model -TEST(ModelFileTest, RWBinModel) -{ - std::stringstream str; - str.str(TEXT_MODEL); - - Gfx::CModelFile modelFile; - - EXPECT_TRUE(modelFile.ReadTextModel(str)); - - EXPECT_EQ(modelFile.GetTriangleCount(), 2); - EXPECT_TRUE(CompareTriangles(modelFile.GetTriangles()[0], TRIANGLE_1)); - EXPECT_TRUE(CompareTriangles(modelFile.GetTriangles()[1], TRIANGLE_2)); - - str.str(""); - - EXPECT_TRUE(modelFile.WriteBinaryModel(str)); - str.seekg(0); - EXPECT_TRUE(modelFile.ReadBinaryModel(str)); - - EXPECT_EQ(modelFile.GetTriangleCount(), 2); - EXPECT_TRUE(CompareTriangles(modelFile.GetTriangles()[0], TRIANGLE_1)); - EXPECT_TRUE(CompareTriangles(modelFile.GetTriangles()[1], TRIANGLE_2)); -} - -// Tests reading/writing old model file -TEST(ModelFileTest, RWOldModel) -{ - std::stringstream str; - str.str(TEXT_MODEL); - - Gfx::CModelFile modelFile; - - EXPECT_TRUE(modelFile.ReadTextModel(str)); - - EXPECT_EQ(modelFile.GetTriangleCount(), 2); - EXPECT_TRUE(CompareTriangles(modelFile.GetTriangles()[0], TRIANGLE_1)); - EXPECT_TRUE(CompareTriangles(modelFile.GetTriangles()[1], TRIANGLE_2)); - - str.str(""); - - EXPECT_TRUE(modelFile.WriteModel(str)); - str.seekg(0); - EXPECT_TRUE(modelFile.ReadModel(str)); - - EXPECT_EQ(modelFile.GetTriangleCount(), 2); - EXPECT_TRUE(CompareTriangles(modelFile.GetTriangles()[0], TRIANGLE_1)); - EXPECT_TRUE(CompareTriangles(modelFile.GetTriangles()[1], TRIANGLE_2)); -} - -int main(int argc, char **argv) -{ - CLogger logger; - - Init(); - - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} - -- cgit v1.2.3-1-g7c22