Skip to content

Commit 69438a5

Browse files
committed
Added back old get_prop_<type> methods
1 parent b02ed76 commit 69438a5

File tree

3 files changed

+118
-37
lines changed

3 files changed

+118
-37
lines changed

src/core/modules/entities/entities_wrap.cpp

Lines changed: 68 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,76 @@ SendPropMap g_SendPropMap;
6262
//-----------------------------------------------------------------------------
6363
// edict_t extension
6464
//-----------------------------------------------------------------------------
65-
object CEdictExt::GetProp( edict_t* pEdict, const char* prop_name )
65+
int CEdictExt::GetPropInt( edict_t* pEdict, const char* prop_name )
6666
{
67-
return CSendProp(pEdict, prop_name).Get();
67+
CSendProp prop = CSendProp(pEdict, prop_name);
68+
if (prop.GetType() != DPT_Int)
69+
BOOST_RAISE_EXCEPTION(PyExc_TypeError, "Property is not an int.");
70+
71+
return prop.Get<int>();
6872
}
6973

70-
void CEdictExt::SetProp( edict_t* pEdict, const char* prop_name, object value)
74+
float CEdictExt::GetPropFloat( edict_t* pEdict, const char* prop_name )
7175
{
72-
CSendProp(pEdict, prop_name).Set(value);
76+
CSendProp prop = CSendProp(pEdict, prop_name);
77+
if (prop.GetType() != DPT_Float)
78+
BOOST_RAISE_EXCEPTION(PyExc_TypeError, "Property is not a float.");
79+
80+
return prop.Get<float>();
81+
}
82+
83+
const char* CEdictExt::GetPropString( edict_t* pEdict, const char* prop_name )
84+
{
85+
CSendProp prop = CSendProp(pEdict, prop_name);
86+
if (prop.GetType() != DPT_String)
87+
BOOST_RAISE_EXCEPTION(PyExc_TypeError, "Property is not a string.");
88+
89+
return prop.Get<const char *>();
90+
}
91+
92+
Vector CEdictExt::GetPropVector( edict_t* pEdict, const char* prop_name )
93+
{
94+
CSendProp prop = CSendProp(pEdict, prop_name);
95+
if (prop.GetType() != DPT_Vector)
96+
BOOST_RAISE_EXCEPTION(PyExc_TypeError, "Property is not a vector.");
97+
98+
return prop.Get<Vector>();
99+
}
100+
101+
void CEdictExt::SetPropInt( edict_t* pEdict, const char* prop_name, int iValue )
102+
{
103+
CSendProp prop = CSendProp(pEdict, prop_name);
104+
if (prop.GetType() != DPT_Int)
105+
BOOST_RAISE_EXCEPTION(PyExc_TypeError, "Property is not an int.");
106+
107+
prop.Set<int>(iValue);
108+
}
109+
110+
void CEdictExt::SetPropFloat( edict_t* pEdict, const char* prop_name, float flValue )
111+
{
112+
CSendProp prop = CSendProp(pEdict, prop_name);
113+
if (prop.GetType() != DPT_Float)
114+
BOOST_RAISE_EXCEPTION(PyExc_TypeError, "Property is not a float.");
115+
116+
prop.Set<float>(flValue);
117+
}
118+
119+
void CEdictExt::SetPropString( edict_t* pEdict, const char* prop_name, const char* szValue )
120+
{
121+
CSendProp prop = CSendProp(pEdict, prop_name);
122+
if (prop.GetType() != DPT_String)
123+
BOOST_RAISE_EXCEPTION(PyExc_TypeError, "Property is not a string.");
124+
125+
prop.Set<const char *>(szValue);
126+
}
127+
128+
void CEdictExt::SetPropVector( edict_t* pEdict, const char* prop_name, Vector vecValue )
129+
{
130+
CSendProp prop = CSendProp(pEdict, prop_name);
131+
if (prop.GetType() != DPT_Vector)
132+
BOOST_RAISE_EXCEPTION(PyExc_TypeError, "Property is not a vector.");
133+
134+
prop.Set<Vector>(vecValue);
73135
}
74136

