Everything should have a true/false flag
Everything should have a true/false flag
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?
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?
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;
}
}
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;
}
}
wholy moley!
T101, thnx for that! that is some seriously interesting stuff to dig in!
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!
T101, thnx for that! that is some seriously interesting stuff to dig in!
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!
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...
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 !
-
- Posts: 158
- Joined: Wed Apr 28, 2004 11:03 am
- Location: Hungary
- Contact:
Why need STLPort?
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)
-
- Posts: 158
- Joined: Wed Apr 28, 2004 11:03 am
- Location: Hungary
- Contact:
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.
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.
-
- Posts: 158
- Joined: Wed Apr 28, 2004 11:03 am
- Location: Hungary
- Contact:
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...
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)
Are we controlled, or is our own will...?
(Edguy)
-
- Posts: 158
- Joined: Wed Apr 28, 2004 11:03 am
- Location: Hungary
- Contact: