multithreading - Writing a game loop for an ncurses game? -
i writing game ncurses , having trouble game loop. have read these 2 pages - this one, , this one several others linked via so, , can understand them (or @ least, can understand talking about, if not how solution works). problem have ncurses, sprites move 1 character step @ time, there no interpolation or integration, sprite.x=sprite.x+1
. tried using pthread , nanosleep , bad guy sprites move nicely player movement sluggish , unresponsive/unreactive. tried using 2 threads , having key input on 1 , game loop on thread key thread didn't @ all. so,how write smooth game loop ncurses?
the main problem key presses (not key releases) can detected running in vt100 style terminal emulator (as ncurses does). little akward games. either player has press keys repeatedly move (or wait until key autorepeats if keybord driver configured so). or can make game player presses key once begin move , presses key again (or key perhaps) stop (like in old sierra adventure games).
you making things more difficult using threads. instead use poll()
wait either input or next tick/scheduled event. not high precission, high resolution timing important games. using ncurses don't think need worry if timing few milliseconds off. can still keep steady calculating timeout this:
next_tick = last_tick + time_interval timeout = next_tick - now();
for smoother movement (especially if things move @ varying speed) can store coordinates higher precicion (for example using floats) , round them down low precision screen coordinates drawing.
Comments
Post a Comment