75137

@@ -186,27 +248,7 @@ CSendProp::CSendProp( edict_t* edict, const char* prop_name )
186248
}
187249
}
188250

189-
void CSendProp::Set( object value )
190-
{
191-
switch(m_send_prop->GetType())
192-
{
193-
case DPT_Int: Set<int>(extract<int>(value)); break;
194-
case DPT_Float: Set<float>(extract<float>(value)); break;
195-
case DPT_String: Set<const char *>(extract<const char *>(value)); break;
196-
case DPT_Vector: Set<Vector>(extract<Vector>(value)); break;
197-
}
198-
BOOST_RAISE_EXCEPTION(PyExc_TypeError, "Unknown property type.");
199-
}
200-
201-
object CSendProp::Get()
251+
inline SendPropType CSendProp::GetType()
202252
{
203-
switch(m_send_prop->GetType())
204-
{
205-
case DPT_Int: return object(Get<int>());
206-
case DPT_Float: return object(Get<float>());
207-
case DPT_String: return object(Get<const char *>());
208-
case DPT_Vector: return object(Get<Vector>());
209-
}
210-
BOOST_RAISE_EXCEPTION(PyExc_TypeError, "Unknown property type.");
211-
return object(); // Just to disable a warning...
253+
return m_send_prop->GetType();
212254
}

src/core/modules/entities/entities_wrap.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,15 @@
4141
class CEdictExt
4242
{
4343
public:
44-
static object GetProp( edict_t* pEdict, const char* prop_name );
45-
static void SetProp( edict_t* pEdict, const char* prop_name, object value);
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 );
48+
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 );
4653
};
4754

4855
//---------------------------------------------------------------------------------
@@ -59,8 +66,6 @@ class CSendProp
5966
T Get()
6067
{ return *(T *) ((char *) m_base_entity + m_prop_offset); }
6168

62-
object Get();
63-
6469
template<class T>
6570
void Set(T value)
6671
{
@@ -83,8 +88,6 @@ class CSendProp
8388
m_edict->StateChanged();
8489
}
8590

86-
void Set(object value);
87-
8891
private:
8992
// Offset from the beginning of the network table that
9093
// this prop is located at.

src/core/modules/entities/entities_wrap_python.cpp

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,14 +369,50 @@ void export_edict()
369369
reference_existing_object_policy()
370370
)
371371

372-
.def("get_prop",
373-
&CEdictExt::GetProp,
374-
"Returns the value of a network property.",
372+
.def("get_prop_int",
373+
&CEdictExt::GetPropInt,
374+
"Returns the value of a network property as an int.",
375375
args("prop_name")
376376
)
377377

378-
.def("set_prop",
379-
&CEdictExt::SetProp,
378+
.def("get_prop_float",
379+
&CEdictExt::GetPropFloat,
380+
"Returns the value of a network property as a float.",
381+
args("prop_name")
382+
)
383+
384+
.def("get_prop_string",
385+
&CEdictExt::GetPropString,
386+
"Returns the value of a network property as a string.",
387+
args("prop_name")
388+
)
389+
390+
.def("get_prop_vector",
391+
&CEdictExt::GetPropFloat,
392+
"Returns the value of a network property as a vector.",
393+
args("prop_name")
394+
)
395+
396+
.def("set_prop_int",
397+
&CEdictExt::SetPropInt,
398+
"Set the a network property to the given value.",
399+
args("prop_name", "value")
400+
)
401+
402+
.def("set_prop_float",
403+
&CEdictExt::SetPropFloat,
404+
"Set the a network property to the given value.",
405+
args("prop_name", "value")
406+
)
407+
408+
.def("set_prop_string",
409+
&CEdictExt::SetPropString,
410+
"Set the a network property to the given value.",
411+
args("prop_name", "value")
412+
)
413+
414+
.def("set_prop_vector",
415+
&CEdictExt::SetPropVector,
380416
"Set the a network property to the given value.",
381417
args("prop_name", "value")
382418
)

0 commit comments

Comments
 (0)