mirror of
https://github.com/glest/glest-source.git
synced 2025-08-26 09:24:24 +02:00
- initial work to save game state to XML. Current only saves when out of synch or game end occurs and saves to same folder as log files and file is called: megaglest-saved.xml
(Currently we store way too much info but this is a starting point)
This commit is contained in:
@@ -18,10 +18,12 @@
|
||||
#include "pixmap.h"
|
||||
#include "texture_manager.h"
|
||||
#include "randomgen.h"
|
||||
#include "xml_parser.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using std::list;
|
||||
using Shared::Util::RandomGen;
|
||||
using Shared::Xml::XmlNode;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
@@ -64,6 +66,8 @@ public:
|
||||
Vec4f getColor() const {return color;}
|
||||
float getSize() const {return size;}
|
||||
int getEnergy() const {return energy;}
|
||||
|
||||
void saveGame(XmlNode *rootNode);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
@@ -74,6 +78,7 @@ class ParticleObserver{
|
||||
public:
|
||||
virtual ~ParticleObserver(){};
|
||||
virtual void update(ParticleSystem *particleSystem)= 0;
|
||||
virtual void saveGame(XmlNode *rootNode) = 0;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
@@ -186,6 +191,8 @@ public:
|
||||
virtual int getChildCount() { return 0; }
|
||||
virtual ParticleSystem* getChild(int i);
|
||||
|
||||
void saveGame(XmlNode *rootNode);
|
||||
|
||||
protected:
|
||||
//protected
|
||||
Particle *createParticle();
|
||||
|
@@ -39,6 +39,9 @@ public:
|
||||
int rand();
|
||||
int randRange(int min, int max);
|
||||
float randRange(float min, float max);
|
||||
|
||||
int getLastNumber() const { return lastNumber; }
|
||||
void setLastNumber(int value) { lastNumber = value; }
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
@@ -1915,12 +1915,20 @@ void Md5Object::render () const {
|
||||
//glRotatef( -90.0, 1.0, 0.0, 0.0 );
|
||||
//glRotatef( -90.0, 0.0, 0.0, 1.0 );
|
||||
//glTranslatef( 0.0f, -60.0f, 0.0f );
|
||||
glRotatef( -20.0, 1.0, 0.0, 0.0 );
|
||||
glRotatef( -20.0, 0.0, 1.0, 0.0 );
|
||||
|
||||
//!glRotatef( -20.0, 1.0, 0.0, 0.0 );
|
||||
//!glRotatef( -20.0, 0.0, 1.0, 0.0 );
|
||||
|
||||
//glRotatef( 50.0, 1.0, 0.0, 0.0 );
|
||||
//glTranslatef( 5.0f, -2.0f, -3.0f );
|
||||
glTranslatef(-1.4f, -1.4f, -7.5f);
|
||||
glScalef(1/4.0f, 1/4.0f, 1);
|
||||
|
||||
//!glTranslatef(-1.4f, -1.4f, -7.5f);
|
||||
|
||||
//glRotatef( 90.0, 0.0, 0.0, 1.0 );
|
||||
//glRotatef( -25.0, 0.0, 1.0, 0.0 );
|
||||
|
||||
//glRotatef( -20.0, 1.0, 0.0, 0.0 );
|
||||
//glScalef(1.0/20.0f, 1.0/20.0f, 1.0f);
|
||||
|
||||
if (!_softwareTransformation) {
|
||||
glMultMatrixf (_modelView._m);
|
||||
|
@@ -20,6 +20,7 @@
|
||||
#include "particle_renderer.h"
|
||||
#include "math_util.h"
|
||||
#include "platform_common.h"
|
||||
#include "conversion.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace std;
|
||||
@@ -36,6 +37,27 @@ namespace Graphics {
|
||||
const bool checkMemory = false;
|
||||
static map<void *,int> memoryObjectList;
|
||||
|
||||
void Particle::saveGame(XmlNode *rootNode) {
|
||||
std::map<string,string> mapTagReplacements;
|
||||
XmlNode *particleNode = rootNode->addChild("Particle");
|
||||
|
||||
// Vec3f pos;
|
||||
particleNode->addAttribute("pos",pos.getString(), mapTagReplacements);
|
||||
// Vec3f lastPos;
|
||||
particleNode->addAttribute("lastPos",lastPos.getString(), mapTagReplacements);
|
||||
// Vec3f speed;
|
||||
particleNode->addAttribute("speed",speed.getString(), mapTagReplacements);
|
||||
// Vec3f accel;
|
||||
particleNode->addAttribute("accel",accel.getString(), mapTagReplacements);
|
||||
// Vec4f color;
|
||||
particleNode->addAttribute("color",color.getString(), mapTagReplacements);
|
||||
// float size;
|
||||
particleNode->addAttribute("size",floatToStr(size), mapTagReplacements);
|
||||
// int energy;
|
||||
particleNode->addAttribute("energy",intToStr(energy), mapTagReplacements);
|
||||
|
||||
}
|
||||
|
||||
ParticleSystem::ParticleSystem(int particleCount) {
|
||||
if(checkMemory) {
|
||||
printf("++ Create ParticleSystem [%p]\n",this);
|
||||
@@ -213,6 +235,65 @@ void ParticleSystem::setVisible(bool visible){
|
||||
getChild(i)->setVisible(visible);
|
||||
}
|
||||
|
||||
void ParticleSystem::saveGame(XmlNode *rootNode) {
|
||||
std::map<string,string> mapTagReplacements;
|
||||
XmlNode *particleSystemNode = rootNode->addChild("ParticleSystem");
|
||||
|
||||
// std::vector<Particle> particles;
|
||||
for(unsigned int i = 0; i < particles.size(); ++i) {
|
||||
Particle &particle = particles[i];
|
||||
particle.saveGame(particleSystemNode);
|
||||
}
|
||||
// RandomGen random;
|
||||
particleSystemNode->addAttribute("random",intToStr(random.getLastNumber()), mapTagReplacements);
|
||||
|
||||
// BlendMode blendMode;
|
||||
particleSystemNode->addAttribute("blendMode",intToStr(blendMode), mapTagReplacements);
|
||||
// State state;
|
||||
particleSystemNode->addAttribute("state",intToStr(state), mapTagReplacements);
|
||||
// bool active;
|
||||
particleSystemNode->addAttribute("active",intToStr(active), mapTagReplacements);
|
||||
// bool visible;
|
||||
particleSystemNode->addAttribute("visible",intToStr(visible), mapTagReplacements);
|
||||
// int aliveParticleCount;
|
||||
particleSystemNode->addAttribute("aliveParticleCount",intToStr(aliveParticleCount), mapTagReplacements);
|
||||
// int particleCount;
|
||||
particleSystemNode->addAttribute("particleCount",intToStr(particleCount), mapTagReplacements);
|
||||
//
|
||||
// Texture *texture;
|
||||
// Vec3f pos;
|
||||
particleSystemNode->addAttribute("pos",pos.getString(), mapTagReplacements);
|
||||
// Vec4f color;
|
||||
particleSystemNode->addAttribute("color",color.getString(), mapTagReplacements);
|
||||
// Vec4f colorNoEnergy;
|
||||
particleSystemNode->addAttribute("colorNoEnergy",colorNoEnergy.getString(), mapTagReplacements);
|
||||
// float emissionRate;
|
||||
particleSystemNode->addAttribute("emissionRate",floatToStr(emissionRate), mapTagReplacements);
|
||||
// float emissionState;
|
||||
particleSystemNode->addAttribute("emissionState",floatToStr(emissionState), mapTagReplacements);
|
||||
// int maxParticleEnergy;
|
||||
particleSystemNode->addAttribute("maxParticleEnergy",intToStr(maxParticleEnergy), mapTagReplacements);
|
||||
// int varParticleEnergy;
|
||||
particleSystemNode->addAttribute("varParticleEnergy",intToStr(varParticleEnergy), mapTagReplacements);
|
||||
// float particleSize;
|
||||
particleSystemNode->addAttribute("particleSize",floatToStr(particleSize), mapTagReplacements);
|
||||
// float speed;
|
||||
particleSystemNode->addAttribute("speed",floatToStr(speed), mapTagReplacements);
|
||||
// Vec3f factionColor;
|
||||
particleSystemNode->addAttribute("factionColor",factionColor.getString(), mapTagReplacements);
|
||||
// bool teamcolorNoEnergy;
|
||||
particleSystemNode->addAttribute("teamcolorNoEnergy",intToStr(teamcolorNoEnergy), mapTagReplacements);
|
||||
// bool teamcolorEnergy;
|
||||
particleSystemNode->addAttribute("teamcolorEnergy",intToStr(teamcolorEnergy), mapTagReplacements);
|
||||
// int alternations;
|
||||
particleSystemNode->addAttribute("alternations",intToStr(alternations), mapTagReplacements);
|
||||
// int particleSystemStartDelay;
|
||||
particleSystemNode->addAttribute("particleSystemStartDelay",intToStr(particleSystemStartDelay), mapTagReplacements);
|
||||
// ParticleObserver *particleObserver;
|
||||
if(particleObserver != NULL) {
|
||||
particleObserver->saveGame(particleSystemNode);
|
||||
}
|
||||
}
|
||||
// =============== MISC =========================
|
||||
void ParticleSystem::fade(){
|
||||
if(particleObserver != NULL){
|
||||
|
@@ -147,6 +147,16 @@ void XmlIo::save(const string &path, const XmlNode *node){
|
||||
|
||||
XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *document= implementation->createDocument(0, str, 0);
|
||||
DOMElement *documentElement= document->getDocumentElement();
|
||||
for(unsigned int i = 0; i < node->getAttributeCount() ; ++i){
|
||||
XmlAttribute *attr = node->getAttribute(i);
|
||||
|
||||
XMLCh strName[strSize];
|
||||
XMLString::transcode(attr->getName().c_str(), strName, strSize-1);
|
||||
XMLCh strValue[strSize];
|
||||
XMLString::transcode(attr->getValue("",false).c_str(), strValue, strSize-1);
|
||||
|
||||
documentElement->setAttribute(strName,strValue);
|
||||
}
|
||||
|
||||
for(unsigned int i=0; i<node->getChildCount(); ++i){
|
||||
documentElement->appendChild(node->getChild(i)->buildElement(document));
|
||||
|
Reference in New Issue
Block a user