예제 #1
0
        public void AddEntity(BaseEntity entity)
        {
            try
            {
                if (SandboxGameAssemblyWrapper.IsDebugging)
                    Console.WriteLine(entity.GetType().Name + " '" + entity.Name + "' is being added ...");

                m_nextEntityToUpdate = entity;

                Action action = InternalAddEntity;
                SandboxGameAssemblyWrapper.Instance.EnqueueMainGameAction(action);
            }
            catch (Exception ex)
            {
                LogManager.ErrorLog.WriteLine(ex);
            }
        }
예제 #2
0
        protected void InternalAddEntity()
        {
            try
            {
                if (m_nextEntityToUpdate == null)
                    return;

                if (SandboxGameAssemblyWrapper.IsDebugging)
                    Console.WriteLine(m_nextEntityToUpdate.GetType().Name + " '" + m_nextEntityToUpdate.GetType().Name + "': Adding to scene ...");

                //Create the backing object
                Type entityType = m_nextEntityToUpdate.GetType();
                Type internalType = (Type)BaseEntity.InvokeStaticMethod(entityType, "get_InternalType");
                if (internalType == null)
                    throw new Exception("Could not get internal type of entity");
                m_nextEntityToUpdate.BackingObject = Activator.CreateInstance(internalType);

                //Initialize the backing object
                BaseEntity.InvokeEntityMethod(m_nextEntityToUpdate.BackingObject, "Init", new object[] { m_nextEntityToUpdate.ObjectBuilder });

                //Add the backing object to the main game object manager
                BaseEntity.InvokeStaticMethod(InternalType, ObjectManagerAddEntity, new object[] { m_nextEntityToUpdate.BackingObject, true });

                if (m_nextEntityToUpdate is FloatingObject)
                {
                    InternalBroadcastAddFloatingObject();
                }
                else
                {
                    InternalBroadcastAddEntity();
                }

                if (SandboxGameAssemblyWrapper.IsDebugging)
                {
                    Type type = m_nextEntityToUpdate.GetType();
                    Console.WriteLine(type.Name + " '" + m_nextEntityToUpdate.Name + "': Finished adding to scene");
                }

                m_nextEntityToUpdate = null;
            }
            catch (Exception ex)
            {
                LogManager.APILog.WriteLineAndConsole("Failed to add new entity");
                LogManager.ErrorLog.WriteLine(ex);
            }
        }
예제 #3
0
 public BaseEntityNetworkManager(BaseEntity parent, Object netManager)
 {
     m_parent = parent;
     m_networkManager = netManager;
 }
예제 #4
0
		public void UpdateEntity(BaseEntity entity)
		{
			foreach (BaseEntity baseEntity in GetSectorEntities())
			{
				if (baseEntity.EntityId == entity.EntityId)
				{
					//Copy over the deserialized dummy entity to the actual entity
					Type type = baseEntity.GetType();
					PropertyInfo[] properties = type.GetProperties();
					foreach (PropertyInfo property in properties)
					{
						try
						{
							if (!property.CanWrite)
								continue;
							if (property.GetSetMethod() == null)
								continue;

							object[] dataMemberAttributes = property.GetCustomAttributes(typeof(DataMemberAttribute), true);
							if (dataMemberAttributes == null || dataMemberAttributes.Length == 0)
								continue;

							Object newValue = property.GetValue(entity, new object[] { });
							if (newValue == null)
								continue;

							Object oldValue = property.GetValue(baseEntity, new object[] { });
							if (newValue.Equals(oldValue))
								continue;

							property.SetValue(baseEntity, newValue, new object[] { });
						}
						catch (Exception)
						{
							//Do nothing
						}
					}
					break;
				}
			}
		}
예제 #5
0
		public void AddEntity( BaseEntity entity )
		{
			try
			{
				if ( AddEntityQueue.Count >= 25 )
				{
					throw new Exception( "AddEntity queue is full. Cannot add more entities yet" );
				}

				if ( ExtenderOptions.IsDebugging )
					ApplicationLog.BaseLog.Debug(String.Format("{0} '{1}': Is being added...", entity.GetType().Name, entity.DisplayName));

				AddEntityQueue.Enqueue( entity );

				MySandboxGame.Static.Invoke( InternalAddEntity );
			}
			catch ( Exception ex )
			{
				ApplicationLog.BaseLog.Error( ex );
			}
		}
예제 #6
0
        public void AddEntity( BaseEntity entity )
        {
            try
            {
                if ( m_addEntityQueue.Count >= 25 )
                {
                    throw new Exception( "AddEntity queue is full. Cannot add more entities yet" );
                }

                if ( ExtenderOptions.IsDebugging )
                    ApplicationLog.BaseLog.Debug( entity.GetType( ).Name + " '" + entity.Name + "' is being added ..." );

                m_addEntityQueue.Enqueue( entity );

                MySandboxGame.Static.Invoke( InternalAddEntity );
            }
            catch ( Exception ex )
            {
                ApplicationLog.BaseLog.Error( ex );
            }
        }
		public void AddEntity(BaseEntity entity)
		{
			try
			{
				if (m_addEntityQueue.Count >= 5)
				{
					throw new Exception("AddEntity queue is full. Cannot add more entities yet");
				}

				if (SandboxGameAssemblyWrapper.IsDebugging)
					Console.WriteLine(entity.GetType().Name + " '" + entity.Name + "' is being added ...");

				m_addEntityQueue.Enqueue(entity);

				Action action = InternalAddEntity;
				SandboxGameAssemblyWrapper.Instance.EnqueueMainGameAction(action);
			}
			catch (Exception ex)
			{
				LogManager.ErrorLog.WriteLine(ex);
			}
		}