public void Reflect(Object obj, Attribute attribute, bool initialize = false) { int vid = m_config.m_reflection_property; if (vid != 0) { int component_type_id = ComponentTypeRegistry.GetVariableOwnerComponentID(vid); if (component_type_id != 0) { Component component = obj.GetComponent(component_type_id); if (component != null) { FixPoint old_value = component.GetVariable(vid); FixPoint new_value = attribute.Value; if (old_value != new_value) { component.SetVariable(vid, attribute.Value); } } } } vid = m_config.m_clamp_property; if (vid != 0) { int component_type_id = ComponentTypeRegistry.GetVariableOwnerComponentID(vid); if (component_type_id != 0) { Component component = obj.GetComponent(component_type_id); if (component != null) { FixPoint old_value = component.GetVariable(vid); if (initialize) { if (old_value < m_config.m_clamp_min_value) //ZZWTODO tricky { component.SetVariable(vid, attribute.Value); } } else { FixPoint new_value = FixPoint.Clamp(old_value, m_config.m_clamp_min_value, attribute.Value); if (old_value != new_value) { component.SetVariable(vid, new_value); } } } } } //END }
public virtual FixPoint Evaluate(IExpressionVariableProvider variable_provider) { Stack <FixPoint> stack = new Stack <FixPoint>(); FixPoint var1, var2, var3; int index = 0; int total_count = m_instructions.Count; while (index < total_count) { OperationCode op_code = (OperationCode)m_instructions[index]; ++index; switch (op_code) { case OperationCode.PUSH_NUMBER: stack.Push(FixPoint.CreateFromRaw(m_instructions[index])); ++index; break; case OperationCode.PUSH_VARIABLE: if (variable_provider != null) { var1 = variable_provider.GetVariable(m_variables[(int)m_instructions[index]], 0); stack.Push(var1); } else { stack.Push(FixPoint.Zero); } ++index; break; case OperationCode.NEGATE: var1 = stack.Pop(); stack.Push(-var1); break; case OperationCode.ADD: var2 = stack.Pop(); var1 = stack.Pop(); stack.Push(var1 + var2); break; case OperationCode.SUBTRACT: var2 = stack.Pop(); var1 = stack.Pop(); stack.Push(var1 - var2); break; case OperationCode.MULTIPLY: var2 = stack.Pop(); var1 = stack.Pop(); stack.Push(var1 * var2); break; case OperationCode.DIVIDE: var2 = stack.Pop(); var1 = stack.Pop(); stack.Push(var1 / var2); break; case OperationCode.SIN: var1 = stack.Pop(); stack.Push(FixPoint.Sin(var1)); break; case OperationCode.COS: var1 = stack.Pop(); stack.Push(FixPoint.Cos(var1)); break; case OperationCode.TAN: var1 = stack.Pop(); stack.Push(FixPoint.Tan(var1)); break; case OperationCode.SQRT: var1 = stack.Pop(); stack.Push(FixPoint.Sqrt(var1)); break; case OperationCode.MIN: var2 = stack.Pop(); var1 = stack.Pop(); stack.Push(FixPoint.Min(var1, var2)); break; case OperationCode.MAX: var2 = stack.Pop(); var1 = stack.Pop(); stack.Push(FixPoint.Max(var1, var2)); break; case OperationCode.CLAMP: var3 = stack.Pop(); var2 = stack.Pop(); var1 = stack.Pop(); stack.Push(FixPoint.Clamp(var1, var2, var3)); break; case OperationCode.EQUAL: var2 = stack.Pop(); var1 = stack.Pop(); if (var1 == var2) { stack.Push(FixPoint.One); } else { stack.Push(FixPoint.Zero); } break; case OperationCode.NOT_EQUAL: var2 = stack.Pop(); var1 = stack.Pop(); if (var1 != var2) { stack.Push(FixPoint.One); } else { stack.Push(FixPoint.Zero); } break; case OperationCode.GREATER: var2 = stack.Pop(); var1 = stack.Pop(); if (var1 > var2) { stack.Push(FixPoint.One); } else { stack.Push(FixPoint.Zero); } break; case OperationCode.GREATER_EQUAL: var2 = stack.Pop(); var1 = stack.Pop(); if (var1 >= var2) { stack.Push(FixPoint.One); } else { stack.Push(FixPoint.Zero); } break; case OperationCode.LESS: var2 = stack.Pop(); var1 = stack.Pop(); if (var1 < var2) { stack.Push(FixPoint.One); } else { stack.Push(FixPoint.Zero); } break; case OperationCode.LESS_EQUAL: var2 = stack.Pop(); var1 = stack.Pop(); if (var1 <= var2) { stack.Push(FixPoint.One); } else { stack.Push(FixPoint.Zero); } break; case OperationCode.AND: var2 = stack.Pop(); var1 = stack.Pop(); if (var1 != FixPoint.Zero && var2 != FixPoint.Zero) { stack.Push(FixPoint.One); } else { stack.Push(FixPoint.Zero); } break; case OperationCode.OR: var2 = stack.Pop(); var1 = stack.Pop(); if (var1 != FixPoint.Zero || var2 != FixPoint.Zero) { stack.Push(FixPoint.One); } else { stack.Push(FixPoint.Zero); } break; case OperationCode.NOT: var1 = stack.Pop(); if (var1 == FixPoint.Zero) { stack.Push(FixPoint.One); } else { stack.Push(FixPoint.Zero); } break; case OperationCode.AND_BITWISE: var2 = stack.Pop(); var1 = stack.Pop(); stack.Push(var1 & var2); break; case OperationCode.OR_BITWISE: var2 = stack.Pop(); var1 = stack.Pop(); stack.Push(var1 | var2); break; case OperationCode.CONDITIONAL_EXPRESSION: var3 = stack.Pop(); var2 = stack.Pop(); var1 = stack.Pop(); if (var1 != FixPoint.Zero) { stack.Push(var2); } else { stack.Push(var3); } break; default: break; } } return(stack.Pop()); }