mirror of
https://github.com/glest/glest-source.git
synced 2025-09-01 20:12:40 +02:00
- bugfix for game save and load (string buffer was too small for one item)
This commit is contained in:
@@ -68,6 +68,7 @@ public:
|
||||
int getEnergy() const {return energy;}
|
||||
|
||||
void saveGame(XmlNode *rootNode);
|
||||
void loadGame(const XmlNode *rootNode);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
@@ -79,6 +80,7 @@ public:
|
||||
virtual ~ParticleObserver(){};
|
||||
virtual void update(ParticleSystem *particleSystem)= 0;
|
||||
virtual void saveGame(XmlNode *rootNode) = 0;
|
||||
virtual void loadGame(const XmlNode *rootNode, void *genericData) = 0;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
@@ -191,7 +193,8 @@ public:
|
||||
virtual int getChildCount() { return 0; }
|
||||
virtual ParticleSystem* getChild(int i);
|
||||
|
||||
void saveGame(XmlNode *rootNode);
|
||||
virtual void saveGame(XmlNode *rootNode);
|
||||
virtual void loadGame(const XmlNode *rootNode);
|
||||
|
||||
protected:
|
||||
//protected
|
||||
@@ -225,6 +228,9 @@ public:
|
||||
//set params
|
||||
void setRadius(float radius);
|
||||
void setWind(float windAngle, float windSpeed);
|
||||
|
||||
virtual void saveGame(XmlNode *rootNode);
|
||||
virtual void loadGame(const XmlNode *rootNode);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
@@ -256,6 +262,10 @@ public:
|
||||
void setPrimitive(Primitive primitive) {this->primitive= primitive;}
|
||||
Vec3f getDirection() const {return direction;}
|
||||
void setModelCycle(float modelCycle) {this->modelCycle= modelCycle;}
|
||||
|
||||
virtual void saveGame(XmlNode *rootNode);
|
||||
virtual void loadGame(const XmlNode *rootNode);
|
||||
|
||||
protected:
|
||||
typedef std::vector<UnitParticleSystem*> Children;
|
||||
Children children;
|
||||
@@ -362,6 +372,10 @@ public:
|
||||
void setParentDirection(Vec3f parentDirection);
|
||||
|
||||
static Shape strToShape(const string& str);
|
||||
|
||||
virtual void saveGame(XmlNode *rootNode);
|
||||
virtual void loadGame(const XmlNode *rootNode);
|
||||
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
|
@@ -658,6 +658,48 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
// playerColor="x [1] y [0] z [0] w [0]"
|
||||
static inline Vec4<T> strToVec4(std::string value) {
|
||||
Vec4<T> result;
|
||||
|
||||
std::vector<std::string> tokens = TokenizeString(value,"[");
|
||||
//for(unsigned int i = 0; i < tokens.size(); ++i) {
|
||||
//printf("#1 Vec2T i = %d [%s]\n",i,tokens[i].c_str());
|
||||
//}
|
||||
if(tokens.size() == 5) {
|
||||
std::vector<std::string> tokens2 = TokenizeString(tokens[1],"]");
|
||||
//for(unsigned int i = 0; i < tokens2.size(); ++i) {
|
||||
//printf("#2 Vec2T i = %d [%s]\n",i,tokens2[i].c_str());
|
||||
//}
|
||||
std::vector<std::string> tokens3 = TokenizeString(tokens[2],"]");
|
||||
//for(unsigned int i = 0; i < tokens3.size(); ++i) {
|
||||
//printf("#3 Vec2T i = %d [%s]\n",i,tokens3[i].c_str());
|
||||
//}
|
||||
|
||||
std::vector<std::string> tokens4 = TokenizeString(tokens[3],"]");
|
||||
//for(unsigned int i = 0; i < tokens3.size(); ++i) {
|
||||
//printf("#3 Vec2T i = %d [%s]\n",i,tokens3[i].c_str());
|
||||
//}
|
||||
|
||||
std::vector<std::string> tokens5 = TokenizeString(tokens[4],"]");
|
||||
//for(unsigned int i = 0; i < tokens3.size(); ++i) {
|
||||
//printf("#3 Vec2T i = %d [%s]\n",i,tokens3[i].c_str());
|
||||
//}
|
||||
|
||||
if(tokens2.size() == 2 && tokens3.size() == 2 &&
|
||||
tokens4.size() == 2 && tokens5.size() == 2) {
|
||||
result.x = (T)strToType<T>(tokens2[0]);
|
||||
result.y = (T)strToType<T>(tokens3[0]);
|
||||
result.z = (T)strToType<T>(tokens4[0]);
|
||||
result.w = (T)strToType<T>(tokens5[0]);
|
||||
|
||||
//printf("#3 Vec2T [%s]\n",result.getString().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
typedef Vec4<int> Vec4i;
|
||||
|
@@ -29,7 +29,7 @@ namespace XERCES_CPP_NAMESPACE{
|
||||
|
||||
namespace Shared{ namespace Xml{
|
||||
|
||||
const int strSize= 4096;
|
||||
const int strSize= 8094;
|
||||
|
||||
class XmlIo;
|
||||
class XmlTree;
|
||||
|
@@ -21,6 +21,7 @@
|
||||
#include "math_util.h"
|
||||
#include "platform_common.h"
|
||||
#include "conversion.h"
|
||||
#include "model.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace std;
|
||||
@@ -58,6 +59,26 @@ void Particle::saveGame(XmlNode *rootNode) {
|
||||
|
||||
}
|
||||
|
||||
void Particle::loadGame(const XmlNode *rootNode) {
|
||||
const XmlNode *particleNode = rootNode;
|
||||
|
||||
//particleNode = aiNode->getAttribute("startLoc")->getIntValue();
|
||||
// Vec3f pos;
|
||||
pos = Vec3f::strToVec3(particleNode->getAttribute("pos")->getValue());
|
||||
// Vec3f lastPos;
|
||||
lastPos = Vec3f::strToVec3(particleNode->getAttribute("lastPos")->getValue());
|
||||
// Vec3f speed;
|
||||
speed = Vec3f::strToVec3(particleNode->getAttribute("speed")->getValue());
|
||||
// Vec3f accel;
|
||||
accel = Vec3f::strToVec3(particleNode->getAttribute("accel")->getValue());
|
||||
// Vec4f color;
|
||||
color = Vec4f::strToVec4(particleNode->getAttribute("color")->getValue());
|
||||
// float size;
|
||||
size = particleNode->getAttribute("size")->getFloatValue();
|
||||
// int energy;
|
||||
energy = particleNode->getAttribute("energy")->getIntValue();
|
||||
}
|
||||
|
||||
ParticleSystem::ParticleSystem(int particleCount) {
|
||||
if(checkMemory) {
|
||||
printf("++ Create ParticleSystem [%p]\n",this);
|
||||
@@ -294,6 +315,75 @@ void ParticleSystem::saveGame(XmlNode *rootNode) {
|
||||
particleObserver->saveGame(particleSystemNode);
|
||||
}
|
||||
}
|
||||
|
||||
void ParticleSystem::loadGame(const XmlNode *rootNode) {
|
||||
const XmlNode *particleSystemNode = rootNode->getChild("ParticleSystem");
|
||||
|
||||
// std::vector<Particle> particles;
|
||||
// for(unsigned int i = 0; i < particles.size(); ++i) {
|
||||
// Particle &particle = particles[i];
|
||||
// particle.saveGame(particleSystemNode);
|
||||
// }
|
||||
vector<XmlNode *> particleNodeList = particleSystemNode->getChildList("Particle");
|
||||
for(unsigned int i = 0; i < particleNodeList.size(); ++i) {
|
||||
XmlNode *node = particleNodeList[i];
|
||||
|
||||
Particle particle;
|
||||
particle.loadGame(node);
|
||||
particles.push_back(particle);
|
||||
}
|
||||
|
||||
// RandomGen random;
|
||||
random.setLastNumber(particleSystemNode->getAttribute("random")->getIntValue());
|
||||
|
||||
// BlendMode blendMode;
|
||||
blendMode = static_cast<BlendMode>(particleSystemNode->getAttribute("blendMode")->getIntValue());
|
||||
// State state;
|
||||
state = static_cast<State>(particleSystemNode->getAttribute("state")->getIntValue());
|
||||
// bool active;
|
||||
active = particleSystemNode->getAttribute("active")->getIntValue();
|
||||
// bool visible;
|
||||
visible = particleSystemNode->getAttribute("visible")->getIntValue();
|
||||
// int aliveParticleCount;
|
||||
aliveParticleCount = particleSystemNode->getAttribute("aliveParticleCount")->getIntValue();
|
||||
// int particleCount;
|
||||
particleCount = particleSystemNode->getAttribute("particleCount")->getIntValue();
|
||||
//
|
||||
// Texture *texture;
|
||||
// Vec3f pos;
|
||||
pos = Vec3f::strToVec3(particleSystemNode->getAttribute("pos")->getValue());
|
||||
// Vec4f color;
|
||||
color = Vec4f::strToVec4(particleSystemNode->getAttribute("color")->getValue());
|
||||
// Vec4f colorNoEnergy;
|
||||
colorNoEnergy = Vec4f::strToVec4(particleSystemNode->getAttribute("colorNoEnergy")->getValue());
|
||||
// float emissionRate;
|
||||
emissionRate = particleSystemNode->getAttribute("emissionRate")->getFloatValue();
|
||||
// float emissionState;
|
||||
emissionState = particleSystemNode->getAttribute("emissionState")->getFloatValue();
|
||||
// int maxParticleEnergy;
|
||||
maxParticleEnergy = particleSystemNode->getAttribute("maxParticleEnergy")->getIntValue();
|
||||
// int varParticleEnergy;
|
||||
varParticleEnergy = particleSystemNode->getAttribute("varParticleEnergy")->getIntValue();
|
||||
// float particleSize;
|
||||
particleSize = particleSystemNode->getAttribute("particleSize")->getFloatValue();
|
||||
// float speed;
|
||||
speed = particleSystemNode->getAttribute("speed")->getFloatValue();
|
||||
// Vec3f factionColor;
|
||||
factionColor = Vec3f::strToVec3(particleSystemNode->getAttribute("factionColor")->getValue());
|
||||
// bool teamcolorNoEnergy;
|
||||
teamcolorNoEnergy = particleSystemNode->getAttribute("teamcolorNoEnergy")->getIntValue();
|
||||
// bool teamcolorEnergy;
|
||||
teamcolorEnergy = particleSystemNode->getAttribute("teamcolorEnergy")->getIntValue();
|
||||
// int alternations;
|
||||
alternations = particleSystemNode->getAttribute("alternations")->getIntValue();
|
||||
// int particleSystemStartDelay;
|
||||
particleSystemStartDelay = particleSystemNode->getAttribute("particleSystemStartDelay")->getIntValue();
|
||||
// ParticleObserver *particleObserver;
|
||||
//if(particleObserver != NULL) {
|
||||
// particleObserver->loadGame(particleSystemNode);
|
||||
//}
|
||||
}
|
||||
|
||||
// =============== MISC =========================
|
||||
void ParticleSystem::fade(){
|
||||
if(particleObserver != NULL){
|
||||
@@ -483,6 +573,28 @@ void FireParticleSystem::setWind(float windAngle, float windSpeed){
|
||||
#endif
|
||||
}
|
||||
|
||||
void FireParticleSystem::saveGame(XmlNode *rootNode) {
|
||||
std::map<string,string> mapTagReplacements;
|
||||
XmlNode *fireParticleSystemNode = rootNode->addChild("FireParticleSystem");
|
||||
|
||||
ParticleSystem::saveGame(fireParticleSystemNode);
|
||||
|
||||
// float radius;
|
||||
fireParticleSystemNode->addAttribute("radius",floatToStr(radius), mapTagReplacements);
|
||||
// Vec3f windSpeed;
|
||||
fireParticleSystemNode->addAttribute("windSpeed",windSpeed.getString(), mapTagReplacements);
|
||||
}
|
||||
void FireParticleSystem::loadGame(const XmlNode *rootNode) {
|
||||
const XmlNode *fireParticleSystemNode = rootNode;
|
||||
|
||||
ParticleSystem::loadGame(fireParticleSystemNode);
|
||||
|
||||
// float radius;
|
||||
radius = fireParticleSystemNode->getAttribute("radius")->getFloatValue();
|
||||
// Vec3f windSpeed;
|
||||
windSpeed = Vec3f::strToVec3(fireParticleSystemNode->getAttribute("windSpeed")->getValue());
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
// GameParticleSystem
|
||||
// ===========================================================================
|
||||
@@ -607,6 +719,69 @@ void GameParticleSystem::setTween(float relative,float absolute) {
|
||||
(*it)->setTween(relative,absolute);
|
||||
}
|
||||
|
||||
void GameParticleSystem::saveGame(XmlNode *rootNode) {
|
||||
std::map<string,string> mapTagReplacements;
|
||||
XmlNode *gameParticleSystemNode = rootNode->addChild("GameParticleSystem");
|
||||
|
||||
ParticleSystem::saveGame(gameParticleSystemNode);
|
||||
|
||||
// Children children;
|
||||
for(unsigned int i = 0; i < children.size(); ++i) {
|
||||
children[i]->saveGame(gameParticleSystemNode);
|
||||
}
|
||||
// Primitive primitive;
|
||||
gameParticleSystemNode->addAttribute("primitive",intToStr(primitive), mapTagReplacements);
|
||||
// Model *model;
|
||||
if(model != NULL) {
|
||||
gameParticleSystemNode->addAttribute("model",model->getFileName(), mapTagReplacements);
|
||||
}
|
||||
// float modelCycle;
|
||||
gameParticleSystemNode->addAttribute("modelCycle",floatToStr(modelCycle), mapTagReplacements);
|
||||
// Vec3f offset;
|
||||
gameParticleSystemNode->addAttribute("offset",offset.getString(), mapTagReplacements);
|
||||
// Vec3f direction;
|
||||
gameParticleSystemNode->addAttribute("direction",direction.getString(), mapTagReplacements);
|
||||
// float tween;
|
||||
gameParticleSystemNode->addAttribute("tween",floatToStr(tween), mapTagReplacements);
|
||||
}
|
||||
void GameParticleSystem::loadGame(const XmlNode *rootNode) {
|
||||
const XmlNode *gameParticleSystemNode = rootNode;
|
||||
|
||||
ParticleSystem::loadGame(gameParticleSystemNode);
|
||||
|
||||
//radius = fireParticleSystemNode->getAttribute("radius")->getFloatValue();
|
||||
|
||||
// Children children;
|
||||
// for(unsigned int i = 0; i < children.size(); ++i) {
|
||||
// children[i]->saveGame(gameParticleSystemNode);
|
||||
// }
|
||||
vector<XmlNode *> childrenNodeList = gameParticleSystemNode->getChildList("UnitParticleSystem");
|
||||
for(unsigned int i = 0; i < childrenNodeList.size(); ++i) {
|
||||
XmlNode *node = childrenNodeList[i];
|
||||
|
||||
UnitParticleSystem *ups = new UnitParticleSystem();
|
||||
ups->loadGame(node);
|
||||
|
||||
children.push_back(ups);
|
||||
}
|
||||
|
||||
// Primitive primitive;
|
||||
primitive = static_cast<Primitive>(gameParticleSystemNode->getAttribute("primitive")->getIntValue());
|
||||
// Model *model;
|
||||
//if(model != NULL) {
|
||||
// gameParticleSystemNode->addAttribute("model",model->getFileName(), mapTagReplacements);
|
||||
//}
|
||||
// float modelCycle;
|
||||
//gameParticleSystemNode->addAttribute("modelCycle",floatToStr(modelCycle), mapTagReplacements);
|
||||
modelCycle = gameParticleSystemNode->getAttribute("modelCycle")->getFloatValue();
|
||||
// Vec3f offset;
|
||||
offset = Vec3f::strToVec3(gameParticleSystemNode->getAttribute("modelCycle")->getValue());
|
||||
// Vec3f direction;
|
||||
direction = Vec3f::strToVec3(gameParticleSystemNode->getAttribute("direction")->getValue());
|
||||
// float tween;
|
||||
tween = gameParticleSystemNode->getAttribute("tween")->getFloatValue();
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
// UnitParticleSystem
|
||||
// ===========================================================================
|
||||
@@ -869,6 +1044,48 @@ void UnitParticleSystem::setWind(float windAngle, float windSpeed){
|
||||
#endif
|
||||
}
|
||||
|
||||
void UnitParticleSystem::saveGame(XmlNode *rootNode) {
|
||||
std::map<string,string> mapTagReplacements;
|
||||
XmlNode *unitParticleSystemNode = rootNode->addChild("UnitParticleSystem");
|
||||
|
||||
GameParticleSystem::saveGame(unitParticleSystemNode);
|
||||
|
||||
//unitParticleSystemNode->addAttribute("radius",floatToStr(radius), mapTagReplacements);
|
||||
|
||||
// float radius;
|
||||
// float minRadius;
|
||||
// Vec3f windSpeed;
|
||||
// Vec3f cRotation;
|
||||
// Vec3f fixedAddition;
|
||||
// Vec3f oldPosition;
|
||||
// bool energyUp;
|
||||
// float startTime;
|
||||
// float endTime;
|
||||
// bool relative;
|
||||
// bool relativeDirection;
|
||||
// bool fixed;
|
||||
// Shape shape;
|
||||
// float angle;
|
||||
// float sizeNoEnergy;
|
||||
// float gravity;
|
||||
// float rotation;
|
||||
// bool isVisibleAtNight;
|
||||
// bool isVisibleAtDay;
|
||||
// bool isDaylightAffected;
|
||||
// bool radiusBasedStartenergy;
|
||||
// int staticParticleCount;
|
||||
// int delay;
|
||||
// int lifetime;
|
||||
// float emissionRateFade;
|
||||
// GameParticleSystem* parent;
|
||||
|
||||
}
|
||||
void UnitParticleSystem::loadGame(const XmlNode *rootNode) {
|
||||
const XmlNode *unitParticleSystemNode = rootNode;
|
||||
|
||||
GameParticleSystem::loadGame(unitParticleSystemNode);
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
// RainParticleSystem
|
||||
// ===========================================================================
|
||||
|
Reference in New Issue
Block a user