DEADSOFTWARE

render: hide panel textures into render
authorDeaDDooMER <deaddoomer@deadsoftware.ru>
Mon, 17 Jan 2022 13:17:10 +0000 (16:17 +0300)
committerDeaDDooMER <deaddoomer@deadsoftware.ru>
Mon, 17 Jan 2022 13:17:10 +0000 (16:17 +0300)
src/game/Doom2DF.lpr
src/game/g_game.pas
src/game/g_map.pas
src/game/g_panel.pas
src/game/g_textures.pas
src/game/opengl/r_game.pas
src/game/opengl/r_map.pas
src/game/opengl/r_panel.pas [deleted file]

index 1f7a19c87747133c9296084bd00821495bbbf72a..400e77701cc60a5b8e8980913526939a8bfc8644 100644 (file)
@@ -161,7 +161,6 @@ uses
   r_map in 'opengl/r_map.pas',
   r_monsters in 'opengl/r_monsters.pas',
   r_netmaster in 'opengl/r_netmaster.pas',
-  r_panel in 'opengl/r_panel.pas',
   r_player in 'opengl/r_player.pas',
   r_playermodel in 'opengl/r_playermodel.pas',
   r_render in 'opengl/r_render.pas',
index 325179744cf8228d7ab254f08722a8d77317e1eb..48b713c6a645f0a2fd997e839636f9bfcbf933ba 100644 (file)
@@ -439,7 +439,7 @@ uses
 {$IFDEF ENABLE_HOLMES}
   g_holmes,
 {$ENDIF}
-  e_res, g_window, g_menu, r_render, r_textures, r_animations, r_gfx,
+  e_res, g_window, g_menu, r_render, r_textures, r_animations, r_gfx, r_map,
   e_input, e_log, g_console, r_console, g_items, g_map, g_panel,
   g_playermodel, g_gfx, g_options, Math,
   g_triggers, g_monsters, e_sound, CONFIG,
@@ -3472,6 +3472,7 @@ begin
   begin
     //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
     result := g_Map_Load(NewWAD+':\'+ResName);
+    r_Map_LoadTextures;
   end;
   if Result then
     begin
index 026ef9bfc35760de0b8ae1fcf6d202b471429967..de67ae2865933f34ed4f863a42b885e0ab98ad32 100644 (file)
@@ -253,8 +253,6 @@ uses
   g_options, g_triggers, g_player, r_textures, r_animations,
   Math, g_monsters, g_saveload, g_language, g_netmsg,
   sfs, xstreams, hashtable, wadreader,
-  ImagingTypes, Imaging, ImagingUtility,
-  ImagingGif, ImagingNetworkGraphics,
   g_res_downloader;
 
 const
@@ -872,18 +870,11 @@ begin
   if (TextNameHash = nil) then TextNameHash := THashStrInt.Create();
   if TextNameHash.get(RecName, result) then exit; // i found her!
 
-  SetLength(Textures, Length(Textures)+1);
-  result := High(Textures);
-
-  with Textures[High(Textures)] do
-  begin
-    TextureName := RecName;
-    Width := 1;
-    Height := 1;
-    Anim := False;
-    TextureID := LongWord(TEXTURE_NONE);
-  end;
-
+  SetLength(Textures, Length(Textures) + 1);
+  Textures[High(Textures)].TextureName := RecName;
+  Textures[High(Textures)].FullName := '';
+  Textures[High(Textures)].Anim := False;
+  Result := High(Textures);
   TextNameHash.put(RecName, result);
 end;
 
@@ -984,9 +975,9 @@ end;
 function CreateTexture (RecName: AnsiString; Map: string; log: Boolean): Integer;
 var
   WAD: TWADFile;
-  TextureData: Pointer;
-  WADName: String;
-  a, ResLength: Integer;
+  WADName, ResName: String;
+  ResData: Pointer;
+  ResLen: Integer;
 begin
   RecName := toLowerCase1251(RecName);
   if (TextNameHash = nil) then TextNameHash := THashStrInt.Create();
@@ -999,93 +990,41 @@ begin
 
   Result := -1;
 
-  if (BadTextNameHash <> nil) and BadTextNameHash.has(RecName) then exit; // don't do it again and again
-
-  {
-  if Textures <> nil then
-  begin
-    for a := 0 to High(Textures) do
-    begin
-      if (Textures[a].TextureName = RecName) then
-      begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü
-        e_LogWritefln('texture ''%s'' already loaded', [RecName]);
-        Result := a;
-        Exit;
-      end;
-    end;
-  end;
-  }
-
-  // Òåêñòóðû ñî ñïåöèàëüíûìè èìåíàìè (âîäà, ëàâà, êèñëîòà):
-  if (RecName = TEXTURE_NAME_WATER) or
-     (RecName = TEXTURE_NAME_ACID1) or
-     (RecName = TEXTURE_NAME_ACID2) then
-  begin
-    SetLength(Textures, Length(Textures)+1);
-
-    with Textures[High(Textures)] do
-    begin
-      TextureName := RecName;
-           if (TextureName = TEXTURE_NAME_WATER) then TextureID := LongWord(TEXTURE_SPECIAL_WATER)
-      else if (TextureName = TEXTURE_NAME_ACID1) then TextureID := LongWord(TEXTURE_SPECIAL_ACID1)
-      else if (TextureName = TEXTURE_NAME_ACID2) then TextureID := LongWord(TEXTURE_SPECIAL_ACID2);
-
-      Anim := False;
-    end;
-
-    result := High(Textures);
-    TextNameHash.put(RecName, result);
-    Exit;
-  end;
-
-  // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à:
-  WADName := GetReplacementWad(g_ExtractWadName(RecName));
-  if (WADName <> '') then addResToExternalResList(WADName);
-  if WADName = '' then WADName := Map; //WADName := GameDir+'/wads/'+WADName else
-
-  WAD := TWADFile.Create();
-  WAD.ReadFile(WADName);
-
-  //txname := RecName;
-  {
-  if (WADName = Map) and WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then
-  begin
-    FreeMem(TextureData);
-    RecName := 'COMMON\ALIEN';
-  end;
-  }
-
-  if WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength, log) then
-  begin
-    SetLength(Textures, Length(Textures)+1);
-    if not e_CreateTextureMem(TextureData, ResLength, Textures[High(Textures)].TextureID) then
-    begin
-      e_WriteLog(Format('Error loading texture %s', [RecName]), TMsgType.Warning);
-      SetLength(Textures, Length(Textures)-1);
-      result := -1;
-      Exit;
-    end;
-    e_GetTextureSize(Textures[High(Textures)].TextureID, @Textures[High(Textures)].Width, @Textures[High(Textures)].Height);
-    FreeMem(TextureData);
-    Textures[High(Textures)].TextureName := RecName;
-    Textures[High(Textures)].Anim := False;
+  if (BadTextNameHash <> nil) and BadTextNameHash.has(RecName) then
+    exit; // don't do it again and again
 
