Sunday 29 September 2013

Flaws Of Object Centric Programming



When thinking about how to create a game’s framework from a high level, we will see that there things that have similar features. From this we group them other, and assign them all to inherit from 1 parent. This can be seen in many games and can be applied the simple game of pack man as shown to the left. This way of thinking for programming is called object centric programming, due to the fact there is a lot of polymorphism, resulting in the huge “is a” chain.



However there are many flaws to this way of programming, which could be devastating for large scale games. When drawing the UML diagram, we can predict a big list to form due to the huge chain of inheritance. From this we can predict that this method will be inefficient, whenever we create a single object we must also create a version of the parent in the memory. If that parent also had a parent, we would have to save some memory for that. Double Polymorphism, is another problem which can cause HUGE errors if done, one case is shown in the chart to the right. Finally if every class in the chain was modified and this resulted in errors, the question comes up, where would the source of these errors be?

In the end we learn that this is one of the framework patterns which has issues with some games. We must be careful and plan how to program games ahead of time so that we won’t run into issues like that.
In short you should have double polymorphism also known as the the criss crossing diamond.

Wednesday 25 September 2013

Battlefield3/Frostbite 2.0+ Havok(physics engine)




One of the first demos I played on my PS3 was 2008's Battlefield:Bad Company, and I LOVED IT! Not only was there a fun atmosphere, a great multiplayer, with big maps, classes and vehicles. Although nothing came close to experience the beautiful frostbite engine's destruction for the first time. In its debut game, the frostbite engine did destruction that few other games could do in its time. Today its one of the most powerful engines in the industry, and a engine of choice for Electronic Arts.
To my surprise this powerful engine uses Havoc to handle all of its crazy physics. The Havoc physics engine widely used in the gaming industry and is used as a middle-ware for physics. This blog will focus on Frostbite version 2.0, which premiered in the highly popular game Battlefield 3.

Battlefield 3 One of the more popular shooters of today, mostly due to its large scale battles of its multiplayer. These matches can reach up to 64 players, and take place in maps up to 5 Kilometer square. The player has access to many gadgets, to the dozens of vehicles, and a ton of guns, all spread out over 4 special classes. With-in the sqauds of 4 teamwork is encouraged, and makes the game fun with friends.  One of the game changing events, is the destruction featured in majority of the buildings.

HavokHavok is only used for physics (and not cloth physics) ever since Battlefield bad company 2, since the animation is using the ANT systems from EA’s sports franchises .

Wall debris 

Whether it be just a simple pillar, to a full concrete wall, you will see chunks of it fly off when you shoot at it. This is especially true if you fire a rocket at a wall, and the debris will fly outwards from the explosion. Sometimes of the debris will be rotating outwards based on the centre of the object, and where the force is applied. Some debris will hit the group on its side, and roll away until it stops on its side. With this, just shooting a simple tiled wall can be graphically amazing, just look at the gif below.

Whole buildings 

When the whole building collapses, you can see every bit of wall crumble. Like above, you can see rubble tumbling outwards from the building, however sometimes the rubble will stay inside the building. The roofs will instantly lose support, and being accelerating the ground. Also when the roofs will split and rebound off the rubble, depending on how much rubble is already on top. Seeing a building collapse in battlefield was a sight for sore eyes.

“Bullet drop” for missiles and projectiles 

With the concept of bullet drop, a simple application of gravity on to the bullet. This concept is also applied to tank shells, grenade launchers, and regular missiles. Also with long ranged projectiles, they have a form of traveling distance associated with them, it takes estimation to hit with them. Theoretically is can be managed easily, however this will be done with all the projectiles of 64 players, and all the destruction occurring.
With the large battlefields snipping can be challenging at times

Driving Vehicles 

When driving vehicles, there are physics involved with handling the vehicle. Some land vehicles will have a suspension based wheels, so you will bounce and land after flying throw the air. Helicopters seem to have a gyroscope system, where the vehicle will accelerate dependant on the rotation of the copter. Jets can perform crazy acrobatic moves such as loops, corkscrews and will stall if they fly too high.
The cock pit of airplanes can be confusing with all the angles along each tilt being displayed
Sometimes the physics allows for some silly vehicular mayhem. For example when you destroy a fast moving jeep/jet, its main body will still exist and retain the velocity which it was at. This is has resulted in the death of hundreds of players including me. A more hilarious approach is launching a light vehicle with explosives, with friends. This will require a lot of explosives, and correct vehicle positioning. If vehicle is too far from the pile of explosives, this will just push the vehicle forward. Done right and you will have a very nice view of the battlefield, for about 5 seconds.

