Convert a bunch of ints to size_t

ints are dumb - only use them when you have to
This commit is contained in:
Clownacy 2020-09-10 17:36:21 +01:00
parent 8ad56ced43
commit 988f1128dd
20 changed files with 104 additions and 96 deletions

View file

@ -13,15 +13,15 @@ typedef struct RenderBackend_Rect
long bottom; long bottom;
} RenderBackend_Rect; } 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_Deinit(void);
void RenderBackend_DrawScreen(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); void RenderBackend_FreeSurface(RenderBackend_Surface *surface);
bool RenderBackend_IsSurfaceLost(RenderBackend_Surface *surface); bool RenderBackend_IsSurfaceLost(RenderBackend_Surface *surface);
void RenderBackend_RestoreSurface(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); unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, size_t *pitch, size_t width, size_t height);
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 RenderBackend_Blit(RenderBackend_Surface *source_surface, const RenderBackend_Rect *rect, RenderBackend_Surface *destination_surface, long x, long y, bool colour_key); 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); 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); RenderBackend_GlyphAtlas* RenderBackend_CreateGlyphAtlas(size_t size);
@ -31,4 +31,4 @@ void RenderBackend_PrepareToDrawGlyphs(RenderBackend_GlyphAtlas *atlas, RenderBa
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_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_FlushGlyphs(void);
void RenderBackend_HandleRenderTargetLoss(void); void RenderBackend_HandleRenderTargetLoss(void);
void RenderBackend_HandleWindowResize(unsigned int width, unsigned int height); void RenderBackend_HandleWindowResize(size_t width, size_t height);

View file

@ -32,8 +32,8 @@ typedef enum RenderMode
typedef struct RenderBackend_Surface typedef struct RenderBackend_Surface
{ {
GLuint texture_id; GLuint texture_id;
unsigned int width; size_t width;
unsigned int height; size_t height;
unsigned char *pixels; unsigned char *pixels;
} RenderBackend_Surface; } RenderBackend_Surface;
@ -75,8 +75,8 @@ static GLuint vertex_buffer_ids[TOTAL_VBOS];
static GLuint framebuffer_id; static GLuint framebuffer_id;
static VertexBufferSlot *local_vertex_buffer; static VertexBufferSlot *local_vertex_buffer;
static unsigned long local_vertex_buffer_size; static size_t local_vertex_buffer_size;
static unsigned long current_vertex_buffer_slot; static size_t current_vertex_buffer_slot;
static RenderMode last_render_mode; static RenderMode last_render_mode;
static GLuint last_source_texture; static GLuint last_source_texture;
@ -86,8 +86,8 @@ static RenderBackend_Surface framebuffer;
static RenderBackend_Surface *glyph_destination_surface; static RenderBackend_Surface *glyph_destination_surface;
static int actual_screen_width; static size_t actual_screen_width;
static int actual_screen_height; static size_t actual_screen_height;
#ifdef USE_OPENGLES2 #ifdef USE_OPENGLES2
static const GLchar *vertex_shader_plain = " \ static const GLchar *vertex_shader_plain = " \
@ -337,8 +337,8 @@ static VertexBufferSlot* GetVertexBufferSlot(unsigned int slots_needed)
static void FlushVertexBuffer(void) static void FlushVertexBuffer(void)
{ {
static unsigned long vertex_buffer_size[TOTAL_VBOS]; static size_t vertex_buffer_size[TOTAL_VBOS];
static unsigned int current_vertex_buffer = 0; static size_t current_vertex_buffer = 0;
if (current_vertex_buffer_slot == 0) if (current_vertex_buffer_slot == 0)
return; return;
@ -425,7 +425,7 @@ static void PostGLCallCallback(const char *name, void *function_pointer, int len
// Render-backend initialisation // // 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 #ifndef USE_OPENGLES2
glad_set_post_callback(PostGLCallCallback); glad_set_post_callback(PostGLCallCallback);
@ -637,7 +637,7 @@ void RenderBackend_DrawScreen(void)
// Surface management // // 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; (void)render_target;
@ -695,7 +695,7 @@ void RenderBackend_RestoreSurface(RenderBackend_Surface *surface)
(void)surface; (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) if (surface == NULL)
return NULL; return NULL;
@ -705,7 +705,7 @@ unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, unsigne
return surface->pixels; 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) if (surface == NULL)
return; return;
@ -1021,7 +1021,7 @@ void RenderBackend_HandleRenderTargetLoss(void)
// No problem for us // 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_width = width;
actual_screen_height = height; actual_screen_height = height;

View file

@ -42,7 +42,7 @@ static void RectToSDLRect(const RenderBackend_Rect *rect, SDL_Rect *sdl_rect)
sdl_rect->h = 0; 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); window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screen_width, screen_height, 0);
@ -100,7 +100,7 @@ void RenderBackend_DrawScreen(void)
Backend_PrintError("Couldn't put window surface on screen: %s", SDL_GetError()); 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; (void)render_target;
@ -141,7 +141,7 @@ void RenderBackend_RestoreSurface(RenderBackend_Surface *surface)
(void)surface; (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)width;
(void)height; (void)height;
@ -155,7 +155,7 @@ unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, unsigne
return (unsigned char*)surface->sdlsurface->pixels; 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)width;
(void)height; (void)height;
@ -287,7 +287,7 @@ void RenderBackend_HandleRenderTargetLoss(void)
// No problem for us // 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)width;
(void)height; (void)height;

