Freeciv-3.2
Loading...
Searching...
No Matches
Data Structures | Macros | Enumerations | Functions | Variables
attribute.c File Reference
#include "dataio.h"
#include "fcintl.h"
#include "genhash.h"
#include "log.h"
#include "mem.h"
#include "packets.h"
#include "client_main.h"
#include "attribute.h"
#include "spechash.h"

Go to the source code of this file.

Data Structures

struct  attr_key
 

Macros

#define log_attribute   log_debug
 
#define SPECHASH_TAG   attribute
 
#define SPECHASH_IKEY_TYPE   struct attr_key *
 
#define SPECHASH_IDATA_TYPE   void *
 
#define SPECHASH_IKEY_VAL   attr_key_val
 
#define SPECHASH_IKEY_COMP   attr_key_comp
 
#define SPECHASH_IKEY_COPY   attr_key_dup
 
#define SPECHASH_IKEY_FREE   attr_key_destroy
 
#define SPECHASH_IDATA_FREE   free
 
#define attribute_hash_values_iterate(hash, pvalue)    TYPED_HASH_DATA_ITERATE(void *, hash, pvalue)
 
#define attribute_hash_values_iterate_end   HASH_DATA_ITERATE_END
 
#define attribute_hash_iterate(hash, pkey, pvalue)    TYPED_HASH_ITERATE(const struct attr_key *, void *, hash, pkey, pvalue)
 
#define attribute_hash_iterate_end   HASH_ITERATE_END
 

Enumerations

enum  attribute_serial { A_SERIAL_FAIL , A_SERIAL_OK , A_SERIAL_OLD }
 

Functions

static genhash_val_t attr_key_val (const struct attr_key *pkey)
 
static bool attr_key_comp (const struct attr_key *pkey1, const struct attr_key *pkey2)
 
static struct attr_keyattr_key_dup (const struct attr_key *pkey)
 
static void attr_key_destroy (struct attr_key *pkey)
 
void attribute_init (void)
 
void attribute_free (void)
 
static enum attribute_serial serialize_hash (const struct attribute_hash *hash, void **pdata, int *pdata_length)
 
static enum attribute_serial unserialize_hash (struct attribute_hash *hash, const void *data, size_t data_length)
 
void attribute_flush (void)
 
void attribute_restore (void)
 
void attribute_set (int key, int id, int x, int y, size_t data_length, const void *const data)
 
size_t attribute_get (int key, int id, int x, int y, size_t max_data_length, void *data)
 
void attr_unit_set (enum attr_unit what, int unit_id, size_t data_length, const void *const data)
 
size_t attr_unit_get (enum attr_unit what, int unit_id, size_t max_data_length, void *data)
 
void attr_unit_set_int (enum attr_unit what, int unit_id, int data)
 
size_t attr_unit_get_int (enum attr_unit what, int unit_id, int *data)
 
void attr_city_set (enum attr_city what, int city_id, size_t data_length, const void *const data)
 
size_t attr_city_get (enum attr_city what, int city_id, size_t max_data_length, void *data)
 
void attr_city_set_int (enum attr_city what, int city_id, int data)
 
size_t attr_city_get_int (enum attr_city what, int city_id, int *data)
 
void attr_player_set (enum attr_player what, int player_id, size_t data_length, const void *const data)
 
size_t attr_player_get (enum attr_player what, int player_id, size_t max_data_length, void *data)
 
void attr_tile_set (enum attr_tile what, int x, int y, size_t data_length, const void *const data)
 
size_t attr_tile_get (enum attr_tile what, int x, int y, size_t max_data_length, void *data)
 

Variables

static struct attribute_hash * attribute_hash = NULL
 

Macro Definition Documentation

◆ attribute_hash_iterate

#define attribute_hash_iterate (   hash,
  pkey,
  pvalue 
)     TYPED_HASH_ITERATE(const struct attr_key *, void *, hash, pkey, pvalue)

Definition at line 64 of file attribute.c.

◆ attribute_hash_iterate_end

