DEADSOFTWARE

simple allocation counter for classes
[d2df-sdl.git] / src / game / g_textures.pas
index 660e999351988a4fb3dad1ccdecabe614d6dda3b..f18695861cd8007a217f07983c312d10c93af076 100644 (file)
@@ -19,7 +19,8 @@ unit g_textures;
 interface
 
 uses
-  e_graphics, BinEditor, ImagingTypes, Imaging, ImagingUtility;
+  mempool,
+  e_graphics, MAPDEF, BinEditor, ImagingTypes, Imaging, ImagingUtility;
 
 Type
   TLevelTexture = record
@@ -35,7 +36,7 @@ Type
 
   TLevelTextureArray = Array of TLevelTexture;
 
-  TAnimation = class(TObject)
+  TAnimation = class(TPoolObject)
   private
     ID:            DWORD;
     FAlpha:        Byte;
@@ -55,7 +56,7 @@ Type
     constructor Create(FramesID: DWORD; Loop: Boolean; Speed: Byte);
     destructor  Destroy(); override;
     procedure   Draw(X, Y: Integer; Mirror: TMirrorType);
-    procedure   DrawEx(X, Y: Integer; Mirror: TMirrorType; RPoint: TPoint;
+    procedure   DrawEx(X, Y: Integer; Mirror: TMirrorType; RPoint: TDFPoint;
                        Angle: SmallInt);
     procedure   Reset();
     procedure   Update();
@@ -84,7 +85,7 @@ Type
 
 function g_Texture_CreateWAD(var ID: DWORD; Resource: String): Boolean;
 function g_Texture_CreateFile(var ID: DWORD; FileName: String): Boolean;
-function g_Texture_CreateWADEx(TextureName: ShortString; Resource: String): Boolean;
+function g_Texture_CreateWADEx(TextureName: ShortString; Resource: String; altrsrc: AnsiString=''): Boolean;
 function g_Texture_CreateFileEx(TextureName: ShortString; FileName: String): Boolean;
 function g_Texture_Get(TextureName: ShortString; var ID: DWORD): Boolean;
 procedure g_Texture_Delete(TextureName: ShortString);
@@ -200,7 +201,7 @@ begin
   end;
 end;
 
-function g_Texture_CreateWADEx(TextureName: ShortString; Resource: String): Boolean;
+function texture_CreateWADExInternal (TextureName: ShortString; Resource: String; showmsg: Boolean): Boolean;
 var
   WAD: TWADFile;
   FileName: String;
@@ -217,25 +218,39 @@ begin
 
   if WAD.GetResource(g_ExtractFilePathName(Resource), TextureData, ResourceLength) then
   begin
-    Result := e_CreateTextureMem(TextureData, ResourceLength, TexturesArray[find_id].ID);
-    if Result then
+    result := e_CreateTextureMem(TextureData, ResourceLength, TexturesArray[find_id].ID);
+    if result then
     begin
-      e_GetTextureSize(TexturesArray[find_id].ID, @TexturesArray[find_id].Width,
-                       @TexturesArray[find_id].Height);
+      e_GetTextureSize(TexturesArray[find_id].ID, @TexturesArray[find_id].Width, @TexturesArray[find_id].Height);
       TexturesArray[find_id].Name := LowerCase(TextureName);
     end
     else
+    begin
       FreeMem(TextureData);
+    end;
   end
   else
   begin
-    e_WriteLog(Format('Error loading texture %s', [Resource]), MSG_WARNING);
+    if showmsg then
+    begin
+      e_WriteLog(Format('Error loading texture %s', [Resource]), MSG_WARNING);
+    end;
     //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
-    Result := False;
+    result := false;
   end;
   WAD.Free();
 end;
 
+function g_Texture_CreateWADEx(TextureName: ShortString; Resource: String; altrsrc: AnsiString=''): Boolean;
+begin
+  if (Length(altrsrc) > 0) then
+  begin
+    result := texture_CreateWADExInternal(TextureName, altrsrc, false);
+    if result then exit;
+  end;
+  result := texture_CreateWADExInternal(TextureName, Resource, true);
+end;
+
 function g_Texture_CreateFileEx(TextureName: ShortString; FileName: String): Boolean;
 var
   find_id: DWORD;
@@ -785,7 +800,7 @@ begin
   FEnabled := True;
 end;
 
-procedure TAnimation.DrawEx(X, Y: Integer; Mirror: TMirrorType; RPoint: TPoint;
+procedure TAnimation.DrawEx(X, Y: Integer; Mirror: TMirrorType; RPoint: TDFPoint;
                             Angle: SmallInt);
 begin
   if not FEnabled then