View file

@ -16,8 +16,8 @@ typedef struct RenderBackend_Surface
{ {
SDL_Texture *texture; SDL_Texture *texture;
unsigned char *pixels; unsigned char *pixels;
unsigned int width; size_t width;
unsigned int height; size_t height;
bool lost; bool lost;
struct RenderBackend_Surface *next; struct RenderBackend_Surface *next;
@ -51,7 +51,7 @@ static void RectToSDLRect(const RenderBackend_Rect *rect, SDL_Rect *sdl_rect)
sdl_rect->h = 0; 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:"); Backend_PrintInfo("Available SDL render drivers:");
@ -141,7 +141,7 @@ void RenderBackend_DrawScreen(void)
SDL_RenderPresent(renderer); 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)); RenderBackend_Surface *surface = (RenderBackend_Surface*)malloc(sizeof(RenderBackend_Surface));
@ -196,7 +196,7 @@ void RenderBackend_RestoreSurface(RenderBackend_Surface *surface)
surface->lost = false; 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) if (surface == NULL)
return NULL; return NULL;
@ -208,7 +208,7 @@ unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, unsigne
return surface->pixels; 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) if (surface == NULL)
return; return;
@ -224,11 +224,11 @@ void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, unsigned int wi
const unsigned char *src_pixel = surface->pixels; const unsigned char *src_pixel = surface->pixels;
// Convert the SDL_Surface's colour-keyed pixels to RGBA32 // 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]; 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[0];
*buffer_pointer++ = src_pixel[1]; *buffer_pointer++ = src_pixel[1];
@ -413,7 +413,7 @@ void RenderBackend_HandleRenderTargetLoss(void)
surface->lost = true; surface->lost = true;
} }
void RenderBackend_HandleWindowResize(unsigned int width, unsigned int height) void RenderBackend_HandleWindowResize(size_t width, size_t height)
{ {
(void)width; (void)width;
(void)height; (void)height;

View file

@ -30,7 +30,7 @@ static RenderBackend_Surface framebuffer;
static unsigned char glyph_colour_channels[3]; static unsigned char glyph_colour_channels[3];
static RenderBackend_Surface *glyph_destination_surface; 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)) if (WindowBackend_Software_CreateWindow(window_title, screen_width, screen_height, fullscreen))
{ {
@ -62,7 +62,7 @@ void RenderBackend_DrawScreen(void)
framebuffer.pixels = WindowBackend_Software_LockFramebuffer(&framebuffer.pitch); 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; (void)render_target;
@ -107,7 +107,7 @@ void RenderBackend_RestoreSurface(RenderBackend_Surface *surface)
(void)surface; (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)width;
(void)height; (void)height;
@ -119,7 +119,7 @@ unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, unsigne
return surface->pixels; 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)surface;
(void)width; (void)width;
@ -334,7 +334,7 @@ void RenderBackend_HandleRenderTargetLoss(void)
// No problem for us // 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); WindowBackend_Software_HandleWindowResize(width, height);
} }

View file

