00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00061 #include "forward.h"
00062 #include "vector.h"
00063
00064
00065
00066
00067
00068
00069
00070
00071 #include <string.h>
00072 #include <stdio.h>
00073 #include <stdlib.h>
00074 #include <math.h>
00075
00076 #if defined(WIN32)
00077
00078
00079 # include <windows.h>
00080
00081
00082
00083 # include "extgl.h"
00084
00085 #else
00086
00087
00088
00089 # include <unistd.h>
00090 # include <sys/time.h>
00091 # include <sys/utsname.h>
00092 # include <X11/Xlib.h>
00093 # include <X11/Xutil.h>
00094
00095 # include <GL/gl.h>
00096 # include <GL/glx.h>
00097 # include <GL/glext.h>
00098
00099 # define MAX_PATH 512
00100
00101 #endif
00102
00103 #include <GL/glu.h>
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 #define OMICRON_VERSION "0.1.1" // please increment thx :)
00117
00119
00121 #define SafeDelete(a) \
00122 { if (a) { delete a; a = NULL; }}
00123
00125 #define SafeArrayDelete(a) \
00126 { if (a) { delete [] a; a = NULL; }}
00127
00129 #define StructElem(type, member) \
00130 (ulong)(((type*)(0))->member)
00131
00133
00134 extern unsigned long assertions;
00135
00140 #define DBGSTAMP \
00141 _log_printf(MSG_DEBUG, "* DEBUG **********************"); \
00142 _log_printf(MSG_DEBUG, "%s - at or near line %u", __FILE__, __LINE__);
00143
00149 #define ASTSTAMP(ex) \
00150 _log_printf(MSG_DEBUG, "* ASSERTION ******************"); \
00151 _log_printf(MSG_DEBUG, "Assertion '" #ex "' failed in" \
00152 "%s - at or near line %u", __FILE__, __LINE__);
00153
00155 #define DebugReturn \
00156 { DBGSTAMP; return; };
00157
00159 #define DebugReturnValue(a) \
00160 { DBGSTAMP; return a; };
00161
00163 #define AssertReturn(ex) \
00164 { ASTSTAMP(ex); assertions++; return; };
00165
00167 #define AssertReturnValue(ex, a) \
00168 { ASTSTAMP(ex); assertions++; return a; };
00169
00170 #define AssertReturn1(a) \
00171 { \
00172 if (!(a)) AssertReturn(a);\
00173 };
00174
00175 #define AssertReturn2(a,b) \
00176 { \
00177 if (!(a)) AssertReturn(a);\
00178 if (!(b)) AssertReturn(b);\
00179 };
00180
00181 #define AssertReturn3(a,b,c) \
00182 { \
00183 if (!(a)) AssertReturn(a);\
00184 if (!(b)) AssertReturn(b);\
00185 if (!(c)) AssertReturn(c);\
00186 };
00187
00188 #define AssertReturn4(a,b,c,d) \
00189 { \
00190 if (!(a)) AssertReturn(a);\
00191 if (!(b)) AssertReturn(b);\
00192 if (!(c)) AssertReturn(c);\
00193 if (!(d)) AssertReturn(d);\
00194 };
00195
00196 #define AssertReturnValue1(a,v) \
00197 { \
00198 if (!(a)) AssertReturnValue(a,v);\
00199 };
00200
00201 #define AssertReturnValue2(a,b,v) \
00202 { \
00203 if (!(a)) AssertReturnValue(a,v);\
00204 if (!(b)) AssertReturnValue(b,v);\
00205 };
00206
00207 #define AssertReturnValue3(a,b,c,v) \
00208 { \
00209 if (!(a)) AssertReturnValue(a,v);\
00210 if (!(b)) AssertReturnValue(b,v);\
00211 if (!(c)) AssertReturnValue(c,v);\
00212 };
00213
00214 #define AssertReturnValue4(a,b,c,d,v) \
00215 { \
00216 if (!(a)) AssertReturnValue(a,v);\
00217 if (!(b)) AssertReturnValue(b,v);\
00218 if (!(c)) AssertReturnValue(c,v);\
00219 if (!(d)) AssertReturnValue(d,v);\
00220 };
00221
00222 #define AssertThis { AssertReturn1(this) };
00223 #define AssertThisV { AssertReturnValue1(this, 0) };
00224 #define AssertThisValue(a) { AssertReturnValue1(this, a) };
00225
00227 #define INVALID_INDEX -1
00228
00230 #define PI 3.1415926535897932384626433832795f
00231
00232 #define PI2 6.2831853071795864769252867665590f
00233
00234 #define SQRT2 1.4142135623730950488016887242097f
00235
00236 #define SIN45 0.7071067811865475244008443621048f
00237
00238 #define DEG2RAD 0.0174532925199432957692369076848f
00239
00240 #define RAD2DEG 57.295779513082320876798154814105f
00241
00242 #define EQUAL_EPSILON 0.01f
00243
00245 #define TRUE_STRING "1yYtT"
00246
00248 #define FALSE_STRING "0nNfF"
00249
00251 #define frand(a,b) (((float)rand())/((float)RAND_MAX)*((b)-(a))+(a))
00252
00253 #define CLAMP(a, min, max) ((a>max)?(max):(a<min?min:a))
00254
00255 #define GETFRACTION(pos, a, b) ((pos-(a))/(b-(a)))
00256
00257 #define QUADVERTX(a) ((((a+1)/2)%2)?-1.0f:1.0f)
00258 #define QUADVERTY(a) ((((a+0)/2)%2)?-1.0f:1.0f)
00259
00260 #define NQUADVERTX(a) ((((a+1)/2)%2)?0.0f:1.0f)
00261 #define NQUADVERTY(a) ((((a+0)/2)%2)?0.0f:1.0f)
00262
00263
00264
00265 #define MSG_DEBUG3 -3 // exteme detail
00266 #define MSG_DEBUG2 -2
00267 #define MSG_DEBUG -1
00268 #define MSG_NORMAL 0 // normal output
00269 #define MSG_WARNING 1
00270 #define MSG_ERROR 2
00271 #define MSG_CRITICAL 3 // exits the program
00272
00273 #ifndef OMICRON_GLOBALTYPES_DEFINED
00274 #define OMICRON_GLOBALTYPES_DEFINED
00275
00276 typedef unsigned long ulong;
00277 typedef signed long slong;
00278
00279 typedef unsigned short ushort;
00280 typedef signed short sshort;
00281
00282 typedef unsigned char uchar;
00283 typedef signed char schar;
00284
00285
00286
00287
00292 typedef struct initvars_s
00293 {
00294
00295
00296 #if defined(WIN32)
00297
00300 HINSTANCE hInstance;
00301
00302 #else
00303
00306 Visual *vis;
00307
00308 XVisualInfo *vi;
00309
00312 Display *dpy;
00313
00314 #endif
00315
00317
00323 ulong wnd;
00324
00327 const char *wndclassname;
00328
00332 const char *wndtitle;
00333
00334 ushort hres,
00335 vres;
00338
00339 int argc;
00340 char **argv;
00341
00342 char bpp,
00343 zbuffer,
00344 stencil;
00352 bool nosound;
00353
00357 bool nogfx;
00358
00362 bool noinput;
00363
00367 bool fullscreen;
00368
00373 bool nolog;
00374
00376 } initvars_t;
00377
00379 class engine_interface_c
00380 {
00381 protected:
00382 public:
00383
00385 virtual void init(){};
00386
00388 virtual void deinit(){};
00389
00391 virtual void world_update(){};
00392
00394 virtual void gui_callback(struct uievent_s*){};
00395
00397 virtual void render(){};
00398
00401 virtual void afterframe(){};
00402 };
00403
00409 typedef struct gvar_s
00410 {
00411 initvars_t init;
00412
00413
00414
00417 bool bExit;
00418
00419 #if defined(WIN32)
00420
00421
00422 HGLRC hrc;
00423 HDC hdc;
00424
00425 #else
00426
00427
00428 GLXContext glxc;
00429
00430 #endif
00431
00432 sshort debuglevel;
00433
00446 list_c<shader_s> *shaders;
00447
00448 ulong lightcount;
00449 struct light_s *lights;
00450 sshort lightmap;
00451
00452 texture_manager_c *texman;
00453 file_manager_c *fileman;
00454 net_manager_c *netman;
00455 sound_manager_c *soundman;
00456 renderer_c *renderer;
00457
00463 gui_c *gui;
00464
00465
00466
00467 float aspect;
00468
00469
00470 float dtime;
00471 float time;
00472 float timescale;
00473 long frame;
00474
00475
00476 sshort mouse_dx;
00477 sshort mouse_dy;
00478 sshort mouse_dz;
00479 sshort mouse_b;
00480 sshort mouse_lb;
00481
00482 uchar kbdstate[256];
00483 uchar lkbdstate[256];
00484
00485 bool active;
00486 engine_interface_c *iface;
00487 } gvar_t;
00488
00489 #endif
00490
00491
00492
00493
00494
00495
00496
00499 void _log_printf
00500 (
00501 sshort level,
00502 char *fmt,
00503 ...
00504 );
00505
00509 void _convert_file_path
00510 (
00511 char *path
00512 );
00513
00516 void _convert_pak_path
00517 (
00518 char *path
00519 );
00520
00524 char* _strtrm
00525 (
00526 char *string,
00527 char *trimchrs
00528 );
00529
00532 schar _sgn
00533 (
00534 float f
00535 );
00536
00538 float _interpolate_float_linear
00539 (
00540 float a,
00541 float b,
00542 float frac
00543 );
00544
00547 void _swap_long
00548 (
00549 ulong &l
00550 );
00551
00552 extern gvar_t gv;
00553
00554 #if !defined(WIN32)
00555
00556 #define strcmpi strcasecmp
00557 #define _snprintf snprintf
00558
00559 #endif
00560
00561 #define fcos (float)cos
00562 #define fsin (float)sin
00563 #define ftan (float)tan