#define attribute_hash_iterate_end   HASH_ITERATE_END

Definition at line 66 of file attribute.c.

◆ attribute_hash_values_iterate

#define attribute_hash_values_iterate (   hash,
  pvalue 
)     TYPED_HASH_DATA_ITERATE(void *, hash, pvalue)

Definition at line 61 of file attribute.c.

◆ attribute_hash_values_iterate_end

#define attribute_hash_values_iterate_end   HASH_DATA_ITERATE_END

Definition at line 63 of file attribute.c.

◆ log_attribute

#define log_attribute   log_debug

Definition at line 33 of file attribute.c.

◆ SPECHASH_IDATA_FREE

#define SPECHASH_IDATA_FREE   free

Definition at line 59 of file attribute.c.

◆ SPECHASH_IDATA_TYPE

#define SPECHASH_IDATA_TYPE   void *

Definition at line 54 of file attribute.c.

◆ SPECHASH_IKEY_COMP

#define SPECHASH_IKEY_COMP   attr_key_comp

Definition at line 56 of file attribute.c.

◆ SPECHASH_IKEY_COPY

#define SPECHASH_IKEY_COPY   attr_key_dup

Definition at line 57 of file attribute.c.

◆ SPECHASH_IKEY_FREE

#define SPECHASH_IKEY_FREE   attr_key_destroy

Definition at line 58 of file attribute.c.

◆ SPECHASH_IKEY_TYPE

#define SPECHASH_IKEY_TYPE   struct attr_key *

Definition at line 53 of file attribute.c.

◆ SPECHASH_IKEY_VAL

#define SPECHASH_IKEY_VAL   attr_key_val

Definition at line 55 of file attribute.c.

◆ SPECHASH_TAG

#define SPECHASH_TAG   attribute

Definition at line 52 of file attribute.c.

Enumeration Type Documentation

◆ attribute_serial

Enumerator
A_SERIAL_FAIL 
A_SERIAL_OK 
A_SERIAL_OLD 

Definition at line 35 of file attribute.c.

Function Documentation

◆ attr_city_get()

size_t attr_city_get ( enum attr_city  what,
int  city_id,
size_t  max_data_length,
void data 
)

Get city related attribute

Definition at line 492 of file attribute.c.

Referenced by attr_city_get_int(), and cma_get_parameter().

◆ attr_city_get_int()

size_t attr_city_get_int ( enum attr_city  what,
int  city_id,
int data 
)

Get city related integer attribute

Definition at line 509 of file attribute.c.

◆ attr_city_set()

void attr_city_set ( enum attr_city  what,
int  city_id,
size_t  data_length,
const void *const  data 
)

Set city related attribute

Definition at line 483 of file attribute.c.

Referenced by attr_city_set_int(), city_remove(), cma_set_parameter(), and release_city().

◆ attr_city_set_int()

void attr_city_set_int ( enum attr_city  what,
int  city_id,
int  data 
)

Set city related integer attribute

Definition at line 501 of file attribute.c.

◆ attr_key_comp()

static bool attr_key_comp ( const struct attr_key pkey1,
const struct attr_key pkey2 
)
static

Compare-function for the keys in the hash table.

Definition at line 82 of file attribute.c.

◆ attr_key_destroy()

static void attr_key_destroy ( struct attr_key pkey)
static

Free an attribute key.

Definition at line 105 of file attribute.c.

◆ attr_key_dup()

static struct attr_key * attr_key_dup ( const struct attr_key pkey)
static

Duplicate an attribute key.

Definition at line 94 of file attribute.c.

◆ attr_key_val()

static genhash_val_t attr_key_val ( const struct attr_key pkey)
static

Hash function for attribute_hash.

Definition at line 74 of file attribute.c.

◆ attr_player_get()

size_t attr_player_get ( enum attr_player  what,
int  player_id,
size_t  max_data_length,
void data 
)

Get player related attribute

Definition at line 526 of file attribute.c.

◆ attr_player_set()

void attr_player_set ( enum attr_player  what,
int  player_id,
size_t  data_length,
const void *const  data 
)

