00001 #include <game.h>
00002
00003 lieu::lieu() : base("lieu")
00004 {
00005 listStatic = new std::vector<staticMesh*>;
00006 listAction = new std::vector<actionMesh*>;
00007 }
00008
00009 lieu::~lieu()
00010 {
00011 delete listAction;
00012 delete listStatic;
00013 }
00014
00015 int lieu::init(int i,coeur* c,IXMLReader* xmlLieu)
00016 {
00017 base::init(i,c);
00018 log(stringc("Lieu xml : ") + stringc(i) + " loading ...");
00019 staticMesh* mesh = 0;
00020 ILightSceneNode* light = 0;
00021 while(xmlLieu && xmlLieu->read())
00022 {
00023 if (xmlLieu->getNodeType()==EXN_ELEMENT)
00024 {
00025 if (core::stringw("lieu") == xmlLieu->getNodeName())
00026 {
00027 listStatic->reserve(xmlLieu->getAttributeValueAsInt(L"nbrstatic"));
00028 listAction->reserve(xmlLieu->getAttributeValueAsInt(L"nbraction"));
00029 }
00030 else if (core::stringw("light") == xmlLieu->getNodeName())
00031 {
00032 light = mycore->addLight(xmlLieu->getAttributeValueAsInt(L"radius"));
00033 log( stringc("New light : radius: ") + xmlLieu->getAttributeValue(L"radius") );
00034 }
00035 else if (core::stringw("static") == xmlLieu->getNodeName())
00036 {
00037 mesh=addStaticMesh(
00038 stringc(xmlLieu->getAttributeValue(L"model")),
00039 xmlLieu->getAttributeValueAsInt(L"id")
00040 );
00041 log( stringc("New static : id:") + xmlLieu->getAttributeValue(L"id") + ", model: " + xmlLieu->getAttributeValue(L"model"));
00042 }
00043 else if (core::stringw("observation") == xmlLieu->getNodeName())
00044 {
00045 mesh=addObservationMesh(
00046 stringc(xmlLieu->getAttributeValue(L"model")),
00047 xmlLieu->getAttributeValueAsInt(L"id"),
00048 xmlLieu->getAttributeValueAsInt(L"combiId")
00049 );
00050 log( stringc("New observation : id:") + xmlLieu->getAttributeValue(L"id") + ", model: " + xmlLieu->getAttributeValue(L"model") + ", combiId: " + xmlLieu->getAttributeValue(L"combiId"));
00051 }
00052 else if (core::stringw("prendre") == xmlLieu->getNodeName())
00053 {
00054 mesh=addPrendreMesh(
00055 stringc(xmlLieu->getAttributeValue(L"model")),
00056 xmlLieu->getAttributeValueAsInt(L"id"),
00057 xmlLieu->getAttributeValueAsInt(L"combiId"),
00058 xmlLieu->getAttributeValueAsInt(L"itemId")
00059 );
00060 log( stringc("New prendre : id:") + xmlLieu->getAttributeValue(L"id") + ", model: " + xmlLieu->getAttributeValue(L"model") + ", combiId: " + xmlLieu->getAttributeValue(L"combiId") + ", itemId: " + xmlLieu->getAttributeValue(L"itemId"));
00061 }
00062 else if (core::stringw("animate") == xmlLieu->getNodeName())
00063 {
00064 mesh=addAnimateMesh(
00065 stringc(xmlLieu->getAttributeValue(L"model")),
00066 xmlLieu->getAttributeValueAsInt(L"id"),
00067 xmlLieu->getAttributeValueAsInt(L"combiId"),
00068 xmlLieu->getAttributeValueAsInt(L"animId"),
00069 xmlLieu->getAttributeValueAsInt(L"begin"),
00070 xmlLieu->getAttributeValueAsInt(L"end")
00071 );
00072 log( stringc("New animated : id:") + xmlLieu->getAttributeValue(L"id") + ", model: " + xmlLieu->getAttributeValue(L"model") + ", combiId: " + xmlLieu->getAttributeValue(L"combiId") + ", animId: " + xmlLieu->getAttributeValue(L"animId") + ", begin: " + xmlLieu->getAttributeValue(L"begin") + ", end: " + xmlLieu->getAttributeValue(L"end"));
00073 }
00074 else if (core::stringw("position") == xmlLieu->getNodeName())
00075 {
00076 ISceneNode* node = 0;
00077 if (mesh)
00078 node = mesh->getNode();
00079 else if (light)
00080 node = light;
00081 else
00082 {
00083 log(stringc(" Bad format : Position comand bad placed"));
00084 continue;
00085 }
00086
00087 node->setPosition(vector3df(
00088 xmlLieu->getAttributeValueAsFloat(L"x"),
00089 xmlLieu->getAttributeValueAsFloat(L"y"),
00090 xmlLieu->getAttributeValueAsFloat(L"z")
00091 ));
00092
00093 log( stringc(" Position : (") + xmlLieu->getAttributeValue(L"x") + "," + xmlLieu->getAttributeValue(L"y") + "," + xmlLieu->getAttributeValue(L"z") + ")");
00094 }
00095 else if (core::stringw("rotation") == xmlLieu->getNodeName())
00096 {
00097 mesh->getNode()->setRotation(vector3df(
00098 xmlLieu->getAttributeValueAsFloat(L"x"),
00099 xmlLieu->getAttributeValueAsFloat(L"y"),
00100 xmlLieu->getAttributeValueAsFloat(L"z")
00101 ));
00102 log( stringc(" Rotation : (") + xmlLieu->getAttributeValue(L"x") + "," + xmlLieu->getAttributeValue(L"y") + "," + xmlLieu->getAttributeValue(L"z") + ")");
00103 }
00104 else if (core::stringw("scale") == xmlLieu->getNodeName())
00105 {
00106 mesh->getNode()->setScale(vector3df(
00107 xmlLieu->getAttributeValueAsFloat(L"x"),
00108 xmlLieu->getAttributeValueAsFloat(L"y"),
00109 xmlLieu->getAttributeValueAsFloat(L"z")
00110 ));
00111 log( stringc(" Scale : (") + xmlLieu->getAttributeValue(L"x") + "," + xmlLieu->getAttributeValue(L"y") + "," + xmlLieu->getAttributeValue(L"z") + ")");
00112 }
00113 else if (core::stringw("color") == xmlLieu->getNodeName())
00114 {
00115 light->getLightData().DiffuseColor = SColorf(
00116 xmlLieu->getAttributeValueAsFloat(L"red"),
00117 xmlLieu->getAttributeValueAsFloat(L"green"),
00118 xmlLieu->getAttributeValueAsFloat(L"blue"),
00119 xmlLieu->getAttributeValueAsFloat(L"alpha")
00120 );
00121 log( stringc(" Color : (") + xmlLieu->getAttributeValue(L"red") + "," + xmlLieu->getAttributeValue(L"green") + "," + xmlLieu->getAttributeValue(L"blue") + "," + xmlLieu->getAttributeValue(L"alpha") + ")");
00122 }
00123 else if (core::stringw("skybox") == xmlLieu->getNodeName())
00124 {
00125 mycore->setSkyBox(
00126 xmlLieu->getAttributeValue(L"top"),
00127 xmlLieu->getAttributeValue(L"bottom"),
00128 xmlLieu->getAttributeValue(L"left"),
00129 xmlLieu->getAttributeValue(L"right"),
00130 xmlLieu->getAttributeValue(L"front"),
00131 xmlLieu->getAttributeValue(L"back")
00132 );
00133 log( stringc(" Skybox"));
00134 }
00135 else if (core::stringw("texture") == xmlLieu->getNodeName())
00136 {
00137 mesh->getNode()->setMaterialTexture(xmlLieu->getAttributeValueAsInt(L"id"),mycore->getTexture(xmlLieu->getAttributeValue(L"path")));
00138 log( stringc(" Texture"));
00139 }
00140 }
00141 if (xmlLieu->getNodeType()==EXN_ELEMENT_END)
00142 {
00143 if ((core::stringw("static") == xmlLieu->getNodeName())||(core::stringw("observation") == xmlLieu->getNodeName())||(core::stringw("prendre") == xmlLieu->getNodeName()))
00144 mesh=0;
00145 else if (core::stringw("light") == xmlLieu->getNodeName())
00146 light=0;
00147 }
00148 }
00149
00150
00151 return 1;
00152 }
00153
00154 int lieu::update()
00155 {
00156 return 1;
00157 }
00158
00159 int lieu::close()
00160 {
00161 log("Closing each staticMesh");
00162 while (! listStatic->empty())
00163 {
00164 log(stringc("Deleting staticMesh ") + stringc(listStatic->back()->getId()));
00165 delete listStatic->back();
00166 listStatic->pop_back();
00167 }
00168 log("Closing each actionMesh");
00169 while (!listAction->empty())
00170 {
00171 log(stringc("Deleting actionMesh ") + stringc(listAction->back()->getId()));
00172 delete listAction->back();
00173 listAction->pop_back();
00174 }
00175 base::close();
00176 return 1;
00177 }
00178
00179 staticMesh* lieu::addStaticMesh(stringc path,int i)
00180 {
00181 staticMesh *m = new staticMesh;
00182 m->init(i,mycore->addMesh(path));
00183 m->getNode()->setID(i);
00184 listStatic->push_back(m);
00185 log("staticMesh added");
00186 return m;
00187 }
00188
00189 observationMesh* lieu::addObservationMesh(stringc path, int i, int c)
00190 {
00191 observationMesh *m = new observationMesh;
00192 m->init(i,mycore->addMesh(path),c);
00193 m->getNode()->setID(i);
00194 listAction->push_back(m);
00195 log("observationMesh added");
00196 return m;
00197 }
00198
00199 prendreMesh* lieu::addPrendreMesh(stringc path, int i, int c, int ite)
00200 {
00201 prendreMesh *m = new prendreMesh;
00202 m->init(i,mycore->addMesh(path),c, ite);
00203 m->getNode()->setID(i);
00204 listAction->push_back(m);
00205 log("prendreMesh added");
00206 return m;
00207 }
00208
00209 animateMesh* lieu::addAnimateMesh(stringc path, int i, int c, int ite, int b, int e)
00210 {
00211 animateMesh *m = new animateMesh;
00212 m->init(i,mycore->addMesh(path),c, ite, b ,e);
00213 m->getNode()->setID(i);
00214 listAction->push_back(m);
00215 log("animateMesh added");
00216 return m;
00217 }
00218
00219 staticMesh* lieu::getStaticMeshFromId(int id)
00220 {
00221 for (unsigned int i=0;i<listStatic->size();i++)
00222 if (listStatic->at(i)->getId() == id)
00223 {
00224 return listStatic->at(i);
00225 }
00226 return 0;
00227 }
00228
00229 actionMesh* lieu::getActionMesh(int id)
00230 {
00231 for (unsigned int i=0;i<listAction->size();i++)
00232 if (listAction->at(i)->getId() == id)
00233 {
00234 return listAction->at(i);
00235 }
00236 return 0;
00237 }
00238
00239 actionMesh* lieu::getActionMesh(ISceneNode* node)
00240 {
00241 for (unsigned int i=0;i<listAction->size();i++)
00242 if (listAction->at(i)->getNode() == node)
00243 {
00244 return listAction->at(i);
00245 }
00246 return 0;
00247 }
00248
00249 bool lieu::OnEvent(const SEvent& event)
00250 {
00251 return false;
00252 }
00253