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.20 by root, Wed Mar 14 00:04:58 2007 UTC vs.
Revision 1.43 by root, Sun Nov 11 05:53:11 2012 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines