@working on decorate support

This commit is contained in:
codeimp 2009-01-21 16:18:30 +00:00
parent d2265287b4
commit 1694d828d1
17 changed files with 164 additions and 58 deletions

View file

@ -67,7 +67,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Go for all the things // Go for all the things
foreach(Thing t in General.Map.Map.Things) foreach(Thing t in General.Map.Map.Things)
{ {
ThingTypeInfo info = General.Map.Config.GetThingInfo(t.Type); ThingTypeInfo info = General.Map.Data.GetThingInfo(t.Type);
bool stucked = false; bool stucked = false;
// Check this thing for getting stucked? // Check this thing for getting stucked?

View file

@ -70,7 +70,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
// This must return the string that is displayed in the listbox // This must return the string that is displayed in the listbox
public override string ToString() public override string ToString()
{ {
return General.Map.Config.GetThingInfo(thing.Type).Title + " is stucked in a wall at " + thing.Position.x + ", " + thing.Position.y; return General.Map.Data.GetThingInfo(thing.Type).Title + " is stucked in a wall at " + thing.Position.x + ", " + thing.Position.y;
} }
// Rendering // Rendering

View file

@ -70,7 +70,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
// This must return the string that is displayed in the listbox // This must return the string that is displayed in the listbox
public override string ToString() public override string ToString()
{ {
return General.Map.Config.GetThingInfo(thing.Type).Title + " is outside the map at " + thing.Position.x + ", " + thing.Position.y; return General.Map.Data.GetThingInfo(thing.Type).Title + " is outside the map at " + thing.Position.x + ", " + thing.Position.y;
} }
// Rendering // Rendering

View file

@ -206,7 +206,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
public void Rebuild() public void Rebuild()
{ {
// Find thing information // Find thing information
info = General.Map.Config.GetThingInfo(Thing.Type); info = General.Map.Data.GetThingInfo(Thing.Type);
// Find sprite texture // Find sprite texture
if(info.Sprite.Length > 0) if(info.Sprite.Length > 0)

View file

@ -158,8 +158,6 @@ namespace CodeImp.DoomBuilder.Config
// Things // Things
public ICollection<string> DefaultThingFlags { get { return defaultthingflags; } } public ICollection<string> DefaultThingFlags { get { return defaultthingflags; } }
public IDictionary<string, string> ThingFlags { get { return thingflags; } } public IDictionary<string, string> ThingFlags { get { return thingflags; } }
public List<ThingCategory> ThingCategories { get { return thingcategories; } }
public ICollection<ThingTypeInfo> Things { get { return things.Values; } }
public List<FlagTranslation> ThingFlagsTranslation { get { return thingflagstranslation; } } public List<FlagTranslation> ThingFlagsTranslation { get { return thingflagstranslation; } }
// Linedefs // Linedefs
@ -683,37 +681,16 @@ namespace CodeImp.DoomBuilder.Config
public byte ReadSetting(string setting, byte defaultsetting) { return cfg.ReadSetting(setting, defaultsetting); } public byte ReadSetting(string setting, byte defaultsetting) { return cfg.ReadSetting(setting, defaultsetting); }
public IDictionary ReadSetting(string setting, IDictionary defaultsetting) { return cfg.ReadSetting(setting, defaultsetting); } public IDictionary ReadSetting(string setting, IDictionary defaultsetting) { return cfg.ReadSetting(setting, defaultsetting); }
// This gets thing information by index // This gets a list of things categories
public ThingTypeInfo GetThingInfo(int thingtype) internal List<ThingCategory> GetThingCategories()
{ {
// Index in config? return new List<ThingCategory>(thingcategories);
if(things.ContainsKey(thingtype))
{
// Return from config
return things[thingtype];
}
else
{
// Create unknown thing info
return new ThingTypeInfo(thingtype);
}
} }
// This gets thing information by index // This gets a list of things
// Returns null when thing type info could not be found internal Dictionary<int, ThingTypeInfo> GetThingTypes()
public ThingTypeInfo GetThingInfoEx(int thingtype)
{ {
// Index in config? return new Dictionary<int, ThingTypeInfo>(things);
if(things.ContainsKey(thingtype))
{
// Return from config
return things[thingtype];
}
else
{
// No such thing type known
return null;
}
} }
// This checks if an action is generalized or predefined // This checks if an action is generalized or predefined

View file

@ -95,7 +95,7 @@ namespace CodeImp.DoomBuilder.Controls
spritepanel.Left = infopanel.Left + infopanel.Width + infopanel.Margin.Right + spritepanel.Margin.Left; spritepanel.Left = infopanel.Left + infopanel.Width + infopanel.Margin.Right + spritepanel.Margin.Left;
// Lookup thing info // Lookup thing info
ti = General.Map.Config.GetThingInfo(t.Type); ti = General.Map.Data.GetThingInfo(t.Type);
// Get thing action information // Get thing action information
if(General.Map.Config.LinedefActions.ContainsKey(t.Action)) if(General.Map.Config.LinedefActions.ContainsKey(t.Action))

View file

@ -31,6 +31,7 @@ using CodeImp.DoomBuilder.Config;
using System.Threading; using System.Threading;
using CodeImp.DoomBuilder.Map; using CodeImp.DoomBuilder.Map;
using CodeImp.DoomBuilder.Windows; using CodeImp.DoomBuilder.Windows;
using CodeImp.DoomBuilder.Decorate;
#endregion #endregion
@ -81,6 +82,10 @@ namespace CodeImp.DoomBuilder.Data
// Used images // Used images
private Dictionary<long, long> usedimages; private Dictionary<long, long> usedimages;
// Things combined with things created from Decorate
private List<ThingCategory> thingcategories;
private Dictionary<int, ThingTypeInfo> thingtypes;
// Disposing // Disposing
private bool isdisposed = false; private bool isdisposed = false;
@ -100,6 +105,8 @@ namespace CodeImp.DoomBuilder.Data
public ImageData Crosshair3D { get { return crosshair; } } public ImageData Crosshair3D { get { return crosshair; } }
public ImageData CrosshairBusy3D { get { return crosshairbusy; } } public ImageData CrosshairBusy3D { get { return crosshairbusy; } }
public ImageData ThingBox { get { return thingbox; } } public ImageData ThingBox { get { return thingbox; } }
public List<ThingCategory> ThingCategories { get { return thingcategories; } }
public ICollection<ThingTypeInfo> ThingTypes { get { return thingtypes.Values; } }
internal ICollection<MatchingTextureSet> TextureSets { get { return texturesets; } } internal ICollection<MatchingTextureSet> TextureSets { get { return texturesets; } }
internal OthersTextureSet OthersTextureSet { get { return othertextures; } } internal OthersTextureSet OthersTextureSet { get { return othertextures; } }
internal AllTextureSet AllTextureSet { get { return alltextures; } } internal AllTextureSet AllTextureSet { get { return alltextures; } }
@ -188,7 +195,7 @@ namespace CodeImp.DoomBuilder.Data
// This loads all data resources // This loads all data resources
internal void Load(DataLocationList locations) internal void Load(DataLocationList locations)
{ {
int texcount, flatcount, spritecount; int texcount, flatcount, spritecount, thingcount;
DataReader c; DataReader c;
// Create collections // Create collections
@ -203,6 +210,8 @@ namespace CodeImp.DoomBuilder.Data
texturesets = new List<MatchingTextureSet>(); texturesets = new List<MatchingTextureSet>();
usedimages = new Dictionary<long, long>(); usedimages = new Dictionary<long, long>();
internalsprites = new Dictionary<string, ImageData>(); internalsprites = new Dictionary<string, ImageData>();
thingcategories = General.Map.Config.GetThingCategories();
thingtypes = General.Map.Config.GetThingTypes();
// Load texture sets // Load texture sets
foreach(DefinedTextureSet ts in General.Map.ConfigSettings.TextureSets) foreach(DefinedTextureSet ts in General.Map.ConfigSettings.TextureSets)
@ -263,6 +272,7 @@ namespace CodeImp.DoomBuilder.Data
LoadPalette(); LoadPalette();
texcount = LoadTextures(); texcount = LoadTextures();
flatcount = LoadFlats(); flatcount = LoadFlats();
thingcount = LoadDecorateThings();
spritecount = LoadSprites(); spritecount = LoadSprites();
LoadInternalSprites(); LoadInternalSprites();
@ -307,7 +317,7 @@ namespace CodeImp.DoomBuilder.Data
StartBackgroundLoader(); StartBackgroundLoader();
// Output info // Output info
General.WriteLogLine("Loaded " + texcount + " textures, " + flatcount + " flats, " + spritecount + " sprites"); General.WriteLogLine("Loaded " + texcount + " textures, " + flatcount + " flats, " + spritecount + " sprites, " + thingcount + " decorate things");
} }
// This unloads all data // This unloads all data
@ -862,7 +872,7 @@ namespace CodeImp.DoomBuilder.Data
private int LoadSprites() private int LoadSprites()
{ {
// Go for all things // Go for all things
foreach(ThingTypeInfo ti in General.Map.Config.Things) foreach(ThingTypeInfo ti in General.Map.Data.ThingTypes)
{ {
// Sprite not added to collection yet? // Sprite not added to collection yet?
if(!sprites.ContainsKey(ti.SpriteLongName) && (ti.Sprite.Length <= 8)) if(!sprites.ContainsKey(ti.SpriteLongName) && (ti.Sprite.Length <= 8))
@ -1017,6 +1027,93 @@ namespace CodeImp.DoomBuilder.Data
#endregion #endregion
#region ================== Things
// This loads the things from Decorate
private int LoadDecorateThings()
{
DecorateParser parser;
int counter = 0;
// Create the parser
parser = new DecorateParser();
parser.OnInclude = LoadDecorateFromLocation;
// 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.
Stream decodata = dr.GetDecorateData("DECORATE");
if(decodata != null)
{
// Parse the data
decodata.Seek(0, SeekOrigin.Begin);
parser.Parse(decodata);
// Check for errors
if(parser.HasError)
{
General.WriteLogLine("ERROR: Unable to parse DECORATE data from location " + dr.Location.location + "!");
General.WriteLogLine(parser.ErrorDescription + " on line " + parser.ErrorLine);
break;
}
}
}
if(!parser.HasError)
{
// Go for all actors in the decorate
// TODO
counter = parser.Actors.Count;
}
// Output info
return counter;
}
// This loads Decorate data from a specific file or lump name
private void LoadDecorateFromLocation(string location)
{
// TODO
int t = 5;
}
// This gets thing information by index
public ThingTypeInfo GetThingInfo(int thingtype)
{
// Index in config?
if(thingtypes.ContainsKey(thingtype))
{
// Return from config
return thingtypes[thingtype];
}
else
{
// Create unknown thing info
return new ThingTypeInfo(thingtype);
}
}
// This gets thing information by index
// Returns null when thing type info could not be found
public ThingTypeInfo GetThingInfoEx(int thingtype)
{
// Index in config?
if(thingtypes.ContainsKey(thingtype))
{
// Return from config
return thingtypes[thingtype];
}
else
{
// No such thing type known
return null;
}
}
#endregion
#region ================== Tools #region ================== Tools
// This finds the first IWAD resource // This finds the first IWAD resource

View file

@ -33,6 +33,14 @@ namespace CodeImp.DoomBuilder.Decorate
{ {
public sealed class DecorateParser public sealed class DecorateParser
{ {
#region ================== Delegates
public delegate void IncludeDelegate(string includefile);
public IncludeDelegate OnInclude;
#endregion
#region ================== Constants #region ================== Constants
// Parsing // Parsing
@ -85,8 +93,10 @@ namespace CodeImp.DoomBuilder.Decorate
// Returns false on errors // Returns false on errors
public bool Parse(Stream stream) public bool Parse(Stream stream)
{ {
datastream = stream; Stream localstream = stream;
datareader = new StreamReader(datastream, Encoding.ASCII); StreamReader localreader = new StreamReader(localstream, Encoding.ASCII);
datastream = localstream;
datareader = localreader;
datastream.Seek(0, SeekOrigin.Begin); datastream.Seek(0, SeekOrigin.Begin);
// Continue until at the end of the stream // Continue until at the end of the stream
@ -103,6 +113,24 @@ namespace CodeImp.DoomBuilder.Decorate
ActorStructure actor = new ActorStructure(this); ActorStructure actor = new ActorStructure(this);
if(this.HasError) break; if(this.HasError) break;
} }
else if(objdeclaration == "#include")
{
// Include a file
SkipWhitespace(true);
string filename = ReadToken();
if(!string.IsNullOrEmpty(filename))
{
if(OnInclude != null) OnInclude(filename);
datastream = localstream;
datareader = localreader;
if(HasError) break;
}
else
{
ReportError("Expected file name to include");
break;
}
}
else else
{ {
// Unknown structure! // Unknown structure!
@ -143,14 +171,15 @@ namespace CodeImp.DoomBuilder.Decorate
internal bool SkipWhitespace(bool skipnewline) internal bool SkipWhitespace(bool skipnewline)
{ {
int offset = skipnewline ? 1 : 0; int offset = skipnewline ? 1 : 0;
char[] cb = new char[1];
int c; int c;
do do
{ {
c = datareader.Read(); c = datareader.Read(cb, 0, 1);
if(c == -1) return false; if(c == -1) return false;
} }
while(WHITESPACE.IndexOf(unchecked((char)c), offset) > -1); while(WHITESPACE.IndexOf(unchecked(cb[0]), offset) > -1);
// Go one character back so we can read this non-whitespace character again // Go one character back so we can read this non-whitespace character again
datastream.Seek(-1, SeekOrigin.Current); datastream.Seek(-1, SeekOrigin.Current);
@ -162,6 +191,7 @@ namespace CodeImp.DoomBuilder.Decorate
internal string ReadToken() internal string ReadToken()
{ {
string token = ""; string token = "";
bool quotedstring = false;
int c; int c;
// Return null when the end of the stream has been reached // Return null when the end of the stream has been reached
@ -169,12 +199,12 @@ namespace CodeImp.DoomBuilder.Decorate
// Start reading // Start reading
c = datareader.Read(); c = datareader.Read();
while((c != -1) && !IsWhitespace(unchecked((char)c))) while((c != -1) && (!IsWhitespace(unchecked((char)c)) || quotedstring))
{ {
char cc = unchecked((char)c); char cc = unchecked((char)c);
// Special token? // Special token?
if(IsSpecialToken(cc)) if(!quotedstring && IsSpecialToken(cc))
{ {
// Not reading a token yet? // Not reading a token yet?
if(token.Length == 0) if(token.Length == 0)
@ -193,6 +223,12 @@ namespace CodeImp.DoomBuilder.Decorate
} }
else else
{ {
// Quote to end the string?
if(quotedstring && (cc == '"')) quotedstring = false;
// First character is a quote?
if((token.Length == 0) && (cc == '"')) quotedstring = true;
token += cc; token += cc;
} }

View file

@ -195,7 +195,7 @@ namespace CodeImp.DoomBuilder.Editing
bool qualifies; bool qualifies;
// Get thing info // Get thing info
ThingTypeInfo ti = General.Map.Config.GetThingInfo(t.Type); ThingTypeInfo ti = General.Map.Data.GetThingInfo(t.Type);
// Check if thing is in unknown category // Check if thing is in unknown category
if(ti.Category == null) if(ti.Category == null)

View file

@ -266,6 +266,7 @@ namespace CodeImp.DoomBuilder
data.Load(configinfo.Resources, options.Resources); data.Load(configinfo.Resources, options.Resources);
// Update structures // Update structures
map.UpdateConfiguration();
map.Update(); map.Update();
thingsfilter.Update(); thingsfilter.Update();
@ -355,6 +356,7 @@ namespace CodeImp.DoomBuilder
data.Load(configinfo.Resources, options.Resources, maplocation); data.Load(configinfo.Resources, options.Resources, maplocation);
// Update structures // Update structures
map.UpdateConfiguration();
map.SnapAllToAccuracy(); map.SnapAllToAccuracy();
map.Update(); map.Update();
thingsfilter.Update(); thingsfilter.Update();

View file

@ -122,8 +122,6 @@ namespace CodeImp.DoomBuilder.IO
// Create new item // Create new item
t = map.CreateThing(); t = map.CreateThing();
t.Update(type, x, y, 0, angle, stringflags, 0, 0, new int[Thing.NUM_ARGS]); t.Update(type, x, y, 0, angle, stringflags, 0, 0, new int[Thing.NUM_ARGS]);
//t.DetermineSector();
t.UpdateConfiguration();
} }
// Done // Done

View file

@ -132,8 +132,6 @@ namespace CodeImp.DoomBuilder.IO
// Create new item // Create new item
t = map.CreateThing(); t = map.CreateThing();
t.Update(type, x, y, z, angle, stringflags, tag, action, args); t.Update(type, x, y, z, angle, stringflags, tag, action, args);
//t.DetermineSector();
t.UpdateConfiguration();
} }
// Done // Done

View file

@ -181,8 +181,6 @@ namespace CodeImp.DoomBuilder.IO
// Create new item // Create new item
Thing t = map.CreateThing(); Thing t = map.CreateThing();
t.Update(type, x, y, height, Angle2D.DoomToReal(angledeg), stringflags, tag, special, args); t.Update(type, x, y, height, Angle2D.DoomToReal(angledeg), stringflags, tag, special, args);
//t.DetermineSector();
t.UpdateConfiguration();
// Custom fields // Custom fields
ReadCustomFields(c, t, "thing"); ReadCustomFields(c, t, "thing");

View file

@ -364,7 +364,7 @@ namespace CodeImp.DoomBuilder.Map
ThingTypeInfo ti; ThingTypeInfo ti;
// Lookup settings // Lookup settings
ti = General.Map.Config.GetThingInfo(type); ti = General.Map.Data.GetThingInfo(type);
// Apply size // Apply size
size = ti.Width; size = ti.Width;

View file

@ -2075,7 +2075,7 @@ namespace CodeImp.DoomBuilder.Windows
if(IsInfoPanelExpanded) thinginfo.ShowInfo(t); if(IsInfoPanelExpanded) thinginfo.ShowInfo(t);
// Show info on collapsed label // Show info on collapsed label
ThingTypeInfo ti = General.Map.Config.GetThingInfo(t.Type); ThingTypeInfo ti = General.Map.Data.GetThingInfo(t.Type);
labelcollapsedinfo.Text = t.Type + " - " + ti.Title; labelcollapsedinfo.Text = t.Type + " - " + ti.Title;
labelcollapsedinfo.Refresh(); labelcollapsedinfo.Refresh();
} }

View file

@ -79,7 +79,7 @@ namespace CodeImp.DoomBuilder.Windows
// Go for all predefined categories // Go for all predefined categories
typelist.Nodes.Clear(); typelist.Nodes.Clear();
nodes = new List<TreeNode>(); nodes = new List<TreeNode>();
foreach(ThingCategory tc in General.Map.Config.ThingCategories) foreach(ThingCategory tc in General.Map.Data.ThingCategories)
{ {
// Create category // Create category
TreeNode cn = typelist.Nodes.Add(tc.Name, tc.Title); TreeNode cn = typelist.Nodes.Add(tc.Name, tc.Title);
@ -283,7 +283,7 @@ namespace CodeImp.DoomBuilder.Windows
if(typeid.Text.Length > 0) if(typeid.Text.Length > 0)
{ {
// Get the info // Get the info
ThingTypeInfo ti = General.Map.Config.GetThingInfoEx(typeid.GetResult(0)); ThingTypeInfo ti = General.Map.Data.GetThingInfoEx(typeid.GetResult(0));
if(ti != null) if(ti != null)
{ {
knownthing = true; knownthing = true;

View file

@ -55,7 +55,7 @@ namespace CodeImp.DoomBuilder.Windows
// Fill the categories combobox // Fill the categories combobox
filtercategory.Items.Add("(any category)"); filtercategory.Items.Add("(any category)");
filtercategory.Items.AddRange(General.Map.Config.ThingCategories.ToArray()); filtercategory.Items.AddRange(General.Map.Data.ThingCategories.ToArray());
// Fill checkboxes list // Fill checkboxes list
foreach(KeyValuePair<string, string> flag in General.Map.Config.ThingFlags) foreach(KeyValuePair<string, string> flag in General.Map.Config.ThingFlags)