public INodeModel CreateStackedNode(Type nodeTypeToCreate, string nodeName = "", int index = -1, SpawnFlags spawnFlags = SpawnFlags.Default, Action <NodeModel> preDefineSetup = null, GUID?guid = null) { SpawnFlags createNodeFlags = (spawnFlags & SpawnFlags.CreateNodeAsset) | SpawnFlags.Orphan; // we don't want to CreateNode to add the node to the graph nor to register undo var graphModel = (GraphModel)GraphModel; NodeModel nodeModel = (NodeModel)graphModel.CreateNodeInternal(nodeTypeToCreate, nodeName, Vector2.zero, createNodeFlags, preDefineSetup, guid); graphModel.RegisterNodeGuid(nodeModel); if (!spawnFlags.IsOrphan()) { if (spawnFlags.IsUndoable()) { Undo.RegisterCreatedObjectUndo(nodeModel.NodeAssetReference, "Create Node"); Undo.RegisterCompleteObjectUndo(NodeAssetReference, "Add Node"); AddStackedNode(nodeModel, index); EditorUtility.SetDirty(NodeAssetReference); } else { AddStackedNode(nodeModel, index); } } nodeModel.DefineNode(); return(nodeModel); }
public GraphNodeCreationData(IGraphModel graphModel, Vector2 position, SpawnFlags spawnFlags = SpawnFlags.Default, IReadOnlyList <GUID> guids = null) { GraphModel = graphModel; Position = position; SpawnFlags = spawnFlags; Guids = guids; }
public StackNodeCreationData(IStackModel stackModel, int index, SpawnFlags spawnFlags = SpawnFlags.Default) { StackModel = stackModel; Index = index; SpawnFlags = spawnFlags; }
public void ApplyTo(Vehicle vehicle, SpawnFlags spawnFlags = SpawnFlags.Default) { ApplyTo2(vehicle, spawnFlags.HasFlag(SpawnFlags.NoOccupants)); if (!spawnFlags.HasFlag(SpawnFlags.NoPosition)) { vehicle.PositionNoOffset = Position; vehicle.Heading = Heading; vehicle.Rotation = Rotation; } if (spawnFlags.HasFlag(SpawnFlags.SetRotation)) { vehicle.Rotation = Rotation; } if (!spawnFlags.HasFlag(SpawnFlags.NoVelocity)) { vehicle.Velocity = Velocity; vehicle.Speed = Speed; } if (spawnFlags.HasFlag(SpawnFlags.NoWheels)) { return; } for (int i = 0; i < WheelsRotations.Length; i++) { VehicleControl.SetWheelRotation(vehicle, i, FusionUtils.Wrap(WheelsRotations[i], -(float)Math.PI, (float)Math.PI)); VehicleControl.SetWheelCompression(vehicle, i, WheelsCompressions[i]); } }
public override void Spawn() { base.Spawn(); SetupPhysicsFromModel(PhysicsMotionType.Keyframed); if (SpawnFlags.Has(Flags.NonSolid)) { EnableSolidCollisions = false; } Locked = SpawnFlags.Has(Flags.StartsLocked); TxOff = Transform; var dir = MoveAngle.Direction; var boundSize = OOBBox.Size; var delta = dir * (MathF.Abs(boundSize.Dot(dir)) - Lip); if (Speed <= 0) { Speed = 0.01f; } SecondsToTake = delta.Length / Speed; TxOn = TxOff.Add(delta, false); }
/// <summary> /// Initializes a new GraphNodeCreationData. /// </summary> /// <param name="graphModel">The interface to the graph where we want the node to be created in.</param> /// <param name="position">The position at which the node should be created.</param> /// <param name="spawnFlags">The flags specifying how the node is to be spawned.</param> /// <param name="guid">The SerializableGUID to assign to the newly created item.</param> public GraphNodeCreationData(IGraphModel graphModel, Vector2 position, SpawnFlags spawnFlags = SpawnFlags.Default, SerializableGUID guid = default) { GraphModel = graphModel; Position = position; SpawnFlags = spawnFlags; Guid = guid; }
public GraphNodeCreationData(IGraphModel graphModel, Vector2 position, SpawnFlags spawnFlags = SpawnFlags.Default) { GraphModel = graphModel; Position = position; SpawnFlags = spawnFlags; }
public void TestFunctionMembers(string query, Type type, SpawnFlags mode) { var funcModel = GraphModel.CreateFunction("TestFunc", Vector2.zero); funcModel.CreateFunctionVariableDeclaration("var", typeof(int).GenerateTypeHandle(GraphModel.Stencil)); funcModel.CreateAndRegisterFunctionParameterDeclaration("par", typeof(string).GenerateTypeHandle(GraphModel.Stencil)); var db = new GraphElementSearcherDatabase(Stencil) .AddFunctionMembers(funcModel) .Build(); var results = db.Search(query, out _); Assert.AreEqual(1, results.Count); var item = (GraphNodeModelSearcherItem)results[0]; var data = (TypeSearcherItemData)item.Data; Assert.AreEqual(SearcherItemTarget.Variable, data.Target); Assert.AreEqual(Stencil.GenerateTypeHandle(type), data.Type); CreateNodesAndValidateGraphModel(item, mode, initialNodes => { var node = GraphModel.NodeModels.OfType <VariableNodeModel>().FirstOrDefault(); Assert.IsNotNull(node); Assert.AreEqual(initialNodes.Count + 1, GraphModel.NodeModels.Count); Assert.AreEqual(type, node.DataType.Resolve(Stencil)); }); }
public void TestBinaryOperator(SpawnFlags mode) { var db = new GraphElementSearcherDatabase(Stencil) .AddBinaryOperators() .Build(); var results = db.Search(nameof(BinaryOperatorKind.Subtract), out _); Assert.AreEqual(1, results.Count); var item = results[0] as GraphNodeModelSearcherItem; Assert.NotNull(item); var data = (BinaryOperatorSearcherItemData)item.Data; Assert.AreEqual(SearcherItemTarget.BinaryOperator, data.Target); Assert.AreEqual(BinaryOperatorKind.Subtract, data.Kind); CreateNodesAndValidateGraphModel(item, mode, initialNodes => { var node = GraphModel.NodeModels.OfType <BinaryOperatorNodeModel>().FirstOrDefault(); Assert.IsNotNull(node); Assert.AreEqual(node.Kind, BinaryOperatorKind.Subtract); Assert.AreEqual(initialNodes.Count + 1, GraphModel.NodeModels.Count); }); }
public void TestGraphVariables(SpawnFlags mode) { const string name = "int"; var var1 = GraphModel.CreateGraphVariableDeclaration(typeof(int).GenerateTypeHandle(), name, ModifierFlags.None, false); var db = new GraphElementSearcherDatabase(Stencil, GraphModel) .AddGraphVariables(GraphModel) .Build(); var results = db.Search("int"); Assert.AreEqual(1, results.Count); var item = (GraphNodeModelSearcherItem)results[0]; var data = (TypeSearcherItemData)item.Data; Assert.AreEqual(var1.DataType, data.Type); CreateNodesAndValidateGraphModel(item, mode, initialNodes => { var node = GraphModel.NodeModels.OfType <VariableNodeModel>().FirstOrDefault(); Assert.IsNotNull(node); Assert.AreEqual(initialNodes.Count + 1, GraphModel.NodeModels.Count); Assert.AreEqual(name.Nicify(), node.DisplayTitle); Assert.AreEqual(typeof(int), node.GetDataType().Resolve()); }); }
public override void Spawn() { base.Spawn(); RotationA = Rot.Angles(); var degrees = RotationDegrees - Lip; if (SpawnFlags.Has(Flags.RotateBackwards)) { degrees *= -1.0f; } if (SpawnFlags.Has(Flags.Pitch)) { RotationB = RotationA + new Angles(degrees, 0, 0); } else if (SpawnFlags.Has(Flags.Roll)) { RotationB = RotationA + new Angles(0, 0, degrees); } else { RotationB = RotationA + new Angles(0, degrees, 0); } }
public static FunctionModel CreateFunction(this IGraphModel graphModel, string methodName, Vector2 position, SpawnFlags spawnFlags = SpawnFlags.Default, GUID?guid = null) { graphModel.Stencil.GetSearcherDatabaseProvider().ClearReferenceItemsSearcherDatabases(); var uniqueMethodName = graphModel.GetUniqueName(methodName); return(graphModel.CreateNode <FunctionModel>(uniqueMethodName, position, spawnFlags, guid: guid)); }
public StackNodeCreationData(IStackModel stackModel, int index, SpawnFlags spawnFlags = SpawnFlags.Default, IReadOnlyList <GUID> guids = null) { StackModel = stackModel; Index = index; SpawnFlags = spawnFlags; Guids = guids; }
public static EventFunctionModel CreateEventFunction(this IGraphModel graphModel, MethodInfo methodInfo, Vector2 position, SpawnFlags spawnFlags = SpawnFlags.Default, GUID?guid = null) { graphModel.Stencil.GetSearcherDatabaseProvider().ClearReferenceItemsSearcherDatabases(); void Setup(EventFunctionModel e) => e.EventType = methodInfo.DeclaringType.GenerateTypeHandle(graphModel.Stencil); return(graphModel.CreateNode <EventFunctionModel>(methodInfo.Name, position, spawnFlags, Setup, guid)); }
/// <summary> /// A player has pressed this /// </summary> public virtual bool OnUse(Entity user) { if (SpawnFlags.Has(Flags.Use)) { Toggle(); } return(false); }
/// <summary> /// Creates a new variable declaration in the graph. /// </summary> /// <param name="self">The graph to add a variable declaration to.</param> /// <param name="variableDataType">The type of data the new variable declaration to create represents.</param> /// <param name="variableName">The name of the new variable declaration to create.</param> /// <param name="modifierFlags">The modifier flags of the new variable declaration to create.</param> /// <param name="isExposed">Whether the variable is exposed externally or not.</param> /// <param name="initializationModel">The initialization model of the new variable declaration to create. Can be <code>null</code>.</param> /// <param name="guid">The SerializableGUID to assign to the newly created item.</param> /// <param name="initializationCallback">An initialization method to be called right after the variable declaration is created.</param> /// <param name="spawnFlags">The flags specifying how the variable declaration is to be spawned.</param> /// <typeparam name="TDeclType">The type of variable declaration to create.</typeparam> /// <returns>The newly created variable declaration.</returns> public static TDeclType CreateGraphVariableDeclaration <TDeclType>(this IGraphModel self, TypeHandle variableDataType, string variableName, ModifierFlags modifierFlags, bool isExposed, IConstant initializationModel = null, SerializableGUID guid = default, Action <TDeclType, IConstant> initializationCallback = null, SpawnFlags spawnFlags = SpawnFlags.Default) where TDeclType : class, IVariableDeclarationModel { return((TDeclType)self.CreateGraphVariableDeclaration(typeof(TDeclType), variableDataType, variableName, modifierFlags, isExposed, initializationModel, guid, (d, c) => initializationCallback?.Invoke((TDeclType)d, c), spawnFlags)); }
public bool OnUse(Entity user) { if (SpawnFlags.Has(Flags.Use)) { Toggle(user); } Log.Info("Door Used"); return(false); }
public override void TakeDamage(DamageInfo info) { base.TakeDamage(info); FireOutput("OnDamaged", info.Attacker, this); if (SpawnFlags.Has(Flags.DamageActivates)) { DoPress(info.Attacker); } }
public static StackBaseModel CreateStack(this IGraphModel graphModel, string name, Vector2 position, SpawnFlags spawnFlags = SpawnFlags.Default, GUID?guid = null) { var stackTypeToCreate = graphModel.Stencil.GetDefaultStackModelType(); if (!typeof(StackModel).IsAssignableFrom(stackTypeToCreate)) { stackTypeToCreate = typeof(StackModel); } return((StackBaseModel)graphModel.CreateNode(stackTypeToCreate, name, position, spawnFlags, guid: guid)); }
public SpawnFlags m_Flags; // is this mobile created by a factory? // Properties // Constructors public ChampLevelData(int max_kills, int max_mobs, int max_spawn, int max_range, TimeSpan spawn_delay, TimeSpan expire_delay, SpawnFlags flags, String[] monsters) { //assign values Monsters = monsters; m_MaxKills = max_kills; m_MaxMobs = max_mobs; m_MaxSpawn = max_spawn; m_MaxRange = max_range; m_SpawnDelay = spawn_delay; m_ExpireDelay = expire_delay; m_Flags = flags; }
public static StackBaseModel CreateStack(this VSGraphModel graphModel, string name, Vector2 position, SpawnFlags spawnFlags = SpawnFlags.Default) { var stackTypeToCreate = graphModel.Stencil.GetDefaultStackModelType(); if (!typeof(StackModel).IsAssignableFrom(stackTypeToCreate)) { stackTypeToCreate = typeof(StackModel); } return(graphModel.CreateModel <StackBaseModel>(stackTypeToCreate, name, position, spawnFlags)); }
/* Useful info * Main.halloween; * Main.xMas; * Main.moonPhase; * NPC.MoonLordCountdown; * NPC.saved??? * NPC.downed??? * NPC.waveNumber */ public static bool SupressSpawns(NPCSpawnInfo info, SpawnFlags required = SpawnFlags.None, SpawnZones requiredZones = SpawnZones.None, SpawnFlags forbidden = SpawnFlags.Forbidden, SpawnZones forbiddenZones = SpawnZones.Forbidden) { forbidden &= ~required; forbiddenZones &= ~requiredZones; ProcessSpawnInfo(info); return ((currentFlags & forbidden) != SpawnFlags.None || (currentZones & forbiddenZones) != SpawnZones.None || (currentFlags & required) != required || (currentZones & requiredZones) != requiredZones); }
internal void DoPress(Entity activator) { if (Locked) { return; } State = !State; FireOutput("OnPressed", activator, this); if (!SpawnFlags.Has(Flags.NoMoving)) { _ = MoveToPosition(State, activator); } }
/// <summary> /// A player has pressed this /// </summary> public virtual bool OnUse(Entity user) { if (Locked) { FireOutput("OnUseLocked", user, this); return(false); } if (SpawnFlags.Has(Flags.UseActivates)) { DoPress(user); } return(false); }
public void TestUnaryOperators(SearcherContext context, string query, UnaryOperatorKind kind, SpawnFlags mode) { var db = new GraphElementSearcherDatabase(Stencil) .AddUnaryOperators() .Build(); var results = db.Search(query, out _); Assert.AreEqual(1, results.Count); var item = results[0] as ISearcherItemDataProvider; Assert.IsNotNull(item); var data = (UnaryOperatorSearcherItemData)item.Data; Assert.AreEqual(SearcherItemTarget.UnaryOperator, data.Target); Assert.AreEqual(kind, data.Kind); if (context == SearcherContext.Graph) { Assert.IsTrue(results[0] is GraphNodeModelSearcherItem); CreateNodesAndValidateGraphModel((GraphNodeModelSearcherItem)item, mode, initialNodes => { var node = GraphModel.NodeModels.OfType <UnaryOperatorNodeModel>().FirstOrDefault(); Assert.IsNotNull(node); Assert.AreEqual(kind, node.Kind); Assert.AreEqual(initialNodes.Count + 1, GraphModel.NodeModels.Count); }); } else { Assert.IsTrue(results[0] is StackNodeModelSearcherItem); CreateNodesAndValidateStackModel((StackNodeModelSearcherItem)item, mode, (initialGraphNodes, stack) => { var node = stack.NodeModels.OfType <UnaryOperatorNodeModel>().FirstOrDefault(); Assert.IsNotNull(node); Assert.AreEqual(kind, node.Kind); Assert.AreEqual(1, stack.NodeModels.Count()); Assert.AreEqual(initialGraphNodes.Count, GraphModel.NodeModels.Count); }); } }
private static void ProcessSpawnInfo(NPCSpawnInfo info) { Player player = info.player; if (Main.time == currentTime && player.whoAmI == currentPlayer) { return; } currentTime = Main.time; currentPlayer = player.whoAmI; MyPlayer modPlayer = player.GetModPlayer <MyPlayer>(); currentZones = (SpawnZones) ((int)player.zone1 + ((int)player.zone2 << 1) + ((int)player.zone3 << 2) + ((int)player.zone4 << 3)); bool notUnderground = player.position.Y < Main.worldSurface; currentFlags = (info.desertCave ? SpawnFlags.Desertcave : SpawnFlags.None) | (info.granite ? SpawnFlags.Granite : SpawnFlags.None) | (info.marble ? SpawnFlags.Marble : SpawnFlags.None) | (info.lihzahrd ? SpawnFlags.Lihzahrd : SpawnFlags.None) | (info.spiderCave ? SpawnFlags.SpiderCave : SpawnFlags.None) | (info.sky ? SpawnFlags.Sky : SpawnFlags.None) | (info.water ? SpawnFlags.Water : SpawnFlags.None) | (info.playerSafe ? SpawnFlags.SafeWall : SpawnFlags.None) | (info.playerInTown ? SpawnFlags.Town : SpawnFlags.None) | (info.invasion ? SpawnFlags.Invasion : SpawnFlags.None) | (Main.bloodMoon && !Main.dayTime && notUnderground ? SpawnFlags.Bloodmoon : SpawnFlags.None) | (Main.eclipse && Main.dayTime && notUnderground ? SpawnFlags.Eclipse : SpawnFlags.None) | (Main.pumpkinMoon && !Main.dayTime && notUnderground ? SpawnFlags.PumpkinMoon : SpawnFlags.None) | (Main.snowMoon && !Main.dayTime && notUnderground ? SpawnFlags.FrostMoon : SpawnFlags.None) | (Main.slimeRainTime != 0.0 && notUnderground ? SpawnFlags.Slimerain : SpawnFlags.None) | (Main.expertMode ? SpawnFlags.Expert : SpawnFlags.None) | (Main.hardMode ? SpawnFlags.Hardmode : SpawnFlags.None) | (Main.dayTime ? SpawnFlags.Daytime : SpawnFlags.None) | (NPC.AnyDanger() ? SpawnFlags.Danger : SpawnFlags.None) | (modPlayer.ZoneSpirit ? SpawnFlags.Spirit : SpawnFlags.None) | (modPlayer.ZoneReach ? SpawnFlags.Reach : SpawnFlags.None) | (MyWorld.BlueMoon && !Main.dayTime && notUnderground ? SpawnFlags.BlueMoon : SpawnFlags.None) | (TideWorld.TheTide && player.ZoneBeach ? SpawnFlags.Tide : SpawnFlags.None); }
#pragma warning restore CS0649 #pragma warning restore CS0414 void CreateNodesAndValidateGraphModel(GraphNodeModelSearcherItem item, SpawnFlags mode, Action <List <INodeModel> > assertNodesCreation) { var initialNodes = GraphModel.NodeModels.ToList(); var initialEdges = GraphModel.EdgeModels.ToList(); item.CreateElements.Invoke(new GraphNodeCreationData(GraphModel, Vector2.zero, mode)); // If nodes are created as Orphan, graphModel should not be modified if (mode.IsOrphan()) { CollectionAssert.AreEqual(initialNodes, GraphModel.NodeModels); CollectionAssert.AreEqual(initialEdges, GraphModel.EdgeModels); return; } assertNodesCreation.Invoke(initialNodes); }
void CreateNodesAndValidateStackModel(StackNodeModelSearcherItem item, SpawnFlags mode, Action <List <INodeModel>, IStackModel> assertNodesCreation) { var stack = GraphModel.CreateStack("stack", Vector2.zero); var initialGraphNodes = GraphModel.NodeModels.ToList(); item.CreateElements.Invoke(new StackNodeCreationData(stack, -1, spawnFlags: mode)); // If nodes are created as Orphan, graphModel and stackModel should not be modified if (mode.IsOrphan()) { Assert.AreEqual(stack.NodeModels.Count(), 0); CollectionAssert.AreEqual(initialGraphNodes, GraphModel.NodeModels); return; } assertNodesCreation.Invoke(initialGraphNodes, stack); }
public override void Spawn() { base.Spawn(); SetupPhysicsFromModel(PhysicsMotionType.Keyframed); if (SpawnFlags.Has(Flags.NonSolid)) { EnableSolidCollisions = false; } Locked = SpawnFlags.Has(Flags.StartsLocked); TxOff = Transform; if (SpawnFlags.Has(Flags.Reverse)) { Degrees *= -1; } var angle = new Angles(0, 1, 0); if (SpawnFlags.Has(Flags.Roll)) { angle = new Angles(0, 0, 1); } else if (SpawnFlags.Has(Flags.Pitch)) { angle = new Angles(1, 0, 0); } var delta = Rotation.From(angle * Degrees); if (Speed <= 0) { Speed = 0.01f; } SecondsToTake = Degrees / Speed; TxOn = TxOff; TxOn.Rot = delta * TxOn.Rot; }
/// <summary> /// Constructor of task /// </summary> /// <param name="priority">The priority of the task</param> /// <param name="flags">The spawn flags</param> public Task(TaskPriority priority, SpawnFlags flags) { PID = NextPID++; FileDescriptors = new FileDescriptors(); Priority = priority; TimeLeft = (int)priority; // Check spawn flags if ((flags & SpawnFlags.SWAP_PID) == SpawnFlags.SWAP_PID) { int old = PID; PID = Tasking.CurrentTask.PID; Tasking.CurrentTask.PID = old; } // Other data GID = Tasking.CurrentTask.GID; UID = Tasking.CurrentTask.UID; m_launchTime = Time.FullTicks; Name = "Nameless"; CMDLine = ""; // Signals m_signalActions = new SignalAction[Signals.NSIG]; // Context Context = new X86Context(); // Filesystem related initialization if we're not a kernel task if ((flags & SpawnFlags.KERNEL_TASK) != SpawnFlags.KERNEL_TASK) { SetFileDescriptors(Tasking.CurrentTask.FileDescriptors.Clone()); CurrentDirectory = String.Clone(Tasking.CurrentTask.CurrentDirectory); } // List of addresses that need to be freed m_usedAddresses = new List(); }
public static bool SpawnAsync(string working_directory, string[] argv, string[] envp, SpawnFlags flags, SpawnChildSetupFunc child_setup, out Process child_process) { int pid; IntPtr error; IntPtr native_dir = Marshaller.StringToPtrGStrdup (working_directory); IntPtr[] native_argv = Marshaller.StringArrayToNullTermPointer (argv); IntPtr[] native_envp = Marshaller.StringArrayToNullTermPointer (envp); SpawnChildSetupWrapper wrapper = new SpawnChildSetupWrapper (child_setup); bool result; if (Global.IsWindowsPlatform) result = g_spawn_async_utf8 (native_dir, native_argv, native_envp, (int) flags, wrapper.NativeCallback, wrapper.Data, out pid, out error); else result = g_spawn_async (native_dir, native_argv, native_envp, (int) flags, wrapper.NativeCallback, wrapper.Data, out pid, out error); child_process = new Process (pid); Marshaller.Free (native_dir); Marshaller.Free (native_argv); Marshaller.Free (native_envp); if (error != IntPtr.Zero) throw new GLib.GException (error); return result; }
public static bool SpawnSync(string working_directory, string[] argv, string[] envp, SpawnFlags flags, SpawnChildSetupFunc child_setup, out string stdout, out string stderr, out int exit_status) { IntPtr native_stdout, native_stderr, error; IntPtr native_dir = Marshaller.StringToPtrGStrdup (working_directory); IntPtr[] native_argv = Marshaller.StringArrayToNullTermPointer (argv); IntPtr[] native_envp = Marshaller.StringArrayToNullTermPointer (envp); SpawnChildSetupWrapper wrapper = new SpawnChildSetupWrapper (child_setup); bool result; if (Global.IsWindowsPlatform) result = g_spawn_sync (native_dir, native_argv, native_envp, (int) flags, wrapper.NativeCallback, wrapper.Data, out native_stdout, out native_stderr, out exit_status, out error); else result = g_spawn_sync (native_dir, native_argv, native_envp, (int) flags, wrapper.NativeCallback, wrapper.Data, out native_stdout, out native_stderr, out exit_status, out error); Marshaller.Free (native_dir); Marshaller.Free (native_argv); Marshaller.Free (native_envp); stdout = Marshaller.PtrToStringGFree (native_stdout); stderr = Marshaller.PtrToStringGFree (native_stderr); if (error != IntPtr.Zero) throw new GLib.GException (error); return result; }
public static bool SpawnAsyncWithPipes(string working_directory, string[] argv, string[] envp, SpawnFlags flags, SpawnChildSetupFunc child_setup, out Process child_process, ref int stdin, ref int stdout, ref int stderr) { int pid; IntPtr error; IntPtr native_dir = Marshaller.StringToPtrGStrdup (working_directory); IntPtr[] native_argv = Marshaller.StringArrayToNullTermPointer (argv); IntPtr[] native_envp = Marshaller.StringArrayToNullTermPointer (envp); SpawnChildSetupWrapper wrapper = new SpawnChildSetupWrapper (child_setup); IntPtr in_ptr = stdin == IgnorePipe ? IntPtr.Zero : Marshal.AllocHGlobal (4); IntPtr out_ptr = stdout == IgnorePipe ? IntPtr.Zero : Marshal.AllocHGlobal (4); IntPtr err_ptr = stderr == IgnorePipe ? IntPtr.Zero : Marshal.AllocHGlobal (4); bool result; if (Global.IsWindowsPlatform) result = g_spawn_async_with_pipes_utf8 (native_dir, native_argv, native_envp, (int) flags, wrapper.NativeCallback, wrapper.Data, out pid, in_ptr, out_ptr, err_ptr, out error); else result = g_spawn_async_with_pipes (native_dir, native_argv, native_envp, (int) flags, wrapper.NativeCallback, wrapper.Data, out pid, in_ptr, out_ptr, err_ptr, out error); child_process = new Process (pid); if (in_ptr != IntPtr.Zero) { stdin = Marshal.ReadInt32 (in_ptr); Marshal.FreeHGlobal (in_ptr); } if (out_ptr != IntPtr.Zero) { stdout = Marshal.ReadInt32 (out_ptr); Marshal.FreeHGlobal (out_ptr); } if (err_ptr != IntPtr.Zero) { stderr = Marshal.ReadInt32 (err_ptr); Marshal.FreeHGlobal (err_ptr); } Marshaller.Free (native_dir); Marshaller.Free (native_argv); Marshaller.Free (native_envp); if (error != IntPtr.Zero) throw new GLib.GException (error); return result; }
// this is called from the engine's deserialize to create a new set of // levels based upon the serialized data public ChampLevelData(GenericReader reader) { int version = reader.ReadInt(); switch (version) { case 2: { m_Flags = (SpawnFlags)reader.ReadInt(); goto case 0; // skip case 1 } case 1: { bool unused = reader.ReadBool(); goto case 0; } case 0: { // read in a seriliased level ! Monsters = new string[reader.ReadInt()]; for (int i = 0; i < Monsters.Length; ++i) Monsters[i] = reader.ReadString(); m_MaxKills = reader.ReadInt(); m_MaxMobs = reader.ReadInt(); m_MaxSpawn = reader.ReadInt(); m_MaxRange = reader.ReadInt(); m_SpawnDelay = reader.ReadTimeSpan(); m_ExpireDelay = reader.ReadTimeSpan(); break; } } }
/// <summary> /// Spawn static grid - must have identity rotation matrix! If dontAdd is true, grid won't be added to enitites. Also it won't have entityId set. /// </summary> public static MyCubeGrid SpawnStaticGrid(MyCubeBlockDefinition blockDefinition, MyEntity builder, MatrixD worldMatrix, Vector3 color, SpawnFlags spawnFlags = SpawnFlags.Default) { Debug.Assert(Sync.IsServer, "Only server can spawn grids! Clients have to send requests!"); var gridBuilder = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_CubeGrid>(); Vector3 offset = Vector3.TransformNormal(MyCubeBlock.GetBlockGridOffset(blockDefinition), worldMatrix); gridBuilder.PositionAndOrientation = new MyPositionAndOrientation(worldMatrix.Translation - offset, worldMatrix.Forward, worldMatrix.Up); gridBuilder.GridSizeEnum = blockDefinition.CubeSize; gridBuilder.IsStatic = true; gridBuilder.CreatePhysics = (spawnFlags & SpawnFlags.CreatePhysics) != SpawnFlags.None; gridBuilder.EnableSmallToLargeConnections = (spawnFlags & SpawnFlags.EnableSmallTolargeConnections) != SpawnFlags.None; gridBuilder.PersistentFlags |= MyPersistentEntityFlags2.Enabled | MyPersistentEntityFlags2.InScene; if ((spawnFlags & SpawnFlags.AddToScene) != SpawnFlags.None) gridBuilder.EntityId = MyEntityIdentifier.AllocateId(); // Block must be placed on (0,0,0) coordinate var blockBuilder = MyObjectBuilderSerializer.CreateNewObject(blockDefinition.Id) as MyObjectBuilder_CubeBlock; blockBuilder.Orientation = Quaternion.CreateFromForwardUp(Vector3I.Forward, Vector3I.Up); blockBuilder.Min = blockDefinition.Size / 2 - blockDefinition.Size + Vector3I.One; if ((spawnFlags & SpawnFlags.AddToScene) != SpawnFlags.None) blockBuilder.EntityId = MyEntityIdentifier.AllocateId(); blockBuilder.ColorMaskHSV = color; MyCubeBuilder.BuildComponent.BeforeCreateBlock(blockDefinition, builder, blockBuilder, buildAsAdmin: (spawnFlags & SpawnFlags.SpawnAsMaster) != SpawnFlags.None); gridBuilder.CubeBlocks.Add(blockBuilder); MyCubeGrid grid; if ((spawnFlags & SpawnFlags.AddToScene) != SpawnFlags.None) { grid = MyEntities.CreateFromObjectBuilderAndAdd(gridBuilder) as MyCubeGrid; } else { grid = MyEntities.CreateFromObjectBuilder(gridBuilder) as MyCubeGrid; } return grid; }
public static MyCubeGrid SpawnDynamicGrid(MyCubeBlockDefinition blockDefinition, MyEntity builder, MatrixD worldMatrix, Vector3 color, long entityId = 0, SpawnFlags spawnFlags = SpawnFlags.Default) { var gridBuilder = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_CubeGrid>(); Vector3 offset = Vector3.TransformNormal(MyCubeBlock.GetBlockGridOffset(blockDefinition), worldMatrix); gridBuilder.PositionAndOrientation = new MyPositionAndOrientation(worldMatrix.Translation - offset, worldMatrix.Forward, worldMatrix.Up); gridBuilder.GridSizeEnum = blockDefinition.CubeSize; gridBuilder.IsStatic = false; gridBuilder.PersistentFlags |= MyPersistentEntityFlags2.Enabled | MyPersistentEntityFlags2.InScene; // Block must be placed on (0,0,0) coordinate var blockBuilder = MyObjectBuilderSerializer.CreateNewObject(blockDefinition.Id) as MyObjectBuilder_CubeBlock; blockBuilder.Orientation = Quaternion.CreateFromForwardUp(Vector3I.Forward, Vector3I.Up); blockBuilder.Min = blockDefinition.Size / 2 - blockDefinition.Size + Vector3I.One; blockBuilder.ColorMaskHSV = color; MyCubeBuilder.BuildComponent.BeforeCreateBlock(blockDefinition, builder, blockBuilder, buildAsAdmin: (spawnFlags & SpawnFlags.SpawnAsMaster) != SpawnFlags.None); gridBuilder.CubeBlocks.Add(blockBuilder); MyCubeGrid grid = null; //TODO: Try to find better way how to sync entity ID of subblocks.. if (entityId != 0) { gridBuilder.EntityId = entityId; blockBuilder.EntityId = entityId + 1; grid = MyEntities.CreateFromObjectBuilderAndAdd(gridBuilder) as MyCubeGrid; } else { Debug.Assert(Sync.IsServer, "Only server can generate grid entity IDs!"); if (Sync.IsServer) { gridBuilder.EntityId = MyEntityIdentifier.AllocateId(); blockBuilder.EntityId = gridBuilder.EntityId + 1; grid = MyEntities.CreateFromObjectBuilderAndAdd(gridBuilder) as MyCubeGrid; } } return grid; }