Hot answers tagged

29

The answer depends a bit on what you mean by "game", and on "used". I'll assume "used" means "written during the course of the specific game project". In my experience and anecdotal data from people I've talked to: in browser based games? None. in typical PC games? None. (But you might see some in low level libraries.) in iOS and Android games? None. "AAA" ...


28

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


26

The bulk of high performance code in modern console games is written using a sort of middle ground between assembly and C++: compiler intrinsics. These constructs look and parse like C++ functions, but are actually translated into single machine instructions. So, for example, my "clamp each value of vector V to be >= a and <= b" function looks like // ...


16

Sure you can, it's just not trivial to get it sounding "nice". I don't know how to do it in Linux, but if you can play a PCM buffer, all you have to do is fill it with whatever you want. So supposing your buffer is set to play in monaural, signed 16-bit samples, at 44100 samples per second, creating a pure (sinusoidal) A4 sound (440 Hz) is as simple as ...


15

How I'd probably do it so I could maintain some art control and not potentially spend a long time trying to tweak a procedural method to get it just right... First, manually create a number of sprites of tea leaf clumps as your art "pool" - not each as an entire cup's worth of tea leaves, but more like a smaller grouping. Say, 20 of them or so? Then place ...


12

Why at a certain point in time the industry switched massively to C++ ? What are the reasons for the choice that ID made ? Id Software is not "the industry". They are one company. While they may be influential, they aren't everyone. I've worked on a couple of game engines that date back to 1999, and they used C++. The principle reasons for the adoption of ...


11

Your interpretation of fp:fast vs fp:precise sounds suspicious; I'm sure there's more of an effect than just rounding error after the 16th decimal place. I refer you to Bruce Dawson's article on floating point precision for more details. In general, floating-point precision error is definitely a real problem in game development. It's especially troublesome ...


10

Many non-PC platforms, including some consoles and handhelds, use a modified GCC as their primary/only compiler. On the PC, most game dev houses just use Visual Studio's compiler. The choice of compiler typically has little impact on runtime speed compared to engine design and graphics, they all paid for Visual Studio anyway due to its feature set as an ...


9

Intel's compiler is just a different compiler. GCC++ and VC++ produce production quality code, just as well as Intel's ICC does. The main difference lies in 4 key areas: a) Features supported (mostly differing on C++11 features) b) Executable size c) Runtime d) Compile time When you're trying to squeeze every last bit of performance out of (mostly) Intel ...


9

Yes, it's possible. No its not a dumb idea. In fact many of the older racing games did something similar. Super Mario Kart is one example. The rendering uses 2d sprites in 3d space instead of polygons, but the physics engine is all 2d.


8

Your problem is the order in which you specify your vertices and texture coordinates: glVertex3f(0, 0, 0); glTexCoord2f(0.0, 0.0); should be: glTexCoord2f(0.0, 0.0); glVertex3f(0, 0, 0); OpenGL is a state machine, and in immediate mode, whenever you call glVertex3f the vertex will take on the different attributes (color, texture coordinates, etc.) ...


8

You are looking for a scripting language that can be embedded into your application. That is, a language which is designed to be interpreted at runtime (in many cases quite efficiently) and can be used to allow user extension of your native code written in C/C++/ObjC. There are many to choose from. Lua and Python are two quite popular ones, particularly ...


8

You could think of individual places as "rooms" with "doors" connecting them: To implement this, you could create a struct Room to hold a room, with fields for a set of items currently in it and what directions its exits lie in. Then simply keep an array of all rooms and have a pointer to the one the player is currently in. There are ways of getting extra ...


7

Try perlin noise with a binary cutoff value of 0.8 or so? Uploaded example image to http://imgur.com/a/Ydc4y . The first is the second image with a threshold applied. The second is basic perlin noise, for which you can find multiple good references such as http://en.wikipedia.org/wiki/Perlin_noise and http://http.developer.nvidia.com/GPUGems2/...


7

The problems that used to require hand rolled assembly are getting fewer in number. What you "might" gain in speed you lose in readability and the ability to debug. It should also be done only as one of the very last optimisation steps on sections of code as in most cases speed problems aren't something that can't be made better with assembly. These days CPU'...


