Changeset 82 for cpp/gdk/nonstd.h


Ignore:
Timestamp:
02/08/13 03:44:31 (11 years ago)
Author:
Maciej Komosinski
Message:

compiles under more platforms and OSes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/gdk/nonstd.h

    r69 r82  
    1 //Define rnd01, rnd0N, and randomN so that they
    2 //work in your C++ environment.
    3 //Some other functions/macros may also be needed if they
    4 //are missing in your environment, like min, max, etc.
     1#ifndef _NONSTD_H_
     2#define _NONSTD_H_
    53
    6 #ifndef __NONSTD_H
    7 #define __NONSTD_H
    8 
    9 #define APPLICATION_NAME "Framsticks"
    10 #define MAIN_FRAMSTICKS
    114#define SAFEDELETE(p) {if (p) {delete p; p=NULL;}}
    125#define SAFEDELETEARRAY(p) {if (p) {delete[] p; p=NULL;}}
    136
    14 //#ifndef _Windows   included below?
    15 //#include <stdlib.h>
    16 //#endif
     7#define roundToInt(x) ((int)(floor((x)+0.5)))
     8
     9
     10#define CPP_STR(s) CPP_XSTR(s)
     11#define CPP_XSTR(s) #s
     12
    1713
    1814#define DB(x) //output debug info. If needed, use #define DB(x) x
    1915//#define DB(x) x
    2016
     17
    2118// ms visual c++
    2219#ifdef _MSC_VER
    23  #define WIN32_LEAN_AND_MEAN     // Exclude rarely-used stuff from Windows headers
    24  #include <windows.h>
    25  #include <stdio.h>
    26  #include <stdarg.h>
     20 #include <stdio.h> //musi byc najpierw ten include zeby robic definy ponizej (albo bedzie '_vsnprintf': attributes inconsistent with previous declaration, stdio.h:358)
    2721 #define vsnprintf _vsnprintf
    28  #define _USE_MATH_DEFINES //after this is defined, the next #include <math.h> or <cmath> will define:
    29  //#ifndef M_PI
    30  //#define M_PI 3.1415926535897932384626433832795
    31  //#endif
    32  //#ifndef M_PI_2
    33  //#define M_PI_2 (M_PI/2)
    34  //#endif
     22 #define snprintf _snprintf
     23#endif
    3524
     25#ifdef MOBILE2D
     26 #define strdup _strdup
    3627#endif
    3728
    3829/////////////////////////////////////////////////////// 64-bit int type and other macros
    39 #ifdef _Windows
     30#ifdef _WIN32
    4031        typedef __int64 LONGLONG;
    41         #define PATHSEPARATORCHAR '\\'
    42         #define PATHSEPARATORSTRING "\\"
     32        #define PATH_SEPARATOR_CHAR '\\'
     33        #define PATH_SEPARATOR_STRING "\\"
    4334        #define FPU_THROWS_EXCEPTIONS
    4435        #define FOPEN_READ "rt"
     
    4738#else
    4839        #define LONGLONG long long int
    49         #define PATHSEPARATORCHAR '/'
    50         #define PATHSEPARATORSTRING "/"
     40        #define PATH_SEPARATOR_CHAR '/'
     41        #define PATH_SEPARATOR_STRING "/"
    5142        #define FOPEN_READ "r"
    5243        #define FOPEN_WRITE "w"
     
    5445#endif
    5546
    56 #ifdef __BORLANDC__
    57         #define fileExists(f) (!access(f,0))
    58         #include "stdlib.h" //random
    59         #define rnd01 ((double)((double)_lrand()/(double)(LRAND_MAX+1)))
    60         //#define rnd01 ((double)((double)rand()/(RAND_MAX+1)))
    61         #define rnd0N(num) ((double)((num)*rnd01))
    62         #define randomN(num) random(num) //uses _lrand
    63 #else
    64         #ifdef _MSC_VER
    65         #define fileExists(f) (!access(f,0))
    66         #else
    67         #define fileExists(f) (!access(f,R_OK))
    68         #endif
    6947
    70         //#define FLOATRAND
    71         #ifdef FLOATRAND
    72                 #define randomN(x) ((int)((x)*drand48()))
    73                 #define rnd01 (drand48())
    74                 #define rnd0N(x) (drand48()*(x))
    75         #else
    76                 #define rnd01 ((double)(rand()/(RAND_MAX+1.0)))
    77                 #define rnd0N(x) ((x)*rnd01)
    78                 #define randomN(x) ((int)rnd0N(x))
    79         #endif
     48
     49#ifdef LINUX
     50 #include <strings.h>
     51 #define stricmp(a,b) strcasecmp(a,b)
     52 #define _isnan(a) isnan(a) //do nonstd_math.h?
     53 #define GET_APP_HOME "./"
     54 #define GET_APP_RESOURCES "./"
    8055#endif
    8156
    82 
    83 #ifdef __GNUC__
    84 /*
    85         #define min(a,b) (((a)>(b))?(b):(a))
    86         #define max(a,b) (((a)>(b))?(a):(b))
    87         #define abs(a) ((a)>=0?(a):-(a))
    88 */
    89 #include <algorithm>
    90 using namespace std;
     57#ifdef IPHONE
     58 #include <string>
     59 #define _isnan(a) isnan(a) //do nonstd_math.h?
     60 std::string getAppHome(); //w tym pliku deklaracja funkcji nie pasuje...
     61 std::string getAppResources();
     62 #define GET_APP_HOME getAppHome()
     63 #define GET_APP_RESOURCES getAppResources()
    9164#endif
    9265
    93 #ifdef DEFINE_STRICMP_AS_STRCASECMP
    94 #define stricmp(a,b) strcasecmp(a,b)
     66#ifdef SHP
     67 //#define __assert_func(a,b,c,d) 0 //Currently, we are sorry to inform you that assert() is not yet supported. We have considered your request for internal discussion. No ale na szczêœcie w³asna (byle by by³a, bo i tak zak³adamy ze assert ktore przeciez dziala tylko w trybie debug nie jest potrzebne na bada) implementacja w "bada-assert.cpp"
     68 #define GET_APP_HOME "/Home/"
     69 #define GET_APP_RESOURCES "/Res/"
    9570#endif
    9671
     72#if defined(_WIN32) && !defined(SHP)
     73    #define GET_APP_HOME ".\\"
     74    #define GET_APP_RESOURCES ".\\"
    9775#endif
     76
     77//typedef unsigned char boolean; //niestety nie mozna uzyc 'bool' bo VC w rpcndr.h wlasnie tak definiuje booleana, jako unsigned char
     78//typedef char byte; //rozne srodowiska c++ definiuja byte jako unsigned char! w javie jest inaczej -> trzeba i tak zmienic w portowanych zrodlach byte na char.
     79
     80#endif
Note: See TracChangeset for help on using the changeset viewer.