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 /// @file collision.h 23 24 #include "egoboo_typedef.h" 25 26 #include "hash.h" 27 #include "bbox.inl" 28 29 //-------------------------------------------------------------------------------------------- 30 //-------------------------------------------------------------------------------------------- 31 struct s_obj_BSP; 32 struct s_chr; 33 struct s_prt; 34 35 //-------------------------------------------------------------------------------------------- 36 //-------------------------------------------------------------------------------------------- 37 38 /// element for storing pair-wise "collision" data 39 /// @note this does not use the "standard" method of inheritance from hash_node_t, where an 40 /// instance of hash_node_t is embedded inside CoNode_t as CoNode_t::base or something. 41 /// Instead, a separate lists of free hash_nodes and free CoNodes are kept, and they are 42 /// associated through the hash_node_t::data pointer when the hash node is added to the 43 /// hash_list_t 44 struct s_CoNode 45 { 46 // the "colliding" objects 47 CHR_REF chra; 48 PRT_REF prta; 49 50 // the "collided with" objects 51 CHR_REF chrb; 52 PRT_REF prtb; 53 Uint32 tileb; 54 55 // some information about the estimated collision 56 float tmin, tmax; 57 oct_bb_t cv; 58 }; 59 typedef struct s_CoNode CoNode_t; 60 61 CoNode_t * CoNode_ctor( CoNode_t * ); 62 Uint8 CoNode_generate_hash( CoNode_t * coll ); 63 int CoNode_cmp( const void * pleft, const void * pright ); 64 65 //-------------------------------------------------------------------------------------------- 66 // a template-like definition of a dynamically allocated array of CoNode_t elements 67 DECLARE_DYNAMIC_ARY( CoNode_ary, CoNode_t ); 68 69 //-------------------------------------------------------------------------------------------- 70 // a template-like definition of a dynamically allocated array of hash_node_t elements 71 DECLARE_DYNAMIC_ARY( HashNode_ary, hash_node_t ); 72 73 //-------------------------------------------------------------------------------------------- 74 75 /// a useful re-typing of the CHashList_t, in case we need to add more variables or functionality later 76 typedef hash_list_t CHashList_t; 77 78 CHashList_t * CHashList_ctor( CHashList_t * pchlst, int size ); 79 CHashList_t * CHashList_dtor( CHashList_t * pchlst ); 80 bool_t CHashList_insert_unique( CHashList_t * pchlst, CoNode_t * pdata, CoNode_ary_t * cdata, HashNode_ary_t * hnlst ); 81 82 CHashList_t * CHashList_get_Instance( int size ); 83 84 //-------------------------------------------------------------------------------------------- 85 extern int CHashList_inserted; 86 87 //-------------------------------------------------------------------------------------------- 88 //-------------------------------------------------------------------------------------------- 89 // global functions 90 91 bool_t collision_system_begin(); 92 void collision_system_end(); 93 94 void bump_all_objects();