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 "SpawnComponentParser.hpp" 00023 #include "sim/schema/SimSchema.hpp" 00024 #include "io/parse/ParseManager.hpp" 00025 #include "io/schema/IoSchema.hpp" 00026 #include "sim/spawn/SpawnComponentFactory.hpp" 00027 #include "sim/script/Script.hpp" 00028 #include "util/error/Log.hpp" 00029 #include "util/vecmath/ViewPoint.hpp" 00030 00031 00032 00033 namespace se_core { 00034 const SpawnComponentParser parserSpawnComponent; 00035 00036 SpawnComponentParser 00037 ::SpawnComponentParser() 00038 : ComponentParser(IoSchema::parser(), TYPE, SUBTYPE) 00039 , dict_(DE_COMPONENT_TYPE, TYPE, "SPAWN") { 00040 } 00041 00042 00043 SpawnComponentParser 00044 ::~SpawnComponentParser() { 00045 } 00046 00047 00048 ComponentFactory* SpawnComponentParser 00049 ::parse(InputStream& in) { 00050 SpawnComponentFactory* factory = new SpawnComponentFactory(); 00051 00052 enum { MAX_SPAWN_POINTS = 20 }; 00053 int spawnPointCount = 0; 00054 ViewPoint* spawnPoints[ MAX_SPAWN_POINTS ]; 00055 for(int i = 0; i < MAX_SPAWN_POINTS; ++i) { 00056 spawnPoints[i] = 0; 00057 } 00058 00059 int code = in.readInfoCode(); 00060 Assert(code == '{'); 00061 00062 while((code = in.readInfoCode()) != '}') { 00063 switch(code) { 00064 case 'E': 00065 { // Spawn Point 00066 short id = in.readShort(); 00067 Assert(id < MAX_SPAWN_POINTS); 00068 Assert(spawnPoints[id] == 0); 00069 00070 ViewPoint* sp = new ViewPoint(); 00071 readSpawnPoint(in, *sp); 00072 00073 spawnPoints[id] = sp; 00074 if(id >= spawnPointCount) { 00075 spawnPointCount = id + 1; 00076 } 00077 } 00078 break; 00079 00080 default: 00081 LogFatal("Unsupported code '" << (char)(code) << "' in file " << in.name()); 00082 } 00083 } 00084 00085 factory->setSpawnPoints(spawnPointCount, spawnPoints); 00086 00087 return factory; 00088 } 00089 00090 00091 void SpawnComponentParser 00092 ::readSpawnPoint(InputStream& in, ViewPoint& sp) { 00093 sp.coor_.reset(); 00094 sp.face_.setIdentity(); 00095 00096 int code = 'X'; 00097 while((code = in.readInfoCode()) != '/') { 00098 switch(code) { 00099 case 'T': // Transform 00100 { 00101 float x = in.readFloat(); 00102 float y = in.readFloat(); 00103 float z = in.readFloat(); 00104 sp.coor_.set(CoorT::fromFloat(x), CoorT::fromFloat(y), CoorT::fromFloat(z)); 00105 } 00106 break; 00107 case 'R': // Transform 00108 { 00109 float yaw = in.readFloat(); 00110 float pitch = in.readFloat(); 00111 float roll = in.readFloat(); 00112 sp.face_.setEuler( 00113 BrayT::fromDeg(yaw) 00114 , BrayT::fromDeg(pitch) 00115 , BrayT::fromDeg(roll) 00116 ); 00117 } 00118 break; 00119 default: 00120 LogFatal("Unknown code '" << (char)(code) << "' in file " << in.name()); 00121 } 00122 } 00123 } 00124 00125 }
Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:10 2007 by Doxygen version 1.3.9.1.