00001 #pragma once
00002
00003
00004
00005 #include <vector>
00006 #include <algorithm>
00007 #include <queue>
00008 #include <map>
00009 #include <stdio.h>
00010
00011 #ifndef WIN32
00012 #include <dirent.h>
00013 #endif
00014
00015 #include <sys/stat.h>
00016 #if defined(FEATURE_WIPI20)
00017 #include "UnknowProject0wipi/clet_types.h"
00018 #endif
00019
00020 #ifndef __GDEFINE_H__
00021 #include "GDEFINE.H"
00022 #endif
00023
00024 #include "gv_types.h"
00025
00026 #ifdef _DEBUG
00027 void _trace(char *fmt, ...);
00028 #define gv_assert(x) {if(!(x)) _asm{int 0x03}}
00029 #define gv_verify(x) {if(!(x)) _asm{int 0x03}}
00030 #define gv_assert_true(x) {if(x) printf("CriticalError [%s][%d][%s]",__FILE__, (DWORD)__LINE__,"check_debug");exit(1); }
00031 #else
00032 #define gv_assert(x)
00033 #define gv_verify(x) x
00034 #define gv_assert_true(x) //{if((x)) printf("CriticalError [%s][%d][%s]",__FILE__, (DWORD)__LINE__,"check"); }
00035 #endif
00036
00037
00038 #ifdef _DEBUG
00039 #define gv_trace _trace
00040 #else
00041 inline void _trace(char* fmt, ...) { }
00042 #define gv_trace 1 ? (void)0 : _trace
00043 #endif
00044
00045 #include "gv_arraylist.h"
00046
00047
00048
00049
00050
00051
00052
00053
00054 #include "gm_timer.h"
00055
00056
00057 #define LOGFILE "console.log"
00058 #define MAXMSGS 1024
00059 #define MSGLENGHT 256
00060
00061
00062
00063
00064 class IOutputDevice {
00065 public:
00066
00067 virtual ~IOutputDevice(void) {};
00068
00069 virtual void Insert(const char *str, ...){};
00070 };
00071
00072
00073
00074
00075
00076 class IErrorDevice {
00077 public:
00078
00079 virtual ~IErrorDevice(void) {};
00080
00081 virtual void Log(const int error, const char *, ...){};
00082 virtual void Debug(const int error, const char *, ...){};
00083 virtual void Box(const int error, const char *, ...){};
00084 virtual void CriticalError(const int error, const char *, ...){};
00085 };
00086
00087
00088
00089
00090
00091
00092
00093
00094 class Var
00095 {
00096 public:
00097
00098 Var(const char *name, int ivalue=0, int flags=0);
00099 Var(const char *name, float fvalue, int flags=0);
00100 Var(const char *name, const char *svalue, int flags=0);
00101 virtual ~Var(void);
00102 virtual void SetString(const char *svalue);
00103 virtual void SetInteger(int ivalue);
00104 virtual void SetFloat(float fvalue);
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 float operator/(float f) { return fvalue/f; }
00115 float operator*(float f) { return fvalue*f; }
00116 float operator-(float f) { return fvalue-f; }
00117 float operator+(float f) { return fvalue+f; }
00118
00119
00120 int operator/(int i) { return ivalue/i; }
00121 int operator*(int i) { return ivalue*i; }
00122
00123 int operator-(int i) { return ivalue-i; }
00124 int operator+(int i) { return ivalue+i; }
00125
00126
00127
00128 virtual void operator= ( class Var );
00129 virtual int operator= ( const int ivalue );
00130 virtual float operator= ( const float fvalue );
00131 virtual void operator= ( const char *svalue );
00132 virtual int operator== ( const char *svalue );
00133 virtual bool operator== ( const int ivalue );
00134 virtual bool operator== ( const float fvalue );
00135
00136 virtual bool CheckLatch(bool bFlag);
00138 char * name;
00139 float fvalue;
00140 int ivalue;
00141 char * svalue;
00142 int flags;
00143 char * comment;
00144
00145 virtual void SetComment(const char *szvalue);
00146
00147
00148
00149 };
00150
00151
00152
00153
00154
00155
00156 class ivars
00157 {
00158 public:
00159
00160 virtual ~ivars(void) {};
00161
00162
00163 virtual bool SetKeyValue(const char *name, const char *szString, int flags=0){return 0;};
00164 virtual bool SetKeyValue(const char *name, const float value, int flags=0){return 0;};
00165 virtual bool SetKeyValue(const char *name, const int value, int flags=0){return 0;};
00166
00167 virtual bool RegisterVar(Var* var){return 0;};
00168 virtual void UnregisterVar(Var* var){};
00169
00170
00171 virtual char * StringForKey(const char * name){return 0;};
00172 virtual float ValueForKey(const char * name){return 0;};
00173 virtual int IntForKey(const char * name, int defaultValue=0){return 0;};
00174 virtual void WriteToFile(const char* filename){};
00175 };
00176
00177
00178
00179
00180
00181
00182 class Error : public IErrorDevice, IOutputDevice {
00183 public:
00184 Error(IOutputDevice *);
00185 void Insert(const char *, ...);
00186 void Log(const int error, const char *, ...);
00187 void Debug(const int error, const char *, ...);
00188 void Box(const int error, const char *, ...);
00189 void CriticalError(const int error, const char *, ...);
00190
00191 int GetLastError(){return LastError;};
00192
00193 char ErrorString[MAXMSGS];
00194
00195 private:
00196
00197
00198
00199 int LastError;
00200
00201 IOutputDevice *out;
00202 };
00203
00204
00208 class Framework
00209 {
00210 public:
00211 class ivars * cvars;
00212 class IOutputDevice * console;
00213 #ifdef _WIN32
00214 class gvTimer_Win32* timer;
00215 #else
00216 class gvTimer_LINUX* timer;
00217 #endif
00218 class IErrorDevice * error;
00219 class IOutputDevice * out;
00220
00221
00222 };
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234 #define GV_MSG_ERROR_LOADING 1
00235 #define GV_MSG_ERROR_ALLOCATING 2
00236
00237 #define MAX_FILEPATH 1024
00238 #define CONSOLE_LINE 1024
00239 #define FILE_NAME 256
00240
00241
00242
00243
00244
00245
00246 extern char * UnZip( FILE *h );
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258 typedef struct _searchPath{
00259 char path[MAX_FILEPATH];
00260 } searchPath;
00261
00262
00263
00264
00265
00266 #define ZIPHeaderSig 0x04034b50
00267 typedef struct _ZIPHeader
00268 {
00269 LONG Signature;
00270 WORD Version;
00271 WORD Flags;
00272 WORD Method;
00273 LONG LastMod;
00274 LONG CRC32;
00275 LONG CompressedSize;
00276 LONG UnCompressedSize;
00277 WORD FileNameLength;
00278 WORD ExtraLength;
00279 } ZIPHeader;
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291 #define ZIPCtrlHeaderSig 0x02014b50
00292 typedef struct
00293 {
00294 LONG Signature;
00295 WORD VersionMade;
00296 WORD VersionNeeded;
00297 WORD Flags;
00298 WORD Method;
00299 LONG LastMod;
00300 LONG CRC32;
00301 LONG CompressedSize;
00302 LONG UnCompressedSize;
00303 WORD FileNameLength;
00304 WORD ExtraLength;
00305 WORD CommentLength;
00306 WORD StartDisk;
00307 WORD IniternalAttribs;
00308 LONG ExternalAttribs;
00309 LONG Offset;
00310 } ZIPCtrlHeader;
00311
00312 #define ZIPEndSig 0x06054b50
00313 typedef struct _ZIPEnd
00314 {
00315 LONG Signature;
00316 WORD DiskNumber;
00317 WORD StartDiskNumber;
00318 WORD FilesOnDisk;
00319 WORD Files;
00320 LONG Size;
00321 LONG Offset;
00322 WORD CommentLength;
00323 } ZIPEnd;
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334 class FileEnvironment
00335 {
00336 public:
00337 static void Init();
00338 static void Shut();
00339 static void AddAppointmentPath(const char *path);
00340 static void AddPath(const char *path=0x00);
00341 static void LoadPacks();
00342 static geArray<searchPath*> Search;
00343 static char main_path[MAX_FILEPATH];
00344 };
00345
00346
00347
00348
00349
00350 class VFile : public FileEnvironment
00351 {
00352 public:
00353 VFile(const char *name, bool pak_search=true,bool err_msg=true,bool enc=false);
00354 ~VFile();
00355 char fname[FILE_NAME];
00356 BYTE * mem;
00357 int size;
00358 int error;
00359 int loadedfrom;
00360
00361
00362
00363 int IsAes(void)
00364 {
00365 return 0;
00366 }
00367 };
00368
00369
00370 class VFile2 : public FileEnvironment
00371 {
00372 public:
00373 VFile2(const char *name, bool pak_search=true);
00374 ~VFile2();
00375 char fname[FILE_NAME];
00376 BYTE * mem;
00377 int size;
00378 int error;
00379 int loadedfrom;
00380 };
00381
00383
00384
00385
00386 class DumpFile : public IOutputDevice {
00387 public:
00388 DumpFile(const char *name,bool bTemp=0);
00389 ~DumpFile();
00390
00391 void Insert(const char *str, ...);
00392 private:
00393 int FileCreated;
00394 protected:
00395 FILE *fp;
00396 char InsertCad[MAXMSGS];
00397 };
00398
00399
00400 #ifdef WIN32
00401
00402
00403
00404
00405
00406
00407
00408
00409 #endif
00410
00411
00412
00413
00414 class SearchFile
00415 {
00416 public:
00417 SearchFile(char *pattern="*");
00418 ~SearchFile();
00419
00420 char *FirstFile();
00421 char *NextFile();
00422 private:
00423 #ifdef WIN32
00424 int handle;
00425 #else
00426 DIR* handle;
00427 struct stat file_stat;
00428 struct dirent *dirp;
00429 #endif
00430 char *pattern;
00431 char *temp_pat;
00432 searchPath *last;
00433 int pathcount;
00434 char lastpath[MAX_FILEPATH];
00435 };
00436
00437
00438
00439
00440
00441
00443 typedef struct _command
00444 {
00445 char *name;
00446 void (*bind)();
00447 } command;
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457 void InitCommonCommands();
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470 class CmdList
00471 {
00472 public:
00473 CmdList();
00474 ~CmdList();
00475 void Add(command *c);
00476 int Exec(const char *name);
00477 void Dump(void);
00478 private:
00479 geArray<command*> list;
00480 };
00481
00482 void GV_COMMAND_ADD(const char* commandString, void (*funcBind)());
00483
00484
00485
00489 class CmdFile : public VFile
00490 {
00491 public:
00492
00493 CmdFile(const char *name);
00494 };
00495
00496
00497
00498
00500 class Parser
00501 {
00502 public:
00503 static bool StartParseFile(char *name);
00504 static void StartParseBuffer(BYTE *buffer,int size);
00505 static void StartParseString(char *szString);
00506
00507 static void StopParseFile();
00508
00509 static bool GetToken(bool crossline);
00510 static bool GetLine(void);
00511 static char token[MAXMSGS];
00512 static char comment[MAXMSGS];
00513 static int scriptline;
00514
00515 protected:
00516 public:
00517 static VFile *file;
00518 protected:
00519 static BYTE *buffer;
00520 static BYTE *buf_end;
00521
00522
00523 };
00524
00525
00526 class Parser_NoStatic
00527 {
00528 public:
00529 Parser_NoStatic(void);
00530 ~Parser_NoStatic(void);
00531 bool StartParseFile(char *name);
00532 void StartParseBuffer(BYTE *buffer,unsigned int size);
00533 void StartParseString(char *szString);
00534 void StopParseFile();
00535
00536 bool GetToken(bool crossline);
00537 bool GetLine(void);
00538 char token[MAXMSGS];
00539 char comment[MAXMSGS];
00540 int scriptline;
00541
00542 protected:
00543 public:
00544 VFile *file;
00545 protected:
00546 BYTE *buffer;
00547 BYTE *buf_end;
00548 };
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559 class vars : public ivars {
00560 private:
00561 gvList<Var*> var_arr;
00562
00563 public:
00564 vars ();
00565 virtual ~vars ();
00566 char* FixupName(char* name);
00567 virtual void WriteToFile(char *filename);
00568 void Dump(IOutputDevice *out);
00569
00570
00571
00572 void CreateVarIGNORE(const char *name, const char *szString, char *comment, int flags=0);
00573 void CreateVar(const char *name, const char *szString, char *comment, int flags=0);
00574 void CreateVar(const char *name, float fvalue, char *comment, int flags=0);
00575 void CreateVar(const char *name, int ivalue, char *comment, int flags=0);
00576 bool SetKeyValue(const char *name, const char *szString, int flags=0);
00577 bool SetKeyValue(const char *name, const float value, int flags=0);
00578 bool SetKeyValue(const char *name, const int value, int flags=0);
00579
00580
00581
00582 bool RegisterVar(Var* var);
00583 void UnregisterVar(Var* var);
00584
00585 char * StringForKey(const char * name);
00586 float ValueForKey(const char * name);
00587 int IntForKey(const char * name, int defaultValue=0);
00588 bool isKey(const char *name);
00589
00590 Var* getpVar(char* varName);
00591 };
00592
00593 extern vars * cvars;
00594
00595
00596
00597
00598
00599 typedef enum _MOUSE_BUTTON {
00600 LEFT_MBUTTON,
00601 RIGHT_MBUTTON,
00602 MIDDLE_MBUTTON
00603 }MOUSE_BUTTON;
00604
00608 typedef enum _B_STATE {
00609 BUTTON_DOWN,
00610 BUTTON_UP,
00611 BUTTON_RELEASED,
00612 BUTTON_PRESSED
00613 }B_STATE;
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716 void f_DosToUnixName(char *name);
00717 void f_UnixToDosName(char *name);
00718
00719 char * f_Name(char *path);
00720 void f_StripName(char *path);
00721 char * f_Extension(char *name);
00722 void f_StripExtension (char *path);
00723
00724
00725 extern CmdList Commands;
00726 extern gv_iTimer *timer;
00727 extern Framework Import;
00728 extern IOutputDevice *out;
00729
00730
00731
00732
00733
00734 class gv_CK_RLE
00735 {
00736 public:
00737 gv_CK_RLE(void);
00738 virtual ~gv_CK_RLE(void);
00739
00740 unsigned char *compress(unsigned char *inputBuffer,int inputNumBytes, int &compressedNumBytes);
00741 int decompress(unsigned char *inputBuffer,int inputNumBytes,unsigned char *outputBuffer,int &outputNumBytes);
00742 };
00743
00744
00745 class button_one
00746 {
00747 private:
00748 char flag[2];
00749 int bclick;
00750 short current_state;
00751 bool m_bActive;
00752 public:
00753
00754 button_one(void);
00755 ~button_one(void);
00756 void Active(bool bActive);
00757 bool IsActive(void);
00758 void click_down(void);
00759 void onclient(void);
00760 void click_up(void);
00761 void update(void);
00762 B_STATE isbutton(void);
00763 };
00764
00765 bool gvCommandFile(const char* szCommandFileName);
00766
00767 int gv_CompressZ(unsigned char* dest,unsigned long* destLen,unsigned char* src, unsigned long srcLen);
00768 int gv_DeCompressZ(unsigned char* dest,unsigned long* destLen,unsigned char* src, unsigned long srcLen);
00769
00770 float gv_getFPS(void);
00771
00772 void var_list_cmd(void);
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804