Skip to content
Permalink
Browse files

make fields in resources structs lowercase

  • Loading branch information...
UnknownShadow200 committed Jul 8, 2019
1 parent d45b37d commit dccabb93c425a4d52344ca51d691a87e8c66bbe1
Showing with 231 additions and 108 deletions.
  1. +2 −1 src/Audio.c
  2. +1 −1 src/Core.h
  3. +1 −1 src/Gui.h
  4. +91 −0 src/Http.c
  5. +16 −23 src/Menus.c
  6. +15 −13 src/Platform.c
  7. +11 −2 src/Program.c
  8. +54 −54 src/Resources.c
  9. +13 −13 src/Resources.h
  10. +27 −0 src/Window.c
@@ -14,7 +14,8 @@

int Audio_SoundsVolume, Audio_MusicVolume;

#ifdef CC_BUILD_WEB
/* TODO: Fix for android */
#if defined CC_BUILD_WEB || defined CC_BUILD_ANDROID
/* Can't use mojang's sounds or music assets, so just stub everything out */
static void Audio_Init(void) { }
static void Audio_Free(void) { }
@@ -112,9 +112,9 @@ typedef struct TextureRec_ { float U1, V1, U2, V2; } TextureRec;
#define CC_BUILD_POSIX
#define CC_BUILD_GL
#define CC_BUILD_GLMODERN
#define CC_BUILD_LIBUNWIND
#define CC_BUILD_GLES
#define CC_BUILD_EGL
#define CC_BUILD_LIBUNWIND
#elif defined __linux__
#define CC_BUILD_LINUX
#define CC_BUILD_POSIX
@@ -12,7 +12,7 @@ enum GuiAnchor {
ANCHOR_CENTRE, /* = (axis/2) - (size/2) - offset; */
ANCHOR_MAX, /* = axis - size - offset */
ANCHOR_CENTRE_MIN, /* = (axis/2) + offset */
ANCHOR_CENTRE_MAX, /* = (axis/2) - size - offset */
ANCHOR_CENTRE_MAX /* = (axis/2) - size - offset */
};

struct IGameComponent;
@@ -720,6 +720,97 @@ static void Http_SysFree(void) {
curl_easy_cleanup(curl);
curl_global_cleanup();
}
#elif defined CC_BUILD_ANDROID
#include <android_native_app_glue.h>
#include "<jni.h>"

static void CallVoidJavaMethod(const char* name, const char* sig, ..) {
jmethodID method = env->GetStaticMethodID(clazz_algo, "init", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
}

bool Http_DescribeError(ReturnCode res, String* dst) {
jni
}

static void Http_SysInit(void) { }

static void Http_AddHeader(const char* key, const String* value) {
jni
}

/* Processes a HTTP header downloaded from the server */
static JNIEXPORT void JNICALL Java_com_classicube_Wrappers_httpParseHeader(JNIEnv* env, jlcass, jstring header) {
String line;
const char* src = (*env)->GetStringUTFChars(env, header, NULL);
jsize length = (*env)->GetStringLength(env, header);

line = String_Init(src, length, length);
Http_ParseHeader(req, &line);
(*env)->ReleaseStringUTFChars(env, src);
}

/* Processes a chunk of data downloaded from the web server */
static JNIEXPORT void JNICALL Java_com_classicube_Wrappers_httpAppendData(JNIEnv* env, jlcass, jbytearray arr, jint len) {
jbyte* src = (*env)->->GetByteArrayElements(env, NULL, 0);

if (!bufferSize) Http_BufferInit(req);
Http_BufferEnsure(req, len);

Mem_Copy(&req->Data[req->Size], src, len);
Http_BufferExpanded(req, len);
(*env)->ReleaseByteArrayElements(env, src, JNI_ABORT);
}

/* Sets general curl options for a request */
static void Http_SetCurlOpts(struct HttpRequest* req) {
curl_easy_setopt(curl, CURLOPT_USERAGENT, GAME_APP_NAME);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
}

static ReturnCode Http_SysDo(struct HttpRequest* req) {
String url = String_FromRawArray(req->URL);
char urlStr[600];
void* post_data = req->Data;
long status = 0;
CURLcode res;

curl_easy_reset(curl);
headers_list = NULL;
Http_SetRequestHeaders(req);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers_list);

Http_SetCurlOpts(req);
Platform_ConvertString(urlStr, &url);
curl_easy_setopt(curl, CURLOPT_URL, urlStr);

if (req->RequestType == REQUEST_TYPE_HEAD) {
curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
} else if (req->RequestType == REQUEST_TYPE_POST) {
curl_easy_setopt(curl, CURLOPT_POST, 1L);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, req->Size);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, req->Data);

