Tag Info

Hot answers tagged

72

Culling is a performance optimisation. So it doesn't make sense to just do it just for the sake of it. You have to have a reason. The GPU (not the XNA Framework) culls triangles and pixels at blindingly fast speed. Every triangle you submit must be transformed (via your vertex shader). Then it culls the ones that land off screen. Then it fills the ...


64

With regards to Java vs C++, I've written a voxel engine in both (C++ version shown above). I've also been writing voxel engines since 2004 (when they were not vogue). :) I can say with little hesitation that C++ performance is far superior (but it is also more difficult to code). Its less about the computational speed, and more about memory ...


58

Optimise your data layout! (This applies to more languages than just C++) You can go pretty deep making this specifically tuned for your data, your processor, handling multi-core nicely, etc. But the basic concept is this: When you are processing things in a tight loop, you want to make the data for each iteration as small as possible, and as close ...


56

A very, very low-level tip, but one that can come in handy: Most compilers support some form of explicit conditional hinting. GCC has a function called __builtin_expect which lets you inform the compiler what the value of a result probably is. GCC can use that data to optimize conditionals to perform as quickly as possible in the expected case, with ...


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


32

Having a single big file has a few benefits for performance, regardless of platform. Many PC games use big files too. You can manually cache the offset of each file within the big file, to avoid the need to read file system directory entries (which can involve multiple seeks per file opened if you miss the cache). You get full control of the order of the ...


28

First step: Think carefully about your data in relation to your algorithms. O(log n) is not always faster than O(n). Simple example: A hash table with only a few keys is often better replaced with a linear search. Second step: Look at the assembly generated. C++ brings a lot of implicit code generation to the table. Sometimes, it sneaks up on you without ...


28

Most of the size used by any game lies in its assets, most notably, audio, video and (to a slightly lesser degree) images/textures. Binaries and game data is typically much smaller than any of those. Then, all of these assets may or may not be compressed, may use different compression schemes, may have different formats, and even have different ...


28

Deferred shading is only a technique to "defer" the actual shading operation for later stages, this can be great to reduce the number of passes needed (for example) to render 10 lights which needs 10 passes. My point is regardless of the rendering technique you are using there are certain possible rendering optimizations that reduce the number of objects ...


23

(C-ish pseudocode - adapt language optimizations as appropriate) bool DoBoxesIntersect(Box a, Box b) { return (abs(a.x - b.x) * 2 < (a.width + b.width)) && (abs(a.y - b.y) * 2 < (a.height + b.height)); } In English: On each axis, check to see if the centers of the boxes are close enough that they'll intersect. If they intersect on ...


23

All AI is search! When you get into the guts of AI it's amazing how much of it is really search. state: the remaining cooldown of all available spells. fitness: total damage done cost: total time taken branches: any known spell. If spell is still in cooldown just add that value to its cast time. goal: total health of target. The goal has to be a ...


23

This sounds like a job for a grid. Divide your game space into a grid and for each grid cell keep a list of the objects currently in it. When objects move across a cell boundary, update which list they're in. When updating an object and searching for others to interact with, you can look at just the current grid cell and a few neighboring ones. You can ...


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

The first tip you'll get is this - don't. Modern compilers are actually really really good at optimizing code, and will be much more likely to do a better job of it than any self-rolled assembly language you may write. The exception would be any specific case where you have determined for certain that the compiler is doing a bad job of optimizing, so ...


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

Just in addition to what David already said in his answer: It is true, that up to 95-99% of almost every modern game size is constituted by its assets: video, audio, textures etc. If you are wondering why some games take only 4Gb whereas others much more having same level of graphics?? It can be also due to the fact that some game store their assets on the ...


18

This works for two rectangles aligned with the X and Y axis. Each rectangle has the properties: "left", the x coordinate of its left side, "top", the y coordinate of its top side, "right", the x coordinate of its right side, "bottom", the y coordinate of its bottom side, function IntersectRect(r1:Rectangle, r2:Rectangle):Boolean { return !(r2.left ...


18

Okay: C++ is a C superset, not a C subset If you're teaming with inexperienced programmers that don't understand inheritance, then it doesn't really matter what language you choose, they're still going to have problems. Compilers can do an amazing job with optimisation. Chances are, apart from a few edge cases, you'll have a hard job writing faster ...


17

I'll be the one going against the grain here and say, it is never too early to learn about optimizations, especially assembly optimizations and more importantly, debugging in assembly. I believe that you will gain the maximum benefit of it if you are a student (because then you have very little to lose [i.e. time/money wise]) and everything to gain. If you ...


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

Remove unnecessary branches On some platforms and with some compilers, branches can throw away your whole pipeline, so even insignificant if() blocks can be expensive. The PowerPC architecture (PS3/x360) offers the floating-point select instruction, fsel. This can be used in the place of a branch if the blocks are simple assignments: float result = 0; if ...


15

Where I've worked, we always use multiple levels of profiling; if you see a problem, you just move down the list a bit more until you figure out what's going on: The "human profiler", aka just play the game; does it feel slow or "hitch" occasionally? Noticing jerky animations? (As a developer, note that you'll be more sensitive to some kinds of ...


15

The Barnes-Hut algorithm is the way to go with this one. It's been used in supercomputer simulations to solve your exact problem. It's not too hard to code, and it's very efficient. I actually wrote a Java applet not too long ago to solve this problem. Visit http://mathandcode.com/programs/javagrav/ and press "start" and "show quadtree". In the options ...


14

Usually, solid optimisation doesn't depend on using Assembly, or doing micro-optimisations with code in higher level languages. If you read a lot of research papers (as I do -- or try to!), you'll see that oftentimes the improvements made to algorithms are at a broader conceptual, "qualitative" level, rather than at the more "quantitative" level of ...


13

Avoid memory accesses and especially random ones at all costs. That's the single most important thing to optimize for on modern CPUs. You can do a shitload of arithmetic and even a lot of wrong predicted branches in the time you wait for data from RAM. You can also read this rule the other way around: Do as much calculations as possible between memory ...


13

What you should do: Lock game logic to a fixed framerate Render graphics as fast as possible That way, if the framerate drops you don't get input lag (I'm looking at you, Just Cause 2), and if the framerate becomes too high (think games from the 90's) the game doesn't become unplayable. Here's how I do it: s_PhysicsCurrent = GetTickCount(); float delta ...


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

Unfortunately, the answer is to draw less. I've found the bottleneck with canvas based applications (on any platform, really) is the time it takes to actually draw pixels. Here are some things to try: Use several canvas layers. Draw your background to one layer while drawing your objects to another layer (absolutely positioned on top of the background ...


13

Split the terrain into square "chunks", load those you care about (mostly: Those near the currently active camera) in Update() and - if you are strapped for space (you likely will be), unload the not needed ones far away. Use pre-calculated low-poly models for far-away terrain LoD, unless you don't mind having a low view distance. Also, if you need the ...



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