Few more compilation issues
This commit is contained in:
parent
efff1cd235
commit
450a83a4dd
@ -35,8 +35,9 @@
|
||||
|
||||
|
||||
WD = ${shell pwd}
|
||||
APPDIR = $(WD)/../../..
|
||||
APPDIR = $(WD)/../../../..
|
||||
TRAVELER = $(WD)/../..
|
||||
NUTTXDIR = $(WD)/../include
|
||||
|
||||
BIN = libwld.a
|
||||
WLDSRCS = wld_createworld.c wld_deallocateworld.c
|
||||
@ -59,7 +60,7 @@ AR = ar -rcv
|
||||
|
||||
DEBUG_LEVEL = 0
|
||||
DEFINES = -DDEBUG_LEVEL=$(DEBUG_LEVEL)
|
||||
INCLUDES = -I. -I$(APPDIR)/include -I$(TRAVELER)/include
|
||||
INCLUDES = -I. -I$(APPDIR)/include -I$(TRAVELER)/include -isystem $(NUTTXDIR)
|
||||
WARNINGS = -Wall -Wstrict-prototypes -Wshadow -Wno-trigraphs
|
||||
|
||||
ifneq ($(DEBUG_LEVEL),0)
|
||||
|
@ -49,15 +49,15 @@
|
||||
*************************************************************************/
|
||||
|
||||
static uint8_t wld_ManageWorldFile(void);
|
||||
static uint8_t wld_ReadIniShortInteger(int16_t *variableValue,
|
||||
static uint8_t wld_read_shortint(int16_t *variableValue,
|
||||
const char *sectionName,
|
||||
const char *variableName);
|
||||
#if 0 /* Not used */
|
||||
static uint8_t wld_ReadIniLongInteger(long *variableValue,
|
||||
const char *sectionName,
|
||||
const char *variableName);
|
||||
static uint8_t wld_read_longint(long *variableValue,
|
||||
const char *sectionName,
|
||||
const char *variableName);
|
||||
#endif
|
||||
static uint8_t wld_ReadIniFileName(char **fileName,
|
||||
static uint8_t wld_read_filename(char **fileName,
|
||||
const char *sectionName,
|
||||
const char *variableName);
|
||||
|
||||
@ -105,11 +105,233 @@ static const char worldPaletteName[] = WORLD_PALETTE;
|
||||
static const char worldImagesName[] = WORLD_IMAGES;
|
||||
|
||||
/*************************************************************************
|
||||
* Private Variables
|
||||
* Private Functions
|
||||
*************************************************************************/
|
||||
|
||||
/*************************************************************************
|
||||
* Name: wld_create_world
|
||||
* Name: wld_ManageWorldFile
|
||||
* Description: This is the guts of wld_create_world. It is implemented as
|
||||
* a separate file to simplify error handling
|
||||
************************************************************************/
|
||||
|
||||
static uint8_t wld_ManageWorldFile(void)
|
||||
{
|
||||
char *fileName;
|
||||
uint8_t result;
|
||||
|
||||
/* Read the initial camera/player position */
|
||||
|
||||
result = wld_read_shortint(&initialCamera.x,
|
||||
cameraSectionName,
|
||||
cameraInitialXName);
|
||||
if (result != 0) return result;
|
||||
|
||||
result = wld_read_shortint(&initialCamera.y,
|
||||
cameraSectionName,
|
||||
cameraInitialYName);
|
||||
if (result != 0) return result;
|
||||
|
||||
result = wld_read_shortint(&initialCamera.z,
|
||||
cameraSectionName,
|
||||
cameraInitialZName);
|
||||
if (result != 0) return result;
|
||||
|
||||
/* Get the player's yaw/pitch orientation */
|
||||
|
||||
result = wld_read_shortint(&initialCamera.yaw,
|
||||
cameraSectionName,
|
||||
cameraInitialYawName);
|
||||
if (result != 0) return result;
|
||||
|
||||
result = wld_read_shortint(&initialCamera.pitch,
|
||||
cameraSectionName,
|
||||
cameraInitialPitchName);
|
||||
if (result != 0) return result;
|
||||
|
||||
/* Get the height of the player */
|
||||
|
||||
result = wld_read_shortint(&playerHeight,
|
||||
playerSectionName,
|
||||
playerHeightName);
|
||||
if (result != 0) return result;
|
||||
|
||||
/* Read the player's capability to step on top of things in the world. */
|
||||
|
||||
result = wld_read_shortint(&walkStepHeight,
|
||||
playerSectionName,
|
||||
playerWalkStepHeightName);
|
||||
if (result != 0) return result;
|
||||
|
||||
result = wld_read_shortint(&runStepHeight,
|
||||
playerSectionName,
|
||||
playerRunStepHeightName);
|
||||
if (result != 0) return result;
|
||||
|
||||
/* Get the name of the file containing the world map */
|
||||
|
||||
result = wld_read_filename(&fileName, worldSectionName, worldMapName);
|
||||
if (result != 0) return result;
|
||||
if (fileName == NULL) return WORLD_PLANE_FILE_NAME_ERROR;
|
||||
|
||||
/* Allocate and load the world */
|
||||
|
||||
result = wld_initialize_planes();
|
||||
if (result != 0) return result;
|
||||
|
||||
result = wld_load_planefile(fileName);
|
||||
if (result != 0) return result;
|
||||
|
||||
inifile_free_string(fileName);
|
||||
|
||||
/* Get the name of the file containing the palette table which is used
|
||||
* to adjust the lighting with distance.
|
||||
*/
|
||||
|
||||
result = wld_read_filename(&fileName, worldSectionName, worldPaletteName);
|
||||
if (result != 0) return result;
|
||||
if (fileName == NULL) return WORLD_PALR_FILE_NAME_ERROR;
|
||||
|
||||
/* Then load it into palTable. */
|
||||
|
||||
result = wld_load_paltable(fileName);
|
||||
if (result != 0) return result;
|
||||
|
||||
inifile_free_string(fileName);
|
||||
|
||||
/* Get the name of the file containing the texture data */
|
||||
|
||||
result = wld_read_filename(&fileName, worldSectionName, worldImagesName);
|
||||
if (result != 0) return result;
|
||||
if (fileName == NULL) return WORLD_BITMAP_FILE_NAME_ERROR;
|
||||
|
||||
/* Then load the bitmaps */
|
||||
|
||||
result = wld_initialize_bitmaps();
|
||||
if (result != 0) return result;
|
||||
|
||||
result = wld_load_bitmapfile(fileName);
|
||||
inifile_free_string(fileName);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
* Name: wld_read_shortint
|
||||
* Description: Reads a long value from the INI file and assures that
|
||||
* it is within range for an a int16_t
|
||||
************************************************************************/
|
||||
|
||||
static uint8_t wld_read_shortint(int16_t *variableValue,
|
||||
const char *sectionName,
|
||||
const char *variableName)
|
||||
{
|
||||
/* Read the long integer from the ini file. We supply the default
|
||||
* value of INT32_MAX. If this value is returned, we assume that
|
||||
* that is evidence that the requested value was not supplied in the
|
||||
* ini file.
|
||||
*/
|
||||
|
||||
long value = inifile_read_integer(sectionName, variableName,
|
||||
INT32_MAX);
|
||||
|
||||
/* Make sure that it is in range for a int16_t . */
|
||||
|
||||
if ((value < INT16_MIN) || (value > INT16_MAX))
|
||||
{
|
||||
/* It is not!... */
|
||||
|
||||
*variableValue = 0;
|
||||
|
||||
/* Is this because the integer was not found? or because
|
||||
* it is really out of range.
|
||||
*/
|
||||
|
||||
if (value != INT32_MAX)
|
||||
{
|
||||
|
||||
fprintf(stderr, "Error: Integer out of range in INI file:\n");
|
||||
fprintf(stderr, " Section=\"%s\" Variable name=\"%s\" value=%ld\n",
|
||||
sectionName, variableName, (long)variableValue);
|
||||
return WORLD_INTEGER_OUT_OF_RANGE;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
fprintf(stderr, "Error: Requird integer not found in INI file:\n");
|
||||
fprintf(stderr, " Section=\"%s\" Variable name=\"%s\"\n",
|
||||
sectionName, variableName);
|
||||
return WORLD_INTEGER_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
*variableValue = (int16_t )value;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
* Name: wld_read_shortint
|
||||
* Description: Reads a long value from the INI file
|
||||
************************************************************************/
|
||||
|
||||
#if 0 /* Not used */
|
||||
static uint8_t wld_read_longint(long *variableValue,
|
||||
const char *sectionName,
|
||||
const char *variableName)
|
||||
{
|
||||
/* Read the long integer from the ini file.*/
|
||||
|
||||
*variableValue = inifile_read_integer(sectionName, variableName, 0);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*************************************************************************
|
||||
* Name: wld_read_shortint
|
||||
* Description: Reads a file name from the the INI file.
|
||||
************************************************************************/
|
||||
|
||||
static uint8_t wld_read_filename(char **fileName,
|
||||
const char *sectionName,
|
||||
const char *variableName)
|
||||
{
|
||||
/* Read the string from the ini file. We supply the default
|
||||
* value of NULL. If this value is returned, we assume that
|
||||
* that is evidence that the requested value was not supplied in the
|
||||
* ini file.
|
||||
*/
|
||||
|
||||
char *value = inifile_read_string(sectionName, variableName, NULL);
|
||||
|
||||
/* Did we get the file name? */
|
||||
|
||||
if (!value)
|
||||
{
|
||||
/* No... */
|
||||
|
||||
*fileName = NULL;
|
||||
|
||||
fprintf(stderr, "Error: Required filename not found in INI file:\n");
|
||||
fprintf(stderr, " Section=\"%s\" Variable name=\"%s\"\n",
|
||||
sectionName, variableName);
|
||||
return WORLD_FILENAME_NOT_FOUND;
|
||||
}
|
||||
else
|
||||
{
|
||||
*fileName = value;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
* Private Functions
|
||||
*************************************************************************/
|
||||
|
||||
/*************************************************************************
|
||||
* Name: wld_create_world
|
||||
* Description:
|
||||
************************************************************************/
|
||||
|
||||
@ -138,221 +360,3 @@ uint8_t wld_create_world(char *wldFile)
|
||||
inifile_uninitialize(handle);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
* Name: wld_ManageWorldFile
|
||||
* Description: This is the guts of wld_create_world. It is implemented as
|
||||
* a separate file to simplify error handling
|
||||
************************************************************************/
|
||||
|
||||
static uint8_t wld_ManageWorldFile(void)
|
||||
{
|
||||
char *fileName;
|
||||
uint8_t result;
|
||||
|
||||
/* Read the initial camera/player position */
|
||||
|
||||
result = wld_ReadIniShortInteger(&initialCamera.x,
|
||||
cameraSectionName,
|
||||
cameraInitialXName);
|
||||
if (result != 0) return result;
|
||||
|
||||
result = wld_ReadIniShortInteger(&initialCamera.y,
|
||||
cameraSectionName,
|
||||
cameraInitialYName);
|
||||
if (result != 0) return result;
|
||||
|
||||
result = wld_ReadIniShortInteger(&initialCamera.z,
|
||||
cameraSectionName,
|
||||
cameraInitialZName);
|
||||
if (result != 0) return result;
|
||||
|
||||
/* Get the player's yaw/pitch orientation */
|
||||
|
||||
result = wld_ReadIniShortInteger(&initialCamera.yaw,
|
||||
cameraSectionName,
|
||||
cameraInitialYawName);
|
||||
if (result != 0) return result;
|
||||
|
||||
result = wld_ReadIniShortInteger(&initialCamera.pitch,
|
||||
cameraSectionName,
|
||||
cameraInitialPitchName);
|
||||
if (result != 0) return result;
|
||||
|
||||
/* Get the height of the player */
|
||||
|
||||
result = wld_ReadIniShortInteger(&playerHeight,
|
||||
playerSectionName,
|
||||
playerHeightName);
|
||||
if (result != 0) return result;
|
||||
|
||||
/* Read the player's capability to step on top of things in the world. */
|
||||
|
||||
result = wld_ReadIniShortInteger(&walkStepHeight,
|
||||
playerSectionName,
|
||||
playerWalkStepHeightName);
|
||||
if (result != 0) return result;
|
||||
|
||||
result = wld_ReadIniShortInteger(&runStepHeight,
|
||||
playerSectionName,
|
||||
playerRunStepHeightName);
|
||||
if (result != 0) return result;
|
||||
|
||||
/* Get the name of the file containing the world map */
|
||||
|
||||
result = wld_ReadIniFileName(&fileName, worldSectionName, worldMapName);
|
||||
if (result != 0) return result;
|
||||
if (fileName == NULL) return WORLD_PLANE_FILE_NAME_ERROR;
|
||||
|
||||
/* Allocate and load the world */
|
||||
|
||||
result = wld_initialize_planes();
|
||||
if (result != 0) return result;
|
||||
|
||||
result = wld_load_planefile(fileName);
|
||||
if (result != 0) return result;
|
||||
|
||||
inifile_free_string(fileName);
|
||||
|
||||
/* Get the name of the file containing the palette table which is used
|
||||
* to adjust the lighting with distance.
|
||||
*/
|
||||
|
||||
result = wld_ReadIniFileName(&fileName, worldSectionName, worldPaletteName);
|
||||
if (result != 0) return result;
|
||||
if (fileName == NULL) return WORLD_PALR_FILE_NAME_ERROR;
|
||||
|
||||
/* Then load it into palTable. */
|
||||
|
||||
result = wld_load_paltable(fileName);
|
||||
if (result != 0) return result;
|
||||
|
||||
inifile_free_string(fileName);
|
||||
|
||||
/* Get the name of the file containing the texture data */
|
||||
|
||||
result = wld_ReadIniFileName(&fileName, worldSectionName, worldImagesName);
|
||||
if (result != 0) return result;
|
||||
if (fileName == NULL) return WORLD_BITMAP_FILE_NAME_ERROR;
|
||||
|
||||
/* Then load the bitmaps */
|
||||
|
||||
result = wld_initialize_bitmaps();
|
||||
if (result != 0) return result;
|
||||
|
||||
result = wld_load_bitmapfile(fileName);
|
||||
inifile_free_string(fileName);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
* Name: wld_ReadIniShortInteger
|
||||
* Description: Reads a long value from the INI file and assures that
|
||||
* it is within range for an a int16_t
|
||||
************************************************************************/
|
||||
|
||||
static uint8_t wld_ReadIniShortInteger(int16_t *variableValue,
|
||||
const char *sectionName,
|
||||
const char *variableName)
|
||||
{
|
||||
/* Read the long integer from the ini file. We supply the default
|
||||
* value of MAX_SINT32. If this value is returned, we assume that
|
||||
* that is evidence that the requested value was not supplied in the
|
||||
* ini file.
|
||||
*/
|
||||
|
||||
long value = ini_read_integer(sectionName, variableName,
|
||||
MAX_SINT32);
|
||||
|
||||
/* Make sure that it is in range for a int16_t . */
|
||||
|
||||
if ((value < MIN_SINT16) || (value > MAX_SINT16))
|
||||
{
|
||||
/* It is not!... */
|
||||
|
||||
*variableValue = 0;
|
||||
|
||||
/* Is this because the integer was not found? or because
|
||||
* it is really out of range.
|
||||
*/
|
||||
|
||||
if (value != MAX_SINT32)
|
||||
{
|
||||
|
||||
fprintf(stderr, "Error: Integer out of range in INI file:\n");
|
||||
fprintf(stderr, " Section=\"%s\" Variable name=\"%s\" value=%ld\n",
|
||||
sectionName, variableName, (long)variableValue);
|
||||
return WORLD_INTEGER_OUT_OF_RANGE;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
fprintf(stderr, "Error: Requird integer not found in INI file:\n");
|
||||
fprintf(stderr, " Section=\"%s\" Variable name=\"%s\"\n",
|
||||
sectionName, variableName);
|
||||
return WORLD_INTEGER_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
*variableValue = (int16_t )value;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
* Name: wld_ReadIniShortInteger
|
||||
* Description: Reads a long value from the INI file
|
||||
************************************************************************/
|
||||
|
||||
#if 0 /* Not used */
|
||||
static uint8_t wld_ReadIniLongInteger(long *variableValue,
|
||||
const char *sectionName,
|
||||
const char *variableName)
|
||||
{
|
||||
/* Read the long integer from the ini file.*/
|
||||
|
||||
*variableValue = ini_read_integer(sectionName, variableName, 0);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*************************************************************************
|
||||
* Name: wld_ReadIniShortInteger
|
||||
* Description: Reads a file name from the the INI file.
|
||||
************************************************************************/
|
||||
|
||||
static uint8_t wld_ReadIniFileName(char **fileName,
|
||||
const char *sectionName,
|
||||
const char *variableName)
|
||||
{
|
||||
/* Read the string from the ini file. We supply the default
|
||||
* value of NULL. If this value is returned, we assume that
|
||||
* that is evidence that the requested value was not supplied in the
|
||||
* ini file.
|
||||
*/
|
||||
|
||||
char *value = ini_read_string(sectionName, variableName, NULL);
|
||||
|
||||
/* Did we get the file name? */
|
||||
|
||||
if (!value)
|
||||
{
|
||||
/* No... */
|
||||
|
||||
*fileName = NULL;
|
||||
|
||||
fprintf(stderr, "Error: Required filename not found in INI file:\n");
|
||||
fprintf(stderr, " Section=\"%s\" Variable name=\"%s\"\n",
|
||||
sectionName, variableName);
|
||||
return WORLD_FILENAME_NOT_FOUND;
|
||||
}
|
||||
else
|
||||
{
|
||||
*fileName = value;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@
|
||||
*************************************************************************/
|
||||
|
||||
/*************************************************************************
|
||||
* Name:
|
||||
* Name: wld_graphicfile_pixel
|
||||
* Description:
|
||||
************************************************************************/
|
||||
|
||||
|
@ -38,7 +38,9 @@
|
||||
* Included files
|
||||
*************************************************************************/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "trv_types.h"
|
||||
#include "wld_mem.h"
|
||||
#include "wld_world.h"
|
||||
@ -53,12 +55,75 @@
|
||||
*************************************************************************/
|
||||
|
||||
/*************************************************************************
|
||||
* Name: wld_LoadBitmaps
|
||||
* Name: wld_read_filename
|
||||
* Description:
|
||||
* Read a file name from the input stream
|
||||
************************************************************************/
|
||||
|
||||
static bool wld_read_filename(FILE *fp, char *fileName)
|
||||
{
|
||||
int16_t nbytes;
|
||||
int ch;
|
||||
|
||||
/* Skip over any leading spaces, new lines, or carriage returns (for
|
||||
* MSDOS compatibility)
|
||||
*/
|
||||
|
||||
do
|
||||
{
|
||||
ch = getc(fp);
|
||||
if (ch == EOF) return false;
|
||||
}
|
||||
while ((ch == ' ') || (ch == '\n') || (ch == '\r'));
|
||||
|
||||
/* Get the file name from the file */
|
||||
|
||||
nbytes = 0;
|
||||
for (;;)
|
||||
{
|
||||
/* Everything up to the next newline or space must be the filename */
|
||||
|
||||
if ((ch != '\n') && (ch != ' ') && (ch != '\r'))
|
||||
{
|
||||
/* Make sure that the file name is not too large */
|
||||
|
||||
if (nbytes >= FILE_NAME_SIZE) return false;
|
||||
|
||||
/* Add the new character to the file name */
|
||||
|
||||
fileName[nbytes] = (char)ch;
|
||||
nbytes++;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* End of the file name -- Don't forget the ASCIIZ terminator */
|
||||
|
||||
fileName[nbytes] = '\0';
|
||||
break;
|
||||
}
|
||||
|
||||
/* Get the character for the next time through the loop. Every file
|
||||
* name should be terminated with a space or a new line. EOF is
|
||||
* unexpected in this context.
|
||||
*/
|
||||
|
||||
ch = getc(fp);
|
||||
if (ch == EOF)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
* Name: wld_load_bitmaps
|
||||
* Description:
|
||||
* This function loads the world data from the input file
|
||||
************************************************************************/
|
||||
|
||||
static uint8_t wld_LoadBitmaps(FILE *fp)
|
||||
static uint8_t wld_load_bitmaps(FILE *fp)
|
||||
{
|
||||
#if MSWINDOWS
|
||||
volatile pcxPicture workPCX;
|
||||
@ -100,7 +165,7 @@ static uint8_t wld_LoadBitmaps(FILE *fp)
|
||||
/* Load the even bitmap */
|
||||
/* Get the name of the file which contains the even bitmap */
|
||||
|
||||
if (!wld_ReadFileName(fp, graphicsFileName))
|
||||
if (!wld_read_filename(fp, graphicsFileName))
|
||||
return BMAP_BML_READ_ERROR;
|
||||
|
||||
#if MSWINDOWS
|
||||
@ -135,7 +200,7 @@ static uint8_t wld_LoadBitmaps(FILE *fp)
|
||||
/* Load the odd bitmap */
|
||||
/* Get the name of the file which contains the odd bitmap */
|
||||
|
||||
if (!wld_ReadFileName(fp, graphicsFileName))
|
||||
if (!wld_read_filename(fp, graphicsFileName))
|
||||
return BMAP_BML_READ_ERROR;
|
||||
|
||||
#ifndef WEDIT
|
||||
@ -165,67 +230,6 @@ static uint8_t wld_LoadBitmaps(FILE *fp)
|
||||
return result;
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
* Name: wld_ReadFileName
|
||||
* Description:
|
||||
* Read a file name from the input stream
|
||||
************************************************************************/
|
||||
|
||||
static boolean wld_ReadFileName(FILE *fp, char *fileName)
|
||||
{
|
||||
int16_t numBytes;
|
||||
int ch;
|
||||
|
||||
/* Skip over any leading spaces, new lines, or carriage returns (for
|
||||
* MSDOS compatibility)
|
||||
*/
|
||||
|
||||
do
|
||||
{
|
||||
ch = getc(fp);
|
||||
if (ch == EOF) return false;
|
||||
}
|
||||
while ((ch == ' ') || (ch == '\n') || (ch == '\r'));
|
||||
|
||||
/* Get the file name from the file */
|
||||
|
||||
numBytes = 0;
|
||||
for (;;)
|
||||
{
|
||||
/* Everything up to the next newline or space must be the filename */
|
||||
|
||||
if ((ch != '\n') && (ch != ' ') && (ch != '\r'))
|
||||
{
|
||||
/* Make sure that the file name is not too large */
|
||||
|
||||
if (numBytes >= FILE_NAME_SIZE) return false;
|
||||
|
||||
/* Add the new character to the file name */
|
||||
|
||||
fileName[numBytes] = (char)ch;
|
||||
numBytes++;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* End of the file name -- Don't forget the ASCIIZ terminator */
|
||||
|
||||
fileName[numBytes] = '\0';
|
||||
break;
|
||||
}
|
||||
|
||||
/* Get the character for the next time through the loop. Every file
|
||||
* name should be terminated with a space or a new line. EOF is
|
||||
* unexpected in this context.
|
||||
*/
|
||||
|
||||
ch = getc(fp);
|
||||
if (ch == EOF) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* Public Functions
|
||||
*************************************************************************/
|
||||
@ -248,7 +252,7 @@ uint8_t wld_load_bitmapfile(char *bmlFile)
|
||||
|
||||
/* Load all of the bitmaps */
|
||||
|
||||
result = wld_LoadBitmaps(fp);
|
||||
result = wld_load_bitmaps(fp);
|
||||
if (result) wld_discard_bitmaps();
|
||||
|
||||
/* We are all done with the file, so close it */
|
||||
|
@ -37,6 +37,7 @@
|
||||
* Included files
|
||||
*************************************************************************/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -89,8 +90,8 @@ int BitOffset = 0, /* Bit Offset of next code */
|
||||
BitMask, /* AND mask for data size */
|
||||
ReadMask; /* Code AND mask for current code size */
|
||||
|
||||
boolean Interlace, HasColormap;
|
||||
boolean Verbose = true;
|
||||
bool Interlace, HasColormap;
|
||||
bool Verbose = true;
|
||||
|
||||
uint8_t *Image; /* The result array */
|
||||
uint8_t *RawGIF; /* The heap array to hold it, raw */
|
||||
|
@ -101,7 +101,7 @@ trv_pixel_t *palTable[NUM_ZONES];
|
||||
* Description:
|
||||
************************************************************************/
|
||||
|
||||
static void wld_AllocatePalTable(uint32 palTabEntrySize)
|
||||
static void wld_AllocatePalTable(uint32_t palTabEntrySize)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
@ -69,7 +69,7 @@
|
||||
*************************************************************************/
|
||||
|
||||
static void wld_loadpcxHeader(FILE *fp, pcxHeader *header);
|
||||
static void wld_loadpcxData(FILE *fp, sint32 imagSize, uint8_t *imageBuffer);
|
||||
static void wld_loadpcxData(FILE *fp, int32_t imagSize, uint8_t *imageBuffer);
|
||||
static void wld_loadpcxPalette(FILE *fp, RGBColor *palette);
|
||||
|
||||
/*************************************************************************
|
||||
@ -94,7 +94,7 @@ uint8_t wld_loadpcx(char *filename, pcxPicturePtr image)
|
||||
{
|
||||
FILE *fp, *fopen();
|
||||
uint16_t imageWidth, imageHeight;
|
||||
uint32 imageSize;
|
||||
uint32_t imageSize;
|
||||
|
||||
/* Open the file */
|
||||
|
||||
@ -133,7 +133,7 @@ GraphicFileType *wld_loadpcx(FILE *fp, char *filename)
|
||||
GraphicFileType *gFile;
|
||||
RGBColor *palette;
|
||||
uint16_t imageWidth, imageHeight;
|
||||
uint32 imageSize;
|
||||
uint32_t imageSize;
|
||||
|
||||
/* Load the PCX Header */
|
||||
|
||||
@ -196,9 +196,9 @@ static void wld_loadpcxHeader(FILE *fp, pcxHeader *header)
|
||||
* Description:
|
||||
************************************************************************/
|
||||
|
||||
static void wld_loadpcxData(FILE *fp, sint32 imageSize, uint8_t *imageBuffer)
|
||||
static void wld_loadpcxData(FILE *fp, int32_t imageSize, uint8_t *imageBuffer)
|
||||
{
|
||||
uint32 count;
|
||||
uint32_t count;
|
||||
int16_t numBytes;
|
||||
uint8_t data;
|
||||
|
||||
|
@ -37,7 +37,9 @@
|
||||
* Included files
|
||||
*************************************************************************/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "trv_types.h"
|
||||
#include "wld_utils.h"
|
||||
|
||||
@ -54,7 +56,7 @@
|
||||
int16_t wld_read_decimal(FILE *fp)
|
||||
{
|
||||
int16_t value = 0;
|
||||
boolean negative = false;
|
||||
bool negative = false;
|
||||
int ch;
|
||||
|
||||
/* Skip over any leading spaces, new lines, or carriage returns (for
|
||||
|
@ -62,29 +62,6 @@
|
||||
* Private Functions
|
||||
*************************************************************************/
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* Name: wld_NewTexture
|
||||
* Description:
|
||||
************************************************************************/
|
||||
|
||||
static bitmapType *wld_NewTexture(uint16_t width, uint16_t height)
|
||||
{
|
||||
bitmapType *t;
|
||||
|
||||
if (height <= 0 || width <= 0)
|
||||
wld_fatal_error("wld_NewTexture: bad texture dimensions");
|
||||
|
||||
t = (bitmapType*)wld_malloc(sizeof(bitmapType));
|
||||
t->bm = (trv_pixel_t*)wld_malloc(height * width * sizeof(trv_pixel_t));
|
||||
|
||||
t->w = width;
|
||||
t->h = height;
|
||||
t->log2h = wld_Log2(height);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
* Name:
|
||||
* Description:
|
||||
@ -92,7 +69,7 @@ static bitmapType *wld_NewTexture(uint16_t width, uint16_t height)
|
||||
* an integer power of 2.
|
||||
************************************************************************/
|
||||
|
||||
static int wld_Log2(int x)
|
||||
static int wld_log2(int x)
|
||||
{
|
||||
int i;
|
||||
unsigned int n;
|
||||
@ -111,11 +88,33 @@ static int wld_Log2(int x)
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
* Name: wld_QuantizeTexture
|
||||
* Name: wld_new_texture
|
||||
* Description:
|
||||
************************************************************************/
|
||||
|
||||
static void wld_QuantizeTexture(GraphicFileType *gFile, bitmapType *t)
|
||||
static bitmapType *wld_new_texture(uint16_t width, uint16_t height)
|
||||
{
|
||||
bitmapType *t;
|
||||
|
||||
if (height <= 0 || width <= 0)
|
||||
wld_fatal_error("wld_new_texture: bad texture dimensions");
|
||||
|
||||
t = (bitmapType*)wld_malloc(sizeof(bitmapType));
|
||||
t->bm = (trv_pixel_t*)wld_malloc(height * width * sizeof(trv_pixel_t));
|
||||
|
||||
t->w = width;
|
||||
t->h = height;
|
||||
t->log2h = wld_log2(height);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
* Name: wld_quantize_texture
|
||||
* Description:
|
||||
************************************************************************/
|
||||
|
||||
static void wld_quantize_texture(GraphicFileType *gFile, bitmapType *t)
|
||||
{
|
||||
RGBColor pixel;
|
||||
trv_pixel_t *destPixel = t->bm;
|
||||
@ -136,7 +135,7 @@ static void wld_QuantizeTexture(GraphicFileType *gFile, bitmapType *t)
|
||||
*************************************************************************/
|
||||
|
||||
/*************************************************************************
|
||||
* Name:
|
||||
* Name: wld_read_texturefile
|
||||
* Description:
|
||||
************************************************************************/
|
||||
|
||||
@ -153,12 +152,12 @@ bitmapType *wld_read_texturefile(char *filename)
|
||||
* texture mapping. Here, we enforce this.
|
||||
*/
|
||||
|
||||
if (wld_Log2(gFile->width) == -1 || wld_Log2(gFile->height) == -1)
|
||||
if (wld_log2(gFile->width) == -1 || wld_log2(gFile->height) == -1)
|
||||
wld_fatal_error("Dimensions texture %s are not powers of two.",
|
||||
filename);
|
||||
|
||||
t = wld_NewTexture(gFile->width, gFile->height);
|
||||
wld_QuantizeTexture(gFile, t);
|
||||
t = wld_new_texture(gFile->width, gFile->height);
|
||||
wld_quantize_texture(gFile, t);
|
||||
|
||||
wld_free_graphicfile(gFile);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user