Beispiel #1
0
        public void SceneGraphLayers(ScriptThread thread)
        {
            int[] layers     = SceneGraph.Layers;
            int   arrayIndex = thread.AllocateArray(DataType.Int, SceneGraph.Layers.Length);

            for (int i = 0; i < SceneGraph.Layers.Length; i++)
            {
                thread.SetArrayElement(arrayIndex, i, layers[i]);
            }
            thread.SetReturnValueArray(arrayIndex);
        }
Beispiel #2
0
        public void Explode(ScriptThread thread)
        {
            string explodee  = thread.GetStringParameter(0);
            char   seperator = thread.GetStringParameter(1)[0];

            string[] exploded = explodee.Split(new char[] { seperator });

            int arrayMemoryIndex = thread.AllocateArray(DataType.String, exploded.Length);

            for (int i = 0; i < exploded.Length; i++)
            {
                thread.SetArrayElement(arrayMemoryIndex, i, exploded[i]);
            }

            thread.SetReturnValueArray(arrayMemoryIndex);
        }
Beispiel #3
0
        /// <summary>
        ///     Called when the value of a variable is changed in the property list view.
        /// </summary>
        /// <param name="item">Property item that was changed</param>
        /// <param name="value">Newly changed value.</param>
        public void SetVariable(PropertyListViewItem item, object value)
        {
            // Is it a global variable?
            if (item.Category == _globalCategory)
            {
                foreach (Symbol symbol in _scriptThread.Process.GlobalScope.Symbols)
                {
                    if (symbol.Type == SymbolType.Variable && symbol.Identifier == item.Name)
                    {
                        VariableSymbol variable = symbol as VariableSymbol;
                        if (variable.IsArray == true)
                        {
                            int index = _scriptThread.AllocateArray(variable.DataType.DataType, ((Array)value).Length);
                            switch (variable.DataType.DataType)
                            {
                            case DataType.Bool:
                                for (int i = 0; i < ((bool[])value).Length; i++)
                                {
                                    _scriptThread.SetArrayElement(index, i, ((bool[])value)[i]);
                                }
                                break;

                            case DataType.Byte:
                                for (int i = 0; i < ((byte[])value).Length; i++)
                                {
                                    _scriptThread.SetArrayElement(index, i, ((byte[])value)[i]);
                                }
                                break;

                            case DataType.Double:
                                for (int i = 0; i < ((double[])value).Length; i++)
                                {
                                    _scriptThread.SetArrayElement(index, i, ((double[])value)[i]);
                                }
                                break;

                            case DataType.Float:
                                for (int i = 0; i < ((float[])value).Length; i++)
                                {
                                    _scriptThread.SetArrayElement(index, i, ((float[])value)[i]);
                                }
                                break;

                            case DataType.Int:
                                for (int i = 0; i < ((int[])value).Length; i++)
                                {
                                    _scriptThread.SetArrayElement(index, i, ((int[])value)[i]);
                                }
                                break;

                            case DataType.Long:
                                for (int i = 0; i < ((bool[])value).Length; i++)
                                {
                                    _scriptThread.SetArrayElement(index, i, ((long[])value)[i]);
                                }
                                break;

                            case DataType.Object:
                                for (int i = 0; i < ((int[])value).Length; i++)
                                {
                                    _scriptThread.SetArrayElement(index, i, ((int[])value)[i] >= _scriptThread.Process.ObjectHeap.Length ? null : _scriptThread.Process.ObjectHeap[((int[])value)[i]]);
                                }
                                break;

                            case DataType.Short:
                                for (int i = 0; i < ((short[])value).Length; i++)
                                {
                                    _scriptThread.SetArrayElement(index, i, ((short[])value)[i]);
                                }
                                break;

                            case DataType.String:
                                for (int i = 0; i < ((string[])value).Length; i++)
                                {
                                    _scriptThread.SetArrayElement(index, i, ((string[])value)[i]);
                                }
                                break;
                            }
                            _scriptThread.SetGlobalArray(variable.Identifier, index);
                        }
                        else
                        {
                            switch (variable.DataType.DataType)
                            {
                            case DataType.Bool: _scriptThread.SetGlobalVariable(variable.Identifier, (bool)value); break;

                            case DataType.Byte: _scriptThread.SetGlobalVariable(variable.Identifier, (byte)value); break;

                            case DataType.Double: _scriptThread.SetGlobalVariable(variable.Identifier, (double)value); break;

                            case DataType.Float: _scriptThread.SetGlobalVariable(variable.Identifier, (float)value); break;

                            case DataType.Int: _scriptThread.SetGlobalVariable(variable.Identifier, (int)value); break;

                            case DataType.Long: _scriptThread.SetGlobalVariable(variable.Identifier, (long)value); break;

                            case DataType.Object:
                                RuntimeValue variableValue = _scriptThread.GetRuntimeValueGlobal(variable.Identifier);     // Can be optimized.
                                _scriptThread.SetGlobalVariable(variable.Identifier, (int)value >= _scriptThread.Process.ObjectHeap.Length ? null : _scriptThread.Process.ObjectHeap[variableValue.ObjectIndex]);
                                break;

                            case DataType.Short: _scriptThread.SetGlobalVariable(variable.Identifier, (short)value); break;

                            case DataType.String: _scriptThread.SetGlobalVariable(variable.Identifier, value as string); break;
                            }
                        }
                    }
                }
            }

            // No? Is it a local then?
            else if (item.Category == _localCategory)
            {
                foreach (Symbol symbol in _lastScope.Symbols)
                {
                    if (symbol.Type == SymbolType.Variable && symbol.Identifier == item.Name)
                    {
                        VariableSymbol variable = symbol as VariableSymbol;
                        if (variable.IsArray == true)
                        {
                            int index = _scriptThread.AllocateArray(variable.DataType.DataType, ((Array)value).Length);
                            switch (variable.DataType.DataType)
                            {
                            case DataType.Bool:
                                for (int i = 0; i < ((bool[])value).Length; i++)
                                {
                                    _scriptThread.SetArrayElement(index, i, ((bool[])value)[i]);
                                }
                                break;

                            case DataType.Byte:
                                for (int i = 0; i < ((byte[])value).Length; i++)
                                {
                                    _scriptThread.SetArrayElement(index, i, ((byte[])value)[i]);
                                }
                                break;

                            case DataType.Double:
                                for (int i = 0; i < ((double[])value).Length; i++)
                                {
                                    _scriptThread.SetArrayElement(index, i, ((double[])value)[i]);
                                }
                                break;

                            case DataType.Float:
                                for (int i = 0; i < ((float[])value).Length; i++)
                                {
                                    _scriptThread.SetArrayElement(index, i, ((float[])value)[i]);
                                }
                                break;

                            case DataType.Int:
                                for (int i = 0; i < ((int[])value).Length; i++)
                                {
                                    _scriptThread.SetArrayElement(index, i, ((int[])value)[i]);
                                }
                                break;

                            case DataType.Long:
                                for (int i = 0; i < ((bool[])value).Length; i++)
                                {
                                    _scriptThread.SetArrayElement(index, i, ((long[])value)[i]);
                                }
                                break;

                            case DataType.Object:
                                for (int i = 0; i < ((int[])value).Length; i++)
                                {
                                    _scriptThread.SetArrayElement(index, i, ((int[])value)[i] >= _scriptThread.Process.ObjectHeap.Length ? null : _scriptThread.Process.ObjectHeap[((int[])value)[i]]);
                                }
                                break;

                            case DataType.Short:
                                for (int i = 0; i < ((short[])value).Length; i++)
                                {
                                    _scriptThread.SetArrayElement(index, i, ((short[])value)[i]);
                                }
                                break;

                            case DataType.String:
                                for (int i = 0; i < ((string[])value).Length; i++)
                                {
                                    _scriptThread.SetArrayElement(index, i, ((string[])value)[i]);
                                }
                                break;
                            }
                            _scriptThread.SetLocalArray(variable.Identifier, index);
                        }
                        else
                        {
                            switch (variable.DataType.DataType)
                            {
                            case DataType.Bool: _scriptThread.SetLocalVariable(variable.Identifier, (bool)value); break;

                            case DataType.Byte: _scriptThread.SetLocalVariable(variable.Identifier, (byte)value); break;

                            case DataType.Double: _scriptThread.SetLocalVariable(variable.Identifier, (double)value); break;

                            case DataType.Float: _scriptThread.SetLocalVariable(variable.Identifier, (float)value); break;

                            case DataType.Int: _scriptThread.SetLocalVariable(variable.Identifier, (int)value); break;

                            case DataType.Long: _scriptThread.SetLocalVariable(variable.Identifier, (long)value); break;

                            case DataType.Object:
                                RuntimeValue variableValue = _scriptThread.GetRuntimeValueLocal(variable.Identifier);     // Can be optimized.
                                _scriptThread.SetLocalVariable(variable.Identifier, (int)value >= _scriptThread.Process.ObjectHeap.Length ? null : _scriptThread.Process.ObjectHeap[(int)value]);
                                break;

                            case DataType.Short: _scriptThread.SetLocalVariable(variable.Identifier, (short)value); break;

                            case DataType.String: _scriptThread.SetLocalVariable(variable.Identifier, value as string); break;
                            }
                        }
                    }
                }
            }
        }