CSE 381 – Advanced Game Programming User Interface & Game Events Management.

Slides:



Advertisements
Similar presentations
Chapter 18 Building the user interface. This chapter discusses n Javas graphical user interface. n Swing: an enhancement of a library called the Abstract.
Advertisements

F27SB2 Software Development 2 Lecture 1: Introduction.
Windows Basics An Introduction to the Windows Operating System.
Cosc 5/4730 Input Keyboard, touch, and Accelerometer.
1 Computer Graphics Chapter 2 Input Devices. RM[2]-2 Input Devices Logical Input Devices  Categorized based on functional characteristics.  Each device.
Developing User Interfaces with Event-driven Programming
3.3. G AME I NPUT Handling input within games. In lecture exploration of answers to frequently asked student questions.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Graphical User Interface (GUI) Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
CS320n –Visual Programming Interactive Programs Mike Scott (Slides 5-1)
Object-Oriented Analysis and Design
SE320: Introduction to Computer Games Week 8: Game Programming Gazihan Alankus.
CSE 331 Software Design & Implementation Dan Grossman Spring 2015 GUI Event-Driven Programming (Based on slides by Mike Ernst, Dan Grossman, David Notkin,
 At the end of this class, students are able to  Describe definition of input devices clearly  List out the examples of input devices  Describe.
BTEc unit 12 software development
Event-driven programming. Most modern computer programs that people use have Graphical User Interfaces (GUIs). A GUI has icons on the computer screen.
Chapter Introduction to Computers and Programming 1.
CSE 381 – Advanced Game Programming 3D Game Architecture.
CS 0004 –Lecture 1 Wednesday, Jan 5 th, 2011 Roxana Gheorghiu.
Model View Controller (MVC) Rick Mercer with a wide variety of others 1.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming 1.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
MVC CompSci 230 S Software Construction. MVC Architecture  A typical application includes software to  maintain application data,  document text.
Overview of Previous Lesson(s) Over View  Visual C++ provides us with 3 basic ways of creating an interactive Windows application  Using the Windows.
Design Document Presentation. Review Quoridor – a board game played on a grid where players must advance tokens across a board to win. Our basic objective:
Developing the Game User Interface (UI) Lesson 5.
1Computer Graphics Input and Interaction Lecture 8 John Shearer Culture Lab – space 2
CHAPTER 5 Input Control © 2008 Cengage Learning EMEA.
Python Programming Graphical User Interfaces Saad Bani Mohammad Department of Computer Science Al al-Bayt University 1 st 2011/2012.
Computing Science 1P Lecture 17: Friday 23 rd February Simon Gay Department of Computing Science University of Glasgow 2006/07.
COMP 321 Week 2. Outline Event-Driven Programming Events, Event Sources, Event Listeners Button and Timer Events Mouse Events, Adapters.
An Introduction to Programming and Object Oriented Design using Java 3 rd Edition. Dec 2007 Jaime Niño Frederick Hosch Chapter 18 Integrating user interface.
“The perfect project plan is possible if one first documents a list of all the unknowns.” Bill Langley.
X-WindowsP.K.K.Thambi The X Window System Module 5.
Observer design pattern A closer look at INotifyPropertyChanged, INotifyPropertyChanging and ObservableCollection Observer design pattern1.
Chapter2: Drawing a Window. Review: Introducing MFC.
Object Oriented Programming.  Interface  Event Handling.
CSE 331 Software Design & Implementation Hal Perkins Autumn 2012 Event-Driven Programming 1.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 27 JavaBeans and.
11 General Game Programming Approach. The program is event-driven The program is event-driven –Messages = events –So as all windows system (for example.
Game Programming Patterns Game Loop From the book by Robert Nystrom
COSC 4126 User Interaction User Interaction capturing and responding to input events.
Programming Input Devices. Getting the device state Schemes for processing input – Polling – Callbacks Ways to intercept messages from input devices –
SCRIPT PROGRAMMING WITH FLASH Introductory Level 1.
Interactive Programming Alice. Control of flow Control of flow -- how the sequence of actions in a program is controlled. What action happens first, what.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 32 JavaBeans and Bean.
Implement User Input Windows Development Fundamentals LESSON 2.4A.
Chapter 1: Introduction to Computers and Programming.
12-Jun-16 Event loops. 2 Programming in prehistoric times Earliest programs were all “batch” processing There was no interaction with the user Input Output.
Hand Gestures Based Applications
CS 134 Alternate Inputs.
CHAPTER 5 Input Control © 2008 Cengage Learning EMEA.
Introduction to Event-Driven Programming
Event-driven programming
Event loops 16-Jun-18.
Milestone 2 Overview.
Lesson 1: Buttons and Events – 12/18
Introduction to Events
Programming in Java Event Handling
Event Driven Programming
Introduction to Computing Using Java
Event loops.
Event loops 17-Jan-19.
Event loops 17-Jan-19.
Week 6: Time and triggers!
Event loops 8-Apr-19.
Event loops.
Event loops 19-Aug-19.
Presentation transcript:

CSE 381 – Advanced Game Programming User Interface & Game Events Management

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

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) …

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

Microsoft Spy++

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”

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

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

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() { }; };

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.

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

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

DXUT Controls CDXUTButton CDXUTStatic CDXUTCheckBox CDXUTRadioButton CDXUTComboBox CDXUTSlider CDXUTEditBox CDXUTIMEEditBox CDXUTListBox CDXUTScrollBar

General Game Event System What’s the purpose? minimize communications between subsystems reduce subsystem interdependency Many-to-Many mappings present problems refactoring alone

Game Event System Has 3 basic parts: Events & event data Event handler delegates Event manager

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

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 …

Event Listener Delegates What are delegates? function pointer + object pointer used as callback we can use fast delegates 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

And finally, the Event Manager Matches events with listeners IEventManager a global singleton VAddListener VRemoveListener VTriggerEvent VQueueEvent VAbortEvent VUpdate Implemented by EventManager