Crossfire Server, Trunk  R20513
Functions | Variables
image.c File Reference

Handles face-related stuff, including the actual face data. More...

#include "global.h"
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "image.h"
Include dependency graph for image.c:

Go to the source code of this file.

Functions

static void check_faceset_fallback (int faceset, int togo)
 Checks fallback are correctly defined. More...
 
static int compare_face (const New_Face *a, const New_Face *b)
 Used for bsearch searching for faces by name. More...
 
static uint8_t find_color (const char *name)
 Finds a color by name. More...
 
unsigned find_face (const char *name, unsigned error)
 This returns an the face number of face 'name'. More...
 
int find_smooth (uint16_t face, uint16_t *smoothed)
 Find the smooth face for a given face. More...
 
void free_all_images (void)
 Deallocates memory allocated by read_bmap_names() and read_smooth(). More...
 
void free_socket_images (void)
 Frees all faceset information. More...
 
int get_face_fallback (int faceset, int imageno)
 This returns the set we will actually use when sending a face. More...
 
int is_valid_faceset (int fsn)
 Checks specified faceset is valid. More...
 
void read_bmap_names (void)
 This reads the bmaps file to get all the bitmap names and stuff. More...
 
void read_client_images (void)
 Loads all the image types into memory. More...
 
static void read_face_data (void)
 This reads the lib/faces file, getting color and visibility information. More...
 
int read_smooth (void)
 Reads the smooth file to know how to smooth datas. More...
 

Variables

New_Faceblank_face
 Following can just as easily be pointers, but it is easier to keep them like this. More...
 
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 face into a numeric index that is then sent to the client for magic map commands. More...
 
New_Faceempty_face
 
face_sets facesets [MAX_FACE_SETS]
 All facesets. More...
 
New_Facenew_faces
 Contains face information, with names, numbers, magicmap color and such. More...
 
unsigned int nrofpixmaps = 0
 Number of bitmaps loaded from the "bmaps" file. More...
 
New_Facesmooth_face
 

Detailed Description

Handles face-related stuff, including the actual face data.

Definition in file image.c.

Function Documentation

static void check_faceset_fallback ( int  faceset,
int  togo 
)
static

Checks fallback are correctly defined.

This is a simple recursive function that makes sure the fallbacks are all proper (eg, the fall back to defined sets, and also eventually fall back to 0). At the top level, togo is set to MAX_FACE_SETS. If togo gets to zero, it means we have a loop. This is only run when we first load the facesets.

Definition at line 412 of file image.c.

References face_sets::fallback, llevError, and LOG().

Referenced by read_client_images().

Here is the call graph for this function:

Here is the caller graph for this function:

static int compare_face ( const New_Face a,
const New_Face b 
)
static

Used for bsearch searching for faces by name.

The face "bug.111" is always put at first.

Todo:
"bug.111" should be a regular face, alas many places consider face 0 to be that face. This should be fixed at some point.
Parameters
afirst item to compare.
bsecond item to compare.
Return values
-1if a < b
0if a == b
1if a > b

Definition at line 83 of file image.c.

References new_face_struct::name.

Referenced by find_face(), and read_bmap_names().

Here is the caller graph for this function:

static uint8_t find_color ( const char *  name)
static

Finds a color by name.

Parameters
namecolor name, case-sensitive.
Returns
the matching color in the coloralias if found, 0 otherwise.
Note
0 will actually be black, so there is no way the calling function can tell if an error occurred or not

Definition at line 106 of file image.c.

References colorname, llevError, and LOG().

Referenced by read_bmap_names(), and read_face_data().

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned find_face ( const char *  name,
unsigned  error 
)

This returns an the face number of face 'name'.

