Presentation is loading. Please wait.

Presentation is loading. Please wait.

02 | What DirectX Can Do and Creating the Main Game Loop

Similar presentations


Presentation on theme: "02 | What DirectX Can Do and Creating the Main Game Loop"— Presentation transcript:

1 02 | What DirectX Can Do and Creating the Main Game Loop
Michael “Mickey” MacDonald | Indie Game Developer Bryan Griffiths | Software Engineer/Game Developer

2 Module Overview Capabilities of DirectX 11 What’s New to DirectX 11
The IFrameworkView and Your App The Basic Game Loop The Update Stage The Rendering Stage

3 Capabilities of DirectX 11
Full featured set of APIs enabling you to create high-end 2D and 3D graphics applications/games. Direct 2D/Direct 3D: Handles graphics. DirectWrite: Handles text rendering features. DirectXMath: Provides handy functions for doing the math you love… ;) XInput: Replaces the old DirectInput API and helps you to provide console controller support. XAudio2: Replaces Direct Audio, allowing you to create a high performance audio engine while improving performance at the same time.

4 What’s New to DirectX 11 New shader pipeline stages:
Hull Shader Tessellator Domain Shader Allows for seamless LOD through dynamic tessellation.

5 What’s New to DirectX 11 Loosely coupled secondary pipeline:
Use of a compute shader allows the GPU to be used as a generic grid of data-parallel processors. It has explicit access to your GPUs faster memory banks. It can also do scattered reads and writes to memory. Allows engine developers to move CPU intensive operations to the GPU as a form of load balancing.

6 The IFrameworkView and Your App
The IFrameworkView class: The main interface class required for Windows Store apps. It controls the main event processing loop and maintains the overall state of the game. The DirectXApp class in the demo extends this interface for us. ref class DirectXApp : public Windows::ApplicationModel::Core::IFrameworkView { /* App code here! */ } But we also need a class to create the view…

7 The IFrameworkView and Your App
The DirectXAppSource class extends IFrameworkViewSource. Which is responsible for creating our view. ref class DirectXAppSource : Windows::ApplicationModel::Core::IFrameworkViewSource { public: virtual Windows::ApplicationModel::Core::IFrameworkView^ CreateView(); }; IFrameworkView^ DirectXAppSource::CreateView() return ref new DirectXApp(); }

8 The IFrameworkView and Your App
As usual the main function kicks everything off. It creates an instance of our source class. Then it instructs the CoreApplication singleton class to run the instance. This starts a process which ends in the creation and initialization of your view class. [Platform::MTAThread] int main(Platform::Array<Platform::String^>^) { auto directXAppSource = ref new DirectXAppSource(); CoreApplication::Run(directXAppSource); return 0; }

9 The IFrameworkView and Your App
What dos the DirectXApp class do? Drives and maintains the main state machine for the game. Creates and maintains three important references to the three major objects used in the game: MoveLookController – handles the input. SumoDX – handles the game’s logic and physics. GameRenderer – renders the game’s objects to the screen. It also registers and responds to the necessary Windows Store app events that may occur over the course of the game.

10 The Basic Game Loop Lets take a look at the pseudo-code for a basic game loop. while the window is active if the window is visible if the game can’t function do to size, or a pop-up, or is simply paused wait for a new event that changes the state of the app. else do the normal processing of incoming messages. update the state of the game and carry out associated actions for that state. then get an updated rendering of the current screen. Process events until we are the visible window. Exiting due to window closing. Make sure to save the game’s state.

11 Taking a walk through the DirectXApp class.

12 The Update Stage The Update function of the game loop is where the majority of your game’s logic and state control will occur. It will handle the initial loading and intro sequences as your game boots up. It will handle transitions between levels, in-game menus and other situations that interrupt the game play such as pop-up messages. It will be responsible for updating the controller, which listens for the player’s input. Most importantly it will be responsible for updating the state of the game world and all of the objects in it.

13 What’s in the DirectXApp’s Update function.

14 The Render Stage After the game has finished its Update stage it moves into the Rendering stage. The render stage can be broken up into various parts depending on the complexity of the visuals required by the game. Some systems require multiple passes for advanced effects like dynamic shadows, x-ray vision and thermal vision. Some systems also require that every other visit to the rendering system alternates between two slightly different camera positions in order to support stereoscopic games.

15 The Render Stage The steps of a basic game rendering stage:
Set where/what you are rendering too. (back buffer, a texture, etc.) Clear the “screen”, if required/desired. Render your 3D objects. Render your HUDs/2D graphics. Render any pop-up or device message warnings. Present the image to the display. In the demo we created a class called GameRenderer to handle all of this for our DirectXApp via its Render() function.

16 What takes place during the Demo’s render stage.

17


Download ppt "02 | What DirectX Can Do and Creating the Main Game Loop"

Similar presentations


Ads by Google