-    result := High(Textures);
-    TextNameHash.put(RecName, result);
-  end
-  else // Íåò òàêîãî ðåóñðñà â WAD'å
-  begin
-    //e_WriteLog(Format('SHIT! Error loading texture %s : %s', [RecName, g_ExtractFilePathName(RecName)]), MSG_WARNING);
-    if (BadTextNameHash = nil) then BadTextNameHash := THashStrInt.Create();
-    if log and (not BadTextNameHash.get(RecName, a)) then
+  case RecName of
+    TEXTURE_NAME_WATER, TEXTURE_NAME_ACID1, TEXTURE_NAME_ACID2:
     begin
-      e_WriteLog(Format('Error loading texture %s', [RecName]), TMsgType.Warning);
-      //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
+      SetLength(Textures, Length(Textures) + 1);
+      Textures[High(Textures)].FullName := RecName;
+      Textures[High(Textures)].TextureName := RecName;
+      Textures[High(Textures)].Anim := False;
+      Result := High(Textures);
+      TextNameHash.put(RecName, result);
+    end
+  else
+    WADName := GetReplacementWad(g_ExtractWadName(RecName));
+    if (WADName <> '') then
+      addResToExternalResList(WADName);
+    if WADName = '' then
+      WADName := Map;
+    ResName := g_ExtractFilePathName(RecName);
+
+    // !!! we have a better way to check that resource exists?
+    WAD := TWADFile.Create();
+    if WAD.ReadFile(WadName) and WAD.GetResource(ResName, ResData, ResLen, log) then
+    begin
+      FreeMem(ResData);
+      SetLength(Textures, Length(Textures) + 1);
+      Textures[High(Textures)].FullName := WADName + ':' + ResName;
+      Textures[High(Textures)].TextureName := RecName;
+      Textures[High(Textures)].Anim := False;
+      Result := High(Textures);
+      TextNameHash.put(RecName, result);
     end;
-    BadTextNameHash.put(RecName, -1);
+    WAD.Free;
   end;
-
-  WAD.Free();
 end;
 
 
@@ -1094,16 +1033,10 @@ var
   WAD: TWADFile;
   TextureWAD: PChar = nil;
   TextData: Pointer = nil;
-  TextureData: Pointer = nil;
   cfg: TConfig = nil;
   WADName: String;
   ResLength: Integer;
-  TextureResource: String;
-  _width, _height, _framecount, _speed: Integer;
-  _backanimation: Boolean;
-  //imgfmt: string;
-  ia: TDynImageDataArray = nil;
-  f, c, frdelay, frloop: Integer;
+  f: Integer;
 begin
   RecName := toLowerCase1251(RecName);
   if (TextNameHash = nil) then TextNameHash := THashStrInt.Create();
@@ -1132,10 +1065,7 @@ begin
 
   WAD := TWADFile.Create();
   try
-    //if WADName <> '' then WADName := GameDir+'/wads/'+WADName else WADName := Map;
-
     WAD.ReadFile(WADName);
-
     if not WAD.GetResource(g_ExtractFilePathName(RecName), TextureWAD, ResLength, log) then
     begin
       if (BadTextNameHash = nil) then BadTextNameHash := THashStrInt.Create();
@@ -1147,197 +1077,46 @@ begin
       BadTextNameHash.put(RecName, -1);
       exit;
     end;
-
-    {TEST
-    if WADName = Map then
-    begin
-      //FreeMem(TextureWAD);
-      if not WAD.GetResource('COMMON/animation', TextureWAD, ResLength) then Halt(1);
-    end;
-    }
-
     WAD.FreeWAD();
 
-    if ResLength < 6 then
+    // íåò, ýòî ñóïåðìåí!
+    if not WAD.ReadMemory(TextureWAD, ResLength) then
     begin
-      e_WriteLog(Format('Animated texture file "%s" too short', [RecName]), TMsgType.Warning);
+      e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName]), TMsgType.Warning);
       BadTextNameHash.put(RecName, -1);
       exit;
     end;
 
-    // ýòî ïòèöà? ýòî ñàìîë¸ò?
-    if isWadData(TextureWAD, ResLength) then
+    // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
+    if not WAD.GetResource('TEXT/ANIM', TextData, ResLength) then
     begin
-      // íåò, ýòî ñóïåðìåí!
-      if not WAD.ReadMemory(TextureWAD, ResLength) then
-      begin
-        e_WriteLog(Format('Animated texture WAD file "%s" is invalid', [RecName]), TMsgType.Warning);
-        BadTextNameHash.put(RecName, -1);
-        exit;
-      end;
-
-      // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè:
-      if not WAD.GetResource('TEXT/ANIM', TextData, ResLength) then
-      begin
-        e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName]), TMsgType.Warning);
-        BadTextNameHash.put(RecName, -1);
-        exit;
-      end;
-
-      cfg := TConfig.CreateMem(TextData, ResLength);
-
-      TextureResource := cfg.ReadStr('', 'resource', '');
-      if TextureResource = '' then
-      begin
-        e_WriteLog(Format('Animated texture WAD file "%s" has no "resource"', [RecName]), TMsgType.Warning);
-        BadTextNameHash.put(RecName, -1);
-        exit;
-      end;
-
-      _width := cfg.ReadInt('', 'framewidth', 0);
-      _height := cfg.ReadInt('', 'frameheight', 0);
-      _framecount := cfg.ReadInt('', 'framecount', 0);
-      _speed := cfg.ReadInt('', 'waitcount', 0);
-      _backanimation := cfg.ReadBool('', 'backanimation', False);
+      e_WriteLog(Format('Animated texture file "%s" has invalid INI', [RecName]), TMsgType.Warning);
+      BadTextNameHash.put(RecName, -1);
+      exit;
+    end;
 
+    WAD.Free();
+    WAD := nil;
+
+    cfg := TConfig.CreateMem(TextData, ResLength);
+    if cfg <> nil then
+    begin
+      SetLength(Textures, Length(Textures) + 1);
+      Textures[High(Textures)].TextureName := RecName;
+      Textures[High(Textures)].FullName := WadName + ':' + g_ExtractFilePathName(RecName);
+      Textures[High(Textures)].Anim := True;
+      Textures[High(Textures)].FramesCount := cfg.ReadInt('', 'framecount', 0);
+      Textures[High(Textures)].Speed := cfg.ReadInt('', 'waitcount', 0);
+      result := High(Textures);
+      TextNameHash.put(RecName, result);
       cfg.Free();
       cfg := nil;
-
-      // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü:
-      if not WAD.GetResource('TEXTURES/'+TextureResource, TextureData, ResLength) then
-      begin
-        e_WriteLog(Format('Animated texture WAD file "%s" has no texture "%s"', [RecName, 'TEXTURES/'+TextureResource]), TMsgType.Warning);
-        BadTextNameHash.put(RecName, -1);
-        exit;
-      end;
-
-      WAD.Free();
-      WAD := nil;
-
-      SetLength(Textures, Length(Textures)+1);
-      with Textures[High(Textures)] do
-      begin
-        // Ñîçäàåì êàäðû àíèì. òåêñòóðû èç ïàìÿòè:
-        if g_Frames_CreateMemory(@FramesID, '', TextureData, ResLength, _width, _height, _framecount, _backanimation) then
-        begin
-          TextureName := RecName;
-          Width := _width;
-          Height := _height;
-          Anim := True;
-          FramesCount := _framecount;
-          Speed := _speed;
-          result := High(Textures);
-          TextNameHash.put(RecName, result);
-        end
-        else
-        begin
-          if (BadTextNameHash = nil) then BadTextNameHash := THashStrInt.Create();
-          if log and (not BadTextNameHash.get(RecName, f)) then
-          begin
-            e_WriteLog(Format('Error loading animation texture %s', [RecName]), TMsgType.Warning);
-          end;
-          BadTextNameHash.put(RecName, -1);
-        end;
-      end;
-    end
-    else
-    begin
-      // try animated image
-      {
-      imgfmt := DetermineMemoryFormat(TextureWAD, ResLength);
-      if length(imgfmt) = 0 then
-      begin
-        e_WriteLog(Format('Animated texture file "%s" has unknown format', [RecName]), MSG_WARNING);
-        exit;
-      end;
-      }
-      GlobalMetadata.ClearMetaItems();
-      GlobalMetadata.ClearMetaItemsForSaving();
-      if not LoadMultiImageFromMemory(TextureWAD, ResLength, ia) then
-      begin
-        e_WriteLog(Format('Animated texture file "%s" cannot be loaded', [RecName]), TMsgType.Warning);
-        BadTextNameHash.put(RecName, -1);
-        exit;
-      end;
-      if length(ia) = 0 then
-      begin
-        e_WriteLog(Format('Animated texture file "%s" has no frames', [RecName]), TMsgType.Warning);
-        BadTextNameHash.put(RecName, -1);
-        exit;
-      end;
-
-      WAD.Free();
-      WAD := nil;
-
-      _width := ia[0].width;
-      _height := ia[0].height;
-      _framecount := length(ia);
-      _speed := 1;
-      _backanimation := false;
-      frdelay := -1;
-      frloop := -666;
-      if GlobalMetadata.HasMetaItem(SMetaFrameDelay) then
-      begin
-        //writeln(' frame delay: ', GlobalMetadata.MetaItems[SMetaFrameDelay]);
-        try
-          f := GlobalMetadata.MetaItems[SMetaFrameDelay];
-          frdelay := f;
-          if f < 0 then f := 0;
-          // rounding ;-)
-          c := f mod 28;
-          if c < 13 then c := 0 else c := 1;
-          f := (f div 28)+c;
-          if f < 1 then f := 1 else if f > 255 then f := 255;
-          _speed := f;
-        except
-        end;
-      end;
-      if GlobalMetadata.HasMetaItem(SMetaAnimationLoops) then
-      begin
-        //writeln(' frame loop : ', GlobalMetadata.MetaItems[SMetaAnimationLoops]);
-        try
-          f := GlobalMetadata.MetaItems[SMetaAnimationLoops];
-          frloop := f;
-          if f <> 0 then _backanimation := true; // non-infinite looping == forth-and-back
-        except
-        end;
-      end;
-      //writeln(' creating animated texture with ', length(ia), ' frames (delay:', _speed, '; backloop:', _backanimation, ') from "', RecName, '"...');
-      //for f := 0 to high(ia) do writeln('  frame #', f, ': ', ia[f].width, 'x', ia[f].height);
-      f := ord(_backanimation);
-      e_WriteLog(Format('Animated texture file "%s": %d frames (delay:%d; back:%d; frdelay:%d; frloop:%d), %dx%d', [RecName, length(ia), _speed, f, frdelay, frloop, _width, _height]), TMsgType.Notify);
-
-      SetLength(Textures, Length(Textures)+1);
-      // cîçäàåì êàäðû àíèì. òåêñòóðû èç êàðòèíîê
-      if g_CreateFramesImg(ia, @Textures[High(Textures)].FramesID, '', _backanimation) then
-      begin
-        Textures[High(Textures)].TextureName := RecName;
-        Textures[High(Textures)].Width := _width;
-        Textures[High(Textures)].Height := _height;
-        Textures[High(Textures)].Anim := True;
-        Textures[High(Textures)].FramesCount := length(ia);
-        Textures[High(Textures)].Speed := _speed;
-        result := High(Textures);
-        TextNameHash.put(RecName, result);
-        //writeln(' CREATED!');
-      end
-      else
-      begin
-        if (BadTextNameHash = nil) then BadTextNameHash := THashStrInt.Create();
-        if log  and (not BadTextNameHash.get(RecName, f)) then
-        begin
-          e_WriteLog(Format('Error loading animation texture "%s" images', [RecName]), TMsgType.Warning);
-        end;
-        BadTextNameHash.put(RecName, -1);
-      end;
     end;
   finally
