diff options
Diffstat (limited to 'src/graphics')
-rw-r--r-- | src/graphics/core/device.h | 3 | ||||
-rw-r--r-- | src/graphics/core/vertex.h | 4 | ||||
-rw-r--r-- | src/graphics/engine/camera.cpp | 3 | ||||
-rw-r--r-- | src/graphics/engine/engine.cpp | 60 | ||||
-rw-r--r-- | src/graphics/engine/engine.h | 10 | ||||
-rw-r--r-- | src/graphics/engine/modelmanager.cpp | 20 | ||||
-rw-r--r-- | src/graphics/engine/modelmanager.h | 17 | ||||
-rw-r--r-- | src/graphics/engine/terrain.cpp | 65 | ||||
-rw-r--r-- | src/graphics/engine/terrain.h | 4 | ||||
-rw-r--r-- | src/graphics/engine/text.cpp | 15 | ||||
-rw-r--r-- | src/graphics/opengl/gldevice.cpp | 13 | ||||
-rw-r--r-- | src/graphics/opengl/gldevice.h | 2 |
12 files changed, 161 insertions, 55 deletions
diff --git a/src/graphics/core/device.h b/src/graphics/core/device.h index 4c1189c..a896104 100644 --- a/src/graphics/core/device.h +++ b/src/graphics/core/device.h @@ -400,6 +400,9 @@ public: virtual void SetFillMode(FillMode mode) = 0; //! Returns the current fill mode virtual FillMode GetFillMode() = 0; + + //! Returns the pixels of the entire screen + virtual void* GetFrameBufferPixels()const = 0; }; diff --git a/src/graphics/core/vertex.h b/src/graphics/core/vertex.h index c3a657a..ca68352 100644 --- a/src/graphics/core/vertex.h +++ b/src/graphics/core/vertex.h @@ -82,7 +82,9 @@ struct VertexCol Math::Vector coord; Color color; - explicit VertexCol(Math::Vector aCoord = Math::Vector(), + VertexCol() = default; + + explicit VertexCol(Math::Vector aCoord, Color aColor = Color()) : coord(aCoord), color(aColor) {} diff --git a/src/graphics/engine/camera.cpp b/src/graphics/engine/camera.cpp index f0c379c..fedc70a 100644 --- a/src/graphics/engine/camera.cpp +++ b/src/graphics/engine/camera.cpp @@ -593,9 +593,6 @@ void CCamera::EffectFrame(const Event &event) dist = Math::Norm((dist - 100.f) / 100.0f); force *= 1.0f-dist; -#if _TEEN - force *= 2.0f; -#endif m_effectOffset *= force; if (m_effectProgress >= 1.0f) diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 5cf7b23..e0861d2 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -19,6 +19,7 @@ #include "graphics/engine/engine.h" #include "app/app.h" +#include "app/gamedata.h" #include "common/image.h" #include "common/key.h" @@ -63,6 +64,7 @@ CEngine::CEngine(CApplication *app) m_planet = nullptr; m_sound = nullptr; m_terrain = nullptr; + m_pause = nullptr; m_showStats = false; @@ -80,7 +82,6 @@ CEngine::CEngine(CApplication *app) m_fogStart[1] = 0.75f; m_waterAddColor = Color(0.0f, 0.0f, 0.0f, 0.0f); - m_pause = false; m_render = true; m_movieLock = false; m_shadowVisible = true; @@ -179,6 +180,7 @@ CEngine::~CEngine() m_lightning = nullptr; m_planet = nullptr; m_terrain = nullptr; + m_pause = nullptr; GetSystemUtils()->DestroyTimeStamp(m_lastFrameTime); m_lastFrameTime = nullptr; @@ -252,6 +254,7 @@ bool CEngine::Create() m_cloud = new CCloud(this); m_lightning = new CLightning(this); m_planet = new CPlanet(this); + m_pause = new CPauseManager(); m_lightMan->SetDevice(m_device); m_particle->SetDevice(m_device); @@ -421,19 +424,25 @@ void CEngine::FrameUpdate() bool CEngine::WriteScreenShot(const std::string& fileName, int width, int height) { - // TODO write screenshot: not very important for now - GetLogger()->Trace("CEngine::WriteSceenShot(): stub!\n"); - return true; -} + void *pixels = m_device->GetFrameBufferPixels(); + CImage img({width,height}); -void CEngine::SetPause(bool pause) -{ - m_pause = pause; + img.SetDataPixels(pixels); + img.flipVertically(); + + if ( img.SavePNG(fileName.c_str()) ){ + GetLogger()->Info("Save SceenShot Saved Successfully!\n"); + return true; + } + else{ + GetLogger()->Error("%s!\n",img.GetError().c_str()); + return false; + } } bool CEngine::GetPause() { - return m_pause; + return m_pause->GetPause(); } void CEngine::SetMovieLock(bool lock) @@ -2249,33 +2258,12 @@ Texture CEngine::CreateTexture(const std::string& texName, const TextureCreatePa if (image == nullptr) { - bool loadedFromTexPack = false; - - std::string texPackName = m_app->GetTexPackFilePath(texName); - if (! texPackName.empty()) - { - 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); - } - } - - if (!loadedFromTexPack) + if (! img.Load(CGameData::GetInstancePointer()->GetFilePath(DIR_TEXTURE, texName))) { - 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 - } + 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; @@ -2438,7 +2426,7 @@ bool CEngine::ChangeTextureColor(const std::string& texName, CImage img; - if (! img.Load(m_app->GetDataFilePath(DIR_TEXTURE, texName))) + if (! img.Load(CGameData::GetInstancePointer()->GetFilePath(DIR_TEXTURE, texName))) { std::string error = img.GetError(); GetLogger()->Error("Couldn't load texture '%s': %s, blacklisting\n", texName.c_str(), error.c_str()); diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index 5ecde8f..d56bf38 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -24,6 +24,7 @@ #include "app/system.h" +#include "app/pausemanager.h" #include "common/event.h" #include "common/singleton.h" @@ -734,11 +735,8 @@ public: bool WriteScreenShot(const std::string& fileName, int width, int height); - //@{ - //! Management of game pause mode - void SetPause(bool pause); + //! Get pause mode TEST_VIRTUAL bool GetPause(); - //@} //@{ //! Management of lock for the duration of movie sequence @@ -1288,6 +1286,7 @@ protected: CLightning* m_lightning; CPlanet* m_planet; CTerrain* m_terrain; + CPauseManager* m_pause; //! Last encountered error std::string m_error; @@ -1300,9 +1299,6 @@ protected: //! Whether to show stats (FPS, etc) bool m_showStats; std::string m_fpsText; - - //! Pause mode - bool m_pause; //! Rendering enabled? bool m_render; //! Lock for duration of movie? diff --git a/src/graphics/engine/modelmanager.cpp b/src/graphics/engine/modelmanager.cpp index abc8c6c..0c0fb98 100644 --- a/src/graphics/engine/modelmanager.cpp +++ b/src/graphics/engine/modelmanager.cpp @@ -1,6 +1,24 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch +// * Copyright (C) 2012-2014, 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 "graphics/engine/modelmanager.h" #include "app/app.h" +#include "app/gamedata.h" #include "common/logger.h" @@ -30,7 +48,7 @@ bool CModelManager::LoadModel(const std::string& fileName, bool mirrored) if (CApplication::GetInstance().IsDebugModeActive(DEBUG_MODELS)) modelFile.SetPrintDebugInfo(true); - std::string filePath = CApplication::GetInstance().GetDataFilePath(DIR_MODEL, fileName); + std::string filePath = CGameData::GetInstancePointer()->GetFilePath(DIR_MODEL, fileName); if (!modelFile.ReadModel(filePath)) { diff --git a/src/graphics/engine/modelmanager.h b/src/graphics/engine/modelmanager.h index 9d50b97..ee5fc27 100644 --- a/src/graphics/engine/modelmanager.h +++ b/src/graphics/engine/modelmanager.h @@ -1,3 +1,20 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch +// * Copyright (C) 2012-2014, 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/. + #pragma once #include "common/singleton.h" diff --git a/src/graphics/engine/terrain.cpp b/src/graphics/engine/terrain.cpp index 4b5384e..5f37cd8 100644 --- a/src/graphics/engine/terrain.cpp +++ b/src/graphics/engine/terrain.cpp @@ -19,6 +19,7 @@ #include "graphics/engine/terrain.h" #include "app/app.h" +#include "app/gamedata.h" #include "common/image.h" #include "common/logger.h" @@ -189,7 +190,7 @@ void CTerrain::AddMaterial(int id, const std::string& texName, const Math::Point bool CTerrain::LoadResources(const std::string& fileName) { CImage img; - std::string path = CApplication::GetInstance().GetDataFilePath(DIR_TEXTURE, fileName); + std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_TEXTURE, fileName); if (! img.Load(path)) { GetLogger()->Error("Cannot load resource file: '%s'\n", path.c_str()); @@ -286,7 +287,7 @@ bool CTerrain::LoadRelief(const std::string &fileName, float scaleRelief, m_scaleRelief = scaleRelief; CImage img; - std::string path = CApplication::GetInstance().GetDataFilePath(DIR_TEXTURE, fileName); + std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_TEXTURE, fileName); if (! img.Load(path)) { GetLogger()->Error("Could not load relief file: '%s'!\n", path.c_str()); @@ -331,6 +332,66 @@ bool CTerrain::LoadRelief(const std::string &fileName, float scaleRelief, return true; } +bool CTerrain::RandomizeRelief() +{ + // Perlin noise + // Based on Python implementation by Marek Rogalski (mafik) + // http://amt2014.pl/archiwum/perlin.py + + int size = (m_mosaicCount*m_brickCount)+1; + const int ilosc_oktaw = 6; + + float* oktawy[ilosc_oktaw]; + for(int i=0; i<ilosc_oktaw; i++) + { + int pxCount = static_cast<int>(pow(2, (i+1)*2)); + oktawy[i] = new float[pxCount]; + for(int j=0; j<pxCount; j++) + { + oktawy[i][j] = Math::Rand(); + } + } + + for(int y2=0; y2 < size; y2++) + { + float y = static_cast<float>(y2) / size; + for(int x2=0; x2 < size; x2++) + { + float x = static_cast<float>(x2) / size; + + float wart = 0; + for(int i=0; i<ilosc_oktaw; i++) + { + int rozmiar_oktawy = sqrt(static_cast<int>(pow(2, (i+1)*2))); + double xi, yi, a, b; + a = modf(x * (rozmiar_oktawy-1), &xi); + b = modf(y * (rozmiar_oktawy-1), &yi); + /*int xi = floor(x * (rozmiar_oktawy-1)); + int yi = floor(y * (rozmiar_oktawy-1)); + float a = (x * (rozmiar_oktawy-1)) - xi; + float b = (y * (rozmiar_oktawy-1)) - yi;*/ + //CLogger::GetInstancePointer()->Error("%f %f %f %f\n", xi, yi, a, b); + + float lg = oktawy[i][static_cast<int>(yi * rozmiar_oktawy + xi)]; + float pg = oktawy[i][static_cast<int>(yi * rozmiar_oktawy + xi + 1)]; + float ld = oktawy[i][static_cast<int>((yi+1) * rozmiar_oktawy + xi)]; + float pd = oktawy[i][static_cast<int>((yi+1) * rozmiar_oktawy + xi + 1)]; + //CLogger::GetInstancePointer()->Error("%f %f %f %f\n", lg, pg, ld, pd); + + float g = pg * a + lg * (1-a); + float d = pd * a + ld * (1-a); + float res = d * b + g * (1-b); + wart += res; + } + + wart /= ilosc_oktaw; + + m_relief[x2+y2*size] = wart * 255.0f; + } + } + return true; +} + bool CTerrain::AddReliefPoint(Math::Vector pos, float scaleRelief) { float dim = (m_mosaicCount*m_brickCount*m_brickSize)/2.0f; diff --git a/src/graphics/engine/terrain.h b/src/graphics/engine/terrain.h index e618691..75a8975 100644 --- a/src/graphics/engine/terrain.h +++ b/src/graphics/engine/terrain.h @@ -212,7 +212,7 @@ struct FlyingLimit * where relief data is specifically adjusted to level space to allow * construction of buildings. * - * Undergound resources can be supplied by loading them from image like relief data. + * Underground resources can be supplied by loading them from image like relief data. * * Terrain also specifies flying limits for player: one global level and possible * additional spherical restrictions. @@ -243,6 +243,8 @@ public: void FlushRelief(); //! Load relief from image bool LoadRelief(const std::string& fileName, float scaleRelief, bool adjustBorder); + //! Load ramdomized relief + bool RandomizeRelief(); //! Load resources from image bool LoadResources(const std::string& fileName); diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index ffd2eb2..8fd01b7 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -19,6 +19,7 @@ #include "graphics/engine/text.h" #include "app/app.h" +#include "app/gamedata.h" #include "common/image.h" #include "common/logger.h" @@ -333,7 +334,7 @@ float CText::GetStringWidth(std::string text, FontType font, float size) // Skip special chars for (char& c : text) { - if (c < 32) + if (c < 32 && c >= 0) c = ':'; } @@ -351,7 +352,7 @@ float CText::GetCharWidth(UTF8Char ch, FontType font, float size, float offset) if (font == FONT_BUTTON) return 0.0f; int width = 1; - if (ch.c1 < 32) + if (ch.c1 < 32 && ch.c1 >= 0) { if (ch.c1 == '\t') width = m_tabSize; @@ -646,7 +647,13 @@ void CText::DrawString(const std::string &text, std::vector<FontMetaChar>::itera DrawCharAndAdjustPos(ch, font, size, pos, color); - fmtIndex++; + // increment fmtIndex for each byte in multibyte character + if ( ch.c1 != 0 ) + fmtIndex++; + if ( ch.c2 != 0 ) + fmtIndex++; + if ( ch.c3 != 0 ) + fmtIndex++; } if (eol != 0) @@ -859,7 +866,7 @@ CachedFont* CText::GetOrOpenFont(FontType font, float size) return m_lastCachedFont; } - std::string path = CApplication::GetInstance().GetDataFilePath(DIR_FONT, mf->fileName); + std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_FONT, mf->fileName); m_lastCachedFont = new CachedFont(); m_lastCachedFont->font = TTF_OpenFont(path.c_str(), pointSize); diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index 9f64fab..b42f29d 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -1791,6 +1791,19 @@ FillMode CGLDevice::GetFillMode() return FILL_POINT; } +void* CGLDevice::GetFrameBufferPixels()const{ + + GLubyte* pixels = new GLubyte [4 * m_config.size.x * m_config.size.y]; + + glReadPixels(0, 0, m_config.size.x, m_config.size.y, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + + unsigned int* p = static_cast<unsigned int*> ( static_cast<void*>(pixels) ); + + for (int i = 0; i < m_config.size.x * m_config.size.y; ++i) + p[i] |= 0xFF000000; + + return static_cast<void*>(p); +} } // namespace Gfx diff --git a/src/graphics/opengl/gldevice.h b/src/graphics/opengl/gldevice.h index c648161..267ee73 100644 --- a/src/graphics/opengl/gldevice.h +++ b/src/graphics/opengl/gldevice.h @@ -188,6 +188,8 @@ public: virtual void SetFillMode(FillMode mode) ; virtual FillMode GetFillMode(); + virtual void* GetFrameBufferPixels()const; + private: //! Updates internal modelview matrix void UpdateModelviewMatrix(); |