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,2009,2010,2011 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 | * |
6 | * |
6 | * 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 |
7 | * 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 |
8 | * 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 |
9 | * option) any later version. |
10 | * option) any later version. |
10 | * |
11 | * |
11 | * 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, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
15 | * GNU General Public License for more details. |
15 | * |
16 | * |
16 | * 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 |
17 | * 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 |
18 | * <http://www.gnu.org/licenses/>. |
19 | * <http://www.gnu.org/licenses/>. |
19 | * |
20 | * |
20 | * 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> |
21 | */ |
22 | */ |
22 | |
23 | |
23 | #include <global.h> |
24 | #include <global.h> |
24 | #include <stdio.h> |
25 | #include <stdio.h> |
… | |
… | |
29 | faceidx blank_face, empty_face, magicmouth_face; |
30 | faceidx blank_face, empty_face, magicmouth_face; |
30 | |
31 | |
31 | facehash_t facehash; |
32 | facehash_t facehash; |
32 | std::vector<faceinfo> faces; |
33 | std::vector<faceinfo> faces; |
33 | |
34 | |
34 | static std::vector<faceidx> faces_free; |
35 | static std::vector<faceidx> faces_freelist; |
35 | |
36 | |
36 | faceidx face_alloc () |
37 | faceidx face_alloc () |
37 | { |
38 | { |
38 | faceidx idx; |
39 | faceidx idx; |
39 | |
40 | |
40 | if (faces_freelist.empty ()) |
41 | if (!faces_freelist.empty ()) |
41 | { |
42 | { |
42 | idx = faces_free.back (); |
43 | idx = faces_freelist.back (); |
43 | faces_free.pop_back (); |
44 | faces_freelist.pop_back (); |
44 | } |
45 | } |
45 | else |
46 | else |
46 | { |
47 | { |
47 | idx = faces.size (); |
48 | idx = faces.size (); |
48 | |
49 | |
… | |
… | |
53 | } |
54 | } |
54 | |
55 | |
55 | return idx; |
56 | return idx; |
56 | } |
57 | } |
57 | |
58 | |
|
|
59 | void |
58 | faceinfo::unref () |
60 | faceinfo::unref () |
59 | { |
61 | { |
60 | if (--refcnt) |
62 | if (--refcnt) |
61 | return; |
63 | return; |
62 | |
64 | |
… | |
… | |
88 | } |
90 | } |
89 | |
91 | |
90 | facedata * |
92 | facedata * |
91 | faceinfo::data (int faceset) const |
93 | faceinfo::data (int faceset) const |
92 | { |
94 | { |
93 | if (!face [faceset].data.size ()) |
95 | if (!face [faceset].chksum_len) |
94 | faceset = 0; |
96 | faceset = 0; |
95 | |
97 | |
96 | return (facedata *)(face + faceset); |
98 | return (facedata *)(face + faceset); |
97 | } |
99 | } |
98 | |
100 | |