[10/26/08] DeM0nFiRe's Irrlicht Test Bed 2 V1.2.0 [Bugfix]

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
roelor
Posts: 240
Joined: Wed Aug 13, 2008 8:06 am

Post by roelor »

when i jump I can launch myself into space. not that there is one in your example. But you get the point.
MasterM
Posts: 128
Joined: Sat Oct 20, 2007 2:38 am
Location: netherlands antilles, Curacao

Post by MasterM »

Since i have an ancient card i decided to test it out...
and i can say that its really impressive...just need to change the models a little bit(stand, turn,etc) and it will be very very good :).
C++ is not the Magdalena...it takes patience...shes like the well aged prostitute, it takes years to learn her tricks! she is cruel...laughs at you when you are naked...
Life of a programmer == Const abuse
DeM0nFiRe
Posts: 117
Joined: Thu Oct 16, 2008 11:59 pm

Post by DeM0nFiRe »

Well, on my Radeon 9200 with 64MB RAM, I get bad performance as well because it is PCI. PCI is just a bad bus, I bet you that if you plug in any old AGP card with at least 32MB RAM, you'd be running fine. There's nothing so complicated in this test that it should be slowing you down as far as code goes, especially since your computer is better in CPU and RAM than mine. Besides, you are the only one of about 20 or 30 who have tried this that get low framerates. Are you sure your OpenGL drivers are up to date and such?

@roelor: Yes, thank you. That is a problem with my movement code, it is a known bug that will be fixed.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

DeM0nFiRe wrote:Well, on my Radeon 9200 with 64MB RAM, I get bad performance as well because it is PCI. PCI is just a bad bus, I bet you that if you plug in any old AGP card with at least 32MB RAM, you'd be running fine.
but not for such a low level test programm... :roll:
what is so special about your test programm that it needs this specs !?!?! :shock:
for example the collision demo from the sdk has much more stuff, like the q3 map, 3 animated meshes, a billboard and it draws a triangle at the collision point...
and it runs like a charm with any driver !!!
the only thing you have is your own movement handler...
so I think your movement handle is done very crappy... :lol:
there are many other programs in the forum that are much more challenging the gpu, for example the grass scene node demo, and they all run pretty smooth for me, either with DX or OGL !!!
or my own programs (look at my site) are all much more complicated than yours and they run all with no peoblems... ;)

what if you make a program with a larger map and more characters and game logics and/or AI, do I need to have the latest industrial high end system to run it then ??? :roll:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

Dunno if this is any better....well

PS: there is no collision detection. just wanted to show some simple camera code.

Code: Select all

#include <irrlicht.h>

class CCamAnim : public irr::scene::ISceneNodeAnimator
{
public:
    CCamAnim(irr::scene::ICameraSceneNode* camera)
    {
        Camera = camera;
        Camera->grab();

        last_time = 0;

        Distance = 50.0f;
        TopOffset = 0.3f;
    }
    ~CCamAnim(void)
    {
        Camera->drop();
    }

    void animateNode(irr::scene::ISceneNode* node, irr::u32 timeMs)
    {
        timer(timeMs);

        irr::core::vector3df top(0,20,0);

        //setTarget might need a offset
        Camera->setTarget(node->getAbsolutePosition()+top);

        Forward.Y -= TopOffset;
        Forward.normalize();
        Forward *= Distance;

        irr::core::vector3df newPos = (node->getAbsolutePosition()+top)-Forward;

        irr::core::vector3df dir = newPos-Camera->getAbsolutePosition();

        //set new CamPos
        Camera->setPosition(Camera->getAbsolutePosition()+dir*diff*3);

        Camera->updateAbsolutePosition();
    }

    void setForward(const irr::core::vector3df& forward)
    {
        Forward = forward;
    }

    void setDistance(const irr::f32& dist)
    {
        if (dist > 10.0f)
            Distance = dist;
    }

    const irr::f32& getDistance(void) const
    {
        return Distance;
    }
protected:
    irr::scene::ICameraSceneNode* Camera;

    //offset stuff
    irr::f32 Distance;
    irr::f32 TopOffset;
    irr::core::vector3df Forward;

    //timer
    irr::u32 last_time;
    irr::f32 diff;
    void timer(irr::u32 timeMs)
    {
        if (last_time == 0)
            last_time = timeMs;

        diff = timeMs-last_time;
        diff /= 1000.0f;

        last_time = timeMs;
    }
};