Set player related attribute

Definition at line 517 of file attribute.c.

◆ attr_tile_get()

size_t attr_tile_get ( enum attr_tile  what,
int  x,
int  y,
size_t  max_data_length,
void data 
)

Get tile related attribute

Definition at line 544 of file attribute.c.

◆ attr_tile_set()

void attr_tile_set ( enum attr_tile  what,
int  x,
int  y,
size_t  data_length,
const void *const  data 
)

Set tile related attribute

Definition at line 535 of file attribute.c.

◆ attr_unit_get()

size_t attr_unit_get ( enum attr_unit  what,
int  unit_id,
size_t  max_data_length,
void data 
)

Get unit related attribute

Definition at line 458 of file attribute.c.

Referenced by attr_unit_get_int().

◆ attr_unit_get_int()

size_t attr_unit_get_int ( enum attr_unit  what,
int  unit_id,
int data 
)

Get unit related integer attribute

Definition at line 475 of file attribute.c.

◆ attr_unit_set()

void attr_unit_set ( enum attr_unit  what,
int  unit_id,
size_t  data_length,
const void *const  data 
)

Set unit related attribute

Definition at line 449 of file attribute.c.

Referenced by attr_unit_set_int().

◆ attr_unit_set_int()

void attr_unit_set_int ( enum attr_unit  what,
int  unit_id,
int  data 
)

Set unit related integer attribute

Definition at line 467 of file attribute.c.

◆ attribute_flush()

void attribute_flush ( void  )

Send current state to the server. Note that the current implementation will send all attributes to the server.

Definition at line 327 of file attribute.c.

Referenced by client_exit(), disconnect_from_server(), send_save_game(), and send_turn_done().

◆ attribute_free()

void attribute_free ( void  )

Frees the attribute module.

Definition at line 123 of file attribute.c.

Referenced by client_game_free(), and client_game_reset().

◆ attribute_get()

size_t attribute_get ( int  key,
int  id,
int  x,
int  y,
size_t  max_data_length,
void data 
)

Low-level function to get an attribute. If data hasn't enough space to hold the attribute data isn't set to the attribute. Returns the actual size of the attribute. Can be zero if the attribute is unset. To get the size of an attribute use size = attribute_get(key, id, x, y, 0, NULL)

Definition at line 416 of file attribute.c.

Referenced by attr_city_get(), attr_player_get(), attr_tile_get(), and attr_unit_get().

◆ attribute_init()

void attribute_init ( void  )

Initializes the attribute module.

Definition at line 114 of file attribute.c.

Referenced by client_game_init(), and client_game_reset().

◆ attribute_restore()

void attribute_restore ( void  )

Recreate the attribute set from the player's attribute_block. Shouldn't be used by normal code.

Definition at line 355 of file attribute.c.

Referenced by handle_player_attribute_chunk().

◆ attribute_set()

void attribute_set ( int  key,
int  id,
int  x,
int  y,
size_t  data_length,
const void *const  data 
)

Low-level function to set an attribute. If data_length is zero the attribute is removed.

Definition at line 384 of file attribute.c.

Referenced by attr_city_set(), attr_player_set(), attr_tile_set(), and attr_unit_set().

◆ serialize_hash()

static enum attribute_serial serialize_hash ( const struct attribute_hash hash,
void **  pdata,
int pdata_length 
)
static

Serialize an attribute hash for network/storage.

Definition at line 134 of file attribute.c.

Referenced by attribute_flush().

◆ unserialize_hash()

static enum attribute_serial unserialize_hash ( struct attribute_hash hash,
const void data,
size_t  data_length 
)
static

This data was serialized (above), sent as an opaque data packet to the server, stored in a savegame, retrieved from the savegame, sent as an opaque data packet back to the client, and now is ready to be restored. Check everything!

Definition at line 230 of file attribute.c.

Referenced by attribute_restore().

Variable Documentation

◆ attribute_hash

struct attribute_hash* attribute_hash = NULL
static