Tag Info

Hot answers tagged

42

I have worked extensively with a pure-C game engine that has shipped several products, so it is absolutely possible. Here's my personal experience with working in both C vs C++ engines: Using pure-C structures allows you to take advantage of knowledge about the alignment of structures, and you can then use this information to build your object persistence ...


36

Hide anything platform-specific behind abstraction layers This means stuff like rendering, audio, user input, and file IO. One common trick to abstracting that without inducing a run-time performance penalty is platform-agnostic headers with platform-specific implementation files: // FileSystem.h class FileSystem { public: FileHandle OpenFile(const ...


30

However, would writing an entire game engine in C be unreasonable today? It's reasonable, but the question is what does it buy you? You likely don't need the extreme portability C offers, and it's a shame to give up all of the features C++ offers unless you're really philosophically set against it. What are, if any, some advantages that C has over ...


21

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


19

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

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


13

The simple answer is no, you do not want to use the glutIdleFunc callback in a game that has some sort of simulation. The reason for this is that this function divorces animation and draw code from window event handling but not asynchronously. In other words, receiving and handing window events stalls draw code (or whatever you put in this callback), this is ...


13

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

Yes and no. Officially, the only thing you can use on the 360 with XNA is C#. You can't ship any unmanaged DLLs with an app on xbox live, and if you want to write your game in C, you need a dev kit and an impossible-to-get contract with Redmond. That said, anything you can compile into CIL that will run on the compact framework will be okay. If you can ...


11

You can find the video memory of an Nvidia card using the NVX_gpu_memory_info extension, or an ATI card using ATI_meminfo. Here is a snippet of code I found which might get you started. However, Paul Nettle at flipcode wonders why one would want to find the available video memory, saying: The reason it's difficult (and sometimes impossible) to ...


10

I am rewriting a 2D game engine written in C++ and Lua into C and Lua. So far the experience have been quite good. Obviously doing vector and matrix operations don't end up as nice looking in C. But apart from that I have found the experience quite refreshing after spending 10+ years as a C++ developer. C has a number of advantages over C++: The compiler ...


10

Assuming... you are talking about converting to a buffer of bytes You are using UDP and performance is a concern Try to avoid wasting space in your packet for defining structure. I.E. send, at minimum, a byte to denote the type of packet, then just assume each packet received follows the predefined structure for that type of packet Should I just read ...


8

I will try to answer this as best as I can, but there are certain "best practices" which I am unsure on, but I'll try to break it down as cleanly as possible. FSMs Firstly, the Miner tutorial is from Programming Game AI by Example by Mat Buckland (which I do recommend you get as an introduction to AI). He uses an enum for each state, NOT a struct. With the ...


8

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


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


8

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


7

Some color data will be lost or changed regardless of your texture format. However, a bigger problem will be gamma correction. Gamma correction can be a tricky subject since your game will not appear visually the same across all display technologies and finding a single solution is not going to be easy. These might help you out: ...


7

Card shuffling is an algorithm which is easy to write intuitively, and get entirely wrong by doing so. There's a good reference for implementing card shuffling correctly on Wikipedia. What I'm presenting here is a very slightly simplified version of the algorithm covered on that page under The modern algorithm. Here's the basic idea, in plain english: ...


7

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


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

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


6

Use an api like opengl/sdl which will give you minimum hassle when going from platform to platform. Make sure you know what platforms you want to support. Don't use opengl just because you think you might want to support multi platform in the future. Start as you mean to go on. Know what hardware limitations are on each of the platforms you want to support. ...


6

The "normalized" parameter affects the use of fixed point values. This doc says the parameter "Specifies whether fixed-point data values should be normalized (GL_TRUE) or converted directly as fixed-point values (GL_FALSE) when they are accessed." Further, this one states "For glVertexAttribPointer, if normalized is set to GL_TRUE, it indicates that values ...


6

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


6

Your guess is basically correct, and it's being done as an optimization (most likely; I can only speculate of course as I did not write the code). While an application in Windows appears to have full access to the entire range of RAM in the machine (or at least the range reported to it by the OS), in practice the OS is virtualizing an application's access ...


6

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


5

Were game makers only or most programmers? In the earliest days of arcade games, and later Atari home systems, Spectrums, and C64's you would often have 1-2 man teams where people all had multiple hats and nearly everyone could program. By the time you hit the NES and later the art requirements for games required people dedicated to that role full time, ...


5

You may find the Tonc Tutorials, which cover the GBA, quite interesting from a hardware history standpoint. I can also highly recommend the iPhone apps 2600 Magic and Dragster Magic for a look back even further toward the dawn of consoles. I can also recommend Steven Levy's book Hackers: Heroes of the Computer Revolution, which covers a lot of the game ...


5

Linear mapping is probably not the best solution (which I believe involves converting your RGB to a CIE colorspace, scaling there, and converting back), but it is very easy to implement, and the range difference is small enough it probably won't matter. If you use SOIL, it can automatically do this when loading the image, by passing SOIL_FLAG_NTSC_SAFE_RGB ...



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