-    for f := 0 to High(ia) do FreeImage(ia[f]);
     WAD.Free();
     cfg.Free();
     if (TextureWAD <> nil) then FreeMem(TextureWAD);
     if (TextData <> nil) then FreeMem(TextData);
-    if (TextureData <> nil) then FreeMem(TextureData);
   end;
 end;
 
@@ -2396,8 +2175,6 @@ begin
 end;
 
 procedure g_Map_Free(freeTextures: Boolean=true);
-var
-  a: Integer;
 
   procedure FreePanelArray(var panels: TPanelArray);
   var
@@ -2446,27 +2223,7 @@ begin
   if freeTextures then
   begin
     e_LogWritefln('g_Map_Free: clearing textures...', []);
-    if (Textures <> nil) then
-    begin
-      for a := 0 to High(Textures) do
-      begin
-        if not g_Map_IsSpecialTexture(Textures[a].TextureName) then
-        begin
-          if Textures[a].Anim then
-          begin
-            g_Frames_DeleteByID(Textures[a].FramesID)
-          end
-          else
-          begin
-            if (Textures[a].TextureID <> LongWord(TEXTURE_NONE)) then
-            begin
-              e_DeleteTexture(Textures[a].TextureID);
-            end;
-          end;
-        end;
-      end;
-      Textures := nil;
-    end;
+    Textures := nil;
     TextNameHash.Free();
     TextNameHash := nil;
     BadTextNameHash.Free();
index d3e4414dc0832afd57c95d541cc5e018e8d858e1..fa4429256576dd18b109dd5ddaf4fbfe9871ac28 100644 (file)
@@ -41,8 +41,6 @@ type
     const
   private
     mGUID: Integer; // will be assigned in "g_map.pas"
-    FTextureWidth:    Word;
-    FTextureHeight:   Word;
     FAlpha:           Byte;
     FBlending:        Boolean;
     FTextureIDs:      ATextureID;
@@ -189,8 +187,6 @@ type
 
     (* private state *)
     property Alpha: Byte read FAlpha;
-    property TextureWidth: Word read FTextureWidth;
-    property TextureHeight: Word read FTextureHeight;
     property Blending: Boolean read FBlending;
     property TextureIDs: ATextureID read FTextureIDs;
 
@@ -357,15 +353,11 @@ begin
   if ({PanelRec.TextureNum}tnum > High(Textures)) then
   begin
     e_WriteLog(Format('WTF?! tnum is out of limits! (%d : %d)', [tnum, High(Textures)]), TMsgType.Warning);
-    FTextureWidth := 2;
-    FTextureHeight := 2;
     FAlpha := 0;
     FBlending := ByteBool(0);
   end
   else if not g_Map_IsSpecialTexture(Textures[{PanelRec.TextureNum}tnum].TextureName) then
   begin
-    FTextureWidth := Textures[{PanelRec.TextureNum}tnum].Width;
-    FTextureHeight := Textures[{PanelRec.TextureNum}tnum].Height;
     FAlpha := PanelRec.Alpha;
     FBlending := ByteBool(PanelRec.Flags and PANEL_FLAG_BLENDING);
   end;
@@ -887,12 +879,12 @@ end;
 function TPanel.GetTextureID(): DWORD;
 begin
   Result := LongWord(TEXTURE_NONE);
