ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/main.C
(Generate patch)

Comparing deliantra/server/server/main.C (file contents):
Revision 1.121 by root, Sun Dec 16 02:36:29 2007 UTC vs.
Revision 1.132 by root, Mon Sep 29 10:20:49 2008 UTC

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 */
108void 110void
109enter_player_savebed (object *op) 111enter_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
124 * the function that calls this should figure them out. 121 * the function that calls this should figure them out.
125 */ 122 */
126void 123void
127object::enter_map (maptile *newmap, int x, int y) 124object::enter_map (maptile *newmap, int x, int y)
128{ 125{
129 if (destroyed () || !newmap || newmap->in_memory != MAP_IN_MEMORY) 126 if (destroyed () || !newmap || newmap->in_memory != MAP_ACTIVE)
130 return; 127 return;
131 128
132 if (out_of_map (newmap, x, y)) 129 if (out_of_map (newmap, x, y))
133 { 130 {
134 LOG (llevError, "enter_map: supplied coordinates are not within the map! (%s: %d, %d)\n", &newmap->path, x, y); 131 LOG (llevError, "enter_map: supplied coordinates are not within the map! (%s: %d, %d)\n", &newmap->path, x, y);
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}
387 LOG (llevDebug, "running cleanup handlers.\n"); 384 LOG (llevDebug, "running cleanup handlers.\n");
388 INVOKE_GLOBAL (CLEANUP); 385 INVOKE_GLOBAL (CLEANUP);
389 386
390 LOG (llevDebug, "cleanup done.\n"); 387 LOG (llevDebug, "cleanup done.\n");
391 388
389 log_cleanup ();
390
392 if (make_core) 391 if (make_core)
393 {
394 cleanup_inform (cause, make_core); 392 cleanup_inform (cause, make_core);
395 cfperl_cleanup (make_core);
396 _exit (1);
397 }
398 else 393 else
399 { 394 {
400 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.");
401 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);
402 client::flush_sockets (); 397 client::flush_sockets ();
398 }
399
403 cfperl_cleanup (make_core); 400 cfperl_cleanup (make_core);
404 _exit (0); 401 _exit (make_core);
405 }
406} 402}
407 403
408/* 404/*
409 * 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.
410 * 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
419 * doing the various things. 415 * doing the various things.
420 */ 416 */
421void 417void
422do_specials (void) 418do_specials (void)
423{ 419{
420 shstr::gc ();
421 archetype::gc ();
422
424 if (expect_false (!(pticks % TICKS_PER_HOUR))) 423 if (expect_false (!(pticks % TICKS_PER_HOUR)))
425 adjust_daylight (); 424 adjust_daylight ();
426
427 if (expect_false (!(pticks % 89)))
428 shstr::gc ();
429 425
430 if (expect_false (!(pticks % 2503))) 426 if (expect_false (!(pticks % 2503)))
431 fix_weight (); /* Hack to fix weightproblems caused by bugs */ 427 fix_weight (); /* Hack to fix weightproblems caused by bugs */
432 428
433 if (expect_false (!(pticks % 5003))) 429 if (expect_false (!(pticks % 5003)))
504 } 500 }
505} 501}
506 502
507#else 503#else
508 504
505#if 0 // just goofing around, look elsewhere
506
507#include <malloc.h>
508#include <execinfo.h>
509
510static void tr_on ();
511static void tr_off ();
512
513static 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
518static void *
519tr_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
532static void
533tr_free (void *ptr, const void *caller)
534{
535 ltr_off ();
536
537 free (ptr);
538
539 ltr_on ();
540}
541
542void static *
543tr_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
553static void *
554tr_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
564static void
565tr_on ()
566{
567 __malloc_hook = tr_malloc;
568 __realloc_hook = tr_realloc;
569 __free_hook = tr_free;
570 __memalign_hook = tr_memalign;
571}
572
573static void
574tr_off ()
575{
576 __malloc_hook = 0;
577 __realloc_hook = 0;
578 __free_hook = 0;
579 __memalign_hook = 0;
580}
581
582void (*__malloc_initialize_hook)(void) = tr_on;
583
584#endif
585
509// normal main 586// normal main
510int 587int
511main (int argc, char **argv) 588main (int argc, char **argv)
512{ 589{
513 settings.argc = argc; 590 settings.argc = argc;
514 settings.argv = argv; 591 settings.argv = argv;
515 592
593 g_thread_init (0); // for the slice allocator only
594
516 init (argc, argv); 595 init (argc, argv);
517 596
518 for (;;) 597 for (;;)
519 cfperl_main (); 598 cfperl_main ();
520} 599}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines