1 #include <time.h> 2 #include <sys/time.h> 3 #include <unistd.h> 4 5 6 #include "globals.h" 7 #include "star.h" 8 #include "sizes.h" 9 #include "network.h" 10 #include "netvariables.h" 11 #include "readserverthread.h" 12 #include "blit.h" 13 #include "timevar.h" 14 #include "thread.h" 15 #include "object.h" 16 #include "ship.h" 17 #include "screen.h" 18 19 20 int BoomDelay; 21 int NextBoom; 22 int BoomPhase; 23 pthread_t readthread; 24 int GameStop; 25 26 27 void NewGame(); 28 void RunGame(); 29 void DoHouseKeeping(); 30 void InitGame(); 31 32 NewGame()33void NewGame() 34 { 35 struct timezone tz; 36 37 // Connect to game server 38 if (ConnectServer()) { 39 return; 40 } 41 42 InitGame(); 43 44 gettimeofday(&LastTime, &tz); 45 gettimeofday(&UpdateTime, &tz); 46 } 47 48 RunGame()49void RunGame() 50 { 51 ClearScreen(); 52 Setup3dMode(); 53 54 if (Ships[myShip]) { 55 DrawStars(); 56 } 57 58 RunFrame(); 59 60 UpdateScreen(); 61 } 62 63 InitGame()64void InitGame() 65 { 66 int i, rc; 67 68 GameStop=0; 69 ShowScore=0; 70 ReverseView=0; 71 72 pthread_mutex_lock(&ClientLock); 73 74 // Create a thread to listen for data from the server and update game data 75 if (rc = pthread_create(&readthread, NULL, ReadServerThread, 76 (void *)svrsock)) { 77 printf("ERROR, return code from pthread_create() is %d\n", rc); 78 pthread_exit(NULL); 79 } 80 81 BoomDelay = 800/FRAME_DELAY; 82 NextBoom = BoomDelay; 83 BoomPhase = 0; 84 } 85