core/sm_globals.h
author David Anderson <dvander@alliedmods.net>
Sat Apr 07 03:58:20 2007 +0000 (2007-04-07)
changeset 673 fc1d50579d06
parent 669 ce01c2eb020c
child 675 40b8bc6ac247
permissions -rw-r--r--
added some levelchange functions to SMGlobalClass to get rid of some messy crap
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5  * ===============================================================
     6  *
     7  * This file is not open source and may not be copied without explicit
     8  * written permission of AlliedModders LLC.  This file may not be redistributed 
     9  * in whole or significant part.
    10  * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
    11  *
    12  * Version: $Id$
    13  */
    14 
    15 #ifndef _INCLUDE_SOURCEMOD_GLOBALS_H_
    16 #define _INCLUDE_SOURCEMOD_GLOBALS_H_
    17 
    18 /**
    19  * @file Contains global headers that most files in SourceMod will need.
    20  */
    21 
    22 #include <sp_vm_types.h>
    23 #include <sp_vm_api.h>
    24 #include "sm_platform.h"
    25 #include <IShareSys.h>
    26 
    27 using namespace SourcePawn;
    28 using namespace SourceMod;
    29 
    30 /**
    31  * @brief Lists result codes possible from attempting to set a core configuration option.
    32  */
    33 enum ConfigResult
    34 {
    35 	ConfigResult_Accept = 0,	/**< Config option was successfully set */
    36 	ConfigResult_Reject = 1,	/**< Config option was given an invalid value and was rejected */
    37 	ConfigResult_Ignore = 2		/**< Config option was invalid, but ignored */
    38 };
    39 
    40 /**
    41  * @brief Lists possible sources of a config option change
    42  */
    43 enum ConfigSource
    44 {
    45 	ConfigSource_File = 0,		/**< Config option was set from config file (core.cfg) */
    46 	ConfigSource_Console = 1,	/**< Config option was set from console command (sm config) */
    47 };
    48 
    49 /** 
    50  * @brief Any class deriving from this will be automatically initiated/shutdown by SourceMod
    51  */
    52 class SMGlobalClass
    53 {
    54 	friend class SourceModBase;
    55 	friend class CoreConfig;
    56 public:
    57 	SMGlobalClass();
    58 public:
    59 	/**
    60 	 * @brief Called when SourceMod is initially loading
    61 	 */
    62 	virtual void OnSourceModStartup(bool late)
    63 	{
    64 	}
    65 
    66 	/**
    67 	 * @brief Called after all global classes have initialized
    68 	 */
    69 	virtual void OnSourceModAllInitialized()
    70 	{
    71 	}
    72 
    73 	/**
    74 	 * @brief Called when SourceMod is shutting down
    75 	 */
    76 	virtual void OnSourceModShutdown()
    77 	{
    78 	}
    79 
    80 	/**
    81 	 * @brief Called after SourceMod is completely shut down
    82 	 */
    83 	virtual void OnSourceModAllShutdown()
    84 	{
    85 	}
    86 
    87 	/**
    88 	 * @brief Called when a core config option is changed.
    89 	 * @note This is called once BEFORE OnSourceModStartup() when SourceMod is loading
    90 	 * @note It can then be called again when the 'sm config' command is used
    91 	 */
    92 	virtual ConfigResult OnSourceModConfigChanged(const char *key, 
    93 												  const char *value, 
    94 												  ConfigSource source,
    95 												  char *error, 
    96 												  size_t maxlength)
    97 	{
    98 		return ConfigResult_Ignore;
    99 	}
   100 
   101 	/**
   102 	 * @brief Called when the level changes.
   103 	 */
   104 	virtual void OnSourceModLevelChange(const char *mapName)
   105 	{
   106 	}
   107 
   108 	/**
   109 	 * @brief Called after plugins are loaded on mapchange.
   110 	 */
   111 	virtual void OnSourceModPluginsLoaded()
   112 	{
   113 	}
   114 private:
   115 	SMGlobalClass *m_pGlobalClassNext;
   116 	static SMGlobalClass *head;
   117 };
   118 
   119 extern ISourcePawnEngine *g_pSourcePawn;
   120 extern IVirtualMachine *g_pVM;
   121 extern IdentityToken_t *g_pCoreIdent;
   122 
   123 #include "sm_autonatives.h"
   124 
   125 #endif //_INCLUDE_SOURCEMOD_GLOBALS_H_