Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

ASys.cpp File Reference


Detailed Description

Implements the 'sys_' functions in AEngine.h.

Definition in file ASys.cpp.

#include "AEngine.h"
#include "AState.h"
#include "AConstants.h"
#include "ADevice.h"
#include "ASharedFunc.h"
#include "float.h"

Include dependency graph for ASys.cpp:

Include dependency graph

Go to the source code of this file.

Functions

void sys_init (HINSTANCE hInst, int width, int height, int colorDepth, bool fullScreen)
 setup the AEngine. You should call this before doing anything else hInst is passed to you by WinMain. Just pass it along to this function note that not all modes can be supported by your video card try standard things such as 800x600x16bit or 1024x768x32bit

void sys_setSkipRate (int rate)
 rate=0 means try never to skip any frame. rate=1 means render every other frame

void sys_setInitFunc (AierraInitFunc f)
 set call-back functions so the engine knows how to init, update the game state, render it, and shut down

void sys_setUpdateFunc (AierraUpdateFunc f)
void sys_setRenderFunc (AierraRenderFunc f)
void sys_setShutdownFunc (AierraShutdownFunc f)
void handleSystemMessages ()
void updateInput ()
void beginRendering ()
void endRendering ()
void drawConsole ()
void drawFPS ()
void checkSysKeys ()
void flushRenderRequests ()
void processRenderRequests ()
void doGameLoop ()
LRESULT WINAPI AierraWindowProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
void createWindow ()
void findCompatibleMode (D3DDISPLAYMODE &d3dDisplayMode)
void createRenderingDevice ()
void sys_shutdown ()
void displayLoadingScreen ()
void sys_go ()
 let the program runs. This function doesn't return (until sys_terminate())

void sys_terminate ()
 terminate the application. This function never returns

void sys_showFPS (bool show)
 whether to show the frame rate in the top-right corner

void sys_showConsole (bool show)
 whether or not to display the console window

void sys_enableConsoleLog (string filename)
 this function must be called before sys_go(); this will log all subsequent output to the console to the specified logfile

ostream & sys_console ()
 this returns you an output stream that you can write stuffs to they will be displayed on the in-game console window if it is set to visible

void sys_flushConsole ()
 flushes all texts sent to consol eto log file (if any)

void sys_fastForwardUpdate (int times)
 quickly update the game state 'times' times. this is quivalent to fast forwarding the game by roughly 'times'/62.5 seconds

DWORD sys_getMilliSec ()
 get current time in ms

void sys_setRandSeed (int seed)
 use these functions instead of the builtin rand, srand so we can log and keep track of what's going on

int sys_randInt ()
FLOAT sys_randFloat ()
int sys_localRandInt ()
FLOAT sys_localRandFloat ()
HWND sys_getWindowHandle ()

Variables

const int UPDATE_RATE = 60
const int UPDATE_INTERVAL = 1000/UPDATE_RATE


Function Documentation

LRESULT WINAPI AierraWindowProc HWND    hWnd,
UINT    msg,
WPARAM    wParam,
LPARAM    lParam
 

Definition at line 411 of file ASys.cpp.

Referenced by createWindow().

00412 {
00413     if( msg==WM_DESTROY ) throw TerminateNormally();
00414     return DefWindowProc( hWnd, msg, wParam, lParam );
00415 }

void beginRendering  
 

Definition at line 173 of file ASys.cpp.

References device_flushSettings().

Referenced by displayLoadingScreen(), and doGameLoop().

00174 {
00175         if(AS.camera_screenSize==1.0f)
00176         {
00177                 AS.pDevice->Clear( 0, NULL, AS.clearFlags, D3DCOLOR_XRGB(0,200,250), 1.0f, 0L );
00178                 
00179                 D3DVIEWPORT8 viewport;
00180                 viewport.X = 0;
00181                 viewport.Y = 0;
00182                 viewport.Width  = AS.windowWidth;
00183                 viewport.Height = AS.windowHeight;
00184                 viewport.MinZ = 0.0f;
00185                 viewport.MaxZ = 1.0f;
00186                 AS.pDevice->SetViewport(&viewport);
00187         }
00188         else
00189         {
00190                 D3DRECT rect;
00191                 rect.x1 = (LONG) (AS.windowWidth /2 - AS.camera_screenSize*AS.windowWidth /2 );
00192                 rect.x2 = (LONG) (AS.windowWidth /2 + AS.camera_screenSize*AS.windowWidth /2 );
00193                 rect.y1 = (LONG) (AS.windowHeight/2 - AS.camera_screenSize*AS.windowHeight/2 );
00194                 rect.y2 = (LONG) (AS.windowHeight/2 + AS.camera_screenSize*AS.windowHeight/2 );
00195                 AS.pDevice->Clear( 1, &rect, AS.clearFlags, D3DCOLOR_XRGB(0,0,0), 1.0f, 0L );
00196 
00197                 D3DVIEWPORT8 viewport;
00198                 viewport.X = rect.x1;
00199                 viewport.Y = rect.y1;
00200                 viewport.Width  = rect.x2 - rect.x1;
00201                 viewport.Height = rect.y2 - rect.y1;
00202                 viewport.MinZ = 0.0f;
00203                 viewport.MaxZ = 1.0f;
00204                 AS.pDevice->SetViewport(&viewport);
00205         }
00206 
00207         AS.pDevice->BeginScene();
00208         device_flushSettings();
00209 }

