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 "O3dThingParser.hpp" 00023 #include "../schema/O3dSchema.hpp" 00024 #include "../thing/ThingMOInfo.hpp" 00025 #include "../thing/ThingMOInfoList.hpp" 00026 #include "../thing/O3dAnimation.hpp" 00027 #include "../thing/O3dThingComponentFactory.hpp" 00028 #include "../io/all.hpp" 00029 #include "io/parse/all.hpp" 00030 #include "io/stream/all.hpp" 00031 #include "io/schema/IoSchema.hpp" 00032 #include "util/type/String.hpp" 00033 #include "util/type/TmpString.hpp" 00034 #include "util/error/Log.hpp" 00035 #include "sim/pos/Pos.hpp" 00036 #include "sim/pos/Anim.hpp" 00037 #include "sim/spawn/SpawnManager.hpp" 00038 #include "comp/CompositeFactory.hpp" 00039 #include <cstring> 00040 #include <cstdio> 00041 #include <vector> 00042 #include <OgreEntity.h> 00043 #include <OgreLight.h> 00044 00045 00046 using namespace se_core; 00047 00048 00049 namespace se_ogre { 00050 O3dThingParser 00051 ::O3dThingParser(ParseManager& parser) 00052 : Parser(parser, Parser::OGRE, Parser::THING, 1) { 00053 } 00054 00055 00056 void O3dThingParser 00057 ::parse(InputStream& in) { 00058 ThingMOInfoList* infoList = new ThingMOInfoList; 00059 00060 int code = in.readInfoCode(); 00061 Assert(code == 'N'); 00062 in.readString(infoList->thingType_); 00063 00064 while((code = in.readInfoCode()) != 'Q') { 00065 //LogDetail((char)(code)); 00066 switch(code) { 00067 case '{': 00068 { 00069 ThingMOInfo* info = new ThingMOInfo(); 00070 parseThingInfo(in, info); 00071 infoList->add(info); 00072 //LogDetail("Added info for " << infoList->thingType_); 00073 } 00074 break; 00075 00076 default: 00077 LogFatal("Unsupported code: " << (char)(code) << " in " << in.name()); 00078 } 00079 } 00080 00081 #ifdef SE_INTERNAL 00082 ThingMOInfo* info = new ThingMOInfo(); 00083 info->movableObjectType_.set("Debug"); 00084 infoList->add(info); 00085 #endif 00086 00087 if(infoList->infoCount_ > 0) { 00088 O3dSchema::thingMOManager.addInfoList(infoList); 00089 CompositeFactory* f = SimSchema::spawnManager().factory(infoList->thingType_.get()); 00090 static O3dThingComponentFactory otcf; 00091 f->addComponent(&otcf); 00092 } 00093 else { 00094 delete infoList; 00095 } 00096 } 00097 00098 00099 void O3dThingParser 00100 ::parseThingInfo(InputStream& in, ThingMOInfo* info) { 00101 int code; 00102 while((code = in.readInfoCode()) != '}') { 00103 //LogDetail((char)(code)); 00104 switch(code) { 00105 case 'M': // Mesh 00106 { 00107 String mesh; 00108 in.readString(mesh); 00109 info->movableObjectType_.set(Ogre::EntityFactory::FACTORY_TYPE_NAME.c_str()); 00110 info->params_["mesh"] = mesh.get(); 00111 } 00112 break; 00113 00114 case 'X': // Point light 00115 { 00116 info->movableObjectType_.set(Ogre::LightFactory::FACTORY_TYPE_NAME.c_str()); 00117 float r = in.readFloat(); 00118 float g = in.readFloat(); 00119 float b = in.readFloat(); 00120 info->diffuse_ = Ogre::ColourValue(r, g, b); 00121 r = in.readFloat(); 00122 g = in.readFloat(); 00123 b = in.readFloat(); 00124 info->specular_ = Ogre::ColourValue(r, g, b); 00125 } 00126 break; 00127 00128 case 'N': // Not shadow caster 00129 { 00130 info->isShadowCaster_ = false; 00131 } 00132 break; 00133 00134 case 'T': // Translation offset 00135 { 00136 info->offset_.x = in.readFloat(); 00137 info->offset_.y = in.readFloat(); 00138 info->offset_.z = in.readFloat(); 00139 } 00140 break; 00141 00142 case 'F': // Translation offset 00143 { 00144 se_core::Euler3 eTmp; 00145 eTmp.yaw_ = BrayT::fromDeg(in.readFloat()); 00146 eTmp.pitch_ = BrayT::fromDeg(in.readFloat()); 00147 eTmp.roll_ = BrayT::fromDeg(in.readFloat()); 00148 00149 se_core::Quat4 qTmp(eTmp); 00150 00151 info->rot_.w = QuatT::toFloat(qTmp.w_); 00152 info->rot_.x = QuatT::toFloat(qTmp.x_); 00153 info->rot_.y = QuatT::toFloat(qTmp.y_); 00154 info->rot_.z = QuatT::toFloat(qTmp.z_); 00155 00156 } 00157 break; 00158 00159 case 'B': // Billboard 00160 { 00161 in.readString(info->defaultMaterial_); 00162 info->movableObjectType_.set("Billboard"); 00163 info->params_["material"] = info->defaultMaterial_.get(); 00164 } 00165 break; 00166 00167 case 'G': // static Geometry 00168 { 00169 String mesh; 00170 in.readString(mesh); 00171 info->movableObjectType_.set("StaticGeometry"); 00172 info->params_["mesh"] = mesh.get(); 00173 info->isStatic_ = true; 00174 } 00175 break; 00176 00177 case 'S': // Scale 00178 info->scale_ = in.readFloat(); 00179 break; 00180 00181 case 'R': // Scale is radius 00182 info->doScaleByRadius_ = true; 00183 break; 00184 00185 case 'O': // movable object 00186 in.readString(info->movableObjectType_); 00187 break; 00188 00189 case 'P': // param 00190 { 00191 String n, v; 00192 in.readString(n); 00193 in.readString(v); 00194 info->params_[ n.get() ] = v.get(); 00195 } 00196 break; 00197 00198 case 'C': // Animation channel count 00199 { 00200 int channelCount = in.readShort(); 00201 info->setAnimationChannels(channelCount); 00202 } 00203 break; 00204 00205 case 'A': // Animation 00206 { 00207 int channelId = in.readShort(); 00208 int animId = in.readDictionaryWord(DE_MOVEMENT_MODE); 00209 O3dAnimation* anim = info->createAnimation(channelId, animId); 00210 in.readString(anim->name_); 00211 anim->speed_ = in.readFloat(); 00212 00213 anim->doLoop_ = (in.readInfoCode() == '+'); 00214 } 00215 break; 00216 00217 case 'D': // Default material / texture 00218 { 00219 in.readString(info->defaultMaterial_); 00220 } 00221 break; 00222 00223 case 'L': // Level of detail 00224 { 00225 info->popInSq_ = in.readFloat(); 00226 info->popInSq_ *= info->popInSq_; 00227 info->popOutSq_ = in.readFloat(); 00228 info->popOutSq_ *= info->popOutSq_; 00229 } 00230 break; 00231 00232 default: 00233 LogFatal("Unsupported code: " << (char)(code) << " in file " << in.name()); 00234 } 00235 } 00236 00237 AssertFatal(!info->movableObjectType_.isEmpty(), "You must define exactly one of mesh name or factory in file " << in.name()); 00238 00239 } 00240 00241 } 00242
Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:06 2007 by Doxygen version 1.3.9.1.