2016-04-06 11:44:38 +00:00
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
|
|
using System;
|
2014-02-26 14:11:06 +00:00
|
|
|
|
using System.Collections.Generic;
|
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
|
|
|
|
using CodeImp.DoomBuilder.Config;
|
|
|
|
|
using CodeImp.DoomBuilder.Data;
|
2016-04-06 11:44:38 +00:00
|
|
|
|
using CodeImp.DoomBuilder.Geometry;
|
2012-05-21 23:51:32 +00:00
|
|
|
|
using CodeImp.DoomBuilder.GZBuilder.Data;
|
2016-04-06 11:44:38 +00:00
|
|
|
|
using SlimDX;
|
|
|
|
|
|
|
|
|
|
#endregion
|
2012-05-21 23:51:32 +00:00
|
|
|
|
|
2016-04-27 09:13:07 +00:00
|
|
|
|
namespace CodeImp.DoomBuilder.ZDoom
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2015-12-21 14:17:47 +00:00
|
|
|
|
internal class ModeldefParser : ZDTextParser
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2016-04-06 11:44:38 +00:00
|
|
|
|
#region ================== Variables
|
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
|
|
|
|
|
2015-12-21 14:17:47 +00:00
|
|
|
|
private readonly Dictionary<string, int> actorsbyclass;
|
2014-01-03 10:33:45 +00:00
|
|
|
|
private Dictionary<string, ModelData> entries; //classname, entry
|
2016-04-06 11:44:38 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
|
|
internal override ScriptType ScriptType { get { return ScriptType.MODELDEF; } }
|
2014-01-03 10:33:45 +00:00
|
|
|
|
internal Dictionary<string, ModelData> Entries { get { return entries; } }
|
2012-05-21 23:51:32 +00:00
|
|
|
|
|
2016-04-06 11:44:38 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Constructor
|
|
|
|
|
|
2015-12-21 14:17:47 +00:00
|
|
|
|
internal ModeldefParser(Dictionary<string, int> actorsbyclass)
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2015-12-21 14:17:47 +00:00
|
|
|
|
this.actorsbyclass = actorsbyclass;
|
2016-04-06 11:44:38 +00:00
|
|
|
|
this.entries = new Dictionary<string, ModelData>(StringComparer.OrdinalIgnoreCase);
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
2012-06-01 10:17:47 +00:00
|
|
|
|
|
2016-04-06 11:44:38 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Parsing
|
|
|
|
|
|
|
|
|
|
// Should be called after all decorate actors are parsed
|
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
|
|
|
|
public override bool Parse(TextResourceData data, bool clearerrors)
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2016-04-06 11:44:38 +00:00
|
|
|
|
// Already parsed?
|
Added, Sector Edit window, UDMF: added UI for sector damage-realted properties.
Added, DECORATE parser: damage types are now parsed.
Added: the editor now reports duplicate textures/flats/patches/sprites/colormaps/voxels in the loaded wads.
Added, all text parsers: added #region/#endregion support.
Added TERRAIN parser.
Added, Script Editor: added special handling for DECORATE special comments.
Added, Sector Edit window, UDMF: Soundsequence value was setup incorrectly when showing the window for multiple sectors with mixed Soundsequence value.
Fixed, Map Options window: "Strictly load patches between P_START and P_END" was not applied when applying the changes.
Fixed, MAPINFO parser: MapInfo should be treated as defined when a map MAPINFO block corresponding to current map is encountered even if it doesn't define any properties recognized by the editor.
Fixed, all text parsers: in some cases error line was calculated incorrectly when reporting an error detected by a text parser.
Cosmetic: changed ' to " in the rest of Error and Warning messages.
Internal: added text resource tracking.
Updated ZDoom_DECORATE.cfg.
Updated documentation ("Game Configuration - Basic Settings" page).
2016-02-22 12:33:19 +00:00
|
|
|
|
if(!base.AddTextResource(data))
|
|
|
|
|
{
|
|
|
|
|
if(clearerrors) ClearError();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Cannot process?
|
|
|
|
|
if(!base.Parse(data, clearerrors)) return false;
|
2012-05-21 23:51:32 +00:00
|
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
|
// Continue until at the end of the stream
|
2015-12-17 10:07:28 +00:00
|
|
|
|
while(SkipWhitespace(true))
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
string token = ReadToken();
|
2016-04-06 22:54:04 +00:00
|
|
|
|
if(string.IsNullOrEmpty(token) || token.ToLowerInvariant() != "model") continue;
|
2015-12-17 10:07:28 +00:00
|
|
|
|
|
2016-04-06 11:44:38 +00:00
|
|
|
|
// Find classname
|
|
|
|
|
SkipWhitespace(true);
|
2016-04-06 22:54:04 +00:00
|
|
|
|
string classname = StripQuotes(ReadToken(ActorStructure.ACTOR_CLASS_SPECIAL_TOKENS));
|
2016-04-06 11:44:38 +00:00
|
|
|
|
if(string.IsNullOrEmpty(classname))
|
|
|
|
|
{
|
|
|
|
|
ReportError("Expected actor class");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-04-06 22:54:04 +00:00
|
|
|
|
|
|
|
|
|
// Check if actor exists
|
|
|
|
|
bool haveplaceableactor = actorsbyclass.ContainsKey(classname);
|
|
|
|
|
if(!haveplaceableactor && !General.Map.Data.Decorate.ActorsByClass.ContainsKey(classname))
|
2016-04-23 23:15:43 +00:00
|
|
|
|
LogWarning("DECORATE class \"" + classname + "\" does not exist");
|
2016-04-06 11:44:38 +00:00
|
|
|
|
|
|
|
|
|
// Now find opening brace
|
|
|
|
|
if(!NextTokenIs("{")) return false;
|
|
|
|
|
|
|
|
|
|
// Parse the structure
|
|
|
|
|
ModeldefStructure mds = new ModeldefStructure();
|
|
|
|
|
if(mds.Parse(this))
|
|
|
|
|
{
|
|
|
|
|
// Fetch Actor info
|
2016-04-06 22:54:04 +00:00
|
|
|
|
if(haveplaceableactor)
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2016-04-06 11:44:38 +00:00
|
|
|
|
ThingTypeInfo info = General.Map.Data.GetThingInfoEx(actorsbyclass[classname]);
|
|
|
|
|
|
|
|
|
|
// Actor has a valid sprite?
|
|
|
|
|
if(info != null && !string.IsNullOrEmpty(info.Sprite) && !info.Sprite.ToLowerInvariant().StartsWith(DataManager.INTERNAL_PREFIX))
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2016-04-06 11:44:38 +00:00
|
|
|
|
string targetsprite = info.Sprite.Substring(0, 5);
|
|
|
|
|
if(mds.Frames.ContainsKey(targetsprite))
|
Textures Browser form: empty texture sets are no longer shown when mixed textures & flats is disabled in the current game configuration.
Textures Browser form: PK3/Directory TEXTURES images are now shown in a separate folder in the resources tree.
Fixed, Textures Browser form: fixed a logic error when trying to select initial flat when mix textures & flats was disabled in the current game configuration (this resulted in the blank textures list after opening the form).
Fixed, Textures Browser form: resources tree showed textures count even when browsing flats.
Fixed, Textures Browser form: PK3/Directory textures took precedence even when browsing flats (this means when there were a flat and a texture with the same name, a texture was displayed when browsing flats).
Fixed, Classic modes: actor's scale set in DECORATE was ignored when rendering models.
Fixed, MODELDEF parser: in some cases, several model definitions were skipped when trying to skip the current one.
Fixed, resource management: flat and sprite TEXTURES definitions were loaded only from TEXTURES files named "TEXTURES".
Fixed/added, PK3/folder resource management: patch locations for sprites defined in TEXTURES are now checked the same way as in ZDoom (previously only the "sprites" folder was checked).
Fixed/added, PK3/folder resource management: patch locations for textures defined in TEXTURES are now checked the same way as in ZDoom (previously only the "textures" folder was checked).
Fixed, PK3/folder resource management: flats defined in TEXTURES were not added to the global Flats image list.
Fixed, PK3/folder resource management: in some cases, the image search algorithm could find flats, textures, patches or sprites in incorrect folders (for example, it could find a flat in "flats_backup" folder).
2014-10-07 00:23:02 +00:00
|
|
|
|
{
|
2016-04-06 11:44:38 +00:00
|
|
|
|
// Create model data
|
|
|
|
|
ModelData md = new ModelData { InheritActorPitch = mds.InheritActorPitch, InheritActorRoll = mds.InheritActorRoll };
|
|
|
|
|
|
|
|
|
|
// Things are complicated in GZDoom...
|
|
|
|
|
Matrix moffset = Matrix.Translation(mds.Offset.Y, -mds.Offset.X, mds.Offset.Z);
|
|
|
|
|
Matrix mrotation = Matrix.RotationY(-Angle2D.DegToRad(mds.RollOffset)) * Matrix.RotationX(-Angle2D.DegToRad(mds.PitchOffset)) * Matrix.RotationZ(Angle2D.DegToRad(mds.AngleOffset));
|
|
|
|
|
md.SetTransform(mrotation, moffset, mds.Scale);
|
|
|
|
|
|
|
|
|
|
// Add models
|
2016-05-04 11:16:17 +00:00
|
|
|
|
int disabledframescount = 0;
|
2016-04-06 11:44:38 +00:00
|
|
|
|
foreach(var fs in mds.Frames[targetsprite])
|
|
|
|
|
{
|
2016-04-21 21:00:58 +00:00
|
|
|
|
// Sanity checks
|
|
|
|
|
if(string.IsNullOrEmpty(mds.ModelNames[fs.ModelIndex]))
|
|
|
|
|
{
|
|
|
|
|
LogWarning("Model definition \"" + classname + "\", frame \"" + fs.SpriteName + " " + fs.FrameName + "\" references undefiend model index " + fs.ModelIndex);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2016-05-04 11:16:17 +00:00
|
|
|
|
|
|
|
|
|
//INFO: setting frame index to a negative number disables model rendering in GZDoom
|
|
|
|
|
if(fs.FrameIndex < 0)
|
|
|
|
|
{
|
|
|
|
|
disabledframescount++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2016-04-21 21:00:58 +00:00
|
|
|
|
|
2016-04-06 11:44:38 +00:00
|
|
|
|
// Texture name will be empty when skin path is embedded in the model
|
|
|
|
|
string texturename = (!string.IsNullOrEmpty(mds.TextureNames[fs.ModelIndex]) ? mds.TextureNames[fs.ModelIndex].ToLowerInvariant() : string.Empty);
|
|
|
|
|
|
|
|
|
|
md.TextureNames.Add(texturename);
|
|
|
|
|
md.ModelNames.Add(mds.ModelNames[fs.ModelIndex].ToLowerInvariant());
|
|
|
|
|
md.FrameNames.Add(fs.FrameName);
|
|
|
|
|
md.FrameIndices.Add(fs.FrameIndex);
|
|
|
|
|
}
|
Textures Browser form: empty texture sets are no longer shown when mixed textures & flats is disabled in the current game configuration.
Textures Browser form: PK3/Directory TEXTURES images are now shown in a separate folder in the resources tree.
Fixed, Textures Browser form: fixed a logic error when trying to select initial flat when mix textures & flats was disabled in the current game configuration (this resulted in the blank textures list after opening the form).
Fixed, Textures Browser form: resources tree showed textures count even when browsing flats.
Fixed, Textures Browser form: PK3/Directory textures took precedence even when browsing flats (this means when there were a flat and a texture with the same name, a texture was displayed when browsing flats).
Fixed, Classic modes: actor's scale set in DECORATE was ignored when rendering models.
Fixed, MODELDEF parser: in some cases, several model definitions were skipped when trying to skip the current one.
Fixed, resource management: flat and sprite TEXTURES definitions were loaded only from TEXTURES files named "TEXTURES".
Fixed/added, PK3/folder resource management: patch locations for sprites defined in TEXTURES are now checked the same way as in ZDoom (previously only the "sprites" folder was checked).
Fixed/added, PK3/folder resource management: patch locations for textures defined in TEXTURES are now checked the same way as in ZDoom (previously only the "textures" folder was checked).
Fixed, PK3/folder resource management: flats defined in TEXTURES were not added to the global Flats image list.
Fixed, PK3/folder resource management: in some cases, the image search algorithm could find flats, textures, patches or sprites in incorrect folders (for example, it could find a flat in "flats_backup" folder).
2014-10-07 00:23:02 +00:00
|
|
|
|
|
2016-04-21 21:00:58 +00:00
|
|
|
|
// More sanity checks...
|
|
|
|
|
if(md.ModelNames.Count == 0)
|
|
|
|
|
{
|
2016-05-04 11:16:17 +00:00
|
|
|
|
// Show warning only when frames were not delibeartely disabled
|
|
|
|
|
if(mds.Frames[targetsprite].Count > 0 && disabledframescount < mds.Frames[targetsprite].Count)
|
|
|
|
|
LogWarning("Model definition \"" + classname + "\" has no defined models");
|
2016-04-21 21:00:58 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Add to collection
|
|
|
|
|
entries[classname] = md;
|
|
|
|
|
}
|
2016-04-06 11:44:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-04-06 11:44:38 +00:00
|
|
|
|
|
|
|
|
|
if(HasError)
|
|
|
|
|
{
|
|
|
|
|
LogError();
|
|
|
|
|
ClearError();
|
|
|
|
|
}
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
2012-05-21 23:51:32 +00:00
|
|
|
|
|
2016-04-06 11:44:38 +00:00
|
|
|
|
return true;
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
2015-12-17 10:07:28 +00:00
|
|
|
|
|
2016-04-06 11:44:38 +00:00
|
|
|
|
#endregion
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
2012-05-21 23:51:32 +00:00
|
|
|
|
}
|