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

@ -56,22 +56,22 @@ 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

@ -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

@ -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

@ -59,24 +59,21 @@ rect_list_t *wld_find_plane(wld_coord_t h, wld_coord_t v, wld_coord_t plane,
{ {
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

@ -54,6 +54,10 @@
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

@ -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

@ -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)
@ -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,49 +161,60 @@ 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
@ -209,24 +222,31 @@ static uint8_t wld_load_bitmaps(FILE *fp)
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])
{
return BMAP_BML_READ_ERROR;
}
# endif # 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

@ -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,7 +214,7 @@ static void AddToPixel(uint8_t Index)
************************************************************************/ ************************************************************************/
/************************************************************************* /*************************************************************************
* Name: * Name: wld_LoadGIF
* Description: * Description:
************************************************************************/ ************************************************************************/
@ -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++)
{ {
@ -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 */
@ -357,20 +374,20 @@ graphic_file_t *wld_LoadGIF(FILE *fp, char *fname)
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,16 +406,17 @@ 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)");
} }
@ -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,10 +473,9 @@ 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)
@ -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

@ -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));
} }
} }
@ -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);
} }
@ -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)
{ {
@ -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 */

View File

@ -99,7 +99,10 @@ 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 */

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,7 +63,10 @@ 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 */
@ -71,8 +74,7 @@ static uint8_t wld_LoadWorldPlane(FILE *fp, rect_head_t *list, uint8_t numRects)
{ {
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;
} }
@ -106,11 +108,11 @@ uint8_t wld_load_planes(FILE *fp)
/* 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
*************************************************************************/ *************************************************************************/

View File

@ -71,8 +71,8 @@ static uint8_t wld_lum2formtype(color_form_t *lum)
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++)
@ -201,9 +201,9 @@ 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)
@ -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

@ -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

@ -60,16 +60,24 @@ void wld_move_plane(rect_list_t *rect, rect_head_t *destList,
/* 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,7 +47,7 @@
*************************************************************************/ *************************************************************************/
/************************************************************************* /*************************************************************************
* Name: * Name: wld_new_graphicfile
* Description: * Description:
************************************************************************/ ************************************************************************/

View File

@ -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

@ -59,11 +59,14 @@ int16_t wld_read_decimal(FILE *fp)
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 */
@ -84,7 +87,10 @@ int16_t wld_read_decimal(FILE *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

@ -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,17 +75,25 @@ 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;
} }
}
/************************************************************************* /*************************************************************************
* Name: wld_new_texture * Name: wld_new_texture
@ -97,7 +105,9 @@ 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));
@ -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

@ -59,16 +59,24 @@ 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

@ -54,8 +54,8 @@ 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,7 +101,7 @@ 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 */
@ -169,9 +170,8 @@ 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));
@ -189,16 +189,14 @@ 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;
@ -229,9 +227,8 @@ void wld_rgblookup_allocate(void)
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;
@ -248,14 +245,12 @@ 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);

View File

@ -47,7 +47,6 @@
* Private Functions * Private Functions
*************************************************************************/ *************************************************************************/
/************************************************************************* /*************************************************************************
* Name: wld_CountRectangles * Name: wld_CountRectangles
* Description: * Description:
@ -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;
@ -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);
} }
@ -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);

View File

@ -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))
{ {
@ -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;
@ -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)
@ -342,8 +343,7 @@ static void x11_map_sharedmemory(tcl_window_t *w, int 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)
{ {