Angband
Data Structures | Functions | Variables
ui-visuals.c File Reference

Appearance for screen elements. More...

#include "angband.h"
#include "game-event.h"
#include "init.h"
#include "monster.h"
#include "parser.h"
#include "ui-visuals.h"
#include "z-color.h"
#include "z-util.h"

Data Structures

struct  visuals_color_cycle
 A set of colors to rotate between. More...
 
struct  visuals_cycle_group
 A group of color cycles. More...
 
struct  visuals_cycler
 A color cycling table, made up of groups of actual color cycles. More...
 
struct  visuals_flicker
 Table to contain all of the color info for the flicker-style cycling. More...
 
struct  visuals_parse_context
 Context data for file parsing. More...
 

Functions

static struct visuals_color_cyclevisuals_color_cycle_new (const char *name, size_t const step_count, byte const invalid_color)
 Create a new color cycle. More...
 
static void visuals_color_cycle_free (struct visuals_color_cycle *cycle)
 Deallocate a color cycle. More...
 
static struct visuals_color_cyclevisuals_color_cycle_copy (struct visuals_color_cycle const *original)
 Copy a given color cycle by creating a new instance with the same values. More...
 
static byte visuals_color_cycle_attr_for_frame (struct visuals_color_cycle const *cycle, size_t const frame)
 Return the next color in the cycle for a given frame. More...
 
static struct visuals_cycle_groupvisuals_cycle_group_new (const char *name, size_t const cycle_count)
 Create a new color cycle group. More...
 
static void visuals_cycle_group_free (struct visuals_cycle_group *group)
 Deallocate a color cycle group. More...
 
static struct visuals_cyclervisuals_cycler_new (size_t const group_count)
 Create a new color cycling table. More...
 
static void visuals_cycler_free (struct visuals_cycler *cycler)
 Deallocate a color cycler. More...
 
static struct visuals_color_cyclevisuals_cycler_cycle_by_name (struct visuals_cycler const *cycler, const char *group_name, const char *cycle_name)
 Search for a color cycle with the given group and name. More...
 
byte visuals_cycler_get_attr_for_frame (const char *group_name, const char *cycle_name, size_t const frame)
 Get an attribute for a color cycle in a color cycle group from the module table. More...
 
void visuals_cycler_set_cycle_for_race (struct monster_race const *race, const char *group_name, const char *cycle_name)
 Set a color cycle for a monster race. More...
 
byte visuals_cycler_get_attr_for_race (struct monster_race const *race, size_t const frame)
 Get an attribute from a monster race's color cycle. More...
 
static struct visuals_flickervisuals_flicker_new (size_t const max_cycles, size_t const colors_per_cycle)
 Allocate a new flicker color table to hold a fixed number of entries. More...
 
static void visuals_flicker_free (struct visuals_flicker *table)
 Deallocate a flicker color table. More...
 
static void visuals_flicker_set_color (struct visuals_flicker *table, size_t const cycle_index, size_t const color_index, byte const attr)
 Set the color that should appear at a particular step in a cycle. More...
 
static byte visuals_flicker_get_color (struct visuals_flicker *table, size_t const cycle_index, size_t const color_index)
 Get the color that should appear at a particular step in a cycle. More...
 
byte visuals_flicker_get_attr_for_frame (byte const selection_attr, size_t const frame)
 Get an attribute for the flicker cycle for a base attribute from the module color table. More...
 
static struct visuals_parse_contextvisuals_parse_context_new (void)
 Allocate a visuals parser context. More...
 
static void visuals_parse_context_free (struct visuals_parse_context *context)
 Deallocate parser context. More...
 
static struct visuals_cyclervisuals_parse_context_convert (struct visuals_parse_context const *context)
 Create a cycler instance from the parser context. More...
 
static enum parser_error visuals_parse_flicker (struct parser *parser)
 Handle a "flicker" row. More...
 
static enum parser_error visuals_parse_flicker_color (struct parser *parser)
 Handle a "flicker-color" row. More...
 
static enum parser_error visuals_parse_cycle (struct parser *parser)
 Handle a "cycle" row. More...
 
static enum parser_error visuals_parse_cycle_color (struct parser *parser)
 Handle a "cycle-color" row. More...
 
static struct parservisuals_file_parser_init (void)
 Create a new instance of the visuals parser. More...
 
static errr visuals_file_parser_run (struct parser *parser)
 Run a parser for a file parser. More...
 
static errr visuals_file_parser_finish (struct parser *parser)
 Clean up the visuals parser itself. More...
 
static void visuals_file_parser_cleanup (void)
 Perform any final things needed after parsing the visuals file. More...
 
static void ui_visuals_module_init (void)
 Set up the visuals module. More...
 
static void ui_visuals_module_cleanup (void)
 Tear down the visuals module. More...
 

Variables

static size_t const VISUALS_GROUPS_MAX = 8
 Max color cycle groups per cycler. More...
 
static size_t const VISUALS_CYCLES_MAX = 64
 Max color cycles per group. More...
 
static size_t const VISUALS_STEPS_MAX = 32
 Max colors per color cycle. More...
 
static byte const VISUALS_INVALID_COLOR = 0xFF
 Value to mark unused or otherwise invalid colors in a color cycle. More...
 
static struct visuals_cyclervisuals_cycler_table = NULL
 Module color cycling table instance. More...
 
struct {
   struct visuals_color_cycle **   race
 
   size_t   max_entries
 
   size_t   alloc_size
 
} * visuals_color_cycles_by_race = NULL
 A table to quickly map monster races to color cycles. More...
 
static struct visuals_flickervisuals_flicker_table = NULL
 Module flicker color table instance. More...
 
static struct file_parser visuals_file_parser
 File parser instance for the visuals file. More...
 
struct init_module ui_visuals_module
 Visuals module registration. More...
 

Detailed Description

Appearance for screen elements.

Copyright (c) 2016 Ben Semmler

This work is free software; you can redistribute it and/or modify it under the terms of either:

a) the GNU General Public License as published by the Free Software Foundation, version 2, or

b) the "Angband licence": This software may be copied and distributed for educational, research, and not for profit purposes provided that this copyright and statement are included in all such copies. Other copyrights may also apply.

Function Documentation

◆ ui_visuals_module_cleanup()

static void ui_visuals_module_cleanup ( void  )
static

Tear down the visuals module.

References mem_free(), visuals_color_cycles_by_race, visuals_cycler_free(), and visuals_flicker_free().

◆ ui_visuals_module_init()

static void ui_visuals_module_init ( void  )
static

Set up the visuals module.

This includes parsing the visuals file.

References file_parser::cleanup, EVENT_INITSTATUS, event_signal_message(), MAX_COLORS, mem_zalloc(), quit(), run_parser(), visuals_color_cycles_by_race, and visuals_flicker_new().

◆ visuals_color_cycle_attr_for_frame()

static byte visuals_color_cycle_attr_for_frame ( struct visuals_color_cycle const cycle,
size_t const  frame 
)
static

Return the next color in the cycle for a given frame.

Parameters
cycleThe color cycle to select a color from.
frameAn arbitrary value used to select the color step.
Returns
A color or BASIC_COLORS if an error occurred.

References BASIC_COLORS, visuals_color_cycle::max_steps, and visuals_color_cycle::steps.

Referenced by visuals_cycler_get_attr_for_frame(), and visuals_cycler_get_attr_for_race().

◆ visuals_color_cycle_copy()

static struct visuals_color_cycle* visuals_color_cycle_copy ( struct visuals_color_cycle const original)
static

Copy a given color cycle by creating a new instance with the same values.

If there are any invalid colors in the original, the copy will contain only the valid colors in the original (preserving the original order).

Parameters
originalThe color cycle to copy.
Returns
A new color cycle instance, containing the same cycle information as original. NULL is returned on error.

References visuals_color_cycle::cycle_name, visuals_color_cycle::invalid_color, visuals_color_cycle::max_steps, visuals_color_cycle::steps, and visuals_color_cycle_new().

Referenced by visuals_parse_context_convert().

◆ visuals_color_cycle_free()

static void visuals_color_cycle_free ( struct visuals_color_cycle cycle)
static

Deallocate a color cycle.

Parameters
cycleThe color cycle to deallocate.

References visuals_color_cycle::cycle_name, mem_free(), visuals_color_cycle::steps, and string_free().

Referenced by visuals_cycle_group_free(), and visuals_parse_context_free().

◆ visuals_color_cycle_new()

static struct visuals_color_cycle* visuals_color_cycle_new ( const char *  name,
size_t const  step_count,
byte const  invalid_color 
)
static

Create a new color cycle.

Parameters
nameThe identifier for the new color cycle.
step_countThe maximum number of steps in the cycle.
invalid_colorA value used to mark steps that should not be considered valid colors. This is also used as the initial value for each value in the steps array.
Returns
A new color cycle instance or NULL if an error occurred.

