Changeset 127
- Timestamp:
- Mar 19, 2008, 2:42:12 AM (14 years ago)
- Location:
- abuse/trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
abuse/trunk/src/game.cpp
r124 r127 60 60 extern CrcManager *net_crcs; 61 61 62 game *the_game;62 Game *the_game = NULL; 63 63 WindowManager *wm = NULL; 64 64 int dev, shift_down = SHIFT_DOWN_DEFAULT, shift_right = SHIFT_RIGHT_DEFAULT; … … 125 125 } 126 126 127 void game::play_sound(int id, int vol, int32_t x, int32_t y)127 void Game::play_sound(int id, int vol, int32_t x, int32_t y) 128 128 { 129 129 if(!(sound_avail & SFX_INITIALIZED)) 130 130 return; 131 if(vol < 1 5)131 if(vol < 1) 132 132 return; 133 133 if(!player_list) 134 134 return; 135 135 136 uint32_t mdist = 0xffffffff;136 int mindist = 500; 137 137 view *cd = NULL; 138 138 for(view *f = player_list; f; f = f->next) 139 139 { 140 if(f->local_player()) 140 if(!f->local_player()) 141 continue; 142 143 int d, cx = abs(f->x_center() - x), cy = abs(f->y_center() - y); 144 if(cx < cy) 145 d = cx + cy - (cx >> 1); 146 else 147 d = cx + cy - (cy >> 1); 148 149 if(d < mindist) 141 150 { 142 int32_t cx = abs(f->x_center()-x), cy = abs(f->y_center()-y), d; 143 if(cx < cy) 144 d = cx + cy - (cx >> 1); 145 else 146 d = cx + cy - (cy >> 1); 147 148 if((unsigned)d < mdist) 149 { 150 cd = f; 151 mdist = d; 152 } 151 cd = f; 152 mindist = d; 153 153 } 154 154 } 155 if(m dist > 500 || !cd)155 if(mindist >= 500) 156 156 return; 157 if(mdist < 100) 158 mdist = 0; 157 158 if(mindist < 100) 159 mindist = 0; 159 160 else 160 mdist -= 100; 161 162 int v = (400 - mdist) * sfx_volume / 400 - (127 - vol); 161 mindist -= 100; 163 162 164 163 // Calculate the position of the sound relative to the player 165 int p = cd->x_center() - x; 166 if(p > 0) 167 p = (int)(((double)p / 255.0) * 128.0); 168 else 169 p = (int)(((double)abs(p) / 255.0) * -128.0); 170 p += 128; 171 if(p < 0) p = 0; 172 if(p > 255) p = 255; 173 164 int p = (cd->x_center() - x) / 2 + 128; 165 if(p < 0) 166 p = 0; 167 if(p > 255) 168 p = 255; 169 170 int v = (400 - mindist) * sfx_volume / 400 - (127 - vol); 174 171 if(v > 0) 175 172 cache.sfx(id)->play(v, 128, p); … … 213 210 } 214 211 215 void game::grow_views(int amount)212 void Game::grow_views(int amount) 216 213 { 217 214 view *f; … … 250 247 } 251 248 252 void game::pan(int xv, int yv)249 void Game::pan(int xv, int yv) 253 250 { 254 251 first_view->pan_x += xv; … … 256 253 } 257 254 258 view * game::view_in(int mousex, int mousey)255 view *Game::view_in(int mousex, int mousey) 259 256 { 260 257 for(view *f = first_view; f; f = f->next) … … 270 267 } 271 268 272 void game::ftile_on(int screenx, int screeny, int32_t &x, int32_t &y)269 void Game::ftile_on(int screenx, int screeny, int32_t &x, int32_t &y) 273 270 { 274 271 mouse_to_game(screenx, screeny, x, y); … … 277 274 } 278 275 279 void game::btile_on(int screenx, int screeny, int32_t &x, int32_t &y)276 void Game::btile_on(int screenx, int screeny, int32_t &x, int32_t &y) 280 277 { 281 278 view *f = view_in(screenx, screeny); … … 294 291 } 295 292 296 void game::mouse_to_game(int32_t x, int32_t y,293 void Game::mouse_to_game(int32_t x, int32_t y, 297 294 int32_t &gamex, int32_t &gamey, view *f) 298 295 { … … 317 314 } 318 315 319 void game::game_to_mouse(int32_t gamex, int32_t gamey, view *which,316 void Game::game_to_mouse(int32_t gamex, int32_t gamey, view *which, 320 317 int32_t &x, int32_t &y) 321 318 { … … 385 382 } 386 383 387 void game::set_state(int new_state)384 void Game::set_state(int new_state) 388 385 { 389 386 int d = 0; … … 457 454 } 458 455 459 void game::joy_calb(event &ev)456 void Game::joy_calb(event &ev) 460 457 { 461 458 if(!joy_win) // make sure the joystick calibration window is open … … 486 483 } 487 484 488 void game::menu_select(event &ev)485 void Game::menu_select(event &ev) 489 486 { 490 487 state = DEV_MOUSE_RELEASE; … … 500 497 501 498 502 void game::show_help(char const *st)499 void Game::show_help(char const *st) 503 500 { 504 501 strcpy(help_text, st); … … 507 504 } 508 505 509 void game::draw_value(image *screen, int x, int y, int w, int h,506 void Game::draw_value(image *screen, int x, int y, int w, int h, 510 507 int val, int max) 511 508 { … … 515 512 516 513 517 void game::set_level(level *nl)514 void Game::set_level(level *nl) 518 515 { 519 516 if(current_level) … … 522 519 } 523 520 524 void game::load_level(char const *name)521 void Game::load_level(char const *name) 525 522 { 526 523 if(current_level) … … 550 547 } 551 548 552 int game::done()549 int Game::done() 553 550 { 554 551 return finished || (main_net_cfg && main_net_cfg->restart_state()); 555 556 } 557 558 void game::end_session() 559 { 560 finished = 1; 552 } 553 554 void Game::end_session() 555 { 556 finished = true; 561 557 if(main_net_cfg) 562 558 { … … 566 562 } 567 563 568 void game::put_block_fg(int x, int y, trans_image *im)564 void Game::put_block_fg(int x, int y, trans_image *im) 569 565 { 570 566 for(view *f = first_view; f; f = f->next) … … 585 581 } 586 582 587 void game::put_block_bg(int x, int y, image *im)583 void Game::put_block_bg(int x, int y, image *im) 588 584 { 589 585 for(view *f = first_view; f; f = f->next) … … 609 605 int need_delay = 1; 610 606 611 void game::dev_scroll()607 void Game::dev_scroll() 612 608 { 613 609 need_delay = 0; … … 672 668 void remap_area(image *screen, int x1, int y1, int x2, int y2, uint8_t *remap) 673 669 { 674 uint8_t *sl=(uint8_t *)screen->scan_line(y1)+x1; 675 int x, y, a = screen->width()-(x2 - x1 + 1); 676 uint8_t c; 677 for(y = y1; y <= y2; y++) 678 { 679 for(x = x1; x <= x2; x++) 680 { 681 c=*sl; 682 *(sl++)=remap[c]; 683 } 684 sl += a; 685 } 670 screen->lock(); 671 672 uint8_t *sl = (uint8_t *)screen->scan_line(y1) + x1; 673 int step = screen->width() - (x2 - x1 + 1); 674 675 for(int y = y1; y <= y2; y++) 676 { 677 for(int x = x1; x <= x2; x++) 678 { 679 uint8_t c = *sl; 680 *(sl++) = remap[c]; 681 } 682 sl += step; 683 } 684 screen->unlock(); 686 685 } 687 686 … … 698 697 } 699 698 700 void game::draw_map(view *v, int interpolate)699 void Game::draw_map(view *v, int interpolate) 701 700 { 702 701 backtile *bt; … … 735 734 { 736 735 int c = v->draw_solid; 736 screen->lock(); 737 737 for(int y = v->cy1; y <= v->cy2; y++) 738 738 memset(screen->scan_line(y)+v->cx1, c, v->cx2 - v->cx1 + 1); 739 screen->unlock(); 739 740 v->draw_solid = -1; 740 741 return; … … 761 762 762 763 763 764 // int32_t max_xoff=(current_level->foreground_width()-1)*ftile_width()-(v->cx2 - v->cx1 + 1);765 // int32_t max_yoff=(current_level->foreground_height()-1)*ftile_height()-(v->cy2 - v->cy1 + 1);766 767 764 int32_t xoff, yoff; 768 765 if(interpolate) … … 786 783 nxoff = xoff * bg_xmul / bg_xdiv; 787 784 nyoff = yoff * bg_ymul / bg_ydiv; 788 789 // int32_t max_bg_xoff=(current_level->background_width())*btile_width()-(v->cx2 - v->cx1 + 1);790 // int32_t max_bg_yoff=(current_level->background_height())*btile_height()-(v->cy2 - v->cy1 + 1);791 // if(nxoff > max_bg_xoff) nxoff = max_xoff;792 // if(nyoff > max_bg_yoff) nyoff = max_yoff;793 785 794 786 … … 965 957 } 966 958 } 967 /* if(dev == 0) 968 current_level->put_fg(x, y, ft->next); */ 969 } 970 971 // if(!(dev & EDIT_MODE)) 972 // server_check(); 959 } 973 960 974 961 int32_t ro = rand_on; … … 1135 1122 } 1136 1123 1137 void game::put_fg(int x, int y, int type)1124 void Game::put_fg(int x, int y, int type) 1138 1125 { 1139 1126 if(current_level->get_fg(x, y)!=type) … … 1143 1130 if(f->drawable()) 1144 1131 draw_map(f); 1145 /* put_block_bg(x, y, get_bg(current_level->get_bg(x / ASPECT, y / ASPECT))->im); 1146 if(type > BLACK) 1147 put_block_fg(x, y, get_fg(type)->im); */ 1148 } 1149 } 1150 1151 void game::put_bg(int x, int y, int type) 1132 } 1133 } 1134 1135 void Game::put_bg(int x, int y, int type) 1152 1136 { 1153 1137 if(current_level->get_bg(x, y)!=type) … … 1157 1141 if(f->drawable()) 1158 1142 draw_map(f); 1159 /* put_block_bg(x, y, get_bg(type)->im); 1160 if(current_level->get_fg(x, y)>BLACK) 1161 put_block_fg(x, y, get_fg(current_level->get_fg(x, y))->im); */ 1162 } 1163 } 1164 1165 int game::in_area(event &ev, int x1, int y1, int x2, int y2) 1143 } 1144 } 1145 1146 int Game::in_area(event &ev, int x1, int y1, int x2, int y2) 1166 1147 { 1167 1148 return (last_demo_mx >= x1 && last_demo_mx <= x2 && … … 1169 1150 } 1170 1151 1171 void game::request_level_load(char *name)1152 void Game::request_level_load(char *name) 1172 1153 { 1173 1154 strcpy(req_name, name); … … 1266 1247 fade_in(cache.img(cdc_logo), 32); 1267 1248 1268 milli_wait( 900);1249 milli_wait(400); 1269 1250 1270 1251 void *space_snd = symbol_value(make_find_symbol("SPACE_SND")); 1271 1252 1272 1253 fade_out(32); 1273 milli_wait( 300);1274 1275 int i , abort = 0;1254 milli_wait(100); 1255 1256 int i; 1276 1257 char *str = lstring_value(eval(make_find_symbol("plot_start"))); 1277 1258 … … 1348 1329 delete fp; 1349 1330 1350 for(i = 0; i < 100 && !abort; i++)1351 {1352 }1353 1354 1331 if(title_screen >= 0) 1355 1332 fade_in(cache.img(title_screen), 32); 1356 1357 wm->set_mouse_shape(cache.img(c_normal)->copy(), 1, 1);1358 1333 } 1359 1334 } … … 1361 1336 extern int start_edit; 1362 1337 1363 void game::request_end()1338 void Game::request_end() 1364 1339 { 1365 1340 req_end = 1; … … 1371 1346 extern void fast_load_stop_reloading(); 1372 1347 1373 game::game(int argc, char **argv)1348 Game::Game(int argc, char **argv) 1374 1349 { 1375 1350 int i; … … 1425 1400 1426 1401 reset_keymap(); // we think all the keys are up right now 1427 finished = 0;1402 finished = false; 1428 1403 1429 1404 calc_light_table(pal); … … 1546 1521 double avg_fps = 15.0, possible_fps = 15.0; 1547 1522 1548 void game::toggle_delay()1523 void Game::toggle_delay() 1549 1524 { 1550 1525 no_delay=!no_delay; … … 1555 1530 } 1556 1531 1557 void game::show_time()1532 void Game::show_time() 1558 1533 { 1559 1534 if(first_view && fps_on) … … 1568 1543 } 1569 1544 1570 void game::update_screen()1545 void Game::update_screen() 1571 1546 { 1572 1547 if(state == HELP_STATE) … … 1625 1600 } 1626 1601 1627 void game::do_intro()1628 { 1629 1630 } 1631 1632 int game::calc_speed()1602 void Game::do_intro() 1603 { 1604 1605 } 1606 1607 int Game::calc_speed() 1633 1608 { 1634 1609 int ret = 0; … … 1694 1669 extern int start_edit; 1695 1670 1696 void game::get_input()1671 void Game::get_input() 1697 1672 { 1698 1673 event ev; … … 1793 1768 case DEV_QUIT: 1794 1769 { 1795 finished = 1;1770 finished = true; 1796 1771 } break; 1797 1772 } … … 1870 1845 } break; 1871 1846 case JK_TAB: 1872 {1873 1847 if(start_edit) 1874 1848 toggle_edit_mode(); 1875 1849 need_refresh(); 1876 }break;1850 break; 1877 1851 case 'c': 1878 {1852 case 'C': 1879 1853 if(chatting_enabled && (!(dev & EDIT_MODE) && chat)) 1880 1854 chat->toggle(); 1881 }break;1855 break; 1882 1856 case '9': 1883 {1884 1857 dev = dev ^ PERFORMANCE_TEST_MODE; 1885 1858 need_refresh(); 1886 } break; 1887 /* case '=': 1888 case '+': 1889 { 1890 if(!dev_cont->need_plus_minus()) 1891 { 1892 if(wm->key_pressed(JK_CTRL_L)) 1893 grow_views(20); 1894 else 1895 grow_views(5); 1896 draw(state == SCENE_STATE); 1897 } 1898 } break; 1899 case JK_F10: 1900 { 1901 make_screen_size(311, 160); 1902 } break; 1903 case '_': 1904 case '-' : 1905 { 1906 if(!dev_cont->need_plus_minus()) 1907 { 1908 if(wm->key_pressed(JK_CTRL_L)) 1909 grow_views(-20); 1910 else 1911 grow_views(-5); 1912 draw(state == SCENE_STATE); 1913 } 1914 } break; 1915 */ 1859 break; 1916 1860 } 1917 1861 } break; … … 2053 1997 } 2054 1998 2055 void game::step()1999 void Game::step() 2056 2000 { 2057 2001 clear_tmp(); … … 2110 2054 main_menu(); 2111 2055 2112 if(key_down('x') && (key_down(JK_ALT_L) || key_down(JK_ALT_R)) && confirm_quit()) finished = 1; 2056 if((key_down('x') || key_down(JK_F4)) 2057 && (key_down(JK_ALT_L) || key_down(JK_ALT_R)) 2058 && confirm_quit()) 2059 finished = true; 2113 2060 } 2114 2061 2115 2062 extern void *current_demo; 2116 2063 2117 game::~game()2064 Game::~Game() 2118 2065 { 2119 2066 current_demo = NULL; … … 2196 2143 2197 2144 2198 void game::draw(int scene_mode)2145 void Game::draw(int scene_mode) 2199 2146 { 2200 2147 screen->add_dirty(0, 0, xres, yres); 2201 // image *bt = cache.img(border_tile); 2202 // int tw = bt->width(), th = bt->height(); 2203 screen->clear(); 2204 // for(y = 0; y < yt; y++, dy += th) 2205 // for(x = 0, dx = 0; x < xt; x++, dx += tw) 2206 // bt->put_image(screen, dx, dy); 2148 2149 screen->clear(); 2207 2150 2208 2151 if(scene_mode) … … 2466 2409 } 2467 2410 2468 #if(defined(__APPLE__) && !defined(__MACH__)) 2469 extern int PixMult; 2470 #if 1 2471 char cmdline[256]; 2472 #elif 1 2473 char cmdline[] = ""; 2474 #elif 1 2475 char cmdline[] = "abuse -server -a deathmat"; 2476 #else 2477 char cmdline[] = "abuse -net 193.246.40.9"; 2478 #endif 2479 char delims[] = " "; 2480 char *tmp_argv[255]; 2481 2482 void GetArgs(int &argc, char **(&argv)) 2483 { 2484 char *s; 2485 2486 printf("Usage:\n" 2487 " abuse [-options]\n\n" 2488 " Options:\n" 2489 " -server -a deathmat become a server for deathmatch game\n" 2490 " -net <dotted ip address> connect to a server\n\n" 2491 "Options for mac:\n" 2492 " Hold down <control> for single pixel mode\n" 2493 " Hold down <option> for edit mode\n" 2494 " Hold down <left shift> for double size mode\n\n" 2495 "If started with no command line options, networking will attempt\n" 2496 " to search the local network for servers\n\n" 2497 ); 2498 printf("Enter command line:\n"); 2499 gets(cmdline); 2500 2501 argc = 0; 2502 argv = tmp_argv; 2503 s = strtok(cmdline, delims); 2504 while(s) 2505 { 2506 argv[argc] = s; 2507 argc++; 2508 s = strtok(0, delims); 2509 } 2510 argv[argc] = 0; 2511 } 2512 2513 #endif 2514 2515 int main(int argc, char **argv) 2516 { 2517 #if(defined(__APPLE__) && !defined(__MACH__)) 2518 GetArgs(argc, argv); 2519 #endif 2520 2411 int main(int argc, char *argv[]) 2412 { 2521 2413 start_argc = argc; 2522 2414 start_argv = argv; … … 2630 2522 dev_init(argc, argv); 2631 2523 2632 game *g = new game(argc, argv);2524 Game *g = new Game(argc, argv); 2633 2525 2634 2526 dev_cont = new dev_controll(); … … 2782 2674 2783 2675 base->packet.packet_reset(); 2784 mem_report("end.mem");2676 // mem_report("end.mem"); 2785 2677 } while(main_net_cfg && main_net_cfg->restart_state()); 2786 2678 -
abuse/trunk/src/game.hpp
r124 r127 50 50 51 51 #define tile_type unsigned short 52 class game;53 extern game *the_game;52 class Game; 53 extern Game *the_game; 54 54 extern int dev; 55 55 extern int morph_sel_frame_color; … … 63 63 extern FILE *open_FILE(char const *filename, char const *mode); 64 64 65 class game65 class Game 66 66 { 67 private: 67 68 JCFont *fnt; 68 intfinished;69 bool finished; 69 70 int bg_top,fg_top; // in the fg/bg window which tile is at the top? 70 71 int bright_color,med_color,dark_color, // for boundaries and windows, etc … … 90 91 int state,zoom; 91 92 93 Game(int argc, char **argv); 94 ~Game(); 92 95 93 game(int argc, char **argv);94 96 void step(); 95 97 void show_help(char const *st); … … 155 157 void request_level_load(char *name); 156 158 void request_end(); 157 ~game();158 159 } ; 159 160
Note: See TracChangeset
for help on using the changeset viewer.