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