… | |
… | |
324 | assert (f.kw == KW_object); |
324 | assert (f.kw == KW_object); |
325 | |
325 | |
326 | typedef std::pair<archetype *, object *> part; |
326 | typedef std::pair<archetype *, object *> part; |
327 | std::vector<part> parts; |
327 | std::vector<part> parts; |
328 | |
328 | |
|
|
329 | coroapi::cede_to_tick_every (100); |
|
|
330 | |
329 | for (;;) |
331 | for (;;) |
330 | { |
332 | { |
331 | archetype *at = get (f.get_str ()); |
333 | archetype *at = get (f.get_str ()); |
332 | object *op = object::create (); |
334 | object *op = object::create (); |
333 | |
335 | |
… | |
… | |
345 | |
347 | |
346 | { |
348 | { |
347 | archetype *head = parts.front ().first; |
349 | archetype *head = parts.front ().first; |
348 | |
350 | |
349 | // check that all archetypes belong to the same object or are heads |
351 | // check that all archetypes belong to the same object or are heads |
350 | for (AUTODECL (p, parts.begin ()); p != parts.end (); ++p) |
352 | for (auto (p, parts.begin ()); p != parts.end (); ++p) |
351 | { |
353 | { |
352 | archetype *at = p->first; |
354 | archetype *at = p->first; |
353 | |
355 | |
354 | if (at->head != head && at->head) |
356 | if (at->head != head && at->head) |
355 | { |
357 | { |
… | |
… | |
377 | overwrite (head, parts.front ().second); |
379 | overwrite (head, parts.front ().second); |
378 | head->tail_x = 0; |
380 | head->tail_x = 0; |
379 | head->tail_y = 0; |
381 | head->tail_y = 0; |
380 | |
382 | |
381 | // link into list of heads, if not already there |
383 | // link into list of heads, if not already there |
382 | if (!head->next) |
384 | if (!head->linked) |
383 | { |
385 | { |
|
|
386 | head->linked = true; |
384 | head->next = first_archetype; |
387 | head->next = first_archetype; |
385 | first_archetype = head; |
388 | first_archetype = head; |
386 | } |
389 | } |
387 | |
390 | |
388 | // reassemble new chain |
391 | // reassemble new chain |
389 | archetype *prev = head; |
392 | archetype *prev = head; |
390 | for (AUTODECL (p, parts.begin () + 1); p != parts.end (); ++p) |
393 | for (auto (p, parts.begin () + 1); p != parts.end (); ++p) |
391 | { |
394 | { |
392 | archetype *at = p->first; |
395 | archetype *at = p->first; |
393 | overwrite (at, p->second); |
396 | overwrite (at, p->second); |
394 | |
397 | |
395 | if (at->clone.x > head->tail_x) head->tail_x = at->clone.x; |
398 | if (at->clone.x > head->tail_x) head->tail_x = at->clone.x; |
… | |
… | |
405 | } |
408 | } |
406 | |
409 | |
407 | return true; |
410 | return true; |
408 | |
411 | |
409 | fail: |
412 | fail: |
410 | for (AUTODECL (p, parts.begin ()); p != parts.end (); ++p) |
413 | for (auto (p, parts.begin ()); p != parts.end (); ++p) |
411 | p->second->destroy (true); |
414 | p->second->destroy (true); |
412 | |
415 | |
413 | return false; |
416 | return false; |
414 | } |
417 | } |
415 | |
418 | |
… | |
… | |
457 | { |
460 | { |
458 | object_thawer f (filename); |
461 | object_thawer f (filename); |
459 | |
462 | |
460 | f.next (); |
463 | f.next (); |
461 | |
464 | |
462 | // make sure the next - long - step is only done after a tick |
|
|
463 | coroapi::wait_for_tick_begin (); |
|
|
464 | |
|
|
465 | if (!load_archetypes (f)) |
465 | if (!load_archetypes (f)) |
466 | return false; |
466 | return false; |
467 | |
467 | |
468 | warn_archetypes = 1; |
468 | warn_archetypes = 1; |
469 | |
469 | |
470 | empty_archetype = archetype::find ("empty_archetype"); |
470 | empty_archetype = archetype::find ("empty_archetype"); |
471 | if (!empty_archetype) |
471 | if (!empty_archetype) |
472 | return false; |
472 | return false; |
473 | |
|
|
474 | coroapi::cede (); |
|
|
475 | |
473 | |
476 | return true; |
474 | return true; |
477 | } |
475 | } |
478 | |
476 | |
479 | /* |
477 | /* |
… | |
… | |
530 | |
528 | |
531 | return arch_to_object (at); |
529 | return arch_to_object (at); |
532 | } |
530 | } |
533 | |
531 | |
534 | /* |
532 | /* |
535 | * Hash-function used by the arch-hashtable. |
|
|
536 | */ |
|
|
537 | |
|
|
538 | unsigned long |
|
|
539 | hasharch (const char *str, int tablesize) |
|
|
540 | { |
|
|
541 | unsigned long hash = 0; |
|
|
542 | unsigned int i = 0; |
|
|
543 | const char *p; |
|
|
544 | |
|
|
545 | /* use the one-at-a-time hash function, which supposedly is |
|
|
546 | * better than the djb2-like one used by perl5.005, but |
|
|
547 | * certainly is better then the bug used here before. |
|
|
548 | * see http://burtleburtle.net/bob/hash/doobs.html |
|
|
549 | */ |
|
|
550 | for (p = str; i < MAXSTRING && *p; p++, i++) |
|
|
551 | { |
|
|
552 | hash += *p; |
|
|
553 | hash += hash << 10; |
|
|
554 | hash ^= hash >> 6; |
|
|
555 | } |
|
|
556 | |
|
|
557 | hash += hash << 3; |
|
|
558 | hash ^= hash >> 11; |
|
|
559 | hash += hash << 15; |
|
|
560 | |
|
|
561 | return hash % tablesize; |
|
|
562 | } |
|
|
563 | |
|
|
564 | /* |
|
|
565 | * Finds, using the hashtable, which archetype matches the given name. |
533 | * Finds, using the hashtable, which archetype matches the given name. |
566 | * returns a pointer to the found archetype, otherwise NULL. |
534 | * returns a pointer to the found archetype, otherwise NULL. |
567 | */ |
535 | */ |
568 | archetype * |
536 | archetype * |
569 | archetype::find (const char *name) |
537 | archetype::find (const char *name) |
570 | { |
538 | { |
571 | if (!name) |
539 | if (!name) |
572 | return 0; |
540 | return 0; |
573 | |
541 | |
574 | AUTODECL (i, ht.find (name)); |
542 | auto (i, ht.find (name)); |
575 | |
543 | |
576 | if (i == ht.end ()) |
544 | if (i == ht.end ()) |
577 | return 0; |
545 | return 0; |
578 | else |
546 | else |
579 | return i->second; |
547 | return i->second; |