class CPlayer : public irr::IEventReceiver, public irr::IReferenceCounted
{
public:
    CPlayer(irr::IrrlichtDevice* device)
    {
        Device = device;
        last_time = 0;
        Device->setEventReceiver(this);
        irr::scene::ISceneManager* smgr = Device->getSceneManager();

        //setup node
        Node = smgr->addAnimatedMeshSceneNode(smgr->getMesh("media/sydney.md2"));
        Node->setMaterialTexture(0, smgr->getVideoDriver()->getTexture("media/sydney.bmp"));
        Node->setMaterialFlag(irr::video::EMF_LIGHTING, false);
        Node->grab();

        //setup cam
        Camera = smgr->addCameraSceneNode();
        Camera->grab();

        //setup cam animator
        CameraAnimator = new CCamAnim(Camera);
        CameraAnimator->grab();

        Node->addAnimator(CameraAnimator);


        //setup movement
        RunForward = false;
        RunBackward = false;
        TurnLeft = false;
        TurnRight = false;
    }

    ~CPlayer(void)
    {
        Node->remove();
        Node->drop();

        Camera->remove();
        Camera->drop();

        CameraAnimator->drop();
    }

    //events
    bool OnEvent(const irr::SEvent& event)
    {
        switch(event.EventType)
        {
            case irr::EET_MOUSE_INPUT_EVENT:
                if (event.MouseInput.Event == irr::EMIE_MOUSE_WHEEL)
                {
                    CameraAnimator->setDistance(CameraAnimator->getDistance()-event.MouseInput.Wheel*1500*diff);
                }
                break;
            case irr::EET_KEY_INPUT_EVENT:
                if (event.KeyInput.Key == irr::KEY_ESCAPE)
                {
                    Device->closeDevice();
                    return true;
                }
                if (event.KeyInput.Key == irr::KEY_KEY_W)
                {
                    RunForward = event.KeyInput.PressedDown;
                    return true;
                }
                if (event.KeyInput.Key == irr::KEY_KEY_S)
                {
                    RunBackward = event.KeyInput.PressedDown;
                    return true;
                }
                if (event.KeyInput.Key == irr::KEY_KEY_A)
                {
                    TurnLeft = event.KeyInput.PressedDown;
                    return true;
                }
                if (event.KeyInput.Key == irr::KEY_KEY_D)
                {
                    TurnRight = event.KeyInput.PressedDown;
                    return true;
                }
                break;
        };

        return false;
    }

    void update(irr::u32 timeMs)
    {
        timer(timeMs);

        //do rotation stuff
        if (TurnLeft)
            Node->setRotation(irr::core::vector3df(0,Node->getRotation().Y-180.0f*diff,0));
        else if (TurnRight)
            Node->setRotation(irr::core::vector3df(0,Node->getRotation().Y+180.0f*diff,0));

        //avoid glimballock
        if (Node->getRotation().Y <= -360.0f)
            Node->setRotation(irr::core::vector3df(0,Node->getRotation().Y+360.0f,0));
        if (Node->getRotation().Y >= 360.0f)
            Node->setRotation(irr::core::vector3df(0,Node->getRotation().Y-360.0f,0));

        //do movement here
        irr::core::vector3df forward(1,0,0);
        irr::core::matrix4 mat;
        mat.setRotationDegrees(irr::core::vector3df(0,Node->getRotation().Y,0));
        mat.transformVect(forward);

        irr::f32 Speed = 100.0f;

        if (RunForward)
            Node->setPosition(Node->getAbsolutePosition()+forward*diff*Speed);
        else if (RunBackward)
        {
            forward*=-1.0f;
            Node->setPosition(Node->getAbsolutePosition()+forward*diff*Speed);
        }

        //update animator
        CameraAnimator->setForward(forward);
    }
protected:
    irr::IrrlichtDevice* Device;

    //mesh node
    irr::scene::IAnimatedMeshSceneNode* Node;

    //camera
    irr::scene::ICameraSceneNode* Camera;

    //camera animator
    CCamAnim* CameraAnimator;

    //movement
    bool RunForward;
    bool RunBackward;
    bool TurnLeft;
    bool TurnRight;

    irr::u32 last_time;
    irr::f32 diff;
    void timer(irr::u32 timeMs)
    {
        if (last_time == 0)
            last_time = timeMs;

        diff = timeMs-last_time;
        diff /= 1000.0f;

        last_time = timeMs;
    }
};

