Skip to content

Commit

Permalink
Fix compatibility with UdonSDK 2020.02.23.13.54
Browse files Browse the repository at this point in the history
  • Loading branch information
MerlinVR committed Feb 24, 2020
1 parent 910a7b9 commit f667bb2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
1 change: 1 addition & 0 deletions Assets/UdonSharp/Editor/UdonSharpASTVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,7 @@ public override void VisitReturnStatement(ReturnStatementSyntax node)
}

visitorContext.uasmBuilder.AddJumpIndirect(visitorContext.returnJumpTarget);
//visitorContext.uasmBuilder.AddJumpToExit();
}

public override void VisitBreakStatement(BreakStatementSyntax node)
Expand Down
2 changes: 1 addition & 1 deletion Assets/UdonSharp/Editor/UdonSharpCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void Compile()
{
AssignHeapConstants(module);

EditorUtility.SetDirty(module.programAsset);
module.programAsset.ApplyProgram();
}
}
}
Expand Down
37 changes: 24 additions & 13 deletions Assets/UdonSharp/Editor/UdonSharpProgramAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using UnityEngine.Experimental.UIElements;
using VRC.Udon;
using VRC.Udon.Common.Interfaces;
using VRC.Udon.Editor.ProgramSources;
using VRC.Udon.Editor.ProgramSources.Attributes;
using VRC.Udon.Serialization.OdinSerializer;

[assembly: UdonProgramSourceNewMenu(typeof(UdonSharp.UdonSharpProgramAsset), "Udon C# Program Asset")]
Expand Down Expand Up @@ -41,7 +43,7 @@ void Start()

private static bool showProgramUasm = false;

public override void RunProgramSourceEditor(Dictionary<string, (object value, Type declaredType)> publicVariables, ref bool dirty)
protected override void DrawProgramSourceGUI(UdonBehaviour udonBehaviour, ref bool dirty)
{
EditorGUI.BeginChangeCheck();
MonoScript newSourceCsScript = (MonoScript)EditorGUILayout.ObjectField("Source Script", sourceCsScript, typeof(MonoScript), false);
Expand All @@ -58,7 +60,7 @@ public override void RunProgramSourceEditor(Dictionary<string, (object value, Ty
return;
}

DrawPublicVariables(publicVariables, ref dirty);
DrawPublicVariables(udonBehaviour, ref dirty);

DrawAssemblyErrorTextArea();

Expand Down Expand Up @@ -90,22 +92,21 @@ public override void RunProgramSourceEditor(Dictionary<string, (object value, Ty
//base.RunProgramSourceEditor(publicVariables, ref dirty);
}

protected override void DoRefreshProgramActions()
protected override void RefreshProgramImpl()
{
CompileCsProgram();
}

protected override (object value, Type declaredType) InitializePublicVariable(Type type, string symbol)
protected override object GetPublicVariableDefaultValue(string symbol, Type type)
{
return (program.Heap.GetHeapVariable(program.SymbolTable.GetAddressFromSymbol(symbol)), type);
return program.Heap.GetHeapVariable(program.SymbolTable.GetAddressFromSymbol(symbol));
}

public void CompileCsProgram()
{
UdonSharpCompiler compiler = new UdonSharpCompiler(this);
compiler.Compile();

EditorUtility.SetDirty(this);
SerializedProgramAsset.StoreProgram(program);
}

private void CompileAllCsPrograms()
Expand All @@ -128,6 +129,12 @@ public void AssembleCsProgram()
AssembleProgram();
}

public void ApplyProgram()
{
SerializedProgramAsset.StoreProgram(program);
EditorUtility.SetDirty(this);
}

public void SetUdonAssembly(string assembly)
{
udonAssembly = assembly;
Expand Down Expand Up @@ -452,13 +459,15 @@ private object DrawFieldForType(string fieldName, string symbol, (object value,

return value;
}

protected override void DrawFieldForTypeString(string symbol, ref (object value, Type declaredType) publicVariable, ref bool dirty, bool enabled)
protected override object DrawPublicVariableField(string symbol, object variableValue, Type variableType, ref bool dirty, bool enabled)
{
object newValue = variableValue;

EditorGUI.BeginDisabledGroup(!enabled);

bool shouldDraw = true;
bool isArray = publicVariable.declaredType.IsArray;
bool isArray = variableType.IsArray;

FieldDefinition symbolField;
if (fieldDefinitions != null && fieldDefinitions.TryGetValue(symbol, out symbolField))
Expand All @@ -481,12 +490,12 @@ protected override void DrawFieldForTypeString(string symbol, ref (object value,
EditorGUILayout.BeginHorizontal();

EditorGUI.BeginChangeCheck();
object newValue = DrawFieldForType(null, symbol, publicVariable, ref dirty, enabled);
newValue = DrawFieldForType(null, symbol, (variableValue, variableType), ref dirty, enabled);

if (EditorGUI.EndChangeCheck())
{
dirty = true;
publicVariable.value = newValue;
variableValue = newValue;
}

if (symbolField.fieldSymbol != null && symbolField.fieldSymbol.syncMode != UdonSyncMode.NotSynced)
Expand All @@ -502,6 +511,8 @@ protected override void DrawFieldForTypeString(string symbol, ref (object value,
}

EditorGUI.EndDisabledGroup();

return variableValue;
}
}

Expand Down
4 changes: 2 additions & 2 deletions Assets/UdonSharp/Editor/UdonSharpUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static int GetUdonInstructionSize(string instruction)
case "NOP":
case "POP":
case "COPY":
return 1;
return 4;
case "PUSH":
case "JUMP_IF_FALSE":
case "JUMP":
Expand All @@ -32,7 +32,7 @@ public static int GetUdonInstructionSize(string instruction)
// they get replaced towards the end of compilation with jumps to concrete addresses
case "JUMP_LABEL":
case "JUMP_IF_FALSE_LABEL":
return 5;
return 8;
case "ANNOTATION":
throw new System.NotImplementedException("ANNOTATION instruction is not yet implemented in Udon");
default:
Expand Down

0 comments on commit f667bb2

Please sign in to comment.