Crossfire Server, Trunk
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::name
sstring name
Definition: face.h:19
Face
Definition: face.h:14
global.h
find_smooth
int find_smooth(const Face *face, const Face **smoothed)
Definition: image.cpp:102
llevError
@ llevError
Definition: logger.h:11
LOG
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.cpp:51
AssetsManager.h
get_face_fallback
int get_face_fallback(int faceset, uint16_t imageno)
Definition: image.cpp:133
dump_faces
void dump_faces(void)
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:332
blank_face
const Face * blank_face
Definition: image.cpp:36
face_sets::id
int id
Definition: image.h:18
getManager
AssetsManager * getManager()
Definition: assets.cpp:309
face_sets::prefix
char * prefix
Definition: image.h:19
Face::number
uint16_t number
Definition: face.h:15
AssetsManager::faces
Faces * faces()
Definition: AssetsManager.h:39
face_info::data
uint8_t * data
Definition: image.h:11
Face::smoothface
struct Face * smoothface
Definition: face.h:18
AssetsCollection::each
void each(std::function< void(T *)> op)
Definition: AssetsCollection.h:158
image.h
face_sets::fallback
struct face_sets * fallback
Definition: image.h:21
is_valid_faceset
int is_valid_faceset(int fsn)
Definition: image.cpp:117
empty_face
const Face * empty_face
Definition: image.cpp:36
find_color
uint8_t find_color(const char *name)
Definition: image.cpp:75
assets.h
npc_dialog.index
int index
Definition: npc_dialog.py:102
face_sets
Definition: image.h:17
smooth_face
const Face * smooth_face
Definition: image.cpp:36
face_sets::faces
face_info * faces
Definition: image.h:26
colorname
static const char *const colorname[]
Definition: image.cpp:46
give.name
name
Definition: give.py:27