/// <summary>
        /// Look up the internal GameObject for an object by object id and
        /// return the C# object state for it.
        ///
        /// The routine does not create the object state for an object id
        /// that is valid but unrecognized to us (i.e. that we have not yet
        /// seen even though it exists engine-side).
        /// </summary>
        /// <param name="ObjectId">Supplies the object id to look up.</param>
        /// <returns>The corresponding C# object state, else null.</returns>
        public GameObject GetGameObject(uint ObjectId)
        {
            GameObject GameObj;

            if (ObjectId == CLRScriptBase.OBJECT_INVALID)
            {
                return(null);
            }

            if (!GameObjectTable.TryGetValue(ObjectId, out GameObj))
            {
                return(null);
            }

            //
            // Even though we have a record of the object in our lookup table,
            // the engine may have already removed its representation of the
            // object.  In that case, pretend that the object state doesn't
            // exist for purposes of by-object-id lookups.
            //

            if (!GameObj.Exists)
            {
                return(null);
            }

            return(GameObj);
        }
Example #2
0
 public Machine(ILogger logger, IInputStream inputStream)
 {
     Memory      = new MachineMemory(Stream.Null);
     StackFrames = new FrameCollection(logger);
     ObjectTable = new GameObjectTable(this);
     Decoder     = new InstructionDecoder(this);
     Output      = new CompositeOutputStream(new DebugOutputStream(logger));
     Logger      = logger.ForContext <Machine>();
     Input       = inputStream;
 }
 /// <summary>
 /// Insert an object into the game object table.
 /// </summary>
 /// <param name="Obj">Supplies the object to insert.</param>
 public void AddGameObject(GameObject Obj)
 {
     if (GameObjectTable.ContainsKey(Obj.ObjectId))
     {
         GameObjectTable[Obj.ObjectId] = Obj;
     }
     else
     {
         GameObjectTable.Add(Obj.ObjectId, Obj);
     }
 }
Example #4
0
 public static GameObject CreateNew(string name, float destoryTime, Vector3 pos, Quaternion rot)
 {
     if (m_objTables.ContainsKey(name))
     {
         return m_objTables[name].CreateNew(destoryTime, pos, rot);
     }
     else
     {
         GameObjectTable tb = new GameObjectTable(name);
         m_objTables[name] = tb;
         return tb.CreateNew(destoryTime, pos, rot);
     }
 }
        /// <summary>
        /// Resolve an object ID to a GameObject without checking for deleted
        /// objects that need garbage collection.  This function should only
        /// be used by the PowerShell diagnostics infrastructure.
        /// </summary>
        /// <param name="ObjectId">Supplies the object id to look up.</param>
        /// <returns>The object in question, else null.</returns>
        internal GameObject GetGameObjectUnsafe(uint ObjectId)
        {
            GameObject GameObj;

            if (ObjectId == CLRScriptBase.OBJECT_INVALID)
            {
                return(null);
            }

            if (!GameObjectTable.TryGetValue(ObjectId, out GameObj))
            {
                return(null);
            }

            return(GameObj);
        }
        /// <summary>
        /// Periodically run as a DelayCommand continuation in order to scan
        /// the object table for objects whose engine parts have been deleted.
        ///
        /// Any such objects found are removed.
        ///
        /// It is necessary to periodically poll for deleted objects because
        /// not all object types provide script events that signify deletion.
        /// </summary>
        private void GarbageCollectObjects()
        {
            //
            // Scan the object table looking for objects that have had their
            // engine side counterpart deleted.  Add these to the object to
            // delete list, but don't mark them as in rundown.  This allows us
            // to differentiate between which objects were still in the
            // dictionary during the subsequent rundown loop (so that we can
            // remove them then, as we can't modify the dictionary during the
            // enumeration).
            //

            foreach (var Entry in GameObjectTable)
            {
                if (Script.GetIsObjectValid(Entry.Key) != CLRScriptBase.FALSE)
                {
                    continue;
                }

                ObjectsToDelete.Add(Entry.Value);
            }

            //
            // For every object that is scheduled for rundown, call the
            // OnRundown notification and remove the object from the deletion
            // list.  If the object was one we moved above, remove it from the
            // lookup table too (otherwise it was already removed from the
            // lookup table ahead of time).
            //

            foreach (GameObject ObjectToRundown in ObjectsToDelete)
            {
                if (ObjectToRundown.IsRundown == false)
                {
                    GameObjectTable.Remove(ObjectToRundown.ObjectId);
                }

                try
                {
                    ObjectToRundown.OnRundown();
                }
                catch (Exception e)
                {
                    Script.WriteTimestampedLogEntry(String.Format(
                                                        "GameObject.GarbageCollectObjects(): Exception {0} running rundown for object {1} of type {2}.", e, ObjectToRundown.ObjectId, ObjectToRundown.ObjectType));
                }
            }

            //
            // Now that we have ran through the object to delete list, clear it
            // out (the last reference that the underlying object system has to
            // these object ids).
            //

            ObjectsToDelete.Clear();

            //
            // Schedule the next garbage collection.
            //

            Script.DelayCommand(60.0f, delegate() { GarbageCollectObjects(); });
        }
 /// <summary>
 /// Remove an object from the game object table.
 /// </summary>
 /// <param name="Obj">Supplies the object to remove.</param>
 public void RemoveGameObject(GameObject Obj)
 {
     GameObjectTable.Remove(Obj.ObjectId);
     ObjectsToDelete.Add(Obj);
 }
Example #8
0
        public GameObjectService(ErrorService errorService, Project project)
        {
            _errorService    = errorService;
            _project         = project;
            GameObjectTable  = new GameObjectTable();
            localGameObjects = JsonConvert.DeserializeObject <GameObject[]>(JsonConvert.SerializeObject(_project.GameObjects));

            for (int i = 0; i < localGameObjects.Length; i++)
            {
                if (localGameObjects[i] == null)
                {
                    localGameObjects[i] = new GameObject()
                    {
                        Group          = "Unused",
                        GameId         = i,
                        GameObjectType = GameObjectType.Global,
                        Name           = "Unused x" + i.ToString("X"),
                        Sprites        = new List <Sprite>()
                        {
                            new Sprite()
                            {
                                Overlay = true, X = 0, Y = 0, TileValueIndex = 8
                            },
                            new Sprite()
                            {
                                Overlay = true, X = 0, Y = 0, TileValueIndex = 0x0A
                            }
                        }
                    };
                }
            }
            RefreshGameObjectTable();
            _startPointPalette = new string[4] {
                "00", "0F", "36", "16"
            };
            _startPointGameObject = new GameObject()
            {
                GameId  = 0,
                Name    = "Start Point",
                Sprites = new List <Sprite>()
                {
                    new Sprite()
                    {
                        X = 0,
                        Y = 0,
                        TileValueIndex = 0x8,
                        TileTableIndex = 4,
                        CustomPalette  = _startPointPalette,
                        Overlay        = true
                    },
                    new Sprite()
                    {
                        X = 8,
                        Y = 0,
                        TileValueIndex = 0xA,
                        TileTableIndex = 4,
                        CustomPalette  = _startPointPalette,
                        Overlay        = true
                    }
                }
            };
        }