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

proceng.h File Reference

#include "Genesis.h"

Go to the source code of this file.

Typedefs

typedef ProcEng ProcEng

Functions

ProcEngProcEng_Create (geVFile *CfgFile, geWorld *World)
void ProcEng_Destroy (ProcEng **pPEng)
geBoolean ProcEng_AddProcedural (ProcEng *PEng, const char *ProcName, geBitmap **Bitmap, const char *Params)
geBoolean ProcEng_Animate (ProcEng *PEng, float ElapsedTime)
geBoolean ProcEng_Minimize (ProcEng *PEng)


Typedef Documentation

typedef struct ProcEng ProcEng
 

Definition at line 16 of file proceng.h.


Function Documentation

geBoolean ProcEng_AddProcedural ProcEng PEng,
const char *  ProcName,
geBitmap **  Bitmap,
const char *  Params
 

Definition at line 403 of file proceng.c.

References Procedural_Table::Create, GE_FALSE, GE_TRUE, geBitmap_CreateRef(), geBoolean, geErrorLog_AddString, int32, Procedural_Table::Name, NULL, ProcEng::NumProcs, ProcEng::NumPTables, PROCENG_MAX_PROCS, ProcEng::Procs, ProcEng::PTables, ProcEng_PTable::Table, and ProcEng_PTable::Uses.

Referenced by ProcEng_Create().

00404 {
00405         int32                   i;
00406         ProcEng_PTable  *pTable;
00407 
00408         assert(PEng);
00409         assert(ProcName);
00410         assert(pBitmap);
00411 
00412         if (PEng->NumProcs+1 >= PROCENG_MAX_PROCS)
00413         {
00414                 geErrorLog_AddString(-1, "ProcEng_AddProcedural:  Max procs.", NULL);
00415                 return GE_FALSE;
00416         }
00417 
00418         // Find Procedural_Table by Name
00419         pTable = PEng->PTables;
00420         for (i=0; i< PEng->NumPTables; i++, pTable++)
00421         {
00422                 // Should we ignore case? ! YES!
00423                 if ( stricmp(pTable->Table->Name, ProcName) == 0)
00424                         break;
00425         }
00426 
00427         if (i == PEng->NumPTables)              // Didn't find it
00428         {
00429                 geErrorLog_AddString(-1, "ProcEng_AddProcedural:  Table not found for procedural.", NULL);
00430                 return GE_FALSE;
00431         }
00432 
00433         assert(pTable->Table);
00434 
00435         // Create the proc (each bitmap should have it's own)
00436         PEng->Procs[PEng->NumProcs].Proc = pTable->Table->Create(pBitmap, Params);
00437 
00438         if (!PEng->Procs[PEng->NumProcs].Proc)
00439         {
00440                 geErrorLog_AddString(-1," ProcEng_AddProcedural:  (%s)->Create failed", pTable->Table->Name);
00441                 return GE_FALSE;
00442         }
00443         if (! *pBitmap)
00444         {
00445                 geErrorLog_AddString(-1,"ProcEng_AddProcedural: No Bitmap:", pTable->Table->Name);
00446                 return GE_FALSE;
00447         }
00448 
00449         PEng->Procs[PEng->NumProcs].Bitmap = *pBitmap;
00450         PEng->Procs[PEng->NumProcs].Table = pTable->Table;
00451 
00452         geBitmap_CreateRef(*pBitmap);
00453         // make sure the bitmap isn't destroyed before our procedural
00454 
00455         PEng->NumProcs++;
00456 
00457         pTable->Uses ++;
00458 
00459         return GE_TRUE;
00460 }

geBoolean ProcEng_Animate ProcEng PEng,
float  ElapsedTime
 

Definition at line 465 of file proceng.c.

References Procedural_Table::Animate, ProcEng_Proc::Bitmap, GE_FALSE, GE_TRUE, geBoolean, geErrorLog_AddString, geWorld_BitmapIsVisible(), int32, NULL, ProcEng::NumProcs, ProcEng_Proc::Proc, ProcEng::Procs, ProcEng_Proc::Table, and ProcEng::World.

Referenced by GameMgr_Frame().

00466 {
00467         int32                   i;
00468         ProcEng_Proc    *pProc;
00469 
00470         pProc = PEng->Procs;
00471         for (i=0; i< PEng->NumProcs; i++, pProc++)
00472         {
00473                 assert(pProc->Table);
00474                 assert(pProc->Proc);
00475 
00476                 if (!geWorld_BitmapIsVisible(PEng->World, pProc->Bitmap))
00477                         continue;
00478 
00479                 if (!pProc->Table->Animate(pProc->Proc, ElapsedTime))
00480                 {
00481                         geErrorLog_AddString(-1,"ProcEng_Animate: pProc->Table->Animate failed", NULL);
00482                         return GE_FALSE;
00483                 }
00484         }
00485         return GE_TRUE;
00486 }

ProcEng* ProcEng_Create geVFile CfgFile,
geWorld World
 

Definition at line 74 of file proceng.c.

References DWORD, GE_FALSE, GE_VFILE_OPEN_DIRECTORY, GE_VFILE_OPEN_READONLY, GE_VFILE_SEEKCUR, GE_VFILE_TYPE_DOS, geErrorLog_AddString, geRam_Allocate, GetProceduralFunc, GetProceduralFunctions, geVFile_Close(), geVFile_CreateFinder(), geVFile_DestroyFinder(), geVFile_FinderGetNextFile(), geVFile_FinderGetProperties(), geVFile_GetS(), geVFile_OpenNewSystem(), geVFile_Seek(), geWorld_GetBitmapByName(), int32, geVFile_Properties::Name, NULL, NumGetProceduralFunctions, ProcEng::NumPTables, Procedurals_Tag, Procedurals_Version, ProcEng_AddProcedural(), ProcEng_Destroy(), ProcEng::PTables, SkipNonWhite, SkipWhite, Procedural_Table::Tag, Procedural_Table::Version, VFile_ReadBetween(), VFile_SeekPastSpaces(), VFile_SeekPastString(), and ProcEng::World.

Referenced by GameMgr_SetWorld().

00075 {
00076         ProcEng         *PEng;
00077         int32           i;
00078 
00079         // For now, hard code in the procedures (but later, load *.dll)...
00080         PEng = geRam_Allocate(sizeof(*PEng));
00081 
00082         if (!PEng)
00083                 return GE_FALSE;
00084 
00085         memset(PEng, 0, sizeof(*PEng));
00086 
00087         // init all compiled-in procedurals:
00088 
00089         for(i=0;i<NumGetProceduralFunctions;i++)
00090         {       
00091                 if ( GetProceduralFunctions[i] )
00092                 {
00093                 Procedural_Table * pTable;
00094                         pTable = (*GetProceduralFunctions[i]) ();
00095                         if ( pTable->Tag == Procedurals_Tag && 
00096                                         pTable->Version == Procedurals_Version )
00097                         {
00098                                 PEng->PTables[PEng->NumPTables].DllHandle = NULL;
00099                                 PEng->PTables[PEng->NumPTables].Table = pTable;
00100                                 PEng->PTables[PEng->NumPTables].Uses  = 0;
00101                                 PEng->NumPTables ++;
00102                         }
00103                         else if ( pTable->Tag == Procedurals_Tag )
00104                         {
00105                         //char ErrStr[1024];
00106                         //      sprintf(ErrStr,"ProcEng_Create : found procedural : %s : but ignored because of version mismatch",pTable->Name);
00107                         //      geErrorLog_AddString(-1,ErrStr);
00108                         }
00109                 }
00110         }
00111 
00112         do
00113         {
00114         geVFile * FileBase;
00115         geVFile_Finder * Finder;
00116         char BasePath[1024];
00117 
00118                 //harcoded path!
00119                 //<>
00120                 strcpy(BasePath,"c:\\genesis\\procedurals");
00121 
00122                 FileBase = geVFile_OpenNewSystem(NULL,GE_VFILE_TYPE_DOS,BasePath,NULL,GE_VFILE_OPEN_READONLY|GE_VFILE_OPEN_DIRECTORY);
00123                 if ( ! FileBase )
00124                 {
00125                         // We really should not use ErrorLog for normal logging info...
00126                         //geErrorLog_AddString(-1,"ProcEng_Create : Couldn't open procedural DLL directory : non_fatal");
00127                         break;
00128                 }
00129 
00130                 Finder = geVFile_CreateFinder(FileBase,"*.dll");
00131                 if ( ! Finder )
00132                 {
00133                         //geErrorLog_AddString(-1,"ProcEng_Create : Couldn't open procedural Finder : non_fatal");
00134                         geVFile_Close(FileBase);
00135                         break;
00136                 }
00137 
00138                 while( geVFile_FinderGetNextFile(Finder) )
00139                 {
00140                 GetProceduralFunc GetProcFunc;
00141                 HMODULE TheDll;
00142                 geVFile_Properties Properties;
00143                 char DLLName[_MAX_PATH];
00144                 Procedural_Table * pTable;
00145                 
00146                         geVFile_FinderGetProperties(Finder,&Properties);
00147 
00148                         strcpy(DLLName,BasePath);
00149                         strcat(DLLName,"\\");
00150                         strcat(DLLName,Properties.Name);
00151 
00152                         TheDll = LoadLibrary(DLLName);
00153                         if ( ! TheDll )
00154                         {
00155                                 #if 0
00156                         //char ErrStr[_MAX_PATH+1024];
00157 
00158                                 //sprintf(ErrStr,"ProcEng_Create : LoadLibrary failed on DLL : %s : non-fatal",DLLName);
00159                                 //geErrorLog_AddString(-1,ErrStr);
00160 
00161                                 {
00162                                 char string[1024];
00163                                 int plen;
00164                                 DWORD err;
00165         
00166                                         err = GetLastError();
00167                                         sprintf(string,"Windows Error : %d = %08X : \0",err,err);
00168                                         plen = strlen(string);
00169                                         FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM , NULL, err, 0, string+plen, sizeof(string)-plen, NULL);
00170                                         geErrorLog_AddString(-1,string);
00171                                 }
00172                                 #endif
00173 
00174                                 continue;
00175                         }
00176 
00177                         GetProcFunc = (GetProceduralFunc) GetProcAddress(TheDll,"GetProceduralTable");
00178                         
00179                         if ( ! GetProcFunc )
00180                         {
00181                         //char ErrStr[_MAX_PATH+1024];
00182                         //      sprintf(ErrStr,"ProcEng_Create : no GetProceduralTable in DLL : %s : non-fatal",DLLName);
00183                         //      geErrorLog_AddString(-1,ErrStr);
00184                                 FreeLibrary(TheDll);
00185                                 continue;
00186                         }
00187 
00188                         pTable = GetProcFunc();
00189                         if ( !pTable || pTable->Tag != Procedurals_Tag || pTable->Version != Procedurals_Version )
00190                         {
00191                         //char ErrStr[1024];
00192                         //      sprintf(ErrStr,"ProcEng_Create : found procedural : %s : but ignored because of version mismatch",pTable == NULL ? "null!" : pTable->Name);
00193                         //      geErrorLog_AddString(-1,ErrStr);
00194                                 FreeLibrary(TheDll);
00195                                 continue;
00196                         }
00197 
00198                         strcpy(PEng->PTables[PEng->NumPTables].DllName,DLLName);
00199                         PEng->PTables[PEng->NumPTables].DllHandle = TheDll;
00200                         PEng->PTables[PEng->NumPTables].Table = pTable;
00201                         PEng->PTables[PEng->NumPTables].Uses  = 0;
00202                         PEng->NumPTables ++;
00203                 }
00204 
00205                 geVFile_DestroyFinder(Finder);
00206                 geVFile_Close(FileBase);
00207         }
00208         while(0);
00209 
00210         if ( CfgFile && VFile_SeekPastString(CfgFile,"procedurals") )
00211         {
00212 
00213                 if ( ! VFile_SeekPastString(CfgFile,"{") )
00214                         goto ExitWithError;
00215                                 
00216                 for(;;)
00217                 {
00218                         char            *TargetName,*ProcName;
00219                         geBitmap        *Bitmap;
00220                         char            InputStr[1024];
00221                         char            *p;
00222                         int                     ReadLen;
00223 
00224                         if ( ! VFile_SeekPastSpaces(CfgFile) )
00225                                 goto ExitWithError;
00226 
00227                         if ( ! geVFile_GetS(CfgFile,InputStr,sizeof(InputStr)) )
00228                                 goto ExitWithError;
00229 
00230                         ReadLen = strlen(InputStr) + 1;
00231 
00232                         if ( p = strchr(InputStr,'}') )
00233                         {
00234                                 p ++;
00235                                 // un-read data we haven't looked at
00236                                 geVFile_Seek(CfgFile, (int)p - ((int)InputStr + ReadLen), GE_VFILE_SEEKCUR);
00237                                 break;
00238                         }
00239 
00240                         p = InputStr;
00241                         SkipWhite(p);
00242                         if ( strnicmp(p,"wbm:",4) == 0 )
00243                         {
00244                         char ParamStr[4096];
00245                         int SeekLen;
00246 
00247 
00248                                 p += 4;
00249                                 SkipWhite(p);
00250                                 TargetName = p;
00251                                 SkipNonWhite(p);
00252                                 if ( *p ) *p++ = 0;
00253                                 SkipWhite(p);
00254                                 ProcName = p;
00255                                 SkipNonWhite(p);
00256                                 
00257                                 if ( strchr(ProcName,'(') < p && strchr(ProcName,'(') )
00258                                 {
00259                                         p = strchr(ProcName,'(');
00260                                         SeekLen = (int)p - ((int)InputStr + ReadLen);
00261                                         // SeekLen --; // ?
00262                                         *p = 0;
00263                                 }
00264                                 else
00265                                 {
00266                                         SeekLen = (int)p - ((int)InputStr + ReadLen);
00267                                         *p = 0;
00268                                 }
00269                 
00270                                 // un-read data we haven't looked at
00271                                 if ( ! geVFile_Seek(CfgFile, SeekLen, GE_VFILE_SEEKCUR) )
00272                                         goto ExitWithError;
00273 
00274                                 VFile_ReadBetween(CfgFile,ParamStr,'(',')');
00275 
00276                                 // find name
00277                                 Bitmap = geWorld_GetBitmapByName(World, TargetName);
00278 
00279                                 if (!Bitmap)
00280                                 {
00281                                 //char ErrStr[1024];
00282                                 //      sprintf(ErrStr, "ProcEng_Create : couldn't find world bitmap : %s\n",TargetName);
00283                                 //      geErrorLog_AddString(-1,ErrStr);
00284                                 }
00285 
00286                                 // Should we really stop when a proc cannot be found for a bitmap?
00287                                 if ( ! ProcEng_AddProcedural(PEng, ProcName, &Bitmap, ParamStr) )
00288                                 {
00289                                 //char ErrStr[1024];
00290                                 //      sprintf(ErrStr, "ProcEng_Create : couldn't find procedural : %s\n",ProcName);
00291                                 //      geErrorLog_AddString(-1,ErrStr);
00292                                 }
00293                         }
00294                 }
00295         }
00296 
00297         PEng->World = World;
00298         //geWorld_CreateRef(World);
00299 
00300         return PEng;                                                                                             
00301 
00302         ExitWithError:
00303 
00304                 geErrorLog_AddString(-1,"ProcEng_Create : failure!", NULL);
00305 
00306                 if (PEng)
00307                 {
00308                         ProcEng_Destroy(&PEng);
00309                 }
00310                         
00311                 return NULL;
00312 }

