@@ -43,7 +43,7 @@ extern IServerGameDLL* servergamedll;
43
43
44
44
45
45
// ----------------------------------------------------------------------------
46
- // CEntityGenerator Constructor.
46
+ // CEntityGenerator
47
47
// ----------------------------------------------------------------------------
48
48
CEntityGenerator::CEntityGenerator ( PyObject* self ):
49
49
IPythonGenerator<edict_t>(self),
@@ -54,9 +54,6 @@ CEntityGenerator::CEntityGenerator( PyObject* self ):
54
54
{
55
55
}
56
56
57
- // ----------------------------------------------------------------------------
58
- // CEntityGenerator Copy-Constructor.
59
- // ----------------------------------------------------------------------------
60
57
CEntityGenerator::CEntityGenerator ( PyObject* self, const CEntityGenerator& rhs ):
61
58
IPythonGenerator<edict_t>(self),
62
59
m_pCurrentEntity(rhs.m_pCurrentEntity),
@@ -66,9 +63,6 @@ CEntityGenerator::CEntityGenerator( PyObject* self, const CEntityGenerator& rhs
66
63
makeStringCopy (rhs.m_szClassName , m_uiClassNameLen);
67
64
}
68
65
69
- // ----------------------------------------------------------------------------
70
- // CEntityGenerator Constructor (takes a filter string).
71
- // ----------------------------------------------------------------------------
72
66
CEntityGenerator::CEntityGenerator (PyObject* self, const char * szClassName):
73
67
IPythonGenerator<edict_t>(self),
74
68
m_pCurrentEntity((CBaseEntity *)servertools->FirstEntity()),
@@ -78,9 +72,6 @@ CEntityGenerator::CEntityGenerator(PyObject* self, const char* szClassName):
78
72
makeStringCopy (szClassName, m_uiClassNameLen);
79
73
}
80
74
81
- // ----------------------------------------------------------------------------
82
- // CEntityGenerator Constructor (takes a filter string and a boolean flag).
83
- // ----------------------------------------------------------------------------
84
75
CEntityGenerator::CEntityGenerator (PyObject* self, const char * szClassName, bool bExactMatch):
85
76
IPythonGenerator<edict_t>(self),
86
77
m_pCurrentEntity((CBaseEntity *)servertools->FirstEntity()),
@@ -90,17 +81,11 @@ CEntityGenerator::CEntityGenerator(PyObject* self, const char* szClassName, bool
90
81
makeStringCopy (szClassName, m_uiClassNameLen);
91
82
}
92
83
93
- // ----------------------------------------------------------------------------
94
- // CEntityGenerator Destructor.
95
- // ----------------------------------------------------------------------------
96
84
CEntityGenerator::~CEntityGenerator ()
97
85
{
98
86
delete[] m_szClassName;
99
87
}
100
88
101
- // ----------------------------------------------------------------------------
102
- // Returns the next valid edict_t instance.
103
- // ----------------------------------------------------------------------------
104
89
edict_t * CEntityGenerator::getNext ()
105
90
{
106
91
while (m_pCurrentEntity)
@@ -126,9 +111,6 @@ edict_t* CEntityGenerator::getNext()
126
111
return NULL ;
127
112
}
128
113
129
- // ---------------------------------------------------------------------------------
130
- // Private function, creates a copy of the class name string.
131
- // ---------------------------------------------------------------------------------
132
114
void CEntityGenerator::makeStringCopy (const char * szClassName, unsigned int uiClassNameLen)
133
115
{
134
116
if (uiClassNameLen > 0 )
@@ -146,55 +128,101 @@ void CEntityGenerator::makeStringCopy(const char* szClassName, unsigned int uiCl
146
128
147
129
148
130
// ----------------------------------------------------------------------------
149
- // CBaseEntityGenerator Constructor.
131
+ // CBaseEntityGenerator
150
132
// ----------------------------------------------------------------------------
151
133
CBaseEntityGenerator::CBaseEntityGenerator ( PyObject* self ):
152
- IPythonGenerator<CBaseEntityWrapper>(self)
134
+ IPythonGenerator<CBaseEntityWrapper>(self),
135
+ m_pCurrentEntity((CBaseEntity *)servertools->FirstEntity()),
136
+ m_szClassName(NULL ),
137
+ m_uiClassNameLen(0 ),
138
+ m_bExactMatch(false )
153
139
{
154
- m_pCurrentEntity = (CBaseEntity *) servertools->FirstEntity ();
155
140
}
156
141
157
- // ----------------------------------------------------------------------------
158
- // CBaseEntityGenerator Copy-Constructor.
159
- // ----------------------------------------------------------------------------
160
142
CBaseEntityGenerator::CBaseEntityGenerator ( PyObject* self, const CBaseEntityGenerator& rhs ):
161
- IPythonGenerator<CBaseEntityWrapper>(self)
143
+ IPythonGenerator<CBaseEntityWrapper>(self),
144
+ m_pCurrentEntity(rhs.m_pCurrentEntity),
145
+ m_uiClassNameLen(rhs.m_uiClassNameLen),
146
+ m_bExactMatch(rhs.m_bExactMatch)
162
147
{
163
- m_pCurrentEntity = rhs.m_pCurrentEntity ;
148
+ makeStringCopy (rhs.m_szClassName , m_uiClassNameLen);
149
+ }
150
+
151
+ CBaseEntityGenerator::CBaseEntityGenerator (PyObject* self, const char * szClassName):
152
+ IPythonGenerator<CBaseEntityWrapper>(self),
153
+ m_pCurrentEntity((CBaseEntity *)servertools->FirstEntity()),
154
+ m_uiClassNameLen(strlen(szClassName)),
155
+ m_bExactMatch(false )
156
+ {
157
+ makeStringCopy (szClassName, m_uiClassNameLen);
158
+ }
159
+
160
+ CBaseEntityGenerator::CBaseEntityGenerator (PyObject* self, const char * szClassName, bool bExactMatch):
161
+ IPythonGenerator<CBaseEntityWrapper>(self),
162
+ m_pCurrentEntity((CBaseEntity *)servertools->FirstEntity()),
163
+ m_uiClassNameLen(strlen(szClassName)),
164
+ m_bExactMatch(bExactMatch)
165
+ {
166
+ makeStringCopy (szClassName, m_uiClassNameLen);
167
+ }
168
+
169
+ void CBaseEntityGenerator::makeStringCopy (const char * szClassName, unsigned int uiClassNameLen)
170
+ {
171
+ if (uiClassNameLen > 0 )
172
+ {
173
+ char * szClassNameCopy = new char [uiClassNameLen + 1 ];
174
+ memcpy (szClassNameCopy, szClassName, uiClassNameLen);
175
+ szClassNameCopy[uiClassNameLen] = 0 ;
176
+ m_szClassName = szClassNameCopy;
177
+ }
178
+ else
179
+ {
180
+ m_szClassName = NULL ;
181
+ }
182
+ }
183
+
184
+ CBaseEntityGenerator::~CBaseEntityGenerator ()
185
+ {
186
+ delete[] m_szClassName;
164
187
}
165
188
166
- // ----------------------------------------------------------------------------
167
- // Returns the next valid CBaseEntity instance.
168
- // ----------------------------------------------------------------------------
169
189
CBaseEntityWrapper* CBaseEntityGenerator::getNext ()
170
190
{
171
- CBaseEntity* result = m_pCurrentEntity;
172
- m_pCurrentEntity = (CBaseEntity *) servertools->NextEntity (m_pCurrentEntity);
173
- return (CBaseEntityWrapper *) result;
191
+ CBaseEntity* result = NULL ;
192
+ while (m_pCurrentEntity)
193
+ {
194
+ result = m_pCurrentEntity;
195
+ m_pCurrentEntity = (CBaseEntity *)servertools->NextEntity (m_pCurrentEntity);
196
+ if (result && m_uiClassNameLen && m_szClassName)
197
+ {
198
+ const char * szClassname = IServerUnknownExt::GetClassname (result);
199
+ if (!m_bExactMatch && strncmp (szClassname, m_szClassName, m_uiClassNameLen) != 0 )
200
+ continue ;
201
+
202
+ else if (m_bExactMatch && strcmp (szClassname, m_szClassName) != 0 )
203
+ continue ;
204
+ }
205
+ return (CBaseEntityWrapper*) result;
206
+ }
207
+ return NULL ;
174
208
}
175
209
176
210
177
211
// ----------------------------------------------------------------------------
178
- // CServerClassGenerator Constructor.
212
+ // CServerClassGenerator
179
213
// ----------------------------------------------------------------------------
180
214
CServerClassGenerator::CServerClassGenerator ( PyObject* self ):
181
215
IPythonGenerator<ServerClass>(self)
182
216
{
183
217
m_pCurrentServerClass = servergamedll->GetAllServerClasses ();
184
218
}
185
219
186
- // ----------------------------------------------------------------------------
187
- // CServerClassGenerator Copy-Constructor.
188
- // ----------------------------------------------------------------------------
189
220
CServerClassGenerator::CServerClassGenerator ( PyObject* self, const CServerClassGenerator& rhs ):
190
221
IPythonGenerator<ServerClass>(self)
191
222
{
192
223
m_pCurrentServerClass = rhs.m_pCurrentServerClass ;
193
224
}
194
225
195
- // ----------------------------------------------------------------------------
196
- // Returns the next valid CBaseEntity instance.
197
- // ----------------------------------------------------------------------------
198
226
ServerClass* CServerClassGenerator::getNext ()
199
227
{
200
228
if (!m_pCurrentServerClass)
0 commit comments