References cycle, visuals_color_cycle::cycle_name, visuals_color_cycle::invalid_color, visuals_color_cycle::max_steps, mem_free(), mem_zalloc(), visuals_color_cycle::steps, and string_make().

Referenced by visuals_color_cycle_copy(), and visuals_parse_cycle().

◆ visuals_cycle_group_free()

static void visuals_cycle_group_free ( struct visuals_cycle_group group)
static

Deallocate a color cycle group.

Parameters
groupThe group to deallocate.

References visuals_cycle_group::cycles, visuals_cycle_group::group_name, i, visuals_cycle_group::max_cycles, mem_free(), string_free(), and visuals_color_cycle_free().

Referenced by visuals_cycler_free().

◆ visuals_cycle_group_new()

static struct visuals_cycle_group* visuals_cycle_group_new ( const char *  name,
size_t const  cycle_count 
)
static

Create a new color cycle group.

Parameters
nameThe identifier for the group.
cycle_countThe maximum number of color cycles that will be in the group.
Returns
A new color cycle group or NULL if an error occurred.

References visuals_cycle_group::cycles, visuals_cycle_group::group_name, visuals_cycle_group::max_cycles, mem_free(), mem_zalloc(), and string_make().

Referenced by visuals_parse_context_convert().

◆ visuals_cycler_cycle_by_name()

static struct visuals_color_cycle* visuals_cycler_cycle_by_name ( struct visuals_cycler const cycler,
const char *  group_name,
const char *  cycle_name 
)
static

Search for a color cycle with the given group and name.

Parameters
cyclerThe cycler to search.
group_nameThe name of the group to search.
cycle_nameThe name of the color cycle to find.
Returns
A color cycle or NULL if an error occurred.

References cycle, visuals_color_cycle::cycle_name, visuals_cycle_group::cycles, visuals_cycle_group::group_name, visuals_cycler::groups, i, visuals_cycle_group::max_cycles, visuals_cycler::max_groups, and streq.

Referenced by visuals_cycler_get_attr_for_frame(), and visuals_cycler_set_cycle_for_race().

◆ visuals_cycler_free()

static void visuals_cycler_free ( struct visuals_cycler cycler)
static

Deallocate a color cycler.

Parameters
cyclerThe cycler to deallocate.

References visuals_cycler::groups, i, visuals_cycler::max_groups, mem_free(), and visuals_cycle_group_free().

Referenced by ui_visuals_module_cleanup().

◆ visuals_cycler_get_attr_for_frame()

byte visuals_cycler_get_attr_for_frame ( const char *  group_name,
const char *  cycle_name,
size_t const  frame 
)

Get an attribute for a color cycle in a color cycle group from the module table.

Parameters
group_nameThe color cycle group to search.
cycle_nameThe color cycle to use.
frameAn arbitrary value used to select which color in the flicker cycle to return.
Returns
An attribute in the color cycle, or BASIC_COLORS if an error occurred.

References BASIC_COLORS, cycle, visuals_color_cycle_attr_for_frame(), visuals_cycler_cycle_by_name(), and visuals_cycler_table.

◆ visuals_cycler_get_attr_for_race()

byte visuals_cycler_get_attr_for_race ( struct monster_race const race,
size_t const  frame 
)

Get an attribute from a monster race's color cycle.

Parameters
raceThe race to get an attribute for.
frameAn arbitrary value used to select which color in the flicker cycle to return.
Returns
An attribute in the color cycle, or BASIC_COLORS if an error occurred.

References BASIC_COLORS, cycle, monster_race::ridx, visuals_color_cycle_attr_for_frame(), and visuals_color_cycles_by_race.

Referenced by do_animation().

◆ visuals_cycler_new()

static struct visuals_cycler* visuals_cycler_new ( size_t const  group_count)
static

Create a new color cycling table.

Parameters
group_countThe maximum number of groups that the table will contain.
Returns
A new color cycling table or NULL if an error occurred.

References visuals_cycler::groups, visuals_cycler::max_groups, mem_free(), and mem_zalloc().

Referenced by visuals_parse_context_convert().

◆ visuals_cycler_set_cycle_for_race()

void visuals_cycler_set_cycle_for_race ( struct monster_race const race,
const char *  group_name,
const char *  cycle_name 
)

Set a color cycle for a monster race.

If a matching color cycle cannot be found, the monster race will not be color cycled.

When this module is set up, we don't know how many monster races there will be, nor is there a maximum permitted number of races. This function will reallocate the visuals_color_cycles_by_race table as needed, using its allocation increment. This table is initially created in the module init function.

Parameters
raceThe monster race to set the color cycle for.
group_nameThe group of the preferred color cycle.
cycle_nameThe name of the preferred color cycle.

References cycle, mem_realloc(), quit(), monster_race::ridx, visuals_color_cycles_by_race, visuals_cycler_cycle_by_name(), and visuals_cycler_table.

Referenced by parse_monster_color_cycle().

◆ visuals_file_parser_cleanup()

static void visuals_file_parser_cleanup ( void  )
static

Perform any final things needed after parsing the visuals file.

◆ visuals_file_parser_finish()

static errr visuals_file_parser_finish ( struct parser parser)
static

Clean up the visuals parser itself.

Parameters
parserThe visuals parser.
Returns
A parser error code.

References parser_destroy(), parser_priv(), visuals_parse_context_convert(), and visuals_parse_context_free().

◆ visuals_file_parser_init()

static struct parser* visuals_file_parser_init ( void  )
static

Create a new instance of the visuals parser.

Returns
A parser or NULL if one could not be created.

References parser, parser_new(), parser_reg(), parser_setpriv(), visuals_parse_context_new(), visuals_parse_cycle(), visuals_parse_cycle_color(), visuals_parse_flicker(), and visuals_parse_flicker_color().

◆ visuals_file_parser_run()

static errr visuals_file_parser_run ( struct parser parser)
static

Run a parser for a file parser.

Parameters
parserThe visuals parser.
Returns
A parser error code.

References parse_file_quit_not_found().

◆ visuals_flicker_free()

static void visuals_flicker_free ( struct visuals_flicker table)
static

Deallocate a flicker color table.

Parameters
tableThe color table to deallocate.

References visuals_flicker::cycles, and mem_free().

Referenced by ui_visuals_module_cleanup().

◆ visuals_flicker_get_attr_for_frame()

byte visuals_flicker_get_attr_for_frame ( byte const  selection_attr,
size_t const  frame 
)

Get an attribute for the flicker cycle for a base attribute from the module color table.

Parameters
selection_attrThe attribute used to select which flicker cycle to use.
frameAn arbitrary value used to select which color in the flicker cycle to return.
Returns
An attribute in the flicker cycle, or BASIC_COLORS if an error occurred.

References BASIC_COLORS, visuals_flicker::colors_per_cycle, visuals_flicker::max_cycles, and visuals_flicker_get_color().

Referenced by do_animation().

◆ visuals_flicker_get_color()

static byte visuals_flicker_get_color ( struct visuals_flicker table,
size_t const  cycle_index,
size_t const  color_index 
)
static

Get the color that should appear at a particular step in a cycle.

If any of the indexes are out of range, the color with index 0 is returned.

Parameters
tableThe color table to use.
cycle_indexThe index of the desired cycle.
color_indexThe desired step in the cycle.
Returns
The color at the given step in the given cycle.

References visuals_flicker::colors_per_cycle, visuals_flicker::cycles, and visuals_flicker::max_cycles.

Referenced by visuals_flicker_get_attr_for_frame().

◆ visuals_flicker_new()

static struct visuals_flicker* visuals_flicker_new ( size_t const  max_cycles,
size_t const  colors_per_cycle 
)
static

Allocate a new flicker color table to hold a fixed number of entries.

Parameters
max_cyclesThe maximum number of cycles to allow for this table.
colors_per_cycleThe maximum number of color steps in each cycle.
Returns
A new flicker color table instance, or NULL if one could not be created.

References BASIC_COLORS, visuals_flicker::colors_per_cycle, visuals_flicker::cycles, visuals_flicker::max_cycles, mem_free(), and mem_zalloc().

Referenced by ui_visuals_module_init().

◆ visuals_flicker_set_color()

static void visuals_flicker_set_color ( struct visuals_flicker table,
size_t const  cycle_index,
size_t const  color_index,
byte const  attr 
)
static

Set the color that should appear at a particular step in a cycle.

If any of the indexes are out of range, the color is ignored.

Parameters
tableThe color table to update.
cycle_indexThe index of the cycle to update.
color_indexThe step in the given cycle to update.
attrThe actual color to use.

References visuals_flicker::colors_per_cycle, visuals_flicker::cycles, and visuals_flicker::max_cycles.

Referenced by visuals_parse_flicker_color().

◆ visuals_parse_context_convert()

static struct visuals_cycler* visuals_parse_context_convert ( struct visuals_parse_context const context)
static

