Sign in to follow this  

code orginization! help!

This topic is 4841 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 my fairly complex breakout clone, I have finished designing it, and I have enough coder art to get me started. So, I sit down and start coding... I now realize that this project is getting fairly big, and I am wondering what the best way to orgainize my code is. I would have like over 40 globals, and I can see how I can reduce it to one or two, by using a class based interface that is derived from a base interface object. I think you can do this with having a base virtual interface class. It would look something like this, right? class StateInterface { public: virtual void Create(void); virtual void Shutdown(void); virtual void SwitchTo(void); virtual void Render(void); private: };

Share this post


Link to post
Share on other sites
Yeah, that looks like it would work, though ideally, you'd have thought of this before you started coding. I'm having a similar problem with too many interdependant classes in an RPG engine. The only really good solution is to lay everything out before you begin coding so you don't run into this.

You may run into some sharing problems along the way, ie, d3d object pointer passing etc. but that shouldn't be too big a worry. And you can always get around that by making the more important pointers globals...

oh well.

Mushu - trying to help those he doesn't know, with things he doesn't know.
Why won't he just go away? An question the universe may never have an answer to...

Share this post


Link to post
Share on other sites
Hope this isn't too off-topic, but as a side issue, can reading an OOD book significantly improve your class design, or does that mainly come from experience?

I wrote a Pong clone in Allegro a few weeks back, and even though I tried to design it beforehand, after breaking down the actual result, I realised that I seem to make classes too specific, which makes code re-use quite difficult.

Funnily enough, PnP Bios, I'm at a similar stage to you. I'm close to starting a BreakOut clone, which I've attempted to design on paper. All I'm doing now, is trying to finish up the artwork and code up a few test runs of different things I don't know, so I don't end up making a hackish mess of it when I do get around to it.

Share this post


Link to post
Share on other sites
Quote:
Original post by Mushu
Yeah, that looks like it would work, though ideally, you'd have thought of this before you started coding. I'm having a similar problem with too many interdependant classes in an RPG engine. The only really good solution is to lay everything out before you begin coding so you don't run into this.

You may run into some sharing problems along the way, ie, d3d object pointer passing etc. but that shouldn't be too big a worry. And you can always get around that by making the more important pointers globals...

oh well.

Mushu - trying to help those he doesn't know, with things he doesn't know.
Why won't he just go away? An question the universe may never have an answer to...


the thing is... I am right at the point where I have to decide. I have all of my structures, all of the design considerations made.
I have the skills to do it either way, but I'm trying to think of a month down the road. I really want to use a state based system because I know how to encapsulate the data perfectly, but I don't like to use classes. I could use function pointers... but thats almost worthless unless I have a method for encapulating data...

Ok, I'm going with classes. Wish me luck.

Share this post


Link to post
Share on other sites
Quote:
Original post by Oluseyi
Quote:
Original post by Mushu
...ideally, you'd have thought of this before you started coding.
Meh. This is why we have refactoring now. Even with extensive up-front design, actual implementation reveals complexities we didn't forsee.


Smack yourself in the head, hard. While it is true that you cannot design your entire engine on paper before you start coding, spending even a little time fleshing out what subsystems you need and how they must interact will save you much time later - and may even prevent you from giving up on the project in disgust.

Share this post


Link to post
Share on other sites
I've already done this. I've already written a pre-version fot this pre-version. I have all of the collsion code working. This project is essentially a rewrite of a previous project. For this project, this issue is almost trivial. Basicly I flipped a coin and decided on going with a class implimentation. I could do either method if I had to.

off to code.

Share this post


Link to post
Share on other sites
I KNOW C++. I know why and when to use classes, for this very reason. I just havn't worked alot with interface classes. I just find normal C easier to work with for smaller projects. I thought my breakout clone was going to be simple.

What? Do I have to prove to everybody that I know C++ as well?

forget this. nobody else reply.

Share this post


Link to post
Share on other sites
Quote:
Original post by Oluseyi
Quote:
Original post by Mushu
...ideally, you'd have thought of this before you started coding.
Meh. This is why we have refactoring now. Even with extensive up-front design, actual implementation reveals complexities we didn't forsee.


Extensive up-front design also results in complexities of implementation that we regret, which is also why we have refactoring. :)

Share this post


Link to post
Share on other sites

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