20 for (
unsigned int id=0;
id <
m_count;
id++)
29 unsigned int lowBlock, highBlock, midBlock;
30 if (timeOffset <= buffer->lookup[0].m_timeOffset) {
33 return &
buffer->m_firstItem;
39 lowBlock = midBlock = (timeOffset*highBlock)/(
buffer->m_lastTimestamp-
buffer->m_firstTimestamp);
43 if (timeOffset <= buffer->lookup[lowBlock].m_timeOffset) {
49 if (midBlock < highBlock)
51 if (timeOffset <= buffer->lookup[midBlock].m_timeOffset) {
59 midBlock = (lowBlock+highBlock)/2;
60 if (midBlock == lowBlock) {
63 }
else if (timeOffset <= buffer->lookup[midBlock].m_timeOffset) {
69 assert (lowBlock != highBlock);
70 *retBlock = highBlock;
112 if (
buffer->m_firstFreePositionW == 0)
115 if (timestamp < buffer->m_firstTimestamp) {
117 return &
buffer->m_firstItem;
121 unsigned short timeOffset = (
unsigned short)(timestamp-
buffer->m_firstTimestamp);
122 unsigned int highBlock;
127 while (item<=limit && item->m_timeOffset < timeOffset )
147 if (
buffer->m_firstFreePositionW == 0)
150 if (timestamp <= buffer->m_firstTimestamp) {
151 if (prevBuffer ==
NULL) {
157 *rBuffer = prevBuffer;
162 unsigned short timeOffset = (
unsigned short)(timestamp-
buffer->m_firstTimestamp);
163 unsigned int highBlock;
169 while (item<=limit && item->m_timeOffset < timeOffset) {
173 assert(item<=limit && prevItem!=
NULL);
180 if (prevBuffer ==
NULL) {
186 *rBuffer = prevBuffer;
197 CacheMap::iterator it;
198 for (it=m_cache.begin(); it!=m_cache.end(); it=m_cache.begin()) {
205 CacheMap::iterator it = m_cache.find(device);
210 if (maxItemSize > 0x3FFF0)
213 if (it == m_cache.end()) {
218 if (!m_cache.insert(CacheMap::value_type(device,entry)).second)
224 for (channel=entry->
m_channelArray,
id=0; id<entry->m_count;
id++, channel++) {
225 if (channel->
m_busy && !strcmp(name, channel->
m_name)) {
232 for (channel=entry->
m_channelArray,
id=0; id<entry->m_count;
id++, channel++) {
254 unsigned int bufSize = 1630*(maxItemSize+4);
257 if (bufSize < maxItemSize+16)
258 bufSize = maxItemSize+16;
259 bufSize = (bufSize + 3) & ~0x3;
266 if (blockSize < maxItemSize+12)
267 blockSize = maxItemSize+12;
270 unsigned int pwr2Size = blockSize;
271 while ((m = (pwr2Size & (pwr2Size-1))) != 0)
273 blockSize = (pwr2Size < blockSize) ? pwr2Size<<1 : pwr2Size;
283 strncpy(channel->
m_name, name,
sizeof(channel->
m_name));
286 for (m=0; blockSize!=1; m++, blockSize>>=1);
293 CacheMap::iterator it = m_cache.find(device);
296 if (it == m_cache.end()) {
310 CacheMap::iterator it = m_cache.find(device);
313 if (it == m_cache.end()) {
325 CacheMap::iterator it = (device) ? m_cache.find(device) : m_cache.begin();
330 unsigned int positionW, block;
332 while (it != m_cache.end()) {
334 for (
unsigned int ch=0; ch<entry->
m_count; ch++) {
344 while ((nextBuffer =
buffer->m_next) !=
NULL) {
345 buffer->m_next = nextBuffer->m_next;
349 if (positionW == 0) {
354 while (nextBuffer !=
buffer) {
355 prevBuffer = nextBuffer;
356 nextBuffer = nextBuffer->m_next;
370 prevItem = &
buffer->m_firstItem;
380 assert(nextItem==item);
383 buffer->m_firstFreePositionW = positionW;
407 CacheMap::iterator it = m_cache.find(device);
412 unsigned int positionW, sizeW, block;
414 if (it == m_cache.end()) {
424 if (timestamp == 0) {
446 positionW =
buffer->m_firstFreePositionW;
475 (positionW > 0 && timestamp >=
buffer->m_firstTimestamp+0x10000)) {
478 if (positionW !=
buffer->m_firstFreePositionW) {
486 previousItem = &
buffer->m_firstItem;
494 previousItem = nextItem;
496 assert(nextItem==item);
499 buffer->m_firstFreePositionW = positionW;
515 item = &
buffer->m_firstItem;
520 if (positionW == 0) {
522 buffer->m_firstTimestamp = timestamp;
526 buffer->m_lastItemPositionW = positionW;
527 buffer->m_firstFreePositionW = positionW+sizeW;
528 buffer->m_lastTimestamp = timestamp;
547 CacheMap::iterator it;
554 it = m_cache.find(device);
556 it = m_cache.begin();
558 if (it == m_cache.end()) {
572 const CacheItem *Cache::getCurrentCacheItemInternal(
const void *device,
int id,
CacheTS timestamp)
574 CacheMap::iterator it = m_cache.find(device);
580 if (it == m_cache.end()) {
597 const CacheItem *item = getCurrentCacheItemInternal(device, channel, timestamp);
603 const CacheItem *item = getCurrentCacheItemInternal(device, channel, timestamp);
605 if (!item || item->
m_sizeW != sizeW)
606 return (
double*)
addCacheItem(device, channel, timestamp, newdata,
length*
sizeof(
double));
610 double *ref = olddata;
613 for (i=
length; i>0; --i) {
614 if (
fabs(*
v-*ref) > threshold)
619 olddata = (
double*)
addCacheItem(device, channel, timestamp, newdata,
length*
sizeof(
double));
void BLI_kdtree_nd_() free(KDTree *tree)
#define CACHE_BLOCK_ITEM_ADDR(chan, buf, block)
#define CACHE_ITEM_DATA_POINTER(item)
#define CACHE_CHANNEL_EXTEND_SIZE
#define CACHE_DEFAULT_BUFFER_SIZE
#define CACHE_ITEM_POSITIONW(buf, item)
#define CACHE_BUFFER_HEADER_SIZE
#define CACHE_LOOKUP_TABLE_SIZE
#define CACHE_NEXT_ITEM(item)
#define CACHE_ITEM_ADDR(buf, pos)
#define CACHE_ITEM_SIZEW(item, length)
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE btScalar length(const btQuaternion &q)
Return the length of a quaternion.
const void * getCurrentCacheItem(const void *device, int channel, CacheTS timestamp)
void clearCacheFrom(const void *device, CacheTS timestamp)
int deleteChannel(const void *device, int channel)
int addChannel(const void *device, const char *name, unsigned int maxItemSize)
int deleteDevice(const void *device)
void * addCacheItem(const void *device, int channel, CacheTS timestamp, void *data, unsigned int length)
double * addCacheVectorIfDifferent(const void *device, int channel, CacheTS timestamp, double *data, unsigned int length, double threshold)
const void * getPreviousCacheItem(const void *device, int channel, CacheTS *timestamp)
__kernel void ccl_constant KernelData ccl_global void ccl_global char ccl_global int ccl_global char ccl_global unsigned int ccl_global float * buffer
static void clear(Message *msg)
CacheItem * _findBlock(CacheBuffer *buffer, unsigned short timeOffset, unsigned int *highBlock)
struct CacheBuffer * m_firstBuffer
unsigned int m_maxItemSizeB
unsigned int m_blockSizeW
struct CacheBuffer * m_lastBuffer
CacheBuffer * allocBuffer()
unsigned char m_positionToBlockShiftW
unsigned int m_lastItemPositionW
unsigned int m_bufferSizeW
CacheItem * findItemEarlier(unsigned int timestamp, CacheBuffer **rBuffer)
unsigned short m_positionToOffsetMaskW
CacheItem * findItemOrLater(unsigned int timestamp, CacheBuffer **rBuffer)
unsigned int m_lastTimestamp
CacheChannel * m_channelArray
unsigned short m_timeOffset
ccl_device_inline float2 fabs(const float2 &a)