I’m engaged on a metropolis constructing recreation the place all buildings are axis aligned rectangles. Presently I’m utilizing spatial hashing to detect if the insertion of a constructing intersects a constructing within the board.
Now I’m implementing an impact system the place each constructing positioned has some results that they can provide to different buildings inside a selected vary. This occurs throughout placement of a brand new constructing into the board.
Principally the way it ought to work is, if I place a constructing inside the vary of one other constructing within the board, the constructing within the board ought to obtain the consequences that the constructing I simply positioned has, and the constructing that I’m inserting also needs to obtain the consequences that the constructing within the board has. Principally like a handshake. This could occur with each constructing that’s within the vary of one other constructing and can solely happen and be calculated when a brand new constructing is inserted into the board.
One other factor to remember is that if a constructing is already within the board and a brand new constructing is positioned inside its vary, that new constructing ought to obtain the consequences of the constructing already within the board even when the opposite constructing doesn’t have this constructing in its vary. Thus this may be a a method switch of results and never a “handshake”.
I at present have the alternate of results working because it ought to, however its sluggish as a result of I’m checking each constructing vary in opposition to each constructing. Thus the extra buildings you place, the slower it will get.
I’m on the lookout for a option to make this quicker whether or not it means altering from spatial hashing to another spatial partitioning. I’m at present studying Hierarchical Hash Grids however I do not know if this can profit me in any respect.