public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            ProfilerShort.Begin("MyEntity.Init(objectBuilder)");
            if (objectBuilder != null)
            {
                if (objectBuilder.PositionAndOrientation.HasValue)
                {
                    var posAndOrient = objectBuilder.PositionAndOrientation.Value;
                    MatrixD matrix = MatrixD.CreateWorld(posAndOrient.Position, posAndOrient.Forward, posAndOrient.Up);
                    MyUtils.AssertIsValid(matrix);

                    Entity.PositionComp.SetWorldMatrix(matrix);
                }
                // Do not copy EntityID if it gets overwritten later. It might
                // belong to some existing entity that we're making copy of.
                if (objectBuilder.EntityId != 0)
                    Entity.EntityId = objectBuilder.EntityId;
                Entity.Name = objectBuilder.Name;
                Entity.Render.PersistentFlags = objectBuilder.PersistentFlags;
            }

            AllocateEntityID();

            Entity.InScene = false;

            MyEntities.SetEntityName(m_entity, false);

            if (m_entity.SyncFlag)
            {
                m_entity.CreateSync();
            }
            GameLogic.Init(objectBuilder);
            ProfilerShort.End();
        }
Пример #2
0
        public override void Init(MyObjectBuilder_EntityBase builder)
        {
            ProfilerShort.Begin("base init");

            SyncFlag = true;

            base.Init(builder);
            base.Init(null, null, null, null, null);
            
            ProfilerShort.BeginNextBlock("Load file");

            var ob = (MyObjectBuilder_VoxelMap)builder;
            if (ob == null)
            {
                return;
            }
            if (ob.MutableStorage)
            {
                StorageName = ob.StorageName;
            }
            else
            {
                StorageName = string.Format("{0}-{1}", ob.StorageName, m_immutableStorageNameSalt++);
            }

            m_storage = MyStorageBase.Load(ob.StorageName);
            m_storage.RangeChanged += storage_RangeChanged;
            m_storageMax = m_storage.Size;

            InitVoxelMap(ob.PositionAndOrientation.Value.Position, m_storage.Size);

            ProfilerShort.End();
        }
Пример #3
0
        public BaseEntity(MyObjectBuilder_EntityBase baseEntity)
            : base(baseEntity)
        {
            if (baseEntity != null)
            {
                m_entityId = baseEntity.EntityId;
                if (baseEntity.PositionAndOrientation != null)
                {
                    m_positionOrientation = baseEntity.PositionAndOrientation.GetValueOrDefault();
                }
                else
                {
                    m_positionOrientation = new MyPositionAndOrientation();
                    m_positionOrientation.Position = UtilityFunctions.GenerateRandomBorderPosition(new Vector3(-500000, -500000, -500000), new Vector3(500000, 500000, 500000));
                    m_positionOrientation.Forward = new Vector3(0, 0, 1);
                    m_positionOrientation.Up = new Vector3(0, 1, 0);
                }
            }
            else
            {
                m_entityId = 0;
                m_positionOrientation = new MyPositionAndOrientation();
                m_positionOrientation.Position = UtilityFunctions.GenerateRandomBorderPosition(new Vector3(-500000, -500000, -500000), new Vector3(500000, 500000, 500000));
                m_positionOrientation.Forward = new Vector3(0, 0, 1);
                m_positionOrientation.Up = new Vector3(0, 1, 0);
            }

            m_linearVelocity = new Vector3(0, 0, 0);
            m_angularVelocity = new Vector3(0, 0, 0);
            m_maxLinearVelocity = (float)104.7;
        }
Пример #4
0
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            base.Init(objectBuilder);

            MyDefinitionManager.Static.TryGetDefinition(new MyDefinitionId(typeof(MyObjectBuilder_AreaMarkerDefinition), objectBuilder.SubtypeId), out m_definition);
            Debug.Assert(m_definition != null, "Area marker definition cannot be null!");
            if (m_definition == null) return;

            InitInternal();
        }
