Questions tagged [design-patterns]

Design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.

339 questions
160
votes
8 answers

Why are MVC & TDD not employed more in game architecture?

I will preface this by saying I haven't looked a huge amount of game source, nor built much in the way of games. But coming from trying to employ 'enterprise' coding practices in web apps, looking at game source code seriously hurts my head: "What…
timoxley
  • 1,731
  • 3
  • 11
  • 9
139
votes
9 answers

What are some programming design patterns that are useful in game development?

I have a few books on Design Patterns, and have read some articles, but cannot intuitively figure out which programming design patterns would be useful in game development. For example, I have a book called ActionScript 3 with Design Patterns that…
jcurrie33
  • 777
  • 3
  • 7
  • 14
79
votes
10 answers

In Unity, how do I correctly implement the singleton pattern?

I have seen several videos and tutorials for creating singleton objects in Unity, mainly for a GameManager , that appear to use different approaches to instantiating and validating a singleton. Is there a correct, or rather, preferred approach to…
Zack Brown
  • 967
  • 4
  • 19
  • 30
55
votes
5 answers

How to avoid the GameManager god object?

I just read an answer to a question about structuring game code . It made me wonder about the ubiquitous GameManager class, and how it often becomes an issue in a production environment. Let me describe this. First, there's prototyping. Nobody cares…
Laurent Couvidou
  • 9,251
  • 2
  • 43
  • 58
43
votes
6 answers

When is the best time to consider performance?

I am coming from software development background. During the software development cycle, we usually focus on functionalities and the working product. At the end of development, we start optimizing the code and improving performance. Now the question…
34
votes
8 answers

Do retail games use "inversion of control" and "dependency injection"?

Many of the more diligent software developers I know are moving to inversion of control and dependency injection to handle references to objects. Coming from a Flash games perspective I don't know all the ins and outs of AAA studios, so: are these…
Iain
  • 6,568
  • 3
  • 36
  • 47
25
votes
4 answers

"The Game Object" - and component-based design

I've been working on some hobby projects the last 3-4 years. Just simple 2d and 3d games. But lately I have started a bigger project. Soo in the last couple of months I've been trying to design a game object class which can be the base of all my…
hayer
  • 596
  • 1
  • 5
  • 12
25
votes
2 answers

How to Interpolate between two game states?

What is the best pattern to create a system that all the objects positions to be interpolated between two update states? The update will always run at the same frequency, but I want to be able to render at any FPS. So the rendering will be as smooth…
AttackingHobo
  • 7,111
  • 4
  • 39
  • 48
24
votes
3 answers

Memory allocation patterns used in game development

I have been researching creating my own allocator methods (that will support things such as a memory pool and profiling), however, as I continue my research I have been looking for how this was done in game development. What memory allocation…
chadb
  • 485
  • 1
  • 4
  • 6
24
votes
1 answer

Why should I always consider creating and using object pools instead of instantiating the new object on the fly?

I have read about this pattern several times (from a best-practices perspective): Memory Allocation : Instead of instantiating the new object on the fly, always consider creating and using object pools. It will help to less memory fragmentation and…
Muhammad Faizan Khan
  • 2,116
  • 4
  • 34
  • 78
23
votes
3 answers

Command Ordering Architecture of Dwarf Fortress

What is the most elegant way to implement a command ordering system for AI? for example in dwarf fortress when you mark a forested area for wood cutting, the dwarfs then would do the following sequence: Go to the tree Chop the tree Deliver wood to…
jedt
  • 333
  • 2
  • 5
23
votes
2 answers

How to design context menus based on whatever the object is?

I'm looking for a solution for a "Right Click Options" behaviour. Basically any and every item in a game, when right clicked, can display a set of options based on whatever the object is. Right click examples for different scenarios : Inventory:…
Mike Hunt
  • 341
  • 1
  • 2
  • 6
22
votes
9 answers

How to create a user-friendly magic spell system?

I'm designing a small 2D top-down open-world survival-ish game with a magic spell system. The way it works so far: The player receives a "wand" at the beginning of the game As the player encounters new items and enemies, they gain spells to help…
Nico A
  • 321
  • 2
  • 6
20
votes
3 answers

Design of a turn-based game where actions have side-effects

I am writing a computer version of the game Dominion . It is a turn-based card game where action cards, treasure cards, and victory point cards are accumulated into a player's personal deck. I have the class structure pretty well developed, and I am…
20
votes
2 answers

Development pattern for interactive in-game tutorials

Interactive in-game tutorials often interrupt game flow and override standard behavior in a way that can be difficult to implement cleanly. For example, imagine we have an action game and we want a tutorial to play when the player first takes…
Kevin
  • 7,500
  • 1
  • 13
  • 36
1
2 3
…
22 23