Crossfire Server, Trunk  R22047
assets.cpp File Reference
#include <dirent.h>
#include <sys/stat.h>
#include "autoconf.h"
#include "global.h"
#include "compat.h"
#include "assets.h"
#include "AssetsManager.h"
#include "AssetCollector.h"
#include "TreasureLoader.h"
#include "ArchetypeLoader.h"
#include "PngLoader.h"
#include "FacesetLoader.h"
#include "FaceLoader.h"
#include "WrapperLoader.h"
#include "MessageLoader.h"
#include "Faces.h"
#include <string.h>
#include <vector>
#include <string>
#include <set>
#include <algorithm>
#include <map>
#include <memory>
#include "AssetWriter.h"
#include "TreasureWriter.h"
#include "FaceWriter.h"
#include "AnimationWriter.h"
#include "ArchetypeWriter.h"
#include "MessageWriter.h"
#include "image.h"
#include "FacesetWriter.h"
#include "ArtifactWriter.h"
#include "FormulaeWriter.h"
#include "microtar.h"
#include "TarLoader.h"
+ Include dependency graph for assets.cpp:

Go to the source code of this file.

Macros

#define MAX_PACK   100
 

Functions

static void add_to_tar (mtar_t *tar, void *data, size_t len, const char *filename)
 
void animations_for_each (anim_op op)
 
void archetypes_for_each (arch_op op)
 
void assets_collect (const char *datadir)
 
size_t assets_dump_undefined ()
 
void assets_end_load ()
 
void assets_finish_archetypes_for_play ()
 
void assets_free ()
 
void assets_init ()
 
size_t assets_number_of_animations ()
 
size_t assets_number_of_archetypes ()
 
size_t assets_number_of_treasurelists ()
 
size_t assets_number_of_treasures ()
 
void assets_pack (const char *what, const char *filename)
 
static void build_filename (const char *name, const char *prefix, char *dest, size_t max)
 
static void check_generators (void)
 
static void check_spells (void)
 
void check_summoned (void)
 
static void check_treasurelist (treasure *t, const treasurelist *tl)
 
template<class T >
static void do_pack (AssetWriter< T > *writer, AssetsCollection< T > *assets, StringBuffer *buf)
 
void faces_for_each (face_op op)
 
void facesets_for_each (faceset_op op)
 
Animationsfind_animation (const char *name)
 
archetype * find_archetype (const char *name)
 
const Facefind_face (const char *name)
 
face_setsfind_faceset (int id)
 
treasurelistfind_treasurelist (const char *name)
 
int get_bitmap_checksum ()
 
const Faceget_face_by_id (uint16_t id)
 
size_t get_faces_count ()
 
const GeneralMessageget_message_from_identifier (const char *identifier)
 
archetype * get_next_archetype (archetype *current)
 
GeneralMessageget_random_message ()
 
AssetsManagergetManager ()
 
static void pack_artifacts (StringBuffer *buf)
 
static void pack_formulae (StringBuffer *buf)
 
static void pack_images (mtar_t *tar)
 
long recipe_find_ingredient_cost (const char *name)
 
Animationstry_find_animation (const char *name)
 
archetype * try_find_archetype (const char *name)
 
const Facetry_find_face (const char *name, const Face *error)
 

Variables

static AssetsManagermanager = nullptr
 
size_t nroftreasures = 0
 

Detailed Description

Handles asset collection.

Definition in file assets.cpp.

Macro Definition Documentation

◆ MAX_PACK

#define MAX_PACK   100

Referenced by assets_pack().

Function Documentation

◆ add_to_tar()

static void add_to_tar ( mtar_t tar,
void *  data,
size_t  len,
const char *  filename 
)
static

Add a file to a .tar file.

Parameters
tarwhere to add the file.
datafile content.
lenlength of data.
filenamename in the .tar file.

Definition at line 388 of file assets.cpp.

References fatal(), llevError, LOG(), mtar_header_t::mode, MTAR_ESUCCESS, MTAR_TREG, mtar_write_data(), mtar_write_header(), mtar_header_t::mtime, mtar_header_t::name, SEE_LAST_ERROR, mtar_header_t::size, and mtar_header_t::type.

Referenced by assets_pack(), and pack_images().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ animations_for_each()

void animations_for_each ( anim_op  op)

Definition at line 273 of file assets.cpp.

References AssetsManager::animations(), and AssetsCollection< T, Key >::each().

Referenced by dump_animations().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ archetypes_for_each()

void archetypes_for_each ( arch_op  op)

Definition at line 300 of file assets.cpp.

References AssetsManager::archetypes(), and AssetsCollection< T, Key >::each().

Referenced by build_class_list_reply(), build_race_list_reply(), cast_create_food(), init_dynamic(), init_gods(), init_mon_info(), init_skills(), send_map_info(), and spellpath_msg().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ assets_collect()

void assets_collect ( const char *  datadir)

Collect all assets from the specified directory and all its subdirectories.

Parameters
datadirdirectory to search from.

Definition at line 114 of file assets.cpp.

References AssetCollector::addLoader(), AssetsManager::animations(), AssetsManager::archetypes(), Settings::archetypes_tracker, AssetCollector::collect(), AssetsManager::faces(), Settings::hooks, Settings::hooks_count, Settings::hooks_filename, init_artifacts(), init_attackmess(), init_formulae(), llevInfo, LOG(), AssetsManager::messages(), settings, ArchetypeLoader::setTracker(), and AssetsManager::treasures().

Referenced by cctk_init_std_archetypes(), and init_library().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ assets_dump_undefined()

size_t assets_dump_undefined ( )

Dump and reset referenced but undefined assets.

Returns
total number of referenced but not defined assets.

Definition at line 202 of file assets.cpp.

References AssetsManager::dumpUndefined().

Referenced by init_library().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ assets_end_load()

void assets_end_load ( )

Called after collect is complete, to check various things.

Definition at line 209 of file assets.cpp.

References check_generators(), check_spells(), check_summoned(), AssetsCollection< T, Key >::each(), and AssetsManager::treasures().

Referenced by init_library().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ assets_finish_archetypes_for_play()

void assets_finish_archetypes_for_play ( )

Definition at line 512 of file assets.cpp.

References AssetsManager::archetypes(), and AssetsCollection< T, Key >::each().

Referenced by init_beforeplay().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ assets_free()

void assets_free ( )

Free all assets-related memory.

Definition at line 74 of file assets.cpp.

References manager.

Referenced by free_globals().

+ Here is the caller graph for this function:

◆ assets_init()

void assets_init ( )

Init assets-related variables.

Definition at line 67 of file assets.cpp.

Referenced by cctk_init_std_archetypes(), and init_library().

+ Here is the caller graph for this function:

◆ assets_number_of_animations()

size_t assets_number_of_animations ( )

Definition at line 261 of file assets.cpp.

References AssetsManager::animations(), and AssetsCollection< T, Key >::count().

Referenced by malloc_info().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ assets_number_of_archetypes()

size_t assets_number_of_archetypes ( )

Definition at line 245 of file assets.cpp.

References AssetsManager::archetypes(), and AssetsCollection< T, Key >::count().

Referenced by malloc_info().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ assets_number_of_treasurelists()

size_t assets_number_of_treasurelists ( )

Definition at line 241 of file assets.cpp.

References AssetsCollection< T, Key >::count(), and AssetsManager::treasures().

Referenced by malloc_info().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ assets_number_of_treasures()

size_t assets_number_of_treasures ( )

Definition at line 238 of file assets.cpp.

References nroftreasures.

Referenced by malloc_info().

+ Here is the caller graph for this function:

◆ assets_pack()

void assets_pack ( const char *  type,
const char *  filename 
)

Pack the specified assets in a file.

Parameters
typeassets type, see actual implementation.
filenamedestination file.

Definition at line 424 of file assets.cpp.

References add_to_tar(), AssetsManager::animations(), AssetsManager::archetypes(), buf, do_pack(), AssetsManager::faces(), AssetsManager::facesets(), fatal(), llevError, LOG(), MAX_PACK, AssetsManager::messages(), mtar_close(), MTAR_ESUCCESS, mtar_finalize(), mtar_open(), pack_artifacts(), pack_formulae(), pack_images(), SEE_LAST_ERROR, split_string(), strdup_local, stringbuffer_delete(), stringbuffer_finish(), stringbuffer_length(), stringbuffer_new(), and AssetsManager::treasures().

Referenced by server_pack_assets().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ build_filename()

static void build_filename ( const char *  name,
const char *  prefix,
char *  dest,
size_t  max 
)
static

Definition at line 365 of file assets.cpp.

References snprintf.

Referenced by pack_images().

+ Here is the caller graph for this function:

◆ check_generators()

static void check_generators ( void  )
static

Check all generators have the other_arch set or something in inventory.

Definition at line 143 of file assets.cpp.

References AssetsManager::archetypes(), AssetsCollection< T, Key >::each(), fatal(), FLAG_CONTENT_ON_GEN, FLAG_GENERATOR, QUERY_FLAG, and SEE_LAST_ERROR.

Referenced by assets_end_load().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ check_spells()

static void check_spells ( void  )
static

This ensures all spells have a skill defined, calling fatal() if any error was found.

Definition at line 184 of file assets.cpp.

References AssetsManager::archetypes(), AssetsCollection< T, Key >::each(), fatal(), and SEE_LAST_ERROR.

Referenced by assets_end_load(), and init_beforeplay().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ check_summoned()

void check_summoned ( void  )

This checks all summonable items for move_type and other things. Will call fatal() if an error is found.

Definition at line 170 of file assets.cpp.

References AssetsManager::archetypes(), AssetsCollection< T, Key >::each(), and SP_SUMMON_GOLEM.

Referenced by assets_end_load().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ do_pack()

template<class T >
static void do_pack ( AssetWriter< T > *  writer,
AssetsCollection< T > *  assets,
StringBuffer buf 
)
static

Definition at line 340 of file assets.cpp.

References AssetsCollection< T, Key >::each(), and AssetWriter< T >::write().

Referenced by assets_pack().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ faces_for_each()

void faces_for_each ( face_op  op)

Definition at line 292 of file assets.cpp.

References AssetsCollection< T, Key >::each(), and AssetsManager::faces().

Referenced by dump_faces().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ facesets_for_each()

void facesets_for_each ( faceset_op  op)

Definition at line 296 of file assets.cpp.

References AssetsCollection< T, Key >::each(), and AssetsManager::facesets().

Referenced by send_image_info(), and START_TEST().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ find_animation()

Animations* find_animation ( const char *  name)

Definition at line 265 of file assets.cpp.

References AssetsManager::animations(), and AssetsCollection< T, Key >::get().

Referenced by mimic_type_apply(), object_give_identified_properties(), and transport_type_apply().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ find_archetype()

◆ find_face()

const Face* find_face ( const char *  name)

Definition at line 277 of file assets.cpp.

References AssetsManager::faces(), and AssetsCollection< T, Key >::get().

Referenced by MessageLoader::load(), load_quests_from_file(), and FaceLoader::loadAnimationBlock().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ find_faceset()

face_sets* find_faceset ( int  id)

Definition at line 335 of file assets.cpp.

References AssetsManager::facesets(), and Facesets::findById().

Referenced by esrv_send_face(), get_face_fallback(), is_valid_faceset(), main(), process_map(), send_image_sums(), and test_faceset().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_bitmap_checksum()

int get_bitmap_checksum ( )

Definition at line 331 of file assets.cpp.

References Faces::checksum(), and AssetsManager::faces().

Referenced by send_image_info().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_face_by_id()

const Face* get_face_by_id ( uint16_t  id)

Get a face from its unique identifier.

Parameters
idface identifier.
Returns
matching face, NULL if no face with this identifier.
Todo:
move back to image.c when migrated

Definition at line 314 of file assets.cpp.

References AssetsManager::faces(), and Faces::findById().

Referenced by ask_smooth_cmd(), cfapi_system_find_face(), CRESmoothFaceMaker::CRESmoothFaceMaker(), send_face_cmd(), send_image_sums(), and test_faceset().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_faces_count()

size_t get_faces_count ( void  )

Definition at line 288 of file assets.cpp.

References AssetsCollection< T, Key >::count(), and AssetsManager::faces().

Referenced by CRESmoothFaceMaker::CRESmoothFaceMaker(), init_connection(), main(), monsterFight(), new_connection(), send_image_info(), send_image_sums(), START_TEST(), and test_faceset().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_message_from_identifier()

const GeneralMessage* get_message_from_identifier ( const char *  identifier)

Find the message from its identifier.

Parameters
identifiermessage's identifier.
Returns
corresponding message, NULL if no such message.

Definition at line 327 of file assets.cpp.

References AssetsCollection< T, Key >::find(), and AssetsManager::messages().

Referenced by knowledge_message_detail(), knowledge_message_face(), knowledge_message_summary(), and knowledge_message_validate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_next_archetype()

◆ get_random_message()

GeneralMessage* get_random_message ( )

Definition at line 318 of file assets.cpp.

References AssetsManager::messages(), and Messages::random().

Referenced by msgfile_msg().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getManager()

◆ pack_artifacts()

static void pack_artifacts ( StringBuffer buf)
static

Definition at line 347 of file assets.cpp.

References first_artifactlist, artifactliststruct::next, and ArtifactWriter::write().

Referenced by assets_pack().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pack_formulae()

static void pack_formulae ( StringBuffer buf)
static

Definition at line 356 of file assets.cpp.

References get_formulalist(), recipeliststruct::next, and FormulaeWriter::write().

Referenced by assets_pack().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pack_images()

static void pack_images ( mtar_t tar)
static

Pack all client-side images in the specified tar file.

Parameters
tarwhere to pack images.

Definition at line 411 of file assets.cpp.

References add_to_tar(), build_filename(), AssetsCollection< T, Key >::each(), AssetsManager::faces(), and AssetsManager::facesets().

Referenced by assets_pack().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ recipe_find_ingredient_cost()

long recipe_find_ingredient_cost ( const char *  name)

Try to find an ingredient with specified name.

If several archetypes have the same name, the value of the first one with that name will be returned. This happens for the mushrooms (mushroom_1, mushroom_2 and mushroom_3). For the monsters' body parts, there may be several monsters with the same name. This is not a problem if these monsters have the same level (e.g. sage & c_sage) or if only one of the monsters generates the body parts that we are looking for (e.g. big_dragon and big_dragon_worthless).

Will also search in artifacts.

Note
migrated from recipe.c for performance issues.
Parameters
nameingredient we're searching for. Can start with a number.
Returns
cost of ingredient, -1 if wasn't found.
Todo:
move back to recipe.c it it migrates to C++.

Definition at line 544 of file assets.cpp.

References AssetsManager::archetypes(), AssetsCollection< T, Key >::each(), llevError, LOG(), safe_strncpy, and strcasecmp().

Referenced by dump_alchemy_costs().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ try_find_animation()

Animations* try_find_animation ( const char *  name)

Definition at line 269 of file assets.cpp.

References AssetsManager::animations(), and AssetsCollection< T, Key >::find().

Referenced by add_abilities(), apply_anim_suffix(), apply_changes_to_player(), cfapi_object_set_property(), and cfapi_system_find_animation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ try_find_archetype()

◆ try_find_face()

const Face* try_find_face ( const char *  name,
const Face error 
)

Variable Documentation

◆ manager

◆ nroftreasures

size_t nroftreasures = 0

Number of treasure items, for malloc info.

Definition at line 82 of file assets.cpp.

Referenced by assets_number_of_treasures(), get_empty_treasure(), and TreasureLoader::loadTreasure().