Crossfire Server, Trunk
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<>
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
Definition: Facesets.cpp:61
castle_read.prefix
string prefix
Definition: castle_read.py:31
strdup_local
#define strdup_local
Definition: compat.h:29
Facesets.h
face_sets::allocated
size_t allocated
Definition: image.h:25
face_sets::id
int id
Definition: image.h:18
face_sets::prefix
char * prefix
Definition: image.h:19
face_sets::extension
char * extension
Definition: image.h:23
AssetsCollection< face_sets >::m_assets
std::map< std::string, face_sets * > m_assets
Definition: AssetsCollection.h:190
asset_create
face_sets * asset_create(const std::string &prefix)
Definition: Facesets.cpp:18
face_sets::comment
char * comment
Definition: image.h:24
Facesets::findById
face_sets * findById(int id)
Definition: Facesets.cpp:35
face_sets::size
char * 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
item
Definition: item.py:1
Facesets::replace
virtual void replace(face_sets *existing, face_sets *update) override
Definition: Facesets.cpp:42
face_sets::fullname
char * fullname
Definition: image.h:20
face_sets
Definition: image.h:17
face_sets::faces
face_info * faces
Definition: image.h:26
diamondslots.id
id
Definition: diamondslots.py:53