Planeshift
|
00001 /* 00002 * psworld.h - author Matze Braun <[email protected]> and 00003 * Keith Fulton <[email protected]> 00004 * 00005 * Copyright (C) 2001 Atomic Blue ([email protected], http://www.atomicblue.org) 00006 * 00007 * 00008 * This program is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU General Public License 00010 * as published by the Free Software Foundation (version 2 of the License) 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 * 00019 */ 00020 #ifndef __PSWORLD_H__ 00021 #define __PSWORLD_H__ 00022 00023 //============================================================================= 00024 // Crystal Space Includes 00025 //============================================================================= 00026 #include <csgeom/transfrm.h> 00027 #include <csutil/parray.h> 00028 #include <csutil/weakref.h> 00029 00030 //============================================================================= 00031 // Project Includes 00032 //============================================================================= 00033 00034 //============================================================================= 00035 // Local Includes 00036 //============================================================================= 00037 00038 struct iBgLoader; 00039 struct iCollection; 00040 struct iEngine; 00041 00047 class psWorld 00048 { 00049 protected: 00050 csRef<iStringArray> regions; 00051 iObjectRegistry* object_reg; 00052 csWeakRef<iEngine> engine; 00053 csRef<iBgLoader> loader; 00054 00055 class sectorTransformation 00056 { 00057 // Transformation 00058 csHash<csReversibleTransform*, csPtrKey<iSector> > trans; 00059 00060 public: 00061 csHash<csReversibleTransform*, csPtrKey<iSector> >::GlobalIterator GetIterator() 00062 { 00063 return trans.GetIterator(); 00064 } 00065 00066 00067 void Set(iSector* sector, csReversibleTransform transform) 00068 { 00069 csReversibleTransform* transf = trans.Get(csPtrKey<iSector> (sector), NULL); 00070 00071 if(!transf) 00072 { 00073 transf = new csReversibleTransform(); 00074 trans.Put(csPtrKey<iSector> (sector), transf); 00075 } 00076 00077 *transf = transform; 00078 } 00079 00080 csReversibleTransform* Get(iSector* sector) 00081 { 00082 csReversibleTransform* got = trans.Get(csPtrKey<iSector> (sector), NULL); 00083 00084 return got; 00085 } 00086 00087 ~sectorTransformation() 00088 { 00089 csHash<csReversibleTransform*, csPtrKey<iSector> >::GlobalIterator iter = trans.GetIterator(); 00090 while(iter.HasNext()) 00091 delete iter.Next(); 00092 00093 trans.Empty(); 00094 } 00095 00096 }; 00097 00098 csArray<sectorTransformation> transarray; 00099 00100 public: 00101 00102 psWorld(); 00103 ~psWorld(); 00104 00106 bool Initialize(iObjectRegistry* object_reg); 00107 00109 bool NewRegion(const char* mapfile); 00110 00112 void GetAllRegionNames(csString &str); 00113 00115 bool WarpSpace(const iSector* from, const iSector* to, csVector3 &pos); 00116 00118 bool WarpSpaceRelative(const iSector* from, const iSector* to, csVector3 &pos); 00119 00121 bool Connected(const iSector* from, const iSector* to); 00122 00125 float Distance(const csVector3 &from_pos, const iSector* from_sector, csVector3 to_pos, const iSector* to_sector); 00126 00129 float Distance2(const csVector3 &from_pos, const iSector* from_sector, csVector3 to_pos, const iSector* to_sector); 00130 00132 float Distance(iMeshWrapper* ent1, iMeshWrapper* ent2); 00133 00135 void GetPosition(iMeshWrapper* entity, csVector3 &pos, float* yrot, iSector* §or); 00136 00143 static float Matrix2YRot(const csMatrix3 &mat); 00144 00151 static csVector3 Matrix2Rot(const csMatrix3 &mat); 00152 00157 iEngine* GetEngine() 00158 { 00159 return engine; 00160 } 00161 00162 void DumpWarpCache(); 00163 void BuildWarpCache(); 00164 }; 00165 00166 00167 #endif 00168