Skip to content

Commit

Permalink
Merge branch 'master' into remove_obsolete_error_uses
Browse files Browse the repository at this point in the history
  • Loading branch information
wixoaGit authored Mar 26, 2024
2 parents cbcf902 + 507bfc2 commit bc11c2a
Show file tree
Hide file tree
Showing 25 changed files with 273 additions and 75 deletions.
4 changes: 2 additions & 2 deletions DMCompiler/Bytecode/DreamProcOpcode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public enum DreamProcOpcode : byte {
[OpcodeMetadata(stackDelta: 1)] PushType = 0x2,
[OpcodeMetadata(stackDelta: 1)] PushString = 0x3,
FormatString = 0x4,
[OpcodeMetadata(stackDelta: -2)]SwitchCaseRange = 0x5, //This could either shrink the stack by 2 or 3. Assume 2.
[OpcodeMetadata(stackDelta: -2)] SwitchCaseRange = 0x5, //This could either shrink the stack by 2 or 3. Assume 2.
[OpcodeMetadata(stackDelta: 1)] PushReferenceValue = 0x6, // TODO: Local refs should be pure, and other refs that aren't modified
//0x7
Rgb = 0x7,
[OpcodeMetadata(stackDelta: -1)] Add = 0x8,
Assign = 0x9,
Call = 0xA,
Expand Down
4 changes: 4 additions & 0 deletions DMCompiler/Compiler/DM/AST/DMAST.Expression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ public sealed class DMASTGradient(Location location, DMASTCallParameter[] parame
public readonly DMASTCallParameter[] Parameters = parameters;
}

public sealed class DMASTRgb(Location location, DMASTCallParameter[] parameters) : DMASTExpression(location) {
public readonly DMASTCallParameter[] Parameters = parameters;
}

public sealed class DMASTPick(Location location, DMASTPick.PickValue[] values) : DMASTExpression(location) {
public struct PickValue(DMASTExpression? weight, DMASTExpression value) {
public readonly DMASTExpression? Weight = weight;
Expand Down
6 changes: 6 additions & 0 deletions DMCompiler/Compiler/DM/DMParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2613,6 +2613,12 @@ private void BracketWhitespace() {
return new DMASTLocate(callLoc, type, container);
}
}
case "rgb": {
if (callParameters.Length is < 3 or > 5)
Error("Expected 3 to 5 arguments for rgb()");

Check failure on line 2618 in DMCompiler/Compiler/DM/DMParser.cs

View workflow job for this annotation

GitHub Actions / build

The name 'Error' does not exist in the current context

Check failure on line 2618 in DMCompiler/Compiler/DM/DMParser.cs

View workflow job for this annotation

GitHub Actions / build

The name 'Error' does not exist in the current context

Check failure on line 2618 in DMCompiler/Compiler/DM/DMParser.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The name 'Error' does not exist in the current context

Check failure on line 2618 in DMCompiler/Compiler/DM/DMParser.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The name 'Error' does not exist in the current context

return new DMASTRgb(identifier.Location, callParameters);
}
default:
return new DMASTProcCall(callLoc, new DMASTCallableProcIdentifier(callLoc, identifier.Identifier), callParameters);
}
Expand Down
10 changes: 7 additions & 3 deletions DMCompiler/Compiler/DMPreprocessor/DMPreprocessorLexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,16 @@ public Token NextToken(bool ignoreWhitespace = false) {

if(nextCharCanTerm && c == '}')
break;
else {

if (HandleLineEnd()) {
TokenTextBuilder.Append('\n');
} else {
TokenTextBuilder.Append(c);
nextCharCanTerm = false;
}

if (c == '"')
nextCharCanTerm = true;

} while (!AtEndOfSource());
} else {
while (c != delimiter && !AtLineEnd() && !AtEndOfSource()) {
Expand Down Expand Up @@ -492,7 +494,9 @@ private Token LexString(bool isLong) {
while (!(!isLong && AtLineEnd()) && !AtEndOfSource()) {
char stringC = GetCurrent();

if (stringC == '[') {
if (HandleLineEnd()) {
textBuilder.Append('\n');
} else if (stringC == '[') {
textBuilder.Append(stringC);
stringTokens.Enqueue(isConstant // First case of '['
? CreateToken(TokenType.DM_Preproc_StringBegin, tokenTextStart + textBuilder, textBuilder.ToString())
Expand Down
2 changes: 2 additions & 0 deletions DMCompiler/DM/Builders/DMExpressionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ public static DMExpression BuildExpression(DMASTExpression expression, DMObject
case DMASTGradient gradient:
return new Gradient(gradient.Location,
new ArgumentList(gradient.Location, dmObject, proc, gradient.Parameters));
case DMASTRgb rgb:
return new Rgb(rgb.Location, new ArgumentList(rgb.Location, dmObject, proc, rgb.Parameters));
case DMASTLocateCoordinates locateCoordinates:
return new LocateCoordinates(locateCoordinates.Location,
BuildExpression(locateCoordinates.X, dmObject, proc, inferredPath),
Expand Down
2 changes: 1 addition & 1 deletion DMCompiler/DM/Builders/DMObjectBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,6 @@ private static bool IsValidRighthandSide(DMObject currentObject, DMVariable vari
return expression switch {
//TODO: A better way of handling procs evaluated at compile time
Expressions.ProcCall procCall => procCall.GetTargetProc(currentObject).Proc?.Name switch {
"rgb" => true,
"generator" => true,
"matrix" => true,
"icon" => true,
Expand All @@ -478,6 +477,7 @@ private static bool IsValidRighthandSide(DMObject currentObject, DMVariable vari
Expressions.DimensionalList => true,
Expressions.NewList => true,
Expressions.NewPath => true,
Expressions.Rgb => true,
// TODO: Check for circular reference loops here
// (Note that we do accidentally support global-field access somewhat when it gets const-folded by TryAsConstant before we get here)
Expressions.GlobalField => false,
Expand Down
7 changes: 7 additions & 0 deletions DMCompiler/DM/DMProc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,13 @@ public void Gradient(DMCallArgumentsType argumentsType, int argumentStackSize) {
WriteInt(argumentStackSize);
}

public void Rgb(DMCallArgumentsType argumentsType, int argumentStackSize) {
ResizeStack(-(argumentStackSize - 1)); // Pops arguments, pushes rgb result
WriteOpcode(DreamProcOpcode.Rgb);
WriteByte((byte)argumentsType);
WriteInt(argumentStackSize);
}

public void PickWeighted(int count) {
ResizeStack(-(count * 2 - 1));
WriteOpcode(DreamProcOpcode.PickWeighted);
Expand Down
12 changes: 12 additions & 0 deletions DMCompiler/DM/Expressions/Builtins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,18 @@ public override void EmitPushValue(DMObject dmObject, DMProc proc) {
}
}

/// rgb(R, G, B)
/// rgb(R, G, B, A)
/// rgb(x, y, z, space)
/// rgb(x, y, z, a, space)
internal sealed class Rgb(Location location, ArgumentList arguments) : DMExpression(location) {
public override void EmitPushValue(DMObject dmObject, DMProc proc) {
var argInfo = arguments.EmitArguments(dmObject, proc);

proc.Rgb(argInfo.Type, argInfo.StackSize);
}
}

// pick(prob(50);x, prob(200);y)
// pick(50;x, 200;y)
// pick(x, y)
Expand Down
1 change: 0 additions & 1 deletion DMCompiler/DMStandard/_Standard.dm
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ proc/range(Dist, Center)
proc/ref(Object)
proc/replacetext(Haystack, Needle, Replacement, Start = 1, End = 0)
proc/replacetextEx(Haystack, Needle, Replacement, Start = 1, End = 0)
proc/rgb(R, G, B, A)
proc/rgb2num(color, space = COLORSPACE_RGB)
proc/roll(ndice = 1, sides)
proc/round(A, B)
Expand Down
2 changes: 1 addition & 1 deletion OpenDreamClient/Input/MouseInputSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void HandleStatClick(string atomRef, bool isMiddle) {
private bool OnPress(ScalingViewport viewport, GUIBoundKeyEventArgs args) {
if (args.Function == EngineKeyFunctions.UIRightClick) { //either turf or atom was clicked, and it was a right-click
var mapCoords = viewport.ScreenToMap(args.PointerLocation.Position);
var entities = _lookupSystem.GetEntitiesInRange(mapCoords, 0.01f);
var entities = _lookupSystem.GetEntitiesInRange(mapCoords, 0.01f, LookupFlags.Uncontained | LookupFlags.Approximate);

//TODO filter entities by the valid verbs that exist on them
//they should only show up if there is a verb attached to usr which matches the filter in world syntax
Expand Down
2 changes: 1 addition & 1 deletion OpenDreamClient/Interface/Controls/ControlChild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private void UpdateGrid() {
_grid.SplitFraction = ChildDescriptor.Splitter / 100f;
}

public override bool TryGetProperty(string property, out string value) {
public override bool TryGetProperty(string property, out string value) {
switch (property) {
case "splitter":
value = $"{_grid.SplitFraction * 100}";
Expand Down
35 changes: 21 additions & 14 deletions OpenDreamClient/Interface/Controls/ControlWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,35 +92,42 @@ public void RegisterOnClydeWindow(IClydeWindow window) {
}

public void UpdateAnchors() {
var windowSize = Size.GetValueOrDefault();
var windowSize = Size;
if (windowSize.X == 0)
windowSize.X = 640;
windowSize.X = _canvas.PixelWidth;
if (windowSize.Y == 0)
windowSize.Y = 440;
windowSize.Y = _canvas.PixelHeight;

ChildControls.Sort((a, b) => { //need a resort if size and pos have changed
if(a.Pos.X <= b.Pos.X || a.Pos.Y <= b.Pos.Y)
return 1;
else
return -1;
});

for (int i = 0; i < ChildControls.Count; i++) {
InterfaceControl control = ChildControls[i];
var element = control.UIElement;
var elementPos = control.Pos.GetValueOrDefault();
var elementSize = control.Size.GetValueOrDefault();
var elementPos = control.Pos;
var elementSize = control.Size;

if (control.Size?.Y == 0) {
if (control.Size.Y == 0) {
elementSize.Y = (windowSize.Y - elementPos.Y);
if (ChildControls.Count - 1 > i) {
if (ChildControls[i + 1].Pos != null && ChildControls[i + 1].UIElement.Visible) {
var nextElementPos = ChildControls[i + 1].Pos.GetValueOrDefault();
if (ChildControls[i + 1].UIElement.Visible) {
var nextElementPos = ChildControls[i + 1].Pos;
elementSize.Y = nextElementPos.Y - elementPos.Y;
}
}

element.SetHeight = ((float)elementSize.Y / windowSize.Y) * _canvas.Height;
}

if (control.Size?.X == 0) {
if (control.Size.X == 0) {
elementSize.X = (windowSize.X - elementPos.X);
if (ChildControls.Count - 1 > i) {
if (ChildControls[i + 1].Pos != null && ChildControls[i + 1].UIElement.Visible) {
var nextElementPos = ChildControls[i + 1].Pos.GetValueOrDefault();
if (ChildControls[i + 1].UIElement.Visible) {
var nextElementPos = ChildControls[i + 1].Pos;
if (nextElementPos.X < (elementSize.X + elementPos.X) &&
nextElementPos.Y < (elementSize.Y + elementPos.Y))
elementSize.X = nextElementPos.X - elementPos.X;
Expand Down Expand Up @@ -225,8 +232,8 @@ public override void AddChild(ElementDescriptor descriptor) {

// Can't have out-of-order components, so make sure they're ordered properly
if (ChildControls.Count > 0) {
var prevPos = ChildControls[^1].Pos.GetValueOrDefault();
var curPos = control.Pos.GetValueOrDefault();
var prevPos = ChildControls[^1].Pos;
var curPos = control.Pos;
if (prevPos.X <= curPos.X && prevPos.Y <= curPos.Y)
ChildControls.Add(control);
else {
Expand All @@ -235,7 +242,7 @@ public override void AddChild(ElementDescriptor descriptor) {

int i = 0;
while (i < ChildControls.Count) {
prevPos = ChildControls[i].Pos.GetValueOrDefault();
prevPos = ChildControls[i].Pos;
if (prevPos.X <= curPos.X && prevPos.Y <= curPos.Y)
i++;
else
Expand Down
4 changes: 2 additions & 2 deletions OpenDreamClient/Interface/Controls/InterfaceControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace OpenDreamClient.Interface.Controls;
public abstract class InterfaceControl : InterfaceElement {
public readonly Control UIElement;
public bool IsDefault => ControlDescriptor.IsDefault;
public Vector2i? Size => ControlDescriptor.Size;
public Vector2i? Pos => ControlDescriptor.Pos;
public Vector2i Size => ControlDescriptor.Size.GetValueOrDefault();
public Vector2i Pos => ControlDescriptor.Pos.GetValueOrDefault();
public Vector2i? Anchor1 => ControlDescriptor.Anchor1;
public Vector2i? Anchor2 => ControlDescriptor.Anchor2;

Expand Down
2 changes: 1 addition & 1 deletion OpenDreamPackageTool/ClientPackaging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private static void Build(Program.ClientOptions options) {
ArgumentList = {
"build",
"OpenDreamClient/OpenDreamClient.csproj",
"-c", "Release",
"-c", options.BuildConfiguration,
"--nologo",
"/v:m",
"/t:Rebuild",
Expand Down
10 changes: 10 additions & 0 deletions OpenDreamPackageTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public static class Program {
public class Options {
public string OutputDir = "release/";
public bool SkipBuild;
public string BuildConfiguration = "Release";
}

public class ServerOptions : Options {
Expand Down Expand Up @@ -96,6 +97,9 @@ private static bool TryParseArgs(string[] args, [NotNullWhen(true)] out Options?
case "--skip-build":
serverOptions.SkipBuild = true;
break;
case "--debug":
serverOptions.BuildConfiguration = "Debug";
break;
case "--platform":
case "-p":
if (i + 1 >= args.Length) {
Expand Down Expand Up @@ -132,6 +136,9 @@ private static bool TryParseArgs(string[] args, [NotNullWhen(true)] out Options?
case "--skip-build":
clientOptions.SkipBuild = true;
break;
case "--debug":
clientOptions.BuildConfiguration = "Debug";
break;
default:
Console.Error.WriteLine($"Invalid argument '{arg}'");
return false;
Expand All @@ -156,6 +163,9 @@ private static bool TryParseArgs(string[] args, [NotNullWhen(true)] out Options?
case "--skip-build":
tgsOptions.SkipBuild = true;
break;
case "--debug":
tgsOptions.BuildConfiguration = "Debug";
break;
default:
Console.Error.WriteLine($"Invalid argument '{arg}'");
return false;
Expand Down
8 changes: 4 additions & 4 deletions OpenDreamPackageTool/ServerPackaging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private static void BuildPlatform(PlatformReg platform, Program.ServerOptions op
ArgumentList = {
"build",
"OpenDreamServer/OpenDreamServer.csproj",
"-c", "Release",
"-c", options.BuildConfiguration,
"--nologo",
"/v:m",
$"/p:TargetOS={platform.TargetOs}",
Expand All @@ -137,7 +137,7 @@ private static void BuildPlatform(PlatformReg platform, Program.ServerOptions op
}
}).Wait();

PublishClientServer(platform.RId, platform.TargetOs);
PublishClientServer(platform.RId, platform.TargetOs, options.BuildConfiguration);
}

string releaseDir = options.OutputDir;
Expand All @@ -155,15 +155,15 @@ private static void BuildPlatform(PlatformReg platform, Program.ServerOptions op
}
}

private static void PublishClientServer(string platformRId, string targetOs) {
private static void PublishClientServer(string platformRId, string targetOs, string buildConfig) {
ProcessHelpers.RunCheck(new ProcessStartInfo {
FileName = "dotnet",
ArgumentList = {
"publish",
"RobustToolbox/Robust.Server/Robust.Server.csproj",
"--runtime", platformRId,
"--no-self-contained",
"-c", "Release",
"-c", buildConfig,
$"/p:TargetOS={targetOs}",
"/p:FullRelease=True",
"/m"
Expand Down
9 changes: 5 additions & 4 deletions OpenDreamPackageTool/TgsPackaging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static void Package(Program.TgsOptions options) {
Platform = platform.RId,
HybridAcz = true, // Force Hybrid ACZ with TGS
SkipBuild = options.SkipBuild,
BuildConfiguration = options.BuildConfiguration,
InPlatformSubDir = false,
TgsEngineBuild = true
});
Expand All @@ -33,7 +34,7 @@ public static void Package(Program.TgsOptions options) {
ArgumentList = {
"build",
"DMCompiler/DMCompiler.csproj",
"-c", "Release",
"-c", options.BuildConfiguration,
"--nologo",
"/v:m",
$"/p:TargetOS={platform.TargetOs}",
Expand All @@ -42,14 +43,14 @@ public static void Package(Program.TgsOptions options) {
}
}).Wait();

PublishCompiler(platform.RId, platform.TargetOs);
PublishCompiler(platform.RId, platform.TargetOs, options.BuildConfiguration);
}

// Package the compiler to <output dir>/bin/compiler
Program.CopyDirectory($"bin/DMCompiler/{platform.RId}/publish", Path.Combine(options.OutputDir, "bin", "compiler"));
}

private static void PublishCompiler(string platformRId, string targetOs) {
private static void PublishCompiler(string platformRId, string targetOs, string buildConfig) {
// TODO: Add a --compiler option to the package tool
ProcessHelpers.RunCheck(new ProcessStartInfo {
FileName = "dotnet",
Expand All @@ -58,7 +59,7 @@ private static void PublishCompiler(string platformRId, string targetOs) {
"DMCompiler/DMCompiler.csproj",
"--runtime", platformRId,
"--no-self-contained",
"-c", "Release",
"-c", buildConfig,
$"/p:TargetOS={targetOs}",
"/m"
}
Expand Down
5 changes: 0 additions & 5 deletions OpenDreamRuntime/DreamValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,6 @@ public bool IsNull {
get => Type == DreamValueType.DreamObject && (_refValue == null || Unsafe.As<DreamObject>(_refValue).Deleted);
}

private DreamValue(DreamValueType type, object refValue) {
Type = type;
_refValue = refValue;
}

public override string ToString() {
if (Type == DreamValueType.Float)
return _floatValue.ToString();
Expand Down
Loading

0 comments on commit bc11c2a

Please sign in to comment.