void QgsProviderRegistry::setLibraryDirectory( QDir const & path ) { mLibraryDirectory = path; clean(); init(); }
Histogram::Histogram(unsigned char max, unsigned char min, unsigned char *n) { clean(); Resize(max, min, n); }
Object::~Object(){ clean(); }
int main(int argc, char **argv) { pdf_cmap *cmap; fz_stream *fi; FILE *fo; char name[256]; char *realname; int i, k, m; fz_context *ctx; if (argc < 3) { fprintf(stderr, "usage: cmapdump output.c lots of cmap files\n"); return 1; } ctx = fz_new_context(NULL, NULL, FZ_STORE_UNLIMITED); if (!ctx) { fprintf(stderr, "cannot initialise context\n"); return 1; } #undef fopen fo = fopen(argv[1], "wb"); if (!fo) { fprintf(stderr, "cmapdump: could not open output file '%s'\n", argv[1]); return 1; } fprintf(fo, "/* This is an automatically generated file. Do not edit. */\n"); for (i = 2; i < argc; i++) { realname = strrchr(argv[i], '/'); if (!realname) realname = strrchr(argv[i], '\\'); if (realname) realname ++; else realname = argv[i]; /* ignore VCS folders (such as .svn) */ if (*realname == '.') continue; if (strlen(realname) > (sizeof name - 1)) { fprintf(stderr, "cmapdump: file name too long\n"); if (fclose(fo)) { fprintf(stderr, "cmapdump: could not close output file '%s'\n", argv[1]); return 1; } return 1; } strcpy(name, realname); clean(name); fi = fz_open_file(ctx, argv[i]); cmap = pdf_load_cmap(ctx, fi); fz_close(fi); fprintf(fo, "\n/* %s */\n\n", cmap->cmap_name); if (cmap->rlen) { fprintf(fo, "static const pdf_range cmap_%s_ranges[] = {", name); for (k = 0; k < cmap->rlen; k++) { if (k % 4 == 0) fprintf(fo, "\n"); fprintf(fo, "{%uu,%uu,%uu},", cmap->ranges[k].low, cmap->ranges[k].high, cmap->ranges[k].out); } fprintf(fo, "\n};\n\n"); } if (cmap->xlen) { fprintf(fo, "static const pdf_xrange cmap_%s_xranges[] = {", name); for (k = 0; k < cmap->xlen; k++) { if (k % 4 == 0) fprintf(fo, "\n"); fprintf(fo, "{%uu,%uu,%uu},", cmap->xranges[k].low, cmap->xranges[k].high, cmap->xranges[k].out); } fprintf(fo, "\n};\n\n"); } if (cmap->mlen > 0) { fprintf(fo, "static const pdf_mrange cmap_%s_mranges[] = {", name); for (k = 0; k < cmap->mlen; k++) { fprintf(fo, "\n{%uu,%uu,{", cmap->mranges[k].low, cmap->mranges[k].len); for (m = 0; m < PDF_MRANGE_CAP; ++m) fprintf(fo, "%uu,", cmap->mranges[k].out[m]); fprintf(fo, "}},"); } fprintf(fo, "\n};\n\n"); } fprintf(fo, "static pdf_cmap cmap_%s = {\n", name); fprintf(fo, "\t{-1, pdf_free_cmap_imp}, "); fprintf(fo, "\"%s\", ", cmap->cmap_name); fprintf(fo, "\"%s\", 0, ", cmap->usecmap_name); fprintf(fo, "%u, ", cmap->wmode); fprintf(fo, "%u,\n\t{ ", cmap->codespace_len); if (cmap->codespace_len == 0) { fprintf(fo, "{0,0,0},"); } for (k = 0; k < cmap->codespace_len; k++) { fprintf(fo, "{%u,%uu,%uu},", cmap->codespace[k].n, cmap->codespace[k].low, cmap->codespace[k].high); } fprintf(fo, " },\n"); if (cmap->rlen) fprintf(fo, "\t%u, %u, (pdf_range*) cmap_%s_ranges,\n", cmap->rlen, cmap->rlen, name); else fprintf(fo, "\t0, 0, NULL,\n"); if (cmap->xlen) fprintf(fo, "\t%u, %u, (pdf_xrange*) cmap_%s_xranges,\n", cmap->xlen, cmap->xlen, name); else fprintf(fo, "\t0, 0, NULL,\n"); if (cmap->mlen) fprintf(fo, "\t%u, %u, (pdf_mrange*) cmap_%s_mranges,\n", cmap->mlen, cmap->mlen, name); else fprintf(fo, "\t0, 0, NULL,\n"); fprintf(fo, "};\n"); if (getenv("verbose")) printf("\t{\"%s\",&cmap_%s},\n", cmap->cmap_name, name); } if (fclose(fo)) { fprintf(stderr, "cmapdump: could not close output file '%s'\n", argv[1]); return 1; } fz_free_context(ctx); return 0; }
void on_signal(int sig) { debug("Caught signal %d.\n", sig); clean(); }
Scope::~Scope() { clean(); }
int ObjLoader::Load(const char* fileName) { //Open the model file ifstream in(fileName); //Temp buffer char buf[256]; if (!in.is_open()) { //If it didn't load cout << "Not opened" << endl; return -1; } while (!in.eof()) { //While we are not at the end of the file, read everything as a string to the coord vector in.getline(buf, 256); coord.push_back(new string(buf)); } //Go through the line and decide what kind of line it is for (int i = 0; i < coord.size(); i++) { //If it's a comment if ((*coord[i])[0] == '#') { //We don't have to do anything with it continue; } //If it's a vertex else if ((*coord[i])[0] == 'v' && (*coord[i])[1] == ' ') { float tmpx, tmpy, tmpz; //Read the 3 floats, which makes up the vertex sscanf(coord[i]->c_str(), "v %f %f %f", &tmpx, &tmpy, &tmpz); //And put it in the vertex vector vertex.push_back(new Vector3D(tmpx, tmpy, tmpz)); } //If it's a normal vector else if ((*coord[i])[0] == 'v' && (*coord[i])[1] == 'n') { float tmpx, tmpy, tmpz; //Read the 3 floats, which makes up the normal sscanf(coord[i]->c_str(), "vn %f %f %f", &tmpx, &tmpy, &tmpz); //And put it in the normal vector normals.push_back(new Vector3D(tmpx, tmpy, tmpz)); isnormals = true; } //If it's a face else if ((*coord[i])[0] == 'f') { int a, b, c, d, e; //If this is a quad if (count(coord[i]->begin(), coord[i]->end(), ' ') == 4) { //If it contains a normal vector, but doesn't contain a texture coorinate if (coord[i]->find("//") != string::npos) { //Read in this form sscanf(coord[i]->c_str(), "f %d//%d %d//%d %d//%d %d//%d", &a, &b, &c, &b, &d, &b, &e, &b); //We don't care about the texture coorinate in this case faces.push_back(new face(b, a, c, d, e, 0, 0, 0, 0, curmat)); } //If we have texture coorinate and normal vectors else if (coord[i]->find("/") != string::npos) { //Texture Coorinates int t[4]; //Read in this form, and put to the end of the vector sscanf(coord[i]->c_str(), "f %d/%d/%d %d/%d/%d %d/%d/%d %d/%d/%d", &a, &t[0], &b, &c, &t[1], &b, &d, &t[2], &b, &e, &t[3], &b); faces.push_back(new face(b, a, c, d, e, t[0], t[1], t[2], t[3], curmat)); } //Else we don't have normal vectors or texture coorinates else { sscanf(coord[i]->c_str(), "f %d %d %d %d", &a, &b, &c, &d); faces.push_back(new face(-1, a, b, c, d, 0, 0, 0, 0, curmat)); } } //If it's a triangle else { //Do the same, except we use one less vertex/texture coorinate/face number if (coord[i]->find("//") != string::npos) { sscanf(coord[i]->c_str(), "f %d//%d %d//%d %d//%d", &a, &b, &c, &b, &d, &b); faces.push_back(new face(b, a, c, d, 0, 0, 0, curmat)); } else if (coord[i]->find("/") != string::npos) { int t[3]; sscanf(coord[i]->c_str(), "f %d/%d/%d %d/%d/%d %d/%d/%d", &a, &t[0], &b, &c, &t[1], &b, &d, &t[2], &b); faces.push_back(new face(b, a, c, d, t[0], t[1], t[2], curmat)); } else { sscanf(coord[i]->c_str(), "f %d %d %d", &a, &b, &c); faces.push_back(new face(-1, a, b, c, 0, 0, 0, curmat)); } } } //Use material_name else if ((*coord[i])[0] == 'u' && (*coord[i])[1] == 's' && (*coord[i])[2] == 'e') { char tmp[200]; //Read the name of the material to tmp sscanf(coord[i]->c_str(), "usemtl %s", tmp); //Go through all of the materials for (int i = 0; i<materials.size(); i++) { //And compare the tmp with the name of the material if (strcmp(materials[i]->name.c_str(), tmp) == 0) { //If it's equal then set the current material to that curmat = i; break; } } } //Material library, a file, which contain all of the materials else if ((*coord[i])[0] == 'm' && (*coord[i])[1] == 't' && (*coord[i])[2] == 'l' && (*coord[i])[3] == 'l') { char filen[200]; //Read the fileName sscanf(coord[i]->c_str(), "mtllib %s", filen); //Open the file ifstream mtlin(filen); //If not opened, show a error message, clean all memory, then return with -1 if (!mtlin.is_open()) { cout << "connot open the material file" << endl; clean(); return -1; } //We use materials ismaterial = true; //Contain the line of the file vector<string> tmp; char c[200]; while (!mtlin.eof()) { //Read all lines to tmp mtlin.getline(c, 200); tmp.push_back(c); } //Name of the material char name[200]; //fileName of the texture char fileName[200]; //Colors, shininess, etc float amb[3], dif[3], spec[3], alpha, ns, ni; int illum; unsigned int texture; //Do we already have a material read in to these variables? bool ismat = false; //Set fileName to nullbyte character strcpy(fileName, "\0"); //Go through all lines of the mtllib file for (int i = 0; i<tmp.size(); i++) { //Ignore comments if (tmp[i][0] == '#') continue; //New material if (tmp[i][0] == 'n' && tmp[i][1] == 'e' && tmp[i][2] == 'w') { //If we have a material if (ismat) { //If we have a texture if (strcmp(fileName, "\0") != 0) { //Push back materials.push_back(new materialObj(name, alpha, ns, ni, dif, amb, spec, illum, texture)); strcpy(fileName, "\0"); } //Push back, but use -1 to texture else { materials.push_back(new materialObj(name, alpha, ns, ni, dif, amb, spec, illum, -1)); } } //We start from a fresh material ismat = false; //Read in the name sscanf(tmp[i].c_str(), "newmtl %s", name); } //Shininess else if (tmp[i][0] == 'N' && tmp[i][1] == 's') { sscanf(tmp[i].c_str(), "Ns %f", &ns); ismat = true; } //Ambient else if (tmp[i][0] == 'K' && tmp[i][1] == 'a') { sscanf(tmp[i].c_str(), "Ka %f %f %f", &amb[0], &amb[1], &amb[2]); ismat = true; } //Diffuse else if (tmp[i][0] == 'K' && tmp[i][1] == 'd') { sscanf(tmp[i].c_str(), "Kd %f %f %f", &dif[0], &dif[1], &dif[2]); ismat = true; } //Specular else if (tmp[i][0] == 'K' && tmp[i][1] == 's') { sscanf(tmp[i].c_str(), "Ks %f %f %f", &spec[0], &spec[1], &spec[2]); ismat = true; } //Others else if (tmp[i][0] == 'N' && tmp[i][1] == 'i') { sscanf(tmp[i].c_str(), "Ni %f", &ni); ismat = true; } //Alpha else if (tmp[i][0] == 'd' && tmp[i][1] == ' ') { sscanf(tmp[i].c_str(), "d %f", &alpha); ismat = true; } //Illum (Not Used) else if (tmp[i][0] == 'i' && tmp[i][1] == 'l') { sscanf(tmp[i].c_str(), "illum %d", &illum); ismat = true; } //Texture else if (tmp[i][0] == 'm' && tmp[i][1] == 'a') { sscanf(tmp[i].c_str(), "map_Kd %s", fileName); //Read the fileName, and use the loadTexture function to load it, and get the id. texture = loadTexture(fileName); ismat = true; } } //There is no newmat after the last newmat, so we have to put the last material 'manually' if (ismat) { if (strcmp(fileName, "\0") != 0) { materials.push_back(new materialObj(name, alpha, ns, ni, dif, amb, spec, illum, texture)); } else{ materials.push_back(new materialObj(name, alpha, ns, ni, dif, amb, spec, illum, -1)); } } } //Back to the obj file, texture coorinate else if ((*coord[i])[0] == 'v' && (*coord[i])[1] == 't') { float u, v; //Read the uv coordinate sscanf(coord[i]->c_str(), "vt %f %f", &u, &v); //I push back 1-v instead of normal v, because obj file use the upper left corner as 0,0 coordinate texturecoordinate.push_back(new texcoordObj(u, 1 - v)); //OpenGL usesvthe bottom left corner as 0, 0, so convert it istexture = true; } } //If for some reason the material file doesn't contain any material, we don't have a material if (materials.size() == 0) ismaterial = false; //Else we have a material else ismaterial = true; //Debug purposes //cout << vertex.size() << " " << normals.size() << " " << faces.size() << " " << materials.size() << endl; //Draw int num; //I generate a unique identifier for the list num = glGenLists(1); glNewList(num, GL_COMPILE); //The last material (default -1, which doesn't exist, so we use the first material) int last = -1; //Go through all faces for (int i = 0; i<faces.size(); i++) { //If we have a meterial AND the last material is not the same if (last != faces[i]->mat && ismaterial) { //Set all of the material property float diffuse[] = { materials[faces[i]->mat]->dif[0], materials[faces[i]->mat]->dif[1], materials[faces[i]->mat]->dif[2], 1.0 }; float ambient[] = { materials[faces[i]->mat]->amb[0], materials[faces[i]->mat]->amb[1], materials[faces[i]->mat]->amb[2], 1.0 }; float specular[] = { materials[faces[i]->mat]->spec[0], materials[faces[i]->mat]->spec[1], materials[faces[i]->mat]->spec[2], 1.0 }; glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse); glMaterialfv(GL_FRONT, GL_AMBIENT, ambient); glMaterialfv(GL_FRONT, GL_SPECULAR, specular); glMaterialf(GL_FRONT, GL_SHININESS, materials[faces[i]->mat]->ns); //Set the current to last last = faces[i]->mat; //if we don't have texture, disable it, else enable it if (materials[faces[i]->mat]->texture == -1) glDisable(GL_TEXTURE_2D); else { glEnable(GL_TEXTURE_2D); //And use it glBindTexture(GL_TEXTURE_2D, materials[faces[i]->mat]->texture); } } //If quad if (faces[i]->four) { //glBegin(GL_QUADS); // ////If there are normals //if (isnormals) //{ // //Use them // glNormal3f(normals[faces[i]->facenum - 1]->x, normals[faces[i]->facenum - 1]->y, normals[faces[i]->facenum - 1]->z); //} //////If there are textures ////if (istexture && materials[faces[i]->mat]->texture != -1) ////{ // ////Set the texture coorinate // //glTexCoord2f(texturecoordinate[faces[i]->texcoord[0] - 1]->u, texturecoordinate[faces[i]->texcoord[0] - 1]->v); ////} //glVertex3f(vertex[faces[i]->faces[0] - 1]->x, vertex[faces[i]->faces[0] - 1]->y, vertex[faces[i]->faces[0] - 1]->z); ///*if (istexture && materials[faces[i]->mat]->texture != -1) // glTexCoord2f(texturecoordinate[faces[i]->texcoord[1] - 1]->u, texturecoordinate[faces[i]->texcoord[1] - 1]->v);*/ //glVertex3f(vertex[faces[i]->faces[1] - 1]->x, vertex[faces[i]->faces[1] - 1]->y, vertex[faces[i]->faces[1] - 1]->z); ///*if (istexture && materials[faces[i]->mat]->texture != -1) // glTexCoord2f(texturecoordinate[faces[i]->texcoord[2] - 1]->u, texturecoordinate[faces[i]->texcoord[2] - 1]->v);*/ //glVertex3f(vertex[faces[i]->faces[2] - 1]->x, vertex[faces[i]->faces[2] - 1]->y, vertex[faces[i]->faces[2] - 1]->z); ///*if (istexture && materials[faces[i]->mat]->texture != -1) // glTexCoord2f(texturecoordinate[faces[i]->texcoord[3] - 1]->u, texturecoordinate[faces[i]->texcoord[3] - 1]->v);*/ //glVertex3f(vertex[faces[i]->faces[3] - 1]->x, vertex[faces[i]->faces[3] - 1]->y, vertex[faces[i]->faces[3] - 1]->z); //glEnd(); } else { glBegin(GL_TRIANGLES); //If there are normals if (isnormals) glNormal3f(normals[faces[i]->facenum - 1]->x, normals[faces[i]->facenum - 1]->y, normals[faces[i]->facenum - 1]->z); //if (istexture && materials[faces[i]->mat]->texture != -1) //glTexCoord2f(texturecoordinate[faces[i]->texcoord[0] - 1]->u, texturecoordinate[faces[i]->texcoord[0] - 1]->v); glVertex3f(vertex[faces[i]->faces[0] - 1]->x, vertex[faces[i]->faces[0] - 1]->y, vertex[faces[i]->faces[0] - 1]->z); //if (istexture && materials[faces[i]->mat]->texture != -1) //glTexCoord2f(texturecoordinate[faces[i]->texcoord[1] - 1]->u, texturecoordinate[faces[i]->texcoord[1] - 1]->v); glVertex3f(vertex[faces[i]->faces[1] - 1]->x, vertex[faces[i]->faces[1] - 1]->y, vertex[faces[i]->faces[1] - 1]->z); //if (istexture && materials[faces[i]->mat]->texture != -1) //glTexCoord2f(texturecoordinate[faces[i]->texcoord[2] - 1]->u, texturecoordinate[faces[i]->texcoord[2] - 1]->v); glVertex3f(vertex[faces[i]->faces[2] - 1]->x, vertex[faces[i]->faces[2] - 1]->y, vertex[faces[i]->faces[2] - 1]->z); glEnd(); } } glEndList(); clean(); lists.push_back(num); return num; }
ActorManager::~ActorManager() { clean(); }
void BonusManager::init() { clean(); instance = new BonusManager(); }
void vpKltOpencv::reset() { clean(); }
bool ActorManager::load(NuvieIO *objlist) { uint16 i; uint8 b1, b2, b3; int game_type; clean(); config->value("config/GameType",game_type); objlist->seek(0x100); // Start of Actor position info if(game_type == NUVIE_GAME_U6) temp_actor_offset = 203; else temp_actor_offset = 224; for(i=0; i < ACTORMANAGER_MAX_ACTORS; i++) { switch(game_type) { case NUVIE_GAME_U6 : actors[i] = new U6Actor(map,obj_manager,clock); break; case NUVIE_GAME_MD : actors[i] = new MDActor(map,obj_manager,clock); break; case NUVIE_GAME_SE : actors[i] = new SEActor(map,obj_manager,clock); break; } b1 = objlist->read1(); b2 = objlist->read1(); b3 = objlist->read1(); actors[i]->x = b1; actors[i]->x += (b2 & 0x3) << 8; actors[i]->y = (b2 & 0xfc) >> 2; actors[i]->y += (b3 & 0xf) << 6; actors[i]->z = (b3 & 0xf0) >> 4; actors[i]->id_n = (uint8)i; actors[i]->temp_actor = is_temp_actor(actors[i]->id_n); } // objlist.seek(0x15f1); for(i=0;i < ACTORMANAGER_MAX_ACTORS; i++) { b1 = objlist->read1(); b2 = objlist->read1(); actors[i]->obj_n = b1; actors[i]->obj_n += (b2 & 0x3) << 8; actors[i]->frame_n = (b2 & 0xfc) >> 2; actors[i]->direction = actors[i]->frame_n / 4; if(actors[i]->obj_n == 0) //Hack to get rid of Exodus. { actors[i]->x = 0; actors[i]->y = 0; actors[i]->z = 0; } } // Object flags. objlist->seek(0x000); for(i=0; i < ACTORMANAGER_MAX_ACTORS; i++) { actors[i]->obj_flags = objlist->read1(); } // Actor status flags. objlist->seek(0x800); for(i=0;i < ACTORMANAGER_MAX_ACTORS; i++) { actors[i]->status_flags = objlist->read1(); actors[i]->alignment = ((actors[i]->status_flags & ACTOR_STATUS_ALIGNMENT_MASK) >> 5) + 1; } //old obj_n & frame_n values objlist->seek(game_type == NUVIE_GAME_U6 ? 0x15f1 : 0x16f1); for(i=0;i < ACTORMANAGER_MAX_ACTORS; i++) { b1 = objlist->read1(); b2 = objlist->read1(); actors[i]->base_obj_n = b1; actors[i]->base_obj_n += (b2 & 0x3) << 8; actors[i]->old_frame_n = (b2 & 0xfc) >> 2; if(actors[i]->obj_n == 0) { //actors[i]->obj_n = actors[i]->base_obj_n; //actors[i]->frame_n = actors[i]->old_frame_n; actors[i]->hide(); } if(actors[i]->base_obj_n == 0) { actors[i]->base_obj_n = actors[i]->obj_n; actors[i]->old_frame_n = actors[i]->frame_n; } } // Strength objlist->seek(0x900); for(i=0;i < ACTORMANAGER_MAX_ACTORS; i++) { actors[i]->strength = objlist->read1(); } // Dexterity objlist->seek(0xa00); for(i=0;i < ACTORMANAGER_MAX_ACTORS; i++) { actors[i]->dex = objlist->read1(); } // Intelligence objlist->seek(0xb00); for(i=0;i < ACTORMANAGER_MAX_ACTORS; i++) { actors[i]->intelligence = objlist->read1(); } // Experience objlist->seek(0xc00); for(i=0;i < ACTORMANAGER_MAX_ACTORS; i++) { actors[i]->exp = objlist->read2(); } // Health objlist->seek(0xe00); for(i=0;i < ACTORMANAGER_MAX_ACTORS; i++) { actors[i]->hp = objlist->read1(); } // Experience Level objlist->seek(0xff1); for(i=0;i < ACTORMANAGER_MAX_ACTORS; i++) { actors[i]->level = objlist->read1(); } // Combat mode objlist->seek(0x12f1); for(i=0;i < ACTORMANAGER_MAX_ACTORS; i++) { switch(game_type) { case NUVIE_GAME_U6 : actors[i]->combat_mode = objlist->read1(); break; case NUVIE_GAME_MD : // FIXME not sure what this is supposed to be case NUVIE_GAME_SE : actors[i]->magic = objlist->read1(); break; } } // Magic Points objlist->seek(0x13f1); for(i=0;i < ACTORMANAGER_MAX_ACTORS; i++) { switch(game_type) { case NUVIE_GAME_U6 : actors[i]->magic = objlist->read1(); break; case NUVIE_GAME_MD : case NUVIE_GAME_SE : actors[i]->combat_mode = objlist->read1(); break; } } if(game_type == NUVIE_GAME_U6) { objlist->seek(OBJLIST_OFFSET_U6_TALK_FLAGS); // Start of Talk flags } else { objlist->seek(OBJLIST_OFFSET_MD_TALK_FLAGS); //MD talk flags location. FIXME: check SE } for(i=0;i < ACTORMANAGER_MAX_ACTORS; i++) { actors[i]->talk_flags = objlist->read1(); } objlist->seek(0x19f1); for(i=0;i < ACTORMANAGER_MAX_ACTORS; i++) //movement flags. { actors[i]->movement_flags = objlist->read1(); } loadActorSchedules(); for(i=0;i < ACTORMANAGER_MAX_ACTORS; i++) { actors[i]->inventory_parse_readied_objects(); actors[i]->init(); //let the actor object do some init } // Moves objlist->seek(game_type == NUVIE_GAME_MD ? OBJLIST_OFFSET_MD_MOVEMENT_POINTS : OBJLIST_OFFSET_U6_MOVEMENT_POINTS); for(i=0;i < ACTORMANAGER_MAX_ACTORS; i++) { actors[i]->moves = objlist->read1(); } // Current Worktype objlist->seek(0x11f1); for(i=0;i < ACTORMANAGER_MAX_ACTORS; i++) { actors[i]->set_worktype(objlist->read1(), true); } //cleanup party actor if not currently set as the player. if(actors[ACTOR_VEHICLE_ID_N]->get_worktype() != ACTOR_WT_PLAYER) { Actor *a = actors[ACTOR_VEHICLE_ID_N]; a->set_obj_n(0); a->x=0; a->y=0; a->z=0; //a->status_flags = ACTOR_STATUS_DEAD; //a->hide(); } updateSchedules(); loadCustomTiles(game_type); return true; }
/** modify **/ bool Url::parse(String* url){ // clean clean(); // check if(!url){ return false; } // prepare sz const char* sz =url->c_str(); // puts(sz); // protocol const char* cursor =strstr(sz, "://"); int64_t pos =(cursor ? (cursor-sz) : -1); if(pos == 0){ ERROR("fail to call %s, len(protocol) can't be 0"); return false; } else if(pos > 0){ ASSIGN_POINTER(m_protocol, String::New(sz, pos)); sz =cursor + 3; } // auth cursor =strchr(sz, '@'); pos =(cursor ? (cursor-sz) : -1); if(pos == 0){ CLEAN_POINTER(m_protocol); ERROR("fail to call %s, len(auth) can't be 0"); return false; } else if(pos > 0){ ASSIGN_POINTER(m_auth, String::New(sz, pos)); sz =cursor + 1; } // host const char* szbeg =sz; while(const char ch =*sz){ if(ch=='/' || ch=='?' || ch=='#'){ break; } ++sz; } if(sz > szbeg){ ASSIGN_POINTER(m_host, String::New(szbeg, sz-szbeg)); } // path if(*sz == '/'){ const char* szbeg =sz++; while(const char ch =*sz){ if(ch=='?' || ch=='#'){ break; } ++sz; } ASSIGN_POINTER(m_path, String::New(szbeg, sz-szbeg)); } // query if(*sz == '?'){ const char* szbeg =++sz; while(const char ch =*sz){ if(ch == '#'){ break; } ++sz; } if(sz > szbeg){ ASSIGN_POINTER(m_query_string, String::New(szbeg, sz-szbeg)); ASSIGN_POINTER(m_query, SafeNew<Hash>()); if(!ParseQuery(m_query_string, m_query)){ clean(); return false; } } else{ ASSIGN_POINTER(m_query_string, String::New(szbeg, sz-szbeg)); } } // fragment if(*sz == '#'){ ASSIGN_POINTER(m_fragment, String::New(sz+1)); } // url ASSIGN_POINTER(m_url, url); return true; }
void Url::finalize(){ clean(); Super::finalize(); }
bool Url::_build(String* protocol, String* auth, String* host, String* path, String* query_string, Hash* query, String* fragment){ // clean clean(); // check if(path && path->size() && !path->hasPrefix("/")){ return false; } // make url BinaryCoder<1024> coder; if(protocol && protocol->size()){ ASSIGN_POINTER(m_protocol, protocol); coder.append(protocol); coder.append("://", 3); } if(auth && auth->size()){ ASSIGN_POINTER(m_auth, auth); coder.append(auth); coder.append("@", 1); } if(host && host->size()){ ASSIGN_POINTER(m_host, host); coder.append(host); } if(path && path->size()){ ASSIGN_POINTER(m_path, path); coder.append(path); } if(query_string && query_string->size()){ ASSIGN_POINTER(m_query_string, query_string); ASSIGN_POINTER(m_query, SafeNew<Hash>()); if(!ParseQuery(m_query_string, m_query)){ clean(); return false; } coder.append("?", 1); coder.append(m_query_string); } else if(query && query->size()){ ASSIGN_POINTER(m_query, query); // make query string BinaryCoder<1024> sub_coder; HashIterator* it =static_cast< HashIterator* >(query->iterator()); while(it->next()){ String* key =static_cast< String* >(it->getKey()); String* val =static_cast< String* >(it->getValue()); if(sub_coder.size() > 0){ sub_coder.append("&", 1); } sub_coder.append(UrlEncode::Encode(key)); sub_coder.append("=", 1); sub_coder.append(UrlEncode::Encode(val)); } // set ASSERT(sub_coder.size()); ASSIGN_POINTER(m_query_string, String::New(sub_coder.c_str(), sub_coder.size())); coder.append("?", 1); coder.append(m_query_string); } if(fragment && fragment->size()){ ASSIGN_POINTER(m_fragment, fragment); coder.append("#", 1); coder.append(fragment); } ASSIGN_POINTER(m_url, String::New(coder.c_str(), coder.size())); return true; }
//this method runs the DV algorithm //--------------------------------------------------------------------------------------------// void Bellman_Ford(){ initialize(); int i,j,rc; int myIndex; i=0; j=0; // printTable(); // printf("num of neig%d\n",routing_table->directNeighbors); threads=malloc(sizeof(pthread_t)*routing_table->directNeighbors*2); myIndex=getNodeIndex(routing_table->table_node->name); //creating thread for calculation //^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ // pthread_t recompute; rc=pthread_create(&recompute,NULL,(void*)recomputeDV,NULL); if(rc){ printf("%s\n", strerror(errno)); exit(0); } //^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ // //creating threads for sending //^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ // while(i<routing_table->directNeighbors){ rc=pthread_create(&threads[j],NULL,(void*)rcvDV,routing_table->nodes[routing_table->directNeig[i]].name); if(rc){ printf("%s\n", strerror(errno)); exit(0); } j++; i++; } //^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ // //creating threads for receiving //^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ // i=0; while(i<routing_table->directNeighbors){ // if(routing_table->r_table[myIndex][i]!=999 &&i!=myIndex){ //sending rc=pthread_create(&threads[j],NULL,(void*)sendDV,&routing_table->nodes[routing_table->directNeig[i]]); if(rc){ printf("%s\n", strerror(errno)); exit(0); } j++; i++; } //^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ // //Synchronizing the sending's ,receving's and recomputing's mutex and conditional variables //^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ // int sentOnce=0; //waiting for all the threads to be exist and go into wait mode while(numOfSentThreadExists<routing_table->directNeighbors||numOfReceivedThreadExists<routing_table->directNeighbors||isRecomputeExists==0); while(1){ pthread_mutex_lock(&mutex); //waking all the sending threads. //^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ // if(sent==0 &&sentOnce==0 ){ // printf("Bellman_Ford():signal sent to convar1\n"); sentOnce=1; for(i=0;i<routing_table->directNeighbors;i++){ pthread_cond_signal(&convar1); pthread_mutex_unlock(&mutex); } pthread_mutex_lock(&mutex); } //^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ // //waking all the sending threads. //^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ // // if(sent==routing_table->directNeighbors){ // //// printf("Bellman_Ford():signal sent to convar2\n"); // // sent=-1; //// for(i=0;i<routing_table->directNeighbors;i++){ //// pthread_cond_signal(&convar2); //// } //// pthread_mutex_unlock(&mutex); //// pthread_mutex_lock(&mutex); // } //^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ // //^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ // //in the case which all of the other nodes sent 0 then finishing the algorithm if(zeroReceived>=routing_table->directNeighbors){ received=-1; sent=-1; // printf("Bellman_Ford():signal sent to convar1+2+3\n"); for(i=0;i<routing_table->directNeighbors;i++){ pthread_cond_signal(&convar1); } // for(i=0;i<routing_table->directNeighbors;i++){ // pthread_cond_signal(&convar2); // } pthread_cond_signal(&convar3); pthread_mutex_unlock(&mutex); pthread_mutex_lock(&mutex); // printf("Bellman_Ford():done=1\n"); break; } //^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ // //^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ // //in the case which all neighbors's DV received ,waking the recomputing thread. if(received>=routing_table->directNeighbors&& sent>=routing_table->directNeighbors){ // printf("Bellman_Ford():signal sent to convar3\n"); received=-1; sent=-1; pthread_cond_signal(&convar3); pthread_mutex_unlock(&mutex); pthread_mutex_lock(&mutex); } //^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ // //^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ ^_^ // //reset all the global variables if(doneComputing==1){ received=0; sent=0; sentOnce=0; doneComputing=0; } pthread_mutex_unlock(&mutex); } // printf("Bellman_Ford():outside main loop\n"); pthread_mutex_unlock(&mutex); //joining all the threads-this means the main thread will wait until all of the threads will exist. pthread_join(recompute, NULL); for (i=0; i<routing_table->directNeighbors*2; i++) { pthread_join(threads[i], NULL); } // printTable(); // printf("printing via\n\n\n"); // for(i=0;i<routing_table->numOfNodes;i++) // printf("%d\t",routing_table->via[i]); // printf("\n\n\n"); printFinalResualt();//printing resualt // printf("\n\n\n"); clean();//cleaning all the dynamically allocated memory, exit(0); }
CubitStatus RefEntityName::add_refentity_name(RefEntity *entity, DLIList<CubitString> &names, bool update_attribs, bool check_name_validity) { names.reset(); //int num_new_names = names.size(); DLIList<CubitString> new_names; for (int i=0; i<names.size(); i++) { CubitString name = names[i]; CubitString in_name = name; CubitBoolean warn_name_change = CUBIT_FALSE; // first, clean the name if (check_name_validity) { if (clean(name)) { // assign original name anyway, then // continue on and assign modified name. add_refentity_name(entity, in_name, false, false); warn_name_change = CUBIT_TRUE; } } // now, check for valid name CubitBoolean name_valid = CUBIT_FALSE; if (name == "") { // blank name entered - do nothing } else if (nameEntityList.move_to(name) && nameEntityList.get()->value() == entity) { // Tried to assign same name to entity if ( DEBUG_FLAG(92) ) { // check to see if it's the same as this entity's default name, // if so, it probably came in on an attribute, and we don't need // to hear about it; otherwise, write the warning CubitString def_name; entity->generate_default_name(def_name); if (name != def_name) PRINT_INFO("Entity name '%s' already assigned to %s %d\n", name.c_str(), entity->class_name(), entity->id()); } } else if (nameEntityList.move_to(name) && nameEntityList.get()->value() != entity) { // Tried to assign existing name to another entity PRINT_DEBUG_92( "Entity name '%s' for %s %d is already used by %s %d\n", name.c_str(), entity->class_name(), entity->id(), nameEntityList.get()->value()->class_name(), nameEntityList.get()->value()->id()); // either we fix it and keep it, or we don't and get rid of it name_valid = CUBIT_FALSE; if (get_fix_duplicate_names()) { if (generate_unique_name(name)) { PRINT_DEBUG_92( "\t%s %d name changed to '%s'\n", entity->class_name(), entity->id(), name.c_str()); if(warn_name_change) { PRINT_WARNING("Entity name '%s' can't be used in commands.\n" " Additional name '%s' assigned.\n", in_name.c_str(), name.c_str()); } name_valid = CUBIT_TRUE; } } } else { if(warn_name_change) { PRINT_WARNING("Entity name '%s' can't be used in commands.\n" " Additional name '%s' assigned.\n", in_name.c_str(), name.c_str()); } // else the name must be valid name_valid = CUBIT_TRUE; } if (name_valid == CUBIT_TRUE) { // name is valid if (name != in_name) // name was changed; change in name list too names[i] = name; // save this name to later new_names.append(names[i]); } } if (new_names.size() > 0) { // there are some valid, new names; add them, then update attribute new_names.reset(); CubitString name; for (int i = new_names.size(); i > 0; i--) { name = new_names.get_and_step(); if (nameEntityList.move_to(name) && nameEntityList.get()->value() == entity) { PRINT_DEBUG_92("Already have name %s for %s %d.\n", name.c_str(), entity->class_name(), entity->id()); } else { nameEntityList.insert(new RefEntityNameMap(name, entity)); } } if (update_attribs == CUBIT_TRUE) { // now tell the entity to update its name attribute CubitAttrib *attrib = entity->get_cubit_attrib(CA_ENTITY_NAME); // force update by resetting update flag attrib->has_updated(CUBIT_FALSE); attrib->update(); } } return CUBIT_SUCCESS; }
void init() { m_exportFile = "exportfile"; m_manager = new QLandmarkManager; m_handler = new QLandmarkFileHandlerLmx; clean(); }
CubitStatus RefEntityName::add_refentity_name(RefEntity *entity, CubitString &name, bool update_attribs, bool check_name_validity) { if (name == "") return CUBIT_FAILURE; CubitString in_name = name; bool warn_name_change = false; if (check_name_validity) { if (clean(name)) { // Assign the invalid name anyway, then continue on and // assign the modified name. add_refentity_name(entity, in_name, false, false); warn_name_change = true; } } if (nameEntityList.move_to(name)) { RefEntity *old_entity = nameEntityList.get()->value(); if (old_entity == entity) { // Tried to assign same name to entity if ( DEBUG_FLAG(92) ) { PRINT_INFO("Entity name '%s' already assigned to %s %d\n", name.c_str(), entity->class_name(), entity->id()); return CUBIT_FAILURE; } return CUBIT_SUCCESS; } else { // Tried to assign existing name to another entity if ( DEBUG_FLAG(92) ) PRINT_WARNING("Entity name '%s' for %s %d is already used by %s %d\n", name.c_str(), entity->class_name(), entity->id(), old_entity->class_name(), old_entity->id()); if (get_fix_duplicate_names()) { if (generate_unique_name(name)) { if (warn_name_change) { PRINT_WARNING("Entity name '%s' can't be used in commands.\n" " Additional name '%s' assigned.\n", in_name.c_str(), name.c_str()); } if ( DEBUG_FLAG(92) ) PRINT_WARNING("\t%s %d name changed to '%s'\n", entity->class_name(), entity->id(), name.c_str()); return add_refentity_name(entity, name, update_attribs, false); } } return CUBIT_FAILURE; } } if (warn_name_change) { PRINT_WARNING("Entity name '%s' can't be used in commands.\n" " Additional name '%s' assigned.\n", in_name.c_str(), name.c_str()); } RefEntityNameMap *entity_name = new RefEntityNameMap(name, entity); nameEntityList.insert(entity_name); if (update_attribs == CUBIT_TRUE) { // now tell the entity to update its name attribute CubitAttrib *attrib = entity->get_cubit_attrib(CA_ENTITY_NAME); // force update by resetting update flag attrib->has_updated(CUBIT_FALSE); attrib->update(); } return CUBIT_SUCCESS; }
void Map::terminate() { clean(); }
ScoreManager::~ScoreManager() { clean(); }
int KrigingMean::execute( GsTL_project* ) { // those flags will be used to signal if some of the nodes could not be // informed bool issue_singular_system_warning = false; bool issue_no_conditioning_data_warning = false; // Set up a progress notifier int total_steps = simul_grid_->size(); int frequency = std::max( total_steps / 20, 1 ); SmartPtr<Progress_notifier> progress_notifier = utils::create_notifier( "Running Kriging", total_steps, frequency ); // create the property appli_message("creating new property: " << property_name_ << "..." ); GsTLGridProperty* prop = geostat_utils::add_property_to_grid( simul_grid_, property_name_ ); simul_grid_->select_property( prop->name() ); typedef Geostat_grid::iterator iterator; iterator begin = simul_grid_->begin(); iterator end = simul_grid_->end(); for( ; begin != end; ++begin ) { if( !progress_notifier->notify() ) { clean( property_name_ ); return 1; } if( begin->is_informed() ) continue; neighborhood_->find_neighbors( *begin ); if( neighborhood_->size() < min_neigh_ ) continue; if(!neighborhood_->is_valid()) continue; double variance; int status; status = kriging_weights_2( kriging_weights_, variance, begin->location(), *(neighborhood_.raw_ptr()), covar_,*rhs_covar_, *Kconstraints_ ); if(status == 0) { // the kriging system could be solved double estimate = (*combiner_)( kriging_weights_.begin(), kriging_weights_.end(), *(neighborhood_.raw_ptr()) ); begin->set_property_value( estimate ); } else { // the kriging system could not be solved, issue a warning and skip the // node issue_singular_system_warning = true; } } /* This pop-up windows breaks script if( issue_singular_system_warning ) GsTLcerr << "Kriging could not be performed at some locations because\n" << "the kriging system was singular\n" << gstlIO::end; if( issue_no_conditioning_data_warning ) GsTLcerr << "Kriging could not be performed at some locations because\n" << "the neighborhood of those locations was empty.\n" << "Try increasing the size of the search ellipsoid.\n" << gstlIO::end; */ return 0; }
MemPager::~MemPager() { clean(); }
int objloader::load(const char* filename) { std::ifstream in(filename); if(!in.is_open()) { std::cout << "Nor oepened" << std::endl; return -1; } char buf[256]; int curmat=0; while(!in.eof()) { in.getline(buf,256); coord.push_back(new std::string(buf)); } for(int i=0;i<coord.size();i++) { if((*coord[i])[0]=='#') continue; else if((*coord[i])[0]=='v' && (*coord[i])[1]==' ') { float tmpx,tmpy,tmpz; sscanf(coord[i]->c_str(),"v %f %f %f",&tmpx,&tmpy,&tmpz); vertex.push_back(new coordinate(tmpx,tmpy,tmpz)); }else if((*coord[i])[0]=='v' && (*coord[i])[1]=='n') { float tmpx,tmpy,tmpz; sscanf(coord[i]->c_str(),"vn %f %f %f",&tmpx,&tmpy,&tmpz); normals.push_back(new coordinate(tmpx,tmpy,tmpz)); }else if((*coord[i])[0]=='f') { int a,b,c,d,e; if(count(coord[i]->begin(),coord[i]->end(),' ')==4) { if(coord[i]->find("//")!=std::string::npos) { sscanf(coord[i]->c_str(),"f %d//%d %d//%d %d//%d %d//%d",&a,&b,&c,&b,&d,&b,&e,&b); faces.push_back(new face(b,a,c,d,e,0,0,0,0,curmat)); }else if(coord[i]->find("/")!=std::string::npos) { int t[4]; sscanf(coord[i]->c_str(),"f %d/%d/%d %d/%d/%d %d/%d/%d %d/%d/%d",&a,&t[0],&b,&c,&t[1],&b,&d,&t[2],&b,&e,&t[3],&b); faces.push_back(new face(b,a,c,d,e,t[0],t[1],t[2],t[3],curmat)); }else{ sscanf(coord[i]->c_str(),"f %d %d %d %d",&a,&b,&c,&d); faces.push_back(new face(-1,a,b,c,d,0,0,0,0,curmat)); } }else{ if(coord[i]->find("//")!=std::string::npos) { sscanf(coord[i]->c_str(),"f %d//%d %d//%d %d//%d",&a,&b,&c,&b,&d,&b); faces.push_back(new face(b,a,c,d,0,0,0,curmat)); }else if(coord[i]->find("/")!=std::string::npos) { int t[3]; sscanf(coord[i]->c_str(),"f %d/%d/%d %d/%d/%d %d/%d/%d",&a,&t[0],&b,&c,&t[1],&b,&d,&t[2],&b); faces.push_back(new face(b,a,c,d,t[0],t[1],t[2],curmat)); }else{ sscanf(coord[i]->c_str(),"f %d %d %d",&a,&b,&c); faces.push_back(new face(-1,a,b,c,0,0,0,curmat)); } } }else if((*coord[i])[0]=='u' && (*coord[i])[1]=='s' && (*coord[i])[2]=='e') { char tmp[200]; sscanf(coord[i]->c_str(),"usemtl %s",tmp); for(int i=0;i<materials.size();i++) { if(strcmp(materials[i]->name.c_str(),tmp)==0) { curmat=i; break; } } }else if((*coord[i])[0]=='m' && (*coord[i])[1]=='t' && (*coord[i])[2]=='l' && (*coord[i])[3]=='l') { char filen[200]; sscanf(coord[i]->c_str(),"mtllib %s",filen); std::ifstream mtlin(filen); if(!mtlin.is_open()) { std::cout << "connot open the material file" << std::endl; clean(); return -1; } ismaterial=true; std::vector<std::string> tmp; char c[200]; while(!mtlin.eof()) { mtlin.getline(c,200); tmp.push_back(c); } char name[200]; char filename[200]; float amb[3],dif[3],spec[3],alpha,ns,ni; int illum; unsigned int texture; bool ismat=false; strcpy(filename,"\0"); std::cout << tmp.size() << std::endl; for(int i=0;i<tmp.size();i++) { if(tmp[i][0]=='#') continue; if(tmp[i][0]=='n' && tmp[i][1]=='e' && tmp[i][2]=='w') { if(ismat) { if(strcmp(filename,"\0")!=0) { materials.push_back(new material(name,alpha,ns,ni,dif,amb,spec,illum,texture)); strcpy(filename,"\0"); }else{ materials.push_back(new material(name,alpha,ns,ni,dif,amb,spec,illum,-1)); } } ismat=false; sscanf(tmp[i].c_str(),"newmtl %s",name); }else if(tmp[i][0]=='N' && tmp[i][1]=='s') { sscanf(tmp[i].c_str(),"Ns %f",&ns); ismat=true; }else if(tmp[i][0]=='K' && tmp[i][1]=='a') { sscanf(tmp[i].c_str(),"Ka %f %f %f",&amb[0],&amb[1],&amb[2]); ismat=true; }else if(tmp[i][0]=='K' && tmp[i][1]=='d') { sscanf(tmp[i].c_str(),"Kd %f %f %f",&dif[0],&dif[1],&dif[2]); ismat=true; }else if(tmp[i][0]=='K' && tmp[i][1]=='s') { sscanf(tmp[i].c_str(),"Ks %f %f %f",&spec[0],&spec[1],&spec[2]); ismat=true; }else if(tmp[i][0]=='N' && tmp[i][1]=='i') { sscanf(tmp[i].c_str(),"Ni %f",&ni); ismat=true; }else if(tmp[i][0]=='d' && tmp[i][1]==' ') { sscanf(tmp[i].c_str(),"d %f",&alpha); ismat=true; }else if(tmp[i][0]=='i' && tmp[i][1]=='l') { sscanf(tmp[i].c_str(),"illum %d",&illum); ismat=true; }else if(tmp[i][0]=='m' && tmp[i][1]=='a') { sscanf(tmp[i].c_str(),"map_Kd %s",filename); texture=loadTexture(filename); ismat=true; } } if(ismat) { if(strcmp(filename,"\0")!=0) { materials.push_back(new material(name,alpha,ns,ni,dif,amb,spec,illum,texture)); }else{ materials.push_back(new material(name,alpha,ns,ni,dif,amb,spec,illum,-1)); } } }else if((*coord[i])[0]=='v' && (*coord[i])[1]=='t') { float u,v; sscanf(coord[i]->c_str(),"vt %f %f",&u,&v); texturecoordinate.push_back(new texcoord(u,1-v)); istexture=true; } } if(materials.size()==0) ismaterial=false; else ismaterial=true; std::cout << vertex.size() << " " << normals.size() << " " << faces.size() << " " << materials.size() << std::endl; //draw if(isvertexnormal) smoothnormals(); int num; num=glGenLists(1); glNewList(num,GL_COMPILE); int last=-1; for(int i=0;i<faces.size();i++) { if(last!=faces[i]->mat && ismaterial) { float diffuse[]={materials[faces[i]->mat]->dif[0],materials[faces[i]->mat]->dif[1],materials[faces[i]->mat]->dif[2],1.0}; float ambient[]={materials[faces[i]->mat]->amb[0],materials[faces[i]->mat]->amb[1],materials[faces[i]->mat]->amb[2],1.0}; float specular[]={materials[faces[i]->mat]->spec[0],materials[faces[i]->mat]->spec[1],materials[faces[i]->mat]->spec[2],1.0}; glMaterialfv(GL_FRONT,GL_DIFFUSE,diffuse); glMaterialfv(GL_FRONT,GL_AMBIENT,ambient); glMaterialfv(GL_FRONT,GL_SPECULAR,specular); glMaterialf(GL_FRONT,GL_SHININESS,materials[faces[i]->mat]->ns); last=faces[i]->mat; if(materials[faces[i]->mat]->texture==-1) glDisable(GL_TEXTURE_2D); else{ glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,materials[faces[i]->mat]->texture); } } if(faces[i]->four) { glBegin(GL_QUADS); glNormal3f(normals[faces[i]->facenum-1]->x,normals[faces[i]->facenum-1]->y,normals[faces[i]->facenum-1]->z); if(istexture && materials[faces[i]->mat]->texture!=-1) glTexCoord2f(texturecoordinate[faces[i]->texcoord[0]-1]->u,texturecoordinate[faces[i]->texcoord[0]-1]->v); if(isvertexnormal) glNormal3f(vertexnormals[faces[i]->faces[0]-1]->x,vertexnormals[faces[i]->faces[0]-1]->y,vertexnormals[faces[i]->faces[0]-1]->z); glVertex3f(vertex[faces[i]->faces[0]-1]->x,vertex[faces[i]->faces[0]-1]->y,vertex[faces[i]->faces[0]-1]->z); if(istexture && materials[faces[i]->mat]->texture!=-1) glTexCoord2f(texturecoordinate[faces[i]->texcoord[1]-1]->u,texturecoordinate[faces[i]->texcoord[1]-1]->v); if(isvertexnormal) glNormal3f(vertexnormals[faces[i]->faces[1]-1]->x,vertexnormals[faces[i]->faces[1]-1]->y,vertexnormals[faces[i]->faces[1]-1]->z); glVertex3f(vertex[faces[i]->faces[1]-1]->x,vertex[faces[i]->faces[1]-1]->y,vertex[faces[i]->faces[1]-1]->z); if(istexture && materials[faces[i]->mat]->texture!=-1) glTexCoord2f(texturecoordinate[faces[i]->texcoord[2]-1]->u,texturecoordinate[faces[i]->texcoord[2]-1]->v); if(isvertexnormal) glNormal3f(vertexnormals[faces[i]->faces[2]-1]->x,vertexnormals[faces[i]->faces[2]-1]->y,vertexnormals[faces[i]->faces[2]-1]->z); glVertex3f(vertex[faces[i]->faces[2]-1]->x,vertex[faces[i]->faces[2]-1]->y,vertex[faces[i]->faces[2]-1]->z); if(istexture && materials[faces[i]->mat]->texture!=-1) glTexCoord2f(texturecoordinate[faces[i]->texcoord[3]-1]->u,texturecoordinate[faces[i]->texcoord[3]-1]->v); if(isvertexnormal) glNormal3f(vertexnormals[faces[i]->faces[3]-1]->x,vertexnormals[faces[i]->faces[3]-1]->y,vertexnormals[faces[i]->faces[3]-1]->z); glVertex3f(vertex[faces[i]->faces[3]-1]->x,vertex[faces[i]->faces[3]-1]->y,vertex[faces[i]->faces[3]-1]->z); glEnd(); }else{ glBegin(GL_TRIANGLES); glNormal3f(normals[faces[i]->facenum-1]->x,normals[faces[i]->facenum-1]->y,normals[faces[i]->facenum-1]->z); if(istexture && materials[faces[i]->mat]->texture!=-1) glTexCoord2f(texturecoordinate[faces[i]->texcoord[0]-1]->u,texturecoordinate[faces[i]->texcoord[0]-1]->v); if(isvertexnormal) glNormal3f(vertexnormals[faces[i]->faces[0]-1]->x,vertexnormals[faces[i]->faces[0]-1]->y,vertexnormals[faces[i]->faces[0]-1]->z); glVertex3f(vertex[faces[i]->faces[0]-1]->x,vertex[faces[i]->faces[0]-1]->y,vertex[faces[i]->faces[0]-1]->z); if(istexture && materials[faces[i]->mat]->texture!=-1) glTexCoord2f(texturecoordinate[faces[i]->texcoord[1]-1]->u,texturecoordinate[faces[i]->texcoord[1]-1]->v); if(isvertexnormal) glNormal3f(vertexnormals[faces[i]->faces[1]-1]->x,vertexnormals[faces[i]->faces[1]-1]->y,vertexnormals[faces[i]->faces[1]-1]->z); glVertex3f(vertex[faces[i]->faces[1]-1]->x,vertex[faces[i]->faces[1]-1]->y,vertex[faces[i]->faces[1]-1]->z); if(istexture && materials[faces[i]->mat]->texture!=-1) glTexCoord2f(texturecoordinate[faces[i]->texcoord[2]-1]->u,texturecoordinate[faces[i]->texcoord[2]-1]->v); if(isvertexnormal) glNormal3f(vertexnormals[faces[i]->faces[2]-1]->x,vertexnormals[faces[i]->faces[2]-1]->y,vertexnormals[faces[i]->faces[2]-1]->z); glVertex3f(vertex[faces[i]->faces[2]-1]->x,vertex[faces[i]->faces[2]-1]->y,vertex[faces[i]->faces[2]-1]->z); glEnd(); } } glEndList(); clean(); lists.push_back(num); return num; }
Xfile * xfile(int fid, int flag) { Xfile **hp, *f, *pf; int k; k = ((uint32_t)fid) % FIDMOD; hp = &xfiles[k]; mlock(&xlocks[k]); pf = nil; for(f=*hp; f; f=f->next){ if(f->fid == fid) break; pf = f; } if(f && pf){ pf->next = f->next; f->next = *hp; *hp = f; } switch(flag){ default: panic("xfile"); case Asis: unmlock(&xlocks[k]); return (f && f->xf && f->xf->dev < 0) ? nil : f; case Clean: break; case Clunk: if(f){ *hp = f->next; unmlock(&xlocks[k]); clean(f); mlock(&freelock); f->next = freelist; freelist = f; unmlock(&freelock); } else unmlock(&xlocks[k]); return nil; } unmlock(&xlocks[k]); if(f) return clean(f); mlock(&freelock); if(f = freelist){ /* assign = */ freelist = f->next; unmlock(&freelock); } else { unmlock(&freelock); f = malloc(sizeof(Xfile)); if(f == nil){ errno = Enomem; return nil; } } mlock(&xlocks[k]); f->next = *hp; *hp = f; unmlock(&xlocks[k]); f->fid = fid; f->flags = 0; f->qid = (Qid){0,0,0}; f->xf = nil; f->ptr = nil; return f; }
Histogram::Histogram() { clean(); }
YARP3DHistogram::YARP3DHistogram() { clean(); }
int main() { INIT_SOCKETS_FOR_WINDOWS; if ( mongo_client( conn, TEST_SERVER, 27017 ) != MONGO_OK ) { printf( "failed to connect\n" ); exit( 1 ); } clean(); printf( "-----\n" ); TIME( serialize_small_test, 0 ); TIME( serialize_medium_test, 0 ); TIME( serialize_large_test, 0 ); printf( "-----\n" ); TIME( single_insert_small_test, 1 ); TIME( single_insert_medium_test, 1 ); TIME( single_insert_large_test, 1 ); printf( "-----\n" ); TIME( index_insert_small_test, 1 ); TIME( index_insert_medium_test, 1 ); TIME( index_insert_large_test, 1 ); printf( "-----\n" ); TIME( batch_insert_small_test, 1 ); TIME( batch_insert_medium_test, 1 ); TIME( batch_insert_large_test, 1 ); #if DO_SLOW_TESTS printf( "-----\n" ); TIME( find_one_noindex_small_test, 0 ); TIME( find_one_noindex_medium_test, 0 ); TIME( find_one_noindex_large_test, 0 ); #endif printf( "-----\n" ); TIME( find_one_index_small_test, 0 ); TIME( find_one_index_medium_test, 0 ); TIME( find_one_index_large_test, 0 ); #if DO_SLOW_TESTS printf( "-----\n" ); TIME( find_noindex_small_test, 0 ); TIME( find_noindex_medium_test, 0 ); TIME( find_noindex_large_test, 0 ); #endif printf( "-----\n" ); TIME( find_index_small_test, 0 ); TIME( find_index_medium_test, 0 ); TIME( find_index_large_test, 0 ); printf( "-----\n" ); TIME( find_range_small_test, 0 ); TIME( find_range_medium_test, 0 ); TIME( find_range_large_test, 0 ); mongo_destroy( conn ); return 0; }
YARP3DHistogram::YARP3DHistogram(unsigned char max, unsigned char min, unsigned char n) { clean(); Resize(max, min, n); }
virtual ~Base() { clean(); }
QgsProviderRegistry::~QgsProviderRegistry() { clean(); }