Sign in to follow this  

C++ custom game engine using main() without user

This topic is 3302 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am working on a game engine that has beginners ( as if total newbs ) in mind ( but not limited to! ). It is designed to be simple to implement and simple to use. I have been showing a few people ( that I know ) the engine and wanting their input. It is also open-source. Anyway, the main() function is being used by the engine already and so is the game loop ( within the main() ) The game loop directs itself to these functions: GameUpdate(), GameDraw(), and GameLoading(). All you have to do is place your wanted game objects into GameInitialze() and make sure they are deleted withing GameKill(). No int main() required. However, one of the people I showed it to mentioned that typical game engines leave out main() for the user to place. So this is where my question begins: is it wrong to do this? Coding-wise. I personally understand where he is coming from, but I also personally don't see it as a big deal. What is your opinion on the subject? Thanks. :]

Share this post


Link to post
Share on other sites
Well, it is a game engine and not designed to make tools but I'm not saying it isn't possible to do so with it. But since it is open-source and under the Zlib license, it doesn't limit you. You have the rights to modify main() to your liking. Does this still provide a hindrance?

@Sneftel:
I am not entirely sure what you are stating.

Share this post


Link to post
Share on other sites
Quote:
Original post by PCN
@Sneftel:
I am not entirely sure what you are stating.
If you provide main() in your engine, you're making it extremely difficult to put the engine in a DLL, or run some other sort of startup code before invoking the engine, for the minor trade off of saving the user 4 lines of code.
If you don't provide main() as part of your engine, the only down side is that the user has to write 4 lines:

int main(int argc, char** argv) {
Engine engine;
return engine.Go();
}

But you're giving the user much more control.

Personally, I'd never write an engine that includes main().

Share this post


Link to post
Share on other sites
Yes yes everyone, he knows, and we all know, that it is not a good programming practice!

But that's not what he is trying for, he stated it was for total n00bs. And n00bs won't be packing it into a DLL, or writing tools for it.

I understand what you're trying to do, cool idea :)

Share this post


Link to post
Share on other sites
Quote:
Original post by Wavesonics
But that's not what he is trying for, he stated it was for total n00bs. And n00bs won't be packing it into a DLL, or writing tools for it.

I understand what you're trying to do, cool idea :)


What is the first and absolutely only thing a "noob" must learn if they wish to write C/C++ code?

Variables? For loops? Functions? Or something else?

Share this post


Link to post
Share on other sites
I suppose I did not make myself clear. I included main(), but it is taken over by game engine code. In main(), there are functions that direct to the given "framework". So you never have to look at main(), just the GameUpdate, GameDraw, etc. functions.

So the programmer doesn't have to write main() themselves.... at all.
My question was is this wrong to have the main() written already for users and not have it to be written.

Gah, I need to find better words to explain myself. >.>

:]

Share this post


Link to post
Share on other sites
What is suggested is that the Engine might have a Go() or Run() method that contains your current main, and then the user can simply only call that or do something else in main() as they like.

But I wonder, what the user has to write. What do you mean by "placing" game objects into a method and why should I look at GameUpdate etc?

Share this post


Link to post
Share on other sites
Quote:
Original post by PCN
Well, it is a game engine and not designed to make tools but I'm not saying it isn't possible to do so with it. But since it is open-source and under the Zlib license, it doesn't limit you. You have the rights to modify main() to your liking. Does this still provide a hindrance?


If the intention of the project is to solely be a game engine, why are you prefixing every method in your engine with "Game". Shouldn't it be implied since it's only a game engine that when we call Update, we're updating the game engine? Sorry, just a nit-pick thing. :)

Share this post


Link to post
Share on other sites
Quote:
Original post by PCN
My question was is this wrong to have the main() written already for users and not have it to be written.
Yes. [smile] Wrong and bad and not worthwhile.

EDIT: Which is not to say that you can't give them a ready-to-use main function in the documentation or a "start with this" source file. Merely that the user should be in control of program start-up.

[Edited by - Sneftel on December 3, 2008 2:45:32 PM]

Share this post


Link to post
Share on other sites
Thank you all for your answers. :]
I will immediately go and change that then.

What I meant by referring to GameUpdate, GameDraw, etc. is this:


do
{
//frame rate and other engine stuff
GameUpdate();
GameDraw();
}while( running );



So the user has to define them:


void GameUpdate()
{
float dt = GetDeltaTime();
//update all your objects here
}

...



So they never look at main() and they use this framework instead. But I'll go and change this. Thanks again everyone. :]

Share this post


Link to post
Share on other sites
That's actually a lot like GLUT's organization: GLUT is in control of the main loop, but the user defines functions to respond to various events (drawing, mouse move, etc.). You might take a page from how GLUT does the callback registration.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
That's actually a lot like GLUT's organization: GLUT is in control of the main loop, but the user defines functions to respond to various events (drawing, mouse move, etc.).

And this weird design is the main reason why GLUT has always been so heavily criticized. It makes it unusable for anything beyond the most trivial proofs of concept or tech demos.

Share this post


Link to post
Share on other sites
Quote:
Original post by Yann L
And this weird design is the main reason why GLUT has always been so heavily criticized. It makes it unusable for anything beyond the most trivial proofs of concept or tech demos.
Sure, because the set of programs it had to be suitable for was "anything that does graphics stuff", which is a pretty tall order. In a situation where the framework has a more limited scope -- say, a game engine -- it makes a lot more sense.

Share this post


Link to post
Share on other sites

This topic is 3302 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this