int main(int args, char* argv[])
{
    irr::IrrlichtDevice *device = irr::createDevice(irr::video::EDT_OPENGL, irr::core::dimension2d<irr::s32>(800,600));

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

    device->getFileSystem()->addZipFileArchive("media/map-20kdm2.pk3");
    irr::scene::IAnimatedMesh* mesh = smgr->getMesh("20kdm2.bsp");
	irr::scene::ISceneNode* node = 0;
	if (mesh)
		node = smgr->addOctTreeSceneNode(mesh->getMesh(0), 0, -1, 128);
	if (node)
		node->setPosition(irr::core::vector3df(-1300,-144,-1249));


    CPlayer* player = new CPlayer(device);

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

        player->update(device->getTimer()->getTime());
    }

    device->drop();
    player->drop();
    return 0;
}
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Sudi wrote:Dunno if this is any better
yeah, that runs very smooth for me, even with collision detection (~100fps) !!! :)
and there is nothing that isn't in DeM0nFiRe's demo (well, except the jumping though)... ;)

I just added some lines for the collision detection and for drawing the fps rate...
so if you want to try it with collision detection:

Code: Select all

#include <irrlicht.h>

irr::scene::ITriangleSelector* selector = 0;

class CCamAnim : public irr::scene::ISceneNodeAnimator
{
public:
    CCamAnim(irr::scene::ICameraSceneNode* camera)
    {
        Camera = camera;
        Camera->grab();

        last_time = 0;

        Distance = 50.0f;
        TopOffset = 0.3f;
    }
    ~CCamAnim(void)
    {
        Camera->drop();
    }

    void animateNode(irr::scene::ISceneNode* node, irr::u32 timeMs)
    {
        timer(timeMs);

        irr::core::vector3df top(0,20,0);

        //setTarget might need a offset
        Camera->setTarget(node->getAbsolutePosition()+top);

        Forward.Y -= TopOffset;
        Forward.normalize();
        Forward *= Distance;

        irr::core::vector3df newPos = (node->getAbsolutePosition()+top)-Forward;

        irr::core::vector3df dir = newPos-Camera->getAbsolutePosition();

        //set new CamPos
        Camera->setPosition(Camera->getAbsolutePosition()+dir*diff*3);

        Camera->updateAbsolutePosition();
    }

    void setForward(const irr::core::vector3df& forward)
    {
        Forward = forward;
    }

    void setDistance(const irr::f32& dist)
    {
        if (dist > 10.0f)
            Distance = dist;
    }

    const irr::f32& getDistance(void) const
    {
        return Distance;
    }
protected:
    irr::scene::ICameraSceneNode* Camera;

    //offset stuff
    irr::f32 Distance;
    irr::f32 TopOffset;
    irr::core::vector3df Forward;

    //timer
    irr::u32 last_time;
    irr::f32 diff;
    void timer(irr::u32 timeMs)
    {
        if (last_time == 0)
            last_time = timeMs;

        diff = timeMs-last_time;
        diff /= 1000.0f;

        last_time = timeMs;
    }
};

class CPlayer : public irr::IEventReceiver, public irr::IReferenceCounted
{
public:
    CPlayer(irr::IrrlichtDevice* device)
    {
        Device = device;
        last_time = 0;
        Device->setEventReceiver(this);
        irr::scene::ISceneManager* smgr = Device->getSceneManager();

        //setup node
        Node = smgr->addAnimatedMeshSceneNode(smgr->getMesh("media/sydney.md2"));
        Node->setMaterialTexture(0, smgr->getVideoDriver()->getTexture("media/sydney.bmp"));
        Node->setMaterialFlag(irr::video::EMF_LIGHTING, false);
        Node->setMD2Animation(irr::scene::EMAT_STAND);
        Node->grab();
        if(selector){
          irr::scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
            selector, Node, irr::core::vector3df(30,40,30),
            irr::core::vector3df(0,-3,0),
            irr::core::vector3df(0,0,0));
          selector->drop();
          Node->addAnimator(anim);
          anim->drop();
        }

        //setup cam
        Camera = smgr->addCameraSceneNode();
        Camera->grab();

        //setup cam animator
        CameraAnimator = new CCamAnim(Camera);
        CameraAnimator->grab();

        Node->addAnimator(CameraAnimator);


        //setup movement
        RunForward = false;
        RunBackward = false;
        TurnLeft = false;
        TurnRight = false;
    }

    ~CPlayer(void)
    {
        Node->remove();
        Node->drop();

        Camera->remove();
        Camera->drop();

        CameraAnimator->drop();
    }

    //events
    bool OnEvent(const irr::SEvent& event)
    {
        switch(event.EventType)
        {
            case irr::EET_MOUSE_INPUT_EVENT:
                if (event.MouseInput.Event == irr::EMIE_MOUSE_WHEEL)
                {
                    CameraAnimator->setDistance(CameraAnimator->getDistance()-event.MouseInput.Wheel*1500*diff);
                }
                break;
            case irr::EET_KEY_INPUT_EVENT:
                if (event.KeyInput.Key == irr::KEY_ESCAPE)
                {
                    Device->closeDevice();
                    return true;
                }
                if (event.KeyInput.Key == irr::KEY_KEY_W)
                {
                    RunForward = event.KeyInput.PressedDown;
                    return true;
                }
                if (event.KeyInput.Key == irr::KEY_KEY_S)
                {
                    RunBackward = event.KeyInput.PressedDown;
                    return true;
                }
                if (event.KeyInput.Key == irr::KEY_KEY_A)
                {
                    TurnLeft = event.KeyInput.PressedDown;
                    return true;
                }
                if (event.KeyInput.Key == irr::KEY_KEY_D)
                {
                    TurnRight = event.KeyInput.PressedDown;
                    return true;
                }
                break;
        };

        return false;
    }

    void update(irr::u32 timeMs)
    {
        timer(timeMs);

        //do rotation stuff
        if (TurnLeft)
            Node->setRotation(irr::core::vector3df(0,Node->getRotation().Y-180.0f*diff,0));
        else if (TurnRight)
            Node->setRotation(irr::core::vector3df(0,Node->getRotation().Y+180.0f*diff,0));

        //avoid glimballock
        if (Node->getRotation().Y <= -360.0f)
            Node->setRotation(irr::core::vector3df(0,Node->getRotation().Y+360.0f,0));
        if (Node->getRotation().Y >= 360.0f)
            Node->setRotation(irr::core::vector3df(0,Node->getRotation().Y-360.0f,0));

        //do movement here
        irr::core::vector3df forward(1,0,0);
        irr::core::matrix4 mat;
        mat.setRotationDegrees(irr::core::vector3df(0,Node->getRotation().Y,0));
        mat.transformVect(forward);

        irr::f32 Speed = 150.0f;

        if (RunForward)
            Node->setPosition(Node->getAbsolutePosition()+forward*diff*Speed);
        else if (RunBackward)
        {
            forward*=-1.0f;
            Node->setPosition(Node->getAbsolutePosition()+forward*diff*Speed);
        }
        static bool isRunning = false;
        if((RunForward || RunBackward) && !isRunning){
          Node->setMD2Animation(irr::scene::EMAT_RUN);
          isRunning = true;
        }else if((!RunForward && !RunBackward) && isRunning){
          Node->setMD2Animation(irr::scene::EMAT_STAND);
          isRunning = false;
        }
        //update animator
        CameraAnimator->setForward(forward);
    }
protected:
    irr::IrrlichtDevice* Device;

    //mesh node
    irr::scene::IAnimatedMeshSceneNode* Node;

    //camera
    irr::scene::ICameraSceneNode* Camera;

    //camera animator
    CCamAnim* CameraAnimator;

    //movement
    bool RunForward;
    bool RunBackward;
    bool TurnLeft;
    bool TurnRight;

    irr::u32 last_time;
    irr::f32 diff;
    void timer(irr::u32 timeMs)
    {
        if (last_time == 0)
            last_time = timeMs;

        diff = timeMs-last_time;
        diff /= 1000.0f;

        last_time = timeMs;
    }
};

int main(int args, char* argv[])
{
    irr::IrrlichtDevice *device = irr::createDevice(irr::video::EDT_DIRECT3D9, irr::core::dimension2d<irr::s32>(800,600));

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

    device->getFileSystem()->addZipFileArchive("media/map-20kdm2.pk3");
    irr::scene::IAnimatedMesh* mesh = smgr->getMesh("20kdm2.bsp");
   irr::scene::ISceneNode* node = 0;
   if (mesh)
      node = smgr->addOctTreeSceneNode(mesh->getMesh(0), 0, -1, 128);
   if (node){
      node->setPosition(irr::core::vector3df(-1300,-144,-1249));
      node->setPosition(irr::core::vector3df(-1350,-130,-1400));
      selector = smgr->createOctTreeTriangleSelector(mesh->getMesh(0), node, 128);
      node->setTriangleSelector(selector);
    }

    CPlayer* player = new CPlayer(device);
    int lastFPS = -1;
    while(device->run())
    {
        driver->beginScene(true, true, irr::video::SColor(255,0,0,255));
        smgr->drawAll();
        driver->endScene();

        player->update(device->getTimer()->getTime());
        int fps = driver->getFPS();

        if (lastFPS != fps)
        {
          irr::core::stringw str = L"Irrlicht Engine - Quake 3 Map example [";
          str += driver->getName();
          str += "] FPS:";
          str += fps;

          device->setWindowCaption(str.c_str());
          lastFPS = fps;
        }
    }

    device->drop();
    player->drop();
    return 0;
}
EDIT: also added the correct animations when moving and standing... ;)
Last edited by Acki on Mon Oct 20, 2008 12:40 am, edited 3 times in total.
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

