Bada an overview



The bada architechture consistes of four layers:

Kernel:It consistes Linux Kernel or Real-time OS

Device: Core function of mobile device platform like telephony, security, graphics and event and window management

Service: Application engines and server based components. Access through API for any server assisted features .

Framework:C++ and Web frameworks that consists of an application framework

Application Model

The base application is stored on ROM and can't be removed using the Application manager .

The applications can be removed or installed if they are not Base Apps , these apps can be made using C++ or Flash .This platform supports Multi-tasking .

Initially it will sow a splash screen then initialize the Application . After that the application comes to the foreground and runs simultaneously .

The role of teacher



The role of teacher assumes great importance as they are in the noble profession of imparting education/ knowledge to the student's .
They are in the profession of important task of moduling young minds. The position of teacher can be well assumed when we say Socrates was teacher of Pleto. Pleto was teacher of Aristotle. Aristottle was teacher of Great Alexander.
Valmiki and Drona were Gurus of the epics, Ramayana and Mahabharata.
The ideals as ststed aforesaid can only be performed by a teacher when he is a person and not just a machine delivering informations only.
To put it simply, the aim of education is to help a student grow into a 'person'.
A teacher should not be a prop to which the growing student clings. On the otherhand a teacher should be like a gardener, watering the plant, seeing that it gets enough light and soil to grow furher.
This can be performed well if the teacher assumes the position of friend than that of a corrector.
In today's parlance this is more true when children have started asserting their right to death.

A teacher should be friend, philosopher and guide specially in the era of break down of joint family system and emergence of the nuclear family. As the children are deprived of the company of grand father, grand mother, brothers and sisters, the teacher of today should fill the vacuum.

Our Economy



Debt is soaring and that is the problem. It would be different if that spending was going into a savings and retirement account or in the case of business, into factory machinery. But it is not. The GDP growth involves spending money and borrowing the money rather than using earnings. That’s where the problem lies. And that’s where the demise of the dollar is going to occur. At some point in the near future, our country is simply going to run out of credit. It is the debt itself, out of control and getting worse that is going to cause the loss of Dollar’s spending power. The higher our consumer debt and our Govt. debt, the weaker the Dollar becomes.
Our economy is fast becoming morbidly obese and we have long abandoned the desire to slim down. We just keep buying bigger and bigger expectations. 

We just live in bubble. The loss of sound money -----money backed by tangible asset, rather than a Govt. process--------is the root imbalance that’s plaguing the Dollar.
We have gone through a strange period where several conditions were combined: Record low interest rates, an exploding budget deficit, record high consumer debt, and the housing and mortgage refinancing bubble, Americas slowest economic recovery even after recession and import is far more than export----- the trade deficit-----is a huge problem that will ultimately destroy the US Dollar  and its spending power.

Think right, win over yourself



The message as expressed in Bhagavad-Gita (6.6) is like ‘that one is, in the final analysis, his own friend or his own enemy. If one were authentic, clear and skilful in his actions and thoughts, no one else can ever cause him any damage.’
Further, no wrong can reach him but by his own ill deeds. His welfare is in his own hands and that none but himself can rob him or repose.
The art of right reaction to matters, which would ensure one is not damaged by situations, transactions or developments, is also summed up in these immortal lines of Ella Wheeler Wilcox in her poem Worthwhile,” Tis easy enough to be pleasant,/when life flows along like a song;/ But the man worthwhile is the one who will smile/ when everything goes dead wrong.”
Retaining one’s cheer and thus his presence of mind too, is thus, is vital stage in attaining that sublime ‘Victory over one self. This is brought about by being watchful and aware of one’s instincts and impulses and thus refining them by and by (shanihi, shanihi). This is the art of transition from being reactive to proactive.
And thus by attaining ‘Victory over one self ‘one indeed can ‘never know any defeat’

demo game for cars



Designers Are Descriptive, Programmers Are Procedural



A designer, a programmer, and a producer walk into a cocktail bar. The barman asks, “What can I get for you?”
The designer says, “Give me something fruity, with an umbrella in. No gin though, it makes me violent.”
The programmer says, “Mix two parts vodka with one part white rum, shake it with ice. Pour it into a glass with strawberry syrup, and top up with sprite. Stick an umbrella in the top and hand it to me.”
The producer, who only came along because they needed a third person to make up the joke, sighs and says, “I’ll have what these guys are having.”

The bartender begins making the drinks, “OK, three Equivalent Expressions, coming up…”

There’s a fundamental difference between the kind of problems that designers and programmers spend their time solving, and as such, I think there’s a difference in their habitual approach to solving problems, and the way they structure and explain their solutions.

Designers are fundamentally interested in the properties of the end result – the visible ‘outer shell’ of the product. They don’t care about the technology inside it, beyond the observable effects (like it being fast enough, not crashing, etc). Their descriptions of the product, and how it should be, are thus all written in terms of these visible properties: which things the player experiences, when and where the player experiences them, and so on.

Programmers, by contrast, are focused on the internals of the product – they are tasked with filling in the gap between the outer shell provided by the designers, and the solid core of functionality provided by the platform. It’s like a translation process – translating high-level game concepts into low-level hardware operations – and so their explanations are in similar terms: which lower-level concepts are in use, how they are combined into large structures, and so on.

Speaking In Tongues

This mismatch in modes of thinking requires extra effort to ‘bridge the gap.’ However, it’s not symmetrical.

As we’ve said, the entire focus of a programmer is on constructing these onion-layers of high-level to low-level concepts, composing and decomposing functionality to create the desired result. Connecting concepts between different layers of abstraction is programming. So when a designer talks to a programmer in the highest-level terms, mapping those terms down to the level that the programmer is working at is employing the programmer’s core skill.

The same is not so true for designers. Taking information about the implementation, and deducing from that the visible effects and constraints upon the outer shell, is not actually a part of design. Design is making decisions about the outer shell, within the constraints imposed by the implementation; figuring out what those constraints are is something different. Good designers can do it, of course, but it’s not their core skill.

To put this in slightly more concrete terms: When a designer tells a programmer that he wants a particular enemy to shout something when he sees the player, figuring out the points in the code that will need to be modified to support that is what programming’s all about. But when a programmer tells a designer that he’s added sound hooks to the base enemy class upon selecting a new object of interest, figuring out what this will actually allow the designer to do is not what design’s all about; it’s deciding which enemies should play sounds, and which sounds, that employs their core skill.

Another example, from outside the games industry, is CSS. Of all the designers I know who’ve done work with CSS, there are a few particular parts that they always have trouble with – display, position, and float. Together, these properties are extremely powerful for producing fluid layouts – but using them the way you want requires that you stop thinking like a visual designer, and start thinking like a web page renderer layout system.

First this box will be laid out, then this one will be floated to the left inside it, then this other one will be positioned relative to it… it’s a procedural combination of pieces, compensating for the fact that CSS is lacking some useful layout concepts, like built-in support for columns. Knowledge of how to achieve things like an equal-height 3-column layout is passed around as a bit of arcane ‘magic’ that designers just learn and apply, understanding it only in as far as is necessary to use it.

