- tilesets now support animated models:

<model path="models/copter_sit.g3d" anim-speed="190"/>
This commit is contained in:
Mark Vejvoda 2012-03-26 23:24:29 +00:00
parent 4d8fdca765
commit 163271203d
8 changed files with 74 additions and 8 deletions

View File

@ -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<Object *> 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) {

View File

@ -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) {

View File

@ -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);

View File

@ -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();

View File

@ -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

View File

@ -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();

View File

@ -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();

View File

@ -289,6 +289,7 @@ private:
int tickFactionIndex();
void computeFow(int factionIdxToTick=-1);
void updateAllTilesetObjects();
void updateAllFactionUnits();
void underTakeDeadFactionUnits();
void updateAllFactionConsumableCosts();