Pol  Revision:4b29d2b
mapwriter.h
Go to the documentation of this file.
1 
8 #ifndef PLIB_MAPWRITER_H
9 #define PLIB_MAPWRITER_H
10 
11 #include "mapblock.h"
12 #include "maptile.h"
13 
14 #include <fstream>
15 #include <string>
16 
17 namespace Pol
18 {
19 namespace Plib
20 {
21 struct SOLIDS_ELEM;
22 struct SOLIDX2_ELEM;
23 struct MAPCELL;
24 
25 class MapWriter
26 {
27 public:
28  MapWriter();
29  ~MapWriter();
30 
31  void SetMapCell( unsigned short x, unsigned short y, MAPCELL cell );
32  void SetMapTile( unsigned short x, unsigned short y, MAPTILE_CELL cell );
33 
34  void Flush();
35 
36  void CreateNewFiles( const std::string& realm_name, unsigned short width, unsigned short height );
37  void OpenExistingFiles( const std::string& realm_name );
38  void WriteConfigFile();
39 
40  void CreateBaseDat( const std::string& realm_name, const std::string& directory );
41  void CreateSolidx1Dat( const std::string& realm_name, const std::string& directory );
42  void CreateSolidx2Dat( const std::string& realm_name, const std::string& directory );
43  void CreateSolidsDat( const std::string& realm_name, const std::string& directory );
44  void CreateMaptileDat( const std::string& realm_name, const std::string& directory );
45 
46  unsigned int NextSolidIndex();
47  unsigned int NextSolidOffset();
48 
49  unsigned int NextSolidx2Offset();
50 
51  void AppendSolid( const SOLIDS_ELEM& solid );
52  void AppendSolidx2Elem( const SOLIDX2_ELEM& elem );
53  void SetSolidx2Offset( unsigned short x_base, unsigned short y_base, unsigned int offset );
54 
55  unsigned width() const { return _width; }
56  unsigned height() const { return _height; }
57 
58 private:
59  std::fstream::pos_type total_size();
60 
61  unsigned int total_solid_blocks();
62  unsigned int total_blocks();
63  unsigned int total_maptile_blocks();
64 
65  void FlushBaseFile();
66  void FlushMapTileFile();
67 
68 private:
69  std::string _realm_name;
70  unsigned short _width;
71  unsigned short _height;
72  std::fstream _ofs_base;
75 
76  std::fstream _ofs_solidx1;
77  std::fstream _ofs_solidx2;
78  std::fstream _ofs_solids;
79 
80  std::fstream _ofs_maptile;
84  size_t solids_offset;
85 };
86 }
87 }
88 #endif
void AppendSolid(const SOLIDS_ELEM &solid)
Definition: mapwriter.cpp:299
std::string _realm_name
Definition: mapwriter.h:69
unsigned int NextSolidOffset()
Definition: mapwriter.cpp:284
unsigned short _height
Definition: mapwriter.h:71
unsigned width() const
Definition: mapwriter.h:55
std::fstream _ofs_maptile
Definition: mapwriter.h:80
unsigned int total_maptile_blocks()
Definition: mapwriter.cpp:212
unsigned int total_solid_blocks()
Definition: mapwriter.cpp:208
unsigned int total_blocks()
Definition: mapwriter.cpp:204
void CreateBaseDat(const std::string &realm_name, const std::string &directory)
Definition: mapwriter.cpp:69
void CreateSolidx1Dat(const std::string &realm_name, const std::string &directory)
Definition: mapwriter.cpp:82
void CreateSolidx2Dat(const std::string &realm_name, const std::string &directory)
Definition: mapwriter.cpp:95
void SetMapTile(unsigned short x, unsigned short y, MAPTILE_CELL cell)
Definition: mapwriter.cpp:241
std::fstream _ofs_solids
Definition: mapwriter.h:78
std::fstream _ofs_solidx2
Definition: mapwriter.h:77
unsigned int NextSolidIndex()
Definition: mapwriter.cpp:289
unsigned height() const
Definition: mapwriter.h:56
std::fstream::pos_type total_size()
Definition: mapwriter.cpp:200
void AppendSolidx2Elem(const SOLIDX2_ELEM &elem)
Definition: mapwriter.cpp:305
std::fstream _ofs_base
Definition: mapwriter.h:72
void CreateMaptileDat(const std::string &realm_name, const std::string &directory)
Definition: mapwriter.cpp:112
void CreateSolidsDat(const std::string &realm_name, const std::string &directory)
Definition: mapwriter.cpp:103
void SetMapCell(unsigned short x, unsigned short y, MAPCELL cell)
Definition: mapwriter.cpp:217
MAPTILE_BLOCK _maptile_block
Definition: mapwriter.h:82
void SetSolidx2Offset(unsigned short x_base, unsigned short y_base, unsigned int offset)
Definition: mapwriter.cpp:311
void CreateNewFiles(const std::string &realm_name, unsigned short width, unsigned short height)
Definition: mapwriter.cpp:126
std::fstream _ofs_solidx1
Definition: mapwriter.h:76
unsigned int NextSolidx2Offset()
Definition: mapwriter.cpp:294
Definition: berror.cpp:12
void OpenExistingFiles(const std::string &realm_name)
Definition: mapwriter.cpp:147
unsigned short _width
Definition: mapwriter.h:70