From d64cda34a561a8aba09f3f37c121fdf12d0d7beb Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Mon, 11 Sep 2017 16:45:30 +0300 Subject: [PATCH] dbg_scale fixes; made non-sky textures always NEAREST --- src/engine/e_graphics.pas | 15 ++++++--- src/game/g_game.pas | 5 ++- src/game/g_holmes.pas | 2 +- src/game/g_map.pas | 70 +++++++++++++++++++++------------------ src/game/g_monsters.pas | 2 +- src/game/g_panel.pas | 2 +- src/game/g_window.pas | 2 +- 7 files changed, 54 insertions(+), 44 deletions(-) diff --git a/src/engine/e_graphics.pas b/src/engine/e_graphics.pas index ded8593..467994f 100644 --- a/src/engine/e_graphics.pas +++ b/src/engine/e_graphics.pas @@ -144,6 +144,7 @@ var e_Colors: TRGB; e_NoGraphics: Boolean = False; e_FastScreenshots: Boolean = true; // it's REALLY SLOW with `false` + g_dbg_scale: Single = 1.0; implementation @@ -468,7 +469,7 @@ begin e_SetViewPort(0, 0, Width, Height); end; -procedure drawTxQuad (x0, y0, w, h: Integer; u, v: single; Mirror: TMirrorType); +procedure drawTxQuad (x0, y0, w, h, tw, th: Integer; u, v: single; Mirror: TMirrorType); var x1, y1, tmp: Integer; begin @@ -477,6 +478,12 @@ begin y1 := y0+h; if Mirror = M_HORIZONTAL then begin tmp := x1; x1 := x0; x0 := tmp; end else if Mirror = M_VERTICAL then begin tmp := y1; y1 := y0; y0 := tmp; end; + //HACK: make texture one pixel shorter, so it won't wrap + if (g_dbg_scale <> 1.0) then + begin + u := u*tw/(tw+1); + v := v*th/(th+1); + end; glTexCoord2f(0, v); glVertex2i(x0, y0); glTexCoord2f(0, 0); glVertex2i(x0, y1); glTexCoord2f(u, 0); glVertex2i(x1, y1); @@ -507,7 +514,7 @@ begin glBindTexture(GL_TEXTURE_2D, e_Textures[ID].tx.id); glBegin(GL_QUADS); - drawTxQuad(X, Y, e_Textures[id].tx.width, e_Textures[id].tx.height, e_Textures[ID].tx.u, e_Textures[ID].tx.v, Mirror); + drawTxQuad(X, Y, e_Textures[id].tx.width, e_Textures[id].tx.height, e_Textures[id].tx.width, e_Textures[id].tx.height, e_Textures[ID].tx.u, e_Textures[ID].tx.v, Mirror); //u := e_Textures[ID].tx.u; //v := e_Textures[ID].tx.v; @@ -604,7 +611,7 @@ begin glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, e_Textures[ID].tx.id); glBegin(GL_QUADS); - drawTxQuad(X, Y, Width, Height, e_Textures[ID].tx.u, e_Textures[ID].tx.v, Mirror); + drawTxQuad(X, Y, Width, Height, e_Textures[id].tx.width, e_Textures[id].tx.height, e_Textures[ID].tx.u, e_Textures[ID].tx.v, Mirror); glEnd(); glDisable(GL_BLEND); @@ -892,7 +899,7 @@ begin glBindTexture(GL_TEXTURE_2D, e_Textures[id].tx.id); glBegin(GL_QUADS); //0-1 1-1 //00 10 - drawTxQuad(X, Y, e_Textures[id].tx.width, e_Textures[id].tx.height, e_Textures[ID].tx.u, e_Textures[ID].tx.v, Mirror); + drawTxQuad(X, Y, e_Textures[id].tx.width, e_Textures[id].tx.height, e_Textures[id].tx.width, e_Textures[id].tx.height, e_Textures[ID].tx.u, e_Textures[ID].tx.v, Mirror); glEnd(); if Angle <> 0 then diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 1d95bda..2b14233 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -324,8 +324,6 @@ var g_rlayer_water: Boolean = true; g_rlayer_fore: Boolean = true; - g_dbg_scale: Single = 1.0; - procedure g_ResetDynlights (); procedure g_AddDynLight (x, y, radius: Integer; r, g, b, a: Single); @@ -337,7 +335,7 @@ function conIsCheatsEnabled (): Boolean; implementation uses - g_textures, g_main, g_window, g_menu, + e_texture, g_textures, g_main, g_window, g_menu, e_input, e_log, g_console, g_items, g_map, g_panel, g_playermodel, g_gfx, g_options, g_weapons, Math, g_triggers, g_monsters, e_sound, CONFIG, @@ -2912,6 +2910,7 @@ begin if setTransMatrix then begin + //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0); glScalef(g_dbg_scale, g_dbg_scale, 1.0); glTranslatef(-sX, -sY, 0); end; diff --git a/src/game/g_holmes.pas b/src/game/g_holmes.pas index b6724a9..96e86c9 100644 --- a/src/game/g_holmes.pas +++ b/src/game/g_holmes.pas @@ -103,7 +103,7 @@ var implementation uses - {rttiobj,} typinfo, + {rttiobj,} typinfo, e_texture, SysUtils, Classes, GL, SDL2, MAPDEF, g_main, g_options, utils, hashtable, xparser; diff --git a/src/game/g_map.pas b/src/game/g_map.pas index bac475b..9c696cb 100644 --- a/src/game/g_map.pas +++ b/src/game/g_map.pas @@ -242,7 +242,7 @@ var implementation uses - e_input, g_main, e_log, SysUtils, g_items, g_gfx, g_console, + e_input, g_main, e_log, e_texture, SysUtils, g_items, g_gfx, g_console, GL, GLExt, g_weapons, g_game, g_sound, e_sound, CONFIG, g_options, g_triggers, g_player, Math, g_monsters, g_saveload, g_language, g_netmsg, @@ -878,6 +878,7 @@ var TextureData: Pointer; WADName: String; a, ResLength: Integer; + oldFilter: Integer; begin RecName := toLowerCase1251(RecName); if (TextNameHash = nil) then TextNameHash := hashNewStrInt(); @@ -947,32 +948,38 @@ begin 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 + oldFilter := TEXTUREFILTER; + TEXTUREFILTER := GL_NEAREST; + try + if WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength, log) then begin - SetLength(Textures, Length(Textures)-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; + SetLength(Textures, Length(Textures)+1); + if not e_CreateTextureMem(TextureData, ResLength, Textures[High(Textures)].TextureID) then + begin + SetLength(Textures, Length(Textures)-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; - 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 := hashNewStrInt(); - if log and (not BadTextNameHash.get(RecName, a)) then + result := High(Textures); + TextNameHash.put(RecName, result); + end + else // Íåò òàêîãî ðåóñðñà â WAD'å begin - e_WriteLog(Format('Error loading texture %s', [RecName]), MSG_WARNING); - //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING); + //e_WriteLog(Format('SHIT! Error loading texture %s : %s', [RecName, g_ExtractFilePathName(RecName)]), MSG_WARNING); + if (BadTextNameHash = nil) then BadTextNameHash := hashNewStrInt(); + if log and (not BadTextNameHash.get(RecName, a)) then + begin + e_WriteLog(Format('Error loading texture %s', [RecName]), MSG_WARNING); + //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING); + end; + BadTextNameHash.put(RecName, -1); end; - BadTextNameHash.put(RecName, -1); + finally + TEXTUREFILTER := oldFilter; end; WAD.Free(); @@ -2084,26 +2091,23 @@ begin mapReader := nil; // Çàãðóçêà íåáà - if gMapInfo.SkyName <> '' then + if (gMapInfo.SkyName <> '') then begin e_WriteLog(' Loading sky: ' + gMapInfo.SkyName, MSG_NOTIFY); g_Game_SetLoadingText(_lc[I_LOAD_SKY], 0, False); FileName := g_ExtractWadName(gMapInfo.SkyName); - if FileName <> '' then - FileName := GameDir+'/wads/'+FileName - else - begin - FileName := g_ExtractWadName(Res); - end; + if (FileName <> '') then FileName := GameDir+'/wads/'+FileName else FileName := g_ExtractWadName(Res); s := FileName+':'+g_ExtractFilePathName(gMapInfo.SkyName); if g_Texture_CreateWAD(BackID, s) then - begin - g_Game_SetupScreenSize(); - end + begin + g_Game_SetupScreenSize(); + end else + begin g_FatalError(Format(_lc[I_GAME_ERROR_SKY], [s])); + end; end; // Çàãðóçêà ìóçûêè diff --git a/src/game/g_monsters.pas b/src/game/g_monsters.pas index 834220a..9647d18 100644 --- a/src/game/g_monsters.pas +++ b/src/game/g_monsters.pas @@ -306,7 +306,7 @@ var implementation uses - e_log, g_main, g_sound, g_gfx, g_player, g_game, + e_log, e_texture, g_main, g_sound, g_gfx, g_player, g_game, g_weapons, g_triggers, MAPDEF, g_items, g_options, g_console, g_map, Math, SysUtils, g_menu, wadreader, g_language, g_netmsg, idpool; diff --git a/src/game/g_panel.pas b/src/game/g_panel.pas index 07fe2d6..16f43c2 100644 --- a/src/game/g_panel.pas +++ b/src/game/g_panel.pas @@ -208,7 +208,7 @@ var implementation uses - SysUtils, g_basic, g_map, g_game, g_gfx, e_graphics, g_weapons, g_triggers, + SysUtils, e_texture, g_basic, g_map, g_game, g_gfx, e_graphics, g_weapons, g_triggers, g_console, g_language, g_monsters, g_player, g_grid, e_log, GL, utils; const diff --git a/src/game/g_window.pas b/src/game/g_window.pas index 5f04992..46ec6df 100644 --- a/src/game/g_window.pas +++ b/src/game/g_window.pas @@ -48,7 +48,7 @@ implementation uses {$IFDEF WINDOWS}Windows,{$ENDIF} SysUtils, Classes, MAPDEF, - SDL2, GL, GLExt, e_graphics, e_log, g_main, + SDL2, GL, GLExt, e_graphics, e_log, e_texture, g_main, g_console, e_input, g_options, g_game, g_basic, g_textures, e_sound, g_sound, g_menu, ENet, g_net, g_map, g_gfx, g_monsters, g_holmes, xprofiler, utils; -- 2.29.2