Skip to content

Commit

Permalink
implemented vef object (mostly)
Browse files Browse the repository at this point in the history
  • Loading branch information
Avenger committed Aug 4, 2013
1 parent 2f6f743 commit 6a16baf
Show file tree
Hide file tree
Showing 11 changed files with 225 additions and 41 deletions.
24 changes: 24 additions & 0 deletions gemrb/core/GameData.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "Spell.h" #include "Spell.h"
#include "SpellMgr.h" #include "SpellMgr.h"
#include "StoreMgr.h" #include "StoreMgr.h"
#include "VEFObject.h"
#include "Scriptable/Actor.h" #include "Scriptable/Actor.h"
#include "System/FileStream.h" #include "System/FileStream.h"


Expand Down Expand Up @@ -431,6 +432,29 @@ ScriptedAnimation* GameData::GetScriptedAnimation( const char *effect, bool doub
return ret; return ret;
} }


VEFObject* GameData::GetVEFObject(const char *effect, bool doublehint)
{
VEFObject *ret = NULL;

if (Exists( effect, IE_VEF_CLASS_ID, true ) ) {
DataStream *ds = GetResource( effect, IE_VEF_CLASS_ID );
ret = new VEFObject();
strnlwrcpy(ret->ResName, effect, 8);
ret->LoadVEF(ds);
} else {
if (Exists( effect, IE_2DA_CLASS_ID, true ) ) {
ret = new VEFObject();
ret->Load2DA(effect);
} else {
ScriptedAnimation *sca = GetScriptedAnimation(effect, doublehint);
if (sca) {
ret = new VEFObject(sca);
}
}
}
return ret;
}

// Return single BAM frame as a sprite. Use if you want one frame only, // Return single BAM frame as a sprite. Use if you want one frame only,
// otherwise it's not efficient // otherwise it's not efficient
Sprite2D* GameData::GetBAMSprite(const ieResRef ResRef, int cycle, int frame, bool silent) Sprite2D* GameData::GetBAMSprite(const ieResRef ResRef, int cycle, int frame, bool silent)
Expand Down
6 changes: 5 additions & 1 deletion gemrb/core/GameData.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ class Palette;
class ScriptedAnimation; class ScriptedAnimation;
class Spell; class Spell;
class Sprite2D; class Sprite2D;
class TableMgr;
class Store; class Store;
class TableMgr;
class VEFObject;


