Index: ps/trunk/source/graphics/CinemaManager.h =================================================================== --- ps/trunk/source/graphics/CinemaManager.h +++ ps/trunk/source/graphics/CinemaManager.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -19,8 +19,8 @@ #define INCLUDED_CINEMAMANAGER #include "lib/input.h" // InReaction - can't forward-declare enum +#include "graphics/Color.h" #include "ps/CStr.h" -#include "ps/Shapes.h" #include "simulation2/helpers/CinemaPath.h" Index: ps/trunk/source/graphics/Color.h =================================================================== --- ps/trunk/source/graphics/Color.h +++ ps/trunk/source/graphics/Color.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2009 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -15,23 +15,20 @@ * along with 0 A.D. If not, see . */ -/* - * Convert float RGB(A) colors to unsigned byte - */ - #ifndef INCLUDED_COLOR #define INCLUDED_COLOR -#include "SColor.h" +#include "graphics/SColor.h" #include "maths/Vector3D.h" #include "maths/Vector4D.h" -// simple defines for 3 and 4 component floating point colors - just map to -// corresponding vector types +// Simple defines for 3 and 4 component floating point colors - just map to +// corresponding vector types. typedef CVector3D RGBColor; typedef CVector4D RGBAColor; -// exposed as function pointer because it is set at init-time to +// Convert float RGB(A) colors to unsigned byte. +// Exposed as function pointer because it is set at init-time to // one of several implementations depending on CPU caps. extern SColor4ub (*ConvertRGBColorTo4ub)(const RGBColor& src); @@ -39,4 +36,41 @@ // possible codepath. extern void ColorActivateFastImpl(); -#endif +class CStr8; + +struct CColor +{ + CColor() : r(-1.f), g(-1.f), b(-1.f), a(1.f) {} + CColor(float cr, float cg, float cb, float ca) : r(cr), g(cg), b(cb), a(ca) {} + + /** + * Try to parse @p Value as a color. Returns true on success, false otherwise. + * @param value Should be "r g b" or "r g b a" where each value is an integer in [0,255]. + * @param defaultAlpha The alpha value that is used if the format of @p Value is "r g b". + */ + bool ParseString(const CStr8& value, int defaultAlpha = 255); + + bool operator==(const CColor& color) const; + bool operator!=(const CColor& color) const + { + return !(*this == color); + } + + // For passing to glColor[34]fv: + const float* FloatArray() const { return &r; } + + // For passing to CRenderer: + SColor4ub AsSColor4ub() const + { + return SColor4ub( + static_cast(r * 255.f), + static_cast(g * 255.f), + static_cast(b * 255.f), + static_cast(a * 255.f) + ); + } + + float r, g, b, a; +}; + +#endif // INCLUDED_COLOR Index: ps/trunk/source/graphics/Color.cpp =================================================================== --- ps/trunk/source/graphics/Color.cpp +++ ps/trunk/source/graphics/Color.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2009 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -15,16 +15,14 @@ * along with 0 A.D. If not, see . */ -/* - * Convert float RGB(A) colors to unsigned byte - */ - #include "precompiled.h" #include "graphics/Color.h" -#include "maths/MathUtil.h" #include "graphics/SColor.h" +#include "maths/MathUtil.h" +#include "ps/CLogger.h" +#include "ps/CStr.h" #if HAVE_SSE # include @@ -34,10 +32,10 @@ static SColor4ub fallback_ConvertRGBColorTo4ub(const RGBColor& src) { SColor4ub result; - result.R=clamp(int(src.X*255),0,255); - result.G=clamp(int(src.Y*255),0,255); - result.B=clamp(int(src.Z*255),0,255); - result.A=0xff; + result.R = clamp(static_cast(src.X * 255), 0, 255); + result.G = clamp(static_cast(src.Y * 255), 0, 255); + result.B = clamp(static_cast(src.Z * 255), 0, 255); + result.A = 255; return result; } @@ -93,3 +91,57 @@ debug_printf("No SSE available. Slow fallback routines will be used.\n"); } } + +bool CColor::ParseString(const CStr8& value, int defaultAlpha) +{ + const size_t NUM_VALS = 4; + int values[NUM_VALS] = { 0, 0, 0, defaultAlpha }; + std::stringstream stream; + stream.str(value); + // Parse each value + size_t i; + for (i = 0; i < NUM_VALS; ++i) + { + if (stream.eof()) + break; + + stream >> values[i]; + if ((stream.rdstate() & std::stringstream::failbit) != 0) + { + LOGWARNING("Unable to parse CColor parameters. Your input: '%s'", value.c_str()); + return false; + } + if (values[i] < 0 || values[i] > 255) + { + LOGWARNING("Invalid value (<0 or >255) when parsing CColor parameters. Your input: '%s'", value.c_str()); + return false; + } + } + + if (i < 3) + { + LOGWARNING("Not enough parameters when parsing as CColor. Your input: '%s'", value.c_str()); + return false; + } + if (!stream.eof()) + { + LOGWARNING("Too many parameters when parsing as CColor. Your input: '%s'", value.c_str()); + return false; + } + + r = values[0] / 255.f; + g = values[1] / 255.f; + b = values[2] / 255.f; + a = values[3] / 255.f; + + return true; +} + +bool CColor::operator==(const CColor& color) const +{ + return + r == color.r && + g == color.g && + b == color.b && + a == color.a; +} Index: ps/trunk/source/graphics/Material.h =================================================================== --- ps/trunk/source/graphics/Material.h +++ ps/trunk/source/graphics/Material.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2012 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -18,11 +18,11 @@ #ifndef INCLUDED_MATERIAL #define INCLUDED_MATERIAL +#include "graphics/Color.h" #include "graphics/ShaderDefines.h" #include "graphics/Texture.h" #include "ps/CStr.h" #include "ps/CStrIntern.h" -#include "ps/Shapes.h" #include "simulation2/helpers/Player.h" class CMaterial Index: ps/trunk/source/graphics/ModelAbstract.h =================================================================== --- ps/trunk/source/graphics/ModelAbstract.h +++ ps/trunk/source/graphics/ModelAbstract.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -18,9 +18,9 @@ #ifndef INCLUDED_MODELABSTRACT #define INCLUDED_MODELABSTRACT -#include "maths/BoundingBoxOriented.h" +#include "graphics/Color.h" #include "graphics/RenderableObject.h" -#include "ps/Shapes.h" +#include "maths/BoundingBoxOriented.h" #include "simulation2/helpers/Player.h" class CModel; Index: ps/trunk/source/graphics/ObjectEntry.h =================================================================== --- ps/trunk/source/graphics/ObjectEntry.h +++ ps/trunk/source/graphics/ObjectEntry.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -29,9 +29,9 @@ #include #include +#include "graphics/Color.h" #include "lib/file/vfs/vfs_path.h" #include "ps/CStr.h" -#include "ps/Shapes.h" #include "graphics/ObjectBase.h" Index: ps/trunk/source/graphics/Overlay.h =================================================================== --- ps/trunk/source/graphics/Overlay.h +++ ps/trunk/source/graphics/Overlay.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -18,12 +18,12 @@ #ifndef INCLUDED_GRAPHICS_OVERLAY #define INCLUDED_GRAPHICS_OVERLAY +#include "graphics/Color.h" #include "graphics/Texture.h" #include "maths/Vector2D.h" #include "maths/Vector3D.h" #include "maths/FixedVector3D.h" #include "ps/CStrIntern.h" -#include "ps/Shapes.h" class CTerrain; class CSimContext; Index: ps/trunk/source/graphics/ShaderProgram.cpp =================================================================== --- ps/trunk/source/graphics/ShaderProgram.cpp +++ ps/trunk/source/graphics/ShaderProgram.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -19,6 +19,7 @@ #include "ShaderProgram.h" +#include "graphics/Color.h" #include "graphics/ShaderManager.h" #include "graphics/TextureManager.h" #include "lib/res/graphics/ogl_tex.h" @@ -27,7 +28,6 @@ #include "ps/CLogger.h" #include "ps/Filesystem.h" #include "ps/PreprocessorWrapper.h" -#include "ps/Shapes.h" #if !CONFIG2_GLES Index: ps/trunk/source/graphics/TerrainProperties.cpp =================================================================== --- ps/trunk/source/graphics/TerrainProperties.cpp +++ ps/trunk/source/graphics/TerrainProperties.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -23,11 +23,11 @@ #include -#include "TerrainTextureManager.h" +#include "graphics/Color.h" +#include "graphics/TerrainTextureManager.h" #include "maths/MathUtil.h" #include "ps/CLogger.h" #include "ps/Filesystem.h" -#include "ps/Shapes.h" #include "ps/XML/XeroXMB.h" #include "ps/XML/Xeromyces.h" Index: ps/trunk/source/graphics/TerritoryTexture.cpp =================================================================== --- ps/trunk/source/graphics/TerritoryTexture.cpp +++ ps/trunk/source/graphics/TerritoryTexture.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -19,10 +19,10 @@ #include "TerritoryTexture.h" +#include "graphics/Color.h" #include "graphics/Terrain.h" #include "lib/bits.h" #include "ps/Profile.h" -#include "ps/Shapes.h" #include "renderer/Renderer.h" #include "simulation2/Simulation2.h" #include "simulation2/helpers/Pathfinding.h" Index: ps/trunk/source/graphics/TextRenderer.h =================================================================== --- ps/trunk/source/graphics/TextRenderer.h +++ ps/trunk/source/graphics/TextRenderer.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2012 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -18,6 +18,7 @@ #ifndef INCLUDED_TEXTRENDERER #define INCLUDED_TEXTRENDERER +#include "graphics/Color.h" #include "graphics/ShaderProgramPtr.h" #include "maths/Matrix3D.h" #include "ps/CStrIntern.h" Index: ps/trunk/source/gui/GUIRenderer.h =================================================================== --- ps/trunk/source/gui/GUIRenderer.h +++ ps/trunk/source/gui/GUIRenderer.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -18,6 +18,7 @@ #ifndef INCLUDED_GUIRENDERER #define INCLUDED_GUIRENDERER +#include "graphics/Color.h" #include "graphics/ShaderTechnique.h" #include "graphics/Texture.h" #include "lib/res/handle.h" Index: ps/trunk/source/gui/GUIbase.h =================================================================== --- ps/trunk/source/gui/GUIbase.h +++ ps/trunk/source/gui/GUIbase.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -35,6 +35,7 @@ #include #include +#include "graphics/Color.h" #include "ps/CStr.h" #include "ps/Errors.h" // I would like to just forward declare CSize, but it doesn't Index: ps/trunk/source/ps/Shapes.h =================================================================== --- ps/trunk/source/ps/Shapes.h +++ ps/trunk/source/ps/Shapes.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -16,49 +16,15 @@ */ /* -Shapes.h - --Overview-- Classes mostly useful for representing 2D screen overlays; includes functionality for overlay position, color, texture and borders. - - CColor is used more widely for various game systems. */ #ifndef INCLUDED_SHAPES #define INCLUDED_SHAPES -#include "graphics/SColor.h" - -class CStr8; - -struct CColor -{ - CColor() : r(-1.f), g(-1.f), b(-1.f), a(1.f) {} - CColor(float cr,float cg,float cb,float ca) : r(cr), g(cg), b(cb), a(ca) {} - - bool ParseString(const CStr8& Value, int DefaultAlpha = 255); - - bool operator == (const CColor &color) const; - - bool operator != (const CColor &color) const - { - return !(*this==color); - } - - // For passing to glColor[34]fv: - const float* FloatArray() const { return &r; } - - // For passing to CRenderer: - SColor4ub AsSColor4ub() const - { - return SColor4ub((u8)(r*255.0), (u8)(g*255.0), (u8)(b*255.0), (u8)(a*255.0)); - } - - float r, g, b, a; -}; - class CPos; class CSize; Index: ps/trunk/source/ps/Shapes.cpp =================================================================== --- ps/trunk/source/ps/Shapes.cpp +++ ps/trunk/source/ps/Shapes.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -15,80 +15,9 @@ * along with 0 A.D. If not, see . */ -/* -Shapes.cpp -*/ - #include "precompiled.h" -#include - #include "Shapes.h" -#include "CLogger.h" -#include "CStr.h" - -/** - * Try to parse @p Value as a color. Returns true on success, false otherwise. - * @param Value Should be "r g b" or "r g b a" where each value is an integer in [0,255]. - * @param DefaultAlpha The alpha value that is used if the format of @p Value is "r g b". - */ -bool CColor::ParseString(const CStr8& Value, int DefaultAlpha) -{ - const unsigned int NUM_VALS = 4; - int values[NUM_VALS] = { 0, 0, 0, DefaultAlpha }; - std::stringstream stream; - stream.str(Value); - // Parse each value - size_t i; - for (i = 0; i < NUM_VALS; ++i) - { - if (stream.eof()) - break; - - stream >> values[i]; - if ((stream.rdstate() & std::stringstream::failbit) != 0) - { - LOGWARNING("Unable to parse CColor parameters. Your input: '%s'", Value.c_str()); - return false; - } - if (values[i] < 0 || values[i] > 255) - { - LOGWARNING("Invalid value (<0 or >255) when parsing CColor parameters. Your input: '%s'", Value.c_str()); - return false; - } - } - - if (i < 3) - { - LOGWARNING("Not enough parameters when parsing as CColor. Your input: '%s'", Value.c_str()); - return false; - } - if (!stream.eof()) - { - LOGWARNING("Too many parameters when parsing as CColor. Your input: '%s'", Value.c_str()); - return false; - } - - r = values[0]/255.f; - g = values[1]/255.f; - b = values[2]/255.f; - a = values[3]/255.f; - - return true; -} - - -/*************************************************************************/ - -bool CColor::operator == (const CColor &color) const -{ - return r==color.r && - g==color.g && - b==color.b && - a==color.a; -} - -/*************************************************************************/ CRect::CRect() : left(0.f), top(0.f), right(0.f), bottom(0.f) Index: ps/trunk/source/ps/tests/test_CColor.h =================================================================== --- ps/trunk/source/ps/tests/test_CColor.h +++ ps/trunk/source/ps/tests/test_CColor.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2014 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -17,8 +17,8 @@ #include "lib/self_test.h" +#include "graphics/Color.h" #include "ps/CLogger.h" -#include "ps/Shapes.h" class TestCColor : public CxxTest::TestSuite { Index: ps/trunk/source/renderer/TerrainOverlay.cpp =================================================================== --- ps/trunk/source/renderer/TerrainOverlay.cpp +++ ps/trunk/source/renderer/TerrainOverlay.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -19,13 +19,13 @@ #include "TerrainOverlay.h" +#include "graphics/Color.h" #include "graphics/Terrain.h" #include "lib/bits.h" #include "lib/ogl.h" #include "maths/MathUtil.h" #include "ps/Game.h" #include "ps/Profile.h" -#include "ps/Shapes.h" #include "ps/World.h" #include "renderer/Renderer.h" #include "renderer/TerrainRenderer.h" Index: ps/trunk/source/renderer/WaterManager.h =================================================================== --- ps/trunk/source/renderer/WaterManager.h +++ ps/trunk/source/renderer/WaterManager.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -22,11 +22,11 @@ #ifndef INCLUDED_WATERMANAGER #define INCLUDED_WATERMANAGER +#include "graphics/Color.h" #include "graphics/Texture.h" #include "lib/ogl.h" #include "maths/Matrix3D.h" #include "maths/Vector2D.h" -#include "ps/Shapes.h" #include "renderer/VertexBufferManager.h" class CSimulation2; Index: ps/trunk/source/simulation2/components/CCmpMinimap.cpp =================================================================== --- ps/trunk/source/simulation2/components/CCmpMinimap.cpp +++ ps/trunk/source/simulation2/components/CCmpMinimap.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -25,7 +25,7 @@ #include "simulation2/components/ICmpOwnership.h" #include "simulation2/MessageTypes.h" -#include "ps/Shapes.h" +#include "graphics/Color.h" class CCmpMinimap : public ICmpMinimap { Index: ps/trunk/source/simulation2/components/ICmpPlayer.cpp =================================================================== --- ps/trunk/source/simulation2/components/ICmpPlayer.cpp +++ ps/trunk/source/simulation2/components/ICmpPlayer.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -19,12 +19,11 @@ #include "ICmpPlayer.h" +#include "graphics/Color.h" #include "maths/FixedVector3D.h" #include "simulation2/system/InterfaceScripted.h" #include "simulation2/scripting/ScriptComponent.h" -#include "ps/Shapes.h" - BEGIN_INTERFACE_WRAPPER(Player) END_INTERFACE_WRAPPER(Player) Index: ps/trunk/source/simulation2/components/ICmpSelectable.cpp =================================================================== --- ps/trunk/source/simulation2/components/ICmpSelectable.cpp +++ ps/trunk/source/simulation2/components/ICmpSelectable.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -21,7 +21,7 @@ #include "simulation2/system/InterfaceScripted.h" -#include "ps/Shapes.h" +#include "graphics/Color.h" BEGIN_INTERFACE_WRAPPER(Selectable) DEFINE_INTERFACE_METHOD_2("SetSelectionHighlight", void, ICmpSelectable, SetSelectionHighlight, CColor, bool) Index: ps/trunk/source/simulation2/scripting/EngineScriptConversions.cpp =================================================================== --- ps/trunk/source/simulation2/scripting/EngineScriptConversions.cpp +++ ps/trunk/source/simulation2/scripting/EngineScriptConversions.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -19,6 +19,7 @@ #include "scriptinterface/ScriptConversions.h" +#include "graphics/Color.h" #include "maths/Fixed.h" #include "maths/FixedVector2D.h" #include "maths/FixedVector3D.h" Index: ps/trunk/source/tools/atlas/GameInterface/Brushes.cpp =================================================================== --- ps/trunk/source/tools/atlas/GameInterface/Brushes.cpp +++ ps/trunk/source/tools/atlas/GameInterface/Brushes.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2009 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -19,12 +19,12 @@ #include "Brushes.h" -#include "ps/Game.h" -#include "ps/Shapes.h" -#include "ps/World.h" +#include "graphics/Color.h" #include "graphics/Terrain.h" #include "lib/ogl.h" #include "maths/MathUtil.h" +#include "ps/Game.h" +#include "ps/World.h" #include "renderer/TerrainOverlay.h" #include "simulation2/Simulation2.h" #include "simulation2/system/SimContext.h"