core/logic/common_logic.cpp
author David Anderson <dvander@alliedmods.net>
Mon Dec 14 23:08:15 2009 -0800 (2009-12-14)
changeset 2878 0e24b9d8abcb
parent 2730 a2ff0a7a1c53
child 2906 33cc9854bd97
permissions -rw-r--r--
Fixed profiler being set to NULL (bug 4143, r=fyren).
     1 /**
     2  * vim: set ts=4 sw=4 :
     3  * =============================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     6  * =============================================================================
     7  *
     8  * This program is free software; you can redistribute it and/or modify it under
     9  * the terms of the GNU General Public License, version 3.0, as published by the
    10  * Free Software Foundation.
    11  * 
    12  * This program is distributed in the hope that it will be useful, but WITHOUT
    13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    15  * details.
    16  *
    17  * You should have received a copy of the GNU General Public License along with
    18  * this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *
    20  * As a special exception, AlliedModders LLC gives you permission to link the
    21  * code of this program (as well as its derivative works) to "Half-Life 2," the
    22  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    23  * by the Valve Corporation.  You must obey the GNU General Public License in
    24  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    25  * this exception to all derivative works.  AlliedModders LLC defines further
    26  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    27  * or <http://www.sourcemod.net/license.php>.
    28  *
    29  * Version: $Id$
    30  */
    31 #include <new>
    32 #include <stdlib.h>
    33 #include <sm_platform.h>
    34 #include <string.h>
    35 #include "common_logic.h"
    36 #include "ThreadSupport.h"
    37 #include "TextParsers.h"
    38 #include "Profiler.h"
    39 
    40 sm_core_t smcore;
    41 IHandleSys *handlesys;
    42 IdentityToken_t *g_pCoreIdent;
    43 SMGlobalClass *SMGlobalClass::head = NULL;
    44 ISourceMod *g_pSM;
    45 ILibrarySys *libsys;
    46 ITextParsers *textparser = &g_TextParser;
    47 IVEngineServer *engine;
    48 IShareSys *sharesys;
    49 IRootConsole *rootmenu;
    50 IPluginManager *pluginsys;
    51 IForwardManager *forwardsys;
    52 
    53 static sm_logic_t logic =
    54 {
    55 	NULL,
    56 	g_pThreader,
    57 	sm_profiler
    58 };
    59 
    60 static void logic_init(const sm_core_t* core, sm_logic_t* _logic)
    61 {
    62 	logic.head = SMGlobalClass::head;
    63 
    64 	memcpy(&smcore, core, sizeof(sm_core_t));
    65 	memcpy(_logic, &logic, sizeof(sm_logic_t));
    66 
    67 	handlesys = core->handlesys;
    68 	libsys = core->libsys;
    69 	engine = core->engine;
    70 	g_pCoreIdent = core->core_ident;
    71 	g_pSM = core->sm;
    72 	sharesys = core->sharesys;
    73 	rootmenu = core->rootmenu;
    74 	pluginsys = core->pluginsys;
    75 	forwardsys = core->forwardsys;
    76 }
    77 
    78 PLATFORM_EXTERN_C ITextParsers *get_textparsers()
    79 {
    80 	return &g_TextParser;
    81 }
    82 
    83 PLATFORM_EXTERN_C LogicInitFunction logic_load(uint32_t magic)
    84 {
    85 	if (magic != SM_LOGIC_MAGIC)
    86 	{
    87 		return NULL;
    88 	}
    89 
    90 	return logic_init;
    91 }
    92 
    93 void CoreNativesToAdd::OnSourceModAllInitialized()
    94 {
    95 	smcore.AddNatives(m_NativeList);
    96 }
    97 
    98 /* Overload a few things to prevent libstdc++ linking */
    99 #if defined __linux__ || defined __APPLE__
   100 extern "C" void __cxa_pure_virtual(void)
   101 {
   102 }
   103 
   104 void *operator new(size_t size)
   105 {
   106 	return malloc(size);
   107 }
   108 
   109 void *operator new[](size_t size) 
   110 {
   111 	return malloc(size);
   112 }
   113 
   114 void operator delete(void *ptr) 
   115 {
   116 	free(ptr);
   117 }
   118 
   119 void operator delete[](void * ptr)
   120 {
   121 	free(ptr);
   122 }
   123 #endif
   124