void checkSysKeys  
 

Definition at line 263 of file ASys.cpp.

References input_isKeyDown(), and input_isKeyPressed().

Referenced by doGameLoop().

00264 {       
00265         // LShift+LCtrl+END ==> quit
00266         if( input_isKeyDown(KeyCodes::key_LCONTROL) && input_isKeyDown(KeyCodes::key_LSHIFT)
00267                 && input_isKeyDown(KeyCodes::key_END) )
00268                 throw TerminateNormally();
00269 
00270         // LShift+LCtrl+C ==> toggle console visibility
00271         if( input_isKeyDown(KeyCodes::key_LCONTROL) && input_isKeyDown(KeyCodes::key_LSHIFT)
00272                 && input_isKeyPressed(KeyCodes::key_C) )        
00273                 AS.showConsole = !AS.showConsole;       
00274 
00275         // LShift+LCtrl+F ==> toggle FPS visibility
00276         if( input_isKeyDown(KeyCodes::key_LCONTROL) && input_isKeyDown(KeyCodes::key_LSHIFT)
00277                 && input_isKeyPressed(KeyCodes::key_F) )
00278                 AS.showFPS = !AS.showFPS;
00279 }

void createRenderingDevice  
 

Definition at line 451 of file ASys.cpp.

References findCompatibleMode().

Referenced by sys_go().

00452 {
00453         AS.pD3D = Direct3DCreate8(D3D_SDK_VERSION);
00454         if( AS.pD3D==NULL) throw Error("Can't create Direct3D");
00455 
00456         int rc;         // return code
00457         D3DDISPLAYMODE                  d3dDisplayMode;
00458         D3DPRESENT_PARAMETERS   d3dParam;
00459         ZeroMemory( &d3dParam, sizeof(d3dParam) );
00460     d3dParam.Windowed = !AS.isFullScreen;
00461     d3dParam.SwapEffect = D3DSWAPEFFECT_DISCARD;
00462 
00463         if(AS.isFullScreen)
00464         {
00465                 AS.clearFlags = D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL ;
00466                 findCompatibleMode(d3dDisplayMode);
00467                 // Confirm Mode Compatibility
00468                 rc = AS.pD3D->CheckDeviceType( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3dDisplayMode.Format,                                                                               
00469                                                 d3dDisplayMode.Format, false );
00470                 if(FAILED(rc)) throw Error("Video Mode Not Compatible");                
00471                 d3dParam.BackBufferWidth  = d3dDisplayMode.Width;
00472                 d3dParam.BackBufferHeight = d3dDisplayMode.Height;
00473                 d3dParam.BackBufferFormat = d3dDisplayMode.Format;      
00474                 d3dParam.EnableAutoDepthStencil = TRUE;
00475                 d3dParam.AutoDepthStencilFormat = D3DFMT_D24S8;
00476                 d3dParam.FullScreen_RefreshRateInHz = d3dDisplayMode.RefreshRate;
00477                 d3dParam.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
00478         }
00479         else
00480         {
00481                 AS.clearFlags= D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER ;
00482                 // choose same display mode as current desktop
00483                 rc = AS.pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3dDisplayMode);
00484                 if(FAILED(rc)) throw Error("Can't Find Existing Display Mode");
00485                 d3dParam.BackBufferFormat = d3dDisplayMode.Format;
00486                 d3dParam.EnableAutoDepthStencil = TRUE; 
00487                 d3dParam.AutoDepthStencilFormat = D3DFMT_D16;
00488         }
00489 
00490         // create direct 3D rendering device
00491         rc = AS.pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, AS.hWnd,
00492                                                         D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dParam, &AS.pDevice );
00493         if( FAILED(rc) ) throw Error("Can't create Direct3D Device");
00494         
00495         ShowWindow(AS.hWnd, SW_SHOWDEFAULT);
00496     UpdateWindow(AS.hWnd);
00497 
00498         if(!AS.isFullScreen)            // get actual window size (minus the border,titlebar)
00499         {               
00500                 RECT rect;
00501                 GetClientRect(AS.hWnd,&rect);
00502                 AS.windowWidth  = rect.right  - rect.left;
00503                 AS.windowHeight = rect.bottom - rect.top;
00504         }
00505 }

void createWindow  
 

Definition at line 417 of file ASys.cpp.

References AierraWindowProc().

Referenced by sys_go().

00418 {
00419         // Register the window class
00420     WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, AierraWindowProc, 0L, 0L, GetModuleHandle(NULL),
00421                                           NULL, LoadCursor(NULL, IDC_ARROW), NULL, NULL, "Aierra Engine", NULL };
00422     RegisterClassEx( &wc );
00423 
00424     // Create the application's window  
00425     AS.hWnd = CreateWindow( "Aierra Engine", "Modern Warfare", WS_VISIBLE, 0,0, 
00426                                                         AS.windowWidth, AS.windowHeight,
00427                             GetDesktopWindow(), NULL, wc.hInstance, NULL );     
00428         if(AS.hWnd==NULL) throw Error("Can't Create New Window");
00429 }

void displayLoadingScreen  
 

Definition at line 524 of file ASys.cpp.

References ATexture, beginRendering(), endRendering(), load_texture(), overlay_flush(), overlay_image(), overlay_render(), and Vec2D.

Referenced by sys_go().

00525 {
00526         overlay_flush();
00527         beginRendering();
00528         ATexture tex = load_texture("textures\\loading.tga");
00529         overlay_image( tex, Vec2D(0.5f,0.5f), Vec2D(1.0f,1.0f) );
00530         overlay_render();
00531         endRendering();
00532 }

void doGameLoop  
 

Definition at line 302 of file ASys.cpp.

References beginRendering(), checkSysKeys(), DWORD, endRendering(), flushRenderRequests(), handleSystemMessages(), processRenderRequests(), profiler_begin(), profiler_end(), profiler_render(), profiler_reset(), sys_console(), sys_getMilliSec(), UPDATE_INTERVAL, and updateInput().

Referenced by sys_go().

00303 {
00304         AS.idealMS = sys_getMilliSec();
00305         profiler_reset();
00306         updateInput();
00307         (AS.updateFunc)();
00308 
00309         while(true)
00310         {
00311                 profiler_begin("sys_overhead");
00312                 DWORD thisMS  = sys_getMilliSec();
00313                 DWORD elapsed = thisMS - AS.idealMS;
00314                 if( elapsed<1  ) elapsed = 1;
00315                 if( elapsed>100) elapsed = 100;
00316 
00317                 if( thisMS-AS.lastCountResetMS >= 1000 )                // calculate update/render/excess rate
00318                 {
00319                         FLOAT deltaT = (FLOAT) (thisMS-AS.lastCountResetMS);
00320                         AS.updateRate = AS.updateCount*1000.0f / deltaT;
00321                         AS.renderRate = AS.renderCount*1000.0f / deltaT;
00322                         AS.excessRate = AS.excessCount*1000.0f / deltaT;
00323                         AS.lastCountResetMS = thisMS;
00324                         AS.updateCount = 0;
00325                         AS.renderCount = 0;
00326                         AS.excessCount = 0;                     
00327                 }
00328 
00329                 if( thisMS-AS.profiler_MSlastReset >= 20000 )   // profiler
00330                 {
00331                         profiler_render();
00332                         profiler_reset();
00333                 }
00334                 profiler_end("sys_overhead");
00335                 
00336                 profiler_begin("sys_update");
00337 
00338                 if( AS.fastForwardAmount>0 )
00339                 {
00340                         for( int i=0; i<AS.fastForwardAmount; i++ )                             // fast forwarding
00341                         {
00342                                 updateInput();
00343                                 checkSysKeys();
00344                                 (AS.updateFunc)();
00345                                 AS.updateCount++;
00346                                 handleSystemMessages();
00347                         }
00348                         elapsed = 0;
00349                         AS.idealMS = sys_getMilliSec();         // attempt to make the system think we're just right on time
00350                         AS.fastForwardAmount = 0;
00351                 }
00352 
00353                 while( elapsed >= 16 )                                          // keep updating until we catch up
00354                 {
00355                         DWORD prevElapsed = elapsed;
00356                         updateInput();                  
00357 
00358                         checkSysKeys();
00359                         (AS.updateFunc)();
00360                         AS.updateCount++;
00361                         AS.idealMS += 16;
00362                         thisMS  = sys_getMilliSec();
00363                         elapsed = thisMS - AS.idealMS;
00364                         if(elapsed >= prevElapsed)
00365                         {
00366                                 sys_console() << "WARNING Update is slower than 62.5Hz" << endl;
00367                                 DWORD timeTaken = 16 + elapsed - prevElapsed;
00368                                 if(timeTaken) sys_console() << "WARNING Update() is taking " << timeTaken << " ms" << endl;
00369                         }                       
00370                         
00371                         handleSystemMessages();
00372                 }               
00373                 profiler_end("sys_update");
00374 
00375                 profiler_begin("sys_render");
00376                 if( AS.renderNumber++ % (1+AS.skipRate) == 0 )
00377                 {                                                                                       // rendering
00378                         AS.renderCount++;
00379                         flushRenderRequests();                  
00380                         (AS.renderFunc)();
00381                         beginRendering();
00382                         processRenderRequests();
00383                         endRendering();                 
00384                 }
00385                 profiler_end("sys_render");
00386 
00387                 thisMS  = sys_getMilliSec();
00388                 elapsed = thisMS - AS.idealMS;
00389                 handleSystemMessages();
00390 
00391                 profiler_begin("sys_sleep");
00392                 if(elapsed<UPDATE_INTERVAL)                                     // block if we are going too fast
00393                 {
00394                         AS.excessCount += 16-elapsed;
00395                         Sleep(16-elapsed);
00396                         while(elapsed<UPDATE_INTERVAL)
00397                         {
00398                                 thisMS = sys_getMilliSec();
00399                                 elapsed = thisMS - AS.idealMS;
00400                                 if( elapsed<1  ) elapsed = 1;
00401                                 if( elapsed>100) elapsed = 100;                                 
00402                         }                               
00403                 }
00404                 profiler_end("sys_sleep");
00405 
00406                 handleSystemMessages();
00407         }
00408 }