struct Table { struct Table {
Holder<TableMgr> tm; Holder<TableMgr> tm;
Expand Down Expand Up @@ -95,6 +96,9 @@ class GEM_EXPORT GameData : public ResourceManager
/** creates a vvc/bam animation object at point */ /** creates a vvc/bam animation object at point */
ScriptedAnimation* GetScriptedAnimation( const char *ResRef, bool doublehint); ScriptedAnimation* GetScriptedAnimation( const char *ResRef, bool doublehint);


/** creates a composite vef/2da animation */
VEFObject* GetVEFObject( const char *ResRef, bool doublehint);

/** returns a single sprite (not cached) from a BAM resource */ /** returns a single sprite (not cached) from a BAM resource */
Sprite2D* GetBAMSprite(const ieResRef ResRef, int cycle, int frame, bool silent=false); Sprite2D* GetBAMSprite(const ieResRef ResRef, int cycle, int frame, bool silent=false);


Expand Down
3 changes: 2 additions & 1 deletion gemrb/core/GameScript/GSUtils.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "StringMgr.h" #include "StringMgr.h"
#include "TableMgr.h" #include "TableMgr.h"
#include "TileMap.h" #include "TileMap.h"
#include "VEFObject.h"
#include "Video.h" #include "Video.h"
#include "WorldMap.h" #include "WorldMap.h"
#include "GUI/GameControl.h" #include "GUI/GameControl.h"
Expand Down Expand Up @@ -806,7 +807,7 @@ void CreateVisualEffectCore(Scriptable *Sender, const Point &position, const cha
if (vvc) { if (vvc) {
vvc->XPos +=position.x; vvc->XPos +=position.x;
vvc->YPos +=position.y; vvc->YPos +=position.y;
Sender->GetCurrentArea( )->AddVVCell( vvc ); Sender->GetCurrentArea( )->AddVVCell( new VEFObject(vvc) );
} }
} }


Expand Down
9 changes: 8 additions & 1 deletion gemrb/core/Interface.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
#include "StringMgr.h" #include "StringMgr.h"
#include "SymbolMgr.h" #include "SymbolMgr.h"
#include "TileMap.h" #include "TileMap.h"
#include "VEFObject.h"
#include "Video.h" #include "Video.h"
#include "WindowMgr.h" #include "WindowMgr.h"
#include "WorldMapMgr.h" #include "WorldMapMgr.h"
Expand Down Expand Up @@ -2252,6 +2253,9 @@ const char* Interface::TypeExt(SClass_ID type) const
case IE_VAR_CLASS_ID: case IE_VAR_CLASS_ID:
return "var"; return "var";


case IE_VEF_CLASS_ID:
return "vef";

case IE_VVC_CLASS_ID: case IE_VVC_CLASS_ID:
return "vvc"; return "vvc";


Expand All @@ -2266,6 +2270,9 @@ const char* Interface::TypeExt(SClass_ID type) const


case IE_WMP_CLASS_ID: case IE_WMP_CLASS_ID:
return "wmp"; return "wmp";

default:
Log(ERROR, "Interface", "No extension associated to class ID: %lu", (unsigned long) type );
} }
return NULL; return NULL;
} }
Expand Down Expand Up @@ -2769,7 +2776,7 @@ Actor *Interface::SummonCreature(const ieResRef resource, const ieResRef vvcres,
vvc->YPos=ab->Pos.y; vvc->YPos=ab->Pos.y;
//force vvc to play only once //force vvc to play only once
vvc->PlayOnce(); vvc->PlayOnce();
map->AddVVCell( vvc ); map->AddVVCell( new VEFObject(vvc) );


//set up the summon disable effect //set up the summon disable effect
Effect *newfx = EffectQueue::CreateEffect(fx_summon_disable_ref, 0, 1, FX_DURATION_ABSOLUTE); Effect *newfx = EffectQueue::CreateEffect(fx_summon_disable_ref, 0, 1, FX_DURATION_ABSOLUTE);
Expand Down
30 changes: 19 additions & 11 deletions gemrb/core/Map.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "SaveGameIterator.h" #include "SaveGameIterator.h"
#include "ScriptedAnimation.h" #include "ScriptedAnimation.h"
#include "TileMap.h" #include "TileMap.h"
#include "VEFObject.h"
#include "Video.h" #include "Video.h"
#include "WorldMap.h" #include "WorldMap.h"
#include "strrefs.h" #include "strrefs.h"
Expand Down Expand Up @@ -105,7 +106,7 @@ void Map::ReleaseMemory()
} }
} }


static inline AnimationObjectType SelectObject(Actor *actor, int q, AreaAnimation *a, ScriptedAnimation *sca, Particles *spark, Projectile *pro, Container *pile) static inline AnimationObjectType SelectObject(Actor *actor, int q, AreaAnimation *a, VEFObject *sca, Particles *spark, Projectile *pro, Container *pile)
{ {
int actorh; int actorh;
if (actor) { if (actor) {
Expand Down Expand Up @@ -632,10 +633,12 @@ void Map::DrawPortal(InfoPoint *ip, int enable)
if (sca) { if (sca) {
sca->SetBlend(); sca->SetBlend();
sca->PlayOnce(); sca->PlayOnce();
sca->XPos=ip->Pos.x; //exact position, because HasVVCCell depends on the coordinates, PST had no coordinate offset anyway
sca->YPos=ip->Pos.y; sca->XPos = ip->Pos.x;
sca->ZPos=gotportal; sca->YPos = ip->Pos.y;
AddVVCell(sca); //this is actually ordered by time, not by height
sca->ZPos = gotportal;
AddVVCell( new VEFObject(sca));
} }
return; return;
} }
Expand Down Expand Up @@ -1101,7 +1104,7 @@ ieDword Map::GetTrapCount(proIterator &iter)




//doesn't increase iterator, because we might need to erase it from the list //doesn't increase iterator, because we might need to erase it from the list
ScriptedAnimation *Map::GetNextScriptedAnimation(scaIterator &iter) VEFObject *Map::GetNextScriptedAnimation(scaIterator &iter)
{ {
if (iter==vvcCells.end()) { if (iter==vvcCells.end()) {
return NULL; return NULL;
Expand Down Expand Up @@ -1172,7 +1175,7 @@ void Map::DrawMap(Region screen)
Container *pile = GetNextPile(pileidx); Container *pile = GetNextPile(pileidx);


AreaAnimation *a = GetNextAreaAnimation(aniidx, gametime); AreaAnimation *a = GetNextAreaAnimation(aniidx, gametime);
ScriptedAnimation *sca = GetNextScriptedAnimation(scaidx); VEFObject *sca = GetNextScriptedAnimation(scaidx);
Projectile *pro = GetNextProjectile(proidx); Projectile *pro = GetNextProjectile(proidx);
Particles *spark = GetNextSpark(spaidx); Particles *spark = GetNextSpark(spaidx);


Expand Down Expand Up @@ -2162,16 +2165,21 @@ ieDword Map::HasVVCCell(const ieResRef resource, const Point &p)
if ((*iter)->YPos!=p.y) continue; if ((*iter)->YPos!=p.y) continue;
} }
if (strnicmp(resource, (*iter)->ResName, sizeof(ieResRef) )) continue; if (strnicmp(resource, (*iter)->ResName, sizeof(ieResRef) )) continue;
ieDword tmp = (*iter)->GetSequenceDuration(AI_UPDATE_TIME)-(*iter)->GetCurrentFrame(); ScriptedAnimation *sca = (*iter)->GetSingleObject();
if (tmp>ret) { if (sca) {
ret = tmp; ieDword tmp = sca->GetSequenceDuration(AI_UPDATE_TIME)-sca->GetCurrentFrame();
if (tmp>ret) {
ret = tmp;
}
} else {
ret = 1;
} }
} }
return ret; return ret;
} }


