Skip to content
Permalink
Browse files

less compile errors as C++

  • Loading branch information...
UnknownShadow200 committed May 16, 2019
1 parent 63ab591 commit a154f617b3cada782f6a3aabc211fb2d670fe58e
Showing with 131 additions and 131 deletions.
  1. +12 −12 src/Audio.c
  2. +3 −3 src/Bitmap.c
  3. +1 −1 src/Block.c
  4. +1 −1 src/Builder.c
  5. +8 −8 src/Deflate.c
  6. +2 −2 src/Generator.c
  7. +27 −27 src/Input.c
  8. +11 −11 src/Input.h
  9. +11 −11 src/LWidgets.c
  10. +1 −1 src/Lighting.c
  11. +26 −26 src/Menus.c
  12. +19 −19 src/Platform.c
  13. +5 −5 src/TexturePack.c
  14. +1 −1 src/TexturePack.h
  15. +3 −3 src/Vorbis.c
@@ -431,7 +431,7 @@ ReturnCode Audio_StopAndClose(AudioHandle handle) {
*#########################################################################################################################*/
struct Sound {
struct AudioFormat Format;
uint8_t* Data; uint32_t DataSize;
uint8_t* Data; uint32_t Size;
};

#define AUDIO_MAX_SOUNDS 10
@@ -475,8 +475,8 @@ static ReturnCode Sound_ReadWaveData(struct Stream* stream, struct Sound* snd) {
snd->Format.BitsPerSample = Stream_GetU16_LE(&tmp[14]);
size -= WAV_FMT_SIZE;
} else if (fourCC == WAV_FourCC('d','a','t','a')) {
snd->Data = Mem_Alloc(size, 1, "WAV sound data");
snd->DataSize = size;
snd->Data = (uint8_t*)Mem_Alloc(size, 1, "WAV sound data");
snd->Size = size;
return Stream_Read(stream, snd->Data, size);
}

@@ -553,8 +553,8 @@ static void Soundboard_Init(struct Soundboard* board, const String* boardName, S
if (res) {
Logger_Warn2(res, "decoding", &file);
Mem_Free(snd->Data);
snd->Data = NULL;
snd->DataSize = 0;
snd->Data = NULL;
snd->Size = 0;
} else { group->Count++; }
}
}
@@ -604,23 +604,23 @@ static void Sounds_PlayRaw(struct SoundOutput* output, struct Sound* snd, struct

/* copy to temp buffer to apply volume */
if (volume < 100) {
if (output->BufferSize < snd->DataSize) {
expandBy = snd->DataSize - output->BufferSize;
if (output->BufferSize < snd->Size) {
expandBy = snd->Size - output->BufferSize;
output->Buffer = Utils_Resize(output->Buffer, &output->BufferSize,
1, AUDIO_DEF_ELEMS, expandBy);
}
data = output->Buffer;

Mem_Copy(data, snd->Data, snd->DataSize);
Mem_Copy(data, snd->Data, snd->Size);
if (fmt->BitsPerSample == 8) {
Volume_Mix8(data, snd->DataSize, volume);
Volume_Mix8((uint8_t*)data, snd->Size, volume);
} else {
Volume_Mix16(data, snd->DataSize / 2, volume);
Volume_Mix16((int16_t*)data, snd->Size / 2, volume);
}
}

if ((res = Audio_BufferData(output->Handle, 0, data, snd->DataSize))) { Sounds_Fail(res); return; }
if ((res = Audio_Play(output->Handle))) { Sounds_Fail(res); return; }
if ((res = Audio_BufferData(output->Handle, 0, data, snd->Size))) { Sounds_Fail(res); return; }
if ((res = Audio_Play(output->Handle))) { Sounds_Fail(res); return; }
}

static void Sounds_Play(uint8_t type, struct Soundboard* board) {
@@ -26,15 +26,15 @@ void Bitmap_CopyBlock(int srcX, int srcY, int dstX, int dstY, Bitmap* src, Bitma

void Bitmap_Allocate(Bitmap* bmp, int width, int height) {
bmp->Width = width; bmp->Height = height;
bmp->Scan0 = Mem_Alloc(width * height, 4, "bitmap data");
bmp->Scan0 = (uint8_t*)Mem_Alloc(width * height, 4, "bitmap data");
}

void Bitmap_AllocateClearedPow2(Bitmap* bmp, int width, int height) {
width = Math_NextPowOf2(width);
height = Math_NextPowOf2(height);

bmp->Width = width; bmp->Height = height;
bmp->Scan0 = Mem_AllocCleared(width * height, 4, "bitmap data");
bmp->Scan0 = (uint8_t*)Mem_AllocCleared(width * height, 4, "bitmap data");
}


@@ -376,7 +376,7 @@ ReturnCode Png_Decode(Bitmap* bmp, struct Stream* stream) {
if (bmp->Width < 0 || bmp->Width > PNG_MAX_DIMS) return PNG_ERR_TOO_WIDE;
if (bmp->Height < 0 || bmp->Height > PNG_MAX_DIMS) return PNG_ERR_TOO_TALL;

bmp->Scan0 = Mem_Alloc(bmp->Width * bmp->Height, 4, "PNG bitmap data");
bmp->Scan0 = (uint8_t*)Mem_Alloc(bmp->Width * bmp->Height, 4, "PNG bitmap data");
bitsPerSample = tmp[8]; col = tmp[9];
rowExpander = Png_GetExpander(col, bitsPerSample);
if (rowExpander == NULL) return PNG_ERR_INVALID_COL_BPP;
@@ -400,7 +400,7 @@ static float Block_GetSpriteBB_MaxY(int size, int tileX, int tileY, const Bitmap
}

void Block_RecalculateBB(BlockID block) {
Bitmap* bmp = &Atlas2D.Bitmap;
Bitmap* bmp = &Atlas2D.Bmp;
int tileSize = Atlas2D.TileSize;
TextureLoc texLoc = Block_Tex(block, FACE_XMAX);
int x = Atlas2D_TileX(texLoc), y = Atlas2D_TileY(texLoc);
@@ -443,7 +443,7 @@ static void Builder_DefaultPostStretchTiles(int x1, int y1, int z1) {
if (vertsCount > Builder_VerticesElems) {
Mem_Free(Builder_Vertices);
/* ensure buffer can be accessed with 64 bytes alignment by putting 2 extra vertices at end. */
Builder_Vertices = Mem_Alloc(vertsCount + 2, sizeof(VertexP3fT2fC4b), "chunk vertices");
Builder_Vertices = (VertexP3fT2fC4b*)Mem_Alloc(vertsCount + 2, sizeof(VertexP3fT2fC4b), "chunk vertices");
Builder_VerticesElems = vertsCount;
}

@@ -928,7 +928,7 @@ static ReturnCode Deflate_StreamWrite(struct Stream* stream, const uint8_t* data
struct DeflateState* state;
ReturnCode res;

state = stream->Meta.Inflate;
state = (struct DeflateState*)stream->Meta.Inflate;
*modified = 0;

while (total > 0) {
@@ -957,7 +957,7 @@ static ReturnCode Deflate_StreamClose(struct Stream* stream) {
struct DeflateState* state;
ReturnCode res;

state = stream->Meta.Inflate;
state = (struct DeflateState*)stream->Meta.Inflate;
res = Deflate_FlushBlock(state, state->InputPosition - DEFLATE_BLOCK_SIZE);
if (res) return res;

@@ -1019,8 +1019,8 @@ void Deflate_MakeStream(struct Stream* stream, struct DeflateState* state, struc
*-----------------------------------------------------GZip (compress)-----------------------------------------------------*
*#########################################################################################################################*/
static ReturnCode GZip_StreamClose(struct Stream* stream) {
struct GZipState* state = (struct GZipState*)stream->Meta.Inflate;
uint8_t data[8];
struct GZipState* state = stream->Meta.Inflate;
ReturnCode res;

if ((res = Deflate_StreamClose(stream))) return res;
@@ -1030,7 +1030,7 @@ static ReturnCode GZip_StreamClose(struct Stream* stream) {
}

static ReturnCode GZip_StreamWrite(struct Stream* stream, const uint8_t* data, uint32_t count, uint32_t* modified) {
struct GZipState* state = stream->Meta.Inflate;
struct GZipState* state = (struct GZipState*)stream->Meta.Inflate;
uint32_t i, crc32 = state->Crc32;
state->Size += count;

@@ -1045,7 +1045,7 @@ static ReturnCode GZip_StreamWrite(struct Stream* stream, const uint8_t* data, u

static ReturnCode GZip_StreamWriteFirst(struct Stream* stream, const uint8_t* data, uint32_t count, uint32_t* modified) {
static uint8_t header[10] = { 0x1F, 0x8B, 0x08 }; /* GZip header */
struct GZipState* state = stream->Meta.Inflate;
struct GZipState* state = (struct GZipState*)stream->Meta.Inflate;
ReturnCode res;

if ((res = Stream_Write(state->Base.Dest, header, sizeof(header)))) return res;
@@ -1066,8 +1066,8 @@ void GZip_MakeStream(struct Stream* stream, struct GZipState* state, struct Stre
*-----------------------------------------------------ZLib (compress)-----------------------------------------------------*
*#########################################################################################################################*/
static ReturnCode ZLib_StreamClose(struct Stream* stream) {
struct ZLibState* state = (struct ZLibState*)stream->Meta.Inflate;
uint8_t data[4];
struct ZLibState* state = stream->Meta.Inflate;
ReturnCode res;

if ((res = Deflate_StreamClose(stream))) return res;
@@ -1076,7 +1076,7 @@ static ReturnCode ZLib_StreamClose(struct Stream* stream) {
}

static ReturnCode ZLib_StreamWrite(struct Stream* stream, const uint8_t* data, uint32_t count, uint32_t* modified) {
struct ZLibState* state = stream->Meta.Inflate;
struct ZLibState* state = (struct ZLibState*)stream->Meta.Inflate;
uint32_t i, adler32 = state->Adler32;
uint32_t s1 = adler32 & 0xFFFF, s2 = (adler32 >> 16) & 0xFFFF;

@@ -1093,7 +1093,7 @@ static ReturnCode ZLib_StreamWrite(struct Stream* stream, const uint8_t* data, u

static ReturnCode ZLib_StreamWriteFirst(struct Stream* stream, const uint8_t* data, uint32_t count, uint32_t* modified) {
static uint8_t header[2] = { 0x78, 0x9C }; /* ZLib header */
struct ZLibState* state = stream->Meta.Inflate;
struct ZLibState* state = (struct ZLibState*)stream->Meta.Inflate;
ReturnCode res;

if ((res = Stream_Write(state->Base.Dest, header, sizeof(header)))) return res;
@@ -17,7 +17,7 @@ static void Gen_Init(void) {
Gen_CurrentProgress = 0.0f;
Gen_CurrentState = "";

Gen_Blocks = Mem_Alloc(World.Volume, 1, "map blocks for gen");
Gen_Blocks = (BlockRaw*)Mem_Alloc(World.Volume, 1, "map blocks for gen");
Gen_Done = false;
}

@@ -609,7 +609,7 @@ static void NotchyGen_PlantTrees(void) {

void NotchyGen_Generate(void) {
Gen_Init();
Heightmap = Mem_Alloc(World.Width * World.Length, 2, "gen heightmap");
Heightmap = (int16_t*)Mem_Alloc(World.Width * World.Length, 2, "gen heightmap");

Random_Seed(&rnd, Gen_Seed);
waterLevel = World.Height / 2;
@@ -233,10 +233,10 @@ static void Hotkeys_QuickSort(int left, int right) {
}
}

static void Hotkeys_AddNewHotkey(Key trigger, uint8_t flags, const String* text, bool more) {
static void Hotkeys_AddNewHotkey(Key trigger, uint8_t modifiers, const String* text, bool more) {
struct HotkeyData hKey;
hKey.Trigger = trigger;
hKey.Flags = flags;
hKey.Flags = modifiers;
hKey.TextIndex = HotkeysText.Count;
hKey.StaysOpen = more;

@@ -262,29 +262,29 @@ static void Hotkeys_RemoveText(int index) {
}


void Hotkeys_Add(Key trigger, HotkeyFlags flags, const String* text, bool more) {
struct HotkeyData* hKey = HotkeysList;
void Hotkeys_Add(Key trigger, uint8_t modifiers, const String* text, bool more) {
struct HotkeyData* hk = HotkeysList;
int i;

for (i = 0; i < HotkeysText.Count; i++, hKey++) {
if (hKey->Trigger != trigger || hKey->Flags != flags) continue;
Hotkeys_RemoveText(hKey->TextIndex);
for (i = 0; i < HotkeysText.Count; i++, hk++) {
if (hk->Trigger != trigger || hk->Flags != modifiers) continue;
Hotkeys_RemoveText(hk->TextIndex);

hKey->StaysOpen = more;
hKey->TextIndex = HotkeysText.Count;
hk->StaysOpen = more;
hk->TextIndex = HotkeysText.Count;
StringsBuffer_Add(&HotkeysText, text);
return;
}
Hotkeys_AddNewHotkey(trigger, flags, text, more);
Hotkeys_AddNewHotkey(trigger, modifiers, text, more);
}

bool Hotkeys_Remove(Key trigger, HotkeyFlags flags) {
struct HotkeyData* hKey = HotkeysList;
bool Hotkeys_Remove(Key trigger, uint8_t modifiers) {
struct HotkeyData* hk = HotkeysList;
int i, j;

for (i = 0; i < HotkeysText.Count; i++, hKey++) {
if (hKey->Trigger != trigger || hKey->Flags != flags) continue;
Hotkeys_RemoveText(hKey->TextIndex);
for (i = 0; i < HotkeysText.Count; i++, hk++) {
if (hk->Trigger != trigger || hk->Flags != modifiers) continue;
Hotkeys_RemoveText(hk->TextIndex);

for (j = i; j < HotkeysText.Count; j++) {
HotkeysList[j] = HotkeysList[j + 1];
@@ -295,17 +295,17 @@ bool Hotkeys_Remove(Key trigger, HotkeyFlags flags) {
}

int Hotkeys_FindPartial(Key key) {
struct HotkeyData hKey;
int i, flags = 0;
struct HotkeyData hk;
int i, modifiers = 0;

if (Key_IsControlPressed()) flags |= HOTKEY_FLAG_CTRL;
if (Key_IsShiftPressed()) flags |= HOTKEY_FLAG_SHIFT;
if (Key_IsAltPressed()) flags |= HOTKEY_FLAG_ALT;
if (Key_IsControlPressed()) modifiers |= HOTKEY_MOD_CTRL;
if (Key_IsShiftPressed()) modifiers |= HOTKEY_MOD_SHIFT;
if (Key_IsAltPressed()) modifiers |= HOTKEY_MOD_ALT;

for (i = 0; i < HotkeysText.Count; i++) {
hKey = HotkeysList[i];
/* e.g. if holding Ctrl and Shift, a hotkey with only Ctrl flags matches */
if ((hKey.Flags & flags) == hKey.Flags && hKey.Trigger == key) return i;
hk = HotkeysList[i];
/* e.g. if holding Ctrl and Shift, a hotkey with only Ctrl modifiers matches */
if ((hk.Flags & modifiers) == hk.Flags && hk.Trigger == key) return i;
}
return -1;
}
@@ -340,21 +340,21 @@ void Hotkeys_Init(void) {
}
}

void Hotkeys_UserRemovedHotkey(Key trigger, HotkeyFlags flags) {
void Hotkeys_UserRemovedHotkey(Key trigger, uint8_t modifiers) {
String key; char keyBuffer[STRING_SIZE];
String_InitArray(key, keyBuffer);

String_Format2(&key, "hotkey-%c&%i", Key_Names[trigger], &flags);
String_Format2(&key, "hotkey-%c&%b", Key_Names[trigger], &modifiers);
Options_SetString(&key, NULL);
}

void Hotkeys_UserAddedHotkey(Key trigger, HotkeyFlags flags, bool moreInput, const String* text) {
void Hotkeys_UserAddedHotkey(Key trigger, uint8_t modifiers, bool moreInput, const String* text) {
String key; char keyBuffer[STRING_SIZE];
String value; char valueBuffer[STRING_SIZE * 2];
String_InitArray(key, keyBuffer);
String_InitArray(value, valueBuffer);

String_Format2(&key, "hotkey-%c&%i", Key_Names[trigger], &flags);
String_Format2(&key, "hotkey-%c&%b", Key_Names[trigger], &modifiers);
String_Format2(&value, "%t&%s", &moreInput, text);
Options_SetString(&key, &value);
}
@@ -119,30 +119,30 @@ void KeyBind_Init(void);

extern const uint8_t Hotkeys_LWJGL[256];
struct HotkeyData {
int TextIndex; /* contents to copy directly into the input bar */
uint8_t Trigger; /* Member of Key enumeration */
uint8_t Flags; /* ctrl 1, shift 2, alt 4 */
bool StaysOpen; /* whether the user is able to enter further input */
int TextIndex; /* contents to copy directly into the input bar */
uint8_t Trigger; /* Member of Key enumeration */
uint8_t Flags; /* HotkeyModifiers bitflags */
bool StaysOpen; /* whether the user is able to enter further input */
};

#define HOTKEYS_MAX_COUNT 256
extern struct HotkeyData HotkeysList[HOTKEYS_MAX_COUNT];
extern StringsBuffer HotkeysText;
typedef enum HotkeyFlags_ {
HOTKEY_FLAG_CTRL = 1, HOTKEY_FLAG_SHIFT = 2, HOTKEY_FLAG_ALT = 4
} HotkeyFlags;
enum HotkeyModifiers {
HOTKEY_MOD_CTRL = 1, HOTKEY_MOD_SHIFT = 2, HOTKEY_MOD_ALT = 4
};

/* Adds or updates a new hotkey. */
void Hotkeys_Add(Key trigger, HotkeyFlags flags, const String* text, bool more);
void Hotkeys_Add(Key trigger, uint8_t modifiers, const String* text, bool more);
/* Removes the given hotkey. */
bool Hotkeys_Remove(Key trigger, HotkeyFlags flags);
bool Hotkeys_Remove(Key trigger, uint8_t modifiers);
/* Returns the first hotkey which is bound to the given key and has its modifiers pressed. */
/* NOTE: The hotkeys list is sorted, so hotkeys with most modifiers are checked first. */
int Hotkeys_FindPartial(Key key);
/* Initalises and loads hotkeys from options. */
void Hotkeys_Init(void);
/* Called when user has removed a hotkey. (removes it from options) */
void Hotkeys_UserRemovedHotkey(Key trigger, HotkeyFlags flags);
void Hotkeys_UserRemovedHotkey(Key trigger, uint8_t modifiers);
/* Called when user has added a hotkey. (Adds it to options) */
void Hotkeys_UserAddedHotkey(Key trigger, HotkeyFlags flags, bool moreInput, const String* text);
void Hotkeys_UserAddedHotkey(Key trigger, uint8_t modifiers, bool moreInput, const String* text);
#endif
Oops, something went wrong.

0 comments on commit a154f61

Please sign in to comment.
You can’t perform that action at this time.