Namespace and styling fix

dev-ui
Piotr Dziwinski 2012-09-19 23:50:28 +02:00
parent 7479f486b6
commit 7b6bbf79c4
43 changed files with 2403 additions and 2223 deletions

View File

@ -200,7 +200,6 @@ ${SDL_IMAGE_INCLUDE_DIR}
${SDLTTF_INCLUDE_DIR} ${SDLTTF_INCLUDE_DIR}
${PNG_INCLUDE_DIRS} ${PNG_INCLUDE_DIRS}
${OPTIONAL_INCLUDE_DIRS} ${OPTIONAL_INCLUDE_DIRS}
..
) )
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/CBot) link_directories(${CMAKE_CURRENT_SOURCE_DIR}/CBot)

View File

@ -14,16 +14,19 @@
// * You should have received a copy of the GNU General Public License // * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/. // * along with this program. If not, see http://www.gnu.org/licenses/.
// color.cpp
#include "graphics/core/color.h" #include "graphics/core/color.h"
#include "math/func.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 min = Math::Min(color.r, color.g, color.b);
float max = Math::Max(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; 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.h = Math::Norm(color.h)*360.0f;
color.s = Math::Norm(color.s); color.s = Math::Norm(color.s);
@ -101,3 +104,5 @@ Gfx::Color Gfx::HSV2RGB(Gfx::ColorHSV color)
return result; return result;
} }
} // namespace Gfx

View File

@ -21,14 +21,17 @@
#pragma once #pragma once
#include <sstream> #include <sstream>
// Graphics module namespace
namespace Gfx { namespace Gfx {
/** /**
\struct Color * \struct Color
\brief RGBA color */ * \brief RGBA color
*/
struct Color struct Color
{ {
//! Red, green, blue and alpha components //! 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) 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) {} : 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! //! Returns the struct cast to \c float* array; use with care!
@ -64,20 +67,21 @@ struct Color
return s.str(); 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; 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); return ! this->operator==(other);
} }
}; };
/** /**
\struct ColorHSV * \struct ColorHSV
\brief HSV color */ * \brief HSV color
*/
struct ColorHSV struct ColorHSV
{ {
float h, s, v; float h, s, v;
@ -96,10 +100,10 @@ struct ColorHSV
}; };
//! Converts a RGB color to HSV color //! Converts a RGB color to HSV color
Gfx::ColorHSV RGB2HSV(Gfx::Color color); ColorHSV RGB2HSV(Color color);
//! Converts a HSV color to RGB color //! Converts a HSV color to RGB color
Gfx::Color HSV2RGB(Gfx::ColorHSV color); Color HSV2RGB(ColorHSV color);
}; // namespace Gfx
} // namespace Gfx

View File

@ -17,7 +17,7 @@
/** /**
* \file graphics/core/device.h * \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 #pragma once
@ -28,6 +28,7 @@
#include "graphics/core/material.h" #include "graphics/core/material.h"
#include "graphics/core/texture.h" #include "graphics/core/texture.h"
#include "graphics/core/vertex.h" #include "graphics/core/vertex.h"
#include "math/intpoint.h" #include "math/intpoint.h"
#include "math/matrix.h" #include "math/matrix.h"
@ -38,13 +39,14 @@ class CImage;
struct ImageData; struct ImageData;
// Graphics module namespace
namespace Gfx { namespace Gfx {
/** /**
\struct DeviceConfig * \struct DeviceConfig
\brief General config for graphics device * \brief General config for graphics device
*
These settings are common window options set by SDL. * These settings are common window options set by SDL.
*/ */
struct DeviceConfig struct DeviceConfig
{ {
@ -78,10 +80,11 @@ struct DeviceConfig
/** /**
\enum TransformType * \enum TransformType
\brief Type of transformation in rendering pipeline * \brief Type of transformation in rendering pipeline
*
These correspond to DirectX's three transformation matrices. */ * These correspond to DirectX's three transformation matrices.
*/
enum TransformType enum TransformType
{ {
TRANSFORM_WORLD, TRANSFORM_WORLD,
@ -90,8 +93,9 @@ enum TransformType
}; };
/** /**
\enum RenderState * \enum RenderState
\brief Render states that can be enabled/disabled */ * \brief Render states that can be enabled/disabled
*/
enum RenderState enum RenderState
{ {
RENDER_STATE_LIGHTING, RENDER_STATE_LIGHTING,
@ -106,8 +110,9 @@ enum RenderState
}; };
/** /**
\enum CompFunc * \enum CompFunc
\brief Type of function used to compare values */ * \brief Type of function used to compare values
*/
enum CompFunc enum CompFunc
{ {
COMP_FUNC_NEVER, COMP_FUNC_NEVER,
@ -121,8 +126,9 @@ enum CompFunc
}; };
/** /**
\enum BlendFunc * \enum BlendFunc
\brief Type of blending function */ * \brief Type of blending function
*/
enum BlendFunc enum BlendFunc
{ {
BLEND_ZERO, BLEND_ZERO,
@ -139,8 +145,9 @@ enum BlendFunc
}; };
/** /**
\enum FogMode * \enum FogMode
\brief Type of fog calculation function */ * \brief Type of fog calculation function
*/
enum FogMode enum FogMode
{ {
FOG_LINEAR, FOG_LINEAR,
@ -149,8 +156,9 @@ enum FogMode
}; };
/** /**
\enum CullMode * \enum CullMode
\brief Culling mode for polygons */ * \brief Culling mode for polygons
*/
enum CullMode enum CullMode
{ {
//! Cull clockwise faces //! Cull clockwise faces
@ -160,8 +168,9 @@ enum CullMode
}; };
/** /**
\enum ShadeModel * \enum ShadeModel
\brief Shade model used in rendering */ * \brief Shade model used in rendering
*/
enum ShadeModel enum ShadeModel
{ {
SHADE_FLAT, SHADE_FLAT,
@ -169,8 +178,9 @@ enum ShadeModel
}; };
/** /**
\enum FillMode * \enum FillMode
\brief Polygon fill mode */ * \brief Polygon fill mode
*/
enum FillMode enum FillMode
{ {
//! Draw only points //! Draw only points
@ -178,12 +188,13 @@ enum FillMode
//! Draw only lines //! Draw only lines
FILL_LINES, FILL_LINES,
//! Draw full polygons //! Draw full polygons
FILL_FILL FILL_POLY
}; };
/** /**
\enum PrimitiveType * \enum PrimitiveType
\brief Type of primitive to render */ * \brief Type of primitive to render
*/
enum PrimitiveType enum PrimitiveType
{ {
PRIMITIVE_POINTS, PRIMITIVE_POINTS,
@ -194,10 +205,11 @@ enum PrimitiveType
}; };
/** /**
\enum IntersectPlane * \enum IntersectPlane
\brief Intersection plane of projection volume * \brief Intersection plane of projection volume
*
These flags can be OR'd together. */ * These flags can be OR'd together.
*/
enum IntersectPlane enum IntersectPlane
{ {
INTERSECT_PLANE_LEFT = 0x01, INTERSECT_PLANE_LEFT = 0x01,
@ -211,67 +223,16 @@ enum IntersectPlane
INTERSECT_PLANE_FRONT | INTERSECT_PLANE_BACK 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 * \class CDevice
\brief Abstract interface of graphics device * \brief Abstract interface of graphics device
*
It is based on DIRECT3DDEVICE class from DirectX to make it easier to port existing code. * 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 * It encapsulates the general graphics device state and provides a common interface
to graphics-specific functions which will be used throughout the program, * 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, * 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. * only those that were used in old code.
*
*/ */
class CDevice class CDevice
{ {
@ -302,72 +263,72 @@ public:
virtual void MultiplyTransform(TransformType type, const Math::Matrix &matrix) = 0; virtual void MultiplyTransform(TransformType type, const Math::Matrix &matrix) = 0;
//! Sets the current material //! Sets the current material
virtual void SetMaterial(const Gfx::Material &material) = 0; virtual void SetMaterial(const Material &material) = 0;
//! Returns the current material //! Returns the current material
virtual const Gfx::Material& GetMaterial() = 0; virtual const Material& GetMaterial() = 0;
//! Returns the maximum number of lights available //! Returns the maximum number of lights available
virtual int GetMaxLightCount() = 0; virtual int GetMaxLightCount() = 0;
//! Sets the light at given index //! 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 //! 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 //! Enables/disables the light at given index
virtual void SetLightEnabled(int index, bool enabled) = 0; virtual void SetLightEnabled(int index, bool enabled) = 0;
//! Returns the current enable state of light at given index //! Returns the current enable state of light at given index
virtual bool GetLightEnabled(int index) = 0; virtual bool GetLightEnabled(int index) = 0;
//! Creates a texture from image; the image can be safely removed after that //! Creates a texture from image; the image can be safely removed after that
virtual Gfx::Texture CreateTexture(CImage *image, const Gfx::TextureCreateParams &params) = 0; virtual Texture CreateTexture(CImage *image, const TextureCreateParams &params) = 0;
//! Creates a texture from raw image data; image data can be freed after that //! Creates a texture from raw image data; image data can be freed after that
virtual Gfx::Texture CreateTexture(ImageData *data, const Gfx::TextureCreateParams &params) = 0; virtual Texture CreateTexture(ImageData *data, const TextureCreateParams &params) = 0;
//! Deletes a given texture, freeing it from video memory //! 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 //! Deletes all textures created so far
virtual void DestroyAllTextures() = 0; virtual void DestroyAllTextures() = 0;
//! Returns the maximum number of multitexture stages //! Returns the maximum number of multitexture stages
virtual int GetMaxTextureCount() = 0; virtual int GetMaxTextureCount() = 0;
//! Sets the texture at given texture stage //! 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 //! Sets the texture image by ID at given texture stage
virtual void SetTexture(int index, unsigned int textureId) = 0; virtual void SetTexture(int index, unsigned int textureId) = 0;
//! Returns the (multi)texture at given index //! 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 //! Enables/disables the given texture stage
virtual void SetTextureEnabled(int index, bool enabled) = 0; virtual void SetTextureEnabled(int index, bool enabled) = 0;
//! Returns the current enable state of given texture stage //! Returns the current enable state of given texture stage
virtual bool GetTextureEnabled(int index) = 0; virtual bool GetTextureEnabled(int index) = 0;
//! Sets the params for texture stage with given index //! Sets the params for texture stage with given index
virtual void SetTextureStageParams(int index, const Gfx::TextureStageParams &params) = 0; virtual void SetTextureStageParams(int index, const TextureStageParams &params) = 0;
//! Returns the current params of texture stage with given index //! 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 //! 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 //! Returns the current texture factor
virtual Gfx::Color GetTextureFactor() = 0; virtual Color GetTextureFactor() = 0;
//! Renders primitive composed of vertices with single texture //! 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 //! 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) //! 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 //! Tests whether a sphere intersects the 6 clipping planes of projection volume
virtual int ComputeSphereVisibility(const Math::Vector &center, float radius) = 0; virtual int ComputeSphereVisibility(const Math::Vector &center, float radius) = 0;
//! Enables/disables the given render state //! 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 //! 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 //! 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 //! 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) //! Sets the depth bias (constant value added to Z-coords)
virtual void SetDepthBias(float factor) = 0; virtual void SetDepthBias(float factor) = 0;
@ -375,44 +336,45 @@ public:
virtual float GetDepthBias() = 0; virtual float GetDepthBias() = 0;
//! Sets the alpha test function and reference value //! 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 //! 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 //! 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 //! 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 //! Sets the clear color
virtual void SetClearColor(const Gfx::Color &color) = 0; virtual void SetClearColor(const Color &color) = 0;
//! Returns the current clear color //! Returns the current clear color
virtual Gfx::Color GetClearColor() = 0; virtual Color GetClearColor() = 0;
//! Sets the global ambient color //! 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 //! 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) //! 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) //! 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 //! Sets the current cull mode
virtual void SetCullMode(Gfx::CullMode mode) = 0; virtual void SetCullMode(CullMode mode) = 0;
//! Returns the current cull mode //! Returns the current cull mode
virtual Gfx::CullMode GetCullMode() = 0; virtual CullMode GetCullMode() = 0;
//! Sets the shade model //! Sets the shade model
virtual void SetShadeModel(Gfx::ShadeModel model) = 0; virtual void SetShadeModel(ShadeModel model) = 0;
//! Returns the current shade model //! Returns the current shade model
virtual Gfx::ShadeModel GetShadeModel() = 0; virtual ShadeModel GetShadeModel() = 0;
//! Sets the current fill mode //! Sets the current fill mode
virtual void SetFillMode(Gfx::FillMode mode) = 0; virtual void SetFillMode(FillMode mode) = 0;
//! Returns the current fill mode //! Returns the current fill mode
virtual Gfx::FillMode GetFillMode() = 0; virtual FillMode GetFillMode() = 0;
}; };
}; // namespace Gfx
} // namespace Gfx

View File

@ -24,14 +24,17 @@
#include "graphics/core/color.h" #include "graphics/core/color.h"
#include "math/vector.h" #include "math/vector.h"
// Graphics module namespace
namespace Gfx { namespace Gfx {
/** /**
\enum LightType * \enum LightType
\brief Type of light in 3D scene */ * \brief Type of light in 3D scene
*/
enum LightType enum LightType
{ {
LIGHT_POINT, LIGHT_POINT,
@ -40,20 +43,21 @@ enum LightType
}; };
/** /**
\struct Light * \struct Light
\brief Properties of light in 3D scene * \brief Properties of light in 3D scene
*
This structure was created as analog to DirectX's D3DLIGHT. */ * This structure was created as analog to DirectX's D3DLIGHT.
*/
struct Light struct Light
{ {
//! Type of light source //! Type of light source
Gfx::LightType type; LightType type;
//! Color of ambient light //! Color of ambient light
Gfx::Color ambient; Color ambient;
//! Color of diffuse light //! Color of diffuse light
Gfx::Color diffuse; Color diffuse;
//! Color of specular light //! Color of specular light
Gfx::Color specular; Color specular;
//! Position in world space (for point & spot lights) //! Position in world space (for point & spot lights)
Math::Vector position; Math::Vector position;
//! Direction in world space (for directional & spot lights) //! Direction in world space (for directional & spot lights)
@ -80,9 +84,9 @@ struct Light
void LoadDefault() void LoadDefault()
{ {
type = LIGHT_POINT; type = LIGHT_POINT;
ambient = Gfx::Color(0.4f, 0.4f, 0.4f); ambient = Color(0.4f, 0.4f, 0.4f);
diffuse = Gfx::Color(0.8f, 0.8f, 0.8f); diffuse = Color(0.8f, 0.8f, 0.8f);
specular = Gfx::Color(1.0f, 1.0f, 1.0f); specular = Color(1.0f, 1.0f, 1.0f);
position = Math::Vector(0.0f, 0.0f, 0.0f); position = Math::Vector(0.0f, 0.0f, 0.0f);
direction = Math::Vector(0.0f, 0.0f, 1.0f); direction = Math::Vector(0.0f, 0.0f, 1.0f);
attenuation0 = 1.0f; attenuation0 = 1.0f;
@ -92,4 +96,5 @@ struct Light
} }
}; };
}; // namespace Gfx
} // namespace Gfx

View File

@ -25,6 +25,7 @@
#include "graphics/core/color.h" #include "graphics/core/color.h"
// Graphics module namespace
namespace Gfx { namespace Gfx {
/** /**
@ -40,21 +41,22 @@ namespace Gfx {
struct Material struct Material
{ {
//! Diffuse color //! Diffuse color
Gfx::Color diffuse; Color diffuse;
//! Ambient color //! Ambient color
Gfx::Color ambient; Color ambient;
//! Specular color //! 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; 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); return ! operator==(mat);
} }
}; };
}; // namespace Gfx
} // namespace Gfx

View File

@ -21,14 +21,17 @@
#pragma once #pragma once
#include "math/intpoint.h" #include "math/intpoint.h"
// Graphics module namespace
namespace Gfx { namespace Gfx {
/** /**
\enum TexImgFormat * \enum TexImgFormat
\brief Format of image data */ * \brief Format of image data
*/
enum TexImgFormat enum TexImgFormat
{ {
//! Try to determine automatically (may not work) //! Try to determine automatically (may not work)
@ -44,10 +47,11 @@ enum TexImgFormat
}; };
/** /**
\enum TexMinFilter * \enum TexMinFilter
\brief Texture minification filter * \brief Texture minification filter
*
Corresponds to OpenGL modes but should translate to DirectX too. */ * Corresponds to OpenGL modes but should translate to DirectX too.
*/
enum TexMinFilter enum TexMinFilter
{ {
TEX_MIN_FILTER_NEAREST, TEX_MIN_FILTER_NEAREST,
@ -59,8 +63,9 @@ enum TexMinFilter
}; };
/** /**
\enum TexMagFilter * \enum TexMagFilter
\brief Texture magnification filter */ * \brief Texture magnification filter
*/
enum TexMagFilter enum TexMagFilter
{ {
TEX_MAG_FILTER_NEAREST, TEX_MAG_FILTER_NEAREST,
@ -68,8 +73,9 @@ enum TexMagFilter
}; };
/** /**
\enum TexWrapMode * \enum TexWrapMode
\brief Wrapping mode for texture coords */ * \brief Wrapping mode for texture coords
*/
enum TexWrapMode enum TexWrapMode
{ {
TEX_WRAP_CLAMP, TEX_WRAP_CLAMP,
@ -77,8 +83,9 @@ enum TexWrapMode
}; };
/** /**
\enum TexMixOperation * \enum TexMixOperation
\brief Multitexture mixing operation */ * \brief Multitexture mixing operation
*/
enum TexMixOperation enum TexMixOperation
{ {
//! Default operation on default params (modulate on computed & texture) //! Default operation on default params (modulate on computed & texture)
@ -94,8 +101,9 @@ enum TexMixOperation
}; };
/** /**
\enum TexMixArgument * \enum TexMixArgument
\brief Multitexture mixing argument */ * \brief Multitexture mixing argument
*/
enum TexMixArgument enum TexMixArgument
{ {
//! Color from current texture //! Color from current texture
@ -119,11 +127,11 @@ struct TextureCreateParams
//! Whether to generate mipmaps //! Whether to generate mipmaps
bool mipmap; bool mipmap;
//! Format of source image data //! Format of source image data
Gfx::TexImgFormat format; TexImgFormat format;
//! Minification filter //! Minification filter
Gfx::TexMinFilter minFilter; TexMinFilter minFilter;
//! Magnification filter //! Magnification filter
Gfx::TexMagFilter magFilter; TexMagFilter magFilter;
//! Constructor; calls LoadDefault() //! Constructor; calls LoadDefault()
TextureCreateParams() TextureCreateParams()
@ -132,11 +140,11 @@ struct TextureCreateParams
//! Loads the default values //! Loads the default values
inline void LoadDefault() inline void LoadDefault()
{ {
format = Gfx::TEX_IMG_RGB; format = TEX_IMG_RGB;
mipmap = false; mipmap = false;
minFilter = Gfx::TEX_MIN_FILTER_NEAREST; minFilter = TEX_MIN_FILTER_NEAREST;
magFilter = Gfx::TEX_MAG_FILTER_NEAREST; magFilter = TEX_MAG_FILTER_NEAREST;
} }
}; };
@ -149,21 +157,21 @@ struct TextureCreateParams
struct TextureStageParams struct TextureStageParams
{ {
//! Mixing operation done on color values //! Mixing operation done on color values
Gfx::TexMixOperation colorOperation; TexMixOperation colorOperation;
//! 1st argument of color operations //! 1st argument of color operations
Gfx::TexMixArgument colorArg1; TexMixArgument colorArg1;
//! 2nd argument of color operations //! 2nd argument of color operations
Gfx::TexMixArgument colorArg2; TexMixArgument colorArg2;
//! Mixing operation done on alpha values //! Mixing operation done on alpha values
Gfx::TexMixOperation alphaOperation; TexMixOperation alphaOperation;
//! 1st argument of alpha operations //! 1st argument of alpha operations
Gfx::TexMixArgument alphaArg1; TexMixArgument alphaArg1;
//! 2nd argument of alpha operations //! 2nd argument of alpha operations
Gfx::TexMixArgument alphaArg2; TexMixArgument alphaArg2;
//! Wrap mode for 1st tex coord //! Wrap mode for 1st tex coord
Gfx::TexWrapMode wrapS; TexWrapMode wrapS;
//! Wrap mode for 2nd tex coord //! Wrap mode for 2nd tex coord
Gfx::TexWrapMode wrapT; TexWrapMode wrapT;
//! Constructor; calls LoadDefault() //! Constructor; calls LoadDefault()
TextureStageParams() TextureStageParams()
@ -172,15 +180,15 @@ struct TextureStageParams
//! Loads the default values //! Loads the default values
inline void LoadDefault() inline void LoadDefault()
{ {
colorOperation = Gfx::TEX_MIX_OPER_DEFAULT; colorOperation = TEX_MIX_OPER_DEFAULT;
colorArg1 = Gfx::TEX_MIX_ARG_COMPUTED_COLOR; colorArg1 = TEX_MIX_ARG_COMPUTED_COLOR;
colorArg2 = Gfx::TEX_MIX_ARG_TEXTURE; colorArg2 = TEX_MIX_ARG_TEXTURE;
alphaOperation = Gfx::TEX_MIX_OPER_DEFAULT; alphaOperation = TEX_MIX_OPER_DEFAULT;
alphaArg1 = Gfx::TEX_MIX_ARG_COMPUTED_COLOR; alphaArg1 = TEX_MIX_ARG_COMPUTED_COLOR;
alphaArg2 = Gfx::TEX_MIX_ARG_TEXTURE; 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 //! 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 // Invalid textures are always "less than" every other texture
@ -235,7 +243,7 @@ struct Texture
} }
//! Comparator //! Comparator
inline bool operator==(const Gfx::Texture &other) const inline bool operator==(const Texture &other) const
{ {
if (Valid() != other.Valid()) if (Valid() != other.Valid())
return false; return false;
@ -246,4 +254,5 @@ struct Texture
} }
}; };
}; // namespace Gfx
} // namespace Gfx

View File

@ -23,11 +23,14 @@
#include "graphics/core/color.h" #include "graphics/core/color.h"
#include "math/vector.h" #include "math/vector.h"
#include "math/point.h" #include "math/point.h"
#include <sstream> #include <sstream>
// Graphics module namespace
namespace Gfx { namespace Gfx {
/** /**
@ -72,20 +75,20 @@ struct Vertex
* *
* It contains: * It contains:
* - vertex coordinates (x,y,z) as Math::Vector, * - vertex coordinates (x,y,z) as Math::Vector,
* - RGBA color as Gfx::Color, * - RGBA color as Color,
* - RGBA specular color as Gfx::Color, * - RGBA specular color as Color,
* - texture coordinates (u,v) as Math::Point. * - texture coordinates (u,v) as Math::Point.
*/ */
struct VertexCol struct VertexCol
{ {
Math::Vector coord; Math::Vector coord;
Gfx::Color color; Color color;
Gfx::Color specular; Color specular;
Math::Point texCoord; Math::Point texCoord;
explicit VertexCol(Math::Vector aCoord = Math::Vector(), explicit VertexCol(Math::Vector aCoord = Math::Vector(),
Gfx::Color aColor = Gfx::Color(), Color aColor = Color(),
Gfx::Color aSpecular = Gfx::Color(), Color aSpecular = Color(),
Math::Point aTexCoord = Math::Point()) Math::Point aTexCoord = Math::Point())
: coord(aCoord), color(aColor), specular(aSpecular), texCoord(aTexCoord) {} : coord(aCoord), color(aColor), specular(aSpecular), texCoord(aTexCoord) {}
@ -105,7 +108,7 @@ struct VertexCol
* \struct VertexTex2 * \struct VertexTex2
* \brief Vertex with secondary texture coordinates * \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 * secondary texture coordinates (u2, v2) as Math::Point
*/ */
struct VertexTex2 struct VertexTex2
@ -121,8 +124,8 @@ struct VertexTex2
Math::Point aTexCoord2 = Math::Point()) Math::Point aTexCoord2 = Math::Point())
: coord(aCoord), normal(aNormal), texCoord(aTexCoord), texCoord2(aTexCoord2) {} : coord(aCoord), normal(aNormal), texCoord(aTexCoord), texCoord2(aTexCoord2) {}
//! Sets the fields from Gfx::Vertex with texCoord2 = (0,0) //! Sets the fields from Vertex with texCoord2 = (0,0)
void FromVertex(const Gfx::Vertex &v) void FromVertex(const Vertex &v)
{ {
coord = v.coord; coord = v.coord;
normal = v.normal; normal = v.normal;
@ -141,4 +144,5 @@ struct VertexTex2
} }
}; };
}; // namespace Gfx
} // namespace Gfx

File diff suppressed because it is too large Load Diff

View File

