SimpleActorParser.cpp

Go to the documentation of this file.
00001 #include "BasicPre.hpp"
00002 #include "SimpleActorParser.hpp"
00003 #include "../thing/SimplePlayerFactory.hpp"
00004 #include "../thing/SimpleCameraFactory.hpp"
00005 #include "../thing/SimpleActorFactory.hpp"
00006 #include "sim/spawn/SpawnManager.hpp"
00007 #include "sim/custom/StatComponentFactory.hpp"
00008 #include "sim/signal/SignalComponentFactory.hpp"
00009 #include "sim/action/Action.hpp"
00010 #include "sim/script/Script.hpp"
00011 #include "sim/stat/Property.hpp"
00012 #include "sim/stat/Dictionary.hpp"
00013 #include "sim/stat/DictionaryEntry.hpp"
00014 
00015 using namespace se_core;
00016 
00017 namespace se_basic {
00018 
00019 
00020     SimpleActorParser
00021     ::SimpleActorParser(ParseManager& parser)
00022             : Parser(parser, Parser::GAME, Parser::THING, 2)  {
00023     }
00024 
00025 
00026     void SimpleActorParser
00027     ::parse(InputStream& in) {
00028         SimpleActorFactory* factory;
00029 
00030         bool shouldAdd = true;
00031         int code = in.readInfoCode();
00032         String* name = new String();
00033         in.readString(*name);
00034 
00035         switch(code) {
00036         case 'A':
00037             factory = new SimpleActorFactory(name);
00038             break;
00039         case 'E':
00040             factory = reinterpret_cast<SimpleActorFactory*>(SpawnManager::singleton().factory(name->get()));
00041             shouldAdd = false;
00042             break;
00043         default:
00044             LogFatal("Unknown thing type '" << (char)(code) << "' in file " << in.name());
00045         }
00046         AssertFatal(factory, "Forgot to create factory");
00047         String collide("none"); // Default collide
00048 
00049         enum { MAX_SPAWN_POINTS = 20 };
00050         int spawnPointCount = 0;
00051         ViewPoint* spawnPoints[ MAX_SPAWN_POINTS ];
00052         for(int i = 0; i < MAX_SPAWN_POINTS; ++i) {
00053             spawnPoints[i] = 0;
00054         }
00055 
00056         while((code = in.readInfoCode()) != 'Q') {
00057             switch(code) {
00058             case 'R': // Radius
00059                 {
00060                     float radius = in.readFloat();
00061                     BoundingBox b;
00062                     b.setMin(-radius, 0, -radius);
00063                     b.setMax(radius, 2 * radius, radius);
00064                     factory->setBounds(b);
00065                 }
00066                 break;
00067 
00068                 /*
00069             case 'S': // Stats
00070                 {
00071                     parseStats(in, factory);
00072                     break;
00073                 }
00074                 break;
00075                 */
00076 
00077             case 'A': // Pos
00078                 {
00079                     parsePos(in, factory);
00080                     break;
00081                 }
00082                 break;
00083 
00084             case 'B': // Bounds
00085                 {
00086                     BoundingBox b;
00087                     b.minX_ = in.readFloat();
00088                     b.minY_ = in.readFloat();
00089                     b.minZ_ = in.readFloat();
00090 
00091                     b.maxX_ = in.readFloat();
00092                     b.maxY_ = in.readFloat();
00093                     b.maxZ_ = in.readFloat();
00094                     factory->setBounds(b);
00095                 }
00096                 break;
00097 
00098             case 'X': // startup script to eXecute
00099                 {
00100                     String scriptName;
00101                     in.readString(scriptName);
00102                     LogWarning("Deprecated X: " << in.name());
00103                     //factory->setScript(scriptName.get());
00104                 }
00105                 break;
00106 
00107             case 'P': // Physics
00108                 {
00109                     String physicsName;
00110                     in.readString(physicsName);
00111                     factory->setPhysics(physicsName.get());
00112                 }
00113                 break;
00114 
00115             case 'T': // Tag
00116                 {
00117                     int t = in.readDictionaryWord(DE_TAG);
00118                     factory->setTag(t);
00119                 }
00120                 break;
00121 
00122             case 'D': // Default action
00123                 {
00124                     String actionName;
00125                     in.readString(actionName);
00126                     factory->setDefaultAction(actionName.get());
00127                 }
00128                 break;
00129 
00130             case 'I': // pIckable
00131                 factory->setPickable(true);
00132                 break;
00133 
00134             case 'C': // Collide
00135                 in.readString(collide);
00136                 break;
00137 
00138             case 'O': // cOllideable
00139                 {
00140                     int sub = in.readDictionaryWord(DE_SUBSTANCE);
00141                     factory->setCollideable(true);
00142                     factory->setSubstance(sub);
00143                 }
00144                 break;
00145 
00146             case 'M': // Mass
00147                 factory->setMass(in.readFloat());
00148                 break;
00149 
00150             case 'F': // Friction
00151                 {
00152                     float linear = in.readFloat();
00153                     float angular = in.readFloat();
00154                     float bounceDecay = in.readFloat();
00155                     factory->setFriction(linear, angular, bounceDecay);
00156                 }
00157                 break;
00158 
00159             case 'E': 
00160                 { // entrance
00161                     short id = in.readShort();
00162                     Assert(id < MAX_SPAWN_POINTS);
00163                     Assert(spawnPoints[id] == 0);
00164 
00165                     ViewPoint* sp = new ViewPoint();
00166                     readSpawnPoint(in, *sp);
00167 
00168                     spawnPoints[id] = sp;
00169                     if(id >= spawnPointCount) {
00170                         spawnPointCount = id + 1;
00171                     }
00172                 }
00173                 break;
00174 
00175             case 'Z':
00176                 {
00177                     int type = in.readDictionaryWord(DE_COMPONENT_TYPE);
00178                     ComponentFactory* f = IoSchema::parser().parseComponent(in, type, 0);
00179                     if(f) {
00180                         factory->addComponent(f);
00181                     }
00182                 }
00183                 break;
00184 
00185             default:
00186                 LogFatal("Unknown code '" << (char)(code) << "' in file " << in.name());
00187             }
00188 
00189         }
00190 
00191         factory->setSpawnPoints(spawnPointCount, spawnPoints);
00192         if(!collide.equals("none")) {
00193             factory->setCollide(collide.get());
00194         }
00195         if(shouldAdd)
00196             SimSchema::spawnManager().addFactory(factory);
00197     }
00198 
00199 
00200     void SimpleActorParser
00201     ::readSpawnPoint(InputStream& in, ViewPoint& sp) {
00202         sp.coor_.reset();
00203         sp.face_.setIdentity();
00204 
00205         int code = 'X';
00206         while((code = in.readInfoCode()) != '/') {
00207             switch(code) {
00208             case 'T': // Transform
00209                 {
00210                     float x = in.readFloat();
00211                     float y = in.readFloat();
00212                     float z = in.readFloat();
00213                     sp.coor_.set(CoorT::fromFloat(x), CoorT::fromFloat(y), CoorT::fromFloat(z));
00214                 }
00215                 break;
00216             case 'R': // Transform
00217                 {
00218                     float yaw = in.readFloat();
00219                     float pitch = in.readFloat();
00220                     float roll = in.readFloat();
00221                     sp.face_.setEuler(
00222                                       BrayT::fromDeg(yaw)
00223                                       , BrayT::fromDeg(pitch)
00224                                       , BrayT::fromDeg(roll)
00225                                       );
00226                 }
00227                 break;
00228             default:
00229                 LogFatal("Unknown code '" << (char)(code) << "' in file " << in.name());
00230             }
00231         }
00232     }
00233 
00234 
00235     /*
00236     void SimpleActorParser
00237     ::parseStats(InputStream& in, SimpleActorFactory* factory) {
00238         int code = in.readInfoCode();
00239         Assert(code == '{');
00240 
00241         while((code = in.readInfoCode()) != '}') {
00242             switch(code) {
00243             // Abilites
00244             case 'A':
00245                 {
00246                     int speed = in.readShort();
00247                     int attack = in.readShort();
00248                     int defense = in.readShort();
00249                     int level = in.readShort();
00250                     factory->setAbilities(speed, attack, defense, level);
00251                 }
00252             }
00253         }
00254     }
00255     */
00256 
00257 
00258 
00259     void SimpleActorParser
00260     ::parsePos(InputStream& in, SimpleActorFactory* factory) {
00261         int code = in.readInfoCode();
00262         Assert(code == '{');
00263 
00264         while((code = in.readInfoCode()) != '}') {
00265             switch(code) {
00266             case 'A':
00267                 {
00268                     int id = in.readShort();
00269                     int animId = in.readDictionaryWord(DE_MOVEMENT_MODE);
00270                     float pos = in.readFloat();
00271                     float speed = in.readFloat();
00272                     factory->setAnim(id, animId, pos, speed);
00273                 }
00274                 break;
00275             }
00276         }
00277     }
00278 
00279 
00280     SimpleComponentParser
00281     ::SimpleComponentParser(const char* name, int type)
00282             : ComponentParser(IoSchema::parser(), type, 0), name_(DE_COMPONENT_TYPE, type, name, true) {
00283     }
00284 
00285 
00286 
00287 
00288     ComponentFactory* SignalComponentParser
00289     ::parse(InputStream& in) {
00290         SignalComponentFactory* factory = new SignalComponentFactory();
00291 
00292         int code = in.readInfoCode();
00293         Assert(code == '{');
00294 
00295         while((code = in.readInfoCode()) != '}') {
00296             switch(code) {
00297             // Abilites
00298             case 'S':
00299                 {
00300                     int id = in.readInt();
00301                     factory->setSendSignal(id);
00302                 }
00303                 break;
00304 
00305             case 'R':
00306                 {
00307                     String signal;
00308                     int mask = in.readInt();
00309                     in.readString(signal);
00310                     factory->setRecieveSignal(mask, signal.get());
00311                 }
00312                 break;
00313             }
00314         }
00315 
00316         return factory;
00317     }
00318 
00319 }

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

SourceForge.net Logo