I'm using cocos2dx and sqlite to store datum. The table looks like this: x INT, y INT, className TEXT, properties TEXT
. I use json to serialize terrains and sprites. But I don't know how to synchronise it. Below is how I'm doing:
//1: create a interface takes an range and returns data in it.
Data getData(Rect range);
//both are global objects.
cachedRange = [];
cachedData = [];
//2: while reading from sqlite, I scale the range and cached other data.
Data getData(Rect range){
//if it has been cached.
if(cachedRect.contains(range)){
return retrieveDataFromCached(cachedData, range);
}
var scaledRange = scale(range, 10);
var data = retrieveFromSqlite(scaledRange);
var inRange = [];
for(var d : data){
if(range.contains(d)){
inRange.append(d);
}else{
cached.append(d);
}
}
cachedRange.append(range);
return inRange;
}
However, these data will change. For example, some mobs are instantiated and then killed, and some are moved. When should I delete original records of the table.