Fixed thing angles so that any value in the −32768..32767 range can be entered. Also fixed the thing angle in the info panel accordingly and optimized the rendering slightly.

This commit is contained in:
codeimp 2010-10-05 08:31:27 +00:00
parent 4807c6d9d1
commit 03a57f3284
11 changed files with 65 additions and 35 deletions

View file

@ -144,7 +144,7 @@ namespace CodeImp.DoomBuilder.Controls
action.Text = actioninfo;
position.Text = t.Position.x.ToString() + ", " + t.Position.y.ToString() + ", " + zinfo;
tag.Text = t.Tag.ToString();
angle.Text = Angle2D.RealToDoom(t.Angle).ToString() + "\u00B0";
angle.Text = t.AngleDoom.ToString() + "\u00B0";
// Sprite
if(ti.Sprite.ToLowerInvariant().StartsWith(DataManager.INTERNAL_PREFIX) && (ti.Sprite.Length > DataManager.INTERNAL_PREFIX.Length))

View file

@ -81,6 +81,8 @@ namespace CodeImp.DoomBuilder.IO
public override int MinThingType { get { return ushort.MinValue; } }
public override double MaxCoordinate { get { return (double)short.MaxValue; } }
public override double MinCoordinate { get { return (double)short.MinValue; } }
public override int MaxThingAngle { get { return short.MaxValue; } }
public override int MinThingAngle { get { return short.MinValue; } }
#endregion
@ -119,9 +121,8 @@ namespace CodeImp.DoomBuilder.IO
{
MemoryStream mem;
BinaryReader reader;
int num, i, x, y, type, flags;
int num, i, x, y, type, flags, angle;
Dictionary<string, bool> stringflags;
float angle;
Thing t;
// Get the lump from wad file
@ -140,7 +141,7 @@ namespace CodeImp.DoomBuilder.IO
// Read properties from stream
x = reader.ReadInt16();
y = reader.ReadInt16();
angle = Angle2D.DoomToReal(reader.ReadInt16());
angle = reader.ReadInt16();
type = reader.ReadUInt16();
flags = reader.ReadUInt16();
@ -447,7 +448,7 @@ namespace CodeImp.DoomBuilder.IO
// Write properties to stream
writer.Write((Int16)t.Position.x);
writer.Write((Int16)t.Position.y);
writer.Write((Int16)Angle2D.RealToDoom(t.Angle));
writer.Write((Int16)t.AngleDoom);
writer.Write((UInt16)t.Type);
writer.Write((UInt16)flags);
}

View file

@ -81,6 +81,8 @@ namespace CodeImp.DoomBuilder.IO
public override int MinThingType { get { return ushort.MinValue; } }
public override double MaxCoordinate { get { return (double)short.MaxValue; } }
public override double MinCoordinate { get { return (double)short.MinValue; } }
public override int MaxThingAngle { get { return short.MaxValue; } }
public override int MinThingAngle { get { return short.MinValue; } }
#endregion
@ -120,10 +122,9 @@ namespace CodeImp.DoomBuilder.IO
{
MemoryStream mem;
BinaryReader reader;
int num, i, tag, z, action, x, y, type, flags;
int num, i, tag, z, action, x, y, type, flags, angle;
int[] args = new int[Thing.NUM_ARGS];
Dictionary<string, bool> stringflags;
float angle;
Thing t;
// Get the lump from wad file
@ -144,7 +145,7 @@ namespace CodeImp.DoomBuilder.IO
x = reader.ReadInt16();
y = reader.ReadInt16();
z = reader.ReadInt16();
angle = Angle2D.DoomToReal(reader.ReadInt16());
angle = reader.ReadInt16();
type = reader.ReadUInt16();
flags = reader.ReadUInt16();
action = reader.ReadByte();
@ -465,7 +466,7 @@ namespace CodeImp.DoomBuilder.IO
writer.Write((Int16)t.Position.x);
writer.Write((Int16)t.Position.y);
writer.Write((Int16)t.Position.z);
writer.Write((Int16)Angle2D.RealToDoom(t.Angle));
writer.Write((Int16)t.AngleDoom);
writer.Write((UInt16)t.Type);
writer.Write((UInt16)flags);
writer.Write((Byte)t.Action);

View file

@ -67,5 +67,7 @@ namespace CodeImp.DoomBuilder.IO
int MinThingType { get; }
double MaxCoordinate { get; }
double MinCoordinate { get; }
int MaxThingAngle { get; }
int MinThingAngle { get; }
}
}

View file

