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.24 by root, Mon May 28 21:21:40 2007 UTC vs.
Revision 1.39 by root, Tue Jan 3 11:25:30 2012 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines