没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
Use of design patterns for mobile
game development
Astahovs Ilja
Ilja Astahovs
Spring 2012
Thesis project, 15 credits
Supervisor: Johan Eliasson
Examiner: Pedher Johansson
Bachelor of Science in Computing Science, 180 credits
Abstract
Design patterns have been a valuable asset to software developers for a long time. All kind of
software, including games, benefit from re-using the well known solutions to the common
problems. Building a game from scratch requires a carefully made design and this is where
design patterns come handy. However, the approach to game development has changed lately.
The importance to learn the design patterns has been de-emphasized as frameworks and
complete game engines emerge. Many design approaches provided by them are used out the
box, often taken as some kind of standard.
The purpose of this paper is to show how some of the classical design patterns can be used in
game development and how some of the modern technologies adopt them. To research the
importance of design patterns in game development, a small mobile game project has been done.
As problems arose, a number of potentially useful design patterns were identified and analyzed.
Those design patterns were practically applied to the project and their potential use with other
related technologies was discussed. The paper emphasizes the important role of design patterns
in game development and gives some insights into how design patterns are implemented in some
of the modern middleware.
Use of design patterns for mobile game development - Ilja Astahovs, 2012
Contents
1 Introduction..............................................................................................1
1.1 Design patterns: historical review........................................................................1
1.2 Design patterns nowadays: do we need them?......................................................1
1.3 Design patterns and game development...............................................................1
1.4 A game implementation without using any of design patterns..................................2
1.5 Project's goals and limitations.............................................................................4
2 Design Pattern: Model-View-Controller.....................................................5
2.1 Case Study: Building a game upon Cocos2d game engine.......................................6
3 Design Pattern: State (State Machine)......................................................7
3.1 Case study: Using State Machine pattern together with Cocos2d..............................7
3.2 In Unity3d.......................................................................................................8
4 Design Pattern: Singleton.........................................................................9
4.1 Singleton in the example project.......................................................................10
4.2 Alternatives to Singleton pattern.......................................................................10
4.3 In Objective C / Cocoa.....................................................................................12
4.4 In Cocos2d.....................................................................................................12
4.5 In Unity3d......................................................................................................12
5 Design Pattern: Observer........................................................................13
5.1 Notification and delegation in Cocoa...................................................................13
5.2 Event dispatching in Cocos2d............................................................................14
5.3 Key-Value Observing in Cocoa...........................................................................14
5.4 Case Study: View/Model synchronization for Car selection.....................................14
5.5 Case Study: View/Model synchronization for NPC status changes...........................17
5.6 Case Study: Building an Event System...............................................................18
5.7 State change notification in Unity3d...................................................................19
6 Conclusions.............................................................................................20
References................................................................................................22
Appendix A: Valet Parking 1989 for the iPhone.........................................24
A.1 Project description.........................................................................................24
A.2 The gameplay................................................................................................24
Appendix B................................................................................................29
B.1 Cocos2d's CCDirector......................................................................................29
B.2 Cocoa's NSNotificationCenter...........................................................................29
Use of design patterns for mobile game development - Ilja Astahovs, 2012
1
1 Introduction
1.1 Design patterns: historical review
The notion of a design pattern (DP) as a well documented approach to solving some common
problem occurring in software development was first popularized by a book “Design Patterns:
Elements of Reusable Object-Oriented Software” by a group of authors
1
also known as “Gang of
Four”. Originally, the patterns were grouped into three categories: structural, creational and
behavioral [GoF]. Other classifications include architectural patterns and concurrency patterns
[18].
Evolution of programming languages and introduction of different design patterns is all about
controlling complexity of software systems. The emerging use of DPs was the next logical step
after invention of object-oriented programming (OOP) [Flynt], which emphasized component-
centered development inside a framework. Applying DPs for solving recurring problems
improves the object-oriented approach and makes it possible to deal with ever-growing
complexity of applications. Understanding the problems solved by certain DPs helps to describe
the purpose of different software components [Flynt, Core]. Instruments such as software
development kits (SDKs) and frameworks used in software development evolve, and it
encourages the programmer to reuse not only some basic components (e.g., reuse of components
belonging to STL, Standard Template Library, in C++) but also complete modules (e.g., parts of
game engines: game state managers, event systems etc.).
1.2 Design patterns nowadays: do we need them?
Even though the design pattern themselves were a product of refactoring [Flynt], one can argue
how well design pattern-driven development fits into iterative and incremental design, which is
what modern game-development process tends to be nowadays. In the modern era of agile
software development, initial ideas quickly turn into prototypes, which in turn can rapidly
transform into actual code blocks. Growing competition inside the industry, tough budgets and
deadlines simply does not leave any resources available for perfectly thought-out design.
Moreover, even though the OOP strove for re-usability (especially on framework-level, where
most of the code in the final products is the code which belongs to the framework components)
[Flynt], the re-usability of the custom code is significantly lower. Writing a re-usable code can
cost three times more than writing a single-use code [19, 20], and integrating design patterns
into the development process requires a lot of effort [Schmidt], so why would one bother paying
extra attention producing a “nicer” design?
DPs can also be grouped into universal patterns and situational patterns. The former, as the
name suggests, does not depend on language or technology, and often describe project's overall
structure, meaning that one can apply it to any project, only with minor changes. Because the
purpose of this thesis is to give a more general insight into what is the role played by the design
patterns in the modern game development and the choice of the technology is a much minor
issue, this thesis will focus on the universal patterns.
1.3 Design patterns and game development
Using the DPs has proved to be useful for the design of general application software, especially
web applications where many of DPs fit naturally into client-server model. But what about game
applications, is there something specific about them? The specifics of game applications
(similarly to other simulation software) are as follows: even small games require dozens of well
organized classes, thus code modularization is required. Compared to web and business
applications, games are more dynamic. The gameworld is subject to constant changes, which
requires fast communication between game objects, as well as keeping visual representation
1
Eric Gamma, Richard Helm, Ralph Johnson and John Vlissides
2
Use of design patterns for mobile game development - Ilja Astahovs, 2012
updated. Games allow intense interaction between player and the gameworld. Games are also
more resource-consuming, so one needs to find a good compromise between code complexity
(size, inheritance levels etc) and performance. In contrast to web applications, the gameworld
simulation (data) and it's representation can be perceived as being more coupled together, as
compared to business applications [2]. Finally, game development involves constantly chasing
ever-changing SDKs, but does it necessary mean using new techniques to solve the old
problems? This thesis will try to show the role of DPs in game development in general and
whether the DPs in question are outdated or not.
Libraries and frameworks
Decisions on how to apply DPs when designing a game application depend on underlying
technology. Few games are written from scratch today. Most games are developed by using
existing 3rd-party libraries or frameworks
2
, for example, a study from 2009 [DeLoura] shows
that 55% of games which were in production at that time were utilizing a game engine. The study
also shows the rising popularity of game engines and middleware. While adding libraries to the
project usually does not affect the current design of the application, building a game upon an
existing framework will directly affect the future design. Being partially-constructed
applications, frameworks may adopt one or few DPs. Those design decisions propagate into
user-written code. [Gregory]
1.4 A game implementation without using any of design patterns
What would an implementation of a typical game application look like if none of the DP were
used? While sticking to object-oriented approach, let us forget about any further modularization
(as in MVC which is one of the DPs discussed in this thesis) for the moment. Listing 1.1. shows a
naïve way to put together basic game functionality: user interaction, update, simulation and
rendering of the game world.
GameObject* objects[]
GUIElement* elements[]
Player* player
Window* window
while (true) {
// read player input
if (key == DOWN) {
update player's position
}
if (joystick is moved) {
update player's position
}
// update each object belonging to the game objects
for (each game object) {
do physics simulation
do AI
}
// render each object belonging to the game objects
for (each game object in objects[]) {
Window->render(object)
}
// render each GUI element
for (each game element in elements[]) {
if (element has been updated) {
Window->render(element)
}
2
here: game engines and game middleware which are structured as frameworks
剩余31页未读,继续阅读
资源评论
劉俊
- 粉丝: 134
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 目标跟踪-基于目标中心点同时进行目标检测+目标跟踪算法实现-项目源码-优质项目实战.zip
- Python《文本特征分析-全唐诗数据挖掘及分析 》+源代码
- Netron-Setup-4.5.0
- 可编辑的地图图形3-世界、各洲、美国地图.xls
- NineAi 新版ChatGPT AI系统网站源码
- Anaconda3-2022.10windows版本
- 基于Servlet的URL访问安全控制.doc
- 可编辑的地图图形-2-中国到省、到市、到县地图.xls
- 快慢指针法判断链表是否有环-go语言实现
- Python《金融新闻数据挖掘分析 (数据抓取、NLP算法分析、量化策略、回测框架等)》+源代码+项目说明
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功