예제 #1
0
cpHandleInit(cpHandle *hand, object obj)
{
	hand.obj = obj;
	hand.retain = 0;
	hand.stamp = 0;
	
	return hand;
}
예제 #2
0
static int handleSetEql(object obj, cpHandle *hand){return (obj == hand.obj);}
예제 #3
0
cpHandleRelease(cpHandle *hand, cpArray *pooledHandles)
{
	hand.retain--;
	if(hand.retain == 0) cpArrayPush(pooledHandles, hand);
}
예제 #4
0
static void cpHandleRetain(cpHandle *hand){hand.retain++;}
예제 #5
0
rehash_helper(cpHandle *hand, cpSpaceHash *hash)
{
	hashHandle(hash, hand, hash.spatialIndex.bbfunc(hand.obj));
}
예제 #6
0
hashHandle(cpSpaceHash *hash, cpHandle *hand, cpBB bb)
{
	// Find the dimensions in cell coordinates.
	double dim = hash.celldim;
	int l = floor_int(bb.l/dim); // Fix by ShiftZ
	int r = floor_int(bb.r/dim);
	int b = floor_int(bb.b/dim);
	int t = floor_int(bb.t/dim);
	
	int n = hash.numcells;
	for(int i=l; i<=r; i++){
		for(int j=b; j<=t; j++){
			cpHashValue idx = hash_func(i,j,n);
			cpSpaceHashBin *bin = hash.table[idx];
			
			// Don't add an object twice to the same cell.
			if(containsHandle(bin, hand)) continue;

			cpHandleRetain(hand);
			// Insert a new bin for the handle in this cell.
			cpSpaceHashBin *newBin = getEmptyBin(hash);
			newBin.handle = hand;
			newBin.next = bin;
			hash.table[idx] = newBin;
		}
	}
}
예제 #7
0
containsHandle(cpSpaceHashBin *bin, cpHandle *hand)
{
	while(bin){
		if(bin.handle == hand) return true;
		bin = bin.next;
	}
	
	return false;
}