示例#1
0
void
cpSpaceHashRemove(cpSpaceHash *hash, void *obj, unsigned int id)
{
	cpHandle *hand = (cpHandle *)cpHashSetRemove(hash->handleSet, id, obj);
	
	if(hand){
		hand->obj = NULL;
		cpHandleRelease(hand);
	}
}
示例#2
0
static void
cpSpaceHashRemove(cpSpaceHash *hash, void *obj, cpHashValue hashid)
{
	cpHandle *hand = (cpHandle *)cpHashSetRemove(hash->handleSet, hashid, obj);
	
	if(hand){
		hand->obj = NULL;
		cpHandleRelease(hand, hash->pooledHandles);
	}
}
示例#3
0
static inline void
clearTableCell(cpSpaceHash *hash, int idx)
{
	cpSpaceHashBin *bin = hash->table[idx];
	while(bin){
		cpSpaceHashBin *next = bin->next;
		
		cpHandleRelease(bin->handle, hash->pooledHandles);
		recycleBin(hash, bin);
		
		bin = next;
	}
	
	hash->table[idx] = NULL;
}
示例#4
0
static inline void
clearHashCell(cpSpaceHash *hash, int index)
{
	cpSpaceHashBin *bin = hash->table[index];
	while(bin){
		cpSpaceHashBin *next = bin->next;
		
		// Release the lock on the handle.
		cpHandleRelease(bin->handle);
		// Recycle the bin.
		bin->next = hash->bins;
		hash->bins = bin;
		
		bin = next;
	}
	
	hash->table[index] = NULL;
}
// Calls the callback function for the objects in a given chain.
static inline void
query(cpSpaceHash *hash, cpSpaceHashBin **bin_ptr, void *obj, cpSpaceHashQueryFunc func, void *data)
{
	cpSpaceHashBin *bin = *bin_ptr;
	while(bin){
//	for(cpSpaceHashBin *bin=*bin_ptr; bin; bin_ptr=&bin->next, bin=bin->next){
		cpHandle *hand = bin->handle;
		void *other = hand->obj;
		
		// Skip over certain conditions
		if(
			// Have we already tried this pair in the currnt query in a different cell?
			hand->stamp == hash->stamp
			// Is obj the same as other?
			|| obj == other 
		){
			bin_ptr = &bin->next;
			bin = bin->next;
			continue;
		}
		
		if(other){
			func(obj, other, data);
			
			// Stamp that the handle was checked already against this object.
			hand->stamp = hash->stamp;
			
			bin_ptr = &bin->next;
			bin = bin->next;
		} else { // The object has been removed 
			cpSpaceHashBin *next = bin->next;
			
			// unlink and recycle the bin
			(*bin_ptr) = bin->next;
			recycleBin(hash, bin);
			
			// release the reference to the handle
			cpHandleRelease(hand, hash->pooledHandles);
			
			bin = next;
		}
	}
}
示例#6
0
static void
remove_orphaned_handles(cpSpaceHash *hash, cpSpaceHashBin **bin_ptr)
{
	cpSpaceHashBin *bin = *bin_ptr;
	while(bin){
		cpHandle *hand = bin->handle;
		cpSpaceHashBin *next = bin->next;
		
		if(!hand->obj){
			// orphaned handle, unlink and recycle the bin
			(*bin_ptr) = bin->next;
			recycleBin(hash, bin);
			
			cpHandleRelease(hand, hash->pooledHandles);
		} else {
			bin_ptr = &bin->next;
		}
		
		bin = next;
	}
}