Skip to content
This repository has been archived by the owner on Feb 26, 2020. It is now read-only.

Commit

Permalink
Fix operators prematurely deleting themselves
Browse files Browse the repository at this point in the history
- Destroy was being called in the wrong place for unused operator objects
  as part of a fix for issue #36
  • Loading branch information
exodrifter committed Dec 14, 2014
1 parent 2ff71cf commit 2d3a791
Show file tree
Hide file tree
Showing 10 changed files with 193 additions and 173 deletions.
322 changes: 173 additions & 149 deletions Assets/Examples/RenPy/Tutorial/game/script-tutorial.asset

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Assets/Examples/TestScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 01846983878a06d4690fa28ff4c7f3c0, type: 3}
m_Name:
m_EditorClassIdentifier:
m_renPyScript: {fileID: 0}
m_renPyScript: {fileID: 11400000, guid: 6adc7978a99934c0c9027533587cadda, type: 2}
m_music: {fileID: 0}
m_sound: {fileID: 0}
m_voice: {fileID: 0}
Expand Down
1 change: 1 addition & 0 deletions Assets/Raconteur/RenPy/Editor/RenPyPostprocessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ private static void CreateRenPyAsset(RenPyFile handle)
} else {
AssetDatabase.CreateAsset(script, handle.path);
}
ExpressionParserFactory.DestroyUnusedExpressions();

// Serialize the parsed script
asset = AssetDatabase.LoadMainAssetAtPath(handle.path);
Expand Down
10 changes: 9 additions & 1 deletion Assets/Raconteur/RenPy/Script/Expressions/ExpressionParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public class ExpressionParser
/// </summary>
private List<Operator> m_operators;

/// <summary>
/// A list of operators that this parser has not used.
/// </summary>
private List<Operator> m_unusedOperators;

/// <summary>
/// The tokenizer for this parser
/// </summary>
Expand All @@ -36,6 +41,7 @@ public class ExpressionParser
public ExpressionParser()
{
m_operators = new List<Operator>();
m_unusedOperators = new List<Operator>();
m_tokenizer = new Tokenizer(true);
m_operatorNoOp = ScriptableObject.CreateInstance<OperatorNoOp>();
}
Expand All @@ -56,6 +62,7 @@ public void SetupOperator(Operator op)

m_tokenizer.SetupToken(op.Symbol);
m_operators.Add(op);
m_unusedOperators.Add(op);
}

#endregion
Expand All @@ -64,7 +71,7 @@ public void SetupOperator(Operator op)

public void Destroy()
{
foreach (Operator op in m_operators) {
foreach (Operator op in m_unusedOperators) {
ScriptableObject.DestroyImmediate(op, true);
}
}
Expand Down Expand Up @@ -102,6 +109,7 @@ private Expression ParseExpression(string[] tokens)
{
if(op.Symbol == token)
{
m_unusedOperators.Remove(op);
string[] left = GetRemainder(i-1, tokens);

Expression leftExp = ParseExpression(left);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ public static ExpressionParser GetRenPyParser()
return m_renPyExpressionParser;
}

public static void DestroyUnusedExpressions()
{
if (m_renPyExpressionParser != null) {
m_renPyExpressionParser.Destroy();
m_renPyExpressionParser = null;
}
}

/// <summary>
/// Returns a new Operator with the specified symbol.
/// </summary>
Expand Down
1 change: 0 additions & 1 deletion Assets/Raconteur/RenPy/Script/RenPyElif.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public override void Parse(ref RenPyScanner tokens)

var parser = ExpressionParserFactory.GetRenPyParser();
m_expression = parser.ParseExpression(expressionString);
parser.Destroy();
}

public override void Execute(RenPyState state)
Expand Down
1 change: 0 additions & 1 deletion Assets/Raconteur/RenPy/Script/RenPyIf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public override void Parse(ref RenPyScanner tokens)

var parser = ExpressionParserFactory.GetRenPyParser();
m_expression = parser.ParseExpression(expressionString);
parser.Destroy();
}

public override void Execute(RenPyState state)
Expand Down
1 change: 0 additions & 1 deletion Assets/Raconteur/RenPy/Script/RenPyVariable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public override void Parse(ref RenPyScanner tokens)

var parser = ExpressionParserFactory.GetRenPyParser();
m_expression = parser.ParseExpression(expressionString);
parser.Destroy();
}

public override void Execute(RenPyState state)
Expand Down
1 change: 0 additions & 1 deletion Assets/Raconteur/RenPy/Script/RenPyWhile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public override void Parse(ref RenPyScanner tokens)

var parser = ExpressionParserFactory.GetRenPyParser();
m_expression = parser.ParseExpression(expressionString);
parser.Destroy();
}

public override void Execute(RenPyState state)
Expand Down
19 changes: 1 addition & 18 deletions ProjectSettings/QualitySettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,4 @@ QualitySettings:
maximumLODLevel: 0
particleRaycastBudget: 4096
excludedTargetPlatforms: []
m_PerPlatformDefaultQuality:
Android: 2
BlackBerry: 2
FlashPlayer: 3
GLES Emulation: 3
PS3: 3
PS4: 3
PSM: 3
PSP2: 3
Samsung TV: 2
Standalone: 3
Tizen: 2
WP8: 3
Web: 3
Windows Store Apps: 3
XBOX360: 3
XboxOne: 3
iPhone: 2
m_PerPlatformDefaultQuality: {}

0 comments on commit 2d3a791

Please sign in to comment.