--- deliantra/server/include/face.h 2007/01/19 17:50:11 1.8 +++ deliantra/server/include/face.h 2012/11/09 00:11:49 1.41 @@ -1,52 +1,132 @@ /* - * CrossFire, A Multiplayer game for X-windows - * - * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team - * Copyright (C) 1994 Mark Wedel - * Copyright (C) 1992 Frank Tore Johansen - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * + * This file is part of Deliantra, the Roguelike Realtime MMORPG. + * + * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * + * Deliantra is free software: you can redistribute it and/or modify it under + * the terms of the Affero GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * - * The author can be reached via e-mail to mark@pyramid.com + * You should have received a copy of the Affero GNU General Public License + * and the GNU General Public License along with this program. If not, see + * . + * + * The authors can be reached via e-mail to */ +#ifndef FACE_H__ +#define FACE_H__ + +#include +#include + +#define CHKSUM_MAXLEN 15 +#define MAX_FACES 65535 // we reserve face #65535 + +typedef uint16 faceidx; + +extern faceidx blank_face, empty_face, magicmouth_face; + +struct facedata +{ + refcnt_buf data; + uint8 chksum[CHKSUM_MAXLEN]; + uint8 chksum_len; + + facedata () + : chksum_len (0) + { } +}; + /* New face structure - this enforces the notion that data is face by * face only - you can not change the color of an item - you need to instead * create a new face with that color. */ -struct facetile +struct faceinfo { - uint16 number; /* This is the image id. It should be the */ - /* same value as its position in the array */ + faceinfo () + : number (0), smooth (0), type (0), smoothlevel (0), visibility (0), magicmap (0), refcnt (1), meta_hv (0) + { + } + shstr name; + HV *meta_hv; /* note, no destructor of copy constructor, must never be freed, but can be moved aorund */ + facedata face[3]; // indexed by faceset, 0 == 32 bit or generic, 1 == 64, 2 == text + faceidx number; /* This is the image id. It should be the */ + /* same value as its position in the array */ + faceidx smooth; /* the smooth face for this face, or 0 */ + uint8 type; // 0 normal face, otherwise other resource + uint8 smoothlevel; // smoothlevel is per-face in 2.x servers uint8 visibility; uint8 magicmap; /* Color to show this in magic map */ + + facedata *data (int faceset) const; + + int refcnt; // reference count - 1 + void ref () { ++refcnt; } + void unref (); }; +inline void +object_freezer::put (const keyword_string k, faceinfo *v) +{ + if (expect_true (v)) + put (k, v->name); + else + put (k); +} + +typedef std::tr1::unordered_map > > facehash_t; + +extern facehash_t facehash; +extern std::vector faces; + +/* This returns an the face number of face 'name'. Number is constant + * during an invocation, but not necessarily between versions (this + * is because the faces are arranged in alphabetical order, so + * if a face is removed or added, all faces after that will now + * have a different number. + * + * If a face is not found, then defidx is returned. This can be useful + * if you want some default face used, or can be set to negative so that + * it will be known that the face could not be found. + */ +faceidx face_find (const char *name, faceidx defidx = 0); +faceidx face_alloc (); +faceinfo *face_info (faceidx idx); +facedata *face_data (faceidx idx, int faceset); + struct MapLook { - facetile *face; + faceinfo *face; uint8 flags; }; +typedef uint16 animidx; + struct animation { + faceidx *faces; /* The different animations */ + int num_animations; /* How many different faces to animate */ + sint8 facings; /* How many facings (1,2,4,8) */ + animidx number; shstr name; /* Name of the animation sequence */ - uint8 num_animations; /* How many different faces to animate */ - uint8 facings; /* How many facings (1,2,4,8) */ - uint16 *faces; /* The different animations */ - uint16 num; /* Where we are in the array */ + + static animation &create (const char *name, uint8 frames, uint8 facings = 1); + static animation &find (const char *name); + + void resize (int new_size); }; +typedef std::tr1::unordered_map > > animhash_t; + +extern std::vector animations; + +#endif +