rogerborg wrote:Every time someone learns to use a debugger, an angel gets their wings.

Dark_Kilauea wrote:One might be able to pull it off without threads
Dark_Kilauea wrote:but IMO threads are both safer
Dark_Kilauea wrote:and easier to implement.
Dark_Kilauea wrote:I'm just worried about the mutex that may be required in the rendering loop to pull this off. A mutex will end up hurting rendering speed.
christianclavet wrote:Just a kind of global value that "loading" is occuring. The rendering will surely be a "little" slower when loading at the same time (I think it's normal, now we don't have nothing)
So when the loading is started and not yet completed a "global" flag somewhere is having "loading proceeding".
If this flag is on when the scene manager will render the scene(a single simple check before rendering the frame)
christianclavet wrote:it will check for every meshes/images to be complete in the buffers.
christianclavet wrote:If loading is complete then it will simply render the scene without checking for this. Only when the first occurence of the loading occur stop the current render
christianclavet wrote:There would be to have some modifications to the core loading functions, and the scene manager also.
I have to ask: have either of you written or maintained a large multithreaded project? It's certainly possible to multithread Irrlicht, but it would be a major rewrite, and the potential to introduce crash bugs and lock ups (race conditions) is significant.
It's not really something that you'd want to commit to if you're learning as you go. I'd suggest that you write some multithreaded sample apps first to help you spot the pitfalls. I'd be happy to help you crash and lock them up.
1. Load file in memory in a separate thread (process as if it was loaded in a buffer). The IRRlicht thread continue execution.
2. When completed the control of the memory zone is given to the IRRlicht thread. This could be a [u]new type of event [/u]that the main IRRlicht thread use to continue the loading process (as the third step)
3. Copy the loaded buffer to the meshbuffer and update the scene graph. (same thing as if the file was loaded, but this time from the memory) (Memory to memory would surely be much faster and the user would not feel the delay too much.)
4. release the memory used to temporarely hold the buffer data.
rogerborg wrote:Every time someone learns to use a debugger, an angel gets their wings.

#include <pthread.h>
#include <windows.h>
#include <stdio.h>
#include <irrlicht.h>
#pragma comment(lib,"pthreadVC2.lib")
#pragma comment(lib,"irrlicht.lib")
using namespace irr;
using namespace scene;
using namespace core;
using namespace video;
struct tStruct
{
IrrlichtDevice* dev;
ISceneNode* node;
IAnimatedMesh* mesh;
}
void* doOtherStuff(void * stuff)
{
tStruct mytStruct = *((tStruct*)stuff);
mytStruct.dev->getSceneManager()->createOctTreeTriangleSelector(mytStruct.mesh->getMesh(0),mytStruct.node);
pthread_exit(NULL);
return (void*)0;
}
int main()
{
IrrlichtDevice* device = createDevice(video::EDT_OPENGL,core::dimension2d<s32>(640,480));
device->getSceneManager()->addCameraSceneNode();
device->getFileSystem()->addZipFileArchive("../../media/map-20kdm2.pk3");
scene::IAnimatedMesh* q3levelmesh = smgr->getMesh("20kdm2.bsp");
scene::ISceneNode* q3node = 0;
if (q3levelmesh)
q3node = smgr->addOctTreeSceneNode(q3levelmesh->getMesh(0));
pthread_t* myThread2 = new pthread_t();
tStruct mytStruct;
mytStruct.dev = device;
mytStruct.mesh = q3levelmesh;
mytStruct.node = q3node;
pthread_create(myThread2,NULL,doOtherStuff,(void*)&mytStruct);
ISceneNode* cuby = device->getSceneManager()->addCubeSceneNode(10,0,-1,vector3df(0,0,30));
cuby->setMaterialFlag(EMF_LIGHTING,false);
ISceneNodeAnimator* anim = device->getSceneManager()->createRotationAnimator(vector3df(0.5f,0.5f,0.5f));
cuby->addAnimator(anim);
// Show something cool while it's loading.
while(device->run())
{
device->getVideoDriver()->beginScene(true,true,video::SColor(255,255,0,0));
device->getSceneManager()->drawAll();
device->getVideoDriver()->endScene();
Sleep(10);
}
device->drop();
pthread_exit(NULL);
}rogerborg wrote:Every time someone learns to use a debugger, an angel gets their wings.

BlindSide wrote:Some stuff don't really need any wariness while threading.
BlindSide wrote:Heres a simple example showing how to do this (Just wrote it now, so might have errors, but I've tried something identical to this and it worked fine.):


Return to Open Discussion and Dev Announcements
Users browsing this forum: No registered users and 0 guests