ref: 988f1128dd96f06c57da106175ccec158160f81d
parent: 8ad56ced43dc9b6f8791143f73a1b37c5662178c
author: Clownacy <Clownacy@users.noreply.github.com>
date: Thu Sep 10 13:36:21 EDT 2020
Convert a bunch of ints to size_t ints are dumb - only use them when you have to
--- a/src/Backends/Rendering.h
+++ b/src/Backends/Rendering.h
@@ -13,15 +13,15 @@
long bottom;
} RenderBackend_Rect;
-RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, bool fullscreen);
+RenderBackend_Surface* RenderBackend_Init(const char *window_title, size_t screen_width, size_t screen_height, bool fullscreen);
void RenderBackend_Deinit(void);
void RenderBackend_DrawScreen(void);
-RenderBackend_Surface* RenderBackend_CreateSurface(unsigned int width, unsigned int height, bool render_target);
+RenderBackend_Surface* RenderBackend_CreateSurface(size_t width, size_t height, bool render_target);
void RenderBackend_FreeSurface(RenderBackend_Surface *surface);
bool RenderBackend_IsSurfaceLost(RenderBackend_Surface *surface);
void RenderBackend_RestoreSurface(RenderBackend_Surface *surface);
-unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, unsigned int *pitch, unsigned int width, unsigned int height);
-void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, unsigned int width, unsigned int height);
+unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, size_t *pitch, size_t width, size_t height);
+void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, size_t width, size_t height);
void RenderBackend_Blit(RenderBackend_Surface *source_surface, const RenderBackend_Rect *rect, RenderBackend_Surface *destination_surface, long x, long y, bool colour_key);
void RenderBackend_ColourFill(RenderBackend_Surface *surface, const RenderBackend_Rect *rect, unsigned char red, unsigned char green, unsigned char blue);
RenderBackend_GlyphAtlas* RenderBackend_CreateGlyphAtlas(size_t size);
@@ -31,4 +31,4 @@
void RenderBackend_DrawGlyph(RenderBackend_GlyphAtlas *atlas, long x, long y, size_t glyph_x, size_t glyph_y, size_t glyph_width, size_t glyph_height);
void RenderBackend_FlushGlyphs(void);
void RenderBackend_HandleRenderTargetLoss(void);
-void RenderBackend_HandleWindowResize(unsigned int width, unsigned int height);
+void RenderBackend_HandleWindowResize(size_t width, size_t height);
--- a/src/Backends/Rendering/OpenGL3.cpp
+++ b/src/Backends/Rendering/OpenGL3.cpp
@@ -32,8 +32,8 @@
typedef struct RenderBackend_Surface
{
GLuint texture_id;
- unsigned int width;
- unsigned int height;
+ size_t width;
+ size_t height;
unsigned char *pixels;
} RenderBackend_Surface;
@@ -75,8 +75,8 @@
static GLuint framebuffer_id;
static VertexBufferSlot *local_vertex_buffer;
-static unsigned long local_vertex_buffer_size;
-static unsigned long current_vertex_buffer_slot;
+static size_t local_vertex_buffer_size;
+static size_t current_vertex_buffer_slot;
static RenderMode last_render_mode;
static GLuint last_source_texture;
@@ -86,8 +86,8 @@
static RenderBackend_Surface *glyph_destination_surface;
-static int actual_screen_width;
-static int actual_screen_height;
+static size_t actual_screen_width;
+static size_t actual_screen_height;
#ifdef USE_OPENGLES2
static const GLchar *vertex_shader_plain = " \
@@ -337,8 +337,8 @@
static void FlushVertexBuffer(void)
{
- static unsigned long vertex_buffer_size[TOTAL_VBOS];
- static unsigned int current_vertex_buffer = 0;
+ static size_t vertex_buffer_size[TOTAL_VBOS];
+ static size_t current_vertex_buffer = 0;
if (current_vertex_buffer_slot == 0)
return;
@@ -425,7 +425,7 @@
// Render-backend initialisation //
///////////////////////////////////
-RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, bool fullscreen)
+RenderBackend_Surface* RenderBackend_Init(const char *window_title, size_t screen_width, size_t screen_height, bool fullscreen)
{
#ifndef USE_OPENGLES2
glad_set_post_callback(PostGLCallCallback);
@@ -637,7 +637,7 @@
// Surface management //
////////////////////////
-RenderBackend_Surface* RenderBackend_CreateSurface(unsigned int width, unsigned int height, bool render_target)
+RenderBackend_Surface* RenderBackend_CreateSurface(size_t width, size_t height, bool render_target)
{
(void)render_target;
@@ -695,7 +695,7 @@
(void)surface;
}
-unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, unsigned int *pitch, unsigned int width, unsigned int height)
+unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, size_t *pitch, size_t width, size_t height)
{
if (surface == NULL)
return NULL;
@@ -705,7 +705,7 @@
return surface->pixels;
}
-void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, unsigned int width, unsigned int height)
+void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, size_t width, size_t height)
{
if (surface == NULL)
return;
@@ -1021,7 +1021,7 @@
// No problem for us
}
-void RenderBackend_HandleWindowResize(unsigned int width, unsigned int height)
+void RenderBackend_HandleWindowResize(size_t width, size_t height)
{
actual_screen_width = width;
actual_screen_height = height;
--- a/src/Backends/Rendering/SDLSurface.cpp
+++ b/src/Backends/Rendering/SDLSurface.cpp
@@ -42,7 +42,7 @@
sdl_rect->h = 0;
}
-RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, bool fullscreen)
+RenderBackend_Surface* RenderBackend_Init(const char *window_title, size_t screen_width, size_t screen_height, bool fullscreen)
{
window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screen_width, screen_height, 0);
@@ -100,7 +100,7 @@
Backend_PrintError("Couldn't put window surface on screen: %s", SDL_GetError());
}
-RenderBackend_Surface* RenderBackend_CreateSurface(unsigned int width, unsigned int height, bool render_target)
+RenderBackend_Surface* RenderBackend_CreateSurface(size_t width, size_t height, bool render_target)
{
(void)render_target;
@@ -141,7 +141,7 @@
(void)surface;
}
-unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, unsigned int *pitch, unsigned int width, unsigned int height)
+unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, size_t *pitch, size_t width, size_t height)
{
(void)width;
(void)height;
@@ -155,7 +155,7 @@
return (unsigned char*)surface->sdlsurface->pixels;
}
-void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, unsigned int width, unsigned int height)
+void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, size_t width, size_t height)
{
(void)width;
(void)height;
@@ -287,7 +287,7 @@
// No problem for us
}
-void RenderBackend_HandleWindowResize(unsigned int width, unsigned int height)
+void RenderBackend_HandleWindowResize(size_t width, size_t height)
{
(void)width;
(void)height;
--- a/src/Backends/Rendering/SDLTexture.cpp
+++ b/src/Backends/Rendering/SDLTexture.cpp
@@ -16,8 +16,8 @@
{
SDL_Texture *texture;
unsigned char *pixels;
- unsigned int width;
- unsigned int height;
+ size_t width;
+ size_t height;
bool lost;
struct RenderBackend_Surface *next;
@@ -51,7 +51,7 @@
sdl_rect->h = 0;
}
-RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, bool fullscreen)
+RenderBackend_Surface* RenderBackend_Init(const char *window_title, size_t screen_width, size_t screen_height, bool fullscreen)
{
Backend_PrintInfo("Available SDL render drivers:");
@@ -141,7 +141,7 @@
SDL_RenderPresent(renderer);
}
-RenderBackend_Surface* RenderBackend_CreateSurface(unsigned int width, unsigned int height, bool render_target)
+RenderBackend_Surface* RenderBackend_CreateSurface(size_t width, size_t height, bool render_target)
{
RenderBackend_Surface *surface = (RenderBackend_Surface*)malloc(sizeof(RenderBackend_Surface));
@@ -196,7 +196,7 @@
surface->lost = false;
}
-unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, unsigned int *pitch, unsigned int width, unsigned int height)
+unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, size_t *pitch, size_t width, size_t height)
{
if (surface == NULL)
return NULL;
@@ -208,7 +208,7 @@
return surface->pixels;
}
-void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, unsigned int width, unsigned int height)
+void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, size_t width, size_t height)
{
if (surface == NULL)
return;
@@ -224,11 +224,11 @@
const unsigned char *src_pixel = surface->pixels;
// Convert the SDL_Surface's colour-keyed pixels to RGBA32
- for (unsigned int y = 0; y < height; ++y)
+ for (size_t y = 0; y < height; ++y)
{
unsigned char *buffer_pointer = &buffer[y * width * 4];
- for (unsigned int x = 0; x < width; ++x)
+ for (size_t x = 0; x < width; ++x)
{
*buffer_pointer++ = src_pixel[0];
*buffer_pointer++ = src_pixel[1];
@@ -413,7 +413,7 @@
surface->lost = true;
}
-void RenderBackend_HandleWindowResize(unsigned int width, unsigned int height)
+void RenderBackend_HandleWindowResize(size_t width, size_t height)
{
(void)width;
(void)height;
--- a/src/Backends/Rendering/Software.cpp
+++ b/src/Backends/Rendering/Software.cpp
@@ -30,7 +30,7 @@
static unsigned char glyph_colour_channels[3];
static RenderBackend_Surface *glyph_destination_surface;
-RenderBackend_Surface* RenderBackend_Init(const char *window_title, int screen_width, int screen_height, bool fullscreen)
+RenderBackend_Surface* RenderBackend_Init(const char *window_title, size_t screen_width, size_t screen_height, bool fullscreen)
{
if (WindowBackend_Software_CreateWindow(window_title, screen_width, screen_height, fullscreen))
{
@@ -62,7 +62,7 @@
framebuffer.pixels = WindowBackend_Software_LockFramebuffer(&framebuffer.pitch);
}
-RenderBackend_Surface* RenderBackend_CreateSurface(unsigned int width, unsigned int height, bool render_target)
+RenderBackend_Surface* RenderBackend_CreateSurface(size_t width, size_t height, bool render_target)
{
(void)render_target;
@@ -107,7 +107,7 @@
(void)surface;
}
-unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, unsigned int *pitch, unsigned int width, unsigned int height)
+unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, size_t *pitch, size_t width, size_t height)
{
(void)width;
(void)height;
@@ -119,7 +119,7 @@
return surface->pixels;
}
-void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, unsigned int width, unsigned int height)
+void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, size_t width, size_t height)
{
(void)surface;
(void)width;
@@ -334,7 +334,7 @@
// No problem for us
}
-void RenderBackend_HandleWindowResize(unsigned int width, unsigned int height)
+void RenderBackend_HandleWindowResize(size_t width, size_t height)
{
WindowBackend_Software_HandleWindowResize(width, height);
}
--- a/src/Backends/Rendering/WiiU.cpp
+++ b/src/Backends/Rendering/WiiU.cpp
@@ -38,8 +38,8 @@
{
GX2Texture texture;
GX2ColorBuffer colour_buffer;
- unsigned int width;
- unsigned int height;
+ size_t width;
+ size_t height;
bool render_target;
unsigned char *lock_buffer; // TODO - Dumb
} RenderBackend_Surface;
@@ -93,8 +93,8 @@
static Viewport drc_viewport;
static VertexBufferSlot *local_vertex_buffer;
-static unsigned long local_vertex_buffer_size;
-static unsigned long current_vertex_buffer_slot;
+static size_t local_vertex_buffer_size;
+static size_t current_vertex_buffer_slot;
static RenderMode last_render_mode;
static GX2Texture *last_source_texture;
@@ -130,8 +130,8 @@
static void FlushVertexBuffer(void)
{
- static unsigned long vertex_buffer_size;
- static unsigned int current_vertex_buffer = 0;
+ static size_t vertex_buffer_size;
+ static size_t current_vertex_buffer = 0;
if (current_vertex_buffer_slot == 0)
return;
@@ -176,7 +176,7 @@
current_vertex_buffer_slot = 0;
}
-static void CalculateViewport(unsigned int actual_screen_width, unsigned int actual_screen_height, Viewport *viewport)
+static void CalculateViewport(size_t actual_screen_width, size_t actual_screen_height, Viewport *viewport)
{
if ((float)actual_screen_width / (float)actual_screen_height > (float)framebuffer_surface->width / (float)framebuffer_surface->height)
{
@@ -449,7 +449,7 @@
GX2SetContextState(gx2_context);
}
-RenderBackend_Surface* RenderBackend_CreateSurface(unsigned int width, unsigned int height, bool render_target)
+RenderBackend_Surface* RenderBackend_CreateSurface(size_t width, size_t height, bool render_target)
{
RenderBackend_Surface *surface = (RenderBackend_Surface*)malloc(sizeof(RenderBackend_Surface));
@@ -539,7 +539,7 @@
(void)surface;
}
-unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, unsigned int *pitch, unsigned int width, unsigned int height)
+unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, size_t *pitch, size_t width, size_t height)
{
if (surface != NULL)
{
@@ -554,7 +554,7 @@
return NULL;
}
-void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, unsigned int width, unsigned int height)
+void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, size_t width, size_t height)
{
if (surface != NULL)
{
@@ -884,7 +884,7 @@
// Doesn't happen on the Wii U
}
-void RenderBackend_HandleWindowResize(unsigned int width, unsigned int height)
+void RenderBackend_HandleWindowResize(size_t width, size_t height)
{
(void)width;
(void)height;
--- a/src/Backends/Rendering/Window/OpenGL.h
+++ b/src/Backends/Rendering/Window/OpenGL.h
@@ -1,5 +1,7 @@
#pragma once
-bool WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_width, int *screen_height, bool fullscreen);
+#include <stddef.h>
+
+bool WindowBackend_OpenGL_CreateWindow(const char *window_title, size_t *screen_width, size_t *screen_height, bool fullscreen);
void WindowBackend_OpenGL_DestroyWindow(void);
void WindowBackend_OpenGL_Display(void);
--- a/src/Backends/Rendering/Window/OpenGL3/GLFW3.cpp
+++ b/src/Backends/Rendering/Window/OpenGL3/GLFW3.cpp
@@ -12,7 +12,7 @@
GLFWwindow *window;
-bool WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_width, int *screen_height, bool fullscreen)
+bool WindowBackend_OpenGL_CreateWindow(const char *window_title, size_t *screen_width, size_t *screen_height, bool fullscreen)
{
#ifdef USE_OPENGLES2
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
--- a/src/Backends/Rendering/Window/OpenGL3/SDL2.cpp
+++ b/src/Backends/Rendering/Window/OpenGL3/SDL2.cpp
@@ -15,7 +15,7 @@
static SDL_GLContext context;
-bool WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_width, int *screen_height, bool fullscreen)
+bool WindowBackend_OpenGL_CreateWindow(const char *window_title, size_t *screen_width, size_t *screen_height, bool fullscreen)
{
#ifdef USE_OPENGLES2
if (SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES) < 0)
--- a/src/Backends/Rendering/Window/Software.h
+++ b/src/Backends/Rendering/Window/Software.h
@@ -2,9 +2,9 @@
#include <stddef.h>
-bool WindowBackend_Software_CreateWindow(const char *window_title, int screen_width, int screen_height, bool fullscreen);
+bool WindowBackend_Software_CreateWindow(const char *window_title, size_t screen_width, size_t screen_height, bool fullscreen);
void WindowBackend_Software_DestroyWindow(void);
unsigned char* WindowBackend_Software_LockFramebuffer(size_t *pitch);
void WindowBackend_Software_UnlockFramebuffer(void);
void WindowBackend_Software_Display(void);
-void WindowBackend_Software_HandleWindowResize(unsigned int width, unsigned int height);
+void WindowBackend_Software_HandleWindowResize(size_t width, size_t height);
--- a/src/Backends/Rendering/Window/Software/GLFW3.cpp
+++ b/src/Backends/Rendering/Window/Software/GLFW3.cpp
@@ -11,8 +11,8 @@
GLFWwindow *window;
static unsigned char *framebuffer;
-static int framebuffer_width;
-static int framebuffer_height;
+static size_t framebuffer_width;
+static size_t framebuffer_height;
static float framebuffer_x_ratio;
static float framebuffer_y_ratio;
@@ -19,7 +19,7 @@
static GLuint screen_texture_id;
-bool WindowBackend_Software_CreateWindow(const char *window_title, int screen_width, int screen_height, bool fullscreen)
+bool WindowBackend_Software_CreateWindow(const char *window_title, size_t screen_width, size_t screen_height, bool fullscreen)
{
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1);
@@ -59,11 +59,11 @@
glGenTextures(1, &screen_texture_id);
glBindTexture(GL_TEXTURE_2D, screen_texture_id);
- int framebuffer_texture_width = 1;
+ size_t framebuffer_texture_width = 1;
while (framebuffer_texture_width < framebuffer_width)
framebuffer_texture_width <<= 1;
- int framebuffer_texture_height = 1;
+ size_t framebuffer_texture_height = 1;
while (framebuffer_texture_height < framebuffer_height)
framebuffer_texture_height <<= 1;
@@ -127,7 +127,7 @@
glfwSwapBuffers(window);
}
-void WindowBackend_Software_HandleWindowResize(unsigned int width, unsigned int height)
+void WindowBackend_Software_HandleWindowResize(size_t width, size_t height)
{
// Do some viewport trickery, to fit the framebuffer in the center of the screen
GLint viewport_x;
--- a/src/Backends/Rendering/Window/Software/Null.cpp
+++ b/src/Backends/Rendering/Window/Software/Null.cpp
@@ -6,7 +6,7 @@
static unsigned char *framebuffer;
static size_t framebuffer_pitch;
-bool WindowBackend_Software_CreateWindow(const char *window_title, int screen_width, int screen_height, bool fullscreen)
+bool WindowBackend_Software_CreateWindow(const char *window_title, size_t screen_width, size_t screen_height, bool fullscreen)
{
(void)window_title;
(void)fullscreen;
@@ -45,7 +45,7 @@
}
-void WindowBackend_Software_HandleWindowResize(unsigned int width, unsigned int height)
+void WindowBackend_Software_HandleWindowResize(size_t width, size_t height)
{
(void)width;
(void)height;
--- a/src/Backends/Rendering/Window/Software/SDL2.cpp
+++ b/src/Backends/Rendering/Window/Software/SDL2.cpp
@@ -13,7 +13,7 @@
static SDL_Surface *window_sdlsurface;
static SDL_Surface *framebuffer_sdlsurface;
-bool WindowBackend_Software_CreateWindow(const char *window_title, int screen_width, int screen_height, bool fullscreen)
+bool WindowBackend_Software_CreateWindow(const char *window_title, size_t screen_width, size_t screen_height, bool fullscreen)
{
window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screen_width, screen_height, 0);
@@ -88,7 +88,7 @@
Backend_PrintError("Couldn't copy window surface to the screen: %s", SDL_GetError());
}
-void WindowBackend_Software_HandleWindowResize(unsigned int width, unsigned int height)
+void WindowBackend_Software_HandleWindowResize(size_t width, size_t height)
{
(void)width;
(void)height;
--- a/src/Backends/Rendering/Window/Software/WiiU.cpp
+++ b/src/Backends/Rendering/Window/Software/WiiU.cpp
@@ -48,7 +48,7 @@
static Viewport tv_viewport;
static Viewport drc_viewport;
-static void CalculateViewport(unsigned int actual_screen_width, unsigned int actual_screen_height, Viewport *viewport)
+static void CalculateViewport(size_t actual_screen_width, size_t actual_screen_height, Viewport *viewport)
{
if (actual_screen_width * fake_framebuffer_height > fake_framebuffer_width * actual_screen_height) // Fancy way to do `if (actual_screen_width / actual_screen_height > fake_framebuffer_width / fake_framebuffer_height)` without floats
{
@@ -68,7 +68,7 @@
}
}
-bool WindowBackend_Software_CreateWindow(const char *window_title, int screen_width, int screen_height, bool fullscreen)
+bool WindowBackend_Software_CreateWindow(const char *window_title, size_t screen_width, size_t screen_height, bool fullscreen)
{
(void)window_title;
(void)fullscreen;
@@ -265,7 +265,7 @@
WHBGfxFinishRender();
}
-void WindowBackend_Software_HandleWindowResize(unsigned int width, unsigned int height)
+void WindowBackend_Software_HandleWindowResize(size_t width, size_t height)
{
(void)width;
(void)height;
--- a/src/Bitmap.cpp
+++ b/src/Bitmap.cpp
@@ -12,12 +12,18 @@
#include "File.h"
-unsigned char* DecodeBitmap(const unsigned char *in_buffer, size_t in_buffer_size, unsigned int *width, unsigned int *height)
+unsigned char* DecodeBitmap(const unsigned char *in_buffer, size_t in_buffer_size, size_t *width, size_t *height)
{
- return stbi_load_from_memory(in_buffer, in_buffer_size, (int*)width, (int*)height, NULL, 3);
+ int int_width, int_height;
+ unsigned char *image_buffer = stbi_load_from_memory(in_buffer, in_buffer_size, &int_width, &int_height, NULL, 3);
+
+ *width = int_width;
+ *height = int_height;
+
+ return image_buffer;
}
-unsigned char* DecodeBitmapFromFile(const char *path, unsigned int *width, unsigned int *height)
+unsigned char* DecodeBitmapFromFile(const char *path, size_t *width, size_t *height)
{
size_t file_size;
unsigned char *file_buffer = LoadFileToMemory(path, &file_size);
@@ -24,7 +30,7 @@
if (file_buffer != NULL)
{
- unsigned char *image_buffer = stbi_load_from_memory(file_buffer, file_size, (int*)width, (int*)height, NULL, 3);
+ unsigned char *image_buffer = DecodeBitmap(file_buffer, file_size, width, height);
free(file_buffer);
--- a/src/Bitmap.h
+++ b/src/Bitmap.h
@@ -2,6 +2,6 @@
#include <stddef.h>
-unsigned char* DecodeBitmap(const unsigned char *in_buffer, size_t in_buffer_size, unsigned int *width, unsigned int *height);
-unsigned char* DecodeBitmapFromFile(const char *path, unsigned int *width, unsigned int *height);
+unsigned char* DecodeBitmap(const unsigned char *in_buffer, size_t in_buffer_size, size_t *width, size_t *height);
+unsigned char* DecodeBitmapFromFile(const char *path, size_t *width, size_t *height);
void FreeBitmap(unsigned char *buffer);
--- a/src/Draw.cpp
+++ b/src/Draw.cpp
@@ -147,10 +147,10 @@
memset(&surface_metadata[s], 0, sizeof(surface_metadata[0]));
}
-static BOOL ScaleAndUploadSurface(const unsigned char *image_buffer, int width, int height, SurfaceID surf_no)
+static BOOL ScaleAndUploadSurface(const unsigned char *image_buffer, size_t width, size_t height, SurfaceID surf_no)
{
// IF YOU WANT TO ADD HD SPRITES, THIS IS THE CODE YOU SHOULD EDIT
- unsigned int pitch;
+ size_t pitch;
unsigned char *pixels = RenderBackend_LockSurface(surf[surf_no], &pitch, width * mag, height * mag);
if (pixels == NULL)
@@ -159,7 +159,7 @@
if (mag == 1)
{
// Just copy the pixels the way they are
- for (int y = 0; y < height; ++y)
+ for (size_t y = 0; y < height; ++y)
{
const unsigned char *src_row = &image_buffer[y * width * 3];
unsigned char *dst_row = &pixels[y * pitch];
@@ -170,7 +170,7 @@
else
{
// Upscale the bitmap to the game's internal resolution
- for (int y = 0; y < height; ++y)
+ for (size_t y = 0; y < height; ++y)
{
const unsigned char *src_row = &image_buffer[y * width * 3];
unsigned char *dst_row = &pixels[y * pitch * mag];
@@ -178,7 +178,7 @@
const unsigned char *src_ptr = src_row;
unsigned char *dst_ptr = dst_row;
- for (int x = 0; x < width; ++x)
+ for (size_t x = 0; x < width; ++x)
{
for (int i = 0; i < mag; ++i)
{
@@ -215,7 +215,7 @@
if (data == NULL)
return FALSE;
- unsigned int width, height;
+ size_t width, height;
unsigned char *image_buffer = DecodeBitmap(data, size, &width, &height);
if (image_buffer == NULL)
@@ -273,7 +273,7 @@
return FALSE;
}
- unsigned int width, height;
+ size_t width, height;
unsigned char *image_buffer = DecodeBitmapFromFile(path.c_str(), &width, &height);
if (image_buffer == NULL)
@@ -319,7 +319,7 @@
if (data == NULL)
return FALSE;
- unsigned int width, height;
+ size_t width, height;
unsigned char *image_buffer = DecodeBitmap(data, size, &width, &height);
if (!ScaleAndUploadSurface(image_buffer, width, height, surf_no))
@@ -357,7 +357,7 @@
return FALSE;
}
- unsigned int width, height;
+ size_t width, height;
unsigned char *image_buffer = DecodeBitmapFromFile(path.c_str(), &width, &height);
if (image_buffer == NULL)
@@ -647,7 +647,7 @@
std::string path = gDataPath + "/Font/font";
// Get font size
- unsigned int width, height;
+ size_t width, height;
switch (mag)
{
--- a/src/Font.cpp
+++ b/src/Font.cpp
@@ -842,7 +842,7 @@
0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020
};
-static unsigned short ShiftJISToUnicode(const unsigned char *string, unsigned int *bytes_read)
+static unsigned short ShiftJISToUnicode(const unsigned char *string, size_t *bytes_read)
{
size_t lookup_index;
@@ -875,9 +875,9 @@
#else
-static unsigned long UTF8ToUnicode(const unsigned char *string, unsigned int *bytes_read)
+static unsigned long UTF8ToUnicode(const unsigned char *string, size_t *bytes_read)
{
- unsigned int length;
+ size_t length;
unsigned long charcode;
unsigned int zero_bit = 0;
@@ -1006,11 +1006,11 @@
switch (font_object->face->glyph->bitmap.pixel_mode)
{
case FT_PIXEL_MODE_GRAY:
- for (unsigned int y = 0; y < bitmap.rows; ++y)
+ for (size_t y = 0; y < bitmap.rows; ++y)
{
unsigned char *pixel_pointer = &bitmap.buffer[y * bitmap.pitch];
- for (unsigned int x = 0; x < bitmap.width; ++x)
+ for (size_t x = 0; x < bitmap.width; ++x)
{
*pixel_pointer = GammaCorrect((*pixel_pointer * 0xFF) / (bitmap.num_grays - 1));
++pixel_pointer;
@@ -1020,11 +1020,11 @@
break;
case FT_PIXEL_MODE_MONO:
- for (unsigned int y = 0; y < bitmap.rows; ++y)
+ for (size_t y = 0; y < bitmap.rows; ++y)
{
unsigned char *pixel_pointer = &bitmap.buffer[y * bitmap.pitch];
- for (unsigned int x = 0; x < bitmap.width; ++x)
+ for (size_t x = 0; x < bitmap.width; ++x)
{
*pixel_pointer = *pixel_pointer ? 0xFF : 0;
++pixel_pointer;
@@ -1058,7 +1058,7 @@
return NULL;
}
-FontObject* LoadFontFromData(const unsigned char *data, size_t data_size, unsigned int cell_width, unsigned int cell_height)
+FontObject* LoadFontFromData(const unsigned char *data, size_t data_size, size_t cell_width, size_t cell_height)
{
FontObject *font_object = (FontObject*)malloc(sizeof(FontObject));
@@ -1118,7 +1118,7 @@
return NULL;
}
-FontObject* LoadFont(const char *font_filename, unsigned int cell_width, unsigned int cell_height)
+FontObject* LoadFont(const char *font_filename, size_t cell_width, size_t cell_height)
{
FontObject *font_object = NULL;
@@ -1149,7 +1149,7 @@
while (string_pointer != string_end)
{
- unsigned int bytes_read;
+ size_t bytes_read;
#ifdef JAPANESE
const unsigned short unicode_value = ShiftJISToUnicode(string_pointer, &bytes_read);
#else
--- a/src/Font.h
+++ b/src/Font.h
@@ -6,7 +6,7 @@
typedef struct FontObject FontObject;
-FontObject* LoadFontFromData(const unsigned char *data, size_t data_size, unsigned int cell_width, unsigned int cell_height);
-FontObject* LoadFont(const char *font_filename, unsigned int cell_width, unsigned int cell_height);
+FontObject* LoadFontFromData(const unsigned char *data, size_t data_size, size_t cell_width, size_t cell_height);
+FontObject* LoadFont(const char *font_filename, size_t cell_width, size_t cell_height);
void DrawText(FontObject *font_object, RenderBackend_Surface *surface, int x, int y, unsigned long colour, const char *string);
void UnloadFont(FontObject *font_object);
--- a/src/Main.cpp
+++ b/src/Main.cpp
@@ -294,7 +294,7 @@
if (window_icon_resource_data != NULL)
{
- unsigned int window_icon_width, window_icon_height;
+ size_t window_icon_width, window_icon_height;
unsigned char *window_icon_rgb_pixels = DecodeBitmap(window_icon_resource_data, window_icon_resource_size, &window_icon_width, &window_icon_height);
if (window_icon_rgb_pixels != NULL)
@@ -311,7 +311,7 @@
if (cursor_resource_data != NULL)
{
- unsigned int cursor_width, cursor_height;
+ size_t cursor_width, cursor_height;
unsigned char *cursor_rgb_pixels = DecodeBitmap(cursor_resource_data, cursor_resource_size, &cursor_width, &cursor_height);
if (cursor_rgb_pixels != NULL)