Download presentation
Presentation is loading. Please wait.
Published byJohn Norris Modified over 9 years ago
1
CSE 381 – Advanced Game Programming User Interface & Game Events Management
2
Reading Input Devices For the application layer Processed and handed to game view layer Game layer then generates response Translates it into a command Who will deal with input hardware? see GameCode4/interfaces.h IKeybaordHandler, IPointerHandler, IJoystickHandler, IGamepadHandler subclasses (control classes) convert input to commands to update the game state
3
Ex: Movement Controller Responds to mouse movement via player movement Class MovementController: public IPointerHandler, public IKeyboardHandler { Mat4x4 m_matFromWorld; Mat4x4 m_matToWorld; Mat4x4 m_matPosition; Cpoint m_lastMousePos; BYTE m_bKey[256]; float m_fTargetYaw; … bool VOnPointerMove(Cpoint &mousePos) void OnUpdate(DWORD delta) …
4
Again, a Command Based System We want a modular design AI bots generate commands Controllers generate commands Both affect control objects Control Objects don’t need to know who is sending them commands AI characters & Humans should be interchangeable
5
Microsoft Spy++
6
Mouse Dragging An important issue for us Why? RTS Unit Selection For handling mouse dragging: 1.Detect & initiate a drag event make sure it’s not on a double click make sure it’s beyond a drag threshold 2.Handle the mouse movement & drag objects accordingly 3.Detect the release and finalize the drag selection of units only if release point is legal involves “picking”
7
Picking Translate mouse click to object selection Screen is in 2D space Objects are in 3D space We’ll learn how after covering 3D graphics, & collision math
8
Other Input Control Issues to Consider Automated Target Selection Dead Zones Directional Input Normalization Dual Stick Input Ramping Character vs. Key Codes Keyboard mapping & Key Combination Confusion Polling vs. Message Pumps Alt key issues
9
So how are UIs managed? class IGameView { virtual HRESULT VOnRestore()=0; virtual void VOnRender(double fTime, float fElapsedTime)=0; virtual HRESULT VOnLostDevice()=0; virtual GameViewType VGetType()=0; virtual GameViewId VGetId() const=0; virtual void VOnAttach(GameViewId vid, ActorId aid)=0; virtual LRESULT CALLBACK VOnMsgProc( AppMsg msg )=0; virtual void VOnUpdate(unsigned long deltaMs)=0; virtual ~IGameView() { }; };
10
The Player’s Game View class HumanView : public IGameView { GameViewId m_ViewId; ActorId m_ActorId; ProcessManager* m_pProcessManager; DWORD m_currTick; DWORD m_lastDraw; bool m_runFullSpeed; BaseGameState m_BaseGameState; ScreenElementList m_ScreenElements; shared_ptr m_pScene; shared_ptr m_pCamera; bool LoadGame(TiXmlElement* pLevelData); // PLUS VOnRestore, VOnUpdate, VRenderText, // VOnLostDevice, VOnRender, VOnAttach, etc.
11
Basic UI elements class BaseUI : public IScreenElement { int m_PosX, m_PosY; int m_Width, m_Height; optional m_Result; boolm_bIsVisible; class StandardHUD : public BaseUI { CDXUTDialog m_HUD; class MessageBox : public BaseUI { CDXUTDialog m_UI; int m_ButtonId; Note: In the textbook, StandardHUD is called CScreenBox
12
So how do UI controls get interactions? Forwarded to all game views from GameCodeApp::MsgProc To where? VOnMsgProc And what does it do? Forwards it to all screen elements Note forward messages to screen elements in reverse order from rendering What does DXUT do for us? builds & renders our controls
13
DXUT Controls CDXUTButton CDXUTStatic CDXUTCheckBox CDXUTRadioButton CDXUTComboBox CDXUTSlider CDXUTEditBox CDXUTIMEEditBox CDXUTListBox CDXUTScrollBar
14
General Game Event System What’s the purpose? minimize communications between subsystems reduce subsystem interdependency Many-to-Many mappings present problems refactoring alone
15
Game Event System Has 3 basic parts: Events & event data Event handler delegates Event manager
16
Game Events When something important happens in your game: fire an event notify all appropriate subsystems of event subsystems process event in their own way Generated by authoritative systems Specify a GUID for each event type done in Visual Studio via Tools Create GUID specifies unique number that survives recompilation
17
What type of events do we have? See EventManager/Events.h EvtData_Destroy_Actor EvtData_Environment_Loaded EvtData_Move_Actor EvtData_New_Actor EvtData_Play_Sound EvtData_Request_New_Actor EvtData_Request_Start_Gamej …
18
Event Listener Delegates What are delegates? function pointer + object pointer used as callback we can use fast delegates http://www.codeproject.com/KB/cpp/FastDelegate.aspx All Event Listener delegates will conform to: typedef shared_ptr IEventDataPtr; void Delegate(IEventDataPtr pEventData); To make delegate & bind to object: MakeDelegate from 3rdParty/FastDelegate
19
And finally, the Event Manager Matches events with listeners IEventManager a global singleton VAddListener VRemoveListener VTriggerEvent VQueueEvent VAbortEvent VUpdate Implemented by EventManager
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.