Keep in mind, it may be hard to add saving and reloading if you rely
too heavily on the callstack.
Consider this.
void first_level()
{
second_level();
}
void second_level()
{
third_level();
}
void third_level()
{
fourth_level();
}
void fourth_level()
{
}
That is of course possible to save, provided you never return from a
level in order to return the player to a previous level.
Consider this, superior, method.
int id=0;\
void main()
{
while(true)// This loop runs forever
{
switch(id)
{
case 0:
first_level();
break;
case 1:
second_level();
break;
case 2:
third_level();
break;
}
if(id==-1)
exit();// Or you could return to the main menu if you like.
}
}
void first_level()
{
id=1;
}
void second_level()
{
id=2;
}
void third_level()
{
id=-1;
}
// In this way, saving becomes pretty easy and the callstack is never very high.
I like using classes for stages to be honest, their very flexible. You
definitely don't have to, though.
Hope I was at least some help.
On 8/31/14, john <[email protected]> wrote:
> The overflow point in bgt is 10000 calls. I was pretty much having functions
> call each other without ever using returns, so odds are I would have hit
> that limit before completing the game. I'm planning to do some
> restructuring, and hopefully I'll be
> able to at least heavily reduce the size of the stack. As a reference point,
> by the time the player would have finished approximately what I expect to be
> the first seen of the game, the call stack is around 400 function calls.
> This is also running on
> an early early setup of the game; so for all I know there's going to be a
> lot more functions added, which would have driven that number up even
> further.
>
> ----- Original Message -----
> From: Thomas Ward <[email protected]
> To: Gamers Discussion list <[email protected]
> Date sent: Sat, 30 Aug 2014 22:17:18 -0400
> Subject: Re: [Audyssey] clear call stack in bgt
>
> Hi John,
>
> I will answer your questions as best I can but I think you have some
> confusion over what the call stack is, how it works, and therefore may
> be worrying about nothing.
>
> First, as to your question there is no way to kill the stack with out
> killing the entire program. If your function that clears the stack
> returns there would essentially be nothing left in memory to return to
> resulting in a crash. Quite frankly put since the stack holds the
> memory address of every function and variable in your program if you
> kill the stack you might as well kill the entire program since there
> are essentially no functions and variables in memory to access.
>
> Second, as for creating the size of the call stack don't worry about
> it too much. If you are paranoid about this all you have to do is some
> very memory efficient coding such as instead of using a lot of global
> variables pass information by reference to functions and use local
> variables as often as possible. Every time a function returns the
> function itself is released from the stack, and any variables etc
> contained there in are also removed freeing up more memory on the
> stack for more functions and variables.
>
> I don't honestly see you having a serious stack overflow here, because
> BGT seems to have a reasonably large enough call stack for any game
> you can conceive of. Its not about how many functions you have in the
> program or how many times you call them. As I said every time a
> function returns the function is removed from the stack along with any
> pointers, objects, and variables it may contain in the local scope so
> its not like that stuff remains in memory forever. Sooner or later it
> will get removed from the stack making room for something else.
>
> That said, using loops like a while loop is more memory efficient than
> using recursion. In other words if you need to perform the same action
> multiple times instead of simply calling the same function over and
> over again, (recursion,) put it in a loop so that the function only
> gets called when a certain state is true, and if not the loop exits
> and the function can be removed from the stack.
>
> Cheers!
>
>
>
> On 8/29/14, john <[email protected]> wrote:
> HI all,
> As the subject suggests, I'm wondering if its possible to clear (or
> increase the size of) the call stack in bgt (or any programming language,
> for that matter). I'm having difficulty from keeping my projects from
> continually increasing the size
> of the stack, and while this would be just fine for a small program, I'm
> pretty sure my major project is going to go over 10000 eventually,
> possibly
> regardless of how perfectly the player performs. If there's no way to do
> this, are there any tips I
> can get as to how to make a program continue running without increasing
> the
> call stack, as I'm going to have to be constantly switching between
> functions, that need to be able to call each other a theoretically
> infinite
> number of times.
>
> ---
> Gamers mailing list __ [email protected]
> If you want to leave the list, send E-mail to
> [email protected].
> You can make changes or update your subscription via the web, at
> http://audyssey.org/mailman/listinfo/gamers_audyssey.org.
> All messages are archived and can be searched and read at
> http://www.mail-archive.com/[email protected].
> If you have any questions or concerns regarding the management of the
> list,
> please send E-mail to [email protected].
>
>
> ---
> Gamers mailing list __ [email protected]
> If you want to leave the list, send E-mail to
> [email protected].
> You can make changes or update your subscription via the web, at
> http://audyssey.org/mailman/listinfo/gamers_audyssey.org.
> All messages are archived and can be searched and read at
> http://www.mail-archive.com/[email protected].
> If you have any questions or concerns regarding the management of the list,
> please send E-mail to [email protected].
>
> ---
> Gamers mailing list __ [email protected]
> If you want to leave the list, send E-mail to
> [email protected].
> You can make changes or update your subscription via the web, at
> http://audyssey.org/mailman/listinfo/gamers_audyssey.org.
> All messages are archived and can be searched and read at
> http://www.mail-archive.com/[email protected].
> If you have any questions or concerns regarding the management of the list,
> please send E-mail to [email protected].
>
---
Gamers mailing list __ [email protected]
If you want to leave the list, send E-mail to [email protected].
You can make changes or update your subscription via the web, at
http://audyssey.org/mailman/listinfo/gamers_audyssey.org.
All messages are archived and can be searched and read at
http://www.mail-archive.com/[email protected].
If you have any questions or concerns regarding the management of the list,
please send E-mail to [email protected].