Any help would be appreciated!
4200 FPS program launch (no nodes)
7 FPS after add nodes
2100 FPS after hide nodes (both opengl and directx drivers)
9 FPS after show nodes
3700 FPS after remove nodes (OpenGL driver does not return to program launch FLS rate?)
4200 FPS after remove nodes (DirectX driver acts as I would expect )
Can anyone explain to me a few items :
1) why does hiding the nodes drop the FPS so much from program start? ( it should only be a run through the list determine if each node is invisible and not process it, or is the list run though that slow?)
2) why does removing all of the nodes not return me to roughly the starting FPS?
Code: Select all
#include <irrlicht.h>
#include "driverChoice.h"
#include "exampleHelper.h"
using namespace irr;
irr::core::array<irr::scene::ISceneNode*> nodes;
irr::scene::IAnimatedMeshSceneNode* createAnimatedMesh(IrrlichtDevice* device, irr::core::stringc actorfilename, irr::core::vector3df pos, irr::core::vector3df rot, irr::core::vector3df scale)
{
irr::scene::IAnimatedMeshSceneNode* node = 0;
scene::IAnimatedMesh* mesh = device->getSceneManager()->getMesh(actorfilename);
if (mesh)
{
node = device->getSceneManager()->addAnimatedMeshSceneNode(mesh, 0, 1, pos, rot, scale);
if (node)
{
node->setMaterialFlag(video::EMF_LIGHTING, false);
node->setMaterialFlag(video::EMF_FOG_ENABLE, false);
return node;
}
}
return node;
}
void toggleVisibility()
{
printf("toggling visibility\n");
for (irr::s32 x = 0; x < nodes.size(); x++)
nodes[x]->setVisible(!nodes[x]->isVisible());
}
void buildNodes(IrrlichtDevice* device)
{
printf("building nodes\n");
irr::core::vector3df pos(0, 0, 0);
irr::core::vector3df rot(0, 0, 0);
irr::core::vector3df scale(2, 2, 2);
float offset = 200;
for (int x = 0; x < 50; x++)
{
for (int z = 0; z < 50; z++)
{
pos.Z += offset;
nodes.push_back(createAnimatedMesh(device, "media/_Assets/_Models/_Characters/RoyalKnight/RoyalKnight.b3d", pos, rot, scale));
}
pos.Z = 0;
pos.X += offset;
}
}
void destroyNodes()
{
printf("destroying\n");
for (irr::s32 x = 0; x < nodes.size(); x++) nodes[x]->remove();
nodes.clear();
}
class MyEventReceiver : public IEventReceiver
{
private:
IrrlichtDevice* device;
public:
MyEventReceiver(IrrlichtDevice* dev):device(dev)
{
}
virtual bool OnEvent(const SEvent& event)
{
switch (event.EventType)
{
case EEVENT_TYPE::EET_MOUSE_INPUT_EVENT:
if (event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN)
device->getSceneManager()->getActiveCamera()->setInputReceiverEnabled(!device->getSceneManager()->getActiveCamera()->isInputReceiverEnabled());
break;
case EEVENT_TYPE::EET_KEY_INPUT_EVENT:
switch (event.KeyInput.Key)
{
case KEY_SPACE: if (event.KeyInput.PressedDown) toggleVisibility(); break;
case KEY_KEY_B: if (event.KeyInput.PressedDown) buildNodes(device); break;
case KEY_KEY_N: if (event.KeyInput.PressedDown) destroyNodes(); break;
}
}
return false;
}
};
/*
The start of the main function starts like in most other example. We ask the
user for the desired renderer and start it up. This time with the advanced
parameter handling.
*/
int main()
{
// ask user for driver
video::E_DRIVER_TYPE driverType = driverChoiceConsole();
if (driverType == video::EDT_COUNT) return 1;
// create device with full flexibility over creation parameters
// you can add more parameters if desired, check irr::SIrrlichtCreationParameters
irr::SIrrlichtCreationParameters params;
params.DriverType = driverType;
params.WindowSize = core::dimension2d<u32>(640, 480);
IrrlichtDevice* device = createDeviceEx(params);
if (device == 0) return 1; // could not create selected driver.
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
gui::IGUIEnvironment* env = device->getGUIEnvironment();
driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);
const io::path mediaPath = getExampleMediaPath();
// add irrlicht logo
env->addImage(driver->getTexture(mediaPath + "irrlichtlogo3.png"), core::position2d<s32>(10, 10));
// add camera
scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(0, 100.0f, 1.2f);
camera->setPosition(core::vector3df(2700 * 2, 255 * 2, 2600 * 2));
camera->setTarget(core::vector3df(2397 * 2, 343 , 2700 * 2));
camera->setFarValue(42000.0f);
camera->setInputReceiverEnabled(false);
// disable mouse cursor
device->getCursorControl()->setVisible(true);
// create event receiver
MyEventReceiver receiver(device);
device->setEventReceiver(&receiver);
int lastFPS = -1;
while (device->run())
if (device->isWindowActive())
{
driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(0));
smgr->drawAll();
env->drawAll();
driver->endScene();
// display frames per second in window title
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw str = L"Terrain Renderer - Irrlicht Engine [";
str += driver->getName();
str += "] FPS:";
str += fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}
device->drop();
return 0;
}