Micropolis
fileio.cpp File Reference

File I/O operations for Micropolis game engine. More...

#include "micropolis.h"

Go to the source code of this file.

Macros

#define SWAP_SHORTS(buf, len)   swap_shorts(buf, len)
 
#define HALF_SWAP_LONGS(buf, len)   half_swap_longs(buf, len)
 

Functions

static void swap_shorts (short *buf, int len)
 
static void half_swap_longs (long *buf, int len)
 
static bool load_short (short *buf, int len, FILE *f)
 
static bool save_short (short *buf, int len, FILE *f)
 

Detailed Description

File I/O operations for Micropolis game engine.

Implements file loading and saving functionalities for the Micropolis game engine. It includes endianess conversions for data compatibility between different architectures, loading and saving city files, handling scenario files, and various utility functions to support file I/O operations. It also includes functions to report file operations to the front-end.

Definition in file fileio.cpp.

Macro Definition Documentation

◆ HALF_SWAP_LONGS

#define HALF_SWAP_LONGS (   buf,
  len 
)    half_swap_longs(buf, len)

Convert an array of long values between MAC and Intel endian formats.

Parameters
bufArray with longs.
lenNumber of long values in the array.

Definition at line 99 of file fileio.cpp.

◆ SWAP_SHORTS

#define SWAP_SHORTS (   buf,
  len 
)    swap_shorts(buf, len)

Convert an array of short values between MAC and Intel endian formats.

Parameters
bufArray with shorts.
lenNumber of short values in the array.

Definition at line 92 of file fileio.cpp.

Function Documentation

◆ half_swap_longs()

static void half_swap_longs ( long *  buf,
int  len 
)
static

Swap upper and lower words of all longs in the array.

Parameters
bufArray with longs.
lenNumber of long values in the array.

Definition at line 123 of file fileio.cpp.

◆ load_short()

static bool load_short ( short *  buf,
int  len,
FILE *  f 
)
static

Load an array of short values from file to memory.

Convert to the correct processor architecture, if necessary.

Parameters
bufBuffer to put the loaded short values in.
lenNumber of short values to load.
fFile handle of the file to load from.
Returns
Load was succesfull.

Definition at line 171 of file fileio.cpp.

References SWAP_SHORTS.

Referenced by Micropolis::loadFileData().

◆ save_short()

static bool save_short ( short *  buf,
int  len,
FILE *  f 
)
static

Save an array of short values from memory to file.

Convert to the correct endianness first, if necessary.

Parameters
bufBuffer containing the short values to save.
lenNumber of short values to save.
fFile handle of the file to save to.
Returns
Save was succesfull.

Definition at line 194 of file fileio.cpp.

References SWAP_SHORTS.

Referenced by Micropolis::saveFile().

◆ swap_shorts()

static void swap_shorts ( short *  buf,
int  len 
)
static

Swap upper and lower byte of all shorts in the array.

Parameters
bufArray with shorts.
lenNumber of short values in the array.

Definition at line 106 of file fileio.cpp.