-  if (FCurTexture >= 0) then
-  begin
-    if FTextureIDs[FCurTexture].Anim then
-      Result := Textures[FTextureIDs[FCurTexture].Texture].FramesID
-    else
-      Result := Textures[FTextureIDs[FCurTexture].Texture].TextureID
+//  if (FCurTexture >= 0) then
+//  begin
+//    if FTextureIDs[FCurTexture].Anim then
+//      Result := Textures[FTextureIDs[FCurTexture].Texture].FramesID
+//    else
+//      Result := Textures[FTextureIDs[FCurTexture].Texture].TextureID
 {
     // !!! old behavior
     if FTextureIDs[FCurTexture].Anim then
@@ -900,7 +892,7 @@ begin
     else
       Result := FTextureIDs[FCurTexture].Tex;
 }
-  end
+//  end
 end;
 
 function TPanel.GetTextureCount(): Integer;
index aaa91b793fe590d5e3bec09c6f432b148141b148..d35fc53be4c961ae19e62c0e973b206c1720d887 100644 (file)
@@ -24,11 +24,10 @@ uses
 
 type
   TLevelTexture = record
-    textureName: AnsiString;
-    width, height: Word;
+    TextureName: AnsiString; // as stored in wad
+    FullName: AnsiString; // full path to texture // !!! merge it with TextureName
     case anim: Boolean of
-      false: (textureID: LongWord);
-      true: (framesID: LongWord; framesCount: Byte; speed: Byte);
+      true: (framesCount: Byte; speed: Byte);
   end;
 
   TLevelTextureArray = array of TLevelTexture;
index 4687ca85537d84f9c6853eed220ba7a3e4982d48..ec87b29133416e670dcfdd3462df0b489e1d242d 100644 (file)
@@ -35,7 +35,7 @@ implementation
     e_input, e_sound,
     g_language, g_console, g_menu, g_triggers, g_player, g_options, g_monsters, g_map, g_panel,
     g_items, g_weapons, g_gfx, g_phys, g_net, g_gui, g_netmaster,
-    g_game, r_console, r_gfx, r_items, r_map, r_panel, r_monsters, r_weapons, r_netmaster, r_player, r_textures,
+    g_game, r_console, r_gfx, r_items, r_map, r_monsters, r_weapons, r_netmaster, r_player, r_textures,
     r_playermodel
   ;
 
index 525bf35e9dc09d0b1f88406659b09038589e6637..7cb4263764ba7b37031ecaff219eafb5541d224e 100644 (file)
@@ -17,7 +17,9 @@ unit r_map;
 
 interface
 
-  uses MAPDEF; // TDFColor
+  uses g_panel, MAPDEF; // TPanel, TDFColor
+
+  procedure r_Map_LoadTextures;
 
   procedure r_Map_DrawBack (dx, dy: Integer);
   procedure r_Map_DrawPanels (PanelType: Word; hasAmbient: Boolean; constref ambColor: TDFColor); // unaccelerated
@@ -25,17 +27,125 @@ interface
   procedure r_Map_DrawPanelShadowVolumes (lightX: Integer; lightY: Integer; radius: Integer);
   procedure r_Map_DrawFlags;
 
+  procedure r_Panel_Draw (constref p: TPanel; hasAmbient: Boolean; constref ambColor: TDFColor);
+  procedure r_Panel_DrawShadowVolume (constref p: TPanel; lightX, lightY: Integer; radius: Integer);
+
 implementation
 
   uses
     {$INCLUDE ../nogl/noGLuses.inc}
-    SysUtils, Classes, Math,
-    r_graphics, r_animations,
+    SysUtils, Classes, Math, e_log, wadreader, CONFIG,
+    r_graphics, r_animations, r_textures,
     g_base, g_basic, g_game, g_options,
-    g_panel, g_map,
-    r_panel
+    g_map
   ;
 
