1 |
elmex |
1.1 |
/* |
2 |
root |
1.29 |
* This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 |
root |
1.41 |
* |
4 |
root |
1.45 |
* Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team |
5 |
root |
1.44 |
* Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
6 |
root |
1.41 |
* |
7 |
root |
1.31 |
* Deliantra is free software: you can redistribute it and/or modify it under |
8 |
|
|
* the terms of the Affero GNU General Public License as published by the |
9 |
|
|
* Free Software Foundation, either version 3 of the License, or (at your |
10 |
|
|
* option) any later version. |
11 |
root |
1.41 |
* |
12 |
root |
1.26 |
* This program is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
|
* GNU General Public License for more details. |
16 |
root |
1.41 |
* |
17 |
root |
1.31 |
* You should have received a copy of the Affero GNU General Public License |
18 |
|
|
* and the GNU General Public License along with this program. If not, see |
19 |
|
|
* <http://www.gnu.org/licenses/>. |
20 |
root |
1.41 |
* |
21 |
root |
1.29 |
* The authors can be reached via e-mail to <support@deliantra.net> |
22 |
pippijn |
1.12 |
*/ |
23 |
elmex |
1.1 |
|
24 |
|
|
#include <global.h> |
25 |
|
|
#include <stdio.h> |
26 |
|
|
|
27 |
root |
1.19 |
#include "face.h" |
28 |
root |
1.17 |
#include "crc.h" |
29 |
|
|
|
30 |
root |
1.35 |
faceidx blank_face, empty_face, magicmouth_face; |
31 |
elmex |
1.1 |
|
32 |
root |
1.19 |
facehash_t facehash; |
33 |
|
|
std::vector<faceinfo> faces; |
34 |
elmex |
1.1 |
|
35 |
root |
1.40 |
static std::vector<faceidx> faces_freelist; |
36 |
root |
1.38 |
|
37 |
|
|
faceidx face_alloc () |
38 |
|
|
{ |
39 |
|
|
faceidx idx; |
40 |
|
|
|
41 |
root |
1.40 |
if (!faces_freelist.empty ()) |
42 |
root |
1.38 |
{ |
43 |
root |
1.40 |
idx = faces_freelist.back (); |
44 |
|
|
faces_freelist.pop_back (); |
45 |
root |
1.38 |
} |
46 |
|
|
else |
47 |
|
|
{ |
48 |
|
|
idx = faces.size (); |
49 |
|
|
|
50 |
|
|
if (!idx) // skip index 0 |
51 |
|
|
idx = 1; |
52 |
|
|
|
53 |
|
|
faces.resize (idx + 1); |
54 |
|
|
} |
55 |
|
|
|
56 |
|
|
return idx; |
57 |
|
|
} |
58 |
|
|
|
59 |
root |
1.40 |
void |
60 |
root |
1.38 |
faceinfo::unref () |
61 |
|
|
{ |
62 |
|
|
if (--refcnt) |
63 |
|
|
return; |
64 |
|
|
|
65 |
|
|
refcnt = 1; |
66 |
|
|
|
67 |
|
|
} |
68 |
|
|
|
69 |
root |
1.20 |
faceidx |
70 |
|
|
face_find (const char *name, faceidx defidx) |
71 |
elmex |
1.1 |
{ |
72 |
root |
1.22 |
if (!name) |
73 |
|
|
return defidx; |
74 |
|
|
|
75 |
root |
1.19 |
facehash_t::iterator i = facehash.find (name); |
76 |
root |
1.6 |
|
77 |
root |
1.19 |
return i == facehash.end () |
78 |
|
|
? defidx : i->second; |
79 |
elmex |
1.1 |
} |
80 |
|
|
|
81 |
root |
1.20 |
faceinfo * |
82 |
|
|
face_info (faceidx idx) |
83 |
root |
1.6 |
{ |
84 |
root |
1.21 |
assert (0 < (faceidx)-1); // faceidx must be unsigned |
85 |
|
|
|
86 |
root |
1.20 |
if (idx >= faces.size ()) |
87 |
|
|
return 0; |
88 |
elmex |
1.1 |
|
89 |
root |
1.20 |
return &faces [idx]; |
90 |
elmex |
1.1 |
} |
91 |
|
|
|
92 |
root |
1.20 |
facedata * |
93 |
root |
1.28 |
faceinfo::data (int faceset) const |
94 |
|
|
{ |
95 |
root |
1.43 |
if (!face [faceset].chksum_len) |
96 |
root |
1.36 |
faceset = 0; |
97 |
|
|
|
98 |
|
|
return (facedata *)(face + faceset); |
99 |
root |
1.28 |
} |
100 |
|
|
|
101 |
|
|
facedata * |
102 |
root |
1.20 |
face_data (faceidx idx, int faceset) |
103 |
root |
1.6 |
{ |
104 |
root |
1.20 |
if (faceinfo *f = face_info (idx)) |
105 |
root |
1.28 |
return f->data (faceset); |
106 |
elmex |
1.1 |
|
107 |
root |
1.20 |
return 0; |
108 |
elmex |
1.1 |
} |
109 |
|
|
|