Пример #5
0
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            base.Init(objectBuilder);

            Init(null, "Models\\Weapons\\Welder.mwm", null, null, null);
            Render.CastShadows = true;
            Render.NeedsResolveCastShadow = false;

            PhysicalObject.GunEntity = (MyObjectBuilder_EntityBase)objectBuilder.Clone();
            PhysicalObject.GunEntity.EntityId = this.EntityId;
        }
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            base.Init(objectBuilder);

            Init(null, null, null, null, null);
            Render.CastShadows = true;
            Render.NeedsResolveCastShadow = false;

            HasSecondaryEffect = false;
            HasPrimaryEffect = false;
            m_firstShot = true;

            //PhysicalObject.GunEntity = (MyObjectBuilder_EntityBase)objectBuilder.Clone();
        }
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            base.Init(objectBuilder);

            m_definition = MyDefinitionManager.Static.GetPhysicalItemDefinition(objectBuilder.GetId());

            Init(null, m_definition.Model, null, null, null);

            Render.SkipIfTooSmall = false;
            Render.NeedsDraw = true;

            this.InitSpherePhysics(MyMaterialType.METAL, Model, 1, 1, 1, 0, Engine.Physics.RigidBodyFlag.RBF_DEFAULT);

            Physics.Enabled = true;
        }
Пример #8
0
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            var builder = objectBuilder as MyObjectBuilder_FloatingObject;
            if (builder.Item.Amount <= 0)
            {
                // I can only prevent creation of entity by throwing exception. This might cause crashes when thrown outside of MyEntities.CreateFromObjectBuilder().
                throw new ArgumentOutOfRangeException("MyInventoryItem.Amount", string.Format("Creating floating object with invalid amount: {0}x '{1}'", builder.Item.Amount, builder.Item.Content.GetId()));
            }
            base.Init(objectBuilder);

            this.Item = new MyInventoryItem(builder.Item);

            InitInternal();

            NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME;
        }
        public override void Init(Sandbox.Common.ObjectBuilders.MyObjectBuilder_EntityBase objectBuilder)
        {
            // Type Sandbox.Common.Components.MyEntityComponentBase used in Init not allowed in script
            logRefCount++;

            myDoor      = this.Entity as IMyDoor;
            myDoorBlock = this.Entity as Sandbox.ModAPI.IMyCubeBlock;

            // hook up events
            myDoor.DoorStateChanged += MyAutoDoor_DoorStateChanged;

            myDoor.NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME;

            SetupToggleAction();             // try to setup the action

            //LogMessage("Started Logging", false);
        }
Пример #10
0
 public override void Init(Sandbox.Common.ObjectBuilders.MyObjectBuilder_EntityBase objectBuilder)
 {
     this.avgGuidance        = new SlidingAverageVector(0.3);
     this.avgCorrectF        = new SlidingAverageVector(0.9);
     this.avgDampenF         = new SlidingAverageVector(0.9);
     Entity.NeedsUpdate     |= MyEntityUpdateEnum.EACH_FRAME;
     this.objectBuilder      = objectBuilder;
     this.id                 = HoverRailEngine.attachcount++;
     this.activeRailGuides   = new HashSet <RailGuide>();
     this.sound_engine_start = new MySoundPair("HoverEngine_Startup");
     this.sound_engine_loop  = new MySoundPair("HoverEngine_Loop");
     MyEntity3DSoundEmitter.PreloadSound(sound_engine_start);
     MyEntity3DSoundEmitter.PreloadSound(sound_engine_loop);
     this.engine_sound         = new MyEntity3DSoundEmitter(Entity as VRage.Game.Entity.MyEntity);
     this.engine_sound.Force3D = true;
     // MyLog.Default.WriteLine(String.Format("ATTACH TO OBJECT {0}", this.id));
     InitPowerComp();
 }