void drawConsole  
 

Definition at line 218 of file ASys.cpp.

References MAX_CONSOLE_LINES, overlay_rect(), overlay_text(), overlay_textOut(), and Vec2D.

Referenced by processRenderRequests().

00219 {
00220         istringstream in(AS.pConsoleStream->str());
00221         string line;
00222         
00223         while(in)                                       // read stuffs from console stream and store in line array
00224         {
00225                 getline( in, line );
00226                 if(line!="" || in)
00227                 {
00228                         AS.consoleLineIndex = (AS.consoleLineIndex+1) % MAX_CONSOLE_LINES;
00229                         AS.consoleLines[ AS.consoleLineIndex ] = line;
00230                         if(AS.pConsoleLogFile) (*AS.pConsoleLogFile) << line << endl;
00231                 }
00232         }
00233 
00234         delete AS.pConsoleStream;
00235         AS.pConsoleStream = new ostringstream;
00236 
00237         // draw blue background box and red border
00238         if(!AS.showConsole) return;
00239         overlay_rect( Vec2D(0.0f,0.0f), Vec2D(0.5f,1.0f), true, Colors::blue, BlendModes::MIX, 0.4f );
00240         overlay_rect( Vec2D(0.0f,0.0f), Vec2D(0.5f,0.999f), false, Colors::red );
00241                 
00242         for( int i=0; i<MAX_CONSOLE_LINES; i++ )                // draw all lines
00243         {
00244                 int lineIndex = (AS.consoleLineIndex+1+i) % MAX_CONSOLE_LINES;
00245                 overlay_text() << AS.consoleLines[lineIndex];
00246                 overlay_textOut( Vec2D(0.005f, i*0.033f) );             
00247         }
00248 }

void drawFPS  
 

Definition at line 252 of file ASys.cpp.

References overlay_text(), overlay_textOut(), and Vec2D.

Referenced by processRenderRequests().

00253 {
00254         if(!AS.showFPS) return;
00255         char s[256];
00256         sprintf( s, "update %6.2f\nrender %6.2f\n excess %8.2f\n", AS.updateRate, AS.renderRate, AS.excessRate );
00257         overlay_text() << s;
00258         overlay_textOut( Vec2D(0.82f,0.0f) );
00259 }

void endRendering  
 

Definition at line 211 of file ASys.cpp.

Referenced by displayLoadingScreen(), and doGameLoop().

00212 {
00213         AS.pDevice->EndScene();
00214         AS.pDevice->Present(NULL,NULL,NULL,NULL);
00215 }

void findCompatibleMode D3DDISPLAYMODE &    d3dDisplayMode
 

Definition at line 432 of file ASys.cpp.

Referenced by createRenderingDevice().

00433 {
00434         int modeCount = AS.pD3D->GetAdapterModeCount(D3DADAPTER_DEFAULT);
00435         bool foundGoodMode = false;
00436         for( int i=0; i<modeCount; i++ )
00437         {
00438                 AS.pD3D->EnumAdapterModes( D3DADAPTER_DEFAULT, i, &d3dDisplayMode );
00439                 D3DFORMAT format = d3dDisplayMode.Format;
00440                 if( d3dDisplayMode.Width==AS.windowWidth && d3dDisplayMode.Height==AS.windowHeight
00441                                                                  && d3dDisplayMode.RefreshRate>=40 )
00442                         if( format==D3DFMT_A8R8G8B8 || format==D3DFMT_A4R4G4B4 || format==D3DFMT_R5G6B5 || format==D3DFMT_R8G8B8 )
00443                         {
00444                                 foundGoodMode = true;
00445                                 i = modeCount;                  // Break the loop
00446                         }                       
00447         }
00448         if(!foundGoodMode) throw Error("Cant't Find Compatible Display Mode");
00449 }

