Crossfire Server, Trunk  1.75.0
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
An asset was either referenced (but undefined) or defined.
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
Replace an asset by an updated version.
Definition: Animations.cpp:37
blank_face
const Face * blank_face
Following can just as easily be pointers, but it is easier to keep them like this.
Definition: image.cpp:36
name
Plugin animator file specs[Config] name
Definition: animfiles.txt:4
add_string
sstring add_string(const char *str)
This will add 'str' to the hash table.
Definition: shstr.cpp:124
AssetsCollection< Animations >::m_undefined
std::set< std::string > m_undefined
List of undefined assets.
Definition: AssetsCollection.h:191
Animations::facings
uint8_t facings
How many facings (1,2,4,8).
Definition: face.h:28
AssetsCollection< Animations >::get
Animations * get(const std::string &name)
Get a named asset.
Definition: AssetsCollection.h:89
Animations::num_animations
uint8_t num_animations
How many different faces to animate, size of the faces array.
Definition: face.h:27
free_string
void free_string(sstring str)
This will reduce the refcount, and if it has reached 0, str will be freed.
Definition: shstr.cpp:280
Animations::faces
const Face ** faces
The actual faces for the animation.
Definition: face.h:30
Animations::has_blank
bool has_blank
If this animation contains a blank face or not, used for invisibility.
Definition: face.h:31
Animations
This represents one animation.
Definition: face.h:25
Animations.h
assets.h
Animations::num
uint16_t num
Where we are in the array.
Definition: face.h:29
AssetsCollection< Animations >::m_assets
std::unordered_map< std::string, Animations * > m_assets
Known assets.
Definition: AssetsCollection.h:190
AllAnimations::AllAnimations
AllAnimations()
Definition: Animations.cpp:32
Animations::name
sstring name
Name of the animation sequence.
Definition: face.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