by ajgamester » Thu Nov 05, 2009 9:15 am
#include "GsMagicParticles.h"
#include "mp_wrap.h"
#include "win_data.h"
#include "globaldefines.h"
#include "settings.h"
#include <pf/pflib.h>
#include <pf/platform.h>
#include "pf/debug.h"
GsMagicParticles::GsMagicParticles()
{
}
GsMagicParticles::~GsMagicParticles()
{
//ScriptUnregisterFunction(TWindowManager::GetInstance()->GetScript(),"SendGameMessage");
TPlatform::GetInstance()->OrphanTextureRefreshListener(_restoreTexture);
if( _restoreTexture )
{
delete _restoreTexture;
_restoreTexture = NULL;
}
if (MP)
{
delete MP;
MP=NULL;
}
}
void GsMagicParticles::Init( const char* particleFile,TVec2 position, int32_t particleFileId, Status playingStatus )
{
MP = new MP_Manager;
_position.x = position.x;
_position.y = position.y;
cur = particleFileId;
_status = playingStatus;
const char* temp_folder=GetPathToTemp();
MP->Initialization(MAGIC_INTERPOLATION_ENABLE, MAGIC_NOLOOP, MAGIC_CHANGE_EMITTER_ONLY, temp_folder);
//const char* file=GetFirstFile();
MP->LoadEmittersFromFile(particleFile);
// Loading Textures
const char* texture_folder=GetPathToTexture();
MP->LoadTextures(texture_folder,1024,1024,0,0.1f);
MP->CreateBackupTextures();
MP->CloseFiles();
MP->Stop();
MP_Emitter* emitter=MP->GetEmitter(cur);
emitter->SetState(MAGIC_STATE_UPDATE);
int k_emitter=MP->GetEmitterCount();
float cx=_position.x;
float cy=_position.y;
for (int i=0;i<k_emitter;i++)
{
emitter=MP->GetEmitter(i);
MP_POSITION pos;
emitter->GetPosition(pos);
pos.x=pos.x+cx;
pos.y=pos.y+cy;
emitter->Move(pos);
}
_restoreTexture = new TTaskRestoreTexture(MP);
TPlatform::GetInstance()->AdoptTextureRefreshListener( _restoreTexture );
}
void GsMagicParticles::Update()
{
MP_Emitter* emitter=MP->GetEmitter(cur);
if( _status == play )
{
static unsigned long last_time=0;
double rate=0.01;
unsigned long new_time=GetTick();
if (new_time>last_time)
{
rate=new_time-last_time;
last_time=new_time;
if (rate>500)
rate=0.01;
}
MP->Update(rate);
}
if( _status == stop )
{
emitter->SetState( MAGIC_STATE_STOP );
}
if( playingLoop == true || _status == play )
{
if( _status != stop )
{
if( emitter->GetState() == MAGIC_STATE_STOP )
{
emitter=MP->GetEmitter(cur);
emitter->SetState(MAGIC_STATE_UPDATE);
}
}
}
}
void GsMagicParticles::Draw()
{
TBegin2d begin2d;
TRenderer* r = TRenderer::GetInstance();
//r->FillRect( TURect(0,0,800,600), TColor(0,0,0,0) );
int k_particles=0;
int k_emitter=MP->GetEmitterCount();
for (int i=0;i<k_emitter;i++)
{
MP_Emitter* emitter=MP->GetEmitter(i);
k_particles+=emitter->Render();
}
}
void GsMagicParticles::SetPosition(TVec2 position)
{
MP_Emitter* emitter=MP->GetEmitter(cur);
emitter->SetState(MAGIC_STATE_UPDATE);
int k_emitter=MP->GetEmitterCount();
float cx = position.x;
float cy = position.y;
for (int i=0;i<k_emitter;i++)
{
emitter=MP->GetEmitter(i);
MP_POSITION pos;
emitter->GetPosition(pos);
pos.x = 0;
pos.y = 0;
pos.z = 0;
pos.x=pos.x+cx;
pos.y=pos.y+cy;
emitter->Move(pos);
}
}
TVec2 GsMagicParticles::GetPosition()
{
return _position;
}
void GsMagicParticles::Play( bool loop )
{
_status = play;
playingLoop = loop;
}
void GsMagicParticles::Pause()
{
_status = pause;
}
void GsMagicParticles::Stop()
{
_status = stop;
}
/// this is the class i created and i am creating instances of this class
problem is happening, one instance particles are drawing ... can u figure out , what is the problem