@ -83,6 +83,8 @@ namespace CodeImp.DoomBuilder.IO
public abstract int MinThingType { get; }
public abstract double MaxCoordinate { get; }
public abstract double MinCoordinate { get; }
public abstract int MaxThingAngle { get; }
public abstract int MinThingAngle { get; }
#endregion

View file

@ -135,6 +135,8 @@ namespace CodeImp.DoomBuilder.IO
public override int MinThingType { get { return int.MinValue; } }
public override double MaxCoordinate { get { return (double)float.MaxValue; } }
public override double MinCoordinate { get { return (double)float.MinValue; } }
public override int MaxThingAngle { get { return int.MaxValue; } }
public override int MinThingAngle { get { return int.MinValue; } }
#endregion

View file

@ -198,7 +198,7 @@ namespace CodeImp.DoomBuilder.IO
Thing t = map.CreateThing();
if(t != null)
{
t.Update(type, x, y, height, Angle2D.DoomToReal(angledeg), stringflags, tag, special, args);
t.Update(type, x, y, height, angledeg, stringflags, tag, special, args);
// Custom fields
ReadCustomFields(c, t, "thing");

View file

@ -280,7 +280,7 @@ namespace CodeImp.DoomBuilder.IO
coll.Add("x", t.Position.x);
coll.Add("y", t.Position.y);
if(t.Position.z != 0.0f) coll.Add("height", (float)t.Position.z);
coll.Add("angle", Angle2D.RealToDoom(t.Angle));
coll.Add("angle", t.AngleDoom);
coll.Add("type", t.Type);
if(t.Action != 0) coll.Add("special", t.Action);
if(t.Args[0] != 0) coll.Add("arg0", t.Args[0]);

View file

@ -54,7 +54,8 @@ namespace CodeImp.DoomBuilder.Map
// Properties
private int type;
private Vector3D pos;
private float angle;
private int angledoom; // Angle as entered / stored in file
private float anglerad; // Angle in radians
private Dictionary<string, bool> flags;
private int tag;
private int action;
@ -73,8 +74,8 @@ namespace CodeImp.DoomBuilder.Map
public MapSet Map { get { return map; } }
public int Type { get { return type; } set { BeforePropsChange(); type = value; } }
public Vector3D Position { get { return pos; } }
public float Angle { get { return angle; } }
public int AngleDeg { get { return (int)Angle2D.RadToDeg(angle); } }
public float Angle { get { return anglerad; } }
public int AngleDoom { get { return angledoom; } }
internal Dictionary<string, bool> Flags { get { return flags; } }
public int Action { get { return action; } set { BeforePropsChange(); action = value; } }
public int[] Args { get { return args; } }
@ -172,13 +173,16 @@ namespace CodeImp.DoomBuilder.Map
flags.Add(t, b);
}
}
s.rwInt(ref type);
s.rwVector3D(ref pos);
s.rwFloat(ref angle);
s.rwInt(ref angledoom);
s.rwInt(ref tag);
s.rwInt(ref action);
for(int i = 0; i < NUM_ARGS; i++) s.rwInt(ref args[i]);
if(!s.IsWriting)
anglerad = Angle2D.DoomToReal(angledoom);
}
// This copies all properties to another thing
@ -188,7 +192,8 @@ namespace CodeImp.DoomBuilder.Map
// Copy properties
t.type = type;
t.angle = angle;
t.anglerad = anglerad;
t.angledoom = angledoom;
t.pos = pos;
t.flags = new Dictionary<string,bool>(flags);
t.tag = tag;
@ -383,7 +388,21 @@ namespace CodeImp.DoomBuilder.Map
BeforePropsChange();
// Change angle
this.angle = newangle;
this.anglerad = newangle;
this.angledoom = Angle2D.RealToDoom(newangle);
if(type != General.Map.Config.Start3DModeThingType)
General.Map.IsChanged = true;
}
// This rotates the thing
public void Rotate(int newangle)
{
BeforePropsChange();
// Change angle
this.anglerad = Angle2D.DoomToReal(newangle);
this.angledoom = newangle;
if(type != General.Map.Config.Start3DModeThingType)
General.Map.IsChanged = true;
@ -391,12 +410,13 @@ namespace CodeImp.DoomBuilder.Map
// This updates all properties
// NOTE: This does not update sector! (call DetermineSector)
public void Update(int type, float x, float y, float zoffset, float angle,
public void Update(int type, float x, float y, float zoffset, int angle,
Dictionary<string, bool> flags, int tag, int action, int[] args)
{
// Apply changes
this.type = type;
this.angle = angle;
this.anglerad = Angle2D.DoomToReal(angle);
this.angledoom = angle;
this.flags = new Dictionary<string, bool>(flags);
this.tag = tag;
this.action = action;
@ -412,7 +432,7 @@ namespace CodeImp.DoomBuilder.Map
// Lookup settings
ti = General.Map.Data.GetThingInfo(type);
// Apply size
size = ti.Radius;
fixedsize = ti.FixedSize;

View file

@ -958,21 +958,24 @@ namespace CodeImp.DoomBuilder.Rendering
verts[offset].v = 1f - 1f / 128f;
offset++;
float sinarrowsize = (float)Math.Sin(t.Angle + Angle2D.PI * 0.25f) * arrowsize;
float cosarrowsize = (float)Math.Cos(t.Angle + Angle2D.PI * 0.25f) * arrowsize;
// Setup rotated rect for arrow
verts[offset].x = screenpos.x + (float)Math.Sin(t.Angle - Angle2D.PI * 0.25f) * arrowsize;
verts[offset].y = screenpos.y + (float)Math.Cos(t.Angle - Angle2D.PI * 0.25f) * arrowsize;
verts[offset].x = screenpos.x + sinarrowsize;
verts[offset].y = screenpos.y + cosarrowsize;
verts[offset].c = -1;
verts[offset].u = 0.50f + t.IconOffset;
verts[offset].v = 0f;
offset++;
verts[offset].x = screenpos.x + (float)Math.Sin(t.Angle + Angle2D.PI * 0.25f) * arrowsize;
verts[offset].y = screenpos.y + (float)Math.Cos(t.Angle + Angle2D.PI * 0.25f) * arrowsize;
verts[offset].x = screenpos.x - cosarrowsize;
verts[offset].y = screenpos.y + sinarrowsize;
verts[offset].c = -1;
verts[offset].u = 0.75f + t.IconOffset;
verts[offset].v = 0f;
offset++;
verts[offset].x = screenpos.x + (float)Math.Sin(t.Angle - Angle2D.PI * 0.75f) * arrowsize;
verts[offset].y = screenpos.y + (float)Math.Cos(t.Angle - Angle2D.PI * 0.75f) * arrowsize;
verts[offset].x = screenpos.x + cosarrowsize;
verts[offset].y = screenpos.y - sinarrowsize;
verts[offset].c = -1;
verts[offset].u = 0.50f + t.IconOffset;
verts[offset].v = 1f;
@ -981,12 +984,12 @@ namespace CodeImp.DoomBuilder.Rendering
offset++;
verts[offset] = verts[offset - 2];
offset++;
verts[offset].x = screenpos.x + (float)Math.Sin(t.Angle + Angle2D.PI * 0.75f) * arrowsize;
verts[offset].y = screenpos.y + (float)Math.Cos(t.Angle + Angle2D.PI * 0.75f) * arrowsize;
verts[offset].x = screenpos.x - sinarrowsize;
verts[offset].y = screenpos.y - cosarrowsize;
verts[offset].c = -1;
verts[offset].u = 0.75f + t.IconOffset;
verts[offset].v = 1f;
// Done
return true;
}

View file

@ -116,9 +116,9 @@ namespace CodeImp.DoomBuilder.Windows
if(ft.Flags.ContainsKey(c.Tag.ToString())) c.Checked = ft.Flags[c.Tag.ToString()];
// Coordination
angle.Text = Angle2D.RealToDoom(ft.Angle).ToString();
angle.Text = ft.AngleDoom.ToString();
height.Text = ((int)ft.Position.z).ToString();
// Action/tags
action.Value = ft.Action;
tag.Text = ft.Tag.ToString();
@ -157,8 +157,7 @@ namespace CodeImp.DoomBuilder.Windows
}
// Coordination
int angledeg = Angle2D.RealToDoom(t.Angle);
if(angledeg.ToString() != angle.Text) angle.Text = "";
if(t.AngleDoom.ToString() != angle.Text) angle.Text = "";
if(((int)t.Position.z).ToString() != height.Text) height.Text = "";
// Action/tags
@ -317,7 +316,7 @@ namespace CodeImp.DoomBuilder.Windows
t.Type = General.Clamp(thingtype.GetResult(t.Type), General.Map.FormatInterface.MinThingType, General.Map.FormatInterface.MaxThingType);
// Coordination
t.Rotate(Angle2D.DoomToReal(angle.GetResult(Angle2D.RealToDoom(t.Angle))));
t.Rotate(angle.GetResult(t.AngleDoom));
t.Move(t.Position.x, t.Position.y, (float)height.GetResult((int)t.Position.z));
// Apply all flags