📄 demomain.cc
字号:
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
#include "platform/platform.h"
#ifndef TGE_RPGCLIENT2 /// TGE_RPGClient2
#include "platform/platformIME.h" //IME
#include "platform/platformVideo.h"
#include "platform/platformInput.h"
#include "platform/platformAudio.h"
#include "platform/event.h"
#include "platform/gameInterface.h"
#include "core/tVector.h"
#include "core/chunkFile.h"
#include "math/mMath.h"
#include "dgl/dgl.h"
#include "dgl/gBitmap.h"
#include "core/resManager.h"
#include "core/fileStream.h"
#include "dgl/gTexManager.h"
#include "dgl/gFont.h"
#include "console/console.h"
#include "console/simBase.h"
#include "gui/core/guiCanvas.h"
#include "sim/actionMap.h"
#include "core/dnet.h"
#include "game/game.h"
#include "core/bitStream.h"
#include "console/telnetConsole.h"
#include "console/telnetDebugger.h"
#include "console/consoleTypes.h"
#include "math/mathTypes.h"
#include "dgl/gTexManager.h"
#include "core/resManager.h"
#include "interior/interiorRes.h"
#include "interior/interiorInstance.h"
#include "interior/interiorMapRes.h"
#include "ts/tsShapeInstance.h"
#include "terrain/terrData.h"
#include "terrain/terrRender.h"
#include "editor/terraformer.h"
#include "sceneGraph/sceneGraph.h"
#include "dgl/materialList.h"
#include "sceneGraph/sceneRoot.h"
#include "game/moveManager.h"
#include "platform/platformVideo.h"
#include "dgl/materialPropertyMap.h"
#include "sim/netStringTable.h"
#include "sim/pathManager.h"
#include "game/gameFunctions.h"
#include "game/fx/particleEngine.h"
#include "platform/platformRedBook.h"
#include "sim/decalManager.h"
#include "core/frameAllocator.h"
#include "sceneGraph/detailManager.h"
#include "interior/interiorLMManager.h"
#include "game/version.h"
#include "platform/profiler.h"
#include "game/shapeBase.h"
#include "game/objectTypes.h"
#include "game/net/serverQuery.h"
#include "game/badWordFilter.h"
#include "game/demoGame.h"
#ifdef TGE_RPG /// TGE_Map
#include "game/WorldWall.h"//
#endif
#ifndef BUILD_TOOLS
DemoGame GameObject;
DemoNetInterface GameNetInterface;
#endif
/// TGE_TerrainScene
extern ResourceInstance *constructTerrainScene(Stream &stream);
extern ResourceInstance *constructTerrainFile(Stream &stream);
extern ResourceInstance *constructTSShape(Stream &);
extern void netInit();
extern void processConnectedReceiveEvent( ConnectedReceiveEvent * event );
extern void processConnectedNotifyEvent( ConnectedNotifyEvent * event );
extern void processConnectedAcceptEvent( ConnectedAcceptEvent * event );
extern void ShowInit();
extern /*static */bool initLibraries();
extern/*static*/ void shutdownLibraries();
static F32 gTimeScale = 1.0;
static U32 gTimeAdvance = 0;
static U32 gFrameSkip = 0;
static U32 gFrameCount = 0;
// Executes an entry script; can be controlled by command-line options.
extern bool runEntryScript (int argc, const char **argv);
/// Initalize game, run the specified startup script
extern bool initGame(int argc, const char **argv);
/// Shutdown the game and delete core objects
extern void shutdownGame();
extern bool gDGLRender;
bool gShuttingDown = false;
/// Main loop of the game
int DemoGame::main(int argc, const char **argv)
{
// if (argc == 1) {
// static const char* argvFake[] = { "dtest.exe", "-jload", "test.jrn" };
// argc = 3;
// argv = argvFake;
// }
// Memory::enableLogging("testMem.log");
// Memory::setBreakAlloc(104717);
if(!initLibraries())
return 0;
#ifdef IHVBUILD
char* pVer = new char[sgVerStringLen + 1];
U32 hi;
for (hi = 0; hi < sgVerStringLen; hi++)
pVer[hi] = sgVerString[hi] ^ 0xFF;
pVer[hi] = '\0';
SHA1Context hashCTX;
hashCTX.init();
hashCTX.hashBytes(pVer, sgVerStringLen);
hashCTX.finalize();
U8 hash[20];
hashCTX.getHash(hash);
for (hi = 0; hi < 20; hi++)
if (U8(hash[hi]) != U8(sgHashVer[hi]))
return 0;
#endif
// Set up the command line args for the console scripts...
Con::setIntVariable("Game::argc", argc);
U32 i;
for (i = 0; i < argc; i++)
Con::setVariable(avar("Game::argv%d", i), argv[i]);
if (initGame(argc, argv) == false)
{
Platform::AlertOK("Error", "Failed to initialize game, shutting down.");
shutdownGame();
shutdownLibraries();
gShuttingDown = true;
return 0;
}
#ifdef IHVBUILD
char* pPrint = new char[dStrlen(sgVerPrintString) + 1];
for (U32 pi = 0; pi < dStrlen(sgVerPrintString); pi++)
pPrint[pi] = sgVerPrintString[pi] ^ 0xff;
pPrint[dStrlen(sgVerPrintString)] = '\0';
Con::printf("");
Con::errorf(ConsoleLogEntry::General, pPrint, pVer);
delete [] pVer;
#endif
while(Game->isRunning())
{
PROFILE_START(MainLoop);
PROFILE_START(JournalMain);
Game->journalProcess();
PROFILE_END();
PROFILE_START(NetProcessMain);
Net::process(); // read in all events
PROFILE_END();
PROFILE_START(PlatformProcessMain);
Platform::process(); // keys, etc.
PROFILE_END();
PROFILE_START(TelconsoleProcessMain);
TelConsole->process();
PROFILE_END();
PROFILE_START(TelDebuggerProcessMain);
TelDebugger->process();
PROFILE_END();
PROFILE_START(TimeManagerProcessMain);
TimeManager::process(); // guaranteed to produce an event
PROFILE_END();
PROFILE_END();
}
shutdownGame();
shutdownLibraries();
gShuttingDown = true;
#if 0
// tg: Argh! This OS version check should be part of Platform, not here...
//
// check os
OSVERSIONINFO osInfo;
dMemset(&osInfo, 0, sizeof(OSVERSIONINFO));
osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
// see if osversioninfoex fails
if(!GetVersionEx((OSVERSIONINFO*)&osInfo))
{
osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if(!GetVersionEx((OSVERSIONINFO*)&osInfo))
return 0;
}
// terminate the process if win95 only!
if((osInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) && // 95, 98, ME
(osInfo.dwMajorVersion == 4) && // 95, 98, ME, NT
(osInfo.dwMinorVersion == 0)) // 95
{
AssertWarn(0, "Forcing termination of app (Win95)! Upgrade your OS now!");
TerminateProcess(GetCurrentProcess(), 0xffffffff);
}
#endif
return 0;
}
//--------------------------------------
/// Resets the FPS variables
extern void fpsReset();
//--------------------------------------
/// Updates the FPS variables
extern void fpsUpdate();
/// Process a mouse movement event, essentially pass to the canvas for handling
void DemoGame::processMouseMoveEvent(MouseMoveEvent * mEvent)
{
if (Canvas)
Canvas->processMouseMoveEvent(mEvent);
}
/// Process an input event, pass to canvas for handling
void DemoGame::processInputEvent(InputEvent *event)
{
PROFILE_START(ProcessInputEvent);
if (!ActionMap::handleEventGlobal(event))
{
// Other input consumers here...
if (!(Canvas && Canvas->processInputEvent(event)))
ActionMap::handleEvent(event);
}
PROFILE_END();
}
/// Process a quit event
void DemoGame::processQuitEvent()
{
setRunning(false);
}
/// Refresh the game window, ask the canvas to set all regions to dirty (need to be updated)
void DemoGame::refreshWindow()
{
if(Canvas)
Canvas->resetUpdateRegions();
}
/// Process a console event
void DemoGame::processConsoleEvent(ConsoleEvent *event)
{
char *argv[2];
argv[0] = "eval";
argv[1] = event->data;
Sim::postCurrentEvent(Sim::getRootGroup(), new SimConsoleEvent(2, const_cast<const char**>(argv), false));
}
/// Process a time event and update all sub-processes
void DemoGame::processTimeEvent(TimeEvent *event)
{
PROFILE_START(ProcessTimeEvent);
U32 elapsedTime = event->elapsedTime;
// cap the elapsed time to one second
// if it's more than that we're probably in a bad catch-up situation
if(elapsedTime > 1024)
elapsedTime = 1024;
U32 timeDelta;
if(gTimeAdvance)
timeDelta = gTimeAdvance;
else
timeDelta = (U32) (elapsedTime * gTimeScale);
Platform::advanceTime(elapsedTime);
bool tickPass;
/// 取消server端逻辑处理
#ifndef TGE_RPGCLIENT2 /// TGE_RPGClient2
PROFILE_START(ServerProcess);
tickPass = serverProcess(timeDelta);
PROFILE_END();
PROFILE_START(ServerNetProcess);
// only send packets if a tick happened
if(tickPass)
GNet->processServer();
PROFILE_END();
#endif
PROFILE_START(SimAdvanceTime);
Sim::advanceTime(timeDelta);
PROFILE_END();
PROFILE_START(ClientProcess);
tickPass = clientProcess(timeDelta);
PROFILE_END();
PROFILE_START(ClientNetProcess);
if(tickPass)
GNet->processClient();
PROFILE_END();
if(Canvas && gDGLRender)
{
bool preRenderOnly = false;
if(gFrameSkip && gFrameCount % gFrameSkip)
preRenderOnly = true;
PROFILE_START(RenderFrame);
ShapeBase::incRenderFrame();
Canvas->renderFrame(preRenderOnly);
PROFILE_END();
gFrameCount++;
}
GNet->checkTimeouts();
fpsUpdate();
PROFILE_END();
// Update the console time
Con::setFloatVariable("Sim::Time",F32(Platform::getVirtualMilliseconds()) / 1000);
}
/// Re-activate the game from, say, a minimized state
void GameReactivate()
{
if ( !Input::isEnabled() )
Input::enable();
if ( !Input::isActive() )
Input::reactivate();
gDGLRender = true;
if ( Canvas )
Canvas->resetUpdateRegions();
}
/// De-activate the game in responce to, say, a minimize event
void GameDeactivate( bool noRender )
{
if ( Input::isActive() )
Input::deactivate();
if ( Input::isEnabled() )
Input::disable();
if ( noRender )
gDGLRender = false;
}
/// Invalidate all the textures
void DemoGame::textureKill()
{
TextureManager::makeZombie();
}
/// Reaquire all textures
void DemoGame::textureResurrect()
{
TextureManager::resurrect();
}
/// Process recieved net-packets
void DemoGame::processPacketReceiveEvent(PacketReceiveEvent * prEvent)
{
GNet->processPacketReceiveEvent(prEvent);
}
#endif //#ifndef TGE_RPGCLIENT2 /// TGE_RPGClient2
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -