1 #pragma once
2 
3 //********************************************************************************************
4 //*
5 //*    This file is part of Egoboo.
6 //*
7 //*    Egoboo is free software: you can redistribute it and/or modify it
8 //*    under the terms of the GNU General Public License as published by
9 //*    the Free Software Foundation, either version 3 of the License, or
10 //*    (at your option) any later version.
11 //*
12 //*    Egoboo is distributed in the hope that it will be useful, but
13 //*    WITHOUT ANY WARRANTY; without even the implied warranty of
14 //*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 //*    General Public License for more details.
16 //*
17 //*    You should have received a copy of the GNU General Public License
18 //*    along with Egoboo.  If not, see <http://www.gnu.org/licenses/>.
19 //*
20 //********************************************************************************************
21 
22 #include "egoboo_typedef.h"
23 #include "egoboo_math.h"
24 
25 #if defined(__cplusplus)
26 extern "C"
27 {
28 #endif
29 
30 //--------------------------------------------------------------------------------------------
31 //--------------------------------------------------------------------------------------------
32 #define GRID_BITS       7
33 #define GRID_ISIZE     (1<<(GRID_BITS))
34 #define GRID_FSIZE     ((float)GRID_ISIZE)
35 #define GRID_MASK      (GRID_ISIZE - 1)
36 
37 #define MAPID                     0x4470614d                   ///< The string... MapD
38 #define MESH_MAXTOTALVERTRICES    1024*100
39 #define MAXMESHFAN                (512*512)                  ///< Terrain mesh size
40 #define MAXMESHTILEY              1024                       ///< Max tiles in y direction
41 #define MAXMESHVERTICES           16                         ///< Fansquare vertices
42 #define MAXMESHTYPE               64                         ///< Number of fansquare command types
43 #define MAXMESHCOMMAND            4                          ///< Draw up to 4 fans
44 #define MAXMESHCOMMANDENTRIES     32                         ///< Fansquare command list size
45 #define MAXMESHCOMMANDSIZE        32                         ///< Max trigs in each command
46 #define MAXTILETYPE               256                        ///< Max number of tile images
47 #define FANOFF                    0xFFFF                     ///< Don't draw the fansquare if tile = this
48 
49 #define CARTMAN_FIXNUM            4.125f ///< 4.150f             ///< Magic number
50 #define CARTMAN_SLOPE             50                        ///< increments for terrain slope
51 
52 #define INVALID_BLOCK ((Uint32)(~0))
53 #define INVALID_TILE  ((Uint32)(~0))
54 
55 #define VALID_GRID(PMPD, ID) ( (INVALID_TILE!=(ID)) && (NULL != (PMPD)) && (ID < (PMPD)->info.tiles_count) )
56 
57 /// The bit flags for mesh tiles
58     enum e_mpd_fx
59     {
60         MPDFX_REF             =       0,     ///< NOT USED
61         ///< Egoboo v1.0 : "0 This tile is drawn 1st"
62 
63         MPDFX_SHA             = ( 1 << 0 ),  ///< 0 == (val & MPDFX_SHA) means that the tile is reflected in the floors
64         ///< Egoboo v1.0: "0 This tile is drawn 2nd"
65         ///< aicodes.txt : FXNOREFLECT
66 
67         MPDFX_DRAWREF         = ( 1 << 1 ),  ///< the tile reflects characters
68         ///< Egoboo v1.0: "1 Draw reflection of characters"
69         ///< aicodes.txt : FXDRAWREFLECT
70 
71         MPDFX_ANIM            = ( 1 << 2 ),  ///< Egoboo v1.0: "2 Animated tile ( 4 frame )"
72         ///< aicodes.txt : FXANIM
73 
74         MPDFX_WATER           = ( 1 << 3 ),  ///< Egoboo v1.0: "3 Render water above surface ( Water details are set per module )"
75         ///< aicodes.txt : FXWATER
76 
77         MPDFX_WALL            = ( 1 << 4 ),  ///< Egoboo v1.0: "4 Wall ( Passable by ghosts, particles )"
78         ///< aicodes.txt : FXBARRIER
79 
80         MPDFX_IMPASS          = ( 1 << 5 ),  ///< Egoboo v1.0: "5 Impassable"
81         ///< aicodes.txt : FXIMPASS
82 
83         MPDFX_DAMAGE          = ( 1 << 6 ),  ///< Egoboo v1.0: "6 Damage"
84         ///< aicodes.txt : FXDAMAGE
85 
86         MPDFX_SLIPPY          = ( 1 << 7 )   ///< Egoboo v1.0: "7 Ice or normal"
87         ///< aicodes.txt : FXSLIPPY
88     };
89 
90 //--------------------------------------------------------------------------------------------
91 //--------------------------------------------------------------------------------------------
92 
93 /// The basic parameters needed to create an mpd
94     struct s_mpd_info
95     {
96         size_t          vertcount;                        ///< For malloc
97         int             tiles_x;                          ///< Size in tiles
98         int             tiles_y;
99     };
100     typedef struct s_mpd_info mpd_info_t;
101 
102 //--------------------------------------------------------------------------------------------
103 
104 /// The data describing a mpd tile
105     struct s_tile_info
106     {
107         Uint8   type;                              ///< Tile type
108         Uint16  img;                               ///< Get texture from this
109         Uint8   fx;                                ///< Special effects flags
110         Uint8   twist;
111     };
112     typedef struct s_tile_info tile_info_t;
113 
114 //--------------------------------------------------------------------------------------------
115 
116 /// The information for a single mpd vertex
117     struct s_mpd_vertex
118     {
119         fvec3_t    pos;                               ///< Vertex position
120         Uint8      a;                                 ///< Vertex base light
121     };
122     typedef struct s_mpd_vertex mpd_vertex_t;
123 
124 //--------------------------------------------------------------------------------------------
125 
126 /// A wrapper for the dynamically allocated memory in an mpd
127     struct s_mpd_mem
128     {
129         size_t          tile_count;                       ///< Number of tiles
130         tile_info_t *   tile_list;                        ///< Tile info
131 
132         size_t          vcount;                           ///< number of vertices
133         mpd_vertex_t *  vlst;                             ///< list of vertices
134     };
135     typedef struct s_mpd_mem mpd_mem_t;
136 
137 //--------------------------------------------------------------------------------------------
138 
139 /// The data describing a single mpd
140     struct s_mpd
141     {
142         mpd_info_t info;
143         mpd_mem_t   mem;
144     };
145     typedef struct s_mpd mpd_t;
146 
147 //--------------------------------------------------------------------------------------------
148 
149 /// A description of a tile type that allows some compression in the way vertices are stored in the mpd file
150     struct s_tile_definition
151     {
152         Uint8           numvertices;                ///< Number of vertices
153         float           u[MAXMESHVERTICES];         ///< Vertex texture posi
154         float           v[MAXMESHVERTICES];
155 
156         Uint8           command_count;                        ///< Number of commands
157         Uint8           command_entries[MAXMESHCOMMAND];      ///< Entries in each command
158         Uint16          command_verts[MAXMESHCOMMANDENTRIES]; ///< Fansquare vertex list
159     };
160     typedef struct s_tile_definition tile_definition_t;
161 
162 //--------------------------------------------------------------------------------------------
163 //--------------------------------------------------------------------------------------------
164     extern tile_definition_t tile_dict[MAXMESHTYPE];
165 
166 //--------------------------------------------------------------------------------------------
167 //--------------------------------------------------------------------------------------------
168 
169 /// the raw mpd loader
170     mpd_t *      mpd_load( const char *modname, mpd_t * pmesh );
171 
172     mpd_t *      mpd_ctor( mpd_t * pmesh );
173     mpd_t *      mpd_dtor( mpd_t * pmesh );
174     bool_t       mpd_free( mpd_t * pmesh );
175 
176     bool_t twist_to_normal( Uint8 twist, float v[], float slide );
177     Uint8  cartman_get_twist( int x, int y );
178 
179     void tile_dictionary_load_vfs( const char * filename, tile_definition_t dict[], size_t dict_size );
180 
181 //--------------------------------------------------------------------------------------------
182 //--------------------------------------------------------------------------------------------
183 
184 #if defined(__cplusplus)
185 }
186 #endif
187 
188 //--------------------------------------------------------------------------------------------
189 //--------------------------------------------------------------------------------------------
190 
191 #define _mpd_file_h