Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

GameMgr.c

Go to the documentation of this file.
00001 /****************************************************************************************/
00002 /*  GameMgr.c                                                                           */
00003 /*                                                                                      */
00004 /*  Author: John Pollard                                                                */
00005 /*  Description:                                                                        */
00006 /*                                                                                      */
00007 /*  Copyright (c) 1997, 1999, Eclipse Entertainment; All rights reserved.               */
00008 /*                                                                                      */
00009 /*  See the accompanying file LICENSE.TXT for terms on the use of this library.         */
00010 /*  This library is distributed in the hope that it will be useful but WITHOUT          */
00011 /*  ANY WARRANTY OF ANY KIND and without any implied warranty of MERCHANTABILITY        */
00012 /*  or FITNESS FOR ANY PURPOSE.  Refer to LICENSE.TXT for more details.                 */
00013 /*                                                                                      */
00014 /****************************************************************************************/
00015 #include <Windows.h>
00016 #include <Assert.h>
00017 #include <stdio.h>
00018 #include <direct.h>
00019 
00020 #include "Ram.h"
00021 #include "Errorlog.h"
00022 
00023 #include "GameMgr.h"
00024 
00025 #include "Procedurals\gebmutil.h"
00026 #include "procedurals/ProcEng.h"
00027 
00028 
00029 extern void     GenVS_Error(const char *Msg, ...);
00030 
00031 extern geVFile *MainFS;
00032 
00033 
00034 //====================================================================================
00035 //      Misc defs
00036 //====================================================================================
00037 static HWND CreateMainWindow(HANDLE hInstance, const char *AppName, int32 Width, int32 Height);
00038 
00039 //====================================================================================
00040 //      Structure defs
00041 //====================================================================================
00042 typedef struct
00043 {
00044         geWorld                         *World;                                                         // World pointer for this world data set
00045         char                            WorldName[GAMEMGR_MAX_WORLD_NAME];
00046 
00047         int32                           NumModels;
00048         geWorld_Model           *Models[GAMEMGR_MAX_MODELS];
00049 
00050 } GameMgr_WorldInfo;
00051 
00052 // The GameMgr object
00053 typedef struct GameMgr
00054 {
00055         GameMgr                         *SelfCheck1;                                            // Head self valid check
00056 
00057         float                           Time;
00058 
00059         // Objects the the game mgr maintains...
00060         geEngine                        *Engine;                                                        // Engine object
00061         geSound_System          *SoundSys;                                                      // Soundsystem object
00062         Console_Console         *Console;
00063 
00064         HWND                            hWnd;
00065 
00066         GameMgr_FrameState      FrameState;
00067         Fx_System                       *FxSystem;
00068         geBitmap                        *ShadowMap;
00069 
00070 
00071         GameMgr_WorldInfo       WorldInfo[GAMEMGR_MAX_WORLDS];
00072 
00073         // Mode specific stuff
00074         VidMode                         VidMode;                                                        // Current VidMode
00075         geCamera                        *Camera;
00076 
00077         GameMgr_ActorIndex              ActorIndex[GAMEMGR_MAX_ACTOR_INDEX];
00078         GameMgr_MotionIndexDef  MotionIndexDefs[GAMEMGR_MAX_MOTION_INDEX];
00079         GameMgr_BoneIndex               BoneIndex[GAMEMGR_MAX_BONE_INDEX];
00080         GameMgr_TextureIndex    TextureIndex[GAMEMGR_MAX_TEXTURE_INDEX];
00081         GameMgr_SoundIndex              SoundIndex[GAMEMGR_MAX_SOUND_INDEX];
00082 
00083         ProcEng                         *ProcEng;
00084 
00085         GameMgr                         *SelfCheck2;                                            // Tail self valid check
00086 } GameMgr;
00087 
00088 //====================================================================================
00089 //      GameMgr_FreeAllObjects
00090 //====================================================================================
00091 void GameMgr_FreeAllObjects(GameMgr *GMgr)
00092 {
00093         assert(GMgr);
00094 
00095         if (GMgr->Camera)
00096                 geCamera_Destroy(&GMgr->Camera);
00097 
00098         GameMgr_FreeWorld(GMgr);                // Make sure no old world is laying around
00099         
00100         if (GMgr->FxSystem)
00101                 Fx_SystemDestroy(GMgr->FxSystem);
00102 
00103         if (GMgr->Console)
00104                 Console_Destroy(GMgr->Console);
00105 
00106         if (GMgr->SoundSys)
00107                 geSound_DestroySoundSystem(GMgr->SoundSys);
00108 
00109         if (GMgr->Engine)
00110                 geEngine_Free(GMgr->Engine);
00111 
00112         GMgr->FxSystem  = NULL;
00113         GMgr->Engine    = NULL;
00114         GMgr->Console   = NULL;
00115         GMgr->SoundSys  = NULL;
00116         GMgr->Camera    = NULL;
00117 
00118         geRam_Free(GMgr);                               // Free the manager itself...
00119 }
00120 
00121 //====================================================================================
00122 //      GameMgr_Create
00123 //====================================================================================
00124 GameMgr *GameMgr_Create(HINSTANCE hInstance, int32 Width, int32 Height, const char *AppName)
00125 {
00126         GameMgr *GMgr;
00127         char    PathBuf[_MAX_PATH];
00128 
00129         assert(AppName);
00130 
00131         // Allocate the GameMgr structure
00132         GMgr = GE_RAM_ALLOCATE_STRUCT(GameMgr);
00133 
00134         if (!GMgr)
00135         {
00136                 geErrorLog_AddString(-1, "GameMgr_Create:  Out of memory for GameMgr.", NULL);
00137                 return NULL;
00138         }
00139 
00140         // Zero out memory
00141         memset(GMgr, 0, sizeof(GameMgr));
00142 
00143         // Save self check flags
00144         GMgr->SelfCheck1 = GMgr;
00145         GMgr->SelfCheck2 = GMgr;
00146 
00147         // Create the window
00148         GMgr->hWnd = CreateMainWindow(hInstance, AppName, Width, Height);
00149         
00150         // Create an engine object
00151         if (_getcwd(PathBuf,_MAX_PATH)==NULL)
00152                 {
00153                         geErrorLog_AddString(-1, "GameMgr_Create:  Could not get current working directory.", NULL);
00154                         goto ExitWithError;
00155                 }
00156         GMgr->Engine = geEngine_Create(GMgr->hWnd, AppName, PathBuf);
00157         
00158         if (!GMgr->Engine)
00159         {
00160                 geErrorLog_AddString(-1, "GameMgr_Create:  Could not create the geEngine object.", NULL);
00161                 goto ExitWithError;
00162         }
00163 
00164         #ifdef _DEBUG
00165         geXForm3d_SetMaximalAssertionMode(GE_FALSE);
00166         #endif
00167         
00168         //
00169         // Create the sound system
00170         //
00171         GMgr->SoundSys = geSound_CreateSoundSystem(GMgr->hWnd);
00172 
00173         if (!GMgr->SoundSys)
00174         {
00175                 geErrorLog_AddString(-1, "GameMgr_Create:  Could not create the geSound_System object. (continuing)", NULL);
00176                 //goto ExitWithError;
00177         }
00178 
00179         GMgr->ProcEng = NULL;
00180 
00181         return GMgr;
00182 
00183         ExitWithError:
00184         {
00185                 if (GMgr)
00186                         GameMgr_FreeAllObjects(GMgr);
00187 
00188                 return NULL;
00189         }
00190 }
00191 
00192 //====================================================================================
00193 //      GameMgr_Destroy
00194 //====================================================================================
00195 void GameMgr_Destroy(GameMgr *GMgr)
00196 {
00197         assert(GMgr);
00198         assert(GameMgr_IsValid(GMgr) == GE_TRUE);
00199 
00200         GameMgr_FreeAllObjects(GMgr);
00201 }
00202 
00203 /*
00204 static  int32   WaterPosX = 2, WaterPosY = 64;
00205 static  int32   NPage;
00206 static  float   TimeToSplashWater = 0.0f;
00207 
00208 static  uint8   OriginalBits[256*256];
00209 static  int16   WaterData[2][256*256];
00210 
00211 //static        uint8   Blend
00212 
00213 void CalcRippleData(int16 *Src, int16 *Dest, int16 Density, int32 W, int32 H)
00214 {
00215         int32   i,j;
00216         int16   Val;
00217 
00218         for(i=0; i< H; i++)
00219         {
00220                 for(j=0; j< W; j++)
00221                 {
00222                         if (i > 0)                                                      // Get top
00223                                 Val = *(Dest - W);
00224                         else
00225                                 Val = *(Dest + W * (H-1));
00226 
00227                         if (i < H-1)                                            // Get bottom
00228                                 Val += *(Dest + W);
00229                         else
00230                                 Val += *(Dest - W * (H-1));
00231 
00232                         if (j > 0)                                                      // Get left
00233                                 Val += *(Dest - 1);
00234                         else
00235                                 Val += *(Dest + (W-1));
00236 
00237                         if (j < W-1)                                            // Get right
00238                                 Val += *(Dest + 1);
00239                         else
00240                                 Val += *(Dest - (W-1));
00241 
00242                         Val >>= 1;
00243                         Val -= *Src;
00244                         Val -= (Val >> Density);
00245 
00246                         *Src = Val;
00247 
00248                         Src++;
00249                         Dest++;
00250 
00251                 }
00252         }
00253 }
00254 
00255 void UpdateWaterTable(int32 Width, int32 Height, float Time)
00256 {
00257         int16           *Page1, *Page2, *Page3;
00258 
00259         Page1 = WaterData[NPage];
00260         Page2 = WaterData[!NPage];
00261 
00262         Page3 = Page2;
00263 
00264         TimeToSplashWater += Time;
00265 
00266         if (TimeToSplashWater > 0.5f)
00267         {
00268                 int32   px, py, cx, cy, c;
00269                 
00270                 TimeToSplashWater = 0.0f;
00271                 
00272                 for (c=0; c< 2; c++)
00273                 {
00274                         px=(1+(rand()%(Width-1-3)));
00275                         py=(1+(rand()%(Height-1-3)));
00276 
00277                         for(cy=py; cy< (py+3); cy++)
00278                                 for(cx=px; cx< (px+3); cx++)
00279                                         WaterData[!NPage][cy * Width + cx]=128;
00280                 }
00281         }
00282 
00283         CalcRippleData(Page1, Page2, 4, Width, Height);
00284 
00285         NPage = !NPage;
00286 }
00287 */
00288 
00289 //====================================================================================
00290 //      GameMgr_Frame
00291 //====================================================================================
00292 geBoolean GameMgr_Frame(GameMgr *GMgr, float Time)
00293 {
00294         assert(GameMgr_IsValid(GMgr) == GE_TRUE);
00295 
00296         if (Time < 0.001f)
00297                 Time = 0.001f;
00298         
00299         if (Time > 0.1f)
00300                 Time = 0.1f;
00301         
00302         GMgr->Time += Time;
00303 
00304         //
00305         //      Do an fx system frame
00306         //
00307         if (GMgr->FxSystem)
00308         {
00309                 if (!Fx_SystemFrame(GMgr->FxSystem, Time))
00310                         GenVS_Error("GameMgr_Frame:  Fx_SystemFrame failed.\n");
00311         }
00312 
00313         if (GMgr->ProcEng)
00314         {
00315                 if (!ProcEng_Animate(GMgr->ProcEng, Time))
00316                         GenVS_Error("GameMgr_Frame:  ProcEng_Animate failed.\n");
00317         }
00318 
00319         return GE_TRUE;
00320 }
00321 
00322 //====================================================================================
00323 //      GameMgr_IsValid
00324 //====================================================================================
00325 geBoolean GameMgr_IsValid(GameMgr *GMgr)
00326 {
00327         if (!GMgr)
00328         {
00329                 geErrorLog_AddString(-1, "GameMgr_IsValid:  The GameMgr object passed was NULL.", NULL);
00330                 return GE_FALSE;
00331         }
00332 
00333         if (GMgr->SelfCheck1 != GMgr)                   // Check head of struct
00334         {
00335                 geErrorLog_AddString(-1, "GameMgr_IsValid:  SelfCheck1 is invalid.", NULL);
00336                 return GE_FALSE;
00337         }
00338 
00339         if (GMgr->SelfCheck2 != GMgr)                   // Check tail of struct
00340         {
00341                 geErrorLog_AddString(-1, "GameMgr_IsValid:  SelfCheck2 is invalid.", NULL);
00342                 return GE_FALSE;
00343         }
00344 
00345         if (!GMgr->Engine)
00346         {
00347                 geErrorLog_AddString(-1, "GameMgr_IsValid:  Engine is NULL.", NULL);
00348                 return GE_FALSE;
00349         }
00350 
00351         return GE_TRUE;
00352 }
00353 
00354 //====================================================================================
00355 //      GameMgr_PrepareToChangeMode
00356 //====================================================================================
00357 void GameMgr_PrepareToChangeMode(GameMgr *GMgr)
00358 {
00359         assert(GameMgr_IsValid(GMgr) == GE_TRUE);
00360 
00361         if (GMgr->Camera)
00362                 geCamera_Destroy(&GMgr->Camera);
00363         GMgr->Camera = NULL;
00364 
00365         if (GMgr->Console)
00366                 Console_Destroy(GMgr->Console);
00367         GMgr->Console = NULL;
00368 }
00369 
00370 //====================================================================================
00371 //      GameMgr_SetDriverAndMode
00372 //====================================================================================
00373 geBoolean GameMgr_SetDriverAndMode(GameMgr *GMgr, geDriver *Driver, geDriver_Mode *DriverMode, int Width, int Height)
00374 {
00375         geRect          CameraRect = {0, 0, 0, 0};
00376 
00377         assert(GameMgr_IsValid(GMgr) == GE_TRUE);
00378 
00379         if (VidMode_SetResolution(&(GMgr->VidMode),Width,Height)==GE_FALSE)
00380                 GenVS_Error("GameMgr_SetDriverAndMode:  VidMode_SetResolution failed.\n");
00381 
00382         // Make the camera be a good default value...
00383         CameraRect.Left = 0;
00384         CameraRect.Right = Width-1;
00385         CameraRect.Top = 0;
00386         CameraRect.Bottom = Height-1;
00387 
00388         //
00389         // Then create a camera for client, etc to use for rendering, etc...
00390         //
00391         GMgr->Camera = geCamera_Create(2.0f, &CameraRect);
00392 
00393         if (!GMgr->Camera)
00394                 GenVS_Error("GameMgr_SetDriverAndMode:  geCamera_Create failed.\n");
00395 
00396         // Set the camera ZScale
00397 //      geCamera_SetZScale(GMgr->Camera, 0.5f);
00398         geCamera_SetZScale(GMgr->Camera, 1.0f);
00399 
00400         //
00401         // Create the console with the new vid mode...
00402         //
00403         GMgr->Console = Console_Create(GMgr->Engine, GMgr->VidMode);
00404 
00405         if (!GMgr->Console)
00406                 GenVS_Error("GameMgr_SetDriverAndMode:  Console_Create failed.\n");
00407 
00408         Console_Printf(GMgr->Console, "Console Created...\n");
00409 
00410         return GE_TRUE;
00411 }
00412 
00413 //====================================================================================
00414 //      GameMgr_BeginFrame
00415 //====================================================================================
00416 geBoolean GameMgr_BeginFrame(GameMgr *GMgr, geWorld *World, geBoolean ClearScreen)
00417 {
00418         geEngine        *Engine;
00419         geCamera        *Camera;
00420 
00421         assert(GameMgr_IsValid(GMgr) == GE_TRUE);
00422 
00423         if (GMgr->FrameState != FrameState_None)
00424                 GenVS_Error("GameMgr_BeginFrame:  GMgr->FrameState != FrameState_None.\n");
00425 
00426         Engine = GameMgr_GetEngine(GMgr);
00427         assert(Engine);
00428 
00429         Camera = GameMgr_GetCamera(GMgr);
00430         assert(Camera);
00431 
00432         if (!geEngine_BeginFrame(Engine, Camera, ClearScreen))
00433         {
00434                 GMgr->FrameState = FrameState_None;
00435                 GenVS_Error("GameMgr_BeginFrame:  geEngine_BeginFrame failed.\n");
00436         }
00437 
00438         GMgr->FrameState = FrameState_Begin;
00439 
00440         return GE_TRUE;
00441 }
00442 
00443 //====================================================================================
00444 //      GameMgr_EndFrame
00445 //====================================================================================
00446 geBoolean GameMgr_EndFrame(GameMgr *GMgr)
00447 {
00448         geEngine        *Engine;
00449 
00450         assert(GameMgr_IsValid(GMgr) == GE_TRUE);
00451 
00452         if (GMgr->FrameState != FrameState_Begin)
00453                 GenVS_Error("GameMgr_EndFrame:  GMgr->FrameState != FrameState_Begin.\n");
00454 
00455         Engine = GameMgr_GetEngine(GMgr);
00456         assert(Engine);
00457 
00458         if (!geEngine_EndFrame(Engine))
00459         {
00460                 GMgr->FrameState = FrameState_None;
00461                 GenVS_Error("GameMgr_EndFrame:  geEngine_EndFrame failed.\n");
00462         }
00463         
00464         GMgr->FrameState = FrameState_None;
00465 
00466         return GE_TRUE;
00467 }
00468 
00469 //=====================================================================================
00470 //      GameMgr_ConsolePrintf
00471 //=====================================================================================
00472 void GameMgr_ConsolePrintf(GameMgr *GMgr, geBoolean DrawNow, const char *Str, ...)
00473 {
00474         geCamera                        *Camera;
00475         geEngine                        *Engine;
00476         GameMgr_FrameState      OldFrameState;
00477         geWorld                         *World;
00478 
00479         Engine = GameMgr_GetEngine(GMgr);
00480         assert(Engine);
00481 
00482         Camera = GameMgr_GetCamera(GMgr);
00483         assert(Camera);
00484 
00485         World = GMgr->WorldInfo[0].World;
00486         
00487         OldFrameState = GMgr->FrameState;
00488 
00489         if (DrawNow && GMgr->FrameState != FrameState_Begin)
00490         {
00491                 if (!GameMgr_BeginFrame(GMgr, World, GE_TRUE))
00492                         GenVS_Error("GameMgr_ConsolePrintf:  GameMgr_BeginFrame 1 failed.\n");
00493         }
00494 
00495         if (!Console_Printf(GMgr->Console, Str))
00496                 GenVS_Error("GameMgr_ConsolePrintf:  Console_Printf failed.\n");
00497 
00498         if (DrawNow && GMgr->FrameState != FrameState_None)
00499         {
00500                 Console_Frame(GMgr->Console, 0.0f);
00501 
00502                 if (!GameMgr_EndFrame(GMgr))
00503                         GenVS_Error("GameMgr_ConsolePrintf:  GameMgr_EndFrame failed.\n");
00504                 
00505                 if (OldFrameState != GMgr->FrameState)          // Restore old state...
00506                 {
00507                         if (!GameMgr_BeginFrame(GMgr, World, GE_TRUE))
00508                                 GenVS_Error("GameMgr_ConsolePrintf:  GameMgr_BeginFrame 3 failed.\n");
00509                 }
00510         }
00511 }
00512 
00513 //=====================================================================================
00514 //      GameMgr_ClearBackground
00515 //=====================================================================================
00516 geBoolean GameMgr_ClearBackground(GameMgr *GMgr, int32 x, int32 y, const char *Str)
00517 {
00518         geCamera                        *Camera;
00519         geEngine                        *Engine;
00520         GameMgr_FrameState      OldFrameState;
00521         geWorld                         *World;
00522 
00523         Engine = GameMgr_GetEngine(GMgr);
00524         assert(Engine);
00525 
00526         Camera = GameMgr_GetCamera(GMgr);
00527         assert(Camera);
00528 
00529         World = GMgr->WorldInfo[0].World;
00530 
00531         OldFrameState = GMgr->FrameState;
00532 
00533         if (GMgr->FrameState != FrameState_None)                // Make sure we are not in a nested begin/frame loop
00534         {
00535                 if (!GameMgr_EndFrame(GMgr))
00536                         GenVS_Error("GameMgr_ClearBackground:  GameMgr_EndFrame 1 failed.\n");
00537         }
00538         
00539         if (!GameMgr_BeginFrame(GMgr, World, GE_TRUE))
00540                 GenVS_Error("GameMgr_ClearBackground:  GameMgr_BeginFrame 1 failed.\n");
00541 
00542         if (!GameMgr_EndFrame(GMgr))
00543                 GenVS_Error("GameMgr_ClearBackground:  GameMgr_EndFrame failed.\n");
00544 
00545         if (!GameMgr_BeginFrame(GMgr, World, GE_TRUE))
00546                 GenVS_Error("GameMgr_ClearBackground:  GameMgr_BeginFrame 2 failed.\n");
00547 
00548         if (Str)
00549                 geEngine_Printf(Engine, x, y, (char*)Str);
00550 
00551         if (!GameMgr_EndFrame(GMgr))
00552                 GenVS_Error("GameMgr_ClearBackground:  GameMgr_EndFrame 2 failed.\n");
00553 
00554         if (OldFrameState != FrameState_None)           // Restore old state...
00555         {
00556                 if (!GameMgr_BeginFrame(GMgr, World, GE_TRUE))
00557                         GenVS_Error("GameMgr_ClearBackground:  GameMgr_BeginFrame 3 failed.\n");
00558         }
00559 
00560         return GE_TRUE;
00561 }
00562 
00563 //====================================================================================
00564 //      GameMgr_FreeWorld
00565 //      Clears GameMgr of all world dependent objects.
00566 //====================================================================================
00567 geBoolean GameMgr_FreeWorld(GameMgr *GMgr)
00568 {
00569         GameMgr_WorldInfo       *WInfo;
00570         int32                           i;
00571         geBoolean                       Ret;
00572 
00573         assert(GameMgr_IsValid(GMgr) == GE_TRUE);
00574 
00575         Ret = GE_TRUE;
00576         
00577         WInfo = &GMgr->WorldInfo[0];
00578 
00579         // There is nothing to fre in these arrays, so just zap them
00580         memset(GMgr->MotionIndexDefs, 0, sizeof(GMgr->MotionIndexDefs));
00581         memset(GMgr->BoneIndex, 0, sizeof(GMgr->BoneIndex));
00582 
00583         // Free all the actors
00584         for (i=0; i<GAMEMGR_MAX_ACTOR_INDEX; i++)
00585         {
00586                 GameMgr_ActorIndex              *AIndex;
00587 
00588                 AIndex = &GMgr->ActorIndex[i];
00589                 
00590                 if (AIndex->ActorDef)
00591                 {
00592                         assert(WInfo->World);
00593                         assert(AIndex->Active == GE_TRUE);
00594                         assert(AIndex->ActorHack);
00595                         
00596                         if (!geWorld_RemoveActor(WInfo->World, AIndex->ActorHack))
00597                         {
00598                                 geErrorLog_AddString(-1, "GameMgr_FreeWorld:  geWorld_RemoveActor failed.", NULL);
00599                                 Ret = GE_FALSE;
00600                         }
00601                         
00602                         geActor_Destroy(&AIndex->ActorHack);
00603 
00604                         geActor_DefDestroy(&AIndex->ActorDef);
00605                 }
00606                 
00607                 memset(AIndex, 0, sizeof(*AIndex));
00608         }
00609 
00610         // Free all the textures
00611         for (i=0; i<GAMEMGR_MAX_TEXTURE_INDEX; i++)
00612         {
00613                 GameMgr_TextureIndex *TIndex;
00614 
00615                 TIndex = &GMgr->TextureIndex[i];
00616 
00617                 if (TIndex->TextureDef)
00618                 {
00619                         assert(WInfo->World);                           // If there are bitmaps, there better be a world!!!
00620                         assert(TIndex->Active == GE_TRUE);
00621 
00622                         if (!geWorld_RemoveBitmap(WInfo->World, TIndex->TextureDef))
00623                                 Ret = GE_FALSE;
00624 
00625                         geBitmap_Destroy(&TIndex->TextureDef);
00626                 }
00627 
00628                 memset(TIndex, 0, sizeof(*TIndex));
00629         }
00630 
00631         for (i=0; i<GAMEMGR_MAX_SOUND_INDEX; i++)
00632         {
00633                 GameMgr_SoundIndex *SIndex;
00634 
00635                 SIndex = &GMgr->SoundIndex[i];
00636 
00637                 if (SIndex->SoundDef)
00638                 {
00639                         assert(GMgr->SoundSys);                         // If there are sounds, there better be a sound system!!!
00640                         assert(SIndex->Active == GE_TRUE);
00641                         geSound_FreeSoundDef(GMgr->SoundSys, SIndex->SoundDef);
00642                 }
00643                 memset(SIndex, 0, sizeof(*SIndex));
00644         }
00645 
00646         if (GMgr->FxSystem)             // YES, Fx_System depends on a world, so it must be freed now, until a new world is loaded...
00647         {
00648                 Fx_SystemDestroy(GMgr->FxSystem);
00649                 GMgr->FxSystem = NULL;
00650         }
00651 
00652         if (GMgr->ShadowMap)
00653         {
00654                 assert(WInfo->World);
00655 
00656                 geWorld_RemoveBitmap(WInfo->World, GMgr->ShadowMap);
00657                 geBitmap_Destroy( &(GMgr->ShadowMap) );
00658                 GMgr->ShadowMap = NULL;
00659         }
00660 
00661         // Free the world last, so that all data contained in the world would have been freed above...
00662         // Free any previously existing world
00663         if (WInfo->World)
00664         {
00665                 if (!Electric_Shutdown())
00666                 {
00667                         geErrorLog_AddString(-1, "GameMgr_FreeWorld:  Electric_Shutdown failed...", NULL);
00668                         Ret = GE_FALSE;
00669                 }
00670 
00671                 if (!Corona_Shutdown())
00672                 {
00673                         geErrorLog_AddString(-1, "GameMgr_FreeWorld:  Corona_Shutdown failed...", NULL);
00674                         Ret = GE_FALSE;
00675                 }
00676 
00677                 if (!geEngine_RemoveWorld(GMgr->Engine, WInfo->World))
00678                 {
00679                         geErrorLog_AddString(-1, "GameMgr_FreeWorld:  geEngine_RemoveWorld failed...", NULL);
00680                         Ret = GE_FALSE;
00681                 }
00682 
00683                 geWorld_Free(WInfo->World);
00684                 
00685                 if ( GMgr->ProcEng )
00686                         ProcEng_Destroy(&(GMgr->ProcEng));
00687                 GMgr->ProcEng = NULL;
00688         }
00689 
00690         WInfo->World = NULL;
00691 
00692         GMgr->Time = 0.0f;              // FIXME:  Take out?  Put in GameMgr_SetWorld?
00693 
00694         return Ret;
00695 }
00696 
00697 #define PATH_SEPERATOR '/'
00698 
00699 //=====================================================================================
00700 //      DefaultExtension
00701 //=====================================================================================
00702 void DefaultExtension (char *Path, const char *Ext)
00703 {
00704         char    *Src;
00705         
00706         Src = Path + strlen(Path) - 1;
00707 
00708         while (*Src != PATH_SEPERATOR && Src != Path)
00709         {
00710                 if (*Src == '.')
00711                         return;                 // it has an extension
00712                 Src--;
00713         }
00714 
00715         strcat (Path, Ext);
00716 }
00717 
00718 //====================================================================================
00719 //      GameMgr_SetWorld
00720 //      Sets the current world in the GameMgr.
00721 //====================================================================================
00722 geBoolean GameMgr_SetWorld(GameMgr *GMgr, const char *WorldName)
00723 {
00724         GameMgr_WorldInfo       *WInfo;
00725         geWorld_Model           *Model;
00726         geVFile *                       WorldFile;
00727         char                            TFile[GAMEMGR_MAX_WORLD_NAME+4];
00728         int                                     Width,Height;
00729         int                                     MessageWidth = 250;
00730 
00731         assert(GameMgr_IsValid(GMgr) == GE_TRUE);
00732         assert(strlen(WorldName) < GAMEMGR_MAX_WORLD_NAME);
00733         
00734         strcpy(TFile, WorldName);
00735 
00736         DefaultExtension(TFile, ".BSP");
00737 
00738         WInfo = &GMgr->WorldInfo[0];
00739 
00740         if (GameMgr_GetFrameState(GMgr) != FrameState_None)
00741                 GenVS_Error("GameMgr_SetWorld:  GameMgr_GetFrameState(GMgr) != FrameState_None.\n");
00742 
00743         VidMode_GetResolution(GMgr->VidMode,&Width,&Height);
00744 
00745         if (!GameMgr_ClearBackground(GMgr, (Width/2)-(MessageWidth/2), Height/2-10, "Loading level, please wait..."))
00746                 GenVS_Error("GameMgr_SetWorld:  GameMgr_ClearBackground failed.\n");
00747         //GameMgr_ConsolePrintf(GMgr, GE_TRUE, "Loading level, please wait...\n");
00748 
00749         // Make sure we free the old world!!!
00750         GameMgr_FreeWorld(GMgr);                // Clear all that belongs to world stuff
00751 
00752         WorldFile = geVFile_Open(MainFS, TFile, GE_VFILE_OPEN_READONLY);
00753 
00754         if      (!WorldFile)
00755                 GenVS_Error("GameMgr_SetWorld:  geVFile_Open failed: %s.\n", TFile);
00756 
00757         WInfo->World = geWorld_Create(WorldFile);
00758         geVFile_Close(WorldFile);
00759 
00760         if (!WInfo->World)
00761                 GenVS_Error("GameMgr_SetWorld:  geWorld_Create failed: %s.\n", TFile);
00762 
00763         if (!geEngine_AddWorld(GMgr->Engine, WInfo->World))
00764                 GenVS_Error("GameMgr_SetWorld:  geEngine_AddWorld failed: %s.\n", TFile);
00765 
00766         {
00767         char ProcCfgName[1024];
00768         geVFile * ProcCfgFile;
00769                 strcpy(ProcCfgName,TFile);
00770                 assert( ProcCfgName[ strlen(TFile) - 4 ] == '.' );
00771                 ProcCfgName[ strlen(TFile) - 4 ] = 0;
00772                 strcat(ProcCfgName,".prc");
00773                 ProcCfgFile = geVFile_Open(MainFS,ProcCfgName, GE_VFILE_OPEN_READONLY);
00774                 
00775                 if      (!ProcCfgFile)
00776                 {
00777                 }
00778                 else
00779                 {
00780                         GMgr->ProcEng = ProcEng_Create(ProcCfgFile, WInfo->World);
00781                         geVFile_Close(ProcCfgFile);
00782                 }
00783         }
00784 
00785         GMgr->FxSystem = Fx_SystemCreate(WInfo->World, NULL);
00786 
00787         if (!GMgr->FxSystem)
00788                 GenVS_Error("GameMgr_SetWorld:  Fx_SystemCreate failed.\n");
00789 
00790         // Create the gamemgr shadow map
00791         if (!(GMgr->ShadowMap = geBitmapUtil_CreateFromFileAndAlphaNames(MainFS, "Bmp\\Fx\\Smoke_05.bmp", "Bmp\\Fx\\A_Smk05.bmp")) )
00792                 GenVS_Error("GameMgr_SetWorld:  geBitmapUtil_CreateFromFileAndAlphaNames failed.\n");
00793 
00794         if (!geWorld_AddBitmap( WInfo->World, GMgr->ShadowMap) )
00795                 GenVS_Error("GameMgr_SetWorld:  geWorld_AddBitmap failed.\n");
00796 
00797         // Setup the models with the world
00798         WInfo->NumModels = 0;
00799         Model = NULL;
00800 
00801         while(1)
00802         {
00803                 assert(WInfo->NumModels <= GAMEMGR_MAX_MODELS);
00804 
00805                 Model = geWorld_GetNextModel(WInfo->World, Model);
00806 
00807                 if (!Model)
00808                         break;
00809 
00810                 WInfo->Models[WInfo->NumModels] = Model;
00811                 WInfo->NumModels++;
00812         }
00813 
00814         // Set some light type defaults
00815         geWorld_SetLTypeTable(WInfo->World, 0, "z");
00816         geWorld_SetLTypeTable(WInfo->World, 1, "mmnmmommommnonmmonqnmmo");
00817         geWorld_SetLTypeTable(WInfo->World, 2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
00818         geWorld_SetLTypeTable(WInfo->World, 3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
00819         geWorld_SetLTypeTable(WInfo->World, 4, "mamamamamama");
00820         geWorld_SetLTypeTable(WInfo->World, 5, "jklmnopqrstuvwxyzyxwvutsrqponmlkj");
00821         geWorld_SetLTypeTable(WInfo->World, 6, "nmonqnmomnmomomno");
00822         geWorld_SetLTypeTable(WInfo->World, 7, "mmmaaaabcdefgmmmmaaaammmaamm");
00823         geWorld_SetLTypeTable(WInfo->World, 8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
00824         geWorld_SetLTypeTable(WInfo->World, 9, "aaaaaaaazzzzzzzz");
00825         geWorld_SetLTypeTable(WInfo->World, 10,"mmamammmmammamamaaamammma");
00826         geWorld_SetLTypeTable(WInfo->World, 11,"abcdefghijklmnopqrrqponmlkjihgfedcba");
00827 
00828         assert(GMgr->Engine);
00829         
00830         // Create the coronas
00831         if (!Corona_Init(GameMgr_GetEngine(GMgr), GameMgr_GetWorld(GMgr), MainFS))
00832                 GenVS_Error("GameMgr_SetWorld:  Corona_Init failed.\n");
00833 
00834         // Create the electric interface
00835         if (!Electric_Init(GameMgr_GetEngine(GMgr), GameMgr_GetWorld(GMgr), MainFS, GameMgr_GetSoundSystem(GMgr)))
00836                 GenVS_Error("GameMgr_SetWorld:  Electric_Init failed.\n");
00837 
00838         // Create the dynlight interface
00839         if (!DynLight_Init(GameMgr_GetEngine(GMgr), GameMgr_GetWorld(GMgr), MainFS))
00840                 GenVS_Error("GameMgr_SetWorld:  DynLight_Init failed.\n");
00841 
00842         // Create the ModelCtl interface
00843         if (!ModelCtl_Init())
00844                 GenVS_Error("GameMgr_SetWorld:  ModelCtl_Init failed.\n");
00845 
00846         return GE_TRUE;
00847 }
00848 
00849 //====================================================================================
00850 //      GameMgr_SetActorIndex
00851 //====================================================================================
00852 geBoolean GameMgr_SetActorIndex(GameMgr *GMgr, int32 Index, const char *FileName)
00853 {
00854         GameMgr_WorldInfo       *WInfo;
00855         GameMgr_ActorIndex      *ActorIndex;
00856         geVFile *                               File;
00857 
00858         assert(GameMgr_IsValid(GMgr) == GE_TRUE);
00859         assert(FileName);
00860         assert(strlen(FileName) < GAMEMGR_MAX_ACTOR_NAME);
00861         assert(Index < GAMEMGR_MAX_ACTOR_INDEX);
00862 
00863         ActorIndex = &GMgr->ActorIndex[Index];
00864 
00865         assert(ActorIndex->ActorDef == NULL);
00866         assert(ActorIndex->ActorHack == NULL);
00867         assert(ActorIndex->Active == GE_FALSE);
00868         assert(GameMgr_GetFrameState(GMgr) == FrameState_None);
00869 
00870         if (GameMgr_GetFrameState(GMgr) != FrameState_None)
00871                 GenVS_Error("GameMgr_SetActorIndex:  GameMgr_GetFrameState(GMgr) != FrameState_None.\n");
00872 
00873         WInfo = &GMgr->WorldInfo[0];
00874 
00875         assert(WInfo->World);
00876 
00877         if (!WInfo->World)
00878                 GenVS_Error("GameMgr_SetActorIndex:  NULL World.\n");
00879 
00880         // It is safe to load the mesh index at this point...
00881         File = geVFile_Open(MainFS, FileName, GE_VFILE_OPEN_READONLY);
00882 
00883         if      (!File)
00884                 GenVS_Error("GameMgr_SetActorIndex:  geVFile_Open failed: %s.\n", FileName);
00885 
00886         ActorIndex->ActorDef = geActor_DefCreateFromFile(File);
00887         geVFile_Close(File);
00888 
00889         if (!ActorIndex->ActorDef)
00890                 GenVS_Error("GameMgr_SetActorIndex:  geActor_DefCreateFromFile failed: %s.\n", FileName);
00891 
00892         // Make our "fake" player, do we know for sure that the textures will remain in memory...
00893         ActorIndex->ActorHack = geActor_Create(ActorIndex->ActorDef);
00894         geWorld_AddActor(WInfo->World, ActorIndex->ActorHack, 0, 0);
00895         
00896         if (!ActorIndex->ActorHack)
00897                 GenVS_Error("GameMgr_SetActorIndex:  geWorld_AddActor failed: %s.\n", FileName);
00898 
00899         strcpy(ActorIndex->FileName, FileName);
00900         ActorIndex->Active = GE_TRUE;
00901 
00902         return GE_TRUE;
00903 }
00904 
00905 //====================================================================================
00906 //      GameMgr_GetActorIndex
00907 //====================================================================================
00908 GameMgr_ActorIndex *GameMgr_GetActorIndex(GameMgr *GMgr, int32 Index)
00909 {
00910         assert(GameMgr_IsValid(GMgr) == GE_TRUE);
00911         assert(Index >= 0 && Index < GAMEMGR_MAX_ACTOR_INDEX);
00912 
00913         return &GMgr->ActorIndex[Index];
00914 }
00915 
00916 //====================================================================================
00917 //      GameMgr_MotionIndexIsValid
00918 //====================================================================================
00919 geBoolean GameMgr_MotionIndexIsValid(GameMgr *GMgr, GameMgr_MotionIndex Index)
00920 {
00921         if (Index == GAMEMGR_MOTION_INDEX_NONE)
00922                 return GE_FALSE;
00923 
00924         if (Index < 0 || Index >= GAMEMGR_MAX_MOTION_INDEX)
00925                 return GE_FALSE;
00926 
00927         return GE_TRUE;
00928 }
00929 
00930 //=====================================================================================
00931 //      GameMgr_SetMotionIndexDef
00932 //=====================================================================================
00933 geBoolean GameMgr_SetMotionIndexDef(GameMgr *GMgr, GameMgr_MotionIndex Index, const char *MotionName)
00934 {
00935         assert(GameMgr_IsValid(GMgr) == GE_TRUE);
00936         assert(MotionName);
00937         assert(strlen(MotionName) < GAMEMGR_MAX_MOTION_NAME);
00938         assert(GameMgr_MotionIndexIsValid(GMgr, Index));
00939         assert(GMgr->MotionIndexDefs[Index].Active == GE_FALSE);
00940 
00941         strcpy(GMgr->MotionIndexDefs[Index].MotionName, MotionName);
00942         GMgr->MotionIndexDefs[Index].Active = GE_TRUE;
00943 
00944         return GE_TRUE;
00945 }
00946 
00947 //====================================================================================
00948 //      GameMgr_GetMotionIndexDef
00949 //====================================================================================
00950 GameMgr_MotionIndexDef *GameMgr_GetMotionIndexDef(GameMgr *GMgr, GameMgr_MotionIndex Index)
00951 {
00952         assert(GameMgr_IsValid(GMgr) == GE_TRUE);
00953         assert(GameMgr_MotionIndexIsValid(GMgr, Index));
00954 
00955         return &GMgr->MotionIndexDefs[Index];
00956 }
00957 
00958 //=====================================================================================
00959 //      GameMgr_SetBoneIndex
00960 //=====================================================================================
00961 geBoolean GameMgr_SetBoneIndex(GameMgr *GMgr, int32 BoneIndex, const char *BoneName)
00962 {
00963         assert(GameMgr_IsValid(GMgr) == GE_TRUE);
00964         assert(BoneName);
00965         assert(BoneIndex < GAMEMGR_MAX_BONE_INDEX);
00966         assert(strlen(BoneName) < GAMEMGR_MAX_BONE_NAME);
00967         assert(GMgr->BoneIndex[BoneIndex].Active == GE_FALSE);
00968 
00969         strcpy(GMgr->BoneIndex[BoneIndex].BoneName, BoneName);
00970         GMgr->BoneIndex[BoneIndex].Active = GE_TRUE;
00971 
00972         return GE_TRUE;
00973 }
00974 
00975 //====================================================================================
00976 //      GameMgr_GetBoneIndex
00977 //====================================================================================
00978 GameMgr_BoneIndex *GameMgr_GetBoneIndex(GameMgr *GMgr, int32 Index)
00979 {
00980         assert(GameMgr_IsValid(GMgr) == GE_TRUE);
00981         assert(Index >= 0 && Index < GAMEMGR_MAX_BONE_INDEX);
00982 
00983         return &GMgr->BoneIndex[Index];
00984 }
00985 
00986 //====================================================================================
00987 //      GameMgr_SetTextureIndex
00988 //====================================================================================
00989 geBoolean GameMgr_SetTextureIndex(GameMgr *GMgr, int32 Index, const char *FileName, const char *AFileName)
00990 {
00991         GameMgr_WorldInfo               *WInfo;
00992         const char                              *pFileName, *pAFileName;
00993         GameMgr_TextureIndex    *TextureIndex;
00994         geBitmap                                *ABitmap;
00995 
00996         ABitmap = NULL;
00997 
00998         assert(GameMgr_IsValid(GMgr) == GE_TRUE);
00999         assert(Index >= 0 && Index < GAMEMGR_MAX_TEXTURE_INDEX);
01000         assert(FileName);
01001         assert(FileName[0]);
01002         assert(strlen(FileName) < GAMEMGR_MAX_FILENAME);
01003 
01004         TextureIndex = &GMgr->TextureIndex[Index];
01005 
01006         assert(TextureIndex->TextureDef == NULL);
01007         assert(TextureIndex->Active == GE_FALSE);
01008         assert(GameMgr_GetFrameState(GMgr) == FrameState_None);
01009 
01010         if (GameMgr_GetFrameState(GMgr) != FrameState_None)
01011                 GenVS_Error("GameMgr_SetTextureIndex:  GameMgr_GetFrameState(GMgr) != FrameState_None.\n");
01012 
01013         WInfo = &GMgr->WorldInfo[0];
01014 
01015         assert(WInfo->World);
01016 
01017         if (!WInfo->World)
01018                 GenVS_Error("GameMgr_SetTextureIndex:  NULL World.\n");
01019 
01020         // It is now safe to load the texture...
01021         // It better be NULL first!!! ot somthing went wrong...
01022         pFileName = FileName;
01023         
01024         if (AFileName && AFileName[0])
01025         {
01026                 assert(strlen(AFileName) < GAMEMGR_MAX_FILENAME);
01027                 pAFileName = AFileName;
01028         }
01029         else
01030                 pAFileName = NULL;
01031 
01032         // Create the bitmaps
01033         TextureIndex->TextureDef = geBitmap_CreateFromFileName(MainFS, pFileName);
01034 
01035         if (!TextureIndex->TextureDef)
01036         {
01037                 geErrorLog_AddString(-1, "GameMgr_SetTextureIndex:  geBitmap_CreateFromFileName failed:", pFileName);
01038                 goto ExitWithError;
01039         }
01040 
01041         // Load the alpha bitmap
01042         if (pAFileName)
01043         {
01044                 ABitmap = geBitmap_CreateFromFileName(MainFS, pAFileName);
01045 
01046                 if (!geBitmap_SetAlpha(TextureIndex->TextureDef, ABitmap))
01047                 {
01048                         geErrorLog_AddString(-1, "GameMgr_SetTextureIndex:  geBitmap_SetAlpha failed.", NULL);
01049                         goto ExitWithError;
01050                 }
01051                 
01052                 // Don't need this anymore
01053                 geBitmap_Destroy(&ABitmap);
01054         }
01055 
01056         if (!geWorld_AddBitmap(WInfo->World, TextureIndex->TextureDef))
01057         {
01058                 geErrorLog_AddString(-1, "GameMgr_SetTextureIndex:  geWorld_AddBimap failed.", NULL);
01059                 goto ExitWithError;
01060         }
01061 
01062         strcpy(TextureIndex->FileName, FileName);
01063         strcpy(TextureIndex->AFileName, AFileName);
01064         TextureIndex->Active = GE_TRUE;
01065 
01066         return GE_TRUE;
01067 
01068         ExitWithError:
01069         {
01070                 if (TextureIndex->TextureDef)
01071                 {
01072                         geBitmap_Destroy(&TextureIndex->TextureDef);
01073                         TextureIndex->TextureDef = NULL;
01074                 }
01075 
01076                 if (ABitmap)
01077                 {
01078                         geBitmap_Destroy(&ABitmap);
01079                         ABitmap = NULL;
01080                 }
01081 
01082                 GenVS_Error("GameMgr_SetTextureIndex:  Failed.\n");
01083                 return GE_FALSE;                // Shut up compiler
01084         }
01085 }
01086 
01087 //====================================================================================
01088 //      GameMgr_GetTextureIndex
01089 //====================================================================================
01090 GameMgr_TextureIndex *GameMgr_GetTextureIndex(GameMgr *GMgr, int32 Index)
01091 {
01092         assert(GameMgr_IsValid(GMgr) == GE_TRUE);
01093         assert(Index >= 0 && Index < GAMEMGR_MAX_TEXTURE_INDEX);
01094 
01095         return &GMgr->TextureIndex[Index];
01096 }
01097 
01098 //=====================================================================================
01099 //      GameMgr_SetSoundIndex
01100 //=====================================================================================
01101 geBoolean GameMgr_SetSoundIndex(GameMgr *GMgr, int32 SoundIndex, const char *FileName)
01102 {
01103         GameMgr_SoundIndex      *pSoundIndex;
01104         geVFile *                               File;
01105 
01106         assert(GameMgr_IsValid(GMgr) == GE_TRUE);
01107         
01108         if (!GMgr->SoundSys)
01109                 return GE_TRUE;
01110         
01111         assert(FileName);
01112         assert(SoundIndex < GAMEMGR_MAX_SOUND_INDEX);
01113         assert(strlen(FileName) < GAMEMGR_MAX_FILENAME);
01114         
01115         pSoundIndex = &GMgr->SoundIndex[SoundIndex];
01116 
01117         assert(pSoundIndex->Active == GE_FALSE);
01118         assert(pSoundIndex->SoundDef == NULL);
01119 
01120         File = geVFile_Open(MainFS, FileName, GE_VFILE_OPEN_READONLY);
01121 
01122         if (!File)
01123                 GenVS_Error("GameMgr_SetSoundIndex:  geVFile_Open failed: %s.\n", FileName);
01124 
01125         pSoundIndex->SoundDef = geSound_LoadSoundDef(GMgr->SoundSys, File);
01126         geVFile_Close(File);
01127 
01128         if (!pSoundIndex->SoundDef)
01129                 GenVS_Error("geSound_LoadSoundDef:  geVFile_Open failed: %s.\n", FileName);
01130 
01131         assert(pSoundIndex->SoundDef);
01132 
01133         strcpy(pSoundIndex->FileName, FileName);
01134         pSoundIndex->Active = GE_TRUE;
01135 
01136         return GE_TRUE;
01137 }
01138 
01139 //====================================================================================
01140 //      GameMgr_GetSoundIndex
01141 //====================================================================================
01142 GameMgr_SoundIndex *GameMgr_GetSoundIndex(GameMgr *GMgr, int32 Index)
01143 {
01144         assert(GameMgr_IsValid(GMgr) == GE_TRUE);
01145         assert(Index >= 0 && Index < GAMEMGR_MAX_SOUND_INDEX);
01146 
01147         return &GMgr->SoundIndex[Index];
01148 }
01149 
01150 //====================================================================================
01151 //      GameMgr_GetEngine
01152 //====================================================================================
01153 geEngine *GameMgr_GetEngine(GameMgr *GMgr)
01154 {
01155         assert(GameMgr_IsValid(GMgr) == GE_TRUE);
01156 
01157         return GMgr->Engine;
01158 }
01159 
01160 //====================================================================================
01161 //      GameMgr_GetSoundSystem
01162 //====================================================================================
01163 geSound_System *GameMgr_GetSoundSystem(GameMgr *GMgr)
01164 {
01165         assert(GameMgr_IsValid(GMgr) == GE_TRUE);
01166 
01167         return GMgr->SoundSys;
01168 }
01169 
01170 //====================================================================================
01171 //      GameMgr_GetConsole
01172 //====================================================================================
01173 Console_Console *GameMgr_GetConsole(GameMgr *GMgr)
01174 {
01175         assert(GameMgr_IsValid(GMgr) == GE_TRUE);
01176 
01177         return GMgr->Console;
01178 }
01179 
01180 //====================================================================================
01181 //      GameMgr_GetWorld
01182 //====================================================================================
01183 geWorld *GameMgr_GetWorld(GameMgr *GMgr)
01184 {
01185         assert(GameMgr_IsValid(GMgr) == GE_TRUE);
01186 
01187         return GMgr->WorldInfo[0].World;
01188 }
01189 
01190 //====================================================================================
01191 //      GameMgr_GetCamera
01192 //====================================================================================
01193 geCamera *GameMgr_GetCamera(GameMgr *GMgr)
01194 {
01195         assert(GameMgr_IsValid(GMgr) == GE_TRUE);
01196 
01197         return GMgr->Camera;
01198 }
01199 
01200 //====================================================================================
01201 //      GameMgr_GetFrameState
01202 //====================================================================================
01203 GameMgr_FrameState GameMgr_GetFrameState(GameMgr *GMgr)
01204 {
01205         assert(GameMgr_IsValid(GMgr) == GE_TRUE);
01206 
01207         return GMgr->FrameState;
01208 }
01209 
01210 //====================================================================================
01211 //      GameMgr_GetNumModels
01212 //====================================================================================
01213 int32 GameMgr_GetNumModels(GameMgr *GMgr)
01214 {
01215         assert(GameMgr_IsValid(GMgr) == GE_TRUE);
01216 
01217         return GMgr->WorldInfo[0].NumModels;
01218 }
01219 
01220 //====================================================================================
01221 //      GameMgr_GetModel
01222 //====================================================================================
01223 geWorld_Model *GameMgr_GetModel(GameMgr *GMgr, int32 Index)
01224 {
01225         assert(GameMgr_IsValid(GMgr) == GE_TRUE);
01226 
01227         assert(Index >= 0 && Index < GameMgr_GetNumModels(GMgr));
01228 
01229         return GMgr->WorldInfo[0].Models[Index];
01230 }
01231 
01232 //====================================================================================
01233 //      GameMgr_GetFxSystem
01234 //====================================================================================
01235 Fx_System *GameMgr_GetFxSystem(GameMgr *GMgr)
01236 {
01237         assert(GameMgr_IsValid(GMgr) == GE_TRUE);
01238 
01239         return GMgr->FxSystem;
01240 }
01241 
01242 //====================================================================================
01243 //      GameMgr_GetShadowMap
01244 //====================================================================================
01245 geBitmap *GameMgr_GetShadowMap(GameMgr *GMgr)
01246 {
01247         assert(GameMgr_IsValid(GMgr) == GE_TRUE);
01248 
01249         return GMgr->ShadowMap;
01250 }
01251 
01252 //====================================================================================
01253 //      GameMgr_GetTime
01254 //====================================================================================
01255 float GameMgr_GetTime(GameMgr *GMgr)
01256 {
01257         assert(GameMgr_IsValid(GMgr) == GE_TRUE);
01258 
01259         return GMgr->Time;
01260 }
01261 
01262 //====================================================================================
01263 //      GameMgr_GethWnd
01264 //====================================================================================
01265 HWND GameMgr_GethWnd(GameMgr *GMgr)
01266 {
01267         assert(GameMgr_IsValid(GMgr) == GE_TRUE);
01268 
01269         return GMgr->hWnd;
01270 }
01271 
01272 //====================================================================================
01273 //      GameMgr_GetVidMode
01274 //====================================================================================
01275 VidMode GameMgr_GetVidMode(GameMgr *GMgr)
01276 {
01277         assert(GameMgr_IsValid(GMgr) == GE_TRUE);
01278 
01279         return GMgr->VidMode;
01280 }
01281 
01282 LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam);
01283 
01284 
01285 void GameMgr_ResetMainWindow(HWND hWnd, int32 Width, int32 Height)
01286 {
01287         RECT ScreenRect;
01288 
01289         GetWindowRect(GetDesktopWindow(),&ScreenRect);
01290 
01291         SetWindowLong(hWnd, 
01292                  GWL_STYLE, 
01293                  GetWindowLong(hWnd, GWL_STYLE) & ~WS_POPUP);
01294 
01295         SetWindowLong(hWnd, 
01296                  GWL_STYLE, 
01297                  GetWindowLong(hWnd, GWL_STYLE) | (WS_OVERLAPPED  | 
01298                                                    WS_CAPTION     | 
01299                                                    WS_SYSMENU     | 
01300                                                    WS_MINIMIZEBOX));
01301 
01302         SetWindowLong(hWnd, 
01303                   GWL_STYLE, 
01304                   GetWindowLong(hWnd, GWL_STYLE) | WS_THICKFRAME |
01305                                                      WS_MAXIMIZEBOX);
01306 
01307         //SetWindowLong(hWnd, 
01308     //              GWL_EXSTYLE, 
01309     //              GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_TOPMOST);
01310 
01311         {
01312                 RECT ClientRect;
01313                 int Style = GetWindowLong (hWnd, GWL_STYLE);
01314                 
01315                 ClientRect.left = 0;
01316                 ClientRect.top = 0;
01317                 ClientRect.right = Width - 1;
01318                 ClientRect.bottom = Height - 1;
01319                 AdjustWindowRect (&ClientRect, Style, FALSE);   // FALSE == No menu     
01320                 
01321                 {
01322                         int WindowWidth = ClientRect.right - ClientRect.left + 1;
01323                         int WindowHeight = ClientRect.bottom - ClientRect.top + 1;
01324                         SetWindowPos 
01325                         (
01326                                 hWnd, HWND_TOP,
01327                                 (ScreenRect.right+ScreenRect.left)/2 - WindowWidth/2,
01328                                 (ScreenRect.bottom+ScreenRect.top)/2 - WindowHeight/2, 
01329                                 WindowWidth, WindowHeight,
01330                                 SWP_NOCOPYBITS | SWP_NOZORDER
01331                         );
01332                 }
01333         }
01334 
01335         ShowWindow(hWnd, SW_SHOWNORMAL);
01336         UpdateWindow(hWnd);
01337         SetFocus(hWnd);
01338 }
01339 
01340 //=====================================================================================
01341 //      CreateMainWindow
01342 //=====================================================================================
01343 static HWND CreateMainWindow(HANDLE hInstance, const char *AppName, int32 Width, int32 Height)
01344 {
01345         WNDCLASS                wc;
01346         HWND                    hWnd;
01347         RECT                ScreenRect;
01348         
01349         //
01350         // Set up and register application window class
01351         //
01352         wc.style         = CS_HREDRAW | CS_VREDRAW;
01353         wc.lpfnWndProc   = WndProc;
01354         wc.cbClsExtra    = 0;
01355         wc.cbWndExtra    = 0;
01356         wc.hInstance     = hInstance;
01357         // change this if we ever make an icon.
01358         wc.hIcon         = NULL; //LoadIcon(hInstance, IDI_APPLICATION);
01359         wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
01360         wc.hbrBackground = GetStockObject(BLACK_BRUSH);
01361         wc.lpszMenuName  = (const char*)NULL;
01362         wc.lpszClassName = AppName;
01363 
01364         RegisterClass(&wc);
01365 
01366         //
01367         // Create application's main window
01368         //
01369         GetWindowRect(GetDesktopWindow(),&ScreenRect);
01370         hWnd = CreateWindowEx(
01371                 0,
01372                 AppName,
01373                 AppName,
01374                 0,
01375                 (ScreenRect.right+ScreenRect.left)/2 - Width/2,
01376                 (ScreenRect.bottom+ScreenRect.top)/2 - Height/2, 
01377                 Width,
01378                 Height,
01379                 NULL,
01380                 NULL,
01381                 hInstance,
01382                 NULL);
01383 
01384         if (!hWnd)
01385         {
01386                 MessageBox(0, "Could not create window.", "** ERROR **", MB_OK);
01387                 _exit(1);
01388         }       
01389 
01390         
01391         GameMgr_ResetMainWindow(hWnd, Width, Height);
01392         SetFocus(hWnd);
01393 
01394         return hWnd;
01395 
01396 }
01397 

Generated on Tue Sep 30 12:35:46 2003 for GTestAndEngine by doxygen 1.3.2