//adding videocell in order, based on its height parameter //adding videocell in order, based on its height parameter
void Map::AddVVCell(ScriptedAnimation* vvc) void Map::AddVVCell(VEFObject* vvc)
{ {
scaIterator iter; scaIterator iter;


Expand Down
9 changes: 5 additions & 4 deletions gemrb/core/Map.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Projectile;
class ScriptedAnimation; class ScriptedAnimation;
class SpriteCover; class SpriteCover;
class TileMap; class TileMap;
class VEFObject;
class Wall_Polygon; class Wall_Polygon;


//distance of actors from spawn point //distance of actors from spawn point
Expand Down Expand Up @@ -241,7 +242,7 @@ enum AnimationObjectType {AOT_AREA, AOT_SCRIPTED, AOT_ACTOR, AOT_SPARK, AOT_PROJ
#define PR_IGNORE 2 #define PR_IGNORE 2


typedef std::list<AreaAnimation*>::iterator aniIterator; typedef std::list<AreaAnimation*>::iterator aniIterator;
typedef std::list<ScriptedAnimation*>::iterator scaIterator; typedef std::list<VEFObject*>::iterator scaIterator;
typedef std::list<Projectile*>::iterator proIterator; typedef std::list<Projectile*>::iterator proIterator;
typedef std::list<Particles*>::iterator spaIterator; typedef std::list<Particles*>::iterator spaIterator;


Expand Down Expand Up @@ -280,7 +281,7 @@ class GEM_EXPORT Map : public Scriptable {
std::vector< Actor*> actors; std::vector< Actor*> actors;
Wall_Polygon **Walls; Wall_Polygon **Walls;
unsigned int WallCount; unsigned int WallCount;
std::list< ScriptedAnimation*> vvcCells; std::list< VEFObject*> vvcCells;
std::list< Projectile*> projectiles; std::list< Projectile*> projectiles;
std::list< Particles*> particles; std::list< Particles*> particles;
std::vector< Entrance*> entrances; std::vector< Entrance*> entrances;
Expand Down Expand Up @@ -397,7 +398,7 @@ class GEM_EXPORT Map : public Scriptable {


//returns the duration of a VVC cell set in the area (point may be set to empty) //returns the duration of a VVC cell set in the area (point may be set to empty)
ieDword HasVVCCell(const ieResRef resource, const Point &p); ieDword HasVVCCell(const ieResRef resource, const Point &p);
void AddVVCell(ScriptedAnimation* vvc); void AddVVCell(VEFObject* vvc);
bool CanFree(); bool CanFree();
int GetCursor( const Point &p); int GetCursor( const Point &p);
//adds a sparkle puff of colour to a point in the area //adds a sparkle puff of colour to a point in the area
Expand Down Expand Up @@ -508,7 +509,7 @@ class GEM_EXPORT Map : public Scriptable {
private: private:
AreaAnimation *GetNextAreaAnimation(aniIterator &iter, ieDword gametime); AreaAnimation *GetNextAreaAnimation(aniIterator &iter, ieDword gametime);
Particles *GetNextSpark(spaIterator &iter); Particles *GetNextSpark(spaIterator &iter);
ScriptedAnimation *GetNextScriptedAnimation(scaIterator &iter); VEFObject *GetNextScriptedAnimation(scaIterator &iter);
Actor *GetNextActor(int &q, int &index); Actor *GetNextActor(int &q, int &index);
Container *GetNextPile (int &index) const; Container *GetNextPile (int &index) const;
void DrawPile (Region screen, int pileidx); void DrawPile (Region screen, int pileidx);
Expand Down
20 changes: 16 additions & 4 deletions gemrb/core/Projectile.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
#include "Image.h" #include "Image.h"
#include "Interface.h" #include "Interface.h"
#include "ProjectileServer.h" #include "ProjectileServer.h"
#include "Scriptable/Actor.h"
#include "Sprite2D.h" #include "Sprite2D.h"
#include "VEFObject.h"
#include "Video.h" #include "Video.h"
#include "Scriptable/Actor.h"


#include <cmath> #include <cmath>
#include <cstdlib> #include <cstdlib>
Expand Down Expand Up @@ -757,10 +758,19 @@ void Projectile::EndTravel()
} }
} }


//Note: trails couldn't be higher than VVC, but this shouldn't be a problem
int Projectile::AddTrail(ieResRef BAM, const ieByte *pal) int Projectile::AddTrail(ieResRef BAM, const ieByte *pal)
{ {
ScriptedAnimation *sca=gamedata->GetScriptedAnimation(BAM,0); /*
VEFObject *vef=gamedata->GetVEFObject(BAM,0);
if (!vef) return 0;
ScriptedAnimation *sca=vef->GetSingleObject();
if (!sca) return 0; if (!sca) return 0;
*/
ScriptedAnimation* sca=gamedata->GetScriptedAnimation(BAM,0);
if (!sca) return 0;
VEFObject *vef = new VEFObject(sca);

if(pal) { if(pal) {
if (ExtFlags & PEF_TINT) { if (ExtFlags & PEF_TINT) {
Color tmpColor[PALSIZE]; Color tmpColor[PALSIZE];
Expand All @@ -779,7 +789,7 @@ int Projectile::AddTrail(ieResRef BAM, const ieByte *pal)
sca->SetBlend(); sca->SetBlend();
sca->XPos += Pos.x; sca->XPos += Pos.x;
sca->YPos += Pos.y; sca->YPos += Pos.y;
area->AddVVCell(sca); area->AddVVCell(vef);
return sca->GetSequenceDuration(AI_UPDATE_TIME); return sca->GetSequenceDuration(AI_UPDATE_TIME);
} }


Expand Down Expand Up @@ -1407,6 +1417,7 @@ void Projectile::DrawExplosion(const Region &screen)
if (phase==P_EXPLODING1) { if (phase==P_EXPLODING1) {
core->GetAudioDrv()->Play(Extension->SoundRes, Pos.x, Pos.y); core->GetAudioDrv()->Play(Extension->SoundRes, Pos.x, Pos.y);
//play VVC in center //play VVC in center
//FIXME: make it possible to play VEF too?
if (aoeflags&PAF_VVC) { if (aoeflags&PAF_VVC) {
ScriptedAnimation* vvc = gamedata->GetScriptedAnimation(Extension->VVCRes, false); ScriptedAnimation* vvc = gamedata->GetScriptedAnimation(Extension->VVCRes, false);
if (vvc) { if (vvc) {
Expand All @@ -1430,7 +1441,8 @@ void Projectile::DrawExplosion(const Region &screen)
vvc->YPos+=Pos.y; vvc->YPos+=Pos.y;
vvc->PlayOnce(); vvc->PlayOnce();
vvc->SetBlend(); vvc->SetBlend();
area->AddVVCell(vvc); //quick hack to use the single object envelope
area->AddVVCell(new VEFObject(vvc));
} }
} }


Expand Down
Loading

0 comments on commit 6a16baf

Please sign in to comment.