So, I think that when it comes to interfacing design and programming, it would be most efficient to get the programmers to learn to ‘speak designer,’ rather than getting the designers to learn to ‘speak programmer.’ It’s a better match to their core skills, to their habitual modes of thinking.

Designing For Designers

Most established programmers already do this in direct communication, I think. When explaining a new system to the design team, you don’t tell them all the class names and algorithms used; you tell them about the features and behaviors that they will use, phrased in their terms, the terms of the end user’s experience. Sure, sometimes you slip up – be it through absent-mindedly forgetting that you’re not talking to fellow programmers, or through enthusiasm about the elegance of what you built, or whatever – but even then, the designers usually speak enough Programmer to follow along.

Where I think this happens less is in tool design.

Internal tools frequently present their concepts and functionality in implementation terms, rather than in end-user-experience terms. Designers get settings with names like ‘Collision Detection mode’ and options like ‘Discrete’ and ‘Continuous,’ which only make sense if you know about how collision detection systems work. So what happens is they learn that they need to set it to ‘Continuous’ for fast-moving objects and ‘Discrete’ for slow-moving objects, and at that point the setting has basically become equivalent to a ‘Movement class’ setting with ‘Fast’ and ‘Slow’ options, except that it includes this extra pointless translation step that needs to be learnt and applied.

It’s not hard to imagine how the tools end up like this. Many of them start out almost as testing rigs for the programmers; the tool is there to allow the programmer to quickly configure and test the system’s features and interactions, so they write it in Programmer, and when they’ve done that it’s technically possible for the designer to set it up however they need it to be, so why make further changes?

Yet while it may be technically possible for for the designers to set things up the way they’re needed, it’s not easy, which means that it requires training, takes longer, distracts the designer, and is more error-prone. These costs are often not taken fully into account. The tool has effectively been designed by a programmer, and if that’s OK, why do you have designers on your team at all?

“Well, what if someday there’s an object that is slow-moving but needs Continuous collision detection for some reason nobody can think of right now? Better to keep the flexibility, right? Also, while it might make it easier for the designer to set things up, it makes it harder for the programmer, because now they’ve got to keep remembering that ‘Fast movement mode’ means ‘Continuous collision detection.’ It’s not saved any work, it’s just moved it around.”

Firstly, bear in mind that remembering things like “Fast movement mode is implemented using continuous collision detection” is a programming core skill – just like remembering things such as “CPU Texture reads are implemented using readback-from-video-memory, which is slow, and so should be avoided.” It might be the same amount of work, but programmers have more practice at it.

Secondly, though: simplicity and flexibility aren’t mutually exclusive! Presenting designers with options “phrased in Designer” doesn’t have to mean taking away the options “phrased in Programmer.” The implementation-level options can be hidden away in ‘Advanced Settings’ sections, or in a ‘Programmer View’ mode. The designer-friendly options can be provided as presets – a quick means for designers to automatically set the implementation-level options, while still being able to keep thinking in terms of the end user experience, and without losing the flexibility of tweaking things more directly when required. These are solvable problems!

Programmers and designers have different habits for thinking about problems. When programmers create tools that designers will use, they should present those tools in ‘design language’ – the language of the end-user experience – rather than just exposing the flags and values that the implementation works with. It’s better for them to do that, than for the designers to learn how to manipulate the implementation, because figuring out how to set the implementation for a particular design goal is what the programmers are good at.

How can you avoid the pitfalls that destroy most entrepreneurs?



Failed entrepreneurs believe that “if you build it, they will come”
They spend too much time on business support and not enough on money-making:
Entrepreneurs often waste valuable time on items related to supporting the business before they’ve figured out their money-making formula. Examples of wasteful business support items include:
  • Accounting – Selecting an accounting program to track their financials.
  • Design – Choosing a logo for business cards or a Web site.
  • Intellectual Property – Figuring out how what parts of your idea can get a copyright, trademark or patent.
While those can be important later on, you shouldn’t sweat supporting a business until you have a business capable of making money. Here are the key money-making topics Kelly says you should dig into before you work on supporting your business:
  • Lead generation – What are your sources for new customers?
  • Converting leads – How do you convert your leads into first-time customers?
Nail those money-makers first before sweating what your new logo should look like.
They run out of money and time: Most entrepreneurs fail because they run out of money or resources. Even mighty Webvan (with billions of dollars available to it) fell victim to this. They run out of money because they did a poor job at one of these three parts of financial projections:
  • You were optimistic on your revenues.
  • You underestimated your expenses.
  • You mis-projected your balances.
Obtaining cash is one good way to buy time. And if you don’t have cash, make sure you minimize your cash outlays until your money-making is kicking in. A good entrepreneur substantially minimizes cash outlays until the business is off the ground.
They lack strong execution: Entrepreneurs often fail because they execute poorly. This is not surprising since a common characteristic of entrepreneurs is that they are often more creative — which is in part why they come up with great ideas for businesses — than they are organized and detail-oriented.
They start too many things: We know an entrepreneur who has a full-time job (which he dreams of quitting) and has three Web sites running in his limited part time. He’s spreading himself too thin on the three web side-projects — one of them is showing promise (it dominates a niche market and generates $1,000 per month in revenue and growing).
It's not advisable to do such things as it will never ever give you the proper identity .

getting the most out of your workers



The real secret to getting the most out of your workers is...get a notepad and pen so you get this all nice! Did we need a book to tell us this? Maybe we did. We have all worked for companies in which the boss or manager was anything but nice. We've all worked for bosses who were raving lunatics. And maybe you are a raving lunatic and your employees absolutely hate you. I have worked for my share. One who couldn't speak a sentence without dropping the "F bomb." Another who was such an ego-maniac that she had to remind employees, almost daily, about the value of her stock holdings. Another who was so tense and humorless that the entire office became infected with misery.

Sound like you?

Take a deep breath. Tracy has some advice. First of all, smile! "When you see someone for the first time each day, smile at that person." Seems obvious, but how many managers don't do it (maybe even you)? Ask questions. "How's everything going? How are you feeling?" And really be interested in the answer. Listen. And don't interrupt when your people are talking to you. Be polite to your staff. Treat them "as if they are talented, intelligent and accomplished." (If they're not all those things, why haven't you fired them?)

If you need some reeducation to start acting the part of a manager who motivates others, Tracy has a basic but valuable outline on how to maximize your talent. Among his principles:

   1. Be Clear: How many managers have you known who give ambiguous direction (or none at all)? Often this is because they have no idea what to do themselves and are hoping their staff can figure it out. This isn't fair. If you're the boss, it's up to you to set expectations without any ambiguity.
   2. Be Competent: You have to lead by example. If you're using your staff to cover up your own incompetence, it's obvious to everyone and no one will respect you.
   3. Be Focused: If you're scattered as a manager, you reflect your disarray on others -- that's very demotivating. People should know what's important to you, because you live it.
   4. Have Integrity: Your reputation is your currency to get things done. Damage it and risk losing the allegiance of your people.