@ -17,18 +17,22 @@
/** /**
* \file graphics/engine/camera.h * \file graphics/engine/camera.h
* \brief Camera handling - Gfx::CCamera class * \brief Camera handling - CCamera class
*/ */
#pragma once #pragma once
#include "engine.h"
#include "common/event.h" #include "common/event.h"
#include "graphics/engine/engine.h"
class CInstanceManager; class CInstanceManager;
class CObject; class CObject;
// Graphics module namespace
namespace Gfx { namespace Gfx {
@ -140,18 +144,18 @@ class CCamera {
CObject* GetControllingObject(); CObject* GetControllingObject();
//! Change the type of camera //! Change the type of camera
void SetType(Gfx::CameraType type); void SetType(CameraType type);
Gfx::CameraType GetType(); CameraType GetType();
//! Management of the smoothing mode //! Management of the smoothing mode
void SetSmooth(CameraSmooth type); void SetSmooth(CameraSmooth type);
Gfx::CameraSmooth GetSmoth(); CameraSmooth GetSmoth();
//! Management of the setback distance //! Management of the setback distance
void SetDist(float dist); void SetDist(float dist);
float GetDist(); float GetDist();
//! Manage angle mode Gfx::CAM_TYPE_FIX //! Manage angle mode CAM_TYPE_FIX
void SetFixDirection(float angle); void SetFixDirection(float angle);
float GetFixDirection(); float GetFixDirection();
@ -181,13 +185,13 @@ class CCamera {
//! Removes the special effect with the camera //! Removes the special effect with the camera
void FlushEffect(); void FlushEffect();
//! Starts a special effect with the camera //! 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 //! Removes the effect of superposition in the foreground
void FlushOver(); void FlushOver();
//! Specifies the base color //! Specifies the base color
void SetOverBaseColor(Gfx::Color color); void SetOverBaseColor(Color color);
void StartOver(Gfx::CameraOverEffect effect, Math::Vector pos, float force); void StartOver(CameraOverEffect effect, Math::Vector pos, float force);
//! Sets the soft movement of the camera //! Sets the soft movement of the camera
void FixCamera(); void FixCamera();
@ -202,7 +206,7 @@ class CCamera {
//! Returns an additional force to turn //! Returns an additional force to turn
float GetMotorTurn(); float GetMotorTurn();
//! Returns the default sprite to use for the mouse //! Returns the default sprite to use for the mouse
Gfx::EngineMouseType GetMouseDef(Math::Point pos); EngineMouseType GetMouseDef(Math::Point pos);
protected: protected:
//! Changes the camera according to the mouse moved //! Changes the camera according to the mouse moved
@ -255,14 +259,14 @@ protected:
protected: protected:
CInstanceManager* m_iMan; CInstanceManager* m_iMan;
Gfx::CEngine* m_engine; CEngine* m_engine;
Gfx::CTerrain* m_terrain; CTerrain* m_terrain;
Gfx::CWater* m_water; CWater* m_water;
//! The type of camera //! The type of camera
Gfx::CameraType m_type; CameraType m_type;
//! Type of smoothing //! Type of smoothing
Gfx::CameraSmooth m_smooth; CameraSmooth m_smooth;
//! Object linked to the camera //! Object linked to the camera
CObject* m_cameraObj; CObject* m_cameraObj;
@ -328,7 +332,7 @@ protected:
//! CAM_TYPE_VISIT: relative time //! CAM_TYPE_VISIT: relative time
float m_visitTime; float m_visitTime;
//! CAM_TYPE_VISIT: initial type //! CAM_TYPE_VISIT: initial type
Gfx::CameraType m_visitType; CameraType m_visitType;
//! CAM_TYPE_VISIT: direction //! CAM_TYPE_VISIT: direction
float m_visitDirectionH; float m_visitDirectionH;
//! CAM_TYPE_VISIT: direction //! CAM_TYPE_VISIT: direction
@ -347,7 +351,7 @@ protected:
float m_motorTurn; float m_motorTurn;
Gfx::CenteringPhase m_centeringPhase; CenteringPhase m_centeringPhase;
float m_centeringAngleH; float m_centeringAngleH;
float m_centeringAngleV; float m_centeringAngleV;
float m_centeringDist; float m_centeringDist;
@ -356,17 +360,17 @@ protected:
float m_centeringTime; float m_centeringTime;
float m_centeringProgress; float m_centeringProgress;
Gfx::CameraEffect m_effectType; CameraEffect m_effectType;
Math::Vector m_effectPos; Math::Vector m_effectPos;
float m_effectForce; float m_effectForce;
float m_effectProgress; float m_effectProgress;
Math::Vector m_effectOffset; Math::Vector m_effectOffset;
Gfx::CameraOverEffect m_overType; CameraOverEffect m_overType;
float m_overForce; float m_overForce;
float m_overTime; float m_overTime;
Gfx::Color m_overColorBase; Color m_overColorBase;
Gfx::Color m_overColor; Color m_overColor;
int m_overMode; int m_overMode;
float m_overFadeIn; float m_overFadeIn;
float m_overFadeOut; float m_overFadeOut;
@ -386,4 +390,4 @@ protected:
}; };
}; // namespace Gfx } // namespace Gfx

View File

@ -15,24 +15,29 @@
// * You should have received a copy of the GNU General Public License // * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/. // * along with this program. If not, see http://www.gnu.org/licenses/.
// cloud.cpp
#include "graphics/engine/cloud.h" #include "graphics/engine/cloud.h"
#include "common/iman.h" #include "common/iman.h"
#include "graphics/core/device.h" #include "graphics/core/device.h"
#include "graphics/engine/engine.h" #include "graphics/engine/engine.h"
#include "graphics/engine/terrain.h" #include "graphics/engine/terrain.h"
#include "math/geometry.h" #include "math/geometry.h"
// Graphics module namespace
namespace Gfx {
const int CLOUD_LINE_PREALLOCATE_COUNT = 100; const int CLOUD_LINE_PREALLOCATE_COUNT = 100;
//! Extension of the bricks dimensions //! Extension of the bricks dimensions
const int CLOUD_SIZE_EXPAND = 4; 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 = iMan;
m_iMan->AddInstance(CLASS_CLOUD, this); 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); m_lines.reserve(CLOUD_LINE_PREALLOCATE_COUNT);
} }
Gfx::CCloud::~CCloud() CCloud::~CCloud()
{ {
m_iMan = nullptr; m_iMan = nullptr;
m_engine = nullptr; m_engine = nullptr;
m_terrain = nullptr; m_terrain = nullptr;
} }
bool Gfx::CCloud::EventProcess(const Event &event) bool CCloud::EventProcess(const Event &event)
{ {
if ( event.type == EVENT_FRAME ) if ( event.type == EVENT_FRAME )
return EventFrame(event); return EventFrame(event);
@ -63,7 +68,7 @@ bool Gfx::CCloud::EventProcess(const Event &event)
return true; return true;
} }
bool Gfx::CCloud::EventFrame(const Event &event) bool CCloud::EventFrame(const Event &event)
{ {
if (m_engine->GetPause()) return true; if (m_engine->GetPause()) return true;
@ -78,7 +83,7 @@ bool Gfx::CCloud::EventFrame(const Event &event)
return true; 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) Math::Point& uv1, Math::Point& uv2)
{ {
uv1.x = (pos.x+20000.0f)/1280.0f; 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; pos.y -= m_level*factor*10.0f;
} }
void Gfx::CCloud::Draw() void CCloud::Draw()
{ {
if (! m_enabled) return; if (! m_enabled) return;
if (m_level == 0.0f) return; if (m_level == 0.0f) return;
if (m_lines.empty()) 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 iDeep = m_engine->GetDeepView();
float deep = (m_brickCount*m_brickSize)/2.0f; float deep = (m_brickCount*m_brickSize)/2.0f;
@ -111,15 +116,15 @@ void Gfx::CCloud::Draw()
float fogStart = deep*0.15f; float fogStart = deep*0.15f;
float fogEnd = deep*0.24f; float fogEnd = deep*0.24f;
Gfx::CDevice* device = m_engine->GetDevice(); CDevice* device = m_engine->GetDevice();
// TODO: do this better? // 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); 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.diffuse = m_diffuse;
material.ambient = m_ambient; material.ambient = m_ambient;
m_engine->SetMaterial(material); m_engine->SetMaterial(material);
@ -127,11 +132,11 @@ void Gfx::CCloud::Draw()
m_engine->SetTexture(m_fileName, 0); m_engine->SetTexture(m_fileName, 0);
m_engine->SetTexture(m_fileName, 1); 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; Math::Matrix matrix;
matrix.LoadIdentity(); matrix.LoadIdentity();
device->SetTransform(Gfx::TRANSFORM_WORLD, matrix); device->SetTransform(TRANSFORM_WORLD, matrix);
float size = m_brickSize/2.0f; float size = m_brickSize/2.0f;
Math::Vector eye = m_engine->GetEyePt(); Math::Vector eye = m_engine->GetEyePt();
@ -154,13 +159,13 @@ void Gfx::CCloud::Draw()
p.z = pos.z+size; p.z = pos.z+size;
p.y = pos.y; p.y = pos.y;
AdjustLevel(p, eye, deep, uv1, uv2); 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.x = pos.x-size;
p.z = pos.z-size; p.z = pos.z-size;
p.y = pos.y; p.y = pos.y;
AdjustLevel(p, eye, deep, uv1, uv2); 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++) for (int j = 0; j < m_lines[i].len; j++)
{ {
@ -168,18 +173,18 @@ void Gfx::CCloud::Draw()
p.z = pos.z+size; p.z = pos.z+size;
p.y = pos.y; p.y = pos.y;
AdjustLevel(p, eye, deep, uv1, uv2); 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.x = pos.x+size;
p.z = pos.z-size; p.z = pos.z-size;
p.y = pos.y; p.y = pos.y;
AdjustLevel(p, eye, deep, uv1, uv2); 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; 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); m_engine->AddStatisticTriangle(vertexIndex - 2);
} }
@ -188,9 +193,9 @@ void Gfx::CCloud::Draw()
m_engine->UpdateMatProj(); // gives depth to initial 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.x = x;
line.y = y; line.y = y;
@ -205,8 +210,8 @@ void Gfx::CCloud::CreateLine(int x, int y, int len)
m_lines.push_back(line); m_lines.push_back(line);
} }
void Gfx::CCloud::Create(const std::string& fileName, void CCloud::Create(const std::string& fileName,
const Gfx::Color& diffuse, const Gfx::Color& ambient, const Color& diffuse, const Color& ambient,
float level) float level)
{ {
m_diffuse = diffuse; m_diffuse = diffuse;
@ -240,30 +245,33 @@ void Gfx::CCloud::Create(const std::string& fileName,
return; return;
} }
void Gfx::CCloud::Flush() void CCloud::Flush()
{ {
m_level = 0.0f; m_level = 0.0f;
} }
void Gfx::CCloud::SetLevel(float level) void CCloud::SetLevel(float level)
{ {
m_level = level; m_level = level;
Create(m_fileName, m_diffuse, m_ambient, m_level); Create(m_fileName, m_diffuse, m_ambient, m_level);
} }
float Gfx::CCloud::GetLevel() float CCloud::GetLevel()
{ {
return m_level; return m_level;
} }
void Gfx::CCloud::SetEnabled(bool enabled) void CCloud::SetEnabled(bool enabled)
{ {
m_enabled = enabled; m_enabled = enabled;
} }
bool Gfx::CCloud::GetEnabled() bool CCloud::GetEnabled()
{ {
return m_enabled; return m_enabled;
} }
} // namespace Gfx

View File

@ -17,13 +17,16 @@
/** /**
* \file graphics/engine/cloud.h * \file graphics/engine/cloud.h
* \brief Cloud rendering - Gfx::CCloud class * \brief Cloud rendering - CCloud class
*/ */
#pragma once #pragma once
#include "common/event.h" #include "common/event.h"
#include "graphics/core/color.h" #include "graphics/core/color.h"
#include "math/point.h" #include "math/point.h"
#include "math/vector.h" #include "math/vector.h"
@ -31,10 +34,10 @@
#include <string> #include <string>
class CInstanceManager; class CInstanceManager;
// Graphics module namespace
namespace Gfx { namespace Gfx {
class CEngine; class CEngine;
@ -83,7 +86,7 @@ public:
//! Removes all the clouds //! Removes all the clouds
void Flush(); void Flush();
//! Creates all areas of cloud //! 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 //! Draw the clouds
void Draw(); void Draw();
@ -110,8 +113,8 @@ protected:
protected: protected:
CInstanceManager* m_iMan; CInstanceManager* m_iMan;
Gfx::CEngine* m_engine; CEngine* m_engine;
Gfx::CTerrain* m_terrain; CTerrain* m_terrain;
bool m_enabled; bool m_enabled;
//! Overall level //! Overall level
@ -121,9 +124,9 @@ protected:
//! Feedrate (wind) //! Feedrate (wind)
Math::Point m_speed; Math::Point m_speed;
//! Diffuse color //! Diffuse color
Gfx::Color m_diffuse; Color m_diffuse;
//! Ambient color //! Ambient color
Gfx::Color m_ambient; Color m_ambient;
float m_time; float m_time;
float m_lastTest; float m_lastTest;
int m_subdiv; int m_subdiv;
@ -135,8 +138,8 @@ protected:
//! Size of a brick element //! Size of a brick element
float m_brickSize; float m_brickSize;
std::vector<Gfx::CloudLine> m_lines; std::vector<CloudLine> m_lines;
}; };
}; // namespace Gfx } // namespace Gfx

File diff suppressed because it is too large Load Diff

View File

