|
pred@1922
|
1 |
/** |
|
pred@1922
|
2 |
* vim: set ts=4 : |
|
pred@1922
|
3 |
* ============================================================================= |
|
pred@1922
|
4 |
* SourceMod SDKTools Extension |
|
pred@1922
|
5 |
* Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. |
|
pred@1922
|
6 |
* ============================================================================= |
|
pred@1922
|
7 |
* |
|
pred@1922
|
8 |
* This program is free software; you can redistribute it and/or modify it under |
|
pred@1922
|
9 |
* the terms of the GNU General Public License, version 3.0, as published by the |
|
pred@1922
|
10 |
* Free Software Foundation. |
|
pred@1922
|
11 |
* |
|
pred@1922
|
12 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
pred@1922
|
13 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
pred@1922
|
14 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
pred@1922
|
15 |
* details. |
|
pred@1922
|
16 |
* |
|
pred@1922
|
17 |
* You should have received a copy of the GNU General Public License along with |
|
pred@1922
|
18 |
* this program. If not, see <http://www.gnu.org/licenses/>. |
|
pred@1922
|
19 |
* |
|
pred@1922
|
20 |
* As a special exception, AlliedModders LLC gives you permission to link the |
|
pred@1922
|
21 |
* code of this program (as well as its derivative works) to "Half-Life 2," the |
|
pred@1922
|
22 |
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software |
|
pred@1922
|
23 |
* by the Valve Corporation. You must obey the GNU General Public License in |
|
pred@1922
|
24 |
* all respects for all other code used. Additionally, AlliedModders LLC grants |
|
pred@1922
|
25 |
* this exception to all derivative works. AlliedModders LLC defines further |
|
pred@1922
|
26 |
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), |
|
pred@1922
|
27 |
* or <http://www.sourcemod.net/license.php>. |
|
pred@1922
|
28 |
* |
|
pred@1922
|
29 |
* Version: $Id: vcallbuilder.h 1566 2007-10-14 22:12:46Z faluco $ |
|
pred@1922
|
30 |
*/ |
|
pred@1922
|
31 |
|
|
pred@1922
|
32 |
#ifndef _INCLUDE_SOURCEMOD_UTIL_H_ |
|
pred@1922
|
33 |
#define _INCLUDE_SOURCEMOD_UTIL_H_ |
|
pred@1922
|
34 |
|
|
pred@1922
|
35 |
#include "utldict.h" |
|
pred@1922
|
36 |
|
|
pred@1922
|
37 |
abstract_class IEntityFactory |
|
pred@1922
|
38 |
{ |
|
pred@1922
|
39 |
public: |
|
pred@1922
|
40 |
virtual IServerNetworkable *Create( const char *pClassName ) = 0; |
|
pred@1922
|
41 |
virtual void Destroy( IServerNetworkable *pNetworkable ) = 0; |
|
pred@1922
|
42 |
virtual size_t GetEntitySize() = 0; |
|
pred@1922
|
43 |
}; |
|
pred@1922
|
44 |
|
|
pred@1922
|
45 |
template <class T> |
|
pred@1922
|
46 |
class CEntityFactory : public IEntityFactory |
|
pred@1922
|
47 |
{ |
|
pred@1922
|
48 |
public: |
|
pred@1922
|
49 |
CEntityFactory( const char *pClassName ) |
|
pred@1922
|
50 |
{ |
|
pred@1922
|
51 |
EntityFactoryDictionary()->InstallFactory( this, pClassName ); |
|
pred@1922
|
52 |
} |
|
pred@1922
|
53 |
|
|
pred@1922
|
54 |
IServerNetworkable *Create( const char *pClassName ) |
|
pred@1922
|
55 |
{ |
|
pred@1922
|
56 |
T* pEnt = _CreateEntityTemplate((T*)NULL, pClassName); |
|
pred@1922
|
57 |
return pEnt->NetworkProp(); |
|
pred@1922
|
58 |
} |
|
pred@1922
|
59 |
|
|
pred@1922
|
60 |
void Destroy( IServerNetworkable *pNetworkable ) |
|
pred@1922
|
61 |
{ |
|
pred@1922
|
62 |
if ( pNetworkable ) |
|
pred@1922
|
63 |
{ |
|
pred@1922
|
64 |
pNetworkable->Release(); |
|
pred@1922
|
65 |
} |
|
pred@1922
|
66 |
} |
|
pred@1922
|
67 |
|
|
pred@1922
|
68 |
virtual size_t GetEntitySize() |
|
pred@1922
|
69 |
{ |
|
pred@1922
|
70 |
return sizeof(T); |
|
pred@1922
|
71 |
} |
|
pred@1922
|
72 |
}; |
|
pred@1922
|
73 |
|
|
pred@1922
|
74 |
abstract_class IEntityFactoryDictionary |
|
pred@1922
|
75 |
{ |
|
pred@1922
|
76 |
public: |
|
pred@1922
|
77 |
virtual void InstallFactory( IEntityFactory *pFactory, const char *pClassName ) = 0; |
|
pred@1922
|
78 |
virtual IServerNetworkable *Create( const char *pClassName ) = 0; |
|
pred@1922
|
79 |
virtual void Destroy( const char *pClassName, IServerNetworkable *pNetworkable ) = 0; |
|
pred@1922
|
80 |
virtual IEntityFactory *FindFactory( const char *pClassName ) = 0; |
|
pred@1922
|
81 |
virtual const char *GetCannonicalName( const char *pClassName ) = 0; |
|
pred@1922
|
82 |
}; |
|
pred@1922
|
83 |
|
|
pred@1922
|
84 |
|
|
pred@1922
|
85 |
class CEntityFactoryDictionary : public IEntityFactoryDictionary |
|
pred@1922
|
86 |
{ |
|
pred@1922
|
87 |
public: |
|
pred@1922
|
88 |
CEntityFactoryDictionary(); |
|
pred@1922
|
89 |
|
|
pred@1922
|
90 |
virtual void InstallFactory( IEntityFactory *pFactory, const char *pClassName ); |
|
pred@1922
|
91 |
virtual IServerNetworkable *Create( const char *pClassName ); |
|
pred@1922
|
92 |
virtual void Destroy( const char *pClassName, IServerNetworkable *pNetworkable ); |
|
pred@1922
|
93 |
virtual const char *GetCannonicalName( const char *pClassName ); |
|
pred@1922
|
94 |
void ReportEntitySizes(); |
|
pred@1922
|
95 |
|
|
pred@1922
|
96 |
private: |
|
pred@1922
|
97 |
IEntityFactory *FindFactory( const char *pClassName ); |
|
pred@1922
|
98 |
public: |
|
pred@1922
|
99 |
CUtlDict< IEntityFactory *, unsigned short > m_Factories; |
|
pred@1922
|
100 |
}; |
|
pred@1922
|
101 |
|
|
pred@1922
|
102 |
#endif //_INCLUDE_SOURCEMOD_UTIL_H_ |