Animations and Gaming: Know-how of the Technology



India is fast going up the animation-outsourcing ladder. Though a recent entrant in the global animation scene, demand for India’s production services is growing at a fast pace. With global entertainment majors like Walt Disney, Imax, Warner Brothers and Sony signing up huge contracts with Indian animation companies, local animation design studios are gradually establishing their credentials overseas and building their skill sets in this high potential global market.

The boom is not only seen in the animation industry. The growth of the mobile industry has lead to a rise in demand in the gaming industry as well. India being a very competent nation with technology has an edge over others in terms of the time involved in game development. Games developed in India have been successful internationally and therefore, are enhancing India’s image as a country with the technical and infrastructure capabilities to provide gaming-related services that meet international standards
With the growing business in animation and gaming an emerging trend that can be seen in the market currently is that a number of Indian companies adopting a co-production business model from an outsourcing model. Shift to the new business model would prove fruitful for the industry as co-production model would drive motivation of industry players and compel them to perform bigger and better business. Going forward, India is expected to position itself as number one in the animation market riding high on its talent potential and quality work it offers the global market.
----NASSCOM Report

The future is really bright in Animations and Gaming .
Before joining any Institute think twice , does they give training upon the latest technology ? Do they teach Game Development or Mobile Applications ? What Technology they are working on ?Do they know how to create a game , then that's on which platform ? PC ? Mobile? I-Phones ? Social Network ? Which Engile They are using to run a game ? How can they create a game character if they are providing training on game designing , as Maya is not at all used to create gaming characters , then how they can teach game designing ?Did they do any project on games ? What's their track record on games ?
In India , there are lot institute who do give training on Multimedia , not even Animation is their cup of tea , but they do give ads that they do give training on Animations , Before joining any Institute for Animations just check the following :

Does the course contain Classical Animations ? They do give training on 2D Animations on Lightbox ? They do give training on Animation Methods Like :
Clay Animation
Cel-Shaded Animation
CG Animation with Actual Human Anatomy Model ?
Mouth Positions
Lip Synchronization
3D Animation (Including Modeling, Texturing, Rigging, Animations, Lighting, Formations, Dynamics )
Film Formats

The above are a simple basic criteria to be a part of Animation Industry .Animation is used not only in Films , but they are used in Medical, Difence , Police, Media, News, Law, Education , Interactive Sector's , Mobiles .Does the institute provide all the informations ? Do they promote the student's on International event's ? What's the pay package you are getting after doing the course from other institutes ?Student's from other institute's are getting low-end salary as they don't know the technicalities and they are not at all trained-up for Industry related Techniques .
Have look at the online tutorial regarding how to do animations at : , you can have a basic idea on how to create character's and how to do animations .

Regarding Game Development only we virtualinfocom gives training on real game development , we do have track record's for the last 10 years on game design and game development training and we are the first indian company who started Mobile Application Training in India .The most beautiful course and updated technology is with us as we are into the production of games and mobile apps . You can have a look at our news at different media and search engine's .

virtualinfocom (VIC), incorporated as digital design institute since 2000. For last several years we have produced more than 5,780 hardcore skilled designers most of them are working with some of the most renowned animation studios, multimediahouses, e-learning companies, national dailies, game development companies, mobile apps, web design firms etc.

At virtualinfocom VIC, we innovate design study by giving an apt environment i.e. full of daily regular sessions, project works, assignments, environmental study, group discussions, celebrating design events, contest and excursion trips. Unified method of teaching also include, updating students through various workshops, symposiums design shows.
We also have received continuous and beaming inspiration from the solid experience of our directors who are always a driving force to inspire the team of trainers & co-ordinater staff. Currently we have 7 centers based in Kolkata, Jaipur, Alahabad ,UK, Nigeria.

What makes virtualinfocom (VIC) different?
Well, our training module is 100% hands on, industry oriented. That is why, our curriculum has been designed with future requirements of industry in mind and that's not all. We regularly update and revise our module not only to keep abreast of latest changes happening in the industry but also to provide our participants with the latest and up-to-date skill inputs. Our course is a unique fusion of theory and practical industrial requirement, which gives our students an advantage anywhere in the world. So, if you have got the inherent belief in yourself and wish to reach the top in the field of creative animation, game development, Mobile Apps and web design, do rely on us.

How Will a student get Benefit?
You'll build a foundation in design concepts, learn through hands-on projects, get critiques from experienced designers, build portfolio projects to show prospective employers, and add credentials to your resume. And, you'll earn a certificate from probably the only Professional institute in Digital art and visual communication.

Why Study at VIC( virtualinfocom )?
Only VIC gives you a platform to execute your creative visualization. With expert faculty and facilities, VIC nurtures your ideas and portrays them on a commercial canvas. Apart from the application learning we also teach you the complete art of visual communication, and allows you to fly with your aesthetic. That's VIC.

We are going to give a basic idea on the Game Development :
Depending on the Type of Play Games can be defined as :

Action Games
A few of them are:
a) FPS: FPS stands for First Person Shooter. It places you in the boots of the main character of the game.
The FPS genre can be further sub-divided into the following:
1. Stealth: These games are based on the ability to sneak around without being seen by opponents. They are different from traditional FPSes because they place more emphasis on sneaking around rather than on an all-guns-blazing approach.
2. Old School: These feature the run-and-gun type of game play. Action in such games is fast paced, with tons of enemies.
3. Tactical: These games place emphasis on tactics, strategy & teamwork. In many ways, these are the exact opposite of the run-and-gun type of games.
4. Military/War: These are military games, based on the art of war. Examples are- The Medal Of Honour series and Call of Duty. As the player, you are placed in various war missions, which may not enable you to single-handedly save the world, but are nonetheless important in the ultimate outcome of the war.
5. Survival Horror: These is a relatively new sub-genre in FPS gaming. Here, the player is placed in a scary situation. Usually involving ghosts or monsters; the sole objective of the game is survival. Naturally, the basic game play consists of running and gunning, but puzzle-solving elements are also usually built into the game.

b) TPS: TPS stands for Third-Person shooter.
c) Platform: This genre consists of games where the player has to move around on, or jump to and from, a number of platforms.

The strategy genre can be further sub-divided into:
a) Puzzle: Puzzle games involve solving puzzles, which could involve logic, pattern recognition, and strategy.
b) RPG: RPG stands for Role-Playing Game. They generally involve long, intricate plots with an emphasis on character development.
c) Real-time Strategy Games: As the name implies, the action in such games takes place in real-time—that is, the state of the game is constantly changing.
d) Board Games: Board games are simply digitized versions of classic board games.
e) Sims: ‘Sim’ is short for ‘simulator’.

Today, most adventure games are a mix of a number of genres. For examples, Prince Of Persia: the sands of time is a mix of action & adventure elements, with a third person view.
This genre is sub divided into:
a) Flight Simulators: Flight simulators, obviously, try and re-create aircraft and their controls. Microsoft Flight Simulator is an excellent example.
b) Racing Simulators: Racing simulators are based on accurately re-creating racing environments. This category includes not only car races, but virtually any kind of race, take boating, for instance.