Пример #11
0
        public override void Init(Sandbox.Common.ObjectBuilders.MyObjectBuilder_EntityBase objectBuilder)
        {
            Entity.NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME;
            m_objectBuilder     = objectBuilder;

            if (Entity as IMyCubeBlock != null && Debugging)
            {
                IMyCubeBlock block = Entity as IMyCubeBlock;
                if (block.BlockDefinition.SubtypeName.Contains("AirlockRKR"))
                {
                    LOG = new Logger("textPanel", Debugging);
                }
            }
            //if (Entity as Sandbox.ModAPI.IMyDoor == null) {
            //    return;
            //}

            // IMyProgrammableBlock progBlock = Entity as IMyProgrammableBlock;
            //if (objectBuilder.SubtypeId.Equals("SmallProgrammableBlockRKR") || objectBuilder.SubtypeId.Equals("LargeProgrammableBlockRKR"))
            //{

            //}
            // MyAPIGateway.Utilities.MessageEntered += Utilities_MessageEntered;
        }
Пример #12
0
 public override void Init(Sandbox.Common.ObjectBuilders.MyObjectBuilder_EntityBase objectBuilder)
 {
     Entity.NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME;
     this.objectBuilder  = objectBuilder;
     FrameCaller.AddComponent(this);
 }
Пример #13
0
            public override void Init(MyObjectBuilder_EntityBase objectBuilder)
            {
                Entity.SyncFlag = true;
                base.Init(objectBuilder);
                Entity.SyncObject.UpdatePosition();

                var builder = (MyObjectBuilder_Meteor)objectBuilder;
                Item = new MyInventoryItem(builder.Item);
                m_particleEffectId = MySession.Static.EnvironmentHostility == MyEnvironmentHostilityEnum.CATACLYSM_UNREAL ? (int)MyParticleEffectsIDEnum.MeteorTrail_FireAndSmoke : (int)MyParticleEffectsIDEnum.MeteorParticle;
                InitInternal();

                Entity.Physics.LinearVelocity = builder.LinearVelocity;
                Entity.Physics.AngularVelocity = builder.AngularVelocity;

                m_integrity = builder.Integrity;
            }
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            base.Init(objectBuilder);

            Render.ModelStorage = MyModels.GetModelOnlyData(@"Models\StoneRoundLargeFull.mwm");
        }     
Пример #15
0
        public static void SavePrefab(string prefabName, MyObjectBuilder_EntityBase entity)
        {
            var fsPath = Path.Combine(MyFileSystem.ContentPath, Path.Combine("Data", "Prefabs", prefabName + ".sbc"));

            var prefab = Sandbox.Common.ObjectBuilders.Serializer.MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_PrefabDefinition>();
            prefab.Id = new MyDefinitionId(new MyObjectBuilderType(typeof(MyObjectBuilder_PrefabDefinition)), prefabName);
            prefab.CubeGrid = (MyObjectBuilder_CubeGrid)entity;
            
            var definitions = Sandbox.Common.ObjectBuilders.Serializer.MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_Definitions>();
            definitions.Prefabs = new MyObjectBuilder_PrefabDefinition[1];
            definitions.Prefabs[0] = prefab;
            
            Sandbox.Common.ObjectBuilders.Serializer.MyObjectBuilderSerializer.SerializeXML(fsPath, false, definitions);
        }
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
 
        }
Пример #17
0
 public static string GetPrefabTypeName(MyObjectBuilder_EntityBase entity)
 {
     if (entity is MyObjectBuilder_VoxelMap)
         return "Asteroid";
     if (entity is MyObjectBuilder_CubeGrid)
     {
         var g = (MyObjectBuilder_CubeGrid)entity;
         if (g.IsStatic)
             return "Station";
         else if (g.GridSizeEnum == MyCubeSize.Large)
             return "LargeShip";
         else
             return "SmallShip";
     }
     if (entity is MyObjectBuilder_Character)
         return "Character";
     return "Unknown";
 }
