18 for (
unsigned int id=0;
id <
m_count;
id++)
27 unsigned int lowBlock, highBlock, midBlock;
28 if (timeOffset <= buffer->
lookup[0].m_timeOffset) {
31 return &
buffer->m_firstItem;
37 lowBlock = midBlock = (timeOffset*highBlock)/(
buffer->m_lastTimestamp-
buffer->m_firstTimestamp);
41 if (timeOffset <= buffer->
lookup[lowBlock].m_timeOffset) {
47 if (midBlock < highBlock)
49 if (timeOffset <= buffer->
lookup[midBlock].m_timeOffset) {
57 midBlock = (lowBlock+highBlock)/2;
58 if (midBlock == lowBlock) {
61 }
else if (timeOffset <= buffer->
lookup[midBlock].m_timeOffset) {
67 assert (lowBlock != highBlock);
68 *retBlock = highBlock;
110 if (
buffer->m_firstFreePositionW == 0)
113 if (timestamp < buffer->m_firstTimestamp) {
115 return &
buffer->m_firstItem;
119 unsigned short timeOffset = (
unsigned short)(timestamp-
buffer->m_firstTimestamp);
120 unsigned int highBlock;
125 while (item<=limit && item->m_timeOffset < timeOffset )
145 if (
buffer->m_firstFreePositionW == 0)
148 if (timestamp <= buffer->m_firstTimestamp) {
149 if (prevBuffer ==
NULL) {
155 *rBuffer = prevBuffer;
160 unsigned short timeOffset = (
unsigned short)(timestamp-
buffer->m_firstTimestamp);
161 unsigned int highBlock;
167 while (item<=limit && item->m_timeOffset < timeOffset) {
171 assert(item<=limit && prevItem!=
NULL);
178 if (prevBuffer ==
NULL) {
184 *rBuffer = prevBuffer;
195 CacheMap::iterator it;
196 for (it=m_cache.begin(); it!=m_cache.end(); it=m_cache.begin()) {
203 CacheMap::iterator it = m_cache.find(device);
208 if (maxItemSize > 0x3FFF0)
211 if (it == m_cache.end()) {
216 if (!m_cache.insert(CacheMap::value_type(device,entry)).second)
222 for (channel=entry->
m_channelArray,
id=0; id<entry->m_count;
id++, channel++) {
223 if (channel->
m_busy && !strcmp(name, channel->
m_name)) {
230 for (channel=entry->
m_channelArray,
id=0; id<entry->m_count;
id++, channel++) {
252 unsigned int bufSize = 1630*(maxItemSize+4);
255 if (bufSize < maxItemSize+16)
256 bufSize = maxItemSize+16;
257 bufSize = (bufSize + 3) & ~0x3;
264 if (blockSize < maxItemSize+12)
265 blockSize = maxItemSize+12;
268 unsigned int pwr2Size = blockSize;
269 while ((m = (pwr2Size & (pwr2Size-1))) != 0)
271 blockSize = (pwr2Size < blockSize) ? pwr2Size<<1 : pwr2Size;
281 strncpy(channel->
m_name, name,
sizeof(channel->
m_name));
284 for (m=0; blockSize!=1; m++, blockSize>>=1);
291 CacheMap::iterator it = m_cache.find(device);
294 if (it == m_cache.end()) {
308 CacheMap::iterator it = m_cache.find(device);
311 if (it == m_cache.end()) {
323 CacheMap::iterator it = (device) ? m_cache.find(device) : m_cache.begin();
328 unsigned int positionW, block;
330 while (it != m_cache.end()) {
332 for (
unsigned int ch=0; ch<entry->
m_count; ch++) {
342 while ((nextBuffer =
buffer->m_next) !=
NULL) {
343 buffer->m_next = nextBuffer->m_next;
347 if (positionW == 0) {
352 while (nextBuffer !=
buffer) {
353 prevBuffer = nextBuffer;
354 nextBuffer = nextBuffer->m_next;
368 prevItem = &
buffer->m_firstItem;
378 assert(nextItem==item);
381 buffer->m_firstFreePositionW = positionW;
405 CacheMap::iterator it = m_cache.find(device);
410 unsigned int positionW, sizeW, block;
412 if (it == m_cache.end()) {
422 if (timestamp == 0) {
444 positionW =
buffer->m_firstFreePositionW;
473 (positionW > 0 && timestamp >=
buffer->m_firstTimestamp+0x10000)) {
476 if (positionW !=
buffer->m_firstFreePositionW) {
484 previousItem = &
buffer->m_firstItem;
492 previousItem = nextItem;
494 assert(nextItem==item);
497 buffer->m_firstFreePositionW = positionW;
513 item = &
buffer->m_firstItem;
518 if (positionW == 0) {
520 buffer->m_firstTimestamp = timestamp;
524 buffer->m_lastItemPositionW = positionW;
525 buffer->m_firstFreePositionW = positionW+sizeW;
526 buffer->m_lastTimestamp = timestamp;
545 CacheMap::iterator it;
552 it = m_cache.find(device);
554 it = m_cache.begin();
556 if (it == m_cache.end()) {
570 const CacheItem *Cache::getCurrentCacheItemInternal(
const void *device,
int id,
CacheTS timestamp)
572 CacheMap::iterator it = m_cache.find(device);
578 if (it == m_cache.end()) {
595 const CacheItem *item = getCurrentCacheItemInternal(device, channel, timestamp);
601 const CacheItem *item = getCurrentCacheItemInternal(device, channel, timestamp);
603 if (!item || item->
m_sizeW != sizeW)
604 return (
double*)
addCacheItem(device, channel, timestamp, newdata,
length*
sizeof(
double));
608 double *ref = olddata;
611 for (i=
length; i>0; --i) {
617 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
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)
ccl_global float * buffer
ccl_gpu_kernel_postfix ccl_global float int int int int float threshold
ccl_device_inline float2 fabs(const float2 &a)
static void clear(Message *msg)
GAttributeReader lookup(const void *owner, const AttributeIDRef &attribute_id)
T length(const vec_base< T, Size > &a)
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