diff options
-rw-r--r-- | src/common/image.cpp | 7 | ||||
-rw-r--r-- | src/common/image.h | 2 | ||||
-rw-r--r-- | src/graphics/core/device.h | 5 | ||||
-rw-r--r-- | src/graphics/core/texture.h | 4 | ||||
-rw-r--r-- | src/graphics/engine/engine.cpp | 206 | ||||
-rw-r--r-- | src/graphics/engine/engine.h | 26 | ||||
-rw-r--r-- | src/graphics/opengl/gldevice.cpp | 23 | ||||
-rw-r--r-- | src/graphics/opengl/gldevice.h | 3 | ||||
-rw-r--r-- | src/object/object.cpp | 12 | ||||
-rw-r--r-- | src/object/robotmain.cpp | 65 | ||||
-rw-r--r-- | src/object/robotmain.h | 2 | ||||
-rw-r--r-- | src/ui/map.cpp | 66 |
12 files changed, 285 insertions, 136 deletions
diff --git a/src/common/image.cpp b/src/common/image.cpp index 6a2ab0e..f78ea94 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -147,6 +147,13 @@ CImage::CImage() m_data = nullptr; } +CImage::CImage(Math::IntPoint size) +{ + m_data = new ImageData(); + m_data->surface = SDL_CreateRGBSurface(0, size.x, size.y, 32, + 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000); +} + CImage::~CImage() { Free(); diff --git a/src/common/image.h b/src/common/image.h index 3391bdb..54bbd3d 100644 --- a/src/common/image.h +++ b/src/common/image.h @@ -60,6 +60,8 @@ private: public: //! Constructs empty image (with NULL data) CImage(); + //! Constructs a RGBA image of given size + CImage(Math::IntPoint size); //! Destroys image, calling Free() virtual ~CImage(); diff --git a/src/graphics/core/device.h b/src/graphics/core/device.h index 0d76644..0777396 100644 --- a/src/graphics/core/device.h +++ b/src/graphics/core/device.h @@ -307,11 +307,6 @@ public: //! Sets only the texture wrap modes (for faster than thru stage params) virtual void SetTextureStageWrap(int index, TexWrapMode wrapS, TexWrapMode wrapT) = 0; - //! Sets the texture factor to the given color value - virtual void SetTextureFactor(const Color &color) = 0; - //! Returns the current texture factor - virtual Color GetTextureFactor() = 0; - //! Renders primitive composed of vertices with single texture virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices , int vertexCount) = 0; //! Renders primitive composed of vertices with color information and single texture diff --git a/src/graphics/core/texture.h b/src/graphics/core/texture.h index 3ebbee5..49b29f8 100644 --- a/src/graphics/core/texture.h +++ b/src/graphics/core/texture.h @@ -22,6 +22,8 @@ #pragma once +#include "graphics/core/color.h" + #include "math/intpoint.h" @@ -175,6 +177,8 @@ struct TextureStageParams TexWrapMode wrapS; //! Wrap mode for 2nd tex coord TexWrapMode wrapT; + //! Constant color factor (for TEX_MIX_ARG_FACTOR) + Color factor; //! Constructor; calls LoadDefault() TextureStageParams() diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index c094c63..7e00134 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -181,9 +181,6 @@ CEngine::CEngine(CInstanceManager *iMan, CApplication *app) m_alphaMode = 1; - m_forceStateColor = true; - m_stateColor = false; - m_updateGeometry = false; m_interfaceMode = false; @@ -1851,13 +1848,12 @@ void CEngine::SetState(int state, const Color& color) m_device->SetRenderState(RENDER_STATE_BLENDING, true); m_device->SetBlendFunc(BLEND_ONE, BLEND_INV_SRC_COLOR); - m_device->SetTextureFactor(color); - TextureStageParams params; params.colorOperation = TEX_MIX_OPER_MODULATE; params.colorArg1 = TEX_MIX_ARG_TEXTURE; params.colorArg2 = TEX_MIX_ARG_FACTOR; params.alphaOperation = TEX_MIX_OPER_DEFAULT; // TODO: replace with src color ? + params.factor = color; m_device->SetTextureEnabled(0, true); m_device->SetTextureStageParams(0, params); @@ -1871,13 +1867,12 @@ void CEngine::SetState(int state, const Color& color) m_device->SetRenderState(RENDER_STATE_BLENDING, true); m_device->SetBlendFunc(BLEND_DST_COLOR, BLEND_ZERO); - m_device->SetTextureFactor(color.Inverse()); - TextureStageParams params; params.colorOperation = TEX_MIX_OPER_ADD; params.colorArg1 = TEX_MIX_ARG_TEXTURE; params.colorArg2 = TEX_MIX_ARG_FACTOR; params.alphaOperation = TEX_MIX_OPER_DEFAULT; // TODO: replace with src color ? + params.factor = color.Inverse(); m_device->SetTextureEnabled(0, true); m_device->SetTextureStageParams(0, params); @@ -1963,14 +1958,13 @@ void CEngine::SetState(int state, const Color& color) m_device->SetAlphaTestFunc(COMP_FUNC_GREATER, 0.5f); - m_device->SetTextureFactor(color); - TextureStageParams params; params.colorOperation = TEX_MIX_OPER_MODULATE; params.colorArg1 = TEX_MIX_ARG_TEXTURE; params.colorArg2 = TEX_MIX_ARG_SRC_COLOR; params.alphaOperation = TEX_MIX_OPER_REPLACE; params.alphaArg1 = TEX_MIX_ARG_TEXTURE; + params.factor = color; m_device->SetTextureEnabled(0, true); m_device->SetTextureStageParams(0, params); @@ -2080,7 +2074,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) +Texture CEngine::CreateTexture(const std::string& texName, const TextureCreateParams& params, CImage* image) { if (texName.empty()) return Texture(); // invalid texture @@ -2088,18 +2082,25 @@ Texture CEngine::CreateTexture(const std::string& texName, const TextureCreatePa if (m_texBlacklist.find(texName) != m_texBlacklist.end()) return Texture(); // invalid texture - // TODO: detect alpha channel? + Texture tex; - CImage img; - if (! img.Load(m_app->GetDataFilePath(DIR_TEXTURE, texName))) + if (image == nullptr) { - 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 - } + CImage img; + 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 + } - Texture tex = m_device->CreateTexture(&img, params); + tex = m_device->CreateTexture(&img, params); + } + else + { + tex = m_device->CreateTexture(image, params); + } if (! tex.Valid()) { @@ -2119,6 +2120,12 @@ Texture CEngine::LoadTexture(const std::string& name) return LoadTexture(name, m_defaultTexParams); } +Texture CEngine::LoadTexture(const std::string& name, CImage* image) +{ + Texture tex = CreateTexture(name, m_defaultTexParams, image); + return tex; +} + Texture CEngine::LoadTexture(const std::string& name, const TextureCreateParams& params) { if (m_texBlacklist.find(name) != m_texBlacklist.end()) @@ -2200,6 +2207,146 @@ bool CEngine::LoadAllTextures() return ok; } +bool IsExcludeColor(Math::Point *exclude, int x, int y) +{ + int i = 0; + while ( exclude[i+0].x != 0.0f || exclude[i+0].y != 0.0f || + exclude[i+1].y != 0.0f || exclude[i+1].y != 0.0f ) + { + if ( x >= static_cast<int>(exclude[i+0].x*256.0f) && + x < static_cast<int>(exclude[i+1].x*256.0f) && + y >= static_cast<int>(exclude[i+0].y*256.0f) && + y < static_cast<int>(exclude[i+1].y*256.0f) ) return true; // exclude + + i += 2; + } + + return false; // point to include +} + + +bool CEngine::ChangeTextureColor(const std::string& texName, + Color colorRef1, Color colorNew1, + Color colorRef2, Color colorNew2, + float tolerance1, float tolerance2, + Math::Point ts, Math::Point ti, + Math::Point *exclude, float shift, bool hsv) +{ + if ( colorRef1.r == colorNew1.r && + colorRef1.g == colorNew1.g && + colorRef1.b == colorNew1.b && + colorRef2.r == colorNew2.r && + colorRef2.g == colorNew2.g && + colorRef2.b == colorNew2.b ) return true; + + + DeleteTexture(texName); + + + CImage img; + 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 false; + } + + + int dx = img.GetSize().x; + int dy = img.GetSize().x; + + int sx = static_cast<int>(ts.x*dx); + int sy = static_cast<int>(ts.y*dy); + + int ex = static_cast<int>(ti.x*dx); + int ey = static_cast<int>(ti.y*dy); + + ColorHSV cr1 = RGB2HSV(colorRef1); + ColorHSV cn1 = RGB2HSV(colorNew1); + ColorHSV cr2 = RGB2HSV(colorRef2); + ColorHSV cn2 = RGB2HSV(colorNew2); + + for (int y = sy; y < ey; y++) + { + for (int x = sx; x < ex; x++) + { + if (exclude != nullptr && IsExcludeColor(exclude, x,y) ) continue; + + Color color = img.GetPixel(Math::IntPoint(x, y)); + + if (hsv) + { + ColorHSV c = RGB2HSV(color); + if (c.s > 0.01f && fabs(c.h - cr1.h) < tolerance1) + { + c.h += cn1.h - cr1.h; + c.s += cn1.s - cr1.s; + c.v += cn1.v - cr1.v; + if (c.h < 0.0f) c.h -= 1.0f; + if (c.h > 1.0f) c.h += 1.0f; + color = HSV2RGB(c); + color.r += shift; + color.g += shift; + color.b += shift; + img.SetPixel(Math::IntPoint(x, y), color); + } + else if (tolerance2 != -1.0f && + c.s > 0.01f && fabs(c.h - cr2.h) < tolerance2) + { + c.h += cn2.h - cr2.h; + c.s += cn2.s - cr2.s; + c.v += cn2.v - cr2.v; + if (c.h < 0.0f) c.h -= 1.0f; + if (c.h > 1.0f) c.h += 1.0f; + color = HSV2RGB(c); + color.r += shift; + color.g += shift; + color.b += shift; + img.SetPixel(Math::IntPoint(x, y), color); + } + } + else + { + if ( fabs(color.r - colorRef1.r) + + fabs(color.g - colorRef1.g) + + fabs(color.b - colorRef1.b) < tolerance1 * 3.0f) + { + color.r = colorNew1.r + color.r - colorRef1.r + shift; + color.g = colorNew1.g + color.g - colorRef1.g + shift; + color.b = colorNew1.b + color.b - colorRef1.b + shift; + img.SetPixel(Math::IntPoint(x, y), color); + } + else if (tolerance2 != -1 && + fabs(color.r - colorRef2.r) + + fabs(color.g - colorRef2.g) + + fabs(color.b - colorRef2.b) < tolerance2 * 3.0f) + { + color.r = colorNew2.r + color.r - colorRef2.r + shift; + color.g = colorNew2.g + color.g - colorRef2.g + shift; + color.b = colorNew2.b + color.b - colorRef2.b + shift; + img.SetPixel(Math::IntPoint(x, y), color); + } + } + } + } + + + Texture tex = m_device->CreateTexture(&img, m_defaultTexParams); + + if (! tex.Valid()) + { + GetLogger()->Error("Couldn't load texture '%s', blacklisting\n", texName.c_str()); + m_texBlacklist.insert(texName); + return false; + } + + m_texNameMap[texName] = tex; + m_revTexNameMap[tex] = texName; + + return true; +} + void CEngine::DeleteTexture(const std::string& texName) { auto it = m_texNameMap.find(texName); @@ -2348,11 +2495,6 @@ bool CEngine::GetFog() return m_fog; } -bool CEngine::GetStateColor() -{ - return m_stateColor; -} - void CEngine::SetSecondTexture(int texNum) { m_secondTexNum = texNum; @@ -2964,18 +3106,8 @@ void CEngine::Draw3DScene() if (transparent) { - int tState = 0; - Color tColor; - if (m_stateColor) - { - tState = ENG_RSTATE_TTEXTURE_BLACK | ENG_RSTATE_2FACE; - tColor = Color(68.0f / 255.0f, 68.0f / 255.0f, 68.0f / 255.0f, 68.0f / 255.0f); - } - else - { - tState = ENG_RSTATE_TCOLOR_BLACK; - tColor = Color(136.0f / 255.0f, 136.0f / 255.0f, 136.0f / 255.0f, 136.0f / 255.0f); - } + int tState = ENG_RSTATE_TTEXTURE_BLACK | ENG_RSTATE_2FACE; + Color tColor = Color(68.0f / 255.0f, 68.0f / 255.0f, 68.0f / 255.0f, 68.0f / 255.0f); for (int l1 = 0; l1 < static_cast<int>( m_objectTree.size() ); l1++) { @@ -3551,8 +3683,6 @@ void CEngine::DrawForegroundImage() // Status: PART_TESTED void CEngine::DrawOverColor() { - if (! m_stateColor) return; - // TODO: fuzzy compare? if ( (m_overColor == Color(0.0f, 0.0f, 0.0f, 0.0f) && m_overMode == ENG_RSTATE_TCOLOR_BLACK) || (m_overColor == Color(1.0f, 1.0f, 1.0f, 1.0f) && m_overMode == ENG_RSTATE_TCOLOR_WHITE) ) return; diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index 6363fd3..14a40db 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -48,6 +48,7 @@ class CApplication; class CInstanceManager; class CObject; class CSoundInterface; +class CImage; // Graphics module namespace @@ -890,12 +891,23 @@ public: const Math::Vector& upVec, float eyeDistance); //! Loads texture, creating it if not already present - Texture LoadTexture(const std::string& name); + Texture LoadTexture(const std::string& name); + //! Loads texture from existing image + Texture LoadTexture(const std::string& name, CImage* image); //! Loads texture, creating it with given params if not already present - Texture LoadTexture(const std::string& name, const TextureCreateParams& params); + Texture LoadTexture(const std::string& name, const TextureCreateParams& params); //! Loads all necessary textures bool LoadAllTextures(); + //! Changes colors in a texture + bool ChangeTextureColor(const std::string& texName, + Color colorRef1, Color colorNew1, + Color colorRef2, Color colorNew2, + float tolerance1, float tolerance2, + Math::Point ts, Math::Point ti, + Math::Point *exclude = nullptr, + float shift = 0.0f, bool hsv = false); + //! Sets texture for given stage; if not present in cache, the texture is loaded /** If loading fails, returns false. */ bool SetTexture(const std::string& name, int stage = 0); @@ -973,19 +985,19 @@ public: //@{ //! Ambient color management void SetAmbientColor(const Color& color, int rank = 0); - Color GetAmbientColor(int rank = 0); + Color GetAmbientColor(int rank = 0); //@} //@{ //! Color management under water void SetWaterAddColor(const Color& color); - Color GetWaterAddColor(); + Color GetWaterAddColor(); //@} //@{ //! Management of the fog color void SetFogColor(const Color& color, int rank = 0); - Color GetFogColor(int rank = 0); + Color GetFogColor(int rank = 0); //@} //@{ @@ -1188,7 +1200,7 @@ protected: const Material& mat, int state); //! Create texture and add it to cache - Texture CreateTexture(const std::string &texName, const TextureCreateParams ¶ms); + Texture CreateTexture(const std::string &texName, const TextureCreateParams ¶ms, CImage* image = nullptr); //! Tests whether the given object is visible bool IsVisible(int objRank); @@ -1291,8 +1303,6 @@ protected: int m_statisticTriangle; bool m_updateGeometry; int m_alphaMode; - bool m_stateColor; - bool m_forceStateColor; bool m_groundSpotVisible; bool m_shadowVisible; bool m_dirty; diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index 56a7130..78a77bd 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -684,6 +684,8 @@ void CGLDevice::SetTextureStageParams(int index, const TextureStageParams ¶m glActiveTexture(GL_TEXTURE0 + index); + glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, params.factor.Array()); + // To save some trouble if ( (params.colorOperation == TEX_MIX_OPER_DEFAULT) && (params.alphaOperation == TEX_MIX_OPER_DEFAULT) ) @@ -836,27 +838,6 @@ TextureStageParams CGLDevice::GetTextureStageParams(int index) return m_textureStageParams[index]; } -void CGLDevice::SetTextureFactor(const Color &color) -{ - // Needs to be set for all texture stages - for (int index = 0; index < static_cast<int>( m_currentTextures.size() ); ++index) - { - glActiveTexture(GL_TEXTURE0 + index); - glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color.Array()); - } -} - -Color CGLDevice::GetTextureFactor() -{ - // Get from 1st stage (should be the same for all stages) - glActiveTexture(GL_TEXTURE0); - - GLfloat color[4] = { 0.0f }; - glGetTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color); - - return Color(color[0], color[1], color[2], color[3]); -} - GLenum TranslateGfxPrimitive(PrimitiveType type) { GLenum flag = 0; diff --git a/src/graphics/opengl/gldevice.h b/src/graphics/opengl/gldevice.h index 78c7433..8af864e 100644 --- a/src/graphics/opengl/gldevice.h +++ b/src/graphics/opengl/gldevice.h @@ -119,9 +119,6 @@ public: virtual void SetTextureStageWrap(int index, Gfx::TexWrapMode wrapS, Gfx::TexWrapMode wrapT); - virtual void SetTextureFactor(const Color &color); - virtual Color GetTextureFactor(); - virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices, int vertexCount); virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices, int vertexCount); virtual void DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, int vertexCount); diff --git a/src/object/object.cpp b/src/object/object.cpp index 0b1a39c..ec8b3c5 100644 --- a/src/object/object.cpp +++ b/src/object/object.cpp @@ -7524,7 +7524,7 @@ bool CObject::GetTraceDown() CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion); if (mv == nullptr) { - GetLogger()->Warn("GetTraceDown() invalid m_motion class!\n"); + GetLogger()->Debug("GetTraceDown() invalid m_motion class!\n"); return false; } return mv->GetTraceDown(); @@ -7536,7 +7536,7 @@ void CObject::SetTraceDown(bool bDown) CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion); if (mv == nullptr) { - GetLogger()->Warn("SetTraceDown() invalid m_motion class!\n"); + GetLogger()->Debug("SetTraceDown() invalid m_motion class!\n"); return; } mv->SetTraceDown(bDown); @@ -7548,7 +7548,7 @@ int CObject::GetTraceColor() CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion); if (mv == nullptr) { - GetLogger()->Warn("GetTraceColor() invalid m_motion class!\n"); + GetLogger()->Debug("GetTraceColor() invalid m_motion class!\n"); return 0; } return mv->GetTraceColor(); @@ -7560,7 +7560,7 @@ void CObject::SetTraceColor(int color) CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion); if (mv == nullptr) { - GetLogger()->Warn("SetTraceColor() invalid m_motion class!\n"); + GetLogger()->Debug("SetTraceColor() invalid m_motion class!\n"); return; } mv->SetTraceColor(color); @@ -7572,7 +7572,7 @@ float CObject::GetTraceWidth() CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion); if (mv == nullptr) { - GetLogger()->Warn("GetTraceWidth() invalid m_motion class!\n"); + GetLogger()->Debug("GetTraceWidth() invalid m_motion class!\n"); return 0.0f; } return mv->GetTraceWidth(); @@ -7584,7 +7584,7 @@ void CObject::SetTraceWidth(float width) CMotionVehicle* mv = dynamic_cast<CMotionVehicle*>(m_motion); if (mv == nullptr) { - GetLogger()->Warn("SetTraceWidth() invalid m_motion class!\n"); + GetLogger()->Debug("SetTraceWidth() invalid m_motion class!\n"); return; } mv->SetTraceWidth(width); diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 327e73f..226bd57 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -26,6 +26,7 @@ #include "common/event.h" #include "common/global.h" #include "common/iman.h" +#include "common/logger.h" #include "common/misc.h" #include "common/profile.h" #include "common/restext.h" @@ -795,6 +796,8 @@ CRobotMain::CRobotMain(CInstanceManager* iMan, CApplication* app) CBotProgram::DefineNum("FilterOnlyLanding", FILTER_ONLYLANDING); CBotProgram::DefineNum("FilterOnlyFliying", FILTER_ONLYFLYING); + CBotProgram::DefineNum("PolskiPortalColobota", 1337); + CBotClass* bc; // Add the class Point. @@ -1799,6 +1802,20 @@ void CRobotMain::ExecuteCmd(char *cmd) object->SetRange(object->GetRange()*10.0f); return; } + + if (strcmp(cmd, "\155\157\157") == 0) + { + // VGhpcyBpcyBlYXN0ZXItZWdnIGFuZCBzbyBpdCBzaG91bGQgYmUgb2JmdXNjYXRlZCEgRG8gbm90 + // IGNsZWFuLXVwIHRoaXMgY29kZSEK + GetLogger()->Info(" _________________________\n"); + GetLogger()->Info("< \x50\x6F\x6C\x73\x6B\x69 \x50\x6F\x72\x74\x61\x6C C\x6F\x6C\x6F\x62\x6F\x74\x61! \x3E\n"); + GetLogger()->Info(" -------------------------\n"); + GetLogger()->Info(" \x5C\x20\x20\x20\x5E\x5F\x5F\x5E\n"); + GetLogger()->Info(" \x20\x5C\x20\x20\x28\x6F\x6F\x29\x5C\x5F\x5F\x5F\x5F\x5F\x5F\x5F\n"); + GetLogger()->Info(" \x28\x5F\x5F\x29\x5C \x20\x20\x20\x20\x29\x5C\x2F\x5C\n"); + GetLogger()->Info(" \x20\x20\x20\x20\x7C|\x2D\x2D\x2D\x2D\x77\x20\x7C\n"); + GetLogger()->Info(" \x20\x20 \x7C\x7C\x20\x20\x20\x20 ||\n"); + } if (strcmp(cmd, "fullpower") == 0) { @@ -4905,7 +4922,7 @@ void CRobotMain::ChangeColor() exclu[3] = Math::Point(256.0f/256.0f, 256.0f/256.0f); // SatCom screen exclu[4] = Math::Point(0.0f, 0.0f); exclu[5] = Math::Point(0.0f, 0.0f); // terminator - // TODO: m_engine->ChangeColor("human.png", colorRef1, colorNew1, colorRef2, colorNew2, 0.30f, 0.01f, ts, ti, exclu); + m_engine->ChangeTextureColor("human.png", colorRef1, colorNew1, colorRef2, colorNew2, 0.30f, 0.01f, ts, ti, exclu); float tolerance; @@ -4952,7 +4969,7 @@ void CRobotMain::ChangeColor() exclu[1] = Math::Point(153.0f/256.0f, 79.0f/166.0f); // blue canister exclu[2] = Math::Point(0.0f, 0.0f); exclu[3] = Math::Point(0.0f, 0.0f); // terminator - // TODO: m_engine->ChangeColor(name, colorRef1, colorNew1, colorRef2, colorNew2, tolerance, 0.00f, ts, ti, exclu); + m_engine->ChangeTextureColor(name, colorRef1, colorNew1, colorRef2, colorNew2, tolerance, 0.00f, ts, ti, exclu); colorRef2.r = 0.0f; colorRef2.g = 0.0f; @@ -4961,19 +4978,19 @@ void CRobotMain::ChangeColor() colorNew2.g = 0.0f; colorNew2.b = 0.0f; - // TODO: m_engine->ChangeColor("base1.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, 0, 0, true); - // TODO: m_engine->ChangeColor("convert.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, 0, 0, true); - // TODO: m_engine->ChangeColor("derrick.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, 0, 0, true); - // TODO: m_engine->ChangeColor("factory.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, 0, 0, true); - // TODO: m_engine->ChangeColor("lemt.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, 0, 0, true); - // TODO: m_engine->ChangeColor("roller.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, 0, 0, true); - // TODO: m_engine->ChangeColor("search.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, 0, 0, true); + m_engine->ChangeTextureColor("base1.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, 0, 0, true); + m_engine->ChangeTextureColor("convert.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, 0, 0, true); + m_engine->ChangeTextureColor("derrick.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, 0, 0, true); + m_engine->ChangeTextureColor("factory.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, 0, 0, true); + m_engine->ChangeTextureColor("lemt.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, 0, 0, true); + m_engine->ChangeTextureColor("roller.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, 0, 0, true); + m_engine->ChangeTextureColor("search.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, 0, 0, true); exclu[0] = Math::Point( 0.0f/256.0f, 160.0f/256.0f); exclu[1] = Math::Point(256.0f/256.0f, 256.0f/256.0f); // pencils exclu[2] = Math::Point(0.0f, 0.0f); exclu[3] = Math::Point(0.0f, 0.0f); // terminator - // TODO: m_engine->ChangeColor("drawer.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, exclu, 0, true); + m_engine->ChangeTextureColor("drawer.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, exclu, 0, true); exclu[0] = Math::Point(237.0f/256.0f, 176.0f/256.0f); exclu[1] = Math::Point(256.0f/256.0f, 220.0f/256.0f); // blue canister @@ -4981,26 +4998,26 @@ void CRobotMain::ChangeColor() exclu[3] = Math::Point(130.0f/256.0f, 214.0f/256.0f); // safe location exclu[4] = Math::Point(0.0f, 0.0f); exclu[5] = Math::Point(0.0f, 0.0f); // terminator - // TODO: m_engine->ChangeColor("subm.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, exclu, 0, true); + m_engine->ChangeTextureColor("subm.png", m_colorRefBot, m_colorNewBot, colorRef2, colorNew2, 0.10f, -1.0f, ts, ti, exclu, 0, true); exclu[0] = Math::Point(128.0f/256.0f, 160.0f/256.0f); exclu[1] = Math::Point(256.0f/256.0f, 256.0f/256.0f); // SatCom exclu[2] = Math::Point(0.0f, 0.0f); exclu[3] = Math::Point(0.0f, 0.0f); // terminator - // TODO: m_engine->ChangeColor("ant.png", m_colorRefAlien, m_colorNewAlien, colorRef2, colorNew2, 0.50f, -1.0f, ts, ti, exclu); - // TODO: m_engine->ChangeColor("mother.png", m_colorRefAlien, m_colorNewAlien, colorRef2, colorNew2, 0.50f, -1.0f, ts, ti); + m_engine->ChangeTextureColor("ant.png", m_colorRefAlien, m_colorNewAlien, colorRef2, colorNew2, 0.50f, -1.0f, ts, ti, exclu); + m_engine->ChangeTextureColor("mother.png", m_colorRefAlien, m_colorNewAlien, colorRef2, colorNew2, 0.50f, -1.0f, ts, ti); - // TODO: m_engine->ChangeColor("plant.png", m_colorRefGreen, m_colorNewGreen, colorRef2, colorNew2, 0.50f, -1.0f, ts, ti); + m_engine->ChangeTextureColor("plant.png", m_colorRefGreen, m_colorNewGreen, colorRef2, colorNew2, 0.50f, -1.0f, ts, ti); // PARTIPLOUF0 and PARTIDROP : ts = Math::Point(0.500f, 0.500f); ti = Math::Point(0.875f, 0.750f); - // TODO: m_engine->ChangeColor("effect00.png", m_colorRefWater, m_colorNewWater, colorRef2, colorNew2, 0.20f, -1.0f, ts, ti, 0, m_colorShiftWater, true); + m_engine->ChangeTextureColor("effect00.png", m_colorRefWater, m_colorNewWater, colorRef2, colorNew2, 0.20f, -1.0f, ts, ti, 0, m_colorShiftWater, true); // PARTIFLIC : ts = Math::Point(0.00f, 0.75f); ti = Math::Point(0.25f, 1.00f); - // TODO: m_engine->ChangeColor("effect02.png", m_colorRefWater, m_colorNewWater, colorRef2, colorNew2, 0.20f, -1.0f, ts, ti, 0, m_colorShiftWater, true); + m_engine->ChangeTextureColor("effect02.png", m_colorRefWater, m_colorNewWater, colorRef2, colorNew2, 0.20f, -1.0f, ts, ti, 0, m_colorShiftWater, true); } //! Updates the number of unnecessary objects @@ -6510,9 +6527,21 @@ bool CRobotMain::GetShowAll() return m_showAll; } -bool CRobotMain::GetCheatRadar() +bool CRobotMain::GetRadar() { - return m_cheatRadar; + if (m_cheatRadar) + return true; + + for (int i = 0; i < 1000000; i++) + { + CObject* obj = static_cast<CObject*>(m_iMan->SearchInstance(CLASS_OBJECT, i)); + if (obj == 0) break; + + ObjectType type = obj->GetType(); + if (type == OBJECT_RADAR) + return true; + } + return false; } const char* CRobotMain::GetSavegameDir() diff --git a/src/object/robotmain.h b/src/object/robotmain.h index 8724b90..70fbc8d 100644 --- a/src/object/robotmain.h +++ b/src/object/robotmain.h @@ -294,7 +294,7 @@ public: bool GetShowSoluce(); bool GetSceneSoluce(); bool GetShowAll(); - bool GetCheatRadar(); + bool GetRadar(); const char* GetSavegameDir(); const char* GetPublicDir(); const char* GetFilesDir(); diff --git a/src/ui/map.cpp b/src/ui/map.cpp index 43d9b7b..b852976 100644 --- a/src/ui/map.cpp +++ b/src/ui/map.cpp @@ -20,6 +20,8 @@ #include "ui/map.h" +#include "common/image.h" + #include <string.h> @@ -986,63 +988,60 @@ void CMap::DrawVertex(Math::Point uv1, Math::Point uv2, float zoom) void CMap::UpdateTerrain() { - Gfx::Color color; - Math::Vector pos; - float scale, water, level, intensity; - int x, y; - - if ( m_fixImage[0] != 0 ) return; // still image? + if (m_fixImage[0] != 0) return; // still image? - // TODO: map texture manipulation - return; + CImage img(Math::IntPoint(256, 256)); - // if ( !m_engine->OpenImage("map.png") ) return; + float scale = m_terrain->GetReliefScale(); + float water = m_water->GetLevel(); - scale = m_terrain->GetReliefScale(); - water = m_water->GetLevel(); + Gfx::Color color; color.a = 0.0f; - for ( y=0 ; y<256 ; y++ ) + for (int y = 0; y < 256; y++) { - for ( x=0 ; x<256 ; x++ ) + for (int x = 0; x < 256; x++) { - pos.x = (static_cast<float>(x)-128.0f)*m_half/128.0f; - pos.z = -(static_cast<float>(y)-128.0f)*m_half/128.0f; + Math::Vector pos; + pos.x = (static_cast<float>(x) - 128.0f) * m_half / 128.0f; + pos.z = -(static_cast<float>(y) - 128.0f) * m_half / 128.0f; pos.y = 0.0f; + float level; + if ( pos.x >= -m_half && pos.x <= m_half && pos.z >= -m_half && pos.z <= m_half ) { - level = m_terrain->GetFloorLevel(pos, true)/scale; + level = m_terrain->GetFloorLevel(pos, true) / scale; } else { level = 1000.0f; } - intensity = level/256.0f; - if ( intensity < 0.0f ) intensity = 0.0f; - if ( intensity > 1.0f ) intensity = 1.0f; + float intensity = level / 256.0f; + if (intensity < 0.0f) intensity = 0.0f; + if (intensity > 1.0f) intensity = 1.0f; - if ( level >= water ) // on water? + if (level >= water) // on water? { - color.r = m_floorColor.r + (intensity-0.5f); - color.g = m_floorColor.g + (intensity-0.5f); - color.b = m_floorColor.b + (intensity-0.5f); + color.r = Math::Norm(m_floorColor.r + (intensity - 0.5f)); + color.g = Math::Norm(m_floorColor.g + (intensity - 0.5f)); + color.b = Math::Norm(m_floorColor.b + (intensity - 0.5f)); } else // underwater? { - color.r = m_waterColor.r + (intensity-0.5f); - color.g = m_waterColor.g + (intensity-0.5f); - color.b = m_waterColor.b + (intensity-0.5f); + color.r = Math::Norm(m_waterColor.r + (intensity - 0.5f)); + color.g = Math::Norm(m_waterColor.g + (intensity - 0.5f)); + color.b = Math::Norm(m_waterColor.b + (intensity - 0.5f)); } - //m_engine->SetDot(x, y, color); + img.SetPixel(Math::IntPoint(x, y), color); } } - //m_engine->CopyImage(); // copy the ground drawing - //m_engine->CloseImage(); + m_engine->DeleteTexture("map.png"); + m_engine->LoadTexture("map.png", &img); } // Updates the field in the map. @@ -1118,7 +1117,7 @@ void CMap::FlushObject() m_totalFix = 0; // object index fixed m_totalMove = MAPMAXOBJECT-2; // moving vehicles index - //m_bRadar = m_main->GetCheatRadar(); // no radar + m_bRadar = m_main->GetRadar(); for ( i=0 ; i<MAPMAXOBJECT ; i++ ) { @@ -1155,12 +1154,7 @@ void CMap::UpdateObject(CObject* pObj) pos.z = ppos.y; dir += m_angle; } - - if ( type == OBJECT_RADAR ) - { - m_bRadar = true; // radar exists - } - + color = MAPCOLOR_NULL; if ( type == OBJECT_BASE ) { |