Sign in to follow this  
Batzer

Writing a simple Framework

Recommended Posts

Batzer    592

Hey guys,

 

I'm currently trying to write a simple 2D platformer with C++ & DirectX and it is going pretty well, but until now most of the code is in the WinMain of my program, thus it's getting realy hard to maintain. So I want to write my self a little framework to make the code more readable and maintainable, but I don't realy know how to structure the whole thing. My first Idea was to copy the design of XNA, because I like how easy it's to use. The problem is that I ended up having mostly small wrapper-classes that would require to have a getter-function so I could actually initialize the other classes.

As an example:

 

class GameWindow {
public:
    GameWindow(int width, int height, const std::wstring& title);
    HWND GetHandle() const; // I need this to initialize the swapchain
};

class Renderer {
public:
    Renderer(HWND window, int backBufferWidth, int backBufferHeight);

    // Need these to create buffers, shaders etc. and draw stuff ...
    ID3D11Device* GetDevice() const;
    ID3D11DeviceContext* GetContext() const;
};

 

I think these classes are near to useless, as they only initialize stuff and return them via getter-functions so I can actually use them.

So my question is: Do you guys have some useful tips on writing a framework? Or is my approach completely wrong?

 

I hope somebody knows how to help me smile.png

Share this post


Link to post
Share on other sites
Sock5    162

Yeah I have something similar - a renderer class that pretty much just encapsulates the device.Btw a word of advice - if it "is going pretty well", just stick with it, there isn't a right or wrong way really.Re-coding your framework from scratch is a mistake(speaking from experience).

Share this post


Link to post
Share on other sites
Batzer    592

You are probalby right. I spend way too much time thinking about how to do things and if it's the right way instead of just getting something finished.

The only problem is that I don't realy have a framework yet. I just put everything in the WinMain. So I guess my problem is that I get stuck the minute real OOP is involved :D

Share this post


Link to post
Share on other sites
Jason Z    6436

To be perfectly honest, I think you should create the objects that you mentioned, even if they are simple and just have helper functionality right now.  Once you have the bones of the framework created, then it will grow organically from there - at least that is how my framework evolved (its been running longer than 10 years!).

 

Give it a shot, see what works and what doesn't, then improve it and repeat.  You learn a ton this way, and you can make it work how you want it to.

Share this post


Link to post
Share on other sites
Dawoodoz    461

It becomes easier to maintain the code if you make your reusable engine in C++ and then call it with game specific code in a more safe language with garbage collection. I would not want a common mistake in a game prototype to crash the core of the engine from poor memory protection.

Share this post


Link to post
Share on other sites

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