Tag Info

Hot answers tagged

210

There are a multitude of ways to represent and implement entity component systems, but here is an explanation of one way. Keep in mind there is no concrete definition of entity/component/system architectures, so this is just one implementation. I'm going to introduce an analogy for entity/component/system architectures that might help. Let's think of an ...


107

As the quote says, many programmers make the mistake of (trying to) build a system, not a game. Typically that system keeps ballooning out of control until it's so complex that theoretically it can handle anything, but in practicality all you have is a big bundle of code. Or more often, before you even get to a working stage, you are so tangled up in code ...


79

There are several reasons for that. I'm just gonna touch on a few: It makes your source code a mess. If you have a lot of dialog (trees), a huge part of your codebase is just text that has nothing to do with your actual game code. You'd need to recompile every time you change so much as a single character. The dialog itself is hard to navigate. I imagine ...


75

The main game loop handles three major tasks: Get user input Update the game state Draw the game A simple game loop just mushes these three tasks into one while loop. This has some undesired results: Game runs at different speeds on different computers. CPU (can be needlessly) pegged at 100% usage. "Game states"/menus are missing or mixed with game ...


66

// in entity_a's code: entity_b->takeDamage(); You asked how comercial games do it. ;)


58

Game Engine Architecture by Jason Gregory is a good book in this topic. You can read it in Google Books before buying it.


58

Good question! Before I get to the specific questions you asked, I'll say: don't underestimate the power of simplicity. Tenpn is right. Keep in mind that all you're trying to do with these approaches is find an elegant way to defer a function call or decouple the caller from the callee. I can recommend coroutines as a surprisingly intuitive way to ...


45

No it shouldn't. The only thing you'd be using from the inheritance is the x and y components. The methods used in a Vector2 class wouldn't be useful in a Vector3 class, they would likely take different arguments and perform operations on a different number of member variables.


43

I'd recommend Glenn Fiedler's article about robust framerate independence, "Fix Your Timestep!" (Less relevant to the topic at hand, but the other articles in the series are also quite good - as is everything on his site!)


41

When you need a single instance of a class throughout your program, we call that class a service. There are several standard methods of implementing services in programs: Global variables. These are the easiest to implement, but the worst design. If you use too many global variables, you will quickly find yourself writing modules that rely on each other ...


39

Unlike other art forms, vector art requires extremely high precision, making it unsuitable for many art styles. Basic shapes and such are easy using Vector art but it's just a pain to add small details which would be really easy to paint. So its kinda restricted to very simple "symbolic" styles. For everything else painting just works better. What vector ...


36

i want to implement it on my own to learn stuff. That's probably the most important thing. If your goal is to learn, writing your own rendering and game loop engines from scratch is fine, and a perfectly good learning experience. If your goal is to make a finished game quickly and easily, then use an existing framework.


35

This is an expansion of my comment to a full answer, as suggested. Yes, plain and simple. Communication needs to happen and while there are situations where 'Are we there yet?'-type polling is required, having things check to see if they should be doing something else generally wastes time. You could instead have them react to things they are told to do. ...


35

I initialize my services in my main application class and then pass them as pointers to whatever needs to use them either through the constructors or functions. This is useful for two reasons. One, the order of initialization and cleanup is simple and clear. There is no way to accidentally initialize one service somewhere else like you can with a ...


32

I think a kind of robust solution would be to go the object oriented way. Depending on what kind of achievement you want to support, you need a way to query the current state of your game and/or the history of actions/events the game objects (like the player) have made. Let's say you have a base Achievement class such as: class AbstractAchievement { ...


31

Vector graphics are usually more efficient than raster graphics for storage (ie. the filesize is smaller) but considerably less efficient for performance (ie. how much time it takes the computer to draw the image). In order to display an image the computer must rasterize that image (ie. calculate the pixels in the image). Since raster graphics are by ...


29

My book, Game Programming Patterns, is incomplete and on hiatus, but what I have is freely available online. You may get some use out of it.


29

First of all, you when build component-based systems, you don't have to take the approach of turning everything into a component. In fact, you generally shouldn't -- it's something of a neophyte mistake. In my experience the best way to tie together rendering and physics systems in a component based architecture is to make those components little more than ...


29

Putting game content data in code means that to see any potential change or iteration of that game content data, you have to recompile the game itself. This is bad for two reasons: Many languages that games are written in have long compile times. C++ is particular can be very bad in this respect, and C++ is a very common language for large commercial ...


28

I think you're just arguing semantics here. It's called Game State because it behaves like a Finite State Machine, with a finite number of states and transitions between them. The 'Game' in 'Game State System' refers to the overall system, with 'Loading', 'MainMenu' etc being states of the game. These could easily be called 'scenes' or 'screens' or 'levels'. ...


28

This excellent article covers a lot of the issues: http://www.gamasutra.com/view/feature/2029/developing_your_own_replay_system.php A few things that the article mentions and does well: your game has to be deterministic. it records the initial state of the game systems on the first frame, and only the player input during gameplay. quantize inputs to lower ...


25

Here's my original answer to a similar question on SO from a while back, at least concerning the MVC part of your question: It's rarely used in games. It took me a while to figure out why, but here's my thoughts: MVC exists to make a distinction between two representations. The Model is the abstract representation of your data. It's how the machine views ...


24

I somewhat support using an MVC structure even for a simple mobile game. If nothing else, it helps with an issue that plagues developers who haven't gotten bitten by it enough times: separating the display code from the game logic. I'll also say, though, to keep in mind that MVC, like all design patterns, exists to make your life easier. That means that ...


23

What you do depends on the nature of the achievement. Unless your achievements all fit a simple pattern (collect X number of Ys), you're going to have to special-case them to some degree. Using a message-based communication system, you can provide hooks that makes the special-case coding localized. You can have certain actions fire messages to listeners who ...


22

One of the tenants of TDD is that you let TDD in some cases influence your design. You write a test for system, then write the code to make that test pass, keep dependencies as shallow as possible. For me, there are only two things I don't test as part of unit testing: First, I don't test visual elements and how things look. I test that and object will be ...


21

The less experience you have, the more time you waste with up-front design. Making good designs is something that you will learn by doing it and then seeing/evaluating how it turns out. Some decisions have far reaching but obscure implications. After some games you will probably be able to make the initial design pretty solid and it will pay off to invest ...


21

C++ does everything C does. You can trivially mix C and C++ in cases where the advantages of C outweigh those of C++. This is a very intentional design decision of C++. C++ does things that C does not. This includes easy polymorphism, but also easy compile time code generation via templates. This is really handy for things like containers, which are ...


21

TL;DR: Your game objects do not know about each other, nor do they perform checks against other objects. You create a collision detection and collision resolution pattern that checks your game objects and performs the appropriate actions to simulate your game physics. The Good Stuff From previous attempts at writing collision detection and reading this ...


20

In an average game, there are hundreds or maybe thousands of obects in the scene. Is it completely correct to allocate memory for all objects, includiding gun shots(bullets), dynamically via default new()? That really depends what you mean by "correct." If you take the term quite literally (and ignore any concept of correctness of the implied ...



Only top voted, non community-wiki answers of a minimum length are eligible