1. 确定网格边界即世界坐标
通过屏幕坐标系,化为256*256的网格,但是Y轴只用到128
简单来书就是像比图比例尺18900:256 = 1:0.00044554
一个贴图会有屏幕坐标,然后进行缩放,计算在网格中的边界值(bounds)
2. 网格实现spatialGrid
// 根:对象
static inline void getCookie(int* raw, iso::IsoWorldCookie*& cookie)
{
// cppcheck-suppress pointerSize; 这就是它的意图
memcpy(&cookie, raw, sizeof(iso::IsoWorldCookie*));
}
static inline void setCookie(int* raw, iso::IsoWorldCookie* cookie)
{
// cppcheck-suppress pointerSize ; 这就是它的意图
memcpy(raw, &cookie, sizeof(iso::IsoWorldCookie*));
}
// 链接:光标根(32 位,有效 20)
static inline int getRoot(int* raw)
{
return raw[0];
}
static inline void setRoot(int* raw, int root)
{
raw[0] = root;
}
// 根:特征
static inline int getMark(int* raw)
{
return raw[2];
}
static inline void setMark(int* raw, int mark)
{
raw[2] = mark;
}
// 链接:下一个链接光标(32 位,有效 20)
static inline int getNext(int* raw)
{
return raw[1];
}
static inline void setNext(int* raw, int next)
{
raw[1] = next;
}
// Link: 单元索引(16 位)
static inline int getIndex(int* raw)
{
return ((uint16_t*)raw)[4];
}
static inline void setIndex(int* raw, int index)
{
((uint16_t*)raw)[4] = (uint16_t)index;
}
// Link: 对象的光标部分(24 位,有效 20)
static inline int getPart(int* raw)
{
return (((uint8_t*)raw)[14] << 16) | ((uint16_t*)raw)[5];
}
static inline void setPart(int* raw, int part)
{
((uint16_t*)raw)[5] = (uint16_t)part;
((uint8_t*)raw)[14] = (uint8_t)(part >> 16);
}
// Link: 上一个链接光标(24 位,有效 20)
static inline int getPrev(int* raw)
{
return (((uint8_t*)raw)[15] << 16) | ((uint16_t*)raw)[6];
}
static inline void setPrev(int* raw, int prev)
{
((uint16_t*)raw)[6] = (uint16_t)prev;
((uint8_t*)raw)[15] = (uint8_t)(prev >> 16);
}
static inline int* FetchLink(int* const pages[], int cursor)
{
int* page = pages[cursor >> 16];
return reinterpret_cast<int*>((uint8_t*)page + (cursor & 0xFFFC));
}
int linkCursor = _Grid[index];
while( linkCursor )
{
int* link = FetchLink(_Pages, linkCursor);
int rootCursor = getRoot(link);
int* root = FetchLink(_Pages, rootCursor);
int visible = getMark(root);
visible++;
setMark(root, visible);
if( visible == 1 )
{
iso::IsoWorldCookie* cookie;
getCookie(root, cookie);
_callback->onBecomesVisible(cookie);
}
linkCursor = getNext(link);
}