internal protected override IGameResource PrecacheResource(Game owner, string resource_name, string r_path, string r_name)
        {
            IGameResource gr     = null;
            bool          result = false;

            switch (resource_name)
            {
            case Managers.BlamDefinition.ResourceScripts:
                gr     = new Scripting.XmlInterface();
                result = gr.Load(r_path, r_name);
                break;

            case Managers.BlamDefinition.ResourceStringIds:
                gr     = new Managers.StringIdStaticCollection();
                result = gr.Load(r_path, r_name);
                break;

            case Managers.BlamDefinition.ResourceVertexBuffers:
                gr     = new Render.VertexBufferInterface.VertexBuffersGen3();
                result = gr.Load(r_path, r_name);
                break;
            }

            if (!result && gr != null)
            {
                gr.Close();
                gr = null;
            }

            return(gr);
        }
Beispiel #2
0
		internal protected override IGameResource PrecacheResource(Game owner, string resource_name, string r_path, string r_name)
		{
			IGameResource gr = null;
			bool result = false;

			switch (resource_name)
			{
				case Managers.BlamDefinition.ResourceScripts:
					gr = new Scripting.XmlInterface();
					result = gr.Load(r_path, r_name);
					break;

				case Managers.BlamDefinition.ResourceStringIds:
					gr = new Managers.StringIdStaticCollection();
					result = gr.Load(r_path, r_name);
					break;

				case Managers.BlamDefinition.ResourceVertexBuffers:
					gr = new Render.VertexBufferInterface.VertexBuffersGen3();
					result = gr.Load(r_path, r_name);
					break;
			}

			if (!result && gr != null)
			{
				gr.Close();
				gr = null;
			}

			return gr;
		}
 /// <summary>
 /// Initialize the execution state for the compiler using a blam-script definition
 /// </summary>
 /// <param name="definition"></param>
 internal Data(Scripting.XmlInterface definition)
 {
     this.definition = definition;
     Nodes           = new List <ScriptNode>(this.definition.MaxNodes);
     StringData      = new Util.StringPool(false);
     Scripts         = new List <ScriptBlock>();
     Globals         = new List <GlobalsBlock>();
 }
Beispiel #4
0
		/// <summary>
		/// Initialize the execution state for the compiler using a blam-script definition
		/// </summary>
		/// <param name="definition"></param>
		internal Data(Scripting.XmlInterface definition)
		{
			this.definition = definition;
			Nodes = new List<ScriptNode>(this.definition.MaxNodes);
			StringData = new Util.StringPool(false);
			Scripts = new List<ScriptBlock>();
			Globals = new List<GlobalsBlock>();
		}
        bool ObjectTypeCanCast(short actual_type, short desired_type)
        {
            Scripting.XmlInterface BSD = State.Definition;

            int actual  = BSD.ObjectTypeMasksList[actual_type];
            int desired = BSD.ObjectTypeMasksList[desired_type];
            int result  = (desired & actual) - actual;

            return(result == 0);
        }
Beispiel #6
0
        public void Dispose()
        {
            compiler.Dispose();

            if (scriptingInterface != null)
            {
                scriptingInterface = null;
                Managers.BlamDefinition gd = Program.GetManager(this.engine);
                (gd as Managers.IScriptingController).ScriptingCacheClose(this.engine);
            }
        }
        Stream(Scripting.Compiler.Data state_data)
        {
            State = state_data;

            Scripting.XmlInterface def = state_data.Definition;
//          _Startup = def.GetScriptType("startup").Opcode;
//          _Dormant = def.GetScriptType("dormant").Opcode;
//          _Continuuous = def.GetScriptType("continuous").Opcode;
            _Static       = def.GetScriptType("static").Opcode;
            _Stub         = def.GetScriptType("stub").Opcode;
            _Unparsed     = def.GetValueType("unparsed").Opcode;
            _SpecialForm  = def.GetValueType("special form").Opcode;
            _FunctionName = def.GetValueType("function name").Opcode;
            _Passthrough  = def.GetValueType("passthrough").Opcode;
            _Void         = def.GetValueType("void").Opcode;

            PrimitiveParsers = new List <Parser>(def.ValueTypeCount);
        }
        bool TypeCanCast(short actual_type, short desired_type)
        {
            Scripting.XmlInterface BSD = State.Definition;

            if (actual_type == _Passthrough || actual_type == desired_type)
            {
                return(true);
            }
            else if (desired_type >= BSD.ObjectTypeFirst || desired_type <= BSD.ObjectTypeLast)
            {
                if (actual_type >= BSD.ObjectTypeFirst || actual_type <= BSD.ObjectTypeLast)
                {
                    return(ObjectTypeCanCast((short)(actual_type - BSD.ObjectTypeFirst),
                                             (short)(desired_type - BSD.ObjectTypeFirst)));
                }
                else if (actual_type >= BSD.ObjectTypeNameFirst || actual_type <= BSD.ObjectTypeNameLast)
                {
                    return(ObjectTypeCanCast((short)(actual_type - BSD.ObjectTypeNameFirst),
                                             (short)(desired_type - BSD.ObjectTypeFirst)));
                }
                else
                {
                    return(false);
                }
            }
            else if (desired_type >= BSD.ObjectTypeNameFirst || desired_type <= BSD.ObjectTypeNameLast)
            {
                if (actual_type >= BSD.ObjectTypeNameFirst || actual_type <= BSD.ObjectTypeNameLast)
                {
                    return(ObjectTypeCanCast((short)(actual_type - BSD.ObjectTypeNameFirst),
                                             (short)(desired_type - BSD.ObjectTypeNameFirst)));
                }
                else
                {
                    return(false);
                }
            }

            return(TypecastingExist(actual_type, desired_type));
        }
