Added colormap rendering to Visual Mode (alpha value is ignored for now)

This commit is contained in:
MascaraSnake 2016-01-04 00:01:07 +01:00
parent a609c3c565
commit f69597c6d1
9 changed files with 92 additions and 40 deletions

View File

@ -104,6 +104,7 @@ namespace CodeImp.DoomBuilder.IO
public override Dictionary<int, int[]> VertexSlopeTypes { get { return vertexSlopeTypes; } }
public override int SlopeVertexType { get { return 9500; } }
public override int Custom3DFloorType { get { return 160; } }
public override int ColormapType { get { return -1; } }
#endregion

View File

@ -104,6 +104,7 @@ namespace CodeImp.DoomBuilder.IO
public override Dictionary<int, int[]> VertexSlopeTypes { get { return vertexSlopeTypes; } }
public override int SlopeVertexType { get { return 9500; } }
public override int Custom3DFloorType { get { return 160; } }
public override int ColormapType { get { return -1; } }
#endregion

View File

@ -76,5 +76,6 @@ namespace CodeImp.DoomBuilder.IO
Dictionary<int, int[]> VertexSlopeTypes { get; }
int SlopeVertexType { get; }
int Custom3DFloorType { get; }
int ColormapType { get; }
}
}

View File

@ -97,6 +97,7 @@ namespace CodeImp.DoomBuilder.IO
public abstract Dictionary<int, int[]> VertexSlopeTypes { get; }
public abstract int SlopeVertexType { get; }
public abstract int Custom3DFloorType { get; }
public abstract int ColormapType { get; }
#endregion

View File

@ -142,6 +142,7 @@ namespace CodeImp.DoomBuilder.IO
public override int SlopeVertexType { get { return 750; } }
public override int MaxThingHeight { get { return 4095; } }
public override int MinThingHeight { get { return 0; } }
public override int ColormapType { get { return 606; } }
#endregion
#region ================== Reading

View File

@ -154,6 +154,7 @@ namespace CodeImp.DoomBuilder.IO
public override Dictionary<int, int[]> VertexSlopeTypes { get { return vertexSlopeTypes; } }
public override int SlopeVertexType { get { return 9500; } }
public override int Custom3DFloorType { get { return 160; } }
public override int ColormapType { get { return -1; } }
#endregion

View File

@ -95,6 +95,7 @@ namespace CodeImp.DoomBuilder.Map
public bool IsSlope { get { return General.Map.FormatInterface.SlopeTypes.ContainsKey(Action); } }
public bool IsSlopeCopy { get { return General.Map.FormatInterface.SlopeCopyTypes.ContainsKey(Action); } }
public bool IsVertexSlope { get { return General.Map.FormatInterface.VertexSlopeTypes.ContainsKey(Action); } }
public bool IsColormap { get { return Action == General.Map.FormatInterface.ColormapType; } }
public int Tag { get { return tags[0]; } set { BeforePropsChange(); tags[0] = value; if((value < General.Map.FormatInterface.MinTag) || (value > General.Map.FormatInterface.MaxTag)) throw new ArgumentOutOfRangeException("Tag", "Invalid tag number"); } } //mxd
public List<int> Tags { get { return tags; } set { BeforePropsChange(); tags = value; } } //mxd
public float LengthSq { get { return lengthsq; } }
@ -833,6 +834,25 @@ namespace CodeImp.DoomBuilder.Map
return result;
}
//Read color value from texture name (#RRGGBBA)
public void ParseColor(string tex, out int color, out int alpha)
{
color = 0x000000;
alpha = 255;
if (tex.StartsWith("#") && tex.Length >= 7)
{
string colorString = tex.Substring(1,6);
Regex r = new Regex("^[A-F0-9]*$");
if (r.IsMatch(colorString)) color = Convert.ToInt32(colorString, 16);
if (tex.Length == 8)
{
char alphaChar = tex.ToUpper()[7];
if (alphaChar >= 'A' && alphaChar <= 'Z') alpha = (int)(((float)(alphaChar - 'A' + 10) / 25) * 255);
else if (alphaChar >= '0' && alphaChar <= '9') alpha = (int)(((float)(alphaChar - '0') / 25) * 255);
}
}
}
//Set slope arguments for SRB2-style slopes. See http://zdoom.org/wiki/Plane_Align.
public void SetSlopeArgs()
{

View File

@ -948,8 +948,32 @@ namespace CodeImp.DoomBuilder.BuilderModes
}
}
if (General.Map.SRB2)
{
//MascaraSnake: Colormap
if (l.IsColormap && l.Front != null)
{
int sectortag = l.Tag;
int color;
int alpha;
l.ParseColor(l.Front.HighTexture, out color, out alpha);
if (sectortags.ContainsKey(sectortag))
{
List<Sector> sectors = sectortags[sectortag];
foreach (Sector s in sectors)
{
s.Fields.BeforeFieldsChange();
if (s.Fields.ContainsKey("lightcolor")) s.Fields["lightcolor"] = new UniValue(UniversalType.Color, color);
else s.Fields.Add("lightcolor", new UniValue(UniversalType.Color, color));
//TODO: Find out why the alpha value is ignored.
/*if (s.Fields.ContainsKey("lightalpha")) s.Fields["lightalpha"] = new UniValue(UniversalType.Integer, alpha);
else s.Fields.Add("lightalpha", new UniValue(UniversalType.Integer, alpha));*/
}
}
}
// MascaraSnake: Vertex slopes, SRB2-style
if (General.Map.SRB2 && l.IsVertexSlope)
if (l.IsVertexSlope)
{
l.SetVertexSlopeArgs();
bool slopefloor = l.Args[1] == 0;
@ -999,6 +1023,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
sd.AddEffectSRB2ThingVertexSlope(slopevertices, slopefloor);
}
}
}
// MascaraSnake: 3D floor handling
// ========== Sector 3D floor (see http://zdoom.org/wiki/Sector_Set3dFloor) ==========

View File

@ -267,6 +267,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
bool fabs = sector.Fields.GetValue("lightfloorabsolute", false);
int clight = sector.Fields.GetValue("lightceiling", 0);
bool cabs = sector.Fields.GetValue("lightceilingabsolute", false);
//int alpha = sector.Fields.GetValue("lightalpha", 255);
// Determine colors & light levels
PixelColor lightcolor = PixelColor.FromInt(color);