Changeset 85
- Timestamp:
- Mar 6, 2008, 2:06:58 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
abuse/trunk/src/game.cpp
r76 r85 1 1 /* 2 * Abuse - dark 2D side -scrolling platform game2 * Abuse - dark 2D side - scrolling platform game 3 3 * Copyright (c) 1995 Crack dot Com 4 4 * … … 9 9 10 10 #include "config.h" 11 12 //#ifdef __POWERPC__13 //#include <profiler.h> //prof14 //#endif15 11 16 12 #include <ctype.h> … … 65 61 extern void show_verinfo(int argc, char **argv); 66 62 game *the_game; 67 window_manager *eh =NULL;68 int dev, shift_down=SHIFT_DOWN_DEFAULT,shift_right=SHIFT_RIGHT_DEFAULT;69 double sum_diffs =1,total_diffs=12;70 int total_active =0;71 int32_t map_xoff =0,map_yoff=0;72 int32_t current_vxadd, current_vyadd;73 int frame_panic =0,massive_frame_panic=0;74 int demo_start =0,idle_ticks=0;75 int req_end =0;63 window_manager *eh = NULL; 64 int dev, shift_down = SHIFT_DOWN_DEFAULT, shift_right = SHIFT_RIGHT_DEFAULT; 65 double sum_diffs = 1, total_diffs = 12; 66 int total_active = 0; 67 int32_t map_xoff = 0, map_yoff = 0; 68 int32_t current_vxadd, current_vyadd; 69 int frame_panic = 0, massive_frame_panic = 0; 70 int demo_start = 0, idle_ticks = 0; 71 int req_end = 0; 76 72 77 73 extern palette *old_pal; 78 74 char **start_argv; 79 75 int start_argc; 80 int has_joystick =0;76 int has_joystick = 0; 81 77 char req_name[100]; 82 78 … … 85 81 extern int confirm_quit(); 86 82 87 #if 83 #if(defined(__APPLE__) && !defined(__MACH__)) 88 84 extern char *macify_name(char *s); 89 85 #endif … … 95 91 FILE *open_FILE(char const *filename, char const *mode) 96 92 { 97 /* char *prefix=get_filename_prefix() ? get_filename_prefix() : "",*c; 98 99 if (get_save_filename_prefix) 100 { 101 for (c=mode;*c;c++) 102 if (c=='w' || c=='W') 103 { 104 } 105 } */ 106 107 108 char tmp_name[200]; 109 if (get_filename_prefix() && filename[0] != '/') 110 sprintf(tmp_name,"%s%s",get_filename_prefix(),filename); 111 else strcpy(tmp_name,filename); 112 #if (defined(__APPLE__) && !defined(__MACH__)) 113 macify_name(tmp_name); 93 /* FIXME: potential buffer overflow here */ 94 char tmp_name[200]; 95 if(get_filename_prefix() && filename[0] != '/') 96 sprintf(tmp_name, "%s %s", get_filename_prefix(), filename); 97 else 98 strcpy(tmp_name, filename); 99 #if(defined(__APPLE__) && !defined(__MACH__)) 100 macify_name(tmp_name); 114 101 #endif 115 return fopen(tmp_name,mode);102 return fopen(tmp_name, mode); 116 103 } 117 104 … … 119 106 void handle_no_space() 120 107 { 121 char const *no_space_msg = 122 "\nYou are out of disk space or the game\n" 123 "was unable to write to disk for some reason\n" 124 "The game cannot continue, please check this out\n" 125 "and try again.\n"; 126 if (eh) 127 { 128 jwindow *no_space=eh->new_window(0,0,-1,-1, 129 new button(WINDOW_FRAME_LEFT,WINDOW_FRAME_TOP,ID_QUIT_OK,"Quit", 130 new info_field(WINDOW_FRAME_LEFT,WINDOW_FRAME_TOP+eh->font()->height()*2,ID_NULL, 131 no_space_msg,NULL)),"ERROR"); 108 static char const *no_space_msg = 109 "\nYou are out of disk space or the game\n" 110 "was unable to write to disk for some reason\n" 111 "The game cannot continue, please check this out\n" 112 "and try again.\n"; 113 114 if(!eh) 115 { 116 fprintf(stderr, "%s\n", no_space_msg); 117 exit(0); 118 } 119 120 info_field *inf = new info_field(WINDOW_FRAME_LEFT, WINDOW_FRAME_TOP + 121 eh->font()->height() * 2, ID_NULL, 122 no_space_msg, NULL); 123 button *b = new button(WINDOW_FRAME_LEFT, WINDOW_FRAME_TOP, 124 ID_QUIT_OK, "Quit", inf); 125 jwindow *no_space = eh->new_window(0, 0, -1, -1, b, "ERROR"); 126 132 127 event ev; 133 do 134 { 135 eh->flush_screen();136 eh->get_event(ev);137 } while (ev.type!=EV_MESSAGE || ev.message.id!=ID_QUIT_OK);128 do 129 { 130 eh->flush_screen(); 131 eh->get_event(ev); 132 } while(ev.type != EV_MESSAGE || ev.message.id != ID_QUIT_OK); 138 133 eh->close_window(no_space); 139 134 140 135 close_graphics(); 141 136 exit(1); 142 } else143 {144 fprintf(stderr,"%s\n",no_space_msg);145 exit(0);146 }147 137 } 148 138 149 139 void game::play_sound(int id, int vol, int32_t x, int32_t y) 150 140 { 151 if( sound_avail & SFX_INITIALIZED ) 152 { 153 if( vol < 15 ) 154 return; 155 if( !player_list ) 156 return; 157 158 uint32_t mdist = 0xffffffff; 159 view *cd = NULL; 160 for( view *f = player_list; f ; f = f->next ) 161 { 162 if( f->local_player() ) 163 { 164 int32_t cx = abs(f->x_center()-x),cy = abs(f->y_center()-y), d; 165 if( cx < cy ) 166 d = cx + cy - ( cx >> 1 ); 167 else 168 d = cx + cy - ( cy >> 1 ); 169 170 if( (unsigned)d < mdist ) 171 { 172 cd = f; 173 mdist = d; 174 } 175 } 176 } 177 if( mdist > 500 || !cd ) 178 return; 179 if( mdist < 100 ) 180 mdist = 0; 181 else 182 mdist -= 100; 183 184 int v = ( 400 - mdist ) * sfx_volume / 400 - ( 127 - vol ); 185 186 // Calculate the position of the sound relative to the player 187 int p = cd->x_center() - x; 188 if( p > 0 ) 189 p = (int)( ( (double)p / 255.0 ) * 128.0 ); 190 else 191 p = (int)( ( (double)abs(p) / 255.0 ) * -128.0 ); 192 p+=128; 193 if( p < 0 ) p = 0; 194 if( p > 255 ) p = 255; 195 196 if( v > 0 ) 197 cash.sfx(id)->play( v, 128, p ); 198 } 141 if(!(sound_avail & SFX_INITIALIZED)) 142 return; 143 if(vol < 15) 144 return; 145 if(!player_list) 146 return; 147 148 uint32_t mdist = 0xffffffff; 149 view *cd = NULL; 150 for(view *f = player_list; f; f = f->next) 151 { 152 if(f->local_player()) 153 { 154 int32_t cx = abs(f->x_center()-x), cy = abs(f->y_center()-y), d; 155 if(cx < cy) 156 d = cx + cy - (cx >> 1); 157 else 158 d = cx + cy - (cy >> 1); 159 160 if((unsigned)d < mdist) 161 { 162 cd = f; 163 mdist = d; 164 } 165 } 166 } 167 if(mdist > 500 || !cd) 168 return; 169 if(mdist < 100) 170 mdist = 0; 171 else 172 mdist -= 100; 173 174 int v = (400 - mdist) * sfx_volume / 400 - (127 - vol); 175 176 // Calculate the position of the sound relative to the player 177 int p = cd->x_center() - x; 178 if(p > 0) 179 p = (int)(((double)p / 255.0) * 128.0); 180 else 181 p = (int)(((double)abs(p) / 255.0) * -128.0); 182 p += 128; 183 if(p < 0) p = 0; 184 if(p > 255) p = 255; 185 186 if(v > 0) 187 cash.sfx(id)->play(v, 128, p); 199 188 } 200 189 201 190 int get_option(char const *name) 202 191 { 203 204 for( i = 1; i < start_argc; i++)205 206 if( !strcmp( start_argv[i], name ))207 208 209 210 211 192 int i; 193 for(i = 1; i < start_argc; i++) 194 { 195 if(!strcmp(start_argv[i], name)) 196 { 197 return i; 198 } 199 } 200 return 0; 212 201 } 213 202 … … 215 204 void make_screen_size(int w, int h) 216 205 { 217 for( view *f = player_list; f; f = f->next)218 219 if( f->local_player())220 { 221 if( (unsigned)w >= xres - 1 ) 222 w = xres - 2; 223 if( (unsigned)h >= yres - 1 ) 224 h = yres - 2; 225 f->suggest.cx1 = ( xres + 1 ) / 2 - w /2;226 f->suggest.cx2 = ( xres + 1 ) / 2 +w / 2;227 f->suggest.cy1 = ( yres - 31 ) / 2 + 5 - h/ 2;228 f->suggest.cy2 = ( yres - 51 ) / 2 + 5 +h / 2;229 f->suggest.shift_down = f->shift_down;230 f->suggest.shift_right = f->shift_right;231 f->suggest.pan_x = f->pan_x;232 f->suggest.pan_y = f->pan_y;233 f->suggest.send_view = 1;234 } 235 206 for(view *f = player_list; f; f = f->next) 207 { 208 if(!f->local_player()) 209 continue; 210 211 if((unsigned)w >= xres - 1) 212 w = xres - 2; 213 if((unsigned)h >= yres - 1) 214 h = yres - 2; 215 f->suggest.cx1 = (xres + 1) / 2 - w / 2; 216 f->suggest.cx2 = (xres + 1) / 2 + w / 2; 217 f->suggest.cy1 = (yres - 31) / 2 + 5 - h / 2; 218 f->suggest.cy2 = (yres - 51) / 2 + 5 + h / 2; 219 f->suggest.shift_down = f->shift_down; 220 f->suggest.shift_right = f->shift_right; 221 f->suggest.pan_x = f->pan_x; 222 f->suggest.pan_y = f->pan_y; 223 f->suggest.send_view = 1; 224 } 236 225 } 237 226 238 227 void game::grow_views(int amount) 239 228 { 240 view *f=first_view; 241 for (;f;f=f->next) 242 { 243 if (f->local_player()) 244 { 245 f->suggest.cx1=(f->cx1-amount); 246 f->suggest.cy1=f->cy1-amount/2; 247 f->suggest.cx2=(f->cx2+amount); 248 f->suggest.cy2=f->cy2+amount/2; 249 f->suggest.shift_down=f->shift_down; 250 f->suggest.shift_right=f->shift_right; 251 f->suggest.pan_x=f->pan_x; 252 f->suggest.pan_y=f->pan_y; 253 254 f->suggest.send_view=1; 255 } 256 } 257 258 259 for (f=first_view;f;f=f->next) 260 { 261 if (f->local_player()) 262 { 263 if (f->suggest.cx2-f->suggest.cx1<20 || f->suggest.cy2-f->suggest.cy1<15 || 264 f->suggest.cx1<0 || f->suggest.cy1<0) f->suggest.send_view=0; 265 if (f->next && f->next->local_player() && f->suggest.cy2>=f->next->cy1) f->suggest.send_view=0; 266 } 267 } 268 } 269 270 void game::pan( int xv, int yv ) 271 { 272 first_view->pan_x += xv; 273 first_view->pan_y += yv; 229 view *f; 230 231 for(f = first_view; f; f = f->next) 232 { 233 if(!f->local_player()) 234 continue; 235 236 f->suggest.cx1=(f->cx1 - amount); 237 f->suggest.cy1 = f->cy1 - amount / 2; 238 f->suggest.cx2=(f->cx2 + amount); 239 f->suggest.cy2 = f->cy2 + amount / 2; 240 f->suggest.shift_down = f->shift_down; 241 f->suggest.shift_right = f->shift_right; 242 f->suggest.pan_x = f->pan_x; 243 f->suggest.pan_y = f->pan_y; 244 245 f->suggest.send_view = 1; 246 } 247 248 for(f = first_view; f; f = f->next) 249 { 250 if(!f->local_player()) 251 continue; 252 253 if(f->suggest.cx2 - f->suggest.cx1 < 20 254 || f->suggest.cy2 - f->suggest.cy1 < 15 255 || f->suggest.cx1 < 0 || f->suggest.cy1 < 0) 256 f->suggest.send_view = 0; 257 258 if(f->next && f->next->local_player() 259 && f->suggest.cy2 >= f->next->cy1) 260 f->suggest.send_view = 0; 261 } 262 } 263 264 void game::pan(int xv, int yv) 265 { 266 first_view->pan_x += xv; 267 first_view->pan_y += yv; 274 268 } 275 269 276 270 view *game::view_in(int mousex, int mousey) 277 271 { 278 for (view *f=first_view;f;f=f->next) 279 if (f->drawable() && mousex>=f->cx1 && mousey>=f->cy1 && mousex<=f->cx2 && mousey<=f->cy2) 280 return f; 281 return NULL; 272 for(view *f = first_view; f; f = f->next) 273 if(f->drawable() && mousex >= f->cx1 && mousey >= f->cy1 274 && mousex <= f->cx2 && mousey <= f->cy2) 275 return f; 276 return NULL; 282 277 } 283 278 284 279 int playing_state(int state) 285 { 286 if (state==RUN_STATE || state==PAUSE_STATE) return 1; 287 else return 0; 280 { 281 return state == RUN_STATE || state == PAUSE_STATE; 288 282 } 289 283 290 284 void game::ftile_on(int screenx, int screeny, int32_t &x, int32_t &y) 291 285 { 292 mouse_to_game(screenx,screeny,x,y); 293 x/=ftile_width(); 294 y/=ftile_height(); 295 /* view *f=view_in(screenx,screeny); 296 if (f) 297 { 298 x=((int32_t)(screenx)-(int32_t)f->cx1+f->xoff())/(int32_t)f_wid; 299 y=((int32_t)(screeny)-(int32_t)f->cy1+f->yoff())/(int32_t)f_hi; 300 } 301 else 302 { 303 x=-1; 304 y=-1; 305 }*/ 286 mouse_to_game(screenx, screeny, x, y); 287 x /= ftile_width(); 288 y /= ftile_height(); 306 289 } 307 290 308 291 void game::btile_on(int screenx, int screeny, int32_t &x, int32_t &y) 309 292 { 310 view *f=view_in(screenx,screeny); 311 if (f) 312 { 313 x=((int32_t)(screenx)-(int32_t)f->cx1+f->xoff()*bg_xmul/bg_xdiv)/(int32_t)b_wid; 314 y=((int32_t)(screeny)-(int32_t)f->cy1+f->yoff()*bg_ymul/bg_ydiv)/(int32_t)b_hi; 315 } 316 else 317 { 318 x=-1; 319 y=-1; 320 } 321 } 322 323 324 void game::mouse_to_game(int32_t x, int32_t y, int32_t &gamex, int32_t &gamey, view *f) 325 { 326 if (!f) 327 { 328 f=view_in(x,y); 329 if (!f) f=player_list; // if not in a view use the first on 330 } 331 332 if (f) 333 { 334 335 if (dev&MAP_MODE) 336 { 337 gamex=((x-(int32_t)f->cx1)*ftile_width()/AUTOTILE_WIDTH+map_xoff*ftile_width()); 338 gamey=((y-(int32_t)f->cy1)*ftile_height()/AUTOTILE_HEIGHT+map_yoff*ftile_height()); 339 } else 340 { 341 gamex=(x-(int32_t)f->cx1+f->xoff()); 342 gamey=(y-(int32_t)f->cy1+f->yoff()); 293 view *f = view_in(screenx, screeny); 294 if(f) 295 { 296 x = ((int32_t)screenx - (int32_t)f->cx1 297 + f->xoff() * bg_xmul / bg_xdiv) / (int32_t)b_wid; 298 y = ((int32_t)screeny - (int32_t)f->cy1 299 + f->yoff() * bg_ymul / bg_ydiv) / (int32_t)b_hi; 300 } 301 else 302 { 303 x = -1; 304 y = -1; 305 } 306 } 307 308 void game::mouse_to_game(int32_t x, int32_t y, 309 int32_t &gamex, int32_t &gamey, view *f) 310 { 311 if(!f) 312 f = view_in(x, y); 313 if(!f) 314 f = player_list; // if not in a view use the first one 315 316 if(f) 317 { 318 if(dev & MAP_MODE) 319 { 320 gamex = (x - (int32_t)f->cx1) * ftile_width() / AUTOTILE_WIDTH + map_xoff * ftile_width(); 321 gamey = (y - (int32_t)f->cy1) * ftile_height() / AUTOTILE_HEIGHT + map_yoff * ftile_height(); 322 } 323 else 324 { 325 gamex = x - (int32_t)f->cx1 + f->xoff(); 326 gamey = y - (int32_t)f->cy1 + f->yoff(); 327 } 328 } 329 } 330 331 void game::game_to_mouse(int32_t gamex, int32_t gamey, view *which, 332 int32_t &x, int32_t &y) 333 { 334 if(!(dev & MAP_MODE)) 335 { 336 x = gamex - which->xoff() + which->cx1; 337 y = gamey - which->yoff() + which->cy1; 338 return; 339 } 340 341 int32_t x1, y1; 342 343 if(dev & EDIT_MODE) 344 { 345 x1 = map_xoff; 346 y1 = map_yoff; 347 } 348 else 349 { 350 if(which->focus) 351 { 352 x1 = which->focus->x / ftile_width() 353 - (which->cx2 - which->cx1) / AUTOTILE_WIDTH / 2; 354 y1 = which->focus->y / ftile_height() 355 - (which->cy2 - which->cy1) / AUTOTILE_HEIGHT / 2; 356 } 357 else 358 x1 = y1 = 0; 359 } 360 361 if(x1 < 0) 362 x1 = 0; 363 if(y1 < 0) 364 y1 = 0; 365 366 x = gamex * AUTOTILE_WIDTH / ftile_width() 367 - x1 * AUTOTILE_WIDTH + which->cx1; 368 if(x1 > 0) 369 x -= (which->focus->x * AUTOTILE_WIDTH / ftile_width()) 370 % AUTOTILE_WIDTH; 371 372 y = gamey * AUTOTILE_HEIGHT / ftile_height() 373 - y1 * AUTOTILE_HEIGHT + which->cy1; 374 if(y1 > 0) 375 y -= (which->focus->y * AUTOTILE_HEIGHT / ftile_height()) 376 % AUTOTILE_HEIGHT; 377 } 378 379 int window_state(int state) 380 { 381 switch (state) 382 { 383 case RUN_STATE: 384 case PAUSE_STATE: 385 case JOY_CALB_STATE: 386 return 1; 387 388 case INTRO_START_STATE: 389 case HELP_STATE: 390 case INTRO_MORPH_STATE: 391 case MENU_STATE: 392 case SCENE_STATE: 393 return 0; 394 } 395 396 return 1; 397 } 398 399 void game::set_state(int new_state) 400 { 401 int d = 0; 402 reset_keymap(); // we think all the keys are up right now 403 404 if(playing_state(new_state) && !playing_state(state)) 405 { 406 if(first_view && first_view != player_list) 407 { 408 while(first_view) 409 { 410 view *tmp = first_view; 411 first_view = first_view->next; 412 delete tmp; 413 } 414 first_view = old_view; 415 old_view = NULL; 416 } 417 first_view = player_list; 418 d = 1; 419 } 420 else if(!playing_state(new_state) && (playing_state(state) || state == START_STATE)) 421 { 422 if(player_list) 423 { 424 first_view = new view(player_list->focus, NULL, -1); 425 first_view->pan_x = player_list->xoff(); 426 first_view->pan_y = player_list->yoff(); 427 } 428 else 429 first_view = new view(NULL, NULL, 0); 430 first_view->cx1 = (xres + 1) / 2 - 155; 431 first_view->cy1 = (yres + 1) / 2 - 95; 432 first_view->cx2 = (xres + 1) / 2 + 155; 433 if(total_weapons) 434 first_view->cy2 = (yres + 1) / 2 + 68; 435 else 436 first_view->cy2 = (yres + 1) / 2 + 95; 437 d = 1; 438 } 439 440 // switching to / from scene mode cause the screen size to change and the border to change 441 // so we need to redraw. 442 if(window_state(new_state) && !window_state(state)) 443 eh->show_windows(); 444 else if(!window_state(new_state) && window_state(state)) 445 eh->hide_windows(); 446 447 int old_state = state; 448 state = new_state; 449 450 pal->load(); // restore old palette 451 452 if(playing_state(state) && !(dev & EDIT_MODE)) 453 eh->set_mouse_shape(cash.img(c_target)->copy(), 8, 8); 454 else 455 eh->set_mouse_shape(cash.img(c_normal)->copy(), 1, 1); 456 457 if(old_state == SCENE_STATE && new_state != SCENE_STATE) 458 { 459 d = 1; 460 scene_director.set_abort(0); // don't skip any more scene stuff 461 } 462 else if(new_state == SCENE_STATE && old_state != SCENE_STATE) 463 d = 1; 464 465 if(d) 466 draw(state == SCENE_STATE); 467 468 dev_cont->set_state(new_state); 469 } 470 471 void game::joy_calb(event &ev) 472 { 473 if(!joy_win) // make sure the joy stick calibration window is open 474 return; 475 476 if(ev.type == EV_SPURIOUS) // spurious means we should update your status 477 { 478 int b1, b2, b3 = 0, x, y; 479 joy_status(b1, b2, b2, x, y); 480 int but = b1|b2|b3; 481 if(x > 0) x = 1; else if(x < 0) x = -1; 482 if(y > 0) y = 1; else if(y < 0) y = -1; 483 if(but) but = 1; 484 int dx = WINDOW_FRAME_LEFT + 20, dy = WINDOW_FRAME_TOP + 5; 485 image *jim = cash.img(joy_picts[but * 9+(y + 1)*3 + x + 1]); 486 joy_win->screen->bar(dx, dy, dx + jim->width()+6, dy + jim->height()+6, eh->black()); 487 jim->put_image(joy_win->screen, dx + 3, dy + 3); 488 489 if(but) 490 joy_calibrate(); 491 } 492 else if(ev.type == EV_MESSAGE && ev.message.id == JOY_OK) 493 { 494 eh->close_window(joy_win); 495 joy_win = NULL; 496 set_state(MENU_STATE); 497 } 498 } 499 500 void game::menu_select(event &ev) 501 { 502 state = DEV_MOUSE_RELEASE; 503 if(top_menu) 504 { 505 #if 0 506 eh->push_event(new event(men_mess[((pick_list *)ev.message.data)->get_selection()], NULL)); 507 eh->close_window(top_menu); 508 top_menu = NULL; 509 #endif 510 } 511 } 512 513 514 void game::show_help(char const *st) 515 { 516 strcpy(help_text, st); 517 help_text_frames = 0; 518 refresh = 1; 519 } 520 521 void game::draw_value(image *screen, int x, int y, int w, int h, 522 int val, int max) 523 { 524 screen->bar(x, y, x + w - 1, y + h, eh->dark_color()); 525 screen->bar(x, y + 1, x + w * val / max, y + h - 1, eh->bright_color()); 526 } 527 528 529 void game::set_level(level *nl) 530 { 531 if(current_level) 532 delete current_level; 533 current_level = nl; 534 } 535 536 void game::load_level(char const *name) 537 { 538 if(current_level) 539 delete current_level; 540 541 bFILE *fp = open_file(name, "rb"); 542 543 if(fp->open_failure()) 544 { 545 delete fp; 546 current_level = new level(100, 100, name); 547 char msg[100]; 548 sprintf(msg, symbol_str("no_file"), name); 549 show_help(msg); 550 } 551 else 552 { 553 spec_directory sd(fp); 554 555 #if 0 556 spec_entry *e = sd.find("Copyright 1995 Crack dot Com, All Rights reserved"); 557 if(!e) 558 { 559 the_game->show_help(symbol_str("missing_c")); 560 current_level = new level(100, 100, "untitled"); 561 the_game->need_refresh(); 562 } 563 else 564 #endif 565 current_level = new level(&sd, fp, name); 566 delete fp; 567 } 568 569 base->current_tick=(current_level->tick_counter()&0xff); 570 571 current_level->level_loaded_notify(); 572 the_game->help_text_frames = 0; 573 } 574 575 int game::done() 576 { 577 return finished || (main_net_cfg && main_net_cfg->restart_state()); 578 579 } 580 581 void game::end_session() 582 { 583 finished = 1; 584 if(main_net_cfg) 585 { 586 delete main_net_cfg; 587 main_net_cfg = NULL; 588 } 589 } 590 591 void game::put_block_fg(int x, int y, trans_image *im) 592 { 593 for(view *f = first_view; f; f = f->next) 594 { 595 if(f->drawable()) 596 { 597 int xoff = f->xoff(), yoff = f->yoff(), viewx1 = f->cx1, viewy1 = f->cy1, viewx2 = f->cx2, viewy2 = f->cy2; 598 if(xoff / ftile_width()>x || xoff / ftile_width()+(viewx2 - viewx1)/ftile_width()+1 < x || 599 yoff / ftile_height()>y || yoff / ftile_height()+(viewy2 - viewy1)/ftile_height()+1 < y) return; 600 short cx1, cy1, cx2, cy2; 601 screen->get_clip(cx1, cy1, cx2, cy2); 602 screen->set_clip(viewx1, viewy1, viewx2, viewy2); 603 im->put_image(screen, (x - xoff / ftile_width())*ftile_width()+viewx1 - xoff % ftile_width(), 604 (y - yoff / ftile_height())*ftile_height()+viewy1 - yoff % ftile_height()); 605 screen->set_clip(cx1, cy1, cx2, cy2); 606 } 607 } 608 } 609 610 void game::put_block_bg(int x, int y, image *im) 611 { 612 for(view *f = first_view; f; f = f->next) 613 { 614 if(f->drawable()) 615 { 616 int xoff = f->xoff(), yoff = f->yoff(), viewx1 = f->cx1, viewy1 = f->cy1, viewx2 = f->cx2, viewy2 = f->cy2; 617 int xo = xoff * bg_xmul / bg_xdiv; 618 int yo = yoff * bg_ymul / bg_ydiv; 619 620 if(xo / btile_width()>x || xo / btile_width()+(viewx2 - viewx1)/btile_width()+1 < x || 621 yo / btile_height()>y || yo / btile_height()+(viewy2 - viewy1)/btile_height()+1 < y) return; 622 short cx1, cy1, cx2, cy2; 623 screen->get_clip(cx1, cy1, cx2, cy2); 624 screen->set_clip(viewx1, viewy1, viewx2, viewy2); 625 im->put_image(screen, (x - xo / btile_width())*btile_width()+viewx1 - xo % btile_width(), 626 (y - yo / btile_height())*btile_height()+viewy1 - yo % btile_height(), 0); 627 screen->set_clip(cx1, cy1, cx2, cy2); 628 } 629 } 630 } 631 632 int need_delay = 1; 633 634 void game::dev_scroll() 635 { 636 need_delay = 0; 637 if(dev) 638 { 639 int xmargin, ymargin; 640 if(xres > 400) 641 { 642 xmargin = 20; 643 ymargin = 10; 644 } 645 else 646 { 647 xmargin = 10; 648 ymargin = 5; 649 } 650 651 int xs, ys; 652 if(mousex < xmargin && dev_cont->ok_to_scroll()) xs = -18; 653 else if(mousex>(screen->width()-xmargin) && dev_cont->ok_to_scroll()) xs = 18; 654 else if(eh->key_pressed(JK_LEFT) && !last_input && !dev_cont->need_arrows()) 655 xs = -18; 656 else if(eh->key_pressed(JK_RIGHT) && !last_input && !dev_cont->need_arrows()) 657 xs = 18; 658 else xs = 0; 659 660 661 if(mousey < ymargin && dev_cont->ok_to_scroll()) ys = -18; 662 else if(mousey>(screen->height()-ymargin) && dev_cont->ok_to_scroll()) ys = 18; 663 else if(eh->key_pressed(JK_UP) && !last_input) 664 ys = -18; 665 else if(eh->key_pressed(JK_DOWN) && !last_input) 666 ys = 18; 667 else ys = 0; 668 669 670 if(xs || ys) 671 { 672 need_delay = 1; 673 if(dev & MAP_MODE) 674 { 675 map_xoff += xs / 2; 676 map_yoff += ys / 2; 677 if(map_xoff < 0) map_xoff = 0; 678 if(map_yoff < 0) map_yoff = 0; 343 679 } 344 345 } 346 347 } 348 349 void game::game_to_mouse(int32_t gamex, int32_t gamey, view *which, int32_t &x, int32_t &y) 350 { 351 if (dev&MAP_MODE) 352 { 353 int32_t x1,y1; 354 if (dev&EDIT_MODE) 355 { 356 x1=map_xoff; 357 y1=map_yoff; 358 } else 359 { 360 if (which->focus) 361 { 362 x1=which->focus->x/ftile_width()-(which->cx2-which->cx1)/AUTOTILE_WIDTH/2; 363 y1=which->focus->y/ftile_height()-(which->cy2-which->cy1)/AUTOTILE_HEIGHT/2; 364 } else x1=y1=0; 365 } 366 if (x1<0) x1=0; 367 if (y1<0) y1=0; 368 369 x=gamex*AUTOTILE_WIDTH/ftile_width()-x1*AUTOTILE_WIDTH+which->cx1; 370 if (x1>0) 371 x-=((which->focus->x*AUTOTILE_WIDTH/ftile_width()) %AUTOTILE_WIDTH); 372 373 y=gamey*AUTOTILE_HEIGHT/ftile_height()-y1*AUTOTILE_HEIGHT+which->cy1; 374 if (y1>0) 375 y-=((which->focus->y*AUTOTILE_HEIGHT/ftile_height()) %AUTOTILE_HEIGHT); 376 } 377 else 378 { 379 x=gamex-which->xoff()+which->cx1; 380 y=gamey-which->yoff()+which->cy1; 381 } 382 } 383 384 int window_state(int state) 385 { 386 switch (state) 387 { 388 case RUN_STATE : 389 case PAUSE_STATE : 390 case JOY_CALB_STATE : 391 { return 1; } break; 392 393 case INTRO_START_STATE : 394 case HELP_STATE : 395 case INTRO_MORPH_STATE : 396 case MENU_STATE : 397 case SCENE_STATE : 398 { return 0; } break; 399 } 400 return 1; 401 } 402 403 404 405 void game::set_state(int new_state) 406 { 407 int d=0; 408 reset_keymap(); // we think all the keys are up right now 409 if (playing_state(new_state) && !playing_state(state)) 410 { 411 if (first_view && first_view!=player_list) 412 { 413 while (first_view) 414 { 415 view *tmp=first_view; 416 first_view=first_view->next; 417 delete tmp; 680 else 681 { 682 for(view *v = first_view; v; v = v->next) 683 { 684 if(xs >= 0 || v->xoff()>0) 685 v->pan_x += xs; 686 if(ys >= 0 || v->yoff()>0) 687 v->pan_y += ys; 688 } 418 689 } 419 first_view=old_view; 420 old_view=NULL; 421 } 422 first_view=player_list; 423 d=1; 424 } else if (!playing_state(new_state) && (playing_state(state) || state==START_STATE)) 425 { 426 if (player_list) 427 { 428 first_view=new view(player_list->focus,NULL,-1); 429 first_view->pan_x=player_list->xoff(); 430 first_view->pan_y=player_list->yoff(); 431 } 432 else 433 first_view=new view(NULL,NULL,0); 434 first_view->cx1=(xres+1)/2-155; 435 first_view->cy1=(yres+1)/2-95; 436 first_view->cx2=(xres+1)/2+155; 437 if (total_weapons) 438 first_view->cy2=(yres+1)/2+68; 439 else 440 first_view->cy2=(yres+1)/2+95; 441 d=1; 442 } 443 444 445 446 // switching to/from scene mode cause the screen size to change and the border to change 447 // so we need to redraw. 448 if (window_state(new_state) && !window_state(state)) 449 eh->show_windows(); 450 else if (!window_state(new_state) && window_state(state)) 451 eh->hide_windows(); 452 453 int old_state=state; 454 state=new_state; 455 456 pal->load(); // restore old palette 457 458 if (playing_state(state) && !(dev&EDIT_MODE)) 459 eh->set_mouse_shape(cash.img(c_target)->copy(),8,8); 460 else 461 eh->set_mouse_shape(cash.img(c_normal)->copy(),1,1); 462 463 if (old_state==SCENE_STATE && new_state!=SCENE_STATE) 464 { 465 d=1; 466 scene_director.set_abort(0); // don't skip any more scene stuff 467 } 468 else if (new_state==SCENE_STATE && old_state!=SCENE_STATE) 469 d=1; 470 471 if (d) 472 draw(state==SCENE_STATE); 473 474 dev_cont->set_state(new_state); 475 } 476 477 void game::joy_calb(event &ev) 478 { 479 if (joy_win) // make sure the joy stick calibration window is open 480 { 481 482 if (ev.type==EV_SPURIOUS) // spurious means we should update your status 483 { 484 int b1,b2,b3=0,x,y; 485 joy_status(b1,b2,b2,x,y); 486 int but=b1|b2|b3; 487 if (x>0) x=1; else if (x<0) x=-1; 488 if (y>0) y=1; else if (y<0) y=-1; 489 if (but) but=1; 490 int dx=WINDOW_FRAME_LEFT+20,dy=WINDOW_FRAME_TOP+5; 491 image *jim=cash.img(joy_picts[but*9+(y+1)*3+x+1]); 492 joy_win->screen->bar(dx,dy,dx+jim->width()+6,dy+jim->height()+6,eh->black()); 493 jim->put_image(joy_win->screen,dx+3,dy+3); 494 495 if (but) 496 joy_calibrate(); 497 } else if (ev.type==EV_MESSAGE && ev.message.id==JOY_OK) 498 { 499 eh->close_window(joy_win); 500 joy_win=NULL; 501 set_state(MENU_STATE); 502 } 503 } 504 } 505 506 void game::menu_select(event &ev) 507 { 508 state=DEV_MOUSE_RELEASE; 509 if (top_menu) 510 { 511 /* eh->push_event(new event(men_mess[((pick_list *)ev.message.data)->get_selection()],NULL)); 512 eh->close_window(top_menu); 513 top_menu=NULL;*/ 514 } 515 } 516 517 518 void game::show_help(char const *st) 519 { 520 strcpy(help_text,st); 521 help_text_frames=0; 522 refresh=1; 523 } 524 525 void game::draw_value(image *screen, int x, int y, int w, int h, int val, int max) 526 { 527 screen->bar(x,y,x+w-1,y+h,eh->dark_color()); 528 screen->bar(x,y+1,x+w*val/max,y+h-1,eh->bright_color()); 529 } 530 531 532 void game::set_level(level *nl) 533 { 534 if (current_level) 535 delete current_level; 536 current_level=nl; 537 } 538 539 void game::load_level(char const *name) 540 { 541 if (current_level) 542 delete current_level; 543 544 bFILE *fp=open_file(name,"rb"); 545 546 if (fp->open_failure()) 547 { 548 delete fp; 549 current_level=new level(100,100,name); 550 char msg[100]; 551 sprintf(msg,symbol_str("no_file"),name); 552 show_help(msg); 553 } 554 else 555 { 556 spec_directory sd(fp); 557 558 #if 0 559 spec_entry *e=sd.find("Copyright 1995 Crack dot Com, All Rights reserved"); 560 if (!e) 561 { 562 the_game->show_help(symbol_str("missing_c")); 563 current_level=new level(100,100,"untitled"); 564 the_game->need_refresh(); 565 } 566 else 567 #endif 568 current_level=new level(&sd,fp,name); 569 delete fp; 570 } 571 572 base->current_tick=(current_level->tick_counter()&0xff); 573 574 current_level->level_loaded_notify(); 575 the_game->help_text_frames=0; 576 577 } 578 579 int game::done() 580 { 581 return finished || (main_net_cfg && main_net_cfg->restart_state()); 582 583 } 584 585 void game::end_session() 586 { 587 finished=1; 588 if (main_net_cfg) 589 { 590 delete main_net_cfg; 591 main_net_cfg=NULL; 592 } 593 } 594 595 void game::put_block_fg(int x, int y, trans_image *im) 596 { 597 for (view *f=first_view;f;f=f->next) 598 { 599 if (f->drawable()) 600 { 601 int xoff=f->xoff(),yoff=f->yoff(),viewx1=f->cx1,viewy1=f->cy1,viewx2=f->cx2,viewy2=f->cy2; 602 if (xoff/ftile_width()>x || xoff/ftile_width()+(viewx2-viewx1)/ftile_width()+1<x || 603 yoff/ftile_height()>y || yoff/ftile_height()+(viewy2-viewy1)/ftile_height()+1<y) return; 604 short cx1,cy1,cx2,cy2; 605 screen->get_clip(cx1,cy1,cx2,cy2); 606 screen->set_clip(viewx1,viewy1,viewx2,viewy2); 607 im->put_image(screen,(x-xoff/ftile_width())*ftile_width()+viewx1-xoff%ftile_width(), 608 (y-yoff/ftile_height())*ftile_height()+viewy1-yoff%ftile_height()); 609 screen->set_clip(cx1,cy1,cx2,cy2); 610 } 611 } 612 } 613 614 void game::put_block_bg(int x, int y, image *im) 615 { 616 for (view *f=first_view;f;f=f->next) 617 { 618 if (f->drawable()) 619 { 620 int xoff=f->xoff(),yoff=f->yoff(),viewx1=f->cx1,viewy1=f->cy1,viewx2=f->cx2,viewy2=f->cy2; 621 int xo=xoff*bg_xmul/bg_xdiv; 622 int yo=yoff*bg_ymul/bg_ydiv; 623 624 if (xo/btile_width()>x || xo/btile_width()+(viewx2-viewx1)/btile_width()+1<x || 625 yo/btile_height()>y || yo/btile_height()+(viewy2-viewy1)/btile_height()+1<y) return; 626 short cx1,cy1,cx2,cy2; 627 screen->get_clip(cx1,cy1,cx2,cy2); 628 screen->set_clip(viewx1,viewy1,viewx2,viewy2); 629 im->put_image(screen,(x-xo/btile_width())*btile_width()+viewx1-xo%btile_width(), 630 (y-yo/btile_height())*btile_height()+viewy1-yo%btile_height(),0); 631 screen->set_clip(cx1,cy1,cx2,cy2); 632 } 633 } 634 } 635 636 int need_delay=1; 637 638 void game::dev_scroll() 639 { 640 need_delay=0; 641 if (dev) 642 { 643 int xmargin,ymargin; 644 if (xres>400) 645 { 646 xmargin=20; 647 ymargin=10; 648 } 649 else 650 { 651 xmargin=10; 652 ymargin=5; 653 } 654 655 int xs,ys; 656 if (mousex<xmargin && dev_cont->ok_to_scroll()) xs=-18; 657 else if (mousex>(screen->width()-xmargin) && dev_cont->ok_to_scroll()) xs=18; 658 else if (eh->key_pressed(JK_LEFT) && !last_input && !dev_cont->need_arrows()) 659 xs=-18; 660 else if (eh->key_pressed(JK_RIGHT) && !last_input && !dev_cont->need_arrows()) 661 xs=18; 662 else xs=0; 663 664 665 if (mousey<ymargin && dev_cont->ok_to_scroll()) ys=-18; 666 else if (mousey>(screen->height()-ymargin) && dev_cont->ok_to_scroll()) ys=18; 667 else if (eh->key_pressed(JK_UP) && !last_input) 668 ys=-18; 669 else if (eh->key_pressed(JK_DOWN) && !last_input) 670 ys=18; 671 else ys=0; 672 673 674 if (xs || ys) 675 { 676 need_delay=1; 677 if (dev&MAP_MODE) 678 { 679 map_xoff+=xs/2; 680 map_yoff+=ys/2; 681 if (map_xoff<0) map_xoff=0; 682 if (map_yoff<0) map_yoff=0; 683 } 684 else 685 { 686 for (view *v=first_view;v;v=v->next) 687 { 688 if (xs>=0 || v->xoff()>0) 689 v->pan_x+=xs; 690 if (ys>=0 || v->yoff()>0) 691 v->pan_y+=ys; 692 } 693 } 694 refresh=1; 690 refresh = 1; 695 691 } 696 692 } … … 700 696 { 701 697 uint8_t *sl=(uint8_t *)screen->scan_line(y1)+x1; 702 int x, y,a=screen->width()-(x2-x1+1);698 int x, y, a = screen->width()-(x2 - x1 + 1); 703 699 uint8_t c; 704 for (y=y1;y<=y2;y++)705 { 706 for (x=x1;x<=x2;x++)700 for(y = y1; y <= y2; y++) 701 { 702 for(x = x1; x <= x2; x++) 707 703 { 708 704 c=*sl; 709 705 *(sl++)=remap[c]; 710 706 } 711 sl +=a;707 sl += a; 712 708 } 713 709 } … … 715 711 static void post_render() 716 712 { 717 if 713 if(DEFINEDP(symbol_function(l_post_render))) 718 714 { 719 715 screen->dirt_off(); 720 716 clear_tmp(); 721 eval_function((lisp_symbol *)l_post_render, NULL);717 eval_function((lisp_symbol *)l_post_render, NULL); 722 718 clear_tmp(); 723 719 screen->dirt_on(); 724 720 } 725 721 } 726 722 727 723 void game::draw_map(view *v, int interpolate) 728 724 { 729 725 backtile *bt; 730 int x1, y1,x2,y2,x,y,xo,yo,nxoff,nyoff;731 short cx1, cy1,cx2,cy2;732 screen->get_clip(cx1, cy1,cx2,cy2);733 734 if (!current_level || state==MENU_STATE)735 { 736 if (title_screen>=0)737 { 738 if (state==SCENE_STATE)739 screen->set_clip(v->cx1, v->cy1,v->cx2,v->cy2);740 image *tit =cash.img(title_screen);741 tit->put_image(screen, screen->width()/2-tit->width()/2,742 screen->height()/2-tit->height()/2);743 if (state==SCENE_STATE)744 screen->set_clip(cx1, cy1,cx2,cy2);726 int x1, y1, x2, y2, x, y, xo, yo, nxoff, nyoff; 727 short cx1, cy1, cx2, cy2; 728 screen->get_clip(cx1, cy1, cx2, cy2); 729 730 if(!current_level || state == MENU_STATE) 731 { 732 if(title_screen >= 0) 733 { 734 if(state == SCENE_STATE) 735 screen->set_clip(v->cx1, v->cy1, v->cx2, v->cy2); 736 image *tit = cash.img(title_screen); 737 tit->put_image(screen, screen->width()/2 - tit->width()/2, 738 screen->height()/2 - tit->height()/2); 739 if(state == SCENE_STATE) 740 screen->set_clip(cx1, cy1, cx2, cy2); 745 741 eh->flush_screen(); 746 } 747 return 748 } 749 750 refresh =0;751 752 753 // save the dirty rect routines some work by markinging evrything in the 742 } 743 return; 744 } 745 746 refresh = 0; 747 748 749 // save the dirty rect routines some work by markinging evrything in the 754 750 // view area dirty alreadt 755 751 756 if 757 screen->add_dirty(v->cx1, v->cy1,(v->cx2-v->cx1+1)*2+v->cx1,v->cy1+(v->cy2-v->cy1+1)*2);752 if(small_render) 753 screen->add_dirty(v->cx1, v->cy1, (v->cx2 - v->cx1 + 1)*2 + v->cx1, v->cy1+(v->cy2 - v->cy1 + 1)*2); 758 754 else 759 screen->add_dirty(v->cx1, v->cy1,v->cx2,v->cy2);760 761 if (v->draw_solid!=-1) // fill the screen and exit..762 { 763 int c =v->draw_solid;764 for (int y=v->cy1;y<=v->cy2;y++)765 memset(screen->scan_line(y)+v->cx1, c,v->cx2-v->cx1+1);766 v->draw_solid =-1;767 return 768 } 769 770 int32_t old_cx1 =0,old_cy1=0,old_cx2=0,old_cy2=0; // if we do a small render, we need to restore these771 image *old_screen =NULL;772 if (small_render && (dev&DRAW_LIGHTS)) // cannot do this if we skip lighting773 { 774 old_cx1 =v->cx1;775 old_cy1 =v->cy1;776 old_cx2 =v->cx2;777 old_cy2 =v->cy2;778 779 v->cx1 =0;780 v->cy1 =0;781 v->cx2 =small_render->width()-1;782 v->cy2 =small_render->height()-1;783 784 old_screen =screen;785 screen =small_render;755 screen->add_dirty(v->cx1, v->cy1, v->cx2, v->cy2); 756 757 if(v->draw_solid != -1) // fill the screen and exit.. 758 { 759 int c = v->draw_solid; 760 for(int y = v->cy1; y <= v->cy2; y++) 761 memset(screen->scan_line(y)+v->cx1, c, v->cx2 - v->cx1 + 1); 762 v->draw_solid = -1; 763 return; 764 } 765 766 int32_t old_cx1 = 0, old_cy1 = 0, old_cx2 = 0, old_cy2 = 0; // if we do a small render, we need to restore these 767 image *old_screen = NULL; 768 if(small_render && (dev & DRAW_LIGHTS)) // cannot do this if we skip lighting 769 { 770 old_cx1 = v->cx1; 771 old_cy1 = v->cy1; 772 old_cx2 = v->cx2; 773 old_cy2 = v->cy2; 774 775 v->cx1 = 0; 776 v->cy1 = 0; 777 v->cx2 = small_render->width()-1; 778 v->cy2 = small_render->height()-1; 779 780 old_screen = screen; 781 screen = small_render; 786 782 } else 787 783 screen->dirt_off(); … … 789 785 790 786 791 // int32_t max_xoff=(current_level->foreground_width()-1)*ftile_width()-(v->cx2 -v->cx1+1);792 // int32_t max_yoff=(current_level->foreground_height()-1)*ftile_height()-(v->cy2 -v->cy1+1);793 794 int32_t xoff, yoff;795 if 796 { 797 xoff =v->interpolated_xoff();798 yoff =v->interpolated_yoff();787 // int32_t max_xoff=(current_level->foreground_width()-1)*ftile_width()-(v->cx2 - v->cx1 + 1); 788 // int32_t max_yoff=(current_level->foreground_height()-1)*ftile_height()-(v->cy2 - v->cy1 + 1); 789 790 int32_t xoff, yoff; 791 if(interpolate) 792 { 793 xoff = v->interpolated_xoff(); 794 yoff = v->interpolated_yoff(); 799 795 } else 800 796 { 801 xoff =v->xoff();802 yoff =v->yoff();803 } 804 805 // if (xoff>max_xoff) xoff=max_xoff;806 // if (yoff>max_yoff) yoff=max_yoff;807 808 current_vxadd =xoff-v->cx1;809 current_vyadd =yoff-v->cy1;810 811 screen->set_clip(v->cx1, v->cy1,v->cx2,v->cy2);812 813 nxoff =xoff*bg_xmul/bg_xdiv;814 nyoff =yoff*bg_ymul/bg_ydiv;815 816 // int32_t max_bg_xoff=(current_level->background_width())*btile_width()-(v->cx2 -v->cx1+1);817 // int32_t max_bg_yoff=(current_level->background_height())*btile_height()-(v->cy2 -v->cy1+1);818 // if (nxoff>max_bg_xoff) nxoff=max_xoff;819 // if (nyoff>max_bg_yoff) nyoff=max_yoff;820 821 822 x1 =nxoff/btile_width(); y1=nyoff/btile_height();823 x2 =x1+(v->cx2-v->cx1+btile_width())/btile_width();824 y2 =y1+(v->cy2-v->cy1+btile_height())/btile_height();825 826 827 xo =v->cx1-nxoff%btile_width();828 yo =v->cy1-nyoff%btile_height();829 830 int xinc, yinc,draw_x,draw_y;831 832 833 if 834 { 835 xinc =btile_width();836 yinc =btile_height();837 838 int bh =current_level->background_height(),bw=current_level->background_width();797 xoff = v->xoff(); 798 yoff = v->yoff(); 799 } 800 801 // if(xoff > max_xoff) xoff = max_xoff; 802 // if(yoff > max_yoff) yoff = max_yoff; 803 804 current_vxadd = xoff - v->cx1; 805 current_vyadd = yoff - v->cy1; 806 807 screen->set_clip(v->cx1, v->cy1, v->cx2, v->cy2); 808 809 nxoff = xoff * bg_xmul / bg_xdiv; 810 nyoff = yoff * bg_ymul / bg_ydiv; 811 812 // int32_t max_bg_xoff=(current_level->background_width())*btile_width()-(v->cx2 - v->cx1 + 1); 813 // int32_t max_bg_yoff=(current_level->background_height())*btile_height()-(v->cy2 - v->cy1 + 1); 814 // if(nxoff > max_bg_xoff) nxoff = max_xoff; 815 // if(nyoff > max_bg_yoff) nyoff = max_yoff; 816 817 818 x1 = nxoff / btile_width(); y1 = nyoff / btile_height(); 819 x2 = x1+(v->cx2 - v->cx1 + btile_width())/btile_width(); 820 y2 = y1+(v->cy2 - v->cy1 + btile_height())/btile_height(); 821 822 823 xo = v->cx1 - nxoff % btile_width(); 824 yo = v->cy1 - nyoff % btile_height(); 825 826 int xinc, yinc, draw_x, draw_y; 827 828 829 if(!(dev & MAP_MODE) && (dev & DRAW_BG_LAYER)) 830 { 831 xinc = btile_width(); 832 yinc = btile_height(); 833 834 int bh = current_level->background_height(), bw = current_level->background_width(); 839 835 uint16_t *bl; 840 for (draw_y=yo,y=y1;y<=y2;y++,draw_y+=yinc)841 { 842 if (y>=bh)843 bl =NULL;836 for(draw_y = yo, y = y1; y <= y2; y++, draw_y += yinc) 837 { 838 if(y >= bh) 839 bl = NULL; 844 840 else 845 bl =current_level->get_bgline(y)+x1;846 847 for (x=x1,draw_x=xo;x<=x2;x++,draw_x+=xinc)848 { 849 if (x<bw && y<bh)850 851 bt =get_bg(*bl);852 853 854 else bt=get_bg(0);855 856 bt->im->put_image(screen, draw_x,draw_y);857 // if 858 // current_level->put_bg(x,y,bt->next);841 bl = current_level->get_bgline(y)+x1; 842 843 for(x = x1, draw_x = xo; x <= x2; x++, draw_x += xinc) 844 { 845 if(x < bw && y < bh) 846 { 847 bt = get_bg(*bl); 848 bl++; 849 } 850 else bt = get_bg(0); 851 852 bt->im->put_image(screen, draw_x, draw_y); 853 // if(!(dev & EDIT_MODE) && bt->next) 854 // current_level->put_bg(x, y, bt->next); 859 855 } 860 856 } 861 857 } 862 858 863 // if (!(dev&EDIT_MODE))859 // if(!(dev & EDIT_MODE)) 864 860 // server_check(); 865 861 866 uint8_t rescan =0;867 868 int fw, fh;869 870 if (dev&MAP_MODE)871 { 872 fw =AUTOTILE_WIDTH;873 fh =AUTOTILE_HEIGHT;874 if (dev&EDIT_MODE)875 { 876 x1=map_xoff;877 y1=map_yoff;862 uint8_t rescan = 0; 863 864 int fw, fh; 865 866 if(dev & MAP_MODE) 867 { 868 fw = AUTOTILE_WIDTH; 869 fh = AUTOTILE_HEIGHT; 870 if(dev & EDIT_MODE) 871 { 872 x1 = map_xoff; 873 y1 = map_yoff; 878 874 } else 879 875 { 880 if(v->focus)881 882 x1=v->focus->x/ftile_width()-(v->cx2-v->cx1)/fw/2;883 y1=v->focus->y/ftile_height()-(v->cy2-v->cy1)/fh/2;884 } else x1=y1=0;876 if(v->focus) 877 { 878 x1 = v->focus->x / ftile_width()-(v->cx2 - v->cx1)/fw / 2; 879 y1 = v->focus->y / ftile_height()-(v->cy2 - v->cy1)/fh / 2; 880 } else x1 = y1 = 0; 885 881 } 886 if (x1>0)887 xo =v->cx1-((v->focus->x*fw/ftile_width()) %fw);888 else xo =v->cx1;889 if (y1>0)890 yo =v->cy1-((v->focus->y*fh/ftile_height()) %fh);891 else yo =v->cy1;882 if(x1 > 0) 883 xo = v->cx1-((v->focus->x * fw / ftile_width()) %fw); 884 else xo = v->cx1; 885 if(y1 > 0) 886 yo = v->cy1-((v->focus->y * fh / ftile_height()) %fh); 887 else yo = v->cy1; 892 888 } else 893 889 { 894 fw =ftile_width();895 fh =ftile_height();890 fw = ftile_width(); 891 fh = ftile_height(); 896 892 x1=(xoff)/fw; y1=(yoff)/fh; 897 xo =v->cx1-xoff%fw;898 yo =v->cy1-yoff%fh;899 900 } 901 if (x1<0) x1=0;902 if (y1<0) y1=0;903 904 x2 =x1+(v->cx2-v->cx1+fw)/fw;905 y2 =y1+(v->cy2-v->cy1+fh)/fh;906 if (x2>=current_level->foreground_width())907 x2 =current_level->foreground_width()-1;908 if (y2>=current_level->foreground_height())909 y2 =current_level->foreground_height()-1;910 911 912 xinc =fw;913 yinc =fh;914 915 if 916 { 917 short ncx1, ncy1,ncx2,ncy2;918 screen->get_clip(ncx1, ncy1,ncx2,ncy2);919 920 int scr_w =screen->width();921 if (dev&MAP_MODE)922 { 923 if (dev&EDIT_MODE)893 xo = v->cx1 - xoff % fw; 894 yo = v->cy1 - yoff % fh; 895 896 } 897 if(x1 < 0) x1 = 0; 898 if(y1 < 0) y1 = 0; 899 900 x2 = x1+(v->cx2 - v->cx1 + fw)/fw; 901 y2 = y1+(v->cy2 - v->cy1 + fh)/fh; 902 if(x2 >= current_level->foreground_width()) 903 x2 = current_level->foreground_width()-1; 904 if(y2 >= current_level->foreground_height()) 905 y2 = current_level->foreground_height()-1; 906 907 908 xinc = fw; 909 yinc = fh; 910 911 if(dev & DRAW_FG_LAYER) 912 { 913 short ncx1, ncy1, ncx2, ncy2; 914 screen->get_clip(ncx1, ncy1, ncx2, ncy2); 915 916 int scr_w = screen->width(); 917 if(dev & MAP_MODE) 918 { 919 if(dev & EDIT_MODE) 924 920 screen->clear(eh->bright_color()); 925 921 else 926 922 screen->clear(eh->black()); 927 for (y=y1,draw_y=yo;y<=y2;y++,draw_y+=yinc) 928 { 929 if (!(draw_y<ncy1 ||draw_y+yinc>=ncy2)) 930 { 931 uint16_t *cl=current_level->get_fgline(y)+x1; 932 uint8_t *sl1=screen->scan_line(draw_y)+xo; 933 for (x=x1,draw_x=xo;x<=x2;x++,cl++,sl1+=xinc,draw_x+=xinc) 934 { 935 if (!(draw_x<ncx1 || draw_x+xinc>=ncx2)) 936 { 937 int fort_num; 938 // if (*cl&0x8000 || (dev&EDIT_MODE)) 939 fort_num=fgvalue(*cl); 940 // else fort_num=0; 941 942 uint8_t *sl2=get_fg(fort_num)->micro_image->scan_line(0); 943 uint8_t *sl3=sl1; 944 memcpy(sl3,sl2,AUTOTILE_WIDTH); sl2+=AUTOTILE_WIDTH; sl3+=scr_w; 945 memcpy(sl3,sl2,AUTOTILE_WIDTH); sl2+=AUTOTILE_WIDTH; sl3+=scr_w; 946 memcpy(sl3,sl2,AUTOTILE_WIDTH); 947 } 948 } 949 } 923 for(y = y1, draw_y = yo; y <= y2; y++, draw_y += yinc) 924 { 925 if(!(draw_y < ncy1 ||draw_y + yinc >= ncy2)) 926 { 927 uint16_t *cl = current_level->get_fgline(y)+x1; 928 uint8_t *sl1 = screen->scan_line(draw_y)+xo; 929 for(x = x1, draw_x = xo; x <= x2; x++, cl++, sl1 += xinc, draw_x += xinc) 930 { 931 if(!(draw_x < ncx1 || draw_x + xinc >= ncx2)) 932 { 933 int fort_num; 934 // if(*cl & 0x8000 || (dev & EDIT_MODE)) 935 fort_num = fgvalue(*cl); 936 // else fort_num = 0; 937 938 uint8_t *sl2 = get_fg(fort_num)->micro_image->scan_line(0); 939 uint8_t *sl3 = sl1; 940 memcpy(sl3, sl2, AUTOTILE_WIDTH); sl2 += AUTOTILE_WIDTH; sl3 += scr_w; 941 memcpy(sl3, sl2, AUTOTILE_WIDTH); sl2 += AUTOTILE_WIDTH; sl3 += scr_w; 942 memcpy(sl3, sl2, AUTOTILE_WIDTH); 943 } 950 944 } 951 952 if (dev&EDIT_MODE) 945 } 946 } 947 948 if(dev & EDIT_MODE) 953 949 current_level->draw_areas(v); 954 950 } else 955 951 { 956 952 957 int fg_h =current_level->foreground_height(),fg_w=current_level->foreground_width();958 959 for (y=y1,draw_y=yo;y<=y2;y++,draw_y+=yinc)960 { 961 962 963 if (y<fg_h)964 cl=current_level->get_fgline(y)+x1;965 else cl=NULL;966 uint8_t *sl1=draw_y<ncy1 ? 0 : screen->scan_line(draw_y)+xo;967 968 for (x=x1,draw_x=xo;x<=x2;x++,draw_x+=xinc,cl++,sl1+=xinc)969 970 if (x<fg_w && y<fg_h)971 972 if(above_tile(*cl))973 rescan=1;974 975 976 int fort_num=fgvalue(*cl); 977 if (fort_num!=BLACK)978 979 if (draw_y<ncy1 || draw_y+yinc>=ncy2 || draw_x<ncx1 || draw_x+xinc>=ncx2)980 get_fg(fort_num)->im->put_image(screen,draw_x,draw_y);981 982 get_fg(fort_num)->im->put_image_offseted(screen,sl1);983 984 if(!(dev & EDIT_MODE))985 *cl|=0x8000; // mark as has-been-seen986 } 987 988 989 990 } 991 } 992 /* if (dev==0)993 current_level->put_fg(x, y,ft->next); */994 } 995 996 // if (!(dev&EDIT_MODE))953 int fg_h = current_level->foreground_height(), fg_w = current_level->foreground_width(); 954 955 for(y = y1, draw_y = yo; y <= y2; y++, draw_y += yinc) 956 { 957 958 uint16_t *cl; 959 if(y < fg_h) 960 cl = current_level->get_fgline(y)+x1; 961 else cl = NULL; 962 uint8_t *sl1 = draw_y < ncy1 ? 0 : screen->scan_line(draw_y)+xo; 963 964 for(x = x1, draw_x = xo; x <= x2; x++, draw_x += xinc, cl++, sl1 += xinc) 965 { 966 if(x < fg_w && y < fg_h) 967 { 968 if(above_tile(*cl)) 969 rescan = 1; 970 else 971 { 972 int fort_num = fgvalue(*cl); 973 if(fort_num != BLACK) 974 { 975 if(draw_y < ncy1 || draw_y + yinc >= ncy2 || draw_x < ncx1 || draw_x + xinc >= ncx2) 976 get_fg(fort_num)->im->put_image(screen, draw_x, draw_y); 977 else 978 get_fg(fort_num)->im->put_image_offseted(screen, sl1); 979 980 if(!(dev & EDIT_MODE)) 981 *cl|=0x8000; // mark as has - been - seen 982 } 983 } 984 } 985 } 986 } 987 } 988 /* if(dev == 0) 989 current_level->put_fg(x, y, ft->next); */ 990 } 991 992 // if(!(dev & EDIT_MODE)) 997 993 // server_check(); 998 994 999 int32_t ro =rand_on;1000 if 1001 { 1002 if 995 int32_t ro = rand_on; 996 if(dev & DRAW_PEOPLE_LAYER) 997 { 998 if(interpolate) 1003 999 current_level->interpolate_draw_objects(v); 1004 1000 else … … 1006 1002 } 1007 1003 1008 // if (!(dev&EDIT_MODE))1004 // if(!(dev & EDIT_MODE)) 1009 1005 // server_check(); 1010 1006 1011 if (!(dev&MAP_MODE))1007 if(!(dev & MAP_MODE)) 1012 1008 { 1013 1009 1014 1010 draw_panims(v); 1015 1011 1016 if (dev & DRAW_FG_LAYER && rescan) 1017 { 1018 for (y=y1,draw_y=yo;y<=y2;y++,draw_y+=yinc) 1019 { 1020 uint16_t *cl=current_level->get_fgline(y)+x1; 1021 for (x=x1,draw_x=xo;x<=x2;x++,draw_x+=xinc,cl++) 1022 { 1023 if (above_tile(*cl)) 1024 { 1025 int fort_num=fgvalue(*cl); 1026 if (fort_num!=BLACK) 1027 { 1028 if (dev & DRAW_BG_LAYER) 1029 get_fg(fort_num)->im->put_image(screen,draw_x,draw_y); 1030 else 1031 get_fg(fort_num)->im->put_image_filled(screen,draw_x,draw_y,0); 1032 1033 if (!(dev & EDIT_MODE)) 1034 current_level->mark_seen(x,y); 1035 else 1036 { 1037 screen->line(draw_x,draw_y,draw_x+xinc,draw_y+yinc,eh->bright_color()); 1038 screen->line(draw_x+xinc,draw_y,draw_x,draw_y+yinc,eh->bright_color()); 1039 } 1040 } 1041 } 1042 } 1043 } 1044 } 1045 1046 1047 if (dev & DRAW_FG_BOUND_LAYER) 1048 { 1049 int b=eh->bright_color(); 1050 int fg_h=current_level->foreground_height(),fg_w=current_level->foreground_width(); 1051 1052 for (y=y1,draw_y=yo;y<=y2;y++,draw_y+=yinc) 1053 { 1054 uint16_t *cl; 1055 if (y<fg_h) 1056 cl=current_level->get_fgline(y)+x1; 1057 else cl=NULL; 1058 for (x=x1,draw_x=xo;x<=x2;x++,draw_x+=xinc,cl++) 1059 { 1060 if (x<fg_w && y<fg_h) 1061 { 1062 int fort_num=fgvalue(*cl); 1063 if (fort_num!=BLACK) 1064 { 1065 point_list *p=get_fg(fort_num)->points; 1066 uint8_t *d=p->data; 1067 if (p->tot) 1068 { 1069 for (int i=1;i<p->tot;i++) 1070 { 1071 d+=2; 1072 screen->line(draw_x+*(d-2),draw_y+*(d-1),draw_x+*d,draw_y+*(d+1),b); 1073 } 1074 screen->line(draw_x+*d,draw_y+*(d-1),draw_x+p->data[0],draw_y+p->data[1],b); 1075 } 1076 } 1077 } 1078 } 1012 if(dev & DRAW_FG_LAYER && rescan) 1013 { 1014 for(y = y1, draw_y = yo; y <= y2; y++, draw_y += yinc) 1015 { 1016 uint16_t *cl = current_level->get_fgline(y)+x1; 1017 for(x = x1, draw_x = xo; x <= x2; x++, draw_x += xinc, cl++) 1018 { 1019 if(above_tile(*cl)) 1020 { 1021 int fort_num = fgvalue(*cl); 1022 if(fort_num != BLACK) 1023 { 1024 if(dev & DRAW_BG_LAYER) 1025 get_fg(fort_num)->im->put_image(screen, draw_x, draw_y); 1026 else 1027 get_fg(fort_num)->im->put_image_filled(screen, draw_x, draw_y, 0); 1028 1029 if(!(dev & EDIT_MODE)) 1030 current_level->mark_seen(x, y); 1031 else 1032 { 1033 screen->line(draw_x, draw_y, draw_x + xinc, draw_y + yinc, eh->bright_color()); 1034 screen->line(draw_x + xinc, draw_y, draw_x, draw_y + yinc, eh->bright_color()); 1035 } 1036 } 1079 1037 } 1080 1038 } 1081 1082 // if (!(dev&EDIT_MODE)) 1039 } 1040 } 1041 1042 1043 if(dev & DRAW_FG_BOUND_LAYER) 1044 { 1045 int b = eh->bright_color(); 1046 int fg_h = current_level->foreground_height(), fg_w = current_level->foreground_width(); 1047 1048 for(y = y1, draw_y = yo; y <= y2; y++, draw_y += yinc) 1049 { 1050 uint16_t *cl; 1051 if(y < fg_h) 1052 cl = current_level->get_fgline(y)+x1; 1053 else cl = NULL; 1054 for(x = x1, draw_x = xo; x <= x2; x++, draw_x += xinc, cl++) 1055 { 1056 if(x < fg_w && y < fg_h) 1057 { 1058 int fort_num = fgvalue(*cl); 1059 if(fort_num != BLACK) 1060 { 1061 point_list *p = get_fg(fort_num)->points; 1062 uint8_t *d = p->data; 1063 if(p->tot) 1064 { 1065 for(int i = 1; i < p->tot; i++) 1066 { 1067 d += 2; 1068 screen->line(draw_x+*(d - 2), draw_y+*(d - 1), draw_x+*d, draw_y+*(d + 1), b); 1069 } 1070 screen->line(draw_x+*d, draw_y+*(d - 1), draw_x + p->data[0], draw_y + p->data[1], b); 1071 } 1072 } 1073 } 1074 } 1075 } 1076 } 1077 1078 // if(!(dev & EDIT_MODE)) 1083 1079 // server_check(); 1084 1080 1085 if 1086 { 1087 if (help_text_frames>=0)1088 { 1089 1090 1091 if (help_text_frames<10)1092 color =2;1093 1094 color =2+(help_text_frames-10);1095 1096 int x1=v->cx1,y1=v->cy1,x2=v->cx2,y2=v->cy1+eh->font()->height()+10;1097 1098 remap_area(screen,x1,y1,x2,y2,white_light+40*256);1099 screen->bar(x1,y1,x2,y1,color);1100 screen->bar(x1,y2,x2,y2,color);1101 1102 eh->font()->put_string(screen,x1+5,y1+5,1103 help_text,color);1104 if (color>30)1105 help_text_frames =-1;1106 1107 1108 } 1109 } 1110 1111 if 1112 dev_cont->dev_draw(v); 1113 if 1114 cash.img(vmm_image)->put_image(screen, v->cx1,v->cy2-cash.img(vmm_image)->height()+1);1115 1116 if (dev&DRAW_LIGHTS)1117 { 1118 if 1119 { 1120 double_light_screen(screen,xoff,yoff,white_light,v->ambient,old_screen,old_cx1,old_cy1);1121 1122 v->cx1=old_cx1;1123 v->cy1=old_cy1;1124 v->cx2=old_cx2;1125 v->cy2=old_cy2;1126 screen=old_screen;1081 if(dev & DRAW_HELP_LAYER) 1082 { 1083 if(help_text_frames >= 0) 1084 { 1085 int color; 1086 1087 if(help_text_frames < 10) 1088 color = 2; 1089 else 1090 color = 2+(help_text_frames - 10); 1091 1092 int x1 = v->cx1, y1 = v->cy1, x2 = v->cx2, y2 = v->cy1 + eh->font()->height()+10; 1093 1094 remap_area(screen, x1, y1, x2, y2, white_light + 40 * 256); 1095 screen->bar(x1, y1, x2, y1, color); 1096 screen->bar(x1, y2, x2, y2, color); 1097 1098 eh->font()->put_string(screen, x1 + 5, y1 + 5, 1099 help_text, color); 1100 if(color > 30) 1101 help_text_frames = -1; 1102 else help_text_frames++; 1103 1104 } 1105 } 1106 1107 if(dev_cont) 1108 dev_cont->dev_draw(v); 1109 if(cash.in_use()) 1110 cash.img(vmm_image)->put_image(screen, v->cx1, v->cy2 - cash.img(vmm_image)->height()+1); 1111 1112 if(dev & DRAW_LIGHTS) 1113 { 1114 if(small_render) 1115 { 1116 double_light_screen(screen, xoff, yoff, white_light, v->ambient, old_screen, old_cx1, old_cy1); 1117 1118 v->cx1 = old_cx1; 1119 v->cy1 = old_cy1; 1120 v->cx2 = old_cx2; 1121 v->cy2 = old_cy2; 1122 screen = old_screen; 1127 1123 } else 1128 { 1129 1130 if (xres*yres<=64000)1131 light_screen(screen, xoff,yoff,white_light,v->ambient);1132 else light_screen(screen,xoff,yoff,white_light,63); // no lighting for hi-rez1124 { 1125 screen->dirt_on(); 1126 if(xres * yres <= 64000) 1127 light_screen(screen, xoff, yoff, white_light, v->ambient); 1128 else light_screen(screen, xoff, yoff, white_light, 63); // no lighting for hi - rez 1133 1129 } 1134 1130 1135 } else 1131 } else 1136 1132 screen->dirt_on(); 1137 1133 … … 1141 1137 screen->dirt_on(); 1142 1138 1143 rand_on =ro; // restore random start in case in draw funs moved it1139 rand_on = ro; // restore random start in case in draw funs moved it 1144 1140 // ... not every machine will draw the same thing 1145 1141 1146 1142 post_render(); 1147 1143 1148 screen->set_clip(cx1, cy1,cx2,cy2);1149 1150 1151 1152 1153 if 1144 screen->set_clip(cx1, cy1, cx2, cy2); 1145 1146 1147 1148 1149 if(playing_state(state)) // draw stuff outside the clipping region 1154 1150 v->draw_character_damage(); 1155 1151 1156 if 1152 if(profiling()) 1157 1153 profile_update(); 1158 1154 … … 1161 1157 1162 1158 void game::put_fg(int x, int y, int type) 1163 { 1164 if (current_level->get_fg(x,y)!=type)1165 { 1166 current_level->put_fg(x, y,type);1167 for (view *f=first_view;f;f=f->next)1168 if 1169 draw_map(f); 1170 /* put_block_bg(x, y,get_bg(current_level->get_bg(x/ASPECT,y/ASPECT))->im);1171 if (type>BLACK)1172 put_block_fg(x, y,get_fg(type)->im); */1159 { 1160 if(current_level->get_fg(x, y)!=type) 1161 { 1162 current_level->put_fg(x, y, type); 1163 for(view *f = first_view; f; f = f->next) 1164 if(f->drawable()) 1165 draw_map(f); 1166 /* put_block_bg(x, y, get_bg(current_level->get_bg(x / ASPECT, y / ASPECT))->im); 1167 if(type > BLACK) 1168 put_block_fg(x, y, get_fg(type)->im); */ 1173 1169 } 1174 1170 } … … 1176 1172 void game::put_bg(int x, int y, int type) 1177 1173 { 1178 if (current_level->get_bg(x,y)!=type)1179 { 1180 current_level->put_bg(x, y,type);1181 for (view *f=first_view;f;f=f->next)1182 if 1183 draw_map(f); 1184 /* put_block_bg(x, y,get_bg(type)->im);1185 if (current_level->get_fg(x,y)>BLACK)1186 put_block_fg(x, y,get_fg(current_level->get_fg(x,y))->im);*/1174 if(current_level->get_bg(x, y)!=type) 1175 { 1176 current_level->put_bg(x, y, type); 1177 for(view *f = first_view; f; f = f->next) 1178 if(f->drawable()) 1179 draw_map(f); 1180 /* put_block_bg(x, y, get_bg(type)->im); 1181 if(current_level->get_fg(x, y)>BLACK) 1182 put_block_fg(x, y, get_fg(current_level->get_fg(x, y))->im); */ 1187 1183 } 1188 1184 } … … 1190 1186 int game::in_area(event &ev, int x1, int y1, int x2, int y2) 1191 1187 { 1192 return (last_demo_mx >=x1 && last_demo_mx<=x2 &&1193 last_demo_my>=y1 && last_demo_my<=y2);1188 return (last_demo_mx >= x1 && last_demo_mx <= x2 && 1189 last_demo_my >= y1 && last_demo_my <= y2); 1194 1190 } 1195 1191 1196 1192 void game::request_level_load(char *name) 1197 1193 { 1198 strcpy(req_name, name);1194 strcpy(req_name, name); 1199 1195 } 1200 1196 … … 1203 1199 void fade_in(image *im, int steps) 1204 1200 { 1205 palette *old_pal =pal->copy();1201 palette *old_pal = pal->copy(); 1206 1202 int i; 1207 if 1203 if(im) 1208 1204 { 1209 1205 screen->clear(); 1210 im->put_image(screen, (xres+1)/2-im->width()/2,(yres+1)/2-im->height()/2);1211 } 1212 1213 for (i=0;i<steps;i++)1214 { 1215 uint8_t *sl1=(uint8_t *)pal->addr(); 1216 uint8_t *sl2=(uint8_t *)old_pal->addr(); 1206 im->put_image(screen, (xres + 1)/2 - im->width()/2, (yres + 1)/2 - im->height()/2); 1207 } 1208 1209 for(i = 0; i < steps; i++) 1210 { 1211 uint8_t *sl1=(uint8_t *)pal->addr(); 1212 uint8_t *sl2=(uint8_t *)old_pal->addr(); 1217 1213 int j; 1218 int v=(i +1)*256/steps;1219 for (j=0;j<256;j++)1220 { 1221 *(sl1)=((int)*(sl2))*v /256; sl1++; sl2++;1222 *(sl1)=((int)*(sl2))*v /256; sl1++; sl2++;1223 *(sl1)=((int)*(sl2))*v /256; sl1++; sl2++;1214 int v=(i + 1)*256 / steps; 1215 for(j = 0; j < 256; j++) 1216 { 1217 *(sl1)=((int)*(sl2))*v / 256; sl1++; sl2++; 1218 *(sl1)=((int)*(sl2))*v / 256; sl1++; sl2++; 1219 *(sl1)=((int)*(sl2))*v / 256; sl1++; sl2++; 1224 1220 } 1225 1221 pal->load(); … … 1228 1224 } 1229 1225 delete pal; 1230 pal =old_pal;1226 pal = old_pal; 1231 1227 } 1232 1228 1233 1229 void fade_out(int steps) 1234 1230 { 1235 palette *old_pal =pal->copy();1231 palette *old_pal = pal->copy(); 1236 1232 int i; 1237 for (i=0;i<steps;i++)1238 { 1239 uint8_t *sl1=(uint8_t *)pal->addr(); 1240 uint8_t *sl2=(uint8_t *)old_pal->addr(); 1233 for(i = 0; i < steps; i++) 1234 { 1235 uint8_t *sl1=(uint8_t *)pal->addr(); 1236 uint8_t *sl2=(uint8_t *)old_pal->addr(); 1241 1237 int j; 1242 int v=(steps -i)*256/steps;1243 for (j=0;j<256;j++)1244 { 1245 *(sl1)=((int)*(sl2))*v /256; sl1++; sl2++;1246 *(sl1)=((int)*(sl2))*v /256; sl1++; sl2++;1247 *(sl1)=((int)*(sl2))*v /256; sl1++; sl2++;1238 int v=(steps - i)*256 / steps; 1239 for(j = 0; j < 256; j++) 1240 { 1241 *(sl1)=((int)*(sl2))*v / 256; sl1++; sl2++; 1242 *(sl1)=((int)*(sl2))*v / 256; sl1++; sl2++; 1243 *(sl1)=((int)*(sl2))*v / 256; sl1++; sl2++; 1248 1244 } 1249 1245 pal->load(); … … 1254 1250 eh->flush_screen(); 1255 1251 delete pal; 1256 pal =old_pal;1257 1252 pal = old_pal; 1253 1258 1254 pal->load(); 1259 1255 } … … 1263 1259 void do_title() 1264 1260 { 1265 if( cdc_logo != -1)1266 1267 if( sound_avail & MUSIC_INITIALIZED)1268 1269 if( current_song)1270 1271 1272 1273 1274 current_song=new song("music/intro.hmi");1275 1276 1277 1278 void *logo_snd = symbol_value( make_find_symbol( "LOGO_SND" ));1279 1280 if( DEFINEDP( logo_snd ) && ( sound_avail & SFX_INITIALIZED ))1281 cash.sfx( lnumber_value( logo_snd ) )->play( sfx_volume);1282 1283 1284 1285 1286 1287 image *blank = new image( 2, 2);1288 1289 eh->set_mouse_shape( blank->copy(), 0, 0); // hide mouse1290 1291 fade_in( cash.img( cdc_logo ), 32);1292 1293 milli_wait( 900);1294 1295 void *space_snd = symbol_value( make_find_symbol( "SPACE_SND" ));1296 1297 fade_out( 32);1298 milli_wait( 300);1299 1300 1301 char *str = lstring_value( eval( make_find_symbol( "plot_start" ) ));1302 1303 bFILE *fp = open_file( "art/smoke.spe", "rb");1304 if( !fp->open_failure())1305 1306 spec_directory sd( fp);1307 1308 pal = new palette( sd.find( SPEC_PALETTE ), fp);1309 pal->shift( 1);1310 1311 image *gray = new image( sd.find( "gray_pict" ), fp);1312 1313 1314 1315 for( i = 0; i < 5; i++)1316 1317 sprintf( nm, "smoke%04d.pcx", i + 1);1318 smoke[i] = new image( sd.find( nm ), fp);1319 1320 1321 1322 1323 1324 int dx = ( xres + 1 ) / 2 - gray->width() / 2, dy = ( yres + 1) / 2 - gray->height() / 2;1325 gray->put_image( screen, dx, dy);1326 smoke[0]->put_image( screen, dx + 24, dy + 5);1327 1328 fade_in( NULL, 16);1329 1330 for( i = 0; i < 32; i++)1331 cmap[i] = pal->find_closest( i * 256 / 32, i * 256 / 32, i * 256 / 32);1332 1333 1334 ev.type=EV_SPURIOUS;1335 1336 1337 for( i = 0; i < 320 && ( ev.type != EV_KEY && ev.type != EV_MOUSE_BUTTON ); i++)1338 1339 gray->put_image( screen, dx, dy);1340 smoke[i % 5]->put_image( screen, dx + 24, dy + 5);1341 text_draw( 205 - i, dx + 15, dy, dx + 320 - 15, dy + 199, str, eh->font(), cmap, eh->bright_color());1342 1343 1344 1345 while( now.diff_time( &start ) < 0.18)1346 1347 1348 1349 1350 1351 1352 1353 while(eh->event_waiting() && ev.type != EV_KEY)1354 1355 1356 1357 if( ( i % 5 ) == 0 && DEFINEDP( space_snd ) && ( sound_avail & SFX_INITIALIZED ))1358 1359 cash.sfx( lnumber_value( space_snd ) )->play( sfx_volume * 90 / 127);1360 1361 1362 1363 1364 1365 1366 1367 for( i = 0; i < 5; i++)1368 1369 1370 1371 1372 1373 1374 1375 for( i = 0; i < 100 && !abort; i++)1376 1377 1378 1379 if( title_screen >= 0)1380 fade_in( cash.img( title_screen ), 32);1381 1382 eh->set_mouse_shape( cash.img( c_normal )->copy(), 1, 1);1383 1261 if(cdc_logo != -1) 1262 { 1263 if(sound_avail & MUSIC_INITIALIZED) 1264 { 1265 if(current_song) 1266 { 1267 current_song->stop(); 1268 delete current_song; 1269 } 1270 current_song = new song("music/intro.hmi"); 1271 current_song->play(music_volume); 1272 } 1273 1274 void *logo_snd = symbol_value(make_find_symbol("LOGO_SND")); 1275 1276 if(DEFINEDP(logo_snd) && (sound_avail & SFX_INITIALIZED)) 1277 cash.sfx(lnumber_value(logo_snd))->play(sfx_volume); 1278 1279 // This must be a dynamic allocated image because if it 1280 // is not and the window gets closed during do_title, then 1281 // exit() will try to delete (through the desctructor of 1282 // image_list in image.cpp) the image on the stack -> boom. 1283 image *blank = new image(2, 2); 1284 blank->clear(); 1285 eh->set_mouse_shape(blank->copy(), 0, 0); // hide mouse 1286 delete blank; 1287 fade_in(cash.img(cdc_logo), 32); 1288 1289 milli_wait(900); 1290 1291 void *space_snd = symbol_value(make_find_symbol("SPACE_SND")); 1292 1293 fade_out(32); 1294 milli_wait(300); 1295 1296 int i, abort = 0; 1297 char *str = lstring_value(eval(make_find_symbol("plot_start"))); 1298 1299 bFILE *fp = open_file("art/smoke.spe", "rb"); 1300 if(!fp->open_failure()) 1301 { 1302 spec_directory sd(fp); 1303 palette *old_pal = pal; 1304 pal = new palette(sd.find(SPEC_PALETTE), fp); 1305 pal->shift(1); 1306 1307 image *gray = new image(sd.find("gray_pict"), fp); 1308 image *smoke[5]; 1309 1310 char nm[20]; 1311 for(i = 0; i < 5; i++) 1312 { 1313 sprintf(nm, "smoke%04d.pcx", i + 1); 1314 smoke[i] = new image(sd.find(nm), fp); 1315 } 1316 1317 screen->clear(); 1318 pal->load(); 1319 1320 int dx = (xres + 1) / 2 - gray->width() / 2, dy = (yres + 1) / 2 - gray->height() / 2; 1321 gray->put_image(screen, dx, dy); 1322 smoke[0]->put_image(screen, dx + 24, dy + 5); 1323 1324 fade_in(NULL, 16); 1325 uint8_t cmap[32]; 1326 for(i = 0; i < 32; i++) 1327 cmap[i] = pal->find_closest(i * 256 / 32, i * 256 / 32, i * 256 / 32); 1328 1329 event ev; 1330 ev.type = EV_SPURIOUS; 1331 time_marker start; 1332 1333 for(i = 0; i < 320 && (ev.type != EV_KEY && ev.type != EV_MOUSE_BUTTON); i++) 1334 { 1335 gray->put_image(screen, dx, dy); 1336 smoke[i % 5]->put_image(screen, dx + 24, dy + 5); 1337 text_draw(205 - i, dx + 15, dy, dx + 320 - 15, dy + 199, str, eh->font(), cmap, eh->bright_color()); 1338 eh->flush_screen(); 1339 time_marker now; 1340 1341 while(now.diff_time(&start) < 0.18) 1342 { 1343 milli_wait(20); // ECS - Added the wait, so CPU utilization stays low during the story 1344 now.get_time(); 1345 } 1346 1347 start.get_time(); 1348 1349 while(eh->event_waiting() && ev.type != EV_KEY) 1350 { 1351 eh->get_event(ev); 1352 } 1353 if((i % 5) == 0 && DEFINEDP(space_snd) && (sound_avail & SFX_INITIALIZED)) 1354 { 1355 cash.sfx(lnumber_value(space_snd))->play(sfx_volume * 90 / 127); 1356 } 1357 } 1358 1359 the_game->reset_keymap(); 1360 1361 fade_out(16); 1362 1363 for(i = 0; i < 5; i++) 1364 delete smoke[i]; 1365 delete gray; 1366 delete pal; 1367 pal = old_pal; 1368 } 1369 delete fp; 1370 1371 for(i = 0; i < 100 && !abort; i++) 1372 { 1373 } 1374 1375 if(title_screen >= 0) 1376 fade_in(cash.img(title_screen), 32); 1377 1378 eh->set_mouse_shape(cash.img(c_normal)->copy(), 1, 1); 1379 } 1384 1380 } 1385 1381 … … 1388 1384 void game::request_end() 1389 1385 { 1390 req_end =1;1386 req_end = 1; 1391 1387 } 1392 1388 … … 1400 1396 int i; 1401 1397 req_name[0]=0; 1402 bg_xmul =bg_ymul=1;1403 bg_xdiv =bg_ydiv=8;1404 last_input =NULL;1405 current_automap =NULL;1406 current_level =NULL;1407 refresh =1;1408 the_game =this;1409 top_menu =joy_win=NULL;1410 old_view =first_view=NULL;1411 nplayers =1;1412 1413 help_text_frames =0;1414 strcpy(help_text, "");1415 1416 1417 for (i=1;i<argc;i++)1418 if (!strcmp(argv[i],"-no_delay"))1419 { 1420 no_delay =1;1398 bg_xmul = bg_ymul = 1; 1399 bg_xdiv = bg_ydiv = 8; 1400 last_input = NULL; 1401 current_automap = NULL; 1402 current_level = NULL; 1403 refresh = 1; 1404 the_game = this; 1405 top_menu = joy_win = NULL; 1406 old_view = first_view = NULL; 1407 nplayers = 1; 1408 1409 help_text_frames = 0; 1410 strcpy(help_text, ""); 1411 1412 1413 for(i = 1; i < argc; i++) 1414 if(!strcmp(argv[i], "-no_delay")) 1415 { 1416 no_delay = 1; 1421 1417 dprintf("Frame delay off (-nodelay)\n"); 1422 1418 } 1423 1419 1424 1425 image_init(); 1426 zoom =15;1427 no_delay =0;1428 1429 if (get_option("-use_joy"))1430 { 1431 has_joystick =joy_init(argc,argv);1420 1421 image_init(); 1422 zoom = 15; 1423 no_delay = 0; 1424 1425 if(get_option("-use_joy")) 1426 { 1427 has_joystick = joy_init(argc, argv); 1432 1428 dprintf("Joystick : "); 1433 if 1429 if(has_joystick) dprintf("detected\n"); 1434 1430 else dprintf("not detected\n"); 1435 1431 } 1436 else has_joystick =0;1437 1438 // 1439 1440 fastpath = (char *)jmalloc( strlen( get_save_filename_prefix() ) + 12 + 1, "fastpath");1441 sprintf( fastpath, "%sfastload.dat", get_save_filename_prefix());1442 fast_load_start_recording( fastpath);1443 load_data(argc,argv); 1444 1445 jfree( fastpath);1446 // ProfilerDump("\pabuse.prof"); //prof1447 // 1432 else has_joystick = 0; 1433 1434 // ProfilerInit(collectDetailed, bestTimeBase, 2000, 200); //prof 1435 char *fastpath; 1436 fastpath = (char *)jmalloc(strlen(get_save_filename_prefix()) + 12 + 1, "fastpath"); 1437 sprintf(fastpath, "%sfastload.dat", get_save_filename_prefix()); 1438 fast_load_start_recording(fastpath); 1439 load_data(argc, argv); 1440 fast_load_stop_recording(); 1441 jfree(fastpath); 1442 // ProfilerDump("\pabuse.prof"); //prof 1443 // ProfilerTerm(); 1448 1444 1449 1445 get_key_bindings(); 1450 1446 1451 1447 reset_keymap(); // we think all the keys are up right now 1452 finished =0;1448 finished = 0; 1453 1449 1454 1450 calc_light_table(pal); 1455 1451 1456 if (current_level==NULL && net_start()) // if we joined a net game get level from server1457 { 1458 if 1452 if(current_level == NULL && net_start()) // if we joined a net game get level from server 1453 { 1454 if(!request_server_entry()) 1459 1455 { 1460 1456 exit(0); 1461 1457 } 1462 1458 net_reload(); 1463 // load_level(NET_STARTFILE); 1464 } 1465 1466 1467 set_mode(19, argc,argv);1468 if (get_option("-2") && (xres<639 || yres<399))1459 // load_level(NET_STARTFILE); 1460 } 1461 1462 1463 set_mode(19, argc, argv); 1464 if(get_option("-2") && (xres < 639 || yres < 399)) 1469 1465 { 1470 1466 close_graphics(); 1471 fprintf(stderr, "Resolution must be > 640x400 to use -2 option\n");1467 fprintf(stderr, "Resolution must be > 640x400 to use -2 option\n"); 1472 1468 exit(0); 1473 1469 } 1474 1470 pal->load(); 1475 1471 1476 1472 recalc_local_view_space(); // now that we know what size the screen is... 1477 1473 1478 dark_color =get_color(cash.img(window_colors)->pixel(2,0));1479 bright_color =get_color(cash.img(window_colors)->pixel(0,0));1480 med_color =get_color(cash.img(window_colors)->pixel(1,0));1481 1482 morph_dark_color =get_color(cash.img(window_colors)->pixel(2,1));1483 morph_bright_color =get_color(cash.img(window_colors)->pixel(0,1));1484 morph_med_color =get_color(cash.img(window_colors)->pixel(1,1));1485 morph_sel_frame_color =pal->find_closest(255,255,0);1486 light_connection_color =morph_sel_frame_color;1487 1488 if 1474 dark_color = get_color(cash.img(window_colors)->pixel(2, 0)); 1475 bright_color = get_color(cash.img(window_colors)->pixel(0, 0)); 1476 med_color = get_color(cash.img(window_colors)->pixel(1, 0)); 1477 1478 morph_dark_color = get_color(cash.img(window_colors)->pixel(2, 1)); 1479 morph_bright_color = get_color(cash.img(window_colors)->pixel(0, 1)); 1480 morph_med_color = get_color(cash.img(window_colors)->pixel(1, 1)); 1481 morph_sel_frame_color = pal->find_closest(255, 255, 0); 1482 light_connection_color = morph_sel_frame_color; 1483 1484 if(NILP(symbol_value(l_default_font))) 1489 1485 { 1490 1486 printf("No font defined, set symbol default-font to an image name\n"); … … 1492 1488 } 1493 1489 int font_pict; 1494 if (big_font_pict!=-1)1495 { 1496 if (small_font_pict!=-1)1497 { 1498 if 1499 { 1500 font_pict=big_font_pict;1501 } 1502 else font_pict =small_font_pict;1503 } else font_pict =big_font_pict;1504 } else font_pict =small_font_pict;1505 1506 if (console_font_pict==-1) console_font_pict=font_pict;1507 game_font =new JCFont(cash.img(font_pict));1508 1509 console_font =new JCFont(cash.img(console_font_pict));1510 1511 eh =new window_manager(screen,pal,bright_color,1490 if(big_font_pict != -1) 1491 { 1492 if(small_font_pict != -1) 1493 { 1494 if(xres/(start_doubled ? 2 : 1)>400) 1495 { 1496 font_pict = big_font_pict; 1497 } 1498 else font_pict = small_font_pict; 1499 } else font_pict = big_font_pict; 1500 } else font_pict = small_font_pict; 1501 1502 if(console_font_pict == -1) console_font_pict = font_pict; 1503 game_font = new JCFont(cash.img(font_pict)); 1504 1505 console_font = new JCFont(cash.img(console_font_pict)); 1506 1507 eh = new window_manager(screen, pal, bright_color, 1512 1508 med_color, 1513 1509 dark_color, 1514 game_font); 1510 game_font); 1515 1511 1516 1512 delete stat_man; // move to a graphical status manager 1517 gui_status_manager *gstat =new gui_status_manager(eh);1513 gui_status_manager *gstat = new gui_status_manager(eh); 1518 1514 gstat->set_window_title("status"); 1519 stat_man =gstat;1520 1521 1522 chat =new chat_console(eh,console_font,50,6);1523 1524 if 1515 stat_man = gstat; 1516 1517 1518 chat = new chat_console(eh, console_font, 50, 6); 1519 1520 if(!eh->has_mouse()) 1525 1521 { 1526 1522 close_graphics(); … … 1533 1529 gamma_correct(pal); 1534 1530 1535 if (main_net_cfg==NULL || (main_net_cfg->state!=net_configuration::SERVER &&1536 main_net_cfg->state!=net_configuration::CLIENT))1537 { 1538 if 1531 if(main_net_cfg == NULL || (main_net_cfg->state != net_configuration::SERVER && 1532 main_net_cfg->state != net_configuration::CLIENT)) 1533 { 1534 if(!start_edit && !net_start()) 1539 1535 do_title(); 1540 } else if (main_net_cfg && main_net_cfg->state==net_configuration::SERVER)1536 } else if(main_net_cfg && main_net_cfg->state == net_configuration::SERVER) 1541 1537 { 1542 1538 the_game->load_level(level_file); 1543 start_running =1;1544 } 1545 1539 start_running = 1; 1540 } 1541 1546 1542 1547 1543 dev|= DRAW_FG_LAYER | DRAW_BG_LAYER | DRAW_PEOPLE_LAYER | DRAW_HELP_LAYER | DRAW_LIGHTS | DRAW_LINKS; 1548 1544 1549 if 1545 if(dev & EDIT_MODE) 1550 1546 set_frame_size(0); 1551 1547 // do_intro(); 1552 state =START_STATE; // first set the state to one that has windows1553 1554 1555 if 1548 state = START_STATE; // first set the state to one that has windows 1549 1550 1551 if(start_running) 1556 1552 set_state(RUN_STATE); 1557 1553 else 1558 1554 { 1559 screen->clear(); 1560 if (title_screen>=0)1561 { 1562 image *tit =cash.img(title_screen);1563 tit->put_image(screen, screen->width()/2-tit->width()/2,1564 screen->height()/2-tit->height()/2);1565 } 1555 screen->clear(); 1556 if(title_screen >= 0) 1557 { 1558 image *tit = cash.img(title_screen); 1559 tit->put_image(screen, screen->width()/2 - tit->width()/2, 1560 screen->height()/2 - tit->height()/2); 1561 } 1566 1562 set_state(MENU_STATE); // then go to menu state so windows will turn off 1567 1563 } … … 1570 1566 1571 1567 1572 time_marker *led_last_time =NULL,*fps_mark_start=NULL;1573 double avg_fps =15.0,possible_fps=15.0;1568 time_marker *led_last_time = NULL, *fps_mark_start = NULL; 1569 double avg_fps = 15.0, possible_fps = 15.0; 1574 1570 1575 1571 void game::toggle_delay() 1576 1572 { 1577 1573 no_delay=!no_delay; 1578 if 1574 if(no_delay) 1579 1575 show_help(symbol_str("delay_off")); 1580 1576 else show_help(symbol_str("delay_on")); 1581 avg_fps =possible_fps=15.0;1577 avg_fps = possible_fps = 15.0; 1582 1578 } 1583 1579 1584 1580 void game::show_time() 1585 1581 { 1586 if 1582 if(first_view && fps_on) 1587 1583 { 1588 1584 char str[10]; 1589 sprintf(str, "%ld",(long)(avg_fps*10.0));1590 console_font->put_string(screen, first_view->cx1,first_view->cy1,str);1591 1592 sprintf(str, "%d",total_active);1593 console_font->put_string(screen, first_view->cx1,first_view->cy1+10,str);1585 sprintf(str, "%ld", (long)(avg_fps * 10.0)); 1586 console_font->put_string(screen, first_view->cx1, first_view->cy1, str); 1587 1588 sprintf(str, "%d", total_active); 1589 console_font->put_string(screen, first_view->cx1, first_view->cy1 + 10, str); 1594 1590 } 1595 1591 } … … 1597 1593 void game::update_screen() 1598 1594 { 1599 if (state==HELP_STATE)1595 if(state == HELP_STATE) 1600 1596 draw_help(); 1601 else if 1602 { 1603 if (!(dev & EDIT_MODE) || refresh)1604 { 1605 view *f =first_view;1597 else if(current_level) 1598 { 1599 if(!(dev & EDIT_MODE) || refresh) 1600 { 1601 view *f = first_view; 1606 1602 current_level->clear_active_list(); 1607 for (;f;f=f->next)1608 { 1609 if (f->focus) 1610 1611 int w,h;1612 1613 w=(f->cx2-f->cx1+1);1614 h=(f->cy2-f->cy1+1);1615 1616 total_active+=current_level->add_drawables(f->xoff()-w/4,f->yoff()-h/4,1617 f->xoff()+w+w/4,f->yoff()+h+h/4);1618 1619 1603 for(; f; f = f->next) 1604 { 1605 if(f->focus) 1606 { 1607 int w, h; 1608 1609 w=(f->cx2 - f->cx1 + 1); 1610 h=(f->cy2 - f->cy1 + 1); 1611 1612 total_active += current_level->add_drawables(f->xoff()-w / 4, f->yoff()-h / 4, 1613 f->xoff()+w + w / 4, f->yoff()+h + h / 4); 1614 1615 } 1620 1616 } 1621 1617 1622 for (f=first_view;f;f=f->next) 1623 { 1624 if (f->drawable()) 1625 { 1626 if (interpolate_draw) 1627 { 1628 draw_map(f,1); 1629 eh->flush_screen(); 1630 } 1631 draw_map(f,0); 1632 } 1618 for(f = first_view; f; f = f->next) 1619 { 1620 if(f->drawable()) 1621 { 1622 if(interpolate_draw) 1623 { 1624 draw_map(f, 1); 1625 eh->flush_screen(); 1633 1626 } 1634 if (current_automap) 1627 draw_map(f, 0); 1628 } 1629 } 1630 if(current_automap) 1635 1631 current_automap->draw(); 1636 } 1637 if (state==PAUSE_STATE)1638 { 1639 for (view *f=first_view;f;f=f->next)1640 cash.img(pause_image)->put_image(screen, (f->cx1+f->cx2)/2-cash.img(pause_image)->width()/2,1641 f->cy1+5,1);1642 } 1643 1632 } 1633 if(state == PAUSE_STATE) 1634 { 1635 for(view *f = first_view; f; f = f->next) 1636 cash.img(pause_image)->put_image(screen, (f->cx1 + f->cx2)/2 - cash.img(pause_image)->width()/2, 1637 f->cy1 + 5, 1); 1638 } 1639 1644 1640 show_time(); 1645 1641 } 1646 1642 1647 if (state==RUN_STATE && cash.prof_is_on())1643 if(state == RUN_STATE && cash.prof_is_on()) 1648 1644 cash.prof_poll_end(); 1649 1645 … … 1659 1655 int game::calc_speed() 1660 1656 { 1661 int ret=0;1662 if( fps_mark_start)1663 1664 1665 1666 1667 double td=t.diff_time(fps_mark_start);1668 if (td<0.001) // something is rotten in the state of demark1669 td=0.001;1670 1671 avg_fps=avg_fps*9.0/10.0+1.0/(td*10.0); 1672 possible_fps=possible_fps*9.0/10.0+1.0/(td*10.0); 1673 1674 if (avg_fps>14)1675 1676 if (massive_frame_panic>20)1677 massive_frame_panic=20;1678 else if(massive_frame_panic)1679 1680 1681 1682 if (avg_fps>15 && ((dev&EDIT_MODE)==0 || need_delay))1683 1684 1685 int32_t stime=(int32_t)((1/15.0-1.0/possible_fps)*1000.0); 1686 if (stime>0 && !no_delay)1687 1688 1689 avg_fps-=1.0/(td*10.0); // subtract out old estimate1690 1691 1692 1693 1694 double td=t.diff_time(fps_mark_start);1695 if (td<0.00001) // something is rotten in the state of demark1696 td=0.00001;1697 1698 avg_fps+=1.0/(td*10.0); // add in new estimate1699 1700 1701 else if (avg_fps<14)1702 1703 if (avg_fps<10)1704 1705 1706 ret=1;1707 1708 else if( dev & EDIT_MODE)1709 1710 1711 1712 1713 1714 1715 delete fps_mark_start; 1716 1717 fps_mark_start=new time_marker;1718 1657 int ret = 0; 1658 if(fps_mark_start) 1659 { 1660 time_marker t; 1661 1662 // find average fps for last 10 frames 1663 double td = t.diff_time(fps_mark_start); 1664 if(td < 0.001) // something is rotten in the state of demark 1665 td = 0.001; 1666 1667 avg_fps = avg_fps * 9.0 / 10.0 + 1.0/(td * 10.0); 1668 possible_fps = possible_fps * 9.0 / 10.0 + 1.0/(td * 10.0); 1669 1670 if(avg_fps > 14) 1671 { 1672 if(massive_frame_panic > 20) 1673 massive_frame_panic = 20; 1674 else if(massive_frame_panic) 1675 massive_frame_panic--; 1676 } 1677 1678 if(avg_fps > 15 && ((dev & EDIT_MODE)==0 || need_delay)) 1679 { 1680 frame_panic = 0; 1681 int32_t stime=(int32_t)((1 / 15.0 - 1.0 / possible_fps)*1000.0); 1682 if(stime > 0 && !no_delay) 1683 { 1684 milli_wait(stime); 1685 avg_fps -= 1.0/(td * 10.0); // subtract out old estimate 1686 1687 time_marker t; 1688 1689 // find average fps for last 10 frames 1690 double td = t.diff_time(fps_mark_start); 1691 if(td < 0.00001) // something is rotten in the state of demark 1692 td = 0.00001; 1693 1694 avg_fps += 1.0/(td * 10.0); // add in new estimate 1695 } 1696 } 1697 else if(avg_fps < 14) 1698 { 1699 if(avg_fps < 10) 1700 massive_frame_panic++; 1701 frame_panic++; 1702 ret = 1; 1703 } 1704 else if(dev & EDIT_MODE) 1705 { 1706 // ECS - Added this case and the wait. It's a cheap hack to assure that 1707 // we don't exceed 30FPS in edit mode and hog the CPU. 1708 milli_wait(33); 1709 } 1710 1711 delete fps_mark_start; 1712 } 1713 fps_mark_start = new time_marker; 1714 return ret; 1719 1715 } 1720 1716 … … 1723 1719 void game::get_input() 1724 1720 { 1725 1726 1727 while( event_waiting( eh ))1728 1729 get_event(ev,eh);1730 1731 if(ev.type == EV_MOUSE_MOVE)1732 1733 1734 1735 1736 1737 1738 if( ev.type != EV_KEY || !key_down( ev.key ) || ev.window || ( dev & EDIT_MODE ))1739 1740 if( ev.type == EV_KEY)1741 1742 set_key_down( ev.key, 1);1743 if( playing_state( state ))1744 1745 if(ev.key < 256)1746 1747 if( chat && chat->chat_event( ev ))1748 base->packet.write_uint8( SCMD_CHAT_KEYPRESS);1749 1750 base->packet.write_uint8( SCMD_KEYPRESS);1751 1752 1753 base->packet.write_uint8( SCMD_EXT_KEYPRESS);1754 base->packet.write_uint8( client_number());1755 if( ev.key > 256)1756 base->packet.write_uint8( ev.key - 256);1757 1758 base->packet.write_uint8( ev.key);1759 1760 1761 else if(ev.type == EV_KEYRELEASE)1762 1763 set_key_down( ev.key, 0);1764 if( playing_state( state ))1765 1766 if( ev.key < 256)1767 base->packet.write_uint8( SCMD_KEYRELEASE);1768 1769 base->packet.write_uint8( SCMD_EXT_KEYRELEASE);1770 base->packet.write_uint8( client_number());1771 if( ev.key > 255)1772 base->packet.write_uint8( ev.key - 256);1773 1774 base->packet.write_uint8( ev.key);1775 1776 1777 1778 if( (dev & EDIT_MODE) || start_edit || ev.type == EV_MESSAGE)1779 1780 dev_cont->handle_event( ev);1781 1782 1783 1784 for( ; v; v = v->next)1785 1786 if( v->local_player() && v->handle_event( ev ))1787 ev.type=EV_SPURIOUS; // if the event was used by the view, gobble it up1788 1789 1790 if( current_automap)1791 1792 current_automap->handle_event( ev);1793 1794 1795 help_handle_event( ev);1796 1797 1798 1799 if(ev.type == EV_MESSAGE)1800 1801 1802 1803 1804 1805 if(!joy_win)1806 1807 int wx=WINDOW_FRAME_LEFT,wy=WINDOW_FRAME_TOP;1808 1809 joy_win=eh->new_window(80,50,-1,-1,1810 new button(wx+70,wy+9,JOY_OK,"OK",1811 new info_field(wx,wy+30,DEV_NULL,1812 1813 "press the fire button",NULL)),1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 else if(ev.type == EV_CLOSE_WINDOW && ev.window == top_menu)1829 1830 eh->close_window( top_menu);1831 1832 1833 1834 switch( state)1835 1836 1837 1838 1839 1840 1841 1842 1843 if(dev & EDIT_MODE)1844 1845 1846 set_state(MENU_STATE); 1847 1848 1849 1850 if( ev.type == EV_KEY && ( ev.key == JK_SPACE || ev.key == JK_ENTER ))1851 1852 set_state( RUN_STATE);1853 1854 1855 1856 1857 if (ev.window==NULL)1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 if( dev & MAP_MODE)1868 1869 else if( ( player_list && player_list->next ) || dev & EDIT_MODE)1870 1871 1872 if( !( dev & MAP_MODE ))1873 1874 if( dev_cont->tbw)1875 1876 1877 1878 1879 1880 1881 1882 eh->push_event(new event(DO_VOLUME,NULL));1883 1884 1885 1886 if (!(dev&EDIT_MODE) && (!main_net_cfg || 1887 (main_net_cfg->state!=net_configuration::SERVER &&1888 main_net_cfg->state!=net_configuration::CLIENT)))1889 1890 1891 1892 1893 1894 1895 if( start_edit)1896 1897 eh->push_event(new event(ID_LEVEL_SAVE,NULL));1898 1899 1900 1901 1902 if( start_edit)1903 1904 1905 1906 1907 1908 if( chatting_enabled && (!(dev&EDIT_MODE) && chat))1909 1910 1911 1912 1913 dev = dev^PERFORMANCE_TEST_MODE;1914 1915 1916 /* 1917 1918 1919 if(!dev_cont->need_plus_minus())1920 1921 if(eh->key_pressed(JK_CTRL_L))1922 1923 1924 1925 draw(state==SCENE_STATE);1926 1927 1928 1929 1930 make_screen_size(311,160);1931 1932 1933 1934 1935 if(!dev_cont->need_plus_minus())1936 1937 if(eh->key_pressed(JK_CTRL_L))1938 1939 1940 1941 draw(state==SCENE_STATE); 1942 1943 1721 event ev; 1722 idle_ticks++; 1723 while(event_waiting(eh)) 1724 { 1725 get_event(ev, eh); 1726 1727 if(ev.type == EV_MOUSE_MOVE) 1728 { 1729 last_input = ev.window; 1730 } 1731 // don't process repeated keys in the main window, it will slow down the game to handle such 1732 // useless events. However in other windows it might be useful, such as in input windows 1733 // where you want to repeatedly scroll down... 1734 if(ev.type != EV_KEY || !key_down(ev.key) || ev.window || (dev & EDIT_MODE)) 1735 { 1736 if(ev.type == EV_KEY) 1737 { 1738 set_key_down(ev.key, 1); 1739 if(playing_state(state)) 1740 { 1741 if(ev.key < 256) 1742 { 1743 if(chat && chat->chat_event(ev)) 1744 base->packet.write_uint8(SCMD_CHAT_KEYPRESS); 1745 else 1746 base->packet.write_uint8(SCMD_KEYPRESS); 1747 } 1748 else 1749 base->packet.write_uint8(SCMD_EXT_KEYPRESS); 1750 base->packet.write_uint8(client_number()); 1751 if(ev.key > 256) 1752 base->packet.write_uint8(ev.key - 256); 1753 else 1754 base->packet.write_uint8(ev.key); 1755 } 1756 } 1757 else if(ev.type == EV_KEYRELEASE) 1758 { 1759 set_key_down(ev.key, 0); 1760 if(playing_state(state)) 1761 { 1762 if(ev.key < 256) 1763 base->packet.write_uint8(SCMD_KEYRELEASE); 1764 else 1765 base->packet.write_uint8(SCMD_EXT_KEYRELEASE); 1766 base->packet.write_uint8(client_number()); 1767 if(ev.key > 255) 1768 base->packet.write_uint8(ev.key - 256); 1769 else 1770 base->packet.write_uint8(ev.key); 1771 } 1772 } 1773 1774 if((dev & EDIT_MODE) || start_edit || ev.type == EV_MESSAGE) 1775 { 1776 dev_cont->handle_event(ev); 1777 } 1778 1779 view *v = first_view; 1780 for(; v; v = v->next) 1781 { 1782 if(v->local_player() && v->handle_event(ev)) 1783 ev.type = EV_SPURIOUS; // if the event was used by the view, gobble it up 1784 } 1785 1786 if(current_automap) 1787 { 1788 current_automap->handle_event(ev); 1789 } 1790 1791 help_handle_event(ev); 1792 mousex = last_demo_mx; 1793 mousey = last_demo_my; 1794 1795 if(ev.type == EV_MESSAGE) 1796 { 1797 switch (ev.message.id) 1798 { 1799 case CALB_JOY: 1800 { 1801 if(!joy_win) 1802 { 1803 int wx = WINDOW_FRAME_LEFT, wy = WINDOW_FRAME_TOP; 1804 1805 joy_win = eh->new_window(80, 50, -1, -1, 1806 new button(wx + 70, wy + 9, JOY_OK, "OK", 1807 new info_field(wx, wy + 30, DEV_NULL, 1808 " Center joystick and\n" 1809 "press the fire button", NULL)), 1810 "Joystick"); 1811 set_state(JOY_CALB_STATE); 1812 } 1813 } 1814 case TOP_MENU: 1815 { 1816 menu_select(ev); 1817 } break; 1818 case DEV_QUIT: 1819 { 1820 finished = 1; 1821 } break; 1822 } 1823 } 1824 else if(ev.type == EV_CLOSE_WINDOW && ev.window == top_menu) 1825 { 1826 eh->close_window(top_menu); 1827 top_menu = NULL; 1828 } 1829 1830 switch(state) 1831 { 1832 case JOY_CALB_STATE: 1833 { 1834 joy_calb(ev); 1835 } break; 1836 case INTRO_START_STATE: 1837 { 1838 do_intro(); 1839 if(dev & EDIT_MODE) 1840 set_state(RUN_STATE); 1841 else 1842 set_state(MENU_STATE); 1843 } break; 1844 case PAUSE_STATE: 1845 { 1846 if(ev.type == EV_KEY && (ev.key == JK_SPACE || ev.key == JK_ENTER)) 1847 { 1848 set_state(RUN_STATE); 1849 } 1850 } break; 1851 case RUN_STATE: 1852 { 1853 if(ev.window == NULL) 1854 { 1855 switch (ev.type) 1856 { 1857 case EV_KEY: 1858 { 1859 switch (ev.key) 1860 { 1861 case 'm': 1862 { 1863 if(dev & MAP_MODE) 1864 dev -= MAP_MODE; 1865 else if((player_list && player_list->next) || dev & EDIT_MODE) 1866 dev |= MAP_MODE; 1867 1868 if(!(dev & MAP_MODE)) 1869 { 1870 if(dev_cont->tbw) 1871 dev_cont->toggle_toolbar(); 1872 edit_mode = ID_DMODE_DRAW; 1873 } 1874 need_refresh(); 1875 } break; 1876 case 'v': 1877 { 1878 eh->push_event(new event(DO_VOLUME, NULL)); 1879 } break; 1880 case 'p': 1881 { 1882 if(!(dev & EDIT_MODE) && (!main_net_cfg || 1883 (main_net_cfg->state != net_configuration::SERVER && 1884 main_net_cfg->state != net_configuration::CLIENT))) 1885 { 1886 set_state(PAUSE_STATE); 1887 } 1888 } break; 1889 case 'S': 1890 { 1891 if(start_edit) 1892 { 1893 eh->push_event(new event(ID_LEVEL_SAVE, NULL)); 1894 } 1895 } break; 1896 case JK_TAB: 1897 { 1898 if(start_edit) 1899 toggle_edit_mode(); 1900 need_refresh(); 1901 } break; 1902 case 'c': 1903 { 1904 if(chatting_enabled && (!(dev & EDIT_MODE) && chat)) 1905 chat->toggle(); 1906 } break; 1907 case '9': 1908 { 1909 dev = dev ^ PERFORMANCE_TEST_MODE; 1910 need_refresh(); 1911 } break; 1912 /* case '=': 1913 case '+': 1914 { 1915 if(!dev_cont->need_plus_minus()) 1916 { 1917 if(eh->key_pressed(JK_CTRL_L)) 1918 grow_views(20); 1919 else 1920 grow_views(5); 1921 draw(state == SCENE_STATE); 1922 } 1923 } break; 1924 case JK_F10: 1925 { 1926 make_screen_size(311, 160); 1927 } break; 1928 case '_': 1929 case '-' : 1930 { 1931 if(!dev_cont->need_plus_minus()) 1932 { 1933 if(eh->key_pressed(JK_CTRL_L)) 1934 grow_views(-20); 1935 else 1936 grow_views(-5); 1937 draw(state == SCENE_STATE); 1938 } 1939 } break; 1944 1940 */ 1945 1946 1947 1948 1949 1950 for( v = first_view; v; v = v->next) // see if any views need to change size1951 1952 if(v->local_player())1953 1954 int w = (xres-10)/(small_render ? 2 : 1);1955 int h = (yres-10)/(small_render ? 2 : 1);1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 screen->add_dirty(ev.redraw.x1,ev.redraw.y1,1973 ev.redraw.x2,ev.redraw.y2);1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 if( ev.message.id == RAISE_SFX && sfx_volume != 127)1985 sfx_volume = min( 127, sfx_volume + 16);1986 if( ev.message.id == LOWER_SFX && sfx_volume != 0)1987 sfx_volume = max( sfx_volume - 16,0);1988 if( ev.message.id == RAISE_MUSIC && music_volume != 126)1989 1990 music_volume = min( music_volume + 16, 127);1991 if( current_song && ( sound_avail & MUSIC_INITIALIZED ))1992 current_song->set_volume( music_volume);1993 1994 1995 if( ev.message.id == LOWER_MUSIC && music_volume != 0)1996 1997 music_volume = max( music_volume - 16, 0);1998 if( current_song && (sound_avail & MUSIC_INITIALIZED ))1999 current_song->set_volume( music_volume);2000 2001 2002 2003 /* 2004 draw_value(volume_window->screen,WINDOW_FRAME_LEFT+2,WINDOW_FRAME_TOP+43,2005 (volume_window->x2()-volume_window->x1()-1),8, sfx_volume,127);2006 draw_value(volume_window->screen,WINDOW_FRAME_LEFT+2,WINDOW_FRAME_TOP+94,2007 (volume_window->x2()-volume_window->x1()-1),8, music_volume,127);1941 } 1942 } break; 1943 case EV_RESIZE: 1944 { 1945 view *v; 1946 for(v = first_view; v; v = v->next) // see if any views need to change size 1947 { 1948 if(v->local_player()) 1949 { 1950 int w = (xres - 10)/(small_render ? 2 : 1); 1951 int h = (yres - 10)/(small_render ? 2 : 1); 1952 1953 v->suggest.send_view = 1; 1954 v->suggest.cx1 = 5; 1955 v->suggest.cx2 = 5 + w; 1956 v->suggest.cy1 = 5; 1957 v->suggest.cy2 = 5 + h; 1958 v->suggest.pan_x = v->pan_x; 1959 v->suggest.pan_y = v->pan_y; 1960 v->suggest.shift_down = v->shift_down; 1961 v->suggest.shift_right = v->shift_right; 1962 } 1963 } 1964 draw(); 1965 } break; 1966 case EV_REDRAW: 1967 { 1968 screen->add_dirty(ev.redraw.x1, ev.redraw.y1, 1969 ev.redraw.x2, ev.redraw.y2); 1970 } break; 1971 case EV_MESSAGE: 1972 { 1973 switch (ev.message.id) 1974 { 1975 case RAISE_SFX: 1976 case LOWER_SFX: 1977 case RAISE_MUSIC: 1978 case LOWER_MUSIC: 1979 { 1980 if(ev.message.id == RAISE_SFX && sfx_volume != 127) 1981 sfx_volume = min(127, sfx_volume + 16); 1982 if(ev.message.id == LOWER_SFX && sfx_volume != 0) 1983 sfx_volume = max(sfx_volume - 16, 0); 1984 if(ev.message.id == RAISE_MUSIC && music_volume != 126) 1985 { 1986 music_volume = min(music_volume + 16, 127); 1987 if(current_song && (sound_avail & MUSIC_INITIALIZED)) 1988 current_song->set_volume(music_volume); 1989 } 1990 1991 if(ev.message.id == LOWER_MUSIC && music_volume != 0) 1992 { 1993 music_volume = max(music_volume - 16, 0); 1994 if(current_song && (sound_avail & MUSIC_INITIALIZED)) 1995 current_song->set_volume(music_volume); 1996 } 1997 1998 ((button *)ev.message.data)->push(); 1999 /* volume_window->inm->redraw(); 2000 draw_value(volume_window->screen, WINDOW_FRAME_LEFT + 2, WINDOW_FRAME_TOP + 43, 2001 (volume_window->x2()-volume_window->x1()-1), 8, sfx_volume, 127); 2002 draw_value(volume_window->screen, WINDOW_FRAME_LEFT + 2, WINDOW_FRAME_TOP + 94, 2003 (volume_window->x2()-volume_window->x1()-1), 8, music_volume, 127); 2008 2004 */ 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 } 2020 2021 2022 void net_send(int force =0)2023 { 2024 if ( (!(dev&EDIT_MODE)) || force)2025 { 2026 if (demo_man.state==demo_manager::PLAYING)2027 { 2028 base->input_state =INPUT_PROCESSING;2005 break; 2006 } 2007 } 2008 } 2009 } 2010 } 2011 } break; 2012 } 2013 } 2014 } 2015 } 2016 2017 2018 void net_send(int force = 0) 2019 { 2020 if((!(dev & EDIT_MODE)) || force) 2021 { 2022 if(demo_man.state == demo_manager::PLAYING) 2023 { 2024 base->input_state = INPUT_PROCESSING; 2029 2025 } else 2030 2026 { 2031 2032 2033 2034 if 2035 { 2036 2037 2027 2028 2029 2030 if(!player_list->focus) 2031 { 2032 dprintf("Players have not been created\ncall create_players"); 2033 exit(0); 2038 2034 } 2039 2035 2040 2036 2041 view *p =player_list;2042 for (;p;p=p->next)2043 if 2044 2037 view *p = player_list; 2038 for(; p; p = p->next) 2039 if(p->local_player()) 2040 p->get_input(); 2045 2041 2046 2042 … … 2048 2044 base->packet.write_uint16(make_sync()); 2049 2045 2050 if 2046 if(base->join_list) 2051 2047 base->packet.write_uint8(SCMD_RELOAD); 2052 2048 2053 // printf("save tick %d, pk size=%d, rand_on=%d, sync=%d\n", current_level->tick_counter(),2054 // base->packet.packet_size(),rand_on,make_sync());2049 // printf("save tick %d, pk size=%d, rand_on=%d, sync=%d\n", current_level->tick_counter(), 2050 // base->packet.packet_size(), rand_on, make_sync()); 2055 2051 send_local_request(); 2056 2052 } … … 2060 2056 void net_receive() 2061 2057 { 2062 if (!(dev&EDIT_MODE) && current_level)2063 { 2064 uint8_t buf[PACKET_MAX_SIZE +1];2058 if(!(dev & EDIT_MODE) && current_level) 2059 { 2060 uint8_t buf[PACKET_MAX_SIZE + 1]; 2065 2061 int size; 2066 2062 2067 if (demo_man.state==demo_manager::PLAYING)2068 { 2069 if (!demo_man.get_packet(buf,size))2070 size =0;2063 if(demo_man.state == demo_manager::PLAYING) 2064 { 2065 if(!demo_man.get_packet(buf, size)) 2066 size = 0; 2071 2067 base->packet.packet_reset(); 2072 base->mem_lock =0;2068 base->mem_lock = 0; 2073 2069 } else 2074 2070 { 2075 size =get_inputs_from_server(buf);2076 if (demo_man.state==demo_manager::RECORDING)2077 demo_man.save_packet(buf,size);2078 } 2079 2080 process_packet_commands(buf, size);2071 size = get_inputs_from_server(buf); 2072 if(demo_man.state == demo_manager::RECORDING) 2073 demo_man.save_packet(buf, size); 2074 } 2075 2076 process_packet_commands(buf, size); 2081 2077 } 2082 2078 } … … 2085 2081 { 2086 2082 clear_tmp(); 2087 if 2083 if(current_level) 2088 2084 { 2089 2085 current_level->unactivate_all(); 2090 total_active =0;2091 for (view *f=first_view;f;f=f->next)2092 { 2093 if (f->focus)2094 { 2095 2096 int w,h;2097 2098 w=(f->cx2-f->cx1+1);2099 h=(f->cy2-f->cy1+1);2100 total_active +=current_level->add_actives(f->xoff()-w/4,f->yoff()-h/4,2101 f->xoff()+w+w/4,f->yoff()+h+h/4);2086 total_active = 0; 2087 for(view *f = first_view; f; f = f->next) 2088 { 2089 if(f->focus) 2090 { 2091 f->update_scroll(); 2092 int w, h; 2093 2094 w=(f->cx2 - f->cx1 + 1); 2095 h=(f->cy2 - f->cy1 + 1); 2096 total_active += current_level->add_actives(f->xoff()-w / 4, f->yoff()-h / 4, 2097 f->xoff()+w + w / 4, f->yoff()+h + h / 4); 2102 2098 } 2103 2099 } 2104 2100 } 2105 2101 2106 if (state==RUN_STATE)2107 { 2108 if ((dev&EDIT_MODE) || (main_net_cfg && (main_net_cfg->state==net_configuration::CLIENT ||2109 main_net_cfg->state==net_configuration::SERVER)))2110 idle_ticks =0;2111 2112 if (demo_man.current_state()==demo_manager::NORMAL && idle_ticks>420 && demo_start)2113 { 2114 idle_ticks =0;2115 set_state(MENU_STATE); 2116 } 2117 else if 2118 { 2119 if 2120 { 2121 2122 set_key_down(JK_ESC,0);2102 if(state == RUN_STATE) 2103 { 2104 if((dev & EDIT_MODE) || (main_net_cfg && (main_net_cfg->state == net_configuration::CLIENT || 2105 main_net_cfg->state == net_configuration::SERVER))) 2106 idle_ticks = 0; 2107 2108 if(demo_man.current_state()==demo_manager::NORMAL && idle_ticks > 420 && demo_start) 2109 { 2110 idle_ticks = 0; 2111 set_state(MENU_STATE); 2112 } 2113 else if(!(dev & EDIT_MODE)) // if edit mode, then don't step anything 2114 { 2115 if(key_down(JK_ESC)) 2116 { 2117 set_state(MENU_STATE); 2118 set_key_down(JK_ESC, 0); 2123 2119 } 2124 ambient_ramp =0;2120 ambient_ramp = 0; 2125 2121 view *v; 2126 for (v=first_view;v;v=v->next)2122 for(v = first_view; v; v = v->next) 2127 2123 v->update_scroll(); 2128 2124 … … 2130 2126 current_level->tick(); 2131 2127 sbar.step(); 2132 } else 2133 dev_scroll(); 2134 } else if (state==JOY_CALB_STATE)2128 } else 2129 dev_scroll(); 2130 } else if(state == JOY_CALB_STATE) 2135 2131 { 2136 2132 event ev; 2137 2133 joy_calb(ev); 2138 } else if (state==MENU_STATE)2139 main_menu(); 2140 2141 if (key_down('x') && (key_down(JK_ALT_L) || key_down(JK_ALT_R)) && confirm_quit()) finished=1;2134 } else if(state == MENU_STATE) 2135 main_menu(); 2136 2137 if(key_down('x') && (key_down(JK_ALT_L) || key_down(JK_ALT_R)) && confirm_quit()) finished = 1; 2142 2138 } 2143 2139 … … 2146 2142 game::~game() 2147 2143 { 2148 current_demo =NULL;2149 if (first_view==player_list) first_view=NULL;2150 while 2151 { 2152 view *p =player_list;2153 game_object *o =p->focus;2154 player_list =player_list->next;2144 current_demo = NULL; 2145 if(first_view == player_list) first_view = NULL; 2146 while(player_list) 2147 { 2148 view *p = player_list; 2149 game_object *o = p->focus; 2150 player_list = player_list->next; 2155 2151 delete p; 2156 2152 o->set_controller(NULL); 2157 if 2153 if(current_level && o) 2158 2154 current_level->delete_object(o); 2159 2155 else delete o; 2160 2156 } 2161 2157 2162 if (current_level) { delete current_level; current_level=NULL; }2163 2164 if (first_view!=player_list)2165 { 2166 while 2167 { 2168 view *p =player_list;2169 player_list =player_list->next;2158 if(current_level) { delete current_level; current_level = NULL; } 2159 2160 if(first_view != player_list) 2161 { 2162 while(player_list) 2163 { 2164 view *p = player_list; 2165 player_list = player_list->next; 2170 2166 delete p; 2171 2167 } 2172 2168 } 2173 2169 2174 while 2175 { 2176 view *p =first_view;2177 first_view =first_view->next;2170 while(first_view) 2171 { 2172 view *p = first_view; 2173 first_view = first_view->next; 2178 2174 delete p; 2179 2175 } 2180 2176 2181 player_list =NULL;2182 2183 if 2184 { 2185 first_view =old_view;2186 while 2187 { 2188 view *p =first_view;2189 first_view =first_view->next;2177 player_list = NULL; 2178 2179 if(old_view) 2180 { 2181 first_view = old_view; 2182 while(first_view) 2183 { 2184 view *p = first_view; 2185 first_view = first_view->next; 2190 2186 delete p; 2191 2187 } 2192 2188 } 2193 old_view =NULL;2194 2195 int i =0;2196 for (;i<total_objects;i++)2189 old_view = NULL; 2190 2191 int i = 0; 2192 for(; i < total_objects; i++) 2197 2193 { 2198 2194 jfree(object_names[i]); … … 2200 2196 } 2201 2197 free_pframes(); 2202 if (fps_mark_start) delete fps_mark_start; fps_mark_start=NULL;2198 if(fps_mark_start) delete fps_mark_start; fps_mark_start = NULL; 2203 2199 delete pal; 2204 2200 jfree(object_names); … … 2207 2203 jfree(backtiles); 2208 2204 jfree(foretiles); 2209 if 2205 if(total_weapons) 2210 2206 jfree(weapon_types); 2211 2207 … … 2216 2212 delete big_font; 2217 2213 delete console_font; 2218 if 2214 if(total_help_screens) 2219 2215 jfree(help_screens); 2220 2216 2221 2217 close_graphics(); 2222 2218 image_uninit(); … … 2227 2223 void game::draw(int scene_mode) 2228 2224 { 2229 screen->add_dirty( 0, 0, xres, yres);2230 // image *bt=cash.img(border_tile);2231 // int tw=bt->width(),th=bt->height();2225 screen->add_dirty(0, 0, xres, yres); 2226 // image *bt = cash.img(border_tile); 2227 // int tw = bt->width(), th = bt->height(); 2232 2228 screen->clear(); 2233 // for (y=0;y<yt;y++,dy+=th)2234 // for (x=0,dx=0;x<xt;x++,dx+=tw)2235 // bt->put_image(screen, dx,dy);2236 2237 if( scene_mode)2238 2239 2240 eh->font()->put_string(screen,screen->width()/2-(eh->font()->width()*strlen(helpstr))/2+1,2241 screen->height()-eh->font()->height()-5+1,helpstr,eh->dark_color());2242 eh->font()->put_string(screen,screen->width()/2-(eh->font()->width()*strlen(helpstr))/2,2243 screen->height()-eh->font()->height()-5,helpstr,eh->bright_color()); 2244 2245 /* 2246 2247 2248 eh->font()->put_string(screen,screen->width()-eh->font()->width()*strlen(helpstr)-5,2249 screen->height()-eh->font()->height()-5,helpstr);2250 2251 /* int dc=cash.img(window_colors)->pixel(0,2);2252 int mc=cash.img(window_colors)->pixel(1,2);2253 int bc=cash.img(window_colors)->pixel(2,2);2254 screen->line(0,0,screen->width()-1,0,dc);2255 screen->line(0,0,0,screen->height()-1,dc);2256 screen->line(0,screen->height()-1,screen->width()-1,screen->height()-1,bc);2257 screen->line(screen->width()-1,0,screen->width()-1,screen->height()-1,bc); */2258 2259 for( view *f = first_view; f; f = f->next)2260 draw_map( f, 0);2261 2262 sbar.redraw( screen);2263 } 2264 2265 int external_print =0;2229 // for(y = 0; y < yt; y++, dy += th) 2230 // for(x = 0, dx = 0; x < xt; x++, dx += tw) 2231 // bt->put_image(screen, dx, dy); 2232 2233 if(scene_mode) 2234 { 2235 char const *helpstr = "ARROW KEYS CHANGE TEXT SPEED"; 2236 eh->font()->put_string(screen, screen->width()/2-(eh->font()->width()*strlen(helpstr))/2 + 1, 2237 screen->height()-eh->font()->height()-5 + 1, helpstr, eh->dark_color()); 2238 eh->font()->put_string(screen, screen->width()/2-(eh->font()->width()*strlen(helpstr))/2, 2239 screen->height()-eh->font()->height()-5, helpstr, eh->bright_color()); 2240 } 2241 /* else 2242 { 2243 char *helpstr="PRESS h FOR HELP"; 2244 eh->font()->put_string(screen, screen->width()-eh->font()->width()*strlen(helpstr)-5, 2245 screen->height()-eh->font()->height()-5, helpstr); 2246 }*/ 2247 /* int dc = cash.img(window_colors)->pixel(0, 2); 2248 int mc = cash.img(window_colors)->pixel(1, 2); 2249 int bc = cash.img(window_colors)->pixel(2, 2); 2250 screen->line(0, 0, screen->width()-1, 0, dc); 2251 screen->line(0, 0, 0, screen->height()-1, dc); 2252 screen->line(0, screen->height()-1, screen->width()-1, screen->height()-1, bc); 2253 screen->line(screen->width()-1, 0, screen->width()-1, screen->height()-1, bc); */ 2254 2255 for(view *f = first_view; f; f = f->next) 2256 draw_map(f, 0); 2257 2258 sbar.redraw(screen); 2259 } 2260 2261 int external_print = 0; 2266 2262 2267 2263 void start_sound(int argc, char **argv) 2268 2264 { 2269 sfx_volume =music_volume=127;2270 2271 for (int i=1;i<argc;i++)2272 if (!strcmp(argv[i],"-sfx_volume"))2265 sfx_volume = music_volume = 127; 2266 2267 for(int i = 1; i < argc; i++) 2268 if(!strcmp(argv[i], "-sfx_volume")) 2273 2269 { 2274 2270 i++; 2275 if 2276 sfx_volume =atoi(argv[i]);2277 else printf("Bad sound effects volume level, use 0..127\n"); 2278 } 2279 else if (!strcmp(argv[i],"-music_volume"))2271 if(atoi(argv[i])>=0 && atoi(argv[i])<127) 2272 sfx_volume = atoi(argv[i]); 2273 else printf("Bad sound effects volume level, use 0..127\n"); 2274 } 2275 else if(!strcmp(argv[i], "-music_volume")) 2280 2276 { 2281 2277 i++; 2282 if 2283 music_volume =atoi(argv[i]);2284 else printf("Bad music volume level, use 0..127\n"); 2285 } 2286 2287 sound_avail =sound_init(argc,argv);2278 if(atoi(argv[i])>=0 && atoi(argv[i])<127) 2279 music_volume = atoi(argv[i]); 2280 else printf("Bad music volume level, use 0..127\n"); 2281 } 2282 2283 sound_avail = sound_init(argc, argv); 2288 2284 } 2289 2285 2290 2286 void game_printer(char *st) 2291 2287 { 2292 if 2288 if(dev_console && !external_print) 2293 2289 { 2294 2290 dev_console->put_string(st); 2295 2291 } 2296 else fprintf(stderr, "%s",st);2292 else fprintf(stderr, "%s", st); 2297 2293 } 2298 2294 … … 2300 2296 void game_getter(char *st, int max) 2301 2297 { 2302 if (!max) return;2298 if(!max) return; 2303 2299 max--; 2304 *st =0;2305 if 2306 { 2300 *st = 0; 2301 if(dev_console && !external_print) 2302 { 2307 2303 dev_console->show(); 2308 int t =0;2304 int t = 0; 2309 2305 event ev; 2310 2306 do 2311 2307 { 2312 get_event(ev, eh);2313 if (ev.type==EV_KEY)2314 { 2315 if (ev.key==JK_BACKSPACE)2316 2317 if (t) 2318 2319 dev_console->print_f("%c",ev.key);2320 2321 2322 *st=0;2323 2324 2325 } else if(ev.key>=' ' && ev.key<='~')2326 2327 dev_console->print_f("%c",ev.key);2328 *st=ev.key;2329 2330 2331 2332 *st=0;2333 } 2308 get_event(ev, eh); 2309 if(ev.type == EV_KEY) 2310 { 2311 if(ev.key == JK_BACKSPACE) 2312 { 2313 if(t) 2314 { 2315 dev_console->print_f("%c", ev.key); 2316 t--; 2317 st--; 2318 *st = 0; 2319 max++; 2320 } 2321 } else if(ev.key>=' ' && ev.key<='~') 2322 { 2323 dev_console->print_f("%c", ev.key); 2324 *st = ev.key; 2325 t++; 2326 max--; 2327 st++; 2328 *st = 0; 2329 } 2334 2330 } 2335 2331 eh->flush_screen(); 2336 } while (ev.type!=EV_KEY || ev.key!=JK_ENTER);2332 } while(ev.type != EV_KEY || ev.key != JK_ENTER); 2337 2333 dprintf("\n"); 2338 2334 } 2339 else 2340 { 2341 if (fgets(st,max,stdin))2342 { 2343 if 2335 else 2336 { 2337 if(fgets(st, max, stdin)) 2338 { 2339 if(*st) 2344 2340 st[strlen(st)-1]=0; 2345 2341 } … … 2350 2346 void show_startup() 2351 2347 { 2352 show_verinfo(start_argc, start_argv);2348 show_verinfo(start_argc, start_argv); 2353 2349 } 2354 2350 2355 2351 char *get_line(int open_braces) 2356 2352 { 2357 char *line=(char *)jmalloc(1000, "lstring");2358 fgets(line, 1000,stdin);2353 char *line=(char *)jmalloc(1000, "lstring"); 2354 fgets(line, 1000, stdin); 2359 2355 2360 2356 char prev=' '; 2361 for (char *s=line;*s && (prev!=' ' || *s!=';');s++)2357 for(char *s = line; *s && (prev!=' ' || *s!=';'); s++) 2362 2358 { 2363 2359 prev=*s; 2364 if 2365 else if 2366 } 2367 if (open_braces<0)2368 fprintf(stderr, "\nToo many)'s\n");2369 else if (open_braces>0)2370 { 2371 char *s2 =get_line(open_braces);2372 line=(char *)jrealloc(line, strlen(line)+strlen(s2)+1,"lstring");2373 strcat(line, s2);2374 jfree(s2); 2375 } 2360 if(*s=='(') open_braces++; 2361 else if(*s==')') open_braces--; 2362 } 2363 if(open_braces < 0) 2364 fprintf(stderr, "\nToo many)'s\n"); 2365 else if(open_braces > 0) 2366 { 2367 char *s2 = get_line(open_braces); 2368 line=(char *)jrealloc(line, strlen(line)+strlen(s2)+1, "lstring"); 2369 strcat(line, s2); 2370 jfree(s2); 2371 } 2376 2372 return line; 2377 2373 } … … 2379 2375 void check_for_upgrade(int argc, char **argv) 2380 2376 { 2381 for (int i=1;i<argc;i++)2382 if (!strcmp(argv[i],"-upgrade"))2383 { 2384 lisp_init(0xf000, 0x30000);2377 for(int i = 1; i < argc; i++) 2378 if(!strcmp(argv[i], "-upgrade")) 2379 { 2380 lisp_init(0xf000, 0x30000); 2385 2381 char const *prog="(load \"lisp/upgrade.lsp\")"; 2386 2382 char const *cs = prog; 2387 if 2388 printf("file does not exists : lisp/upgrade.lsp, cannot upgrade\n");2383 if(!eval(compile(cs))) 2384 printf("file \"lisp/upgrade.lsp\" does not exist, cannot upgrade\n"); 2389 2385 2390 2386 exit(0); 2391 } 2387 } 2392 2388 } 2393 2389 2394 2390 void check_for_lisp(int argc, char **argv) 2395 2391 { 2396 for( int i = 1; i < argc; i++)2397 2398 if( !strcmp( argv[i], "-lisp" ))2399 2400 lisp_init(0xf000,0x30000);2401 char const *eof_char = "CTRL-D";2402 2403 2404 2405 "Type (%s) to exit\n",eof_char);2406 2407 while(!feof(stdin))2408 2409 fprintf(stderr,"Lisp> ");2410 2411 2412 while(*s)2413 2414 void *prog=compile(s);2415 2416 while(*s==' ' || *s=='\t' || *s=='\r' || *s=='\n') s++;2417 2418 2419 2420 2421 2422 fprintf(stderr,"End of input : bye\n");2423 2424 2425 2392 for(int i = 1; i < argc; i++) 2393 { 2394 if(!strcmp(argv[i], "-lisp")) 2395 { 2396 lisp_init(0xf000, 0x30000); 2397 char const *eof_char = "Ctrl-D"; 2398 fprintf(stderr, 2399 " CLIVE (C) 1995 Jonathan Clark, all rights reserved\n" 2400 " (C LISP interpreter and various extentions)\n" 2401 "Type (%s) to exit\n", eof_char); 2402 2403 while(!feof(stdin)) 2404 { 2405 fprintf(stderr, "Lisp> "); 2406 char *l = get_line(0); 2407 char const *s = l; 2408 while(*s) 2409 { 2410 void *prog = compile(s); 2411 l_user_stack.push(prog); 2412 while(*s==' ' || *s=='\t' || *s=='\r' || *s=='\n') s++; 2413 lprint(eval(prog)); 2414 l_user_stack.pop(1); 2415 } 2416 jfree(l); 2417 } 2418 fprintf(stderr, "End of input : bye\n"); 2419 exit(0); 2420 } 2421 } 2426 2422 } 2427 2423 … … 2429 2425 void music_check() 2430 2426 { 2431 if (sound_avail&MUSIC_INITIALIZED)2432 { 2433 if 2427 if(sound_avail & MUSIC_INITIALIZED) 2428 { 2429 if(current_song && !current_song->playing()) 2434 2430 { 2435 2431 current_song->play(); 2436 2432 dprintf("song finished\n"); 2437 2433 } 2438 if 2439 { 2440 2441 current_song =new song("music/intro.hmi");2434 if(!current_song) 2435 { 2436 2437 current_song = new song("music/intro.hmi"); 2442 2438 current_song->play(music_volume); 2443 2439 2444 /* if 2445 { 2446 int sp=current_space;2447 current_space=PERM_SPACE;2448 eval_function((lisp_symbol *)l_next_song,NULL);2449 current_space=sp;2440 /* if(DEFINEDP(symbol_function(l_next_song))) // if user function installed, call it to load up next song 2441 { 2442 int sp = current_space; 2443 current_space = PERM_SPACE; 2444 eval_function((lisp_symbol *)l_next_song, NULL); 2445 current_space = sp; 2450 2446 } */ 2451 } 2447 } 2452 2448 } 2453 2449 } … … 2469 2465 { 2470 2466 int nonet=!net_init(argc, argv); 2471 if 2467 if(nonet) 2472 2468 dprintf("No network driver, or network driver returned failure\n"); 2473 else 2469 else 2474 2470 { 2475 2471 set_file_opener(open_nfs_file); 2476 if (main_net_cfg && main_net_cfg->state==net_configuration::CLIENT)2477 { 2478 if 2479 start_running =1;2472 if(main_net_cfg && main_net_cfg->state == net_configuration::CLIENT) 2473 { 2474 if(set_file_server(net_server)) 2475 start_running = 1; 2480 2476 else 2481 2477 { 2482 2483 2478 dprintf("Unable to attach to server, quiting\n"); 2479 exit(0); 2484 2480 } 2485 2481 } else 2486 2482 { 2487 2483 int i; 2488 for (i=1;i<argc-1;i++)2489 if (!strcmp(argv[i],"-fs"))2490 if (!set_file_server(argv[i+1]))2491 dprintf("could not set defualt file server to %s\n", argv[i+1]);2492 } 2493 } 2494 2495 } 2496 2497 #if 2484 for(i = 1; i < argc - 1; i++) 2485 if(!strcmp(argv[i], "-fs")) 2486 if(!set_file_server(argv[i + 1])) 2487 dprintf("could not set defualt file server to %s\n", argv[i + 1]); 2488 } 2489 } 2490 2491 } 2492 2493 #if(defined(__APPLE__) && !defined(__MACH__)) 2498 2494 extern int PixMult; 2499 2495 #if 1 … … 2511 2507 void GetArgs(int &argc, char **(&argv)) 2512 2508 { 2513 2514 2515 printf("Usage:\n"2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 while(s)2534 2535 2536 2537 2538 2539 2509 char *s; 2510 2511 printf("Usage:\n" 2512 " abuse [-options]\n\n" 2513 " Options:\n" 2514 " -server -a deathmat become a server for deathmatch game\n" 2515 " -net <dotted ip address> connect to a server\n\n" 2516 "Options for mac:\n" 2517 " Hold down <control> for single pixel mode\n" 2518 " Hold down <option> for edit mode\n" 2519 " Hold down <left shift> for double size mode\n\n" 2520 "If started with no command line options, networking will attempt\n" 2521 " to search the local network for servers\n\n" 2522 ); 2523 printf("Enter command line:\n"); 2524 gets(cmdline); 2525 2526 argc = 0; 2527 argv = tmp_argv; 2528 s = strtok(cmdline, delims); 2529 while(s) 2530 { 2531 argv[argc] = s; 2532 argc++; 2533 s = strtok(0, delims); 2534 } 2535 argv[argc] = 0; 2540 2536 } 2541 2537 … … 2544 2540 int main(int argc, char **argv) 2545 2541 { 2546 #if 2547 GetArgs(argc,argv);2542 #if(defined(__APPLE__) && !defined(__MACH__)) 2543 GetArgs(argc, argv); 2548 2544 #endif 2549 2545 2550 2551 2552 2553 for( int i = 0; i < argc; i++)2554 2555 if( !strcmp( argv[i], "-cprint" ))2556 2557 2558 2559 2560 if( !strcmp( argv[i], "-min_low" ))2561 2562 2563 jmalloc_min_low_size = atoi( argv[i]);2564 2565 2566 2567 // jmalloc_max_size =0x150000;2568 jmalloc_init( 0x150000);2546 start_argc = argc; 2547 start_argv = argv; 2548 2549 for(int i = 0; i < argc; i++) 2550 { 2551 if(!strcmp(argv[i], "-cprint")) 2552 { 2553 external_print = 1; 2554 } 2555 2556 if(!strcmp(argv[i], "-min_low")) 2557 { 2558 i++; 2559 jmalloc_min_low_size = atoi(argv[i]); 2560 } 2561 } 2562 2563 // jmalloc_max_size = 0x150000; 2564 jmalloc_init(0x150000); 2569 2565 // jmalloc_init(100000); 2570 2566 2571 #if 2572 2573 2574 fprintf(stderr,"Mac Options: ");2575 2576 2577 if((km[ 0x3a >>3] >> (0x3a & 7)) &1 != 0)2578 2579 dev|=EDIT_MODE; 2580 start_edit=1;2581 start_running=1;2582 disable_autolight=1;2583 fprintf(stderr,"Edit Mode...");2584 2585 if((km[ 0x3b >>3] >> (0x3b & 7)) &1 != 0)2586 2587 2588 fprintf(stderr,"Single Pixel...");2589 2590 2591 2592 2593 fprintf(stderr,"Double Pixel...");2594 2595 if((km[ 0x38 >>3] >> (0x38 & 7)) &1 != 0)2596 2597 2598 fprintf(stderr,"Double Size...");2599 2600 fprintf(stderr,"\n");2601 2602 if(tcpip.installed())2603 2567 #if(defined(__APPLE__) && !defined(__MACH__)) 2568 unsigned char km[16]; 2569 2570 fprintf(stderr, "Mac Options: "); 2571 xres = 320; yres = 200; 2572 GetKeys((uint32_t*)&km); 2573 if((km[ 0x3a >>3] >> (0x3a & 7)) &1 != 0) 2574 { 2575 dev|=EDIT_MODE; 2576 start_edit = 1; 2577 start_running = 1; 2578 disable_autolight = 1; 2579 fprintf(stderr, "Edit Mode..."); 2580 } 2581 if((km[ 0x3b >>3] >> (0x3b & 7)) &1 != 0) 2582 { 2583 PixMult = 1; 2584 fprintf(stderr, "Single Pixel..."); 2585 } 2586 else 2587 { 2588 PixMult = 2; 2589 fprintf(stderr, "Double Pixel..."); 2590 } 2591 if((km[ 0x38 >>3] >> (0x38 & 7)) &1 != 0) 2592 { 2593 xres *= 2; yres *= 2; 2594 fprintf(stderr, "Double Size..."); 2595 } 2596 fprintf(stderr, "\n"); 2597 2598 if(tcpip.installed()) 2599 fprintf(stderr, "Using %s\n", tcpip.name()); 2604 2600 #endif 2605 2601 2606 2607 2608 2609 2610 setup(argc,argv);2611 2612 2613 2614 start_sound(argc,argv);2615 2616 2617 if( !get_option("-no_timer"))2618 2619 2620 2621 2622 2623 if( getenv("ABUSE_PATH"))2624 2625 set_filename_prefix( getenv( "ABUSE_PATH" ));2626 2627 2628 2629 if( getenv( "ABUSE_SAVE_PATH" ))2630 2631 set_save_filename_prefix( getenv( "ABUSE_SAVE_PATH" ));2632 2633 2634 2635 jrand();// so compiler doesn't complain2636 2637 2638 2639 check_for_lisp( argc, argv);2640 check_for_upgrade( argc, argv);2641 2642 2643 2644 if( main_net_cfg)2645 2646 if( !main_net_cfg->notify_reset())2647 2648 if( !get_option( "-no_timer" ))2649 2650 2651 2652 2653 2654 2655 game_net_init(argc,argv);2656 lisp_init(0x16000,0x94000);2657 // lisp_init(0x100000,0x10000);2658 2659 dev_init(argc,argv);2660 2661 game *g = new game( argc, argv);2662 2663 dev_cont=new dev_controll();2664 2665 2666 g->get_input();// prime the net2667 2668 2669 for( xx = 1; xx < argc; xx++)2670 2671 if (!strcmp(argv[xx],"-server"))2672 2673 2674 if( !become_server( argv[xx] ))2675 2676 dprintf( "unable to become a server\n");2677 2678 2679 2680 2681 2682 2683 if( main_net_cfg)2684 2685 2686 2687 2688 net_send( 1);2689 if( net_start())2690 2691 g->step();// process all the objects in the2692 2693 g->update_screen();// redraw the screen with any changes2694 2695 2696 while 2602 set_dprinter(game_printer); 2603 set_dgetter(game_getter); 2604 set_no_space_handler(handle_no_space); 2605 2606 setup(argc, argv); 2607 2608 show_startup(); 2609 2610 start_sound(argc, argv); 2611 2612 stat_man = new text_status_manager(); 2613 if(!get_option("-no_timer")) 2614 { 2615 timer_init(); 2616 } 2617 2618 // look to see if we are supposed to fetch the data elsewhere 2619 if(getenv("ABUSE_PATH")) 2620 { 2621 set_filename_prefix(getenv("ABUSE_PATH")); 2622 } 2623 2624 // look to see if we are supposed to save the data elsewhere 2625 if(getenv("ABUSE_SAVE_PATH")) 2626 { 2627 set_save_filename_prefix(getenv("ABUSE_SAVE_PATH")); 2628 } 2629 2630 jrand_init(); 2631 jrand(); // so compiler doesn't complain 2632 2633 set_spec_main_file("abuse.spe"); 2634 2635 check_for_lisp(argc, argv); 2636 check_for_upgrade(argc, argv); 2637 2638 do 2639 { 2640 if(main_net_cfg) 2641 { 2642 if(!main_net_cfg->notify_reset()) 2643 { 2644 if(!get_option("-no_timer")) 2645 timer_uninit(); 2646 sound_uninit(); 2647 exit(0); 2648 } 2649 } 2650 2651 game_net_init(argc, argv); 2652 lisp_init(0x16000, 0x94000); 2653 // lisp_init(0x100000, 0x10000); 2654 2655 dev_init(argc, argv); 2656 2657 game *g = new game(argc, argv); 2658 2659 dev_cont = new dev_controll(); 2660 dev_cont->load_stuff(); 2661 2662 g->get_input(); // prime the net 2663 2664 int xx; 2665 for(xx = 1; xx < argc; xx++) 2666 { 2667 if(!strcmp(argv[xx], "-server")) 2668 { 2669 xx++; 2670 if(!become_server(argv[xx])) 2671 { 2672 dprintf("unable to become a server\n"); 2673 exit(0); 2674 } 2675 xx = argc + 1; 2676 } 2677 } 2678 2679 if(main_net_cfg) 2680 { 2681 wait_min_players(); 2682 } 2683 2684 net_send(1); 2685 if(net_start()) 2686 { 2687 g->step(); // process all the objects in the 2688 g->calc_speed(); 2689 g->update_screen(); // redraw the screen with any changes 2690 } 2691 2692 while(!g->done()) 2697 2693 { 2698 2694 music_check(); 2699 2695 2700 if 2701 { 2702 2703 current_level=NULL;2704 2705 2706 2707 2708 req_end=0;2696 if(req_end) 2697 { 2698 delete current_level; 2699 current_level = NULL; 2700 2701 show_end(); 2702 2703 the_game->set_state(MENU_STATE); 2704 req_end = 0; 2709 2705 } 2710 2706 2711 if 2712 { 2713 2707 if(demo_man.current_state()==demo_manager::NORMAL) 2708 { 2709 net_receive(); 2714 2710 } 2715 2711 2716 if 2712 if(req_name[0]) // see if a request for a level load was made during the last tick 2717 2713 { 2718 2714 g->load_level(req_name); 2719 2715 req_name[0]=0; 2720 g->draw(g->state ==SCENE_STATE);2716 g->draw(g->state == SCENE_STATE); 2721 2717 } 2722 2718 2723 // if 2719 // if(demo_man.current_state()!=demo_manager::PLAYING) 2724 2720 g->get_input(); 2725 2721 2726 if 2722 if(demo_man.current_state()==demo_manager::NORMAL) 2727 2723 net_send(); 2728 2724 else demo_man.do_inputs(); … … 2730 2726 service_net_request(); 2731 2727 2732 g->step(); // process all the objects in the 2728 g->step(); // process all the objects in the 2733 2729 2734 2730 server_check(); 2735 2731 2736 2732 g->calc_speed(); 2737 if 2733 if(!req_name[0]) // see if a request for a level load was made during the last tick 2738 2734 g->update_screen(); // redraw the screen with any changes 2739 2735 … … 2743 2739 net_uninit(); 2744 2740 2745 if 2741 if(net_crcs) 2746 2742 { 2747 2743 net_crcs->clean_up(); 2748 2744 delete net_crcs; 2749 net_crcs =NULL;2745 net_crcs = NULL; 2750 2746 } 2751 2747 … … 2754 2750 milli_wait(500); 2755 2751 2756 if (small_render) { delete small_render; small_render=NULL; }2757 2758 if (current_song)2752 if(small_render) { delete small_render; small_render = NULL; } 2753 2754 if(current_song) 2759 2755 { current_song->stop(); 2760 delete current_song; 2761 current_song =NULL;2756 delete current_song; 2757 current_song = NULL; 2762 2758 } 2763 2759 … … 2766 2762 2767 2763 2768 if 2764 if(dev_console) 2769 2765 { 2770 2766 delete dev_console; 2771 dev_console =NULL;2772 } 2773 2774 if 2767 dev_console = NULL; 2768 } 2769 2770 if(dev_menu) 2775 2771 { 2776 2772 delete dev_menu; 2777 dev_menu =NULL;2773 dev_menu = NULL; 2778 2774 } 2779 2775 2780 2776 delete g; 2781 if (old_pal) delete old_pal; old_pal=NULL;2777 if(old_pal) delete old_pal; old_pal = NULL; 2782 2778 compiled_uninit(); 2783 2779 delete_all_lights(); 2784 2780 jfree(white_light_initial); 2785 2781 2786 for (int i=0;i<TTINTS;i++) jfree(tints[i]);2782 for(int i = 0; i < TTINTS; i++) jfree(tints[i]); 2787 2783 2788 2784 2789 2785 dev_cleanup(); 2790 delete dev_cont; dev_cont =NULL;2791 delete stat_man; 2792 stat_man =new text_status_manager();2793 2794 if 2795 { 2796 void *end_msg =make_find_symbol("end_msg");2797 if 2798 printf("%s\n", lstring_value(symbol_value(end_msg)));2786 delete dev_cont; dev_cont = NULL; 2787 delete stat_man; 2788 stat_man = new text_status_manager(); 2789 2790 if(!(main_net_cfg && main_net_cfg->restart_state())) 2791 { 2792 void *end_msg = make_find_symbol("end_msg"); 2793 if(DEFINEDP(symbol_value(end_msg))) 2794 printf("%s\n", lstring_value(symbol_value(end_msg))); 2799 2795 } 2800 2796 … … 2803 2799 base->packet.packet_reset(); 2804 2800 mem_report("end.mem"); 2805 } while 2806 2807 2808 2809 if( main_net_cfg)2810 2811 2812 main_net_cfg=NULL;2813 2814 2815 2816 2817 if( !get_option( "-no_timer" ))2818 2819 2820 2801 } while(main_net_cfg && main_net_cfg->restart_state()); 2802 2803 delete stat_man; 2804 2805 if(main_net_cfg) 2806 { 2807 delete main_net_cfg; 2808 main_net_cfg = NULL; 2809 } 2810 set_filename_prefix(NULL); // dealloc this mem if there was any 2811 set_save_filename_prefix(NULL); 2812 2813 if(!get_option("-no_timer")) 2814 { 2815 timer_uninit(); 2816 } 2821 2817 2822 2818 // AK -> Commented this out to stop a crash as the file prefix has already 2823 2819 // been released. Need to fix this. 2824 // mem_report("end.mem"); 2825 2826 // jmalloc_uninit(); 2827 l_user_stack.clean_up(); 2828 l_ptr_stack.clean_up(); 2829 2830 sound_uninit(); 2831 2832 exit(0); 2833 2834 return 0; 2835 } 2836 2837 2820 // mem_report("end.mem"); 2821 2822 // jmalloc_uninit(); 2823 l_user_stack.clean_up(); 2824 l_ptr_stack.clean_up(); 2825 2826 sound_uninit(); 2827 2828 exit(0); 2829 2830 return 0; 2831 } 2832
Note: See TracChangeset
for help on using the changeset viewer.