From: DeaDDooMER Date: Mon, 17 Jan 2022 13:17:10 +0000 (+0300) Subject: render: hide panel textures into render X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=8028f947967b9156e80eea51b7f8b50f3c5862b3;p=d2df-sdl.git render: hide panel textures into render --- diff --git a/src/game/Doom2DF.lpr b/src/game/Doom2DF.lpr index 275c6f3..80bd774 100644 --- a/src/game/Doom2DF.lpr +++ b/src/game/Doom2DF.lpr @@ -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', diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 3423b33..b786671 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -448,7 +448,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, @@ -3549,6 +3549,7 @@ begin begin //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName); result := g_Map_Load(NewWAD+':\'+ResName); + r_Map_LoadTextures; end; if Result then begin diff --git a/src/game/g_map.pas b/src/game/g_map.pas index c8adfdf..eb351a0 100644 --- a/src/game/g_map.pas +++ b/src/game/g_map.pas @@ -254,8 +254,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 @@ -873,18 +871,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; @@ -985,9 +976,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(); @@ -1000,93 +991,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; @@ -1095,16 +1034,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(); @@ -1133,10 +1066,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(); @@ -1148,197 +1078,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; @@ -2397,8 +2176,6 @@ begin end; procedure g_Map_Free(freeTextures: Boolean=true); -var - a: Integer; procedure FreePanelArray(var panels: TPanelArray); var @@ -2447,27 +2224,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(); diff --git a/src/game/g_panel.pas b/src/game/g_panel.pas index 9d08ba3..abdb26d 100644 --- a/src/game/g_panel.pas +++ b/src/game/g_panel.pas @@ -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; @@ -195,8 +193,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; @@ -367,15 +363,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; @@ -950,12 +942,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 @@ -963,7 +955,7 @@ begin else Result := FTextureIDs[FCurTexture].Tex; } - end +// end end; function TPanel.GetTextureCount(): Integer; diff --git a/src/game/g_textures.pas b/src/game/g_textures.pas index aaa91b7..d35fc53 100644 --- a/src/game/g_textures.pas +++ b/src/game/g_textures.pas @@ -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; diff --git a/src/game/opengl/r_game.pas b/src/game/opengl/r_game.pas index 931769c..ed204cd 100644 --- a/src/game/opengl/r_game.pas +++ b/src/game/opengl/r_game.pas @@ -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 ; diff --git a/src/game/opengl/r_map.pas b/src/game/opengl/r_map.pas index cf7bc3e..1be9bbc 100644 --- a/src/game/opengl/r_map.pas +++ b/src/game/opengl/r_map.pas @@ -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,126 @@ 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, utils, + 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(); @@ -145,4 +256,128 @@ begin end; end; + procedure Panel_Lerp (p: TPanel; t: Single; out tX, tY, tW, tH: Integer); + begin + if p.movingActive then + begin + tX := nlerp(p.OldX, p.X, t); + tY := nlerp(p.OldY, p.Y, t); + tW := nlerp(p.OldWidth, p.Width, t); + tH := nlerp(p.OldHeight, p.Height, t); + end + else + begin + tX := p.X; + tY := p.Y; + tW := p.Width; + tH := p.Height; + end; + end; + + procedure r_Panel_Draw (constref p: TPanel; hasAmbient: Boolean; constref ambColor: TDFColor); + var tx, ty, tw, th, 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 + Panel_Lerp(p, gLerpFactor, tx, ty, tw, th); + 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 tw div w - 1 do + for yy := 0 to th div h - 1 do + r_AnimationState_Draw(FramesID, p.TextureIDs[p.FCurTexture].AnTex, tx + xx * w, ty + 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(tx, ty, tx + tw - 1, ty + th - 1, 0, 0, 255, 0, TBlending.Filter); + LongWord(TEXTURE_SPECIAL_ACID1): e_DrawFillQuad(tx, ty, tx + tw - 1, ty + th - 1, 0, 230, 0, 0, TBlending.Filter); + LongWord(TEXTURE_SPECIAL_ACID2): e_DrawFillQuad(tx, ty, tx + tw - 1, ty + th - 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, tx, ty, tw div NW, th div NH, 0, False, False); + end + else + begin + xx := tx + (tw div 2); + yy := ty + (th div 2); + e_DrawFillQuad(tx, ty, xx, yy, 255, 0, 255, 0); + e_DrawFillQuad(xx, ty, tx + tw - 1, yy, 255, 255, 0, 0); + e_DrawFillQuad(tx, yy, xx, ty + th - 1, 255, 255, 0, 0); + e_DrawFillQuad(xx, yy, tx + tw - 1, ty + th - 1, 255, 0, 255, 0); + end; + else + if not p.movingActive then + e_DrawFill(TextureID, tx, ty, tw div w, th div h, p.Alpha, True, p.Blending, hasAmbient) + else + e_DrawFillX(TextureID, tx, ty, tw, th, p.Alpha, True, p.Blending, g_dbg_scale, hasAmbient); + if hasAmbient then + e_AmbientQuad(tx, ty, tw, th, 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 tx, ty, tw, th: Integer; 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, tw, th, sX, sY, sWidth, sHeight)} then + begin + Panel_Lerp(p, gLerpFactor, tx, ty, tw, th); + if not p.TextureIDs[p.FCurTexture].Anim then + begin + Texture := p.TextureIDs[p.FCurTexture].Texture; + 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 (tx + tw < lightX - radius) then exit; + if (ty + th < lightY - radius) then exit; + if (tx > lightX + radius) then exit; + if (ty > lightY + radius) then exit; + //e_DrawFill(TextureIDs[FCurTexture].Tex, X, Y, tw div TextureWidth, th div TextureHeight, Alpha, True, Blending); + glBegin(GL_QUADS); + drawLine(tx, ty, tx + tw, ty); // top + drawLine(tx + tw, ty, tx + tw, ty + th); // right + drawLine(tx + tw, ty + th, tx, ty + th); // bottom + drawLine(tx, ty + th, tx, ty); // 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 index 539c9a7..0000000 --- a/src/game/opengl/r_panel.pas +++ /dev/null @@ -1,156 +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 . - *) -{$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, utils, - r_graphics, g_options, r_animations, r_textures, - g_base, g_basic, g_map, g_game - ; - - procedure Panel_Lerp (p: TPanel; t: Single; out tX, tY, tW, tH: Integer); - begin - if p.movingActive then - begin - tX := nlerp(p.OldX, p.X, t); - tY := nlerp(p.OldY, p.Y, t); - tW := nlerp(p.OldWidth, p.Width, t); - tH := nlerp(p.OldHeight, p.Height, t); - end - else - begin - tX := p.X; - tY := p.Y; - tW := p.Width; - tH := p.Height; - end; - end; - - // TODO: remove WITH operator - - procedure r_Panel_Draw (constref p: TPanel; hasAmbient: Boolean; constref ambColor: TDFColor); - var tx, ty, tw, th, 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 - Panel_Lerp(p, gLerpFactor, tx, ty, tw, th); - 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 tw div p.TextureWidth - 1 do - for yy := 0 to th div p.TextureHeight - 1 do - r_AnimationState_Draw(FramesID, p.TextureIDs[p.FCurTexture].AnTex, tx + xx * p.TextureWidth, ty + yy * p.TextureHeight, TMirrorType.None); - end - end - else - begin - TextureID := Textures[Texture].TextureID; // GL texture - case TextureID of - LongWord(TEXTURE_SPECIAL_WATER): e_DrawFillQuad(tx, ty, tx + tw - 1, ty + th - 1, 0, 0, 255, 0, TBlending.Filter); - LongWord(TEXTURE_SPECIAL_ACID1): e_DrawFillQuad(tx, ty, tx + tw - 1, ty + th - 1, 0, 230, 0, 0, TBlending.Filter); - LongWord(TEXTURE_SPECIAL_ACID2): e_DrawFillQuad(tx, ty, tx + tw - 1, ty + th - 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, tx, ty, tw div NW, th div NH, 0, False, False); - end - else - begin - xx := tx + (tw div 2); - yy := ty + (th div 2); - e_DrawFillQuad(tx, ty, xx, yy, 255, 0, 255, 0); - e_DrawFillQuad(xx, ty, tx + tw - 1, yy, 255, 255, 0, 0); - e_DrawFillQuad(tx, yy, xx, ty + th - 1, 255, 255, 0, 0); - e_DrawFillQuad(xx, yy, tx + tw - 1, ty + th - 1, 255, 0, 255, 0); - end; - else - if not p.movingActive then - e_DrawFill(TextureID, tx, ty, tw div p.TextureWidth, th div p.TextureHeight, p.Alpha, True, p.Blending, hasAmbient) - else - e_DrawFillX(TextureID, tx, ty, tw, th, p.Alpha, True, p.Blending, g_dbg_scale, hasAmbient); - if hasAmbient then - e_AmbientQuad(tx, ty, tw, th, 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 tx, ty, tw, th: Integer; 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, tw, th, sX, sY, sWidth, sHeight)} then - begin - Panel_Lerp(p, gLerpFactor, tx, ty, tw, th); - 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 (tx + tw < lightX - radius) then exit; - if (ty + th < lightY - radius) then exit; - if (tx > lightX + radius) then exit; - if (ty > lightY + radius) then exit; - //e_DrawFill(TextureIDs[FCurTexture].Tex, X, Y, tw div TextureWidth, th div TextureHeight, Alpha, True, Blending); - glBegin(GL_QUADS); - drawLine(tx, ty, tx + tw, ty); // top - drawLine(tx + tw, ty, tx + tw, ty + th); // right - drawLine(tx + tw, ty + th, tx, ty + th); // bottom - drawLine(tx, ty + th, tx, ty); // left - glEnd; - end - end; - -end.