@ -17,17 +17,21 @@
/** /**
* \file graphics/engine/engine.h * \file graphics/engine/engine.h
* \brief Main graphics engine - Gfx::CEngine class * \brief Main graphics engine - CEngine class
*/ */
#pragma once #pragma once
#include "app/system.h" #include "app/system.h"
#include "common/event.h" #include "common/event.h"
#include "graphics/core/color.h" #include "graphics/core/color.h"
#include "graphics/core/material.h" #include "graphics/core/material.h"
#include "graphics/core/texture.h" #include "graphics/core/texture.h"
#include "graphics/core/vertex.h" #include "graphics/core/vertex.h"
#include "math/intpoint.h" #include "math/intpoint.h"
#include "math/matrix.h" #include "math/matrix.h"
#include "math/point.h" #include "math/point.h"
@ -46,6 +50,7 @@ class CObject;
class CSoundInterface; class CSoundInterface;
// Graphics module namespace
namespace Gfx { namespace Gfx {
class CDevice; class CDevice;
@ -60,11 +65,12 @@ class CTerrain;
/** /**
\enum EngineRenderState * \enum EngineRenderState
\brief Render state of graphics engine * \brief Render state of graphics engine
*
States are used for settings certain modes, for instance texturing and blending. * 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. */ * The enum is a bitmask and some of the states can be OR'd together.
*/
enum EngineRenderState enum EngineRenderState
{ {
//! Normal opaque materials //! Normal opaque materials
@ -115,8 +121,9 @@ enum EngineRenderState
/** /**
\enum EngineTriangleType * \enum EngineTriangleType
\brief Type of triangles drawn for engine objects */ * \brief Type of triangles drawn for engine objects
*/
enum EngineTriangleType enum EngineTriangleType
{ {
//! Triangles //! Triangles
@ -126,14 +133,15 @@ enum EngineTriangleType
}; };
/** /**
\struct EngineTriangle * \struct EngineTriangle
\brief A triangle drawn by the graphics engine */ * \brief A triangle drawn by the graphics engine
*/
struct EngineTriangle struct EngineTriangle
{ {
//! Triangle vertices //! Triangle vertices
Gfx::VertexTex2 triangle[3]; VertexTex2 triangle[3];
//! Material //! Material
Gfx::Material material; Material material;
//! Render state //! Render state
int state; int state;
//! 1st texture //! 1st texture
@ -143,7 +151,7 @@ struct EngineTriangle
EngineTriangle() EngineTriangle()
{ {
state = Gfx::ENG_RSTATE_NORMAL; state = ENG_RSTATE_NORMAL;
} }
}; };
@ -169,8 +177,9 @@ enum EngineObjectType
}; };
/** /**
\struct EngineObject * \struct EngineObject
\brief Object drawn by the graphics engine */ * \brief Object drawn by the graphics engine
*/
struct EngineObject struct EngineObject
{ {
//! If true, object is valid in objects vector //! If true, object is valid in objects vector
@ -184,7 +193,7 @@ struct EngineObject
//! Number of triangles //! Number of triangles
int totalTriangles; int totalTriangles;
//! Type of object //! Type of object
Gfx::EngineObjectType type; EngineObjectType type;
//! Transformation matrix //! Transformation matrix
Math::Matrix transform; Math::Matrix transform;
//! Distance to object from eye point //! Distance to object from eye point
@ -214,7 +223,7 @@ struct EngineObject
drawWorld = false; drawWorld = false;
drawFront = false; drawFront = false;
totalTriangles = 0; totalTriangles = 0;
type = Gfx::ENG_OBJTYPE_NULL; type = ENG_OBJTYPE_NULL;
transform.LoadIdentity(); transform.LoadIdentity();
bboxMax.LoadZero(); bboxMax.LoadZero();
bboxMin.LoadZero(); bboxMin.LoadZero();
@ -231,66 +240,71 @@ struct EngineObjLevel3;
struct EngineObjLevel4; struct EngineObjLevel4;
/** /**
\struct EngineObjLevel4 * \struct EngineObjLevel4
\brief Tier 4 of object tree */ * \brief Tier 4 of object tree
*/
struct EngineObjLevel4 struct EngineObjLevel4
{ {
bool used; bool used;
Gfx::EngineTriangleType type; EngineTriangleType type;
Gfx::Material material; Material material;
int state; int state;
std::vector<Gfx::VertexTex2> vertices; std::vector<VertexTex2> vertices;
EngineObjLevel4(bool used = false, EngineObjLevel4(bool used = false,
Gfx::EngineTriangleType type = Gfx::ENG_TRIANGLE_TYPE_TRIANGLES, EngineTriangleType type = ENG_TRIANGLE_TYPE_TRIANGLES,
const Gfx::Material& material = Gfx::Material(), const Material& material = Material(),
int state = Gfx::ENG_RSTATE_NORMAL); int state = ENG_RSTATE_NORMAL);
}; };
/** /**
\struct EngineObjLevel3 * \struct EngineObjLevel3
\brief Tier 3 of object tree */ * \brief Tier 3 of object tree
*/
struct EngineObjLevel3 struct EngineObjLevel3
{ {
bool used; bool used;
float min; float min;
float max; float max;
std::vector<Gfx::EngineObjLevel4> next; std::vector<EngineObjLevel4> next;
EngineObjLevel3(bool used = false, float min = 0.0f, float max = 0.0f); EngineObjLevel3(bool used = false, float min = 0.0f, float max = 0.0f);
}; };
/** /**
\struct EngineObjLevel2 * \struct EngineObjLevel2
\brief Tier 2 of object tree */ * \brief Tier 2 of object tree
*/
struct EngineObjLevel2 struct EngineObjLevel2
{ {
bool used; bool used;
int objRank; int objRank;
std::vector<Gfx::EngineObjLevel3> next; std::vector<EngineObjLevel3> next;
EngineObjLevel2(bool used = false, int objRank = -1); EngineObjLevel2(bool used = false, int objRank = -1);
}; };
/** /**
\struct EngineObjLevel1 * \struct EngineObjLevel1
\brief Tier 1 of object tree */ * \brief Tier 1 of object tree
*/
struct EngineObjLevel1 struct EngineObjLevel1
{ {
bool used; bool used;
std::string tex1Name; std::string tex1Name;
Gfx::Texture tex1; Texture tex1;
std::string tex2Name; std::string tex2Name;
Gfx::Texture tex2; Texture tex2;
std::vector<Gfx::EngineObjLevel2> next; std::vector<EngineObjLevel2> next;
EngineObjLevel1(bool used = false, const std::string& tex1Name = "", EngineObjLevel1(bool used = false, const std::string& tex1Name = "",
const std::string& tex2Name = ""); const std::string& tex2Name = "");
}; };
/** /**
\struct EngineShadowType * \struct EngineShadowType
\brief Type of shadow drawn by the graphics engine */ * \brief Type of shadow drawn by the graphics engine
*/
enum EngineShadowType enum EngineShadowType
{ {
//! Normal shadow //! Normal shadow
@ -300,8 +314,9 @@ enum EngineShadowType
}; };
/** /**
\struct EngineShadow * \struct EngineShadow
\brief Shadow drawn by the graphics engine */ * \brief Shadow drawn by the graphics engine
*/
struct EngineShadow struct EngineShadow
{ {
//! If true, shadow is valid //! If true, shadow is valid
@ -311,7 +326,7 @@ struct EngineShadow
//! Rank of the associated object //! Rank of the associated object
int objRank; int objRank;
//! Type of shadow //! Type of shadow
Gfx::EngineShadowType type; EngineShadowType type;
//! Position of the shadow //! Position of the shadow
Math::Vector pos; Math::Vector pos;
//! Normal to the terrain //! Normal to the terrain
@ -335,7 +350,7 @@ struct EngineShadow
used = false; used = false;
hide = false; hide = false;
objRank = 0; objRank = 0;
type = Gfx::ENG_SHADOW_NORM; type = ENG_SHADOW_NORM;
pos.LoadZero(); pos.LoadZero();
normal.LoadZero(); normal.LoadZero();
angle = radius = intensity = height = 0.0f; angle = radius = intensity = height = 0.0f;
@ -343,14 +358,15 @@ struct EngineShadow
}; };
/** /**
\struct EngineGroundSpot * \struct EngineGroundSpot
\brief A spot (large shadow) drawn on the ground by the graphics engine */ * \brief A spot (large shadow) drawn on the ground by the graphics engine
*/
struct EngineGroundSpot struct EngineGroundSpot
{ {
//! If true, ground spot is valid //! If true, ground spot is valid
bool used; bool used;
//! Color of the shadow //! Color of the shadow
Gfx::Color color; Color color;
//! Min altitude //! Min altitude
float min; float min;
//! Max altitude //! Max altitude
@ -374,7 +390,7 @@ struct EngineGroundSpot
void LoadDefault() void LoadDefault()
{ {
used = false; used = false;
color = Gfx::Color(); color = Color();
pos.LoadZero(); pos.LoadZero();
drawPos.LoadZero(); drawPos.LoadZero();
min = max = smooth = radius = drawRadius = 0.0f; min = max = smooth = radius = drawRadius = 0.0f;
@ -382,8 +398,9 @@ struct EngineGroundSpot
}; };
/** /**
\enum EngineGroundMarkPhase * \enum EngineGroundMarkPhase
\brief Phase of life of an EngineGroundMark */ * \brief Phase of life of an EngineGroundMark
*/
enum EngineGroundMarkPhase enum EngineGroundMarkPhase
{ {
//! Null phase //! Null phase
@ -397,14 +414,15 @@ enum EngineGroundMarkPhase
}; };
/** /**
\struct EngineGroundMark * \struct EngineGroundMark
\brief A mark on ground drawn by the graphics engine */ * \brief A mark on ground drawn by the graphics engine
*/
struct EngineGroundMark struct EngineGroundMark
{ {
//! If true, draw mark //! If true, draw mark
bool draw; bool draw;
//! Phase of life //! Phase of life
Gfx::EngineGroundMarkPhase phase; EngineGroundMarkPhase phase;
//! Times for 3 life phases //! Times for 3 life phases
float delay[3]; float delay[3];
//! Fixed time //! Fixed time
@ -447,8 +465,8 @@ struct EngineGroundMark
}; };
/** /**
\enum EngineTextureMapping * \enum EngineTextureMapping
\brief Type of texture mapping * \brief Type of texture mapping
*/ */
enum EngineTextureMapping enum EngineTextureMapping
{ {
@ -462,8 +480,9 @@ enum EngineTextureMapping
/** /**
\enum EngineMouseType * \enum EngineMouseType
\brief Type of mouse cursor displayed in-game */ * \brief Type of mouse cursor displayed in-game
*/
enum EngineMouseType enum EngineMouseType
{ {
//! Normal cursor (arrow) //! Normal cursor (arrow)
@ -506,8 +525,9 @@ enum EngineMouseType
}; };
/** /**
\struct EngineMouse * \struct EngineMouse
\brief Information about mouse cursor */ * \brief Information about mouse cursor
*/
struct EngineMouse struct EngineMouse
{ {
//! Index of texture element for 1st image //! Index of texture element for 1st image
@ -517,15 +537,15 @@ struct EngineMouse
//! Shadow texture part //! Shadow texture part
int iconShadow; int iconShadow;
//! Mode to render 1st image in //! Mode to render 1st image in
Gfx::EngineRenderState mode1; EngineRenderState mode1;
//! Mode to render 2nd image in //! Mode to render 2nd image in
Gfx::EngineRenderState mode2; EngineRenderState mode2;
//! Hot point //! Hot point
Math::Point hotPoint; Math::Point hotPoint;
EngineMouse(int icon1 = -1, int icon2 = -1, int iconShadow = -1, EngineMouse(int icon1 = -1, int icon2 = -1, int iconShadow = -1,
Gfx::EngineRenderState mode1 = Gfx::ENG_RSTATE_NORMAL, EngineRenderState mode1 = ENG_RSTATE_NORMAL,
Gfx::EngineRenderState mode2 = Gfx::ENG_RSTATE_NORMAL, EngineRenderState mode2 = ENG_RSTATE_NORMAL,
Math::Point hotPoint = Math::Point()) Math::Point hotPoint = Math::Point())
{ {
this->icon1 = icon1; this->icon1 = icon1;
@ -625,7 +645,7 @@ struct EngineMouse
* Textures are loaded from a texture subdir in data directory. In the old code, textures were identified * 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 * 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 * 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 * 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. * and texture structs but it will also be subject to refactoring in the future.
*/ */
@ -636,12 +656,12 @@ public:
~CEngine(); ~CEngine();
//! Sets the device to be used //! Sets the device to be used
void SetDevice(Gfx::CDevice* device); void SetDevice(CDevice* device);
//! Returns the current device //! Returns the current device
Gfx::CDevice* GetDevice(); CDevice* GetDevice();
//! Sets the terrain object //! Sets the terrain object
void SetTerrain(Gfx::CTerrain* terrain); void SetTerrain(CTerrain* terrain);
//! Returns the text rendering engine //! Returns the text rendering engine
CText* GetText(); CText* GetText();
@ -737,8 +757,8 @@ public:
//@{ //@{
//! Management of engine object type //! Management of engine object type
bool SetObjectType(int objRank, Gfx::EngineObjectType type); bool SetObjectType(int objRank, EngineObjectType type);
Gfx::EngineObjectType GetObjectType(int objRank); EngineObjectType GetObjectType(int objRank);
//@} //@}
//@{ //@{
@ -762,30 +782,30 @@ public:
int GetObjectTotalTriangles(int objRank); int GetObjectTotalTriangles(int objRank);
//! Adds triangles to given object with the specified params //! Adds triangles to given object with the specified params
bool AddTriangles(int objRank, const std::vector<Gfx::VertexTex2>& vertices, bool AddTriangles(int objRank, const std::vector<VertexTex2>& vertices,
const Gfx::Material& material, int state, const Material& material, int state,
std::string tex1Name, std::string tex2Name, std::string tex1Name, std::string tex2Name,
float min, float max, bool globalUpdate); float min, float max, bool globalUpdate);
//! Adds a surface to given object with the specified params //! Adds a surface to given object with the specified params
bool AddSurface(int objRank, const std::vector<Gfx::VertexTex2>& vertices, bool AddSurface(int objRank, const std::vector<VertexTex2>& vertices,
const Gfx::Material& material, int state, const Material& material, int state,
std::string tex1Name, std::string tex2Name, std::string tex1Name, std::string tex2Name,
float min, float max, bool globalUpdate); float min, float max, bool globalUpdate);
//! Adds a tier 4 engine object directly //! 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, std::string tex1Name, std::string tex2Name,
float min, float max, bool globalUpdate); float min, float max, bool globalUpdate);
//! Returns the first found tier 4 engine object for the given params or nullptr if not found //! 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, int state, std::string tex1Name, std::string tex2Name,
float min, float max); float min, float max);
//! Returns a partial list of triangles for given object //! Returns a partial list of triangles for given object
int GetPartialTriangles(int objRank, float min, float max, float percent, int maxCount, 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 //! Updates LOD after parameter or resolution change
void ChangeLOD(); void ChangeLOD();
@ -794,15 +814,15 @@ public:
bool ChangeSecondTexture(int objRank, const std::string& tex2Name); bool ChangeSecondTexture(int objRank, const std::string& tex2Name);
//! Changes (recalculates) texture mapping for given object //! 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, 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); float au, float bu, float av, float bv);
//! Changes texture mapping for robot tracks //! 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, 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); float pos, float factor, float tl, float ts, float tt);
//! Detects the target object that is selected with the mouse //! Detects the target object that is selected with the mouse
@ -817,7 +837,7 @@ public:
//@{ //@{
//! Management of different shadow params //! Management of different shadow params
bool SetObjectShadowHide(int objRank, bool hide); 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 SetObjectShadowPos(int objRank, const Math::Vector& pos);
bool SetObjectShadowNormal(int objRank, const Math::Vector& normal); bool SetObjectShadowNormal(int objRank, const Math::Vector& normal);
bool SetObjectShadowAngle(int objRank, float angle); bool SetObjectShadowAngle(int objRank, float angle);
@ -843,7 +863,7 @@ public:
//! Management of different ground spot params //! Management of different ground spot params
bool SetObjectGroundSpotPos(int rank, const Math::Vector& pos); bool SetObjectGroundSpotPos(int rank, const Math::Vector& pos);
bool SetObjectGroundSpotRadius(int rank, float radius); 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 SetObjectGroundSpotMinMax(int rank, float min, float max);
bool SetObjectGroundSpotSmooth(int rank, float smooth); bool SetObjectGroundSpotSmooth(int rank, float smooth);
//@} //@}
@ -862,19 +882,19 @@ public:
/* *************** Mode setting *************** */ /* *************** Mode setting *************** */
//! Sets the current rendering state //! 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 //! Sets the current material
void SetMaterial(const Gfx::Material& mat); void SetMaterial(const Material& mat);
//! Specifies the location and direction of view //! Specifies the location and direction of view
void SetViewParams(const Math::Vector& eyePt, const Math::Vector& lookatPt, void SetViewParams(const Math::Vector& eyePt, const Math::Vector& lookatPt,
const Math::Vector& upVec, float eyeDistance); const Math::Vector& upVec, float eyeDistance);
//! Loads texture, creating it if not already present //! 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 //! 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 //! Loads all necessary textures
bool LoadAllTextures(); bool LoadAllTextures();
@ -882,12 +902,12 @@ public:
/** If loading fails, returns false. */ /** If loading fails, returns false. */
bool SetTexture(const std::string& name, int stage = 0); bool SetTexture(const std::string& name, int stage = 0);
//! Sets texture for given stage //! 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 //! Deletes the given texture, unloading it and removing from cache
void DeleteTexture(const std::string& name); void DeleteTexture(const std::string& name);
//! Deletes the given texture, unloading it and removing from cache //! 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) //! Border management (distance limits) depends of the resolution (LOD = level-of-detail)
@ -954,20 +974,20 @@ public:
//@{ //@{
//! Ambient color management //! Ambient color management
void SetAmbientColor(const Gfx::Color& color, int rank = 0); void SetAmbientColor(const Color& color, int rank = 0);
Gfx::Color GetAmbientColor(int rank = 0); Color GetAmbientColor(int rank = 0);
//@} //@}
//@{ //@{
//! Color management under water //! Color management under water
void SetWaterAddColor(const Gfx::Color& color); void SetWaterAddColor(const Color& color);
Gfx::Color GetWaterAddColor(); Color GetWaterAddColor();
//@} //@}
//@{ //@{
//! Management of the fog color //! Management of the fog color
void SetFogColor(const Gfx::Color& color, int rank = 0); void SetFogColor(const Color& color, int rank = 0);
Gfx::Color GetFogColor(int rank = 0); Color GetFogColor(int rank = 0);
//@} //@}
//@{ //@{
@ -989,11 +1009,11 @@ public:
//@{ //@{
//! Management of the background image to use //! Management of the background image to use
void SetBackground(const std::string& name, Gfx::Color up = Gfx::Color(), Gfx::Color down = Gfx::Color(), void SetBackground(const std::string& name, Color up = Color(), Color down = Color(),
Gfx::Color cloudUp = Gfx::Color(), Gfx::Color cloudDown = Gfx::Color(), Color cloudUp = Color(), Color cloudDown = Color(),
bool full = false, Math::Point scale = Math::Point(1.0f, 1.0f)); bool full = false, Math::Point scale = Math::Point(1.0f, 1.0f));
void GetBackground(std::string& name, Gfx::Color& up, Gfx::Color& down, void GetBackground(std::string& name, Color& up, Color& down,
Gfx::Color& cloudUp, Gfx::Color& cloudDown, Color& cloudUp, Color& cloudDown,
bool& full, Math::Point& scale); bool& full, Math::Point& scale);
//@} //@}
@ -1002,7 +1022,7 @@ public:
//! Specifies whether to draw the foreground //! Specifies whether to draw the foreground
void SetOverFront(bool front); void SetOverFront(bool front);
//! Sets the foreground overlay color //! 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 //! Management of the particle density
@ -1116,8 +1136,8 @@ public:
//@{ //@{
//! Management of mouse cursor type //! Management of mouse cursor type
void SetMouseType(Gfx::EngineMouseType type); void SetMouseType(EngineMouseType type);
Gfx::EngineMouseType GetMouseType(); EngineMouseType GetMouseType();
//@} //@}
//! Returns the view matrix //! Returns the view matrix
@ -1153,7 +1173,7 @@ protected:
//! Draws the gradient background //! Draws the gradient background
void DrawBackground(); void DrawBackground();
//! Draws the gradient background //! 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 //! Draws the image background
void DrawBackgroundImage(); void DrawBackgroundImage();
//! Draws all the planets //! Draws all the planets
@ -1170,17 +1190,17 @@ protected:
void DrawMouseSprite(Math::Point pos, Math::Point dim, int icon); void DrawMouseSprite(Math::Point pos, Math::Point dim, int icon);
//! Creates new tier 1 object //! 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 //! 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 //! 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 //! Creates a new tier 4 object
Gfx::EngineObjLevel4& AddLevel4(Gfx::EngineObjLevel3 &p3, Gfx::EngineTriangleType type, EngineObjLevel4& AddLevel4(EngineObjLevel3 &p3, EngineTriangleType type,
const Gfx::Material& mat, int state); const Material& mat, int state);
//! Create texture and add it to cache //! Create texture and add it to cache
Gfx::Texture CreateTexture(const std::string &texName, const Gfx::TextureCreateParams &params); Texture CreateTexture(const std::string &texName, const TextureCreateParams &params);
//! Tests whether the given object is visible //! Tests whether the given object is visible
bool IsVisible(int objRank); bool IsVisible(int objRank);
@ -1192,7 +1212,7 @@ protected:
bool GetBBox2D(int objRank, Math::Point& min, Math::Point& max); bool GetBBox2D(int objRank, Math::Point& min, Math::Point& max);
//! Detects whether the mouse is in a triangle. //! 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 //! Transforms a 3D point (x, y, z) in 2D space (x, y, -) of the window
/** The coordinated p2D.z gives the distance. */ /** The coordinated p2D.z gives the distance. */
@ -1208,15 +1228,15 @@ protected:
CInstanceManager* m_iMan; CInstanceManager* m_iMan;
CApplication* m_app; CApplication* m_app;
CSoundInterface* m_sound; CSoundInterface* m_sound;
Gfx::CDevice* m_device; CDevice* m_device;
Gfx::CText* m_text; CText* m_text;
Gfx::CLightManager* m_lightMan; CLightManager* m_lightMan;
Gfx::CParticle* m_particle; CParticle* m_particle;
Gfx::CWater* m_water; CWater* m_water;
Gfx::CCloud* m_cloud; CCloud* m_cloud;
Gfx::CLightning* m_lightning; CLightning* m_lightning;
Gfx::CPlanet* m_planet; CPlanet* m_planet;
Gfx::CTerrain* m_terrain; CTerrain* m_terrain;
//! Last encountered error //! Last encountered error
std::string m_error; std::string m_error;
@ -1253,15 +1273,15 @@ protected:
Math::IntPoint m_lastSize; Math::IntPoint m_lastSize;
//! Root of tree object structure (level 1 list) //! Root of tree object structure (level 1 list)
std::vector<Gfx::EngineObjLevel1> m_objectTree; std::vector<EngineObjLevel1> m_objectTree;
//! Object parameters //! Object parameters
std::vector<Gfx::EngineObject> m_objects; std::vector<EngineObject> m_objects;
//! Shadow list //! Shadow list
std::vector<Gfx::EngineShadow> m_shadows; std::vector<EngineShadow> m_shadows;
//! Ground spot list //! Ground spot list
std::vector<Gfx::EngineGroundSpot> m_groundSpots; std::vector<EngineGroundSpot> m_groundSpots;
//! Ground mark //! Ground mark
Gfx::EngineGroundMark m_groundMark; EngineGroundMark m_groundMark;
//! Location of camera //! Location of camera
Math::Vector m_eyePt; Math::Vector m_eyePt;
@ -1270,12 +1290,12 @@ protected:
float m_eyeDirH; float m_eyeDirH;
float m_eyeDirV; float m_eyeDirV;
int m_rankView; int m_rankView;
Gfx::Color m_ambientColor[2]; Color m_ambientColor[2];
Gfx::Color m_backColor[2]; Color m_backColor[2];
Gfx::Color m_fogColor[2]; Color m_fogColor[2];
float m_deepView[2]; float m_deepView[2];
float m_fogStart[2]; float m_fogStart[2];
Gfx::Color m_waterAddColor; Color m_waterAddColor;
int m_statisticTriangle; int m_statisticTriangle;
bool m_updateGeometry; bool m_updateGeometry;
int m_alphaMode; int m_alphaMode;
@ -1290,16 +1310,16 @@ protected:
bool m_backgroundFull; bool m_backgroundFull;
Math::Point m_backgroundScale; Math::Point m_backgroundScale;
std::string m_backgroundName; std::string m_backgroundName;
Gfx::Texture m_backgroundTex; Texture m_backgroundTex;
Gfx::Color m_backgroundColorUp; Color m_backgroundColorUp;
Gfx::Color m_backgroundColorDown; Color m_backgroundColorDown;
Gfx::Color m_backgroundCloudUp; Color m_backgroundCloudUp;
Gfx::Color m_backgroundCloudDown; Color m_backgroundCloudDown;
bool m_overFront; bool m_overFront;
Gfx::Color m_overColor; Color m_overColor;
int m_overMode; int m_overMode;
std::string m_foregroundName; std::string m_foregroundName;
Gfx::Texture m_foregroundTex; Texture m_foregroundTex;
bool m_drawWorld; bool m_drawWorld;
bool m_drawFront; bool m_drawFront;
float m_limitLOD[2]; float m_limitLOD[2];
@ -1337,25 +1357,25 @@ protected:
//! Texture directory name //! Texture directory name
std::string m_texPath; std::string m_texPath;
//! Default texture create params //! Default texture create params
Gfx::TextureCreateParams m_defaultTexParams; TextureCreateParams m_defaultTexParams;
//! Map of loaded textures (by name) //! 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) //! 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 //! Blacklist map of textures
/** Textures on this list were not successful in first loading, /** Textures on this list were not successful in first loading,
* so are disabled for subsequent load calls. */ * so are disabled for subsequent load calls. */
std::set<std::string> m_texBlacklist; std::set<std::string> m_texBlacklist;
//! Mouse cursor definitions //! Mouse cursor definitions
Gfx::EngineMouse m_mice[Gfx::ENG_MOUSE_COUNT]; EngineMouse m_mice[ENG_MOUSE_COUNT];
//! Texture with mouse cursors //! Texture with mouse cursors
Gfx::Texture m_miceTexture; Texture m_miceTexture;
//! Size of mouse cursor //! Size of mouse cursor
Math::Point m_mouseSize; Math::Point m_mouseSize;
//! Type of mouse cursor //! Type of mouse cursor
Gfx::EngineMouseType m_mouseType; EngineMouseType m_mouseType;
//! Position of mouse in interface coords //! Position of mouse in interface coords
Math::Point m_mousePos; Math::Point m_mousePos;
//! Is mouse visible? //! Is mouse visible?
@ -1364,11 +1384,12 @@ protected:
//! Last engine render state (-1 at the beginning of frame) //! Last engine render state (-1 at the beginning of frame)
int m_lastState; int m_lastState;
//! Last color set with render state //! Last color set with render state
Gfx::Color m_lastColor; Color m_lastColor;
//! Last texture names for 2 used texture stages //! Last texture names for 2 used texture stages
std::string m_lastTexture[2]; std::string m_lastTexture[2];
//! Last material //! Last material
Gfx::Material m_lastMaterial; Material m_lastMaterial;
}; };
}; // namespace Gfx
} // namespace Gfx

View File

@ -15,18 +15,23 @@
// * You should have received a copy of the GNU General Public License // * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/. // * along with this program. If not, see http://www.gnu.org/licenses/.
// light.cpp
#include "graphics/engine/lightman.h" #include "graphics/engine/lightman.h"
#include "common/iman.h" #include "common/iman.h"
#include "graphics/core/device.h" #include "graphics/core/device.h"
#include "math/geometry.h" #include "math/geometry.h"
#include <cmath> #include <cmath>
void Gfx::LightProgression::Init(float value) namespace Gfx {
void LightProgression::Init(float value)
{ {
starting = value; starting = value;
ending = value; ending = value;
@ -35,7 +40,7 @@ void Gfx::LightProgression::Init(float value)
speed = 100.0f; speed = 100.0f;
} }
void Gfx::LightProgression::Update(float rTime) void LightProgression::Update(float rTime)
{ {
if (speed < 100.0f) 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; starting = current;
ending = value; ending = value;
@ -62,15 +67,15 @@ void Gfx::LightProgression::SetTarget(float value)
} }
Gfx::DynamicLight::DynamicLight() DynamicLight::DynamicLight()
{ {
used = enabled = false; 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 = iMan;
m_iMan->AddInstance(CLASS_LIGHT, this); m_iMan->AddInstance(CLASS_LIGHT, this);
@ -81,7 +86,7 @@ Gfx::CLightManager::CLightManager(CInstanceManager* iMan, Gfx::CEngine* engine)
m_time = 0.0f; m_time = 0.0f;
} }
Gfx::CLightManager::~CLightManager() CLightManager::~CLightManager()
{ {
m_iMan->DeleteInstance(CLASS_LIGHT, this); m_iMan->DeleteInstance(CLASS_LIGHT, this);
@ -90,14 +95,14 @@ Gfx::CLightManager::~CLightManager()
m_engine = NULL; m_engine = NULL;
} }
void Gfx::CLightManager::SetDevice(Gfx::CDevice* device) void CLightManager::SetDevice(CDevice* device)
{ {
m_device = 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++) 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. */ /** 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++) for (int i = 0; i < static_cast<int>( m_dynLights.size() ); i++)
{ {
if (m_dynLights[i].used) continue; if (m_dynLights[i].used) continue;
m_dynLights[i] = Gfx::DynamicLight(); m_dynLights[i] = DynamicLight();
m_dynLights[i].used = true; m_dynLights[i].used = true;
m_dynLights[i].enabled = true; m_dynLights[i].enabled = true;
m_dynLights[i].includeType = Gfx::ENG_OBJTYPE_NULL; m_dynLights[i].includeType = ENG_OBJTYPE_NULL;
m_dynLights[i].excludeType = Gfx::ENG_OBJTYPE_NULL; m_dynLights[i].excludeType = ENG_OBJTYPE_NULL;
m_dynLights[i].light.type = Gfx::LIGHT_DIRECTIONAL; m_dynLights[i].light.type = LIGHT_DIRECTIONAL;
m_dynLights[i].light.diffuse = Gfx::Color(0.5f, 0.5f, 0.5f); 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.position = Math::Vector(-100.0f, 100.0f, -100.0f);
m_dynLights[i].light.direction = Math::Vector( 1.0f, -1.0f, 1.0f); m_dynLights[i].light.direction = Math::Vector( 1.0f, -1.0f, 1.0f);
@ -137,7 +142,7 @@ int Gfx::CLightManager::CreateLight()
return -1; return -1;
} }
bool Gfx::CLightManager::DeleteLight(int lightRank) bool CLightManager::DeleteLight(int lightRank)
{ {
if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) ) if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) )
return false; return false;
@ -148,7 +153,7 @@ bool Gfx::CLightManager::DeleteLight(int lightRank)
return true; 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() )) ) if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) )
return false; return false;
@ -162,7 +167,7 @@ bool Gfx::CLightManager::SetLight(int lightRank, const Gfx::Light &light)
return true; 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() )) ) if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) )
return false; return false;
@ -171,7 +176,7 @@ bool Gfx::CLightManager::GetLight(int lightRank, Gfx::Light &light)
return true; 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() )) ) if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) )
return false; return false;
@ -180,7 +185,7 @@ bool Gfx::CLightManager::SetLightEnabled(int lightRank, bool enabled)
return true; 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() )) ) if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) )
return false; return false;
@ -189,7 +194,7 @@ bool Gfx::CLightManager::SetLightIncludeType(int lightRank, Gfx::EngineObjectTyp
return true; 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() )) ) if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) )
return false; return false;
@ -198,7 +203,7 @@ bool Gfx::CLightManager::SetLightExcludeType(int lightRank, Gfx::EngineObjectTyp
return true; 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() )) ) if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) )
return false; return false;
@ -207,7 +212,7 @@ bool Gfx::CLightManager::SetLightPos(int lightRank, const Math::Vector &pos)
return true; 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() )) ) if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) )
return Math::Vector(0.0f, 0.0f, 0.0f); 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; 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() )) ) if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) )
return false; return false;
@ -224,7 +229,7 @@ bool Gfx::CLightManager::SetLightDir(int lightRank, const Math::Vector &dir)
return true; 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() )) ) if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) )
return Math::Vector(0.0f, 0.0f, 0.0f); 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; 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() )) ) if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) )
return false; return false;
@ -241,7 +246,7 @@ bool Gfx::CLightManager::SetLightIntensitySpeed(int lightRank, float speed)
return true; 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() )) ) if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) )
return false; return false;
@ -250,7 +255,7 @@ bool Gfx::CLightManager::SetLightIntensity(int lightRank, float value)
return true; return true;
} }
float Gfx::CLightManager::GetLightIntensity(int lightRank) float CLightManager::GetLightIntensity(int lightRank)
{ {
if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) ) if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) )
return 0.0f; 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() )) ) if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) )
return false; return false;
@ -270,7 +275,7 @@ bool Gfx::CLightManager::SetLightColorSpeed(int lightRank, float speed)
return true; 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() )) ) if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) )
return false; return false;
@ -281,26 +286,26 @@ bool Gfx::CLightManager::SetLightColor(int lightRank, const Gfx::Color &color)
return true; return true;
} }
Gfx::Color Gfx::CLightManager::GetLightColor(int lightRank) Color CLightManager::GetLightColor(int lightRank)
{ {
if ( (lightRank < 0) || (lightRank >= static_cast<int>( m_dynLights.size() )) ) 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.r = m_dynLights[lightRank].colorRed.current;
color.g = m_dynLights[lightRank].colorGreen.current; color.g = m_dynLights[lightRank].colorGreen.current;
color.b = m_dynLights[lightRank].colorBlue.current; color.b = m_dynLights[lightRank].colorBlue.current;
return color; 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++) for (int i = 0; i < static_cast<int>( m_dynLights.size() ); i++)
{ {
if (! m_dynLights[i].used) if (! m_dynLights[i].used)
continue; continue;
Gfx::Color value; Color value;
value.r = m_dynLights[i].colorRed.current; value.r = m_dynLights[i].colorRed.current;
value.g = m_dynLights[i].colorGreen.current; value.g = m_dynLights[i].colorGreen.current;
value.b = m_dynLights[i].colorBlue.current; value.b = m_dynLights[i].colorBlue.current;
@ -317,7 +322,7 @@ void Gfx::CLightManager::AdaptLightColor(const Gfx::Color &color, float factor)
UpdateLights(); UpdateLights();
} }
void Gfx::CLightManager::UpdateProgression(float rTime) void CLightManager::UpdateProgression(float rTime)
{ {
if (m_engine->GetPause()) if (m_engine->GetPause())
return; return;
@ -334,14 +339,14 @@ void Gfx::CLightManager::UpdateProgression(float rTime)
m_dynLights[i].colorGreen.Update(rTime); m_dynLights[i].colorGreen.Update(rTime);
m_dynLights[i].colorBlue.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.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.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); 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(); Math::Vector dir = m_engine->GetEyePt() - m_engine->GetLookatPt();
float angle = Math::RotateAngle(dir.x, dir.z); 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++) 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++) 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) if (m_dynLights[i].intensity.current == 0.0f)
continue; 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); bool enabled = (m_dynLights[i].includeType == type);
m_device->SetLightEnabled(i, enabled); 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); bool enabled = (m_dynLights[i].excludeType != type);
m_device->SetLightEnabled(i, enabled); m_device->SetLightEnabled(i, enabled);
} }
} }
} }
} // namespace Gfx

View File

@ -17,7 +17,7 @@
/** /**
* \file graphics/engine/lightman.h * \file graphics/engine/lightman.h
* \brief Dynamic light manager - Gfx::CLightManager class * \brief Dynamic light manager - CLightManager class
*/ */
#pragma once #pragma once
@ -26,9 +26,11 @@
#include "graphics/core/color.h" #include "graphics/core/color.h"
#include "graphics/core/light.h" #include "graphics/core/light.h"
#include "graphics/engine/engine.h" #include "graphics/engine/engine.h"
#include "math/vector.h" #include "math/vector.h"
// Graphics module namespace
namespace Gfx { namespace Gfx {
/** /**
@ -76,21 +78,21 @@ struct DynamicLight
bool enabled; bool enabled;
//! Configuration of the light //! Configuration of the light
Gfx::Light light; Light light;
//! Progression of intensity [0, 1] //! Progression of intensity [0, 1]
Gfx::LightProgression intensity; LightProgression intensity;
//! Progression of red diffuse color //! Progression of red diffuse color
Gfx::LightProgression colorRed; LightProgression colorRed;
//! Progression of green diffuse color //! Progression of green diffuse color
Gfx::LightProgression colorGreen; LightProgression colorGreen;
//! Progression of blue diffuse color //! 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 //! Type of objects included in lighting with this light; if ENG_OBJTYPE_NULL is used, it is ignored
Gfx::EngineObjectType includeType; EngineObjectType includeType;
//! Type of objects excluded from lighting with this light; if Gfx::ENG_OBJTYPE_NULL is used, it is ignored //! Type of objects excluded from lighting with this light; if ENG_OBJTYPE_NULL is used, it is ignored
Gfx::EngineObjectType excludeType; EngineObjectType excludeType;
DynamicLight(); DynamicLight();
}; };
@ -101,7 +103,7 @@ struct DynamicLight
(Old CLight class) (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. The dynamic lights are created, updated and deleted through the class' interface.
Number of available lights depends on graphics device used. Class allocates vector Number of available lights depends on graphics device used. Class allocates vector
@ -111,12 +113,12 @@ class CLightManager
{ {
public: public:
//! Constructor //! Constructor
CLightManager(CInstanceManager *iMan, Gfx::CEngine* engine); CLightManager(CInstanceManager *iMan, CEngine* engine);
//! Destructor //! Destructor
virtual ~CLightManager(); virtual ~CLightManager();
//! Sets the device to be used //! Sets the device to be used
void SetDevice(Gfx::CDevice* device); void SetDevice(CDevice* device);
//! Clears and disables all lights //! Clears and disables all lights
void FlushLights(); void FlushLights();
@ -125,16 +127,16 @@ public:
//! Deletes and disables the given dynamic light //! Deletes and disables the given dynamic light
bool DeleteLight(int lightRank); bool DeleteLight(int lightRank);
//! Sets the light parameters for dynamic light //! 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 //! 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 //! Enables/disables the given dynamic light
bool SetLightEnabled(int lightRank, bool enable); bool SetLightEnabled(int lightRank, bool enable);
//! Sets what objects are included in given dynamic light //! 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 //! 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 //! Sets the position of dynamic light
bool SetLightPos(int lightRank, const Math::Vector &pos); bool SetLightPos(int lightRank, const Math::Vector &pos);
@ -154,12 +156,12 @@ public:
bool SetLightIntensitySpeed(int lightRank, float speed); bool SetLightIntensitySpeed(int lightRank, float speed);
//! Adjusts the color of all dynamic lights //! 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 //! 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 //! Returns current light color
Gfx::Color GetLightColor(int lightRank); Color GetLightColor(int lightRank);
//! Sets the rate of change for dynamic light colors (RGB) //! Sets the rate of change for dynamic light colors (RGB)
bool SetLightColorSpeed(int lightRank, float speed); bool SetLightColorSpeed(int lightRank, float speed);
@ -168,7 +170,7 @@ public:
//! Updates (recalculates) all dynamic lights //! Updates (recalculates) all dynamic lights
void UpdateLights(); void UpdateLights();
//! Enables or disables dynamic lights affecting the given object type //! Enables or disables dynamic lights affecting the given object type
void UpdateLightsEnableState(Gfx::EngineObjectType type); void UpdateLightsEnableState(EngineObjectType type);
protected: protected:
CInstanceManager* m_iMan; CInstanceManager* m_iMan;
@ -178,7 +180,7 @@ protected:
//! Current time //! Current time
float m_time; float m_time;
//! List of dynamic lights //! List of dynamic lights
std::vector<Gfx::DynamicLight> m_dynLights; std::vector<DynamicLight> m_dynLights;
}; };
}; // namespace Gfx }; // namespace Gfx

View File

@ -15,75 +15,81 @@
// * You should have received a copy of the GNU General Public License // * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/. // * along with this program. If not, see http://www.gnu.org/licenses/.
// lightning.cpp (aka blitz.cpp)
#include "graphics/engine/lightning.h" #include "graphics/engine/lightning.h"
#include "common/logger.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"); GetLogger()->Trace("CLightning::CLightning() stub!\n");
// TODO! // TODO!
} }
Gfx::CLightning::~CLightning() CLightning::~CLightning()
{ {
GetLogger()->Trace("CLightning::~CLightning() stub!\n"); GetLogger()->Trace("CLightning::~CLightning() stub!\n");
// TODO! // TODO!
} }
void Gfx::CLightning::Flush() void CLightning::Flush()
{ {
GetLogger()->Trace("CLightning::Flush() stub!\n"); GetLogger()->Trace("CLightning::Flush() stub!\n");
// TODO! // TODO!
} }
bool Gfx::CLightning::EventProcess(const Event &event) bool CLightning::EventProcess(const Event &event)
{ {
GetLogger()->Trace("CLightning::EventProcess() stub!\n"); GetLogger()->Trace("CLightning::EventProcess() stub!\n");
// TODO! // TODO!
return true; 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"); GetLogger()->Trace("CLightning::Create() stub!\n");
// TODO! // TODO!
return true; 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"); GetLogger()->Trace("CLightning::GetStatus() stub!\n");
// TODO! // TODO!
return true; 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"); GetLogger()->Trace("CLightning::SetStatus() stub!\n");
// TODO! // TODO!
return true; return true;
} }
void Gfx::CLightning::Draw() void CLightning::Draw()
{ {
GetLogger()->Trace("CLightning::Draw() stub!\n"); GetLogger()->Trace("CLightning::Draw() stub!\n");
// TODO! // TODO!
} }
bool Gfx::CLightning::EventFrame(const Event &event) bool CLightning::EventFrame(const Event &event)
{ {
GetLogger()->Trace("CLightning::EventFrame() stub!\n"); GetLogger()->Trace("CLightning::EventFrame() stub!\n");
// TODO! // TODO!
return true; return true;
} }
CObject* Gfx::CLightning::SearchObject(Math::Vector pos) CObject* CLightning::SearchObject(Math::Vector pos)
{ {
GetLogger()->Trace("CLightning::SearchObject() stub!\n"); GetLogger()->Trace("CLightning::SearchObject() stub!\n");
// TODO! // TODO!
return nullptr; return nullptr;
} }
} // namespace Gfx

View File

@ -17,12 +17,14 @@
/** /**
* \file graphics/engine/lightning.h * \file graphics/engine/lightning.h
* \brief Lightning rendering - Gfx::CLightning class (aka blitz) * \brief Lightning rendering - CLightning class (aka blitz)
*/ */
#pragma once #pragma once
#include "common/event.h" #include "common/event.h"
#include "math/vector.h" #include "math/vector.h"
@ -31,6 +33,7 @@ class CObject;
class CSound; class CSound;
// Graphics module namespace
namespace Gfx { namespace Gfx {
class CEngine; class CEngine;
@ -81,7 +84,7 @@ protected:
float m_sleep; float m_sleep;
float m_delay; float m_delay;
float m_magnetic; float m_magnetic;
Gfx::BlitzPhase m_phase; BlitzPhase m_phase;
float m_time; float m_time;
float m_speed; float m_speed;
float m_progress; float m_progress;
@ -90,4 +93,5 @@ protected:
float m_width[BLITZMAX]; float m_width[BLITZMAX];
}; };
}; // namespace Gfx
} // namespace Gfx

View File

@ -15,7 +15,6 @@
// * You should have received a copy of the GNU General Public License // * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/. // * along with this program. If not, see http://www.gnu.org/licenses/.
// modelfile.cpp (aka modfile.cpp)
#include "graphics/engine/modelfile.h" #include "graphics/engine/modelfile.h"
@ -23,10 +22,13 @@
#include "common/ioutils.h" #include "common/ioutils.h"
#include "common/logger.h" #include "common/logger.h"
#include "common/stringutils.h" #include "common/stringutils.h"
#include "graphics/engine/engine.h" #include "graphics/engine/engine.h"
#include "math/geometry.h" #include "math/geometry.h"
#include <string.h>
#include <cstring>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
@ -39,12 +41,16 @@
*/ */
// Graphics module namespace
namespace Gfx {
//! How big the triangle vector is by default //! How big the triangle vector is by default
const int TRIANGLE_PREALLOCATE_COUNT = 2000; 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.x = IOUtils::ReadBinaryFloat(stream);
vertex.coord.y = IOUtils::ReadBinaryFloat(stream); vertex.coord.y = IOUtils::ReadBinaryFloat(stream);
@ -58,7 +64,7 @@ bool ReadBinaryVertex(std::istream& stream, Gfx::Vertex& vertex)
return !stream.fail(); 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.x, stream);
IOUtils::WriteBinaryFloat(vertex.coord.y, stream); IOUtils::WriteBinaryFloat(vertex.coord.y, stream);
@ -72,7 +78,7 @@ bool WriteBinaryVertex(Gfx::Vertex vertex, std::ostream& stream)
return !stream.fail(); 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.x = IOUtils::ReadBinaryFloat(stream);
vertex.coord.y = IOUtils::ReadBinaryFloat(stream); vertex.coord.y = IOUtils::ReadBinaryFloat(stream);
@ -88,7 +94,7 @@ bool ReadBinaryVertexTex2(std::istream& stream, Gfx::VertexTex2& vertex)
return !stream.fail(); 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.x, stream);
IOUtils::WriteBinaryFloat(vertex.coord.y, stream); IOUtils::WriteBinaryFloat(vertex.coord.y, stream);
@ -104,7 +110,7 @@ bool WriteBinaryVertexTex2(Gfx::VertexTex2 vertex, std::ostream& stream)
return !stream.fail(); return !stream.fail();
} }
bool ReadTextVertexTex2(const std::string& text, Gfx::VertexTex2& vertex) bool ReadTextVertexTex2(const std::string& text, VertexTex2& vertex)
{ {
std::stringstream stream; std::stringstream stream;
stream.str(text); stream.str(text);
@ -138,7 +144,7 @@ bool ReadTextVertexTex2(const std::string& text, Gfx::VertexTex2& vertex)
return !stream.fail(); 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 << "c " << vertex.coord.x << " " << vertex.coord.y << " " << vertex.coord.z;
stream << " n " << vertex.normal.x << " " << vertex.normal.y << " " << vertex.normal.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(); 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.r = IOUtils::ReadBinaryFloat(stream);
material.diffuse.g = IOUtils::ReadBinaryFloat(stream); material.diffuse.g = IOUtils::ReadBinaryFloat(stream);
@ -176,7 +182,7 @@ bool ReadBinaryMaterial(std::istream& stream, Gfx::Material& material)
return !stream.fail(); 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.r, stream);
IOUtils::WriteBinaryFloat(material.diffuse.g, stream); IOUtils::WriteBinaryFloat(material.diffuse.g, stream);
@ -203,7 +209,7 @@ bool WriteBinaryMaterial(const Gfx::Material& material, std::ostream& stream)
return !stream.fail(); return !stream.fail();
} }
bool ReadTextMaterial(const std::string& text, Gfx::Material& material) bool ReadTextMaterial(const std::string& text, Material& material)
{ {
std::stringstream stream; std::stringstream stream;
stream.str(text); stream.str(text);
@ -240,7 +246,7 @@ bool ReadTextMaterial(const std::string& text, Gfx::Material& material)
return !stream.fail(); 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 stream << "dif " << material.diffuse.r
<< " " << material.diffuse.g << " " << 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; m_iMan = iMan;
@ -327,7 +333,7 @@ Gfx::CModelFile::CModelFile(CInstanceManager* iMan)
m_triangles.reserve(TRIANGLE_PREALLOCATE_COUNT); m_triangles.reserve(TRIANGLE_PREALLOCATE_COUNT);
} }
Gfx::CModelFile::~CModelFile() CModelFile::~CModelFile()
{ {
} }
@ -370,10 +376,10 @@ struct OldModelTriangle1
{ {
char used; char used;
char selected; char selected;
Gfx::Vertex p1; Vertex p1;
Gfx::Vertex p2; Vertex p2;
Gfx::Vertex p3; Vertex p3;
Gfx::Material material; Material material;
char texName[20]; char texName[20];
float min; float min;
float max; float max;
@ -394,10 +400,10 @@ struct OldModelTriangle2
{ {
char used; char used;
char selected; char selected;
Gfx::Vertex p1; Vertex p1;
Gfx::Vertex p2; Vertex p2;
Gfx::Vertex p3; Vertex p3;
Gfx::Material material; Material material;
char texName[20]; char texName[20];
float min; float min;
float max; float max;
@ -422,10 +428,10 @@ struct OldModelTriangle3
{ {
char used; char used;
char selected; char selected;
Gfx::VertexTex2 p1; VertexTex2 p1;
Gfx::VertexTex2 p2; VertexTex2 p2;
Gfx::VertexTex2 p3; VertexTex2 p3;
Gfx::Material material; Material material;
char texName[20]; char texName[20];
float min; float min;
float max; 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(); m_triangles.clear();
@ -456,7 +462,7 @@ bool Gfx::CModelFile::ReadModel(const std::string& fileName)
return ReadModel(stream); return ReadModel(stream);
} }
bool Gfx::CModelFile::ReadModel(std::istream& stream) bool CModelFile::ReadModel(std::istream& stream)
{ {
m_triangles.clear(); m_triangles.clear();
@ -501,7 +507,7 @@ bool Gfx::CModelFile::ReadModel(std::istream& stream)
return false; return false;
} }
Gfx::ModelTriangle triangle; ModelTriangle triangle;
triangle.p1.FromVertex(t.p1); triangle.p1.FromVertex(t.p1);
triangle.p2.FromVertex(t.p2); triangle.p2.FromVertex(t.p2);
triangle.p3.FromVertex(t.p3); triangle.p3.FromVertex(t.p3);
@ -545,7 +551,7 @@ bool Gfx::CModelFile::ReadModel(std::istream& stream)
return false; return false;
} }
Gfx::ModelTriangle triangle; ModelTriangle triangle;
triangle.p1.FromVertex(t.p1); triangle.p1.FromVertex(t.p1);
triangle.p2.FromVertex(t.p2); triangle.p2.FromVertex(t.p2);
triangle.p3.FromVertex(t.p3); triangle.p3.FromVertex(t.p3);
@ -590,7 +596,7 @@ bool Gfx::CModelFile::ReadModel(std::istream& stream)
return false; return false;
} }
Gfx::ModelTriangle triangle; ModelTriangle triangle;
triangle.p1 = t.p1; triangle.p1 = t.p1;
triangle.p2 = t.p2; triangle.p2 = t.p2;
triangle.p3 = t.p3; triangle.p3 = t.p3;
@ -603,15 +609,15 @@ bool Gfx::CModelFile::ReadModel(std::istream& stream)
triangle.variableTex2 = t.texNum2 == 1; triangle.variableTex2 = t.texNum2 == 1;
if (triangle.tex1Name == "plant.png") if (triangle.tex1Name == "plant.png")
triangle.state |= Gfx::ENG_RSTATE_ALPHA; triangle.state |= ENG_RSTATE_ALPHA;
if (!triangle.variableTex2 && t.texNum2 != 0) if (!triangle.variableTex2 && t.texNum2 != 0)
{ {
if (t.texNum2 >= 1 && t.texNum2 <= 10) 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) if (t.texNum2 >= 11 && t.texNum2 <= 20)
triangle.state |= Gfx::ENG_RSTATE_DUAL_WHITE; triangle.state |= ENG_RSTATE_DUAL_WHITE;
char tex2Name[20] = { 0 }; char tex2Name[20] = { 0 };
sprintf(tex2Name, "dirty%.2d.png", t.texNum2); // hardcoded as in original code sprintf(tex2Name, "dirty%.2d.png", t.texNum2); // hardcoded as in original code
@ -653,7 +659,7 @@ bool Gfx::CModelFile::ReadModel(std::istream& stream)
return true; return true;
} }
bool Gfx::CModelFile::WriteModel(const std::string& fileName) bool CModelFile::WriteModel(const std::string& fileName)
{ {
std::ofstream stream; std::ofstream stream;
stream.open(fileName.c_str(), std::ios_base::out | std::ios_base::binary); stream.open(fileName.c_str(), std::ios_base::out | std::ios_base::binary);
@ -666,7 +672,7 @@ bool Gfx::CModelFile::WriteModel(const std::string& fileName)
return WriteModel(stream); return WriteModel(stream);
} }
bool Gfx::CModelFile::WriteModel(std::ostream& stream) bool CModelFile::WriteModel(std::ostream& stream)
{ {
if (m_triangles.size() == 0) if (m_triangles.size() == 0)
{ {
@ -767,13 +773,13 @@ struct NewModelHeader
struct NewModelTriangle1 struct NewModelTriangle1
{ {
//! 1st vertex //! 1st vertex
Gfx::VertexTex2 p1; VertexTex2 p1;
//! 2nd vertex //! 2nd vertex
Gfx::VertexTex2 p2; VertexTex2 p2;
//! 3rd vertex //! 3rd vertex
Gfx::VertexTex2 p3; VertexTex2 p3;
//! Material //! Material
Gfx::Material material; Material material;
//! Name of 1st texture //! Name of 1st texture
std::string tex1Name; std::string tex1Name;
//! Name of 2nd texture //! Name of 2nd texture
@ -796,7 +802,7 @@ struct NewModelTriangle1
}; };
bool Gfx::CModelFile::ReadTextModel(const std::string& fileName) bool CModelFile::ReadTextModel(const std::string& fileName)
{ {
std::ifstream stream; std::ifstream stream;
stream.open(fileName.c_str(), std::ios_base::in); stream.open(fileName.c_str(), std::ios_base::in);
@ -809,7 +815,7 @@ bool Gfx::CModelFile::ReadTextModel(const std::string& fileName)
return ReadTextModel(stream); return ReadTextModel(stream);
} }
bool Gfx::CModelFile::ReadTextModel(std::istream& stream) bool CModelFile::ReadTextModel(std::istream& stream)
{ {
m_triangles.clear(); m_triangles.clear();
@ -859,7 +865,7 @@ bool Gfx::CModelFile::ReadTextModel(std::istream& stream)
t.variableTex2 = varTex2Ch == 'Y'; t.variableTex2 = varTex2Ch == 'Y';
Gfx::ModelTriangle triangle; ModelTriangle triangle;
triangle.p1 = t.p1; triangle.p1 = t.p1;
triangle.p2 = t.p2; triangle.p2 = t.p2;
triangle.p3 = t.p3; triangle.p3 = t.p3;
@ -905,7 +911,7 @@ bool Gfx::CModelFile::ReadTextModel(std::istream& stream)
return true; return true;
} }
bool Gfx::CModelFile::WriteTextModel(const std::string &fileName) bool CModelFile::WriteTextModel(const std::string &fileName)
{ {
std::ofstream stream; std::ofstream stream;
stream.open(fileName.c_str(), std::ios_base::out); stream.open(fileName.c_str(), std::ios_base::out);
@ -918,7 +924,7 @@ bool Gfx::CModelFile::WriteTextModel(const std::string &fileName)
return WriteTextModel(stream); return WriteTextModel(stream);
} }
bool Gfx::CModelFile::WriteTextModel(std::ostream& stream) bool CModelFile::WriteTextModel(std::ostream& stream)
{ {
if (m_triangles.size() == 0) if (m_triangles.size() == 0)
{ {
@ -982,7 +988,7 @@ bool Gfx::CModelFile::WriteTextModel(std::ostream& stream)
return true; return true;
} }
bool Gfx::CModelFile::ReadBinaryModel(const std::string& fileName) bool CModelFile::ReadBinaryModel(const std::string& fileName)
{ {
std::ifstream stream; std::ifstream stream;
stream.open(fileName.c_str(), std::ios_base::in | std::ios_base::binary); stream.open(fileName.c_str(), std::ios_base::in | std::ios_base::binary);
@ -995,7 +1001,7 @@ bool Gfx::CModelFile::ReadBinaryModel(const std::string& fileName)
return ReadBinaryModel(stream); return ReadBinaryModel(stream);
} }
bool Gfx::CModelFile::ReadBinaryModel(std::istream& stream) bool CModelFile::ReadBinaryModel(std::istream& stream)
{ {
m_triangles.clear(); m_triangles.clear();
@ -1034,7 +1040,7 @@ bool Gfx::CModelFile::ReadBinaryModel(std::istream& stream)
return false; return false;
} }
Gfx::ModelTriangle triangle; ModelTriangle triangle;
triangle.p1 = t.p1; triangle.p1 = t.p1;
triangle.p2 = t.p2; triangle.p2 = t.p2;
triangle.p3 = t.p3; triangle.p3 = t.p3;
@ -1078,7 +1084,7 @@ bool Gfx::CModelFile::ReadBinaryModel(std::istream& stream)
return true; return true;
} }
bool Gfx::CModelFile::WriteBinaryModel(const std::string& fileName) bool CModelFile::WriteBinaryModel(const std::string& fileName)
{ {
std::ofstream stream; std::ofstream stream;
stream.open(fileName.c_str(), std::ios_base::out | std::ios_base::binary); stream.open(fileName.c_str(), std::ios_base::out | std::ios_base::binary);
@ -1091,7 +1097,7 @@ bool Gfx::CModelFile::WriteBinaryModel(const std::string& fileName)
return WriteBinaryModel(stream); return WriteBinaryModel(stream);
} }
bool Gfx::CModelFile::WriteBinaryModel(std::ostream& stream) bool CModelFile::WriteBinaryModel(std::ostream& stream)
{ {
if (m_triangles.size() == 0) if (m_triangles.size() == 0)
{ {
@ -1150,9 +1156,9 @@ bool Gfx::CModelFile::WriteBinaryModel(std::ostream& stream)
#ifndef MODELFILE_NO_ENGINE #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]; float limit[2];
limit[0] = m_engine->GetLimitLOD(0); // frontier AB as config limit[0] = m_engine->GetLimitLOD(0); // frontier AB as config
@ -1188,10 +1194,10 @@ bool Gfx::CModelFile::CreateEngineObject(int objRank)
int texNum = m_engine->GetSecondTexture(); int texNum = m_engine->GetSecondTexture();
if (texNum >= 1 && texNum <= 10) if (texNum >= 1 && texNum <= 10)
state |= Gfx::ENG_RSTATE_DUAL_BLACK; state |= ENG_RSTATE_DUAL_BLACK;
if (texNum >= 11 && texNum <= 20) if (texNum >= 11 && texNum <= 20)
state |= Gfx::ENG_RSTATE_DUAL_WHITE; state |= ENG_RSTATE_DUAL_WHITE;
char name[20] = { 0 }; char name[20] = { 0 };
sprintf(name, "dirty%.2d.png", texNum); sprintf(name, "dirty%.2d.png", texNum);
@ -1217,11 +1223,11 @@ bool Gfx::CModelFile::CreateEngineObject(int objRank)
#endif #endif
void Gfx::CModelFile::Mirror() void CModelFile::Mirror()
{ {
for (int i = 0; i < static_cast<int>( m_triangles.size() ); i++) 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].p1 = m_triangles[i].p2;
m_triangles[i].p2 = t; m_triangles[i].p2 = t;
@ -1235,17 +1241,17 @@ void Gfx::CModelFile::Mirror()
} }
} }
const std::vector<Gfx::ModelTriangle>& Gfx::CModelFile::GetTriangles() const std::vector<ModelTriangle>& CModelFile::GetTriangles()
{ {
return m_triangles; return m_triangles;
} }
int Gfx::CModelFile::GetTriangleCount() int CModelFile::GetTriangleCount()
{ {
return m_triangles.size(); return m_triangles.size();
} }
float Gfx::CModelFile::GetHeight(Math::Vector pos) float CModelFile::GetHeight(Math::Vector pos)
{ {
float limit = 5.0f; float limit = 5.0f;
@ -1267,20 +1273,23 @@ float Gfx::CModelFile::GetHeight(Math::Vector pos)
return 0.0f; 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); Math::Vector n = Math::NormalToPlane(p3, p2, p1);
triangle.p1 = Gfx::VertexTex2(p1, n); triangle.p1 = VertexTex2(p1, n);
triangle.p2 = Gfx::VertexTex2(p2, n); triangle.p2 = VertexTex2(p2, n);
triangle.p3 = Gfx::VertexTex2(p3, n); triangle.p3 = VertexTex2(p3, n);
triangle.material.diffuse = Gfx::Color(1.0f, 1.0f, 1.0f, 0.0f); triangle.material.diffuse = Color(1.0f, 1.0f, 1.0f, 0.0f);
triangle.material.ambient = Gfx::Color(0.5f, 0.5f, 0.5f, 0.0f); triangle.material.ambient = Color(0.5f, 0.5f, 0.5f, 0.0f);
triangle.min = min; triangle.min = min;
triangle.max = max; triangle.max = max;
m_triangles.push_back(triangle); m_triangles.push_back(triangle);
} }
} // namespace Gfx

View File

@ -17,11 +17,15 @@
/** /**
* \file graphics/engine/modelfile.h * \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/vertex.h"
#include "graphics/core/material.h" #include "graphics/core/material.h"
#include "math/vector.h" #include "math/vector.h"
#include <string> #include <string>
@ -32,6 +36,7 @@
class CInstanceManager; class CInstanceManager;
// Graphics module namespace
namespace Gfx { namespace Gfx {
class CEngine; class CEngine;
@ -44,13 +49,13 @@ class CEngine;
struct ModelTriangle struct ModelTriangle
{ {
//! 1st vertex //! 1st vertex
Gfx::VertexTex2 p1; VertexTex2 p1;
//! 2nd vertex //! 2nd vertex
Gfx::VertexTex2 p2; VertexTex2 p2;
//! 3rd vertex //! 3rd vertex
Gfx::VertexTex2 p3; VertexTex2 p3;
//! Material //! Material
Gfx::Material material; Material material;
//! Name of 1st texture //! Name of 1st texture
std::string tex1Name; std::string tex1Name;
//! Name of 2nd texture //! Name of 2nd texture
@ -121,7 +126,7 @@ public:
int GetTriangleCount(); int GetTriangleCount();
//! Returns the triangle vector //! 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 //! Returns the height of model -- closest point to X and Z coords of \a pos
float GetHeight(Math::Vector pos); float GetHeight(Math::Vector pos);
@ -138,10 +143,10 @@ protected:
protected: protected:
CInstanceManager* m_iMan; CInstanceManager* m_iMan;
Gfx::CEngine* m_engine; CEngine* m_engine;
//! Model triangles //! Model triangles
std::vector<Gfx::ModelTriangle> m_triangles; std::vector<ModelTriangle> m_triangles;
}; };
}; // namespace Gfx }; // namespace Gfx

View File

@ -15,45 +15,48 @@
// * You should have received a copy of the GNU General Public License // * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/. // * along with this program. If not, see http://www.gnu.org/licenses/.
// particle.cpp (aka particule.cpp)
#include "graphics/engine/particle.h" #include "graphics/engine/particle.h"
#include "common/logger.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"); GetLogger()->Trace("CParticle::CParticle() stub!\n");
// TODO! // TODO!
} }
Gfx::CParticle::~CParticle() CParticle::~CParticle()
{ {
GetLogger()->Trace("CParticle::~CParticle() stub!\n"); GetLogger()->Trace("CParticle::~CParticle() stub!\n");
// TODO! // TODO!
} }
void Gfx::CParticle::SetDevice(Gfx::CDevice* device) void CParticle::SetDevice(CDevice* device)
{ {
GetLogger()->Trace("CParticle::SetDevice() stub!\n"); GetLogger()->Trace("CParticle::SetDevice() stub!\n");
// TODO! // TODO!
} }
void Gfx::CParticle::FlushParticle() void CParticle::FlushParticle()
{ {
GetLogger()->Trace("CParticle::FlushParticle() stub!\n"); GetLogger()->Trace("CParticle::FlushParticle() stub!\n");
// TODO! // TODO!
} }
void Gfx::CParticle::FlushParticle(int sheet) void CParticle::FlushParticle(int sheet)
{ {
GetLogger()->Trace("CParticle::FlushParticle() stub!\n"); GetLogger()->Trace("CParticle::FlushParticle() stub!\n");
// TODO! // TODO!
} }
int Gfx::CParticle::CreateParticle(Math::Vector pos, Math::Vector speed, Math::Point dim, int CParticle::CreateParticle(Math::Vector pos, Math::Vector speed, Math::Point dim,
Gfx::ParticleType type, float duration, float mass, ParticleType type, float duration, float mass,
float windSensitivity, int sheet) float windSensitivity, int sheet)
{ {
GetLogger()->Trace("CParticle::CreateParticle() stub!\n"); GetLogger()->Trace("CParticle::CreateParticle() stub!\n");
@ -61,8 +64,8 @@ int Gfx::CParticle::CreateParticle(Math::Vector pos, Math::Vector speed, Math::P
return 0; return 0;
} }
int Gfx::CParticle::CreateFrag(Math::Vector pos, Math::Vector speed, Gfx::EngineTriangle *triangle, int CParticle::CreateFrag(Math::Vector pos, Math::Vector speed, EngineTriangle *triangle,
Gfx::ParticleType type, float duration, float mass, ParticleType type, float duration, float mass,
float windSensitivity, int sheet) float windSensitivity, int sheet)
{ {
GetLogger()->Trace("CParticle::CreateFrag() stub!\n"); GetLogger()->Trace("CParticle::CreateFrag() stub!\n");
@ -70,7 +73,7 @@ int Gfx::CParticle::CreateFrag(Math::Vector pos, Math::Vector speed, Gfx::Engine
return 0; 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 duration, float mass, float weight,
float windSensitivity, int sheet) float windSensitivity, int sheet)
{ {
@ -79,7 +82,7 @@ int Gfx::CParticle::CreatePart(Math::Vector pos, Math::Vector speed, Gfx::Partic
return 0; 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) float duration, int sheet)
{ {
GetLogger()->Trace("CParticle::CreateRay() stub!\n"); GetLogger()->Trace("CParticle::CreateRay() stub!\n");
@ -87,7 +90,7 @@ int Gfx::CParticle::CreateRay(Math::Vector pos, Math::Vector goal, Gfx::Particle
return 0; 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) float duration, float mass, float length, float width)
{ {
GetLogger()->Trace("CParticle::CreateTrack() stub!\n"); GetLogger()->Trace("CParticle::CreateTrack() stub!\n");
@ -95,208 +98,211 @@ int Gfx::CParticle::CreateTrack(Math::Vector pos, Math::Vector speed, Math::Poin
return 0; return 0;
} }
void Gfx::CParticle::CreateWheelTrace(const Math::Vector &p1, const Math::Vector &p2, const Math::Vector &p3, void CParticle::CreateWheelTrace(const Math::Vector &p1, const Math::Vector &p2, const Math::Vector &p3,
const Math::Vector &p4, Gfx::ParticleType type) const Math::Vector &p4, ParticleType type)
{ {
GetLogger()->Trace("CParticle::CreateWheelTrace() stub!\n"); GetLogger()->Trace("CParticle::CreateWheelTrace() stub!\n");
// TODO! // TODO!
} }
void Gfx::CParticle::DeleteParticle(Gfx::ParticleType type) void CParticle::DeleteParticle(ParticleType type)
{ {
GetLogger()->Trace("CParticle::DeleteParticle() stub!\n"); GetLogger()->Trace("CParticle::DeleteParticle() stub!\n");
// TODO! // TODO!
} }
void Gfx::CParticle::DeleteParticle(int channel) void CParticle::DeleteParticle(int channel)
{ {
GetLogger()->Trace("CParticle::DeleteParticle() stub!\n"); GetLogger()->Trace("CParticle::DeleteParticle() stub!\n");
// TODO! // TODO!
} }
void Gfx::CParticle::SetObjectLink(int channel, CObject *object) void CParticle::SetObjectLink(int channel, CObject *object)
{ {
GetLogger()->Trace("CParticle::SetObjectLink() stub!\n"); GetLogger()->Trace("CParticle::SetObjectLink() stub!\n");
// TODO! // TODO!
} }
void Gfx::CParticle::SetObjectFather(int channel, CObject *object) void CParticle::SetObjectFather(int channel, CObject *object)
{ {
GetLogger()->Trace("CParticle::SetObjectFather() stub!\n"); GetLogger()->Trace("CParticle::SetObjectFather() stub!\n");
// TODO! // TODO!
} }
void Gfx::CParticle::SetPosition(int channel, Math::Vector pos) void CParticle::SetPosition(int channel, Math::Vector pos)
{ {
GetLogger()->Trace("CParticle::SetPosition() stub!\n"); GetLogger()->Trace("CParticle::SetPosition() stub!\n");
// TODO! // TODO!
} }
void Gfx::CParticle::SetDimension(int channel, Math::Point dim) void CParticle::SetDimension(int channel, Math::Point dim)
{ {
GetLogger()->Trace("CParticle::SetDimension() stub!\n"); GetLogger()->Trace("CParticle::SetDimension() stub!\n");
// TODO! // TODO!
} }
void Gfx::CParticle::SetZoom(int channel, float zoom) void CParticle::SetZoom(int channel, float zoom)
{ {
GetLogger()->Trace("CParticle::SetZoom() stub!\n"); GetLogger()->Trace("CParticle::SetZoom() stub!\n");
// TODO! // TODO!
} }
void Gfx::CParticle::SetAngle(int channel, float angle) void CParticle::SetAngle(int channel, float angle)
{ {
GetLogger()->Trace("CParticle::SetAngle() stub!\n"); GetLogger()->Trace("CParticle::SetAngle() stub!\n");
// TODO! // TODO!
} }
void Gfx::CParticle::SetIntensity(int channel, float intensity) void CParticle::SetIntensity(int channel, float intensity)
{ {
GetLogger()->Trace("CParticle::SetIntensity() stub!\n"); GetLogger()->Trace("CParticle::SetIntensity() stub!\n");
// TODO! // 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"); GetLogger()->Trace("CParticle::SetParam() stub!\n");
// TODO! // 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"); GetLogger()->Trace("CParticle::SetPhase() stub!\n");
// TODO! // TODO!
} }
bool Gfx::CParticle::GetPosition(int channel, Math::Vector &pos) bool CParticle::GetPosition(int channel, Math::Vector &pos)
{ {
GetLogger()->Trace("CParticle::GetPosition() stub!\n"); GetLogger()->Trace("CParticle::GetPosition() stub!\n");
// TODO! // TODO!
return true; return true;
} }
Gfx::Color Gfx::CParticle::GetFogColor(Math::Vector pos) Color CParticle::GetFogColor(Math::Vector pos)
{ {
GetLogger()->Trace("CParticle::GetFogColor() stub!\n"); GetLogger()->Trace("CParticle::GetFogColor() stub!\n");
// TODO! // 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"); GetLogger()->Trace("CParticle::SetFrameUpdate() stub!\n");
// TODO! // TODO!
} }
void Gfx::CParticle::FrameParticle(float rTime) void CParticle::FrameParticle(float rTime)
{ {
GetLogger()->Trace("CParticle::FrameParticle() stub!\n"); GetLogger()->Trace("CParticle::FrameParticle() stub!\n");
// TODO! // TODO!
} }
void Gfx::CParticle::DrawParticle(int sheet) void CParticle::DrawParticle(int sheet)
{ {
GetLogger()->Trace("CParticle::DrawParticle() stub!\n"); GetLogger()->Trace("CParticle::DrawParticle() stub!\n");
// TODO! // 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"); GetLogger()->Trace("CParticle::WriteWheelTrace() stub!\n");
// TODO! // TODO!
return true; return true;
} }
void Gfx::CParticle::DeleteRank(int rank) void CParticle::DeleteRank(int rank)
{ {
GetLogger()->Trace("CParticle::DeleteRank() stub!\n"); GetLogger()->Trace("CParticle::DeleteRank() stub!\n");
// TODO! // TODO!
} }
bool Gfx::CParticle::CheckChannel(int &channel) bool CParticle::CheckChannel(int &channel)
{ {
GetLogger()->Trace("CParticle::CheckChannel() stub!\n"); GetLogger()->Trace("CParticle::CheckChannel() stub!\n");
// TODO! // TODO!
return true; return true;
} }
void Gfx::CParticle::DrawParticleTriangle(int i) void CParticle::DrawParticleTriangle(int i)
{ {
GetLogger()->Trace("CParticle::DrawParticleTriangle() stub!\n"); GetLogger()->Trace("CParticle::DrawParticleTriangle() stub!\n");
// TODO! // TODO!
} }
void Gfx::CParticle::DrawParticleNorm(int i) void CParticle::DrawParticleNorm(int i)
{ {
GetLogger()->Trace("CParticle::DrawParticleNorm() stub!\n"); GetLogger()->Trace("CParticle::DrawParticleNorm() stub!\n");
// TODO! // TODO!
} }
void Gfx::CParticle::DrawParticleFlat(int i) void CParticle::DrawParticleFlat(int i)
{ {
GetLogger()->Trace("CParticle::DrawParticleFlat() stub!\n"); GetLogger()->Trace("CParticle::DrawParticleFlat() stub!\n");
// TODO! // TODO!
} }
void Gfx::CParticle::DrawParticleFog(int i) void CParticle::DrawParticleFog(int i)
{ {
GetLogger()->Trace("CParticle::DrawParticleFog() stub!\n"); GetLogger()->Trace("CParticle::DrawParticleFog() stub!\n");
// TODO! // TODO!
} }
void Gfx::CParticle::DrawParticleRay(int i) void CParticle::DrawParticleRay(int i)
{ {
GetLogger()->Trace("CParticle::DrawParticleRay() stub!\n"); GetLogger()->Trace("CParticle::DrawParticleRay() stub!\n");
// TODO! // TODO!
} }
void Gfx::CParticle::DrawParticleSphere(int i) void CParticle::DrawParticleSphere(int i)
{ {
GetLogger()->Trace("CParticle::DrawParticleSphere() stub!\n"); GetLogger()->Trace("CParticle::DrawParticleSphere() stub!\n");
// TODO! // TODO!
} }
void Gfx::CParticle::DrawParticleCylinder(int i) void CParticle::DrawParticleCylinder(int i)
{ {
GetLogger()->Trace("CParticle::DrawParticleCylinder() stub!\n"); GetLogger()->Trace("CParticle::DrawParticleCylinder() stub!\n");
// TODO! // TODO!
} }
void Gfx::CParticle::DrawParticleWheel(int i) void CParticle::DrawParticleWheel(int i)
{ {
GetLogger()->Trace("CParticle::DrawParticleWheel() stub!\n"); GetLogger()->Trace("CParticle::DrawParticleWheel() stub!\n");
// TODO! // 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"); GetLogger()->Trace("CParticle::SearchObjectGun() stub!\n");
// TODO! // TODO!
return nullptr; 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"); GetLogger()->Trace("CParticle::SearchObjectRay() stub!\n");
// TODO! // TODO!
return nullptr; 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"); GetLogger()->Trace("CParticle::Play() stub!\n");
// TODO! // 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"); GetLogger()->Trace("CParticle::TrackMove() stub!\n");
// TODO! // TODO!
return true; return true;
} }
void Gfx::CParticle::TrackDraw(int i, Gfx::ParticleType type) void CParticle::TrackDraw(int i, ParticleType type)
{ {
GetLogger()->Trace("CParticle::TrackDraw() stub!\n"); GetLogger()->Trace("CParticle::TrackDraw() stub!\n");
// TODO! // TODO!
} }
} // namespace Gfx

View File

@ -17,22 +17,24 @@
/** /**
* \file graphics/engine/particle.h * \file graphics/engine/particle.h
* \brief Particle rendering - Gfx::CParticle class (aka particule) * \brief Particle rendering - CParticle class (aka particule)
*/ */
#pragma once #pragma once
#include "engine.h" #include "engine.h"
#include "sound/sound.h" #include "sound/sound.h"
class CInstanceManager; class CInstanceManager;
class CRobotMain; class CRobotMain;
class CObject; class CObject;
class CSound; class CSoundInterface;
// Graphics module namespace
namespace Gfx { namespace Gfx {
const short MAXPARTICULE = 500; const short MAXPARTICULE = 500;
@ -265,29 +267,29 @@ struct WheelTrace
class CParticle class CParticle
{ {
public: public:
CParticle(CInstanceManager* iMan, Gfx::CEngine* engine); CParticle(CInstanceManager* iMan, CEngine* engine);
~CParticle(); ~CParticle();
void SetDevice(Gfx::CDevice* device); void SetDevice(CDevice* device);
void FlushParticle(); void FlushParticle();
void FlushParticle(int sheet); void FlushParticle(int sheet);
int CreateParticle(Math::Vector pos, Math::Vector speed, Math::Point dim, 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); float windSensitivity=1.0f, int sheet=0);
int CreateFrag(Math::Vector pos, Math::Vector speed, Gfx::EngineTriangle *triangle, int CreateFrag(Math::Vector pos, Math::Vector speed, EngineTriangle *triangle,
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); 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 duration=1.0f, float mass=0.0f, float weight=0.0f,
float windSensitivity=1.0f, int sheet=0); 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); 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); 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, void CreateWheelTrace(const Math::Vector &p1, const Math::Vector &p2, const Math::Vector &p3,
const Math::Vector &p4, Gfx::ParticleType type); const Math::Vector &p4, ParticleType type);
void DeleteParticle(Gfx::ParticleType type); void DeleteParticle(ParticleType type);
void DeleteParticle(int channel); void DeleteParticle(int channel);
void SetObjectLink(int channel, CObject *object); void SetObjectLink(int channel, CObject *object);
void SetObjectFather(int channel, CObject *object); void SetObjectFather(int channel, CObject *object);
@ -297,10 +299,10 @@ public:
void SetAngle(int channel, float angle); void SetAngle(int channel, float angle);
void SetIntensity(int channel, float intensity); void SetIntensity(int channel, float intensity);
void SetParam(int channel, Math::Vector pos, Math::Point dim, float zoom, float angle, 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); 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 SetFrameUpdate(int sheet, bool update);
void FrameParticle(float rTime); void FrameParticle(float rTime);
@ -319,27 +321,27 @@ protected:
void DrawParticleSphere(int i); void DrawParticleSphere(int i);
void DrawParticleCylinder(int i); void DrawParticleCylinder(int i);
void DrawParticleWheel(int i); void DrawParticleWheel(int i);
CObject* SearchObjectGun(Math::Vector old, Math::Vector pos, 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, Gfx::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); void Play(Sound sound, Math::Vector pos, float amplitude);
bool TrackMove(int i, Math::Vector pos, float progress); bool TrackMove(int i, Math::Vector pos, float progress);
void TrackDraw(int i, Gfx::ParticleType type); void TrackDraw(int i, ParticleType type);
protected: protected:
CInstanceManager* m_iMan; CInstanceManager* m_iMan;
Gfx::CEngine* m_engine; CEngine* m_engine;
Gfx::CDevice* m_device; CDevice* m_device;
Gfx::CTerrain* m_terrain; CTerrain* m_terrain;
Gfx::CWater* m_water; CWater* m_water;
CRobotMain* m_main; CRobotMain* m_main;
CSound* m_sound; CSoundInterface* m_sound;
Gfx::Particle m_particule[MAXPARTICULE*MAXPARTITYPE]; Particle m_particule[MAXPARTICULE*MAXPARTITYPE];
Gfx::EngineTriangle m_triangle[MAXPARTICULE]; // triangle if PartiType == 0 EngineTriangle m_triangle[MAXPARTICULE]; // triangle if PartiType == 0
Gfx::Track m_track[MAXTRACK]; Track m_track[MAXTRACK];
int m_wheelTraceTotal; int m_wheelTraceTotal;
int m_wheelTraceIndex; int m_wheelTraceIndex;
Gfx::WheelTrace m_wheelTrace[MAXWHEELTRACE]; WheelTrace m_wheelTrace[MAXWHEELTRACE];
int m_totalInterface[MAXPARTITYPE][SH_MAX]; int m_totalInterface[MAXPARTITYPE][SH_MAX];
bool m_frameUpdate[SH_MAX]; bool m_frameUpdate[SH_MAX];
int m_fogTotal; int m_fogTotal;
@ -351,4 +353,4 @@ protected:
}; };
}; // namespace Gfx } // namespace Gfx

View File

@ -15,19 +15,23 @@
// * You should have received a copy of the GNU General Public License // * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/. // * along with this program. If not, see http://www.gnu.org/licenses/.
// planet.cpp
#include "graphics/engine/planet.h" #include "graphics/engine/planet.h"
#include "common/iman.h" #include "common/iman.h"
#include "graphics/core/device.h" #include "graphics/core/device.h"
#include "graphics/engine/engine.h" #include "graphics/engine/engine.h"
// Graphics module namespace
namespace Gfx {
const int PLANET_PREALLOCATE_COUNT = 10; 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 = iMan;
m_iMan->AddInstance(CLASS_PLANET, this); 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; m_iMan = nullptr;
} }
void Gfx::CPlanet::Flush() void CPlanet::Flush()
{ {
for (int j = 0; j < 2; j++) for (int j = 0; j < 2; j++)
m_planet[j].clear(); m_planet[j].clear();
@ -55,7 +59,7 @@ void Gfx::CPlanet::Flush()
m_time = 0.0f; m_time = 0.0f;
} }
bool Gfx::CPlanet::EventProcess(const Event &event) bool CPlanet::EventProcess(const Event &event)
{ {
if (event.type == EVENT_FRAME) if (event.type == EVENT_FRAME)
return EventFrame(event); return EventFrame(event);
@ -63,7 +67,7 @@ bool Gfx::CPlanet::EventProcess(const Event &event)
return true; return true;
} }
bool Gfx::CPlanet::EventFrame(const Event &event) bool CPlanet::EventFrame(const Event &event)
{ {
if (m_engine->GetPause()) return true; if (m_engine->GetPause()) return true;
@ -82,7 +86,7 @@ bool Gfx::CPlanet::EventFrame(const Event &event)
return true; return true;
} }
void Gfx::CPlanet::LoadTexture() void CPlanet::LoadTexture()
{ {
for (int j = 0; j < 2; j++) 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 eyeDirH = m_engine->GetEyeDirH();
float eyeDirV = m_engine->GetEyeDirV(); float eyeDirV = m_engine->GetEyeDirV();
@ -107,9 +111,9 @@ void Gfx::CPlanet::Draw()
m_engine->SetTexture(m_planet[m_mode][i].name); m_engine->SetTexture(m_planet[m_mode][i].name);
if (m_planet[m_mode][i].transparent) 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 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; Math::Point p1, p2;
@ -129,26 +133,26 @@ void Gfx::CPlanet::Draw()
float u2 = m_planet[m_mode][i].uv2.x - dp; float u2 = m_planet[m_mode][i].uv2.x - dp;
float v2 = m_planet[m_mode][i].uv2.y - 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)), 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)), 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)), 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(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); 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) float dir, const std::string& name, Math::Point uv1, Math::Point uv2)
{ {
if (mode < 0) mode = 0; if (mode < 0) mode = 0;
if (mode > 1) mode = 1; if (mode > 1) mode = 1;
Gfx::Planet planet; Planet planet;
planet.start = start; planet.start = start;
planet.angle = start; planet.angle = start;
@ -167,19 +171,22 @@ void Gfx::CPlanet::Create(int mode, Math::Point start, float dim, float speed,
m_planetExist = true; m_planetExist = true;
} }
bool Gfx::CPlanet::PlanetExist() bool CPlanet::PlanetExist()
{ {
return m_planetExist; return m_planetExist;
} }
void Gfx::CPlanet::SetMode(int mode) void CPlanet::SetMode(int mode)
{ {
if (mode < 0) mode = 0; if (mode < 0) mode = 0;
if (mode > 1) mode = 1; if (mode > 1) mode = 1;
m_mode = mode; m_mode = mode;
} }
int Gfx::CPlanet::GetMode() int CPlanet::GetMode()
{ {
return m_mode; return m_mode;
} }
} // namespace Gfx

