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,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2001-2003,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2001-2003 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
11 | * option) any later version. |
… | |
… | |
33 | |
33 | |
34 | #include <../random_maps/random_map.h> |
34 | #include <../random_maps/random_map.h> |
35 | #include <../random_maps/rproto.h> |
35 | #include <../random_maps/rproto.h> |
36 | #include "path.h" |
36 | #include "path.h" |
37 | |
37 | |
38 | static char days[7][4] = { |
|
|
39 | "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" |
|
|
40 | }; |
|
|
41 | |
|
|
42 | void |
38 | void |
43 | version (object *op) |
39 | version (object *op) |
44 | { |
40 | { |
45 | 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); |
46 | } |
42 | } |
… | |
… | |
151 | if (i < 0) |
147 | if (i < 0) |
152 | golem->drop_and_destroy (); |
148 | golem->drop_and_destroy (); |
153 | else |
149 | else |
154 | { |
150 | { |
155 | newmap->insert (golem, x + freearr_x[i], y + freearr_y[i]); |
151 | newmap->insert (golem, x + freearr_x[i], y + freearr_y[i]); |
156 | golem->direction = find_dir_2 (x - golem->x, y - golem->y); |
152 | golem->direction = find_dir_2 (golem->x - x, golem->y - y); |
157 | } |
153 | } |
158 | } |
154 | } |
159 | |
155 | |
160 | /* since the players map is already loaded, we don't need to worry |
156 | /* since the players map is already loaded, we don't need to worry |
161 | * about pending objects. |
157 | * about pending objects. |
… | |
… | |
191 | |
187 | |
192 | for_all_players (pl) |
188 | for_all_players (pl) |
193 | { |
189 | { |
194 | object *ob = pl->ob; |
190 | object *ob = pl->ob; |
195 | |
191 | |
|
|
192 | // process_objects destroys the speed_left value |
|
|
193 | pl->speed_left_save = ob->speed_left; |
|
|
194 | |
196 | if (expect_false (!ob || !pl->ns || !ob->active)) |
195 | if (expect_false (!ob || !pl->ns || !ob->active)) |
197 | continue; |
196 | continue; |
198 | |
197 | |
199 | do_some_living (ob); |
198 | do_some_living (ob); |
200 | } |
199 | } |
… | |
… | |
204 | process_players2 () |
203 | process_players2 () |
205 | { |
204 | { |
206 | /* 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 */ |
207 | for_all_players (pl) |
206 | for_all_players (pl) |
208 | { |
207 | { |
|
|
208 | // restore speed_left value saved by process_players1 |
|
|
209 | pl->ob->speed_left = pl->speed_left_save; |
|
|
210 | |
209 | 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); |
210 | 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); |
211 | } |
213 | } |
212 | } |
214 | } |
213 | |
215 | |
… | |
… | |
216 | { |
218 | { |
217 | process_players1 (); |
219 | process_players1 (); |
218 | |
220 | |
219 | for_all_actives (op) |
221 | for_all_actives (op) |
220 | { |
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 | |
221 | /* Now process op */ |
237 | /* Now process op */ |
222 | if (expect_false (QUERY_FLAG (op, FLAG_FREED))) |
238 | if (expect_false (op->flag [FLAG_FREED])) |
223 | { |
239 | { |
224 | LOG (llevError, "BUG: process_events(): Free object on list\n"); |
240 | LOG (llevError, "BUG: process_events(): Free object on list\n"); |
225 | op->set_speed (0); |
241 | op->set_speed (0); |
226 | continue; |
242 | continue; |
227 | } |
243 | } |
… | |
… | |
257 | { |
273 | { |
258 | --op->speed_left; |
274 | --op->speed_left; |
259 | process_object (op); |
275 | process_object (op); |
260 | } |
276 | } |
261 | |
277 | |
262 | if (expect_true (!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. |
263 | op->speed_left = min (abs (op->speed), op->speed_left + abs (op->speed)); |
281 | op->speed_left = min (op->speed, op->speed_left + op->speed); |
264 | } |
282 | } |
265 | |
283 | |
266 | process_players2 (); |
284 | process_players2 (); |
267 | } |
285 | } |
268 | |
286 | |
… | |
… | |
353 | * |
371 | * |
354 | * 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 |
355 | * doing the various things. |
373 | * doing the various things. |
356 | */ |
374 | */ |
357 | static void |
375 | static void |
358 | do_specials (void) |
376 | do_specials () |
359 | { |
377 | { |
360 | shstr::gc (); |
378 | shstr::gc (); |
361 | archetype::gc (); |
379 | archetype::gc (); |
362 | |
380 | |
363 | if (expect_false (!(pticks % TICKS_PER_HOUR))) |
381 | if (expect_false (!(pticks % TICKS_PER_HOUR))) |
… | |
… | |
390 | // then do some bookkeeping, should not really be here |
408 | // then do some bookkeeping, should not really be here |
391 | do_specials (); /* Routines called from time to time. */ |
409 | do_specials (); /* Routines called from time to time. */ |
392 | attachable::check_mortals (); |
410 | attachable::check_mortals (); |
393 | |
411 | |
394 | ++pticks; |
412 | ++pticks; |
|
|
413 | |
|
|
414 | if (object::object_count >= RESTART_COUNT) |
|
|
415 | cleanup ("running out of protocol ID values - need full restart"); |
395 | } |
416 | } |
396 | |
417 | |
397 | // normal main |
418 | // normal main |
398 | int |
419 | int |
399 | main (int argc, char **argv) |
420 | main (int argc, char **argv) |