2 Copyright (C) 2004 Parallel Realities
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 void Math::limitChar(signed char *in
, int low
, int high
)
31 void Math::limitChar(unsigned char *in
, int low
, int high
)
39 void Math::limitInt(int *in
, int low
, int high
)
47 void Math::limitFloat(float *in
, float low
, float high
)
55 void Math::wrapChar(signed char *in
, signed char low
, signed char high
)
63 void Math::wrapInt(int *in
, int low
, int high
)
71 void Math::wrapFloat(float *in
, float low
, float high
)
81 pSeed
= pSeed
* 7654321 + 12345;
82 pSeed
= (unsigned int)(pSeed
/ 65536) % 32768;
87 int Math::rrand(int min
, int max
)
98 return r
+= prand() % (max
- min
);
101 void Math::addBit(long *currentBits
, long newBits
)
103 if (!(*currentBits
& newBits
))
104 *currentBits
+= newBits
;
107 void Math::removeBit(long *currentBits
, long oldBits
)
109 if (*currentBits
& oldBits
)
110 *currentBits
-= oldBits
;
113 void Math::calculateSlope(float x
, float y
, float x2
, float y2
, float *dx
, float *dy
)
115 int steps
= (int)max(fabs(x
- x2
), fabs(y
- y2
));
129 char *Math::formatTime(int t
)
131 static char time
[1024];
135 int hours
= t
/ 3600;
136 int minutes
= (t
% 3600) / 60;
137 int seconds
= (t
% 60);
139 sprintf(time
, "%dh %dm %ds", hours
, minutes
, seconds
);
144 unsigned int Math::pSeed
;