19 for (
unsigned int id=0;
id <
m_count;
id++)
28 unsigned int lowBlock, highBlock, midBlock;
29 if (timeOffset <= buffer->lookup[0].m_timeOffset) {
38 lowBlock = midBlock = (timeOffset*highBlock)/(buffer->m_lastTimestamp-buffer->m_firstTimestamp);
42 if (timeOffset <= buffer->lookup[lowBlock].m_timeOffset) {
48 if (midBlock < highBlock)
50 if (timeOffset <= buffer->lookup[midBlock].m_timeOffset) {
58 midBlock = (lowBlock+highBlock)/2;
59 if (midBlock == lowBlock) {
62 }
else if (timeOffset <= buffer->lookup[midBlock].m_timeOffset) {
68 assert (lowBlock != highBlock);
69 *retBlock = highBlock;
77 next = buffer->m_next;
110 for (buffer=
m_firstBuffer; buffer; buffer = buffer->m_next) {
111 if (buffer->m_firstFreePositionW == 0)
114 if (timestamp < buffer->m_firstTimestamp) {
120 unsigned short timeOffset = (
unsigned short)(timestamp-buffer->m_firstTimestamp);
121 unsigned int highBlock;
122 item =
_findBlock(buffer, timeOffset, &highBlock);
126 while (item<=limit && item->m_timeOffset < timeOffset )
145 for (prevBuffer=NULL, buffer=
m_firstBuffer; buffer; prevBuffer = buffer, buffer = buffer->m_next) {
146 if (buffer->m_firstFreePositionW == 0)
149 if (timestamp <= buffer->m_firstTimestamp) {
150 if (prevBuffer == NULL) {
156 *rBuffer = prevBuffer;
161 unsigned short timeOffset = (
unsigned short)(timestamp-buffer->m_firstTimestamp);
162 unsigned int highBlock;
163 item =
_findBlock(buffer, timeOffset, &highBlock);
168 while (item<=limit && item->m_timeOffset < timeOffset) {
172 assert(item<=limit && prevItem!=NULL);
179 if (prevBuffer == NULL) {
185 *rBuffer = prevBuffer;
196 CacheMap::iterator it;
197 for (it=m_cache.begin(); it!=m_cache.end(); it=m_cache.begin()) {
204 CacheMap::iterator it = m_cache.find(device);
209 if (maxItemSize > 0x3FFF0)
212 if (it == m_cache.end()) {
217 if (!m_cache.insert(CacheMap::value_type(device,entry)).second) {
225 for (channel=entry->
m_channelArray,
id=0; id<entry->m_count;
id++, channel++) {
233 for (channel=entry->
m_channelArray,
id=0; id<entry->m_count;
id++, channel++) {
255 unsigned int bufSize = 1630*(maxItemSize+4);
258 if (bufSize < maxItemSize+16)
259 bufSize = maxItemSize+16;
260 bufSize = (bufSize + 3) & ~0x3;
267 if (blockSize < maxItemSize+12)
268 blockSize = maxItemSize+12;
271 unsigned int pwr2Size = blockSize;
272 while ((m = (pwr2Size & (pwr2Size-1))) != 0)
274 blockSize = (pwr2Size < blockSize) ? pwr2Size<<1 : pwr2Size;
287 for (m=0; blockSize!=1; m++, blockSize>>=1);
294 CacheMap::iterator it = m_cache.find(device);
297 if (it == m_cache.end()) {
311 CacheMap::iterator it = m_cache.find(device);
314 if (it == m_cache.end()) {
326 CacheMap::iterator it = (device) ? m_cache.find(device) : m_cache.begin();
331 unsigned int positionW, block;
333 while (it != m_cache.end()) {
335 for (
unsigned int ch=0; ch<entry->
m_count; ch++) {
345 while ((nextBuffer = buffer->m_next) != NULL) {
346 buffer->m_next = nextBuffer->m_next;
350 if (positionW == 0) {
355 while (nextBuffer != buffer) {
356 prevBuffer = nextBuffer;
357 nextBuffer = nextBuffer->m_next;
384 buffer->m_firstFreePositionW = positionW;
385 buffer->m_lastTimestamp = buffer->m_firstTimestamp + prevItem->
m_timeOffset;
388 buffer->lookup[block].m_timeOffset = prevItem->
m_timeOffset;
408 CacheMap::iterator it = m_cache.find(device);
413 unsigned int positionW, sizeW, block;
415 if (it == m_cache.end()) {
425 if (timestamp == 0) {
447 positionW = buffer->m_firstFreePositionW;
462 while ((
next = buffer->m_next) != NULL) {
463 buffer->m_next =
next->m_next;
476 (positionW > 0 && timestamp >= buffer->m_firstTimestamp+0x10000)) {
479 if (positionW != buffer->m_firstFreePositionW) {
495 previousItem = nextItem;
500 buffer->m_firstFreePositionW = positionW;
501 buffer->m_lastTimestamp = buffer->m_firstTimestamp + previousItem->
m_timeOffset;
504 buffer->lookup[block].m_timeOffset = previousItem->
m_timeOffset;
512 if (buffer->m_next == NULL)
514 buffer = buffer->m_next;
521 if (positionW == 0) {
523 buffer->m_firstTimestamp = timestamp;
525 item->
m_timeOffset = (
unsigned short)(timestamp-buffer->m_firstTimestamp);
527 buffer->m_lastItemPositionW = positionW;
528 buffer->m_firstFreePositionW = positionW+sizeW;
529 buffer->m_lastTimestamp = timestamp;
532 buffer->lookup[block].m_timeOffset = item->
m_timeOffset;
534 buffer->m_firstFreePositionW = buffer->m_lastItemPositionW+item->
m_sizeW;
548 CacheMap::iterator it;
555 it = m_cache.find(device);
557 it = m_cache.begin();
559 if (it == m_cache.end()) {
569 *timestamp = (buffer) ? buffer->m_firstTimestamp+item->
m_timeOffset : 0;
573const CacheItem *Cache::getCurrentCacheItemInternal(
const void *device,
int id,
CacheTS timestamp)
575 CacheMap::iterator it = m_cache.find(device);
581 if (it == m_cache.end()) {
591 if (buffer && buffer->m_firstTimestamp+item->
m_timeOffset != timestamp)
598 const CacheItem *item = getCurrentCacheItemInternal(device, channel, timestamp);
604 const CacheItem *item = getCurrentCacheItemInternal(device, channel, timestamp);
606 if (!item || item->
m_sizeW != sizeW)
607 return (
double*)
addCacheItem(device, channel, timestamp, newdata,
length*
sizeof(
double));
611 double *ref = olddata;
615 if (
fabs(*
v-*ref) > threshold)
620 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)
BMesh const char void * data
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)
#define assert(assertion)
float length(VecOp< float, D >) RET
ccl_device_inline float2 fabs(const float2 a)
static void clear(Message &msg)
struct CacheItem m_firstItem
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