View File

@ -17,12 +17,14 @@
/** /**
* \file graphics/engine/planet.h * \file graphics/engine/planet.h
* \brief Planet rendering - Gfx::CPlanet class * \brief Planet rendering - CPlanet class
*/ */
#pragma once #pragma once
#include "common/event.h" #include "common/event.h"
#include "math/point.h" #include "math/point.h"
#include <vector> #include <vector>
@ -31,6 +33,7 @@
class CInstanceManager; class CInstanceManager;
// Graphics module namespace
namespace Gfx { namespace Gfx {
class CEngine; class CEngine;
@ -79,7 +82,7 @@ struct Planet
class CPlanet class CPlanet
{ {
public: public:
CPlanet(CInstanceManager* iMan, Gfx::CEngine* engine); CPlanet(CInstanceManager* iMan, CEngine* engine);
~CPlanet(); ~CPlanet();
//! Removes all the planets //! Removes all the planets
@ -107,12 +110,13 @@ protected:
protected: protected:
CInstanceManager* m_iMan; CInstanceManager* m_iMan;
Gfx::CEngine* m_engine; CEngine* m_engine;
float m_time; float m_time;
int m_mode; int m_mode;
std::vector<Gfx::Planet> m_planet[2]; std::vector<Planet> m_planet[2];
bool m_planetExist; bool m_planetExist;
}; };
}; // namespace Gfx
} // namespace Gfx