Conclusion

            All the physics for Battlefield 3 combined with the amazing animation, graphics, and amount of content makes Battlefield 3 a great game. With this the frostbite engine 2.0 was a great iteration of the engine utilizing Havoc and other technology/techniques. In the end, Frostbite 2.0 was originally designed forthe “next generation” of consoles, although a Frostbite 3.0 is close to completion right now. With Battlefield 4 almost a month away, I'm honestly excited to see what the Frostbite 3.0 engine will do.


Saturday 21 September 2013

Design Patterns For Game Engine Programming.



            When looking back at my second year code, I wondered how I could improve its readability and efficiency. Then comes along this week’s lecture about design patterns to help us streamline our code, making it neater and better. My mind was blown, as these patterns could be applied to any form of software design, and maybe even more... Well let’s not go there, but wrapping my head around it (with wrappers) this was an excellent way to start our game for this year. From the lecture we learned about ways to design our code with patterns to accomplish this. 3 main design patterns stood out for me: Singleton, state, and factory, all which had a unique use.

Singleton- one class to manage

            Personally I can see this as a great way to save on memory, and organize your code a lot more! As you can guess, this design pattern involves have only a single instance of this object. This pattern is designed so that these objects will just have one memory address, and any other instance of it will just be a reference to this memory.
This pattern good for any sort of manger class, a general class which will manage a specific subsystem. Similar to managers, in real life they manage a department, and will report to any higher management. However these “departments” can also report to other “departments” and access their information if needed. A good example of a manger class would be for physics, as there should only be one class to handle all the physics within the scene. With that class, we may have an animation manager which will need some physics information for it to animate.  With this approach, subsystems communicating to each other can be streamlined, so data can flow through our game much easier.

State- a class to think

            Indirectly used in my last year game, the state pattern is versatile, and can be used as a “brain” in games. The state pattern involves having different states for an object, each giving it a different attribute. The state will only change if a certain condition (or two) is meet at a specific time. Generally a state would be represented by an enum, saved as a number variable but defined as a readable word in code.

 One great use of the state pattern is for AI, where an enemy can be set to anything from patrolling to pursing. When spawned an enemy would probably be on the patrol state, moving on a specific route until it “encounters” the player. When this happens, the enemy would change its state to purse, which would result in different behavior. This could range from a change in movement pattern (locomotion), a visual change (aesthetics or animation) or even a simple change in variables. This process will keep repeating until the enemy is dead, or the game is over.

            However the state pattern can be used for other game uses, such as is the weapon states as in doom 3. Looking at the weapon code, a weapon will have 20 possible states, ranging from holstered, reloading, to “owner died”! Each state will not just affect the weapon, but also many areas of the player. For example when the weapon is being raised, due to switching, the raising animation will affect the player’s character. Also elements of the HUD will have to be altered, due to different weapon attributes.  With the state pattern, a lot of “detail and depth” can transition from thought to the game.

Factory- a class to construct!

            If you tire of having to see different objects being made in the main code, the factory class can help you stream line. Like in any factory, it can create any thing as long as you give it the right plan and materials. In code this is basically making it inherit other class so it can make them. The point of the factory class is to allow for it to create objects of a similar type, allow for a great deal of organization.  

            One example of this last year was my enemy class, which used a similar and cruder version of this. All enemies would be created as that one initialize function, and from there they would appear in the game a wreck havoc on the player. So how would I tell the class which enemy to spawn to?  Simple give in an integer to tell which enemy for it to spawn, and all the inherited values from the other object should do the rest! This was possible since the class would inhert from my other enemy classes which I constructed earlier.

Conclusion

Designing code is a high level concept which if done right can make all the down and dirty work much easier. With these 3 software designs implemented in your game properly, you can navigate your code much easier now and hunt down those bugs easier! Don't stop with just using 3 patterns, there are dozens of them out there of solve problems which you won't have even thought of yet. In doing so, your teacher won’t have to pull a hair or two just looking at a wall of code,  and could save you a possible fail.

Sunday 15 September 2013

