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 (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
|
|
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
|
|
7 | * |
6 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
7 | * 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 |
8 | * 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 |
9 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
10 | * option) any later version. |
12 | * |
11 | * |
13 | * This program is distributed in the hope that it will be useful, |
12 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
15 | * GNU General Public License for more details. |
17 | * |
16 | * |
18 | * You should have received a copy of the Affero GNU General Public License |
17 | * 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 |
18 | * and the GNU General Public License along with this program. If not, see |
20 | * <http://www.gnu.org/licenses/>. |
19 | * <http://www.gnu.org/licenses/>. |
21 | * |
20 | * |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
22 | */ |
24 | |
23 | |
25 | #include <global.h> |
24 | #include <global.h> |
26 | #include <stdio.h> |
25 | #include <stdio.h> |
27 | |
26 | |
28 | #include "face.h" |
27 | #include "face.h" |
29 | #include "crc.h" |
28 | #include "crc.h" |
30 | |
29 | |
31 | faceidx blank_face, empty_face; |
30 | faceidx blank_face, empty_face, magicmouth_face; |
32 | |
31 | |
33 | facehash_t facehash; |
32 | facehash_t facehash; |
34 | std::vector<faceinfo> faces; |
33 | std::vector<faceinfo> faces; |
35 | |
34 | |
36 | /* the only thing this table is used for now is to |
35 | static std::vector<faceidx> faces_freelist; |
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 | "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 | }; |
|
|
57 | |
36 | |
58 | /* |
37 | faceidx face_alloc () |
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 | static uint8 |
|
|
64 | find_color (const char *name) |
|
|
65 | { |
38 | { |
66 | uint8 i; |
39 | faceidx idx; |
67 | |
40 | |
68 | for (i = 0; i < sizeof (colorname) / sizeof (*colorname); i++) |
41 | if (!faces_freelist.empty ()) |
69 | if (!strcmp (name, colorname[i])) |
42 | { |
70 | return i; |
43 | idx = faces_freelist.back (); |
|
|
44 | faces_freelist.pop_back (); |
|
|
45 | } |
|
|
46 | else |
|
|
47 | { |
|
|
48 | idx = faces.size (); |
71 | |
49 | |
72 | LOG (llevError, "Unknown color: %s\n", name); |
50 | if (!idx) // skip index 0 |
|
|
51 | idx = 1; |
|
|
52 | |
|
|
53 | faces.resize (idx + 1); |
|
|
54 | } |
|
|
55 | |
73 | return 0; |
56 | return idx; |
|
|
57 | } |
|
|
58 | |
|
|
59 | void |
|
|
60 | faceinfo::unref () |
|
|
61 | { |
|
|
62 | if (--refcnt) |
|
|
63 | return; |
|
|
64 | |
|
|
65 | refcnt = 1; |
|
|
66 | |
74 | } |
67 | } |
75 | |
68 | |
76 | faceidx |
69 | faceidx |
77 | face_find (const char *name, faceidx defidx) |
70 | face_find (const char *name, faceidx defidx) |
78 | { |
71 | { |
… | |
… | |
97 | } |
90 | } |
98 | |
91 | |
99 | facedata * |
92 | facedata * |
100 | faceinfo::data (int faceset) const |
93 | faceinfo::data (int faceset) const |
101 | { |
94 | { |
102 | return (facedata *)&(faceset && !type && data64.data.size () ? data64 : data32); |
95 | if (!face [faceset].chksum_len) |
|
|
96 | faceset = 0; |
|
|
97 | |
|
|
98 | return (facedata *)(face + faceset); |
103 | } |
99 | } |
104 | |
100 | |
105 | facedata * |
101 | facedata * |
106 | face_data (faceidx idx, int faceset) |
102 | face_data (faceidx idx, int faceset) |
107 | { |
103 | { |