View File

@ -15,165 +15,171 @@
// * You should have received a copy of the GNU General Public License // * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/. // * along with this program. If not, see http://www.gnu.org/licenses/.
// pyro.cpp
#include "graphics/engine/pyro.h" #include "graphics/engine/pyro.h"
#include "common/logger.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"); GetLogger()->Trace("CParticle::CPyro() stub!\n");
// TODO! // TODO!
} }
Gfx::CPyro::~CPyro() CPyro::~CPyro()
{ {
GetLogger()->Trace("CPyro::~CPyro() stub!"); GetLogger()->Trace("CPyro::~CPyro() stub!");
// TODO! // TODO!
} }
void Gfx::CPyro::DeleteObject(bool all) void CPyro::DeleteObject(bool all)
{ {
GetLogger()->Trace("CPyro::DeleteObject() stub!"); GetLogger()->Trace("CPyro::DeleteObject() stub!");
// TODO! // 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!"); GetLogger()->Trace("CPyro::Create() stub!");
// TODO! // TODO!
return true; return true;
} }
bool Gfx::CPyro::EventProcess(const Event &event) bool CPyro::EventProcess(const Event &event)
{ {
GetLogger()->Trace("CPyro::EventProcess() stub!\n"); GetLogger()->Trace("CPyro::EventProcess() stub!\n");
// TODO! // TODO!
return true; return true;
} }
Error Gfx::CPyro::IsEnded() Error CPyro::IsEnded()
{ {
GetLogger()->Trace("CPyro::IsEnded() stub!\n"); GetLogger()->Trace("CPyro::IsEnded() stub!\n");
// TODO! // TODO!
return ERR_OK; return ERR_OK;
} }
void Gfx::CPyro::CutObjectLink(CObject* pObj) void CPyro::CutObjectLink(CObject* pObj)
{ {
GetLogger()->Trace("CPyro::CutObjectLink() stub!\n"); GetLogger()->Trace("CPyro::CutObjectLink() stub!\n");
// TODO! // TODO!
} }
void Gfx::CPyro::DisplayError(PyroType type, CObject* pObj) void CPyro::DisplayError(PyroType type, CObject* pObj)
{ {
GetLogger()->Trace("CPyro::DisplayError() stub!\n"); GetLogger()->Trace("CPyro::DisplayError() stub!\n");
// TODO! // TODO!
} }
bool Gfx::CPyro::CreateLight(Math::Vector pos, float height) bool CPyro::CreateLight(Math::Vector pos, float height)
{ {
GetLogger()->Trace("CPyro::CreateLight() stub!\n"); GetLogger()->Trace("CPyro::CreateLight() stub!\n");
// TODO! // TODO!
return true; return true;
} }
void Gfx::CPyro::DeleteObject(bool primary, bool secondary) void CPyro::DeleteObject(bool primary, bool secondary)
{ {
GetLogger()->Trace("CPyro::DeleteObject() stub!\n"); GetLogger()->Trace("CPyro::DeleteObject() stub!\n");
// TODO! // 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"); GetLogger()->Trace("CPyro::CreateTriangle() stub!\n");
// TODO! // TODO!
} }
void Gfx::CPyro::ExploStart() void CPyro::ExploStart()
{ {
GetLogger()->Trace("CPyro::ExploStart() stub!\n"); GetLogger()->Trace("CPyro::ExploStart() stub!\n");
// TODO! // TODO!
} }
void Gfx::CPyro::ExploTerminate() void CPyro::ExploTerminate()
{ {
GetLogger()->Trace("CPyro::ExploTerminate() stub!\n"); GetLogger()->Trace("CPyro::ExploTerminate() stub!\n");
// TODO! // TODO!
} }
void Gfx::CPyro::BurnStart() void CPyro::BurnStart()
{ {
GetLogger()->Trace("CPyro::BurnStart() stub!\n"); GetLogger()->Trace("CPyro::BurnStart() stub!\n");
// TODO! // 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"); GetLogger()->Trace("CPyro::BurnAddPart() stub!\n");
// TODO! // TODO!
} }
void Gfx::CPyro::BurnProgress() void CPyro::BurnProgress()
{ {
GetLogger()->Trace("CPyro::BurnProgress() stub!\n"); GetLogger()->Trace("CPyro::BurnProgress() stub!\n");
// TODO! // TODO!
} }
bool Gfx::CPyro::BurnIsKeepPart(int part) bool CPyro::BurnIsKeepPart(int part)
{ {
GetLogger()->Trace("CPyro::BurnIsKeepPart() stub!\n"); GetLogger()->Trace("CPyro::BurnIsKeepPart() stub!\n");
// TODO! // TODO!
return true; return true;
} }
void Gfx::CPyro::BurnTerminate() void CPyro::BurnTerminate()
{ {
GetLogger()->Trace("CPyro::BurnTerminate() stub!\n"); GetLogger()->Trace("CPyro::BurnTerminate() stub!\n");
// TODO! // TODO!
} }
void Gfx::CPyro::FallStart() void CPyro::FallStart()
{ {
GetLogger()->Trace("CPyro::FallStart() stub!\n"); GetLogger()->Trace("CPyro::FallStart() stub!\n");
// TODO! // TODO!
} }
CObject* Gfx::CPyro::FallSearchBeeExplo() CObject* CPyro::FallSearchBeeExplo()
{ {
GetLogger()->Trace("CPyro::FallSearchBeeExplo() stub!\n"); GetLogger()->Trace("CPyro::FallSearchBeeExplo() stub!\n");
// TODO! // TODO!
return nullptr; return nullptr;
} }
void Gfx::CPyro::FallProgress(float rTime) void CPyro::FallProgress(float rTime)
{ {
GetLogger()->Trace("CPyro::FallProgress() stub!\n"); GetLogger()->Trace("CPyro::FallProgress() stub!\n");
// TODO! // TODO!
} }
Error Gfx::CPyro::FallIsEnded() Error CPyro::FallIsEnded()
{ {
GetLogger()->Trace("CPyro::FallIsEnded() stub!\n"); GetLogger()->Trace("CPyro::FallIsEnded() stub!\n");
// TODO! // TODO!
return ERR_OK; return ERR_OK;
} }
void Gfx::CPyro::LightOperFlush() void CPyro::LightOperFlush()
{ {
GetLogger()->Trace("CPyro::LightOperFlush() stub!\n"); GetLogger()->Trace("CPyro::LightOperFlush() stub!\n");
// TODO! // 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"); GetLogger()->Trace("CPyro::LightOperAdd() stub!\n");
// TODO! // TODO!
} }
void Gfx::CPyro::LightOperFrame(float rTime) void CPyro::LightOperFrame(float rTime)
{ {
GetLogger()->Trace("CPyro::LightOperFrame() stub!\n"); GetLogger()->Trace("CPyro::LightOperFrame() stub!\n");
// TODO! // TODO!
} }
} // namespace Gfx