c) Combat Simulators: These take the realistic elements of simulators & adapt them into a combat style game.
d) Sports Simulators: The objective here is very simple- to recreate the playing condition of a particular sport in the most realistic way.

MMOG stands for massively multiplayer online game. Online gaming has really taken of at present, with broadband internet becoming a reality for a large number of people.

The most popular MMOG are::
a) MMORPGs: MMORPGs (Massively Multiplayer Online Role Playing Games) are the most popular types of MMOGs. They follow the client server model, where the gamers running the client’s software is represented in the online world they inhabit via an avatar.

b) MMOFPS: this is a massively multiplayer version of the traditional FPS.

c) MMORTS: The third & probably least popular category of MMOGs is the MMORTS, where RTS stands for Real Time Strategy.
Technology Used to create Games

Manual Drawing and Classical Animations.
Character Build-up
3Ds Max
Flash with Hard Core Action Script
Alice 99
Object C
Open GL
Direct X
JavaScript & RMI
JiniScript etc

The next generation technology is with Social Networking and Mobile Tech and we do give training on how to create game's on social network as well as mobiles and other device's like PS and X-Box .
Before taking any step just think do the other institutes gives training on social games? Do they teach X-Box Programming , Do they teach on how to build a Game Engine ?
Do they give training on OpenGL , Qt, XNA ?
If they claim's that they do train on Social game's just ask them what's the technology behind that , and do they teach on that or not .Will you learn how to develop a First Person Shooting game ? Then which engine you are using ? From a point of view of a student , you don't know the technology , so just cross chk it on the web what's the technology available on game development .Are you really ready for the Social Network games ? Then what could be your career path ?
Which are the companies who does social games ? We know the fact's , for more clarifications you call to our 24 X 7 Support desk on career's regarding games. +91 9830082617

Virtualinfocom provides Industry Oriented course on game development and Mobile Tech as they do have 79+ Tie-ups with different game development companies , they course is up-todate with latest technology and up-standard faculty stuff .The faculty here are from the production unit of virtualinfocom it-self , they do know what's the real life problem in game development as well as how to train a student.

Following are some of the game character's created by us , ask any other institutes , how to create these type of character's for gaming (N.B: These image's are sole property of virtualinfocom , so don't try to copy them), these are made by virtualinfocom student's .

Introduction to Game AI



In the broadest sense, most games incorporate some form of artificial intelligence (AI). For instance, developers have used AI for years to give seemingly intelligent life to countless game characters, from the ghosts in the classic arcade game Pac Man to the bots in the first-person shooter Unreal, and many others in between. The huge variety of game genres and game characters necessitates a rather broad interpretation as to what is considered game AI. Indeed, this is true of AI in more traditional scientific applications as well.
Some developers consider tasks such as pathfinding as part of game AI. Steven Woodcock reported in his "2003 Game Developer's Conference AI Roundtable Moderator's Report' that some developers even consider collision detection to be part of game AI.Clearly, some wide-ranging interpretations of game AI exist.
We're going to stick with a broad interpretation of game AI, which includes everything from simple chasing and evading, to pattern movement, to neural networks and genetic algorithms. Game AI probably best fits within the scope of weak AI (see the sidebar "Defining AI"). However, in a sense you can think of game AI in even broader terms.
In games, we aren't always interested in giving nonplayer characters human-level intellect. Perhaps we are
writing code to control nonhuman creatures such as dragons, robots, or even rodents. Further, who says we always have to make nonplayer characters smart? Making some nonplayer characters dumb adds to the variety and richness of game content. Although it is true that game AI is often called upon to solve fairly complex problems, we can employ AI in attempts to give nonplayer characters the appearance of having different personalities, or of portraying emotions or various dispositionsfor example, scared, agitated, and so on.

Defining AI
The question "what is artificial intelligence?" is not easy to answer. If you look up artificial intelligence in a dictionary, you'll probably find a definition that reads something like this: "The ability of a computer or other machine to perform those activities that are normally thought to require intelligence." This definition comes from The American Heritage Dictionary of the English Language, Fourth Edition (Houghton Mifflin Company). Still other sources define artificial intelligence as the process or science of creating intelligent machines.
From another perspective it's appropriate to think of AI as the intelligent behavior exhibited by the machine that has been created, or perhaps the artificial brains behind that intelligent behavior. But even this interpretation is not complete. To some folks, the study of AI is not necessarily for the purpose of creating intelligent machines, but for the purpose of gaining better insight into the nature of human intelligence. Still others study AI methods to create machines that exhibit some limited form of intelligence.
This begs the question: "what is intelligence?" To some, the litmus test for AI is how close it is to human intelligence. Others argue that additional requirements must be met for a machine to be considered intelligent. Some people say intelligence requires a conscience and that emotions are integrally tied to intelligence, while others say the ability to solve a problem requiring intelligence if it were to be solved by a human is not enough; AI must also learn and adapt to be considered intelligent.
AI that satisfies all these requirements is considered strong AI. Unlike strong AI, weak AI involves a broader range of purposes and technologies to give machines specialized intelligent qualities.

Game AI falls into the category of weak AI.
The bottom line is that the definition of game AI is rather broad and flexible. Anything that gives the illusion of intelligence to an appropriate level, thus making the game more immersive, challenging, and, most importantly,
fun, can be considered game AI. Just like the use of real physics in games, good AI adds to the immersiveness of the game, drawing players in and suspending their reality for a time.

Deterministic Versus Nondeterministic AI
Game AI techniques generally come in two flavors: deterministic and nondeterministic.

Deterministic behavior or performance is specified and predictable. There's no uncertainty. An example of deterministic behavior is a simple chasing algorithm. You can explicitly code a nonplayer character to
move toward some target point by advancing along the x and y coordinate axes until the character's x and y coordinates coincide with the target location.

Nondeterministic behavior is the opposite of deterministic behavior. Behavior has a degree of uncertainty and is somewhat unpredictable (the degree of uncertainty depends on the AI method employed and how well that method is understood). An example of nondeterministic behavior is a nonplayer character learning to adapt to the fighting tactics of a player. Such learning could use a neural network, a Bayesian technique, or a genetic algorithm.
Deterministic AI techniques are the bread and butter of game AI. These techniques are predictable, fast, and easy to implement, understand, test, and debug. Although they have a lot going for them, deterministic methods place the burden of anticipating all scenarios and coding all behavior explicitly on the developers' shoulders.

Further, deterministic methods do not facilitate learning or evolving. And after a little gameplay, deterministic behaviors tend to become predictable. This limits a game's play-life, so to speak.
Nondeterministic methods facilitate learning and unpredictable gameplay. Further, developers don't have to explicitly code all behaviors in anticipation of all possible scenarios. Nondeterministic methods also can learn
and extrapolate on their own, and they can promote so-called emergent behavior, or behavior that emerges without explicit instructions.

