void loadSchemePack(uint32_t id, uint32_t loc) { ResHandle scheme = resource_get_handle(id); size_t len = resource_size(scheme); uint8_t* data = malloc(sizeof(uint8_t) * len); resource_load(scheme, data, len); pack = parseSchemePack(data); free(data); ResHandle loca = resource_get_handle(loc); len = resource_size(loca); data = malloc(sizeof(uint8_t) * len); resource_load(loca, data, len); pack->names = parseNames(data, &(pack->namesLen)); free(data); }
FPath* fpath_load_from_resource_into_buffer(uint32_t resource_id, void* buffer) { ResHandle res_handle = resource_get_handle(resource_id); size_t res_size = resource_size(res_handle); FPath* fpath = (FPath*)buffer; if (fpath) { fpath->size = (int16_t)res_size; resource_load(res_handle, fpath->data, res_size); return fpath; } return NULL; }
FPath* fpath_create_from_resource(uint32_t resource_id) { ResHandle res_handle = resource_get_handle(resource_id); size_t res_size = resource_size(res_handle); size_t path_size = res_size + sizeof(FPath); FPath* fpath = (FPath*)malloc(path_size); if (fpath) { fpath->size = (int16_t)res_size; resource_load(res_handle, fpath->data, res_size); return fpath; } return NULL; }
void load_holomesh(int craft_index) { g_current_craft = craft_index; #ifdef OVERDRAW_TEST int resource_id = RESOURCE_ID_HOLO_TIEFTR; #else int resource_id = c_craft_info[craft_index].resource_id; #endif ResHandle handle = resource_get_handle(resource_id); #ifdef PROFILE max_time = 0; min_time = 10000; total_time = 0; samples = 0; #endif // Allocate space for the resource // TODO: estimate this better if (g_holomesh == NULL) { g_holomesh = (holomesh_t*) malloc(MAX_MEMORY_SIZE); ASSERT(g_holomesh != NULL); } // Load it size_t size = resource_size(handle); size_t copied = resource_load(handle, (uint8_t*) g_holomesh, size); ASSERT(copied == g_holomesh->file_size); ASSERT(size >= g_holomesh->file_size); // Deserialize it holomesh_result hr = holomesh_deserialize(g_holomesh, size); ASSERT(hr == hmresult_ok); // Allocate renderer resources size_t scratch_size = g_holomesh->scratch_size; scratch_set(((uint8_t*)g_holomesh) + size, scratch_size); // Init the renderer render_init(); // Load the logo load_background_image(g_holomesh->info.affiliation); APP_LOG(APP_LOG_LEVEL_DEBUG, "HOLOMESH: %u bytes [0x%x-0x%x], %u mesh, %u scratch, %u hulls", (unsigned) MAX_MEMORY_SIZE, (unsigned) g_holomesh, (unsigned) g_holomesh + (unsigned) MAX_MEMORY_SIZE, (unsigned) size, (unsigned) scratch_size, (unsigned) g_holomesh->hulls.size); ASSERT(g_holomesh->hulls.size <= MAX_HULLS); }
void load_background_image(int affiliation) { int logo_resource_id = c_affiliation_logos[affiliation]; ASSERT(logo_resource_id != 0); APP_LOG(APP_LOG_LEVEL_DEBUG, "Loading logo resource %i for affiliation %i", logo_resource_id, affiliation); ResHandle logo_resource_handle = resource_get_handle(logo_resource_id); ASSERT(resource_size(logo_resource_handle) == sizeof(g_background_blob)); if (resource_load(logo_resource_handle, g_background_blob, sizeof(g_background_blob)) != sizeof(g_background_blob)) { APP_LOG(APP_LOG_LEVEL_ERROR, "Failed to load background logo resource %u", (unsigned) logo_resource_id); } else if (logoBitmap == NULL) { const uint8_t* data = prezr_load_image_data(g_background_blob); logoBitmap = gbitmap_create_with_data(data); if (logoBitmap == NULL) { APP_LOG(APP_LOG_LEVEL_ERROR, "Loaded background logo resource %u but gbitmap create failed", (unsigned) logo_resource_id); } } }
// Populates a table of names, like weekday or month names, from the language resource. void fill_date_names(char *date_names[], int num_date_names, char date_names_buffer[], int date_names_max_buffer, int resource_id) { ResHandle rh = resource_get_handle(resource_id); size_t bytes_read = resource_load(rh, (void *)date_names_buffer, date_names_max_buffer); date_names_buffer[bytes_read] = '\0'; int i = 0; char *p = date_names_buffer; date_names[i] = p; ++i; while (i < num_date_names && p < date_names_buffer + bytes_read) { if (*p == '\0') { ++p; date_names[i] = p; ++i; } else { ++p; } } while (i < num_date_names) { date_names[i] = NULL; ++i; } }
void instruction_window_load(Window *window) { // set size variables for instructions short size = get_instruction_size(instruction_type); short height = get_instruction_height(instruction_type); ResHandle rh = get_resource_handle(instruction_type); // allocate text holder and load resource instruction_text_ptr = malloc(size*sizeof(char)); reset_text(); resource_load(rh, (uint8_t *)instruction_text_ptr, size*sizeof(char)); // get bounds of the window and set bounds of text Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_frame(window_layer); GRect text_bounds = GRect(0, 0, bounds.size.w, height); // create layers s_instruction_scroll_layer = scroll_layer_create(bounds); s_instruction_text_layer = text_layer_create(text_bounds); // setup scroll view scroll_layer_set_content_size(s_instruction_scroll_layer, GSize(SCROLL_WIDTH,height)); scroll_layer_set_click_config_onto_window(s_instruction_scroll_layer, s_instruction_window); // setup text view text_layer_set_text(s_instruction_text_layer, instruction_text_ptr); text_layer_set_text_alignment(s_instruction_text_layer, GTextAlignmentCenter); // add children layer_add_child(window_get_root_layer(s_instruction_window), scroll_layer_get_layer(s_instruction_scroll_layer)); scroll_layer_add_child(s_instruction_scroll_layer, text_layer_get_layer(s_instruction_text_layer)); scroll_layer_set_content_offset(s_instruction_scroll_layer, GPoint(0,0), false); // free memory free(instruction_text_ptr); }
static BOOL script_initCodeFromUri(struct Shader_Script* me, const char* uri) { size_t i; int rv; resource_item_t *res; ppCScripts p = (ppCScripts)gglobal()->CScripts.prv; rv = FALSE; /* initialize it */ /* strip off whitespace at the beginning JAS */ while ((*uri<= ' ') && (*uri>0)) uri++; /* Try javascript protocol */ for(i=0; i!=ARR_SIZE(JS_PROTOCOLS); ++i) { const char* u=uri; const char* v=JS_PROTOCOLS[i]; while(*u && *v && *u==*v) { ++u; ++v; } /* Is this a "data:text/plain," uri? JAS*/ if((!*v && *u==',') || (!*v && *u==':')) { if (me != NULL) { return script_initCode(me, u+1); /* a script */ } else { p->buffer = STRDUP(u+1); return TRUE; /* a shader, program text will be in the "buffer" */ } } } /* Not a valid script in this SFString. Lets see if this is this a possible file that we have to get? */ DEBUG_CPARSER("script_initCodeFromUri, uri is %s\n", uri); printf ("script_initCodeFromUri, uri is %s\n", uri); res = resource_create_single(uri); resource_identify(gglobal()->resources.root_res, res); if (res->type != rest_invalid) { if (resource_fetch(res)) { if (resource_load(res)) { s_list_t *l; openned_file_t *of; l = res->openned_files; of = ml_elem(l); /* ok - Scripts get initialized; shaders get the buffer returned */ if (me==NULL) { /* a Shader */ p->buffer = STRDUP(of->fileData); /* JAS printf("**** Shader:\n%s\n", buffer); printf ("*** Shader: doing the quick return here\n"); */ return TRUE; } else { /* a Script */ /* printf("**** Script:\n%s\n", buffer); */ rv = script_initCode(me, of->fileData); } } } } if (res->status == ress_loaded && rv) { /* ok - we are replacing EXTERNPROTO with PROTO */ res->status = ress_parsed; res->complete = TRUE; return TRUE; } else { /* failure, FIXME: remove res from root_res... */ /* resource_destroy(res); */ } return FALSE; }
void script_set(const char *name) { _current = NULL; resource_load(name, &_load, &_release, &_current); }