Create a cycler instance from the parser context.

Parameters
contextThe current visuals parser context.
Returns
A new cycler instance or NULL if an error occurred.

References cycle, visuals_cycle_group::cycles, visuals_parse_context::group_cycles, visuals_parse_context::group_names, visuals_cycler::groups, visuals_color_cycle_copy(), visuals_cycle_group_new(), visuals_cycler_new(), and VISUALS_CYCLES_MAX.

Referenced by visuals_file_parser_finish().

◆ visuals_parse_context_free()

static void visuals_parse_context_free ( struct visuals_parse_context context)
static

◆ visuals_parse_context_new()

static struct visuals_parse_context* visuals_parse_context_new ( void  )
static

◆ visuals_parse_cycle()

static enum parser_error visuals_parse_cycle ( struct parser parser)
static

◆ visuals_parse_cycle_color()

static enum parser_error visuals_parse_cycle_color ( struct parser parser)
static

◆ visuals_parse_flicker()

static enum parser_error visuals_parse_flicker ( struct parser parser)
static

Handle a "flicker" row.

Parameters
parserThe visuals parser.
Returns
A parser error code.

References color_char_to_attr(), visuals_parse_context::flicker_color_index, visuals_parse_context::flicker_cycle_index, parser_getsym(), and parser_priv().

Referenced by visuals_file_parser_init().

◆ visuals_parse_flicker_color()

static enum parser_error visuals_parse_flicker_color ( struct parser parser)
static

Handle a "flicker-color" row.

Parameters
parserThe visuals parser.
Returns
A parser error code.

References color_char_to_attr(), visuals_parse_context::flicker_color_index, visuals_parse_context::flicker_cycle_index, parser_getsym(), parser_priv(), and visuals_flicker_set_color().

Referenced by visuals_file_parser_init().

Variable Documentation

◆ alloc_size

size_t alloc_size

◆ max_entries

size_t max_entries

◆ race

struct visuals_color_cycle** race

◆ ui_visuals_module

struct init_module ui_visuals_module
Initial value:
= {
.name = "ui-visuals",
}
static void ui_visuals_module_cleanup(void)
Tear down the visuals module.
Definition: ui-visuals.c:1141
static void ui_visuals_module_init(void)
Set up the visuals module.
Definition: ui-visuals.c:1105

Visuals module registration.

◆ visuals_color_cycles_by_race

struct { ... } * visuals_color_cycles_by_race

A table to quickly map monster races to color cycles.

Referenced by ui_visuals_module_cleanup(), ui_visuals_module_init(), visuals_cycler_get_attr_for_race(), and visuals_cycler_set_cycle_for_race().

◆ visuals_cycler_table

struct visuals_cycler* visuals_cycler_table = NULL
static

Module color cycling table instance.

Referenced by visuals_cycler_get_attr_for_frame(), and visuals_cycler_set_cycle_for_race().

◆ VISUALS_CYCLES_MAX

size_t const VISUALS_CYCLES_MAX = 64
static

Max color cycles per group.

Referenced by visuals_parse_context_convert(), visuals_parse_context_new(), and visuals_parse_cycle().

◆ visuals_file_parser

struct file_parser visuals_file_parser
static
Initial value:
= {
.name = "visuals",
}
static errr visuals_file_parser_finish(struct parser *parser)
Clean up the visuals parser itself.
Definition: ui-visuals.c:1072
static struct parser * visuals_file_parser_init(void)
Create a new instance of the visuals parser.
Definition: ui-visuals.c:1038
static errr visuals_file_parser_run(struct parser *parser)
Run a parser for a file parser.
Definition: ui-visuals.c:1061
static void visuals_file_parser_cleanup(void)
Perform any final things needed after parsing the visuals file.
Definition: ui-visuals.c:1084

File parser instance for the visuals file.

◆ visuals_flicker_table

struct visuals_flicker* visuals_flicker_table = NULL
static

Module flicker color table instance.

◆ VISUALS_GROUPS_MAX

size_t const VISUALS_GROUPS_MAX = 8
static

Max color cycle groups per cycler.

Referenced by visuals_parse_context_new().

◆ VISUALS_INVALID_COLOR

byte const VISUALS_INVALID_COLOR = 0xFF
static

Value to mark unused or otherwise invalid colors in a color cycle.

Referenced by visuals_parse_cycle().

◆ VISUALS_STEPS_MAX

size_t const VISUALS_STEPS_MAX = 32
static

Max colors per color cycle.

Referenced by visuals_parse_cycle().