void ProcEng_Destroy ProcEng **  pPEng  ) 
 

Definition at line 317 of file proceng.c.

References ProcEng_Proc::Bitmap, Procedural_Table::Destroy, ProcEng_PTable::DllHandle, geBitmap_Destroy(), geRam_Free, int32, NULL, ProcEng::NumProcs, ProcEng::NumPTables, ProcEng_Proc::Proc, ProcEng::Procs, ProcEng::PTables, ProcEng_Proc::Table, and ProcEng::World.

Referenced by GameMgr_FreeWorld(), and ProcEng_Create().

00318 {
00319         int32                   i;
00320         ProcEng_Proc    *pProc;
00321         ProcEng_PTable  *pTable;
00322         ProcEng                 *PEng;
00323 
00324         assert(pPEng);
00325 
00326         PEng = *pPEng;
00327         if ( ! PEng )
00328                 return;
00329         
00330         // Free all the allocated procs
00331         pProc = PEng->Procs;
00332         for (i=0; i< PEng->NumProcs; i++, pProc++)
00333         {
00334                 assert(pProc->Table);
00335                 assert(pProc->Proc);
00336 
00337                 pProc->Table->Destroy(pProc->Proc);
00338 
00339                 geBitmap_Destroy(&(pProc->Bitmap)); // we did creatref
00340 
00341                 memset(pProc, 0, sizeof(*pProc));       
00342         }
00343         PEng->NumProcs = 0;
00344 
00345         // Free all the table dlls...
00346         pTable = PEng->PTables;
00347         for (i=0; i< PEng->NumPTables; i++, pTable++)
00348         {
00349                 if ( pTable->DllHandle )
00350                 {
00351                         FreeLibrary(pTable->DllHandle);
00352                 }
00353                 memset(pTable, 0, sizeof(*pTable));
00354         }
00355         PEng->NumPTables = 0;
00356 
00357         //if (PEng)
00358         //      geWorld_Free(PEng->World);
00359         PEng->World = NULL;
00360 
00361         geRam_Free(PEng);
00362 
00363         *pPEng = NULL;
00364 }

geBoolean ProcEng_Minimize ProcEng PEng  ) 
 

Definition at line 369 of file proceng.c.

References ProcEng_PTable::DllHandle, GE_TRUE, geBoolean, ProcEng::NumPTables, ProcEng::PTables, and ProcEng_PTable::Uses.

00370 {
00371 ProcEng_PTable  *pTable;
00372 ProcEng_PTable  *pTableLast;
00373 
00374         assert(PEng);
00375 
00376         // Free all the table dlls...
00377         pTable = PEng->PTables;
00378         pTableLast = pTable + (PEng->NumPTables - 1);
00379         while( pTable <= pTableLast )
00380         {
00381                 if ( pTable->Uses < 1 )
00382                 {
00383                         if ( pTable->DllHandle )
00384                         {
00385                                 FreeLibrary(pTable->DllHandle);
00386                         }
00387                         *pTable = *pTableLast;
00388                         pTableLast--;
00389                         PEng->NumPTables --;
00390                 }
00391                 else
00392                 {
00393                         pTable ++;
00394                 }
00395         }
00396         return GE_TRUE;
00397 }


Generated on Tue Sep 30 12:37:57 2003 for GTestAndEngine by doxygen 1.3.2