Minor fixes

Includes (mostly) type fixes, dead code removal, signed vs unsigned
comparison fixes, memory leaks removal.
This commit is contained in:
Michał Janiszewski 2015-10-20 01:18:59 +02:00
parent be7d3d5b54
commit 8e45cccb7a
19 changed files with 45 additions and 44 deletions

View File

@ -167,6 +167,7 @@ bool sprite_file_export(int spriteIndex, const char *outPath)
pngError = lodepng_encode(&pngData, &pngSize, pixels, spriteHeader->width, spriteHeader->height, &pngState);
if (pngError != 0) {
free(pngData);
fprintf(stderr, "Error creating PNG data, %u: %s", pngError, lodepng_error_text(pngError));
return false;
} else {
@ -247,6 +248,7 @@ bool sprite_file_import(const char *path, rct_g1_element *outElement, uint8 **ou
pngError = lodepng_decode_file(&pixels, &width, &height, path, LCT_RGBA, 8);
if (pngError != 0) {
free(pixels);
fprintf(stderr, "Error creating PNG data, %u: %s", pngError, lodepng_error_text(pngError));
return false;
}
@ -373,6 +375,7 @@ bool sprite_file_import(const char *path, rct_g1_element *outElement, uint8 **ou
}
}
free(pixels);
free(src);
int bufferLength = (int)(dst - buffer);
buffer = realloc(buffer, bufferLength);

View File

@ -373,7 +373,7 @@ bool config_save_default()
bool config_open(const utf8string path)
{
SDL_RWops *file;
uint8 *lineBuffer;
utf8string lineBuffer;
size_t lineBufferCapacity;
size_t lineLength;
int c;
@ -1216,7 +1216,7 @@ bool themes_save_preset(int preset)
bool themes_open(const_utf8string path)
{
SDL_RWops *file;
uint8 *lineBuffer;
utf8string lineBuffer;
size_t lineBufferCapacity;
size_t lineLength;
int c, preset;
@ -1255,7 +1255,7 @@ bool themes_open(const_utf8string path)
// Skim UTF-8 byte order mark
SDL_RWread(file, lineBuffer, 3, 1);
if (!(lineBuffer[0] == 0xEF && lineBuffer[1] == 0xBB && lineBuffer[2] == 0xBF))
if (!(lineBuffer[0] == (utf8)0xEF && lineBuffer[1] == (utf8)0xBB && lineBuffer[2] == (utf8)0xBF))
SDL_RWseek(file, 0, SEEK_SET);
while ((c = rwopsreadc(file)) != EOF) {

View File

@ -111,7 +111,7 @@ static void gfx_draw_dirty_blocks(int x, int y, int columns, int rows);
void gfx_clear(rct_drawpixelinfo *dpi, int colour)
{
int y, w, h;
char* ptr;
uint8* ptr;
w = dpi->width >> dpi->zoom_level;
h = dpi->height >> dpi->zoom_level;
@ -149,7 +149,7 @@ void gfx_transpose_palette(int pal, unsigned char product)
source_pointer += 3;
dest_pointer += 4;
}
platform_update_palette((char*)RCT2_ADDRESS_PALETTE, 10, 236);
platform_update_palette((uint8*)RCT2_ADDRESS_PALETTE, 10, 236);
}
/* rct2: 0x006837E3 */
@ -175,7 +175,7 @@ void load_palette(){
source_pointer += 3;
dest_pointer += 4;
}
platform_update_palette((char*)RCT2_ADDRESS_PALETTE, 10, 236);
platform_update_palette((uint8*)RCT2_ADDRESS_PALETTE, 10, 236);
}
/**

View File

@ -26,7 +26,7 @@
// Size: 0x10
typedef struct {
char* bits; // 0x00
uint8* bits; // 0x00
short x; // 0x04
short y; // 0x06
short width; // 0x08

View File

@ -53,13 +53,13 @@ void gfx_draw_line_on_buffer(rct_drawpixelinfo *dpi, char colour, int y, int x,
if (no_pixels <= 0)return;
}
char* bits_pointer;
uint8* bits_pointer;
//Get the buffer we are drawing to and move to the first coordinate.
bits_pointer = dpi->bits + y*(dpi->pitch + dpi->width) + x;
//Draw the line to the specified colour
for (; no_pixels > 0; --no_pixels, ++bits_pointer){
*((uint8*)bits_pointer) = colour;
*bits_pointer = colour;
}
}
@ -147,4 +147,4 @@ void gfx_draw_line(rct_drawpixelinfo *dpi, int x1, int y1, int x2, int y2, int c
}
}
return;
}
}

View File

@ -126,7 +126,7 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot
if (colour & 0x4000000){
//0x4000000
// 00678B8A 00678E38
char* dest_pointer;
uint8* dest_pointer;
dest_pointer = start_y * (dpi->width + dpi->pitch) + start_x + dpi->bits;
//The pattern loops every 15 lines this is which
@ -142,7 +142,7 @@ void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bot
pattern_pointer = RCT2_ADDRESS(0x0097FEFC,uint16*)[colour >> 28]; // or possibly uint8)[esi*4] ?
for (int no_lines = height; no_lines > 0; no_lines--) {
char* next_dest_pointer = dest_pointer + dpi->width + dpi->pitch;
uint8* next_dest_pointer = dest_pointer + dpi->width + dpi->pitch;
uint16 pattern = pattern_pointer[pattern_y];
for (int no_pixels = width; no_pixels > 0; --no_pixels) {

View File

@ -24,7 +24,7 @@ void scrolling_text_initialise_bitmaps()
{
uint8 drawingSurface[64];
rct_drawpixelinfo dpi = {
.bits = (char*)&drawingSurface,
.bits = (uint8 *)&drawingSurface,
.x = 0,
.y = 0,
.width = 8,
@ -135,7 +135,7 @@ int scrolling_text_setup(rct_string_id stringId, uint16 scroll, uint16 scrolling
utf8 scrollString[256];
scrolling_text_format(scrollString, scrollText);
sint16* scrollingModePositions = RCT2_ADDRESS(RCT2_ADDRESS_SCROLLING_MODE_POSITIONS, uint16*)[scrollingMode];
sint16* scrollingModePositions = RCT2_ADDRESS(RCT2_ADDRESS_SCROLLING_MODE_POSITIONS, sint16*)[scrollingMode];
memset(scrollText->bitmap, 0, 320 * 8);
if (gUseTrueTypeFont) {

View File

@ -644,7 +644,6 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in
eax = 0;
memcpy((char*)new_source_pointer, (char*)source_pointer, ecx);
new_source_pointer += ecx;
source_pointer += ecx;
source_pointer = (uint8*)ebx;
}
source_pointer = new_source_pointer_start + g1_source->width*source_start_y + source_start_x;

View File

@ -742,7 +742,7 @@ void gfx_draw_string_centred_wrapped_partial(rct_drawpixelinfo *dpi, int x, int
static uint32 _ttf_surface_cache_hash(TTF_Font *font, const utf8 *text)
{
uint32 hash = ((uint32)font * 23) ^ 0xAAAAAAAA;
for (const uint8 *ch = text; *ch != 0; ch++) {
for (const utf8 *ch = text; *ch != 0; ch++) {
hash = ror32(hash, 3) ^ (*ch * 13);
}
return hash;

View File

@ -759,7 +759,6 @@ int game_load_sv6(SDL_RWops* rw)
if (!load_success){
set_load_objects_fail_reason();
if (RCT2_GLOBAL(RCT2_ADDRESS_INPUT_FLAGS, uint32) & INPUT_FLAG_5){
RCT2_GLOBAL(0x14241BC, uint32) = 2;
//call 0x0040705E Sets cursor position and something else. Calls maybe wind func 8 probably pointless
RCT2_GLOBAL(0x14241BC, uint32) = 0;
RCT2_GLOBAL(RCT2_ADDRESS_INPUT_FLAGS, uint32) &= ~INPUT_FLAG_5;
@ -838,7 +837,6 @@ int game_load_network(SDL_RWops* rw)
if (!load_success){
set_load_objects_fail_reason();
if (RCT2_GLOBAL(RCT2_ADDRESS_INPUT_FLAGS, uint32) & INPUT_FLAG_5){
RCT2_GLOBAL(0x14241BC, uint32) = 2;
//call 0x0040705E Sets cursor position and something else. Calls maybe wind func 8 probably pointless
RCT2_GLOBAL(0x14241BC, uint32) = 0;
RCT2_GLOBAL(RCT2_ADDRESS_INPUT_FLAGS, uint32) &= ~INPUT_FLAG_5;

View File

@ -142,7 +142,8 @@ int screenshot_dump_bmp()
BitmapInfoHeader info;
int i, y, index, width, height, stride;
char *buffer, path[MAX_PATH], *row;
char path[MAX_PATH];
uint8 *buffer, *row;
SDL_RWops *fp;
unsigned int bytesWritten;

View File

@ -878,7 +878,7 @@ int sub_98197C(sint8 al, sint8 ah, int image_id, sint8 cl, int edx, sint16 si, s
void viewport_vehicle_paint_setup(rct_vehicle *vehicle, int imageDirection)
{
rct_ride_type *rideEntry;
rct_ride_type_vehicle *vehicleEntry;
const rct_ride_type_vehicle *vehicleEntry;
int x = vehicle->x;
int y = vehicle->y;
@ -1171,7 +1171,7 @@ void viewport_ride_entrance_exit_paint_setup(uint8 direction, int height, rct_ma
string_id = STR_RIDE_ENTRANCE_NAME;
}
uint8 entrance_string[MAX_PATH];
utf8 entrance_string[MAX_PATH];
if (gConfigGeneral.upper_case_banners) {
format_string_to_upper(entrance_string, string_id, RCT2_ADDRESS(RCT2_ADDRESS_COMMON_FORMAT_ARGS, void));
} else {
@ -1275,7 +1275,7 @@ void viewport_park_entrance_paint_setup(uint8 direction, int height, rct_map_ele
park_text_id = 1731;
}
uint8 park_name[MAX_PATH];
utf8 park_name[MAX_PATH];
if (gConfigGeneral.upper_case_banners) {
format_string_to_upper(park_name, park_text_id, RCT2_ADDRESS(RCT2_ADDRESS_COMMON_FORMAT_ARGS, void));
} else {
@ -2094,7 +2094,7 @@ static void viewport_draw_money_effects()
do {
format_string(buffer, ps->string_id, &ps->args);
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16) = FONT_SPRITE_BASE_MEDIUM;
gfx_draw_string_with_y_offsets(&dpi, buffer, 0, ps->x, ps->y, ps->y_offsets);
gfx_draw_string_with_y_offsets(&dpi, buffer, 0, ps->x, ps->y, (sint8 *)ps->y_offsets);
} while ((ps = ps->next) != NULL);
}

View File

@ -114,7 +114,7 @@ rct_object_entry *object_get_next(rct_object_entry *entry);
int write_object_file(SDL_RWops* rw, rct_object_entry* entry);
void reset_loaded_objects();
int find_object_in_entry_group(rct_object_entry* entry, uint8* entry_type, uint8* entry_index);
void object_create_identifier_name(uint8* string_buffer, rct_object_entry* object);
void object_create_identifier_name(char* string_buffer, const rct_object_entry* object);
rct_object_entry *object_list_find(rct_object_entry *entry);

View File

@ -462,7 +462,7 @@ int check_object_entry(rct_object_entry *entry)
}
/* rct2: 0x006AB344 */
void object_create_identifier_name(uint8* string_buffer, rct_object_entry* object){
void object_create_identifier_name(char* string_buffer, const rct_object_entry* object){
for (uint8 i = 0; i < 8; ++i){
if (object->name[i] != ' '){
*string_buffer++ = object->name[i];
@ -473,14 +473,14 @@ void object_create_identifier_name(uint8* string_buffer, rct_object_entry* objec
for (uint8 i = 0; i < 4; ++i){
uint8 flag_part = (object->flags >> (i * 8)) & 0xFF;
*string_buffer++ = RCT2_ADDRESS(0x0098DA64, uint8)[flag_part >> 4];
*string_buffer++ = RCT2_ADDRESS(0x0098DA64, uint8)[flag_part & 0xF];
*string_buffer++ = RCT2_ADDRESS(0x0098DA64, char)[flag_part >> 4];
*string_buffer++ = RCT2_ADDRESS(0x0098DA64, char)[flag_part & 0xF];
}
for (uint8 i = 0; i < 4; ++i){
uint8 checksum_part = (object->checksum >> (i * 8)) & 0xFF;
*string_buffer++ = RCT2_ADDRESS(0x0098DA64, uint8)[checksum_part >> 4];
*string_buffer++ = RCT2_ADDRESS(0x0098DA64, uint8)[checksum_part & 0xF];
*string_buffer++ = RCT2_ADDRESS(0x0098DA64, char)[checksum_part >> 4];
*string_buffer++ = RCT2_ADDRESS(0x0098DA64, char)[checksum_part & 0xF];
}
*string_buffer++ = '\0';
}
@ -714,7 +714,7 @@ static uint32 install_object_entry(rct_object_entry* entry, rct_object_entry* in
memcpy(installed_entry_pointer, entry, sizeof(rct_object_entry));
installed_entry_pointer += sizeof(rct_object_entry);
strcpy(installed_entry_pointer, path);
strcpy((char *)installed_entry_pointer, path);
while (*installed_entry_pointer++);
// Chunk size is set to unknown
@ -772,11 +772,11 @@ static uint32 install_object_entry(rct_object_entry* entry, rct_object_entry* in
// Always extract only the vehicle type, since the track type is always displayed in the left column, to prevent duplicate track names.
rct_string_id nameStringId = object_get_name_string_id(entry, chunk);
if (nameStringId == STR_NONE) {
if (nameStringId == (rct_string_id)STR_NONE) {
nameStringId = (rct_string_id)RCT2_GLOBAL(RCT2_ADDRESS_CURR_OBJECT_BASE_STRING_ID, uint32);
}
strcpy(installed_entry_pointer, language_get_string(nameStringId));
strcpy((char *)installed_entry_pointer, language_get_string(nameStringId));
while (*installed_entry_pointer++);
// This is deceptive. Due to setting the total no images earlier to 0xF26E

View File

@ -33,7 +33,7 @@
#include "../openrct2.h"
#include "platform.h"
typedef void(*update_palette_func)(char*, int, int);
typedef void(*update_palette_func)(const uint8*, int, int);
openrct2_cursor gCursorState;
const unsigned char *gKeysState;

View File

@ -5815,10 +5815,10 @@ void ride_all_has_any_track_elements(bool *rideIndexArray)
/* rct2: 0x006847BA */
void set_vehicle_type_image_max_sizes(rct_ride_type_vehicle* vehicle_type, int num_images){
char bitmap[200][200] = { 0 };
uint8 bitmap[200][200] = { 0 };
rct_drawpixelinfo dpi = {
.bits = (char*)bitmap,
.bits = (uint8*)bitmap,
.x = -100,
.y = -100,
.width = 200,

View File

@ -2141,7 +2141,7 @@ void draw_track_preview(uint8** preview){
dpi->width = 370;
dpi->height = 217;
dpi->pitch = 0;
dpi->bits = (char*)preview;
dpi->bits = (uint8*)preview;
top = y;
left = x;

View File

@ -2314,7 +2314,7 @@ static void window_ride_vehicle_mousedown(int widgetIndex, rct_window *w, rct_wi
rct_ride_type *rideEntry, *currentRideEntry;
rct_string_id stringId;
int i, minCars, maxCars, cars, numItems, quadIndex, bitIndex, rideEntryIndex, selectedIndex, rideTypeIterator, rideTypeIteratorMax;
uint8 *rideEntryIndexPtr, *currentRideEntryIndex;
uint8 *rideEntryIndexPtr;
bool selectionShouldBeExpanded;
ride = GET_RIDE(w->number);
@ -2345,9 +2345,8 @@ static void window_ride_vehicle_mousedown(int widgetIndex, rct_window *w, rct_wi
continue;
rideEntryIndexPtr = get_ride_entry_indices_for_ride_type(rideTypeIterator);
currentRideEntryIndex;
for (currentRideEntryIndex = rideEntryIndexPtr; *currentRideEntryIndex != 0xFF; currentRideEntryIndex++) {
for (uint8 *currentRideEntryIndex = rideEntryIndexPtr; *currentRideEntryIndex != 0xFF; currentRideEntryIndex++) {
rideEntryIndex = *currentRideEntryIndex;
currentRideEntry = GET_RIDE_ENTRY(rideEntryIndex);
// Skip if vehicle has the same track type, but not same subtype, unless subtype switching is enabled
@ -5802,7 +5801,7 @@ static void window_ride_income_paint(rct_window *w, rct_drawpixelinfo *dpi)
// Running cost per hour
costPerHour = ride->upkeep_cost * 16;
stringId = ride->upkeep_cost == 0xFFFF ? STR_RUNNING_COST_UNKNOWN : STR_RUNNING_COST_PER_HOUR;
stringId = ride->upkeep_cost == (money16)0xFFFF ? STR_RUNNING_COST_UNKNOWN : STR_RUNNING_COST_PER_HOUR;
gfx_draw_string_left(dpi, stringId, &costPerHour, 0, x, y);
y += 10;

View File

@ -153,7 +153,7 @@ void window_track_list_open(ride_list_item item)
*/
static void window_track_list_select(rct_window *w, int index)
{
uint8 *trackDesignItem, *trackDesignList = RCT2_ADDRESS(RCT2_ADDRESS_TRACK_LIST, uint8);
utf8 *trackDesignItem, *trackDesignList = RCT2_ADDRESS(RCT2_ADDRESS_TRACK_LIST, utf8);
rct_track_design *trackDesign;
w->track_list.var_480 = index;
@ -172,7 +172,7 @@ static void window_track_list_select(rct_window *w, int index)
index--;
trackDesignItem = trackDesignList + (index * 128);
RCT2_GLOBAL(0x00F4403C, uint8*) = trackDesignItem;
RCT2_GLOBAL(0x00F4403C, utf8*) = trackDesignItem;
window_track_list_format_name(
(char*)0x009BC313,
@ -382,7 +382,8 @@ static void window_track_list_paint(rct_window *w, rct_drawpixelinfo *dpi)
{
rct_widget *widget;
rct_track_design *trackDesign = NULL;
uint8 *image, *trackDesignList = RCT2_ADDRESS(RCT2_ADDRESS_TRACK_LIST, uint8);
uint8 *image;
utf8 *trackDesignList = RCT2_ADDRESS(RCT2_ADDRESS_TRACK_LIST, utf8);
uint16 holes, speed, drops, dropHeight, inversions;
fixed32_2dp rating;
int trackIndex, x, y, colour, gForces, airTime;
@ -559,7 +560,7 @@ static void window_track_list_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi,
{
rct_string_id stringId, stringId2;
int i, x, y, colour;
uint8 *trackDesignItem, *trackDesignList = RCT2_ADDRESS(RCT2_ADDRESS_TRACK_LIST, uint8);
utf8 *trackDesignItem, *trackDesignList = RCT2_ADDRESS(RCT2_ADDRESS_TRACK_LIST, utf8);
colour = RCT2_GLOBAL(0x00141FC48 + (w->colours[0] * 8), uint8);
colour = (colour << 24) | (colour << 16) | (colour << 8) | colour;