00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef WORLDFILE_HH
00028 #define WORLDFILE_HH
00029
00030
00031 #include <stdint.h>
00032 #include <stdio.h>
00033 #include <glib.h>
00034
00035
00036 struct CProperty
00037 {
00038
00039 int entity;
00040
00041
00042 const char *name;
00043
00044 char* key;
00045
00046
00047 int value_count;
00048 int *values;
00049
00050
00051 int line;
00052
00053
00054 bool used;
00055 };
00056
00057
00058
00059
00060
00061
00062
00063 class Stg::Worldfile
00064 {
00065
00066 public: Worldfile();
00067 public: ~Worldfile();
00068
00069
00070
00071 protected: FILE* FileOpen(const char *filename, const char* method);
00072
00073
00074 public: bool Load(const char *filename);
00075
00076
00077
00078 public: bool Save(const char *filename);
00079
00080
00081 public: bool WarnUnused();
00082
00083
00084 public: const char *ReadString(int entity, const char *name, const char *value);
00085
00086
00087 public: void WriteString(int entity, const char *name, const char *value);
00088
00089
00090 public: int ReadInt(int entity, const char *name, int value);
00091
00092
00093 public: void WriteInt(int entity, const char *name, int value);
00094
00095
00096 public: double ReadFloat(int entity, const char *name, double value);
00097
00098
00099 public: void WriteFloat(int entity, const char *name, double value);
00100
00101
00102 public: double ReadLength(int entity, const char *name, double value);
00103
00104
00105 public: void WriteLength(int entity, const char *name, double value);
00106
00107
00108 public: double ReadAngle(int entity, const char *name, double value);
00109
00110
00111
00112
00113
00114 public: uint32_t ReadColor(int entity, const char *name, uint32_t value);
00115
00116
00117
00118
00119 public: const char *ReadFilename(int entity, const char *name, const char *value);
00120
00121
00122 public: const char *ReadTupleString(int entity, const char *name,
00123 int index, const char *value);
00124
00125
00126 public: void WriteTupleString(int entity, const char *name,
00127 int index, const char *value);
00128
00129
00130 public: double ReadTupleFloat(int entity, const char *name,
00131 int index, double value);
00132
00133
00134 public: void WriteTupleFloat(int entity, const char *name,
00135 int index, double value);
00136
00137
00138 public: double ReadTupleLength(int entity, const char *name,
00139 int index, double value);
00140
00141
00142 public: void WriteTupleLength(int entity, const char *name,
00143 int index, double value);
00144
00145
00146 public: double ReadTupleAngle(int entity, const char *name,
00147 int index, double value);
00148
00149
00150 public: void WriteTupleAngle(int entity, const char *name,
00151 int index, double value);
00152
00153
00155
00156
00157
00158 private: bool LoadTokens(FILE *file, int include);
00159
00160
00161 private: bool LoadTokenComment(FILE *file, int *line, int include);
00162
00163
00164 private: bool LoadTokenWord(FILE *file, int *line, int include);
00165
00166
00167 private: bool LoadTokenInclude(FILE *file, int *line, int include);
00168
00169
00170 private: bool LoadTokenNum(FILE *file, int *line, int include);
00171
00172
00173 private: bool LoadTokenString(FILE *file, int *line, int include);
00174
00175
00176 private: bool LoadTokenSpace(FILE *file, int *line, int include);
00177
00178
00179 private: bool SaveTokens(FILE *file);
00180
00181
00182 private: void ClearTokens();
00183
00184
00185 private: bool AddToken(int type, const char *value, int include);
00186
00187
00188 private: bool SetTokenValue(int index, const char *value);
00189
00190
00191 private: const char *GetTokenValue(int index);
00192
00193
00194 private: void DumpTokens();
00195
00196
00197 private: bool ParseTokens();
00198
00199
00200 private: bool ParseTokenInclude(int *index, int *line);
00201
00202
00203 private: bool ParseTokenDefine(int *index, int *line);
00204
00205
00206 private: bool ParseTokenWord(int entity, int *index, int *line);
00207
00208
00209 private: bool ParseTokenEntity(int entity, int *index, int *line);
00210
00211
00212 private: bool ParseTokenProperty(int entity, int *index, int *line);
00213
00214
00215 private: bool ParseTokenTuple( CProperty* property, int *index, int *line);
00216
00217
00218 private: void ClearMacros();
00219
00220
00221 private: int AddMacro(const char *macroname, const char *entityname,
00222 int line, int starttoken, int endtoken);
00223
00224
00225
00226 private: int LookupMacro(const char *macroname);
00227
00228
00229 private: void DumpMacros();
00230
00231
00232 private: void ClearEntities();
00233
00234
00235 private: int AddEntity(int parent, const char *type);
00236
00237
00238 public: int GetEntityCount();
00239
00240
00241 public: const char *GetEntityType(int entity);
00242
00243
00244
00245 public: int LookupEntity(const char *type);
00246
00247
00248
00249 public: int GetEntityParent(int entity);
00250
00251
00252 private: void DumpEntities();
00253
00254
00255 private: void ClearProperties();
00256
00257
00258 private: CProperty* AddProperty(int entity, const char *name, int line);
00259
00260 private: void AddPropertyValue( CProperty* property, int index, int value_token);
00261
00262
00263 public: CProperty* GetProperty(int entity, const char *name);
00264
00265
00266
00267 bool PropertyExists( int section, char* token );
00268
00269
00270 private: void SetPropertyValue( CProperty* property, int index, const char *value);
00271
00272
00273 private: const char *GetPropertyValue( CProperty* property, int index);
00274
00275
00276 private: void DumpProperties();
00277
00278
00279 private: enum
00280 {
00281 TokenComment,
00282 TokenWord, TokenNum, TokenString,
00283 TokenOpenEntity, TokenCloseEntity,
00284 TokenOpenTuple, TokenCloseTuple,
00285 TokenSpace, TokenEOL
00286 };
00287
00288
00289 private: struct CToken
00290 {
00291
00292 int include;
00293
00294
00295 int type;
00296
00297
00298 char *value;
00299 };
00300
00301
00302
00303 private: int token_size, token_count;
00304 private: CToken *tokens;
00305
00306
00307 private: struct CMacro
00308 {
00309
00310 const char *macroname;
00311
00312
00313 const char *entityname;
00314
00315
00316 int line;
00317
00318
00319 int starttoken, endtoken;
00320 };
00321
00322
00323 private: int macro_size;
00324 private: int macro_count;
00325 private: CMacro *macros;
00326
00327
00328 private: struct CEntity
00329 {
00330
00331 int parent;
00332
00333
00334 const char *type;
00335 };
00336
00337
00338 private: int entity_size;
00339 private: int entity_count;
00340 private: CEntity *entities;
00341
00342
00343
00344
00345 private: int property_count;
00346
00347
00348 private: GHashTable* nametable;
00349
00350
00351 public: char *filename;
00352
00353
00354 private: double unit_length;
00355 private: double unit_angle;
00356 };
00357
00358 #endif