Skip to content

Commit bfe25f1

Browse files
committed
Reworked vecmath_c module
- Renamed vecmath_c to mathlib_c - Fixed get_pop_<type> and set_prop_<type> methods
1 parent ab90b9d commit bfe25f1

File tree

8 files changed

+242
-627
lines changed

8 files changed

+242
-627
lines changed

src/CMakeLists.txt

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -262,15 +262,13 @@ Set(SOURCEPYTHON_MEMORY_MODULE_SOURCES
262262
)
263263

264264
# ------------------------------------------------------------------
265-
# Vecmath module
265+
# Mathlib module
266266
# ------------------------------------------------------------------
267-
Set(SOURCEPYTHON_VECMATH_MODULE_HEADERS
268-
core/modules/vecmath/vecmath_wrap.h
267+
Set(SOURCEPYTHON_MATHLIB_MODULE_HEADERS
269268
)
270269

271-
Set(SOURCEPYTHON_VECMATH_MODULE_SOURCES
272-
core/modules/vecmath/vecmath_wrap.cpp
273-
core/modules/vecmath/vecmath_wrap_python.cpp
270+
Set(SOURCEPYTHON_MATHLIB_MODULE_SOURCES
271+
core/modules/mathlib/mathlib_wrap_python.cpp
274272
)
275273

276274
# ------------------------------------------------------------------
@@ -317,8 +315,8 @@ Set(SOURCEPYTHON_MODULE_FILES
317315
${SOURCEPYTHON_MEMORY_MODULE_HEADERS}
318316
${SOURCEPYTHON_MEMORY_MODULE_SOURCES}
319317

320-
${SOURCEPYTHON_VECMATH_MODULE_HEADERS}
321-
${SOURCEPYTHON_VECMATH_MODULE_SOURCES}
318+
${SOURCEPYTHON_MATHLIB_MODULE_HEADERS}
319+
${SOURCEPYTHON_MATHLIB_MODULE_SOURCES}
322320

323321
${SOURCEPYTHON_EFFECTS_MODULE_HEADERS}
324322
${SOURCEPYTHON_EFFECTS_MODULE_SOURCES}
@@ -343,7 +341,7 @@ Source_Group("Header Files\\Module\\Players" FILES ${SOURCEPYTHON
343341
Source_Group("Header Files\\Module\\Listeners" FILES ${SOURCEPYTHON_LISTENERS_MODULE_HEADERS})
344342
Source_Group("Header Files\\Module\\Globals" FILES ${SOURCEPYTHON_GLOBALS_MODULE_HEADERS})
345343
Source_Group("Header Files\\Module\\Memory" FILES ${SOURCEPYTHON_MEMORY_MODULE_HEADERS})
346-
Source_Group("Header Files\\Module\\Vecmath" FILES ${SOURCEPYTHON_VECMATH_MODULE_HEADERS})
344+
Source_Group("Header Files\\Module\\Mathlib" FILES ${SOURCEPYTHON_MATHLIB_MODULE_HEADERS})
347345
Source_Group("Header Files\\Module\\Effects" FILES ${SOURCEPYTHON_EFFECTS_MODULE_HEADERS})
348346

349347
Source_Group("Source Files\\Addons" FILES ${SOURCEPYTHON_ADDON_SOURCES})
@@ -362,7 +360,7 @@ Source_Group("Source Files\\Module\\Players" FILES ${SOURCEPYTHON
362360
Source_Group("Source Files\\Module\\Listeners" FILES ${SOURCEPYTHON_LISTENERS_MODULE_SOURCES})
363361
Source_Group("Source Files\\Module\\Globals" FILES ${SOURCEPYTHON_GLOBALS_MODULE_SOURCES})
364362
Source_Group("Source Files\\Module\\Memory" FILES ${SOURCEPYTHON_MEMORY_MODULE_SOURCES})
365-
Source_Group("Source Files\\Module\\Vecmath" FILES ${SOURCEPYTHON_VECMATH_MODULE_SOURCES})
363+
Source_Group("Source Files\\Module\\Mathlib" FILES ${SOURCEPYTHON_MATHLIB_MODULE_SOURCES})
366364
Source_Group("Source Files\\Module\\Effects" FILES ${SOURCEPYTHON_EFFECTS_MODULE_SOURCES})
367365

368366
# ------------------------------------------------------------------

src/core/modules/effects/effects_wrap_python.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include <stddef.h>
3333
#include "wchartypes.h"
3434
#include "string_t.h"
35-
#include "../vecmath/vecmath_wrap.h"
3635
#include "shake.h"
3736
#include "IEffects.h"
3837
#include "utility/wrap_macros.h"

src/core/modules/entities/entities_wrap.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include "edict.h"
3333
#include "server_class.h"
3434
#include <cstdint>
35-
#include "modules/vecmath/vecmath_wrap.h"
3635

3736

3837
//---------------------------------------------------------------------------------
@@ -41,15 +40,15 @@
4140
class CEdictExt
4241
{
4342
public:
44-
int GetPropInt( edict_t* pEdict, const char* prop_name );
45-
float GetPropFloat( edict_t* pEdict, const char* prop_name );
46-
const char* GetPropString( edict_t* pEdict, const char* prop_name );
47-
Vector GetPropVector( edict_t* pEdict, const char* prop_name );
43+
static int GetPropInt( edict_t* pEdict, const char* prop_name );
44+
static float GetPropFloat( edict_t* pEdict, const char* prop_name );
45+
static const char* GetPropString( edict_t* pEdict, const char* prop_name );
46+
static Vector GetPropVector( edict_t* pEdict, const char* prop_name );
4847

49-
void SetPropInt( edict_t* pEdict, const char* prop_name, int iValue );
50-
void SetPropFloat( edict_t* pEdict, const char* prop_name, float flValue );
51-
void SetPropString( edict_t* pEdict, const char* prop_name, const char* szValue );
52-
void SetPropVector( edict_t* pEdict, const char* prop_name, Vector vecValue );
48+
static void SetPropInt( edict_t* pEdict, const char* prop_name, int iValue );
49+
static void SetPropFloat( edict_t* pEdict, const char* prop_name, float flValue );
50+
static void SetPropString( edict_t* pEdict, const char* prop_name, const char* szValue );
51+
static void SetPropVector( edict_t* pEdict, const char* prop_name, Vector vecValue );
5352
};
5453

5554
//---------------------------------------------------------------------------------

src/core/modules/entities/entities_wrap_python.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ void export_edict()
388388
)
389389

390390
.def("get_prop_vector",
391-
&CEdictExt::GetPropFloat,
391+
&CEdictExt::GetPropVector,
392392
"Returns the value of a network property as a vector.",
393393
args("prop_name")
394394
)
Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
/**
2+
* =============================================================================
3+
* Source Python
4+
* Copyright (C) 2012 Source Python Development Team. All rights reserved.
5+
* =============================================================================
6+
*
7+
* This program is free software; you can redistribute it and/or modify it under
8+
* the terms of the GNU General Public License, version 3.0, as published by the
9+
* Free Software Foundation.
10+
*
11+
* This program is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13+
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14+
* details.
15+
*
16+
* You should have received a copy of the GNU General Public License along with
17+
* this program. If not, see <http://www.gnu.org/licenses/>.
18+
*
19+
* As a special exception, the Source Python Team gives you permission
20+
* to link the code of this program (as well as its derivative works) to
21+
* "Half-Life 2," the "Source Engine," and any Game MODs that run on software
22+
* by the Valve Corporation. You must obey the GNU General Public License in
23+
* all respects for all other code used. Additionally, the Source.Python
24+
* Development Team grants this exception to all derivative works.
25+
*/
26+
27+
//-----------------------------------------------------------------------------
28+
// Includes
29+
//-----------------------------------------------------------------------------
30+
#include "modules/export_main.h"
31+
#include "mathlib/vector.h"
32+
33+
34+
//-----------------------------------------------------------------------------
35+
// Exposes the mathlib_c module.
36+
//-----------------------------------------------------------------------------
37+
void export_vector();
38+
39+
DECLARE_SP_MODULE(mathlib_c)
40+
{
41+
export_vector();
42+
}
43+
44+
//-----------------------------------------------------------------------------
45+
// Exposes Vector
46+
//-----------------------------------------------------------------------------
47+
class VectorExt
48+
{
49+
public:
50+
static void SetItem(Vector* pVec, int iIndex, float fValue)
51+
{
52+
pVec[iIndex] = fValue;
53+
}
54+
};
55+
56+
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(is_zero_overload, IsZero, 0, 1)
57+
58+
void export_vector()
59+
{
60+
// TODO: Rename
61+
class_<Vector>("CVector")
62+
.def(init<float, float, float>())
63+
.def(init<float>())
64+
65+
// Members
66+
.def_readwrite("x",
67+
&Vector::x
68+
)
69+
70+
.def_readwrite("y",
71+
&Vector::y
72+
)
73+
74+
.def_readwrite("z",
75+
&Vector::z
76+
)
77+
78+
// Methods
79+
.def("init",
80+
&Vector::Init
81+
)
82+
83+
.def("is_valid",
84+
&Vector::IsValid,
85+
"Returns True if the vector is valid."
86+
)
87+
88+
.def("invalidated",
89+
&Vector::Invalidate,
90+
"Invalidates the vector."
91+
)
92+
93+
.def("__getitem__",
94+
static_cast< float(Vector::*)( int ) const >(&Vector::operator[])
95+
)
96+
97+
.def("__setitem__",
98+
&VectorExt::SetItem
99+
)
100+
101+
.def("as_vector_2D",
102+
GET_METHOD(Vector2D&, Vector, AsVector2D),
103+
reference_existing_object_policy()
104+
)
105+
106+
.def("random",
107+
&Vector::Random,
108+
args("min", "max"),
109+
"Fills the vector with random values within the given range."
110+
)
111+
112+
.def("zero",
113+
&Vector::Zero,
114+
"Zeros out the vector."
115+
)
116+
117+
.def(self == self)
118+
.def(self != self)
119+
.def(self += self)
120+
.def(self -= self)
121+
.def(self *= self)
122+
.def(self *= float())
123+
.def(self /= self)
124+
.def(self /= float())
125+
.def(self += float())
126+
.def(self -= float())
127+
128+
.def("negate",
129+
&Vector::Negate,
130+
"Negates the vector."
131+
)
132+
133+
.def("get_length",
134+
&Vector::Length,
135+
"Returns the vector's 3D length."
136+
)
137+
138+
.def("get_length_sqr",
139+
&Vector::LengthSqr,
140+
"Returns the vector's 3D length as a square product."
141+
)
142+
143+
.def("is_zero",
144+
&Vector::IsZero,
145+
is_zero_overload(
146+
args("tolerance"),
147+
"Returns True if x, y and z are zero or within the tolerance."
148+
)
149+
)
150+
151+
.def("normalize",
152+
&Vector::NormalizeInPlace,
153+
"Normalizes the vector."
154+
)
155+
156+
.def("is_length_greater_than",
157+
&Vector::IsLengthGreaterThan
158+
)
159+
160+
.def("is_length_less_than",
161+
&Vector::IsLengthLessThan
162+
)
163+
164+
.def("is_within_box",
165+
&Vector::WithinAABox,
166+
args("mins", "maxs"),
167+
"Returns True if the vector is within the given box coordinates."
168+
)
169+
170+
.def("get_distance",
171+
&Vector::DistTo,
172+
args("other"),
173+
"Returns the distance to the other vector."
174+
)
175+
176+
.def("get_distance_sqr",
177+
&Vector::DistToSqr,
178+
args("other"),
179+
"Returns the distance to the other vector as a square product."
180+
)
181+
182+
.def("mul_add",
183+
&Vector::MulAdd,
184+
args("a", "b", "scalar"),
185+
"Multiply and add. this = a + b * scalar."
186+
)
187+
188+
.def("dot",
189+
&Vector::Dot,
190+
"Returns the dot product."
191+
)
192+
193+
.def("get_length_2D",
194+
&Vector::Length2D,
195+
"Returns the vector's 2D length."
196+
)
197+
198+
.def("get_length_2D_sqr",
199+
&Vector::Length2DSqr,
200+
"Returns the vector's 2D length as a square product."
201+
)
202+
203+
.def(self + self)
204+
.def(self - self)
205+
.def(self * self)
206+
.def(self / self)
207+
.def(self * float())
208+
.def(self / float())
209+
210+
.def("cross",
211+
&Vector::Cross,
212+
"Returns the cross product between two vectors."
213+
)
214+
215+
.def("min",
216+
&Vector::Min,
217+
"Returns a new vector containing the lowest values of both vectors."
218+
)
219+
220+
.def("max",
221+
&Vector::Max,
222+
"Returns a new vector containing the biggest values of both vectors."
223+
)
224+
;
225+
}

0 commit comments

Comments
 (0)