1 / 20

The Art of Computer Science Part II

The Art of Computer Science Part II. Bill Klinger – RVCC Computer Science Dept. The Art of Computer Science. Architecture structure of the processes interaction of the processes Algorithms clever efficient Making the electrons dance We will examine the “art” of a computer game.

Download Presentation

The Art of Computer Science Part II

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Art of Computer SciencePart II Bill Klinger – RVCC Computer Science Dept.

  2. The Art of Computer Science • Architecture • structure of the processes • interaction of the processes • Algorithms • clever • efficient • Making the electrons dance • We will examine the “art” of a computer game

  3. Sockets and Threads in Action

  4. The Art of Computer SciencePart II • Art in Algorithms • real-time problems and solutions • Examples • collaborative Pong • collaborative Driving

  5. Homework • How do we keep users in synch when the timing intervals are much smaller than potential variances? • In a driving game, we move ahead by advancing frames based upon our speed. Given: n = frame drawings per second m = max speed of car (in mph) s = current speed of car (in mph) What algorithm should we use to draw the frames?

  6. Problems in Real-time Games • Need to keep the action going • But • there is network delay • PCs run at different speeds • may be other activity on a PC • PCs will get out of synch

  7. Multi-user Pong

  8. Dead Reckoning • Definition • A method of estimating the position of an craft without astronomical observations, as by applying to a previously determined position the course and distance traveled since. • Predictive calculation based on inference; guesswork

  9. Dead Reckoning in Pong • Predict future position based upon last position and action • know ball x, y, dx, dy • know paddle y, dy • bounce off walls and paddles • Adjust, if necessary, when get new info • Problem – how to do this when listening to server and user? • another thread

  10. The Electrons Dancing

  11. Let’s Try It • Keep in mind • Threads that get your input • Threads that listen to the server • Threads that move • Sockets • Pong Exercise • login with guest name and password • go to Academic Departments • go to Computer Science • click on William Klinger faculty link • click on Participant Material on lower left side of page • click on Pattern Exercise

  12. Art in Algorithms - 3 • Problem: how to advance the frames to show the speed of a car?

  13. Art in Algorithms - Speed • We update the graphics n times per second • But we don’t advance the frames on each update • if at half speed, update every other frame • if at quarter speed, update one cycle, skip three cycles • if at three-fourths speed, update three cycles, skip one

  14. Speed % of #CYCLES #CYCLES MAXSPEEDADVANCINGNOT MOVING 0 0 all 20% 1 4 25% 1 3 33% 1 2 50% 1 1 66% 2 1 75% 3 1 80% 4 1

  15. How Long to Wait? • Let: c = cycles per second (game loops) s = speed m = max speed w = number of cycles not moving • Then w = total cycles waiting / total cycles moving w = [ c * (1 – (s / m ) ) ] / [ c * (s / m) ] w = (1 – (s / m ) ) / (s / m) w = ( m / s ) - 1 c’s cancel multiply num and denom by m / s

  16. The Speed Formula • If speed < .5 max speed max speed # wait cycles = speed - 1 • If speed >= .5 max speed 1 # adv cycles = # wait cycles Note this is independent of the # cycles per second!

  17. Speed Algorithm countCycles++; if( speed < (MAXSPEED / 2 )) { // the algorithm is to wait waitcycles times waitCycles = (MAXSPEED / speed) - 1 ; if( countCycles > waitCycles ) { // waited enough cycles now advance the car countCycles = 0; countMoves = 1; trackLoc++; } // end if - no else - don't advance the car } // end moving if .5 maxspeed

  18. More Speed // the speed is .5 maxspeed domoves = 1.0 / ((MAXSPEED / speed) - 1 ); if( countmoves <= domoves) { // advance the car countmoves++; countcycles = 0; trackLoc++; } // end if advancing else { // pause a frame and reset countcycles = 0; countmoves = 0; }

  19. I Feel the Need for Speed • Think about • threads listening to your input • threads listening to the server • threads moving the car • server threads sending moves • Driver Exercise • go back to Participant Material • click on Driver Exercise

  20. The Art of Computer Science • You can admire the graphics • You can read the code • Some art lives where you can’t see it

More Related