void flushRenderRequests  
 

Definition at line 281 of file ASys.cpp.

References mesh_flush(), overlay_flush(), sprite_flush(), and terrain_flush().

Referenced by doGameLoop().

00282 {
00283         overlay_flush();
00284         mesh_flush();
00285         terrain_flush();
00286         sprite_flush();
00287 }

void handleSystemMessages  
 

Definition at line 85 of file ASys.cpp.

Referenced by doGameLoop().

00086 {
00087         MSG msg; 
00088         while(PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))    
00089     {
00090                 TranslateMessage( &msg );
00091         DispatchMessage( &msg );
00092         }
00093 }

void processRenderRequests  
 

Definition at line 289 of file ASys.cpp.

References drawConsole(), drawFPS(), flare_process(), mesh_processRenderRequests(), overlay_render(), sprite_process(), and terrain_processRenderRequest().

Referenced by doGameLoop().

00290 {
00291         mesh_processRenderRequests();
00292         terrain_processRenderRequest();
00293         sprite_process();
00294         flare_process();
00295         
00296         drawConsole();
00297         drawFPS();
00298         overlay_render();
00299 }

ostream& sys_console  
 

this returns you an output stream that you can write stuffs to they will be displayed on the in-game console window if it is set to visible

Definition at line 629 of file ASys.cpp.

Referenced by NetworkData::addData(), Globals::MessagesReceived::addMessage(), City::deleteJetGuard(), BattleGroup::destroyUnit(), doGameLoop(), BattleGroup::fire(), getGameTick(), BattleEntry::initBattle(), BattleEntry::isBattleFinished(), NetworkSubsystem::loadNetworkData(), mesh_init(), net_connectToServer(), net_recv(), Overhead::overhead_init(), Overhead::overhead_update(), Helper::playerColorToPlayerNumber(), Overhead::playerStrength(), Overhead::printAllMilitaryUnits(), NetworkSubsystem::processNetworkData(), BattleEntry::processQueuedInput(), profiler_render(), NetworkSubsystem::receiveNetworkData(), terrain_getHeight(), City::update(), and Overhead::updateBattleEntries().

00630 {       
00631         assert(AS.pConsoleStream);
00632         return *(AS.pConsoleStream);
00633 }

void sys_enableConsoleLog string    filename
 

this function must be called before sys_go(); this will log all subsequent output to the console to the specified logfile

Definition at line 617 of file ASys.cpp.

Referenced by main_init().

00618 {
00619         // make sure we wipe out all previous content in the file if it already exists
00620         AS.pConsoleLogFile = new ofstream(filename.c_str());
00621         (*AS.pConsoleLogFile) << "Clear Log" << endl;
00622         AS.pConsoleLogFile->close();
00623         delete AS.pConsoleLogFile;
00624 
00625         // open up the file for writting
00626         AS.pConsoleLogFile = new ofstream(filename.c_str());
00627 }

void sys_fastForwardUpdate int    times
 

quickly update the game state 'times' times. this is quivalent to fast forwarding the game by roughly 'times'/62.5 seconds

Definition at line 656 of file ASys.cpp.

Referenced by Overhead::overhead_render().

00657 {
00658         assert(times>=0 && times<1000);
00659         AS.fastForwardAmount = times;   
00660 }

void sys_flushConsole  
 

flushes all texts sent to consol eto log file (if any)

Definition at line 635 of file ASys.cpp.

References MAX_CONSOLE_LINES.

Referenced by NetworkData::addData(), City::deleteJetGuard(), getGameTick(), NetworkSubsystem::processNetworkData(), BattleEntry::processQueuedInput(), NetworkSubsystem::receiveNetworkData(), and sys_terminate().

00636 {
00637         if(!AS.pConsoleLogFile) return;
00638 
00639         istringstream in(AS.pConsoleStream->str());
00640         string line;    
00641         while(in)
00642         {
00643                 getline( in, line );
00644                 if(line!="" || in)
00645                 {
00646                         AS.consoleLineIndex = (AS.consoleLineIndex+1) % MAX_CONSOLE_LINES;
00647                         AS.consoleLines[ AS.consoleLineIndex ] = line;
00648                         (*AS.pConsoleLogFile) << line << endl;
00649                 }
00650         }
00651 
00652         delete AS.pConsoleStream;
00653         AS.pConsoleStream = new ostringstream();
00654 }

DWORD sys_getMilliSec  
 

get current time in ms

Definition at line 662 of file ASys.cpp.

