Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
16 views46 pages

GP Unit 3

The document discusses application layers for game programming. It covers the basic features of application layers including console and window applications. It then discusses the game application layer and covers key aspects like input devices, files/RAM, and the game lifetime including the main loop, initialization and shutdown. It also covers fundamental concepts of game development.

Uploaded by

sgovindu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views46 pages

GP Unit 3

The document discusses application layers for game programming. It covers the basic features of application layers including console and window applications. It then discusses the game application layer and covers key aspects like input devices, files/RAM, and the game lifetime including the main loop, initialization and shutdown. It also covers fundamental concepts of game development.

Uploaded by

sgovindu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 46

UNIT 3

GAME PROGRAMMING
APPLICATION LAYER

• A software program needs an application framework in which to run.


• For a graphics application, we minimally need to create a window and a renderer to draw to it.
• Game applications as well as some other applications will need input from devices attached to the system.
These devices can include a keyboard, a mouse, a gamepad, and/or a joystick.
• An application must be prepared to handle events generated by these devices.
• The application can use 2D sound capabilities to play music and special sound effects, but it also might use
3D sound capabilities, taking advantage of 3D sound hardware
BASIC FEATURES OF APPLICATION LAYER

• A console application layer for those applications requiring neither a window nor a renderer
For example, the ScenePrinter tool is an application on the CD-ROM that traverses a scene graph and creates an
ASCII file of information about it.

• A window application layer that supports both 2D and 3D applications.

• An application library that supports both console and windowed applications, so you need only link in one
library for any application, regardless of its type.
GAME APPLICATION LAYER:
1. Devices (Input, Files, RAM, Time )
2. Operating System (Language, DLL, Threads, Network )
3. Game Lifetime (Core Lib, Main Loop, Init & Shutdown )

Input Devices:-
Abstraction of input to actions:
• device driver input -> game actions
• send game actions to game logic subsystem

Files/RAM:-
• loading/saving game state
• assets loading
• resource caching
• memory management
• Virtual memory use
Game Lifetime:
 Main Loop-
• Queuing input
• Tick game logic
• Keep simulation time
• Events/Triggers

 Init & Shutdown-


i. Init: ii. Shutdown:
• Initialize game logic • Memory de-allocation
• Initialize game views • Close files, network, etc.

• Reset simulation time


• Handshake network, input devices
Game logic refers to the internal mechanism of a game in order to perform all the tasks needed for
it to work.
It is programming logic applied to games, like collision detection, AI, animation, and so on.

What are Data Structures?


• Common to Game Design
• Arrays
• Linked Lists
• Hash Tables
• Trees, B-Trees
• Graphs
• Stacks and Queues
FUNDAMENTAL CONCEPTS OF GAME DEVELOPMENT
1. Main Loop:-
i. Initialisation
ii. Process Player Input
iii. Perform game logic
iv. Render Scene, Graphics, SFX etc
v. Shutdown

2. Game UI & States:-


vi. The Human Game View
vii. Player Movement Controller
viii. Screen Elements
ix. Game Controls
v. Game Events & Events Data
vi. Event Listener & Manager

3. Loading and Caching Game data:-


i. Game Resources formats and storage
ii. 3D Environment Mesh
iii. 2D Sprites and Texture data
iv. Sound, Music & Animation data
v. Effects Cinematics Shader, Shadows

4. Programming Input Devices:-


vi. Working on life Controller
vii. Touch Devices Controller
viii. Two Axis Controls
ix. Get State & Normalising Input
MEMORY MANAGEMENT:

• The issues in building a memory management system are the same as those for building other software
components. You have a number of goals to achieve and not all of them are possible simultaneously.

• The three main issues to deal with are memory utilization, speed of allocation/ deallocation, and memory
reclamation.

• A memory management system with good memory utilization will waste as little space as possible in the full
amount of memory it must manage.

• If the current memory has lots of small chunks of unused memory, finding a chunk to accommodate an allocation
request is costly, so the allocation is slow.
• On the other hand, if the memory manager does not have to search every available chunk of unused memory to find a
free block to satisfy an allocation request, the allocation is quite fast.

