mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-19 04:26:52 -04:00
few less compile errors in C client.
This commit is contained in:
parent
c2112c4b94
commit
89e7175c62
@ -13,18 +13,13 @@ typedef struct Bitmap_ {
|
|||||||
Int32 Height; /* Number of pixels vertically. */
|
Int32 Height; /* Number of pixels vertically. */
|
||||||
} Bitmap;
|
} Bitmap;
|
||||||
|
|
||||||
/* Size of each ARGB pixel in bytes. */
|
|
||||||
#define Bitmap_PixelBytesSize 4
|
#define Bitmap_PixelBytesSize 4
|
||||||
/* Calculates size of data of a 2D bitmap in bytes. */
|
|
||||||
#define Bitmap_DataSize(width, height) ((UInt32)(width) * (UInt32)(height) * (UInt32)Bitmap_PixelBytesSize)
|
#define Bitmap_DataSize(width, height) ((UInt32)(width) * (UInt32)(height) * (UInt32)Bitmap_PixelBytesSize)
|
||||||
/* Returns a pointer to the start of the y'th scanline. */
|
|
||||||
#define Bitmap_GetRow(bmp, y) ((UInt32*)((bmp)->Scan0 + ((y) * (bmp)->Stride)))
|
#define Bitmap_GetRow(bmp, y) ((UInt32*)((bmp)->Scan0 + ((y) * (bmp)->Stride)))
|
||||||
|
#define Bitmap_GetPixel(bmp, x, y) (((UInt32*)((bmp)->Scan0 + ((y) * (bmp)->Stride)))[x])
|
||||||
|
|
||||||
/* Constructs or updates a Bitmap instance. */
|
|
||||||
void Bitmap_Create(Bitmap* bmp, Int32 width, Int32 height, UInt8* scan0);
|
void Bitmap_Create(Bitmap* bmp, Int32 width, Int32 height, UInt8* scan0);
|
||||||
/* Copies a block of pixels from one bitmap to another. */
|
|
||||||
void Bitmap_CopyBlock(Int32 srcX, Int32 srcY, Int32 dstX, Int32 dstY, Bitmap* src, Bitmap* dst, Int32 size);
|
void Bitmap_CopyBlock(Int32 srcX, Int32 srcY, Int32 dstX, Int32 dstY, Bitmap* src, Bitmap* dst, Int32 size);
|
||||||
/* Copies a row of pixels from one bitmap to another. */
|
|
||||||
void Bitmap_CopyRow(Int32 srcY, Int32 dstY, Bitmap* src, Bitmap* dst, Int32 width);
|
void Bitmap_CopyRow(Int32 srcY, Int32 dstY, Bitmap* src, Bitmap* dst, Int32 width);
|
||||||
/* Allocates a new bitmap of the given dimensions. You are responsible for freeing its memory! */
|
/* Allocates a new bitmap of the given dimensions. You are responsible for freeing its memory! */
|
||||||
void Bitmap_Allocate(Bitmap* bmp, Int32 width, Int32 height);
|
void Bitmap_Allocate(Bitmap* bmp, Int32 width, Int32 height);
|
||||||
|
@ -20,10 +20,10 @@ typedef struct IGameComponent_ {
|
|||||||
/* Called to update the component's state when the user has finished loading a new map. */
|
/* Called to update the component's state when the user has finished loading a new map. */
|
||||||
void (*OnNewMapLoaded)(void);
|
void (*OnNewMapLoaded)(void);
|
||||||
} IGameComponent;
|
} IGameComponent;
|
||||||
|
|
||||||
/* Makes an empty game component with all its function pointers initalised to null. */
|
/* Makes an empty game component with all its function pointers initalised to null. */
|
||||||
IGameComponent IGameComponent_MakeEmpty(void);
|
IGameComponent IGameComponent_MakeEmpty(void);
|
||||||
|
|
||||||
|
|
||||||
/* Represents a task that periodically runs on the main thread every specified interval. */
|
/* Represents a task that periodically runs on the main thread every specified interval. */
|
||||||
typedef struct ScheduledTask_ {
|
typedef struct ScheduledTask_ {
|
||||||
/* How long (in seconds) has elapsed since callback was last invoked. */
|
/* How long (in seconds) has elapsed since callback was last invoked. */
|
||||||
|
@ -131,7 +131,7 @@ void Player_ApplySkin(Player* player, Player* from) {
|
|||||||
/* Custom mob textures */
|
/* Custom mob textures */
|
||||||
dst->MobTextureId = NULL;
|
dst->MobTextureId = NULL;
|
||||||
String skin = String_FromRawArray(player->SkinNameRaw);
|
String skin = String_FromRawArray(player->SkinNameRaw);
|
||||||
if (Utils.IsUrlPrefix(&skin, 0)) {
|
if (Utils_IsUrlPrefix(&skin, 0)) {
|
||||||
dst->MobTextureId = dst->TextureId;
|
dst->MobTextureId = dst->TextureId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -236,7 +236,7 @@ void Player_CheckSkin(Player* player) {
|
|||||||
|
|
||||||
Player_SetSkinAll(player, true);
|
Player_SetSkinAll(player, true);
|
||||||
Player_EnsurePow2(player, &bmp);
|
Player_EnsurePow2(player, &bmp);
|
||||||
entity->SkinType = Utils.GetSkinType(bmp);
|
entity->SkinType = Utils_GetSkinType(&bmp);
|
||||||
|
|
||||||
if (entity->SkinType == SKIN_TYPE_INVALID) {
|
if (entity->SkinType == SKIN_TYPE_INVALID) {
|
||||||
Player_SetSkinAll(player, true);
|
Player_SetSkinAll(player, true);
|
||||||
|
@ -709,18 +709,16 @@ void LoadingScreen_MapLoading(void* obj, Real32 progress) {
|
|||||||
|
|
||||||
void LoadingScreen_OnResize(Screen* elem) {
|
void LoadingScreen_OnResize(Screen* elem) {
|
||||||
LoadingScreen* screen = (LoadingScreen*)elem;
|
LoadingScreen* screen = (LoadingScreen*)elem;
|
||||||
Widget* widget = &screen->TitleWidget.Base;
|
Widget* widget;
|
||||||
widget->Reposition(widget);
|
widget = &screen->TitleWidget.Base; widget->Reposition(widget);
|
||||||
widget = &screen->MessageWidget.Base;
|
widget = &screen->MessageWidget.Base; widget->Reposition(widget);
|
||||||
widget->Reposition(widget);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadingScreen_ContextLost(void* obj) {
|
void LoadingScreen_ContextLost(void* obj) {
|
||||||
LoadingScreen* screen = (LoadingScreen*)obj;
|
LoadingScreen* screen = (LoadingScreen*)obj;
|
||||||
GuiElement* elem = &screen->TitleWidget.Base.Base;
|
GuiElement* elem;
|
||||||
elem->Free(elem);
|
elem = &screen->TitleWidget.Base.Base; elem->Free(elem);
|
||||||
GuiElement* elem = &screen->MessageWidget.Base.Base;
|
elem = &screen->MessageWidget.Base.Base; elem->Free(elem);
|
||||||
elem->Free(elem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadingScreen_ContextRecreated(void* obj) {
|
void LoadingScreen_ContextRecreated(void* obj) {
|
||||||
|
@ -35,15 +35,6 @@ Int64 DateTime_MillisecondsBetween(DateTime* start, DateTime* end) {
|
|||||||
return msEnd - msStart;
|
return msEnd - msStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
Int32 Utils_AccumulateWheelDelta(Real32* accmulator, Real32 delta) {
|
|
||||||
/* Some mice may use deltas of say (0.2, 0.2, 0.2, 0.2, 0.2) */
|
|
||||||
/* We must use rounding at final step, not at every intermediate step. */
|
|
||||||
*accmulator += delta;
|
|
||||||
Int32 steps = (Int32)*accmulator;
|
|
||||||
*accmulator -= steps;
|
|
||||||
return steps;
|
|
||||||
}
|
|
||||||
|
|
||||||
UInt32 Utils_ParseEnum(STRING_PURE String* text, UInt32 defValue, const UInt8** names, UInt32 namesCount) {
|
UInt32 Utils_ParseEnum(STRING_PURE String* text, UInt32 defValue, const UInt8** names, UInt32 namesCount) {
|
||||||
UInt32 i;
|
UInt32 i;
|
||||||
for (i = 0; i < namesCount; i++) {
|
for (i = 0; i < namesCount; i++) {
|
||||||
@ -56,3 +47,31 @@ UInt32 Utils_ParseEnum(STRING_PURE String* text, UInt32 defValue, const UInt8**
|
|||||||
bool Utils_IsValidInputChar(UInt8 c, bool supportsCP437) {
|
bool Utils_IsValidInputChar(UInt8 c, bool supportsCP437) {
|
||||||
return supportsCP437 || (Convert_CP437ToUnicode(c) == c);
|
return supportsCP437 || (Convert_CP437ToUnicode(c) == c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Utils_IsUrlPrefix(STRING_PURE String* value, Int32 index) {
|
||||||
|
String httpStr = String_FromConst("http://");
|
||||||
|
String httpsStr = String_FromConst("https://");
|
||||||
|
Int32 http = String_IndexOfString(value, &httpStr);
|
||||||
|
Int32 https = String_IndexOfString(value, &httpsStr);
|
||||||
|
return http == index || https == index;
|
||||||
|
}
|
||||||
|
|
||||||
|
Int32 Utils_AccumulateWheelDelta(Real32* accmulator, Real32 delta) {
|
||||||
|
/* Some mice may use deltas of say (0.2, 0.2, 0.2, 0.2, 0.2) */
|
||||||
|
/* We must use rounding at final step, not at every intermediate step. */
|
||||||
|
*accmulator += delta;
|
||||||
|
Int32 steps = (Int32)(*accmulator);
|
||||||
|
*accmulator -= steps;
|
||||||
|
return steps;
|
||||||
|
}
|
||||||
|
|
||||||
|
UInt8 Utils_GetSkinType(Bitmap* bmp) {
|
||||||
|
if (bmp->Width == bmp->Height * 2) return SKIN_TYPE_64x32;
|
||||||
|
if (bmp->Width != bmp->Height) return SKIN_TYPE_INVALID;
|
||||||
|
|
||||||
|
/* Minecraft alex skins have this particular pixel with alpha of 0 */
|
||||||
|
Int32 scale = bmp->Width / 64;
|
||||||
|
UInt32 pixel = Bitmap_GetPixel(bmp, 54 * scale, 20 * scale);
|
||||||
|
UInt8 alpha = (UInt8)(pixel >> 24);
|
||||||
|
return alpha >= 127 ? SKIN_TYPE_64x64 : SKIN_TYPE_64x64_SLIM;
|
||||||
|
}
|
@ -2,6 +2,7 @@
|
|||||||
#define CC_UTILS_H
|
#define CC_UTILS_H
|
||||||
#include "Typedefs.h"
|
#include "Typedefs.h"
|
||||||
#include "String.h"
|
#include "String.h"
|
||||||
|
#include "Bitmap.h"
|
||||||
/* Implements various utility functions.
|
/* Implements various utility functions.
|
||||||
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
||||||
*/
|
*/
|
||||||
@ -25,8 +26,12 @@ typedef struct DateTime_ {
|
|||||||
Int64 DateTime_TotalMilliseconds(DateTime* time);
|
Int64 DateTime_TotalMilliseconds(DateTime* time);
|
||||||
Int64 DateTime_MillisecondsBetween(DateTime* start, DateTime* end);
|
Int64 DateTime_MillisecondsBetween(DateTime* start, DateTime* end);
|
||||||
|
|
||||||
Int32 Utils_AccumulateWheelDelta(Real32* accmulator, Real32 delta);
|
|
||||||
UInt32 Utils_ParseEnum(STRING_PURE String* text, UInt32 defValue, const UInt8** names, UInt32 namesCount);
|
UInt32 Utils_ParseEnum(STRING_PURE String* text, UInt32 defValue, const UInt8** names, UInt32 namesCount);
|
||||||
bool Utils_IsValidInputChar(UInt8 c, bool supportsCP437);
|
bool Utils_IsValidInputChar(UInt8 c, bool supportsCP437);
|
||||||
|
bool Utils_IsUrlPrefix(STRING_PURE String* value, Int32 index);
|
||||||
|
|
||||||
|
Int32 Utils_AccumulateWheelDelta(Real32* accmulator, Real32 delta);
|
||||||
#define Utils_AdjViewDist(value) ((Int32)(1.4142135f * (value)))
|
#define Utils_AdjViewDist(value) ((Int32)(1.4142135f * (value)))
|
||||||
|
|
||||||
|
UInt8 Utils_GetSkinType(Bitmap* bmp);
|
||||||
#endif
|
#endif
|
Loading…
x
Reference in New Issue
Block a user