changed paths for models and levels. Now it's possible to load level. Merged with latest trunk

dev-ui
Zaba999 2012-09-20 23:04:37 +02:00
commit 34a11021da
55 changed files with 3589 additions and 3395 deletions

View File

@ -11,6 +11,14 @@ find_package(SDL_image 1.2 REQUIRED)
find_package(SDL_ttf 2.0 REQUIRED)
find_package(PNG 1.2 REQUIRED)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
set(Boost_ADDITIONALVERSION "1.51" "1.51.0")
find_package(Boost COMPONENTS system filesystem REQUIRED)
# GLEW requirement depends on platform
# By default it is auto detected
# This setting may be used to override

View File

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

View File

@ -15,16 +15,18 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
// app.cpp
#include "app/app.h"
#include "app/system.h"
#include "common/logger.h"
#include "common/iman.h"
#include "common/image.h"
#include "common/key.h"
#include "graphics/opengl/gldevice.h"
#include "object/robotmain.h"
@ -35,6 +37,7 @@
#include <stdlib.h>
#include <libintl.h>
#include <unistd.h>
template<> CApplication* CSingleton<CApplication>::mInstance = nullptr;
@ -116,6 +119,8 @@ CApplication::CApplication()
m_joystickEnabled = false;
m_mouseMode = MOUSE_SYSTEM;
m_kmodState = 0;
m_mouseButtonsState = 0;
m_trackedKeys = 0;
@ -123,6 +128,8 @@ CApplication::CApplication()
m_dataPath = "./data";
m_language = LANG_ENGLISH;
m_lowCPU = true;
}
CApplication::~CApplication()
@ -649,8 +656,7 @@ void CApplication::UpdateMouse()
{
Math::IntPoint pos;
SDL_GetMouseState(&pos.x, &pos.y);
m_systemMousePos = m_engine->WindowToInterfaceCoords(pos);
m_engine->SetMousePos(m_systemMousePos);
m_mousePos = m_engine->WindowToInterfaceCoords(pos);
}
int CApplication::Run()
@ -661,6 +667,8 @@ int CApplication::Run()
GetCurrentTimeStamp(m_lastTimeStamp);
GetCurrentTimeStamp(m_curTimeStamp);
MoveMouse(Math::Point(0.5f, 0.5f)); // center mouse on start
while (true)
{
// To be sure no old event remains
@ -752,6 +760,11 @@ int CApplication::Run()
// Update simulation state
StepSimulation();
if (m_lowCPU)
{
usleep(20000); // should still give plenty of fps
}
}
}
@ -889,25 +902,12 @@ bool CApplication::ProcessEvent(Event &event)
CLogger *l = GetLogger();
event.trackedKeys = m_trackedKeys;
if (GetSystemMouseVisibile())
event.mousePos = m_systemMousePos;
else
event.mousePos = m_engine->GetMousePos();
event.mousePos = m_mousePos;
if (event.type == EVENT_ACTIVE)
{
if (m_debugMode)
l->Info("Focus change: active = %s\n", event.active.gain ? "true" : "false");
/*if (m_active != event.active.gain)
{
m_active = event.active.gain;
if (m_active)
ResumeSimulation();
else
SuspendSimulation();
}*/
}
else if (event.type == EVENT_KEY_DOWN)
{
@ -1268,27 +1268,31 @@ bool CApplication::GetGrabInput()
return result == SDL_GRAB_ON;
}
void CApplication::SetSystemMouseVisible(bool visible)
void CApplication::SetMouseMode(MouseMode mode)
{
SDL_ShowCursor(visible ? SDL_ENABLE : SDL_DISABLE);
m_mouseMode = mode;
if ((m_mouseMode == MOUSE_SYSTEM) || (m_mouseMode == MOUSE_BOTH))
SDL_ShowCursor(SDL_ENABLE);
else
SDL_ShowCursor(SDL_DISABLE);
}
bool CApplication::GetSystemMouseVisibile()
MouseMode CApplication::GetMouseMode()
{
int result = SDL_ShowCursor(SDL_QUERY);
return result == SDL_ENABLE;
return m_mouseMode;
}
void CApplication::SetSystemMousePos(Math::Point pos)
Math::Point CApplication::GetMousePos()
{
return m_mousePos;
}
void CApplication::MoveMouse(Math::Point pos)
{
m_mousePos = pos;
Math::IntPoint windowPos = m_engine->InterfaceToWindowCoords(pos);
SDL_WarpMouse(windowPos.x, windowPos.y);
m_systemMousePos = pos;
}
Math::Point CApplication::GetSystemMousePos()
{
return m_systemMousePos;
}
std::vector<JoystickDevice> CApplication::GetJoystickList()
@ -1349,3 +1353,13 @@ void CApplication::SetLanguage(Language language)
{
m_language = language;
}
void CApplication::SetLowCPU(bool low)
{
m_lowCPU = low;
}
bool CApplication::GetLowCPU()
{
return m_lowCPU;
}

View File

@ -22,12 +22,15 @@
#pragma once
#include "common/global.h"
#include "common/singleton.h"
#include "graphics/core/device.h"
#include "graphics/engine/engine.h"
#include "graphics/opengl/gldevice.h"
#include <string>
#include <vector>
@ -98,6 +101,18 @@ enum ParseArgsStatus
PARSE_ARGS_HELP = 3 //! < -help requested
};
/**
* \enum MouseMode
* \brief Mode of mouse cursor
*/
enum MouseMode
{
MOUSE_SYSTEM, //! < system cursor visible; in-game cursor hidden
MOUSE_ENGINE, //! < in-game cursor visible; system cursor hidden
MOUSE_BOTH, //! < both cursors visible (only for debug)
MOUSE_NONE, //! < no cursor visible
};
struct ApplicationPrivate;
/**
@ -250,17 +265,17 @@ public:
bool GetGrabInput();
//@}
//! Management of the visiblity of system mouse cursor
//! Management of mouse mode
//@{
void SetSystemMouseVisible(bool visible);
bool GetSystemMouseVisibile();
void SetMouseMode(MouseMode mode);
MouseMode GetMouseMode();
//@}
//! Management of the position of system mouse cursor (in interface coords)
//@{
void SetSystemMousePos(Math::Point pos);
Math::Point GetSystemMousePos();
//@}
//! Returns the position of mouse cursor (in interface coords)
Math::Point GetMousePos();
//! Moves (warps) the mouse cursor to the specified position (in interface coords)
void MoveMouse(Math::Point pos);
//! Management of debug mode (prints more info in logger)
//@{
@ -277,6 +292,12 @@ public:
void SetLanguage(Language language);
//@}
//! Management of sleep in main loop (lowers CPU usage)
//@{
void SetLowCPU(bool low);
bool GetLowCPU();
//@}
protected:
//! Creates the window's SDL_Surface
bool CreateVideoSurface();
@ -357,8 +378,10 @@ protected:
//! Current state of mouse buttons (mask of button indexes)
unsigned int m_mouseButtonsState;
//! Current system mouse position
Math::Point m_systemMousePos;
//! Current mode of mouse
MouseMode m_mouseMode;
//! Current position of mouse cursor
Math::Point m_mousePos;
//! Info about current joystick device
JoystickDevice m_joystick;
@ -374,5 +397,8 @@ protected:
//! Application language
Language m_language;
//! Low cpu mode
bool m_lowCPU;
};

View File

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

View File

@ -21,14 +21,17 @@
#pragma once
#include <sstream>
// Graphics module namespace
namespace Gfx {
/**
\struct Color
\brief RGBA color */
* \struct Color
* \brief RGBA color
*/
struct Color
{
//! Red, green, blue and alpha components
@ -38,9 +41,9 @@ struct Color
explicit Color(float aR = 0.0f, float aG = 0.0f, float aB = 0.0f, float aA = 0.0f)
: r(aR), g(aG), b(aB), a(aA) {}
inline Gfx::Color Inverse() const
inline Color Inverse() const
{
return Gfx::Color(1.0f - r, 1.0f - g, 1.0f - b, 1.0f - a);
return Color(1.0f - r, 1.0f - g, 1.0f - b, 1.0f - a);
}
//! Returns the struct cast to \c float* array; use with care!
@ -64,20 +67,21 @@ struct Color
return s.str();
}
inline bool operator==(const Gfx::Color &other) const
inline bool operator==(const Color &other) const
{
return r == other.r && g == other.g && b == other.b && a == other.a;
}
inline bool operator!=(const Gfx::Color &other) const
inline bool operator!=(const Color &other) const
{
return ! this->operator==(other);
}
};
/**
\struct ColorHSV
\brief HSV color */
* \struct ColorHSV
* \brief HSV color
*/
struct ColorHSV
{
float h, s, v;
@ -96,10 +100,10 @@ struct ColorHSV
};
//! Converts a RGB color to HSV color
Gfx::ColorHSV RGB2HSV(Gfx::Color color);
ColorHSV RGB2HSV(Color color);
//! Converts a HSV color to RGB color
Gfx::Color HSV2RGB(Gfx::ColorHSV color);
Color HSV2RGB(ColorHSV color);
}; // namespace Gfx
} // namespace Gfx

View File

