annotate Engine/OurMath.h @ 2567:d569340b05ff

Few constants changed into enum values
author a.parshin
date Thu, 21 May 2015 01:50:59 +0200
parents 1bcadc6dd203
children
rev   line source
2499
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
1 #pragma once
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
2
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
3 #include <cassert>
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
4 #include <limits>
2534
1bcadc6dd203 enum SOUND_
Ritor1
parents: 2499
diff changeset
5 #define pi_double 3.14159265358979323846
2499
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
6 /* 186 */
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
7 #pragma pack(push, 1)
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
8 struct stru193_math
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
9 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
10 stru193_math();
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
11 int Cos(int angle);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
12 unsigned int Atan2(int x, int y);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
13 int Sin(int angle);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
14
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
15 int pTanTable[520];
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
16 int pCosTable[520];
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
17 int pInvCosTable[520];
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
18 static const unsigned int uIntegerPi = 1024;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
19 static const unsigned int uIntegerHalfPi = 512;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
20 static const unsigned int uIntegerDoublePi = 2048;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
21 static const unsigned int uDoublePiMask = 2047;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
22 static const unsigned int uPiMask = 1023;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
23 static const unsigned int uHalfPiMask = 511;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
24 };
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
25 #pragma pack(pop)
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
26
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
27 __int64 fixpoint_mul(int, int);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
28 __int64 fixpoint_dot(int x1, int x2, int y1, int y2, int z1, int z2);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
29 __int64 fixpoint_div(int, int);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
30 __int64 fixpoint_sub_unknown(int, int);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
31 int fixpoint_from_float(float value);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
32 int fixpoint_from_int(int lhv, int rhv);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
33 int integer_sqrt(int val);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
34 int __fastcall GetDiceResult(unsigned int uNumDice, unsigned int uDiceSides); // idb
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
35 inline int round_to_int(float x) { return (int)floor(x + 0.5f); }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
36
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
37 template <typename FloatType>
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
38 inline int bankersRounding(const FloatType& value)
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
39 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
40 assert("Method unsupported for this type" && false);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
41 return value;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
42 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
43
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
44 template<> inline int bankersRounding<float>(const float& inValue)
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
45 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
46 union Cast
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
47 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
48 double d;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
49 long l;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
50 };
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
51 volatile Cast c;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
52 c.d = inValue + 6755399441055744.0;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
53 return c.l;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
54 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
55
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
56 #pragma push_macro("max")
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
57 #undef max
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
58 template<> inline int bankersRounding<double>(const double& inValue)
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
59 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
60 double maxValue = std::numeric_limits<int>::max();
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
61 assert(maxValue - 6755399441055744.0 >= inValue);
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
62 union Cast
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
63 {
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
64 double d;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
65 long l;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
66 };
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
67 volatile Cast c;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
68 c.d = inValue + 6755399441055744.0;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
69 return c.l;
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
70 }
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
71 #pragma pop_macro("max")
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
72
68cdef6879a0 engine folder
Ritor1
parents:
diff changeset
73 extern struct stru193_math *stru_5C6E00;