GLBasic forum

Main forum => GLBasic - en => Topic started by: MrTAToad on 2009-Mar-05

Title: Pre/post initialisation and pre-finalisation calls
Post by: MrTAToad on 2009-Mar-05
Ocean and I thought it might be a A Good Idea if it was possible to call a user-defined function (if present) at the following stages of program execution :

A)  Just before the initial screen initialisation
B)  Just after the initial screen initialisation
C)  Just before the program terminates

The idea is that various things can be checked (and memory allocated) etc and exit the program (if needed) before the main screen appears.
The one just before the program terminates can be used to free any allocated memory.
Title: Re: Pre/post initialisation and pre-finalisation calls
Post by: Kitty Hello on 2009-Mar-05
GLBasic does all that for you. Why wouldn't it.
If you play with inline, things change.

I do it this way:

Code (glbasic) Select


FUNCTION PreInit:
// If you use any String functions here, you're in trouble!
ENDFUNCTION

FUNCTION PreQuit:
// Some GLBasic functions might break here, too
ENDFUNCTION

INLINE
class XXX
{
public:
   XXX() {PreInit();}
   ~XXX() {PreQuit();}
} __g_PreXXX;
ENDINLINE


Again, I really, really encourage you _NOT_ to use INLINE under any circumstances. If there's need for it, come here and ask. Either I give you a GLBasic way to do it, or I implement a function for you. INLINE is the very last way to do it. I know Ocean does a lot of INLINE where it's absolutely not required. The SIN/COS tables, e.g. can propably be written with pure GLBasic, too.
Title: Re: Pre/post initialisation and pre-finalisation calls
Post by: MrTAToad on 2009-Mar-05
Indeed - there could be occurances where you want the program to exit, but it would be a bit too ugly to do it just after the main screen has appeared.
Title: Re: Pre/post initialisation and pre-finalisation calls
Post by: Moru on 2009-Mar-05
wow, this was exactly what I was thinking of today. I want to be able to exit the program before the screen init if the screen isn't needed...
Title: Re: Pre/post initialisation and pre-finalisation calls
Post by: MrTAToad on 2009-Mar-05
It could be useful - the only downside is that it would probably not be used frequently
Title: Re: Pre/post initialisation and pre-finalisation calls
Post by: Moru on 2009-Mar-05
Hmm, since I'm not allowed to use any string functions it's not needed. The command line is a string and this is the only thing that I can think of that I would need to see if the program actually needs to run or not. This is for making screensavers. Windows sends "/p" on the commandline when it expects the screensaver to just display the preview in that small window. There is no meaning of starting a fullscreen application at this time since the whole screen will suddenly go black as soon as you choose the screensaver in the list.
Title: Re: Pre/post initialisation and pre-finalisation calls
Post by: Kitty Hello on 2009-Mar-06
You can do that with the main game function, too.
You can either display a dialog, using DDGui, or the screensaver in fullscreen mode. No big deal.