home *** CD-ROM | disk | FTP | other *** search
/ 3D Games - Real-time Rend…ng & Software Technology / 3D Games - Real-time Rendering & Software Technology.iso / flysdk / lib / Fly3D.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-28  |  22.1 KB  |  886 lines

  1. #ifndef STRICT
  2. #define STRICT
  3. #endif
  4.  
  5. #ifdef FLY_EXPORTS
  6. #define FLY_API __declspec(dllexport)
  7. #else
  8. #define FLY_API __declspec(dllimport)
  9. #endif
  10.  
  11. class FLY_API boundbox;
  12. class FLY_API plane;
  13. class FLY_API face;
  14. class FLY_API local_system;
  15. class FLY_API base_object;
  16. class FLY_API sound;
  17. class FLY_API mesh;
  18. class FLY_API anim_mesh;
  19. class FLY_API stripfan_mesh;
  20. class FLY_API bezier_curve;
  21. class FLY_API bezier_patch;
  22. class FLY_API particle;
  23. class FLY_API bsp_node;
  24. class FLY_API bsp_object;
  25. class FLY_API static_mesh;
  26. class FLY_API light_map;
  27. class FLY_API light_map_pic;
  28. class FLY_API light_vertex;
  29. class FLY_API class_desc;
  30. class FLY_API console;
  31. class FLY_API flydll;
  32. class FLY_API flydllgroup;
  33. class FLY_API flyEngine;
  34.  
  35. #define MAX_ELEMDRAW 16384
  36. #define MAX_LIGHTMAP 8192
  37. #define MAX_PICTURES 1024
  38. #define MAX_VERT 4096
  39. #define MAX_HWLIGHTS 8
  40. #define MAX_TEXTURE_UNITS 4
  41. #define MAX_LATEDRAW_LAYERS 8
  42. #define MAX_SOUND_CHANNELS    4
  43.  
  44. #define NUM_DEFAULT_PARAM 12
  45.  
  46. #define FLYM_INITSCENE            1000
  47. #define FLYM_UPDATESCENE        1001
  48. #define FLYM_DRAWSCENE            1002
  49. #define FLYM_DRAWTEXT            1003
  50. #define FLYM_CLOSESCENE            1004
  51. #define FLYM_MPMESSAGE            1005
  52. #define FLYM_MPUPDATE            1006
  53.  
  54. #define FLYOBJM_CHANGEPARAM        2000
  55. #define FLYOBJM_ILLUM            2001
  56. #define FLYOBJM_STATICILLUM        2002
  57. #define FLYOBJM_DYNILLUM        2003
  58. #define FLYOBJM_DAMAGE            2004
  59.  
  60. #define FLYAPPID_NONE            0
  61. #define FLYAPPID_FLY            1
  62. #define FLYAPPID_FLYEDITOR        2
  63. #define FLYAPPID_LIGHTBSP        3
  64. #define FLYAPPID_FLYSERV        4
  65. #define FLYAPPID_FLYOCX            5
  66. #define FLYAPPID_VIEWBSPGL        6
  67.  
  68. #define TYPE_STATIC_MESH -1
  69.  
  70. #define MAPPING_NUM            4
  71. #define MAPPING_OPTIONS        16
  72. #define MAPPING_TEXTURE        1
  73. #define MAPPING_DETAIL        2
  74. #define MAPPING_LIGHTMAP    4
  75. #define MAPPING_FOGMAP        8
  76.  
  77. #define MESH_IMPLODE 1
  78. #define MESH_FACENORM 2
  79. #define MESH_VERTNORM 4
  80. #define MESH_BBOX 8
  81. #define MESH_EDGES 16
  82.  
  83. #define PATCH_EVAL_POINT        1
  84. #define PATCH_EVAL_TEXTCOORD    2
  85. #define PATCH_EVAL_NORMAL        4
  86.  
  87. #define CONSOLE_MAX_LINES 128
  88. #define CONSOLE_COL 40
  89. #define CONSOLE_LIN 30
  90. #define FONTS_IMG_SIZE 128
  91. #define FONTS_SIZE 16
  92. #define FONTS_NUM 8
  93.  
  94. #define PVS_TEST(from,to) \
  95.         (*(pvs + (from)*pvsrowsize + ((to)>>3)) & (1 << ((to) & 7)))
  96.  
  97. #include <windows.h>
  98. #include <stdio.h>
  99. #include <math.h>
  100. #include <mmsystem.h>
  101. #include <gl\gl.h>
  102. #include <gl\glu.h>
  103. #include "glext.h"
  104. #include "dx.h"
  105. #include "vecmat.h"
  106. #include "render.h"
  107. #include "picture.h"
  108. #include "flypak.h"
  109. #include "3dsimpexp.h"
  110.  
  111. struct vertex
  112. {
  113.     vector pos,normal,color;
  114.     float u,v,ul,vl;
  115. };
  116.  
  117. class FLY_API boundbox
  118. {
  119.     public:
  120.         vector min,max;
  121.  
  122.     void reset() { min.vec(BIG,BIG,BIG); max.vec(-BIG,-BIG,-BIG); };
  123.     int ray_intersect(vector& ro,vector& rd,float& tnear,float& tfar);
  124.     void add_point(vector &p);
  125.     void add_point(float x,float y,float z);
  126. };
  127.  
  128. class FLY_API local_system
  129. {
  130.     public:
  131.         vector X,Y,Z;    // base axis vector4s
  132.         mat4x4 mat,mat_t; // rotation matrix and transpose
  133.  
  134.     void update_mat();
  135.     void rotate(vector& rot);
  136.     void rotate(float ang,vector& v);
  137.     void rotate(vector &v, vector &u, float maxang=360);
  138.     void align_z(vector& z);
  139. };
  140.  
  141. class FLY_API plane
  142. {
  143.     public:
  144.         vector normal;        // plane normal
  145.         float d0;            // the perpendicular distance from the 
  146.                             // plane to the origin
  147.  
  148.     // computes the perpendicular distance from 
  149.     // a point to the plane
  150.     inline float distance(vector &v)
  151.         { return vec_dot(normal,v)+d0; }
  152. };
  153.  
  154. class FLY_API face : public plane
  155. {
  156.     public:
  157.         vector *vert[3];        // the 3 vertices
  158.         vector edgenormal[3];    // the 3 edge normals
  159.         vector vertnormal[3];    // the 3 vertices normals
  160.         vector color;            // the face color
  161.         int texpic;                // the texture applyed to the face
  162.         int lm;                    // the lightmap applyed to the face
  163.         float uv[3][2];            // the 3 vertices (u,v) texture coord.
  164.         float lmuv[3][2];        // lightmap 3 vertices (u,v) texture coord.
  165.         float emmradius;        // illum radius
  166.         int lastdraw;            // last time draw
  167.         int indx;                // face index into face array
  168.  
  169.     face() { texpic=-1; lm=-1; };
  170.  
  171.     // computes ray intersection with the face
  172.     int ray_intersect(vector& ro,vector& rd,vector& ip,float& dist,float rad=0.0f);
  173.  
  174.     // convert point p in face u,v coordinates
  175.     void inverse_map(vector& p,float& u,float& v);
  176.     // convert face u,v coordinates to point p
  177.     void forward_map(float& u,float& v,vector& p);
  178. };
  179.  
  180. class FLY_API base_object
  181. {
  182.     public: 
  183.         char name[32];            // the object name
  184.         char long_name[32];        // the object long name
  185.         base_object *next_obj;    // the next object in the linked list
  186.  
  187.     base_object()
  188.     { next_obj=0; name[0]=long_name[0]=0; };
  189.     virtual ~base_object()
  190.     { ; };
  191. };
  192.  
  193. class FLY_API sound : public base_object
  194. {
  195.     public:
  196.         int total_time;
  197.         
  198.         int bufuse[MAX_SOUND_CHANNELS];
  199.         LPDIRECTSOUNDBUFFER buf[MAX_SOUND_CHANNELS];
  200.         LPDIRECTSOUND3DBUFFER buf3d[MAX_SOUND_CHANNELS];
  201.  
  202.     void reset();
  203.     int load_wav(char *filename);
  204.     int get_sound_instace();
  205.     void free_sound_instance(int i);
  206.     
  207.     sound();
  208.     ~sound();
  209. };
  210.  
  211. // the object class implements a 3d object
  212. // its faces may reference the local faces or
  213. // the global engine bsp faces
  214. class FLY_API mesh : public base_object
  215. {
  216.     public:
  217.         int nv,        // number of vertices
  218.             nf;        // number of faces
  219.         vector *vert;    // the vertices
  220.         vector *vertnorm; // the vertices normals
  221.         face **faces;    // the faces
  222.         boundbox bbox;    // the object bound box
  223.         vector pivotpos;    // object pivot position
  224.         face *localfaces;    // the local faces
  225.         int *edges,nedges;    // the edges info
  226.         vector color;        // the color multiplier
  227.         float scrollu,scrollv;    // texture scroll values
  228.         int lastdraw;        // last time this mesh was drawn
  229.  
  230.     // frees the object
  231.     void reset();
  232.     // draws all object faces
  233.     virtual void draw();
  234.     virtual void draw_cartoon(vector& campos,vector& light,light_vertex& lights,float edgewidth);
  235.     virtual void draw_shadow_volume(vector& lightpos);
  236.     // loads a 3dsfile into this object
  237.     int load_3ds(char *name);
  238.     // compute face normals for all object faces and its boundbox
  239.     void compute_normals(int flag);
  240.     // computes ray intersection with all object faces
  241.     int ray_intersect(vector& ro,vector& rd,vector& ip,float& dist,float rad=0.0f);
  242.     // returns on first ray intersection
  243.     int ray_intersect_test(vector& ro,vector& rd,float rad=0.0f);
  244.     // dynamicaly illuminate object faces
  245.     void illum_faces(vector& ip,float d_max,vector& c,int shadows);
  246.     // weld all vertices closer then mindist
  247.     void implode(float mindist=0.1f);
  248.     // find a vertex edge for two mesh vertices
  249.     int get_edge(int v1,int v2);
  250.     // returns a new mesh identical to the original
  251.     mesh *clone();
  252.     void set_numverts(int nverts,int keep=0);
  253.     void set_numfaces(int nfaces,int local=0,int keep=0);
  254.  
  255.     mesh() 
  256.     { 
  257.         nv=0; nf=0;
  258.         vert=0; vertnorm=0; 
  259.         faces=0; localfaces=0; 
  260.         edges=0; nedges=0;
  261.         color.vec(1.0f,1.0f,1.0f,1.0f); 
  262.         scrollu=scrollv=0.0f;
  263.         lastdraw=0; 
  264.     };
  265.     virtual ~mesh()
  266.     { reset(); };
  267. };
  268.  
  269. class FLY_API anim_mesh : public mesh
  270. {
  271.     public:
  272.         int nframes,texpic;
  273.         vector *ao_vert;
  274.         vector *ao_bbox;
  275.         
  276.         int nstripfan,nstripfanvert,*stripfancount,*stripfanvert;
  277.         vertex *vertdata;
  278.  
  279.     void reset();
  280.     void compute_bbox();
  281.     int load_fao(char *name);
  282.     void set_key(float key);
  283.     void set_key(int key);
  284.     void draw();
  285.  
  286.     virtual ~anim_mesh() 
  287.     { reset(); };
  288.     anim_mesh()
  289.     {
  290.         ao_vert=0;
  291.         ao_bbox=0;
  292.         nframes=0;
  293.         nstripfan=0;
  294.         nstripfanvert=0;
  295.         stripfancount=0;
  296.         stripfanvert=0;
  297.         vertdata=0;
  298.         texpic=-1;
  299.     }
  300. };
  301.  
  302. class FLY_API stripfan_mesh
  303. {
  304.     public:
  305.         int nstripfan;
  306.         int *stripfandata;
  307.  
  308.         int nvert;
  309.         vertex *vertdata;
  310.  
  311.         void reset();
  312.         void draw(int mode);
  313.         mesh *build_mesh();
  314.         vertex *add_stripfan(int nvert,int texpic,int lmpic);
  315.     
  316.     stripfan_mesh()
  317.     {
  318.     nstripfan=0; stripfandata=0;
  319.     nvert=0; vertdata=0;
  320.     }
  321.     virtual ~stripfan_mesh()
  322.     {
  323.         reset();
  324.     }
  325. };
  326.  
  327. class FLY_API bezier_curve : public base_object
  328. {
  329.     protected:
  330.         float distance(float *p,float *p1,float *p2);
  331.         void subdiv(float u1,float u2,float *p1,float *p2,float *points,int& npoints,float maxerror,int maxpoints);
  332.  
  333.     public:
  334.         float *p;    // curve control points
  335.         int np,        // number of control points
  336.             ns,        // number of bezier segments ((np-1)/3)
  337.             nd;        // curve dimensions (2->2D, 3->3D, etc...)
  338.         vector pivot;    // curve pivot position
  339.  
  340.     void reset();
  341.     void set_dim(int ndim);
  342.     void add_point(float *f);
  343.     void evaluate(float u,float *f);
  344.     void evaluate_tangent(float u,float *f);
  345.     
  346.     int load_bez(char *file);
  347.     int adaptative_subdiv(float maxerror,float *points,int maxpoints);
  348.     float length();
  349.  
  350.     bezier_curve() { p=0; reset(); };
  351.     virtual ~bezier_curve() { reset(); };
  352. };
  353.  
  354. class FLY_API bezier_patch : public base_object
  355. {
  356.     public:
  357.         int mode;        // 2 for quadratic and 3 for cubic
  358.         vector *p;        // the surface control points
  359.         vector *t;        // the surface texture control points
  360.         int np,     // num points
  361.             npu, // num points in u dir
  362.             npv, // num points in v dir
  363.             nsu, // num segments in u dir
  364.             nsv; // num segments in u dir
  365.  
  366.         int levelu,levelv; // subdivision level in u and v
  367.         int nvertu,nvertv; // surface num vertices in u and v
  368.         int texpic,lm;    // texture and lightmap
  369.         vector *surf;    // discretized surface
  370.         vector pivot;    // the pivot position
  371.  
  372.     void reset();
  373.     int load_pch(char *file);
  374.     void build_loft(bezier_curve *shape,bezier_curve *path,int texture,int lightmap,float tileu,float tilev);
  375.     void evaluate(int evaltype,float u,float v,vector *dest);
  376.     void build_surface();
  377.     void illuminate(vector& p,float rad,vector& color,int shadows);
  378.     void draw(int nleveldrop=0);
  379.     mesh *build_mesh();
  380.  
  381.     bezier_patch()    { p=0; t=0; surf=0; reset(); };
  382.     ~bezier_patch()    { reset(); };
  383. };
  384.  
  385. // particle class implements a single, invisible, particle 
  386. class FLY_API particle
  387. {
  388.     public:
  389.         vector pos,        // particle position
  390.             vel,        // partuicle velocity
  391.             force;        // particle force
  392.         float mass,        // particle mass
  393.             bump,        // particle bump factor [0-1]
  394.             friction,    // particle friction factor [0-1]
  395.             radius;        // particle radius in mm
  396.         int life;        // particle life in ms
  397.         int col_flag;    // collision flag (0-no collision, 
  398.                         // 1-do collision, 3-collide and die)
  399.  
  400.     // computes particle collision
  401.     int compute_collision(vector& p,vector& v);
  402.  
  403.     // moves the particle dt ms
  404.     int step(int dt);
  405. };
  406.  
  407. class FLY_API param_desc
  408. {
  409.     public:
  410.         char name[64];
  411.         int type;
  412.         void *data;
  413.     
  414.     char *get_string();
  415.     void set_string(char *str);
  416. };
  417.  
  418. // the bsp_node class implements a node from the bsp tree
  419. // if it has no childs (child[0]==child[1]==0), elements
  420. // may be present in the elem linked list member
  421. class FLY_API bsp_node : public plane
  422. {
  423.     public:
  424.         bsp_node *child[2];        // the node childs
  425.         bsp_object 
  426.             *elem,            // the elements in this node
  427.             **last_elem;
  428.  
  429.         int leaf;        // leaf index (-1 not a leaf)
  430.         vector color;    // ambient light
  431.  
  432.     bsp_node()
  433.     { child[0]=child[1]=0; elem=0; leaf=-1; last_elem=&elem; };
  434.     virtual ~bsp_node();
  435. };
  436.  
  437. // bsp_object implements any object that is moving in space and
  438. // is considered a particle to bsp
  439. class FLY_API bsp_object :    public base_object,
  440.                             public particle, 
  441.                             public local_system
  442. {
  443.     public:
  444.         int type;            // object type
  445.         int active;            // actite at startup?
  446.         int latedraw;        // draw after standard objects
  447.         vector rot;            // rotation at startup
  448.         bsp_object *next_elem;    // next element in the bsp node
  449.         bsp_object *source;        // original object after cloning
  450.         bsp_node *node;            // the bsptree node the object is in
  451.  
  452.     // adds object to the bsp
  453.     void add_to_bsp();    
  454.  
  455.     // removes the object from the bsp
  456.     void remove_from_bsp();
  457.  
  458.     // moves the object dt ms
  459.     virtual int step(int dt)            
  460.     { return particle::step(dt); };
  461.  
  462.     virtual bsp_object *clone() 
  463.     { return 0; };
  464.  
  465.     virtual mesh *get_mesh()
  466.     { return 0; };
  467.  
  468.     virtual void init()
  469.     { ; };
  470.  
  471.     int get_param_desc(int i,param_desc *pd);
  472.  
  473.     virtual int get_custom_param_desc(int i,param_desc *pd)
  474.     { return 0; };
  475.  
  476.     virtual mesh *ray_intersect(vector& ro,vector& rd,vector& ip,float& dist,int &facenum,float rad=0.0f);
  477.     virtual int ray_intersect_test(vector& ro,vector& rd,float rad=0.0f);
  478.  
  479.     virtual int message(vector& p,float rad,int msg,int param,void *data)
  480.     { return 0; };
  481.  
  482.     virtual void draw();
  483.  
  484.     void load_default_params(fly_pak *file,char *sec);
  485.     void load_params(fly_pak *file,char *sec);
  486.  
  487.     bsp_object() 
  488.     { node=0; col_flag=0; source=0; next_elem=0; type=0; };
  489.     virtual ~bsp_object() 
  490.     { if (node) remove_from_bsp(); };
  491. };
  492.  
  493. // the static_object class implements the group of faces 
  494. // that are presentg at a bsp leaf node
  495. class FLY_API static_mesh : public bsp_object
  496. {
  497.     public:
  498.         mesh *objmesh;
  499.  
  500.     // computes ray intersection with the static object
  501.     mesh *ray_intersect(vector& ro,vector& rd,vector& ip,float& dist,int &facenum,float rad=0.0f);
  502.     int ray_intersect_test(vector& ro,vector& rd,float rad);
  503.     int message(vector& p,float rad,int msg,int param,void *data);
  504.  
  505.     static_mesh() 
  506.     { type=TYPE_STATIC_MESH; objmesh=new mesh; };
  507.     virtual ~static_mesh()
  508.     { if (objmesh) delete objmesh; };
  509. };
  510.  
  511. class FLY_API light_map_pic
  512. {
  513.     public:
  514.         unsigned char *bmp;
  515.         int sizex,sizey;
  516.         int bytesx,bytesxy;
  517.         int bytespixel;
  518.  
  519.     light_map_pic(int sx,int sy,int bp=3)
  520.     {
  521.         bytespixel=bp;
  522.         sizex=sx; 
  523.         sizey=sy; 
  524.         bytesx=sx*bytespixel;
  525.         bytesxy=bytesx*sizey;
  526.         bmp=new unsigned char [bytesxy];
  527.     };
  528.     virtual ~light_map_pic() 
  529.     { 
  530.         if(bmp) delete bmp; 
  531.     };
  532. };
  533.  
  534. class FLY_API light_map
  535. {
  536.     protected:
  537.         vector v0, v1, v2, normal;
  538.         float det;
  539.         float uv[3][2];
  540.     public:
  541.         int lastupdate;
  542.         int pic;
  543.         int offsetx,offsety;
  544.         int sizex,sizey;
  545.         int facenum;
  546.         unsigned char *bmp;
  547.         int bytespixel,bytesx,bytesxy;
  548.         vector d0, d1, d2;
  549.  
  550.     void map_point(float u, float v, vector &point);
  551.     void set_base(face *f,light_map_pic *lmp,vector& pos=vector(0,0,0));
  552.     void illum(vector& pos,vector& color,float rad,int shadows);
  553.     void load(light_map_pic *lmp);
  554.     void save(light_map_pic *lmp);
  555.  
  556.     light_map(int f,int p,int x,int y,int sx,int sy,int bp=3)
  557.     {
  558.         facenum=f;
  559.         pic=p;
  560.         offsetx=x;
  561.         offsety=y;
  562.         sizex=sx;
  563.         sizey=sy;
  564.         bytespixel=bp;
  565.         lastupdate=0;
  566.         bytesx=sx*bp;
  567.         if (bytesx&3) bytesx+=4-(bytesx&3);
  568.         bytesxy=bytesx*sy;
  569.         bmp=new unsigned char[bytesxy];
  570.     };
  571.     virtual ~light_map() 
  572.     { 
  573.         if (bmp) 
  574.             delete bmp; 
  575.     };
  576. };
  577.  
  578. class FLY_API light_vertex
  579. {
  580.     public:
  581.         int nlights;
  582.         vector pos[MAX_HWLIGHTS];
  583.         vector color[MAX_HWLIGHTS];
  584.         float radius[MAX_HWLIGHTS];
  585.  
  586.     light_vertex() { nlights=0; };
  587.     void add_light(vector& p,vector& c,float r);
  588.     void init_draw(bsp_object *obj);
  589.     void end_draw();
  590. };
  591.  
  592. // the class_desc, flydll and flydllgroup
  593. // classes are used to manage the plugins
  594. class FLY_API class_desc
  595. {
  596.     public:
  597.         virtual void *create()=0;
  598.         virtual char *get_name()=0;
  599.         virtual int get_type()=0;
  600. };
  601.  
  602. class FLY_API console
  603. {
  604.     public:
  605.         int mode,time,nlines,linecount,winlines;
  606.         char *buf[CONSOLE_MAX_LINES];
  607.  
  608.         char cmd_line[256];
  609.         int cmd_pos;
  610.  
  611.         float dx,dy;
  612.  
  613.     console();
  614.     ~console();
  615.  
  616.     void show();
  617.     void hide();
  618.     void draw();
  619.     void step(int dt);
  620.     float draw_text(float x,float y,char *text);
  621.  
  622.     void key_press(int key);
  623.     void add_string(char *fmt, ...);
  624.     int command_tokens(char *str,char **token);
  625.     void command_exec(char *str);
  626. };
  627.  
  628. class FLY_API flydll
  629. {
  630.     public:
  631.         HINSTANCE hdll;
  632.         char dll_filename[256];
  633.         int nclasses;
  634.  
  635.     int (* num_classes)();
  636.     class_desc *(* get_class_desc)(int i);
  637.     int (* fly_message)(int msg,int param,void *data);
  638. };
  639.  
  640. class FLY_API flydllgroup
  641. {
  642.     public:
  643.         int ndll;
  644.         flydll **dll;
  645.  
  646.         int ncd;
  647.         class_desc **cd;
  648.         
  649.     flydllgroup();
  650.     virtual ~flydllgroup();
  651.     
  652.     void reset();
  653.     
  654.     int add_dll(char *filename);
  655.     int delete_dll(char *filename);
  656.     void move_dll(char *filename,int newrelpos);
  657.  
  658.     int send_message(int msg,int param,void *data);
  659.     
  660.     void load_all_classes(fly_pak *file);
  661.     void load_classes(int d,fly_pak *file);
  662.     void load_default_param(bsp_object *o,char *sec,fly_pak *file);
  663.     void delete_class(bsp_object *o);
  664.     void delete_references(bsp_object *o);
  665.     bsp_object *add_class(char *name);
  666. };
  667.  
  668. class FLY_API flyEngine
  669. {
  670.     private:
  671.         int load_data();
  672.         void save_bsp(bsp_node *n,FILE *fp);
  673.         void load_bsp(bsp_node **n,fly_pak *fp);
  674.         
  675.         void find_leaf(bsp_node *n);
  676.         void draw_static_faces(int *fd,int nfd);
  677.         void draw_static_faces_cartoon(int *fd,int nfd);
  678.         void draw_bsp(bsp_node *n);
  679.  
  680.     protected:
  681.         void reset();
  682.         int load_pictures(char *name);
  683.         void load_level();
  684.         void compute_normals();
  685.         void compute_node_light();
  686.         void compute_edges();
  687.  
  688.         int load_bsp(char *file);
  689.         int save_bsp(char *file);
  690.  
  691.         int save_lightmaps(char *file);
  692.  
  693.         void alloc_pvs(char value);
  694.         int load_pvs(char *file);
  695.         int save_pvs(char *file);
  696.  
  697.     public:
  698.         int load_lightmaps(char *file);
  699.         int    cur_step,cur_step_base;
  700.         int cur_frame,cur_frame_base;
  701.         int start_time,cur_time,cur_dt;
  702.         int intropic,introtime;
  703.  
  704.         flydllgroup dll;
  705.         console con;
  706.  
  707.         bsp_object *player;
  708.         bsp_object *cam;
  709.         vector frustrum[5];
  710.  
  711.         bsp_object *excludecollision,*stepobj;
  712.  
  713.         int nelemdraw;
  714.         bsp_object *elemdraw[MAX_ELEMDRAW];
  715.         int nelemlatedraw[MAX_LATEDRAW_LAYERS];
  716.         bsp_object *elemlatedraw[MAX_LATEDRAW_LAYERS][MAX_ELEMDRAW];
  717.         int *facedraw;
  718.         int nfacedraw;
  719.         int *facedrawtransp;
  720.         int nfacedrawtransp;
  721.  
  722.         char flysdkpath[256];   // the sdk path (c:\flysdk\)
  723.         char flyfile[256];        // the .fly file (ship\ship.fly)
  724.         char flydatapath[256];    // the .fly path (c:\flysdk\data\ship\)
  725.         char flyfilename[256];    // the .fly full file (c:\flysdk\data\ship\ship.fly)
  726.         char bspfile[256];        // the bsp file (ship)
  727.         char status_msg[256];
  728.         char console_command[256];
  729.         unsigned status_msg_time;
  730.         
  731.         float bboxdiag,viewmaxdist,viewmindist,camangle,aspect,geomdetail,
  732.             curveerr,lmpxsize,detailtile,cartoonwidth,shadowdepth;
  733.         vector bbox1,bbox2,bboxC,filter,background,cartooncolor,shadowcolor;
  734.         int nodedrawcount,nodeonly,pvsoff,fog,mpdelay,antialias,
  735.             amblight,mapmode,shadows,noinput,wireframe,mute,mouse,
  736.             clearbk,moving,crosshairpic,crosshairsize,appid,multitexture,
  737.             detailpic,hwlights,stencil,cartoonpic,cartoonpicbsp;
  738.  
  739.         // linked list of active objects
  740.         bsp_object *active_obj0,*last_active_obj;
  741.         
  742.         // linked list of stock script objects
  743.         bsp_object *stock_obj0;
  744.  
  745.         // linked list of model objects
  746.         mesh *model_obj0;
  747.  
  748.         // linked list of sound objects
  749.         sound *sound_obj0;
  750.  
  751.         // linked list of bezier curves
  752.         bezier_curve *bezier_curve0;
  753.  
  754.         // linked list of bezier patches
  755.         bezier_patch *bezier_patch0;
  756.  
  757.         // dynamic shadows
  758.         bsp_object *shadow_obj;
  759.  
  760.         // ray intersection data
  761.         bsp_object *hitobj;
  762.         mesh *hitmesh;
  763.         int hitface;
  764.         vector hitip;
  765.  
  766.         // fonts
  767.         int fonts_width[64];
  768.         int status,fontspic,consolepic;
  769.  
  770.         // vertex array for static bsp faces
  771.         vector *vert,*vertcolor,*vertnormal;
  772.         int nvert;
  773.  
  774.         // faces array for static bsp
  775.         face *faces;
  776.         int nfaces;
  777.  
  778.         // edges array for static bsp faces
  779.         int *edges,nedges,*faceedges;
  780.  
  781.         // the bsp tree
  782.         bsp_node *bsp;
  783.  
  784.         // array of pictures used as texture maps
  785.         picture *piclib[MAX_PICTURES];
  786.         int npiclib;
  787.  
  788.         // lightmaps
  789.         light_map *lm[MAX_LIGHTMAP];
  790.         light_map_pic *lmpic[MAX_LIGHTMAP];
  791.         int nlm,lmbase,nlmpic;
  792.  
  793.         // fogmaps
  794.         light_map *fm[MAX_LIGHTMAP];
  795.         light_map_pic *fmpic[MAX_LIGHTMAP];
  796.         int fmbase;
  797.  
  798.         // the pvs
  799.         char *pvs;
  800.         bsp_node **leaf;
  801.         int nleaf,pvssize,pvsrowsize;
  802.  
  803.         // draws the scene recusively
  804.         void draw_bsp(int mode=0);
  805.  
  806.         // draws edges of the selected bsp faces from the draw_bsp function
  807.         void draw_bsp_edges();
  808.  
  809.         // compute collision
  810.         int collision_bsp(bsp_node *n,vector& p1,vector& p2,int elemtype=0,float rad=0.0f);
  811.         int collision_test(bsp_node *n,vector& p1,vector& p2,int elemtype=0,float rad=0.0f);
  812.  
  813.         // update scene for elapsed time dt in ms
  814.         void step(int dt);
  815.         int step();
  816.  
  817.         // recurse bsp calling a custom function
  818.         void apply_bsp(bsp_node *n,vector& p,float rad,void *data,void (*func)(void *data,bsp_object *e));
  819.         void apply_bsp(bsp_node *n,vector *p,int np,void *data,void (*func)(void *data,bsp_object *e));
  820.  
  821.         // recurse bsp sending messages
  822.         void send_bsp_message(bsp_node *n,vector& p,float rad,int msg,int param,void *data);
  823.  
  824.         // opens/closes a .fly file
  825.         int open_fly_file(char *file);
  826.         void close_fly_file();
  827.         int save_fly_file(char *file);
  828.  
  829.         // init/close the texture cache
  830.         int add_lightmap(int sx,int sy);
  831.         void init_texture_cache();
  832.         void close_texture_cache();
  833.     
  834.         // text output functions
  835.         void start_text_mode();
  836.         void end_text_mode();
  837.         int draw_text(int x,int y,char *text);
  838.         int draw_text_center(int x,int y,char *text);
  839.         void set_status_msg(char *fmt, ...);
  840.  
  841.         // load a picture to the texture cache or
  842.         // return its index if already loaded
  843.         int get_picture(char *file);
  844.  
  845.         // get objects from the scene
  846.         bsp_object *get_stock_object(char *name);
  847.         bsp_object *get_active_object(char *name);
  848.         mesh *get_model_object(char *name);
  849.         sound *get_sound_object(char *name);
  850.         bezier_curve *get_bezier_curve(char *name);
  851.         bezier_patch *get_bezier_patch(char *name);
  852.         bsp_object *get_next_stock_object(bsp_object *o,int type=0);
  853.         bsp_object *get_next_active_object(bsp_object *o,int type=0);
  854.         
  855.         int set_obj_param(char *objname,char *param,char *value);
  856.         int get_obj_param(char *objname,char *param,char *value);
  857.         int set_global_param(char *name,char *value);
  858.         int get_global_param_desc(int i,param_desc *pd);
  859.  
  860.         void activate(bsp_object *d,int flag=1);
  861.         void set_camera(bsp_object *d);
  862.  
  863.         // get a random point iside the level
  864.         bsp_node *get_random_point(vector& v,float mindist);
  865.         bsp_node *find_node(bsp_node *n,vector& v,float mindist);
  866.  
  867.         int join_multiplayer();
  868.         void close_multiplayer();
  869.         void check_multiplayer();
  870.  
  871.         flyEngine();
  872.         virtual ~flyEngine()
  873.         { close_fly_file(); };
  874. };
  875.  
  876. extern FLY_API flyEngine *flyengine;
  877. extern FLY_API GUID FLYGUID;
  878. extern FLY_API HWND hFlyWnd;
  879. extern FLY_API HINSTANCE hFlyInst;
  880.  
  881. FLY_API void init_engine(HWND hWnd,HINSTANCE hInst,int appid=FLYAPPID_NONE);
  882. FLY_API void set_engine(flyEngine *eng,HWND hWnd,HINSTANCE hInst,int appid=FLYAPPID_NONE);
  883. FLY_API void free_engine();
  884.  
  885. FLY_API BOOL FAR PASCAL MultiplayerProc(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam);
  886.