This Trac instance is not used for development anymore!

We migrated our development workflow to git and Gitea.
To test the future redirection, replace trac by ariadne in the page URL.

Changeset 334 for ps


Ignore:
Timestamp:
06/01/04 19:34:12 (21 years ago)
Author:
janwas
Message:

lots of type fixes; types.h is now a convenience wrapper on top of the standard uintN_t routines

Location:
ps/trunk/source
Files:
41 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/source/graphics/MapReader.cpp

    r316 r334  
    1 // switch off warnings before including stl files
    2 #pragma warning(disable : 4786) // identifier truncated to 255 chars
     1#include "precompiled.h"
    32
    43#include "Types.h"
     
    1716extern CLightEnv g_LightEnv;
    1817
    19 #include <set>
    20 #include <stdio.h>
    2118
    2219
  • ps/trunk/source/graphics/MapWriter.cpp

    r306 r334  
    1 // switch off warnings before including stl files
    2 #pragma warning(disable : 4786) // identifier truncated to 255 chars
     1#include "precompiled.h"
    32
    43#include "Types.h"
     
    1312extern CTerrain g_Terrain;
    1413extern CLightEnv g_LightEnv;
    15 
    16 #include <set>
    17 #include <stdio.h>
    1814
    1915///////////////////////////////////////////////////////////////////////////////////////////////////
  • ps/trunk/source/graphics/Terrain.cpp

    r306 r334  
    129129// GetPatch: return the patch at (x,z) in patch space, or null if the patch is
    130130// out of bounds
    131 CPatch* CTerrain::GetPatch(int32 x,int32 z)
    132 {
    133     if (x<0 || x>=int32(m_MapSizePatches)) return 0;   
    134     if (z<0 || z>=int32(m_MapSizePatches)) return 0;
     131CPatch* CTerrain::GetPatch(int32_t x,int32_t z)
     132{
     133    if (x<0 || x>=int32_t(m_MapSizePatches)) return 0; 
     134    if (z<0 || z>=int32_t(m_MapSizePatches)) return 0;
    135135    return &m_Patches[(z*m_MapSizePatches)+x];
    136136}
     
    140140// GetPatch: return the tile at (x,z) in tile space, or null if the tile is out
    141141// of bounds
    142 CMiniPatch* CTerrain::GetTile(int32 x,int32 z)
    143 {
    144     if (x<0 || x>=int32(m_MapSize)-1) return 0;
    145     if (z<0 || z>=int32(m_MapSize)-1) return 0;
     142CMiniPatch* CTerrain::GetTile(int32_t x,int32_t z)
     143{
     144    if (x<0 || x>=int32_t(m_MapSize)-1) return 0;   
     145    if (z<0 || z>=int32_t(m_MapSize)-1) return 0;
    146146
    147147    CPatch* patch=GetPatch(x/16,z/16);
  • ps/trunk/source/graphics/Terrain.h

    r306 r334  
    5252    // get patch at given coordinates, expressed in patch-space; return 0 if
    5353    // coordinates represent patch off the edge of the map
    54     CPatch* GetPatch(int32 x,int32 z);
     54    CPatch* GetPatch(int32_t x,int32_t z);
    5555    // get tile at given coordinates, expressed in tile-space; return 0 if
    5656    // coordinates represent tile off the edge of the map
    57     CMiniPatch* GetTile(int32 x,int32 z);
     57    CMiniPatch* GetTile(int32_t x,int32_t z);
    5858
    5959    // calculate the position of a given vertex
  • ps/trunk/source/gui/CGUI.h

    r290 r334  
    419419    /// Used when reading in XML files
    420420    // TODO Gee: Used?
    421     int16 m_Errors;
     421    int16_t m_Errors;
    422422
    423423    //@}
  • ps/trunk/source/gui/GUItext.cpp

    r291 r334  
    217217    Parser.InputTaskType("end", "/$ident");
    218218
    219     _long position = 0;
    220     _long from=0;           // the position in the raw string where the last tag ended
    221     _long from_nonraw=0;    // like from only in position of the REAL string, with tags.
    222     _long curpos = 0;
     219    long position = 0;
     220    long from=0;            // the position in the raw string where the last tag ended
     221    long from_nonraw=0; // like from only in position of the REAL string, with tags.
     222    long curpos = 0;
    223223
    224224    // Current Text Chunk
     
    247247            // First check if there is another TagStart before a TagEnd,
    248248            //  in that case it's just a regular TagStart and we can continue.
    249             _long pos_left = str.Find(curpos+1, TagStart);
    250             _long pos_right = str.Find(curpos+1, TagEnd);
     249            long pos_left = str.Find(curpos+1, TagStart);
     250            long pos_right = str.Find(curpos+1, TagEnd);
    251251
    252252            if (pos_right == -1)
     
    429429    {
    430430        // Find the next word-delimiter.
    431         _long dl = m_RawString.Find(position, ' ');
     431        long dl = m_RawString.Find(position, ' ');
    432432
    433433        if (dl == -1)
     
    442442    {
    443443        // Find the next word-delimiter.
    444         _long dl = m_RawString.Find(position, '-');
     444        long dl = m_RawString.Find(position, '-');
    445445
    446446        if (dl == -1)
     
    455455    {
    456456        // Find the next word-delimiter.
    457         _long dl = m_RawString.Find(position, '\n');
     457        long dl = m_RawString.Find(position, '\n');
    458458
    459459        if (dl == -1)
  • ps/trunk/source/gui/IGUIScrollBar.h

    r290 r334  
    229229     * @param width Width
    230230     */
    231     void SetWidth(const int16 &width) { m_Width = width; }
     231    void SetWidth(const int16_t &width) { m_Width = width; }
    232232   
    233233    /**
  • ps/trunk/source/lib/detect.h

    r266 r334  
    2020#define __DETECT_H__
    2121
    22 #include "misc.h"
     22#include "lib.h"
    2323
    2424#ifdef __cplusplus
     
    2929// useful for choosing a video mode. not called by detect().
    3030// if we fail, outputs are unchanged (assumed initialized to defaults)
    31 extern int get_cur_resolution(int& xres, int& yres);
     31extern int get_cur_vmode(int* xres, int* yres, int* bpp, int* freq);
    3232
    3333// useful for determining aspect ratio. not called by detect().
  • ps/trunk/source/lib/lib.cpp

    r277 r334  
    3737//   so we may have shut down something important already).
    3838
    39 const int MAX_EXIT_FUNCS = 64;
     39static const int MAX_EXIT_FUNCS = 32;
    4040
    4141
     
    112112    atexit(call_exit_funcs);
    113113}
     114
     115
     116
     117
     118
     119
     120
     121
     122
     123
     124// FNV1-A hash - good for strings.
     125// if len = 0 (default), treat buf as a C-string;
     126// otherwise, hash <len> bytes of buf.
     127u32 fnv_hash(const void* buf, const size_t len)
     128{
     129    u32 h = 0x811c9dc5;
     130        // give distinct values for different length 0 buffers.
     131        // value taken from FNV; it has no special significance.
     132
     133    const u8* p = (const u8*)buf;
     134
     135    // expected case: string
     136    if(!len)
     137    {
     138        while(*p)
     139        {
     140            h ^= *p++;
     141            h *= 0x01000193;
     142        }
     143    }
     144    else
     145    {
     146        size_t bytes_left = len;
     147        while(bytes_left != 0)
     148        {
     149            h ^= *p++;
     150            h *= 0x01000193;
     151
     152            bytes_left--;
     153        }
     154    }
     155
     156    return h;
     157}
     158
     159
     160// FNV1-A hash - good for strings.
     161// if len = 0 (default), treat buf as a C-string;
     162// otherwise, hash <len> bytes of buf.
     163u64 fnv_hash64(const void* buf, const size_t len)
     164{
     165    u64 h = 0xCBF29CE484222325ull;
     166        // give distinct values for different length 0 buffers.
     167        // value taken from FNV; it has no special significance.
     168
     169    const u8* p = (const u8*)buf;
     170
     171    // expected case: string
     172    if(!len)
     173    {
     174        while(*p)
     175        {
     176            h ^= *p++;
     177            h *= 0x100000001B3;
     178        }
     179    }
     180    else
     181    {
     182        size_t bytes_left = len;
     183        while(bytes_left != 0)
     184        {
     185            h ^= *p++;
     186            h *= 0x100000001B3;
     187
     188            bytes_left--;
     189        }
     190    }
     191
     192    return h;
     193}
     194
     195
     196
     197
     198bool is_pow2(const long n)
     199{
     200    return (n != 0) && !(n & (n-1));
     201}
     202
     203
     204// return -1 if not an integral power of 2,
     205// otherwise the base2 logarithm
     206
     207int ilog2(const int n)
     208{
     209#ifdef _M_IX86
     210
     211    __asm
     212    {
     213        mov     ecx, [n]
     214        or      eax, -1         // return value
     215        lea     edx, [ecx-1]
     216        test    ecx, edx        // power of 2?
     217        jnz     $ret
     218        bsf     eax, ecx
     219    $ret:
     220        mov     [n], eax
     221    }
     222
     223    return n;
     224
     225#else
     226
     227    if(n || n & (n-1))
     228        return -1;
     229
     230    int i = 1, j = 0;
     231    for(; i != n; i += i, j++)
     232        ;
     233    return j;
     234
     235#endif
     236}
     237
     238
     239int ilog2(const float x)
     240{
     241    u32 i = (u32&)x;
     242    u32 exp = (i >> 23) & 0xff;
     243    return (int)exp - 127;
     244}
     245
     246
     247uintptr_t round_up(const uintptr_t n, const uintptr_t multiple)
     248{
     249    assert(multiple != 0);
     250    const uintptr_t padded = n + multiple-1;
     251    const uintptr_t remainder = padded % multiple;
     252    const uintptr_t result = padded - remainder;
     253    assert(n <= result && result < n+multiple);
     254    return result;
     255}
     256
     257
     258u16 addusw(u16 x, u16 y)
     259{
     260    u32 t = x;
     261    return (u16)MIN(t+y, 0xffff);
     262}
     263
     264
     265u16 subusw(u16 x, u16 y)
     266{
     267    long t = x;
     268    return (u16)(MAX(t-y, 0));
     269}
     270
     271
     272// provide fminf for non-C99 compilers
     273#ifndef HAVE_C99
     274
     275float fminf(float a, float b)
     276{
     277    return (a < b)? a : b;
     278}
     279
     280#endif
     281
     282
     283
     284long round(double x)
     285{
     286    return (long)(x + 0.5);
     287}
     288
     289
     290// input in [0, 1); convert to u8 range
     291u8 fp_to_u8(double in)
     292{
     293    if(!(0 <= in && in < 1.0))
     294    {
     295        debug_warn("clampf not in [0,1)");
     296        return 255;
     297    }
     298
     299    int l = round(in * 255.0);
     300    assert((unsigned int)l <= 255);
     301    return (u8)l;
     302}
     303
     304
     305// input in [0, 1); convert to u16 range
     306u16 fp_to_u16(double in)
     307{
     308    if(!(0 <= in && in < 1.0))
     309    {
     310        debug_warn("clampf not in [0,1)");
     311        return 65535;
     312    }
     313
     314    long l = round(in * 65535.0);
     315    assert((unsigned long)l <= 65535);
     316    return (u16)l;
     317}
     318
     319
     320
     321// big endian!
     322void base32(const int len, const u8* in, u8* out)
     323{
     324    int bits = 0;
     325    u32 pool = 0;
     326
     327    static u8 tbl[33] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
     328
     329    for(int i = 0; i < len; i++)
     330    {
     331        if(bits < 5)
     332        {
     333            pool <<= 8;
     334            pool |= *in++;
     335            bits += 8;
     336        }
     337
     338        bits -= 5;
     339        int c = (pool >> bits) & 31;
     340        *out++ = tbl[c];
     341    }
     342}
     343/*
     344#ifndef _WIN32
     345
     346char *_itoa(int value, char *out, int radix)
     347{
     348    return _ltoa(value, out, radix);
     349}
     350
     351static const char digits[]="0123456789abcdef";
     352   
     353char *_ultoa(unsigned long int value, char *out, int radix)
     354{
     355    char buf[21];
     356    char *p=buf+21;
     357   
     358    do
     359    {
     360        *(--p)=digits[value % radix];
     361        value /= radix;
     362    }
     363    while (value);
     364   
     365    memcpy(out, p, (buf+21)-p);
     366    out[(buf+21)-p]=0;
     367    return out;
     368}
     369
     370char *_ltoa(long val, char *out, int radix)
     371{
     372    char buf[21];
     373    char *p=buf+21;
     374    bool sign=val < 0;
     375    if (sign) val=-val;
     376   
     377    do
     378    {
     379        *(--p)=digits[val % radix];
     380        val /= radix;
     381    }
     382    while (val);
     383   
     384    if (sign) *(--p) = '-';
     385   
     386    memcpy(out, p, (buf+21)-p);
     387    out[(buf+21)-p]=0;
     388    return out;
     389}
     390
     391#endif
     392*/
     393
     394
  • ps/trunk/source/lib/lib.h

    r293 r334  
    2121
    2222#include "config.h"
    23 
    24 #include "misc.h"
     23#include "posix.h"
    2524#include "types.h"
    2625
    2726#include "sysdep/sysdep.h"
    28 
    29 
    30 // yikes! avoid template warning spew on VC6
    31 #if _MSC_VER <= 1200
    32 #pragma warning(disable:4786)
    33 #endif
    3427
    3528
     
    4639
    4740
     41
    4842#define STMT(STMT_code__) do { STMT_code__; } while(0)
    4943
     
    5145#define ONCE(ONCE_code__)\
    5246STMT(\
    53     static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;\
     47/*  static pthread_mutex_t ONCE_mutex__ = PTHREAD_MUTEX_INITIALIZER;\
     48    if(pthread_mutex_trylock(&ONCE_mutex__) == 0)\*/\
    5449    static bool ONCE_done__ = false;\
    55     if(pthread_mutex_trylock(&(mutex)) == 0 && !ONCE_done__)\
     50    if(!ONCE_done__)\
    5651    {\
    5752        ONCE_done__ = true;\
     
    192187extern int atexit2(void* func);
    193188
    194 #include "posix.h"
     189
     190
     191
     192
     193
     194
     195
     196
     197
     198
     199// FNV1-A hash - good for strings.
     200// if len = 0 (default), treat buf as a C-string;
     201// otherwise, hash <len> bytes of buf.
     202extern u32 fnv_hash(const void* buf, const size_t len = 0);
     203extern u64 fnv_hash64(const void* buf, const size_t len);
     204
     205// hash (currently FNV) of a filename
     206typedef u32 FnHash;
     207
     208
     209#ifndef min
     210inline int min(int a, int b)
     211{
     212    return (a < b)? a : b;
     213}
     214
     215inline int max(int a, int b)
     216{
     217    return (a > b)? a : b;
     218}
     219#endif
     220
     221extern u16 addusw(u16 x, u16 y);
     222extern u16 subusw(u16 x, u16 y);
     223
     224
     225
     226
     227static inline u16 read_le16(const void* p)
     228{
     229#ifdef BIG_ENDIAN
     230    const u8* _p = (const u8*)p;
     231    return (u16)_p[0] | (u16)_p[1] << 8;
     232#else
     233    return *(u16*)p;
     234#endif
     235}
     236
     237
     238static inline u32 read_le32(const void* p)
     239{
     240#ifdef BIG_ENDIAN
     241    u32 t = 0;
     242    for(int i = 0; i < 4; i++)
     243    {
     244        t <<= 8;
     245        t |= *((const u8*)p)++;
     246    }
     247    return t;
     248#else
     249    return *(u32*)p;
     250#endif
     251}
     252
     253
     254extern bool is_pow2(long n);
     255
     256
     257// return -1 if not an integral power of 2,
     258// otherwise the base2 logarithm
     259extern int ilog2(const int n);
     260
     261
     262extern uintptr_t round_up(uintptr_t val, uintptr_t multiple);
     263
     264
     265// provide fminf for non-C99 compilers
     266#ifndef HAVE_C99
     267extern float fminf(float, float);
     268#endif
     269
     270
     271
     272extern long round(double);
     273extern u16 fp_to_u16(double in);
     274
     275// big endian!
     276extern void base32(const int len, const u8* in, u8* out);
     277
     278#ifndef _WIN32
     279
     280char *_itoa(int, char *, int radix);
     281char *_ultoa(unsigned long int, char*, int radix);
     282char *_ltoa(long, char *, int radix);
     283
     284#endif
     285
     286
     287
    195288
    196289
  • ps/trunk/source/lib/misc.cpp

    r293 r334  
    2222#include "misc.h"
    2323
    24 
    25 // FNV1-A hash - good for strings.
    26 // if len = 0 (default), treat buf as a C-string;
    27 // otherwise, hash <len> bytes of buf.
    28 u32 fnv_hash(const void* buf, const size_t len)
    29 {
    30     u32 h = 0x811c9dc5;
    31         // give distinct values for different length 0 buffers.
    32         // value taken from FNV; it has no special significance.
    33 
    34     const u8* p = (const u8*)buf;
    35 
    36     // expected case: string
    37     if(!len)
    38     {
    39         while(*p)
    40         {
    41             h ^= *p++;
    42             h *= 0x01000193;
    43         }
    44     }
    45     else
    46     {
    47         size_t bytes_left = len;
    48         while(bytes_left != 0)
    49         {
    50             h ^= *p++;
    51             h *= 0x01000193;
    52 
    53             bytes_left--;
    54         }
    55     }
    56 
    57     return h;
    58 }
    59 
    60 
    61 // FNV1-A hash - good for strings.
    62 // if len = 0 (default), treat buf as a C-string;
    63 // otherwise, hash <len> bytes of buf.
    64 u64 fnv_hash64(const void* buf, const size_t len)
    65 {
    66     u64 h = 0xCBF29CE484222325ull;
    67         // give distinct values for different length 0 buffers.
    68         // value taken from FNV; it has no special significance.
    69 
    70     const u8* p = (const u8*)buf;
    71 
    72     // expected case: string
    73     if(!len)
    74     {
    75         while(*p)
    76         {
    77             h ^= *p++;
    78             h *= 0x100000001B3;
    79         }
    80     }
    81     else
    82     {
    83         size_t bytes_left = len;
    84         while(bytes_left != 0)
    85         {
    86             h ^= *p++;
    87             h *= 0x100000001B3;
    88 
    89             bytes_left--;
    90         }
    91     }
    92 
    93     return h;
    94 }
    95 
    96 
    97 
    98 
    99 bool is_pow2(const long n)
    100 {
    101     return (n != 0) && !(n & (n-1));
    102 }
    103 
    104 
    105 // return -1 if not an integral power of 2,
    106 // otherwise the base2 logarithm
    107 
    108 int ilog2(const int n)
    109 {
    110 #ifdef _M_IX86
    111 
    112     __asm
    113     {
    114         mov     ecx, [n]
    115         or      eax, -1         // return value
    116         lea     edx, [ecx-1]
    117         test    ecx, edx        // power of 2?
    118         jnz     $ret
    119         bsf     eax, ecx
    120     $ret:
    121         mov     [n], eax
    122     }
    123 
    124     return n;
    125 
    126 #else
    127 
    128     if(n || n & (n-1))
    129         return -1;
    130 
    131     int i = 1, j = 0;
    132     for(; i != n; i += i, j++)
    133         ;
    134     return j;
    135 
    136 #endif
    137 }
    138 
    139 
    140 int ilog2(const float x)
    141 {
    142     u32 i = (u32&)x;
    143     u32 exp = (i >> 23) & 0xff;
    144     return (int)exp - 127;
    145 }
    146 
    147 
    148 uintptr_t round_up(uintptr_t val, uintptr_t multiple)
    149 {
    150     val += multiple-1;
    151     val -= val % multiple;
    152     return val;
    153 }
    154 
    155 
    156 u16 addusw(u16 x, u16 y)
    157 {
    158     u32 t = x;
    159     return (u16)MIN(t+y, 0xffff);
    160 }
    161 
    162 
    163 u16 subusw(u16 x, u16 y)
    164 {
    165     long t = x;
    166     return (u16)(MAX(t-y, 0));
    167 }
    168 
    169 
    170 // provide fminf for non-C99 compilers
    171 #ifndef HAVE_C99
    172 
    173 float fminf(float a, float b)
    174 {
    175     return (a < b)? a : b;
    176 }
    177 
    178 #endif
    179 
    180 
    181 
    182 long round(double x)
    183 {
    184     return (long)(x + 0.5);
    185 }
    186 
    187 
    188 // input in [0, 1); convert to u8 range
    189 u8 fp_to_u8(double in)
    190 {
    191     if(!(0 <= in && in < 1.0))
    192     {
    193         debug_warn("clampf not in [0,1)");
    194         return 255;
    195     }
    196 
    197     int l = round(in * 255.0);
    198     assert((unsigned int)l <= 255);
    199     return (u8)l;
    200 }
    201 
    202 
    203 // input in [0, 1); convert to u16 range
    204 u16 fp_to_u16(double in)
    205 {
    206     if(!(0 <= in && in < 1.0))
    207     {
    208         debug_warn("clampf not in [0,1)");
    209         return 65535;
    210     }
    211 
    212     long l = round(in * 65535.0);
    213     assert((unsigned long)l <= 65535);
    214     return (u16)l;
    215 }
    216 
    217 
    218 
    219 // big endian!
    220 void base32(const int len, const u8* in, u8* out)
    221 {
    222     int bits = 0;
    223     u32 pool = 0;
    224 
    225     static u8 tbl[33] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
    226 
    227     for(int i = 0; i < len; i++)
    228     {
    229         if(bits < 5)
    230         {
    231             pool <<= 8;
    232             pool |= *in++;
    233             bits += 8;
    234         }
    235 
    236         bits -= 5;
    237         int c = (pool >> bits) & 31;
    238         *out++ = tbl[c];
    239     }
    240 }
    241 /*
    242 #ifndef _WIN32
    243 
    244 char *_itoa(int value, char *out, int radix)
    245 {
    246     return _ltoa(value, out, radix);
    247 }
    248 
    249 static const char digits[]="0123456789abcdef";
    250    
    251 char *_ultoa(unsigned long int value, char *out, int radix)
    252 {
    253     char buf[21];
    254     char *p=buf+21;
    255    
    256     do
    257     {
    258         *(--p)=digits[value % radix];
    259         value /= radix;
    260     }
    261     while (value);
    262    
    263     memcpy(out, p, (buf+21)-p);
    264     out[(buf+21)-p]=0;
    265     return out;
    266 }
    267 
    268 char *_ltoa(long val, char *out, int radix)
    269 {
    270     char buf[21];
    271     char *p=buf+21;
    272     bool sign=val < 0;
    273     if (sign) val=-val;
    274    
    275     do
    276     {
    277         *(--p)=digits[val % radix];
    278         val /= radix;
    279     }
    280     while (val);
    281    
    282     if (sign) *(--p) = '-';
    283    
    284     memcpy(out, p, (buf+21)-p);
    285     out[(buf+21)-p]=0;
    286     return out;
    287 }
    288 
    289 #endif
    290 */
    291 
  • ps/trunk/source/lib/misc.h

    r293 r334  
    2020#define __MISC_H__
    2121
    22 #include "types.h"
    23 #include "config.h"
    24 
    25 #ifdef __cplusplus
    26 extern "C" {
    27 #endif
    28 
    29 
    30 // FNV1-A hash - good for strings.
    31 // if len = 0 (default), treat buf as a C-string;
    32 // otherwise, hash <len> bytes of buf.
    33 extern u32 fnv_hash(const void* buf, const size_t len = 0);
    34 extern u64 fnv_hash64(const void* buf, const size_t len);
    35 
    36 // hash (currently FNV) of a filename
    37 typedef u32 FnHash;
    38 
    39 
    40 #ifndef min
    41 inline int min(int a, int b)
    42 {
    43     return (a < b)? a : b;
    44 }
    45 
    46 inline int max(int a, int b)
    47 {
    48     return (a > b)? a : b;
    49 }
    50 #endif
    51 
    52 extern u16 addusw(u16 x, u16 y);
    53 extern u16 subusw(u16 x, u16 y);
    54 
    55 
    56 
    57 
    58 static inline u16 read_le16(const void* p)
    59 {
    60 #ifdef BIG_ENDIAN
    61     const u8* _p = (const u8*)p;
    62     return (u16)_p[0] | (u16)_p[1] << 8;
    63 #else
    64     return *(u16*)p;
    65 #endif
    66 }
    67 
    68 
    69 static inline u32 read_le32(const void* p)
    70 {
    71 #ifdef BIG_ENDIAN
    72     u32 t = 0;
    73     for(int i = 0; i < 4; i++)
    74     {
    75         t <<= 8;
    76         t |= *((const u8*)p)++;
    77     }
    78     return t;
    79 #else
    80     return *(u32*)p;
    81 #endif
    82 }
    83 
    84 
    85 extern bool is_pow2(long n);
    86 
    87 
    88 // return -1 if not an integral power of 2,
    89 // otherwise the base2 logarithm
    90 extern int ilog2(const int n);
    91 
    92 
    93 extern uintptr_t round_up(uintptr_t val, uintptr_t multiple);
    94 
    95 
    96 // provide fminf for non-C99 compilers
    97 #ifndef HAVE_C99
    98 extern float fminf(float, float);
    99 #endif
    100 
    101 
    102 
    103 extern long round(double);
    104 extern u16 fp_to_u16(double in);
    105 
    106 // big endian!
    107 extern void base32(const int len, const u8* in, u8* out);
    108 
    109 #ifndef _WIN32
    110 
    111 char *_itoa(int, char *, int radix);
    112 char *_ultoa(unsigned long int, char*, int radix);
    113 char *_ltoa(long, char *, int radix);
    114 
    115 #endif
    116 
    117 
    11822
    11923
  • ps/trunk/source/lib/precompiled.h

    r258 r334  
    11#include <string.h>
    22#include <stdlib.h>
    3 
    43#include <stdio.h>
    54
     
    98#include <limits.h>
    109#include <time.h>
    11 
    1210#include <wchar.h>
    13 
    1411
    1512#include <list>
     
    1815#include <stack>
    1916#include <string>
     17#include <set>
     18#include <deque>
    2019
    2120#include <functional>
    2221#include <algorithm>
    23 
    2422#include <numeric>
    2523
    26 #pragma warning(disable:4996)
     24#ifdef _MSC_VER
     25#pragma warning(disable:4996)   // function is deprecated
     26#pragma warning(disable:4786)   // identifier truncated to 255 chars
     27#endif
  • ps/trunk/source/lib/res/file.cpp

    r276 r334  
    754754
    755755// free all allocated IOs, so they aren't seen as resource leaks.
    756 static void io_cleanup(void)
     756static void io_shutdown(void)
    757757{
    758758    std::for_each(all_ios.begin(), all_ios.end(), Free());
     
    762762static Handle io_alloc()
    763763{
    764     ONCE(atexit(io_cleanup));
     764    ONCE(atexit(io_shutdown));
    765765/*
    766766    // grab from freelist
  • ps/trunk/source/lib/res/font.cpp

    r266 r334  
    2222
    2323#include "lib.h"
    24 #include "mem.h"
    25 #include "font.h"
    26 #include "h_mgr.h"
    27 #include "vfs.h"
    28 #include "tex.h"
     24#include "res.h"
    2925#include "ogl.h"
    30 #include "misc.h"
    3126
    3227/*
     
    109104struct Font
    110105{
    111     Handle ht;
     106    Handle ht;      // handle to font texture
    112107    uint list_base;
    113108};
  • ps/trunk/source/lib/res/h_mgr.cpp

    r323 r334  
    2020
    2121#include "lib.h"
    22 #include "misc.h"
    2322#include "h_mgr.h"
    2423#include "mem.h"
     
    236235
    237236
    238 static void cleanup(void)
     237void h_mgr_shutdown(void)
    239238{
    240239    // close open handles
     
    373372Handle h_alloc(H_Type type, const char* fn, uint flags, ...)
    374373{
    375     ONCE(atexit2(cleanup));
     374    ONCE(atexit2(h_mgr_shutdown));
    376375
    377376    Handle err;
  • ps/trunk/source/lib/res/h_mgr.h

    r292 r334  
    2020#define H_MGR_H__
    2121
    22 #ifdef __cplusplus
    23 extern "C" {
    24 #endif
    2522
    2623#include <stdarg.h>     // type init routines get va_list of args
    2724
    28 #include "../types.h"
     25#include "lib.h"
    2926
    3027
    3128// handle type (for 'type safety' - can't use a texture handle as a sound)
     29
     30   
    3231//
    3332// rationale: we could use the destructor passed to h_alloc to identify
     
    185184extern int res_cur_scope;
    186185
    187 #ifdef __cplusplus
    188 }
    189 #endif
    190 
    191186
    192187#endif  // #ifndef H_MGR_H__
  • ps/trunk/source/lib/res/mem.cpp

    r227 r334  
    44
    55#include "lib.h"
    6 #include "types.h"
    7 #include "mem.h"
     6#include "res.h"
    87#include "h_mgr.h"
    9 #include "misc.h"
    10 
    11 #include <map>
    12 
    13 
    148
    159
     
    2418
    2519
    26 static void* heap_alloc(const size_t size, const int align, uintptr_t& ctx, MEM_DTOR& dtor)
     20static void* heap_alloc(const size_t size, const size_t align, uintptr_t& ctx, MEM_DTOR& dtor)
    2721{
    2822    u8* org_p = (u8*)malloc(size+align-1);
     
    5650
    5751
    58 static void* pool_alloc(const size_t size, const uint align, uintptr_t& ctx, MEM_DTOR& dtor)
     52static void* pool_alloc(const size_t size, const size_t align, uintptr_t& ctx, MEM_DTOR& dtor)
    5953{
    6054    if(!pool)
     
    209203    // we've already allocated that pointer - returns its handle
    210204    Handle hm = find_alloc(p);
    211     if(hm)
     205    if(hm > 0)
    212206        return hm;
    213207
     
    234228
    235229
    236 void* mem_alloc(size_t size, const uint align, uint flags, Handle* phm)
     230void* mem_alloc(size_t size, const size_t align, uint flags, Handle* phm)
    237231{
    238232    if(phm)
  • ps/trunk/source/lib/res/mem.h

    r167 r334  
    2020};
    2121
    22 extern void* mem_alloc(size_t size, uint align = 1, uint flags = 0, Handle* ph = 0);
     22extern void* mem_alloc(size_t size, size_t align = 1, uint flags = 0, Handle* ph = 0);
    2323
    2424#define mem_free(p) mem_free_p((void*&)p)
  • ps/trunk/source/lib/res/tex.cpp

    r322 r334  
    2222
    2323#include "lib.h"
    24 #include "vfs.h"
    25 #include "tex.h"
    26 #include "mem.h"
     24#include "res.h"
    2725#include "ogl.h"
    28 #include "h_mgr.h"
    29 #include "misc.h"
    3026
    3127
     
    3834#endif
    3935
    40 
     36// libpng includes windows.h - prevent that, and define what it needs.
    4137#define _WINDOWS_
    4238#define WINAPI __stdcall
     
    4440
    4541#ifndef NO_PNG
    46  #include <libpng10/png.h>
    47 #pragma comment(lib, "libpng10.lib")
     42# include <libpng10/png.h>
     43# ifdef _MSC_VER
     44#  pragma comment(lib, "libpng10.lib")
     45# endif
    4846#endif
    4947
     
    470468
    471469
    472 static void png_read_fn(png_struct* png_ptr, u8* data, png_size_t length)
     470static void png_read_fn(png_struct* const png_ptr, u8* const data, const png_size_t length)
    473471{
    474472    MemRange* const mr = (MemRange*)png_ptr->io_ptr;
     
    478476    memcpy(data, mr->p, length);
    479477    mr->p += length;
    480     mr->size -= length; // > 0 due to test above
     478    mr->size -= length; // >= 0 due to test above
    481479}
    482480
     
    513511    }
    514512
    515     u8** rows;
     513    const u8** rows;
     514        // freed in cleanup code; need scoping on VC6 due to goto
    516515
    517516    {
     
    525524    png_get_IHDR(png_ptr, info_ptr, &w, &h, &prec, &color_type, 0, 0, 0);
    526525
    527     size_t pitch = png_get_rowbytes(png_ptr, info_ptr);
     526    const size_t pitch = png_get_rowbytes(png_ptr, info_ptr);
    528527
    529528    const u32 fmts[8] = { 0, ~0, GL_RGB, ~0, GL_LUMINANCE_ALPHA, ~0, GL_RGBA, ~0 };
     
    543542
    544543    // allocate mem for image - rows point into buffer (sequential)
    545     rows = (u8**)malloc((h+1)*sizeof(void*));
     544    rows = (const u8**)malloc(h*sizeof(void*));
    546545    if(!rows)
    547546        goto fail;
    548     size_t img_size = pitch * (h+1);
     547    const size_t img_size = pitch * h;
    549548    Handle img_hm;
    550     u8* img = (u8*)mem_alloc(img_size, 64*KB, 0, &img_hm);
     549    const u8* img = (const u8*)mem_alloc(img_size, 64*KB, 0, &img_hm);
    551550    if(!img)
    552551        goto fail;
    553     u8* pos = img;
    554     for(u32 i = 0; i < h+1; i++)
     552    const u8* pos = img;
     553    for(size_t i = 0; i < h; i++)
    555554    {
    556555        rows[i] = pos;
     
    558557    }
    559558
    560     png_read_image(png_ptr, rows);
     559    png_read_image(png_ptr, (png_bytepp)rows);
    561560
    562561    png_read_end(png_ptr, info_ptr);
    563    
    564562
    565563    mem_free_h(t->hm);
  • ps/trunk/source/lib/res/tex.h

    r322 r334  
    2020#define __TEX_H__
    2121
    22 #include "types.h"
    2322#include "h_mgr.h"
    24 #include "misc.h"
    2523
    2624// load and return a handle to the texture given in <fn>.
     
    3331extern int tex_info(Handle ht, int* w, int* h, int *fmt, int *bpp, void** p);
    3432
    35 extern int tex_filter;  // GL values; default: GL_LINEAR
    36 extern uint tex_bpp;    // 16 or 32; default: 32
     33extern int tex_filter;          // GL values; default: GL_LINEAR
     34extern unsigned int tex_bpp;    // 16 or 32; default: 32
    3735
    3836// upload the specified texture to OpenGL. Texture filter and internal format
  • ps/trunk/source/lib/res/vfs.cpp

    r292 r334  
    2121
    2222#include "lib.h"
    23 #include "file.h"
    24 #include "zip.h"
    25 #include "misc.h"
    26 #include "vfs.h"
    27 #include "mem.h"
     23#include "res.h"
    2824#include "adts.h"
    2925
     
    184180// when opening a file (slow).
    185181//
    186 // one Loc is allocated for each archive or directory mounted.
    187 // therefore, files only /point/ to a (possibly shared) Loc.
     182// one FileLoc is allocated for each archive or directory mounted.
     183// therefore, files only /point/ to a (possibly shared) FileLoc.
    188184// if a file's location changes (e.g. after mounting a higher-priority
    189 // directory), the VFS entry will point to the new Loc; the priority
     185// directory), the VFS entry will point to the new FileLoc; the priority
    190186// of both locations is unchanged.
    191187//
     
    198194
    199195// not many instances => don't worry about struct size / alignment.
    200 struct Loc
     196struct FileLoc
    201197{
    202198    Handle archive;
    203 
    204199    std::string dir;
    205 
    206200    uint pri;
    207201
    208     Loc() {}
    209     Loc(Handle _archive, const char* _dir, uint _pri)
     202    FileLoc() {}
     203    FileLoc(Handle _archive, const char* _dir, uint _pri)
    210204        : archive(_archive), dir(_dir), pri(_pri) {}
    211205};
    212206
    213207
    214 struct TreeDir;
    215 
    216 typedef std::map<std::string, TreeDir*> SubDirs;
     208// rationale for separate file / subdir containers:
     209// problems:
     210// - more code for insertion (oh well);
     211// - makes ordered output of all dirents difficult
     212//   (but dirs and files are usually displayed separately)
     213// advantages:
     214// - simplifies lookup code: it can just check if a path is there,
     215//   no need to check if the entry is actually a directory
     216// - storing Dir objects directly in the map means less
     217//   memory allocations / no need to free them.
     218//
     219// *_add guard against a subdir and file of the same name.
     220
     221typedef std::map<const std::string, FileLoc*> Files;
     222typedef Files::iterator FileIt;
     223    // notes:
     224    // - FileLoc is allocated and owned by caller (the mount code)
     225    // - priority is accessed by following the FileLoc pointer.
     226    //   keeping a copy in the map would lead to better cache coherency,
     227    //   but it's a bit more clumsy (map filename to struct {pri, FileLoc*}).
     228    //   revisit if file lookup open is too slow (unlikely).
     229
     230struct Dir;
     231typedef std::pair<const std::string, Dir> SubDir;
     232typedef std::map<const std::string, Dir> SubDirs;
    217233typedef SubDirs::iterator SubDirIt;
    218234
    219 typedef std::map<std::string, const Loc*> Files;
    220 typedef Files::iterator FileIt;
    221     // note: priority is accessed by following the Loc pointer.
    222     // keeping a copy in the map would lead to better cache coherency,
    223     // but it's a bit more clumsy (map filename to struct {pri, Loc*}).
    224     // revisit if file lookup open is too slow (unlikely).
    225 
    226 struct TreeDir
    227 {
    228     std::string v_name;
    229 
    230     void* watch;
    231 
    232 
    233     int file_add(const char* const fn, const uint pri, const Loc* const loc)
    234     {
    235         std::string _fn(fn);
    236 
    237         typedef std::pair<std::string, const Loc*> Ent;
    238         Ent ent = std::make_pair(_fn, loc);
    239         std::pair<FileIt, bool> ret;
    240         ret = files.insert(ent);
    241         // file already in dir
    242         if(!ret.second)
    243         {
    244             FileIt it = ret.first;
    245             const Loc*& old_loc = it->second;
    246 
    247             // new Loc is of higher priority; replace pointer
    248             if(old_loc->pri <= loc->pri)
    249             {
    250                 old_loc = loc;
    251                 return 0;
    252             }
    253             // new Loc is of lower priority; keep old pointer
    254             else
    255                 return 1;
    256         }
    257 
     235struct Dir
     236{
     237    int file_add(const char* name, const FileLoc* loc);
     238    FileLoc* file_find(const char* name);
     239
     240    int subdir_add(const char* name);
     241    Dir* subdir_find(const char* name);
     242
     243    void clearR();
     244
     245    SubDirs subdirs;
     246    Files files;
     247};
     248
     249
     250int Dir::subdir_add(const char* const fn)
     251{
     252    if(file_find(fn) || subdir_find(fn))
     253    {
     254        debug_warn("dir_add: file or subdirectory of same name already exists");
     255        return -1;
     256    }
     257
     258    subdirs[fn];
     259        // side effect: maps <fn> to a newly constructed Dir()
     260        // non-const => cannot be optimized away.
     261    return 0;
     262}
     263
     264
     265Dir* Dir::subdir_find(const char* const fn)
     266{
     267    SubDirIt it = subdirs.find(fn);
     268    if(it == subdirs.end())
    258269        return 0;
    259     }
    260 
    261     const Loc* file_find(const char* fn)
    262     {
    263         std::string _fn(fn);
    264         FileIt it = files.find(_fn);
    265         if(it == files.end())
    266             return 0;
    267         return it->second;
    268     }
    269 
    270     TreeDir* subdir_add(const char* name)
    271     {
    272         TreeDir* vdir = new TreeDir;
    273         const std::string _name(name);
    274         vdir->v_name = _name;
    275 
    276         std::pair<std::string, TreeDir*> item = std::make_pair(_name, vdir);
    277         std::pair<SubDirIt, bool> res;
    278         res = subdirs.insert(item);
    279         // already in container
    280         if(!res.second)
    281             debug_warn("already in subdir");
    282 
    283         SubDirIt it = res.first;
    284         return it->second;
    285     }
    286 
    287     TreeDir* subdir_find(const char* name)
    288     {
    289         const std::string _name(name);
    290         SubDirIt it = subdirs.find(_name);
    291         if(it == subdirs.end())
    292             return 0;
    293         return it->second;
    294     }
    295 
    296     void subdir_clear()
    297     {
    298         for(SubDirIt it = subdirs.begin(); it != subdirs.end(); ++it)
    299             delete(it->second);
    300         subdirs.clear();
    301     }
    302 
    303     friend void tree_clearR(TreeDir*);
    304 
    305     SubDirs subdirs;    // can't make private; needed for iterator
    306     Files files;
    307 
    308 
    309 private:;
    310 
    311 
    312 };
    313 
    314 
    315 static TreeDir vfs_root;
     270    return &it->second;
     271}
     272
     273
     274int Dir::file_add(const char* const fn, const FileLoc* const loc)
     275{
     276    if(subdir_find(fn))
     277    {
     278        debug_warn("dir_add: file of same name already exists");
     279        return -1;
     280    }
     281
     282    // default pointer ctor sets it to 0 =>
     283    // if fn wasn't already in the container, old_loc is 0.
     284    const FileLoc*& old_loc = files[fn];
     285    // old loc exists and is higher priority - keep it.
     286    if(old_loc && old_loc->pri > loc->pri)
     287        return 1;
     288
     289    old_loc = loc;
     290    return 0;
     291}
     292
     293
     294FileLoc* Dir::file_find(const char* const fn)
     295{
     296    FileIt it = files.find(fn);
     297    if(it == files.end())
     298        return 0;
     299    return it->second;
     300}
     301
     302
     303void Dir::clearR()
     304{
     305    SubDirIt it;
     306    for(it = subdirs.begin(); it != subdirs.end(); ++it)
     307    {
     308        Dir& subdir = it->second;
     309        subdir.clearR();
     310    }
     311
     312    subdirs.clear();
     313    files.clear();
     314}
     315
     316
     317
     318
     319static Dir vfs_root;
    316320
    317321
     
    325329// starts in VFS root directory (path = "").
    326330// path doesn't need to, and shouldn't, start with '/'.
    327 static int tree_lookup(const char* path, const Loc** const loc = 0, TreeDir** const dir = 0, LookupFlags flags = LF_DEFAULT)
     331static int tree_lookup(const char* path, const FileLoc** const loc = 0, Dir** const dir = 0, LookupFlags flags = LF_DEFAULT)
    328332{
    329333    CHECK_PATH(path);
     
    338342    const bool create_missing_components = flags & LF_CREATE_MISSING_COMPONENTS;
    339343
    340     TreeDir* cur_dir = &vfs_root;
    341 
     344    Dir* cur_dir = &vfs_root;
     345
     346    // for each path component:
    342347    for(;;)
    343348    {
    344349        char* slash = strchr(cur_component, '/');
    345         // we have followed all path components.
    346         // cur_component is the filename or ""
     350        // done, cur_component is the filename or "" if <path> is a directory
    347351        if(!slash)
    348         {
    349             // caller wants pointer to file location returned
    350             if(loc)
    351             {
    352                 const char* fn = cur_component;
    353                 *loc = cur_dir->file_find(fn);
    354 
    355                 // user wanted its loc, but it's not found - fail
    356                 if(!*loc)
    357                     return ERR_FILE_NOT_FOUND;
    358             }
    359             // caller wants pointer to this dir returned
    360             if(dir)
    361                 *dir = cur_dir;
    362             return 0;
    363         }
    364         // cur_component is a subdirectory name; change to it
    365         else
    366         {
    367             const char* subdir_name = cur_component;
    368             *slash = 0;
    369 
    370             TreeDir* subdir = cur_dir->subdir_find(subdir_name);
    371             if(!subdir)
    372             {
    373                 if(create_missing_components)
    374                     subdir = cur_dir->subdir_add(subdir_name);
    375                 else
    376                     return ERR_PATH_NOT_FOUND;
    377             }
    378 
    379             cur_dir = subdir;
    380             cur_component = slash+1;
    381         }
    382     }
    383 }
    384 
    385 
    386 static void tree_clearR(TreeDir* const dir)
    387 {
    388     SubDirIt it;
    389     for(it = dir->subdirs.begin(); it != dir->subdirs.end(); ++it)
    390     {
    391         TreeDir* subdir = it->second;
    392         tree_clearR(subdir);
    393     }
    394 
    395     dir->files.clear();
    396     dir->subdir_clear();
     352            break;
     353        *slash = 0; // 0-terminate cur_component
     354        const char* subdir_name = cur_component;
     355
     356        // create <subdir_name>
     357        // (note: no-op if it already exists
     358        if(create_missing_components)
     359            cur_dir->subdir_add(subdir_name);
     360
     361        // switch to <subdir_name>
     362        Dir* subdir = cur_dir->subdir_find(subdir_name);
     363        if(!subdir)
     364            return ERR_PATH_NOT_FOUND;
     365
     366        // next component
     367        cur_dir = subdir;
     368        cur_component = slash+1;
     369    }
     370
     371    // we have followed all path components.
     372
     373    // caller wants pointer to file location returned
     374    if(loc)
     375    {
     376        *loc = cur_dir->file_find(cur_component);
     377        // .. but the file doesn't exist
     378        if(!*loc)
     379            return ERR_FILE_NOT_FOUND;
     380    }
     381    // caller wants pointer to this dir returned
     382    if(dir)
     383        *dir = cur_dir;
     384    return 0;
    397385}
    398386
     
    400388static inline void tree_clear()
    401389{
    402     tree_clearR(&vfs_root);
    403 }
     390    vfs_root.clearR();
     391}
     392
     393
    404394
    405395
    406396struct FileCBParams
    407397{
    408     TreeDir* dir;
    409     const Loc* loc;
     398    Dir* const dir;
     399    const FileLoc* loc;
    410400};
    411401
     
    424414{
    425415    const FileCBParams* const params = (FileCBParams*)user;
    426     TreeDir* const cur_dir      = params->dir;
    427     const Loc* const cur_loc = params->loc;
     416    Dir* const cur_dir = params->dir;
     417    const FileLoc* const cur_loc = params->loc;
     418
     419    int err;
    428420
    429421    // directory
    430422    if(flags & LOC_DIR)
    431         cur_dir->subdir_add(fn);
     423        err = cur_dir->subdir_add(fn);
    432424    // file
    433425    else
    434         CHECK_ERR(cur_dir->file_add(fn, cur_loc->pri, cur_loc));
    435 
    436     return 0;
    437 }
    438 
    439 
    440 static int tree_add_dirR(TreeDir* const vdir, const char* const f_path, const Loc* const loc)
     426        err = cur_dir->file_add(fn, cur_loc);
     427
     428    if(err < 0)
     429        return -EEXIST;
     430    return 0;
     431}
     432
     433
     434static int tree_add_dirR(Dir* const dir, const char* const f_path, const FileLoc* const loc)
    441435{
    442436    CHECK_PATH(f_path);
    443437
    444     // add watch
    445     if(!vdir->watch)
    446         vdir->watch = 0;
    447 
    448438    // add files and subdirs to vdir
    449     const FileCBParams params = { vdir, loc };
     439    const FileCBParams params = { dir, loc };
    450440    file_enum(f_path, add_dirent_cb, (uintptr_t)&params);
    451441
    452     for(SubDirIt it = vdir->subdirs.begin(); it != vdir->subdirs.end(); ++it)
    453     {
    454         TreeDir* const vsubdir = it->second;
     442    for(SubDirIt it = dir->subdirs.begin(); it != dir->subdirs.end(); ++it)
     443    {
     444        Dir* const subdir = &it->second;
     445        const char* const subdir_name_c = (it->first).c_str();
    455446
    456447        char f_subdir_path[VFS_MAX_PATH];
    457         const char* const v_subdir_name_c = vsubdir->v_name.c_str();
    458         CHECK_ERR(path_append(f_subdir_path, f_path, v_subdir_name_c));
    459 
    460         tree_add_dirR(vsubdir, f_subdir_path, loc);
    461     }
    462 
    463     return 0;
    464 }
    465 
    466 
    467 static int tree_add_loc(TreeDir* const vdir, const Loc* const loc)
     448        CHECK_ERR(path_append(f_subdir_path, f_path, subdir_name_c));
     449
     450        tree_add_dirR(subdir, f_subdir_path, loc);
     451    }
     452
     453    return 0;
     454}
     455
     456
     457static int tree_add_loc(Dir* const dir, const FileLoc* const loc)
    468458{
    469459    if(loc->archive > 0)
    470460    {
    471         FileCBParams params = { vdir, loc };
     461        FileCBParams params = { dir, loc };
    472462        return zip_enum(loc->archive, add_dirent_cb, (uintptr_t)&params);
    473463    }
     
    475465    {
    476466        const char* f_path_c = loc->dir.c_str();
    477         return tree_add_dirR(vdir, f_path_c, loc);
     467        return tree_add_dirR(dir, f_path_c, loc);
    478468    }
    479469}
     
    490480// (we keep and pass around pointers to Mount.archive_locs elements)
    491481// see below.
    492 typedef std::list<Loc> Locs;
     482typedef std::list<FileLoc> Locs;
    493483typedef Locs::iterator LocIt;
    494484
     
    506496
    507497    // storage for all Locs ensuing from this mounting.
    508     // the VFS tree only holds pointers to Loc, which is why the
     498    // the VFS tree only holds pointers to FileLoc, which is why the
    509499    // Locs container must not invalidate its contents after adding,
    510500    // and also why the VFS tree must be rebuilt after unmounting something.
    511     Loc dir_loc;
     501    FileLoc dir_loc;
    512502    Locs archive_locs;
    513         // if not is_single_archive, contains one Loc for every archive
     503        // if not is_single_archive, contains one FileLoc for every archive
    514504        // in the directory (but not its children - see remount()).
    515         // otherwise, contains exactly one Loc for the single archive.
     505        // otherwise, contains exactly one FileLoc for the single archive.
    516506
    517507    // is f_name an archive filename? if not, it's a directory.
     
    547537    uint pri;
    548538
    549     // will add one Loc to this container for
     539    // will add one FileLoc to this container for
    550540    // every archive successfully opened.
    551541    Locs* archive_locs;
     
    574564    const Handle archive = zip_archive_open(f_path);
    575565    if(archive > 0)
    576         archive_locs->push_back(Loc(archive, "", pri));
     566        archive_locs->push_back(FileLoc(archive, "", pri));
    577567
    578568    // only add archive to list; don't add its files into the VFS yet,
     
    593583    const char* const f_name = m.f_name.c_str();
    594584    const uint pri           = m.pri;
    595     Loc& dir_loc             = m.dir_loc;
     585    FileLoc& dir_loc         = m.dir_loc;
    596586    Locs& archive_locs       = m.archive_locs;
    597587
    598     TreeDir* vdir;
    599     CHECK_ERR(tree_lookup(v_path, 0, &vdir, LF_CREATE_MISSING_COMPONENTS));
     588    Dir* dir;
     589    CHECK_ERR(tree_lookup(v_path, 0, &dir, LF_CREATE_MISSING_COMPONENTS));
    600590
    601591    // check if target is a single Zip archive
     
    605595    {
    606596        m.is_single_archive = true;
    607         archive_locs.push_back(Loc(archive, "", pri));
    608         const Loc* loc = &archive_locs.front();
    609         return tree_add_loc(vdir, loc);
     597        archive_locs.push_back(FileLoc(archive, "", pri));
     598        const FileLoc* loc = &archive_locs.front();
     599        return tree_add_loc(dir, loc);
    610600    }
    611601
     
    616606    for(LocIt it = archive_locs.begin(); it != archive_locs.end(); ++it)
    617607    {
    618         const Loc* const loc = &*it;
    619         tree_add_loc(vdir, loc);
     608        const FileLoc* const loc = &*it;
     609        tree_add_loc(dir, loc);
    620610    }
    621611
    622612
    623613    dir_loc.dir = f_name;
    624     err = tree_add_loc(vdir, &dir_loc);
     614    err = tree_add_loc(dir, &dir_loc);
    625615    if(err < 0)
    626616        err = err;
     
    634624    for(LocIt it = m.archive_locs.begin(); it != m.archive_locs.end(); ++it)
    635625    {
    636         Loc& loc = *it;
     626        FileLoc& loc = *it;
    637627        zip_archive_close(loc.archive);
    638628    }
     
    650640
    651641
    652 static void cleanup(void)
     642void vfs_shutdown(void)
    653643{
    654644    tree_clear();
     
    659649int vfs_mount(const char* const vfs_mount_point, const char* const name, const uint pri)
    660650{
    661     ONCE(atexit2(cleanup));
     651    ONCE(atexit2(vfs_shutdown));
    662652
    663653    // make sure it's not already mounted, i.e. in mounts
     
    716706///////////////////////////////////////////////////////////////////////////////
    717707//
    718 //
     708// directory
    719709//
    720710///////////////////////////////////////////////////////////////////////////////
    721711
    722 // OLD
    723 // rationale for n-archives per PATH entry:
    724 // We need to be able to unmount specific paths (e.g. when switching mods).
    725 // Don't want to remount everything (slow), or specify a mod tag when mounting
    726 // (not this module's job). Instead, we include all archives in one path entry;
    727 // the game keeps track of what path(s) it mounted for a mod,
    728 // and unmounts those when needed.
    729 
    730712
    731713int vfs_realpath(const char* fn, char* full_path)
    732714{
    733     const Loc* loc;
     715    const FileLoc* loc;
    734716    CHECK_ERR(tree_lookup(fn, &loc));
    735717
     
    752734int vfs_stat(const char* fn, struct stat* s)
    753735{
    754     const Loc* loc;
     736    const FileLoc* loc;
    755737    CHECK_ERR(tree_lookup(fn, &loc));
    756738
     
    767749struct VDir
    768750{
    769     TreeDir* dir;
    770     FileIt it;
     751    // we need to cache the complete contents of the directory:
     752    //
     753    SubDirs* subdirs;
     754    SubDirIt subdir_it;
     755    Files* files;
     756    FileIt file_it;
    771757};
    772758
    773759H_TYPE_DEFINE(VDir);
    774760
    775 
    776 
    777761static void VDir_init(VDir* vd, va_list args)
    778762{
     
    781765static void VDir_dtor(VDir* vd)
    782766{
    783     // remove reference to TreeDir, unlock it for further use
     767    delete vd->subdirs;
     768    delete vd->files;
    784769}
    785770
     
    787772{
    788773    // check if actually reloaded, and why it happened?
    789     // hmm, if TreeDir changes while handle is open, we are screwed.
    790     // need a lock.
    791 
    792     CHECK_ERR(tree_lookup(path, 0, &vd->dir));
    793 
    794     vd->it = vd->dir->files.begin();
     774
     775    Dir* dir;
     776    CHECK_ERR(tree_lookup(path, 0, &dir));
     777
     778    vd->subdirs = new SubDirs(dir->subdirs);
     779    vd->subdir_it = vd->subdirs->begin();
     780    vd->files = new Files(dir->files);
     781    vd->file_it = vd->files->begin();
    795782    return 0;
    796783}
     
    802789}
    803790
     791
    804792int vfs_close_dir(Handle& hd)
    805793{
     
    807795}
    808796
     797
     798// filter:
     799// 0: any file
     800// ".": file without extension (filename doesn't contain '.')
     801// ".ext": file with extension <ext> (which must not contain '.')
     802// "/": subdirectory
    809803int vfs_next_dirent(const Handle hd, vfsDirEnt* ent, const char* const filter)
    810804{
    811     // make sure filter is valid
    812     // interpret filter, decide if they want files or subdirs
    813 
    814     // until no more entries, or one matches filter
     805    H_DEREF(hd, VDir, vd);
     806
     807    // interpret filter
     808    bool filter_dir = false;
     809    bool filter_no_ext = false;
     810    if(filter)
     811    {
     812        if(filter[0] == '/')
     813        {
     814            if(filter[1] != '\0')
     815                goto invalid_filter;
     816            filter_dir = true;
     817        }
     818        else if(filter[0] == '.')
     819        {
     820            if(strchr(filter+1, '.'))
     821                goto invalid_filter;
     822            filter_no_ext = filter[1] == '\0';
     823        }
     824        else
     825            goto invalid_filter;
     826    }
     827
     828    const char* fn;
     829
     830    // caller wants a subdirectory; return the next one.
     831    if(filter_dir)
     832    {
     833        if(vd->subdir_it == vd->subdirs->end())
     834            return -1;
     835        fn = vd->subdir_it->first.c_str();
     836        ++vd->subdir_it;
     837        goto have_match;
     838    }
     839
     840    // caller wants a file; loop until one matches or end of list.
    815841    for(;;)
    816842    {
    817         H_DEREF(hd, VDir, vd);
    818         if(vd->it == vd->dir->files.end())
    819             return 1;
    820 
    821         const std::string& fn_s = vd->it->first;
    822         const char* const fn = fn_s.c_str();
    823 
    824         if(filter)
    825         {
    826             char* ext = strrchr(fn, '.');
    827             if(!ext || strcmp(ext, filter) != 0)
    828                 continue;
    829         }
    830 
    831         // found matching entry
    832     }
     843        if(vd->file_it == vd->files->end())
     844            return -1;
     845        fn = vd->file_it->first.c_str();
     846        ++vd->file_it;
     847
     848        char* const ext = strrchr(fn, '.');
     849        if(!filter || (filter_no_ext && !ext) || strcmp(ext, filter) == 0)
     850            goto have_match;
     851    }
     852
     853have_match:
     854    ent->name = fn;
     855    return 0;
     856
     857invalid_filter:
     858    debug_warn("vfs_next_dirent: invalid filter");
     859    return -1;
    833860}
    834861
     
    928955
    929956
    930     const Loc* loc;
     957    const FileLoc* loc;
    931958    CHECK_ERR(tree_lookup(path, &loc));
    932959
  • ps/trunk/source/lib/sysdep/win/waio.cpp

    r277 r334  
    2323#include "lib.h"
    2424#include "win_internal.h"
    25 #include "misc.h"
    26 #include "types.h"
    2725
    2826
  • ps/trunk/source/lib/sysdep/win/wdetect.cpp

    r293 r334  
    5252// useful for choosing a video mode. not called by detect().
    5353// if we fail, outputs are unchanged (assumed initialized to defaults)
    54 int get_cur_resolution(int& xres, int& yres)
    55 {
    56     DEVMODEA dm;
     54int get_cur_vmode(int* xres, int* yres, int* bpp, int* freq)
     55{
     56    DEVMODEW dm;
    5757    memset(&dm, 0, sizeof(dm));
    5858    dm.dmSize = sizeof(dm);
    5959    // dm.dmDriverExtra already set to 0 by memset
    6060
    61     if(!EnumDisplaySettingsA(0, ENUM_CURRENT_SETTINGS, &dm))
    62         return -1;
    63 
    64     xres = dm.dmPelsWidth;
    65     yres = dm.dmPelsHeight;
     61    if(!EnumDisplaySettingsW(0, ENUM_CURRENT_SETTINGS, &dm))
     62        return -1;
     63
     64    if(dm.dmFields & DM_PELSWIDTH && xres)
     65        *xres = (int)dm.dmPelsWidth;
     66    if(dm.dmFields & DM_PELSHEIGHT && yres)
     67        *yres = (int)dm.dmPelsHeight;
     68    if(dm.dmFields & DM_BITSPERPEL && bpp)
     69        *bpp  = (int)dm.dmBitsPerPel;
     70    if(dm.dmFields & DM_DISPLAYFREQUENCY && freq)
     71        *freq = (int)dm.dmDisplayFrequency;
     72
    6673    return 0;
    6774}
  • ps/trunk/source/lib/sysdep/win/wposix.cpp

    r322 r334  
    2727#include "hrt.h"
    2828
     29// waio included via lib -> posix -> wposix
     30
     31
     32static HANDLE mk_handle(intptr_t i)
     33{
     34    // passing in -1 (e.g. if _get_osfhandle fails),
     35    // is fine, it ends up INVALID_HANDLE_VALUE.
     36    return (HANDLE)((char*)0 + i);
     37}
     38
    2939
    3040//////////////////////////////////////////////////////////////////////////////
     
    6878int close(int fd)
    6979{
     80    assert(3 <= fd && fd < 256);
    7081    aio_close(fd);
    7182    return _close(fd);
     
    7586int ioctl(int fd, int op, int* data)
    7687{
    77     HANDLE h = (HANDLE)((char*)0 + _get_osfhandle(fd));
     88    const HANDLE h = mk_handle(_get_osfhandle(fd));
    7889
    7990    switch(op)
     
    213224
    214225
    215 static HANDLE std_h[2] = { (HANDLE)(((char*)0) + 3), (HANDLE)(((char*)0) + 7) };
     226static HANDLE std_h[2] = { (HANDLE)((char*)0 + 3), (HANDLE)((char*)0 + 7) };
    216227
    217228
     
    275286    if(param)
    276287    {
    277         HANDLE hThread = (HANDLE)((char*)0 + thread);
     288        const HANDLE hThread = mk_handle((intptr_t)thread);
    278289        param->sched_priority = GetThreadPriority(hThread);
    279290    }
     
    287298        SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
    288299
    289     HANDLE hThread = (HANDLE)((char*)0 + thread);
    290 
     300    const HANDLE hThread = mk_handle((intptr_t)thread);
    291301    SetThreadPriority(hThread, param->sched_priority);
    292302    return 0;
     
    389399    DWORD len_hi = (DWORD)((u64)len >> 32), len_lo = (DWORD)len & 0xffffffff;
    390400
    391     HANDLE hFile = (HANDLE)((char*)0 + _get_osfhandle(fd));
     401    HANDLE hFile = mk_handle(_get_osfhandle(fd));
    392402    HANDLE hMap = CreateFileMapping(hFile, &sec, flProtect, len_hi, len_lo, 0);
    393403
  • ps/trunk/source/lib/sysdep/win/wposix.h

    r277 r334  
    2727
    2828#include <sys/types.h>
     29#include <stddef.h>
    2930
    3031#ifdef __cplusplus
     
    3334
    3435
    35 #define IMP(ret, name, param) extern "C" __declspec(dllimport) ret __stdcall name param;
    36 
    37 // for functions actually implemented in the CRT
    38 #ifdef _DLL
    39 #define _CRTIMP __declspec(dllimport)
     36//
     37// <inttypes.h>
     38//
     39
     40typedef char int8_t;
     41typedef short int16_t;
     42typedef int int32_t;
     43#if defined(_MSC_VER) || defined(__INTEL_COMPILER) || defined(__LCC__)
     44typedef __int64 int64_t;
     45#elif defined(__GNUC__) || defined(__MWERKS__) || defined(__SUNPRO_C) || defined(__DMC__)
     46typedef long long int64_t;
    4047#else
    41 #define _CRTIMP
     48#error "port int64_t"
    4249#endif
    4350
    44 
    45 
    46 //
    47 // <inttypes.h>
    48 //
    49 
    50 typedef unsigned short u16_t;
     51typedef unsigned char uint8_t;
     52typedef unsigned short uint16_t;
     53typedef unsigned int uint32_t;
     54#if defined(_MSC_VER) || defined(__INTEL_COMPILER) || defined(__LCC__)
     55typedef unsigned __int64 uint64_t;
     56#elif defined(__GNUC__) || defined(__MWERKS__) || defined(__SUNPRO_C) || defined(__DMC__)
     57typedef unsigned long long uint64_t;
     58#else
     59#error "port uint64_t"
     60#endif
     61
     62#ifdef _MSC_VER
     63# ifndef _UINTPTR_T_DEFINED
     64#  define _UINTPTR_T_DEFINED
     65#  define uintptr_t unsigned int
     66# endif // _UINTPTR_T_DEFINED
     67# ifndef _INTPTR_T_DEFINED
     68#  define _INTPTR_T_DEFINED
     69#  define intptr_t signed int
     70# endif // _INTPTR_T_DEFINED
     71#else   // _MSC_VER
     72#include <stdint.h>
     73#endif  // _MSC_VER
    5174
    5275
     
    226249extern long sysconf(int name);
    227250
    228 #ifndef _WINSOCKAPI_
    229 
    230 IMP(int, gethostname, (char* name, size_t namelen))
    231 
    232 #endif
    233251
    234252//
  • ps/trunk/source/lib/sysdep/win/wsdl.cpp

    r329 r334  
    3232#include "lib.h"
    3333#include "win_internal.h"
    34 #include "misc.h"
    3534
    3635#include <SDL_vkeys.h>
  • ps/trunk/source/lib/sysdep/win/wsock.cpp

    r277 r334  
    4747
    4848
    49 u16_t htons(u16_t s)
     49uint16_t htons(uint16_t s)
    5050{
    5151    return (s >> 8) | ((s & 0xff) << 8);
  • ps/trunk/source/lib/sysdep/win/wsock.h

    r277 r334  
    22#define WSOCK_H__
    33
     4#define IMP(ret, name, param) extern "C" __declspec(dllimport) ret __stdcall name param;
     5
     6IMP(int, gethostname, (char* name, size_t namelen))
     7
    48
    59//
     
    1014typedef unsigned short sa_family_t;
    1115
    12 //#ifndef _WINSOCKAPI_
    13 
    1416// Win32 values - do not change
    15 
    1617#define SOCK_STREAM 1
    1718#define SOCK_DGRAM 2
     
    179180//
    180181
    181 extern u16_t htons(u16_t hostshort);
     182extern uint16_t htons(uint16_t hostshort);
    182183#define ntohs htons
    183184IMP(unsigned long, htonl, (unsigned long hostlong))
     
    194195IMP(ssize_t, sendto, (int, const void*, size_t, int, const struct sockaddr*, socklen_t))
    195196IMP(ssize_t, recvfrom, (int, void*, size_t, int, struct sockaddr*, socklen_t*))
    196  
    197 //#endif /* _WINSOCKAPI_ */
    198 
     197
     198
     199#undef IMP
    199200
    200201#endif  // #ifndef WSOCK_H__
  • ps/trunk/source/lib/sysdep/x.cpp

    r221 r334  
    2525// useful for choosing a video mode. not called by detect().
    2626// if we fail, outputs are unchanged (assumed initialized to defaults)
    27 int get_cur_resolution(int& xres, int& yres)
     27int get_cur_vmode(int* xres, int* yres, int* bpp, int* freq)
    2828{
    2929    Display* disp = XOpenDisplay(0);
     
    3232
    3333    int screen = XDefaultScreen(disp);
    34     xres = XDisplayWidth (disp, screen);
    35     yres = XDisplayHeight(disp, screen);
     34    if(xres)
     35        *xres = XDisplayWidth (disp, screen);
     36    if(yres)
     37        *yres = XDisplayHeight(disp, screen);
     38    if(bpp)
     39        *bpp = 0;
     40    if(freq)
     41        *freq = 0;
    3642    XCloseDisplay(disp);
    3743    return 0;
  • ps/trunk/source/lib/timer.cpp

    r221 r334  
    1818#include "precompiled.h"
    1919
     20#include "lib.h"
    2021#include "timer.h"
    21 #include "types.h"
    22 #include "misc.h"
    23 #include "lib.h"
    2422
    2523#ifdef _WIN32
  • ps/trunk/source/lib/types.h

    r164 r334  
     1// convenience type (shorter defs than stdint uintN_t)
     2
    13#ifndef __TYPES_H__
    24#define __TYPES_H__
    35
     6#include "posix.h"
    47
    58// defines instead of typedefs so we can #undef conflicting decls
    6 
    79
    810#define ulong unsigned long
     
    1012#define uint unsigned int
    1113
    12 #define i8 signed char
    13 #define i16 short
    14 #define i32 long
     14#define i8 int8_t
     15#define i16 int16_t
     16#define i32 int32_t
     17#define i64 int64_t
    1518
    16 #define u8  unsigned char
    17 #define u16 unsigned short
    18 #define u32 unsigned long       // long to match Win32 DWORD
    19 
    20 #if defined(_MSC_VER) || defined(__INTEL_COMPILER) || defined(__LCC__)
    21 #define i64 __int64
    22 #define u64 unsigned __int64
    23 #elif defined(__GNUC__) || defined(__MWERKS__) || defined(__SUNPRO_C) || defined(__DMC__)
    24 #define i64 long long
    25 #define u64 unsigned long long
    26 #else
    27 #error "TODO: port u64"
    28 #endif
     19#define u8  uint8_t
     20#define u16 uint16_t
     21#define u32 uint32_t
     22#define u64 uint64_t
    2923
    3024
    31 #define int8 i8
    32 #define int16 i16
    33 #define int32 i32
    34 
    35 #include <stddef.h>
    36 #ifdef _MSC_VER
    37 # ifndef _UINTPTR_T_DEFINED
    38 #  define _UINTPTR_T_DEFINED
    39 #  define uintptr_t u32
    40 # endif // _UINTPTR_T_DEFINED
    41 # ifndef _INTPTR_T_DEFINED
    42 #  define _INTPTR_T_DEFINED
    43 #  define intptr_t i32
    44 # endif // _INTPTR_T_DEFINED
    45 #else   // !_MSC_VER
    46 # include <stdint.h>
    47 #endif  // _MSC_VER
    48 
     25// the standard only guarantees 16 bits.
     26// we use this for memory offsets and ranges, so it better be big enough.
     27#if defined(SIZE_MAX) && SIZE_MAX < 32
     28#error "check size_t and SIZE_MAX - too small?"
     29#endif
     30   
    4931
    5032#endif // #ifndef __TYPES_H__
  • ps/trunk/source/main.cpp

    r322 r334  
    110110    fprintf(f, "%s\n", gfx_card);
    111111    fprintf(f, "%s\n", gfx_drv_ver);
     112    fprintf(f, "%dx%d:%d@%d\n", g_xres, g_yres, g_bpp, g_freq);
    112113    // .. network name / ips
    113114    char hostname[100]; // possibly nodename != hostname
    114115    gethostname(hostname, sizeof(hostname));
    115116    fprintf(f, "%s\n", hostname);
    116     hostent* h = gethostbyname(hostname);
    117     if(h)
    118     {
    119         struct in_addr** ips = (struct in_addr**)h->h_addr_list;
     117    hostent* host = gethostbyname(hostname);
     118    if(host)
     119    {
     120        struct in_addr** ips = (struct in_addr**)host->h_addr_list;
    120121        for(int i = 0; ips && ips[i]; i++)
    121122            fprintf(f, "%s ", inet_ntoa(*ips[i]));
     
    229230
    230231//////////////////////////////////////////////////////////////////////////////////////////////////
    231 // SubmitModelRecursive: recurse down given model, submitting it and all it's descendents to the
     232// SubmitModelRecursive: recurse down given model, submitting it and all its descendents to the
    232233// renderer
    233234void SubmitModelRecursive(CModel* model)
     
    434435#endif
    435436
     437
    436438    detect();
    437439
     
    477479    // preferred video mode = current desktop settings
    478480    // (command line params may override these)
    479     get_cur_resolution(g_xres, g_yres);
     481    get_cur_vmode(&g_xres, &g_yres, &g_bpp, &g_freq);
    480482
    481483    for(int a = 1; a < argc; a++)
     
    514516    vfs_mount("", "mods/official/", 0);
    515517////    dir_add_watch("mods\\official", false);
    516 
    517 
    518 //Handle xx = tex_load("art/textures/skins/structural/null.png");
    519518
    520519#ifndef NO_GUI
     
    640639    }
    641640
    642     // TODO MT: Move this to atexit() code? Capture original gamma ramp at initialization and restore it?
    643 
    644     SDL_SetGamma( 1.0f, 1.0f, 1.0f );
    645 
    646641#ifndef NO_GUI
    647642    g_GUI.Destroy();
     
    666661    delete CRenderer::GetSingletonPtr();
    667662
     663    exit(0);
    668664    return 0;
    669665}
  • ps/trunk/source/ps/Config.h

    r157 r334  
    4848//--------------------------------------------------------
    4949
    50 #include "stdlib.h"
     50#include <stdlib.h>
     51
    5152#include "Prometheus.h"
    5253#include "Singleton.h"
    5354#include "CStr.h"
    5455#include "LogFile.h"
    55 #include "posix.h"
    56 #include "misc.h"
     56#include "lib.h"
    5757
    5858#include <vector>
  • ps/trunk/source/ps/Overlay.cpp

    r288 r334  
    5050}
    5151
    52 CRect::CRect(const int32 &_l, const int32 &_t, const int32 &_r, const int32 &_b) :
     52CRect::CRect(const int32_t &_l, const int32_t &_t, const int32_t &_r, const int32_t &_b) :
    5353    left(_l), top(_t), right(_r), bottom(_b)
    5454{
     
    181181}
    182182
    183 int32 CRect::GetWidth() const
     183int32_t CRect::GetWidth() const
    184184{
    185185    return right-left;
    186186}
    187187
    188 int32 CRect::GetHeight() const
     188int32_t CRect::GetHeight() const
    189189{
    190190    return bottom-top;
     
    225225}
    226226
    227 CPos::CPos(const int32 &_x, const int32 &_y) : x(_x), y(_y)
     227CPos::CPos(const int32_t &_x, const int32_t &_y) : x(_x), y(_y)
    228228{
    229229}
     
    326326}
    327327
    328 CSize::CSize(const int32 &_cx, const int32 &_cy) : cx(_cx), cy(_cy)
     328CSize::CSize(const int32_t &_cx, const int32_t &_cy) : cx(_cx), cy(_cy)
    329329{
    330330}
  • ps/trunk/source/ps/Overlay.h

    r322 r334  
    1313#define COVERLAY_H
    1414
    15 #include "types.h"
     15#include "lib.h"
    1616
    1717struct CColor
     
    6161    CRect(const CPos &upperleft, const CPos &bottomright);
    6262    CRect(const CPos &pos, const CSize &size);
    63     CRect(const int32 &_l, const int32 &_t, const int32 &_r, const int32 &_b);
     63    CRect(const int32_t &_l, const int32_t &_t, const int32_t &_r, const int32_t &_b);
    6464
    6565    // Operators
     
    8787     * @return Width of Rectangle
    8888     */
    89     int32 GetWidth() const;
     89    int32_t GetWidth() const;
    9090   
    9191    /**
    9292     * @return Height of Rectangle
    9393     */
    94     int32 GetHeight() const;
     94    int32_t GetHeight() const;
    9595
    9696    /**
     
    129129     * Dimensions
    130130     */
    131     int32 left, top, right, bottom;
     131    int32_t left, top, right, bottom;
    132132};
    133133
     
    143143public:
    144144    CPos();
    145     CPos(const int32 &_x, const int32 &_y);
     145    CPos(const int32_t &_x, const int32_t &_y);
    146146
    147147    // Operators
     
    166166     * Position
    167167     */
    168     int32 x, y;
     168    int32_t x, y;
    169169};
    170170
     
    184184    CSize(const CRect &rect);
    185185    CSize(const CPos &pos);
    186     CSize(const int32 &_cx, const int32 &_cy);
     186    CSize(const int32_t &_cx, const int32_t &_cy);
    187187
    188188    // Operators
     
    207207     * Size
    208208     */
    209     int32 cx, cy;
     209    int32_t cx, cy;
    210210};
    211211
  • ps/trunk/source/ps/Singleton.h

    r162 r334  
    2121
    2222#include <assert.h>
    23 #include "types.h"  // uintptr_t - not otherwise defined by VC6
     23#include "lib.h"
    2424
    2525
  • ps/trunk/source/ps/ThreadUtil.h

    r170 r334  
    6767//--------------------------------------------------------
    6868
    69 #include "posix.h"
    70 #include "misc.h"
     69#include "lib.h"
     70
    7171#ifdef DEBUG_LOCKS
    7272
  • ps/trunk/source/renderer/PatchRData.cpp

    r322 r334  
    1 #pragma warning(disable:4786)
     1#include "precompiled.h"
    22
    33#include <assert.h>
  • ps/trunk/source/simulation/EntityProperties.cpp

    r284 r334  
    5050}
    5151
    52 CGenericProperty& CGenericProperty::operator=( int32 value )
     52CGenericProperty& CGenericProperty::operator=( int32_t value )
    5353{
    5454    if( m_type & PROP_TYPELOCKED )
  • ps/trunk/source/terrain/terrainMain.cpp

    r330 r334  
    4242void terr_init()
    4343{
    44     int xres,yres;
    45     get_cur_resolution(xres,yres);
    46     g_Renderer.Open(xres,yres,32);
     44    g_Renderer.Open(g_xres,g_yres,g_bpp);
    4745
    4846    SViewPort vp;
    4947    vp.m_X=0;
    5048    vp.m_Y=0;
    51     vp.m_Width=xres;
    52     vp.m_Height=yres;
     49    vp.m_Width=g_xres;
     50    vp.m_Height=g_yres;
    5351    g_Camera.SetViewPort(&vp);
    5452
Note: See TracChangeset for help on using the changeset viewer.