View File

@ -17,14 +17,17 @@
/** /**
* \file graphics/engine/pyro.h * \file graphics/engine/pyro.h
* \brief Fire effect rendering - Gfx::CPyro class * \brief Fire effect rendering - CPyro class
*/ */
#pragma once #pragma once
#include "common/event.h" #include "common/event.h"
#include "common/global.h" #include "common/global.h"
#include "graphics/engine/engine.h" #include "graphics/engine/engine.h"
#include "object/object.h" #include "object/object.h"
@ -32,9 +35,10 @@ class CInstanceManager;
class CObject; class CObject;
class CDisplayText; class CDisplayText;
class CRobotMain; class CRobotMain;
class CSound; class CSoundInterface;
// Graphics module namespace
namespace Gfx { namespace Gfx {
class CEngine; class CEngine;
@ -87,7 +91,7 @@ struct PyroLightOper
{ {
float progress; float progress;
float intensity; float intensity;
Gfx::Color color; Color color;
}; };
@ -104,7 +108,7 @@ public:
~CPyro(); ~CPyro();
void DeleteObject(bool all=false); 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); bool EventProcess(const Event &event);
Error IsEnded(); Error IsEnded();
void CutObjectLink(CObject* pObj); void CutObjectLink(CObject* pObj);
@ -136,20 +140,20 @@ protected:
protected: protected:
CInstanceManager* m_iMan; CInstanceManager* m_iMan;
Gfx::CEngine* m_engine; CEngine* m_engine;
Gfx::CTerrain* m_terrain; CTerrain* m_terrain;
Gfx::CCamera* m_camera; CCamera* m_camera;
Gfx::CParticle* m_particule; CParticle* m_particule;
Gfx::CLightManager* m_lightMan; CLightManager* m_lightMan;
CObject* m_object; CObject* m_object;
CDisplayText* m_displayText; CDisplayText* m_displayText;
CRobotMain* m_main; CRobotMain* m_main;
CSound* m_sound; CSoundInterface* m_sound;
Math::Vector m_pos; // center of the effect Math::Vector m_pos; // center of the effect
Math::Vector m_posPower; // center of the battery Math::Vector m_posPower; // center of the battery
bool m_power; // battery exists? bool m_power; // battery exists?
Gfx::PyroType m_type; PyroType m_type;
float m_force; float m_force;
float m_size; float m_size;
float m_progress; float m_progress;
@ -161,12 +165,12 @@ protected:
int m_lightRank; int m_lightRank;
int m_lightOperTotal; int m_lightOperTotal;
Gfx::PyroLightOper m_lightOper[10]; PyroLightOper m_lightOper[10];
float m_lightHeight; float m_lightHeight;
ObjectType m_burnType; ObjectType m_burnType;
int m_burnPartTotal; int m_burnPartTotal;
Gfx::PyroBurnPart m_burnPart[10]; PyroBurnPart m_burnPart[10];
int m_burnKeepPart[10]; int m_burnKeepPart[10];
float m_burnFall; float m_burnFall;
@ -180,4 +184,5 @@ protected:
float m_crashSphereRadius[50]; float m_crashSphereRadius[50];
}; };
}; // namespace Gfx
} // namespace Gfx

View File

@ -15,7 +15,6 @@
// * You should have received a copy of the GNU General Public License // * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/. // * along with this program. If not, see http://www.gnu.org/licenses/.
// terrain.cpp
#include "graphics/engine/terrain.h" #include "graphics/engine/terrain.h"
@ -31,18 +30,22 @@
#include <SDL/SDL.h> #include <SDL/SDL.h>
// Graphics module namespace
namespace Gfx {
const int LEVEL_MAT_PREALLOCATE_COUNT = 101; const int LEVEL_MAT_PREALLOCATE_COUNT = 101;
const int FLYING_LIMIT_PREALLOCATE_COUNT = 10; const int FLYING_LIMIT_PREALLOCATE_COUNT = 10;
const int BUILDING_LEVEL_PREALLOCATE_COUNT = 101; const int BUILDING_LEVEL_PREALLOCATE_COUNT = 101;
Gfx::CTerrain::CTerrain(CInstanceManager* iMan) CTerrain::CTerrain(CInstanceManager* iMan)
{ {
m_iMan = iMan; m_iMan = iMan;
m_iMan->AddInstance(CLASS_TERRAIN, this); m_iMan->AddInstance(CLASS_TERRAIN, this);
m_engine = static_cast<Gfx::CEngine*>( m_iMan->SearchInstance(CLASS_ENGINE) ); m_engine = static_cast<CEngine*>( m_iMan->SearchInstance(CLASS_ENGINE) );
m_water = static_cast<Gfx::CWater*>( m_iMan->SearchInstance(CLASS_WATER) ); m_water = static_cast<CWater*>( m_iMan->SearchInstance(CLASS_WATER) );
m_mosaicCount = 20; m_mosaicCount = 20;
m_brickCount = 1 << 4; m_brickCount = 1 << 4;
@ -66,11 +69,11 @@ Gfx::CTerrain::CTerrain(CInstanceManager* iMan)
FlushMaterials(); 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) float vision, int depth, float hardness)
{ {
m_mosaicCount = mosaicCount; 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; return m_mosaicCount;
} }
int Gfx::CTerrain::GetBrickCount() int CTerrain::GetBrickCount()
{ {
return m_brickCount; return m_brickCount;
} }
float Gfx::CTerrain::GetBrickSize() float CTerrain::GetBrickSize()
{ {
return m_brickSize; return m_brickSize;
} }
float Gfx::CTerrain::GetReliefScale() float CTerrain::GetReliefScale()
{ {
return m_scaleRelief; 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; 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_materials.clear();
m_maxMaterialID = 0; m_maxMaterialID = 0;
@ -157,7 +160,7 @@ void Gfx::CTerrain::FlushMaterials()
FlushMaterialPoints(); 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, int up, int right, int down, int left,
float hardness) float hardness)
{ {
@ -166,7 +169,7 @@ void Gfx::CTerrain::AddMaterial(int id, const std::string& texName, const Math::
if (id == 0) if (id == 0)
id = m_materialAutoID++; id = m_materialAutoID++;
Gfx::TerrainMaterial tm; TerrainMaterial tm;
tm.texName = texName; tm.texName = texName;
tm.id = id; tm.id = id;
tm.uv = uv; 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 * The image must be 24 bits/pixel and grayscale and dx x dy in size
* with dx = dy = (mosaic*brick)+1 */ * with dx = dy = (mosaic*brick)+1 */
bool Gfx::CTerrain::LoadResources(const std::string& fileName) bool CTerrain::LoadResources(const std::string& fileName)
{ {
CImage img; CImage img;
if (! img.Load(CApplication::GetInstance().GetDataFilePath(m_engine->GetTextureDir(), fileName))) if (! img.Load(CApplication::GetInstance().GetDataFilePath(m_engine->GetTextureDir(), fileName)))
@ -220,17 +223,17 @@ bool Gfx::CTerrain::LoadResources(const std::string& fileName)
return true; return true;
} }
Gfx::TerrainRes Gfx::CTerrain::GetResource(const Math::Vector &p) TerrainRes CTerrain::GetResource(const Math::Vector &p)
{ {
if (m_resources.empty()) 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 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); 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 || if ( x < 0 || x > m_mosaicCount*m_brickCount ||
y < 0 || y > 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; 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 resG = m_resources[3*x+3*size*(size-y-1)+1];
int resB = m_resources[3*x+3*size*(size-y-1)+2]; 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 == 0 && resB == 0) return TR_STONE;
if (resR == 255 && resG == 255 && resB == 0) return Gfx::TR_URANIUM; if (resR == 255 && resG == 255 && resB == 0) return TR_URANIUM;
if (resR == 0 && resG == 255 && resB == 0) return Gfx::TR_POWER; if (resR == 0 && resG == 255 && resB == 0) return TR_POWER;
// TODO key res values // TODO key res values
//if (ress == 24) return Gfx::TR_KEY_A; // ~green? //if (ress == 24) return TR_KEY_A; // ~green?
//if (ress == 25) return Gfx::TR_KEY_B; // ~green? //if (ress == 25) return TR_KEY_B; // ~green?
//if (ress == 26) return Gfx::TR_KEY_C; // ~green? //if (ress == 26) return TR_KEY_C; // ~green?
//if (ress == 27) return Gfx::TR_KEY_D; // ~green? //if (ress == 27) return TR_KEY_D; // ~green?
return TR_NULL; return TR_NULL;
} }
void Gfx::CTerrain::FlushRelief() void CTerrain::FlushRelief()
{ {
m_relief.clear(); m_relief.clear();
} }
@ -259,7 +262,7 @@ void Gfx::CTerrain::FlushRelief()
/** /**
* The image must be 24 bits/pixel and dx x dy in size * The image must be 24 bits/pixel and dx x dy in size
* with dx = dy = (mosaic*brick)+1 */ * 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) bool adjustBorder)
{ {
m_scaleRelief = scaleRelief; m_scaleRelief = scaleRelief;
@ -304,7 +307,7 @@ bool Gfx::CTerrain::LoadRelief(const std::string &fileName, float scaleRelief,
return true; 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; float dim = (m_mosaicCount*m_brickCount*m_brickSize)/2.0f;
int size = (m_mosaicCount*m_brickCount)+1; int size = (m_mosaicCount*m_brickCount)+1;
@ -324,7 +327,7 @@ bool Gfx::CTerrain::AddReliefPoint(Math::Vector pos, float scaleRelief)
return true; return true;
} }
void Gfx::CTerrain::AdjustRelief() void CTerrain::AdjustRelief()
{ {
if (m_depth == 1) return; 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; Math::Vector p;
p.x = x*m_brickSize - (m_mosaicCount*m_brickCount*m_brickSize) / 2.0; 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 +---f---e--> x
\endverbatim */ \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); Math::Vector o = GetVector(x, y);
v.coord = o; v.coord = o;
@ -473,8 +476,8 @@ Gfx::VertexTex2 Gfx::CTerrain::GetVertex(int x, int y, int step)
| |
+-------------------> x +-------------------> x
\endverbatim */ \endverbatim */
bool Gfx::CTerrain::CreateMosaic(int ox, int oy, int step, int objRank, bool CTerrain::CreateMosaic(int ox, int oy, int step, int objRank,
const Gfx::Material &mat, const Material &mat,
float min, float max) float min, float max)
{ {
std::string texName1; 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; 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; int total = ((brick/step)+1)*2;
float pixel = 1.0f/256.0f; // 1 pixel cover (*) 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) for (int y = 0; y < brick; y += step)
{ {
Gfx::EngineObjLevel4 buffer; EngineObjLevel4 buffer;
buffer.vertices.reserve(total); buffer.vertices.reserve(total);
buffer.type = Gfx::ENG_TRIANGLE_TYPE_SURFACE; buffer.type = ENG_TRIANGLE_TYPE_SURFACE;
buffer.material = mat; 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) if (step == 1)
buffer.state |= Gfx::ENG_RSTATE_DUAL_BLACK; buffer.state |= ENG_RSTATE_DUAL_BLACK;
for (int x = 0; x <= brick; x += step) 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); 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 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; p1.coord.x -= o.coord.x; p1.coord.z -= o.coord.z;
p2.coord.x -= o.coord.x; p2.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; 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++) 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; 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; x /= m_brickCount/m_textureSubdivCount;
y /= 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); 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]; 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 hc = GetHeight(x, y);
float h[4] = float h[4] =
@ -714,7 +717,7 @@ bool Gfx::CTerrain::CheckMaterialPoint(int x, int y, float min, float max, float
return false; 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++) for (int i = 0; i < static_cast<int>( m_materials.size() ); i++)
{ {
@ -727,7 +730,7 @@ int Gfx::CTerrain::FindMaterialByNeighbors(char *mat)
return -1; 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); TerrainMaterial* tm = FindMaterial(id);
if (tm == nullptr) return; 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]; char test[4];
@ -862,7 +865,7 @@ bool Gfx::CTerrain::CondChangeMaterialPoint(int x, int y, int id, char *mat)
return true; return true;
} }
bool Gfx::CTerrain::ChangeMaterialPoint(int x, int y, int id) bool CTerrain::ChangeMaterialPoint(int x, int y, int id)
{ {
char mat[4]; char mat[4];
@ -1022,7 +1025,7 @@ bool Gfx::CTerrain::ChangeMaterialPoint(int x, int y, int id)
return false; return false;
} }
bool Gfx::CTerrain::InitMaterials(int id) bool CTerrain::InitMaterials(int id)
{ {
TerrainMaterial* tm = FindMaterial(id); TerrainMaterial* tm = FindMaterial(id);
if (tm == nullptr) return false; if (tm == nullptr) return false;
@ -1038,7 +1041,7 @@ bool Gfx::CTerrain::InitMaterials(int id)
return true; 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, float slope, float freq,
Math::Vector center, float radius) Math::Vector center, float radius)
{ {
@ -1118,13 +1121,13 @@ bool Gfx::CTerrain::GenerateMaterials(int *id, float min, float max,
return true; return true;
} }
void Gfx::CTerrain::InitMaterialPoints() void CTerrain::InitMaterialPoints()
{ {
if (! m_useMaterials) return; if (! m_useMaterials) return;
if (! m_materialPoints.empty()) return; // already allocated if (! m_materialPoints.empty()) return; // already allocated
m_materialPointCount = (m_mosaicCount*m_brickCount)/(m_brickCount/m_textureSubdivCount)+1; 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++) 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(); m_materialPoints.clear();
} }
bool Gfx::CTerrain::CreateSquare(int x, int y) bool CTerrain::CreateSquare(int x, int y)
{ {
Gfx::Material mat; Material mat;
mat.diffuse = Gfx::Color(1.0f, 1.0f, 1.0f); mat.diffuse = Color(1.0f, 1.0f, 1.0f);
mat.ambient = Gfx::Color(0.0f, 0.0f, 0.0f); mat.ambient = Color(0.0f, 0.0f, 0.0f);
int objRank = m_engine->CreateObject(); 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; m_objRanks[x+y*m_mosaicCount] = objRank;
@ -1163,7 +1166,7 @@ bool Gfx::CTerrain::CreateSquare(int x, int y)
return true; return true;
} }
bool Gfx::CTerrain::CreateObjects() bool CTerrain::CreateObjects()
{ {
AdjustRelief(); AdjustRelief();
@ -1177,7 +1180,7 @@ bool Gfx::CTerrain::CreateObjects()
} }
/** ATTENTION: ok only with m_depth = 2! */ /** 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; 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; return true;
} }
void Gfx::CTerrain::SetWind(Math::Vector speed) void CTerrain::SetWind(Math::Vector speed)
{ {
m_wind = speed; m_wind = speed;
} }
Math::Vector Gfx::CTerrain::GetWind() Math::Vector CTerrain::GetWind()
{ {
return m_wind; return m_wind;
} }
float Gfx::CTerrain::GetFineSlope(const Math::Vector &pos) float CTerrain::GetFineSlope(const Math::Vector &pos)
{ {
Math::Vector n; Math::Vector n;
if (! GetNormal(n, pos)) return 0.0f; if (! GetNormal(n, pos)) return 0.0f;
return fabs(Math::RotateAngle(Math::Point(n.x, n.z).Length(), n.y) - Math::PI/2.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; 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); 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; 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; 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; 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; 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; 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; 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; 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 * @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; bool ok = true;
@ -1476,7 +1479,7 @@ bool Gfx::CTerrain::AdjustToStandardBounds(Math::Vector& pos)
* @param margin margin to the terrain border * @param margin margin to the terrain border
* @returns \c false if the initial coordinate was outside terrain area; \c true otherwise * @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; bool ok = true;
float limit = m_mosaicCount*m_brickCount*m_brickSize/2.0f - margin; 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; return ok;
} }
void Gfx::CTerrain::FlushBuildingLevel() void CTerrain::FlushBuildingLevel()
{ {
m_buildingLevels.clear(); 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) float height, float factor)
{ {
int i = 0; 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() )) 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].center = center;
m_buildingLevels[i].min = min; m_buildingLevels[i].min = min;
@ -1543,7 +1546,7 @@ bool Gfx::CTerrain::AddBuildingLevel(Math::Vector center, float min, float max,
return true; 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++) 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; 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++) 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; 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++) 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 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++) 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); float factor = GetBuildingFactor(p);
if (factor != 1.0f) return 1.0f; // on building level 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; return tm->hardness;
} }
void Gfx::CTerrain::ShowFlatGround(Math::Vector pos) void CTerrain::ShowFlatGround(Math::Vector pos)
{ {
static char table[41*41] = { 1 }; static char table[41*41] = { 1 };
@ -1681,7 +1684,7 @@ void Gfx::CTerrain::ShowFlatGround(Math::Vector pos)
float angle = GetFineSlope(pos+p); float angle = GetFineSlope(pos+p);
if (angle < Gfx::TERRAIN_FLATLIMIT) if (angle < TERRAIN_FLATLIMIT)
table[i] = 1; table[i] = 1;
else else
table[i] = 2; 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); 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); float angle = GetFineSlope(center);
if (angle >= Gfx::TERRAIN_FLATLIMIT) if (angle >= TERRAIN_FLATLIMIT)
return 0.0f; return 0.0f;
float ref = GetFloorLevel(center, true); float ref = GetFloorLevel(center, true);
@ -1724,27 +1727,27 @@ float Gfx::CTerrain::GetFlatZoneRadius(Math::Vector center, float max)
return max; return max;
} }
void Gfx::CTerrain::SetFlyingMaxHeight(float height) void CTerrain::SetFlyingMaxHeight(float height)
{ {
m_flyingMaxHeight = height; m_flyingMaxHeight = height;
} }
float Gfx::CTerrain::GetFlyingMaxHeight() float CTerrain::GetFlyingMaxHeight()
{ {
return m_flyingMaxHeight; return m_flyingMaxHeight;
} }
void Gfx::CTerrain::FlushFlyingLimit() void CTerrain::FlushFlyingLimit()
{ {
m_flyingMaxHeight = 280.0f; m_flyingMaxHeight = 280.0f;
m_flyingLimits.clear(); m_flyingLimits.clear();
} }
void Gfx::CTerrain::AddFlyingLimit(Math::Vector center, void CTerrain::AddFlyingLimit(Math::Vector center,
float extRadius, float intRadius, float extRadius, float intRadius,
float maxHeight) float maxHeight)
{ {
Gfx::FlyingLimit fl; FlyingLimit fl;
fl.center = center; fl.center = center;
fl.extRadius = extRadius; fl.extRadius = extRadius;
fl.intRadius = intRadius; fl.intRadius = intRadius;
@ -1752,7 +1755,7 @@ void Gfx::CTerrain::AddFlyingLimit(Math::Vector center,
m_flyingLimits.push_back(fl); m_flyingLimits.push_back(fl);
} }
float Gfx::CTerrain::GetFlyingLimit(Math::Vector pos, bool noLimit) float CTerrain::GetFlyingLimit(Math::Vector pos, bool noLimit)
{ {
if (noLimit) if (noLimit)
return 280.0f; return 280.0f;
@ -1780,3 +1783,6 @@ float Gfx::CTerrain::GetFlyingLimit(Math::Vector pos, bool noLimit)
return m_flyingMaxHeight; return m_flyingMaxHeight;
} }
} // namespace Gfx

View File

@ -17,17 +17,19 @@
/** /**
* \file graphics/engine/terrain.h * \file graphics/engine/terrain.h
* \brief Terrain rendering - Gfx::CTerrain class * \brief Terrain rendering - CTerrain class
*/ */
#pragma once #pragma once
#include "graphics/engine/engine.h" #include "graphics/engine/engine.h"
class CInstanceManager; class CInstanceManager;
// Graphics module namespace
namespace Gfx { namespace Gfx {
class CEngine; class CEngine;
@ -277,7 +279,7 @@ public:
//! Adjusts 3D position so that it is within terrain boundaries and the given margin //! Adjusts 3D position so that it is within terrain boundaries and the given margin
bool AdjustToBounds(Math::Vector& pos, float margin); bool AdjustToBounds(Math::Vector& pos, float margin);
//! Returns the resource type available underground at 2D (XZ) position //! 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 //! Empty the table of elevations
void FlushBuildingLevel(); void FlushBuildingLevel();
@ -326,14 +328,14 @@ protected:
//! Calculates a vector of the terrain //! Calculates a vector of the terrain
Math::Vector GetVector(int x, int y); Math::Vector GetVector(int x, int y);
//! Calculates a vertex of the terrain //! 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 //! 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 //! Creates all objects in a mesh square ground
bool CreateSquare(int x, int y); bool CreateSquare(int x, int y);
//! Seeks a material based on its ID //! Seeks a material based on its ID
Gfx::TerrainMaterial* FindMaterial(int id); TerrainMaterial* FindMaterial(int id);
//! Seeks a material based on neighbor values //! Seeks a material based on neighbor values
int FindMaterialByNeighbors(char *mat); int FindMaterialByNeighbors(char *mat);
//! Returns the texture name and UV coords to use for a given square //! Returns the texture name and UV coords to use for a given square
@ -399,15 +401,15 @@ protected:
//! True if using terrain material mapping //! True if using terrain material mapping
bool m_useMaterials; bool m_useMaterials;
//! Terrain materials //! Terrain materials
std::vector<Gfx::TerrainMaterial> m_materials; std::vector<TerrainMaterial> m_materials;
//! Material for terrain points //! Material for terrain points
std::vector<Gfx::TerrainMaterialPoint> m_materialPoints; std::vector<TerrainMaterialPoint> m_materialPoints;
//! Maximum level ID (no ID is >= to this) //! Maximum level ID (no ID is >= to this)
int m_maxMaterialID; int m_maxMaterialID;
//! Internal counter for auto generation of material IDs //! Internal counter for auto generation of material IDs
int m_materialAutoID; int m_materialAutoID;
std::vector<Gfx::BuildingLevel> m_buildingLevels; std::vector<BuildingLevel> m_buildingLevels;
//! Wind speed //! Wind speed
Math::Vector m_wind; Math::Vector m_wind;
@ -415,7 +417,8 @@ protected:
//! Global flying height limit //! Global flying height limit
float m_flyingMaxHeight; float m_flyingMaxHeight;
//! List of local flight limits //! List of local flight limits
std::vector<Gfx::FlyingLimit> m_flyingLimits; std::vector<FlyingLimit> m_flyingLimits;
}; };
}; // namespace Gfx
} // namespace Gfx

View File

