Permalink
Browse files

C client: Minor code cleanup

  • Loading branch information...
UnknownShadow200 committed Sep 11, 2018
1 parent ab8a35f commit 6eb08b70e2355d83e820bd191313949d459b4956
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View
@@ -11,6 +11,7 @@
#include "ErrorHandler.h"
#include "Errors.h"
#include "Stream.h"
#include "Bitmap.h"
#define LIQUID_ANIM_MAX 64
/*########################################################################################################################*
@@ -142,7 +143,7 @@ struct AnimationData {
Int16 Tick, TickDelay;
};
struct Bitmap anims_bmp;
Bitmap anims_bmp;
struct AnimationData anims_list[ATLAS1D_MAX_ATLASES];
Int32 anims_count;
bool anims_validated, anims_useLavaAnim, anims_useWaterAnim;
@@ -215,7 +216,7 @@ static void Animations_Draw(struct AnimationData* data, TextureLoc texLoc, Int32
Int32 index_1D = Atlas1D_Index(texLoc);
Int32 rowId_1D = Atlas1D_RowId(texLoc);
struct Bitmap animPart; Bitmap_Create(&animPart, size, size, buffer);
Bitmap animPart; Bitmap_Create(&animPart, size, size, buffer);
if (!data) {
if (texLoc == 30) {
View
@@ -2,7 +2,6 @@
#define CC_ASYNCDOWNLOADER_H
#include "Constants.h"
#include "Utils.h"
#include "Bitmap.h"
/* Downloads images, texture packs, skins, etc in async manner.
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
*/
View
@@ -7,11 +7,11 @@
#include "Stream.h"
#include "Errors.h"
void Bitmap_Create(struct Bitmap* bmp, Int32 width, Int32 height, UInt8* scan0) {
void Bitmap_Create(Bitmap* bmp, Int32 width, Int32 height, UInt8* scan0) {
bmp->Width = width; bmp->Height = height; bmp->Scan0 = scan0;
}
void Bitmap_CopyBlock(Int32 srcX, Int32 srcY, Int32 dstX, Int32 dstY, struct Bitmap* src, struct Bitmap* dst, Int32 size) {
void Bitmap_CopyBlock(Int32 srcX, Int32 srcY, Int32 dstX, Int32 dstY, Bitmap* src, Bitmap* dst, Int32 size) {
Int32 x, y;
for (y = 0; y < size; y++) {
UInt32* srcRow = Bitmap_GetRow(src, srcY + y);
@@ -22,12 +22,12 @@ void Bitmap_CopyBlock(Int32 srcX, Int32 srcY, Int32 dstX, Int32 dstY, struct Bit
}
}
void Bitmap_Allocate(struct Bitmap* bmp, Int32 width, Int32 height) {
void Bitmap_Allocate(Bitmap* bmp, Int32 width, Int32 height) {
bmp->Width = width; bmp->Height = height;
bmp->Scan0 = Mem_Alloc(width * height, BITMAP_SIZEOF_PIXEL, "bitmap data");
}
void Bitmap_AllocateClearedPow2(struct Bitmap* bmp, Int32 width, Int32 height) {
void Bitmap_AllocateClearedPow2(Bitmap* bmp, Int32 width, Int32 height) {
width = Math_NextPowOf2(width);
height = Math_NextPowOf2(height);
@@ -308,7 +308,7 @@ Png_RowExpander Png_GetExpander(UInt8 col, UInt8 bitsPerSample) {
return NULL;
}
static void Png_ComputeTransparency(struct Bitmap* bmp, UInt32 transparentCol) {
static void Png_ComputeTransparency(Bitmap* bmp, UInt32 transparentCol) {
UInt32 trnsRGB = transparentCol & PNG_RGB_MASK;
Int32 x, y, width = bmp->Width, height = bmp->Height;
@@ -324,7 +324,7 @@ static void Png_ComputeTransparency(struct Bitmap* bmp, UInt32 transparentCol) {
/* Most bits per sample is 16. Most samples per pixel is 4. Add 1 for filter byte. */
#define PNG_BUFFER_SIZE ((PNG_MAX_DIMS * 2 * 4 + 1) * 2)
/* TODO: Test a lot of .png files and ensure output is right */
ReturnCode Bitmap_DecodePng(struct Bitmap* bmp, struct Stream* stream) {
ReturnCode Bitmap_DecodePng(Bitmap* bmp, struct Stream* stream) {
Bitmap_Create(bmp, 0, 0, NULL);
UInt8 tmp[PNG_PALETTE * 3];
ReturnCode res;
@@ -607,7 +607,7 @@ static void Png_EncodeRow(UInt8* src, UInt8* cur, UInt8* prior, UInt8* best, Int
best[0] = bestFilter;
}
ReturnCode Bitmap_EncodePng(struct Bitmap* bmp, struct Stream* stream) {
ReturnCode Bitmap_EncodePng(Bitmap* bmp, struct Stream* stream) {
ReturnCode res;
UInt8 tmp[32];
if ((res = Stream_Write(stream, png_sig, PNG_SIG_SIZE))) return res;
View
@@ -5,27 +5,26 @@
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
*/
struct Stream;
struct Bitmap { UInt8* Scan0; Int32 Width, Height; };
#define PNG_MAX_DIMS 0x8000L
#define BITMAP_SIZEOF_PIXEL 4 /* 32 bit ARGB */
#define Bitmap_DataSize(width, height) ((UInt32)(width) * (UInt32)(height) * (UInt32)BITMAP_SIZEOF_PIXEL)
#define Bitmap_GetRow(bmp, y) ((UInt32*)((bmp)->Scan0 + ((y) * ((bmp)->Width << 2))))
#define Bitmap_GetPixel(bmp, x, y) (Bitmap_GetRow(bmp, y)[x])
void Bitmap_Create(struct Bitmap* bmp, Int32 width, Int32 height, UInt8* scan0);
void Bitmap_CopyBlock(Int32 srcX, Int32 srcY, Int32 dstX, Int32 dstY, struct Bitmap* src, struct Bitmap* dst, Int32 size);
void Bitmap_Create(Bitmap* bmp, Int32 width, Int32 height, UInt8* scan0);
void Bitmap_CopyBlock(Int32 srcX, Int32 srcY, Int32 dstX, Int32 dstY, Bitmap* src, Bitmap* dst, Int32 size);
/* Allocates a new bitmap of the given dimensions. You are responsible for freeing its memory! */
void Bitmap_Allocate(struct Bitmap* bmp, Int32 width, Int32 height);
void Bitmap_Allocate(Bitmap* bmp, Int32 width, Int32 height);
/* Allocates a power-of-2 sized bitmap larger or equal to to the given size, and clears it to 0. You are responsible for freeing its memory! */
void Bitmap_AllocateClearedPow2(struct Bitmap* bmp, Int32 width, Int32 height);
void Bitmap_AllocateClearedPow2(Bitmap* bmp, Int32 width, Int32 height);
bool Bitmap_DetectPng(UInt8* data, UInt32 len);
/*
Partially based off information from
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
*/
ReturnCode Bitmap_DecodePng(struct Bitmap* bmp, struct Stream* stream);
ReturnCode Bitmap_EncodePng(struct Bitmap* bmp, struct Stream* stream);
ReturnCode Bitmap_DecodePng(Bitmap* bmp, struct Stream* stream);
ReturnCode Bitmap_EncodePng(Bitmap* bmp, struct Stream* stream);
#endif
View
@@ -7,6 +7,7 @@
#include "Inventory.h"
#include "Event.h"
#include "Platform.h"
#include "Bitmap.h"
const char* Sound_Names[SOUND_COUNT] = {
"none", "wood", "gravel", "grass", "stone",
@@ -275,7 +276,7 @@ void Block_RecalculateSpriteBB(void) {
}
}
static Real32 Block_GetSpriteBB_MinX(Int32 size, Int32 tileX, Int32 tileY, struct Bitmap* bmp) {
static Real32 Block_GetSpriteBB_MinX(Int32 size, Int32 tileX, Int32 tileY, Bitmap* bmp) {
Int32 x, y;
for (x = 0; x < size; x++) {
for (y = 0; y < size; y++) {
@@ -288,7 +289,7 @@ static Real32 Block_GetSpriteBB_MinX(Int32 size, Int32 tileX, Int32 tileY, struc
return 1.0f;
}
static Real32 Block_GetSpriteBB_MinY(Int32 size, Int32 tileX, Int32 tileY, struct Bitmap* bmp) {
static Real32 Block_GetSpriteBB_MinY(Int32 size, Int32 tileX, Int32 tileY, Bitmap* bmp) {
Int32 x, y;
for (y = size - 1; y >= 0; y--) {
UInt32* row = Bitmap_GetRow(bmp, tileY * size + y) + (tileX * size);
@@ -301,7 +302,7 @@ static Real32 Block_GetSpriteBB_MinY(Int32 size, Int32 tileX, Int32 tileY, struc
return 1.0f;
}
static Real32 Block_GetSpriteBB_MaxX(Int32 size, Int32 tileX, Int32 tileY, struct Bitmap* bmp) {
static Real32 Block_GetSpriteBB_MaxX(Int32 size, Int32 tileX, Int32 tileY, Bitmap* bmp) {
Int32 x, y;
for (x = size - 1; x >= 0; x--) {
for (y = 0; y < size; y++) {
@@ -314,7 +315,7 @@ static Real32 Block_GetSpriteBB_MaxX(Int32 size, Int32 tileX, Int32 tileY, struc
return 0.0f;
}
static Real32 Block_GetSpriteBB_MaxY(Int32 size, Int32 tileX, Int32 tileY, struct Bitmap* bmp) {
static Real32 Block_GetSpriteBB_MaxY(Int32 size, Int32 tileX, Int32 tileY, Bitmap* bmp) {
Int32 x, y;
for (y = 0; y < size; y++) {
UInt32* row = Bitmap_GetRow(bmp, tileY * size + y) + (tileX * size);
@@ -328,7 +329,7 @@ static Real32 Block_GetSpriteBB_MaxY(Int32 size, Int32 tileX, Int32 tileY, struc
}
void Block_RecalculateBB(BlockID block) {
struct Bitmap* bmp = &Atlas2D_Bitmap;
Bitmap* bmp = &Atlas2D_Bitmap;
Int32 tileSize = Atlas2D_TileSize;
TextureLoc texLoc = Block_GetTexLoc(block, FACE_XMAX);
Int32 x = Atlas2D_TileX(texLoc), y = Atlas2D_TileY(texLoc);
View
@@ -34,20 +34,20 @@ static void PerspectiveCamera_GetPickedBlock(struct PickedPos* pos) {
Picking_CalculatePickedBlock(eyePos, dir, reach, pos);
}
struct Point2D cam_prev, cam_delta;
Point2D cam_prev, cam_delta;
static void PerspectiveCamera_CentreMousePosition(void) {
struct Point2D topLeft = Window_PointToScreen(Point2D_Empty);
Point2D topLeft = Window_PointToScreen(0, 0);
Int32 cenX = topLeft.X + Game_Width / 2;
Int32 cenY = topLeft.Y + Game_Height / 2;
Window_SetDesktopCursorPos(Point2D_Make(cenX, cenY));
Window_SetDesktopCursorPos(cenX, cenY);
/* Fixes issues with large DPI displays on Windows >= 8.0. */
cam_prev = Window_GetDesktopCursorPos();
}
static void PerspectiveCamera_RegrabMouse(void) {
if (!Window_Exists) return;
cam_delta = Point2D_Empty;
cam_delta.X = 0; cam_delta.Y = 0;
PerspectiveCamera_CentreMousePosition();
}
@@ -99,10 +99,10 @@ static void PerspectiveCamera_UpdateMouseRotation(void) {
static void PerspectiveCamera_UpdateMouse(void) {
struct Screen* screen = Gui_GetActiveScreen();
if (screen->HandlesAllInput) {
cam_delta = Point2D_Empty;
cam_delta.X = 0; cam_delta.Y = 0;
} else if (Window_Focused) {
struct Point2D pos = Window_GetDesktopCursorPos();
cam_delta = Point2D_Make(pos.X - cam_prev.X, pos.Y - cam_prev.Y);
Point2D pos = Window_GetDesktopCursorPos();
cam_delta.X = pos.X - cam_prev.X; cam_delta.Y = pos.Y - cam_prev.Y;
PerspectiveCamera_CentreMousePosition();
}
PerspectiveCamera_UpdateMouseRotation();
View
@@ -389,8 +389,7 @@ static void ResolutionCommand_Execute(STRING_PURE String* args, Int32 argsCount)
} else if (width <= 0 || height <= 0) {
Chat_AddRaw("&e/client: &cWidth and height must be above 0.");
} else {
struct Size2D size = { width, height };
Window_SetClientSize(size);
Window_SetClientSize(width, height);
Options_SetInt(OPT_WINDOW_WIDTH, width);
Options_SetInt(OPT_WINDOW_HEIGHT, height);
}
View
@@ -187,7 +187,6 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="2DStructs.h" />
<ClInclude Include="AsyncDownloader.h" />
<ClInclude Include="Audio.h" />
<ClInclude Include="AxisLinesRenderer.h" />
@@ -255,7 +254,6 @@
<ClInclude Include="World.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="2DStructs.c" />
<ClCompile Include="AsyncDownloader.c" />
<ClCompile Include="Audio.c" />
<ClCompile Include="Camera.c" />
@@ -19,9 +19,6 @@
<Filter Include="Header Files\Generator">
<UniqueIdentifier>{6acee9ab-36de-4f0d-b434-b915b4b52c02}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Defines">
<UniqueIdentifier>{405d40c2-3d05-4d42-8ccb-415189b379a4}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Platform">
<UniqueIdentifier>{eab38ecc-57ac-48f4-9ed2-7cbd40effb24}</UniqueIdentifier>
</Filter>
@@ -216,12 +213,6 @@
<ClInclude Include="MapRenderer.h">
<Filter>Header Files\Rendering\Map</Filter>
</ClInclude>
<ClInclude Include="Constants.h">
<Filter>Header Files\Defines</Filter>
</ClInclude>
<ClInclude Include="2DStructs.h">
<Filter>Header Files\2D\Utils</Filter>
</ClInclude>
<ClInclude Include="MapGenerator.h">
<Filter>Header Files\Generator</Filter>
</ClInclude>
@@ -336,12 +327,15 @@
<ClInclude Include="Errors.h">
<Filter>Header Files\Utils</Filter>
</ClInclude>
<ClInclude Include="Core.h">
<Filter>Header Files\Defines</Filter>
</ClInclude>
<ClInclude Include="Model.h">
<Filter>Header Files\Entities\Model</Filter>
</ClInclude>
<ClInclude Include="Constants.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Core.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="String.c">
@@ -386,9 +380,6 @@
<ClCompile Include="MapRenderer.c">
<Filter>Source Files\Rendering\Map</Filter>
</ClCompile>
<ClCompile Include="2DStructs.c">
<Filter>Source Files\2D\Utils</Filter>
</ClCompile>
<ClCompile Include="AxisLinesRenderer.c">
<Filter>Source Files\SelectionBox</Filter>
</ClCompile>
View
@@ -47,14 +47,14 @@
/* Number of faces on a cube. */
#define FACE_COUNT 6
#define SKIN_TYPE_64x32 0
#define SKIN_TYPE_64x64 1
#define SKIN_TYPE_64x64_SLIM 2
#define SKIN_TYPE_INVALID 3
#define FONT_STYLE_NORMAL 0
#define FONT_STYLE_BOLD 1
#define FONT_STYLE_UNDERLINE 2
enum SKIN_TYPE { SKIN_64x32, SKIN_64x64, SKIN_64x64_SLIM, SKIN_INVALID };
enum FONT_STYLE { FONT_STYLE_NORMAL, FONT_STYLE_BOLD, FONT_STYLE_UNDERLINE };
#define DRAWER2D_MAX_COLS 256
#define UInt8_MaxValue ((UInt8)255)
#define Int16_MinValue ((Int16)-32768)
#define Int16_MaxValue ((Int16)32767)
#define UInt16_MaxValue ((UInt16)65535)
#define Int32_MinValue ((Int32)-2147483647L - (Int32)1L)
#define Int32_MaxValue ((Int32)2147483647L)
#endif
View
@@ -1,6 +1,6 @@
#ifndef CC_TYPEDEFS_H
#define CC_TYPEDEFS_H
/* Ensures variables are of a fixed size.
#ifndef CC_CORE_H
#define CC_CORE_H
/* Core fixed-size integer and floating point types, and common small structs.
Copyright 2017 ClassicalSharp | Licensed under BSD-3
*/
@@ -49,15 +49,12 @@ typedef UInt16 TextureLoc;
typedef UInt8 Face;
typedef UInt32 ReturnCode;
struct FontDesc { void* Handle; UInt16 Size, Style; };
#define UInt8_MaxValue ((UInt8)255)
#define Int16_MinValue ((Int16)-32768)
#define Int16_MaxValue ((Int16)32767)
#define UInt16_MaxValue ((UInt16)65535)
#define Int32_MinValue ((Int32)-2147483647L - (Int32)1L)
#define Int32_MaxValue ((Int32)2147483647L)
#define UInt32_MaxValue ((UInt32)4294967295UL)
typedef struct Rect2D_ { Int32 X, Y, Width, Height; } Rect2D;
typedef struct Point2D_ { Int32 X, Y; } Point2D;
typedef struct Size2D_ { Int32 Width, Height; } Size2D;
typedef struct FontDesc_ { void* Handle; UInt16 Size, Style; } FontDesc;
typedef struct TextureRec_ { Real32 U1, V1, U2, V2; } TextureRec;
typedef struct Bitmap_ { UInt8* Scan0; Int32 Width, Height; } Bitmap;
#define CC_BUILD_GL11 false
#define CC_BUILD_D3D9 true
Oops, something went wrong.

0 comments on commit 6eb08b7

Please sign in to comment.