Skip to content

Commit e198ce1

Browse files
committed
inline pm_math.h
1 parent 8b54710 commit e198ce1

File tree

11 files changed

+504
-559
lines changed

11 files changed

+504
-559
lines changed

cl_dll/hud/hud_spectator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ extern "C++"
2626
#include "demo_api.h"
2727
#include "event_api.h"
2828

29-
#include "studio_util.h"
29+
#include "pm_math.h"
3030

3131
#include "screenfade.h"
3232
#include "draw_util.h"

cl_dll/rain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "parsemsg.h"
2727
#include "com_model.h"
2828

29-
#include "studio/studio_util.h"
29+
#include "pm_math.h"
3030

3131
#include <new>
3232

cl_dll/studio/StudioModelRenderer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
#include "event_api.h"
4141
#include "pm_defs.h"
42+
#include "pm_math.h"
4243

4344
#include "com_weapons.h"
4445

cl_dll/studio/studio_util.h

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
//========= Copyright © 1996-2002, Valve LLC, All rights reserved. ============
2-
//
3-
// Purpose:
4-
//
5-
// $NoKeywords: $
6-
//=============================================================================
1+
/*
2+
studio_util.h
3+
Copyright (C) 2019 Moemod Hymei
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
*/
15+
716
#pragma once
817
#if !defined( STUDIO_UTIL_H )
918
#define STUDIO_UTIL_H
@@ -17,10 +26,10 @@ auto FDotProduct(VectorTypeA a, VectorTypeB b) -> decltype(fabs((a[0])*(b[0])) +
1726
}
1827

