bool Document::save(const QString& to) { QString file = !to.isEmpty() ? to : _fileName; if (!file.endsWith(".kst")) { file.append(".kst"); } QFile f(file); if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate)) { _lastError = QObject::tr("File could not be opened for writing."); return false; } Q_ASSERT(objectStore()); objectStore()->cleanUpDataSourceList(); _fileName = file; QXmlStreamWriter xml; xml.setDevice(&f); xml.setAutoFormatting(true); xml.writeStartDocument(); xml.writeStartElement("kst"); xml.writeAttribute("version", "2.0"); xml.writeStartElement("data"); foreach (DataSourcePtr s, objectStore()->dataSourceList()) { s->saveSource(xml); }
Document::Document(MainWindow *window) : CoreDocument(), _win(window), _dirty(false), _isOpen(false) { _session = new SessionModel(objectStore()); _fileName.clear(); UpdateManager::self()->setStore(objectStore()); }
static char* test_object_persistence_with_store(LCStoreRef store, char *storeType) { LCContextRef context = contextCreate(store, NULL, 0); mu_assert("contextStringToType", contextStringToType(context, "LCString") == LCTypeString); char* string = "abcdef"; LCStringRef test = LCStringCreate(string); objectStore(test, context); objectDeleteCache(test, context); mu_assert("string persistence", LCStringEqualCString(test, string)); char hash[HASH_LENGTH]; objectHash(test, hash); FILE *fd = storeReadData(store, LCTypeString, hash); LCStringRef stringFromFile = objectCreateFromFile(context, fd); mu_assert("objectCreateFromFile", LCStringEqualCString(stringFromFile, string)); LCStringRef string1 = LCStringCreate("abc"); LCStringRef string2 = LCStringCreate("def"); LCStringRef string3 = LCStringCreate("ghi"); LCStringRef stringArray[] = {string1, string2, string3}; LCArrayRef array = LCArrayCreate(stringArray, 3); objectStore(array, context); objectDeleteCache(array, context); LCStringRef *strings = LCArrayObjects(array); mu_assert("array persistence", LCStringEqual(string1, strings[0]) && LCStringEqual(string2, strings[1]) && LCStringEqual(string3, strings[2])); LCKeyValueRef keyValue = LCKeyValueCreate(string1, array); objectStore(keyValue, context); objectDeleteCache(keyValue, context); objectCache(keyValue); mu_assert("keyValue persistence", LCStringEqual(LCKeyValueKey(keyValue), string1)); LCArrayRef mArray = LCMutableArrayCreate(stringArray, 3); objectStore(mArray, context); objectDeleteCache(mArray, context); LCMutableArrayAddObject(mArray, string1); objectStore(mArray, context); objectDeleteCache(mArray, context); objectCache(mArray); LCStringRef *strings1 = LCMutableArrayObjects(mArray); mu_assert("mutable array persistence", LCStringEqual(string1, strings1[0]) && LCStringEqual(string2, strings1[1]) && LCStringEqual(string3, strings1[2]) && LCStringEqual(string1, strings1[3])); LCMutableArrayAddObject(mArray, LCStringCreate("test1")); objectStoreAsComposite(mArray, context); objectDeleteCache(mArray, context); LCStringRef *strings2 = LCMutableArrayObjects(mArray); mu_assert("composite persistence", LCStringEqual(string1, strings2[0]) && LCStringEqual(string2, strings2[1]) && LCStringEqual(string3, strings2[2]) && LCStringEqual(string1, strings2[3])); return 0; }
void velIntoPos() { int objCount = *(int *)objectStore(NULL,GET_OBJ_COUNT); object *objects = (object *)objectStore(NULL,GET_OBJECT); Uint32 frameTime = *(Uint32 *)sdlStore(NULL,GET_FRAMETIME); int i; for(i = 0;i < objCount;i++) { if(objects[i].radius <= 0) continue; objects[i].vel.x += FIXED_MULT_NORMAL(frameTime,objects[i].force.x / objects[i].radius,1000); objects[i].vel.y += FIXED_MULT_NORMAL(frameTime,objects[i].force.y / objects[i].radius,1000); objects[i].force = (vector){0,0}; objects[i].pos.x += FIXED_MULT_NORMAL((double)frameTime,objects[i].vel.x,1000); objects[i].pos.y += FIXED_MULT_NORMAL((double)frameTime,objects[i].vel.y,1000); } }
void movePlayerFromData(int player,SDL_Event event) { //only run if the mouse is being pressed down int mouseDown = movePlayerStore(0,GET_PLAYER_STORE_MOUSE_DOWN); if(mouseDown) { //retrieve data object *obj = (object *)objectStore(NULL,GET_OBJECT); //retrieve mouse position vector mousePos; mousePos.x = (double)event.motion.x; mousePos.y = (double)event.motion.y; //convert mousepos from relative to absolute SDL_Rect *camera = (SDL_Rect *)sdlStore(NULL,GET_CAMERA); mousePos.x += (double)camera->x; mousePos.y += (double)camera->y; //Convert object data to vector vector objPos; objPos.x = obj[player].pos.x; objPos.y = obj[player].pos.y; //subtract coordinates from one another vector relative; FIND_REL_POS(mousePos,objPos,relative); //find opposing vector from origin of object relative.x = -relative.x; relative.y = -relative.y; //divide components by length of vector normalize(&relative); //determine force, //this should lead to a direction opposite of the mouse position relative the object obj[player].force.x = (double)SPEED * relative.x; obj[player].force.y = (double)SPEED * relative.y; } }
static void storeChildCallback(void *cookie, char *key, LCObjectRef objects[], size_t length, bool composite) { LCContextRef context = (LCContextRef)cookie; for (LCInteger i=0; i<length; i++) { if (!composite) { objectStore(objects[i], context); } } }
/** return a list of data objects where all dependencies appear earlier in the list */ ObjectList<DataObject> Document::sortedDataObjectList() { ObjectList<DataObject> sorted; ObjectList<DataObject> raw = objectStore()->getObjects<DataObject>(); sorted.clear(); // set the flag for all primitives: not strictly necessary // since it should have been done in the constructor, but... PrimitiveList all_primitives = objectStore()->getObjects<Primitive>(); int n = all_primitives.size(); for (int i=0; i<n; i++) { all_primitives[i]->setFlag(true); } // now unset the flags of all output primitives to indicate their parents haven't been // put in the sorted list yet n = raw.size(); for (int i=0; i<n; i++) { raw[i]->setOutputFlags(false); } // now place into the sorted list all data objects whose inputs haven't got parents // or whose inputs have parents which are already in the sorted list. // do this at most n^2 times, which is worse than worse case. int i=0; while (!raw.isEmpty() && (++i <= n*n)) { DataObjectPtr D = raw.takeFirst(); if (D->inputFlagsSet()) { D->setOutputFlags(true); sorted.append(D); } else { raw.append(D); // try again later } } if ((i== n*n) && (n>1)) { qDebug() << "Warning: loop detected, File will not be able to be loaded correctly!"; while (!raw.isEmpty()) { DataObjectPtr D = raw.takeFirst(); sorted.append(D); } } return sorted; }
NS_IMETHODIMP IDBIndex::GetObjectStore(nsIIDBObjectStore** aObjectStore) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); nsCOMPtr<nsIIDBObjectStore> objectStore(mObjectStore); objectStore.forget(aObjectStore); return NS_OK; }
void moveCamera() { //Get data SDL_Rect *camera = sdlStore(NULL,GET_CAMERA); object *objects = objectStore(NULL,GET_OBJECT); int selObj = *(int *)sdlStore(NULL,GET_SELECTED_OBJECT); //Set camera position to center of player object camera->x = (int)objects[selObj].pos.x - (camera->w / 2); camera->y = (int)objects[selObj].pos.y - (camera->h / 2); //Adjust camera position so it isn't displaying anything outside of bounds if(camera->x < 0) camera->x = 0; if(camera->y < 0) camera->y = 0; if(camera->x + camera->w > LEVEL_WIDTH) camera->x = LEVEL_WIDTH - camera->w; if(camera->y + camera->h > LEVEL_HEIGHT) camera->y = LEVEL_HEIGHT - camera->h; }
WebIDBMetadata::operator IDBDatabaseMetadata() const { IDBDatabaseMetadata db(name, id, version, intVersion, maxObjectStoreId); for (size_t i = 0; i < objectStores.size(); ++i) { const ObjectStore webObjectStore = objectStores[i]; IDBObjectStoreMetadata objectStore(webObjectStore.name, webObjectStore.id, webObjectStore.keyPath, webObjectStore.autoIncrement, webObjectStore.maxIndexId); for (size_t j = 0; j < webObjectStore.indexes.size(); ++j) { const Index webIndex = webObjectStore.indexes[j]; IDBIndexMetadata index(webIndex.name, webIndex.id, webIndex.keyPath, webIndex.unique, webIndex.multiEntry); objectStore.indexes.set(index.id, index); } db.objectStores.set(objectStore.id, objectStore); } return db; }
void underOverlap() { object *obj = objectStore(NULL,GETOBJECT); int j; for(j = 0;j < OBJECTS;j++) { if(obj[j].radius <= 0) continue; int i; for(i = 0;i < OBJECTS;i++) { if(j == i || obj[i].radius <= 0) continue; int combinedRadius = obj[j].radius + obj[i].radius; vector relativePos = findRelativePos(obj[j].pos,obj[i].pos); double distance = sqrt(relativePos.x * relativePos.x + relativePos.y * relativePos.y); if(distance >= combinedRadius) continue; double angle = atan2(obj[i].pos.y - obj[j].pos.y,obj[i].pos.x - obj[j].pos.x); double radius = obj[j].radius + obj[i].radius; obj[i].pos.x = (cos(angle) * radius) + obj[j].pos.x; obj[i].pos.y = (sin(angle) * radius) + obj[j].pos.y; } } }
void objectsStore(LCObjectRef objects[], size_t length, LCContextRef context) { for (LCInteger i=0; i<length; i++) { objectStore(objects[i], context); } }
void initObjectPosAndSize() { object *obj = objectStore(NULL,GET_OBJECT); int player = *(int *)sdlStore(NULL,GET_PLAYER); int objCount = *(int *)objectStore(NULL,GET_OBJ_COUNT); int i; obj[player].radius = STARTING_PLAYER_OBJECT_SIZE; obj[player].pos = (vector) { LEVEL_WIDTH / 2,LEVEL_HEIGHT / 2 }; //Object being moved for(i = 0; i < objCount; i++) { if(i == player) continue; obj[i].radius = randomResult(MAX_OBJECT_SIZE,MIN_OBJECT_SIZE); unsigned int run = 0, found = 0; vector newPos; unsigned long combinedRadius; int k; //Object who's position is being used to find new object position for(k = 0;; k++) { if(k >= i) k = 0, run++; if(k == i || obj[k].radius == 0) continue; if(run == 0) combinedRadius = obj[k].radius + obj[i].radius + STARTING_OBJECT_SPACING; else combinedRadius = obj[k].radius + obj[i].radius + STARTING_OBJECT_SPACING + (STARTING_OBJECT_SPACING_INCREMENT * run); found = 1; int m; randomSelector sides[SIDES_TO_CHECK]; int sidesLeft = SIDES_TO_CHECK - 1; for(m = 0; m < SIDES_TO_CHECK; m++) sides[m].num = m, sides[m].checked = 0; //Cycle through new positions for(m = 0; m < SIDES_TO_CHECK; m++) { int randNum = randomResult(sidesLeft,0); //printf("rand %d, sides left %d num %d\n",randNum,sidesLeft,sides[randNum].num); sides[randNum].checked = 1; switch(sides[randNum].num) { case 0: if(obj[k].pos.x + combinedRadius + obj[i].radius < LEVEL_WIDTH) { newPos = (vector) { obj[k].pos.x + combinedRadius, obj[k].pos.y }; //printf("%d selected right of %d\n",i,k); }; break; case 1: if(obj[k].pos.x - combinedRadius - obj[i].radius > 0) { newPos = (vector) { obj[k].pos.x - combinedRadius, obj[k].pos.y }; //printf("%d selected left of %d\n",i,k); }; break; case 2: if(obj[k].pos.y + combinedRadius + obj[i].radius < LEVEL_HEIGHT) { newPos = (vector) { obj[k].pos.x, obj[k].pos.y + combinedRadius }; //printf("%d selected down of %d\n",i,k); }; break; case 3: if(obj[k].pos.y - combinedRadius - obj[i].radius > 0) { newPos = (vector) { obj[k].pos.x, obj[k].pos.y - combinedRadius }; //printf("%d selected up of %d\n",i,k); }; break; } int j; for(j = SIDES_TO_CHECK; j > 0; j--) { if(sides[j].checked == 0) sides[randNum] = sides[j]; } sidesLeft--; //Checking to see whether new found position collides with other objects for(j = 0; j < objCount; j++) { if(isCollidedVectorAndRadius(newPos,obj[j].pos,obj[j].radius + obj[i].radius)) { found = 0; } //DEBUG //printf("r %lu x %f y %f x2 %f y2 %f\n",obj[j].radius + obj[i].radius,newPos.x,newPos.y,obj[j].pos.x,obj[j].pos.y); } if(found) break; } /* if(found == 1) printf("%d used %d\n",i,k); else printf("%d attempted to use %d\n",i,k); */ /* printf("i %d, k %d, run %u, np-x %.0f, np-y %.0f, k-x %.0f, k-y %.0f, cr %lu\n" ,i,k,run,newPos.x,newPos.y,obj[k].pos.x,obj[k].pos.y,combinedRadius); */ if(found) break; } if(found == 1) { /* printf("FOUND - i %d\n",i); printf("np-x %.0f, np-y %.0f\n",newPos.x,newPos.y); */ obj[i].pos = newPos; } //DEBUG /* int m; for(m = 0;m < OBJECTS;m++) { if(i == m) continue; if(isCollidedVectorAndRadius(newPos,obj[m].pos,obj[i].radius + obj[m].radius)) { printf("%d is colliding with %d\n",i,m); } } if(found == 0) printf("nothing found for %d\n",i); puts(""); */ } }
void updateSelectedObj(int keyboard) { object *obj = objectStore(NULL,GET_OBJECT); int player = *(int *)sdlStore(NULL,GET_PLAYER); if(obj[player].radius != 0) { return; } int selObj = *(int *)sdlStore(NULL,GET_SELECTED_OBJECT); int down = 0; int up = 0; switch(keyboard) { case KEYBOARD_LEFT: selObj--; down = 1; break; case KEYBOARD_RIGHT: selObj++; up = 1; break; } int objCount = *(int *)objectStore(NULL,GET_OBJ_COUNT); if(selObj >= objCount) { selObj = 0; } if(selObj < 0) { selObj = objCount - 1; } if(obj[selObj].radius == 0) { if(up) { int i; for(i = selObj;;i++) { if(i >= objCount) { i = 0; } if(obj[i].radius > 0) { selObj = i; break; } } } if(down) { int i; for(i = selObj;;i--) { if(i < 0) { i = objCount - 1; } if(obj[i].radius > 0) { selObj = i; break; } } } } //DEBUG //printf("selObj: %d selObj-radius: %lu\n\n",selObj,obj[selObj].radius); sdlStore((void *)&selObj,SET_SELECTED_OBJECT); }