@ -38,8 +38,8 @@ typedef struct RenderBackend_Surface
{ {
GX2Texture texture; GX2Texture texture;
GX2ColorBuffer colour_buffer; GX2ColorBuffer colour_buffer;
unsigned int width; size_t width;
unsigned int height; size_t height;
bool render_target; bool render_target;
unsigned char *lock_buffer; // TODO - Dumb unsigned char *lock_buffer; // TODO - Dumb
} RenderBackend_Surface; } RenderBackend_Surface;
@ -93,8 +93,8 @@ static Viewport tv_viewport;
static Viewport drc_viewport; static Viewport drc_viewport;
static VertexBufferSlot *local_vertex_buffer; static VertexBufferSlot *local_vertex_buffer;
static unsigned long local_vertex_buffer_size; static size_t local_vertex_buffer_size;
static unsigned long current_vertex_buffer_slot; static size_t current_vertex_buffer_slot;
static RenderMode last_render_mode; static RenderMode last_render_mode;
static GX2Texture *last_source_texture; static GX2Texture *last_source_texture;
@ -130,8 +130,8 @@ static VertexBufferSlot* GetVertexBufferSlot(void)
static void FlushVertexBuffer(void) static void FlushVertexBuffer(void)
{ {
static unsigned long vertex_buffer_size; static size_t vertex_buffer_size;
static unsigned int current_vertex_buffer = 0; static size_t current_vertex_buffer = 0;
if (current_vertex_buffer_slot == 0) if (current_vertex_buffer_slot == 0)
return; return;
@ -176,7 +176,7 @@ static void FlushVertexBuffer(void)
current_vertex_buffer_slot = 0; 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) if ((float)actual_screen_width / (float)actual_screen_height > (float)framebuffer_surface->width / (float)framebuffer_surface->height)
{ {
@ -449,7 +449,7 @@ void RenderBackend_DrawScreen(void)
GX2SetContextState(gx2_context); 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)); RenderBackend_Surface *surface = (RenderBackend_Surface*)malloc(sizeof(RenderBackend_Surface));
@ -539,7 +539,7 @@ void RenderBackend_RestoreSurface(RenderBackend_Surface *surface)
(void)surface; (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) if (surface != NULL)
{ {
@ -554,7 +554,7 @@ unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, unsigne
return NULL; 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) if (surface != NULL)
{ {
@ -884,7 +884,7 @@ void RenderBackend_HandleRenderTargetLoss(void)
// Doesn't happen on the Wii U // 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)width;
(void)height; (void)height;

View file

@ -1,5 +1,7 @@
#pragma once #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_DestroyWindow(void);
void WindowBackend_OpenGL_Display(void); void WindowBackend_OpenGL_Display(void);

View file

@ -12,7 +12,7 @@
GLFWwindow *window; 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 #ifdef USE_OPENGLES2
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);

View file

@ -15,7 +15,7 @@ SDL_Window *window;
static SDL_GLContext context; 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 #ifdef USE_OPENGLES2
if (SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES) < 0) if (SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES) < 0)

View file

@ -2,9 +2,9 @@
#include <stddef.h> #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); void WindowBackend_Software_DestroyWindow(void);
unsigned char* WindowBackend_Software_LockFramebuffer(size_t *pitch); unsigned char* WindowBackend_Software_LockFramebuffer(size_t *pitch);
void WindowBackend_Software_UnlockFramebuffer(void); void WindowBackend_Software_UnlockFramebuffer(void);
void WindowBackend_Software_Display(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);

View file

@ -11,15 +11,15 @@
GLFWwindow *window; GLFWwindow *window;
static unsigned char *framebuffer; static unsigned char *framebuffer;
static int framebuffer_width; static size_t framebuffer_width;
static int framebuffer_height; static size_t framebuffer_height;
static float framebuffer_x_ratio; static float framebuffer_x_ratio;
static float framebuffer_y_ratio; static float framebuffer_y_ratio;
static GLuint screen_texture_id; 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_CLIENT_API, GLFW_OPENGL_API);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1);
@ -59,11 +59,11 @@ bool WindowBackend_Software_CreateWindow(const char *window_title, int screen_wi
glGenTextures(1, &screen_texture_id); glGenTextures(1, &screen_texture_id);
glBindTexture(GL_TEXTURE_2D, 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) while (framebuffer_texture_width < framebuffer_width)
framebuffer_texture_width <<= 1; framebuffer_texture_width <<= 1;
int framebuffer_texture_height = 1; size_t framebuffer_texture_height = 1;
while (framebuffer_texture_height < framebuffer_height) while (framebuffer_texture_height < framebuffer_height)
framebuffer_texture_height <<= 1; framebuffer_texture_height <<= 1;
@ -127,7 +127,7 @@ void WindowBackend_Software_Display(void)
glfwSwapBuffers(window); 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 // Do some viewport trickery, to fit the framebuffer in the center of the screen
GLint viewport_x; GLint viewport_x;

View file

@ -6,7 +6,7 @@
static unsigned char *framebuffer; static unsigned char *framebuffer;
static size_t framebuffer_pitch; 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)window_title;
(void)fullscreen; (void)fullscreen;
@ -45,7 +45,7 @@ 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)
{ {
(void)width; (void)width;
(void)height; (void)height;

View file

@ -13,7 +13,7 @@ SDL_Window *window;
static SDL_Surface *window_sdlsurface; static SDL_Surface *window_sdlsurface;
static SDL_Surface *framebuffer_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); window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screen_width, screen_height, 0);
@ -88,7 +88,7 @@ void WindowBackend_Software_Display(void)
Backend_PrintError("Couldn't copy window surface to the screen: %s", SDL_GetError()); 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)width;
(void)height; (void)height;