/* per curl docs, we must persist POST data until request finishes */
req->Data = NULL;
HttpRequest_Free(req);
}

bufferSize = 0;
http_curProgress = ASYNC_PROGRESS_FETCHING_DATA;
res = curl_easy_perform(curl);
http_curProgress = 100;

/* non-obsolete is CURLINFO_RESPONSE_CODE */
curl_easy_getinfo(curl, CURLINFO_HTTP_CODE, &status);
req->StatusCode = status;

curl_slist_free_all(headers_list);
/* can free now that request has finished */
Mem_Free(post_data);
return res;
}

static void Http_SysFree(void) { }
#endif

#ifndef CC_BUILD_WEB
@@ -2224,9 +2224,6 @@ static void ClassicOptionsScreen_SetHacks(const String* v) {
}

static void ClassicOptionsScreen_ContextRecreated(void* screen) {
static const String title = String_FromConst("Controls...");
struct MenuOptionsScreen* s = (struct MenuOptionsScreen*)screen;

static const struct MenuOptionDesc buttons[9] = {
{ -1, -150, "Music", MenuOptionsScreen_Bool,
ClassicOptionsScreen_GetMusic, ClassicOptionsScreen_SetMusic },
@@ -2248,6 +2245,8 @@ static void ClassicOptionsScreen_ContextRecreated(void* screen) {
{ 0, 60, "Hacks enabled", MenuOptionsScreen_Bool,
ClassicOptionsScreen_GetHacks, ClassicOptionsScreen_SetHacks }
};
static const String title = String_FromConst("Controls...");
struct MenuOptionsScreen* s = (struct MenuOptionsScreen*)screen;

MenuOptionsScreen_MakeButtons(s, buttons, Array_Elems(buttons));
Menu_Button(s, 9, &s->buttons[9], 400, &title, &s->titleFont, Menu_SwitchKeysClassic,
@@ -2309,9 +2308,6 @@ static void EnvSettingsScreen_GetEdgeHeight(String* v) { String_AppendInt(v, Env
static void EnvSettingsScreen_SetEdgeHeight(const String* v) { Env_SetEdgeHeight(Menu_Int(v)); }

static void EnvSettingsScreen_ContextRecreated(void* screen) {
struct MenuOptionsScreen* s = (struct MenuOptionsScreen*)screen;
struct Widget** widgets = s->widgets;

static const struct MenuOptionDesc buttons[10] = {
{ -1, -150, "Clouds col", MenuOptionsScreen_Input,
EnvSettingsScreen_GetCloudsCol, EnvSettingsScreen_SetCloudsCol },
@@ -2335,6 +2331,8 @@ static void EnvSettingsScreen_ContextRecreated(void* screen) {
{ 1, 50, "Water level", MenuOptionsScreen_Input,
EnvSettingsScreen_GetEdgeHeight, EnvSettingsScreen_SetEdgeHeight }
};
struct MenuOptionsScreen* s = (struct MenuOptionsScreen*)screen;
struct Widget** widgets = s->widgets;

MenuOptionsScreen_MakeButtons(s, buttons, Array_Elems(buttons));
Menu_Back(s, 10, &s->buttons[10], "Done", &s->titleFont, Menu_SwitchOptions);
@@ -2414,9 +2412,6 @@ static void GraphicsOptionsScreen_SetMipmaps(const String* v) {
}

static void GraphicsOptionsScreen_ContextRecreated(void* screen) {
struct MenuOptionsScreen* s = (struct MenuOptionsScreen*)screen;
struct Widget** widgets = s->widgets;

static const struct MenuOptionDesc buttons[6] = {
{ -1, -50, "FPS mode", MenuOptionsScreen_Enum,
MenuOptionsScreen_GetFPS, MenuOptionsScreen_SetFPS },
@@ -2432,6 +2427,8 @@ static void GraphicsOptionsScreen_ContextRecreated(void* screen) {
{ 1, 50, "Mipmaps", MenuOptionsScreen_Bool,
GraphicsOptionsScreen_GetMipmaps, GraphicsOptionsScreen_SetMipmaps }
};
struct MenuOptionsScreen* s = (struct MenuOptionsScreen*)screen;
struct Widget** widgets = s->widgets;

MenuOptionsScreen_MakeButtons(s, buttons, Array_Elems(buttons));
Menu_Back(s, 6, &s->buttons[6], "Done", &s->titleFont, Menu_SwitchOptions);
@@ -2521,9 +2518,6 @@ static void GuiOptionsScreen_SetUseFont(const String* v) {
}

static void GuiOptionsScreen_ContextRecreated(void* screen) {
struct MenuOptionsScreen* s = (struct MenuOptionsScreen*)screen;
struct Widget** widgets = s->widgets;

static const struct MenuOptionDesc buttons[10] = {
{ -1, -150, "Black text shadows", MenuOptionsScreen_Bool,
GuiOptionsScreen_GetShadows, GuiOptionsScreen_SetShadows },
@@ -2547,6 +2541,8 @@ static void GuiOptionsScreen_ContextRecreated(void* screen) {
{ 1, 50, "Select system font", Menu_SwitchFont,
NULL, NULL }
};
struct MenuOptionsScreen* s = (struct MenuOptionsScreen*)screen;
struct Widget** widgets = s->widgets;

MenuOptionsScreen_MakeButtons(s, buttons, Array_Elems(buttons));
Menu_Back(s, 10, &s->buttons[10], "Done", &s->titleFont, Menu_SwitchOptions);
@@ -2669,10 +2665,6 @@ static void HacksSettingsScreen_ContextLost(void* screen) {
}

static void HacksSettingsScreen_ContextRecreated(void* screen) {
struct MenuOptionsScreen* s = (struct MenuOptionsScreen*)screen;
struct Widget** widgets = s->widgets;
Event_RegisterVoid(&UserEvents.HackPermissionsChanged, s, HacksSettingsScreen_CheckHacksAllowed);

static const struct MenuOptionDesc buttons[10] = {
{ -1, -150, "Hacks enabled", MenuOptionsScreen_Bool,
HacksSettingsScreen_GetHacks, HacksSettingsScreen_SetHacks },
@@ -2696,6 +2688,9 @@ static void HacksSettingsScreen_ContextRecreated(void* screen) {
{ 1, 50, "Field of view", MenuOptionsScreen_Input,
HacksSettingsScreen_GetFOV, HacksSettingsScreen_SetFOV },
};
struct MenuOptionsScreen* s = (struct MenuOptionsScreen*)screen;
struct Widget** widgets = s->widgets;
Event_RegisterVoid(&UserEvents.HackPermissionsChanged, s, HacksSettingsScreen_CheckHacksAllowed);

MenuOptionsScreen_MakeButtons(s, buttons, Array_Elems(buttons));
Menu_Back(s, 10, &s->buttons[10], "Done", &s->titleFont, Menu_SwitchOptions);
@@ -2772,9 +2767,6 @@ static void MiscOptionsScreen_SetSensitivity(const String* v) {
}

static void MiscOptionsScreen_ContextRecreated(void* screen) {
struct MenuOptionsScreen* s = (struct MenuOptionsScreen*)screen;
struct Widget** widgets = s->widgets;

static const struct MenuOptionDesc buttons[8] = {
{ -1, -100, "Reach distance", MenuOptionsScreen_Input,
MiscOptionsScreen_GetReach, MiscOptionsScreen_SetReach },
@@ -2794,6 +2786,8 @@ static void MiscOptionsScreen_ContextRecreated(void* screen) {
{ 1, 50, "Mouse sensitivity", MenuOptionsScreen_Input,
MiscOptionsScreen_GetSensitivity, MiscOptionsScreen_SetSensitivity }
};
struct MenuOptionsScreen* s = (struct MenuOptionsScreen*)screen;
struct Widget** widgets = s->widgets;

MenuOptionsScreen_MakeButtons(s, buttons, Array_Elems(buttons));
Menu_Back(s, 8, &s->buttons[8], "Done", &s->titleFont, Menu_SwitchOptions);
@@ -2863,10 +2857,6 @@ static void NostalgiaScreen_SwitchBack(void* a, void* b) {
}

static void NostalgiaScreen_ContextRecreated(void* screen) {
static const String descText = String_FromConst("&eButtons on the right require restarting game");
struct MenuOptionsScreen* s = (struct MenuOptionsScreen*)screen;
static struct TextWidget desc;

static const struct MenuOptionDesc buttons[8] = {
{ -1, -150, "Classic hand model", MenuOptionsScreen_Bool,
NostalgiaScreen_GetHand, NostalgiaScreen_SetHand },
@@ -2886,6 +2876,9 @@ static void NostalgiaScreen_ContextRecreated(void* screen) {
{ 1, -50, "Use server textures", MenuOptionsScreen_Bool,
NostalgiaScreen_GetTexs, NostalgiaScreen_SetTexs },
};
static const String descText = String_FromConst("&eButtons on the right require restarting game");
struct MenuOptionsScreen* s = (struct MenuOptionsScreen*)screen;
static struct TextWidget desc;

MenuOptionsScreen_MakeButtons(s, buttons, Array_Elems(buttons));
Menu_Back(s, 8, &s->buttons[8], "Done", &s->titleFont, NostalgiaScreen_SwitchBack);
@@ -92,7 +92,7 @@ const ReturnCode ReturnCode_SocketWouldBlock = EWOULDBLOCK;
#endif

/* Attempts to set current/working directory to the directory exe file is in */
static void Platform_DefaultSetCurrent(void) {
static void SetCurrentToExeDirectory(void) {
String path; char pathBuffer[FILENAME_SIZE];
int i;
ReturnCode res;
@@ -382,6 +382,7 @@ ReturnCode Directory_Enum(const String* dirPath, void* obj, Directory_EnumCallba
WIN32_FIND_DATA entry;
HANDLE find;
ReturnCode res;
int i;

/* Need to append \* to search for files in directory */
String_InitArray(path, pathBuffer);
@@ -399,8 +400,7 @@ ReturnCode Directory_Enum(const String* dirPath, void* obj, Directory_EnumCallba
TCHAR* src = entry.cFileName;
if (src[0] == '.' && src[1] == '\0') continue;
if (src[0] == '.' && src[1] == '.' && src[2] == '\0') continue;

int i;

for (i = 0; i < MAX_PATH && src[i]; i++) {
String_Append(&path, Convert_UnicodeToCP437(src[i]));
}
@@ -425,13 +425,14 @@ ReturnCode Directory_SetCurrent(const String* path) {
}

ReturnCode File_GetModifiedTime(const String* path, TimeMS* time) {
FileHandle file;
FileHandle file;
FILETIME ft;
uint64_t raw;
ReturnCode res = File_Open(&file, path);
if (res) return res;

FILETIME ft;
if (GetFileTime(file, NULL, NULL, &ft)) {
uint64_t raw = ft.dwLowDateTime | ((uint64_t)ft.dwHighDateTime << 32);
raw = ft.dwLowDateTime | ((uint64_t)ft.dwHighDateTime << 32);
*time = FileTime_TotalMS(raw);
} else {
res = GetLastError();
@@ -443,11 +444,12 @@ ReturnCode File_GetModifiedTime(const String* path, TimeMS* time) {

ReturnCode File_SetModifiedTime(const String* path, TimeMS time) {
FileHandle file;
FILETIME ft;
uint64_t raw;
ReturnCode res = File_Append(&file, path);
if (res) return res;

FILETIME ft;
uint64_t raw = 10000 * (time - FILETIME_EPOCH);
raw = 10000 * (time - FILETIME_EPOCH);
ft.dwLowDateTime = (uint32_t)raw;
ft.dwHighDateTime = (uint32_t)(raw >> 32);

@@ -1300,12 +1302,12 @@ static void Font_Init(void) {
#if defined CC_BUILD_WIN
char winFolder[FILENAME_SIZE];
TCHAR winTmp[FILENAME_SIZE];

UINT winLen;
/* System folder path may not be C:/Windows */
String dirs[1];
String_InitArray(dirs[0], winFolder);

UINT winLen = GetWindowsDirectory(winTmp, FILENAME_SIZE);
winLen = GetWindowsDirectory(winTmp, FILENAME_SIZE);
if (winLen) {
Platform_DecodeString(&dirs[0], winTmp, winLen);
} else {
@@ -1856,7 +1858,7 @@ void Platform_Free(void) {
WSACleanup();
HeapDestroy(heap);
}
void Platform_SetDefaultCurrentDirectory(void) { Platform_DefaultSetCurrent(); }
void Platform_SetDefaultCurrentDirectory(void) { SetCurrentToExeDirectory(); }

static String Platform_NextArg(STRING_REF String* args) {
String arg;
@@ -2009,7 +2011,7 @@ void Platform_Init(void) {
/* stopwatch always in nanoseconds */
sw_freqDiv = 1000;
}
void Platform_SetDefaultCurrentDirectory(void) { Platform_DefaultSetCurrent(); }
void Platform_SetDefaultCurrentDirectory(void) { SetCurrentToExeDirectory(); }
#elif defined CC_BUILD_OSX
static void Platform_InitStopwatch(void) {
mach_timebase_info_data_t tb = { 0 };
@@ -2029,7 +2031,7 @@ void Platform_Init(void) {
/* NOTE: TransformProcessType is OSX 10.3 or later */
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
}
void Platform_SetDefaultCurrentDirectory(void) { Platform_DefaultSetCurrent(); }
void Platform_SetDefaultCurrentDirectory(void) { SetCurrentToExeDirectory(); }
#elif defined CC_BUILD_WEB
void Platform_Init(void) {
EM_ASM( Module['websocket']['subprotocol'] = 'ClassiCube'; );
@@ -94,9 +94,10 @@ CC_NOINLINE static void ExitMissingArgs(int argsCount, const String* args) {
Process_Exit(1);
}

/* This is used when compiling with MingW without linking to startup files. */
/* NOTE: This is used when compiling with MingW without linking to startup files. */
/* The final code produced for "main" is our "main" combined with crt's main. (mingw-w64-crt/crt/gccmain.c) */
/* This immediately crashes the game on startup. Using a different name fixes. */
/* This immediately crashes the game on startup. */
/* Using main_real instead and setting main_real as the entrypoint fixes the crash. */
#ifdef CC_NOMAIN
int main_real(int argc, char** argv) {
#else
@@ -172,3 +173,11 @@ int main(int argc, char** argv) {
Process_Exit(0);
return 0;
}
/* android NDK doesn't let us use regular main */
#ifdef CC_BUILD_ANDROID
#include <android_native_app_glue.h>
void android_main(struct android_app* app) {
Window_Handle = app;
main(0, NULL);
}
#endif

0 comments on commit dccabb9

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