Crossfire Server, Trunk  1.75.0
image.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
5  * Copyright (c) 1992 Frank Tore Johansen
6  *
7  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8  * welcome to redistribute it under certain conditions. For details, please
9  * see COPYING and LICENSE.
10  *
11  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
12  */
13 
19 #include "global.h"
20 
21 #include <assert.h>
22 #include <errno.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 
27 #include "image.h"
28 
29 #include "assets.h"
30 #include "AssetsManager.h"
31 
37 
38 
46 static const char *const colorname[] = {
47  "black", /* 0 */
48  "white", /* 1 */
49  "blue", /* 2 */
50  "red", /* 3 */
51  "orange", /* 4 */
52  "light_blue", /* 5 */
53  "dark_orange", /* 6 */
54  "green", /* 7 */
55  "light_green", /* 8 */
56  "grey", /* 9 */
57  "brown", /* 10 */
58  "yellow", /* 11 */
59  "khaki" /* 12 */
60 };
61 
75 uint8_t find_color(const char *name) {
76  uint8_t i;
77 
78  for (i = 0; i < sizeof(colorname)/sizeof(*colorname); i++)
79  if (!strcmp(name, colorname[i]))
80  return i;
81 
82  LOG(llevError, "Unknown color: %s\n", name);
83  return 0;
84 }
85 
86 const char *get_colorname(uint8_t index) {
87  if (index < sizeof(colorname) / sizeof(*colorname)) {
88  return colorname[index];
89  }
90  return "";
91 }
92 
102 int find_smooth(const Face *face, const Face **smoothed) {
103  (*smoothed) = NULL;
104 
105  if (face && face->smoothface) {
106  (*smoothed) = face->smoothface;
107  return 1;
108  }
109 
110  return 0;
111 }
112 
117 int is_valid_faceset(int fsn) {
118  return find_faceset(fsn) != NULL;
119 }
120 
133 int get_face_fallback(int faceset, uint16_t imageno) {
134  /* faceset 0 is supposed to have every image, so just return. Doing
135  * so also prevents infinite loops in the case if it not having
136  * the face, but in that case, we are likely to crash when we try
137  * to access the data, but that is probably preferable to an infinite
138  * loop.
139  */
140 
141  face_sets *fs = find_faceset(faceset);
142  if (!fs || !fs->prefix) {
143  LOG(llevError, "get_face_fallback called with unused set (%d)?\n", faceset);
144  return 0; /* use default set */
145  }
146  if (imageno < fs->allocated && fs->faces[imageno].data)
147  return faceset;
148 
149  if (!fs->fallback) {
150  return 0;
151  }
152 
153  return get_face_fallback(fs->fallback->id, imageno);
154 }
155 
159 void dump_faces(void) {
160  fprintf(stderr, "id name smooth\n");
161  getManager()->faces()->each([] (const Face *face) {
162  fprintf(stderr, "%5d %50s %50s\n", face->number, face->name, face->smoothface ? face->smoothface->name : "(none)");
163  });
164 }
Face
New face structure - this enforces the notion that data is face by face only - you can not change the...
Definition: face.h:14
global.h
find_smooth
int find_smooth(const Face *face, const Face **smoothed)
Find the smooth face for a given face.
Definition: image.cpp:102
llevError
@ llevError
Error, serious thing.
Definition: logger.h:11
LOG
void LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
Definition: logger.cpp:58
AssetsManager.h
get_face_fallback
int get_face_fallback(int faceset, uint16_t imageno)
This returns the set we will actually use when sending a face.
Definition: image.cpp:133
dump_faces
void dump_faces(void)
Dump all faces to stderr, for debugging purposes.
Definition: image.cpp:159
get_colorname
const char * get_colorname(uint8_t index)
Definition: image.cpp:86
find_faceset
face_sets * find_faceset(int id)
Definition: assets.cpp:328
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
face_sets::id
int id
Definition: image.h:18
getManager
AssetsManager * getManager()
Definition: assets.cpp:305
face_sets::prefix
char * prefix
Faceset short name, used in pictures names (base, clsc).
Definition: image.h:19
name
Plugin animator file specs[Config] name
Definition: animfiles.txt:4
treasurelist::name
sstring name
Usually monster-name/combination.
Definition: treasure.h:86
AssetsManager::faces
Faces * faces()
Get faces.
Definition: AssetsManager.h:39
face_info::data
uint8_t * data
Image data.
Definition: image.h:11
AssetsCollection::each
void each(std::function< void(T *)> op)
Apply a function to each asset.
Definition: AssetsCollection.h:158
image.h
face_sets::fallback
struct face_sets * fallback
Faceset to use when an image is not found in this faceset.
Definition: image.h:21
is_valid_faceset
int is_valid_faceset(int fsn)
Checks specified faceset is valid.
Definition: image.cpp:117
empty_face
const Face * empty_face
Definition: image.cpp:36
find_color
uint8_t find_color(const char *name)
Finds a color by name.
Definition: image.cpp:75
assets.h
face_sets
Information about one face set.
Definition: image.h:17
smooth_face
const Face * smooth_face
Definition: image.cpp:36
face_sets::faces
face_info * faces
images in this faceset
Definition: image.h:26
colorname
static const char *const colorname[]
The only thing this table is used for now is to translate the colorname in the magicmap field of the ...
Definition: image.cpp:46
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