diff --git a/source/glest_game/global/core_data.cpp b/source/glest_game/global/core_data.cpp index 83d0d6ae..266b69b9 100644 --- a/source/glest_game/global/core_data.cpp +++ b/source/glest_game/global/core_data.cpp @@ -87,6 +87,70 @@ void CoreData::cleanup() { waterSounds.getSoundsPtr()->clear(); } +Texture2D *CoreData::getTextureBySystemId(TextureSystemType type) const { + Texture2D *result = NULL; + switch(type) { + case tsyst_logoTexture: + result = logoTexture; + break; + //std::vector logoTextureList; + case tsyst_backgroundTexture: + result = backgroundTexture; + break; + case tsyst_fireTexture: + result = fireTexture; + break; + case tsyst_teamColorTexture: + result = teamColorTexture; + break; + case tsyst_snowTexture: + result = snowTexture; + break; + case tsyst_waterSplashTexture: + result = waterSplashTexture; + break; + case tsyst_customTexture: + result = customTexture; + break; + case tsyst_buttonSmallTexture: + result = buttonSmallTexture; + break; + case tsyst_buttonBigTexture: + result = buttonBigTexture; + break; + case tsyst_horizontalLineTexture: + result = horizontalLineTexture; + break; + case tsyst_verticalLineTexture: + result = verticalLineTexture; + break; + case tsyst_checkBoxTexture: + result = checkBoxTexture; + break; + case tsyst_checkedCheckBoxTexture: + result = checkedCheckBoxTexture; + break; + case tsyst_gameWinnerTexture: + result = gameWinnerTexture; + break; + case tsyst_notOnServerTexture: + result = notOnServerTexture; + break; + case tsyst_onServerDifferentTexture: + result = onServerDifferentTexture; + break; + case tsyst_onServerTexture: + result = onServerTexture; + break; + case tsyst_onServerInstalledTexture: + result = onServerInstalledTexture; + break; + + //std::vector miscTextureList; + } + return result; +} + void CoreData::load() { string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey); if(data_path != "") { @@ -103,6 +167,7 @@ void CoreData::load() { if(backgroundTexture) { backgroundTexture->setMipmap(false); backgroundTexture->getPixmap()->load(getGameCustomCoreDataPath(data_path, "data/core/menu/textures/back.tga")); + backgroundTexture->setTextureSystemId(tsyst_backgroundTexture); } fireTexture= renderer.newTexture2D(rsGlobal); @@ -110,6 +175,7 @@ void CoreData::load() { fireTexture->setFormat(Texture::fAlpha); fireTexture->getPixmap()->init(1); fireTexture->getPixmap()->load(getGameCustomCoreDataPath(data_path, "data/core/misc_textures/fire_particle.tga")); + fireTexture->setTextureSystemId(tsyst_fireTexture); } teamColorTexture= renderer.newTexture2D(rsGlobal); @@ -117,6 +183,7 @@ void CoreData::load() { teamColorTexture->setFormat(Texture::fAlpha); teamColorTexture->getPixmap()->init(1); teamColorTexture->getPixmap()->load(getGameCustomCoreDataPath(data_path, "data/core/misc_textures/team_color_texture.tga")); + teamColorTexture->setTextureSystemId(tsyst_teamColorTexture); } snowTexture= renderer.newTexture2D(rsGlobal); @@ -125,33 +192,40 @@ void CoreData::load() { snowTexture->setFormat(Texture::fAlpha); snowTexture->getPixmap()->init(1); snowTexture->getPixmap()->load(getGameCustomCoreDataPath(data_path, "data/core/misc_textures/snow_particle.tga")); + snowTexture->setTextureSystemId(tsyst_snowTexture); } customTexture= renderer.newTexture2D(rsGlobal); if(customTexture) { customTexture->getPixmap()->load(getGameCustomCoreDataPath(data_path, "data/core/menu/textures/custom_texture.tga")); + customTexture->setTextureSystemId(tsyst_customTexture); } notOnServerTexture= renderer.newTexture2D(rsGlobal); if(notOnServerTexture) { notOnServerTexture->getPixmap()->load(getGameCustomCoreDataPath(data_path, "data/core/menu/textures/not_on_server.tga")); + notOnServerTexture->setTextureSystemId(tsyst_notOnServerTexture); } onServerDifferentTexture= renderer.newTexture2D(rsGlobal); if(onServerDifferentTexture) { onServerDifferentTexture->getPixmap()->load(getGameCustomCoreDataPath(data_path, "data/core/menu/textures/on_server_different.tga")); + onServerDifferentTexture->setTextureSystemId(tsyst_onServerDifferentTexture); onServerTexture= renderer.newTexture2D(rsGlobal); onServerTexture->getPixmap()->load(getGameCustomCoreDataPath(data_path, "data/core/menu/textures/on_server.tga")); + onServerTexture->setTextureSystemId(tsyst_onServerTexture); onServerInstalledTexture= renderer.newTexture2D(rsGlobal); onServerInstalledTexture->getPixmap()->load(getGameCustomCoreDataPath(data_path, "data/core/menu/textures/on_server_installed.tga")); + onServerInstalledTexture->setTextureSystemId(tsyst_onServerInstalledTexture); } logoTexture= renderer.newTexture2D(rsGlobal); if(logoTexture) { logoTexture->setMipmap(false); logoTexture->getPixmap()->load(getGameCustomCoreDataPath(data_path, "data/core/menu/textures/logo.tga")); + logoTexture->setTextureSystemId(tsyst_logoTexture); } logoTextureList.clear(); @@ -227,48 +301,56 @@ void CoreData::load() { waterSplashTexture->setFormat(Texture::fAlpha); waterSplashTexture->getPixmap()->init(1); waterSplashTexture->getPixmap()->load(getGameCustomCoreDataPath(data_path, "data/core/misc_textures/water_splash.tga")); + waterSplashTexture->setTextureSystemId(tsyst_waterSplashTexture); } buttonSmallTexture= renderer.newTexture2D(rsGlobal); if(buttonSmallTexture) { buttonSmallTexture->setForceCompressionDisabled(true); buttonSmallTexture->getPixmap()->load(getGameCustomCoreDataPath(data_path, "data/core/menu/textures/button_small.tga")); + buttonSmallTexture->setTextureSystemId(tsyst_buttonSmallTexture); } buttonBigTexture= renderer.newTexture2D(rsGlobal); if(buttonBigTexture) { buttonBigTexture->setForceCompressionDisabled(true); buttonBigTexture->getPixmap()->load(getGameCustomCoreDataPath(data_path, "data/core/menu/textures/button_big.tga")); + buttonBigTexture->setTextureSystemId(tsyst_buttonBigTexture); } horizontalLineTexture= renderer.newTexture2D(rsGlobal); if(horizontalLineTexture) { horizontalLineTexture->setForceCompressionDisabled(true); horizontalLineTexture->getPixmap()->load(getGameCustomCoreDataPath(data_path, "data/core/menu/textures/line_horizontal.tga")); + horizontalLineTexture->setTextureSystemId(tsyst_horizontalLineTexture); } verticalLineTexture= renderer.newTexture2D(rsGlobal); if(verticalLineTexture) { verticalLineTexture->setForceCompressionDisabled(true); verticalLineTexture->getPixmap()->load(getGameCustomCoreDataPath(data_path, "data/core/menu/textures/line_vertical.tga")); + verticalLineTexture->setTextureSystemId(tsyst_verticalLineTexture); } checkBoxTexture= renderer.newTexture2D(rsGlobal); if(checkBoxTexture) { checkBoxTexture->setForceCompressionDisabled(true); checkBoxTexture->getPixmap()->load(getGameCustomCoreDataPath(data_path, "data/core/menu/textures/checkbox.tga")); + checkBoxTexture->setTextureSystemId(tsyst_checkBoxTexture); } checkedCheckBoxTexture= renderer.newTexture2D(rsGlobal); if(checkedCheckBoxTexture) { checkedCheckBoxTexture->setForceCompressionDisabled(true); checkedCheckBoxTexture->getPixmap()->load(getGameCustomCoreDataPath(data_path, "data/core/menu/textures/checkbox_checked.tga")); + checkedCheckBoxTexture->setTextureSystemId(tsyst_checkedCheckBoxTexture); } gameWinnerTexture= renderer.newTexture2D(rsGlobal); if(gameWinnerTexture) { gameWinnerTexture->setForceCompressionDisabled(true); gameWinnerTexture->getPixmap()->load(getGameCustomCoreDataPath(data_path, "data/core/misc_textures/game_winner.png")); + gameWinnerTexture->setTextureSystemId(tsyst_gameWinnerTexture); } loadFonts(); diff --git a/source/glest_game/global/core_data.h b/source/glest_game/global/core_data.h index 2c27e615..c31ec9ce 100644 --- a/source/glest_game/global/core_data.h +++ b/source/glest_game/global/core_data.h @@ -84,6 +84,33 @@ private: Font3D *menuFontVeryBig3D; Font3D *consoleFont3D; +public: + + enum TextureSystemType { + tsyst_NONE, + tsyst_logoTexture, + //std::vector logoTextureList; + tsyst_backgroundTexture, + tsyst_fireTexture, + tsyst_teamColorTexture, + tsyst_snowTexture, + tsyst_waterSplashTexture, + tsyst_customTexture, + tsyst_buttonSmallTexture, + tsyst_buttonBigTexture, + tsyst_horizontalLineTexture, + tsyst_verticalLineTexture, + tsyst_checkBoxTexture, + tsyst_checkedCheckBoxTexture, + tsyst_gameWinnerTexture, + tsyst_notOnServerTexture, + tsyst_onServerDifferentTexture, + tsyst_onServerTexture, + tsyst_onServerInstalledTexture + + //std::vector miscTextureList; + }; + public: ~CoreData(); @@ -93,6 +120,8 @@ public: void cleanup(); void loadFonts(); + Texture2D *getTextureBySystemId(TextureSystemType type) const; + Texture2D *getBackgroundTexture() const {return backgroundTexture;} Texture2D *getFireTexture() const {return fireTexture;} Texture2D *getTeamColorTexture() const {return teamColorTexture;} diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 0db23974..f3c0c528 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -460,30 +460,30 @@ void Renderer::initGame(const Game *game, GameCamera *gameCamera) { } void Renderer::manageDeferredParticleSystems() { - //std::vector > deferredParticleSystems - //printf("Before deferredParticleSystems.size() = %d\n",deferredParticleSystems.size()); for(unsigned int i = 0; i < deferredParticleSystems.size(); ++i) { std::pair &deferredParticleSystem = deferredParticleSystems[i]; ParticleSystem *ps = deferredParticleSystem.first; ResourceScope rs = deferredParticleSystem.second; if(ps->getTextureFileLoadDeferred() != "" && ps->getTexture() == NULL) { - Texture2D *texture= newTexture2D(rsGame); - if(texture) { -// if(textureNode->getAttribute("luminance")->getBoolValue()){ -// texture->setFormat(Texture::fAlpha); -// texture->getPixmap()->init(1); -// } -// else{ - texture->getPixmap()->init(4); -// } - } -// string currentPath = dir; -// endPathWithSlash(currentPath); - if(texture) { - texture->load(ps->getTextureFileLoadDeferred()); + CoreData::TextureSystemType textureSystemId = + static_cast( + ps->getTextureFileLoadDeferredSystemId()); + if(textureSystemId != CoreData::tsyst_NONE) { + Texture2D *texture= CoreData::getInstance().getTextureBySystemId(textureSystemId); + //printf("Loading texture from system [%d] [%p]\n",textureSystemId,texture); ps->setTexture(texture); } -// loadedFileList[textureNode->getAttribute("path")->getRestrictedValue(currentPath)].push_back(make_pair(parentLoader,textureNode->getAttribute("path")->getRestrictedValue())); + else { + Texture2D *texture= newTexture2D(rs); + if(texture) { + texture->setFormat(ps->getTextureFileLoadDeferredFormat()); + texture->getPixmap()->init(ps->getTextureFileLoadDeferredComponents()); + } + if(texture) { + texture->load(ps->getTextureFileLoadDeferred()); + ps->setTexture(texture); + } + } } if(dynamic_cast(ps) != NULL) { GameParticleSystem *gps = dynamic_cast(ps); @@ -494,10 +494,9 @@ void Renderer::manageDeferredParticleSystems() { model->load(gps->getModelFileLoadDeferred(), false, &loadedFileList, NULL); gps->setModel(model); } - //loadedFileList[path].push_back(make_pair(parentLoader,modelNode->getAttribute("path")->getRestrictedValue())); } } - manageParticleSystem(deferredParticleSystem.first, deferredParticleSystem.second); + manageParticleSystem(ps, rs); } deferredParticleSystems.clear(); //printf("After deferredParticleSystems.size() = %d\n",deferredParticleSystems.size()); diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index c3d1e3e5..a9431689 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -3377,6 +3377,24 @@ int glestMain(int argc, char** argv) { if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) { fileName = paramPartTokens[1]; + if(fileExists(fileName) == false) { + // Save the file now + string saveGameFile = "saved/" + fileName; + if(getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) != "") { + saveGameFile = getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) + saveGameFile; + } + else { + string userData = config.getString("UserData_Root",""); + if(userData != "") { + endPathWithSlash(userData); + } + saveGameFile = userData + saveGameFile; + } + if(fileExists(saveGameFile) == true) { + fileName = saveGameFile; + } + } + if(fileExists(fileName) == false) { char szBuf[8096]=""; sprintf(szBuf,"File specified for loading a saved game cannot be found: [%s]",fileName.c_str()); diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 29bd031d..f58cb6fd 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -1054,28 +1054,38 @@ void Unit::setTargetPos(const Vec2i &targetPos) { void Unit::setVisible(const bool visible) { this->visible = visible; - for(UnitParticleSystems::iterator it= unitParticleSystems.begin(); it != unitParticleSystems.end(); ++it) { - if(Renderer::getInstance().validateParticleSystemStillExists((*it),rsGame) == true) { - (*it)->setVisible(visible); + if(unitParticleSystems.empty() == false) { + for(UnitParticleSystems::iterator it= unitParticleSystems.begin(); it != unitParticleSystems.end(); ++it) { + if(Renderer::getInstance().validateParticleSystemStillExists((*it),rsGame) == true) { + (*it)->setVisible(visible); + } } } - for(UnitParticleSystems::iterator it= damageParticleSystems.begin(); it != damageParticleSystems.end(); ++it) { - if(Renderer::getInstance().validateParticleSystemStillExists((*it),rsGame) == true) { - (*it)->setVisible(visible); + if(damageParticleSystems.empty() == false) { + for(UnitParticleSystems::iterator it= damageParticleSystems.begin(); it != damageParticleSystems.end(); ++it) { + if(Renderer::getInstance().validateParticleSystemStillExists((*it),rsGame) == true) { + (*it)->setVisible(visible); + } } } - for(UnitParticleSystems::iterator it= smokeParticleSystems.begin(); it != smokeParticleSystems.end(); ++it) { - if(Renderer::getInstance().validateParticleSystemStillExists((*it),rsGame) == true) { - (*it)->setVisible(visible); + if(smokeParticleSystems.empty() == false) { + for(UnitParticleSystems::iterator it= smokeParticleSystems.begin(); it != smokeParticleSystems.end(); ++it) { + if(Renderer::getInstance().validateParticleSystemStillExists((*it),rsGame) == true) { + if((*it)->getVisible() != visible) { + //printf("Changing visibility for smoke particle system to: %d\n",visible); + (*it)->setVisible(visible); + } + } } } - - for(unsigned int i = 0; i < currentAttackBoostEffects.size(); ++i) { - UnitAttackBoostEffect *effect = currentAttackBoostEffects[i]; - if(effect != NULL && effect->ups != NULL) { - bool particleValid = Renderer::getInstance().validateParticleSystemStillExists(effect->ups,rsGame); - if(particleValid == true) { - effect->ups->setVisible(visible); + if(currentAttackBoostEffects.empty() == false) { + for(unsigned int i = 0; i < currentAttackBoostEffects.size(); ++i) { + UnitAttackBoostEffect *effect = currentAttackBoostEffects[i]; + if(effect != NULL && effect->ups != NULL) { + bool particleValid = Renderer::getInstance().validateParticleSystemStillExists(effect->ups,rsGame); + if(particleValid == true) { + effect->ups->setVisible(visible); + } } } } @@ -2895,6 +2905,8 @@ void Unit::stopDamageParticles(bool force) { if(smokeParticleSystems.empty() == false) { + //printf("Checking to stop smokeparticles for unit [%s - %d] hp = %d\n",this->getType()->getName().c_str(),this->getId(),hp); + for(int i = smokeParticleSystems.size()-1; i >= 0; --i) { UnitParticleSystem *ps = smokeParticleSystems[i]; if(Renderer::getInstance().validateParticleSystemStillExists(ps,rsGame) == true) { @@ -2905,6 +2917,8 @@ void Unit::stopDamageParticles(bool force) { } if(damageParticleSystems.empty() == false) { + //printf("Checking to stop damageparticles for unit [%s - %d] hp = %d\n",this->getType()->getName().c_str(),this->getId(),hp); + for(int i = damageParticleSystems.size()-1; i >= 0; --i) { UnitParticleSystem *ps = damageParticleSystems[i]; UnitParticleSystemType *pst = NULL; @@ -3552,7 +3566,7 @@ void Unit::saveGame(XmlNode *rootNode) { // vector unitParticleSystems; if(unitParticleSystems.size() > 0) { - XmlNode *unitParticleSystemsNode = rootNode->addChild("unitParticleSystems"); + XmlNode *unitParticleSystemsNode = unitNode->addChild("unitParticleSystems"); for(unsigned int i = 0; i < unitParticleSystems.size(); ++i) { UnitParticleSystem *ups= unitParticleSystems[i]; @@ -3563,7 +3577,7 @@ void Unit::saveGame(XmlNode *rootNode) { } // vector queuedUnitParticleSystemTypes; if(queuedUnitParticleSystemTypes.size() > 0) { - XmlNode *queuedUnitParticleSystemTypesNode = rootNode->addChild("queuedUnitParticleSystemTypes"); + XmlNode *queuedUnitParticleSystemTypesNode = unitNode->addChild("queuedUnitParticleSystemTypes"); for(unsigned int i = 0; i < queuedUnitParticleSystemTypes.size(); ++i) { UnitParticleSystemType *upst= queuedUnitParticleSystemTypes[i]; if(upst != NULL) { @@ -3573,7 +3587,7 @@ void Unit::saveGame(XmlNode *rootNode) { } // UnitParticleSystems damageParticleSystems; if(damageParticleSystems.size() > 0) { - XmlNode *damageParticleSystemsNode = rootNode->addChild("damageParticleSystems"); + XmlNode *damageParticleSystemsNode = unitNode->addChild("damageParticleSystems"); for(unsigned int i = 0; i < damageParticleSystems.size(); ++i) { UnitParticleSystem *ups= damageParticleSystems[i]; if(ups != NULL && Renderer::getInstance().validateParticleSystemStillExists(ups,rsGame) == true) { @@ -3583,7 +3597,7 @@ void Unit::saveGame(XmlNode *rootNode) { } // std::map damageParticleSystemsInUse; if(damageParticleSystemsInUse.size() > 0) { - XmlNode *damageParticleSystemsInUseNode = rootNode->addChild("damageParticleSystemsInUse"); + XmlNode *damageParticleSystemsInUseNode = unitNode->addChild("damageParticleSystemsInUse"); for(std::map::const_iterator iterMap = damageParticleSystemsInUse.begin(); iterMap != damageParticleSystemsInUse.end(); ++iterMap) { @@ -3598,7 +3612,7 @@ void Unit::saveGame(XmlNode *rootNode) { // vector fireParticleSystems; if(fireParticleSystems.size() > 0) { - XmlNode *fireParticleSystemsNode = rootNode->addChild("fireParticleSystems"); + XmlNode *fireParticleSystemsNode = unitNode->addChild("fireParticleSystems"); for(unsigned int i = 0; i < fireParticleSystems.size(); ++i) { ParticleSystem *ps= fireParticleSystems[i]; if(ps != NULL && Renderer::getInstance().validateParticleSystemStillExists(ps,rsGame) == true) { @@ -3609,11 +3623,12 @@ void Unit::saveGame(XmlNode *rootNode) { // vector smokeParticleSystems; if(smokeParticleSystems.size() > 0) { - XmlNode *smokeParticleSystemsNode = rootNode->addChild("smokeParticleSystems"); + XmlNode *smokeParticleSystemsNode = unitNode->addChild("smokeParticleSystems"); for(unsigned int i = 0; i < smokeParticleSystems.size(); ++i) { UnitParticleSystem *ups= smokeParticleSystems[i]; if(ups != NULL && Renderer::getInstance().validateParticleSystemStillExists(ups,rsGame) == true) { ups->saveGame(smokeParticleSystemsNode); + //printf("Saving smoke particles:\n[%s]\n",ups->toString().c_str()); } } } @@ -3838,6 +3853,7 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction * XmlNode *fireNode = unitNode->getChild("FireParticleSystem"); result->fire = new FireParticleSystem(); result->fire->loadGame(fireNode); + //result->fire->setTexture(CoreData::getInstance().getFireTexture()); result->fireParticleSystems.push_back(result->fire); //Renderer::getInstance().manageParticleSystem(result->fire, rsGame); @@ -3959,6 +3975,7 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction * FireParticleSystem *ups = new FireParticleSystem(); ups->loadGame(node); + //ups->setTexture(CoreData::getInstance().getFireTexture()); result->fireParticleSystems.push_back(ups); //Renderer::getInstance().manageParticleSystem(result->fire, rsGame); @@ -3977,12 +3994,35 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction * for(unsigned int i = 0; i < unitParticleSystemNodeList.size(); ++i) { XmlNode *node = unitParticleSystemNodeList[i]; +// printf("Load Smoke particle i = %d\n",i); UnitParticleSystem *ups = new UnitParticleSystem(); ups->loadGame(node); + //ups->setTexture(CoreData::getInstance().getFireTexture()); result->smokeParticleSystems.push_back(ups); +// UnitParticleSystem *ups= new UnitParticleSystem(400); +// ups->setColorNoEnergy(Vec4f(0.0f, 0.0f, 0.0f, 0.13f)); +// ups->setColor(Vec4f(0.115f, 0.115f, 0.115f, 0.22f)); +// ups->setPos(result->getCurrVector()); +// ups->setBlendMode(ups->strToBlendMode("black")); +// ups->setOffset(Vec3f(0,2,0)); +// ups->setDirection(Vec3f(0,1,-0.2f)); +// ups->setRadius(result->type->getSize()/3.f); +// ups->setShape(Shared::Graphics::UnitParticleSystem::sLinear); +// ups->setTexture(CoreData::getInstance().getFireTexture()); +// const Game *game = Renderer::getInstance().getGame(); +// ups->setSpeed(2.0f / game->getWorld()->getUpdateFps(result->getFactionIndex())); +// ups->setGravity(0.0004f); +// ups->setEmissionRate(1); +// ups->setMaxParticleEnergy(150); +// ups->setSizeNoEnergy(result->type->getSize()*0.6f); +// ups->setParticleSize(result->type->getSize()*0.8f); +// result->smokeParticleSystems.push_back(ups); + //Renderer::getInstance().manageParticleSystem(result->fire, rsGame); Renderer::getInstance().addToDeferredParticleSystemList(make_pair(ups, rsGame)); + + //printf("Loading smoke particles:\n[%s]\n",ups->toString().c_str()); } } diff --git a/source/shared_lib/include/graphics/particle.h b/source/shared_lib/include/graphics/particle.h index d91db347..e99176d0 100644 --- a/source/shared_lib/include/graphics/particle.h +++ b/source/shared_lib/include/graphics/particle.h @@ -125,6 +125,10 @@ protected: int particleCount; string textureFileLoadDeferred; + int textureFileLoadDeferredSystemId; + Texture::Format textureFileLoadDeferredFormat; + int textureFileLoadDeferredComponents; + Texture *texture; Vec3f pos; Vec4f color; @@ -164,6 +168,10 @@ public: virtual bool getVisible() const {return visible;} virtual string getTextureFileLoadDeferred(); + virtual int getTextureFileLoadDeferredSystemId(); + virtual Texture::Format getTextureFileLoadDeferredFormat(); + virtual int getTextureFileLoadDeferredComponents(); + //set virtual void setState(State state); void setTexture(Texture *texture); @@ -194,6 +202,8 @@ public: virtual int getChildCount() { return 0; } virtual ParticleSystem* getChild(int i); + string toString() const; + virtual void saveGame(XmlNode *rootNode); virtual void loadGame(const XmlNode *rootNode); diff --git a/source/shared_lib/include/graphics/texture.h b/source/shared_lib/include/graphics/texture.h index 96b0b892..52c84fe3 100644 --- a/source/shared_lib/include/graphics/texture.h +++ b/source/shared_lib/include/graphics/texture.h @@ -66,6 +66,7 @@ protected: bool inited; bool forceCompressionDisabled; + int textureSystemId; public: Texture(); @@ -77,6 +78,9 @@ public: Format getFormat() const {return format;} bool getInited() const {return inited;} + int getTextureSystemId() const { return textureSystemId; } + void setTextureSystemId(int id) { textureSystemId = id; } + void setMipmap(bool mipmap) {this->mipmap= mipmap;} void setWrapMode(WrapMode wrapMode) {this->wrapMode= wrapMode;} void setPixmapInit(bool pixmapInit) {this->pixmapInit= pixmapInit;} diff --git a/source/shared_lib/sources/graphics/particle.cpp b/source/shared_lib/sources/graphics/particle.cpp index e21003fc..b93c762b 100644 --- a/source/shared_lib/sources/graphics/particle.cpp +++ b/source/shared_lib/sources/graphics/particle.cpp @@ -22,6 +22,7 @@ #include "platform_common.h" #include "conversion.h" #include "model.h" +#include "texture.h" #include "leak_dumper.h" using namespace std; @@ -56,7 +57,6 @@ void Particle::saveGame(XmlNode *rootNode) { particleNode->addAttribute("size",floatToStr(size), mapTagReplacements); // int energy; particleNode->addAttribute("energy",intToStr(energy), mapTagReplacements); - } void Particle::loadGame(const XmlNode *rootNode) { @@ -86,6 +86,10 @@ ParticleSystem::ParticleSystem(int particleCount) { } //assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false); + textureFileLoadDeferred = ""; + textureFileLoadDeferredSystemId = 0; + textureFileLoadDeferredFormat = Texture::fAuto; + textureFileLoadDeferredComponents = 0; //init particle vector blendMode= bmOne; @@ -256,6 +260,51 @@ void ParticleSystem::setVisible(bool visible){ getChild(i)->setVisible(visible); } +string ParticleSystem::toString() const { + string result = ""; + + result += "particles = " + intToStr(particles.size()); + +// for(unsigned int i = 0; i < particles.size(); ++i) { +// Particle &particle = particles[i]; +// +// } + + result += "\nrandom = " + intToStr(random.getLastNumber()); + + result += "\nblendMode = " + intToStr(blendMode); + result += "\nstate = " + intToStr(state); + result += "\nactive = " + intToStr(active); + result += "\nvisible = " + intToStr(visible); + result += "\naliveParticleCount = " + intToStr(aliveParticleCount); + result += "\nparticleCount = " + intToStr(particleCount); + + result += "\ntextureFileLoadDeferred = " + textureFileLoadDeferred; + result += "\ntextureFileLoadDeferredFormat = " + intToStr(textureFileLoadDeferredFormat); + result += "\ntextureFileLoadDeferredComponents = " + intToStr(textureFileLoadDeferredComponents); + + if(texture != NULL) { + result += "\ntexture = " + texture->getPath(); + } + result += "\npos = " + pos.getString(); + result += "\ncolor = " + color.getString(); + result += "\ncolorNoEnergy = " + colorNoEnergy.getString(); + result += "\nemissionRate = " + floatToStr(emissionRate); + result += "\nemissionState = " + floatToStr(emissionState); + result += "\nmaxParticleEnergy = " + intToStr(maxParticleEnergy); + result += "\nvarParticleEnergy = " + intToStr(varParticleEnergy); + result += "\nparticleSize = " + floatToStr(particleSize); + result += "\nspeed = " + floatToStr(speed); + result += "\nfactionColor = " + factionColor.getString(); + result += "\nteamcolorNoEnergy = " + intToStr(teamcolorNoEnergy); + result += "\nteamcolorEnergy = " + intToStr(teamcolorEnergy); + result += "\nalternations = " + intToStr(alternations); + result += "\nparticleSystemStartDelay = " + intToStr(particleSystemStartDelay); + //ParticleObserver *particleObserver; + + return result; +} + void ParticleSystem::saveGame(XmlNode *rootNode) { std::map mapTagReplacements; XmlNode *particleSystemNode = rootNode->addChild("ParticleSystem"); @@ -284,6 +333,12 @@ void ParticleSystem::saveGame(XmlNode *rootNode) { // Texture *texture; if(texture != NULL) { particleSystemNode->addAttribute("texture",texture->getPath(), mapTagReplacements); + particleSystemNode->addAttribute("textureid",intToStr(texture->getTextureSystemId()), mapTagReplacements); + particleSystemNode->addAttribute("textureFormat",intToStr(texture->getFormat()), mapTagReplacements); + Texture2D *t2d = dynamic_cast(texture); + if(t2d != NULL && t2d->getPixmapConst() != NULL) { + particleSystemNode->addAttribute("textureComponents",intToStr(t2d->getPixmapConst()->getComponents()), mapTagReplacements); + } } // Vec3f pos; particleSystemNode->addAttribute("pos",pos.getString(), mapTagReplacements); @@ -322,23 +377,40 @@ void ParticleSystem::saveGame(XmlNode *rootNode) { string ParticleSystem::getTextureFileLoadDeferred() { return textureFileLoadDeferred; } +int ParticleSystem::getTextureFileLoadDeferredSystemId() { + return textureFileLoadDeferredSystemId; +} +Texture::Format ParticleSystem::getTextureFileLoadDeferredFormat() { + return textureFileLoadDeferredFormat; +} +int ParticleSystem::getTextureFileLoadDeferredComponents() { + return textureFileLoadDeferredComponents; +} void ParticleSystem::loadGame(const XmlNode *rootNode) { const XmlNode *particleSystemNode = rootNode->getChild("ParticleSystem"); + particleCount = particleSystemNode->getAttribute("particleCount")->getIntValue(); + //printf("Load Smoke particle (ParticleSystem)\n"); // std::vector particles; // for(unsigned int i = 0; i < particles.size(); ++i) { // Particle &particle = particles[i]; // particle.saveGame(particleSystemNode); // } - vector 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); - } + particles.clear(); + particles.resize(particleCount); + +// vector particleNodeList = particleSystemNode->getChildList("Particle"); +// for(unsigned int i = 0; i < particleNodeList.size(); ++i) { +// XmlNode *node = particleNodeList[i]; +// +// //printf("Load Smoke particle (Particle = %d)\n",i); +// +// Particle particle; +// particle.loadGame(node); +// particles.push_back(particle); +// } // RandomGen random; random.setLastNumber(particleSystemNode->getAttribute("random")->getIntValue()); @@ -359,6 +431,12 @@ void ParticleSystem::loadGame(const XmlNode *rootNode) { // Texture *texture; if(particleSystemNode->hasAttribute("texture") == true) { textureFileLoadDeferred = particleSystemNode->getAttribute("texture")->getValue(); + textureFileLoadDeferredSystemId = particleSystemNode->getAttribute("textureid")->getIntValue(); + + textureFileLoadDeferredFormat = static_cast(particleSystemNode->getAttribute("textureFormat")->getIntValue()); + if(particleSystemNode->hasAttribute("textureComponents") == true) { + textureFileLoadDeferredComponents = particleSystemNode->getAttribute("textureComponents")->getIntValue(); + } } // Vec3f pos; @@ -389,6 +467,7 @@ void ParticleSystem::loadGame(const XmlNode *rootNode) { alternations = particleSystemNode->getAttribute("alternations")->getIntValue(); // int particleSystemStartDelay; particleSystemStartDelay = particleSystemNode->getAttribute("particleSystemStartDelay")->getIntValue(); + // ParticleObserver *particleObserver; //if(particleObserver != NULL) { // particleObserver->loadGame(particleSystemNode); @@ -397,6 +476,8 @@ void ParticleSystem::loadGame(const XmlNode *rootNode) { // =============== MISC ========================= void ParticleSystem::fade(){ + //printf("**************Fading particle System:\n[%s]\n",this->toString().c_str()); + if(particleObserver != NULL){ if(state != sPlay) { char szBuf[4096]=""; @@ -762,8 +843,9 @@ void GameParticleSystem::saveGame(XmlNode *rootNode) { gameParticleSystemNode->addAttribute("tween",floatToStr(tween), mapTagReplacements); } void GameParticleSystem::loadGame(const XmlNode *rootNode) { - const XmlNode *gameParticleSystemNode = rootNode; + const XmlNode *gameParticleSystemNode = rootNode->getChild("GameParticleSystem"); + //printf("Load Smoke particle (GameParticleSystem)\n"); ParticleSystem::loadGame(gameParticleSystemNode); // Children children; @@ -795,7 +877,7 @@ void GameParticleSystem::loadGame(const XmlNode *rootNode) { //gameParticleSystemNode->addAttribute("modelCycle",floatToStr(modelCycle), mapTagReplacements); modelCycle = gameParticleSystemNode->getAttribute("modelCycle")->getFloatValue(); // Vec3f offset; - offset = Vec3f::strToVec3(gameParticleSystemNode->getAttribute("modelCycle")->getValue()); + offset = Vec3f::strToVec3(gameParticleSystemNode->getAttribute("offset")->getValue()); // Vec3f direction; direction = Vec3f::strToVec3(gameParticleSystemNode->getAttribute("direction")->getValue()); // float tween; @@ -1128,6 +1210,7 @@ void UnitParticleSystem::saveGame(XmlNode *rootNode) { void UnitParticleSystem::loadGame(const XmlNode *rootNode) { const XmlNode *unitParticleSystemNode = rootNode; + //printf("Load Smoke particle (UnitParticleSystem)\n"); GameParticleSystem::loadGame(unitParticleSystemNode); // float radius; @@ -1181,6 +1264,7 @@ void UnitParticleSystem::loadGame(const XmlNode *rootNode) { // float emissionRateFade; emissionRateFade = unitParticleSystemNode->getAttribute("emissionRateFade")->getFloatValue(); // GameParticleSystem* parent; + parent = NULL; //if(parent != NULL) { // parent->saveGame(unitParticleSystemNode); //} @@ -1189,7 +1273,7 @@ void UnitParticleSystem::loadGame(const XmlNode *rootNode) { // void GameParticleSystem::saveGame(XmlNode *rootNode) // std::map mapTagReplacements; // XmlNode *gameParticleSystemNode = rootNode->addChild("GameParticleSystem"); - XmlNode *gameParticleSystemNode = unitParticleSystemNode->getChild("GameParticleSystem"); + //XmlNode *gameParticleSystemNode = unitParticleSystemNode->getChild("GameParticleSystem"); //!!! //} } diff --git a/source/shared_lib/sources/graphics/texture.cpp b/source/shared_lib/sources/graphics/texture.cpp index 1922a744..bd01f0ba 100644 --- a/source/shared_lib/sources/graphics/texture.cpp +++ b/source/shared_lib/sources/graphics/texture.cpp @@ -43,6 +43,7 @@ Texture::Texture() { pixmapInit= true; wrapMode= wmRepeat; format= fAuto; + textureSystemId = 0; inited= false; forceCompressionDisabled=false;