+  var
+    RenTextures: array of record
+      ID: DWORD;
+      Width, Height: WORD;
+    end;
+
+  procedure r_Map_LoadTextures;
+    const
+      log = True;
+    var
+      i, n: Integer;
+      WadName, ResName: String;
+      WAD, WADZ: TWADFile;
+      ResData, ReszData: Pointer;
+      ResLen, ReszLen: Integer;
+      cfg: TConfig;
+      TextureResource: String;
+      Width, Height: Integer;
+      FramesCount: Integer;
+      BackAnim: Boolean;
+  begin
+    if Textures <> nil then
+    begin
+      n := Length(Textures);
+      SetLength(RenTextures, n);
+      for i := 0 to n - 1 do
+      begin
+        RenTextures[i].ID := LongWord(TEXTURE_NONE);
+        RenTextures[i].Width := 0;
+        RenTextures[i].Height := 0;
+        case Textures[i].TextureName of
+          TEXTURE_NAME_WATER: RenTextures[i].ID := LongWord(TEXTURE_SPECIAL_WATER);
+          TEXTURE_NAME_ACID1: RenTextures[i].ID := LongWord(TEXTURE_SPECIAL_ACID1);
+          TEXTURE_NAME_ACID2: RenTextures[i].ID := LongWord(TEXTURE_SPECIAL_ACID2);
+        else
+          WadName := g_ExtractWadName(Textures[i].FullName);
+          ResName := g_ExtractFilePathName(Textures[i].FullName);
+          WAD := TWADFile.Create();
+          if WAD.ReadFile(WadName) then
+          begin
+            if WAD.GetResource(ResName, ResData, ResLen, log) then
+            begin
+              if Textures[i].Anim then
+              begin
+                WADz := TWADFile.Create();
+                if WADz.ReadMemory(ResData, ResLen) then
+                begin
+                  if WADz.GetResource('TEXT/ANIM', ReszData, ReszLen) then
+                  begin
+                    cfg := TConfig.CreateMem(ReszData, ReszLen);
+                    FreeMem(ReszData);
+                    if cfg <> nil then
+                    begin
+                      TextureResource := cfg.ReadStr('', 'resource', '');
+                      Width := cfg.ReadInt('', 'framewidth', 0);
+                      Height := cfg.ReadInt('', 'frameheight', 0);
+                      FramesCount := cfg.ReadInt('', 'framecount', 0);
+                      // Speed := cfg.ReadInt('', 'waitcount', 0);
+                      BackAnim := cfg.ReadBool('', 'backanimation', False);
+                      RenTextures[i].Width := Width;
+                      RenTextures[i].Height := Height;
+                      if TextureResource <> '' then
+                      begin
+                        if WADz.GetResource('TEXTURES/' + TextureResource, ReszData, ReszLen) then
+                        begin
+                          if not g_Frames_CreateMemory(@RenTextures[i].ID, '', ReszData, ReszLen, Width, Height, FramesCount, BackAnim) then
+                            e_LogWritefln('r_Map_LoadTextures: failed to create frames object (%s)', [Textures[i].FullName]);
+                          FreeMem(ReszData)
+                        end
+                        else
+                          e_LogWritefln('r_Map_LoadTextures: failed to open animation resources (%s)', [Textures[i].FullName])
+                      end
+                      else
+                        e_LogWritefln('r_Map_LoadTextures: failed to animation has no texture resource string (%s)', [Textures[i].FullName]);
+                      cfg.Free
+                    end
+                    else
+                      e_LogWritefln('r_Map_LoadTextures: failed to parse animation description (%s)', [Textures[i].FullName])
+                  end
+                  else
+                    e_LogWritefln('r_Map_LoadTextures: failed to open animation description (%s)', [Textures[i].FullName])
+                end
+                else
+                  e_LogWritefln('r_Map_LoadTextures: failed to open animation (%s)', [Textures[i].FullName]);
+                WADz.Free
+              end
+              else
+              begin
+                if e_CreateTextureMem(ResData, ResLen, RenTextures[i].ID) then
+                  e_GetTextureSize(RenTextures[i].ID, @RenTextures[i].Width, @RenTextures[i].Height)
+                else
+                  e_LogWritefln('r_Map_LoadTextures: failed to create texture (%s)', [Textures[i].FullName])
+              end;
+              FreeMem(ResData);
+            end
+            else
+              e_LogWritefln('r_Map_LoadTextures: failed to open (%s)', [Textures[i].FullName])
+          end
+          else
+            e_LogWritefln('r_Map_LoadTextures: failed to open %s', [WadName]);
+          WAD.Free;
+        end
+      end
+    end
+  end;
+
 procedure dplClear ();
 begin
   if (gDrawPanelList = nil) then gDrawPanelList := TBinHeapPanelDraw.Create() else gDrawPanelList.clear();
@@ -142,4 +252,109 @@ begin
       end;
 end;
 