@ -17,7 +17,7 @@
/**
* \file graphics/core/device.h
* \brief Abstract graphics device - Gfx::CDevice class and related structs/enums
* \brief Abstract graphics device - CDevice class and related structs/enums
*/
#pragma once
@ -28,6 +28,7 @@
#include "graphics/core/material.h"
#include "graphics/core/texture.h"
#include "graphics/core/vertex.h"
#include "math/intpoint.h"
#include "math/matrix.h"
@ -38,14 +39,15 @@ class CImage;
struct ImageData;
// Graphics module namespace
namespace Gfx {
/**
\struct DeviceConfig
\brief General config for graphics device
These settings are common window options set by SDL.
*/
* \struct DeviceConfig
* \brief General config for graphics device
*
* These settings are common window options set by SDL.
*/
struct DeviceConfig
{
//! Screen size
@ -78,10 +80,11 @@ struct DeviceConfig
/**
\enum TransformType
\brief Type of transformation in rendering pipeline
These correspond to DirectX's three transformation matrices. */
* \enum TransformType
* \brief Type of transformation in rendering pipeline
*
* These correspond to DirectX's three transformation matrices.
*/
enum TransformType
{
TRANSFORM_WORLD,
@ -90,8 +93,9 @@ enum TransformType
};
/**
\enum RenderState
\brief Render states that can be enabled/disabled */
* \enum RenderState
* \brief Render states that can be enabled/disabled
*/
enum RenderState
{
RENDER_STATE_LIGHTING,
@ -106,8 +110,9 @@ enum RenderState
};
/**
\enum CompFunc
\brief Type of function used to compare values */
* \enum CompFunc
* \brief Type of function used to compare values
*/
enum CompFunc
{
COMP_FUNC_NEVER,
@ -121,8 +126,9 @@ enum CompFunc
};
/**
\enum BlendFunc
\brief Type of blending function */
* \enum BlendFunc
* \brief Type of blending function
*/
enum BlendFunc
{
BLEND_ZERO,
@ -139,8 +145,9 @@ enum BlendFunc
};
/**
\enum FogMode
\brief Type of fog calculation function */
* \enum FogMode
* \brief Type of fog calculation function
*/
enum FogMode
{
FOG_LINEAR,
@ -149,8 +156,9 @@ enum FogMode
};
/**
\enum CullMode
\brief Culling mode for polygons */
* \enum CullMode
* \brief Culling mode for polygons
*/
enum CullMode
{
//! Cull clockwise faces
@ -160,8 +168,9 @@ enum CullMode
};
/**
\enum ShadeModel
\brief Shade model used in rendering */
* \enum ShadeModel
* \brief Shade model used in rendering
*/
enum ShadeModel
{
SHADE_FLAT,
@ -169,8 +178,9 @@ enum ShadeModel
};
/**
\enum FillMode
\brief Polygon fill mode */
* \enum FillMode
* \brief Polygon fill mode
*/
enum FillMode
{
//! Draw only points
@ -178,12 +188,13 @@ enum FillMode
//! Draw only lines
FILL_LINES,
//! Draw full polygons
FILL_FILL
FILL_POLY
};
/**
\enum PrimitiveType
\brief Type of primitive to render */
* \enum PrimitiveType
* \brief Type of primitive to render
*/
enum PrimitiveType
{
PRIMITIVE_POINTS,
@ -194,10 +205,11 @@ enum PrimitiveType
};
/**
\enum IntersectPlane
\brief Intersection plane of projection volume
These flags can be OR'd together. */
* \enum IntersectPlane
* \brief Intersection plane of projection volume
*
* These flags can be OR'd together.
*/
enum IntersectPlane
{
INTERSECT_PLANE_LEFT = 0x01,
@ -211,67 +223,16 @@ enum IntersectPlane
INTERSECT_PLANE_FRONT | INTERSECT_PLANE_BACK
};
/*
Notes for rewriting DirectX code:
>> SetRenderState() translates to many functions depending on param
D3DRENDERSTATE_ALPHABLENDENABLE -> SetRenderState() with RENDER_STATE_BLENDING
D3DRENDERSTATE_ALPHAFUNC -> SetAlphaTestFunc() func
D3DRENDERSTATE_ALPHAREF -> SetAlphaTestFunc() ref
D3DRENDERSTATE_ALPHATESTENABLE -> SetRenderState() with RENDER_STATE_ALPHA_TEST
D3DRENDERSTATE_AMBIENT -> SetGlobalAmbient()
D3DRENDERSTATE_CULLMODE -> SetCullMode()
D3DRENDERSTATE_DESTBLEND -> SetBlendFunc() dest blending func
D3DRENDERSTATE_DITHERENABLE -> SetRenderState() with RENDER_STATE_DITHERING
D3DRENDERSTATE_FILLMODE -> SetFillMode()
D3DRENDERSTATE_FOGCOLOR -> SetFogParams()
D3DRENDERSTATE_FOGENABLE -> SetRenderState() with RENDER_STATE_FOG
D3DRENDERSTATE_FOGEND -> SetFogParams()
D3DRENDERSTATE_FOGSTART -> SetFogParams()
D3DRENDERSTATE_FOGVERTEXMODE -> SetFogParams() fog model
D3DRENDERSTATE_LIGHTING -> SetRenderState() with RENDER_STATE_LIGHTING
D3DRENDERSTATE_SHADEMODE -> SetShadeModel()
D3DRENDERSTATE_SPECULARENABLE -> doesn't matter (always enabled)
D3DRENDERSTATE_SRCBLEND -> SetBlendFunc() src blending func
D3DRENDERSTATE_TEXTUREFACTOR -> SetTextureFactor()
D3DRENDERSTATE_ZBIAS -> SetDepthBias()
D3DRENDERSTATE_ZENABLE -> SetRenderState() with RENDER_STATE_DEPTH_TEST
D3DRENDERSTATE_ZFUNC -> SetDepthTestFunc()
D3DRENDERSTATE_ZWRITEENABLE -> SetRenderState() with RENDER_STATE_DEPTH_WRITE
>> SetTextureStageState() translates to SetTextureParams() or CreateTexture() for some params
Params from enum in struct TextureCreateParams or TextureParams
D3DTSS_ADDRESS -> Gfx::TexWrapMode wrapS, wrapT
D3DTSS_ALPHAARG1 -> Gfx::TexMixArgument alphaArg1
D3DTSS_ALPHAARG2 -> Gfx::TexMixArgument alphaArg2
D3DTSS_ALPHAOP -> Gfx::TexMixOperation alphaOperation
D3DTSS_COLORARG1 -> Gfx::TexMixArgument colorArg1
D3DTSS_COLORARG2 -> Gfx::TexMixArgument colorArg2
D3DTSS_COLOROP -> Gfx::TexMixOperation colorOperation
D3DTSS_MAGFILTER -> Gfx::TexMagFilter magFilter
D3DTSS_MINFILTER -> Gfx::TexMinFilter minFilter
D3DTSS_TEXCOORDINDEX -> doesn't matter (texture coords are set explicitly by glMultiTexCoordARB*)
Note that D3DTSS_ALPHAOP or D3DTSS_COLOROP set to D3DTOP_DISABLE must translate to disabling the whole texture stage.
In DirectX, you shouldn't mix enabling one and disabling the other.
Also, if previous stage is disabled in DirectX, the later ones are disabled, too. In OpenGL, that is not the case.
*/
/**
\class CDevice
\brief Abstract interface of graphics device
It is based on DIRECT3DDEVICE class from DirectX to make it easier to port existing code.
It encapsulates the general graphics device state and provides a common interface
to graphics-specific functions which will be used throughout the program,
both in CEngine class and in UI classes. Note that it doesn't contain all functions from DirectX,
only those that were used in old code.
* \class CDevice
* \brief Abstract interface of graphics device
*
* It is based on DIRECT3DDEVICE class from DirectX to make it easier to port existing code.
* It encapsulates the general graphics device state and provides a common interface
* to graphics-specific functions which will be used throughout the program,
* both in CEngine class and in UI classes. Note that it doesn't contain all functions from DirectX,
* only those that were used in old code.
*
*/
class CDevice
{
@ -302,72 +263,72 @@ public:
virtual void MultiplyTransform(TransformType type, const Math::Matrix &matrix) = 0;
//! Sets the current material
virtual void SetMaterial(const Gfx::Material &material) = 0;
virtual void SetMaterial(const Material &material) = 0;
//! Returns the current material
virtual const Gfx::Material& GetMaterial() = 0;
virtual const Material& GetMaterial() = 0;
//! Returns the maximum number of lights available
virtual int GetMaxLightCount() = 0;
//! Sets the light at given index
virtual void SetLight(int index, const Gfx::Light &light) = 0;
virtual void SetLight(int index, const Light &light) = 0;
//! Returns the current light at given index
virtual const Gfx::Light& GetLight(int index) = 0;
virtual const Light& GetLight(int index) = 0;
//! Enables/disables the light at given index
virtual void SetLightEnabled(int index, bool enabled) = 0;
//! Returns the current enable state of light at given index
virtual bool GetLightEnabled(int index) = 0;
//! Creates a texture from image; the image can be safely removed after that
virtual Gfx::Texture CreateTexture(CImage *image, const Gfx::TextureCreateParams &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
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
virtual void DestroyTexture(const Gfx::Texture &texture) = 0;
virtual void DestroyTexture(const Texture &texture) = 0;
//! Deletes all textures created so far
virtual void DestroyAllTextures() = 0;
//! Returns the maximum number of multitexture stages
virtual int GetMaxTextureCount() = 0;
//! Sets the texture at given texture stage
virtual void SetTexture(int index, const Gfx::Texture &texture) = 0;
virtual void SetTexture(int index, const Texture &texture) = 0;
//! Sets the texture image by ID at given texture stage
virtual void SetTexture(int index, unsigned int textureId) = 0;
//! Returns the (multi)texture at given index
virtual Gfx::Texture GetTexture(int index) = 0;
virtual Texture GetTexture(int index) = 0;
//! Enables/disables the given texture stage
virtual void SetTextureEnabled(int index, bool enabled) = 0;
//! Returns the current enable state of given texture stage
virtual bool GetTextureEnabled(int index) = 0;
//! Sets the params for texture stage with given index
virtual void SetTextureStageParams(int index, const Gfx::TextureStageParams &params) = 0;
virtual void SetTextureStageParams(int index, const TextureStageParams &params) = 0;
//! Returns the current params of texture stage with given index
virtual Gfx::TextureStageParams GetTextureStageParams(int index) = 0;
virtual TextureStageParams GetTextureStageParams(int index) = 0;
//! Sets the texture factor to the given color value
virtual void SetTextureFactor(const Gfx::Color &color) = 0;
virtual void SetTextureFactor(const Color &color) = 0;
//! Returns the current texture factor
virtual Gfx::Color GetTextureFactor() = 0;
virtual Color GetTextureFactor() = 0;
//! Renders primitive composed of vertices with single texture
virtual void DrawPrimitive(Gfx::PrimitiveType type, const Gfx::Vertex *vertices , int vertexCount) = 0;
virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices , int vertexCount) = 0;
//! Renders primitive composed of vertices with color information and single texture
virtual void DrawPrimitive(Gfx::PrimitiveType type, const Gfx::VertexCol *vertices , int vertexCount) = 0;
virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices , int vertexCount) = 0;
//! Renders primitive composed of vertices with multitexturing (2 textures)
virtual void DrawPrimitive(Gfx::PrimitiveType type, const Gfx::VertexTex2 *vertices, int vertexCount) = 0;
virtual void DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, int vertexCount) = 0;
//! Tests whether a sphere intersects the 6 clipping planes of projection volume
virtual int ComputeSphereVisibility(const Math::Vector &center, float radius) = 0;
//! Enables/disables the given render state
virtual void SetRenderState(Gfx::RenderState state, bool enabled) = 0;
virtual void SetRenderState(RenderState state, bool enabled) = 0;
//! Returns the current setting of given render state
virtual bool GetRenderState(Gfx::RenderState state) = 0;
virtual bool GetRenderState(RenderState state) = 0;
//! Sets the function of depth test
virtual void SetDepthTestFunc(Gfx::CompFunc func) = 0;
virtual void SetDepthTestFunc(CompFunc func) = 0;
//! Returns the current function of depth test
virtual Gfx::CompFunc GetDepthTestFunc() = 0;
virtual CompFunc GetDepthTestFunc() = 0;
//! Sets the depth bias (constant value added to Z-coords)
virtual void SetDepthBias(float factor) = 0;
@ -375,44 +336,45 @@ public:
virtual float GetDepthBias() = 0;
//! Sets the alpha test function and reference value
virtual void SetAlphaTestFunc(Gfx::CompFunc func, float refValue) = 0;
virtual void SetAlphaTestFunc(CompFunc func, float refValue) = 0;
//! Returns the current alpha test function and reference value
virtual void GetAlphaTestFunc(Gfx::CompFunc &func, float &refValue) = 0;
virtual void GetAlphaTestFunc(CompFunc &func, float &refValue) = 0;
//! Sets the blending functions for source and destination operations
virtual void SetBlendFunc(Gfx::BlendFunc srcBlend, Gfx::BlendFunc dstBlend) = 0;
virtual void SetBlendFunc(BlendFunc srcBlend, BlendFunc dstBlend) = 0;
//! Returns the current blending functions for source and destination operations
virtual void GetBlendFunc(Gfx::BlendFunc &srcBlend, Gfx::BlendFunc &dstBlend) = 0;
virtual void GetBlendFunc(BlendFunc &srcBlend, BlendFunc &dstBlend) = 0;
//! Sets the clear color
virtual void SetClearColor(const Gfx::Color &color) = 0;
virtual void SetClearColor(const Color &color) = 0;
//! Returns the current clear color
virtual Gfx::Color GetClearColor() = 0;
virtual Color GetClearColor() = 0;
//! Sets the global ambient color
virtual void SetGlobalAmbient(const Gfx::Color &color) = 0;
virtual void SetGlobalAmbient(const Color &color) = 0;
//! Returns the global ambient color
virtual Gfx::Color GetGlobalAmbient() = 0;
virtual Color GetGlobalAmbient() = 0;
//! Sets the fog parameters: mode, color, start distance, end distance and density (for exp models)
virtual void SetFogParams(Gfx::FogMode mode, const Gfx::Color &color, float start, float end, float density) = 0;
virtual void SetFogParams(FogMode mode, const Color &color, float start, float end, float density) = 0;
//! Returns the current fog parameters: mode, color, start distance, end distance and density (for exp models)
virtual void GetFogParams(Gfx::FogMode &mode, Gfx::Color &color, float &start, float &end, float &density) = 0;
virtual void GetFogParams(FogMode &mode, Color &color, float &start, float &end, float &density) = 0;
//! Sets the current cull mode
virtual void SetCullMode(Gfx::CullMode mode) = 0;
virtual void SetCullMode(CullMode mode) = 0;
//! Returns the current cull mode
virtual Gfx::CullMode GetCullMode() = 0;
virtual CullMode GetCullMode() = 0;
//! Sets the shade model
virtual void SetShadeModel(Gfx::ShadeModel model) = 0;
virtual void SetShadeModel(ShadeModel model) = 0;
//! Returns the current shade model
virtual Gfx::ShadeModel GetShadeModel() = 0;
virtual ShadeModel GetShadeModel() = 0;
//! Sets the current fill mode
virtual void SetFillMode(Gfx::FillMode mode) = 0;
virtual void SetFillMode(FillMode mode) = 0;
//! Returns the current fill mode
virtual Gfx::FillMode GetFillMode() = 0;
virtual FillMode GetFillMode() = 0;
};
}; // namespace Gfx
} // namespace Gfx