Developers traditionally have been a bit wary of AI that is nondeterministic, although this is changing.
Unpredictability is difficult to test and debughow can you test all possible variations of player action to make sure the game doesn't do something silly in some cases? Game developers face an ever-shortening development cycle that makes developing and testing new technology to production-ready standards extremely difficult. Such short development periods make it difficult for developers to understand cutting-edge AI technologies fully and to see their implications in a mass-market commercial game.

At least until recently, another factor that has limited game AI development is the fact that developers have been focusing most of their attention on graphics quality. As it turns out, such focus on developing better and faster
graphics techniques, including hardware acceleration, might now afford more resources to be allocated toward developing better, more sophisticated AI. This fact, along with the pressure to produce the next hit game, is encouraging game developers to more thoroughly explore nondeterministic techniques.

Established Game AI
Perhaps the most widely used AI technique in games is cheating. For example, in a war simulation game the computer team can have access to all information on its human opponentslocation of their base; the types,
number, and location of units, etc.without having to send out scouts to gather such intelligence the way a human player must. Cheating in this manner is common and helps give the computer an edge against intelligent human players. However, cheating can be bad. If it is obvious to the player that the computer is cheating, the player likely will assume his efforts are futile and lose interest in the game. Also, unbalanced cheating can give
computer opponents too much power, making it impossible for the player to beat the computer. Here again, the player is likely to lose interest if he sees his efforts are futile. Cheating must be balanced to create just enough of a challenge for the player to keep the game interesting and fun.
Of course, cheating isn't the only well-established AI technique. Finite state machines are a ubiquitous game AI technique.

Developers commonly use fuzzy logic in fuzzy state machines to make the resulting actions somewhat less predictable and to reduce the burden of having to enumerate huge numbers of if-then rules. Rather than have a
rule that states if distance = 10 and health = 100 then attack, as you might in a finite state machine, fuzzy logic enables you to craft rules using less precise conditions, such as if close and healthy then attack aggressively.
Effective and efficient pathfinding is a fundamental task that nonplayer characters must accomplish in all sorts of games. Nonplayer character units in a war simulation must be able to navigate over terrain and avoid barriers to reach the enemy. Creatures in a first-person shooter must be able to navigate through dungeons or buildings to reach or escape from the player. The scenarios are endless, and it's no wonder that AI developers give path finding tremendous attention .
These are only a few of the established game AI techniques; others include scripting, rules-based systems, and some artificial life (A-life) techniques, to name a few. A-life techniques are common in robotic applications, and developers have adapted and used them with great success in video games. Basically, an A-life system is a synthetic system that exhibits natural behaviors. These behaviors are emergent and develop as a result of the combined effect of lower-level algorithms.

Chasing and Evading:

The chasing/evading problem consists of two parts. The first part involves the decision to initiate a chase or to evade. The second part involves effecting the chase or evasionthat is, getting your predator to the prey, or
having the prey get as far from the predator as possible without getting caught. In a sense, one could argue that the chasing/evading problem contains a third element: obstacle avoidance. Having to avoid obstacles while chasing or evading definitely complicates matters, making the algorithms more difficult to program.
The simplest, easiest-to-program, and most common method you can use to make a predator chase its prey involves updating the predator's coordinates through each game loop such that the difference between the
predator's coordinates and the prey's coordinates gets increasingly small. This algorithm pays no attention to the predator and prey's respective headings (the direction in which they're traveling) or their speeds.
For example, in games that incorporate real-time physics engines you can employ methods that consider the positions and velocities of both the predator and its prey so that the predator can try to intercept its prey instead of relentlessly chasing it. In this case the relative position and velocity information can be used as input to an algorithm that will determine appropriate force actuation steering forces, for exampleto guide the predator to the target. Yet another method involves using potential functions to influence the behavior of the predator in a manner that makes it chase its prey, or more specifically, makes the prey attract the predator. Similarly, you can use such potential functions to cause the prey to run from or repel a predator.

Basic chase algorithm

if (predatorX > preyX)
else if (predatorX < preyX)
if (predatorY > preyY)
else if (predatorY < preyY)

In this example, the prey is located at coordinates preyX and preyY, while the predator is located at coordinates predatorX and predatorY. During each cycle through the game loop the predator's coordinates are checked against the prey's. If the predator's x-coordinate is greater than the prey's x-coordinate, the predator's x coordinate is decremented, moving it closer to the prey's x-position. Conversely, if the predator's x-coordinate is less than the prey's, the predator's x-coordinate is incremented. Similar logic applies to the predator's y coordinate based on the prey's y-coordinate. The end result is that the predator will move closer and closer to the prey each cycle through the game loop.

Basic evade algorithm

if (preyX > predatorX)
else if (preyX < predatorX)
if (preyY > predatorY)
else if (preyY < predatorY)

In tile-based games the game domain is divided into discrete tilessquares, hexagons, etc.and the player's position is fixed to a discrete tile. Movement goes tile by tile, and the number of directions in which the player
can make headway is limited. In a continuous environment, position is represented by floating-point coordinates, which can represent any location in the game domain. The player also is free to head in any direction.

You can apply the approach illustrated in these two examples whether your game incorporates tile-based or continuous movement. In tile-based games, the xs and ys can represent columns and rows in a grid that encompasses the game domain. In this case, the xs and ys would be integers. In a continuous environment, the xs and ysand zs if yours is a 3D gamewould be real numbers representing the coordinates in a Cartesian coordinate system encompassing the game domain.

There's no doubt that although it's simple, this method works. The predator will chase his prey with unrelenting determination.

Basic tile-based chase example

