CompositeParser.cpp

Go to the documentation of this file.
00001 /*
00002 SagaEngine library
00003 Copyright (c) 2002-2006 Skalden Studio AS
00004 
00005 This software is provided 'as-is', without any express or implied 
00006 warranty. In no event will the authors be held liable for any 
00007 damages arising from the use of this software.
00008 
00009 Permission is granted to distribute the library under the terms of the 
00010 Q Public License version 1.0. Be sure to read and understand the license
00011 before using the library. It should be included here, or you may read it
00012 at http://www.trolltech.com/products/qt/licenses/licensing/qpl
00013 
00014 The original version of this library can be located at:
00015 http://www.sagaengine.com/
00016 
00017 Rune Myrland
00018 rune@skalden.com
00019 */
00020 
00021 
00022 #include "CompositeParser.hpp"
00023 #include "io/stream/InputStream.hpp"
00024 #include "sim/sim.hpp"
00025 #include "sim/schema/SimSchema.hpp"
00026 #include "sim/spawn/SpawnManager.hpp"
00027 #include "comp/comp.hpp"
00028 #include "comp/Composite.hpp"
00029 #include "comp/CompositeFactory.hpp"
00030 #include "comp/schema/CompSchema.hpp"
00031 #include "io/schema/IoSchema.hpp"
00032 #include "util/type/String.hpp"
00033 #include "util/error/Log.hpp"
00034 #include <cstring>
00035 #include <cstdio>
00036 
00037 
00038 namespace se_core {
00039 
00040 
00041     CompositeParser
00042     ::CompositeParser(ParseManager& parser)
00043         : Parser(parser, Parser::ENGINE, Parser::THING, 1)  {
00044     }
00045 
00046 
00047     void CompositeParser
00048     ::parse(InputStream& in) {
00049         String* name = new String();
00050         CompositeFactory* factory;
00051 
00052         bool shouldAdd = true;
00053         int code = in.readInfoCode();
00054         in.readString(*name);
00055 
00056         switch(code) {
00057         case 'L': // Level
00058             factory = new CompositeFactory(st_LEVEL, name);
00059             break;
00060         case 'A': // Area
00061             factory = new CompositeFactory(st_AREA, name);
00062             break;
00063         case 'T': // Thing/Actor
00064             factory = new CompositeFactory(st_ACTOR, name);
00065             break;
00066         case 'E': // Existing entity
00067             factory = SpawnManager::singleton().factory(name->get());
00068             shouldAdd = false;
00069             break;
00070         default:
00071             LogFatal("Unknown thing type '" << (char)(code) << "' in file " << in.name());
00072         }
00073         AssertFatal(factory, "Forgot to create factory in file " << in.name());
00074 
00075         while(!in.eof() && (code = in.readInfoCode()) != 'Q') {
00076             switch(code) {
00077             case 'Z':
00078                 {
00079                     int type = in.readDictionaryWord(DE_COMPONENT_TYPE);
00080                     ComponentFactory* f = IoSchema::parser().parseComponent(in, type, 0);
00081                     if(f) {
00082                         factory->addComponent(f);
00083                     }
00084                 }
00085                 break;
00086 
00087             default:
00088                 LogFatal("Unknown code '" << (char)(code) << "' in file " << in.name());
00089             }
00090         }
00091 
00092         if(shouldAdd) {
00093             SimSchema::spawnManager().addFactory(factory);
00094         }
00095     }
00096 
00097 }

Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:10 2007 by Doxygen version 1.3.9.1.

SourceForge.net Logo