ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/image.C
Revision: 1.31
Committed: Mon Oct 12 14:00:57 2009 UTC (14 years, 7 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-2_82, rel-2_81
Changes since 1.30: +7 -6 lines
Log Message:
clarify license

File Contents

# User Rev Content
1 elmex 1.1 /*
2 root 1.29 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 pippijn 1.12 *
4 root 1.30 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 root 1.24 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6     * Copyright (©) 1992,2007 Frank Tore Johansen
7 pippijn 1.12 *
8 root 1.31 * Deliantra is free software: you can redistribute it and/or modify it under
9     * the terms of the Affero GNU General Public License as published by the
10     * Free Software Foundation, either version 3 of the License, or (at your
11     * option) any later version.
12 pippijn 1.12 *
13 root 1.26 * 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 pippijn 1.12 *
18 root 1.31 * You should have received a copy of the Affero GNU General Public License
19     * and the GNU General Public License along with this program. If not, see
20     * <http://www.gnu.org/licenses/>.
21 root 1.24 *
22 root 1.29 * The authors can be reached via e-mail to <support@deliantra.net>
23 pippijn 1.12 */
24 elmex 1.1
25     #include <global.h>
26     #include <stdio.h>
27    
28 root 1.19 #include "face.h"
29 root 1.17 #include "crc.h"
30    
31 root 1.19 faceidx blank_face, empty_face;
32 elmex 1.1
33 root 1.19 facehash_t facehash;
34     std::vector<faceinfo> faces;
35 elmex 1.1
36     /* the only thing this table is used for now is to
37     * translate the colorname in the magicmap field of the
38     * face into a numeric index that is then sent to the
39     * client for magic map commands. The order of this table
40     * must match that of the NDI colors in include/newclient.h.
41     */
42     static const char *const colorname[] = {
43 root 1.6 "black", /* 0 */
44     "white", /* 1 */
45     "blue", /* 2 */
46     "red", /* 3 */
47     "orange", /* 4 */
48     "light_blue", /* 5 */
49     "dark_orange", /* 6 */
50     "green", /* 7 */
51     "light_green", /* 8 */
52     "grey", /* 9 */
53     "brown", /* 10 */
54     "yellow", /* 11 */
55     "khaki" /* 12 */
56 elmex 1.1 };
57    
58     /*
59     * Returns the matching color in the coloralias if found,
60     * 0 otherwise. Note that 0 will actually be black, so there is no
61     * way the calling function can tell if an error occurred or not
62     */
63 root 1.6 static uint8
64     find_color (const char *name)
65     {
66 elmex 1.1 uint8 i;
67 root 1.6
68     for (i = 0; i < sizeof (colorname) / sizeof (*colorname); i++)
69     if (!strcmp (name, colorname[i]))
70 elmex 1.1 return i;
71 root 1.19
72 root 1.6 LOG (llevError, "Unknown color: %s\n", name);
73 elmex 1.1 return 0;
74     }
75    
76 root 1.20 faceidx
77     face_find (const char *name, faceidx defidx)
78 elmex 1.1 {
79 root 1.22 if (!name)
80     return defidx;
81    
82 root 1.19 facehash_t::iterator i = facehash.find (name);
83 root 1.6
84 root 1.19 return i == facehash.end ()
85     ? defidx : i->second;
86 elmex 1.1 }
87    
88 root 1.20 faceinfo *
89     face_info (faceidx idx)
90 root 1.6 {
91 root 1.21 assert (0 < (faceidx)-1); // faceidx must be unsigned
92    
93 root 1.20 if (idx >= faces.size ())
94     return 0;
95 elmex 1.1
96 root 1.20 return &faces [idx];
97 elmex 1.1 }
98    
99 root 1.20 facedata *
100 root 1.28 faceinfo::data (int faceset) const
101     {
102     return (facedata *)&(faceset && !type && data64.data.size () ? data64 : data32);
103     }
104    
105     facedata *
106 root 1.20 face_data (faceidx idx, int faceset)
107 root 1.6 {
108 root 1.20 if (faceinfo *f = face_info (idx))
109 root 1.28 return f->data (faceset);
110 elmex 1.1
111 root 1.20 return 0;
112 elmex 1.1 }
113