+  procedure r_Panel_Draw (constref p: TPanel; hasAmbient: Boolean; constref ambColor: TDFColor);
+    var xx, yy: Integer; NoTextureID, TextureID, FramesID: DWORD; NW, NH: Word; Texture: Cardinal; IsAnim: Boolean; w, h: Integer;
+  begin
+    if {p.Enabled and} (p.FCurTexture >= 0) and (p.Width > 0) and (p.Height > 0) and (p.Alpha < 255) {and g_Collide(X, Y, Width, Height, sX, sY, sWidth, sHeight)} then
+    begin
+      Texture := p.TextureIDs[p.FCurTexture].Texture;
+      IsAnim := p.TextureIDs[p.FCurTexture].Anim;
+      if IsAnim then
+      begin
+        if p.TextureIDs[p.FCurTexture].AnTex <> nil then
+        begin
+          FramesID := RenTextures[Texture].ID;
+          w := RenTextures[Texture].Width;
+          h := RenTextures[Texture].Height;
+          for xx := 0 to p.Width div w - 1 do
+            for yy := 0 to p.Height div h - 1 do
+              r_AnimationState_Draw(FramesID, p.TextureIDs[p.FCurTexture].AnTex, p.X + xx * w, p.Y + yy * h, TMirrorType.None);
+        end
+      end
+      else
+      begin
+        TextureID := RenTextures[Texture].ID;
+        w := RenTextures[Texture].Width;
+        h := RenTextures[Texture].Height;
+        case TextureID of
+          LongWord(TEXTURE_SPECIAL_WATER): e_DrawFillQuad(p.X, p.Y, p.X + p.Width - 1, p.Y + p.Height - 1, 0, 0, 255, 0, TBlending.Filter);
+          LongWord(TEXTURE_SPECIAL_ACID1): e_DrawFillQuad(p.X, p.Y, p.X + p.Width - 1, p.Y + p.Height - 1, 0, 230, 0, 0, TBlending.Filter);
+          LongWord(TEXTURE_SPECIAL_ACID2): e_DrawFillQuad(p.X, p.Y, p.X + p.Width - 1, p.Y + p.Height - 1, 230, 0, 0, 0, TBlending.Filter);
+          LongWord(TEXTURE_NONE):
+            if g_Texture_Get('NOTEXTURE', NoTextureID) then
+            begin
+              e_GetTextureSize(NoTextureID, @NW, @NH);
+              e_DrawFill(NoTextureID, p.X, p.Y, p.Width div NW, p.Height div NH, 0, False, False);
+            end
+            else
+            begin
+              xx := p.X + (p.Width div 2);
+              yy := p.Y + (p.Height div 2);
+              e_DrawFillQuad(p.X, p.Y, xx, yy, 255, 0, 255, 0);
+              e_DrawFillQuad(xx, p.Y, p.X + p.Width - 1, yy, 255, 255, 0, 0);
+              e_DrawFillQuad(p.X, yy, xx, p.Y + p.Height - 1, 255, 255, 0, 0);
+              e_DrawFillQuad(xx, yy, p.X + p.Width - 1, p.Y + p.Height - 1, 255, 0, 255, 0);
+            end;
+        else
+          if not p.movingActive then
+            e_DrawFill(TextureID, p.X, p.Y, p.Width div w, p.Height div h, p.Alpha, True, p.Blending, hasAmbient)
+          else
+            e_DrawFillX(TextureID, p.X, p.Y, p.Width, p.Height, p.Alpha, True, p.Blending, g_dbg_scale, hasAmbient);
+          if hasAmbient then
+            e_AmbientQuad(p.X, p.Y, p.Width, p.Height, ambColor.r, ambColor.g, ambColor.b, ambColor.a);
+        end
+      end
+    end
+  end;
+
+  procedure r_Panel_DrawShadowVolume (constref p: TPanel; lightX, lightY: Integer; radius: Integer);
+    var Texture: Cardinal;
+
+    procedure extrude (x: Integer; y: Integer);
+    begin
+      glVertex2i(x + (x - lightX) * 500, y + (y - lightY) * 500);
+      //e_WriteLog(Format('  : (%d,%d)', [x + (x - lightX) * 300, y + (y - lightY) * 300]), MSG_WARNING);
+    end;
+
+    procedure drawLine (x0: Integer; y0: Integer; x1: Integer; y1: Integer);
+    begin
+      // does this side facing the light?
+      if ((x1 - x0) * (lightY - y0) - (lightX - x0) * (y1 - y0) >= 0) then exit;
+      //e_WriteLog(Format('lightpan: (%d,%d)-(%d,%d)', [x0, y0, x1, y1]), MSG_WARNING);
+      // this edge is facing the light, extrude and draw it
+      glVertex2i(x0, y0);
+      glVertex2i(x1, y1);
+      extrude(x1, y1);
+      extrude(x0, y0);
+    end;
+
+  begin
+    if radius < 4 then exit;
+    if p.Enabled and (p.FCurTexture >= 0) and (p.Width > 0) and (p.Height > 0) and (p.Alpha < 255) {and g_Collide(X, Y, Width, Height, sX, sY, sWidth, sHeight)} then
+    begin
+      if not p.TextureIDs[p.FCurTexture].Anim then
+      begin
+        Texture := p.TextureIDs[p.FCurTexture].Texture;
+        // case Textures[Texture].TextureID of
+        case RenTextures[Texture].ID of
+          LongWord(TEXTURE_SPECIAL_WATER): exit;
+          LongWord(TEXTURE_SPECIAL_ACID1): exit;
+          LongWord(TEXTURE_SPECIAL_ACID2): exit;
+          LongWord(TEXTURE_NONE): exit;
+        end;
+      end;
+      if (p.X + p.Width < lightX - radius) then exit;
+      if (p.Y + p.Height < lightY - radius) then exit;
+      if (p.X > lightX + radius) then exit;
+      if (p.Y > lightY + radius) then exit;
+      //e_DrawFill(TextureIDs[FCurTexture].Tex, X, Y, Width div TextureWidth, Height div TextureHeight, Alpha, True, Blending);
+      glBegin(GL_QUADS);
+        drawLine(p.x,           p.y,            p.x + p.width, p.y); // top
+        drawLine(p.x + p.width, p.y,            p.x + p.width, p.y + p.height); // right
+        drawLine(p.x + p.width, p.y + p.height, p.x,           p.y + p.height); // bottom
+        drawLine(p.x,           p.y + p.height, p.x,           p.y); // left
+      glEnd;
+    end
+  end;
+
 end.
