ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/image.C
Revision: 1.22
Committed: Wed Mar 14 20:33:10 2007 UTC (17 years, 2 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.21: +3 -0 lines
Log Message:
- be more robust when reading faces.
- do write face names, not face indices, when saving files.

File Contents

# User Rev Content
1 elmex 1.1 /*
2 root 1.13 * CrossFire, A Multiplayer game
3 pippijn 1.12 *
4     * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
5     * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
6     * Copyright (C) 1992 Frank Tore Johansen
7     *
8     * This program is free software; you can redistribute it and/or modify
9     * it under the terms of the GNU General Public License as published by
10     * the Free Software Foundation; either version 2 of the License, or
11     * (at your option) any later version.
12     *
13     * This program is distributed in the hope that it will be useful,
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16     * GNU General Public License for more details.
17     *
18     * You should have received a copy of the GNU General Public License
19     * along with this program; if not, write to the Free Software
20     * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21     *
22     * The maintainer of this code can be reached at <crossfire@schmorp.de>
23     */
24 elmex 1.1
25    
26     #include <global.h>
27     #include <stdio.h>
28    
29 root 1.19 #include "face.h"
30 root 1.17 #include "crc.h"
31    
32 root 1.19 faceidx blank_face, empty_face;
33 elmex 1.1
34 root 1.19 facehash_t facehash;
35     std::vector<faceinfo> faces;
36 elmex 1.1
37     /* the only thing this table is used for now is to
38     * translate the colorname in the magicmap field of the
39     * face into a numeric index that is then sent to the
40     * client for magic map commands. The order of this table
41     * must match that of the NDI colors in include/newclient.h.
42     */
43     static const char *const colorname[] = {
44 root 1.6 "black", /* 0 */
45     "white", /* 1 */
46     "blue", /* 2 */
47     "red", /* 3 */
48     "orange", /* 4 */
49     "light_blue", /* 5 */
50     "dark_orange", /* 6 */
51     "green", /* 7 */
52     "light_green", /* 8 */
53     "grey", /* 9 */
54     "brown", /* 10 */
55     "yellow", /* 11 */
56     "khaki" /* 12 */
57 elmex 1.1 };
58    
59     /*
60     * Returns the matching color in the coloralias if found,
61     * 0 otherwise. Note that 0 will actually be black, so there is no
62     * way the calling function can tell if an error occurred or not
63     */
64 root 1.6 static uint8
65     find_color (const char *name)
66     {
67 elmex 1.1 uint8 i;
68 root 1.6
69     for (i = 0; i < sizeof (colorname) / sizeof (*colorname); i++)
70     if (!strcmp (name, colorname[i]))
71 elmex 1.1 return i;
72 root 1.19
73 root 1.6 LOG (llevError, "Unknown color: %s\n", name);
74 elmex 1.1 return 0;
75     }
76    
77 root 1.20 faceidx
78     face_find (const char *name, faceidx defidx)
79 elmex 1.1 {
80 root 1.22 if (!name)
81     return defidx;
82    
83 root 1.19 facehash_t::iterator i = facehash.find (name);
84 root 1.6
85 root 1.19 return i == facehash.end ()
86     ? defidx : i->second;
87 elmex 1.1 }
88    
89 root 1.20 faceinfo *
90     face_info (faceidx idx)
91 root 1.6 {
92 root 1.21 assert (0 < (faceidx)-1); // faceidx must be unsigned
93    
94 root 1.20 if (idx >= faces.size ())
95     return 0;
96 elmex 1.1
97 root 1.20 return &faces [idx];
98 elmex 1.1 }
99    
100 root 1.20 facedata *
101     face_data (faceidx idx, int faceset)
102 root 1.6 {
103 root 1.20 if (faceinfo *f = face_info (idx))
104     return &(faceset ? f->data32 : f->data64);
105 elmex 1.1
106 root 1.20 return 0;
107 elmex 1.1 }
108