Bitmap *CreateBitmapStruct(void) { #if defined(TARGET_SDL) return checked_calloc(sizeof(struct SDLSurfaceInfo)); #else return checked_calloc(sizeof(struct X11DrawableInfo)); #endif }
bdd_mgr_t * bdd_mgr_create_with_hint (unsigned num_vars, unsigned capacity_hint) { bdd_mgr_t *mgr = (bdd_mgr_t *) checked_malloc (sizeof(bdd_mgr_t)); /* fprintf (stderr, "!!! creating a manager at %p with %u vars and %u capacity hint\n", (void *) mgr, num_vars, capacity_hint); */ assert (num_vars > 0); assert (num_vars <= _BDD_MAX_NUM_VARS); mgr->num_vars = num_vars; mgr->capacity = size_hint_to_size (capacity_hint); mgr->num_nodes = 0; mgr->nodes = (node_t *) checked_malloc (mgr->capacity * sizeof(node_t)); _initialize_nodes (mgr->nodes, 0, mgr->capacity); create_nodes_hash_table (mgr); create_lvl_var_mapping (mgr); mgr->lvl_chain_roots = (unsigned *) checked_calloc (num_vars, sizeof(unsigned)); mgr->nodes_at_level = (unsigned *) checked_calloc (num_vars, sizeof(unsigned)); /* FIXME: use a more reasonable cache size */ bdd_ite_cache_create_with_hint (&mgr->ite_cache, 1024 * 32); mgr->ite_cache_stats = make_cache_stats (); mgr->last_used_alloc_idx = 0; add_terminal_node (mgr, 0, num_vars, 1, 0); /* false terminal */ add_terminal_node (mgr, 1, num_vars, 0, 1); /* true terminal */ _bdd_mgr_check_invariants (mgr); return mgr; }
static struct MouseCursorInfo *get_cursor_from_image(const char **image) { struct MouseCursorInfo *cursor; boolean bit_order_msb = (cursor_bit_order == BIT_ORDER_MSB); int header_lines = 4; int x, y, i; cursor = checked_calloc(sizeof(struct MouseCursorInfo)); sscanf(image[0], " %d %d ", &cursor->width, &cursor->height); i = -1; for (y = 0; y < cursor->width; y++) { for (x = 0; x < cursor->height; x++) { int bit_nr = x % 8; int bit_mask = 0x01 << (bit_order_msb ? 7 - bit_nr : bit_nr ); if (bit_nr == 0) { i++; cursor->data[i] = cursor->mask[i] = 0; } switch (image[header_lines + y][x]) { case 'X': cursor->data[i] |= bit_mask; cursor->mask[i] |= bit_mask; break; case '.': cursor->mask[i] |= bit_mask; break; case ' ': break; } } } sscanf(image[header_lines + y], "%d,%d", &cursor->hot_x, &cursor->hot_y); return cursor; }
static void create_nodes_hash_table (bdd_mgr_t *mgr) { mgr->nodes_hash = (unsigned *) checked_calloc (_bdd_mgr_num_hash_buckets (mgr), sizeof(unsigned)); }
//update a MESH structure with the info from a GROUP structure void updateMesh(MODL *model, MESH *mesh, GROUP *group, float meshOffset[3]) { //update the vertice array //replace the mesh vertice array with the group vertice array mesh->numVertices = group->numVertices; free(mesh->vertices); //we had allocated memory for this mesh->vertices = group->vertices; //sever the pointer from the GROUP structure (so the memory isnt interfered with) group->vertices = NULL; //subtract the meshOffset from all vertice coordinates for(int i=0; i<mesh->numVertices; i++) { float *v = mesh->vertices[i]; for(int j=0; j<3; j++) { v[j] -= meshOffset[j]; } } //update the texture vertice array mesh->numTexVertices = group->numTexVertices; free(mesh->texVertices); mesh->texVertices = group->texVertices; group->texVertices = NULL; //update the normals array //reallocate the array to the correct size mesh->normals = checked_realloc(mesh->normals, sizeof(vector3)*mesh->numVertices); //remember as we update each normal (while updating the FACE's) int *isUpdated = checked_calloc(mesh->numVertices, sizeof(int)); //update the face array //free the old FACE structures for(int i=0; i<mesh->numFaces; i++) { freeFACE(mesh->faces[i]); } //update the size of the face array mesh->numFaces = group->numFaces; mesh->faces = checked_realloc(mesh->faces, sizeof(FACE *)*mesh->numFaces); //allocate new FACE structures for(int i=0; i<mesh->numFaces; i++) { mesh->faces[i] = createFACE(); mesh->faces[i]->faceID = i; //guessing just face index //fill in some default values for most of it setFaceDefaults(mesh, mesh->faces[i]); } //UPDATE EACH FACE for(int i=0; i<mesh->numFaces; i++) { FACE *f = mesh->faces[i]; OBJFACE *of = group->faces[i]; f->numVertices = of->numVertices; f->vertexIndices = checked_malloc(sizeof(int)*f->numVertices); f->texVertexIndices = checked_malloc(sizeof(int)*f->numVertices); for(int j=0; j<f->numVertices; j++) { //NOTE: .obj indices start from 1, so must subtract 1 from each type of index f->vertexIndices[j] = of->indices[j][0] - 1; f->texVertexIndices[j] = of->indices[j][1] - 1; //normals not needed in each FACE but must update array in the outer MESH int normalIndex = of->indices[j][2] - 1; //if the normal for this vertex has not been updated yet if(isUpdated[f->vertexIndices[j]] != 1) { //destination and source of the normal data float *dn = mesh->normals[f->vertexIndices[j]]; float *sn = group->normals[normalIndex]; //float *sn = mesh->vertices[f->vertexIndices[j]]; //copy it over for(int k=0; k<3; k++) dn[k] = sn[k]; /* float x = sn[0]; float y = sn[1]; float z = sn[2]; float mag = sqrt(x*x + y*y + z*z); x = x/mag; y = y/mag; z = z/mag; dn[0] = x; dn[1] = y; dn[2] = z; */ isUpdated[f->vertexIndices[j]] = 1; } } /* Determine which material to use based on the name specified in the .obj file */ if(f->hasMaterial != 0) { //check for an exact matching name int found = 0; for(int i=0; i < model->numMaterials; i++) { //if the .obj material name matches one in the MODL if(strcmp(model->materialNames[i], of->materialName) == 0) { //use this material and stop searching f->materialIndex = i; found = 1; break; } } //if we dont find a material with that exact name, //look for one which has the significant part of it as a substring //i.e if there is a texture gl_chest.mat and gl_chest appears in the material name use it if(found == 0) { char buffer[33]; for(int i=0; i < model->numMaterials; i++) { //find the significant part of this material name strncpy(buffer, model->materialNames[i], 33); //locate the first fullstop in the name and terminate the string there char *dot = strchr(buffer, '.'); if(dot != NULL) { *dot = '\0'; } //if the .obj material name has one of the materials as a substring if(strstr(of->materialName, buffer) != NULL) { f->materialIndex = i; found = 1; break; } } } //if still not found, report taht we are using the deafult if(found == 0) { fprintf(stderr, "Could not find a corresponding material for %s\n", of->materialName); } } } //FINISHED updating faces //in the above process the normals array should have been filled out as they were specified //just alert if this is not quite working for(int i=0; i<mesh->numVertices; i++) { //if this normal was never updated during the process if(isUpdated[i] != 1) { printf("%d\n", isUpdated[i]); fprintf(stderr, "The normal for vertex %d was NOT updated in updateMESH()\n", i); } } //no longer need this free(isUpdated); //resize the extra light data and unknown2 arrays appropriately mesh->lightData = checked_calloc(mesh->numVertices, sizeof(float)); //all 0.0 is default mesh->unknown2 = checked_calloc(mesh->numVertices, sizeof(int)); //dont know what this does, or even what type it should be, set to 0 with calloc and see what happens return; }