SIBCUtil.h

00001 //***************************************************************************************
00002 //
00003 // File supervisor: Softimage 3D Games & 3D Bridge team
00004 //
00005 // (c) Copyright 1999-2002 Avid Technology, Inc. . All rights reserved.
00006 //
00007 // SIBCUtil.h | Main header file for SIBCUtil implementation
00008 //***************************************************************************************
00009 
00010 /****************************************************************************************
00011 THIS CODE IS PUBLISHED AS A SAMPLE ONLY AND IS PROVIDED "AS IS".
00012 IN NO EVENT SHALL SOFTIMAGE, AVID TECHNOLOGY, INC. AND/OR THEIR RESPECTIVE
00013 SUPPLIERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
00014 DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00015 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
00016 CONNECTION WITH THE USE OR PERFORMANCE OF THIS CODE .
00017 
00018 COPYRIGHT NOTICE. Copyright © 1999-2002 Avid Technology Inc. . All rights reserved. 
00019 
00020 SOFTIMAGE is a registered trademark of Avid Technology Inc. or its subsidiaries 
00021 or divisions. Windows NT is a registered trademark of Microsoft Corp. All other
00022 trademarks contained herein are the property of their respective owners. 
00023 ****************************************************************************************/
00024 
00025 //**************************************************************************************
00026 // Defines
00027 //**************************************************************************************
00028 #ifndef __CSIBCUtil_H__
00029 #define __CSIBCUtil_H__
00030 
00031 #if defined(unix) && (defined(WIN64) || defined(_WIN64) || defined(__x86_64))
00032 typedef unsigned int ULONG;
00033 typedef int LONG;
00034 #else
00035 typedef unsigned long ULONG;
00036 typedef long LONG;
00037 #endif
00038 
00039 #ifdef unix
00040   #include <string.h>
00041   #ifdef __APPLE__
00042     #include <math.h>
00043   #endif
00044 #endif
00045 
00046 #include <SIBCMath.h>
00047 
00048 #ifdef _WIN32
00049 #ifndef _XBOX
00050 #include <windows.h>
00051 #include <winuser.h>
00052 #else
00053 #include <xtl.h>
00054 #endif
00055 #endif
00056 
00057 //**************************************************************************************
00058 // Includes
00059 //**************************************************************************************
00060 #ifndef _WIN32_WCE
00061 #include <assert.h>
00062 #else
00063 #endif
00064 
00065 
00066 //**************************************************************************************
00067 // Typedefs
00068 //**************************************************************************************
00069 #ifndef _CUS_DLL
00070 
00080 typedef enum {
00081 
00082 
00083     SI_SUCCESS      =   0,      
00084 
00085     // general errors //
00086     SI_ERR_NONE     =   0,      
00087     SI_ERR_STATUS_MSG,          
00088     SI_ERR_MESSAGE_MSG,         
00089     SI_ERR_WARNING_MSG,         
00090     SI_ERR_ERROR_MSG,           
00091     SI_ERR_MODE_MSG,            
00092     SI_ERR_INTERNAL,            
00093     SI_ERR_NOTYETIMPLEMENTED,   
00094     SI_ERR_NOTSUPPORTED,        
00095 
00096     // argument check //
00097     SI_ERR_BAD_MDLTYPE,     
00098     SI_ERR_BAD_CHAPID,      
00099     SI_ERR_BAD_GROUPID,     
00100     SI_ERR_BAD_GROUPLIST,   
00101     SI_ERR_BAD_ELEMENT,     
00102     SI_ERR_BAD_DICTIONARY,  
00103     SI_ERR_BAD_RELID,       
00104     SI_ERR_BAD_ARGUMENT,    
00105     SI_ERR_BAD_DATABASE,    
00106     SI_ERR_BAD_RELNDX,      
00107     SI_ERR_BAD_MSMSH,       
00108     SI_ERR_BAD_MFACE,       
00109     SI_ERR_BAD_MPTCH,       
00110     SI_ERR_BAD_MSPLN,       
00111     SI_ERR_BAD_PARAM,       
00112     SI_ERR_BAD_NBPARAM,     
00113     SI_ERR_BAD_NOPARAM,     
00114     SI_ERR_BAD_CHP4REL,     
00115     SI_ERR_BAD_SHAPEID,     
00116     SI_ERR_CLS_NOMODEL,     
00117     SI_ERR_LAT_NOMODEL,     
00118 
00119     // relations & rel resources //
00120     SI_ERR_RELRSRC_CANTOPEN,    
00121     SI_ERR_RELRSRC_INVGRP,      
00122     SI_ERR_RELRSRC_INVCHP,      
00123     SI_ERR_RELPAIR_CANTADD,     
00124     SI_ERR_RELPAIR_CANTDEL,     
00125     SI_ERR_REL_CANTDEL,         
00126 
00127     // dictionary //
00128     SI_ERR_ELEM_NOTFOUND,   
00129     SI_ERR_NAME_DUPL,       
00130     SI_ERR_NAME_FORMAT,     
00131 
00132     // file access //
00133     SI_ERR_DB_NOTFOUND,     
00134     SI_ERR_DB_INVALID,      
00135     SI_ERR_DB_CANTCREATE,   
00136     SI_ERR_DB_CANTDELETE,   
00137     SI_ERR_DBDELETE,        
00138     SI_ERR_ACCESS_CANTSET,  
00139     SI_ERR_SCENE_CANTREAD,  
00140     SI_ERR_SCENE_CANTWRITE, 
00141     SI_ERR_SCENE_CANTDEL,   
00142     SI_ERR_ELEM_CANTREAD,   
00143     SI_ERR_ELEM_CANTWRITE,  
00144     SI_ERR_SAVE_NOTROOT,    
00145     SI_ERR_NOVERS_FOUND,    
00146 
00147     // Data access and Conversion //
00148     SI_ERR_NUM_VERTICES,        
00149     SI_ERR_SHAPE_VERTICES,      
00150     SI_ERR_TOO_FEW_VERTICES,    
00151     SI_ERR_TOO_MANY_VERTICES,   
00152     SI_ERR_NULL_TRANSFO,        
00153     SI_ERR_NULL_VECTOR,         
00154     SI_ERR_BAD_COORDSYS,        
00155     SI_ERR_BAD_VNDX,            
00156     SI_ERR_CHAPNOTFOUND,        
00157     SI_ERR_FCVNOTFOUND,         
00158     SI_ERR_NOT_TRIANGULATED,    
00159 
00160     // Update list and animation //
00161     SI_ERR_CYCLE_DETECTED,      
00162 
00163     // Dynalink library //
00164     SI_ERR_DYNALINK_NOT_LOADED,     
00165     SI_ERR_DYNALINK_NOT_RESOLVED,   
00166     SI_ERR_DYNALINK_NOT_UNLOADED,   
00167 
00168     // Custom Value //
00169     SI_ERR_CUSVAL_SYMBOL_NOT_FOUND, 
00170     SI_ERR_CUSVAL_INCORRECT_TYPE,   
00171     SI_ERR_CUSVAL_BUFFER_TOO_SMALL, 
00172 
00173     // SAAPHIRE stuff //
00174     SI_ERR_ALLOC_PROBLEM,       
00175     SI_ERR_INVALID_SCENE,       
00176     SI_ERR_ELEM_UNSCENE,        
00177     SI_ERR_ELEM_TYPE,           
00178     SI_ERR_ELEM_ROOT,           
00179     SI_ERR_WRONG_COUNT,         
00180     SI_ERR_INVALID_LTYPE,       
00181     SI_ERR_NO_RESET,            
00182     SI_ERR_INVALID_SELEM,       
00183     SI_ERR_BAD_MATERIAL,        
00184     SI_ERR_INVALID_TESSELATION, 
00185     SI_ERR_NON_TESSELATABLE,    
00186     SI_ERR_INVALID_MODEL_DATA,  
00187     SI_ERR_NO_MATERIAL,         
00188     SI_ERR_NO_TEXTURE,          
00189     SI_ERR_ELEM_NOT_LEAF_NODE,  
00190     SI_ERR_ELEM_CANTDEL,        
00191     SI_ERR_FCURVE_EXISTS,       
00192     SI_ERR_ELEM_CHNROOT,        
00193     SI_ERR_ELEM_EFFECTOR,       
00194     SI_ERR_GOAL_NOT_SET,        
00195     SI_ERR_USERDATA_EXISTS,     
00196     SI_ERR_INVALID_INDEX,       
00197 
00198     // Opensyst //
00199     SI_ERR_CUS_SECOND_SYMBOL,   
00200     SI_ERR_CUS_NO_SYMBOL_NAME,  
00201 
00202     // DSO's //
00203     SI_ERR_CUSTOM_FATAL,        
00204 
00205     // DLL's //
00206     SI_ERR_UNFOUND_GLBSYMB_TAB, 
00207 
00208     // Graphic //
00209     SI_ERR_STOP,        
00210     SI_ERR_TXT_NAME,    
00211     SI_ERR_NO_CAM,      
00212 
00213     // Reason why a transformation is not applicable to a model //
00214     SI_ERR_TRANSFO_METASYSTEM,      
00215     SI_ERR_TRANSFO_PATCHDEFORM,     
00216     SI_ERR_TRANSFO_SPLINEDEFORM,    
00217     SI_ERR_SCAL_CHAIN,              
00218     SI_ERR_SCAL_CNSSCL,             
00219     SI_ERR_ROT_JOINT,               
00220     SI_ERR_ROT_CHNROOT,             
00221     SI_ERR_ROT_CNSORI,              
00222     SI_ERR_TRANS_CHNROOT,           
00223     SI_ERR_TRANS_JOINT,             
00224     SI_ERR_TRANS_DYNLEAF,           
00225     SI_ERR_TRANS_MAINGLOBENV,       
00226     SI_ERR_TRANS_CONSTRAINT,        
00227 
00228     // Additional SAAPHIRE error codes //
00229     SI_ERR_SUBELEM_TOTAL_FAILURE,   
00230     SI_ERR_SOFTIMAGE_TOO_OLD,       
00231     SI_ERR_SAAPHIRE_TOO_OLD,        
00232     SI_ERR_SAA_TOO_OLD_FOR_EFFECT,  
00233     SI_ERR_FILE_EXISTS,             
00234     SI_ERR_UNRELATED_T2D,           
00235     SI_ERR_INCOMPATIBLE_T2DMAP,     
00236     SI_ERR_SHADER_EXISTS,           
00237     SI_ERR_INCOMPAT_MAP_METHOD,     
00238     SI_ERR_MODEL_NO_SHAPES,         
00239     SI_ERR_CLUSTER_NO_KEYS,         
00240 
00241     // DSO's (no status bar message) //
00242     SI_ERR_CUSTOM_FATAL_NOMSG,      
00243     SI_ERR_NO_FCV_EDITOR,           
00244 
00245     // Render errors //
00246     SI_ERR_RENDER_WARNING,          
00247     SI_ERR_RENDER_ERROR,            
00248 
00249     // physical property Error //
00250     SI_ERR_MODEL_NO_PHYSPROPS,      
00251 
00252     // dialog errors //
00253     SI_ERR_EFFECT_NODG,     
00254     SI_ERR_DG_NOTFOUND,     
00255 
00256     // more render errors //
00257     SI_ERR_RENDER_VOLUNTARYEXIT,    
00258 
00259     // Audio support //
00260     SI_ERR_AUDIO_DEVICEINUSE,   
00261     SI_ERR_AUDIO_INVALIDFORMAT, 
00262     SI_ERR_AUDIO_INACTIVE,      
00263     SI_ERR_FILENOTFOUND,        
00264     SI_ERR_AUDIO_INVALIDTRACK,  
00265     SI_ERR_FILEPASSEDEOF,       
00266 
00267     // Action Support //
00268     SI_ERR_NO_ACTION,               
00269     SI_ERR_MARKER_NOTFOUND,         
00270     SI_ERR_ACTIONMARKERS_OVERLAP,   
00271 
00272     // More audio errors //
00273     SI_ERR_AUDIO_FILENOTSET,        
00274     SI_ERR_AUDIO_FILEALREADYSET,    
00275     SI_ERR_AUDIO_MIXINGNOTENABLED,  
00276 
00277     // Licensing //
00278     SI_ERR_LIC_INVALID_HANDLE,  
00279     SI_ERR_LIC_INVALID_ARGS,    
00280     SI_ERR_LIC_CHECKOUT,        
00281     SI_ERR_NUM,                 
00282 
00283     //XSI specific
00284     SI_FILE_NOT_FOUND,          
00285     SI_NO_AVAILABLE_DRIVER,     
00286     //Image Lib error
00287     SI_IMAGE_BAD_FORMAT     
00288 
00289 } eSI_Error;
00290 
00293 typedef int SI_Error;   
00294 
00297 #else
00298 
00299 //To be cross compatible with SAAphire
00300 #include <saa.h>
00301 
00302 #define SI_FILE_NOT_FOUND (SI_ERR_NUM + 1)
00303 #define SI_NO_AVAILABLE_DRIVER (SI_FILE_NOT_FOUND + 1)
00304 #endif
00305 
00310 #ifndef TRUE
00311 #define TRUE        1       
00312 #endif
00313 
00314 #ifndef FALSE
00315 #define FALSE       0       
00316 #endif
00317 
00318 #define SI_TRUE TRUE        
00319 #define SI_FALSE FALSE      
00323 // Already documented in SIBCMathLib.h
00324 #ifndef NULL
00325 #define NULL 0
00326 #endif
00327 
00335 #define SI_Bool     unsigned short      
00336 #define SI_Byte     char                
00337 #define SI_UByte    unsigned char       
00338 #define SI_Short    short               
00339 #define SI_UShort   unsigned short      
00340 #define SI_Int      int                 
00341 #define SI_UInt     unsigned int        
00342 #define SI_Float    float               
00343 #define SI_Double   double              
00344 #define SI_Long     int                 
00345 #define SI_Void     void                
00346 #define SI_ULong    unsigned int        
00347 typedef SI_Float    SI_Matrix[4][4];    
00348 /* @} */    // endgroup
00349 
00350 // CustomPset Data Type String. These are not used in the FTK.
00351 #define SI_CUSTOMPSET_PCHAR "Text"
00352 #define SI_CUSTOMPSET_BOOL  "Boolean"
00353 #define SI_CUSTOMPSET_INT   "Integer"
00354 #define SI_CUSTOMPSET_UBYTE "Small Integer Number"
00355 #define SI_CUSTOMPSET_DOUBLE    "Floating Point Number"
00356 
00357 
00365 #define SI_VT_BOOL      0   
00366 #define SI_VT_BYTE      1   
00367 #define SI_VT_UBYTE     2   
00368 #define SI_VT_SHORT     3   
00369 #define SI_VT_USHORT    4   
00370 #define SI_VT_INT       5   
00371 #define SI_VT_UINT      6   
00372 #define SI_VT_FLOAT     7   
00373 #define SI_VT_DOUBLE    8   
00374 #define SI_VT_LONG      9   
00375 #define SI_VT_ULONG     10  
00377 #define SI_VT_PBOOL     11  
00378 #define SI_VT_PBYTE     12  
00379 #define SI_VT_PUBYTE    13  
00380 #define SI_VT_PSHORT    14  
00381 #define SI_VT_PUSHORT   15  
00382 #define SI_VT_PINT      16  
00383 #define SI_VT_PUINT     17  
00384 #define SI_VT_PFLOAT    18  
00385 #define SI_VT_PDOUBLE   19  
00386 #define SI_VT_PLONG     20  
00387 #define SI_VT_PULONG    21  
00389 #define SI_VT_PCHAR     22  
00390 #define SI_VT_PPCHAR    23  
00392 #define SI_VT_PVOID     24      // endgroup.
00394 
00395 
00403 #define SI_TT_NONE      0   
00404 #define SI_TT_POSITION  1   
00405 #define SI_TT_NORMAL    2   
00406 #define SI_TT_TEXCOORD  3   
00407 #define SI_TT_COLOR     4   
00408 #define SI_TT_TRANSFO   5   
00409 #define SI_TT_INTEGER   6   
00410 #define SI_TT_FLOAT     7   
00411 #define SI_TT_TINYFLOAT 8       // endgroup.
00413 
00421 struct TinyVariant {
00422 
00423     TinyVariant() { memset(this,0,sizeof(TinyVariant));};
00424     TinyVariant(SI_Int v,SI_Int t,SI_Int e )
00425     { 
00426         variantType = v;
00427         tweakType = t;
00428         numElems = e;
00429     };
00430 
00431     SI_Int          variantType;    
00432     SI_Int          tweakType;      
00433     SI_Int          numElems;       
00438     union {
00439         SI_Bool     boolVal;    
00440         SI_Byte     bVal;       
00441         SI_UByte    ubVal;      
00442         SI_Short    sVal;       
00443         SI_UShort   usVal;      
00444         SI_Int      nVal;       
00445         SI_UInt     unVal;      
00446         SI_Float    fVal;       
00447         SI_Double   dVal;       
00448         SI_Long     lVal;       
00449         SI_ULong    ulVal;      
00451         SI_Bool     *p_boolVal; 
00452         SI_Byte     *p_bVal;    
00453         SI_UByte    *p_ubVal;   
00454         SI_Short    *p_sVal;    
00455         SI_UShort   *p_usVal;   
00456         SI_Int      *p_nVal;    
00457         SI_UInt     *p_unVal;   
00458         SI_Float    *p_fVal;    
00459         SI_Double   *p_dVal;    
00460         SI_Long     *p_lVal;    
00461         SI_ULong    *p_ulVal;   
00463         // We used char instead of SI_Char because SI_Char is plateform dependant.
00464         char        *p_cVal;    
00465         char        **pp_cVal;  
00467         SI_Void     *p_voidVal; 
00468     };
00469 };
00470 
00474 typedef TinyVariant SI_TinyVariant;
00475 
00478 //**************************************************************************************
00479 // Macros
00480 //**************************************************************************************
00482 //
00483 #if defined(unix)
00484 
00485 #include <stdio.h>
00486 #include <stdlib.h>
00487 #include <stdarg.h>
00488 #ifndef __APPLE__
00489 #include <malloc.h>
00490 #else
00491 #include <sys/malloc.h>
00492 #endif
00493 
00494 #ifdef __XSI_MAINLIB_
00495 #define XSIEXPORT 
00496 #define XSITEMPLATEEXP
00497 #endif
00498 
00499 #ifdef __XSI_PLUGIN_
00500 #define XSIEXPORT 
00501 #define XSITEMPLATEEXP
00502 #endif
00503 
00504 #ifdef __XSI_APPLICATION_
00505 #ifdef XSI_STATIC_LINK
00506 #define XSIEXPORT
00507 #define XSITEMPLATEEXP
00508 #else
00509 #define XSIEXPORT 
00510 #define XSITEMPLATEEXP
00511 #endif
00512 #endif
00513 
00514 #define XSICOREEXPORT
00515 
00516 #define _SI_INITCORE
00517 #define _SI_EXITCORE
00518 
00519 // Memory stuff
00520 #define _SI_MSIZE( x )          0
00521 #define _SI_MEMCPY( x, y, z )   memcpy( x, y, z )
00522 
00523 // character string format
00524 #define SI_Char         char
00525 #define _SI_STRCMP      strcmp
00526 #define _SI_STRNCMP     strncmp
00527 #define _SI_STRICMP     strcasecmp
00528 #define _SI_STRDUP      si_strdup
00529 #define _SI_BSTRDUP     si_bstrdup
00530 #define _SI_STRCPY      strcpy
00531 #define _SI_STRNCPY     strncpy
00532 #define _SI_STRCAT      strcat
00533 #define _SI_SPRINTF     sprintf
00534 #define _SI_STRLEN      strlen
00535 #define _SI_TEXT(quote) quote
00536 #define _SI_PRINTF      CSIBCUtil::printf
00537 #define _SI_RAND()      rand()
00538 #define _SI_STRTOK      strtok
00539 #define _SI_STRSTR      strstr
00540 #define _SI_STRCHR      strchr
00541 #define _SI_STRRCHR     strrchr
00542 #define _SI_SPLITPATH   si_splitpath
00543 #define _SI_ATOI        atoi
00544 #define _SI_ATOF        atof
00545 
00546 #ifndef __APPLE__
00547 //Math Stuff
00548 #define _SI_SQRT        sqrt
00549 #define _SI_SQRTF       sqrtf
00550 #define _SI_ASIN        asin
00551 #define _SI_ASINF       asinf
00552 #define _SI_ACOS        acos
00553 #define _SI_ACOSF       acosf
00554 #define _SI_FLOOR       floor
00555 #define _SI_FLOORF      floorf
00556 #define _SI_COS         cos
00557 #define _SI_COSF        cosf
00558 #define _SI_SIN         sin
00559 #define _SI_SINF        sinf
00560 #define _SI_TAN         tan
00561 #define _SI_TANF        tanf
00562 #define _SI_ATANF       atanf
00563 #define _SI_ATAN        atan
00564 #else
00565 //Math Stuff
00566 #define _SI_SQRT                sqrt
00567 #define _SI_SQRTF               sqrt
00568 #define _SI_ASIN                asin
00569 #define _SI_ASINF               asin
00570 #define _SI_ACOS                acos
00571 #define _SI_ACOSF               acos
00572 #define _SI_FLOOR               floor
00573 #define _SI_FLOORF              floor
00574 #define _SI_COS                 cos
00575 #define _SI_COSF                cos
00576 #define _SI_SIN                 sin
00577 #define _SI_SINF                sin
00578 #define _SI_TAN                 tan
00579 #define _SI_TANF                tan
00580 #define _SI_ATANF               atan
00581 #define _SI_ATAN                atan
00582 #endif
00583 
00584 
00585 //File stuff
00586 #define __SI_FILE       FILE *
00587 #define __SI_FILE_MODE  SI_Char *
00588 #define __SI_FILE_NULL  (NULL)
00589 #define __SI_FILE_READ_TEXT "r"
00590 #define __SI_FILE_READ_BINARY "rb"
00591 #define __SI_FILE_WRITE_TEXT    "w"
00592 #define __SI_FILE_WRITE_BINARY "wb"
00593 #define __SI_FILE_SET SEEK_SET
00594 #define __SI_FILE_CUR SEEK_CUR
00595 #define __SI_FILE_END SEEK_END
00596 #define __SI_IS_FILE_MODE( a, b ) !_SI_STRCMP ( a, b )
00597 #define __SI_FOPEN( name, mode )        fopen( name, mode )
00598 #define __SI_FCLOSE( x )        fclose( x )
00599 #define __SI_FREAD( a, b, c, d ) fread( a, b, c, d )
00600 #define __SI_FWRITE( a, b, c, d ) fwrite( a, b, c, d )
00601 #define __SI_FPRINTF( a, b ) fprintf( a, b )
00602 #define __SI_FSEEK( ptr, count, type ) fseek( ptr, count, type )
00603 #define __SI_FTELL( ptr ) ftell( ptr )
00604 #define __SI_FGETC( fp ) ::fgetc(fp)
00605 #define __SI_FEOF( x )   feof(x)
00606 #define __SI_FERROR( x ) (ferror(x))
00607 #define __SI_FFLUSH( x ) (fflush(x))
00608 #define __SI_UNGETC( ch, fp )  (ungetc(ch,fp))
00609 
00610 //Assertion
00611 #ifdef _DEBUG
00612 #define _SI_ASSERT(x) assert(x) 
00613 #else
00614 //void XSIEXPORT si_exit(SI_Char *, SI_Char *, const int );
00615 //#define _SI_ASSERT(exp) if (!(exp)) si_exit( #exp, __FILE__, __LINE__ );
00616 #define _SI_ASSERT(exp)
00617 #endif
00618 
00619 //Loadable module 
00620 #define _SI_LIBHANDLE int
00621 
00622 // Local Memory Allocators 
00623 XSICOREEXPORT void AllocateLocalMemory(SI_Char* &, SI_Long);
00624 XSICOREEXPORT void AllocateLocalMemory(SI_Char** &, SI_Long);
00625 
00626 #if !defined(MAX_PATH)
00627 #define MAX_PATH PATH_MAX
00628 #endif
00629 
00630 #endif
00631 
00632 //
00634 //
00635 //
00637 //
00638 
00639 #if ((defined _WIN32) || (defined WIN32)) && !(defined _WIN32_WCE) && !(defined _XBOX)
00640 
00641 #include <string.h>
00642 #include <stdio.h>
00643 #include <stdlib.h>
00644 #include <stdarg.h>
00645 #include <malloc.h>
00646 
00647 #ifdef __XSI_MAINLIB_
00648 #define XSIEXPORT _declspec(dllexport)
00649 #define XSITEMPLATEEXP
00650 #endif
00651 
00652 #ifdef __XSI_PLUGIN_
00653 #define XSIEXPORT _declspec(dllexport)
00654 #define XSITEMPLATEEXP
00655 #endif
00656 
00657 #ifdef __XSI_APPLICATION_
00658 #ifdef XSI_STATIC_LINK
00659 #define XSIEXPORT
00660 #define XSITEMPLATEEXP
00661 #else
00662 #define XSIEXPORT _declspec(dllimport)
00663 #define XSITEMPLATEEXP extern
00664 #endif
00665 #endif
00666 
00667 #ifndef XSICOREEXPORT
00668 # if ((defined _WIN32) || (defined WIN32)) && !(defined _WIN32_WCE) && !(defined _XBOX)
00669 #  ifdef XSICORE_IMPL
00670 #   define XSICOREEXPORT __declspec(dllexport)
00671 #  elif defined(XSICORE_STATIC)
00672 #   define XSICOREEXPORT
00673 #  else
00674 #   define XSICOREEXPORT __declspec(dllimport)
00675 #  endif
00676 # else
00677 #  define XSICOREEXPORT
00678 # endif
00679 #endif
00680 
00681 #define _SI_INITCORE
00682 #define _SI_EXITCORE
00683 
00684 // Memory stuff
00685 #define _SI_MSIZE( x )          _msize( x )
00686 #define _SI_MEMCPY( x, y, z )   memcpy( x, y, z )
00687 
00688 // character string format
00689 #define SI_Char         char
00690 #define _SI_STRCMP      strcmp
00691 #define _SI_STRNCMP     strncmp
00692 #define _SI_STRICMP     stricmp
00693 #define _SI_STRDUP      si_strdup
00694 #define _SI_BSTRDUP     si_bstrdup
00695 #define _SI_STRCPY      strcpy
00696 #define _SI_STRNCPY     strncpy
00697 #define _SI_STRCAT      strcat
00698 #define _SI_SPRINTF     sprintf
00699 #define _SI_STRLEN      strlen
00700 #define _SI_TEXT(quote) quote
00701 #define _SI_PRINTF      CSIBCUtil::printf
00702 #define _SI_RAND()      rand()
00703 #define _SI_STRTOK      strtok
00704 #define _SI_STRSTR      strstr
00705 #define _SI_STRCHR      strchr
00706 #define _SI_STRRCHR     strrchr
00707 #define _SI_SPLITPATH   _splitpath
00708 #define _SI_ATOI        atoi
00709 #define _SI_ATOF        atof
00710 
00711 
00712 //Math Stuff
00713 #define _SI_SQRT        sqrt
00714 #define _SI_SQRTF       sqrtf
00715 #define _SI_ASIN        asin
00716 #define _SI_ASINF       asinf
00717 #define _SI_ACOS        acos
00718 #define _SI_ACOSF       acosf
00719 #define _SI_FLOOR       floor
00720 #define _SI_FLOORF      floorf
00721 #define _SI_COS         cos
00722 #define _SI_COSF        cosf
00723 #define _SI_SIN         sin
00724 #define _SI_SINF        sinf
00725 #define _SI_TAN         tan
00726 #define _SI_TANF        tanf
00727 #define _SI_ATANF       atanf
00728 #define _SI_ATAN        atan
00729 
00730 //File stuff
00731 #define __SI_FILE       FILE *
00732 #define __SI_FILE_MODE  SI_Char *
00733 #define __SI_FILE_NULL  (NULL)
00734 #define __SI_FILE_READ_TEXT "r"
00735 #define __SI_FILE_READ_BINARY "rb"
00736 #define __SI_FILE_WRITE_TEXT    "w"
00737 #define __SI_FILE_WRITE_BINARY "wb"
00738 #define __SI_FILE_SET SEEK_SET
00739 #define __SI_FILE_CUR SEEK_CUR
00740 #define __SI_FILE_END SEEK_END
00741 #define __SI_IS_FILE_MODE( a, b ) !_SI_STRCMP ( a, b )
00742 #define __SI_FOPEN( name, mode )        fopen( name, mode )
00743 #define __SI_FCLOSE( x )        fclose( x )
00744 #define __SI_FREAD( a, b, c, d ) fread( a, b, c, d )
00745 #define __SI_FWRITE( a, b, c, d ) fwrite( a, b, c, d )
00746 #define __SI_FPRINTF( a, b ) fprintf( a, b )
00747 #define __SI_FSEEK( ptr, count, type ) fseek( ptr, count, type )
00748 #define __SI_FTELL( ptr ) ftell( ptr )
00749 #define __SI_FGETC( fp ) ::fgetc(fp)
00750 #define __SI_FEOF( x )   feof( x )
00751 #define __SI_FERROR( x ) (ferror(x))
00752 #define __SI_FFLUSH( x ) (fflush(x))
00753 #define __SI_UNGETC( ch, fp )  (ungetc(ch,fp))
00754 
00755 
00756 //Assertion
00757 #ifdef _DEBUG
00758 #define _SI_ASSERT(x) assert(x) 
00759 #else
00760 //void XSIEXPORT si_exit(SI_Char *, SI_Char *, const int );
00761 //#define _SI_ASSERT(exp) if (!(exp)) si_exit( #exp, __FILE__, __LINE__ );
00762 #define _SI_ASSERT(exp)
00763 #endif
00764 
00765 //Loadable module
00766 #define SI_INVALID_LIB_HANDLE NULL
00767 #define _SI_LIBHANDLE   HMODULE
00768 #define _SI_LOADMODULE  LoadLibrary
00769 #define _SI_UNLOADMODULE( x )  FreeLibrary( x )
00770 #define _SI_LOADFUNCTION( HAND, NAME ) GetProcAddress( HAND, NAME )
00771 
00772 // Local Memory Allocators 
00773 XSICOREEXPORT void AllocateLocalMemory(SI_Char* &, SI_Long);
00774 XSICOREEXPORT void AllocateLocalMemory(SI_Char** &, SI_Long);
00775 
00776 #endif
00777 
00778 //
00780 //
00781 
00782 //
00784 //
00785 #ifdef _WIN32_WCE
00786 
00787 #include <string.h>
00788 #include <stdio.h>
00789 #include <stdlib.h>
00790 #include <stdarg.h>
00791 
00792 //WINDOWS CE
00793 #define _SI_ASSERT(x) 
00794 #include <tchar.h>
00795 #include <winbase.h>
00796 
00797 // Memory stuff
00798 #define _SI_MSIZE( x )          0
00799 #define _SI_MEMCPY( x, y, z )   0
00800 
00801 // character string format
00802 #define SI_Char         wchar_t
00803 #define _SI_STRCMP      wcscmp
00804 #define _SI_STRNCMP     wcsncmp
00805 #define _SI_STRICMP     wcsicmp
00806 #define _SI_STRCPY      lstrcpy
00807 #define _SI_STRNCPY     wsncpy
00808 #define _SI_STRDUP      si_strdup
00809 #define _SI_BSTRDUP     si_bstrdup
00810 #define _SI_STRCAT      wcscat
00811 #define _SI_SPRINTF     swprintf
00812 #define _SI_FPRINTF     fprintf
00813 #define _SI_STRLEN      wcslen
00814 #define _SI_TEXT(quote) __TEXT(quote)
00815 #define _SI_ATOI        _wtoi
00816 
00817 #define _SI_PRINTF      NKDbgPrintfW
00818 #define _SI_RAND()      rand()
00819 #define _SI_STRTOK      wcstok
00820 #define _SI_STRSTR      wcsstr
00821 #define _SI_STRCHR      wcschr
00822 #define _SI_STRRCHR     wcsrchr
00823 #define _SI_SPLITPATH   _wsplitpath
00824 
00825 extern  SI_Char         *_SI_ENDCHAR;
00826 #define _SI_ATOF(x)     wcstod(x, &_SI_ENDCHAR)
00827 
00828 #define _SI_SQRT        sqrt
00829 #define _SI_SQRTF       (SI_Float)sqrt
00830 #define _SI_ASIN        asin
00831 #define _SI_ASINF       (SI_Float)asin
00832 #define _SI_ACOS        acos
00833 #define _SI_ACOSF       (SI_Float)acos
00834 #define _SI_FLOOR       floor
00835 #define _SI_FLOORF      (SI_Float)floor
00836 #define _SI_COS         cos
00837 #define _SI_COSF        (SI_Float)cos
00838 #define _SI_SIN         sin
00839 #define _SI_SINF        (SI_Float)sin
00840 #define _SI_TAN         tan
00841 #define _SI_TANF        (SI_Float)tan
00842 
00843 // Some PPSH helper functions.
00844 extern "C" 
00845 {
00846     int U_ropen(const WCHAR *, UINT);
00847     int U_rread(int, BYTE *, int);
00848     int U_rclose(int);
00849 }
00850 
00851 
00852 #define __SI_FILE               int
00853 #define __SI_FILE_MODE          int
00854 #define __SI_FILE_NULL          0
00855 #define __SI_FILE_READ_TEXT     0x00010002
00856 #define __SI_FILE_READ_BINARY   0x00010002
00857 #define __SI_FOPEN( name, mode )    U_ropen( name, mode) 
00858 #define __SI_FCLOSE( x )            U_rclose( x )
00859 #define __SI_FREAD(a,b,c,d)     U_rread( d, (BYTE *) a, b * c)
00860 #define __SI_FEOF( x )           0
00861 #define __SI_IS_FILE_MODE( a, b ) a == b
00862 
00863 #endif
00864 
00865 //
00867 //
00868 
00869 //
00871 //
00872 #ifdef  _XBOX
00873 #include <string.h>
00874 #include <stdio.h>
00875 #include <stdlib.h>
00876 #include <stdarg.h>
00877 #include <malloc.h>
00878 
00879 
00880 #ifdef __XSI_MAINLIB_
00881 #define XSIEXPORT       _declspec(dllexport)
00882 #endif
00883 
00884 #ifdef __XSI_PLUGIN_
00885 #define XSIEXPORT _declspec(dllexport)
00886 #define XSITEMPLATEEXP
00887 #endif
00888 
00889 #ifdef __XSI_APPLICATION_
00890 #ifdef XSI_STATIC_LINK
00891 #define XSIEXPORT
00892 #undef XSICOREEXPORT
00893 #define XSICOREEXPORT
00894 #define XSITEMPLATEEXP
00895 #else
00896 #define XSIEXPORT _declspec(dllimport)
00897 #define XSICOREEXPORT   _declspec(dllimport)
00898 #define XSITEMPLATEEXP extern
00899 #endif
00900 #endif
00901 
00902 #define _SI_INITCORE
00903 #define _SI_EXITCORE
00904 
00905 // Memory stuff
00906 #define _SI_MSIZE( x )          _msize( x )
00907 #define _SI_MEMCPY( x, y, z )   memcpy( x, y, z )
00908 
00909 // character string format
00910 #define SI_Char         char
00911 #define _SI_STRCMP      strcmp
00912 #define _SI_STRNCMP     strncmp
00913 #define _SI_STRICMP     stricmp
00914 #define _SI_STRDUP      si_strdup
00915 #define _SI_BSTRDUP     si_bstrdup
00916 #define _SI_STRCPY      strcpy
00917 #define _SI_STRNCPY     strncpy
00918 #define _SI_STRCAT      strcat
00919 #define _SI_SPRINTF     sprintf
00920 #define _SI_STRLEN      strlen
00921 #define _SI_TEXT(quote) quote
00922 #define _SI_PRINTF      CSIBCUtil::printf
00923 #define _SI_RAND()      rand()
00924 #define _SI_STRTOK      strtok
00925 #define _SI_STRSTR      strstr
00926 #define _SI_STRCHR      strchr
00927 #define _SI_STRRCHR     strrchr
00928 #define _SI_SPLITPATH   _splitpath
00929 #define _SI_ATOI        atoi
00930 #define _SI_ATOF        atof
00931 
00932 //Math Stuff
00933 #define _SI_SQRT        sqrt
00934 #define _SI_SQRTF       sqrtf
00935 #define _SI_ASIN        asin
00936 #define _SI_ASINF       asinf
00937 #define _SI_ACOS        acos
00938 #define _SI_ACOSF       acosf
00939 #define _SI_FLOOR       floor
00940 #define _SI_FLOORF      floorf
00941 #define _SI_COS         cos
00942 #define _SI_COSF        cosf
00943 #define _SI_SIN         sin
00944 #define _SI_SINF        sinf
00945 #define _SI_TAN         tan
00946 #define _SI_TANF        tanf
00947 #define _SI_ATANF       atanf
00948 #define _SI_ATAN        atan
00949 
00950 typedef FILE* (*_XBOX_FOPEN_FNC)    ( char * filename, char* mode );
00951 typedef int (*_XBOX_FCLOSE_FNC) ( FILE* fdesc );
00952 typedef int (*_XBOX_FREAD_FNC)  ( void *result, int size, int count, FILE* );
00953 typedef int (*_XBOX_FWRITE_FNC) ( void *data, int size, int count, FILE* );
00954 typedef int (*_XBOX_FSEEK_FNC)  ( FILE*, LONG count, int mode );
00955 typedef int (*_XBOX_FTELL_FNC)  ( FILE* );
00956 typedef int (*_XBOX_FEOF_FNC)   ( FILE* );
00957 typedef int (*_XBOX_FGETC_FNC)  ( FILE* );
00958 
00959 
00960 FILE*   XBOXFileOpen ( char *filename , char* mode );
00961 int XBOXFileClose ( FILE* );
00962 int XBOXFileRead ( void *result, int size, int count, FILE* );
00963 int XBOXFileWrite ( void *data, int size, int count, FILE* );
00964 int XBOXFileSeek ( FILE*, LONG count, int mode );
00965 int XBOXFileTell ( FILE* );
00966 int XBOXFileEOF ( FILE* fdesc );
00967 int XBOXFileGETC ( FILE* fdesc );
00968 
00969 //File stuff
00970 
00971 #define __SI_FILE       FILE *
00972 #define __SI_FILE_MODE  SI_Char *
00973 #define __SI_FILE_NULL  (NULL)
00974 #define __SI_FILE_READ_TEXT "r"
00975 #define __SI_FILE_READ_BINARY "rb"
00976 #define __SI_FILE_WRITE_TEXT    "w"
00977 #define __SI_FILE_WRITE_BINARY "wb"
00978 #define __SI_FILE_SET SEEK_SET
00979 #define __SI_FILE_CUR SEEK_CUR
00980 #define __SI_FILE_END SEEK_END
00981 #define __SI_IS_FILE_MODE( a, b ) !_SI_STRCMP ( a, b )
00982 #define __SI_FOPEN( name, mode )    XBOXFileOpen( name, mode )
00983 #define __SI_FCLOSE( x )        XBOXFileClose( x )
00984 #define __SI_FREAD( a, b, c, d )    XBOXFileRead( a, b, c, d )
00985 #define __SI_FWRITE( a, b, c, d )   XBOXFileWrite( a, b, c, d )
00986 #define __SI_FPRINTF( a, b ) (0)
00987 #define __SI_FSEEK( ptr, count, type ) XBOXFileSeek( ptr, count, type )
00988 #define __SI_FTELL( ptr ) XBOXFileTell( ptr )
00989 #define __SI_FGETC( fp ) XBOXFileGETC(fp)
00990 #define __SI_FEOF( x )   XBOXFileEOF( x )
00991 #define __SI_FERROR( x ) (0)
00992 #define __SI_FFLUSH( x ) (0)
00993 
00994 XSICOREEXPORT SI_Char si_ungetc( SI_Char ch, __SI_FILE x );
00995 
00996 #define __SI_UNGETC( ch, fp )  (0)
00997 
00998 //Assertion
00999 #ifdef _DEBUG
01000 #define _SI_ASSERT(x) assert(x) 
01001 #else
01002 //void XSIEXPORT si_exit(SI_Char *, SI_Char *, const int );
01003 //#define _SI_ASSERT(exp) if (!(exp)) si_exit( #exp, __FILE__, __LINE__ );
01004 #define _SI_ASSERT(exp)
01005 #endif
01006 
01007 //Loadable module
01008 #define SI_INVALID_LIB_HANDLE NULL
01009 #define _SI_LIBHANDLE   HMODULE
01010 #define _SI_LOADMODULE  LoadLibrary
01011 #define _SI_UNLOADMODULE( x )  FreeLibrary( x )
01012 #define _SI_LOADFUNCTION( HAND, NAME ) GetProcAddress( HAND, NAME )
01013 
01014 // Local Memory Allocators 
01015 XSICOREEXPORT void AllocateLocalMemory(SI_Char* &, SI_Long);
01016 XSICOREEXPORT void AllocateLocalMemory(SI_Char** &, SI_Long);
01017 #endif
01018 
01019 
01020 //
01022 //
01023 #if defined( _PSX2 ) || defined( __MWERKS__ )
01024 
01025 #include <eekernel.h> 
01026 #include <sifdev.h>
01027 #include <eeregs.h>
01028 #include <eetypes.h>
01029 #include <stdio.h>
01030 #include <string.h>
01031 #include <stdlib.h>
01032 #include <SIPS2Comm.h>
01033 
01034 //#include "SIPS2DisplayDriverSwitch.h"
01035 
01036 //#include <sys/types.h>
01037 //#include <fcntl.h>
01038 
01039 #ifdef __XSI_MAINLIB_
01040 #define XSIEXPORT 
01041 #define XSITEMPLATEEXP
01042 #endif
01043 
01044 #ifdef __XSI_PLUGIN_
01045 #define XSIEXPORT 
01046 #define XSITEMPLATEEXP
01047 #endif
01048 
01049 #ifdef __XSI_APPLICATION_
01050 #ifdef XSI_STATIC_LINK
01051 #define XSIEXPORT
01052 #define XSITEMPLATEEXP
01053 #else
01054 #define XSIEXPORT 
01055 #define XSITEMPLATEEXP
01056 #endif
01057 #endif
01058 
01059 #ifndef XSICOREEXPORT
01060 #define XSICOREEXPORT
01061 #endif
01062 
01063 #ifndef XSIEXPORT
01064 #define XSIEXPORT
01065 #endif
01066 
01067 #ifndef min
01068 # define min(a,b) ((a) < (b) ? (a) : (b))
01069 #endif
01070 
01071 #ifndef max
01072 # define max(a,b) ((a) > (b) ? (a) : (b))
01073 #endif
01074 
01075 #ifndef _PSX2_FILEIO_NATIVE
01076 #define _PSX2_FILEIO_NATIVE
01077 #endif
01078 
01079 //predefinition
01080 #ifdef __cplusplus
01081 extern "C"
01082 {
01083 #endif
01084     int open( const char *, int );
01085     int close( int );
01086 //  off_t lseek( int fildes, off_t offset, int whence );
01087     char *strcat( char *dest, const char *src );
01088     int sprintf( char *str, const char *, ...);
01089     int printf( const char *, ... );
01090     int rand(void);
01091     int read( int , void*, int);
01092     int atoi( const char * );
01093     double atof( const char * );
01094     char * si_strchr( char *, int );
01095 
01096 #ifdef __cplusplus
01097 }
01098 #endif
01099 
01100 
01101 // Memory stuff
01102 #define _SI_MSIZE( x )          0
01103 #define _SI_MEMCPY( x, y, z )   memcpy( x, y, z )
01104 
01105 // character string format
01106 #define SI_Char         char
01107 #define _SI_STRCMP      strcmp
01108 #define _SI_STRNCMP     strncmp
01109 #define _SI_STRICMP     stricmp
01110 #define _SI_STRDUP      si_strdup
01111 #define _SI_BSTRDUP     si_bstrdup
01112 #define _SI_STRCPY      strcpy
01113 #define _SI_STRNCPY     strncpy
01114 #define _SI_STRCAT      strcat
01115 #define _SI_SPRINTF     sprintf
01116 #define _SI_STRLEN      strlen
01117 #define _SI_TEXT(quote) quote
01118 #define _SI_PRINTF      printf
01119 #define _SI_ATOI        atoi
01120 #define _SI_ATOF        atof
01121 
01122 // fprintf is not available and not needed on the PS2
01123 //#define _SI_FPRINTF     
01124 
01125 #define _SI_RAND()      rand()
01126 #define _SI_STRTOK      strtok
01127 #define _SI_STRSTR      strstr
01128 #define _SI_STRCHR      si_strchr // MJD - Found a bug in strchr on GSCube
01129 #define _SI_STRRCHR     strrchr
01130 
01131 
01132 
01133 //Math Stuff
01134 #define _SI_SQRT        sqrt
01135 #define _SI_SQRTF       sqrtf
01136 #define _SI_ASIN        asin
01137 #define _SI_ASINF       asinf
01138 #define _SI_ACOS        acos
01139 #define _SI_ACOSF       acosf
01140 #define _SI_FLOOR       floor
01141 #define _SI_FLOORF      floorf
01142 #define _SI_TAN         tan
01143 #define _SI_TANF        tanf
01144 #define _SI_ATANF       atanf
01145 
01146 #ifdef _INLINETRIG_
01147 #define _SI_COS(x)      SI_CosineTable[((int)(x) * 10000) % 62831]
01148 #define _SI_COSF(x)     SI_CosineTable[((int)(x) * 10000) % 62831]
01149 #define _SI_SIN(x)      SI_SineTable[((int)(x) * 10000) % 62831]
01150 #define _SI_SINF(x)     SI_SineTable[((int)(x) * 10000) % 62831]
01151 #else
01152 #define _SI_COS         CSIBCUtil::cos
01153 #define _SI_COSF        CSIBCUtil::cos
01154 #define _SI_SIN         CSIBCUtil::sin
01155 #define _SI_SINF        CSIBCUtil::sin
01156 #endif
01157 
01158 
01159 
01160 
01161 
01162 
01163 
01164 // use only if files come from a DOS/Windows system (which is the case)
01165 #ifndef __APPLE__
01166 #define LITTLE_ENDIAN
01167 #endif
01168 
01169 //File stuff
01170 #define __SI_FILE               int
01171 #define __SI_FILE_MODE          int
01172 #define __SI_FILE_NULL          (int)(-1) 
01173 #define __SI_FILE_READ_TEXT SCE_RDONLY
01174 #define __SI_FILE_READ_BINARY SCE_RDONLY 
01175 #define __SI_FILE_WRITE_TEXT    SCE_WRONLY | SCE_TRUNC | SCE_CREAT
01176 #define __SI_FILE_WRITE_BINARY SCE_WRONLY | SCE_TRUNC | SCE_CREAT
01177 #define __SI_FILE_SET SCE_SEEK_SET
01178 #define __SI_FILE_CUR SCE_SEEK_CUR
01179 #define __SI_FILE_END SCE_SEEK_END
01180 #define __SI_IS_FILE_MODE( a, b ) ((a)==(b))
01181 #define __SI_FOPEN( NAME, MODE ) PS2FileOpen( NAME, MODE )
01182 #define __SI_FCLOSE( x ) PS2FileClose( x )
01183 #define __SI_FREAD( buf, size, count, fp ) PS2FileRead( fp, buf, size, count )
01184 #define __SI_FWRITE( buf, size, count, fp ) PS2FileWrite( fp, buf, size, count )
01185 // fprintf is not available and not needed on the PS2
01186 #define __SI_FSEEK( ptr, count, type ) PS2FileSeek( ptr, count, type )
01187 #define __SI_FTELL( ptr ) PS2FileTell( ptr )
01188 #define __SI_FGETC( fp ) PS2FileGetC( fp )
01189 #define __SI_FEOF( x )   PS2FileEOF( x )
01190 
01191 #define _SI_INITCORE SIPS2CommInit();
01192 #define _SI_EXITCORE SIPS2CommClose();
01193 
01194 #ifdef _DEBUG
01195 #define _SI_ASSERT(x) assert(x) 
01196 #else
01197 void XSIEXPORT si_exit(SI_Char *, SI_Char *, const int );
01198 //#define _SI_ASSERT(exp) if (!(exp)) si_exit( #exp, __FILE__, __LINE__ );
01199 #define _SI_ASSERT(exp)
01200 #endif
01201 
01202 
01203 //Loadable module
01204 #define SI_INVALID_LIB_HANDLE -1
01205 #define _SI_LIBHANDLE   int
01206 
01207 #endif
01208 //
01210 //
01211 
01212 // Already documented in SIBCMath.h
01213 #ifndef M_PI
01214 #define M_PI        3.14159265358979323846
01215 #endif
01216 
01222 #define _ERRMSG(x) _SI_PRINTF(_SI_TEXT("ERROR : %s\n"),x);  
01223 
01225 #define _MSG(x)    _SI_PRINTF(_SI_TEXT("MSG   : %s\n"),x);
01226 
01228 #define _SI_NEW(x,y) {  x = new y; _SI_ASSERT( x != NULL ); }
01229 
01231 #define _SI_DELETE( ptr ) { if ( ptr != NULL ) { delete ptr; ptr = NULL; }  }
01232 
01234 #define _SI_DELETE_ARRAY( ptr ) {if ( ptr != NULL ) { delete [] ptr; ptr = NULL; }  }
01235 
01240 #define _SI_CALL(x,y) { if (result==SI_SUCCESS) { result = x;if(result != SI_SUCCESS){_ERRMSG(y);}}}
01241 
01242 #define _SI_CHKRESULT( RESULT, MESSAGE, ACTION ){if (RESULT != SI_SUCCESS){ _ERRMSG( MESSAGE ); ACTION; }   }
01243 
01244 XSICOREEXPORT SI_Char *  si_strdup( const SI_Char * );
01245 XSICOREEXPORT SI_Char *  si_bstrdup( const SI_Byte * );
01246 XSICOREEXPORT SI_Error si_bstringtostring( SI_Char *, const SI_Byte * );
01247 XSICOREEXPORT SI_Void si_splitpath(const SI_Char *, SI_Char *, SI_Char *, SI_Char *, SI_Char *);
01248 
01249 #define _SI_STRDUPL(D,S) { D = (char *) alloca(strlen(S)); strcpy(D,S); }
01250 
01251 #ifdef __cplusplus //If included by C-files this causes an error
01252 
01253 #ifdef _INLINETRIG_
01254 extern  float   SI_SineTable[62831];
01255 extern  float   SI_CosineTable[62831];
01256 #endif
01257 
01258 //**************************************************************************************
01259 // CSIBCUtil | Utility functions.
01260 //**************************************************************************************
01261 
01263 
01267 class XSICOREEXPORT CSIBCUtil
01268 {
01269 public:
01270 
01274     CSIBCUtil();
01275     ~CSIBCUtil();
01276 
01287     static  SI_Error    Open(SI_Char *in_pFilename);
01288 
01298     static  SI_Error    Close();
01299     
01303     static  void        SetToStderr();
01304 
01311     static  void        printf(SI_Char * str,...);
01312     
01313     // Fast lookup table for trigonometric functions
01314 
01319     static  void        InitializeTrigTables();
01320 
01327     static  float       cos(float x);
01328 
01335     static  float       sin(float x);
01336     
01337 protected:  
01338     static SI_Char m_Filename[256];
01339 
01340 private:
01341     SI_Void             *m_pUnused;
01342 
01343 };
01344 
01345 #endif
01346 
01347 
01348 //**************************************************************************************
01349 // Inline code
01350 //**************************************************************************************
01351 
01352 
01353 //***************************************************************************************
01354 // Author   : Games S.W.A.T. Team
01355 // Date     :
01356 //
01357 // Calculates the cosine of an angle.
01358 // float | x | Angle. 
01359 // Result of the cosine operation.
01360 //***************************************************************************************
01361 inline float CSIBCUtil::cos(float x)
01362 {
01363 #ifdef _INLINETRIG_
01364     int     index = (int) ( x * 10000.0f);
01365         
01366     if (index < 0)
01367         index += 628310000;
01368     
01369     return SI_CosineTable[index % 62831];
01370 #else
01371     return _SI_COSF(x);
01372 #endif
01373 }
01374 
01375 //***************************************************************************************
01376 // Author   : Games S.W.A.T. Team
01377 // Date     :
01378 //
01379 // Calculates the sine of an angle.
01380 // float | x | Angle.
01381 // Result of the sin operation.
01382 //***************************************************************************************
01383 inline float CSIBCUtil::sin(float x)
01384 {
01385 #ifdef _INLINETRIG_
01386     int     index = (int) ( x * 10000.0f);
01387     
01388     if (index < 0)
01389         index += 628310000;
01390         
01391     return SI_SineTable[index % 62831];
01392 #else
01393     return _SI_SINF(x);
01394 #endif
01395 }
01396 
01397 //**************************************************************************************
01398 // _SI_FILE macro definitions
01399 //
01400 //
01401 //**************************************************************************************
01402 
01403 // SIFILE things
01404 
01405 // No need to document this class, it is only used as a private member of SIFilePtr.
01406 class SIFileInterface
01407 {
01408 public:
01409     virtual ~SIFileInterface()
01410     {
01411     }
01412     
01413     // FUNCTIONS
01414     virtual int close() = 0;
01415 
01416     virtual size_t read( void *pbuffer, size_t size, size_t count ) = 0;
01417 
01418     virtual size_t write( const void *buffer, size_t size, size_t count ) = 0;
01419 
01420     virtual int printf( const char *format ) = 0;
01421 
01422     virtual int seek( LONG offset, int origin ) = 0;
01423 
01424     virtual LONG tell() = 0;
01425 
01426     virtual int fgetc() = 0;
01427 
01428     virtual int eof() = 0;
01429 
01430     virtual int error() = 0;
01431 
01432     virtual int flush() = 0;
01433 
01434     virtual int siungetc( int ch ) = 0;
01435 
01436     // OPERATORS
01437     virtual operator __SI_FILE() = 0;
01438 
01439     //virtual operator bool() const = 0;
01440 
01441     // you must define:  operator=( __SI_FILE const& other )
01442 };
01443 class SIFile: public SIFileInterface
01444 {
01445 private:
01446     __SI_FILE fp;
01447 
01448 public:
01449     enum openMode
01450     {
01451         Read_Text = 0,
01452         Read_Binary,
01453         Write_Text,
01454         Write_Binary,
01455     };
01456 
01457     enum seekDir
01458     {
01459 #ifdef __SI_FILE_SET
01460         sdSet = __SI_FILE_SET,
01461 #endif
01462 #ifdef __SI_FILE_CUR
01463         sdCur = __SI_FILE_CUR,
01464 #endif
01465 #ifdef __SI_FILE_END
01466         sdEnd = __SI_FILE_END,
01467 #endif
01468     };
01469 
01470     // CONSTRUCTORS
01471 
01472     SIFile(): fp( __SI_FILE_NULL ) {}
01473 
01474     SIFile( __SI_FILE file ): fp( file ) {}
01475 
01476     SIFile( const char *name, int mode )        // open
01477     {
01478 #ifdef __SI_FOPEN
01479         static __SI_FILE_MODE const mt[] =
01480         {
01481 #ifdef __SI_FILE_READ_TEXT
01482         __SI_FILE_READ_TEXT, 
01483 #else
01484     #error you need to define this
01485 #endif
01486 #ifdef __SI_FILE_READ_BINARY
01487         __SI_FILE_READ_BINARY, 
01488 #else
01489     #error you need to define this
01490 #endif
01491 #ifdef __SI_FILE_WRITE_TEXT
01492         __SI_FILE_WRITE_TEXT, 
01493 #else
01494     #error you need to define this
01495 #endif
01496 #ifdef __SI_FILE_WRITE_BINARY
01497         __SI_FILE_WRITE_BINARY,
01498 #else
01499     #error you need to define this
01500 #endif
01501         };
01502         fp = __SI_FOPEN( (char*)name, mt[mode] );
01503 #else
01504     #error you need to define this
01505 #endif
01506     }
01507 
01508     // FUNCTIONS
01509     int close()
01510     {
01511 #ifdef __SI_FCLOSE
01512         int     temp = __SI_FCLOSE( fp );
01513         fp = __SI_FILE_NULL;                        // extra safety
01514         return temp;
01515 #else
01516         _SI_ASSERT( false );
01517         return 0;
01518 #endif
01519     }
01520 
01521     size_t read( void *buffer, size_t size, size_t count )
01522     {
01523 #ifdef __SI_FREAD
01524         return __SI_FREAD( buffer, size, count, fp );
01525 #else
01526         _SI_ASSERT( false );
01527         return 0;
01528 #endif
01529     }
01530 
01531     size_t write( const void *buffer, size_t size, size_t count )
01532     {
01533 #ifdef __SI_FWRITE
01534         return __SI_FWRITE( (void*)buffer, size, count, fp );
01535 #else
01536         _SI_ASSERT( false );
01537         return 0;
01538 #endif
01539     }
01540 
01541     int printf( const char *format )
01542     {
01543 #ifdef __SI_FPRINTF
01544         return __SI_FPRINTF( fp, format );
01545 #else
01546         _SI_ASSERT( false );
01547         return 0;
01548 #endif
01549     }
01550 
01551     int seek( LONG offset, int origin )
01552     {
01553 #ifdef __SI_FSEEK
01554         return __SI_FSEEK( fp, offset, origin );
01555 #else
01556         _SI_ASSERT( false );
01557         return 0;
01558 #endif
01559     }
01560 
01561     LONG tell()
01562     {
01563 #ifdef __SI_FTELL
01564         return __SI_FTELL( fp );
01565 #else
01566         _SI_ASSERT( false );
01567         return 0;
01568 #endif
01569     }
01570 
01571     int fgetc()
01572     {
01573 #ifdef __SI_FGETC
01574         return __SI_FGETC( fp );
01575 #else
01576         _SI_ASSERT( false );
01577         return 0;
01578 #endif
01579     }
01580 
01581     int eof()
01582     {
01583 #ifdef __SI_FEOF
01584         return __SI_FEOF( fp );
01585 #else
01586         _SI_ASSERT( false );
01587         return 0;
01588 #endif
01589     }
01590 
01591     int error()
01592     {
01593 #ifdef __SI_FERROR
01594         return __SI_FERROR( fp );
01595 #else
01596         _SI_ASSERT( false );
01597         return 0;
01598 #endif
01599     }
01600     
01601     int flush()
01602     {
01603 #ifdef __SI_FFLUSH
01604         return __SI_FFLUSH( fp );
01605 #else
01606         _SI_ASSERT( false );
01607         return 0;
01608 #endif
01609     }
01610 
01611     int siungetc( int ch )
01612     {
01613 #ifdef __SI_UNGETC
01614         return __SI_UNGETC( ch, fp );
01615 #else
01616         _SI_ASSERT( false );
01617         return 0;
01618 #endif
01619     }
01620     
01621     // OPERATORS
01622     operator __SI_FILE()
01623     {
01624         return fp;
01625     }
01626 
01627     /*operator bool() const
01628     {
01629         return fp == __SI_FILE_NULL;
01630     }*/
01631 
01632     SIFile operator=( __SI_FILE const& other )
01633     {
01634         fp = other;
01635         return *this;
01636     }
01637 
01638     SIFile operator=( SIFile const& other )
01639     {
01640         fp = other.fp;
01641         return *this;
01642     }
01643 };
01644 
01645 //***************************************************************************************
01646 //
01647 // Author  : Neil Girdhar / Softimage Games Team
01648 // Date    : July 8th 2002
01649 //
01650 // FILE STUFF
01651 //
01652 //***************************************************************************************
01653 
01654 // BUFFERED FILE
01655 
01656 #if defined( _XBOX ) || defined( _PSX2 )
01657 class BufferedFile: public SIFileInterface
01658 {
01659 private:
01660     char                *buffer;
01661     int                 goodBytes;          // bytes of the buffer that are good
01662     int                 position;           // position of next read in buffer
01663     unsigned int        bufferSize;
01664     SIFile              fp;
01665     /*
01666     our position in the underlying stream will always be goodBytes.
01667     to synchronise the surface stream, we would seek (position-goodBytes) (a negative number) bytes forward.
01668     */
01669 
01670 public:
01671     // CONSTRUCTORS
01672     BufferedFile(): buffer( NULL ), goodBytes(0), position(0), bufferSize( 0 ), fp()
01673     {
01674     }
01675 
01676     BufferedFile( __SI_FILE fpIn ): buffer( NULL ), goodBytes(0), position(0), bufferSize( 0 ), fp( fpIn )
01677     {
01678     }
01679 
01680     BufferedFile( const char *name, int mode, unsigned int bs ): buffer( new char[bs] ), goodBytes(0), position(0), bufferSize( bs ), fp()
01681     {
01682         fp = SIFile( name, mode );
01683     }
01684 
01685     virtual ~BufferedFile()
01686     {
01687         if( buffer!=NULL ) delete [] buffer;
01688     }
01689     
01690     // BUFFERING FUNCTIONS
01691     void clearBuffer()
01692     {
01693         goodBytes = 0;
01694     }
01695 
01696     void reseekBuffer()
01697     {
01698         int         seekdistance = position-goodBytes;      // see note above
01699         if( seekdistance==0 ) return;           // already seeked
01700         fp.seek( seekdistance, SIFile::sdCur ); // seek forward to where the user thinks we are  (room for optimization)
01701         position = 0;                           // set our position
01702         clearBuffer();                          // clear the buffer after reseek
01703     }
01704 
01705     unsigned int fillBuffer()
01706     {
01707         reseekBuffer();
01708         goodBytes = fp.read( buffer, 1, bufferSize );
01709 #ifdef  _PSX2
01710         if (goodBytes < 0)
01711             goodBytes = 0;
01712 #endif
01713         position = 0;
01714         return  goodBytes;
01715     }
01716 
01717     unsigned int remainingBytesInBuffer()
01718     {
01719         return goodBytes-position;
01720     }
01721 
01722     // FUNCTIONS
01723     int close()
01724     {
01725         clearBuffer();
01726         return fp.close();
01727     }
01728 
01729     size_t read( void *pbuffer, size_t size, size_t count )
01730     {
01731         if( size*count<=bufferSize )        // only cache for small reads
01732         //if( false )
01733         {
01734             char        *dest = (char*)pbuffer;
01735             int         copiedWords = 0;
01736 
01737             while( count>0 )
01738             {
01739                 if( remainingBytesInBuffer()<size ) 
01740                 { 
01741                     if( fillBuffer()<size )
01742                     {
01743                         break;  // could not read at least one word/record
01744                     }
01745                 }
01746 
01747                 // buffer is not empty, so copy out good bytes
01748                 {
01749                     int         copyWords = min( remainingBytesInBuffer()/size, count );    // words to copy
01750                     int         copyBytes = copyWords * size;                   // bytes to copy
01751                 
01752                     _SI_MEMCPY( dest, buffer+position, copyBytes );
01753                     
01754                     dest += copyBytes;
01755                     position += copyBytes;
01756                     
01757                     copiedWords += copyWords;
01758                     count -= copyWords;
01759                 }
01760             }
01761         
01762             return copiedWords;
01763         }
01764         else
01765         {
01766             reseekBuffer();
01767             clearBuffer();
01768             return fp.read( pbuffer, size, count );
01769         }
01770     }
01771 
01772     size_t write( const void *buffer, size_t size, size_t count )
01773     {
01774         reseekBuffer();
01775         clearBuffer();
01776         return fp.write( buffer, size, count );
01777     }
01778 
01779     int printf( const char *format )
01780     {
01781         reseekBuffer();
01782         clearBuffer();
01783         return fp.printf( format );
01784     }
01785 
01786     int seek( LONG offset, int origin )
01787     {
01788         if( origin==SIFile::sdCur )
01789         {
01790             offset+=position-goodBytes;             // collect position and offset together
01791         }
01792         position = 0;                       // after the seek, we will be at position 0
01793         clearBuffer();                      // buffer is invalid after seek; there is room for optimization here, but it shouldn't matter in general use
01794         return fp.seek( offset, origin );   // recurse
01795     }
01796 
01797     LONG tell()
01798     {
01799         return fp.tell() + position;        // user thinks we are position bytes ahead
01800     }
01801 
01802     int fgetc()
01803     {
01804         char retval;
01805         if( read( &retval, 1, 1 )==0 )
01806         {
01807             return fp.fgetc();              // same EOF/error characteristics
01808         }
01809         return retval;
01810     }
01811 
01812     int eof()
01813     {
01814         if( goodBytes > position ) return 0;
01815         reseekBuffer();
01816         return fp.eof();
01817     }
01818 
01819     int error()
01820     {
01821         reseekBuffer();
01822         return fp.error();
01823     }
01824 
01825     int flush()
01826     {
01827         // no need to reseek or clear buffer
01828         return fp.flush();
01829     }
01830 
01831     int siungetc( int ch )
01832     {
01833         reseekBuffer();
01834         clearBuffer();
01835         return fp.siungetc( ch );
01836     }
01837 
01838     // OPERATORS
01839     operator SIFile()
01840     {
01841         reseekBuffer();
01842         clearBuffer();
01843         return fp;
01844     }
01845 
01846     operator __SI_FILE()
01847     {
01848         reseekBuffer();
01849         clearBuffer();
01850         return fp;
01851     }
01852 
01853     /*operator bool() const
01854     {
01855         return (bool)fp;
01856     }*/
01857 };
01858 #endif
01859 
01860 class SIFilePtr
01861 {
01862 private:
01863     SIFileInterface     *fp;
01864 
01865 public:
01866     SIFilePtr()
01867     {
01868         fp = NULL;
01869     }
01870 
01871     SIFilePtr( __SI_FILE file )
01872     {
01873         fp = NULL;
01874         this->operator=( file );
01875     }
01876 
01877 
01878     SIFilePtr( const char *name, int mode )
01879     {
01880 #if (defined _XBOX) || (defined _PSX2)
01881         fp = (SIFileInterface*)new BufferedFile( name, mode, 2048 );        // bufferring
01882 #elif (defined unix) \
01883         || ((defined _WIN32) || (defined WIN32)) && !(defined _WIN32_WCE) && !(defined _XBOX) \
01884         || (defined _WIN32_WCE)
01885         fp = (SIFileInterface*)new SIFile( name, mode );                    // no bufferring
01886 #else
01887         // unknown platform
01888         fp = (SIFileInterface*)new SIFile( name, mode );                    // no bufferring
01889 #endif
01890     }
01891 
01892     ~SIFilePtr()
01893     {
01894     }
01895     
01896     // FUNCTIONS
01897     int close()
01898     {
01899         int retval = fp->close();
01900         delete fp;
01901         return retval;
01902     }
01903 
01904     size_t read( void *pbuffer, size_t size, size_t count )
01905     {
01906         return fp->read( pbuffer, size, count );
01907     }
01908 
01909     size_t write( const void *buffer, size_t size, size_t count )
01910     {
01911         return fp->write( buffer, size, count );
01912     }
01913 
01914     int printf( const char *format )
01915     {
01916         return fp->printf( format );
01917     }
01918 
01919     int seek( LONG offset, int origin )
01920     {
01921         return fp->seek( offset, origin );  // recurse
01922     }
01923 
01924     LONG tell()
01925     {
01926         return fp->tell();
01927     }
01928 
01929     int fgetc()
01930     {
01931         return fp->fgetc();
01932     }
01933 
01934     int eof()
01935     {
01936         return fp->eof();
01937     }
01938 
01939     int error()
01940     {
01941         return fp->error();
01942     }
01943 
01944     int flush()
01945     {
01946         return fp->flush();
01947     }
01948 
01949     int siungetc( int ch )
01950     {
01951         return fp->siungetc( ch );
01952     }
01953 
01954     // OPERATORS
01955 
01956     operator __SI_FILE()
01957     {
01958         if( fp==NULL ) return __SI_FILE_NULL;
01959         return (__SI_FILE)(*fp);
01960     }
01961 
01962     /*operator bool() const
01963     {
01964         if( fp==NULL ) return false;
01965         return fp->operator bool();
01966     }*/
01967 
01968     SIFilePtr& operator=( __SI_FILE const & other )
01969     {
01970         if( other == __SI_FILE_NULL )
01971         {
01972             fp = NULL;
01973         }
01974         else
01975         {
01976             fp = (SIFileInterface*)new SIFile( other );
01977         }
01978         return *this;
01979     }
01980 
01981     SIFilePtr& operator=( const SIFilePtr &other )
01982     {
01983         // check for equality (are we the same as what we're assigning to)
01984         if (this != &other) {
01985             fp = other.fp;
01986         }
01987         return *this;
01988     }
01989 };
01990 
01991 typedef SIFilePtr _SI_FILE;
01992 
01993 XSICOREEXPORT SI_Char si_getc( _SI_FILE x );
01994 XSICOREEXPORT SI_Char si_ungetc( SI_Char ch, _SI_FILE x );
01995 
01996 
01997 // FILE MACROS
01998 #define _SI_FILE_MODE   SIFile::openMode
01999 #define _SI_FILE_NULL   __SI_FILE_NULL
02000 #define _SI_FILE_READ_TEXT  (SIFile::Read_Text)
02001 #define _SI_FILE_READ_BINARY (SIFile::Read_Binary)
02002 #define _SI_FILE_WRITE_TEXT (SIFile::Write_Text)
02003 #define _SI_FILE_WRITE_BINARY (SIFile::Write_Binary)
02004 #define _SI_FILE_SET (SIFile::sdSet)
02005 #define _SI_FILE_CUR (SIFile::sdCur)
02006 #define _SI_FILE_END (SIFile::sdEnd)
02007 #define _SI_IS_FILE_MODE( a, b ) ((a)==(b))
02008 #define _SI_FOPEN( name, mode )     (_SI_FILE( name, mode ))
02009 #define _SI_FCLOSE( x )     ((x).close())
02010 #define _SI_FREAD( a, b, c, d ) ((d).read( a, b, c ))
02011 #define _SI_FWRITE( a, b, c, d ) ((d).write( a, b, c ))
02012 #define _SI_FPRINTF( a, b ) ((a).printf( b ))
02013 #define _SI_FSEEK( ptr, count, type ) ((ptr).seek( count, type ))
02014 #define _SI_FTELL( ptr ) ((ptr).tell())
02015 #define _SI_FGETC( fp ) ((fp).fgetc())
02016 #define _SI_FEOF( x ) ((x).eof())
02017 #define _SI_FERROR( x ) ((x).error())
02018 #define _SI_FFLUSH( fp ) ((fp).flush())
02019 #define _SI_UNGETC( fp ) ((fp).siungetc())
02020 
02021 //**************************************************************************************
02022 // WARNING CALLBACK FUNCTION
02023 //
02024 //
02025 //**************************************************************************************
02026 
02027 typedef SI_Void (*SI_WARNING_CALLBACK_FNC)  ( SI_Char*, SI_Int );
02028 #define SI_MESSAGE  0
02029 #define SI_WARNING  1
02030 #define SI_ERROR    2
02031 
02032 //
02033 // Allocation
02034 //
02035 
02036 XSICOREEXPORT void  *   FTK_calloc( size_t, size_t );
02037 XSICOREEXPORT void      FTK_free( void * );
02038 XSICOREEXPORT void      FTK_delete( void * );
02039 
02040 //**************************************************************************************
02041 // URL FUNCTIONS
02042 //
02043 //
02044 //**************************************************************************************
02045 
02046 class CSIBCString;
02047 SI_Error FTK_GetURLParts(char* in_pURL, CSIBCString* out_pScheme, CSIBCString* out_pAuthority, CSIBCString* out_pPath, CSIBCString* out_pQuery, CSIBCString* out_pFragment);
02048 void FTK_ConvertStringFromURL(CSIBCString &io_String);
02049 void FTK_ConvertStringToURL(CSIBCString &io_String);
02050 
02051 #endif // CSIBCUtil