Bitmap shouldn't be typedefed

This commit is contained in:
UnknownShadow200 2020-08-01 12:19:58 +10:00
parent f2cfdb372d
commit e221e9f343
27 changed files with 167 additions and 158 deletions

View File

@ -15,7 +15,7 @@
#define LIQUID_ANIM_MAX 64 #define LIQUID_ANIM_MAX 64
#define WATER_TEX_LOC 14 #define WATER_TEX_LOC 14
#define LAVA_TEX_LOC 30 #define LAVA_TEX_LOC 30
static void Animations_Update(int loc, Bitmap* bmp, int stride); static void Animations_Update(int loc, struct Bitmap* bmp, int stride);
#ifndef CC_BUILD_WEB #ifndef CC_BUILD_WEB
/* Based off the incredible work from https://dl.dropboxusercontent.com/u/12694594/lava.txt /* Based off the incredible work from https://dl.dropboxusercontent.com/u/12694594/lava.txt
@ -37,7 +37,7 @@ static void LavaAnimation_Tick(void) {
float soupHeat, potHeat, col; float soupHeat, potHeat, col;
int size, mask, shift; int size, mask, shift;
int x, y, i = 0; int x, y, i = 0;
Bitmap bmp; struct Bitmap bmp;
size = min(Atlas2D.TileSize, LIQUID_ANIM_MAX); size = min(Atlas2D.TileSize, LIQUID_ANIM_MAX);
mask = size - 1; mask = size - 1;
@ -118,7 +118,7 @@ static void WaterAnimation_Tick(void) {
float soupHeat, col; float soupHeat, col;
int size, mask, shift; int size, mask, shift;
int x, y, i = 0; int x, y, i = 0;
Bitmap bmp; struct Bitmap bmp;
size = min(Atlas2D.TileSize, LIQUID_ANIM_MAX); size = min(Atlas2D.TileSize, LIQUID_ANIM_MAX);
mask = size - 1; mask = size - 1;
@ -179,7 +179,7 @@ struct AnimationData {
cc_uint16 frameDelay; /* Delay between each frame */ cc_uint16 frameDelay; /* Delay between each frame */
}; };
static Bitmap anims_bmp; static struct Bitmap anims_bmp;
static struct AnimationData anims_list[ATLAS1D_MAX_ATLASES]; static struct AnimationData anims_list[ATLAS1D_MAX_ATLASES];
static int anims_count; static int anims_count;
static cc_bool anims_validated, useLavaAnim, useWaterAnim, alwaysLavaAnim, alwaysWaterAnim; static cc_bool anims_validated, useLavaAnim, useWaterAnim, alwaysLavaAnim, alwaysWaterAnim;
@ -242,7 +242,7 @@ static void Animations_ReadDescription(struct Stream* stream, const String* path
} }
} }
static void Animations_Update(int texLoc, Bitmap* bmp, int stride) { static void Animations_Update(int texLoc, struct Bitmap* bmp, int stride) {
int dstX = Atlas1D_Index(texLoc); int dstX = Atlas1D_Index(texLoc);
int dstY = Atlas1D_RowId(texLoc) * Atlas2D.TileSize; int dstY = Atlas1D_RowId(texLoc) * Atlas2D.TileSize;
GfxResourceID tex; GfxResourceID tex;
@ -252,8 +252,8 @@ static void Animations_Update(int texLoc, Bitmap* bmp, int stride) {
} }
static void Animations_Apply(struct AnimationData* data) { static void Animations_Apply(struct AnimationData* data) {
struct Bitmap frame;
int loc, size; int loc, size;
Bitmap frame;
if (data->delay) { data->delay--; return; } if (data->delay) { data->delay--; return; }
data->state++; data->state++;

View File

@ -8,7 +8,8 @@
#include "Errors.h" #include "Errors.h"
#include "Utils.h" #include "Utils.h"
void Bitmap_UNSAFE_CopyBlock(int srcX, int srcY, int dstX, int dstY, Bitmap* src, Bitmap* dst, int size) { void Bitmap_UNSAFE_CopyBlock(int srcX, int srcY, int dstX, int dstY,
struct Bitmap* src, struct Bitmap* dst, int size) {
int x, y; int x, y;
for (y = 0; y < size; y++) { for (y = 0; y < size; y++) {
BitmapCol* srcRow = Bitmap_GetRow(src, srcY + y) + srcX; BitmapCol* srcRow = Bitmap_GetRow(src, srcY + y) + srcX;
@ -17,17 +18,17 @@ void Bitmap_UNSAFE_CopyBlock(int srcX, int srcY, int dstX, int dstY, Bitmap* src
} }
} }
void Bitmap_Allocate(Bitmap* bmp, int width, int height) { void Bitmap_Allocate(struct Bitmap* bmp, int width, int height) {
bmp->width = width; bmp->height = height; bmp->width = width; bmp->height = height;
bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, 4, "bitmap data"); bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, 4, "bitmap data");
} }
void Bitmap_TryAllocate(Bitmap* bmp, int width, int height) { void Bitmap_TryAllocate(struct Bitmap* bmp, int width, int height) {
bmp->width = width; bmp->height = height; bmp->width = width; bmp->height = height;
bmp->scan0 = (BitmapCol*)Mem_TryAlloc(width * height, 4); bmp->scan0 = (BitmapCol*)Mem_TryAlloc(width * height, 4);
} }
void Bitmap_AllocateClearedPow2(Bitmap* bmp, int width, int height) { void Bitmap_AllocateClearedPow2(struct Bitmap* bmp, int width, int height) {
width = Math_NextPowOf2(width); width = Math_NextPowOf2(width);
height = Math_NextPowOf2(height); height = Math_NextPowOf2(height);
@ -35,7 +36,7 @@ void Bitmap_AllocateClearedPow2(Bitmap* bmp, int width, int height) {
bmp->scan0 = (BitmapCol*)Mem_AllocCleared(width * height, 4, "bitmap data"); bmp->scan0 = (BitmapCol*)Mem_AllocCleared(width * height, 4, "bitmap data");
} }
void Bitmap_TryAllocateClearedPow2(Bitmap* bmp, int width, int height) { void Bitmap_TryAllocateClearedPow2(struct Bitmap* bmp, int width, int height) {
width = Math_NextPowOf2(width); width = Math_NextPowOf2(width);
height = Math_NextPowOf2(height); height = Math_NextPowOf2(height);
@ -43,7 +44,8 @@ void Bitmap_TryAllocateClearedPow2(Bitmap* bmp, int width, int height) {
bmp->scan0 = (BitmapCol*)Mem_TryAllocCleared(width * height, 4); bmp->scan0 = (BitmapCol*)Mem_TryAllocCleared(width * height, 4);
} }
void Bitmap_Scale(Bitmap* dst, Bitmap* src, int srcX, int srcY, int srcWidth, int srcHeight) { void Bitmap_Scale(struct Bitmap* dst, struct Bitmap* src,
int srcX, int srcY, int srcWidth, int srcHeight) {
BitmapCol* dstRow; BitmapCol* dstRow;
BitmapCol* srcRow; BitmapCol* srcRow;
int x, y, width, height; int x, y, width, height;
@ -320,7 +322,7 @@ static Png_RowExpander Png_GetExpander(cc_uint8 col, cc_uint8 bitsPerSample) {
} }
/* Sets alpha to 0 for any pixels in the bitmap whose RGB is same as col */ /* Sets alpha to 0 for any pixels in the bitmap whose RGB is same as col */
static void ComputeTransparency(Bitmap* bmp, BitmapCol col) { static void ComputeTransparency(struct Bitmap* bmp, BitmapCol col) {
BitmapCol trnsRGB = col & BITMAPCOL_RGB_MASK; BitmapCol trnsRGB = col & BITMAPCOL_RGB_MASK;
int x, y, width = bmp->width, height = bmp->height; int x, y, width = bmp->width, height = bmp->height;
@ -338,7 +340,7 @@ static void ComputeTransparency(Bitmap* bmp, BitmapCol col) {
#define PNG_BUFFER_SIZE ((PNG_MAX_DIMS * 2 * 4 + 1) * 2) #define PNG_BUFFER_SIZE ((PNG_MAX_DIMS * 2 * 4 + 1) * 2)
/* TODO: Test a lot of .png files and ensure output is right */ /* TODO: Test a lot of .png files and ensure output is right */
cc_result Png_Decode(Bitmap* bmp, struct Stream* stream) { cc_result Png_Decode(struct Bitmap* bmp, struct Stream* stream) {
cc_uint8 tmp[PNG_PALETTE * 3]; cc_uint8 tmp[PNG_PALETTE * 3];
cc_uint32 dataSize, fourCC; cc_uint32 dataSize, fourCC;
cc_result res; cc_result res;
@ -630,8 +632,9 @@ static void Png_EncodeRow(const cc_uint8* cur, const cc_uint8* prior, cc_uint8*
best[0] = bestFilter; best[0] = bestFilter;
} }
static int Png_SelectRow(Bitmap* bmp, int y) { return y; } static int Png_SelectRow(struct Bitmap* bmp, int y) { return y; }
cc_result Png_Encode(Bitmap* bmp, struct Stream* stream, Png_RowSelector selectRow, cc_bool alpha) { cc_result Png_Encode(struct Bitmap* bmp, struct Stream* stream,
Png_RowSelector selectRow, cc_bool alpha) {
cc_uint8 tmp[32]; cc_uint8 tmp[32];
/* TODO: This should be * 4 for alpha (should switch to mem_alloc though) */ /* TODO: This should be * 4 for alpha (should switch to mem_alloc though) */
cc_uint8 prevLine[PNG_MAX_DIMS * 3], curLine[PNG_MAX_DIMS * 3]; cc_uint8 prevLine[PNG_MAX_DIMS * 3], curLine[PNG_MAX_DIMS * 3];

View File

@ -42,7 +42,7 @@ typedef cc_uint32 BitmapCol;
#define BITMAPCOL_WHITE BitmapCol_Make(255, 255, 255, 255) #define BITMAPCOL_WHITE BitmapCol_Make(255, 255, 255, 255)
/* A 2D array of BitmapCol pixels */ /* A 2D array of BitmapCol pixels */
typedef struct Bitmap_ { BitmapCol* scan0; int width, height; } Bitmap; struct Bitmap { BitmapCol* scan0; int width, height; };
#define PNG_MAX_DIMS 0x8000 #define PNG_MAX_DIMS 0x8000
/* Returns number of bytes a bitmap consumes. */ /* Returns number of bytes a bitmap consumes. */
@ -58,34 +58,37 @@ typedef struct Bitmap_ { BitmapCol* scan0; int width, height; } Bitmap;
/* Copies a rectangle of pixels from one bitmap to another. */ /* Copies a rectangle of pixels from one bitmap to another. */
/* NOTE: If src and dst are the same, src and dst rectangles MUST NOT overlap. */ /* NOTE: If src and dst are the same, src and dst rectangles MUST NOT overlap. */
/* NOTE: Rectangles are NOT checked for whether they lie inside the bitmaps. */ /* NOTE: Rectangles are NOT checked for whether they lie inside the bitmaps. */
void Bitmap_UNSAFE_CopyBlock(int srcX, int srcY, int dstX, int dstY, Bitmap* src, Bitmap* dst, int size); void Bitmap_UNSAFE_CopyBlock(int srcX, int srcY, int dstX, int dstY,
struct Bitmap* src, struct Bitmap* dst, int size);
/* Allocates a new bitmap of the given dimensions. */ /* Allocates a new bitmap of the given dimensions. */
/* NOTE: You are responsible for freeing its memory! */ /* NOTE: You are responsible for freeing its memory! */
void Bitmap_Allocate(Bitmap* bmp, int width, int height); void Bitmap_Allocate(struct Bitmap* bmp, int width, int height);
/* Attemps to allocates a new bitmap of the given dimensions. */ /* Attemps to allocates a new bitmap of the given dimensions. */
/* NOTE: You are responsible for freeing its memory! */ /* NOTE: You are responsible for freeing its memory! */
void Bitmap_TryAllocate(Bitmap* bmp, int width, int height); void Bitmap_TryAllocate(struct Bitmap* bmp, int width, int height);
/* Allocates a power-of-2 sized bitmap equal to or greater than the given size, and clears it to 0. */ /* Allocates a power-of-2 sized bitmap equal to or greater than the given size, and clears it to 0. */
/* NOTE: You are responsible for freeing its memory! */ /* NOTE: You are responsible for freeing its memory! */
void Bitmap_AllocateClearedPow2(Bitmap* bmp, int width, int height); void Bitmap_AllocateClearedPow2(struct Bitmap* bmp, int width, int height);
/* Attempts to allocate a power-of-2 sized bitmap >= than the given size, and clears it to 0. */ /* Attempts to allocate a power-of-2 sized bitmap >= than the given size, and clears it to 0. */
/* NOTE: You are responsible for freeing its memory! */ /* NOTE: You are responsible for freeing its memory! */
void Bitmap_TryAllocateClearedPow2(Bitmap* bmp, int width, int height); void Bitmap_TryAllocateClearedPow2(struct Bitmap* bmp, int width, int height);
/* Scales a region of the source bitmap to occupy the entirety of the destination bitmap. */ /* Scales a region of the source bitmap to occupy the entirety of the destination bitmap. */
/* The pixels from the region are scaled upwards or downwards depending on destination width and height. */ /* The pixels from the region are scaled upwards or downwards depending on destination width and height. */
CC_API void Bitmap_Scale(Bitmap* dst, Bitmap* src, int srcX, int srcY, int srcWidth, int srcHeight); CC_API void Bitmap_Scale(struct Bitmap* dst, struct Bitmap* src,
int srcX, int srcY, int srcWidth, int srcHeight);
/* Whether data starts with PNG format signature/identifier. */ /* Whether data starts with PNG format signature/identifier. */
cc_bool Png_Detect(const cc_uint8* data, cc_uint32 len); cc_bool Png_Detect(const cc_uint8* data, cc_uint32 len);
typedef int (*Png_RowSelector)(Bitmap* bmp, int row); typedef int (*Png_RowSelector)(struct Bitmap* bmp, int row);
/* /*
Decodes a bitmap in PNG format. Partially based off information from Decodes a bitmap in PNG format. Partially based off information from
https://handmade.network/forums/wip/t/2363-implementing_a_basic_png_reader_the_handmade_way https://handmade.network/forums/wip/t/2363-implementing_a_basic_png_reader_the_handmade_way
https://github.com/nothings/stb/blob/master/stb_image.h https://github.com/nothings/stb/blob/master/stb_image.h
*/ */
CC_API cc_result Png_Decode(Bitmap* bmp, struct Stream* stream); CC_API cc_result Png_Decode(struct Bitmap* bmp, struct Stream* stream);
/* Encodes a bitmap in PNG format. */ /* Encodes a bitmap in PNG format. */
/* selectRow is optional. Can be used to modify how rows are encoded. (e.g. flip image) */ /* selectRow is optional. Can be used to modify how rows are encoded. (e.g. flip image) */
/* if alpha is non-zero, RGBA channels are saved, otherwise only RGB channels are. */ /* if alpha is non-zero, RGBA channels are saved, otherwise only RGB channels are. */
CC_API cc_result Png_Encode(Bitmap* bmp, struct Stream* stream, Png_RowSelector selectRow, cc_bool alpha); CC_API cc_result Png_Encode(struct Bitmap* bmp, struct Stream* stream,
Png_RowSelector selectRow, cc_bool alpha);
#endif #endif

View File

@ -342,7 +342,7 @@ void Block_RecalculateAllSpriteBB(void) {
} }
} }
static float Block_GetSpriteBB_MinX(int size, int tileX, int tileY, const Bitmap* bmp) { static float GetSpriteBB_MinX(int size, int tileX, int tileY, const struct Bitmap* bmp) {
BitmapCol* row; BitmapCol* row;
int x, y; int x, y;
@ -355,7 +355,7 @@ static float Block_GetSpriteBB_MinX(int size, int tileX, int tileY, const Bitmap
return 1.0f; return 1.0f;
} }
static float Block_GetSpriteBB_MinY(int size, int tileX, int tileY, const Bitmap* bmp) { static float GetSpriteBB_MinY(int size, int tileX, int tileY, const struct Bitmap* bmp) {
BitmapCol* row; BitmapCol* row;
int x, y; int x, y;
@ -368,7 +368,7 @@ static float Block_GetSpriteBB_MinY(int size, int tileX, int tileY, const Bitmap
return 1.0f; return 1.0f;
} }
static float Block_GetSpriteBB_MaxX(int size, int tileX, int tileY, const Bitmap* bmp) { static float GetSpriteBB_MaxX(int size, int tileX, int tileY, const struct Bitmap* bmp) {
BitmapCol* row; BitmapCol* row;
int x, y; int x, y;
@ -381,7 +381,7 @@ static float Block_GetSpriteBB_MaxX(int size, int tileX, int tileY, const Bitmap
return 0.0f; return 0.0f;
} }
static float Block_GetSpriteBB_MaxY(int size, int tileX, int tileY, const Bitmap* bmp) { static float GetSpriteBB_MaxY(int size, int tileX, int tileY, const struct Bitmap* bmp) {
BitmapCol* row; BitmapCol* row;
int x, y; int x, y;
@ -395,7 +395,7 @@ static float Block_GetSpriteBB_MaxY(int size, int tileX, int tileY, const Bitmap
} }
void Block_RecalculateBB(BlockID block) { void Block_RecalculateBB(BlockID block) {
Bitmap* bmp = &Atlas2D.Bmp; struct Bitmap* bmp = &Atlas2D.Bmp;
int tileSize = Atlas2D.TileSize; int tileSize = Atlas2D.TileSize;
TextureLoc texLoc = Block_Tex(block, FACE_XMAX); TextureLoc texLoc = Block_Tex(block, FACE_XMAX);
int x = Atlas2D_TileX(texLoc), y = Atlas2D_TileY(texLoc); int x = Atlas2D_TileX(texLoc), y = Atlas2D_TileY(texLoc);
@ -405,10 +405,10 @@ void Block_RecalculateBB(BlockID block) {
Vec3 minRaw, maxRaw; Vec3 minRaw, maxRaw;
if (y < Atlas2D.RowsCount) { if (y < Atlas2D.RowsCount) {
minX = Block_GetSpriteBB_MinX(tileSize, x, y, bmp); minX = GetSpriteBB_MinX(tileSize, x, y, bmp);
minY = Block_GetSpriteBB_MinY(tileSize, x, y, bmp); minY = GetSpriteBB_MinY(tileSize, x, y, bmp);
maxX = Block_GetSpriteBB_MaxX(tileSize, x, y, bmp); maxX = GetSpriteBB_MaxX(tileSize, x, y, bmp);
maxY = Block_GetSpriteBB_MaxY(tileSize, x, y, bmp); maxY = GetSpriteBB_MaxY(tileSize, x, y, bmp);
} }
minRaw = Vec3_RotateY3(minX - 0.5f, minY, 0.0f, 45.0f * MATH_DEG2RAD); minRaw = Vec3_RotateY3(minX - 0.5f, minY, 0.0f, 45.0f * MATH_DEG2RAD);

View File

@ -100,7 +100,7 @@ static void CheckFont(void) {
Logger_Abort("Unable to init default font"); Logger_Abort("Unable to init default font");
} }
static Bitmap fontBitmap; static struct Bitmap fontBitmap;
static int tileSize = 8; /* avoid divide by 0 if default.png missing */ static int tileSize = 8; /* avoid divide by 0 if default.png missing */
/* So really 16 characters per row */ /* So really 16 characters per row */
#define LOG2_CHARS_PER_ROW 4 #define LOG2_CHARS_PER_ROW 4
@ -138,7 +138,7 @@ static void FreeFontBitmap(void) {
Mem_Free(fontBitmap.scan0); Mem_Free(fontBitmap.scan0);
} }
cc_bool Drawer2D_SetFontBitmap(Bitmap* bmp) { cc_bool Drawer2D_SetFontBitmap(struct Bitmap* bmp) {
/* If not all of these cases are accounted for, end up overwriting memory after tileWidths */ /* If not all of these cases are accounted for, end up overwriting memory after tileWidths */
if (bmp->width != bmp->height) { if (bmp->width != bmp->height) {
static const String msg = String_FromConst("&cWidth of default.png must equal its height"); static const String msg = String_FromConst("&cWidth of default.png must equal its height");
@ -174,13 +174,13 @@ void Font_ReducePadding(struct FontDesc* desc, int scale) {
/* Measures width of the given text when drawn with the given system font. */ /* Measures width of the given text when drawn with the given system font. */
static int Font_SysTextWidth(struct DrawTextArgs* args); static int Font_SysTextWidth(struct DrawTextArgs* args);
/* Draws the given text with the given system font onto the given bitmap. */ /* Draws the given text with the given system font onto the given bitmap. */
static void Font_SysTextDraw(struct DrawTextArgs* args, Bitmap* bmp, int x, int y, cc_bool shadow); static void Font_SysTextDraw(struct DrawTextArgs* args, struct Bitmap* bmp, int x, int y, cc_bool shadow);
/*########################################################################################################################* /*########################################################################################################################*
*---------------------------------------------------Drawing functions-----------------------------------------------------* *---------------------------------------------------Drawing functions-----------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
cc_bool Drawer2D_Clamp(Bitmap* bmp, int* x, int* y, int* width, int* height) { cc_bool Drawer2D_Clamp(struct Bitmap* bmp, int* x, int* y, int* width, int* height) {
if (*x >= bmp->width || *y >= bmp->height) return false; if (*x >= bmp->width || *y >= bmp->height) return false;
/* origin is negative, move inside */ /* origin is negative, move inside */
@ -193,7 +193,7 @@ cc_bool Drawer2D_Clamp(Bitmap* bmp, int* x, int* y, int* width, int* height) {
} }
#define Drawer2D_ClampPixel(p) p = (p < 0 ? 0 : (p > 255 ? 255 : p)) #define Drawer2D_ClampPixel(p) p = (p < 0 ? 0 : (p > 255 ? 255 : p))
void Gradient_Noise(Bitmap* bmp, BitmapCol col, int variation, void Gradient_Noise(struct Bitmap* bmp, BitmapCol col, int variation,
int x, int y, int width, int height) { int x, int y, int width, int height) {
BitmapCol* dst; BitmapCol* dst;
int R, G, B, xx, yy, n; int R, G, B, xx, yy, n;
@ -217,7 +217,7 @@ void Gradient_Noise(Bitmap* bmp, BitmapCol col, int variation,
} }
} }
void Gradient_Vertical(Bitmap* bmp, BitmapCol a, BitmapCol b, void Gradient_Vertical(struct Bitmap* bmp, BitmapCol a, BitmapCol b,
int x, int y, int width, int height) { int x, int y, int width, int height) {
BitmapCol* row, col; BitmapCol* row, col;
int xx, yy; int xx, yy;
@ -238,7 +238,7 @@ void Gradient_Vertical(Bitmap* bmp, BitmapCol a, BitmapCol b,
} }
} }
void Gradient_Blend(Bitmap* bmp, BitmapCol col, int blend, void Gradient_Blend(struct Bitmap* bmp, BitmapCol col, int blend,
int x, int y, int width, int height) { int x, int y, int width, int height) {
BitmapCol* dst; BitmapCol* dst;
int R, G, B, xx, yy; int R, G, B, xx, yy;
@ -267,7 +267,7 @@ void Gradient_Blend(Bitmap* bmp, BitmapCol col, int blend,
} }
} }
void Gradient_Tint(Bitmap* bmp, cc_uint8 tintA, cc_uint8 tintB, void Gradient_Tint(struct Bitmap* bmp, cc_uint8 tintA, cc_uint8 tintB,
int x, int y, int width, int height) { int x, int y, int width, int height) {
BitmapCol* row, col; BitmapCol* row, col;
cc_uint8 tint; cc_uint8 tint;
@ -291,7 +291,7 @@ void Gradient_Tint(Bitmap* bmp, cc_uint8 tintA, cc_uint8 tintB,
} }
} }
void Drawer2D_BmpCopy(Bitmap* dst, int x, int y, Bitmap* src) { void Drawer2D_BmpCopy(struct Bitmap* dst, int x, int y, struct Bitmap* src) {
int width = src->width, height = src->height; int width = src->width, height = src->height;
BitmapCol* dstRow; BitmapCol* dstRow;
BitmapCol* srcRow; BitmapCol* srcRow;
@ -306,7 +306,8 @@ void Drawer2D_BmpCopy(Bitmap* dst, int x, int y, Bitmap* src) {
} }
} }
void Drawer2D_Clear(Bitmap* bmp, BitmapCol col, int x, int y, int width, int height) { void Drawer2D_Clear(struct Bitmap* bmp, BitmapCol col,
int x, int y, int width, int height) {
BitmapCol* row; BitmapCol* row;
int xx, yy; int xx, yy;
if (!Drawer2D_Clamp(bmp, &x, &y, &width, &height)) return; if (!Drawer2D_Clamp(bmp, &x, &y, &width, &height)) return;
@ -320,8 +321,8 @@ void Drawer2D_Clear(Bitmap* bmp, BitmapCol col, int x, int y, int width, int hei
void Drawer2D_MakeTextTexture(struct Texture* tex, struct DrawTextArgs* args) { void Drawer2D_MakeTextTexture(struct Texture* tex, struct DrawTextArgs* args) {
static struct Texture empty = { 0, Tex_Rect(0,0, 0,0), Tex_UV(0,0, 1,1) }; static struct Texture empty = { 0, Tex_Rect(0,0, 0,0), Tex_UV(0,0, 1,1) };
struct Bitmap bmp;
int width, height; int width, height;
Bitmap bmp;
/* pointless to draw anything when context is lost */ /* pointless to draw anything when context is lost */
if (Gfx.LostContext) { *tex = empty; return; } if (Gfx.LostContext) { *tex = empty; return; }
@ -337,7 +338,7 @@ void Drawer2D_MakeTextTexture(struct Texture* tex, struct DrawTextArgs* args) {
Mem_Free(bmp.scan0); Mem_Free(bmp.scan0);
} }
void Drawer2D_MakeTexture(struct Texture* tex, Bitmap* bmp, int width, int height) { void Drawer2D_MakeTexture(struct Texture* tex, struct Bitmap* bmp, int width, int height) {
tex->ID = Gfx_CreateTexture(bmp, false, false); tex->ID = Gfx_CreateTexture(bmp, false, false);
tex->X = 0; tex->Width = width; tex->X = 0; tex->Width = width;
tex->Y = 0; tex->Height = height; tex->Y = 0; tex->Height = height;
@ -417,7 +418,7 @@ void Drawer2D_ReducePadding_Height(int* height, int point, int scale) {
} }
/* Quickly fills the given box region */ /* Quickly fills the given box region */
static void Drawer2D_Underline(Bitmap* bmp, int x, int y, int width, int height, BitmapCol col) { static void Drawer2D_Underline(struct Bitmap* bmp, int x, int y, int width, int height, BitmapCol col) {
BitmapCol* row; BitmapCol* row;
int xx, yy; int xx, yy;
@ -432,7 +433,7 @@ static void Drawer2D_Underline(Bitmap* bmp, int x, int y, int width, int height,
} }
} }
static void DrawBitmappedTextCore(Bitmap* bmp, struct DrawTextArgs* args, int x, int y, cc_bool shadow) { static void DrawBitmappedTextCore(struct Bitmap* bmp, struct DrawTextArgs* args, int x, int y, cc_bool shadow) {
BitmapCol col; BitmapCol col;
String text = args->text; String text = args->text;
int i, point = args->font->size, count = 0; int i, point = args->font->size, count = 0;
@ -530,7 +531,7 @@ static void DrawBitmappedTextCore(Bitmap* bmp, struct DrawTextArgs* args, int x,
} }
} }
static void DrawBitmappedText(Bitmap* bmp, struct DrawTextArgs* args, int x, int y) { static void DrawBitmappedText(struct Bitmap* bmp, struct DrawTextArgs* args, int x, int y) {
int offset = Drawer2D_ShadowOffset(args->font->size); int offset = Drawer2D_ShadowOffset(args->font->size);
if (args->useShadow) { if (args->useShadow) {
@ -565,7 +566,7 @@ static int MeasureBitmappedWidth(const struct DrawTextArgs* args) {
return width; return width;
} }
void Drawer2D_DrawText(Bitmap* bmp, struct DrawTextArgs* args, int x, int y) { void Drawer2D_DrawText(struct Bitmap* bmp, struct DrawTextArgs* args, int x, int y) {
if (Drawer2D_IsEmptyText(&args->text)) return; if (Drawer2D_IsEmptyText(&args->text)) return;
if (Drawer2D_BitmappedText) { DrawBitmappedText(bmp, args, x, y); return; } if (Drawer2D_BitmappedText) { DrawBitmappedText(bmp, args, x, y); return; }
@ -593,7 +594,8 @@ int Drawer2D_FontHeight(const struct FontDesc* font, cc_bool useShadow) {
return height; return height;
} }
void Drawer2D_DrawClippedText(Bitmap* bmp, struct DrawTextArgs* args, int x, int y, int maxWidth) { void Drawer2D_DrawClippedText(struct Bitmap* bmp, struct DrawTextArgs* args,
int x, int y, int maxWidth) {
char strBuffer[512]; char strBuffer[512];
struct DrawTextArgs part; struct DrawTextArgs part;
int i, width; int i, width;
@ -652,7 +654,7 @@ static void OnReset(void) {
} }
static void OnFileChanged(void* obj, struct Stream* src, const String* name) { static void OnFileChanged(void* obj, struct Stream* src, const String* name) {
Bitmap bmp; struct Bitmap bmp;
cc_result res; cc_result res;
if (!String_CaselessEqualsConst(name, "default.png")) return; if (!String_CaselessEqualsConst(name, "default.png")) return;
@ -712,7 +714,7 @@ void Font_Free(struct FontDesc* desc) {
void SysFonts_Register(const String* path) { } void SysFonts_Register(const String* path) { }
static int Font_SysTextWidth(struct DrawTextArgs* args) { return 0; } static int Font_SysTextWidth(struct DrawTextArgs* args) { return 0; }
static void Font_SysTextDraw(struct DrawTextArgs* args, Bitmap* bmp, int x, int y, cc_bool shadow) { } static void Font_SysTextDraw(struct DrawTextArgs* args, struct Bitmap* bmp, int x, int y, cc_bool shadow) { }
#else #else
#include "freetype/ft2build.h" #include "freetype/ft2build.h"
#include "freetype/freetype.h" #include "freetype/freetype.h"
@ -1057,7 +1059,7 @@ static int Font_SysTextWidth(struct DrawTextArgs* args) {
return width; return width;
} }
static void DrawGrayscaleGlyph(FT_Bitmap* img, Bitmap* bmp, int x, int y, BitmapCol col) { static void DrawGrayscaleGlyph(FT_Bitmap* img, struct Bitmap* bmp, int x, int y, BitmapCol col) {
cc_uint8* src; cc_uint8* src;
BitmapCol* dst; BitmapCol* dst;
cc_uint8 I, invI; /* intensity */ cc_uint8 I, invI; /* intensity */
@ -1085,7 +1087,7 @@ static void DrawGrayscaleGlyph(FT_Bitmap* img, Bitmap* bmp, int x, int y, Bitmap
} }
} }
static void DrawBlackWhiteGlyph(FT_Bitmap* img, Bitmap* bmp, int x, int y, BitmapCol col) { static void DrawBlackWhiteGlyph(FT_Bitmap* img, struct Bitmap* bmp, int x, int y, BitmapCol col) {
cc_uint8* src; cc_uint8* src;
BitmapCol* dst; BitmapCol* dst;
cc_uint8 intensity; cc_uint8 intensity;
@ -1109,7 +1111,7 @@ static void DrawBlackWhiteGlyph(FT_Bitmap* img, Bitmap* bmp, int x, int y, Bitma
} }
static FT_Vector shadow_delta = { 83, -83 }; static FT_Vector shadow_delta = { 83, -83 };
static void Font_SysTextDraw(struct DrawTextArgs* args, Bitmap* bmp, int x, int y, cc_bool shadow) { static void Font_SysTextDraw(struct DrawTextArgs* args, struct Bitmap* bmp, int x, int y, cc_bool shadow) {
struct SysFont* font = (struct SysFont*)args->font->handle; struct SysFont* font = (struct SysFont*)args->font->handle;
FT_BitmapGlyph* glyphs = font->glyphs; FT_BitmapGlyph* glyphs = font->glyphs;

View File

@ -31,39 +31,41 @@ extern String Drawer2D_FontName;
/* Clamps the given rectangle to line inside the bitmap. */ /* Clamps the given rectangle to line inside the bitmap. */
/* Returns false if rectangle is completely outside bitmap's rectangle. */ /* Returns false if rectangle is completely outside bitmap's rectangle. */
cc_bool Drawer2D_Clamp(Bitmap* bmp, int* x, int* y, int* width, int* height); cc_bool Drawer2D_Clamp(struct Bitmap* bmp, int* x, int* y, int* width, int* height);
/* Fills the given area with a simple noisy pattern. */ /* Fills the given area with a simple noisy pattern. */
/* Variation determines how 'visible/obvious' the noise is. */ /* Variation determines how 'visible/obvious' the noise is. */
CC_API void Gradient_Noise(Bitmap* bmp, BitmapCol col, int variation, CC_API void Gradient_Noise(struct Bitmap* bmp, BitmapCol col, int variation,
int x, int y, int width, int height); int x, int y, int width, int height);
/* Fills the given area with a vertical gradient, linerarly interpolating from a to b. */ /* Fills the given area with a vertical gradient, linerarly interpolating from a to b. */
/* First drawn row is filled with 'a', while last drawn is filled with 'b'. */ /* First drawn row is filled with 'a', while last drawn is filled with 'b'. */
CC_API void Gradient_Vertical(Bitmap* bmp, BitmapCol a, BitmapCol b, CC_API void Gradient_Vertical(struct Bitmap* bmp, BitmapCol a, BitmapCol b,
int x, int y, int width, int height); int x, int y, int width, int height);
/* Blends the given area with the given colour. */ /* Blends the given area with the given colour. */
/* Note that this only blends RGB, A is not blended. */ /* Note that this only blends RGB, A is not blended. */
CC_API void Gradient_Blend(Bitmap* bmp, BitmapCol col, int blend, CC_API void Gradient_Blend(struct Bitmap* bmp, BitmapCol col, int blend,
int x, int y, int width, int height); int x, int y, int width, int height);
/* Tints the given area, linearly interpolating from a to b. */ /* Tints the given area, linearly interpolating from a to b. */
/* Note that this only tints RGB, A is not tinted. */ /* Note that this only tints RGB, A is not tinted. */
CC_API void Gradient_Tint(Bitmap* bmp, cc_uint8 tintA, cc_uint8 tintB, CC_API void Gradient_Tint(struct Bitmap* bmp, cc_uint8 tintA, cc_uint8 tintB,
int x, int y, int width, int height); int x, int y, int width, int height);
/* Fills the given area using pixels from the source bitmap. */ /* Fills the given area using pixels from the source bitmap. */
CC_API void Drawer2D_BmpCopy(Bitmap* dst, int x, int y, Bitmap* src); CC_API void Drawer2D_BmpCopy(struct Bitmap* dst, int x, int y, struct Bitmap* src);
/* Fills the area with the given colour. */ /* Fills the area with the given colour. */
CC_API void Drawer2D_Clear(Bitmap* bmp, BitmapCol col, int x, int y, int width, int height); CC_API void Drawer2D_Clear(struct Bitmap* bmp, BitmapCol col,
int x, int y, int width, int height);
/* Draws text using the given font at the given coordinates. */ /* Draws text using the given font at the given coordinates. */
CC_API void Drawer2D_DrawText(Bitmap* bmp, struct DrawTextArgs* args, int x, int y); CC_API void Drawer2D_DrawText(struct Bitmap* bmp, struct DrawTextArgs* args, int x, int y);
/* Returns how wide the given text would be when drawn. */ /* Returns how wide the given text would be when drawn. */
CC_API int Drawer2D_TextWidth(struct DrawTextArgs* args); CC_API int Drawer2D_TextWidth(struct DrawTextArgs* args);
/* Returns how tall the given text would be when drawn. */ /* Returns how tall the given text would be when drawn. */
/* NOTE: Height returned only depends on the font. (see Drawer2D_FontHeight). */ /* NOTE: Height returned only depends on the font. (see Drawer2D_FontHeight). */
CC_API int Drawer2D_TextHeight(struct DrawTextArgs* args); CC_API int Drawer2D_TextHeight(struct DrawTextArgs* args);
/* Similar to Drawer2D_DrawText, but trims the text with trailing ".." if wider than maxWidth. */ /* Similar to Drawer2D_DrawText, but trims the text with trailing ".." if wider than maxWidth. */
void Drawer2D_DrawClippedText(Bitmap* bmp, struct DrawTextArgs* args, int x, int y, int maxWidth); void Drawer2D_DrawClippedText(struct Bitmap* bmp, struct DrawTextArgs* args,
int x, int y, int maxWidth);
/* Returns the line height for drawing any character in the font. */ /* Returns the line height for drawing any character in the font. */
int Drawer2D_FontHeight(const struct FontDesc* font, cc_bool useShadow); int Drawer2D_FontHeight(const struct FontDesc* font, cc_bool useShadow);
@ -73,7 +75,7 @@ CC_API void Drawer2D_MakeTextTexture(struct Texture* tex, struct DrawTextArgs* a
/* Creates a texture consisting of the pixels from the given bitmap. */ /* Creates a texture consisting of the pixels from the given bitmap. */
/* NOTE: bmp must always have power of two dimensions. */ /* NOTE: bmp must always have power of two dimensions. */
/* width/height specifies what region of the texture actually should be drawn. */ /* width/height specifies what region of the texture actually should be drawn. */
CC_API void Drawer2D_MakeTexture(struct Texture* tex, Bitmap* bmp, int width, int height); CC_API void Drawer2D_MakeTexture(struct Texture* tex, struct Bitmap* bmp, int width, int height);
/* Returns whether the given colour code is used/valid. */ /* Returns whether the given colour code is used/valid. */
/* NOTE: This can change if the server defines custom colour codes. */ /* NOTE: This can change if the server defines custom colour codes. */
@ -89,7 +91,7 @@ void Drawer2D_ReducePadding_Tex(struct Texture* tex, int point, int scale);
void Drawer2D_ReducePadding_Height(int* height, int point, int scale); void Drawer2D_ReducePadding_Height(int* height, int point, int scale);
/* Sets the bitmap used for drawing bitmapped fonts. (i.e. default.png) */ /* Sets the bitmap used for drawing bitmapped fonts. (i.e. default.png) */
/* The bitmap must be square and consist of a 16x16 tile layout. */ /* The bitmap must be square and consist of a 16x16 tile layout. */
cc_bool Drawer2D_SetFontBitmap(Bitmap* bmp); cc_bool Drawer2D_SetFontBitmap(struct Bitmap* bmp);
/* Gets the list of all supported system font names on this platform. */ /* Gets the list of all supported system font names on this platform. */
CC_API void Font_GetNames(struct StringsBuffer* buffer); CC_API void Font_GetNames(struct StringsBuffer* buffer);

View File

@ -234,10 +234,10 @@ static void MakeNameTexture(struct Entity* e) {
struct DrawTextArgs args; struct DrawTextArgs args;
struct FontDesc font; struct FontDesc font;
struct Bitmap bmp;
cc_bool bitmapped; cc_bool bitmapped;
int width, height; int width, height;
String name; String name;
Bitmap bmp;
/* Names are always drawn not using the system font */ /* Names are always drawn not using the system font */
bitmapped = Drawer2D_BitmappedText; bitmapped = Drawer2D_BitmappedText;
@ -387,7 +387,7 @@ static void Entity_SetSkinAll(struct Entity* source, cc_bool reset) {
/* Clears hat area from a skin bitmap if it's completely white or black, /* Clears hat area from a skin bitmap if it's completely white or black,
so skins edited with Microsoft Paint or similiar don't have a solid hat */ so skins edited with Microsoft Paint or similiar don't have a solid hat */
static void Entity_ClearHat(Bitmap* bmp, cc_uint8 skinType) { static void Entity_ClearHat(struct Bitmap* bmp, cc_uint8 skinType) {
int sizeX = (bmp->width / 64) * 32; int sizeX = (bmp->width / 64) * 32;
int yScale = skinType == SKIN_64x32 ? 32 : 64; int yScale = skinType == SKIN_64x32 ? 32 : 64;
int sizeY = (bmp->height / yScale) * 16; int sizeY = (bmp->height / yScale) * 16;
@ -412,10 +412,10 @@ static void Entity_ClearHat(Bitmap* bmp, cc_uint8 skinType) {
} }
/* Ensures skin is a power of two size, resizing if needed. */ /* Ensures skin is a power of two size, resizing if needed. */
static cc_result Entity_EnsurePow2(struct Entity* e, Bitmap* bmp) { static cc_result Entity_EnsurePow2(struct Entity* e, struct Bitmap* bmp) {
struct Bitmap scaled;
cc_uint32 stride; cc_uint32 stride;
int width, height; int width, height;
Bitmap scaled;
int y; int y;
width = Math_NextPowOf2(bmp->width); width = Math_NextPowOf2(bmp->width);
@ -446,7 +446,7 @@ static void Entity_CheckSkin(struct Entity* e) {
struct HttpRequest item; struct HttpRequest item;
struct Stream mem; struct Stream mem;
Bitmap bmp; struct Bitmap bmp;
cc_result res; cc_result res;
/* Don't check skin if don't have to */ /* Don't check skin if don't have to */

View File

@ -566,7 +566,7 @@ static cc_bool ShadowComponent_GetBlocks(struct Entity* e, int x, int y, int z,
static void ShadowComponent_MakeTex(void) { static void ShadowComponent_MakeTex(void) {
BitmapCol pixels[sh_size * sh_size]; BitmapCol pixels[sh_size * sh_size];
BitmapCol col = BitmapCol_Make(0, 0, 0, 200); BitmapCol col = BitmapCol_Make(0, 0, 0, 200);
Bitmap bmp; struct Bitmap bmp;
cc_uint32 x, y; cc_uint32 x, y;
Bitmap_Init(bmp, sh_size, sh_size, pixels); Bitmap_Init(bmp, sh_size, sh_size, pixels);

View File

@ -220,7 +220,7 @@ cc_bool Game_CanPick(BlockID block) {
} }
cc_bool Game_UpdateTexture(GfxResourceID* texId, struct Stream* src, const String* file, cc_uint8* skinType) { cc_bool Game_UpdateTexture(GfxResourceID* texId, struct Stream* src, const String* file, cc_uint8* skinType) {
Bitmap bmp; struct Bitmap bmp;
cc_bool success; cc_bool success;
cc_result res; cc_result res;
@ -238,7 +238,7 @@ cc_bool Game_UpdateTexture(GfxResourceID* texId, struct Stream* src, const Strin
return success; return success;
} }
cc_bool Game_ValidateBitmap(const String* file, Bitmap* bmp) { cc_bool Game_ValidateBitmap(const String* file, struct Bitmap* bmp) {
int maxWidth = Gfx.MaxTexWidth, maxHeight = Gfx.MaxTexHeight; int maxWidth = Gfx.MaxTexWidth, maxHeight = Gfx.MaxTexHeight;
if (!bmp->scan0) { if (!bmp->scan0) {
Chat_Add1("&cError loading %s from the texture pack.", file); Chat_Add1("&cError loading %s from the texture pack.", file);

View File

@ -72,7 +72,7 @@ cc_bool Game_CanPick(BlockID block);
cc_bool Game_UpdateTexture(GfxResourceID* texId, struct Stream* src, const String* file, cc_uint8* skinType); cc_bool Game_UpdateTexture(GfxResourceID* texId, struct Stream* src, const String* file, cc_uint8* skinType);
/* Checks that the given bitmap can be loaded into a native gfx texture. */ /* Checks that the given bitmap can be loaded into a native gfx texture. */
/* (must be power of two size and be <= Gfx_MaxTexWidth/Gfx_MaxHeight) */ /* (must be power of two size and be <= Gfx_MaxTexWidth/Gfx_MaxHeight) */
cc_bool Game_ValidateBitmap(const String* file, Bitmap* bmp); cc_bool Game_ValidateBitmap(const String* file, struct Bitmap* bmp);
/* Updates Game_Width and Game_Height. */ /* Updates Game_Width and Game_Height. */
void Game_UpdateDimensions(void); void Game_UpdateDimensions(void);
/* Sets the strategy/method used to limit frames per second. */ /* Sets the strategy/method used to limit frames per second. */

View File

@ -201,11 +201,11 @@ void Gfx_RestoreAlphaState(cc_uint8 draw) {
} }
void Gfx_UpdateTexturePart(GfxResourceID texId, int x, int y, Bitmap* part, cc_bool mipmaps) { void Gfx_UpdateTexturePart(GfxResourceID texId, int x, int y, struct Bitmap* part, cc_bool mipmaps) {
Gfx_UpdateTexture(texId, x, y, part, part->width, mipmaps); Gfx_UpdateTexture(texId, x, y, part, part->width, mipmaps);
} }
static void CopyTextureData(void* dst, int dstStride, const Bitmap* src, int srcStride) { static void CopyTextureData(void* dst, int dstStride, const struct Bitmap* src, int srcStride) {
/* We need to copy scanline by scanline, as generally srcStride != dstStride */ /* We need to copy scanline by scanline, as generally srcStride != dstStride */
cc_uint8* src_ = (cc_uint8*)src->scan0; cc_uint8* src_ = (cc_uint8*)src->scan0;
cc_uint8* dst_ = (cc_uint8*)dst; cc_uint8* dst_ = (cc_uint8*)dst;
@ -482,7 +482,7 @@ static void Gfx_RestoreState(void) {
/*########################################################################################################################* /*########################################################################################################################*
*---------------------------------------------------------Textures--------------------------------------------------------* *---------------------------------------------------------Textures--------------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
static void D3D9_SetTextureData(IDirect3DTexture9* texture, Bitmap* bmp, int lvl) { static void D3D9_SetTextureData(IDirect3DTexture9* texture, struct Bitmap* bmp, int lvl) {
D3DLOCKED_RECT rect; D3DLOCKED_RECT rect;
cc_result res = IDirect3DTexture9_LockRect(texture, lvl, &rect, NULL, 0); cc_result res = IDirect3DTexture9_LockRect(texture, lvl, &rect, NULL, 0);
if (res) Logger_Abort2(res, "D3D9_LockTextureData"); if (res) Logger_Abort2(res, "D3D9_LockTextureData");
@ -494,7 +494,7 @@ static void D3D9_SetTextureData(IDirect3DTexture9* texture, Bitmap* bmp, int lvl
if (res) Logger_Abort2(res, "D3D9_UnlockTextureData"); if (res) Logger_Abort2(res, "D3D9_UnlockTextureData");
} }
static void D3D9_SetTexturePartData(IDirect3DTexture9* texture, int x, int y, const Bitmap* bmp, int rowWidth, int lvl) { static void D3D9_SetTexturePartData(IDirect3DTexture9* texture, int x, int y, const struct Bitmap* bmp, int rowWidth, int lvl) {
D3DLOCKED_RECT rect; D3DLOCKED_RECT rect;
cc_result res; cc_result res;
RECT part; RECT part;
@ -510,10 +510,10 @@ static void D3D9_SetTexturePartData(IDirect3DTexture9* texture, int x, int y, co
if (res) Logger_Abort2(res, "D3D9_UnlockTexturePartData"); if (res) Logger_Abort2(res, "D3D9_UnlockTexturePartData");
} }
static void D3D9_DoMipmaps(IDirect3DTexture9* texture, int x, int y, Bitmap* bmp, int rowWidth, cc_bool partial) { static void D3D9_DoMipmaps(IDirect3DTexture9* texture, int x, int y, struct Bitmap* bmp, int rowWidth, cc_bool partial) {
BitmapCol* prev = bmp->scan0; BitmapCol* prev = bmp->scan0;
BitmapCol* cur; BitmapCol* cur;
Bitmap mipmap; struct Bitmap mipmap;
int lvls = CalcMipmapsLevels(bmp->width, bmp->height); int lvls = CalcMipmapsLevels(bmp->width, bmp->height);
int lvl, width = bmp->width, height = bmp->height; int lvl, width = bmp->width, height = bmp->height;
@ -540,7 +540,7 @@ static void D3D9_DoMipmaps(IDirect3DTexture9* texture, int x, int y, Bitmap* bmp
if (prev != bmp->scan0) Mem_Free(prev); if (prev != bmp->scan0) Mem_Free(prev);
} }
GfxResourceID Gfx_CreateTexture(Bitmap* bmp, cc_bool managedPool, cc_bool mipmaps) { GfxResourceID Gfx_CreateTexture(struct Bitmap* bmp, cc_bool managedPool, cc_bool mipmaps) {
IDirect3DTexture9* tex; IDirect3DTexture9* tex;
cc_result res; cc_result res;
int mipmapsLevels = CalcMipmapsLevels(bmp->width, bmp->height); int mipmapsLevels = CalcMipmapsLevels(bmp->width, bmp->height);
@ -578,7 +578,7 @@ GfxResourceID Gfx_CreateTexture(Bitmap* bmp, cc_bool managedPool, cc_bool mipmap
return tex; return tex;
} }
void Gfx_UpdateTexture(GfxResourceID texId, int x, int y, Bitmap* part, int rowWidth, cc_bool mipmaps) { void Gfx_UpdateTexture(GfxResourceID texId, int x, int y, struct Bitmap* part, int rowWidth, cc_bool mipmaps) {
IDirect3DTexture9* texture = (IDirect3DTexture9*)texId; IDirect3DTexture9* texture = (IDirect3DTexture9*)texId;
D3D9_SetTexturePartData(texture, x, y, part, rowWidth, 0); D3D9_SetTexturePartData(texture, x, y, part, rowWidth, 0);
if (mipmaps) D3D9_DoMipmaps(texture, x, y, part, rowWidth, true); if (mipmaps) D3D9_DoMipmaps(texture, x, y, part, rowWidth, true);
@ -905,7 +905,7 @@ cc_result Gfx_TakeScreenshot(struct Stream* output) {
IDirect3DSurface9* temp = NULL; IDirect3DSurface9* temp = NULL;
D3DSURFACE_DESC desc; D3DSURFACE_DESC desc;
D3DLOCKED_RECT rect; D3DLOCKED_RECT rect;
Bitmap bmp; struct Bitmap bmp;
cc_result res; cc_result res;
res = IDirect3DDevice9_GetBackBuffer(device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer); res = IDirect3DDevice9_GetBackBuffer(device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
@ -1129,7 +1129,7 @@ static void* FastAllocTempMem(int size) {
/*########################################################################################################################* /*########################################################################################################################*
*---------------------------------------------------------Textures--------------------------------------------------------* *---------------------------------------------------------Textures--------------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
static void Gfx_DoMipmaps(int x, int y, Bitmap* bmp, int rowWidth, cc_bool partial) { static void Gfx_DoMipmaps(int x, int y, struct Bitmap* bmp, int rowWidth, cc_bool partial) {
BitmapCol* prev = bmp->scan0; BitmapCol* prev = bmp->scan0;
BitmapCol* cur; BitmapCol* cur;
@ -1157,7 +1157,7 @@ static void Gfx_DoMipmaps(int x, int y, Bitmap* bmp, int rowWidth, cc_bool parti
if (prev != bmp->scan0) Mem_Free(prev); if (prev != bmp->scan0) Mem_Free(prev);
} }
GfxResourceID Gfx_CreateTexture(Bitmap* bmp, cc_bool managedPool, cc_bool mipmaps) { GfxResourceID Gfx_CreateTexture(struct Bitmap* bmp, cc_bool managedPool, cc_bool mipmaps) {
GLuint texId; GLuint texId;
glGenTextures(1, &texId); glGenTextures(1, &texId);
glBindTexture(GL_TEXTURE_2D, texId); glBindTexture(GL_TEXTURE_2D, texId);
@ -1185,7 +1185,7 @@ GfxResourceID Gfx_CreateTexture(Bitmap* bmp, cc_bool managedPool, cc_bool mipmap
} }
#define UPDATE_FAST_SIZE (64 * 64) #define UPDATE_FAST_SIZE (64 * 64)
static CC_NOINLINE void UpdateTextureSlow(int x, int y, Bitmap* part, int rowWidth) { static CC_NOINLINE void UpdateTextureSlow(int x, int y, struct Bitmap* part, int rowWidth) {
BitmapCol buffer[UPDATE_FAST_SIZE]; BitmapCol buffer[UPDATE_FAST_SIZE];
void* ptr = (void*)buffer; void* ptr = (void*)buffer;
int count = part->width * part->height; int count = part->width * part->height;
@ -1200,7 +1200,7 @@ static CC_NOINLINE void UpdateTextureSlow(int x, int y, Bitmap* part, int rowWid
if (count > UPDATE_FAST_SIZE) Mem_Free(ptr); if (count > UPDATE_FAST_SIZE) Mem_Free(ptr);
} }
void Gfx_UpdateTexture(GfxResourceID texId, int x, int y, Bitmap* part, int rowWidth, cc_bool mipmaps) { void Gfx_UpdateTexture(GfxResourceID texId, int x, int y, struct Bitmap* part, int rowWidth, cc_bool mipmaps) {
glBindTexture(GL_TEXTURE_2D, (GLuint)texId); glBindTexture(GL_TEXTURE_2D, (GLuint)texId);
/* TODO: Use GL_UNPACK_ROW_LENGTH for Desktop OpenGL */ /* TODO: Use GL_UNPACK_ROW_LENGTH for Desktop OpenGL */
@ -1423,9 +1423,10 @@ void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, int vCount) {
/*########################################################################################################################* /*########################################################################################################################*
*-----------------------------------------------------------Misc----------------------------------------------------------* *-----------------------------------------------------------Misc----------------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
static int GL_SelectRow(Bitmap* bmp, int y) { return (bmp->height - 1) - y; } /* OpenGL stores bitmap in bottom-up order, so flip order when saving */
static int SelectRow(struct Bitmap* bmp, int y) { return (bmp->height - 1) - y; }
cc_result Gfx_TakeScreenshot(struct Stream* output) { cc_result Gfx_TakeScreenshot(struct Stream* output) {
Bitmap bmp; struct Bitmap bmp;
cc_result res; cc_result res;
GLint vp[4]; GLint vp[4];
@ -1437,7 +1438,7 @@ cc_result Gfx_TakeScreenshot(struct Stream* output) {
if (!bmp.scan0) return ERR_OUT_OF_MEMORY; if (!bmp.scan0) return ERR_OUT_OF_MEMORY;
glReadPixels(0, 0, bmp.width, bmp.height, PIXEL_FORMAT, TRANSFER_FORMAT, bmp.scan0); glReadPixels(0, 0, bmp.width, bmp.height, PIXEL_FORMAT, TRANSFER_FORMAT, bmp.scan0);
res = Png_Encode(&bmp, output, GL_SelectRow, false); res = Png_Encode(&bmp, output, SelectRow, false);
Mem_Free(bmp.scan0); Mem_Free(bmp.scan0);
return res; return res;
} }

View File

@ -59,12 +59,12 @@ extern GfxResourceID Gfx_quadVb, Gfx_texVb;
/* Creates a new texture. (and also generates mipmaps if mipmaps) */ /* Creates a new texture. (and also generates mipmaps if mipmaps) */
/* NOTE: Only set mipmaps to true if Gfx_Mipmaps is also true, because whether textures /* NOTE: Only set mipmaps to true if Gfx_Mipmaps is also true, because whether textures
use mipmapping may be either a per-texture or global state depending on the backend. */ use mipmapping may be either a per-texture or global state depending on the backend. */
CC_API GfxResourceID Gfx_CreateTexture(Bitmap* bmp, cc_bool managedPool, cc_bool mipmaps); CC_API GfxResourceID Gfx_CreateTexture(struct Bitmap* bmp, cc_bool managedPool, cc_bool mipmaps);
/* Updates a region of the given texture. (and mipmapped regions if mipmaps) */ /* Updates a region of the given texture. (and mipmapped regions if mipmaps) */
CC_API void Gfx_UpdateTexturePart(GfxResourceID texId, int x, int y, Bitmap* part, cc_bool mipmaps); /* OBSOLETE */ CC_API void Gfx_UpdateTexturePart(GfxResourceID texId, int x, int y, struct Bitmap* part, cc_bool mipmaps); /* OBSOLETE */
/* Updates a region of the given texture. (and mipmapped regions if mipmaps) */ /* Updates a region of the given texture. (and mipmapped regions if mipmaps) */
/* NOTE: rowWidth is in pixels (so for normal bitmaps, rowWidth equals width) */ /* NOTE: rowWidth is in pixels (so for normal bitmaps, rowWidth equals width) */
CC_API void Gfx_UpdateTexture(GfxResourceID texId, int x, int y, Bitmap* part, int rowWidth, cc_bool mipmaps); CC_API void Gfx_UpdateTexture(GfxResourceID texId, int x, int y, struct Bitmap* part, int rowWidth, cc_bool mipmaps);
/* Sets the currently active texture. */ /* Sets the currently active texture. */
CC_API void Gfx_BindTexture(GfxResourceID texId); CC_API void Gfx_BindTexture(GfxResourceID texId);
/* Deletes the given texture, then sets it to 0. */ /* Deletes the given texture, then sets it to 0. */

View File

@ -294,7 +294,7 @@ void Gui_Layout(void) {
void TextAtlas_Make(struct TextAtlas* atlas, const String* chars, struct FontDesc* font, const String* prefix) { void TextAtlas_Make(struct TextAtlas* atlas, const String* chars, struct FontDesc* font, const String* prefix) {
struct DrawTextArgs args; struct DrawTextArgs args;
int width, height; int width, height;
Bitmap bmp; struct Bitmap bmp;
int i, charWidth; int i, charWidth;
Gfx_DeleteTexture(&atlas->tex.ID); Gfx_DeleteTexture(&atlas->tex.ID);

View File

@ -541,14 +541,14 @@ struct FetchFlagsData FetchFlagsTask;
static int flagsCount, flagsCapacity; static int flagsCount, flagsCapacity;
struct Flag { struct Flag {
Bitmap bmp; struct Bitmap bmp;
char country[2]; char country[2];
}; };
static struct Flag* flags; static struct Flag* flags;
/* Scales up flag bitmap if necessary */ /* Scales up flag bitmap if necessary */
static void FetchFlagsTask_Scale(Bitmap* bmp) { static void FetchFlagsTask_Scale(struct Bitmap* bmp) {
Bitmap scaled; struct Bitmap scaled;
int width = Display_ScaleX(bmp->width); int width = Display_ScaleX(bmp->width);
int height = Display_ScaleY(bmp->height); int height = Display_ScaleY(bmp->height);
/* at default DPI don't need to rescale it */ /* at default DPI don't need to rescale it */
@ -624,7 +624,7 @@ void FetchFlagsTask_Add(const struct ServerInfo* server) {
FetchFlagsTask_DownloadNext(); FetchFlagsTask_DownloadNext();
} }
Bitmap* Flags_Get(const struct ServerInfo* server) { struct Bitmap* Flags_Get(const struct ServerInfo* server) {
int i; int i;
for (i = 0; i < FetchFlagsTask.count; i++) { for (i = 0; i < FetchFlagsTask.count; i++) {
if (flags[i].country[0] != server->country[0]) continue; if (flags[i].country[0] != server->country[0]) continue;

View File

@ -114,7 +114,7 @@ extern struct FetchFlagsData {
/* Asynchronously downloads the flag associated with the given server's country. */ /* Asynchronously downloads the flag associated with the given server's country. */
void FetchFlagsTask_Add(const struct ServerInfo* server); void FetchFlagsTask_Add(const struct ServerInfo* server);
/* Gets the bitmap for the flag associated with the given server's country. */ /* Gets the bitmap for the flag associated with the given server's country. */
Bitmap* Flags_Get(const struct ServerInfo* server); struct Bitmap* Flags_Get(const struct ServerInfo* server);
/* Frees all flag bitmaps. */ /* Frees all flag bitmaps. */
void Flags_Free(void); void Flags_Free(void);
#endif #endif

View File

@ -706,7 +706,7 @@ void LSlider_Init(struct LScreen* s, struct LSlider* w, int width, int height, B
*------------------------------------------------------TableWidget--------------------------------------------------------* *------------------------------------------------------TableWidget--------------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
static void FlagColumn_Draw(struct ServerInfo* row, struct DrawTextArgs* args, int x, int y) { static void FlagColumn_Draw(struct ServerInfo* row, struct DrawTextArgs* args, int x, int y) {
Bitmap* bmp = Flags_Get(row); struct Bitmap* bmp = Flags_Get(row);
if (!bmp) return; if (!bmp) return;
Drawer2D_BmpCopy(&Launcher_Framebuffer, x + flagXOffset, y + flagYOffset, bmp); Drawer2D_BmpCopy(&Launcher_Framebuffer, x + flagXOffset, y + flagYOffset, bmp);
} }

View File

@ -20,7 +20,7 @@
#ifndef CC_BUILD_WEB #ifndef CC_BUILD_WEB
static struct LScreen* activeScreen; static struct LScreen* activeScreen;
Rect2D Launcher_Dirty; Rect2D Launcher_Dirty;
Bitmap Launcher_Framebuffer; struct Bitmap Launcher_Framebuffer;
cc_bool Launcher_ClassicBackground; cc_bool Launcher_ClassicBackground;
struct FontDesc Launcher_TitleFont, Launcher_TextFont, Launcher_HintFont; struct FontDesc Launcher_TitleFont, Launcher_TextFont, Launcher_HintFont;
@ -33,7 +33,7 @@ static char hashBuffer[STRING_SIZE];
String Launcher_AutoHash = String_FromArray(hashBuffer); String Launcher_AutoHash = String_FromArray(hashBuffer);
static cc_bool useBitmappedFont; static cc_bool useBitmappedFont;
static Bitmap dirtBmp, stoneBmp, fontBmp; static struct Bitmap dirtBmp, stoneBmp, fontBmp;
#define TILESIZE 48 #define TILESIZE 48
void Launcher_SetScreen(struct LScreen* screen) { void Launcher_SetScreen(struct LScreen* screen) {
@ -428,7 +428,7 @@ static cc_bool Launcher_SelectZipEntry(const String* path) {
String_CaselessEqualsConst(path, "terrain.png"); String_CaselessEqualsConst(path, "terrain.png");
} }
static void LoadTextures(Bitmap* bmp) { static void LoadTextures(struct Bitmap* bmp) {
int tileSize = bmp->width / 16; int tileSize = bmp->width / 16;
Bitmap_Allocate(&dirtBmp, TILESIZE, TILESIZE); Bitmap_Allocate(&dirtBmp, TILESIZE, TILESIZE);
Bitmap_Allocate(&stoneBmp, TILESIZE, TILESIZE); Bitmap_Allocate(&stoneBmp, TILESIZE, TILESIZE);
@ -442,7 +442,7 @@ static void LoadTextures(Bitmap* bmp) {
} }
static cc_result Launcher_ProcessZipEntry(const String* path, struct Stream* data, struct ZipState* s) { static cc_result Launcher_ProcessZipEntry(const String* path, struct Stream* data, struct ZipState* s) {
Bitmap bmp; struct Bitmap bmp;
cc_result res; cc_result res;
if (String_CaselessEqualsConst(path, "default.png")) { if (String_CaselessEqualsConst(path, "default.png")) {
@ -518,8 +518,8 @@ void Launcher_UpdateLogoFont(void) {
} }
/* Fills the given area using pixels from the source bitmap, by repeatedly tiling the bitmap. */ /* Fills the given area using pixels from the source bitmap, by repeatedly tiling the bitmap. */
CC_NOINLINE static void ClearTile(int x, int y, int width, int height, Bitmap* src) { CC_NOINLINE static void ClearTile(int x, int y, int width, int height, struct Bitmap* src) {
Bitmap* dst = &Launcher_Framebuffer; struct Bitmap* dst = &Launcher_Framebuffer;
BitmapCol* dstRow; BitmapCol* dstRow;
BitmapCol* srcRow; BitmapCol* srcRow;
int xx, yy; int xx, yy;

View File

@ -12,7 +12,7 @@ struct FontDesc;
/* If width is 0, means no area needs to be redrawn. */ /* If width is 0, means no area needs to be redrawn. */
extern Rect2D Launcher_Dirty; extern Rect2D Launcher_Dirty;
/* Contains the pixels that are drawn to the window. */ /* Contains the pixels that are drawn to the window. */
extern Bitmap Launcher_Framebuffer; extern struct Bitmap Launcher_Framebuffer;
/* Whether to use stone tile background like minecraft.net. */ /* Whether to use stone tile background like minecraft.net. */
extern cc_bool Launcher_ClassicBackground; extern cc_bool Launcher_ClassicBackground;
/* Default font for buttons and labels. */ /* Default font for buttons and labels. */

View File

@ -526,7 +526,6 @@ void CustomModel_BuildPart(struct CustomModel* cm, struct CustomModelPartDef* pa
part->rotationOrigin.X, part->rotationOrigin.Y, part->rotationOrigin.Z); part->rotationOrigin.X, part->rotationOrigin.Y, part->rotationOrigin.Z);
} }
static void CustomModel_MakeParts(void) { }
static struct ModelVertex oldVertices[MODEL_BOX_VERTICES]; static struct ModelVertex oldVertices[MODEL_BOX_VERTICES];
static float CustomModel_GetAnimationValue( static float CustomModel_GetAnimationValue(
struct CustomModelAnim* anim, struct CustomModelAnim* anim,
@ -762,7 +761,7 @@ void CustomModel_Register(struct CustomModel* cm) {
cm->model.name = cm->name; cm->model.name = cm->name;
cm->model.defaultTex = &customDefaultTex; cm->model.defaultTex = &customDefaultTex;
cm->model.MakeParts = CustomModel_MakeParts; cm->model.MakeParts = Model_NoParts;
cm->model.Draw = CustomModel_Draw; cm->model.Draw = CustomModel_Draw;
cm->model.GetNameY = CustomModel_GetNameY; cm->model.GetNameY = CustomModel_GetNameY;
cm->model.GetEyeY = CustomModel_GetEyeY; cm->model.GetEyeY = CustomModel_GetEyeY;

View File

@ -340,7 +340,7 @@ static cc_result ZipPatcher_WriteZipEntry(struct Stream* src, struct ResourceTex
return 0; return 0;
} }
static cc_result ZipPatcher_WritePng(struct Stream* s, struct ResourceTexture* tex, Bitmap* src) { static cc_result ZipPatcher_WritePng(struct Stream* s, struct ResourceTexture* tex, struct Bitmap* src) {
cc_result res; cc_result res;
if ((res = ZipPatcher_LocalFile(s, tex))) return res; if ((res = ZipPatcher_LocalFile(s, tex))) return res;
@ -370,7 +370,7 @@ static cc_result ZipPatcher_WritePng(struct Stream* s, struct ResourceTexture* t
"\r\n" \ "\r\n" \
"# fire\r\n" \ "# fire\r\n" \
"6 2 0 0 16 32 0" "6 2 0 0 16 32 0"
static Bitmap terrainBmp; static struct Bitmap terrainBmp;
static cc_bool ClassicPatcher_SelectEntry(const String* path) { static cc_bool ClassicPatcher_SelectEntry(const String* path) {
String name = *path; String name = *path;
@ -434,7 +434,7 @@ CC_NOINLINE static const struct TilePatch* ModernPatcher_GetTile(const String* p
} }
static cc_result ModernPatcher_PatchTile(struct Stream* data, const struct TilePatch* tile) { static cc_result ModernPatcher_PatchTile(struct Stream* data, const struct TilePatch* tile) {
Bitmap bmp; struct Bitmap bmp;
cc_result res; cc_result res;
if ((res = Png_Decode(&bmp, data))) return res; if ((res = Png_Decode(&bmp, data))) return res;
@ -462,7 +462,7 @@ static cc_result ModernPatcher_MakeAnimations(struct Stream* s, struct Stream* d
static const String animsPng = String_FromConst("animations.png"); static const String animsPng = String_FromConst("animations.png");
struct ResourceTexture* entry; struct ResourceTexture* entry;
BitmapCol pixels[512 * 16]; BitmapCol pixels[512 * 16];
Bitmap anim, bmp; struct Bitmap anim, bmp;
cc_result res; cc_result res;
int i; int i;
@ -532,14 +532,14 @@ static cc_result TexPatcher_NewFiles(struct Stream* s) {
return res; return res;
} }
static void TexPatcher_PatchTile(Bitmap* src, int srcX, int srcY, int dstX, int dstY) { static void TexPatcher_PatchTile(struct Bitmap* src, int srcX, int srcY, int dstX, int dstY) {
Bitmap_UNSAFE_CopyBlock(srcX, srcY, dstX * 16, dstY * 16, src, &terrainBmp, 16); Bitmap_UNSAFE_CopyBlock(srcX, srcY, dstX * 16, dstY * 16, src, &terrainBmp, 16);
} }
static cc_result TexPatcher_Terrain(struct Stream* s) { static cc_result TexPatcher_Terrain(struct Stream* s) {
static const String terrainPng = String_FromConst("terrain.png"); static const String terrainPng = String_FromConst("terrain.png");
struct ResourceTexture* entry; struct ResourceTexture* entry;
Bitmap bmp; struct Bitmap bmp;
struct Stream src; struct Stream src;
cc_result res; cc_result res;

View File

@ -37,7 +37,7 @@ static void Atlas_Convert2DTo1D(void) {
int tileSize = Atlas2D.TileSize; int tileSize = Atlas2D.TileSize;
int tilesPerAtlas = Atlas1D.TilesPerAtlas; int tilesPerAtlas = Atlas1D.TilesPerAtlas;
int atlasesCount = Atlas1D.Count; int atlasesCount = Atlas1D.Count;
Bitmap atlas1D; struct Bitmap atlas1D;
int atlasX, atlasY; int atlasX, atlasY;
int tile = 0, i, y; int tile = 0, i, y;
@ -73,7 +73,7 @@ static void Atlas_Update1D(void) {
} }
/* Loads the given atlas and converts it into an array of 1D atlases. */ /* Loads the given atlas and converts it into an array of 1D atlases. */
static void Atlas_Update(Bitmap* bmp) { static void Atlas_Update(struct Bitmap* bmp) {
Atlas2D.Bmp = *bmp; Atlas2D.Bmp = *bmp;
Atlas2D.TileSize = bmp->width / ATLAS2D_TILES_PER_ROW; Atlas2D.TileSize = bmp->width / ATLAS2D_TILES_PER_ROW;
Atlas2D.RowsCount = bmp->height / Atlas2D.TileSize; Atlas2D.RowsCount = bmp->height / Atlas2D.TileSize;
@ -83,7 +83,7 @@ static void Atlas_Update(Bitmap* bmp) {
Atlas_Convert2DTo1D(); Atlas_Convert2DTo1D();
} }
static GfxResourceID Atlas_LoadTile_Raw(TextureLoc texLoc, Bitmap* element) { static GfxResourceID Atlas_LoadTile_Raw(TextureLoc texLoc, struct Bitmap* element) {
int size = Atlas2D.TileSize; int size = Atlas2D.TileSize;
int x = Atlas2D_TileX(texLoc), y = Atlas2D_TileY(texLoc); int x = Atlas2D_TileX(texLoc), y = Atlas2D_TileY(texLoc);
if (y >= Atlas2D.RowsCount) return 0; if (y >= Atlas2D.RowsCount) return 0;
@ -95,7 +95,7 @@ static GfxResourceID Atlas_LoadTile_Raw(TextureLoc texLoc, Bitmap* element) {
GfxResourceID Atlas2D_LoadTile(TextureLoc texLoc) { GfxResourceID Atlas2D_LoadTile(TextureLoc texLoc) {
BitmapCol pixels[64 * 64]; BitmapCol pixels[64 * 64];
int size = Atlas2D.TileSize; int size = Atlas2D.TileSize;
Bitmap tile; struct Bitmap tile;
GfxResourceID texId; GfxResourceID texId;
/* Try to allocate bitmap on stack if possible */ /* Try to allocate bitmap on stack if possible */
@ -122,7 +122,7 @@ static void Atlas1D_Free(void) {
} }
} }
cc_bool Atlas_TryChange(Bitmap* atlas) { cc_bool Atlas_TryChange(struct Bitmap* atlas) {
static const String terrain = String_FromConst("terrain.png"); static const String terrain = String_FromConst("terrain.png");
if (!Game_ValidateBitmap(&terrain, atlas)) return false; if (!Game_ValidateBitmap(&terrain, atlas)) return false;
@ -299,7 +299,7 @@ static cc_result ExtractZip(struct Stream* stream) {
} }
static cc_result ExtractPng(struct Stream* stream) { static cc_result ExtractPng(struct Stream* stream) {
Bitmap bmp; struct Bitmap bmp;
cc_result res = Png_Decode(&bmp, stream); cc_result res = Png_Decode(&bmp, stream);
if (!res && Atlas_TryChange(&bmp)) return 0; if (!res && Atlas_TryChange(&bmp)) return 0;
@ -416,7 +416,7 @@ void TexturePack_DownloadAsync(const String* url, const String* id) {
*---------------------------------------------------Textures component----------------------------------------------------* *---------------------------------------------------Textures component----------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
static void OnFileChanged(void* obj, struct Stream* stream, const String* name) { static void OnFileChanged(void* obj, struct Stream* stream, const String* name) {
Bitmap bmp; struct Bitmap bmp;
cc_result res; cc_result res;
if (!String_CaselessEqualsConst(name, "terrain.png")) return; if (!String_CaselessEqualsConst(name, "terrain.png")) return;

View File

@ -30,7 +30,7 @@ extern struct IGameComponent Textures_Component;
CC_VAR extern struct _Atlas2DData { CC_VAR extern struct _Atlas2DData {
/* Bitmap that contains the textures of all tiles. */ /* Bitmap that contains the textures of all tiles. */
/* Tiles are indexed left to right, top to bottom. */ /* Tiles are indexed left to right, top to bottom. */
Bitmap Bmp; struct Bitmap Bmp;
/* Size of each tile in pixels. (default 16x16) */ /* Size of each tile in pixels. (default 16x16) */
int TileSize; int TileSize;
/* Number of rows in the atlas. (default 16, can be 32) */ /* Number of rows in the atlas. (default 16, can be 32) */
@ -61,7 +61,7 @@ CC_VAR extern struct _Atlas1DData {
/* Loads the given tile into a new separate texture. */ /* Loads the given tile into a new separate texture. */
GfxResourceID Atlas2D_LoadTile(TextureLoc texLoc); GfxResourceID Atlas2D_LoadTile(TextureLoc texLoc);
/* Attempts to change the terrain atlas. (bitmap containing textures for all blocks) */ /* Attempts to change the terrain atlas. (bitmap containing textures for all blocks) */
cc_bool Atlas_TryChange(Bitmap* bmp); cc_bool Atlas_TryChange(struct Bitmap* bmp);
/* Returns the UV rectangle of the given tile id in the 1D atlases. */ /* Returns the UV rectangle of the given tile id in the 1D atlases. */
/* That is, returns U1/U2/V1/V2 coords that make up the tile in a 1D atlas. */ /* That is, returns U1/U2/V1/V2 coords that make up the tile in a 1D atlas. */
/* index is set to the index of the 1D atlas that the tile is in. */ /* index is set to the index of the 1D atlas that the tile is in. */

View File

@ -68,7 +68,7 @@ int Utils_AccumulateWheelDelta(float* accumulator, float delta) {
} }
/* Checks if an area is completely black, so Alex skins edited with Microsoft Paint are still treated as Alex */ /* Checks if an area is completely black, so Alex skins edited with Microsoft Paint are still treated as Alex */
static cc_bool Utils_IsAllBlack(const Bitmap* bmp, int x1, int y1, int width, int height) { static cc_bool IsAllBlack(const struct Bitmap* bmp, int x1, int y1, int width, int height) {
int x, y; int x, y;
for (y = y1; y < y1 + height; y++) { for (y = y1; y < y1 + height; y++) {
BitmapCol* row = Bitmap_GetRow(bmp, y); BitmapCol* row = Bitmap_GetRow(bmp, y);
@ -80,7 +80,7 @@ static cc_bool Utils_IsAllBlack(const Bitmap* bmp, int x1, int y1, int width, in
return true; return true;
} }
cc_uint8 Utils_CalcSkinType(const Bitmap* bmp) { cc_uint8 Utils_CalcSkinType(const struct Bitmap* bmp) {
BitmapCol col; BitmapCol col;
int scale; int scale;
if (bmp->width == bmp->height * 2) return SKIN_64x32; if (bmp->width == bmp->height * 2) return SKIN_64x32;
@ -91,8 +91,8 @@ cc_uint8 Utils_CalcSkinType(const Bitmap* bmp) {
col = Bitmap_GetPixel(bmp, 54 * scale, 20 * scale); col = Bitmap_GetPixel(bmp, 54 * scale, 20 * scale);
if (BitmapCol_A(col) < 128) return SKIN_64x64_SLIM; if (BitmapCol_A(col) < 128) return SKIN_64x64_SLIM;
return Utils_IsAllBlack(bmp, 54 * scale, 20 * scale, 2 * scale, 12 * scale) return IsAllBlack(bmp, 54 * scale, 20 * scale, 2 * scale, 12 * scale)
&& Utils_IsAllBlack(bmp, 50 * scale, 16 * scale, 2 * scale, 4 * scale) ? SKIN_64x64_SLIM : SKIN_64x64; && IsAllBlack(bmp, 50 * scale, 16 * scale, 2 * scale, 4 * scale) ? SKIN_64x64_SLIM : SKIN_64x64;
} }
cc_uint32 Utils_CRC32(const cc_uint8* data, cc_uint32 length) { cc_uint32 Utils_CRC32(const cc_uint8* data, cc_uint32 length) {

View File

@ -37,7 +37,7 @@ void Utils_UNSAFE_TrimFirstDirectory(STRING_REF String* path);
int Utils_AccumulateWheelDelta(float* accumulator, float delta); int Utils_AccumulateWheelDelta(float* accumulator, float delta);
#define Utils_AdjViewDist(value) ((int)(1.4142135f * (value))) #define Utils_AdjViewDist(value) ((int)(1.4142135f * (value)))
cc_uint8 Utils_CalcSkinType(const Bitmap* bmp); cc_uint8 Utils_CalcSkinType(const struct Bitmap* bmp);
cc_uint32 Utils_CRC32(const cc_uint8* data, cc_uint32 length); cc_uint32 Utils_CRC32(const cc_uint8* data, cc_uint32 length);
/* CRC32 lookup table, for faster CRC32 calculations. */ /* CRC32 lookup table, for faster CRC32 calculations. */
/* NOTE: This cannot be just indexed by byte value - see Utils_CRC32 implementation. */ /* NOTE: This cannot be just indexed by byte value - see Utils_CRC32 implementation. */

View File

@ -1435,7 +1435,7 @@ static void MenuInputWidget_RemakeTexture(void* widget) {
struct Texture* tex; struct Texture* tex;
int textWidth, lineHeight; int textWidth, lineHeight;
int width, height, hintX, y; int width, height, hintX, y;
Bitmap bmp; struct Bitmap bmp;
DrawTextArgs_Make(&args, &w->base.text, w->base.font, false); DrawTextArgs_Make(&args, &w->base.text, w->base.font, false);
textWidth = Drawer2D_TextWidth(&args); textWidth = Drawer2D_TextWidth(&args);
@ -1540,7 +1540,7 @@ static void ChatInputWidget_RemakeTexture(void* widget) {
struct InputWidget* w = (struct InputWidget*)widget; struct InputWidget* w = (struct InputWidget*)widget;
struct DrawTextArgs args; struct DrawTextArgs args;
int width = 0, height = 0; int width = 0, height = 0;
Bitmap bmp; struct Bitmap bmp;
char lastCol; char lastCol;
int i, x, y; int i, x, y;
@ -2056,7 +2056,7 @@ static void TextGroupWidget_DrawAdvanced(struct TextGroupWidget* w, struct Textu
struct Portion bit; struct Portion bit;
int width, height; int width, height;
int partWidths[Array_Elems(portions)]; int partWidths[Array_Elems(portions)];
Bitmap bmp; struct Bitmap bmp;
int portionsCount; int portionsCount;
int i, x, ul; int i, x, ul;
@ -2281,7 +2281,7 @@ static int SpecialInputWidget_MeasureTitles(struct SpecialInputWidget* w) {
return width; return width;
} }
static void SpecialInputWidget_DrawTitles(struct SpecialInputWidget* w, Bitmap* bmp) { static void SpecialInputWidget_DrawTitles(struct SpecialInputWidget* w, struct Bitmap* bmp) {
BitmapCol col_selected = BitmapCol_Make(30, 30, 30, 200); BitmapCol col_selected = BitmapCol_Make(30, 30, 30, 200);
BitmapCol col_inactive = BitmapCol_Make( 0, 0, 0, 127); BitmapCol col_inactive = BitmapCol_Make( 0, 0, 0, 127);
BitmapCol col; BitmapCol col;
@ -2325,7 +2325,7 @@ static int SpecialInputWidget_ContentHeight(struct SpecialInputWidget* w, struct
return w->elementHeight * rows; return w->elementHeight * rows;
} }
static void SpecialInputWidget_DrawContent(struct SpecialInputWidget* w, struct SpecialInputTab* tab, Bitmap* bmp, int yOffset) { static void SpecialInputWidget_DrawContent(struct SpecialInputWidget* w, struct SpecialInputTab* tab, struct Bitmap* bmp, int yOffset) {
struct DrawTextArgs args; struct DrawTextArgs args;
int i, x, y, item; int i, x, y, item;
@ -2348,7 +2348,7 @@ static void SpecialInputWidget_Make(struct SpecialInputWidget* w, struct Special
int titlesWidth, titlesHeight; int titlesWidth, titlesHeight;
int contentWidth, contentHeight; int contentWidth, contentHeight;
int width, height; int width, height;
Bitmap bmp; struct Bitmap bmp;
titlesWidth = SpecialInputWidget_MeasureTitles(w); titlesWidth = SpecialInputWidget_MeasureTitles(w);
titlesHeight = w->titleHeight; titlesHeight = w->titleHeight;

View File

@ -376,7 +376,7 @@ static void ShowDialogCore(const char* title, const char* msg) {
} }
static SDL_Surface* surface; static SDL_Surface* surface;
void Window_AllocFramebuffer(Bitmap* bmp) { void Window_AllocFramebuffer(struct Bitmap* bmp) {
surface = SDL_GetWindowSurface(win_handle); surface = SDL_GetWindowSurface(win_handle);
if (!surface) Window_SDLFail("getting window surface"); if (!surface) Window_SDLFail("getting window surface");
@ -394,7 +394,7 @@ void Window_DrawFramebuffer(Rect2D r) {
SDL_UpdateWindowSurfaceRects(win_handle, &rect, 1); SDL_UpdateWindowSurfaceRects(win_handle, &rect, 1);
} }
void Window_FreeFramebuffer(Bitmap* bmp) { void Window_FreeFramebuffer(struct Bitmap* bmp) {
/* SDL docs explicitly say to NOT free the surface */ /* SDL docs explicitly say to NOT free the surface */
/* https://wiki.libsdl.org/SDL_GetWindowSurface */ /* https://wiki.libsdl.org/SDL_GetWindowSurface */
/* TODO: Do we still need to unlock it though? */ /* TODO: Do we still need to unlock it though? */
@ -887,7 +887,7 @@ static void ShowDialogCore(const char* title, const char* msg) {
static HDC draw_DC; static HDC draw_DC;
static HBITMAP draw_DIB; static HBITMAP draw_DIB;
void Window_AllocFramebuffer(Bitmap* bmp) { void Window_AllocFramebuffer(struct Bitmap* bmp) {
BITMAPINFO hdr = { 0 }; BITMAPINFO hdr = { 0 };
if (!draw_DC) draw_DC = CreateCompatibleDC(win_DC); if (!draw_DC) draw_DC = CreateCompatibleDC(win_DC);
@ -906,7 +906,7 @@ void Window_DrawFramebuffer(Rect2D r) {
SelectObject(draw_DC, oldSrc); SelectObject(draw_DC, oldSrc);
} }
void Window_FreeFramebuffer(Bitmap* bmp) { void Window_FreeFramebuffer(struct Bitmap* bmp) {
DeleteObject(draw_DIB); DeleteObject(draw_DIB);
} }
@ -1796,7 +1796,7 @@ static void ShowDialogCore(const char* title, const char* msg) {
static GC fb_gc; static GC fb_gc;
static XImage* fb_image; static XImage* fb_image;
void Window_AllocFramebuffer(Bitmap* bmp) { void Window_AllocFramebuffer(struct Bitmap* bmp) {
if (!fb_gc) fb_gc = XCreateGC(win_display, win_handle, 0, NULL); if (!fb_gc) fb_gc = XCreateGC(win_display, win_handle, 0, NULL);
bmp->scan0 = (BitmapCol*)Mem_Alloc(bmp->width * bmp->height, 4, "window pixels"); bmp->scan0 = (BitmapCol*)Mem_Alloc(bmp->width * bmp->height, 4, "window pixels");
@ -1810,7 +1810,7 @@ void Window_DrawFramebuffer(Rect2D r) {
r.X, r.Y, r.X, r.Y, r.Width, r.Height); r.X, r.Y, r.X, r.Y, r.Width, r.Height);
} }
void Window_FreeFramebuffer(Bitmap* bmp) { void Window_FreeFramebuffer(struct Bitmap* bmp) {
XFree(fb_image); XFree(fb_image);
Mem_Free(bmp->scan0); Mem_Free(bmp->scan0);
} }
@ -2492,10 +2492,10 @@ static void ShowDialogCore(const char* title, const char* msg) {
} }
static CGrafPtr fb_port; static CGrafPtr fb_port;
static Bitmap fb_bmp; static struct Bitmap fb_bmp;
static CGColorSpaceRef colorSpace; static CGColorSpaceRef colorSpace;
void Window_AllocFramebuffer(Bitmap* bmp) { void Window_AllocFramebuffer(struct Bitmap* bmp) {
if (!fb_port) fb_port = GetWindowPort(win_handle); if (!fb_port) fb_port = GetWindowPort(win_handle);
bmp->scan0 = Mem_Alloc(bmp->width * bmp->height, 4, "window pixels"); bmp->scan0 = Mem_Alloc(bmp->width * bmp->height, 4, "window pixels");
@ -2542,7 +2542,7 @@ void Window_DrawFramebuffer(Rect2D r) {
CGDataProviderRelease(provider); CGDataProviderRelease(provider);
} }
void Window_FreeFramebuffer(Bitmap* bmp) { void Window_FreeFramebuffer(struct Bitmap* bmp) {
Mem_Free(bmp->scan0); Mem_Free(bmp->scan0);
CGColorSpaceRelease(colorSpace); CGColorSpaceRelease(colorSpace);
} }
@ -2966,8 +2966,8 @@ static void ShowDialogCore(const char* title, const char* msg) {
CFRelease(msgCF); CFRelease(msgCF);
} }
static Bitmap fb_bmp; static struct Bitmap fb_bmp;
void Window_AllocFramebuffer(Bitmap* bmp) { void Window_AllocFramebuffer(struct Bitmap* bmp) {
bmp->scan0 = (BitmapCol*)Mem_Alloc(bmp->width * bmp->height, 4, "window pixels"); bmp->scan0 = (BitmapCol*)Mem_Alloc(bmp->width * bmp->height, 4, "window pixels");
fb_bmp = *bmp; fb_bmp = *bmp;
} }
@ -3017,7 +3017,7 @@ void Window_DrawFramebuffer(Rect2D r) {
objc_msgSend(viewHandle, selDisplayIfNeeded); objc_msgSend(viewHandle, selDisplayIfNeeded);
} }
void Window_FreeFramebuffer(Bitmap* bmp) { void Window_FreeFramebuffer(struct Bitmap* bmp) {
Mem_Free(bmp->scan0); Mem_Free(bmp->scan0);
} }
#endif #endif
@ -3465,9 +3465,9 @@ static void ShowDialogCore(const char* title, const char* msg) {
EM_ASM_({ alert(UTF8ToString($0) + "\n\n" + UTF8ToString($1)); }, title, msg); EM_ASM_({ alert(UTF8ToString($0) + "\n\n" + UTF8ToString($1)); }, title, msg);
} }
void Window_AllocFramebuffer(Bitmap* bmp) { } void Window_AllocFramebuffer(struct Bitmap* bmp) { }
void Window_DrawFramebuffer(Rect2D r) { } void Window_DrawFramebuffer(Rect2D r) { }
void Window_FreeFramebuffer(Bitmap* bmp) { } void Window_FreeFramebuffer(struct Bitmap* bmp) { }
EMSCRIPTEN_KEEPALIVE void Window_OnTextChanged(const char* src) { EMSCRIPTEN_KEEPALIVE void Window_OnTextChanged(const char* src) {
char buffer[800]; char buffer[800];
@ -3822,8 +3822,8 @@ static void ShowDialogCore(const char* title, const char* msg) {
(*env)->DeleteLocalRef(env, args[1].l); (*env)->DeleteLocalRef(env, args[1].l);
} }
static Bitmap fb_bmp; static struct Bitmap fb_bmp;
void Window_AllocFramebuffer(Bitmap* bmp) { void Window_AllocFramebuffer(struct Bitmap* bmp) {
bmp->scan0 = (BitmapCol*)Mem_Alloc(bmp->width * bmp->height, 4, "window pixels"); bmp->scan0 = (BitmapCol*)Mem_Alloc(bmp->width * bmp->height, 4, "window pixels");
fb_bmp = *bmp; fb_bmp = *bmp;
} }
@ -3865,7 +3865,7 @@ void Window_DrawFramebuffer(Rect2D r) {
if (res) Logger_Abort2(res, "Unlocking window pixels"); if (res) Logger_Abort2(res, "Unlocking window pixels");
} }
void Window_FreeFramebuffer(Bitmap* bmp) { void Window_FreeFramebuffer(struct Bitmap* bmp) {
Mem_Free(bmp->scan0); Mem_Free(bmp->scan0);
} }

View File

@ -78,7 +78,6 @@ void Window_Init(void);
void Window_Create(int width, int height); void Window_Create(int width, int height);
/* Sets the text of the titlebar above the window. */ /* Sets the text of the titlebar above the window. */
CC_API void Window_SetTitle(const String* title); CC_API void Window_SetTitle(const String* title);
/* TODO: IMPLEMENT void Window_SetIcon(Bitmap* bmp); */
typedef void (*RequestClipboardCallback)(String* value, void* obj); typedef void (*RequestClipboardCallback)(String* value, void* obj);
/* Gets the text currently on the clipboard. */ /* Gets the text currently on the clipboard. */
@ -121,12 +120,12 @@ CC_API void Window_ShowDialog(const char* title, const char* msg);
/* Allocates a framebuffer that can be drawn/transferred to the window. */ /* Allocates a framebuffer that can be drawn/transferred to the window. */
/* NOTE: Do NOT free bmp->Scan0, use Window_FreeFramebuffer. */ /* NOTE: Do NOT free bmp->Scan0, use Window_FreeFramebuffer. */
/* NOTE: This MUST be called whenever the window is resized. */ /* NOTE: This MUST be called whenever the window is resized. */
void Window_AllocFramebuffer(Bitmap* bmp); void Window_AllocFramebuffer(struct Bitmap* bmp);
/* Transfers pixels from the allocated framebuffer to the on-screen window. */ /* Transfers pixels from the allocated framebuffer to the on-screen window. */
/* r can be used to only update a small region of pixels (may be ignored) */ /* r can be used to only update a small region of pixels (may be ignored) */
void Window_DrawFramebuffer(Rect2D r); void Window_DrawFramebuffer(Rect2D r);
/* Frees the previously allocated framebuffer. */ /* Frees the previously allocated framebuffer. */
void Window_FreeFramebuffer(Bitmap* bmp); void Window_FreeFramebuffer(struct Bitmap* bmp);
/* Displays on-screen keyboard for platforms that lack physical keyboard input. */ /* Displays on-screen keyboard for platforms that lack physical keyboard input. */
/* NOTE: On desktop platforms, this won't do anything. */ /* NOTE: On desktop platforms, this won't do anything. */