(***) means this might be changed soon.
Ownership and similar things
MassesCreateMass() mallocs the space and returns it.
FreeMass() frees the memory.
PlaceMassNearby() does not transfer ownership.
AddMassToField() transfers ownership to field.c; refcounting starts.
RemoveMassFromField() tells field.c that the mass is dead. It will be freed as soon as all other references are gone.
m->interfacesA MassInterface is a linked list which holds pointer to other masses that are nearby. Uses:
Field CellsThis is a cache to find masses inside a region without having to go through all masses. Those details are only relevant in field.c, after AddMassToField().
The field is divided into rectangular cells, each cell is a list of masses being in there. There are special cells, one for unclassified and oversized masses and one for zombies (masses that have been removed but are still referenced). This optimization was needed because GetMassesInRect() is called for every mass every round to find out about neighbour masses.