cs sdk v 1.14 released

Home  |  Product  |  Documents  |  Tutorials  |  FAQ |   Download  |   Forum |   Contacts  |   Link  


  Cross Suit

 Cross Suit SDK

 Documents
      classes
 Starting...
           Tutorials

 LUA tutorials

   Support

  Forum
  q&a

 Product parts

 Virtual File system

 Virtual Render
 Virtual Machine
   

  Demo Games

   

 3D Engine

  gvSystem(dx9)

 Link

 

 

gv_system.h

Go to the documentation of this file.
00001 #pragma once
00002 //
00003 //#define _DEBUG
00004 //
00005 #include <vector>
00006 #include <algorithm>
00007 #include <queue>
00008 #include <map>
00009 #include <stdio.h>
00010 //#include <stdarg.h>
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 #ifndef __POINTERARRAY_H__
00049 #include "PtrArray.H"
00050 #endif
00051 */
00052 //#include "GVZ.H"
00053 
00054 #include "gm_timer.h"
00055 
00056 
00057 #define LOGFILE         "console.log"
00058 #define MAXMSGS         1024
00059 #define MSGLENGHT       256
00060 
00061 //
00062 // Generic Output Device
00063 //
00064 class IOutputDevice {
00065 public:
00066 // Ãß°¡.
00067         virtual ~IOutputDevice(void) {};
00068 //      
00069         virtual void Insert(const char *str, ...){};
00070 };
00071 
00072 
00073 //
00074 // Generic Output Devide for errors
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         Definitions:
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 //      float operator () { return fvalue; };
00107 //      int operator () { return ivalue;};
00108         //
00109 /*      virtual float operator/(float f) { return fvalue/f; }
00110         virtual int operator/(int i) { return ivalue/i; }
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 //      Var *   next;   // if next is here, the cost of recorrer the list is very hight, because
00148                                         // vars are stored in very different places of the memory.
00149 };
00150 
00151 
00152 
00153 //
00154 // Variable Sytem Interface
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         // query methods:
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         Classes:
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 //#ifndef WIN32
00197 //      FILE * ErrorStream;// = stdout;
00198 //#endif
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;  // FIXME: export a timer interface, instead the timer itself
00215 #else
00216         class gvTimer_LINUX*            timer;  // FIXME: export a timer interface, instead the timer itself
00217 #endif
00218         class IErrorDevice *    error;
00219         class IOutputDevice *   out;
00220 //      class IInput *  input;
00221 
00222 };
00223 
00224 //
00225 // ¾ÐÃà ÆÄÀÏ °ü·Ã Ŭ·¡½º
00226 //
00227 
00228 
00229 
00230 /*---------------------------------------------------------------------------
00231         Definitions:
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         Definici? de funciones locales.
00245 ---------------------------------------------------------------------------*/
00246 extern char  * UnZip( FILE *h );
00247 
00248 
00249 
00250 
00251 /*---------------------------------------------------------------------------
00252         Types
00253 ---------------------------------------------------------------------------*/
00254 
00255 //
00256 //      Typical string list
00257 //
00258 typedef struct _searchPath{
00259         char path[MAX_FILEPATH];
00260 } searchPath;
00261 
00262 
00263 //#pragma pack( push, before_ZIPStructs )
00264 //#pragma pack(1)
00265 
00266 #define ZIPHeaderSig    0x04034b50
00267 typedef struct _ZIPHeader
00268 {
00269         LONG    Signature;                 //  (0x04034b50)
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 typedef struct {
00282 
00283 char a;
00284 
00285 int b;
00286 
00287 } __attribute__(packed) myST;
00288 
00289 */
00290 
00291 #define ZIPCtrlHeaderSig        0x02014b50
00292 typedef struct  
00293 {
00294         LONG    Signature;                 //  (0x02014b50)
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;                 //  (0x06054b50)
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 //#pragma pack( pop, before_ZIPStructs )
00327 
00328 
00329 
00330 
00331 //
00332 //      Global file acces functions
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 // Read-only virtual file
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         //aes °ü·Ã.
00363         int IsAes(void)
00364         {
00365                 return 0;
00366         }
00367 };
00368 
00369 // not using...
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 // Inserts strings into a file
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 // 2001/11/01 Ãß°¡ À©µµ Àӽà µð·ºÅ丮¸¦ ã¾Æ »ý¼ºÇÑ´Ù.
00400 #ifdef WIN32
00401 /*class DumpTempFile : public DumpFile 
00402 {
00403 public:
00404         DumpTempFile(char *name);
00405         ~DumpTempFile();
00406 
00407 };
00408 */
00409 #endif
00410 
00411 //
00412 // Searchs for a filenames given a pattern
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;                                             // io handle
00425 #else
00426         DIR*    handle;
00427         struct stat file_stat;
00428         struct dirent *dirp;    
00429 #endif
00430         char *pattern;
00431         char *temp_pat;                                 // last pattern used.
00432         searchPath *last;                                       // last path searched.
00433         int     pathcount;
00434         char lastpath[MAX_FILEPATH];    // this will save the name of the last path until f_FindNext is called.
00435 };
00436 
00437 
00438 
00439 /*---------------------------------------------------------------------------
00440         Types:
00441 ---------------------------------------------------------------------------*/
00443 typedef struct _command 
00444 {
00445         char *name;
00446         void (*bind)();
00447 } command;
00448 
00449 
00450 /*---------------------------------------------------------------------------
00451         Functions:
00452 ---------------------------------------------------------------------------*/
00453 
00454 //
00455 //      Initializes command list with some trivial commands (set, echo, ...)
00456 //
00457 void InitCommonCommands();
00458 
00459 
00460 
00461 
00462 
00463 /*---------------------------------------------------------------------------
00464         Classes:
00465 ---------------------------------------------------------------------------*/
00466 
00467 //
00468 //      List of commands
00469 //
00470 class CmdList 
00471 {
00472 public:
00473         CmdList();
00474         ~CmdList();
00475         void Add(command  *c);
00476         int Exec(const char *name);// returns true if cmd found and exec
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 //      Parses a command file automatically
00489 class CmdFile : public VFile 
00490 {
00491 public:
00492         //##ModelId=3B9E68D9004F
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); // Ãß°¡ÇÔ.2005/11/02
00511         static char token[MAXMSGS];                             // buffer for tokens
00512         static char comment[MAXMSGS];                           // buffer for tokens
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); // Ãß°¡ÇÔ.2005/11/02
00538         char token[MAXMSGS];                            // buffer for tokens
00539         char comment[MAXMSGS];                          // buffer for tokens
00540         int scriptline;
00541 
00542 protected:
00543 public:
00544         VFile *file;
00545 protected:
00546         BYTE *buffer;
00547         BYTE *buf_end;
00548 };
00549 
00550 //
00551 // VARS
00552 //
00553 
00554 /*-----------------------------------------------------------------------------
00555         Variable list:
00556 -----------------------------------------------------------------------------*/
00557 // ¸®½ºÆ® ±¸Á¶Ã¼¿¡¼­ Æ÷ÀÎÅÍ ¾î·¹ÀÌ·Î ¹Ù…f´Ù.
00558 // 
00559 class vars : public ivars {
00560 private:
00561         gvList<Var*> var_arr;
00562         //geArray<Var*> var_arr;
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         // Create a temporal variable.
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         // Register a variable if it doesnt exists. If it exists and is temporal replace it.
00581         //
00582         bool RegisterVar(Var* var);
00583         void UnregisterVar(Var* var);
00584         // query methods:
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;  // global vars
00594 
00595 
00596 // Input °ü·Ã stdinput / DirectX Input »ç¿ë
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         Interfaces:
00625 ---------------------------------------------------------------------------*/
00626 /*
00627 //
00628 // Memory allocator.
00629 //
00630 class IAlloc 
00631 {
00632 public:
00633 
00634         virtual void Init(){};
00635         virtual void Shut(){};
00636         virtual void * Malloc( DWORD count, const char* Tag ){};
00637         virtual void * Realloc( void *mem, DWORD count, const char* Tag ){};
00638         virtual void Free( void *mem ){};
00639         virtual void DumpAllocs(){};
00640         virtual void HeapCheck(){};
00641 };
00642 */
00643 
00644 
00645 /*---------------------------------------------------------------------------
00646         Functions:
00647 ---------------------------------------------------------------------------*/
00648 /*
00649 inline void *Align( void *ptr, INT alignment ) 
00650 {
00651         return (void *)(((DWORD)ptr + alignment - 1) & ~(alignment-1));
00652 }
00653 */
00654 
00655 /*
00656 
00657 class TSimpleAlloc : public IAlloc 
00658 {
00659 private:
00660         int allocations;
00661 
00662 public:
00663         virtual void Init();
00664         virtual void Shut();
00665         virtual void * Malloc( DWORD count, const char *Tag );
00666         virtual void * Realloc( void* mem, DWORD count, const char *Tag );
00667         virtual void Free( void* mem );
00668         virtual void DumpAllocs();
00669         virtual void HeapCheck();
00670 };
00671 //
00672 //
00673 //
00674 
00675 //extern TSimpleAlloc GMalloc;
00676 
00677 
00678 //#define appMalloc     GMalloc.Malloc
00679 //#define appFree       GMalloc.Free
00680 //#define appRealloc    GMalloc.Realloc
00681 
00682 void* appMalloc( DWORD count, const char *Tag);
00683 void appFree( void* mem );
00684 void * appRealloc( void* mem, DWORD count, const char *Tag );
00685 //
00686 // C++ style memory allocation.
00687 //
00688 //#if !defined(_MemoryLeak_Defined_)
00689 inline void* operator new( unsigned int size )
00690 {
00691         return appMalloc( size, TEXT("new"));
00692 }
00693 inline void operator delete( void* ptr )
00694 {
00695         appFree( ptr );
00696 }
00697 
00698 inline void* operator new[]( unsigned int size )
00699 {
00700         return appMalloc( size, TEXT("new[]") );
00701 }
00702 
00703 inline void operator delete[]( void* ptr )
00704 {
00705         appFree( ptr );
00706 }
00707 */
00708 //#endif
00709 //
00710 // UNZIP
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 class gvRender
00778 {
00779 public:
00780         virtual ~gvRender(void) {};
00781 //
00782         virtual void init(int w, int h, int bpp){};
00783         virtual void shut(void){};
00784         virtual void flush(void){};
00785 // 
00786         virtual void addvertex(void* pvoid){};
00787 //
00788         virtual bool createtexture(int w, int h, int bpp){};
00789         virtual bool removetexture(int idx){};
00790         virtual void* gettexture(int idx){};
00791         virtual void settexture(int state){};
00792 //      
00793 };
00794 
00795 class gvRenderDX9 : public gvRender
00796 {
00797 };
00798 class gvRenderHB3 : public gvRender
00799 {
00800 
00801 };
00802 
00803 */
00804 

Copyright(C) gvSystem & GamePlus All Rights Reserved.