Пример #18
0
 public override void Init(Sandbox.Common.ObjectBuilders.MyObjectBuilder_EntityBase objectBuilder)
 {
     base.Init(objectBuilder);
     swivel_short = "jr_swivel_right";
     swivel_long  = "jr_swivel_left";
 }
 public MyObjectBuilder_PhysicalGunObject(MyObjectBuilder_EntityBase gunEntity)
 {
     GunEntity = gunEntity;
 }
		public static void SendEntityCreated(MyObjectBuilder_EntityBase entity, ulong userId)
		{
			Type sendCreateClassType = SandboxGameAssemblyWrapper.Instance.GetAssemblyType(MultiplayerNamespace, SendCreateClass);
			Type sendCreateCompressedMsgType = sendCreateClassType.GetNestedType(SendCreateCompressedMsg, BindingFlags.NonPublic);

			FieldInfo createObjectBuilders = sendCreateCompressedMsgType.GetField(SendCreateCompressedMsgObjectBuilders);
			FieldInfo createBuilderLengths = sendCreateCompressedMsgType.GetField(SendCreateCompressedMsgBuilderLengths);

			MemoryStream memoryStream = new MemoryStream();
			MyObjectBuilderSerializer.SerializeXML(memoryStream, entity, MyObjectBuilderSerializer.XmlCompression.Gzip, typeof(MyObjectBuilder_EntityBase));
			if (memoryStream.Length > (long)2147483647)
			{
				return;
			}

			object createMessage = Activator.CreateInstance(sendCreateCompressedMsgType);

			createObjectBuilders.SetValue(createMessage, memoryStream.ToArray());
			createBuilderLengths.SetValue(createMessage, new int[] { (int)memoryStream.Length });

			SendMessage(createMessage, userId, sendCreateCompressedMsgType, 1);
		}
 //Entities are usualy initialized from builder immediately after creation by factory
 public virtual void Init(MyObjectBuilder_EntityBase objectBuilder)
 {}
Пример #22
0
 public override void Init(MyObjectBuilder_EntityBase builder)
 {
     Init(builder, createPhysics: true);
 }
Пример #23
0
        public void Init(MyObjectBuilder_EntityBase builder, bool createPhysics)
        {
            MyObjectBuilder_VoxelMap ob = (MyObjectBuilder_VoxelMap)builder;
            Profiler.Begin("base init");

            NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME;
            SyncFlag = true;
            base.Init(builder);
            base.Init(null, null, null, null, null);

            Profiler.BeginNextBlock("Load file");
            LoadFile(builder.PositionAndOrientation.Value.Position, ob);
            Profiler.End();

            NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
        }
Пример #24
0
 public static void AddEntity(MyObjectBuilder_EntityBase entityBuilder)
 {
     MyEntities.CreateFromObjectBuilderAndAdd(entityBuilder);
 }
Пример #25
0
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            base.Init(objectBuilder);

            Init(null, null, null, null);

            BoundingBoxD aabbWorld = BoundingBoxD.CreateInvalid();
            Dictionary<MyStringId, HkShape> subtypeIdToShape = new Dictionary<MyStringId, HkShape>();
            HkStaticCompoundShape sectorRootShape = new HkStaticCompoundShape(HkReferencePolicy.None);
            var builder = (MyObjectBuilder_EnvironmentItems)objectBuilder;

            MyDefinitionId defId = new MyDefinitionId(builder.TypeId, builder.SubtypeId);

            // Compatibility
            if (builder.SubtypeId == MyStringId.NullOrEmpty)
            {
                if (objectBuilder is MyObjectBuilder_Bushes)
                {
                    defId = new MyDefinitionId(typeof(MyObjectBuilder_DestroyableItems), "Bushes");
                }
                else if (objectBuilder is MyObjectBuilder_TreesMedium)
                {
                    defId = new MyDefinitionId(typeof(MyObjectBuilder_Trees), "TreesMedium");
                }
                else if (objectBuilder is MyObjectBuilder_Trees)
                {
                    defId = new MyDefinitionId(typeof(MyObjectBuilder_Trees), "Trees");
                }
            }

            if (!MyDefinitionManager.Static.TryGetDefinition<MyEnvironmentItemsDefinition>(defId, out m_definition))
            {
                Debug.Assert(false, "Could not find definition " + defId.ToString() + " for environment items!");
                return;
            }

            if (builder.Items != null)
            {
                foreach (var item in builder.Items)
                {
                    MyStringId itemSubtype = MyStringId.GetOrCompute(item.SubtypeName);
                    Debug.Assert(m_definition.ContainsItemDefinition(itemSubtype));
                    if (!m_definition.ContainsItemDefinition(itemSubtype))
                    {
                        continue;
                    }

                    MatrixD worldMatrix = item.PositionAndOrientation.GetMatrix();
                    AddItem(m_definition.GetItemDefinition(itemSubtype), ref worldMatrix, ref aabbWorld, sectorRootShape, subtypeIdToShape);
                }
            }

            PrepareItems(sectorRootShape, ref aabbWorld);

            foreach (var pair in subtypeIdToShape)
            {
                pair.Value.RemoveReference();
            }

            NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME;
        }
