private void DrawSite(MapSiteInstance site) { var ownTransform = new HierarchyTransform(site.GlobalPos, site.GlobalRot, null); ownTransform.DrawAsDir(0.3f); var _rectShape = new RectShapeHandle(); _rectShape.Size = new Vector2f(site.Def.SizeX, site.Def.SizeY); _rectShape.FillColor = Color.Transparent; _rectShape.OutlineThickness = 1; _rectShape.OutlineColor = Color.Red; ownTransform.DrawShapeAt(_rectShape, Vec2.New(0.5f, 0.5f)); foreach (var subSite in site.SubSites) { //siteT.Rotate(subSite.Value.Rot); DrawSite(subSite.Value); } foreach (var con in site.Connections) { //siteT.Rotate(con.Value.Rot); DrawSite(con.Value); } foreach (var shape in site.World._shapes) { if (shape is OverlapBox box) { _rectShape.OutlineColor = Color.Green; _rectShape.Size = new Vector2f(box.Size.X, box.Size.Y); var t = new HierarchyTransform(Vec2.New(box.Pos.X, box.Pos.Y), box.RotAngles, null); t.DrawShapeAt(_rectShape, Vec2.New(0.5f, 0.5f)); } } foreach (var shape in site.World._failedShapes) { if (shape is OverlapBox box) { _rectShape.OutlineColor = Color.Cyan; _rectShape.Size = new Vector2f(box.Size.X, box.Size.Y); var t = new HierarchyTransform(Vec2.New(box.Pos.X, box.Pos.Y), box.RotAngles, null); t.DrawShapeAt(_rectShape, Vec2.New(0.5f, 0.5f)); } } }
public void Update(bool onlyDrawGUI) { if (onlyDrawGUI && character != null) { CharGUI.Render(_node, _win, character as CharacterEntity, _charView); return; } if (!_connected.IsCompleted) { _node.Tick().Wait(); return; } else if (!_connected.Result) { _node.Tick().Wait(); return; } if (!joined) { var session = _node.AllGhosts().SingleOrDefault(x => x is SessionEntity); if (session != null) { ((SessionEntity)session).Join("Name" + (new System.Random()).Next().ToString()); joined = true; } } if (_win != null) { _win.DispatchEvents(); _win.Clear(Color.Blue); } var deltaTime = GetDeltaTime(); foreach (var ghost in _node.AllGhosts()) { if (ghost is ICharacterLikeMovement charLikeMovement) { if (charLikeMovement.PhysicsBody == null) { var pos = ((IPositionedEntity)ghost).Position; lock (_physicsWorld) { var body = _physicsWorld.CreateDynamicBody(new Vector2(pos.X, pos.Y), 1, _physicsWorld.CreateCircleWorldSpace(new Vector2(pos.X, pos.Y), 1f, 1)); body.UserData = ghost.Id; charLikeMovement.PhysicsBody = body; } } else { var pos = ((IPositionedEntity)ghost).Position; var _debugPhysicsShape = new RectShapeHandle(); var aabb = charLikeMovement.PhysicsBody.AABB; HierarchyTransform v = new HierarchyTransform(Vec2.New(aabb.Center.x, aabb.Center.y), 0, null); _debugPhysicsShape.FillColor = Color.Transparent; _debugPhysicsShape.OutlineColor = Color.Red; _debugPhysicsShape.OutlineThickness = 1; _debugPhysicsShape.Size = new SFML.System.Vector2f(aabb.Extent.x * 2, aabb.Extent.y * 2); v.DrawShapeAt(_debugPhysicsShape, Vec2.New(0.5f, 0.5f)); } if (ghost.HasAuthority) { character = ghost; if (_win != null ? _win.HasFocus() : true) { charLikeMovement.UpdateControls(); } charLikeMovement.UpdateMovement(); _charView.Center = new Vector2f(charLikeMovement.SmoothPosition.X, charLikeMovement.SmoothPosition.Y); if (_win != null) { _charView.Size = new Vector2f(256, -256 * ((float)_win.Size.Y / (float)_win.Size.X)); _win.SetView(_charView); } } else { charLikeMovement.InterpolationUpdate(deltaTime); } } } DrawSite(SimpleServer._debugCreator._rootInstance); foreach (var ghost in _node.AllGhosts()) { if (ghost is IRenderable rnd) { rnd.Render(_win); } } CharGUI.Render(_node, _win, character as CharacterEntity, _charView); var tick = _node.Tick(); lock (_physicsWorld) { _physicsWorld.DeltaTime = EnvironmentAPI.Time.DeltaTime; _physicsWorld.Update(); } lock (_physicsWorld) { foreach (var body in _physicsWorld.Bodies) { var aabb = body.AABB; var _shape = new RectShapeHandle(); HierarchyTransform v = new HierarchyTransform(Vec2.New(aabb.Center.x, aabb.Center.y), body.Angle / Mathf.PI * 180, null); _shape.FillColor = Color.Transparent; _shape.OutlineColor = Color.Red; _shape.OutlineThickness = 1; _shape.Size = new SFML.System.Vector2f(aabb.Extent.x * 2, aabb.Extent.y * 2); foreach (var shape in body.shapes) { if (shape is VoltPolygon vp) { HierarchyTransform vpt = new HierarchyTransform(Vec2.New(vp.bodySpaceAABB.Center.x, vp.bodySpaceAABB.Center.y), 0, v); _shape.FillColor = Color.Transparent; _shape.OutlineColor = Color.Yellow; _shape.OutlineThickness = 1; _shape.Size = new SFML.System.Vector2f(vp.bodySpaceAABB.Extent.x * 2, vp.bodySpaceAABB.Extent.y * 2); vpt.DrawShapeAt(_shape, Vec2.New(0.5f, 0.5f)); } } } } if (_win != null) { _win.Display(); } tick.Wait(); }