diff --git a/src/game/opengl/r_panel.pas b/src/game/opengl/r_panel.pas
deleted file mode 100644 (file)
index de73d72..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-(* Copyright (C)  Doom 2D: Forever Developers
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3 of the License ONLY.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *)
-{$INCLUDE ../../shared/a_modes.inc}
-unit r_panel;
-
-interface
-
-  uses g_panel, MAPDEF; // TPanel + TDFColor
-
-  procedure r_Panel_Draw (constref p: TPanel; hasAmbient: Boolean; constref ambColor: TDFColor);
-  procedure r_Panel_DrawShadowVolume (constref p: TPanel; lightX, lightY: Integer; radius: Integer);
-
-implementation
-
-  uses
-    {$INCLUDE ../nogl/noGLuses.inc}
-    SysUtils, Classes, Math,
-    r_graphics, g_options, r_animations, r_textures,
-    g_base, g_basic, g_map
-  ;
-
-  // TODO: remove WITH operator
-
-  procedure r_Panel_Draw (constref p: TPanel; hasAmbient: Boolean; constref ambColor: TDFColor);
-    var xx, yy: Integer; NoTextureID, TextureID, FramesID: DWORD; NW, NH: Word; Texture: Cardinal; IsAnim: Boolean;
-  begin
-    if {p.Enabled and} (p.FCurTexture >= 0) and (p.Width > 0) and (p.Height > 0) and (p.Alpha < 255) {and g_Collide(X, Y, Width, Height, sX, sY, sWidth, sHeight)} then
-    begin
-      Texture := p.TextureIDs[p.FCurTexture].Texture;
-      IsAnim := p.TextureIDs[p.FCurTexture].Anim;
-      if IsAnim then
-      begin
-        if p.TextureIDs[p.FCurTexture].AnTex <> nil then
-        begin
-          FramesID := Textures[Texture].FramesID;
-          for xx := 0 to p.Width div p.TextureWidth - 1 do
-            for yy := 0 to p.Height div p.TextureHeight - 1 do
-              r_AnimationState_Draw(FramesID, p.TextureIDs[p.FCurTexture].AnTex, p.X + xx * p.TextureWidth, p.Y + yy * p.TextureHeight, TMirrorType.None);
-        end
-      end
-      else
-      begin
-        TextureID := Textures[Texture].TextureID; // GL texture
-        case TextureID of
-          LongWord(TEXTURE_SPECIAL_WATER): e_DrawFillQuad(p.X, p.Y, p.X + p.Width - 1, p.Y + p.Height - 1, 0, 0, 255, 0, TBlending.Filter);
-          LongWord(TEXTURE_SPECIAL_ACID1): e_DrawFillQuad(p.X, p.Y, p.X + p.Width - 1, p.Y + p.Height - 1, 0, 230, 0, 0, TBlending.Filter);
-          LongWord(TEXTURE_SPECIAL_ACID2): e_DrawFillQuad(p.X, p.Y, p.X + p.Width - 1, p.Y + p.Height - 1, 230, 0, 0, 0, TBlending.Filter);
-          LongWord(TEXTURE_NONE):
-            if g_Texture_Get('NOTEXTURE', NoTextureID) then
-            begin
-              e_GetTextureSize(NoTextureID, @NW, @NH);
-              e_DrawFill(NoTextureID, p.X, p.Y, p.Width div NW, p.Height div NH, 0, False, False);
-            end
-            else
-            begin
-              xx := p.X + (p.Width div 2);
-              yy := p.Y + (p.Height div 2);
-              e_DrawFillQuad(p.X, p.Y, xx, yy, 255, 0, 255, 0);
-              e_DrawFillQuad(xx, p.Y, p.X + p.Width - 1, yy, 255, 255, 0, 0);
-              e_DrawFillQuad(p.X, yy, xx, p.Y + p.Height - 1, 255, 255, 0, 0);
-              e_DrawFillQuad(xx, yy, p.X + p.Width - 1, p.Y + p.Height - 1, 255, 0, 255, 0);
-            end;
-        else
-          if not p.movingActive then
-            e_DrawFill(TextureID, p.X, p.Y, p.Width div p.TextureWidth, p.Height div p.TextureHeight, p.Alpha, True, p.Blending, hasAmbient)
-          else
-            e_DrawFillX(TextureID, p.X, p.Y, p.Width, p.Height, p.Alpha, True, p.Blending, g_dbg_scale, hasAmbient);
-          if hasAmbient then
-            e_AmbientQuad(p.X, p.Y, p.Width, p.Height, ambColor.r, ambColor.g, ambColor.b, ambColor.a);
-        end
-      end
-    end
-  end;
-
-  procedure r_Panel_DrawShadowVolume (constref p: TPanel; lightX, lightY: Integer; radius: Integer);
-    var Texture: Cardinal;
-
-    procedure extrude (x: Integer; y: Integer);
-    begin
-      glVertex2i(x + (x - lightX) * 500, y + (y - lightY) * 500);
-      //e_WriteLog(Format('  : (%d,%d)', [x + (x - lightX) * 300, y + (y - lightY) * 300]), MSG_WARNING);
-    end;
-
-    procedure drawLine (x0: Integer; y0: Integer; x1: Integer; y1: Integer);
-    begin
-      // does this side facing the light?
-      if ((x1 - x0) * (lightY - y0) - (lightX - x0) * (y1 - y0) >= 0) then exit;
-      //e_WriteLog(Format('lightpan: (%d,%d)-(%d,%d)', [x0, y0, x1, y1]), MSG_WARNING);
-      // this edge is facing the light, extrude and draw it
-      glVertex2i(x0, y0);
-      glVertex2i(x1, y1);
-      extrude(x1, y1);
-      extrude(x0, y0);
-    end;
-
-  begin
-    if radius < 4 then exit;
-    if p.Enabled and (p.FCurTexture >= 0) and (p.Width > 0) and (p.Height > 0) and (p.Alpha < 255) {and g_Collide(X, Y, Width, Height, sX, sY, sWidth, sHeight)} then
-    begin
-      if not p.TextureIDs[p.FCurTexture].Anim then
-      begin
-        Texture := p.TextureIDs[p.FCurTexture].Texture;
-        case Textures[Texture].TextureID of
-          LongWord(TEXTURE_SPECIAL_WATER): exit;
-          LongWord(TEXTURE_SPECIAL_ACID1): exit;
-          LongWord(TEXTURE_SPECIAL_ACID2): exit;
-          LongWord(TEXTURE_NONE): exit;
-        end;
-      end;
-      if (p.X + p.Width < lightX - radius) then exit;
-      if (p.Y + p.Height < lightY - radius) then exit;
-      if (p.X > lightX + radius) then exit;
-      if (p.Y > lightY + radius) then exit;
-      //e_DrawFill(TextureIDs[FCurTexture].Tex, X, Y, Width div TextureWidth, Height div TextureHeight, Alpha, True, Blending);
-      glBegin(GL_QUADS);
-        drawLine(p.x,           p.y,            p.x + p.width, p.y); // top
-        drawLine(p.x + p.width, p.y,            p.x + p.width, p.y + p.height); // right
-        drawLine(p.x + p.width, p.y + p.height, p.x,           p.y + p.height); // bottom
-        drawLine(p.x,           p.y + p.height, p.x,           p.y); // left
-      glEnd;
-    end
-  end;
-
-end.