gamedata.c File Reference

#include "race.h"
#include <stdio.h>
#include "gamedata.h"
#include "int_types.h"

Go to the source code of this file.

Defines

#define DECL_FREAD(struct, type, bufelems)
#define DECL_FWRITE(struct, type, bufelems)
#define DECL_GET_END   }
#define DECL_GET_FIELD_SCALAR(type, name, num)
#define DECL_GET_FIELD_STRUCT(str, type, name, num)
#define DECL_GET_START(struct, type)
#define DECL_PUT_END   }
#define DECL_PUT_FIELD_SCALAR(type, name, num)
#define DECL_PUT_FIELD_STRUCT(str, type, name, num)
#define DECL_PUT_START(struct, type)
#define DECL_SIGNED_GET(bits)
#define DECL_SIGNED_PUT(bits)
#define DECL_UNSIGNED_GET(bits, from)
#define DECL_UNSIGNED_PUT(bits, from)
#define DECL_xINT_FREAD(bits, sign)
#define DECL_xINT_FWRITE(bits, sign)
#define get_char   (char)get_uint8_t
#define put_char   (char)get_uint8_t
#define sizeof_char   (sizeof(char))
#define sizeof_int16_t   (sizeof(int16_t))
#define sizeof_int32_t   (sizeof(int32_t))
#define sizeof_int8_t   (sizeof(int8_t))
#define sizeof_uint16_t   (sizeof(uint16_t))
#define sizeof_uint32_t   (sizeof(uint32_t))
#define sizeof_uint8_t   (sizeof(uint8_t))

Functions

static uint8_t get_uint8_t (const void *buf)
static void put_uint8_t (void *buf, uint8_t v)


Define Documentation

#define DECL_FREAD ( struct,
type,
bufelems   ) 

Value:

size_t \
fread_##type(struct type *dst, size_t num, FILE *f) \
{ \
    uint8_t tmp[(bufelems)*sizeof_##type]; \
    int i = 0, total = 0, elems = 0; \
    while (num > 0) \
    { \
        elems = (num < (bufelems)) ? num : (bufelems); \
        elems = fread(tmp, sizeof_##type, elems, f); \
        if (!elems) \
            break; \
        for (i = 0; i < elems; ++i) \
            get_##type(dst++, tmp+i*sizeof_##type); \
        total += elems; \
        num -= elems; \
    } \
    return total; \
} \

#define DECL_FWRITE ( struct,
type,
bufelems   ) 

Value:

size_t \
fwrite_##type(const struct type *src, size_t num, FILE *f) \
{ \
    uint8_t tmp[(bufelems)*sizeof_##type]; \
    int i = 0, total = 0, elems = 0; \
    while (num > 0) \
    { \
        elems = (num < (bufelems)) ? num : (bufelems); \
        for (i = 0; i < elems; ++i) \
            put_##type(tmp+i*sizeof_##type, src++); \
        elems = fwrite(tmp, sizeof_##type, elems, f); \
        if (!elems) \
            break; \
        total += elems; \
        num -= elems; \
    } \
    return total; \
} \

#define DECL_GET_END   }

#define DECL_GET_FIELD_SCALAR ( type,
name,
num   ) 

Value:

for (i = 0; i < (num); ++i) \
    { \
        *(((type *)&dst->name)+i) = get_##type(src); \
        src += sizeof_##type; \
    } \

#define DECL_GET_FIELD_STRUCT ( str,
type,
name,
num   ) 

Value:

for (i = 0; i < (num); ++i) \
    { \
        get_##type((((str type *)&dst->name)+i), src); \
        src += sizeof_##type; \
    } \

#define DECL_GET_START ( struct,
type   ) 

Value:

static inline void \
get_##type (struct type *dst, const uint8_t *src) \
{ \
    int i = 0; \

#define DECL_PUT_END   }

#define DECL_PUT_FIELD_SCALAR ( type,
name,
num   ) 

Value:

for (i = 0; i < (num); ++i) \
    { \
        put_##type(dst, *(((type *)&src->name)+i)); \
        dst += sizeof_##type; \
    } \

#define DECL_PUT_FIELD_STRUCT ( str,
type,
name,
num   ) 

Value:

