Tag Info

Hot answers tagged

48

To say "Python is slow compared to C++" is a generalization that ignores a lot of real-world practicalities and is usually a poor kind of judgement to rely on. What you really want to do is look at what a particular language or technology can bring to the table in terms of your needs and, similarly, evaluate any potential downfalls of that technology against ...


40

For example having a GameObject base class with a deep inheritance hierarchy could be good for maintenance... Actually, deep hierarchies are generally worse for maintainability than shallow ones, and the modern architectural style for game objects is trending towards shallowing, aggregation-based approaches. However I think this approach can ...


34

The large penalty from mixing ints (of any kind) and floats is because these are in different register sets. To go from one register set to the other, you have to write the value to memory and read it back, which incurs a a load-hit-store stall. Going between different sizes or signed-ness of ints keeps everything in the same register set, so you avoid the ...


30

It will cause one CPU core to always run on 100%. This usually doesn't cause any harm to the system. CPUs are designed to run on 100% for hours. But on a mobile device it will drain the battery quickly and heat up the device, which will likely cost you about a stars in your store ratings. On a desktop computer this is less of a problem, but it will consume ...


27

Console: static hardware that never varies across every single iteration. Home PC: hardware that changes from day to day, with a million different chip designs. Console: closed system that lives in its own, secure environment from birth to death. Home PC: wild west, barroom brawls and your OS is the sheriff keeping everyone from getting shot. Carmack: ...


27

This would depend on the game and the indexing structure used for the chunks. Though, at such a high level, it's not too likely it has much to do with memory or a specific performance enhancement. More than likely it's an arbitrary decision for sizing chunks in a predictable way. It allows for some counting and indexing tricks using bit shifting that ...


23

If you need something that stays linear over any distance (unlike distance^2) and yet appears vaguely circular (unlike the squarish Chebyshev and diamond-like Manhattan distances), you can average the latter two techniques to get an octagonally-shaped distance approximation: dx = abs(x1 - x0) dy = abs(y1 - y0) dist = 0.5 * (dx + dy + max(dx, dy)) Here is ...


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 problem is not with performing the distance function. Your problem is performing the distance function so many times. In other words you need an algorithmic optimization rather than a mathematical one. [EDIT] I am deleting the first section of my answer, because people are hating it. The question title was asking for alternative distance ...


19

One big upside to C++: If you decide to do so, it'll be relatively easy to port to Android/PC/DS/PSP/(insert platform of choice here). Objective-C will lock you into iOS until you decide to rewrite the entire game.


19

I like to think of performance in terms of "limits". It's a handy way to conceptualise a fairly complicated, interconnected system. When you have a performance problem, you ask the question: "What limits am I hitting?" (Or: "Am I CPU/GPU bound?") You can break it down into multiple levels. At the highest level you have the CPU and the GPU. You might be CPU ...


18

Once it's in memory, verts are verts.


18

Is there a substantial overhead to allocating / deallocating VBOs (I mean the mere act of setting up a buffer)? Define "substantial." It is generally wise not to create them in the middle of frames; they should be set up during initialization or wherever. But this is true of most OpenGL objects, like textures, renderbuffers, or shaders. If I'm ...


17

Sometimes this question can arise not because of the cost of performing distance calculations, but because of the number of times the calculation is being made. In a large game world with many actors, it is unscalable to keep checking the distance between one actor and all the others. As more players, NPCs and projectiles enter the world, the number of ...


15

There are no real pros or cons here, at least none that should force a programmer comfortable in one language to have to use the other. Performance shouldn't be an issue. It's unlikely that you'd write any heavy lifting with lots of messaging in the inner loops if you're a good Obj-C programmer, which means you'll really be writing those inner loops in C. ...


15

Direct3D drivers on Windows are ridiculously optimized, sometimes for specific games, and developed by individual hardware vendors. Apple's OpenGL drivers are written and maintained (AFAIK) by Apple, and are intended for "general" OS use, compositing the UI and whatnot. There's no so much optimization for gaming and high-performance throughput. Basically, ...


15