Пример #26
0
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            base.Init(objectBuilder);
            var ob = objectBuilder as MyObjectBuilder_FracturedPiece;
            if (ob.Shapes.Count == 0)
            {
                Debug.Fail("Invalid fracture piece! Dont call init without valid OB. Use pool/noinit.");
                throw new Exception("Fracture piece has no shapes."); //throwing exception, otherwise there is fp with null physics which can mess up somwhere else
            }

            foreach (var shape in ob.Shapes)
            {
                Render.AddPiece(shape.Name, Matrix.CreateFromQuaternion(shape.Orientation));
            }
            OriginalBlocks.Clear();
            foreach (var def in ob.BlockDefinitions)
            {
                string model = null;
                MyPhysicalModelDefinition mdef;
                if (MyDefinitionManager.Static.TryGetDefinition<MyPhysicalModelDefinition>(def, out mdef))
                    model = mdef.Model;

                if (model == null)
                {
                    Debug.Fail("Fracture piece Definition not found");
                    continue;
                }
                if (MyModels.GetModelOnlyData(model).HavokBreakableShapes == null)
                {
                    MyDestructionData.Static.LoadModelDestruction(mdef, false, Vector3.One);
                }
                var shape = MyModels.GetModelOnlyData(model).HavokBreakableShapes[0];
                var si = new HkdShapeInstanceInfo(shape, null, null);
                m_children.Add(si);
                shape.GetChildren(m_children);
                OriginalBlocks.Add(def);
            }
            m_shapes.AddRange(ob.Shapes);

            Vector3? offset = null;
            int shapeAtZero = 0;
            for (int i = 0; i < m_children.Count; i++)
            {
                var child = m_children[i];
                Func<MyObjectBuilder_FracturedPiece.Shape, bool> x = s => s.Name == child.ShapeName;
                var result = m_shapes.Where(x);
                if (result.Count() > 0)
                {
                    var found = result.First();
                    var m = Matrix.CreateFromQuaternion(found.Orientation);
                    if (!offset.HasValue && found.Name == m_shapes[0].Name)
                    {
                        offset = child.GetTransform().Translation;
                        shapeAtZero = m_shapeInfos.Count;
                    }
                    m.Translation = child.GetTransform().Translation;
                    var si = new HkdShapeInstanceInfo(child.Shape.Clone(), m);
                    if(found.Fixed)
                        si.Shape.SetFlagRecursively(HkdBreakableShape.Flags.IS_FIXED);
                    m_shapeInfos.Add(si);
                    m_shapes.Remove(found);
                }
                else
                {
                    child.GetChildren(m_children);
                }
            }

            if (m_shapeInfos.Count == 0)
            {
                Debug.Fail("No relevant shape was found for fractured piece. It was probably reexported and names changed.");
                //HkdShapeInstanceInfo si = new HkdShapeInstanceInfo(new HkdBreakableShape((HkShape)new HkBoxShape(Vector3.One)), Matrix.Identity);
                //m_shapeInfos.Add(si);
                throw new Exception("No relevant shape was found for fractured piece. It was probably reexported and names changed.");
            }

            if (offset.HasValue)
            {
                for (int i = 0; i < m_shapeInfos.Count; i++)
                {
                    var m = m_shapeInfos[i].GetTransform();
                    m.Translation -= offset.Value;
                    m_shapeInfos[i].SetTransform(ref m);
                }
                {
                    var m = m_shapeInfos[shapeAtZero].GetTransform();
                    m.Translation = Vector3.Zero;
                    m_shapeInfos[shapeAtZero].SetTransform(ref m);
                }
            }

            if (m_shapeInfos.Count > 0)
            {
                if (m_shapeInfos.Count == 1)
                    Shape = m_shapeInfos[0].Shape;
                else
                {
                    Shape = new HkdCompoundBreakableShape(null, m_shapeInfos);
                    ((HkdCompoundBreakableShape)Shape).RecalcMassPropsFromChildren();
                }
                Shape.SetStrenght(MyDestructionConstants.STRENGTH);
                var mp = new HkMassProperties();
                Shape.BuildMassProperties(ref mp);
                Shape.SetChildrenParent(Shape);
                Physics = new MyPhysicsBody(this, RigidBodyFlag.RBF_DEBRIS);
                Physics.InitialSolverDeactivation = HkSolverDeactivation.Medium;
                Physics.CreateFromCollisionObject(Shape.GetShape(), Vector3.Zero, PositionComp.WorldMatrix, mp);
                Physics.BreakableBody = new HkdBreakableBody(Shape, Physics.RigidBody, MyPhysics.SingleWorld.DestructionWorld, (Matrix)PositionComp.WorldMatrix);
                Physics.BreakableBody.AfterReplaceBody += Physics.FracturedBody_AfterReplaceBody;

                var rigidBody = Physics.RigidBody;
                bool isFixed = MyDestructionHelper.IsFixed(Physics.BreakableBody.BreakableShape);
                if (isFixed)
                {
                    rigidBody.UpdateMotionType(HkMotionType.Fixed);
                    rigidBody.LinearVelocity = Vector3.Zero;
                    rigidBody.AngularVelocity = Vector3.Zero;
                }

                //Cannot set keyframed in constructor, because Havok does not allow set CoM on kinematic object..
                if(!Sync.IsServer)
                    Physics.RigidBody.UpdateMotionType(HkMotionType.Keyframed);
                Physics.Enabled = true;
            }
            m_children.Clear();
            m_shapeInfos.Clear();
        }
Пример #27
0
        public virtual void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            ProfilerShort.Begin("MyEntity.Init(objectBuilder)");
            this.Render.PersistentFlags = MyPersistentEntityFlags2.CastShadows;
            if (objectBuilder != null)
            {
                if (objectBuilder.PositionAndOrientation.HasValue)
                {
                    var posAndOrient = objectBuilder.PositionAndOrientation.Value;
                    MatrixD matrix = MatrixD.CreateWorld(posAndOrient.Position, posAndOrient.Forward, posAndOrient.Up);
                    MyUtils.AssertIsValid(matrix);

                    PositionComp.SetWorldMatrix((MatrixD)matrix);
                    if(MyPerGameSettings.LimitedWorld)
                    {
                        ClampToWorld();                    
                    }
                }
                // Do not copy EntityID if it gets overwritten later. It might
                // belong to some existing entity that we're making copy of.
                if (objectBuilder.EntityId != 0)
                    this.EntityId = objectBuilder.EntityId;
                this.Name = objectBuilder.Name;
                this.Render.PersistentFlags = objectBuilder.PersistentFlags;
            }

            AllocateEntityID();

            this.InScene = false;

            MyEntities.SetEntityName(this, false);

            if (SyncFlag)
            {
                CreateSync();
            }
            GameLogic.Init(objectBuilder);
            ProfilerShort.End();
        }
Пример #28
0
        public static void SendEntityCreated(MyObjectBuilder_EntityBase entity)
        {
            var msg = new CreateCompressedMsg();

            MemoryStream stream = new MemoryStream();
            Sandbox.Common.ObjectBuilders.Serializer.MyObjectBuilderSerializer.SerializeXML(stream, (MyObjectBuilder_Base)entity, Sandbox.Common.ObjectBuilders.Serializer.MyObjectBuilderSerializer.XmlCompression.Gzip, typeof(MyObjectBuilder_EntityBase));

            Debug.Assert(stream.Length <= int.MaxValue);
            if (stream.Length > int.MaxValue)
            {
                MySandboxGame.Log.WriteLine("Cannot synchronize created entity: number of bytes when serialized is larger than int.MaxValue!");
                return;
            }
             
            msg.ObjectBuilders = stream.ToArray();
            msg.BuilderLengths = new int[1];
            msg.BuilderLengths[0] = (int)stream.Length;
            
            MySession.Static.SyncLayer.SendMessageToAll(ref msg);
        }
Пример #29
0
 public override void Init(Sandbox.Common.ObjectBuilders.MyObjectBuilder_EntityBase objectBuilder)
 {
     Entity.NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME;
 }
Пример #30
0
        public static void SendEntityCreatedRelative(MyObjectBuilder_EntityBase entity, MyEntity baseEntity, Vector3 relativeVelocity)
        {
            var msg = new CreateRelativeCompressedMsg();

            MemoryStream stream = new MemoryStream();
            Matrix relativeMatrix = entity.PositionAndOrientation.Value.GetMatrix() * baseEntity.PositionComp.WorldMatrixNormalizedInv;
            entity.PositionAndOrientation = new MyPositionAndOrientation(relativeMatrix);
            Sandbox.Common.ObjectBuilders.Serializer.MyObjectBuilderSerializer.SerializeXML(stream, (MyObjectBuilder_Base)entity, Sandbox.Common.ObjectBuilders.Serializer.MyObjectBuilderSerializer.XmlCompression.Gzip, typeof(MyObjectBuilder_EntityBase));

            Debug.Assert(stream.Length <= int.MaxValue);
            if (stream.Length > int.MaxValue)
            {
                MySandboxGame.Log.WriteLine("Cannot synchronize created entity: number of bytes when serialized is larger than int.MaxValue!");
                return;
            }

            msg.CreateMessage.ObjectBuilders = stream.ToArray();
            msg.CreateMessage.BuilderLengths = new int[1];
            msg.CreateMessage.BuilderLengths[0] = (int)stream.Length;

            msg.BaseEntity = baseEntity.EntityId;
            msg.RelativeVelocity = relativeVelocity;

            MySession.Static.SyncLayer.SendMessageToAll(ref msg);
        }