for (i = 0; i < (num); ++i) \
    { \
        put_##type(dst, ((str type *)(&src->name))+i); \
        dst += sizeof_##type; \
    } \

#define DECL_PUT_START ( struct,
type   ) 

Value:

static inline void \
put_##type (uint8_t *dst, const struct type *src) \
{ \
    int i = 0; \

#define DECL_SIGNED_GET ( bits   ) 

Value:

static inline int ## bits ## _t \
    get_int ## bits ##_t (const void *buf) \
    { \
        return (int ## bits ## _t) get_uint ## bits ##_t (buf);  \
    } \

Definition at line 34 of file gamedata.c.

#define DECL_SIGNED_PUT ( bits   ) 

Value:

static inline void \
    put_int ## bits ##_t (void *buf, int##bits##_t v) \
    { \
        put_uint ## bits ## _t (buf, (uint##bits##_t)v); \
    } \

Definition at line 63 of file gamedata.c.

#define DECL_UNSIGNED_GET ( bits,
from   ) 

Value:

static inline uint ## bits ## _t \
    get_uint ## bits ##_t (const void *buf) \
    { \
        return get_uint ## from ##_t (buf) \
        | (get_uint ## from##_t ((const char*)buf + (from)/8) << (from)); \
    } \

Definition at line 26 of file gamedata.c.

#define DECL_UNSIGNED_PUT ( bits,
from   ) 

Value:

static inline void \
    put_uint ## bits ## _t (void *buf, uint ## bits ## _t v) \
    { \
        put_uint ## from ##_t (buf, (v & ((1 << (from))-1))); \
        put_uint ## from ##_t ((char*)buf + (from)/8, \
                (v >> (from)) & ((1L << (from))-1)); \
    } \

Definition at line 54 of file gamedata.c.

#define DECL_xINT_FREAD ( bits,
sign   ) 

Value:

size_t fread_##sign##int##bits##_t \
        (sign##int##bits##_t *p, size_t n, FILE *f) { \
        int i = 0; int elems = 0; \
        elems = fread (p, (bits)/8, n, f); \
        for (i = 0; i < elems; ++i, ++p) { \
            *p = get_##sign##int##bits##_t(p); \
        } \
        return elems; \
    } \

Definition at line 76 of file gamedata.c.

#define DECL_xINT_FWRITE ( bits,
sign   ) 

Value:

size_t fwrite_##sign##int##bits##_t \
        (const sign##int##bits##_t *p, size_t n, FILE *f) { \
        sign##int##bits##_t t[256]; \
        int i = 0, elems = 0, total = 0; \
        while (n > 0) { \
            elems = (n < 256) ? n : 256; \
            for (i = 0; i < elems; ++i, ++p) \
                put_##sign##int##bits##_t(t+i, *p); \
            elems = fwrite(t, (bits)/8, elems, f); \
            if (!elems) break; \
            n -= elems; \
            total += elems; \
        } \
        return total; \
    } \

Definition at line 87 of file gamedata.c.

#define get_char   (char)get_uint8_t

Definition at line 17 of file gamedata.c.

#define put_char   (char)get_uint8_t

Definition at line 18 of file gamedata.c.

#define sizeof_char   (sizeof(char))

Definition at line 8 of file gamedata.c.

#define sizeof_int16_t   (sizeof(int16_t))

Definition at line 10 of file gamedata.c.

#define sizeof_int32_t   (sizeof(int32_t))

Definition at line 11 of file gamedata.c.

#define sizeof_int8_t   (sizeof(int8_t))

Definition at line 9 of file gamedata.c.

#define sizeof_uint16_t   (sizeof(uint16_t))

Definition at line 13 of file gamedata.c.

#define sizeof_uint32_t   (sizeof(uint32_t))

Definition at line 14 of file gamedata.c.

#define sizeof_uint8_t   (sizeof(uint8_t))

Definition at line 12 of file gamedata.c.


Function Documentation

static uint8_t get_uint8_t ( const void buf  )  [inline, static]

Definition at line 21 of file gamedata.c.

static void put_uint8_t ( void buf,
uint8_t  v 
) [inline, static]

Definition at line 48 of file gamedata.c.


Generated on Fri Sep 28 00:35:46 2007 for raceintospace by  doxygen 1.5.3