X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Ftools%2Fmapgen.dpr;h=c53aa4eb9ee22b74608b8e0d873f53c3d7df9db3;hb=923fa980434e55419f35422119af2faae2bf68d7;hp=32db7726c3f03d841708a271cfea9c7ec4a56377;hpb=ae4069ace642a386dd8651379dbfb0e6330d915b;p=d2df-sdl.git diff --git a/src/tools/mapgen.dpr b/src/tools/mapgen.dpr index 32db772..c53aa4e 100644 --- a/src/tools/mapgen.dpr +++ b/src/tools/mapgen.dpr @@ -1,12 +1,16 @@ {$INCLUDE ../shared/a_modes.inc} -{$APPTYPE CONSOLE} +{$IFDEF WINDOWS} + {$APPTYPE CONSOLE} +{$ENDIF} uses SysUtils, Classes, xstreams in '../shared/xstreams.pas', xparser in '../shared/xparser.pas', xdynrec in '../shared/xdynrec.pas', + xprofiler in '../shared/xprofiler.pas', utils in '../shared/utils.pas', + hashtable in '../shared/hashtable.pas', conbuf in '../shared/conbuf.pas', e_log in '../engine/e_log.pas'; @@ -15,11 +19,15 @@ uses var pr: TTextParser; dfmapdef: TDynMapDef; - fo: TextFile; + fo, fohlp, foimpl: TextFile; st: TStream = nil; ch: AnsiChar; wdt: Integer; s: AnsiString; + tidx, nidx, fidx: Integer; + needComma: Boolean; + trec: TDynRecord; + fld: TDynField; begin //writeln(getFilenamePath(ParamStr(0)), '|'); @@ -56,9 +64,156 @@ begin writeln('writing "mapdef.inc"...'); AssignFile(fo, 'mapdef.inc'); Rewrite(fo); + + AssignFile(fohlp, 'mapdef_help.inc'); + Rewrite(fohlp); + + AssignFile(foimpl, 'mapdef_impl.inc'); + Rewrite(foimpl); + write(fo, '// *** WARNING! ***'#10); write(fo, '// regenerate this part directly from "mapdef.txt" with ''mapgen'', NEVER manually change anything here!'#10#10#10); - write(fo, dfmapdef.pasdef); + write(fo, dfmapdef.pasdefconst); + + write(fohlp, '// *** WARNING! ***'#10); + write(fohlp, '// regenerate this part directly from "mapdef.txt" with ''mapgen'', NEVER manually change anything here!'#10#10); + + // generate trigger helpers +{ +function TDynRecordHelper.trigTargetPoint (): TDFPoint; inline; begin result := getPointField('target'); end; +function TDynRecordHelper.trigD2DTeleport (): Boolean; inline; begin result := (getFieldWithType('d2d', TDynField.TType.TBool).ival <> 0); end; +function TDynRecordHelper.trigSilentTeleport (): Boolean; inline; begin result := (getFieldWithType('silent', TDynField.TType.TBool).ival <> 0); end; +function TDynRecordHelper.trigTlpDir (): Byte; inline; begin result := Byte(getFieldWithType('direction', TDynField.TType.TUByte).ival); end; +} + + write(foimpl, #10#10'// ////////////////////////////////////////////////////////////////////////// //'#10); + write(foimpl, '// trigger helpers'#10); + for tidx := 0 to dfmapdef.trigTypeCount-1 do + begin + // header comment + write(foimpl, #10'// '); + needComma := false; + trec := dfmapdef.trigType[tidx]; + for nidx := 0 to trec.forTrigCount-1 do + begin + if needComma then write(foimpl, ', ') else needComma := true; + write(foimpl, trec.forTrigAt[nidx]); + end; + write(foimpl, #10); + // fields + for fidx := 0 to trec.count-1 do + begin + fld := trec.fieldAt[fidx]; + if fld.internal then continue; + if (fld.binOfs < 0) then continue; + // HACK! + if (fld.name = 'panelid') or (fld.name = 'monsterid') then + begin + writeln('skipping ', fld.pasname, ' <', fld.name, '>'); + continue; + end; + if (fld.baseType <> TDynField.TType.TPoint) and (fld.baseType <> TDynField.TType.TSize) then + begin + write(foimpl, 'function TDynRecordHelper.trig', fld.pasname, ' (): '); + write(fohlp, 'function trig', fld.pasname, ' (): '); + end; + case fld.baseType of + TDynField.TType.TBool: + begin + write(fohlp, 'Boolean; inline;'#10); + write(foimpl, 'Boolean; inline; begin result := (getFieldWithType(''', fld.name, ''', TDynField.TType.TBool).ival '); + if fld.negbool then write(foimpl, '=') else write(foimpl, '<>'); + write(foimpl, ' 0); end;'#10); + end; + TDynField.TType.TChar: + begin + write(fohlp, 'AnsiString; inline;'#10); + write(foimpl, 'AnsiString; inline; begin result := utf2win(getFieldWithType(''', fld.name, ''', TDynField.TType.TChar).sval); end;'#10); + end; + TDynField.TType.TByte: + begin + write(fohlp, 'SmallInt; inline;'#10); + write(foimpl, 'SmallInt; inline; begin result := ShortInt(getFieldWithType(''', fld.name, ''', TDynField.TType.TByte).ival); end;'#10); + end; + TDynField.TType.TUByte: + begin + write(fohlp, 'Byte; inline;'#10); + write(foimpl, 'Byte; inline; begin result := Byte(getFieldWithType(''', fld.name, ''', TDynField.TType.TUByte).ival); end;'#10); + end; + TDynField.TType.TShort: + begin + write(fohlp, 'ShortInt; inline;'#10); + write(foimpl, 'ShortInt; inline; begin result := SmallInt(getFieldWithType(''', fld.name, ''', TDynField.TType.TShort).ival); end;'#10); + end; + TDynField.TType.TUShort: + begin + write(fohlp, 'Word; inline;'#10); + write(foimpl, 'Word; inline; begin result := Word(getFieldWithType(''', fld.name, ''', TDynField.TType.TUShort).ival); end;'#10); + end; + TDynField.TType.TInt: + begin + write(fohlp, 'LongInt; inline;'#10); + write(foimpl, 'LongInt; inline; begin result := LongInt(getFieldWithType(''', fld.name, ''', TDynField.TType.TInt).ival); end;'#10); + end; + TDynField.TType.TUInt: + begin + write(fohlp, 'LongWord; inline;'#10); + write(foimpl, 'LongWord; inline; begin result := LongWord(getFieldWithType(''', fld.name, ''', TDynField.TType.TUInt).ival); end;'#10); + end; + TDynField.TType.TString: + begin + write(fohlp, 'AnsiString; inline;'#10); + write(foimpl, 'AnsiString; inline; begin result := utf2win(getFieldWithType(''', fld.name, ''', TDynField.TType.TChar).sval); end;'#10); + end; + TDynField.TType.TPoint: + begin + if fld.hasTPrefix or fld.separatePasFields then + begin + write(fohlp, 'function trig'); if fld.hasTPrefix then write(fohlp, 'T'); write(fohlp, 'X (): LongInt; inline;'#10); + write(fohlp, 'function trig'); if fld.hasTPrefix then write(fohlp, 'T'); write(fohlp, 'Y (): LongInt; inline;'#10); + // [T]X + write(foimpl, 'function TDynRecordHelper.trig'); + if fld.hasTPrefix then write(foimpl, 'T'); + write(foimpl, 'X (): LongInt; inline; begin result := LongInt(getFieldWithType(''', fld.name, ''', TDynField.TType.TPoint).ival); end;'#10); + // [T]Y + write(foimpl, 'function TDynRecordHelper.trig'); + if fld.hasTPrefix then write(foimpl, 'T'); + write(foimpl, 'Y (): LongInt; inline; begin result := LongInt(getFieldWithType(''', fld.name, ''', TDynField.TType.TPoint).ival2); end;'#10); + end + else + begin + write(fohlp, 'function trig', fld.pasname, ' (): TDFPoint; inline;'#10); + write(foimpl, 'function TDynRecordHelper.trig', fld.pasname, ' (): TDFPoint; inline; begin result := getPointField(''', fld.name, '''); end;'#10); + end; + end; + TDynField.TType.TSize: + begin + if fld.hasTPrefix or fld.separatePasFields then + begin + write(fohlp, 'function trig'); if fld.hasTPrefix then write(fohlp, 'T'); write(fohlp, 'Width (): Word; inline;'#10); + write(fohlp, 'function trig'); if fld.hasTPrefix then write(fohlp, 'T'); write(fohlp, 'Height (): Word; inline;'#10); + // [T]X + write(foimpl, 'function TDynRecordHelper.trig'); + if fld.hasTPrefix then write(foimpl, 'T'); + write(foimpl, 'Width (): Word; inline; begin result := Word(getFieldWithType(''', fld.name, ''', TDynField.TType.TSize).ival); end;'#10); + // [T]Y + write(foimpl, 'function TDynRecordHelper.trig'); + if fld.hasTPrefix then write(foimpl, 'T'); + write(foimpl, 'Height (): Word; inline; begin result := Word(getFieldWithType(''', fld.name, ''', TDynField.TType.TSize).ival2); end;'#10); + end + else + begin + raise Exception.Create('no non-separate sizes in triggers, pelase'); + end; + end; + TDynField.TType.TList: + raise Exception.Create('no lists in triggers, pelase'); + TDynField.TType.TTrigData: + raise Exception.Create('no triggers in triggers, pelase'); + end; + end; + end; + //st := openDiskFileRO('mapdef.txt'); st.position := 0; @@ -75,4 +230,6 @@ begin write(fo, #10';'); CloseFile(fo); + CloseFile(fohlp); + CloseFile(foimpl); end.