Permalink
Browse files

Move feature animation to his own function in CustomAnimator

Also implement ANIM_FLAG_NOT_REPEAT to make us able to make one-way animation
  • Loading branch information...
1 parent 4ae8724 commit d8e0469e18796b496fcc7c78f5e334a5f2258796 @MartinUbl MartinUbl committed Apr 4, 2012
Showing with 46 additions and 27 deletions.
  1. +1 −0 include/Display/Display.h
  2. +4 −0 include/Display/Effects/Animations.h
  3. +3 −26 src/Display/Display.cpp
  4. +38 −1 src/Display/Effects/Animations.cpp
@@ -156,6 +156,7 @@ struct ModelDisplayListRecord: public DisplayListRecord
uint32 modelId;
uint32 AnimTicket;
+ uint32 CustomFrame;
float scale, rotate;
FeatureList features;
@@ -17,6 +17,7 @@ enum AnimFlags
{
ANIM_FLAG_BOTHWAY = 0x01,
ANIM_FLAG_FORCE_LOADING = 0x02,
+ ANIM_FLAG_NOT_REPEAT = 0x04,
};
struct AnimationRecord
@@ -27,6 +28,7 @@ struct AnimationRecord
uint8 animType;
uint32 frameSkipSpeed;
bool bothWay; // dovoluje animovat nejdriv k nejvyssimu a pak k nejnizsimu framu
+ uint8 animFlags;
// Dynamicka data
uint32 nextFrameTime;
@@ -80,6 +82,8 @@ class CustomAnimator
void AnimateModelObjectByFrame(t3DObject *object, uint32 modelId, uint32 frame);
void AnimateModelObjectByFrame(t3DObject *object, t3DModel* model, uint32 modelId, uint32 frame);
void AnimateModelObjectByFrame(t3DObject *object, t3DModel* model, uint32 modelId, uint32 frame, ModelAnimType anim);
+
+ void AnimateModelFeatures(ModelDisplayListRecord* record);
};
#define sCustomAnimator Singleton<CustomAnimator>::instance()
View
@@ -225,6 +225,8 @@ ModelDisplayListRecord* Display::DrawModel(uint32 modelId, float x, float y, flo
else
pNew->AnimTicket = 0;
+ pNew->CustomFrame = 0;
+
pNew->animRestriction = animRest;
pNew->remove = false;
@@ -361,32 +363,7 @@ void Display::DrawModels()
y = temp->y;
z = temp->z;
- if (!temp->features.empty())
- {
- for (FeatureList::iterator itr = temp->features.begin(); itr != temp->features.end(); ++itr)
- {
- switch ((*itr)->type)
- {
- case MF_TYPE_MODEL:
- (*itr)->ToModel()->x = x + ((*itr)->offset_x * MODEL_SCALE * temp->scale * pModel->customScale[sAnimator->GetActualFrame(temp->AnimTicket)]);
- (*itr)->ToModel()->y = y + ((*itr)->offset_y * MODEL_SCALE * temp->scale * pModel->customScale[sAnimator->GetActualFrame(temp->AnimTicket)]);
- (*itr)->ToModel()->z = z + ((*itr)->offset_z * MODEL_SCALE * temp->scale * pModel->customScale[sAnimator->GetActualFrame(temp->AnimTicket)]);
- break;
- case MF_TYPE_BILLBOARD:
- (*itr)->ToBillboard()->x = x + ((*itr)->offset_x * MODEL_SCALE * temp->scale * pModel->customScale[sAnimator->GetActualFrame(temp->AnimTicket)]);
- (*itr)->ToBillboard()->y = y + ((*itr)->offset_y * MODEL_SCALE * temp->scale * pModel->customScale[sAnimator->GetActualFrame(temp->AnimTicket)]);
- (*itr)->ToBillboard()->z = z + ((*itr)->offset_z * MODEL_SCALE * temp->scale * pModel->customScale[sAnimator->GetActualFrame(temp->AnimTicket)]);
- break;
- case MF_TYPE_EMITTER:
- (*itr)->ToEmitter()->m_centerX = x + ((*itr)->offset_x * MODEL_SCALE * temp->scale * pModel->customScale[sAnimator->GetActualFrame(temp->AnimTicket)]);
- (*itr)->ToEmitter()->m_centerY = y + ((*itr)->offset_y * MODEL_SCALE * temp->scale * pModel->customScale[sAnimator->GetActualFrame(temp->AnimTicket)]);
- (*itr)->ToEmitter()->m_centerZ = z + ((*itr)->offset_z * MODEL_SCALE * temp->scale * pModel->customScale[sAnimator->GetActualFrame(temp->AnimTicket)]);
- break;
- default:
- break;
- }
- }
- }
+ sCustomAnimator->AnimateModelFeatures(temp);
//if (pythagoras_c(fabs(fabs(x)-fabs(view_x)),fabs(fabs(z)-fabs(view_z))) > 2.0f)
//{
@@ -118,7 +118,7 @@ void Animator::Update()
}
// Pokud jsme na poslednim framu animace, opakujeme
- if (!temp->reversed && sStorage->ModelAnimation[temp->sourceId].Anim[temp->animId].frameLast <= temp->actualFrame)
+ if (!temp->reversed && !(temp->animFlags & ANIM_FLAG_NOT_REPEAT) && sStorage->ModelAnimation[temp->sourceId].Anim[temp->animId].frameLast <= temp->actualFrame)
{
if (temp->bothWay)
{
@@ -276,6 +276,7 @@ uint32 Animator::GetModelAnimTicket(uint32 modelId, uint32 animId, uint32 frameS
temp->nextFrameTime = clock();
temp->frameSkipSpeed = (frameSkipSpeed > 0) ? frameSkipSpeed : 1;
temp->bothWay = (flags & ANIM_FLAG_BOTHWAY);
+ temp->animFlags = flags;
return pos;
}
@@ -600,3 +601,39 @@ void CustomAnimator::AnimateModelObjectByFrame(t3DObject *object, t3DModel* mode
}
}
}
+
+void CustomAnimator::AnimateModelFeatures(ModelDisplayListRecord *record)
+{
+ if (!record || record->features.empty())
+ return;
+
+ t3DModel* pModel = sStorage->Models[record->modelId];
+
+ if (!pModel)
+ return;
+
+ // Posunuti vsech model featur podle nadrazeneho modelu
+ for (FeatureList::iterator itr = record->features.begin(); itr != record->features.end(); ++itr)
+ {
+ switch ((*itr)->type)
+ {
+ case MF_TYPE_MODEL:
+ (*itr)->ToModel()->x = record->x + ((*itr)->offset_x * MODEL_SCALE * record->scale * pModel->customScale[sAnimator->GetActualFrame(record->AnimTicket)]);
+ (*itr)->ToModel()->y = record->y + ((*itr)->offset_y * MODEL_SCALE * record->scale * pModel->customScale[sAnimator->GetActualFrame(record->AnimTicket)]);
+ (*itr)->ToModel()->z = record->z + ((*itr)->offset_z * MODEL_SCALE * record->scale * pModel->customScale[sAnimator->GetActualFrame(record->AnimTicket)]);
+ break;
+ case MF_TYPE_BILLBOARD:
+ (*itr)->ToBillboard()->x = record->x + ((*itr)->offset_x * MODEL_SCALE * record->scale * pModel->customScale[sAnimator->GetActualFrame(record->AnimTicket)]);
+ (*itr)->ToBillboard()->y = record->y + ((*itr)->offset_y * MODEL_SCALE * record->scale * pModel->customScale[sAnimator->GetActualFrame(record->AnimTicket)]);
+ (*itr)->ToBillboard()->z = record->z + ((*itr)->offset_z * MODEL_SCALE * record->scale * pModel->customScale[sAnimator->GetActualFrame(record->AnimTicket)]);
+ break;
+ case MF_TYPE_EMITTER:
+ (*itr)->ToEmitter()->m_centerX = record->x + ((*itr)->offset_x * MODEL_SCALE * record->scale * pModel->customScale[sAnimator->GetActualFrame(record->AnimTicket)]);
+ (*itr)->ToEmitter()->m_centerY = record->y + ((*itr)->offset_y * MODEL_SCALE * record->scale * pModel->customScale[sAnimator->GetActualFrame(record->AnimTicket)]);
+ (*itr)->ToEmitter()->m_centerZ = record->z + ((*itr)->offset_z * MODEL_SCALE * record->scale * pModel->customScale[sAnimator->GetActualFrame(record->AnimTicket)]);
+ break;
+ default:
+ break;
+ }
+ }
+}

0 comments on commit d8e0469

Please sign in to comment.