1928
namespace cl {
20-
void AngleMatrix (const float *angles, float (*matrix)[4]);
21-
int VectorCompare (const float *v1, const float *v2);
22-
void CrossProduct (const float *v1, const float *v2, float *cross);
23-
void VectorTransform (const float *in1, float in2[3][4], float *out);
29+
//void AngleMatrix (const float *angles, float (*matrix)[4]);
30+
//int VectorCompare (const float *v1, const float *v2);
31+
//void CrossProduct (const float *v1, const float *v2, float *cross);
32+
//void VectorTransform (const float *in1, float in2[3][4], float *out);
2433
void ConcatTransforms (float in1[3][4], float in2[3][4], float out[3][4]);
2534
void MatrixCopy( float in[3][4], float out[3][4] );
2635
void QuaternionMatrix( vec4_t quaternion, float (*matrix)[4] );

cl_dll/view.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
#include "hud.h"
1313

14+
#include "pm_math.h"
15+
1416
#include "cl_util.h"
1517
#include "cvardef.h"
1618
#include "usercmd.h"
@@ -36,16 +38,6 @@
3638
#include "kbutton.h"
3739
#include "input.h"
3840

39-
#ifndef M_PI
40-
#define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h
41-
#endif
42-
43-
namespace cl { // pm_math.cpp
44-
void NormalizeAngles(vec_t angles[3]);
45-
float Distance(const vec_t v1[3], const vec_t v2[3]);
46-
void VectorAngles(const vec_t forward[3], vec_t angles[3]);
47-
};
48-
4941
namespace cl {
5042

5143
int PM_GetVisEntInfo(int ent);

common/mathlib.h

Lines changed: 33 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -13,54 +13,24 @@
1313
*
1414
****/
1515
// mathlib.h
16-
16+
#pragma once
17+
#ifndef MATHLIB_H
18+
#define MATHLIB_H
1719
#include <math.h>
1820

1921
typedef float vec_t;
20-
#ifndef vec3_t
22+
typedef vec_t vec2_t[2];
2123
typedef vec_t vec3_t[3];
22-
#endif
2324
typedef vec_t vec4_t[4]; // x,y,z,w
24-
typedef vec_t vec5_t[5];
25-
26-
typedef short vec_s_t;
27-
typedef vec_s_t vec3s_t[3];
28-
typedef vec_s_t vec4s_t[4]; // x,y,z,w
29-
typedef vec_s_t vec5s_t[5];
3025

31-
typedef int fixed4_t;
32-
typedef int fixed8_t;
33-
typedef int fixed16_t;
3426
#ifndef M_PI
3527
#define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h
3628
#endif
3729

38-
#ifdef __cplusplus
39-
# ifdef min
40-
# undef min
41-
# endif
42-
43-
# ifdef max
44-
# undef max
45-
# endif
46-
47-
# ifdef clamp
48-
# undef clamp
49-
# endif
50-
#endif
51-
5230
struct mplane_s;
5331

54-
#if defined(CLIENT_DLL)
55-
namespace cl {
56-
#elif defined(SERVER_DLL)
57-
namespace sv {
58-
#elif defined(__cplusplus)
59-
extern "C++" {
60-
#endif
61-
62-
extern vec3_t vec3_origin;
63-
extern int nanmask;
32+
extern vec3_t vec3_origin;
33+
extern int nanmask;
6434

6535
#define IS_NAN(x) (((*(int *)&x)&nanmask)==nanmask)
6636

@@ -73,64 +43,42 @@ extern "C++" {
7343
#define VectorCopy(a,b) {(b)[0]=(a)[0];(b)[1]=(a)[1];(b)[2]=(a)[2];}
7444
#define VectorClear(a) {(a)[0]=0.0;(a)[1]=0.0;(a)[2]=0.0;}
7545

76-
void VectorMA(const vec3_t veca, float scale, const vec3_t vecb, vec3_t vecc);
77-
78-
vec_t _DotProduct(vec3_t v1, vec3_t v2);
79-
void _VectorSubtract(vec3_t veca, vec3_t vecb, vec3_t out);
80-
void _VectorAdd(vec3_t veca, vec3_t vecb, vec3_t out);
81-
void _VectorCopy(vec3_t in, vec3_t out);
46+
void VectorMA (const vec3_t veca, float scale, const vec3_t vecb, vec3_t vecc);
8247

83-
int VectorCompare(const vec3_t v1, const vec3_t v2);
84-
float Length(const vec3_t v);
85-
void CrossProduct(const vec3_t v1, const vec3_t v2, vec3_t cross);
86-
float VectorNormalize(vec3_t v); // returns vector length
87-
void VectorInverse(vec3_t v);
88-
void VectorScale(const vec3_t in, vec_t scale, vec3_t out);
89-
int Q_log2(int val);
48+
vec_t _DotProduct (vec3_t v1, vec3_t v2);
49+
void _VectorSubtract (vec3_t veca, vec3_t vecb, vec3_t out);
50+
void _VectorAdd (vec3_t veca, vec3_t vecb, vec3_t out);
51+
void _VectorCopy (vec3_t in, vec3_t out);
9052

91-
void R_ConcatRotations(float in1[3][3], float in2[3][3], float out[3][3]);
92-
void R_ConcatTransforms(float in1[3][4], float in2[3][4], float out[3][4]);
53+
int VectorCompare (const vec3_t v1, const vec3_t v2);
54+
float Length (const vec3_t v);
55+
void CrossProduct (const vec3_t v1, const vec3_t v2, vec3_t cross);
56+
float VectorNormalize (vec3_t v); // returns vector length
57+
void VectorInverse (vec3_t v);
58+
void VectorScale (const vec3_t in, vec_t scale, vec3_t out);
9359

94-
// Here are some "manual" INLINE routines for doing floating point to integer conversions
95-
extern short new_cw, old_cw;
60+
void R_ConcatRotations (float in1[3][3], float in2[3][3], float out[3][3]);
61+
void R_ConcatTransforms (float in1[3][4], float in2[3][4], float out[3][4]);
9662

97-
typedef union DLONG {
98-
int i[2];
99-
double d;
100-
float f;
101-
} DLONG;
102-
103-
extern DLONG dlong;
104-
105-
106-
107-
void FloorDivMod(double numer, double denom, int *quotient,
108-
int *rem);
109-
fixed16_t Invert24To16(fixed16_t val);
110-
int GreatestCommonDivisor(int i1, int i2);
111-
112-
void AngleVectors(const float *angles, float *forward, float *right, float *up);
113-
void AngleVectorsTranspose(const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up);
63+
void AngleVectors (const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up);
64+
void AngleVectorsTranspose (const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up);
11465
#define AngleIVectors AngleVectorsTranspose
11566

116-
void AngleMatrix(const float *angles, float(*matrix)[4]);
117-
void AngleIMatrix(const vec3_t angles, float(*matrix)[4]);
118-
void VectorTransform(const vec_t *in1, float (*in2)[4], vec_t *out);
67+
void AngleMatrix (const vec3_t angles, float (*matrix)[4] );
68+
void AngleIMatrix (const vec3_t angles, float (*matrix)[4] );
69+
void VectorTransform (const vec3_t in1, float in2[3][4], vec3_t out);
11970

120-
void NormalizeAngles(vec3_t angles);
121-
void InterpolateAngles(vec3_t start, vec3_t end, vec3_t output, float frac);
122-
float AngleBetweenVectors(const vec3_t v1, const vec3_t v2);
71+
void NormalizeAngles( vec3_t angles );
72+
void InterpolateAngles( vec3_t start, vec3_t end, vec3_t output, float frac );
73+
float AngleBetweenVectors( const vec3_t v1, const vec3_t v2 );
12374

75+
void VectorMatrix( vec3_t forward, vec3_t right, vec3_t up);
76+
void VectorAngles( const vec3_t forward, vec3_t angles );
12477

125-
void VectorMatrix(vec3_t forward, vec3_t right, vec3_t up);
126-
void VectorAngles(const vec3_t forward, vec3_t angles);
127-
128-
int InvertMatrix(const float * m, float *out);
129-
130-
int BoxOnPlaneSide(vec3_t emins, vec3_t emaxs, struct mplane_s *plane);
131-
float anglemod(float a);
132-
78+
int InvertMatrix( const float * m, float *out );
13379

80+
int BoxOnPlaneSide (vec3_t emins, vec3_t emaxs, struct mplane_s *plane);
81+
float anglemod(float a);
13482

13583
#define BOX_ON_PLANE_SIDE(emins, emaxs, p) \
13684
(((p)->type < 3)? \
@@ -147,7 +95,4 @@ extern "C++" {
14795
) \
14896
: \
14997
BoxOnPlaneSide( (emins), (emaxs), (p)))
150-
151-
#ifdef __cplusplus
152-
}
153-
#endif
98+
#endif // MATHLIB_H

dlls/animation.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
#include "scriptevent.h"
88
#include "player.h"
99

10-
#define PITCH 0 // up/down
11-
#define YAW 1 // left/right
12-
#define ROLL 2 // fall over
10+
#include "pm_math.h"
1311

1412
namespace sv {
1513

@@ -19,14 +17,6 @@ namespace sv {
1917
#define ANIM_SWIM_2 9
2018
#define ANIM_FIRST_DEATH_SEQUENCE 101
2119

22-
void AngleMatrix( const float *angles, float (*matrix)[4] );
23-
static void VectorCopy( const float *in, float *out )
24-
{
25-
out[0] = in[0];
26-
out[1] = in[1];
27-
out[2] = in[2];
28-
}
29-
3020
/*
3121
* Globals initialization
3222
*/

pm_shared/pm_debug.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
#ifdef vec3_t
1717
#undef vec3_t
1818
#endif
19-
#include "mathlib.h"
2019

2120
#include "basetypes.h"
21+
#include "pm_math.h"
2222
#include "const.h"
2323
#include "usercmd.h"
2424
#include "pm_defs.h"
@@ -196,9 +196,9 @@ void PM_DrawPhysEntBBox(int num, int pcolor, float life)
196196
for (j = 0; j < 8; j++)
197197
{
198198
VectorCopy(p[j], tmp);
199-
p[j][0] = _DotProduct ( tmp, forward );
200-
p[j][1] = _DotProduct ( tmp, right );
201-
p[j][2] = _DotProduct ( tmp, up );
199+
p[j][0] = DotProduct ( tmp, forward );
200+
p[j][1] = DotProduct ( tmp, right );
201+
p[j][2] = DotProduct ( tmp, up );
202202
}
203203
}
204204

0 commit comments

Comments
 (0)