Number is constant during an invocation, but not necessarily between versions (this is because the faces are arranged in alphabetical order, so if a face is removed or added, all faces after that will now have a different number.

Parameters
nameface to search for
errorvalue to return if face was not found.
Note
If a face is not found, then error is returned. This can be useful if you want some default face used, or can be set to negative so that it will be known that the face could not be found (needed in client, so that it will know to request that image from the server)

Definition at line 303 of file image.c.

References compare_face(), new_face_struct::name, nrofpixmaps, and new_face_struct::number.

Referenced by add_abilities(), cfapi_object_set_property(), cfapi_system_find_face(), fix_flesh_item(), init_anim(), init_msgfile(), knowledge_process_incremental(), knowledge_send_info(), load_quests_from_file(), object_give_identified_properties(), read_bmap_names(), read_client_images(), read_face_data(), read_smooth(), send_account_players(), set_object_face_main(), set_object_face_other(), and transport_type_apply().

Here is the call graph for this function:

Here is the caller graph for this function:

int find_smooth ( uint16_t  face,
uint16_t smoothed 
)

Find the smooth face for a given face.

Parameters
facethe face to find the smoothing face for
smoothedreturn value: set to smooth face
Returns
1=smooth face found, 0=no smooth face found

Definition at line 379 of file image.c.

References nrofpixmaps, and new_face_struct::smoothface.

Referenced by send_smooth().

Here is the caller graph for this function:

void free_all_images ( void  )

Deallocates memory allocated by read_bmap_names() and read_smooth().

Definition at line 396 of file image.c.

References nrofpixmaps.

Referenced by cleanup().

Here is the caller graph for this function:

void free_socket_images ( void  )

Frees all faceset information.

Definition at line 572 of file image.c.

References MAX_FACE_SETS, and nrofpixmaps.

Referenced by free_all_newserver().

Here is the caller graph for this function:

int get_face_fallback ( int  faceset,
int  imageno 
)

This returns the set we will actually use when sending a face.

This is used because the image files may be sparse. This function is recursive. imageno is the face number we are trying to send

If face is not found in specified faceset, tries with 'fallback' faceset.

Parameters
facesetfaceset to check
imagenoimage number

Definition at line 602 of file image.c.

References get_face_fallback(), llevError, and LOG().

Referenced by esrv_send_face(), get_face_fallback(), process_map(), and send_image_sums().

Here is the call graph for this function:

Here is the caller graph for this function:

int is_valid_faceset ( int  fsn)

Checks specified faceset is valid.

Parameters
fsnfaceset number

Definition at line 563 of file image.c.

References FALSE, MAX_FACE_SETS, and TRUE.

Referenced by main(), and set_up_cmd().

Here is the caller graph for this function:

void read_bmap_names ( void  )

This reads the bmaps file to get all the bitmap names and stuff.

It only needs to be done once, because it is player independent (ie, what display the person is on will not make a difference.)

Note
will call exit() if file doesn't exist, and abort() in case of memory error.

Definition at line 180 of file image.c.

References BLANK_FACE_NAME, bmaps_checksum, compare_face(), Settings::datadir, EMPTY_FACE_NAME, FACE_FLOOR, fatal(), find_color(), find_face(), llevDebug, llevError, LOG(), new_face_struct::magicmap, MAX_BUF, new_face_struct::name, nrofpixmaps, new_face_struct::number, OUT_OF_MEMORY, read_face_data(), ROTATE_RIGHT, SEE_LAST_ERROR, settings, SMOOTH_FACE_NAME, new_face_struct::smoothface, snprintf, strdup_local, and new_face_struct::visibility.

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:

void read_client_images ( void  )

Loads all the image types into memory.

This way, we can easily send them to the client. We should really do something better than abort on any errors - on the other hand, these are all fatal to the server (can't work around them), but the abort just seems a bit messy (exit would probably be better.)

Couple of notes: We assume that the faces are in a continous block. This works fine for now, but this could perhaps change in the future

Function largely rewritten May 2000 to be more general purpose. The server itself does not care what the image data is - to the server, it is just data it needs to allocate. As such, the code is written to do such.

Definition at line 448 of file image.c.

References check_faceset_fallback(), face_info::checksum, face_sets::comment, face_info::data, Settings::datadir, face_info::datalen, face_sets::extension, face_sets::faces, face_sets::fallback, find_face(), face_sets::fullname, HUGE_BUF, llevDebug, llevError, LOG(), MAX_FACE_SETS, MAX_IMAGE_SIZE, nrofpixmaps, face_sets::prefix, ROTATE_RIGHT, settings, face_sets::size, snprintf, split_string(), and strdup_local.

Referenced by init_server(), ResourcesManager::load(), and main().

Here is the call graph for this function:

Here is the caller graph for this function:

static void read_face_data ( void  )
static

This reads the lib/faces file, getting color and visibility information.

It is called by read_bmap_names().

Note
will call exit() if file doesn't exist.

Definition at line 124 of file image.c.

References Settings::datadir, FACE_FLOOR, find_color(), find_face(), llevDebug, llevError, LOG(), new_face_struct::magicmap, MAX_BUF, settings, snprintf, and new_face_struct::visibility.

Referenced by read_bmap_names().

Here is the call graph for this function:

Here is the caller graph for this function:

int read_smooth ( void  )

Reads the smooth file to know how to smooth datas.

the smooth file if made of 2 elements lines. lines starting with # are comment the first element of line is face to smooth the next element is the 16x2 faces picture used for smoothing

Note
will call exit() if file can't be opened.

Definition at line 323 of file image.c.

References Settings::datadir, find_face(), llevDebug, llevError, LOG(), MAX_BUF, settings, new_face_struct::smoothface, and snprintf.

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:

Variable Documentation

New_Face* blank_face
const char* const colorname[]
static
Initial value:
= {
"black",
"white",
"blue",
"red",
"orange",
"light_blue",
"dark_orange",
"green",
"light_green",
"grey",
"brown",
"yellow",
"khaki"
}

The only thing this table is used for now is to translate the colorname in the magicmap field of the face into a numeric index that is then sent to the client for magic map commands.

The order of this table must match that of the NDI colors in include/newclient.h.

Definition at line 56 of file image.c.

Referenced by find_color().

New_Face * empty_face

Definition at line 39 of file image.c.

Referenced by esrv_draw_look(), and esrv_send_inventory().

All facesets.

Definition at line 47 of file image.c.

Referenced by esrv_send_face(), CREPixmap::getIcon(), main(), process_map(), send_image_info(), and send_image_sums().

New_Face* new_faces
unsigned int nrofpixmaps = 0
New_Face * smooth_face

Definition at line 39 of file image.c.

Referenced by send_smooth().