summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2012-07-30 22:59:18 +0200
committerPiotr Dziwinski <piotrdz@gmail.com>2012-07-30 22:59:18 +0200
commit5e637ca0288ddd631ec33e1d620cd4a73bcdc2be (patch)
treeb26b0e9572f101744aba712133e646fb93ed58d2
parentd8a0c8d32e160e7ae86bb5b85ead8e5f71b1fd01 (diff)
downloadcolobot-5e637ca0288ddd631ec33e1d620cd4a73bcdc2be.tar.gz
colobot-5e637ca0288ddd631ec33e1d620cd4a73bcdc2be.tar.bz2
colobot-5e637ca0288ddd631ec33e1d620cd4a73bcdc2be.zip
Switched to new style casts
- rewrote old C-style casts to new ..._cast<> - corrected some dangerous casts - added -Wold-style-cast to compile flags
-rw-r--r--CMakeLists.txt4
-rw-r--r--src/app/app.cpp16
-rw-r--r--src/common/image.cpp6
-rw-r--r--src/common/iman.cpp2
-rw-r--r--src/common/ioutils.h18
-rw-r--r--src/common/stringutils.cpp8
-rw-r--r--src/graphics/core/color.cpp2
-rw-r--r--src/graphics/core/color.h4
-rw-r--r--src/graphics/engine/modelfile.cpp16
-rw-r--r--src/graphics/opengl/gldevice.cpp80
-rw-r--r--src/math/func.h10
-rw-r--r--src/math/matrix.h2
-rw-r--r--src/math/point.h4
-rw-r--r--src/math/vector.h4
14 files changed, 90 insertions, 86 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 092a812..98e9732 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -23,8 +23,8 @@ set(USE_GLEW auto)
set(CMAKE_BUILD_TYPE debug)
# Global compile flags
-set(CMAKE_CXX_FLAGS_RELEASE "-O2 -Wall -std=gnu++0x")
-set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -Wall -std=gnu++0x")
+set(CMAKE_CXX_FLAGS_RELEASE "-O2 -Wall -Wold-style-cast -std=gnu++0x")
+set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -Wall -Wold-style-cast -std=gnu++0x")
# Include cmake directory
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${colobot_SOURCE_DIR}/cmake")
diff --git a/src/app/app.cpp b/src/app/app.cpp
index 5c6ef49..d20232d 100644
--- a/src/app/app.cpp
+++ b/src/app/app.cpp
@@ -461,7 +461,7 @@ void CApplication::UpdateJoystick()
SDL_JoystickUpdate();
- for (int axis = 0; axis < (int) m_joyAxeState.size(); ++axis)
+ for (int axis = 0; axis < static_cast<int>( m_joyAxeState.size() ); ++axis)
{
int newValue = SDL_JoystickGetAxis(m_private->joystick, axis);
@@ -480,7 +480,7 @@ void CApplication::UpdateJoystick()
}
}
- for (int button = 0; button < (int) m_joyButtonState.size(); ++button)
+ for (int button = 0; button < static_cast<int>( m_joyButtonState.size() ); ++button)
{
bool newValue = SDL_JoystickGetButton(m_private->joystick, button) == 1;
@@ -621,14 +621,14 @@ PressState TranslatePressState(unsigned char state)
- y: 0=down, 1=up */
Math::Point CApplication::WindowToInterfaceCoords(Math::IntPoint pos)
{
- return Math::Point( (float)pos.x / (float)m_deviceConfig.size.w,
- 1.0f - (float)pos.y / (float)m_deviceConfig.size.h);
+ return Math::Point( static_cast<float>(pos.x) / static_cast<float>(m_deviceConfig.size.w),
+ 1.0f - static_cast<float>(pos.y) / static_cast<float>(m_deviceConfig.size.h) );
}
Math::IntPoint CApplication::InterfaceToWindowCoords(Math::Point pos)
{
- return Math::IntPoint((int)(pos.x * m_deviceConfig.size.w),
- (int)((1.0f - pos.y) * m_deviceConfig.size.h));
+ return Math::IntPoint(static_cast<int>(pos.x * m_deviceConfig.size.w),
+ static_cast<int>((1.0f - pos.y) * m_deviceConfig.size.h));
}
/** The SDL event parsed is stored internally.
@@ -822,10 +822,10 @@ VideoQueryResult CApplication::GetVideoResolutionList(std::vector<Math::IntSize>
SDL_Rect **modes = SDL_ListModes(NULL, videoFlags);
- if (modes == (SDL_Rect **)0)
+ if (modes == reinterpret_cast<SDL_Rect **>(0) )
return VIDEO_QUERY_NONE; // no modes available
- if (modes == (SDL_Rect **)-1)
+ if (modes == reinterpret_cast<SDL_Rect **>(-1) )
return VIDEO_QUERY_ALL; // all resolutions are possible
diff --git a/src/common/image.cpp b/src/common/image.cpp
index 78834b4..3d64377 100644
--- a/src/common/image.cpp
+++ b/src/common/image.cpp
@@ -102,7 +102,7 @@ bool PNGSaveSurface(const char *filename, SDL_Surface *surf)
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL)
{
- png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
+ png_destroy_write_struct(&png_ptr, static_cast<png_infopp>(NULL));
PNG_ERROR = "png_create_info_struct() error!";
return false;
}
@@ -123,9 +123,9 @@ bool PNGSaveSurface(const char *filename, SDL_Surface *surf)
png_write_info(png_ptr, info_ptr);
png_set_packing(png_ptr);
- row_pointers = (png_bytep*) malloc(sizeof(png_bytep)*surf->h);
+ row_pointers = static_cast<png_bytep*>( malloc(sizeof(png_bytep)*surf->h) );
for (i = 0; i < surf->h; i++)
- row_pointers[i] = (png_bytep)(Uint8 *)surf->pixels + i*surf->pitch;
+ row_pointers[i] = static_cast<png_bytep>( static_cast<Uint8 *>(surf->pixels) ) + i*surf->pitch;
png_write_image(png_ptr, row_pointers);
png_write_end(png_ptr, info_ptr);
diff --git a/src/common/iman.cpp b/src/common/iman.cpp
index 28ee3d3..90b0c1e 100644
--- a/src/common/iman.cpp
+++ b/src/common/iman.cpp
@@ -93,7 +93,7 @@ bool CInstanceManager::AddInstance(ClassType classType, void* pointer, int max)
if ( m_table[classType].classPointer == 0 )
{
- m_table[classType].classPointer = (void**)malloc(max*sizeof(void*));
+ m_table[classType].classPointer = static_cast<void**>( malloc(max*sizeof(void*)) );
m_table[classType].totalPossible = max;
m_table[classType].totalUsed = 0;
}
diff --git a/src/common/ioutils.h b/src/common/ioutils.h
index f17c961..a7bd044 100644
--- a/src/common/ioutils.h
+++ b/src/common/ioutils.h
@@ -21,6 +21,7 @@
#include <iostream>
+#include <cstring>
namespace IOUtils {
@@ -35,7 +36,7 @@ void WriteBinary(T value, std::ostream &ostr)
for (int i = 0; i < N; ++i)
{
unsigned char byte = (value >> (i*8)) & 0xFF;
- ostr.write((char*)&byte, 1);
+ ostr.write(reinterpret_cast<char*>(&byte), 1);
}
}
@@ -51,7 +52,7 @@ T ReadBinary(std::istream &istr)
for (int i = 0; i < N; ++i)
{
unsigned char byte = 0;
- istr.read((char*)&byte, 1);
+ istr.read(reinterpret_cast<char*>(&byte), 1);
value |= byte << (i*8);
}
return value;
@@ -63,8 +64,10 @@ T ReadBinary(std::istream &istr)
NOTE: code is probably not portable as there are platforms with other float representations. */
void WriteBinaryFloat(float value, std::ostream &ostr)
{
- unsigned int iValue = *( (unsigned int*)( (void*)(&value) ) );
- IOUtils::WriteBinary<4, unsigned int>(iValue, ostr);
+ union { float fValue; unsigned int iValue; } u;
+ memset(&u, 0, sizeof(u));
+ u.fValue = value;
+ IOUtils::WriteBinary<4, unsigned int>(u.iValue, ostr);
}
//! Reads a binary 32-bit float from input stream
@@ -73,9 +76,10 @@ void WriteBinaryFloat(float value, std::ostream &ostr)
NOTE: code is probably not portable as there are platforms with other float representations. */
float ReadBinaryFloat(std::istream &istr)
{
- unsigned int iValue = IOUtils::ReadBinary<4, unsigned int>(istr);
- float result = *( (float*)( (void*)(&iValue) ) );
- return result;
+ union { float fValue; unsigned int iValue; } u;
+ memset(&u, 0, sizeof(u));
+ u.iValue = IOUtils::ReadBinary<4, unsigned int>(istr);
+ return u.fValue;
}
}; // namespace IOUtils
diff --git a/src/common/stringutils.cpp b/src/common/stringutils.cpp
index 9a7aa61..585bb46 100644
--- a/src/common/stringutils.cpp
+++ b/src/common/stringutils.cpp
@@ -36,7 +36,7 @@ std::string StrUtils::UnicodeCharToUtf8(unsigned int ch)
std::string result;
if (ch < 0x0080)
{
- result += (char)(ch);
+ result += static_cast<char>(ch);
}
else if (ch < 0x0800)
{
@@ -61,7 +61,7 @@ std::string StrUtils::UnicodeStringToUtf8(const std::wstring &str)
{
std::string result;
for (unsigned int i = 0; i < str.size(); ++i)
- result += StrUtils::UnicodeCharToUtf8((unsigned int)str[i]);
+ result += StrUtils::UnicodeCharToUtf8(static_cast<unsigned int>(str[i]));
return result;
}
@@ -75,7 +75,7 @@ unsigned int StrUtils::Utf8CharToUnicode(const std::string &ch)
if ((ch[0] & 0x80) == 0)
{
if (ch.size() == 1)
- result = (unsigned int)ch[0];
+ result = static_cast<unsigned int>(ch[0]);
}
else if ((ch[0] & 0xC0) == 0xC0)
{
@@ -111,7 +111,7 @@ std::wstring StrUtils::Utf8StringToUnicode(const std::string &str)
break;
std::string ch = str.substr(pos, len);
- result += (wchar_t)(StrUtils::Utf8CharToUnicode(ch));
+ result += static_cast<wchar_t>(StrUtils::Utf8CharToUnicode(ch));
pos += len;
}
return result;
diff --git a/src/graphics/core/color.cpp b/src/graphics/core/color.cpp
index 8dec0e4..f241227 100644
--- a/src/graphics/core/color.cpp
+++ b/src/graphics/core/color.cpp
@@ -79,7 +79,7 @@ Gfx::Color Gfx::HSV2RGB(Gfx::ColorHSV color)
{
if ( color.h == 360.0f ) color.h = 0.0f;
color.h /= 60.0f;
- int i = (int)color.h; // integer part (0 .. 5)
+ int i = static_cast<int>(color.h); // integer part (0 .. 5)
float f = color.h-i; // fractional part
float v = color.v;
diff --git a/src/graphics/core/color.h b/src/graphics/core/color.h
index 907a3b9..6973644 100644
--- a/src/graphics/core/color.h
+++ b/src/graphics/core/color.h
@@ -44,13 +44,13 @@ struct Color
//! Returns the struct cast to \c float* array; use with care!
inline float* Array()
{
- return (float*)this;
+ return reinterpret_cast<float*>(this);
}
//! Returns the struct cast to <tt>const float*</tt> array; use with care!
inline const float* Array() const
{
- return (const float*)this;
+ return reinterpret_cast<const float*>(this);
}
//! Returns a string (r, g, b, a)
diff --git a/src/graphics/engine/modelfile.cpp b/src/graphics/engine/modelfile.cpp
index 537add4..844958f 100644
--- a/src/graphics/engine/modelfile.cpp
+++ b/src/graphics/engine/modelfile.cpp
@@ -246,7 +246,7 @@ Gfx::CModelFile::CModelFile(CInstanceManager* iMan)
{
m_iMan = iMan;
- m_engine = (CEngine*)m_iMan->SearchInstance(CLASS_ENGINE);
+ m_engine = static_cast<CEngine*>(m_iMan->SearchInstance(CLASS_ENGINE));
m_triangles.reserve(TRIANGLE_PREALLOCATE_COUNT);
}
@@ -431,7 +431,7 @@ bool Gfx::CModelFile::ReadModel(std::istream &stream, bool edit, bool meta)
}
}
- for (int i = 0; i < (int) m_triangles.size(); ++i)
+ for (int i = 0; i < static_cast<int>( m_triangles.size() ); ++i)
{
m_triangles[i].tex1Name = StrUtils::Replace(m_triangles[i].tex1Name, "bmp", "tga");
@@ -521,7 +521,7 @@ bool Gfx::CModelFile::WriteModel(std::ostream &stream)
for (int i = 0; i < 10; ++i)
IOUtils::WriteBinary<4, int>(header.reserved[i], stream);
- for (int i = 0; i < (int)m_triangles.size(); ++i)
+ for (int i = 0; i < static_cast<int>( m_triangles.size() ); ++i)
{
NewModelTriangle t;
@@ -701,9 +701,9 @@ bool Gfx::CModelFile::ReadDXF(std::istream &stream, float min, float max)
faceNum --;
if ( faceNum >= 0 )
{
- assert( (p1-1 >= 0) && (p1-1 < (int)vertices.size() ) );
- assert( (p2-1 >= 0) && (p2-1 < (int)vertices.size() ) );
- assert( (p3-1 >= 0) && (p3-1 < (int)vertices.size() ) );
+ assert( (p1-1 >= 0) && (p1-1 < static_cast<int>(vertices.size())) );
+ assert( (p2-1 >= 0) && (p2-1 < static_cast<int>(vertices.size())) );
+ assert( (p3-1 >= 0) && (p3-1 < static_cast<int>(vertices.size())) );
CreateTriangle(vertices[p3-1], vertices[p2-1], vertices[p1-1], min, max);
waitFaceX = true;
@@ -774,7 +774,7 @@ bool Gfx::CModelFile::CreateEngineObject(int objRank, int addState)
void Gfx::CModelFile::Mirror()
{
- for (int i = 0; i < (int)m_triangles.size(); i++)
+ for (int i = 0; i < static_cast<int>( m_triangles.size() ); i++)
{
Gfx::VertexTex2 t = m_triangles[i].p1;
m_triangles[i].p1 = m_triangles[i].p2;
@@ -804,7 +804,7 @@ float Gfx::CModelFile::GetHeight(Math::Vector pos)
{
float limit = 5.0f;
- for (int i = 0; i < (int)m_triangles.size(); i++)
+ for (int i = 0; i < static_cast<int>( m_triangles.size() ); i++)
{
if ( fabs(pos.x - m_triangles[i].p1.coord.x) < limit &&
fabs(pos.z - m_triangles[i].p1.coord.z) < limit )
diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp
index e80b101..3a255f4 100644
--- a/src/graphics/opengl/gldevice.cpp
+++ b/src/graphics/opengl/gldevice.cpp
@@ -266,7 +266,7 @@ void Gfx::CGLDevice::UpdateModelviewMatrix()
if (m_lighting)
{
- for (int index = 0; index < (int)m_lights.size(); ++index)
+ for (int index = 0; index < static_cast<int>( m_lights.size() ); ++index)
UpdateLightPosition(index);
}
}
@@ -293,7 +293,7 @@ int Gfx::CGLDevice::GetMaxLightCount()
void Gfx::CGLDevice::SetLight(int index, const Gfx::Light &light)
{
assert(index >= 0);
- assert(index < (int)m_lights.size());
+ assert(index < static_cast<int>( m_lights.size() ));
m_lights[index] = light;
@@ -322,7 +322,7 @@ void Gfx::CGLDevice::SetLight(int index, const Gfx::Light &light)
void Gfx::CGLDevice::UpdateLightPosition(int index)
{
assert(index >= 0);
- assert(index < (int)m_lights.size());
+ assert(index < static_cast<int>( m_lights.size() ));
if ((! m_lighting) || (! m_lightsEnabled[index]))
return;
@@ -357,7 +357,7 @@ void Gfx::CGLDevice::UpdateLightPosition(int index)
const Gfx::Light& Gfx::CGLDevice::GetLight(int index)
{
assert(index >= 0);
- assert(index < (int)m_lights.size());
+ assert(index < static_cast<int>( m_lights.size() ));
return m_lights[index];
}
@@ -365,7 +365,7 @@ const Gfx::Light& Gfx::CGLDevice::GetLight(int index)
void Gfx::CGLDevice::SetLightEnabled(int index, bool enabled)
{
assert(index >= 0);
- assert(index < (int)m_lights.size());
+ assert(index < static_cast<int>( m_lights.size() ));
m_lightsEnabled[index] = enabled;
@@ -375,7 +375,7 @@ void Gfx::CGLDevice::SetLightEnabled(int index, bool enabled)
bool Gfx::CGLDevice::GetLightEnabled(int index)
{
assert(index >= 0);
- assert(index < (int)m_lights.size());
+ assert(index < static_cast<int>( m_lights.size() ));
return m_lightsEnabled[index];
}
@@ -479,7 +479,7 @@ void Gfx::CGLDevice::DestroyTexture(const Gfx::Texture &texture)
m_allTextures.erase(it);
// Unbind the texture if in use anywhere
- for (int index = 0; index < (int)m_currentTextures.size(); ++index)
+ for (int index = 0; index < static_cast<int>( m_currentTextures.size() ); ++index)
{
if (m_currentTextures[index] == texture)
SetTexture(index, Gfx::Texture()); // set to invalid texture
@@ -508,7 +508,7 @@ int Gfx::CGLDevice::GetMaxTextureCount()
void Gfx::CGLDevice::SetTexture(int index, const Gfx::Texture &texture)
{
assert(index >= 0);
- assert(index < (int)m_currentTextures.size());
+ assert(index < static_cast<int>( m_currentTextures.size() ));
// Enable the given texture stage
glActiveTexture(GL_TEXTURE0 + index);
@@ -536,7 +536,7 @@ void Gfx::CGLDevice::SetTexture(int index, const Gfx::Texture &texture)
Gfx::Texture Gfx::CGLDevice::GetTexture(int index)
{
assert(index >= 0);
- assert(index < (int)m_currentTextures.size());
+ assert(index < static_cast<int>( m_currentTextures.size() ));
return m_currentTextures[index];
}
@@ -544,7 +544,7 @@ Gfx::Texture Gfx::CGLDevice::GetTexture(int index)
void Gfx::CGLDevice::SetTextureEnabled(int index, bool enabled)
{
assert(index >= 0);
- assert(index < (int)m_currentTextures.size());
+ assert(index < static_cast<int>( m_currentTextures.size() ));
m_texturesEnabled[index] = enabled;
@@ -558,7 +558,7 @@ void Gfx::CGLDevice::SetTextureEnabled(int index, bool enabled)
bool Gfx::CGLDevice::GetTextureEnabled(int index)
{
assert(index >= 0);
- assert(index < (int)m_currentTextures.size());
+ assert(index < static_cast<int>( m_currentTextures.size() ));
return m_texturesEnabled[index];
}
@@ -570,7 +570,7 @@ bool Gfx::CGLDevice::GetTextureEnabled(int index)
void Gfx::CGLDevice::SetTextureStageParams(int index, const Gfx::TextureStageParams &params)
{
assert(index >= 0);
- assert(index < (int)m_currentTextures.size());
+ assert(index < static_cast<int>( m_currentTextures.size() ));
// Remember the settings
m_textureStageParams[index] = params;
@@ -708,7 +708,7 @@ after_tex_operations:
Gfx::TextureStageParams Gfx::CGLDevice::GetTextureStageParams(int index)
{
assert(index >= 0);
- assert(index < (int)m_currentTextures.size());
+ assert(index < static_cast<int>( m_currentTextures.size() ));
return m_textureStageParams[index];
}
@@ -716,7 +716,7 @@ Gfx::TextureStageParams Gfx::CGLDevice::GetTextureStageParams(int index)
void Gfx::CGLDevice::SetTextureFactor(const Gfx::Color &color)
{
// Needs to be set for all texture stages
- for (int index = 0; index < (int)m_currentTextures.size(); ++index)
+ for (int index = 0; index < static_cast<int>( m_currentTextures.size() ); ++index)
{
// Activate stage
glActiveTexture(GL_TEXTURE0 + index);
@@ -908,7 +908,7 @@ void Gfx::CGLDevice::SetRenderState(Gfx::RenderState state, bool enabled)
if (enabled)
{
- for (int index = 0; index < (int)m_lights.size(); ++index)
+ for (int index = 0; index < static_cast<int>( m_lights.size() ); ++index)
UpdateLightPosition(index);
}
@@ -919,7 +919,7 @@ void Gfx::CGLDevice::SetRenderState(Gfx::RenderState state, bool enabled)
m_texturing = enabled;
// Enable/disable stages with new setting
- for (int index = 0; index < (int)m_currentTextures.size(); ++index)
+ for (int index = 0; index < static_cast<int>( m_currentTextures.size() ); ++index)
{
glActiveTexture(GL_TEXTURE0 + index);
if (m_texturing && m_texturesEnabled[index])
@@ -1019,9 +1019,9 @@ void Gfx::CGLDevice::SetDepthTestFunc(Gfx::CompFunc func)
Gfx::CompFunc Gfx::CGLDevice::GetDepthTestFunc()
{
- GLenum flag = 0;
- glGetIntegerv(GL_DEPTH_FUNC, (GLint*)&flag);
- return TranslateGLCompFunc(flag);
+ GLint flag = 0;
+ glGetIntegerv(GL_DEPTH_FUNC, &flag);
+ return TranslateGLCompFunc(static_cast<GLenum>(flag));
}
void Gfx::CGLDevice::SetDepthBias(float factor)
@@ -1043,11 +1043,11 @@ void Gfx::CGLDevice::SetAlphaTestFunc(Gfx::CompFunc func, float refValue)
void Gfx::CGLDevice::GetAlphaTestFunc(Gfx::CompFunc &func, float &refValue)
{
- GLenum flag = 0;
- glGetIntegerv(GL_ALPHA_TEST_FUNC, (GLint*)&flag);
- func = TranslateGLCompFunc(flag);
+ GLint flag = 0;
+ glGetIntegerv(GL_ALPHA_TEST_FUNC, &flag);
+ func = TranslateGLCompFunc(static_cast<GLenum>(flag));
- glGetFloatv(GL_ALPHA_TEST_REF, (GLfloat*) &refValue);
+ glGetFloatv(GL_ALPHA_TEST_REF, static_cast<GLfloat*>(&refValue));
}
Gfx::BlendFunc TranslateGLBlendFunc(GLenum flag)
@@ -1098,13 +1098,13 @@ void Gfx::CGLDevice::SetBlendFunc(Gfx::BlendFunc srcBlend, Gfx::BlendFunc dstBle
void Gfx::CGLDevice::GetBlendFunc(Gfx::BlendFunc &srcBlend, Gfx::BlendFunc &dstBlend)
{
- GLenum srcFlag = 0;
- glGetIntegerv(GL_ALPHA_TEST_FUNC, (GLint*)&srcFlag);
- srcBlend = TranslateGLBlendFunc(srcFlag);
+ GLint srcFlag = 0;
+ glGetIntegerv(GL_ALPHA_TEST_FUNC, &srcFlag);
+ srcBlend = TranslateGLBlendFunc(static_cast<GLenum>(srcFlag));
- GLenum dstFlag = 0;
- glGetIntegerv(GL_ALPHA_TEST_FUNC, (GLint*)&dstFlag);
- dstBlend = TranslateGLBlendFunc(dstFlag);
+ GLint dstFlag = 0;
+ glGetIntegerv(GL_ALPHA_TEST_FUNC, &dstFlag);
+ dstBlend = TranslateGLBlendFunc(static_cast<GLenum>(dstFlag));
}
void Gfx::CGLDevice::SetClearColor(const Gfx::Color &color)
@@ -1145,16 +1145,16 @@ void Gfx::CGLDevice::SetFogParams(Gfx::FogMode mode, const Gfx::Color &color, fl
void Gfx::CGLDevice::GetFogParams(Gfx::FogMode &mode, Gfx::Color &color, float &start, float &end, float &density)
{
- GLenum flag = 0;
- glGetIntegerv(GL_FOG_MODE, (GLint*)&flag);
+ GLint flag = 0;
+ glGetIntegerv(GL_FOG_MODE, &flag);
if (flag == GL_LINEAR) mode = Gfx::FOG_LINEAR;
else if (flag == GL_EXP) mode = Gfx::FOG_EXP;
else if (flag == GL_EXP2) mode = Gfx::FOG_EXP2;
else assert(false);
- glGetFloatv(GL_FOG_START, (GLfloat*)&start);
- glGetFloatv(GL_FOG_END, (GLfloat*)&end);
- glGetFloatv(GL_FOG_DENSITY, (GLfloat*)&density);
+ glGetFloatv(GL_FOG_START, static_cast<GLfloat*>(&start));
+ glGetFloatv(GL_FOG_END, static_cast<GLfloat*>(&end));
+ glGetFloatv(GL_FOG_DENSITY, static_cast<GLfloat*>(&density));
}
void Gfx::CGLDevice::SetCullMode(Gfx::CullMode mode)
@@ -1166,8 +1166,8 @@ void Gfx::CGLDevice::SetCullMode(Gfx::CullMode mode)
Gfx::CullMode Gfx::CGLDevice::GetCullMode()
{
- GLenum flag = 0;
- glGetIntegerv(GL_CULL_FACE, (GLint*)&flag);
+ GLint flag = 0;
+ glGetIntegerv(GL_CULL_FACE, &flag);
if (flag == GL_CW) return Gfx::CULL_CW;
else if (flag == GL_CCW) return Gfx::CULL_CCW;
else assert(false);
@@ -1183,8 +1183,8 @@ void Gfx::CGLDevice::SetShadeModel(Gfx::ShadeModel model)
Gfx::ShadeModel Gfx::CGLDevice::GetShadeModel()
{
- GLenum flag = 0;
- glGetIntegerv(GL_SHADE_MODEL, (GLint*)&flag);
+ GLint flag = 0;
+ glGetIntegerv(GL_SHADE_MODEL, &flag);
if (flag == GL_FLAT) return Gfx::SHADE_FLAT;
else if (flag == GL_SMOOTH) return Gfx::SHADE_SMOOTH;
else assert(false);
@@ -1201,8 +1201,8 @@ void Gfx::CGLDevice::SetFillMode(Gfx::FillMode mode)
Gfx::FillMode Gfx::CGLDevice::GetFillMode()
{
- GLenum flag = 0;
- glGetIntegerv(GL_POLYGON_MODE, (GLint*)&flag);
+ GLint flag = 0;
+ glGetIntegerv(GL_POLYGON_MODE, &flag);
if (flag == GL_POINT) return Gfx::FILL_POINT;
else if (flag == GL_LINE) return Gfx::FILL_LINES;
else if (flag == GL_FILL) return Gfx::FILL_FILL;
diff --git a/src/math/func.h b/src/math/func.h
index 9a417dc..2127d1a 100644
--- a/src/math/func.h
+++ b/src/math/func.h
@@ -118,13 +118,13 @@ inline void Swap(float &a, float &b)
Mod(n, 1) = fractional part of n */
inline float Mod(float a, float m)
{
- return a - ((int)(a/m))*m;
+ return a - ( static_cast<int>(a / m) ) * m;
}
//! Returns a random value between 0 and 1.
inline float Rand()
{
- return (float)rand()/RAND_MAX;
+ return static_cast<float>(rand()) / static_cast<float>(RAND_MAX);
}
//! Returns a normalized angle, that is in other words between 0 and 2 * PI
@@ -153,10 +153,10 @@ inline bool TestAngle(float angle, float min, float max)
//! Calculates a value (radians) proportional between a and b (degrees)
inline float PropAngle(int a, int b, float p)
{
- float aa = (float)a * DEG_TO_RAD;
- float bb = (float)b * DEG_TO_RAD;
+ float aa = static_cast<float>(a) * DEG_TO_RAD;
+ float bb = static_cast<float>(b) * DEG_TO_RAD;
- return aa+p*(bb-aa);
+ return aa + p * (bb - aa);
}
//! Calculates the angle to rotate the angle \a a to the angle \a g
diff --git a/src/math/matrix.h b/src/math/matrix.h
index 7ee40e8..45a7d75 100644
--- a/src/math/matrix.h
+++ b/src/math/matrix.h
@@ -121,7 +121,7 @@ struct Matrix
//! Returns the struct cast to \c float* array; use with care!
inline float* Array()
{
- return (float*)this;
+ return reinterpret_cast<float*>(this);
}
//! Transposes the matrix
diff --git a/src/math/point.h b/src/math/point.h
index 740b275..ea20db9 100644
--- a/src/math/point.h
+++ b/src/math/point.h
@@ -71,13 +71,13 @@ struct Point
//! Returns the struct cast to \c float* array; use with care!
inline float* Array()
{
- return (float*)this;
+ return reinterpret_cast<float*>(this);
}
//! Returns the struct cast to <tt>const float*</tt> array; use with care!
inline const float* Array() const
{
- return (const float*)this;
+ return reinterpret_cast<const float*>(this);
}
//! Returns the distance from (0,0) to the point (x,y)
diff --git a/src/math/vector.h b/src/math/vector.h
index 148d648..147869f 100644
--- a/src/math/vector.h
+++ b/src/math/vector.h
@@ -76,13 +76,13 @@ struct Vector
//! Returns the struct cast to \c float* array; use with care!
inline float* Array()
{
- return (float*)this;
+ return reinterpret_cast<float*>(this);
}
//! Returns the struct cast to <tt>const float*</tt> array; use with care!
inline const float* Array() const
{
- return (const float*)this;
+ return reinterpret_cast<const float*>(this);
}
//! Returns the vector length