Hot answers tagged

24

I think you're making this too complicated. The trick to preserving precision in your floating point numbers is just to keep their magnitude small. No chaining through doubles or two-stage fractional/whole conversion required. If you want millimetre accuracy, single-precision floats will keep that as long as your numbers are less than about 16 km. (If your ...


17

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


10

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


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

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


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

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


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


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


7

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

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

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

The most consistent way to do this is to use a fixed time step for your game logic. This avoids game logic oddities due to rounding errors when frame rate changes (collisions or events that don't happen or happen too often). Fixed Step: A typical fixed step loop would look like: Uint32 time_step_ms = 1000 / fps_the_game_was_designed_for; Uint32 ...


6

If you don't want a 2d array of chunks indexed by world position because the player might get very far away from the world origin or you might have negative indexes, then it might be worth to look at other data structures. A hash table with the coordinates as keys A 2-d tree which you auto-balance so that the root is always at the player (can also be useful ...


5

On windows, most people use visual studio and its build tools. Xbox 360 uses it as well. On just about everything else, some version of GCC is typically used. (PS3 & Nintendo consoles use a customized version of GCC)


5

I'd squeeze in another variable - cells travelled - it could act as your "planning" score. Base Given the core variables speed, length, cells travelled, the main formula could be: score = base * (length * speed) With base being: base = cells traveled; // basically, this could prove enough // optionally base *= board size coefficient; // a coefficient ...


5

If you are for some reason dead set on C, OpenAL may be the audio API to choose as it is a pure C API. OpenAL is a very low-level API. I'm unsure how it compares to DirectSound as I'm used to working with more complete frameworks/engines/games which tend to use something like FMOD or Wwise rather than trying to roll their own high-level audio manipulation ...


5

The vertex shader is called only 6 times, if you're drawing a full-screen quad using two triangles. I'm guessing that you're getting confused because the outputs of the vertex shader (here, the PixelInputType struct) are being fed as inputs to the pixel shader. What's going on is that those values are being linearly interpolated between the vertices, to ...


5

Yes. FBO, shader (changing the currently active program, not necessarily shader state itself) and texture state changes tend to be the most expensive. Conversely, vertex pointers and uniforms tend to be the cheapest states to change. It is almost impossible to actually calculate the expense of any one state change in modern GL implementations; you might pay ...


5

Imagine dots are doors and lines are corridors. This is how you can have three doors connected: There is no reason why you can't link a door to more than one other door. You can have corridors merge at some point. But oldskool roguelikes didn't even do this; they simply connected random pairs of rooms with corridors, and if they happen to cross into a room,...


5

SDL uses a type called SDL_RWops for this purpose. This is essentially a wrapper around a stream. When you call a function like IMG_Load(filename) it is just a small wrapper around IMG_Load_RW(ops) which constructs the ops using SDL_RWFromFile. You can create an SDL_RWops yourself (it's just a struct with some function pointers) if you have a custom stream ...


5

From the stb_image.h file itself: Do this: #define STB_IMAGE_IMPLEMENTATION before you include this file in one C or C++ file to create the implementation. You must not #define STB_IMAGE_IMPLEMENTATION in header (.h) files. Only in one C/C++ file to create the implementation (the stuff that has to be unique and done only once.) The header ...


5

In a comment I mentioned in passing that you could switch to representing 1024ths of meters instead of millimeters. That also helps with representability generally. Your code would look like this: int i = 1234567890; float f = ((float)i) / 1024.f; You don't need to worry about representability at all here. The temporary float value will already be the best ...


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