From b1cfdccaae88aed021b3d82532cdc6ef7046fda3 Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Thu, 7 Sep 2017 07:56:51 +0300 Subject: [PATCH] simplified trigger loading code --- src/game/g_map.pas | 87 ++++++++++++----------------------------- src/game/g_triggers.pas | 12 ++---- src/shared/MAPDEF.pas | 54 +++++++++++++++++++------ 3 files changed, 72 insertions(+), 81 deletions(-) diff --git a/src/game/g_map.pas b/src/game/g_map.pas index e976be4..d18aece 100644 --- a/src/game/g_map.pas +++ b/src/game/g_map.pas @@ -1600,17 +1600,13 @@ type //TexturePanel: Integer; tnum: Integer; id: Integer; - texPanIdx: Integer; - LiftPanelIdx: Integer; - DoorPanelIdx: Integer; - ShotPanelIdx: Integer; - MPlatPanelIdx: Integer; trigrec: TDynRecord; - texPan: TDynRecord; - liftPan: TDynRecord; - doorPan: TDynRecord; - shotPan: TDynRecord; - mplatPan: TDynRecord; + // texture pane; + texPanelIdx: Integer; + texPanel: TDynRecord; + // "action" panel + actPanelIdx: Integer; + actPanel: TDynRecord; end; var WAD: TWADFile; @@ -1807,49 +1803,23 @@ begin //SetLength(TriggersTable, triggers.count); g_Game_SetLoadingText(_lc[I_LOAD_TRIGGERS_TABLE], triggers.count-1, False); + SetLength(TriggersTable, triggers.count); + trignum := -1; for rec in triggers do begin - SetLength(TriggersTable, Length(TriggersTable)+1); - pttit := @TriggersTable[High(TriggersTable)]; + Inc(trignum); + pttit := @TriggersTable[trignum]; pttit.trigrec := rec; // Ñìåíà òåêñòóðû (âîçìîæíî, êíîïêè) - pttit.texPan := mapReader.panel[rec.TexturePanel]; - pttit.liftPan := nil; - pttit.doorPan := nil; - pttit.shotPan := nil; - pttit.mplatPan := nil; - pttit.texPanIdx := -1; - pttit.LiftPanelIdx := -1; - pttit.DoorPanelIdx := -1; - pttit.ShotPanelIdx := -1; - pttit.MPlatPanelIdx := -1; - // Ëèôòû - if rec.TriggerType in [TRIGGER_LIFTUP, TRIGGER_LIFTDOWN, TRIGGER_LIFT] then - begin - pttit.liftPan := mapReader.panel[rec.trigRec.tgPanelID]; - end; - // Äâåðè - if rec.TriggerType in [TRIGGER_OPENDOOR, TRIGGER_CLOSEDOOR, TRIGGER_DOOR, TRIGGER_DOOR5, TRIGGER_CLOSETRAP, TRIGGER_TRAP] then - begin - pttit.doorPan := mapReader.panel[rec.trigRec.tgPanelID]; - end; - // Òóðåëü - if (rec.TriggerType = TRIGGER_SHOT) then - begin - pttit.shotPan := mapReader.panel[rec.trigRec.tgShotPanelID]; - end; - // - if rec.TriggerType in [TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF] then - begin - pttit.mplatPan := mapReader.panel[rec.trigRec.tgPanelID]; - end; - - if (pttit.texPan <> nil) then pttit.texPan.userPanelTrigRef := true; - if (pttit.liftPan <> nil) then pttit.liftPan.userPanelTrigRef := true; - if (pttit.doorPan <> nil) then pttit.doorPan.userPanelTrigRef := true; - if (pttit.shotPan <> nil) then pttit.shotPan.userPanelTrigRef := true; - if (pttit.mplatPan <> nil) then pttit.mplatPan.userPanelTrigRef := true; - + pttit.texPanelIdx := -1; // will be fixed later + pttit.texPanel := rec.TexturePanelRec; + // action panel + pttit.actPanelIdx := -1; + if (rec.trigRec <> nil) then pttit.actPanel := rec.trigRec.tgPanelRec else pttit.actPanel := nil; + // set flag + if (pttit.texPanel <> nil) then pttit.texPanel.userPanelTrigRef := true; + if (pttit.actPanel <> nil) then pttit.actPanel.userPanelTrigRef := true; + // update progress g_Game_StepLoading(); end; end; @@ -2038,11 +2008,8 @@ begin // ×èíèì ID'û ïàíåëåé, êîòîðûå èñïîëüçóþòñÿ â òðèããåðàõ for b := 0 to High(TriggersTable) do begin - if (TriggersTable[b].texPan <> nil) then TriggersTable[b].texPanIdx := TriggersTable[b].texPan.userPanelId; - if (TriggersTable[b].liftPan <> nil) then TriggersTable[b].LiftPanelIdx := TriggersTable[b].liftPan.userPanelId; - if (TriggersTable[b].doorPan <> nil) then TriggersTable[b].DoorPanelIdx := TriggersTable[b].doorPan.userPanelId; - if (TriggersTable[b].shotPan <> nil) then TriggersTable[b].ShotPanelIdx := TriggersTable[b].shotPan.userPanelId; - if (TriggersTable[b].mplatPan <> nil) then TriggersTable[b].MPlatPanelIdx := TriggersTable[b].mplatPan.userPanelId; + if (TriggersTable[b].texPanel <> nil) then TriggersTable[b].texPanelIdx := TriggersTable[b].texPanel.userPanelId; + if (TriggersTable[b].actPanel <> nil) then TriggersTable[b].actPanelIdx := TriggersTable[b].actPanel.userPanelId; end; // create map grid, init other grids (for monsters, for example) @@ -2059,17 +2026,13 @@ begin for rec in triggers do begin Inc(trignum); - if (TriggersTable[trignum].texPan <> nil) then b := TriggersTable[trignum].texPan.PanelType else b := 0; - if (TriggersTable[trignum].shotPan <> nil) then c := TriggersTable[trignum].shotPan.PanelType else c := 0; + if (TriggersTable[trignum].texPanel <> nil) then b := TriggersTable[trignum].texPanel.PanelType else b := 0; + if (TriggersTable[trignum].actPanel <> nil) then c := TriggersTable[trignum].actPanel.PanelType else c := 0; // we can have only one of those - if (TriggersTable[trignum].LiftPanelIdx <> -1) then tgpid := TriggersTable[trignum].LiftPanelIdx - else if (TriggersTable[trignum].DoorPanelIdx <> -1) then tgpid := TriggersTable[trignum].DoorPanelIdx - else if (TriggersTable[trignum].ShotPanelIdx <> -1) then tgpid := TriggersTable[trignum].ShotPanelIdx - else if (TriggersTable[trignum].MPlatPanelIdx <> -1) then tgpid := TriggersTable[trignum].MPlatPanelIdx - else tgpid := -1; + tgpid := TriggersTable[trignum].actPanelIdx; //e_LogWritefln('creating trigger #%s; texpantype=%s; shotpantype=%s (%d,%d)', [trignum, b, c, TriggersTable[trignum].texPanIdx, TriggersTable[trignum].ShotPanelIdx]); TriggersTable[trignum].tnum := trignum; - TriggersTable[trignum].id := CreateTrigger(trignum, rec, TriggersTable[trignum].texPanIdx, tgpid, Word(b), Word(c)); + TriggersTable[trignum].id := CreateTrigger(trignum, rec, TriggersTable[trignum].texPanelIdx, tgpid, Word(b), Word(c)); end; end; diff --git a/src/game/g_triggers.pas b/src/game/g_triggers.pas index 88e5134..fab30ec 100644 --- a/src/game/g_triggers.pas +++ b/src/game/g_triggers.pas @@ -66,16 +66,12 @@ type mapIndex: Integer; // index in fields['trigger'], used in save/load trigPanelGUID: Integer; - //TrigData: TTriggerData; - trigDataRec: TDynRecord; // triggerdata; owned by trigger + trigDataRec: TDynRecord; // triggerdata; owned by trigger (cloned) {$INCLUDE ../shared/mapdef_tgc_def.inc} public function trigCenter (): TDFPoint; inline; - - public - property trigShotPanelGUID: Integer read trigPanelGUID write trigPanelGUID; end; function g_Triggers_Create(Trigger: TTrigger; forceInternalIndex: Integer=-1): DWORD; @@ -692,9 +688,9 @@ begin begin if (tgcAmmo = 0) or ((tgcAmmo > 0) and (ShotAmmoCount > 0)) then begin - if (trigShotPanelGUID <> -1) and (ShotPanelTime = 0) then + if (trigPanelGUID <> -1) and (ShotPanelTime = 0) then begin - g_Map_SwitchTextureGUID(ShotPanelType, trigShotPanelGUID); + g_Map_SwitchTextureGUID(ShotPanelType, trigPanelGUID); ShotPanelTime := 4; // òèêîâ íà âñïûøêó âûñòðåëà end; @@ -2395,7 +2391,7 @@ begin if ShotPanelTime > 0 then begin Dec(ShotPanelTime); - if ShotPanelTime = 0 then g_Map_SwitchTextureGUID(ShotPanelType, trigShotPanelGUID); + if ShotPanelTime = 0 then g_Map_SwitchTextureGUID(ShotPanelType, trigPanelGUID); end; if ShotSightTime > 0 then begin diff --git a/src/shared/MAPDEF.pas b/src/shared/MAPDEF.pas index 9875fa1..53bedb7 100644 --- a/src/shared/MAPDEF.pas +++ b/src/shared/MAPDEF.pas @@ -72,11 +72,8 @@ type function getPanelByIdx (idx: Integer): TDynRecord; inline; - //function getPanelId (): Integer; inline; - //procedure setPanelId (v: Integer); inline; - function getTexturePanel (): Integer; inline; - //procedure setTexturePanel (v: Integer); inline; + function getTexturePanelRec (): TDynRecord; inline; function getPanelIndex (pan: TDynRecord): Integer; @@ -143,6 +140,7 @@ type {$INCLUDE mapdef_help.inc} function trigMonsterId (): Integer; inline; function trigPanelId (): Integer; inline; // panel index in list + function trigPanelRec (): TDynRecord; inline; private // user fields @@ -156,9 +154,10 @@ type property panel[idx: Integer]: TDynRecord read getPanelByIdx; property panelIndex[pan: TDynRecord]: Integer read getPanelIndex; // triggers - property tgPanelID: Integer read trigPanelId {write setPanelId}; - property tgShotPanelID: Integer read trigPanelId {write setPanelId}; - property TexturePanel: Integer read getTexturePanel {write setTexturePanel}; // texturepanel, int + property tgPanelId: Integer read trigPanelId; + property tgPanelRec: TDynRecord read trigPanelRec; + property TexturePanelId: Integer read getTexturePanel; // texturepanel, int + property TexturePanelRec: TDynRecord read getTexturePanelRec; // user fields property userPanelId: Integer read getUserPanelId write setUserPanelId; property userPanelTrigRef: Boolean read getUserTrigRef write setUserTrigRef; @@ -328,7 +327,6 @@ begin if (fld <> nil) then result := fld.recref else result := nil; end; - function TDynRecordHelper.trigMonsterId (): Integer; inline; var fld: TDynField; @@ -341,6 +339,17 @@ begin result := fld.recrefIndex; end; +function TDynRecordHelper.trigPanelRec (): TDynRecord; inline; +var + fld: TDynField; +begin + result := nil; + fld := field['panelid']; + if (fld = nil) then exit; + if (fld.baseType <> TDynField.TType.TInt) then exit; + result := fld.recref; + if (result <> nil) and (result.typeName <> 'panel') then result := nil; +end; // panel index in list function TDynRecordHelper.trigPanelId (): Integer; inline; @@ -352,6 +361,32 @@ begin if (fld = nil) then exit; if (fld.baseType <> TDynField.TType.TInt) then exit; if (fld.recref = nil) then exit; + if (fld.recref.typeName <> 'panel') then exit; + result := fld.recrefIndex; +end; + +function TDynRecordHelper.getTexturePanelRec (): TDynRecord; +var + fld: TDynField; +begin + result := nil; + fld := field['texture_panel']; + if (fld = nil) then exit; + if (fld.baseType <> TDynField.TType.TInt) then exit; + result := fld.recref; + if (result <> nil) and (result.typeName <> 'panel') then result := nil; +end; + +function TDynRecordHelper.getTexturePanel (): Integer; +var + fld: TDynField; +begin + result := -1; + fld := field['texture_panel']; + if (fld = nil) then exit; + if (fld.baseType <> TDynField.TType.TInt) then exit; + if (fld.recref = nil) then exit; + if (fld.recref.typeName <> 'panel') then exit; result := fld.recrefIndex; end; @@ -382,9 +417,6 @@ function TDynRecordHelper.TriggerType (): Byte; inline; begin result := Byte(get function TDynRecordHelper.ActivateType (): Byte; inline; begin result := Byte(getFieldWithType('activate_type', TDynField.TType.TUByte).ival); end; function TDynRecordHelper.Keys (): Byte; inline; begin result := Byte(getFieldWithType('keys', TDynField.TType.TUByte).ival); end; -//function TDynRecordHelper.getPanelId (): Integer; inline; begin result := getFieldWithType('panelid', TDynField.TType.TInt).recrefIndex; end; -function TDynRecordHelper.getTexturePanel (): Integer; begin result := getFieldWithType('texture_panel', TDynField.TType.TInt).recrefIndex; end; - {$INCLUDE mapdef_impl.inc} -- 2.29.2