1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
|
/*
Map2cs: a convertor to convert the frequently used MAP format, into
something, that can be directly understood by Crystal Space.
Copyright (C) 1999 Thomas Hieber (thieber@gmx.net)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef MAP_H
#define MAP_H
#include "contain.h"
#include "texman.h"
class csConfigFile;
class CZipFile;
struct TextureInfo
{
csString FileName;
int SizeX;
int SizeY;
bool WadTexture;
};
/**
* This is the main class to manage all information found within
* a map file.
* That file can consist of any number of entities, which can all
* contain any number of brushes.
* The entities will define the function of the brushes (world
* geometry, doors, water).
* For simplification, we will also store all possible planes here.
* This is an optimisation, that is being done while reading, because
* only unique planes are being created. This will allow a direct
* realtion to the plane statement in Crystal Space worldfiles, which
* will define the texture orientation.
*/
class CMapFile
{
public:
/**
* Constructs the map
*/
CMapFile();
/**
* Destructor, will do cleanup. It will take care of removing all
* entities and planes.
*/
~CMapFile();
/**
* Reads the given mapfile. It will do detailed error handling and
* error messages by itself. It will return, true, if it was able
* to load the complete file, and false, if there was an error, and
* loading did not successfully finish. It will _not_ clean up the
* already loaded part.
* This method can currently be called only once for every instance
* of this class. Otherwise, you will merge both map files.
*/
bool Read(const char* filename, const char* configfile);
/**
* Writes all the missing textures to the configfile.
*/
bool WriteTextureinfo();
/**
* This method will look for the given Plane in the Plane List.
* If a similar Plane (Same position Texture and Texture alignment)
* is found, it will return a pointer the the already available
* plane otherwise it will create a new plane and return a pointer
* to that plane.
*/
CMapTexturedPlane* AddPlane(CdVector3 v1, CdVector3 v2, CdVector3 v3,
const char* TextureName,
double x_off, double y_off,
double rot_angle,
double x_scale, double y_scale,
bool QuarkModeTexture,
bool QuarkMirrored);
/**
* Adds a flatshaded plane. the given values are the color components
*/
CMapTexturedPlane* AddPlane(CdVector3 v1, CdVector3 v2, CdVector3 v3,
int r, int g, int b);
/**
* Make all entities create their polygons.
*/
void CreatePolygons();
/**
* Will traverse all the map, and get the Minimum and Maximum vertex
* Coordinates. The map needs to be prepared by CreatePolygons()
* before, otherwise you will get a zero size. Also note, that this
* is a pretty expensive operation, so you should memorize the size
* somewhere and not call this method too often.
*/
void GetMapSize(CdVector3& Min, CdVector3& Max);
/**
* Get the TextureFile for the given original Texture name. If the texture
* is not found, it will return NULL.
*/
CTextureFile* GetTexture(const char* TextureName);
/// Get the number of all contained entities
int GetNumEntities() {return m_Entities.Length();}
/// Get the specified entity
CMapEntity* GetEntity(int index) {return m_Entities.Get(index);}
/// Get the number of the contained planes
int GetPlaneCount() {return m_Planes.Length();}
/// Get the specified plane
CMapTexturedPlane* GetPlane(int index) {return m_Planes.Get(index);}
/// Get the total number of brushes in this map
int GetNumBrushes() {return m_NumBrushes;}
/// Get a pointer to the Config File
csConfigFile* GetConfigFile() {return m_pConfigFile;}
CTextureManager* GetTextureManager() {return &m_TextureManager;}
/**
* Get an integer value from the configuration instance.
* (Store the default if the key is not found)
*/
int GetConfigInt (const char *Path, int def = 0);
/**
* Get a real value from the configuration instance.
* (Store the default if the key is not found)
*/
double GetConfigFloat (const char *Path, double def = 0.0);
/**
* Get a string value from the configuration instance.
* (Store the default if the key is not found)
*/
const char *GetConfigStr (const char *Path, const char *def = "");
protected:
/**
* Look for the texture with the given "name" in all given paths.
* returns true, if the file is found, else return false. If it
* returns true, then the fully qualified name is copied to
* fullname
*/
bool FindTextureFile(const char* name, char* fullname);
/**
* Add a CMapTexturedPlane object to the Map. (If a similar plane already exists,
* the given plane is deleted!)
*/
CMapTexturedPlane* AddPlane(CMapTexturedPlane* pNewPlane);
protected:
/**
* Here all the possible planes are stored. Note, that this will be
* all unique planes.
*/
CMapTexturedPlaneVector m_Planes;
/**
* Here all entities are being stored.
*/
CMapEntityVector m_Entities;
/**
* The texture manager takes care of texture information
*/
CTextureManager m_TextureManager;
/**
* This is the configuration file, that will control the conversion
* process.
*/
csConfigFile* m_pConfigFile;
///remember the name of the Inifile here
char* m_IniFilename;
/// For statistics: How many Brushes are in this map.
int m_NumBrushes;
};
#endif
|