Everything should have a true/false flag

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Everything should have a true/false flag

Post by afecelis »

Hi guys!

I was thinking it would be easier to make boolean variables work if everything had a true/false flag.

For instance, if you wanted a particle system to dissappear without having to remove the node you would just create a boolean variable for it, create an event receiver, asign the particle to a key, and then change your true/false flag for your boolean variable.

This would be useful for many many things:
1.rockets activated by a key or a mouse clic
2. turning lights on/off
3. switching cameras and rendermodes easier

etc etc etc

dunno, but with the things that have a true/false flag like some rendering methods, things r easier to set.

or am I too crazy?
Image
T101
Posts: 44
Joined: Thu Jul 29, 2004 4:41 pm

Post by T101 »

Suppose you have 2000 objects, 40 of which are active at any time.
How much overhead is there going to be in checking all of those flags?

Hopefully not much, but maybe a list of all objects that need updating is a better idea.
Use member functions, say activate() and deactivate(), to add and remove from the list of active objects, and loop through the list when calling postrender functions etc.

You need two pointers and a flag per scenenode (so that it is easy to remove the node from the middle of the list):

global:
ISceneNode *First;
ISceneNode *Last;


ISceneNode:
ISceneNode *Prev;
ISceneNode *Next;
bool IsActive;

ISceneNode()
{
Prev=NULL;
Next=NULL;
IsActive = false;
}

~ISceneNode()
{
deactivate();
...
}

// appends node to the end of the active list
void activate()
{
if(IsActive) // already in the active list
return;

IsActive=true;

Prev=Last;

if(Last)
Last->Next=this;
else
First=this;
}

void deactivate()
{
if(!IsActive)
return;

if(Prev)
Prev->Next=Next;
else
Last=Next;

if(Next)
Next->Prev=Prev;
else
First=Next;

IsActive=false;
}

Update loop:
void ProcessActiveNodes()
{
ISceneNode *currentnode;

currentnode=First;

while(currentnode) {
... // call functions for currentnode
currentnode=currentnode->Next;
}
}
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Post by afecelis »

wholy moley!

T101, thnx for that! that is some seriously interesting stuff to dig in!

:D

pretty much like creating your own nodes.

I had never thought of it that way. C++ is a beauty for the multiple alternatives to do stuff. and of course, the differences in the way of thinking from one person to another opens even more doors!

thnx!
:D :D :D
Image
erSitzt
Posts: 52
Joined: Sun May 09, 2004 11:59 am

Post by erSitzt »

Why not use setVisible(bool isVisible)...

If you want to disable other things like animations/positionchanges etc for your entities create a manager-class which holds a list of all your entities.
You could then add/remove your entities to/from that manager.

Updates for all your entities are handled in the engine-loop by calling a manager->updateEntities()

...but im not sure if that was your intention... :)
Hardwarespecs in signatures suck !
AssiDragon
Posts: 158
Joined: Wed Apr 28, 2004 11:03 am
Location: Hungary
Contact:

Post by AssiDragon »

T101, interesting idea. :) Not sure, but wouldn't be an std::map (or perhaps an std::vector ?) be simplier though? I know, needs STLPort, but technically it shouldn't be slower... I think :?
Staring through eyes of hate we kill
Are we controlled, or is our own will...?
(Edguy)
punt
Posts: 13
Joined: Fri Jul 09, 2004 7:57 pm

Why need STLPort?

Post by punt »

AssiDragon wrote:T101, interesting idea. :) Not sure, but wouldn't be an std::map (or perhaps an std::vector ?) be simplier though? I know, needs STLPort, but technically it shouldn't be slower... I think :?

Why does it need STLPort? map and vector or both part of the Standard C++ Library, and most current compiliers fully support them. (admittingly, borland 5 had a pretty broken STL, and VS 6 wasn't great on namespaces)
AssiDragon
Posts: 158
Joined: Wed Apr 28, 2004 11:03 am
Location: Hungary
Contact:

Post by AssiDragon »

VC6 and VC7's STLPorts are something I would never eeeeeeeeeeeever use. Even VC7.1's default STLPort falls short when you compare them to the STLPort itself.
Staring through eyes of hate we kill
Are we controlled, or is our own will...?
(Edguy)
Guest

Post by Guest »

T101 here - of course there are multiple ways of doing it.
I'm more of a C programmer myself - that's why I use
pointers for this sort of stuff. But using some sort of "standard"
linked list functionality (maybe something is already in Irr for that)
could work just as well.
Still, using pointers for this is pretty clean.
AssiDragon
Posts: 158
Joined: Wed Apr 28, 2004 11:03 am
Location: Hungary
Contact:

Post by AssiDragon »

Why I prefer maps is they auto-update themselves, and make sure no bogus information gets in when I forget to sg manually (like to call a function before deleting an object or something). I know it sounds lamerish, but I have the most problems with these sorts of mistakes knowing myself...

And well, about more ways doing it - using VC6.00's STLPort implementation is a mere suicide from the view of your program, imho. Even VC7.1's STLPort implementation has some issues and bugs I can reproduce - and VC6.00 was sortof full of them...
Staring through eyes of hate we kill
Are we controlled, or is our own will...?
(Edguy)
jikbar
Posts: 62
Joined: Wed Aug 25, 2004 4:48 pm
Location: Canada
Contact:

Post by jikbar »

i know what you mean.

just trying to use the string class in vc6 gives me about 200 errors or so. Apparently the compiler doesnt even like the keyword <template> :evil:
AssiDragon
Posts: 158
Joined: Wed Apr 28, 2004 11:03 am
Location: Hungary
Contact:

Post by AssiDragon »

Did quite so here too... :?
Staring through eyes of hate we kill
Are we controlled, or is our own will...?
(Edguy)
Post Reply