Jump to content
  • Advertisement
Sign in to follow this  
Eralp

Game Engine (C++)

This topic is 3935 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

Hi, I'm trying to write my game engine. But I dont even know If I'm following the right way.. Let me explain;I am creating the input,sound,d3d.. in seperate files as classes, they all have initialiaze() and clean() functions and special functions,and I have an engine class that includes all of the other classes like input,sound and d3d. In its initialiaze function, I call all of the initialiaze functions of the member classes and in the clean() I follow the same way. Till now I explained you about my engine and the question is, do I do something "at least" acceptable :) ? And here comes the more specific question. I can't continue to writing without it :/. I have a Map class and it loads "level" files. In level files(i.e. "level1.mlvl") in the first line there is an integer which is "the number of the sprites that will be used in this level".And the following lines there are file names that will be used to load sprites. there is a LoadSpriteFromFile(string filename) function in 3ddrawing class but I cant use it from my Map class! TO SHORTEN: I have a X class that contains Y and Z classes and I cant use Y.sth() function from Z class..

Share this post


Link to post
Share on other sites
Advertisement
You probably should not be writing an engine.

Quote:

Till now I explained you about my engine and the question is, do I do something "at least" acceptable :) ?

What you've described is far too general to comment on, although it's entirely possible that having "init" and "clean" functions is just useless interface homogenization that you do not actually require (why can't you use constructors and destructors; your entry and exist points are already controlled?)

Quote:

there is a LoadSpriteFromFile(string filename) function in 3ddrawing class but I cant use it from my Map class!

TO SHORTEN: I have a X class that contains Y and Z classes and I cant use Y.sth() function from Z class..

You need an instance of a class to call a non-static member of that class. Your load functions are improperly designed, as they should not require an instance (as such, should not be members), but should rather return them.

Without more information I cannot provide more answers.

Share this post


Link to post
Share on other sites
Hmm I think you are right its very general question but I cant explain it more, its hard :)

And I bet there are many different ways of creating engines but can you reply to my first question? Is creating all parts of the engine in seperate classes and than binding them in one single class acceptable? Or should I change my point of view?

Share this post


Link to post
Share on other sites
Quote:

And I bet there are many different ways of creating engines but can you reply to my first question? Is creating all parts of the engine in seperate classes and than binding them in one single class acceptable? Or should I change my point of view?

I already did. It's probably not; it's too monolithic an approach, suggesting too many "manager" type objects that are frequently not a good idea. Without specifics, it's hard to tell. Frankly, the nature of your questions suggest to me you you're out of your depth.

Write what you need to produce whatever game you have in mind. What you actually need, right now. Rarely do you actually need all those listed subsystems up and running at once.

Share this post


Link to post
Share on other sites
Quote:

Original post by Eralp
TO SHORTEN: I have a X class that contains Y and Z classes and I cant use Y.sth() function from Z class..


So pass Z a reference to Y (either in the constructor or in a member function, whichever is more appropriate in your situation).

Quote:

Original post by jpetrie
Your load functions are improperly designed, as they should not require an instance (as such, should not be members), but should rather return them.


What do you mean? Why can't LoadSpriteFromFile() be a member function (for example, of a class that manages a cache of sprites to save memory)?

Share this post


Link to post
Share on other sites
I actually dont have to write an engine, yes you are right but I think OOP is very enjoyable :) so I want to use all of my OOP knowledge.. I once wrote a game with directx and c++ but it was very bad programmed, though it was smooth and it ran fast.So I dont want to repeat it.I didnt even know a thing about pointers at that time or vectors.. :)

Share this post


Link to post
Share on other sites
Quote:
Original post by Gage64
So pass Z a reference to Y (either in the constructor or in a member function, whichever is more appropriate in your situation).


I though of that too to pass a reference, but what would it be if I pass all of the classes to all of the classes. And I want to pass the ONE class that has been initialiazed by the main engine class.Do single-ton classes solve my problem, u think?

Share this post


Link to post
Share on other sites
Quote:
Original post by Eralp
I though of that too to pass a reference, but what would it be if I pass all of the classes to all of the classes. And I want to pass the ONE class that has been initialiazed by the main engine class.Do single-ton classes solve my problem, u think?


Definetly not.

Do you really need all the classes to have access to all the classes? If the answer is yes, then your design is way too coupled and you need to rethink it.

Share this post


Link to post
Share on other sites
Quote:
Original post by Gage64
Quote:
Original post by Eralp
I though of that too to pass a reference, but what would it be if I pass all of the classes to all of the classes. And I want to pass the ONE class that has been initialiazed by the main engine class.Do single-ton classes solve my problem, u think?


Definetly not.

Do you really need all the classes to have access to all the classes? If the answer is yes, then your design is way too coupled and you need to rethink it.


Actually I dont need all the classes to have access to all the classes but I have a question in my mind "What if I have to when I continue my project?" cuz when you do something than you can repeat the same solution.

Thank you for your helps I will take my time reading the links you provided.
See you

Share this post


Link to post
Share on other sites
Quote:

What do you mean? Why can't LoadSpriteFromFile() be a member function (for example, of a class that manages a cache of sprites to save memory)?

Because of the Single Reponsibility Principal, and because object-obsession is counterproductive.

A class that caches resources dilutes its responsibilities by becoming a class that loads resources (sprites) as well. Especially as the number of resource types loaded increases; the class becomes a container for caching logic as well as for resource-type-specific format marshalling.

Object-obsession is about turning everything into an object and everything else into a member function. Member functions should represent semantic actions corresponding to the object model; nothing in the real world can "load" itself from something else, completely re-inventing it's state, so a sprite should not have a "Load" member function or similar. Loading is a process of creation, and should be expressed as such by the loading method being external -- a non-member of some kind. Even disregarding attempts at real-world analogy (which are not always justified), writing a loading method as a member function also decreases encapsulation and maintainability -- for example by requiring the object to be implemented as a 'resetable' object, which introduces a lot of extra pitfalls.

Quote:

I actually dont have to write an engine, yes you are right but I think OOP is very enjoyable :) so I want to use all of my OOP knowledge.. I once wrote a game with directx and c++ but it was very bad programmed, though it was smooth and it ran fast.So I dont want to repeat it.I didnt even know a thing about pointers at that time or vectors.. :)

Writing an engine isn't the only way to practice OO design. Writing a game suffices perfectly well -- if not better. Don't completely abandon the work you did on your previous game. Revisit it and determine what worked well (and reuse that) and needed tweaking (and tweak that).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!