SimpleAreaThingEncoder.cpp

Go to the documentation of this file.
00001 #include "SimpleAreaThingEncoder.hpp"
00002 #include "comp/list/CompositeList.hpp"
00003 #include "io/stream/OutputStream.hpp"
00004 #include "sim/area/AreaManager.hpp"
00005 #include "sim/area/Area.hpp"
00006 #include "sim/pos/PosComponent.hpp"
00007 #include "sim/spawn/SpawnComponent.hpp"
00008 #include "sim/zone/ZoneAreaComponent.hpp"
00009 #include "sim/custom/StatComponent.hpp"
00010 #include "sim/signal/SignalComponent.hpp"
00011 #include "io/parse/Parser.hpp"
00012 #include <cstring>
00013 
00014 using namespace se_core;
00015 
00016 
00017 namespace se_basic {
00018 
00019     SimpleAreaThingEncoder
00020     ::SimpleAreaThingEncoder(EncodeManager& encoder)
00021             : Encoder(encoder, Parser::GAME, Parser::AREA_THINGS, 1)  {
00022     }
00023 
00024 
00025     SimpleAreaThingEncoder
00026     ::~SimpleAreaThingEncoder() {
00027     }
00028 
00029 
00030     void SimpleAreaThingEncoder
00031     ::encode(OutputStream& out) {
00032 
00033         for(int i = 0; i < SimSchema::areaManager.areaCount(); ++i) {
00034             out.writeHeaderCode(headerCode());
00035             const Area* a = SimSchema::areaManager.area(i);
00036             out.writeInfoCode('N');
00037             out.writeString(a->owner()->name());
00038 
00039             const SpawnComponent* pSpawn = SpawnComponent::get(*a);
00040             for(int j = 0; j < pSpawn->spawnPointCount(); ++j) {
00041                 if(pSpawn->hasSpawnPoint(j)) {
00042                     const ViewPoint* sp = pSpawn->spawnPoint(j);
00043                     out.writeInfoCode('E');
00044                     out.writeShort(j);
00045                     out.writeInfoCode('T');
00046                     out.writeFloat(sp->coor_.x_);
00047                     out.writeFloat(sp->coor_.y_);
00048                     out.writeFloat(sp->coor_.z_);
00049                     out.writeInfoCode('R');
00050                     out.writeFloat(BrayT::toDeg(sp->face_.yaw_));
00051                     out.writeFloat(BrayT::toDeg(sp->face_.pitch_));
00052                     out.writeFloat(BrayT::toDeg(sp->face_.roll_));
00053                     out.writeInfoCode('/');
00054                 }
00055             }
00056 
00057             const ZoneAreaComponent::Ptr pZone(*a);
00058             Assert(!pZone.isNull());
00059             for(int j = 0; j < pZone->exitCount(); ++j) {
00060                 const Exit& exit = pZone->exit(j);
00061                 out.writeInfoCode('X');
00062                 out.writeString(exit.area_->get());
00063                 out.writeShort(exit.entrance_);
00064             }
00065 
00066             const PosComponent* aPos = PosComponent::get(*a);
00067 
00068             CompositeList::Iterator it(a->owner()->children());
00069             while(it.hasNext()) {
00070                 Composite& t = it.next();
00071                 if(!StatComponent::Ptr(t)->shouldSave())
00072                     continue;
00073                 out.writeInfoCode('A');
00074                 out.writeString(t.name());
00075                 PosComponent* pPos = PosComponent::get(t);
00076                 if(pPos->pos().isGrounded()) {
00077                     out.writeInfoCode('G');
00078                 }
00079                 ViewPoint vp(pPos->pos().worldViewPoint());
00080                 vp.sub(aPos->pos().worldViewPoint());
00081                 out.writeInfoCode('T');
00082                 out.writeFloat(vp.coor_.x_);
00083                 out.writeFloat(vp.coor_.y_);
00084                 out.writeFloat(vp.coor_.z_);
00085                 out.writeInfoCode('R');
00086                 out.writeFloat(BrayT::toDeg(vp.face_.yaw_));
00087                 out.writeFloat(BrayT::toDeg(vp.face_.pitch_));
00088                 out.writeFloat(BrayT::toDeg(vp.face_.roll_));
00089 
00090                 for(int i = 0; i < 4; ++i) {
00091                     const Anim& a = pPos->pos().anim(i);
00092                     out.writeInfoCode('A');
00093                     out.writeShort(i);
00094                     out.writeShort(a.movementMode());
00095                     out.writeFloat(a.startPos());
00096                     out.writeFloat(a.pos());
00097                     out.writeFloat(a.speed());
00098                     out.writeFloat(a.weight());
00099                 }
00100 
00101                 SignalComponent::Ptr signal(t);
00102                 if(!signal.isNull() && signal->isOn()) {
00103                     bool state = signal->isOn();
00104                     out.writeInfoCode('I');
00105                     // TODO: ??? Test this
00106                     //out.writeShort(state ? 1 : 0);
00107                     out.writeShort(0);
00108                 }
00109 
00110                 out.writeInfoCode('/');
00111             }
00112 
00113             out.writeInfoCode('Q');
00114         }
00115     }
00116 
00117 }

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