1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2001-2003,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2001-2003,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
… | |
… | |
25 | #include <object.h> |
25 | #include <object.h> |
26 | #include <tod.h> |
26 | #include <tod.h> |
27 | |
27 | |
28 | #include <sproto.h> |
28 | #include <sproto.h> |
29 | #include <time.h> |
29 | #include <time.h> |
|
|
30 | |
|
|
31 | #include <glib.h> |
30 | |
32 | |
31 | #include <../random_maps/random_map.h> |
33 | #include <../random_maps/random_map.h> |
32 | #include <../random_maps/rproto.h> |
34 | #include <../random_maps/rproto.h> |
33 | #include "path.h" |
35 | #include "path.h" |
34 | |
36 | |
… | |
… | |
106 | * goes someplace. |
108 | * goes someplace. |
107 | */ |
109 | */ |
108 | void |
110 | void |
109 | enter_player_savebed (object *op) |
111 | enter_player_savebed (object *op) |
110 | { |
112 | { |
111 | object *tmp = object::create (); |
113 | op->player_goto (op->contr->savebed_map, op->contr->bed_x, op->contr->bed_y); |
112 | EXIT_PATH (tmp) = op->contr->savebed_map; |
|
|
113 | EXIT_X (tmp) = op->contr->bed_x; |
|
|
114 | EXIT_Y (tmp) = op->contr->bed_y; |
|
|
115 | op->enter_exit (tmp); |
|
|
116 | tmp->destroy (); |
|
|
117 | } |
114 | } |
118 | |
115 | |
119 | /* |
116 | /* |
120 | * enter_map(): Moves the player and pets from current map (if any) to |
117 | * enter_map(): Moves the player and pets from current map (if any) to |
121 | * new map. map, x, y must be set. map is the map we are moving the |
118 | * new map. map, x, y must be set. map is the map we are moving the |
… | |
… | |
207 | if (object *golem = contr->golem) |
204 | if (object *golem = contr->golem) |
208 | { |
205 | { |
209 | int i = find_free_spot (golem, newmap, x, y, 1, SIZEOFFREE); |
206 | int i = find_free_spot (golem, newmap, x, y, 1, SIZEOFFREE); |
210 | |
207 | |
211 | if (i < 0) |
208 | if (i < 0) |
|
|
209 | { |
|
|
210 | golem->destroy_inv (true); // be explicit about dropping |
212 | golem->destroy (); |
211 | golem->destroy (true); |
|
|
212 | } |
213 | else |
213 | else |
214 | { |
214 | { |
215 | newmap->insert (golem, x + freearr_x[i], y + freearr_y[i]); |
215 | newmap->insert (golem, x + freearr_x[i], y + freearr_y[i]); |
216 | golem->direction = find_dir_2 (x - golem->x, y - golem->y); |
216 | golem->direction = find_dir_2 (x - golem->x, y - golem->y); |
217 | } |
217 | } |
… | |
… | |
311 | op->last_anim = 1; |
311 | op->last_anim = 1; |
312 | } |
312 | } |
313 | else |
313 | else |
314 | ++op->last_anim; |
314 | ++op->last_anim; |
315 | |
315 | |
316 | if (op->speed_left > 0.f) |
316 | if (expect_false (op->speed_left > 0.f)) |
317 | { |
317 | { |
318 | --op->speed_left; |
318 | --op->speed_left; |
319 | process_object (op); |
319 | process_object (op); |
320 | |
|
|
321 | if (op->destroyed ()) |
|
|
322 | continue; |
|
|
323 | } |
320 | } |
324 | |
321 | |
325 | if (!op->contr) |
322 | if (expect_true (!op->contr)) |
326 | op->speed_left = min (abs (op->speed), op->speed_left + abs (op->speed)); |
323 | op->speed_left = min (abs (op->speed), op->speed_left + abs (op->speed)); |
327 | } |
324 | } |
328 | |
325 | |
329 | process_players2 (); |
326 | process_players2 (); |
330 | } |
327 | } |
… | |
… | |
390 | LOG (llevDebug, "cleanup done.\n"); |
387 | LOG (llevDebug, "cleanup done.\n"); |
391 | |
388 | |
392 | log_cleanup (); |
389 | log_cleanup (); |
393 | |
390 | |
394 | if (make_core) |
391 | if (make_core) |
395 | { |
|
|
396 | cleanup_inform (cause, make_core); |
392 | cleanup_inform (cause, make_core); |
397 | cfperl_cleanup (make_core); |
|
|
398 | _exit (1); |
|
|
399 | } |
|
|
400 | else |
393 | else |
401 | { |
394 | { |
402 | new_draw_info_format (NDI_REPLY | NDI_UNIQUE | NDI_ALL | NDI_GREEN, 0, 0, "Maps and players successfully saved, exiting."); |
395 | new_draw_info_format (NDI_REPLY | NDI_UNIQUE | NDI_ALL | NDI_GREEN, 0, 0, "Maps and players successfully saved, exiting."); |
403 | new_draw_info_format (NDI_REPLY | NDI_UNIQUE | NDI_ALL | NDI_GREEN, 0, 0, "And again: " CLEANUP_MESSAGE); |
396 | new_draw_info_format (NDI_REPLY | NDI_UNIQUE | NDI_ALL | NDI_GREEN, 0, 0, "And again: " CLEANUP_MESSAGE); |
404 | client::flush_sockets (); |
397 | client::flush_sockets (); |
|
|
398 | } |
|
|
399 | |
405 | cfperl_cleanup (make_core); |
400 | cfperl_cleanup (make_core); |
406 | _exit (0); |
401 | _exit (make_core); |
407 | } |
|
|
408 | } |
402 | } |
409 | |
403 | |
410 | /* |
404 | /* |
411 | * do_specials() is a collection of functions to call from time to time. |
405 | * do_specials() is a collection of functions to call from time to time. |
412 | * Modified 2000-1-14 MSW to use the global pticks count to determine how |
406 | * Modified 2000-1-14 MSW to use the global pticks count to determine how |
… | |
… | |
422 | */ |
416 | */ |
423 | void |
417 | void |
424 | do_specials (void) |
418 | do_specials (void) |
425 | { |
419 | { |
426 | shstr::gc (); |
420 | shstr::gc (); |
|
|
421 | archetype::gc (); |
427 | |
422 | |
428 | if (expect_false (!(pticks % TICKS_PER_HOUR))) |
423 | if (expect_false (!(pticks % TICKS_PER_HOUR))) |
429 | adjust_daylight (); |
424 | adjust_daylight (); |
430 | |
425 | |
431 | if (expect_false (!(pticks % 2503))) |
426 | if (expect_false (!(pticks % 2503))) |
… | |
… | |
505 | } |
500 | } |
506 | } |
501 | } |
507 | |
502 | |
508 | #else |
503 | #else |
509 | |
504 | |
|
|
505 | #if 0 // just goofing around, look elsewhere |
|
|
506 | |
|
|
507 | #include <malloc.h> |
|
|
508 | #include <execinfo.h> |
|
|
509 | |
|
|
510 | static void tr_on (); |
|
|
511 | static void tr_off (); |
|
|
512 | |
|
|
513 | static SMUTEX(tr_mutex); |
|
|
514 | |
|
|
515 | #define ltr_off() SMUTEX_LOCK (tr_mutex); tr_off () |
|
|
516 | #define ltr_on() tr_on (); SMUTEX_UNLOCK (tr_mutex); |
|
|
517 | |
|
|
518 | static void * |
|
|
519 | tr_malloc (size_t size, const void *caller) |
|
|
520 | { |
|
|
521 | ltr_off (); |
|
|
522 | |
|
|
523 | void *bt [8]; |
|
|
524 | backtrace (bt, 8); |
|
|
525 | |
|
|
526 | void *ptr = malloc (size); |
|
|
527 | |
|
|
528 | ltr_on (); |
|
|
529 | return (char *)ptr; |
|
|
530 | } |
|
|
531 | |
|
|
532 | static void |
|
|
533 | tr_free (void *ptr, const void *caller) |
|
|
534 | { |
|
|
535 | ltr_off (); |
|
|
536 | |
|
|
537 | free (ptr); |
|
|
538 | |
|
|
539 | ltr_on (); |
|
|
540 | } |
|
|
541 | |
|
|
542 | void static * |
|
|
543 | tr_realloc (void *ptr, size_t size, const void *caller) |
|
|
544 | { |
|
|
545 | ltr_off (); |
|
|
546 | |
|
|
547 | void *nptr = realloc (ptr, size); |
|
|
548 | |
|
|
549 | ltr_on (); |
|
|
550 | return nptr; |
|
|
551 | } |
|
|
552 | |
|
|
553 | static void * |
|
|
554 | tr_memalign (size_t size, size_t alignment, const void *caller) |
|
|
555 | { |
|
|
556 | ltr_off (); |
|
|
557 | |
|
|
558 | void *ptr = memalign (size, alignment < 16 ? 16 : alignment); |
|
|
559 | |
|
|
560 | ltr_on (); |
|
|
561 | return ptr; |
|
|
562 | } |
|
|
563 | |
|
|
564 | static void |
|
|
565 | tr_on () |
|
|
566 | { |
|
|
567 | __malloc_hook = tr_malloc; |
|
|
568 | __realloc_hook = tr_realloc; |
|
|
569 | __free_hook = tr_free; |
|
|
570 | __memalign_hook = tr_memalign; |
|
|
571 | } |
|
|
572 | |
|
|
573 | static void |
|
|
574 | tr_off () |
|
|
575 | { |
|
|
576 | __malloc_hook = 0; |
|
|
577 | __realloc_hook = 0; |
|
|
578 | __free_hook = 0; |
|
|
579 | __memalign_hook = 0; |
|
|
580 | } |
|
|
581 | |
|
|
582 | void (*__malloc_initialize_hook)(void) = tr_on; |
|
|
583 | |
|
|
584 | #endif |
|
|
585 | |
510 | // normal main |
586 | // normal main |
511 | int |
587 | int |
512 | main (int argc, char **argv) |
588 | main (int argc, char **argv) |
513 | { |
589 | { |
514 | settings.argc = argc; |
590 | settings.argc = argc; |
515 | settings.argv = argv; |
591 | settings.argv = argv; |
516 | |
592 | |
|
|
593 | g_thread_init (0); // for the slice allocator only |
|
|
594 | |
517 | init (argc, argv); |
595 | init (argc, argv); |
518 | |
596 | |
519 | for (;;) |
597 | for (;;) |
520 | cfperl_main (); |
598 | cfperl_main (); |
521 | } |
599 | } |