Two instances of particles are not drawing

All information about Magic Particles: news, question, comments, etc.

Two instances of particles are not drawing

Postby ajgamester » Wed Nov 04, 2009 12:36 pm

Hi ,
I have created class for drawing particles... Two type of particles are not drawing in the same window
ajgamester
 
Posts: 11
Joined: Fri Oct 09, 2009 6:55 am

Re: Two instances of particles are not drawing

Postby Odin_KG » Wed Nov 04, 2009 1:10 pm

Hi,

If you created 2 copy of MP_Manager then it is error. All emitters places in one array inside API.
User avatar
Odin_KG
Administrator
Administrator
 
Posts: 255
Joined: Sat May 09, 2009 10:53 pm

Re: Two instances of particles are not drawing

Postby 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
ajgamester
 
Posts: 11
Joined: Fri Oct 09, 2009 6:55 am

Re: Two instances of particles are not drawing

Postby Odin_KG » Thu Nov 05, 2009 10:10 am

How many objects of GsMagicParticles do you create simultaneously? You can create one object only.
User avatar
Odin_KG
Administrator
Administrator
 
Posts: 255
Joined: Sat May 09, 2009 10:53 pm

Re: Two instances of particles are not drawing

Postby ajgamester » Thu Nov 05, 2009 10:15 am

what is the problem if i create multiple objects of GsMagicParticles ???????????????

I want to create multiple particles at the same time .... can please tell how can we create ...
ajgamester
 
Posts: 11
Joined: Fri Oct 09, 2009 6:55 am

Re: Two instances of particles are not drawing

Postby Odin_KG » Thu Nov 05, 2009 10:47 am

what is the problem if i create multiple objects of GsMagicParticles ?

MP->LoadTextures(texture_folder,1024,1024,0,0.1f);
The atlases are created for ALL loaded emitters. Read API.chm->Magic_CreateAtlases.
You can make other way to load textures. You can get all information about textures from API.chm->MAGIC_TEXTURE.

I want to create multiple particles at the same time .... can please tell how can we create ...

Delete in my wrapper the line:
MP->Stop();
and ALL emitters will be shown simultaneously.

You can turn on/off any emitter with help MP_Emitter::SetState.
User avatar
Odin_KG
Administrator
Administrator
 
Posts: 255
Joined: Sat May 09, 2009 10:53 pm

Re: Two instances of particles are not drawing

Postby ajgamester » Thu Nov 05, 2009 11:30 am

if i delete this line
Mp->Stop() ... it is crashing at.... this line

renderer->DrawIndexedVertices(TRenderer::kDrawTriangles, vertex_array, buffer.GetIndexArray(), k_particles*6);
ajgamester
 
Posts: 11
Joined: Fri Oct 09, 2009 6:55 am

Re: Two instances of particles are not drawing

Postby Odin_KG » Thu Nov 05, 2009 11:54 am

if i delete this line
Mp->Stop() ... it is crashing at.... this line

I have deleted Mp->Stop() and all works well. You can delete the line in MY wrapper. If you deleted this line in your new code I can't know about result.
User avatar
Odin_KG
Administrator
Administrator
 
Posts: 255
Joined: Sat May 09, 2009 10:53 pm

Re: Two instances of particles are not drawing

Postby ajgamester » Thu Nov 05, 2009 12:05 pm

This is the class i created ( attached ) using same wrapper class,

please try to create object of this class in swarm class like following code

GsMagicParticles* _mouseOverParticles;

////in Init
_mouseOverParticles = new GsMagicParticles();
_mouseOverParticles->Init( "fire.ptc", TVec2( 0, 0 ), 2, GsMagicParticles::pause );
_mouseOverParticles->Play( true );

// Update
if( _mouseOverParticles ) _mouseOverParticles->Update();

//Draw
if( _mouseOverParticles ) _mouseOverParticles->Draw();




please try to fix this problem
Attachments
particles.zip
(1.73 KiB) Downloaded 2835 times
ajgamester
 
Posts: 11
Joined: Fri Oct 09, 2009 6:55 am

Re: Two instances of particles are not drawing

Postby Odin_KG » Thu Nov 05, 2009 12:19 pm

I am sorry, but I have own work and can't find your errors. The wrapper works well, if you decide to improve wrapper then you have to find your errors yourself.
User avatar
Odin_KG
Administrator
Administrator
 
Posts: 255
Joined: Sat May 09, 2009 10:53 pm

Next

Return to Magic Particles

Who is online

Users browsing this forum: No registered users and 6 guests

cron