7

It's also interesting to note that the ID software decide to completely rewrite the codebase for the IdTech 4 in C++, a massive amount of work that honestly i can't understand without a really good list of reasons. It's been common for them to rewrite pretty much the whole engine for every release (at least until recently - I don't know much about the last ...


7

Update for November 2018 LLVM/Clang is the primary (or only) compiler for many gaming platforms these days. iOS, Android, PlayStation 4, MacOS/OSX, and Nintendo Switch all use Clang as their default native compiler. XBox One is only supported by Microsoft's compiler, and their compiler is also still the most commonly used for Windows. A handful of legacy ...


7

You haven't set a diffuse colour for your light (via glMatrialfv (GL_DIFFUSE, ...) and - according to the GL spec - the default diffuse colour is {0.8, 0.8, 0.8, 1.0} - i.e. light grey. You also haven't set an ambient colour (default {0.2, 0.2, 0.2, 1.0} - dark grey). The default behaviour of lighting is that it multiplies by the current colour, so with an ...


7

It's not dumb, but realize that car/racing physics are very different from traditional game physics. You're not going to be able to just drop in Box2D. Traction, handling, acceleration, braking, etc. are all going to need a good deal of special casing. It'll likely be a lot easier sticking to 2D collision handling, of course, but collision is hardly going ...


6

Box2D is very popular and well documented with lots of examples. Of course it's a full on physics library so it'll give you a good amount of flexibility for expanding later if you want. But you don't need to use those features if you don't want them. For learning more about the algorithms and how to implement them yourself you can check this out. ...


6

Fabian Sanglard has some excellent code reviews of id's C engines, such as his Quake 2 code review. It's a good reference for how a reasonably "modern" game was written in C.


6

I'm not entirely sure that you understand what the article means by a fixed timestep. requestAnimationFrame is defined as: Tells the browser that you wish to perform an animation; this requests that the browser schedule a repaint of the window for the next animation frame. The amount of time that passes between each invocation of the function varies ...


6

The u[3] is a 3x3 rotation matrix mapping from the OBB's local space to world space. The three elements are the vectors that the x, y, and z axes of local space end up being mapped to by the rotation. So your guess was somewhat correct - the vectors do point to the center of each of three perpendicular sides of the OBB. However, they are unit vectors; the ...


6

It's not only possible, it's actually been done. More than once. OK, I wouldn't go so far as to call out early id Software code as the epitome of good coding standards, but it does demonstrate that using DirectX in pure C isn't something that exists on a theoretical level, but rather something that has shipped in popular working commercial products. ...


6

In broad terms, there are a few standard architectures for networking systems. In terms of topology, you have: Client-Server: All clients talk to a single server, which may be a dedicated server executable, or may be another copy of the game, just operating in "server mode". (this is the one you mentioned) Promiscuous Peer-to-Peer: Every peer talks ...


6

It depends on what level of physics realism you are aiming for. If you're fine with a Mario-kart type of racing game, then you won't have much trouble with a 2D physics engine. But if you want a top-heavy vehicle to roll over when it goes around a sharp turn at high speed, then you will need 3D physics.


6

In SDL2 the creation of the window is separate from the rendering environment used to draw into that window. So, while you might pass "SDL_WINDOW_OPENGL" to SDL_CreateWindow(), this simply states that the window should support rendering from an OpenGL context later down the line and doesn't actually create an OpenGL context at that point. So, from ...


6

For future readers, here is what I did in order to handle multi key inputs with ncurses : I realized you can call getch() multiple times during a frame, and it will return a different key each time as long as there are other key pressed. For example if I am holding keys 'A', 'B', and 'C', three calls to getch() will give me the 3 different keys, and the ...


6

As a pattern ECS and data oriented programming in general are closer to pure C than C++. Entity component systems consist of three major elements. Components are simply holding data; they shouldn't hold any logic. A simple struct should be enough to model them in C. Systems is where all your logic lives. Finally, Entities don't hold anything (logic or ...


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