Transcript Slide 1

Matakuliah : T0944-Game Design and Programming
Tahun
: 2010
Introduction to Game Programming
Pertemuan 11
The Component of Game Programming
Game Loop
Shutdown
Initialization
Synchronize
Display
Retrieve
Player Input
Perform AI
and
Game Logic
Render
Next
Frame
The Component of Game Programming
•
Initialization
–
•
Enter Game Loop
–
•
This section draws the image on an off-screen buffer area, and then copied very quickly to the visible
display.
Synchronize Display
–
•
This section contains the majority of the game code.
Render Next Frame
–
•
Retrieve player input from keyboard, mouse or joystick.
Perform AI and Game Logic
–
•
This is where the action begins and continues until user exits the main loop.
Retrieve Player Input
–
•
Memory allocations, resource acquisition, loading data from disk, etc.
Manage the frame rate. Usually 30 fps is considered to be optimal.
Shutdown
–
Indicates the end of the game. This section perform cleanup and exit to operating systems.
Windows Programming Model
•
Multitasking
– Windows allows a number of
different applications to be
executed simultaneously an a
round robin fashion, where each
application gets a small time slice
to run in and then the next
application takes its turn.
Game
Program
Print
Spoiler
CPU
Word
Processor
Paint
Program
Windows Programming Model
• Multithreading
– Programs are really
composed of a number of
simpler threads of execution.
– These threads are scheduled
just like heavier-weight
processes, such as programs.
Process 0
Thread 0
Thread 1
Thread 2
CPU
Thread 0
Thread 1
Process 1
Thread 0
…
Thread 1
Process n
Thread 2
Windows Programming Model
•
Event-Driven Model
System Event Queue
– Windows programs sit
and wait for the user
to do something,
which fires an event,
and the Windows
responds to the event
an takes action.
Message 1
Message 2
…
…
…
Message n
WinMain(){
…
}
WinProc()
WinMain(){
…
}
Local
Even
Queue
Local
Even
Queue
WinProc()
API (Application Programming Interface)
•
•
Is a programmatically implemented interface provided in the form of a
library. This interface provide a certain number of services for use by an
application program.
Common APIs:
– Windows 32 API.
•
•
int MessageBox(HWND hwnd, LPCTSTR lptext, LPCTSTR lpcaption, UINT utype)
DWORD GetTickCount(void);
– Windows GDI
•
•
–
–
–
–
BOOL LineTo(HDC hdc, int xEnd, int yEnd)
BOOL Rectangular (HDC hdc , int nLeftRect , int nTopRect , int nRightRect , int
nBottomRect)
OpenGL graphic API
Microsoft DirectX API
Sun Microsystem’s Java Platform
Xbox 360’s XInput API
Introduction to DirectX
Windows
Device
Driver
Interface
Direct Show
GDI
Direct Sound
Direct Sound 3D
Direct Music
Windows Win32 Application
Direct Input
Direct Play
Direct Setup
•
Basically a system
of software that
abstracts video,
audio, input,
networking,
installation, and
more.
DirectX technology
is many times faster
and more robust
that GDI and/or
MCI (Media Control
Interface)
Direct Draw
Direct 3D
•
Hardware Emulation Layer
Hardware Abstraction Layer
Hardware: Audio, Video, Input, Storage
Introduction to OpenGL
• Is a procedural-based 3D graphics API explicitly designed by Silicon
Graphic for the standardized development of 3D and 2D graphical
applications.
• OpenGL is also designed for the creation and execution of graphical
applications over networked computing enviroment.
• Example:
–
glColor(), glVertex(), glBegin()
Game Programming Topics
•
Algorithm, Data Structure, Memory Management
– Arrays, Linked List, Recursion, Tree, Multiple Player Management
•
Artificial Intelligence
– Deterministic Algorithm, Patterns and Scripts, Behavioral state system, Memory
and Learning, Path-finding, Neural Network, Genetic Algorithm, Fuzzy Logic.
•
Physic Modeling
– Fundamental laws of physics: Mass, Time, Position, Velocity, Acceleration,
Force, Momentum.
– Gravity, Friction, Collision response, Forward kinematics, Particle system.
Game Programming Resource
• Game Programming Website
– http://www.gamedev.net
– http://www.gamesdomain.com
– http://www.gdconf.com
• Game Development Magazine
– http://www.gdmag.com
– http://www.gamasutra.com