From 3a016cd76ab4af26fd21169377a9d39f648410dc Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Sun, 16 Jan 2022 20:43:52 +0300 Subject: [PATCH] models: remove TModelInfo --- src/game/g_menu.pas | 13 +++-- src/game/g_playermodel.pas | 79 ++++++++++++++----------------- src/game/opengl/r_playermodel.pas | 16 +++---- 3 files changed, 50 insertions(+), 58 deletions(-) diff --git a/src/game/g_menu.pas b/src/game/g_menu.pas index f81733b..c83a8fa 100644 --- a/src/game/g_menu.pas +++ b/src/game/g_menu.pas @@ -1425,7 +1425,7 @@ end; procedure ProcOptionsPlayersMIMenu(); var s, a: string; - b: TModelInfo; + i: Integer; begin if g_ActiveWindow.Name = 'OptionsPlayersP1Menu' then s := 'P1' else s := 'P2'; @@ -1433,15 +1433,14 @@ begin if a = '' then Exit; - b := g_PlayerModel_GetInfo(a); - + i := g_PlayerModel_GetIndex(a); with TGUIMenu(g_GUI_GetWindow('OptionsPlayersMIMenu').GetControl('mOptionsPlayersMIMenu')) do begin - TGUILabel(GetControl('lbName')).Text := b.Name; - TGUILabel(GetControl('lbAuthor')).Text := b.Author; - TGUIMemo(GetControl('meComment')).SetText(b.Description); + TGUILabel(GetControl('lbName')).Text := PlayerModelsArray[i].Name; + TGUILabel(GetControl('lbAuthor')).Text := PlayerModelsArray[i].Author; + TGUIMemo(GetControl('meComment')).SetText(PlayerModelsArray[i].Description); - if b.HaveWeapon then + if PlayerModelsArray[i].HaveWeapon then TGUILabel(GetControl('lbWeapon')).Text := _lc[I_MENU_YES] else TGUILabel(GetControl('lbWeapon')).Text := _lc[I_MENU_NO]; diff --git a/src/game/g_playermodel.pas b/src/game/g_playermodel.pas index 393e07d..ca4b6dc 100644 --- a/src/game/g_playermodel.pas +++ b/src/game/g_playermodel.pas @@ -80,13 +80,6 @@ type R, G, B, Kind: Byte; end; - TModelInfo = record - Name: String; - Author: String; - Description: String; - HaveWeapon: Boolean; - end; - TModelSound = record ID: DWORD; Level: Byte; @@ -145,17 +138,21 @@ procedure g_PlayerModel_LoadAll; procedure g_PlayerModel_FreeData(); function g_PlayerModel_Load(FileName: String): Boolean; function g_PlayerModel_GetNames(): SSArray; -function g_PlayerModel_GetInfo(ModelName: String): TModelInfo; function g_PlayerModel_GetBlood(ModelName: String): TModelBlood; function g_PlayerModel_Get(ModelName: String): TPlayerModel; function g_PlayerModel_GetAnim(ModelName: String; AnimTyp: Byte; var _Anim, _Mask: TAnimation): Boolean; function g_PlayerModel_GetGibs(ModelName: String; var Gibs: TGibsArray): Boolean; +function g_PlayerModel_GetIndex (ModelName: String): Integer; + (* --- private data --- *) type TPlayerModelInfo = record - Info: TModelInfo; + Name: String; + Author: String; + Description: String; + HaveWeapon: Boolean; ModelSpeed: Array [A_STAND..A_PAIN] of Byte; FlagPoint: TDFPoint; FlagAngle: SmallInt; @@ -202,6 +199,20 @@ const WeapNames: Array [WP_FIRST + 1..WP_LAST] of String = ('csaw', 'hgun', 'sg', 'ssg', 'mgun', 'rkt', 'plz', 'bfg', 'spl', 'flm'); + function g_PlayerModel_GetIndex (ModelName: String): Integer; + var i: Integer; + begin + Result := -1; + if PlayerModelsArray <> nil then + begin + i := 0; + while (i < Length(PlayerModelsArray)) and (PlayerModelsArray[i].Name <> ModelName) do + Inc(i); + if i < Length(PlayerModelsArray) then + Result := i + end + end; + function GetPoint(var str: String; var point: TDFPoint): Boolean; var a, x, y: Integer; @@ -401,13 +412,9 @@ begin prefix := FileName+':TEXTURES\'; - with PlayerModelsArray[ID].Info do - begin - Name := s; - Author := config.ReadStr('Model', 'author', ''); - Description := config.ReadStr('Model', 'description', ''); - end; - + PlayerModelsArray[ID].Name := s; + PlayerModelsArray[ID].Author := config.ReadStr('Model', 'author', ''); + PlayerModelsArray[ID].Description := config.ReadStr('Model', 'description', ''); PlayerModelsArray[ID].FileName := FileName; with PlayerModelsArray[ID] do begin @@ -614,7 +621,7 @@ begin end; {if ok then g_Console_Add(Info.Name+' weapon points ok') else g_Console_Add(Info.Name+' weapon points fail');} - Info.HaveWeapon := ok; + PlayerModelsArray[ID].HaveWeapon := ok; s := config.ReadStr('Model', 'flag_point', ''); if not GetPoint(s, FlagPoint) then @@ -629,7 +636,7 @@ begin Result := True; end; -function g_PlayerModel_Get(ModelName: String): TPlayerModel; +function g_PlayerModel_Get (ModelName: String): TPlayerModel; var a: Integer; begin Result := nil; @@ -638,7 +645,7 @@ begin for a := 0 to High(PlayerModelsArray) do begin - if AnsiLowerCase(PlayerModelsArray[a].Info.Name) = AnsiLowerCase(ModelName) then + if AnsiLowerCase(PlayerModelsArray[a].Name) = AnsiLowerCase(ModelName) then begin Result := TPlayerModel.Create; @@ -662,19 +669,20 @@ begin if PlayerModelsArray = nil then Exit; for a := 0 to High(PlayerModelsArray) do - if PlayerModelsArray[a].Info.Name = ModelName then + if PlayerModelsArray[a].Name = ModelName then with PlayerModelsArray[a] do begin if AnimTyp in [A_STAND, A_WALK] then c := True else c := False; - if not g_Frames_Get(ID, Info.Name+'_RIGHTANIM'+IntToStr(AnimTyp)) then - if not g_Frames_Get(ID, Info.Name+'_LEFTANIM'+IntToStr(AnimTyp)) then Exit; + if not g_Frames_Get(ID, Name + '_RIGHTANIM' + IntToStr(AnimTyp)) then + if not g_Frames_Get(ID, Name + '_LEFTANIM' + IntToStr(AnimTyp)) then Exit; _Anim := TAnimation.Create(ID, c, ModelSpeed[AnimTyp]); _Anim.Speed := ModelSpeed[AnimTyp]; - if not g_Frames_Get(ID, Info.Name+'_RIGHTANIM'+IntToStr(AnimTyp)+'_MASK') then - if not g_Frames_Get(ID, Info.Name+'_LEFTANIM'+IntToStr(AnimTyp)+'_MASK') then Exit; + if not g_Frames_Get(ID, Name + '_RIGHTANIM' + IntToStr(AnimTyp) + '_MASK') then + if not g_Frames_Get(ID, Name + '_LEFTANIM' + IntToStr(AnimTyp) + '_MASK') then + Exit; _Mask := TAnimation.Create(ID, c, ModelSpeed[AnimTyp]); _Mask.Speed := ModelSpeed[AnimTyp]; @@ -700,7 +708,7 @@ begin SetLength(Gibs, gGibsCount); for a := 0 to High(PlayerModelsArray) do - if PlayerModelsArray[a].Info.Name = ModelName then + if PlayerModelsArray[a].Name = ModelName then begin for i := 0 to High(Gibs) do begin @@ -735,25 +743,10 @@ begin for i := 0 to High(PlayerModelsArray) do begin SetLength(Result, Length(Result)+1); - Result[High(Result)] := PlayerModelsArray[i].Info.Name; + Result[High(Result)] := PlayerModelsArray[i].Name; end; end; -function g_PlayerModel_GetInfo(ModelName: string): TModelInfo; -var - a: Integer; -begin - FillChar(Result, SizeOf(Result), 0); - if PlayerModelsArray = nil then Exit; - - for a := 0 to High(PlayerModelsArray) do - if PlayerModelsArray[a].Info.Name = ModelName then - begin - Result := PlayerModelsArray[a].Info; - Break; - end; -end; - function g_PlayerModel_GetBlood(ModelName: string): TModelBlood; var a: Integer; @@ -765,7 +758,7 @@ begin if PlayerModelsArray = nil then Exit; for a := 0 to High(PlayerModelsArray) do - if PlayerModelsArray[a].Info.Name = ModelName then + if PlayerModelsArray[a].Name = ModelName then begin Result := PlayerModelsArray[a].Blood; Break; @@ -905,7 +898,7 @@ end; function TPlayerModel.GetName (): String; begin - Result := PlayerModelsArray[FID].Info.Name + Result := PlayerModelsArray[FID].Name end; procedure TPlayerModel.Update; diff --git a/src/game/opengl/r_playermodel.pas b/src/game/opengl/r_playermodel.pas index 0914bd0..f17be32 100644 --- a/src/game/opengl/r_playermodel.pas +++ b/src/game/opengl/r_playermodel.pas @@ -119,7 +119,7 @@ implementation prefix := PlayerModelsArray[i].FileName + ':TEXTURES\'; for b := A_STAND to A_LAST do begin - aname := PlayerModelsArray[i].Info.Name + '_RIGHTANIM' + IntToStr(b); + aname := PlayerModelsArray[i].Name + '_RIGHTANIM' + IntToStr(b); with PlayerModelsArray[i].Anim[TDirection.D_RIGHT, b] do begin if not (g_Frames_CreateWAD(@ID1, aname, prefix + Resource, 64, 64, Frames, Back) and @@ -127,7 +127,7 @@ implementation begin if b > A_LASTBASE then begin - ExtAnimFromBaseAnim(PlayerModelsArray[i].Info.Name, b); + ExtAnimFromBaseAnim(PlayerModelsArray[i].Name, b); continue end end; @@ -138,7 +138,7 @@ implementation begin if (Resource <> '') and (Mask <> '') then begin - aname := PlayerModelsArray[i].Info.Name + '_LEFTANIM' + IntToStr(b); + aname := PlayerModelsArray[i].Name + '_LEFTANIM' + IntToStr(b); g_Frames_CreateWAD(@ID1, aname, prefix + Resource, 64, 64, Frames, Back); g_Frames_CreateWAD(@ID2, aname + '_MASK', prefix + Mask, 64, 64, Frames, Back); Models[i].Frames[TDirection.D_LEFT, b].base := ID1; @@ -162,10 +162,10 @@ implementation begin for a := A_STAND to A_LAST do begin - g_Frames_DeleteByName(Info.Name+'_LEFTANIM'+IntToStr(a)); - g_Frames_DeleteByName(Info.Name+'_LEFTANIM'+IntToStr(a)+'_MASK'); - g_Frames_DeleteByName(Info.Name+'_RIGHTANIM'+IntToStr(a)); - g_Frames_DeleteByName(Info.Name+'_RIGHTANIM'+IntToStr(a)+'_MASK'); + g_Frames_DeleteByName(Name + '_LEFTANIM' + IntToStr(a)); + g_Frames_DeleteByName(Name + '_LEFTANIM' + IntToStr(a) + '_MASK'); + g_Frames_DeleteByName(Name + '_RIGHTANIM' + IntToStr(a)); + g_Frames_DeleteByName(Name + '_RIGHTANIM' + IntToStr(a) + '_MASK'); end; if Gibs <> nil then begin @@ -232,7 +232,7 @@ begin else Mirror := TMirrorType.Horizontal; - if PlayerModelsArray[pm.id].Info.HaveWeapon and (not (pm.CurrentAnimation in [A_DIE1, A_DIE2, A_PAIN])) and (pm.CurrentWeapon in [WP_FIRST + 1..WP_LAST]) then + if PlayerModelsArray[pm.id].HaveWeapon and (not (pm.CurrentAnimation in [A_DIE1, A_DIE2, A_PAIN])) and (pm.CurrentWeapon in [WP_FIRST + 1..WP_LAST]) then begin if pm.CurrentAnimation in [A_SEEUP, A_ATTACKUP] then pos := W_POS_UP -- 2.29.2