View file

@ -48,7 +48,7 @@ static GX2Texture screen_texture;
static Viewport tv_viewport; static Viewport tv_viewport;
static Viewport drc_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 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 @@ static void CalculateViewport(unsigned int actual_screen_width, unsigned int act
} }
} }
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)window_title;
(void)fullscreen; (void)fullscreen;
@ -265,7 +265,7 @@ ATTRIBUTE_HOT void WindowBackend_Software_Display(void)
WHBGfxFinishRender(); WHBGfxFinishRender();
} }
void WindowBackend_Software_HandleWindowResize(unsigned int width, unsigned int height) void WindowBackend_Software_HandleWindowResize(size_t width, size_t height)
{ {
(void)width; (void)width;
(void)height; (void)height;

View file

@ -12,19 +12,25 @@
#include "File.h" #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; size_t file_size;
unsigned char *file_buffer = LoadFileToMemory(path, &file_size); unsigned char *file_buffer = LoadFileToMemory(path, &file_size);
if (file_buffer != NULL) 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); free(file_buffer);

View file

@ -2,6 +2,6 @@
#include <stddef.h> #include <stddef.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);
unsigned char* DecodeBitmapFromFile(const char *path, unsigned int *width, unsigned int *height); unsigned char* DecodeBitmapFromFile(const char *path, size_t *width, size_t *height);
void FreeBitmap(unsigned char *buffer); void FreeBitmap(unsigned char *buffer);

View file

@ -147,10 +147,10 @@ void ReleaseSurface(SurfaceID s)
memset(&surface_metadata[s], 0, sizeof(surface_metadata[0])); 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 // 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); unsigned char *pixels = RenderBackend_LockSurface(surf[surf_no], &pitch, width * mag, height * mag);
if (pixels == NULL) if (pixels == NULL)
@ -159,7 +159,7 @@ static BOOL ScaleAndUploadSurface(const unsigned char *image_buffer, int width,
if (mag == 1) if (mag == 1)
{ {
// Just copy the pixels the way they are // 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]; const unsigned char *src_row = &image_buffer[y * width * 3];
unsigned char *dst_row = &pixels[y * pitch]; unsigned char *dst_row = &pixels[y * pitch];
@ -170,7 +170,7 @@ static BOOL ScaleAndUploadSurface(const unsigned char *image_buffer, int width,
else else
{ {
// Upscale the bitmap to the game's internal resolution // 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]; const unsigned char *src_row = &image_buffer[y * width * 3];
unsigned char *dst_row = &pixels[y * pitch * mag]; unsigned char *dst_row = &pixels[y * pitch * mag];
@ -178,7 +178,7 @@ static BOOL ScaleAndUploadSurface(const unsigned char *image_buffer, int width,
const unsigned char *src_ptr = src_row; const unsigned char *src_ptr = src_row;
unsigned char *dst_ptr = dst_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) for (int i = 0; i < mag; ++i)
{ {
@ -215,7 +215,7 @@ BOOL MakeSurface_Resource(const char *name, SurfaceID surf_no)
if (data == NULL) if (data == NULL)
return FALSE; return FALSE;
unsigned int width, height; size_t width, height;
unsigned char *image_buffer = DecodeBitmap(data, size, &width, &height); unsigned char *image_buffer = DecodeBitmap(data, size, &width, &height);
if (image_buffer == NULL) if (image_buffer == NULL)
@ -273,7 +273,7 @@ BOOL MakeSurface_File(const char *name, SurfaceID surf_no)
return FALSE; return FALSE;
} }
unsigned int width, height; size_t width, height;
unsigned char *image_buffer = DecodeBitmapFromFile(path.c_str(), &width, &height); unsigned char *image_buffer = DecodeBitmapFromFile(path.c_str(), &width, &height);
if (image_buffer == NULL) if (image_buffer == NULL)
@ -319,7 +319,7 @@ BOOL ReloadBitmap_Resource(const char *name, SurfaceID surf_no)
if (data == NULL) if (data == NULL)
return FALSE; return FALSE;
unsigned int width, height; size_t width, height;
unsigned char *image_buffer = DecodeBitmap(data, size, &width, &height); unsigned char *image_buffer = DecodeBitmap(data, size, &width, &height);
if (!ScaleAndUploadSurface(image_buffer, width, height, surf_no)) if (!ScaleAndUploadSurface(image_buffer, width, height, surf_no))
@ -357,7 +357,7 @@ BOOL ReloadBitmap_File(const char *name, SurfaceID surf_no)
return FALSE; return FALSE;
} }
unsigned int width, height; size_t width, height;
unsigned char *image_buffer = DecodeBitmapFromFile(path.c_str(), &width, &height); unsigned char *image_buffer = DecodeBitmapFromFile(path.c_str(), &width, &height);
if (image_buffer == NULL) if (image_buffer == NULL)
@ -647,7 +647,7 @@ void InitTextObject(const char *name)
std::string path = gDataPath + "/Font/font"; std::string path = gDataPath + "/Font/font";
// Get font size // Get font size
unsigned int width, height; size_t width, height;
switch (mag) switch (mag)
{ {

View file

@ -842,7 +842,7 @@ static const unsigned short shiftjis_to_unicode_lookup[0x3100] = {
0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020 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; size_t lookup_index;
@ -875,9 +875,9 @@ static unsigned short ShiftJISToUnicode(const unsigned char *string, unsigned in
#else #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 long charcode;
unsigned int zero_bit = 0; unsigned int zero_bit = 0;
@ -1006,11 +1006,11 @@ static Glyph* GetGlyph(FontObject *font_object, unsigned long unicode_value)
switch (font_object->face->glyph->bitmap.pixel_mode) switch (font_object->face->glyph->bitmap.pixel_mode)
{ {
case FT_PIXEL_MODE_GRAY: 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]; 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 = GammaCorrect((*pixel_pointer * 0xFF) / (bitmap.num_grays - 1));
++pixel_pointer; ++pixel_pointer;
@ -1020,11 +1020,11 @@ static Glyph* GetGlyph(FontObject *font_object, unsigned long unicode_value)
break; break;
case FT_PIXEL_MODE_MONO: 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]; 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 = *pixel_pointer ? 0xFF : 0;
++pixel_pointer; ++pixel_pointer;
@ -1058,7 +1058,7 @@ static Glyph* GetGlyph(FontObject *font_object, unsigned long unicode_value)
return NULL; 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)); FontObject *font_object = (FontObject*)malloc(sizeof(FontObject));
@ -1118,7 +1118,7 @@ FontObject* LoadFontFromData(const unsigned char *data, size_t data_size, unsign
return NULL; 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; FontObject *font_object = NULL;
@ -1149,7 +1149,7 @@ void DrawText(FontObject *font_object, RenderBackend_Surface *surface, int x, in
while (string_pointer != string_end) while (string_pointer != string_end)
{ {
unsigned int bytes_read; size_t bytes_read;
#ifdef JAPANESE #ifdef JAPANESE
const unsigned short unicode_value = ShiftJISToUnicode(string_pointer, &bytes_read); const unsigned short unicode_value = ShiftJISToUnicode(string_pointer, &bytes_read);
#else #else

View file

@ -6,7 +6,7 @@
typedef struct FontObject FontObject; typedef struct FontObject FontObject;
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* 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);
void DrawText(FontObject *font_object, RenderBackend_Surface *surface, int x, int y, unsigned long colour, const char *string); void DrawText(FontObject *font_object, RenderBackend_Surface *surface, int x, int y, unsigned long colour, const char *string);
void UnloadFont(FontObject *font_object); void UnloadFont(FontObject *font_object);

View file

@ -294,7 +294,7 @@ int main(int argc, char *argv[])
if (window_icon_resource_data != NULL) 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); 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) if (window_icon_rgb_pixels != NULL)
@ -311,7 +311,7 @@ int main(int argc, char *argv[])
if (cursor_resource_data != NULL) 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); unsigned char *cursor_rgb_pixels = DecodeBitmap(cursor_resource_data, cursor_resource_size, &cursor_width, &cursor_height);
if (cursor_rgb_pixels != NULL) if (cursor_rgb_pixels != NULL)