• Main Page
  • Related Pages
  • Classes
  • Files
  • File List
  • File Members

public/compat_wrappers.h

00001 /**
00002  * vim: set ts=4 :
00003  * =============================================================================
00004  * SourceMod
00005  * Copyright (C) 2004-2010 AlliedModders LLC.  All rights reserved.
00006  * =============================================================================
00007  *
00008  * This program is free software; you can redistribute it and/or modify it under
00009  * the terms of the GNU General Public License, version 3.0, as published by the
00010  * Free Software Foundation.
00011  * 
00012  * This program is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00014  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00015  * details.
00016  *
00017  * You should have received a copy of the GNU General Public License along with
00018  * this program.  If not, see <http://www.gnu.org/licenses/>.
00019  *
00020  * As a special exception, AlliedModders LLC gives you permission to link the
00021  * code of this program (as well as its derivative works) to "Half-Life 2," the
00022  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
00023  * by the Valve Corporation.  You must obey the GNU General Public License in
00024  * all respects for all other code used.  Additionally, AlliedModders LLC grants
00025  * this exception to all derivative works.  AlliedModders LLC defines further
00026  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
00027  * or <http://www.sourcemod.net/license.php>.
00028  *
00029  * Version: $Id$
00030  */
00031 
00032 #ifndef _INCLUDE_SOURCEMOD_COMPAT_WRAPPERS_H_
00033 #define _INCLUDE_SOURCEMOD_COMPAT_WRAPPERS_H_
00034 
00035 #include <datamap.h>
00036 
00037 #if SOURCE_ENGINE >= SE_ORANGEBOX
00038           #define CONVAR_REGISTER(object)                                       ConVar_Register(0, object)
00039 
00040           inline bool IsFlagSet(ConCommandBase *cmd, int flag)
00041           {
00042                     return cmd->IsFlagSet(flag);
00043           }
00044           inline void InsertServerCommand(const char *buf)
00045           {
00046                     engine->InsertServerCommand(buf);
00047           }
00048           inline ConCommandBase *FindCommandBase(const char *name)
00049           {
00050                     return icvar->FindCommandBase(name);
00051           }
00052           inline ConCommand *FindCommand(const char *name)
00053           {
00054                     return icvar->FindCommand(name);
00055           }
00056 #else
00057           class CCommand
00058           {
00059           public:
00060                     inline const char *ArgS() const
00061                     {
00062                               return engine->Cmd_Args();
00063                     }
00064                     inline int ArgC() const
00065                     {
00066                               return engine->Cmd_Argc();
00067                     }
00068                     inline const char *Arg(int index) const
00069                     {
00070                               return engine->Cmd_Argv(index);
00071                     }
00072           };
00073 
00074           inline bool IsFlagSet(ConCommandBase *cmd, int flag)
00075           {
00076                     return cmd->IsBitSet(flag);
00077           }
00078           inline void InsertServerCommand(const char *buf)
00079           {
00080                     engine->InsertServerCommand(buf);
00081           }
00082           inline ConCommandBase *FindCommandBase(const char *name)
00083           {
00084                     ConCommandBase *pBase = icvar->GetCommands();
00085                     while (pBase)
00086                     {
00087                               if (strcmp(pBase->GetName(), name) == 0)
00088                               {
00089                                         if (!pBase->IsCommand())
00090                                         {
00091                                                   return NULL;
00092                                         }
00093 
00094                                         return pBase;
00095                               }
00096                               pBase = const_cast<ConCommandBase *>(pBase->GetNext());
00097                     }
00098                     return NULL;
00099           }
00100           inline ConCommand *FindCommand(const char *name)
00101           {
00102                     ConCommandBase *pBase = icvar->GetCommands();
00103                     while (pBase)
00104                     {
00105                               if (strcmp(pBase->GetName(), name) == 0)
00106                               {
00107                                         if (!pBase->IsCommand())
00108                                         {
00109                                                   return NULL;
00110                                         }
00111 
00112                                         return static_cast<ConCommand *>(pBase);
00113                               }
00114                               pBase = const_cast<ConCommandBase *>(pBase->GetNext());
00115                     }
00116                     return NULL;
00117           }
00118 
00119           #define CVAR_INTERFACE_VERSION                                        VENGINE_CVAR_INTERFACE_VERSION
00120 
00121           #define CONVAR_REGISTER(object)                                       ConCommandBaseMgr::OneTimeInit(object)
00122           typedef FnChangeCallback                                              FnChangeCallback_t;
00123 #endif //SOURCE_ENGINE >= SE_ORANGEBOX
00124 
00125 #if SOURCE_ENGINE >= SE_LEFT4DEAD
00126           inline int IndexOfEdict(const edict_t *pEdict)
00127           {
00128                     return (int)(pEdict - gpGlobals->pEdicts);
00129           }
00130           inline edict_t *PEntityOfEntIndex(int iEntIndex)
00131           {
00132                     if (iEntIndex >= 0 && iEntIndex < gpGlobals->maxEntities)
00133                     {
00134                               return (edict_t *)(gpGlobals->pEdicts + iEntIndex);
00135                     }
00136                     return NULL;
00137           }
00138           inline int GetTypeDescOffs(typedescription_t *td)
00139           {
00140                     return td->fieldOffset;
00141           }
00142 #else
00143           inline int IndexOfEdict(const edict_t *pEdict)
00144           {
00145                     return engine->IndexOfEdict(pEdict);
00146           }
00147           inline edict_t *PEntityOfEntIndex(int iEntIndex)
00148           {
00149                     return engine->PEntityOfEntIndex(iEntIndex);
00150           }
00151           inline int GetTypeDescOffs(typedescription_t *td)
00152           {
00153                     return td->fieldOffset[TD_OFFSET_NORMAL];
00154           }
00155 #endif //SOURCE_ENGINE >= SE_LEFT4DEAD
00156 
00157 #endif //_INCLUDE_SOURCEMOD_COMPAT_WRAPPERS_H_

Generated on Wed Dec 7 2011 18:50:02 for SourceMod SDK by  doxygen 1.7.1