Design patterns and game development

Started by
8 comments, last by Lightness1024 11 years, 1 month ago

Hi there,

I'm currently returning to game development from my traditional software development, but years ago when I started with C and SDL I didn't care about design patterns at all, so now I found myself surrounded with their chaos and can't simply code without standing with one of them.

I don't understand which one fits better into game dev (MVC? Components? ... ), and indeed, I don't know many of them however.

So my question is, where to start in design patterns? I'm studying the library SFML with C++ right now, which is a language I had forgotten (And I hated) but industry right now almost force you to know C++, and I was very lazy with Java, so I need that change.

Thanks in advance.

Advertisement

Hi Puyover,

In my opinion, componentization has been a very good architecture design decision for games as it provides a lot of reusability as well as elegance. In games, try to prefer components over inheritance. I'll leave this references here:

http://cowboyprogramming.com/2007/01/05/evolve-your-heirachy/

http://www.richardlord.net/blog/what-is-an-entity-framework

http://www.richardlord.net/blog/why-use-an-entity-framework

Hope this helps!

Hi Puyover,

In my opinion, componentization has been a very good architecture design decision for games as it provides a lot of reusability as well as elegance. In games, try to prefer components over inheritance. I'll leave this references here:

http://cowboyprogramming.com/2007/01/05/evolve-your-heirachy/

http://www.richardlord.net/blog/what-is-an-entity-framework

http://www.richardlord.net/blog/why-use-an-entity-framework

Hope this helps!

Thank you skullfire, nice to know there is a pattern at least which is well established into game development tongue.png

I will give that articles a read.

Hi there,
years ago when I started with C and SDL I didn't care about design patterns at all, so now I found myself surrounded with their chaos and can't simply code without standing with one of them.
...
So my question is, where to start in design patterns?

Design patterns are simply patterns that are frequently observed in good (or bad) software.

People say "I did this thing lots of times", and name it, and talk about it publicly, and then it gets called a pattern.

You can read books or web pages on design patterns all you want, they will help teach you things you can do, and things that are not recommended.

The thing about the patterns is that they are useful in discussing what is going on.

Patterns are not some magical thing that you must use; they are just designs that people noticed were frequently found in code.

There are various wikis filled up with thousands of design patterns. If you don't have a design pattern that fits your goals, write a design of your own.

If you are building your code by trying to put together a few design patterns you are doing it wrong.

You should reason about your application, design it to fit your goals. If some of your design turns out to be a exact or very similar version of an existing design pattern, you name that code after the design pattern to make it easier to recognize this familiar pattern.

I have encountered a few people out there (very smart people) that have done some coding and when reading it, I discover a design pattern hidden by custom names. The very idea of design patterns is that they other developers should recognize them and thus having design pattern, but not organizing your code after it misses the very idea.

For example, if you are rolling a MVC architecture, split the application into one model, view and controller layer named just that. Don't create a bunch of files named x, y, z and make them behave as a design pattern. Of course this applies to class names/functions etc.

So my suggestion is to first think about the design from a bird's eye perspective, figure out what layers you want, often de-coupling / few dependencies is a goal for a well designed application.

Once you have that down, you can start to look if your solution would be or close to be a design pattern and make sure it is clear in your code.

For example, you might decide that you want 3 tier system that decouples the rendering, the logic and the data (http://en.wikipedia.org/wiki/Multitier_architecture).

For the rendering you decide a data-oriented component based system would fit best, while you roll a chain of command structure to handle the logic in the logic layer.

Also looking into the model you might decide to make it a more standard OO design of those since those are not run in an update loop and cause cache misses.

For communication between those layers you might find that the observer pattern is close to the design of the logic->data layer, while producer/consumer is more close to the rendering->logic layer.

This is pretty hard to get right from the start, it requires a lot of experience, which you only get by doing it. Good luck :)

Hi there,
years ago when I started with C and SDL I didn't care about design patterns at all, so now I found myself surrounded with their chaos and can't simply code without standing with one of them.
...
So my question is, where to start in design patterns?

Design patterns are simply patterns that are frequently observed in good (or bad) software.

People say "I did this thing lots of times", and name it, and talk about it publicly, and then it gets called a pattern.

You can read books or web pages on design patterns all you want, they will help teach you things you can do, and things that are not recommended.

The thing about the patterns is that they are useful in discussing what is going on.

Patterns are not some magical thing that you must use; they are just designs that people noticed were frequently found in code.

There are various wikis filled up with thousands of design patterns. If you don't have a design pattern that fits your goals, write a design of your own.

Yeah but naming something a pattern also allows a community to refine it to its purest and most robust form. like boost did with smart pointers for example. or iterators, optional, variants, destruction closures and wtf you name it...

Entities/components, seriously, this is not a pattern. a pattern is a factory, or a visitor. it is a part of the code. (a very small part)

entity/component however, is the paradigm you choose to code with. so instead of functional, or object oriented, or procedural, you will choose entity/component.

It is much higher over patterns for me, it is a paradigm. It encompasses your whole program, and you code into it, not the other way around.

though, same property, naming it will allow community to refine it.

I see one big issue, that was covered by some of the 3 links : adoption by peers in the same company. hem; the guy of tony hawks had an ONLY 3 year old code base, and very very understanding coworkers to finally go along with the adoption. Frankly, in my company, the chance of adoption is zero, yeah, the Kelvin absolute cold 0.

I find that wikipedia is a really good resource for reading about existing design patterns:

http://en.wikipedia.org/wiki/Software_design_pattern

Design patterns are not chaos. They clean up the chaos.

As far as your question, the series on Pattern Oriented Software Architecture (5 volumes), Design Patterns, and Game Engine Architecture are good resources.

Entities/components, seriously, this is not a pattern. a pattern is a factory, or a visitor.

I disagree. Entity-Component-System is a behavioral pattern that can be seen as an extension of the Strategy pattern, which is one of the early design patterns (found in "Design patterns").

[size=2]Current project: Ephenation.
[size=2]Sharing OpenGL experiences: http://ephenationopengl.blogspot.com/

Well. after all, I cannot deny that this is a design. On another hand, I can't deny that this has been seen and documented many times either, so it is a pattern. Therefore, in the end, it is a "design pattern" when you put the two words together.

However, I disagree with the comparison with Strategy, or maybe a reversed strategy then. Because strategy uses modular code. ECS uses modular data. So somewhat its the reverse. And I repeat why I don't like the comparison with any design pattern, because existing patterns until now don't concern the whole code base. ECS is one of a kind.

ps: Isn't it off topic ?

This topic is closed to new replies.

Advertisement