Пример #31
0
 public MyObjectBuilder_PhysicalGunObject(MyObjectBuilder_EntityBase gunEntity)
 {
     GunEntity = gunEntity;
 }
 public override void Init(MyObjectBuilder_EntityBase objectBuilder)
 {
     Sensor = Entity as IMySensorBlock;
     Sensor.StateChanged += sensor_StateChanged;
 }
		public static void SendEntityCreatedRelative(MyObjectBuilder_EntityBase entity, IMyCubeGrid grid, Vector3 relativeVelocity, ulong userId)
		{
			// Extract Type and Field Info
			Type sendCreateClassType = SandboxGameAssemblyWrapper.Instance.GetAssemblyType(MultiplayerNamespace, SendCreateClass);
			Type sendCreateRelativeCompressedMsgType = sendCreateClassType.GetNestedType(SendCreateRelativeCompressedMsg, BindingFlags.NonPublic);
			Type sendCreateCompressedMsgType = sendCreateClassType.GetNestedType(SendCreateCompressedMsg, BindingFlags.NonPublic);

			FieldInfo createMessageField = sendCreateRelativeCompressedMsgType.GetField(SendCreateRelativeCompressedMsgCreateMessage);
			FieldInfo createBaseEntity = sendCreateRelativeCompressedMsgType.GetField(SendCreateRelativeCompressedMsgBaseEntity);
			FieldInfo createRelativeVelocity = sendCreateRelativeCompressedMsgType.GetField(SendCreateRelativeCompressedMsgRelativeVelocity);

			FieldInfo createObjectBuilders = sendCreateCompressedMsgType.GetField(SendCreateCompressedMsgObjectBuilders);
			FieldInfo createBuilderLengths = sendCreateCompressedMsgType.GetField(SendCreateCompressedMsgBuilderLengths);

			// Run logic
			MemoryStream memoryStream = new MemoryStream();
			MyPositionAndOrientation value = entity.PositionAndOrientation.Value;
			Matrix matrix = value.GetMatrix() * grid.PositionComp.WorldMatrixNormalizedInv;
			entity.PositionAndOrientation = new MyPositionAndOrientation?(new MyPositionAndOrientation(matrix));
			MyObjectBuilderSerializer.SerializeXML(memoryStream, entity, MyObjectBuilderSerializer.XmlCompression.Gzip, typeof(MyObjectBuilder_EntityBase));
			if (memoryStream.Length > (long)2147483647)
			{
				return;
			}

			// SetValues
			object relativeMessage = Activator.CreateInstance(sendCreateRelativeCompressedMsgType);
			object createMessage = createMessageField.GetValue(relativeMessage);

			createObjectBuilders.SetValue(createMessage, memoryStream.ToArray());
			createBuilderLengths.SetValue(createMessage, new int[] { (int)memoryStream.Length });

			createBaseEntity.SetValue(relativeMessage, entity.EntityId);
			createRelativeVelocity.SetValue(relativeMessage, relativeVelocity);

			SendMessage(relativeMessage, userId, sendCreateCompressedMsgType, 1);
		}
        public void RequestSwitchToWeapon(MyDefinitionId? weapon, MyObjectBuilder_EntityBase weaponObjectBuilder, long weaponEntityId)
        {
            if (!Sync.IsServer)
            {
                m_switchWeaponCounter++;
            }

            var msg = new SwitchToWeaponMsg();
            msg.ControlledEntityId = SyncedEntityId;
            msg.Weapon = weapon;
            msg.WeaponObjectBuilder = weaponObjectBuilder;
            msg.WeaponEntityId = weaponEntityId;

            Sync.Layer.SendMessageToServer(ref msg);
        }
Пример #35
0
        public BaseEntity(MyObjectBuilder_EntityBase baseEntity, Object backingObject)
            : base(baseEntity, backingObject)
        {
            if (baseEntity != null)
            {
                m_entityId = baseEntity.EntityId;
                if (baseEntity.PositionAndOrientation != null)
                {
                    m_positionOrientation = baseEntity.PositionAndOrientation.GetValueOrDefault();
                }
                else
                {
                    m_positionOrientation = new MyPositionAndOrientation();
                    m_positionOrientation.Position = UtilityFunctions.GenerateRandomBorderPosition(new Vector3(-500000, -500000, -500000), new Vector3(500000, 500000, 500000));
                    m_positionOrientation.Forward = new Vector3(0, 0, 1);
                    m_positionOrientation.Up = new Vector3(0, 1, 0);
                }
            }
            else
            {
                m_entityId = 0;
                m_positionOrientation = new MyPositionAndOrientation();
                m_positionOrientation.Position = UtilityFunctions.GenerateRandomBorderPosition(new Vector3(-500000, -500000, -500000), new Vector3(500000, 500000, 500000));
                m_positionOrientation.Forward = new Vector3(0, 0, 1);
                m_positionOrientation.Up = new Vector3(0, 1, 0);
            }

            m_networkManager = new BaseEntityNetworkManager(this, GetEntityNetworkManager(BackingObject));

            m_linearVelocity = new Vector3(0, 0, 0);
            m_angularVelocity = new Vector3(0, 0, 0);
            m_maxLinearVelocity = (float)104.7;

            Action action = InternalRegisterEntityMovedEvent;
            SandboxGameAssemblyWrapper.Instance.EnqueueMainGameAction(action);
        }
Пример #36
0
 public override void Init(Sandbox.Common.ObjectBuilders.MyObjectBuilder_EntityBase objectBuilder)
 {
     this.objectBuilder = objectBuilder;
     // TODO freeze junctions when they're not moving
     Entity.NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME;
 }