• Thus, memory utilization and speed of allocation are at direct odds with each other. Regardless of which factor you
decide on, it is possible that enough free memory exists to satisfy an allocation request, but the problem is that the
required amount is not contiguous.

• There are few methods for responding to the allocation request, but the most easiest and undesirable way is to simply
fail and return a null pointer.

• Another possibility is to borrow memory from the global heap, but this defeats the requirement of having a memory
budget.
Yet another possibility, one that is desirable but comes with some cost, is to reorganize the free memory and package it
into a contiguous block, after which the allocation request is granted.
This reorganization is referred to as memory compaction, or garbage collection.

ALLOCATION USING SEQUENTIAL-FIT METHODS

• The full memory block is a contiguous collection of bytes.


• Sub-blocks of contiguous bytes are either free for allocation or used because they were already allocated
and are currently in use by the application.
• The free blocks are maintained as a doubly linked list. Hypothetical block structures are listed next. The
status flag, Used, is listed as a Boolean in order to keep the pseudocode simple.
class HeaderBlock {
public:
bool Used;
unsigned int Size;
Block* Prev;
Block* Next;
};
class FooterBlock {
public:
bool Used;
unsigned int Size;
};
Allocation Using Buddy-System Methods

• A different approach to memory allocation is the buddy system. The goal is to improve on sequential-fit
methods by having faster allocation, hopefully not leading to a significant reduction in memory utilization.

• The full memory pool has 2^m storage locations for some user-specified m. The memory blocks used to
satisfy allocation requests are required to have sizes that are powers of 2.

• The maximum block size is, of course, 2m.


The minimum block size must be large enough to store any header and footer information as well as what
the user has requested for the allocation.
• Memory allocation is described by the following pseudocode. It assumes that the
MemoryManager class has defined a set of free lists for the various block sizes. The data member
of MemoryManager that stores the power m of 2m, the size of the full memory, is m_maxPower.

char* MemoryManager::Allocate (unsigned int requestedSize)


{
// Compute the smallest integer k for which the requested
// size n satisfies n <= pow(2,k) and there is a free list
// with blocks of size pow(2,k).
unsigned int kmin = ceiling(Log2(requestedSize));
unsigned int k = kmin;
List freeList = empty_list;
for (/**/; k <= m_maxPower; k++) {
freeList = m_freeList[k];
if (freeList is not empty)
{
break;
}
}
if (freeList is empty or k > m_maxPower) {
// The request cannot be satisfied. What to do?
return NULL;
}
}
Allocation Using Segregated-Storage
Methods
• The sequential-fit methods and the buddy methods both use a contiguous block of
memory to manage. The blocks can be of arbitrary (and nonuniform) sizes.
• The mixing of block sizes is problematic in affecting the performance of the memory
manager, but mixed block sizes are essential in a general-purpose system.
• Segregated storage methods are a compromise in hopes of obtaining better
performance.
• A contiguous block of memory is used by the memory manager, but this block is partitioned into smaller

chunks. Each chunk has its own mechanism for storage, allocation, and deallocation.

• In a general-purpose system, each chunk might represent a collection of uniform-sized blocks, which are

easier to manage regarding allocation and deallocation.

• Systems like these are used in memory paging systems for standard operating systems. They have also been

studied extensively in the field of database management.

• The systems have partitioned storage, but then require some type of indexed structure on top of the partitions

to allow fast access to them.


• The material in the preceding sections on memory management is intended to get you to think about

memory budgets and the fact that building your own memory management system for a game

component (graphics engine, physics engine, etc.) is a reasonable thing to do when you need really tight

control over the resources on a game console


Memory Compaction
• A memory management system must deal with the improbable, but possible, failure to grant an

allocation request.

• In a language such as Java, the memory management system automatically handles this problem.

Moreover, the programmer do not have to explicitly allocate or deallocate memory. The objects in Java

are reference counted.

• Whenever you are finished referencing an object and either explicitly or implicitly release your hold on

that object, if the object’s reference count becomes zero, Java will make the associated memory available

for later use.


This might not happen the moment you release your hold on the object, but the language does allow
you to tell the system to do garbage collection.

• Reclaiming small memory blocks in order to satisfy an allocation request is called memory
compaction. The topics of memory compaction and garbage collection are quite large.

• The key algorithms to look into are mark-and-sweep methods for automatic reclamation,
incremental garbage collection in order to amortize the cost of reclamation rather than forcing the
application to wait for a long period of time when reclamation is initiated, and copying and
moving of cyclic, doubly linked lists in bounded memory.
• In the context of a game application on a console with limited memory, the goal is to avoid having a

subsystem run out of the memory budgeted to it.

• The preferred method/way is to trap the failure to satisfy an allocation request, and then determine if the

problem is that the budget was really not large enough or if the problem really is memory fragmentation.

The latter case is not what you want in the game application, so it is better to spend your time on rethinking

the budget rather than on implementing a sophisticated memory compaction and garbage collection scheme.
Real-Time Loops
All real-time interactive applications consist of 3 tasks running concurrently.

Game Loop:-
In a game, both the world simulation and the user input can be considered tasks
belonging to the same global behavior, which is “updating” the world.

Updating Rendering

long lastTime = GetTime(); while (! end)


{
if ((GetTime()- lastTime) > 1000/frequency)
{
game_logic();
lastTime = GetTime();
}
presentation();
}
1. Updating
We can divide it into 2 main blocks:
i. updating the player
We need an updated snapshot of the player state in each frame.
Getting the input from the player  Restricting Player Interactions  Player Update
(abstract device controllers) (Geometric & Logical restrictions)
• Restricting Player Interactions is usually the hardest step.
ii. updating the world
Passive Entities:
• These items play a key role in the player restriction section, but are not very important for the sake
of world updating.
• In games with large worlds, we can pre-select a subset of passive entities so that player restriction
portion can only focus on those entities.
• But the majority of time in the world update section is spent checking the other type of entities.

Active Entities:
i.) Logical Entities:- ii.) AI Entities:-

 Sort According to Relevance  Sort According to Relevance

 Update State  Sense Internal State and Goals


 Sense Restrictions
 Decision Engine
 Update State
2. Rendering
Usually any world-rendering pipeline will consist of 2 parts:
i. Selecting the Relevant Subset
We only want to draw parts of the game world that are visible from the player’s viewpoint.
Sometimes level of detail (LOD) technique is used too.
ii. Actual Rendering

Game Loop in Networked games:


• The player update section must change to make sure every player update is followed by a
broadcast message that sends the newly computed position to other gamers through the
network.
• Al section needs a special-case Al module that receives data from the communications
channel and reflects it to the local gaming environment.
PROGRAMMING PROCESS-
• Programming must be planned to ensure timely and complete delivery.
• Any modern game requires hundreds or thousands of source files and several hundred thousand lines of code.
• Game programming is a very complex task.

DEVELOPMENT STAGES:-
1. Preproduction
2. Production
3. Maintenance

4. Pre-Production
• The concept of the game is agreed upon.
• Different technologies and solutions are evaluated.
• Gameplay formulae are tested.
• Some early concept art is created.
• The result is a working prototype of the game.
• The game design should be final.
• It's the only phase where a game company should be allowed to experiment.
• The role of preproduction is, then, to analyze alternatives andfinally create a detailed plan.
• Technology prototypes usually focus more on showcasing the key elements of the gameplay.
The presentation layer is kept in a very early and crude form.
Feature sets-
Lead programmer should at first define a list of features to be implemented into the game.
This list should be crafted as a team effort between the design and the coding team.
A good way of getting a reasonable feature set laid out on paper is to use an expansion-
contraction process.

Expansion-Contraction Process

Create an Exhaustive List Clustering Features

Choosing Best Features


Minimax Method

• A good, objective way to choose which clusters to implement is to use the classic minimax method.
• Minimax tries to minimize disadvantages and maximize advantages.

• This is usually depicted in a 2D matrix of cost versus benefit.


2. Production

• After completing pre-production and securing funding for the game, production begins.

• It's the longest part of the process and usually takes between one and three years to complete.

• Production is often divided into milestones.

• The game takes shape following the planning that has been laid out during preproduction.

• The technology prototype built during preproduction will also mutate to implement all the final features

the game needs.

• In the case of console games, this process is a bit more complex than for a PC title.
• Production is usually where all the eye candy is put in place, and games show their full technological

complexity.

• Art assets are created in a factory-like fashion, game levels are crafted, and so on.

• At the end of this iterative process, a final version of the game must be developed.

• This process ensures that the game is virtually bug-free and also reaches the desired quality standard.
3. Maintenance

• Games usually have a relatively short shelf life.


• Support must be provided: patches, editing tools for the fan community, and additional
missions.
• Maintenance is the moment when relationships with consumers are at their highest point.
• Games with good maintenance have longer shelf lives.
• The maintenance phase is a great time to organize, archive, and document.
• Developers forget good coding practices during lengthy crunch times.
• Some maintenance time should go into revising your code, and storing and documenting the
reusable modules.
• There's no deadline pressure on the maintenance phase.
USER INTERFACE MANAGEMENT
A user interface in games purpose is to allow a user to carry out a task within a game world
either through direct input or through an action on a Heads Up Display (HUD).
The user interface is the section of a program that allows for human-computer interactions
(HCI).

• User Interfaces must be designed with care and understanding for human psychology and
physiology, this is because the colour, shape, and way a program is used dictates how well a
UI is crafted.
• The colour choice in UI design should be based on colour psychology theory to give the user
a certain feeling while interacting with each area of the UI, the shape of a UI is equally as
important in crafting certain feelings in a user.
• UI should not require the user to have to learn many if any, new skills to gain access to it and be built with the idea
of what knowledge a user already has in mind.
• Many variations of UI allow for as much user choice as possible either through buttons, menus, sliders, and other
optional widgets or through the creation of UIs which allow for manual changes by the user, and toggle options can
be used here also.
• UIs purpose should always be made with the idea of enhancing the user experience and simplifying tasks.

Use of shape and colour in UI


• The use of shape and colour in a UI is crafted purposely by the designer to make the player feel a certain way.
• Successful UI designs use colour as a way of manipulating a users emotions to give them a very specific
experience
• The choice of colour is based around the psychological understanding of colour theory where colours relate to
certain emotions in humans.
Personalisation and choice through the UIs inputs

• Personalisation allows for users to feel much more comfortable with their UI as adjustments can be made by a user
to make the UI work much better on their device or more suited for their needs.
• It also give users a positive feeling if they think they have a lot of control.
• When UI is designed with personalisation, in mind it allows for developers to create much simpler designs with
more add on features, so that the user can add and take away from the design as they wish.
• It also means that the design can be made more easily adaptive and the designer will not need to make drastic
changes to fit different screen sizes and device types as it will all be handled by a user.
• UI designs can either be intelligently adaptive designs, meaning users have much more control over how the UI will
look and behave and allows for more personalisation, it also means that the UI will auto adapt to different screen
sizes and machine types itself meaning designers only have to create a broad outline for how it must look.
• Tailor-made interfaces are another design type, these allow for designers to place objects in very specific
locations on a screen or HUD.
• However this type of design means the designer must have a great understanding of who their users
are, and what the display settings will be for the final product.
• This design type also means that if it is to be used on multiple different display types it must be re-
created multiple times over and fixed to fit with each design type.
• Personalisation through input methods and design allow developers to create something which a user
has significantly more control over and designs can be made to suit multiple devices in a much simpler
manner.
UI usability and functionality

• The purpose of UI is to allow a user to complete a task and it should be a priority of a UI designer to create a UI

with usability and functionality in mind to make each task easier for a user.

• A user’s perception of a UI is directly linked to how functional it is, it should be easy for users to find information

and the UI should not have a steep learning curve.

• It should allow new users to pick up on what is being made available to them through the use of the design and

use as much common knowledge as a basis for how users will interpret features.
• A developer can make a UI design more functional by adding elements of personalisation and using proper

layouts, mixed with colour and shaped designs to make the UI feel better for users to interact with.

• A player’s perception of the information available to them is mostly influenced by the usefulness and design

characteristics of the user interface.

• UIs tools and functions are directly linked to a user’s perception of what information is available to them and how

they are to access or assess said information.


THANK YOU

You might also like