I request the following:
- A generic method to forbid mining tiles if the tile underneath them would collide with the entities on the tile. This could be a flag on the tile prototype or something different.
No, rails are entities and they reference the train that is on them.mrvn wrote:Isn't that similar to mining rails when a train in on them?
Do I understand this right? Every tick every entity checks the tiles it stands on and if they conflict with what the entity requires then the entity dies?Gergely wrote: Tue Aug 28, 2018 8:51 pmNo, rails are entities and they reference the train that is on them.mrvn wrote:Isn't that similar to mining rails when a train in on them?
Tiles however don't know if there is an entity on top of them while they are being removed. The entities on mined tiles die as soon as they are ticked when it's already too late to undo the tile removal.
In other words, rails are more self-conscious.
So that's why implementing this can potentially impact the performance. When removing a single tile, all entities inside the chunk and neighboring chunks might have to be checked.
No.mrvn wrote: Mon Sep 17, 2018 7:36 am Do I understand this right? Every tick every entity checks the tiles it stands on and if they conflict with what the entity requires then the entity dies?
That sounds like a horrible design.
Huh? Why?Rseding91 wrote: Mon Sep 17, 2018 10:23 amNo.mrvn wrote: Mon Sep 17, 2018 7:36 am Do I understand this right? Every tick every entity checks the tiles it stands on and if they conflict with what the entity requires then the entity dies?
That sounds like a horrible design.
When a tile is changed the game scans the entities on the tile and destroys any that collide with the new tile.
The problem with "don't mine if any collide" is it has to then scan every time the mining operation starts in addition to every time it finishes.
Code: Select all
if (dont_destroy) return false; // mining would destroy building
I thought the idea was to not allow mining if it would destroy entities. So the first one you find that must be destroyed you stop and the mining fails.Rseding91 wrote: Wed Sep 19, 2018 7:01 am Mining a tile can destroy multiple entities which means it can't just "stop mining the tile if it found 1 entity while destroying that can't be destroyed" since it could have destroyed others already.
Ummm....mrvn wrote: Thu Sep 20, 2018 9:42 amBut even your case seems rather simple. Assuming entities overlap and some can be destroyed and other not. You first scan the area for any entities that may be destroyed and add them to a list. If you don't find any conflicts in the area the mining will succeed and you destroy all the entities in the list.
Gergely wrote: Fri Sep 21, 2018 8:29 amUmmm....mrvn wrote: Thu Sep 20, 2018 9:42 amBut even your case seems rather simple. Assuming entities overlap and some can be destroyed and other not. You first scan the area for any entities that may be destroyed and add them to a list. If you don't find any conflicts in the area the mining will succeed and you destroy all the entities in the list.
How exactly do you imagine "adding them to a list" would work memory wise if this is supposed to be extremely optimized?
Code: Select all
std::vector to_be_destroyed(4);
for(entities_in_area) {
if (should_be_destroyed(entity))
to_be_destroyed.push_back(entity);
}
Aaaaaoooohhh...mrvn wrote: Tue Sep 25, 2018 8:17 amAs said the normal case would be at most 1 entity since they normally do not overlap. The vector starts of with space for 4. If more than 4 entities overlap the tile and need to be destroyed then the std::vector will allocate memory as needed in amortized O(1) cost per entity.Code: Select all
std::vector to_be_destroyed(4); for(entities_in_area) { if (should_be_destroyed(entity)) to_be_destroyed.push_back(entity); }
Note the part about the vector/list being small and pre-allocating it to fit 99.99% of all cases.Gergely wrote: Sat Sep 29, 2018 8:10 pm Careful!
std:vector needs to re-allocate it's array a lot during which it takes up almost double the space.
This might make linked list a better choice because it would be faster, though less efficient on memory.