Moved all VS specific math code (i.e. for round(), isnan) into vs.hpp

and used it everywhere (I hope).


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@14640 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2013-12-06 03:49:55 +00:00
parent 33525285d7
commit b074dc5f09
7 changed files with 13 additions and 30 deletions

View File

@ -35,7 +35,6 @@
#include "utils/string_utils.hpp"
#include "utils/time.hpp"
#include "utils/translation.hpp"
#include "utils/vs.hpp"
// ----------------------------------------------------------------------------
/** Create a thread that handles all network functions independent of the

View File

@ -25,6 +25,7 @@
#include "config/user_config.hpp"
#include "io/file_manager.hpp"
#include "race/race_manager.hpp"
#include "utils/vs.hpp"
#ifdef __APPLE__
# include <OpenAL/al.h>
@ -33,16 +34,10 @@
#endif
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <string>
#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__MINGW32__)
# define isnan _isnan
#else
# include <math.h>
#endif
SFXOpenAL::SFXOpenAL(SFXBuffer* buffer, bool positional, float gain, bool ownsBuffer) : SFXBase()
{
m_soundBuffer = buffer;

View File

@ -323,10 +323,10 @@ void LayoutManager::applyCoords(Widget* self, AbstractTopLevelContainer* topLeve
else if (self->m_relative_y > -1) self->m_y = (int)(parent_y + parent_h*self->m_relative_y/100);
if (self->m_absolute_w > -1) self->m_w = self->m_absolute_w;
else if (self->m_relative_w > -1) self->m_w = (int)roundf(parent_w*self->m_relative_w/100.0);
else if (self->m_relative_w > -1) self->m_w = (int)roundf(parent_w*self->m_relative_w/100.0f);
if (self->m_absolute_h > -1) self->m_h = self->m_absolute_h;
else if (self->m_relative_h > -1) self->m_h = (int)roundf(parent_h*self->m_relative_h/100.0);
else if (self->m_relative_h > -1) self->m_h = (int)roundf(parent_h*self->m_relative_h/100.0f);
// ---- can't make widget bigger than parent
if (self->m_h > (int)parent_h)

View File

@ -265,8 +265,6 @@ void DynamicRibbonWidget::add()
assert(m_row_amount != -1);
}
// m_row_amount = (int)round((m_h - m_label_height) / (float)m_child_height);
if (m_properties[PROP_MAX_ROWS].size() > 0)
{
const int max_rows = atoi(m_properties[PROP_MAX_ROWS].c_str());

View File

@ -19,20 +19,12 @@
#include "guiengine/modaldialog.hpp"
#include "guiengine/widgets/rating_bar_widget.hpp"
#include "utils/string_utils.hpp"
#include "utils/vs.hpp"
#include <IGUIEnvironment.h>
#include <IGUIElement.h>
#include <IGUIButton.h>
#include <cmath>
#if defined(WIN32) && _MSC_VER < 1800
// VS up to and including VS 2012 do not provide the normal round function
static inline float round(float val)
{
return floor(val + 0.5f);
}
#endif
#include <string.h>
using namespace GUIEngine;
@ -87,7 +79,7 @@ void RatingBarWidget::setStepValues(float float_rating)
m_star_values[star] = m_steps-1;
else
{
m_star_values[star] =(int)round((float_rating * (m_steps-1)) - (star*(m_steps-1)));
m_star_values[star] =(int)roundf((float_rating * (m_steps-1)) - (star*(m_steps-1)));
}
}
}
@ -109,7 +101,7 @@ void RatingBarWidget::setStepValuesByMouse(const core::position2di & mouse_posit
{
m_hovering = true;
float exact_hover = (float)(mouse_position.X - stars_rect.UpperLeftCorner.X) / (float)stars_rect.getWidth() * (float)m_stars;
m_hover_rating = round(exact_hover * (m_steps-1)) / (m_steps-1);
m_hover_rating = roundf(exact_hover * (m_steps-1)) / (m_steps-1);
setStepValues(m_hover_rating);
}
else if(m_hovering)

View File

@ -30,7 +30,6 @@
#if defined(WIN32) && !defined(__CYGWIN__)
# include <windows.h>
# define isnan _isnan
#else
# include <sys/time.h>
# include <math.h>

View File

@ -1,12 +1,12 @@
// Visual studio workarounds in one place
/** Visual studio workarounds in one place
* Note that Visual Studio 2013 does have the maths functions defined,
* so we define the work arounds only for compiler versions before 18.00
*/
#if defined(_MSC_VER)
# include <WinSock2.h>
# include <windows.h>
#if defined(WIN32) && _MSC_VER < 1800
# include <math.h>
# define isnan _isnan
//# define round(x) (floor(x + 0.5f))
# define roundf(x) (floor(x + 0.5f))
# define roundf(x) (floorf(x + 0.5f))
#endif