From: Ketmar Dark Date: Sun, 17 Apr 2016 08:49:58 +0000 (+0300) Subject: remap textures X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=86c4f7d86fa84e806fbe22d1499cec948cf792db;p=d2df-sdl.git remap textures --- diff --git a/src/game/g_map.pas b/src/game/g_map.pas index 584a88f..de8bc5b 100644 --- a/src/game/g_map.pas +++ b/src/game/g_map.pas @@ -346,9 +346,10 @@ begin Result := len; end; -procedure CreateNullTexture(RecName: String); +function CreateNullTexture(RecName: String): Integer; begin SetLength(Textures, Length(Textures)+1); + result := High(Textures); with Textures[High(Textures)] do begin @@ -360,7 +361,7 @@ begin end; end; -function CreateTexture(RecName: String; Map: string; log: Boolean): Boolean; +function CreateTexture(RecName: String; Map: string; log: Boolean): Integer; var WAD: TWADEditor_1; TextureData: Pointer; @@ -369,13 +370,13 @@ var TextureName: String; a, ResLength: Integer; begin - Result := False; + Result := -1; if Textures <> nil then for a := 0 to High(Textures) do if Textures[a].TextureName = RecName then begin // Òåêñòóðà ñ òàêèì èìåíåì óæå åñòü - Result := True; + Result := a; Exit; end; @@ -402,7 +403,7 @@ begin Anim := False; end; - Result := True; + result := High(Textures); Exit; end; @@ -430,7 +431,7 @@ begin Textures[High(Textures)].TextureName := RecName; Textures[High(Textures)].Anim := False; - Result := True; + result := High(Textures); end else // Íåò òàêîãî ðåóñðñà â WAD'å if log then @@ -442,7 +443,7 @@ begin WAD.Free(); end; -function CreateAnimTexture(RecName: String; Map: string; log: Boolean): Boolean; +function CreateAnimTexture(RecName: String; Map: string; log: Boolean): Integer; var WAD: TWADEditor_1; TextureWAD: Pointer; @@ -457,7 +458,7 @@ var _width, _height, _framecount, _speed: Integer; _backanimation: Boolean; begin - Result := False; + Result := -1; // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü: g_ProcessResourceStr(RecName, WADName, SectionName, TextureName); @@ -545,7 +546,7 @@ begin FramesCount := _framecount; Speed := _speed; - Result := True; + result := High(Textures); end else if log then @@ -758,6 +759,7 @@ var MapReader: TMapReader_1; Header: TMapHeaderRec_1; _textures: TTexturesRec1Array; + _texnummap: array of Integer; // `_textures` -> `Textures` panels: TPanelsRec1Array; items: TItemsRec1Array; monsters: TMonsterRec1Array; @@ -778,7 +780,7 @@ var Data: Pointer; Len: Integer; ok, isAnim, trigRef: Boolean; - CurTex: Integer; + CurTex, ntn: Integer; begin Result := False; gMapInfo.Map := Res; @@ -825,12 +827,14 @@ begin // Çàãðóçêà òåêñòóð: g_Game_SetLoadingText(_lc[I_LOAD_TEXTURES], 0, False); _textures := MapReader.GetTextures(); + _texnummap := nil; // Äîáàâëåíèå òåêñòóð â Textures[]: if _textures <> nil then begin e_WriteLog(' Loading textures:', MSG_NOTIFY); g_Game_SetLoadingText(_lc[I_LOAD_TEXTURES], High(_textures), False); + SetLength(_texnummap, length(_textures)); for a := 0 to High(_textures) do begin @@ -842,23 +846,27 @@ begin SetLength(s, b-1); Break; end; - e_WriteLog(' Loading texture: ' + s, MSG_NOTIFY); + e_WriteLog(Format(' Loading texture #%d: %s', [a, s]), MSG_NOTIFY); + //if g_Map_IsSpecialTexture(s) then e_WriteLog(' SPECIAL!', MSG_NOTIFY); // Àíèìèðîâàííàÿ òåêñòóðà: if ByteBool(_textures[a].Anim) then begin - if not CreateAnimTexture(_textures[a].Resource, FileName, True) then + ntn := CreateAnimTexture(_textures[a].Resource, FileName, True); + if ntn < 0 then begin g_SimpleError(Format(_lc[I_GAME_ERROR_TEXTURE_ANIM], [s])); - CreateNullTexture(_textures[a].Resource); + ntn := CreateNullTexture(_textures[a].Resource); end; end else // Îáû÷íàÿ òåêñòóðà: - if not CreateTexture(_textures[a].Resource, FileName, True) then + ntn := CreateTexture(_textures[a].Resource, FileName, True); + if ntn < 0 then begin g_SimpleError(Format(_lc[I_GAME_ERROR_TEXTURE_SIMPLE], [s])); - CreateNullTexture(_textures[a].Resource); + ntn := CreateNullTexture(_textures[a].Resource); end; + _texnummap[a] := ntn; // fix texture number g_Game_StepLoading(); end; end; @@ -874,6 +882,18 @@ begin g_Game_SetLoadingText(_lc[I_LOAD_PANELS], 0, False); panels := MapReader.GetPanels(); + // check texture numbers for panels + for a := 0 to High(panels) do + begin + if panels[a].TextureNum > High(_textures) then + begin + e_WriteLog('error loading map: invalid texture index for panel', MSG_FATALERROR); + result := false; + exit; + end; + panels[a].TextureNum := _texnummap[panels[a].TextureNum]; + end; + // Ñîçäàíèå òàáëèöû òðèããåðîâ (ñîîòâåòñòâèå ïàíåëåé òðèããåðàì): if triggers <> nil then begin @@ -981,21 +1001,21 @@ begin if ByteBool(texture.Anim) then begin // Íà÷àëüíàÿ - àíèìèðîâàííàÿ, èùåì àíèìèðîâàííóþ isAnim := True; - ok := CreateAnimTexture(TexName, FileName, False); + ok := CreateAnimTexture(TexName, FileName, False) >= 0; if not ok then begin // Íåò àíèìèðîâàííîé, èùåì îáû÷íóþ isAnim := False; - ok := CreateTexture(TexName, FileName, False); + ok := CreateTexture(TexName, FileName, False) >= 0; end; end else begin // Íà÷àëüíàÿ - îáû÷íàÿ, èùåì îáû÷íóþ isAnim := False; - ok := CreateTexture(TexName, FileName, False); + ok := CreateTexture(TexName, FileName, False) >= 0; if not ok then begin // Íåò îáû÷íîé, èùåì àíèìèðîâàííóþ isAnim := True; - ok := CreateAnimTexture(TexName, FileName, False); + ok := CreateAnimTexture(TexName, FileName, False) >= 0; end; end; @@ -1039,6 +1059,8 @@ begin CurTex := 0; end; + //e_WriteLog(Format('panel #%d: TextureNum=%d; ht=%d; ht1=%d; atl=%d', [a, panels[a].TextureNum, High(_textures), High(Textures), High(AddTextures)]), MSG_NOTIFY); + // Ñîçäàåì ïàíåëü è çàïîìèíàåì åå íîìåð: PanelID := CreatePanel(panels[a], AddTextures, CurTex, trigRef);