diff --git a/source/graphics/CinemaManager.h b/source/graphics/CinemaManager.h
index 4c2005db7e..45a9fc1339 100644
--- a/source/graphics/CinemaManager.h
+++ b/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"
diff --git a/source/graphics/Color.cpp b/source/graphics/Color.cpp
index ab41a1a4df..cfbd22fbd5 100644
--- a/source/graphics/Color.cpp
+++ b/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 @@ void ColorActivateFastImpl()
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;
+}
diff --git a/source/graphics/Color.h b/source/graphics/Color.h
index 22dd01ae25..18251f5ab3 100644
--- a/source/graphics/Color.h
+++ b/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 @@ extern SColor4ub (*ConvertRGBColorTo4ub)(const RGBColor& src);
// 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
diff --git a/source/graphics/Material.h b/source/graphics/Material.h
index 7c2c00c96d..2812f3aa2c 100644
--- a/source/graphics/Material.h
+++ b/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
diff --git a/source/graphics/ModelAbstract.h b/source/graphics/ModelAbstract.h
index 1bbe906e49..75519d9f1d 100644
--- a/source/graphics/ModelAbstract.h
+++ b/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;
diff --git a/source/graphics/ObjectEntry.h b/source/graphics/ObjectEntry.h
index 371fb9a12b..897ca9e297 100644
--- a/source/graphics/ObjectEntry.h
+++ b/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 @@ struct SPropPoint;
#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"
diff --git a/source/graphics/Overlay.h b/source/graphics/Overlay.h
index 2d9385bcf7..ba547c34f8 100644
--- a/source/graphics/Overlay.h
+++ b/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;
diff --git a/source/graphics/ShaderProgram.cpp b/source/graphics/ShaderProgram.cpp
index 58b2d737b7..55d6ef5faf 100644
--- a/source/graphics/ShaderProgram.cpp
+++ b/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
diff --git a/source/graphics/TerrainProperties.cpp b/source/graphics/TerrainProperties.cpp
index a54469bb2b..89d35cb7d6 100644
--- a/source/graphics/TerrainProperties.cpp
+++ b/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"
diff --git a/source/graphics/TerritoryTexture.cpp b/source/graphics/TerritoryTexture.cpp
index c73c28c99f..01cb307c85 100644
--- a/source/graphics/TerritoryTexture.cpp
+++ b/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"
diff --git a/source/graphics/TextRenderer.h b/source/graphics/TextRenderer.h
index d4b93f569b..2ab8a6d5dc 100644
--- a/source/graphics/TextRenderer.h
+++ b/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"
diff --git a/source/gui/GUIRenderer.h b/source/gui/GUIRenderer.h
index 6008e58e6d..e5dce45467 100644
--- a/source/gui/GUIRenderer.h
+++ b/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"
diff --git a/source/gui/GUIbase.h b/source/gui/GUIbase.h
index 43df71abea..3211821913 100644
--- a/source/gui/GUIbase.h
+++ b/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 @@ GUI Core, stuff that the whole GUI uses
#include