Author: grumbel Date: 2008-07-03 22:07:57 +0200 (Thu, 03 Jul 2008) New Revision: 3644
Added: trunk/pingus/src/math.cpp Modified: trunk/pingus/SConstruct trunk/pingus/src/actions/angel.cpp trunk/pingus/src/actions/angel.hpp trunk/pingus/src/actions/boarder.hpp trunk/pingus/src/actions/faller.cpp trunk/pingus/src/actions/superman.hpp trunk/pingus/src/components/playfield.cpp trunk/pingus/src/graphic_context_state.cpp trunk/pingus/src/input/control.hpp trunk/pingus/src/input_old/pointers/axis_pointer.cpp trunk/pingus/src/input_old/scrollers/axis_scroller.cpp trunk/pingus/src/layer_manager.hpp trunk/pingus/src/math.hpp trunk/pingus/src/math/rect.cpp trunk/pingus/src/math/vector2f.cpp trunk/pingus/src/math/vector3f.cpp trunk/pingus/src/pingu.cpp trunk/pingus/src/pingu.hpp trunk/pingus/src/pingu_action.cpp trunk/pingus/src/world.cpp trunk/pingus/src/worldmap/level_dot.cpp trunk/pingus/src/worldmap/path_graph.cpp trunk/pingus/src/worldmap/pingus.hpp trunk/pingus/src/worldobjs/snow_generator.cpp Log: Wrappered all math.h calls to Math:: calls Modified: trunk/pingus/SConstruct =================================================================== --- trunk/pingus/SConstruct 2008-07-03 19:40:44 UTC (rev 3643) +++ trunk/pingus/SConstruct 2008-07-03 20:07:57 UTC (rev 3644) @@ -232,6 +232,7 @@ 'src/string_util.cpp', 'src/math/origin.cpp', 'src/math/rect.cpp', +'src/math.cpp', 'src/system.cpp', 'src/timer.cpp', 'src/tinygettext/iconv.cpp', Modified: trunk/pingus/src/actions/angel.cpp =================================================================== --- trunk/pingus/src/actions/angel.cpp 2008-07-03 19:40:44 UTC (rev 3643) +++ trunk/pingus/src/actions/angel.cpp 2008-07-03 20:07:57 UTC (rev 3644) @@ -15,9 +15,9 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. -#include <math.h> #include "../display/scene_context.hpp" #include "../pingu.hpp" +#include "../math.hpp" #include "../resource.hpp" #include "../globals.hpp" #include "angel.hpp" @@ -38,7 +38,7 @@ sprite.update (); counter += game_speed; - pingu->set_pos((float)x_pos + 20 * (float)sin (counter * 3.0f), pingu->get_y() - 50.0f * 0.025f); + pingu->set_pos((float)x_pos + 20 * (float)Math::sin(counter * 3.0f), pingu->get_y() - 50.0f * 0.025f); // Out of screen, let the pingu die if (pingu->get_y() < -32) Modified: trunk/pingus/src/actions/angel.hpp =================================================================== --- trunk/pingus/src/actions/angel.hpp 2008-07-03 19:40:44 UTC (rev 3643) +++ trunk/pingus/src/actions/angel.hpp 2008-07-03 20:07:57 UTC (rev 3644) @@ -25,8 +25,8 @@ class Angel : public PinguAction { private: - double counter; - double x_pos; + float counter; + float x_pos; Sprite sprite; public: Modified: trunk/pingus/src/actions/boarder.hpp =================================================================== --- trunk/pingus/src/actions/boarder.hpp 2008-07-03 19:40:44 UTC (rev 3643) +++ trunk/pingus/src/actions/boarder.hpp 2008-07-03 20:07:57 UTC (rev 3644) @@ -28,7 +28,6 @@ class Boarder : public PinguAction { private: - //double counter; float x_pos; float speed; StateSprite sprite; Modified: trunk/pingus/src/actions/faller.cpp =================================================================== --- trunk/pingus/src/actions/faller.cpp 2008-07-03 19:40:44 UTC (rev 3643) +++ trunk/pingus/src/actions/faller.cpp 2008-07-03 20:07:57 UTC (rev 3644) @@ -15,7 +15,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. -#include <math.h> +#include "../math.hpp" #include "../col_map.hpp" #include "../colliders/pingu_collider.hpp" #include "../debug.hpp" @@ -108,7 +108,7 @@ pingu->set_action(Actions::Drown); } // Did we stop too fast? - else if (fabs(pingu->get_velocity().y) > deadly_velocity) + else if (Math::abs(pingu->get_velocity().y) > deadly_velocity) { //std::cout << "Pingus splashed: " << pingu->get_velocity().y << " " << deadly_velocity << std::endl; pingu->set_action(Actions::Splashed); @@ -146,8 +146,8 @@ Faller::is_tumbling () const { // If we are going fast enough to get smashed, start tumbling - return ( fabs(pingu->get_velocity().x) > deadly_velocity - || fabs(pingu->get_velocity().y) > deadly_velocity); + return (Math::abs(pingu->get_velocity().x) > deadly_velocity + || Math::abs(pingu->get_velocity().y) > deadly_velocity); } bool Modified: trunk/pingus/src/actions/superman.hpp =================================================================== --- trunk/pingus/src/actions/superman.hpp 2008-07-03 19:40:44 UTC (rev 3643) +++ trunk/pingus/src/actions/superman.hpp 2008-07-03 20:07:57 UTC (rev 3644) @@ -25,8 +25,8 @@ class Superman : public PinguAction { private: - double counter; - double x_pos; + float counter; + float x_pos; Sprite sprite; public: Modified: trunk/pingus/src/components/playfield.cpp =================================================================== --- trunk/pingus/src/components/playfield.cpp 2008-07-03 19:40:44 UTC (rev 3643) +++ trunk/pingus/src/components/playfield.cpp 2008-07-03 20:07:57 UTC (rev 3644) @@ -98,8 +98,8 @@ Pingu* Playfield::current_pingu_find(const Vector2f& pos) { - double min_dist = 500.0; - double dist; + float min_dist = 500.0; + float dist; Pingu* c_pingu = 0; for (PinguIter pingu = server->get_world()->get_pingus()->begin(); Modified: trunk/pingus/src/graphic_context_state.cpp =================================================================== --- trunk/pingus/src/graphic_context_state.cpp 2008-07-03 19:40:44 UTC (rev 3643) +++ trunk/pingus/src/graphic_context_state.cpp 2008-07-03 20:07:57 UTC (rev 3644) @@ -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/>. -#include <math.h> #include "math.hpp" #include "display/display.hpp" #include "graphic_context_state.hpp" @@ -226,8 +225,8 @@ Vector2f pos(float(pos_.x - impl->rect.left), float(pos_.y - impl->rect.top)); - float sa = (float)sin(-impl->rotation/180.0f*Math::pi); - float ca = (float)cos(-impl->rotation/180.0f*Math::pi); + float sa = Math::sin(-impl->rotation/180.0f*Math::pi); + float ca = Math::cos(-impl->rotation/180.0f*Math::pi); float dx = pos.x - (float)get_width()/2; float dy = pos.y - (float)get_height()/2; Modified: trunk/pingus/src/input/control.hpp =================================================================== --- trunk/pingus/src/input/control.hpp 2008-07-03 19:40:44 UTC (rev 3643) +++ trunk/pingus/src/input/control.hpp 2008-07-03 20:07:57 UTC (rev 3644) @@ -20,7 +20,6 @@ #include <iostream> #include <vector> -#include <math.h> #include "math.hpp" #include "math/vector2f.hpp" @@ -167,7 +166,7 @@ if (invert) new_pos = -new_pos; - if (fabsf(new_pos) < dead_zone) + if (Math::abs(new_pos) < dead_zone) new_pos = 0.0f; if (new_pos != pos) Modified: trunk/pingus/src/input_old/pointers/axis_pointer.cpp =================================================================== --- trunk/pingus/src/input_old/pointers/axis_pointer.cpp 2008-07-03 19:40:44 UTC (rev 3643) +++ trunk/pingus/src/input_old/pointers/axis_pointer.cpp 2008-07-03 20:07:57 UTC (rev 3644) @@ -16,7 +16,6 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#include <math.h> #include <assert.h> #include "../axis.hpp" #include "axis_pointer.hpp" @@ -62,8 +61,8 @@ { (*it)->update(delta); - x_pos += (float)cos((*it)->get_angle() * 3.14159265 / 180) * speed * delta * (*it)->get_pos(); - y_pos += (float)sin((*it)->get_angle() * 3.14159265 / 180) * speed * delta * (*it)->get_pos(); + x_pos += (float)Math::cos((*it)->get_angle() * 3.14159265 / 180) * speed * delta * (*it)->get_pos(); + y_pos += (float)Math::sin((*it)->get_angle() * 3.14159265 / 180) * speed * delta * (*it)->get_pos(); } } Modified: trunk/pingus/src/input_old/scrollers/axis_scroller.cpp =================================================================== --- trunk/pingus/src/input_old/scrollers/axis_scroller.cpp 2008-07-03 19:40:44 UTC (rev 3643) +++ trunk/pingus/src/input_old/scrollers/axis_scroller.cpp 2008-07-03 20:07:57 UTC (rev 3644) @@ -16,7 +16,6 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#include <math.h> #include <assert.h> #include "../../debug.hpp" #include "../../math.hpp" @@ -71,8 +70,8 @@ { (*it)->update(delta); - x_delta += (float)cos((*it)->get_angle() * Math::pi / 180) * speed * delta * (*it)->get_pos(); - y_delta += (float)sin((*it)->get_angle() * Math::pi / 180) * speed * delta * (*it)->get_pos(); + x_delta += (float)Math::cos((*it)->get_angle() * Math::pi / 180) * speed * delta * (*it)->get_pos(); + y_delta += (float)Math::sin((*it)->get_angle() * Math::pi / 180) * speed * delta * (*it)->get_pos(); } } Modified: trunk/pingus/src/layer_manager.hpp =================================================================== --- trunk/pingus/src/layer_manager.hpp 2008-07-03 19:40:44 UTC (rev 3643) +++ trunk/pingus/src/layer_manager.hpp 2008-07-03 20:07:57 UTC (rev 3644) @@ -18,13 +18,12 @@ #ifndef HEADER_PINGUS_LAYER_MANAGER_HPP #define HEADER_PINGUS_LAYER_MANAGER_HPP +#include "math.hpp" #include "pingus.hpp" -#include <cmath> #include "sprite.hpp" #include "display/display.hpp" #include "display/drawing_context.hpp" - class LayerManager { private: @@ -64,8 +63,8 @@ void update (float delta) { - x_pos = fmod((x_pos + x_update * delta),(float)Display::get_width()); - y_pos = fmod((y_pos + y_update * delta),(float)Display::get_height()); + x_pos = Math::mod((x_pos + x_update * delta),(float)Display::get_width()); + y_pos = Math::mod((y_pos + y_update * delta),(float)Display::get_height()); } }; Modified: trunk/pingus/src/math/rect.cpp =================================================================== --- trunk/pingus/src/math/rect.cpp 2008-07-03 19:40:44 UTC (rev 3643) +++ trunk/pingus/src/math/rect.cpp 2008-07-03 20:07:57 UTC (rev 3644) @@ -27,8 +27,6 @@ ** (if your name is missing here, please add it) */ - -#include <cmath> #include <iostream> #include "rect.hpp" Modified: trunk/pingus/src/math/vector2f.cpp =================================================================== --- trunk/pingus/src/math/vector2f.cpp 2008-07-03 19:40:44 UTC (rev 3643) +++ trunk/pingus/src/math/vector2f.cpp 2008-07-03 20:07:57 UTC (rev 3644) @@ -16,8 +16,8 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. #include <config.h> -#include <cmath> #include <iostream> +#include "math.hpp" #include "math/vector2f.hpp" void @@ -36,7 +36,7 @@ float Vector2f::magnitude() const { - return sqrt(x*x + y*y); + return Math::sqrt(x*x + y*y); } std::ostream& operator<<(std::ostream& s, const Vector2f& v) @@ -49,7 +49,7 @@ Vector2f::rotate(float angle) const { float len = magnitude(); - return Vector2f(len * cos(angle), len * sin(angle)); + return Vector2f(len * Math::cos(angle), len * Math::sin(angle)); } /* EOF */ Modified: trunk/pingus/src/math/vector3f.cpp =================================================================== --- trunk/pingus/src/math/vector3f.cpp 2008-07-03 19:40:44 UTC (rev 3643) +++ trunk/pingus/src/math/vector3f.cpp 2008-07-03 20:07:57 UTC (rev 3644) @@ -15,8 +15,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. -#include <math.h> #include <iostream> +#include "math.hpp" #include "vector3f.hpp" #include "vector2f.hpp" @@ -103,7 +103,7 @@ void Vector3f::normalize () { - float f = sqrt(x * x + y * y + z * z); + float f = Math::sqrt(x * x + y * y + z * z); if (f) { @@ -116,14 +116,14 @@ float Vector3f::length() const { - return sqrt(x * x + y * y + z * z); + return Math::sqrt(x * x + y * y + z * z); } Vector3f Vector3f::rotate (float angle, const Vector3f& pos) const { - const float s = sin(angle); - const float c = cos(angle); + const float s = Math::sin(angle); + const float c = Math::cos(angle); return Vector3f( x * (pos.x * pos.x * (1-c) + c) + y * (pos.x * pos.y * (1-c) - pos.z *s) @@ -146,7 +146,7 @@ float y = b.y - a.y; float z = b.z - a.z; - return fabsf(sqrt((x * x) + (y * y) + (z * z))); + return Math::abs(Math::sqrt((x * x) + (y * y) + (z * z))); } float @@ -155,7 +155,7 @@ float x = b.x - a.x; float y = b.y - a.y; - return fabsf(sqrt((x * x) + (y * y))); + return Math::abs(Math::sqrt((x * x) + (y * y))); } Vector3f Added: trunk/pingus/src/math.cpp =================================================================== --- trunk/pingus/src/math.cpp 2008-07-03 19:40:44 UTC (rev 3643) +++ trunk/pingus/src/math.cpp 2008-07-03 20:07:57 UTC (rev 3644) @@ -0,0 +1,54 @@ +// Pingus - A free Lemmings clone +// Copyright (C) 2000 Ingo Ruhnke <[EMAIL PROTECTED]> +// +// 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/>. + +#include <math.h> +#include "math.hpp" + +namespace Math { + +float abs(float v) +{ + return ::fabs(v); +} + +float sin(float a) +{ + return ::sinf(a); +} + +float cos(float a) +{ + return ::cosf(a); +} + +float sqrt(float a) +{ + return ::sqrt(a); +} + +float mod(float x, float y) +{ + return ::fmodf(x, y); +} + +float floor(float x) +{ + return ::floorf(x); +} + +} // namespace Math + +/* EOF */ Property changes on: trunk/pingus/src/math.cpp ___________________________________________________________________ Name: svn:keywords + Id Name: svn:eol-style + native Modified: trunk/pingus/src/math.hpp =================================================================== --- trunk/pingus/src/math.hpp 2008-07-03 19:40:44 UTC (rev 3643) +++ trunk/pingus/src/math.hpp 2008-07-03 20:07:57 UTC (rev 3644) @@ -1,4 +1,3 @@ - // Pingus - A free Lemmings clone // Copyright (C) 2000 Ingo Ruhnke <[EMAIL PROTECTED]> // @@ -29,8 +28,8 @@ @brief A collection of mathematical helper functions */ namespace Math { -const double pi = 3.14159265358979323846; /* pi */ -const double pi_2 = 1.57079632679489661923; /* pi/2 */ +const float pi = 3.14159265358979323846; /* pi */ +const float pi_2 = 1.57079632679489661923; /* pi/2 */ // Win32 defines these are defines already, so we have to undef them #ifdef min @@ -77,8 +76,7 @@ return rand()%2 == 0; } -inline -int round (float f) +inline int round (float f) { if (f >= 0.0f) return int(f + 0.5f); @@ -86,6 +84,13 @@ return int(f - 0.5f); } +float abs(float v); +float sin(float a); +float cos(float a); +float sqrt(float a); +float mod(float x, float y); +float floor(float x); + } // namespace Math #endif Modified: trunk/pingus/src/pingu.cpp =================================================================== --- trunk/pingus/src/pingu.cpp 2008-07-03 19:40:44 UTC (rev 3643) +++ trunk/pingus/src/pingu.cpp 2008-07-03 20:07:57 UTC (rev 3644) @@ -17,8 +17,8 @@ #include <sstream> #include <assert.h> -#include <math.h> #include <stdio.h> +#include "math.hpp" #include "globals.hpp" #include "world.hpp" #include "sound/sound.hpp" @@ -295,12 +295,12 @@ } // Returns the distance between the Pingu and a given coordinate -double +float Pingu::dist (int x, int y) { Vector3f p = get_center_pos (); - return sqrt(((p.x - x) * (p.x - x) + (p.y - y) * (p.y - y))); + return Math::sqrt(((p.x - x) * (p.x - x) + (p.y - y) * (p.y - y))); } // Let the pingu do his job (i.e. walk his way) Modified: trunk/pingus/src/pingu.hpp =================================================================== --- trunk/pingus/src/pingu.hpp 2008-07-03 19:40:44 UTC (rev 3643) +++ trunk/pingus/src/pingu.hpp 2008-07-03 20:07:57 UTC (rev 3644) @@ -194,7 +194,7 @@ bool is_inside (int x1, int y1, int x2, int y2); - double dist (int x, int y); + float dist (int x, int y); /** Return true if the pingu can be caught with the mouse and another action can be applied, false otherwise (exiter, Modified: trunk/pingus/src/pingu_action.cpp =================================================================== --- trunk/pingus/src/pingu_action.cpp 2008-07-03 19:40:44 UTC (rev 3643) +++ trunk/pingus/src/pingu_action.cpp 2008-07-03 20:07:57 UTC (rev 3644) @@ -16,7 +16,7 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. #include <assert.h> -#include <math.h> +#include "math.hpp" #include "math/vector3f.hpp" #include "col_map.hpp" #include "world.hpp" @@ -168,20 +168,20 @@ int x_inc = 0; int y_inc = 0; - if (fabs(resultant_force.x) > fabs(resultant_force.y)) + if (Math::abs(resultant_force.x) > Math::abs(resultant_force.y)) { // Initialise so that we move in whole pixels in x direction and // 'fractions' of a pixel in y direction. - denominator = static_cast<int>(fabs(resultant_force.x)); + denominator = static_cast<int>(Math::abs(resultant_force.x)); x_inc = denominator; - y_inc = static_cast<int>(fabs(resultant_force.y)); + y_inc = static_cast<int>(Math::abs(resultant_force.y)); } else { // Initialise so that we move in whole pixels in y direction and // 'fractions' of a pixel in x direction. - denominator = static_cast<int>(fabs(resultant_force.y)); - x_inc = static_cast<int>(fabs(resultant_force.x)); + denominator = static_cast<int>(Math::abs(resultant_force.y)); + x_inc = static_cast<int>(Math::abs(resultant_force.x)); y_inc = denominator; } Modified: trunk/pingus/src/world.cpp =================================================================== --- trunk/pingus/src/world.cpp 2008-07-03 19:40:44 UTC (rev 3643) +++ trunk/pingus/src/world.cpp 2008-07-03 20:07:57 UTC (rev 3644) @@ -248,7 +248,7 @@ World::get_pingu (const Vector3f& pos) { Pingu* current_pingu = 0; - double distance = -1.0; + float distance = -1.0; for (PinguIter i = pingus->begin (); i != pingus->end (); ++i) { if ((*i)->is_over(int(pos.x), int(pos.y))) Modified: trunk/pingus/src/worldmap/level_dot.cpp =================================================================== --- trunk/pingus/src/worldmap/level_dot.cpp 2008-07-03 19:40:44 UTC (rev 3643) +++ trunk/pingus/src/worldmap/level_dot.cpp 2008-07-03 20:07:57 UTC (rev 3644) @@ -16,7 +16,6 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. #include <iostream> -#include <math.h> #include "../font.hpp" #include "../gettext.h" #include "../globals.hpp" @@ -61,7 +60,7 @@ bool highlight = false; - if (sqrt(x*x + y*y) < 30.0f) + if (Math::sqrt(x*x + y*y) < 30.0f) highlight = true; Savegame* savegame = SavegameManager::instance()->get(plf.get_resname()); Modified: trunk/pingus/src/worldmap/path_graph.cpp =================================================================== --- trunk/pingus/src/worldmap/path_graph.cpp 2008-07-03 19:40:44 UTC (rev 3643) +++ trunk/pingus/src/worldmap/path_graph.cpp 2008-07-03 20:07:57 UTC (rev 3644) @@ -16,7 +16,7 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. #include <iostream> -#include <math.h> +#include "../math.hpp" #include "../file_reader.hpp" #include "../pingus_error.hpp" #include "dot.hpp" @@ -258,7 +258,7 @@ float x = x_pos - (*i)->get_pos().x; float y = y_pos - (*i)->get_pos().y; - if (sqrt(x*x + y*y) < 30.0f) + if (Math::sqrt(x*x + y*y) < 30.0f) return *i; } return 0; Modified: trunk/pingus/src/worldmap/pingus.hpp =================================================================== --- trunk/pingus/src/worldmap/pingus.hpp 2008-07-03 19:40:44 UTC (rev 3643) +++ trunk/pingus/src/worldmap/pingus.hpp 2008-07-03 20:07:57 UTC (rev 3644) @@ -18,7 +18,6 @@ #ifndef HEADER_PINGUS_WORLDMAP_PINGUS_HPP #define HEADER_PINGUS_WORLDMAP_PINGUS_HPP -#include <math.h> #include "../state_sprite.hpp" #include "drawable.hpp" #include "path_graph.hpp" Modified: trunk/pingus/src/worldobjs/snow_generator.cpp =================================================================== --- trunk/pingus/src/worldobjs/snow_generator.cpp 2008-07-03 19:40:44 UTC (rev 3643) +++ trunk/pingus/src/worldobjs/snow_generator.cpp 2008-07-03 20:07:57 UTC (rev 3644) @@ -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/>. -#include <math.h> #include <iostream> #include "../math.hpp" #include "../world.hpp" @@ -38,7 +37,7 @@ void SnowGenerator::update() { - for(int i = 0; i < floor(intensity); ++i) + for(int i = 0; i < Math::floor(intensity); ++i) { if (rand() % 3 != 0) world->get_snow_particle_holder()->add_particle(rand() % world->get_width(), -tile_size, false); _______________________________________________ pingus-cvs mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/pingus-cvs
