Writing a simple Framework

Started by
3 comments, last by Dawoodoz 11 years ago

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

Advertisement

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).

>removed<

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

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.

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.

This topic is closed to new replies.

Advertisement