References DWORD.

Referenced by doGameLoop(), Typer::input(), and profiler_reset().

00663 {
00664         LARGE_INTEGER                   tick;
00665         static LARGE_INTEGER    freq    = {0};  
00666         static bool                             inited  = false;
00667         if (!inited)
00668         {
00669                 inited = true;
00670                 QueryPerformanceFrequency( &freq );
00671         }
00672         QueryPerformanceCounter( &tick );
00673         return (DWORD)((tick.QuadPart * 1000) / freq.QuadPart);
00674 }

HWND sys_getWindowHandle  
 

Definition at line 707 of file ASys.cpp.

00708 {
00709         return AS.hWnd;
00710 }

void sys_go  
 

let the program runs. This function doesn't return (until sys_terminate())

Definition at line 534 of file ASys.cpp.

References createRenderingDevice(), createWindow(), displayLoadingScreen(), doGameLoop(), flare_init(), input_init(), MAX_LOCAL_RANDON_FLOAT, MAX_LOCAL_RANDON_NUM, mesh_init(), overlay_init(), sprite_init(), sys_randFloat(), sys_shutdown(), and Vec2D.

Referenced by WinMain().

00535 {
00536         createWindow();
00537         createRenderingDevice();
00538 
00539         // init all major components
00540         input_init();
00541         overlay_init(); 
00542 
00543         // init all sub components
00544         // init console
00545         AS.showConsole = true;
00546         AS.showFPS     = false;
00547         AS.pConsoleStream = new ostringstream();
00548         AS.consoleLineIndex = 0;
00549 
00550         AS.camera_screenSize = 1.0f;
00551         AS.camera_vibratePos = 0.0f;
00552         AS.camera_vibrateSpeed = 0.0f;
00553 
00554         AS.input_mouseIdleTickCount = 0;
00555         AS.input_lastTickMousePos = Vec2D(0,0);
00556 
00557         // init game loop control counters
00558         AS.lastCountResetMS = 0;
00559         AS.updateCount = 0;
00560         AS.updateRate  = 0;
00561         AS.renderCount = 0;
00562         AS.renderRate  = 0;
00563         AS.excessCount = 0;
00564         AS.excessRate  = 0;
00565         AS.renderNumber = 0;
00566         AS.fastForwardAmount = 0;
00567 
00568         // specific to this game
00569         displayLoadingScreen();
00570 
00571         // networking
00572         AS.net_isInit = false;
00573 
00574         for(int i=0; i<MAX_LOCAL_RANDON_NUM; i++)                                       // local random number generator
00575                 AS.res_localRandomNums.push_back( rand()%256 );
00576         for(int i=0; i<MAX_LOCAL_RANDON_FLOAT; i++ )
00577                 AS.res_localRandomFloats.push_back( sys_randFloat() );
00578         AS.res_localRandomNumIndex = 0;
00579         AS.res_localRandomFloatIndex = 0;
00580 
00581         // user-defined initialization
00582         (AS.initFunc)();
00583 
00584         mesh_init();
00585         flare_init();
00586         sprite_init();
00587 
00588         // Let it all go
00589         try
00590         {
00591                 doGameLoop();
00592         }
00593         catch(TerminateNormally e)
00594         {
00595                 sys_shutdown();
00596                 if(AS.shutdownFunc) (AS.shutdownFunc)();
00597                 return;
00598         }
00599 }

void sys_init HINSTANCE    hInst,
int    width,
int    height,
int    colorDepth,
bool    fullScreen
 

setup the AEngine. You should call this before doing anything else hInst is passed to you by WinMain. Just pass it along to this function note that not all modes can be supported by your video card try standard things such as 800x600x16bit or 1024x768x32bit

Definition at line 35 of file ASys.cpp.

References Vec3D.

Referenced by WinMain().

00036 {       
00037         AS.hInst = hInst;
00038         AS.windowWidth  = width;
00039         AS.windowHeight = height;
00040         AS.colorDepth   = colorDepth;
00041         AS.isFullScreen = fullScreen;
00042         AS.initFunc   = NULL;
00043         AS.updateFunc = NULL;
00044         AS.renderFunc = NULL;
00045         AS.shutdownFunc = NULL;
00046         AS.pConsoleLogFile = NULL;
00047         AS.vshader_terrain = NULL;
00048 
00049         AS.camera_pos    = Vec3D( 3.0f, 0.0f, 3.0f );
00050         AS.camera_target = Vec3D( 0.0f, 0.0f, 0.0f );
00051         D3DXMatrixIdentity(& (AS.camera_world2projMatrix) );
00052         AS.skipRate = 0;
00053 
00054         //unsigned int newFlags = _RC_DOWN | _PC_64;
00055         //unsigned int mask             = _MCW_RC | _MCW_PC;
00056         //_controlfp(newFlags,mask);
00057 }

