1 /*! 2 * \file 3 * \ingroup display 4 * \brief Handles rendering and loading 2d objects 5 */ 6 #ifndef __OBJ_2D_H__ 7 #define __OBJ_2D_H__ 8 9 #include "vmath.h" 10 #include "bbox_tree.h" 11 12 #ifdef __cplusplus 13 extern "C" { 14 #endif 15 16 /*! 17 *\name 2D Object array sizes 18 * The sizes of the arrays where we keep 2d objects and 2d object definitions 19 */ 20 /*! \{ */ 21 #define MAX_OBJ_2D 15000 /*!<Maximum number of 2d objects in a map*/ 22 #define MAX_OBJ_2D_DEF 1000 /*!<Maximum number of loaded 2d object definitions*/ 23 /*! \} */ 24 25 /*! 26 * obj_2d_def is loaded from a .2do-file and is shared amongst all objects of that type in the obj_2d_def_cache array 27 */ 28 typedef struct 29 { 30 #ifdef FASTER_MAP_LOAD 31 char file_name[128]; /*!< name of the file that contains the definition of the 2d object */ 32 #endif 33 34 /*! 35 * \name start and end coordinates of the texture 36 * @{ 37 */ 38 float u_start; /*!< start position of the u coordinate */ 39 float u_end; /*!< end position of the u coordinate */ 40 float v_start; /*!< start position of the v coordinate */ 41 float v_end; /*!< end position of the v coordiante */ 42 /*! @} */ 43 44 /*! 45 * \name size of the 2d object 46 * @{ 47 */ 48 float x_size; /*!< size in x direction */ 49 float y_size; /*!< size in y direction */ 50 /*! @} */ 51 52 float alpha_test; /*!< Use alpha?*/ 53 int object_type; /*!< Is this a ground, fence or plant object? 54 * ground: don't change rotation 55 * plant: put in an upwards rotation (x_rot+=90) and set z_rot=-rz 56 * fence: put in an upwards rotation (x_rot+=90) 57 */ 58 int texture_id; /*!< The location in the texture cache. */ 59 } obj_2d_def; 60 61 /*! 62 * The obj_2d determines the position and rotation of the given 2d object. Furthermore it determines the type 63 */ 64 typedef struct 65 { 66 #ifndef FASTER_MAP_LOAD 67 char file_name[80]; /*!< name of the file that contains the definition of the 2d object */ 68 #endif 69 70 /*! 71 * \name position of the object 72 * @{ 73 */ 74 float x_pos; 75 float y_pos; 76 float z_pos; 77 /*! @} */ 78 79 /*! 80 * \name rotation of the object 81 * @{ 82 */ 83 float x_rot; 84 float y_rot; 85 float z_rot; 86 /*! @} */ 87 88 MATRIX4x4 matrix; /*!< translation and rotaion matrix */ 89 char display;/*!< flag determining whether the object is to be shown on screen. */ 90 char state; /*!< state flag for future expansion & data alignment. */ 91 obj_2d_def *obj_pointer; /**< Points to the 2d object type in the obj_2d_def list */ 92 93 #ifdef CLUSTER_INSIDES 94 short cluster; 95 #endif 96 } obj_2d; 97 98 #ifndef FASTER_MAP_LOAD 99 /*! 100 * This is used for searching the 2d object cache for an already existing instance of the object definition 101 */ 102 typedef struct 103 { 104 char file_name[128]; /*!< the filename of the object */ 105 obj_2d_def *obj_2d_def_id; /*!< a pointer to the header structure of this object */ 106 }obj_2d_cache_struct; 107 108 extern obj_2d_cache_struct obj_2d_def_cache[MAX_OBJ_2D_DEF]; /*!< The 2d object cache array - holds all loaded 2d object definitions*/ 109 #endif // FASTER_MAP_LOAD 110 extern obj_2d *obj_2d_list[MAX_OBJ_2D]; /*!< The 2d object array - holds all 2d objects on that map*/ 111 112 extern float texture_scale; /*!< scaling factor for textures */ 113 114 /*! 115 * \ingroup display_2d 116 * \brief Displays the 2d object given by object_id 117 * 118 * Displays the 2D object given by object_id 119 */ 120 void draw_2d_object(obj_2d * object_id); 121 122 /*! 123 * \ingroup display_2d 124 * \brief Displays the 2dobjects in the obj_2d_list array 125 * 126 * Parses through the obj_2d_list, checking for an object within the viewing distance (dist_x^2+dist_y^2<=220) 127 * 128 * \sa draw_2d_object 129 * \sa obj_2d_list 130 * \callgraph 131 */ 132 void display_2d_objects(); 133 134 #ifdef CLUSTER_INSIDES 135 /*! 136 * \ingroup load_2d 137 * \brief Get the bounding box of a 2D object 138 * 139 * Compute the bounding box for the 2D object with ID \a id. 140 * 141 * \param id The position on obj_2d_list of the object 142 * \param box Pointer to the resulting bounding box 143 * \retval int 0 on failure, 1 on success 144 */ 145 int get_2d_bbox (int id, AABBOX* box); 146 #endif // CLUSTER_INSIDES 147 148 #ifdef FASTER_MAP_LOAD 149 /*! 150 * \ingroup load_2d 151 * \brief Adds a 2d object at the given location. 152 * 153 * Add a 2d object at the given location. 154 * This is usually called in the map loading process. Requires a location and 155 * rotation for the 2d object, that's loaded from the file \a file_name. 156 * 157 * \param id_hint Hint on the position of the object in the list. If 158 * this spot is already taken, a vacant spot will be 159 * chosen, but chances are that mouse click events on 160 * object will not work because of a wrong ID. 161 * \param file_name The filename of the object we wish to add 162 * \param x_pos The x position 163 * \param y_pos The y position 164 * \param z_pos The z position 165 * \param x_rot The x rotation 166 * \param y_rot The y rotation 167 * \param z_rot The z rotation 168 * \param dynamic Whether this is a dynamic object 169 * \retval int Returns -1 on failure and the location in the obj_2d_list if it succeeds 170 * \note Parameter \a dynamic seems to be always 0 in the current code. It is also 171 * unclear whether it has any use at all. 172 * \callgraph 173 */ 174 int add_2d_obj(int id_hint, const char* file_name, 175 float x_pos, float y_pos, float z_pos, 176 float x_rot, float y_rot, float z_rot, unsigned int dynamic); 177 #else // FASTER_MAP_LOAD 178 /*! 179 * \ingroup load_2d 180 * \brief Adds a 2d object at the given location. 181 * 182 * Adds a 2d object at the given location. 183 * It's usually called in the map loading process. Requires a location and rotation for the 2d object, that's loaded from the file given by the first parameter 184 * 185 * \param file_name The filename of the object we wish to add 186 * \param x_pos The x position 187 * \param y_pos The y position 188 * \param z_pos The z position 189 * \param x_rot The x rotation 190 * \param y_rot The y rotation 191 * \param z_rot The z rotation 192 * \param dynamic Whether this is a dynamic object 193 * \retval int Returns -1 on failure and the location in the obj_2d_list if it succeeds 194 * \note Parameter \a dynamic seems to be always 0 in the current code. It is also 195 * unclear whether it has any use at all. 196 * \callgraph 197 */ 198 int add_2d_obj(char * file_name, float x_pos, float y_pos, float z_pos, 199 float x_rot, float y_rot, float z_rot, unsigned int dynamic); 200 #endif // FASTER_MAP_LOAD 201 202 /*! 203 * \ingroup load_2d 204 * \brief Show or hide one or more 2D map objects 205 * 206 * Show or hide 2D map objects. 207 * This routine is usually under server control to allow dynamically enabling or disabling seeing objects 208 * 209 * \param display whether the objects are to be displayed or not 210 * \param ptr pointer to an array of object ID's to be affected 211 * \param len the length in bytes of the array 212 * \callgraph 213 */ 214 void set_2d_object (Uint8 display, const void *ptr, int len); 215 216 /*! 217 * \ingroup load_2d 218 * \brief Set the state for one or more 2D map objects 219 * 220 * Set the sate for 2D map objects. 221 * This routine is usually under server control to allow dynamically setting a state for an object, this is for future expansion 222 * 223 * \param state The state to set for the object or objects 224 * \param ptr pointer to an array of object ID's to be affected 225 * \param len the length in bytes of the array 226 * \callgraph 227 */ 228 void state_2d_object (Uint8 state, const void *ptr, int len); 229 230 /*! 231 * \ingroup display_2d 232 * \brief Destroys the 2d object at position i in the obj_2d_list 233 * 234 * Destroys the 2d object on position i in the obj_2d_list - frees the memory and sets the obj_2d_list[i]=NULL. 235 * 236 * \param i The position in the obj_2d_list 237 * 238 * \callgraph 239 */ 240 void destroy_2d_object(int i); 241 242 /*! 243 * \ingroup display_2d 244 * \brief Destroys all current 2d objects 245 * 246 * Destroys all 2d objects currently in the obj_2d_list 247 * 248 * \callgraph 249 */ 250 void destroy_all_2d_objects(void); 251 252 /*! 253 * \ingroup display_2d 254 * \brief Destroys all current 2d object defs 255 * 256 * Destroys all 2d object defs currently in the obj_2d_def_cache 257 * 258 * \callgraph 259 */ 260 void destroy_all_2d_object_defs(void); 261 262 #ifdef NEW_SOUND 263 /*! 264 * \ingroup load_2d 265 * \brief Searches for a 2d ground object at a location 266 * 267 * It searches for a 2d ground object at the specified location 268 * 269 * \param x_pos The x position to search for 270 * \param y_pos The y position to search for 271 * \retval char Returns the object's filename if found, "" otherwise. 272 * 273 * \sa add_e3d_at_id 274 * 275 * \callgraph 276 */ 277 const char* get_2dobject_at_location(float x_pos, float y_pos); 278 #endif // NEW_SOUND 279 280 #ifdef MAP_EDITOR2 281 /*! 282 * \ingroup display_2d 283 * \brief Draws all 2D objects and evaluates collision with the mouse pointer 284 * 285 * Draws all 2D objects and evaluates collision with the mouse pointer - if there's a collision it sets selected_2d_object accordingly 286 */ 287 void get_2d_object_under_mouse(); 288 #endif 289 290 #ifdef __cplusplus 291 } // extern "C" 292 #endif 293 294 #endif 295