mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2025-01-18 22:41:46 +00:00
Internal: started implementing ZScript parser. Nothing works for now, aside from the actual parsing code.
This commit is contained in:
parent
96ffb78678
commit
38ffc861cb
8 changed files with 148 additions and 12 deletions
|
@ -520,6 +520,8 @@
|
|||
<Compile Include="VisualModes\VisualSector.cs" />
|
||||
<Compile Include="Rendering\World3DShader.cs" />
|
||||
<Compile Include="Rendering\WorldVertex.cs" />
|
||||
<Compile Include="ZDoom\ZScriptParser.cs" />
|
||||
<Compile Include="ZDoom\ZScriptTokenizer.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="JetBrains.Profiler.Core.Api, Version=1.3.1661.20096, Culture=neutral, PublicKeyToken=1010a0d8d6380325" Condition=" '$(Configuration)|$(Platform)' == 'Debug + Profiler|x86' Or '$(Configuration)|$(Platform)' == 'Release + Profiler|x86' ">
|
||||
|
|
|
@ -52,6 +52,7 @@ namespace CodeImp.DoomBuilder.Config
|
|||
GAMEINFO,
|
||||
KEYCONF,
|
||||
FONTDEFS,
|
||||
ZSCRIPT,
|
||||
}
|
||||
|
||||
internal class ScriptConfiguration : IComparable<ScriptConfiguration>
|
||||
|
|
|
@ -136,6 +136,7 @@ namespace CodeImp.DoomBuilder.Data
|
|||
|
||||
// Things combined with things created from Decorate
|
||||
private DecorateParser decorate;
|
||||
private ZScriptParser zscript;
|
||||
private List<ThingCategory> thingcategories;
|
||||
private Dictionary<int, ThingTypeInfo> thingtypes;
|
||||
|
||||
|
@ -191,6 +192,7 @@ namespace CodeImp.DoomBuilder.Data
|
|||
public List<ThingCategory> ThingCategories { get { return thingcategories; } }
|
||||
public ICollection<ThingTypeInfo> ThingTypes { get { return thingtypes.Values; } }
|
||||
public DecorateParser Decorate { get { return decorate; } }
|
||||
public ZScriptParser ZScript { get { return zscript; } }
|
||||
internal ICollection<MatchingTextureSet> TextureSets { get { return texturesets; } }
|
||||
internal ICollection<ResourceTextureSet> ResourceTextureSets { get { return resourcetextures; } }
|
||||
internal AllTextureSet AllTextureSet { get { return alltextures; } }
|
||||
|
@ -444,7 +446,7 @@ namespace CodeImp.DoomBuilder.Data
|
|||
//mxd. Load Script Editor-only stuff...
|
||||
LoadExtraTextLumps();
|
||||
|
||||
int thingcount = LoadDecorateThings(spawnnums, doomednums);
|
||||
int thingcount = LoadZScriptThings(spawnnums, doomednums) + LoadDecorateThings(spawnnums, doomednums);
|
||||
int spritecount = LoadThingSprites();
|
||||
LoadInternalSprites();
|
||||
LoadInternalTextures(); //mxd
|
||||
|
@ -1819,6 +1821,57 @@ namespace CodeImp.DoomBuilder.Data
|
|||
|
||||
#region ================== Things
|
||||
|
||||
private int LoadZScriptThings(Dictionary<int, string> spawnnumsoverride, Dictionary<int, string> doomednumsoverride)
|
||||
{
|
||||
int counter = 0;
|
||||
|
||||
// Create new parser
|
||||
zscript = new ZScriptParser { OnInclude = LoadZScriptFromLocation };
|
||||
|
||||
// Only load these when the game configuration supports the use of decorate
|
||||
if (!string.IsNullOrEmpty(General.Map.Config.DecorateGames))
|
||||
{
|
||||
// Go for all opened containers
|
||||
foreach (DataReader dr in containers)
|
||||
{
|
||||
// Load Decorate info cumulatively (the last Decorate is added to the previous)
|
||||
// I'm not sure if this is the right thing to do though.
|
||||
currentreader = dr;
|
||||
IEnumerable<TextResourceData> streams = dr.GetDecorateData("ZSCRIPT");
|
||||
foreach (TextResourceData data in streams)
|
||||
{
|
||||
// Parse the data
|
||||
data.Stream.Seek(0, SeekOrigin.Begin);
|
||||
zscript.Parse(data, true);
|
||||
|
||||
//mxd. DECORATE lumps are interdepandable. Can't carry on...
|
||||
if (zscript.HasError)
|
||||
{
|
||||
zscript.LogError();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//mxd. Add to text resources collection
|
||||
scriptresources[zscript.ScriptType] = new HashSet<ScriptResource>(zscript.ScriptResources.Values);
|
||||
currentreader = null;
|
||||
|
||||
if (!zscript.HasError)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// Return after adding parsed resources
|
||||
return counter;
|
||||
}
|
||||
}
|
||||
|
||||
// Output info
|
||||
return counter;
|
||||
}
|
||||
|
||||
// This loads the things from Decorate
|
||||
private int LoadDecorateThings(Dictionary<int, string> spawnnumsoverride, Dictionary<int, string> doomednumsoverride)
|
||||
{
|
||||
|
@ -2145,6 +2198,23 @@ namespace CodeImp.DoomBuilder.Data
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadZScriptFromLocation(ZScriptParser parser, string location)
|
||||
{
|
||||
IEnumerable<TextResourceData> streams = currentreader.GetZScriptData(location);
|
||||
foreach (TextResourceData data in streams)
|
||||
{
|
||||
// Parse this data
|
||||
parser.Parse(data, false);
|
||||
|
||||
//mxd. DECORATE lumps are interdepandable. Can't carry on...
|
||||
if (parser.HasError)
|
||||
{
|
||||
parser.LogError();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This gets thing information by index
|
||||
public ThingTypeInfo GetThingInfo(int thingtype)
|
||||
|
|
|
@ -222,8 +222,11 @@ namespace CodeImp.DoomBuilder.Data
|
|||
// When implemented, this returns DECORATE lumps
|
||||
public abstract IEnumerable<TextResourceData> GetDecorateData(string pname);
|
||||
|
||||
//mxd. When implemented, this returns MAPINFO lumps
|
||||
public abstract IEnumerable<TextResourceData> GetMapinfoData();
|
||||
// [ZZ] When implemented, this returns ZSCRIPT lumps
|
||||
public abstract IEnumerable<TextResourceData> GetZScriptData(string pname);
|
||||
|
||||
//mxd. When implemented, this returns MAPINFO lumps
|
||||
public abstract IEnumerable<TextResourceData> GetMapinfoData();
|
||||
|
||||
//mxd. When implemented, this returns GLDEFS lumps
|
||||
public abstract IEnumerable<TextResourceData> GetGldefsData(string basegame);
|
||||
|
|
|
@ -524,12 +524,56 @@ namespace CodeImp.DoomBuilder.Data
|
|||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region ================== VOXELDEF (mxd)
|
||||
#region ================== ZSCRIPT
|
||||
|
||||
//mxd. This returns the list of voxels, which can be used without VOXELDEF definition
|
||||
public override HashSet<string> GetVoxelNames()
|
||||
// This finds and returns ZSCRIPT streams
|
||||
public override IEnumerable<TextResourceData> GetZScriptData(string pname)
|
||||
{
|
||||
// Error when suspended
|
||||
if (issuspended) throw new Exception("Data reader is suspended");
|
||||
|
||||
List<TextResourceData> result = new List<TextResourceData>();
|
||||
string[] allfilenames;
|
||||
|
||||
// Find in root directory
|
||||
string filename = Path.GetFileName(pname);
|
||||
string pathname = Path.GetDirectoryName(pname);
|
||||
|
||||
if (filename.IndexOf('.') > -1)
|
||||
{
|
||||
string fullname = Path.Combine(pathname, filename);
|
||||
if (FileExists(fullname))
|
||||
{
|
||||
allfilenames = new string[1];
|
||||
allfilenames[0] = Path.Combine(pathname, filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
allfilenames = new string[0];
|
||||
General.ErrorLogger.Add(ErrorType.Warning, "Unable to load ZSCRIPT file \"" + fullname + "\"");
|
||||
}
|
||||
}
|
||||
else
|
||||
allfilenames = GetAllFilesWithTitle(pathname, filename, false);
|
||||
|
||||
foreach (string foundfile in allfilenames)
|
||||
result.Add(new TextResourceData(this, LoadFile(foundfile), foundfile, true));
|
||||
|
||||
// Find in any of the wad files
|
||||
for (int i = wads.Count - 1; i >= 0; i--)
|
||||
result.AddRange(wads[i].GetZScriptData(pname));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== VOXELDEF (mxd)
|
||||
|
||||
//mxd. This returns the list of voxels, which can be used without VOXELDEF definition
|
||||
public override HashSet<string> GetVoxelNames()
|
||||
{
|
||||
// Error when suspended
|
||||
if(issuspended) throw new Exception("Data reader is suspended");
|
||||
|
|
|
@ -1017,8 +1017,22 @@ namespace CodeImp.DoomBuilder.Data
|
|||
return new List<TextResourceData> {result[result.Count - 1]};
|
||||
}
|
||||
|
||||
//mxd. Should be only one entry per wad
|
||||
public override IEnumerable<TextResourceData> GetMapinfoData()
|
||||
// [ZZ] This finds and returns ZSCRIPT streams
|
||||
public override IEnumerable<TextResourceData> GetZScriptData(string pname)
|
||||
{
|
||||
if (issuspended) throw new Exception("Data reader is suspended");
|
||||
List<TextResourceData> result = GetAllLumpsData(pname); //mxd
|
||||
|
||||
//mxd. Return ALL DECORATE lumps
|
||||
if (result.Count == 0 || string.Compare(pname, "ZSCRIPT", StringComparison.OrdinalIgnoreCase) == 0)
|
||||
return result;
|
||||
|
||||
//mxd. Return THE LAST include lump, because that's the way ZDoom seems to operate
|
||||
return new List<TextResourceData> { result[result.Count - 1] };
|
||||
}
|
||||
|
||||
//mxd. Should be only one entry per wad
|
||||
public override IEnumerable<TextResourceData> GetMapinfoData()
|
||||
{
|
||||
if(issuspended) throw new Exception("Data reader is suspended");
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ namespace CodeImp.DoomBuilder.ZDoom
|
|||
private string errordesc;
|
||||
private string errorsource; // Rooted path to the troubling file
|
||||
private string shorterrorsource; //mxd. Resource name + filename
|
||||
private long prevstreamposition; //mxd. Text stream position storted before performing ReadToken.
|
||||
protected long prevstreamposition; //mxd. Text stream position storted before performing ReadToken.
|
||||
|
||||
//mxd. Text lumps
|
||||
protected string textresourcepath;
|
||||
|
@ -757,7 +757,7 @@ namespace CodeImp.DoomBuilder.ZDoom
|
|||
protected int GetCurrentLineNumber()
|
||||
{
|
||||
long pos = datastream.Position;
|
||||
long finishpos = Math.Min(prevstreamposition, pos);
|
||||
long finishpos = (prevstreamposition >= 0 ? Math.Min(prevstreamposition, pos) : pos);
|
||||
long readpos = 0;
|
||||
int linenumber = -1;
|
||||
|
||||
|
|
|
@ -75,7 +75,9 @@
|
|||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="StairSectorBuilderForm.cs" />
|
||||
<Compile Include="StairSectorBuilderForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="StairSectorBuilderForm.designer.cs">
|
||||
<DependentUpon>StairSectorBuilderForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
|
|
Loading…
Reference in a new issue