2010-03-27 04:09:11 +01:00
|
|
|
|
// ==============================================================
|
|
|
|
|
// This file is part of Glest (www.glest.org)
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
|
|
|
|
//
|
|
|
|
|
// You can redistribute this code and/or modify it under
|
|
|
|
|
// the terms of the GNU General Public License as published
|
|
|
|
|
// by the Free Software Foundation; either version 2 of the
|
|
|
|
|
// License, or (at your option) any later version
|
|
|
|
|
// ==============================================================
|
|
|
|
|
|
|
|
|
|
#include "unit_particle_type.h"
|
|
|
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
|
#include "core_data.h"
|
|
|
|
|
#include "xml_parser.h"
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#include "game_constants.h"
|
|
|
|
|
|
|
|
|
|
#include "leak_dumper.h"
|
|
|
|
|
|
|
|
|
|
using namespace Shared::Xml;
|
|
|
|
|
using namespace Shared::Graphics;
|
2010-10-06 22:22:06 +02:00
|
|
|
|
using namespace Shared::Util;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
|
|
|
|
|
namespace Glest{ namespace Game{
|
|
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
|
// class UnitParticleSystemType
|
|
|
|
|
// =====================================================
|
|
|
|
|
|
2011-03-15 16:30:28 +01:00
|
|
|
|
void UnitParticleSystemType::load(const XmlNode *particleSystemNode, const string &dir,
|
|
|
|
|
RendererInterface *renderer, std::map<string,int> &loadedFileList) {
|
|
|
|
|
ParticleSystemType::load(particleSystemNode, dir, renderer, loadedFileList);
|
2010-03-27 04:09:11 +01:00
|
|
|
|
//radius
|
|
|
|
|
const XmlNode *radiusNode= particleSystemNode->getChild("radius");
|
|
|
|
|
radius= radiusNode->getAttribute("value")->getFloatValue();
|
|
|
|
|
|
|
|
|
|
//relative
|
|
|
|
|
const XmlNode *relativeNode= particleSystemNode->getChild("relative");
|
|
|
|
|
relative= relativeNode->getAttribute("value")->getBoolValue();
|
|
|
|
|
|
2011-03-02 00:36:33 +01:00
|
|
|
|
//direction
|
|
|
|
|
const XmlNode *directionNode= particleSystemNode->getChild("direction");
|
|
|
|
|
direction.x= directionNode->getAttribute("x")->getFloatValue();
|
|
|
|
|
direction.y= directionNode->getAttribute("y")->getFloatValue();
|
|
|
|
|
direction.z= directionNode->getAttribute("z")->getFloatValue();
|
|
|
|
|
|
2010-03-27 04:09:11 +01:00
|
|
|
|
//relativeDirection
|
|
|
|
|
if(particleSystemNode->hasChild("relativeDirection")){
|
|
|
|
|
const XmlNode *relativeDirectionNode= particleSystemNode->getChild("relativeDirection");
|
|
|
|
|
relativeDirection= relativeDirectionNode->getAttribute("value")->getBoolValue();
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
relativeDirection=true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-25 16:38:00 +02:00
|
|
|
|
if(particleSystemNode->hasChild("static-particle-count")){
|
|
|
|
|
//staticParticleCount
|
|
|
|
|
const XmlNode *staticParticleCountNode= particleSystemNode->getChild("static-particle-count");
|
|
|
|
|
staticParticleCount= staticParticleCountNode->getAttribute("value")->getIntValue();
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
staticParticleCount=0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-14 00:16:07 +01:00
|
|
|
|
//isVisibleAtNight
|
|
|
|
|
if(particleSystemNode->hasChild("isVisibleAtNight")){
|
|
|
|
|
const XmlNode *isVisibleAtNightNode= particleSystemNode->getChild("isVisibleAtNight");
|
|
|
|
|
isVisibleAtNight= isVisibleAtNightNode->getAttribute("value")->getBoolValue();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
isVisibleAtNight=true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//isVisibleAtDay
|
|
|
|
|
if(particleSystemNode->hasChild("isVisibleAtDay")){
|
|
|
|
|
const XmlNode *isVisibleAtDayNode= particleSystemNode->getChild("isVisibleAtDay");
|
|
|
|
|
isVisibleAtDay= isVisibleAtDayNode->getAttribute("value")->getBoolValue();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
isVisibleAtDay=true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//radiusBasedStartenergy
|
|
|
|
|
if(particleSystemNode->hasChild("radiusBasedStartenergy")){
|
|
|
|
|
const XmlNode *isVisibleAtDayNode= particleSystemNode->getChild("radiusBasedStartenergy");
|
|
|
|
|
radiusBasedStartenergy= isVisibleAtDayNode->getAttribute("value")->getBoolValue();
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
radiusBasedStartenergy= true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-27 04:09:11 +01:00
|
|
|
|
//fixed
|
|
|
|
|
const XmlNode *fixedNode= particleSystemNode->getChild("fixed");
|
|
|
|
|
fixed= fixedNode->getAttribute("value")->getBoolValue();
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-09 02:32:27 +01:00
|
|
|
|
const void UnitParticleSystemType::setValues(UnitParticleSystem *ups){
|
2010-03-27 04:09:11 +01:00
|
|
|
|
ups->setTexture(texture);
|
|
|
|
|
ups->setPrimitive(UnitParticleSystem::strToPrimitive(primitive));
|
|
|
|
|
ups->setOffset(offset);
|
|
|
|
|
ups->setDirection(direction);
|
|
|
|
|
ups->setColor(color);
|
|
|
|
|
ups->setColorNoEnergy(colorNoEnergy);
|
|
|
|
|
ups->setSpeed(speed);
|
|
|
|
|
ups->setGravity(gravity);
|
|
|
|
|
ups->setParticleSize(size);
|
|
|
|
|
ups->setSizeNoEnergy(sizeNoEnergy);
|
|
|
|
|
ups->setEmissionRate(emissionRate);
|
|
|
|
|
ups->setMaxParticleEnergy(energyMax);
|
|
|
|
|
ups->setVarParticleEnergy(energyVar);
|
|
|
|
|
ups->setFixed(fixed);
|
|
|
|
|
ups->setRelative(relative);
|
|
|
|
|
ups->setRelativeDirection(relativeDirection);
|
|
|
|
|
ups->setTeamcolorNoEnergy(teamcolorNoEnergy);
|
|
|
|
|
ups->setTeamcolorEnergy(teamcolorEnergy);
|
2011-03-14 00:16:07 +01:00
|
|
|
|
ups->setAlternations(alternations);
|
|
|
|
|
|
|
|
|
|
ups->setIsVisibleAtNight(isVisibleAtNight);
|
|
|
|
|
ups->setIsVisibleAtDay(isVisibleAtDay);
|
2010-09-25 16:38:00 +02:00
|
|
|
|
ups->setStaticParticleCount(staticParticleCount);
|
2010-03-27 04:09:11 +01:00
|
|
|
|
ups->setRadius(radius);
|
|
|
|
|
ups->setBlendMode(ParticleSystem::strToBlendMode(mode));
|
2011-03-14 00:16:07 +01:00
|
|
|
|
ups->setRadiusBasedStartenergy(radiusBasedStartenergy);
|
2010-09-25 16:38:00 +02:00
|
|
|
|
//prepare system for given staticParticleCount
|
|
|
|
|
if(staticParticleCount>0)
|
|
|
|
|
{
|
|
|
|
|
ups->setEmissionRate(0.0f);
|
|
|
|
|
ups->setSpeed(0);
|
|
|
|
|
direction.x= 0.0f;
|
|
|
|
|
direction.y= 0.0f;
|
|
|
|
|
direction.z= 0.0f;
|
|
|
|
|
ups->setDirection(direction);
|
|
|
|
|
}
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-15 16:30:28 +01:00
|
|
|
|
void UnitParticleSystemType::load(const string &dir, const string &path,
|
|
|
|
|
RendererInterface *renderer, std::map<string,int> &loadedFileList) {
|
2010-03-27 04:09:11 +01:00
|
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
XmlTree xmlTree;
|
|
|
|
|
xmlTree.load(path);
|
2011-03-15 16:30:28 +01:00
|
|
|
|
loadedFileList[path]++;
|
2010-03-27 04:09:11 +01:00
|
|
|
|
const XmlNode *particleSystemNode= xmlTree.getRootNode();
|
|
|
|
|
|
2011-03-15 16:30:28 +01:00
|
|
|
|
UnitParticleSystemType::load(particleSystemNode, dir, renderer,
|
|
|
|
|
loadedFileList);
|
2010-03-27 04:09:11 +01:00
|
|
|
|
}
|
|
|
|
|
catch(const exception &e){
|
2010-10-06 22:22:06 +02:00
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
|
2010-03-27 04:09:11 +01:00
|
|
|
|
throw runtime_error("Error loading ParticleSystem: "+ path + "\n" +e.what());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}}//end mamespace
|