The way OpenGL works, whenever you use non-VBO data, the driver has to make a copy of it - in practice creating a temporary VBO - since nothing stps you from modifying your user-space naked arrays between calls to OpenGL. There may be some driver-side trickery to make the temp allocation faster, but there's nothing you can do to avoid the copying. So yeah, ...


15

Luckily, as you pointed out, the COMPACT Mono builds use a generational GC (in stark contrast to the Microsoft ones, like WinMo/WinPhone/XBox, who just maintain a flat list). If your game is simple the GC should handle it just fine, but here are some pointers you might want to look into. Premature Optimization First make sure this is actually a problem ...


15

First, multiplying by powers of two is much cheaper than multiplying by an arbitrary number, since you can do it by bit shifting. Most of the time the compiler can do this for you, so whenever you write "* 16" in your code, the compiler actually does a shift by four, and you don't need to worry about it - you just need to give the compiler the opportunity by ...


14

Yes, it is. Allocation time isn't the only factor. Allocation can have side-effects, such as inducing a garbage collection pass, which can not only impact performance negatively it can also impact performance unpredictably. The specifics of this will depend on your language and platform choices. Pooling also generally improves locality of reference for the ...


13

1. There is no general best practice. If you got a lot of (complex shaped) elements, particles etc. in your game, the bitmap buffer approach is going to be much faster. The bitmap buffer will also scale better with increasing complexity of your sprites. The vector renderer will become slower with more complex shapes or tween (shape tween) animations, it ...


13

Use one of the common space partitioning algorithms, such as a Quadtree, Octree, BSP tree, or even a simple Grid System. Each has their own pros and cons for each specific scenario. You may read more about them in these books. Generally (or so I've heard, I'm not too familiar with the reasoning behind this) a Quadtree or Octree is better fit for outdoor ...


13

Is there any notable performance between Vector2s and Vector3s, for example when adding or multiplying them, or when calling Normalize, Transform, or Distance? Yes, you have one more coordinate so you will use more CPU cycles. But it is very unlikely that it will ever give you any trouble. XNA 4 is using SIMD extensions for vector math (EDIT: on ...


13

Are associative arrays a good idea for games? Perhaps, depending on your needs. However, you need to differentiate between comments about "associative arrays" and specifically about the class std::map. Associative Arrays Associative arrays are just some kind of data structure that allows you to associate one kind of value with another, such that you can ...


13

getBodiesToCheck() There could be two problems with the getBodiesToCheck() function; first: if(!contains(bodiesToCheck, b)) bodiesToCheck.push_back(b); This part is O(n2) isn't it? Rather than checking to see if the body is already in the list, use painting instead. loop_count++; if(!loop_count) { // if loop_count can wrap, // you just need to ...


12

It just means that the game matches the refresh rate of the monitor/screen. So if you have a 60Hz monitor (meaning the monitor image is refreshed 60 times a second), the game won't perform above 60 FPS. If you have vertical synchronisation (vsync) turned off, then if the GPU and monitor go out of sync, then you get an artifact commonly known as "tearing" ...


12

You want a better communication protocol then HTTP. You probably want UDP or TCP. Browsers have no way of doing UDP communication so your only choice is TCP. For TCP you would want to use a WebSocket, however browser support is unstable on websockets. This means you would need to use a COMET technique to emulate TCP, one popular emulation would be a ...


11

It may be more useful to create a diagram showing frames per second over a period of time. Ideally this diagram contains annotations about what happened in the world, for example changes of areas, starting and ending of fights. In the sample diagram it is easy to see that the frame rate is a lot better in the home town than in the dungeon. And there seems ...


11

While I won't discount the optimization that Microsoft may have put into Windows and/or DirectX, I strongly believe that most programs perform better on Windows simply because that's what the developers focus on (that's where the money is). They make design decisions with Windows in mind, and then later try to make it work in other OSs (Mac, Linux, etc.). ...


11

It depends on the CPU in question, but for a modern CPU the list is something like this: Bitwise, addition, subtraction, comparison, multiplication Division Control flow (see answer 3) Depending on CPU there may be a considerable toll for working with 64 bit data types. Your questions: Not at all or not appreciably on a modern CPU. Depend on CPU. That ...



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