@ -15,7 +15,6 @@
// * You should have received a copy of the GNU General Public License // * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/. // * along with this program. If not, see http://www.gnu.org/licenses/.
// text.cpp
#include "graphics/engine/text.h" #include "graphics/engine/text.h"
@ -30,25 +29,27 @@
#include <SDL/SDL_ttf.h> #include <SDL/SDL_ttf.h>
namespace Gfx // Graphics module namespace
{ namespace Gfx {
/** /**
\struct CachedFont * \struct CachedFont
\brief Base TTF font with UTF-8 char cache */ * \brief Base TTF font with UTF-8 char cache
*/
struct CachedFont struct CachedFont
{ {
TTF_Font* font; TTF_Font* font;
std::map<Gfx::UTF8Char, Gfx::CharTexture> cache; std::map<UTF8Char, CharTexture> cache;
CachedFont() : font(nullptr) {} CachedFont() : font(nullptr) {}
}; };
};
Gfx::CText::CText(CInstanceManager *iMan, Gfx::CEngine* engine)
CText::CText(CInstanceManager *iMan, CEngine* engine)
{ {
m_iMan = iMan; m_iMan = iMan;
m_iMan->AddInstance(CLASS_TEXT, this); m_iMan->AddInstance(CLASS_TEXT, this);
@ -59,12 +60,12 @@ Gfx::CText::CText(CInstanceManager *iMan, Gfx::CEngine* engine)
m_defaultSize = 12.0f; m_defaultSize = 12.0f;
m_fontPath = "fonts"; m_fontPath = "fonts";
m_lastFontType = Gfx::FONT_COLOBOT; m_lastFontType = FONT_COLOBOT;
m_lastFontSize = 0; m_lastFontSize = 0;
m_lastCachedFont = nullptr; m_lastCachedFont = nullptr;
} }
Gfx::CText::~CText() CText::~CText()
{ {
m_iMan->DeleteInstance(CLASS_TEXT, this); m_iMan->DeleteInstance(CLASS_TEXT, this);
@ -73,7 +74,7 @@ Gfx::CText::~CText()
m_engine = nullptr; m_engine = nullptr;
} }
bool Gfx::CText::Create() bool CText::Create()
{ {
if (TTF_Init() != 0) if (TTF_Init() != 0)
{ {
@ -81,16 +82,16 @@ bool Gfx::CText::Create()
return false; return false;
} }
m_fonts[Gfx::FONT_COLOBOT] = new MultisizeFont("dvu_sans.ttf"); m_fonts[FONT_COLOBOT] = new MultisizeFont("dvu_sans.ttf");
m_fonts[Gfx::FONT_COLOBOT_BOLD] = new MultisizeFont("dvu_sans_bold.ttf"); m_fonts[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_ITALIC] = new MultisizeFont("dvu_sans_italic.ttf");
m_fonts[Gfx::FONT_COURIER] = new MultisizeFont("dvu_sans_mono.ttf"); m_fonts[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_BOLD] = new MultisizeFont("dvu_sans_mono_bold.ttf");
for (auto it = m_fonts.begin(); it != m_fonts.end(); ++it) 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); CachedFont* cf = GetOrOpenFont(type, m_defaultSize);
if (cf == nullptr || cf->font == nullptr) if (cf == nullptr || cf->font == nullptr)
return false; return false;
@ -99,7 +100,7 @@ bool Gfx::CText::Create()
return true; return true;
} }
void Gfx::CText::Destroy() void CText::Destroy()
{ {
for (auto it = m_fonts.begin(); it != m_fonts.end(); ++it) for (auto it = m_fonts.begin(); it != m_fonts.end(); ++it)
{ {
@ -126,17 +127,17 @@ void Gfx::CText::Destroy()
TTF_Quit(); TTF_Quit();
} }
void Gfx::CText::SetDevice(Gfx::CDevice* device) void CText::SetDevice(CDevice* device)
{ {
m_device = device; m_device = device;
} }
std::string Gfx::CText::GetError() std::string CText::GetError()
{ {
return m_error; return m_error;
} }
void Gfx::CText::FlushCache() void CText::FlushCache()
{ {
for (auto it = m_fonts.begin(); it != m_fonts.end(); ++it) 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, void CText::DrawText(const std::string &text, const std::vector<FontMetaChar> &format,
float size, Math::Point pos, float width, Gfx::TextAlign align, float size, Math::Point pos, float width, TextAlign align,
int eol) int eol)
{ {
float sw = 0.0f; float sw = 0.0f;
if (align == Gfx::TEXT_ALIGN_CENTER) if (align == TEXT_ALIGN_CENTER)
{ {
sw = GetStringWidth(text, format, size); sw = GetStringWidth(text, format, size);
if (sw > width) sw = width; if (sw > width) sw = width;
pos.x -= sw / 2.0f; pos.x -= sw / 2.0f;
} }
else if (align == Gfx::TEXT_ALIGN_RIGHT) else if (align == TEXT_ALIGN_RIGHT)
{ {
sw = GetStringWidth(text, format, size); sw = GetStringWidth(text, format, size);
if (sw > width) sw = width; 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); DrawString(text, format, size, pos, width, eol);
} }
void Gfx::CText::DrawText(const std::string &text, Gfx::FontType font, void CText::DrawText(const std::string &text, FontType font,
float size, Math::Point pos, float width, Gfx::TextAlign align, float size, Math::Point pos, float width, TextAlign align,
int eol) int eol)
{ {
float sw = 0.0f; float sw = 0.0f;
if (align == Gfx::TEXT_ALIGN_CENTER) if (align == TEXT_ALIGN_CENTER)
{ {
sw = GetStringWidth(text, font, size); sw = GetStringWidth(text, font, size);
if (sw > width) sw = width; if (sw > width) sw = width;
pos.x -= sw / 2.0f; pos.x -= sw / 2.0f;
} }
else if (align == Gfx::TEXT_ALIGN_RIGHT) else if (align == TEXT_ALIGN_RIGHT)
{ {
sw = GetStringWidth(text, font, size); sw = GetStringWidth(text, font, size);
if (sw > width) sw = width; 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); DrawString(text, font, size, pos, width, eol);
} }
void Gfx::CText::SizeText(const std::string &text, const std::vector<FontMetaChar> &format, void CText::SizeText(const std::string &text, const std::vector<FontMetaChar> &format,
float size, Math::Point pos, Gfx::TextAlign align, float size, Math::Point pos, TextAlign align,
Math::Point &start, Math::Point &end) Math::Point &start, Math::Point &end)
{ {
start = end = pos; start = end = pos;
float sw = GetStringWidth(text, format, size); float sw = GetStringWidth(text, format, size);
end.x += sw; end.x += sw;
if (align == Gfx::TEXT_ALIGN_CENTER) if (align == TEXT_ALIGN_CENTER)
{ {
start.x -= sw/2.0f; start.x -= sw/2.0f;
end.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; start.x -= sw;
end.x -= sw; end.x -= sw;
} }
start.y -= GetDescent(Gfx::FONT_COLOBOT, size); start.y -= GetDescent(FONT_COLOBOT, size);
end.y += GetAscent(Gfx::FONT_COLOBOT, size); end.y += GetAscent(FONT_COLOBOT, size);
} }
void Gfx::CText::SizeText(const std::string &text, Gfx::FontType font, void CText::SizeText(const std::string &text, FontType font,
float size, Math::Point pos, Gfx::TextAlign align, float size, Math::Point pos, TextAlign align,
Math::Point &start, Math::Point &end) Math::Point &start, Math::Point &end)
{ {
start = end = pos; start = end = pos;
float sw = GetStringWidth(text, font, size); float sw = GetStringWidth(text, font, size);
end.x += sw; end.x += sw;
if (align == Gfx::TEXT_ALIGN_CENTER) if (align == TEXT_ALIGN_CENTER)
{ {
start.x -= sw/2.0f; start.x -= sw/2.0f;
end.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; start.x -= sw;
end.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); 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); assert(cf != nullptr);
Math::IntPoint wndSize; Math::IntPoint wndSize;
wndSize.y = TTF_FontAscent(cf->font); wndSize.y = TTF_FontAscent(cf->font);
@ -251,11 +252,11 @@ float Gfx::CText::GetAscent(Gfx::FontType font, float size)
return ifSize.y; 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); assert(cf != nullptr);
Math::IntPoint wndSize; Math::IntPoint wndSize;
wndSize.y = TTF_FontDescent(cf->font); wndSize.y = TTF_FontDescent(cf->font);
@ -263,11 +264,11 @@ float Gfx::CText::GetDescent(Gfx::FontType font, float size)
return ifSize.y; 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); assert(cf != nullptr);
Math::IntPoint wndSize; Math::IntPoint wndSize;
wndSize.y = TTF_FontHeight(cf->font); 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) const std::vector<FontMetaChar> &format, float size)
{ {
assert(StrUtils::Utf8StringLength(text) == format.size()); assert(StrUtils::Utf8StringLength(text) == format.size());
@ -286,9 +287,9 @@ float Gfx::CText::GetStringWidth(const std::string &text,
unsigned int fmtIndex = 0; unsigned int fmtIndex = 0;
while (index < text.length()) 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); int len = StrUtils::Utf8CharSizeAt(text, index);
if (len >= 1) if (len >= 1)
@ -307,13 +308,13 @@ float Gfx::CText::GetStringWidth(const std::string &text,
return width; 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? // TODO: special chars?
Gfx::CachedFont* cf = GetOrOpenFont(font, size); CachedFont* cf = GetOrOpenFont(font, size);
assert(cf != nullptr); assert(cf != nullptr);
Math::IntPoint wndSize; Math::IntPoint wndSize;
TTF_SizeUTF8(cf->font, text.c_str(), &wndSize.x, &wndSize.y); 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; 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) // TODO: if (font == FONT_BUTTON)
if (font == Gfx::FONT_BUTTON) return 0.0f; if (font == FONT_BUTTON) return 0.0f;
// TODO: special chars? // TODO: special chars?
// TODO: tab sizing // TODO: tab sizing
Gfx::CachedFont* cf = GetOrOpenFont(font, size); CachedFont* cf = GetOrOpenFont(font, size);
assert(cf != nullptr); assert(cf != nullptr);
Gfx::CharTexture tex; CharTexture tex;
auto it = cf->cache.find(ch); auto it = cf->cache.find(ch);
if (it != cf->cache.end()) if (it != cf->cache.end())
tex = (*it).second; 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) float size, float width)
{ {
assert(StrUtils::Utf8StringLength(text) == format.size()); 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; unsigned int fmtIndex = 0;
while (index < text.length()) 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); int len = StrUtils::Utf8CharSizeAt(text, index);
if (len >= 1) if (len >= 1)
@ -366,7 +367,7 @@ int Gfx::CText::Justify(const std::string &text, const std::vector<FontMetaChar>
if (len >= 3) if (len >= 3)
ch.c3 = text[index+2]; ch.c3 = text[index+2];
if (font != Gfx::FONT_BUTTON) if (font != FONT_BUTTON)
{ {
if (ch.c1 == '\n') if (ch.c1 == '\n')
return index+1; return index+1;
@ -388,16 +389,16 @@ int Gfx::CText::Justify(const std::string &text, const std::vector<FontMetaChar>
return index; 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; float pos = 0.0f;
int cut = 0; int cut = 0;
unsigned int index = 0; unsigned int index = 0;
while (index < text.length()) while (index < text.length())
{ {
Gfx::UTF8Char ch; UTF8Char ch;
int len = StrUtils::Utf8CharSizeAt(text, index); int len = StrUtils::Utf8CharSizeAt(text, index);
if (len >= 1) if (len >= 1)
@ -426,7 +427,7 @@ int Gfx::CText::Justify(const std::string &text, Gfx::FontType font, float size,
return index; 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) float size, float offset)
{ {
assert(StrUtils::Utf8StringLength(text) == format.size()); 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; unsigned int fmtIndex = 0;
while (index < text.length()) 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) // TODO: if (font == FONT_BUTTON)
if (font == Gfx::FONT_BUTTON) continue; if (font == FONT_BUTTON) continue;
Gfx::UTF8Char ch; UTF8Char ch;
int len = StrUtils::Utf8CharSizeAt(text, index); int len = StrUtils::Utf8CharSizeAt(text, index);
if (len >= 1) if (len >= 1)
@ -466,15 +467,15 @@ int Gfx::CText::Detect(const std::string &text, const std::vector<FontMetaChar>
return index; 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; float pos = 0.0f;
unsigned int index = 0; unsigned int index = 0;
while (index < text.length()) while (index < text.length())
{ {
Gfx::UTF8Char ch; UTF8Char ch;
int len = StrUtils::Utf8CharSizeAt(text, index); int len = StrUtils::Utf8CharSizeAt(text, index);
if (len >= 1) if (len >= 1)
@ -499,26 +500,26 @@ int Gfx::CText::Detect(const std::string &text, Gfx::FontType font, float size,
return index; 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) float size, Math::Point pos, float width, int eol)
{ {
assert(StrUtils::Utf8StringLength(text) == format.size()); 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; float start = pos.x;
unsigned int index = 0; unsigned int index = 0;
unsigned int fmtIndex = 0; unsigned int fmtIndex = 0;
while (index < text.length()) 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) // TODO: if (font == FONT_BUTTON)
if (font == Gfx::FONT_BUTTON) continue; if (font == FONT_BUTTON) continue;
Gfx::UTF8Char ch; UTF8Char ch;
int len = StrUtils::Utf8CharSizeAt(text, index); int len = StrUtils::Utf8CharSizeAt(text, index);
if (len >= 1) if (len >= 1)
@ -536,8 +537,8 @@ void Gfx::CText::DrawString(const std::string &text, const std::vector<FontMetaC
break; break;
} }
Gfx::FontHighlight hl = static_cast<Gfx::FontHighlight>(format[fmtIndex] & Gfx::FONT_MASK_HIGHLIGHT); FontHighlight hl = static_cast<FontHighlight>(format[fmtIndex] & FONT_MASK_HIGHLIGHT);
if (hl != Gfx::FONT_HIGHLIGHT_NONE) if (hl != FONT_HIGHLIGHT_NONE)
{ {
Math::Point charSize; Math::Point charSize;
charSize.x = GetCharWidth(ch, font, size, offset); 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 // 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) 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; unsigned int index = 0;
while (index < text.length()) while (index < text.length())
{ {
Gfx::UTF8Char ch; UTF8Char ch;
int len = StrUtils::Utf8CharSizeAt(text, index); int len = StrUtils::Utf8CharSizeAt(text, index);
if (len >= 1) 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 // Gradient colors
Gfx::Color grad[4]; Color grad[4];
// TODO: switch to alpha factors // TODO: switch to alpha factors
switch (hl) switch (hl)
{ {
case Gfx::FONT_HIGHLIGHT_LINK: case FONT_HIGHLIGHT_LINK:
grad[0] = grad[1] = grad[2] = grad[3] = Gfx::Color(0.0f, 0.0f, 1.0f, 0.5f); grad[0] = grad[1] = grad[2] = grad[3] = Color(0.0f, 0.0f, 1.0f, 0.5f);
break; break;
case Gfx::FONT_HIGHLIGHT_TOKEN: case FONT_HIGHLIGHT_TOKEN:
grad[0] = grad[1] = Gfx::Color(248.0f / 256.0f, 248.0f / 256.0f, 248.0f / 256.0f, 0.5f); grad[0] = grad[1] = 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); grad[2] = grad[3] = Color(248.0f / 256.0f, 220.0f / 256.0f, 188.0f / 256.0f, 0.5f);
break; break;
case Gfx::FONT_HIGHLIGHT_TYPE: case FONT_HIGHLIGHT_TYPE:
grad[0] = grad[1] = Gfx::Color(248.0f / 256.0f, 248.0f / 256.0f, 248.0f / 256.0f, 0.5f); grad[0] = grad[1] = 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); grad[2] = grad[3] = Color(169.0f / 256.0f, 234.0f / 256.0f, 169.0f / 256.0f, 0.5f);
break; break;
case Gfx::FONT_HIGHLIGHT_CONST: case FONT_HIGHLIGHT_CONST:
grad[0] = grad[1] = Gfx::Color(248.0f / 256.0f, 248.0f / 256.0f, 248.0f / 256.0f, 0.5f); grad[0] = grad[1] = 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); grad[2] = grad[3] = Color(248.0f / 256.0f, 176.0f / 256.0f, 169.0f / 256.0f, 0.5f);
break; break;
case Gfx::FONT_HIGHLIGHT_REM: case FONT_HIGHLIGHT_REM:
grad[0] = grad[1] = Gfx::Color(248.0f / 256.0f, 248.0f / 256.0f, 248.0f / 256.0f, 0.5f); grad[0] = grad[1] = 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); grad[2] = grad[3] = Color(248.0f / 256.0f, 169.0f / 256.0f, 248.0f / 256.0f, 0.5f);
break; break;
case Gfx::FONT_HIGHLIGHT_KEY: case FONT_HIGHLIGHT_KEY:
grad[0] = grad[1] = grad[2] = grad[3] = 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; break;
default: default:
@ -633,7 +634,7 @@ void Gfx::CText::DrawHighlight(Gfx::FontHighlight hl, Math::Point pos, Math::Poi
p1.x = pos.x; p1.x = pos.x;
p2.x = pos.x + size.x; p2.x = pos.x + size.x;
if (hl == Gfx::FONT_HIGHLIGHT_LINK) if (hl == FONT_HIGHLIGHT_LINK)
{ {
p1.y = pos.y; p1.y = pos.y;
p2.y = pos.y + h; // just emphasized 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; 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]), VertexCol(Math::Vector(p1.x, p1.y, 0.0f), grad[3]),
Gfx::VertexCol(Math::Vector(p1.x, p2.y, 0.0f), grad[0]), VertexCol(Math::Vector(p1.x, p2.y, 0.0f), grad[0]),
Gfx::VertexCol(Math::Vector(p2.x, p1.y, 0.0f), grad[2]), 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(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_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) // TODO: if (font == FONT_BUTTON)
if (font == Gfx::FONT_BUTTON) return; if (font == FONT_BUTTON) return;
// TODO: special chars? // 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 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)), 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)), 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)), 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(p2.x, p2.y, 0.0f), n, Math::Point(1.0f, 0.0f))
}; };
m_device->SetTexture(0, tex.id); 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); m_engine->AddStatisticTriangle(2);
pos.x += tex.charSize.x; pos.x += tex.charSize.x;
} }
Gfx::CachedFont* Gfx::CText::GetOrOpenFont(Gfx::FontType font, float size) CachedFont* CText::GetOrOpenFont(FontType font, float size)
{ {
// TODO: sizing // TODO: sizing
int pointSize = static_cast<int>(size); int pointSize = static_cast<int>(size);
@ -749,7 +750,7 @@ Gfx::CachedFont* Gfx::CText::GetOrOpenFont(Gfx::FontType font, float size)
return m_lastCachedFont; return m_lastCachedFont;
} }
Gfx::CharTexture Gfx::CText::CreateCharTexture(Gfx::UTF8Char ch, Gfx::CachedFont* font) CharTexture CText::CreateCharTexture(UTF8Char ch, CachedFont* font)
{ {
CharTexture texture; CharTexture texture;
@ -775,13 +776,13 @@ Gfx::CharTexture Gfx::CText::CreateCharTexture(Gfx::UTF8Char ch, Gfx::CachedFont
ImageData data; ImageData data;
data.surface = textureSurface; data.surface = textureSurface;
Gfx::TextureCreateParams createParams; TextureCreateParams createParams;
createParams.format = Gfx::TEX_IMG_RGBA; createParams.format = TEX_IMG_RGBA;
createParams.minFilter = Gfx::TEX_MIN_FILTER_NEAREST; createParams.minFilter = TEX_MIN_FILTER_NEAREST;
createParams.magFilter = Gfx::TEX_MAG_FILTER_NEAREST; createParams.magFilter = TEX_MAG_FILTER_NEAREST;
createParams.mipmap = false; createParams.mipmap = false;
Gfx::Texture tex = m_device->CreateTexture(&data, createParams); Texture tex = m_device->CreateTexture(&data, createParams);
data.surface = nullptr; data.surface = nullptr;
@ -802,3 +803,6 @@ Gfx::CharTexture Gfx::CText::CreateCharTexture(Gfx::UTF8Char ch, Gfx::CachedFont
return texture; return texture;
} }
} // namespace Gfx

View File

@ -17,18 +17,22 @@
/** /**
* \file graphics/engine/text.h * \file graphics/engine/text.h
* \brief Text rendering - Gfx::CText class * \brief Text rendering - CText class
*/ */
#pragma once #pragma once
#include "math/point.h" #include "math/point.h"
#include <vector> #include <vector>
#include <map> #include <map>
class CInstanceManager; class CInstanceManager;
// Graphics module namespace
namespace Gfx { namespace Gfx {
class CEngine; class CEngine;
@ -40,8 +44,9 @@ const float FONT_SIZE_SMALL = 10.0f;
const float FONT_SIZE_BIG = 15.0f; const float FONT_SIZE_BIG = 15.0f;
/** /**
\enum TextAlign * \enum TextAlign
\brief Type of text alignment */ * \brief Type of text alignment
*/
enum TextAlign enum TextAlign
{ {
TEXT_ALIGN_RIGHT, TEXT_ALIGN_RIGHT,
@ -55,10 +60,11 @@ enum TextAlign
typedef short FontMetaChar; typedef short FontMetaChar;
/** /**
\enum FontType * \enum FontType
\brief Type of font * \brief Type of font
*
Bitmask in lower 4 bits (mask 0x00f) */ * Bitmask in lower 4 bits (mask 0x00f)
*/
enum FontType enum FontType
{ {
//! Flag for bold font subtype //! Flag for bold font subtype
@ -85,12 +91,13 @@ enum FontType
}; };
/** /**
\enum FontTitle * \enum FontTitle
\brief Size of font title * \brief Size of font title
*
Used internally by CEdit * Used internally by CEdit
*
Bitmask in 2 bits left shifted 4 (mask 0x030) */ * Bitmask in 2 bits left shifted 4 (mask 0x030)
*/
enum FontTitle enum FontTitle
{ {
FONT_TITLE_BIG = 0x01 << 4, FONT_TITLE_BIG = 0x01 << 4,
@ -99,10 +106,11 @@ enum FontTitle
}; };
/** /**
\enum FontHighlight * \enum FontHighlight
\brief Type of color highlight for text * \brief Type of color highlight for text
*
Bitmask in 3 bits left shifted 6 (mask 0x1c0) */ * Bitmask in 3 bits left shifted 6 (mask 0x1c0)
*/
enum FontHighlight enum FontHighlight
{ {
FONT_HIGHLIGHT_NONE = 0x00 << 6, FONT_HIGHLIGHT_NONE = 0x00 << 6,
@ -116,8 +124,9 @@ enum FontHighlight
}; };
/** /**
\enum FontMask * \enum FontMask
\brief Masks in FontMetaChar for different attributes */ * \brief Masks in FontMetaChar for different attributes
*/
enum FontMask enum FontMask
{ {
//! Mask for FontType //! Mask for FontType
@ -132,10 +141,11 @@ enum FontMask
/** /**
\struct UTF8Char * \struct UTF8Char
\brief UTF-8 character in font cache * \brief UTF-8 character in font cache
*
Only 3-byte chars are supported */ * Only 3-byte chars are supported
*/
struct UTF8Char struct UTF8Char
{ {
char c1, c2, c3; char c1, c2, c3;
@ -165,8 +175,9 @@ struct UTF8Char
}; };
/** /**
\struct CharTexture * \struct CharTexture
\brief Texture of font character */ * \brief Texture of font character
*/
struct CharTexture struct CharTexture
{ {
unsigned int id; unsigned int id;
@ -180,8 +191,9 @@ struct CharTexture
struct CachedFont; struct CachedFont;
/** /**
\struct MultisizeFont * \struct MultisizeFont
\brief Font with multiple possible sizes */ * \brief Font with multiple possible sizes
*/
struct MultisizeFont struct MultisizeFont
{ {
std::string fileName; std::string fileName;
@ -192,28 +204,28 @@ struct MultisizeFont
}; };
/** /**
\class CText * \class CText
\brief Text rendering engine * \brief Text rendering engine
*
CText is responsible for drawing text in 2D interface. Font rendering is done using * CText is responsible for drawing text in 2D interface. Font rendering is done using
textures generated by SDL_ttf from TTF font files. * textures generated by SDL_ttf from TTF font files.
*
All functions rendering text are divided into two types: * All functions rendering text are divided into two types:
- single font - function takes a single Gfx::FontType argument that (along with size) * - single font - function takes a single FontType argument that (along with size)
determines the font to be used for all characters, * determines the font to be used for all characters,
- multi-font - function takes the text as one argument and a std::vector of FontMetaChar * - 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) * with per-character formatting information (font, highlights and some other info used by CEdit)
*
All font rendering is done in UTF-8. * All font rendering is done in UTF-8.
*/ */
class CText class CText
{ {
public: public:
CText(CInstanceManager *iMan, Gfx::CEngine* engine); CText(CInstanceManager *iMan, CEngine* engine);
~CText(); ~CText();
//! Sets the device to be used //! Sets the device to be used
void SetDevice(Gfx::CDevice *device); void SetDevice(CDevice *device);
//! Returns the last encountered error //! Returns the last encountered error
std::string GetError(); std::string GetError();
@ -227,75 +239,76 @@ public:
void FlushCache(); void FlushCache();
//! Draws text (multi-format) //! Draws text (multi-format)
void DrawText(const std::string &text, const std::vector<Gfx::FontMetaChar> &format, void DrawText(const std::string &text, const std::vector<FontMetaChar> &format,
float size, Math::Point pos, float width, Gfx::TextAlign align, float size, Math::Point pos, float width, TextAlign align,
int eol); int eol);
//! Draws text (one font) //! Draws text (one font)
void DrawText(const std::string &text, Gfx::FontType font, void DrawText(const std::string &text, FontType font,
float size, Math::Point pos, float width, Gfx::TextAlign align, float size, Math::Point pos, float width, TextAlign align,
int eol); int eol);
//! Calculates dimensions for text (multi-format) //! Calculates dimensions for text (multi-format)
void SizeText(const std::string &text, const std::vector<Gfx::FontMetaChar> &format, void SizeText(const std::string &text, const std::vector<FontMetaChar> &format,
float size, Math::Point pos, Gfx::TextAlign align, float size, Math::Point pos, TextAlign align,
Math::Point &start, Math::Point &end); Math::Point &start, Math::Point &end);
//! Calculates dimensions for text (one font) //! Calculates dimensions for text (one font)
void SizeText(const std::string &text, Gfx::FontType font, void SizeText(const std::string &text, FontType font,
float size, Math::Point pos, Gfx::TextAlign align, float size, Math::Point pos, TextAlign align,
Math::Point &start, Math::Point &end); Math::Point &start, Math::Point &end);
//! Returns the ascent font metric //! Returns the ascent font metric
float GetAscent(Gfx::FontType font, float size); float GetAscent(FontType font, float size);
//! Returns the descent font metric //! Returns the descent font metric
float GetDescent(Gfx::FontType font, float size); float GetDescent(FontType font, float size);
//! Returns the height font metric //! Returns the height font metric
float GetHeight(Gfx::FontType font, float size); float GetHeight(FontType font, float size);
//! Returns width of string (multi-format) //! Returns width of string (multi-format)
float GetStringWidth(const std::string &text, 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) //! 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 //! 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) //! 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); float size, float width);
//! Justifies a line of text (one font) //! 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) //! 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); float size, float offset);
//! Returns the most suitable position to a given offset (one font) //! 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: protected:
Gfx::CachedFont* GetOrOpenFont(Gfx::FontType type, float size); CachedFont* GetOrOpenFont(FontType type, float size);
Gfx::CharTexture CreateCharTexture(Gfx::UTF8Char ch, Gfx::CachedFont* font); 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); 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); float size, Math::Point pos, float width, int eol);
void DrawHighlight(Gfx::FontHighlight hl, Math::Point pos, Math::Point size); void DrawHighlight(FontHighlight hl, Math::Point pos, Math::Point size);
void DrawChar(Gfx::UTF8Char ch, Gfx::FontType font, float size, Math::Point &pos); void DrawChar(UTF8Char ch, FontType font, float size, Math::Point &pos);
protected: protected:
CInstanceManager* m_iMan; CInstanceManager* m_iMan;
Gfx::CEngine* m_engine; CEngine* m_engine;
Gfx::CDevice* m_device; CDevice* m_device;
std::string m_error; std::string m_error;
float m_defaultSize; float m_defaultSize;
std::string m_fontPath; 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; int m_lastFontSize;
Gfx::CachedFont* m_lastCachedFont; CachedFont* m_lastCachedFont;
}; };
}; // namespace Gfx
} // namespace Gfx

View File

@ -15,27 +15,34 @@
// * You should have received a copy of the GNU General Public License // * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/. // * along with this program. If not, see http://www.gnu.org/licenses/.
// water.cpp
#include "graphics/engine/water.h" #include "graphics/engine/water.h"
#include "common/iman.h" #include "common/iman.h"
#include "common/logger.h" #include "common/logger.h"
#include "graphics/core/device.h" #include "graphics/core/device.h"
#include "graphics/engine/engine.h" #include "graphics/engine/engine.h"
#include "graphics/engine/terrain.h" #include "graphics/engine/terrain.h"
#include "math/geometry.h" #include "math/geometry.h"
#include "object/object.h" #include "object/object.h"
#include "sound/sound.h" #include "sound/sound.h"
// Graphics module namespace
namespace Gfx {
const int WATERLINE_PREALLOCATE_COUNT = 500; const int WATERLINE_PREALLOCATE_COUNT = 500;
// TODO: remove the limit? // TODO: remove the limit?
const int VAPOR_SIZE = 10; const int VAPOR_SIZE = 10;
Gfx::CWater::CWater(CInstanceManager* iMan, Gfx::CEngine* engine) CWater::CWater(CInstanceManager* iMan, CEngine* engine)
{ {
m_iMan = iMan; m_iMan = iMan;
m_iMan->AddInstance(CLASS_WATER, this); m_iMan->AddInstance(CLASS_WATER, this);
@ -50,15 +57,15 @@ Gfx::CWater::CWater(CInstanceManager* iMan, Gfx::CEngine* engine)
m_level = 0.0f; m_level = 0.0f;
m_draw = true; m_draw = true;
m_lava = false; 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_subdiv = 4;
m_lines.reserve(WATERLINE_PREALLOCATE_COUNT); 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_iMan = nullptr;
m_engine = 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) if (event.type == EVENT_FRAME)
return EventFrame(event); return EventFrame(event);
@ -76,7 +83,7 @@ bool Gfx::CWater::EventProcess(const Event &event)
return true; return true;
} }
bool Gfx::CWater::EventFrame(const Event &event) bool CWater::EventFrame(const Event &event)
{ {
if (m_engine->GetPause()) return true; if (m_engine->GetPause()) return true;
@ -90,10 +97,10 @@ bool Gfx::CWater::EventFrame(const Event &event)
return true; return true;
} }
void Gfx::CWater::LavaFrame(float rTime) void CWater::LavaFrame(float rTime)
{ {
if (m_particule == nullptr) 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++) for (int i = 0; i < static_cast<int>( m_vapors.size() ); i++)
VaporFrame(i, rTime); VaporFrame(i, rTime);
@ -123,29 +130,29 @@ void Gfx::CWater::LavaFrame(float rTime)
level = Math::Rand(); level = Math::Rand();
if (level < 0.8f) 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; m_lastLava = m_time;
} }
else if (level < 0.9f) 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; m_lastLava = m_time;
} }
else 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; m_lastLava = m_time;
} }
} }
} }
} }
void Gfx::CWater::VaporFlush() void CWater::VaporFlush()
{ {
m_vapors.clear(); 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++) 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; return false;
} }
void Gfx::CWater::VaporFrame(int i, float rTime) void CWater::VaporFrame(int i, float rTime)
{ {
m_vapors[i].time += 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) Math::Point &uv1, Math::Point &uv2)
{ {
float t1 = m_time*1.5f + pos.x*0.1f * pos.z*0.2f; 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! */ /** This surface prevents to see the sky (background) underwater! */
void Gfx::CWater::DrawBack() void CWater::DrawBack()
{ {
if (! m_draw) return; if (! m_draw) return;
if (m_type[0] == WATER_NULL) return; if (m_type[0] == WATER_NULL) return;
@ -267,16 +274,16 @@ void Gfx::CWater::DrawBack()
Math::Vector eye = m_engine->GetEyePt(); Math::Vector eye = m_engine->GetEyePt();
Math::Vector lookat = m_engine->GetLookatPt(); Math::Vector lookat = m_engine->GetLookatPt();
Gfx::Material material; Material material;
material.diffuse = m_diffuse; material.diffuse = m_diffuse;
material.ambient = m_ambient; material.ambient = m_ambient;
m_engine->SetMaterial(material); m_engine->SetMaterial(material);
m_engine->SetTexture("", 0); // TODO: disable texturing 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); float deep = m_engine->GetDeepView(0);
m_engine->SetDeepView(deep*2.0f, 0); m_engine->SetDeepView(deep*2.0f, 0);
@ -285,7 +292,7 @@ void Gfx::CWater::DrawBack()
Math::Matrix matrix; Math::Matrix matrix;
matrix.LoadIdentity(); matrix.LoadIdentity();
device->SetTransform(Gfx::TRANSFORM_WORLD, matrix); device->SetTransform(TRANSFORM_WORLD, matrix);
Math::Vector p; Math::Vector p;
p.x = eye.x; p.x = eye.x;
@ -308,15 +315,15 @@ void Gfx::CWater::DrawBack()
n.z = (lookat.z-eye.z)/dist; n.z = (lookat.z-eye.z)/dist;
n.y = 0.0f; n.y = 0.0f;
Gfx::Vertex vertices[4] = Vertex vertices[4] =
{ {
Gfx::Vertex(Math::Vector(p1.x, p2.y, p1.z), n), Vertex(Math::Vector(p1.x, p2.y, p1.z), n),
Gfx::Vertex(Math::Vector(p1.x, p1.y, p1.z), n), Vertex(Math::Vector(p1.x, p1.y, p1.z), n),
Gfx::Vertex(Math::Vector(p2.x, p2.y, p2.z), n), Vertex(Math::Vector(p2.x, p2.y, p2.z), n),
Gfx::Vertex(Math::Vector(p2.x, p1.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->AddStatisticTriangle(2);
m_engine->SetDeepView(deep, 0); m_engine->SetDeepView(deep, 0);
@ -324,26 +331,26 @@ void Gfx::CWater::DrawBack()
m_engine->UpdateMatProj(); // gives the initial depth of view m_engine->UpdateMatProj(); // gives the initial depth of view
} }
void Gfx::CWater::DrawSurf() void CWater::DrawSurf()
{ {
if (! m_draw) return; if (! m_draw) return;
if (m_type[0] == Gfx::WATER_NULL) return; if (m_type[0] == WATER_NULL) return;
if (m_lines.empty()) 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(); Math::Vector eye = m_engine->GetEyePt();
int rankview = m_engine->GetRankView(); int rankview = m_engine->GetRankView();
bool under = ( rankview == 1); bool under = ( rankview == 1);
Gfx::CDevice* device = m_engine->GetDevice(); CDevice* device = m_engine->GetDevice();
Math::Matrix matrix; Math::Matrix matrix;
matrix.LoadIdentity(); matrix.LoadIdentity();
device->SetTransform(Gfx::TRANSFORM_WORLD, matrix); device->SetTransform(TRANSFORM_WORLD, matrix);
Gfx::Material material; Material material;
material.diffuse = m_diffuse; material.diffuse = m_diffuse;
material.ambient = m_ambient; material.ambient = m_ambient;
m_engine->SetMaterial(material); m_engine->SetMaterial(material);
@ -352,18 +359,18 @@ void Gfx::CWater::DrawSurf()
m_engine->SetTexture(m_fileName, 1); m_engine->SetTexture(m_fileName, 1);
if (m_type[rankview] == WATER_TT) 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) 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) 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) 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 size = m_brickSize/2.0f;
float sizez = 0.0f; float sizez = 0.0f;
@ -398,14 +405,14 @@ void Gfx::CWater::DrawSurf()
p.y = pos.y; p.y = pos.y;
AdjustLevel(p, n, uv1, uv2); AdjustLevel(p, n, uv1, uv2);
if (under) n.y = -n.y; 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.x = pos.x-size;
p.z = pos.z+sizez; p.z = pos.z+sizez;
p.y = pos.y; p.y = pos.y;
AdjustLevel(p, n, uv1, uv2); AdjustLevel(p, n, uv1, uv2);
if (under) n.y = -n.y; 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++) for (int j = 0; j < m_lines[i].len; j++)
{ {
@ -414,24 +421,24 @@ void Gfx::CWater::DrawSurf()
p.y = pos.y; p.y = pos.y;
AdjustLevel(p, n, uv1, uv2); AdjustLevel(p, n, uv1, uv2);
if (under) n.y = -n.y; 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.x = pos.x+size;
p.z = pos.z+sizez; p.z = pos.z+sizez;
p.y = pos.y; p.y = pos.y;
AdjustLevel(p, n, uv1, uv2); AdjustLevel(p, n, uv1, uv2);
if (under) n.y = -n.y; 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; 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); m_engine->AddStatisticTriangle(vertexIndex - 2);
} }
} }
bool Gfx::CWater::GetWater(int x, int y) bool CWater::GetWater(int x, int y)
{ {
x *= m_subdiv; x *= m_subdiv;
y *= m_subdiv; y *= m_subdiv;
@ -455,9 +462,9 @@ bool Gfx::CWater::GetWater(int x, int y)
return false; 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.x = x;
line.y = y; line.y = y;
@ -472,8 +479,8 @@ void Gfx::CWater::CreateLine(int x, int y, int len)
m_lines.push_back(line); m_lines.push_back(line);
} }
void Gfx::CWater::Create(Gfx::WaterType type1, Gfx::WaterType type2, const std::string& fileName, void CWater::Create(WaterType type1, WaterType type2, const std::string& fileName,
Gfx::Color diffuse, Gfx::Color ambient, Color diffuse, Color ambient,
float level, float glint, Math::Vector eddy) float level, float glint, Math::Vector eddy)
{ {
m_type[0] = type1; 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[0] = WATER_NULL;
m_type[1] = Gfx::WATER_NULL; m_type[1] = WATER_NULL;
m_level = 0.0f; m_level = 0.0f;
m_lava = false; m_lava = false;
} }
void Gfx::CWater::SetLevel(float level) void CWater::SetLevel(float level)
{ {
m_level = level; m_level = level;
@ -550,12 +557,12 @@ void Gfx::CWater::SetLevel(float level)
m_level, m_glint, m_eddy); m_level, m_glint, m_eddy);
} }
float Gfx::CWater::GetLevel() float CWater::GetLevel()
{ {
return m_level; return m_level;
} }
float Gfx::CWater::GetLevel(CObject* object) float CWater::GetLevel(CObject* object)
{ {
ObjectType type = object->GetType(); ObjectType type = object->GetType();
@ -599,17 +606,17 @@ float Gfx::CWater::GetLevel(CObject* object)
return m_level; return m_level;
} }
void Gfx::CWater::SetLava(bool lava) void CWater::SetLava(bool lava)
{ {
m_lava = lava; m_lava = lava;
} }
bool Gfx::CWater::GetLava() bool CWater::GetLava()
{ {
return m_lava; return m_lava;
} }
void Gfx::CWater::AdjustEye(Math::Vector &eye) void CWater::AdjustEye(Math::Vector &eye)
{ {
if (m_lava) if (m_lava)
{ {
@ -624,3 +631,5 @@ void Gfx::CWater::AdjustEye(Math::Vector &eye)
} }
} }
} // namespace Gfx

View File

@ -17,12 +17,14 @@
/** /**
* \file graphics/engine/water.h * \file graphics/engine/water.h
* \brief Water rendering - Gfx::CWater class * \brief Water rendering - CWater class
*/ */
#pragma once #pragma once
#include "common/event.h" #include "common/event.h"
#include "graphics/engine/particle.h" #include "graphics/engine/particle.h"
@ -30,8 +32,10 @@ class CInstanceManager;
class CSoundInterface; class CSoundInterface;
// Graphics module namespace
namespace Gfx { namespace Gfx {
class CEngine; class CEngine;
class CTerrain; class CTerrain;
@ -65,7 +69,7 @@ struct WaterLine
struct WaterVapor struct WaterVapor
{ {
bool used; bool used;
Gfx::ParticleType type; ParticleType type;
Math::Vector pos; Math::Vector pos;
float delay; float delay;
float time; float time;
@ -74,7 +78,7 @@ struct WaterVapor
WaterVapor() WaterVapor()
{ {
used = false; used = false;
type = Gfx::PARTIWATER; type = PARTIWATER;
delay = time = last = 0.0f; delay = time = last = 0.0f;
} }
}; };
@ -113,16 +117,16 @@ enum WaterType
class CWater class CWater
{ {
public: public:
CWater(CInstanceManager* iMan, Gfx::CEngine* engine); CWater(CInstanceManager* iMan, CEngine* engine);
~CWater(); ~CWater();
void SetDevice(Gfx::CDevice* device); void SetDevice(CDevice* device);
bool EventProcess(const Event &event); bool EventProcess(const Event &event);
//! Removes all the water //! Removes all the water
void Flush(); void Flush();
//! Creates all expanses of water //! Creates all expanses of water
void Create(WaterType type1, WaterType type2, const std::string& fileName, 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 //! Draw the back surface of the water
void DrawBack(); void DrawBack();
//! Draws the flat surface of the water //! Draws the flat surface of the water
@ -165,10 +169,10 @@ protected:
protected: protected:
CInstanceManager* m_iMan; CInstanceManager* m_iMan;
Gfx::CEngine* m_engine; CEngine* m_engine;
Gfx::CDevice* m_device; CDevice* m_device;
Gfx::CTerrain* m_terrain; CTerrain* m_terrain;
Gfx::CParticle* m_particule; CParticle* m_particule;
CSoundInterface* m_sound; CSoundInterface* m_sound;
WaterType m_type[2]; WaterType m_type[2];
@ -180,9 +184,9 @@ protected:
//! Amplitude of swirls //! Amplitude of swirls
Math::Vector m_eddy; Math::Vector m_eddy;
//! Diffuse color //! Diffuse color
Gfx::Color m_diffuse; Color m_diffuse;
//! Ambient color //! Ambient color
Gfx::Color m_ambient; Color m_ambient;
float m_time; float m_time;
float m_lastLava; float m_lastLava;
int m_subdiv; int m_subdiv;
@ -197,7 +201,8 @@ protected:
bool m_draw; bool m_draw;
bool m_lava; bool m_lava;
Gfx::Color m_color; Color m_color;
}; };
}; // namespace Gfx
} // namespace Gfx

File diff suppressed because it is too large Load Diff

View File

@ -16,7 +16,7 @@
/** /**
* \file graphics/opengl/gldevice.h * \file graphics/opengl/gldevice.h
* \brief OpenGL implementation - Gfx::CGLDevice class * \brief OpenGL implementation - CGLDevice class
*/ */
#pragma once #pragma once
@ -29,6 +29,7 @@
#include <set> #include <set>
// Graphics module namespace
namespace Gfx { namespace Gfx {
/** /**
@ -70,10 +71,10 @@ struct GLDevicePrivate;
Because of that, CGLDeviceConfig is outside the CDevice class and must be set Because of that, CGLDeviceConfig is outside the CDevice class and must be set
in CApplication. in CApplication.
*/ */
class CGLDevice : public Gfx::CDevice class CGLDevice : public CDevice
{ {
public: public:
CGLDevice(const Gfx::GLDeviceConfig &config); CGLDevice(const GLDeviceConfig &config);
virtual ~CGLDevice(); virtual ~CGLDevice();
virtual void DebugHook(); virtual void DebugHook();
@ -81,82 +82,82 @@ public:
virtual bool Create(); virtual bool Create();
virtual void Destroy(); virtual void Destroy();
void ConfigChanged(const Gfx::GLDeviceConfig &newConfig); void ConfigChanged(const GLDeviceConfig &newConfig);
virtual void BeginScene(); virtual void BeginScene();
virtual void EndScene(); virtual void EndScene();
virtual void Clear(); virtual void Clear();
virtual void SetTransform(Gfx::TransformType type, const Math::Matrix &matrix); virtual void SetTransform(TransformType type, const Math::Matrix &matrix);
virtual const Math::Matrix& GetTransform(Gfx::TransformType type); virtual const Math::Matrix& GetTransform(TransformType type);
virtual void MultiplyTransform(Gfx::TransformType type, const Math::Matrix &matrix); virtual void MultiplyTransform(TransformType type, const Math::Matrix &matrix);
virtual void SetMaterial(const Gfx::Material &material); virtual void SetMaterial(const Material &material);
virtual const Gfx::Material& GetMaterial(); virtual const Material& GetMaterial();
virtual int GetMaxLightCount(); virtual int GetMaxLightCount();
virtual void SetLight(int index, const Gfx::Light &light); virtual void SetLight(int index, const Light &light);
virtual const Gfx::Light& GetLight(int index); virtual const Light& GetLight(int index);
virtual void SetLightEnabled(int index, bool enabled); virtual void SetLightEnabled(int index, bool enabled);
virtual bool GetLightEnabled(int index); virtual bool GetLightEnabled(int index);
virtual Gfx::Texture CreateTexture(CImage *image, const Gfx::TextureCreateParams &params); virtual Texture CreateTexture(CImage *image, const TextureCreateParams &params);
virtual Gfx::Texture CreateTexture(ImageData *data, const Gfx::TextureCreateParams &params); virtual Texture CreateTexture(ImageData *data, const TextureCreateParams &params);
virtual void DestroyTexture(const Gfx::Texture &texture); virtual void DestroyTexture(const Texture &texture);
virtual void DestroyAllTextures(); virtual void DestroyAllTextures();
virtual int GetMaxTextureCount(); 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 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 void SetTextureEnabled(int index, bool enabled);
virtual bool GetTextureEnabled(int index); virtual bool GetTextureEnabled(int index);
virtual void SetTextureStageParams(int index, const Gfx::TextureStageParams &params); virtual void SetTextureStageParams(int index, const TextureStageParams &params);
virtual Gfx::TextureStageParams GetTextureStageParams(int index); virtual TextureStageParams GetTextureStageParams(int index);
virtual void SetTextureFactor(const Gfx::Color &color); virtual void SetTextureFactor(const Color &color);
virtual Gfx::Color GetTextureFactor(); virtual Color GetTextureFactor();
virtual void DrawPrimitive(Gfx::PrimitiveType type, const Gfx::Vertex *vertices, int vertexCount); virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices, int vertexCount);
virtual void DrawPrimitive(Gfx::PrimitiveType type, const Gfx::VertexCol *vertices, int vertexCount); virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices, int vertexCount);
virtual void DrawPrimitive(Gfx::PrimitiveType type, const Gfx::VertexTex2 *vertices, int vertexCount); virtual void DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, int vertexCount);
virtual int ComputeSphereVisibility(const Math::Vector &center, float radius); virtual int ComputeSphereVisibility(const Math::Vector &center, float radius);
virtual void SetRenderState(Gfx::RenderState state, bool enabled); virtual void SetRenderState(RenderState state, bool enabled);
virtual bool GetRenderState(Gfx::RenderState state); virtual bool GetRenderState(RenderState state);
virtual void SetDepthTestFunc(Gfx::CompFunc func); virtual void SetDepthTestFunc(CompFunc func);
virtual Gfx::CompFunc GetDepthTestFunc(); virtual CompFunc GetDepthTestFunc();
virtual void SetDepthBias(float factor); virtual void SetDepthBias(float factor);
virtual float GetDepthBias(); virtual float GetDepthBias();
virtual void SetAlphaTestFunc(Gfx::CompFunc func, float refValue); virtual void SetAlphaTestFunc(CompFunc func, float refValue);
virtual void GetAlphaTestFunc(Gfx::CompFunc &func, float &refValue); virtual void GetAlphaTestFunc(CompFunc &func, float &refValue);
virtual void SetBlendFunc(Gfx::BlendFunc srcBlend, Gfx::BlendFunc dstBlend); virtual void SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend);
virtual void GetBlendFunc(Gfx::BlendFunc &srcBlend, Gfx::BlendFunc &dstBlend); virtual void GetBlendFunc(BlendFunc &srcBlend, BlendFunc &dstBlend);
virtual void SetClearColor(const Gfx::Color &color); virtual void SetClearColor(const Color &color);
virtual Gfx::Color GetClearColor(); virtual Color GetClearColor();
virtual void SetGlobalAmbient(const Gfx::Color &color); virtual void SetGlobalAmbient(const Color &color);
virtual Gfx::Color GetGlobalAmbient(); virtual Color GetGlobalAmbient();
virtual void SetFogParams(Gfx::FogMode mode, const 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(Gfx::FogMode &mode, Gfx::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 void SetCullMode(CullMode mode);
virtual Gfx::CullMode GetCullMode(); virtual CullMode GetCullMode();
virtual void SetShadeModel(Gfx::ShadeModel model); virtual void SetShadeModel(ShadeModel model);
virtual Gfx::ShadeModel GetShadeModel(); virtual ShadeModel GetShadeModel();
virtual void SetFillMode(Gfx::FillMode mode) ; virtual void SetFillMode(FillMode mode) ;
virtual Gfx::FillMode GetFillMode(); virtual FillMode GetFillMode();
private: private:
//! Updates internal modelview matrix //! Updates internal modelview matrix
@ -166,7 +167,7 @@ private:
private: private:
//! Current config //! Current config
Gfx::GLDeviceConfig m_config; GLDeviceConfig m_config;
//! Current world matrix //! Current world matrix
Math::Matrix m_worldMat; Math::Matrix m_worldMat;
@ -178,26 +179,27 @@ private:
Math::Matrix m_projectionMat; Math::Matrix m_projectionMat;
//! The current material //! The current material
Gfx::Material m_material; Material m_material;
//! Whether lighting is enabled //! Whether lighting is enabled
bool m_lighting; bool m_lighting;
//! Current lights //! Current lights
std::vector<Gfx::Light> m_lights; std::vector<Light> m_lights;
//! Current lights enable status //! Current lights enable status
std::vector<bool> m_lightsEnabled; std::vector<bool> m_lightsEnabled;
//! Whether texturing is enabled in general //! Whether texturing is enabled in general
bool m_texturing; bool m_texturing;
//! Current textures; \c NULL value means unassigned //! Current textures; \c NULL value means unassigned
std::vector<Gfx::Texture> m_currentTextures; std::vector<Texture> m_currentTextures;
//! Current texture stages enable status //! Current texture stages enable status
std::vector<bool> m_texturesEnabled; std::vector<bool> m_texturesEnabled;
//! Current texture params //! Current texture params
std::vector<Gfx::TextureStageParams> m_textureStageParams; std::vector<TextureStageParams> m_textureStageParams;
//! Set of all created textures //! Set of all created textures
std::set<Gfx::Texture> m_allTextures; std::set<Texture> m_allTextures;
}; };
}; // namespace Gfx
} // namespace Gfx

View File

@ -21,9 +21,10 @@
#pragma once #pragma once
#include "const.h"
#include "func.h" #include "math/const.h"
#include "point.h" #include "math/func.h"
#include "vector.h" #include "math/point.h"
#include "matrix.h" #include "math/vector.h"
#include "geometry.h" #include "math/matrix.h"
#include "math/geometry.h"

View File

@ -21,12 +21,13 @@
#pragma once #pragma once
#include <cmath> #include <cmath>
// Math module namespace // Math module namespace
namespace Math namespace Math {
{
//! Tolerance level -- minimum accepted float value //! Tolerance level -- minimum accepted float value
const float TOLERANCE = 1e-6f; const float TOLERANCE = 1e-6f;
@ -50,4 +51,5 @@ const float RAD_TO_DEG = 57.29577951308232286465f;
//! Natural logarithm of 2 //! Natural logarithm of 2
const float LOG_2 = log(2.0f); const float LOG_2 = log(2.0f);
}; // namespace Math
} // namespace Math

View File

@ -22,15 +22,17 @@
#pragma once #pragma once
#include "const.h"
#include "math/const.h"
#include <cmath> #include <cmath>
#include <cstdlib> #include <cstdlib>
// Math module namespace // Math module namespace
namespace Math namespace Math {
{
//! Compares \a a and \a b within \a tolerance //! Compares \a a and \a b within \a tolerance
inline bool IsEqual(float a, float b, float tolerance = Math::TOLERANCE) inline bool IsEqual(float a, float b, float tolerance = Math::TOLERANCE)
@ -253,4 +255,5 @@ inline float Bounce(float progress, float middle = 0.3f, float bounce = 0.4f)
} }
} }
}; // namespace Math
} // namespace Math

View File

@ -22,19 +22,21 @@
#pragma once #pragma once
#include "const.h"
#include "func.h" #include "math/const.h"
#include "point.h" #include "math/func.h"
#include "vector.h" #include "math/point.h"
#include "matrix.h" #include "math/matrix.h"
#include "math/vector.h"
#include <cmath> #include <cmath>
#include <cstdlib> #include <cstdlib>
// Math module namespace // Math module namespace
namespace Math namespace Math {
{
//! Returns py up on the line \a a - \a b //! Returns py up on the line \a a - \a b
inline float MidPoint(const Math::Point &a, const Math::Point &b, float px) inline float MidPoint(const Math::Point &a, const Math::Point &b, float px)
@ -617,4 +619,5 @@ inline Math::Vector RotateView(Math::Vector center, float angleH, float angleV,
return eye+center; return eye+center;
} }
}; // namespace Math
} // namespace Math

View File

@ -21,6 +21,8 @@
#pragma once #pragma once
// Math module namespace
namespace Math { namespace Math {
/** /**
@ -39,4 +41,5 @@ struct IntPoint
IntPoint(int aX = 0, int aY = 0) : x(aX), y(aY) {} IntPoint(int aX = 0, int aY = 0) : x(aX), y(aY) {}
}; };
}; // namespace Math
} // namespace Math

View File

@ -21,17 +21,18 @@
#pragma once #pragma once
#include "const.h"
#include "func.h" #include "math/const.h"
#include "vector.h" #include "math/func.h"
#include "math/vector.h"
#include <cmath> #include <cmath>
#include <cassert> #include <cassert>
// Math module namespace // Math module namespace
namespace Math namespace Math {
{
/** /**
* \struct Matrix math/matrix.h * \struct Matrix math/matrix.h
@ -459,4 +460,5 @@ inline Math::Vector MatrixVectorMultiply(const Math::Matrix &m, const Math::Vect
return Math::Vector(x, y, z); return Math::Vector(x, y, z);
} }
}; // namespace Math
} // namespace Math

View File

@ -21,16 +21,18 @@
#pragma once #pragma once
#include "const.h"
#include "func.h" #include "math/const.h"
#include "math/func.h"
#include <cmath> #include <cmath>
#include <sstream> #include <sstream>
// Math module namespace // Math module namespace
namespace Math namespace Math {
{
/** /**
* \struct Point * \struct Point
@ -187,4 +189,5 @@ inline float Distance(const Point &a, const Point &b)
return sqrtf((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y)); return sqrtf((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
} }
}; // namespace Math
} // namespace Math

View File

@ -5,6 +5,7 @@ set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -Wall -Wold-style-cast -std=gnu++0x")
include_directories( include_directories(
. .
../..
../../.. ../../..
${GTEST_DIR}/include ${GTEST_DIR}/include
) )

View File

@ -21,16 +21,18 @@
#pragma once #pragma once
#include "const.h"
#include "func.h" #include "math/const.h"
#include "math/func.h"
#include <cmath> #include <cmath>
#include <sstream> #include <sstream>
// Math module namespace // Math module namespace
namespace Math namespace Math {
{
/** /**
* \struct Vector * \struct Vector
@ -277,4 +279,5 @@ inline Vector Clamp(const Vector &vec, const Vector &min, const Vector &max)
return clamped; return clamped;
} }
}; // namespace Math
} // namespace Math