use const in a few more places, reduce some compiler warnings

This commit is contained in:
UnknownShadow200 2019-03-06 23:27:48 +11:00
parent ef21348fff
commit ae9eb607a9
9 changed files with 35 additions and 15 deletions

View File

@ -11,6 +11,7 @@ struct LScreen;
typedef void (*LScreen_Func)(struct LScreen* s);
typedef void(*LWidget_Func)(struct LScreen* s, struct LWidget* w);
#ifndef CC_BUILD_WEB
#define LScreen_Layout \
LScreen_Func Init; /* Initialises widgets and other data. */ \
@ -45,3 +46,4 @@ struct LScreen* ServersScreen_MakeInstance(void);
struct LScreen* SettingsScreen_MakeInstance(void);
struct LScreen* UpdatesScreen_MakeInstance(void);
#endif
#endif

View File

@ -9,6 +9,7 @@
struct JsonContext;
typedef void (*JsonOnValue)(struct JsonContext* ctx, const String* v);
typedef void (*JsonOnNew)(struct JsonContext* ctx);
#ifndef CC_BUILD_WEB
/* State for parsing JSON text */
struct JsonContext {
@ -118,3 +119,4 @@ Bitmap* Flags_Get(const String* name);
/* Frees all flag bitmaps. */
void Flags_Free(void);
#endif
#endif

View File

@ -7,6 +7,7 @@
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
*/
#ifndef CC_BUILD_WEB
struct LWidgetVTABLE {
/* Called to draw contents of this widget */
void (*Draw)(void* widget);
@ -193,3 +194,4 @@ void LTable_Sort(struct LTable* table);
/* If selected row is not visible, adjusts top row so it does show. */
void LTable_ShowSelected(struct LTable* table);
#endif
#endif

View File

@ -7,6 +7,7 @@
*/
struct LScreen;
#ifndef CC_BUILD_WEB
/* Currently active screen/menu. */
extern struct LScreen* Launcher_Screen;
/* The area/region of the window that needs to be redrawn and presented to the screen. */
@ -70,3 +71,4 @@ void Launcher_Run(void);
/* Starts the game from the given arguments. */
bool Launcher_StartGame(const String* user, const String* mppass, const String* ip, const String* port, const String* server);
#endif
#endif

View File

@ -1236,25 +1236,22 @@ static void* FT_ReallocWrapper(FT_Memory memory, long cur_size, long new_size, v
#define FONT_CACHE_FILE "fontscache.txt"
static void Font_Init(void) {
#ifdef CC_BUILD_WIN
#if defined CC_BUILD_WIN
const static String dirs[2] = {
String_FromConst("C:/Windows/Fonts"),
String_FromConst("C:/WINNT/Fonts")
};
#endif
#ifdef CC_BUILD_UNIX
#elif defined CC_BUILD_UNIX
const static String dirs[2] = {
String_FromConst("/usr/share/fonts"),
String_FromConst("/usr/local/share/fonts")
};
#endif
#ifdef CC_BUILD_OSX
#elif defined CC_BUILD_OSX
const static String dirs[2] = {
String_FromConst("/System/Library/Fonts"),
String_FromConst("/Library/Fonts")
};
#endif
#ifdef CC_BUILD_WEB
#elif defined CC_BUILD_WEB
/* TODO: Implement fonts */
const static String dirs[1] = { String_FromConst("Fonts") };
#endif
@ -1304,10 +1301,15 @@ ReturnCode Socket_Available(SocketHandle socket, uint32_t* available) {
return Socket_ioctl(socket, FIONREAD, available);
}
ReturnCode Socket_SetBlocking(SocketHandle socket, bool blocking) {
#ifdef CC_BUILD_WEB
return ReturnCode_NotSupported; /* sockets always async */
#else
int blocking_raw = blocking ? 0 : -1;
return Socket_ioctl(socket, FIONBIO, &blocking_raw);
#endif
}
ReturnCode Socket_GetError(SocketHandle socket, ReturnCode* result) {
int resultSize = sizeof(ReturnCode);
return getsockopt(socket, SOL_SOCKET, SO_ERROR, result, &resultSize);
@ -1341,7 +1343,9 @@ ReturnCode Socket_Close(SocketHandle socket) {
ReturnCode res = 0;
ReturnCode res1, res2;
#ifdef CC_BUILD_WIN
#if defined CC_BUILD_WEB
res1 = 0;
#elif defined CC_BUILD_WIN
res1 = shutdown(socket, SD_BOTH);
#else
res1 = shutdown(socket, SHUT_RDWR);

View File

@ -65,6 +65,7 @@ static void Program_RunGame(void) {
/* Attempts to set current/working directory to the directory exe file is in */
static void Program_SetCurrentDirectory(void) {
#ifndef CC_BUILD_WEB
String path; char pathBuffer[FILENAME_SIZE];
int i;
ReturnCode res;
@ -79,6 +80,7 @@ static void Program_SetCurrentDirectory(void) {
}
res = Platform_SetCurrentDirectory(&path);
if (res) { Logger_Warn(res, "setting current directory"); return; }
#endif
}
/* Terminates the program due to an invalid command line argument */
@ -137,7 +139,12 @@ int main(int argc, char** argv) {
/* argsCount = String_UNSAFE_Split(&rawArgs, ' ', args, 4); */
if (argsCount == 0) {
#ifdef CC_BUILD_WEB
String_AppendConst(&Game_Username, "WebTest!");
Program_RunGame();
#else
Launcher_Run();
#endif
} else if (argsCount == 1) {
String_Copy(&Game_Username, &args[0]);
Program_RunGame();

View File

@ -10,6 +10,7 @@
#define FLAG_GUI 0x04 /* file depends on patched gui.png */
#define FLAG_TERRAIN 0x08 /* file depends on patched terrain.png */
#ifndef CC_BUILD_WEB
extern struct ResourceFile {
const char* Name;
const char* Url;
@ -64,5 +65,5 @@ void Fetcher_Run(void);
/* Checks if any resources have finished downloading. */
/* If any have, performs required patching and saving. */
void Fetcher_Update(void);
#endif
#endif

View File

@ -561,7 +561,7 @@ int Convert_UnicodeToUtf8(Codepoint cp, uint8_t* data) {
}
}
void Convert_DecodeUtf16(String* value, Codepoint* chars, int numBytes) {
void Convert_DecodeUtf16(String* value, const Codepoint* chars, int numBytes) {
int i; char c;
for (i = 0; i < (numBytes >> 1); i++) {
@ -569,7 +569,7 @@ void Convert_DecodeUtf16(String* value, Codepoint* chars, int numBytes) {
}
}
void Convert_DecodeUtf8(String* value, uint8_t* chars, int numBytes) {
void Convert_DecodeUtf8(String* value, const uint8_t* chars, int numBytes) {
int len; Codepoint cp; char c;
for (; numBytes > 0; numBytes -= len) {
@ -581,7 +581,7 @@ void Convert_DecodeUtf8(String* value, uint8_t* chars, int numBytes) {
}
}
void Convert_DecodeAscii(String* value, uint8_t* chars, int numBytes) {
void Convert_DecodeAscii(String* value, const uint8_t* chars, int numBytes) {
int i; char c;
for (i = 0; i < numBytes; i++) {

View File

@ -171,13 +171,13 @@ int Convert_UnicodeToUtf8(Codepoint cp, uint8_t* data);
/* Attempts to append all characters from UTF16 encoded data to the given string. */
/* Characters not in code page 437 are omitted. */
void Convert_DecodeUtf16(String* str, Codepoint* chars, int numBytes);
void Convert_DecodeUtf16(String* str, const Codepoint* chars, int numBytes);
/* Attempts to append all characters from UTF8 encoded data to the given string. */
/* Characters not in code page 437 are omitted. */
void Convert_DecodeUtf8(String* str, uint8_t* chars, int numBytes);
void Convert_DecodeUtf8(String* str, const uint8_t* chars, int numBytes);
/* Attempts to append all characters from ASCII encoded data to the given string. */
/* Characters not in code page 437 are omitted. */
void Convert_DecodeAscii(String* str, uint8_t* chars, int numBytes);
void Convert_DecodeAscii(String* str, const uint8_t* chars, int numBytes);
/* Attempts to convert the given string into an unsigned 8 bit integer. */
CC_API bool Convert_ParseUInt8(const String* str, uint8_t* value);