From 163271203d1b3cd7caf43b5f050372417d8d1445 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Mon, 26 Mar 2012 23:24:29 +0000 Subject: [PATCH] - tilesets now support animated models: --- source/glest_game/graphics/renderer.cpp | 5 +++- source/glest_game/type_instances/object.cpp | 28 ++++++++++++++++++- source/glest_game/type_instances/object.h | 4 +++ .../glest_game/types/tileset_model_type.cpp | 8 ++++++ source/glest_game/types/tileset_model_type.h | 14 ++++++---- source/glest_game/world/tileset.cpp | 5 ++++ source/glest_game/world/world.cpp | 17 +++++++++++ source/glest_game/world/world.h | 1 + 8 files changed, 74 insertions(+), 8 deletions(-) diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index f3c0c528..d8c93ac6 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -4252,6 +4252,7 @@ void Renderer::renderObjects(const int renderFps) { Object *o = qCache.visibleObjectList[visibleIndex]; Model *objModel= o->getModelPtr(); + //objModel->updateInterpolationData(o->getAnimProgress(), true); const Vec3f &v= o->getConstPos(); if(modelRenderStarted == false) { @@ -4289,7 +4290,8 @@ void Renderer::renderObjects(const int renderFps) { glTranslatef(v.x, v.y, v.z); glRotatef(o->getRotation(), 0.f, 1.f, 0.f); - objModel->updateInterpolationData(0.f, true); + //objModel->updateInterpolationData(0.f, true); + objModel->updateInterpolationData(o->getAnimProgress(), true); modelRenderer->render(objModel); triangleCount+= objModel->getTriangleCount(); @@ -6739,6 +6741,7 @@ vector Renderer::renderObjectsFast(bool renderingShadows, bool resour if(resourceOnly == false || o->getResource()!= NULL) { Model *objModel= o->getModelPtr(); + objModel->updateInterpolationData(o->getAnimProgress(), true); const Vec3f &v= o->getConstPos(); if(colorPickingSelection == false) { diff --git a/source/glest_game/type_instances/object.cpp b/source/glest_game/type_instances/object.cpp index f0e5d87a..a8c25df4 100644 --- a/source/glest_game/type_instances/object.cpp +++ b/source/glest_game/type_instances/object.cpp @@ -51,7 +51,7 @@ Object::Object(ObjectType *objectType, const Vec3f &pos, const Vec2i &mapPos) : } } visible=false; - + animProgress=0.0f; } Object::~Object() { @@ -122,6 +122,32 @@ void Object::setHeight(float height) { } } +void Object::update() { + if(objectType != NULL && objectType->getTilesetModelType(variation) != NULL && + objectType->getTilesetModelType(variation)->getAnimSpeed() != 0.0) { +// printf("#1 Object updating [%s] Speed [%d] animProgress [%f]\n",this->objectType->getTilesetModelType(variation)->getModel()->getFileName().c_str(),objectType->getTilesetModelType(variation)->getAnimSpeed(),animProgress); + + float heightFactor = 1.f; + const float speedDivider= 100.f; + float speedDenominator = (speedDivider * GameConstants::updateFps); + float newAnimProgress = animProgress + (((float)objectType->getTilesetModelType(variation)->getAnimSpeed() * heightFactor) / speedDenominator); + +// printf("A [%f] B [%f] C [%f] D [%f] E [%f] F [%f]\n", +// ((float)objectType->getTilesetModelType(variation)->getAnimSpeed() * heightFactor), +// speedDenominator, +// ((objectType->getTilesetModelType(variation)->getAnimSpeed() * heightFactor) / speedDenominator), +// (animProgress + ((objectType->getTilesetModelType(variation)->getAnimSpeed() * heightFactor) / speedDenominator)), +// animProgress,newAnimProgress); + + animProgress = newAnimProgress; +// printf("#2 new animProgress [%f]\n",animProgress); + + if(animProgress > 1.f) { + animProgress = 0.f; + } + } +} + Model *Object::getModelPtr() const { Model* result = NULL; if(objectType==NULL) { diff --git a/source/glest_game/type_instances/object.h b/source/glest_game/type_instances/object.h index 30d8ea2f..b02535f3 100644 --- a/source/glest_game/type_instances/object.h +++ b/source/glest_game/type_instances/object.h @@ -57,6 +57,7 @@ private: int lastRenderFrame; Vec2i mapPos; bool visible; + float animProgress; static ObjectStateInterface *stateCallback; @@ -88,6 +89,9 @@ public: const Vec2i & getMapPos() const { return mapPos; } + void update(); + float getAnimProgress() const { return animProgress;} + virtual string getUniquePickName() const; void saveGame(XmlNode *rootNode); void loadGame(const XmlNode *rootNode,const TechTree *techTree); diff --git a/source/glest_game/types/tileset_model_type.cpp b/source/glest_game/types/tileset_model_type.cpp index 1d7e4850..df213410 100644 --- a/source/glest_game/types/tileset_model_type.cpp +++ b/source/glest_game/types/tileset_model_type.cpp @@ -18,6 +18,14 @@ namespace Glest{ namespace Game{ // class TilesetModelType // ===================================================== +TilesetModelType::TilesetModelType() { + model = NULL; + height = 0; + rotationAllowed = false; + + animSpeed = 0; +} + TilesetModelType::~TilesetModelType(){ while(!(particleTypes.empty())){ delete particleTypes.back(); diff --git a/source/glest_game/types/tileset_model_type.h b/source/glest_game/types/tileset_model_type.h index 91fd2787..7bc9a9b7 100644 --- a/source/glest_game/types/tileset_model_type.h +++ b/source/glest_game/types/tileset_model_type.h @@ -40,16 +40,14 @@ private: int height; bool rotationAllowed; + int animSpeed; + public: - TilesetModelType() { - model = NULL; - height = 0; - rotationAllowed = false; - } + TilesetModelType(); ~TilesetModelType(); void addParticleSystem(ObjectParticleSystemType *particleSystem); - bool hasParticles() const {return !particleTypes.empty();} + bool hasParticles() const {return particleTypes.empty() == false;} ModelParticleSystemTypes* getParticleTypes() { return &particleTypes ;} @@ -58,8 +56,12 @@ public: int getHeight() const {return height;} void setHeight(int height) {this->height=height;} + bool getRotationAllowed() const {return rotationAllowed;} void setRotationAllowed(bool rotationAllowed) {this->rotationAllowed=rotationAllowed;} + + int getAnimSpeed() const {return animSpeed;} + void setAnimSpeed(int value) {animSpeed = value;} }; }}//end namespace diff --git a/source/glest_game/world/tileset.cpp b/source/glest_game/world/tileset.cpp index 8caf7d77..da4515c0 100644 --- a/source/glest_game/world/tileset.cpp +++ b/source/glest_game/world/tileset.cpp @@ -231,6 +231,11 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck TilesetModelType* tmt=objectTypes[i].loadModel(pathAttribute->getRestrictedValue(currentPath),&loadedFileList, sourceXMLFile); loadedFileList[pathAttribute->getRestrictedValue(currentPath)].push_back(make_pair(sourceXMLFile,pathAttribute->getRestrictedValue())); + if(modelNode->hasAttribute("anim-speed") == true) { + int animSpeed= modelNode->getAttribute("anim-speed")->getIntValue(); + tmt->setAnimSpeed(animSpeed); + } + if(modelNode->hasChild("particles")){ const XmlNode *particleNode= modelNode->getChild("particles"); bool particleEnabled= particleNode->getAttribute("value")->getBoolValue(); diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index 0fb99c10..8a2b5899 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -355,6 +355,20 @@ void World::setQueuedScenario(string scenarioName,bool keepFactions) { queuedScenarioKeepFactions = keepFactions; } +void World::updateAllTilesetObjects() { + for(int x = 0; x < map.getSurfaceW(); ++x) { + for(int y = 0; y < map.getSurfaceH(); ++y) { + SurfaceCell *sc = map.getSurfaceCell(x,y); + if(sc != NULL) { + Object *obj = sc->getObject(); + if(obj != NULL) { + obj->update(); + } + } + } + } +} + void World::updateAllFactionUnits() { scriptManager->onTimerTriggerEvent(); @@ -512,6 +526,9 @@ void World::update(){ //if(needToUpdateUnits == true) { // SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] needToUpdateUnits = %d, frameCount = %d\n",__FILE__,__FUNCTION__,__LINE__,needToUpdateUnits,frameCount); + // objects on the map from tilesets + updateAllTilesetObjects(); + //units updateAllFactionUnits(); diff --git a/source/glest_game/world/world.h b/source/glest_game/world/world.h index c1ca7602..4d6cfad7 100644 --- a/source/glest_game/world/world.h +++ b/source/glest_game/world/world.h @@ -289,6 +289,7 @@ private: int tickFactionIndex(); void computeFow(int factionIdxToTick=-1); + void updateAllTilesetObjects(); void updateAllFactionUnits(); void underTakeDeadFactionUnits(); void updateAllFactionConsumableCosts();