/*Texture meneger. by stalkerg[PLG Team] stalkerg@newmail.ru http://plg.lrn.ru */ #include #include #include #include #include #include #include #include "./xml/tinyxml.h" #include "../uni.h" #include "texture.h" #include "tga.h" using namespace std; Texture *GetTFName(string name, TextureList *inlist) { TextureList::iterator i; for(i=inlist->begin(); i!=inlist->end(); ++i) if (name==i->name) return &(*i); return NULL; } /*Get Matrix view texture.*/ Texture **GetHesh(TextureList *inlist, int *outsize) { Texture **temp; int i2=0; *outsize=inlist->size(); temp=(Texture**)calloc(inlist->size(), sizeof(Texture*)); //temp= new (Texture*)[inlist->size()]; TextureList::iterator i; for (i=inlist->begin(); i!=inlist->end(); ++i) { temp[i2]= &(*i); i2++; } return temp; } /*Without size out.*/ Texture **GetHesh(TextureList *inlist) { int nulll; return GetHesh(inlist, &nulll); } void DeleteTFName(string name, TextureList *inlist) { TextureList::iterator i; for(i=inlist->begin(); i!=inlist->end(); ++i) { if (name==i->name) { inlist->erase(i); return; } } } void addTexture(TextureList *TL, char *FileName, char *Name, int Param, float *ticknow) { string temp=Name; TextureList::iterator i; for(i=TL->begin(); i!=TL->end(); ++i) { if (i->name==temp) { cout<<"Error add texture(Dublicated name "<push_front(Temp); GetTFName(Name,TL)->LoadTexture(Param); } void addTexture(TextureList *TL, const char *FileName, const char *Name, int Param, float *ticknow) { string temp=Name; TextureList::iterator i; for(i=TL->begin(); i!=TL->end(); ++i) { if (i->name==temp) { cout<<"Error add texture(Dublicated name "<push_front(Temp); GetTFName(Name,TL)->LoadTexture(Param); } void Texture::LoadTexture(const char *FileName, int Param) { string t1; SDL_Surface *texture=NULL; SDL_RWops *rw=NULL; file=FileName; t1=strrchr(FileName,'.'); struct DTA temp; int swi=0; FILE *prov=fopen(FileName,"r"); if (prov==NULL) { cout<<"Error load texture:"<w, texture->h, GL_RGB, GL_UNSIGNED_BYTE, texture->pixels); } if (t1==".png") { gluBuild2DMipmaps (GL_TEXTURE_2D, 4, texture->w, texture->h, GL_RGBA, GL_UNSIGNED_BYTE, texture->pixels); } SDL_FreeSurface(texture); SDL_FreeRW(rw); enable=true; timenow=SDL_GetTicks(); }; void LoadTextureList(string file,TextureList *inlist, float *ticknow) { string temp; TiXmlDocument doc; if(doc.LoadFile(file.c_str()) == false) { cout<FirstChildElement(); while (element) { while (true) { if((temp=element->Value())=="texture") { #ifdef DEBUG cout<Value()<<"\t"<Attribute("name")<Attribute("name"); P=element->Attribute("path"); P=PKGDATADIR+P; addTexture(inlist, P.c_str(), N.c_str(), 6, ticknow); } if (element->NextSiblingElement()) element=element->NextSiblingElement(); else break; } element=element->FirstChildElement(); } } int ManagerTexture(void *unused) { while(true) { TextureList::iterator i; for(i=((DueTList*)unused)->Main->begin(); i!=((DueTList*)unused)->Main->end(); ++i) { if(i->enable&&SDL_GetTicks()-i->timenow> ((DueTList*)unused)->in_options->tm_live_texture) ((DueTList*)unused)->Slave->push_front(&(*i)); SDL_Delay(((DueTList*)unused)->in_options->tm_iteration_pause); } SDL_Delay(((DueTList*)unused)->in_options->tm_loop_pause); } return 0; }