Changeset 455

Show
Ignore:
Timestamp:
08/06/07 18:20:38 (1 year ago)
Author:
takkaria
Message:

Move the quark package out to z-quark.c, making it expand as necessary in the process. Also, use a quark_t type to store the type, to make things a bit clearer, and make this a sane type (size_t rather than s16b). (Matthew Jones)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/Makefile.src

    r400 r455  
    1414HEADERS = $(HDRS) $(INCS) 
    1515 
    16 ZFILES = z-file.o z-form.o z-rand.o z-term.o z-type.o z-util.o z-virt.o 
     16ZFILES = z-file.o z-form.o z-quark.o z-rand.o z-term.o z-type.o z-util.o z-virt.o 
    1717MAINFILES = main.o maid-x11.o main-crb.o main-gcu.o main-gtk.o \ 
    1818        main-ros.o main-sdl.o main-win.o main-x11.o main-xaw.o snd-sdl.o 
  • trunk/src/angband.h

    r96 r455  
    2626#include "z-rand.h" 
    2727#include "z-term.h" 
     28#include "z-quark.h" 
    2829 
    2930/* 
  • trunk/src/defines.h

    r453 r455  
    209209 */ 
    210210#define MACRO_MAX       512 
    211  
    212 /* 
    213  * OPTION: Maximum number of "quarks" (see "util.c") 
    214  * Default: assume at most 512 different inscriptions are used 
    215  */ 
    216 #define QUARK_MAX       512 
    217211 
    218212/* 
  • trunk/src/externs.h

    r453 r455  
    636636extern void bell(cptr reason); 
    637637extern void sound(int val); 
    638 extern s16b quark_add(cptr str); 
    639 extern cptr quark_str(s16b i); 
    640 extern errr quarks_init(void); 
    641 extern errr quarks_free(void); 
    642638extern bool check_for_inscrip(const object_type *o_ptr, const char *inscrip); 
    643639extern s16b message_num(void); 
  • trunk/src/object1.c

    r399 r455  
    15691569 
    15701570 
    1571         /* Use standard inscription */ 
    1572         if (o_ptr->note) 
    1573         { 
    1574                 u = quark_str(o_ptr->note); 
    1575         } 
    1576  
    1577         /* Use nothing */ 
    1578         else 
    1579         { 
    1580                 u = NULL; 
    1581         } 
     1571        /* Get inscription */ 
     1572        u = (o_ptr->note ? quark_str(o_ptr->note) : NULL); 
    15821573 
    15831574 
  • trunk/src/types.h

    r448 r455  
    503503        byte marked;            /* Object is marked */ 
    504504 
    505         u16b note;                    /* Inscription index */ 
     505        quark_t note;                 /* Inscription index */ 
    506506 
    507507        s16b next_o_idx;        /* Next object in stack (if any) */ 
  • trunk/src/util.c

    r399 r455  
    13711371} 
    13721372 
    1373  
    1374  
    1375  
    1376 /* 
    1377  * The "quark" package 
    1378  * 
    1379  * This package is used to reduce the memory usage of object inscriptions. 
    1380  * 
    1381  * We use dynamic string allocation because otherwise it is necessary to 
    1382  * pre-guess the amount of quark activity.  We limit the total number of 
    1383  * quarks, but this is much easier to "expand" as needed.  XXX XXX XXX 
    1384  * 
    1385  * Two objects with the same inscription will have the same "quark" index. 
    1386  * 
    1387  * Some code uses "zero" to indicate the non-existance of a quark. 
    1388  * 
    1389  * Note that "quark zero" is NULL and should never be "dereferenced". 
    1390  * 
    1391  * ToDo: Add reference counting for quarks, so that unused quarks can 
    1392  * be overwritten. 
    1393  * 
    1394  * ToDo: Automatically resize the array if necessary. 
    1395  */ 
    1396  
    1397  
    1398 /* 
    1399  * The number of quarks (first quark is NULL) 
    1400  */ 
    1401 static s16b quark__num = 1; 
    1402  
    1403  
    1404 /* 
    1405  * The array[QUARK_MAX] of pointers to the quarks 
    1406  */ 
    1407 static char **quark__str; 
    1408  
    1409  
    1410 /* 
    1411  * Add a new "quark" to the set of quarks. 
    1412  */ 
    1413 s16b quark_add(cptr str) 
    1414 { 
    1415         int i; 
    1416  
    1417         /* Look for an existing quark */ 
    1418         for (i = 1; i < quark__num; i++) 
    1419         { 
    1420                 /* Check for equality */ 
    1421                 if (streq(quark__str[i], str)) return (i); 
    1422         } 
    1423  
    1424         /* Hack -- Require room XXX XXX XXX */ 
    1425         if (quark__num == QUARK_MAX) return (0); 
    1426  
    1427         /* New quark */ 
    1428         i = quark__num++; 
    1429  
    1430         /* Add a new quark */ 
    1431         quark__str[i] = string_make(str); 
    1432  
    1433         /* Return the index */ 
    1434         return (i); 
    1435 } 
    1436  
    1437  
    1438 /* 
    1439  * This function looks up a quark 
    1440  */ 
    1441 cptr quark_str(s16b i) 
    1442 { 
    1443         cptr q; 
    1444  
    1445         /* Verify */ 
    1446         if ((i < 0) || (i >= quark__num)) i = 0; 
    1447  
    1448         /* Get the quark */ 
    1449         q = quark__str[i]; 
    1450  
    1451         /* Return the quark */ 
    1452         return (q); 
    1453 } 
    1454  
    1455  
    1456 /* 
    1457  * Initialize the "quark" package 
    1458  */ 
    1459 errr quarks_init(void) 
    1460 { 
    1461         /* Quark variables */ 
    1462         quark__str = C_ZNEW(QUARK_MAX, const char *); 
    1463  
    1464         /* Success */ 
    1465         return (0); 
    1466 } 
    1467  
    1468  
    1469 /* 
    1470  * Free the "quark" package 
    1471  */ 
    1472 errr quarks_free(void) 
    1473 { 
    1474         int i; 
    1475  
    1476         /* Free the "quarks" */ 
    1477         for (i = 1; i < quark__num; i++) 
    1478                 string_free(quark__str[i]); 
    1479  
    1480         /* Free the list of "quarks" */ 
    1481         FREE(quark__str); 
    1482  
    1483         /* Success */ 
    1484         return (0); 
    1485 } 
    14861373 
    14871374/*