void EmitIssueAboutUnsupportedEffect(Effect?effect, string effectName) { if (effect is not null) { EmitIssueAboutUnsupportedEffect(effectName); } }
// TODO: Shapes (filled, borders) // Textures // Shaders public void Begin(Matrix?view = null, Effect?effect = null) { if (view != null) { _view = view.Value; } else { _view = Matrix.Identity; } if (effect != null) { _effect = effect; _customEffect = true; } else { _effect = _defaultEffect; _customEffect = false; } int width = _graphicsDevice.Viewport.Width; int height = _graphicsDevice.Viewport.Height; _projection = Matrix.CreateOrthographicOffCenter(0, width, height, 0, 0, 1); }
/// <summary> /// Constructor that sets delay, easing, effect and duration properties /// </summary> /// <param name="delay">delay as int</param> /// <param name="easing">easing as enum</param> /// <param name="effect">effect as enum</param> /// <param name="duration">duration as int</param> public DialogAnimate(int?delay = null, Easing?easing = null, Effect?effect = null, int?duration = null) { this.Delay = delay; this.Effect = effect; this.Easing = easing; this.Duration = duration; }
/// <summary> /// Begins a new sprite and text batch with the specified render state. /// </summary> /// <param name="sortMode">The drawing order for sprite and text drawing. <see cref="SpriteSortMode.Deferred"/> by default.</param> /// <param name="blendState">State of the blending. Uses <see cref="BlendState.AlphaBlend"/> if null.</param> /// <param name="samplerState">State of the sampler. Uses <see cref="SamplerState.LinearClamp"/> if null.</param> /// <param name="depthStencilState">State of the depth-stencil buffer. Uses <see cref="DepthStencilState.None"/> if null.</param> /// <param name="rasterizerState">State of the rasterization. Uses <see cref="RasterizerState.CullCounterClockwise"/> if null.</param> /// <param name="effect">A custom <see cref="Effect"/> to override the default sprite effect. Uses default sprite effect if null.</param> /// <param name="transformMatrix">An optional matrix used to transform the sprite geometry. Uses <see cref="Matrix4x4.Identity"/> if null.</param> /// <exception cref="InvalidOperationException"><see cref="Begin"/> is called next time without previous <see cref="End"/>.</exception> /// <remarks> /// <see cref="Begin"/> should be called before draw methods, /// and you cannot call it again before subsequent <see cref="End"/>. /// </remarks> public void Begin( SpriteSortMode sortMode = SpriteSortMode.Deferred, BlendState?blendState = null, SamplerState?samplerState = null, DepthStencilState?depthStencilState = null, RasterizerState?rasterizerState = null, Effect?effect = null, Matrix4x4?transformMatrix = null) { if (_beginCalled) { throw new InvalidOperationException( "Begin cannot be called again until End has been called."); } // defaults _sortMode = sortMode; _blendState = blendState ?? BlendState.AlphaBlend; _samplerState = samplerState ?? SamplerState.LinearClamp; _depthStencilState = depthStencilState ?? DepthStencilState.None; _rasterizerState = rasterizerState ?? RasterizerState.CullCounterClockwise; _effect = effect; SpriteEffect.TransformMatrix = transformMatrix; // Setup things now so a user can change them. if (sortMode == SpriteSortMode.Immediate) { Setup(); } _beginCalled = true; }
protected void Init(FrameworkElement root) { _root = root; _root.Opacity = 0; // keep Root shadow reference, remove it from view, apply after animation _rootEffect = _root.Effect; _root.Effect = null; }
/// <summary> /// Include a change state effect in the current transition /// </summary> /// <param name="varName">the variable to change</param> /// <param name="value">the value to add to the variable</param> /// <returns>the FluentMachine builder</returns> public FluentMachine ChangeState(string varName, int value) { possibleEffect = Effect.CHANGE; if (!variables.Contains(varName)) { throw new Exception("Undefined variable: " + varName); } effectVariable = varName; effectArgument = value; return(this); }
/// <summary> /// 获取消耗item /// </summary> /// <param name="tid">tid</param> /// <returns></returns> public EffectElement?[] GetEffectElementsByKey(uint tid) { Effect?effectVO = m_Config.EffectsByKey(tid); Assert.IsTrue(effectVO.HasValue, "CfgEternityProxy => EffectsByKey not exist tid " + tid); EffectElement?[] effectElements = new EffectElement?[effectVO.Value.ElementsLength]; for (int i = 0; i < effectVO.Value.ElementsLength; i++) { effectElements[i] = effectVO.Value.Elements(i); } return(effectElements); }
public GenericTransition(string target, Effect?possibleEffect, string effectVariableName, int?effectArgument, Condition?cond, string possibleCondVariableName, int?condValue) : base(target) { this.possibleEffect = possibleEffect; this.effectVariableName = effectVariableName; this.effectArgument = effectArgument; this.possibleCondition = cond; this.possibleCondVariableName = possibleCondVariableName; this.condValue = condValue; if (possibleEffect != null && effectVariableName == null) { throw new Exception("Inconsistent effect description"); } }
/// <summary> /// Manage the selection of a new Effect for a Player that is leveling up /// </summary> /// <param name="player">Player that is leveling up</param> /// <returns>Effect chosen for the Player leveling up (if invalid, returns null)</returns> public Effect?PlayerLevelsUp(Player player) { // We define the dices int dice1 = Dice.Roll6(); int dice2 = Dice.Roll6(); // We send their results Net.INT.Send(comm.GetStream(), dice1); Net.INT.Send(comm.GetStream(), dice2); // While we wait for the result... // Select the Effect Types the player can level up in List <EffectType> types = EffectStuff.GetEffectTypesForLevelUp(player.role, dice1, dice2); List <List <Effect> > effects = EffectStuff.GetEffectsForLevelUp(types); // We receive the Effect chosen Effect?effectReceived = Net.EFFECT.Receive(comm.GetStream()); // We check if the Effect received is valid // By default, we think it is false, so we search to find the Effect in the valid one. If we find it, then it is valid ! bool isValid = false; foreach (List <Effect> currentList in effects) { foreach (Effect effect in currentList) { // if we find the Effect : good ! if (effect == effectReceived) { isValid = true; break; } } // We stop itirating once it is found if (isValid) { break; } } // We return to the user whether the Effect was accepted or not Net.BOOL.Send(comm.GetStream(), isValid); // If reached, return the effect received return((isValid) ? effectReceived : null); }
/// <summary> /// Flush the current transition, in preparation for the start of a new transition or state /// </summary> /// <param name="condition">the condition type, if any, on the transition being finalized</param> /// <param name="possibleCondVariableName">the variable to test on, if any</param> /// <param name="condValue">the value to compare to, if any</param> private void FlushTransition(Condition?condition, string possibleCondVariableName, int condValue) { if (pendingEvent == null) { return; } if (targetTransition == null && possibleEffect == null) { return; } Transition <GenericRuntimeState> transition = factory.CreateTransitionHook(targetTransition, possibleEffect, effectVariable, effectArgument, condition, possibleCondVariableName, condValue); currentState.AddTransition(pendingEvent, transition); possibleEffect = null; effectVariable = null; effectArgument = null; }
/// <summary> /// Sends the triangle list to the graphics device. Here is where the actual drawing starts. /// </summary> /// <param name="quads">The vertices to draw.</param> /// <param name="effect">The custom effect to apply to the geometry.</param> /// <param name="texture">The texture to draw.</param> private void FlushQuads( ReadOnlySpan <SpriteQuad> quads, Effect?effect, Texture texture) { if (quads.IsEmpty) { return; } Debug.Assert(_indexBuffer != null); Debug.Assert(_vertexBuffer != null); const PrimitiveType primitiveType = PrimitiveType.TriangleList; var vertices = MemoryMarshal.Cast <SpriteQuad, VertexPositionColorTexture>(quads); _vertexBuffer.SetData(vertices); _device.SetVertexBuffer(_vertexBuffer); _device.Indices = _indexBuffer; if (effect == null) { // If no custom effect is defined, then simply render. _device.DrawIndexedPrimitives(primitiveType, 0, 0, vertices.Length / 2); } else { // If the effect is not null, then apply each pass and render the geometry foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); // Whatever happens in pass.Apply, make sure the texture being drawn // ends up in Textures[0]. _device.Textures[0] = texture; _device.DrawIndexedPrimitives(primitiveType, 0, 0, vertices.Length / 2); } } }
/// <summary> /// Constructor that sets enable, delay, easing, effect and duration properties /// </summary> /// <param name="enable">enable as bool</param> /// <param name="delay">delay as int</param> /// <param name="easing">easing as enum</param> /// <param name="effect">effect as enum</param> /// <param name="duration">duration as int</param> public TabAnimate(bool?enable = null, int?delay = null, Easing?easing = null, Effect?effect = null, int?duration = null) { this.Enable = enable; this.Delay = delay; this.Easing = easing; this.Effect = effect; this.Duration = duration; }
/// <summary> /// Server's HUB : it does stuff. /// </summary> public void DoOperation() { while (true) { // We receive a Communication from the client Communication communication = Net.COMMUNICATION.Receive(comm.GetStream()); // We extract the data Instructions instruction = communication.instruction; Object content = communication.content; // We display the instruction CONSOLE.WriteLine(ConsoleColor.Cyan, "\nINSTRUCTION : " + instruction); // According to the instruction, we'll do a specific action switch (instruction) { case Instructions.Exit_Software: // We raise the event : a user left the software When_Server_Exit?.Invoke(comm); break; // CREDENTIALS case Instructions.LogIn: if (LogIn((Credentials)content)) { // We raise the event : a user has logged in When_Server_LogIn?.Invoke(comm); } break; case Instructions.SignIn: // We get the profile Signed In CoachWithPassword newCoach = SignIn((CoachWithPassword)content); // If the Profile's ID is not Empty (means that the Sign In was successful) if (newCoach.id != Guid.Empty) { // We raise the event : a user has logged in When_Server_LogIn?.Invoke(comm); // We raise the event : a Profile has been created When_Coach_Create(newCoach); } break; case Instructions.LogOut: LogOut(); // We raise the event : a user has logged off When_Server_LogOff?.Invoke(comm); break; // COACH case Instructions.Coach_GetById: GetCoachById((Guid)content); break; // TEAM case Instructions.Team_New: // We get the newly created Team Team newTeam = NewTeam((Team)content); // If the Team can be created (ID is not empty) if (newTeam.IsComplete) { // We raise the event : a Team has been created When_Team_Create?.Invoke(newTeam); } break; case Instructions.Team_AddPlayer: // We get the newly created Player Player newPlayer = NewPlayer((Player)content); // If the Player can be created (ID is not empty) if (newPlayer.IsComplete) { // We raise the event : a Player has been created When_Player_Create?.Invoke(newPlayer); } break; case Instructions.Team_RemovePlayer: // We get the Player to remove Player playerToRemove = (Player)content; // We remove him from the database playerToRemove = RemovePlayer(playerToRemove); // If the removal was successful) if (playerToRemove.IsComplete) { // We raise the event : a Player has been removed When_Player_Remove?.Invoke(playerToRemove); } break; // PLAYER case Instructions.Player_LevelUp: // We get the Player to remove Player player = (Player)content; // We add a new Effect to the player Effect?newEffect = PlayerLevelsUp(player); // If a new effect was chosen if (newEffect != null) { // We add the effect to the Player player.effects.Add((Effect)newEffect); // We raise the event : an Effect has been added When_Player_LevelsUp?.Invoke(player); } break; // otherwise : Error (should not occur, but we're not taking any chance) default: CONSOLE.WriteLine(ConsoleColor.Red, "Message instruction not understood : " + instruction); break; } } }
/// <summary> /// Hook method allowing the creation of a transition to be changed, as specified by the arguments. /// </summary> /// <param name="target">the target of the transition</param> /// <param name="effect">the effect of the transition, if any</param> /// <param name="effectVarName">the variable that the transition has an effect on, if any</param> /// <param name="effectArg">the argument of the effect, if any</param> /// <param name="condition">the condition of the transition, if any</param> /// <param name="possibleCondVariable">the variable used in the condition, if any</param> /// <param name="condValue">the value used in the condition, if any</param> /// <returns>a transition object created according to the specification.</returns> internal Transition <GenericRuntimeState> CreateTransitionHook(string target, Effect?effect, string effectVarName, int?effectArg, Condition?condition, string possibleCondVariable, int?condValue) { return(new GenericTransition(target, effect, effectVarName, effectArg, condition, possibleCondVariable, condValue)); }
/// <summary> /// Sorts the batch items and then groups batch drawing into maximal allowed batch sets that do not /// overflow the 16-bit array indices for vertices. /// </summary> /// <param name="sortMode">The type of depth sorting desired for the rendering.</param> /// <param name="effect">The custom effect to apply to the drawn geometry</param> public unsafe void DrawBatch(SpriteSortMode sortMode, Effect?effect) { if (effect != null && effect.IsDisposed) { throw new ArgumentException( "The effect is disposed.", nameof(effect), new ObjectDisposedException(effect.GetType().FullName)); } // nothing to do if (_itemCount == 0) { return; } // sort the batch items switch (sortMode) { case SpriteSortMode.Texture: case SpriteSortMode.FrontToBack: case SpriteSortMode.BackToFront: Array.Sort(_batchItems, 0, _itemCount); break; } // iterate through the batches, doing clamped sets of vertices at the time Span <SpriteQuad> quadBuffer = _quadBuffer.AsSpan(); int itemIndex = 0; int itemsLeft = _itemCount; while (itemsLeft > 0) { int itemsToProcess = itemsLeft; if (itemsToProcess > MaxBatchSize) { itemsToProcess = MaxBatchSize; } int count = 0; Texture2D?tex = null; // TODO: create a path with sort-by-texture that does less ref-equality checks // (having such a path allows copying multiple items at once) // draw the batches for (int i = 0; i < itemsToProcess; i++, count++) { var item = _batchItems[itemIndex++]; // if the texture changed, we need to flush and bind the new texture if (!ReferenceEquals(item.Texture, tex)) { Debug.Assert(item.Texture != null); FlushQuads(quadBuffer.Slice(0, count), effect, tex); count = 0; tex = item.Texture; _device.Textures[0] = tex; } item.Texture = null; // release texture from item quadBuffer[count] = item.Quad; } // flush the remaining data FlushQuads(quadBuffer.Slice(0, count), effect, tex); itemsLeft -= itemsToProcess; } unchecked { _device._graphicsMetrics._spriteCount += _itemCount; } _itemCount = 0; }
public static void WithScissor(SpriteBatch b, SpriteSortMode mode, Rectangle rectangle, Action action, RenderTarget2D?target = null) { var smField = Helper?.Reflection.GetField <SpriteSortMode>(b, "_sortMode", false); SpriteSortMode old_sort = smField?.GetValue() ?? mode; var bsField = Helper?.Reflection.GetField <BlendState>(b, "_blendState", false); BlendState?old_blend = bsField?.GetValue(); var ssField = Helper?.Reflection.GetField <SamplerState>(b, "_samplerState", false); SamplerState?old_sampler = ssField?.GetValue(); var dsField = Helper?.Reflection.GetField <DepthStencilState>(b, "_depthStencilState", false); DepthStencilState?old_depth = dsField?.GetValue(); var rsField = Helper?.Reflection.GetField <RasterizerState>(b, "_rasterizerState", false); RasterizerState?old_rasterizer = rsField?.GetValue(); var efField = Helper?.Reflection.GetField <Effect>(b, "_effect", false); Effect?old_effect = efField?.GetValue(); var old_scissor = b.GraphicsDevice.ScissorRectangle; var old_targets = b.GraphicsDevice.GetRenderTargets(); RasterizerState state = new() { ScissorTestEnable = true }; if (old_rasterizer != null) { state.CullMode = old_rasterizer.CullMode; state.FillMode = old_rasterizer.FillMode; state.DepthBias = old_rasterizer.DepthBias; state.MultiSampleAntiAlias = old_rasterizer.MultiSampleAntiAlias; state.SlopeScaleDepthBias = old_rasterizer.SlopeScaleDepthBias; state.DepthClipEnable = old_rasterizer.DepthClipEnable; } b.End(); b.Begin( sortMode: mode, blendState: old_blend, samplerState: old_sampler, depthStencilState: old_depth, rasterizerState: state, effect: old_effect, transformMatrix: null ); if (target != null) { b.GraphicsDevice.SetRenderTarget(target); } b.GraphicsDevice.ScissorRectangle = Rectangle.Intersect(rectangle, old_scissor); try { action?.Invoke(); } finally { b.End(); b.Begin( sortMode: old_sort, blendState: old_blend, samplerState: old_sampler, depthStencilState: old_depth, rasterizerState: old_rasterizer, effect: old_effect, transformMatrix: null ); if (target != null) { var rt = (old_targets?.Length ?? 0) > 0 ? old_targets ![0].RenderTarget : null; b.GraphicsDevice.SetRenderTarget((RenderTarget2D?)rt); }
public static void OnBegin(XSpriteBatch __instance, ref SpriteSortMode sortMode, BlendState?blendState, SamplerState?samplerState, DepthStencilState?depthStencilState, RasterizerState?rasterizerState, Effect?effect, Matrix?transformMatrix) { if (!Config.IsEnabled) { return; } /* * if (sortMode is (SpriteSortMode.Deferred or SpriteSortMode.Immediate)) { * sortMode = SpriteSortMode.Texture; * } */ DrawState.OnBegin( __instance, sortMode, blendState ?? BlendState.AlphaBlend, samplerState ?? SamplerState.PointClamp, depthStencilState ?? DepthStencilState.None, rasterizerState ?? RasterizerState.CullCounterClockwise, effect, transformMatrix ?? Matrix.Identity ); }
public static Effect?ToEffect(this CGameEffect?effect, bool memoryOwn) { Effect?retVal = effect != null && effect.Pointer != IntPtr.Zero ? new Effect(effect, memoryOwn) : null; return(retVal); }