Bennu Game Development

Foros en Español => Mesa de Ayuda => Topic started by: Danielo515 on June 17, 2009, 12:27:45 PM

Title: Lista de hijos.
Post by: Danielo515 on June 17, 2009, 12:27:45 PM
Se puede acceder de forma recursiva a los hijos de un proceso?
Lo pregutno por si hay alguna forma ya pensada. A mí se me ocurre un array dinamico con las ids de los hijos, o acceder a todos los procesos e ir comprobando si la id de su padre es la misma id que la de mi proceso. ¿alguna otra sugerencia?
Title: Re: Lista de hijos.
Post by: Sandman on June 17, 2009, 02:03:56 PM
There is a local variable Son (http://wiki.bennugd.org/index.php?title=Son) and you can use it with Bigbro (http://wiki.bennugd.org/index.php?title=Bigbro) to obtain all the children of a process:

import "mod_proc"
import "mod_say"

Process Main()
Private
int sonID;
Begin
Proc();
Proc();
Proc();

sonID = son;
while(sonID)
say("Son: " + sonID);
sonID = sonID.bigbro;
end

signal(ALL_PROCESS,S_KILL);

End

Process Proc()
Begin
Loop
frame;
End
End
Title: Re: Lista de hijos.
Post by: syous on June 17, 2009, 02:11:44 PM
 ;D sandman you are crack

karma up
Title: Re: Lista de hijos.
Post by: Sandman on June 17, 2009, 02:23:40 PM
Thanks. :)

If you want to do a full recursion (preorder), you can do this:

import "mod_proc"
import "mod_say"

Process Main()
Private
int sonID;
Begin
Proc();
Proc();
Proc();

say("Preorder Search:");

Traverse_Offspring_PreOrder(0,id);

signal(ALL_PROCESS,S_KILL);

End

Process Proc()
Begin
Proc2();
Proc2();
Loop
frame;
End
End

Process Proc2()
Begin
Loop
frame;
End
End

Function int Traverse_Offspring_PreOrder(int level, int procID)
Begin

if(!procID)
return 0;
end

say( level + " > " + procID);

procID = procID.son;
while(procID)
if(procID.reserved.process_type != type Traverse_Offspring_PreOrder)
Traverse_Offspring_PreOrder(level+1, procID);
end
procID = procID.bigbro;
end

End


Note that if(procID.reserved.process_type != type Traverse_Offspring_PreOrder) is important, because else the Traverse_Offspring_PreOrder process is counted too. This is important for all levels.

[EDIT]
I edited the code, because it could go wrong if Traverse_Offspring_PreOrder() was called from a descendant.
Title: Re: Lista de hijos.
Post by: SplinterGU on June 17, 2009, 03:03:55 PM
Tambien existe smallbro
Title: Re: Lista de hijos.
Post by: Sandman on June 17, 2009, 03:44:13 PM
Modified the code a bit, because there were situations where it could have gone wrong.
Title: Re: Lista de hijos.
Post by: Danielo515 on June 17, 2009, 04:12:22 PM
Thanks sandman, karma up!