Talk:SDL:Tutorials:Simple Engine Framework

From GDWiki

Jump to: navigation, search

Thanks for the many edits and corrections! I don't know who to thank since only the IPs are showing, but thanks anyway whoever you are! ;)

--User:ostamo2 Is there a way we could show an example of using the engine by displaying a bitmap


PS. The MouseMove method doesn't include infomation about the mouse buttom states (the iButton-variable). iButton will alway be 0. I'll try to fix it sometime.

I also need to throw in some more error handling, making some functions const and use references to the variables in the functions for increased speed.

--Sion 12:41, 21 Mar 2005 (EST)


Regarding the removing of #include "SDL.h":

It's not really worth a revert, but it is good practice to include SDL.h in files where you use SDL functions/types, even if it's included an included header file.

- sik0fewl 18:25, 21 Mar 2005 (EST)

Contents

[edit] Suggestions And Improvements

I really like your approach of writing an engine, but wouldn't it be better to use: virtual void AdditionalInit() = 0 instead of virtual void AdditionalInit() {}?

Also I would suggest to declarate the virtual functions even in the CMyEngine class as virtual. Although it is not necessary most people prefer it, cuz this way you always keep in mind what kind of function this is.

Sorry for my bad language skills! AndreMagnus 10:39, 4 May 2005 (EDT)



Hey Andre, welcome to the GPwiki and thanks for your suggestions!

- To the question about virtual versus pure virtual, you are correct. It would probably be better to make them pure in order to force users to implement the functions. It would be even better to have the CEngine-class inheirit an interface-class (a pure virutal class), but I'll leave the structure as it is for now.

EDIT: I changed all the virtual function to pure virtual functions, and sat looking at the code for a bit. It then occured to me that I don't want to force people to implement functions like WindowActive and WindowInactive or even AdditionalInit and End. The user can just implement the functions he or she want.

- To the suggestion of making the implementations of the virtual functions virtual as well; good idea but it would undermine the stability of the class hierarchy. That would allow other class to inheirit the CMyEngine-class and make their own implementation of the virtual functions, but that also opens a lot of possible errors. To make it appearent that they are virtual functions, a uppercase "V" could be prefixed to the function name. Some developers use this approach to be able to tell normal and virtual functions apart. I'll leave it as it is. Making the functions virtual just to signify that they are implementations of virtual functions dosen't make much sense to me.

And your written english is fine! :)

Sion 17:10, 4 May 2005 (EDT)

[edit] Questions

Wot's the license for this code - i.e. GPL, BSD, public domain, some random terms for usage, or maybe I have to stand on my head and do three back-flips while whistling obscure dance club mixes backwards? :) --69.132.183.189 21:16, 4 Sep 2005 (EDT) Never mind, I just saw the notice about source copyright below as I was posting this.

I know that the source in the code that's in archive for you to download is required to be Public Domain, but I don't know about code that's actually on the page. It's either FDL or Pub. Domain. If you're reading this, you could ask in the forums. --Snoolas 14:58, 5 Sep 2005 (EDT)

[edit] FrameTickValue?

I was wondering what FrameTickValue is for since it is not used at all after it is defined. How do you control the fps? Thanks. --68.160.34.253 01:43, 11 December 2005 (EST)

You are exactly right. m_lFrameTickValue is not being used. It is a variable that I used for keeping the framerate steady, but now the engine uses time based calculations instead, so it's really just a left-over. The elapsed time since the last update is calulated in CEngine::DoThink(), and time is then passed to the concrete engines Think() method. It is then responsible for updating the logic according to the time passed. Here's the code that finds the elapsed time, it pretty straight-forward:
/** Handles the updating routine. **/
void CEngine::DoThink() 
{
	long iElapsedTicks = SDL_GetTicks() - m_lLastTick;
	m_lLastTick = SDL_GetTicks();

	Think( iElapsedTicks );

	m_iFPSTickCounter += iElapsedTicks;
}
Thanks for letting me know about the unused variable, I didn't mean to confuse you. I'll remove it right away :)
-- Sion 10:14, 11 December 2005 (EST)
No problem, thanks for clearing that up. --68.160.34.253 20:17, 12 December 2005 (EST)

[edit] WaitMessage()

Anyone got portable alternative for this? Can't be that SDL doesn't have something for handling things like this. --Enmoku 15:21, 5 June 2007 (EDT)

I'm running Linux and I was wondering this too. Does SDL_WaitEvent() produce the same results or does it not 'release some system resources'? Thanks. --DannyW 11:54, 27 July 2007 (EDT)


Destructor and atexit will lead to that SDL_Quit is twice executed.

[edit] Regulating framerate

In this example, how would you regulate framerate properly?

Thanks already!