… | |
… | |
22 | */ |
22 | */ |
23 | |
23 | |
24 | #include <cassert> |
24 | #include <cassert> |
25 | |
25 | |
26 | #include <global.h> |
26 | #include <global.h> |
27 | #include <funcpoint.h> |
|
|
28 | #include <loader.h> |
27 | #include <loader.h> |
29 | |
28 | |
30 | #include <tr1/functional> |
29 | #include <tr1/functional> |
31 | #include <tr1/unordered_map> |
30 | #include <tr1/unordered_map> |
32 | |
31 | |
… | |
… | |
134 | * - name: The name we're searching for (ex: "writing pen"); |
133 | * - name: The name we're searching for (ex: "writing pen"); |
135 | * Return value: |
134 | * Return value: |
136 | * - a corresponding object if found; a singularity object if not found. |
135 | * - a corresponding object if found; a singularity object if not found. |
137 | * Note by MSW - it appears that it takes the full name and keeps |
136 | * Note by MSW - it appears that it takes the full name and keeps |
138 | * shortening it until it finds a match. I re-wrote this so that it |
137 | * shortening it until it finds a match. I re-wrote this so that it |
139 | * doesn't malloc it each time - not that this function is used much, |
138 | * doesn't allocate it each time - not that this function is used much, |
140 | * but it otherwise had a big memory leak. |
139 | * but it otherwise had a big memory leak. |
141 | */ |
140 | */ |
142 | object * |
141 | object * |
143 | get_archetype_by_object_name (const char *name) |
142 | get_archetype_by_object_name (const char *name) |
144 | { |
143 | { |
… | |
… | |
514 | else |
513 | else |
515 | { |
514 | { |
516 | LOG (llevDebug, "garbage collect arch %s", at->debug_desc ()); |
515 | LOG (llevDebug, "garbage collect arch %s", at->debug_desc ()); |
517 | assert (at->arch == at); // verify that refcnt == 1 is truely valid |
516 | assert (at->arch == at); // verify that refcnt == 1 is truely valid |
518 | allarch.erase (idx); |
517 | allarch.erase (idx); |
|
|
518 | |
|
|
519 | // break chain |
|
|
520 | for (object *op = at->head_ (); op; ) |
|
|
521 | { |
|
|
522 | object *next = op->more; |
|
|
523 | op->head = 0; |
|
|
524 | op->more = 0; |
|
|
525 | op = next; |
|
|
526 | } |
|
|
527 | |
|
|
528 | at->destroy (); |
519 | at->arch = 0; |
529 | at->arch = 0; |
520 | at->more = 0; |
|
|
521 | at->destroy (); |
|
|
522 | } |
530 | } |
523 | } |
531 | } |
524 | while (--cnt); |
532 | while (--cnt); |
525 | } |
533 | } |
526 | |
534 | |
… | |
… | |
586 | return create_singularity (name); |
594 | return create_singularity (name); |
587 | |
595 | |
588 | return arch_to_object (at); |
596 | return arch_to_object (at); |
589 | } |
597 | } |
590 | |
598 | |
|
|
599 | object * |
|
|
600 | archetype::get (const char *name) |
|
|
601 | { |
|
|
602 | return get_archetype (name); |
|
|
603 | } |
|
|
604 | |
591 | /* |
605 | /* |
592 | * Returns the first archetype using the given type. |
606 | * Returns the first archetype using the given type. |
593 | * Used in treasure-generation. |
607 | * Used in treasure-generation. |
594 | */ |
608 | */ |
595 | archetype * |
609 | archetype * |