Run some .c files throut nuttx/tools/indents.sh

This commit is contained in:
Gregory Nutt 2016-11-10 12:21:47 -06:00
parent 85ba39f596
commit 8db489ed8c
42 changed files with 968 additions and 862 deletions

View File

@ -52,26 +52,26 @@
* This function adds a plane to a world plane list * This function adds a plane to a world plane list
************************************************************************/ ************************************************************************/
void wld_add_plane(rect_list_t *newRect, rect_head_t *list) void wld_add_plane(rect_list_t * newRect, rect_head_t * list)
{ {
rect_list_t *nextRect, *prevRect; rect_list_t *nextRect, *prevRect;
/* Search the list to find the location to insert the new rectangle. /* Search the list to find the location to insert the new rectangle. Each
* Each is list is maintained in ascending plane order. * list is maintained in ascending plane order.
*/ */
for (nextRect = list->head; for (nextRect = list->head;
((nextRect) && (nextRect->d.plane < newRect->d.plane)); ((nextRect) && (nextRect->d.plane < newRect->d.plane));
nextRect = nextRect->flink); nextRect = nextRect->flink);
/* Add the newRect to the spot found in the list. Check if the newRect /* Add the newRect to the spot found in the list. Check if the newRect goes
* goes at the end of the list. * at the end of the list.
*/ */
if (!nextRect) if (!nextRect)
{ {
/* No rectangle with plane larger than the one to be added was /* No rectangle with plane larger than the one to be added was found in
* found in the list. The newRect goes at the end of the list. * the list. The newRect goes at the end of the list.
*/ */
prevRect = list->tail; prevRect = list->tail;

View File

@ -50,9 +50,9 @@
* bitmaps * bitmaps
*/ */
wld_bitmap_t *evenBitmaps[MAX_BITMAPS]; wld_bitmap_t *g_even_bitmaps[MAX_BITMAPS];
#ifndef WEDIT #ifndef WEDIT
wld_bitmap_t *oddBitmaps[MAX_BITMAPS]; wld_bitmap_t *g_odd_bitmaps[MAX_BITMAPS];
#endif #endif
/* This is the palette to use for the selected world */ /* This is the palette to use for the selected world */
@ -63,7 +63,7 @@ RGBColor worldPalette[256];
/* This is the maximum value + 1 of a texture code. */ /* This is the maximum value + 1 of a texture code. */
uint16_t numBitmaps; uint16_t g_nbitmaps;
/* These are the colors from the worldPalette which should used to rend /* These are the colors from the worldPalette which should used to rend
* the sky and ground * the sky and ground

View File

@ -101,9 +101,9 @@ typedef struct
* bitmaps * bitmaps
*/ */
extern wld_bitmap_t *evenBitmaps[MAX_BITMAPS]; extern wld_bitmap_t *g_even_bitmaps[MAX_BITMAPS];
#ifndef WEDIT #ifndef WEDIT
extern wld_bitmap_t *oddBitmaps[MAX_BITMAPS]; extern wld_bitmap_t *g_odd_bitmaps[MAX_BITMAPS];
#endif #endif
/* This is the palette to use for the selected world */ /* This is the palette to use for the selected world */
@ -114,7 +114,7 @@ extern RGBColor worldPalette[256];
/* This is the maximum value + 1 of a texture code */ /* This is the maximum value + 1 of a texture code */
extern uint16_t numBitmaps; extern uint16_t g_nbitmaps;
/* These are the colors from the worldPalette which should used to rend /* These are the colors from the worldPalette which should used to rend
* the sky and ground * the sky and ground

View File

@ -126,43 +126,50 @@ static uint8_t wld_manage_worldfile(INIHANDLE handle)
/* Read the initial camera/player position */ /* Read the initial camera/player position */
result = wld_read_shortint(handle, &g_initial_camera.x, result = wld_read_shortint(handle, &g_initial_camera.x,
g_camera_section_name, g_camera_section_name, g_camera_initialx_name);
g_camera_initialx_name);
if (result != 0) if (result != 0)
{
return result; return result;
}
result = wld_read_shortint(handle, &g_initial_camera.y, result = wld_read_shortint(handle, &g_initial_camera.y,
g_camera_section_name, g_camera_section_name, g_camera_initialy_name);
g_camera_initialy_name);
if (result != 0) if (result != 0)
{
return result; return result;
}
result = wld_read_shortint(handle, &g_initial_camera.z, result = wld_read_shortint(handle, &g_initial_camera.z,
g_camera_section_name, g_camera_section_name, g_camera_initialz_name);
g_camera_initialz_name);
if (result != 0) if (result != 0)
{
return result; return result;
}
/* Get the player's yaw/pitch orientation */ /* Get the player's yaw/pitch orientation */
result = wld_read_shortint(handle, &g_initial_camera.yaw, result = wld_read_shortint(handle, &g_initial_camera.yaw,
g_camera_section_name, g_camera_section_name, g_camera_initialyaw_name);
g_camera_initialyaw_name);
if (result != 0) if (result != 0)
{
return result; return result;
}
result = wld_read_shortint(handle, &g_initial_camera.pitch, result = wld_read_shortint(handle, &g_initial_camera.pitch,
g_camera_section_name, g_camera_initialpitch_name); g_camera_section_name, g_camera_initialpitch_name);
if (result != 0) if (result != 0)
{
return result; return result;
}
/* Get the height of the player */ /* Get the height of the player */
result = wld_read_shortint(handle, &playerHeight, result = wld_read_shortint(handle, &playerHeight,
g_player_section_name, g_player_section_name, g_player_height_name);
g_player_height_name);
if (result != 0) if (result != 0)
{
return result; return result;
}
/* Read the player's capability to step on top of things in the world. */ /* Read the player's capability to step on top of things in the world. */
@ -170,33 +177,45 @@ static uint8_t wld_manage_worldfile(INIHANDLE handle)
g_player_section_name, g_player_section_name,
g_player_walk_stepheight_name); g_player_walk_stepheight_name);
if (result != 0) if (result != 0)
{
return result; return result;
}
result = wld_read_shortint(handle, &runStepHeight, result = wld_read_shortint(handle, &runStepHeight,
g_player_section_name, g_player_section_name,
g_player_run_stepheight_name); g_player_run_stepheight_name);
if (result != 0) if (result != 0)
{
return result; return result;
}
/* Get the name of the file containing the world map */ /* Get the name of the file containing the world map */
result = wld_read_filename(handle, &filename, result = wld_read_filename(handle, &filename,
g_world_section_name, g_world_section_name, g_wold_map_name);
g_wold_map_name);
if (result != 0) if (result != 0)
{
return result; return result;
}
if (filename == NULL) if (filename == NULL)
{
return WORLD_PLANE_FILE_NAME_ERROR; return WORLD_PLANE_FILE_NAME_ERROR;
}
/* Allocate and load the world */ /* Allocate and load the world */
result = wld_initialize_planes(); result = wld_initialize_planes();
if (result != 0) if (result != 0)
{
return result; return result;
}
result = wld_load_planefile(filename); result = wld_load_planefile(filename);
if (result != 0) if (result != 0)
{
return result; return result;
}
inifile_free_string(filename); inifile_free_string(filename);
@ -206,15 +225,22 @@ static uint8_t wld_manage_worldfile(INIHANDLE handle)
result = wld_read_filename(handle, &filename, g_world_section_name, result = wld_read_filename(handle, &filename, g_world_section_name,
g_world_palette_name); g_world_palette_name);
if (result != 0) if (result != 0)
{
return result; return result;
}
if (filename == NULL) if (filename == NULL)
{
return WORLD_PALR_FILE_NAME_ERROR; return WORLD_PALR_FILE_NAME_ERROR;
}
/* Then load it into g_pal_table. */ /* Then load it into g_pal_table. */
result = wld_load_paltable(filename); result = wld_load_paltable(filename);
if (result != 0) if (result != 0)
{
return result; return result;
}
inifile_free_string(filename); inifile_free_string(filename);
@ -223,9 +249,14 @@ static uint8_t wld_manage_worldfile(INIHANDLE handle)
result = wld_read_filename(handle, &filename, g_world_section_name, result = wld_read_filename(handle, &filename, g_world_section_name,
g_world_images_name); g_world_images_name);
if (result != 0) if (result != 0)
{
return result; return result;
}
if (filename == NULL) if (filename == NULL)
{
return WORLD_BITMAP_FILE_NAME_ERROR; return WORLD_BITMAP_FILE_NAME_ERROR;
}
/* Create the RGB lookup table */ /* Create the RGB lookup table */
@ -235,7 +266,9 @@ static uint8_t wld_manage_worldfile(INIHANDLE handle)
result = wld_initialize_bitmaps(); result = wld_initialize_bitmaps();
if (result != 0) if (result != 0)
{
return result; return result;
}
result = wld_load_bitmapfile(filename); result = wld_load_bitmapfile(filename);
inifile_free_string(filename); inifile_free_string(filename);
@ -329,8 +362,7 @@ static uint8_t wld_read_filename(INIHANDLE handle,
{ {
/* Read the string from the ini file. We supply the default value of NULL. /* 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 * If this value is returned, we assume that that is evidence that the
* requested value was not supplied in the ini file. * requested value was not supplied in the ini file. */
*/
char *value = inifile_read_string(handle, section_name, variable_name, char *value = inifile_read_string(handle, section_name, variable_name,
NULL); NULL);

View File

@ -45,7 +45,7 @@
#include "wld_world.h" #include "wld_world.h"
#include "wld_bitmaps.h" #include "wld_bitmaps.h"
#if (MSWINDOWS) #if (MSWINDOWS)
#include "wld_pcx.h" # include "wld_pcx.h"
#endif #endif
/************************************************************************* /*************************************************************************
@ -63,20 +63,20 @@ void wld_discard_bitmaps(void)
int i; int i;
for (i = 0; i < MAX_BITMAPS; i++) for (i = 0; i < MAX_BITMAPS; i++)
{ {
if (evenBitmaps[i]) if (g_even_bitmaps[i])
{ {
wld_free_texture((void*)evenBitmaps[i]); wld_free_texture((void *)g_even_bitmaps[i]);
evenBitmaps[i] = NULL; g_even_bitmaps[i] = NULL;
} }
#ifndef WEDIT #ifndef WEDIT
if (oddBitmaps[i]) if (g_odd_bitmaps[i])
{ {
wld_free_texture((void*)oddBitmaps[i]); wld_free_texture((void *)g_odd_bitmaps[i]);
oddBitmaps[i] = NULL; g_odd_bitmaps[i] = NULL;
} }
#endif #endif
} }
numBitmaps = 0; g_nbitmaps = 0;
} }

View File

@ -54,6 +54,7 @@
void wld_discard_paltable(void) void wld_discard_paltable(void)
{ {
int i; int i;
for (i = 0; i < NUM_ZONES; i++) for (i = 0; i < NUM_ZONES; i++)
{ {
if (g_pal_table[i]) if (g_pal_table[i])

View File

@ -53,14 +53,14 @@
* This function deallocates one plane of the world * This function deallocates one plane of the world
************************************************************************/ ************************************************************************/
static void wld_DiscardWorldPlane(rect_list_t *rect) static void wld_DiscardWorldPlane(rect_list_t * rect)
{ {
rect_list_t *next; rect_list_t *next;
while (rect) while (rect)
{ {
next = rect->flink; next = rect->flink;
wld_free((void *) rect); wld_free((void *)rect);
rect = next; rect = next;
} }
} }
@ -77,13 +77,12 @@ static void wld_DiscardWorldPlane(rect_list_t *rect)
void wld_discard_planes(void) void wld_discard_planes(void)
{ {
wld_DiscardWorldPlane(xPlane.head); wld_DiscardWorldPlane(g_xplane_list.head);
xPlane.head = xPlane.tail = NULL; g_xplane_list.head = g_xplane_list.tail = NULL;
wld_DiscardWorldPlane(yPlane.head); wld_DiscardWorldPlane(g_yplane_list.head);
yPlane.head = yPlane.tail = NULL; g_yplane_list.head = g_yplane_list.tail = NULL;
wld_DiscardWorldPlane(zPlane.head); wld_DiscardWorldPlane(g_zplane_list.head);
zPlane.head = zPlane.tail = NULL; g_zplane_list.head = g_zplane_list.tail = NULL;
wld_DiscardWorldPlane(freeList); wld_DiscardWorldPlane(freeList);
freeList = NULL; freeList = NULL;
} }

View File

@ -55,28 +55,25 @@
************************************************************************/ ************************************************************************/
rect_list_t *wld_find_plane(wld_coord_t h, wld_coord_t v, wld_coord_t plane, rect_list_t *wld_find_plane(wld_coord_t h, wld_coord_t v, wld_coord_t plane,
rect_head_t *list) rect_head_t * list)
{ {
rect_list_t *rect; rect_list_t *rect;
/* Search until we find the first occurrence of a rectangle in the /* Search until we find the first occurrence of a rectangle in the specified
* specified plane * plane.
*/ */
for (rect = list->head; for (rect = list->head;
((rect) && (rect->d.plane < plane)); ((rect) && (rect->d.plane < plane)); rect = rect->flink);
rect = rect->flink);
/* Then look at every occurrence of rectangles at this plane or /* Then look at every occurrence of rectangles at this plane or until a
* until a rectangle containing the specified point is found * rectangle containing the specified point is found.
*/ */
for (; for (; ((rect) && (rect->d.plane == plane)); rect = rect->flink)
((rect) && (rect->d.plane == plane));
rect = rect->flink)
{ {
/* There is another rectangle in this plane. Check if the /* There is another rectangle in this plane. Check if the point lies
* point lies within the rectangle. * within the rectangle.
*/ */
if ((h >= rect->d.hStart) && (h <= rect->d.hEnd) if ((h >= rect->d.hStart) && (h <= rect->d.hEnd)
@ -86,5 +83,3 @@ rect_list_t *wld_find_plane(wld_coord_t h, wld_coord_t v, wld_coord_t plane,
return NULL; return NULL;
} }

View File

@ -51,7 +51,7 @@
* Description: * Description:
************************************************************************/ ************************************************************************/
void wld_free_graphicfile(graphic_file_t *gfile) void wld_free_graphicfile(graphic_file_t * gfile)
{ {
if (gfile != NULL) if (gfile != NULL)
{ {

View File

@ -52,8 +52,12 @@
* Description: * Description:
************************************************************************/ ************************************************************************/
void wld_free_texture(wld_bitmap_t *t) void wld_free_texture(wld_bitmap_t * t)
{ {
if (t->bm) wld_free(t->bm); if (t->bm)
{
wld_free(t->bm);
}
wld_free(t); wld_free(t);
} }

View File

@ -71,4 +71,3 @@ RGBColor wld_graphicfile_pixel(graphic_file_t *gfile, int x, int y)
return rgb; return rgb;
} }
} }

View File

@ -45,7 +45,7 @@
#include "wld_world.h" #include "wld_world.h"
#include "wld_bitmaps.h" #include "wld_bitmaps.h"
#if (MSWINDOWS) #if (MSWINDOWS)
#include "wld_pcx.h" # include "wld_pcx.h"
#endif #endif
/************************************************************************* /*************************************************************************
@ -62,12 +62,12 @@ uint8_t wld_initialize_bitmaps(void)
int i; int i;
for (i = 0; i < MAX_BITMAPS; i++) for (i = 0; i < MAX_BITMAPS; i++)
{ {
evenBitmaps[i] = NULL; g_even_bitmaps[i] = NULL;
#ifndef WEDIT #ifndef WEDIT
oddBitmaps[i] = NULL; g_odd_bitmaps[i] = NULL;
#endif #endif
} }
numBitmaps = 0; g_nbitmaps = 0;
return BMAP_SUCCESS; return BMAP_SUCCESS;
} }

View File

@ -1,3 +1,4 @@
/**************************************************************************** /****************************************************************************
* apps/graphics/traveler/tools/libwld/wld_initializeplanes.c * apps/graphics/traveler/tools/libwld/wld_initializeplanes.c
* This file contains the logic initialize world plane data structures * This file contains the logic initialize world plane data structures
@ -54,9 +55,9 @@
uint8_t wld_initialize_planes(void) uint8_t wld_initialize_planes(void)
{ {
xPlane.head = xPlane.tail = NULL; g_xplane_list.head = g_xplane_list.tail = NULL;
yPlane.head = yPlane.tail = NULL; g_yplane_list.head = g_yplane_list.tail = NULL;
zPlane.head = zPlane.tail = NULL; g_zplane_list.head = g_zplane_list.tail = NULL;
freeList = NULL; freeList = NULL;
return PLANE_SUCCESS; return PLANE_SUCCESS;

View File

@ -46,7 +46,7 @@
#include "wld_world.h" #include "wld_world.h"
#include "wld_bitmaps.h" #include "wld_bitmaps.h"
#if (MSWINDOWS) #if (MSWINDOWS)
#include "wld_pcx.h" # include "wld_pcx.h"
#endif #endif
#include "wld_utils.h" #include "wld_utils.h"
@ -60,7 +60,7 @@
* Read a file name from the input stream * Read a file name from the input stream
************************************************************************/ ************************************************************************/
static bool wld_read_filename(FILE *fp, char *fileName) static bool wld_read_filename(FILE * fp, char *fileName)
{ {
int16_t nbytes; int16_t nbytes;
int ch; int ch;
@ -72,7 +72,8 @@ static bool wld_read_filename(FILE *fp, char *fileName)
do do
{ {
ch = getc(fp); ch = getc(fp);
if (ch == EOF) return false; if (ch == EOF)
return false;
} }
while ((ch == ' ') || (ch == '\n') || (ch == '\r')); while ((ch == ' ') || (ch == '\n') || (ch == '\r'));
@ -87,7 +88,10 @@ static bool wld_read_filename(FILE *fp, char *fileName)
{ {
/* Make sure that the file name is not too large */ /* Make sure that the file name is not too large */
if (nbytes >= FILE_NAME_SIZE) return false; if (nbytes >= FILE_NAME_SIZE)
{
return false;
}
/* Add the new character to the file name */ /* Add the new character to the file name */
@ -102,10 +106,9 @@ static bool wld_read_filename(FILE *fp, char *fileName)
break; break;
} }
/* Get the character for the next time through the loop. Every file /* Get the character for the next time through the loop. Every file name
* name should be terminated with a space or a new line. EOF is * should be terminated with a space or a new line. EOF is unexpected in
* unexpected in this context. * this context. */
*/
ch = getc(fp); ch = getc(fp);
if (ch == EOF) if (ch == EOF)
@ -123,7 +126,7 @@ static bool wld_read_filename(FILE *fp, char *fileName)
* This function loads the world data from the input file * This function loads the world data from the input file
************************************************************************/ ************************************************************************/
static uint8_t wld_load_bitmaps(FILE *fp) static uint8_t wld_load_bitmaps(FILE * fp)
{ {
#if MSWINDOWS #if MSWINDOWS
volatile pcxPicture workPCX; volatile pcxPicture workPCX;
@ -139,8 +142,8 @@ static uint8_t wld_load_bitmaps(FILE *fp)
/* Get the number of bitmaps in the bitmap file */ /* Get the number of bitmaps in the bitmap file */
numBitmaps = wld_read_decimal(fp); g_nbitmaps = wld_read_decimal(fp);
if (numBitmaps >= MAX_BITMAPS) if (g_nbitmaps >= MAX_BITMAPS)
return BMAP_TOO_MANY; return BMAP_TOO_MANY;
/* Read the colors used to rend the sky and ground */ /* Read the colors used to rend the sky and ground */
@ -149,9 +152,8 @@ static uint8_t wld_load_bitmaps(FILE *fp)
groundColor = wld_read_decimal(fp); groundColor = wld_read_decimal(fp);
#if MSWINDOWS #if MSWINDOWS
/* Load the textures -- Note that the first texture will be used /* Load the textures -- Note that the first texture will be used to define
* to define the worldPalette * the worldPalette */
*/
palette = worldPalette; palette = worldPalette;
#endif #endif
@ -159,74 +161,92 @@ static uint8_t wld_load_bitmaps(FILE *fp)
/* Load each bitmap file */ /* Load each bitmap file */
for (bMapIndex = 0; for (bMapIndex = 0;
((bMapIndex < numBitmaps) && (result == BMAP_SUCCESS)); ((bMapIndex < g_nbitmaps) && (result == BMAP_SUCCESS)); bMapIndex++)
bMapIndex++)
{ {
/* Load the even bitmap */ /* Load the even bitmap */
/* Get the name of the file which contains the even bitmap */ /* Get the name of the file which contains the even bitmap */
if (!wld_read_filename(fp, graphicsFileName)) if (!wld_read_filename(fp, graphicsFileName))
{
return BMAP_BML_READ_ERROR; return BMAP_BML_READ_ERROR;
}
#if MSWINDOWS #if MSWINDOWS
/* Setup to load the PCX bitmap from the file for the event bitmap */ /* Setup to load the PCX bitmap from the file for the event bitmap */
result = wld_pcx_init(&workPCX, BITMAP_HEIGHT, BITMAP_WIDTH, result = wld_pcx_init(&workPCX, BITMAP_HEIGHT, BITMAP_WIDTH,
palette, NULL); palette, NULL);
if (result) return result; if (result)
{
return result;
}
/* Put the bitmap buffer into the evenBitmap list */ /* Put the bitmap buffer into the evenBitmap list */
evenBitmaps[bMapIndex].w = BITMAP_WIDTH; g_even_bitmaps[bMapIndex].w = BITMAP_WIDTH;
evenBitmaps[bMapIndex].h = BITMAP_HEIGHT; g_even_bitmaps[bMapIndex].h = BITMAP_HEIGHT;
evenBitmaps[bMapIndex].log2h = BITMAP_LOG2H; g_even_bitmaps[bMapIndex].log2h = BITMAP_LOG2H;
evenBitmaps[bMapIndex].bm = workPCX.buffer; g_even_bitmaps[bMapIndex].bm = workPCX.buffer;
/* Load the PCX bitmap from the file for the event bitmap */ /* Load the PCX bitmap from the file for the event bitmap */
result = wld_loadpcx(graphicsFileName, &workPCX); result = wld_loadpcx(graphicsFileName, &workPCX);
if (result) return result; if (result)
{
return result;
}
/* Don't bother to load the palette on the rest of the textures -- /* Don't bother to load the palette on the rest of the textures -- we
* we will assume the same palette for all textures. * will assume the same palette for all textures. */
*/
palette = NULL; palette = NULL;
#else #else
evenBitmaps[bMapIndex] = wld_read_texturefile(graphicsFileName); g_even_bitmaps[bMapIndex] = wld_read_texturefile(graphicsFileName);
if (!evenBitmaps[bMapIndex]) return BMAP_BML_READ_ERROR; if (!g_even_bitmaps[bMapIndex])
{
return BMAP_BML_READ_ERROR;
}
#endif #endif
/* Load the odd bitmap */ /* Load the odd bitmap */
/* Get the name of the file which contains the odd bitmap */ /* Get the name of the file which contains the odd bitmap */
if (!wld_read_filename(fp, graphicsFileName)) if (!wld_read_filename(fp, graphicsFileName))
{
return BMAP_BML_READ_ERROR; return BMAP_BML_READ_ERROR;
}
#ifndef WEDIT #ifndef WEDIT
#if MSWINDOWS # if MSWINDOWS
/* Setup to load the PCX bitmap from the file for the odd bitmap */ /* Setup to load the PCX bitmap from the file for the odd bitmap */
result = wld_pcx_init(&workPCX, BITMAP_HEIGHT, BITMAP_WIDTH, result = wld_pcx_init(&workPCX, BITMAP_HEIGHT, BITMAP_WIDTH,
palette, NULL); palette, NULL);
if (result) return result; if (result)
{
return result;
}
/* Put the bitmap buffer into the oddBitmap list */ /* Put the bitmap buffer into the oddBitmap list */
oddBitmaps[bMapIndex].w = BITMAP_WIDTH; g_odd_bitmaps[bMapIndex].w = BITMAP_WIDTH;
oddBitmaps[bMapIndex].h = BITMAP_HEIGHT; g_odd_bitmaps[bMapIndex].h = BITMAP_HEIGHT;
oddBitmaps[bMapIndex].log2h = BITMAP_LOG2H; g_odd_bitmaps[bMapIndex].log2h = BITMAP_LOG2H;
oddBitmaps[bMapIndex].bm = workPCX.buffer; g_odd_bitmaps[bMapIndex].bm = workPCX.buffer;
/* Load the PCX bitmap from the file for the odd bitmap */ /* Load the PCX bitmap from the file for the odd bitmap */
result = wld_loadpcx(graphicsFileName, &workPCX); result = wld_loadpcx(graphicsFileName, &workPCX);
#else # else
oddBitmaps[bMapIndex] = wld_read_texturefile(graphicsFileName); g_odd_bitmaps[bMapIndex] = wld_read_texturefile(graphicsFileName);
if (!oddBitmaps[bMapIndex]) return BMAP_BML_READ_ERROR; if (!g_odd_bitmaps[bMapIndex])
#endif {
return BMAP_BML_READ_ERROR;
}
# endif
#endif #endif
} }
return result; return result;
} }
@ -248,12 +268,14 @@ uint8_t wld_load_bitmapfile(char *bmlFile)
/* Open the file which contains the names of all of the bitmap files */ /* Open the file which contains the names of all of the bitmap files */
fp = fopen(bmlFile, "r"); fp = fopen(bmlFile, "r");
if (!fp) return BMAP_BML_OPEN_ERROR; if (!fp)
return BMAP_BML_OPEN_ERROR;
/* Load all of the bitmaps */ /* Load all of the bitmaps */
result = wld_load_bitmaps(fp); result = wld_load_bitmaps(fp);
if (result) wld_discard_bitmaps(); if (result)
wld_discard_bitmaps();
/* We are all done with the file, so close it */ /* We are all done with the file, so close it */

View File

@ -85,7 +85,7 @@ int BitOffset = 0, /* Bit Offset of next code */
EOFCode, /* GIF end-of-information code */ EOFCode, /* GIF end-of-information code */
CurCode, OldCode, InCode, /* Decompressor variables */ CurCode, OldCode, InCode, /* Decompressor variables */
FirstFree, /* First free code, generated per GIF spec */ FirstFree, /* First free code, generated per GIF spec */
FreeCode, /* Decompressor, next free slot in hash table*/ FreeCode, /* Decompressor, next free slot in hash table */
FinChar, /* Decompressor variable */ FinChar, /* Decompressor variable */
BitMask, /* AND mask for data size */ BitMask, /* AND mask for data size */
ReadMask; /* Code AND mask for current code size */ ReadMask; /* Code AND mask for current code size */
@ -142,17 +142,17 @@ static int ReadCode(void)
RawCode >>= (BitOffset % 8); RawCode >>= (BitOffset % 8);
BitOffset += CodeSize; BitOffset += CodeSize;
return(RawCode & ReadMask); return (RawCode & ReadMask);
} }
static void AddToPixel(uint8_t Index) static void AddToPixel(uint8_t Index)
{ {
if (YC<Height) if (YC < Height)
*(Image + YC * BytesPerScanline + XC) = Index; *(Image + YC * BytesPerScanline + XC) = Index;
if (!used[Index]) if (!used[Index])
{ {
used[Index]=1; used[Index] = 1;
numused++; numused++;
} }
@ -164,11 +164,13 @@ static void AddToPixel(uint8_t Index)
/* If a non-interlaced picture, just increment YC to the next scan line. /* If a non-interlaced picture, just increment YC to the next scan line.
* If it's interlaced, deal with the interlace as described in the GIF * If it's interlaced, deal with the interlace as described in the GIF
* spec. Put the decoded scan line out to the screen if we haven't gone * spec. Put the decoded scan line out to the screen if we haven't gone
* pwld_ the bottom of it * pwld_ the bottom of it */
*/
XC = 0; XC = 0;
if (!Interlace) YC++; if (!Interlace)
{
YC++;
}
else else
{ {
switch (Pass) switch (Pass)
@ -212,11 +214,11 @@ static void AddToPixel(uint8_t Index)
************************************************************************/ ************************************************************************/
/************************************************************************* /*************************************************************************
* Name: * Name: wld_LoadGIF
* Description: * Description:
************************************************************************/ ************************************************************************/
graphic_file_t *wld_LoadGIF(FILE *fp, char *fname) graphic_file_t *wld_LoadGIF(FILE * fp, char *fname)
{ {
graphic_file_t *gfile; graphic_file_t *gfile;
int filesize; int filesize;
@ -239,7 +241,9 @@ graphic_file_t *wld_LoadGIF(FILE *fp, char *fname)
fseek(fp, 0L, 0); fseek(fp, 0L, 0);
if (!(ptr = RawGIF = (uint8_t *) malloc(filesize))) if (!(ptr = RawGIF = (uint8_t *) malloc(filesize)))
{
wld_fatal_error("not enough memory to read gif file"); wld_fatal_error("not enough memory to read gif file");
}
if (!(Rwld_er = (uint8_t *) malloc(filesize))) if (!(Rwld_er = (uint8_t *) malloc(filesize)))
{ {
@ -251,8 +255,12 @@ graphic_file_t *wld_LoadGIF(FILE *fp, char *fname)
wld_fatal_error("GIF data read failed"); wld_fatal_error("GIF data read failed");
if (strncmp(ptr, id87, 6)) if (strncmp(ptr, id87, 6))
{
if (strncmp(ptr, id89, 6)) if (strncmp(ptr, id89, 6))
{
wld_fatal_error("not a GIF file"); wld_fatal_error("not a GIF file");
}
}
ptr += 6; ptr += 6;
@ -264,7 +272,9 @@ graphic_file_t *wld_LoadGIF(FILE *fp, char *fname)
RHeight = ch + 0x100 * NEXTBYTE; RHeight = ch + 0x100 * NEXTBYTE;
if (Verbose) if (Verbose)
{
fprintf(stderr, "screen dims: %dx%d.\n", RWidth, RHeight); fprintf(stderr, "screen dims: %dx%d.\n", RWidth, RHeight);
}
ch = NEXTBYTE; ch = NEXTBYTE;
HasColormap = ((ch & COLORMAPMASK) ? true : false); HasColormap = ((ch & COLORMAPMASK) ? true : false);
@ -276,15 +286,19 @@ graphic_file_t *wld_LoadGIF(FILE *fp, char *fname)
Background = NEXTBYTE; /* background color... not used. */ Background = NEXTBYTE; /* background color... not used. */
if (NEXTBYTE) /* supposed to be NULL */ if (NEXTBYTE) /* supposed to be NULL */
{
wld_fatal_error("corrupt GIF file (bad screen descriptor)"); wld_fatal_error("corrupt GIF file (bad screen descriptor)");
}
/* Read in global colormap. */ /* Read in global colormap. */
if (HasColormap) if (HasColormap)
{ {
if (Verbose) if (Verbose)
{
fprintf(stderr, "%s is %dx%d, %d bits per pixel, (%d colors).\n", fprintf(stderr, "%s is %dx%d, %d bits per pixel, (%d colors).\n",
fname, RWidth,RHeight,BitsPerPixel, ColorMapSize); fname, RWidth, RHeight, BitsPerPixel, ColorMapSize);
}
for (i = 0; i < ColorMapSize; i++) for (i = 0; i < ColorMapSize; i++)
{ {
@ -299,7 +313,7 @@ graphic_file_t *wld_LoadGIF(FILE *fp, char *fname)
/* look for image separator */ /* look for image separator */
for (ch = NEXTBYTE ; ch != IMAGESEP ; ch = NEXTBYTE) for (ch = NEXTBYTE; ch != IMAGESEP; ch = NEXTBYTE)
{ {
i = ch; i = ch;
fprintf(stderr, "EXTENSION CHARACTER: %x\n", i); fprintf(stderr, "EXTENSION CHARACTER: %x\n", i);
@ -317,6 +331,7 @@ graphic_file_t *wld_LoadGIF(FILE *fp, char *fname)
transparency = ptr[3]; /* transparent color index */ transparency = ptr[3]; /* transparent color index */
fprintf(stderr, "transparency index: %i\n", transparency); fprintf(stderr, "transparency index: %i\n", transparency);
} }
ptr += ch; ptr += ch;
break; break;
case PLAINTEXT_EXT: case PLAINTEXT_EXT:
@ -330,8 +345,10 @@ graphic_file_t *wld_LoadGIF(FILE *fp, char *fname)
} }
while ((ch = NEXTBYTE)) while ((ch = NEXTBYTE))
{
ptr += ch; ptr += ch;
} }
}
/* Now read in values from the image descriptor */ /* Now read in values from the image descriptor */
@ -350,27 +367,27 @@ graphic_file_t *wld_LoadGIF(FILE *fp, char *fname)
Width, Height, (Interlace) ? "" : "non-"); Width, Height, (Interlace) ? "" : "non-");
gfile = wld_new_graphicfile(); gfile = wld_new_graphicfile();
gfile->palette = (RGBColor*)wld_malloc(sizeof(RGBColor) * ColorMapSize); gfile->palette = (RGBColor *) wld_malloc(sizeof(RGBColor) * ColorMapSize);
for (i = 0; i < ColorMapSize; i++) for (i = 0; i < ColorMapSize; i++)
{ {
gfile->palette[i].red = Red[i]; gfile->palette[i].red = Red[i];
gfile->palette[i].green = Green[i]; gfile->palette[i].green = Green[i];
gfile->palette[i].blue = Blue[i]; gfile->palette[i].blue = Blue[i];
} }
gfile->bitmap = (uint8_t*)wld_malloc(Width * Height);
gfile->bitmap = (uint8_t *) wld_malloc(Width * Height);
gfile->type = gfPaletted; gfile->type = gfPaletted;
gfile->width = Width; gfile->width = Width;
gfile->height = Height; gfile->height = Height;
gfile->transparent_entry = transparency; gfile->transparent_entry = transparency;
/* Note that I ignore the possible existence of a local color map. /* Note that I ignore the possible existence of a local color map. I'm told
* I'm told there aren't many files around that use them, and the spec * there aren't many files around that use them, and the spec says it's
* says it's defined for future use. This could lead to an error * defined for future use. This could lead to an error reading some files.
* reading some files.
*/ */
/* Start reading the rwld_er data. First we get the intial code size /* Start reading the rwld_er data. First we get the intial code size and
* and compute decompressor constant values, based on this code size. * compute decompressor constant values, based on this code size.
*/ */
CodeSize = NEXTBYTE; CodeSize = NEXTBYTE;
@ -378,10 +395,10 @@ graphic_file_t *wld_LoadGIF(FILE *fp, char *fname)
EOFCode = ClearCode + 1; EOFCode = ClearCode + 1;
FreeCode = FirstFree = ClearCode + 2; FreeCode = FirstFree = ClearCode + 2;
/* The GIF spec has it that the code size is the code size used to /* The GIF spec has it that the code size is the code size used to compute
* compute the above values is the code size given in the file, but the * the above values is the code size given in the file, but the code size
* code size used in compression/decompression is the code size given in * used in compression/decompression is the code size given in the file plus
* the file plus one. (thus the ++). * one. (thus the ++).
*/ */
CodeSize++; CodeSize++;
@ -389,20 +406,21 @@ graphic_file_t *wld_LoadGIF(FILE *fp, char *fname)
MaxCode = (1 << CodeSize); MaxCode = (1 << CodeSize);
ReadMask = MaxCode - 1; ReadMask = MaxCode - 1;
/* Read the rwld_er data. Here we just transpose it from the GIF array /* Read the rwld_er data. Here we just transpose it from the GIF array to
* to the Rwld_er array, turning it from a series of blocks into one long * the Rwld_er array, turning it from a series of blocks into one long data
* data stream, which makes life much easier for ReadCode(). * stream, which makes life much easier for ReadCode().
*/ */
ptr1 = Rwld_er; ptr1 = Rwld_er;
do do
{ {
ch = ch1 = NEXTBYTE; ch = ch1 = NEXTBYTE;
while (ch--) *ptr1++ = NEXTBYTE; while (ch--)
*ptr1++ = NEXTBYTE;
if ((ptr1 - Rwld_er) > filesize) if ((ptr1 - Rwld_er) > filesize)
wld_fatal_error("corrupt GIF file (unblock)"); wld_fatal_error("corrupt GIF file (unblock)");
} }
while(ch1); while (ch1);
free(RawGIF); /* We're done with the raw data now... */ free(RawGIF); /* We're done with the raw data now... */
@ -415,9 +433,8 @@ graphic_file_t *wld_LoadGIF(FILE *fp, char *fname)
Image = gfile->bitmap; Image = gfile->bitmap;
BytesPerScanline = Width; BytesPerScanline = Width;
/* Decompress the file, continuing until you see the GIF EOF code. One
/* Decompress the file, continuing until you see the GIF EOF code. * obvious enhancement is to add checking for corrupt files here.
* One obvious enhancement is to add checking for corrupt files here.
*/ */
Code = ReadCode(); Code = ReadCode();
@ -440,15 +457,14 @@ graphic_file_t *wld_LoadGIF(FILE *fp, char *fname)
} }
else else
{ {
/* If not a clear code, then must be data: save same as CurCode and
/* If not a clear code, then must be data: save same as CurCode * InCode
* and InCode
*/ */
CurCode = InCode = Code; CurCode = InCode = Code;
/* If greater or equal to FreeCode, not in the hash table yet; /* If greater or equal to FreeCode, not in the hash table yet; repeat
* repeat the lwld_ character decoded * the lwld_ character decoded
*/ */
if (CurCode >= FreeCode) if (CurCode >= FreeCode)
@ -457,17 +473,16 @@ graphic_file_t *wld_LoadGIF(FILE *fp, char *fname)
OutCode[OutCount++] = FinChar; OutCode[OutCount++] = FinChar;
} }
/* Unless this code is raw data, pursue the chain pointed to /* Unless this code is raw data, pursue the chain pointed to by
* by CurCode through the hash table to its end; each code * CurCode through the hash table to its end; each code in the chain
* in the chain puts its associated output code on the output * puts its associated output code on the output queue.
* queue.
*/ */
while (CurCode > BitMask) while (CurCode > BitMask)
{ {
if (OutCount > 1024) if (OutCount > 1024)
{ {
fprintf(stderr,"\nCorrupt GIF file (OutCount)!\n"); fprintf(stderr, "\nCorrupt GIF file (OutCount)!\n");
exit(-1); exit(-1);
} }
OutCode[OutCount++] = Suffix[CurCode]; OutCode[OutCount++] = Suffix[CurCode];
@ -479,8 +494,8 @@ graphic_file_t *wld_LoadGIF(FILE *fp, char *fname)
FinChar = CurCode & BitMask; FinChar = CurCode & BitMask;
OutCode[OutCount++] = FinChar; OutCode[OutCount++] = FinChar;
/* Now we put the data out to the Output routine. /* Now we put the data out to the Output routine. It's been stacked
* It's been stacked LIFO, so deal with it that way... * LIFO, so deal with it that way...
*/ */
for (i = OutCount - 1; i >= 0; i--) for (i = OutCount - 1; i >= 0; i--)
@ -494,9 +509,8 @@ graphic_file_t *wld_LoadGIF(FILE *fp, char *fname)
OldCode = InCode; OldCode = InCode;
/* Point to the next slot in the table. If we exceed the current /* Point to the next slot in the table. If we exceed the current
* MaxCode value, increment the code size unless it's already 12. * MaxCode value, increment the code size unless it's already 12. If
* If it is, do nothing: the next code decompressed better be * it is, do nothing: the next code decompressed better be CLEAR
* CLEAR
*/ */
FreeCode++; FreeCode++;
@ -510,16 +524,20 @@ graphic_file_t *wld_LoadGIF(FILE *fp, char *fname)
} }
} }
} }
Code = ReadCode(); Code = ReadCode();
} }
free(Rwld_er); free(Rwld_er);
if (Verbose) if (Verbose)
{
fprintf(stderr, "done.\n"); fprintf(stderr, "done.\n");
}
else else
fprintf(stderr,"(of which %d are used)\n",numused); {
fprintf(stderr, "(of which %d are used)\n", numused);
}
return gfile; return gfile;
} }

View File

@ -50,8 +50,8 @@
#include "wld_world.h" #include "wld_world.h"
#include "wld_paltable.h" #include "wld_paltable.h"
#if (!MSWINDOWS) #if (!MSWINDOWS)
#include "wld_bitmaps.h" # include "wld_bitmaps.h"
#include "wld_color.h" # include "wld_color.h"
#endif #endif
#include "wld_mem.h" #include "wld_mem.h"
#include "wld_utils.h" #include "wld_utils.h"
@ -74,11 +74,11 @@
#if USE_PAL_RANGES #if USE_PAL_RANGES
typedef struct typedef struct
{ {
uint8_t firstColor; uint8_t firstColor;
int8_t colorRange; int8_t colorRange;
uint8_t clipColor; uint8_t clipColor;
} pal_range_t; } pal_range_t;
#endif #endif
/************************************************************************* /*************************************************************************
@ -106,7 +106,8 @@ static void wld_allocate_paltable(uint32_t palTabEntrySize)
for (i = 0; i < NUM_ZONES; i++) for (i = 0; i < NUM_ZONES; i++)
{ {
g_pal_table[i] = (trv_pixel_t*)wld_malloc(palTabEntrySize*sizeof(trv_pixel_t)); g_pal_table[i] =
(trv_pixel_t *) wld_malloc(palTabEntrySize * sizeof(trv_pixel_t));
} }
} }
@ -131,7 +132,7 @@ uint8_t wld_load_paltable(char *file)
/* Allocate memory to hold the palette range mapping data */ /* Allocate memory to hold the palette range mapping data */
wld_allocate_paltable(TRV_PIXEL_MAX+1); wld_allocate_paltable(TRV_PIXEL_MAX + 1);
/* The first zone is just the identity transformation */ /* The first zone is just the identity transformation */
@ -165,9 +166,8 @@ uint8_t wld_load_paltable(char *file)
lum.luminance *= scale; lum.luminance *= scale;
/* Then save the pixel associated with this scaled value in /* Then save the pixel associated with this scaled value in the range
* the range palette table * palette table */
*/
*palptr++ = wld_lum2pixel(&lum); *palptr++ = wld_lum2pixel(&lum);
} }
@ -176,7 +176,7 @@ uint8_t wld_load_paltable(char *file)
return WORLD_SUCCESS; return WORLD_SUCCESS;
#else #else
#if USE_PAL_RANGES # if USE_PAL_RANGES
FILE *fp, *fopen(); FILE *fp, *fopen();
int16_t i; int16_t i;
int16_t nranges; int16_t nranges;
@ -189,7 +189,10 @@ uint8_t wld_load_paltable(char *file)
/* Open the file which contains the palette table */ /* Open the file which contains the palette table */
fp = fopen(file, "r"); fp = fopen(file, "r");
if (!fp) return PALR_FILE_OPEN_ERROR; if (!fp)
{
return PALR_FILE_OPEN_ERROR;
}
/* Read the number of ranges from the file */ /* Read the number of ranges from the file */
@ -229,9 +232,8 @@ uint8_t wld_load_paltable(char *file)
for (palndx = 0; palndx < PALETTE_SIZE; palndx++) for (palndx = 0; palndx < PALETTE_SIZE; palndx++)
{ {
/* Assume that the range will not be found. In this case, we /* Assume that the range will not be found. In this case, we will
* will perform the 1-to-1 mapping * perform the 1-to-1 mapping */
*/
plotcolor = palndx; plotcolor = palndx;
@ -255,12 +257,11 @@ uint8_t wld_load_paltable(char *file)
plotcolor -= zone; plotcolor -= zone;
/* Check if we have exceeded the range of this /* Check if we have exceeded the range of this color.
* color. If so, then set the color to the * If so, then set the color to the clipColor */
* clipColor
*/
if (plotcolor <= ranges[i].firstColor + ranges[i].colorRange) if (plotcolor <=
ranges[i].firstColor + ranges[i].colorRange)
{ {
plotcolor = ranges[i].clipColor; plotcolor = ranges[i].clipColor;
} }
@ -286,8 +287,7 @@ uint8_t wld_load_paltable(char *file)
plotcolor += zone; plotcolor += zone;
/* Check if we have exceeded the range of this color. If so, /* Check if we have exceeded the range of this color. If so,
* then set the color to black * then set the color to black */
*/
if (plotcolor >= ranges[i].firstColor + ranges[i].colorRange) if (plotcolor >= ranges[i].firstColor + ranges[i].colorRange)
{ {
@ -308,7 +308,7 @@ uint8_t wld_load_paltable(char *file)
} }
return WORLD_SUCCESS; return WORLD_SUCCESS;
#else # else
FILE *fp; FILE *fp;
int16_t zone; int16_t zone;
int16_t palndx; int16_t palndx;
@ -322,7 +322,10 @@ uint8_t wld_load_paltable(char *file)
/* Open the file which contains the palette table */ /* Open the file which contains the palette table */
fp = fopen(file, "r"); fp = fopen(file, "r");
if (!fp) return PALR_FILE_OPEN_ERROR; if (!fp)
{
return PALR_FILE_OPEN_ERROR;
}
/* Process each distance zone */ /* Process each distance zone */
@ -344,6 +347,6 @@ uint8_t wld_load_paltable(char *file)
fclose(fp); fclose(fp);
return WORLD_SUCESS; return WORLD_SUCESS;
#endif /* USE_PAL_RANGES */ # endif /* USE_PAL_RANGES */
#endif /* !MSWINDOWS */ #endif /* !MSWINDOWS */
} }

View File

@ -51,8 +51,8 @@
#include "trv_types.h" #include "trv_types.h"
#include "wld_mem.h" #include "wld_mem.h"
#if (!MSWINDOWS) #if (!MSWINDOWS)
#include "wld_bitmaps.h" # include "wld_bitmaps.h"
#include "wld_graphicfile.h" # include "wld_graphicfile.h"
#endif #endif
#include "wld_pcx.h" #include "wld_pcx.h"
@ -68,9 +68,9 @@
* Private Function Prototypes * Private Function Prototypes
*************************************************************************/ *************************************************************************/
static void wld_loadpcxHeader(FILE *fp, pcxHeader *header); static void wld_loadpcxHeader(FILE * fp, pcxHeader * header);
static void wld_loadpcxData(FILE *fp, int32_t imagSize, uint8_t *imageBuffer); static void wld_loadpcxData(FILE * fp, int32_t imagSize, uint8_t * imageBuffer);
static void wld_loadpcxPalette(FILE *fp, RGBColor *palette); static void wld_loadpcxPalette(FILE * fp, RGBColor * palette);
/************************************************************************* /*************************************************************************
* Global Variables * Global Variables
@ -98,8 +98,11 @@ uint8_t wld_loadpcx(char *filename, pcxPicturePtr image)
/* Open the file */ /* Open the file */
fp = fopen(filename,"rb"); fp = fopen(filename, "rb");
if (!fp) return PCX_OPEN_ERROR; if (!fp)
{
return PCX_OPEN_ERROR;
}
/* Load the PCX Header */ /* Load the PCX Header */
@ -126,7 +129,7 @@ uint8_t wld_loadpcx(char *filename, pcxPicturePtr image)
return PCX_SUCCESS; return PCX_SUCCESS;
} }
#else #else
graphic_file_t *wld_loadpcx(FILE *fp, char *filename) graphic_file_t *wld_loadpcx(FILE * fp, char *filename)
{ {
pcxHeader header; pcxHeader header;
trv_pixel_t *buffer; trv_pixel_t *buffer;
@ -144,15 +147,15 @@ graphic_file_t *wld_loadpcx(FILE *fp, char *filename)
imageWidth = header.width - header.x + 1; imageWidth = header.width - header.x + 1;
imageHeight = header.height - header.y + 1; imageHeight = header.height - header.y + 1;
imageSize = imageHeight * imageWidth * sizeof(trv_pixel_t); imageSize = imageHeight * imageWidth * sizeof(trv_pixel_t);
buffer = (trv_pixel_t*)wld_malloc(imageSize + 1); buffer = (trv_pixel_t *) wld_malloc(imageSize + 1);
/* Load the PCX data into the buffer */ /* Load the PCX data into the buffer */
wld_loadpcxData(fp, imageSize, (uint8_t*)buffer); wld_loadpcxData(fp, imageSize, (uint8_t *) buffer);
/* Allocate space to hold the PCX palette */ /* Allocate space to hold the PCX palette */
palette = (RGBColor*)wld_malloc(sizeof(RGBColor) * 256); palette = (RGBColor *) wld_malloc(sizeof(RGBColor) * 256);
/* Load the PCX palette */ /* Load the PCX palette */
@ -176,14 +179,14 @@ graphic_file_t *wld_loadpcx(FILE *fp, char *filename)
* Description: * Description:
************************************************************************/ ************************************************************************/
static void wld_loadpcxHeader(FILE *fp, pcxHeader *header) static void wld_loadpcxHeader(FILE * fp, pcxHeader * header)
{ {
uint8_t *tempBuffer; uint8_t *tempBuffer;
int i; int i;
/* Load the header */ /* Load the header */
tempBuffer = (uint8_t*)header; tempBuffer = (uint8_t *) header;
for (i = 0; i < SIZEOF_PCX_HEADER; i++) for (i = 0; i < SIZEOF_PCX_HEADER; i++)
{ {
@ -196,14 +199,14 @@ static void wld_loadpcxHeader(FILE *fp, pcxHeader *header)
* Description: * Description:
************************************************************************/ ************************************************************************/
static void wld_loadpcxData(FILE *fp, int32_t imageSize, uint8_t *imageBuffer) static void wld_loadpcxData(FILE * fp, int32_t imageSize, uint8_t * imageBuffer)
{ {
uint32_t count; uint32_t count;
int16_t numBytes; int16_t numBytes;
uint8_t data; uint8_t data;
count = 0; count = 0;
while(count <= imageSize) while (count <= imageSize)
{ {
/* Get the first piece of data */ /* Get the first piece of data */
@ -211,7 +214,7 @@ static void wld_loadpcxData(FILE *fp, int32_t imageSize, uint8_t *imageBuffer)
/* Is this a run length encoding? */ /* Is this a run length encoding? */
if ((data >= 192) /* && (data <= 255) */) if ((data >= 192) /* && (data <= 255) */ )
{ {
/* How many bytes in run? */ /* How many bytes in run? */
@ -223,7 +226,7 @@ static void wld_loadpcxData(FILE *fp, int32_t imageSize, uint8_t *imageBuffer)
/* Replicate data in buffer numBytes times */ /* Replicate data in buffer numBytes times */
while(numBytes-- > 0) while (numBytes-- > 0)
{ {
imageBuffer[count++] = data; imageBuffer[count++] = data;
} }
@ -242,7 +245,7 @@ static void wld_loadpcxData(FILE *fp, int32_t imageSize, uint8_t *imageBuffer)
* Description: * Description:
************************************************************************/ ************************************************************************/
static void wld_loadpcxPalette(FILE *fp, RGBColor *palette) static void wld_loadpcxPalette(FILE * fp, RGBColor * palette)
{ {
int i; int i;

View File

@ -46,14 +46,14 @@
* Private Functions * Private Functions
*************************************************************************/ *************************************************************************/
/************************************************************************* /*************************************************************************
* Name: wld_LoadWorldPlane * Name: wld_load_worldplane
* Description: * Description:
* This function loads the world data for one plane * This function loads the world data for one plane
************************************************************************/ ************************************************************************/
static uint8_t wld_LoadWorldPlane(FILE *fp, rect_head_t *list, uint8_t numRects) static uint8_t wld_load_worldplane(FILE * fp, rect_head_t * list,
uint8_t numRects)
{ {
rect_list_t *rect; rect_list_t *rect;
int i; int i;
@ -63,16 +63,18 @@ static uint8_t wld_LoadWorldPlane(FILE *fp, rect_head_t *list, uint8_t numRects)
/* Allocate space for the next rectangle */ /* Allocate space for the next rectangle */
rect = wld_new_plane(); rect = wld_new_plane();
if (!rect) return PLANE_ALLOCATION_FAILURE; if (!rect)
{
return PLANE_ALLOCATION_FAILURE;
}
/* Read the next rectangle from the input file */ /* Read the next rectangle from the input file */
if (fread((char*)&rect->d, SIZEOF_RECTDATATYPE, 1, fp) != 1) if (fread((char *)&rect->d, SIZEOF_RECTDATATYPE, 1, fp) != 1)
{ {
fprintf(stderr, "Error: read of rectangle %d (of %d) failed! ", fprintf(stderr, "Error: read of rectangle %d (of %d) failed! ",
i, numRects); i, numRects);
fprintf(stderr, "feof=%d ferror=%d\n", fprintf(stderr, "feof=%d ferror=%d\n", feof(fp), ferror(fp));
feof(fp), ferror(fp));
return PLANE_DATA_READ_ERROR; return PLANE_DATA_READ_ERROR;
} }
@ -94,23 +96,23 @@ static uint8_t wld_LoadWorldPlane(FILE *fp, rect_head_t *list, uint8_t numRects)
* This function loads the world data from the opened file * This function loads the world data from the opened file
************************************************************************/ ************************************************************************/
uint8_t wld_load_planes(FILE *fp) uint8_t wld_load_planes(FILE * fp)
{ {
plane_file_header_t fileHeader; plane_file_header_t fileHeader;
uint8_t result; uint8_t result;
/* Read the plane file header */ /* Read the plane file header */
if (fread((char*)&fileHeader, SIZEOF_PLANEFILEHEADERTYPE, 1, fp) != 1) if (fread((char *)&fileHeader, SIZEOF_PLANEFILEHEADERTYPE, 1, fp) != 1)
return PLANE_HEADER_READ_ERROR; return PLANE_HEADER_READ_ERROR;
/* Then load each grid, performing run length (rle) decoding */ /* Then load each grid, performing run length (rle) decoding */
result = wld_LoadWorldPlane(fp, &xPlane, fileHeader.numXRects); result = wld_load_worldplane(fp, &g_xplane_list, fileHeader.numXRects);
if (!result) if (!result)
result = wld_LoadWorldPlane(fp, &yPlane, fileHeader.numYRects); result = wld_load_worldplane(fp, &g_yplane_list, fileHeader.numYRects);
if (!result) if (!result)
result = wld_LoadWorldPlane(fp, &zPlane, fileHeader.numZRects); result = wld_load_worldplane(fp, &g_zplane_list, fileHeader.numZRects);
return result; return result;
} }

View File

@ -47,7 +47,6 @@
#include "wld_graphicfile.h" #include "wld_graphicfile.h"
#include "wld_utils.h" #include "wld_utils.h"
/************************************************************************* /*************************************************************************
* Private Functions * Private Functions
*************************************************************************/ *************************************************************************/
@ -58,7 +57,7 @@
* Skip white space and comments. * Skip white space and comments.
************************************************************************/ ************************************************************************/
static void skip_cruft(FILE *fp) static void skip_cruft(FILE * fp)
{ {
int c; int c;
@ -97,7 +96,7 @@ static void skip_cruft(FILE *fp)
* Description: * Description:
************************************************************************/ ************************************************************************/
graphic_file_t *wld_LoadPPM(FILE *fp, char *filename) graphic_file_t *wld_LoadPPM(FILE * fp, char *filename)
{ {
int width, height; int width, height;
int unknown; int unknown;
@ -132,7 +131,7 @@ graphic_file_t *wld_LoadPPM(FILE *fp, char *filename)
gfile->palette = NULL; gfile->palette = NULL;
gfile->width = width; gfile->width = width;
gfile->height = height; gfile->height = height;
gfile->bitmap = (uint8_t*)wld_malloc(height * width * 3); gfile->bitmap = (uint8_t *) wld_malloc(height * width * 3);
if (fread(gfile->bitmap, height * width * 3, 1, fp) != 1) if (fread(gfile->bitmap, height * width * 3, 1, fp) != 1)
{ {

View File

@ -53,7 +53,7 @@
****************************************************************************/ ****************************************************************************/
#if RGB_CUBE_SIZE < MIN_LUM_LEVELS #if RGB_CUBE_SIZE < MIN_LUM_LEVELS
static uint8_t wld_lum2formtype(color_form_t *lum) static uint8_t wld_lum2formtype(color_form_t * lum)
{ {
float factor1; float factor1;
float factor2; float factor2;
@ -68,11 +68,11 @@ static uint8_t wld_lum2formtype(color_form_t *lum)
factor1 = g_wld_colorform[0].max - lum->max; factor1 = g_wld_colorform[0].max - lum->max;
factor2 = g_wld_colorform[0].mid - lum->mid; factor2 = g_wld_colorform[0].mid - lum->mid;
factor3 = g_wld_colorform[0].min - lum->min; factor3 = g_wld_colorform[0].min - lum->min;
lse = factor1*factor1 + factor2*factor2 + factor3*factor3; lse = factor1 * factor1 + factor2 * factor2 + factor3 * factor3;
formno = 0; formno = 0;
/* Now, search the rest of the table, keeping the form with least /* Now, search the rest of the table, keeping the form with least squared
* squared error value * error value
*/ */
for (i = 1; i < NCOLOR_FORMS; i++) for (i = 1; i < NCOLOR_FORMS; i++)
@ -80,7 +80,7 @@ static uint8_t wld_lum2formtype(color_form_t *lum)
factor1 = g_wld_colorform[i].max - lum->max; factor1 = g_wld_colorform[i].max - lum->max;
factor2 = g_wld_colorform[i].mid - lum->mid; factor2 = g_wld_colorform[i].mid - lum->mid;
factor3 = g_wld_colorform[i].min - lum->min; factor3 = g_wld_colorform[i].min - lum->min;
error = factor1*factor1 + factor2*factor2 + factor3*factor3; error = factor1 * factor1 + factor2 * factor2 + factor3 * factor3;
if (error < lse) if (error < lse)
{ {
lse = error; lse = error;
@ -102,7 +102,7 @@ static uint8_t wld_lum2formtype(color_form_t *lum)
****************************************************************************/ ****************************************************************************/
#if RGB_CUBE_SIZE < MIN_LUM_LEVELS #if RGB_CUBE_SIZE < MIN_LUM_LEVELS
static enum unit_vector_index_e wld_lum2colorform(color_lum_t *lum) static enum unit_vector_index_e wld_lum2colorform(color_lum_t * lum)
{ {
color_form_t orderedLum; color_form_t orderedLum;
enum unit_vector_index_e uvndx; enum unit_vector_index_e uvndx;
@ -163,7 +163,7 @@ static enum unit_vector_index_e wld_lum2colorform(color_lum_t *lum)
} }
else else
{ {
/* GREEN >= BLUE > RED*/ /* GREEN >= BLUE > RED */
orderedLum.max = lum->green; orderedLum.max = lum->green;
orderedLum.mid = lum->blue; orderedLum.mid = lum->blue;
@ -191,7 +191,7 @@ static enum unit_vector_index_e wld_lum2colorform(color_lum_t *lum)
* Description: Convert an RGB-Luminance value into a pixel * Description: Convert an RGB-Luminance value into a pixel
****************************************************************************/ ****************************************************************************/
wld_pixel_t wld_color_lum2pixel(color_lum_t *lum) wld_pixel_t wld_color_lum2pixel(color_lum_t * lum)
{ {
#if RGB_CUBE_SIZE < MIN_LUM_LEVELS #if RGB_CUBE_SIZE < MIN_LUM_LEVELS
enum unit_vector_index_e uvndx; enum unit_vector_index_e uvndx;
@ -201,18 +201,18 @@ wld_pixel_t wld_color_lum2pixel(color_lum_t *lum)
uvndx = wld_lum2colorform(lum); uvndx = wld_lum2colorform(lum);
/* Get the luminance number associated with this lum at this index /* Get the luminance number associated with this lum at this index Make sure
* Make sure that the requested luminance does not exceed the maximum * that the requested luminance does not exceed the maximum allowed for this
* allowed for this unit vector. * unit vector.
*/ */
if (lum->luminance >= g_unit_vector[uvndx].luminance) if (lum->luminance >= g_unit_vector[uvndx].luminance)
{ {
lumndx = (NLUMINANCES-1); lumndx = (NLUMINANCES - 1);
} }
else else
{ {
lumndx = (uint8_t)((float)NLUMINANCES lumndx = (uint8_t) ((float)NLUMINANCES
* lum->luminance / g_unit_vector[uvndx].luminance); * lum->luminance / g_unit_vector[uvndx].luminance);
if (lumndx > 0) if (lumndx > 0)
{ {
@ -221,8 +221,8 @@ wld_pixel_t wld_color_lum2pixel(color_lum_t *lum)
} }
/* Now get the pixel value from the unit vector index and the luminance /* Now get the pixel value from the unit vector index and the luminance
* number. We will probably have to expand this later from the 8-bit * number. We will probably have to expand this later from the 8-bit index
* index to a wider representation. * to a wider representation.
*/ */
return TRV_UVLUM2NDX(uvndx, lumndx); return TRV_UVLUM2NDX(uvndx, lumndx);

View File

@ -61,5 +61,6 @@ void *wld_malloc(size_t size)
{ {
wld_fatal_error("out of memory (wld_malloc %x bytes)", size); wld_fatal_error("out of memory (wld_malloc %x bytes)", size);
} }
return new; return new;
} }

View File

@ -52,7 +52,7 @@
* This function concatenates two world plane lists * This function concatenates two world plane lists
************************************************************************/ ************************************************************************/
void wld_merge_planelists(rect_head_t *outList, rect_head_t *inList) void wld_merge_planelists(rect_head_t * outList, rect_head_t * inList)
{ {
rect_list_t *inRect, *nextInRect; rect_list_t *inRect, *nextInRect;
rect_list_t *outRect, *prevRect; rect_list_t *outRect, *prevRect;
@ -67,24 +67,21 @@ void wld_merge_planelists(rect_head_t *outList, rect_head_t *inList)
{ {
nextInRect = inRect->flink; nextInRect = inRect->flink;
/* Search the output plane list to find the location to insert the /* Search the output plane list to find the location to insert the input
* input rectangle. Each is list is maintained in ascending plane * rectangle. Each is list is maintained in ascending plane order.
* order.
*/ */
for (; for (;
((outRect) && (outRect->d.plane < inRect->d.plane)); ((outRect) && (outRect->d.plane < inRect->d.plane));
outRect = outRect->flink); outRect = outRect->flink);
/* Add the inRect to the spot found in the list. Check if the /* Add the inRect to the spot found in the list. Check if the inRect
* inRect goes at the one of the ends of the list. * goes at the one of the ends of the list. */
*/
if (!outRect) if (!outRect)
{ {
/* No rectangle with plane larger than the one to be added /* No rectangle with plane larger than the one to be added was found
* was found in the list. The inRect goes at the end of * in the list. The inRect goes at the end of the list.
* the list.
*/ */
prevRect = outList->tail; prevRect = outList->tail;

View File

@ -54,22 +54,30 @@
* then adds it to the world plane destList * then adds it to the world plane destList
************************************************************************/ ************************************************************************/
void wld_move_plane(rect_list_t *rect, rect_head_t *destList, void wld_move_plane(rect_list_t * rect, rect_head_t * destList,
rect_head_t *srcList) rect_head_t * srcList)
{ {
/* Un-hook the backward link to the rect */ /* Un-hook the backward link to the rect */
if (rect->flink) if (rect->flink)
{
rect->flink->blink = rect->blink; rect->flink->blink = rect->blink;
}
else else
{
srcList->tail = rect->blink; srcList->tail = rect->blink;
}
/* Un-hook the forward link to the rect */ /* Un-hook the forward link to the rect */
if (rect->blink) if (rect->blink)
{
rect->blink->flink = rect->flink; rect->blink->flink = rect->flink;
}
else else
{
srcList->head = rect->flink; srcList->head = rect->flink;
}
/* Then add the rect to the specified list */ /* Then add the rect to the specified list */

View File

@ -47,13 +47,13 @@
*************************************************************************/ *************************************************************************/
/************************************************************************* /*************************************************************************
* Name: * Name: wld_new_graphicfile
* Description: * Description:
************************************************************************/ ************************************************************************/
graphic_file_t *wld_new_graphicfile( void ) graphic_file_t *wld_new_graphicfile(void)
{ {
graphic_file_t *gf = (graphic_file_t*)wld_malloc(sizeof(graphic_file_t)); graphic_file_t *gf = (graphic_file_t *) wld_malloc(sizeof(graphic_file_t));
gf->transparent_entry = -1; gf->transparent_entry = -1;

View File

@ -70,7 +70,7 @@ rect_list_t *wld_new_plane(void)
{ {
/* Nothing on the free list. Allocate a new one */ /* Nothing on the free list. Allocate a new one */
rect = (rect_list_t*)wld_malloc(sizeof(rect_list_t)); rect = (rect_list_t *) wld_malloc(sizeof(rect_list_t));
} }
return rect; return rect;

View File

@ -40,11 +40,11 @@
* Included files * Included files
*************************************************************************/ *************************************************************************/
#include <stdio.h> # include <stdio.h>
#include <malloc.h> # include <malloc.h>
#include "trv_types.h" # include "trv_types.h"
#include "wld_mem.h" # include "wld_mem.h"
#include "wld_pcx.h" # include "wld_pcx.h"
/************************************************************************* /*************************************************************************
* Public Functions * Public Functions
@ -57,7 +57,7 @@
************************************************************************/ ************************************************************************/
uint8_t wld_pcx_init(pcxPicturePtr image, uint16_t height, uint16_t width, uint8_t wld_pcx_init(pcxPicturePtr image, uint16_t height, uint16_t width,
RGBColor *palette, uint8_t *buffer) RGBColor * palette, uint8_t * buffer)
{ {
image->palette = palette; image->palette = palette;
@ -67,7 +67,7 @@ uint8_t wld_pcx_init(pcxPicturePtr image, uint16_t height, uint16_t width,
} }
else else
{ {
image->buffer = (uint8_t*)wld_malloc(height * width + 1); image->buffer = (uint8_t *) wld_malloc(height * width + 1);
} }
if (!image->buffer) if (!image->buffer)

View File

@ -49,14 +49,14 @@
* Private Data * Private Data
*************************************************************************/ *************************************************************************/
static float g_cube2pixel = (float)TRV_PIXEL_MAX / (float)(RGB_CUBE_SIZE-1); static float g_cube2pixel = (float)TRV_PIXEL_MAX / (float)(RGB_CUBE_SIZE - 1);
/************************************************************************* /*************************************************************************
* Function: wld_pixel2lum * Function: wld_pixel2lum
* Description: Convert a pixel value into RGB-Luminance value. * Description: Convert a pixel value into RGB-Luminance value.
************************************************************************/ ************************************************************************/
void wld_pixel2lum(trv_pixel_t pixel_value, color_lum_t *lum) void wld_pixel2lum(trv_pixel_t pixel_value, color_lum_t * lum)
{ {
dev_pixel_t devpixel = g_devpixel_lut[pixel_value]; dev_pixel_t devpixel = g_devpixel_lut[pixel_value];
@ -69,8 +69,7 @@ void wld_pixel2lum(trv_pixel_t pixel_value, color_lum_t *lum)
/* Get the luminance associated with the RGB value */ /* Get the luminance associated with the RGB value */
lum->luminance = sqrt(lum->red * lum->red + lum->luminance = sqrt(lum->red * lum->red +
lum->green * lum->green + lum->green * lum->green + lum->blue * lum->blue);
lum->blue * lum->blue);
/* Convert the RGB Component into unit vector + luminance */ /* Convert the RGB Component into unit vector + luminance */

View File

@ -51,12 +51,11 @@
* for each of the X, Y, and Z planes. * for each of the X, Y, and Z planes.
*/ */
rect_head_t xPlane; /* list of X=plane rectangles */ rect_head_t g_xplane_list; /* list of X=plane rectangles */
rect_head_t yPlane; /* list of Y=plane rectangles */ rect_head_t g_yplane_list; /* list of Y=plane rectangles */
rect_head_t zPlane; /* list of Z=plane rectangles */ rect_head_t g_zplane_list; /* list of Z=plane rectangles */
rect_list_t *freeList; rect_list_t *freeList;
/************************************************************************* /*************************************************************************
* Private Variables * Private Variables
*************************************************************************/ *************************************************************************/

View File

@ -150,9 +150,9 @@ typedef struct
* for each of the X, Y, and Z planes. * for each of the X, Y, and Z planes.
*/ */
extern rect_head_t xPlane; /* list of X=plane rectangles */ extern rect_head_t g_xplane_list; /* list of X=plane rectangles */
extern rect_head_t yPlane; /* list of Y=plane rectangles */ extern rect_head_t g_yplane_list; /* list of Y=plane rectangles */
extern rect_head_t zPlane; /* list of Z=plane rectangles */ extern rect_head_t g_zplane_list; /* list of Z=plane rectangles */
/* This is the maximum value of a texture code */ /* This is the maximum value of a texture code */

View File

@ -53,17 +53,20 @@
* Read a decimal number from the steam fp * Read a decimal number from the steam fp
************************************************************************/ ************************************************************************/
int16_t wld_read_decimal(FILE *fp) int16_t wld_read_decimal(FILE * fp)
{ {
int16_t value = 0; int16_t value = 0;
bool negative = false; bool negative = false;
int ch; int ch;
/* Skip over any leading spaces, new lines, or carriage returns (for /* Skip over any leading spaces, new lines, or carriage returns (for MSDOS
* MSDOS compatibility) * compatibility)
*/ */
do ch = getc(fp); do
{
ch = getc(fp);
}
while ((ch == ' ') || (ch == '\n') || (ch == '\r')); while ((ch == ' ') || (ch == '\n') || (ch == '\r'));
/* if the first character is '-', then its a negative number */ /* if the first character is '-', then its a negative number */
@ -78,13 +81,16 @@ int16_t wld_read_decimal(FILE *fp)
while ((ch >= '0') && (ch <= '9')) while ((ch >= '0') && (ch <= '9'))
{ {
value = 10*value + (ch - (int)'0'); value = 10 * value + (ch - (int)'0');
ch = getc(fp); ch = getc(fp);
} }
/* Apply the negation, if appropriate */ /* Apply the negation, if appropriate */
if (negative) value = -value; if (negative)
{
value = -value;
}
return value; return value;
} }

View File

@ -47,8 +47,8 @@
#include "wld_pcx.h" #include "wld_pcx.h"
#include "wld_utils.h" #include "wld_utils.h"
graphic_file_t *wld_LoadPPM(FILE *fp, char *filename); graphic_file_t *wld_LoadPPM(FILE * fp, char *filename);
graphic_file_t *wld_LoadGIF(FILE *fp, char *filename); graphic_file_t *wld_LoadGIF(FILE * fp, char *filename);
/************************************************************************* /*************************************************************************
* Private Data * Private Data
@ -65,7 +65,7 @@ static const char pcxExtension[] = ".PCX";
* Description: * Description:
************************************************************************/ ************************************************************************/
static graphic_file_format_t wld_CheckFormat(FILE *fp, char *filename) static graphic_file_format_t wld_CheckFormat(FILE * fp, char *filename)
{ {
char magic[MAGIC_LENGTH]; char magic[MAGIC_LENGTH];
@ -101,7 +101,7 @@ static graphic_file_format_t wld_CheckFormat(FILE *fp, char *filename)
/* Check if the extension matches */ /* Check if the extension matches */
for (ptr2 = (char*)pcxExtension; ((*ptr1) && (*ptr2)); ptr1++, ptr2++) for (ptr2 = (char *)pcxExtension; ((*ptr1) && (*ptr2)); ptr1++, ptr2++)
{ {
if (toupper((int)*ptr1) != *ptr2) if (toupper((int)*ptr1) != *ptr2)
{ {
@ -109,8 +109,8 @@ static graphic_file_format_t wld_CheckFormat(FILE *fp, char *filename)
} }
} }
/* If it is an exact match, both pointers should refer to the /* If it is an exact match, both pointers should refer to the NULL
* NULL terminator. * terminator.
*/ */
if (!(*ptr1) && !(*ptr2)) if (!(*ptr1) && !(*ptr2))
@ -177,4 +177,3 @@ graphic_file_t *wld_readgraphic_file(char *filename)
fclose(fp); fclose(fp);
return gfile; return gfile;
} }

View File

@ -75,16 +75,24 @@ static int wld_log2(int x)
unsigned int n; unsigned int n;
if (x <= 0) if (x <= 0)
{
return -1; return -1;
}
else else
n = (unsigned int) x; {
n = (unsigned int)x;
}
for (i = 0; (n & 0x1) == 0; i++, n >>= 1); for (i = 0; (n & 0x1) == 0; i++, n >>= 1);
if (n == 1) if (n == 1)
{
return i; return i;
}
else else
{
return -1; return -1;
}
} }
/************************************************************************* /*************************************************************************
@ -97,10 +105,12 @@ static wld_bitmap_t *wld_new_texture(uint16_t width, uint16_t height)
wld_bitmap_t *t; wld_bitmap_t *t;
if (height <= 0 || width <= 0) if (height <= 0 || width <= 0)
{
wld_fatal_error("wld_new_texture: bad texture dimensions"); wld_fatal_error("wld_new_texture: bad texture dimensions");
}
t = (wld_bitmap_t*)wld_malloc(sizeof(wld_bitmap_t)); t = (wld_bitmap_t *) wld_malloc(sizeof(wld_bitmap_t));
t->bm = (trv_pixel_t*)wld_malloc(height * width * sizeof(trv_pixel_t)); t->bm = (trv_pixel_t *) wld_malloc(height * width * sizeof(trv_pixel_t));
t->w = width; t->w = width;
t->h = height; t->h = height;
@ -114,7 +124,7 @@ static wld_bitmap_t *wld_new_texture(uint16_t width, uint16_t height)
* Description: * Description:
************************************************************************/ ************************************************************************/
static void wld_quantize_texture(graphic_file_t *gFile, wld_bitmap_t *t) static void wld_quantize_texture(graphic_file_t * gFile, wld_bitmap_t * t)
{ {
RGBColor pixel; RGBColor pixel;
trv_pixel_t *destPixel = t->bm; trv_pixel_t *destPixel = t->bm;
@ -146,15 +156,17 @@ wld_bitmap_t *wld_read_texturefile(char *filename)
gFile = wld_readgraphic_file(filename); gFile = wld_readgraphic_file(filename);
if (gFile == NULL) if (gFile == NULL)
{
wld_fatal_error("Error reading texture %s.", filename); wld_fatal_error("Error reading texture %s.", filename);
}
/* The height and width should be powers of two for efficient /* The height and width should be powers of two for efficient texture
* texture mapping. Here, we enforce this. * 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); wld_fatal_error("Dimensions texture %s are not powers of two.", filename);
}
t = wld_new_texture(gFile->width, gFile->height); t = wld_new_texture(gFile->width, gFile->height);
wld_quantize_texture(gFile, t); wld_quantize_texture(gFile, t);

View File

@ -61,5 +61,6 @@ void *wld_realloc(void *addr, size_t size)
{ {
wld_fatal_error("out of memory (wtrealloc %x bytes)", size); wld_fatal_error("out of memory (wtrealloc %x bytes)", size);
} }
return new; return new;
} }

View File

@ -54,21 +54,29 @@
* and "deallocates" it by saving it on the free list * and "deallocates" it by saving it on the free list
************************************************************************/ ************************************************************************/
void wld_remove_plane(rect_list_t *rect, rect_head_t *list) void wld_remove_plane(rect_list_t * rect, rect_head_t * list)
{ {
/* Un-hook the backward link to the rect */ /* Un-hook the backward link to the rect */
if (rect->flink) if (rect->flink)
{
rect->flink->blink = rect->blink; rect->flink->blink = rect->blink;
}
else else
{
list->tail = rect->blink; list->tail = rect->blink;
}
/* Un-hook the forward link to the rect */ /* Un-hook the forward link to the rect */
if (rect->blink) if (rect->blink)
{
rect->blink->flink = rect->flink; rect->blink->flink = rect->flink;
}
else else
{
list->head = rect->flink; list->head = rect->flink;
}
/* Then put the rect on the free list */ /* Then put the rect on the free list */

View File

@ -49,13 +49,13 @@
* TRV_PIXEL_MAX. * TRV_PIXEL_MAX.
****************************************************************************/ ****************************************************************************/
trv_pixel_t wld_rgb2pixel(color_rgb_t *pixel) trv_pixel_t wld_rgb2pixel(color_rgb_t * pixel)
{ {
#if RGB_CUBE_SIZE < MIN_LUM_LEVELS #if RGB_CUBE_SIZE < MIN_LUM_LEVELS
color_lum_t lum; color_lum_t lum;
/* Convert the RGB Value into a luminance value. /* Convert the RGB Value into a luminance value. Get the luminance associated
* Get the luminance associated with the RGB value. * with the RGB value.
*/ */
lum.luminance = sqrt(pixel->red * pixel->red lum.luminance = sqrt(pixel->red * pixel->red

View File

@ -59,6 +59,7 @@
****************************************************************************/ ****************************************************************************/
#if RGB_CUBE_SIZE < MIN_LUM_LEVELS #if RGB_CUBE_SIZE < MIN_LUM_LEVELS
/* These arrays map color forms into g_unit_vector array indices */ /* These arrays map color forms into g_unit_vector array indices */
static const enum unit_vector_index_e g_wld_bgrform_map[NCOLOR_FORMS] = static const enum unit_vector_index_e g_wld_bgrform_map[NCOLOR_FORMS] =
@ -100,42 +101,42 @@ static float g_wld_cube2pixel;
****************************************************************************/ ****************************************************************************/
#if RGB_CUBE_SIZE < MIN_LUM_LEVELS #if RGB_CUBE_SIZE < MIN_LUM_LEVELS
FAR color_lum_t *g_pixel2um_lut; color_lum_t *g_pixel2um_lut;
/* The following defines the "form" of each color in the g_unit_vector array */ /* The following defines the "form" of each color in the g_unit_vector array */
const color_form_t g_wld_colorform[NCOLOR_FORMS] = const color_form_t g_wld_colorform[NCOLOR_FORMS] =
{ {
{ 1.0, 0.0, 0.0 }, {1.0, 0.0, 0.0},
{ 0.875, 0.4841229, 0.0 }, {0.875, 0.4841229, 0.0},
{ 0.7071068, 0.7071068, 0.0 }, {0.7071068, 0.7071068, 0.0},
{ 0.6666667, 0.5270463, 0.5270463 }, {0.6666667, 0.5270463, 0.5270463},
{ 0.5773503, 0.5773503, 0.5773503 } {0.5773503, 0.5773503, 0.5773503}
}; };
/* This array defines each color supported in the luminance model */ /* This array defines each color supported in the luminance model */
const color_lum_t g_unit_vector[NUNIT_VECTORS] = const color_lum_t g_unit_vector[NUNIT_VECTORS] =
{ {
{ 0.5773503, 0.5773503, 0.5773503, 441.672932,}, /* GREY_NDX */ {0.5773503, 0.5773503, 0.5773503, 441.672932,}, /* GREY_NDX */
{ 0.0, 0.0, 1.0, 255.0 }, /* BLUE_NDX */ {0.0, 0.0, 1.0, 255.0}, /* BLUE_NDX */
{ 0.0, 0.4841229, 0.875, 291.428571 }, /* GREENERBLUE_NDX */ {0.0, 0.4841229, 0.875, 291.428571}, /* GREENERBLUE_NDX */
{ 0.0, 0.7071068, 0.7071068, 360.624445 }, /* BLUEGREEN_NDX */ {0.0, 0.7071068, 0.7071068, 360.624445}, /* BLUEGREEN_NDX */
{ 0.4841229, 0.0, 0.875, 291.428571 }, /* BLUEVIOLET_NDX */ {0.4841229, 0.0, 0.875, 291.428571}, /* BLUEVIOLET_NDX */
{ 0.7071068, 0.0, 0.7071068, 360.624445 }, /* VIOLET_NDX */ {0.7071068, 0.0, 0.7071068, 360.624445}, /* VIOLET_NDX */
{ 0.5270463, 0.5270463, 0.6666667, 382.499981 }, /* LIGHTBLUE_NDX */ {0.5270463, 0.5270463, 0.6666667, 382.499981}, /* LIGHTBLUE_NDX */
{ 0.0, 1.0, 0.0, 255.0 }, /* GREEN_NDX */ {0.0, 1.0, 0.0, 255.0}, /* GREEN_NDX */
{ 0.0, 0.875, 0.4841229, 291.428571 }, /* BLUERGREN_NDX */ {0.0, 0.875, 0.4841229, 291.428571}, /* BLUERGREN_NDX */
{ 0.4841229, 0.875, 0.0, 291.428571 }, /* YELLOWGREEN_NDX */ {0.4841229, 0.875, 0.0, 291.428571}, /* YELLOWGREEN_NDX */
{ 0.7071068, 0.7071068, 0.0, 360.624445 }, /* YELLOW_NDX */ {0.7071068, 0.7071068, 0.0, 360.624445}, /* YELLOW_NDX */
{ 0.5270463, 0.6666667, 0.5270463, 382.499981 }, /* LIGHTGREEN_NDX */ {0.5270463, 0.6666667, 0.5270463, 382.499981}, /* LIGHTGREEN_NDX */
{ 1.0, 0.0, 0.0, 255.0 }, /* RED_NDX */ {1.0, 0.0, 0.0, 255.0}, /* RED_NDX */
{ 0.875, 0.0, 0.4841229, 291.428571 }, /* REDVIOLET_NDX */ {0.875, 0.0, 0.4841229, 291.428571}, /* REDVIOLET_NDX */
{ 0.875, 0.4841229, 0.0, 291.428571 }, /* ORANGE_NDX */ {0.875, 0.4841229, 0.0, 291.428571}, /* ORANGE_NDX */
{ 0.6666667, 0.5270463, 0.5270463, 382.499981 }, /* PINK_NDX */ {0.6666667, 0.5270463, 0.5270463, 382.499981}, /* PINK_NDX */
}; };
#endif #endif
@ -159,8 +160,8 @@ void wld_rgblookup_allocate(void)
/* Check if a color lookup table has been allocated */ /* Check if a color lookup table has been allocated */
g_devpixel_lut = (dev_pixel_t*) g_devpixel_lut = (dev_pixel_t *)
wld_malloc(sizeof(dev_pixel_t) * (NUNIT_VECTORS*NLUMINANCES)); wld_malloc(sizeof(dev_pixel_t) * (NUNIT_VECTORS * NLUMINANCES));
if (!g_devpixel_lut) if (!g_devpixel_lut)
{ {
@ -169,12 +170,11 @@ void wld_rgblookup_allocate(void)
lut = g_devpixel_lut; lut = g_devpixel_lut;
/* Save the color information and color lookup table for use in /* Save the color information and color lookup table for use in color mapping
* color mapping below. * below. */
*/
g_pixel2um_lut = (color_lum_t*) g_pixel2um_lut = (color_lum_t *)
wld_malloc(sizeof(color_lum_t) * (NUNIT_VECTORS*NLUMINANCES)); wld_malloc(sizeof(color_lum_t) * (NUNIT_VECTORS * NLUMINANCES));
if (!g_pixel2um_lut) if (!g_pixel2um_lut)
{ {
@ -189,24 +189,22 @@ void wld_rgblookup_allocate(void)
for (lumndx = 0; lumndx < NLUMINANCES; lumndx++) for (lumndx = 0; lumndx < NLUMINANCES; lumndx++)
{ {
color_rgb_t color; color_rgb_t color;
FAR color_lum_t *lum; color_lum_t *lum;
/* Get a convenience pointer to the lookup table entry */ /* Get a convenience pointer to the lookup table entry */
lum = &g_pixel2um_lut[index]; lum = &g_pixel2um_lut[index];
*lum = g_unit_vector[uvndx]; *lum = g_unit_vector[uvndx];
/* Get the luminance associated with this lum for this /* Get the luminance associated with this lum for this unit vector. */
* unit vector.
*/
lum->luminance = (lum->luminance * (float)(lumndx + 1)) / NLUMINANCES; lum->luminance = (lum->luminance * (float)(lumndx + 1)) / NLUMINANCES;
/* Convert to RGB and allocate the color */ /* Convert to RGB and allocate the color */
color.red = (short) (lum->red * lum->luminance); color.red = (short)(lum->red * lum->luminance);
color.green = (short) (lum->green * lum->luminance); color.green = (short)(lum->green * lum->luminance);
color.blue = (short) (lum->blue * lum->luminance); color.blue = (short)(lum->blue * lum->luminance);
/* Save the RGB to pixel lookup data */ /* Save the RGB to pixel lookup data */
@ -221,24 +219,23 @@ void wld_rgblookup_allocate(void)
/* Check if a color lookup table has been allocated */ /* Check if a color lookup table has been allocated */
g_devpixel_lut = (dev_pixel_t*) g_devpixel_lut = (dev_pixel_t *)
wld_malloc(sizeof(dev_pixel_t) * (WLD_PIXEL_MAX+1)); wld_malloc(sizeof(dev_pixel_t) * (WLD_PIXEL_MAX + 1));
if (!g_devpixel_lut) if (!g_devpixel_lut)
{ {
wld_fatal_error("ERROR: Failed to allocate color lookup table\n"); wld_fatal_error("ERROR: Failed to allocate color lookup table\n");
} }
/* Save the color information and color lookup table for use in /* Save the color information and color lookup table for use in subsequent
* subsequent color mapping. * color mapping. */
*/
lut = g_devpixel_lut; lut = g_devpixel_lut;
/* Check if a Pixel-to-RGB color mapping table has been allocated */ /* Check if a Pixel-to-RGB color mapping table has been allocated */
g_devpixel_lut = (color_rgb_t*) g_devpixel_lut = (color_rgb_t *)
wld_malloc(sizeof(color_rgb_t) * (WLD_PIXEL_MAX+1)); wld_malloc(sizeof(color_rgb_t) * (WLD_PIXEL_MAX + 1));
if (!g_devpixel_lut) if (!g_devpixel_lut)
{ {
@ -248,16 +245,14 @@ void wld_rgblookup_allocate(void)
for (index = 0; index <= WLD_PIXEL_MAX; index++) for (index = 0; index <= WLD_PIXEL_MAX; index++)
{ {
g_devpixel_lut[index].red g_devpixel_lut[index].red
= g_devpixel_lut[index].green = g_devpixel_lut[index].green = g_devpixel_lut[index].blue = 0;
= g_devpixel_lut[index].blue = 0;
} }
/* Calculate the cube to trv_pixel_t scale factor. This factor will /* Calculate the cube to trv_pixel_t scale factor. This factor will convert
* convert an RGB component in the range {0..RGB_CUBE_SIZE-1} to * an RGB component in the range {0..RGB_CUBE_SIZE-1} to a value in the range
* a value in the range {0..WLD_PIXEL_MAX}. * {0..WLD_PIXEL_MAX}. */
*/
g_wld_cube2pixel = (float)WLD_PIXEL_MAX / (float)(RGB_CUBE_SIZE-1); g_wld_cube2pixel = (float)WLD_PIXEL_MAX / (float)(RGB_CUBE_SIZE - 1);
/* Allocate each color in the RGB Cube */ /* Allocate each color in the RGB Cube */
@ -267,9 +262,9 @@ void wld_rgblookup_allocate(void)
{ {
color_rgb_t color; color_rgb_t color;
color.red = (short) (rgb.red * 65535 / (RGB_CUBE_SIZE - 1)); color.red = (short)(rgb.red * 65535 / (RGB_CUBE_SIZE - 1));
color.green = (short) (rgb.green * 65535 / (RGB_CUBE_SIZE - 1)); color.green = (short)(rgb.green * 65535 / (RGB_CUBE_SIZE - 1));
color.blue = (short) (rgb.blue * 65535 / (RGB_CUBE_SIZE - 1)); color.blue = (short)(rgb.blue * 65535 / (RGB_CUBE_SIZE - 1));
/* Save the RGB to pixel lookup data */ /* Save the RGB to pixel lookup data */

View File

@ -47,14 +47,13 @@
* Private Functions * Private Functions
*************************************************************************/ *************************************************************************/
/************************************************************************* /*************************************************************************
* Name: wld_CountRectangles * Name: wld_CountRectangles
* Description: * Description:
* This function counts the number of rectangles in one plane * This function counts the number of rectangles in one plane
************************************************************************/ ************************************************************************/
static uint16_t wld_CountRectangles(rect_list_t *rect) static uint16_t wld_CountRectangles(rect_list_t * rect)
{ {
uint16_t count; uint16_t count;
for (count = 0; (rect); count++, rect = rect->flink); for (count = 0; (rect); count++, rect = rect->flink);
@ -67,7 +66,7 @@ static uint16_t wld_CountRectangles(rect_list_t *rect)
* This function stores the world data for one plane * This function stores the world data for one plane
************************************************************************/ ************************************************************************/
static uint8_t wld_SaveWorldPlane(FILE *fp, rect_list_t *rect) static uint8_t wld_SaveWorldPlane(FILE * fp, rect_list_t * rect)
{ {
/* For each rectangle in the list */ /* For each rectangle in the list */
@ -75,7 +74,7 @@ static uint8_t wld_SaveWorldPlane(FILE *fp, rect_list_t *rect)
{ {
/* Write the rectangle to the output file */ /* Write the rectangle to the output file */
if (fwrite((char*)&rect->d, SIZEOF_RECTDATATYPE, 1, fp) != 1) if (fwrite((char *)&rect->d, SIZEOF_RECTDATATYPE, 1, fp) != 1)
return PLANE_DATA_WRITE_ERROR; return PLANE_DATA_WRITE_ERROR;
} }
@ -101,28 +100,38 @@ uint8_t wld_save_planes(const char *wldFile)
/* Open the file which contains the description of the world */ /* Open the file which contains the description of the world */
fp = fopen(wldFile, "wb"); fp = fopen(wldFile, "wb");
if (!fp) return PLANE_WRITE_OPEN_ERROR; if (!fp)
{
return PLANE_WRITE_OPEN_ERROR;
}
/* Create world file header */ /* Create world file header */
fileHeader.numXRects = wld_CountRectangles(xPlane.head); fileHeader.numXRects = wld_CountRectangles(g_xplane_list.head);
fileHeader.numYRects = wld_CountRectangles(yPlane.head); fileHeader.numYRects = wld_CountRectangles(g_yplane_list.head);
fileHeader.numZRects = wld_CountRectangles(zPlane.head); fileHeader.numZRects = wld_CountRectangles(g_zplane_list.head);
/* Write the file header to the output file */ /* Write the file header to the output file */
if (fwrite((char*)&fileHeader, SIZEOF_PLANEFILEHEADERTYPE, 1, fp) != 1) if (fwrite((char *)&fileHeader, SIZEOF_PLANEFILEHEADERTYPE, 1, fp) != 1)
{
result = PLANE_HEADER_WRITE_ERROR; result = PLANE_HEADER_WRITE_ERROR;
}
/* Save the world, one plane at a time */ /* Save the world, one plane at a time */
else else
{ {
result = wld_SaveWorldPlane(fp, xPlane.head); result = wld_SaveWorldPlane(fp, g_xplane_list.head);
if (result == PLANE_SUCCESS) if (result == PLANE_SUCCESS)
result = wld_SaveWorldPlane(fp, yPlane.head); {
result = wld_SaveWorldPlane(fp, g_yplane_list.head);
}
if (result == PLANE_SUCCESS) if (result == PLANE_SUCCESS)
wld_SaveWorldPlane(fp, zPlane.head); {
wld_SaveWorldPlane(fp, g_zplane_list.head);
}
} }
/* Close the file */ /* Close the file */

View File

@ -112,7 +112,7 @@ extern wld_coord_t runStepHeight;
* Global Function Prototypes * Global Function Prototypes
*************************************************************************/ *************************************************************************/
uint8_t wld_create_world(FAR char *mapfile); uint8_t wld_create_world(char *mapfile);
void wld_deallocate_world(void); void wld_deallocate_world(void);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -78,7 +78,8 @@ tcl_window_t windows[NUM_PLANES] =
.plane = EDITPLANE_X, .plane = EDITPLANE_X,
.width = WINDOW_SIZE, .width = WINDOW_SIZE,
.height = WINDOW_SIZE, .height = WINDOW_SIZE,
.palette = { .palette =
{
Lavender, Red, Red, LemonChiffon, Lavender, Red, Red, LemonChiffon,
LightCyan, LightSkyBlue, DeepSkyBlue, LightGray, LightCyan, LightSkyBlue, DeepSkyBlue, LightGray,
@ -94,7 +95,8 @@ tcl_window_t windows[NUM_PLANES] =
.plane = EDITPLANE_Y, .plane = EDITPLANE_Y,
.width = WINDOW_SIZE, .width = WINDOW_SIZE,
.height = WINDOW_SIZE, .height = WINDOW_SIZE,
.palette = { .palette =
{
Lavender, Red, Red, LemonChiffon, Lavender, Red, Red, LemonChiffon,
LightCyan, LightSkyBlue, DeepSkyBlue, LightGray, LightCyan, LightSkyBlue, DeepSkyBlue, LightGray,
@ -110,7 +112,8 @@ tcl_window_t windows[NUM_PLANES] =
.plane = EDITPLANE_Z, .plane = EDITPLANE_Z,
.width = WINDOW_SIZE, .width = WINDOW_SIZE,
.height = WINDOW_SIZE, .height = WINDOW_SIZE,
.palette = { .palette =
{
Lavender, Red, Red, LemonChiffon, Lavender, Red, Red, LemonChiffon,
LightCyan, LightSkyBlue, DeepSkyBlue, LightGray, LightCyan, LightSkyBlue, DeepSkyBlue, LightGray,
@ -120,8 +123,9 @@ tcl_window_t windows[NUM_PLANES] =
LightGray, DarkGray, DarkGray, DarkGray, LightGray, DarkGray, DarkGray, DarkGray,
LightSteelBlue, SlateGray, SlateGray, SteelBlue, LightSteelBlue, SlateGray, SlateGray, SteelBlue,
}, },
}, }
}; };
rect_data_t editRect; rect_data_t editRect;
/**************************************************************************** /****************************************************************************
@ -166,8 +170,7 @@ static void astUpdateNEWModeDisplay(void)
*/ */
static int astSetEditMode(ClientData clientData, static int astSetEditMode(ClientData clientData,
Tcl_Interp *interp, Tcl_Interp * interp, int argc, const char *argv[])
int argc, const char *argv[])
{ {
ginfo("Processing command: %s\n", argv[0]); ginfo("Processing command: %s\n", argv[0]);
@ -226,17 +229,16 @@ static int astSetEditMode(ClientData clientData,
} }
else else
{ {
wld_fatal_error("%s: Unrecognized mode: %s\n", wld_fatal_error("%s: Unrecognized mode: %s\n", __FUNCTION__, argv[1]);
__FUNCTION__, argv[1]);
} }
return TCL_OK; return TCL_OK;
} }
/* Called in response to the "ast_position" Tcl command */ /* Called in response to the "ast_position" Tcl command */
static int astNewPosition(ClientData clientData, static int astNewPosition(ClientData clientData,
Tcl_Interp *interp, Tcl_Interp * interp, int argc, const char *argv[])
int argc, const char *argv[])
{ {
ginfo("Processing command: %s\n", argv[0]); ginfo("Processing command: %s\n", argv[0]);
@ -260,8 +262,7 @@ static int astNewPosition(ClientData clientData,
/* Called in response to the "ast_zoom" Tcl command */ /* Called in response to the "ast_zoom" Tcl command */
static int astNewZoom(ClientData clientData, static int astNewZoom(ClientData clientData,
Tcl_Interp *interp, Tcl_Interp * interp, int argc, const char *argv[])
int argc, const char *argv[])
{ {
ginfo("Processing command: %s\n", argv[0]); ginfo("Processing command: %s\n", argv[0]);
@ -331,8 +332,7 @@ static int astNewZoom(ClientData clientData,
/* Called in response to the "ast_edit" Tcl command */ /* Called in response to the "ast_edit" Tcl command */
static int astNewEdit(ClientData clientData, static int astNewEdit(ClientData clientData,
Tcl_Interp *interp, Tcl_Interp * interp, int argc, const char *argv[])
int argc, const char *argv[])
{ {
int start; int start;
int end; int end;
@ -446,8 +446,7 @@ static int astNewEdit(ClientData clientData,
/* Called in response to the "ast_attribute" Tcl command */ /* Called in response to the "ast_attribute" Tcl command */
static int astNewAttributes(ClientData clientData, static int astNewAttributes(ClientData clientData,
Tcl_Interp *interp, Tcl_Interp * interp, int argc, const char *argv[])
int argc, const char *argv[])
{ {
const char *attributes; const char *attributes;
int tmp; int tmp;
@ -500,7 +499,7 @@ static int astNewAttributes(ClientData clientData,
ginfo("attributes: %s->%02x\n", attributes, editRect.attribute); ginfo("attributes: %s->%02x\n", attributes, editRect.attribute);
tmp = atoi(argv[2]); tmp = atoi(argv[2]);
if ((tmp >=0) && (tmp < 256)) if ((tmp >= 0) && (tmp < 256))
{ {
editRect.texture = tmp; editRect.texture = tmp;
} }
@ -511,7 +510,7 @@ static int astNewAttributes(ClientData clientData,
ginfo("texture: %s->%d\n", argv[2], editRect.texture); ginfo("texture: %s->%d\n", argv[2], editRect.texture);
tmp = atoi(argv[3]); tmp = atoi(argv[3]);
if ((tmp >=0) && (tmp <= MAXX_SCALING)) if ((tmp >= 0) && (tmp <= MAXX_SCALING))
{ {
editRect.scale = tmp; editRect.scale = tmp;
} }
@ -521,14 +520,14 @@ static int astNewAttributes(ClientData clientData,
} }
ginfo("scale: %s->%d\n", argv[3], editRect.scale); ginfo("scale: %s->%d\n", argv[3], editRect.scale);
} }
return TCL_OK; return TCL_OK;
} }
/* Called in response to the "ast_addrectangle" Tcl command */ /* Called in response to the "ast_addrectangle" Tcl command */
static int astAddRectangle(ClientData clientData, static int astAddRectangle(ClientData clientData,
Tcl_Interp *interp, Tcl_Interp * interp, int argc, const char *argv[])
int argc, const char *argv[])
{ {
ginfo("Processing command: %s\n", argv[0]); ginfo("Processing command: %s\n", argv[0]);
@ -556,15 +555,15 @@ static int astAddRectangle(ClientData clientData,
switch (editPlane) switch (editPlane)
{ {
case EDITPLANE_X: case EDITPLANE_X:
wld_add_plane(rect, &xPlane); wld_add_plane(rect, &g_xplane_list);
break; break;
case EDITPLANE_Y: case EDITPLANE_Y:
wld_add_plane(rect, &yPlane); wld_add_plane(rect, &g_yplane_list);
break; break;
case EDITPLANE_Z: case EDITPLANE_Z:
wld_add_plane(rect, &zPlane); wld_add_plane(rect, &g_zplane_list);
break; break;
} }
} }
@ -574,8 +573,7 @@ static int astAddRectangle(ClientData clientData,
/* Called in response to the "ast_save" Tcl command */ /* Called in response to the "ast_save" Tcl command */
static int astSaveRectangles(ClientData clientData, static int astSaveRectangles(ClientData clientData,
Tcl_Interp *interp, Tcl_Interp * interp, int argc, const char *argv[])
int argc, const char *argv[])
{ {
ginfo("Processing command: %s\n", argv[0]); ginfo("Processing command: %s\n", argv[0]);
@ -592,8 +590,7 @@ static int astSaveRectangles(ClientData clientData,
static void show_usage(const char *progname) static void show_usage(const char *progname)
{ {
fprintf(stderr, "USAGE:\n\t%s [-o <outfilename>] <infilename>\n", fprintf(stderr, "USAGE:\n\t%s [-o <outfilename>] <infilename>\n", progname);
progname);
exit(1); exit(1);
} }
@ -613,7 +610,7 @@ int main(int argc, char **argv, char **envp)
{ {
switch (option) switch (option)
{ {
case 'o' : case 'o':
astOutFileName = optarg; astOutFileName = optarg;
break; break;
default: default:
@ -623,29 +620,26 @@ int main(int argc, char **argv, char **envp)
} }
} }
/* We expect at least one argument after the options: The input /* We expect at least one argument after the options: The input file name. */
* file name.
*/
if (optind > argc - 1) if (optind > argc - 1)
{ {
fprintf(stderr, "Expected input file name\n"); fprintf(stderr, "Expected input file name\n");
show_usage(argv[0]); show_usage(argv[0]);
} }
astInFileName = argv[optind]; astInFileName = argv[optind];
/* Read the plane file now so that we can be certain that it is /* Read the plane file now so that we can be certain that it is a valid
* a valid plaine file. * plaine file. */
*/
if (wld_load_planefile(astInFileName) != PLANE_SUCCESS) if (wld_load_planefile(astInFileName) != PLANE_SUCCESS)
{ {
exit(1); exit(1);
} }
/* Tk_Main creates a Tcl interpreter and calls Tcl_AppInit() then /* Tk_Main creates a Tcl interpreter and calls Tcl_AppInit() then begins
* begins processing window events and interactive commands. * processing window events and interactive commands. */
*/
Tk_Main(1, argv, Tcl_AppInit); Tk_Main(1, argv, Tcl_AppInit);
exit(0); exit(0);
@ -665,7 +659,7 @@ int do_tcl_action(const char *script)
* is entered. * is entered.
*/ */
int Tcl_AppInit(Tcl_Interp *interp) int Tcl_AppInit(Tcl_Interp * interp)
{ {
int i; int i;
@ -695,19 +689,19 @@ int Tcl_AppInit(Tcl_Interp *interp)
/* Define application-specific commands */ /* Define application-specific commands */
Tcl_CreateCommand(astInterp, "ast_seteditmode", astSetEditMode, Tcl_CreateCommand(astInterp, "ast_seteditmode", astSetEditMode,
(ClientData)0, (Tcl_CmdDeleteProc *) NULL); (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
Tcl_CreateCommand(astInterp, "ast_position", astNewPosition, Tcl_CreateCommand(astInterp, "ast_position", astNewPosition,
(ClientData)0, (Tcl_CmdDeleteProc *) NULL); (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
Tcl_CreateCommand(astInterp, "ast_zoom", astNewZoom, Tcl_CreateCommand(astInterp, "ast_zoom", astNewZoom,
(ClientData)0, (Tcl_CmdDeleteProc *) NULL); (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
Tcl_CreateCommand(astInterp, "ast_edit", astNewEdit, Tcl_CreateCommand(astInterp, "ast_edit", astNewEdit,
(ClientData)0, (Tcl_CmdDeleteProc *) NULL); (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
Tcl_CreateCommand(astInterp, "ast_attributes", astNewAttributes, Tcl_CreateCommand(astInterp, "ast_attributes", astNewAttributes,
(ClientData)0, (Tcl_CmdDeleteProc *) NULL); (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
Tcl_CreateCommand(astInterp, "ast_addrectangle", astAddRectangle, Tcl_CreateCommand(astInterp, "ast_addrectangle", astAddRectangle,
(ClientData)0, (Tcl_CmdDeleteProc *) NULL); (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
Tcl_CreateCommand(astInterp, "ast_save", astSaveRectangles, Tcl_CreateCommand(astInterp, "ast_save", astSaveRectangles,
(ClientData)0, (Tcl_CmdDeleteProc *) NULL); (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
/* Initialize the Tcl parser */ /* Initialize the Tcl parser */

View File

@ -46,8 +46,8 @@
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <sys/ipc.h> #include <sys/ipc.h>
#ifndef NO_XSHM #ifndef NO_XSHM
#include <sys/shm.h> # include <sys/shm.h>
#include <X11/extensions/XShm.h> # include <X11/extensions/XShm.h>
#endif #endif
#include "trv_types.h" #include "trv_types.h"
@ -75,11 +75,11 @@ static int useShm;
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
static void x11_create_window(tcl_window_t *w); static void x11_create_window(tcl_window_t * w);
static void x11_load_palette(tcl_window_t *w); static void x11_load_palette(tcl_window_t * w);
static bool x11_allocate_colors(tcl_window_t *w, Colormap colormap); static bool x11_allocate_colors(tcl_window_t * w, Colormap colormap);
static void x11_map_sharedmemory(tcl_window_t *w, int depth); static void x11_map_sharedmemory(tcl_window_t * w, int depth);
static void x11_unmap_sharedmemory(tcl_window_t *w); static void x11_unmap_sharedmemory(tcl_window_t * w);
static void x11_unmap_all_sharedmemory(void); static void x11_unmap_all_sharedmemory(void);
/**************************************************************************** /****************************************************************************
@ -91,7 +91,7 @@ static void x11_unmap_all_sharedmemory(void);
* Description: * Description:
***************************************************************************/ ***************************************************************************/
static void x11_create_window(tcl_window_t *w) static void x11_create_window(tcl_window_t * w)
{ {
XGCValues gcValues; XGCValues gcValues;
char *argv[2] = { "xast", NULL }; char *argv[2] = { "xast", NULL };
@ -114,8 +114,8 @@ static void x11_create_window(tcl_window_t *w)
XStringListToTextProperty(&iconName, 1, &iNameProp); XStringListToTextProperty(&iconName, 1, &iNameProp);
sizeHints.flags = PSize | PMinSize | PMaxSize; sizeHints.flags = PSize | PMinSize | PMaxSize;
sizeHints.width= sizeHints.min_width = sizeHints.max_width = w->width; sizeHints.width = sizeHints.min_width = sizeHints.max_width = w->width;
sizeHints.height= sizeHints.min_height = sizeHints.max_height = w->height; sizeHints.height = sizeHints.min_height = sizeHints.max_height = w->height;
XSetWMProperties(w->display, w->win, &wNameProp, &iNameProp, argv, 1, XSetWMProperties(w->display, w->win, &wNameProp, &iNameProp, argv, 1,
&sizeHints, NULL, NULL); &sizeHints, NULL, NULL);
@ -133,7 +133,7 @@ static void x11_create_window(tcl_window_t *w)
* Description: * Description:
***************************************************************************/ ***************************************************************************/
static void x11_load_palette(tcl_window_t *w) static void x11_load_palette(tcl_window_t * w)
{ {
Colormap cMap; Colormap cMap;
@ -147,8 +147,7 @@ static void x11_load_palette(tcl_window_t *w)
XFreeColors(w->display, cMap, w->colorLookup, w->ncolors, 0); XFreeColors(w->display, cMap, w->colorLookup, w->ncolors, 0);
cMap = XCreateColormap(w->display, w->win, cMap = XCreateColormap(w->display, w->win,
DefaultVisual(w->display, w->screen), DefaultVisual(w->display, w->screen), AllocNone);
AllocNone);
if (!x11_allocate_colors(w, cMap)) if (!x11_allocate_colors(w, cMap))
{ {
@ -166,7 +165,7 @@ static void x11_load_palette(tcl_window_t *w)
* Description: * Description:
***************************************************************************/ ***************************************************************************/
static bool x11_allocate_colors(tcl_window_t *w, Colormap colormap) static bool x11_allocate_colors(tcl_window_t * w, Colormap colormap)
{ {
int i; int i;
@ -215,7 +214,7 @@ static bool x11_allocate_colors(tcl_window_t *w, Colormap colormap)
***************************************************************************/ ***************************************************************************/
#ifndef NO_XSHM #ifndef NO_XSHM
static int errorHandler(Display *display, XErrorEvent *event) static int errorHandler(Display * display, XErrorEvent * event)
{ {
xError = 1; xError = 1;
@ -242,9 +241,9 @@ static void trapErrors(void)
***************************************************************************/ ***************************************************************************/
#ifndef NO_XSHM #ifndef NO_XSHM
static int untrapErrors(Display *display) static int untrapErrors(Display * display)
{ {
XSync(display,0); XSync(display, 0);
XSetErrorHandler(NULL); XSetErrorHandler(NULL);
return xError; return xError;
} }
@ -255,7 +254,7 @@ static int untrapErrors(Display *display)
* Description: * Description:
***************************************************************************/ ***************************************************************************/
static void x11_map_sharedmemory(tcl_window_t *w, int depth) static void x11_map_sharedmemory(tcl_window_t * w, int depth)
{ {
#ifndef NO_XSHM #ifndef NO_XSHM
Status result; Status result;
@ -264,7 +263,8 @@ static void x11_map_sharedmemory(tcl_window_t *w, int depth)
shmCheckPoint = 0; shmCheckPoint = 0;
x11_unmap_sharedmemory(w); x11_unmap_sharedmemory(w);
if (!shmCheckPoint) atexit(x11_unmap_all_sharedmemory); if (!shmCheckPoint)
atexit(x11_unmap_all_sharedmemory);
shmCheckPoint = 1; shmCheckPoint = 1;
useShm = 0; useShm = 0;
@ -303,8 +303,8 @@ static void x11_map_sharedmemory(tcl_window_t *w, int depth)
} }
shmCheckPoint++; shmCheckPoint++;
w->image->data = (char *) shmat(xshminfo.shmid, 0, 0); w->image->data = (char *)shmat(xshminfo.shmid, 0, 0);
if (image->data == ((char *) -1)) if (image->data == ((char *)-1))
{ {
x11_unmap_sharedmemory(w); x11_unmap_sharedmemory(w);
goto shmerror; goto shmerror;
@ -323,7 +323,8 @@ static void x11_map_sharedmemory(tcl_window_t *w, int depth)
} }
shmCheckPoint++; shmCheckPoint++;
} else }
else
#endif #endif
if (!useShm) if (!useShm)
@ -333,7 +334,7 @@ static void x11_map_sharedmemory(tcl_window_t *w, int depth)
#endif #endif
useShm = 0; useShm = 0;
w->frameBuffer = (dev_pixel_t*) w->frameBuffer = (dev_pixel_t *)
wld_malloc(w->width * w->height * sizeof(dev_pixel_t)); wld_malloc(w->width * w->height * sizeof(dev_pixel_t));
w->image = XCreateImage(w->display, w->image = XCreateImage(w->display,
@ -341,9 +342,8 @@ static void x11_map_sharedmemory(tcl_window_t *w, int depth)
depth, depth,
ZPixmap, ZPixmap,
0, 0,
(char*)w->frameBuffer, (char *)w->frameBuffer,
w->width, w->height, w->width, w->height, 8, 0);
8, 0);
if (w->image == NULL) if (w->image == NULL)
{ {
@ -359,7 +359,7 @@ static void x11_map_sharedmemory(tcl_window_t *w, int depth)
* Description: * Description:
***************************************************************************/ ***************************************************************************/
static void x11_unmap_sharedmemory(tcl_window_t *w) static void x11_unmap_sharedmemory(tcl_window_t * w)
{ {
#ifndef NO_XSHM #ifndef NO_XSHM
if (shmCheckPoint > 4) if (shmCheckPoint > 4)
@ -413,7 +413,7 @@ static void x11_unmap_all_sharedmemory(void)
* Description: * Description:
***************************************************************************/ ***************************************************************************/
void x11_UpdateScreen(tcl_window_t *w) void x11_UpdateScreen(tcl_window_t * w)
{ {
#ifndef NO_XSHM #ifndef NO_XSHM
if (useShm) if (useShm)
@ -439,7 +439,7 @@ void x11_UpdateScreen(tcl_window_t *w)
* Description: * Description:
***************************************************************************/ ***************************************************************************/
void x11_InitGraphics(tcl_window_t *w) void x11_InitGraphics(tcl_window_t * w)
{ {
XWindowAttributes windowAttributes; XWindowAttributes windowAttributes;
@ -467,7 +467,7 @@ void x11_InitGraphics(tcl_window_t *w)
* Description: * Description:
***************************************************************************/ ***************************************************************************/
void x11_EndGraphics(tcl_window_t *w) void x11_EndGraphics(tcl_window_t * w)
{ {
x11_unmap_all_sharedmemory(); x11_unmap_all_sharedmemory();
XCloseDisplay(w->display); XCloseDisplay(w->display);