Jump to content

  • Log In with Google      Sign In   
  • Create Account

Writing a simple Framework


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Batzer   Members   -  Reputation: 259

Like
0Likes
Like

Posted 03 April 2013 - 05:58 PM

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



Sponsor:

#2 Sock5   Members   -  Reputation: 162

Like
0Likes
Like

Posted 03 April 2013 - 10:15 PM

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<


#3 Batzer   Members   -  Reputation: 259

Like
0Likes
Like

Posted 04 April 2013 - 11:02 AM

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



#4 Jason Z   Crossbones+   -  Reputation: 5284

Like
0Likes
Like

Posted 04 April 2013 - 04:02 PM

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.



#5 Dawoodoz   Members   -  Reputation: 331

Like
0Likes
Like

Posted 05 April 2013 - 05:06 AM

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.


My open source DirectX 10/11 graphics engine. https://sites.google.com/site/dawoodoz

"My design pattern is the simplest to understand. Everyone else is just too stupid to understand it."





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS