Sign in to follow this  
  • entries
    33
  • comments
    51
  • views
    12552

Foundations

Sign in to follow this  
Metorical

23 views

Throwing together the basics to get the Blockwars (Robotron?) clone going as seen below was fairly straight forward with the SDL Library however going forward I want to integrate it with my foundation framework. I have no illusions of grandeur here, at least yet, but there are some fundamentals I have to put together.

Designing a Controller Manager

It's very easy to read the state of various controllers with the SDL events. Whenever the state changes an event is fired and you just have to filter through it to figure out what type of event it is, what it's updating and the new value.

My first crack at using it was very straightforward, I read the new state and then updated the Player Object. This worked fine and dandy 100% but something doesn't sit well when my event loop needs to know about my Player Object.

I decided to build a ControllerManager and Controller class.

Classes

1. The ControllerManager stores a list of Controllers connected to the system and is responsible for dishing them out.

2. The Controller Class defines the interface between the Controller and the Object being controlled. In this case I defined a controller to have 4 axis (e.g. 2 analog sticks) and 4 buttons.

3. I use inheritance to define specific controllers e.g. "XBox-360 Gamepad" or "Keyboard and Mouse" which implement the interface of the Controller.

The idea being that when the game starts I can initialise the ControllerManager which will detect all connected devices, create a Controller of the right sub-class and then pass on the events to the correct controller.

Interfacing with the Controller

From the standard interface defined in the Controller Class I can read the state of the pad. I've added an Updated member so that I only have to read it if the state changes to avoid excessive polling too. My issue lies in how to build the relationship between Player Object and Controller Object.

1. A Player Object has a Controller Object. I include a pointer to the Controller (retrieve from the ControllerManager) then on each Update I check to see if there's been an Update and if there has I update the state.

2. A Controller Object has a Player Object. I include a pointer to the Player Object and define a standard interface on all Playable Objects. When the event is triggered I can update to the Player Object.

3. Another option?

Your comments would be appreciated.
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now