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.115 by root, Sat Nov 17 23:33:17 2018 UTC vs.
Revision 1.118 by root, Tue Nov 27 18:50:22 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,2012,2013,2014,2015,2016 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
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 ska::flat_hash_map< 37typedef ska::flat_hash_map
38 <
37 const char *, 39 const char *,
38 arch_ptr, 40 arch_ptr,
39 str_hash, 41 str_hash,
40 str_equal, 42 str_equal,
41 slice_allocator< std::pair<const char *const, arch_ptr> > 43 slice_allocator< std::pair<const char *const, arch_ptr> >
42> HT; 44 > HT;
43 45
44static HT ht (10000); 46static HT ht (10000);
45archvec archetypes; 47archvec archetypes;
46static unordered_vector<archetype *> allarch; 48static unordered_vector<archetype *> allarch;
47static int dirtycnt; 49static int dirtycnt;
422 goto fail; 424 goto fail;
423 } 425 }
424 } 426 }
425 427
426 { 428 {
427 auto (at, parts.begin ());
428
429 archetype *new_head = parts.front (); 429 archetype *new_head = parts.front ();
430 archetype *old_head = find (new_head->archname); 430 archetype *old_head = find (new_head->archname);
431 431
432 if (old_head && !old_head->is_head ()) 432 if (old_head && !old_head->is_head ())
433 { 433 {
435 &new_head->archname, &old_head->archname); 435 &new_head->archname, &old_head->archname);
436 goto fail; 436 goto fail;
437 } 437 }
438 438
439 // 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
440 for (auto (at, parts.begin ()); at != parts.end (); ++at) 440 for (auto &&at : parts)
441 { 441 {
442 archetype *new_part = *at; 442 archetype *new_part = at;
443 archetype *old_part = find (new_part->archname); 443 archetype *old_part = find (new_part->archname);
444 444
445 if (old_part && old_part->head_ () != old_head) 445 if (old_part && old_part->head_ () != old_head)
446 { 446 {
447 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",
452 452
453 // assemble new chain 453 // assemble new chain
454 new_head->max_x = new_head->x; 454 new_head->max_x = new_head->x;
455 455
456 archetype *less = new_head; 456 archetype *less = new_head;
457 for (auto (p, parts.begin () + 1); p != parts.end (); ++p) 457 for (auto &&p = parts.begin () + 1; p != parts.end (); ++p)
458 { 458 {
459 archetype *at = *p; 459 archetype *at = *p;
460 460
461 // some flags get inherited from the head (probably a lot more) 461 // some flags get inherited from the head (probably a lot more)
462 // 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
477 477
478 return new_head; 478 return new_head;
479 } 479 }
480 480
481fail: 481fail:
482 for (auto (p, parts.begin ()); p != parts.end (); ++p) 482 for (auto &&at : parts)
483 (*p)->destroy (); 483 at->destroy ();
484 484
485 return 0; 485 return 0;
486} 486}
487 487
488void 488void
494 494
495void 495void
496archetype::commit_load () 496archetype::commit_load ()
497{ 497{
498 // unlink old archetypes and link in new ones */ 498 // unlink old archetypes and link in new ones */
499 for (auto (p, postponed_arch.begin ()); p != postponed_arch.end (); ++p) 499 for (auto &&at : postponed_arch)
500 { 500 {
501 archetype *at = *p;
502
503 if (archetype *old = find (at->archname)) 501 if (archetype *old = find (at->archname))
504 old->unlink (); 502 old->unlink ();
505 503
506 allarch.push_back (at); 504 allarch.push_back (at);
507 505
510 } 508 }
511 509
512 postponed_arch.clear (); 510 postponed_arch.clear ();
513 511
514 // now resolve arch references 512 // now resolve arch references
515 for (auto (p, postponed_arch_ref.begin ()); p != postponed_arch_ref.end (); ++p) 513 for (auto &&p : postponed_arch_ref) // not yet C++17
516 { 514 {
517 arch_ptr *ap = p->first; 515 arch_ptr *ap = p.first;
518 archetype *at = find (p->second); 516 archetype *at = find (p.second);
519 517
520 if (!at) 518 if (!at)
521 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);
522 520
523 *ap = at; 521 *ap = at;
524 } 522 }
525 523
526 postponed_arch_ref.clear (); 524 postponed_arch_ref.clear ();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines