Permalink
Browse files

render the objects only in the scheduled time window, set up run leng…

…th of videocells
  • Loading branch information...
1 parent 63dbae7 commit 5b5ebb0f0f623757276464082b272b3640bc5d64 @AvengerTeamBG AvengerTeamBG committed Aug 3, 2013
Showing with 31 additions and 7 deletions.
  1. +26 −5 gemrb/core/VEFObject.cpp
  2. +5 −2 gemrb/core/VEFObject.h
View
@@ -24,6 +24,7 @@
#include "win32def.h"
+#include "Game.h"
#include "GameData.h"
#include "Interface.h"
#include "ScriptedAnimation.h"
@@ -53,19 +54,29 @@ void VEFObject::Init()
}
}
-void VEFObject::AddEntry(ieResRef res, ieDword st, ieDword len, Point pos, ieDword type)
+void VEFObject::AddEntry(ieResRef res, ieDword st, ieDword len, Point pos, ieDword type, ieDword gtime)
{
ScheduleEntry entry;
memcpy(entry.resourceName, res, sizeof(ieResRef) );
- entry.start = st;
+ entry.start = gtime+st;
+ if (len!=0xffffffff) len+=entry.start;
entry.length = len;
entry.offset = pos;
entry.type = type;
entry.ptr = NULL;
entries.push_back(entry);
}
+ScriptedAnimation *VEFObject::CreateCell(ieResRef res, ieDword start, ieDword end)
+{
+ ScriptedAnimation *sca = gamedata->GetScriptedAnimation( res, false);
+ if (sca && end!=0xffffffff) {
+ sca->SetDefaultDuration(AI_UPDATE_TIME*(end-start) );
+ }
+ return sca;
+}
+
VEFObject *VEFObject::CreateObject(ieResRef res, SClass_ID id)
{
if (gamedata->Exists( res, id, true) ) {
@@ -87,10 +98,15 @@ bool VEFObject::Draw(const Region &screen, Point &position, const Color &p_tint,
bool ret = true;
if (!area) return true; //end immediately
+ ieDword GameTime = core->GetGame()->GameTime;
std::list<ScheduleEntry>::iterator iter;
for(iter=entries.begin();iter!=entries.end();iter++) {
+ //don't render the animation if it is outside of the cycle
+ if ( (*iter).start>GameTime) continue;
+ if ( (*iter).length<GameTime) continue;
+
Point pos = ((*iter).offset);
pos.x+=position.x;
pos.y+=position.y;
@@ -108,7 +124,7 @@ bool VEFObject::Draw(const Region &screen, Point &position, const Color &p_tint,
//fall back to BAM or VVC
case VEF_BAM: //just a BAM
case VEF_VVC: //videocell (can contain a BAM)
- (*iter).ptr = gamedata->GetScriptedAnimation( (*iter).resourceName, false);
+ (*iter).ptr = CreateCell( (*iter).resourceName, (*iter).length, (*iter).start);
break;
default:;
}
@@ -129,6 +145,9 @@ bool VEFObject::Draw(const Region &screen, Point &position, const Color &p_tint,
default:
tmp = true; //unknown/invalid type
}
+ if (tmp) {
+ (*iter).length = 0; //stop playing this if reached end
+ }
ret &= tmp;
}
return ret;
@@ -142,6 +161,7 @@ void VEFObject::Load2DA(ieResRef resource)
if (!tab) {
return;
}
+ ieDword GameTime = core->GetGame()->GameTime;
int rows = tab->GetRowCount();
while(rows--) {
Point offset;
@@ -153,7 +173,7 @@ void VEFObject::Load2DA(ieResRef resource)
delay = atoi(tab->QueryField(rows,3));
duration = atoi(tab->QueryField(rows,4));
strnuprcpy(resource, tab->QueryField(rows,2), 8);
- AddEntry(resource, delay, duration, offset, VEF_VVC);
+ AddEntry(resource, delay, duration, offset, VEF_VVC, GameTime);
}
}
@@ -178,7 +198,8 @@ void VEFObject::ReadEntry(DataStream *stream)
stream->Seek( 49*4, GEM_CURRENT_POS); //skip empty fields
if (continuous) length = -1;
- AddEntry(resource, start, length, position, type);
+ ieDword GameTime = core->GetGame()->GameTime;
+ AddEntry(resource, start, length, position, type, GameTime);
}
void VEFObject::LoadVEF(DataStream *stream)
View
@@ -31,6 +31,7 @@ namespace GemRB {
class DataStream;
class Map;
+class ScriptedAnimation;
typedef enum VEF_TYPES {VEF_INVALID=-1, VEF_BAM=0, VEF_VVC, VEF_VEF, VEF_2DA} VEF_TYPES;
@@ -48,16 +49,18 @@ class GEM_EXPORT VEFObject {
std::list<ScheduleEntry> entries;
public:
//adds a new entry (use when loading)
- void AddEntry(ieResRef res, ieDword st, ieDword len, Point pos, ieDword type);
+ void AddEntry(ieResRef res, ieDword st, ieDword len, Point pos, ieDword type, ieDword gtime);
//renders the object
bool Draw(const Region &screen, Point &position, const Color &p_tint, Map *area, int dither, int orientation, int height);
void Load2DA(ieResRef resource);
void LoadVEF(DataStream *stream);
private:
//clears the schedule, used internally
void Init();
- //load a resource into the object
+ //load a 2DA/VEF resource into the object
VEFObject *CreateObject(ieResRef res, SClass_ID id);
+ //load a BAM/VVC resource into the object
+ ScriptedAnimation *CreateCell(ieResRef res, ieDword start, ieDword end);
//load a single entry from stream
void ReadEntry(DataStream *stream);
};

0 comments on commit 5b5ebb0

Please sign in to comment.