Planeshift
psworld.h
Go to the documentation of this file.
1 /*
2  * psworld.h - author Matze Braun <MatzeBraun@gmx.de> and
3  * Keith Fulton <keith@paqrat.com>
4  *
5  * Copyright (C) 2001 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
6  *
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation (version 2 of the License)
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  *
19  */
20 #ifndef __PSWORLD_H__
21 #define __PSWORLD_H__
22 
23 //=============================================================================
24 // Crystal Space Includes
25 //=============================================================================
26 #include <csgeom/transfrm.h>
27 #include <csutil/parray.h>
28 #include <csutil/weakref.h>
29 
30 //=============================================================================
31 // Project Includes
32 //=============================================================================
33 
34 //=============================================================================
35 // Local Includes
36 //=============================================================================
37 
38 struct iBgLoader;
39 struct iCollection;
40 struct iEngine;
41 
47 class psWorld
48 {
49 protected:
50  csRef<iStringArray> regions;
51  iObjectRegistry* object_reg;
52  csWeakRef<iEngine> engine;
53  csRef<iBgLoader> loader;
54 
56  {
57  // Transformation
58  csHash<csReversibleTransform*, csPtrKey<iSector> > trans;
59 
60  public:
61  csHash<csReversibleTransform*, csPtrKey<iSector> >::GlobalIterator GetIterator()
62  {
63  return trans.GetIterator();
64  }
65 
66 
67  void Set(iSector* sector, csReversibleTransform transform)
68  {
69  csReversibleTransform* transf = trans.Get(csPtrKey<iSector> (sector), NULL);
70 
71  if(!transf)
72  {
73  transf = new csReversibleTransform();
74  trans.Put(csPtrKey<iSector> (sector), transf);
75  }
76 
77  *transf = transform;
78  }
79 
80  csReversibleTransform* Get(iSector* sector)
81  {
82  csReversibleTransform* got = trans.Get(csPtrKey<iSector> (sector), NULL);
83 
84  return got;
85  }
86 
88  {
89  csHash<csReversibleTransform*, csPtrKey<iSector> >::GlobalIterator iter = trans.GetIterator();
90  while(iter.HasNext())
91  delete iter.Next();
92 
93  trans.Empty();
94  }
95 
96  };
97 
98  csArray<sectorTransformation> transarray;
99 
100 public:
101 
102  psWorld();
103  ~psWorld();
104 
106  bool Initialize(iObjectRegistry* object_reg);
107 
109  bool NewRegion(const char* mapfile);
110 
112  void GetAllRegionNames(csString &str);
113 
115  bool WarpSpace(const iSector* from, const iSector* to, csVector3 &pos);
116 
118  bool WarpSpaceRelative(const iSector* from, const iSector* to, csVector3 &pos);
119 
121  bool Connected(const iSector* from, const iSector* to);
122 
125  float Distance(const csVector3 &from_pos, const iSector* from_sector, csVector3 to_pos, const iSector* to_sector);
126 
129  float Distance2(const csVector3 &from_pos, const iSector* from_sector, csVector3 to_pos, const iSector* to_sector);
130 
132  float Distance(iMeshWrapper* ent1, iMeshWrapper* ent2);
133 
135  void GetPosition(iMeshWrapper* entity, csVector3 &pos, float* yrot, iSector* &sector);
136 
143  static float Matrix2YRot(const csMatrix3 &mat);
144 
151  static csVector3 Matrix2Rot(const csMatrix3 &mat);
152 
157  iEngine* GetEngine()
158  {
159  return engine;
160  }
161 
162  void DumpWarpCache();
163  void BuildWarpCache();
164 };
165 
166 
167 #endif
168 
psWorld is in charge of managing all regions (zone map files) and loading/unloading them as needed...
Definition: psworld.h:47
bool Connected(const iSector *from, const iSector *to)
Checks whether 2 sectors are connected via a warp portal.
csWeakRef< iEngine > engine
Definition: psworld.h:52
void Set(iSector *sector, csReversibleTransform transform)
Definition: psworld.h:67
void DumpWarpCache()
float Distance2(const csVector3 &from_pos, const iSector *from_sector, csVector3 to_pos, const iSector *to_sector)
Calculate the 2d distance between two to points either in same or different sectors. Return INFINITY_DISTANCE if no connection sectors where found.
void GetAllRegionNames(csString &str)
This makes a string out of all region names, separated by | chars.
csArray< sectorTransformation > transarray
Definition: psworld.h:98
static float Matrix2YRot(const csMatrix3 &mat)
obtain final rotation about y axis of an object.
csReversibleTransform * Get(iSector *sector)
Definition: psworld.h:80
csHash< csReversibleTransform *, csPtrKey< iSector > >::GlobalIterator GetIterator()
Definition: psworld.h:61
bool WarpSpaceRelative(const iSector *from, const iSector *to, csVector3 &pos)
Changes pos according to the warp portal between adjacent sectors from and to using a relative transf...
csRef< iBgLoader > loader
Definition: psworld.h:53
bool NewRegion(const char *mapfile)
Create a new psRegion entry and load it if specified.
csRef< iStringArray > regions
Definition: psworld.h:50
bool Initialize(iObjectRegistry *object_reg)
Initialize psWorld.
bool WarpSpace(const iSector *from, const iSector *to, csVector3 &pos)
Changes pos according to the warp portal between adjacent sectors from and to.
iEngine * GetEngine()
obtain the engine.
Definition: psworld.h:157
static csVector3 Matrix2Rot(const csMatrix3 &mat)
obtain the rotation about the axes - expensive.
iObjectRegistry * object_reg
Definition: psworld.h:51
float Distance(const csVector3 &from_pos, const iSector *from_sector, csVector3 to_pos, const iSector *to_sector)
Calculate the distance between two to points either in same or different sectors. Return INFINITY_DIS...
void GetPosition(iMeshWrapper *entity, csVector3 &pos, float *yrot, iSector *&sector)
Return an enties position.
void BuildWarpCache()