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.123 by root, Tue Apr 15 03:16:02 2008 UTC vs.
Revision 1.144 by root, Thu Nov 19 04:30:46 2009 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 it under
9 * it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation, either version 3 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 11 * option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
20 * 21 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 22 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 23 */
23 24
24#include <global.h> 25#include <global.h>
26#include <tod.h> 27#include <tod.h>
27 28
28#include <sproto.h> 29#include <sproto.h>
29#include <time.h> 30#include <time.h>
30 31
32#include <glib.h>
33
31#include <../random_maps/random_map.h> 34#include <../random_maps/random_map.h>
32#include <../random_maps/rproto.h> 35#include <../random_maps/rproto.h>
33#include "path.h" 36#include "path.h"
34 37
35static char days[7][4] = {
36 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
37};
38
39void 38void
40version (object *op) 39version (object *op)
41{ 40{
42 new_draw_info_format (NDI_UNIQUE, 0, op, "This is Deliantra v%s", VERSION); 41 new_draw_info_format (NDI_UNIQUE, 0, op, "This is Deliantra v%s", VERSION);
43
44#if 0
45 new_draw_info (NDI_UNIQUE, 0, op, "Authors and contributors to this program:");
46 new_draw_info (NDI_UNIQUE, 0, op, "Marc A. Lehmann <pcg@goof.com>");
47 new_draw_info (NDI_UNIQUE, 0, op, "Robin Redeker <elmex@x-paste.de>");
48 new_draw_info (NDI_UNIQUE, 0, op, "Pippijn van Steenhoven <pip88nl@gmail.com>");
49 new_draw_info (NDI_UNIQUE, 0, op, "");
50 new_draw_info (NDI_UNIQUE, 0, op, "Authors and contributors to the original Crossfire:");
51 new_draw_info (NDI_UNIQUE, 0, op, "Mark Wedel <mwedel@sonic.net>");
52 new_draw_info (NDI_UNIQUE, 0, op, "Frank Tore Johansen <frankj@ifi.uio.no>");
53 new_draw_info (NDI_UNIQUE, 0, op, "Kjetil Torgrim Homme <kjetilho@ifi.uio.no>");
54 new_draw_info (NDI_UNIQUE, 0, op, "Tyler Van Gorder <tvangod@ecst.csuchico.edu>");
55 new_draw_info (NDI_UNIQUE, 0, op, "Tony Elmroth <elmroth@cd.chalmers.se>");
56 new_draw_info (NDI_UNIQUE, 0, op, "Dougal Scott <dougal.scott@fcit.monasu.edu.au>");
57 new_draw_info (NDI_UNIQUE, 0, op, "William <wchuang@athena.mit.edu>");
58 new_draw_info (NDI_UNIQUE, 0, op, "Geoff Bailey <ftww@cs.su.oz.au>");
59 new_draw_info (NDI_UNIQUE, 0, op, "Kjetil Wiekhorst Jørgensen <jorgens@flipper.pvv.unit.no>");
60 new_draw_info (NDI_UNIQUE, 0, op, "Cameron Blackwood <c.blackwood@rdt.monash.edu.au>");
61 new_draw_info (NDI_UNIQUE, 0, op, "Joseph L. Traub <jtraub+@cmu.edu>");
62 new_draw_info (NDI_UNIQUE, 0, op, "Rupert G. Goldie <rgg@aaii.oz.au>");
63 new_draw_info (NDI_UNIQUE, 0, op, "Eric A. Anderson <eanders+@cmu.edu>");
64 new_draw_info (NDI_UNIQUE, 0, op, "Rickard Eneqvist <eneq@Prag.DoCS.UU.SE>");
65 new_draw_info (NDI_UNIQUE, 0, op, "Jarkko Sonninen <Jarkko.Sonninen@lut.fi>");
66 new_draw_info (NDI_UNIQUE, 0, op, "Karl Holland <kholland@sunlab.cit.cornell.du>");
67 new_draw_info (NDI_UNIQUE, 0, op, "Mikael Lundgren <vick@bern.docs.uu.se>");
68 new_draw_info (NDI_UNIQUE, 0, op, "Mikael Olsson <mol@meryl.csd.uu.se>");
69 new_draw_info (NDI_UNIQUE, 0, op, "Tero Haatanen <Tero.Haatanen@lut.fi>");
70 new_draw_info (NDI_UNIQUE, 0, op, "Lasse Ylitalo <ylitalo@student.docs.uu.se>");
71 new_draw_info (NDI_UNIQUE, 0, op, "Niilo Neuvo <anipa@guru.magic.fi>");
72 new_draw_info (NDI_UNIQUE, 0, op, "Markku J{rvinen <mta@modeemi.cs.tut.fi>");
73 new_draw_info (NDI_UNIQUE, 0, op, "Sylvain Meunier <meunier@inf.enst.fr>");
74 new_draw_info (NDI_UNIQUE, 0, op, "Jason Fosback <jfosback@darmok.uoregon.edu>");
75 new_draw_info (NDI_UNIQUE, 0, op, "Carl Edman <cedman@capitalist.princeton.edu>");
76 new_draw_info (NDI_UNIQUE, 0, op, "Charles Henrich <henrich@crh.cl.msu.edu>");
77 new_draw_info (NDI_UNIQUE, 0, op, "Gregor Schmid <schmid@fb3-s7.math.tu-berlin.de>");
78 new_draw_info (NDI_UNIQUE, 0, op, "Raphael Quinet <quinet@montefiore.ulg.ac.be>");
79 new_draw_info (NDI_UNIQUE, 0, op, "Jari Vanhala <jam@modeemi.cs.tut.fi>");
80 new_draw_info (NDI_UNIQUE, 0, op, "Tero Kivinen <kivinen@joker.cs.hut.fi>");
81 new_draw_info (NDI_UNIQUE, 0, op, "Peter Mardahl <peterm@soda.berkeley.edu>");
82 new_draw_info (NDI_UNIQUE, 0, op, "Matthew Zeher <matt@cs.odu.edu>");
83 new_draw_info (NDI_UNIQUE, 0, op, "Scott R. Turner <srt@sun-dimas.aero.org>");
84 new_draw_info (NDI_UNIQUE, 0, op, "Ben Fennema <huma@netcom.com>");
85 new_draw_info (NDI_UNIQUE, 0, op, "Nick Williams <njw@cs.city.ac.uk>");
86 new_draw_info (NDI_UNIQUE, 0, op, "Laurent Wacrenier <Wacren@Gin.ObsPM.Fr>");
87 new_draw_info (NDI_UNIQUE, 0, op, "Brian Thomas <thomas@astro.psu.edu>");
88 new_draw_info (NDI_UNIQUE, 0, op, "John Steven Moerk <jsm@axon.ksc.nasa.gov>");
89 new_draw_info (NDI_UNIQUE, 0, op, "Delbecq David <david.delbecq@mailandnews.com>");
90 new_draw_info (NDI_UNIQUE, 0, op, "Chachkoff Yann <yann.chachkoff@mailandnews.com>\n");
91 new_draw_info (NDI_UNIQUE, 0, op, "");
92 new_draw_info (NDI_UNIQUE, 0, op, "Images and art:");
93 new_draw_info (NDI_UNIQUE, 0, op, "Peter Gardner");
94 new_draw_info (NDI_UNIQUE, 0, op, "David Gervais <david_eg@mail.com>");
95 new_draw_info (NDI_UNIQUE, 0, op, "Mitsuhiro Itakura <ita@gold.koma.jaeri.go.jp>");
96 new_draw_info (NDI_UNIQUE, 0, op, "Hansjoerg Malthaner <hansjoerg.malthaner@danet.de>");
97 new_draw_info (NDI_UNIQUE, 0, op, "Mårten Woxberg <maxmc@telia.com>");
98 new_draw_info (NDI_UNIQUE, 0, op, "");
99 new_draw_info (NDI_UNIQUE, 0, op, "And many more!");
100#endif
101} 42}
102 43
103/* This is a basic little function to put the player back to his 44/* This is a basic little function to put the player back to his
104 * savebed. We do some error checking - its possible that the 45 * savebed. We do some error checking - its possible that the
105 * savebed map may no longer exist, so we make sure the player 46 * savebed map may no longer exist, so we make sure the player
106 * goes someplace. 47 * goes someplace.
107 */ 48 */
108void 49void
109enter_player_savebed (object *op) 50enter_player_savebed (object *op)
110{ 51{
111 object *tmp = object::create (); 52 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} 53}
118 54
119/* 55/*
120 * enter_map(): Moves the player and pets from current map (if any) to 56 * 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 57 * 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. 60 * the function that calls this should figure them out.
125 */ 61 */
126void 62void
127object::enter_map (maptile *newmap, int x, int y) 63object::enter_map (maptile *newmap, int x, int y)
128{ 64{
129 if (destroyed () || !newmap || newmap->in_memory != MAP_IN_MEMORY) 65 if (destroyed () || !newmap || newmap->in_memory != MAP_ACTIVE)
130 return; 66 return;
131 67
132 if (out_of_map (newmap, x, y)) 68 if (out_of_map (newmap, x, y))
133 { 69 {
134 LOG (llevError, "enter_map: supplied coordinates are not within the map! (%s: %d, %d)\n", &newmap->path, x, y); 70 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) 143 if (object *golem = contr->golem)
208 { 144 {
209 int i = find_free_spot (golem, newmap, x, y, 1, SIZEOFFREE); 145 int i = find_free_spot (golem, newmap, x, y, 1, SIZEOFFREE);
210 146
211 if (i < 0) 147 if (i < 0)
212 golem->destroy (); 148 golem->drop_and_destroy ();
213 else 149 else
214 { 150 {
215 newmap->insert (golem, x + freearr_x[i], y + freearr_y[i]); 151 newmap->insert (golem, x + freearr_x[i], y + freearr_y[i]);
216 golem->direction = find_dir_2 (x - golem->x, y - golem->y); 152 golem->direction = find_dir_2 (x - golem->x, y - golem->y);
217 } 153 }
251 187
252 for_all_players (pl) 188 for_all_players (pl)
253 { 189 {
254 object *ob = pl->ob; 190 object *ob = pl->ob;
255 191
192 // process_objects destroys the speed_left value
193 pl->speed_left_save = ob->speed_left;
194
256 if (expect_false (!ob || !pl->ns || !ob->active)) 195 if (expect_false (!ob || !pl->ns || !ob->active))
257 continue; 196 continue;
258 197
259 do_some_living (ob); 198 do_some_living (ob);
260 } 199 }
264process_players2 () 203process_players2 ()
265{ 204{
266 /* Then check if any players should use weapon-speed instead of speed */ 205 /* Then check if any players should use weapon-speed instead of speed */
267 for_all_players (pl) 206 for_all_players (pl)
268 { 207 {
208 // restore speed_left value saved by process_players1
209 pl->ob->speed_left = pl->speed_left_save;
210
269 pl->weapon_sp_left = min (pl->weapon_sp, pl->weapon_sp_left + pl->weapon_sp); 211 pl->weapon_sp_left = min (pl->weapon_sp, pl->weapon_sp_left + pl->weapon_sp);
270 pl->ob->speed_left = min (pl->ob->speed, pl->ob->speed_left + pl->ob->speed); 212 pl->ob->speed_left = min (pl->ob->speed, pl->ob->speed_left + pl->ob->speed);
271 } 213 }
272} 214}
273 215
274void 216static void
275process_events () 217process_events ()
276{ 218{
277 process_players1 (); 219 process_players1 ();
278 220
279 for_all_actives (op) 221 for_all_actives (op)
280 { 222 {
223 // try to prefetch some stuff we expect to need
224 // obviously, it should be grouped into the same cacheline.
225 // preliminary results indicate that this gives halves the speed
226 // used for the inner loop
227 if (_i < actives.size ()) // HACK, rely on _i :/
228 {
229 object *next = actives [_i + 1];
230
231 prefetch (&next->flag , 0, 1);
232 prefetch (&next->speed , 0, 1);
233 prefetch (&next->anim_speed, 0, 1);
234 prefetch (&next->contr , 0, 1);
235 }
236
281 /* Now process op */ 237 /* Now process op */
282 if (expect_false (QUERY_FLAG (op, FLAG_FREED))) 238 if (expect_false (QUERY_FLAG (op, FLAG_FREED)))
283 { 239 {
284 LOG (llevError, "BUG: process_events(): Free object on list\n"); 240 LOG (llevError, "BUG: process_events(): Free object on list\n");
285 op->set_speed (0); 241 op->set_speed (0);
311 op->last_anim = 1; 267 op->last_anim = 1;
312 } 268 }
313 else 269 else
314 ++op->last_anim; 270 ++op->last_anim;
315 271
316 if (op->speed_left > 0.f) 272 if (expect_false (op->speed_left > 0.f))
317 { 273 {
318 --op->speed_left; 274 --op->speed_left;
319 process_object (op); 275 process_object (op);
320
321 if (op->destroyed ())
322 continue;
323 } 276 }
324 277
325 if (!op->contr) 278 // this will destroy the speed_left value for players, but
279 // process_players1 and ..2 save/restore the real value,
280 // so we can avoid a costly test here.
326 op->speed_left = min (abs (op->speed), op->speed_left + abs (op->speed)); 281 op->speed_left = min (abs (op->speed), op->speed_left + abs (op->speed));
327 } 282 }
328 283
329 process_players2 (); 284 process_players2 ();
330} 285}
331 286
390 LOG (llevDebug, "cleanup done.\n"); 345 LOG (llevDebug, "cleanup done.\n");
391 346
392 log_cleanup (); 347 log_cleanup ();
393 348
394 if (make_core) 349 if (make_core)
395 {
396 cleanup_inform (cause, make_core); 350 cleanup_inform (cause, make_core);
397 cfperl_cleanup (make_core);
398 _exit (1);
399 }
400 else 351 else
401 { 352 {
402 new_draw_info_format (NDI_REPLY | NDI_UNIQUE | NDI_ALL | NDI_GREEN, 0, 0, "Maps and players successfully saved, exiting."); 353 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); 354 new_draw_info_format (NDI_REPLY | NDI_UNIQUE | NDI_ALL | NDI_GREEN, 0, 0, "And again: " CLEANUP_MESSAGE);
404 client::flush_sockets (); 355 client::flush_sockets ();
356 }
357
405 cfperl_cleanup (make_core); 358 cfperl_cleanup (make_core);
406 _exit (0); 359 _exit (make_core);
407 }
408} 360}
409 361
410/* 362/*
411 * do_specials() is a collection of functions to call from time to time. 363 * 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 364 * Modified 2000-1-14 MSW to use the global pticks count to determine how
418 * done on the same tick, but that will happen very infrequently 370 * done on the same tick, but that will happen very infrequently
419 * 371 *
420 * I also think this code makes it easier to see how often we really are 372 * I also think this code makes it easier to see how often we really are
421 * doing the various things. 373 * doing the various things.
422 */ 374 */
423void 375static void
424do_specials (void) 376do_specials (void)
425{ 377{
426 shstr::gc (); 378 shstr::gc ();
379 archetype::gc ();
427 380
428 if (expect_false (!(pticks % TICKS_PER_HOUR))) 381 if (expect_false (!(pticks % TICKS_PER_HOUR)))
429 adjust_daylight (); 382 maptile::adjust_daylight ();
430 383
431 if (expect_false (!(pticks % 2503))) 384 if (expect_false (!(pticks % 2503)))
432 fix_weight (); /* Hack to fix weightproblems caused by bugs */ 385 fix_weight (); /* Hack to fix weightproblems caused by bugs */
433 386
434 if (expect_false (!(pticks % 5003))) 387 if (expect_false (!(pticks % 5003)))
457 attachable::check_mortals (); 410 attachable::check_mortals ();
458 411
459 ++pticks; 412 ++pticks;
460} 413}
461 414
462#if 0
463// used fro benchmarking (x86/amd64-specific)
464typedef unsigned long tval;
465typedef unsigned long long stamp64;
466
467extern inline tval
468stamp (void)
469{
470 tval tsc;
471 asm volatile ("rdtsc":"=a" (tsc)::"edx");
472
473 return tsc;
474}
475
476extern inline tval
477measure (tval t)
478{
479 tval tsc;
480 asm volatile ("rdtsc":"=a" (tsc)::"edx");
481
482 if (tsc > t)
483 return tsc - t;
484 else
485 return t - tsc;
486}
487
488int
489main (int argc, char **argv)
490{
491 rand_gen rg(0);
492 tval fastest = 0x7fffffff;
493 for (int loop = 10000; loop--; )
494 {
495 tval s = stamp ();
496 volatile int i = rg.get_int(25);
497 fastest = min (fastest, measure (s));
498 }
499
500 //printf ("fastest %d\n", fastest);
501 for (int i = 0; i < 1024*1024*3; ++i)
502 {
503 char c = rg.get_int (256);
504 write (2, &c, 1);
505 }
506}
507
508#else
509
510// normal main 415// normal main
511int 416int
512main (int argc, char **argv) 417main (int argc, char **argv)
513{ 418{
514 settings.argc = argc; 419 settings.argc = argc;
515 settings.argv = argv; 420 settings.argv = argv;
421
422 rndm.seed (time (0));
423 g_thread_init (0); // for the slice allocator only
516 424
517 init (argc, argv); 425 init (argc, argv);
518 426
519 for (;;) 427 for (;;)
520 cfperl_main (); 428 cfperl_main ();
521} 429}
522#endif
523 430
524#if 0
525int xyzzy ()
526{
527 return rndm(8);
528}
529
530void xyzzy (object_ptr &a, object_ptr &o)
531{
532 asm volatile ("int3");
533 a = o;
534 asm volatile ("int3");
535}
536#endif
537

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines