1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * |
5 | * |
6 | * Deliantra is free software: you can redistribute it and/or modify it under |
6 | * Deliantra is free software: you can redistribute it and/or modify it under |
7 | * the terms of the Affero GNU General Public License as published by the |
7 | * the terms of the Affero GNU General Public License as published by the |
8 | * Free Software Foundation, either version 3 of the License, or (at your |
8 | * Free Software Foundation, either version 3 of the License, or (at your |
9 | * option) any later version. |
9 | * option) any later version. |
10 | * |
10 | * |
11 | * This program is distributed in the hope that it will be useful, |
11 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
14 | * GNU General Public License for more details. |
15 | * |
15 | * |
16 | * You should have received a copy of the Affero GNU General Public License |
16 | * You should have received a copy of the Affero GNU General Public License |
17 | * and the GNU General Public License along with this program. If not, see |
17 | * and the GNU General Public License along with this program. If not, see |
18 | * <http://www.gnu.org/licenses/>. |
18 | * <http://www.gnu.org/licenses/>. |
19 | * |
19 | * |
20 | * The authors can be reached via e-mail to <support@deliantra.net> |
20 | * The authors can be reached via e-mail to <support@deliantra.net> |
21 | */ |
21 | */ |
22 | |
22 | |
23 | #include <global.h> |
23 | #include <global.h> |
24 | #include <stdio.h> |
24 | #include <stdio.h> |
25 | |
25 | |
26 | #include "face.h" |
26 | #include "face.h" |
27 | #include "crc.h" |
27 | #include "crc.h" |
28 | |
28 | |
29 | faceidx blank_face, empty_face; |
29 | faceidx blank_face, empty_face, magicmouth_face; |
30 | |
30 | |
31 | facehash_t facehash; |
31 | facehash_t facehash; |
32 | std::vector<faceinfo> faces; |
32 | std::vector<faceinfo> faces; |
33 | |
33 | |
34 | /* the only thing this table is used for now is to |
34 | static std::vector<faceidx> faces_freelist; |
35 | * translate the colorname in the magicmap field of the |
|
|
36 | * face into a numeric index that is then sent to the |
|
|
37 | * client for magic map commands. The order of this table |
|
|
38 | * must match that of the NDI colors in include/newclient.h. |
|
|
39 | */ |
|
|
40 | static const char *const colorname[] = { |
|
|
41 | "black", /* 0 */ |
|
|
42 | "white", /* 1 */ |
|
|
43 | "blue", /* 2 */ |
|
|
44 | "red", /* 3 */ |
|
|
45 | "orange", /* 4 */ |
|
|
46 | "light_blue", /* 5 */ |
|
|
47 | "dark_orange", /* 6 */ |
|
|
48 | "green", /* 7 */ |
|
|
49 | "light_green", /* 8 */ |
|
|
50 | "grey", /* 9 */ |
|
|
51 | "brown", /* 10 */ |
|
|
52 | "yellow", /* 11 */ |
|
|
53 | "khaki" /* 12 */ |
|
|
54 | }; |
|
|
55 | |
35 | |
56 | /* |
36 | faceidx face_alloc () |
57 | * Returns the matching color in the coloralias if found, |
|
|
58 | * 0 otherwise. Note that 0 will actually be black, so there is no |
|
|
59 | * way the calling function can tell if an error occurred or not |
|
|
60 | */ |
|
|
61 | static uint8 |
|
|
62 | find_color (const char *name) |
|
|
63 | { |
37 | { |
64 | uint8 i; |
38 | faceidx idx; |
65 | |
39 | |
66 | for (i = 0; i < sizeof (colorname) / sizeof (*colorname); i++) |
40 | if (!faces_freelist.empty ()) |
67 | if (!strcmp (name, colorname[i])) |
41 | { |
68 | return i; |
42 | idx = faces_freelist.back (); |
|
|
43 | faces_freelist.pop_back (); |
|
|
44 | } |
|
|
45 | else |
|
|
46 | { |
|
|
47 | idx = faces.size (); |
69 | |
48 | |
70 | LOG (llevError, "Unknown color: %s\n", name); |
49 | if (!idx) // skip index 0 |
|
|
50 | idx = 1; |
|
|
51 | |
|
|
52 | faces.resize (idx + 1); |
|
|
53 | } |
|
|
54 | |
71 | return 0; |
55 | return idx; |
|
|
56 | } |
|
|
57 | |
|
|
58 | void |
|
|
59 | faceinfo::unref () |
|
|
60 | { |
|
|
61 | if (--refcnt) |
|
|
62 | return; |
|
|
63 | |
|
|
64 | refcnt = 1; |
|
|
65 | |
72 | } |
66 | } |
73 | |
67 | |
74 | faceidx |
68 | faceidx |
75 | face_find (const char *name, faceidx defidx) |
69 | face_find (const char *name, faceidx defidx) |
76 | { |
70 | { |
… | |
… | |
95 | } |
89 | } |
96 | |
90 | |
97 | facedata * |
91 | facedata * |
98 | faceinfo::data (int faceset) const |
92 | faceinfo::data (int faceset) const |
99 | { |
93 | { |
100 | return (facedata *)&(faceset && !type && data64.data.size () ? data64 : data32); |
94 | if (!face [faceset].chksum_len) |
|
|
95 | faceset = 0; |
|
|
96 | |
|
|
97 | return (facedata *)(face + faceset); |
101 | } |
98 | } |
102 | |
99 | |
103 | facedata * |
100 | facedata * |
104 | face_data (faceidx idx, int faceset) |
101 | face_data (faceidx idx, int faceset) |
105 | { |
102 | { |