if (predatorCol > preyCol)
else if (predatorCol < preyCol)
if (predatorRow> preyRow)
else if (predatorRow

BuildPathToTarget function

void ai_Entity::BuildPathToTarget (void)
int nextCol=col;
int nextRow=row;
int deltaRow=endRow-row;
int deltaCol=endCol-col;
int stepCol, stepRow;
int currentStep, fraction;

Path initialization

for (currentStep=0;currentStep

Path direction calculation
if (deltaRow < 0) stepRow=-1; else stepRow=1;
if (deltaCol < 0) stepCol=-1; else stepCol=1;

Bresenham algorithm

if (deltaCol >deltaRow)
fraction = deltaRow *2-deltaCol;
while (nextCol != endCol)
if (fraction >=0)
nextRow =nextRow +stepRow;
fraction =fraction -deltaCol;
fraction=fraction +deltaRow;
fraction =deltaCol *2-deltaRow;
while (nextRow !=endRow)
if (fraction >=0)
fraction=fraction -deltaRow;
nextRow =nextRow +stepRow;
fraction=fraction +deltaCol;

The initial if conditional uses the values in deltaCol and deltaRow to determine which axis is the longest. The first block of code after the if statement will be executed if the column axis is the longest. The else part will be executed if the row axis is the longest.

Wait for the next topic on AI in Gaming

What is a Game Engine?



Game engines are particularly useful in situations in which you plan on creating more than one game, and you don't want to have to reinvent the wheel each time around. The idea is that you figure out what common functionality all games use, and you write it once and stick it in the game engine. Another significant benefit of a game engine for Windows games is that it allows you to hide the messy details of Windows-specific code that doesn't necessarily have anything to do with a game. For example, virtually all the code in the Skeleton application in Appendix C has nothing to do with a game, but it's required of every Windows application.

A game engine represents an organization of the code for a game so that general application tasks are separated from game-specific tasks. The benefit to the game developer is that you can add features to a game engine that you will be able to reuse in all of your future games. Additionally, using a game engine allows you to simplify the code for your games and focus your attention on the game code that matters most. Once you get accustomed to using a game engine, you'll wonder how games could be created any other way. In reality, most commercial game developers do have their own custom game engines that they've developed over years of learning what common features most games require.

It is the responsibility of a game engine to handle the chores of setting up a game, making sure that it runs properly, and then shutting it down. Although it is true that these tasks are required of any program, certain aspects of initializing, running, and cleaning up after games are truly unique to games. Therefore, it is important for a game engine to address the unique needs of games and help make the process of building games around the engine as simple and straightforward as possible. With a well-designed game engine, you'll find that creating a game requires a lot less code than if you had not relied on a game engine. The idea is to develop certain core game routines once, stick them in the game engine, and then never bother with them again unless absolutely necessary. For example, once you've written code to load an image and draw it on the screen, there is never a reason to rewrite the code again. Loading and drawing images is a basic feature required of all game engines

Breaking a Game Down into Events

Every Windows program can be broken down into events, which are things that take place while a program is running, such as mouse clicks and window resizes. Just as Windows programs have events that they must handle, games have their own unique set of events that must be taken into consideration during development. The initialization process of a game can be considered an event, and its responsibilities are to load graphics and sounds for the game, clear the playing field, zero out the score, and so on. Similarly, user input carries over to games as well, meaning that mouse clicks and key presses are events that games certainly must concern themselves with. Additionally, keep in mind that, in Windows, it's possible for some games to be minimized or otherwise placed into the background, which means that you'll probably want to pause the game. This activation and reactivation process can be represented by a couple of events.

Although many other events could certainly factor into a game engine, the following are some of the core events applicable to just about any game:
  • Initialization
  • Start
  • End
  • Activation
  • Deactivation
  • Paint
  • Cycle
The initialization event occurs when a game is first launched and gives a game a chance to perform critical initial setup tasks, including creating the game engine itself. The start and end events correspond to the start and end of a game, and they provide good places to perform initialization and cleanup tasks associated with a specific game session. The activation and deactivation events come into play when a game is minimized or sent to the background and then later restored. The paint event is sent when a game needs to draw itself and is similar to the Windows WM_PAINT message. Finally, the cycle event enables a game to perform a single game cycle, which is very important, as you learn next.
Establishing the Timing for Games
If you've never taken a look at a game from a programming perspective, it might surprise you to learn how all the movement and the animation in a game are orchestrated. You will learn all the details of animated graphics in Chapter 9, "Making Things Move with Sprite Animation," but for now, I want to touch on the importance of game timing as it applies to animation and other facets of games. Every game, except extremely simple card games, relies on some sort of timing mechanism to enable the game to break down its execution into frames or cycles. A cycle of a game is one slice of time, which usually corresponds to a snapshot of the game's graphics and data. If you think of a game as a movie playing on a VCR or DVD player, pressing Pause allows you to view a single cycle. Stepping forward one frame in the video is like moving to the next cycle of the game. In any given cycle, a game takes care of updating its graphics, as well as performing any other calculations and processing related to how characters and objects are moving and interacting with each other.

A good way to get a grasp on the importance of game cycles is to take a practical game as an example. The classic Space Invaders game was mentioned in the opener of this chapter, so let's use it as an example to demonstrate game cycles. When Space Invaders first starts, the ship is created, along with several rows of alien invaders. Each of these objects has an initial position and velocity. If Space Invaders had no timing or game cycles, the game would be forever frozen in its initial state, as if you had pressed a permanent Pause button when the game started. We know that this isn't the case, however, because the game starts out with the aliens slowly moving across the screen. If you were to view Space Invaders a cycle at a time, you would notice that, in each cycle, the aliens are only moved slightly. This is because there happen to be quite a few cycles taking place in a given period of time, which gives the effect of smooth motion. The role of a game cycle is to update the status of all the objects in the game and then reflect these changes by updating the graphics shown on the screen. As a comparison, televisions display 30 different images (cycles) per second, whereas motion pictures rely on 24 images per second. You learn much more about the significance of different rates of animation in Chapter 9. For now, it's important to understand that just about every game is highly dependent on periodic cycles.
Note - A single screen of graphics in a game is known as a frame. Because a new screen of graphics is drawn during each game cycle, the speed of games is often measured in frames per second, or fps. Because the discussion in this chapter is centered on cycles, as opposed to frames, I refer to game speeds in cycles per second. However, cycles per second, frames per second, and even images per second are really the same measurement.
The more cycles a game can run through in a given amount of time, the smoother the game appears to run. As an extreme example, compare the "smoothness" of a slideshow to a motion picture. The slideshow abruptly moves from one still image to another with no transition or sense of smooth movement, whereas a motion picture shows fluid motion as if you were experiencing it in real-time. Similarly, a game with only a few cycles per second will appear choppy, whereas a higher number of cycles per second will result in a much smoother game. A larger number of cycles per second also gives you more flexibility in speeding up or slowing down a game to arrive at a perfect speed.

Knowing that more cycles result in smoother graphics and better flexibility, you might think that you could crank up the cycles per second really high. As with most things in life, there is a trade-off when it comes to game cycles and game efficiency. The problem lies in the fact that the amount of processing taking place in a game in each cycle is often considerable, which means that to perform numerous cycles per second, your computer's processor and graphics card have to be able to keep up. Even with the blazingly fast computers prevalent these days, there are practical limitations as to how fast most computers can perform game processing. In reality, most games will fall in the range of 15 to 20 cycles per second, with a maximum speed surpassing that of a motion picture at 30 cycles per second. Except for some rare situations, the minimum speed you should shoot for is 12 cycles per second.
Note - Commercial 3D games are always pushing the envelope of what is possible given the current computer hardware available. The number of cycles per second for a modern 3D game is the most common measurement used to determine if the game is being too ambitious in terms of how much it is taxing the processing capabilities of the computer. In an ideal world, you would design games with beautifully detailed graphics and not worry about whether the game brings a user's system to a screeching halt. In reality, game designers are always walking a tight rope to make games look incredibly good yet still maintain a decent frame rate (ideally, 30fps or more).
Now that you understand how the timing of a game is expressed in terms of cycles, you can probably see why a cycle is a type of game event. It works like this: When a game first starts, you initialize the game engine with the game speed in cycles per second. Let's say that you go with 12 cycles per second. The game engine is then responsible for setting up and managing a timer that fires a cycle event 12 times each second. The game code receives these cycle messages and handles them by updating the objects in the game and redrawing the game screen. You can think of a cycle event as a snooze alarm that keeps going off over and over; except in this case, it's going off 12 times a second. Your game clearly isn't getting much sleep!
Note - Speaking of sleep, another role of a game engine is to put a game to sleep whenever it is no longer the active window. In practical terms, putting a game to sleep simply means that the game engine stops sending cycle messages. Because no cycle messages are being sent, the game is effectively paused.
The Game Event Functions
The first place to start in creating a game engine is to create handler functions that correspond to the game events mentioned earlier in the chapter. When an event occurs in a game, the corresponding event handler function will be called, which gives your game a chance to respond accordingly. The following are these functions, which should make some sense to you because they correspond directly to the game events:
BOOL GameInitialize(HINSTANCE hInstance);
void GameStart(HWND hWindow);
void GameEnd();
void GameActivate(HWND hWindow);
void GameDeactivate(HWND hWindow);
void GamePaint(HDC hDC);
void GameCycle();
The first function, GameInitialize(), is probably the only one that needs special explanation simply because of the argument that gets sent into it. I'm referring to the hInstance argument, which is of type HINSTANCE. This is a Win32 data type that refers to an application instance. An application instance is basically a program that has been loaded into memory and is running in Windows. If you've ever used Alt+Tab to switch between running applications in Windows, you're familiar with different application instances. The HINSTANCE data type is a handle to an application instance, and it is very important because it enables a program to access its resources since they are stored with the application in memory.

Developing a Game Engine

The first place to start in creating a game engine is to create handler functions that correspond to the game events mentioned earlier in the chapter. When an event occurs in a game, the corresponding event handler function will be called, which gives your game a chance to respond accordingly. The following are these functions, which should make some sense to you because they correspond directly to the game events:
BOOL GameInitialize(HINSTANCE hInstance);
void GameStart(HWND hWindow);
void GameEnd();
void GameActivate(HWND hWindow);
void GameDeactivate(HWND hWindow);
void GamePaint(HDC hDC);
void GameCycle();
The first function, GameInitialize(), is probably the only one that needs special explanation simply because of the argument that gets sent into it. I'm referring to the hInstance argument, which is of type HINSTANCE. This is a Win32 data type that refers to an application instance. An application instance is basically a program that has been loaded into memory and is running in Windows. If you've ever used Alt+Tab to switch between running applications in Windows, you're familiar with different application instances. The HINSTANCE data type is a handle to an application instance, and it is very important because it enables a program to access its resources since they are stored with the application in memory.

The GameEngine Class

The GameEngine Class The game event handler functions are actually separated from the game engine itself, even though there is a close tie between them. This is necessary because it is organizationally better to place the game engine in its own C++ class. This class is called GameEngine and is shown in Listing 2.1.
Note - If you were trying to adhere strictly to object-oriented design principles, you would place the game event handler functions in the GameEngine class as virtual methods to be overridden. However, although that would represent good OOP design, it would also make it a little messier to assemble a game because you would have to derive your own custom game engine class from GameEngine in every game. By using functions for the event handlers, you simplify the coding of games at the expense of breaking an OOP design rule. Such are the trade-offs of game programming.
Listing 2.1 The GameEngine Class Definition Reveals How the Game Engine Is Designed

class GameEngine
// Member Variables
static GameEngine* m_pGameEngine;
HINSTANCE m_hInstance;
HWND m_hWindow;
TCHAR m_szWindowClass[32];
TCHAR m_szTitle[32];
WORD m_wIcon, m_wSmallIcon;
int m_iWidth, m_iHeight;
int m_iFrameDelay;
BOOL m_bSleep;
// Constructor(s)/Destructor
GameEngine(HINSTANCE hInstance, LPTSTR szWindowClass, LPTSTR szTitle,
WORD wIcon, WORD wSmallIcon, int iWidth = 640, int iHeight = 480);
virtual ~GameEngine();
// General Methods
static GameEngine* GetEngine() { return m_pGameEngine; };
BOOL Initialize(int iCmdShow);
LRESULT HandleEvent(HWND hWindow, UINT msg, WPARAM wParam,
LPARAM lParam);
// Accessor Methods
HINSTANCE GetInstance() { return m_hInstance; };
HWND GetWindow() { return m_hWindow; };
void SetWindow(HWND hWindow) { m_hWindow = hWindow; };
LPTSTR GetTitle() { return m_szTitle; };
WORD GetIcon() { return m_wIcon; };
WORD GetSmallIcon() { return m_wSmallIcon; };
int GetWidth() { return m_iWidth; };
int GetHeight() { return m_iHeight; };
int GetFrameDelay() { return m_iFrameDelay; };
void SetFrameRate(int iFrameRate) { m_iFrameDelay = 1000 /
iFrameRate; };
BOOL GetSleep() { return m_bSleep; };
void SetSleep(BOOL bSleep) { m_bSleep = bSleep; };

The GameEngine class definition reveals a subtle variable naming convention that you might or might not be familiar with. This naming convention involves naming member variables of a class with an initial m_ to indicate that they are class members. Additionally, global variables are named with a leading g_ to indicate that they are globals. This convention is useful because it helps you to immediately distinguish between local variables, member variables, and global variables in a program. The member variables for the GameEngine class all take advantage of this naming convention.

The GameEngine class defines a static pointer to itself, m_pGameEngine, which is used for outside access by a game program. The application instance and main window handles of the game program are stored away in the game engine using the m_hInstance and m_hWindow member variables. The name of the window class and the title of the main game window are stored in the m_szWindowClass and m_szTitle member variables. The numeric IDs of the two program icons for the game are stored in the m_wIcon and m_wSmallIcon members. The width and height of the game screen are stored in the m_iWidth and m_iHeight members. It's important to note that this width and height correspond to the size of the game screen, or play area, not the size of the overall program window, which is larger to accommodate borders, a title bar, menus, and so on. The m_iFrameDelay member variable indicates the amount of time between game cycles in milliseconds. Finally, m_bSleep is a Boolean member variable that indicates whether the game is sleeping (paused).

The GameEngine constructor and destructor are defined after the member variables, as you might expect. The constructor is very important because it accepts arguments that dramatically impact the game being created. More specifically, the GameEngine() constructor accepts an instance handle, window classname, title, icon ID, small icon ID, width, and height. Notice that the iWidth and iHeight arguments default to values of 640 and 480, respectively, which is a reasonable minimum size for game screens. The ~GameEngine() destructor doesn't do anything, but it's worth defining in case you need to add some cleanup code to it later. I mentioned that the GameEngine class maintains a static pointer to itself. This pointer is accessed from outside the engine using the static GetEngine() method. The Initialize() method is another important general method in the GameEngine class, and its job is to initialize the game program once the engine is created. The HandleEvent() method is responsible for handling standard Windows events within the game engine and is a good example of how the game engine hides the details of generic Windows code from game code. The remaining methods in the GameEngine class are accessor methods used to access member variables; these methods are all used to get and set member variables. The one accessor method to pay special attention to is SetFrameRate(), which sets the frame rate or number of cycles per second of the game engine. Because the actual member variable that controls the number of game cycles per second is m_iFrameDelay, which is measured in milliseconds, it's necessary to perform a quick calculation to convert the frame rate in SetFrameRate() to milliseconds.

The source code for the GameEngine class provides implementations for the methods described in the header that you just saw, as well as the standard WinMain() and WndProc() functions that tie into the game engine. The GameEngine source code also initializes the static game engine pointer, like this: GameEngine *GameEngine::m_pGameEngine = NULL; 
Listing 2.2 The WinMain() Function in the Game Engine Makes Calls to Game Engine Functions and Methods and Provides a Neat Way of Separating Standard Windows Program Code from Game Code
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow) {
MSG msg;
static int iTickTrigger = 0;
int iTickCount;
if (GameInitialize(hInstance))
// Initialize the game engine
if (!GameEngine::GetEngine()->Initialize(iCmdShow))
return FALSE;
// Enter the main message loop
while (TRUE)
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
// Process the message
if (msg.message == WM_QUIT)
// Make sure the game engine isn't sleeping
if (!GameEngine::GetEngine()->GetSleep())
// Check the tick count to see if a game cycle has elapsed
iTickCount = GetTickCount();
if (iTickCount > iTickTrigger)
{ iTickTrigger = iTickCount +
return (int)msg.wParam;
// End the game
return TRUE;
Although this WinMain() function is similar to those found in every Windows application, there is an important difference. The difference has to do with the fact that this WinMain() function establishes a game loop that takes care of generating game cycle events at a specified interval. The smallest unit of time measurement in a Windows program is called a tick, which is equivalent to one millisecond and is useful in performing accurate timing tasks. In this case, WinMain() counts ticks in order to determine when it should notify the game that a new cycle is in order. The iTickTrigger and iTickCount variables are used to establish the game cycle timing in WinMain().

The first function called in WinMain() is GameInitialize(), which gives the game a chance to be initialized. Remember that GameInitialize() is a game event function provided as part of the game-specific code for the game; therefore, it isn't a direct part of the game engine. A method that is part of the game engine is Initialize(), which is called to get the game engine itself initialized. From there, WinMain() enters the main message loop for the game program. The else part of the main message loop is where things get interesting. This part of the loop first checks to make sure that the game isn't sleeping and then uses the frame delay for the game engine to count ticks and determine when to call the GameCycle() function to trigger a game cycle event. WinMain() finishes up by calling GameEnd() to give the game program a chance to wrap up the game and clean up after itself. The other standard Windows function included in the game engine is WndProc(), which is very simple because the HandleEvent() method of the GameEngine class is responsible for processing Windows messages:
// Route all Windows messages to the game engine
return GameEngine::GetEngine()->HandleEvent(hWindow, msg, wParam, lParam);
All WndProc() really does is pass along all messages to HandleEvent(), which might at first seem like a waste of time. However, the idea is to allow a method of the GameEngine class to handle the messages so that they can be processed in a manner that is consistent with the game engine.
Speaking of the GameEngine class, now that you have a feel for the support functions in the game engine, we can move right along and examine specific code in the GameEngine class. Listing 2.3 contains the source code for the GameEngine() constructor and destructor.
Listing 2.3 The GameEngine::GameEngine() Constructor Takes Care of Initializing Game Engine Member Variables, Whereas the Destructor is Left Empty for Possible Future Use
GameEngine::GameEngine(HINSTANCE hInstance, LPTSTR szWindowClass, LPTSTR szTitle, WORD wIcon, WORD wSmallIcon, int iWidth, int iHeight)
// Set the member variables for the game engine
m_pGameEngine = this;
m_hInstance = hInstance;
m_hWindow = NULL;
if (lstrlen(szWindowClass) > 0)
lstrcpy(m_szWindowClass, szWindowClass);
if (lstrlen(szTitle) > 0)
lstrcpy(m_szTitle, szTitle);
m_wIcon = wIcon;
m_wSmallIcon = wSmallIcon;
m_iWidth = iWidth;
m_iHeight = iHeight;
m_iFrameDelay = 50; // 20 FPS default
m_bSleep = TRUE;
The GameEngine() constructor is relatively straightforward in that it sets all the member variables for the game engine. The only member variable whose setting might seem a little strange at first is m_iFrameDelay, which is set to a default frame delay of 50 milliseconds. You can determine the number of frames (cycles) per second for the game by dividing 1,000 by the frame delay, which in this case results in 20 frames per second. This is a reasonable default for most games, although specific testing might reveal that it needs to be tweaked up or down. Keep in mind that you should always shoot for the highest frame rate (lowest frame delay) possible that allows your game to run smoothly; you don't want to see a game slowing down because it can't keep up with a high frame rate.

The Initialize() method in the GameEngine class is used to initialize the game engine. More specifically, the Initialize() method now performs a great deal of the messy Windows setup tasks, such as creating a window class for the main game window and then creating a window from the class. Listing 2.4 shows the code for the Initialize() method.
Listing 2.4 The GameEngine::Initialize() Method Handles Some of the Dirty Work that Usually Takes Place in WinMain()
BOOL GameEngine::Initialize(int iCmdShow)
WNDCLASSEX wndclass;
// Create the window class for the main window
wndclass.cbSize = sizeof(wndclass); = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = m_hInstance;
wndclass.hIcon = LoadIcon(m_hInstance,
wndclass.hIconSm = LoadIcon(m_hInstance,
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = m_szWindowClass;
// Register the window class
if (!RegisterClassEx(&wndclass))
return FALSE;
// Calculate the window size and position based upon the game size
int iWindowWidth = m_iWidth + GetSystemMetrics(SM_CXFIXEDFRAME) * 2,
iWindowHeight = m_iHeight + GetSystemMetrics(SM_CYFIXEDFRAME) * 2 +
if (wndclass.lpszMenuName != NULL)
iWindowHeight += GetSystemMetrics(SM_CYMENU);
int iXWindowPos = (GetSystemMetrics(SM_CXSCREEN) - iWindowWidth) / 2,
iYWindowPos = (GetSystemMetrics(SM_CYSCREEN) - iWindowHeight) / 2;
// Create the window
m_hWindow = CreateWindow(m_szWindowClass, m_szTitle, WS_POPUPWINDOW |
WS_CAPTION | WS_MINIMIZEBOX, iXWindowPos, iYWindowPos, iWindowWidth,
iWindowHeight, NULL, NULL, m_hInstance, NULL);
if (!m_hWindow)
return FALSE;
// Show and update the window
ShowWindow(m_hWindow, iCmdShow);
return TRUE;
This code is similar to the Skeleton program example found in Appendix C, and it should be familiar to you if you've done any Windows programming using the Win32 API. An important thing to note in this code is how it determines the game application window size, which is calculated based on the size of the game client area. The GetSystemMetrics() Win32 function is called to get various standard window sizes, such as the width and height of the window frame, as well as the menu height. The position of the game application window is then calculated so that the game is centered on the screen.

Copyright © 2009 virtualinfocom All rights reserved. Theme by Games. | animation Ani2Pix.