00001 #include <se_core.hpp> 00002 #include "WangAreaGridParser.hpp" 00003 #include "../area/WangAreaGrid.hpp" 00004 #include <cstring> 00005 #include <cstdio> 00006 00007 using namespace se_core; 00008 00009 namespace se_basic { 00010 00011 WangAreaGridParser 00012 ::WangAreaGridParser(ParseManager& parser) 00013 : Parser(parser, Parser::GAME, Parser::AREA_GRID, 2) { 00014 } 00015 00016 00017 void WangAreaGridParser 00018 ::parse(InputStream& in) { 00019 // (width height) 00020 unsigned short xSize = in.readShort(); 00021 unsigned short zSize = in.readShort(); 00022 00023 // Strip extension from basename, so that 00024 // .bin and .txt versions of the same grid produce 00025 // the same hash id 00026 String name(in.basename(), -in.extLen()); 00027 00028 // Create area 00029 WangAreaGrid grid(xSize, zSize, name.get()); 00030 int seed = 19; 00031 00032 int code; 00033 while((code = in.readInfoCode()) != 'Q' && !in.eof()) { 00034 switch(code) { 00035 case 'S': 00036 seed = in.readShort(); 00037 break; 00038 00039 case 'T': // Tile definition 00040 { 00041 String name; 00042 String wang; 00043 in.readString(name); 00044 in.readString(wang); 00045 grid.addDefinition(name, (const unsigned char*)wang.get()); 00046 } 00047 break; 00048 00049 case 'C': 00050 { 00051 short z = in.readShort(); 00052 AssertFatal(z < zSize, in.name()); 00053 int c = in.readInfoCode(); 00054 AssertFatal(c == '{', "Missing { in '" << in.name() << "' - C: " << z); 00055 int x = 0; 00056 while(x < xSize) { 00057 short def = in.readShort(); 00058 grid.setArea(x, z, def); 00059 ++x; 00060 } 00061 c = in.readInfoCode(); 00062 AssertFatal(c == '}', "Missing } in '" << in.name() << "' - C: " << z); 00063 } 00064 break; 00065 00066 case 'B': 00067 { 00068 int c = in.readShort(); 00069 grid.setDefaultBorder(c); 00070 } 00071 break; 00072 00073 case 'G': 00074 grid.generate(seed); 00075 break; 00076 00077 case 'O': 00078 { 00079 String tmp; 00080 in.readString(tmp); 00081 grid.save(tmp.get()); 00082 break; 00083 } 00084 } 00085 00086 } 00087 00088 } 00089 00090 }
Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:02 2007 by Doxygen version 1.3.9.1.