/// <summary> /// Expands an existing node. In the node: /// * All optional children are assigned if they aren't /// * If the node is a feature call, with no arguments, an empty argument is inserted. /// </summary> /// <param name="expandedIndex">Index of the expanded node.</param> /// <param name="isChanged">True upon return if the node was changed. False if the node was already expanded.</param> public virtual void Expand(IWriteableNodeIndex expandedIndex, out bool isChanged) { Contract.RequireNotNull(expandedIndex, out IWriteableNodeIndex ExpandedIndex); Debug.Assert(StateTable.ContainsKey(ExpandedIndex)); Debug.Assert(StateTable[ExpandedIndex] is IWriteablePlaceholderNodeState); WriteableOperationList OperationList = CreateOperationList(); DebugObjects.AddReference(OperationList); Expand(ExpandedIndex, OperationList); if (OperationList.Count > 0) { WriteableOperationReadOnlyList OperationReadOnlyList = OperationList.ToReadOnly(); WriteableOperationGroup OperationGroup = CreateOperationGroup(OperationReadOnlyList, null); SetLastOperation(OperationGroup); CheckInvariant(); isChanged = true; } else { isChanged = false; } }
private protected virtual ReadOnlyInnerReadOnlyDictionary <string> BuildInnerTable(ReadOnlyBrowseContext browseContext) { IReadOnlyNodeState State = browseContext.State; Debug.Assert(State.InnerTable == null); ReadOnlyIndexCollectionReadOnlyList IndexCollectionList = browseContext.IndexCollectionList; ReadOnlyInnerDictionary <string> InnerTable = CreateInnerTable(); foreach (IReadOnlyIndexCollection NodeIndexCollection in IndexCollectionList) { string PropertyName = NodeIndexCollection.PropertyName; Debug.Assert(!InnerTable.ContainsKey(PropertyName)); IReadOnlyInner Inner = BuildInner(State, NodeIndexCollection); InnerTable.Add(PropertyName, Inner); } if (InnerTable.Count > 0) { DebugObjects.AddReference(InnerTable); } return(InnerTable.ToReadOnly()); }
/// <summary> /// Initializes a new instance of the <see cref="WriteableController"/> class. /// </summary> private protected WriteableController() { _OperationStack = CreateOperationGroupStack(); DebugObjects.AddReference(_OperationStack); OperationStack = _OperationStack.ToReadOnly(); RedoIndex = 0; }
/// <summary> /// Returns a list of states for all child nodes. /// </summary> public IReadOnlyNodeStateReadOnlyList GetAllChildren() { IReadOnlyNodeStateList StateList = CreateNodeStateList(); AddChildStates(StateList, this); DebugObjects.AddReference(StateList); return(StateList.ToReadOnly()); }
/// <summary> /// Checks if the tree of cell views under this state is valid. /// </summary> public virtual bool IsCellViewTreeValid() { bool IsValid = true; IsValid &= RootCellView != null; if (IsValid && !(RootCellView is IFrameEmptyCellView)) { FrameAssignableCellViewDictionary <string> ActualCellViewTable = CreateCellViewTable(); IsValid &= RootCellView.IsCellViewTreeValid(CellViewTable, ActualCellViewTable); IsValid &= AllCellViewsProperlyAssigned(CellViewTable, ActualCellViewTable); DebugObjects.AddReference(ActualCellViewTable); } return(IsValid); }
private protected virtual void UpdateFocusChain(IFocusNodeState state, Node focusedNode, IFocusFrame focusedFrame) { FocusFocusList NewFocusChain = CreateFocusChain(); IFocusNodeState RootState = Controller.RootState; IFocusNodeStateView RootStateView = (IFocusNodeStateView)StateViewTable[RootState]; IFocusFocus MatchingFocus = null; RootStateView.UpdateFocusChain(NewFocusChain, focusedNode, focusedFrame, ref MatchingFocus); // Ensured by all templates having at least one preferred (hence focusable) frame. Debug.Assert(NewFocusChain.Count > 0); // First run, initialize the focus to the first focusable cell. if (Focus == null) { Debug.Assert(FocusChain == null); Focus = NewFocusChain[0]; ResetCaretPosition(0, true); } else if (MatchingFocus != null) { Focus = MatchingFocus; UpdateMaxCaretPosition(); // The focus didn't change, but the content may have. } else { RecoverFocus(state, NewFocusChain); // The focus has forcibly changed. } FocusChain = NewFocusChain; DebugObjects.AddReference(NewFocusChain); Debug.Assert(Focus != null); Debug.Assert(FocusChain.Contains(Focus)); SelectionAnchor = Focus.CellView.StateView; SelectionExtension = 0; }
public bool AddGameObjectIfCollidesWithMouse <T>(IList <T> collection) where T : GameObject { for (int i = 0; i < collection.Count; i++) { GameObject gameObj = collection[i]; Vector2 worldMousePos = Engine.Renderer.Camera.ScreenToWorld(Engine.InputManager.MousePosition); // Check if object collides with the mouse pointer if (CollisionUtils.PointIsInRectangleInclusive(worldMousePos, gameObj.ToRectangle())) { // Check if an object with this Name already exists in DebugObjects DebugObject debugObj = new DebugObject(gameObj); if (DebugObjects.Find(o => o.Item.Name == gameObj.Name) == null) { // Add the object to DebugObjects DebugObjects.Add(debugObj); // Return true to signal that an object was added and the other calls can be skipped return(true); } } } return(false); }
public void Update() { if (CodeVariant == 2) { if (SecondaryLayer.CurrentTrack?.File.Name == "frozen cave loop 3.wav") { SecondaryLayer.LoopingCurrent = true; } } // Update the player Player.Update(); // Update the camera Vector2 windowSize = Engine.Host.Window.Size; // Change to render size? // The center of the player on the X axis only float playerXCenter = Player.X + Player.Size.X / 2; if (playerXCenter < Engine.Renderer.Camera.X) { // Check left camera side if (Engine.Renderer.Camera.X - (windowSize.X / 2) > 0 + Player.VelocityX) { // Engine.Renderer.Camera.X -= VelocityX; Engine.Renderer.Camera.X = playerXCenter; // Move the foreground decorations faster than the player foreach (Decoration dec in ForegroundDecorations) { dec.X += Player.VelocityX + dec.VelocityOffsetX; } } // If not fix the camera along the edge of the room else { Engine.Renderer.Camera.X = 0 + (windowSize.X / 2); } } else if (playerXCenter > Engine.Renderer.Camera.X) { // Check right camera side if (Engine.Renderer.Camera.X + (windowSize.X / 2) < LoadedRoom.Size.X - Player.VelocityX) { // Engine.Renderer.Camera.X += VelocityX; Engine.Renderer.Camera.X = playerXCenter; // Move the foreground decorations faster than the player foreach (Decoration dec in ForegroundDecorations) { dec.X -= Player.VelocityX + dec.VelocityOffsetX; } } // If not fix the camera along the edge of the room else { Engine.Renderer.Camera.X = LoadedRoom.Size.X - (windowSize.X / 2); } } float playYCenterWithOffset = Player.Center.Y - 216; if (playYCenterWithOffset < Engine.Renderer.Camera.Y) { // When the vertical velocity is negative treat it as 0 in the calculations float velocityY = Player.VelocityY > 0 ? Player.VelocityY : 0; // If the upper border of the camera has enough room to move up with velocityY, then move it if (Engine.Renderer.Camera.Y - (windowSize.Y / 2) > 0 + velocityY) { Engine.Renderer.Camera.Y = playYCenterWithOffset; // CameraOffsetY } // If not fix the camera along the edge of the room else { Engine.Renderer.Camera.Y = 0 + (windowSize.Y / 2); } } else if (playYCenterWithOffset > Engine.Renderer.Camera.Y) { // When falling the camera always follows the player Engine.Renderer.Camera.Y = playYCenterWithOffset; // CameraOffsetY } // Interaction if (Player.IsInteracting && CurrentInteration == null) { CurrentInteration = new Interaction(Player, Player.InteractTarget); } else if (!Player.IsInteracting && CurrentInteration != null) { CurrentInteration = null; } else if (Player.IsInteracting && CurrentInteration != null) { CurrentInteration.Update(); } // Update all non-player units for (int i = 0; i < NonPlayerUnits.Count; i++) { NonPlayerUnits[i].Update(); } // Check for collision with Scene changers SceneChanger sceneChanger = CollisionUtils.IntersectsWithSceneChangers(Player.CollisionBox.ToRectangle()); if (sceneChanger != null) { ChangeSceneEventArgs eventArgs = new ChangeSceneEventArgs(); eventArgs.NextScenePath = sceneChanger.NextScene; this.OnChangeScene(eventArgs); } // Debug // Mouse click to add to DebugObjects if (Engine.InputManager.IsMouseKeyDown(MouseKey.Left)) { AddDebugObject(); } else if (Engine.InputManager.IsMouseKeyDown(MouseKey.Right) && DebugObjects.Count > 0) { DebugObjects.RemoveAt(DebugObjects.Count - 1); } // Camera Zoom Out if (Engine.InputManager.IsKeyDown(Key.R)) { if (Engine.Renderer.Camera.Zoom == 1f) { Engine.Renderer.Camera.Zoom = 0.4f; } else if (Engine.Renderer.Camera.Zoom == 0.4f) { Engine.Renderer.Camera.Zoom = 0.1f; } else if (Engine.Renderer.Camera.Zoom == 0.1f) { Engine.Renderer.Camera.Zoom = 1f; } } // Quit on Escape press if (Engine.InputManager.IsKeyHeld(Key.Escape)) { Engine.Quit(); } }
void Awake() { Instance = this; }
public void DebugGetStateList() { DebugObjects.AddReference(_StateList); }
public GameStatePlay(IGameStateManager gameStateManager, IWorldManager worldManager, IChunkManager chunkManager, IChunkPartManager chunkPartManager, IBlockSelector blockSelector, IBlocksProvider blocksProvider, World world) { Debug = new DebugObjects(); _world = world; _gameStateManager = gameStateManager; _worldManager = worldManager; _chunkManager = chunkManager; _chunkPartManager = chunkPartManager; _blockSelector = blockSelector; _blocksProvider = blocksProvider; _selectedBlockId = _blockSelector.GetNextBlock(0); _selectedBlockMetadata = 0; _aabbShader = ShaderManager.GetWithGeometry("AabbShader"); _baseShader = ShaderManager.GetWithGeometry("BaseShader"); _debugShader = ShaderManager.GetWithGeometry("Debug"); _guiShader = ShaderManager.Get("GuiShader"); _skyboxShader = ShaderManager.Get("SkyboxShader"); _player = new Player() { Position = new Vector3(0, 90, 0) }; _camera = new Camera(new Vector3(0), new Vector3(0), (float)(80f * (Math.PI / 180f))); _frustum = new Plane[6]; for (int i = 0; i < _frustum.Length; i++) { _frustum[i] = new Plane(); } _terrainTexture = TextureManager.Get("terrain.png", TextureMinFilter.Nearest, TextureMagFilter.Nearest); _iconsTexture = TextureManager.Get("icons.png", TextureMinFilter.Nearest, TextureMagFilter.Nearest); _skyTexture = TextureManager.Get("skybox.png", TextureMinFilter.Nearest, TextureMagFilter.Nearest); _text = new Text(new Vector2(5, 0), FontManager.Get("glyphs"), _guiShader, ""); _renderDistance = 16; _crosshair = new Sprite(new Vector2(36, 36), new Vector2(0), new Vector2(16 / 256f), _guiShader); _crosshair.UploadInGl(); _selectedBlocks = new AABBObjects(); _skybox = new Mesh() { Vertices = new List <Vertex>() { // FRONT new Vertex(new Vector3(-10, -10, -10), Vector3.One, new Vector2(1 / 4f, 2 / 3f)), new Vertex(new Vector3(10, -10, -10), Vector3.One, new Vector2(2 / 4f, 2 / 3f)), new Vertex(new Vector3(-10, 10, -10), Vector3.One, new Vector2(1 / 4f, 1 / 3f)), new Vertex(new Vector3(-10, 10, -10), Vector3.One, new Vector2(1 / 4f, 1 / 3f)), new Vertex(new Vector3(10, -10, -10), Vector3.One, new Vector2(2 / 4f, 2 / 3f)), new Vertex(new Vector3(10, 10, -10), Vector3.One, new Vector2(2 / 4f, 1 / 3f)), // RIGHT new Vertex(new Vector3(10, -10, -10), Vector3.One, new Vector2(2 / 4f, 2 / 3f)), new Vertex(new Vector3(10, -10, 10), Vector3.One, new Vector2(3 / 4f, 2 / 3f)), new Vertex(new Vector3(10, 10, -10), Vector3.One, new Vector2(2 / 4f, 1 / 3f)), new Vertex(new Vector3(10, 10, -10), Vector3.One, new Vector2(2 / 4f, 1 / 3f)), new Vertex(new Vector3(10, -10, 10), Vector3.One, new Vector2(3 / 4f, 2 / 3f)), new Vertex(new Vector3(10, 10, 10), Vector3.One, new Vector2(3 / 4f, 1 / 3f)), // LEFT new Vertex(new Vector3(-10, -10, 10), Vector3.One, new Vector2(0 / 4f, 2 / 3f)), new Vertex(new Vector3(-10, -10, -10), Vector3.One, new Vector2(1 / 4f, 2 / 3f)), new Vertex(new Vector3(-10, 10, 10), Vector3.One, new Vector2(0 / 4f, 1 / 3f)), new Vertex(new Vector3(-10, 10, 10), Vector3.One, new Vector2(0 / 4f, 1 / 3f)), new Vertex(new Vector3(-10, -10, -10), Vector3.One, new Vector2(1 / 4f, 2 / 3f)), new Vertex(new Vector3(-10, 10, -10), Vector3.One, new Vector2(1 / 4f, 1 / 3f)), // TOP new Vertex(new Vector3(-10, 10, -10), Vector3.One, new Vector2(1 / 4f, 1 / 3f)), new Vertex(new Vector3(10, 10, -10), Vector3.One, new Vector2(2 / 4f, 1 / 3f)), new Vertex(new Vector3(-10, 10, 10), Vector3.One, new Vector2(1 / 4f, 0 / 3f)), new Vertex(new Vector3(-10, 10, 10), Vector3.One, new Vector2(1 / 4f, 0 / 3f)), new Vertex(new Vector3(10, 10, -10), Vector3.One, new Vector2(2 / 4f, 1 / 3f)), new Vertex(new Vector3(10, 10, 10), Vector3.One, new Vector2(2 / 4f, 0 / 3f)), // BOTTOM new Vertex(new Vector3(-10, -10, 10), Vector3.One, new Vector2(1 / 4f, 3 / 3f)), new Vertex(new Vector3(10, -10, 10), Vector3.One, new Vector2(2 / 4f, 3 / 3f)), new Vertex(new Vector3(-10, -10, -10), Vector3.One, new Vector2(1 / 4f, 2 / 3f)), new Vertex(new Vector3(-10, -10, -10), Vector3.One, new Vector2(1 / 4f, 2 / 3f)), new Vertex(new Vector3(10, -10, 10), Vector3.One, new Vector2(2 / 4f, 3 / 3f)), new Vertex(new Vector3(10, -10, -10), Vector3.One, new Vector2(2 / 4f, 2 / 3f)), // BACK new Vertex(new Vector3(10, -10, 10), Vector3.One, new Vector2(3 / 4f, 2 / 3f)), new Vertex(new Vector3(-10, -10, 10), Vector3.One, new Vector2(4 / 4f, 2 / 3f)), new Vertex(new Vector3(10, 10, 10), Vector3.One, new Vector2(3 / 4f, 1 / 3f)), new Vertex(new Vector3(10, 10, 10), Vector3.One, new Vector2(3 / 4f, 1 / 3f)), new Vertex(new Vector3(-10, -10, 10), Vector3.One, new Vector2(4 / 4f, 2 / 3f)), new Vertex(new Vector3(-10, 10, 10), Vector3.One, new Vector2(4 / 4f, 1 / 3f)), } }; _skybox.LoadInGl(); _loadingThread = new Thread(new ThreadStart(() => { Func <int, Tuple <int, int> > spiral = (n) => { var k = (int)Math.Ceiling((Math.Sqrt(n) - 1) / 2); var t = 2 * k + 1; var m = t * t; t = t - 1; var mt = m - t; if (n > mt) { return(new Tuple <int, int>(k - (m - n), -k)); } m = mt; mt = m - t; if (n > mt) { return(new Tuple <int, int>(-k, -k + (m - n))); } m = mt; mt = m - t; if (n > mt) { return(new Tuple <int, int>(-k + (m - n), k)); } return(new Tuple <int, int>(k, k - (m - n - t))); }; while (!_stopLoading) { var chunks = _worldManager.GetLoadedChunks(_world); var playerPosition = _player.Position; var playerPos2D = playerPosition.Xz; ChunkPosition?chunkToLoad = null; var renderDistanceTime2Square = _renderDistance * 2; renderDistanceTime2Square = renderDistanceTime2Square * renderDistanceTime2Square; for (var i = 0; i < renderDistanceTime2Square; i++) { var pos = spiral(i); var chunkPositionInLocalCoordinates = new Vector2(pos.Item1, pos.Item2); if (chunkPositionInLocalCoordinates.LengthFast < _renderDistance) { var chunkPosition = new ChunkPosition((int)((chunkPositionInLocalCoordinates.X + Math.Floor(playerPos2D.X / 16f))), (int)((chunkPositionInLocalCoordinates.Y + Math.Floor(playerPos2D.Y / 16f)))); if (!chunks.Any(chunk => chunk.Item1.Equals(chunkPosition))) { chunkToLoad = chunkPosition; break; } } } if (chunkToLoad != null) { _worldManager.GetChunkAt(_world, chunkToLoad.Value.X, chunkToLoad.Value.Z); } else { Thread.Sleep(1000); } } })) { IsBackground = true }; _loadingThread.Start(); }
public void DebugGetStateTable() { DebugObjects.AddReference(_StateTable); }