Which Game Engine be used?


            This week we quickly went over which engine you would want to choose, if you were to develop a game. You must keep in mind what type of game you want to make, and what constraints you have. These constraints could range from budget, type of game, and team experience, such as if you have more programmers than artists or vice versa. From this you can determine which engine is best suited for your game or if you should make your own.

First fact which you must acknowledge, every engine is made for a specific genre of game and NEVER every single game. Some engines in the industry today is usually developed and launched alongside a flagship game. A couple examples are Half Life 2 and Source, Gears of War and Unreal 3, StarCraft 2 and its engine. Despite all these engines and their flexibility in creating games of multiple genres, they weren’t made to do this. For example creating a 2D based platformer with the Source engine would be a nightmare, due to the fact it is well made for 3d models.
 When making a game, developers will also look at other options, such as making their own engine out of smaller engines or free software. This software could range from a simple free math library, to render engines such as OGRE, to even free engines such as WildMagic. Generally making your own engine from scratch would be a good idea for a simple 2D game, like for simple indie games like Super Meat Boy and Mark of the Ninja. However when it comes a 3d game, you will have to determine whether to use an expensive existing engine, or you create your own/modify one with existing software. In the end it will come down to the features and scope of the game which you have planned.
In class we compared game engines to a real life car engine, and discussed what it does for the car. An engine is something which brings all the parts of the car together and all them to function together as 1 system. Because of this, the engine which you use must be coherent with the function of the car. One question asked is, would you use a Ferrari engine in a Honda car? No, first off you have to modify the car use this powerful car engine, which is time consuming and unwanted. Second the Ferrari engine is an expensive engine, while the Honda brand is made to be a not as expensive brand of vehicles.

Sunday 8 September 2013

GDW3- Design Idea

 The following is a design idea for our upcoming game which we will make for this year. We may not follow this document exactly, however elements from this idea may be incorporated into the final game.
Game Type- survival

Game premise- you are placed in a strange arena one which will test your strength and skills. In this arena you will fight enemies of each element using weapons which specialize in each element. 

Gameplay mechanics
            Hostile arena –Even though the user will be in 1 area only, we will have so that it will change with each wave. No wave will be the same as the other wave.
·         Elemental enemies- each enemy will have to type of element which they will embody. With these elements they will have ones which "counter" their element and be super effective, while some other elements may enhance the enemy rather than damage them. 
       Mix and match- With each elemental weapon for the player, they will have special effects to the enemies. The player can use different weapons on each enemy to have multiple effects on it.

Shaders needed
  •  (MAIN)GPU based Particles- With all the elements, you cannot simply represent them by texture, and we want to apply it to multiple objects. To do this we have to have to make particles and make a lot of them.
  •   Mesh skinning- with this year we will need to create moving models which will need to be rigged and moving. 
  •    Deferred rendering – Lighting will be required with with some of the effects, such as fire, light, and maybe even used with the darkness.
  • Toon shading – If the game wants to have a “zany” toon feeling then we will need some form of toon shading in. Here we will need a edge detection and cel shading/lighting to be applied to all the models.
The elements
  •  Fire- close and good for crowd clearing
  • Ice- precise and far range
  •  Light- precise and fast
  •  Dark –good for crowd clearing and slower
  • Earth (posion)
  • Air( Earth counter) 
Possible references/influences 

Dungeon defenders: Similar in concept to our game, with survival, elemental magic and its toon looks. This may be a heavy influence if we decide to go for the med-evil/magical influence.  Also the gameplay could be similar if we decide to make it 3rd person.
League of Legends: In this case it just be purely visual, however with over 100 champions, there is a wide range of effects which we can look at.
Also if our game is isometric, we may have a cadiate for our game should look.





Borderlands 2: This game may be good if we decide to set our game in a sci-fi cartoony universe. Not only do they have over a dozen enemies to draw influence from, but also a ton of guns which we can get some influence from. Its bright and colorful art palet is right for the game, and we also have access to the art book too ;D



Rachet and Clank: If we decide to set our game in a sci-fi universe, this would be a good game to look at. The PS2 game would be a nice point of reference, and they have some great multiplayer ideas.  Also if we decide to make the player use wacky elemental based weapons, this would be a good influence.







There is no doubt if we were to follow this idea, it would be an ambitious undertaking. There would be durastic changes to this idea to fit our time constraints, and alot of content cutting to be done. We will see by the end of this semester, or this April, if we can make a game of a similar style or .