public NetworkShadowWorld(IEventEngine <INetworkEventContext> networkEventEngine) { _networkEventEngine = networkEventEngine; _messagesRecieved = new Queue <MxMessageEventArgs>(); _clientsConnected = new Queue <MxClientEventArgs>(); _clientsDisconnected = new Queue <MxClientEventArgs>(); }
/// <summary> /// Handles physics events raised by the physics event engine. /// </summary> /// <param name="context">The physics event context, which doesn't contain any information.</param> /// <param name="eventEngine">The event engine for physics events.</param> /// <param name="event">The physics event that is being handled.</param> /// <returns>Whether the physics event was consumed by this event binder.</returns> public bool Handle(IPhysicsEventContext context, IEventEngine <IPhysicsEventContext> eventEngine, Event @event) { var physicsCollisionBeginEvent = @event as PhysicsCollisionBeginEvent; var physicsCollisionEndEvent = @event as PhysicsCollisionEndEvent; if (physicsCollisionBeginEvent == null && physicsCollisionEndEvent == null) { // Do not consume the event unless we're going to process it. return(false); } IEventListener <IPhysicsEventContext>[] involvedEntities; if (physicsCollisionBeginEvent != null) { involvedEntities = new[] { physicsCollisionBeginEvent.Owner1 as IEventListener <IPhysicsEventContext>, physicsCollisionBeginEvent.Owner2 as IEventListener <IPhysicsEventContext>, }; } else { involvedEntities = new[] { physicsCollisionEndEvent.Owner1 as IEventListener <IPhysicsEventContext>, physicsCollisionEndEvent.Owner2 as IEventListener <IPhysicsEventContext>, }; } // Dispatch the event to the involved entities. involvedEntities[0]?.Handle(context, eventEngine, @event); involvedEntities[1]?.Handle(context, eventEngine, @event); return(true); }
/// <summary> /// Handles an incoming event and attempts to dispatch it to all known UI elements. /// </summary> /// <param name="context"> /// The current game context. /// </param> /// <param name="eventEngine"> /// The event engine that fired the event. /// </param> /// <param name="event"> /// The event that was fired. /// </param> /// <returns> /// Whether the event was handled by this listener. /// </returns> public bool Handle(IGameContext context, IEventEngine <IGameContext> eventEngine, Event @event) { var worldHasCanvases = context.World as IHasCanvases; if (worldHasCanvases != null) { foreach (var kv in worldHasCanvases.Canvases) { if (kv.Key.HandleEvent(this.m_Skin, kv.Value, context, @event)) { return(true); } } } foreach (var kv in context.World.GetEntitiesForWorld(context.Hierarchy).OfType <IHasCanvases>().SelectMany(x => x.Canvases)) { if (kv.Key.HandleEvent(this.m_Skin, kv.Value, context, @event)) { return(true); } } return(false); }
public NetworkShadowWorld(IEventEngine<INetworkEventContext> networkEventEngine) { _networkEventEngine = networkEventEngine; _messagesRecieved = new Queue<MxMessageEventArgs>(); _clientsConnected = new Queue<MxClientEventArgs>(); _clientsDisconnected = new Queue<MxClientEventArgs>(); }
public PhysicsShadowWorld( IEventEngine <IPhysicsEventContext> physicsEventEngine, IHierarchy hierarchy, IDebugRenderer debugRenderer, IConsoleHandle consoleHandle) { _physicsEventEngine = physicsEventEngine; _hierarchy = hierarchy; _debugRenderer = debugRenderer; _consoleHandle = consoleHandle; var collisionSystem = new CollisionSystemPersistentSAP { EnableSpeculativeContacts = true }; _physicsWorld = new JitterWorld(collisionSystem); _physicsWorld.ContactSettings.MaterialCoefficientMixing = ContactSettings.MaterialCoefficientMixingType.TakeMinimum; _physicsWorld.Gravity = new JVector(0, -10f, 0); _rigidBodyMappings = new List <RigidBodyMapping>(); _lastFramePosition = new Dictionary <int, Vector3>(); _lastFrameRotation = new Dictionary <int, Quaternion>(); _transformCache = new Dictionary <int, WeakReference <IHasTransform> >(); _physicsWorld.Events.BodiesBeginCollide += EventsOnBodiesBeginCollide; _physicsWorld.Events.BodiesEndCollide += EventsOnBodiesEndCollide; }
public QueryResolver(ISeriesEngine seriesEngine, IMissionEngine missionEngine, ILogEngine logEngine, IEventEngine eventEngine) { _seriesEngine = seriesEngine; _missionEngine = missionEngine; _logEngine = logEngine; _eventEngine = eventEngine; }
public bool Handle(IGameContext context, IEventEngine <IGameContext> eventEngine, Event @event) { if (_loadedGame.State == LoadedGameState.Paused || _loadedGame.State == LoadedGameState.Playing) { _loadedGame.Playing = !_loadedGame.Playing; } return(true); }
public bool Handle(IGameContext context, IEventEngine <IGameContext> eventEngine, Event @event) { // TODO FIX /*if (_loadedGame.State == LoadedGameState.Paused || * _loadedGame.State == LoadedGameState.Playing) * { * _loadedGame.Playing = !_loadedGame.Playing; * }*/ return(true); }
public bool Handle(INetworkEventContext context, IEventEngine <INetworkEventContext> eventEngine, Event @event) { foreach (var child in _node.Children.Select(x => x.UntypedValue).OfType <IEventListener <INetworkEventContext> >()) { if (child.Handle(context, eventEngine, @event)) { return(true); } } return(false); }
public PerPixelCollisionShadowWorld( IHierarchy hierarchy, IEventEngine <IPerPixelCollisionEventContext> perPixelCollisionEventEngine, IDebugRenderer debugRenderer) { _hierarchy = hierarchy; _perPixelCollisionEventEngine = perPixelCollisionEventEngine; _debugRenderer = debugRenderer; _components = new HashSet <WeakReference <IPerPixelCollisionComponent> >(); _waitForChanges = false; _pendingChanges = new List <Action>(); }
/// <summary> /// Handles events from an event engine. This implementation propagates events through the /// component hierarchy to components that implement <see cref="IEventfulComponent"/>. /// </summary> /// <param name="context">The current game context.</param> /// <param name="eventEngine">The event engine from which the event was fired.</param> /// <param name="event">The event that is to be handled.</param> /// <returns>Whether or not the event was consumed.</returns> public virtual bool Handle(IGameContext context, IEventEngine <IGameContext> eventEngine, Event @event) { if (EnabledInterfaces.Contains(typeof(IEventfulComponent))) { var state = new EventState { Consumed = false }; _handleEvent.Invoke(context, eventEngine, @event, state); return(state.Consumed); } return(false); }
public bool Handle(IGameContext context, IEventEngine <IGameContext> eventEngine, Event @event) { if (EnabledInterfaces.Contains(typeof(IEventListener <IGameContext>))) { foreach (var child in _node.Children.Select(x => x.UntypedValue).OfType <IEventListener <IGameContext> >()) { if (child.Handle(context, eventEngine, @event)) { return(true); } } } return(false); }
/// <summary> /// Handles per-pixel collision events from the per-pixel collision engine. /// </summary> /// <param name="context">The current game context.</param> /// <param name="eventEngine">The event engine from which the event was fired.</param> /// <param name="event">The per-pixel collision event that is to be handled.</param> /// <returns>Whether or not the event was consumed.</returns> public virtual bool Handle(IPerPixelCollisionEventContext context, IEventEngine <IPerPixelCollisionEventContext> eventEngine, Event @event) { if (_hasPerPixelCollidableComponentDescendants) { var perPixelCollisionEvent = @event as PerPixelCollisionEvent; if (perPixelCollisionEvent != null) { PerPixelCollision( perPixelCollisionEvent.GameContext, perPixelCollisionEvent.ServerContext, perPixelCollisionEvent.UpdateContext, perPixelCollisionEvent.Object1, perPixelCollisionEvent.Object2); } } return(false); }
/// <summary> /// Handles physics events raised by the physics event engine. /// </summary> /// <param name="context">The physics event context, which doesn't contain any information.</param> /// <param name="eventEngine">The event engine for physics events.</param> /// <param name="event">The physics event that is being handled.</param> /// <returns>Whether the physics event was consumed by this event binder.</returns> public bool Handle(IPerPixelCollisionEventContext context, IEventEngine <IPerPixelCollisionEventContext> eventEngine, Event @event) { var perPixelEvent = @event as PerPixelCollisionEvent; if (perPixelEvent == null) { // Do not consume the event unless we're going to process it. return(false); } var involvedEntities = new[] { perPixelEvent.Object1 as IEventListener <IPerPixelCollisionEventContext>, perPixelEvent.Object2 as IEventListener <IPerPixelCollisionEventContext>, }; // Dispatch the event to the involved entities. involvedEntities[0]?.Handle(context, eventEngine, @event); involvedEntities[1]?.Handle(context, eventEngine, @event); return(true); }
/// <summary> /// Handles network events from an event engine. This implementation propagates events through the /// component hierarchy to components that implement <see cref="INetworkedComponent"/>. /// </summary> /// <param name="context">The current game context.</param> /// <param name="eventEngine">The event engine from which the event was fired.</param> /// <param name="event">The network event that is to be handled.</param> /// <returns>Whether or not the event was consumed.</returns> public virtual bool Handle(INetworkEventContext context, IEventEngine <INetworkEventContext> eventEngine, Event @event) { var networkEvent = @event as NetworkMessageReceivedEvent; if (networkEvent == null) { return(false); } var state = new EventState { Consumed = false }; if (networkEvent.GameContext != null) { _handleMessageRecievedClient.Invoke( networkEvent.GameContext, networkEvent.UpdateContext, networkEvent.Dispatcher, networkEvent.Client, networkEvent.Payload, networkEvent.ProtocolID, state); } if (networkEvent.ServerContext != null && !state.Consumed) { _handleMessageRecievedServer.Invoke( networkEvent.ServerContext, networkEvent.UpdateContext, networkEvent.Dispatcher, networkEvent.Client, networkEvent.Payload, networkEvent.ProtocolID, state); } return(state.Consumed); }
/// <summary> /// Handles the event as appropriate for the in-game console. /// </summary> /// <param name="gameContext"> /// The current game context. /// </param> /// <param name="eventEngine"> /// The current event engine. /// </param> /// <param name="event"> /// The event that is being handled. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public bool Handle(IGameContext gameContext, IEventEngine <IGameContext> eventEngine, Event @event) { // The console never handles non-keyboard events. if (!(@event is KeyboardEvent)) { return(false); } // If the console is open, consume all keyboard events. var keyPressEvent = @event as KeyPressEvent; if (_console.State == ConsoleState.Open || _console.State == ConsoleState.FullOpen) { if (keyPressEvent != null && keyPressEvent.Key == Keys.OemTilde) { _console.Toggle(); } return(true); } // We have a keyboard event, and the console isn't open. // If we aren't handling a key press, then let the event pass through. if (!(@event is KeyPressEvent)) { return(false); } // We have a key press; if it's the tilde then we open the console // and consume the event. if (keyPressEvent.Key == Keys.OemTilde) { _console.Toggle(); return(true); } // Let the event pass through. return(false); }
/// <summary> /// Handles physics events from an event engine. This implementation propagates events through the /// component hierarchy to components that implement <see cref="ICollidableComponent"/>. /// </summary> /// <param name="context">The current game context.</param> /// <param name="eventEngine">The event engine from which the event was fired.</param> /// <param name="event">The physics event that is to be handled.</param> /// <returns>Whether or not the event was consumed.</returns> public virtual bool Handle(IPhysicsEventContext context, IEventEngine <IPhysicsEventContext> eventEngine, Event @event) { if (_hasCollidableComponentDescendants) { var physicsCollisionBeginEvent = @event as PhysicsCollisionBeginEvent; var physicsCollisionEndEvent = @event as PhysicsCollisionEndEvent; if (physicsCollisionBeginEvent == null && physicsCollisionEndEvent == null) { return(false); } if (physicsCollisionBeginEvent != null) { CollisionBegin( physicsCollisionBeginEvent.GameContext, physicsCollisionBeginEvent.ServerContext, physicsCollisionBeginEvent.UpdateContext, physicsCollisionBeginEvent.Owner1, physicsCollisionBeginEvent.Owner2, physicsCollisionBeginEvent.Body1, physicsCollisionBeginEvent.Body2); } if (physicsCollisionEndEvent != null) { CollisionEnd( physicsCollisionEndEvent.GameContext, physicsCollisionEndEvent.ServerContext, physicsCollisionEndEvent.UpdateContext, physicsCollisionEndEvent.Owner1, physicsCollisionEndEvent.Owner2, physicsCollisionEndEvent.Body1, physicsCollisionEndEvent.Body2); } } return(false); }
/// <summary> /// The handle. /// </summary> /// <param name="context"> /// The context. /// </param> /// <param name="eventEngine"> /// The event engine. /// </param> /// <param name="event"> /// The event. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public bool Handle(TContext context, IEventEngine <TContext> eventEngine, Event @event) { if (!this.m_Configured) { this.Configure(); this.m_Configured = true; } if (!this.Filter(context, @event)) { return(false); } foreach (var binding in this.m_Bindings) { if (binding(context, eventEngine, @event)) { return(true); } } return(false); }
public bool Handle(ComponentizedEntity componentizedEntity, IGameContext gameContext, IEventEngine<IGameContext> eventEngine, Event @event) { if (!Enabled) { return false; } var gamepadEvent = @event as GamePadEvent; var keyHeldEvent = @event as KeyHeldEvent; var mouseEvent = @event as MouseEvent; if (gamepadEvent != null) { _firstPersonCameraComponent.Yaw -= gamepadEvent.GamePadState.ThumbSticks.Right.X* ThumbstickLookSensitivity; _firstPersonCameraComponent.Pitch += gamepadEvent.GamePadState.ThumbSticks.Right.Y* ThumbstickLookSensitivity; var limit = MathHelper.PiOver2 - MathHelper.ToRadians(5); _firstPersonCameraComponent.Pitch = MathHelper.Clamp(_firstPersonCameraComponent.Pitch, -limit, limit); var lookAt = _firstPersonCameraComponent.Transform.LocalMatrix; var relativeMovementVector = new Vector3( gamepadEvent.GamePadState.ThumbSticks.Left.X*ThumbstickMoveSensitivity, 0f, -gamepadEvent.GamePadState.ThumbSticks.Left.Y*ThumbstickMoveSensitivity); var absoluteMovementVector = Vector3.Transform(relativeMovementVector, lookAt); componentizedEntity.Transform.LocalPosition += absoluteMovementVector; return true; } if (mouseEvent != null) { var centerX = gameContext.Window.ClientBounds.Width/2; var centerY = gameContext.Window.ClientBounds.Height/2; _firstPersonCameraComponent.Yaw += (centerX - mouseEvent.MouseState.X)/1000f; _firstPersonCameraComponent.Pitch += (centerY - mouseEvent.MouseState.Y)/1000f; var limit = MathHelper.PiOver2 - MathHelper.ToRadians(5); _firstPersonCameraComponent.Pitch = MathHelper.Clamp(_firstPersonCameraComponent.Pitch, -limit, limit); Mouse.SetPosition(centerX, centerY); return true; } if (keyHeldEvent != null) { var didConsume = false; var moveX = 0; var moveZ = 0; if (keyHeldEvent.Key == Keys.A) { moveX = -1; didConsume = true; } if (keyHeldEvent.Key == Keys.D) { moveX = 1; didConsume = true; } if (keyHeldEvent.Key == Keys.W) { moveZ = 1; didConsume = true; } if (keyHeldEvent.Key == Keys.S) { moveZ = -1; didConsume = true; } var lookAt = _firstPersonCameraComponent.Transform.LocalMatrix; var relativeMovementVector = new Vector3( moveX*ThumbstickMoveSensitivity, 0f, -moveZ*ThumbstickMoveSensitivity); var absoluteMovementVector = Vector3.Transform(relativeMovementVector, lookAt); componentizedEntity.Transform.LocalPosition += absoluteMovementVector; return didConsume; } return false; }
/// <summary> /// Internally handles propagating events to <see cref="IEventfulComponent"/>. We need to structure /// it like this because if a component consumes an event, no other component should then be able to /// handle it. /// </summary> /// <param name="component">The component being processed.</param> /// <param name="gameContext">The current game context.</param> /// <param name="eventEngine">The event engine from which the event was fired.</param> /// <param name="event">The event that is to be handled.</param> /// <param name="eventState">Whether the event has been consumed yet.</param> private void EventCallback(IEventfulComponent component, IGameContext gameContext, IEventEngine <IGameContext> eventEngine, Event @event, EventState eventState) { if (!eventState.Consumed) { eventState.Consumed = component.Handle(this, gameContext, eventEngine, @event); } }
public bool Handle(ComponentizedEntity componentizedEntity, IGameContext gameContext, IEventEngine <IGameContext> eventEngine, Event @event) { if (!Enabled) { return(false); } var gamepadEvent = @event as GamePadEvent; var keyHeldEvent = @event as KeyHeldEvent; var mouseEvent = @event as MouseEvent; if (gamepadEvent != null) { _firstPersonCameraComponent.Yaw -= gamepadEvent.GamePadState.ThumbSticks.Right.X * ThumbstickLookSensitivity; _firstPersonCameraComponent.Pitch += gamepadEvent.GamePadState.ThumbSticks.Right.Y * ThumbstickLookSensitivity; var limit = MathHelper.PiOver2 - MathHelper.ToRadians(5); _firstPersonCameraComponent.Pitch = MathHelper.Clamp(_firstPersonCameraComponent.Pitch, -limit, limit); var lookAt = _firstPersonCameraComponent.Transform.LocalMatrix; var relativeMovementVector = new Vector3( gamepadEvent.GamePadState.ThumbSticks.Left.X * ThumbstickMoveSensitivity * MovementSpeed, 0f, -gamepadEvent.GamePadState.ThumbSticks.Left.Y * ThumbstickMoveSensitivity * MovementSpeed); var absoluteMovementVector = _firstPersonCameraComponent.ComputeWorldSpaceVectorFromLocalSpace(relativeMovementVector); _firstPersonControllerPhysicsComponent.TargetVelocity = absoluteMovementVector; _didSetVelocityLastFrame = true; return(true); } if (mouseEvent != null && MouseLock) { var centerX = gameContext.Window.ClientBounds.Width / 2; var centerY = gameContext.Window.ClientBounds.Height / 2; _firstPersonCameraComponent.Yaw += (centerX - mouseEvent.MouseState.X) / 1000f; _firstPersonCameraComponent.Pitch += (centerY - mouseEvent.MouseState.Y) / 1000f; var limit = MathHelper.PiOver2 - MathHelper.ToRadians(5); _firstPersonCameraComponent.Pitch = MathHelper.Clamp(_firstPersonCameraComponent.Pitch, -limit, limit); Mouse.SetPosition(centerX, centerY); return(true); } if (keyHeldEvent != null) { var didConsume = false; var moveX = 0; var moveZ = 0; if (keyHeldEvent.Key == Keys.A) { _cumulativeMoveX -= 1; didConsume = true; } if (keyHeldEvent.Key == Keys.D) { _cumulativeMoveX += 1; didConsume = true; } if (keyHeldEvent.Key == Keys.W) { _cumulativeMoveZ += 1; didConsume = true; } if (keyHeldEvent.Key == Keys.S) { _cumulativeMoveZ -= 1; didConsume = true; } var relativeMovementVector = new Vector3( _cumulativeMoveX * ThumbstickMoveSensitivity * MovementSpeed, 0f, -_cumulativeMoveZ * ThumbstickMoveSensitivity * MovementSpeed); var absoluteMovementVector = _firstPersonCameraComponent.ComputeWorldSpaceVectorFromLocalSpace(relativeMovementVector); _firstPersonControllerPhysicsComponent.TargetVelocity = absoluteMovementVector; _didSetVelocityLastFrame = true; return(didConsume); } return(false); }
public bool Handle(INetworkEventContext context, IEventEngine <INetworkEventContext> eventEngine, Event @event) { var networkReceiveEvent = @event as NetworkMessageReceivedEvent; if (networkReceiveEvent == null) { return(false); } var @object = _networkMessageSerialization.Deserialize(networkReceiveEvent.Payload); if (networkReceiveEvent.GameContext != null) { // Messages which are only allowed to be handled by the client. var createEntityMessage = @object as EntityCreateMessage; if (createEntityMessage != null) { if (_networkEngine.FindObjectByNetworkId(createEntityMessage.EntityID) != null) { // This entity was already created on the client, so we ignore it. return(true); } // Spawn an entity in the world... var world = networkReceiveEvent.GameContext.World; var spawnedEntity = _kernel.Get( Type.GetType(createEntityMessage.EntityType), _hierarchy.Lookup(world)) as IEntity; _networkEngine.RegisterObjectAsNetworkId( createEntityMessage.EntityID, spawnedEntity); if (spawnedEntity != null) { spawnedEntity.Transform.Assign(createEntityMessage.InitialTransform.DeserializeFromNetwork()); } var networkIdentifiableEntity = spawnedEntity as INetworkIdentifiable; if (networkIdentifiableEntity != null) { networkIdentifiableEntity.ReceiveNetworkIDFromServer( networkReceiveEvent.GameContext, networkReceiveEvent.UpdateContext, createEntityMessage.EntityID, createEntityMessage.FrameTick); } // Send any pending property messages? var networkEventListener = spawnedEntity as IEventListener <INetworkEventContext>; if (networkEventListener != null) { if (_pendingEntityPropertyMessages.ContainsKey(createEntityMessage.EntityID)) { foreach (var propertyMessage in _pendingEntityPropertyMessages[createEntityMessage.EntityID] .Where(x => x.Item1 > createEntityMessage.MessageOrder).OrderBy(x => x.Item1)) { networkEventListener.Handle(context, eventEngine, propertyMessage.Item2); } _pendingEntityPropertyMessages.Remove(createEntityMessage.EntityID); } } return(true); } var entityPropertiesMessage = @object as EntityPropertiesMessage; if (entityPropertiesMessage != null) { var targetObject = _networkEngine.FindObjectByNetworkId(entityPropertiesMessage.EntityID); if (targetObject != null) { // The object willingly didn't accept the message. } else { if (!_pendingEntityPropertyMessages.ContainsKey(entityPropertiesMessage.EntityID)) { _pendingEntityPropertyMessages[entityPropertiesMessage.EntityID] = new List <Tuple <int, Event> >(); } _pendingEntityPropertyMessages[entityPropertiesMessage.EntityID].Add(new Tuple <int, Event>(entityPropertiesMessage.MessageOrder, networkReceiveEvent)); } } } return(false); }
public bool Handle(INetworkEventContext context, IEventEngine <INetworkEventContext> eventEngine, Event @event) { var networkEvent = @event as NetworkEvent; if (networkEvent == null) { return(false); } var networkMessageReceivedEvent = @event as NetworkMessageReceivedEvent; var networkClientConnectedEvent = @event as NetworkClientConnectedEvent; var networkClientDisconnectedEvent = @event as NetworkClientDisconnectedEvent; if (networkEvent.GameContext != null) { var networkedWorld = networkEvent.GameContext.World as INetworkedWorld; if (networkedWorld != null) { if (networkMessageReceivedEvent != null) { if (networkedWorld.ReceiveMessage( networkEvent.GameContext, networkEvent.UpdateContext, networkEvent.Dispatcher, networkEvent.Client, networkMessageReceivedEvent.Payload, networkMessageReceivedEvent.ProtocolID)) { return(true); } } if (networkClientConnectedEvent != null) { if (networkedWorld.ClientConnected( networkEvent.GameContext, networkEvent.UpdateContext, networkEvent.Dispatcher, networkEvent.Client)) { return(true); } } if (networkClientDisconnectedEvent != null) { if (networkedWorld.ClientDisconnected( networkEvent.GameContext, networkEvent.UpdateContext, networkEvent.Dispatcher, networkEvent.Client)) { return(true); } } } foreach (var entity in networkEvent.GameContext.World.GetEntitiesForWorld(_hierarchy).OfType <IEventListener <INetworkEventContext> >()) { if (entity.Handle(context, eventEngine, @event)) { return(true); } } } else if (networkEvent.ServerContext != null) { var networkedWorld = networkEvent.ServerContext.World as INetworkedServerWorld; if (networkedWorld != null) { if (networkMessageReceivedEvent != null) { if (networkedWorld.ReceiveMessage( networkEvent.ServerContext, networkEvent.UpdateContext, networkEvent.Dispatcher, networkEvent.Client, networkMessageReceivedEvent.Payload, networkMessageReceivedEvent.ProtocolID)) { return(true); } } if (networkClientConnectedEvent != null) { if (networkedWorld.ClientConnected( networkEvent.ServerContext, networkEvent.UpdateContext, networkEvent.Dispatcher, networkEvent.Client)) { return(true); } } if (networkClientDisconnectedEvent != null) { if (networkedWorld.ClientDisconnected( networkEvent.ServerContext, networkEvent.UpdateContext, networkEvent.Dispatcher, networkEvent.Client)) { return(true); } } } foreach (var entity in networkEvent.ServerContext.World.GetEntitiesForWorld(_hierarchy).OfType <IEventListener <INetworkEventContext> >()) { if (entity.Handle(context, eventEngine, @event)) { return(true); } } } return(false); }
public EditorEventEngineHook(IEventEngine <IGameContext> eventEngine) { _queuedEvents = new ConcurrentQueue <Event>(); _eventEngine = eventEngine; }
/// <summary> /// Initializes a new instance of the <see cref="EventEngineHook"/> class. /// </summary> /// <param name="eventEngine"> /// The event engine to raise events on. /// </param> public EventEngineHook(IEventEngine <IGameContext> eventEngine) { this.m_EventEngine = eventEngine; this.m_LastGamePadStates = new Dictionary <PlayerIndex, GamePadState>(); }
/// <summary> /// Initializes a new instance of the <see cref="EventEngineHook"/> class. /// </summary> /// <param name="eventEngine"> /// The event engine to raise events on. /// </param> public EventEngineHook(IEventEngine<IGameContext> eventEngine) { _eventEngine = eventEngine; _lastGamePadStates = new Dictionary<int, GamePadState>(); }
/// <summary> /// Initializes a new instance of the <see cref="EventEngineHook"/> class. /// </summary> /// <param name="eventEngine"> /// The event engine to raise events on. /// </param> public EventEngineHook(IEventEngine <IGameContext> eventEngine) { _eventEngine = eventEngine; _lastGamePadStates = new Dictionary <int, GamePadState>(); }
public bool Handle(ComponentizedEntity componentizedEntity, IGameContext gameContext, IEventEngine <IGameContext> eventEngine, Event @event) { if (!Enabled) { return(false); } var gamepadEvent = @event as GamePadEvent; var keyHeldEvent = @event as KeyHeldEvent; var mouseEvent = @event as MouseEvent; if (gamepadEvent != null) { _firstPersonCameraComponent.Yaw -= gamepadEvent.GamePadState.ThumbSticks.Right.X * ThumbstickLookSensitivity; _firstPersonCameraComponent.Pitch += gamepadEvent.GamePadState.ThumbSticks.Right.Y * ThumbstickLookSensitivity; var limit = MathHelper.PiOver2 - MathHelper.ToRadians(5); _firstPersonCameraComponent.Pitch = MathHelper.Clamp(_firstPersonCameraComponent.Pitch, -limit, limit); var lookAt = _firstPersonCameraComponent.Transform.LocalMatrix; var relativeMovementVector = new Vector3( gamepadEvent.GamePadState.ThumbSticks.Left.X * ThumbstickMoveSensitivity, 0f, -gamepadEvent.GamePadState.ThumbSticks.Left.Y * ThumbstickMoveSensitivity); var absoluteMovementVector = Vector3.Transform(relativeMovementVector, lookAt); componentizedEntity.Transform.LocalPosition += absoluteMovementVector; return(true); } if (mouseEvent != null) { var centerX = gameContext.Window.ClientBounds.Width / 2; var centerY = gameContext.Window.ClientBounds.Height / 2; _firstPersonCameraComponent.Yaw += (centerX - mouseEvent.MouseState.X) / 1000f; _firstPersonCameraComponent.Pitch += (centerY - mouseEvent.MouseState.Y) / 1000f; var limit = MathHelper.PiOver2 - MathHelper.ToRadians(5); _firstPersonCameraComponent.Pitch = MathHelper.Clamp(_firstPersonCameraComponent.Pitch, -limit, limit); Mouse.SetPosition(centerX, centerY); return(true); } if (keyHeldEvent != null) { var didConsume = false; var moveX = 0; var moveZ = 0; if (keyHeldEvent.Key == Keys.A) { moveX = -1; didConsume = true; } if (keyHeldEvent.Key == Keys.D) { moveX = 1; didConsume = true; } if (keyHeldEvent.Key == Keys.W) { moveZ = 1; didConsume = true; } if (keyHeldEvent.Key == Keys.S) { moveZ = -1; didConsume = true; } var lookAt = _firstPersonCameraComponent.Transform.LocalMatrix; var relativeMovementVector = new Vector3( moveX * ThumbstickMoveSensitivity, 0f, -moveZ * ThumbstickMoveSensitivity); var absoluteMovementVector = Vector3.Transform(relativeMovementVector, lookAt); componentizedEntity.Transform.LocalPosition += absoluteMovementVector; return(didConsume); } return(false); }
/// <summary> /// Initializes a new instance of the <see cref="EventEngineHook"/> class. /// </summary> /// <param name="eventEngine"> /// The event engine to raise events on. /// </param> public EventEngineHook(IEventEngine<IGameContext> eventEngine) { this.m_EventEngine = eventEngine; this.m_LastGamePadStates = new Dictionary<PlayerIndex, GamePadState>(); }
public EventManager(IEventEngine eventEngine, IEventAccessor eventAccessor) { EventEngine = eventEngine; EventAccessor = eventAccessor; }
public bool Handle(ComponentizedEntity componentizedEntity, IGameContext gameContext, IEventEngine<IGameContext> eventEngine, Event @event) { if (!Enabled) { return false; } var gamepadEvent = @event as GamePadEvent; var keyHeldEvent = @event as KeyHeldEvent; var mouseEvent = @event as MouseEvent; if (gamepadEvent != null) { _firstPersonCameraComponent.Yaw -= gamepadEvent.GamePadState.ThumbSticks.Right.X* ThumbstickLookSensitivity; _firstPersonCameraComponent.Pitch += gamepadEvent.GamePadState.ThumbSticks.Right.Y* ThumbstickLookSensitivity; var limit = MathHelper.PiOver2 - MathHelper.ToRadians(5); _firstPersonCameraComponent.Pitch = MathHelper.Clamp(_firstPersonCameraComponent.Pitch, -limit, limit); var lookAt = _firstPersonCameraComponent.Transform.LocalMatrix; var relativeMovementVector = new Vector3( gamepadEvent.GamePadState.ThumbSticks.Left.X*ThumbstickMoveSensitivity* MovementSpeed, 0f, -gamepadEvent.GamePadState.ThumbSticks.Left.Y*ThumbstickMoveSensitivity * MovementSpeed); var absoluteMovementVector = _firstPersonCameraComponent.ComputeWorldSpaceVectorFromLocalSpace(relativeMovementVector); _firstPersonControllerPhysicsComponent.TargetVelocity = absoluteMovementVector; _didSetVelocityLastFrame = true; return true; } if (mouseEvent != null && MouseLock) { var centerX = gameContext.Window.ClientBounds.Width/2; var centerY = gameContext.Window.ClientBounds.Height/2; _firstPersonCameraComponent.Yaw += (centerX - mouseEvent.MouseState.X)/1000f; _firstPersonCameraComponent.Pitch += (centerY - mouseEvent.MouseState.Y)/1000f; var limit = MathHelper.PiOver2 - MathHelper.ToRadians(5); _firstPersonCameraComponent.Pitch = MathHelper.Clamp(_firstPersonCameraComponent.Pitch, -limit, limit); Mouse.SetPosition(centerX, centerY); return true; } if (keyHeldEvent != null) { var didConsume = false; var moveX = 0; var moveZ = 0; if (keyHeldEvent.Key == Keys.A) { _cumulativeMoveX -= 1; didConsume = true; } if (keyHeldEvent.Key == Keys.D) { _cumulativeMoveX += 1; didConsume = true; } if (keyHeldEvent.Key == Keys.W) { _cumulativeMoveZ += 1; didConsume = true; } if (keyHeldEvent.Key == Keys.S) { _cumulativeMoveZ -= 1; didConsume = true; } var relativeMovementVector = new Vector3( _cumulativeMoveX * ThumbstickMoveSensitivity * MovementSpeed, 0f, -_cumulativeMoveZ * ThumbstickMoveSensitivity * MovementSpeed); var absoluteMovementVector = _firstPersonCameraComponent.ComputeWorldSpaceVectorFromLocalSpace(relativeMovementVector); _firstPersonControllerPhysicsComponent.TargetVelocity = absoluteMovementVector; _didSetVelocityLastFrame = true; return didConsume; } return false; }
public EventLogic() { eventEngine = new EventEngine(); }