Pol  Revision:4b29d2b
multidef.h
Go to the documentation of this file.
1 
9 #ifndef MULTIDEF_H
10 #define MULTIDEF_H
11 
12 // also consider: multimap<unsigned int, unsigned int>
13 // unsigned int is (x << 16) | y
14 // unsigned int is z << 16 | objtype
15 // hell, even multimap<unsigned short,unsigned int>
16 // unsigned short is (x<<8)|y
17 // (relative signed x/y, -128 to +127
18 // unsigned int is z << 16 | objtype
19 
20 
21 #include <boost/noncopyable.hpp>
22 #include <cstdio>
23 #include <map>
24 #include <set>
25 #include <vector>
26 
27 #include "../../clib/rawtypes.h"
28 #include "../udatfile.h"
29 
30 namespace Pol
31 {
32 namespace Clib
33 {
34 class ConfigElem;
35 }
36 namespace Plib
37 {
38 class MapShapeList;
39 }
40 namespace Multi
41 {
42 extern void read_multidefs();
43 
44 struct MULTI_ELEM
45 {
46  unsigned short objtype;
47  s16 x;
48  s16 y;
49  s16 z;
50  bool is_static;
51 };
52 
53 class MultiDef
54 {
55 public:
56  explicit MultiDef( Clib::ConfigElem& elem, u16 multiid );
57  ~MultiDef();
58 
60  enum HOUSETYPE : u8
61  {
65  STAIRS
66  } type;
67 
68  std::vector<MULTI_ELEM> elems;
69 
70  short xbase; // x[0] is really x[xbase]
71  short xsize;
72  short ybase;
73  short ysize;
74 
75  typedef std::vector<const MULTI_ELEM*> HullList;
76  HullList hull;
77  HullList internal_hull;
78  typedef std::set<unsigned short> HullList2;
79  HullList2 hull2;
80  HullList2 internal_hull2;
81 
82  typedef std::multimap<unsigned short, const MULTI_ELEM*> Components;
83  typedef std::pair<Components::const_iterator, Components::const_iterator> ItrPair;
84 
85  short minrx, minry, minrz; // minimum relative distances
86  short maxrx, maxry, maxrz;
87  Components components;
88 
89  static short global_minrx;
90  static short global_minry;
91  static short global_minrz;
92  static short global_maxrx;
93  static short global_maxry;
94  static short global_maxrz;
95 
96  ItrPair findcomponents( short rx, short ry );
97 
98  bool findcomponents( Components::const_iterator& beg, Components::const_iterator& end, short rx,
99  short ry ) const;
100 
101  static unsigned short getkey( short rx, short ry );
102 
103  // returns true if it finds anything at this rx,ry
104  bool readobjects( Core::StaticList& vec, short rx, short ry, short zbase ) const;
105  bool readshapes( Plib::MapShapeList& vec, short rx, short ry, short zbase,
106  unsigned int anyflags ) const;
107 
108  bool body_contains( short rx, short ry ) const;
109  const MULTI_ELEM* find_component( short rx, short ry ) const;
110 
111  void add_to_hull( const MULTI_ELEM* elem );
112  void add_to_internal_hull( const MULTI_ELEM* elem );
113  void add_row_tohull( short y );
114  void add_body_tohull();
115  void eliminate_hull_dupes();
116  void computehull();
117  void addrec( const MULTI_ELEM* elem );
118  void fill_hull2();
119 
120  void init();
121 
122  size_t estimateSize() const;
123 };
124 
125 bool MultiDefByMultiIDExists( u16 multiid );
126 const MultiDef* MultiDefByMultiID( u16 multiid );
127 
128 inline unsigned short MultiDef::getkey( short rx, short ry )
129 {
130  unsigned char crx = static_cast<unsigned char>( rx );
131  unsigned char cry = static_cast<unsigned char>( ry );
132 
133  unsigned short key = ( crx << 8 ) | cry;
134  return key;
135 }
136 }
137 }
138 #endif
unsigned char u8
Definition: rawtypes.h:25
std::vector< StaticRec > StaticList
Definition: udatfile.h:38
static short global_maxry
Definition: multidef.h:93
HullList2 internal_hull2
Definition: multidef.h:80
Components components
Definition: multidef.h:87
static short global_maxrx
Definition: multidef.h:92
unsigned short u16
Definition: rawtypes.h:26
static short global_maxrz
Definition: multidef.h:94
signed short s16
Definition: rawtypes.h:30
std::pair< Components::const_iterator, Components::const_iterator > ItrPair
Definition: multidef.h:83
std::set< unsigned short > HullList2
Definition: multidef.h:78
std::vector< MULTI_ELEM > elems
Definition: multidef.h:68
static short global_minrz
Definition: multidef.h:91
std::vector< const MULTI_ELEM * > HullList
Definition: multidef.h:75
HullList2 hull2
Definition: multidef.h:79
bool MultiDefByMultiIDExists(u16 multiid)
Definition: multidef.cpp:293
static short global_minrx
Definition: multidef.h:89
static short global_minry
Definition: multidef.h:90
void read_multidefs()
Definition: multidef.cpp:309
std::multimap< unsigned short, const MULTI_ELEM * > Components
Definition: multidef.h:82
Definition: berror.cpp:12
HullList internal_hull
Definition: multidef.h:77
const MultiDef * MultiDefByMultiID(u16 multiid)
Definition: multidef.cpp:297
unsigned short objtype
Definition: multidef.h:46