Skip to content
Gabor Szauer edited this page Aug 19, 2015 · 3 revisions

#Managers

There are 4 managers total, you will HEAVILY depends on these as they form the framework.

  • Graphcis Manager: Responsible for clearing the screen and flipping back buffers. Also can write strings to window.
  • Texture Manager: Responsible for loading drawing textures to the screen. Valid types: png, jpg and bmp
  • Sound Manager: Responsible for loading and playing sounds. Only Mp3 and Wav files are supported
  • Input Manager: Responsible for profiving a clean interfact to the mouse, keyboard and any connected joystick.

All of the managers are Singletons. They all have an Initialize and a Shutdown method. The Initialize method for every manager takes a OpenTK.GameWindow object as argument, this is the window that the selected managet will be bound to.

#Special Consideration The Texture Manager is special. It depends on functionality in Graphics Manager. Always Initialize the graphics manager BEFORE the Texture Manager.

The Inout Manager has an Update method. This has to be called once a frame, as the FIRST thing in that frame. Failure to do so will cause buffered input to break.

#Initialize / Shutdown Whatever order you intialize things in, you want to shut them down in the reverse order.

For example, if start looks like this

public void GameStart(OpenTK.GameWindow window) {
	GraphicsManager.Instance.Initialize(window);
	TextureManager.Instance.Initialize(window);
	SoundManager.Instance.Initialize(window);
	InputManager.Instance.Initialize(window);
}

Then your end function should look like this

public void GameEnd(OpenTK.GameWindow window) {
	InputManager.Instance.Initialize(window);
	SoundManager.Instance.Initialize(window);
	TextureManager.Instance.Initialize(window);
	GraphicsManager.Instance.Initialize(window);
}

#Reference Counting Both the TextureManager and SoundManager implement reference counting internally. Trough reference counting we manager to only load a texture one time, this can save a LOT of memory if there where multiple instances of the same texture.

How does it work? When an asset (texture or sound) is loaded we first check to see if it is already loaded. If it is, we add one to an integer counter. If it is not, we load it and set it's ref count to 1. An object is not eligable for deletion (grabage collection) until it's reference counter reaches 0;

For every asset load, the asset must be unloaded. If you forget to do so, the framework will warn you (in debug mode only)

#Internals TextureManager is the simplest, most straight forward manager to read trough. I've added extensive comments to the class. Try browsing TextureManager.cs for a bit, see if you can build up a mental model of how it works.

Clone this wiki locally