Crossfire Server  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 }
face_info * faces
images in this faceset
Definition: image.h:26
#define strdup_local
Definition: compat.h:29
virtual void added(face_sets *face) override
An asset was either referenced (but undefined) or defined.
Definition: Facesets.cpp:61
int id
Definition: image.h:18
std::unordered_map< std::string, face_sets *> m_assets
Known assets.
size_t allocated
Allocated size of faces.
Definition: image.h:25
face_sets * findById(int id)
Attempt to find a faceset from its identifier.
Definition: Facesets.cpp:35
char * prefix
Faceset short name, used in pictures names (base, clsc).
Definition: image.h:19
char * extension
Supplementary description.
Definition: image.h:23
char * size
Human-readable set size.
Definition: image.h:22
virtual void replace(face_sets *existing, face_sets *update) override
Replace an asset by an updated version.
Definition: Facesets.cpp:42
char * comment
Human-readable comment for this set.
Definition: image.h:24
face_sets * asset_create(const std::string &prefix)
Definition: Facesets.cpp:18
void asset_destroy(face_sets *item)
Definition: Facesets.cpp:25
char * fullname
Full faceset name.
Definition: image.h:20
Information about one face set.
Definition: image.h:17