yet more optimisations..
- optimised character shadows (and now they also can be turned off)
- optimised normals (monsters now use precached normals for lighting when they can)
also a major optimisation for collisons:
now my scheme for spatial subdivision is a bit primitive ..
I use a giant 2D grid and each grid cells store a list of pointers to triangles
(they were originally a big std::vector of pointers but that turned out to be too slow
so now just a regular vector of pointers .. but I digress)
now turns out when testing for collisions what you want is a function
that stops testing as early as possible
what I mean is something that identify empty areas really well and doesn't do much testing
thing is the actual function that checks if a line hits a triangle is used very rarely
and most of the time you go through lists of triangles .. and going through this list is slow by itself
and with many moving characters all around the level it just adds up
now early on I made a mistake and I only checked if a triangle is within a cell by a simple test
based on it's minimum and maximum coordinates (aka the box the triangle fits in)
this worked fine for small test levels but as the levels grow it became a serious problem
even though the levels are still relatively low poly (about ~50k tris per level)
anyway as you can see on this image this was a very wasteful approach
especially for large triangles (which are also used quite often due to the low poly
nature of the game)
and here we have the fixed version - adding this optimization nearly doubled the speed of the game
turns out it affects nearly everything: collisions, decals, dynamic lights etc.
all needed checks that used the grid
the fix is simple - there was already closest point to triangle test used by actors to move around
so this function was repurposed and
we check the cells center to the closest point in the triangle
and then we see if this closest point to that overlaps the cell
(in this case the cell is just a axis aligned rectangle)
I'm in a bit of a rut level design wise .. I want to have a level before the second boss
but despite having many ideas for it everytime I start on it .. well it goes nowhere
and I keep restarting
(the restaurant level will come after the second boss - that part is covered)
anyway for now here is a video about the new tripmine weapon:
until next time!