diff options
author | Zaba999 <zaba.marcin@gmail.com> | 2012-09-20 23:04:37 +0200 |
---|---|---|
committer | Zaba999 <zaba.marcin@gmail.com> | 2012-09-20 23:04:37 +0200 |
commit | 34a11021daca9d6b51e8cc29c1562a75815df7b3 (patch) | |
tree | 7d1427b27337d32224cf66cc114adf4f3665bbee /src/graphics | |
parent | 191fdc614ed8022c145d3530f9d412e715ae37db (diff) | |
parent | e25823f98437461826b52521bcf9d70eb11a00b3 (diff) | |
download | colobot-34a11021daca9d6b51e8cc29c1562a75815df7b3.tar.gz colobot-34a11021daca9d6b51e8cc29c1562a75815df7b3.tar.bz2 colobot-34a11021daca9d6b51e8cc29c1562a75815df7b3.zip |
changed paths for models and levels. Now it's possible to load level. Merged with latest trunk
Diffstat (limited to 'src/graphics')
33 files changed, 2454 insertions, 2262 deletions
diff --git a/src/graphics/core/color.cpp b/src/graphics/core/color.cpp index f241227..1f9d7a5 100644 --- a/src/graphics/core/color.cpp +++ b/src/graphics/core/color.cpp @@ -14,16 +14,19 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// color.cpp #include "graphics/core/color.h" #include "math/func.h" -Gfx::ColorHSV Gfx::RGB2HSV(Gfx::Color color) +// Graphics module namespace +namespace Gfx { + + +ColorHSV RGB2HSV(Color color) { - Gfx::ColorHSV result; + ColorHSV result; float min = Math::Min(color.r, color.g, color.b); float max = Math::Max(color.r, color.g, color.b); @@ -61,9 +64,9 @@ Gfx::ColorHSV Gfx::RGB2HSV(Gfx::Color color) return result; } -Gfx::Color Gfx::HSV2RGB(Gfx::ColorHSV color) +Color HSV2RGB(ColorHSV color) { - Gfx::Color result; + Color result; color.h = Math::Norm(color.h)*360.0f; color.s = Math::Norm(color.s); @@ -101,3 +104,5 @@ Gfx::Color Gfx::HSV2RGB(Gfx::ColorHSV color) return result; } + +} // namespace Gfx diff --git a/src/graphics/core/color.h b/src/graphics/core/color.h index bcd0af1..4b152c1 100644 --- a/src/graphics/core/color.h +++ b/src/graphics/core/color.h @@ -21,14 +21,17 @@ #pragma once + #include <sstream> +// Graphics module namespace namespace Gfx { /** - \struct Color - \brief RGBA color */ + * \struct Color + * \brief RGBA color + */ struct Color { //! Red, green, blue and alpha components @@ -38,9 +41,9 @@ struct Color explicit Color(float aR = 0.0f, float aG = 0.0f, float aB = 0.0f, float aA = 0.0f) : r(aR), g(aG), b(aB), a(aA) {} - inline Gfx::Color Inverse() const + inline Color Inverse() const { - return Gfx::Color(1.0f - r, 1.0f - g, 1.0f - b, 1.0f - a); + return Color(1.0f - r, 1.0f - g, 1.0f - b, 1.0f - a); } //! Returns the struct cast to \c float* array; use with care! @@ -64,20 +67,21 @@ struct Color return s.str(); } - inline bool operator==(const Gfx::Color &other) const + inline bool operator==(const Color &other) const { return r == other.r && g == other.g && b == other.b && a == other.a; } - inline bool operator!=(const Gfx::Color &other) const + inline bool operator!=(const Color &other) const { return ! this->operator==(other); } }; /** - \struct ColorHSV - \brief HSV color */ + * \struct ColorHSV + * \brief HSV color + */ struct ColorHSV { float h, s, v; @@ -96,10 +100,10 @@ struct ColorHSV }; //! Converts a RGB color to HSV color -Gfx::ColorHSV RGB2HSV(Gfx::Color color); +ColorHSV RGB2HSV(Color color); //! Converts a HSV color to RGB color -Gfx::Color HSV2RGB(Gfx::ColorHSV color); +Color HSV2RGB(ColorHSV color); -}; // namespace Gfx +} // namespace Gfx diff --git a/src/graphics/core/device.h b/src/graphics/core/device.h index 9eb6f6d..7c60d21 100644 --- a/src/graphics/core/device.h +++ b/src/graphics/core/device.h @@ -17,7 +17,7 @@ /** * \file graphics/core/device.h - * \brief Abstract graphics device - Gfx::CDevice class and related structs/enums + * \brief Abstract graphics device - CDevice class and related structs/enums */ #pragma once @@ -28,6 +28,7 @@ #include "graphics/core/material.h" #include "graphics/core/texture.h" #include "graphics/core/vertex.h" + #include "math/intpoint.h" #include "math/matrix.h" @@ -38,14 +39,15 @@ class CImage; struct ImageData; +// Graphics module namespace namespace Gfx { /** - \struct DeviceConfig - \brief General config for graphics device - - These settings are common window options set by SDL. -*/ + * \struct DeviceConfig + * \brief General config for graphics device + * + * These settings are common window options set by SDL. + */ struct DeviceConfig { //! Screen size @@ -78,10 +80,11 @@ struct DeviceConfig /** - \enum TransformType - \brief Type of transformation in rendering pipeline - - These correspond to DirectX's three transformation matrices. */ + * \enum TransformType + * \brief Type of transformation in rendering pipeline + * + * These correspond to DirectX's three transformation matrices. + */ enum TransformType { TRANSFORM_WORLD, @@ -90,8 +93,9 @@ enum TransformType }; /** - \enum RenderState - \brief Render states that can be enabled/disabled */ + * \enum RenderState + * \brief Render states that can be enabled/disabled + */ enum RenderState { RENDER_STATE_LIGHTING, @@ -106,8 +110,9 @@ enum RenderState }; /** - \enum CompFunc - \brief Type of function used to compare values */ + * \enum CompFunc + * \brief Type of function used to compare values + */ enum CompFunc { COMP_FUNC_NEVER, @@ -121,8 +126,9 @@ enum CompFunc }; /** - \enum BlendFunc - \brief Type of blending function */ + * \enum BlendFunc + * \brief Type of blending function + */ enum BlendFunc { BLEND_ZERO, @@ -139,8 +145,9 @@ enum BlendFunc }; /** - \enum FogMode - \brief Type of fog calculation function */ + * \enum FogMode + * \brief Type of fog calculation function + */ enum FogMode { FOG_LINEAR, @@ -149,8 +156,9 @@ enum FogMode }; /** - \enum CullMode - \brief Culling mode for polygons */ + * \enum CullMode + * \brief Culling mode for polygons + */ enum CullMode { //! Cull clockwise faces @@ -160,8 +168,9 @@ enum CullMode }; /** - \enum ShadeModel - \brief Shade model used in rendering */ + * \enum ShadeModel + * \brief Shade model used in rendering + */ enum ShadeModel { SHADE_FLAT, @@ -169,8 +178,9 @@ enum ShadeModel }; /** - \enum FillMode - \brief Polygon fill mode */ + * \enum FillMode + * \brief Polygon fill mode + */ enum FillMode { //! Draw only points @@ -178,12 +188,13 @@ enum FillMode //! Draw only lines FILL_LINES, //! Draw full polygons - FILL_FILL + FILL_POLY }; /** - \enum PrimitiveType - \brief Type of primitive to render */ + * \enum PrimitiveType + * \brief Type of primitive to render + */ enum PrimitiveType { PRIMITIVE_POINTS, @@ -194,10 +205,11 @@ enum PrimitiveType }; /** - \enum IntersectPlane - \brief Intersection plane of projection volume - - These flags can be OR'd together. */ + * \enum IntersectPlane + * \brief Intersection plane of projection volume + * + * These flags can be OR'd together. + */ enum IntersectPlane { INTERSECT_PLANE_LEFT = 0x01, @@ -211,67 +223,16 @@ enum IntersectPlane INTERSECT_PLANE_FRONT | INTERSECT_PLANE_BACK }; -/* - -Notes for rewriting DirectX code: - ->> SetRenderState() translates to many functions depending on param - -D3DRENDERSTATE_ALPHABLENDENABLE -> SetRenderState() with RENDER_STATE_BLENDING -D3DRENDERSTATE_ALPHAFUNC -> SetAlphaTestFunc() func -D3DRENDERSTATE_ALPHAREF -> SetAlphaTestFunc() ref -D3DRENDERSTATE_ALPHATESTENABLE -> SetRenderState() with RENDER_STATE_ALPHA_TEST -D3DRENDERSTATE_AMBIENT -> SetGlobalAmbient() -D3DRENDERSTATE_CULLMODE -> SetCullMode() -D3DRENDERSTATE_DESTBLEND -> SetBlendFunc() dest blending func -D3DRENDERSTATE_DITHERENABLE -> SetRenderState() with RENDER_STATE_DITHERING -D3DRENDERSTATE_FILLMODE -> SetFillMode() -D3DRENDERSTATE_FOGCOLOR -> SetFogParams() -D3DRENDERSTATE_FOGENABLE -> SetRenderState() with RENDER_STATE_FOG -D3DRENDERSTATE_FOGEND -> SetFogParams() -D3DRENDERSTATE_FOGSTART -> SetFogParams() -D3DRENDERSTATE_FOGVERTEXMODE -> SetFogParams() fog model -D3DRENDERSTATE_LIGHTING -> SetRenderState() with RENDER_STATE_LIGHTING -D3DRENDERSTATE_SHADEMODE -> SetShadeModel() -D3DRENDERSTATE_SPECULARENABLE -> doesn't matter (always enabled) -D3DRENDERSTATE_SRCBLEND -> SetBlendFunc() src blending func -D3DRENDERSTATE_TEXTUREFACTOR -> SetTextureFactor() -D3DRENDERSTATE_ZBIAS -> SetDepthBias() -D3DRENDERSTATE_ZENABLE -> SetRenderState() with RENDER_STATE_DEPTH_TEST -D3DRENDERSTATE_ZFUNC -> SetDepthTestFunc() -D3DRENDERSTATE_ZWRITEENABLE -> SetRenderState() with RENDER_STATE_DEPTH_WRITE - - ->> SetTextureStageState() translates to SetTextureParams() or CreateTexture() for some params - -Params from enum in struct TextureCreateParams or TextureParams - D3DTSS_ADDRESS -> Gfx::TexWrapMode wrapS, wrapT - D3DTSS_ALPHAARG1 -> Gfx::TexMixArgument alphaArg1 - D3DTSS_ALPHAARG2 -> Gfx::TexMixArgument alphaArg2 - D3DTSS_ALPHAOP -> Gfx::TexMixOperation alphaOperation - D3DTSS_COLORARG1 -> Gfx::TexMixArgument colorArg1 - D3DTSS_COLORARG2 -> Gfx::TexMixArgument colorArg2 - D3DTSS_COLOROP -> Gfx::TexMixOperation colorOperation - D3DTSS_MAGFILTER -> Gfx::TexMagFilter magFilter - D3DTSS_MINFILTER -> Gfx::TexMinFilter minFilter - D3DTSS_TEXCOORDINDEX -> doesn't matter (texture coords are set explicitly by glMultiTexCoordARB*) - -Note that D3DTSS_ALPHAOP or D3DTSS_COLOROP set to D3DTOP_DISABLE must translate to disabling the whole texture stage. -In DirectX, you shouldn't mix enabling one and disabling the other. -Also, if previous stage is disabled in DirectX, the later ones are disabled, too. In OpenGL, that is not the case. - -*/ - /** - \class CDevice - \brief Abstract interface of graphics device - - It is based on DIRECT3DDEVICE class from DirectX to make it easier to port existing code. - It encapsulates the general graphics device state and provides a common interface - to graphics-specific functions which will be used throughout the program, - both in CEngine class and in UI classes. Note that it doesn't contain all functions from DirectX, - only those that were used in old code. - + * \class CDevice + * \brief Abstract interface of graphics device + * + * It is based on DIRECT3DDEVICE class from DirectX to make it easier to port existing code. + * It encapsulates the general graphics device state and provides a common interface + * to graphics-specific functions which will be used throughout the program, + * both in CEngine class and in UI classes. Note that it doesn't contain all functions from DirectX, + * only those that were used in old code. + * */ class CDevice { @@ -302,72 +263,72 @@ public: virtual void MultiplyTransform(TransformType type, const Math::Matrix &matrix) = 0; //! Sets the current material - virtual void SetMaterial(const Gfx::Material &material) = 0; + virtual void SetMaterial(const Material &material) = 0; //! Returns the current material - virtual const Gfx::Material& GetMaterial() = 0; + virtual const Material& GetMaterial() = 0; //! Returns the maximum number of lights available virtual int GetMaxLightCount() = 0; //! Sets the light at given index - virtual void SetLight(int index, const Gfx::Light &light) = 0; + virtual void SetLight(int index, const Light &light) = 0; //! Returns the current light at given index - virtual const Gfx::Light& GetLight(int index) = 0; + virtual const Light& GetLight(int index) = 0; //! Enables/disables the light at given index virtual void SetLightEnabled(int index, bool enabled) = 0; //! Returns the current enable state of light at given index virtual bool GetLightEnabled(int index) = 0; //! Creates a texture from image; the image can be safely removed after that - virtual Gfx::Texture CreateTexture(CImage *image, const Gfx::TextureCreateParams ¶ms) = 0; + virtual Texture CreateTexture(CImage *image, const TextureCreateParams ¶ms) = 0; //! Creates a texture from raw image data; image data can be freed after that - virtual Gfx::Texture CreateTexture(ImageData *data, const Gfx::TextureCreateParams ¶ms) = 0; + virtual Texture CreateTexture(ImageData *data, const TextureCreateParams ¶ms) = 0; //! Deletes a given texture, freeing it from video memory - virtual void DestroyTexture(const Gfx::Texture &texture) = 0; + virtual void DestroyTexture(const Texture &texture) = 0; //! Deletes all textures created so far virtual void DestroyAllTextures() = 0; //! Returns the maximum number of multitexture stages virtual int GetMaxTextureCount() = 0; //! Sets the texture at given texture stage - virtual void SetTexture(int index, const Gfx::Texture &texture) = 0; + virtual void SetTexture(int index, const Texture &texture) = 0; //! Sets the texture image by ID at given texture stage virtual void SetTexture(int index, unsigned int textureId) = 0; //! Returns the (multi)texture at given index - virtual Gfx::Texture GetTexture(int index) = 0; + virtual Texture GetTexture(int index) = 0; //! Enables/disables the given texture stage virtual void SetTextureEnabled(int index, bool enabled) = 0; //! Returns the current enable state of given texture stage virtual bool GetTextureEnabled(int index) = 0; //! Sets the params for texture stage with given index - virtual void SetTextureStageParams(int index, const Gfx::TextureStageParams ¶ms) = 0; + virtual void SetTextureStageParams(int index, const TextureStageParams ¶ms) = 0; //! Returns the current params of texture stage with given index - virtual Gfx::TextureStageParams GetTextureStageParams(int index) = 0; + virtual TextureStageParams GetTextureStageParams(int index) = 0; //! Sets the texture factor to the given color value - virtual void SetTextureFactor(const Gfx::Color &color) = 0; + virtual void SetTextureFactor(const Color &color) = 0; //! Returns the current texture factor - virtual Gfx::Color GetTextureFactor() = 0; + virtual Color GetTextureFactor() = 0; //! Renders primitive composed of vertices with single texture - virtual void DrawPrimitive(Gfx::PrimitiveType type, const Gfx::Vertex *vertices , int vertexCount) = 0; + virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices , int vertexCount) = 0; //! Renders primitive composed of vertices with color information and single texture - virtual void DrawPrimitive(Gfx::PrimitiveType type, const Gfx::VertexCol *vertices , int vertexCount) = 0; + virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices , int vertexCount) = 0; //! Renders primitive composed of vertices with multitexturing (2 textures) - virtual void DrawPrimitive(Gfx::PrimitiveType type, const Gfx::VertexTex2 *vertices, int vertexCount) = 0; + virtual void DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, int vertexCount) = 0; //! Tests whether a sphere intersects the 6 clipping planes of projection volume virtual int ComputeSphereVisibility(const Math::Vector ¢er, float radius) = 0; //! Enables/disables the given render state - virtual void SetRenderState(Gfx::RenderState state, bool enabled) = 0; + virtual void SetRenderState(RenderState state, bool enabled) = 0; //! Returns the current setting of given render state - virtual bool GetRenderState(Gfx::RenderState state) = 0; + virtual bool GetRenderState(RenderState state) = 0; //! Sets the function of depth test - virtual void SetDepthTestFunc(Gfx::CompFunc func) = 0; + virtual void SetDepthTestFunc(CompFunc func) = 0; //! Returns the current function of depth test - virtual Gfx::CompFunc GetDepthTestFunc() = 0; + virtual CompFunc GetDepthTestFunc() = 0; //! Sets the depth bias (constant value added to Z-coords) virtual void SetDepthBias(float factor) = 0; @@ -375,44 +336,45 @@ public: virtual float GetDepthBias() = 0; //! Sets the alpha test function and reference value - virtual void SetAlphaTestFunc(Gfx::CompFunc func, float refValue) = 0; + virtual void SetAlphaTestFunc(CompFunc func, float refValue) = 0; //! Returns the current alpha test function and reference value - virtual void GetAlphaTestFunc(Gfx::CompFunc &func, float &refValue) = 0; + virtual void GetAlphaTestFunc(CompFunc &func, float &refValue) = 0; //! Sets the blending functions for source and destination operations - virtual void SetBlendFunc(Gfx::BlendFunc srcBlend, Gfx::BlendFunc dstBlend) = 0; + virtual void SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend) = 0; //! Returns the current blending functions for source and destination operations - virtual void GetBlendFunc(Gfx::BlendFunc &srcBlend, Gfx::BlendFunc &dstBlend) = 0; + virtual void GetBlendFunc(BlendFunc &srcBlend, BlendFunc &dstBlend) = 0; //! Sets the clear color - virtual void SetClearColor(const Gfx::Color &color) = 0; + virtual void SetClearColor(const Color &color) = 0; //! Returns the current clear color - virtual Gfx::Color GetClearColor() = 0; + virtual Color GetClearColor() = 0; //! Sets the global ambient color - virtual void SetGlobalAmbient(const Gfx::Color &color) = 0; + virtual void SetGlobalAmbient(const Color &color) = 0; //! Returns the global ambient color - virtual Gfx::Color GetGlobalAmbient() = 0; + virtual Color GetGlobalAmbient() = 0; //! Sets the fog parameters: mode, color, start distance, end distance and density (for exp models) - virtual void SetFogParams(Gfx::FogMode mode, const Gfx::Color &color, float start, float end, float density) = 0; + virtual void SetFogParams(FogMode mode, const Color &color, float start, float end, float density) = 0; //! Returns the current fog parameters: mode, color, start distance, end distance and density (for exp models) - virtual void GetFogParams(Gfx::FogMode &mode, Gfx::Color &color, float &start, float &end, float &density) = 0; + virtual void GetFogParams(FogMode &mode, Color &color, float &start, float &end, float &density) = 0; //! Sets the current cull mode - virtual void SetCullMode(Gfx::CullMode mode) = 0; + virtual void SetCullMode(CullMode mode) = 0; //! Returns the current cull mode - virtual Gfx::CullMode GetCullMode() = 0; + virtual CullMode GetCullMode() = 0; //! Sets the shade model - virtual void SetShadeModel(Gfx::ShadeModel model) = 0; + virtual void SetShadeModel(ShadeModel model) = 0; //! Returns the current shade model - virtual Gfx::ShadeModel GetShadeModel() = 0; + virtual ShadeModel GetShadeModel() = 0; //! Sets the current fill mode - virtual void SetFillMode(Gfx::FillMode mode) = 0; + virtual void SetFillMode(FillMode mode) = 0; //! Returns the current fill mode - virtual Gfx::FillMode GetFillMode() = 0; + virtual FillMode GetFillMode() = 0; }; -}; // namespace Gfx + +} // namespace Gfx diff --git a/src/graphics/core/light.h b/src/graphics/core/light.h index 0601c5b..35f37e6 100644 --- a/src/graphics/core/light.h +++ b/src/graphics/core/light.h @@ -24,14 +24,17 @@ #include "graphics/core/color.h" + #include "math/vector.h" +// Graphics module namespace namespace Gfx { /** - \enum LightType - \brief Type of light in 3D scene */ + * \enum LightType + * \brief Type of light in 3D scene + */ enum LightType { LIGHT_POINT, @@ -40,20 +43,21 @@ enum LightType }; /** - \struct Light - \brief Properties of light in 3D scene - - This structure was created as analog to DirectX's D3DLIGHT. */ + * \struct Light + * \brief Properties of light in 3D scene + * + * This structure was created as analog to DirectX's D3DLIGHT. + */ struct Light { //! Type of light source - Gfx::LightType type; + LightType type; //! Color of ambient light - Gfx::Color ambient; + Color ambient; //! Color of diffuse light - Gfx::Color diffuse; + Color diffuse; //! Color of specular light - Gfx::Color specular; + Color specular; //! Position in world space (for point & spot lights) Math::Vector position; //! Direction in world space (for directional & spot lights) @@ -80,9 +84,9 @@ struct Light void LoadDefault() { type = LIGHT_POINT; - ambient = Gfx::Color(0.4f, 0.4f, 0.4f); - diffuse = Gfx::Color(0.8f, 0.8f, 0.8f); - specular = Gfx::Color(1.0f, 1.0f, 1.0f); + ambient = Color(0.4f, 0.4f, 0.4f); + diffuse = Color(0.8f, 0.8f, 0.8f); + specular = Color(1.0f, 1.0f, 1.0f); position = Math::Vector(0.0f, 0.0f, 0.0f); direction = Math::Vector(0.0f, 0.0f, 1.0f); attenuation0 = 1.0f; @@ -92,4 +96,5 @@ struct Light } }; -}; // namespace Gfx + +} // namespace Gfx diff --git a/src/graphics/core/material.h b/src/graphics/core/material.h index 156ff36..07782d5 100644 --- a/src/graphics/core/material.h +++ b/src/graphics/core/material.h @@ -25,6 +25,7 @@ #include "graphics/core/color.h" +// Graphics module namespace namespace Gfx { /** @@ -40,21 +41,22 @@ namespace Gfx { struct Material { //! Diffuse color - Gfx::Color diffuse; + Color diffuse; //! Ambient color - Gfx::Color ambient; + Color ambient; //! Specular color - Gfx::Color specular; + Color specular; - bool operator==(const Gfx::Material &mat) const + bool operator==(const Material &mat) const { return diffuse == mat.diffuse && ambient == mat.ambient && specular == mat.specular; } - bool operator!=(const Gfx::Material &mat) const + bool operator!=(const Material &mat) const { return ! operator==(mat); } }; -}; // namespace Gfx + +} // namespace Gfx diff --git a/src/graphics/core/texture.h b/src/graphics/core/texture.h index 8abe86a..e9117e2 100644 --- a/src/graphics/core/texture.h +++ b/src/graphics/core/texture.h @@ -21,14 +21,17 @@ #pragma once + #include "math/intpoint.h" +// Graphics module namespace namespace Gfx { /** - \enum TexImgFormat - \brief Format of image data */ + * \enum TexImgFormat + * \brief Format of image data + */ enum TexImgFormat { //! Try to determine automatically (may not work) @@ -44,10 +47,11 @@ enum TexImgFormat }; /** - \enum TexMinFilter - \brief Texture minification filter - - Corresponds to OpenGL modes but should translate to DirectX too. */ + * \enum TexMinFilter + * \brief Texture minification filter + * + * Corresponds to OpenGL modes but should translate to DirectX too. + */ enum TexMinFilter { TEX_MIN_FILTER_NEAREST, @@ -59,8 +63,9 @@ enum TexMinFilter }; /** - \enum TexMagFilter - \brief Texture magnification filter */ + * \enum TexMagFilter + * \brief Texture magnification filter + */ enum TexMagFilter { TEX_MAG_FILTER_NEAREST, @@ -68,8 +73,9 @@ enum TexMagFilter }; /** - \enum TexWrapMode - \brief Wrapping mode for texture coords */ + * \enum TexWrapMode + * \brief Wrapping mode for texture coords + */ enum TexWrapMode { TEX_WRAP_CLAMP, @@ -77,8 +83,9 @@ enum TexWrapMode }; /** - \enum TexMixOperation - \brief Multitexture mixing operation */ + * \enum TexMixOperation + * \brief Multitexture mixing operation + */ enum TexMixOperation { //! Default operation on default params (modulate on computed & texture) @@ -94,8 +101,9 @@ enum TexMixOperation }; /** - \enum TexMixArgument - \brief Multitexture mixing argument */ + * \enum TexMixArgument + * \brief Multitexture mixing argument + */ enum TexMixArgument { //! Color from current texture @@ -119,11 +127,11 @@ struct TextureCreateParams //! Whether to generate mipmaps bool mipmap; //! Format of source image data - Gfx::TexImgFormat format; + TexImgFormat format; //! Minification filter - Gfx::TexMinFilter minFilter; + TexMinFilter minFilter; //! Magnification filter - Gfx::TexMagFilter magFilter; + TexMagFilter magFilter; //! Constructor; calls LoadDefault() TextureCreateParams() @@ -132,11 +140,11 @@ struct TextureCreateParams //! Loads the default values inline void LoadDefault() { - format = Gfx::TEX_IMG_RGB; + format = TEX_IMG_RGB; mipmap = false; - minFilter = Gfx::TEX_MIN_FILTER_NEAREST; - magFilter = Gfx::TEX_MAG_FILTER_NEAREST; + minFilter = TEX_MIN_FILTER_NEAREST; + magFilter = TEX_MAG_FILTER_NEAREST; } }; @@ -149,21 +157,21 @@ struct TextureCreateParams struct TextureStageParams { //! Mixing operation done on color values - Gfx::TexMixOperation colorOperation; + TexMixOperation colorOperation; //! 1st argument of color operations - Gfx::TexMixArgument colorArg1; + TexMixArgument colorArg1; //! 2nd argument of color operations - Gfx::TexMixArgument colorArg2; + TexMixArgument colorArg2; //! Mixing operation done on alpha values - Gfx::TexMixOperation alphaOperation; + TexMixOperation alphaOperation; //! 1st argument of alpha operations - Gfx::TexMixArgument alphaArg1; + TexMixArgument alphaArg1; //! 2nd argument of alpha operations - Gfx::TexMixArgument alphaArg2; + TexMixArgument alphaArg2; //! Wrap mode for 1st tex coord - Gfx::TexWrapMode wrapS; + TexWrapMode wrapS; //! Wrap mode for 2nd tex coord - Gfx::TexWrapMode wrapT; + TexWrapMode wrapT; //! Constructor; calls LoadDefault() TextureStageParams() @@ -172,15 +180,15 @@ struct TextureStageParams //! Loads the default values inline void LoadDefault() { - colorOperation = Gfx::TEX_MIX_OPER_DEFAULT; - colorArg1 = Gfx::TEX_MIX_ARG_COMPUTED_COLOR; - colorArg2 = Gfx::TEX_MIX_ARG_TEXTURE; + colorOperation = TEX_MIX_OPER_DEFAULT; + colorArg1 = TEX_MIX_ARG_COMPUTED_COLOR; + colorArg2 = TEX_MIX_ARG_TEXTURE; - alphaOperation = Gfx::TEX_MIX_OPER_DEFAULT; - alphaArg1 = Gfx::TEX_MIX_ARG_COMPUTED_COLOR; - alphaArg2 = Gfx::TEX_MIX_ARG_TEXTURE; + alphaOperation = TEX_MIX_OPER_DEFAULT; + alphaArg1 = TEX_MIX_ARG_COMPUTED_COLOR; + alphaArg2 = TEX_MIX_ARG_TEXTURE; - wrapS = wrapT = Gfx::TEX_WRAP_REPEAT; + wrapS = wrapT = TEX_WRAP_REPEAT; } }; @@ -218,7 +226,7 @@ struct Texture } //! Comparator for use in texture maps and sets - inline bool operator<(const Gfx::Texture &other) const + inline bool operator<(const Texture &other) const { // Invalid textures are always "less than" every other texture @@ -235,7 +243,7 @@ struct Texture } //! Comparator - inline bool operator==(const Gfx::Texture &other) const + inline bool operator==(const Texture &other) const { if (Valid() != other.Valid()) return false; @@ -246,4 +254,5 @@ struct Texture } }; -}; // namespace Gfx + +} // namespace Gfx diff --git a/src/graphics/core/vertex.h b/src/graphics/core/vertex.h index a99d618..9ab4dbb 100644 --- a/src/graphics/core/vertex.h +++ b/src/graphics/core/vertex.h @@ -23,11 +23,14 @@ #include "graphics/core/color.h" + #include "math/vector.h" #include "math/point.h" #include <sstream> + +// Graphics module namespace namespace Gfx { /** @@ -72,20 +75,20 @@ struct Vertex * * It contains: * - vertex coordinates (x,y,z) as Math::Vector, - * - RGBA color as Gfx::Color, - * - RGBA specular color as Gfx::Color, + * - RGBA color as Color, + * - RGBA specular color as Color, * - texture coordinates (u,v) as Math::Point. */ struct VertexCol { Math::Vector coord; - Gfx::Color color; - Gfx::Color specular; + Color color; + Color specular; Math::Point texCoord; explicit VertexCol(Math::Vector aCoord = Math::Vector(), - Gfx::Color aColor = Gfx::Color(), - Gfx::Color aSpecular = Gfx::Color(), + Color aColor = Color(), + Color aSpecular = Color(), Math::Point aTexCoord = Math::Point()) : coord(aCoord), color(aColor), specular(aSpecular), texCoord(aTexCoord) {} @@ -105,7 +108,7 @@ struct VertexCol * \struct VertexTex2 * \brief Vertex with secondary texture coordinates * - * In addition to fields from Gfx::Vector, it contains + * In addition to fields from Vector, it contains * secondary texture coordinates (u2, v2) as Math::Point */ struct VertexTex2 @@ -121,8 +124,8 @@ struct VertexTex2 Math::Point aTexCoord2 = Math::Point()) : coord(aCoord), normal(aNormal), texCoord(aTexCoord), texCoord2(aTexCoord2) {} - //! Sets the fields from Gfx::Vertex with texCoord2 = (0,0) - void FromVertex(const Gfx::Vertex &v) + //! Sets the fields from Vertex with texCoord2 = (0,0) + void FromVertex(const Vertex &v) { coord = v.coord; normal = v.normal; @@ -141,4 +144,5 @@ struct VertexTex2 } }; -}; // namespace Gfx + +} // namespace Gfx diff --git a/src/graphics/engine/camera.cpp b/src/graphics/engine/camera.cpp index cd7e307..23131ef 100644 --- a/src/graphics/engine/camera.cpp +++ b/src/graphics/engine/camera.cpp @@ -15,19 +15,27 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// camera.cpp #include "graphics/engine/camera.h" #include "common/iman.h" + #include "graphics/engine/engine.h" #include "graphics/engine/terrain.h" #include "graphics/engine/water.h" + #include "math/const.h" #include "math/geometry.h" + #include "object/object.h" + #include "physics/physics.h" + +// Graphics module namespace +namespace Gfx { + + //! Changes the level of transparency of an object and objects transported (battery & cargo) void SetTransparency(CObject* obj, float value) { @@ -44,17 +52,17 @@ void SetTransparency(CObject* obj, float value) -Gfx::CCamera::CCamera(CInstanceManager* iMan) +CCamera::CCamera(CInstanceManager* iMan) { m_iMan = iMan; m_iMan->AddInstance(CLASS_CAMERA, this); - m_engine = static_cast<Gfx::CEngine*> ( m_iMan->SearchInstance(CLASS_ENGINE) ); - m_terrain = static_cast<Gfx::CTerrain*>( m_iMan->SearchInstance(CLASS_TERRAIN) ); - m_water = static_cast<Gfx::CWater*> ( m_iMan->SearchInstance(CLASS_WATER) ); + m_engine = static_cast<CEngine*> ( m_iMan->SearchInstance(CLASS_ENGINE) ); + m_terrain = static_cast<CTerrain*>( m_iMan->SearchInstance(CLASS_TERRAIN) ); + m_water = static_cast<CWater*> ( m_iMan->SearchInstance(CLASS_WATER) ); - m_type = Gfx::CAM_TYPE_FREE; - m_smooth = Gfx::CAM_SMOOTH_NORM; + m_type = CAM_TYPE_FREE; + m_smooth = CAM_SMOOTH_NORM; m_cameraObj = 0; m_eyeDistance = 10.0f; @@ -93,7 +101,7 @@ Gfx::CCamera::CCamera(CInstanceManager* iMan) m_visitGoal = Math::Vector(0.0f, 0.0f, 0.0f); m_visitDist = 0.0f; m_visitTime = 0.0f; - m_visitType = Gfx::CAM_TYPE_NULL; + m_visitType = CAM_TYPE_NULL; m_visitDirectionH = 0.0f; m_visitDirectionV = 0.0f; @@ -108,7 +116,7 @@ Gfx::CCamera::CCamera(CInstanceManager* iMan) m_motorTurn = 0.0f; - m_centeringPhase = Gfx::CAM_PHASE_NULL; + m_centeringPhase = CAM_PHASE_NULL; m_centeringAngleH = 0.0f; m_centeringAngleV = 0.0f; m_centeringDist = 0.0f; @@ -117,7 +125,7 @@ Gfx::CCamera::CCamera(CInstanceManager* iMan) m_centeringTime = 0.0f; m_centeringProgress = 0.0f; - m_effectType = Gfx::CAM_EFFECT_NULL; + m_effectType = CAM_EFFECT_NULL; m_effectPos = Math::Vector(0.0f, 0.0f, 0.0f); m_effectForce = 0.0f; m_effectProgress = 0.0f; @@ -132,45 +140,45 @@ Gfx::CCamera::CCamera(CInstanceManager* iMan) m_cameraInvertY = false; } -Gfx::CCamera::~CCamera() +CCamera::~CCamera() { } -void Gfx::CCamera::SetEffect(bool enable) +void CCamera::SetEffect(bool enable) { m_effect = enable; } -void Gfx::CCamera::SetCameraScroll(bool scroll) +void CCamera::SetCameraScroll(bool scroll) { m_cameraScroll = scroll; } -void Gfx::CCamera::SetCameraInvertX(bool invert) +void CCamera::SetCameraInvertX(bool invert) { m_cameraInvertX = invert; } -void Gfx::CCamera::SetCameraInvertY(bool invert) +void CCamera::SetCameraInvertY(bool invert) { m_cameraInvertY = invert; } -float Gfx::CCamera::GetMotorTurn() +float CCamera::GetMotorTurn() { - if (m_type == Gfx::CAM_TYPE_BACK) + if (m_type == CAM_TYPE_BACK) return m_motorTurn; return 0.0f; } -void Gfx::CCamera::Init(Math::Vector eye, Math::Vector lookat, float delay) +void CCamera::Init(Math::Vector eye, Math::Vector lookat, float delay) { m_initDelay = delay; eye.y += m_terrain->GetFloorLevel(eye, true); lookat.y += m_terrain->GetFloorLevel(lookat, true); - m_type = Gfx::CAM_TYPE_FREE; + m_type = CAM_TYPE_FREE; m_eyePt = eye; m_directionH = Math::RotateAngle(eye.x - lookat.x, eye.z - lookat.z) + Math::PI / 2.0f; @@ -185,7 +193,7 @@ void Gfx::CCamera::Init(Math::Vector eye, Math::Vector lookat, float delay) m_fixDist = 50.0f; m_fixDirectionH = Math::PI*0.25f; m_fixDirectionV = -Math::PI*0.10f; - m_centeringPhase = Gfx::CAM_PHASE_NULL; + m_centeringPhase = CAM_PHASE_NULL; m_actualEye = m_eyePt; m_actualLookat = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, 50.0f); m_finalEye = m_actualEye; @@ -198,26 +206,26 @@ void Gfx::CCamera::Init(Math::Vector eye, Math::Vector lookat, float delay) FlushEffect(); FlushOver(); - SetType(Gfx::CAM_TYPE_FREE); + SetType(CAM_TYPE_FREE); } -void Gfx::CCamera::SetControllingObject(CObject* object) +void CCamera::SetControllingObject(CObject* object) { m_cameraObj = object; } -CObject* Gfx::CCamera::GetControllingObject() +CObject* CCamera::GetControllingObject() { return m_cameraObj; } -void Gfx::CCamera::SetType(CameraType type) +void CCamera::SetType(CameraType type) { m_remotePan = 0.0f; m_remoteZoom = 0.0f; - if ( (m_type == Gfx::CAM_TYPE_BACK) && m_transparency ) + if ( (m_type == CAM_TYPE_BACK) && m_transparency ) { for (int i = 0; i < 1000000; i++) { @@ -233,8 +241,8 @@ void Gfx::CCamera::SetType(CameraType type) } m_transparency = false; - if (type == Gfx::CAM_TYPE_INFO || - type == Gfx::CAM_TYPE_VISIT) // xx -> info ? + if (type == CAM_TYPE_INFO || + type == CAM_TYPE_VISIT) // xx -> info ? { m_normEye = m_engine->GetEyePt(); m_normLookat = m_engine->GetLookatPt(); @@ -244,8 +252,8 @@ void Gfx::CCamera::SetType(CameraType type) return; } - if (m_type == Gfx::CAM_TYPE_INFO || - m_type == Gfx::CAM_TYPE_VISIT) // info -> xx ? + if (m_type == CAM_TYPE_INFO || + m_type == CAM_TYPE_VISIT) // info -> xx ? { m_engine->SetFocus(m_focus); // gives initial focus m_type = type; @@ -255,33 +263,33 @@ void Gfx::CCamera::SetType(CameraType type) return; } - if ( m_type == Gfx::CAM_TYPE_BACK && type == Gfx::CAM_TYPE_FREE ) // back -> free ? + if ( m_type == CAM_TYPE_BACK && type == CAM_TYPE_FREE ) // back -> free ? m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, -50.0f); - if ( m_type == Gfx::CAM_TYPE_BACK && type == Gfx::CAM_TYPE_EDIT ) // back -> edit ? + if ( m_type == CAM_TYPE_BACK && type == CAM_TYPE_EDIT ) // back -> edit ? m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, -1.0f); - if ( m_type == Gfx::CAM_TYPE_ONBOARD && type == Gfx::CAM_TYPE_FREE ) // onboard -> free ? + if ( m_type == CAM_TYPE_ONBOARD && type == CAM_TYPE_FREE ) // onboard -> free ? m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, -30.0f); - if ( m_type == Gfx::CAM_TYPE_ONBOARD && type == Gfx::CAM_TYPE_EDIT ) // onboard -> edit ? + if ( m_type == CAM_TYPE_ONBOARD && type == CAM_TYPE_EDIT ) // onboard -> edit ? m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, -30.0f); - if ( m_type == Gfx::CAM_TYPE_ONBOARD && type == Gfx::CAM_TYPE_EXPLO ) // onboard -> explo ? + if ( m_type == CAM_TYPE_ONBOARD && type == CAM_TYPE_EXPLO ) // onboard -> explo ? m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, -50.0f); - if ( m_type == Gfx::CAM_TYPE_BACK && type == Gfx::CAM_TYPE_EXPLO ) // back -> explo ? + if ( m_type == CAM_TYPE_BACK && type == CAM_TYPE_EXPLO ) // back -> explo ? m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, -20.0f); - if ( type == Gfx::CAM_TYPE_FIX || - type == Gfx::CAM_TYPE_PLANE ) + if ( type == CAM_TYPE_FIX || + type == CAM_TYPE_PLANE ) AbortCentering(); // Special stops framing m_fixDist = 50.0f; - if ( type == Gfx::CAM_TYPE_PLANE ) + if ( type == CAM_TYPE_PLANE ) m_fixDist = 60.0f; - if ( type == Gfx::CAM_TYPE_BACK ) + if ( type == CAM_TYPE_BACK ) { AbortCentering(); // Special stops framing m_addDirectionH = 0.0f; @@ -317,10 +325,10 @@ void Gfx::CCamera::SetType(CameraType type) if ( oType == OBJECT_HUSTON ) m_backMin = 80.0f; } - if ( type != Gfx::CAM_TYPE_ONBOARD && m_cameraObj != 0 ) + if ( type != CAM_TYPE_ONBOARD && m_cameraObj != 0 ) m_cameraObj->SetGunGoalH(0.0f); // puts the cannon right - if ( type == Gfx::CAM_TYPE_ONBOARD ) + if ( type == CAM_TYPE_ONBOARD ) m_focus = 1.50f; // Wide else m_focus = 1.00f; // normal @@ -328,82 +336,82 @@ void Gfx::CCamera::SetType(CameraType type) m_type = type; - SetSmooth(Gfx::CAM_SMOOTH_NORM); + SetSmooth(CAM_SMOOTH_NORM); } -Gfx::CameraType Gfx::CCamera::GetType() +CameraType CCamera::GetType() { return m_type; } -void Gfx::CCamera::SetSmooth(CameraSmooth type) +void CCamera::SetSmooth(CameraSmooth type) { m_smooth = type; } -Gfx::CameraSmooth Gfx::CCamera::GetSmoth() +CameraSmooth CCamera::GetSmoth() { return m_smooth; } -void Gfx::CCamera::SetDist(float dist) +void CCamera::SetDist(float dist) { m_fixDist = dist; } -float Gfx::CCamera::GetDist() +float CCamera::GetDist() { return m_fixDist; } -void Gfx::CCamera::SetFixDirection(float angle) +void CCamera::SetFixDirection(float angle) { m_fixDirectionH = angle; } -float Gfx::CCamera::GetFixDirection() +float CCamera::GetFixDirection() { return m_fixDirectionH; } -void Gfx::CCamera::SetRemotePan(float value) +void CCamera::SetRemotePan(float value) { m_remotePan = value; } -float Gfx::CCamera::GetRemotePan() +float CCamera::GetRemotePan() { return m_remotePan; } -void Gfx::CCamera::SetRemoteZoom(float value) +void CCamera::SetRemoteZoom(float value) { value = Math::Norm(value); - if ( m_type == Gfx::CAM_TYPE_BACK ) + if ( m_type == CAM_TYPE_BACK ) m_backDist = m_backMin + (200.0f - m_backMin) * value; - if ( m_type == Gfx::CAM_TYPE_FIX || - m_type == Gfx::CAM_TYPE_PLANE ) + if ( m_type == CAM_TYPE_FIX || + m_type == CAM_TYPE_PLANE ) m_fixDist = 10.0f + (200.0f - 10.0f) * value; } -float Gfx::CCamera::GetRemoteZoom() +float CCamera::GetRemoteZoom() { - if ( m_type == Gfx::CAM_TYPE_BACK ) + if ( m_type == CAM_TYPE_BACK ) return (m_backDist - m_backMin) / (200.0f - m_backMin); - if ( m_type == Gfx::CAM_TYPE_FIX || - m_type == Gfx::CAM_TYPE_PLANE ) + if ( m_type == CAM_TYPE_FIX || + m_type == CAM_TYPE_PLANE ) return (m_fixDist - 10.0f) / (200.0f - 10.0f); return 0.0f; } -void Gfx::CCamera::StartVisit(Math::Vector goal, float dist) +void CCamera::StartVisit(Math::Vector goal, float dist) { m_visitType = m_type; - SetType(Gfx::CAM_TYPE_VISIT); + SetType(CAM_TYPE_VISIT); m_visitGoal = goal; m_visitDist = dist; m_visitTime = 0.0f; @@ -411,32 +419,32 @@ void Gfx::CCamera::StartVisit(Math::Vector goal, float dist) m_visitDirectionV = -Math::PI*0.10f; } -void Gfx::CCamera::StopVisit() +void CCamera::StopVisit() { SetType(m_visitType); // presents the initial type } -void Gfx::CCamera::GetCamera(Math::Vector &eye, Math::Vector &lookat) +void CCamera::GetCamera(Math::Vector &eye, Math::Vector &lookat) { eye = m_eyePt; lookat = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, 50.0f); } -bool Gfx::CCamera::StartCentering(CObject *object, float angleH, float angleV, +bool CCamera::StartCentering(CObject *object, float angleH, float angleV, float dist, float time) { - if (m_type != Gfx::CAM_TYPE_BACK) + if (m_type != CAM_TYPE_BACK) return false; if (object != m_cameraObj) return false; - if (m_centeringPhase != Gfx::CAM_PHASE_NULL) + if (m_centeringPhase != CAM_PHASE_NULL) return false; if (m_addDirectionH > Math::PI) angleH = Math::PI * 2.0f - angleH; - m_centeringPhase = Gfx::CAM_PHASE_START; + m_centeringPhase = CAM_PHASE_START; m_centeringAngleH = angleH; m_centeringAngleV = angleV; m_centeringDist = dist; @@ -448,18 +456,18 @@ bool Gfx::CCamera::StartCentering(CObject *object, float angleH, float angleV, return true; } -bool Gfx::CCamera::StopCentering(CObject *object, float time) +bool CCamera::StopCentering(CObject *object, float time) { - if (m_type != Gfx::CAM_TYPE_BACK) + if (m_type != CAM_TYPE_BACK) return false; if (object != m_cameraObj) return false; - if (m_centeringPhase != Gfx::CAM_PHASE_START && - m_centeringPhase != Gfx::CAM_PHASE_WAIT) + if (m_centeringPhase != CAM_PHASE_START && + m_centeringPhase != CAM_PHASE_WAIT) return false; - m_centeringPhase = Gfx::CAM_PHASE_STOP; + m_centeringPhase = CAM_PHASE_STOP; if (m_centeringAngleH != 99.9f) m_centeringAngleH = m_centeringCurrentH; @@ -473,16 +481,16 @@ bool Gfx::CCamera::StopCentering(CObject *object, float time) return true; } -void Gfx::CCamera::AbortCentering() +void CCamera::AbortCentering() { - if (m_type == Gfx::CAM_TYPE_INFO || - m_type == Gfx::CAM_TYPE_VISIT ) + if (m_type == CAM_TYPE_INFO || + m_type == CAM_TYPE_VISIT ) return; - if (m_centeringPhase == Gfx::CAM_PHASE_NULL) + if (m_centeringPhase == CAM_PHASE_NULL) return; - m_centeringPhase = Gfx::CAM_PHASE_NULL; + m_centeringPhase = CAM_PHASE_NULL; if ( m_centeringAngleH != 99.9f ) m_addDirectionH = m_centeringCurrentH; @@ -491,15 +499,15 @@ void Gfx::CCamera::AbortCentering() m_addDirectionV = m_centeringCurrentV; } -void Gfx::CCamera::FlushEffect() +void CCamera::FlushEffect() { - m_effectType = Gfx::CAM_EFFECT_NULL; + m_effectType = CAM_EFFECT_NULL; m_effectForce = 0.0f; m_effectProgress = 0.0f; m_effectOffset = Math::Vector(0.0f, 0.0f, 0.0f); } -void Gfx::CCamera::StartEffect(CameraEffect effect, Math::Vector pos, float force) +void CCamera::StartEffect(CameraEffect effect, Math::Vector pos, float force) { if ( !m_effect ) return; @@ -509,20 +517,20 @@ void Gfx::CCamera::StartEffect(CameraEffect effect, Math::Vector pos, float forc m_effectProgress = 0.0f; } -void Gfx::CCamera::EffectFrame(const Event &event) +void CCamera::EffectFrame(const Event &event) { - if (m_type == Gfx::CAM_TYPE_INFO || - m_type == Gfx::CAM_TYPE_VISIT) + if (m_type == CAM_TYPE_INFO || + m_type == CAM_TYPE_VISIT) return; - if (m_effectType == Gfx::CAM_EFFECT_NULL) + if (m_effectType == CAM_EFFECT_NULL) return; m_effectOffset = Math::Vector(0.0f, 0.0f, 0.0f); float force = m_effectForce; - if ( m_effectType == Gfx::CAM_EFFECT_TERRAFORM ) + if ( m_effectType == CAM_EFFECT_TERRAFORM ) { m_effectProgress += event.rTime * 0.7f; m_effectOffset.x = (Math::Rand() - 0.5f) * 10.0f; @@ -532,7 +540,7 @@ void Gfx::CCamera::EffectFrame(const Event &event) force *= 1.0f-m_effectProgress; } - if ( m_effectType == Gfx::CAM_EFFECT_EXPLO ) + if ( m_effectType == CAM_EFFECT_EXPLO ) { m_effectProgress += event.rTime * 1.0f; m_effectOffset.x = (Math::Rand() - 0.5f) *5.0f; @@ -542,7 +550,7 @@ void Gfx::CCamera::EffectFrame(const Event &event) force *= 1.0f-m_effectProgress; } - if ( m_effectType == Gfx::CAM_EFFECT_SHOT ) + if ( m_effectType == CAM_EFFECT_SHOT ) { m_effectProgress += event.rTime * 1.0f; m_effectOffset.x = (Math::Rand() - 0.5f) * 2.0f; @@ -552,7 +560,7 @@ void Gfx::CCamera::EffectFrame(const Event &event) force *= 1.0f-m_effectProgress; } - if ( m_effectType == Gfx::CAM_EFFECT_CRASH ) + if ( m_effectType == CAM_EFFECT_CRASH ) { m_effectProgress += event.rTime * 5.0f; m_effectOffset.y = sinf(m_effectProgress * Math::PI) * 1.5f; @@ -560,7 +568,7 @@ void Gfx::CCamera::EffectFrame(const Event &event) m_effectOffset.z = (Math::Rand() - 0.5f) * 1.0f * (1.0f - m_effectProgress); } - if ( m_effectType == Gfx::CAM_EFFECT_VIBRATION ) + if ( m_effectType == CAM_EFFECT_VIBRATION ) { m_effectProgress += event.rTime * 0.1f; m_effectOffset.y = (Math::Rand() - 0.5f) * 1.0f * (1.0f - m_effectProgress); @@ -568,7 +576,7 @@ void Gfx::CCamera::EffectFrame(const Event &event) m_effectOffset.z = (Math::Rand() - 0.5f) * 1.0f * (1.0f - m_effectProgress); } - if ( m_effectType == Gfx::CAM_EFFECT_PET ) + if ( m_effectType == CAM_EFFECT_PET ) { m_effectProgress += event.rTime *5.0f; m_effectOffset.x = (Math::Rand() - 0.5f) * 0.2f; @@ -589,25 +597,25 @@ void Gfx::CCamera::EffectFrame(const Event &event) FlushEffect(); } -void Gfx::CCamera::FlushOver() +void CCamera::FlushOver() { - m_overType = Gfx::CAM_OVER_EFFECT_NULL; - m_overColorBase = Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f); // black + m_overType = CAM_OVER_EFFECT_NULL; + m_overColorBase = Color(0.0f, 0.0f, 0.0f, 0.0f); // black m_engine->SetOverColor(); // nothing } -void Gfx::CCamera::SetOverBaseColor(Gfx::Color color) +void CCamera::SetOverBaseColor(Color color) { m_overColorBase = color; } -void Gfx::CCamera::StartOver(Gfx::CameraOverEffect effect, Math::Vector pos, float force) +void CCamera::StartOver(CameraOverEffect effect, Math::Vector pos, float force) { m_overType = effect; m_overTime = 0.0f; float decay; - if (m_overType == Gfx::CAM_OVER_EFFECT_LIGHTNING) + if (m_overType == CAM_OVER_EFFECT_LIGHTNING) decay = 400.0f; else decay = 100.0f; @@ -619,70 +627,70 @@ void Gfx::CCamera::StartOver(Gfx::CameraOverEffect effect, Math::Vector pos, flo m_overForce = force * (1.0f - dist); - if (m_overType == Gfx::CAM_OVER_EFFECT_BLOOD) + if (m_overType == CAM_OVER_EFFECT_BLOOD) { - m_overColor = Gfx::Color(0.8f, 0.1f, 0.1f); // red - m_overMode = Gfx::ENG_RSTATE_TCOLOR_BLACK; + m_overColor = Color(0.8f, 0.1f, 0.1f); // red + m_overMode = ENG_RSTATE_TCOLOR_BLACK; m_overFadeIn = 0.4f; m_overFadeOut = 0.8f; m_overForce = 1.0f; } - if ( m_overType == Gfx::CAM_OVER_EFFECT_FADEIN_WHITE ) + if ( m_overType == CAM_OVER_EFFECT_FADEIN_WHITE ) { - m_overColor = Gfx::Color(1.0f, 1.0f, 1.0f); // white - m_overMode = Gfx::ENG_RSTATE_TCOLOR_BLACK; + m_overColor = Color(1.0f, 1.0f, 1.0f); // white + m_overMode = ENG_RSTATE_TCOLOR_BLACK; m_overFadeIn = 0.0f; m_overFadeOut = 20.0f; m_overForce = 1.0f; } - if ( m_overType == Gfx::CAM_OVER_EFFECT_FADEOUT_WHITE ) + if ( m_overType == CAM_OVER_EFFECT_FADEOUT_WHITE ) { - m_overColor = Gfx::Color(1.0f, 1.0f, 1.0f); // white - m_overMode = Gfx::ENG_RSTATE_TCOLOR_BLACK; + m_overColor = Color(1.0f, 1.0f, 1.0f); // white + m_overMode = ENG_RSTATE_TCOLOR_BLACK; m_overFadeIn = 6.0f; m_overFadeOut = 100000.0f; m_overForce = 1.0f; } - if ( m_overType == Gfx::CAM_OVER_EFFECT_FADEOUT_BLACK ) + if ( m_overType == CAM_OVER_EFFECT_FADEOUT_BLACK ) { m_overColor = m_engine->GetFogColor(1); // fog color underwater - m_overMode = Gfx::ENG_RSTATE_TTEXTURE_WHITE; + m_overMode = ENG_RSTATE_TTEXTURE_WHITE; m_overFadeIn = 4.0f; m_overFadeOut = 100000.0f; m_overForce = 1.0f; } - if ( m_overType == Gfx::CAM_OVER_EFFECT_LIGHTNING ) + if ( m_overType == CAM_OVER_EFFECT_LIGHTNING ) { - m_overColor = Gfx::Color(0.9f, 1.0f, 1.0f); // white-cyan - m_overMode = Gfx::ENG_RSTATE_TCOLOR_BLACK; + m_overColor = Color(0.9f, 1.0f, 1.0f); // white-cyan + m_overMode = ENG_RSTATE_TCOLOR_BLACK; m_overFadeIn = 0.0f; m_overFadeOut = 1.0f; } } -void Gfx::CCamera::OverFrame(const Event &event) +void CCamera::OverFrame(const Event &event) { - if (m_type == Gfx::CAM_TYPE_INFO || - m_type == Gfx::CAM_TYPE_VISIT) + if (m_type == CAM_TYPE_INFO || + m_type == CAM_TYPE_VISIT) return; - if (m_overType == Gfx::CAM_OVER_EFFECT_NULL) + if (m_overType == CAM_OVER_EFFECT_NULL) return; m_overTime += event.rTime; - if (m_overType == Gfx::CAM_OVER_EFFECT_LIGHTNING) + if (m_overType == CAM_OVER_EFFECT_LIGHTNING) { - Gfx::Color color; + Color color; if (rand() % 2 == 0) { color.r = m_overColor.r * m_overForce; @@ -691,7 +699,7 @@ void Gfx::CCamera::OverFrame(const Event &event) } else { - color = Gfx::Color(0.0f, 0.0f, 0.0f); + color = Color(0.0f, 0.0f, 0.0f); } color.a = 0.0f; m_engine->SetOverColor(color, m_overMode); @@ -703,8 +711,8 @@ void Gfx::CCamera::OverFrame(const Event &event) float intensity = m_overTime / m_overFadeIn; intensity *= m_overForce; - Gfx::Color color; - if (m_overMode == Gfx::ENG_RSTATE_TCOLOR_WHITE) + Color color; + if (m_overMode == ENG_RSTATE_TCOLOR_WHITE) { color.r = 1.0f - (1.0f - m_overColor.r) * intensity; color.g = 1.0f - (1.0f - m_overColor.g) * intensity; @@ -728,8 +736,8 @@ void Gfx::CCamera::OverFrame(const Event &event) float intensity = 1.0f - (m_overTime - m_overFadeIn) / m_overFadeOut; intensity *= m_overForce; - Gfx::Color color; - if (m_overMode == Gfx::ENG_RSTATE_TCOLOR_WHITE) + Color color; + if (m_overMode == ENG_RSTATE_TCOLOR_WHITE) { color.r = 1.0f-(1.0f-m_overColor.r) * intensity; color.g = 1.0f-(1.0f-m_overColor.g) * intensity; @@ -757,7 +765,7 @@ void Gfx::CCamera::OverFrame(const Event &event) } } -void Gfx::CCamera::FixCamera() +void CCamera::FixCamera() { m_initDelay = 0.0f; m_actualEye = m_finalEye = m_scriptEye; @@ -765,13 +773,13 @@ void Gfx::CCamera::FixCamera() SetViewTime(m_scriptEye, m_scriptLookat, 0.0f); } -void Gfx::CCamera::SetViewTime(const Math::Vector &eyePt, +void CCamera::SetViewTime(const Math::Vector &eyePt, const Math::Vector &lookatPt, float rTime) { Math::Vector eye, lookat; - if (m_type == Gfx::CAM_TYPE_INFO) + if (m_type == CAM_TYPE_INFO) { eye = eyePt; lookat = lookatPt; @@ -797,10 +805,10 @@ void Gfx::CCamera::SetViewTime(const Math::Vector &eyePt, float prog = 0.0f; float dist = Math::Distance(m_finalEye, m_actualEye); - if (m_smooth == Gfx::CAM_SMOOTH_NONE) prog = dist; - if (m_smooth == Gfx::CAM_SMOOTH_NORM) prog = powf(dist, 1.5f) * rTime * 0.5f; - if (m_smooth == Gfx::CAM_SMOOTH_HARD) prog = powf(dist, 1.0f) * rTime * 4.0f; - if (m_smooth == Gfx::CAM_SMOOTH_SPEC) prog = powf(dist, 1.0f) * rTime * 0.05f; + if (m_smooth == CAM_SMOOTH_NONE) prog = dist; + if (m_smooth == CAM_SMOOTH_NORM) prog = powf(dist, 1.5f) * rTime * 0.5f; + if (m_smooth == CAM_SMOOTH_HARD) prog = powf(dist, 1.0f) * rTime * 4.0f; + if (m_smooth == CAM_SMOOTH_SPEC) prog = powf(dist, 1.0f) * rTime * 0.05f; if (dist == 0.0f) { m_actualEye = m_finalEye; @@ -813,10 +821,10 @@ void Gfx::CCamera::SetViewTime(const Math::Vector &eyePt, } dist = Math::Distance(m_finalLookat, m_actualLookat); - if ( m_smooth == Gfx::CAM_SMOOTH_NONE ) prog = dist; - if ( m_smooth == Gfx::CAM_SMOOTH_NORM ) prog = powf(dist, 1.5f) * rTime * 2.0f; - if ( m_smooth == Gfx::CAM_SMOOTH_HARD ) prog = powf(dist, 1.0f) * rTime * 4.0f; - if ( m_smooth == Gfx::CAM_SMOOTH_SPEC ) prog = powf(dist, 1.0f) * rTime * 4.0f; + if ( m_smooth == CAM_SMOOTH_NONE ) prog = dist; + if ( m_smooth == CAM_SMOOTH_NORM ) prog = powf(dist, 1.5f) * rTime * 2.0f; + if ( m_smooth == CAM_SMOOTH_HARD ) prog = powf(dist, 1.0f) * rTime * 4.0f; + if ( m_smooth == CAM_SMOOTH_SPEC ) prog = powf(dist, 1.0f) * rTime * 4.0f; if ( dist == 0.0f ) { m_actualLookat = m_finalLookat; @@ -842,15 +850,15 @@ void Gfx::CCamera::SetViewTime(const Math::Vector &eyePt, SetViewParams(eye, lookat, upVec); } -bool Gfx::CCamera::IsCollision(Math::Vector &eye, Math::Vector lookat) +bool CCamera::IsCollision(Math::Vector &eye, Math::Vector lookat) { - if (m_type == Gfx::CAM_TYPE_BACK ) return IsCollisionBack(eye, lookat); - if (m_type == Gfx::CAM_TYPE_FIX ) return IsCollisionFix (eye, lookat); - if (m_type == Gfx::CAM_TYPE_PLANE) return IsCollisionFix (eye, lookat); + if (m_type == CAM_TYPE_BACK ) return IsCollisionBack(eye, lookat); + if (m_type == CAM_TYPE_FIX ) return IsCollisionFix (eye, lookat); + if (m_type == CAM_TYPE_PLANE) return IsCollisionFix (eye, lookat); return false; } -bool Gfx::CCamera::IsCollisionBack(Math::Vector &eye, Math::Vector lookat) +bool CCamera::IsCollisionBack(Math::Vector &eye, Math::Vector lookat) { ObjectType iType; if (m_cameraObj == NULL) @@ -945,7 +953,7 @@ bool Gfx::CCamera::IsCollisionBack(Math::Vector &eye, Math::Vector lookat) return false; } -bool Gfx::CCamera::IsCollisionFix(Math::Vector &eye, Math::Vector lookat) +bool CCamera::IsCollisionFix(Math::Vector &eye, Math::Vector lookat) { for (int i = 0; i < 1000000; i++) { @@ -990,7 +998,7 @@ bool Gfx::CCamera::IsCollisionFix(Math::Vector &eye, Math::Vector lookat) return false; } -bool Gfx::CCamera::EventProcess(const Event &event) +bool CCamera::EventProcess(const Event &event) { switch (event.type) { @@ -1012,15 +1020,15 @@ bool Gfx::CCamera::EventProcess(const Event &event) return true; } -bool Gfx::CCamera::EventMouseMove(const Event &event) +bool CCamera::EventMouseMove(const Event &event) { m_mousePos = event.pos; return true; } -void Gfx::CCamera::EventMouseWheel(WheelDirection dir) +void CCamera::EventMouseWheel(WheelDirection dir) { - if (m_type == Gfx::CAM_TYPE_BACK) + if (m_type == CAM_TYPE_BACK) { if (dir == WHEEL_UP) { @@ -1036,8 +1044,8 @@ void Gfx::CCamera::EventMouseWheel(WheelDirection dir) } } - if ( m_type == Gfx::CAM_TYPE_FIX || - m_type == Gfx::CAM_TYPE_PLANE ) + if ( m_type == CAM_TYPE_FIX || + m_type == CAM_TYPE_PLANE ) { if (dir == WHEEL_UP) { @@ -1053,7 +1061,7 @@ void Gfx::CCamera::EventMouseWheel(WheelDirection dir) } } - if ( m_type == Gfx::CAM_TYPE_VISIT ) + if ( m_type == CAM_TYPE_VISIT ) { if (dir == WHEEL_UP) { @@ -1070,58 +1078,58 @@ void Gfx::CCamera::EventMouseWheel(WheelDirection dir) } } -bool Gfx::CCamera::EventFrame(const Event &event) +bool CCamera::EventFrame(const Event &event) { EffectFrame(event); OverFrame(event); - if (m_type == Gfx::CAM_TYPE_FREE) + if (m_type == CAM_TYPE_FREE) return EventFrameFree(event); - if (m_type == Gfx::CAM_TYPE_EDIT) + if (m_type == CAM_TYPE_EDIT) return EventFrameEdit(event); - if (m_type == Gfx::CAM_TYPE_DIALOG) + if (m_type == CAM_TYPE_DIALOG) return EventFrameDialog(event); - if (m_type == Gfx::CAM_TYPE_BACK) + if (m_type == CAM_TYPE_BACK) return EventFrameBack(event); - if (m_type == Gfx::CAM_TYPE_FIX || - m_type == Gfx::CAM_TYPE_PLANE) + if (m_type == CAM_TYPE_FIX || + m_type == CAM_TYPE_PLANE) return EventFrameFix(event); - if (m_type == Gfx::CAM_TYPE_EXPLO) + if (m_type == CAM_TYPE_EXPLO) return EventFrameExplo(event); - if (m_type == Gfx::CAM_TYPE_ONBOARD) + if (m_type == CAM_TYPE_ONBOARD) return EventFrameOnBoard(event); - if (m_type == Gfx::CAM_TYPE_SCRIPT) + if (m_type == CAM_TYPE_SCRIPT) return EventFrameScript(event); - if (m_type == Gfx::CAM_TYPE_INFO) + if (m_type == CAM_TYPE_INFO) return EventFrameInfo(event); - if (m_type == Gfx::CAM_TYPE_VISIT) + if (m_type == CAM_TYPE_VISIT) return EventFrameVisit(event); return true; } -Gfx::EngineMouseType Gfx::CCamera::GetMouseDef(Math::Point pos) +EngineMouseType CCamera::GetMouseDef(Math::Point pos) { - Gfx::EngineMouseType type = Gfx::ENG_MOUSE_NORM; + EngineMouseType type = ENG_MOUSE_NORM; m_mousePos = pos; - if (m_type == Gfx::CAM_TYPE_INFO) + if (m_type == CAM_TYPE_INFO) return type; if (m_rightDown) // the right button pressed? { m_rightPosMove.x = pos.x - m_rightPosCenter.x; m_rightPosMove.y = pos.y - m_rightPosCenter.y; - type = Gfx::ENG_MOUSE_MOVE; + type = ENG_MOUSE_MOVE; } else { @@ -1143,26 +1151,26 @@ Gfx::EngineMouseType Gfx::CCamera::GetMouseDef(Math::Point pos) if (pos.y > 1.0f-m_mouseMarging) m_mouseDirV = 1.0f - (1.0f - pos.y) / m_mouseMarging; - if ( m_type == Gfx::CAM_TYPE_FREE || - m_type == Gfx::CAM_TYPE_EDIT || - m_type == Gfx::CAM_TYPE_BACK || - m_type == Gfx::CAM_TYPE_FIX || - m_type == Gfx::CAM_TYPE_PLANE || - m_type == Gfx::CAM_TYPE_EXPLO ) + if ( m_type == CAM_TYPE_FREE || + m_type == CAM_TYPE_EDIT || + m_type == CAM_TYPE_BACK || + m_type == CAM_TYPE_FIX || + m_type == CAM_TYPE_PLANE || + m_type == CAM_TYPE_EXPLO ) { if (m_mouseDirH > 0.0f) - type = Gfx::ENG_MOUSE_SCROLLR; + type = ENG_MOUSE_SCROLLR; if (m_mouseDirH < 0.0f) - type = Gfx::ENG_MOUSE_SCROLLL; + type = ENG_MOUSE_SCROLLL; } - if ( m_type == Gfx::CAM_TYPE_FREE || - m_type == Gfx::CAM_TYPE_EDIT ) + if ( m_type == CAM_TYPE_FREE || + m_type == CAM_TYPE_EDIT ) { if (m_mouseDirV > 0.0f) - type = Gfx::ENG_MOUSE_SCROLLU; + type = ENG_MOUSE_SCROLLU; if (m_mouseDirV < 0.0f) - type = Gfx::ENG_MOUSE_SCROLLD; + type = ENG_MOUSE_SCROLLD; } if (m_cameraInvertX) @@ -1172,7 +1180,7 @@ Gfx::EngineMouseType Gfx::CCamera::GetMouseDef(Math::Point pos) return type; } -bool Gfx::CCamera::EventFrameFree(const Event &event) +bool CCamera::EventFrameFree(const Event &event) { float factor = m_heightEye * 0.5f + 30.0f; @@ -1235,7 +1243,7 @@ bool Gfx::CCamera::EventFrameFree(const Event &event) return true; } -bool Gfx::CCamera::EventFrameEdit(const Event &event) +bool CCamera::EventFrameEdit(const Event &event) { float factor = m_editHeight * 0.5f + 30.0f; @@ -1277,12 +1285,12 @@ bool Gfx::CCamera::EventFrameEdit(const Event &event) return true; } -bool Gfx::CCamera::EventFrameDialog(const Event &event) +bool CCamera::EventFrameDialog(const Event &event) { return true; } -bool Gfx::CCamera::EventFrameBack(const Event &event) +bool CCamera::EventFrameBack(const Event &event) { ObjectType type; if (m_cameraObj == NULL) @@ -1327,7 +1335,7 @@ bool Gfx::CCamera::EventFrameBack(const Event &event) float centeringV = 0.0f; float centeringD = 0.0f; - if (m_centeringPhase == Gfx::CAM_PHASE_START) + if (m_centeringPhase == CAM_PHASE_START) { m_centeringProgress += event.rTime / m_centeringTime; if (m_centeringProgress > 1.0f) m_centeringProgress = 1.0f; @@ -1335,17 +1343,17 @@ bool Gfx::CCamera::EventFrameBack(const Event &event) centeringV = m_centeringProgress; centeringD = m_centeringProgress; if (m_centeringProgress >= 1.0f) - m_centeringPhase = Gfx::CAM_PHASE_WAIT; + m_centeringPhase = CAM_PHASE_WAIT; } - if (m_centeringPhase == Gfx::CAM_PHASE_WAIT) + if (m_centeringPhase == CAM_PHASE_WAIT) { centeringH = 1.0f; centeringV = 1.0f; centeringD = 1.0f; } - if (m_centeringPhase == Gfx::CAM_PHASE_STOP) + if (m_centeringPhase == CAM_PHASE_STOP) { m_centeringProgress += event.rTime / m_centeringTime; if (m_centeringProgress > 1.0f) m_centeringProgress = 1.0f; @@ -1353,7 +1361,7 @@ bool Gfx::CCamera::EventFrameBack(const Event &event) centeringV = 1.0f-m_centeringProgress; centeringD = 1.0f-m_centeringProgress; if (m_centeringProgress >= 1.0f) - m_centeringPhase = Gfx::CAM_PHASE_NULL; + m_centeringPhase = CAM_PHASE_NULL; } if (m_centeringAngleH == 99.9f) centeringH = 0.0f; @@ -1437,7 +1445,7 @@ bool Gfx::CCamera::EventFrameBack(const Event &event) return true; } -bool Gfx::CCamera::EventFrameFix(const Event &event) +bool CCamera::EventFrameFix(const Event &event) { // +/-. if (event.keyState & KS_NUMPLUS) @@ -1470,7 +1478,7 @@ bool Gfx::CCamera::EventFrameFix(const Event &event) float d = m_fixDist; m_eyePt = RotateView(lookatPt, h, v, d); - if (m_type == Gfx::CAM_TYPE_PLANE) m_eyePt.y += m_fixDist / 2.0f; + if (m_type == CAM_TYPE_PLANE) m_eyePt.y += m_fixDist / 2.0f; m_eyePt = ExcludeTerrain(m_eyePt, lookatPt, h, v); m_eyePt = ExcludeObject(m_eyePt, lookatPt, h, v); @@ -1483,7 +1491,7 @@ bool Gfx::CCamera::EventFrameFix(const Event &event) return true; } -bool Gfx::CCamera::EventFrameExplo(const Event &event) +bool CCamera::EventFrameExplo(const Event &event) { if (m_mouseDirH != 0.0f) m_directionH -= m_mouseDirH * event.rTime * 0.7f * m_speed; @@ -1514,7 +1522,7 @@ bool Gfx::CCamera::EventFrameExplo(const Event &event) return true; } -bool Gfx::CCamera::EventFrameOnBoard(const Event &event) +bool CCamera::EventFrameOnBoard(const Event &event) { if (m_cameraObj != NULL) { @@ -1531,7 +1539,7 @@ bool Gfx::CCamera::EventFrameOnBoard(const Event &event) return true; } -bool Gfx::CCamera::EventFrameInfo(const Event &event) +bool CCamera::EventFrameInfo(const Event &event) { SetViewTime(Math::Vector(0.0f, 0.0f, 0.0f), Math::Vector(0.0f, 0.0f, 1.0f), @@ -1539,7 +1547,7 @@ bool Gfx::CCamera::EventFrameInfo(const Event &event) return true; } -bool Gfx::CCamera::EventFrameVisit(const Event &event) +bool CCamera::EventFrameVisit(const Event &event) { m_visitTime += event.rTime; @@ -1584,36 +1592,36 @@ bool Gfx::CCamera::EventFrameVisit(const Event &event) return true; } -bool Gfx::CCamera::EventFrameScript(const Event &event) +bool CCamera::EventFrameScript(const Event &event) { SetViewTime(m_scriptEye + m_effectOffset, m_scriptLookat + m_effectOffset, event.rTime); return true; } -void Gfx::CCamera::SetScriptEye(Math::Vector eye) +void CCamera::SetScriptEye(Math::Vector eye) { m_scriptEye = eye; } -void Gfx::CCamera::SetScriptLookat(Math::Vector lookat) +void CCamera::SetScriptLookat(Math::Vector lookat) { m_scriptLookat = lookat; } -void Gfx::CCamera::SetViewParams(const Math::Vector &eye, const Math::Vector &lookat, +void CCamera::SetViewParams(const Math::Vector &eye, const Math::Vector &lookat, const Math::Vector &up) { m_engine->SetViewParams(eye, lookat, up, m_eyeDistance); bool under = (eye.y < m_water->GetLevel()); // Is it underwater? - if (m_type == Gfx::CAM_TYPE_INFO) + if (m_type == CAM_TYPE_INFO) under = false; m_engine->SetRankView(under ? 1 : 0); } -Math::Vector Gfx::CCamera::ExcludeTerrain(Math::Vector eye, Math::Vector lookat, +Math::Vector CCamera::ExcludeTerrain(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV) { Math::Vector pos = eye; @@ -1630,7 +1638,7 @@ Math::Vector Gfx::CCamera::ExcludeTerrain(Math::Vector eye, Math::Vector lookat, return eye; } -Math::Vector Gfx::CCamera::ExcludeObject(Math::Vector eye, Math::Vector lookat, +Math::Vector CCamera::ExcludeObject(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV) { return eye; @@ -1657,3 +1665,5 @@ Math::Vector Gfx::CCamera::ExcludeObject(Math::Vector eye, Math::Vector lookat, return eye;*/ } + +} diff --git a/src/graphics/engine/camera.h b/src/graphics/engine/camera.h index 7a7350f..20d252d 100644 --- a/src/graphics/engine/camera.h +++ b/src/graphics/engine/camera.h @@ -17,18 +17,22 @@ /** * \file graphics/engine/camera.h - * \brief Camera handling - Gfx::CCamera class + * \brief Camera handling - CCamera class */ #pragma once -#include "engine.h" + #include "common/event.h" +#include "graphics/engine/engine.h" + class CInstanceManager; class CObject; + +// Graphics module namespace namespace Gfx { @@ -140,18 +144,18 @@ class CCamera { CObject* GetControllingObject(); //! Change the type of camera - void SetType(Gfx::CameraType type); - Gfx::CameraType GetType(); + void SetType(CameraType type); + CameraType GetType(); //! Management of the smoothing mode void SetSmooth(CameraSmooth type); - Gfx::CameraSmooth GetSmoth(); + CameraSmooth GetSmoth(); //! Management of the setback distance void SetDist(float dist); float GetDist(); - //! Manage angle mode Gfx::CAM_TYPE_FIX + //! Manage angle mode CAM_TYPE_FIX void SetFixDirection(float angle); float GetFixDirection(); @@ -181,13 +185,13 @@ class CCamera { //! Removes the special effect with the camera void FlushEffect(); //! Starts a special effect with the camera - void StartEffect(Gfx::CameraEffect effect, Math::Vector pos, float force); + void StartEffect(CameraEffect effect, Math::Vector pos, float force); //! Removes the effect of superposition in the foreground void FlushOver(); //! Specifies the base color - void SetOverBaseColor(Gfx::Color color); - void StartOver(Gfx::CameraOverEffect effect, Math::Vector pos, float force); + void SetOverBaseColor(Color color); + void StartOver(CameraOverEffect effect, Math::Vector pos, float force); //! Sets the soft movement of the camera void FixCamera(); @@ -202,7 +206,7 @@ class CCamera { //! Returns an additional force to turn float GetMotorTurn(); //! Returns the default sprite to use for the mouse - Gfx::EngineMouseType GetMouseDef(Math::Point pos); + EngineMouseType GetMouseDef(Math::Point pos); protected: //! Changes the camera according to the mouse moved @@ -255,14 +259,14 @@ protected: protected: CInstanceManager* m_iMan; - Gfx::CEngine* m_engine; - Gfx::CTerrain* m_terrain; - Gfx::CWater* m_water; + CEngine* m_engine; + CTerrain* m_terrain; + CWater* m_water; //! The type of camera - Gfx::CameraType m_type; + CameraType m_type; //! Type of smoothing - Gfx::CameraSmooth m_smooth; + CameraSmooth m_smooth; //! Object linked to the camera CObject* m_cameraObj; @@ -328,7 +332,7 @@ protected: //! CAM_TYPE_VISIT: relative time float m_visitTime; //! CAM_TYPE_VISIT: initial type - Gfx::CameraType m_visitType; + CameraType m_visitType; //! CAM_TYPE_VISIT: direction float m_visitDirectionH; //! CAM_TYPE_VISIT: direction @@ -347,7 +351,7 @@ protected: float m_motorTurn; - Gfx::CenteringPhase m_centeringPhase; + CenteringPhase m_centeringPhase; float m_centeringAngleH; float m_centeringAngleV; float m_centeringDist; @@ -356,17 +360,17 @@ protected: float m_centeringTime; float m_centeringProgress; - Gfx::CameraEffect m_effectType; + CameraEffect m_effectType; Math::Vector m_effectPos; float m_effectForce; float m_effectProgress; Math::Vector m_effectOffset; - Gfx::CameraOverEffect m_overType; + CameraOverEffect m_overType; float m_overForce; float m_overTime; - Gfx::Color m_overColorBase; - Gfx::Color m_overColor; + Color m_overColorBase; + Color m_overColor; int m_overMode; float m_overFadeIn; float m_overFadeOut; @@ -386,4 +390,4 @@ protected: }; -}; // namespace Gfx +} // namespace Gfx diff --git a/src/graphics/engine/cloud.cpp b/src/graphics/engine/cloud.cpp index 26a75ab..0df0d12 100644 --- a/src/graphics/engine/cloud.cpp +++ b/src/graphics/engine/cloud.cpp @@ -15,24 +15,29 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// cloud.cpp #include "graphics/engine/cloud.h" #include "common/iman.h" + #include "graphics/core/device.h" #include "graphics/engine/engine.h" #include "graphics/engine/terrain.h" + #include "math/geometry.h" +// Graphics module namespace +namespace Gfx { + + const int CLOUD_LINE_PREALLOCATE_COUNT = 100; //! Extension of the bricks dimensions const int CLOUD_SIZE_EXPAND = 4; -Gfx::CCloud::CCloud(CInstanceManager* iMan, Gfx::CEngine* engine) +CCloud::CCloud(CInstanceManager* iMan, CEngine* engine) { m_iMan = iMan; m_iMan->AddInstance(CLASS_CLOUD, this); @@ -48,14 +53,14 @@ Gfx::CCloud::CCloud(CInstanceManager* iMan, Gfx::CEngine* engine) m_lines.reserve(CLOUD_LINE_PREALLOCATE_COUNT); } -Gfx::CCloud::~CCloud() +CCloud::~CCloud() { m_iMan = nullptr; m_engine = nullptr; m_terrain = nullptr; } -bool Gfx::CCloud::EventProcess(const Event &event) +bool CCloud::EventProcess(const Event &event) { if ( event.type == EVENT_FRAME ) return EventFrame(event); @@ -63,7 +68,7 @@ bool Gfx::CCloud::EventProcess(const Event &event) return true; } -bool Gfx::CCloud::EventFrame(const Event &event) +bool CCloud::EventFrame(const Event &event) { if (m_engine->GetPause()) return true; @@ -78,7 +83,7 @@ bool Gfx::CCloud::EventFrame(const Event &event) return true; } -void Gfx::CCloud::AdjustLevel(Math::Vector& pos, Math::Vector& eye, float deep, +void CCloud::AdjustLevel(Math::Vector& pos, Math::Vector& eye, float deep, Math::Point& uv1, Math::Point& uv2) { uv1.x = (pos.x+20000.0f)/1280.0f; @@ -94,13 +99,13 @@ void Gfx::CCloud::AdjustLevel(Math::Vector& pos, Math::Vector& eye, float deep, pos.y -= m_level*factor*10.0f; } -void Gfx::CCloud::Draw() +void CCloud::Draw() { if (! m_enabled) return; if (m_level == 0.0f) return; if (m_lines.empty()) return; - std::vector<Gfx::VertexTex2> vertices((m_brickCount+2)*2, Gfx::VertexTex2()); + std::vector<VertexTex2> vertices((m_brickCount+2)*2, VertexTex2()); float iDeep = m_engine->GetDeepView(); float deep = (m_brickCount*m_brickSize)/2.0f; @@ -111,15 +116,15 @@ void Gfx::CCloud::Draw() float fogStart = deep*0.15f; float fogEnd = deep*0.24f; - Gfx::CDevice* device = m_engine->GetDevice(); + CDevice* device = m_engine->GetDevice(); // TODO: do this better? - device->SetFogParams(Gfx::FOG_LINEAR, m_engine->GetFogColor( m_engine->GetRankView() ), + device->SetFogParams(FOG_LINEAR, m_engine->GetFogColor( m_engine->GetRankView() ), fogStart, fogEnd, 1.0f); - device->SetTransform(Gfx::TRANSFORM_VIEW, m_engine->GetMatView()); + device->SetTransform(TRANSFORM_VIEW, m_engine->GetMatView()); - Gfx::Material material; + Material material; material.diffuse = m_diffuse; material.ambient = m_ambient; m_engine->SetMaterial(material); @@ -127,11 +132,11 @@ void Gfx::CCloud::Draw() m_engine->SetTexture(m_fileName, 0); m_engine->SetTexture(m_fileName, 1); - m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK | Gfx::ENG_RSTATE_FOG | Gfx::ENG_RSTATE_WRAP); + m_engine->SetState(ENG_RSTATE_TTEXTURE_BLACK | ENG_RSTATE_FOG | ENG_RSTATE_WRAP); Math::Matrix matrix; matrix.LoadIdentity(); - device->SetTransform(Gfx::TRANSFORM_WORLD, matrix); + device->SetTransform(TRANSFORM_WORLD, matrix); float size = m_brickSize/2.0f; Math::Vector eye = m_engine->GetEyePt(); @@ -154,13 +159,13 @@ void Gfx::CCloud::Draw() p.z = pos.z+size; p.y = pos.y; AdjustLevel(p, eye, deep, uv1, uv2); - vertices[vertexIndex++] = Gfx::VertexTex2(p, n, uv1, uv2); + vertices[vertexIndex++] = VertexTex2(p, n, uv1, uv2); p.x = pos.x-size; p.z = pos.z-size; p.y = pos.y; AdjustLevel(p, eye, deep, uv1, uv2); - vertices[vertexIndex++] = Gfx::VertexTex2(p, n, uv1, uv2); + vertices[vertexIndex++] = VertexTex2(p, n, uv1, uv2); for (int j = 0; j < m_lines[i].len; j++) { @@ -168,18 +173,18 @@ void Gfx::CCloud::Draw() p.z = pos.z+size; p.y = pos.y; AdjustLevel(p, eye, deep, uv1, uv2); - vertices[vertexIndex++] = Gfx::VertexTex2(p, n, uv1, uv2); + vertices[vertexIndex++] = VertexTex2(p, n, uv1, uv2); p.x = pos.x+size; p.z = pos.z-size; p.y = pos.y; AdjustLevel(p, eye, deep, uv1, uv2); - vertices[vertexIndex++] = Gfx::VertexTex2(p, n, uv1, uv2); + vertices[vertexIndex++] = VertexTex2(p, n, uv1, uv2); pos.x += size*2.0f; } - device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, &vertices[0], vertexIndex); + device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, &vertices[0], vertexIndex); m_engine->AddStatisticTriangle(vertexIndex - 2); } @@ -188,9 +193,9 @@ void Gfx::CCloud::Draw() m_engine->UpdateMatProj(); // gives depth to initial } -void Gfx::CCloud::CreateLine(int x, int y, int len) +void CCloud::CreateLine(int x, int y, int len) { - Gfx::CloudLine line; + CloudLine line; line.x = x; line.y = y; @@ -205,8 +210,8 @@ void Gfx::CCloud::CreateLine(int x, int y, int len) m_lines.push_back(line); } -void Gfx::CCloud::Create(const std::string& fileName, - const Gfx::Color& diffuse, const Gfx::Color& ambient, +void CCloud::Create(const std::string& fileName, + const Color& diffuse, const Color& ambient, float level) { m_diffuse = diffuse; @@ -240,30 +245,33 @@ void Gfx::CCloud::Create(const std::string& fileName, return; } -void Gfx::CCloud::Flush() +void CCloud::Flush() { m_level = 0.0f; } -void Gfx::CCloud::SetLevel(float level) +void CCloud::SetLevel(float level) { m_level = level; Create(m_fileName, m_diffuse, m_ambient, m_level); } -float Gfx::CCloud::GetLevel() +float CCloud::GetLevel() { return m_level; } -void Gfx::CCloud::SetEnabled(bool enabled) +void CCloud::SetEnabled(bool enabled) { m_enabled = enabled; } -bool Gfx::CCloud::GetEnabled() +bool CCloud::GetEnabled() { return m_enabled; } + + +} // namespace Gfx diff --git a/src/graphics/engine/cloud.h b/src/graphics/engine/cloud.h index a9109fa..6f6985f 100644 --- a/src/graphics/engine/cloud.h +++ b/src/graphics/engine/cloud.h @@ -17,13 +17,16 @@ /** * \file graphics/engine/cloud.h - * \brief Cloud rendering - Gfx::CCloud class + * \brief Cloud rendering - CCloud class */ #pragma once + #include "common/event.h" + #include "graphics/core/color.h" + #include "math/point.h" #include "math/vector.h" @@ -31,10 +34,10 @@ #include <string> - class CInstanceManager; +// Graphics module namespace namespace Gfx { class CEngine; @@ -83,7 +86,7 @@ public: //! Removes all the clouds void Flush(); //! Creates all areas of cloud - void Create(const std::string& fileName, const Gfx::Color& diffuse, const Gfx::Color& ambient, float level); + void Create(const std::string& fileName, const Color& diffuse, const Color& ambient, float level); //! Draw the clouds void Draw(); @@ -110,8 +113,8 @@ protected: protected: CInstanceManager* m_iMan; - Gfx::CEngine* m_engine; - Gfx::CTerrain* m_terrain; + CEngine* m_engine; + CTerrain* m_terrain; bool m_enabled; //! Overall level @@ -121,9 +124,9 @@ protected: //! Feedrate (wind) Math::Point m_speed; //! Diffuse color - Gfx::Color m_diffuse; + Color m_diffuse; //! Ambient color - Gfx::Color m_ambient; + Color m_ambient; float m_time; float m_lastTest; int m_subdiv; @@ -135,8 +138,8 @@ protected: //! Size of a brick element float m_brickSize; - std::vector<Gfx::CloudLine> m_lines; + std::vector<CloudLine> m_lines; }; -}; // namespace Gfx +} // namespace Gfx diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 86554e5..f88a37b 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -15,15 +15,16 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// engine.cpp #include "graphics/engine/engine.h" #include "app/app.h" + #include "common/iman.h" #include "common/image.h" #include "common/key.h" #include "common/logger.h" + #include "graphics/core/device.h" #include "graphics/engine/camera.h" #include "graphics/engine/cloud.h" @@ -35,11 +36,18 @@ #include "graphics/engine/terrain.h" #include "graphics/engine/text.h" #include "graphics/engine/water.h" + #include "math/geometry.h" + #include "sound/sound.h" + #include "ui/interface.h" +// Graphics module namespace +namespace Gfx { + + // Initial size of various vectors const int OBJECT_PREALLOCATE_COUNT = 1200; const int SHADOW_PREALLOCATE_COUNT = 500; @@ -52,7 +60,7 @@ const int LEVEL4_PREALLOCATE_COUNT = 100; const int LEVEL4_VERTEX_PREALLOCATE_COUNT = 200; -Gfx::EngineObjLevel1::EngineObjLevel1(bool used, const std::string& tex1Name, const std::string& tex2Name) +EngineObjLevel1::EngineObjLevel1(bool used, const std::string& tex1Name, const std::string& tex2Name) { this->used = used; this->tex1Name = tex1Name; @@ -61,7 +69,7 @@ Gfx::EngineObjLevel1::EngineObjLevel1(bool used, const std::string& tex1Name, co next.reserve(LEVEL2_PREALLOCATE_COUNT); } -Gfx::EngineObjLevel2::EngineObjLevel2(bool used, int objRank) +EngineObjLevel2::EngineObjLevel2(bool used, int objRank) { this->used = used; this->objRank = objRank; @@ -69,7 +77,7 @@ Gfx::EngineObjLevel2::EngineObjLevel2(bool used, int objRank) next.reserve(LEVEL3_PREALLOCATE_COUNT); } -Gfx::EngineObjLevel3::EngineObjLevel3(bool used, float min, float max) +EngineObjLevel3::EngineObjLevel3(bool used, float min, float max) { this->used = used; this->min = min; @@ -78,7 +86,7 @@ Gfx::EngineObjLevel3::EngineObjLevel3(bool used, float min, float max) next.reserve(LEVEL4_PREALLOCATE_COUNT); } -Gfx::EngineObjLevel4::EngineObjLevel4(bool used, Gfx::EngineTriangleType type, const Gfx::Material& material, int state) +EngineObjLevel4::EngineObjLevel4(bool used, EngineTriangleType type, const Material& material, int state) { this->used = used; this->type = type; @@ -88,7 +96,7 @@ Gfx::EngineObjLevel4::EngineObjLevel4(bool used, Gfx::EngineTriangleType type, c vertices.reserve(LEVEL4_VERTEX_PREALLOCATE_COUNT); } -Gfx::CEngine::CEngine(CInstanceManager *iMan, CApplication *app) +CEngine::CEngine(CInstanceManager *iMan, CApplication *app) { m_iMan = iMan; m_app = app; @@ -108,19 +116,21 @@ Gfx::CEngine::CEngine(CInstanceManager *iMan, CApplication *app) m_sound = nullptr; m_terrain = nullptr; + m_showStats = false; + m_focus = 0.75f; m_rankView = 0; - m_ambientColor[0] = Gfx::Color(0.5f, 0.5f, 0.5f, 0.5f); - m_ambientColor[1] = Gfx::Color(0.5f, 0.5f, 0.5f, 0.5f); - m_fogColor[0] = Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f); - m_fogColor[1] = Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f); + m_ambientColor[0] = Color(0.5f, 0.5f, 0.5f, 0.5f); + m_ambientColor[1] = Color(0.5f, 0.5f, 0.5f, 0.5f); + m_fogColor[0] = Color(1.0f, 1.0f, 1.0f, 1.0f); + m_fogColor[1] = Color(1.0f, 1.0f, 1.0f, 1.0f); m_deepView[0] = 1000.0f; m_deepView[1] = 1000.0f; m_fogStart[0] = 0.75f; m_fogStart[1] = 0.75f; - m_waterAddColor = Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f); + m_waterAddColor = Color(0.0f, 0.0f, 0.0f, 0.0f); m_pause = false; m_render = true; @@ -129,19 +139,18 @@ Gfx::CEngine::CEngine(CInstanceManager *iMan, CApplication *app) m_groundSpotVisible = true; m_dirty = true; m_fog = true; - m_speed = 1.0f; m_secondTexNum = 0; m_eyeDirH = 0.0f; m_eyeDirV = 0.0f; m_backgroundName = ""; // no background image - m_backgroundColorUp = Gfx::Color(); - m_backgroundColorDown = Gfx::Color(); - m_backgroundCloudUp = Gfx::Color(); - m_backgroundCloudDown = Gfx::Color(); + m_backgroundColorUp = Color(); + m_backgroundColorDown = Color(); + m_backgroundCloudUp = Color(); + m_backgroundCloudDown = Color(); m_backgroundFull = false; m_backgroundScale = Math::Point(1.0f, 1.0f); m_overFront = true; - m_overColor = Gfx::Color(); + m_overColor = Color(); m_overMode = ENG_RSTATE_TCOLOR_BLACK; m_highlightRank[0] = -1; // empty list m_highlightTime = 0.0f; @@ -163,7 +172,7 @@ Gfx::CEngine::CEngine(CInstanceManager *iMan, CApplication *app) m_lensMode = true; m_waterMode = true; m_skyMode = true; - m_backForce = false; // TODO: change to true? + m_backForce = true; m_planetMode = true; m_lightMode = true; m_editIndentMode = true; @@ -177,33 +186,35 @@ Gfx::CEngine::CEngine(CInstanceManager *iMan, CApplication *app) m_updateGeometry = false; - m_mice[Gfx::ENG_MOUSE_NORM] = Gfx::EngineMouse( 0, 1, 32, Gfx::ENG_RSTATE_TTEXTURE_WHITE, Gfx::ENG_RSTATE_TTEXTURE_BLACK, Math::Point( 1.0f, 1.0f)); - m_mice[Gfx::ENG_MOUSE_WAIT] = Gfx::EngineMouse( 2, 3, 33, Gfx::ENG_RSTATE_TTEXTURE_WHITE, Gfx::ENG_RSTATE_TTEXTURE_BLACK, Math::Point( 8.0f, 12.0f)); - m_mice[Gfx::ENG_MOUSE_HAND] = Gfx::EngineMouse( 4, 5, 34, Gfx::ENG_RSTATE_TTEXTURE_WHITE, Gfx::ENG_RSTATE_TTEXTURE_BLACK, Math::Point( 7.0f, 2.0f)); - m_mice[Gfx::ENG_MOUSE_NO] = Gfx::EngineMouse( 6, 7, 35, Gfx::ENG_RSTATE_TTEXTURE_WHITE, Gfx::ENG_RSTATE_TTEXTURE_BLACK, Math::Point(10.0f, 10.0f)); - m_mice[Gfx::ENG_MOUSE_EDIT] = Gfx::EngineMouse( 8, 9, -1, Gfx::ENG_RSTATE_TTEXTURE_BLACK, Gfx::ENG_RSTATE_TTEXTURE_WHITE, Math::Point( 6.0f, 10.0f)); - m_mice[Gfx::ENG_MOUSE_CROSS] = Gfx::EngineMouse(10, 11, -1, Gfx::ENG_RSTATE_TTEXTURE_BLACK, Gfx::ENG_RSTATE_TTEXTURE_WHITE, Math::Point(10.0f, 10.0f)); - m_mice[Gfx::ENG_MOUSE_MOVEV] = Gfx::EngineMouse(12, 13, -1, Gfx::ENG_RSTATE_TTEXTURE_BLACK, Gfx::ENG_RSTATE_TTEXTURE_WHITE, Math::Point( 5.0f, 11.0f)); - m_mice[Gfx::ENG_MOUSE_MOVEH] = Gfx::EngineMouse(14, 15, -1, Gfx::ENG_RSTATE_TTEXTURE_BLACK, Gfx::ENG_RSTATE_TTEXTURE_WHITE, Math::Point(11.0f, 5.0f)); - m_mice[Gfx::ENG_MOUSE_MOVED] = Gfx::EngineMouse(16, 17, -1, Gfx::ENG_RSTATE_TTEXTURE_BLACK, Gfx::ENG_RSTATE_TTEXTURE_WHITE, Math::Point( 9.0f, 9.0f)); - m_mice[Gfx::ENG_MOUSE_MOVEI] = Gfx::EngineMouse(18, 19, -1, Gfx::ENG_RSTATE_TTEXTURE_BLACK, Gfx::ENG_RSTATE_TTEXTURE_WHITE, Math::Point( 9.0f, 9.0f)); - m_mice[Gfx::ENG_MOUSE_MOVE] = Gfx::EngineMouse(20, 21, -1, Gfx::ENG_RSTATE_TTEXTURE_BLACK, Gfx::ENG_RSTATE_TTEXTURE_WHITE, Math::Point(11.0f, 11.0f)); - m_mice[Gfx::ENG_MOUSE_TARGET] = Gfx::EngineMouse(22, 23, -1, Gfx::ENG_RSTATE_TTEXTURE_BLACK, Gfx::ENG_RSTATE_TTEXTURE_WHITE, Math::Point(15.0f, 15.0f)); - m_mice[Gfx::ENG_MOUSE_SCROLLL] = Gfx::EngineMouse(24, 25, 43, Gfx::ENG_RSTATE_TTEXTURE_BLACK, Gfx::ENG_RSTATE_TTEXTURE_WHITE, Math::Point( 2.0f, 9.0f)); - m_mice[Gfx::ENG_MOUSE_SCROLLR] = Gfx::EngineMouse(26, 27, 44, Gfx::ENG_RSTATE_TTEXTURE_BLACK, Gfx::ENG_RSTATE_TTEXTURE_WHITE, Math::Point(17.0f, 9.0f)); - m_mice[Gfx::ENG_MOUSE_SCROLLU] = Gfx::EngineMouse(28, 29, 45, Gfx::ENG_RSTATE_TTEXTURE_BLACK, Gfx::ENG_RSTATE_TTEXTURE_WHITE, Math::Point( 9.0f, 2.0f)); - m_mice[Gfx::ENG_MOUSE_SCROLLD] = Gfx::EngineMouse(30, 31, 46, Gfx::ENG_RSTATE_TTEXTURE_BLACK, Gfx::ENG_RSTATE_TTEXTURE_WHITE, Math::Point( 9.0f, 17.0f)); + 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)); + m_mice[ENG_MOUSE_NO] = EngineMouse( 6, 7, 35, ENG_RSTATE_TTEXTURE_WHITE, ENG_RSTATE_TTEXTURE_BLACK, Math::Point(10.0f, 10.0f)); + m_mice[ENG_MOUSE_EDIT] = EngineMouse( 8, 9, -1, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::Point( 6.0f, 10.0f)); + m_mice[ENG_MOUSE_CROSS] = EngineMouse(10, 11, -1, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::Point(10.0f, 10.0f)); + m_mice[ENG_MOUSE_MOVEV] = EngineMouse(12, 13, -1, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::Point( 5.0f, 11.0f)); + m_mice[ENG_MOUSE_MOVEH] = EngineMouse(14, 15, -1, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::Point(11.0f, 5.0f)); + m_mice[ENG_MOUSE_MOVED] = EngineMouse(16, 17, -1, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::Point( 9.0f, 9.0f)); + m_mice[ENG_MOUSE_MOVEI] = EngineMouse(18, 19, -1, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::Point( 9.0f, 9.0f)); + m_mice[ENG_MOUSE_MOVE] = EngineMouse(20, 21, -1, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::Point(11.0f, 11.0f)); + m_mice[ENG_MOUSE_TARGET] = EngineMouse(22, 23, -1, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::Point(15.0f, 15.0f)); + m_mice[ENG_MOUSE_SCROLLL] = EngineMouse(24, 25, 43, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::Point( 2.0f, 9.0f)); + m_mice[ENG_MOUSE_SCROLLR] = EngineMouse(26, 27, 44, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::Point(17.0f, 9.0f)); + m_mice[ENG_MOUSE_SCROLLU] = EngineMouse(28, 29, 45, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::Point( 9.0f, 2.0f)); + m_mice[ENG_MOUSE_SCROLLD] = EngineMouse(30, 31, 46, ENG_RSTATE_TTEXTURE_BLACK, ENG_RSTATE_TTEXTURE_WHITE, Math::Point( 9.0f, 17.0f)); m_mouseSize = Math::Point(0.04f, 0.04f * (800.0f / 600.0f)); - m_mousePos = Math::Point(0.5f, 0.5f); - m_mouseType = Gfx::ENG_MOUSE_NORM; - m_mouseVisible = false; + m_mouseType = ENG_MOUSE_NORM; + + m_fpsCounter = 0; + m_lastFrameTime = CreateTimeStamp(); + m_currentFrameTime = CreateTimeStamp(); m_texPath = "textures/"; - m_defaultTexParams.format = Gfx::TEX_IMG_AUTO; + m_defaultTexParams.format = TEX_IMG_AUTO; m_defaultTexParams.mipmap = true; - m_defaultTexParams.minFilter = Gfx::TEX_MIN_FILTER_LINEAR_MIPMAP_LINEAR; - m_defaultTexParams.magFilter = Gfx::TEX_MAG_FILTER_LINEAR; + m_defaultTexParams.minFilter = TEX_MIN_FILTER_LINEAR_MIPMAP_LINEAR; + m_defaultTexParams.magFilter = TEX_MAG_FILTER_LINEAR; m_objectTree.reserve(LEVEL1_PREALLOCATE_COUNT); m_objects.reserve(OBJECT_PREALLOCATE_COUNT); @@ -211,46 +222,51 @@ Gfx::CEngine::CEngine(CInstanceManager *iMan, CApplication *app) m_groundSpots.reserve(GROUNDSPOT_PREALLOCATE_COUNT); } -Gfx::CEngine::~CEngine() +CEngine::~CEngine() { m_iMan = nullptr; m_app = nullptr; m_device = nullptr; m_sound = nullptr; m_terrain = nullptr; + + DestroyTimeStamp(m_lastFrameTime); + m_lastFrameTime = nullptr; + DestroyTimeStamp(m_currentFrameTime); + m_currentFrameTime = nullptr; } -void Gfx::CEngine::SetDevice(Gfx::CDevice *device) +void CEngine::SetDevice(CDevice *device) { m_device = device; } -Gfx::CDevice* Gfx::CEngine::GetDevice() +CDevice* CEngine::GetDevice() { return m_device; } -void Gfx::CEngine::SetTerrain(Gfx::CTerrain* terrain) +void CEngine::SetTerrain(CTerrain* terrain) { m_terrain = terrain; } -Gfx::CText* Gfx::CEngine::GetText() +CText* CEngine::GetText() { return m_text; } -bool Gfx::CEngine::Create() +bool CEngine::Create() { m_size = m_lastSize = m_app->GetVideoConfig().size; - m_lightMan = new Gfx::CLightManager(m_iMan, this); - m_text = new Gfx::CText(m_iMan, this); - m_particle = new Gfx::CParticle(m_iMan, this); - m_water = new Gfx::CWater(m_iMan, this); - m_cloud = new Gfx::CCloud(m_iMan, this); - m_lightning = new Gfx::CLightning(m_iMan, this); - m_planet = new Gfx::CPlanet(m_iMan, this); + m_lightMan = new CLightManager(m_iMan, this); + m_text = new CText(m_iMan, this); + m_particle = new CParticle(m_iMan, this); + m_water = new CWater(m_iMan, this); + m_cloud = new CCloud(m_iMan, this); + m_lightning = new CLightning(m_iMan, this); + m_planet = new CPlanet(m_iMan, this); m_lightMan->SetDevice(m_device); @@ -262,9 +278,9 @@ bool Gfx::CEngine::Create() return false; } - m_device->SetClearColor(Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f)); - m_device->SetShadeModel(Gfx::SHADE_SMOOTH); - m_device->SetFillMode(Gfx::FILL_FILL); + m_device->SetClearColor(Color(0.0f, 0.0f, 0.0f, 0.0f)); + m_device->SetShadeModel(SHADE_SMOOTH); + m_device->SetFillMode(FILL_POLY); SetFocus(m_focus); @@ -273,17 +289,20 @@ bool Gfx::CEngine::Create() Math::LoadOrthoProjectionMatrix(m_matProjInterface, 0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f); - Gfx::TextureCreateParams params; - params.format = Gfx::TEX_IMG_RGB; - params.minFilter = Gfx::TEX_MIN_FILTER_NEAREST; - params.magFilter = Gfx::TEX_MAG_FILTER_NEAREST; + TextureCreateParams params; + params.format = TEX_IMG_RGB; + params.minFilter = TEX_MIN_FILTER_NEAREST; + params.magFilter = TEX_MAG_FILTER_NEAREST; params.mipmap = false; m_miceTexture = LoadTexture("mouse.png", params); + GetCurrentTimeStamp(m_currentFrameTime); + GetCurrentTimeStamp(m_lastFrameTime); + return true; } -void Gfx::CEngine::Destroy() +void CEngine::Destroy() { m_text->Destroy(); @@ -309,35 +328,46 @@ void Gfx::CEngine::Destroy() m_planet = nullptr; } -void Gfx::CEngine::ResetAfterDeviceChanged() +void CEngine::ResetAfterDeviceChanged() { // TODO reload textures, reset device state, etc. } -bool Gfx::CEngine::ProcessEvent(const Event &event) +bool CEngine::ProcessEvent(const Event &event) { if (event.type == EVENT_KEY_DOWN) { - // !! Debug, to be removed later !! - - if (event.key.key == KEY(F1)) - { - m_mouseVisible = !m_mouseVisible; - m_app->SetSystemMouseVisible(! m_app->GetSystemMouseVisibile()); - } - else if (event.key.key == KEY(F2)) - { - int index = static_cast<int>(m_mouseType); - m_mouseType = static_cast<Gfx::EngineMouseType>( (index + 1) % Gfx::ENG_MOUSE_COUNT ); - } + if (event.key.key == KEY(F12)) + m_showStats = !m_showStats; } // By default, pass on all events return true; } -void Gfx::CEngine::FrameUpdate() +void CEngine::FrameUpdate() { + m_fpsCounter++; + + GetCurrentTimeStamp(m_currentFrameTime); + float diff = TimeStampDiff(m_lastFrameTime, m_currentFrameTime, STU_SEC); + if (diff > 1.0f) + { + CopyTimeStamp(m_lastFrameTime, m_currentFrameTime); + + m_fps = m_fpsCounter / diff; + + if (m_showStats) + { + std::stringstream str; + str << "FPS: "; + str.precision(2); + str.setf(std::ios_base::fixed); + str << m_fps; + m_fpsText = str.str(); + } + } + float rTime = m_app->GetRelTime(); m_lightMan->UpdateProgression(rTime); @@ -349,134 +379,134 @@ void Gfx::CEngine::FrameUpdate() if (m_groundMark.draw) { - if (m_groundMark.phase == Gfx::ENG_GR_MARK_PHASE_INC) // growing? + if (m_groundMark.phase == ENG_GR_MARK_PHASE_INC) // growing? { m_groundMark.intensity += rTime*(1.0f/m_groundMark.delay[0]); if (m_groundMark.intensity >= 1.0f) { m_groundMark.intensity = 1.0f; m_groundMark.fix = 0.0f; - m_groundMark.phase = Gfx::ENG_GR_MARK_PHASE_FIX; + m_groundMark.phase = ENG_GR_MARK_PHASE_FIX; } } - else if (m_groundMark.phase == Gfx::ENG_GR_MARK_PHASE_FIX) // fixed? + else if (m_groundMark.phase == ENG_GR_MARK_PHASE_FIX) // fixed? { m_groundMark.fix += rTime*(1.0f/m_groundMark.delay[1]); if (m_groundMark.fix >= 1.0f) - m_groundMark.phase = Gfx::ENG_GR_MARK_PHASE_DEC; + m_groundMark.phase = ENG_GR_MARK_PHASE_DEC; } - else if (m_groundMark.phase == Gfx::ENG_GR_MARK_PHASE_DEC) // decay? + else if (m_groundMark.phase == ENG_GR_MARK_PHASE_DEC) // decay? { m_groundMark.intensity -= rTime*(1.0f/m_groundMark.delay[2]); if (m_groundMark.intensity < 0.0f) { m_groundMark.intensity = 0.0f; - m_groundMark.phase = Gfx::ENG_GR_MARK_PHASE_NULL; + m_groundMark.phase = ENG_GR_MARK_PHASE_NULL; m_groundMark.draw = false; } } } } -bool Gfx::CEngine::WriteScreenShot(const std::string& fileName, int width, int height) +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; } -bool Gfx::CEngine::ReadSettings() +bool CEngine::ReadSettings() { // TODO: when INI reading is completed return true; } -bool Gfx::CEngine::WriteSettings() +bool CEngine::WriteSettings() { // TODO: when INI writing is completed return true; } -void Gfx::CEngine::SetPause(bool pause) +void CEngine::SetPause(bool pause) { m_pause = pause; } -bool Gfx::CEngine::GetPause() +bool CEngine::GetPause() { return m_pause; } -void Gfx::CEngine::SetMovieLock(bool lock) +void CEngine::SetMovieLock(bool lock) { m_movieLock = lock; } -bool Gfx::CEngine::GetMovieLock() +bool CEngine::GetMovieLock() { return m_movieLock; } -void Gfx::CEngine::SetShowStats(bool show) +void CEngine::SetShowStats(bool show) { m_showStats = show; } -bool Gfx::CEngine::GetShowStats() +bool CEngine::GetShowStats() { return m_showStats; } -void Gfx::CEngine::SetRenderEnable(bool enable) +void CEngine::SetRenderEnable(bool enable) { m_render = enable; } -Math::IntPoint Gfx::CEngine::GetWindowSize() +Math::IntPoint CEngine::GetWindowSize() { return m_size; } -Math::IntPoint Gfx::CEngine::GetLastWindowSize() +Math::IntPoint CEngine::GetLastWindowSize() { return m_lastSize; } -Math::Point Gfx::CEngine::WindowToInterfaceCoords(Math::IntPoint pos) +Math::Point CEngine::WindowToInterfaceCoords(Math::IntPoint pos) { return Math::Point( static_cast<float>(pos.x) / static_cast<float>(m_size.x), 1.0f - static_cast<float>(pos.y) / static_cast<float>(m_size.y) ); } -Math::IntPoint Gfx::CEngine::InterfaceToWindowCoords(Math::Point pos) +Math::IntPoint CEngine::InterfaceToWindowCoords(Math::Point pos) { return Math::IntPoint(static_cast<int>(pos.x * m_size.x), static_cast<int>((1.0f - pos.y) * m_size.y)); } -Math::Point Gfx::CEngine::WindowToInterfaceSize(Math::IntPoint size) +Math::Point CEngine::WindowToInterfaceSize(Math::IntPoint size) { return Math::Point(static_cast<float>(size.x) / static_cast<float>(m_size.x), static_cast<float>(size.y) / static_cast<float>(m_size.y)); } -Math::IntPoint Gfx::CEngine::InterfaceToWindowSize(Math::Point size) +Math::IntPoint CEngine::InterfaceToWindowSize(Math::Point size) { return Math::IntPoint(static_cast<int>(size.x * m_size.x), static_cast<int>(size.y * m_size.y)); } -std::string Gfx::CEngine::GetTextureDir() +std::string CEngine::GetTextureDir() { return m_texPath; } -void Gfx::CEngine::AddStatisticTriangle(int count) +void CEngine::AddStatisticTriangle(int count) { m_statisticTriangle += count; } -int Gfx::CEngine::GetStatisticTriangle() +int CEngine::GetStatisticTriangle() { return m_statisticTriangle; } @@ -489,7 +519,7 @@ int Gfx::CEngine::GetStatisticTriangle() -int Gfx::CEngine::CreateObject() +int CEngine::CreateObject() { int i = 0; for ( ; i < static_cast<int>( m_objects.size() ); i++) @@ -502,7 +532,7 @@ int Gfx::CEngine::CreateObject() } if (i == static_cast<int>( m_objects.size() )) - m_objects.push_back(Gfx::EngineObject()); + m_objects.push_back(EngineObject()); m_objects[i].used = true; @@ -520,7 +550,7 @@ int Gfx::CEngine::CreateObject() return i; } -void Gfx::CEngine::FlushObject() +void CEngine::FlushObject() { m_objectTree.clear(); m_objects.clear(); @@ -530,7 +560,7 @@ void Gfx::CEngine::FlushObject() FlushGroundSpot(); } -bool Gfx::CEngine::DeleteObject(int objRank) +bool CEngine::DeleteObject(int objRank) { if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) ) return false; @@ -538,12 +568,12 @@ bool Gfx::CEngine::DeleteObject(int objRank) // Delete object's triangles for (int l1 = 0; l1 < static_cast<int>( m_objectTree.size() ); l1++) { - Gfx::EngineObjLevel1& p1 = m_objectTree[l1]; + EngineObjLevel1& p1 = m_objectTree[l1]; if (! p1.used) continue; for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++) { - Gfx::EngineObjLevel2& p2 = p1.next[l2]; + EngineObjLevel2& p2 = p1.next[l2]; if (! p2.used) continue; if (p2.objRank == objRank) @@ -563,7 +593,7 @@ bool Gfx::CEngine::DeleteObject(int objRank) return true; } -bool Gfx::CEngine::SetObjectType(int objRank, Gfx::EngineObjectType type) +bool CEngine::SetObjectType(int objRank, EngineObjectType type) { if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) ) return false; @@ -572,16 +602,16 @@ bool Gfx::CEngine::SetObjectType(int objRank, Gfx::EngineObjectType type) return true; } -Gfx::EngineObjectType Gfx::CEngine::GetObjectType(int objRank) +EngineObjectType CEngine::GetObjectType(int objRank) { if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) ) - return Gfx::ENG_OBJTYPE_NULL; + return ENG_OBJTYPE_NULL; return m_objects[objRank].type; } -bool Gfx::CEngine::SetObjectTransform(int objRank, const Math::Matrix& transform) +bool CEngine::SetObjectTransform(int objRank, const Math::Matrix& transform) { if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) ) return false; @@ -590,7 +620,7 @@ bool Gfx::CEngine::SetObjectTransform(int objRank, const Math::Matrix& transform return true; } -bool Gfx::CEngine::GetObjectTransform(int objRank, Math::Matrix& transform) +bool CEngine::GetObjectTransform(int objRank, Math::Matrix& transform) { if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) ) return false; @@ -599,7 +629,7 @@ bool Gfx::CEngine::GetObjectTransform(int objRank, Math::Matrix& transform) return true; } -bool Gfx::CEngine::SetObjectDrawWorld(int objRank, bool draw) +bool CEngine::SetObjectDrawWorld(int objRank, bool draw) { if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) ) return false; @@ -608,7 +638,7 @@ bool Gfx::CEngine::SetObjectDrawWorld(int objRank, bool draw) return true; } -bool Gfx::CEngine::SetObjectDrawFront(int objRank, bool draw) +bool CEngine::SetObjectDrawFront(int objRank, bool draw) { if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) ) return false; @@ -617,7 +647,7 @@ bool Gfx::CEngine::SetObjectDrawFront(int objRank, bool draw) return true; } -bool Gfx::CEngine::SetObjectTransparency(int objRank, float value) +bool CEngine::SetObjectTransparency(int objRank, float value) { if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) ) return false; @@ -626,7 +656,7 @@ bool Gfx::CEngine::SetObjectTransparency(int objRank, float value) return true; } -bool Gfx::CEngine::GetObjectBBox(int objRank, Math::Vector& min, Math::Vector& max) +bool CEngine::GetObjectBBox(int objRank, Math::Vector& min, Math::Vector& max) { if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) ) return 0; @@ -637,7 +667,7 @@ bool Gfx::CEngine::GetObjectBBox(int objRank, Math::Vector& min, Math::Vector& m } -int Gfx::CEngine::GetObjectTotalTriangles(int objRank) +int CEngine::GetObjectTotalTriangles(int objRank) { if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) ) return 0; @@ -646,7 +676,7 @@ int Gfx::CEngine::GetObjectTotalTriangles(int objRank) } -Gfx::EngineObjLevel1& Gfx::CEngine::AddLevel1(const std::string& tex1Name, const std::string& tex2Name) +EngineObjLevel1& CEngine::AddLevel1(const std::string& tex1Name, const std::string& tex2Name) { bool unusedPresent = false; for (int i = 0; i < static_cast<int>( m_objectTree.size() ); i++) @@ -675,11 +705,11 @@ Gfx::EngineObjLevel1& Gfx::CEngine::AddLevel1(const std::string& tex1Name, const } } - m_objectTree.push_back(Gfx::EngineObjLevel1(true, tex1Name, tex2Name)); + m_objectTree.push_back(EngineObjLevel1(true, tex1Name, tex2Name)); return m_objectTree.back(); } -Gfx::EngineObjLevel2& Gfx::CEngine::AddLevel2(Gfx::EngineObjLevel1& p1, int objRank) +EngineObjLevel2& CEngine::AddLevel2(EngineObjLevel1& p1, int objRank) { bool unusedPresent = false; for (int i = 0; i < static_cast<int>( p1.next.size() ); i++) @@ -707,11 +737,11 @@ Gfx::EngineObjLevel2& Gfx::CEngine::AddLevel2(Gfx::EngineObjLevel1& p1, int objR } } - p1.next.push_back(Gfx::EngineObjLevel2(true, objRank)); + p1.next.push_back(EngineObjLevel2(true, objRank)); return p1.next.back(); } -Gfx::EngineObjLevel3& Gfx::CEngine::AddLevel3(Gfx::EngineObjLevel2& p2, float min, float max) +EngineObjLevel3& CEngine::AddLevel3(EngineObjLevel2& p2, float min, float max) { bool unusedPresent = false; for (int i = 0; i < static_cast<int>( p2.next.size() ); i++) @@ -740,12 +770,12 @@ Gfx::EngineObjLevel3& Gfx::CEngine::AddLevel3(Gfx::EngineObjLevel2& p2, float mi } } - p2.next.push_back(Gfx::EngineObjLevel3(true, min, max)); + p2.next.push_back(EngineObjLevel3(true, min, max)); return p2.next.back(); } -Gfx::EngineObjLevel4& Gfx::CEngine::AddLevel4(Gfx::EngineObjLevel3& p3, Gfx::EngineTriangleType type, - const Gfx::Material& material, int state) +EngineObjLevel4& CEngine::AddLevel4(EngineObjLevel3& p3, EngineTriangleType type, + const Material& material, int state) { bool unusedPresent = false; for (int i = 0; i < static_cast<int>( p3.next.size() ); i++) @@ -775,12 +805,12 @@ Gfx::EngineObjLevel4& Gfx::CEngine::AddLevel4(Gfx::EngineObjLevel3& p3, Gfx::Eng } } - p3.next.push_back(Gfx::EngineObjLevel4(true, type, material, state)); + p3.next.push_back(EngineObjLevel4(true, type, material, state)); return p3.next.back(); } -bool Gfx::CEngine::AddTriangles(int objRank, const std::vector<Gfx::VertexTex2>& vertices, - const Gfx::Material& material, int state, +bool CEngine::AddTriangles(int objRank, const std::vector<VertexTex2>& vertices, + const Material& material, int state, std::string tex1Name, std::string tex2Name, float min, float max, bool globalUpdate) { @@ -794,10 +824,10 @@ bool Gfx::CEngine::AddTriangles(int objRank, const std::vector<Gfx::VertexTex2>& m_lastObjectDetail = m_objectDetail; m_lastClippingDistance = m_clippingDistance; - Gfx::EngineObjLevel1& p1 = AddLevel1(tex1Name, tex2Name); - Gfx::EngineObjLevel2& p2 = AddLevel2(p1, objRank); - Gfx::EngineObjLevel3& p3 = AddLevel3(p2, min, max); - Gfx::EngineObjLevel4& p4 = AddLevel4(p3, Gfx::ENG_TRIANGLE_TYPE_TRIANGLES, material, state); + EngineObjLevel1& p1 = AddLevel1(tex1Name, tex2Name); + EngineObjLevel2& p2 = AddLevel2(p1, objRank); + EngineObjLevel3& p3 = AddLevel3(p2, min, max); + EngineObjLevel4& p4 = AddLevel4(p3, ENG_TRIANGLE_TYPE_TRIANGLES, material, state); p4.vertices.insert(p4.vertices.end(), vertices.begin(), vertices.end()); @@ -826,8 +856,8 @@ bool Gfx::CEngine::AddTriangles(int objRank, const std::vector<Gfx::VertexTex2>& return true; } -bool Gfx::CEngine::AddSurface(int objRank, const std::vector<Gfx::VertexTex2>& vertices, - const Gfx::Material& material, int state, +bool CEngine::AddSurface(int objRank, const std::vector<VertexTex2>& vertices, + const Material& material, int state, std::string tex1Name, std::string tex2Name, float min, float max, bool globalUpdate) { @@ -841,10 +871,10 @@ bool Gfx::CEngine::AddSurface(int objRank, const std::vector<Gfx::VertexTex2>& v m_lastObjectDetail = m_objectDetail; m_lastClippingDistance = m_clippingDistance; - Gfx::EngineObjLevel1& p1 = AddLevel1(tex1Name, tex2Name); - Gfx::EngineObjLevel2& p2 = AddLevel2(p1, objRank); - Gfx::EngineObjLevel3& p3 = AddLevel3(p2, min, max); - Gfx::EngineObjLevel4& p4 = AddLevel4(p3, Gfx::ENG_TRIANGLE_TYPE_SURFACE, material, state); + EngineObjLevel1& p1 = AddLevel1(tex1Name, tex2Name); + EngineObjLevel2& p2 = AddLevel2(p1, objRank); + EngineObjLevel3& p3 = AddLevel3(p2, min, max); + EngineObjLevel4& p4 = AddLevel4(p3, ENG_TRIANGLE_TYPE_SURFACE, material, state); p4.vertices.insert(p4.vertices.end(), vertices.begin(), vertices.end()); @@ -873,7 +903,7 @@ bool Gfx::CEngine::AddSurface(int objRank, const std::vector<Gfx::VertexTex2>& v return true; } -bool Gfx::CEngine::AddQuick(int objRank, const Gfx::EngineObjLevel4& buffer, +bool CEngine::AddQuick(int objRank, const EngineObjLevel4& buffer, std::string tex1Name, std::string tex2Name, float min, float max, bool globalUpdate) { @@ -883,9 +913,9 @@ bool Gfx::CEngine::AddQuick(int objRank, const Gfx::EngineObjLevel4& buffer, return false; } - Gfx::EngineObjLevel1& p1 = AddLevel1(tex1Name, tex2Name); - Gfx::EngineObjLevel2& p2 = AddLevel2(p1, objRank); - Gfx::EngineObjLevel3& p3 = AddLevel3(p2, min, max); + EngineObjLevel1& p1 = AddLevel1(tex1Name, tex2Name); + EngineObjLevel2& p2 = AddLevel2(p1, objRank); + EngineObjLevel3& p3 = AddLevel3(p2, min, max); p3.next.push_back(buffer); p3.next.back().used = true; // ensure that it is used @@ -910,15 +940,15 @@ bool Gfx::CEngine::AddQuick(int objRank, const Gfx::EngineObjLevel4& buffer, m_objects[objRank].bboxMax.Length()); } - if (buffer.type == Gfx::ENG_TRIANGLE_TYPE_TRIANGLES) + if (buffer.type == ENG_TRIANGLE_TYPE_TRIANGLES) m_objects[objRank].totalTriangles += buffer.vertices.size() / 3; - else if (buffer.type == Gfx::ENG_TRIANGLE_TYPE_SURFACE) + else if (buffer.type == ENG_TRIANGLE_TYPE_SURFACE) m_objects[objRank].totalTriangles += buffer.vertices.size() - 2; return true; } -Gfx::EngineObjLevel4* Gfx::CEngine::FindTriangles(int objRank, const Gfx::Material& material, +EngineObjLevel4* CEngine::FindTriangles(int objRank, const Material& material, int state, std::string tex1Name, std::string tex2Name, float min, float max) { @@ -930,7 +960,7 @@ Gfx::EngineObjLevel4* Gfx::CEngine::FindTriangles(int objRank, const Gfx::Materi for (int l1 = 0; l1 < static_cast<int>( m_objectTree.size() ); l1++) { - Gfx::EngineObjLevel1& p1 = m_objectTree[l1]; + EngineObjLevel1& p1 = m_objectTree[l1]; if (! p1.used) continue; if (p1.tex1Name != tex1Name) continue; @@ -938,24 +968,24 @@ Gfx::EngineObjLevel4* Gfx::CEngine::FindTriangles(int objRank, const Gfx::Materi for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++) { - Gfx::EngineObjLevel2& p2 = p1.next[l2]; + EngineObjLevel2& p2 = p1.next[l2]; if (! p2.used) continue; if (p2.objRank != objRank) continue; for (int l3 = 0; l3 < static_cast<int>( p2.next.size() ); l3++) { - Gfx::EngineObjLevel3& p3 = p2.next[l3]; + EngineObjLevel3& p3 = p2.next[l3]; if (! p3.used) continue; if (p3.min != min || p3.max != max) continue; for (int l4 = 0; l4 < static_cast<int>( p3.next.size() ); l4++) { - Gfx::EngineObjLevel4& p4 = p3.next[l4]; + EngineObjLevel4& p4 = p3.next[l4]; if (! p4.used) continue; - if ( (p4.state & (~(Gfx::ENG_RSTATE_DUAL_BLACK|Gfx::ENG_RSTATE_DUAL_WHITE))) != state || + if ( (p4.state & (~(ENG_RSTATE_DUAL_BLACK|ENG_RSTATE_DUAL_WHITE))) != state || p4.material != material ) continue; @@ -968,8 +998,8 @@ Gfx::EngineObjLevel4* Gfx::CEngine::FindTriangles(int objRank, const Gfx::Materi return nullptr; } -int Gfx::CEngine::GetPartialTriangles(int objRank, float min, float max, float percent, int maxCount, - std::vector<Gfx::EngineTriangle>& triangles) +int CEngine::GetPartialTriangles(int objRank, float min, float max, float percent, int maxCount, + std::vector<EngineTriangle>& triangles) { if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) ) { @@ -985,29 +1015,29 @@ int Gfx::CEngine::GetPartialTriangles(int objRank, float min, float max, float p for (int l1 = 0; l1 < static_cast<int>( m_objectTree.size() ); l1++) { - Gfx::EngineObjLevel1& p1 = m_objectTree[l1]; + EngineObjLevel1& p1 = m_objectTree[l1]; if (! p1.used) continue; for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++) { - Gfx::EngineObjLevel2& p2 = p1.next[l2]; + EngineObjLevel2& p2 = p1.next[l2]; if (! p2.used) continue; if (p2.objRank != objRank) continue; for (int l3 = 0; l3 < static_cast<int>( p2.next.size() ); l3++) { - Gfx::EngineObjLevel3& p3 = p2.next[l3]; + EngineObjLevel3& p3 = p2.next[l3]; if (! p3.used) continue; if (p3.min != min || p3.max != max) continue; for (int l4 = 0; l4 < static_cast<int>( p3.next.size() ); l4++) { - Gfx::EngineObjLevel4& p4 = p3.next[l4]; + EngineObjLevel4& p4 = p3.next[l4]; if (! p4.used) continue; - if (p4.type == Gfx::ENG_TRIANGLE_TYPE_TRIANGLES) + if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES) { for (int i = 0; i < static_cast<int>( p4.vertices.size() ); i += 3) { @@ -1017,7 +1047,7 @@ int Gfx::CEngine::GetPartialTriangles(int objRank, float min, float max, float p if (actualCount >= maxCount) break; - Gfx::EngineTriangle t; + EngineTriangle t; t.triangle[0] = p4.vertices[i]; t.triangle[1] = p4.vertices[i+1]; t.triangle[2] = p4.vertices[i+2]; @@ -1031,7 +1061,7 @@ int Gfx::CEngine::GetPartialTriangles(int objRank, float min, float max, float p ++actualCount; } } - else if (p4.type == Gfx::ENG_TRIANGLE_TYPE_SURFACE) + else if (p4.type == ENG_TRIANGLE_TYPE_SURFACE) { for (int i = 0; i < static_cast<int>( p4.vertices.size() ); i += 1) { @@ -1041,7 +1071,7 @@ int Gfx::CEngine::GetPartialTriangles(int objRank, float min, float max, float p if (actualCount >= maxCount) break; - Gfx::EngineTriangle t; + EngineTriangle t; t.triangle[0] = p4.vertices[i]; t.triangle[1] = p4.vertices[i+1]; t.triangle[2] = p4.vertices[i+2]; @@ -1063,7 +1093,7 @@ int Gfx::CEngine::GetPartialTriangles(int objRank, float min, float max, float p return actualCount; } -void Gfx::CEngine::ChangeLOD() +void CEngine::ChangeLOD() { float oldLimit[2] = { @@ -1082,17 +1112,17 @@ void Gfx::CEngine::ChangeLOD() for (int l1 = 0; l1 < static_cast<int>( m_objectTree.size() ); l1++) { - Gfx::EngineObjLevel1& p1 = m_objectTree[l1]; + EngineObjLevel1& p1 = m_objectTree[l1]; if (! p1.used) continue; for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++) { - Gfx::EngineObjLevel2& p2 = p1.next[l2]; + EngineObjLevel2& p2 = p1.next[l2]; if (! p2.used) continue; for (int l3 = 0; l3 < static_cast<int>( p2.next.size() ); l3++) { - Gfx::EngineObjLevel3& p3 = p2.next[l3]; + EngineObjLevel3& p3 = p2.next[l3]; if (! p3.used) continue; if ( Math::IsEqual(p3.min, 0.0f ) && @@ -1125,27 +1155,27 @@ void Gfx::CEngine::ChangeLOD() m_lastClippingDistance = m_clippingDistance; } -bool Gfx::CEngine::ChangeSecondTexture(int objRank, const std::string& tex2Name) +bool CEngine::ChangeSecondTexture(int objRank, const std::string& tex2Name) { for (int l1 = 0; l1 < static_cast<int>( m_objectTree.size() ); l1++) { - Gfx::EngineObjLevel1& p1 = m_objectTree[l1]; + EngineObjLevel1& p1 = m_objectTree[l1]; if (! p1.used) continue; if (p1.tex2Name == tex2Name) continue; // already new for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++) { - Gfx::EngineObjLevel2& p2 = p1.next[l2]; + EngineObjLevel2& p2 = p1.next[l2]; if (! p2.used) continue; if (p2.objRank != objRank) continue; - Gfx::EngineObjLevel1& newP1 = AddLevel1(p1.tex1Name, tex2Name); + EngineObjLevel1& newP1 = AddLevel1(p1.tex1Name, tex2Name); - newP1.next.push_back(Gfx::EngineObjLevel2(true, objRank)); + newP1.next.push_back(EngineObjLevel2(true, objRank)); - Gfx::EngineObjLevel2& newP2 = newP1.next.back(); + EngineObjLevel2& newP2 = newP1.next.back(); newP2.next.swap(p2.next); p2.used = false; @@ -1154,18 +1184,18 @@ bool Gfx::CEngine::ChangeSecondTexture(int objRank, const std::string& tex2Name) return true; } -bool Gfx::CEngine::ChangeTextureMapping(int objRank, const Gfx::Material& mat, int state, +bool CEngine::ChangeTextureMapping(int objRank, const Material& mat, int state, const std::string& tex1Name, const std::string& tex2Name, - float min, float max, Gfx::EngineTextureMapping mode, + float min, float max, EngineTextureMapping mode, float au, float bu, float av, float bv) { - Gfx::EngineObjLevel4* p4 = FindTriangles(objRank, mat, state, tex1Name, tex2Name, min, max); + EngineObjLevel4* p4 = FindTriangles(objRank, mat, state, tex1Name, tex2Name, min, max); if (p4 == nullptr) return false; int nb = p4->vertices.size(); - if (mode == Gfx::ENG_TEX_MAPPING_X) + if (mode == ENG_TEX_MAPPING_X) { for (int i = 0; i < nb; i++) { @@ -1173,7 +1203,7 @@ bool Gfx::CEngine::ChangeTextureMapping(int objRank, const Gfx::Material& mat, i p4->vertices[i].texCoord.y = p4->vertices[i].coord.y * av + bv; } } - else if (mode == Gfx::ENG_TEX_MAPPING_Y) + else if (mode == ENG_TEX_MAPPING_Y) { for (int i = 0; i < nb; i++) { @@ -1181,7 +1211,7 @@ bool Gfx::CEngine::ChangeTextureMapping(int objRank, const Gfx::Material& mat, i p4->vertices[i].texCoord.y = p4->vertices[i].coord.z * av + bv; } } - else if (mode == Gfx::ENG_TEX_MAPPING_Z) + else if (mode == ENG_TEX_MAPPING_Z) { for (int i = 0; i < nb; i++) { @@ -1189,21 +1219,21 @@ bool Gfx::CEngine::ChangeTextureMapping(int objRank, const Gfx::Material& mat, i p4->vertices[i].texCoord.y = p4->vertices[i].coord.y * av + bv; } } - else if (mode == Gfx::ENG_TEX_MAPPING_1X) + else if (mode == ENG_TEX_MAPPING_1X) { for (int i = 0; i < nb; i++) { p4->vertices[i].texCoord.x = p4->vertices[i].coord.x * au + bu; } } - else if (mode == Gfx::ENG_TEX_MAPPING_1Y) + else if (mode == ENG_TEX_MAPPING_1Y) { for (int i = 0; i < nb; i++) { p4->vertices[i].texCoord.y = p4->vertices[i].coord.y * au + bu; } } - else if (mode == Gfx::ENG_TEX_MAPPING_1Z) + else if (mode == ENG_TEX_MAPPING_1Z) { for (int i = 0; i < nb; i++) { @@ -1214,9 +1244,9 @@ bool Gfx::CEngine::ChangeTextureMapping(int objRank, const Gfx::Material& mat, i return true; } -bool Gfx::CEngine::TrackTextureMapping(int objRank, const Gfx::Material& mat, int state, +bool CEngine::TrackTextureMapping(int objRank, const Material& mat, int state, const std::string& tex1Name, const std::string& tex2Name, - float min, float max, Gfx::EngineTextureMapping mode, + float min, float max, EngineTextureMapping mode, float pos, float factor, float tl, float ts, float tt) { // TODO track texture mapping: pretty complex code, so leaving it for now @@ -1225,7 +1255,7 @@ bool Gfx::CEngine::TrackTextureMapping(int objRank, const Gfx::Material& mat, in } -bool Gfx::CEngine::CreateShadow(int objRank) +bool CEngine::CreateShadow(int objRank) { if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) ) return false; @@ -1243,7 +1273,7 @@ bool Gfx::CEngine::CreateShadow(int objRank) } } - m_shadows.push_back(Gfx::EngineShadow()); + m_shadows.push_back(EngineShadow()); m_shadows[index].used = true; m_shadows[index].objRank = objRank; @@ -1254,7 +1284,7 @@ bool Gfx::CEngine::CreateShadow(int objRank) return true; } -void Gfx::CEngine::DeleteShadow(int objRank) +void CEngine::DeleteShadow(int objRank) { if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) ) return; @@ -1269,7 +1299,7 @@ void Gfx::CEngine::DeleteShadow(int objRank) m_objects[objRank].shadowRank = -1; } -bool Gfx::CEngine::SetObjectShadowHide(int objRank, bool hide) +bool CEngine::SetObjectShadowHide(int objRank, bool hide) { if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) ) return false; @@ -1282,7 +1312,7 @@ bool Gfx::CEngine::SetObjectShadowHide(int objRank, bool hide) return true; } -bool Gfx::CEngine::SetObjectShadowType(int objRank, Gfx::EngineShadowType type) +bool CEngine::SetObjectShadowType(int objRank, EngineShadowType type) { if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) ) return false; @@ -1295,7 +1325,7 @@ bool Gfx::CEngine::SetObjectShadowType(int objRank, Gfx::EngineShadowType type) return true; } -bool Gfx::CEngine::SetObjectShadowPos(int objRank, const Math::Vector& pos) +bool CEngine::SetObjectShadowPos(int objRank, const Math::Vector& pos) { if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) ) return false; @@ -1308,7 +1338,7 @@ bool Gfx::CEngine::SetObjectShadowPos(int objRank, const Math::Vector& pos) return true; } -bool Gfx::CEngine::SetObjectShadowNormal(int objRank, const Math::Vector& normal) +bool CEngine::SetObjectShadowNormal(int objRank, const Math::Vector& normal) { if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) ) return false; @@ -1321,7 +1351,7 @@ bool Gfx::CEngine::SetObjectShadowNormal(int objRank, const Math::Vector& normal return true; } -bool Gfx::CEngine::SetObjectShadowAngle(int objRank, float angle) +bool CEngine::SetObjectShadowAngle(int objRank, float angle) { if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) ) return false; @@ -1334,7 +1364,7 @@ bool Gfx::CEngine::SetObjectShadowAngle(int objRank, float angle) return true; } -bool Gfx::CEngine::SetObjectShadowRadius(int objRank, float radius) +bool CEngine::SetObjectShadowRadius(int objRank, float radius) { if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) ) return false; @@ -1347,7 +1377,7 @@ bool Gfx::CEngine::SetObjectShadowRadius(int objRank, float radius) return true; } -bool Gfx::CEngine::SetObjectShadowIntensity(int objRank, float intensity) +bool CEngine::SetObjectShadowIntensity(int objRank, float intensity) { if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) ) return false; @@ -1360,7 +1390,7 @@ bool Gfx::CEngine::SetObjectShadowIntensity(int objRank, float intensity) return true; } -bool Gfx::CEngine::SetObjectShadowHeight(int objRank, float height) +bool CEngine::SetObjectShadowHeight(int objRank, float height) { if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) ) return false; @@ -1373,7 +1403,7 @@ bool Gfx::CEngine::SetObjectShadowHeight(int objRank, float height) return true; } -float Gfx::CEngine::GetObjectShadowRadius(int objRank) +float CEngine::GetObjectShadowRadius(int objRank) { if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) ) return 0.0f; @@ -1385,14 +1415,14 @@ float Gfx::CEngine::GetObjectShadowRadius(int objRank) return m_shadows[i].radius; } -bool Gfx::CEngine::GetHighlight(Math::Point &p1, Math::Point &p2) +bool CEngine::GetHighlight(Math::Point &p1, Math::Point &p2) { p1 = m_highlightP1; p2 = m_highlightP2; return m_highlight; } -void Gfx::CEngine::SetHighlightRank(int *rankList) +void CEngine::SetHighlightRank(int *rankList) { int i = 0; while ( *rankList != -1 ) @@ -1402,7 +1432,7 @@ void Gfx::CEngine::SetHighlightRank(int *rankList) m_highlightRank[i] = -1; // terminator } -bool Gfx::CEngine::GetBBox2D(int objRank, Math::Point &min, Math::Point &max) +bool CEngine::GetBBox2D(int objRank, Math::Point &min, Math::Point &max) { min.x = 1000000.0f; min.y = 1000000.0f; @@ -1438,7 +1468,7 @@ bool Gfx::CEngine::GetBBox2D(int objRank, Math::Point &min, Math::Point &max) return true; } -void Gfx::CEngine::FlushGroundSpot() +void CEngine::FlushGroundSpot() { m_groundSpots.clear(); m_firstGroundSpot = true; @@ -1446,7 +1476,7 @@ void Gfx::CEngine::FlushGroundSpot() // TODO: blank all shadow textures } -int Gfx::CEngine::CreateGroundSpot() +int CEngine::CreateGroundSpot() { int index = 0; for ( ; index < static_cast<int>( m_groundSpots.size() ); index++) @@ -1458,7 +1488,7 @@ int Gfx::CEngine::CreateGroundSpot() } } - m_groundSpots.push_back(Gfx::EngineGroundSpot()); + m_groundSpots.push_back(EngineGroundSpot()); m_groundSpots[index].used = true; m_groundSpots[index].smooth = 1.0f; @@ -1466,13 +1496,13 @@ int Gfx::CEngine::CreateGroundSpot() return index; } -void Gfx::CEngine::DeleteGroundSpot(int rank) +void CEngine::DeleteGroundSpot(int rank) { m_groundSpots[rank].used = false; m_groundSpots[rank].pos = Math::Vector(0.0f, 0.0f, 0.0f); } -bool Gfx::CEngine::SetObjectGroundSpotPos(int rank, const Math::Vector& pos) +bool CEngine::SetObjectGroundSpotPos(int rank, const Math::Vector& pos) { if ( rank < 0 || rank >= static_cast<int>( m_groundSpots.size() ) ) return 0.0f; @@ -1481,7 +1511,7 @@ bool Gfx::CEngine::SetObjectGroundSpotPos(int rank, const Math::Vector& pos) return true; } -bool Gfx::CEngine::SetObjectGroundSpotRadius(int rank, float radius) +bool CEngine::SetObjectGroundSpotRadius(int rank, float radius) { if ( rank < 0 || rank >= static_cast<int>( m_groundSpots.size() ) ) return 0.0f; @@ -1490,7 +1520,7 @@ bool Gfx::CEngine::SetObjectGroundSpotRadius(int rank, float radius) return true; } -bool Gfx::CEngine::SetObjectGroundSpotColor(int rank, const Gfx::Color& color) +bool CEngine::SetObjectGroundSpotColor(int rank, const Color& color) { if ( rank < 0 || rank >= static_cast<int>( m_groundSpots.size() ) ) return 0.0f; @@ -1499,7 +1529,7 @@ bool Gfx::CEngine::SetObjectGroundSpotColor(int rank, const Gfx::Color& color) return true; } -bool Gfx::CEngine::SetObjectGroundSpotMinMax(int rank, float min, float max) +bool CEngine::SetObjectGroundSpotMinMax(int rank, float min, float max) { if ( rank < 0 || rank >= static_cast<int>( m_groundSpots.size() ) ) return 0.0f; @@ -1509,7 +1539,7 @@ bool Gfx::CEngine::SetObjectGroundSpotMinMax(int rank, float min, float max) return true; } -bool Gfx::CEngine::SetObjectGroundSpotSmooth(int rank, float smooth) +bool CEngine::SetObjectGroundSpotSmooth(int rank, float smooth) { if ( rank < 0 || rank >= static_cast<int>( m_groundSpots.size() ) ) return 0.0f; @@ -1518,13 +1548,13 @@ bool Gfx::CEngine::SetObjectGroundSpotSmooth(int rank, float smooth) return true; } -void Gfx::CEngine::CreateGroundMark(Math::Vector pos, float radius, +void CEngine::CreateGroundMark(Math::Vector pos, float radius, float delay1, float delay2, float delay3, int dx, int dy, char* table) { m_groundMark.LoadDefault(); - m_groundMark.phase = Gfx::ENG_GR_MARK_PHASE_INC; + m_groundMark.phase = ENG_GR_MARK_PHASE_INC; m_groundMark.delay[0] = delay1; m_groundMark.delay[1] = delay2; m_groundMark.delay[2] = delay3; @@ -1536,12 +1566,12 @@ void Gfx::CEngine::CreateGroundMark(Math::Vector pos, float radius, m_groundMark.table = table; } -void Gfx::CEngine::DeleteGroundMark(int rank) +void CEngine::DeleteGroundMark(int rank) { m_groundMark.LoadDefault(); } -void Gfx::CEngine::ComputeDistance() +void CEngine::ComputeDistance() { // TODO: s_resol??? @@ -1558,7 +1588,7 @@ void Gfx::CEngine::ComputeDistance() } } -void Gfx::CEngine::UpdateGeometry() +void CEngine::UpdateGeometry() { if (! m_updateGeometry) return; @@ -1576,22 +1606,22 @@ void Gfx::CEngine::UpdateGeometry() for (int l1 = 0; l1 < static_cast<int>( m_objectTree.size() ); l1++) { - Gfx::EngineObjLevel1& p1 = m_objectTree[l1]; + EngineObjLevel1& p1 = m_objectTree[l1]; if (! p1.used) continue; for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++) { - Gfx::EngineObjLevel2& p2 = p1.next[l2]; + EngineObjLevel2& p2 = p1.next[l2]; if (! p2.used) continue; for (int l3 = 0; l3 < static_cast<int>( p2.next.size() ); l3++) { - Gfx::EngineObjLevel3& p3 = p2.next[l3]; + EngineObjLevel3& p3 = p2.next[l3]; if (! p3.used) continue; for (int l4 = 0; l4 < static_cast<int>( p3.next.size() ); l4++) { - Gfx::EngineObjLevel4& p4 = p3.next[l4]; + EngineObjLevel4& p4 = p3.next[l4]; if (! p4.used) continue; int objRank = p2.objRank; @@ -1616,13 +1646,13 @@ void Gfx::CEngine::UpdateGeometry() m_updateGeometry = false; } -void Gfx::CEngine::Update() +void CEngine::Update() { ComputeDistance(); UpdateGeometry(); } -bool Gfx::CEngine::DetectBBox(int objRank, Math::Point mouse) +bool CEngine::DetectBBox(int objRank, Math::Point mouse) { Math::Point min, max; min.x = 1000000.0f; @@ -1657,38 +1687,38 @@ bool Gfx::CEngine::DetectBBox(int objRank, Math::Point mouse) mouse.y <= max.y ); } -int Gfx::CEngine::DetectObject(Math::Point mouse) +int CEngine::DetectObject(Math::Point mouse) { float min = 1000000.0f; int nearest = -1; for (int l1 = 0; l1 < static_cast<int>( m_objectTree.size() ); l1++) { - Gfx::EngineObjLevel1& p1 = m_objectTree[l1]; + EngineObjLevel1& p1 = m_objectTree[l1]; if (! p1.used) continue; for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++) { - Gfx::EngineObjLevel2& p2 = p1.next[l2]; + EngineObjLevel2& p2 = p1.next[l2]; if (! p2.used) continue; - if (m_objects[p2.objRank].type == Gfx::ENG_OBJTYPE_TERRAIN) continue; + if (m_objects[p2.objRank].type == ENG_OBJTYPE_TERRAIN) continue; if (! DetectBBox(p2.objRank, mouse)) continue; for (int l3 = 0; l3 < static_cast<int>( p2.next.size() ); l3++) { - Gfx::EngineObjLevel3& p3 = p2.next[l3]; + EngineObjLevel3& p3 = p2.next[l3]; if (! p3.used) continue; if (p3.min != 0.0f) continue; // LOD B or C? for (int l4 = 0; l4 < static_cast<int>( p3.next.size() ); l4++) { - Gfx::EngineObjLevel4& p4 = p3.next[l4]; + EngineObjLevel4& p4 = p3.next[l4]; if (! p4.used) continue; - if (p4.type == Gfx::ENG_TRIANGLE_TYPE_TRIANGLES) + if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES) { for (int i = 0; i < static_cast<int>( p4.vertices.size() ); i += 3) { @@ -1700,7 +1730,7 @@ int Gfx::CEngine::DetectObject(Math::Point mouse) } } } - else if (p4.type == Gfx::ENG_TRIANGLE_TYPE_SURFACE) + else if (p4.type == ENG_TRIANGLE_TYPE_SURFACE) { for (int i = 0; i < static_cast<int>( p4.vertices.size() ) - 2; i += 1) { @@ -1720,7 +1750,7 @@ int Gfx::CEngine::DetectObject(Math::Point mouse) return nearest; } -bool Gfx::CEngine::DetectTriangle(Math::Point mouse, Gfx::VertexTex2* triangle, int objRank, float& dist) +bool CEngine::DetectTriangle(Math::Point mouse, VertexTex2* triangle, int objRank, float& dist) { Math::Vector p2D[3], p3D; @@ -1762,13 +1792,13 @@ bool Gfx::CEngine::DetectTriangle(Math::Point mouse, Gfx::VertexTex2* triangle, return true; } -bool Gfx::CEngine::IsVisible(int objRank) +bool CEngine::IsVisible(int objRank) { // TODO: use ComputeSphereVisiblity() after tested OK return true; } -bool Gfx::CEngine::TransformPoint(Math::Vector& p2D, int objRank, Math::Vector p3D) +bool CEngine::TransformPoint(Math::Vector& p2D, int objRank, Math::Vector p3D) { p3D = Math::Transform(m_objects[objRank].transform, p3D); p3D = Math::Transform(m_matView, p3D); @@ -1793,7 +1823,7 @@ bool Gfx::CEngine::TransformPoint(Math::Vector& p2D, int objRank, Math::Vector p -void Gfx::CEngine::SetState(int state, const Gfx::Color& color) +void CEngine::SetState(int state, const Color& color) { if (state == m_lastState && color == m_lastColor) return; @@ -1801,204 +1831,204 @@ void Gfx::CEngine::SetState(int state, const Gfx::Color& color) m_lastState = state; m_lastColor = color; - if (m_alphaMode != 1 && (state & Gfx::ENG_RSTATE_ALPHA)) + if (m_alphaMode != 1 && (state & ENG_RSTATE_ALPHA)) { - state &= ~Gfx::ENG_RSTATE_ALPHA; + state &= ~ENG_RSTATE_ALPHA; if (m_alphaMode == 2) - state |= Gfx::ENG_RSTATE_TTEXTURE_BLACK; + state |= ENG_RSTATE_TTEXTURE_BLACK; } - if (state & Gfx::ENG_RSTATE_TTEXTURE_BLACK) // transparent black texture? + if (state & ENG_RSTATE_TTEXTURE_BLACK) // transparent black texture? { - m_device->SetRenderState(Gfx::RENDER_STATE_FOG, false); - m_device->SetRenderState(Gfx::RENDER_STATE_DEPTH_WRITE, false); - m_device->SetRenderState(Gfx::RENDER_STATE_ALPHA_TEST, false); + m_device->SetRenderState(RENDER_STATE_FOG, false); + m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, false); + m_device->SetRenderState(RENDER_STATE_ALPHA_TEST, false); - m_device->SetRenderState(Gfx::RENDER_STATE_BLENDING, true); - m_device->SetBlendFunc(Gfx::BLEND_ONE, Gfx::BLEND_INV_SRC_COLOR); + m_device->SetRenderState(RENDER_STATE_BLENDING, true); + m_device->SetBlendFunc(BLEND_ONE, BLEND_INV_SRC_COLOR); - m_device->SetRenderState(Gfx::RENDER_STATE_TEXTURING, true); + m_device->SetRenderState(RENDER_STATE_TEXTURING, true); m_device->SetTextureFactor(color); - Gfx::TextureStageParams params; - params.colorOperation = Gfx::TEX_MIX_OPER_MODULATE; - params.colorArg1 = Gfx::TEX_MIX_ARG_TEXTURE; - params.colorArg2 = Gfx::TEX_MIX_ARG_FACTOR; - params.alphaOperation = Gfx::TEX_MIX_OPER_DEFAULT; // TODO: replace with src 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 ? m_device->SetTextureEnabled(0, true); m_device->SetTextureStageParams(0, params); } - else if (state & Gfx::ENG_RSTATE_TTEXTURE_WHITE) // transparent white texture? + else if (state & ENG_RSTATE_TTEXTURE_WHITE) // transparent white texture? { - m_device->SetRenderState(Gfx::RENDER_STATE_FOG, false); - m_device->SetRenderState(Gfx::RENDER_STATE_DEPTH_WRITE, false); - m_device->SetRenderState(Gfx::RENDER_STATE_ALPHA_TEST, false); + m_device->SetRenderState(RENDER_STATE_FOG, false); + m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, false); + m_device->SetRenderState(RENDER_STATE_ALPHA_TEST, false); - m_device->SetRenderState(Gfx::RENDER_STATE_BLENDING, true); - m_device->SetBlendFunc(Gfx::BLEND_DST_COLOR, Gfx::BLEND_ZERO); + m_device->SetRenderState(RENDER_STATE_BLENDING, true); + m_device->SetBlendFunc(BLEND_DST_COLOR, BLEND_ZERO); - m_device->SetRenderState(Gfx::RENDER_STATE_TEXTURING, true); + m_device->SetRenderState(RENDER_STATE_TEXTURING, true); m_device->SetTextureFactor(color.Inverse()); - Gfx::TextureStageParams params; - params.colorOperation = Gfx::TEX_MIX_OPER_ADD; - params.colorArg1 = Gfx::TEX_MIX_ARG_TEXTURE; - params.colorArg2 = Gfx::TEX_MIX_ARG_FACTOR; - params.alphaOperation = Gfx::TEX_MIX_OPER_DEFAULT; // TODO: replace with src color ? + 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 ? m_device->SetTextureEnabled(0, true); m_device->SetTextureStageParams(0, params); } - else if (state & Gfx::ENG_RSTATE_TCOLOR_BLACK) // transparent black color? + else if (state & ENG_RSTATE_TCOLOR_BLACK) // transparent black color? { - m_device->SetRenderState(Gfx::RENDER_STATE_FOG, false); - m_device->SetRenderState(Gfx::RENDER_STATE_DEPTH_WRITE, false); - m_device->SetRenderState(Gfx::RENDER_STATE_ALPHA_TEST, false); - m_device->SetRenderState(Gfx::RENDER_STATE_TEXTURING, false); + m_device->SetRenderState(RENDER_STATE_FOG, false); + m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, false); + m_device->SetRenderState(RENDER_STATE_ALPHA_TEST, false); + m_device->SetRenderState(RENDER_STATE_TEXTURING, false); - m_device->SetRenderState(Gfx::RENDER_STATE_BLENDING, true); - m_device->SetBlendFunc(Gfx::BLEND_ONE, Gfx::BLEND_INV_SRC_COLOR); + m_device->SetRenderState(RENDER_STATE_BLENDING, true); + m_device->SetBlendFunc(BLEND_ONE, BLEND_INV_SRC_COLOR); } - else if (state & Gfx::ENG_RSTATE_TCOLOR_WHITE) // transparent white color? + else if (state & ENG_RSTATE_TCOLOR_WHITE) // transparent white color? { - m_device->SetRenderState(Gfx::RENDER_STATE_FOG, false); - m_device->SetRenderState(Gfx::RENDER_STATE_DEPTH_WRITE, false); - m_device->SetRenderState(Gfx::RENDER_STATE_ALPHA_TEST, false); - m_device->SetRenderState(Gfx::RENDER_STATE_TEXTURING, false); + m_device->SetRenderState(RENDER_STATE_FOG, false); + m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, false); + m_device->SetRenderState(RENDER_STATE_ALPHA_TEST, false); + m_device->SetRenderState(RENDER_STATE_TEXTURING, false); - m_device->SetRenderState(Gfx::RENDER_STATE_BLENDING, true); - m_device->SetBlendFunc(Gfx::BLEND_DST_COLOR, Gfx::BLEND_ZERO); + m_device->SetRenderState(RENDER_STATE_BLENDING, true); + m_device->SetBlendFunc(BLEND_DST_COLOR, BLEND_ZERO); } - else if (state & Gfx::ENG_RSTATE_TDIFFUSE) // diffuse color as transparent? + else if (state & ENG_RSTATE_TDIFFUSE) // diffuse color as transparent? { - m_device->SetRenderState(Gfx::RENDER_STATE_FOG, false); - m_device->SetRenderState(Gfx::RENDER_STATE_DEPTH_WRITE, false); - m_device->SetRenderState(Gfx::RENDER_STATE_ALPHA_TEST, false); + m_device->SetRenderState(RENDER_STATE_FOG, false); + m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, false); + m_device->SetRenderState(RENDER_STATE_ALPHA_TEST, false); - m_device->SetRenderState(Gfx::RENDER_STATE_BLENDING, true); - m_device->SetBlendFunc(Gfx::BLEND_SRC_ALPHA, Gfx::BLEND_DST_ALPHA); + m_device->SetRenderState(RENDER_STATE_BLENDING, true); + m_device->SetBlendFunc(BLEND_SRC_ALPHA, BLEND_DST_ALPHA); - m_device->SetRenderState(Gfx::RENDER_STATE_TEXTURING, true); + m_device->SetRenderState(RENDER_STATE_TEXTURING, true); - Gfx::TextureStageParams params; - params.colorOperation = Gfx::TEX_MIX_OPER_REPLACE; - params.colorArg1 = Gfx::TEX_MIX_ARG_TEXTURE; - params.alphaOperation = Gfx::TEX_MIX_OPER_DEFAULT; // TODO: replace with src color ? + TextureStageParams params; + params.colorOperation = TEX_MIX_OPER_REPLACE; + params.colorArg1 = TEX_MIX_ARG_TEXTURE; + params.alphaOperation = TEX_MIX_OPER_DEFAULT; // TODO: replace with src color ? m_device->SetTextureEnabled(0, true); m_device->SetTextureStageParams(0, params); } - else if (state & Gfx::ENG_RSTATE_OPAQUE_TEXTURE) // opaque texture ? + else if (state & ENG_RSTATE_OPAQUE_TEXTURE) // opaque texture ? { - m_device->SetRenderState(Gfx::RENDER_STATE_FOG, false); - m_device->SetRenderState(Gfx::RENDER_STATE_DEPTH_WRITE, false); - m_device->SetRenderState(Gfx::RENDER_STATE_ALPHA_TEST, false); - m_device->SetRenderState(Gfx::RENDER_STATE_BLENDING, false); + m_device->SetRenderState(RENDER_STATE_FOG, false); + m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, false); + m_device->SetRenderState(RENDER_STATE_ALPHA_TEST, false); + m_device->SetRenderState(RENDER_STATE_BLENDING, false); - m_device->SetRenderState(Gfx::RENDER_STATE_TEXTURING, true); + m_device->SetRenderState(RENDER_STATE_TEXTURING, true); m_device->SetTextureEnabled(0, true); - m_device->SetTextureStageParams(0, Gfx::TextureStageParams()); // default operation + m_device->SetTextureStageParams(0, TextureStageParams()); // default operation } - else if (state & Gfx::ENG_RSTATE_OPAQUE_COLOR) // opaque color ? + else if (state & ENG_RSTATE_OPAQUE_COLOR) // opaque color ? { - m_device->SetRenderState(Gfx::RENDER_STATE_FOG, false); - m_device->SetRenderState(Gfx::RENDER_STATE_DEPTH_WRITE, false); - m_device->SetRenderState(Gfx::RENDER_STATE_ALPHA_TEST, false); - m_device->SetRenderState(Gfx::RENDER_STATE_BLENDING, false); - m_device->SetRenderState(Gfx::RENDER_STATE_TEXTURING, false); + m_device->SetRenderState(RENDER_STATE_FOG, false); + m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, false); + m_device->SetRenderState(RENDER_STATE_ALPHA_TEST, false); + m_device->SetRenderState(RENDER_STATE_BLENDING, false); + m_device->SetRenderState(RENDER_STATE_TEXTURING, false); } - else if (state & Gfx::ENG_RSTATE_TEXT) // font rendering? + else if (state & ENG_RSTATE_TEXT) // font rendering? { - m_device->SetRenderState(Gfx::RENDER_STATE_FOG, false); - m_device->SetRenderState(Gfx::RENDER_STATE_DEPTH_WRITE, false); - m_device->SetRenderState(Gfx::RENDER_STATE_ALPHA_TEST, false); + m_device->SetRenderState(RENDER_STATE_FOG, false); + m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, false); + m_device->SetRenderState(RENDER_STATE_ALPHA_TEST, false); - m_device->SetRenderState(Gfx::RENDER_STATE_BLENDING, true); - m_device->SetBlendFunc(Gfx::BLEND_SRC_ALPHA, Gfx::BLEND_INV_SRC_ALPHA); + m_device->SetRenderState(RENDER_STATE_BLENDING, true); + m_device->SetBlendFunc(BLEND_SRC_ALPHA, BLEND_INV_SRC_ALPHA); - m_device->SetRenderState(Gfx::RENDER_STATE_TEXTURING, true); + m_device->SetRenderState(RENDER_STATE_TEXTURING, true); - Gfx::TextureStageParams params; - params.colorOperation = Gfx::TEX_MIX_OPER_DEFAULT; // default modulate operation - params.alphaOperation = Gfx::TEX_MIX_OPER_DEFAULT; // default modulate operation + TextureStageParams params; + params.colorOperation = TEX_MIX_OPER_DEFAULT; // default modulate operation + params.alphaOperation = TEX_MIX_OPER_DEFAULT; // default modulate operation m_device->SetTextureEnabled(0, true); m_device->SetTextureStageParams(0, params); } - else if (state & Gfx::ENG_RSTATE_ALPHA) // image with alpha channel? + else if (state & ENG_RSTATE_ALPHA) // image with alpha channel? { - m_device->SetRenderState(Gfx::RENDER_STATE_BLENDING, false); + m_device->SetRenderState(RENDER_STATE_BLENDING, false); - m_device->SetRenderState(Gfx::RENDER_STATE_FOG, true); - m_device->SetRenderState(Gfx::RENDER_STATE_DEPTH_WRITE, true); + m_device->SetRenderState(RENDER_STATE_FOG, true); + m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, true); - m_device->SetRenderState(Gfx::RENDER_STATE_ALPHA_TEST, true); + m_device->SetRenderState(RENDER_STATE_ALPHA_TEST, true); - m_device->SetAlphaTestFunc(Gfx::COMP_FUNC_GREATER, 0.5f); + m_device->SetAlphaTestFunc(COMP_FUNC_GREATER, 0.5f); - m_device->SetRenderState(Gfx::RENDER_STATE_TEXTURING, true); + m_device->SetRenderState(RENDER_STATE_TEXTURING, true); m_device->SetTextureFactor(color); - Gfx::TextureStageParams params; - params.colorOperation = Gfx::TEX_MIX_OPER_MODULATE; - params.colorArg1 = Gfx::TEX_MIX_ARG_TEXTURE; - params.colorArg2 = Gfx::TEX_MIX_ARG_SRC_COLOR; - params.alphaOperation = Gfx::TEX_MIX_OPER_REPLACE; - params.alphaArg1 = Gfx::TEX_MIX_ARG_TEXTURE; + 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; m_device->SetTextureEnabled(0, true); m_device->SetTextureStageParams(0, params); } else // normal ? { - m_device->SetRenderState(Gfx::RENDER_STATE_ALPHA_TEST, false); - m_device->SetRenderState(Gfx::RENDER_STATE_BLENDING, false); + m_device->SetRenderState(RENDER_STATE_ALPHA_TEST, false); + m_device->SetRenderState(RENDER_STATE_BLENDING, false); - m_device->SetRenderState(Gfx::RENDER_STATE_DEPTH_WRITE, true); - m_device->SetRenderState(Gfx::RENDER_STATE_FOG, true); + m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, true); + m_device->SetRenderState(RENDER_STATE_FOG, true); - m_device->SetRenderState(Gfx::RENDER_STATE_TEXTURING, true); + m_device->SetRenderState(RENDER_STATE_TEXTURING, true); - Gfx::TextureStageParams params; - params.colorOperation = Gfx::TEX_MIX_OPER_DEFAULT; // default modulate - params.alphaOperation = Gfx::TEX_MIX_OPER_DEFAULT; // TODO: replace with src color ? + TextureStageParams params; + params.colorOperation = TEX_MIX_OPER_DEFAULT; // default modulate + params.alphaOperation = TEX_MIX_OPER_DEFAULT; // TODO: replace with src color ? m_device->SetTextureEnabled(0, true); m_device->SetTextureStageParams(0, params); } - if (state & Gfx::ENG_RSTATE_FOG) - m_device->SetRenderState(Gfx::RENDER_STATE_FOG, true); + if (state & ENG_RSTATE_FOG) + m_device->SetRenderState(RENDER_STATE_FOG, true); bool second = m_groundSpotVisible || m_dirty; - if ( !m_groundSpotVisible && (state & Gfx::ENG_RSTATE_SECOND) != 0 ) second = false; - if ( !m_dirty && (state & Gfx::ENG_RSTATE_SECOND) == 0 ) second = false; + if ( !m_groundSpotVisible && (state & ENG_RSTATE_SECOND) != 0 ) second = false; + if ( !m_dirty && (state & ENG_RSTATE_SECOND) == 0 ) second = false; if ((state & ENG_RSTATE_DUAL_BLACK) && second) { - Gfx::TextureStageParams params; - params.colorOperation = Gfx::TEX_MIX_OPER_MODULATE; - params.colorArg1 = Gfx::TEX_MIX_ARG_TEXTURE; - params.colorArg2 = Gfx::TEX_MIX_ARG_COMPUTED_COLOR; - params.alphaOperation = Gfx::TEX_MIX_OPER_DEFAULT; // TODO: ??? + TextureStageParams params; + params.colorOperation = TEX_MIX_OPER_MODULATE; + params.colorArg1 = TEX_MIX_ARG_TEXTURE; + params.colorArg2 = TEX_MIX_ARG_COMPUTED_COLOR; + params.alphaOperation = TEX_MIX_OPER_DEFAULT; // TODO: ??? m_device->SetTextureEnabled(0, true); m_device->SetTextureStageParams(1, params); } else if ((state & ENG_RSTATE_DUAL_WHITE) && second) { - Gfx::TextureStageParams params; - params.colorOperation = Gfx::TEX_MIX_OPER_ADD; - params.colorArg1 = Gfx::TEX_MIX_ARG_TEXTURE; - params.colorArg2 = Gfx::TEX_MIX_ARG_COMPUTED_COLOR; - params.alphaOperation = Gfx::TEX_MIX_OPER_DEFAULT; // TODO: ??? + TextureStageParams params; + params.colorOperation = TEX_MIX_OPER_ADD; + params.colorArg1 = TEX_MIX_ARG_TEXTURE; + params.colorArg2 = TEX_MIX_ARG_COMPUTED_COLOR; + params.alphaOperation = TEX_MIX_OPER_DEFAULT; // TODO: ??? m_device->SetTextureEnabled(0, true); m_device->SetTextureStageParams(1, params); } @@ -2007,52 +2037,52 @@ void Gfx::CEngine::SetState(int state, const Gfx::Color& color) m_device->SetTextureEnabled(1, false); } - if (state & Gfx::ENG_RSTATE_WRAP) + if (state & ENG_RSTATE_WRAP) { // TODO: separate function for setting wrap mode? - Gfx::TextureStageParams p1 = m_device->GetTextureStageParams(0); - p1.wrapS = p1.wrapT = Gfx::TEX_WRAP_REPEAT; + TextureStageParams p1 = m_device->GetTextureStageParams(0); + p1.wrapS = p1.wrapT = TEX_WRAP_REPEAT; m_device->SetTextureStageParams(0, p1); - Gfx::TextureStageParams p2 = m_device->GetTextureStageParams(1); - p2.wrapS = p2.wrapT = Gfx::TEX_WRAP_REPEAT; + TextureStageParams p2 = m_device->GetTextureStageParams(1); + p2.wrapS = p2.wrapT = TEX_WRAP_REPEAT; m_device->SetTextureStageParams(1, p2); } - else // if (state & Gfx::ENG_RSTATE_CLAMP) or otherwise + else // if (state & ENG_RSTATE_CLAMP) or otherwise { - Gfx::TextureStageParams p1 = m_device->GetTextureStageParams(0); - p1.wrapS = p1.wrapT = Gfx::TEX_WRAP_CLAMP; + TextureStageParams p1 = m_device->GetTextureStageParams(0); + p1.wrapS = p1.wrapT = TEX_WRAP_CLAMP; m_device->SetTextureStageParams(0, p1); - Gfx::TextureStageParams p2 = m_device->GetTextureStageParams(1); - p2.wrapS = p2.wrapT = Gfx::TEX_WRAP_CLAMP; + TextureStageParams p2 = m_device->GetTextureStageParams(1); + p2.wrapS = p2.wrapT = TEX_WRAP_CLAMP; m_device->SetTextureStageParams(1, p2); } - if (state & Gfx::ENG_RSTATE_2FACE) + if (state & ENG_RSTATE_2FACE) { - m_device->SetRenderState(Gfx::RENDER_STATE_CULLING, false); + m_device->SetRenderState(RENDER_STATE_CULLING, false); } else { - m_device->SetRenderState(Gfx::RENDER_STATE_CULLING, true); - m_device->SetCullMode(Gfx::CULL_CCW); + m_device->SetRenderState(RENDER_STATE_CULLING, true); + m_device->SetCullMode(CULL_CCW); } - if (state & Gfx::ENG_RSTATE_LIGHT) - m_device->SetGlobalAmbient(Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f)); + if (state & ENG_RSTATE_LIGHT) + m_device->SetGlobalAmbient(Color(1.0f, 1.0f, 1.0f, 1.0f)); else m_device->SetGlobalAmbient(m_ambientColor[m_rankView]); } -void Gfx::CEngine::SetMaterial(const Gfx::Material& mat) +void CEngine::SetMaterial(const Material& mat) { m_lastMaterial = mat; m_device->SetMaterial(mat); } -void Gfx::CEngine::SetViewParams(const Math::Vector& eyePt, const Math::Vector& lookatPt, +void CEngine::SetViewParams(const Math::Vector& eyePt, const Math::Vector& lookatPt, const Math::Vector& upVec, float eyeDistance) { m_eyePt = eyePt; @@ -2069,10 +2099,10 @@ void Gfx::CEngine::SetViewParams(const Math::Vector& eyePt, const Math::Vector& m_sound->SetListener(eyePt, lookatPt); } -Gfx::Texture Gfx::CEngine::CreateTexture(const std::string& texName, const Gfx::TextureCreateParams& params) +Texture CEngine::CreateTexture(const std::string& texName, const TextureCreateParams& params) { if (m_texBlacklist.find(texName) != m_texBlacklist.end()) - return Gfx::Texture(); // invalid texture + return Texture(); // invalid texture // TODO: detect alpha channel? @@ -2082,10 +2112,10 @@ Gfx::Texture Gfx::CEngine::CreateTexture(const std::string& texName, const Gfx:: 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 Gfx::Texture(); // invalid texture + return Texture(); // invalid texture } - Gfx::Texture tex = m_device->CreateTexture(&img, params); + Texture tex = m_device->CreateTexture(&img, params); if (! tex.Valid()) { @@ -2100,25 +2130,25 @@ Gfx::Texture Gfx::CEngine::CreateTexture(const std::string& texName, const Gfx:: return tex; } -Gfx::Texture Gfx::CEngine::LoadTexture(const std::string& name) +Texture CEngine::LoadTexture(const std::string& name) { return LoadTexture(name, m_defaultTexParams); } -Gfx::Texture Gfx::CEngine::LoadTexture(const std::string& name, const Gfx::TextureCreateParams& params) +Texture CEngine::LoadTexture(const std::string& name, const TextureCreateParams& params) { if (m_texBlacklist.find(name) != m_texBlacklist.end()) - return Gfx::Texture(); + return Texture(); - std::map<std::string, Gfx::Texture>::iterator it = m_texNameMap.find(name); + std::map<std::string, Texture>::iterator it = m_texNameMap.find(name); if (it != m_texNameMap.end()) return (*it).second; - Gfx::Texture tex = CreateTexture(name, params); + Texture tex = CreateTexture(name, params); return tex; } -bool Gfx::CEngine::LoadAllTextures() +bool CEngine::LoadAllTextures() { LoadTexture("text.png"); m_miceTexture = LoadTexture("mouse.png"); @@ -2146,7 +2176,7 @@ bool Gfx::CEngine::LoadAllTextures() for (int l1 = 0; l1 < static_cast<int>( m_objectTree.size() ); l1++) { - Gfx::EngineObjLevel1& p1 = m_objectTree[l1]; + EngineObjLevel1& p1 = m_objectTree[l1]; if (! p1.used) continue; if (! p1.tex1Name.empty()) @@ -2167,7 +2197,7 @@ bool Gfx::CEngine::LoadAllTextures() return ok; } -void Gfx::CEngine::DeleteTexture(const std::string& texName) +void CEngine::DeleteTexture(const std::string& texName) { auto it = m_texNameMap.find(texName); if (it == m_texNameMap.end()) @@ -2181,7 +2211,7 @@ void Gfx::CEngine::DeleteTexture(const std::string& texName) m_texNameMap.erase(it); } -void Gfx::CEngine::DeleteTexture(const Gfx::Texture& tex) +void CEngine::DeleteTexture(const Texture& tex) { if (! tex.Valid()) return; @@ -2198,7 +2228,7 @@ void Gfx::CEngine::DeleteTexture(const Gfx::Texture& tex) m_texNameMap.erase(it); } -bool Gfx::CEngine::SetTexture(const std::string& name, int stage) +bool CEngine::SetTexture(const std::string& name, int stage) { auto it = m_texNameMap.find(name); if (it != m_texNameMap.end()) @@ -2224,17 +2254,17 @@ bool Gfx::CEngine::SetTexture(const std::string& name, int stage) return false; // should not happen normally } -void Gfx::CEngine::SetTexture(const Gfx::Texture& tex, int stage) +void CEngine::SetTexture(const Texture& tex, int stage) { m_device->SetTexture(stage, tex); } -void Gfx::CEngine::SetLimitLOD(int rank, float limit) +void CEngine::SetLimitLOD(int rank, float limit) { m_limitLOD[rank] = limit; } -float Gfx::CEngine::GetLimitLOD(int rank, bool last) +float CEngine::GetLimitLOD(int rank, bool last) { float limit = 0.0f; @@ -2256,12 +2286,12 @@ float Gfx::CEngine::GetLimitLOD(int rank, bool last) return limit; } -void Gfx::CEngine::SetTerrainVision(float vision) +void CEngine::SetTerrainVision(float vision) { m_terrainVision = vision; } -void Gfx::CEngine::SetFocus(float focus) +void CEngine::SetFocus(float focus) { m_focus = focus; m_size = m_app->GetVideoConfig().size; @@ -2270,67 +2300,67 @@ void Gfx::CEngine::SetFocus(float focus) Math::LoadProjectionMatrix(m_matProj, m_focus, aspect, 0.5f, m_deepView[0]); } -float Gfx::CEngine::GetFocus() +float CEngine::GetFocus() { return m_focus; } -void Gfx::CEngine::SetGroundSpot(bool mode) +void CEngine::SetGroundSpot(bool mode) { m_groundSpotVisible = mode; } -bool Gfx::CEngine::GetGroundSpot() +bool CEngine::GetGroundSpot() { return m_groundSpotVisible; } -void Gfx::CEngine::SetShadow(bool mode) +void CEngine::SetShadow(bool mode) { m_shadowVisible = mode; } -bool Gfx::CEngine::GetShadow() +bool CEngine::GetShadow() { return m_shadowVisible; } -void Gfx::CEngine::SetDirty(bool mode) +void CEngine::SetDirty(bool mode) { m_dirty = mode; } -bool Gfx::CEngine::GetDirty() +bool CEngine::GetDirty() { return m_dirty; } -void Gfx::CEngine::SetFog(bool mode) +void CEngine::SetFog(bool mode) { m_fog = mode; } -bool Gfx::CEngine::GetFog() +bool CEngine::GetFog() { return m_fog; } -bool Gfx::CEngine::GetStateColor() +bool CEngine::GetStateColor() { return m_stateColor; } -void Gfx::CEngine::SetSecondTexture(int texNum) +void CEngine::SetSecondTexture(int texNum) { m_secondTexNum = texNum; } -int Gfx::CEngine::GetSecondTexture() +int CEngine::GetSecondTexture() { return m_secondTexNum; } -void Gfx::CEngine::SetRankView(int rank) +void CEngine::SetRankView(int rank) { if (rank < 0) rank = 0; if (rank > 1) rank = 1; @@ -2344,52 +2374,52 @@ void Gfx::CEngine::SetRankView(int rank) m_rankView = rank; } -int Gfx::CEngine::GetRankView() +int CEngine::GetRankView() { return m_rankView; } -void Gfx::CEngine::SetDrawWorld(bool draw) +void CEngine::SetDrawWorld(bool draw) { m_drawWorld = draw; } -void Gfx::CEngine::SetDrawFront(bool draw) +void CEngine::SetDrawFront(bool draw) { m_drawFront = draw; } -void Gfx::CEngine::SetAmbientColor(const Gfx::Color& color, int rank) +void CEngine::SetAmbientColor(const Color& color, int rank) { m_ambientColor[rank] = color; } -Gfx::Color Gfx::CEngine::GetAmbientColor(int rank) +Color CEngine::GetAmbientColor(int rank) { return m_ambientColor[rank]; } -void Gfx::CEngine::SetWaterAddColor(const Gfx::Color& color) +void CEngine::SetWaterAddColor(const Color& color) { m_waterAddColor = color; } -Gfx::Color Gfx::CEngine::GetWaterAddColor() +Color CEngine::GetWaterAddColor() { return m_waterAddColor; } -void Gfx::CEngine::SetFogColor(const Gfx::Color& color, int rank) +void CEngine::SetFogColor(const Color& color, int rank) { m_fogColor[rank] = color; } -Gfx::Color Gfx::CEngine::GetFogColor(int rank) +Color CEngine::GetFogColor(int rank) { return m_fogColor[rank]; } -void Gfx::CEngine::SetDeepView(float length, int rank, bool ref) +void CEngine::SetDeepView(float length, int rank, bool ref) { if (ref) length *= m_clippingDistance; @@ -2397,23 +2427,23 @@ void Gfx::CEngine::SetDeepView(float length, int rank, bool ref) m_deepView[rank] = length; } -float Gfx::CEngine::GetDeepView(int rank) +float CEngine::GetDeepView(int rank) { return m_deepView[rank]; } -void Gfx::CEngine::SetFogStart(float start, int rank) +void CEngine::SetFogStart(float start, int rank) { m_fogStart[rank] = start; } -float Gfx::CEngine::GetFogStart(int rank) +float CEngine::GetFogStart(int rank) { return m_fogStart[rank]; } -void Gfx::CEngine::SetBackground(const std::string& name, Gfx::Color up, Gfx::Color down, - Gfx::Color cloudUp, Gfx::Color cloudDown, +void CEngine::SetBackground(const std::string& name, Color up, Color down, + Color cloudUp, Color cloudDown, bool full, Math::Point scale) { if (m_backgroundTex.Valid()) @@ -2434,8 +2464,8 @@ void Gfx::CEngine::SetBackground(const std::string& name, Gfx::Color up, Gfx::Co m_backgroundTex = LoadTexture(m_backgroundName); } -void Gfx::CEngine::GetBackground(std::string& name, Gfx::Color& up, Gfx::Color& down, - Gfx::Color& cloudUp, Gfx::Color& cloudDown, +void CEngine::GetBackground(std::string& name, Color& up, Color& down, + Color& cloudUp, Color& cloudDown, bool &full, Math::Point& scale) { name = m_backgroundName; @@ -2447,7 +2477,7 @@ void Gfx::CEngine::GetBackground(std::string& name, Gfx::Color& up, Gfx::Color& scale = m_backgroundScale; } -void Gfx::CEngine::SetForegroundName(const std::string& name) +void CEngine::SetForegroundName(const std::string& name) { if (m_foregroundTex.Valid()) { @@ -2461,30 +2491,30 @@ void Gfx::CEngine::SetForegroundName(const std::string& name) m_foregroundTex = LoadTexture(m_foregroundName); } -void Gfx::CEngine::SetOverFront(bool front) +void CEngine::SetOverFront(bool front) { m_overFront = front; } -void Gfx::CEngine::SetOverColor(const Gfx::Color& color, int mode) +void CEngine::SetOverColor(const Color& color, int mode) { m_overColor = color; m_overMode = mode; } -void Gfx::CEngine::SetParticleDensity(float value) +void CEngine::SetParticleDensity(float value) { if (value < 0.0f) value = 0.0f; if (value > 2.0f) value = 2.0f; m_particleDensity = value; } -float Gfx::CEngine::GetParticleDensity() +float CEngine::GetParticleDensity() { return m_particleDensity; } -float Gfx::CEngine::ParticleAdapt(float factor) +float CEngine::ParticleAdapt(float factor) { if (m_particleDensity == 0.0f) return 1000000.0f; @@ -2492,31 +2522,31 @@ float Gfx::CEngine::ParticleAdapt(float factor) return factor / m_particleDensity; } -void Gfx::CEngine::SetClippingDistance(float value) +void CEngine::SetClippingDistance(float value) { if (value < 0.5f) value = 0.5f; if (value > 2.0f) value = 2.0f; m_clippingDistance = value; } -float Gfx::CEngine::GetClippingDistance() +float CEngine::GetClippingDistance() { return m_clippingDistance; } -void Gfx::CEngine::SetObjectDetail(float value) +void CEngine::SetObjectDetail(float value) { if ( value < 0.0f ) value = 0.0f; if ( value > 2.0f ) value = 2.0f; m_objectDetail = value; } -float Gfx::CEngine::GetObjectDetail() +float CEngine::GetObjectDetail() { return m_objectDetail; } -void Gfx::CEngine::SetGadgetQuantity(float value) +void CEngine::SetGadgetQuantity(float value) { if (value < 0.0f) value = 0.0f; if (value > 1.0f) value = 1.0f; @@ -2524,12 +2554,12 @@ void Gfx::CEngine::SetGadgetQuantity(float value) m_gadgetQuantity = value; } -float Gfx::CEngine::GetGadgetQuantity() +float CEngine::GetGadgetQuantity() { return m_gadgetQuantity; } -void Gfx::CEngine::SetTextureQuality(int value) +void CEngine::SetTextureQuality(int value) { if (value < 0) value = 0; if (value > 2) value = 2; @@ -2541,187 +2571,167 @@ void Gfx::CEngine::SetTextureQuality(int value) } } -int Gfx::CEngine::GetTextureQuality() +int CEngine::GetTextureQuality() { return m_textureQuality; } -void Gfx::CEngine::SetTotoMode(bool present) +void CEngine::SetTotoMode(bool present) { m_totoMode = present; } -bool Gfx::CEngine::GetTotoMode() +bool CEngine::GetTotoMode() { return m_totoMode; } -void Gfx::CEngine::SetLensMode(bool present) +void CEngine::SetLensMode(bool present) { m_lensMode = present; } -bool Gfx::CEngine::GetLensMode() +bool CEngine::GetLensMode() { return m_lensMode; } -void Gfx::CEngine::SetWaterMode(bool present) +void CEngine::SetWaterMode(bool present) { m_waterMode = present; } -bool Gfx::CEngine::GetWaterMode() +bool CEngine::GetWaterMode() { return m_waterMode; } -void Gfx::CEngine::SetLightingMode(bool present) +void CEngine::SetLightingMode(bool present) { m_lightMode = present; } -bool Gfx::CEngine::GetLightingMode() +bool CEngine::GetLightingMode() { return m_lightMode; } -void Gfx::CEngine::SetSkyMode(bool present) +void CEngine::SetSkyMode(bool present) { m_skyMode = present; } -bool Gfx::CEngine::GetSkyMode() +bool CEngine::GetSkyMode() { return m_skyMode; } -void Gfx::CEngine::SetBackForce(bool present) +void CEngine::SetBackForce(bool present) { m_backForce = present; } -bool Gfx::CEngine::GetBackForce() +bool CEngine::GetBackForce() { return m_backForce; } -void Gfx::CEngine::SetPlanetMode(bool present) +void CEngine::SetPlanetMode(bool present) { m_planetMode = present; } -bool Gfx::CEngine::GetPlanetMode() +bool CEngine::GetPlanetMode() { return m_planetMode; } -void Gfx::CEngine::SetLightMode(bool present) +void CEngine::SetLightMode(bool present) { m_lightMode = present; } -bool Gfx::CEngine::GetLightMode() +bool CEngine::GetLightMode() { return m_lightMode; } -void Gfx::CEngine::SetEditIndentMode(bool autoIndent) +void CEngine::SetEditIndentMode(bool autoIndent) { m_editIndentMode = autoIndent; } -bool Gfx::CEngine::GetEditIndentMode() +bool CEngine::GetEditIndentMode() { return m_editIndentMode; } -void Gfx::CEngine::SetEditIndentValue(int value) +void CEngine::SetEditIndentValue(int value) { m_editIndentValue = value; } -int Gfx::CEngine::GetEditIndentValue() +int CEngine::GetEditIndentValue() { return m_editIndentValue; } -void Gfx::CEngine::SetTracePrecision(float factor) +void CEngine::SetTracePrecision(float factor) { m_tracePrecision = factor; } -float Gfx::CEngine::GetTracePrecision() +float CEngine::GetTracePrecision() { return m_tracePrecision; } -void Gfx::CEngine::SetMouseVisible(bool visible) -{ - m_mouseVisible = visible; -} - -bool Gfx::CEngine::GetMouseVisible() -{ - return m_mouseVisible; -} - -void Gfx::CEngine::SetMousePos(Math::Point pos) -{ - m_mousePos = pos; -} - -Math::Point Gfx::CEngine::GetMousePos() -{ - return m_mousePos; -} - -void Gfx::CEngine::SetMouseType(Gfx::EngineMouseType type) +void CEngine::SetMouseType(EngineMouseType type) { m_mouseType = type; } -Gfx::EngineMouseType Gfx::CEngine::GetMouseType() +EngineMouseType CEngine::GetMouseType() { return m_mouseType; } -const Math::Matrix& Gfx::CEngine::GetMatView() +const Math::Matrix& CEngine::GetMatView() { return m_matView; } -Math::Vector Gfx::CEngine::GetEyePt() +Math::Vector CEngine::GetEyePt() { return m_eyePt; } -Math::Vector Gfx::CEngine::GetLookatPt() +Math::Vector CEngine::GetLookatPt() { return m_lookatPt; } -float Gfx::CEngine::GetEyeDirH() +float CEngine::GetEyeDirH() { return m_eyeDirH; } -float Gfx::CEngine::GetEyeDirV() +float CEngine::GetEyeDirV() { return m_eyeDirV; } -bool Gfx::CEngine::IsVisiblePoint(const Math::Vector &pos) +bool CEngine::IsVisiblePoint(const Math::Vector &pos) { return Math::Distance(m_eyePt, pos) <= m_deepView[0]; } -void Gfx::CEngine::UpdateMatProj() +void CEngine::UpdateMatProj() { - m_device->SetTransform(Gfx::TRANSFORM_PROJECTION, m_matProj); + m_device->SetTransform(TRANSFORM_PROJECTION, m_matProj); } -void Gfx::CEngine::ApplyChange() +void CEngine::ApplyChange() { m_deepView[0] /= m_lastClippingDistance; m_deepView[1] /= m_lastClippingDistance; @@ -2744,18 +2754,18 @@ void Gfx::CEngine::ApplyChange() /** This function sets up render states, clears the viewport, and renders the scene. */ -void Gfx::CEngine::Render() +void CEngine::Render() { if (! m_render) return; m_statisticTriangle = 0; m_lastState = -1; - m_lastColor = Gfx::Color(-1.0f); - m_lastMaterial = Gfx::Material(); + m_lastColor = Color(-1.0f); + m_lastMaterial = Material(); m_lightMan->UpdateLights(); - Gfx::Color color; + Color color; if (m_skyMode && m_cloud->GetLevel() != 0.0f) // clouds? color = m_backgroundCloudDown; else @@ -2775,7 +2785,7 @@ void Gfx::CEngine::Render() m_device->EndScene(); } -void Gfx::CEngine::Draw3DScene() +void CEngine::Draw3DScene() { if (m_groundSpotVisible) UpdateGroundSpotTextures(); @@ -2787,28 +2797,28 @@ void Gfx::CEngine::Draw3DScene() // Display the objects - m_device->SetRenderState(Gfx::RENDER_STATE_DEPTH_TEST, true); - m_device->SetRenderState(Gfx::RENDER_STATE_LIGHTING, true); - m_device->SetRenderState(Gfx::RENDER_STATE_FOG, true); -// -// float fogStart = m_deepView[m_rankView]*m_fogStart[m_rankView]; -// float fogEnd = m_deepView[m_rankView]; - m_device->SetFogParams(Gfx::FOG_LINEAR, m_fogColor[m_rankView], fogStart, fogEnd, 1.0f); + m_device->SetRenderState(RENDER_STATE_DEPTH_TEST, true); + m_device->SetRenderState(RENDER_STATE_LIGHTING, true); + m_device->SetRenderState(RENDER_STATE_FOG, true); + + float fogStart = m_deepView[m_rankView]*m_fogStart[m_rankView]; + float fogEnd = m_deepView[m_rankView]; + m_device->SetFogParams(FOG_LINEAR, m_fogColor[m_rankView], fogStart, fogEnd, 1.0f); - m_device->SetTransform(Gfx::TRANSFORM_PROJECTION, m_matProj); - m_device->SetTransform(Gfx::TRANSFORM_VIEW, m_matView); + m_device->SetTransform(TRANSFORM_PROJECTION, m_matProj); + m_device->SetTransform(TRANSFORM_VIEW, m_matView); if (m_waterMode) m_water->DrawBack(); // draws water background if (m_shadowVisible) { - m_lightMan->UpdateLightsEnableState(Gfx::ENG_OBJTYPE_TERRAIN); + m_lightMan->UpdateLightsEnableState(ENG_OBJTYPE_TERRAIN); // Draw the terrain for (int l1 = 0; l1 < static_cast<int>( m_objectTree.size() ); l1++) { - Gfx::EngineObjLevel1& p1 = m_objectTree[l1]; + EngineObjLevel1& p1 = m_objectTree[l1]; if (! p1.used) continue; // Should be loaded by now @@ -2817,23 +2827,23 @@ void Gfx::CEngine::Draw3DScene() for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++) { - Gfx::EngineObjLevel2& p2 = p1.next[l2]; + EngineObjLevel2& p2 = p1.next[l2]; if (! p2.used) continue; int objRank = p2.objRank; - if (m_objects[objRank].type != Gfx::ENG_OBJTYPE_TERRAIN) + if (m_objects[objRank].type != ENG_OBJTYPE_TERRAIN) continue; if (! m_objects[objRank].drawWorld) continue; - m_device->SetTransform(Gfx::TRANSFORM_WORLD, m_objects[objRank].transform); + m_device->SetTransform(TRANSFORM_WORLD, m_objects[objRank].transform); if (! IsVisible(objRank)) continue; for (int l3 = 0; l3 < static_cast<int>( p2.next.size() ); l3++) { - Gfx::EngineObjLevel3& p3 = p2.next[l3]; + EngineObjLevel3& p3 = p2.next[l3]; if (! p3.used) continue; if ( m_objects[objRank].distance < p3.min || @@ -2842,22 +2852,22 @@ void Gfx::CEngine::Draw3DScene() for (int l4 = 0; l4 < static_cast<int>( p3.next.size() ); l4++) { - Gfx::EngineObjLevel4& p4 = p3.next[l4]; + EngineObjLevel4& p4 = p3.next[l4]; if (! p4.used) continue; SetMaterial(p4.material); SetState(p4.state); - if (p4.type == Gfx::ENG_TRIANGLE_TYPE_TRIANGLES) + if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES) { - m_device->DrawPrimitive( Gfx::PRIMITIVE_TRIANGLES, + m_device->DrawPrimitive( PRIMITIVE_TRIANGLES, &p4.vertices[0], p4.vertices.size() ); m_statisticTriangle += p4.vertices.size() / 3; } - if (p4.type == Gfx::ENG_TRIANGLE_TYPE_SURFACE) + if (p4.type == ENG_TRIANGLE_TYPE_SURFACE) { - m_device->DrawPrimitive( Gfx::PRIMITIVE_TRIANGLE_STRIP, + m_device->DrawPrimitive( PRIMITIVE_TRIANGLE_STRIP, &p4.vertices[0], p4.vertices.size() ); m_statisticTriangle += p4.vertices.size() - 2; @@ -2877,7 +2887,7 @@ void Gfx::CEngine::Draw3DScene() for (int l1 = 0; l1 < static_cast<int>( m_objectTree.size() ); l1++) { - Gfx::EngineObjLevel1& p1 = m_objectTree[l1]; + EngineObjLevel1& p1 = m_objectTree[l1]; if (! p1.used) continue; // Should be loaded by now @@ -2886,18 +2896,18 @@ void Gfx::CEngine::Draw3DScene() for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++) { - Gfx::EngineObjLevel2& p2 = p1.next[l2]; + EngineObjLevel2& p2 = p1.next[l2]; if (! p2.used) continue; int objRank = p2.objRank; - if (m_shadowVisible && m_objects[objRank].type == Gfx::ENG_OBJTYPE_TERRAIN) + if (m_shadowVisible && m_objects[objRank].type == ENG_OBJTYPE_TERRAIN) continue; if (! m_objects[objRank].drawWorld) continue; - m_device->SetTransform(Gfx::TRANSFORM_WORLD, m_objects[objRank].transform); + m_device->SetTransform(TRANSFORM_WORLD, m_objects[objRank].transform); if (! IsVisible(objRank)) continue; @@ -2906,7 +2916,7 @@ void Gfx::CEngine::Draw3DScene() for (int l3 = 0; l3 < static_cast<int>( p2.next.size() ); l3++) { - Gfx::EngineObjLevel3& p3 = p2.next[l3]; + EngineObjLevel3& p3 = p2.next[l3]; if (! p3.used) continue; if ( m_objects[objRank].distance < p3.min || @@ -2914,7 +2924,7 @@ void Gfx::CEngine::Draw3DScene() for (int l4 = 0; l4 < static_cast<int>( p3.next.size() ); l4++) { - Gfx::EngineObjLevel4& p4 = p3.next[l4]; + EngineObjLevel4& p4 = p3.next[l4]; if (! p4.used) continue; if (m_objects[objRank].transparency != 0.0f) // transparent ? @@ -2926,17 +2936,17 @@ void Gfx::CEngine::Draw3DScene() SetMaterial(p4.material); SetState(p4.state); - if (p4.type == Gfx::ENG_TRIANGLE_TYPE_TRIANGLES) + if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES) { - m_device->DrawPrimitive( Gfx::PRIMITIVE_TRIANGLES, + m_device->DrawPrimitive( PRIMITIVE_TRIANGLES, &p4.vertices[0], p4.vertices.size() ); m_statisticTriangle += p4.vertices.size() / 3; } - else if (p4.type == Gfx::ENG_TRIANGLE_TYPE_SURFACE) + else if (p4.type == ENG_TRIANGLE_TYPE_SURFACE) { - m_device->DrawPrimitive( Gfx::PRIMITIVE_TRIANGLE_STRIP, + m_device->DrawPrimitive( PRIMITIVE_TRIANGLE_STRIP, &p4.vertices[0], p4.vertices.size() ); @@ -2952,21 +2962,21 @@ void Gfx::CEngine::Draw3DScene() if (transparent) { int tState = 0; - Gfx::Color tColor; + Color tColor; if (m_stateColor) { - tState = Gfx::ENG_RSTATE_TTEXTURE_BLACK | Gfx::ENG_RSTATE_2FACE; - tColor = Gfx::Color(68.0f / 255.0f, 68.0f / 255.0f, 68.0f / 255.0f, 68.0f / 255.0f); + 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 = Gfx::ENG_RSTATE_TCOLOR_BLACK; - tColor = Gfx::Color(136.0f / 255.0f, 136.0f / 255.0f, 136.0f / 255.0f, 136.0f / 255.0f); + tState = ENG_RSTATE_TCOLOR_BLACK; + tColor = Color(136.0f / 255.0f, 136.0f / 255.0f, 136.0f / 255.0f, 136.0f / 255.0f); } for (int l1 = 0; l1 < static_cast<int>( m_objectTree.size() ); l1++) { - Gfx::EngineObjLevel1& p1 = m_objectTree[l1]; + EngineObjLevel1& p1 = m_objectTree[l1]; if (! p1.used) continue; // Should be loaded by now @@ -2975,18 +2985,18 @@ void Gfx::CEngine::Draw3DScene() for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++) { - Gfx::EngineObjLevel2& p2 = p1.next[l2]; + EngineObjLevel2& p2 = p1.next[l2]; if (! p2.used) continue; int objRank = p2.objRank; - if (m_shadowVisible && m_objects[objRank].type == Gfx::ENG_OBJTYPE_TERRAIN) + if (m_shadowVisible && m_objects[objRank].type == ENG_OBJTYPE_TERRAIN) continue; if (! m_objects[objRank].drawWorld) continue; - m_device->SetTransform(Gfx::TRANSFORM_WORLD, m_objects[objRank].transform); + m_device->SetTransform(TRANSFORM_WORLD, m_objects[objRank].transform); if (! IsVisible(objRank)) continue; @@ -2995,7 +3005,7 @@ void Gfx::CEngine::Draw3DScene() for (int l3 = 0; l3 < static_cast<int>( p2.next.size() ); l3++) { - Gfx::EngineObjLevel3& p3 = p2.next[l3]; + EngineObjLevel3& p3 = p2.next[l3]; if (! p3.used) continue; if ( m_objects[objRank].distance < p3.min || @@ -3003,7 +3013,7 @@ void Gfx::CEngine::Draw3DScene() for (int l4 = 0; l4 < static_cast<int>( p3.next.size() ); l4++) { - Gfx::EngineObjLevel4& p4 = p3.next[l4]; + EngineObjLevel4& p4 = p3.next[l4]; if (! p4.used) continue; if (m_objects[objRank].transparency == 0.0f) @@ -3012,17 +3022,17 @@ void Gfx::CEngine::Draw3DScene() SetMaterial(p4.material); SetState(tState, tColor); - if (p4.type == Gfx::ENG_TRIANGLE_TYPE_TRIANGLES) + if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES) { - m_device->DrawPrimitive( Gfx::PRIMITIVE_TRIANGLES, + m_device->DrawPrimitive( PRIMITIVE_TRIANGLES, &p4.vertices[0], p4.vertices.size() ); m_statisticTriangle += p4.vertices.size() / 3; } - else if (p4.type == Gfx::ENG_TRIANGLE_TYPE_SURFACE) + else if (p4.type == ENG_TRIANGLE_TYPE_SURFACE) { - m_device->DrawPrimitive( Gfx::PRIMITIVE_TRIANGLE_STRIP, + m_device->DrawPrimitive( PRIMITIVE_TRIANGLE_STRIP, &p4.vertices[0], p4.vertices.size() ); m_statisticTriangle += p4.vertices.size() - 2; @@ -3033,55 +3043,55 @@ void Gfx::CEngine::Draw3DScene() } } - m_lightMan->UpdateLightsEnableState(Gfx::ENG_OBJTYPE_TERRAIN); + m_lightMan->UpdateLightsEnableState(ENG_OBJTYPE_TERRAIN); if (m_waterMode) m_water->DrawSurf(); // draws water surface - m_particle->DrawParticle(Gfx::SH_WORLD); // draws the particles of the 3D world + m_particle->DrawParticle(SH_WORLD); // draws the particles of the 3D world m_lightning->Draw(); // draws lightning if (m_lensMode) DrawForegroundImage(); // draws the foreground if (! m_overFront) DrawOverColor(); // draws the foreground color } -void Gfx::CEngine::DrawInterface() +void CEngine::DrawInterface() { - m_device->SetRenderState(Gfx::RENDER_STATE_DEPTH_TEST, false); - m_device->SetRenderState(Gfx::RENDER_STATE_LIGHTING, false); - m_device->SetRenderState(Gfx::RENDER_STATE_FOG, false); + m_device->SetRenderState(RENDER_STATE_DEPTH_TEST, false); + m_device->SetRenderState(RENDER_STATE_LIGHTING, false); + m_device->SetRenderState(RENDER_STATE_FOG, false); - m_device->SetTransform(Gfx::TRANSFORM_VIEW, m_matViewInterface); - m_device->SetTransform(Gfx::TRANSFORM_PROJECTION, m_matProjInterface); - m_device->SetTransform(Gfx::TRANSFORM_WORLD, m_matWorldInterface); + m_device->SetTransform(TRANSFORM_VIEW, m_matViewInterface); + m_device->SetTransform(TRANSFORM_PROJECTION, m_matProjInterface); + m_device->SetTransform(TRANSFORM_WORLD, m_matWorldInterface); // Draw the entire interface Ui::CInterface* interface = static_cast<Ui::CInterface*>( m_iMan->SearchInstance(CLASS_INTERFACE) ); if (interface != nullptr) interface->Draw(); - m_particle->DrawParticle(Gfx::SH_INTERFACE); // draws the particles of the interface + m_particle->DrawParticle(SH_INTERFACE); // draws the particles of the interface // 3D objects drawn in front of interface if (m_drawFront) { // Display the objects - m_device->SetRenderState(Gfx::RENDER_STATE_DEPTH_TEST, true); + m_device->SetRenderState(RENDER_STATE_DEPTH_TEST, true); - m_device->SetTransform(Gfx::TRANSFORM_PROJECTION, m_matProj); + m_device->SetTransform(TRANSFORM_PROJECTION, m_matProj); m_device->SetGlobalAmbient(m_ambientColor[m_rankView]); - m_device->SetRenderState(Gfx::RENDER_STATE_LIGHTING, true); + m_device->SetRenderState(RENDER_STATE_LIGHTING, true); - m_device->SetRenderState(Gfx::RENDER_STATE_FOG, true); + m_device->SetRenderState(RENDER_STATE_FOG, true); float fogStart = m_deepView[m_rankView]*m_fogStart[m_rankView]; float fogEnd = m_deepView[m_rankView]; - m_device->SetFogParams(Gfx::FOG_LINEAR, m_fogColor[m_rankView], fogStart, fogEnd, 1.0f); + m_device->SetFogParams(FOG_LINEAR, m_fogColor[m_rankView], fogStart, fogEnd, 1.0f); - m_device->SetTransform(Gfx::TRANSFORM_VIEW, m_matView); + m_device->SetTransform(TRANSFORM_VIEW, m_matView); for (int l1 = 0; l1 < static_cast<int>( m_objectTree.size() ); l1++) { - Gfx::EngineObjLevel1& p1 = m_objectTree[l1]; + EngineObjLevel1& p1 = m_objectTree[l1]; if (! p1.used) continue; // Should be loaded by now @@ -3090,18 +3100,18 @@ void Gfx::CEngine::DrawInterface() for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++) { - Gfx::EngineObjLevel2& p2 = p1.next[l2]; + EngineObjLevel2& p2 = p1.next[l2]; if (! p2.used) continue; int objRank = p2.objRank; - if (m_shadowVisible && m_objects[objRank].type == Gfx::ENG_OBJTYPE_TERRAIN) + if (m_shadowVisible && m_objects[objRank].type == ENG_OBJTYPE_TERRAIN) continue; if (! m_objects[objRank].drawFront) continue; - m_device->SetTransform(Gfx::TRANSFORM_WORLD, m_objects[objRank].transform); + m_device->SetTransform(TRANSFORM_WORLD, m_objects[objRank].transform); if (! IsVisible(objRank)) continue; @@ -3110,7 +3120,7 @@ void Gfx::CEngine::DrawInterface() for (int l3 = 0; l3 < static_cast<int>( p2.next.size() ); l3++) { - Gfx::EngineObjLevel3& p3 = p2.next[l3]; + EngineObjLevel3& p3 = p2.next[l3]; if (! p3.used) continue; if ( m_objects[objRank].distance < p3.min || @@ -3118,23 +3128,23 @@ void Gfx::CEngine::DrawInterface() for (int l4 = 0; l4 < static_cast<int>( p3.next.size() ); l4++) { - Gfx::EngineObjLevel4& p4 = p3.next[l4]; + EngineObjLevel4& p4 = p3.next[l4]; if (! p4.used) continue; SetMaterial(p4.material); SetState(p4.state); - if (p4.type == Gfx::ENG_TRIANGLE_TYPE_TRIANGLES) + if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES) { - m_device->DrawPrimitive( Gfx::PRIMITIVE_TRIANGLES, + m_device->DrawPrimitive( PRIMITIVE_TRIANGLES, &p4.vertices[0], p4.vertices.size() ); m_statisticTriangle += p4.vertices.size() / 3; } - else if (p4.type == Gfx::ENG_TRIANGLE_TYPE_SURFACE) + else if (p4.type == ENG_TRIANGLE_TYPE_SURFACE) { - m_device->DrawPrimitive( Gfx::PRIMITIVE_TRIANGLE_STRIP, + m_device->DrawPrimitive( PRIMITIVE_TRIANGLE_STRIP, &p4.vertices[0], p4.vertices.size() ); m_statisticTriangle += p4.vertices.size() - 2; @@ -3144,45 +3154,46 @@ void Gfx::CEngine::DrawInterface() } } - m_particle->DrawParticle(Gfx::SH_FRONT); // draws the particles of the 3D world + m_particle->DrawParticle(SH_FRONT); // draws the particles of the 3D world - m_device->SetRenderState(Gfx::RENDER_STATE_DEPTH_TEST, false); - m_device->SetRenderState(Gfx::RENDER_STATE_LIGHTING, false); - m_device->SetRenderState(Gfx::RENDER_STATE_FOG, false); + m_device->SetRenderState(RENDER_STATE_DEPTH_TEST, false); + m_device->SetRenderState(RENDER_STATE_LIGHTING, false); + m_device->SetRenderState(RENDER_STATE_FOG, false); - m_device->SetTransform(Gfx::TRANSFORM_VIEW, m_matViewInterface); - m_device->SetTransform(Gfx::TRANSFORM_PROJECTION, m_matProjInterface); - m_device->SetTransform(Gfx::TRANSFORM_WORLD, m_matWorldInterface); + m_device->SetTransform(TRANSFORM_VIEW, m_matViewInterface); + m_device->SetTransform(TRANSFORM_PROJECTION, m_matProjInterface); + m_device->SetTransform(TRANSFORM_WORLD, m_matWorldInterface); } // Draw foreground color if (m_overFront) DrawOverColor(); - // Mouse & highlight at the end + // At the end to not overlap DrawMouse(); DrawHighlight(); + DrawStats(); } -void Gfx::CEngine::UpdateGroundSpotTextures() +void CEngine::UpdateGroundSpotTextures() { // TODO the original code modifying the textures is very complex, so stub for now GetLogger()->Trace("CEngine::UpdateGroundSpotTextures(): stub!\n"); } -void Gfx::CEngine::DrawShadow() +void CEngine::DrawShadow() { - m_device->SetRenderState(Gfx::RENDER_STATE_DEPTH_WRITE, false); - m_device->SetRenderState(Gfx::RENDER_STATE_LIGHTING, false); + m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, false); + m_device->SetRenderState(RENDER_STATE_LIGHTING, false); Math::Matrix matrix; matrix.LoadIdentity(); - m_device->SetTransform(Gfx::TRANSFORM_WORLD, matrix); + m_device->SetTransform(TRANSFORM_WORLD, matrix); - Gfx::Material material; - material.diffuse = Gfx::Color(1.0f, 1.0f, 1.0f); - material.ambient = Gfx::Color(0.5f, 0.5f, 0.5f); + Material material; + material.diffuse = Color(1.0f, 1.0f, 1.0f); + material.ambient = Color(0.5f, 0.5f, 0.5f); SetMaterial(material); // TODO: create a separate texture @@ -3263,7 +3274,7 @@ void Gfx::CEngine::DrawShadow() Math::Vector corner[4]; - if (m_shadows[i].type == Gfx::ENG_SHADOW_NORM) + if (m_shadows[i].type == ENG_SHADOW_NORM) { corner[0].x = +radius; corner[0].z = +radius; @@ -3308,7 +3319,7 @@ void Gfx::CEngine::DrawShadow() corner[3].z = rot.y; corner[3].y = 0.0f; - if (m_shadows[i].type == Gfx::ENG_SHADOW_WORM) + if (m_shadows[i].type == ENG_SHADOW_WORM) { ts.x = 96.0f/256.0f; ti.x = 128.0f/256.0f; @@ -3333,12 +3344,12 @@ void Gfx::CEngine::DrawShadow() ts.x += dp; ti.x -= dp; - Gfx::Vertex vertex[4] = + Vertex vertex[4] = { - Gfx::Vertex(corner[1], n, Math::Point(ts.x, ts.y)), - Gfx::Vertex(corner[0], n, Math::Point(ti.x, ts.y)), - Gfx::Vertex(corner[3], n, Math::Point(ts.x, ti.y)), - Gfx::Vertex(corner[2], n, Math::Point(ti.x, ti.y)) + Vertex(corner[1], n, Math::Point(ts.x, ts.y)), + Vertex(corner[0], n, Math::Point(ti.x, ts.y)), + Vertex(corner[3], n, Math::Point(ts.x, ti.y)), + Vertex(corner[2], n, Math::Point(ti.x, ti.y)) }; float intensity = (0.5f+m_shadows[i].intensity*0.5f)*hFactor; @@ -3353,19 +3364,19 @@ void Gfx::CEngine::DrawShadow() if (lastIntensity != intensity) // intensity changed? { lastIntensity = intensity; - SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE, Gfx::Color(intensity, intensity, intensity, intensity)); + SetState(ENG_RSTATE_TTEXTURE_WHITE, Color(intensity, intensity, intensity, intensity)); } - m_device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 4); + m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertex, 4); AddStatisticTriangle(2); } - m_device->SetRenderState(Gfx::RENDER_STATE_DEPTH_WRITE, true); - m_device->SetRenderState(Gfx::RENDER_STATE_LIGHTING, true); + m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, true); + m_device->SetRenderState(RENDER_STATE_LIGHTING, true); } // STATUS: TESTED, VERIFIED -void Gfx::CEngine::DrawBackground() +void CEngine::DrawBackground() { if (m_skyMode && m_cloud->GetLevel() != 0.0f) // clouds ? { @@ -3385,38 +3396,38 @@ void Gfx::CEngine::DrawBackground() } // STATUS: TESTED -void Gfx::CEngine::DrawBackgroundGradient(const Gfx::Color& up, const Gfx::Color& down) +void CEngine::DrawBackgroundGradient(const Color& up, const Color& down) { Math::Point p1(0.0f, 0.5f); Math::Point p2(1.0f, 1.0f); - Gfx::Color color[3] = + Color color[3] = { up, down, - Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f) + Color(0.0f, 0.0f, 0.0f, 0.0f) }; - SetState(Gfx::ENG_RSTATE_OPAQUE_COLOR); + SetState(ENG_RSTATE_OPAQUE_COLOR); - m_device->SetTransform(Gfx::TRANSFORM_VIEW, m_matViewInterface); - m_device->SetTransform(Gfx::TRANSFORM_PROJECTION, m_matProjInterface); - m_device->SetTransform(Gfx::TRANSFORM_WORLD, m_matWorldInterface); + m_device->SetTransform(TRANSFORM_VIEW, m_matViewInterface); + m_device->SetTransform(TRANSFORM_PROJECTION, m_matProjInterface); + m_device->SetTransform(TRANSFORM_WORLD, m_matWorldInterface); - Gfx::VertexCol vertex[4] = + VertexCol vertex[4] = { - Gfx::VertexCol(Math::Vector(p1.x, p1.y, 0.0f), color[1], color[2]), - Gfx::VertexCol(Math::Vector(p1.x, p2.y, 0.0f), color[0], color[2]), - Gfx::VertexCol(Math::Vector(p2.x, p1.y, 0.0f), color[1], color[2]), - Gfx::VertexCol(Math::Vector(p2.x, p2.y, 0.0f), color[0], color[2]) + VertexCol(Math::Vector(p1.x, p1.y, 0.0f), color[1], color[2]), + VertexCol(Math::Vector(p1.x, p2.y, 0.0f), color[0], color[2]), + VertexCol(Math::Vector(p2.x, p1.y, 0.0f), color[1], color[2]), + VertexCol(Math::Vector(p2.x, p2.y, 0.0f), color[0], color[2]) }; - m_device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 4); + m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertex, 4); AddStatisticTriangle(2); } // Status: TESTED, VERIFIED -void Gfx::CEngine::DrawBackgroundImage() +void CEngine::DrawBackgroundImage() { Math::Point p1, p2; p1.x = 0.0f; @@ -3453,41 +3464,41 @@ Math::Vector n = Math::Vector(0.0f, 0.0f, -1.0f); // normal v2 *= m_backgroundScale.y; SetTexture(m_backgroundTex); - SetState(Gfx::ENG_RSTATE_OPAQUE_TEXTURE | Gfx::ENG_RSTATE_WRAP); + SetState(ENG_RSTATE_OPAQUE_TEXTURE | ENG_RSTATE_WRAP); - m_device->SetTransform(Gfx::TRANSFORM_VIEW, m_matViewInterface); - m_device->SetTransform(Gfx::TRANSFORM_PROJECTION, m_matProjInterface); - m_device->SetTransform(Gfx::TRANSFORM_WORLD, m_matWorldInterface); + m_device->SetTransform(TRANSFORM_VIEW, m_matViewInterface); + m_device->SetTransform(TRANSFORM_PROJECTION, m_matProjInterface); + m_device->SetTransform(TRANSFORM_WORLD, m_matWorldInterface); - Gfx::Vertex vertex[4] = + Vertex vertex[4] = { - Gfx::Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(u1, v2)), - Gfx::Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(u1, v1)), - Gfx::Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(u2, v2)), - Gfx::Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(u2, v1)) + Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(u1, v2)), + Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(u1, v1)), + Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(u2, v2)), + Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(u2, v1)) }; - m_device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 4); + m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertex, 4); AddStatisticTriangle(2); } -void Gfx::CEngine::DrawPlanet() +void CEngine::DrawPlanet() { if (! m_planet->PlanetExist()) return; - m_device->SetRenderState(Gfx::RENDER_STATE_DEPTH_WRITE, false); - m_device->SetRenderState(Gfx::RENDER_STATE_LIGHTING, false); - m_device->SetRenderState(Gfx::RENDER_STATE_FOG, false); + m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, false); + m_device->SetRenderState(RENDER_STATE_LIGHTING, false); + m_device->SetRenderState(RENDER_STATE_FOG, false); - m_device->SetTransform(Gfx::TRANSFORM_VIEW, m_matViewInterface); - m_device->SetTransform(Gfx::TRANSFORM_PROJECTION, m_matProjInterface); - m_device->SetTransform(Gfx::TRANSFORM_WORLD, m_matWorldInterface); + m_device->SetTransform(TRANSFORM_VIEW, m_matViewInterface); + m_device->SetTransform(TRANSFORM_PROJECTION, m_matProjInterface); + m_device->SetTransform(TRANSFORM_WORLD, m_matWorldInterface); m_planet->Draw(); // draws the planets } // Status: PART_TESTED -void Gfx::CEngine::DrawForegroundImage() +void CEngine::DrawForegroundImage() { if (m_foregroundName.empty()) return; @@ -3503,70 +3514,70 @@ void Gfx::CEngine::DrawForegroundImage() float v2 = 1.0f; - Gfx::Vertex vertex[4] = + Vertex vertex[4] = { - Gfx::Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(u1, v2)), - Gfx::Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(u1, v1)), - Gfx::Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(u2, v2)), - Gfx::Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(u2, v1)) + Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(u1, v2)), + Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(u1, v1)), + Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(u2, v2)), + Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(u2, v1)) }; SetTexture(m_foregroundTex); - SetState(Gfx::ENG_RSTATE_CLAMP | Gfx::ENG_RSTATE_TTEXTURE_BLACK); + SetState(ENG_RSTATE_CLAMP | ENG_RSTATE_TTEXTURE_BLACK); - m_device->SetTransform(Gfx::TRANSFORM_VIEW, m_matViewInterface); - m_device->SetTransform(Gfx::TRANSFORM_PROJECTION, m_matProjInterface); - m_device->SetTransform(Gfx::TRANSFORM_WORLD, m_matWorldInterface); + m_device->SetTransform(TRANSFORM_VIEW, m_matViewInterface); + m_device->SetTransform(TRANSFORM_PROJECTION, m_matProjInterface); + m_device->SetTransform(TRANSFORM_WORLD, m_matWorldInterface); - m_device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 4); + m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertex, 4); AddStatisticTriangle(2); } // Status: PART_TESTED -void Gfx::CEngine::DrawOverColor() +void CEngine::DrawOverColor() { if (! m_stateColor) return; // TODO: fuzzy compare? - if ( (m_overColor == Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f) && m_overMode == Gfx::ENG_RSTATE_TCOLOR_BLACK) || - (m_overColor == Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f) && m_overMode == Gfx::ENG_RSTATE_TCOLOR_WHITE) ) return; + 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; Math::Point p1(0.0f, 0.0f); Math::Point p2(1.0f, 1.0f); - Gfx::Color color[3] = + Color color[3] = { m_overColor, m_overColor, - Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f) + Color(0.0f, 0.0f, 0.0f, 0.0f) }; SetState(m_overMode); // TODO: set also with m_overMode ? - m_device->SetRenderState(Gfx::RENDER_STATE_DEPTH_WRITE, false); - m_device->SetRenderState(Gfx::RENDER_STATE_LIGHTING, false); - m_device->SetRenderState(Gfx::RENDER_STATE_FOG, false); - m_device->SetRenderState(Gfx::RENDER_STATE_TEXTURING, false); + m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, false); + m_device->SetRenderState(RENDER_STATE_LIGHTING, false); + m_device->SetRenderState(RENDER_STATE_FOG, false); + m_device->SetRenderState(RENDER_STATE_TEXTURING, false); - m_device->SetTransform(Gfx::TRANSFORM_VIEW, m_matViewInterface); - m_device->SetTransform(Gfx::TRANSFORM_PROJECTION, m_matProjInterface); - m_device->SetTransform(Gfx::TRANSFORM_WORLD, m_matWorldInterface); + m_device->SetTransform(TRANSFORM_VIEW, m_matViewInterface); + m_device->SetTransform(TRANSFORM_PROJECTION, m_matProjInterface); + m_device->SetTransform(TRANSFORM_WORLD, m_matWorldInterface); - Gfx::VertexCol vertex[4] = + VertexCol vertex[4] = { - Gfx::VertexCol(Math::Vector(p1.x, p1.y, 0.0f), color[1], color[2]), - Gfx::VertexCol(Math::Vector(p1.x, p2.y, 0.0f), color[0], color[2]), - Gfx::VertexCol(Math::Vector(p2.x, p1.y, 0.0f), color[1], color[2]), - Gfx::VertexCol(Math::Vector(p2.x, p2.y, 0.0f), color[0], color[2]) + VertexCol(Math::Vector(p1.x, p1.y, 0.0f), color[1], color[2]), + VertexCol(Math::Vector(p1.x, p2.y, 0.0f), color[0], color[2]), + VertexCol(Math::Vector(p2.x, p1.y, 0.0f), color[1], color[2]), + VertexCol(Math::Vector(p2.x, p2.y, 0.0f), color[0], color[2]) }; - m_device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 4); + m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertex, 4); AddStatisticTriangle(2); } // Status: TESTED, VERIFIED -void Gfx::CEngine::DrawHighlight() +void CEngine::DrawHighlight() { Math::Point min, max; min.x = 1000000.0f; @@ -3615,7 +3626,7 @@ void Gfx::CEngine::DrawHighlight() if (nbOut > 2) return; - SetState(Gfx::ENG_RSTATE_OPAQUE_COLOR); + SetState(ENG_RSTATE_OPAQUE_COLOR); float d = 0.5f+sinf(m_highlightTime*6.0f)*0.5f; d *= (p2.x-p1.x)*0.1f; @@ -3624,13 +3635,13 @@ void Gfx::CEngine::DrawHighlight() p2.x -= d; p2.y -= d; - Gfx::Color color(1.0f, 1.0f, 0.0f); // yellow + Color color(1.0f, 1.0f, 0.0f); // yellow - Gfx::VertexCol line[3] = + VertexCol line[3] = { - Gfx::VertexCol(Math::Vector(), color), - Gfx::VertexCol(Math::Vector(), color), - Gfx::VertexCol(Math::Vector(), color) + VertexCol(Math::Vector(), color), + VertexCol(Math::Vector(), color), + VertexCol(Math::Vector(), color) }; float dx = (p2.x - p1.x) / 5.0f; @@ -3639,51 +3650,49 @@ void Gfx::CEngine::DrawHighlight() line[0].coord = Math::Vector(p1.x, p1.y + dy, 0.0f); line[1].coord = Math::Vector(p1.x, p1.y, 0.0f); line[2].coord = Math::Vector(p1.x + dx, p1.y, 0.0f); - m_device->DrawPrimitive(Gfx::PRIMITIVE_LINE_STRIP, line, 3); + m_device->DrawPrimitive(PRIMITIVE_LINE_STRIP, line, 3); line[0].coord = Math::Vector(p2.x - dx, p1.y, 0.0f); line[1].coord = Math::Vector(p2.x, p1.y, 0.0f); line[2].coord = Math::Vector(p2.x, p1.y + dy, 0.0f); - m_device->DrawPrimitive(Gfx::PRIMITIVE_LINE_STRIP, line, 3); + m_device->DrawPrimitive(PRIMITIVE_LINE_STRIP, line, 3); line[0].coord = Math::Vector(p2.x, p2.y - dy, 0.0f); line[1].coord = Math::Vector(p2.x, p2.y, 0.0f); line[2].coord = Math::Vector(p2.x - dx, p2.y, 0.0f); - m_device->DrawPrimitive(Gfx::PRIMITIVE_LINE_STRIP, line, 3); + m_device->DrawPrimitive(PRIMITIVE_LINE_STRIP, line, 3); line[0].coord = Math::Vector(p1.x + dx, p2.y, 0.0f); line[1].coord = Math::Vector(p1.x, p2.y, 0.0f); line[2].coord = Math::Vector(p1.x, p2.y - dy, 0.0f); - m_device->DrawPrimitive(Gfx::PRIMITIVE_LINE_STRIP, line, 3); + m_device->DrawPrimitive(PRIMITIVE_LINE_STRIP, line, 3); } // Status: TESTED, VERIFIED -void Gfx::CEngine::DrawMouse() +void CEngine::DrawMouse() { - if (! m_mouseVisible) + MouseMode mode = m_app->GetMouseMode(); + if (mode != MOUSE_ENGINE && mode != MOUSE_BOTH) return; - if (m_app->GetSystemMouseVisibile()) - return; - - Gfx::Material material; - material.diffuse = Gfx::Color(1.0f, 1.0f, 1.0f); - material.ambient = Gfx::Color(0.5f, 0.5f, 0.5f); + Material material; + material.diffuse = Color(1.0f, 1.0f, 1.0f); + material.ambient = Color(0.5f, 0.5f, 0.5f); m_device->SetMaterial(material); m_device->SetTexture(0, m_miceTexture); int index = static_cast<int>(m_mouseType); - Math::Point pos = m_mousePos; - pos.x = m_mousePos.x - (m_mice[index].hotPoint.x * m_mouseSize.x) / 32.0f; - pos.y = m_mousePos.y - ((32.0f - m_mice[index].hotPoint.y) * m_mouseSize.y) / 32.0f; + Math::Point pos = m_app->GetMousePos(); + pos.x = pos.x - (m_mice[index].hotPoint.x * m_mouseSize.x) / 32.0f; + pos.y = pos.y - ((32.0f - m_mice[index].hotPoint.y) * m_mouseSize.y) / 32.0f; Math::Point shadowPos; shadowPos.x = pos.x + (4.0f/800.0f); shadowPos.y = pos.y - (3.0f/600.0f); - SetState(Gfx::ENG_RSTATE_TCOLOR_WHITE); + SetState(ENG_RSTATE_TCOLOR_WHITE); DrawMouseSprite(shadowPos, m_mouseSize, m_mice[index].iconShadow); SetState(m_mice[index].mode1); @@ -3694,7 +3703,7 @@ void Gfx::CEngine::DrawMouse() } // Status: TESTED, VERIFIED -void Gfx::CEngine::DrawMouseSprite(Math::Point pos, Math::Point size, int icon) +void CEngine::DrawMouseSprite(Math::Point pos, Math::Point size, int icon) { if (icon == -1) return; @@ -3715,16 +3724,55 @@ void Gfx::CEngine::DrawMouseSprite(Math::Point pos, Math::Point size, int icon) Math::Vector normal(0.0f, 0.0f, -1.0f); - Gfx::Vertex vertex[4] = + Vertex vertex[4] = { - Gfx::Vertex(Math::Vector(p1.x, p1.y, 0.0f), normal, Math::Point(u1, v2)), - Gfx::Vertex(Math::Vector(p1.x, p2.y, 0.0f), normal, Math::Point(u1, v1)), - Gfx::Vertex(Math::Vector(p2.x, p1.y, 0.0f), normal, Math::Point(u2, v2)), - Gfx::Vertex(Math::Vector(p2.x, p2.y, 0.0f), normal, Math::Point(u2, v1)) + Vertex(Math::Vector(p1.x, p1.y, 0.0f), normal, Math::Point(u1, v2)), + Vertex(Math::Vector(p1.x, p2.y, 0.0f), normal, Math::Point(u1, v1)), + Vertex(Math::Vector(p2.x, p1.y, 0.0f), normal, Math::Point(u2, v2)), + Vertex(Math::Vector(p2.x, p2.y, 0.0f), normal, Math::Point(u2, v1)) }; - m_device->SetRenderState(Gfx::RENDER_STATE_DEPTH_TEST, false); - m_device->SetRenderState(Gfx::RENDER_STATE_DEPTH_WRITE, false); - m_device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 4); + m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertex, 4); AddStatisticTriangle(2); } + +void CEngine::DrawStats() +{ + if (!m_showStats) + return; + + std::stringstream str; + str << "Triangles: "; + str << m_statisticTriangle; + std::string triangleText = str.str(); + + float height = m_text->GetAscent(FONT_COLOBOT, 12.0f); + float width = 0.15f; + + Math::Point pos(0.04f, 0.04f + height); + + SetState(ENG_RSTATE_OPAQUE_COLOR); + + Gfx::Color black(0.0f, 0.0f, 0.0f, 0.0f); + + VertexCol vertex[4] = + { + VertexCol(Math::Vector(pos.x , pos.y - height, 0.0f), black), + VertexCol(Math::Vector(pos.x , pos.y + height, 0.0f), black), + VertexCol(Math::Vector(pos.x + width, pos.y - height, 0.0f), black), + VertexCol(Math::Vector(pos.x + width, pos.y + height, 0.0f), black) + }; + + m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertex, 4); + + SetState(ENG_RSTATE_TEXT); + + m_text->DrawText(triangleText, FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0); + + pos.y -= height; + + m_text->DrawText(m_fpsText, FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0); +} + + +} // namespace Gfx diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index 01a1dee..9d69a28 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -17,17 +17,21 @@ /** * \file graphics/engine/engine.h - * \brief Main graphics engine - Gfx::CEngine class + * \brief Main graphics engine - CEngine class */ #pragma once + #include "app/system.h" + #include "common/event.h" + #include "graphics/core/color.h" #include "graphics/core/material.h" #include "graphics/core/texture.h" #include "graphics/core/vertex.h" + #include "math/intpoint.h" #include "math/matrix.h" #include "math/point.h" @@ -46,8 +50,10 @@ class CObject; class CSoundInterface; +// Graphics module namespace namespace Gfx { + class CDevice; class CLightManager; class CText; @@ -60,11 +66,12 @@ class CTerrain; /** - \enum EngineRenderState - \brief Render state of graphics engine - - States are used for settings certain modes, for instance texturing and blending. - The enum is a bitmask and some of the states can be OR'd together. */ + * \enum EngineRenderState + * \brief Render state of graphics engine + * + * States are used for settings certain modes, for instance texturing and blending. + * The enum is a bitmask and some of the states can be OR'd together. + */ enum EngineRenderState { //! Normal opaque materials @@ -115,8 +122,9 @@ enum EngineRenderState /** - \enum EngineTriangleType - \brief Type of triangles drawn for engine objects */ + * \enum EngineTriangleType + * \brief Type of triangles drawn for engine objects + */ enum EngineTriangleType { //! Triangles @@ -126,24 +134,25 @@ enum EngineTriangleType }; /** - \struct EngineTriangle - \brief A triangle drawn by the graphics engine */ + * \struct EngineTriangle + * \brief A triangle drawn by the graphics engine + */ struct EngineTriangle { //! Triangle vertices - Gfx::VertexTex2 triangle[3]; + VertexTex2 triangle[3]; //! Material - Gfx::Material material; + Material material; //! Render state - int state; + int state; //! 1st texture - std::string tex1Name; + std::string tex1Name; //! 2nd texture - std::string tex2Name; + std::string tex2Name; EngineTriangle() { - state = Gfx::ENG_RSTATE_NORMAL; + state = ENG_RSTATE_NORMAL; } }; @@ -169,8 +178,9 @@ enum EngineObjectType }; /** - \struct EngineObject - \brief Object drawn by the graphics engine */ + * \struct EngineObject + * \brief Object drawn by the graphics engine + */ struct EngineObject { //! If true, object is valid in objects vector @@ -184,7 +194,7 @@ struct EngineObject //! Number of triangles int totalTriangles; //! Type of object - Gfx::EngineObjectType type; + EngineObjectType type; //! Transformation matrix Math::Matrix transform; //! Distance to object from eye point @@ -214,7 +224,7 @@ struct EngineObject drawWorld = false; drawFront = false; totalTriangles = 0; - type = Gfx::ENG_OBJTYPE_NULL; + type = ENG_OBJTYPE_NULL; transform.LoadIdentity(); bboxMax.LoadZero(); bboxMin.LoadZero(); @@ -231,66 +241,71 @@ struct EngineObjLevel3; struct EngineObjLevel4; /** - \struct EngineObjLevel4 - \brief Tier 4 of object tree */ + * \struct EngineObjLevel4 + * \brief Tier 4 of object tree + */ struct EngineObjLevel4 { - bool used; - Gfx::EngineTriangleType type; - Gfx::Material material; - int state; - std::vector<Gfx::VertexTex2> vertices; + bool used; + EngineTriangleType type; + Material material; + int state; + std::vector<VertexTex2> vertices; EngineObjLevel4(bool used = false, - Gfx::EngineTriangleType type = Gfx::ENG_TRIANGLE_TYPE_TRIANGLES, - const Gfx::Material& material = Gfx::Material(), - int state = Gfx::ENG_RSTATE_NORMAL); + EngineTriangleType type = ENG_TRIANGLE_TYPE_TRIANGLES, + const Material& material = Material(), + int state = ENG_RSTATE_NORMAL); }; /** - \struct EngineObjLevel3 - \brief Tier 3 of object tree */ + * \struct EngineObjLevel3 + * \brief Tier 3 of object tree + */ struct EngineObjLevel3 { - bool used; - float min; - float max; - std::vector<Gfx::EngineObjLevel4> next; + bool used; + float min; + float max; + std::vector<EngineObjLevel4> next; EngineObjLevel3(bool used = false, float min = 0.0f, float max = 0.0f); }; /** - \struct EngineObjLevel2 - \brief Tier 2 of object tree */ + * \struct EngineObjLevel2 + * \brief Tier 2 of object tree + */ struct EngineObjLevel2 { - bool used; - int objRank; - std::vector<Gfx::EngineObjLevel3> next; + bool used; + int objRank; + std::vector<EngineObjLevel3> next; EngineObjLevel2(bool used = false, int objRank = -1); }; /** - \struct EngineObjLevel1 - \brief Tier 1 of object tree */ + * \struct EngineObjLevel1 + * \brief Tier 1 of object tree + */ struct EngineObjLevel1 { - bool used; - std::string tex1Name; - Gfx::Texture tex1; - std::string tex2Name; - Gfx::Texture tex2; - std::vector<Gfx::EngineObjLevel2> next; + bool used; + std::string tex1Name; + Texture tex1; + std::string tex2Name; + Texture tex2; + std::vector<EngineObjLevel2> next; EngineObjLevel1(bool used = false, const std::string& tex1Name = "", const std::string& tex2Name = ""); }; /** - \struct EngineShadowType - \brief Type of shadow drawn by the graphics engine */ + * \struct EngineShadowType + * \brief Type of shadow drawn by the graphics engine + */ enum EngineShadowType { //! Normal shadow @@ -300,8 +315,9 @@ enum EngineShadowType }; /** - \struct EngineShadow - \brief Shadow drawn by the graphics engine */ + * \struct EngineShadow + * \brief Shadow drawn by the graphics engine + */ struct EngineShadow { //! If true, shadow is valid @@ -311,7 +327,7 @@ struct EngineShadow //! Rank of the associated object int objRank; //! Type of shadow - Gfx::EngineShadowType type; + EngineShadowType type; //! Position of the shadow Math::Vector pos; //! Normal to the terrain @@ -335,7 +351,7 @@ struct EngineShadow used = false; hide = false; objRank = 0; - type = Gfx::ENG_SHADOW_NORM; + type = ENG_SHADOW_NORM; pos.LoadZero(); normal.LoadZero(); angle = radius = intensity = height = 0.0f; @@ -343,14 +359,15 @@ struct EngineShadow }; /** - \struct EngineGroundSpot - \brief A spot (large shadow) drawn on the ground by the graphics engine */ + * \struct EngineGroundSpot + * \brief A spot (large shadow) drawn on the ground by the graphics engine + */ struct EngineGroundSpot { //! If true, ground spot is valid bool used; //! Color of the shadow - Gfx::Color color; + Color color; //! Min altitude float min; //! Max altitude @@ -374,7 +391,7 @@ struct EngineGroundSpot void LoadDefault() { used = false; - color = Gfx::Color(); + color = Color(); pos.LoadZero(); drawPos.LoadZero(); min = max = smooth = radius = drawRadius = 0.0f; @@ -382,8 +399,9 @@ struct EngineGroundSpot }; /** - \enum EngineGroundMarkPhase - \brief Phase of life of an EngineGroundMark */ + * \enum EngineGroundMarkPhase + * \brief Phase of life of an EngineGroundMark + */ enum EngineGroundMarkPhase { //! Null phase @@ -397,14 +415,15 @@ enum EngineGroundMarkPhase }; /** - \struct EngineGroundMark - \brief A mark on ground drawn by the graphics engine */ + * \struct EngineGroundMark + * \brief A mark on ground drawn by the graphics engine + */ struct EngineGroundMark { //! If true, draw mark bool draw; //! Phase of life - Gfx::EngineGroundMarkPhase phase; + EngineGroundMarkPhase phase; //! Times for 3 life phases float delay[3]; //! Fixed time @@ -447,8 +466,8 @@ struct EngineGroundMark }; /** - \enum EngineTextureMapping - \brief Type of texture mapping + * \enum EngineTextureMapping + * \brief Type of texture mapping */ enum EngineTextureMapping { @@ -462,8 +481,9 @@ enum EngineTextureMapping /** - \enum EngineMouseType - \brief Type of mouse cursor displayed in-game */ + * \enum EngineMouseType + * \brief Type of mouse cursor displayed in-game + */ enum EngineMouseType { //! Normal cursor (arrow) @@ -506,8 +526,9 @@ enum EngineMouseType }; /** - \struct EngineMouse - \brief Information about mouse cursor */ + * \struct EngineMouse + * \brief Information about mouse cursor + */ struct EngineMouse { //! Index of texture element for 1st image @@ -517,15 +538,15 @@ struct EngineMouse //! Shadow texture part int iconShadow; //! Mode to render 1st image in - Gfx::EngineRenderState mode1; + EngineRenderState mode1; //! Mode to render 2nd image in - Gfx::EngineRenderState mode2; + EngineRenderState mode2; //! Hot point Math::Point hotPoint; EngineMouse(int icon1 = -1, int icon2 = -1, int iconShadow = -1, - Gfx::EngineRenderState mode1 = Gfx::ENG_RSTATE_NORMAL, - Gfx::EngineRenderState mode2 = Gfx::ENG_RSTATE_NORMAL, + EngineRenderState mode1 = ENG_RSTATE_NORMAL, + EngineRenderState mode2 = ENG_RSTATE_NORMAL, Math::Point hotPoint = Math::Point()) { this->icon1 = icon1; @@ -625,7 +646,7 @@ struct EngineMouse * Textures are loaded from a texture subdir in data directory. In the old code, textures were identified * by file name and loaded using some D3D util code. With new code and OpenGL backend, this approach is not * efficient - name comparison, etc. takes a lot of time. In the future, textures should be loaded once - * at object creation time, and then referenced to as Gfx::Texture structs, or even as unsigned int ID's + * at object creation time, and then referenced to as Texture structs, or even as unsigned int ID's * which is what OpenGL actually wants. The old method is kept for now, with mapping between texture names * and texture structs but it will also be subject to refactoring in the future. */ @@ -636,12 +657,12 @@ public: ~CEngine(); //! Sets the device to be used - void SetDevice(Gfx::CDevice* device); + void SetDevice(CDevice* device); //! Returns the current device - Gfx::CDevice* GetDevice(); + CDevice* GetDevice(); //! Sets the terrain object - void SetTerrain(Gfx::CTerrain* terrain); + void SetTerrain(CTerrain* terrain); //! Returns the text rendering engine CText* GetText(); @@ -737,8 +758,8 @@ public: //@{ //! Management of engine object type - bool SetObjectType(int objRank, Gfx::EngineObjectType type); - Gfx::EngineObjectType GetObjectType(int objRank); + bool SetObjectType(int objRank, EngineObjectType type); + EngineObjectType GetObjectType(int objRank); //@} //@{ @@ -762,30 +783,30 @@ public: int GetObjectTotalTriangles(int objRank); //! Adds triangles to given object with the specified params - bool AddTriangles(int objRank, const std::vector<Gfx::VertexTex2>& vertices, - const Gfx::Material& material, int state, + bool AddTriangles(int objRank, const std::vector<VertexTex2>& vertices, + const Material& material, int state, std::string tex1Name, std::string tex2Name, float min, float max, bool globalUpdate); //! Adds a surface to given object with the specified params - bool AddSurface(int objRank, const std::vector<Gfx::VertexTex2>& vertices, - const Gfx::Material& material, int state, + bool AddSurface(int objRank, const std::vector<VertexTex2>& vertices, + const Material& material, int state, std::string tex1Name, std::string tex2Name, float min, float max, bool globalUpdate); //! Adds a tier 4 engine object directly - bool AddQuick(int objRank, const Gfx::EngineObjLevel4& buffer, + bool AddQuick(int objRank, const EngineObjLevel4& buffer, std::string tex1Name, std::string tex2Name, float min, float max, bool globalUpdate); //! Returns the first found tier 4 engine object for the given params or nullptr if not found - Gfx::EngineObjLevel4* FindTriangles(int objRank, const Gfx::Material& material, + EngineObjLevel4* FindTriangles(int objRank, const Material& material, int state, std::string tex1Name, std::string tex2Name, float min, float max); //! Returns a partial list of triangles for given object int GetPartialTriangles(int objRank, float min, float max, float percent, int maxCount, - std::vector<Gfx::EngineTriangle>& triangles); + std::vector<EngineTriangle>& triangles); //! Updates LOD after parameter or resolution change void ChangeLOD(); @@ -794,15 +815,15 @@ public: bool ChangeSecondTexture(int objRank, const std::string& tex2Name); //! Changes (recalculates) texture mapping for given object - bool ChangeTextureMapping(int objRank, const Gfx::Material& mat, int state, + bool ChangeTextureMapping(int objRank, const Material& mat, int state, const std::string& tex1Name, const std::string& tex2Name, - float min, float max, Gfx::EngineTextureMapping mode, + float min, float max, EngineTextureMapping mode, float au, float bu, float av, float bv); //! Changes texture mapping for robot tracks - bool TrackTextureMapping(int objRank, const Gfx::Material& mat, int state, + bool TrackTextureMapping(int objRank, const Material& mat, int state, const std::string& tex1Name, const std::string& tex2Name, - float min, float max, Gfx::EngineTextureMapping mode, + float min, float max, EngineTextureMapping mode, float pos, float factor, float tl, float ts, float tt); //! Detects the target object that is selected with the mouse @@ -817,7 +838,7 @@ public: //@{ //! Management of different shadow params bool SetObjectShadowHide(int objRank, bool hide); - bool SetObjectShadowType(int objRank, Gfx::EngineShadowType type); + bool SetObjectShadowType(int objRank, EngineShadowType type); bool SetObjectShadowPos(int objRank, const Math::Vector& pos); bool SetObjectShadowNormal(int objRank, const Math::Vector& normal); bool SetObjectShadowAngle(int objRank, float angle); @@ -843,7 +864,7 @@ public: //! Management of different ground spot params bool SetObjectGroundSpotPos(int rank, const Math::Vector& pos); bool SetObjectGroundSpotRadius(int rank, float radius); - bool SetObjectGroundSpotColor(int rank, const Gfx::Color& color); + bool SetObjectGroundSpotColor(int rank, const Color& color); bool SetObjectGroundSpotMinMax(int rank, float min, float max); bool SetObjectGroundSpotSmooth(int rank, float smooth); //@} @@ -862,19 +883,19 @@ public: /* *************** Mode setting *************** */ //! Sets the current rendering state - void SetState(int state, const Gfx::Color& color = Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f)); + void SetState(int state, const Color& color = Color(1.0f, 1.0f, 1.0f, 1.0f)); //! Sets the current material - void SetMaterial(const Gfx::Material& mat); + void SetMaterial(const Material& mat); //! Specifies the location and direction of view void SetViewParams(const Math::Vector& eyePt, const Math::Vector& lookatPt, const Math::Vector& upVec, float eyeDistance); //! Loads texture, creating it if not already present - Gfx::Texture LoadTexture(const std::string& name); + Texture LoadTexture(const std::string& name); //! Loads texture, creating it with given params if not already present - Gfx::Texture LoadTexture(const std::string& name, const Gfx::TextureCreateParams& params); + Texture LoadTexture(const std::string& name, const TextureCreateParams& params); //! Loads all necessary textures bool LoadAllTextures(); @@ -882,12 +903,12 @@ public: /** If loading fails, returns false. */ bool SetTexture(const std::string& name, int stage = 0); //! Sets texture for given stage - void SetTexture(const Gfx::Texture& tex, int stage = 0); + void SetTexture(const Texture& tex, int stage = 0); //! Deletes the given texture, unloading it and removing from cache void DeleteTexture(const std::string& name); //! Deletes the given texture, unloading it and removing from cache - void DeleteTexture(const Gfx::Texture& tex); + void DeleteTexture(const Texture& tex); //@{ //! Border management (distance limits) depends of the resolution (LOD = level-of-detail) @@ -954,20 +975,20 @@ public: //@{ //! Ambient color management - void SetAmbientColor(const Gfx::Color& color, int rank = 0); - Gfx::Color GetAmbientColor(int rank = 0); + void SetAmbientColor(const Color& color, int rank = 0); + Color GetAmbientColor(int rank = 0); //@} //@{ //! Color management under water - void SetWaterAddColor(const Gfx::Color& color); - Gfx::Color GetWaterAddColor(); + void SetWaterAddColor(const Color& color); + Color GetWaterAddColor(); //@} //@{ //! Management of the fog color - void SetFogColor(const Gfx::Color& color, int rank = 0); - Gfx::Color GetFogColor(int rank = 0); + void SetFogColor(const Color& color, int rank = 0); + Color GetFogColor(int rank = 0); //@} //@{ @@ -989,11 +1010,11 @@ public: //@{ //! Management of the background image to use - void SetBackground(const std::string& name, Gfx::Color up = Gfx::Color(), Gfx::Color down = Gfx::Color(), - Gfx::Color cloudUp = Gfx::Color(), Gfx::Color cloudDown = Gfx::Color(), + 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)); - void GetBackground(std::string& name, Gfx::Color& up, Gfx::Color& down, - Gfx::Color& cloudUp, Gfx::Color& cloudDown, + void GetBackground(std::string& name, Color& up, Color& down, + Color& cloudUp, Color& cloudDown, bool& full, Math::Point& scale); //@} @@ -1002,7 +1023,7 @@ public: //! Specifies whether to draw the foreground void SetOverFront(bool front); //! Sets the foreground overlay color - void SetOverColor(const Gfx::Color& color = Gfx::Color(), int mode = ENG_RSTATE_TCOLOR_BLACK); + void SetOverColor(const Color& color = Color(), int mode = ENG_RSTATE_TCOLOR_BLACK); //@{ //! Management of the particle density @@ -1103,21 +1124,9 @@ public: //@} //@{ - //! Management of mouse cursor visibility - void SetMouseVisible(bool show); - bool GetMouseVisible(); - //@} - - //@{ - //! Management of mouse cursor position - void SetMousePos(Math::Point pos); - Math::Point GetMousePos(); - //@} - - //@{ //! Management of mouse cursor type - void SetMouseType(Gfx::EngineMouseType type); - Gfx::EngineMouseType GetMouseType(); + void SetMouseType(EngineMouseType type); + EngineMouseType GetMouseType(); //@} //! Returns the view matrix @@ -1153,7 +1162,7 @@ protected: //! Draws the gradient background void DrawBackground(); //! Draws the gradient background - void DrawBackgroundGradient(const Gfx::Color& up, const Gfx::Color& down); + void DrawBackgroundGradient(const Color& up, const Color& down); //! Draws the image background void DrawBackgroundImage(); //! Draws all the planets @@ -1168,19 +1177,21 @@ protected: void DrawMouse(); //! Draw part of mouse cursor sprite void DrawMouseSprite(Math::Point pos, Math::Point dim, int icon); + //! Draw statistic texts + void DrawStats(); //! Creates new tier 1 object - Gfx::EngineObjLevel1& AddLevel1(const std::string& tex1Name, const std::string& tex2Name); + EngineObjLevel1& AddLevel1(const std::string& tex1Name, const std::string& tex2Name); //! Creates a new tier 2 object - Gfx::EngineObjLevel2& AddLevel2(Gfx::EngineObjLevel1 &p1, int objRank); + EngineObjLevel2& AddLevel2(EngineObjLevel1 &p1, int objRank); //! Creates a new tier 3 object - Gfx::EngineObjLevel3& AddLevel3(Gfx::EngineObjLevel2 &p2, float min, float max); + EngineObjLevel3& AddLevel3(EngineObjLevel2 &p2, float min, float max); //! Creates a new tier 4 object - Gfx::EngineObjLevel4& AddLevel4(Gfx::EngineObjLevel3 &p3, Gfx::EngineTriangleType type, - const Gfx::Material& mat, int state); + EngineObjLevel4& AddLevel4(EngineObjLevel3 &p3, EngineTriangleType type, + const Material& mat, int state); //! Create texture and add it to cache - Gfx::Texture CreateTexture(const std::string &texName, const Gfx::TextureCreateParams ¶ms); + Texture CreateTexture(const std::string &texName, const TextureCreateParams ¶ms); //! Tests whether the given object is visible bool IsVisible(int objRank); @@ -1192,7 +1203,7 @@ protected: bool GetBBox2D(int objRank, Math::Point& min, Math::Point& max); //! Detects whether the mouse is in a triangle. - bool DetectTriangle(Math::Point mouse, Gfx::VertexTex2* triangle, int objRank, float& dist); + bool DetectTriangle(Math::Point mouse, VertexTex2* triangle, int objRank, float& dist); //! Transforms a 3D point (x, y, z) in 2D space (x, y, -) of the window /** The coordinated p2D.z gives the distance. */ @@ -1205,27 +1216,31 @@ protected: void UpdateGeometry(); protected: - CInstanceManager* m_iMan; - CApplication* m_app; - CSoundInterface* m_sound; - Gfx::CDevice* m_device; - Gfx::CText* m_text; - Gfx::CLightManager* m_lightMan; - Gfx::CParticle* m_particle; - Gfx::CWater* m_water; - Gfx::CCloud* m_cloud; - Gfx::CLightning* m_lightning; - Gfx::CPlanet* m_planet; - Gfx::CTerrain* m_terrain; + CInstanceManager* m_iMan; + CApplication* m_app; + CSoundInterface* m_sound; + CDevice* m_device; + CText* m_text; + CLightManager* m_lightMan; + CParticle* m_particle; + CWater* m_water; + CCloud* m_cloud; + CLightning* m_lightning; + CPlanet* m_planet; + CTerrain* m_terrain; //! Last encountered error std::string m_error; + SystemTimeStamp* m_lastFrameTime; + SystemTimeStamp* m_currentFrameTime; + int m_fpsCounter; + float m_fps; + //! Whether to show stats (FPS, etc) bool m_showStats; + std::string m_fpsText; - //! Speed of animation - float m_speed; //! Pause mode bool m_pause; //! Rendering enabled? @@ -1253,15 +1268,15 @@ protected: Math::IntPoint m_lastSize; //! Root of tree object structure (level 1 list) - std::vector<Gfx::EngineObjLevel1> m_objectTree; + std::vector<EngineObjLevel1> m_objectTree; //! Object parameters - std::vector<Gfx::EngineObject> m_objects; + std::vector<EngineObject> m_objects; //! Shadow list - std::vector<Gfx::EngineShadow> m_shadows; + std::vector<EngineShadow> m_shadows; //! Ground spot list - std::vector<Gfx::EngineGroundSpot> m_groundSpots; + std::vector<EngineGroundSpot> m_groundSpots; //! Ground mark - Gfx::EngineGroundMark m_groundMark; + EngineGroundMark m_groundMark; //! Location of camera Math::Vector m_eyePt; @@ -1270,12 +1285,12 @@ protected: float m_eyeDirH; float m_eyeDirV; int m_rankView; - Gfx::Color m_ambientColor[2]; - Gfx::Color m_backColor[2]; - Gfx::Color m_fogColor[2]; + Color m_ambientColor[2]; + Color m_backColor[2]; + Color m_fogColor[2]; float m_deepView[2]; float m_fogStart[2]; - Gfx::Color m_waterAddColor; + Color m_waterAddColor; int m_statisticTriangle; bool m_updateGeometry; int m_alphaMode; @@ -1290,16 +1305,16 @@ protected: bool m_backgroundFull; Math::Point m_backgroundScale; std::string m_backgroundName; - Gfx::Texture m_backgroundTex; - Gfx::Color m_backgroundColorUp; - Gfx::Color m_backgroundColorDown; - Gfx::Color m_backgroundCloudUp; - Gfx::Color m_backgroundCloudDown; + Texture m_backgroundTex; + Color m_backgroundColorUp; + Color m_backgroundColorDown; + Color m_backgroundCloudUp; + Color m_backgroundCloudDown; bool m_overFront; - Gfx::Color m_overColor; + Color m_overColor; int m_overMode; std::string m_foregroundName; - Gfx::Texture m_foregroundTex; + Texture m_foregroundTex; bool m_drawWorld; bool m_drawFront; float m_limitLOD[2]; @@ -1337,38 +1352,35 @@ protected: //! Texture directory name std::string m_texPath; //! Default texture create params - Gfx::TextureCreateParams m_defaultTexParams; + TextureCreateParams m_defaultTexParams; //! Map of loaded textures (by name) - std::map<std::string, Gfx::Texture> m_texNameMap; + std::map<std::string, Texture> m_texNameMap; //! Reverse map of loaded textures (by texture) - std::map<Gfx::Texture, std::string> m_revTexNameMap; + std::map<Texture, std::string> m_revTexNameMap; //! Blacklist map of textures /** Textures on this list were not successful in first loading, * so are disabled for subsequent load calls. */ std::set<std::string> m_texBlacklist; //! Mouse cursor definitions - Gfx::EngineMouse m_mice[Gfx::ENG_MOUSE_COUNT]; + EngineMouse m_mice[ENG_MOUSE_COUNT]; //! Texture with mouse cursors - Gfx::Texture m_miceTexture; + Texture m_miceTexture; //! Size of mouse cursor - Math::Point m_mouseSize; + Math::Point m_mouseSize; //! Type of mouse cursor - Gfx::EngineMouseType m_mouseType; - //! Position of mouse in interface coords - Math::Point m_mousePos; - //! Is mouse visible? - bool m_mouseVisible; + EngineMouseType m_mouseType; //! Last engine render state (-1 at the beginning of frame) int m_lastState; //! Last color set with render state - Gfx::Color m_lastColor; + Color m_lastColor; //! Last texture names for 2 used texture stages std::string m_lastTexture[2]; //! Last material - Gfx::Material m_lastMaterial; + Material m_lastMaterial; }; -}; // namespace Gfx + +} // namespace Gfx diff --git a/src/graphics/engine/lightman.cpp b/src/graphics/engine/lightman.cpp index 46000d7..02719de 100644 --- a/src/graphics/engine/lightman.cpp +++ b/src/graphics/engine/lightman.cpp @@ -15,18 +15,23 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// light.cpp #include "graphics/engine/lightman.h" #include "common/iman.h" + #include "graphics/core/device.h" + #include "math/geometry.h" + #include <cmath> -void Gfx::LightProgression::Init(float value) +namespace Gfx { + + +void LightProgression::Init(float value) { starting = value; ending = value; @@ -35,7 +40,7 @@ void Gfx::LightProgression::Init(float value) speed = 100.0f; } -void Gfx::LightProgression::Update(float rTime) +void LightProgression::Update(float rTime) { if (speed < 100.0f) { @@ -54,7 +59,7 @@ void Gfx::LightProgression::Update(float rTime) } } -void Gfx::LightProgression::SetTarget(float value) +void LightProgression::SetTarget(float value) { starting = current; ending = value; @@ -62,15 +67,15 @@ void Gfx::LightProgression::SetTarget(float value) } -Gfx::DynamicLight::DynamicLight() +DynamicLight::DynamicLight() { used = enabled = false; - includeType = excludeType = Gfx::ENG_OBJTYPE_NULL; + includeType = excludeType = ENG_OBJTYPE_NULL; } -Gfx::CLightManager::CLightManager(CInstanceManager* iMan, Gfx::CEngine* engine) +CLightManager::CLightManager(CInstanceManager* iMan, CEngine* engine) { m_iMan = iMan; m_iMan->AddInstance(CLASS_LIGHT, this); @@ -81,7 +86,7 @@ Gfx::CLightManager::CLightManager(CInstanceManager* iMan, Gfx::CEngine* engine) m_time = 0.0f; } -Gfx::CLightManager::~CLightManager() +CLightManager::~CLightManager() { m_iMan->DeleteInstance(CLASS_LIGHT, this); @@ -90,14 +95,14 @@ Gfx::CLightManager::~CLightManager() m_engine = NULL; } -void Gfx::CLightManager::SetDevice(Gfx::CDevice* device) +void CLightManager::SetDevice(CDevice* device) { m_device = device; - m_dynLights = std::vector<Gfx::DynamicLight>(m_device->GetMaxLightCount(), Gfx::DynamicLight()); + m_dynLights = std::vector<DynamicLight>(m_device->GetMaxLightCount(), DynamicLight()); } -void Gfx::CLightManager::FlushLights() +void CLightManager::FlushLights() { for (int i = 0; i < static_cast<int>( m_dynLights.size() ); i++) { @@ -107,22 +112,22 @@ void Gfx::CLightManager::FlushLights() } /** Returns the index of light created or -1 if all lights are used. */ -int Gfx::CLightManager::CreateLight() +int CLightManager::CreateLight() { for (int i = 0; i < static_cast<int>( m_dynLights.size() ); i++) { if (m_dynLights[i].used) continue; - m_dynLights[i] = Gfx::DynamicLight(); + m_dynLights[i] = DynamicLight(); m_dynLights[i].used = true; m_dynLights[i].enabled = true; - m_dynLights[i].includeType = Gfx::ENG_OBJTYPE_NULL; - m_dynLights[i].excludeType = Gfx::ENG_OBJTYPE_NULL; + m_dynLights[i].includeType = ENG_OBJTYPE_NULL; + m_dynLights[i].excludeType = ENG_OBJTYPE_NULL; - m_dynLights[i].light.type = Gfx::LIGHT_DIRECTIONAL; - m_dynLights[i].light.diffuse = Gfx::Color(0.5f, 0.5f, 0.5f); + m_dynLights[i].light.type = LIGHT_DIRECTIONAL; + m_dynLights[i].light.diffuse = Color(0.5f, 0.5f, 0.5f); m_dynLights[i].light.position = Math::Vector(-100.0f, 100.0f, -100.0f); m_dynLights[i].light.direction = Math::Vector( 1.0f, -1.0f, 1.0f); @@ -137,7 +142,7 @@ int Gfx::CLightManager::CreateLight() return -1; } -bool Gfx::CLightManager::DeleteLight(int lightRank) +bool CLightManager::DeleteLight(int lightRank) { if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) ) return false; @@ -148,7 +153,7 @@ bool Gfx::CLightManager::DeleteLight(int lightRank) return true; } -bool Gfx::CLightManager::SetLight(int lightRank, const Gfx::Light &light) +bool CLightManager::SetLight(int lightRank, const Light &light) { if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) ) return false; @@ -162,7 +167,7 @@ bool Gfx::CLightManager::SetLight(int lightRank, const Gfx::Light &light) return true; } -bool Gfx::CLightManager::GetLight(int lightRank, Gfx::Light &light) +bool CLightManager::GetLight(int lightRank, Light &light) { if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) ) return false; @@ -171,7 +176,7 @@ bool Gfx::CLightManager::GetLight(int lightRank, Gfx::Light &light) return true; } -bool Gfx::CLightManager::SetLightEnabled(int lightRank, bool enabled) +bool CLightManager::SetLightEnabled(int lightRank, bool enabled) { if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) ) return false; @@ -180,7 +185,7 @@ bool Gfx::CLightManager::SetLightEnabled(int lightRank, bool enabled) return true; } -bool Gfx::CLightManager::SetLightIncludeType(int lightRank, Gfx::EngineObjectType type) +bool CLightManager::SetLightIncludeType(int lightRank, EngineObjectType type) { if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) ) return false; @@ -189,7 +194,7 @@ bool Gfx::CLightManager::SetLightIncludeType(int lightRank, Gfx::EngineObjectTyp return true; } -bool Gfx::CLightManager::SetLightExcludeType(int lightRank, Gfx::EngineObjectType type) +bool CLightManager::SetLightExcludeType(int lightRank, EngineObjectType type) { if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) ) return false; @@ -198,7 +203,7 @@ bool Gfx::CLightManager::SetLightExcludeType(int lightRank, Gfx::EngineObjectTyp return true; } -bool Gfx::CLightManager::SetLightPos(int lightRank, const Math::Vector &pos) +bool CLightManager::SetLightPos(int lightRank, const Math::Vector &pos) { if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) ) return false; @@ -207,7 +212,7 @@ bool Gfx::CLightManager::SetLightPos(int lightRank, const Math::Vector &pos) return true; } -Math::Vector Gfx::CLightManager::GetLightPos(int lightRank) +Math::Vector CLightManager::GetLightPos(int lightRank) { if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) ) return Math::Vector(0.0f, 0.0f, 0.0f); @@ -215,7 +220,7 @@ Math::Vector Gfx::CLightManager::GetLightPos(int lightRank) return m_dynLights[lightRank].light.position; } -bool Gfx::CLightManager::SetLightDir(int lightRank, const Math::Vector &dir) +bool CLightManager::SetLightDir(int lightRank, const Math::Vector &dir) { if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) ) return false; @@ -224,7 +229,7 @@ bool Gfx::CLightManager::SetLightDir(int lightRank, const Math::Vector &dir) return true; } -Math::Vector Gfx::CLightManager::GetLightDir(int lightRank) +Math::Vector CLightManager::GetLightDir(int lightRank) { if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) ) return Math::Vector(0.0f, 0.0f, 0.0f); @@ -232,7 +237,7 @@ Math::Vector Gfx::CLightManager::GetLightDir(int lightRank) return m_dynLights[lightRank].light.direction; } -bool Gfx::CLightManager::SetLightIntensitySpeed(int lightRank, float speed) +bool CLightManager::SetLightIntensitySpeed(int lightRank, float speed) { if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) ) return false; @@ -241,7 +246,7 @@ bool Gfx::CLightManager::SetLightIntensitySpeed(int lightRank, float speed) return true; } -bool Gfx::CLightManager::SetLightIntensity(int lightRank, float value) +bool CLightManager::SetLightIntensity(int lightRank, float value) { if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) ) return false; @@ -250,7 +255,7 @@ bool Gfx::CLightManager::SetLightIntensity(int lightRank, float value) return true; } -float Gfx::CLightManager::GetLightIntensity(int lightRank) +float CLightManager::GetLightIntensity(int lightRank) { if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) ) return 0.0f; @@ -259,7 +264,7 @@ float Gfx::CLightManager::GetLightIntensity(int lightRank) } -bool Gfx::CLightManager::SetLightColorSpeed(int lightRank, float speed) +bool CLightManager::SetLightColorSpeed(int lightRank, float speed) { if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) ) return false; @@ -270,7 +275,7 @@ bool Gfx::CLightManager::SetLightColorSpeed(int lightRank, float speed) return true; } -bool Gfx::CLightManager::SetLightColor(int lightRank, const Gfx::Color &color) +bool CLightManager::SetLightColor(int lightRank, const Color &color) { if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) ) return false; @@ -281,26 +286,26 @@ bool Gfx::CLightManager::SetLightColor(int lightRank, const Gfx::Color &color) return true; } -Gfx::Color Gfx::CLightManager::GetLightColor(int lightRank) +Color CLightManager::GetLightColor(int lightRank) { if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) ) - return Gfx::Color(0.5f, 0.5f, 0.5f, 0.5f); + return Color(0.5f, 0.5f, 0.5f, 0.5f); - Gfx::Color color; + Color color; color.r = m_dynLights[lightRank].colorRed.current; color.g = m_dynLights[lightRank].colorGreen.current; color.b = m_dynLights[lightRank].colorBlue.current; return color; } -void Gfx::CLightManager::AdaptLightColor(const Gfx::Color &color, float factor) +void CLightManager::AdaptLightColor(const Color &color, float factor) { for (int i = 0; i < static_cast<int>( m_dynLights.size() ); i++) { if (! m_dynLights[i].used) continue; - Gfx::Color value; + Color value; value.r = m_dynLights[i].colorRed.current; value.g = m_dynLights[i].colorGreen.current; value.b = m_dynLights[i].colorBlue.current; @@ -317,7 +322,7 @@ void Gfx::CLightManager::AdaptLightColor(const Gfx::Color &color, float factor) UpdateLights(); } -void Gfx::CLightManager::UpdateProgression(float rTime) +void CLightManager::UpdateProgression(float rTime) { if (m_engine->GetPause()) return; @@ -334,14 +339,14 @@ void Gfx::CLightManager::UpdateProgression(float rTime) m_dynLights[i].colorGreen.Update(rTime); m_dynLights[i].colorBlue.Update(rTime); - if (m_dynLights[i].includeType == Gfx::ENG_OBJTYPE_QUARTZ) + if (m_dynLights[i].includeType == ENG_OBJTYPE_QUARTZ) { m_dynLights[i].light.direction.x = sinf(1.0f * (m_time + i*Math::PI*0.5f)); m_dynLights[i].light.direction.z = cosf(1.1f * (m_time + i*Math::PI*0.5f)); m_dynLights[i].light.direction.y = -1.0f + 0.5f * cosf((m_time + i*Math::PI*0.5f)*2.7f); } - if (m_dynLights[i].includeType == Gfx::ENG_OBJTYPE_METAL) + if (m_dynLights[i].includeType == ENG_OBJTYPE_METAL) { Math::Vector dir = m_engine->GetEyePt() - m_engine->GetLookatPt(); float angle = Math::RotateAngle(dir.x, dir.z); @@ -353,7 +358,7 @@ void Gfx::CLightManager::UpdateProgression(float rTime) } -void Gfx::CLightManager::UpdateLights() +void CLightManager::UpdateLights() { for (int i = 0; i < static_cast<int>( m_dynLights.size() ); i++) { @@ -389,7 +394,7 @@ void Gfx::CLightManager::UpdateLights() } } -void Gfx::CLightManager::UpdateLightsEnableState(Gfx::EngineObjectType type) +void CLightManager::UpdateLightsEnableState(EngineObjectType type) { for (int i = 0; i < static_cast<int>( m_dynLights.size() ); i++) { @@ -400,16 +405,19 @@ void Gfx::CLightManager::UpdateLightsEnableState(Gfx::EngineObjectType type) if (m_dynLights[i].intensity.current == 0.0f) continue; - if (m_dynLights[i].includeType != Gfx::ENG_OBJTYPE_NULL) + if (m_dynLights[i].includeType != ENG_OBJTYPE_NULL) { bool enabled = (m_dynLights[i].includeType == type); m_device->SetLightEnabled(i, enabled); } - if (m_dynLights[i].excludeType != Gfx::ENG_OBJTYPE_NULL) + if (m_dynLights[i].excludeType != ENG_OBJTYPE_NULL) { bool enabled = (m_dynLights[i].excludeType != type); m_device->SetLightEnabled(i, enabled); } } } + + +} // namespace Gfx diff --git a/src/graphics/engine/lightman.h b/src/graphics/engine/lightman.h index 52058c8..c50d176 100644 --- a/src/graphics/engine/lightman.h +++ b/src/graphics/engine/lightman.h @@ -17,7 +17,7 @@ /** * \file graphics/engine/lightman.h - * \brief Dynamic light manager - Gfx::CLightManager class + * \brief Dynamic light manager - CLightManager class */ #pragma once @@ -26,9 +26,11 @@ #include "graphics/core/color.h" #include "graphics/core/light.h" #include "graphics/engine/engine.h" + #include "math/vector.h" +// Graphics module namespace namespace Gfx { /** @@ -76,21 +78,21 @@ struct DynamicLight bool enabled; //! Configuration of the light - Gfx::Light light; + Light light; //! Progression of intensity [0, 1] - Gfx::LightProgression intensity; + LightProgression intensity; //! Progression of red diffuse color - Gfx::LightProgression colorRed; + LightProgression colorRed; //! Progression of green diffuse color - Gfx::LightProgression colorGreen; + LightProgression colorGreen; //! Progression of blue diffuse color - Gfx::LightProgression colorBlue; + LightProgression colorBlue; - //! Type of objects included in lighting with this light; if Gfx::ENG_OBJTYPE_NULL is used, it is ignored - Gfx::EngineObjectType includeType; - //! Type of objects excluded from lighting with this light; if Gfx::ENG_OBJTYPE_NULL is used, it is ignored - Gfx::EngineObjectType excludeType; + //! Type of objects included in lighting with this light; if ENG_OBJTYPE_NULL is used, it is ignored + EngineObjectType includeType; + //! Type of objects excluded from lighting with this light; if ENG_OBJTYPE_NULL is used, it is ignored + EngineObjectType excludeType; DynamicLight(); }; @@ -101,7 +103,7 @@ struct DynamicLight (Old CLight class) - The class is responsible for managing dynamic lights (struct Gfx::DynamicLight) used in 3D scene. + The class is responsible for managing dynamic lights (struct DynamicLight) used in 3D scene. The dynamic lights are created, updated and deleted through the class' interface. Number of available lights depends on graphics device used. Class allocates vector @@ -111,12 +113,12 @@ class CLightManager { public: //! Constructor - CLightManager(CInstanceManager *iMan, Gfx::CEngine* engine); + CLightManager(CInstanceManager *iMan, CEngine* engine); //! Destructor virtual ~CLightManager(); //! Sets the device to be used - void SetDevice(Gfx::CDevice* device); + void SetDevice(CDevice* device); //! Clears and disables all lights void FlushLights(); @@ -125,16 +127,16 @@ public: //! Deletes and disables the given dynamic light bool DeleteLight(int lightRank); //! Sets the light parameters for dynamic light - bool SetLight(int lightRank, const Gfx::Light &light); + bool SetLight(int lightRank, const Light &light); //! Returns the light parameters for given dynamic light - bool GetLight(int lightRank, Gfx::Light &light); + bool GetLight(int lightRank, Light &light); //! Enables/disables the given dynamic light bool SetLightEnabled(int lightRank, bool enable); //! Sets what objects are included in given dynamic light - bool SetLightIncludeType(int lightRank, Gfx::EngineObjectType type); + bool SetLightIncludeType(int lightRank, EngineObjectType type); //! Sets what objects are excluded from given dynamic light - bool SetLightExcludeType(int lightRank, Gfx::EngineObjectType type); + bool SetLightExcludeType(int lightRank, EngineObjectType type); //! Sets the position of dynamic light bool SetLightPos(int lightRank, const Math::Vector &pos); @@ -154,12 +156,12 @@ public: bool SetLightIntensitySpeed(int lightRank, float speed); //! Adjusts the color of all dynamic lights - void AdaptLightColor(const Gfx::Color &color, float factor); + void AdaptLightColor(const Color &color, float factor); //! Sets the destination color for dynamic light's color progression - bool SetLightColor(int lightRank, const Gfx::Color &color); + bool SetLightColor(int lightRank, const Color &color); //! Returns current light color - Gfx::Color GetLightColor(int lightRank); + Color GetLightColor(int lightRank); //! Sets the rate of change for dynamic light colors (RGB) bool SetLightColorSpeed(int lightRank, float speed); @@ -168,7 +170,7 @@ public: //! Updates (recalculates) all dynamic lights void UpdateLights(); //! Enables or disables dynamic lights affecting the given object type - void UpdateLightsEnableState(Gfx::EngineObjectType type); + void UpdateLightsEnableState(EngineObjectType type); protected: CInstanceManager* m_iMan; @@ -178,7 +180,7 @@ protected: //! Current time float m_time; //! List of dynamic lights - std::vector<Gfx::DynamicLight> m_dynLights; + std::vector<DynamicLight> m_dynLights; }; }; // namespace Gfx diff --git a/src/graphics/engine/lightning.cpp b/src/graphics/engine/lightning.cpp index b6b111a..1b9cbf1 100644 --- a/src/graphics/engine/lightning.cpp +++ b/src/graphics/engine/lightning.cpp @@ -15,75 +15,81 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// lightning.cpp (aka blitz.cpp) #include "graphics/engine/lightning.h" #include "common/logger.h" -Gfx::CLightning::CLightning(CInstanceManager* iMan, Gfx::CEngine* engine) +// Graphics module namespace +namespace Gfx { + + +CLightning::CLightning(CInstanceManager* iMan, CEngine* engine) { GetLogger()->Trace("CLightning::CLightning() stub!\n"); // TODO! } -Gfx::CLightning::~CLightning() +CLightning::~CLightning() { GetLogger()->Trace("CLightning::~CLightning() stub!\n"); // TODO! } -void Gfx::CLightning::Flush() +void CLightning::Flush() { GetLogger()->Trace("CLightning::Flush() stub!\n"); // TODO! } -bool Gfx::CLightning::EventProcess(const Event &event) +bool CLightning::EventProcess(const Event &event) { GetLogger()->Trace("CLightning::EventProcess() stub!\n"); // TODO! return true; } -bool Gfx::CLightning::Create(float sleep, float delay, float magnetic) +bool CLightning::Create(float sleep, float delay, float magnetic) { GetLogger()->Trace("CLightning::Create() stub!\n"); // TODO! return true; } -bool Gfx::CLightning::GetStatus(float &sleep, float &delay, float &magnetic, float &progress) +bool CLightning::GetStatus(float &sleep, float &delay, float &magnetic, float &progress) { GetLogger()->Trace("CLightning::GetStatus() stub!\n"); // TODO! return true; } -bool Gfx::CLightning::SetStatus(float sleep, float delay, float magnetic, float progress) +bool CLightning::SetStatus(float sleep, float delay, float magnetic, float progress) { GetLogger()->Trace("CLightning::SetStatus() stub!\n"); // TODO! return true; } -void Gfx::CLightning::Draw() +void CLightning::Draw() { GetLogger()->Trace("CLightning::Draw() stub!\n"); // TODO! } -bool Gfx::CLightning::EventFrame(const Event &event) +bool CLightning::EventFrame(const Event &event) { GetLogger()->Trace("CLightning::EventFrame() stub!\n"); // TODO! return true; } -CObject* Gfx::CLightning::SearchObject(Math::Vector pos) +CObject* CLightning::SearchObject(Math::Vector pos) { GetLogger()->Trace("CLightning::SearchObject() stub!\n"); // TODO! return nullptr; } + + +} // namespace Gfx diff --git a/src/graphics/engine/lightning.h b/src/graphics/engine/lightning.h index af389f2..d873c64 100644 --- a/src/graphics/engine/lightning.h +++ b/src/graphics/engine/lightning.h @@ -17,12 +17,14 @@ /** * \file graphics/engine/lightning.h - * \brief Lightning rendering - Gfx::CLightning class (aka blitz) + * \brief Lightning rendering - CLightning class (aka blitz) */ #pragma once + #include "common/event.h" + #include "math/vector.h" @@ -31,6 +33,7 @@ class CObject; class CSound; +// Graphics module namespace namespace Gfx { class CEngine; @@ -81,7 +84,7 @@ protected: float m_sleep; float m_delay; float m_magnetic; - Gfx::BlitzPhase m_phase; + BlitzPhase m_phase; float m_time; float m_speed; float m_progress; @@ -90,4 +93,5 @@ protected: float m_width[BLITZMAX]; }; -}; // namespace Gfx + +} // namespace Gfx diff --git a/src/graphics/engine/modelfile.cpp b/src/graphics/engine/modelfile.cpp index 2049749..c0d04a0 100644 --- a/src/graphics/engine/modelfile.cpp +++ b/src/graphics/engine/modelfile.cpp @@ -15,7 +15,6 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// modelfile.cpp (aka modfile.cpp) #include "graphics/engine/modelfile.h" @@ -23,10 +22,13 @@ #include "common/ioutils.h" #include "common/logger.h" #include "common/stringutils.h" + #include "graphics/engine/engine.h" + #include "math/geometry.h" -#include <string.h> + +#include <cstring> #include <fstream> #include <sstream> @@ -39,12 +41,16 @@ */ +// Graphics module namespace +namespace Gfx { + + //! How big the triangle vector is by default const int TRIANGLE_PREALLOCATE_COUNT = 2000; -bool ReadBinaryVertex(std::istream& stream, Gfx::Vertex& vertex) +bool ReadBinaryVertex(std::istream& stream, Vertex& vertex) { vertex.coord.x = IOUtils::ReadBinaryFloat(stream); vertex.coord.y = IOUtils::ReadBinaryFloat(stream); @@ -58,7 +64,7 @@ bool ReadBinaryVertex(std::istream& stream, Gfx::Vertex& vertex) return !stream.fail(); } -bool WriteBinaryVertex(Gfx::Vertex vertex, std::ostream& stream) +bool WriteBinaryVertex(Vertex vertex, std::ostream& stream) { IOUtils::WriteBinaryFloat(vertex.coord.x, stream); IOUtils::WriteBinaryFloat(vertex.coord.y, stream); @@ -72,7 +78,7 @@ bool WriteBinaryVertex(Gfx::Vertex vertex, std::ostream& stream) return !stream.fail(); } -bool ReadBinaryVertexTex2(std::istream& stream, Gfx::VertexTex2& vertex) +bool ReadBinaryVertexTex2(std::istream& stream, VertexTex2& vertex) { vertex.coord.x = IOUtils::ReadBinaryFloat(stream); vertex.coord.y = IOUtils::ReadBinaryFloat(stream); @@ -88,7 +94,7 @@ bool ReadBinaryVertexTex2(std::istream& stream, Gfx::VertexTex2& vertex) return !stream.fail(); } -bool WriteBinaryVertexTex2(Gfx::VertexTex2 vertex, std::ostream& stream) +bool WriteBinaryVertexTex2(VertexTex2 vertex, std::ostream& stream) { IOUtils::WriteBinaryFloat(vertex.coord.x, stream); IOUtils::WriteBinaryFloat(vertex.coord.y, stream); @@ -104,7 +110,7 @@ bool WriteBinaryVertexTex2(Gfx::VertexTex2 vertex, std::ostream& stream) return !stream.fail(); } -bool ReadTextVertexTex2(const std::string& text, Gfx::VertexTex2& vertex) +bool ReadTextVertexTex2(const std::string& text, VertexTex2& vertex) { std::stringstream stream; stream.str(text); @@ -138,7 +144,7 @@ bool ReadTextVertexTex2(const std::string& text, Gfx::VertexTex2& vertex) return !stream.fail(); } -bool WriteTextVertexTex2(const Gfx::VertexTex2& vertex, std::ostream& stream) +bool WriteTextVertexTex2(const VertexTex2& vertex, std::ostream& stream) { stream << "c " << vertex.coord.x << " " << vertex.coord.y << " " << vertex.coord.z; stream << " n " << vertex.normal.x << " " << vertex.normal.y << " " << vertex.normal.z; @@ -149,7 +155,7 @@ bool WriteTextVertexTex2(const Gfx::VertexTex2& vertex, std::ostream& stream) return !stream.fail(); } -bool ReadBinaryMaterial(std::istream& stream, Gfx::Material& material) +bool ReadBinaryMaterial(std::istream& stream, Material& material) { material.diffuse.r = IOUtils::ReadBinaryFloat(stream); material.diffuse.g = IOUtils::ReadBinaryFloat(stream); @@ -176,7 +182,7 @@ bool ReadBinaryMaterial(std::istream& stream, Gfx::Material& material) return !stream.fail(); } -bool WriteBinaryMaterial(const Gfx::Material& material, std::ostream& stream) +bool WriteBinaryMaterial(const Material& material, std::ostream& stream) { IOUtils::WriteBinaryFloat(material.diffuse.r, stream); IOUtils::WriteBinaryFloat(material.diffuse.g, stream); @@ -203,7 +209,7 @@ bool WriteBinaryMaterial(const Gfx::Material& material, std::ostream& stream) return !stream.fail(); } -bool ReadTextMaterial(const std::string& text, Gfx::Material& material) +bool ReadTextMaterial(const std::string& text, Material& material) { std::stringstream stream; stream.str(text); @@ -240,7 +246,7 @@ bool ReadTextMaterial(const std::string& text, Gfx::Material& material) return !stream.fail(); } -bool WriteTextMaterial(const Gfx::Material& material, std::ostream& stream) +bool WriteTextMaterial(const Material& material, std::ostream& stream) { stream << "dif " << material.diffuse.r << " " << material.diffuse.g @@ -316,7 +322,7 @@ bool ReadLineString(std::istream& stream, const std::string& prefix, std::string } -Gfx::CModelFile::CModelFile(CInstanceManager* iMan) +CModelFile::CModelFile(CInstanceManager* iMan) { m_iMan = iMan; @@ -327,7 +333,7 @@ Gfx::CModelFile::CModelFile(CInstanceManager* iMan) m_triangles.reserve(TRIANGLE_PREALLOCATE_COUNT); } -Gfx::CModelFile::~CModelFile() +CModelFile::~CModelFile() { } @@ -370,10 +376,10 @@ struct OldModelTriangle1 { char used; char selected; - Gfx::Vertex p1; - Gfx::Vertex p2; - Gfx::Vertex p3; - Gfx::Material material; + Vertex p1; + Vertex p2; + Vertex p3; + Material material; char texName[20]; float min; float max; @@ -394,10 +400,10 @@ struct OldModelTriangle2 { char used; char selected; - Gfx::Vertex p1; - Gfx::Vertex p2; - Gfx::Vertex p3; - Gfx::Material material; + Vertex p1; + Vertex p2; + Vertex p3; + Material material; char texName[20]; float min; float max; @@ -422,10 +428,10 @@ struct OldModelTriangle3 { char used; char selected; - Gfx::VertexTex2 p1; - Gfx::VertexTex2 p2; - Gfx::VertexTex2 p3; - Gfx::Material material; + VertexTex2 p1; + VertexTex2 p2; + VertexTex2 p3; + Material material; char texName[20]; float min; float max; @@ -441,7 +447,7 @@ struct OldModelTriangle3 } }; -bool Gfx::CModelFile::ReadModel(const std::string& fileName) +bool CModelFile::ReadModel(const std::string& fileName) { m_triangles.clear(); @@ -456,7 +462,7 @@ bool Gfx::CModelFile::ReadModel(const std::string& fileName) return ReadModel(stream); } -bool Gfx::CModelFile::ReadModel(std::istream& stream) +bool CModelFile::ReadModel(std::istream& stream) { m_triangles.clear(); @@ -484,6 +490,8 @@ bool Gfx::CModelFile::ReadModel(std::istream& stream) t.used = IOUtils::ReadBinary<1, char>(stream); t.selected = IOUtils::ReadBinary<1, char>(stream); + /* padding */ IOUtils::ReadBinary<2, unsigned int>(stream); + ReadBinaryVertex(stream, t.p1); ReadBinaryVertex(stream, t.p2); ReadBinaryVertex(stream, t.p3); @@ -499,7 +507,7 @@ bool Gfx::CModelFile::ReadModel(std::istream& stream) return false; } - Gfx::ModelTriangle triangle; + ModelTriangle triangle; triangle.p1.FromVertex(t.p1); triangle.p2.FromVertex(t.p2); triangle.p3.FromVertex(t.p3); @@ -520,6 +528,8 @@ bool Gfx::CModelFile::ReadModel(std::istream& stream) t.used = IOUtils::ReadBinary<1, char>(stream); t.selected = IOUtils::ReadBinary<1, char>(stream); + /* padding */ IOUtils::ReadBinary<2, unsigned int>(stream); + ReadBinaryVertex(stream, t.p1); ReadBinaryVertex(stream, t.p2); ReadBinaryVertex(stream, t.p3); @@ -541,7 +551,7 @@ bool Gfx::CModelFile::ReadModel(std::istream& stream) return false; } - Gfx::ModelTriangle triangle; + ModelTriangle triangle; triangle.p1.FromVertex(t.p1); triangle.p2.FromVertex(t.p2); triangle.p3.FromVertex(t.p3); @@ -586,7 +596,7 @@ bool Gfx::CModelFile::ReadModel(std::istream& stream) return false; } - Gfx::ModelTriangle triangle; + ModelTriangle triangle; triangle.p1 = t.p1; triangle.p2 = t.p2; triangle.p3 = t.p3; @@ -599,15 +609,15 @@ bool Gfx::CModelFile::ReadModel(std::istream& stream) triangle.variableTex2 = t.texNum2 == 1; if (triangle.tex1Name == "plant.png") - triangle.state |= Gfx::ENG_RSTATE_ALPHA; + triangle.state |= ENG_RSTATE_ALPHA; if (!triangle.variableTex2 && t.texNum2 != 0) { if (t.texNum2 >= 1 && t.texNum2 <= 10) - triangle.state |= Gfx::ENG_RSTATE_DUAL_BLACK; + triangle.state |= ENG_RSTATE_DUAL_BLACK; if (t.texNum2 >= 11 && t.texNum2 <= 20) - triangle.state |= Gfx::ENG_RSTATE_DUAL_WHITE; + triangle.state |= ENG_RSTATE_DUAL_WHITE; char tex2Name[20] = { 0 }; sprintf(tex2Name, "dirty%.2d.png", t.texNum2); // hardcoded as in original code @@ -649,7 +659,7 @@ bool Gfx::CModelFile::ReadModel(std::istream& stream) return true; } -bool Gfx::CModelFile::WriteModel(const std::string& fileName) +bool CModelFile::WriteModel(const std::string& fileName) { std::ofstream stream; stream.open(fileName.c_str(), std::ios_base::out | std::ios_base::binary); @@ -662,7 +672,7 @@ bool Gfx::CModelFile::WriteModel(const std::string& fileName) return WriteModel(stream); } -bool Gfx::CModelFile::WriteModel(std::ostream& stream) +bool CModelFile::WriteModel(std::ostream& stream) { if (m_triangles.size() == 0) { @@ -763,13 +773,13 @@ struct NewModelHeader struct NewModelTriangle1 { //! 1st vertex - Gfx::VertexTex2 p1; + VertexTex2 p1; //! 2nd vertex - Gfx::VertexTex2 p2; + VertexTex2 p2; //! 3rd vertex - Gfx::VertexTex2 p3; + VertexTex2 p3; //! Material - Gfx::Material material; + Material material; //! Name of 1st texture std::string tex1Name; //! Name of 2nd texture @@ -792,7 +802,7 @@ struct NewModelTriangle1 }; -bool Gfx::CModelFile::ReadTextModel(const std::string& fileName) +bool CModelFile::ReadTextModel(const std::string& fileName) { std::ifstream stream; stream.open(fileName.c_str(), std::ios_base::in); @@ -805,7 +815,7 @@ bool Gfx::CModelFile::ReadTextModel(const std::string& fileName) return ReadTextModel(stream); } -bool Gfx::CModelFile::ReadTextModel(std::istream& stream) +bool CModelFile::ReadTextModel(std::istream& stream) { m_triangles.clear(); @@ -848,14 +858,14 @@ bool Gfx::CModelFile::ReadTextModel(std::istream& stream) if (!triOk || stream.fail()) { - GetLogger()->Error("Error reading model file header\n"); + GetLogger()->Error("Error reading model data\n"); return false; } t.variableTex2 = varTex2Ch == 'Y'; - Gfx::ModelTriangle triangle; + ModelTriangle triangle; triangle.p1 = t.p1; triangle.p2 = t.p2; triangle.p3 = t.p3; @@ -901,7 +911,7 @@ bool Gfx::CModelFile::ReadTextModel(std::istream& stream) return true; } -bool Gfx::CModelFile::WriteTextModel(const std::string &fileName) +bool CModelFile::WriteTextModel(const std::string &fileName) { std::ofstream stream; stream.open(fileName.c_str(), std::ios_base::out); @@ -914,7 +924,7 @@ bool Gfx::CModelFile::WriteTextModel(const std::string &fileName) return WriteTextModel(stream); } -bool Gfx::CModelFile::WriteTextModel(std::ostream& stream) +bool CModelFile::WriteTextModel(std::ostream& stream) { if (m_triangles.size() == 0) { @@ -978,7 +988,7 @@ bool Gfx::CModelFile::WriteTextModel(std::ostream& stream) return true; } -bool Gfx::CModelFile::ReadBinaryModel(const std::string& fileName) +bool CModelFile::ReadBinaryModel(const std::string& fileName) { std::ifstream stream; stream.open(fileName.c_str(), std::ios_base::in | std::ios_base::binary); @@ -991,7 +1001,7 @@ bool Gfx::CModelFile::ReadBinaryModel(const std::string& fileName) return ReadBinaryModel(stream); } -bool Gfx::CModelFile::ReadBinaryModel(std::istream& stream) +bool CModelFile::ReadBinaryModel(std::istream& stream) { m_triangles.clear(); @@ -1030,7 +1040,7 @@ bool Gfx::CModelFile::ReadBinaryModel(std::istream& stream) return false; } - Gfx::ModelTriangle triangle; + ModelTriangle triangle; triangle.p1 = t.p1; triangle.p2 = t.p2; triangle.p3 = t.p3; @@ -1074,7 +1084,7 @@ bool Gfx::CModelFile::ReadBinaryModel(std::istream& stream) return true; } -bool Gfx::CModelFile::WriteBinaryModel(const std::string& fileName) +bool CModelFile::WriteBinaryModel(const std::string& fileName) { std::ofstream stream; stream.open(fileName.c_str(), std::ios_base::out | std::ios_base::binary); @@ -1087,7 +1097,7 @@ bool Gfx::CModelFile::WriteBinaryModel(const std::string& fileName) return WriteBinaryModel(stream); } -bool Gfx::CModelFile::WriteBinaryModel(std::ostream& stream) +bool CModelFile::WriteBinaryModel(std::ostream& stream) { if (m_triangles.size() == 0) { @@ -1146,9 +1156,9 @@ bool Gfx::CModelFile::WriteBinaryModel(std::ostream& stream) #ifndef MODELFILE_NO_ENGINE -bool Gfx::CModelFile::CreateEngineObject(int objRank) +bool CModelFile::CreateEngineObject(int objRank) { - std::vector<Gfx::VertexTex2> vs(3, Gfx::VertexTex2()); + std::vector<VertexTex2> vs(3, VertexTex2()); float limit[2]; limit[0] = m_engine->GetLimitLOD(0); // frontier AB as config @@ -1184,10 +1194,10 @@ bool Gfx::CModelFile::CreateEngineObject(int objRank) int texNum = m_engine->GetSecondTexture(); if (texNum >= 1 && texNum <= 10) - state |= Gfx::ENG_RSTATE_DUAL_BLACK; + state |= ENG_RSTATE_DUAL_BLACK; if (texNum >= 11 && texNum <= 20) - state |= Gfx::ENG_RSTATE_DUAL_WHITE; + state |= ENG_RSTATE_DUAL_WHITE; char name[20] = { 0 }; sprintf(name, "dirty%.2d.png", texNum); @@ -1213,11 +1223,11 @@ bool Gfx::CModelFile::CreateEngineObject(int objRank) #endif -void Gfx::CModelFile::Mirror() +void CModelFile::Mirror() { for (int i = 0; i < static_cast<int>( m_triangles.size() ); i++) { - Gfx::VertexTex2 t = m_triangles[i].p1; + VertexTex2 t = m_triangles[i].p1; m_triangles[i].p1 = m_triangles[i].p2; m_triangles[i].p2 = t; @@ -1231,17 +1241,17 @@ void Gfx::CModelFile::Mirror() } } -const std::vector<Gfx::ModelTriangle>& Gfx::CModelFile::GetTriangles() +const std::vector<ModelTriangle>& CModelFile::GetTriangles() { return m_triangles; } -int Gfx::CModelFile::GetTriangleCount() +int CModelFile::GetTriangleCount() { return m_triangles.size(); } -float Gfx::CModelFile::GetHeight(Math::Vector pos) +float CModelFile::GetHeight(Math::Vector pos) { float limit = 5.0f; @@ -1263,20 +1273,23 @@ float Gfx::CModelFile::GetHeight(Math::Vector pos) return 0.0f; } -void Gfx::CModelFile::CreateTriangle(Math::Vector p1, Math::Vector p2, Math::Vector p3, float min, float max) +void CModelFile::CreateTriangle(Math::Vector p1, Math::Vector p2, Math::Vector p3, float min, float max) { - Gfx::ModelTriangle triangle; + ModelTriangle triangle; Math::Vector n = Math::NormalToPlane(p3, p2, p1); - triangle.p1 = Gfx::VertexTex2(p1, n); - triangle.p2 = Gfx::VertexTex2(p2, n); - triangle.p3 = Gfx::VertexTex2(p3, n); + triangle.p1 = VertexTex2(p1, n); + triangle.p2 = VertexTex2(p2, n); + triangle.p3 = VertexTex2(p3, n); - triangle.material.diffuse = Gfx::Color(1.0f, 1.0f, 1.0f, 0.0f); - triangle.material.ambient = Gfx::Color(0.5f, 0.5f, 0.5f, 0.0f); + triangle.material.diffuse = Color(1.0f, 1.0f, 1.0f, 0.0f); + triangle.material.ambient = Color(0.5f, 0.5f, 0.5f, 0.0f); triangle.min = min; triangle.max = max; m_triangles.push_back(triangle); } + + +} // namespace Gfx diff --git a/src/graphics/engine/modelfile.h b/src/graphics/engine/modelfile.h index 833cdf6..6c573b8 100644 --- a/src/graphics/engine/modelfile.h +++ b/src/graphics/engine/modelfile.h @@ -17,11 +17,15 @@ /** * \file graphics/engine/modelfile.h - * \brief Model loading - Gfx::CModelFile class (aka modfile) + * \brief Model loading - CModelFile class (aka modfile) */ +#pragma once + + #include "graphics/core/vertex.h" #include "graphics/core/material.h" + #include "math/vector.h" #include <string> @@ -32,6 +36,7 @@ class CInstanceManager; +// Graphics module namespace namespace Gfx { class CEngine; @@ -44,13 +49,13 @@ class CEngine; struct ModelTriangle { //! 1st vertex - Gfx::VertexTex2 p1; + VertexTex2 p1; //! 2nd vertex - Gfx::VertexTex2 p2; + VertexTex2 p2; //! 3rd vertex - Gfx::VertexTex2 p3; + VertexTex2 p3; //! Material - Gfx::Material material; + Material material; //! Name of 1st texture std::string tex1Name; //! Name of 2nd texture @@ -121,7 +126,7 @@ public: int GetTriangleCount(); //! Returns the triangle vector - const std::vector<Gfx::ModelTriangle>& GetTriangles(); + const std::vector<ModelTriangle>& GetTriangles(); //! Returns the height of model -- closest point to X and Z coords of \a pos float GetHeight(Math::Vector pos); @@ -138,10 +143,10 @@ protected: protected: CInstanceManager* m_iMan; - Gfx::CEngine* m_engine; + CEngine* m_engine; //! Model triangles - std::vector<Gfx::ModelTriangle> m_triangles; + std::vector<ModelTriangle> m_triangles; }; }; // namespace Gfx diff --git a/src/graphics/engine/particle.cpp b/src/graphics/engine/particle.cpp index c177deb..9d3d084 100644 --- a/src/graphics/engine/particle.cpp +++ b/src/graphics/engine/particle.cpp @@ -15,45 +15,48 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// particle.cpp (aka particule.cpp) #include "graphics/engine/particle.h" #include "common/logger.h" -Gfx::CParticle::CParticle(CInstanceManager* iMan, Gfx::CEngine* engine) +// Graphics module namespace +namespace Gfx { + + +CParticle::CParticle(CInstanceManager* iMan, CEngine* engine) { GetLogger()->Trace("CParticle::CParticle() stub!\n"); // TODO! } -Gfx::CParticle::~CParticle() +CParticle::~CParticle() { GetLogger()->Trace("CParticle::~CParticle() stub!\n"); // TODO! } -void Gfx::CParticle::SetDevice(Gfx::CDevice* device) +void CParticle::SetDevice(CDevice* device) { GetLogger()->Trace("CParticle::SetDevice() stub!\n"); // TODO! } -void Gfx::CParticle::FlushParticle() +void CParticle::FlushParticle() { GetLogger()->Trace("CParticle::FlushParticle() stub!\n"); // TODO! } -void Gfx::CParticle::FlushParticle(int sheet) +void CParticle::FlushParticle(int sheet) { GetLogger()->Trace("CParticle::FlushParticle() stub!\n"); // TODO! } -int Gfx::CParticle::CreateParticle(Math::Vector pos, Math::Vector speed, Math::Point dim, - Gfx::ParticleType type, float duration, float mass, +int CParticle::CreateParticle(Math::Vector pos, Math::Vector speed, Math::Point dim, + ParticleType type, float duration, float mass, float windSensitivity, int sheet) { GetLogger()->Trace("CParticle::CreateParticle() stub!\n"); @@ -61,8 +64,8 @@ int Gfx::CParticle::CreateParticle(Math::Vector pos, Math::Vector speed, Math::P return 0; } -int Gfx::CParticle::CreateFrag(Math::Vector pos, Math::Vector speed, Gfx::EngineTriangle *triangle, - Gfx::ParticleType type, float duration, float mass, +int CParticle::CreateFrag(Math::Vector pos, Math::Vector speed, EngineTriangle *triangle, + ParticleType type, float duration, float mass, float windSensitivity, int sheet) { GetLogger()->Trace("CParticle::CreateFrag() stub!\n"); @@ -70,7 +73,7 @@ int Gfx::CParticle::CreateFrag(Math::Vector pos, Math::Vector speed, Gfx::Engine return 0; } -int Gfx::CParticle::CreatePart(Math::Vector pos, Math::Vector speed, Gfx::ParticleType type, +int CParticle::CreatePart(Math::Vector pos, Math::Vector speed, ParticleType type, float duration, float mass, float weight, float windSensitivity, int sheet) { @@ -79,7 +82,7 @@ int Gfx::CParticle::CreatePart(Math::Vector pos, Math::Vector speed, Gfx::Partic return 0; } -int Gfx::CParticle::CreateRay(Math::Vector pos, Math::Vector goal, Gfx::ParticleType type, Math::Point dim, +int CParticle::CreateRay(Math::Vector pos, Math::Vector goal, ParticleType type, Math::Point dim, float duration, int sheet) { GetLogger()->Trace("CParticle::CreateRay() stub!\n"); @@ -87,7 +90,7 @@ int Gfx::CParticle::CreateRay(Math::Vector pos, Math::Vector goal, Gfx::Particle return 0; } -int Gfx::CParticle::CreateTrack(Math::Vector pos, Math::Vector speed, Math::Point dim, Gfx::ParticleType type, +int CParticle::CreateTrack(Math::Vector pos, Math::Vector speed, Math::Point dim, ParticleType type, float duration, float mass, float length, float width) { GetLogger()->Trace("CParticle::CreateTrack() stub!\n"); @@ -95,208 +98,211 @@ int Gfx::CParticle::CreateTrack(Math::Vector pos, Math::Vector speed, Math::Poin return 0; } -void Gfx::CParticle::CreateWheelTrace(const Math::Vector &p1, const Math::Vector &p2, const Math::Vector &p3, - const Math::Vector &p4, Gfx::ParticleType type) +void CParticle::CreateWheelTrace(const Math::Vector &p1, const Math::Vector &p2, const Math::Vector &p3, + const Math::Vector &p4, ParticleType type) { GetLogger()->Trace("CParticle::CreateWheelTrace() stub!\n"); // TODO! } -void Gfx::CParticle::DeleteParticle(Gfx::ParticleType type) +void CParticle::DeleteParticle(ParticleType type) { GetLogger()->Trace("CParticle::DeleteParticle() stub!\n"); // TODO! } -void Gfx::CParticle::DeleteParticle(int channel) +void CParticle::DeleteParticle(int channel) { GetLogger()->Trace("CParticle::DeleteParticle() stub!\n"); // TODO! } -void Gfx::CParticle::SetObjectLink(int channel, CObject *object) +void CParticle::SetObjectLink(int channel, CObject *object) { GetLogger()->Trace("CParticle::SetObjectLink() stub!\n"); // TODO! } -void Gfx::CParticle::SetObjectFather(int channel, CObject *object) +void CParticle::SetObjectFather(int channel, CObject *object) { GetLogger()->Trace("CParticle::SetObjectFather() stub!\n"); // TODO! } -void Gfx::CParticle::SetPosition(int channel, Math::Vector pos) +void CParticle::SetPosition(int channel, Math::Vector pos) { GetLogger()->Trace("CParticle::SetPosition() stub!\n"); // TODO! } -void Gfx::CParticle::SetDimension(int channel, Math::Point dim) +void CParticle::SetDimension(int channel, Math::Point dim) { GetLogger()->Trace("CParticle::SetDimension() stub!\n"); // TODO! } -void Gfx::CParticle::SetZoom(int channel, float zoom) +void CParticle::SetZoom(int channel, float zoom) { GetLogger()->Trace("CParticle::SetZoom() stub!\n"); // TODO! } -void Gfx::CParticle::SetAngle(int channel, float angle) +void CParticle::SetAngle(int channel, float angle) { GetLogger()->Trace("CParticle::SetAngle() stub!\n"); // TODO! } -void Gfx::CParticle::SetIntensity(int channel, float intensity) +void CParticle::SetIntensity(int channel, float intensity) { GetLogger()->Trace("CParticle::SetIntensity() stub!\n"); // TODO! } -void Gfx::CParticle::SetParam(int channel, Math::Vector pos, Math::Point dim, float zoom, float angle, float intensity) +void CParticle::SetParam(int channel, Math::Vector pos, Math::Point dim, float zoom, float angle, float intensity) { GetLogger()->Trace("CParticle::SetParam() stub!\n"); // TODO! } -void Gfx::CParticle::SetPhase(int channel, Gfx::ParticlePhase phase, float duration) +void CParticle::SetPhase(int channel, ParticlePhase phase, float duration) { GetLogger()->Trace("CParticle::SetPhase() stub!\n"); // TODO! } -bool Gfx::CParticle::GetPosition(int channel, Math::Vector &pos) +bool CParticle::GetPosition(int channel, Math::Vector &pos) { GetLogger()->Trace("CParticle::GetPosition() stub!\n"); // TODO! return true; } -Gfx::Color Gfx::CParticle::GetFogColor(Math::Vector pos) +Color CParticle::GetFogColor(Math::Vector pos) { GetLogger()->Trace("CParticle::GetFogColor() stub!\n"); // TODO! - return Gfx::Color(); + return Color(); } -void Gfx::CParticle::SetFrameUpdate(int sheet, bool update) +void CParticle::SetFrameUpdate(int sheet, bool update) { GetLogger()->Trace("CParticle::SetFrameUpdate() stub!\n"); // TODO! } -void Gfx::CParticle::FrameParticle(float rTime) +void CParticle::FrameParticle(float rTime) { GetLogger()->Trace("CParticle::FrameParticle() stub!\n"); // TODO! } -void Gfx::CParticle::DrawParticle(int sheet) +void CParticle::DrawParticle(int sheet) { GetLogger()->Trace("CParticle::DrawParticle() stub!\n"); // TODO! } -bool Gfx::CParticle::WriteWheelTrace(const char *filename, int width, int height, Math::Vector dl, Math::Vector ur) +bool CParticle::WriteWheelTrace(const char *filename, int width, int height, Math::Vector dl, Math::Vector ur) { GetLogger()->Trace("CParticle::WriteWheelTrace() stub!\n"); // TODO! return true; } -void Gfx::CParticle::DeleteRank(int rank) +void CParticle::DeleteRank(int rank) { GetLogger()->Trace("CParticle::DeleteRank() stub!\n"); // TODO! } -bool Gfx::CParticle::CheckChannel(int &channel) +bool CParticle::CheckChannel(int &channel) { GetLogger()->Trace("CParticle::CheckChannel() stub!\n"); // TODO! return true; } -void Gfx::CParticle::DrawParticleTriangle(int i) +void CParticle::DrawParticleTriangle(int i) { GetLogger()->Trace("CParticle::DrawParticleTriangle() stub!\n"); // TODO! } -void Gfx::CParticle::DrawParticleNorm(int i) +void CParticle::DrawParticleNorm(int i) { GetLogger()->Trace("CParticle::DrawParticleNorm() stub!\n"); // TODO! } -void Gfx::CParticle::DrawParticleFlat(int i) +void CParticle::DrawParticleFlat(int i) { GetLogger()->Trace("CParticle::DrawParticleFlat() stub!\n"); // TODO! } -void Gfx::CParticle::DrawParticleFog(int i) +void CParticle::DrawParticleFog(int i) { GetLogger()->Trace("CParticle::DrawParticleFog() stub!\n"); // TODO! } -void Gfx::CParticle::DrawParticleRay(int i) +void CParticle::DrawParticleRay(int i) { GetLogger()->Trace("CParticle::DrawParticleRay() stub!\n"); // TODO! } -void Gfx::CParticle::DrawParticleSphere(int i) +void CParticle::DrawParticleSphere(int i) { GetLogger()->Trace("CParticle::DrawParticleSphere() stub!\n"); // TODO! } -void Gfx::CParticle::DrawParticleCylinder(int i) +void CParticle::DrawParticleCylinder(int i) { GetLogger()->Trace("CParticle::DrawParticleCylinder() stub!\n"); // TODO! } -void Gfx::CParticle::DrawParticleWheel(int i) +void CParticle::DrawParticleWheel(int i) { GetLogger()->Trace("CParticle::DrawParticleWheel() stub!\n"); // TODO! } -CObject* Gfx::CParticle::SearchObjectGun(Math::Vector old, Math::Vector pos, Gfx::ParticleType type, CObject *father) +CObject* CParticle::SearchObjectGun(Math::Vector old, Math::Vector pos, ParticleType type, CObject *father) { GetLogger()->Trace("CParticle::SearchObjectGun() stub!\n"); // TODO! return nullptr; } -CObject* Gfx::CParticle::SearchObjectRay(Math::Vector pos, Math::Vector goal, Gfx::ParticleType type, CObject *father) +CObject* CParticle::SearchObjectRay(Math::Vector pos, Math::Vector goal, ParticleType type, CObject *father) { GetLogger()->Trace("CParticle::SearchObjectRay() stub!\n"); // TODO! return nullptr; } -void Gfx::CParticle::Play(Sound sound, Math::Vector pos, float amplitude) +void CParticle::Play(Sound sound, Math::Vector pos, float amplitude) { GetLogger()->Trace("CParticle::Play() stub!\n"); // TODO! } -bool Gfx::CParticle::TrackMove(int i, Math::Vector pos, float progress) +bool CParticle::TrackMove(int i, Math::Vector pos, float progress) { GetLogger()->Trace("CParticle::TrackMove() stub!\n"); // TODO! return true; } -void Gfx::CParticle::TrackDraw(int i, Gfx::ParticleType type) +void CParticle::TrackDraw(int i, ParticleType type) { GetLogger()->Trace("CParticle::TrackDraw() stub!\n"); // TODO! } + + +} // namespace Gfx diff --git a/src/graphics/engine/particle.h b/src/graphics/engine/particle.h index f78e242..33a5c1b 100644 --- a/src/graphics/engine/particle.h +++ b/src/graphics/engine/particle.h @@ -17,22 +17,24 @@ /** * \file graphics/engine/particle.h - * \brief Particle rendering - Gfx::CParticle class (aka particule) + * \brief Particle rendering - CParticle class (aka particule) */ #pragma once + #include "engine.h" + #include "sound/sound.h" class CInstanceManager; class CRobotMain; class CObject; -class CSound; - +class CSoundInterface; +// Graphics module namespace namespace Gfx { const short MAXPARTICULE = 500; @@ -265,29 +267,29 @@ struct WheelTrace class CParticle { public: - CParticle(CInstanceManager* iMan, Gfx::CEngine* engine); + CParticle(CInstanceManager* iMan, CEngine* engine); ~CParticle(); - void SetDevice(Gfx::CDevice* device); + void SetDevice(CDevice* device); void FlushParticle(); void FlushParticle(int sheet); int CreateParticle(Math::Vector pos, Math::Vector speed, Math::Point dim, - Gfx::ParticleType type, float duration=1.0f, float mass=0.0f, + ParticleType type, float duration=1.0f, float mass=0.0f, float windSensitivity=1.0f, int sheet=0); - int CreateFrag(Math::Vector pos, Math::Vector speed, Gfx::EngineTriangle *triangle, - Gfx::ParticleType type, float duration=1.0f, float mass=0.0f, + int CreateFrag(Math::Vector pos, Math::Vector speed, EngineTriangle *triangle, + ParticleType type, float duration=1.0f, float mass=0.0f, float windSensitivity=1.0f, int sheet=0); - int CreatePart(Math::Vector pos, Math::Vector speed, Gfx::ParticleType type, + int CreatePart(Math::Vector pos, Math::Vector speed, ParticleType type, float duration=1.0f, float mass=0.0f, float weight=0.0f, float windSensitivity=1.0f, int sheet=0); - int CreateRay(Math::Vector pos, Math::Vector goal, Gfx::ParticleType type, Math::Point dim, + int CreateRay(Math::Vector pos, Math::Vector goal, ParticleType type, Math::Point dim, float duration=1.0f, int sheet=0); - int CreateTrack(Math::Vector pos, Math::Vector speed, Math::Point dim, Gfx::ParticleType type, + int CreateTrack(Math::Vector pos, Math::Vector speed, Math::Point dim, ParticleType type, float duration=1.0f, float mass=0.0f, float length=10.0f, float width=1.0f); void CreateWheelTrace(const Math::Vector &p1, const Math::Vector &p2, const Math::Vector &p3, - const Math::Vector &p4, Gfx::ParticleType type); - void DeleteParticle(Gfx::ParticleType type); + const Math::Vector &p4, ParticleType type); + void DeleteParticle(ParticleType type); void DeleteParticle(int channel); void SetObjectLink(int channel, CObject *object); void SetObjectFather(int channel, CObject *object); @@ -297,10 +299,10 @@ public: void SetAngle(int channel, float angle); void SetIntensity(int channel, float intensity); void SetParam(int channel, Math::Vector pos, Math::Point dim, float zoom, float angle, float intensity); - void SetPhase(int channel, Gfx::ParticlePhase phase, float duration); + void SetPhase(int channel, ParticlePhase phase, float duration); bool GetPosition(int channel, Math::Vector &pos); - Gfx::Color GetFogColor(Math::Vector pos); + Color GetFogColor(Math::Vector pos); void SetFrameUpdate(int sheet, bool update); void FrameParticle(float rTime); @@ -319,27 +321,27 @@ protected: void DrawParticleSphere(int i); void DrawParticleCylinder(int i); void DrawParticleWheel(int i); - CObject* SearchObjectGun(Math::Vector old, Math::Vector pos, Gfx::ParticleType type, CObject *father); - CObject* SearchObjectRay(Math::Vector pos, Math::Vector goal, Gfx::ParticleType type, CObject *father); + CObject* SearchObjectGun(Math::Vector old, Math::Vector pos, ParticleType type, CObject *father); + CObject* SearchObjectRay(Math::Vector pos, Math::Vector goal, ParticleType type, CObject *father); void Play(Sound sound, Math::Vector pos, float amplitude); bool TrackMove(int i, Math::Vector pos, float progress); - void TrackDraw(int i, Gfx::ParticleType type); + void TrackDraw(int i, ParticleType type); protected: CInstanceManager* m_iMan; - Gfx::CEngine* m_engine; - Gfx::CDevice* m_device; - Gfx::CTerrain* m_terrain; - Gfx::CWater* m_water; + CEngine* m_engine; + CDevice* m_device; + CTerrain* m_terrain; + CWater* m_water; CRobotMain* m_main; - CSound* m_sound; + CSoundInterface* m_sound; - Gfx::Particle m_particule[MAXPARTICULE*MAXPARTITYPE]; - Gfx::EngineTriangle m_triangle[MAXPARTICULE]; // triangle if PartiType == 0 - Gfx::Track m_track[MAXTRACK]; + Particle m_particule[MAXPARTICULE*MAXPARTITYPE]; + EngineTriangle m_triangle[MAXPARTICULE]; // triangle if PartiType == 0 + Track m_track[MAXTRACK]; int m_wheelTraceTotal; int m_wheelTraceIndex; - Gfx::WheelTrace m_wheelTrace[MAXWHEELTRACE]; + WheelTrace m_wheelTrace[MAXWHEELTRACE]; int m_totalInterface[MAXPARTITYPE][SH_MAX]; bool m_frameUpdate[SH_MAX]; int m_fogTotal; @@ -351,4 +353,4 @@ protected: }; -}; // namespace Gfx +} // namespace Gfx diff --git a/src/graphics/engine/planet.cpp b/src/graphics/engine/planet.cpp index 022de66..0ac2524 100644 --- a/src/graphics/engine/planet.cpp +++ b/src/graphics/engine/planet.cpp @@ -15,19 +15,23 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// planet.cpp #include "graphics/engine/planet.h" #include "common/iman.h" + #include "graphics/core/device.h" #include "graphics/engine/engine.h" +// Graphics module namespace +namespace Gfx { + + const int PLANET_PREALLOCATE_COUNT = 10; -Gfx::CPlanet::CPlanet(CInstanceManager* iMan, Gfx::CEngine* engine) +CPlanet::CPlanet(CInstanceManager* iMan, CEngine* engine) { m_iMan = iMan; m_iMan->AddInstance(CLASS_PLANET, this); @@ -40,12 +44,12 @@ Gfx::CPlanet::CPlanet(CInstanceManager* iMan, Gfx::CEngine* engine) } -Gfx::CPlanet::~CPlanet() +CPlanet::~CPlanet() { m_iMan = nullptr; } -void Gfx::CPlanet::Flush() +void CPlanet::Flush() { for (int j = 0; j < 2; j++) m_planet[j].clear(); @@ -55,7 +59,7 @@ void Gfx::CPlanet::Flush() m_time = 0.0f; } -bool Gfx::CPlanet::EventProcess(const Event &event) +bool CPlanet::EventProcess(const Event &event) { if (event.type == EVENT_FRAME) return EventFrame(event); @@ -63,7 +67,7 @@ bool Gfx::CPlanet::EventProcess(const Event &event) return true; } -bool Gfx::CPlanet::EventFrame(const Event &event) +bool CPlanet::EventFrame(const Event &event) { if (m_engine->GetPause()) return true; @@ -82,7 +86,7 @@ bool Gfx::CPlanet::EventFrame(const Event &event) return true; } -void Gfx::CPlanet::LoadTexture() +void CPlanet::LoadTexture() { for (int j = 0; j < 2; j++) { @@ -93,9 +97,9 @@ void Gfx::CPlanet::LoadTexture() } } -void Gfx::CPlanet::Draw() +void CPlanet::Draw() { - Gfx::CDevice* device = m_engine->GetDevice(); + CDevice* device = m_engine->GetDevice(); float eyeDirH = m_engine->GetEyeDirH(); float eyeDirV = m_engine->GetEyeDirV(); @@ -107,9 +111,9 @@ void Gfx::CPlanet::Draw() m_engine->SetTexture(m_planet[m_mode][i].name); if (m_planet[m_mode][i].transparent) - m_engine->SetState(Gfx::ENG_RSTATE_WRAP | Gfx::ENG_RSTATE_ALPHA); + m_engine->SetState(ENG_RSTATE_WRAP | ENG_RSTATE_ALPHA); else - m_engine->SetState(Gfx::ENG_RSTATE_WRAP | Gfx::ENG_RSTATE_TTEXTURE_BLACK); + m_engine->SetState(ENG_RSTATE_WRAP | ENG_RSTATE_TTEXTURE_BLACK); Math::Point p1, p2; @@ -129,26 +133,26 @@ void Gfx::CPlanet::Draw() float u2 = m_planet[m_mode][i].uv2.x - dp; float v2 = m_planet[m_mode][i].uv2.y - dp; - Gfx::Vertex quad[4] = + Vertex quad[4] = { - Gfx::Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(u1, v2)), - Gfx::Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(u1, v1)), - Gfx::Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(u2, v2)), - Gfx::Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(u2, v1)) + Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(u1, v2)), + Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(u1, v1)), + Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(u2, v2)), + Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(u2, v1)) }; - device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, quad, 4); + device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, quad, 4); m_engine->AddStatisticTriangle(2); } } -void Gfx::CPlanet::Create(int mode, Math::Point start, float dim, float speed, +void CPlanet::Create(int mode, Math::Point start, float dim, float speed, float dir, const std::string& name, Math::Point uv1, Math::Point uv2) { if (mode < 0) mode = 0; if (mode > 1) mode = 1; - Gfx::Planet planet; + Planet planet; planet.start = start; planet.angle = start; @@ -167,19 +171,22 @@ void Gfx::CPlanet::Create(int mode, Math::Point start, float dim, float speed, m_planetExist = true; } -bool Gfx::CPlanet::PlanetExist() +bool CPlanet::PlanetExist() { return m_planetExist; } -void Gfx::CPlanet::SetMode(int mode) +void CPlanet::SetMode(int mode) { if (mode < 0) mode = 0; if (mode > 1) mode = 1; m_mode = mode; } -int Gfx::CPlanet::GetMode() +int CPlanet::GetMode() { return m_mode; } + + +} // namespace Gfx diff --git a/src/graphics/engine/planet.h b/src/graphics/engine/planet.h index fd119f6..82c3aea 100644 --- a/src/graphics/engine/planet.h +++ b/src/graphics/engine/planet.h @@ -17,12 +17,14 @@ /** * \file graphics/engine/planet.h - * \brief Planet rendering - Gfx::CPlanet class + * \brief Planet rendering - CPlanet class */ #pragma once + #include "common/event.h" + #include "math/point.h" #include <vector> @@ -31,6 +33,7 @@ class CInstanceManager; +// Graphics module namespace namespace Gfx { class CEngine; @@ -79,7 +82,7 @@ struct Planet class CPlanet { public: - CPlanet(CInstanceManager* iMan, Gfx::CEngine* engine); + CPlanet(CInstanceManager* iMan, CEngine* engine); ~CPlanet(); //! Removes all the planets @@ -107,12 +110,13 @@ protected: protected: CInstanceManager* m_iMan; - Gfx::CEngine* m_engine; + CEngine* m_engine; float m_time; int m_mode; - std::vector<Gfx::Planet> m_planet[2]; + std::vector<Planet> m_planet[2]; bool m_planetExist; }; -}; // namespace Gfx + +} // namespace Gfx diff --git a/src/graphics/engine/pyro.cpp b/src/graphics/engine/pyro.cpp index c97131e..04568ae 100644 --- a/src/graphics/engine/pyro.cpp +++ b/src/graphics/engine/pyro.cpp @@ -15,165 +15,171 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// pyro.cpp #include "graphics/engine/pyro.h" #include "common/logger.h" -Gfx::CPyro::CPyro(CInstanceManager* iMan) +// Graphics module namespace +namespace Gfx { + + +CPyro::CPyro(CInstanceManager* iMan) { GetLogger()->Trace("CParticle::CPyro() stub!\n"); // TODO! } -Gfx::CPyro::~CPyro() +CPyro::~CPyro() { GetLogger()->Trace("CPyro::~CPyro() stub!"); // TODO! } -void Gfx::CPyro::DeleteObject(bool all) +void CPyro::DeleteObject(bool all) { GetLogger()->Trace("CPyro::DeleteObject() stub!"); // TODO! } -bool Gfx::CPyro::Create(Gfx::PyroType type, CObject* pObj, float force) +bool CPyro::Create(PyroType type, CObject* pObj, float force) { GetLogger()->Trace("CPyro::Create() stub!"); // TODO! return true; } -bool Gfx::CPyro::EventProcess(const Event &event) +bool CPyro::EventProcess(const Event &event) { GetLogger()->Trace("CPyro::EventProcess() stub!\n"); // TODO! return true; } -Error Gfx::CPyro::IsEnded() +Error CPyro::IsEnded() { GetLogger()->Trace("CPyro::IsEnded() stub!\n"); // TODO! return ERR_OK; } -void Gfx::CPyro::CutObjectLink(CObject* pObj) +void CPyro::CutObjectLink(CObject* pObj) { GetLogger()->Trace("CPyro::CutObjectLink() stub!\n"); // TODO! } -void Gfx::CPyro::DisplayError(PyroType type, CObject* pObj) +void CPyro::DisplayError(PyroType type, CObject* pObj) { GetLogger()->Trace("CPyro::DisplayError() stub!\n"); // TODO! } -bool Gfx::CPyro::CreateLight(Math::Vector pos, float height) +bool CPyro::CreateLight(Math::Vector pos, float height) { GetLogger()->Trace("CPyro::CreateLight() stub!\n"); // TODO! return true; } -void Gfx::CPyro::DeleteObject(bool primary, bool secondary) +void CPyro::DeleteObject(bool primary, bool secondary) { GetLogger()->Trace("CPyro::DeleteObject() stub!\n"); // TODO! } -void Gfx::CPyro::CreateTriangle(CObject* pObj, ObjectType oType, int part) +void CPyro::CreateTriangle(CObject* pObj, ObjectType oType, int part) { GetLogger()->Trace("CPyro::CreateTriangle() stub!\n"); // TODO! } -void Gfx::CPyro::ExploStart() +void CPyro::ExploStart() { GetLogger()->Trace("CPyro::ExploStart() stub!\n"); // TODO! } -void Gfx::CPyro::ExploTerminate() +void CPyro::ExploTerminate() { GetLogger()->Trace("CPyro::ExploTerminate() stub!\n"); // TODO! } -void Gfx::CPyro::BurnStart() +void CPyro::BurnStart() { GetLogger()->Trace("CPyro::BurnStart() stub!\n"); // TODO! } -void Gfx::CPyro::BurnAddPart(int part, Math::Vector pos, Math::Vector angle) +void CPyro::BurnAddPart(int part, Math::Vector pos, Math::Vector angle) { GetLogger()->Trace("CPyro::BurnAddPart() stub!\n"); // TODO! } -void Gfx::CPyro::BurnProgress() +void CPyro::BurnProgress() { GetLogger()->Trace("CPyro::BurnProgress() stub!\n"); // TODO! } -bool Gfx::CPyro::BurnIsKeepPart(int part) +bool CPyro::BurnIsKeepPart(int part) { GetLogger()->Trace("CPyro::BurnIsKeepPart() stub!\n"); // TODO! return true; } -void Gfx::CPyro::BurnTerminate() +void CPyro::BurnTerminate() { GetLogger()->Trace("CPyro::BurnTerminate() stub!\n"); // TODO! } -void Gfx::CPyro::FallStart() +void CPyro::FallStart() { GetLogger()->Trace("CPyro::FallStart() stub!\n"); // TODO! } -CObject* Gfx::CPyro::FallSearchBeeExplo() +CObject* CPyro::FallSearchBeeExplo() { GetLogger()->Trace("CPyro::FallSearchBeeExplo() stub!\n"); // TODO! return nullptr; } -void Gfx::CPyro::FallProgress(float rTime) +void CPyro::FallProgress(float rTime) { GetLogger()->Trace("CPyro::FallProgress() stub!\n"); // TODO! } -Error Gfx::CPyro::FallIsEnded() +Error CPyro::FallIsEnded() { GetLogger()->Trace("CPyro::FallIsEnded() stub!\n"); // TODO! return ERR_OK; } -void Gfx::CPyro::LightOperFlush() +void CPyro::LightOperFlush() { GetLogger()->Trace("CPyro::LightOperFlush() stub!\n"); // TODO! } -void Gfx::CPyro::LightOperAdd(float progress, float intensity, float r, float g, float b) +void CPyro::LightOperAdd(float progress, float intensity, float r, float g, float b) { GetLogger()->Trace("CPyro::LightOperAdd() stub!\n"); // TODO! } -void Gfx::CPyro::LightOperFrame(float rTime) +void CPyro::LightOperFrame(float rTime) { GetLogger()->Trace("CPyro::LightOperFrame() stub!\n"); // TODO! } + + +} // namespace Gfx diff --git a/src/graphics/engine/pyro.h b/src/graphics/engine/pyro.h index c0c0144..d91b049 100644 --- a/src/graphics/engine/pyro.h +++ b/src/graphics/engine/pyro.h @@ -17,14 +17,17 @@ /** * \file graphics/engine/pyro.h - * \brief Fire effect rendering - Gfx::CPyro class + * \brief Fire effect rendering - CPyro class */ #pragma once + #include "common/event.h" #include "common/global.h" + #include "graphics/engine/engine.h" + #include "object/object.h" @@ -32,9 +35,10 @@ class CInstanceManager; class CObject; class CDisplayText; class CRobotMain; -class CSound; +class CSoundInterface; +// Graphics module namespace namespace Gfx { class CEngine; @@ -87,7 +91,7 @@ struct PyroLightOper { float progress; float intensity; - Gfx::Color color; + Color color; }; @@ -104,7 +108,7 @@ public: ~CPyro(); void DeleteObject(bool all=false); - bool Create(Gfx::PyroType type, CObject* pObj, float force=1.0f); + bool Create(PyroType type, CObject* pObj, float force=1.0f); bool EventProcess(const Event &event); Error IsEnded(); void CutObjectLink(CObject* pObj); @@ -136,20 +140,20 @@ protected: protected: CInstanceManager* m_iMan; - Gfx::CEngine* m_engine; - Gfx::CTerrain* m_terrain; - Gfx::CCamera* m_camera; - Gfx::CParticle* m_particule; - Gfx::CLightManager* m_lightMan; + CEngine* m_engine; + CTerrain* m_terrain; + CCamera* m_camera; + CParticle* m_particule; + CLightManager* m_lightMan; CObject* m_object; CDisplayText* m_displayText; CRobotMain* m_main; - CSound* m_sound; + CSoundInterface* m_sound; Math::Vector m_pos; // center of the effect Math::Vector m_posPower; // center of the battery bool m_power; // battery exists? - Gfx::PyroType m_type; + PyroType m_type; float m_force; float m_size; float m_progress; @@ -161,12 +165,12 @@ protected: int m_lightRank; int m_lightOperTotal; - Gfx::PyroLightOper m_lightOper[10]; + PyroLightOper m_lightOper[10]; float m_lightHeight; ObjectType m_burnType; int m_burnPartTotal; - Gfx::PyroBurnPart m_burnPart[10]; + PyroBurnPart m_burnPart[10]; int m_burnKeepPart[10]; float m_burnFall; @@ -180,4 +184,5 @@ protected: float m_crashSphereRadius[50]; }; -}; // namespace Gfx + +} // namespace Gfx diff --git a/src/graphics/engine/terrain.cpp b/src/graphics/engine/terrain.cpp index 3e70719..05b7a2d 100644 --- a/src/graphics/engine/terrain.cpp +++ b/src/graphics/engine/terrain.cpp @@ -15,7 +15,6 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// terrain.cpp #include "graphics/engine/terrain.h" @@ -31,18 +30,22 @@ #include <SDL/SDL.h> + +// Graphics module namespace +namespace Gfx { + const int LEVEL_MAT_PREALLOCATE_COUNT = 101; const int FLYING_LIMIT_PREALLOCATE_COUNT = 10; const int BUILDING_LEVEL_PREALLOCATE_COUNT = 101; -Gfx::CTerrain::CTerrain(CInstanceManager* iMan) +CTerrain::CTerrain(CInstanceManager* iMan) { m_iMan = iMan; m_iMan->AddInstance(CLASS_TERRAIN, this); - m_engine = static_cast<Gfx::CEngine*>( m_iMan->SearchInstance(CLASS_ENGINE) ); - m_water = static_cast<Gfx::CWater*>( m_iMan->SearchInstance(CLASS_WATER) ); + m_engine = static_cast<CEngine*>( m_iMan->SearchInstance(CLASS_ENGINE) ); + m_water = static_cast<CWater*>( m_iMan->SearchInstance(CLASS_WATER) ); m_mosaicCount = 20; m_brickCount = 1 << 4; @@ -66,11 +69,11 @@ Gfx::CTerrain::CTerrain(CInstanceManager* iMan) FlushMaterials(); } -Gfx::CTerrain::~CTerrain() +CTerrain::~CTerrain() { } -bool Gfx::CTerrain::Generate(int mosaicCount, int brickCountPow2, float brickSize, +bool CTerrain::Generate(int mosaicCount, int brickCountPow2, float brickSize, float vision, int depth, float hardness) { m_mosaicCount = mosaicCount; @@ -102,27 +105,27 @@ bool Gfx::CTerrain::Generate(int mosaicCount, int brickCountPow2, float brickSiz } -int Gfx::CTerrain::GetMosaicCount() +int CTerrain::GetMosaicCount() { return m_mosaicCount; } -int Gfx::CTerrain::GetBrickCount() +int CTerrain::GetBrickCount() { return m_brickCount; } -float Gfx::CTerrain::GetBrickSize() +float CTerrain::GetBrickSize() { return m_brickSize; } -float Gfx::CTerrain::GetReliefScale() +float CTerrain::GetReliefScale() { return m_scaleRelief; } -bool Gfx::CTerrain::InitTextures(const std::string& baseName, int* table, int dx, int dy) +bool CTerrain::InitTextures(const std::string& baseName, int* table, int dx, int dy) { m_useMaterials = false; @@ -149,7 +152,7 @@ bool Gfx::CTerrain::InitTextures(const std::string& baseName, int* table, int dx } -void Gfx::CTerrain::FlushMaterials() +void CTerrain::FlushMaterials() { m_materials.clear(); m_maxMaterialID = 0; @@ -157,7 +160,7 @@ void Gfx::CTerrain::FlushMaterials() FlushMaterialPoints(); } -void Gfx::CTerrain::AddMaterial(int id, const std::string& texName, const Math::Point &uv, +void CTerrain::AddMaterial(int id, const std::string& texName, const Math::Point &uv, int up, int right, int down, int left, float hardness) { @@ -166,7 +169,7 @@ void Gfx::CTerrain::AddMaterial(int id, const std::string& texName, const Math:: if (id == 0) id = m_materialAutoID++; - Gfx::TerrainMaterial tm; + TerrainMaterial tm; tm.texName = texName; tm.id = id; tm.uv = uv; @@ -191,7 +194,7 @@ void Gfx::CTerrain::AddMaterial(int id, const std::string& texName, const Math:: /** * The image must be 24 bits/pixel and grayscale and dx x dy in size * with dx = dy = (mosaic*brick)+1 */ -bool Gfx::CTerrain::LoadResources(const std::string& fileName) +bool CTerrain::LoadResources(const std::string& fileName) { CImage img; if (! img.Load(CApplication::GetInstance().GetDataFilePath(m_engine->GetTextureDir(), fileName))) @@ -220,17 +223,17 @@ bool Gfx::CTerrain::LoadResources(const std::string& fileName) return true; } -Gfx::TerrainRes Gfx::CTerrain::GetResource(const Math::Vector &p) +TerrainRes CTerrain::GetResource(const Math::Vector &p) { if (m_resources.empty()) - return Gfx::TR_NULL; + return TR_NULL; int x = static_cast<int>((p.x + (m_mosaicCount*m_brickCount*m_brickSize)/2.0f)/m_brickSize); int y = static_cast<int>((p.z + (m_mosaicCount*m_brickCount*m_brickSize)/2.0f)/m_brickSize); if ( x < 0 || x > m_mosaicCount*m_brickCount || y < 0 || y > m_mosaicCount*m_brickCount ) - return Gfx::TR_NULL; + return TR_NULL; int size = (m_mosaicCount*m_brickCount)+1; @@ -238,20 +241,20 @@ Gfx::TerrainRes Gfx::CTerrain::GetResource(const Math::Vector &p) int resG = m_resources[3*x+3*size*(size-y-1)+1]; int resB = m_resources[3*x+3*size*(size-y-1)+2]; - if (resR == 255 && resG == 0 && resB == 0) return Gfx::TR_STONE; - if (resR == 255 && resG == 255 && resB == 0) return Gfx::TR_URANIUM; - if (resR == 0 && resG == 255 && resB == 0) return Gfx::TR_POWER; + if (resR == 255 && resG == 0 && resB == 0) return TR_STONE; + if (resR == 255 && resG == 255 && resB == 0) return TR_URANIUM; + if (resR == 0 && resG == 255 && resB == 0) return TR_POWER; // TODO key res values - //if (ress == 24) return Gfx::TR_KEY_A; // ~green? - //if (ress == 25) return Gfx::TR_KEY_B; // ~green? - //if (ress == 26) return Gfx::TR_KEY_C; // ~green? - //if (ress == 27) return Gfx::TR_KEY_D; // ~green? + //if (ress == 24) return TR_KEY_A; // ~green? + //if (ress == 25) return TR_KEY_B; // ~green? + //if (ress == 26) return TR_KEY_C; // ~green? + //if (ress == 27) return TR_KEY_D; // ~green? return TR_NULL; } -void Gfx::CTerrain::FlushRelief() +void CTerrain::FlushRelief() { m_relief.clear(); } @@ -259,7 +262,7 @@ void Gfx::CTerrain::FlushRelief() /** * The image must be 24 bits/pixel and dx x dy in size * with dx = dy = (mosaic*brick)+1 */ -bool Gfx::CTerrain::LoadRelief(const std::string &fileName, float scaleRelief, +bool CTerrain::LoadRelief(const std::string &fileName, float scaleRelief, bool adjustBorder) { m_scaleRelief = scaleRelief; @@ -304,7 +307,7 @@ bool Gfx::CTerrain::LoadRelief(const std::string &fileName, float scaleRelief, return true; } -bool Gfx::CTerrain::AddReliefPoint(Math::Vector pos, float scaleRelief) +bool CTerrain::AddReliefPoint(Math::Vector pos, float scaleRelief) { float dim = (m_mosaicCount*m_brickCount*m_brickSize)/2.0f; int size = (m_mosaicCount*m_brickCount)+1; @@ -324,7 +327,7 @@ bool Gfx::CTerrain::AddReliefPoint(Math::Vector pos, float scaleRelief) return true; } -void Gfx::CTerrain::AdjustRelief() +void CTerrain::AdjustRelief() { if (m_depth == 1) return; @@ -383,7 +386,7 @@ void Gfx::CTerrain::AdjustRelief() } } -Math::Vector Gfx::CTerrain::GetVector(int x, int y) +Math::Vector CTerrain::GetVector(int x, int y) { Math::Vector p; p.x = x*m_brickSize - (m_mosaicCount*m_brickCount*m_brickSize) / 2.0; @@ -416,9 +419,9 @@ Math::Vector Gfx::CTerrain::GetVector(int x, int y) | \| \| +---f---e--> x \endverbatim */ -Gfx::VertexTex2 Gfx::CTerrain::GetVertex(int x, int y, int step) +VertexTex2 CTerrain::GetVertex(int x, int y, int step) { - Gfx::VertexTex2 v; + VertexTex2 v; Math::Vector o = GetVector(x, y); v.coord = o; @@ -473,8 +476,8 @@ Gfx::VertexTex2 Gfx::CTerrain::GetVertex(int x, int y, int step) | +-------------------> x \endverbatim */ -bool Gfx::CTerrain::CreateMosaic(int ox, int oy, int step, int objRank, - const Gfx::Material &mat, +bool CTerrain::CreateMosaic(int ox, int oy, int step, int objRank, + const Material &mat, float min, float max) { std::string texName1; @@ -494,7 +497,7 @@ bool Gfx::CTerrain::CreateMosaic(int ox, int oy, int step, int objRank, int brick = m_brickCount/m_textureSubdivCount; - Gfx::VertexTex2 o = GetVertex(ox*m_brickCount+m_brickCount/2, oy*m_brickCount+m_brickCount/2, step); + VertexTex2 o = GetVertex(ox*m_brickCount+m_brickCount/2, oy*m_brickCount+m_brickCount/2, step); int total = ((brick/step)+1)*2; float pixel = 1.0f/256.0f; // 1 pixel cover (*) @@ -526,22 +529,22 @@ bool Gfx::CTerrain::CreateMosaic(int ox, int oy, int step, int objRank, for (int y = 0; y < brick; y += step) { - Gfx::EngineObjLevel4 buffer; + EngineObjLevel4 buffer; buffer.vertices.reserve(total); - buffer.type = Gfx::ENG_TRIANGLE_TYPE_SURFACE; + buffer.type = ENG_TRIANGLE_TYPE_SURFACE; buffer.material = mat; - buffer.state = Gfx::ENG_RSTATE_WRAP; + buffer.state = ENG_RSTATE_WRAP; - buffer.state |= Gfx::ENG_RSTATE_SECOND; + buffer.state |= ENG_RSTATE_SECOND; if (step == 1) - buffer.state |= Gfx::ENG_RSTATE_DUAL_BLACK; + buffer.state |= ENG_RSTATE_DUAL_BLACK; for (int x = 0; x <= brick; x += step) { - Gfx::VertexTex2 p1 = GetVertex(ox*m_brickCount+mx*brick+x, oy*m_brickCount+my*brick+y+0 , step); - Gfx::VertexTex2 p2 = GetVertex(ox*m_brickCount+mx*brick+x, oy*m_brickCount+my*brick+y+step, step); + VertexTex2 p1 = GetVertex(ox*m_brickCount+mx*brick+x, oy*m_brickCount+my*brick+y+0 , step); + VertexTex2 p2 = GetVertex(ox*m_brickCount+mx*brick+x, oy*m_brickCount+my*brick+y+step, step); p1.coord.x -= o.coord.x; p1.coord.z -= o.coord.z; p2.coord.x -= o.coord.x; p2.coord.z -= o.coord.z; @@ -633,7 +636,7 @@ bool Gfx::CTerrain::CreateMosaic(int ox, int oy, int step, int objRank, return true; } -Gfx::TerrainMaterial* Gfx::CTerrain::FindMaterial(int id) +TerrainMaterial* CTerrain::FindMaterial(int id) { for (int i = 0; i < static_cast<int>( m_materials.size() ); i++) { @@ -644,7 +647,7 @@ Gfx::TerrainMaterial* Gfx::CTerrain::FindMaterial(int id) return nullptr; } -void Gfx::CTerrain::GetTexture(int x, int y, std::string& name, Math::Point &uv) +void CTerrain::GetTexture(int x, int y, std::string& name, Math::Point &uv) { x /= m_brickCount/m_textureSubdivCount; y /= m_brickCount/m_textureSubdivCount; @@ -662,7 +665,7 @@ void Gfx::CTerrain::GetTexture(int x, int y, std::string& name, Math::Point &uv) } } -float Gfx::CTerrain::GetHeight(int x, int y) +float CTerrain::GetHeight(int x, int y) { int size = (m_mosaicCount*m_brickCount+1); @@ -674,7 +677,7 @@ float Gfx::CTerrain::GetHeight(int x, int y) return m_relief[x+y*size]; } -bool Gfx::CTerrain::CheckMaterialPoint(int x, int y, float min, float max, float slope) +bool CTerrain::CheckMaterialPoint(int x, int y, float min, float max, float slope) { float hc = GetHeight(x, y); float h[4] = @@ -714,7 +717,7 @@ bool Gfx::CTerrain::CheckMaterialPoint(int x, int y, float min, float max, float return false; } -int Gfx::CTerrain::FindMaterialByNeighbors(char *mat) +int CTerrain::FindMaterialByNeighbors(char *mat) { for (int i = 0; i < static_cast<int>( m_materials.size() ); i++) { @@ -727,7 +730,7 @@ int Gfx::CTerrain::FindMaterialByNeighbors(char *mat) return -1; } -void Gfx::CTerrain::SetMaterialPoint(int x, int y, int id, char *mat) +void CTerrain::SetMaterialPoint(int x, int y, int id, char *mat) { TerrainMaterial* tm = FindMaterial(id); if (tm == nullptr) return; @@ -806,7 +809,7 @@ void Gfx::CTerrain::SetMaterialPoint(int x, int y, int id, char *mat) } } -bool Gfx::CTerrain::CondChangeMaterialPoint(int x, int y, int id, char *mat) +bool CTerrain::CondChangeMaterialPoint(int x, int y, int id, char *mat) { char test[4]; @@ -862,7 +865,7 @@ bool Gfx::CTerrain::CondChangeMaterialPoint(int x, int y, int id, char *mat) return true; } -bool Gfx::CTerrain::ChangeMaterialPoint(int x, int y, int id) +bool CTerrain::ChangeMaterialPoint(int x, int y, int id) { char mat[4]; @@ -1022,7 +1025,7 @@ bool Gfx::CTerrain::ChangeMaterialPoint(int x, int y, int id) return false; } -bool Gfx::CTerrain::InitMaterials(int id) +bool CTerrain::InitMaterials(int id) { TerrainMaterial* tm = FindMaterial(id); if (tm == nullptr) return false; @@ -1038,7 +1041,7 @@ bool Gfx::CTerrain::InitMaterials(int id) return true; } -bool Gfx::CTerrain::GenerateMaterials(int *id, float min, float max, +bool CTerrain::GenerateMaterials(int *id, float min, float max, float slope, float freq, Math::Vector center, float radius) { @@ -1118,13 +1121,13 @@ bool Gfx::CTerrain::GenerateMaterials(int *id, float min, float max, return true; } -void Gfx::CTerrain::InitMaterialPoints() +void CTerrain::InitMaterialPoints() { if (! m_useMaterials) return; if (! m_materialPoints.empty()) return; // already allocated m_materialPointCount = (m_mosaicCount*m_brickCount)/(m_brickCount/m_textureSubdivCount)+1; - std::vector<Gfx::TerrainMaterialPoint>(m_materialPointCount*m_materialPointCount).swap(m_materialPoints); + std::vector<TerrainMaterialPoint>(m_materialPointCount*m_materialPointCount).swap(m_materialPoints); for (int i = 0; i < m_materialPointCount * m_materialPointCount; i++) { @@ -1133,19 +1136,19 @@ void Gfx::CTerrain::InitMaterialPoints() } } -void Gfx::CTerrain::FlushMaterialPoints() +void CTerrain::FlushMaterialPoints() { m_materialPoints.clear(); } -bool Gfx::CTerrain::CreateSquare(int x, int y) +bool CTerrain::CreateSquare(int x, int y) { - Gfx::Material mat; - mat.diffuse = Gfx::Color(1.0f, 1.0f, 1.0f); - mat.ambient = Gfx::Color(0.0f, 0.0f, 0.0f); + Material mat; + mat.diffuse = Color(1.0f, 1.0f, 1.0f); + mat.ambient = Color(0.0f, 0.0f, 0.0f); int objRank = m_engine->CreateObject(); - m_engine->SetObjectType(objRank, Gfx::ENG_OBJTYPE_TERRAIN); + m_engine->SetObjectType(objRank, ENG_OBJTYPE_TERRAIN); m_objRanks[x+y*m_mosaicCount] = objRank; @@ -1163,7 +1166,7 @@ bool Gfx::CTerrain::CreateSquare(int x, int y) return true; } -bool Gfx::CTerrain::CreateObjects() +bool CTerrain::CreateObjects() { AdjustRelief(); @@ -1177,7 +1180,7 @@ bool Gfx::CTerrain::CreateObjects() } /** ATTENTION: ok only with m_depth = 2! */ -bool Gfx::CTerrain::Terraform(const Math::Vector &p1, const Math::Vector &p2, float height) +bool CTerrain::Terraform(const Math::Vector &p1, const Math::Vector &p2, float height) { float dim = (m_mosaicCount*m_brickCount*m_brickSize)/2.0f; @@ -1262,24 +1265,24 @@ bool Gfx::CTerrain::Terraform(const Math::Vector &p1, const Math::Vector &p2, fl return true; } -void Gfx::CTerrain::SetWind(Math::Vector speed) +void CTerrain::SetWind(Math::Vector speed) { m_wind = speed; } -Math::Vector Gfx::CTerrain::GetWind() +Math::Vector CTerrain::GetWind() { return m_wind; } -float Gfx::CTerrain::GetFineSlope(const Math::Vector &pos) +float CTerrain::GetFineSlope(const Math::Vector &pos) { Math::Vector n; if (! GetNormal(n, pos)) return 0.0f; return fabs(Math::RotateAngle(Math::Point(n.x, n.z).Length(), n.y) - Math::PI/2.0f); } -float Gfx::CTerrain::GetCoarseSlope(const Math::Vector &pos) +float CTerrain::GetCoarseSlope(const Math::Vector &pos) { if (m_relief.empty()) return 0.0f; @@ -1305,7 +1308,7 @@ float Gfx::CTerrain::GetCoarseSlope(const Math::Vector &pos) return atanf((max-min)/m_brickSize); } -bool Gfx::CTerrain::GetNormal(Math::Vector &n, const Math::Vector &p) +bool CTerrain::GetNormal(Math::Vector &n, const Math::Vector &p) { float dim = (m_mosaicCount*m_brickCount*m_brickSize)/2.0f; @@ -1328,7 +1331,7 @@ bool Gfx::CTerrain::GetNormal(Math::Vector &n, const Math::Vector &p) return true; } -float Gfx::CTerrain::GetFloorLevel(const Math::Vector &pos, bool brut, bool water) +float CTerrain::GetFloorLevel(const Math::Vector &pos, bool brut, bool water) { float dim = (m_mosaicCount*m_brickCount*m_brickSize)/2.0f; @@ -1364,7 +1367,7 @@ float Gfx::CTerrain::GetFloorLevel(const Math::Vector &pos, bool brut, bool wate return ps.y; } -float Gfx::CTerrain::GetHeightToFloor(const Math::Vector &pos, bool brut, bool water) +float CTerrain::GetHeightToFloor(const Math::Vector &pos, bool brut, bool water) { float dim = (m_mosaicCount*m_brickCount*m_brickSize)/2.0f; @@ -1400,7 +1403,7 @@ float Gfx::CTerrain::GetHeightToFloor(const Math::Vector &pos, bool brut, bool w return pos.y-ps.y; } -bool Gfx::CTerrain::AdjustToFloor(Math::Vector &pos, bool brut, bool water) +bool CTerrain::AdjustToFloor(Math::Vector &pos, bool brut, bool water) { float dim = (m_mosaicCount*m_brickCount*m_brickSize)/2.0f; @@ -1438,7 +1441,7 @@ bool Gfx::CTerrain::AdjustToFloor(Math::Vector &pos, bool brut, bool water) /** * @returns \c false if the initial coordinate was outside terrain area; \c true otherwise */ -bool Gfx::CTerrain::AdjustToStandardBounds(Math::Vector& pos) +bool CTerrain::AdjustToStandardBounds(Math::Vector& pos) { bool ok = true; @@ -1476,7 +1479,7 @@ bool Gfx::CTerrain::AdjustToStandardBounds(Math::Vector& pos) * @param margin margin to the terrain border * @returns \c false if the initial coordinate was outside terrain area; \c true otherwise */ -bool Gfx::CTerrain::AdjustToBounds(Math::Vector& pos, float margin) +bool CTerrain::AdjustToBounds(Math::Vector& pos, float margin) { bool ok = true; float limit = m_mosaicCount*m_brickCount*m_brickSize/2.0f - margin; @@ -1508,12 +1511,12 @@ bool Gfx::CTerrain::AdjustToBounds(Math::Vector& pos, float margin) return ok; } -void Gfx::CTerrain::FlushBuildingLevel() +void CTerrain::FlushBuildingLevel() { m_buildingLevels.clear(); } -bool Gfx::CTerrain::AddBuildingLevel(Math::Vector center, float min, float max, +bool CTerrain::AddBuildingLevel(Math::Vector center, float min, float max, float height, float factor) { int i = 0; @@ -1527,7 +1530,7 @@ bool Gfx::CTerrain::AddBuildingLevel(Math::Vector center, float min, float max, } if (i == static_cast<int>( m_buildingLevels.size() )) - m_buildingLevels.push_back(Gfx::BuildingLevel()); + m_buildingLevels.push_back(BuildingLevel()); m_buildingLevels[i].center = center; m_buildingLevels[i].min = min; @@ -1543,7 +1546,7 @@ bool Gfx::CTerrain::AddBuildingLevel(Math::Vector center, float min, float max, return true; } -bool Gfx::CTerrain::UpdateBuildingLevel(Math::Vector center) +bool CTerrain::UpdateBuildingLevel(Math::Vector center) { for (int i = 0; i < static_cast<int>( m_buildingLevels.size() ); i++) { @@ -1558,7 +1561,7 @@ bool Gfx::CTerrain::UpdateBuildingLevel(Math::Vector center) return false; } -bool Gfx::CTerrain::DeleteBuildingLevel(Math::Vector center) +bool CTerrain::DeleteBuildingLevel(Math::Vector center) { for (int i = 0; i < static_cast<int>( m_buildingLevels.size() ); i++) { @@ -1575,7 +1578,7 @@ bool Gfx::CTerrain::DeleteBuildingLevel(Math::Vector center) return false; } -float Gfx::CTerrain::GetBuildingFactor(const Math::Vector &p) +float CTerrain::GetBuildingFactor(const Math::Vector &p) { for (int i = 0; i < static_cast<int>( m_buildingLevels.size() ); i++) { @@ -1592,7 +1595,7 @@ float Gfx::CTerrain::GetBuildingFactor(const Math::Vector &p) return 1.0f; // it is normal on the ground } -void Gfx::CTerrain::AdjustBuildingLevel(Math::Vector &p) +void CTerrain::AdjustBuildingLevel(Math::Vector &p) { for (int i = 0; i < static_cast<int>( m_buildingLevels.size() ); i++) { @@ -1628,7 +1631,7 @@ void Gfx::CTerrain::AdjustBuildingLevel(Math::Vector &p) } } -float Gfx::CTerrain::GetHardness(const Math::Vector &p) +float CTerrain::GetHardness(const Math::Vector &p) { float factor = GetBuildingFactor(p); if (factor != 1.0f) return 1.0f; // on building level @@ -1658,7 +1661,7 @@ float Gfx::CTerrain::GetHardness(const Math::Vector &p) return tm->hardness; } -void Gfx::CTerrain::ShowFlatGround(Math::Vector pos) +void CTerrain::ShowFlatGround(Math::Vector pos) { static char table[41*41] = { 1 }; @@ -1681,7 +1684,7 @@ void Gfx::CTerrain::ShowFlatGround(Math::Vector pos) float angle = GetFineSlope(pos+p); - if (angle < Gfx::TERRAIN_FLATLIMIT) + if (angle < TERRAIN_FLATLIMIT) table[i] = 1; else table[i] = 2; @@ -1691,10 +1694,10 @@ void Gfx::CTerrain::ShowFlatGround(Math::Vector pos) m_engine->CreateGroundMark(pos, 40.0f, 0.001f, 15.0f, 0.001f, 41, 41, table); } -float Gfx::CTerrain::GetFlatZoneRadius(Math::Vector center, float max) +float CTerrain::GetFlatZoneRadius(Math::Vector center, float max) { float angle = GetFineSlope(center); - if (angle >= Gfx::TERRAIN_FLATLIMIT) + if (angle >= TERRAIN_FLATLIMIT) return 0.0f; float ref = GetFloorLevel(center, true); @@ -1724,27 +1727,27 @@ float Gfx::CTerrain::GetFlatZoneRadius(Math::Vector center, float max) return max; } -void Gfx::CTerrain::SetFlyingMaxHeight(float height) +void CTerrain::SetFlyingMaxHeight(float height) { m_flyingMaxHeight = height; } -float Gfx::CTerrain::GetFlyingMaxHeight() +float CTerrain::GetFlyingMaxHeight() { return m_flyingMaxHeight; } -void Gfx::CTerrain::FlushFlyingLimit() +void CTerrain::FlushFlyingLimit() { m_flyingMaxHeight = 280.0f; m_flyingLimits.clear(); } -void Gfx::CTerrain::AddFlyingLimit(Math::Vector center, +void CTerrain::AddFlyingLimit(Math::Vector center, float extRadius, float intRadius, float maxHeight) { - Gfx::FlyingLimit fl; + FlyingLimit fl; fl.center = center; fl.extRadius = extRadius; fl.intRadius = intRadius; @@ -1752,7 +1755,7 @@ void Gfx::CTerrain::AddFlyingLimit(Math::Vector center, m_flyingLimits.push_back(fl); } -float Gfx::CTerrain::GetFlyingLimit(Math::Vector pos, bool noLimit) +float CTerrain::GetFlyingLimit(Math::Vector pos, bool noLimit) { if (noLimit) return 280.0f; @@ -1780,3 +1783,6 @@ float Gfx::CTerrain::GetFlyingLimit(Math::Vector pos, bool noLimit) return m_flyingMaxHeight; } + + +} // namespace Gfx diff --git a/src/graphics/engine/terrain.h b/src/graphics/engine/terrain.h index 80eed07..b83bfc8 100644 --- a/src/graphics/engine/terrain.h +++ b/src/graphics/engine/terrain.h @@ -17,17 +17,19 @@ /** * \file graphics/engine/terrain.h - * \brief Terrain rendering - Gfx::CTerrain class + * \brief Terrain rendering - CTerrain class */ #pragma once + #include "graphics/engine/engine.h" class CInstanceManager; +// Graphics module namespace namespace Gfx { class CEngine; @@ -277,7 +279,7 @@ public: //! Adjusts 3D position so that it is within terrain boundaries and the given margin bool AdjustToBounds(Math::Vector& pos, float margin); //! Returns the resource type available underground at 2D (XZ) position - Gfx::TerrainRes GetResource(const Math::Vector& pos); + TerrainRes GetResource(const Math::Vector& pos); //! Empty the table of elevations void FlushBuildingLevel(); @@ -326,14 +328,14 @@ protected: //! Calculates a vector of the terrain Math::Vector GetVector(int x, int y); //! Calculates a vertex of the terrain - Gfx::VertexTex2 GetVertex(int x, int y, int step); + VertexTex2 GetVertex(int x, int y, int step); //! Creates all objects of a mosaic - bool CreateMosaic(int ox, int oy, int step, int objRank, const Gfx::Material& mat, float min, float max); + bool CreateMosaic(int ox, int oy, int step, int objRank, const Material& mat, float min, float max); //! Creates all objects in a mesh square ground bool CreateSquare(int x, int y); //! Seeks a material based on its ID - Gfx::TerrainMaterial* FindMaterial(int id); + TerrainMaterial* FindMaterial(int id); //! Seeks a material based on neighbor values int FindMaterialByNeighbors(char *mat); //! Returns the texture name and UV coords to use for a given square @@ -399,15 +401,15 @@ protected: //! True if using terrain material mapping bool m_useMaterials; //! Terrain materials - std::vector<Gfx::TerrainMaterial> m_materials; + std::vector<TerrainMaterial> m_materials; //! Material for terrain points - std::vector<Gfx::TerrainMaterialPoint> m_materialPoints; + std::vector<TerrainMaterialPoint> m_materialPoints; //! Maximum level ID (no ID is >= to this) int m_maxMaterialID; //! Internal counter for auto generation of material IDs int m_materialAutoID; - std::vector<Gfx::BuildingLevel> m_buildingLevels; + std::vector<BuildingLevel> m_buildingLevels; //! Wind speed Math::Vector m_wind; @@ -415,7 +417,8 @@ protected: //! Global flying height limit float m_flyingMaxHeight; //! List of local flight limits - std::vector<Gfx::FlyingLimit> m_flyingLimits; + std::vector<FlyingLimit> m_flyingLimits; }; -}; // namespace Gfx + +} // namespace Gfx diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index 8fc8709..7e226a0 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -15,7 +15,6 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// text.cpp #include "graphics/engine/text.h" @@ -30,25 +29,27 @@ #include <SDL/SDL_ttf.h> -namespace Gfx -{ +// Graphics module namespace +namespace Gfx { + /** - \struct CachedFont - \brief Base TTF font with UTF-8 char cache */ + * \struct CachedFont + * \brief Base TTF font with UTF-8 char cache + */ struct CachedFont { TTF_Font* font; - std::map<Gfx::UTF8Char, Gfx::CharTexture> cache; + std::map<UTF8Char, CharTexture> cache; CachedFont() : font(nullptr) {} }; -}; -Gfx::CText::CText(CInstanceManager *iMan, Gfx::CEngine* engine) + +CText::CText(CInstanceManager *iMan, CEngine* engine) { m_iMan = iMan; m_iMan->AddInstance(CLASS_TEXT, this); @@ -59,12 +60,12 @@ Gfx::CText::CText(CInstanceManager *iMan, Gfx::CEngine* engine) m_defaultSize = 12.0f; m_fontPath = "fonts"; - m_lastFontType = Gfx::FONT_COLOBOT; + m_lastFontType = FONT_COLOBOT; m_lastFontSize = 0; m_lastCachedFont = nullptr; } -Gfx::CText::~CText() +CText::~CText() { m_iMan->DeleteInstance(CLASS_TEXT, this); @@ -73,7 +74,7 @@ Gfx::CText::~CText() m_engine = nullptr; } -bool Gfx::CText::Create() +bool CText::Create() { if (TTF_Init() != 0) { @@ -81,16 +82,16 @@ bool Gfx::CText::Create() return false; } - m_fonts[Gfx::FONT_COLOBOT] = new MultisizeFont("dvu_sans.ttf"); - m_fonts[Gfx::FONT_COLOBOT_BOLD] = new MultisizeFont("dvu_sans_bold.ttf"); - m_fonts[Gfx::FONT_COLOBOT_ITALIC] = new MultisizeFont("dvu_sans_italic.ttf"); + m_fonts[FONT_COLOBOT] = new MultisizeFont("dvu_sans.ttf"); + m_fonts[FONT_COLOBOT_BOLD] = new MultisizeFont("dvu_sans_bold.ttf"); + m_fonts[FONT_COLOBOT_ITALIC] = new MultisizeFont("dvu_sans_italic.ttf"); - m_fonts[Gfx::FONT_COURIER] = new MultisizeFont("dvu_sans_mono.ttf"); - m_fonts[Gfx::FONT_COURIER_BOLD] = new MultisizeFont("dvu_sans_mono_bold.ttf"); + m_fonts[FONT_COURIER] = new MultisizeFont("dvu_sans_mono.ttf"); + m_fonts[FONT_COURIER_BOLD] = new MultisizeFont("dvu_sans_mono_bold.ttf"); for (auto it = m_fonts.begin(); it != m_fonts.end(); ++it) { - Gfx::FontType type = (*it).first; + FontType type = (*it).first; CachedFont* cf = GetOrOpenFont(type, m_defaultSize); if (cf == nullptr || cf->font == nullptr) return false; @@ -99,7 +100,7 @@ bool Gfx::CText::Create() return true; } -void Gfx::CText::Destroy() +void CText::Destroy() { for (auto it = m_fonts.begin(); it != m_fonts.end(); ++it) { @@ -126,17 +127,17 @@ void Gfx::CText::Destroy() TTF_Quit(); } -void Gfx::CText::SetDevice(Gfx::CDevice* device) +void CText::SetDevice(CDevice* device) { m_device = device; } -std::string Gfx::CText::GetError() +std::string CText::GetError() { return m_error; } -void Gfx::CText::FlushCache() +void CText::FlushCache() { for (auto it = m_fonts.begin(); it != m_fonts.end(); ++it) { @@ -149,19 +150,19 @@ void Gfx::CText::FlushCache() } } -void Gfx::CText::DrawText(const std::string &text, const std::vector<FontMetaChar> &format, - float size, Math::Point pos, float width, Gfx::TextAlign align, +void CText::DrawText(const std::string &text, const std::vector<FontMetaChar> &format, + float size, Math::Point pos, float width, TextAlign align, int eol) { float sw = 0.0f; - if (align == Gfx::TEXT_ALIGN_CENTER) + if (align == TEXT_ALIGN_CENTER) { sw = GetStringWidth(text, format, size); if (sw > width) sw = width; pos.x -= sw / 2.0f; } - else if (align == Gfx::TEXT_ALIGN_RIGHT) + else if (align == TEXT_ALIGN_RIGHT) { sw = GetStringWidth(text, format, size); if (sw > width) sw = width; @@ -171,19 +172,19 @@ void Gfx::CText::DrawText(const std::string &text, const std::vector<FontMetaCha DrawString(text, format, size, pos, width, eol); } -void Gfx::CText::DrawText(const std::string &text, Gfx::FontType font, - float size, Math::Point pos, float width, Gfx::TextAlign align, +void CText::DrawText(const std::string &text, FontType font, + float size, Math::Point pos, float width, TextAlign align, int eol) { float sw = 0.0f; - if (align == Gfx::TEXT_ALIGN_CENTER) + if (align == TEXT_ALIGN_CENTER) { sw = GetStringWidth(text, font, size); if (sw > width) sw = width; pos.x -= sw / 2.0f; } - else if (align == Gfx::TEXT_ALIGN_RIGHT) + else if (align == TEXT_ALIGN_RIGHT) { sw = GetStringWidth(text, font, size); if (sw > width) sw = width; @@ -193,43 +194,43 @@ void Gfx::CText::DrawText(const std::string &text, Gfx::FontType font, DrawString(text, font, size, pos, width, eol); } -void Gfx::CText::SizeText(const std::string &text, const std::vector<FontMetaChar> &format, - float size, Math::Point pos, Gfx::TextAlign align, +void CText::SizeText(const std::string &text, const std::vector<FontMetaChar> &format, + float size, Math::Point pos, TextAlign align, Math::Point &start, Math::Point &end) { start = end = pos; float sw = GetStringWidth(text, format, size); end.x += sw; - if (align == Gfx::TEXT_ALIGN_CENTER) + if (align == TEXT_ALIGN_CENTER) { start.x -= sw/2.0f; end.x -= sw/2.0f; } - else if (align == Gfx::TEXT_ALIGN_RIGHT) + else if (align == TEXT_ALIGN_RIGHT) { start.x -= sw; end.x -= sw; } - start.y -= GetDescent(Gfx::FONT_COLOBOT, size); - end.y += GetAscent(Gfx::FONT_COLOBOT, size); + start.y -= GetDescent(FONT_COLOBOT, size); + end.y += GetAscent(FONT_COLOBOT, size); } -void Gfx::CText::SizeText(const std::string &text, Gfx::FontType font, - float size, Math::Point pos, Gfx::TextAlign align, +void CText::SizeText(const std::string &text, FontType font, + float size, Math::Point pos, TextAlign align, Math::Point &start, Math::Point &end) { start = end = pos; float sw = GetStringWidth(text, font, size); end.x += sw; - if (align == Gfx::TEXT_ALIGN_CENTER) + if (align == TEXT_ALIGN_CENTER) { start.x -= sw/2.0f; end.x -= sw/2.0f; } - else if (align == Gfx::TEXT_ALIGN_RIGHT) + else if (align == TEXT_ALIGN_RIGHT) { start.x -= sw; end.x -= sw; @@ -239,11 +240,11 @@ void Gfx::CText::SizeText(const std::string &text, Gfx::FontType font, end.y += GetAscent(font, size); } -float Gfx::CText::GetAscent(Gfx::FontType font, float size) +float CText::GetAscent(FontType font, float size) { - assert(font != Gfx::FONT_BUTTON); + assert(font != FONT_BUTTON); - Gfx::CachedFont* cf = GetOrOpenFont(font, size); + CachedFont* cf = GetOrOpenFont(font, size); assert(cf != nullptr); Math::IntPoint wndSize; wndSize.y = TTF_FontAscent(cf->font); @@ -251,11 +252,11 @@ float Gfx::CText::GetAscent(Gfx::FontType font, float size) return ifSize.y; } -float Gfx::CText::GetDescent(Gfx::FontType font, float size) +float CText::GetDescent(FontType font, float size) { - assert(font != Gfx::FONT_BUTTON); + assert(font != FONT_BUTTON); - Gfx::CachedFont* cf = GetOrOpenFont(font, size); + CachedFont* cf = GetOrOpenFont(font, size); assert(cf != nullptr); Math::IntPoint wndSize; wndSize.y = TTF_FontDescent(cf->font); @@ -263,11 +264,11 @@ float Gfx::CText::GetDescent(Gfx::FontType font, float size) return ifSize.y; } -float Gfx::CText::GetHeight(Gfx::FontType font, float size) +float CText::GetHeight(FontType font, float size) { - assert(font != Gfx::FONT_BUTTON); + assert(font != FONT_BUTTON); - Gfx::CachedFont* cf = GetOrOpenFont(font, size); + CachedFont* cf = GetOrOpenFont(font, size); assert(cf != nullptr); Math::IntPoint wndSize; wndSize.y = TTF_FontHeight(cf->font); @@ -276,7 +277,7 @@ float Gfx::CText::GetHeight(Gfx::FontType font, float size) } -float Gfx::CText::GetStringWidth(const std::string &text, +float CText::GetStringWidth(const std::string &text, const std::vector<FontMetaChar> &format, float size) { assert(StrUtils::Utf8StringLength(text) == format.size()); @@ -286,9 +287,9 @@ float Gfx::CText::GetStringWidth(const std::string &text, unsigned int fmtIndex = 0; while (index < text.length()) { - Gfx::FontType font = static_cast<Gfx::FontType>(format[fmtIndex] & Gfx::FONT_MASK_FONT); + FontType font = static_cast<FontType>(format[fmtIndex] & FONT_MASK_FONT); - Gfx::UTF8Char ch; + UTF8Char ch; int len = StrUtils::Utf8CharSizeAt(text, index); if (len >= 1) @@ -307,13 +308,13 @@ float Gfx::CText::GetStringWidth(const std::string &text, return width; } -float Gfx::CText::GetStringWidth(const std::string &text, Gfx::FontType font, float size) +float CText::GetStringWidth(const std::string &text, FontType font, float size) { - assert(font != Gfx::FONT_BUTTON); + assert(font != FONT_BUTTON); // TODO: special chars? - Gfx::CachedFont* cf = GetOrOpenFont(font, size); + CachedFont* cf = GetOrOpenFont(font, size); assert(cf != nullptr); Math::IntPoint wndSize; TTF_SizeUTF8(cf->font, text.c_str(), &wndSize.x, &wndSize.y); @@ -321,18 +322,18 @@ float Gfx::CText::GetStringWidth(const std::string &text, Gfx::FontType font, fl return ifSize.x; } -float Gfx::CText::GetCharWidth(Gfx::UTF8Char ch, Gfx::FontType font, float size, float offset) +float CText::GetCharWidth(UTF8Char ch, FontType font, float size, float offset) { - // TODO: if (font == Gfx::FONT_BUTTON) - if (font == Gfx::FONT_BUTTON) return 0.0f; + // TODO: if (font == FONT_BUTTON) + if (font == FONT_BUTTON) return 0.0f; // TODO: special chars? // TODO: tab sizing - Gfx::CachedFont* cf = GetOrOpenFont(font, size); + CachedFont* cf = GetOrOpenFont(font, size); assert(cf != nullptr); - Gfx::CharTexture tex; + CharTexture tex; auto it = cf->cache.find(ch); if (it != cf->cache.end()) tex = (*it).second; @@ -343,7 +344,7 @@ float Gfx::CText::GetCharWidth(Gfx::UTF8Char ch, Gfx::FontType font, float size, } -int Gfx::CText::Justify(const std::string &text, const std::vector<FontMetaChar> &format, +int CText::Justify(const std::string &text, const std::vector<FontMetaChar> &format, float size, float width) { assert(StrUtils::Utf8StringLength(text) == format.size()); @@ -354,9 +355,9 @@ int Gfx::CText::Justify(const std::string &text, const std::vector<FontMetaChar> unsigned int fmtIndex = 0; while (index < text.length()) { - Gfx::FontType font = static_cast<Gfx::FontType>(format[fmtIndex] & Gfx::FONT_MASK_FONT); + FontType font = static_cast<FontType>(format[fmtIndex] & FONT_MASK_FONT); - Gfx::UTF8Char ch; + UTF8Char ch; int len = StrUtils::Utf8CharSizeAt(text, index); if (len >= 1) @@ -366,7 +367,7 @@ int Gfx::CText::Justify(const std::string &text, const std::vector<FontMetaChar> if (len >= 3) ch.c3 = text[index+2]; - if (font != Gfx::FONT_BUTTON) + if (font != FONT_BUTTON) { if (ch.c1 == '\n') return index+1; @@ -388,16 +389,16 @@ int Gfx::CText::Justify(const std::string &text, const std::vector<FontMetaChar> return index; } -int Gfx::CText::Justify(const std::string &text, Gfx::FontType font, float size, float width) +int CText::Justify(const std::string &text, FontType font, float size, float width) { - assert(font != Gfx::FONT_BUTTON); + assert(font != FONT_BUTTON); float pos = 0.0f; int cut = 0; unsigned int index = 0; while (index < text.length()) { - Gfx::UTF8Char ch; + UTF8Char ch; int len = StrUtils::Utf8CharSizeAt(text, index); if (len >= 1) @@ -426,7 +427,7 @@ int Gfx::CText::Justify(const std::string &text, Gfx::FontType font, float size, return index; } -int Gfx::CText::Detect(const std::string &text, const std::vector<FontMetaChar> &format, +int CText::Detect(const std::string &text, const std::vector<FontMetaChar> &format, float size, float offset) { assert(StrUtils::Utf8StringLength(text) == format.size()); @@ -436,12 +437,12 @@ int Gfx::CText::Detect(const std::string &text, const std::vector<FontMetaChar> unsigned int fmtIndex = 0; while (index < text.length()) { - Gfx::FontType font = static_cast<Gfx::FontType>(format[fmtIndex] & Gfx::FONT_MASK_FONT); + FontType font = static_cast<FontType>(format[fmtIndex] & FONT_MASK_FONT); - // TODO: if (font == Gfx::FONT_BUTTON) - if (font == Gfx::FONT_BUTTON) continue; + // TODO: if (font == FONT_BUTTON) + if (font == FONT_BUTTON) continue; - Gfx::UTF8Char ch; + UTF8Char ch; int len = StrUtils::Utf8CharSizeAt(text, index); if (len >= 1) @@ -466,15 +467,15 @@ int Gfx::CText::Detect(const std::string &text, const std::vector<FontMetaChar> return index; } -int Gfx::CText::Detect(const std::string &text, Gfx::FontType font, float size, float offset) +int CText::Detect(const std::string &text, FontType font, float size, float offset) { - assert(font != Gfx::FONT_BUTTON); + assert(font != FONT_BUTTON); float pos = 0.0f; unsigned int index = 0; while (index < text.length()) { - Gfx::UTF8Char ch; + UTF8Char ch; int len = StrUtils::Utf8CharSizeAt(text, index); if (len >= 1) @@ -499,26 +500,26 @@ int Gfx::CText::Detect(const std::string &text, Gfx::FontType font, float size, return index; } -void Gfx::CText::DrawString(const std::string &text, const std::vector<FontMetaChar> &format, +void CText::DrawString(const std::string &text, const std::vector<FontMetaChar> &format, float size, Math::Point pos, float width, int eol) { assert(StrUtils::Utf8StringLength(text) == format.size()); - m_engine->SetState(Gfx::ENG_RSTATE_TEXT); + m_engine->SetState(ENG_RSTATE_TEXT); - Gfx::FontType font = Gfx::FONT_COLOBOT; + FontType font = FONT_COLOBOT; float start = pos.x; unsigned int index = 0; unsigned int fmtIndex = 0; while (index < text.length()) { - font = static_cast<Gfx::FontType>(format[fmtIndex] & Gfx::FONT_MASK_FONT); + font = static_cast<FontType>(format[fmtIndex] & FONT_MASK_FONT); - // TODO: if (font == Gfx::FONT_BUTTON) - if (font == Gfx::FONT_BUTTON) continue; + // TODO: if (font == FONT_BUTTON) + if (font == FONT_BUTTON) continue; - Gfx::UTF8Char ch; + UTF8Char ch; int len = StrUtils::Utf8CharSizeAt(text, index); if (len >= 1) @@ -536,8 +537,8 @@ void Gfx::CText::DrawString(const std::string &text, const std::vector<FontMetaC break; } - Gfx::FontHighlight hl = static_cast<Gfx::FontHighlight>(format[fmtIndex] & Gfx::FONT_MASK_HIGHLIGHT); - if (hl != Gfx::FONT_HIGHLIGHT_NONE) + FontHighlight hl = static_cast<FontHighlight>(format[fmtIndex] & FONT_MASK_HIGHLIGHT); + if (hl != FONT_HIGHLIGHT_NONE) { Math::Point charSize; charSize.x = GetCharWidth(ch, font, size, offset); @@ -554,17 +555,17 @@ void Gfx::CText::DrawString(const std::string &text, const std::vector<FontMetaC // TODO: eol } -void Gfx::CText::DrawString(const std::string &text, Gfx::FontType font, +void CText::DrawString(const std::string &text, FontType font, float size, Math::Point pos, float width, int eol) { - assert(font != Gfx::FONT_BUTTON); + assert(font != FONT_BUTTON); - m_engine->SetState(Gfx::ENG_RSTATE_TEXT); + m_engine->SetState(ENG_RSTATE_TEXT); unsigned int index = 0; while (index < text.length()) { - Gfx::UTF8Char ch; + UTF8Char ch; int len = StrUtils::Utf8CharSizeAt(text, index); if (len >= 1) @@ -580,42 +581,42 @@ void Gfx::CText::DrawString(const std::string &text, Gfx::FontType font, } } -void Gfx::CText::DrawHighlight(Gfx::FontHighlight hl, Math::Point pos, Math::Point size) +void CText::DrawHighlight(FontHighlight hl, Math::Point pos, Math::Point size) { // Gradient colors - Gfx::Color grad[4]; + Color grad[4]; // TODO: switch to alpha factors switch (hl) { - case Gfx::FONT_HIGHLIGHT_LINK: - grad[0] = grad[1] = grad[2] = grad[3] = Gfx::Color(0.0f, 0.0f, 1.0f, 0.5f); + case FONT_HIGHLIGHT_LINK: + grad[0] = grad[1] = grad[2] = grad[3] = Color(0.0f, 0.0f, 1.0f, 0.5f); break; - case Gfx::FONT_HIGHLIGHT_TOKEN: - grad[0] = grad[1] = Gfx::Color(248.0f / 256.0f, 248.0f / 256.0f, 248.0f / 256.0f, 0.5f); - grad[2] = grad[3] = Gfx::Color(248.0f / 256.0f, 220.0f / 256.0f, 188.0f / 256.0f, 0.5f); + case FONT_HIGHLIGHT_TOKEN: + grad[0] = grad[1] = Color(248.0f / 256.0f, 248.0f / 256.0f, 248.0f / 256.0f, 0.5f); + grad[2] = grad[3] = Color(248.0f / 256.0f, 220.0f / 256.0f, 188.0f / 256.0f, 0.5f); break; - case Gfx::FONT_HIGHLIGHT_TYPE: - grad[0] = grad[1] = Gfx::Color(248.0f / 256.0f, 248.0f / 256.0f, 248.0f / 256.0f, 0.5f); - grad[2] = grad[3] = Gfx::Color(169.0f / 256.0f, 234.0f / 256.0f, 169.0f / 256.0f, 0.5f); + case FONT_HIGHLIGHT_TYPE: + grad[0] = grad[1] = Color(248.0f / 256.0f, 248.0f / 256.0f, 248.0f / 256.0f, 0.5f); + grad[2] = grad[3] = Color(169.0f / 256.0f, 234.0f / 256.0f, 169.0f / 256.0f, 0.5f); break; - case Gfx::FONT_HIGHLIGHT_CONST: - grad[0] = grad[1] = Gfx::Color(248.0f / 256.0f, 248.0f / 256.0f, 248.0f / 256.0f, 0.5f); - grad[2] = grad[3] = Gfx::Color(248.0f / 256.0f, 176.0f / 256.0f, 169.0f / 256.0f, 0.5f); + case FONT_HIGHLIGHT_CONST: + grad[0] = grad[1] = Color(248.0f / 256.0f, 248.0f / 256.0f, 248.0f / 256.0f, 0.5f); + grad[2] = grad[3] = Color(248.0f / 256.0f, 176.0f / 256.0f, 169.0f / 256.0f, 0.5f); break; - case Gfx::FONT_HIGHLIGHT_REM: - grad[0] = grad[1] = Gfx::Color(248.0f / 256.0f, 248.0f / 256.0f, 248.0f / 256.0f, 0.5f); - grad[2] = grad[3] = Gfx::Color(248.0f / 256.0f, 169.0f / 256.0f, 248.0f / 256.0f, 0.5f); + case FONT_HIGHLIGHT_REM: + grad[0] = grad[1] = Color(248.0f / 256.0f, 248.0f / 256.0f, 248.0f / 256.0f, 0.5f); + grad[2] = grad[3] = Color(248.0f / 256.0f, 169.0f / 256.0f, 248.0f / 256.0f, 0.5f); break; - case Gfx::FONT_HIGHLIGHT_KEY: + case FONT_HIGHLIGHT_KEY: grad[0] = grad[1] = grad[2] = grad[3] = - Gfx::Color(192.0f / 256.0f, 192.0f / 256.0f, 192.0f / 256.0f, 0.5f); + Color(192.0f / 256.0f, 192.0f / 256.0f, 192.0f / 256.0f, 0.5f); break; default: @@ -633,7 +634,7 @@ void Gfx::CText::DrawHighlight(Gfx::FontHighlight hl, Math::Point pos, Math::Poi p1.x = pos.x; p2.x = pos.x + size.x; - if (hl == Gfx::FONT_HIGHLIGHT_LINK) + if (hl == FONT_HIGHLIGHT_LINK) { p1.y = pos.y; p2.y = pos.y + h; // just emphasized @@ -644,26 +645,26 @@ void Gfx::CText::DrawHighlight(Gfx::FontHighlight hl, Math::Point pos, Math::Poi p2.y = pos.y + size.y; } - m_device->SetRenderState(Gfx::RENDER_STATE_TEXTURING, false); + m_device->SetRenderState(RENDER_STATE_TEXTURING, false); - Gfx::VertexCol quad[] = + VertexCol quad[] = { - Gfx::VertexCol(Math::Vector(p1.x, p1.y, 0.0f), grad[3]), - Gfx::VertexCol(Math::Vector(p1.x, p2.y, 0.0f), grad[0]), - Gfx::VertexCol(Math::Vector(p2.x, p1.y, 0.0f), grad[2]), - Gfx::VertexCol(Math::Vector(p2.x, p2.y, 0.0f), grad[1]) + VertexCol(Math::Vector(p1.x, p1.y, 0.0f), grad[3]), + VertexCol(Math::Vector(p1.x, p2.y, 0.0f), grad[0]), + VertexCol(Math::Vector(p2.x, p1.y, 0.0f), grad[2]), + VertexCol(Math::Vector(p2.x, p2.y, 0.0f), grad[1]) }; - m_device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, quad, 4); + m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, quad, 4); m_engine->AddStatisticTriangle(2); - m_device->SetRenderState(Gfx::RENDER_STATE_TEXTURING, true); + m_device->SetRenderState(RENDER_STATE_TEXTURING, true); } -void Gfx::CText::DrawChar(Gfx::UTF8Char ch, Gfx::FontType font, float size, Math::Point &pos) +void CText::DrawChar(UTF8Char ch, FontType font, float size, Math::Point &pos) { - // TODO: if (font == Gfx::FONT_BUTTON) - if (font == Gfx::FONT_BUTTON) return; + // TODO: if (font == FONT_BUTTON) + if (font == FONT_BUTTON) return; // TODO: special chars? @@ -693,22 +694,22 @@ void Gfx::CText::DrawChar(Gfx::UTF8Char ch, Gfx::FontType font, float size, Math Math::Vector n(0.0f, 0.0f, -1.0f); // normal - Gfx::Vertex quad[4] = + Vertex quad[4] = { - Gfx::Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(0.0f, 1.0f)), - Gfx::Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(0.0f, 0.0f)), - Gfx::Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(1.0f, 1.0f)), - Gfx::Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(1.0f, 0.0f)) + Vertex(Math::Vector(p1.x, p1.y, 0.0f), n, Math::Point(0.0f, 1.0f)), + Vertex(Math::Vector(p1.x, p2.y, 0.0f), n, Math::Point(0.0f, 0.0f)), + Vertex(Math::Vector(p2.x, p1.y, 0.0f), n, Math::Point(1.0f, 1.0f)), + Vertex(Math::Vector(p2.x, p2.y, 0.0f), n, Math::Point(1.0f, 0.0f)) }; m_device->SetTexture(0, tex.id); - m_device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, quad, 4); + m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, quad, 4); m_engine->AddStatisticTriangle(2); pos.x += tex.charSize.x; } -Gfx::CachedFont* Gfx::CText::GetOrOpenFont(Gfx::FontType font, float size) +CachedFont* CText::GetOrOpenFont(FontType font, float size) { // TODO: sizing int pointSize = static_cast<int>(size); @@ -749,7 +750,7 @@ Gfx::CachedFont* Gfx::CText::GetOrOpenFont(Gfx::FontType font, float size) return m_lastCachedFont; } -Gfx::CharTexture Gfx::CText::CreateCharTexture(Gfx::UTF8Char ch, Gfx::CachedFont* font) +CharTexture CText::CreateCharTexture(UTF8Char ch, CachedFont* font) { CharTexture texture; @@ -775,13 +776,13 @@ Gfx::CharTexture Gfx::CText::CreateCharTexture(Gfx::UTF8Char ch, Gfx::CachedFont ImageData data; data.surface = textureSurface; - Gfx::TextureCreateParams createParams; - createParams.format = Gfx::TEX_IMG_RGBA; - createParams.minFilter = Gfx::TEX_MIN_FILTER_NEAREST; - createParams.magFilter = Gfx::TEX_MAG_FILTER_NEAREST; + TextureCreateParams createParams; + createParams.format = TEX_IMG_RGBA; + createParams.minFilter = TEX_MIN_FILTER_NEAREST; + createParams.magFilter = TEX_MAG_FILTER_NEAREST; createParams.mipmap = false; - Gfx::Texture tex = m_device->CreateTexture(&data, createParams); + Texture tex = m_device->CreateTexture(&data, createParams); data.surface = nullptr; @@ -802,3 +803,6 @@ Gfx::CharTexture Gfx::CText::CreateCharTexture(Gfx::UTF8Char ch, Gfx::CachedFont return texture; } + + +} // namespace Gfx diff --git a/src/graphics/engine/text.h b/src/graphics/engine/text.h index 24251ab..61996b8 100644 --- a/src/graphics/engine/text.h +++ b/src/graphics/engine/text.h @@ -17,18 +17,22 @@ /** * \file graphics/engine/text.h - * \brief Text rendering - Gfx::CText class + * \brief Text rendering - CText class */ #pragma once + #include "math/point.h" #include <vector> #include <map> + class CInstanceManager; + +// Graphics module namespace namespace Gfx { class CEngine; @@ -40,8 +44,9 @@ const float FONT_SIZE_SMALL = 10.0f; const float FONT_SIZE_BIG = 15.0f; /** - \enum TextAlign - \brief Type of text alignment */ + * \enum TextAlign + * \brief Type of text alignment + */ enum TextAlign { TEXT_ALIGN_RIGHT, @@ -55,10 +60,11 @@ enum TextAlign typedef short FontMetaChar; /** - \enum FontType - \brief Type of font - - Bitmask in lower 4 bits (mask 0x00f) */ + * \enum FontType + * \brief Type of font + * + * Bitmask in lower 4 bits (mask 0x00f) + */ enum FontType { //! Flag for bold font subtype @@ -85,12 +91,13 @@ enum FontType }; /** - \enum FontTitle - \brief Size of font title - - Used internally by CEdit - - Bitmask in 2 bits left shifted 4 (mask 0x030) */ + * \enum FontTitle + * \brief Size of font title + * + * Used internally by CEdit + * + * Bitmask in 2 bits left shifted 4 (mask 0x030) + */ enum FontTitle { FONT_TITLE_BIG = 0x01 << 4, @@ -99,10 +106,11 @@ enum FontTitle }; /** - \enum FontHighlight - \brief Type of color highlight for text - - Bitmask in 3 bits left shifted 6 (mask 0x1c0) */ + * \enum FontHighlight + * \brief Type of color highlight for text + * + * Bitmask in 3 bits left shifted 6 (mask 0x1c0) + */ enum FontHighlight { FONT_HIGHLIGHT_NONE = 0x00 << 6, @@ -116,8 +124,9 @@ enum FontHighlight }; /** - \enum FontMask - \brief Masks in FontMetaChar for different attributes */ + * \enum FontMask + * \brief Masks in FontMetaChar for different attributes + */ enum FontMask { //! Mask for FontType @@ -132,10 +141,11 @@ enum FontMask /** - \struct UTF8Char - \brief UTF-8 character in font cache - - Only 3-byte chars are supported */ + * \struct UTF8Char + * \brief UTF-8 character in font cache + * + * Only 3-byte chars are supported + */ struct UTF8Char { char c1, c2, c3; @@ -165,8 +175,9 @@ struct UTF8Char }; /** - \struct CharTexture - \brief Texture of font character */ + * \struct CharTexture + * \brief Texture of font character + */ struct CharTexture { unsigned int id; @@ -180,8 +191,9 @@ struct CharTexture struct CachedFont; /** - \struct MultisizeFont - \brief Font with multiple possible sizes */ + * \struct MultisizeFont + * \brief Font with multiple possible sizes + */ struct MultisizeFont { std::string fileName; @@ -192,28 +204,28 @@ struct MultisizeFont }; /** - \class CText - \brief Text rendering engine - - CText is responsible for drawing text in 2D interface. Font rendering is done using - textures generated by SDL_ttf from TTF font files. - - All functions rendering text are divided into two types: - - single font - function takes a single Gfx::FontType argument that (along with size) - determines the font to be used for all characters, - - multi-font - function takes the text as one argument and a std::vector of FontMetaChar - with per-character formatting information (font, highlights and some other info used by CEdit) - - All font rendering is done in UTF-8. -*/ + * \class CText + * \brief Text rendering engine + * + * CText is responsible for drawing text in 2D interface. Font rendering is done using + * textures generated by SDL_ttf from TTF font files. + * + * All functions rendering text are divided into two types: + * - single font - function takes a single FontType argument that (along with size) + * determines the font to be used for all characters, + * - multi-font - function takes the text as one argument and a std::vector of FontMetaChar + * with per-character formatting information (font, highlights and some other info used by CEdit) + * + * All font rendering is done in UTF-8. + */ class CText { public: - CText(CInstanceManager *iMan, Gfx::CEngine* engine); + CText(CInstanceManager *iMan, CEngine* engine); ~CText(); //! Sets the device to be used - void SetDevice(Gfx::CDevice *device); + void SetDevice(CDevice *device); //! Returns the last encountered error std::string GetError(); @@ -227,75 +239,76 @@ public: void FlushCache(); //! Draws text (multi-format) - void DrawText(const std::string &text, const std::vector<Gfx::FontMetaChar> &format, - float size, Math::Point pos, float width, Gfx::TextAlign align, + void DrawText(const std::string &text, const std::vector<FontMetaChar> &format, + float size, Math::Point pos, float width, TextAlign align, int eol); //! Draws text (one font) - void DrawText(const std::string &text, Gfx::FontType font, - float size, Math::Point pos, float width, Gfx::TextAlign align, + void DrawText(const std::string &text, FontType font, + float size, Math::Point pos, float width, TextAlign align, int eol); //! Calculates dimensions for text (multi-format) - void SizeText(const std::string &text, const std::vector<Gfx::FontMetaChar> &format, - float size, Math::Point pos, Gfx::TextAlign align, + void SizeText(const std::string &text, const std::vector<FontMetaChar> &format, + float size, Math::Point pos, TextAlign align, Math::Point &start, Math::Point &end); //! Calculates dimensions for text (one font) - void SizeText(const std::string &text, Gfx::FontType font, - float size, Math::Point pos, Gfx::TextAlign align, + void SizeText(const std::string &text, FontType font, + float size, Math::Point pos, TextAlign align, Math::Point &start, Math::Point &end); //! Returns the ascent font metric - float GetAscent(Gfx::FontType font, float size); + float GetAscent(FontType font, float size); //! Returns the descent font metric - float GetDescent(Gfx::FontType font, float size); + float GetDescent(FontType font, float size); //! Returns the height font metric - float GetHeight(Gfx::FontType font, float size); + float GetHeight(FontType font, float size); //! Returns width of string (multi-format) float GetStringWidth(const std::string &text, - const std::vector<Gfx::FontMetaChar> &format, float size); + const std::vector<FontMetaChar> &format, float size); //! Returns width of string (single font) - float GetStringWidth(const std::string &text, Gfx::FontType font, float size); + float GetStringWidth(const std::string &text, FontType font, float size); //! Returns width of single character - float GetCharWidth(Gfx::UTF8Char ch, Gfx::FontType font, float size, float offset); + float GetCharWidth(UTF8Char ch, FontType font, float size, float offset); //! Justifies a line of text (multi-format) - int Justify(const std::string &text, const std::vector<Gfx::FontMetaChar> &format, + int Justify(const std::string &text, const std::vector<FontMetaChar> &format, float size, float width); //! Justifies a line of text (one font) - int Justify(const std::string &text, Gfx::FontType font, float size, float width); + int Justify(const std::string &text, FontType font, float size, float width); //! Returns the most suitable position to a given offset (multi-format) - int Detect(const std::string &text, const std::vector<Gfx::FontMetaChar> &format, + int Detect(const std::string &text, const std::vector<FontMetaChar> &format, float size, float offset); //! Returns the most suitable position to a given offset (one font) - int Detect(const std::string &text, Gfx::FontType font, float size, float offset); + int Detect(const std::string &text, FontType font, float size, float offset); protected: - Gfx::CachedFont* GetOrOpenFont(Gfx::FontType type, float size); - Gfx::CharTexture CreateCharTexture(Gfx::UTF8Char ch, Gfx::CachedFont* font); + CachedFont* GetOrOpenFont(FontType type, float size); + CharTexture CreateCharTexture(UTF8Char ch, CachedFont* font); - void DrawString(const std::string &text, const std::vector<Gfx::FontMetaChar> &format, + void DrawString(const std::string &text, const std::vector<FontMetaChar> &format, float size, Math::Point pos, float width, int eol); - void DrawString(const std::string &text, Gfx::FontType font, + void DrawString(const std::string &text, FontType font, float size, Math::Point pos, float width, int eol); - void DrawHighlight(Gfx::FontHighlight hl, Math::Point pos, Math::Point size); - void DrawChar(Gfx::UTF8Char ch, Gfx::FontType font, float size, Math::Point &pos); + void DrawHighlight(FontHighlight hl, Math::Point pos, Math::Point size); + void DrawChar(UTF8Char ch, FontType font, float size, Math::Point &pos); protected: CInstanceManager* m_iMan; - Gfx::CEngine* m_engine; - Gfx::CDevice* m_device; + CEngine* m_engine; + CDevice* m_device; std::string m_error; float m_defaultSize; std::string m_fontPath; - std::map<Gfx::FontType, Gfx::MultisizeFont*> m_fonts; + std::map<FontType, MultisizeFont*> m_fonts; - Gfx::FontType m_lastFontType; + FontType m_lastFontType; int m_lastFontSize; - Gfx::CachedFont* m_lastCachedFont; + CachedFont* m_lastCachedFont; }; -}; // namespace Gfx + +} // namespace Gfx diff --git a/src/graphics/engine/water.cpp b/src/graphics/engine/water.cpp index a2ff081..81034a3 100644 --- a/src/graphics/engine/water.cpp +++ b/src/graphics/engine/water.cpp @@ -15,27 +15,34 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// water.cpp #include "graphics/engine/water.h" #include "common/iman.h" #include "common/logger.h" + #include "graphics/core/device.h" #include "graphics/engine/engine.h" #include "graphics/engine/terrain.h" + #include "math/geometry.h" + #include "object/object.h" + #include "sound/sound.h" +// Graphics module namespace +namespace Gfx { + + const int WATERLINE_PREALLOCATE_COUNT = 500; // TODO: remove the limit? const int VAPOR_SIZE = 10; -Gfx::CWater::CWater(CInstanceManager* iMan, Gfx::CEngine* engine) +CWater::CWater(CInstanceManager* iMan, CEngine* engine) { m_iMan = iMan; m_iMan->AddInstance(CLASS_WATER, this); @@ -50,15 +57,15 @@ Gfx::CWater::CWater(CInstanceManager* iMan, Gfx::CEngine* engine) m_level = 0.0f; m_draw = true; m_lava = false; - m_color = Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f); + m_color = Color(1.0f, 1.0f, 1.0f, 1.0f); m_subdiv = 4; m_lines.reserve(WATERLINE_PREALLOCATE_COUNT); - std::vector<Gfx::WaterVapor>(VAPOR_SIZE).swap(m_vapors); + std::vector<WaterVapor>(VAPOR_SIZE).swap(m_vapors); } -Gfx::CWater::~CWater() +CWater::~CWater() { m_iMan = nullptr; m_engine = nullptr; @@ -68,7 +75,7 @@ Gfx::CWater::~CWater() } -bool Gfx::CWater::EventProcess(const Event &event) +bool CWater::EventProcess(const Event &event) { if (event.type == EVENT_FRAME) return EventFrame(event); @@ -76,7 +83,7 @@ bool Gfx::CWater::EventProcess(const Event &event) return true; } -bool Gfx::CWater::EventFrame(const Event &event) +bool CWater::EventFrame(const Event &event) { if (m_engine->GetPause()) return true; @@ -90,10 +97,10 @@ bool Gfx::CWater::EventFrame(const Event &event) return true; } -void Gfx::CWater::LavaFrame(float rTime) +void CWater::LavaFrame(float rTime) { if (m_particule == nullptr) - m_particule = static_cast<Gfx::CParticle*>( m_iMan->SearchInstance(CLASS_PARTICULE) ); + m_particule = static_cast<CParticle*>( m_iMan->SearchInstance(CLASS_PARTICULE) ); for (int i = 0; i < static_cast<int>( m_vapors.size() ); i++) VaporFrame(i, rTime); @@ -123,29 +130,29 @@ void Gfx::CWater::LavaFrame(float rTime) level = Math::Rand(); if (level < 0.8f) { - if ( VaporCreate(Gfx::PARTIFIRE, pos, 0.02f+Math::Rand()*0.06f) ) + if ( VaporCreate(PARTIFIRE, pos, 0.02f+Math::Rand()*0.06f) ) m_lastLava = m_time; } else if (level < 0.9f) { - if ( VaporCreate(Gfx::PARTIFLAME, pos, 0.5f+Math::Rand()*3.0f) ) + if ( VaporCreate(PARTIFLAME, pos, 0.5f+Math::Rand()*3.0f) ) m_lastLava = m_time; } else { - if ( VaporCreate(Gfx::PARTIVAPOR, pos, 0.2f+Math::Rand()*2.0f) ) + if ( VaporCreate(PARTIVAPOR, pos, 0.2f+Math::Rand()*2.0f) ) m_lastLava = m_time; } } } } -void Gfx::CWater::VaporFlush() +void CWater::VaporFlush() { m_vapors.clear(); } -bool Gfx::CWater::VaporCreate(Gfx::ParticleType type, Math::Vector pos, float delay) +bool CWater::VaporCreate(ParticleType type, Math::Vector pos, float delay) { for (int i = 0; i < static_cast<int>( m_vapors.size() ); i++) { @@ -171,7 +178,7 @@ bool Gfx::CWater::VaporCreate(Gfx::ParticleType type, Math::Vector pos, float de return false; } -void Gfx::CWater::VaporFrame(int i, float rTime) +void CWater::VaporFrame(int i, float rTime) { m_vapors[i].time += rTime; @@ -240,7 +247,7 @@ void Gfx::CWater::VaporFrame(int i, float rTime) } } -void Gfx::CWater::AdjustLevel(Math::Vector &pos, Math::Vector &norm, +void CWater::AdjustLevel(Math::Vector &pos, Math::Vector &norm, Math::Point &uv1, Math::Point &uv2) { float t1 = m_time*1.5f + pos.x*0.1f * pos.z*0.2f; @@ -258,7 +265,7 @@ void Gfx::CWater::AdjustLevel(Math::Vector &pos, Math::Vector &norm, } /** This surface prevents to see the sky (background) underwater! */ -void Gfx::CWater::DrawBack() +void CWater::DrawBack() { if (! m_draw) return; if (m_type[0] == WATER_NULL) return; @@ -267,16 +274,16 @@ void Gfx::CWater::DrawBack() Math::Vector eye = m_engine->GetEyePt(); Math::Vector lookat = m_engine->GetLookatPt(); - Gfx::Material material; + Material material; material.diffuse = m_diffuse; material.ambient = m_ambient; m_engine->SetMaterial(material); m_engine->SetTexture("", 0); // TODO: disable texturing - Gfx::CDevice* device = m_engine->GetDevice(); + CDevice* device = m_engine->GetDevice(); - m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); + m_engine->SetState(ENG_RSTATE_NORMAL); float deep = m_engine->GetDeepView(0); m_engine->SetDeepView(deep*2.0f, 0); @@ -285,7 +292,7 @@ void Gfx::CWater::DrawBack() Math::Matrix matrix; matrix.LoadIdentity(); - device->SetTransform(Gfx::TRANSFORM_WORLD, matrix); + device->SetTransform(TRANSFORM_WORLD, matrix); Math::Vector p; p.x = eye.x; @@ -308,15 +315,15 @@ void Gfx::CWater::DrawBack() n.z = (lookat.z-eye.z)/dist; n.y = 0.0f; - Gfx::Vertex vertices[4] = + Vertex vertices[4] = { - Gfx::Vertex(Math::Vector(p1.x, p2.y, p1.z), n), - Gfx::Vertex(Math::Vector(p1.x, p1.y, p1.z), n), - Gfx::Vertex(Math::Vector(p2.x, p2.y, p2.z), n), - Gfx::Vertex(Math::Vector(p2.x, p1.y, p2.z), n) + Vertex(Math::Vector(p1.x, p2.y, p1.z), n), + Vertex(Math::Vector(p1.x, p1.y, p1.z), n), + Vertex(Math::Vector(p2.x, p2.y, p2.z), n), + Vertex(Math::Vector(p2.x, p1.y, p2.z), n) }; - device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertices, 4); + device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, vertices, 4); m_engine->AddStatisticTriangle(2); m_engine->SetDeepView(deep, 0); @@ -324,26 +331,26 @@ void Gfx::CWater::DrawBack() m_engine->UpdateMatProj(); // gives the initial depth of view } -void Gfx::CWater::DrawSurf() +void CWater::DrawSurf() { if (! m_draw) return; - if (m_type[0] == Gfx::WATER_NULL) return; + if (m_type[0] == WATER_NULL) return; if (m_lines.empty()) return; - std::vector<Gfx::VertexTex2> vertices((m_brickCount+2)*2, Gfx::VertexTex2()); + std::vector<VertexTex2> vertices((m_brickCount+2)*2, VertexTex2()); Math::Vector eye = m_engine->GetEyePt(); int rankview = m_engine->GetRankView(); bool under = ( rankview == 1); - Gfx::CDevice* device = m_engine->GetDevice(); + CDevice* device = m_engine->GetDevice(); Math::Matrix matrix; matrix.LoadIdentity(); - device->SetTransform(Gfx::TRANSFORM_WORLD, matrix); + device->SetTransform(TRANSFORM_WORLD, matrix); - Gfx::Material material; + Material material; material.diffuse = m_diffuse; material.ambient = m_ambient; m_engine->SetMaterial(material); @@ -352,18 +359,18 @@ void Gfx::CWater::DrawSurf() m_engine->SetTexture(m_fileName, 1); if (m_type[rankview] == WATER_TT) - m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK | Gfx::ENG_RSTATE_DUAL_WHITE | Gfx::ENG_RSTATE_WRAP, m_color); + m_engine->SetState(ENG_RSTATE_TTEXTURE_BLACK | ENG_RSTATE_DUAL_WHITE | ENG_RSTATE_WRAP, m_color); else if (m_type[rankview] == WATER_TO) - m_engine->SetState(Gfx::ENG_RSTATE_NORMAL | Gfx::ENG_RSTATE_DUAL_WHITE | Gfx::ENG_RSTATE_WRAP); + m_engine->SetState(ENG_RSTATE_NORMAL | ENG_RSTATE_DUAL_WHITE | ENG_RSTATE_WRAP); else if (m_type[rankview] == WATER_CT) - m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_BLACK); + m_engine->SetState(ENG_RSTATE_TTEXTURE_BLACK); else if (m_type[rankview] == WATER_CO) - m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); + m_engine->SetState(ENG_RSTATE_NORMAL); - device->SetRenderState(Gfx::RENDER_STATE_FOG, true); + device->SetRenderState(RENDER_STATE_FOG, true); float size = m_brickSize/2.0f; float sizez = 0.0f; @@ -398,14 +405,14 @@ void Gfx::CWater::DrawSurf() p.y = pos.y; AdjustLevel(p, n, uv1, uv2); if (under) n.y = -n.y; - vertices[vertexIndex++] = Gfx::VertexTex2(p, n, uv1, uv2); + vertices[vertexIndex++] = VertexTex2(p, n, uv1, uv2); p.x = pos.x-size; p.z = pos.z+sizez; p.y = pos.y; AdjustLevel(p, n, uv1, uv2); if (under) n.y = -n.y; - vertices[vertexIndex++] = Gfx::VertexTex2(p, n, uv1, uv2); + vertices[vertexIndex++] = VertexTex2(p, n, uv1, uv2); for (int j = 0; j < m_lines[i].len; j++) { @@ -414,24 +421,24 @@ void Gfx::CWater::DrawSurf() p.y = pos.y; AdjustLevel(p, n, uv1, uv2); if (under) n.y = -n.y; - vertices[vertexIndex++] = Gfx::VertexTex2(p, n, uv1, uv2); + vertices[vertexIndex++] = VertexTex2(p, n, uv1, uv2); p.x = pos.x+size; p.z = pos.z+sizez; p.y = pos.y; AdjustLevel(p, n, uv1, uv2); if (under) n.y = -n.y; - vertices[vertexIndex++] = Gfx::VertexTex2(p, n, uv1, uv2); + vertices[vertexIndex++] = VertexTex2(p, n, uv1, uv2); pos.x += size*2.0f; } - device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, &vertices[0], vertexIndex); + device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, &vertices[0], vertexIndex); m_engine->AddStatisticTriangle(vertexIndex - 2); } } -bool Gfx::CWater::GetWater(int x, int y) +bool CWater::GetWater(int x, int y) { x *= m_subdiv; y *= m_subdiv; @@ -455,9 +462,9 @@ bool Gfx::CWater::GetWater(int x, int y) return false; } -void Gfx::CWater::CreateLine(int x, int y, int len) +void CWater::CreateLine(int x, int y, int len) { - Gfx::WaterLine line; + WaterLine line; line.x = x; line.y = y; @@ -472,8 +479,8 @@ void Gfx::CWater::CreateLine(int x, int y, int len) m_lines.push_back(line); } -void Gfx::CWater::Create(Gfx::WaterType type1, Gfx::WaterType type2, const std::string& fileName, - Gfx::Color diffuse, Gfx::Color ambient, +void CWater::Create(WaterType type1, WaterType type2, const std::string& fileName, + Color diffuse, Color ambient, float level, float glint, Math::Vector eddy) { m_type[0] = type1; @@ -534,15 +541,15 @@ void Gfx::CWater::Create(Gfx::WaterType type1, Gfx::WaterType type2, const std:: } } -void Gfx::CWater::Flush() +void CWater::Flush() { - m_type[0] = Gfx::WATER_NULL; - m_type[1] = Gfx::WATER_NULL; + m_type[0] = WATER_NULL; + m_type[1] = WATER_NULL; m_level = 0.0f; m_lava = false; } -void Gfx::CWater::SetLevel(float level) +void CWater::SetLevel(float level) { m_level = level; @@ -550,12 +557,12 @@ void Gfx::CWater::SetLevel(float level) m_level, m_glint, m_eddy); } -float Gfx::CWater::GetLevel() +float CWater::GetLevel() { return m_level; } -float Gfx::CWater::GetLevel(CObject* object) +float CWater::GetLevel(CObject* object) { ObjectType type = object->GetType(); @@ -599,17 +606,17 @@ float Gfx::CWater::GetLevel(CObject* object) return m_level; } -void Gfx::CWater::SetLava(bool lava) +void CWater::SetLava(bool lava) { m_lava = lava; } -bool Gfx::CWater::GetLava() +bool CWater::GetLava() { return m_lava; } -void Gfx::CWater::AdjustEye(Math::Vector &eye) +void CWater::AdjustEye(Math::Vector &eye) { if (m_lava) { @@ -624,3 +631,5 @@ void Gfx::CWater::AdjustEye(Math::Vector &eye) } } + +} // namespace Gfx diff --git a/src/graphics/engine/water.h b/src/graphics/engine/water.h index 9b31045..a43c740 100644 --- a/src/graphics/engine/water.h +++ b/src/graphics/engine/water.h @@ -17,12 +17,14 @@ /** * \file graphics/engine/water.h - * \brief Water rendering - Gfx::CWater class + * \brief Water rendering - CWater class */ #pragma once + #include "common/event.h" + #include "graphics/engine/particle.h" @@ -30,8 +32,10 @@ class CInstanceManager; class CSoundInterface; +// Graphics module namespace namespace Gfx { + class CEngine; class CTerrain; @@ -65,7 +69,7 @@ struct WaterLine struct WaterVapor { bool used; - Gfx::ParticleType type; + ParticleType type; Math::Vector pos; float delay; float time; @@ -74,7 +78,7 @@ struct WaterVapor WaterVapor() { used = false; - type = Gfx::PARTIWATER; + type = PARTIWATER; delay = time = last = 0.0f; } }; @@ -113,16 +117,16 @@ enum WaterType class CWater { public: - CWater(CInstanceManager* iMan, Gfx::CEngine* engine); + CWater(CInstanceManager* iMan, CEngine* engine); ~CWater(); - void SetDevice(Gfx::CDevice* device); + void SetDevice(CDevice* device); bool EventProcess(const Event &event); //! Removes all the water void Flush(); //! Creates all expanses of water void Create(WaterType type1, WaterType type2, const std::string& fileName, - Gfx::Color diffuse, Gfx::Color ambient, float level, float glint, Math::Vector eddy); + Color diffuse, Color ambient, float level, float glint, Math::Vector eddy); //! Draw the back surface of the water void DrawBack(); //! Draws the flat surface of the water @@ -165,10 +169,10 @@ protected: protected: CInstanceManager* m_iMan; - Gfx::CEngine* m_engine; - Gfx::CDevice* m_device; - Gfx::CTerrain* m_terrain; - Gfx::CParticle* m_particule; + CEngine* m_engine; + CDevice* m_device; + CTerrain* m_terrain; + CParticle* m_particule; CSoundInterface* m_sound; WaterType m_type[2]; @@ -180,9 +184,9 @@ protected: //! Amplitude of swirls Math::Vector m_eddy; //! Diffuse color - Gfx::Color m_diffuse; + Color m_diffuse; //! Ambient color - Gfx::Color m_ambient; + Color m_ambient; float m_time; float m_lastLava; int m_subdiv; @@ -197,7 +201,8 @@ protected: bool m_draw; bool m_lava; - Gfx::Color m_color; + Color m_color; }; -}; // namespace Gfx + +} // namespace Gfx diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index 416b506..360a058 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -14,13 +14,13 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// gldevice.cpp #include "graphics/opengl/gldevice.h" #include "common/config.h" #include "common/image.h" #include "common/logger.h" + #include "math/geometry.h" @@ -45,10 +45,13 @@ #include <cassert> +// Graphics module namespace +namespace Gfx { + -void Gfx::GLDeviceConfig::LoadDefault() +void GLDeviceConfig::LoadDefault() { - Gfx::DeviceConfig::LoadDefault(); + DeviceConfig::LoadDefault(); hardwareAccel = true; @@ -62,7 +65,7 @@ void Gfx::GLDeviceConfig::LoadDefault() -Gfx::CGLDevice::CGLDevice(const Gfx::GLDeviceConfig &config) +CGLDevice::CGLDevice(const GLDeviceConfig &config) { m_config = config; m_lighting = false; @@ -70,18 +73,18 @@ Gfx::CGLDevice::CGLDevice(const Gfx::GLDeviceConfig &config) } -Gfx::CGLDevice::~CGLDevice() +CGLDevice::~CGLDevice() { } -void Gfx::CGLDevice::DebugHook() +void CGLDevice::DebugHook() { /* This function is only called here, so it can be used * as a breakpoint when debugging using gDEBugger */ glColor3i(0, 0, 0); } -bool Gfx::CGLDevice::Create() +bool CGLDevice::Create() { GetLogger()->Info("Creating CDevice\n"); @@ -132,22 +135,22 @@ bool Gfx::CGLDevice::Create() int numLights = 0; glGetIntegerv(GL_MAX_LIGHTS, &numLights); - m_lights = std::vector<Gfx::Light>(numLights, Gfx::Light()); + m_lights = std::vector<Light>(numLights, Light()); m_lightsEnabled = std::vector<bool> (numLights, false); int maxTextures = 0; glGetIntegerv(GL_MAX_TEXTURE_UNITS, &maxTextures); - m_currentTextures = std::vector<Gfx::Texture> (maxTextures, Gfx::Texture()); + m_currentTextures = std::vector<Texture> (maxTextures, Texture()); m_texturesEnabled = std::vector<bool> (maxTextures, false); - m_textureStageParams = std::vector<Gfx::TextureStageParams>(maxTextures, Gfx::TextureStageParams()); + m_textureStageParams = std::vector<TextureStageParams>(maxTextures, TextureStageParams()); GetLogger()->Info("CDevice created successfully\n"); return true; } -void Gfx::CGLDevice::Destroy() +void CGLDevice::Destroy() { // Delete the remaining textures // Should not be strictly necessary, but just in case @@ -161,7 +164,7 @@ void Gfx::CGLDevice::Destroy() m_textureStageParams.clear(); } -void Gfx::CGLDevice::ConfigChanged(const Gfx::GLDeviceConfig& newConfig) +void CGLDevice::ConfigChanged(const GLDeviceConfig& newConfig) { m_config = newConfig; @@ -172,7 +175,7 @@ void Gfx::CGLDevice::ConfigChanged(const Gfx::GLDeviceConfig& newConfig) Create(); } -void Gfx::CGLDevice::BeginScene() +void CGLDevice::BeginScene() { Clear(); @@ -182,29 +185,29 @@ void Gfx::CGLDevice::BeginScene() UpdateModelviewMatrix(); } -void Gfx::CGLDevice::EndScene() +void CGLDevice::EndScene() { } -void Gfx::CGLDevice::Clear() +void CGLDevice::Clear() { glDepthMask(GL_TRUE); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } -void Gfx::CGLDevice::SetTransform(Gfx::TransformType type, const Math::Matrix &matrix) +void CGLDevice::SetTransform(TransformType type, const Math::Matrix &matrix) { - if (type == Gfx::TRANSFORM_WORLD) + if (type == TRANSFORM_WORLD) { m_worldMat = matrix; UpdateModelviewMatrix(); } - else if (type == Gfx::TRANSFORM_VIEW) + else if (type == TRANSFORM_VIEW) { m_viewMat = matrix; UpdateModelviewMatrix(); } - else if (type == Gfx::TRANSFORM_PROJECTION) + else if (type == TRANSFORM_PROJECTION) { m_projectionMat = matrix; glMatrixMode(GL_PROJECTION); @@ -216,13 +219,13 @@ void Gfx::CGLDevice::SetTransform(Gfx::TransformType type, const Math::Matrix &m } } -const Math::Matrix& Gfx::CGLDevice::GetTransform(Gfx::TransformType type) +const Math::Matrix& CGLDevice::GetTransform(TransformType type) { - if (type == Gfx::TRANSFORM_WORLD) + if (type == TRANSFORM_WORLD) return m_worldMat; - else if (type == Gfx::TRANSFORM_VIEW) + else if (type == TRANSFORM_VIEW) return m_viewMat; - else if (type == Gfx::TRANSFORM_PROJECTION) + else if (type == TRANSFORM_PROJECTION) return m_projectionMat; else assert(false); @@ -230,19 +233,19 @@ const Math::Matrix& Gfx::CGLDevice::GetTransform(Gfx::TransformType type) return m_worldMat; // to avoid warning } -void Gfx::CGLDevice::MultiplyTransform(Gfx::TransformType type, const Math::Matrix &matrix) +void CGLDevice::MultiplyTransform(TransformType type, const Math::Matrix &matrix) { - if (type == Gfx::TRANSFORM_WORLD) + if (type == TRANSFORM_WORLD) { m_worldMat = Math::MultiplyMatrices(m_worldMat, matrix); UpdateModelviewMatrix(); } - else if (type == Gfx::TRANSFORM_VIEW) + else if (type == TRANSFORM_VIEW) { m_viewMat = Math::MultiplyMatrices(m_viewMat, matrix); UpdateModelviewMatrix(); } - else if (type == Gfx::TRANSFORM_PROJECTION) + else if (type == TRANSFORM_PROJECTION) { m_projectionMat = Math::MultiplyMatrices(m_projectionMat, matrix); glMatrixMode(GL_PROJECTION); @@ -254,7 +257,7 @@ void Gfx::CGLDevice::MultiplyTransform(Gfx::TransformType type, const Math::Matr } } -void Gfx::CGLDevice::UpdateModelviewMatrix() +void CGLDevice::UpdateModelviewMatrix() { m_modelviewMat = Math::MultiplyMatrices(m_viewMat, m_worldMat); @@ -270,7 +273,7 @@ void Gfx::CGLDevice::UpdateModelviewMatrix() } } -void Gfx::CGLDevice::SetMaterial(const Gfx::Material &material) +void CGLDevice::SetMaterial(const Material &material) { m_material = material; @@ -279,17 +282,17 @@ void Gfx::CGLDevice::SetMaterial(const Gfx::Material &material) glMaterialfv(GL_FRONT, GL_SPECULAR, m_material.specular.Array()); } -const Gfx::Material& Gfx::CGLDevice::GetMaterial() +const Material& CGLDevice::GetMaterial() { return m_material; } -int Gfx::CGLDevice::GetMaxLightCount() +int CGLDevice::GetMaxLightCount() { return m_lights.size(); } -void Gfx::CGLDevice::SetLight(int index, const Gfx::Light &light) +void CGLDevice::SetLight(int index, const Light &light) { assert(index >= 0); assert(index < static_cast<int>( m_lights.size() )); @@ -305,7 +308,7 @@ void Gfx::CGLDevice::SetLight(int index, const Gfx::Light &light) glLightf(GL_LIGHT0 + index, GL_LINEAR_ATTENUATION, light.attenuation1); glLightf(GL_LIGHT0 + index, GL_QUADRATIC_ATTENUATION, light.attenuation2); - if (light.type == Gfx::LIGHT_SPOT) + if (light.type == LIGHT_SPOT) { glLightf(GL_LIGHT0 + index, GL_SPOT_CUTOFF, light.spotAngle); glLightf(GL_LIGHT0 + index, GL_SPOT_EXPONENT, light.spotIntensity); @@ -318,7 +321,7 @@ void Gfx::CGLDevice::SetLight(int index, const Gfx::Light &light) UpdateLightPosition(index); } -void Gfx::CGLDevice::UpdateLightPosition(int index) +void CGLDevice::UpdateLightPosition(int index) { assert(index >= 0); assert(index < static_cast<int>( m_lights.size() )); @@ -344,7 +347,7 @@ void Gfx::CGLDevice::UpdateLightPosition(int index) glLightfv(GL_LIGHT0 + index, GL_POSITION, position); } - if (m_lights[index].type == Gfx::LIGHT_SPOT) + if (m_lights[index].type == LIGHT_SPOT) { GLfloat direction[4] = { m_lights[index].direction.x, m_lights[index].direction.y, m_lights[index].direction.z, 0.0f }; glLightfv(GL_LIGHT0 + index, GL_SPOT_DIRECTION, direction); @@ -353,7 +356,7 @@ void Gfx::CGLDevice::UpdateLightPosition(int index) glPopMatrix(); } -const Gfx::Light& Gfx::CGLDevice::GetLight(int index) +const Light& CGLDevice::GetLight(int index) { assert(index >= 0); assert(index < static_cast<int>( m_lights.size() )); @@ -361,7 +364,7 @@ const Gfx::Light& Gfx::CGLDevice::GetLight(int index) return m_lights[index]; } -void Gfx::CGLDevice::SetLightEnabled(int index, bool enabled) +void CGLDevice::SetLightEnabled(int index, bool enabled) { assert(index >= 0); assert(index < static_cast<int>( m_lights.size() )); @@ -371,7 +374,7 @@ void Gfx::CGLDevice::SetLightEnabled(int index, bool enabled) glEnable(GL_LIGHT0 + index); } -bool Gfx::CGLDevice::GetLightEnabled(int index) +bool CGLDevice::GetLightEnabled(int index) { assert(index >= 0); assert(index < static_cast<int>( m_lights.size() )); @@ -380,23 +383,23 @@ bool Gfx::CGLDevice::GetLightEnabled(int index) } /** If image is invalid, returns invalid texture. - Otherwise, returns pointer to new Gfx::Texture struct. + Otherwise, returns pointer to new Texture struct. This struct must not be deleted in other way than through DeleteTexture() */ -Gfx::Texture Gfx::CGLDevice::CreateTexture(CImage *image, const Gfx::TextureCreateParams ¶ms) +Texture CGLDevice::CreateTexture(CImage *image, const TextureCreateParams ¶ms) { ImageData *data = image->GetData(); if (data == NULL) { GetLogger()->Error("Invalid texture data\n"); - return Gfx::Texture(); // invalid texture + return Texture(); // invalid texture } return CreateTexture(data, params); } -Gfx::Texture Gfx::CGLDevice::CreateTexture(ImageData *data, const Gfx::TextureCreateParams ¶ms) +Texture CGLDevice::CreateTexture(ImageData *data, const TextureCreateParams ¶ms) { - Gfx::Texture result; + Texture result; result.size.x = data->surface->w; result.size.y = data->surface->h; @@ -413,19 +416,19 @@ Gfx::Texture Gfx::CGLDevice::CreateTexture(ImageData *data, const Gfx::TextureCr // Set params GLint minF = 0; - if (params.minFilter == Gfx::TEX_MIN_FILTER_NEAREST) minF = GL_NEAREST; - else if (params.minFilter == Gfx::TEX_MIN_FILTER_LINEAR) minF = GL_LINEAR; - else if (params.minFilter == Gfx::TEX_MIN_FILTER_NEAREST_MIPMAP_NEAREST) minF = GL_NEAREST_MIPMAP_NEAREST; - else if (params.minFilter == Gfx::TEX_MIN_FILTER_LINEAR_MIPMAP_NEAREST) minF = GL_LINEAR_MIPMAP_NEAREST; - else if (params.minFilter == Gfx::TEX_MIN_FILTER_NEAREST_MIPMAP_LINEAR) minF = GL_NEAREST_MIPMAP_LINEAR; - else if (params.minFilter == Gfx::TEX_MIN_FILTER_LINEAR_MIPMAP_LINEAR) minF = GL_LINEAR_MIPMAP_LINEAR; + if (params.minFilter == TEX_MIN_FILTER_NEAREST) minF = GL_NEAREST; + else if (params.minFilter == TEX_MIN_FILTER_LINEAR) minF = GL_LINEAR; + else if (params.minFilter == TEX_MIN_FILTER_NEAREST_MIPMAP_NEAREST) minF = GL_NEAREST_MIPMAP_NEAREST; + else if (params.minFilter == TEX_MIN_FILTER_LINEAR_MIPMAP_NEAREST) minF = GL_LINEAR_MIPMAP_NEAREST; + else if (params.minFilter == TEX_MIN_FILTER_NEAREST_MIPMAP_LINEAR) minF = GL_NEAREST_MIPMAP_LINEAR; + else if (params.minFilter == TEX_MIN_FILTER_LINEAR_MIPMAP_LINEAR) minF = GL_LINEAR_MIPMAP_LINEAR; else assert(false); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minF); GLint magF = 0; - if (params.magFilter == Gfx::TEX_MAG_FILTER_NEAREST) magF = GL_NEAREST; - else if (params.magFilter == Gfx::TEX_MAG_FILTER_LINEAR) magF = GL_LINEAR; + if (params.magFilter == TEX_MAG_FILTER_NEAREST) magF = GL_NEAREST; + else if (params.magFilter == TEX_MAG_FILTER_LINEAR) magF = GL_LINEAR; else assert(false); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magF); @@ -439,27 +442,27 @@ Gfx::Texture Gfx::CGLDevice::CreateTexture(ImageData *data, const Gfx::TextureCr bool convert = false; GLenum sourceFormat = 0; - if (params.format == Gfx::TEX_IMG_RGB) + if (params.format == TEX_IMG_RGB) { sourceFormat = GL_RGB; result.alpha = false; } - else if (params.format == Gfx::TEX_IMG_BGR) + else if (params.format == TEX_IMG_BGR) { sourceFormat = GL_BGR; result.alpha = false; } - else if (params.format == Gfx::TEX_IMG_RGBA) + else if (params.format == TEX_IMG_RGBA) { sourceFormat = GL_RGBA; result.alpha = true; } - else if (params.format == Gfx::TEX_IMG_BGRA) + else if (params.format == TEX_IMG_BGRA) { sourceFormat = GL_BGRA; result.alpha = true; } - else if (params.format == Gfx::TEX_IMG_AUTO) + else if (params.format == TEX_IMG_AUTO) { if (data->surface->format->Amask != 0) { @@ -554,9 +557,9 @@ Gfx::Texture Gfx::CGLDevice::CreateTexture(ImageData *data, const Gfx::TextureCr return result; } -void Gfx::CGLDevice::DestroyTexture(const Gfx::Texture &texture) +void CGLDevice::DestroyTexture(const Texture &texture) { - std::set<Gfx::Texture>::iterator it = m_allTextures.find(texture); + std::set<Texture>::iterator it = m_allTextures.find(texture); if (it != m_allTextures.end()) m_allTextures.erase(it); @@ -564,21 +567,21 @@ void Gfx::CGLDevice::DestroyTexture(const Gfx::Texture &texture) for (int index = 0; index < static_cast<int>( m_currentTextures.size() ); ++index) { if (m_currentTextures[index] == texture) - SetTexture(index, Gfx::Texture()); // set to invalid texture + SetTexture(index, Texture()); // set to invalid texture } glDeleteTextures(1, &texture.id); } -void Gfx::CGLDevice::DestroyAllTextures() +void CGLDevice::DestroyAllTextures() { - std::set<Gfx::Texture> allCopy = m_allTextures; - std::set<Gfx::Texture>::iterator it; + std::set<Texture> allCopy = m_allTextures; + std::set<Texture>::iterator it; for (it = allCopy.begin(); it != allCopy.end(); ++it) DestroyTexture(*it); } -int Gfx::CGLDevice::GetMaxTextureCount() +int CGLDevice::GetMaxTextureCount() { return m_currentTextures.size(); } @@ -587,7 +590,7 @@ int Gfx::CGLDevice::GetMaxTextureCount() If \a texture is invalid, unbinds the given texture. If valid, binds the texture and enables the given texture stage. The setting is remembered, even if texturing is disabled at the moment. */ -void Gfx::CGLDevice::SetTexture(int index, const Gfx::Texture &texture) +void CGLDevice::SetTexture(int index, const Texture &texture) { assert(index >= 0); assert(index < static_cast<int>( m_currentTextures.size() )); @@ -613,7 +616,7 @@ void Gfx::CGLDevice::SetTexture(int index, const Gfx::Texture &texture) glDisable(GL_TEXTURE_2D); } -void Gfx::CGLDevice::SetTexture(int index, unsigned int textureId) +void CGLDevice::SetTexture(int index, unsigned int textureId) { assert(index >= 0); assert(index < static_cast<int>( m_currentTextures.size() )); @@ -633,7 +636,7 @@ void Gfx::CGLDevice::SetTexture(int index, unsigned int textureId) /** Returns the previously assigned texture or invalid texture if the given stage is not enabled. */ -Gfx::Texture Gfx::CGLDevice::GetTexture(int index) +Texture CGLDevice::GetTexture(int index) { assert(index >= 0); assert(index < static_cast<int>( m_currentTextures.size() )); @@ -641,7 +644,7 @@ Gfx::Texture Gfx::CGLDevice::GetTexture(int index) return m_currentTextures[index]; } -void Gfx::CGLDevice::SetTextureEnabled(int index, bool enabled) +void CGLDevice::SetTextureEnabled(int index, bool enabled) { assert(index >= 0); assert(index < static_cast<int>( m_currentTextures.size() )); @@ -655,7 +658,7 @@ void Gfx::CGLDevice::SetTextureEnabled(int index, bool enabled) glDisable(GL_TEXTURE_2D); } -bool Gfx::CGLDevice::GetTextureEnabled(int index) +bool CGLDevice::GetTextureEnabled(int index) { assert(index >= 0); assert(index < static_cast<int>( m_currentTextures.size() )); @@ -667,7 +670,7 @@ bool Gfx::CGLDevice::GetTextureEnabled(int index) Sets the texture parameters for the given texture stage. If the given texture was not set (bound) yet, nothing happens. The settings are remembered, even if texturing is disabled at the moment. */ -void Gfx::CGLDevice::SetTextureStageParams(int index, const Gfx::TextureStageParams ¶ms) +void CGLDevice::SetTextureStageParams(int index, const TextureStageParams ¶ms) { assert(index >= 0); assert(index < static_cast<int>( m_currentTextures.size() )); @@ -686,8 +689,8 @@ void Gfx::CGLDevice::SetTextureStageParams(int index, const Gfx::TextureStagePar glBindTexture(GL_TEXTURE_2D, m_currentTextures[index].id); // To save some trouble - if ( (params.colorOperation == Gfx::TEX_MIX_OPER_DEFAULT) && - (params.alphaOperation == Gfx::TEX_MIX_OPER_DEFAULT) ) + if ( (params.colorOperation == TEX_MIX_OPER_DEFAULT) && + (params.alphaOperation == TEX_MIX_OPER_DEFAULT) ) { glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); goto after_tex_operations; @@ -703,42 +706,42 @@ void Gfx::CGLDevice::SetTextureStageParams(int index, const Gfx::TextureStagePar // Color operation - if (params.colorOperation == Gfx::TEX_MIX_OPER_DEFAULT) + if (params.colorOperation == TEX_MIX_OPER_DEFAULT) { glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE); goto after_tex_color; } - else if (params.colorOperation == Gfx::TEX_MIX_OPER_REPLACE) + else if (params.colorOperation == TEX_MIX_OPER_REPLACE) glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE); - else if (params.colorOperation == Gfx::TEX_MIX_OPER_MODULATE) + else if (params.colorOperation == TEX_MIX_OPER_MODULATE) glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE); - else if (params.colorOperation == Gfx::TEX_MIX_OPER_ADD) + else if (params.colorOperation == TEX_MIX_OPER_ADD) glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD); - else if (params.colorOperation == Gfx::TEX_MIX_OPER_SUBTRACT) + else if (params.colorOperation == TEX_MIX_OPER_SUBTRACT) glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_SUBTRACT); else assert(false); // Color arg1 - if (params.colorArg1 == Gfx::TEX_MIX_ARG_TEXTURE) + if (params.colorArg1 == TEX_MIX_ARG_TEXTURE) glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE); - else if (params.colorArg1 == Gfx::TEX_MIX_ARG_COMPUTED_COLOR) + else if (params.colorArg1 == TEX_MIX_ARG_COMPUTED_COLOR) glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS); - else if (params.colorArg1 == Gfx::TEX_MIX_ARG_SRC_COLOR) + else if (params.colorArg1 == TEX_MIX_ARG_SRC_COLOR) glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PRIMARY_COLOR); - else if (params.colorArg1 == Gfx::TEX_MIX_ARG_FACTOR) + else if (params.colorArg1 == TEX_MIX_ARG_FACTOR) glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_CONSTANT); else assert(false); // Color arg2 - if (params.colorArg2 == Gfx::TEX_MIX_ARG_TEXTURE) + if (params.colorArg2 == TEX_MIX_ARG_TEXTURE) glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE); - else if (params.colorArg2 == Gfx::TEX_MIX_ARG_COMPUTED_COLOR) + else if (params.colorArg2 == TEX_MIX_ARG_COMPUTED_COLOR) glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PREVIOUS); - else if (params.colorArg2 == Gfx::TEX_MIX_ARG_SRC_COLOR) + else if (params.colorArg2 == TEX_MIX_ARG_SRC_COLOR) glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PRIMARY_COLOR); - else if (params.colorArg2 == Gfx::TEX_MIX_ARG_FACTOR) + else if (params.colorArg2 == TEX_MIX_ARG_FACTOR) glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_CONSTANT); else assert(false); @@ -746,57 +749,57 @@ void Gfx::CGLDevice::SetTextureStageParams(int index, const Gfx::TextureStagePar after_tex_color: // Alpha operation - if (params.alphaOperation == Gfx::TEX_MIX_OPER_DEFAULT) + if (params.alphaOperation == TEX_MIX_OPER_DEFAULT) { glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_PREVIOUS); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_TEXTURE); goto after_tex_operations; } - else if (params.colorOperation == Gfx::TEX_MIX_OPER_REPLACE) + else if (params.colorOperation == TEX_MIX_OPER_REPLACE) glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE); - else if (params.alphaOperation == Gfx::TEX_MIX_OPER_MODULATE) + else if (params.alphaOperation == TEX_MIX_OPER_MODULATE) glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE); - else if (params.alphaOperation == Gfx::TEX_MIX_OPER_ADD) + else if (params.alphaOperation == TEX_MIX_OPER_ADD) glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_ADD); - else if (params.alphaOperation == Gfx::TEX_MIX_OPER_SUBTRACT) + else if (params.alphaOperation == TEX_MIX_OPER_SUBTRACT) glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_SUBTRACT); else assert(false); // Alpha arg1 - if (params.alphaArg1 == Gfx::TEX_MIX_ARG_TEXTURE) + if (params.alphaArg1 == TEX_MIX_ARG_TEXTURE) glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE); - else if (params.alphaArg1 == Gfx::TEX_MIX_ARG_COMPUTED_COLOR) + else if (params.alphaArg1 == TEX_MIX_ARG_COMPUTED_COLOR) glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_PREVIOUS); - else if (params.alphaArg1 == Gfx::TEX_MIX_ARG_SRC_COLOR) + else if (params.alphaArg1 == TEX_MIX_ARG_SRC_COLOR) glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_PRIMARY_COLOR); - else if (params.alphaArg1 == Gfx::TEX_MIX_ARG_FACTOR) + else if (params.alphaArg1 == TEX_MIX_ARG_FACTOR) glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_CONSTANT); else assert(false); // Alpha arg2 - if (params.alphaArg2 == Gfx::TEX_MIX_ARG_TEXTURE) + if (params.alphaArg2 == TEX_MIX_ARG_TEXTURE) glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_TEXTURE); - else if (params.alphaArg2 == Gfx::TEX_MIX_ARG_COMPUTED_COLOR) + else if (params.alphaArg2 == TEX_MIX_ARG_COMPUTED_COLOR) glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_PREVIOUS); - else if (params.alphaArg2 == Gfx::TEX_MIX_ARG_SRC_COLOR) + else if (params.alphaArg2 == TEX_MIX_ARG_SRC_COLOR) glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_PRIMARY_COLOR); - else if (params.alphaArg2 == Gfx::TEX_MIX_ARG_FACTOR) + else if (params.alphaArg2 == TEX_MIX_ARG_FACTOR) glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_CONSTANT); else assert(false); after_tex_operations: - if (params.wrapS == Gfx::TEX_WRAP_CLAMP) + if (params.wrapS == TEX_WRAP_CLAMP) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); - else if (params.wrapS == Gfx::TEX_WRAP_REPEAT) + else if (params.wrapS == TEX_WRAP_REPEAT) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); else assert(false); - if (params.wrapT == Gfx::TEX_WRAP_CLAMP) + if (params.wrapT == TEX_WRAP_CLAMP) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); - else if (params.wrapT == Gfx::TEX_WRAP_REPEAT) + else if (params.wrapT == TEX_WRAP_REPEAT) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); else assert(false); @@ -805,7 +808,7 @@ after_tex_operations: glDisable(GL_TEXTURE_2D); } -Gfx::TextureStageParams Gfx::CGLDevice::GetTextureStageParams(int index) +TextureStageParams CGLDevice::GetTextureStageParams(int index) { assert(index >= 0); assert(index < static_cast<int>( m_currentTextures.size() )); @@ -813,7 +816,7 @@ Gfx::TextureStageParams Gfx::CGLDevice::GetTextureStageParams(int index) return m_textureStageParams[index]; } -void Gfx::CGLDevice::SetTextureFactor(const Gfx::Color &color) +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) @@ -830,7 +833,7 @@ void Gfx::CGLDevice::SetTextureFactor(const Gfx::Color &color) } } -Gfx::Color Gfx::CGLDevice::GetTextureFactor() +Color CGLDevice::GetTextureFactor() { // Get from 1st stage (should be the same for all stages) glActiveTexture(GL_TEXTURE0); @@ -843,25 +846,25 @@ Gfx::Color Gfx::CGLDevice::GetTextureFactor() if ( (! m_texturing) || (! m_texturesEnabled[0]) ) glDisable(GL_TEXTURE_2D); - return Gfx::Color(color[0], color[1], color[2], color[3]); + return Color(color[0], color[1], color[2], color[3]); } -GLenum TranslateGfxPrimitive(Gfx::PrimitiveType type) +GLenum TranslateGfxPrimitive(PrimitiveType type) { GLenum flag = 0; switch (type) { - case Gfx::PRIMITIVE_POINTS: flag = GL_POINTS; break; - case Gfx::PRIMITIVE_LINES: flag = GL_LINES; break; - case Gfx::PRIMITIVE_LINE_STRIP: flag = GL_LINE_STRIP; break; - case Gfx::PRIMITIVE_TRIANGLES: flag = GL_TRIANGLES; break; - case Gfx::PRIMITIVE_TRIANGLE_STRIP: flag = GL_TRIANGLE_STRIP; break; + case PRIMITIVE_POINTS: flag = GL_POINTS; break; + case PRIMITIVE_LINES: flag = GL_LINES; break; + case PRIMITIVE_LINE_STRIP: flag = GL_LINE_STRIP; break; + case PRIMITIVE_TRIANGLES: flag = GL_TRIANGLES; break; + case PRIMITIVE_TRIANGLE_STRIP: flag = GL_TRIANGLE_STRIP; break; default: assert(false); break; } return flag; } -void Gfx::CGLDevice::DrawPrimitive(Gfx::PrimitiveType type, const Vertex *vertices, int vertexCount) +void CGLDevice::DrawPrimitive(PrimitiveType type, const Vertex *vertices, int vertexCount) { glBegin(TranslateGfxPrimitive(type)); @@ -877,7 +880,7 @@ void Gfx::CGLDevice::DrawPrimitive(Gfx::PrimitiveType type, const Vertex *vertic glEnd(); } -void Gfx::CGLDevice::DrawPrimitive(Gfx::PrimitiveType type, const Gfx::VertexCol *vertices, int vertexCount) +void CGLDevice::DrawPrimitive(PrimitiveType type, const VertexCol *vertices, int vertexCount) { glBegin(TranslateGfxPrimitive(type)); @@ -892,7 +895,7 @@ void Gfx::CGLDevice::DrawPrimitive(Gfx::PrimitiveType type, const Gfx::VertexCol glEnd(); } -void Gfx::CGLDevice::DrawPrimitive(Gfx::PrimitiveType type, const VertexTex2 *vertices, int vertexCount) +void CGLDevice::DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, int vertexCount) { glBegin(TranslateGfxPrimitive(type)); @@ -925,7 +928,7 @@ bool InPlane(Math::Vector normal, float originPlane, Math::Vector center, float */ // TODO: testing -int Gfx::CGLDevice::ComputeSphereVisibility(const Math::Vector ¢er, float radius) +int CGLDevice::ComputeSphereVisibility(const Math::Vector ¢er, float radius) { Math::Matrix m; m.LoadIdentity(); @@ -975,29 +978,29 @@ int Gfx::CGLDevice::ComputeSphereVisibility(const Math::Vector ¢er, float ra int result = 0; if (InPlane(vec[0], originPlane[0], center, radius)) - result |= Gfx::INTERSECT_PLANE_LEFT; + result |= INTERSECT_PLANE_LEFT; if (InPlane(vec[1], originPlane[1], center, radius)) - result |= Gfx::INTERSECT_PLANE_RIGHT; + result |= INTERSECT_PLANE_RIGHT; if (InPlane(vec[2], originPlane[2], center, radius)) - result |= Gfx::INTERSECT_PLANE_TOP; + result |= INTERSECT_PLANE_TOP; if (InPlane(vec[3], originPlane[3], center, radius)) - result |= Gfx::INTERSECT_PLANE_BOTTOM; + result |= INTERSECT_PLANE_BOTTOM; if (InPlane(vec[4], originPlane[4], center, radius)) - result |= Gfx::INTERSECT_PLANE_FRONT; + result |= INTERSECT_PLANE_FRONT; if (InPlane(vec[5], originPlane[5], center, radius)) - result |= Gfx::INTERSECT_PLANE_BACK; + result |= INTERSECT_PLANE_BACK; return result; } -void Gfx::CGLDevice::SetRenderState(Gfx::RenderState state, bool enabled) +void CGLDevice::SetRenderState(RenderState state, bool enabled) { - if (state == Gfx::RENDER_STATE_DEPTH_WRITE) + if (state == RENDER_STATE_DEPTH_WRITE) { glDepthMask(enabled ? GL_TRUE : GL_FALSE); return; } - else if (state == Gfx::RENDER_STATE_LIGHTING) + else if (state == RENDER_STATE_LIGHTING) { m_lighting = enabled; @@ -1014,7 +1017,7 @@ void Gfx::CGLDevice::SetRenderState(Gfx::RenderState state, bool enabled) return; } - else if (state == Gfx::RENDER_STATE_TEXTURING) + else if (state == RENDER_STATE_TEXTURING) { m_texturing = enabled; @@ -1035,12 +1038,12 @@ void Gfx::CGLDevice::SetRenderState(Gfx::RenderState state, bool enabled) switch (state) { - case Gfx::RENDER_STATE_BLENDING: flag = GL_BLEND; break; - case Gfx::RENDER_STATE_FOG: flag = GL_FOG; break; - case Gfx::RENDER_STATE_DEPTH_TEST: flag = GL_DEPTH_TEST; break; - case Gfx::RENDER_STATE_ALPHA_TEST: flag = GL_ALPHA_TEST; break; - case Gfx::RENDER_STATE_CULLING: flag = GL_CULL_FACE; break; - case Gfx::RENDER_STATE_DITHERING: flag = GL_DITHER; break; + case RENDER_STATE_BLENDING: flag = GL_BLEND; break; + case RENDER_STATE_FOG: flag = GL_FOG; break; + case RENDER_STATE_DEPTH_TEST: flag = GL_DEPTH_TEST; break; + case RENDER_STATE_ALPHA_TEST: flag = GL_ALPHA_TEST; break; + case RENDER_STATE_CULLING: flag = GL_CULL_FACE; break; + case RENDER_STATE_DITHERING: flag = GL_DITHER; break; default: assert(false); break; } @@ -1050,25 +1053,25 @@ void Gfx::CGLDevice::SetRenderState(Gfx::RenderState state, bool enabled) glDisable(flag); } -bool Gfx::CGLDevice::GetRenderState(Gfx::RenderState state) +bool CGLDevice::GetRenderState(RenderState state) { - if (state == Gfx::RENDER_STATE_LIGHTING) + if (state == RENDER_STATE_LIGHTING) return m_lighting; - if (state == Gfx::RENDER_STATE_TEXTURING) + if (state == RENDER_STATE_TEXTURING) return m_texturing; GLenum flag = 0; switch (state) { - case Gfx::RENDER_STATE_DEPTH_WRITE: flag = GL_DEPTH_WRITEMASK; break; - case Gfx::RENDER_STATE_BLENDING: flag = GL_BLEND; break; - case Gfx::RENDER_STATE_FOG: flag = GL_FOG; break; - case Gfx::RENDER_STATE_DEPTH_TEST: flag = GL_DEPTH_TEST; break; - case Gfx::RENDER_STATE_ALPHA_TEST: flag = GL_ALPHA_TEST; break; - case Gfx::RENDER_STATE_CULLING: flag = GL_CULL_FACE; break; - case Gfx::RENDER_STATE_DITHERING: flag = GL_DITHER; break; + case RENDER_STATE_DEPTH_WRITE: flag = GL_DEPTH_WRITEMASK; break; + case RENDER_STATE_BLENDING: flag = GL_BLEND; break; + case RENDER_STATE_FOG: flag = GL_FOG; break; + case RENDER_STATE_DEPTH_TEST: flag = GL_DEPTH_TEST; break; + case RENDER_STATE_ALPHA_TEST: flag = GL_ALPHA_TEST; break; + case RENDER_STATE_CULLING: flag = GL_CULL_FACE; break; + case RENDER_STATE_DITHERING: flag = GL_DITHER; break; default: assert(false); break; } @@ -1078,70 +1081,70 @@ bool Gfx::CGLDevice::GetRenderState(Gfx::RenderState state) return result == GL_TRUE; } -Gfx::CompFunc TranslateGLCompFunc(GLenum flag) +CompFunc TranslateGLCompFunc(GLenum flag) { switch (flag) { - case GL_NEVER: return Gfx::COMP_FUNC_NEVER; - case GL_LESS: return Gfx::COMP_FUNC_LESS; - case GL_EQUAL: return Gfx::COMP_FUNC_EQUAL; - case GL_NOTEQUAL: return Gfx::COMP_FUNC_NOTEQUAL; - case GL_LEQUAL: return Gfx::COMP_FUNC_LEQUAL; - case GL_GREATER: return Gfx::COMP_FUNC_GREATER; - case GL_GEQUAL: return Gfx::COMP_FUNC_GEQUAL; - case GL_ALWAYS: return Gfx::COMP_FUNC_ALWAYS; + case GL_NEVER: return COMP_FUNC_NEVER; + case GL_LESS: return COMP_FUNC_LESS; + case GL_EQUAL: return COMP_FUNC_EQUAL; + case GL_NOTEQUAL: return COMP_FUNC_NOTEQUAL; + case GL_LEQUAL: return COMP_FUNC_LEQUAL; + case GL_GREATER: return COMP_FUNC_GREATER; + case GL_GEQUAL: return COMP_FUNC_GEQUAL; + case GL_ALWAYS: return COMP_FUNC_ALWAYS; default: assert(false); break; } - return Gfx::COMP_FUNC_NEVER; + return COMP_FUNC_NEVER; } -GLenum TranslateGfxCompFunc(Gfx::CompFunc func) +GLenum TranslateGfxCompFunc(CompFunc func) { switch (func) { - case Gfx::COMP_FUNC_NEVER: return GL_NEVER; - case Gfx::COMP_FUNC_LESS: return GL_LESS; - case Gfx::COMP_FUNC_EQUAL: return GL_EQUAL; - case Gfx::COMP_FUNC_NOTEQUAL: return GL_NOTEQUAL; - case Gfx::COMP_FUNC_LEQUAL: return GL_LEQUAL; - case Gfx::COMP_FUNC_GREATER: return GL_GREATER; - case Gfx::COMP_FUNC_GEQUAL: return GL_GEQUAL; - case Gfx::COMP_FUNC_ALWAYS: return GL_ALWAYS; + case COMP_FUNC_NEVER: return GL_NEVER; + case COMP_FUNC_LESS: return GL_LESS; + case COMP_FUNC_EQUAL: return GL_EQUAL; + case COMP_FUNC_NOTEQUAL: return GL_NOTEQUAL; + case COMP_FUNC_LEQUAL: return GL_LEQUAL; + case COMP_FUNC_GREATER: return GL_GREATER; + case COMP_FUNC_GEQUAL: return GL_GEQUAL; + case COMP_FUNC_ALWAYS: return GL_ALWAYS; default: assert(false); break; } return 0; } -void Gfx::CGLDevice::SetDepthTestFunc(Gfx::CompFunc func) +void CGLDevice::SetDepthTestFunc(CompFunc func) { glDepthFunc(TranslateGfxCompFunc(func)); } -Gfx::CompFunc Gfx::CGLDevice::GetDepthTestFunc() +CompFunc CGLDevice::GetDepthTestFunc() { GLint flag = 0; glGetIntegerv(GL_DEPTH_FUNC, &flag); return TranslateGLCompFunc(static_cast<GLenum>(flag)); } -void Gfx::CGLDevice::SetDepthBias(float factor) +void CGLDevice::SetDepthBias(float factor) { glPolygonOffset(factor, 0.0f); } -float Gfx::CGLDevice::GetDepthBias() +float CGLDevice::GetDepthBias() { GLfloat result = 0.0f; glGetFloatv(GL_POLYGON_OFFSET_FACTOR, &result); return result; } -void Gfx::CGLDevice::SetAlphaTestFunc(Gfx::CompFunc func, float refValue) +void CGLDevice::SetAlphaTestFunc(CompFunc func, float refValue) { glAlphaFunc(TranslateGfxCompFunc(func), refValue); } -void Gfx::CGLDevice::GetAlphaTestFunc(Gfx::CompFunc &func, float &refValue) +void CGLDevice::GetAlphaTestFunc(CompFunc &func, float &refValue) { GLint flag = 0; glGetIntegerv(GL_ALPHA_TEST_FUNC, &flag); @@ -1150,53 +1153,53 @@ void Gfx::CGLDevice::GetAlphaTestFunc(Gfx::CompFunc &func, float &refValue) glGetFloatv(GL_ALPHA_TEST_REF, static_cast<GLfloat*>(&refValue)); } -Gfx::BlendFunc TranslateGLBlendFunc(GLenum flag) +BlendFunc TranslateGLBlendFunc(GLenum flag) { switch (flag) { - case GL_ZERO: return Gfx::BLEND_ZERO; - case GL_ONE: return Gfx::BLEND_ONE; - case GL_SRC_COLOR: return Gfx::BLEND_SRC_COLOR; - case GL_ONE_MINUS_SRC_COLOR: return Gfx::BLEND_INV_SRC_COLOR; - case GL_DST_COLOR: return Gfx::BLEND_DST_COLOR; - case GL_ONE_MINUS_DST_COLOR: return Gfx::BLEND_INV_DST_COLOR; - case GL_SRC_ALPHA: return Gfx::BLEND_SRC_ALPHA; - case GL_ONE_MINUS_SRC_ALPHA: return Gfx::BLEND_INV_SRC_ALPHA; - case GL_DST_ALPHA: return Gfx::BLEND_DST_ALPHA; - case GL_ONE_MINUS_DST_ALPHA: return Gfx::BLEND_INV_DST_ALPHA; - case GL_SRC_ALPHA_SATURATE: return Gfx::BLEND_SRC_ALPHA_SATURATE; + case GL_ZERO: return BLEND_ZERO; + case GL_ONE: return BLEND_ONE; + case GL_SRC_COLOR: return BLEND_SRC_COLOR; + case GL_ONE_MINUS_SRC_COLOR: return BLEND_INV_SRC_COLOR; + case GL_DST_COLOR: return BLEND_DST_COLOR; + case GL_ONE_MINUS_DST_COLOR: return BLEND_INV_DST_COLOR; + case GL_SRC_ALPHA: return BLEND_SRC_ALPHA; + case GL_ONE_MINUS_SRC_ALPHA: return BLEND_INV_SRC_ALPHA; + case GL_DST_ALPHA: return BLEND_DST_ALPHA; + case GL_ONE_MINUS_DST_ALPHA: return BLEND_INV_DST_ALPHA; + case GL_SRC_ALPHA_SATURATE: return BLEND_SRC_ALPHA_SATURATE; default: assert(false); break; } - return Gfx::BLEND_ZERO; + return BLEND_ZERO; } -GLenum TranslateGfxBlendFunc(Gfx::BlendFunc func) +GLenum TranslateGfxBlendFunc(BlendFunc func) { switch (func) { - case Gfx::BLEND_ZERO: return GL_ZERO; - case Gfx::BLEND_ONE: return GL_ONE; - case Gfx::BLEND_SRC_COLOR: return GL_SRC_COLOR; - case Gfx::BLEND_INV_SRC_COLOR: return GL_ONE_MINUS_SRC_COLOR; - case Gfx::BLEND_DST_COLOR: return GL_DST_COLOR; - case Gfx::BLEND_INV_DST_COLOR: return GL_ONE_MINUS_DST_COLOR; - case Gfx::BLEND_SRC_ALPHA: return GL_SRC_ALPHA; - case Gfx::BLEND_INV_SRC_ALPHA: return GL_ONE_MINUS_SRC_ALPHA; - case Gfx::BLEND_DST_ALPHA: return GL_DST_ALPHA; - case Gfx::BLEND_INV_DST_ALPHA: return GL_ONE_MINUS_DST_ALPHA; - case Gfx::BLEND_SRC_ALPHA_SATURATE: return GL_SRC_ALPHA_SATURATE; + case BLEND_ZERO: return GL_ZERO; + case BLEND_ONE: return GL_ONE; + case BLEND_SRC_COLOR: return GL_SRC_COLOR; + case BLEND_INV_SRC_COLOR: return GL_ONE_MINUS_SRC_COLOR; + case BLEND_DST_COLOR: return GL_DST_COLOR; + case BLEND_INV_DST_COLOR: return GL_ONE_MINUS_DST_COLOR; + case BLEND_SRC_ALPHA: return GL_SRC_ALPHA; + case BLEND_INV_SRC_ALPHA: return GL_ONE_MINUS_SRC_ALPHA; + case BLEND_DST_ALPHA: return GL_DST_ALPHA; + case BLEND_INV_DST_ALPHA: return GL_ONE_MINUS_DST_ALPHA; + case BLEND_SRC_ALPHA_SATURATE: return GL_SRC_ALPHA_SATURATE; default: assert(false); break; } return 0; } -void Gfx::CGLDevice::SetBlendFunc(Gfx::BlendFunc srcBlend, Gfx::BlendFunc dstBlend) +void CGLDevice::SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend) { glBlendFunc(TranslateGfxBlendFunc(srcBlend), TranslateGfxBlendFunc(dstBlend)); } -void Gfx::CGLDevice::GetBlendFunc(Gfx::BlendFunc &srcBlend, Gfx::BlendFunc &dstBlend) +void CGLDevice::GetBlendFunc(BlendFunc &srcBlend, BlendFunc &dstBlend) { GLint srcFlag = 0; glGetIntegerv(GL_ALPHA_TEST_FUNC, &srcFlag); @@ -1207,35 +1210,35 @@ void Gfx::CGLDevice::GetBlendFunc(Gfx::BlendFunc &srcBlend, Gfx::BlendFunc &dstB dstBlend = TranslateGLBlendFunc(static_cast<GLenum>(dstFlag)); } -void Gfx::CGLDevice::SetClearColor(const Gfx::Color &color) +void CGLDevice::SetClearColor(const Color &color) { glClearColor(color.r, color.g, color.b, color.a); } -Gfx::Color Gfx::CGLDevice::GetClearColor() +Color CGLDevice::GetClearColor() { GLfloat color[4] = { 0.0f }; glGetFloatv(GL_COLOR_CLEAR_VALUE, color); - return Gfx::Color(color[0], color[1], color[2], color[3]); + return Color(color[0], color[1], color[2], color[3]); } -void Gfx::CGLDevice::SetGlobalAmbient(const Gfx::Color &color) +void CGLDevice::SetGlobalAmbient(const Color &color) { glLightModelfv(GL_LIGHT_MODEL_AMBIENT, color.Array()); } -Gfx::Color Gfx::CGLDevice::GetGlobalAmbient() +Color CGLDevice::GetGlobalAmbient() { GLfloat color[4] = { 0.0f }; glGetFloatv(GL_LIGHT_MODEL_AMBIENT, color); - return Gfx::Color(color[0], color[1], color[2], color[3]); + return Color(color[0], color[1], color[2], color[3]); } -void Gfx::CGLDevice::SetFogParams(Gfx::FogMode mode, const Gfx::Color &color, float start, float end, float density) +void CGLDevice::SetFogParams(FogMode mode, const Color &color, float start, float end, float density) { - if (mode == Gfx::FOG_LINEAR) glFogi(GL_FOG_MODE, GL_LINEAR); - else if (mode == Gfx::FOG_EXP) glFogi(GL_FOG_MODE, GL_EXP); - else if (mode == Gfx::FOG_EXP2) glFogi(GL_FOG_MODE, GL_EXP2); + if (mode == FOG_LINEAR) glFogi(GL_FOG_MODE, GL_LINEAR); + else if (mode == FOG_EXP) glFogi(GL_FOG_MODE, GL_EXP); + else if (mode == FOG_EXP2) glFogi(GL_FOG_MODE, GL_EXP2); else assert(false); glFogf(GL_FOG_START, start); @@ -1243,13 +1246,13 @@ void Gfx::CGLDevice::SetFogParams(Gfx::FogMode mode, const Gfx::Color &color, fl glFogf(GL_FOG_DENSITY, density); } -void Gfx::CGLDevice::GetFogParams(Gfx::FogMode &mode, Gfx::Color &color, float &start, float &end, float &density) +void CGLDevice::GetFogParams(FogMode &mode, Color &color, float &start, float &end, float &density) { GLint flag = 0; glGetIntegerv(GL_FOG_MODE, &flag); - if (flag == GL_LINEAR) mode = Gfx::FOG_LINEAR; - else if (flag == GL_EXP) mode = Gfx::FOG_EXP; - else if (flag == GL_EXP2) mode = Gfx::FOG_EXP2; + if (flag == GL_LINEAR) mode = FOG_LINEAR; + else if (flag == GL_EXP) mode = FOG_EXP; + else if (flag == GL_EXP2) mode = FOG_EXP2; else assert(false); glGetFloatv(GL_FOG_START, static_cast<GLfloat*>(&start)); @@ -1257,57 +1260,60 @@ void Gfx::CGLDevice::GetFogParams(Gfx::FogMode &mode, Gfx::Color &color, float & glGetFloatv(GL_FOG_DENSITY, static_cast<GLfloat*>(&density)); } -void Gfx::CGLDevice::SetCullMode(Gfx::CullMode mode) +void CGLDevice::SetCullMode(CullMode mode) { // Cull clockwise back faces, so front face is the opposite // (assuming GL_CULL_FACE is GL_BACK) - if (mode == Gfx::CULL_CW ) glFrontFace(GL_CCW); - else if (mode == Gfx::CULL_CCW) glFrontFace(GL_CW); + if (mode == CULL_CW ) glFrontFace(GL_CCW); + else if (mode == CULL_CCW) glFrontFace(GL_CW); else assert(false); } -Gfx::CullMode Gfx::CGLDevice::GetCullMode() +CullMode CGLDevice::GetCullMode() { GLint flag = 0; glGetIntegerv(GL_FRONT_FACE, &flag); - if (flag == GL_CW) return Gfx::CULL_CCW; - else if (flag == GL_CCW) return Gfx::CULL_CW; + if (flag == GL_CW) return CULL_CCW; + else if (flag == GL_CCW) return CULL_CW; else assert(false); - return Gfx::CULL_CW; + return CULL_CW; } -void Gfx::CGLDevice::SetShadeModel(Gfx::ShadeModel model) +void CGLDevice::SetShadeModel(ShadeModel model) { - if (model == Gfx::SHADE_FLAT) glShadeModel(GL_FLAT); - else if (model == Gfx::SHADE_SMOOTH) glShadeModel(GL_SMOOTH); + if (model == SHADE_FLAT) glShadeModel(GL_FLAT); + else if (model == SHADE_SMOOTH) glShadeModel(GL_SMOOTH); else assert(false); } -Gfx::ShadeModel Gfx::CGLDevice::GetShadeModel() +ShadeModel CGLDevice::GetShadeModel() { GLint flag = 0; glGetIntegerv(GL_SHADE_MODEL, &flag); - if (flag == GL_FLAT) return Gfx::SHADE_FLAT; - else if (flag == GL_SMOOTH) return Gfx::SHADE_SMOOTH; + if (flag == GL_FLAT) return SHADE_FLAT; + else if (flag == GL_SMOOTH) return SHADE_SMOOTH; else assert(false); - return Gfx::SHADE_FLAT; + return SHADE_FLAT; } -void Gfx::CGLDevice::SetFillMode(Gfx::FillMode mode) +void CGLDevice::SetFillMode(FillMode mode) { - if (mode == Gfx::FILL_POINT) glPolygonMode(GL_FRONT_AND_BACK, GL_POINT); - else if (mode == Gfx::FILL_LINES) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - else if (mode == Gfx::FILL_FILL) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + if (mode == FILL_POINT) glPolygonMode(GL_FRONT_AND_BACK, GL_POINT); + else if (mode == FILL_LINES) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + else if (mode == FILL_POLY) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); else assert(false); } -Gfx::FillMode Gfx::CGLDevice::GetFillMode() +FillMode CGLDevice::GetFillMode() { GLint flag = 0; glGetIntegerv(GL_POLYGON_MODE, &flag); - if (flag == GL_POINT) return Gfx::FILL_POINT; - else if (flag == GL_LINE) return Gfx::FILL_LINES; - else if (flag == GL_FILL) return Gfx::FILL_FILL; + if (flag == GL_POINT) return FILL_POINT; + else if (flag == GL_LINE) return FILL_LINES; + else if (flag == GL_FILL) return FILL_POLY; else assert(false); - return Gfx::FILL_POINT; + return FILL_POINT; } + + +} // namespace Gfx diff --git a/src/graphics/opengl/gldevice.h b/src/graphics/opengl/gldevice.h index b59af1c..1274ee9 100644 --- a/src/graphics/opengl/gldevice.h +++ b/src/graphics/opengl/gldevice.h @@ -16,7 +16,7 @@ /** * \file graphics/opengl/gldevice.h - * \brief OpenGL implementation - Gfx::CGLDevice class + * \brief OpenGL implementation - CGLDevice class */ #pragma once @@ -29,6 +29,7 @@ #include <set> +// Graphics module namespace namespace Gfx { /** @@ -70,10 +71,10 @@ struct GLDevicePrivate; Because of that, CGLDeviceConfig is outside the CDevice class and must be set in CApplication. */ -class CGLDevice : public Gfx::CDevice +class CGLDevice : public CDevice { public: - CGLDevice(const Gfx::GLDeviceConfig &config); + CGLDevice(const GLDeviceConfig &config); virtual ~CGLDevice(); virtual void DebugHook(); @@ -81,82 +82,82 @@ public: virtual bool Create(); virtual void Destroy(); - void ConfigChanged(const Gfx::GLDeviceConfig &newConfig); + void ConfigChanged(const GLDeviceConfig &newConfig); virtual void BeginScene(); virtual void EndScene(); virtual void Clear(); - virtual void SetTransform(Gfx::TransformType type, const Math::Matrix &matrix); - virtual const Math::Matrix& GetTransform(Gfx::TransformType type); - virtual void MultiplyTransform(Gfx::TransformType type, const Math::Matrix &matrix); + virtual void SetTransform(TransformType type, const Math::Matrix &matrix); + virtual const Math::Matrix& GetTransform(TransformType type); + virtual void MultiplyTransform(TransformType type, const Math::Matrix &matrix); - virtual void SetMaterial(const Gfx::Material &material); - virtual const Gfx::Material& GetMaterial(); + virtual void SetMaterial(const Material &material); + virtual const Material& GetMaterial(); virtual int GetMaxLightCount(); - virtual void SetLight(int index, const Gfx::Light &light); - virtual const Gfx::Light& GetLight(int index); + virtual void SetLight(int index, const Light &light); + virtual const Light& GetLight(int index); virtual void SetLightEnabled(int index, bool enabled); virtual bool GetLightEnabled(int index); - virtual Gfx::Texture CreateTexture(CImage *image, const Gfx::TextureCreateParams ¶ms); - virtual Gfx::Texture CreateTexture(ImageData *data, const Gfx::TextureCreateParams ¶ms); - virtual void DestroyTexture(const Gfx::Texture &texture); + virtual Texture CreateTexture(CImage *image, const TextureCreateParams ¶ms); + virtual Texture CreateTexture(ImageData *data, const TextureCreateParams ¶ms); + virtual void DestroyTexture(const Texture &texture); virtual void DestroyAllTextures(); virtual int GetMaxTextureCount(); - virtual void SetTexture(int index, const Gfx::Texture &texture); + virtual void SetTexture(int index, const Texture &texture); virtual void SetTexture(int index, unsigned int textureId); - virtual Gfx::Texture GetTexture(int index); + virtual Texture GetTexture(int index); virtual void SetTextureEnabled(int index, bool enabled); virtual bool GetTextureEnabled(int index); - virtual void SetTextureStageParams(int index, const Gfx::TextureStageParams ¶ms); - virtual Gfx::TextureStageParams GetTextureStageParams(int index); + virtual void SetTextureStageParams(int index, const TextureStageParams ¶ms); + virtual TextureStageParams GetTextureStageParams(int index); - virtual void SetTextureFactor(const Gfx::Color &color); - virtual Gfx::Color GetTextureFactor(); + virtual void SetTextureFactor(const Color &color); + virtual Color GetTextureFactor(); - virtual void DrawPrimitive(Gfx::PrimitiveType type, const Gfx::Vertex *vertices, int vertexCount); - virtual void DrawPrimitive(Gfx::PrimitiveType type, const Gfx::VertexCol *vertices, int vertexCount); - virtual void DrawPrimitive(Gfx::PrimitiveType type, const Gfx::VertexTex2 *vertices, int vertexCount); + 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); virtual int ComputeSphereVisibility(const Math::Vector ¢er, float radius); - virtual void SetRenderState(Gfx::RenderState state, bool enabled); - virtual bool GetRenderState(Gfx::RenderState state); + virtual void SetRenderState(RenderState state, bool enabled); + virtual bool GetRenderState(RenderState state); - virtual void SetDepthTestFunc(Gfx::CompFunc func); - virtual Gfx::CompFunc GetDepthTestFunc(); + virtual void SetDepthTestFunc(CompFunc func); + virtual CompFunc GetDepthTestFunc(); virtual void SetDepthBias(float factor); virtual float GetDepthBias(); - virtual void SetAlphaTestFunc(Gfx::CompFunc func, float refValue); - virtual void GetAlphaTestFunc(Gfx::CompFunc &func, float &refValue); + virtual void SetAlphaTestFunc(CompFunc func, float refValue); + virtual void GetAlphaTestFunc(CompFunc &func, float &refValue); - virtual void SetBlendFunc(Gfx::BlendFunc srcBlend, Gfx::BlendFunc dstBlend); - virtual void GetBlendFunc(Gfx::BlendFunc &srcBlend, Gfx::BlendFunc &dstBlend); + virtual void SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend); + virtual void GetBlendFunc(BlendFunc &srcBlend, BlendFunc &dstBlend); - virtual void SetClearColor(const Gfx::Color &color); - virtual Gfx::Color GetClearColor(); + virtual void SetClearColor(const Color &color); + virtual Color GetClearColor(); - virtual void SetGlobalAmbient(const Gfx::Color &color); - virtual Gfx::Color GetGlobalAmbient(); + virtual void SetGlobalAmbient(const Color &color); + virtual Color GetGlobalAmbient(); - virtual void SetFogParams(Gfx::FogMode mode, const Gfx::Color &color, float start, float end, float density); - virtual void GetFogParams(Gfx::FogMode &mode, Gfx::Color &color, float &start, float &end, float &density); + virtual void SetFogParams(FogMode mode, const Color &color, float start, float end, float density); + virtual void GetFogParams(FogMode &mode, Color &color, float &start, float &end, float &density); - virtual void SetCullMode(Gfx::CullMode mode); - virtual Gfx::CullMode GetCullMode(); + virtual void SetCullMode(CullMode mode); + virtual CullMode GetCullMode(); - virtual void SetShadeModel(Gfx::ShadeModel model); - virtual Gfx::ShadeModel GetShadeModel(); + virtual void SetShadeModel(ShadeModel model); + virtual ShadeModel GetShadeModel(); - virtual void SetFillMode(Gfx::FillMode mode) ; - virtual Gfx::FillMode GetFillMode(); + virtual void SetFillMode(FillMode mode) ; + virtual FillMode GetFillMode(); private: //! Updates internal modelview matrix @@ -166,7 +167,7 @@ private: private: //! Current config - Gfx::GLDeviceConfig m_config; + GLDeviceConfig m_config; //! Current world matrix Math::Matrix m_worldMat; @@ -178,26 +179,27 @@ private: Math::Matrix m_projectionMat; //! The current material - Gfx::Material m_material; + Material m_material; //! Whether lighting is enabled bool m_lighting; //! Current lights - std::vector<Gfx::Light> m_lights; + std::vector<Light> m_lights; //! Current lights enable status std::vector<bool> m_lightsEnabled; //! Whether texturing is enabled in general bool m_texturing; //! Current textures; \c NULL value means unassigned - std::vector<Gfx::Texture> m_currentTextures; + std::vector<Texture> m_currentTextures; //! Current texture stages enable status std::vector<bool> m_texturesEnabled; //! Current texture params - std::vector<Gfx::TextureStageParams> m_textureStageParams; + std::vector<TextureStageParams> m_textureStageParams; //! Set of all created textures - std::set<Gfx::Texture> m_allTextures; + std::set<Texture> m_allTextures; }; -}; // namespace Gfx + +} // namespace Gfx |