2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#region ================== Copyright (c) 2007 Pascal vd Heiden
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
|
|
|
* This program is released under GNU General Public License
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
2017-01-16 08:20:47 +00:00
|
|
|
using CodeImp.DoomBuilder.Data;
|
2009-04-19 18:07:22 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.ZDoom
|
|
|
|
{
|
2017-01-16 08:20:47 +00:00
|
|
|
public class StateStructure
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2016-04-20 20:06:16 +00:00
|
|
|
#region ================== FrameInfo (mxd)
|
|
|
|
|
|
|
|
public class FrameInfo
|
|
|
|
{
|
|
|
|
public string Sprite;
|
2016-04-20 21:55:33 +00:00
|
|
|
public string LightName;
|
2016-04-20 20:06:16 +00:00
|
|
|
public bool Bright;
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
// All we care about is the first sprite in the sequence
|
2017-01-16 08:20:47 +00:00
|
|
|
internal List<FrameInfo> sprites;
|
|
|
|
internal StateGoto gotostate;
|
|
|
|
internal DataManager dataman;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
2010-08-22 11:36:09 +00:00
|
|
|
|
|
|
|
public int SpritesCount { get { return sprites.Count; } }
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor
|
2017-01-16 08:20:47 +00:00
|
|
|
internal StateStructure(ActorStructure actor, ZDTextParser parser, DataManager dataman)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2010-08-19 15:06:15 +00:00
|
|
|
this.gotostate = null;
|
2017-01-16 08:20:47 +00:00
|
|
|
this.dataman = dataman;
|
2016-04-20 20:06:16 +00:00
|
|
|
this.sprites = new List<FrameInfo>();
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
2013-04-19 11:35:56 +00:00
|
|
|
//mxd
|
2017-01-16 12:10:11 +00:00
|
|
|
internal StateStructure(string spritename, DataManager dataman)
|
2014-12-03 23:15:26 +00:00
|
|
|
{
|
2013-04-19 11:35:56 +00:00
|
|
|
this.gotostate = null;
|
2017-01-16 12:10:11 +00:00
|
|
|
this.dataman = dataman;
|
2016-04-20 20:06:16 +00:00
|
|
|
this.sprites = new List<FrameInfo> { new FrameInfo { Sprite = spritename } };
|
2013-04-19 11:35:56 +00:00
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
2010-08-19 15:06:15 +00:00
|
|
|
|
|
|
|
// This finds the first valid sprite and returns it
|
2016-04-20 20:06:16 +00:00
|
|
|
public FrameInfo GetSprite(int index)
|
2010-08-28 16:48:17 +00:00
|
|
|
{
|
2016-04-20 20:06:16 +00:00
|
|
|
return GetSprite(index, new HashSet<StateStructure>());
|
2010-08-28 16:48:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This version of GetSprite uses a callstack to check if it isn't going into an endless loop
|
2016-04-20 20:06:16 +00:00
|
|
|
private FrameInfo GetSprite(int index, HashSet<StateStructure> prevstates)
|
2010-08-19 15:06:15 +00:00
|
|
|
{
|
2010-08-20 06:07:56 +00:00
|
|
|
// If we have sprite of our own, see if we can return this index
|
2015-12-17 10:07:28 +00:00
|
|
|
if(index < sprites.Count) return sprites[index];
|
2010-08-28 16:48:17 +00:00
|
|
|
|
2010-08-20 06:07:56 +00:00
|
|
|
// Otherwise, continue searching where goto tells us to go
|
2010-08-28 16:48:17 +00:00
|
|
|
if(gotostate != null)
|
2010-08-19 15:06:15 +00:00
|
|
|
{
|
|
|
|
// Find the class
|
2017-01-16 08:20:47 +00:00
|
|
|
ActorStructure a = dataman.GetZDoomActor(gotostate.ClassName);
|
2010-08-19 15:06:15 +00:00
|
|
|
if(a != null)
|
|
|
|
{
|
|
|
|
StateStructure s = a.GetState(gotostate.StateName);
|
2010-08-28 16:48:17 +00:00
|
|
|
if((s != null) && !prevstates.Contains(s))
|
2010-08-19 15:06:15 +00:00
|
|
|
{
|
2010-08-28 16:48:17 +00:00
|
|
|
prevstates.Add(this);
|
|
|
|
return s.GetSprite(gotostate.SpriteOffset, prevstates);
|
2010-08-19 15:06:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-08-28 16:48:17 +00:00
|
|
|
|
2010-08-20 06:07:56 +00:00
|
|
|
// If there is no goto keyword used, just give us one of our sprites if we can
|
2010-08-28 16:48:17 +00:00
|
|
|
if(sprites.Count > 0)
|
2010-08-20 06:07:56 +00:00
|
|
|
{
|
|
|
|
// The following behavior should really depend on the flow control keyword (loop or stop) but who cares.
|
|
|
|
return sprites[0];
|
|
|
|
}
|
2010-08-19 15:06:15 +00:00
|
|
|
|
2016-04-20 20:06:16 +00:00
|
|
|
return new FrameInfo();
|
2010-08-19 15:06:15 +00:00
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|