Advertisement

Handling Direct Input states in program

Started by November 15, 2000 01:26 AM
-1 comments, last by paulcoz 24 years, 1 month ago
Can you please give me your opinion on this: I have a program that gets input from the keyboard & mouse via an input.cpp file. A CheckForInput procedure is called every frame in my main program, and any clicks of the mouse, or movements of the mouse, or key presses, are dealt with by setting a bool value for each state eg. mousebuttondown, mousebuttonup, key w down, key g down etc.. These boolean values are then passed back to the main program (defined in input.cpp as externals initialised in main.cpp). Is this a normal way of handling direct input? I need to be able to do different things in different "modes" eg. key g in one mode does this, key g in another mode does something else. At the moment I am passing these boolean values back to the main program (and checking with a statement like if mode = 2 && if mousedwn then) and I would like your opinion on whether this is a sensible of doing it. I don't know whether to keep doing it like this: (1) Every frame, check for input: (a) if mouse button clicked, set mousedwn = TRUE (b) if key g up, set keygdwn = FALSE (2) In main program: (a) if mousedwn, and mode = 1, do this (b) if mousedwn, and mode = 2, do something else OR whether I should do it with code inside input.cpp: (1) Call CheckForInput procedure each frame with CheckForInput(mode): (2) In input.cpp CheckForInput procedure: (a) if mouse button down, and mode = 3, call correct procedure (b) if key g down, and mode = 2, call correct procedure Are these dumb ways of dealing with input or do other people do it this way too? The second way would certainly get rid of a lot of extern boolean variables, but it does make your direct input more messy, because you have code related to your different modes in the direct input file, and having it "hard-coded" makes it more of a bother to change later on, if you need to. Paulcoz. Edited by - paulcoz on 11/15/00 2:18:05 AM

This topic is closed to new replies.

Advertisement