Thanks for adding it acki :D
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
xray
Posts: 231
Joined: Fri Feb 02, 2007 1:06 pm
Location: Germany, Munich
Contact:

Post by xray »

I have to agree with acki that something have to be messed with your code and not with hour video cards, because I also get about 2-3 frames per second and my specs are:

Intel CoreDuo 2.4 Ghz
1 GB Ram
ATI x1900 256 MB PCI Express
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

It sounds like the problem is that he is using Irrlicht 1.4.1, and not Irrlicht 1.4.2. I looked over the OP post, and I didn't see anything that suggests the version he actually is using.
TheQuestion = 2B || !2B
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Halifax wrote:It sounds like the problem is that he is using Irrlicht 1.4.1, and not Irrlicht 1.4.2.
I think that doesn't matter...
I'm using Irrlicht since v0.4 and I saw not a single program with such a bad fps rate... ;)
remember there are only the q3 map and Sydney from the sdk in this program !!! :lol:
this should also run with an ancient vga card plus a VooDoo card (if someone remembers this) !!! :twisted:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

Acki wrote:
Halifax wrote:It sounds like the problem is that he is using Irrlicht 1.4.1, and not Irrlicht 1.4.2.
I think that doesn't matter...
I'm using Irrlicht since v0.4 and I saw not a single program with such a bad fps rate... ;)
remember there are only the q3 map and Sydney from the sdk in this program !!! :lol:
this should also run with an ancient vga card plus a VooDoo card (if someone remembers this) !!! :twisted:
No it definitely does matter if he is using OpenGL, and especially the q3 map.
- Fixed the major problem with OpenGL drivers, that claim to be 2.x compatible, but don't offer NPOT support (well, they do, but only in sw rendering...). Now we check for the extension string only.
TheQuestion = 2B || !2B
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

Maybe he should post some code so we can see if he is doing something wrong.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

Yes, a bug was introduced in 1.4.1 and then fixed in 1.4.2 where a false positive in openGL caused a resizing of all textures to pot2 at every single frame. Thus, this bug if present can cripple any application thoroughly.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Dorth wrote:Yes, a bug was introduced in 1.4.1 and then fixed in 1.4.2 where a false positive in openGL caused a resizing of all textures to pot2 at every single frame. Thus, this bug if present can cripple any application thoroughly.
uhh, I see, yes this could be a problem indeed... :lol:

so if you're using Irrlicht v1.4.1 with OpenGL then either switch to 1.4.2 or use another driver... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
DeM0nFiRe
Posts: 117
Joined: Thu Oct 16, 2008 11:59 pm

Post by DeM0nFiRe »

There we go, that would be the problem. I will re-compile this with 1.4.2, as I am using 1.4.1 right now. With the code that is in my demo now, there is no way that my code is causing a loss of many thousands of percent of FPS than what would otherwise be expected. With this demo I get between 100 and 120 FPS, if the final product runs about 60FPS on my computer than most everybody will be ok.

To clarify, I am not saying that my code does not need optimization. It does very much, just not as badly as the problem you are experiencing.

Now, I have another bug to add to the list:
[004]Because the program is compiled with Irrlicht 1.4.1 as opposed to 1.4.2, the program runs at an incredibly low framerate for some.

I should hopefully have time mid to late this week to fix bugs 003 and 004. Maybe just for laughs I will also try to make my own map and model (very simple ones) to go with the demo, and maybe I will add lights.


As for collision detection with the camera, for now it is intentionally left out because I have not decided with what I would like the camera to collide. What I will probably do is, in a later version, register certain nodes with some sort of manager to tell the camera what it should and should not collide with.

@sudi: the problem with your code is that the Device can only handle one event reciever at a time (not including cameras), so I would rather that the primary event receiver not be part of the player. I am looking at this project in a forward thinking kind of way so I need to make sure my code now will fit with more code later. (Unless I am wrong that the Device can handle only one? If the device can handle more, someone please clarify that for me :D )
Post Reply