mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 03:25:14 -04:00
few less compile errors in C client.
This commit is contained in:
parent
c2112c4b94
commit
89e7175c62
@ -7,24 +7,19 @@
|
||||
*/
|
||||
|
||||
typedef struct Bitmap_ {
|
||||
UInt8* Scan0; /* Pointer to first scaneline. */
|
||||
UInt8* Scan0; /* Pointer to first scaneline. */
|
||||
UInt32 Stride; /* Number of bytes in each scanline. TODO: Obsolete this completely and just use Width << 2 ? */
|
||||
Int32 Width; /* Number of pixels horizontally. */
|
||||
Int32 Height; /* Number of pixels vertically. */
|
||||
Int32 Width; /* Number of pixels horizontally. */
|
||||
Int32 Height; /* Number of pixels vertically. */
|
||||
} Bitmap;
|
||||
|
||||
/* Size of each ARGB pixel in bytes. */
|
||||
#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)
|
||||
/* Returns a pointer to the start of the y'th scanline. */
|
||||
#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);
|
||||
/* 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);
|
||||
/* Copies a row of pixels from one bitmap to another. */
|
||||
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! */
|
||||
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. */
|
||||
void (*OnNewMapLoaded)(void);
|
||||
} IGameComponent;
|
||||
|
||||
/* Makes an empty game component with all its function pointers initalised to null. */
|
||||
IGameComponent IGameComponent_MakeEmpty(void);
|
||||
|
||||
|
||||
/* Represents a task that periodically runs on the main thread every specified interval. */
|
||||
typedef struct ScheduledTask_ {
|
||||
/* 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 */
|
||||
dst->MobTextureId = NULL;
|
||||
String skin = String_FromRawArray(player->SkinNameRaw);
|
||||
if (Utils.IsUrlPrefix(&skin, 0)) {
|
||||
if (Utils_IsUrlPrefix(&skin, 0)) {
|
||||
dst->MobTextureId = dst->TextureId;
|
||||
}
|
||||
}
|
||||
@ -236,7 +236,7 @@ void Player_CheckSkin(Player* player) {
|
||||
|
||||
Player_SetSkinAll(player, true);
|
||||
Player_EnsurePow2(player, &bmp);
|
||||
entity->SkinType = Utils.GetSkinType(bmp);
|
||||
entity->SkinType = Utils_GetSkinType(&bmp);
|
||||
|
||||
if (entity->SkinType == SKIN_TYPE_INVALID) {
|
||||
Player_SetSkinAll(player, true);
|
||||
|
@ -709,18 +709,16 @@ void LoadingScreen_MapLoading(void* obj, Real32 progress) {
|
||||
|
||||
void LoadingScreen_OnResize(Screen* elem) {
|
||||
LoadingScreen* screen = (LoadingScreen*)elem;
|
||||
Widget* widget = &screen->TitleWidget.Base;
|
||||
widget->Reposition(widget);
|
||||
widget = &screen->MessageWidget.Base;
|
||||
widget->Reposition(widget);
|
||||
Widget* widget;
|
||||
widget = &screen->TitleWidget.Base; widget->Reposition(widget);
|
||||
widget = &screen->MessageWidget.Base; widget->Reposition(widget);
|
||||
}
|
||||
|
||||
void LoadingScreen_ContextLost(void* obj) {
|
||||
LoadingScreen* screen = (LoadingScreen*)obj;
|
||||
GuiElement* elem = &screen->TitleWidget.Base.Base;
|
||||
elem->Free(elem);
|
||||
GuiElement* elem = &screen->MessageWidget.Base.Base;
|
||||
elem->Free(elem);
|
||||
GuiElement* elem;
|
||||
elem = &screen->TitleWidget.Base.Base; elem->Free(elem);
|
||||
elem = &screen->MessageWidget.Base.Base; elem->Free(elem);
|
||||
}
|
||||
|
||||
void LoadingScreen_ContextRecreated(void* obj) {
|
||||
|
@ -35,15 +35,6 @@ Int64 DateTime_MillisecondsBetween(DateTime* start, DateTime* end) {
|
||||
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 i;
|
||||
for (i = 0; i < namesCount; i++) {
|
||||
@ -55,4 +46,32 @@ UInt32 Utils_ParseEnum(STRING_PURE String* text, UInt32 defValue, const UInt8**
|
||||
|
||||
bool Utils_IsValidInputChar(UInt8 c, bool supportsCP437) {
|
||||
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
|
||||
#include "Typedefs.h"
|
||||
#include "String.h"
|
||||
#include "Bitmap.h"
|
||||
/* Implements various utility functions.
|
||||
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
||||
*/
|
||||
@ -25,8 +26,12 @@ typedef struct DateTime_ {
|
||||
Int64 DateTime_TotalMilliseconds(DateTime* time);
|
||||
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);
|
||||
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)))
|
||||
|
||||
UInt8 Utils_GetSkinType(Bitmap* bmp);
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user