Beispiel #9
0
        protected ProjectState(BlamVersion engine, Project proj)
        {
            this.engine = engine;

            Managers.GameManager.Namespace nspace;
            Managers.GameManager.Platform  plat;
            // Get the namespace of the engine we're using
            Managers.GameManager.FromBlamVersion(engine, out nspace, out plat);

            // Read the CheApe engine definition data we need for importing
            definition = new XmlInterface(engine);
            definition.Read(Managers.GameManager.GetRelativePath(nspace), "CheApe.xml");

            InitializeTypeIndicies();

            proj.OwnerState = this;
            project         = proj;

            Managers.BlamDefinition gd = Program.GetManager(engine);
            (gd as Managers.IScriptingController).ScriptingCacheOpen(engine);
            scriptingInterface = gd[engine].GetResource <Scripting.XmlInterface>(Managers.BlamDefinition.ResourceScripts);
        }
Beispiel #10
0
		protected ProjectState(BlamVersion engine, Project proj)
		{
			this.engine = engine;

			Managers.GameManager.Namespace nspace;
			Managers.GameManager.Platform plat;
			// Get the namespace of the engine we're using
			Managers.GameManager.FromBlamVersion(engine, out nspace, out plat);

			// Read the CheApe engine definition data we need for importing
			definition = new XmlInterface(engine);
			definition.Read(Managers.GameManager.GetRelativePath(nspace), "CheApe.xml");

			InitializeTypeIndicies();

			proj.OwnerState = this;
			project = proj;

 			Managers.BlamDefinition gd = Program.GetManager(engine);
 			(gd as Managers.IScriptingController).ScriptingCacheOpen(engine);
			scriptingInterface = gd[engine].GetResource<Scripting.XmlInterface>(Managers.BlamDefinition.ResourceScripts);
		}
Beispiel #11
0
		public void Dispose()
		{
			compiler.Dispose();

			if (scriptingInterface != null)
			{
				scriptingInterface = null;
				Managers.BlamDefinition gd = Program.GetManager(this.engine);
				(gd as Managers.IScriptingController).ScriptingCacheClose(this.engine);
			}
		}
        bool ParseNonPrimitive(Scripting.ScriptNode _node)
        {
            #region if the node is actually a primitive...
            if (Util.Flags.Test(_node.PointerType, (short)NodeFlags.Primitive))
            {
                throw new CompileException("i expected {0}, but i got an expression. {1}:0x{2:X}", "File offset",
                                           (_node.Type == _SpecialForm) ? "\"script\" or \"global\"" : "a function name",
                                           "File offset", _node.Pointer
                                           );
            }
            #endregion

            #region if a special form (ie, global or script)
            if (_node.Type == _SpecialForm)
            {
                if (StrCmp(_node.Pointer, "global"))
                {
                    return(AddGlobal(_node));
                }
                else if (StrCmp(_node.Pointer, "script"))
                {
                    return(AddScript(_node));
                }
                else
                {
                    throw new CompileException("i expected \"script\" or \"global\".");
                }
            }
            #endregion
            #region else everything else
            else
            {
                CallPredicate(_node);
                // script or function index
                short proc_index = _node.Opcode;

                if (proc_index == -1)
                {
                    throw new CompileException("this is not a valid function or script name. {0}:0x{1:X}", "File offset", _node.Pointer);
                }

                Scripting.XmlInterface BSD = State.Definition;

                #region if node is script return expression
                if (!Util.Flags.Test(_node.PointerType, (short)NodeFlags.ReturnFuncValue))
                {
                    if (State.Scripts[proc_index].ScriptType != _Static ||
                        State.Scripts[proc_index].ScriptType != _Stub)
                    {
                        throw new CompileException("this is not a static script. {0}:0x{1:X}", "File offset", _node.Pointer);
                    }
                    else
                    {
                        if (_node.Type != _Unparsed || TypeCanCast(State.Scripts[proc_index].ReturnType, _node.Type))
                        {
                            if (_node.Type == _Unparsed)
                            {
                                _node.Type = State.Scripts[proc_index].ReturnType;
                            }
                        }
                        else
                        {
                            throw new CompileException("i expected a {0}, but this script returns a {1}. {2}:0x{3:X}",
                                                       BSD.GetValueType(_node.Type).Name,
                                                       BSD.GetValueType(State.Scripts[proc_index].ReturnType).Name,
                                                       "File offset", _node.Pointer);
                        }
                    }

                    return(true);
                }
                #endregion
                #region else its a function call
                else
                {
                    if (_node.Type != _Unparsed)
                    {
                        if (!TypeCanCast(BSD.GetFunction(proc_index).ReturnType, _node.Type))
                        {
                            throw new CompileException("i expected a {0}, but this function returns a {1}. {2}:0x{3:X}",
                                                       BSD.GetValueType(BSD.GetFunction(proc_index).ReturnType).Name,
                                                       BSD.GetValueType(_node.Type).Name,
                                                       "File offset", _node.Pointer);
                        }
                    }

                    if (CantCompileBlocks && IsSleeperFunction(proc_index))
                    {
                        throw new CompileException("it is illegal to block in this context. {0}:0x{1:X}", "File offset", _node.Pointer);
                    }
                    else if (CantCompileVariableSets && IsVarSetterFunction(proc_index))
                    {
                        throw new CompileException("it is illegal to set the value of variables in this context. {0}:0x{1:X}", "File offset", _node.Pointer);
                    }

                    if (_node.Type == _Unparsed && BSD.GetFunction(proc_index).ReturnType != _Passthrough)
                    {
                        _node.Type = BSD.GetFunction(_node.Opcode).ReturnType;
                    }

                    return(ParseFunction(proc_index, _node));
                }
                #endregion
            }
            #endregion
        }