#include <stdlib.h>#include <math.h>#include <Assert.h>#include <ctype.h>#include <windows.h>#include "Genesis.h"#include "Ram.h"#include "Errorlog.h"#include "Stdio.h"#include "String.h"#include "ProcEng.h"#include "Procedural.h"Go to the source code of this file.
|
|
Definition at line 31 of file proceng.c. Referenced by ProcEng_AddProcedural(). |
|
|
|
|
|
Definition at line 69 of file proceng.c. Referenced by ProcEng_Create(). |
|
|
Definition at line 68 of file proceng.c. Referenced by ProcEng_Create(). |
|
|
|
|
|
Definition at line 25 of file proceng.c. Referenced by ProcEng_Create(). |
|
|
|
|
|
|
|
|
|
|
||||||||||||||||||||
|
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 }
|
|
||||||||||||
|
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 }
|
|
||||||||||||
|
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 }
|
|
|
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 }
|
|
|
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 }
|
|
||||||||||||
|
Definition at line 562 of file proceng.c. References NULL.
00563 {
00564
00565 while ( *StrBase )
00566 {
00567 if ( toupper(*StrBase) == toupper(*SubBase) )
00568 {
00569 const char * Str,* Sub;
00570 Str = StrBase + 1;
00571 Sub = SubBase + 1;
00572 while ( *Sub && toupper(*Sub) == toupper(*Str) )
00573 {
00574 Sub++; Str++;
00575 }
00576 if ( ! *Sub) return((char *)StrBase);
00577 }
00578 StrBase++;
00579 }
00580
00581 return(NULL);
00582 }
|
|
|
Definition at line 529 of file proceng.c. References geVFile_Read(), and uint8. Referenced by VFile_ReadBetween(), and VFile_SeekPastSpaces().
00530 {
00531 uint8 Char;
00532 if ( ! geVFile_Read(File,&Char,1) )
00533 return -1;
00534 return (int)Char;
00535 }
|
|
||||||||||||||||||||
|
Definition at line 584 of file proceng.c. References GE_FALSE, GE_TRUE, geBoolean, VFile_GetC(), VFile_SeekPastSpaces(), and VFile_UnGetC(). Referenced by ProcEng_Create().
00585 {
00586 int c;
00587 int ins;
00588
00589 Into[0] = 0;
00590
00591 if ( ! VFile_SeekPastSpaces(File) )
00592 return GE_FALSE;
00593
00594 if ( (c = VFile_GetC(File)) == Start )
00595 {
00596 char *p;
00597 ins = 1;
00598 p = Into;
00599 for(;;)
00600 {
00601 c = VFile_GetC(File);
00602 if ( c == -1 )
00603 {
00604 *p = 0;
00605 return GE_FALSE;
00606 }
00607 *p = c;
00608 if ( c == Start ) ins ++;
00609 else if ( c == Stop ) ins --;
00610 if ( ins == 0 ) break;
00611 p++;
00612 }
00613 *p = 0;
00614 }
00615 else
00616 {
00617 if ( c == -1 )
00618 return GE_FALSE;
00619 else
00620 VFile_UnGetC(File);
00621 }
00622
00623 return GE_TRUE;
00624 }
|
|
|
Definition at line 542 of file proceng.c. References GE_FALSE, GE_TRUE, GE_VFILE_SEEKSET, geBoolean, geVFile_Seek(), geVFile_Tell(), VFile_GetC(), and VFile_UnGetC(). Referenced by ProcEng_Create(), VFile_ReadBetween(), and VFile_SeekPastString().
00543 {
00544 long LastPosition;
00545 int Char;
00546
00547 if ( ! geVFile_Tell(File,&LastPosition) )
00548 return GE_FALSE;
00549
00550 while( (Char = VFile_GetC(File)) != -1 )
00551 {
00552 if ( ! isspace(Char) )
00553 {
00554 VFile_UnGetC(File);
00555 return GE_TRUE;
00556 }
00557 }
00558 geVFile_Seek(File,LastPosition,GE_VFILE_SEEKSET);
00559 return GE_FALSE;
00560 }
|
|
||||||||||||
|
Definition at line 493 of file proceng.c. References GE_FALSE, GE_TRUE, GE_VFILE_SEEKCUR, GE_VFILE_SEEKSET, geBoolean, geVFile_Read(), geVFile_Seek(), geVFile_Tell(), and VFile_SeekPastSpaces(). Referenced by ProcEng_Create().
00494 {
00495 long LastPosition;
00496 char Buf[1024];
00497 int len;
00498
00499 if ( strlen(str) == 0 )
00500 return GE_FALSE;
00501
00502 if ( ! geVFile_Tell(File,&LastPosition) )
00503 return GE_FALSE;
00504
00505 for(;;)
00506 {
00507 if ( ! VFile_SeekPastSpaces(File) )
00508 goto fail;
00509
00510 len = strlen(str);
00511 if ( ! geVFile_Read(File,Buf,len) )
00512 goto fail;
00513 Buf[len] = 0;
00514
00515 if ( stricmp(Buf,str) == 0 )
00516 return GE_TRUE;
00517
00518 len = 1 - len;
00519 if ( ! geVFile_Seek(File,len,GE_VFILE_SEEKCUR) )
00520 goto fail;
00521 }
00522
00523 fail:
00524
00525 geVFile_Seek(File,LastPosition,GE_VFILE_SEEKSET);
00526 return GE_FALSE;
00527 }
|
|
|
Definition at line 537 of file proceng.c. References GE_VFILE_SEEKCUR, and geVFile_Seek(). Referenced by VFile_ReadBetween(), and VFile_SeekPastSpaces().
00538 {
00539 geVFile_Seek(File,-1,GE_VFILE_SEEKCUR);
00540 }
|
|
|
Definition at line 27 of file proceng.c. Referenced by ProcEng_Create(). |
|
|
Definition at line 28 of file proceng.c. Referenced by ProcEng_Create(). |
1.3.2