;============================================ ;Texture and TextureManager objects ; ;The Texture object is a container for ;a loaded IDirect3DTexture9 object, and the ;name of the file from which it was loaded. ; ;The TextureManager object's job is to ensure ;that no texture is ever loaded more than once. ;It manages a Collection of shared Texture objects. ;============================================= TextureID equ 25774 Object Texture,TextureID,Primer RedefineMethod Done DefineVariable pName,Pointer,NULL DefineVariable pTexture,Pointer,NULL ObjectEnd Method Texture.Done,uses esi SetObject esi ;Free namestring, if any .if [esi].pName!=0 MemFree [esi].pName .endif ;Release IDirect3DTexture9 object, if any .if [esi].pTexture!=0 OCall [esi].pTexture::IUnknown.Release .endif MethodEnd ;============================================================= TextureManagerID equ 25775 Object TextureManager,TextureManagerID,Primer RedefineMethod Init,Pointer RedefineMethod Done StaticMethod FindTextureByName,Pointer StaticMethod LoadFromFile,Pointer DefineVariable pTextures,Pointer,NULL ObjectEnd Method TextureManager.Init,uses esi,pOwner SetObject esi mov [esi].pTextures,$New(Collection,Init,esi,16,256,-1) ACall Init,pOwner MethodEnd Method TextureManager.Done,uses esi SetObject esi Destroy [esi].pTextures MethodEnd ;Searches the Collection of Loaded Textures ;for a Texture whose name matches that given, ;returns ptr to IDirect3DTexture9 or NULL Method TextureManager.FindTextureByName,uses esi,pfilename LOCAL cnt,ptex SetObject esi mov eax,[esi].pTextures m2m cnt,[eax].Collection.dCount xor ecx,ecx .while ecx