FLOAT sys_localRandFloat  
 

Definition at line 701 of file ASys.cpp.

References MAX_LOCAL_RANDON_FLOAT.

Referenced by Overhead::overheadRender().

00702 {
00703         AS.res_localRandomFloatIndex = (AS.res_localRandomFloatIndex + 1) % MAX_LOCAL_RANDON_FLOAT;
00704         return AS.res_localRandomFloats[ AS.res_localRandomFloatIndex ];
00705 }

int sys_localRandInt  
 

Definition at line 695 of file ASys.cpp.

References MAX_LOCAL_RANDON_NUM.

Referenced by Overhead::overheadRender(), Sound::playRandomSound(), playVoiceContact(), playVoicePanick(), and playVoiceStress().

00696 {
00697         AS.res_localRandomNumIndex = (AS.res_localRandomNumIndex + 1) % MAX_LOCAL_RANDON_NUM;
00698         return AS.res_localRandomNums[ AS.res_localRandomNumIndex ];
00699 }

FLOAT sys_randFloat  
 

Definition at line 690 of file ASys.cpp.

Referenced by Globals::ArtWork::ArtWork(), BattleGroup::destroyUnit(), BattleJets::fireAntiAirMissiles(), BattleJets::fireAntiSurfaceMissiles(), BattleJets::flyTo(), MilitaryUnit::move(), sys_go(), and BattleJets::takeHit().

00691 {
00692         return (rand()&0x0ff) / 128.0f - 1.0f;
00693 }

int sys_randInt  
 

Definition at line 685 of file ASys.cpp.

Referenced by Globals::ArtWork::ArtWork(), City::changeOwner(), BattleGroup::destroyUnit(), BattleGroup::fire(), BattleGroup::fireAntiAir(), BattleJets::fireAntiAirMissiles(), BattleJets::fireAntiSurfaceMissiles(), Jet::move(), NetworkSubsystem::processNetworkData(), BattleJets::takeHit(), BattleEntry::updateDebris(), and updateMultiplayMenu().

00686 {
00687         return rand();
00688 }

void sys_setInitFunc AierraInitFunc    f
 

set call-back functions so the engine knows how to init, update the game state, render it, and shut down

Definition at line 64 of file ASys.cpp.

Referenced by WinMain().

00065 {
00066         AS.initFunc = f;
00067 }

void sys_setRandSeed int    seed
 

use these functions instead of the builtin rand, srand so we can log and keep track of what's going on

Definition at line 678 of file ASys.cpp.

References MAX_LOCAL_RANDON_FLOAT, and MAX_LOCAL_RANDON_NUM.

Referenced by processIncomingMessages().

00679 {
00680         srand( (unsigned int)seed );
00681         AS.res_localRandomNumIndex = seed % MAX_LOCAL_RANDON_NUM;
00682         AS.res_localRandomFloatIndex = seed % MAX_LOCAL_RANDON_FLOAT;
00683 }

void sys_setRenderFunc AierraRenderFunc    f
 

Definition at line 74 of file ASys.cpp.

Referenced by WinMain().

00075 {
00076         AS.renderFunc = f;
00077 }

void sys_setShutdownFunc AierraShutdownFunc    f
 

Definition at line 79 of file ASys.cpp.

Referenced by WinMain().

00080 {
00081         AS.shutdownFunc = f;
00082 }

void sys_setSkipRate int    rate
 

rate=0 means try never to skip any frame. rate=1 means render every other frame

Definition at line 59 of file ASys.cpp.

Referenced by main_init().

00060 {
00061         AS.skipRate = rate;
00062 }

void sys_setUpdateFunc AierraUpdateFunc    f
 

Definition at line 69 of file ASys.cpp.

Referenced by WinMain().

00070 {
00071         AS.updateFunc = f;
00072 }

void sys_showConsole bool    show
 

whether or not to display the console window

Definition at line 612 of file ASys.cpp.

Referenced by main_init().

00613 {
00614         AS.showConsole = show;  
00615 }

void sys_showFPS bool    show
 

whether to show the frame rate in the top-right corner

Definition at line 607 of file ASys.cpp.

00608 {
00609         AS.showFPS = show;
00610 }

void sys_shutdown  
 

:

Definition at line 508 of file ASys.cpp.

References UINT.

Referenced by sys_go().

00509 {
00510         static bool shutdownAlready = false;
00511         assert(!shutdownAlready);
00512         shutdownAlready = true;
00513 
00514         delete AS.pConsoleStream;
00515         
00516         for( UINT i=0; i<AS.res_fonts.size(); i++ )  delete AS.res_fonts[i];            // fonts
00517 
00518         delete AS.overlay_pTextStream;
00519 
00520         delete AS.pConsoleLogFile;
00521 
00522 }

