Horrible slowdown with particles...

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Serg Nechaeff
Posts: 162
Joined: Wed Nov 26, 2003 5:24 pm
Location: Europe

Horrible slowdown with particles...

Post by Serg Nechaeff »

Please help, I guess Im doing smth wrong because I have like 7fps with ~300 triangles :-/
Tried both ogl and dx renderers... I mean I have not the fastest PC (P-III-950, WinXP, tnt 2) but I have a great speed with my blitz basic 3d particle code :)

Code: Select all

#include <irrlicht.h>
#include <wchar.h>
#include <windows.h>

using namespace irr;
#pragma comment(lib, "Irrlicht.lib")


scene::ICameraSceneNode* camera = 0;


class MyEventReceiver : public IEventReceiver {
public:
        virtual bool OnEvent(SEvent event)
        {
                if (camera)
                        return camera->OnEvent(event);

                return false;
        }
};

int WINAPI WinMain(HINSTANCE        hInstance,      
                   HINSTANCE        hPrevInstance, 
                   LPSTR            lpCmdLine,      
                   int              nCmdShow) 
{ 
////////////////////////////////////////////////////

	MyEventReceiver receiver;
////////////////////////////////////////////////////
	IrrlichtDevice *device =
                createDevice(video::DT_OPENGL, core::dimension2d<s32>(640, 480), 16, false, false, &receiver);

	
	video::IVideoDriver* driver = device->getVideoDriver();
	scene::ISceneManager* smgr = device->getSceneManager();
////////////////////////////////////////////////////

	camera = smgr->addCameraSceneNodeFPS(0, 200.0f, 500.0f );
	camera->setPosition(core::vector3df(-50,45,-150));
	camera->setFarValue(15000.0f);
 
////////////////////////////////////////////////////

	scene::IParticleSystemSceneNode* ps = 0;

	ps = smgr->addParticleSystemSceneNode(false);
	ps->setPosition(core::vector3df(-70,60,40));
	ps->setScale(core::vector3df(2,2,2));

	ps->setParticleSize(core::dimension2d<f32>(20.0f, 10.0f));

	scene::IParticleEmitter* em = ps->createBoxEmitter(
		core::aabbox3d<f32>(-7,0,-7,7,1,7), 
		core::vector3df(0.0f,0.03f,0.0f),
		800,1000, 
		video::SColor(0,255,255,255), video::SColor(0,255,255,255),
		80,100);

	ps->setEmitter(em);
	em->drop();

	scene::IParticleAffector* paf = 
		ps->createFadeOutParticleAffector();

	ps->addAffector(paf);
	paf->drop();

	ps->setMaterialFlag(video::EMF_LIGHTING, false);
	ps->setMaterialTexture(0, driver->getTexture("sprites/2.jpg"));
	ps->setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA);

////////////////////////////////////////////////////


	int lastFPS = -1;

	while(device->run()) {
		
		driver->beginScene(true, true, video::SColor(0,0,0,0));
        smgr->drawAll();
        driver->endScene();

        int fps = driver->getFPS();

        if (lastFPS != fps) {
			wchar_t tmp[1024];
            swprintf(tmp, 1024, L"Quake 3 Map Example - Irrlicht Engine (fps:%d) Triangles:%d", 
						fps, driver->getPrimitiveCountDrawn());

			device->setWindowCaption(tmp);
			lastFPS = fps;}}

        /*
        In the end, delete the Irrlicht device.
        */
        device->drop();



   return 0; 

}; 
DarkWhoppy
Posts: 386
Joined: Thu Sep 25, 2003 12:43 pm
Contact:

Post by DarkWhoppy »

You don't need to create a window using WinMain. Just start a new Win32 applicatio nand use " int main() ". Irrlicht will do the rest... that may be one of your probs. (My PC isn't the fastest either... (300Mhz, 8Mb Video) but with 5,000 triangles I get 10-11 FPS with three particle emitters...)
[dx/x]=HUNT3R
Posts: 271
Joined: Sat Aug 23, 2003 5:52 pm
Location: Hurricane Central, Florida

Post by [dx/x]=HUNT3R »

Your problem is that your video card sux and your trying to put too many particles on the screen. You trying to spit out 800-1000 particles per second and theres not way a TNT video card is gonna run good with that much stuff on the screen. Take some zeros off of those max and min particles per second and that'll help. Also, I'd stick with the WinMain if I was you, no need for that stupid console window, you're writing Windows applications here...

Code: Select all

scene::IParticleEmitter* em = ps->createBoxEmitter( 
      core::aabbox3d<f32>(-7,0,-7,7,1,7), 
      core::vector3df(0.0f,0.03f,0.0f), 
      800,1000, // this is the min and max particles/sec. Try 8,10 or 80,100
      video::SColor(0,255,255,255), video::SColor(0,255,255,255), 
      80,100);
DarkWhoppy
Posts: 386
Joined: Thu Sep 25, 2003 12:43 pm
Contact:

Post by DarkWhoppy »

You don't get a console window when you create a Win32 application and use " int main()" ... (because I don't.. and when I create a Console App and use the same "int main()" i do get a console window... either way... it works)
Serg Nechaeff
Posts: 162
Joined: Wed Nov 26, 2003 5:24 pm
Location: Europe

Post by Serg Nechaeff »

Right... can't believe how stupid I am :)
Thanks a lot for your help!
[dx/x]=HUNT3R
Posts: 271
Joined: Sat Aug 23, 2003 5:52 pm
Location: Hurricane Central, Florida

Post by [dx/x]=HUNT3R »

DarkWhoppy wrote:You don't get a console window when you create a Win32 application and use " int main()"
Ok but can you define an icon or cursor for your program without using a WinMain? Plus it just doesn't handle Windows messages properly, best to stick with a WinMain.
DarkWhoppy
Posts: 386
Joined: Thu Sep 25, 2003 12:43 pm
Contact:

Post by DarkWhoppy »

Actually... I don't... I wrote a tutorial on how to make a mouse cursor with the engine and I use Dev-C++ to put in the icon.

http://www.phyer.net/whoppyarts/downloa ... cursor.cpp
Post Reply