View File

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

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -17,17 +17,21 @@
/**
* \file graphics/engine/engine.h
* \brief Main graphics engine - Gfx::CEngine class
* \brief Main graphics engine - CEngine class
*/
#pragma once
#include "app/system.h"
#include "common/event.h"
#include "graphics/core/color.h"
#include "graphics/core/material.h"
#include "graphics/core/texture.h"
#include "graphics/core/vertex.h"
#include "math/intpoint.h"
#include "math/matrix.h"
#include "math/point.h"
@ -46,8 +50,10 @@ class CObject;
class CSoundInterface;
// Graphics module namespace
namespace Gfx {
class CDevice;
class CLightManager;
class CText;
@ -60,11 +66,12 @@ class CTerrain;
/**
\enum EngineRenderState
\brief Render state of graphics engine
States are used for settings certain modes, for instance texturing and blending.
The enum is a bitmask and some of the states can be OR'd together. */
* \enum EngineRenderState
* \brief Render state of graphics engine
*
* States are used for settings certain modes, for instance texturing and blending.
* The enum is a bitmask and some of the states can be OR'd together.
*/
enum EngineRenderState
{
//! Normal opaque materials
@ -115,8 +122,9 @@ enum EngineRenderState
/**
\enum EngineTriangleType
\brief Type of triangles drawn for engine objects */
* \enum EngineTriangleType
* \brief Type of triangles drawn for engine objects
*/
enum EngineTriangleType
{
//! Triangles
@ -126,24 +134,25 @@ enum EngineTriangleType
};
/**
\struct EngineTriangle
\brief A triangle drawn by the graphics engine */
* \struct EngineTriangle
* \brief A triangle drawn by the graphics engine
*/
struct EngineTriangle
{
//! Triangle vertices
Gfx::VertexTex2 triangle[3];
VertexTex2 triangle[3];
//! Material
Gfx::Material material;
Material material;
//! Render state
int state;
int state;
//! 1st texture
std::string tex1Name;
std::string tex1Name;
//! 2nd texture
std::string tex2Name;
std::string tex2Name;
EngineTriangle()
{
state = Gfx::ENG_RSTATE_NORMAL;
state = ENG_RSTATE_NORMAL;
}
};
@ -169,8 +178,9 @@ enum EngineObjectType
};
/**
\struct EngineObject
\brief Object drawn by the graphics engine */
* \struct EngineObject
* \brief Object drawn by the graphics engine
*/
struct EngineObject
{
//! If true, object is valid in objects vector
@ -184,7 +194,7 @@ struct EngineObject
//! Number of triangles
int totalTriangles;
//! Type of object
Gfx::EngineObjectType type;
EngineObjectType type;
//! Transformation matrix
Math::Matrix transform;
//! Distance to object from eye point
@ -214,7 +224,7 @@ struct EngineObject
drawWorld = false;
drawFront = false;
totalTriangles = 0;
type = Gfx::ENG_OBJTYPE_NULL;
type = ENG_OBJTYPE_NULL;
transform.LoadIdentity();
bboxMax.LoadZero();
bboxMin.LoadZero();
@ -231,66 +241,71 @@ struct EngineObjLevel3;
struct EngineObjLevel4;
/**
\struct EngineObjLevel4
\brief Tier 4 of object tree */
* \struct EngineObjLevel4
* \brief Tier 4 of object tree
*/
struct EngineObjLevel4
{
bool used;
Gfx::EngineTriangleType type;
Gfx::Material material;
int state;
std::vector<Gfx::VertexTex2> vertices;
bool used;
EngineTriangleType type;
Material material;
int state;
std::vector<VertexTex2> vertices;
EngineObjLevel4(bool used = false,
Gfx::EngineTriangleType type = Gfx::ENG_TRIANGLE_TYPE_TRIANGLES,
const Gfx::Material& material = Gfx::Material(),
int state = Gfx::ENG_RSTATE_NORMAL);
EngineTriangleType type = ENG_TRIANGLE_TYPE_TRIANGLES,
const Material& material = Material(),
int state = ENG_RSTATE_NORMAL);
};
/**
\struct EngineObjLevel3
\brief Tier 3 of object tree */
* \struct EngineObjLevel3
* \brief Tier 3 of object tree
*/
struct EngineObjLevel3
{
bool used;
float min;
float max;
std::vector<Gfx::EngineObjLevel4> next;
bool used;
float min;
float max;
std::vector<EngineObjLevel4> next;
EngineObjLevel3(bool used = false, float min = 0.0f, float max = 0.0f);
};
/**
\struct EngineObjLevel2
\brief Tier 2 of object tree */
* \struct EngineObjLevel2
* \brief Tier 2 of object tree
*/
struct EngineObjLevel2
{
bool used;
int objRank;
std::vector<Gfx::EngineObjLevel3> next;
bool used;
int objRank;
std::vector<EngineObjLevel3> next;
EngineObjLevel2(bool used = false, int objRank = -1);
};
/**
\struct EngineObjLevel1
\brief Tier 1 of object tree */
* \struct EngineObjLevel1
* \brief Tier 1 of object tree
*/
struct EngineObjLevel1
{
bool used;
std::string tex1Name;
Gfx::Texture tex1;
std::string tex2Name;
Gfx::Texture tex2;
std::vector<Gfx::EngineObjLevel2> next;
bool used;
std::string tex1Name;
Texture tex1;
std::string tex2Name;
Texture tex2;
std::vector<EngineObjLevel2> next;
EngineObjLevel1(bool used = false, const std::string& tex1Name = "",
const std::string& tex2Name = "");
};
/**
\struct EngineShadowType
\brief Type of shadow drawn by the graphics engine */
* \struct EngineShadowType
* \brief Type of shadow drawn by the graphics engine
*/
enum EngineShadowType
{
//! Normal shadow
@ -300,8 +315,9 @@ enum EngineShadowType
};
/**
\struct EngineShadow
\brief Shadow drawn by the graphics engine */
* \struct EngineShadow
* \brief Shadow drawn by the graphics engine
*/
struct EngineShadow
{
//! If true, shadow is valid
@ -311,7 +327,7 @@ struct EngineShadow
//! Rank of the associated object
int objRank;
//! Type of shadow
Gfx::EngineShadowType type;
EngineShadowType type;
//! Position of the shadow
Math::Vector pos;
//! Normal to the terrain
@ -335,7 +351,7 @@ struct EngineShadow
used = false;
hide = false;
objRank = 0;
type = Gfx::ENG_SHADOW_NORM;
type = ENG_SHADOW_NORM;
pos.LoadZero();
normal.LoadZero();
angle = radius = intensity = height = 0.0f;
@ -343,14 +359,15 @@ struct EngineShadow
};
/**
\struct EngineGroundSpot
\brief A spot (large shadow) drawn on the ground by the graphics engine */
* \struct EngineGroundSpot
* \brief A spot (large shadow) drawn on the ground by the graphics engine
*/
struct EngineGroundSpot
{
//! If true, ground spot is valid
bool used;
//! Color of the shadow
Gfx::Color color;
Color color;
//! Min altitude
float min;
//! Max altitude
@ -374,7 +391,7 @@ struct EngineGroundSpot
void LoadDefault()
{
used = false;
color = Gfx::Color();
color = Color();
pos.LoadZero();
drawPos.LoadZero();
min = max = smooth = radius = drawRadius = 0.0f;
@ -382,8 +399,9 @@ struct EngineGroundSpot
};
/**
\enum EngineGroundMarkPhase
\brief Phase of life of an EngineGroundMark */
* \enum EngineGroundMarkPhase
* \brief Phase of life of an EngineGroundMark
*/
enum EngineGroundMarkPhase
{
//! Null phase
@ -397,14 +415,15 @@ enum EngineGroundMarkPhase
};
/**
\struct EngineGroundMark
\brief A mark on ground drawn by the graphics engine */
* \struct EngineGroundMark
* \brief A mark on ground drawn by the graphics engine
*/
struct EngineGroundMark
{
//! If true, draw mark
bool draw;
//! Phase of life
Gfx::EngineGroundMarkPhase phase;
EngineGroundMarkPhase phase;
//! Times for 3 life phases
float delay[3];
//! Fixed time
@ -447,8 +466,8 @@ struct EngineGroundMark
};
/**
\enum EngineTextureMapping
\brief Type of texture mapping
* \enum EngineTextureMapping
* \brief Type of texture mapping
*/
enum EngineTextureMapping
{
@ -462,8 +481,9 @@ enum EngineTextureMapping
/**
\enum EngineMouseType
\brief Type of mouse cursor displayed in-game */
* \enum EngineMouseType
* \brief Type of mouse cursor displayed in-game
*/
enum EngineMouseType
{
//! Normal cursor (arrow)
@ -506,8 +526,9 @@ enum EngineMouseType
};
/**
\struct EngineMouse
\brief Information about mouse cursor */
* \struct EngineMouse
* \brief Information about mouse cursor
*/
struct EngineMouse
{
//! Index of texture element for 1st image
@ -517,15 +538,15 @@ struct EngineMouse
//! Shadow texture part
int iconShadow;
//! Mode to render 1st image in
Gfx::EngineRenderState mode1;
EngineRenderState mode1;
//! Mode to render 2nd image in
Gfx::EngineRenderState mode2;
EngineRenderState mode2;
//! Hot point
Math::Point hotPoint;
EngineMouse(int icon1 = -1, int icon2 = -1, int iconShadow = -1,
Gfx::EngineRenderState mode1 = Gfx::ENG_RSTATE_NORMAL,
Gfx::EngineRenderState mode2 = Gfx::ENG_RSTATE_NORMAL,
EngineRenderState mode1 = ENG_RSTATE_NORMAL,
EngineRenderState mode2 = ENG_RSTATE_NORMAL,
Math::Point hotPoint = Math::Point())
{
this->icon1 = icon1;
@ -625,7 +646,7 @@ struct EngineMouse
* Textures are loaded from a texture subdir in data directory. In the old code, textures were identified
* by file name and loaded using some D3D util code. With new code and OpenGL backend, this approach is not
* efficient - name comparison, etc. takes a lot of time. In the future, textures should be loaded once
* at object creation time, and then referenced to as Gfx::Texture structs, or even as unsigned int ID's
* at object creation time, and then referenced to as Texture structs, or even as unsigned int ID's
* which is what OpenGL actually wants. The old method is kept for now, with mapping between texture names
* and texture structs but it will also be subject to refactoring in the future.
*/
@ -636,12 +657,12 @@ public:
~CEngine();
//! Sets the device to be used
void SetDevice(Gfx::CDevice* device);
void SetDevice(CDevice* device);
//! Returns the current device
Gfx::CDevice* GetDevice();
CDevice* GetDevice();
//! Sets the terrain object
void SetTerrain(Gfx::CTerrain* terrain);
void SetTerrain(CTerrain* terrain);
//! Returns the text rendering engine
CText* GetText();
@ -737,8 +758,8 @@ public:
//@{
//! Management of engine object type
bool SetObjectType(int objRank, Gfx::EngineObjectType type);
Gfx::EngineObjectType GetObjectType(int objRank);
bool SetObjectType(int objRank, EngineObjectType type);
EngineObjectType GetObjectType(int objRank);
//@}
//@{
@ -762,30 +783,30 @@ public:
int GetObjectTotalTriangles(int objRank);
//! Adds triangles to given object with the specified params
bool AddTriangles(int objRank, const std::vector<Gfx::VertexTex2>& vertices,
const Gfx::Material& material, int state,
bool AddTriangles(int objRank, const std::vector<VertexTex2>& vertices,
const Material& material, int state,
std::string tex1Name, std::string tex2Name,
float min, float max, bool globalUpdate);
//! Adds a surface to given object with the specified params
bool AddSurface(int objRank, const std::vector<Gfx::VertexTex2>& vertices,
const Gfx::Material& material, int state,
bool AddSurface(int objRank, const std::vector<VertexTex2>& vertices,
const Material& material, int state,
std::string tex1Name, std::string tex2Name,
float min, float max, bool globalUpdate);
//! Adds a tier 4 engine object directly
bool AddQuick(int objRank, const Gfx::EngineObjLevel4& buffer,
bool AddQuick(int objRank, const EngineObjLevel4& buffer,
std::string tex1Name, std::string tex2Name,
float min, float max, bool globalUpdate);
//! Returns the first found tier 4 engine object for the given params or nullptr if not found
Gfx::EngineObjLevel4* FindTriangles(int objRank, const Gfx::Material& material,
EngineObjLevel4* FindTriangles(int objRank, const Material& material,
int state, std::string tex1Name, std::string tex2Name,
float min, float max);
//! Returns a partial list of triangles for given object
int GetPartialTriangles(int objRank, float min, float max, float percent, int maxCount,
std::vector<Gfx::EngineTriangle>& triangles);
std::vector<EngineTriangle>& triangles);
//! Updates LOD after parameter or resolution change
void ChangeLOD();
@ -794,15 +815,15 @@ public:
bool ChangeSecondTexture(int objRank, const std::string& tex2Name);
//! Changes (recalculates) texture mapping for given object
bool ChangeTextureMapping(int objRank, const Gfx::Material& mat, int state,
bool ChangeTextureMapping(int objRank, const Material& mat, int state,
const std::string& tex1Name, const std::string& tex2Name,
float min, float max, Gfx::EngineTextureMapping mode,
float min, float max, EngineTextureMapping mode,
float au, float bu, float av, float bv);
//! Changes texture mapping for robot tracks
bool TrackTextureMapping(int objRank, const Gfx::Material& mat, int state,
bool TrackTextureMapping(int objRank, const Material& mat, int state,
const std::string& tex1Name, const std::string& tex2Name,
float min, float max, Gfx::EngineTextureMapping mode,
float min, float max, EngineTextureMapping mode,
float pos, float factor, float tl, float ts, float tt);
//! Detects the target object that is selected with the mouse
@ -817,7 +838,7 @@ public:
//@{
//! Management of different shadow params
bool SetObjectShadowHide(int objRank, bool hide);
bool SetObjectShadowType(int objRank, Gfx::EngineShadowType type);
bool SetObjectShadowType(int objRank, EngineShadowType type);
bool SetObjectShadowPos(int objRank, const Math::Vector& pos);
bool SetObjectShadowNormal(int objRank, const Math::Vector& normal);
bool SetObjectShadowAngle(int objRank, float angle);
@ -843,7 +864,7 @@ public:
//! Management of different ground spot params
bool SetObjectGroundSpotPos(int rank, const Math::Vector& pos);
bool SetObjectGroundSpotRadius(int rank, float radius);
bool SetObjectGroundSpotColor(int rank, const Gfx::Color& color);
bool SetObjectGroundSpotColor(int rank, const Color& color);
bool SetObjectGroundSpotMinMax(int rank, float min, float max);
bool SetObjectGroundSpotSmooth(int rank, float smooth);
//@}
@ -862,19 +883,19 @@ public:
/* *************** Mode setting *************** */
//! Sets the current rendering state
void SetState(int state, const Gfx::Color& color = Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f));
void SetState(int state, const Color& color = Color(1.0f, 1.0f, 1.0f, 1.0f));
//! Sets the current material
void SetMaterial(const Gfx::Material& mat);
void SetMaterial(const Material& mat);
//! Specifies the location and direction of view
void SetViewParams(const Math::Vector& eyePt, const Math::Vector& lookatPt,
const Math::Vector& upVec, float eyeDistance);
//! Loads texture, creating it if not already present
Gfx::Texture LoadTexture(const std::string& name);
Texture LoadTexture(const std::string& name);
//! Loads texture, creating it with given params if not already present
Gfx::Texture LoadTexture(const std::string& name, const Gfx::TextureCreateParams& params);
Texture LoadTexture(const std::string& name, const TextureCreateParams& params);
//! Loads all necessary textures
bool LoadAllTextures();
@ -882,12 +903,12 @@ public:
/** If loading fails, returns false. */
bool SetTexture(const std::string& name, int stage = 0);
//! Sets texture for given stage
void SetTexture(const Gfx::Texture& tex, int stage = 0);
void SetTexture(const Texture& tex, int stage = 0);
//! Deletes the given texture, unloading it and removing from cache
void DeleteTexture(const std::string& name);
//! Deletes the given texture, unloading it and removing from cache
void DeleteTexture(const Gfx::Texture& tex);
void DeleteTexture(const Texture& tex);
//@{
//! Border management (distance limits) depends of the resolution (LOD = level-of-detail)
@ -954,20 +975,20 @@ public:
//@{
//! Ambient color management
void SetAmbientColor(const Gfx::Color& color, int rank = 0);
Gfx::Color GetAmbientColor(int rank = 0);
void SetAmbientColor(const Color& color, int rank = 0);
Color GetAmbientColor(int rank = 0);
//@}
//@{
//! Color management under water
void SetWaterAddColor(const Gfx::Color& color);
Gfx::Color GetWaterAddColor();
void SetWaterAddColor(const Color& color);
Color GetWaterAddColor();
//@}
//@{
//! Management of the fog color
void SetFogColor(const Gfx::Color& color, int rank = 0);
Gfx::Color GetFogColor(int rank = 0);
void SetFogColor(const Color& color, int rank = 0);
Color GetFogColor(int rank = 0);
//@}
//@{
@ -989,11 +1010,11 @@ public:
//@{
//! Management of the background image to use
void SetBackground(const std::string& name, Gfx::Color up = Gfx::Color(), Gfx::Color down = Gfx::Color(),
Gfx::Color cloudUp = Gfx::Color(), Gfx::Color cloudDown = Gfx::Color(),
void SetBackground(const std::string& name, Color up = Color(), Color down = Color(),
Color cloudUp = Color(), Color cloudDown = Color(),
bool full = false, Math::Point scale = Math::Point(1.0f, 1.0f));
void GetBackground(std::string& name, Gfx::Color& up, Gfx::Color& down,
Gfx::Color& cloudUp, Gfx::Color& cloudDown,
void GetBackground(std::string& name, Color& up, Color& down,
Color& cloudUp, Color& cloudDown,
bool& full, Math::Point& scale);
//@}
@ -1002,7 +1023,7 @@ public:
//! Specifies whether to draw the foreground
void SetOverFront(bool front);
//! Sets the foreground overlay color
void SetOverColor(const Gfx::Color& color = Gfx::Color(), int mode = ENG_RSTATE_TCOLOR_BLACK);
void SetOverColor(const Color& color = Color(), int mode = ENG_RSTATE_TCOLOR_BLACK);
//@{
//! Management of the particle density
@ -1102,22 +1123,10 @@ public:
float GetTracePrecision();
//@}
//@{
//! Management of mouse cursor visibility
void SetMouseVisible(bool show);
bool GetMouseVisible();
//@}
//@{
//! Management of mouse cursor position
void SetMousePos(Math::Point pos);
Math::Point GetMousePos();
//@}
//@{
//! Management of mouse cursor type
void SetMouseType(Gfx::EngineMouseType type);
Gfx::EngineMouseType GetMouseType();
void SetMouseType(EngineMouseType type);
EngineMouseType GetMouseType();
//@}
//! Returns the view matrix
@ -1153,7 +1162,7 @@ protected:
//! Draws the gradient background
void DrawBackground();
//! Draws the gradient background
void DrawBackgroundGradient(const Gfx::Color& up, const Gfx::Color& down);
void DrawBackgroundGradient(const Color& up, const Color& down);
//! Draws the image background
void DrawBackgroundImage();
//! Draws all the planets
@ -1168,19 +1177,21 @@ protected:
void DrawMouse();
//! Draw part of mouse cursor sprite
void DrawMouseSprite(Math::Point pos, Math::Point dim, int icon);
//! Draw statistic texts
void DrawStats();
//! Creates new tier 1 object
Gfx::EngineObjLevel1& AddLevel1(const std::string& tex1Name, const std::string& tex2Name);
EngineObjLevel1& AddLevel1(const std::string& tex1Name, const std::string& tex2Name);
//! Creates a new tier 2 object
Gfx::EngineObjLevel2& AddLevel2(Gfx::EngineObjLevel1 &p1, int objRank);
EngineObjLevel2& AddLevel2(EngineObjLevel1 &p1, int objRank);
//! Creates a new tier 3 object
Gfx::EngineObjLevel3& AddLevel3(Gfx::EngineObjLevel2 &p2, float min, float max);
EngineObjLevel3& AddLevel3(EngineObjLevel2 &p2, float min, float max);
//! Creates a new tier 4 object
Gfx::EngineObjLevel4& AddLevel4(Gfx::EngineObjLevel3 &p3, Gfx::EngineTriangleType type,
const Gfx::Material& mat, int state);
EngineObjLevel4& AddLevel4(EngineObjLevel3 &p3, EngineTriangleType type,
const Material& mat, int state);
//! Create texture and add it to cache
Gfx::Texture CreateTexture(const std::string &texName, const Gfx::TextureCreateParams &params);
Texture CreateTexture(const std::string &texName, const TextureCreateParams &params);
//! Tests whether the given object is visible
bool IsVisible(int objRank);
@ -1192,7 +1203,7 @@ protected:
bool GetBBox2D(int objRank, Math::Point& min, Math::Point& max);
//! Detects whether the mouse is in a triangle.
bool DetectTriangle(Math::Point mouse, Gfx::VertexTex2* triangle, int objRank, float& dist);
bool DetectTriangle(Math::Point mouse, VertexTex2* triangle, int objRank, float& dist);
//! Transforms a 3D point (x, y, z) in 2D space (x, y, -) of the window
/** The coordinated p2D.z gives the distance. */
@ -1205,27 +1216,31 @@ protected:
void UpdateGeometry();
protected:
CInstanceManager* m_iMan;
CApplication* m_app;
CSoundInterface* m_sound;
Gfx::CDevice* m_device;
Gfx::CText* m_text;
Gfx::CLightManager* m_lightMan;
Gfx::CParticle* m_particle;
Gfx::CWater* m_water;
Gfx::CCloud* m_cloud;
Gfx::CLightning* m_lightning;
Gfx::CPlanet* m_planet;
Gfx::CTerrain* m_terrain;
CInstanceManager* m_iMan;
CApplication* m_app;
CSoundInterface* m_sound;
CDevice* m_device;
CText* m_text;
CLightManager* m_lightMan;
CParticle* m_particle;
CWater* m_water;
CCloud* m_cloud;
CLightning* m_lightning;
CPlanet* m_planet;
CTerrain* m_terrain;
//! Last encountered error
std::string m_error;
SystemTimeStamp* m_lastFrameTime;
SystemTimeStamp* m_currentFrameTime;
int m_fpsCounter;
float m_fps;
//! Whether to show stats (FPS, etc)
bool m_showStats;
std::string m_fpsText;
//! Speed of animation
float m_speed;
//! Pause mode
bool m_pause;
//! Rendering enabled?
@ -1253,15 +1268,15 @@ protected:
Math::IntPoint m_lastSize;
//! Root of tree object structure (level 1 list)
std::vector<Gfx::EngineObjLevel1> m_objectTree;
std::vector<EngineObjLevel1> m_objectTree;
//! Object parameters
std::vector<Gfx::EngineObject> m_objects;
std::vector<EngineObject> m_objects;
//! Shadow list
std::vector<Gfx::EngineShadow> m_shadows;
std::vector<EngineShadow> m_shadows;
//! Ground spot list
std::vector<Gfx::EngineGroundSpot> m_groundSpots;
std::vector<EngineGroundSpot> m_groundSpots;
//! Ground mark
Gfx::EngineGroundMark m_groundMark;
EngineGroundMark m_groundMark;
//! Location of camera
Math::Vector m_eyePt;
@ -1270,12 +1285,12 @@ protected:
float m_eyeDirH;
float m_eyeDirV;
int m_rankView;
Gfx::Color m_ambientColor[2];
Gfx::Color m_backColor[2];
Gfx::Color m_fogColor[2];
Color m_ambientColor[2];
Color m_backColor[2];
Color m_fogColor[2];
float m_deepView[2];
float m_fogStart[2];
Gfx::Color m_waterAddColor;
Color m_waterAddColor;
int m_statisticTriangle;
bool m_updateGeometry;
int m_alphaMode;
@ -1290,16 +1305,16 @@ protected:
bool m_backgroundFull;
Math::Point m_backgroundScale;
std::string m_backgroundName;
Gfx::Texture m_backgroundTex;
Gfx::Color m_backgroundColorUp;
Gfx::Color m_backgroundColorDown;
Gfx::Color m_backgroundCloudUp;
Gfx::Color m_backgroundCloudDown;
Texture m_backgroundTex;
Color m_backgroundColorUp;
Color m_backgroundColorDown;
Color m_backgroundCloudUp;
Color m_backgroundCloudDown;
bool m_overFront;
Gfx::Color m_overColor;
Color m_overColor;
int m_overMode;
std::string m_foregroundName;
Gfx::Texture m_foregroundTex;
Texture m_foregroundTex;
bool m_drawWorld;
bool m_drawFront;
float m_limitLOD[2];
@ -1337,38 +1352,35 @@ protected:
//! Texture directory name
std::string m_texPath;
//! Default texture create params
Gfx::TextureCreateParams m_defaultTexParams;
TextureCreateParams m_defaultTexParams;
//! Map of loaded textures (by name)
std::map<std::string, Gfx::Texture> m_texNameMap;
std::map<std::string, Texture> m_texNameMap;
//! Reverse map of loaded textures (by texture)
std::map<Gfx::Texture, std::string> m_revTexNameMap;
std::map<Texture, std::string> m_revTexNameMap;
//! Blacklist map of textures
/** Textures on this list were not successful in first loading,
* so are disabled for subsequent load calls. */
std::set<std::string> m_texBlacklist;
//! Mouse cursor definitions
Gfx::EngineMouse m_mice[Gfx::ENG_MOUSE_COUNT];
EngineMouse m_mice[ENG_MOUSE_COUNT];
//! Texture with mouse cursors
Gfx::Texture m_miceTexture;
Texture m_miceTexture;
//! Size of mouse cursor
Math::Point m_mouseSize;
Math::Point m_mouseSize;
//! Type of mouse cursor
Gfx::EngineMouseType m_mouseType;
//! Position of mouse in interface coords
Math::Point m_mousePos;
//! Is mouse visible?
bool m_mouseVisible;
EngineMouseType m_mouseType;
//! Last engine render state (-1 at the beginning of frame)
int m_lastState;
//! Last color set with render state
Gfx::Color m_lastColor;
Color m_lastColor;
//! Last texture names for 2 used texture stages
std::string m_lastTexture[2];
//! Last material
Gfx::Material m_lastMaterial;
Material m_lastMaterial;
};
}; // namespace Gfx
} // namespace Gfx

View File

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

View File

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

View File

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

View File

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

View File

@ -15,7 +15,6 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
// modelfile.cpp (aka modfile.cpp)
#include "graphics/engine/modelfile.h"
@ -23,10 +22,13 @@
#include "common/ioutils.h"
#include "common/logger.h"
#include "common/stringutils.h"
#include "graphics/engine/engine.h"
#include "math/geometry.h"
#include <string.h>
#include <cstring>
#include <fstream>
#include <sstream>
@ -39,12 +41,16 @@
*/
// Graphics module namespace
namespace Gfx {
//! How big the triangle vector is by default
const int TRIANGLE_PREALLOCATE_COUNT = 2000;
bool ReadBinaryVertex(std::istream& stream, Gfx::Vertex& vertex)
bool ReadBinaryVertex(std::istream& stream, Vertex& vertex)
{
vertex.coord.x = IOUtils::ReadBinaryFloat(stream);
vertex.coord.y = IOUtils::ReadBinaryFloat(stream);
@ -58,7 +64,7 @@ bool ReadBinaryVertex(std::istream& stream, Gfx::Vertex& vertex)
return !stream.fail();
}
bool WriteBinaryVertex(Gfx::Vertex vertex, std::ostream& stream)
bool WriteBinaryVertex(Vertex vertex, std::ostream& stream)
{
IOUtils::WriteBinaryFloat(vertex.coord.x, stream);
IOUtils::WriteBinaryFloat(vertex.coord.y, stream);
@ -72,7 +78,7 @@ bool WriteBinaryVertex(Gfx::Vertex vertex, std::ostream& stream)
return !stream.fail();
}
bool ReadBinaryVertexTex2(std::istream& stream, Gfx::VertexTex2& vertex)
bool ReadBinaryVertexTex2(std::istream& stream, VertexTex2& vertex)
{
vertex.coord.x = IOUtils::ReadBinaryFloat(stream);
vertex.coord.y = IOUtils::ReadBinaryFloat(stream);
@ -88,7 +94,7 @@ bool ReadBinaryVertexTex2(std::istream& stream, Gfx::VertexTex2& vertex)
return !stream.fail();
}
bool WriteBinaryVertexTex2(Gfx::VertexTex2 vertex, std::ostream& stream)
bool WriteBinaryVertexTex2(VertexTex2 vertex, std::ostream& stream)
{
IOUtils::WriteBinaryFloat(vertex.coord.x, stream);
IOUtils::WriteBinaryFloat(vertex.coord.y, stream);
@ -104,7 +110,7 @@ bool WriteBinaryVertexTex2(Gfx::VertexTex2 vertex, std::ostream& stream)
return !stream.fail();
}
bool ReadTextVertexTex2(const std::string& text, Gfx::VertexTex2& vertex)
bool ReadTextVertexTex2(const std::string& text, VertexTex2& vertex)
{
std::stringstream stream;
stream.str(text);
@ -138,7 +144,7 @@ bool ReadTextVertexTex2(const std::string& text, Gfx::VertexTex2& vertex)
return !stream.fail();
}
bool WriteTextVertexTex2(const Gfx::VertexTex2& vertex, std::ostream& stream)
bool WriteTextVertexTex2(const VertexTex2& vertex, std::ostream& stream)
{
stream << "c " << vertex.coord.x << " " << vertex.coord.y << " " << vertex.coord.z;
stream << " n " << vertex.normal.x << " " << vertex.normal.y << " " << vertex.normal.z;
@ -149,7 +155,7 @@ bool WriteTextVertexTex2(const Gfx::VertexTex2& vertex, std::ostream& stream)
return !stream.fail();
}
bool ReadBinaryMaterial(std::istream& stream, Gfx::Material& material)
bool ReadBinaryMaterial(std::istream& stream, Material& material)
{
material.diffuse.r = IOUtils::ReadBinaryFloat(stream);
material.diffuse.g = IOUtils::ReadBinaryFloat(stream);
@ -176,7 +182,7 @@ bool ReadBinaryMaterial(std::istream& stream, Gfx::Material& material)
return !stream.fail();
}
bool WriteBinaryMaterial(const Gfx::Material& material, std::ostream& stream)
bool WriteBinaryMaterial(const Material& material, std::ostream& stream)
{
IOUtils::WriteBinaryFloat(material.diffuse.r, stream);
IOUtils::WriteBinaryFloat(material.diffuse.g, stream);
@ -203,7 +209,7 @@ bool WriteBinaryMaterial(const Gfx::Material& material, std::ostream& stream)
return !stream.fail();
}
bool ReadTextMaterial(const std::string& text, Gfx::Material& material)
bool ReadTextMaterial(const std::string& text, Material& material)
{
std::stringstream stream;
stream.str(text);
@ -240,7 +246,7 @@ bool ReadTextMaterial(const std::string& text, Gfx::Material& material)
return !stream.fail();
}
bool WriteTextMaterial(const Gfx::Material& material, std::ostream& stream)
bool WriteTextMaterial(const Material& material, std::ostream& stream)
{
stream << "dif " << material.diffuse.r
<< " " << material.diffuse.g
@ -316,7 +322,7 @@ bool ReadLineString(std::istream& stream, const std::string& prefix, std::string
}
Gfx::CModelFile::CModelFile(CInstanceManager* iMan)
CModelFile::CModelFile(CInstanceManager* iMan)
{
m_iMan = iMan;
@ -327,7 +333,7 @@ Gfx::CModelFile::CModelFile(CInstanceManager* iMan)
m_triangles.reserve(TRIANGLE_PREALLOCATE_COUNT);
}
Gfx::CModelFile::~CModelFile()
CModelFile::~CModelFile()
{
}
@ -370,10 +376,10 @@ struct OldModelTriangle1
{
char used;
char selected;
Gfx::Vertex p1;
Gfx::Vertex p2;
Gfx::Vertex p3;
Gfx::Material material;
Vertex p1;
Vertex p2;
Vertex p3;
Material material;
char texName[20];
float min;
float max;
@ -394,10 +400,10 @@ struct OldModelTriangle2
{
char used;
char selected;
Gfx::Vertex p1;
Gfx::Vertex p2;
Gfx::Vertex p3;
Gfx::Material material;
Vertex p1;
Vertex p2;
Vertex p3;
Material material;
char texName[20];
float min;
float max;
@ -422,10 +428,10 @@ struct OldModelTriangle3
{
char used;
char selected;
Gfx::VertexTex2 p1;
Gfx::VertexTex2 p2;
Gfx::VertexTex2 p3;
Gfx::Material material;
VertexTex2 p1;
VertexTex2 p2;
VertexTex2 p3;
Material material;
char texName[20];
float min;
float max;
@ -441,7 +447,7 @@ struct OldModelTriangle3
}
};
bool Gfx::CModelFile::ReadModel(const std::string& fileName)
bool CModelFile::ReadModel(const std::string& fileName)
{
m_triangles.clear();
@ -456,7 +462,7 @@ bool Gfx::CModelFile::ReadModel(const std::string& fileName)
return ReadModel(stream);
}
bool Gfx::CModelFile::ReadModel(std::istream& stream)
bool CModelFile::ReadModel(std::istream& stream)
{
m_triangles.clear();
@ -484,6 +490,8 @@ bool Gfx::CModelFile::ReadModel(std::istream& stream)
t.used = IOUtils::ReadBinary<1, char>(stream);
t.selected = IOUtils::ReadBinary<1, char>(stream);
/* padding */ IOUtils::ReadBinary<2, unsigned int>(stream);
ReadBinaryVertex(stream, t.p1);
ReadBinaryVertex(stream, t.p2);
ReadBinaryVertex(stream, t.p3);
@ -499,7 +507,7 @@ bool Gfx::CModelFile::ReadModel(std::istream& stream)
return false;
}
Gfx::ModelTriangle triangle;
ModelTriangle triangle;
triangle.p1.FromVertex(t.p1);
triangle.p2.FromVertex(t.p2);
triangle.p3.FromVertex(t.p3);
@ -520,6 +528,8 @@ bool Gfx::CModelFile::ReadModel(std::istream& stream)
t.used = IOUtils::ReadBinary<1, char>(stream);
t.selected = IOUtils::ReadBinary<1, char>(stream);
/* padding */ IOUtils::ReadBinary<2, unsigned int>(stream);
ReadBinaryVertex(stream, t.p1);
ReadBinaryVertex(stream, t.p2);
ReadBinaryVertex(stream, t.p3);
@ -541,7 +551,7 @@ bool Gfx::CModelFile::ReadModel(std::istream& stream)
return false;
}
Gfx::ModelTriangle triangle;
ModelTriangle triangle;
triangle.p1.FromVertex(t.p1);
triangle.p2.FromVertex(t.p2);
triangle.p3.FromVertex(t.p3);
@ -586,7 +596,7 @@ bool Gfx::CModelFile::ReadModel(std::istream& stream)
return false;
}
Gfx::ModelTriangle triangle;
ModelTriangle triangle;
triangle.p1 = t.p1;
triangle.p2 = t.p2;
triangle.p3 = t.p3;
@ -599,15 +609,15 @@ bool Gfx::CModelFile::ReadModel(std::istream& stream)
triangle.variableTex2 = t.texNum2 == 1;
if (triangle.tex1Name == "plant.png")
triangle.state |= Gfx::ENG_RSTATE_ALPHA;
triangle.state |= ENG_RSTATE_ALPHA;
if (!triangle.variableTex2 && t.texNum2 != 0)
{
if (t.texNum2 >= 1 && t.texNum2 <= 10)
triangle.state |= Gfx::ENG_RSTATE_DUAL_BLACK;
triangle.state |= ENG_RSTATE_DUAL_BLACK;
if (t.texNum2 >= 11 && t.texNum2 <= 20)
triangle.state |= Gfx::ENG_RSTATE_DUAL_WHITE;
triangle.state |= ENG_RSTATE_DUAL_WHITE;
char tex2Name[20] = { 0 };
sprintf(tex2Name, "dirty%.2d.png", t.texNum2); // hardcoded as in original code
@ -649,7 +659,7 @@ bool Gfx::CModelFile::ReadModel(std::istream& stream)
return true;
}
bool Gfx::CModelFile::WriteModel(const std::string& fileName)
bool CModelFile::WriteModel(const std::string& fileName)
{
std::ofstream stream;
stream.open(fileName.c_str(), std::ios_base::out | std::ios_base::binary);
@ -662,7 +672,7 @@ bool Gfx::CModelFile::WriteModel(const std::string& fileName)
return WriteModel(stream);
}
bool Gfx::CModelFile::WriteModel(std::ostream& stream)
bool CModelFile::WriteModel(std::ostream& stream)
{
if (m_triangles.size() == 0)
{
@ -763,13 +773,13 @@ struct NewModelHeader
struct NewModelTriangle1
{
//! 1st vertex
Gfx::VertexTex2 p1;
VertexTex2 p1;
//! 2nd vertex
Gfx::VertexTex2 p2;
VertexTex2 p2;
//! 3rd vertex
Gfx::VertexTex2 p3;
VertexTex2 p3;
//! Material
Gfx::Material material;
Material material;
//! Name of 1st texture
std::string tex1Name;
//! Name of 2nd texture
@ -792,7 +802,7 @@ struct NewModelTriangle1
};
bool Gfx::CModelFile::ReadTextModel(const std::string& fileName)
bool CModelFile::ReadTextModel(const std::string& fileName)
{
std::ifstream stream;
stream.open(fileName.c_str(), std::ios_base::in);
@ -805,7 +815,7 @@ bool Gfx::CModelFile::ReadTextModel(const std::string& fileName)
return ReadTextModel(stream);
}
bool Gfx::CModelFile::ReadTextModel(std::istream& stream)
bool CModelFile::ReadTextModel(std::istream& stream)
{
m_triangles.clear();
@ -848,14 +858,14 @@ bool Gfx::CModelFile::ReadTextModel(std::istream& stream)
if (!triOk || stream.fail())
{
GetLogger()->Error("Error reading model file header\n");
GetLogger()->Error("Error reading model data\n");
return false;
}
t.variableTex2 = varTex2Ch == 'Y';
Gfx::ModelTriangle triangle;
ModelTriangle triangle;
triangle.p1 = t.p1;
triangle.p2 = t.p2;
triangle.p3 = t.p3;
@ -901,7 +911,7 @@ bool Gfx::CModelFile::ReadTextModel(std::istream& stream)
return true;
}
bool Gfx::CModelFile::WriteTextModel(const std::string &fileName)
bool CModelFile::WriteTextModel(const std::string &fileName)
{
std::ofstream stream;
stream.open(fileName.c_str(), std::ios_base::out);
@ -914,7 +924,7 @@ bool Gfx::CModelFile::WriteTextModel(const std::string &fileName)
return WriteTextModel(stream);
}
bool Gfx::CModelFile::WriteTextModel(std::ostream& stream)
bool CModelFile::WriteTextModel(std::ostream& stream)
{
if (m_triangles.size() == 0)
{
@ -978,7 +988,7 @@ bool Gfx::CModelFile::WriteTextModel(std::ostream& stream)
return true;
}
bool Gfx::CModelFile::ReadBinaryModel(const std::string& fileName)
bool CModelFile::ReadBinaryModel(const std::string& fileName)
{
std::ifstream stream;
stream.open(fileName.c_str(), std::ios_base::in | std::ios_base::binary);
@ -991,7 +1001,7 @@ bool Gfx::CModelFile::ReadBinaryModel(const std::string& fileName)
return ReadBinaryModel(stream);
}
bool Gfx::CModelFile::ReadBinaryModel(std::istream& stream)
bool CModelFile::ReadBinaryModel(std::istream& stream)
{
m_triangles.clear();
@ -1030,7 +1040,7 @@ bool Gfx::CModelFile::ReadBinaryModel(std::istream& stream)
return false;
}
Gfx::ModelTriangle triangle;
ModelTriangle triangle;
triangle.p1 = t.p1;
triangle.p2 = t.p2;
triangle.p3 = t.p3;
@ -1074,7 +1084,7 @@ bool Gfx::CModelFile::ReadBinaryModel(std::istream& stream)
return true;
}
bool Gfx::CModelFile::WriteBinaryModel(const std::string& fileName)
bool CModelFile::WriteBinaryModel(const std::string& fileName)
{
std::ofstream stream;
stream.open(fileName.c_str(), std::ios_base::out | std::ios_base::binary);
@ -1087,7 +1097,7 @@ bool Gfx::CModelFile::WriteBinaryModel(const std::string& fileName)
return WriteBinaryModel(stream);
}
bool Gfx::CModelFile::WriteBinaryModel(std::ostream& stream)
bool CModelFile::WriteBinaryModel(std::ostream& stream)
{
if (m_triangles.size() == 0)
{
@ -1146,9 +1156,9 @@ bool Gfx::CModelFile::WriteBinaryModel(std::ostream& stream)
#ifndef MODELFILE_NO_ENGINE
bool Gfx::CModelFile::CreateEngineObject(int objRank)
bool CModelFile::CreateEngineObject(int objRank)
{
std::vector<Gfx::VertexTex2> vs(3, Gfx::VertexTex2());
std::vector<VertexTex2> vs(3, VertexTex2());
float limit[2];
limit[0] = m_engine->GetLimitLOD(0); // frontier AB as config
@ -1184,10 +1194,10 @@ bool Gfx::CModelFile::CreateEngineObject(int objRank)
int texNum = m_engine->GetSecondTexture();
if (texNum >= 1 && texNum <= 10)
state |= Gfx::ENG_RSTATE_DUAL_BLACK;
state |= ENG_RSTATE_DUAL_BLACK;
if (texNum >= 11 && texNum <= 20)
state |= Gfx::ENG_RSTATE_DUAL_WHITE;
state |= ENG_RSTATE_DUAL_WHITE;
char name[20] = { 0 };
sprintf(name, "dirty%.2d.png", texNum);
@ -1213,11 +1223,11 @@ bool Gfx::CModelFile::CreateEngineObject(int objRank)
#endif
void Gfx::CModelFile::Mirror()
void CModelFile::Mirror()
{
for (int i = 0; i < static_cast<int>( m_triangles.size() ); i++)
{
Gfx::VertexTex2 t = m_triangles[i].p1;
VertexTex2 t = m_triangles[i].p1;
m_triangles[i].p1 = m_triangles[i].p2;
m_triangles[i].p2 = t;
@ -1231,17 +1241,17 @@ void Gfx::CModelFile::Mirror()
}
}
const std::vector<Gfx::ModelTriangle>& Gfx::CModelFile::GetTriangles()
const std::vector<ModelTriangle>& CModelFile::GetTriangles()
{
return m_triangles;
}
int Gfx::CModelFile::GetTriangleCount()
int CModelFile::GetTriangleCount()
{
return m_triangles.size();
}
float Gfx::CModelFile::GetHeight(Math::Vector pos)
float CModelFile::GetHeight(Math::Vector pos)
{
float limit = 5.0f;
@ -1263,20 +1273,23 @@ float Gfx::CModelFile::GetHeight(Math::Vector pos)
return 0.0f;
}
void Gfx::CModelFile::CreateTriangle(Math::Vector p1, Math::Vector p2, Math::Vector p3, float min, float max)
void CModelFile::CreateTriangle(Math::Vector p1, Math::Vector p2, Math::Vector p3, float min, float max)
{
Gfx::ModelTriangle triangle;
ModelTriangle triangle;
Math::Vector n = Math::NormalToPlane(p3, p2, p1);
triangle.p1 = Gfx::VertexTex2(p1, n);
triangle.p2 = Gfx::VertexTex2(p2, n);
triangle.p3 = Gfx::VertexTex2(p3, n);
triangle.p1 = VertexTex2(p1, n);
triangle.p2 = VertexTex2(p2, n);
triangle.p3 = VertexTex2(p3, n);
triangle.material.diffuse = Gfx::Color(1.0f, 1.0f, 1.0f, 0.0f);
triangle.material.ambient = Gfx::Color(0.5f, 0.5f, 0.5f, 0.0f);
triangle.material.diffuse = Color(1.0f, 1.0f, 1.0f, 0.0f);
triangle.material.ambient = Color(0.5f, 0.5f, 0.5f, 0.0f);
triangle.min = min;
triangle.max = max;
m_triangles.push_back(triangle);
}
} // namespace Gfx

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -15,7 +15,6 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
// terrain.cpp
#include "graphics/engine/terrain.h"
@ -31,18 +30,22 @@
#include <SDL/SDL.h>
// Graphics module namespace
namespace Gfx {
const int LEVEL_MAT_PREALLOCATE_COUNT = 101;
const int FLYING_LIMIT_PREALLOCATE_COUNT = 10;
const int BUILDING_LEVEL_PREALLOCATE_COUNT = 101;
Gfx::CTerrain::CTerrain(CInstanceManager* iMan)
CTerrain::CTerrain(CInstanceManager* iMan)
{
m_iMan = iMan;
m_iMan->AddInstance(CLASS_TERRAIN, this);
m_engine = static_cast<Gfx::CEngine*>( m_iMan->SearchInstance(CLASS_ENGINE) );
m_water = static_cast<Gfx::CWater*>( m_iMan->SearchInstance(CLASS_WATER) );
m_engine = static_cast<CEngine*>( m_iMan->SearchInstance(CLASS_ENGINE) );
m_water = static_cast<CWater*>( m_iMan->SearchInstance(CLASS_WATER) );
m_mosaicCount = 20;
m_brickCount = 1 << 4;
@ -66,11 +69,11 @@ Gfx::CTerrain::CTerrain(CInstanceManager* iMan)
FlushMaterials();
}
Gfx::CTerrain::~CTerrain()
CTerrain::~CTerrain()
{
}
bool Gfx::CTerrain::Generate(int mosaicCount, int brickCountPow2, float brickSize,
bool CTerrain::Generate(int mosaicCount, int brickCountPow2, float brickSize,
float vision, int depth, float hardness)
{
m_mosaicCount = mosaicCount;
@ -102,27 +105,27 @@ bool Gfx::CTerrain::Generate(int mosaicCount, int brickCountPow2, float brickSiz
}
int Gfx::CTerrain::GetMosaicCount()
int CTerrain::GetMosaicCount()
{
return m_mosaicCount;
}
int Gfx::CTerrain::GetBrickCount()
int CTerrain::GetBrickCount()
{
return m_brickCount;
}
float Gfx::CTerrain::GetBrickSize()
float CTerrain::GetBrickSize()
{
return m_brickSize;
}
float Gfx::CTerrain::GetReliefScale()
float CTerrain::GetReliefScale()
{
return m_scaleRelief;
}
bool Gfx::CTerrain::InitTextures(const std::string& baseName, int* table, int dx, int dy)
bool CTerrain::InitTextures(const std::string& baseName, int* table, int dx, int dy)
{
m_useMaterials = false;
@ -149,7 +152,7 @@ bool Gfx::CTerrain::InitTextures(const std::string& baseName, int* table, int dx
}
void Gfx::CTerrain::FlushMaterials()
void CTerrain::FlushMaterials()
{
m_materials.clear();
m_maxMaterialID = 0;
@ -157,7 +160,7 @@ void Gfx::CTerrain::FlushMaterials()
FlushMaterialPoints();
}
void Gfx::CTerrain::AddMaterial(int id, const std::string& texName, const Math::Point &uv,
void CTerrain::AddMaterial(int id, const std::string& texName, const Math::Point &uv,
int up, int right, int down, int left,
float hardness)
{
@ -166,7 +169,7 @@ void Gfx::CTerrain::AddMaterial(int id, const std::string& texName, const Math::
if (id == 0)
id = m_materialAutoID++;
Gfx::TerrainMaterial tm;
TerrainMaterial tm;
tm.texName = texName;
tm.id = id;
tm.uv = uv;
@ -191,7 +194,7 @@ void Gfx::CTerrain::AddMaterial(int id, const std::string& texName, const Math::
/**
* The image must be 24 bits/pixel and grayscale and dx x dy in size
* with dx = dy = (mosaic*brick)+1 */
bool Gfx::CTerrain::LoadResources(const std::string& fileName)
bool CTerrain::LoadResources(const std::string& fileName)
{
CImage img;
if (! img.Load(CApplication::GetInstance().GetDataFilePath(m_engine->GetTextureDir(), fileName)))
@ -220,17 +223,17 @@ bool Gfx::CTerrain::LoadResources(const std::string& fileName)
return true;
}
Gfx::TerrainRes Gfx::CTerrain::GetResource(const Math::Vector &p)
TerrainRes CTerrain::GetResource(const Math::Vector &p)
{
if (m_resources.empty())
return Gfx::TR_NULL;
return TR_NULL;
int x = static_cast<int>((p.x + (m_mosaicCount*m_brickCount*m_brickSize)/2.0f)/m_brickSize);
int y = static_cast<int>((p.z + (m_mosaicCount*m_brickCount*m_brickSize)/2.0f)/m_brickSize);
if ( x < 0 || x > m_mosaicCount*m_brickCount ||
y < 0 || y > m_mosaicCount*m_brickCount )
return Gfx::TR_NULL;
return TR_NULL;
int size = (m_mosaicCount*m_brickCount)+1;
@ -238,20 +241,20 @@ Gfx::TerrainRes Gfx::CTerrain::GetResource(const Math::Vector &p)
int resG = m_resources[3*x+3*size*(size-y-1)+1];
int resB = m_resources[3*x+3*size*(size-y-1)+2];
if (resR == 255 && resG == 0 && resB == 0) return Gfx::TR_STONE;
if (resR == 255 && resG == 255 && resB == 0) return Gfx::TR_URANIUM;
if (resR == 0 && resG == 255 && resB == 0) return Gfx::TR_POWER;
if (resR == 255 && resG == 0 && resB == 0) return TR_STONE;
if (resR == 255 && resG == 255 && resB == 0) return TR_URANIUM;
if (resR == 0 && resG == 255 && resB == 0) return TR_POWER;
// TODO key res values
//if (ress == 24) return Gfx::TR_KEY_A; // ~green?
//if (ress == 25) return Gfx::TR_KEY_B; // ~green?
//if (ress == 26) return Gfx::TR_KEY_C; // ~green?
//if (ress == 27) return Gfx::TR_KEY_D; // ~green?
//if (ress == 24) return TR_KEY_A; // ~green?
//if (ress == 25) return TR_KEY_B; // ~green?
//if (ress == 26) return TR_KEY_C; // ~green?
//if (ress == 27) return TR_KEY_D; // ~green?
return TR_NULL;
}
void Gfx::CTerrain::FlushRelief()
void CTerrain::FlushRelief()
{
m_relief.clear();
}
@ -259,7 +262,7 @@ void Gfx::CTerrain::FlushRelief()
/**
* The image must be 24 bits/pixel and dx x dy in size
* with dx = dy = (mosaic*brick)+1 */
bool Gfx::CTerrain::LoadRelief(const std::string &fileName, float scaleRelief,
bool CTerrain::LoadRelief(const std::string &fileName, float scaleRelief,
bool adjustBorder)
{
m_scaleRelief = scaleRelief;
@ -304,7 +307,7 @@ bool Gfx::CTerrain::LoadRelief(const std::string &fileName, float scaleRelief,
return true;
}
bool Gfx::CTerrain::AddReliefPoint(Math::Vector pos, float scaleRelief)
bool CTerrain::AddReliefPoint(Math::Vector pos, float scaleRelief)
{
float dim = (m_mosaicCount*m_brickCount*m_brickSize)/2.0f;
int size = (m_mosaicCount*m_brickCount)+1;
@ -324,7 +327,7 @@ bool Gfx::CTerrain::AddReliefPoint(Math::Vector pos, float scaleRelief)
return true;
}
void Gfx::CTerrain::AdjustRelief()
void CTerrain::AdjustRelief()
{
if (m_depth == 1) return;
@ -383,7 +386,7 @@ void Gfx::CTerrain::AdjustRelief()
}
}
Math::Vector Gfx::CTerrain::GetVector(int x, int y)
Math::Vector CTerrain::GetVector(int x, int y)
{
Math::Vector p;
p.x = x*m_brickSize - (m_mosaicCount*m_brickCount*m_brickSize) / 2.0;
@ -416,9 +419,9 @@ Math::Vector Gfx::CTerrain::GetVector(int x, int y)
| \| \|
+---f---e--> x
\endverbatim */
Gfx::VertexTex2 Gfx::CTerrain::GetVertex(int x, int y, int step)
VertexTex2 CTerrain::GetVertex(int x, int y, int step)
{
Gfx::VertexTex2 v;
VertexTex2 v;
Math::Vector o = GetVector(x, y);
v.coord = o;
@ -473,8 +476,8 @@ Gfx::VertexTex2 Gfx::CTerrain::GetVertex(int x, int y, int step)
|
+-------------------> x
\endverbatim */
bool Gfx::CTerrain::CreateMosaic(int ox, int oy, int step, int objRank,
const Gfx::Material &mat,
bool CTerrain::CreateMosaic(int ox, int oy, int step, int objRank,
const Material &mat,
float min, float max)
{
std::string texName1;
@ -494,7 +497,7 @@ bool Gfx::CTerrain::CreateMosaic(int ox, int oy, int step, int objRank,
int brick = m_brickCount/m_textureSubdivCount;
Gfx::VertexTex2 o = GetVertex(ox*m_brickCount+m_brickCount/2, oy*m_brickCount+m_brickCount/2, step);
VertexTex2 o = GetVertex(ox*m_brickCount+m_brickCount/2, oy*m_brickCount+m_brickCount/2, step);
int total = ((brick/step)+1)*2;
float pixel = 1.0f/256.0f; // 1 pixel cover (*)
@ -526,22 +529,22 @@ bool Gfx::CTerrain::CreateMosaic(int ox, int oy, int step, int objRank,
for (int y = 0; y < brick; y += step)
{
Gfx::EngineObjLevel4 buffer;
EngineObjLevel4 buffer;
buffer.vertices.reserve(total);
buffer.type = Gfx::ENG_TRIANGLE_TYPE_SURFACE;
buffer.type = ENG_TRIANGLE_TYPE_SURFACE;
buffer.material = mat;
buffer.state = Gfx::ENG_RSTATE_WRAP;
buffer.state = ENG_RSTATE_WRAP;
buffer.state |= Gfx::ENG_RSTATE_SECOND;
buffer.state |= ENG_RSTATE_SECOND;
if (step == 1)
buffer.state |= Gfx::ENG_RSTATE_DUAL_BLACK;
buffer.state |= ENG_RSTATE_DUAL_BLACK;
for (int x = 0; x <= brick; x += step)
{
Gfx::VertexTex2 p1 = GetVertex(ox*m_brickCount+mx*brick+x, oy*m_brickCount+my*brick+y+0 , step);
Gfx::VertexTex2 p2 = GetVertex(ox*m_brickCount+mx*brick+x, oy*m_brickCount+my*brick+y+step, step);
VertexTex2 p1 = GetVertex(ox*m_brickCount+mx*brick+x, oy*m_brickCount+my*brick+y+0 , step);
VertexTex2 p2 = GetVertex(ox*m_brickCount+mx*brick+x, oy*m_brickCount+my*brick+y+step, step);
p1.coord.x -= o.coord.x; p1.coord.z -= o.coord.z;
p2.coord.x -= o.coord.x; p2.coord.z -= o.coord.z;
@ -633,7 +636,7 @@ bool Gfx::CTerrain::CreateMosaic(int ox, int oy, int step, int objRank,
return true;
}
Gfx::TerrainMaterial* Gfx::CTerrain::FindMaterial(int id)
TerrainMaterial* CTerrain::FindMaterial(int id)
{
for (int i = 0; i < static_cast<int>( m_materials.size() ); i++)
{
@ -644,7 +647,7 @@ Gfx::TerrainMaterial* Gfx::CTerrain::FindMaterial(int id)
return nullptr;
}
void Gfx::CTerrain::GetTexture(int x, int y, std::string& name, Math::Point &uv)
void CTerrain::GetTexture(int x, int y, std::string& name, Math::Point &uv)
{
x /= m_brickCount/m_textureSubdivCount;
y /= m_brickCount/m_textureSubdivCount;
@ -662,7 +665,7 @@ void Gfx::CTerrain::GetTexture(int x, int y, std::string& name, Math::Point &uv)
}
}
float Gfx::CTerrain::GetHeight(int x, int y)
float CTerrain::GetHeight(int x, int y)
{
int size = (m_mosaicCount*m_brickCount+1);
@ -674,7 +677,7 @@ float Gfx::CTerrain::GetHeight(int x, int y)
return m_relief[x+y*size];
}
bool Gfx::CTerrain::CheckMaterialPoint(int x, int y, float min, float max, float slope)
bool CTerrain::CheckMaterialPoint(int x, int y, float min, float max, float slope)
{
float hc = GetHeight(x, y);
float h[4] =
@ -714,7 +717,7 @@ bool Gfx::CTerrain::CheckMaterialPoint(int x, int y, float min, float max, float
return false;
}
int Gfx::CTerrain::FindMaterialByNeighbors(char *mat)
int CTerrain::FindMaterialByNeighbors(char *mat)
{
for (int i = 0; i < static_cast<int>( m_materials.size() ); i++)
{
@ -727,7 +730,7 @@ int Gfx::CTerrain::FindMaterialByNeighbors(char *mat)
return -1;
}
void Gfx::CTerrain::SetMaterialPoint(int x, int y, int id, char *mat)
void CTerrain::SetMaterialPoint(int x, int y, int id, char *mat)
{
TerrainMaterial* tm = FindMaterial(id);
if (tm == nullptr) return;
@ -806,7 +809,7 @@ void Gfx::CTerrain::SetMaterialPoint(int x, int y, int id, char *mat)
}
}
bool Gfx::CTerrain::CondChangeMaterialPoint(int x, int y, int id, char *mat)
bool CTerrain::CondChangeMaterialPoint(int x, int y, int id, char *mat)
{
char test[4];
@ -862,7 +865,7 @@ bool Gfx::CTerrain::CondChangeMaterialPoint(int x, int y, int id, char *mat)
return true;
}
bool Gfx::CTerrain::ChangeMaterialPoint(int x, int y, int id)
bool CTerrain::ChangeMaterialPoint(int x, int y, int id)
{
char mat[4];
@ -1022,7 +1025,7 @@ bool Gfx::CTerrain::ChangeMaterialPoint(int x, int y, int id)
return false;
}
bool Gfx::CTerrain::InitMaterials(int id)
bool CTerrain::InitMaterials(int id)
{
TerrainMaterial* tm = FindMaterial(id);
if (tm == nullptr) return false;
@ -1038,7 +1041,7 @@ bool Gfx::CTerrain::InitMaterials(int id)
return true;
}
bool Gfx::CTerrain::GenerateMaterials(int *id, float min, float max,
bool CTerrain::GenerateMaterials(int *id, float min, float max,
float slope, float freq,
Math::Vector center, float radius)
{
@ -1118,13 +1121,13 @@ bool Gfx::CTerrain::GenerateMaterials(int *id, float min, float max,
return true;
}
void Gfx::CTerrain::InitMaterialPoints()
void CTerrain::InitMaterialPoints()
{
if (! m_useMaterials) return;
if (! m_materialPoints.empty()) return; // already allocated
m_materialPointCount = (m_mosaicCount*m_brickCount)/(m_brickCount/m_textureSubdivCount)+1;
std::vector<Gfx::TerrainMaterialPoint>(m_materialPointCount*m_materialPointCount).swap(m_materialPoints);
std::vector<TerrainMaterialPoint>(m_materialPointCount*m_materialPointCount).swap(m_materialPoints);
for (int i = 0; i < m_materialPointCount * m_materialPointCount; i++)
{
@ -1133,19 +1136,19 @@ void Gfx::CTerrain::InitMaterialPoints()
}
}
void Gfx::CTerrain::FlushMaterialPoints()
void CTerrain::FlushMaterialPoints()
{
m_materialPoints.clear();
}
bool Gfx::CTerrain::CreateSquare(int x, int y)
bool CTerrain::CreateSquare(int x, int y)
{
Gfx::Material mat;
mat.diffuse = Gfx::Color(1.0f, 1.0f, 1.0f);
mat.ambient = Gfx::Color(0.0f, 0.0f, 0.0f);
Material mat;
mat.diffuse = Color(1.0f, 1.0f, 1.0f);
mat.ambient = Color(0.0f, 0.0f, 0.0f);
int objRank = m_engine->CreateObject();
m_engine->SetObjectType(objRank, Gfx::ENG_OBJTYPE_TERRAIN);
m_engine->SetObjectType(objRank, ENG_OBJTYPE_TERRAIN);
m_objRanks[x+y*m_mosaicCount] = objRank;
@ -1163,7 +1166,7 @@ bool Gfx::CTerrain::CreateSquare(int x, int y)
return true;
}
bool Gfx::CTerrain::CreateObjects()
bool CTerrain::CreateObjects()
{
AdjustRelief();
@ -1177,7 +1180,7 @@ bool Gfx::CTerrain::CreateObjects()
}
/** ATTENTION: ok only with m_depth = 2! */
bool Gfx::CTerrain::Terraform(const Math::Vector &p1, const Math::Vector &p2, float height)
bool CTerrain::Terraform(const Math::Vector &p1, const Math::Vector &p2, float height)
{
float dim = (m_mosaicCount*m_brickCount*m_brickSize)/2.0f;
@ -1262,24 +1265,24 @@ bool Gfx::CTerrain::Terraform(const Math::Vector &p1, const Math::Vector &p2, fl
return true;
}
void Gfx::CTerrain::SetWind(Math::Vector speed)
void CTerrain::SetWind(Math::Vector speed)
{
m_wind = speed;
}
Math::Vector Gfx::CTerrain::GetWind()
Math::Vector CTerrain::GetWind()
{
return m_wind;
}
float Gfx::CTerrain::GetFineSlope(const Math::Vector &pos)
float CTerrain::GetFineSlope(const Math::Vector &pos)
{
Math::Vector n;
if (! GetNormal(n, pos)) return 0.0f;
return fabs(Math::RotateAngle(Math::Point(n.x, n.z).Length(), n.y) - Math::PI/2.0f);
}
float Gfx::CTerrain::GetCoarseSlope(const Math::Vector &pos)
float CTerrain::GetCoarseSlope(const Math::Vector &pos)
{
if (m_relief.empty()) return 0.0f;
@ -1305,7 +1308,7 @@ float Gfx::CTerrain::GetCoarseSlope(const Math::Vector &pos)
return atanf((max-min)/m_brickSize);
}
bool Gfx::CTerrain::GetNormal(Math::Vector &n, const Math::Vector &p)
bool CTerrain::GetNormal(Math::Vector &n, const Math::Vector &p)
{
float dim = (m_mosaicCount*m_brickCount*m_brickSize)/2.0f;
@ -1328,7 +1331,7 @@ bool Gfx::CTerrain::GetNormal(Math::Vector &n, const Math::Vector &p)
return true;
}
float Gfx::CTerrain::GetFloorLevel(const Math::Vector &pos, bool brut, bool water)
float CTerrain::GetFloorLevel(const Math::Vector &pos, bool brut, bool water)
{
float dim = (m_mosaicCount*m_brickCount*m_brickSize)/2.0f;
@ -1364,7 +1367,7 @@ float Gfx::CTerrain::GetFloorLevel(const Math::Vector &pos, bool brut, bool wate
return ps.y;
}
float Gfx::CTerrain::GetHeightToFloor(const Math::Vector &pos, bool brut, bool water)
float CTerrain::GetHeightToFloor(const Math::Vector &pos, bool brut, bool water)
{
float dim = (m_mosaicCount*m_brickCount*m_brickSize)/2.0f;
@ -1400,7 +1403,7 @@ float Gfx::CTerrain::GetHeightToFloor(const Math::Vector &pos, bool brut, bool w
return pos.y-ps.y;
}
bool Gfx::CTerrain::AdjustToFloor(Math::Vector &pos, bool brut, bool water)
bool CTerrain::AdjustToFloor(Math::Vector &pos, bool brut, bool water)
{
float dim = (m_mosaicCount*m_brickCount*m_brickSize)/2.0f;
@ -1438,7 +1441,7 @@ bool Gfx::CTerrain::AdjustToFloor(Math::Vector &pos, bool brut, bool water)
/**
* @returns \c false if the initial coordinate was outside terrain area; \c true otherwise
*/
bool Gfx::CTerrain::AdjustToStandardBounds(Math::Vector& pos)
bool CTerrain::AdjustToStandardBounds(Math::Vector& pos)
{
bool ok = true;
@ -1476,7 +1479,7 @@ bool Gfx::CTerrain::AdjustToStandardBounds(Math::Vector& pos)
* @param margin margin to the terrain border
* @returns \c false if the initial coordinate was outside terrain area; \c true otherwise
*/
bool Gfx::CTerrain::AdjustToBounds(Math::Vector& pos, float margin)
bool CTerrain::AdjustToBounds(Math::Vector& pos, float margin)
{
bool ok = true;
float limit = m_mosaicCount*m_brickCount*m_brickSize/2.0f - margin;
@ -1508,12 +1511,12 @@ bool Gfx::CTerrain::AdjustToBounds(Math::Vector& pos, float margin)
return ok;
}
void Gfx::CTerrain::FlushBuildingLevel()
void CTerrain::FlushBuildingLevel()
{
m_buildingLevels.clear();
}
bool Gfx::CTerrain::AddBuildingLevel(Math::Vector center, float min, float max,
bool CTerrain::AddBuildingLevel(Math::Vector center, float min, float max,
float height, float factor)
{
int i = 0;
@ -1527,7 +1530,7 @@ bool Gfx::CTerrain::AddBuildingLevel(Math::Vector center, float min, float max,
}
if (i == static_cast<int>( m_buildingLevels.size() ))
m_buildingLevels.push_back(Gfx::BuildingLevel());
m_buildingLevels.push_back(BuildingLevel());
m_buildingLevels[i].center = center;
m_buildingLevels[i].min = min;
@ -1543,7 +1546,7 @@ bool Gfx::CTerrain::AddBuildingLevel(Math::Vector center, float min, float max,
return true;
}
bool Gfx::CTerrain::UpdateBuildingLevel(Math::Vector center)
bool CTerrain::UpdateBuildingLevel(Math::Vector center)
{
for (int i = 0; i < static_cast<int>( m_buildingLevels.size() ); i++)
{
@ -1558,7 +1561,7 @@ bool Gfx::CTerrain::UpdateBuildingLevel(Math::Vector center)
return false;
}
bool Gfx::CTerrain::DeleteBuildingLevel(Math::Vector center)
bool CTerrain::DeleteBuildingLevel(Math::Vector center)
{
for (int i = 0; i < static_cast<int>( m_buildingLevels.size() ); i++)
{
@ -1575,7 +1578,7 @@ bool Gfx::CTerrain::DeleteBuildingLevel(Math::Vector center)
return false;
}
float Gfx::CTerrain::GetBuildingFactor(const Math::Vector &p)
float CTerrain::GetBuildingFactor(const Math::Vector &p)
{
for (int i = 0; i < static_cast<int>( m_buildingLevels.size() ); i++)
{
@ -1592,7 +1595,7 @@ float Gfx::CTerrain::GetBuildingFactor(const Math::Vector &p)
return 1.0f; // it is normal on the ground
}
void Gfx::CTerrain::AdjustBuildingLevel(Math::Vector &p)
void CTerrain::AdjustBuildingLevel(Math::Vector &p)
{
for (int i = 0; i < static_cast<int>( m_buildingLevels.size() ); i++)
{
@ -1628,7 +1631,7 @@ void Gfx::CTerrain::AdjustBuildingLevel(Math::Vector &p)
}
}
float Gfx::CTerrain::GetHardness(const Math::Vector &p)
float CTerrain::GetHardness(const Math::Vector &p)
{
float factor = GetBuildingFactor(p);
if (factor != 1.0f) return 1.0f; // on building level
@ -1658,7 +1661,7 @@ float Gfx::CTerrain::GetHardness(const Math::Vector &p)
return tm->hardness;
}
void Gfx::CTerrain::ShowFlatGround(Math::Vector pos)
void CTerrain::ShowFlatGround(Math::Vector pos)
{
static char table[41*41] = { 1 };
@ -1681,7 +1684,7 @@ void Gfx::CTerrain::ShowFlatGround(Math::Vector pos)
float angle = GetFineSlope(pos+p);
if (angle < Gfx::TERRAIN_FLATLIMIT)
if (angle < TERRAIN_FLATLIMIT)
table[i] = 1;
else
table[i] = 2;
@ -1691,10 +1694,10 @@ void Gfx::CTerrain::ShowFlatGround(Math::Vector pos)
m_engine->CreateGroundMark(pos, 40.0f, 0.001f, 15.0f, 0.001f, 41, 41, table);
}
float Gfx::CTerrain::GetFlatZoneRadius(Math::Vector center, float max)
float CTerrain::GetFlatZoneRadius(Math::Vector center, float max)
{
float angle = GetFineSlope(center);
if (angle >= Gfx::TERRAIN_FLATLIMIT)
if (angle >= TERRAIN_FLATLIMIT)
return 0.0f;
float ref = GetFloorLevel(center, true);
@ -1724,27 +1727,27 @@ float Gfx::CTerrain::GetFlatZoneRadius(Math::Vector center, float max)
return max;
}
void Gfx::CTerrain::SetFlyingMaxHeight(float height)
void CTerrain::SetFlyingMaxHeight(float height)
{
m_flyingMaxHeight = height;
}
float Gfx::CTerrain::GetFlyingMaxHeight()
float CTerrain::GetFlyingMaxHeight()
{
return m_flyingMaxHeight;
}
void Gfx::CTerrain::FlushFlyingLimit()
void CTerrain::FlushFlyingLimit()
{
m_flyingMaxHeight = 280.0f;
m_flyingLimits.clear();
}
void Gfx::CTerrain::AddFlyingLimit(Math::Vector center,
void CTerrain::AddFlyingLimit(Math::Vector center,
float extRadius, float intRadius,
float maxHeight)
{
Gfx::FlyingLimit fl;
FlyingLimit fl;
fl.center = center;
fl.extRadius = extRadius;
fl.intRadius = intRadius;
@ -1752,7 +1755,7 @@ void Gfx::CTerrain::AddFlyingLimit(Math::Vector center,
m_flyingLimits.push_back(fl);
}
float Gfx::CTerrain::GetFlyingLimit(Math::Vector pos, bool noLimit)
float CTerrain::GetFlyingLimit(Math::Vector pos, bool noLimit)
{
if (noLimit)
return 280.0f;
@ -1780,3 +1783,6 @@ float Gfx::CTerrain::GetFlyingLimit(Math::Vector pos, bool noLimit)
return m_flyingMaxHeight;
}
} // namespace Gfx

View File

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

View File

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

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

View File

@ -22,15 +22,17 @@
#pragma once
#include "const.h"
#include "math/const.h"
#include <cmath>
#include <cstdlib>
// Math module namespace
namespace Math
{
namespace Math {
//! Compares \a a and \a b within \a 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
#include "const.h"
#include "func.h"
#include "point.h"
#include "vector.h"
#include "matrix.h"
#include "math/const.h"
#include "math/func.h"
#include "math/point.h"
#include "math/matrix.h"
#include "math/vector.h"
#include <cmath>
#include <cstdlib>
// Math module namespace
namespace Math
{
namespace Math {
//! Returns py up on the line \a a - \a b
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;
}
}; // namespace Math
} // namespace Math

View File

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

View File

@ -21,17 +21,18 @@
#pragma once
#include "const.h"
#include "func.h"
#include "vector.h"
#include "math/const.h"
#include "math/func.h"
#include "math/vector.h"
#include <cmath>
#include <cassert>
// Math module namespace
namespace Math
{
namespace Math {
/**
* \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);
}
}; // namespace Math
} // namespace Math

View File

@ -21,16 +21,18 @@
#pragma once
#include "const.h"
#include "func.h"
#include "math/const.h"
#include "math/func.h"
#include <cmath>
#include <sstream>
// Math module namespace
namespace Math
{
namespace Math {
/**
* \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));
}
}; // 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(
.
../..
../../..
${GTEST_DIR}/include
)

View File

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

View File

@ -22,12 +22,14 @@
#include "CBot/CBotDll.h"
#include "app/app.h"
#include "common/event.h"
#include "common/global.h"
#include "common/iman.h"
#include "common/misc.h"
#include "common/profile.h"
#include "common/restext.h"
#include "graphics/engine/camera.h"
#include "graphics/engine/cloud.h"
#include "graphics/engine/engine.h"
@ -40,8 +42,10 @@
#include "graphics/engine/terrain.h"
#include "graphics/engine/text.h"
#include "graphics/engine/water.h"
#include "math/const.h"
#include "math/geometry.h"
#include "object/auto/auto.h"
#include "object/auto/autobase.h"
#include "object/brain.h"
@ -53,11 +57,15 @@
#include "object/task/task.h"
#include "object/task/taskbuild.h"
#include "object/task/taskmanip.h"
#include "physics/physics.h"
#include "script/cbottoken.h"
#include "script/cmdtoken.h"
#include "script/script.h"
#include "sound/sound.h"
#include "ui/button.h"
#include "ui/displayinfo.h"
#include "ui/displaytext.h"
@ -983,6 +991,8 @@ void CRobotMain::ChangePhase(Phase phase)
m_dialog->WriteGamerInfo();
}
m_app->SetLowCPU(true); // doesn't use much CPU in interface phases
DeleteAllObjects(); // removes all the current 3D Scene
m_phase = phase;
@ -1078,19 +1088,14 @@ void CRobotMain::ChangePhase(Phase phase)
if (m_phase == PHASE_INIT)
{
// TODO: replace with new textures once done
m_engine->DeleteTexture("generna.png");
m_engine->DeleteTexture("genernb.png");
m_engine->DeleteTexture("genernc.png");
m_engine->DeleteTexture("genernd.png");
m_engine->DeleteTexture("generic.png");
}
if (m_phase == PHASE_SIMUL)
{
m_engine->DeleteTexture("inter01a.png");
m_engine->DeleteTexture("inter01b.png");
m_engine->DeleteTexture("inter01c.png");
m_engine->DeleteTexture("inter01d.png");
m_engine->DeleteTexture("interface.png");
m_app->SetLowCPU(false); // high CPU for simulation
char* read = m_dialog->GetSceneRead();
bool loading = (read[0] != 0);
@ -1193,9 +1198,9 @@ void CRobotMain::ChangePhase(Phase phase)
}
if (m_phase == PHASE_LOADING)
m_engine->SetMouseVisible(false);
m_app->SetMouseMode(MOUSE_NONE);
else
m_engine->SetMouseVisible(true);
m_app->SetMouseMode(MOUSE_ENGINE);
m_engine->LoadAllTextures();
}
@ -2862,7 +2867,7 @@ void CRobotMain::HiliteObject(Math::Point pos)
if (m_fixScene && m_phase != PHASE_PERSO) return;
if (m_movieLock) return;
if (m_movie->IsExist()) return;
if (!m_engine->GetMouseVisible()) return;
if (m_app->GetMouseMode() == MOUSE_NONE) return;
ClearInterface(); // removes setting evidence and tooltip
@ -3171,7 +3176,7 @@ void CRobotMain::AbortMovie()
automat->Abort();
}
m_engine->SetMouseVisible(true);
m_app->SetMouseMode(MOUSE_ENGINE);
}
@ -6623,7 +6628,11 @@ void CRobotMain::SetMovieLock(bool lock)
CreateShortcuts();
m_map->ShowMap(!m_movieLock && m_mapShow);
if (m_movieLock) HiliteClear();
m_engine->SetMouseVisible(! m_movieLock);
if (m_movieLock)
m_app->SetMouseMode(MOUSE_NONE);
else
m_app->SetMouseMode(MOUSE_ENGINE);
}
bool CRobotMain::GetMovieLock()

File diff suppressed because it is too large Load Diff

View File

@ -1,95 +1,95 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
// *
// * This program is free software: you can redistribute it and/or modify
// * it under the terms of the GNU General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
// alsound.h
#pragma once
#include <map>
#include <string>
#include <AL/alut.h>
#include <common/iman.h>
#include <common/logger.h>
#include <sound/sound.h>
#include "buffer.h"
#include "channel.h"
#include "check.h"
class ALSound : public CSoundInterface
{
public:
ALSound();
~ALSound();
bool Create(bool b3D);
void CacheAll();
bool Cache(Sound, std::string);
bool RetEnable();
void SetSound3D(bool bMode);
bool RetSound3D();
bool RetSound3DCap();
void SetAudioVolume(int volume);
int RetAudioVolume();
void SetMusicVolume(int volume);
int RetMusicVolume();
void SetListener(Math::Vector eye, Math::Vector lookat);
void FrameMove(float rTime);
int Play(Sound sound, float amplitude=1.0f, float frequency=1.0f, bool bLoop = false);
int Play(Sound sound, Math::Vector pos, float amplitude=1.0f, float frequency=1.0f, bool bLoop = false);
bool FlushEnvelope(int channel);
bool AddEnvelope(int channel, float amplitude, float frequency, float time, SoundNext oper);
bool Position(int channel, Math::Vector pos);
bool Frequency(int channel, float frequency);
bool Stop(int channel);
bool StopAll();
bool MuteAll(bool bMute);
bool PlayMusic(int rank, bool bRepeat);
bool RestartMusic();
void SuspendMusic();
void StopMusic();
bool IsPlayingMusic();
// plugin interface
std::string PluginName();
int PluginVersion();
void InstallPlugin();
bool UninstallPlugin(std::string &);
private:
void CleanUp();
int RetPriority(Sound);
bool SearchFreeBuffer(Sound sound, int &channel, bool &bAlreadyLoaded);
bool mEnabled;
bool m3D;
bool mMute;
int mAudioVolume;
ALCdevice* audioDevice;
ALCcontext* audioContext;
std::map<Sound, Buffer*> mSounds;
std::map<int, Channel*> mChannels;
};
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
// *
// * This program is free software: you can redistribute it and/or modify
// * it under the terms of the GNU General Public License as published by
// * the Free Software Foundation, either version 3 of the License, or
// * (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
// alsound.h
#pragma once
#include <map>
#include <string>
#include <AL/alut.h>
#include <common/iman.h>
#include <common/logger.h>
#include <sound/sound.h>
#include "buffer.h"
#include "channel.h"
#include "check.h"
class ALSound : public CSoundInterface
{
public:
ALSound();
~ALSound();
bool Create(bool b3D);
void CacheAll();
bool Cache(Sound, std::string);
bool RetEnable();
void SetSound3D(bool bMode);
bool RetSound3D();
bool RetSound3DCap();
void SetAudioVolume(int volume);
int RetAudioVolume();
void SetMusicVolume(int volume);
int RetMusicVolume();
void SetListener(Math::Vector eye, Math::Vector lookat);
void FrameMove(float rTime);
int Play(Sound sound, float amplitude=1.0f, float frequency=1.0f, bool bLoop = false);
int Play(Sound sound, Math::Vector pos, float amplitude=1.0f, float frequency=1.0f, bool bLoop = false);
bool FlushEnvelope(int channel);
bool AddEnvelope(int channel, float amplitude, float frequency, float time, SoundNext oper);
bool Position(int channel, Math::Vector pos);
bool Frequency(int channel, float frequency);
bool Stop(int channel);
bool StopAll();
bool MuteAll(bool bMute);
bool PlayMusic(int rank, bool bRepeat);
bool RestartMusic();
void SuspendMusic();
void StopMusic();
bool IsPlayingMusic();
// plugin interface
std::string PluginName();
int PluginVersion();
void InstallPlugin();
bool UninstallPlugin(std::string &);
private:
void CleanUp();
int RetPriority(Sound);
bool SearchFreeBuffer(Sound sound, int &channel, bool &bAlreadyLoaded);
bool mEnabled;
bool m3D;
bool mMute;
int mAudioVolume;
ALCdevice* audioDevice;
ALCcontext* audioContext;
std::map<Sound, Buffer*> mSounds;
std::map<int, Channel*> mChannels;
};

View File

@ -1,286 +1,286 @@
#include "common/iman.h"
#include "common/logger.h"
#include "graphics/engine/modelfile.h"
#include <iostream>
#include <map>
bool EndsWith(std::string const &fullString, std::string const &ending)
{
if (fullString.length() >= ending.length()) {
return (0 == fullString.compare (fullString.length() - ending.length(), ending.length(), ending));
} else {
return false;
}
}
struct Args
{
bool usage;
bool dumpInfo;
bool mirror;
std::string inputFile;
std::string outputFile;
std::string inputFormat;
std::string outputFormat;
Args()
{
usage = false;
dumpInfo = false;
mirror = false;
}
};
Args ARGS;
void PrintUsage(const std::string& program)
{
std::cerr << "Colobot model converter" << std::endl;
std::cerr << std::endl;
std::cerr << "Usage:" << std::endl;
std::cerr << std::endl;
std::cerr << " Convert files:" << std::endl;
std::cerr << " " << program << " -i input_file -if input_format -o output_file -of output_format [-m]" << std::endl;
std::cerr << " -m => mirror" << std::endl;
std::cerr << std::endl;
std::cerr << " Dump info:" << std::endl;
std::cerr << " " << program << " -d -i input_file -if input_format" << std::endl;
std::cerr << std::endl;
std::cerr << " Help:" << std::endl;
std::cerr << " " << program << " -h" << std::endl;
std::cerr << std::endl;
std::cerr << "Model formats:" << std::endl;
std::cerr << " old => old binary format" << std::endl;
std::cerr << " new_bin => new binary format" << std::endl;
std::cerr << " new_txt => new text format" << std::endl;
}
bool ParseArgs(int argc, char *argv[])
{
bool waitI = false, waitO = false;
bool waitIf = false, waitOf = false;
for (int i = 1; i < argc; ++i)
{
std::string arg = std::string(argv[i]);
if (arg == "-i")
{
waitI = true;
continue;
}
if (arg == "-o")
{
waitO = true;
continue;
}
if (arg == "-if")
{
waitIf = true;
continue;
}
if (arg == "-of")
{
waitOf = true;
continue;
}
if (waitI)
{
waitI = false;
ARGS.inputFile = arg;
}
else if (waitO)
{
waitO = false;
ARGS.outputFile = arg;
}
else if (waitIf)
{
waitIf = false;
ARGS.inputFormat = arg;
}
else if (waitOf)
{
waitOf = false;
ARGS.outputFormat = arg;
}
else if (arg == "-h")
{
PrintUsage(argv[0]);
ARGS.usage = true;
}
else if (arg == "-d")
{
ARGS.dumpInfo = true;
}
else if (arg == "-m")
{
ARGS.mirror = true;
}
else
{
return false;
}
}
if (waitI || waitO || waitIf || waitOf)
return false;
if (ARGS.usage)
return true;
if (ARGS.inputFile.empty() || (!ARGS.dumpInfo && ARGS.outputFile.empty() ))
return false;
if (ARGS.inputFormat.empty() || (!ARGS.dumpInfo && ARGS.outputFormat.empty() ))
return false;
return true;
}
template<typename T>
void PrintStats(const std::map<T, int>& stats, int total)
{
for (auto it = stats.begin(); it != stats.end(); ++it)
{
std::cerr << " " << (*it).first << " : " << (*it).second << " / " << total << std::endl;
}
}
int main(int argc, char *argv[])
{
CLogger logger;
logger.SetLogLevel(LOG_ERROR);
if (!ParseArgs(argc, argv))
{
std::cerr << "Invalid arguments! Run with -h for usage info." << std::endl;
return 1;
}
if (ARGS.usage)
return 0;
CInstanceManager iMan;
Gfx::CModelFile model(&iMan);
bool ok = true;
if (ARGS.inputFormat == "old")
{
ok = model.ReadModel(ARGS.inputFile);
}
else if (ARGS.inputFormat == "new_bin")
{
ok = model.ReadBinaryModel(ARGS.inputFile);
}
else if (ARGS.inputFormat == "new_txt")
{
ok = model.ReadTextModel(ARGS.inputFile);
}
else
{
std::cerr << "Invalid input format" << std::endl;
return 1;
}
if (!ok)
{
std::cerr << "Reading input model failed" << std::endl;
return 1;
}
if (ARGS.dumpInfo)
{
const std::vector<Gfx::ModelTriangle>& triangles = model.GetTriangles();
Math::Vector min( Math::HUGE_NUM, Math::HUGE_NUM, Math::HUGE_NUM);
Math::Vector max(-Math::HUGE_NUM, -Math::HUGE_NUM, -Math::HUGE_NUM);
std::map<std::string, int> texs1, texs2;
std::map<int, int> states;
std::map<float, int> mins, maxs;
int variableTexs2 = 0;
for (int i = 0; i < static_cast<int>( triangles.size() ); ++i)
{
const Gfx::ModelTriangle& t = triangles[i];
min.x = Math::Min(t.p1.coord.x, t.p2.coord.x, t.p3.coord.x, min.x);
min.y = Math::Min(t.p1.coord.y, t.p2.coord.y, t.p3.coord.y, min.y);
min.z = Math::Min(t.p1.coord.z, t.p2.coord.z, t.p3.coord.z, min.z);
max.x = Math::Max(t.p1.coord.x, t.p2.coord.x, t.p3.coord.x, max.x);
max.y = Math::Max(t.p1.coord.y, t.p2.coord.y, t.p3.coord.y, max.y);
max.z = Math::Max(t.p1.coord.z, t.p2.coord.z, t.p3.coord.z, max.z);
texs1[t.tex1Name] += 1;
if (! t.tex2Name.empty())
texs2[t.tex2Name] += 1;
if (t.variableTex2)
variableTexs2 += 1;
states[t.state] += 1;
mins[t.min] += 1;
maxs[t.max] += 1;
}
std::cerr << "---- Info ----" << std::endl;
std::cerr << "Total triangles: " << triangles.size();
std::cerr << std::endl;
std::cerr << "Bounding box:" << std::endl;
std::cerr << " min: [" << min.x << ", " << min.y << ", " << min.z << "]" << std::endl;
std::cerr << " max: [" << max.x << ", " << max.y << ", " << max.z << "]" << std::endl;
std::cerr << std::endl;
std::cerr << "Textures:" << std::endl;
std::cerr << " tex1:" << std::endl;
PrintStats(texs1, triangles.size());
std::cerr << " tex2:" << std::endl;
PrintStats(texs2, triangles.size());
std::cerr << " variable tex2: " << variableTexs2 << " / " << triangles.size() << std::endl;
std::cerr << std::endl;
std::cerr << "States:" << std::endl;
PrintStats(states, triangles.size());
std::cerr << std::endl;
std::cerr << "LOD:" << std::endl;
std::cerr << " min:" << std::endl;
PrintStats(mins, triangles.size());
std::cerr << " max:" << std::endl;
PrintStats(maxs, triangles.size());
return 0;
}
if (ARGS.mirror)
model.Mirror();
if (ARGS.outputFormat == "old")
{
ok = model.WriteModel(ARGS.outputFile);
}
else if (ARGS.outputFormat == "new_bin")
{
ok = model.WriteBinaryModel(ARGS.outputFile);
}
else if (ARGS.outputFormat == "new_txt")
{
ok = model.WriteTextModel(ARGS.outputFile);
}
else
{
std::cerr << "Invalid output format" << std::endl;
return 1;
}
if (!ok)
{
std::cerr << "Writing output model failed" << std::endl;
return 1;
}
return 0;
}
#include "common/iman.h"
#include "common/logger.h"
#include "graphics/engine/modelfile.h"
#include <iostream>
#include <map>
bool EndsWith(std::string const &fullString, std::string const &ending)
{
if (fullString.length() >= ending.length()) {
return (0 == fullString.compare (fullString.length() - ending.length(), ending.length(), ending));
} else {
return false;
}
}
struct Args
{
bool usage;
bool dumpInfo;
bool mirror;
std::string inputFile;
std::string outputFile;
std::string inputFormat;
std::string outputFormat;
Args()
{
usage = false;
dumpInfo = false;
mirror = false;
}
};
Args ARGS;
void PrintUsage(const std::string& program)
{
std::cerr << "Colobot model converter" << std::endl;
std::cerr << std::endl;
std::cerr << "Usage:" << std::endl;
std::cerr << std::endl;
std::cerr << " Convert files:" << std::endl;
std::cerr << " " << program << " -i input_file -if input_format -o output_file -of output_format [-m]" << std::endl;
std::cerr << " -m => mirror" << std::endl;
std::cerr << std::endl;
std::cerr << " Dump info:" << std::endl;
std::cerr << " " << program << " -d -i input_file -if input_format" << std::endl;
std::cerr << std::endl;
std::cerr << " Help:" << std::endl;
std::cerr << " " << program << " -h" << std::endl;
std::cerr << std::endl;
std::cerr << "Model formats:" << std::endl;
std::cerr << " old => old binary format" << std::endl;
std::cerr << " new_bin => new binary format" << std::endl;
std::cerr << " new_txt => new text format" << std::endl;
}
bool ParseArgs(int argc, char *argv[])
{
bool waitI = false, waitO = false;
bool waitIf = false, waitOf = false;
for (int i = 1; i < argc; ++i)
{
std::string arg = std::string(argv[i]);
if (arg == "-i")
{
waitI = true;
continue;
}
if (arg == "-o")
{
waitO = true;
continue;
}
if (arg == "-if")
{
waitIf = true;
continue;
}
if (arg == "-of")
{
waitOf = true;
continue;
}
if (waitI)
{
waitI = false;
ARGS.inputFile = arg;
}
else if (waitO)
{
waitO = false;
ARGS.outputFile = arg;
}
else if (waitIf)
{
waitIf = false;
ARGS.inputFormat = arg;
}
else if (waitOf)
{
waitOf = false;
ARGS.outputFormat = arg;
}
else if (arg == "-h")
{
PrintUsage(argv[0]);
ARGS.usage = true;
}
else if (arg == "-d")
{
ARGS.dumpInfo = true;
}
else if (arg == "-m")
{
ARGS.mirror = true;
}
else
{
return false;
}
}
if (waitI || waitO || waitIf || waitOf)
return false;
if (ARGS.usage)
return true;
if (ARGS.inputFile.empty() || (!ARGS.dumpInfo && ARGS.outputFile.empty() ))
return false;
if (ARGS.inputFormat.empty() || (!ARGS.dumpInfo && ARGS.outputFormat.empty() ))
return false;
return true;
}
template<typename T>
void PrintStats(const std::map<T, int>& stats, int total)
{
for (auto it = stats.begin(); it != stats.end(); ++it)
{
std::cerr << " " << (*it).first << " : " << (*it).second << " / " << total << std::endl;
}
}
int main(int argc, char *argv[])
{
CLogger logger;
logger.SetLogLevel(LOG_ERROR);
if (!ParseArgs(argc, argv))
{
std::cerr << "Invalid arguments! Run with -h for usage info." << std::endl;
return 1;
}
if (ARGS.usage)
return 0;
CInstanceManager iMan;
Gfx::CModelFile model(&iMan);
bool ok = true;
if (ARGS.inputFormat == "old")
{
ok = model.ReadModel(ARGS.inputFile);
}
else if (ARGS.inputFormat == "new_bin")
{
ok = model.ReadBinaryModel(ARGS.inputFile);
}
else if (ARGS.inputFormat == "new_txt")
{
ok = model.ReadTextModel(ARGS.inputFile);
}
else
{
std::cerr << "Invalid input format" << std::endl;
return 1;
}
if (!ok)
{
std::cerr << "Reading input model failed" << std::endl;
return 1;
}
if (ARGS.dumpInfo)
{
const std::vector<Gfx::ModelTriangle>& triangles = model.GetTriangles();
Math::Vector min( Math::HUGE_NUM, Math::HUGE_NUM, Math::HUGE_NUM);
Math::Vector max(-Math::HUGE_NUM, -Math::HUGE_NUM, -Math::HUGE_NUM);
std::map<std::string, int> texs1, texs2;
std::map<int, int> states;
std::map<float, int> mins, maxs;
int variableTexs2 = 0;
for (int i = 0; i < static_cast<int>( triangles.size() ); ++i)
{
const Gfx::ModelTriangle& t = triangles[i];
min.x = Math::Min(t.p1.coord.x, t.p2.coord.x, t.p3.coord.x, min.x);
min.y = Math::Min(t.p1.coord.y, t.p2.coord.y, t.p3.coord.y, min.y);
min.z = Math::Min(t.p1.coord.z, t.p2.coord.z, t.p3.coord.z, min.z);
max.x = Math::Max(t.p1.coord.x, t.p2.coord.x, t.p3.coord.x, max.x);
max.y = Math::Max(t.p1.coord.y, t.p2.coord.y, t.p3.coord.y, max.y);
max.z = Math::Max(t.p1.coord.z, t.p2.coord.z, t.p3.coord.z, max.z);
texs1[t.tex1Name] += 1;
if (! t.tex2Name.empty())
texs2[t.tex2Name] += 1;
if (t.variableTex2)
variableTexs2 += 1;
states[t.state] += 1;
mins[t.min] += 1;
maxs[t.max] += 1;
}
std::cerr << "---- Info ----" << std::endl;
std::cerr << "Total triangles: " << triangles.size();
std::cerr << std::endl;
std::cerr << "Bounding box:" << std::endl;
std::cerr << " min: [" << min.x << ", " << min.y << ", " << min.z << "]" << std::endl;
std::cerr << " max: [" << max.x << ", " << max.y << ", " << max.z << "]" << std::endl;
std::cerr << std::endl;
std::cerr << "Textures:" << std::endl;
std::cerr << " tex1:" << std::endl;
PrintStats(texs1, triangles.size());
std::cerr << " tex2:" << std::endl;
PrintStats(texs2, triangles.size());
std::cerr << " variable tex2: " << variableTexs2 << " / " << triangles.size() << std::endl;
std::cerr << std::endl;
std::cerr << "States:" << std::endl;
PrintStats(states, triangles.size());
std::cerr << std::endl;
std::cerr << "LOD:" << std::endl;
std::cerr << " min:" << std::endl;
PrintStats(mins, triangles.size());
std::cerr << " max:" << std::endl;
PrintStats(maxs, triangles.size());
return 0;
}
if (ARGS.mirror)
model.Mirror();
if (ARGS.outputFormat == "old")
{
ok = model.WriteModel(ARGS.outputFile);
}
else if (ARGS.outputFormat == "new_bin")
{
ok = model.WriteBinaryModel(ARGS.outputFile);
}
else if (ARGS.outputFormat == "new_txt")
{
ok = model.WriteTextModel(ARGS.outputFile);
}
else
{
std::cerr << "Invalid output format" << std::endl;
return 1;
}
if (!ok)
{
std::cerr << "Writing output model failed" << std::endl;
return 1;
}
return 0;
}

View File

@ -160,7 +160,7 @@ void CCheck::Draw()
pos.x = m_pos.x + m_dim.y / 0.9f;
pos.y = m_pos.y + m_dim.y * 0.50f;
pos.y -= m_engine->GetText()->GetHeight(m_fontType, m_fontSize)/2.0f;
m_engine->GetText()->DrawText(m_name, m_fontType, m_fontSize, pos, m_dim.x, m_textAlign, 0);
m_engine->GetText()->DrawText(m_name, m_fontType, m_fontSize, pos, m_dim.x, Gfx::TEXT_ALIGN_LEFT, 0);
}
}

View File

@ -105,7 +105,7 @@ bool CColor::EventProcess(const Event &event)
}
if ( event.type == EVENT_MOUSE_BUTTON_DOWN &&
event.mouseButton.button == 1 &&
event.mouseButton.button == 1 &&
(m_state & STATE_VISIBLE) &&
(m_state & STATE_ENABLE) )
{

View File

@ -52,7 +52,7 @@ namespace Ui {
protected:
bool m_bRepeat;
float m_repeat;
Gfx::Color m_color;
Gfx::Color m_color;
};

View File

@ -199,13 +199,13 @@ std::string CControl::GetName()
void CControl::SetTextAlign(Gfx::TextAlign mode)
{
m_textAlign = mode;
m_textAlign = mode;
// m_justif = mode;
}
int CControl::GetTextAlign()
{
return m_textAlign;
return m_textAlign;
// return m_justif;
}

View File

@ -20,6 +20,7 @@
#include "common/global.h"
#include "common/event.h"
#include "common/logger.h"
#include "common/misc.h"
#include "common/profile.h"
#include "common/iman.h"
@ -53,9 +54,6 @@ namespace Ui
const int KEY_VISIBLE = 6; // number of visible keys redefinable
/*TODO: #if _SCHOOL & _TEEN
const int KEY_TOTAL = 13; // total number of keys redefinable
#else*/
const int KEY_TOTAL = 21; // total number of keys redefinable
const float WELCOME_LENGTH = 2.0f;
@ -100,36 +98,6 @@ static int perso_color[3*10*3] =
};
/* TODO: ? #if _NET
// Check if the key "school" is present in the registry.
bool SchoolCheck()
{
HKEY key;
char buffer[100];
LONG i;
DWORD type, len;
i = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
#if _NEWLOOK
"Software\\Epsitec\\CeeBot\\Setup",
#else
"Software\\Epsitec\\Colobot\\Setup",
#endif
0, KEY_READ, &key);
if ( i != ERROR_SUCCESS ) return false;
type = REG_SZ;
len = sizeof(buffer);
i = RegQueryValueEx(key, "School", NULL, &type, (LPBYTE)buffer, &len);
if ( i != ERROR_SUCCESS || type != REG_SZ ) return false;
if ( strcmp(buffer, "ToBoLoC") != 0 ) return false;
return true;
}
#endif
*/
// Constructor of robot application.
@ -157,11 +125,7 @@ CMainDialog::CMainDialog(CInstanceManager* iMan)
m_sceneRank = 0;
m_bSceneSoluce = false;
m_bSimulSetup = false;
/* TODO: ? #if _NET
m_accessEnable = SchoolCheck();
m_accessMission= false;
m_accessUser = false;
#else*/
m_accessEnable = true;
m_accessMission= true;
m_accessUser = true;
@ -363,14 +327,9 @@ void CMainDialog::ChangePhase(Phase phase)
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_DEFI);
pb->SetState(STATE_SHADOW);
/* TODO: setup mode?
if ( m_engine->GetSetupMode() )
{
pos.y = oy+sy*5.1f;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_SETUP);
pb->SetState(STATE_SHADOW);
} */
pos.y = oy+sy*5.1f;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_SETUP);
pb->SetState(STATE_SHADOW);
pos.y = oy+sy*4.0f;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_NAME);
@ -499,14 +458,12 @@ void CMainDialog::ChangePhase(Phase phase)
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_NOK);
pb->SetState(STATE_SHADOW);
/* TODO: #if !_TEEN
pos.x = 380.0f/640.0f;
pos.y = 250.0f/480.0f;
ddim.x =100.0f/640.0f;
ddim.y = 52.0f/480.0f;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_PERSO);
pb->SetState(STATE_SHADOW);
#endif*/
pos.x = 200.0f/640.0f;
pos.y = 150.0f/480.0f;
@ -2037,7 +1994,7 @@ void CMainDialog::ChangePhase(Phase phase)
// Processing an event.
// Geturns false if the event has been processed completely.
// Returns false if the event has been processed completely.
bool CMainDialog::EventProcess(const Event &event)
{
@ -2209,7 +2166,7 @@ bool CMainDialog::EventProcess(const Event &event)
return false;
}
if ( /*TODO: m_engine->GetMouseVisible() &&*/
if ( /* m_engine->GetMouseVisible() && TODO: WTF ?! */
!m_interface->EventProcess(event) )
{
return false;
@ -2786,8 +2743,11 @@ bool CMainDialog::EventProcess(const Event &event)
break;
case EVENT_INTERFACE_MOUSE:
m_engine->SetMouseVisible(!m_engine->GetMouseVisible());
// TODO: system mouse visible
if (m_app->GetMouseMode() == MOUSE_ENGINE)
m_app->SetMouseMode(MOUSE_SYSTEM);
else if (m_app->GetMouseMode() == MOUSE_SYSTEM)
m_app->SetMouseMode(MOUSE_ENGINE);
ChangeSetupButtons();
UpdateSetupButtons();
break;
@ -3243,7 +3203,7 @@ void CMainDialog::GlintMove()
}
// Geturns the position for a sound.
// Returns the position for a sound.
Math::Vector SoundPos(Math::Point pos)
{
@ -3256,7 +3216,7 @@ Math::Vector SoundPos(Math::Point pos)
return s;
}
// Geturns a random position for a sound.
// Returns a random position for a sound.
Math::Vector SoundRand()
{
@ -3643,7 +3603,7 @@ void CMainDialog::BuildResumeName(char *filename, char *base, int rank)
sprintf(filename, "Scene %s %d", base, rank);
}
// Geturns the name of the file or save the files.
// Returns the name of the file or save the files.
char* CMainDialog::GetFilesDir()
{
@ -4679,7 +4639,7 @@ bool CMainDialog::IOReadScene()
}
// Geturns the number of accessible chapters.
// Returns the number of accessible chapters.
int CMainDialog::GetChapPassed()
{
@ -5968,21 +5928,6 @@ void CMainDialog::ChangeSetupQuality(int quality)
static int key_table[KEY_TOTAL] =
{
/* TODO: #if _SCHOOL & _TEEN
INPUT_SLOT_LEFT,
INPUT_SLOT_RIGHT,
INPUT_SLOT_UP,
INPUT_SLOT_DOWN,
INPUT_SLOT_CAMERA,
INPUT_SLOT_NEAR,
INPUT_SLOT_AWAY,
INPUT_SLOT_HELP,
INPUT_SLOT_PROG,
INPUT_SLOT_SPEED10,
INPUT_SLOT_SPEED15,
INPUT_SLOT_SPEED20,
INPUT_SLOT_QUIT,
#else */
INPUT_SLOT_LEFT,
INPUT_SLOT_RIGHT,
INPUT_SLOT_UP,
@ -6004,26 +5949,10 @@ static int key_table[KEY_TOTAL] =
INPUT_SLOT_SPEED15,
INPUT_SLOT_SPEED20,
INPUT_SLOT_QUIT,
// #endif
};
static EventType key_event[KEY_TOTAL] =
{
/* TODO: #if _SCHOOL & _TEEN
EVENT_INTERFACE_KLEFT,
EVENT_INTERFACE_KRIGHT,
EVENT_INTERFACE_KUP,
EVENT_INTERFACE_KDOWN,
EVENT_INTERFACE_KCAMERA,
EVENT_INTERFACE_KNEAR,
EVENT_INTERFACE_KAWAY,
EVENT_INTERFACE_KHELP,
EVENT_INTERFACE_KPROG,
EVENT_INTERFACE_KSPEED10,
EVENT_INTERFACE_KSPEED15,
EVENT_INTERFACE_KSPEED20,
EVENT_INTERFACE_KQUIT,
#else */
EVENT_INTERFACE_KLEFT,
EVENT_INTERFACE_KRIGHT,
EVENT_INTERFACE_KUP,
@ -6045,7 +5974,6 @@ static EventType key_event[KEY_TOTAL] =
EVENT_INTERFACE_KSPEED15,
EVENT_INTERFACE_KSPEED20,
EVENT_INTERFACE_KQUIT,
//#endif
};
// Updates the list of keys.
@ -6179,13 +6107,9 @@ void CMainDialog::StartAbort()
pb->SetState(STATE_WARNING);
}
/* TODO: setup mode?
if ( m_engine->GetSetupMode() )
{
pos.y = 0.39f;
pb = pw->CreateButton(pos, dim, -1, EVENT_INTERFACE_SETUP);
pb->SetState(STATE_SHADOW);
}*/
pos.y = 0.39f;
pb = pw->CreateButton(pos, dim, -1, EVENT_INTERFACE_SETUP);
pb->SetState(STATE_SHADOW);
pos.y = 0.25f;
pb = pw->CreateButton(pos, dim, -1, EVENT_INTERFACE_AGAIN);
@ -6591,7 +6515,7 @@ void CMainDialog::SetSceneRead(const char* name)
strcpy(m_sceneRead, name);
}
// Geturns the name of the scene to read.
// Returns the name of the scene to read.
char* CMainDialog::GetSceneRead()
{
@ -6605,7 +6529,7 @@ void CMainDialog::SetStackRead(const char* name)
strcpy(m_stackRead, name);
}
// Geturns the name of the scene to read.
// Returns the name of the scene to read.
char* CMainDialog::GetStackRead()
{
@ -6619,7 +6543,7 @@ void CMainDialog::SetSceneName(const char* name)
strcpy(m_sceneName, name);
}
// Geturns the name of the chosen to play scene.
// Returns the name of the chosen to play scene.
char* CMainDialog::GetSceneName()
{
@ -6633,14 +6557,14 @@ void CMainDialog::SetSceneRank(int rank)
m_sceneRank = rank;
}
// Geturns the rank of the chosen to play scene.
// Returns the rank of the chosen to play scene.
int CMainDialog::GetSceneRank()
{
return m_sceneRank;
}
// Geturns folder name of the scene that user selected to play.
// Returns folder name of the scene that user selected to play.
char* CMainDialog::GetSceneDir()
{
@ -6659,14 +6583,14 @@ bool CMainDialog::GetSceneSoluce()
return m_bSceneSoluce;
}
// Geturns the name of the folder to save.
// Returns the name of the folder to save.
char* CMainDialog::GetSavegameDir()
{
return m_savegameDir;
}
// Geturns the name of public folder.
// Returns the name of public folder.
char* CMainDialog::GetPublicDir()
{
@ -6966,5 +6890,6 @@ bool CMainDialog::NextMission()
return true;
}
} // namespace Ui