void sys_terminate  
 

terminate the application. This function never returns

Definition at line 601 of file ASys.cpp.

References sys_flushConsole().

Referenced by Overhead::overhead_update(), and updateMainMenu().

00602 {
00603         sys_flushConsole();
00604         throw TerminateNormally();
00605 }

void updateInput  
 

Definition at line 96 of file ASys.cpp.

References input_getMouseX(), input_getMouseY(), MAX_KEY, and Vec2D.

Referenced by doGameLoop().

00097 {
00098         NDX_Input &N = AS.ndxInput;
00099 
00100         // update mouse
00101         DIMOUSESTATE mouseState;
00102         if( N.lpDIDMouse->GetDeviceState(sizeof(mouseState),&mouseState) != DI_OK )
00103                 N.lpDIDMouse->Acquire();
00104 
00105         N.MouseX=mouseState.lX;
00106         N.MouseY=mouseState.lY;
00107         N.MouseXPos+=N.MouseX;
00108         N.MouseYPos+=N.MouseY;
00109         if(N.MouseXPos<N.MouseLimit.left)               N.MouseXPos=N.MouseLimit.left;
00110         if(N.MouseXPos>N.MouseLimit.right-1)    N.MouseXPos=N.MouseLimit.right-1;
00111         if(N.MouseYPos<N.MouseLimit.top)                N.MouseYPos=N.MouseLimit.top;
00112         if(N.MouseYPos>N.MouseLimit.bottom-1)   N.MouseYPos=N.MouseLimit.bottom-1;
00113         AS.input_mouseWheel += ((FLOAT)(mouseState.lZ)) / 1500.0f;
00114         if( AS.input_mouseWheel > 1.0f ) AS.input_mouseWheel = 1.0f;
00115         if( AS.input_mouseWheel < 0.0f ) AS.input_mouseWheel = 0.0f;
00116 
00117                 N.MouseLBClick = !N.MouseLB && mouseState.rgbButtons[0];
00118                 N.MouseRBClick = !N.MouseRB && mouseState.rgbButtons[1];
00119                 N.MouseMBClick = !N.MouseMB && mouseState.rgbButtons[2];
00120         N.MouseLB = (mouseState.rgbButtons[0]) != 0;
00121         N.MouseRB = (mouseState.rgbButtons[1]) != 0;
00122         N.MouseMB = (mouseState.rgbButtons[2]) != 0;
00123         N.MouseLBDblClick = false;
00124         N.MouseMBDblClick = false;
00125         N.MouseRBDblClick = false;
00126         if(N.MouseLBClick)
00127         {
00128             if( (GetTickCount() - N.m_dwDoubleClickTimeLB) < N.m_dwDoubleClickDelay)         
00129                 N.MouseLBDblClick = true;
00130             else
00131                 N.m_dwDoubleClickTimeLB = GetTickCount();
00132         }
00133 
00134         if(N.MouseMBClick)
00135         {
00136             if( (GetTickCount() - N.m_dwDoubleClickTimeMB) < N.m_dwDoubleClickDelay)
00137                 N.MouseMBDblClick = true;
00138             else
00139                 N.m_dwDoubleClickTimeMB = GetTickCount();
00140         }
00141 
00142         if(N.MouseRBClick)
00143         {
00144             if( (GetTickCount() - N.m_dwDoubleClickTimeRB) < N.m_dwDoubleClickDelay)
00145                 N.MouseRBDblClick = true;
00146             else
00147                 N.m_dwDoubleClickTimeRB = GetTickCount();            
00148         }
00149         
00150         // update keyboard
00151         if( N.lpDIDKeys->GetDeviceState(256,&N.Keys) != DI_OK )
00152                 N.lpDIDKeys->Acquire();
00153         for( int i=0; i<MAX_KEY; i++ )
00154         {
00155                 AS.keyDownLastCycle[i] = AS.keyDownThisCycle[i];
00156                 AS.keyDownThisCycle[i] = N.Keys[i] != 0;
00157         }
00158 
00159         // mouse idle
00160         Vec2D thisMouse( input_getMouseX(), input_getMouseY() );
00161         if( thisMouse != AS.input_lastTickMousePos )
00162         {
00163                 AS.input_lastTickMousePos = thisMouse;
00164                 AS.input_mouseIdleTickCount = 0;
00165         }
00166         else
00167         {
00168                 AS.input_mouseIdleTickCount++;
00169         }
00170         
00171 }


Variable Documentation

const int UPDATE_INTERVAL = 1000/UPDATE_RATE
 

Definition at line 32 of file ASys.cpp.

Referenced by doGameLoop().

const int UPDATE_RATE = 60
 

Definition at line 31 of file ASys.cpp.


Generated on Wed Apr 23 05:50:36 2003 for Modern Warfare by doxygen1.3-rc2