public static ComponentType Instance(Constant.enumComponent iD) { if (m_InstanceList == null) { m_InstanceList = new List<ComponentType>(); } if (!m_InstanceList.Any(x=>x.m_ComponentTypeID ==iD)) { m_InstanceList.Add(new ComponentType(iD)); } return m_InstanceList.FirstOrDefault(x=>x.m_ComponentTypeID==iD); }
public static MessageType Instance(Constant.enumMessage iD, Boolean command) { if (m_InstanceList == null) { m_InstanceList = new List<MessageType>(); } if (!m_InstanceList.Any(x => x.m_MsgTypeID == iD && x.m_Command == command)) { m_InstanceList.Add(new MessageType(iD, command)); } return m_InstanceList.FirstOrDefault(x => x.m_MsgTypeID == iD && x.m_Command == command); }
public RigidBody(float mass = 0.0f, float drag = 0.0f, float angularDrag = 0.0f, Boolean gravity = false, Boolean kinematic = false, Constant.enumCollisionDetection collisionDetection = Constant.enumCollisionDetection.DISCRETE_CD, Vector3 freezePos = null, Vector3 freezeRot = null) { m_Mass = mass; if (drag >= 0.0f && drag <= 1.0f) { m_Drag = drag; } else { if (drag < 0.0f) m_Drag = 0.0f; if (drag > 1.0f) m_Drag = 1.0f; } if (angularDrag >= 0.0f && angularDrag <= 1.0f) { m_AngularDrag = angularDrag; } else { if (angularDrag < 0.0f) m_AngularDrag = 0.0f; if (angularDrag > 1.0f) m_AngularDrag = 1.0f; } m_Gravity = gravity; m_Kinematic = kinematic; m_CollisionDetection = collisionDetection; m_FreezePosition = freezePos == null ? new Vector3() : freezePos; m_FreezeRotation = freezeRot == null ? new Vector3() : freezeRot; m_ComponentType = ComponentType.Instance(Constant.enumComponent.RIGIDBODY); m_Position = new Vector3(); m_Rotation = new Vector3(); m_Velocity = new Vector3(); m_Acceleration = new Vector3(); m_PreviousFrameAcceleration = new Vector3(); m_PreviousFrameVelocity = new Vector3(); m_PreviousFramePosition = new Vector3(); }
public void SendMessage(Constant.enumMessage msgTypeID, Object[] data = null, Boolean command = true) { if (command) { IMessage msg2 = new Message(msgTypeID, true, null); m_POBox.Add(msg2); } if (data != null) { IMessage msg = new Message(msgTypeID, false, data); m_POBox.Add(msg); } if (data == null && !command) { throw new ApplicationException(); } m_Observer.Notify(true); m_POBox.Clear(); if(command) m_Observer.Notify(false); }
public void RemoveMessage(Constant.enumMessage msgTypeID, Constant.enumModuleID moduleID, Boolean command = true) { //m_LetterBoxes[moduleID].Remove(m_LetterBoxes[moduleID].Where(msg => msg.m_MsgType.m_MsgTypeID == msgTypeID).FirstOrDefault()); IMessage[] msgArray = m_LetterBoxes[moduleID].Where(msg => msg.m_MsgType.m_MsgTypeID == msgTypeID && (command ? msg.m_MsgType.m_Command : !msg.m_MsgType.m_Command)).ToArray(); foreach(IMessage msg in msgArray) { m_LetterBoxes[moduleID].Remove(msg); } //throw new NotImplementedException(); }
public void LockMessageType(Constant.enumMessage msgTypeID) { if (m_MsgLockables.Contains(msgTypeID) && !m_LockList.Contains(msgTypeID)) { m_LockList.Add(msgTypeID); } }
//TODO: Remove if GetMessageObjects(Constant.enumModuleID moduleID, Constant.enumMessage msgID) works fine /* public Object[] GetMessageObjects(Constant.enumModuleID moduleID, Constant.enumMessage msgID, Boolean command = false) { return m_LetterBoxes[moduleID].Where(msg => msgID == msg.m_MsgType.m_MsgTypeID && (command ? msg.m_MsgType.m_Command : !msg.m_MsgType.m_Command)).Select(msg => msg.m_Data).ToArray(); } public Object[] GetMessageObjects(Constant.enumModuleID moduleID, Constant.enumMessage[] msgIDArray, Boolean command = false) { return m_LetterBoxes[moduleID].Where(msg => msgIDArray.Contains(msg.m_MsgType.m_MsgTypeID) && (command ? msg.m_MsgType.m_Command : !msg.m_MsgType.m_Command)).Select(msg => msg.m_Data).ToArray(); }*/ /* public T[] GetMessageObjects<T>(Constant.enumModuleID moduleID, Constant.enumMessage msgID, Boolean command = false) { IMessage[] msgArray = m_LetterBoxes[moduleID].Where(x => msgID == x.m_MsgType.m_MsgTypeID && command ? x.m_MsgType.m_Command : !x.m_MsgType.m_Command).ToArray(); List<T> tList = new List<T>(); foreach (IMessage msg in msgArray) { tList.Add(msg.m_Data(typeof(T); } throw new NotImplementedException(); } */ /* public Constant.enumMessage[] getMessageTypeIDs(Constant.enumModuleID moduleID, Boolean command = true) { if (!command) { return m_LetterBoxes[moduleID].Select(msg => msg.m_MsgType.m_MsgTypeID).ToArray(); } else { return m_LetterBoxes[moduleID].Where(msg => (command ? msg.m_MsgType.m_Command : !msg.m_MsgType.m_Command)).Select(msg => msg.m_MsgType.m_MsgTypeID).ToArray(); } //throw new NotImplementedException(); } */ public Constant.enumMessage[] getMessageTypeIDs(Constant.enumModuleID moduleID) { return m_LetterBoxes[moduleID].Where(msg => msg.m_MsgType.m_Command).Select(msg => msg.m_MsgType.m_MsgTypeID).Where(id=>!m_LockList.Contains(id)).ToArray(); //throw new NotImplementedException(); }
public IMessage[] GetMessages(Constant.enumModuleID moduleID, Constant.enumMessage[] msgIDList = null, Boolean? command = null) { if (!command.HasValue) { return m_LetterBoxes[moduleID].Where(msg => msgIDList.Contains(msg.m_MsgType.m_MsgTypeID)).ToArray(); } else { return m_LetterBoxes[moduleID].Where(msg => msgIDList.Contains(msg.m_MsgType.m_MsgTypeID) && (command.HasValue ? msg.m_MsgType.m_Command : !msg.m_MsgType.m_Command)).ToArray(); } }
public Object[] GetMessageObjects(Constant.enumModuleID moduleID, Constant.enumMessage[] msgIDArray) { IMessage[] result = m_LetterBoxes[moduleID].Where(msg => msgIDArray.Contains(msg.m_MsgType.m_MsgTypeID)).ToArray(); m_LetterBoxes[moduleID] = m_LetterBoxes[moduleID].Except(result).ToList(); return result.Select(msg => msg.m_Data).ToArray(); }
private void ProcessCommands(Constant.enumMessage[] commands) { foreach (Constant.enumMessage c in commands) { m_PostOffice.LockMessageType(c); m_PostOffice.RemoveMessage(c, m_ModuleID); switch (c) { case Constant.enumMessage.INITIALISE: Init(); break; case Constant.enumMessage.UPDATE: Update(); break; default: Console.WriteLine("AI Module: Unhandled Post Office Message: " + c.ToString()); break; } m_PostOffice.UnLockMessageType(c); } }
public Message(Constant.enumMessage msgTypeID, Boolean command = false, Object[] data = null) { m_MsgType = MessageType.Instance(msgTypeID, command); m_Data = data; }
protected ComponentType(Constant.enumComponent iD) { m_ComponentTypeID = iD; }
protected MessageType(Constant.enumMessage msgTypeID, Boolean command) { m_MsgTypeID = msgTypeID; m_Command = command; }
private void ProcessCommands(Constant.enumMessage[] commands) { foreach (Constant.enumMessage c in commands) { m_PostOffice.LockMessageType(c); m_PostOffice.RemoveMessage(c, m_ModuleID); switch (c) { case Constant.enumMessage.INITIALISE: Init(); break; case Constant.enumMessage.UPDATE: Update(); break; case Constant.enumMessage.GET_INPUT_EVENT_HANDLERS: SendInputEventHandlers(); break; case Constant.enumMessage.GET_MOUSE_POSITION: SendMousePosition(); break; case Constant.enumMessage.GET_PRESSED_MOUSEBUTTONS: SendPressedMouseButtons(); break; case Constant.enumMessage.GET_MOUSE_WHEEL_DELTA: SendMouseWheelDelta(); break; case Constant.enumMessage.GET_PRESSED_KEYS: SendKeysPressed(); break; default: PrintError("Unhandled PostOffice Message - " + c.ToString()); break; } m_PostOffice.UnLockMessageType(c); } }
public void UnLockMessageType(Constant.enumMessage msgTypeID) { if (m_MsgLockables.Contains(msgTypeID)) m_LockList.Remove(msgTypeID); }
//TODO find a way to pass a data object containing different data types in one object[] so they can be picked up by helper method currently have to create multiple msgs and send them using //SendMessages(IMessage[] msgArray) /* public void SendMessage(Constant.enumMessage msgTypeID, Boolean command = true, Object[] data =null, Boolean split = false) { List<Object> typeList = new List<Object>(); if (data != null) { if (split) { foreach (Object obj in data) { if (!typeList.Any(o => o.GetType() == obj.GetType())) { Object[] objArray = data.Where(o => o.GetType() == obj.GetType()).ToArray(); foreach (Object o in objArray) { IMessage msgSplit = new Message(msgTypeID, false,o); m_POBox.Add(msgSplit); } typeList.Add(obj); } } } else { IMessage msg = new Message(msgTypeID, false, data); m_POBox.Add(msg); } } if (command) { IMessage msg2 = new Message(msgTypeID, true, null); m_POBox.Add(msg2); } if (data == null && !command) { throw new ApplicationException(); } m_Observer.Notify(true); m_POBox.Clear(); if (command) m_Observer.Notify(false); } */ //TODO make this generic so data is stored as an array of T and is passed, it is possible to force the game developer to define all data as an array before being passed so uses the //sendmessage(Constant.enumMessage msgTypeID, Boolean command = true, Object[] data = null) which bypasses all issues but i believe to be unclean /// <summary> /// NOTICE: this doesnt work correctly needs Type of data to be passed or will be converted to object[] meaning GetObjectArrayOf can not find by datas actual type /// </summary> /* public void SendMessage(Constant.enumMessage msgTypeID, Boolean command, Object data) { if (command) { IMessage msg2 = new Message(msgTypeID, true, null); m_POBox.Add(msg2); } if (data != null) { IMessage msg = new Message(msgTypeID, false, data); m_POBox.Add(msg); } if (data == null && !command) { throw new ApplicationException(); } m_Observer.Notify(true); m_POBox.Clear(); if (command) m_Observer.Notify(false); } */ public void CheckMessages(Constant.enumModuleID moduleID, Constant.enumMessage[] msgIDList) { m_LetterBoxes[moduleID].AddRange(m_POBox.Where(x => msgIDList.Contains(x.m_MsgType.m_MsgTypeID)).ToArray()); }
private void ProcessCommands(Constant.enumMessage[] commands) { foreach (Constant.enumMessage c in commands) { m_PostOffice.LockMessageType(c); m_PostOffice.RemoveMessage(c, m_ModuleID); switch (c) { case Constant.enumMessage.INITIALISE: Init(); break; case Constant.enumMessage.UPDATE: Update(); break; case Constant.enumMessage.DRAW: Render(); break; case Constant.enumMessage.GET_GRAPHICS_SETTINGS: SendGraphicsSettings(); break; case Constant.enumMessage.UPDATE_GRAPHICS_SETTINGS: IGraphicsSettings[] sentSettings = Methods.GetObjectArrayOf<IGraphicsSettings>(m_PostOffice.GetMessageObjects(m_ModuleID, c)); if (sentSettings.Length != 0) { UpdateGraphicsSettings(sentSettings[0]); } break; case Constant.enumMessage.LOAD_TEXTURES: AddTextures(); break; case Constant.enumMessage.SEND_MOUSE_WHEEL_EVENT_HANDLER: m_MouseWheelEventHandler = Methods.GetObjectArrayOf<EventHandler<MouseWheelEventArgs>>(m_PostOffice.GetMessageObjects(m_ModuleID, c)).FirstOrDefault(); break; case Constant.enumMessage.SEND_MOUSE_BUTTON_EVENT_HANDLER: m_MouseButtonEventHandler = Methods.GetObjectArrayOf<EventHandler<MouseButtonEventArgs>>(m_PostOffice.GetMessageObjects(m_ModuleID, c)).FirstOrDefault(); break; case Constant.enumMessage.SEND_MOUSE_MOVE_EVENT_HANDLER: m_MouseMoveEventHandler = Methods.GetObjectArrayOf<EventHandler<MouseMoveEventArgs>>(m_PostOffice.GetMessageObjects(m_ModuleID, c)).FirstOrDefault(); break; case Constant.enumMessage.SEND_KEYBOARD_EVENT_HANDLER: m_KeyEventHandler = Methods.GetObjectArrayOf<EventHandler<SFML.Window.KeyEventArgs>>(m_PostOffice.GetMessageObjects(m_ModuleID, c)).FirstOrDefault(); break; case Constant.enumMessage.SWITCH_SPRITES_DRAW_STATUS: SwitchSpritesDrawState(Methods.GetObjectArrayOf<string>(m_PostOffice.GetMessageObjects(m_ModuleID, c))); break; case Constant.enumMessage.CLOSING: DisposeRenderWindow(); break; default: PrintError(("Unhandled PostOffice Message - " + c.ToString()), m_ErrorStatus.DEBUG); break; } m_PostOffice.UnLockMessageType(c); } }
private void ProcessCommands(Constant.enumMessage[] commands) { foreach (Constant.enumMessage c in commands) { m_PostOffice.LockMessageType(c); m_PostOffice.RemoveMessage(c,m_ModuleID); switch (c) { case (Constant.enumMessage.UPDATE): Update(); break; case (Constant.enumMessage.COLLISIONDETECTION): CollisionDetection(); break; default: break; } m_PostOffice.UnLockMessageType(c); } }