ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/image.C
(Generate patch)

Comparing deliantra/server/common/image.C (file contents):
Revision 1.29 by root, Thu Nov 8 19:43:23 2007 UTC vs.
Revision 1.45 by root, Sat Nov 17 23:40:00 2018 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines