Sign in to follow this  
load_bitmap_file

Dealing with data from INI files and different types of input devices (2 questions)

Recommended Posts

1. In a typical INI file I see things like: default_player_name = "Omg wtf lol" initial_lives = 3 gravity = 9.81 point being that are multiple types of variables being assigned. So, I have a bunch of global consts like gravity, playerAttackVelocity, and playerLives which consist of different types, namely strings, floats, ints, and D3DXVector2s. I can parse out the variable name and the value as strings easily enough, but now I have to figure out what to do with it. How do programs typically deal with multiple types of variables when loading and assigning their values from INI files? The only thing I could think of so far is to have a std::map for each type of variable with the variable name as the key for each, and the value as a pointer of that type, e.g. std::map<std::string, float*>, std::map<std::string, std::string*>, etc and pass in the globals into the map and run through all of them to check for variable names and assign it that way. I'm hoping there's a more elegant solution though. 2. Do most games abstract their input devices so that there is one "KeyPressed" function that checks for whether a keyboard key or a mouse button or a joystick button is being pressed? I ask because when customizing controls, any PC game lets you assign any function to the keyboard or the mouse or the joystick. That means in my code I have to differentiate between each type of control, since I have separate input checking functions for the mouse/keyboard/joystick. Combining them all is a bit weird, any advice on how to correct this situation?

Share this post


Link to post
Share on other sites
1. Have you looked at boost::program_options ?

2. Don't know about modern games, but I can describe how I solved this in my engine.

I got my own wrapper for DX buffered input from mouse and keyboard. I define a type for calback function for button press/release, be it mouse or keyboard. Then there's always one active storage of functions (struct consisting of an array of 256 pointers for keyboard and 3 for mouse), that are being called when proper input is received. As game enters menu, or console, I can quickly switch for another storage (with function pointers properly reacting while game is in a 'in menu' state), not modifying the previous one at all.

So no, I do not have one input function "OnKeyPressed". Well, actually there is one, but it only redirects the flow to proper handles, it does not do any actual work itself, it dosn't even know if it's a game or text editor.

Share this post


Link to post
Share on other sites
2. What you meant to ask is, do programs abstract input and route it through a single interface rather than receiving it through three or more different interfaces? Most probably do, especially if they allow user-configuration of keys using any device attached to the system.

My own engine can receive input from two sources: the main form, or the input module, which uses DirectInput. If the input module has not been initialized, it defaults to form events, but in the end the virtual machine itself doesn't care where the input comes from. The VM has an input interface that receives and converts input to control codes (e.g., jump, shoot, activate) and passes those codes to the VM for processing. Input comes from any source, but in the end it all looks the same to the VM. The exception is with mouse input, which uses its own set of control codes but is otherwise routed in the same way.

Share this post


Link to post
Share on other sites

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

Sign in to follow this