Crossfire Server, Trunk
Animations.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 2020 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 "Animations.h"
14 #include "global.h"
15 #include "assets.h"
16 
17 template<>
18 Animations *asset_create(const std::string& name) {
19  Animations *anim = (Animations *)calloc(1, sizeof(Animations));
20  anim->name = add_string(name.c_str());
21  anim->num_animations = 1;
22  return anim;
23 }
24 
25 template<>
27  free_string(item->name);
28  free(item->faces);
29  free(item);
30 }
31 
33  get("###none");
34  m_undefined.clear();
35 }
36 
37 void AllAnimations::replace(Animations *existing, Animations *update) {
38  free(existing->faces);
39  existing->faces = update->faces;
40  update->faces = nullptr;
41  existing->facings = update->facings;
42  existing->num_animations = update->num_animations;
43  existing->has_blank = false;
44  for (uint8_t face = 0; existing->faces && face < existing->num_animations; face++)
45  if (existing->faces[face] == blank_face) {
46  existing->has_blank = true;
47  break;
48  }
49  free_string(update->name);
50  free(update);
51 }
52 
54  anim->num = m_assets.size() - 1;
55  anim->has_blank = false;
56  for (uint8_t face = 0; anim->faces && face < anim->num_animations; face++)
57  if (anim->faces[face] == blank_face) {
58  anim->has_blank = true;
59  break;
60  }
61 }
global.h
asset_create
Animations * asset_create(const std::string &name)
Definition: Animations.cpp:18
AllAnimations::added
virtual void added(Animations *anim) override
Definition: Animations.cpp:53
asset_destroy
void asset_destroy(Animations *item)
Definition: Animations.cpp:26
AllAnimations::replace
virtual void replace(Animations *existing, Animations *update) override
Definition: Animations.cpp:37
blank_face
const Face * blank_face
Definition: image.cpp:36
add_string
sstring add_string(const char *str)
Definition: shstr.cpp:124
AssetsCollection< Animations >::m_undefined
std::set< std::string > m_undefined
Definition: AssetsCollection.h:191
Animations::facings
uint8_t facings
Definition: face.h:28
AssetsCollection< Animations >::get
Animations * get(const std::string &name)
Definition: AssetsCollection.h:89
animate.anim
string anim
Definition: animate.py:20
Animations::num_animations
uint8_t num_animations
Definition: face.h:27
free_string
void free_string(sstring str)
Definition: shstr.cpp:280
Animations::faces
const Face ** faces
Definition: face.h:30
Animations::has_blank
bool has_blank
Definition: face.h:31
item
Definition: item.py:1
Animations
Definition: face.h:25
Animations.h
assets.h
AssetsCollection< Animations >::m_assets
std::unordered_map< std::string, Animations * > m_assets
Definition: AssetsCollection.h:190
AllAnimations::AllAnimations
AllAnimations()
Definition: Animations.cpp:32
Animations::name
sstring name
Definition: face.h:26
give.name
name
Definition: give.py:27