summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d807a4f)
raw | patch | inline | side by side (parent: d807a4f)
author | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Sat, 2 Sep 2017 21:03:18 +0000 (00:03 +0300) | ||
committer | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Sat, 2 Sep 2017 21:03:46 +0000 (00:03 +0300) |
diff --git a/src/game/g_gfx.pas b/src/game/g_gfx.pas
index 47c638c8e3bf79d92738398d24e1719f936549c7..e49a72cdaf286758c9a048d96a40b7e26259f3bd 100644 (file)
--- a/src/game/g_gfx.pas
+++ b/src/game/g_gfx.pas
begin
pan := g_Map_PanelAtPoint(x, y, GridTagObstacle);
end;
+ if (pan <> nil) then continue;
env := TEnvType.EAir;
// color
diff --git a/src/game/g_gui.pas b/src/game/g_gui.pas
index d7735ab374d568a4e51cf47c543f1a2c458d7522..4f4a2c3b07f86eeb542b8383e6a6e2a4099ff703 100644 (file)
--- a/src/game/g_gui.pas
+++ b/src/game/g_gui.pas
try
map := g_Map_ParseMap(Data, Len);
except
+ FreeMem(Data);
map.Free();
- raise;
+ //raise;
+ exit;
end;
FreeMem(Data);
- panlist := map.field['panel'];
- //header := GetMapHeader(map);
+ try
+ panlist := map.field['panel'];
+ //header := GetMapHeader(map);
- FMapSize.X := map.Width div 16;
- FMapSize.Y := map.Height div 16;
+ FMapSize.X := map.Width div 16;
+ FMapSize.Y := map.Height div 16;
- rX := Ceil(map.Width / (MAPPREVIEW_WIDTH*256.0));
- rY := Ceil(map.Height / (MAPPREVIEW_HEIGHT*256.0));
- FScale := max(rX, rY);
+ rX := Ceil(map.Width / (MAPPREVIEW_WIDTH*256.0));
+ rY := Ceil(map.Height / (MAPPREVIEW_HEIGHT*256.0));
+ FScale := max(rX, rY);
- FMapData := nil;
+ FMapData := nil;
- if (panlist <> nil) then
- begin
- for pan in panlist do
+ if (panlist <> nil) then
begin
- if (pan.PanelType and (PANEL_WALL or PANEL_CLOSEDOOR or
- PANEL_STEP or PANEL_WATER or
- PANEL_ACID1 or PANEL_ACID2)) <> 0 then
+ for pan in panlist do
begin
- SetLength(FMapData, Length(FMapData)+1);
- with FMapData[High(FMapData)] do
+ if (pan.PanelType and (PANEL_WALL or PANEL_CLOSEDOOR or
+ PANEL_STEP or PANEL_WATER or
+ PANEL_ACID1 or PANEL_ACID2)) <> 0 then
begin
- X1 := pan.X div 16;
- Y1 := pan.Y div 16;
+ SetLength(FMapData, Length(FMapData)+1);
+ with FMapData[High(FMapData)] do
+ begin
+ X1 := pan.X div 16;
+ Y1 := pan.Y div 16;
- X2 := (pan.X + pan.Width) div 16;
- Y2 := (pan.Y + pan.Height) div 16;
+ X2 := (pan.X + pan.Width) div 16;
+ Y2 := (pan.Y + pan.Height) div 16;
- X1 := Trunc(X1/FScale + 0.5);
- Y1 := Trunc(Y1/FScale + 0.5);
- X2 := Trunc(X2/FScale + 0.5);
- Y2 := Trunc(Y2/FScale + 0.5);
+ X1 := Trunc(X1/FScale + 0.5);
+ Y1 := Trunc(Y1/FScale + 0.5);
+ X2 := Trunc(X2/FScale + 0.5);
+ Y2 := Trunc(Y2/FScale + 0.5);
- if (X1 <> X2) or (Y1 <> Y2) then
- begin
- if X1 = X2 then
- X2 := X2 + 1;
- if Y1 = Y2 then
- Y2 := Y2 + 1;
- end;
+ if (X1 <> X2) or (Y1 <> Y2) then
+ begin
+ if X1 = X2 then
+ X2 := X2 + 1;
+ if Y1 = Y2 then
+ Y2 := Y2 + 1;
+ end;
- PanelType := pan.PanelType;
+ PanelType := pan.PanelType;
+ end;
end;
end;
end;
+ finally
+ //writeln('freeing map');
+ map.Free();
end;
-
- map.Free();
end;
procedure TGUIMapPreview.ClearMap();
diff --git a/src/game/g_map.pas b/src/game/g_map.pas
index 395a2ccbc4320a256545a286de9b34bb5e8e3137..ae8ee105f42f3bc783b26d62a6ec4ac7ff08d70f 100644 (file)
--- a/src/game/g_map.pas
+++ b/src/game/g_map.pas
@@ -273,6 +273,7 @@ function g_Map_MaxY (): Integer; inline; begin if (mapGrid <> nil) then result :
var
dfmapdef: TDynMapDef = nil;
+
procedure loadMapDefinition ();
var
pr: TTextParser = nil;
WAD: TWADFile = nil;
begin
if (dfmapdef <> nil) then exit;
+
try
e_LogWritefln('parsing "mapdef.txt"...', []);
st := openDiskFileRO(DataDir+'mapdef.txt');
+ e_LogWritefln('found local "%smapdef.txt"', [DataDir]);
except
st := nil;
- e_LogWritefln('local "%smapdef.txt" not found', [DataDir]);
end;
+
if (st = nil) then
begin
WAD := TWADFile.Create();
end;
end;
- if (st = nil) then
- begin
- //raise Exception.Create('cannot open "mapdef.txt"');
- e_LogWritefln('using default "mapdef.txt"...', [], MSG_WARNING);
- pr := TStrTextParser.Create(defaultMapDef);
- end
- else
- begin
- pr := TFileTextParser.Create(st);
+ try
+ if (st = nil) then
+ begin
+ //raise Exception.Create('cannot open "mapdef.txt"');
+ e_LogWriteln('using default "mapdef.txt"...');
+ pr := TStrTextParser.Create(defaultMapDef);
+ end
+ else
+ begin
+ pr := TFileTextParser.Create(st);
+ end;
+ except on e: Exception do
+ begin
+ e_LogWritefln('something is VERY wrong here! -- ', [e.message]);
+ raise;
+ end;
end;
try
begin
result := nil;
if (dataLen < 4) then exit;
+
+ if (dfmapdef = nil) then writeln('need to load mapdef');
loadMapDefinition();
if (dfmapdef = nil) then raise Exception.Create('internal map loader error');
begin
// binary map
try
+ //e_LogWriteln('parsing binary map...');
result := dfmapdef.parseBinMap(wst);
except on e: Exception do
begin
// text map
pr := TFileTextParser.Create(wst);
try
+ //e_LogWriteln('parsing text map...');
result := dfmapdef.parseMap(pr);
except on e: Exception do
begin
end;
pr.Free(); // will free `wst`
end;
+ //e_LogWriteln('map parsed.');
end;
end
else
begin
- trigData := Trigger.trigRec.clone();
+ trigData := Trigger.trigRec.clone(nil);
end;
end;
mapReader := g_Map_ParseMap(Data, Len);
except
mapReader := nil;
+ FreeMem(Data);
+ exit;
end;
FreeMem(Data);
index 53b023b995235d07dd989df3f91d4d4b311ef25d..1c8a586126ee9f15517ffba8d288b0245aa7254b 100644 (file)
--- a/src/game/g_triggers.pas
+++ b/src/game/g_triggers.pas
Trigger.mapIndex := mapidx;
if (Trigger.trigData.trigRec <> nil) then
begin
- Trigger.trigData := Trigger.trigData.trigRec.clone();
+ Trigger.trigData := Trigger.trigData.trigRec.clone({Trigger.trigData.headerRec}nil);
end
else
begin
diff --git a/src/shared/xdynrec.pas b/src/shared/xdynrec.pas
index c71250ce9ee8bc4697133ee8960465739b57f537..e1bd571235d2ba9be15abe8d1e8e1480df4d22a6 100644 (file)
--- a/src/shared/xdynrec.pas
+++ b/src/shared/xdynrec.pas
function definition (): AnsiString;
function pasdef (): AnsiString;
- function clone (newOwner: TDynRecord=nil): TDynField;
+ function clone (newOwner: TDynRecord=nil; registerIn: TDynRecord=nil): TDynField;
procedure parseValue (pr: TTextParser);
procedure parseBinValue (st: TStream);
mTagInt: Integer;
mTagPtr: Pointer;
+ mRec2Free: TDynRecList;
+
private
procedure parseDef (pr: TTextParser); // parse definition
function getForTrigCount (): Integer; inline;
function getForTrigAt (idx: Integer): AnsiString; inline;
+ procedure regrec (rec: TDynRecord);
+
protected
function findRecordByTypeId (const atypename, aid: AnsiString): TDynRecord;
function findRecordNumByType (const atypename: AnsiString; rc: TDynRecord): Integer;
function definition (): AnsiString;
function pasdef (): AnsiString;
- function clone (): TDynRecord;
+ function clone (registerIn: TDynRecord): TDynRecord;
function isSimpleEqu (rec: TDynRecord): Boolean;
end;
-function TDynField.clone (newOwner: TDynRecord=nil): TDynField;
+function TDynField.clone (newOwner: TDynRecord=nil; registerIn: TDynRecord=nil): TDynField;
var
rec: TDynRecord;
begin
begin
if (result.mRVal = nil) then result.mRVal := TDynRecList.Create(mRVal.count);
if (result.mRHash = nil) then result.mRHash := hashNewStrInt();
- for rec in mRVal do result.addListItem(rec.clone());
+ for rec in mRVal do result.addListItem(rec.clone(registerIn));
end;
result.mRecRef := mRecRef;
result.mMaxDim := mMaxDim;
if (tfld = nil) then raise Exception.Create(Format('triggerdata value for field ''%s'' in record ''%s'' without TriggerType field', [mName, rec.mName]));
rc := mOwner.mOwner.findTrigFor(tfld.mSVal); // find in mapdef
if (rc = nil) then raise Exception.Create(Format('triggerdata definition for field ''%s'' in record ''%s'' with type ''%s'' not found', [mName, rec.mName, tfld.mSVal]));
- rc := rc.clone();
+ rc := rc.clone(mOwner.mHeaderRec);
rc.mHeaderRec := mOwner.mHeaderRec;
try
rc.parseBinValue(st, true);
if (tfld = nil) then raise Exception.Create(Format('triggerdata value for field ''%s'' in record ''%s'' without ''type'' field', [mName, rec.mName]));
rc := mOwner.mOwner.findTrigFor(tfld.mSVal); // find in mapdef
if (rc = nil) then raise Exception.Create(Format('triggerdata definition for field ''%s'' in record ''%s'' with type ''%s'' not found', [mName, rec.mName, tfld.mSVal]));
- rc := rc.clone();
+ rc := rc.clone(mOwner.mHeaderRec);
rc.mHeaderRec := mOwner.mHeaderRec;
//writeln(rc.definition);
try
rec := nil;
if (mEBSType <> nil) and (mEBSType is TDynRecord) then rec := (mEBSType as TDynRecord);
if (rec = nil) then raise Exception.Create(Format('record type ''%s'' for field ''%s'' not found', [mEBSTypeName, mName]));
- rc := rec.clone();
+ rc := rec.clone(mOwner.mHeaderRec);
rc.mHeaderRec := mOwner.mHeaderRec;
rc.parseValue(pr);
mRecRef := rc;
mHeaderRec := nil;
mTagInt := 0;
mTagPtr := nil;
+ mRec2Free := nil;
end;
destructor TDynRecord.Destroy ();
+var
+ fld: TDynField;
+ rec: TDynRecord;
begin
+ if (mRec2Free <> nil) then
+ begin
+ for rec in mRec2Free do if (rec <> self) then rec.Free();
+ mRec2Free.Free();
+ mRec2Free := nil;
+ end;
mName := '';
+ for fld in mFields do fld.Free();
mFields.Free();
mFields := nil;
{$IF DEFINED(XDYNREC_USE_FIELDHASH)}
end;
+procedure TDynRecord.regrec (rec: TDynRecord);
+begin
+ if (rec <> nil) and (rec <> self) then
+ begin
+ if (mRec2Free = nil) then mRec2Free := TDynRecList.Create();
+ mRec2Free.append(rec);
+ end;
+end;
+
+
procedure TDynRecord.addField (fld: TDynField); inline;
begin
if (fld = nil) then raise Exception.Create('cannot append nil field to record');
end;
-function TDynRecord.clone (): TDynRecord;
+function TDynRecord.clone (registerIn: TDynRecord): TDynRecord;
var
fld: TDynField;
f: Integer;
result.mPasName := mPasName;
result.mName := mName;
result.mSize := mSize;
+ result.mHeader := mHeader;
+ result.mBinBlock := mBinBlock;
+ result.mHeaderRec := mHeaderRec;
+ result.mTagInt := mTagInt;
+ result.mTagPtr := mTagPtr;
if (mFields.count > 0) then
begin
result.mFields.capacity := mFields.count;
- for fld in mFields do result.addField(fld.clone(result));
+ for fld in mFields do result.addField(fld.clone(result, registerIn));
end;
SetLength(result.mTrigTypes, Length(mTrigTypes));
for f := 0 to High(mTrigTypes) do result.mTrigTypes[f] := mTrigTypes[f];
- result.mHeader := mHeader;
- result.mBinBlock := mBinBlock;
- result.mHeaderRec := mHeaderRec;
- result.mTagInt := mTagInt;
- result.mTagPtr := mTagPtr;
+ if (registerIn <> nil) then registerIn.regrec(result);
end;
end;
-{
-procedure TDynRecord.setUserField (const fldname: AnsiString; v: LongInt);
-var
- fld: TDynField;
-begin
- if (Length(fldname) = 0) then exit;
- fld := field[fldname];
- if (fld <> nil) then
- begin
- if (fld.mType <> fld.TType.TInt) or (fld.mEBS <> fld.TEBS.TNone) then
- begin
- raise Exception.Create(Format('invalid user field ''%s'' type', [fld.name]));
- end;
- end
- else
- begin
- fld := TDynField.Create(fldname, fld.TType.TInt);
- fld.mOwner := self;
- fld.mIVal := v;
- fld.mInternal := true;
- fld.mDefined := true;
- addField(fld);
- end;
-end;
-
-
-procedure TDynRecord.setUserField (const fldname: AnsiString; v: AnsiString);
-var
- fld: TDynField;
-begin
- if (Length(fldname) = 0) then exit;
- fld := field[fldname];
- if (fld <> nil) then
- begin
- if (fld.mType <> fld.TType.TString) or (fld.mEBS <> fld.TEBS.TNone) then
- begin
- raise Exception.Create(Format('invalid user field ''%s'' type', [fld.name]));
- end;
- end
- else
- begin
- fld := TDynField.Create(fldname, fld.TType.TString);
- fld.mOwner := self;
- fld.mSVal := v;
- fld.mInternal := true;
- fld.mDefined := true;
- addField(fld);
- end;
-end;
-
-
-procedure TDynRecord.setUserField (const fldname: AnsiString; v: Boolean);
-var
- fld: TDynField;
-begin
- if (Length(fldname) = 0) then exit;
- fld := field[fldname];
- if (fld <> nil) then
- begin
- if (fld.mType <> fld.TType.TBool) or (fld.mEBS <> fld.TEBS.TNone) then
- begin
- raise Exception.Create(Format('invalid user field ''%s'' type', [fld.name]));
- end;
- end
- else
- begin
- fld := TDynField.Create(fldname, fld.TType.TBool);
- fld.mOwner := self;
- fld.mIVal := Integer(v);
- fld.mInternal := true;
- fld.mDefined := true;
- addField(fld);
- end;
-end;
-}
-
-
procedure TDynRecord.parseDef (pr: TTextParser);
var
fld: TDynField;
for f := 0 to (bsize div rec.mSize)-1 do
begin
mst.setup(buf+f*rec.mSize, rec.mSize);
- rec := rect.clone();
+ rec := rect.clone(self);
rec.mHeaderRec := self;
rec.parseBinValue(mst);
rec.mId := Format('%s%d', [rec.mName, f]);
if (trc <> nil) then
begin
{$IF DEFINED(D2D_DYNREC_PROFILER)}stt := curTimeMicro();{$ENDIF}
- rec := trc.clone();
+ rec := trc.clone(mHeaderRec);
{$IF DEFINED(D2D_DYNREC_PROFILER)}profCloneRec := curTimeMicro()-stt;{$ENDIF}
rec.mHeaderRec := mHeaderRec;
try
result := nil;
try
pr.expectId(headerType.name);
- res := headerType.clone();
+ res := headerType.clone(nil);
res.mHeaderRec := res;
res.parseValue(pr);
result := res;
begin
result := nil;
try
- res := headerType.clone();
+ res := headerType.clone(nil);
res.mHeaderRec := res;
res.parseBinValue(st);
result := res;