void init_books() { #ifdef NEW_TEXTURES paper1_text = load_texture_cached ("textures/paper1.dds", tt_image); book1_text = load_texture_cached ("textures/book1.dds", tt_image); #else /* NEW_TEXTURES */ paper1_text = load_texture_cache_deferred ("./textures/paper1.bmp", 0); book1_text = load_texture_cache_deferred ("./textures/book1.bmp", 0); #endif /* NEW_TEXTURES */ read_book("books/races/human.xml", 2, book_human); read_book("books/races/gnome.xml", 2, book_gnome); //Adding books out of order helps slightly for our tree. read_book("books/races/dwarf.xml", 2, book_dwarf); read_book("books/races/elf.xml", 2, book_elf); read_book("books/races/orchan.xml", 2, book_orchan); read_book("books/races/draegoni.xml", 2, book_draegoni); read_knowledge_book_index(); }
void ParseSimage(xmlAttr *a_node) { xmlAttr *cur_attr=NULL; for (cur_attr = a_node; cur_attr; cur_attr = cur_attr->next) { if (cur_attr->type==XML_ATTRIBUTE_NODE){ //name="" if(!xmlStrcasecmp(cur_attr->name,(xmlChar*)"name")){ #ifdef NEW_TEXTURES id = load_texture_cached((char*)cur_attr->children->content, tt_gui); #else /* NEW_TEXTURES */ id=load_texture_cache_deferred((char*)cur_attr->children->content,0); #endif /* NEW_TEXTURES */ } //isize="" if(!xmlStrcasecmp(cur_attr->name,(xmlChar*)"isize")){ isize=atoi((char*)cur_attr->children->content); } //tsize="" if(!xmlStrcasecmp(cur_attr->name,(xmlChar*)"tsize")){ tsize=atoi((char*)cur_attr->children->content); } //tid="" if(!xmlStrcasecmp(cur_attr->name,(xmlChar*)"tid")){ tid=atoi((char*)cur_attr->children->content); } //size="" if(!xmlStrcasecmp(cur_attr->name,(xmlChar*)"size")){ ssize=atoi((char*)cur_attr->children->content); } //x="" if(!xmlStrcasecmp(cur_attr->name,(xmlChar*)"x")){ x=atoi((char*)cur_attr->children->content); } //y="" if(!xmlStrcasecmp(cur_attr->name,(xmlChar*)"y")){ y=atoi((char*)cur_attr->children->content); } //mouseover="" if(!xmlStrcasecmp(cur_attr->name,(xmlChar*)"mouseover")){ mouseover=atoi((char*)cur_attr->children->content); } //xposupdate="" if(!xmlStrcasecmp(cur_attr->name,(xmlChar*)"xposupdate")){ xposupdate=atoi((char*)cur_attr->children->content); } //yposupdate="" if(!xmlStrcasecmp(cur_attr->name,(xmlChar*)"yposupdate")){ yposupdate=atoi((char*)cur_attr->children->content); } } } }
bp_Image * bp_parseImage(bp_Context * context, xmlNodePtr node) { bp_Image * result = malloc(sizeof(bp_Image)); xmlAttrPtr attr; bp_initNode(&result->node, BPE_IMAGE); result->_float = bp_defaultFloatAttributes; result->width = 32; result->height = 32; result->mirror = 0; result->rotate = 0; result->left = 0.0f; result->right = 1.0f; result->top = 0.0f; result->bottom = 1.0f; result->texture = 0; for (attr = node->properties; attr; attr = attr->next) { switch(ATTR(attr)) { case BPA_WIDTH: result->width = bp_parseInt(context, attr->children); break; case BPA_HEIGHT: result->height = bp_parseInt(context, attr->children); break; case BPA_MIRROR: result->mirror = bp_parseMirroring(context, attr->children); break; case BPA_ROTATE: result->rotate = bp_parseRotation(context, attr->children); break; case BPA_TEX_LEFT: result->left = bp_parseFloat(context, attr->children); break; case BPA_TEX_RIGHT: result->right = bp_parseFloat(context, attr->children); break; case BPA_TEX_TOP: result->top = bp_parseFloat(context, attr->children); break; case BPA_TEX_BOTTOM: result->bottom = bp_parseFloat(context, attr->children); break; case BPA_TEX_FILE: result->texture = load_texture_cache_deferred(attr->children->content, 0); break; default: bp_parseFloatAttribute(context, &result->_float, attr); } } return result; }
void fd_load() { char path[256]; xmlDocPtr doc = NULL; xmlNodePtr rootNode, fontNode; int maxFont = 0; snprintf(path, sizeof(path), "%s/fontdef.xml", datadir); doc = xmlParseFile(path); if (doc) { // find root tag for (rootNode = doc->children; rootNode && strcmp(rootNode->name, "fontdef"); rootNode = rootNode->next); if (rootNode) { // find highest font id for (fontNode = rootNode->children; fontNode; fontNode = fontNode->next) { if (!strcmp(fontNode->name, "font")) { xmlChar * strval = xmlGetProp(fontNode, "id"); if (strval) { int fontID = atoi(strval); if (fontID > maxFont) maxFont = fontID; xmlFree(strval); } } } // allocate space fd_nFonts = maxFont + 1; fd_fonts = calloc(fd_nFonts, sizeof(fd_Font *)); // calloc fills memory with zeroes bp_fonts = st_create(fd_nFonts); // load the fonts for (fontNode = rootNode->children; fontNode; fontNode = fontNode->next) { if (!strcmp(fontNode->name, "font")) { fd_Font * font = malloc(sizeof(fd_Font)); xmlChar *strval; int maxChar = 0; xmlNodePtr texNode, charNode; strval = xmlGetProp(fontNode, "linesize"); if (strval) { int linesize = atoi(strval); if (linesize > 0) { font->linesize = linesize; } else { LOG_ERROR("fontdef: 'linesize' attribute needs to be positive"); free(font); continue; } } else { LOG_ERROR("fontdef: font needs to carry 'linesize' attribute"); free(font); continue; } strval = xmlGetProp(fontNode, "baseline"); if (strval) { int baseline = atoi(strval); if (baseline >= 0) { font->baseline = baseline; } else { LOG_ERROR("fontdef: 'baseline' attribute needs to be non-negative"); free(font); continue; } } else { font->baseline = 0; } strval = xmlGetProp(fontNode, "name"); if (strval) { int size = strlen(strval) + 1; font->name = malloc(size); memcpy(font->name, strval, size); } else { LOG_ERROR("fontdef: font needs to carry 'name' attribute"); free(font); continue; } strval = xmlGetProp(fontNode, "id"); if (strval) { int fontID = atoi(strval); if (fontID >= 0) { // add font to font and symbol table fd_fonts[fontID] = font; st_addnum(bp_fonts, font->name, fontID); } xmlFree(strval); } else { LOG_ERROR("fontdef: font needs to carry 'id' attribute"); free(font->name); free(font); continue; } // find highest char value for (texNode = fontNode->children; texNode; texNode = texNode->next) { if (!strcmp(texNode->name, "texture")) { for (charNode = texNode->children; charNode; charNode = charNode->next) { if (!strcmp(charNode->name, "text")) { Uint8 * pch = charNode->content; if (pch) { while (*pch) { Uint32 uch = fd_utf8_decode(pch++); if (uch != 0xffffffff && !isspace(uch) && uch > maxChar) maxChar = uch; // find next line while (*pch && *pch != '\n') pch++; if (!*pch) break; pch++; } } } } } } // allocate space font->nChars = maxChar + 1; font->chars = calloc(font->nChars, sizeof(fd_Char)); // sets the array to zero // load the chars for (texNode = fontNode->children; texNode; texNode = texNode->next) { if (!strcmp(texNode->name, "texture")) { int tex; float texWidth, texHeight; char * texPath; texPath = xmlGetProp(texNode, "src"); if (texPath) { tex = load_texture_cache_deferred(texPath,0); xmlFree(texPath); } else { LOG_ERROR("fontdef: texture element needs to carry 'src' attribute"); continue; } strval = xmlGetProp(texNode, "width"); if (strval) { texWidth = atof(strval); xmlFree(strval); } else { LOG_ERROR("fontdef: texture element needs to carry 'width' attribute"); continue; } strval = xmlGetProp(texNode, "height"); if (strval) { texHeight = atof(strval); xmlFree(strval); } else { LOG_ERROR("fontdef: texture element needs to carry 'height' attribute"); continue; } for (charNode = texNode->children; charNode; charNode = charNode->next) { if (!strcmp(charNode->name, "text")) { const Uint8 * pch = charNode->content; if (pch) { while (*pch) { // get the char Uint32 uch = fd_utf8_decode(pch++); pch = fd_utf8_next_char(pch); if (uch != 0xffffffff && !isspace(uch)) { fd_Char * dest = &font->chars[uch]; int left, top, width, height, baseline; // get the char properties sscanf(pch, " %i %i %i %i %i", &left, &top, &width, &height, &baseline); dest->tex = tex; dest->left = ((float) left) / texWidth; dest->top = ((float) top) / texHeight; dest->right = ((float) left + width) / texWidth; dest->bottom = ((float) top + height) / texHeight; dest->width = width; dest->height = height; dest->baseline = baseline; dest->valid = 1; } // find next line while (*pch && *pch != '\n') pch++; if (!*pch) break; pch++; } } } } } } } } } st_commit(bp_fonts); free(doc); } }
void draw_window_alphaborder(window_info *win) { int w = win->len_x, h= win->len_y; // width, height if (!alpha_border_tex) { #ifdef NEW_TEXTURES alpha_border_tex = load_texture_cached("textures/alphaborder.dds", tt_image); #else /* NEW_TEXTURES */ alpha_border_tex= load_texture_cache_deferred("textures/alphaborder.bmp", 0); #endif /* NEW_TEXTURES */ if (!alpha_border_tex) return; } glColor3fv(win->back_color); glBegin(GL_LINE_LOOP); glVertex3i(0, 0, 0); glVertex3i(w, 0, 0); glVertex3i(w, h, 0); glVertex3i(0, h, 0); glEnd(); // The higher the alpha value (a=r+g+b/3) in the border texture, // the darker the shadow glEnable(GL_BLEND); glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_TEXTURE_2D); #ifdef NEW_TEXTURES bind_texture(alpha_border_tex); #else /* NEW_TEXTURES */ get_and_set_texture_id(alpha_border_tex); #endif /* NEW_TEXTURES */ glBegin(GL_QUADS); /* * * r===============================i * 11| |99 * 111| |999 * 111| |999 * 222| |888 * 222| |888 * 222| |888 * 222| |888 * 222| |888 * 222| |888 * 222| |888 * 222| |888 * 222| |888 * 222| |888 * 222| |888 * 222| |888 * 222'-------------------------------'888 * 333444555555555555555555555555555666777 * 333444555555555555555555555555555666777 * 3344455555555555555555555555555566677 * 4455555555555555555555555555566 */ #ifdef NEW_TEXTURES glTexCoord2f(1.0f, 1.0f); glVertex2i( - 8, 0); glTexCoord2f(1.0f, 0.5f); glVertex2i( 0, 0); glTexCoord2f(0.5f, 0.5f); glVertex2i( 0, 16); glTexCoord2f(0.5f, 1.0f); glVertex2i( - 8, 16); glTexCoord2f(0.5f, 1.0f); glVertex2i( - 8, 16); glTexCoord2f(0.5f, 0.5f); glVertex2i( 0, 16); glTexCoord2f(0.1f, 0.5f); glVertex2i( 0, h ); glTexCoord2f(0.1f, 1.0f); glVertex2i( - 8, h ); glTexCoord2f(0.5f, 1.0f); glVertex2i( - 8, h ); glTexCoord2f(0.5f, 0.5f); glVertex2i( 0, h ); glTexCoord2f(1.0f, 0.5f); glVertex2i( 0, h+16); glTexCoord2f(1.0f, 1.0f); glVertex2i( - 8, h+16); glTexCoord2f(0.5f, 0.5f); glVertex2i( 0, h ); glTexCoord2f(0.5f, 0.0f); glVertex2i( 8, h ); glTexCoord2f(1.0f, 0.0f); glVertex2i( 8, h+16); glTexCoord2f(1.0f, 0.5f); glVertex2i( 0, h+16); glTexCoord2f(0.1f, 0.0f); glVertex2i( 8, h ); glTexCoord2f(0.5f, 0.0f); glVertex2i(w- 8, h ); glTexCoord2f(0.5f, 1.0f); glVertex2i(w- 8, h+16); glTexCoord2f(0.1f, 1.0f); glVertex2i( 8, h+16); glTexCoord2f(0.5f, 0.0f); glVertex2i(w- 8, h ); glTexCoord2f(0.5f, 0.5f); glVertex2i(w , h ); glTexCoord2f(1.0f, 0.5f); glVertex2i(w , h+16); glTexCoord2f(1.0f, 0.0f); glVertex2i(w- 8, h+16); glTexCoord2f(0.5f, 0.5f); glVertex2i(w , h ); glTexCoord2f(0.5f, 1.0f); glVertex2i(w+ 8, h ); glTexCoord2f(1.0f, 1.0f); glVertex2i(w+ 8, h+16); glTexCoord2f(1.0f, 0.5f); glVertex2i(w , h+16); glTexCoord2f(0.1f, 0.5f); glVertex2i(w , 16); glTexCoord2f(0.1f, 1.0f); glVertex2i(w+ 8, 16); glTexCoord2f(0.5f, 1.0f); glVertex2i(w+ 8, h ); glTexCoord2f(0.5f, 0.5f); glVertex2i(w , h ); glTexCoord2f(1.0f, 0.5f); glVertex2i(w , 0); glTexCoord2f(1.0f, 1.0f); glVertex2i(w+ 8, 0); glTexCoord2f(0.5f, 1.0f); glVertex2i(w+ 8, 16); glTexCoord2f(0.5f, 0.5f); glVertex2i(w , 16); #else /* NEW_TEXTURES */ glTexCoord2f(1.0f, 0.0f); glVertex2i( - 8, 0); glTexCoord2f(1.0f, 0.5f); glVertex2i( 0, 0); glTexCoord2f(0.5f, 0.5f); glVertex2i( 0, 16); glTexCoord2f(0.5f, 0.0f); glVertex2i( - 8, 16); glTexCoord2f(0.5f, 0.0f); glVertex2i( - 8, 16); glTexCoord2f(0.5f, 0.5f); glVertex2i( 0, 16); glTexCoord2f(0.1f, 0.5f); glVertex2i( 0, h ); glTexCoord2f(0.1f, 0.0f); glVertex2i( - 8, h ); glTexCoord2f(0.5f, 0.0f); glVertex2i( - 8, h ); glTexCoord2f(0.5f, 0.5f); glVertex2i( 0, h ); glTexCoord2f(1.0f, 0.5f); glVertex2i( 0, h+16); glTexCoord2f(1.0f, 0.0f); glVertex2i( - 8, h+16); glTexCoord2f(0.5f, 0.5f); glVertex2i( 0, h ); glTexCoord2f(0.5f, 1.0f); glVertex2i( 8, h ); glTexCoord2f(1.0f, 1.0f); glVertex2i( 8, h+16); glTexCoord2f(1.0f, 0.5f); glVertex2i( 0, h+16); glTexCoord2f(0.1f, 1.0f); glVertex2i( 8, h ); glTexCoord2f(0.5f, 1.0f); glVertex2i(w- 8, h ); glTexCoord2f(0.5f, 0.0f); glVertex2i(w- 8, h+16); glTexCoord2f(0.1f, 0.0f); glVertex2i( 8, h+16); glTexCoord2f(0.5f, 1.0f); glVertex2i(w- 8, h ); glTexCoord2f(0.5f, 0.5f); glVertex2i(w , h ); glTexCoord2f(1.0f, 0.5f); glVertex2i(w , h+16); glTexCoord2f(1.0f, 1.0f); glVertex2i(w- 8, h+16); glTexCoord2f(0.5f, 0.5f); glVertex2i(w , h ); glTexCoord2f(0.5f, 0.0f); glVertex2i(w+ 8, h ); glTexCoord2f(1.0f, 0.0f); glVertex2i(w+ 8, h+16); glTexCoord2f(1.0f, 0.5f); glVertex2i(w , h+16); glTexCoord2f(0.1f, 0.5f); glVertex2i(w , 16); glTexCoord2f(0.1f, 0.0f); glVertex2i(w+ 8, 16); glTexCoord2f(0.5f, 0.0f); glVertex2i(w+ 8, h ); glTexCoord2f(0.5f, 0.5f); glVertex2i(w , h ); glTexCoord2f(1.0f, 0.5f); glVertex2i(w , 0); glTexCoord2f(1.0f, 0.0f); glVertex2i(w+ 8, 0); glTexCoord2f(0.5f, 0.0f); glVertex2i(w+ 8, 16); glTexCoord2f(0.5f, 0.5f); glVertex2i(w , 16); #endif /* NEW_TEXTURES */ glEnd(); glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); #ifdef OPENGL_TRACE CHECK_GL_ERRORS(); #endif //OPENGL_TRACE }
int load_font_textures () { #ifndef NEW_TEXTURES int poor_man_save=poor_man; int use_mipmaps_save=use_mipmaps; #endif /* NEW_TEXTURES */ size_t i = 0; char *glob_pattern; #ifdef WINDOWS struct _finddata_t c_file; long hFile; #else //WINDOWS int ret; glob_t glob_res; size_t j; #endif //WINDOWS char file[60] = ""; char str[60] = ""; if (fonts[0] == NULL || fonts[1] == NULL || fonts[2] == NULL || fonts[3]==NULL ) { for (i = 0; i < FONTS_ARRAY_SIZE; i++) { if (fonts[i] != NULL) free (fonts[i]); fonts[i] = NULL; } if ( !init_fonts () ) return 0; } #ifndef NEW_TEXTURES poor_man=0; use_mipmaps=0; #endif /* NEW_TEXTURES */ #ifdef NEW_TEXTURES fonts[0]->texture_id = load_texture_cached("textures/font.dds", tt_font); #else /* NEW_TEXTURES */ fonts[0]->texture_id = load_texture_cache("./textures/font.bmp", 0); #endif /* NEW_TEXTURES */ i = 1; // Force the selection of the base font. add_multi_option("chat_font", "Type 1"); add_multi_option("name_font", "Type 1"); // Find what font's exist and load them glob_pattern = malloc(strlen(datadir)+sizeof(texture_dir)+10+1); //+10 = font*.bmp* #ifdef NEW_TEXTURES sprintf(glob_pattern, "%s%sfont*.dds", datadir, texture_dir); #else /* NEW_TEXTURES */ sprintf(glob_pattern, "%s%sfont*.bmp*", datadir, texture_dir); #endif /* NEW_TEXTURES */ #ifdef WINDOWS if( (hFile = _findfirst( glob_pattern, &c_file )) == -1L ){ free(glob_pattern); return 0; } do { int len; safe_strncpy(file, c_file.name, sizeof(file)); #else //!WINDOWS ret = glob(glob_pattern, 0, NULL, &glob_res); if(ret != 0) { LOG_ERROR("Unable to find any font textures\n"); free(glob_pattern); return 0; } j = 0; while (j < glob_res.gl_pathc && i < FONTS_ARRAY_SIZE) { int len; safe_strncpy(file, glob_res.gl_pathv[j]+sizeof(texture_dir)-1+strlen(datadir), sizeof(file)); #endif //WINDOWS len= strlen(file); #ifdef NEW_TEXTURES if (((len + sizeof(texture_dir) - 1) < sizeof(str)) && !strncasecmp(file, "font", 4) && has_suffix(file, len, ".dds", 4)) { safe_snprintf(str, sizeof(str), "./textures/%s", file); //Use a relative path here, load_texture_cache_deferred() is using the path wrappers. file[len - 4] = 0; fonts[i]->texture_id = load_texture_cached(str, tt_font); #else /* NEW_TEXTURES */ if (len+sizeof(texture_dir)-1 < sizeof(str) && !strncasecmp(file, "font", 4) && (has_suffix(file, len, ".bmp", 4) || has_suffix(file, len, ".bmp.gz", 7)) && (!has_suffix(file, len, "_alpha.bmp", 10)) && (!has_suffix(file, len, "_alpha.bmp.gz", 13))) { // Get the filename, remove the .bmp and add _alpha.bmp to a copy, then replace the .bmp safe_snprintf(str, sizeof(str), "./textures/%s", file); //Use a relative path here, load_texture_cache_deferred() is using the path wrappers. if(has_suffix(file, len, ".bmp.gz", 7)){ file[len - 7]= 0; } else { file[len - 4]= 0; } fonts[i]->texture_id = load_texture_cache_deferred(str, 0); #endif /* NEW_TEXTURES */ safe_snprintf(font_names[i], sizeof(font_names[i]), "Type %i - %s", i + 1, file); add_multi_option("chat_font", font_names[i]); add_multi_option("name_font", font_names[i]); i++; } #ifndef WINDOWS j++; #endif //WINDOWS } #ifdef WINDOWS while ( _findnext( hFile, &c_file ) == 0 ); _findclose( hFile ); #else //!WINDOWS globfree(&glob_res); #endif //WINDOWS free(glob_pattern); #ifndef NEW_TEXTURES poor_man=poor_man_save; use_mipmaps=use_mipmaps_save; #endif /* NEW_TEXTURES */ //set the default font cur_font_num = 0; font_text = fonts[0]->texture_id; return 1; } int set_font_parameters (int num) { int i; // error checking if(num < 0 || num >= FONTS_ARRAY_SIZE) { return -1; } // allocate space if needed if(fonts[num] == NULL) { fonts[num]=(font_info *)calloc(1, sizeof(font_info)); if(fonts[num] == NULL) { LOG_ERROR(cant_load_font); return -1; } } //watch the highest font if(num >= max_fonts) { max_fonts=num+1; } // set default font info my_strcp (fonts[num]->name, "default"); fonts[num]->spacing=0; // load font information // TODO: write this and remove the hack! if(num!=1||num!=2)for(i=0; i<FONTS_ARRAY_SIZE*FONT_CHARS_PER_LINE; i++) fonts[num]->widths[i]=12; if(num==1){ static int widths[]={ 4,2,7,11,8,12,12,2,7,7,9,10,3,8, 2,10,10,10,8,8,10,7,9,9,9,9,3,3, 10,10,10,9,12,12,9,10,10,9,9,10,9,8, 7,11,8,11,10,11,9,11,11,9,10,9,12,12, 12,12,10,6,10,6,10,12,3,11,9,9,9,9, 8,9,9,4,6,10,4,11,9,10,9,9,8,8, 8,9,10,12,10,10,9,8,2,8,10,8,12,12, 12,12,12,12,12,12,12,12,12,12,12,12,12,12, 12,12,12,12,12,12,12,12,12,12,12,12,12,12, 12,12,12,12,12,12,12,12,12,12,12,12,12,12, }; memcpy(fonts[num]->widths, widths, sizeof(widths)); fonts[num]->spacing=4; } if(num==2){ static int widths[]={ 8, 8, 8, 10, 8, 10, 10, 8, 8, 8, 8, 10, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 10, 10, 10, 8, 12, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 8, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 8, 8, 8, 8, 8, 8, 8, 10, 8, 8, 8, 8, 8, 8, 10, 8, 8, 8, 8, 8, 8, 8, 8, 8, 10, 8, 8, 8, 10, 8, 10, 10, 8, 10, 8, 8, 8, 10, 10, 10, 8, 10, 10, 8, 8, 8, 12, 12, 12, 10, 10, 12, 10, 12, 12, 12, }; memcpy(fonts[num]->widths, widths, sizeof(widths)); fonts[num]->spacing=2; } //and return return num; } int set_font(int num) { if(num >= 0 && num < max_fonts && fonts[num] && fonts[num]->texture_id >= 0) { cur_font_num=num; font_text=fonts[cur_font_num]->texture_id; } return cur_font_num; }
bp_Book * bp_parseBook(bp_Context * context, xmlNodePtr node) { bp_Book * result = malloc(sizeof(bp_Book)); bp_Node * const parent = &result->node; bp_Node * page; xmlAttrPtr attr; xmlNodePtr child; bp_Page ** pages; st_data * fontSym; context->blockOutside = (void *) &bp_defaultBlockOutsideAttributes; context->blockBorder = (void *) &bp_defaultBlockBorderAttributes; context->blockInside = (void *) &bp_defaultBlockInsideAttributes; context->inlineAttr = (void *) &bp_defaultInlineAttributes; bp_pushBlockOutside(context); bp_pushBlockBorder(context); bp_pushBlockInside(context); bp_pushInline(context); bp_initNode(&result->node, BPE_BOOK); result->width = 528; result->height = 320; result->background = load_texture_cache_deferred("textures/book1.bmp",0); fontSym = st_lookup (bp_fonts, "default"); if (fontSym != NULL) { result->fontFace = fontSym->num; } else { LOG_ERROR("FATAL: default font missing in font symbol table\n"); exit(1); } result->layout = BPL_BOOK; result->blockProgression = BPD_DOWN; result->inlineProgression = BPD_RIGHT; result->pages = NULL; result->nPages = 0; for (attr = node->properties; attr; attr = attr->next) { bp_parseBlockOutsideAttribute(context, context->blockOutside, attr); bp_parseBlockBorderAttribute(context, context->blockBorder, attr); bp_parseBlockInsideAttribute(context, context->blockInside, attr); bp_parseInlineAttribute(context, context->inlineAttr, attr); } for (child = node->children; child; child = child->next) { switch(ELEM(child)) { case BPE_PAGE: result->nPages++; ADD(bp_parsePage(context, child)); break; default: DISCARD(child); } } bp_popBlockOutside(context); bp_popBlockBorder(context); bp_popBlockInside(context); bp_popInline(context); /* create page index */ pages = calloc(result->nPages, sizeof(bp_Page *)); result->pages = pages; for (page = parent->children; page; page = page->next) { *pages++ = (bp_Page *) page; } return result; }
void ParseImage(xmlAttr *a_node) { xmlAttr *cur_attr=NULL; for (cur_attr = a_node; cur_attr; cur_attr = cur_attr->next) { if (cur_attr->type==XML_ATTRIBUTE_NODE){ //u="" if(!xmlStrcasecmp(cur_attr->name,(xmlChar*)"u")){ u=(float)atof((char*)cur_attr->children->content); } //v="" if(!xmlStrcasecmp(cur_attr->name,(xmlChar*)"v")){ v=(float)atof((char*)cur_attr->children->content); } //uend="" if(!xmlStrcasecmp(cur_attr->name,(xmlChar*)"uend")){ uend=(float)atof((char*)cur_attr->children->content); } //vend="" if(!xmlStrcasecmp(cur_attr->name,(xmlChar*)"vend")){ vend=(float)atof((char*)cur_attr->children->content); } //xend="" if(!xmlStrcasecmp(cur_attr->name,(xmlChar*)"xlen")){ xend=(float)atof((char*)cur_attr->children->content); } //yend="" if(!xmlStrcasecmp(cur_attr->name,(xmlChar*)"ylen")){ yend=(float)atof((char*)cur_attr->children->content); } //name="" if(!xmlStrcasecmp(cur_attr->name,(xmlChar*)"name")){ #ifdef NEW_TEXTURES id = load_texture_cached((char*)cur_attr->children->content, tt_gui); #else /* NEW_TEXTURES */ id=load_texture_cache_deferred((char*)cur_attr->children->content,0); #endif /* NEW_TEXTURES */ } //x="" if(!xmlStrcasecmp(cur_attr->name,(xmlChar*)"x")){ x=atoi((char*)cur_attr->children->content); } //y="" if(!xmlStrcasecmp(cur_attr->name,(xmlChar*)"y")){ y=atoi((char*)cur_attr->children->content); } //mouseover="" if(!xmlStrcasecmp(cur_attr->name,(xmlChar*)"mouseover")){ mouseover=atoi((char*)cur_attr->children->content); } //xposupdate="" if(!xmlStrcasecmp(cur_attr->name,(xmlChar*)"xposupdate")){ xposupdate=atoi((char*)cur_attr->children->content); } //yposupdate="" if(!xmlStrcasecmp(cur_attr->name,(xmlChar*)"yposupdate")){ yposupdate=atoi((char*)cur_attr->children->content); } } } }
static e3d_object* do_load_e3d_detail(e3d_object* cur_object) { e3d_header header; e3d_material material; char cur_dir[1024]; int i, idx, l, mem_size, vertex_size, material_size; int file_pos, indices_size, index_size; char text_file_name[1024]; Uint32 tmp; Uint16 tmp_16; Uint8* index_pointer; el_file_ptr file; version_number version; if (cur_object == 0) return 0; memset(cur_dir, 0, sizeof(cur_dir)); //get the current directory l = strlen(cur_object->file_name); //parse the string backwards, until we find a / while (l > 0) { if ((cur_object->file_name[l] == '/') || (cur_object->file_name[l] == '\\')) break; l--; } i = 0; if (l)//prevent invalid dir names { while (l >= 0) { cur_dir[i] = cur_object->file_name[i]; i++; l--; } cur_dir[i+1] = 0; } LOG_DEBUG_OLD("Loading e3d file '%s'.", cur_object->file_name); file = el_open(cur_object->file_name); if (file == 0) { LOG_ERROR_OLD("Can't open file '%s'!", cur_object->file_name); free_e3d_pointer(cur_object); return 0; } if (read_and_check_elc_header(file, EL3D_FILE_MAGIC_NUMBER, &version, cur_object->file_name) != 0) { LOG_ERROR_OLD("File '%s' has wrong header!", cur_object->file_name); free_e3d_pointer(cur_object); el_close(file); return 0; } el_read(file, sizeof(e3d_header), &header); cur_object->vertex_no = SDL_SwapLE32(header.vertex_no); cur_object->index_no = SDL_SwapLE32(header.index_no); cur_object->material_no = SDL_SwapLE32(header.material_no); vertex_size = SDL_SwapLE32(header.vertex_size); material_size = SDL_SwapLE32(header.material_size); index_size = SDL_SwapLE32(header.index_size); LOG_DEBUG_OLD("E3d file vertex count %d and size %d.", cur_object->vertex_no, vertex_size); LOG_DEBUG_OLD("E3d file index count %d and size %d.", cur_object->index_no, index_size); LOG_DEBUG_OLD("E3d file material count %d and size %d.", cur_object->material_no, material_size); LOG_DEBUG_OLD("E3d file version %d.%d.%d.%d.", version[0], version[1], version[2], version[3]); if ((version[0] == 1) && (version[1] == 1)) { if ((header.vertex_options & 0xF0) != 0) { LOG_ERROR_OLD("Unknow options (%d) for file %s.", header.vertex_options, cur_object->file_name); } header.vertex_options &= 0x0F; if ((header.vertex_format & 0xE0) != 0) { LOG_ERROR_OLD("Unknow format (%d) for file %s.", header.vertex_format, cur_object->file_name); } header.vertex_format &= 0x1F; } else { if ((version[0] == 1) && (version[1] == 0)) { header.vertex_format = 0; header.vertex_options ^= 0x01; header.vertex_options &= 0x07; } else { LOG_ERROR_OLD("File '%s' has wrong version number!", cur_object->file_name); free_e3d_pointer(cur_object); el_close(file); return 0; } } idx = 0; if (has_normal(header.vertex_options)) { idx += 1; } if (has_color(header.vertex_options)) { idx += 2; } cur_object->vertex_layout = &(vertex_layout_array[idx]); // They have at least the size we expected if (check_vertex_size(vertex_size, header.vertex_options, header.vertex_format) == 0) { LOG_ERROR_OLD("File '%s' has wrong vertex size!", cur_object->file_name); free_e3d_pointer(cur_object); el_close(file); return 0; } if (material_size != get_material_size(header.vertex_options)) { LOG_ERROR_OLD("File '%s' has wrong material size! Expected size %d, found size %d.", cur_object->file_name, get_material_size(header.vertex_options), material_size); free_e3d_pointer(cur_object); el_close(file); return 0; } if (short_index(header.vertex_format)) { if (index_size != sizeof(Uint16)) { LOG_ERROR_OLD("File '%s' has wrong index size! Expected size %d, found size %d.", cur_object->file_name, sizeof(Uint16), index_size); free_e3d_pointer(cur_object); el_close(file); return 0; } } else { if (index_size != sizeof(Uint32)) { LOG_ERROR_OLD("File '%s' has wrong index size! Expected size %d, found size %d.", cur_object->file_name, sizeof(Uint32), index_size); free_e3d_pointer(cur_object); el_close(file); return 0; } } LOG_DEBUG_OLD("Reading vertices at %d from e3d file '%s'.", SDL_SwapLE32(header.vertex_offset), cur_object->file_name); // Now reading the vertices el_seek(file, SDL_SwapLE32(header.vertex_offset), SEEK_SET); cur_object->vertex_data = malloc(cur_object->vertex_no * cur_object->vertex_layout->size); mem_size = cur_object->vertex_no * cur_object->vertex_layout->size; if (!CHECK_POINTER(cur_object->vertex_data, "vertex data")) return 0; read_vertex_buffer(file, (float*)(cur_object->vertex_data), cur_object->vertex_no, vertex_size, header.vertex_options, header.vertex_format); LOG_DEBUG_OLD("Reading indices at %d from e3d file '%s'.", SDL_SwapLE32(header.index_offset), cur_object->file_name); // Now reading the indices el_seek(file, SDL_SwapLE32(header.index_offset), SEEK_SET); if (cur_object->index_no < 65536) { indices_size = 2; cur_object->index_type = GL_UNSIGNED_SHORT; } else { indices_size = 4; cur_object->index_type = GL_UNSIGNED_INT; } cur_object->indices = malloc(cur_object->index_no * indices_size); index_pointer = 0; for (i = 0; i < cur_object->index_no; i++) { if (index_size == 2) { el_read(file, sizeof(Uint16), &tmp_16); tmp = SDL_SwapLE16(tmp_16); } else { el_read(file, sizeof(Uint32), &tmp); tmp = SDL_SwapLE32(tmp); } if (indices_size == 2) { ((Uint16*)(cur_object->indices))[i] = tmp; } else { ((Uint32*)(cur_object->indices))[i] = tmp; } } // only allocate the materials structure if it doesn't exist (on initial load) if (cur_object->materials == 0) { cur_object->materials = (e3d_draw_list*)malloc(cur_object->material_no*sizeof(e3d_draw_list)); if (!CHECK_POINTER(cur_object->materials, "materials")) return 0; memset(cur_object->materials, 0, cur_object->material_no * sizeof(e3d_draw_list)); } mem_size += cur_object->material_no * sizeof(e3d_draw_list); LOG_DEBUG_OLD("Reading materials at %d from e3d file '%s'.", SDL_SwapLE32(header.material_offset), cur_object->file_name); // Now reading the materials el_seek(file, SDL_SwapLE32(header.material_offset), SEEK_SET); cur_object->min_x = 1e10f; cur_object->min_y = 1e10f; cur_object->min_z = 1e10f; cur_object->max_x = -1e10f; cur_object->max_y = -1e10f; cur_object->max_z = -1e10f; cur_object->max_size = -1e10f; for (i = 0; i < cur_object->material_no; i++) { file_pos = el_tell(file); el_read(file, sizeof(e3d_material), &material); safe_snprintf(text_file_name, sizeof(text_file_name), "%s%s", cur_dir, material.material_name); cur_object->materials[i].options = SDL_SwapLE32(material.options); #ifdef MAP_EDITOR #ifdef NEW_TEXTURES cur_object->materials[i].texture = load_texture_cached(text_file_name, tt_mesh); #else /* NEW_TEXTURES */ cur_object->materials[i].texture = load_texture_cache(text_file_name,0); #endif /* NEW_TEXTURES */ #else //MAP_EDITOR #ifdef NEW_TEXTURES cur_object->materials[i].texture = load_texture_cached(text_file_name, tt_mesh); #else /* NEW_TEXTURES */ #ifdef NEW_ALPHA // prepare to load the textures depending on if it is transparent or not (diff alpha handling) if (material_is_transparent(cur_object->materials[i].options)) { // is this object transparent? cur_object->materials[i].texture= load_texture_cache_deferred(text_file_name, -1); } else { cur_object->materials[i].texture= load_texture_cache_deferred(text_file_name, -1); //255); } #else //NEW_ALPHA // cur_object->materials[i].texture = load_texture_cache_deferred(text_file_name, 255); cur_object->materials[i].texture = load_texture_cache_deferred(text_file_name, 0); #endif //NEW_ALPHA #endif /* NEW_TEXTURES */ #endif //MAP_EDITOR cur_object->materials[i].min_x = SwapLEFloat(material.min_x); cur_object->materials[i].min_y = SwapLEFloat(material.min_y); cur_object->materials[i].min_z = SwapLEFloat(material.min_z); cur_object->materials[i].max_x = SwapLEFloat(material.max_x); cur_object->materials[i].max_y = SwapLEFloat(material.max_y); cur_object->materials[i].max_z = SwapLEFloat(material.max_z); // calculate the max size for cruse LOD processing cur_object->materials[i].max_size= max2f(max2f(cur_object->materials[i].max_x-cur_object->materials[i].min_x, cur_object->materials[i].max_y-cur_object->materials[i].min_y), cur_object->materials[i].max_z-cur_object->materials[i].min_z); cur_object->min_x = min2f(cur_object->min_x, cur_object->materials[i].min_x); cur_object->min_y = min2f(cur_object->min_y, cur_object->materials[i].min_y); cur_object->min_z = min2f(cur_object->min_z, cur_object->materials[i].min_z); cur_object->max_x = max2f(cur_object->max_x, cur_object->materials[i].max_x); cur_object->max_y = max2f(cur_object->max_y, cur_object->materials[i].max_y); cur_object->max_z = max2f(cur_object->max_z, cur_object->materials[i].max_z); cur_object->max_size = max2f(cur_object->max_size, cur_object->materials[i].max_size); cur_object->materials[i].triangles_indices_index = indices_size*SDL_SwapLE32(material.index) + index_pointer; cur_object->materials[i].triangles_indices_count = SDL_SwapLE32(material.count); cur_object->materials[i].triangles_indices_min = SDL_SwapLE32(material.triangles_min_index); cur_object->materials[i].triangles_indices_max = SDL_SwapLE32(material.triangles_max_index); file_pos += SDL_SwapLE32(material_size); el_seek(file, file_pos, SEEK_SET); } el_close(file); LOG_DEBUG_OLD("Building vertex buffers for e3d file '%s'.", cur_object->file_name); //Generate the buffers glGenBuffersARB(1, &cur_object->vertex_vbo); glBindBufferARB(GL_ARRAY_BUFFER_ARB, cur_object->vertex_vbo); glBufferDataARB(GL_ARRAY_BUFFER_ARB, cur_object->vertex_no * cur_object->vertex_layout->size, cur_object->vertex_data, GL_STATIC_DRAW_ARB); #ifndef MAP_EDITOR free(cur_object->vertex_data); cur_object->vertex_data = 0; #endif //MAP_EDITOR glGenBuffersARB(1, &cur_object->indices_vbo); glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, cur_object->indices_vbo); glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, cur_object->index_no * indices_size, cur_object->indices, GL_STATIC_DRAW_ARB); #ifndef MAP_EDITOR free(cur_object->indices); cur_object->indices = 0; #endif //MAP_EDITOR glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); #ifndef MAP_EDITOR LOG_DEBUG_OLD("Adding e3d file '%s' to cache.", cur_object->file_name); cache_adj_size(cache_e3d, mem_size, cur_object); #endif //MAP_EDITOR return cur_object; }
static obj_2d_def* load_obj_2d_def(const char *file_name) { int f_size; int i,k,l; el_file_ptr file = NULL; char cur_dir[200]={0}; obj_2d_def *cur_object; char *obj_file_mem; char texture_file_name[256] = {0}; float x_size,y_size; float alpha_test; int file_x_len; int file_y_len; int u_start,u_end,v_start,v_end; cur_object=calloc(1, sizeof(obj_2d_def)); //get the current directory l=strlen(file_name); //parse the string backwards, until we find a / while(l>0) { if(file_name[l]=='/' || file_name[l]=='\\')break; l--; } i=0; if(l)//prevent invalid dir names { while(l>=0) { cur_dir[i]=file_name[i]; i++; l--; } cur_dir[i+1]=0; } file = el_open(file_name); if(file == NULL){ LOG_ERROR("%s: %s \"%s\": %s\n", reg_error_str, cant_open_file, file_name, strerror(errno)); free(cur_object); return NULL; } obj_file_mem = el_get_pointer(file); if(obj_file_mem == NULL){ LOG_ERROR("%s: %s (read)\"%s\"\n", reg_error_str, cant_open_file, file_name); el_close(file); free(cur_object); return NULL; } f_size = el_get_size(file); //ok, the file is loaded, so parse it file_x_len=get_integer_after_string("file_x_len:",obj_file_mem,f_size); file_y_len=get_integer_after_string("file_y_len:",obj_file_mem,f_size); u_start=get_integer_after_string("u_start:",obj_file_mem,f_size); u_end=get_integer_after_string("u_end:",obj_file_mem,f_size); v_start=get_integer_after_string("v_start:",obj_file_mem,f_size); v_end=get_integer_after_string("v_end:",obj_file_mem,f_size); x_size=get_float_after_string("x_size:",obj_file_mem,f_size); y_size=get_float_after_string("y_size:",obj_file_mem,f_size); alpha_test=get_float_after_string("alpha_test:",obj_file_mem,f_size); if(alpha_test<0)alpha_test=0; //get the proper u/v coordinates cur_object->u_start=(float)u_start/file_x_len; cur_object->u_end=(float)u_end/file_x_len; cur_object->v_start=1.0f-(float)v_start/file_y_len; cur_object->v_end=1.0f-(float)v_end/file_y_len; cur_object->x_size=x_size; cur_object->y_size=y_size; cur_object->alpha_test=alpha_test; //now find the texture name i=get_string_occurance("texture:",obj_file_mem,40,0); obj_file_mem+=i; k=0; //find the file name while(k<128) { if(obj_file_mem[k]!=' ' && obj_file_mem[k]!=0x0a)break; k++; } //we found the beginning of the file name //now, copy the current directory string to the file_name string i=strlen(cur_dir); l=0; while(l<i) { texture_file_name[l]=cur_dir[l]; l++; } while(l<128) { if(obj_file_mem[k]!=' ' && obj_file_mem[k]!=0x0a && obj_file_mem[k]!=0x0d) { texture_file_name[l]=obj_file_mem[k]; k++; l++; } else { texture_file_name[l]=0; break; } } #ifdef NEW_TEXTURES cur_object->texture_id = load_texture_cached(texture_file_name, tt_mesh); #else /* NEW_TEXTURES */ cur_object->texture_id=load_texture_cache_deferred(texture_file_name,0); #endif /* NEW_TEXTURES */ //now get the object type i=get_string_occurance("type:",obj_file_mem,f_size,0); obj_file_mem+=i; k=0; for(k=0;k<10;k++) { if(obj_file_mem[k]==0x0a) { cur_object->object_type=INVALID; break; } if(obj_file_mem[k]==' ')continue; if(obj_file_mem[k]=='g' || obj_file_mem[k]=='G') { cur_object->object_type=GROUND; break; } if(obj_file_mem[k]=='p' || obj_file_mem[k]=='P') { cur_object->object_type=PLANT; break; } if(obj_file_mem[k]=='f' || obj_file_mem[k]=='F') { cur_object->object_type=FENCE; break; } } el_close(file); return cur_object; }
static void parse_2d0(const char* desc, Uint32 len, const char* cur_dir, obj_2d_def *def) { char name[256], value[256]; const char *cp, *cp_end; Uint32 i; int file_x_len = -1, file_y_len = -1; int u_start = -1, u_end = -1, v_start = -1, v_end = -1; def->x_size = def->y_size = def->alpha_test = -1; cp = desc; cp_end = cp + len; while (1) { // skip whitespace while (cp < cp_end && isspace(*cp)) cp++; if (cp >= cp_end) break; // copy the key i = 0; while (cp < cp_end && i < sizeof(name)-1 && !isspace(*cp) && *cp != ':' && *cp != '=') name[i++] = *cp++; name[i] = '\0'; if (cp >= cp_end) break; // skip separators while (cp < cp_end && (isspace(*cp) || *cp == ':' || *cp == '=')) { if (*cp == '\n') break; cp++; } if (cp >= cp_end) break; if (*cp == '\n') continue; // no value // copy value i = 0; while (cp < cp_end && i < sizeof(value)-1 && !isspace(*cp)) value[i++] = *cp++; value[i] = '\0'; if (!strcasecmp(name, "file_x_len")) file_x_len = atoi(value); else if (!strcasecmp(name, "file_y_len")) file_y_len = atoi(value); else if (!strcasecmp(name, "u_start")) u_start = atoi(value); else if (!strcasecmp(name, "u_end")) u_end = atoi(value); else if (!strcasecmp(name, "v_start")) v_start = atoi(value); else if (!strcasecmp(name, "v_end")) v_end = atoi(value); else if (!strcasecmp(name, "x_size")) def->x_size = atof(value); else if (!strcasecmp(name, "y_size")) def->y_size = atof(value); else if (!strcasecmp(name, "alpha_test")) def->alpha_test = atof(value); else if (!strcasecmp(name, "texture")) { char texture_file_name[256]; safe_snprintf(texture_file_name, sizeof(texture_file_name), "%s/%s", cur_dir, value); #ifdef NEW_TEXTURES def->texture_id = load_texture_cached(texture_file_name, tt_mesh); #else /* NEW_TEXTURES */ def->texture_id = load_texture_cache_deferred(texture_file_name, 0); #endif /* NEW_TEXTURES */ } else if (!strcmp(name, "type")) { switch (*value) { case 'g': case 'G': def->object_type = GROUND; break; case 'p': case 'P': def->object_type = PLANT; break; case 'f': case 'F': def->object_type = FENCE; break; default: def->object_type = INVALID; } } } def->u_start = (float)u_start/file_x_len; def->u_end = (float)u_end/file_x_len; def->v_start = 1.0f - (float)v_start/file_y_len; def->v_end = 1.0f - (float)v_end/file_y_len; if (def->alpha_test < 0) def->alpha_test = 0; }