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

Comparing deliantra/server/common/arch.C (file contents):
Revision 1.109 by root, Sat Dec 31 06:18:00 2011 UTC vs.
Revision 1.119 by root, Sat Dec 1 20:22:12 2018 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 (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 5 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team 6 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992 Frank Tore Johansen 7 * Copyright (©) 1992 Frank Tore Johansen
7 * 8 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 9 * 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 10 * 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 11 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 12 * option) any later version.
12 * 13 *
13 * This program is distributed in the hope that it will be useful, 14 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 17 * GNU General Public License for more details.
17 * 18 *
18 * You should have received a copy of the Affero GNU General Public License 19 * You should have received a copy of the Affero GNU General Public License
19 * and the GNU General Public License along with this program. If not, see 20 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>. 21 * <http://www.gnu.org/licenses/>.
21 * 22 *
22 * The authors can be reached via e-mail to <support@deliantra.net> 23 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 24 */
24 25
25#include <cassert> 26#include <cassert>
27#include <functional>
28
29#include <flat_hash_map.hpp>
26 30
27#include <global.h> 31#include <global.h>
28
29#include <tr1/functional>
30#include <tr1/unordered_map>
31 32
32archetype *loading_arch; // ugly flag to object loader etc. to suppress/request special processing 33archetype *loading_arch; // ugly flag to object loader etc. to suppress/request special processing
33arch_ptr archetype::empty; 34arch_ptr archetype::empty;
34 35
35// the hashtable 36// the hashtable
36typedef std::tr1::unordered_map 37typedef ska::flat_hash_map
37 < 38 <
38 const char *, 39 const char *,
39 arch_ptr, 40 arch_ptr,
40 str_hash, 41 str_hash,
41 str_equal, 42 str_equal,
346archetype::find (const char *name) 347archetype::find (const char *name)
347{ 348{
348 if (!name) 349 if (!name)
349 return 0; 350 return 0;
350 351
351 auto (i, ht.find (name)); 352 auto i = ht.find (name);
352 353
353 if (i == ht.end ()) 354 if (i == ht.end ())
354 return 0; 355 return 0;
355 else 356 else
356 return i->second; 357 return i->second;
423 goto fail; 424 goto fail;
424 } 425 }
425 } 426 }
426 427
427 { 428 {
428 auto (at, parts.begin ());
429
430 archetype *new_head = parts.front (); 429 archetype *new_head = parts.front ();
431 archetype *old_head = find (new_head->archname); 430 archetype *old_head = find (new_head->archname);
432 431
433 if (old_head && !old_head->is_head ()) 432 if (old_head && !old_head->is_head ())
434 { 433 {
436 &new_head->archname, &old_head->archname); 435 &new_head->archname, &old_head->archname);
437 goto fail; 436 goto fail;
438 } 437 }
439 438
440 // check that all archetypes belong to the same old object or are new 439 // check that all archetypes belong to the same old object or are new
441 for (auto (at, parts.begin ()); at != parts.end (); ++at) 440 for (auto &&at : parts)
442 { 441 {
443 archetype *new_part = *at; 442 archetype *new_part = at;
444 archetype *old_part = find (new_part->archname); 443 archetype *old_part = find (new_part->archname);
445 444
446 if (old_part && old_part->head_ () != old_head) 445 if (old_part && old_part->head_ () != old_head)
447 { 446 {
448 LOG (llevError, "%s: unable to overwrite archetype '%s' with archetype of different object, skipping.\n", 447 LOG (llevError, "%s: unable to overwrite archetype '%s' with archetype of different object, skipping.\n",
453 452
454 // assemble new chain 453 // assemble new chain
455 new_head->max_x = new_head->x; 454 new_head->max_x = new_head->x;
456 455
457 archetype *less = new_head; 456 archetype *less = new_head;
458 for (auto (p, parts.begin () + 1); p != parts.end (); ++p) 457 for (auto &&p = parts.begin () + 1; p != parts.end (); ++p)
459 { 458 {
460 archetype *at = *p; 459 archetype *at = *p;
461 460
462 // some flags get inherited from the head (probably a lot more) 461 // some flags get inherited from the head (probably a lot more)
463 // doing it here doesn't feel too cozy, but it allows code 462 // doing it here doesn't feel too cozy, but it allows code
478 477
479 return new_head; 478 return new_head;
480 } 479 }
481 480
482fail: 481fail:
483 for (auto (p, parts.begin ()); p != parts.end (); ++p) 482 for (auto &&at : parts)
484 (*p)->destroy (); 483 at->destroy ();
485 484
486 return 0; 485 return 0;
487} 486}
488 487
489void 488void
495 494
496void 495void
497archetype::commit_load () 496archetype::commit_load ()
498{ 497{
499 // unlink old archetypes and link in new ones */ 498 // unlink old archetypes and link in new ones */
500 for (auto (p, postponed_arch.begin ()); p != postponed_arch.end (); ++p) 499 for (auto &&at : postponed_arch)
501 { 500 {
502 archetype *at = *p;
503
504 if (archetype *old = find (at->archname)) 501 if (archetype *old = find (at->archname))
505 old->unlink (); 502 old->unlink ();
506 503
507 allarch.push_back (at); 504 allarch.push_back (at);
508 505
511 } 508 }
512 509
513 postponed_arch.clear (); 510 postponed_arch.clear ();
514 511
515 // now resolve arch references 512 // now resolve arch references
516 for (auto (p, postponed_arch_ref.begin ()); p != postponed_arch_ref.end (); ++p) 513 for (auto &&p : postponed_arch_ref) // not yet C++17
517 { 514 {
518 arch_ptr *ap = p->first; 515 arch_ptr *ap = p.first;
519 archetype *at = find (p->second); 516 archetype *at = find (p.second);
520 517
521 if (!at) 518 if (!at)
522 LOG (llevError, "unable to resolve postponed arch reference to '%s'", &p->second); 519 LOG (llevError, "unable to resolve postponed arch reference to '%s'", &p.second);
523 520
524 *ap = at; 521 *ap = at;
525 } 522 }
526 523
527 postponed_arch_ref.clear (); 524 postponed_arch_ref.clear ();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines