/* obj_loadObjects Load objects for an area. (The map must be loaded first before this can be done.) */ void obj_loadObjects(char *areafile) { extern ObjContainer the_objects; int l; /* Allocate the same number of layers as the map has: */ the_objects.n_layers = map_getNLayers(); the_objects.layers = (ObjLayer *) dyn_1dArrayAlloc(the_objects.n_layers, sizeof(ObjLayer)); /* Allocate the layers based on the dimensions of sectors and the dimensions of each map layer */ for (l = 0; l < the_objects.n_layers; l++) { /* Make sure to round up here so that there are enough sectors: */ the_objects.layers[l].w = (int) ceilf(obj_realToSectorX((float) map_mapToRealX(map_getLayerWidth(l)))); the_objects.layers[l].h = (int) ceilf(obj_realToSectorY((float) map_mapToRealY(map_getLayerHeight(l)))); the_objects.layers[l].obj_array = (Object ***) dyn_arrayAlloc(the_objects.layers[l].w, the_objects.layers[l].h, sizeof(Object *)); } /* Load the objects from the area file */ file_openFile(areafile, 'r'); /* Loop through all of the objects in the file */ while (file_nextObject(areafile)) { Velocity vel; Point pos; int z, type; /* Get the attributes for this object */ file_getObjectAtts(areafile, &z, &pos, &vel, &type); /* Create the object and put it into the container */ insertObj(newObject(z, pos, vel, type)); } /* Close the file */ file_closeFile(areafile); }
INT32 rtnCoordInsert::shardAnObj( CHAR *pInsertor, const CoordCataInfoPtr &cataInfo, pmdEDUCB * cb, GroupSubCLMap &groupSubCLMap ) { INT32 rc = SDB_OK; std::string subCLName ; UINT32 groupID = CAT_INVALID_GROUPID; try { BSONObj insertObj( pInsertor ) ; CoordCataInfoPtr subClCataInfo; rc = cataInfo->getSubCLNameByRecord( insertObj, subCLName ) ; PD_CHECK( SDB_OK == rc, SDB_CLS_COORD_NODE_CAT_VER_OLD, error, PDWARNING, "couldn't find the match sub-collection(rc=%d)", rc ) ; rc = rtnCoordGetCataInfo( cb, subCLName.c_str(), FALSE, subClCataInfo ); PD_CHECK( SDB_OK == rc, SDB_CLS_COORD_NODE_CAT_VER_OLD, error, PDWARNING, "failed to get catalog of sub-collection(%s)", subCLName.c_str() ); rc = subClCataInfo->getGroupByRecord( insertObj, groupID ); PD_CHECK( SDB_OK == rc, SDB_CLS_COORD_NODE_CAT_VER_OLD, error, PDWARNING, "couldn't find the match catalog of " "sub-collection(%s)", subCLName.c_str() ); (groupSubCLMap[ groupID ])[ subCLName ].push_back( pInsertor ); } catch ( std::exception &e ) { PD_CHECK( FALSE, SDB_INVALIDARG, error, PDERROR, "Failed to shard the data, occur unexpected error:%s", e.what() ); } done: return rc ; error: goto done ; }
/* obj_handleSignals Handle signals that have accumulated in the module's queue. Such signals may include object killing or spawning signals. */ void obj_handleSignals(void) { extern SigQ signals; Signal sig; while (sig_poll(&signals, &sig)) { switch (sig.type) { case SPAWN_KILL_SIG: switch (sig.sig.sk.todo) { case SPAWN_OBJECT: insertObj((Object *) sig.sig.sk.obj); break; case KILL_OBJECT: freeObject((Object *) sig.sig.sk.obj); break; } break; } } }
/* obj_setObjPos sets the position of an object, making sure it is in the appropriate sector */ void obj_setObjPos(Object *object_ptr, Point new_pos) { /* Move it if the sector has changed: */ if (obj_realToSectorX(new_pos.x) != obj_realToSectorX(object_ptr->pos.x) || obj_realToSectorY(new_pos.y) != obj_realToSectorY(object_ptr->pos.y)) { /* Remove the object from its current sector: */ removeObj(object_ptr); /* Actually update the position: */ object_ptr->pos = new_pos; /* Insert the object into its new sector: */ insertObj(object_ptr); } /* If it hasn't changed sectors just update the position: */ else { object_ptr->pos = new_pos; } }
bool graph::processObj(string line) { try { int last = 0; for (unsigned int i = 0; i < line.length(); i++) { if (line.at(i) == ';') { string sub = line.substr(last, i - last + 1); int benefit, weight; string name; int slast = 0, type = 0; for (unsigned int j = 0; j < sub.length(); j++) { if (sub.at(j) == ',' || sub.at(j) == ';' || j == sub.length() - 1) { switch(type) { case 0: name = sub.substr(slast, j - slast); break; case 1: weight = atoi(sub.substr(slast, j - slast).c_str()); break; case 2: benefit = atoi(sub.substr(slast, j - slast).c_str()); break; } slast = j + 1; type++; } } obj *nobj = new obj(objc++, name, weight, benefit); insertObj(nobj); last = i + 1; } } return true; } catch (exception e) { return false; } }
void _bbObjInsAfter( BBObj *o1,BBObj *o2 ){ if( o1==o2 ) return; unlinkObj( o1 ); insertObj( o1,o2->next ); }
void _bbObjInsBefore( BBObj *o1,BBObj *o2 ){ if( o1==o2 ) return; unlinkObj( o1 ); insertObj( o1,o2 ); }
void _bbObjRelease( BBObj *obj ){ if( !obj || --obj->ref_cnt ) return; unlinkObj( obj ); insertObj( obj,&obj->type->free ); --unrelObjCnt; }
//callbacks void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: exit (0); break; //draw objects case 'y': insertObj(Cube); break; case 'u': insertObj(Sphere); break; case 'i': insertObj(Cone); break; case 'o': insertObj(Torus); break; case 'p': insertObj(Teapot); break; //transformations case 'a': //-x if (sceneObjs->size()!=0) { if (mode%3==0) currentObj->translate(-0.1, 0, 0); if (mode%3==1&&!currentObj->isLight) currentObj->scale(-0.1, 0,0); if (mode%3==2&&!currentObj->isLight) currentObj->rotate(-5,0,0); } break; case 'd': //+x if (sceneObjs->size()!=0) { if (mode%3==0) currentObj->translate(0.1, 0, 0); if (mode%3==1&&!currentObj->isLight) currentObj->scale(0.1,0,0); if (mode%3==2&&!currentObj->isLight) currentObj->rotate(5,0,0); } break; case 'q': //-z if (sceneObjs->size()!=0) { if (mode%3==0) currentObj->translate(0, 0, -0.1); if (mode%3==1&&!currentObj->isLight) currentObj->scale(0, 0,-0.1); if (mode%3==2&&!currentObj->isLight) currentObj->rotate(0,0,-5); } break; case 'e': //+z if (sceneObjs->size()!=0) { if (mode%3==0) currentObj->translate(0, 0, 0.1); if (mode%3==1&&!currentObj->isLight) currentObj->scale(0, 0,0.1); if (mode%3==2&&!currentObj->isLight) currentObj->rotate(0,0,5); } break; case 's': //-y if (sceneObjs->size()!=0) { if (mode%3==0) currentObj->translate(0, -0.1, 0); if (mode%3==1&&!currentObj->isLight) currentObj->scale(0, -0.1,0); if (mode%3==2&&!currentObj->isLight) currentObj->rotate(0,-5,0); } break; case 'w': //+y if (sceneObjs->size()!=0) { if (mode%3==0) currentObj->translate(0, 0.1, 0); if (mode%3==1&&!currentObj->isLight) currentObj->scale(0, 0.1,0); if (mode%3==2&&!currentObj->isLight) currentObj->rotate(0,5,0); } break; case 't': //transform type toggle mode++; if (mode%3==0) transformMode = t; if (mode%3==1) transformMode = s; if (mode%3==2) transformMode = r; break; case 32: //load/save if (glutGetModifiers()==GLUT_ACTIVE_CTRL) { sceneObjs = SG->load(); nextChild = sceneObjs->size(); currentObj = sceneObjs->at(0); currentObj->select(); } else SG->save(); break; //toggle materials case '1': curMat = m1; break; case '2': curMat = m2; break; case '3': curMat = m3; break; case '4': curMat = m4; break; case '5': curMat = m5; break; //change selected object's material to current material case 'm': if (!currentObj->isLight) currentObj->changeMaterial(curMat); break; //delete selected object case 'x': if (sceneObjs->size()!=0) { deleteObj(currentObj->ID); } break; //reset scene case 'r': SG = new SceneGraph(); nextChild = 0; sceneObjs = new vector<SceneObj*>; insertLight(light_pos0, amb0, diff0, spec0, 0); insertLight(light_pos1, amb1, diff1, spec1, 1); break; case 9: // toggle selected object (was used before ray picking implemented, still useful anyway) currentObj->unselect(); currentObj = sceneObjs->at(currentObjIndex++%sceneObjs->size()); currentObj->select(); break; default: break; } glutPostRedisplay(); }