ScummVM API documentation
imath.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef M4_CORE_IMATH_H
23#define M4_CORE_IMATH_H
24
25#include "common/endian.h"
26#include "m4/m4_types.h"
27
28namespace M4 {
29
30#define FRAC16(a,b) ((a<<16) + (b))
31
32#define Atan2F16(x1, x2) ArcTan(x1, x2)
33#define MulSF16(x1, x2) FixedMul(x1, x2)
34#define DivSF16(x1, x2) FixedDiv(x1, x2)
35#define RecipUF16(x) FixedDiv(1, x)
36#define SquareSF16(x) FixedMul(x, x)
37
38#define SWAP_INT16(x) ((((x)>>8)&0x00ff) + (((x)&0x00ff)<<8))
39#define SWAP_INT32(x) ((((int32)(x)&0x000000ff)<<24) + (((int32)(x)&0x0000ff00)<<8) + \
40 (((int32)(x)&0x00ff0000)>>8) + (((int32)(x)>>24)&0x000000ff))
41
42
43frac16 FixedMul(frac16 Multiplicand, frac16 Multiplier);
44frac16 FixedDiv(frac16 Dividend, frac16 Divisor);
45
46int32 imath_max(int32 a, int32 b);
47int32 imath_min(int32 a, int32 b);
48int32 imath_abs(int32 a);
49
50void imath_seed(int32 seedNum);
51
52int32 imath_ranged_rand(int32 a, int32 b);
53frac16 imath_ranged_rand16(frac16 a, frac16 b);
54bool imath_rand_bool(int max);
55
56frac16 SqrtF16(frac16 n);
57frac16 ArcTan(frac16 x, frac16 y);
58
59uint32 convert_intel32(uint32 a);
60uint16 convert_intel16(uint16 a);
61
62//
63// I N L I N E S
64//
65
66inline short abs(short a) {
67 return (a >= 0) ? a : -a;
68}
69
70inline long abs(long a) {
71 return (a >= 0) ? a : -a;
72}
73
74} // namespace M4
75
76#endif
Definition: database.h:28
intptr frac16
Definition: m4_types.h:45