That's not my point about placement new; the question is, why use a std::vector<Particle*> and placement new into a separate array (which incurs a pointless pointer follow per particle update, doesn't keep a consistent order as particles are deleted, takes more memory as you need to store the pointers, and requires extra bookkeeping for when the underlying array is full) instead of just using std::vector<Particle> directly?
I don't understand why you are storing pointers to placement-newed particles instead of just using the value type in the array itself. That'd solve the issues of update order (as you are always updating in order, the next particle is nearly guaranteed to be in cache) as well as simplifying the rest of the code.
Deleting might be a bit more expensive due to the larger amount of memory being swapped (if we are truly talking 130 bytes per particle...) , but I'm not convinced that it's a huge difference.
If you do the deletions in a separate loop beforehand it's effectively just a memcpy, and furthermore it'll be likely to increase the update performance as it'll avoid the possibility of branch mispredicts as well as simplifying the code, more easily allowing the compiler to utilise SIMD instructions or unroll the loop.
Really slow? Seriously? You realize that floats are used in pretty much all games?
Seriously, if floats are fast enough for massive RTSes like Supreme Commander, for physics engines like Bullet, and for... well, every single damn modern game, they are good enough for a damn 2D indie game.
If they are moving cells every iteration, there is no performance improvement to independently checking if they change cell, so that is certainly worth a try.
I'd definitely expect more than a 10x per improvement with 700 objects. What sort of collision checking are you doing? If it is a sphere or circle collision check, be sure to compare squared distance and radii instead of true distance, as this avoids a costly square root operation.
Real-time Collision Detection is a great book and definitely is still relevant, although it's a pretty in-depth read.
For optimization, it's better to try to reduce the amount of checks rather than parallelizing or otherwise optimizing the checks themselves. Speedup via that method is unsustainable, as a O(n²) runtime will collapse once you get over a relatively low count of entities.
Look into broad-phase collision detection - I use a spatial partitioning grid in many of my projects which drastically speeds up computation and is a relatively simple technique. It incurs a bit of static overhead initially, but drastically speeds up performance with high entity counts, to near O(n) performance characteristics.
The issue with this is that it doesn't work too well when you have many objects interacting of different sizes. Some physics engines use a technique called sweep and prune, which can often handle these cases better.
The easiest way is just to move both the old and new transform. An extra flag is a messy method of doing it IMO, which introduces a bunch of extra unnecessary logic.
It's been pretty good, but I've not done a massive amount on it. The game I've been making has however required a few big changes to the engine source, but being that it is an RTS that's almost to be expected.
Documentation is certainly pretty lacking, and it's hard to understand what some things are meant to be used for, but the code is clean and easy to understand.
There's a few issues with bugs that I cannot find any assistance with, such as models disappearing in certain circumstances, which is probably the most concerning thing to me.
It's a new engine. It also misses some fundamental features that are expected for modern AAA engines, i.e physics render-state interpolation.
I don't want to talk-down Godot too much here, as it's a good engine, but it's missing quite a bit from the last time I looked at it. I investigated Godot 3.0 for a prototype of mines but dropped it for Urho3d, which is less immediately impressive but seems to support more of the fundamentals.
These huge spikes I'm talking about aren't due to usage. They are due to small edge cases that can drastically cut down performance, and in an unpredictable manner (i.e when a certain subset of parameters are used). SQL optimizers can be very finicky. Having the possibility for cases like that in a game seems troubling, giving how much more difficult it can be to test the infinite possibilities in a game versus a simple search.
That's the point. We're talking about games and databases do not optimize for latency. Databases have always cared less about latency and more about throughput, and less about worst-case timings and more about average-case timings.
This is doubly bad for games, because generally speaking the times we care about with a game engine are worst-case times (which cause frameskips) moreso than average-case times.
Maybe 50ms is not fast, and is certainly slow in terms of throughput per request and as an average metric, but in terms of concurrent requests that's not bad.
A db's worst case (i.e the first time they parse and optimize a query) is far worse than their average case (a generic request from an already prepared optimized query). In a game you could try to do this stuff up-front as much as possible in loading screens, but it'll be unavoidable that you'll need some queries that are simply too dynamic for effective optimization, especially given that the types of queries that games use a lot of (i.e distance/collision checks) aren't well suited for relational databases.
Relational databases know how to optimize joins and simplify unused parameters out of queries, like for filters and searches where a lot of advanced options are rarely used. That's meaningless for a game. A game needs in-depth domain-specific optimizations typically, such as broadphase collision detection, and RDBMS cannot do that.
My current job is effectively full-stack web development and the assumptions DBs make have burned us a few times. Db's worst cases can cause huge spikes in certain circumstances especially when not tweaking and micromanaging each query to have the right recompilation flags etc. That's bad enough for webpages, but catastrophic in a game.
Depends on the query. I'd wager that most queries need to be used for the current frame (in which case multithreading doesn't help without input lag).
Furthermore, multithreading is no magic bullet. That's still CPU time being spent. That's time that could be spent calculating other tasks, that's battery being drained, and it's fundamentally still time being spent, just on another core. It's not free time coming from nowhere.
The issue with a database is that a DB's idea of efficient and a games idea are two extremely different things.
An efficient DB is one that can handle thousands of concurrent requests, complex atomic data operations and latencies to return data of less than a quarter of a second or so.
An efficient game is one that generally attempts to read as little data as necessary, with non-atomic operations (doesn't matter if a powercut corrupts data), and has latencies that are far, far lower.
A db will happily spend loads of CPU time to compile a query to be more efficient if it means less data must be loaded from disk. A game needs that CPU time, and has everything loaded in memory already.
When a DB says a query is fast, they say it only takes 50ms. An operation taking 50ms in a game equals a huge frame skip.
I was thinking that I could run 1000 generations for each turn and select the best gene as the set of actions that the AI would take in that turn. In the end, I decided against it because I'm not so sure how long 1000 generations would take. I mean sure the game is turn based but we don't want the player to wait too long for the AI to execute.
I can't tell if you are talking about genetic algorithms or a minimax algorithm there.
A genetic algorithm only requires training once - before you play the game. Real time games with Supreme Commander 2 or Planetary Annihilation use neural networks trained using genetic algorithms, and run in real time (with great AI). It's usually not considered a "brute force" method, either - it's actually more of the opposite, it's about training an AI a set of "rules of thumbs" that it can figure out itself based on the game state.
The training can be expensive, but usually actually performing the AI is instant. This seems to be talking more about looking 1000 turns ahead and choosing the best choice, which is a minimax algorithm. Minimax can be slow, but it's the same sort of algorithm used to play connect-4 and chess (although often with heuristics and other optimizations like monte-carlo tree search).
Find it quite amazing how legible it still is. it almost looks like how somebody would fake it, with relatively minor changes like a few letters here and there and lowercase/uppercae toggles - I never thought a real malfunction would be so similar!
Yes. I don't know whether this can really be called software gore, though; it's impossible to have compression which reliably compresses ALL data to less than 100% of the original size.
That's not my point about placement new; the question is, why use a std::vector<Particle*> and placement new into a separate array (which incurs a pointless pointer follow per particle update, doesn't keep a consistent order as particles are deleted, takes more memory as you need to store the pointers, and requires extra bookkeeping for when the underlying array is full) instead of just using std::vector<Particle> directly?
I don't understand why you are storing pointers to placement-newed particles instead of just using the value type in the array itself. That'd solve the issues of update order (as you are always updating in order, the next particle is nearly guaranteed to be in cache) as well as simplifying the rest of the code.
Deleting might be a bit more expensive due to the larger amount of memory being swapped (if we are truly talking 130 bytes per particle...) , but I'm not convinced that it's a huge difference.
If you do the deletions in a separate loop beforehand it's effectively just a memcpy, and furthermore it'll be likely to increase the update performance as it'll avoid the possibility of branch mispredicts as well as simplifying the code, more easily allowing the compiler to utilise SIMD instructions or unroll the loop.
Really slow? Seriously? You realize that floats are used in pretty much all games?
Seriously, if floats are fast enough for massive RTSes like Supreme Commander, for physics engines like Bullet, and for... well, every single damn modern game, they are good enough for a damn 2D indie game.
If they are moving cells every iteration, there is no performance improvement to independently checking if they change cell, so that is certainly worth a try.
I'd definitely expect more than a 10x per improvement with 700 objects. What sort of collision checking are you doing? If it is a sphere or circle collision check, be sure to compare squared distance and radii instead of true distance, as this avoids a costly square root operation.
A grid should give a massive performance gain, or at least does for me. Are you sure that your interpretation is correct?
A grid is, from my experiments, faster than a kd tree or quad tree, presuming many entities of near equal size. More complex doesn't mean better.
Real-time Collision Detection is a great book and definitely is still relevant, although it's a pretty in-depth read.
For optimization, it's better to try to reduce the amount of checks rather than parallelizing or otherwise optimizing the checks themselves. Speedup via that method is unsustainable, as a O(n²) runtime will collapse once you get over a relatively low count of entities.
Look into broad-phase collision detection - I use a spatial partitioning grid in many of my projects which drastically speeds up computation and is a relatively simple technique. It incurs a bit of static overhead initially, but drastically speeds up performance with high entity counts, to near O(n) performance characteristics.
The issue with this is that it doesn't work too well when you have many objects interacting of different sizes. Some physics engines use a technique called sweep and prune, which can often handle these cases better.
The easiest way is just to move both the old and new transform. An extra flag is a messy method of doing it IMO, which introduces a bunch of extra unnecessary logic.
It's been pretty good, but I've not done a massive amount on it. The game I've been making has however required a few big changes to the engine source, but being that it is an RTS that's almost to be expected.
Documentation is certainly pretty lacking, and it's hard to understand what some things are meant to be used for, but the code is clean and easy to understand.
There's a few issues with bugs that I cannot find any assistance with, such as models disappearing in certain circumstances, which is probably the most concerning thing to me.
It's a new engine. It also misses some fundamental features that are expected for modern AAA engines, i.e physics render-state interpolation.
I don't want to talk-down Godot too much here, as it's a good engine, but it's missing quite a bit from the last time I looked at it. I investigated Godot 3.0 for a prototype of mines but dropped it for Urho3d, which is less immediately impressive but seems to support more of the fundamentals.
These huge spikes I'm talking about aren't due to usage. They are due to small edge cases that can drastically cut down performance, and in an unpredictable manner (i.e when a certain subset of parameters are used). SQL optimizers can be very finicky. Having the possibility for cases like that in a game seems troubling, giving how much more difficult it can be to test the infinite possibilities in a game versus a simple search.
That's the point. We're talking about games and databases do not optimize for latency. Databases have always cared less about latency and more about throughput, and less about worst-case timings and more about average-case timings.
This is doubly bad for games, because generally speaking the times we care about with a game engine are worst-case times (which cause frameskips) moreso than average-case times.
Maybe 50ms is not fast, and is certainly slow in terms of throughput per request and as an average metric, but in terms of concurrent requests that's not bad.
A db's worst case (i.e the first time they parse and optimize a query) is far worse than their average case (a generic request from an already prepared optimized query). In a game you could try to do this stuff up-front as much as possible in loading screens, but it'll be unavoidable that you'll need some queries that are simply too dynamic for effective optimization, especially given that the types of queries that games use a lot of (i.e distance/collision checks) aren't well suited for relational databases.
Relational databases know how to optimize joins and simplify unused parameters out of queries, like for filters and searches where a lot of advanced options are rarely used. That's meaningless for a game. A game needs in-depth domain-specific optimizations typically, such as broadphase collision detection, and RDBMS cannot do that.
My current job is effectively full-stack web development and the assumptions DBs make have burned us a few times. Db's worst cases can cause huge spikes in certain circumstances especially when not tweaking and micromanaging each query to have the right recompilation flags etc. That's bad enough for webpages, but catastrophic in a game.
Throughput != latency. You can run concurrent queries.
Depends on the query. I'd wager that most queries need to be used for the current frame (in which case multithreading doesn't help without input lag).
Furthermore, multithreading is no magic bullet. That's still CPU time being spent. That's time that could be spent calculating other tasks, that's battery being drained, and it's fundamentally still time being spent, just on another core. It's not free time coming from nowhere.
The issue with a database is that a DB's idea of efficient and a games idea are two extremely different things.
An efficient DB is one that can handle thousands of concurrent requests, complex atomic data operations and latencies to return data of less than a quarter of a second or so.
An efficient game is one that generally attempts to read as little data as necessary, with non-atomic operations (doesn't matter if a powercut corrupts data), and has latencies that are far, far lower.
A db will happily spend loads of CPU time to compile a query to be more efficient if it means less data must be loaded from disk. A game needs that CPU time, and has everything loaded in memory already.
When a DB says a query is fast, they say it only takes 50ms. An operation taking 50ms in a game equals a huge frame skip.
Bullet physics support is in a pull request for Godot 3.0 and is likely to be a feature.
Unless you manually set the value of the dropdown in the HTML
Because double quotes aren't used for strings in SQL...?
No, that's C#. C++ is:
And C would be:
You can see a pentagon in the middle of the bottom-left image.
Floating point precision artifacts.
In the post, you mention this:
I can't tell if you are talking about genetic algorithms or a minimax algorithm there.
A genetic algorithm only requires training once - before you play the game. Real time games with Supreme Commander 2 or Planetary Annihilation use neural networks trained using genetic algorithms, and run in real time (with great AI). It's usually not considered a "brute force" method, either - it's actually more of the opposite, it's about training an AI a set of "rules of thumbs" that it can figure out itself based on the game state.
The training can be expensive, but usually actually performing the AI is instant. This seems to be talking more about looking 1000 turns ahead and choosing the best choice, which is a minimax algorithm. Minimax can be slow, but it's the same sort of algorithm used to play connect-4 and chess (although often with heuristics and other optimizations like monte-carlo tree search).
Find it quite amazing how legible it still is. it almost looks like how somebody would fake it, with relatively minor changes like a few letters here and there and lowercase/uppercae toggles - I never thought a real malfunction would be so similar!
Yes. I don't know whether this can really be called software gore, though; it's impossible to have compression which reliably compresses ALL data to less than 100% of the original size.
I actually feel physically sick when looked at this.
It's the ALS challenge, not the ice bucket challenge. When you remove the entire thing it's trying to raise awareness about, it's meaningless.