/* Copyright (c) 2015 Alex Diener This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Alex Diener alex@ludobloom.com */ #ifndef __CollisionPairQueue_H__ #define __CollisionPairQueue_H__ #ifdef __cplusplus extern "C" { #endif typedef struct CollisionPairQueue CollisionPairQueue; #define CollisionPairQueue_superclass StemObject #include "collision/CollisionObject.h" #include "stemobject/StemObject.h" #include "utilities/HashTable.h" #include struct collisionObjectPair { CollisionObject * object1; CollisionObject * object2; }; #define CollisionPairQueue_ivars \ StemObject_ivars \ \ size_t pairCount; \ size_t private_ivar(pairAllocatedCount); \ struct collisionObjectPair * pairs; \ size_t nextPairCount; \ size_t private_ivar(nextPairAllocatedCount); \ struct collisionObjectPair * nextPairs; \ size_t nextObjectCount; \ size_t private_ivar(nextObjectAllocatedCount); \ CollisionObject ** nextObjects; \ HashTable * private_ivar(pairHashTable); \ size_t queuePosition; #define CollisionPairQueue_vtable(self_type) \ StemObject_vtable(self_type) stemobject_declare(CollisionPairQueue) CollisionPairQueue * CollisionPairQueue_create(); bool CollisionPairQueue_init(CollisionPairQueue * self); void CollisionPairQueue_dispose(CollisionPairQueue * self); // Adds all permutations of objects pairs in the list to the initial queue. Pairs which can safely be ignored // (static vs. static) will not be added. void CollisionPairQueue_addInitialPairs(CollisionPairQueue * self, CollisionObject ** movingObjects, size_t movingObjectCount, CollisionObject ** staticObjects, size_t staticObjectCount); // Adds a single pair to the next queue. Does not affect current queue. void CollisionPairQueue_addNextPair(CollisionPairQueue * self, CollisionObject * object1, CollisionObject * object2); // Queues an object to be considered during the next iteration. void CollisionPairQueue_addNextObject(CollisionPairQueue * self, CollisionObject * object); // If there are pairs left to process in the current queue, returns true and sets the out parameters to the next // pair to be processed, removing it from the queue. bool CollisionPairQueue_nextPair(CollisionPairQueue * self, CollisionObject ** outObject1, CollisionObject ** outObject2); // Empties the current queue refills it using objects added by addNextObject, returning true if there are any pairs remaining to be processed. bool CollisionPairQueue_nextIteration(CollisionPairQueue * self, CollisionObject ** movingObjects, size_t movingObjectCount, CollisionObject ** staticObjects, size_t staticObjectCount); #ifdef __cplusplus } #endif #endif