@@ -59,6 +59,20 @@ typedef boost::unordered_map<std::string, CSendPropHashTable*> SendPropMap;
5959SendPropMap g_SendPropMap;
6060
6161
62+ // -----------------------------------------------------------------------------
63+ // edict_t extension
64+ // -----------------------------------------------------------------------------
65+ object CEdictExt::GetProp ( edict_t * pEdict, const char * prop_name )
66+ {
67+ return CSendProp (pEdict, prop_name).Get ();
68+ }
69+
70+ void CEdictExt::SetProp ( edict_t * pEdict, const char * prop_name, object value)
71+ {
72+ CSendProp (pEdict, prop_name).Set (value);
73+ }
74+
75+
6276// -----------------------------------------------------------------------------
6377// CSendProp code.
6478// -----------------------------------------------------------------------------
@@ -172,120 +186,27 @@ CSendProp::CSendProp( edict_t* edict, const char* prop_name )
172186 }
173187}
174188
175- void CSendProp::set_int ( int iValue )
176- {
177- // Is the property of "integer" type?
178- if ( m_send_prop->GetType () == DPT_Int )
179- {
180- // Set the value.
181- *(int *)((char *)m_base_entity + m_prop_offset) = iValue;
182-
183- // Force a network update.
184- m_edict->StateChanged ();
185- }
186- else
187- {
188- BOOST_RAISE_EXCEPTION (PyExc_TypeError, " Property is not an integer." );
189- }
190- }
191-
192- void CSendProp::set_float ( float flValue )
189+ void CSendProp::Set ( object value )
193190{
194- // Is the property of "float" type?
195- if ( m_send_prop->GetType () == DPT_Float )
196- {
197- // Set the value.
198- *(float *)((char *)m_base_entity + m_prop_offset) = flValue;
199-
200- // Force a network update.
201- m_edict->StateChanged ();
202- }
203- else
191+ switch (m_send_prop->GetType ())
204192 {
205- BOOST_RAISE_EXCEPTION (PyExc_TypeError, " Property is not a float." );
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 ;
206197 }
198+ BOOST_RAISE_EXCEPTION (PyExc_TypeError, " Unknown property type." );
207199}
208200
209- void CSendProp::set_string ( const char * szValue )
201+ object CSendProp::Get ( )
210202{
211- // Is the property of "string" type?
212- if ( m_send_prop->GetType () == DPT_String )
203+ switch (m_send_prop->GetType ())
213204 {
214- // Get the address of the string buffer.
215- char * data_buffer = (char *)((char *)m_base_entity + m_prop_offset);
216-
217- // Write the string to the buffer.
218- V_strncpy (data_buffer, szValue, DT_MAX_STRING_BUFFERSIZE);
219-
220- // Force a network update.
221- m_edict->StateChanged ();
222- }
223- else
224- {
225- BOOST_RAISE_EXCEPTION (PyExc_TypeError, " Property is not a string." );
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>());
226209 }
227- }
228-
229- void CSendProp::set_vector ( CVector* vecValue )
230- {
231- // Is the property of "vector" type?
232- if ( m_send_prop->GetType () == DPT_Vector )
233- {
234- *(Vector *)((char *)m_base_entity + m_prop_offset) = *(Vector *) vecValue;
235-
236- // Force a network update.
237- m_edict->StateChanged ();
238- }
239- else
240- {
241- BOOST_RAISE_EXCEPTION (PyExc_TypeError, " Property is not a vector." );
242- }
243- }
244-
245- int CSendProp::get_int ()
246- {
247- // Is the property of "integer" type?
248- if ( m_send_prop->GetType () == DPT_Int )
249- {
250- return *(int *)((char *)m_base_entity + m_prop_offset);
251- }
252-
253- BOOST_RAISE_EXCEPTION (PyExc_TypeError, " Property is not an integer." );
254- return NULL ;
255- }
256-
257- float CSendProp::get_float ()
258- {
259- // Is the property of "float" type?
260- if ( m_send_prop->GetType () == DPT_Float )
261- {
262- return *(float *)((char *)m_base_entity + m_prop_offset);
263- }
264-
265- BOOST_RAISE_EXCEPTION (PyExc_TypeError, " Property is not a float." );
266- return NULL ;
267- }
268-
269- const char * CSendProp::get_string ()
270- {
271- // Is the property of "string" type?
272- if ( m_send_prop->GetType () == DPT_String )
273- {
274- return (const char *)((char *)m_base_entity + m_prop_offset);
275- }
276-
277- BOOST_RAISE_EXCEPTION (PyExc_TypeError, " Property is not a string." );
278- return NULL ;
279- }
280-
281- CVector* CSendProp::get_vector ()
282- {
283- // Is the property of "vector" type?
284- if ( m_send_prop->GetType () == DPT_Vector )
285- {
286- return new CVector (*(Vector *) ((char *)m_base_entity + m_prop_offset));
287- }
288-
289- BOOST_RAISE_EXCEPTION (PyExc_TypeError, " Property is not a vector." );
290- return NULL ;
210+ BOOST_RAISE_EXCEPTION (PyExc_TypeError, " Unknown property type." );
211+ return object (); // Just to disable a warning...
291212}
0 commit comments