Crossfire Server, Trunk  1.75.0
Facesets.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 2020-2021 the Crossfire Development Team
5  *
6  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
7  * welcome to redistribute it under certain conditions. For details, please
8  * see COPYING and LICENSE.
9  *
10  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
11  */
12 
13 #include "Facesets.h"
14 
15 #include "string.h"
16 
17 template<>
18 face_sets *asset_create(const std::string& prefix) {
19  auto fs = static_cast<face_sets *>(calloc(1, sizeof(face_sets)));
20  fs->prefix = strdup_local(prefix.c_str());
21  return fs;
22 }
23 
24 template<>
25 void asset_destroy(face_sets *item) {
26  free(item->prefix);
27  free(item->fullname);
28  free(item->size);
29  free(item->extension);
30  free(item->comment);
31  free(item->faces);
32  free(item);
33 }
34 
36  auto found = std::find_if(m_assets.begin(), m_assets.end(), [&id] (const auto fs) {
37  return fs.second->id == id;
38  });
39  return found == m_assets.end() ? nullptr : found->second;
40 }
41 
42 void Facesets::replace(face_sets *existing, face_sets *update) {
43  auto id = existing->id;
44  free(existing->prefix);
45  free(existing->fullname);
46  free(existing->size);
47  free(existing->extension);
48  free(existing->comment);
49  if (update->allocated) {
50  free(existing->faces);
51  } else {
52  free(update->faces);
53  update->faces = existing->faces;
54  update->allocated = existing->allocated;
55  }
56  *existing = *update;
57  existing->id = id;
58  free(update);
59 }
60 
62  face->id = m_assets.size() - 1;
63 }
Facesets::added
virtual void added(face_sets *face) override
An asset was either referenced (but undefined) or defined.
Definition: Facesets.cpp:61
strdup_local
#define strdup_local
Definition: compat.h:29
Facesets.h
face_sets::allocated
size_t allocated
Allocated size of faces.
Definition: image.h:25
face_sets::id
int id
Definition: image.h:18
face_sets::prefix
char * prefix
Faceset short name, used in pictures names (base, clsc).
Definition: image.h:19
face_sets::extension
char * extension
Supplementary description.
Definition: image.h:23
asset_create
face_sets * asset_create(const std::string &prefix)
Definition: Facesets.cpp:18
face_sets::comment
char * comment
Human-readable comment for this set.
Definition: image.h:24
Facesets::findById
face_sets * findById(int id)
Attempt to find a faceset from its identifier.
Definition: Facesets.cpp:35
face_sets::size
char * size
Human-readable set size.
Definition: image.h:22
asset_destroy
void asset_destroy(face_sets *item)
Definition: Facesets.cpp:25
is_valid_types_gen.found
found
Definition: is_valid_types_gen.py:39
Facesets::replace
virtual void replace(face_sets *existing, face_sets *update) override
Replace an asset by an updated version.
Definition: Facesets.cpp:42
face_sets::fullname
char * fullname
Full faceset name.
Definition: image.h:20
AssetsCollection< face_sets >::m_assets
std::unordered_map< std::string, face_sets * > m_assets
Known assets.
Definition: AssetsCollection.h:190
face_sets
Information about one face set.
Definition: image.h:17
face_sets::faces
face_info * faces
images in this faceset
Definition: image.h:26
face
in that case they will be relative to whatever the PWD of the crossfire server process is You probably shouldn though Notes on Specific and settings file datadir Usually usr share crossfire Contains data that the server does not need to modify while such as the etc A default install will pack the and treasurelist definitions into a single or trs file and the graphics into a face(metadata) and .tar(bitmaps) file