Merge branch 'master' into 3ds-dualscreen

This commit is contained in:
camthehaxman 2024-01-22 15:30:01 -06:00
commit b6f1c6728e
48 changed files with 417 additions and 323 deletions

Binary file not shown.

View File

@ -50,6 +50,9 @@ static void AudioWarn(cc_result res, const char* action) {
} }
static void AudioBase_Clear(struct AudioContext* ctx); static void AudioBase_Clear(struct AudioContext* ctx);
static cc_bool AudioBase_AdjustSound(struct AudioContext* ctx, struct AudioData* data); static cc_bool AudioBase_AdjustSound(struct AudioContext* ctx, struct AudioData* data);
static void AudioBase_AllocChunks(int size, void** chunks, int numChunks);
static void AudioBase_FreeChunks(void** chunks, int numChunks);
/* achieve higher speed by playing samples at higher sample rate */ /* achieve higher speed by playing samples at higher sample rate */
#define Audio_AdjustSampleRate(data) ((data->sampleRate * data->rate) / 100) #define Audio_AdjustSampleRate(data) ((data->sampleRate * data->rate) / 100)
@ -323,12 +326,12 @@ cc_bool Audio_DescribeError(cc_result res, cc_string* dst) {
return err != NULL; return err != NULL;
} }
void* Audio_AllocChunk(cc_uint32 size) { void Audio_AllocChunks(cc_uint32 size, void** chunks, int numChunks) {
return Mem_TryAlloc(size, 1); AudioBase_AllocChunks(size, chunks, numChunks);
} }
void Audio_FreeChunk(void* data) { void Audio_FreeChunks(void** chunks, int numChunks) {
Mem_Free(data); AudioBase_FreeChunks(chunks, numChunks);
} }
#elif defined CC_BUILD_WINMM #elif defined CC_BUILD_WINMM
/*########################################################################################################################* /*########################################################################################################################*
@ -525,12 +528,12 @@ cc_bool Audio_DescribeError(cc_result res, cc_string* dst) {
return true; return true;
} }
void* Audio_AllocChunk(cc_uint32 size) { void Audio_AllocChunks(cc_uint32 size, void** chunks, int numChunks) {
return Mem_TryAlloc(size, 1); AudioBase_AllocChunks(size, chunks, numChunks);
} }
void Audio_FreeChunk(void* data) { void Audio_FreeChunks(void** chunks, int numChunks) {
Mem_Free(data); AudioBase_FreeChunks(chunks, numChunks);
} }
#elif defined CC_BUILD_OPENSLES #elif defined CC_BUILD_OPENSLES
/*########################################################################################################################* /*########################################################################################################################*
@ -761,12 +764,12 @@ cc_bool Audio_DescribeError(cc_result res, cc_string* dst) {
return err != NULL; return err != NULL;
} }
void* Audio_AllocChunk(cc_uint32 size) { void Audio_AllocChunks(cc_uint32 size, void** chunks, int numChunks) {
return Mem_TryAlloc(size, 1); AudioBase_AllocChunks(size, chunks, numChunks);
} }
void Audio_FreeChunk(void* data) { void Audio_FreeChunks(void** chunks, int numChunks) {
Mem_Free(data); AudioBase_FreeChunks(chunks, numChunks);
} }
#elif defined CC_BUILD_3DS #elif defined CC_BUILD_3DS
/*########################################################################################################################* /*########################################################################################################################*
@ -778,6 +781,7 @@ struct AudioContext {
ndspWaveBuf bufs[AUDIO_MAX_BUFFERS]; ndspWaveBuf bufs[AUDIO_MAX_BUFFERS];
int count, channels, sampleRate; int count, channels, sampleRate;
void* _tmpData; int _tmpSize; void* _tmpData; int _tmpSize;
cc_bool stereo;
}; };
static int channelIDs; static int channelIDs;
@ -806,7 +810,7 @@ void Audio_Init(struct AudioContext* ctx, int buffers) {
ctx->count = buffers; ctx->count = buffers;
ctx->chanID = chanID; ctx->chanID = chanID;
ctx->used = true; ctx->used = true;
ndspChnSetInterp(ctx->chanID, NDSP_INTERP_LINEAR); ndspChnSetInterp(ctx->chanID, NDSP_INTERP_LINEAR);
} }
@ -814,6 +818,7 @@ void Audio_Close(struct AudioContext* ctx) {
if (ctx->used) { if (ctx->used) {
ndspChnWaveBufClear(ctx->chanID); ndspChnWaveBufClear(ctx->chanID);
ctx->channels &= ~(1 << ctx->chanID); ctx->channels &= ~(1 << ctx->chanID);
channelIDs &= ~(1 << ctx->chanID);
} }
ctx->used = false; ctx->used = false;
@ -821,7 +826,8 @@ void Audio_Close(struct AudioContext* ctx) {
} }
cc_result Audio_SetFormat(struct AudioContext* ctx, int channels, int sampleRate) { cc_result Audio_SetFormat(struct AudioContext* ctx, int channels, int sampleRate) {
int fmt = channels == 1 ? NDSP_FORMAT_MONO_PCM16 : NDSP_FORMAT_STEREO_PCM16; ctx->stereo = (channels == 2);
int fmt = ctx->stereo ? NDSP_FORMAT_STEREO_PCM16 : NDSP_FORMAT_MONO_PCM16;
ndspChnSetFormat(ctx->chanID, fmt); ndspChnSetFormat(ctx->chanID, fmt);
ndspChnSetRate(ctx->chanID, sampleRate); ndspChnSetRate(ctx->chanID, sampleRate);
@ -831,16 +837,25 @@ cc_result Audio_SetFormat(struct AudioContext* ctx, int channels, int sampleRate
cc_result Audio_QueueChunk(struct AudioContext* ctx, void* chunk, cc_uint32 dataSize) { cc_result Audio_QueueChunk(struct AudioContext* ctx, void* chunk, cc_uint32 dataSize) {
ndspWaveBuf* buf; ndspWaveBuf* buf;
// DSP audio buffers must be aligned to a multiple of 0x80, according to the example code I could find.
if (((uintptr_t)chunk & 0x7F) != 0) {
Platform_Log1("Audio_QueueData: tried to queue buffer with non-aligned audio buffer 0x%x\n", &chunk);
}
if ((dataSize & 0x7F) != 0) {
Platform_Log1("Audio_QueueData: unaligned audio data size 0x%x\n", &dataSize);
}
for (int i = 0; i < ctx->count; i++) for (int i = 0; i < ctx->count; i++)
{ {
buf = &ctx->bufs[i]; buf = &ctx->bufs[i];
//Platform_Log2("QUEUE_CHUNK: %i = %i", &ctx->chanID, &buf->status); //Platform_Log2("QUEUE_CHUNK: %i = %i", &ctx->chanID, &buf->status);
if (buf->status == NDSP_WBUF_QUEUED || buf->status == NDSP_WBUF_PLAYING) if (buf->status == NDSP_WBUF_QUEUED || buf->status == NDSP_WBUF_PLAYING)
continue; continue;
buf->data_pcm16 = chunk; buf->data_pcm16 = chunk;
buf->nsamples = dataSize / 2; // 16 bit samples buf->nsamples = dataSize / (sizeof(cc_int16) * (ctx->stereo ? 2 : 1));
//Platform_Log1("PLAYING ON: %i", &ctx->chanID); //Platform_Log1("PLAYING ON: %i", &ctx->chanID);
DSP_FlushDataCache(buf->data_pcm16, dataSize);
ndspChnWaveBufAdd(ctx->chanID, buf); ndspChnWaveBufAdd(ctx->chanID, buf);
return 0; return 0;
} }
@ -889,6 +904,19 @@ cc_result Audio_PlayData(struct AudioContext* ctx, struct AudioData* data) {
cc_bool Audio_DescribeError(cc_result res, cc_string* dst) { cc_bool Audio_DescribeError(cc_result res, cc_string* dst) {
return false; return false;
} }
void Audio_AllocChunks(cc_uint32 size, void** chunks, int numChunks) {
size = (size + 0x7F) & ~0x7F; // round up to nearest multiple of 0x80
cc_uint8* dst = linearAlloc(size * numChunks);
for (int i = 0; i < numChunks; i++) {
chunks[i] = dst ? (dst + size * i) : NULL;
}
}
void Audio_FreeChunks(void** chunks, int numChunks) {
linearFree(chunks[0]);
}
#elif defined CC_BUILD_WEBAUDIO #elif defined CC_BUILD_WEBAUDIO
/*########################################################################################################################* /*########################################################################################################################*
*-----------------------------------------------------WebAudio backend----------------------------------------------------* *-----------------------------------------------------WebAudio backend----------------------------------------------------*
@ -947,12 +975,12 @@ cc_bool Audio_DescribeError(cc_result res, cc_string* dst) {
return len > 0; return len > 0;
} }
void* Audio_AllocChunk(cc_uint32 size) { void Audio_AllocChunks(cc_uint32 size, void** chunks, int numChunks) {
return Mem_TryAlloc(size, 1); AudioBase_AllocChunks(size, chunks, numChunks);
} }
void Audio_FreeChunk(void* data) { void Audio_FreeChunks(void** chunks, int numChunks) {
Mem_Free(data); AudioBase_FreeChunks(chunks, numChunks);
} }
#endif #endif
@ -996,6 +1024,20 @@ static cc_bool AudioBase_AdjustSound(struct AudioContext* ctx, struct AudioData*
data->data = audio; data->data = audio;
return true; return true;
} }
static void AudioBase_AllocChunks(int size, void** chunks, int numChunks) {
cc_uint8* dst = (cc_uint8*)Mem_TryAlloc(numChunks, size);
int i;
for (i = 0; i < numChunks; i++)
{
chunks[i] = dst ? (dst + size * i) : NULL;
}
}
static void AudioBase_FreeChunks(void** chunks, int numChunks) {
Mem_Free(chunks[0]);
}
#endif #endif
@ -1064,7 +1106,7 @@ static cc_result Sound_ReadWaveData(struct Stream* stream, struct Sound* snd) {
if (bitsPerSample != 16) return WAV_ERR_SAMPLE_BITS; if (bitsPerSample != 16) return WAV_ERR_SAMPLE_BITS;
size -= WAV_FMT_SIZE; size -= WAV_FMT_SIZE;
} else if (fourCC == WAV_FourCC('d','a','t','a')) { } else if (fourCC == WAV_FourCC('d','a','t','a')) {
snd->data = Audio_AllocChunk(size); Audio_AllocChunks(size, &snd->data, 1);
snd->size = size; snd->size = size;
if (!snd->data) return ERR_OUT_OF_MEMORY; if (!snd->data) return ERR_OUT_OF_MEMORY;
@ -1129,7 +1171,7 @@ static void Soundboard_Load(struct Soundboard* board, const cc_string* boardName
if (res) { if (res) {
Logger_SysWarn2(res, "decoding", file); Logger_SysWarn2(res, "decoding", file);
Mem_Free(snd->data); Audio_FreeChunks(&snd->data, 1);
snd->data = NULL; snd->data = NULL;
snd->size = 0; snd->size = 0;
} else { group->count++; } } else { group->count++; }
@ -1353,7 +1395,7 @@ static cc_result Music_PlayOgg(struct Stream* source) {
int channels, sampleRate; int channels, sampleRate;
int chunkSize, samplesPerSecond; int chunkSize, samplesPerSecond;
cc_int16* data = NULL; void* chunks[AUDIO_MAX_BUFFERS] = { 0 };
int inUse, i, cur; int inUse, i, cur;
cc_result res; cc_result res;
@ -1370,27 +1412,33 @@ static cc_result Music_PlayOgg(struct Stream* source) {
chunkSize = channels * (sampleRate + vorbis.blockSizes[1]); chunkSize = channels * (sampleRate + vorbis.blockSizes[1]);
samplesPerSecond = channels * sampleRate; samplesPerSecond = channels * sampleRate;
cur = 0; Audio_AllocChunks(chunkSize * 2, chunks, AUDIO_MAX_BUFFERS);
data = (cc_int16*)Audio_AllocChunk(chunkSize * AUDIO_MAX_BUFFERS * 2); for (i = 0; i < AUDIO_MAX_BUFFERS; i++)
if (!data) { res = ERR_OUT_OF_MEMORY; goto cleanup; } {
if (chunks[i]) continue;
res = ERR_OUT_OF_MEMORY; goto cleanup;
}
/* fill up with some samples before playing */ /* fill up with some samples before playing */
for (i = 0; i < AUDIO_MAX_BUFFERS && !res; i++) { for (i = 0; i < AUDIO_MAX_BUFFERS && !res; i++)
res = Music_Buffer(&data[chunkSize * cur], samplesPerSecond, &vorbis); {
cur = (cur + 1) % AUDIO_MAX_BUFFERS; res = Music_Buffer((cc_int16*)chunks[i], samplesPerSecond, &vorbis);
} }
if (music_stopping) goto cleanup; if (music_stopping) goto cleanup;
res = Audio_Play(&music_ctx); res = Audio_Play(&music_ctx);
if (res) goto cleanup; if (res) goto cleanup;
cur = 0;
while (!music_stopping) { while (!music_stopping) {
#ifdef CC_BUILD_ANDROID #ifdef CC_BUILD_ANDROID
/* Don't play music while in the background on Android */ /* Don't play music while in the background on Android */
/* TODO: Not use such a terrible approach */ /* TODO: Not use such a terrible approach */
if (!WindowInfo.Handle) { if (!Window_Main.Handle) {
Audio_Pause(&music_ctx); Audio_Pause(&music_ctx);
while (!WindowInfo.Handle && !music_stopping) { while (!Window_Main.Handle && !music_stopping) {
Thread_Sleep(10); continue; Thread_Sleep(10); continue;
} }
Audio_Play(&music_ctx); Audio_Play(&music_ctx);
@ -1404,7 +1452,7 @@ static cc_result Music_PlayOgg(struct Stream* source) {
Thread_Sleep(10); continue; Thread_Sleep(10); continue;
} }
res = Music_Buffer(&data[chunkSize * cur], samplesPerSecond, &vorbis); res = Music_Buffer((cc_int16*)chunks[cur], samplesPerSecond, &vorbis);
cur = (cur + 1) % AUDIO_MAX_BUFFERS; cur = (cur + 1) % AUDIO_MAX_BUFFERS;
/* need to specially handle last bit of audio */ /* need to specially handle last bit of audio */
@ -1425,7 +1473,7 @@ static cc_result Music_PlayOgg(struct Stream* source) {
} }
cleanup: cleanup:
Mem_Free(data); Audio_FreeChunks(chunks, AUDIO_MAX_BUFFERS);
Vorbis_Free(&vorbis); Vorbis_Free(&vorbis);
return res == ERR_END_OF_STREAM ? 0 : res; return res == ERR_END_OF_STREAM ? 0 : res;
} }

View File

@ -66,8 +66,8 @@ cc_bool Audio_FastPlay(struct AudioContext* ctx, struct AudioData* data);
/* Outputs more detailed information about errors with audio. */ /* Outputs more detailed information about errors with audio. */
cc_bool Audio_DescribeError(cc_result res, cc_string* dst); cc_bool Audio_DescribeError(cc_result res, cc_string* dst);
/* Allocates a chunk of data to store audio samples */ /* Allocates a group of chunks of data to store audio samples */
void* Audio_AllocChunk(cc_uint32 size); void Audio_AllocChunks(cc_uint32 size, void** chunks, int numChunks);
/* Frees a previously allocated chunk of data */ /* Frees a previously allocated group of chunks of data */
void Audio_FreeChunk(void* chunk); void Audio_FreeChunks(void** chunks, int numChunks);
#endif #endif

View File

@ -109,7 +109,7 @@ static void PerspectiveCamera_UpdateMouseRotation(double delta) {
} }
static void PerspectiveCamera_UpdateMouse(double delta) { static void PerspectiveCamera_UpdateMouse(double delta) {
if (!Gui.InputGrab && WindowInfo.Focused) Window_UpdateRawMouse(); if (!Gui.InputGrab && Window_Main.Focused) Window_UpdateRawMouse();
PerspectiveCamera_UpdateMouseRotation(delta); PerspectiveCamera_UpdateMouseRotation(delta);
cam_deltaX = 0; cam_deltaY = 0; cam_deltaX = 0; cam_deltaY = 0;

View File

@ -213,7 +213,7 @@ static void ResolutionCommand_Execute(const cc_string* args, int argsCount) {
int width, height; int width, height;
if (argsCount < 2) { if (argsCount < 2) {
Chat_Add4("&e/client: &fCurrent resolution is %i@%f2 x %i@%f2", Chat_Add4("&e/client: &fCurrent resolution is %i@%f2 x %i@%f2",
&WindowInfo.Width, &DisplayInfo.ScaleX, &WindowInfo.Height, &DisplayInfo.ScaleY); &Window_Main.Width, &DisplayInfo.ScaleX, &Window_Main.Height, &DisplayInfo.ScaleY);
} else if (!Convert_ParseInt(&args[0], &width) || !Convert_ParseInt(&args[1], &height)) { } else if (!Convert_ParseInt(&args[0], &width) || !Convert_ParseInt(&args[1], &height)) {
Chat_AddRaw("&e/client: &cWidth and height must be integers."); Chat_AddRaw("&e/client: &cWidth and height must be integers.");
} else if (width <= 0 || height <= 0) { } else if (width <= 0 || height <= 0) {

View File

@ -282,7 +282,6 @@ typedef cc_uint8 cc_bool;
#undef CC_BUILD_FREETYPE #undef CC_BUILD_FREETYPE
#elif defined __3DS__ #elif defined __3DS__
#define CC_BUILD_3DS #define CC_BUILD_3DS
#define CC_BUILD_OPENAL
#define CC_BUILD_HTTPCLIENT #define CC_BUILD_HTTPCLIENT
#define CC_BUILD_BEARSSL #define CC_BUILD_BEARSSL
#define CC_BUILD_LOWMEM #define CC_BUILD_LOWMEM

View File

@ -783,22 +783,22 @@ static void UpdateMapEdges(void) {
*---------------------------------------------------------General---------------------------------------------------------* *---------------------------------------------------------General---------------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
static void CloudsPngProcess(struct Stream* stream, const cc_string* name) { static void CloudsPngProcess(struct Stream* stream, const cc_string* name) {
Game_UpdateTexture(&clouds_tex, stream, name, NULL); Game_UpdateTexture(&clouds_tex, stream, name, NULL, NULL);
} }
static struct TextureEntry clouds_entry = { "clouds.png", CloudsPngProcess }; static struct TextureEntry clouds_entry = { "clouds.png", CloudsPngProcess };
static void SkyboxPngProcess(struct Stream* stream, const cc_string* name) { static void SkyboxPngProcess(struct Stream* stream, const cc_string* name) {
Game_UpdateTexture(&skybox_tex, stream, name, NULL); Game_UpdateTexture(&skybox_tex, stream, name, NULL, NULL);
} }
static struct TextureEntry skybox_entry = { "skybox.png", SkyboxPngProcess }; static struct TextureEntry skybox_entry = { "skybox.png", SkyboxPngProcess };
static void SnowPngProcess(struct Stream* stream, const cc_string* name) { static void SnowPngProcess(struct Stream* stream, const cc_string* name) {
Game_UpdateTexture(&snow_tex, stream, name, NULL); Game_UpdateTexture(&snow_tex, stream, name, NULL, NULL);
} }
static struct TextureEntry snow_entry = { "snow.png", SnowPngProcess }; static struct TextureEntry snow_entry = { "snow.png", SnowPngProcess };
static void RainPngProcess(struct Stream* stream, const cc_string* name) { static void RainPngProcess(struct Stream* stream, const cc_string* name) {
Game_UpdateTexture(&rain_tex, stream, name, NULL); Game_UpdateTexture(&rain_tex, stream, name, NULL, NULL);
} }
static struct TextureEntry rain_entry = { "rain.png", RainPngProcess }; static struct TextureEntry rain_entry = { "rain.png", RainPngProcess };

View File

@ -213,13 +213,18 @@ cc_bool Game_CanPick(BlockID block) {
return Blocks.Collide[block] != COLLIDE_LIQUID || Game_BreakableLiquids; return Blocks.Collide[block] != COLLIDE_LIQUID || Game_BreakableLiquids;
} }
cc_bool Game_UpdateTexture(GfxResourceID* texId, struct Stream* src, const cc_string* file, cc_uint8* skinType) { cc_bool Game_UpdateTexture(GfxResourceID* texId, struct Stream* src, const cc_string* file,
cc_uint8* skinType, int* heightDivisor) {
struct Bitmap bmp; struct Bitmap bmp;
cc_bool success; cc_bool success;
cc_result res; cc_result res;
res = Png_Decode(&bmp, src); res = Png_Decode(&bmp, src);
if (res) { Logger_SysWarn2(res, "decoding", file); } if (res) { Logger_SysWarn2(res, "decoding", file); }
/* E.g. gui.png, icons.png only need top half of the texture loaded */
if (heightDivisor && bmp.height >= *heightDivisor)
bmp.height /= *heightDivisor;
success = !res && Game_ValidateBitmap(file, &bmp); success = !res && Game_ValidateBitmap(file, &bmp);
if (success) { if (success) {
@ -273,8 +278,8 @@ cc_bool Game_ValidateBitmapPow2(const cc_string* file, struct Bitmap* bmp) {
} }
void Game_UpdateDimensions(void) { void Game_UpdateDimensions(void) {
Game.Width = max(WindowInfo.Width, 1); Game.Width = max(Window_Main.Width, 1);
Game.Height = max(WindowInfo.Height, 1); Game.Height = max(Window_Main.Height, 1);
} }
static void Game_OnResize(void* obj) { static void Game_OnResize(void* obj) {
@ -298,7 +303,7 @@ static void HandleOnNewMapLoaded(void* obj) {
} }
static void HandleInactiveChanged(void* obj) { static void HandleInactiveChanged(void* obj) {
if (WindowInfo.Inactive) { if (Window_Main.Inactive) {
Chat_AddOf(&Gfx_LowPerfMessage, MSG_TYPE_EXTRASTATUS_2); Chat_AddOf(&Gfx_LowPerfMessage, MSG_TYPE_EXTRASTATUS_2);
Gfx_SetFpsLimit(false, 1000 / 1.0f); Gfx_SetFpsLimit(false, 1000 / 1.0f);
} else { } else {
@ -601,7 +606,7 @@ static void Game_RenderFrame(double delta) {
Game_Vertices = 0; Game_Vertices = 0;
Camera.Active->UpdateMouse(delta); Camera.Active->UpdateMouse(delta);
if (!WindowInfo.Focused && !Gui.InputGrab) Gui_ShowPauseMenu(); if (!Window_Main.Focused && !Gui.InputGrab) Gui_ShowPauseMenu();
if (KeyBind_IsPressed(KEYBIND_ZOOM_SCROLL) && !Gui.InputGrab) { if (KeyBind_IsPressed(KEYBIND_ZOOM_SCROLL) && !Gui.InputGrab) {
InputHandler_SetFOV(Camera.ZoomFov); InputHandler_SetFOV(Camera.ZoomFov);
@ -618,7 +623,7 @@ static void Game_RenderFrame(double delta) {
UpdateViewMatrix(); UpdateViewMatrix();
/* TODO: Not calling Gfx_EndFrame doesn't work with Direct3D9 */ /* TODO: Not calling Gfx_EndFrame doesn't work with Direct3D9 */
if (WindowInfo.Inactive) return; if (Window_Main.Inactive) return;
Gfx_Clear(); Gfx_Clear();
Gfx_LoadMatrix(MATRIX_PROJECTION, &Gfx.Projection); Gfx_LoadMatrix(MATRIX_PROJECTION, &Gfx.Projection);

View File

@ -92,18 +92,20 @@ CC_API void Game_UpdateBlock(int x, int y, int z, BlockID block);
CC_API void Game_ChangeBlock(int x, int y, int z, BlockID block); CC_API void Game_ChangeBlock(int x, int y, int z, BlockID block);
cc_bool Game_CanPick(BlockID block); cc_bool Game_CanPick(BlockID block);
cc_bool Game_UpdateTexture(GfxResourceID* texId, struct Stream* src, const cc_string* file, cc_uint8* skinType); /* Updates Game_Width and Game_Height. */
void Game_UpdateDimensions(void);
/* Sets the strategy/method used to limit frames per second. */
/* See FPS_LIMIT_ for valid strategies/methods */
void Game_SetFpsLimit(int method);
cc_bool Game_UpdateTexture(GfxResourceID* texId, struct Stream* src, const cc_string* file,
cc_uint8* skinType, int* heightDivisor);
/* Checks that the given bitmap can be loaded into a native gfx texture. */ /* Checks that the given bitmap can be loaded into a native gfx texture. */
/* (must be power of two size and be <= Gfx_MaxTexWidth/Gfx_MaxHeight) */ /* (must be power of two size and be <= Gfx_MaxTexWidth/Gfx_MaxHeight) */
cc_bool Game_ValidateBitmap(const cc_string* file, struct Bitmap* bmp); cc_bool Game_ValidateBitmap(const cc_string* file, struct Bitmap* bmp);
/* Checks that the given bitmap is a power of two size */ /* Checks that the given bitmap is a power of two size */
/* NOTE: Game_ValidateBitmap should nearly always be used instead of this */ /* NOTE: Game_ValidateBitmap should nearly always be used instead of this */
cc_bool Game_ValidateBitmapPow2(const cc_string* file, struct Bitmap* bmp); cc_bool Game_ValidateBitmapPow2(const cc_string* file, struct Bitmap* bmp);
/* Updates Game_Width and Game_Height. */
void Game_UpdateDimensions(void);
/* Sets the strategy/method used to limit frames per second. */
/* See FPS_LIMIT_ for valid strategies/methods */
void Game_SetFpsLimit(int method);
/* Runs the main game loop until the window is closed. */ /* Runs the main game loop until the window is closed. */
void Game_Run(int width, int height, const cc_string* title); void Game_Run(int width, int height, const cc_string* title);

View File

@ -74,7 +74,7 @@ static void CreateDeviceAndSwapChain(void) {
desc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; desc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
// RefreshRate intentionally left at 0 so display's refresh rate is used // RefreshRate intentionally left at 0 so display's refresh rate is used
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
desc.OutputWindow = WindowInfo.Handle; desc.OutputWindow = Window_Main.Handle;
desc.SampleDesc.Count = 1; desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0; desc.SampleDesc.Quality = 0;
desc.Windowed = TRUE; desc.Windowed = TRUE;
@ -656,8 +656,8 @@ static void RS_UpdateViewport(void) {
D3D11_VIEWPORT viewport; D3D11_VIEWPORT viewport;
viewport.TopLeftX = 0; viewport.TopLeftX = 0;
viewport.TopLeftY = 0; viewport.TopLeftY = 0;
viewport.Width = WindowInfo.Width; viewport.Width = Window_Main.Width;
viewport.Height = WindowInfo.Height; viewport.Height = Window_Main.Height;
viewport.MinDepth = 0.0f; viewport.MinDepth = 0.0f;
viewport.MaxDepth = 1.0f; viewport.MaxDepth = 1.0f;
ID3D11DeviceContext_RSSetViewports(context, 1, &viewport); ID3D11DeviceContext_RSSetViewports(context, 1, &viewport);
@ -1074,8 +1074,8 @@ cc_result Gfx_TakeScreenshot(struct Stream* output) {
ID3D11RenderTargetView_GetDesc(backbuffer, &backbuffer_desc); ID3D11RenderTargetView_GetDesc(backbuffer, &backbuffer_desc);
D3D11_TEXTURE2D_DESC desc = { 0 }; D3D11_TEXTURE2D_DESC desc = { 0 };
desc.Width = WindowInfo.Width; desc.Width = Window_Main.Width;
desc.Height = WindowInfo.Height; desc.Height = Window_Main.Height;
desc.MipLevels = 1; desc.MipLevels = 1;
desc.ArraySize = 1; desc.ArraySize = 1;
desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;

View File

@ -137,7 +137,7 @@ static cc_bool deviceCreated;
static void TryCreateDevice(void) { static void TryCreateDevice(void) {
cc_result res; cc_result res;
D3DCAPS9 caps; D3DCAPS9 caps;
HWND winHandle = (HWND)WindowInfo.Handle; HWND winHandle = (HWND)Window_Main.Handle;
D3DPRESENT_PARAMETERS args = { 0 }; D3DPRESENT_PARAMETERS args = { 0 };
D3D9_FillPresentArgs(&args); D3D9_FillPresentArgs(&args);

View File

@ -139,8 +139,8 @@ static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, cc_uint8 flags, cc_boo
glGenTextures(1, &tex->textureID); glGenTextures(1, &tex->textureID);
glBindTexture(GL_TEXTURE_2D, tex->textureID); glBindTexture(GL_TEXTURE_2D, tex->textureID);
// NOTE: Enabling these fixes textures, but seems to break on cen64 // NOTE: Enabling these fixes textures, but seems to break on cen64
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mipmaps ? GL_LINEAR : GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mipmaps ? GL_LINEAR : GL_NEAREST);
tex->surface = surface_alloc(bit16 ? FMT_RGBA16 : FMT_RGBA32, bmp->width, bmp->height); tex->surface = surface_alloc(bit16 ? FMT_RGBA16 : FMT_RGBA32, bmp->width, bmp->height);
surface_t* fb = &tex->surface; surface_t* fb = &tex->surface;

View File

@ -27,8 +27,8 @@ static cc_uint8 priorities[GUI_MAX_SCREENS];
*----------------------------------------------------------Gui------------------------------------------------------------* *----------------------------------------------------------Gui------------------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
static CC_NOINLINE int GetWindowScale(void) { static CC_NOINLINE int GetWindowScale(void) {
float widthScale = WindowInfo.Width / 640.0f; float widthScale = Window_Main.Width / 640.0f;
float heightScale = WindowInfo.Height / 480.0f; float heightScale = Window_Main.Height / 480.0f;
/* Use larger UI scaling on mobile */ /* Use larger UI scaling on mobile */
/* TODO move this DPI scaling elsewhere.,. */ /* TODO move this DPI scaling elsewhere.,. */
@ -403,8 +403,8 @@ void Widget_SetLocation(void* widget, cc_uint8 horAnchor, cc_uint8 verAnchor, in
void Widget_CalcPosition(void* widget) { void Widget_CalcPosition(void* widget) {
struct Widget* w = (struct Widget*)widget; struct Widget* w = (struct Widget*)widget;
w->x = Gui_CalcPos(w->horAnchor, w->xOffset, w->width , WindowInfo.Width ); w->x = Gui_CalcPos(w->horAnchor, w->xOffset, w->width , Window_Main.Width );
w->y = Gui_CalcPos(w->verAnchor, w->yOffset, w->height, WindowInfo.Height); w->y = Gui_CalcPos(w->verAnchor, w->yOffset, w->height, Window_Main.Height);
} }
void Widget_Reset(void* widget) { void Widget_Reset(void* widget) {
@ -566,22 +566,25 @@ void Screen_PointerUp(void* s, int id, int x, int y) { }
*------------------------------------------------------Gui component------------------------------------------------------* *------------------------------------------------------Gui component------------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
static void GuiPngProcess(struct Stream* stream, const cc_string* name) { static void GuiPngProcess(struct Stream* stream, const cc_string* name) {
Game_UpdateTexture(&Gui.GuiTex, stream, name, NULL); int heightDivisor = 2; /* only top half of gui png is used */
Game_UpdateTexture(&Gui.GuiTex, stream, name, NULL, &heightDivisor);
} }
static struct TextureEntry gui_entry = { "gui.png", GuiPngProcess }; static struct TextureEntry gui_entry = { "gui.png", GuiPngProcess };
static void GuiClassicPngProcess(struct Stream* stream, const cc_string* name) { static void GuiClassicPngProcess(struct Stream* stream, const cc_string* name) {
Game_UpdateTexture(&Gui.GuiClassicTex, stream, name, NULL); int heightDivisor = 2; /* only top half of gui png is used */
Game_UpdateTexture(&Gui.GuiClassicTex, stream, name, NULL, &heightDivisor);
} }
static struct TextureEntry guiClassic_entry = { "gui_classic.png", GuiClassicPngProcess }; static struct TextureEntry guiClassic_entry = { "gui_classic.png", GuiClassicPngProcess };
static void IconsPngProcess(struct Stream* stream, const cc_string* name) { static void IconsPngProcess(struct Stream* stream, const cc_string* name) {
Game_UpdateTexture(&Gui.IconsTex, stream, name, NULL); int heightDivisor = 4; /* only top quarter of icons png is used */
Game_UpdateTexture(&Gui.IconsTex, stream, name, NULL, &heightDivisor);
} }
static struct TextureEntry icons_entry = { "icons.png", IconsPngProcess }; static struct TextureEntry icons_entry = { "icons.png", IconsPngProcess };
static void TouchPngProcess(struct Stream* stream, const cc_string* name) { static void TouchPngProcess(struct Stream* stream, const cc_string* name) {
Game_UpdateTexture(&Gui.TouchTex, stream, name, NULL); Game_UpdateTexture(&Gui.TouchTex, stream, name, NULL, NULL);
} }
static struct TextureEntry touch_entry = { "touch.png", TouchPngProcess }; static struct TextureEntry touch_entry = { "touch.png", TouchPngProcess };

View File

@ -1149,7 +1149,7 @@ static void OnInputUp(void* obj, int key) {
if (KeyBind_Claims(KEYBIND_PICK_BLOCK, key)) MouseStateRelease(MOUSE_MIDDLE); if (KeyBind_Claims(KEYBIND_PICK_BLOCK, key)) MouseStateRelease(MOUSE_MIDDLE);
} }
static void OnFocusChanged(void* obj) { if (!WindowInfo.Focused) Input_Clear(); } static void OnFocusChanged(void* obj) { if (!Window_Main.Focused) Input_Clear(); }
static void OnInit(void) { static void OnInit(void) {
Event_Register_(&PointerEvents.Moved, NULL, OnPointerMove); Event_Register_(&PointerEvents.Moved, NULL, OnPointerMove);
Event_Register_(&PointerEvents.Down, NULL, OnPointerDown); Event_Register_(&PointerEvents.Down, NULL, OnPointerDown);

View File

@ -120,11 +120,11 @@ static void LBackend_LayoutDimensions(struct LWidget* w) {
switch (l->type) switch (l->type)
{ {
case LLAYOUT_WIDTH: case LLAYOUT_WIDTH:
w->width = WindowInfo.Width - w->x - Display_ScaleX(l->offset); w->width = Window_Main.Width - w->x - Display_ScaleX(l->offset);
w->width = max(1, w->width); w->width = max(1, w->width);
break; break;
case LLAYOUT_HEIGHT: case LLAYOUT_HEIGHT:
w->height = WindowInfo.Height - w->y - Display_ScaleY(l->offset); w->height = Window_Main.Height - w->y - Display_ScaleY(l->offset);
w->height = max(1, w->height); w->height = max(1, w->height);
break; break;
} }
@ -135,8 +135,8 @@ static void LBackend_LayoutDimensions(struct LWidget* w) {
void LBackend_LayoutWidget(struct LWidget* w) { void LBackend_LayoutWidget(struct LWidget* w) {
const struct LLayout* l = w->layouts; const struct LLayout* l = w->layouts;
w->x = Gui_CalcPos(l[0].type & 0xFF, Display_ScaleX(l[0].offset), w->width, WindowInfo.Width); w->x = Gui_CalcPos(l[0].type & 0xFF, Display_ScaleX(l[0].offset), w->width, Window_Main.Width);
w->y = Gui_CalcPos(l[1].type & 0xFF, Display_ScaleY(l[1].offset), w->height, WindowInfo.Height); w->y = Gui_CalcPos(l[1].type & 0xFF, Display_ScaleY(l[1].offset), w->height, Window_Main.Height);
/* e.g. Table widget needs adjusts width/height based on window */ /* e.g. Table widget needs adjusts width/height based on window */
if (l[1].type & LLAYOUT_EXTRA) if (l[1].type & LLAYOUT_EXTRA)
@ -181,8 +181,8 @@ static CC_NOINLINE void MarkAreaDirty(int x, int y, int width, int height) {
void LBackend_InitFramebuffer(void) { void LBackend_InitFramebuffer(void) {
struct Bitmap bmp; struct Bitmap bmp;
bmp.width = max(WindowInfo.Width, 1); bmp.width = max(Window_Main.Width, 1);
bmp.height = max(WindowInfo.Height, 1); bmp.height = max(Window_Main.Height, 1);
Window_AllocFramebuffer(&bmp); Window_AllocFramebuffer(&bmp);
Context2D_Wrap(&framebuffer, &bmp); Context2D_Wrap(&framebuffer, &bmp);
@ -1088,7 +1088,7 @@ static void LTable_ScrollbarClick(struct LTable* w, int idx) {
} }
void LBackend_TableMouseDown(struct LTable* w, int idx) { void LBackend_TableMouseDown(struct LTable* w, int idx) {
if (Pointers[idx].x >= WindowInfo.Width - scrollbarWidth) { if (Pointers[idx].x >= Window_Main.Width - scrollbarWidth) {
LTable_ScrollbarClick(w, idx); LTable_ScrollbarClick(w, idx);
w->_lastRow = -1; w->_lastRow = -1;
} else if (Pointers[idx].y < w->rowsBegY) { } else if (Pointers[idx].y < w->rowsBegY) {

View File

@ -1304,7 +1304,7 @@ static void ServersScreen_Activated(struct LScreen* s_) {
ServersScreen_ReloadServers(s); ServersScreen_ReloadServers(s);
/* This is so typing on keyboard by default searchs server list */ /* This is so typing on keyboard by default searchs server list */
/* But don't do that when it would cause on-screen keyboard to show */ /* But don't do that when it would cause on-screen keyboard to show */
if (WindowInfo.SoftKeyboard) return; if (Window_Main.SoftKeyboard) return;
LScreen_SelectWidget(s_, 0, (struct LWidget*)&s->iptSearch, false); LScreen_SelectWidget(s_, 0, (struct LWidget*)&s->iptSearch, false);
} }

View File

@ -273,7 +273,7 @@ void Launcher_Run(void) {
for (;;) { for (;;) {
Window_ProcessEvents(10 / 1000.0); Window_ProcessEvents(10 / 1000.0);
if (!WindowInfo.Exists || Launcher_ShouldExit) break; if (!Window_Main.Exists || Launcher_ShouldExit) break;
Launcher_Active->Tick(Launcher_Active); Launcher_Active->Tick(Launcher_Active);
LBackend_Tick(); LBackend_Tick();
@ -296,7 +296,7 @@ void Launcher_Run(void) {
if (res) Logger_SysWarn(res, action); if (res) Logger_SysWarn(res, action);
} }
if (WindowInfo.Exists) Window_RequestClose(); if (Window_Main.Exists) Window_RequestClose();
#endif #endif
Window_3DS_SetRenderScreen(scr); Window_3DS_SetRenderScreen(scr);
@ -534,7 +534,7 @@ void Launcher_DrawTitle(struct FontDesc* font, const char* text, struct Context2
int x; int x;
/* Skip dragging logo when very small window to save space */ /* Skip dragging logo when very small window to save space */
if (WindowInfo.Height < 240) return; if (Window_Main.Height < 240) return;
DrawTextArgs_Make(&args, &title, font, false); DrawTextArgs_Make(&args, &title, font, false);
x = ctx->width / 2 - Drawer2D_TextWidth(&args) / 2; x = ctx->width / 2 - Drawer2D_TextWidth(&args) / 2;

View File

@ -79,7 +79,7 @@ static void Menu_RenderBounds(void) {
Then using wolfram alpha to solve the glblendfunc equation */ Then using wolfram alpha to solve the glblendfunc equation */
PackedCol topCol = PackedCol_Make(24, 24, 24, 105); PackedCol topCol = PackedCol_Make(24, 24, 24, 105);
PackedCol bottomCol = PackedCol_Make(51, 51, 98, 162); PackedCol bottomCol = PackedCol_Make(51, 51, 98, 162);
Gfx_Draw2DGradient(0, 0, WindowInfo.Width, WindowInfo.Height, topCol, bottomCol); Gfx_Draw2DGradient(0, 0, Window_Main.Width, Window_Main.Height, topCol, bottomCol);
} }
@ -994,13 +994,13 @@ static void EditHotkeyScreen_Update(void* screen, double delta) {
static void EditHotkeyScreen_Layout(void* screen) { static void EditHotkeyScreen_Layout(void* screen) {
struct EditHotkeyScreen* s = (struct EditHotkeyScreen*)screen; struct EditHotkeyScreen* s = (struct EditHotkeyScreen*)screen;
s->barWidth = Display_ScaleX(500); s->barWidth = Display_ScaleX(500);
s->barX = Gui_CalcPos(ANCHOR_CENTRE, 0, s->barWidth, WindowInfo.Width); s->barX = Gui_CalcPos(ANCHOR_CENTRE, 0, s->barWidth, Window_Main.Width);
s->barHeight = Display_ScaleY(2); s->barHeight = Display_ScaleY(2);
s->barY[0] = Gui_CalcPos(ANCHOR_CENTRE, Display_ScaleY(-65), s->barY[0] = Gui_CalcPos(ANCHOR_CENTRE, Display_ScaleY(-65),
s->barHeight, WindowInfo.Height); s->barHeight, Window_Main.Height);
s->barY[1] = Gui_CalcPos(ANCHOR_CENTRE, Display_ScaleY( 45), s->barY[1] = Gui_CalcPos(ANCHOR_CENTRE, Display_ScaleY( 45),
s->barHeight, WindowInfo.Height); s->barHeight, Window_Main.Height);
Widget_SetLocation(&s->btns[0], ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -150); Widget_SetLocation(&s->btns[0], ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -150);
Widget_SetLocation(&s->btns[1], ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -100); Widget_SetLocation(&s->btns[1], ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -100);
@ -2334,7 +2334,7 @@ static void MenuInputOverlay_Layout(void* screen) {
Widget_SetLocation(&s->input, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 110); Widget_SetLocation(&s->input, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 110);
Widget_SetLocation(&s->ok, ANCHOR_CENTRE, ANCHOR_CENTRE, 240, 110); Widget_SetLocation(&s->ok, ANCHOR_CENTRE, ANCHOR_CENTRE, 240, 110);
Widget_SetLocation(&s->Default, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 150); Widget_SetLocation(&s->Default, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 150);
} else if (WindowInfo.SoftKeyboard == SOFT_KEYBOARD_SHIFT) { } else if (Window_Main.SoftKeyboard == SOFT_KEYBOARD_SHIFT) {
Widget_SetLocation(&s->input, ANCHOR_CENTRE, ANCHOR_MAX, 0, 65); Widget_SetLocation(&s->input, ANCHOR_CENTRE, ANCHOR_MAX, 0, 65);
Widget_SetLocation(&s->ok, ANCHOR_CENTRE, ANCHOR_MAX, 120, 25); Widget_SetLocation(&s->ok, ANCHOR_CENTRE, ANCHOR_MAX, 120, 25);
Widget_SetLocation(&s->Default, ANCHOR_CENTRE, ANCHOR_MAX, -120, 25); Widget_SetLocation(&s->Default, ANCHOR_CENTRE, ANCHOR_MAX, -120, 25);
@ -2458,7 +2458,7 @@ static void MenuOptionsScreen_LayoutExtHelp(struct MenuOptionsScreen* s) {
Widget_SetLocation(&s->extHelp, ANCHOR_MIN, ANCHOR_CENTRE_MIN, 0, 100); Widget_SetLocation(&s->extHelp, ANCHOR_MIN, ANCHOR_CENTRE_MIN, 0, 100);
/* If use centre align above, then each line in extended help gets */ /* If use centre align above, then each line in extended help gets */
/* centered aligned separately - which is not the desired behaviour. */ /* centered aligned separately - which is not the desired behaviour. */
s->extHelp.xOffset = WindowInfo.Width / 2 - s->extHelp.width / 2; s->extHelp.xOffset = Window_Main.Width / 2 - s->extHelp.width / 2;
Widget_Layout(&s->extHelp); Widget_Layout(&s->extHelp);
} }
@ -2941,8 +2941,13 @@ static void GraphicsOptionsScreen_InitWidgets(struct MenuOptionsScreen* s) {
GraphicsOptionsScreen_GetNames, GraphicsOptionsScreen_SetNames }, GraphicsOptionsScreen_GetNames, GraphicsOptionsScreen_SetNames },
{ 1, 0, "Shadows", MenuOptionsScreen_Enum, { 1, 0, "Shadows", MenuOptionsScreen_Enum,
GraphicsOptionsScreen_GetShadows, GraphicsOptionsScreen_SetShadows }, GraphicsOptionsScreen_GetShadows, GraphicsOptionsScreen_SetShadows },
#ifdef CC_BUILD_N64
{ 1, 50, "Filtering", MenuOptionsScreen_Bool,
GraphicsOptionsScreen_GetMipmaps, GraphicsOptionsScreen_SetMipmaps }
#else
{ 1, 50, "Mipmaps", MenuOptionsScreen_Bool, { 1, 50, "Mipmaps", MenuOptionsScreen_Bool,
GraphicsOptionsScreen_GetMipmaps, GraphicsOptionsScreen_SetMipmaps } GraphicsOptionsScreen_GetMipmaps, GraphicsOptionsScreen_SetMipmaps }
#endif
}; };
s->numCore = 8; s->numCore = 8;
@ -3546,12 +3551,12 @@ static void TexIdsOverlay_Layout(void* screen) {
struct TexIdsOverlay* s = (struct TexIdsOverlay*)screen; struct TexIdsOverlay* s = (struct TexIdsOverlay*)screen;
int size; int size;
size = WindowInfo.Height / ATLAS2D_TILES_PER_ROW; size = Window_Main.Height / ATLAS2D_TILES_PER_ROW;
size = (size / 8) * 8; size = (size / 8) * 8;
Math_Clamp(size, 8, 40); Math_Clamp(size, 8, 40);
s->xOffset = Gui_CalcPos(ANCHOR_CENTRE, 0, size * Atlas2D.RowsCount, WindowInfo.Width); s->xOffset = Gui_CalcPos(ANCHOR_CENTRE, 0, size * Atlas2D.RowsCount, Window_Main.Width);
s->yOffset = Gui_CalcPos(ANCHOR_CENTRE, 0, size * ATLAS2D_TILES_PER_ROW, WindowInfo.Height); s->yOffset = Gui_CalcPos(ANCHOR_CENTRE, 0, size * ATLAS2D_TILES_PER_ROW, Window_Main.Height);
s->tileSize = size; s->tileSize = size;
/* Can't use vertical centreing here */ /* Can't use vertical centreing here */

View File

@ -512,10 +512,11 @@ void Model_RegisterTexture(struct ModelTex* tex) {
static void Models_TextureChanged(void* obj, struct Stream* stream, const cc_string* name) { static void Models_TextureChanged(void* obj, struct Stream* stream, const cc_string* name) {
struct ModelTex* tex; struct ModelTex* tex;
for (tex = textures_head; tex; tex = tex->next) { for (tex = textures_head; tex; tex = tex->next)
{
if (!String_CaselessEqualsConst(name, tex->name)) continue; if (!String_CaselessEqualsConst(name, tex->name)) continue;
Game_UpdateTexture(&tex->texID, stream, name, &tex->skinType); Game_UpdateTexture(&tex->texID, stream, name, &tex->skinType, NULL);
return; return;
} }
} }

View File

@ -574,7 +574,7 @@ void Particles_CustomEffect(int effectID, float x, float y, float z, float origi
*---------------------------------------------------Particles component---------------------------------------------------* *---------------------------------------------------Particles component---------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
static void ParticlesPngProcess(struct Stream* stream, const cc_string* name) { static void ParticlesPngProcess(struct Stream* stream, const cc_string* name) {
Game_UpdateTexture(&particles_TexId, stream, name, NULL); Game_UpdateTexture(&particles_TexId, stream, name, NULL, NULL);
} }
static struct TextureEntry particles_entry = { "particles.png", ParticlesPngProcess }; static struct TextureEntry particles_entry = { "particles.png", ParticlesPngProcess };

View File

@ -281,8 +281,7 @@ void Waitable_Wait(void* handle) {
void Waitable_WaitFor(void* handle, cc_uint32 milliseconds) { void Waitable_WaitFor(void* handle, cc_uint32 milliseconds) {
s64 timeout_ns = milliseconds * (1000 * 1000); // milliseconds to nanoseconds s64 timeout_ns = milliseconds * (1000 * 1000); // milliseconds to nanoseconds
int res = LightEvent_WaitTimeout((LightEvent*)handle, timeout_ns); LightEvent_WaitTimeout((LightEvent*)handle, timeout_ns);
if (res) Logger_Abort2(res, "Waiting timed event");
} }

View File

@ -141,7 +141,7 @@ void android_main(void) {
#elif defined CC_BUILD_CONSOLE #elif defined CC_BUILD_CONSOLE
int main(int argc, char** argv) { int main(int argc, char** argv) {
SetupProgram(argc, argv); SetupProgram(argc, argv);
while (WindowInfo.Exists) { while (Window_Main.Exists) {
RunProgram(argc, argv); RunProgram(argc, argv);
} }

View File

@ -327,9 +327,12 @@ static void SoundPatcher_Save(const char* name, struct HttpRequest* req) {
cc_string path; char pathBuffer[STRING_SIZE]; cc_string path; char pathBuffer[STRING_SIZE];
struct OggState ogg; struct OggState ogg;
struct Stream src, dst; struct Stream src, dst;
struct VorbisState ctx = { 0 }; struct VorbisState* ctx;
cc_result res; cc_result res;
ctx = (struct VorbisState*)Mem_TryAllocCleared(1, sizeof(struct VorbisState));
if (!ctx) { Logger_SysWarn(ERR_OUT_OF_MEMORY, "allocating memory"); return; }
Stream_ReadonlyMemory(&src, req->data, req->size); Stream_ReadonlyMemory(&src, req->data, req->size);
String_InitArray(path, pathBuffer); String_InitArray(path, pathBuffer);
String_Format1(&path, "audio/%c.wav", name); String_Format1(&path, "audio/%c.wav", name);
@ -338,12 +341,14 @@ static void SoundPatcher_Save(const char* name, struct HttpRequest* req) {
if (res) { Logger_SysWarn(res, "creating .wav file"); return; } if (res) { Logger_SysWarn(res, "creating .wav file"); return; }
Ogg_Init(&ogg, &src); Ogg_Init(&ogg, &src);
ctx.source = &ogg; ctx->source = &ogg;
SoundPatcher_WriteWav(&dst, &ctx); SoundPatcher_WriteWav(&dst, ctx);
res = dst.Close(&dst); res = dst.Close(&dst);
if (res) Logger_SysWarn(res, "closing .wav file"); if (res) Logger_SysWarn(res, "closing .wav file");
Vorbis_Free(&ctx);
Vorbis_Free(ctx);
Mem_Free(ctx);
} }

View File

@ -153,7 +153,7 @@ static SECURITY_STATUS SSL_Connect(struct SSLContext* ctx, const char* hostname)
out_desc.cBuffers = Array_Elems(out_buffers); out_desc.cBuffers = Array_Elems(out_buffers);
out_desc.pBuffers = out_buffers; out_desc.pBuffers = out_buffers;
res = FP_InitializeSecurityContextA(&ctx->handle, NULL, hostname, flags, 0, 0, res = FP_InitializeSecurityContextA(&ctx->handle, NULL, (char*)hostname, flags, 0, 0,
NULL, 0, &ctx->context, &out_desc, &flags, NULL); NULL, 0, &ctx->context, &out_desc, &flags, NULL);
if (res != SEC_I_CONTINUE_NEEDED) return res; if (res != SEC_I_CONTINUE_NEEDED) return res;
res = 0; res = 0;

View File

@ -336,15 +336,14 @@ static void HUDScreen_Update(void* screen, double delta) {
#define CH_EXTENT 16 #define CH_EXTENT 16
static void HUDScreen_BuildCrosshairsMesh(struct VertexTextured** ptr) { static void HUDScreen_BuildCrosshairsMesh(struct VertexTextured** ptr) {
static struct Texture tex = { 0, Tex_Rect(0,0,0,0), Tex_UV(0.0f,0.0f, 15/256.0f,15/256.0f) }; /* Only top quarter of icons.png is used */
static struct Texture tex = { 0, Tex_Rect(0,0,0,0), Tex_UV(0.0f,0.0f, 15/256.0f,15/64.0f) };
int extent; int extent;
enum Screen3DS scr = Window_3DS_SetRenderScreen(TOP_SCREEN); enum Screen3DS scr = Window_3DS_SetRenderScreen(TOP_SCREEN);
extent = (int)(CH_EXTENT * Gui_Scale(WindowInfo.Height / 480.0f)); extent = (int)(CH_EXTENT * Gui_Scale(Window_Main.Height / 480.0f));
tex.ID = Gui.IconsTex; tex.x = (Window_Main.Width / 2) - extent;
tex.x = (WindowInfo.Width / 2) - extent; tex.y = (Window_Main.Height / 2) - extent;
tex.y = (WindowInfo.Height / 2) - extent;
tex.Width = extent * 2; tex.Width = extent * 2;
tex.Height = extent * 2; tex.Height = extent * 2;
@ -520,9 +519,9 @@ static void TabListOverlay_Layout(void* screen) {
width += paddingX * 2; width += paddingX * 2;
height += paddingY * 2; height += paddingY * 2;
y = WindowInfo.Height / 4 - height / 2; y = Window_Main.Height / 4 - height / 2;
s->x = Gui_CalcPos(ANCHOR_CENTRE, 0, width , WindowInfo.Width ); s->x = Gui_CalcPos(ANCHOR_CENTRE, 0, width , Window_Main.Width );
s->y = Gui_CalcPos(ANCHOR_CENTRE, -max(0, y), height, WindowInfo.Height); s->y = Gui_CalcPos(ANCHOR_CENTRE, -max(0, y), height, Window_Main.Height);
x = s->x + paddingX; x = s->x + paddingX;
y = s->y + paddingY; y = s->y + paddingY;
@ -898,11 +897,11 @@ static void ChatScreen_UpdateChatYOffsets(struct ChatScreen* s) {
y = min(s->input.base.y, Gui_HUD->hotbar.y); y = min(s->input.base.y, Gui_HUD->hotbar.y);
y -= s->input.base.yOffset; /* add some padding */ y -= s->input.base.yOffset; /* add some padding */
s->altText.yOffset = WindowInfo.Height - y; s->altText.yOffset = Window_Main.Height - y;
Widget_Layout(&s->altText); Widget_Layout(&s->altText);
pad = s->altText.active ? 5 : 10; pad = s->altText.active ? 5 : 10;
s->clientStatus.yOffset = WindowInfo.Height - s->altText.y + pad; s->clientStatus.yOffset = Window_Main.Height - s->altText.y + pad;
Widget_Layout(&s->clientStatus); Widget_Layout(&s->clientStatus);
s->chat.yOffset = s->clientStatus.yOffset + s->clientStatus.height; s->chat.yOffset = s->clientStatus.yOffset + s->clientStatus.height;
Widget_Layout(&s->chat); Widget_Layout(&s->chat);
@ -1250,19 +1249,19 @@ static void ChatScreen_Layout(void* screen) {
Widget_Layout(&s->bottomRight); Widget_Layout(&s->bottomRight);
Widget_SetLocation(&s->announcement, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 0); Widget_SetLocation(&s->announcement, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 0);
s->announcement.yOffset = -WindowInfo.Height / 4; s->announcement.yOffset = -Window_Main.Height / 4;
Widget_Layout(&s->announcement); Widget_Layout(&s->announcement);
Widget_SetLocation(&s->bigAnnouncement, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 0); Widget_SetLocation(&s->bigAnnouncement, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 0);
s->bigAnnouncement.yOffset = -WindowInfo.Height / 16; s->bigAnnouncement.yOffset = -Window_Main.Height / 16;
Widget_Layout(&s->bigAnnouncement); Widget_Layout(&s->bigAnnouncement);
Widget_SetLocation(&s->smallAnnouncement, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 0); Widget_SetLocation(&s->smallAnnouncement, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 0);
s->smallAnnouncement.yOffset = WindowInfo.Height / 20; s->smallAnnouncement.yOffset = Window_Main.Height / 20;
Widget_Layout(&s->smallAnnouncement); Widget_Layout(&s->smallAnnouncement);
#ifdef CC_BUILD_TOUCH #ifdef CC_BUILD_TOUCH
if (WindowInfo.SoftKeyboard == SOFT_KEYBOARD_SHIFT) { if (Window_Main.SoftKeyboard == SOFT_KEYBOARD_SHIFT) {
Widget_SetLocation(&s->send, ANCHOR_MAX, ANCHOR_MAX, 10, 60); Widget_SetLocation(&s->send, ANCHOR_MAX, ANCHOR_MAX, 10, 60);
Widget_SetLocation(&s->cancel, ANCHOR_MAX, ANCHOR_MAX, 10, 10); Widget_SetLocation(&s->cancel, ANCHOR_MAX, ANCHOR_MAX, 10, 10);
Widget_SetLocation(&s->more, ANCHOR_MAX, ANCHOR_MAX, 10, 110); Widget_SetLocation(&s->more, ANCHOR_MAX, ANCHOR_MAX, 10, 110);
@ -1358,7 +1357,7 @@ static void ChatScreen_KeyUp(void* screen, int key) {
#endif #endif
if (Server.SupportsFullCP437 && KeyBind_Claims(KEYBIND_EXT_INPUT, key)) { if (Server.SupportsFullCP437 && KeyBind_Claims(KEYBIND_EXT_INPUT, key)) {
if (!WindowInfo.Focused) return; if (!Window_Main.Focused) return;
ChatScreen_ToggleAltInput(s); ChatScreen_ToggleAltInput(s);
} }
} }
@ -1792,7 +1791,7 @@ static void LoadingScreen_SetMessage(struct LoadingScreen* s) {
} }
static void LoadingScreen_CalcMaxVertices(struct LoadingScreen* s) { static void LoadingScreen_CalcMaxVertices(struct LoadingScreen* s) {
s->rows = Math_CeilDiv(WindowInfo.Height, LOADING_TILE_SIZE); s->rows = Math_CeilDiv(Window_Main.Height, LOADING_TILE_SIZE);
s->maxVertices = Screen_CalcDefaultMaxVertices(s) + s->rows * 4; s->maxVertices = Screen_CalcDefaultMaxVertices(s) + s->rows * 4;
} }
@ -1804,9 +1803,9 @@ static void LoadingScreen_Layout(void* screen) {
y = Display_ScaleY(34); y = Display_ScaleY(34);
s->progWidth = Display_ScaleX(200); s->progWidth = Display_ScaleX(200);
s->progX = Gui_CalcPos(ANCHOR_CENTRE, 0, s->progWidth, WindowInfo.Width); s->progX = Gui_CalcPos(ANCHOR_CENTRE, 0, s->progWidth, Window_Main.Width);
s->progHeight = Display_ScaleY(4); s->progHeight = Display_ScaleY(4);
s->progY = Gui_CalcPos(ANCHOR_CENTRE, y, s->progHeight, WindowInfo.Height); s->progY = Gui_CalcPos(ANCHOR_CENTRE, y, s->progHeight, Window_Main.Height);
oldRows = s->rows; oldRows = s->rows;
LoadingScreen_CalcMaxVertices(s); LoadingScreen_CalcMaxVertices(s);
@ -1840,9 +1839,9 @@ static void LoadingScreen_BuildMesh(void* screen) {
ptr = &data; ptr = &data;
loc = Block_Tex(BLOCK_DIRT, FACE_YMAX); loc = Block_Tex(BLOCK_DIRT, FACE_YMAX);
Tex_SetRect(tex, 0,0, WindowInfo.Width,LOADING_TILE_SIZE); Tex_SetRect(tex, 0,0, Window_Main.Width,LOADING_TILE_SIZE);
tex.uv = Atlas1D_TexRec(loc, 1, &atlasIndex); tex.uv = Atlas1D_TexRec(loc, 1, &atlasIndex);
tex.uv.U2 = (float)WindowInfo.Width / LOADING_TILE_SIZE; tex.uv.U2 = (float)Window_Main.Width / LOADING_TILE_SIZE;
for (i = 0; i < s->rows; i++) { for (i = 0; i < s->rows; i++) {
tex.y = i * LOADING_TILE_SIZE; tex.y = i * LOADING_TILE_SIZE;
@ -2116,7 +2115,7 @@ static void DisconnectScreen_Update(void* screen, double delta) {
static void DisconnectScreen_Render(void* screen, double delta) { static void DisconnectScreen_Render(void* screen, double delta) {
PackedCol top = PackedCol_Make(64, 32, 32, 255); PackedCol top = PackedCol_Make(64, 32, 32, 255);
PackedCol bottom = PackedCol_Make(80, 16, 16, 255); PackedCol bottom = PackedCol_Make(80, 16, 16, 255);
Gfx_Draw2DGradient(0, 0, WindowInfo.Width, WindowInfo.Height, top, bottom); Gfx_Draw2DGradient(0, 0, Window_Main.Width, Window_Main.Height, top, bottom);
Screen_Render2Widgets(screen, delta); Screen_Render2Widgets(screen, delta);
} }

View File

@ -127,13 +127,19 @@ static void SPConnection_BeginConnect(void) {
Random_SeedFromCurrentTime(&rnd); Random_SeedFromCurrentTime(&rnd);
World_NewMap(); World_NewMap();
#if defined CC_BUILD_LOWMEM #if defined CC_BUILD_LOWMEM
World_SetDimensions(64, 64, 64); World_SetDimensions(64, 64, 64);
#else #else
World_SetDimensions(128, 64, 128); World_SetDimensions(128, 64, 128);
#endif #endif
#ifdef CC_BUILD_N64
Gen_Active = &FlatgrassGen;
#else
Gen_Active = &NotchyGen; Gen_Active = &NotchyGen;
#endif
Gen_Seed = Random_Next(&rnd, Int32_MaxValue); Gen_Seed = Random_Next(&rnd, Int32_MaxValue);
Gen_Start(); Gen_Start();

View File

@ -17,7 +17,6 @@
#include "Block.h" #include "Block.h"
#include "Input.h" #include "Input.h"
#define Widget_UV(u1,v1, u2,v2) Tex_UV(u1/256.0f,v1/256.0f, u2/256.0f,v2/256.0f)
static void Widget_NullFunc(void* widget) { } static void Widget_NullFunc(void* widget) { }
static int Widget_Pointer(void* elem, int id, int x, int y) { return false; } static int Widget_Pointer(void* elem, int id, int x, int y) { return false; }
static void Widget_InputUp(void* elem, int key) { } static void Widget_InputUp(void* elem, int key) { }
@ -98,10 +97,12 @@ void TextWidget_SetConst(struct TextWidget* w, const char* text, struct FontDesc
*------------------------------------------------------ButtonWidget-------------------------------------------------------* *------------------------------------------------------ButtonWidget-------------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
#define BUTTON_uWIDTH (200.0f / 256.0f) #define BUTTON_uWIDTH (200.0f / 256.0f)
/* Only top half of gui.png is used */
#define Button_UV(u1,v1, u2,v2) Tex_UV(u1/256.0f,v1/128.0f, u2/256.0f,v2/128.0f)
static struct Texture btnShadowTex = { 0, Tex_Rect(0,0, 0,0), Widget_UV(0,66, 200,86) }; static struct Texture btnShadowTex = { 0, Tex_Rect(0,0, 0,0), Button_UV(0,66, 200,86) };
static struct Texture btnSelectedTex = { 0, Tex_Rect(0,0, 0,0), Widget_UV(0,86, 200,106) }; static struct Texture btnSelectedTex = { 0, Tex_Rect(0,0, 0,0), Button_UV(0,86, 200,106) };
static struct Texture btnDisabledTex = { 0, Tex_Rect(0,0, 0,0), Widget_UV(0,46, 200,66) }; static struct Texture btnDisabledTex = { 0, Tex_Rect(0,0, 0,0), Button_UV(0,46, 200,66) };
static void ButtonWidget_Free(void* widget) { static void ButtonWidget_Free(void* widget) {
struct ButtonWidget* w = (struct ButtonWidget*)widget; struct ButtonWidget* w = (struct ButtonWidget*)widget;
@ -512,11 +513,13 @@ static void HotbarWidget_Reposition(void* widget) {
w->slotWidth = 20.0f * scaleX; w->slotWidth = 20.0f * scaleX;
Tex_SetRect(w->backTex, w->x,w->y, w->width,w->height); Tex_SetRect(w->backTex, w->x,w->y, w->width,w->height);
Tex_SetUV(w->backTex, 0,0, 182/256.0f,22/256.0f); /* Only top half of gui png is used */
Tex_SetUV(w->backTex, 0,0, 182/256.0f,22/128.0f);
y = w->y + (w->height - (int)(23.0f * scaleY)); y = w->y + (w->height - (int)(23.0f * scaleY));
Tex_SetRect(w->selTex, 0,y, (int)w->selWidth,w->height); Tex_SetRect(w->selTex, 0,y, (int)w->selWidth,w->height);
Tex_SetUV(w->selTex, 0,22/256.0f, 24/256.0f,44/256.0f); /* Only top half of gui png is used */
Tex_SetUV(w->selTex, 0,22/128.0f, 24/256.0f,44/128.0f);
} }
static int HotbarWidget_MapKey(int key) { static int HotbarWidget_MapKey(int key) {
@ -570,7 +573,7 @@ static void HotbarWidget_InputUp(void* widget, int key) {
if (w->altHandled) { w->altHandled = false; return; } /* handled already */ if (w->altHandled) { w->altHandled = false; return; } /* handled already */
/* Don't switch hotbar when alt+tabbing to another window */ /* Don't switch hotbar when alt+tabbing to another window */
if (WindowInfo.Focused) Inventory_SwitchHotbar(); if (Window_Main.Focused) Inventory_SwitchHotbar();
} }
static int HotbarWidget_PointerDown(void* widget, int id, int x, int y) { static int HotbarWidget_PointerDown(void* widget, int id, int x, int y) {
@ -1785,7 +1788,7 @@ static void ChatInputWidget_Render(void* widget, double delta) {
caretAtEnd = (w->caretY == i) && (w->caretX == INPUTWIDGET_LEN || w->caretPos == -1); caretAtEnd = (w->caretY == i) && (w->caretX == INPUTWIDGET_LEN || w->caretPos == -1);
width = w->lineWidths[i] + (caretAtEnd ? w->caretTex.Width : 0); width = w->lineWidths[i] + (caretAtEnd ? w->caretTex.Width : 0);
/* Cover whole window width to match Minecraft behaviour */ /* Cover whole window width to match Minecraft behaviour */
width = max(width, WindowInfo.Width - x * 4); width = max(width, Window_Main.Width - x * 4);
Gfx_Draw2DFlat(x, y, width + w->padding * 2, w->lineHeight, backColor); Gfx_Draw2DFlat(x, y, width + w->padding * 2, w->lineHeight, backColor);
y += w->lineHeight; y += w->lineHeight;
@ -2040,7 +2043,7 @@ static void TextGroupWidget_Reposition(void* widget) {
for (i = 0, y = w->y; i < w->lines; i++) for (i = 0, y = w->y; i < w->lines; i++)
{ {
textures[i].x = Gui_CalcPos(w->horAnchor, w->xOffset, textures[i].Width, WindowInfo.Width); textures[i].x = Gui_CalcPos(w->horAnchor, w->xOffset, textures[i].Width, Window_Main.Width);
textures[i].y = y; textures[i].y = y;
y += textures[i].Height; y += textures[i].Height;
} }
@ -2318,7 +2321,7 @@ void TextGroupWidget_Redraw(struct TextGroupWidget* w, int index) {
tex.Height = w->collapsible[index] ? 0 : w->defaultHeight; tex.Height = w->collapsible[index] ? 0 : w->defaultHeight;
} }
tex.x = Gui_CalcPos(w->horAnchor, w->xOffset, tex.Width, WindowInfo.Width); tex.x = Gui_CalcPos(w->horAnchor, w->xOffset, tex.Width, Window_Main.Width);
w->textures[index] = tex; w->textures[index] = tex;
Widget_Layout(w); Widget_Layout(w);
} }

View File

@ -68,8 +68,8 @@ static CC_INLINE int Display_ScaleX(int x) { return (int)(x * DisplayInfo.ScaleX
/* Scales the given Y coordinate from 96 dpi to current display dpi. */ /* Scales the given Y coordinate from 96 dpi to current display dpi. */
static CC_INLINE int Display_ScaleY(int y) { return (int)(y * DisplayInfo.ScaleY); } static CC_INLINE int Display_ScaleY(int y) { return (int)(y * DisplayInfo.ScaleY); }
/* Data for the game/launcher window. */ /* Data for a window */
CC_VAR extern struct _WinData { struct _WindowData {
/* Readonly platform-specific handle to the window. */ /* Readonly platform-specific handle to the window. */
void* Handle; void* Handle;
/* Size of the content area of the window. (i.e. area that can draw to) */ /* Size of the content area of the window. (i.e. area that can draw to) */
@ -84,7 +84,13 @@ CC_VAR extern struct _WinData {
/* Whether this window is backgrounded / inactivated */ /* Whether this window is backgrounded / inactivated */
/* (rendering is not performed when window is inactive) */ /* (rendering is not performed when window is inactive) */
cc_bool Inactive; cc_bool Inactive;
} WindowInfo; };
/* Data for the game/launcher window */
CC_VAR extern struct _WindowData WindowInfo; /* Named WindowInfo for backwards compatibility */
#define Window_Main WindowInfo
/* Data for alternate game window (e.g. 3DS) */
extern struct _WindowData Window_Alt;
/* Initialises state for window, input, and display. */ /* Initialises state for window, input, and display. */
void Window_Init(void); void Window_Init(void);

View File

@ -18,7 +18,8 @@ static Result irrst_result;
static enum Screen3DS renderScreen = TOP_SCREEN; static enum Screen3DS renderScreen = TOP_SCREEN;
struct _DisplayData DisplayInfo; struct _DisplayData DisplayInfo;
struct _WinData WindowInfo; struct _WindowData WindowInfo;
struct _WindowData Window_Alt;
// Note from https://github.com/devkitPro/libctru/blob/master/libctru/include/3ds/gfx.h // Note from https://github.com/devkitPro/libctru/blob/master/libctru/include/3ds/gfx.h
@ -40,17 +41,21 @@ void Window_Init(void) {
DisplayInfo.Width = height; // deliberately swapped DisplayInfo.Width = height; // deliberately swapped
DisplayInfo.Height = width; // deliberately swapped DisplayInfo.Height = width; // deliberately swapped
DisplayInfo.Depth = 4; // 32 bit DisplayInfo.Depth = 4; // 32 bit
DisplayInfo.ScaleX = 0.5; DisplayInfo.ScaleX = 0.5f;
DisplayInfo.ScaleY = 0.5; DisplayInfo.ScaleY = 0.5f;
WindowInfo.Width = height; // deliberately swapped Window_Main.Width = height; // deliberately swapped
WindowInfo.Height = width; // deliberately swapped Window_Main.Height = width; // deliberately swapped
WindowInfo.Focused = true; Window_Main.Focused = true;
WindowInfo.Exists = true; Window_Main.Exists = true;
Input_SetTouchMode(true); Input_SetTouchMode(true);
Input.Sources = INPUT_SOURCE_GAMEPAD; Input.Sources = INPUT_SOURCE_GAMEPAD;
irrst_result = irrstInit(); irrst_result = irrstInit();
gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, &width, &height);
Window_Alt.Width = height; // deliberately swapped
Window_Alt.Height = width; // deliberately swapped
} }
void Window_Free(void) { irrstExit(); } void Window_Free(void) { irrstExit(); }
@ -133,7 +138,7 @@ static void ProcessTouchInput(int mods) {
if (touchActive) { if (touchActive) {
// rescale X from [0, bottom_FB_width) to [0, top_FB_width) // rescale X from [0, bottom_FB_width) to [0, top_FB_width)
int x = touch.px * WindowInfo.Width / GSP_SCREEN_HEIGHT_BOTTOM; int x = touch.px * Window_Main.Width / GSP_SCREEN_HEIGHT_BOTTOM;
int y = touch.py; int y = touch.py;
Pointer_SetPosition(0, x, y); Pointer_SetPosition(0, x, y);
} }
@ -158,7 +163,7 @@ void Window_ProcessEvents(double delta) {
/* TODO implement */ /* TODO implement */
if (!aptMainLoop()) { if (!aptMainLoop()) {
WindowInfo.Exists = false; Window_Main.Exists = false;
Window_RequestClose(); Window_RequestClose();
return; return;
} }

View File

@ -20,9 +20,9 @@ static jmethodID JAVA_processedSurfaceDestroyed, JAVA_processEvents;
static jmethodID JAVA_getDpiX, JAVA_getDpiY, JAVA_setupForGame; static jmethodID JAVA_getDpiX, JAVA_getDpiY, JAVA_setupForGame;
static void RefreshWindowBounds(void) { static void RefreshWindowBounds(void) {
WindowInfo.Width = ANativeWindow_getWidth(win_handle); Window_Main.Width = ANativeWindow_getWidth(win_handle);
WindowInfo.Height = ANativeWindow_getHeight(win_handle); Window_Main.Height = ANativeWindow_getHeight(win_handle);
Platform_Log2("SCREEN BOUNDS: %i,%i", &WindowInfo.Width, &WindowInfo.Height); Platform_Log2("SCREEN BOUNDS: %i,%i", &Window_Main.Width, &Window_Main.Height);
Event_RaiseVoid(&WindowEvents.Resized); Event_RaiseVoid(&WindowEvents.Resized);
} }
@ -149,7 +149,7 @@ static void JNICALL java_processSurfaceCreated(JNIEnv* env, jobject o, jobject s
Platform_LogConst("WIN - CREATED"); Platform_LogConst("WIN - CREATED");
win_handle = ANativeWindow_fromSurface(env, surface); win_handle = ANativeWindow_fromSurface(env, surface);
winCreated = true; winCreated = true;
WindowInfo.Handle = win_handle; Window_Main.Handle = win_handle;
RefreshWindowBounds(); RefreshWindowBounds();
/* TODO: Restore context */ /* TODO: Restore context */
Event_RaiseVoid(&WindowEvents.Created); Event_RaiseVoid(&WindowEvents.Created);
@ -160,7 +160,7 @@ static void JNICALL java_processSurfaceDestroyed(JNIEnv* env, jobject o) {
if (win_handle) ANativeWindow_release(win_handle); if (win_handle) ANativeWindow_release(win_handle);
win_handle = NULL; win_handle = NULL;
WindowInfo.Handle = NULL; Window_Main.Handle = NULL;
/* eglSwapBuffers might return EGL_BAD_SURFACE, EGL_BAD_ALLOC, or some other error */ /* eglSwapBuffers might return EGL_BAD_SURFACE, EGL_BAD_ALLOC, or some other error */
/* Instead the context is lost here in a consistent manner */ /* Instead the context is lost here in a consistent manner */
if (Gfx.Created) Gfx_LoseContext("surface lost"); if (Gfx.Created) Gfx_LoseContext("surface lost");
@ -198,20 +198,20 @@ static void JNICALL java_onPause(JNIEnv* env, jobject o) {
static void JNICALL java_onDestroy(JNIEnv* env, jobject o) { static void JNICALL java_onDestroy(JNIEnv* env, jobject o) {
Platform_LogConst("APP - ON DESTROY"); Platform_LogConst("APP - ON DESTROY");
if (WindowInfo.Exists) Window_RequestClose(); if (Window_Main.Exists) Window_RequestClose();
/* TODO: signal to java code we're done */ /* TODO: signal to java code we're done */
/* JavaICall_Void(env, JAVA_processedDestroyed", NULL); */ /* JavaICall_Void(env, JAVA_processedDestroyed", NULL); */
} }
static void JNICALL java_onGotFocus(JNIEnv* env, jobject o) { static void JNICALL java_onGotFocus(JNIEnv* env, jobject o) {
Platform_LogConst("APP - GOT FOCUS"); Platform_LogConst("APP - GOT FOCUS");
WindowInfo.Focused = true; Window_Main.Focused = true;
Event_RaiseVoid(&WindowEvents.FocusChanged); Event_RaiseVoid(&WindowEvents.FocusChanged);
} }
static void JNICALL java_onLostFocus(JNIEnv* env, jobject o) { static void JNICALL java_onLostFocus(JNIEnv* env, jobject o) {
Platform_LogConst("APP - LOST FOCUS"); Platform_LogConst("APP - LOST FOCUS");
WindowInfo.Focused = false; Window_Main.Focused = false;
Event_RaiseVoid(&WindowEvents.FocusChanged); Event_RaiseVoid(&WindowEvents.FocusChanged);
/* TODO: Disable rendering? */ /* TODO: Disable rendering? */
} }
@ -280,7 +280,7 @@ void Window_Init(void) {
JavaRegisterNatives(env, methods); JavaRegisterNatives(env, methods);
CacheMethodRefs(env); CacheMethodRefs(env);
WindowInfo.SoftKeyboard = SOFT_KEYBOARD_RESIZE; Window_Main.SoftKeyboard = SOFT_KEYBOARD_RESIZE;
Input_SetTouchMode(true); Input_SetTouchMode(true);
Input.Sources = INPUT_SOURCE_NORMAL; Input.Sources = INPUT_SOURCE_NORMAL;
@ -312,7 +312,7 @@ static void RemakeWindowSurface(void) {
} }
static void DoCreateWindow(void) { static void DoCreateWindow(void) {
WindowInfo.Exists = true; Window_Main.Exists = true;
RemakeWindowSurface(); RemakeWindowSurface();
/* always start as fullscreen */ /* always start as fullscreen */
Window_EnterFullscreen(); Window_EnterFullscreen();
@ -358,7 +358,7 @@ void Window_Show(void) { } /* Window already visible */
void Window_SetSize(int width, int height) { } void Window_SetSize(int width, int height) { }
void Window_RequestClose(void) { void Window_RequestClose(void) {
WindowInfo.Exists = false; Window_Main.Exists = false;
Event_RaiseVoid(&WindowEvents.Closing); Event_RaiseVoid(&WindowEvents.Closing);
/* TODO: Do we need to call finish here */ /* TODO: Do we need to call finish here */
/* ANativeActivity_finish(app->activity); */ /* ANativeActivity_finish(app->activity); */

View File

@ -163,8 +163,8 @@ static void RefreshWindowBounds(void) {
/* TODO: kWindowContentRgn ??? */ /* TODO: kWindowContentRgn ??? */
GetWindowBounds(win_handle, kWindowGlobalPortRgn, &r); GetWindowBounds(win_handle, kWindowGlobalPortRgn, &r);
windowX = r.left; WindowInfo.Width = r.right - r.left; windowX = r.left; Window_Main.Width = r.right - r.left;
windowY = r.top; WindowInfo.Height = r.bottom - r.top; windowY = r.top; Window_Main.Height = r.bottom - r.top;
} }
static OSStatus Window_ProcessKeyboardEvent(EventRef inEvent) { static OSStatus Window_ProcessKeyboardEvent(EventRef inEvent) {
@ -209,30 +209,30 @@ static OSStatus Window_ProcessWindowEvent(EventRef inEvent) {
switch (GetEventKind(inEvent)) { switch (GetEventKind(inEvent)) {
case kEventWindowClose: case kEventWindowClose:
WindowInfo.Exists = false; Window_Main.Exists = false;
Event_RaiseVoid(&WindowEvents.Closing); Event_RaiseVoid(&WindowEvents.Closing);
return eventNotHandledErr; return eventNotHandledErr;
case kEventWindowClosed: case kEventWindowClosed:
WindowInfo.Exists = false; Window_Main.Exists = false;
return 0; return 0;
case kEventWindowBoundsChanged: case kEventWindowBoundsChanged:
oldWidth = WindowInfo.Width; oldHeight = WindowInfo.Height; oldWidth = Window_Main.Width; oldHeight = Window_Main.Height;
RefreshWindowBounds(); RefreshWindowBounds();
if (oldWidth != WindowInfo.Width || oldHeight != WindowInfo.Height) { if (oldWidth != Window_Main.Width || oldHeight != Window_Main.Height) {
Event_RaiseVoid(&WindowEvents.Resized); Event_RaiseVoid(&WindowEvents.Resized);
} }
return eventNotHandledErr; return eventNotHandledErr;
case kEventWindowActivated: case kEventWindowActivated:
WindowInfo.Focused = true; Window_Main.Focused = true;
Event_RaiseVoid(&WindowEvents.FocusChanged); Event_RaiseVoid(&WindowEvents.FocusChanged);
return eventNotHandledErr; return eventNotHandledErr;
case kEventWindowDeactivated: case kEventWindowDeactivated:
WindowInfo.Focused = false; Window_Main.Focused = false;
Event_RaiseVoid(&WindowEvents.FocusChanged); Event_RaiseVoid(&WindowEvents.FocusChanged);
return eventNotHandledErr; return eventNotHandledErr;
@ -285,8 +285,8 @@ static OSStatus Window_ProcessMouseEvent(EventRef inEvent) {
if (!win_fullscreen) { if (!win_fullscreen) {
mouseX -= windowX; mouseY -= windowY; mouseX -= windowX; mouseY -= windowY;
if (mouseX < 0 || mouseX >= WindowInfo.Width) return eventNotHandledErr; if (mouseX < 0 || mouseX >= Window_Main.Width) return eventNotHandledErr;
if (mouseY < 0 || mouseY >= WindowInfo.Height) return eventNotHandledErr; if (mouseY < 0 || mouseY >= Window_Main.Height) return eventNotHandledErr;
} }
kind = GetEventKind(inEvent); kind = GetEventKind(inEvent);
@ -501,8 +501,8 @@ static void DoCreateWindow(int width, int height) {
/* TODO: Use BringWindowToFront instead.. (look in the file which has RepositionWindow in it) !!!! */ /* TODO: Use BringWindowToFront instead.. (look in the file which has RepositionWindow in it) !!!! */
HookEvents(); HookEvents();
Window_CommonCreate(); Window_CommonCreate();
WindowInfo.Exists = true; Window_Main.Exists = true;
WindowInfo.Handle = win_handle; Window_Main.Handle = win_handle;
/* CGAssociateMouseAndMouseCursorPosition implicitly grabs cursor */ /* CGAssociateMouseAndMouseCursorPosition implicitly grabs cursor */
conn = _CGSDefaultConnection(); conn = _CGSDefaultConnection();
@ -549,8 +549,8 @@ void Window_SetSize(int width, int height) {
void Window_RequestClose(void) { void Window_RequestClose(void) {
/* DisposeWindow only sends a kEventWindowClosed */ /* DisposeWindow only sends a kEventWindowClosed */
Event_RaiseVoid(&WindowEvents.Closing); Event_RaiseVoid(&WindowEvents.Closing);
if (WindowInfo.Exists) DisposeWindow(win_handle); if (Window_Main.Exists) DisposeWindow(win_handle);
WindowInfo.Exists = false; Window_Main.Exists = false;
} }
void Window_ProcessEvents(double delta) { void Window_ProcessEvents(double delta) {
@ -626,8 +626,8 @@ void Window_DrawFramebuffer(Rect2D r) {
/* TODO: Only update changed bit.. */ /* TODO: Only update changed bit.. */
rect.origin.x = 0; rect.origin.y = 0; rect.origin.x = 0; rect.origin.y = 0;
rect.size.width = WindowInfo.Width; rect.size.width = Window_Main.Width;
rect.size.height = WindowInfo.Height; rect.size.height = Window_Main.Height;
err = QDBeginCGContext(fb_port, &context); err = QDBeginCGContext(fb_port, &context);
if (err) Logger_Abort2(err, "Begin draw"); if (err) Logger_Abort2(err, "Begin draw");
@ -700,11 +700,11 @@ cc_result Window_EnterFullscreen(void) {
} }
win_fullscreen = true; win_fullscreen = true;
ctx_windowWidth = WindowInfo.Width; ctx_windowWidth = Window_Main.Width;
ctx_windowHeight = WindowInfo.Height; ctx_windowHeight = Window_Main.Height;
windowX = DisplayInfo.x; WindowInfo.Width = DisplayInfo.Width; windowX = DisplayInfo.x; Window_Main.Width = DisplayInfo.Width;
windowY = DisplayInfo.y; WindowInfo.Height = DisplayInfo.Height; windowY = DisplayInfo.y; Window_Main.Height = DisplayInfo.Height;
Event_RaiseVoid(&WindowEvents.Resized); Event_RaiseVoid(&WindowEvents.Resized);
return 0; return 0;

View File

@ -14,7 +14,7 @@
static cc_bool launcherMode; static cc_bool launcherMode;
struct _DisplayData DisplayInfo; struct _DisplayData DisplayInfo;
struct _WinData WindowInfo; struct _WindowData WindowInfo;
void Window_Init(void) { void Window_Init(void) {
DisplayInfo.Width = vid_mode->width; DisplayInfo.Width = vid_mode->width;
@ -23,10 +23,10 @@ void Window_Init(void) {
DisplayInfo.ScaleX = 1; DisplayInfo.ScaleX = 1;
DisplayInfo.ScaleY = 1; DisplayInfo.ScaleY = 1;
WindowInfo.Width = vid_mode->width; Window_Main.Width = vid_mode->width;
WindowInfo.Height = vid_mode->height; Window_Main.Height = vid_mode->height;
WindowInfo.Focused = true; Window_Main.Focused = true;
WindowInfo.Exists = true; Window_Main.Exists = true;
Input.Sources = INPUT_SOURCE_GAMEPAD; Input.Sources = INPUT_SOURCE_GAMEPAD;
DisplayInfo.ContentOffsetX = 10; DisplayInfo.ContentOffsetX = 10;

View File

@ -22,11 +22,11 @@ static void* xfb;
static GXRModeObj* rmode; static GXRModeObj* rmode;
void* Window_XFB; void* Window_XFB;
struct _DisplayData DisplayInfo; struct _DisplayData DisplayInfo;
struct _WinData WindowInfo; struct _WindowData WindowInfo;
static void OnPowerOff(void) { static void OnPowerOff(void) {
WindowInfo.Exists = false; Window_Main.Exists = false;
Window_RequestClose(); Window_RequestClose();
} }
static void InitVideo(void) { static void InitVideo(void) {
@ -67,10 +67,10 @@ void Window_Init(void) {
DisplayInfo.ScaleX = 1; DisplayInfo.ScaleX = 1;
DisplayInfo.ScaleY = 1; DisplayInfo.ScaleY = 1;
WindowInfo.Width = rmode->fbWidth; Window_Main.Width = rmode->fbWidth;
WindowInfo.Height = rmode->xfbHeight; Window_Main.Height = rmode->xfbHeight;
WindowInfo.Focused = true; Window_Main.Focused = true;
WindowInfo.Exists = true; Window_Main.Exists = true;
Input.Sources = INPUT_SOURCE_GAMEPAD; Input.Sources = INPUT_SOURCE_GAMEPAD;
DisplayInfo.ContentOffsetX = 10; DisplayInfo.ContentOffsetX = 10;

View File

@ -15,7 +15,7 @@
static cc_bool launcherMode; static cc_bool launcherMode;
struct _DisplayData DisplayInfo; struct _DisplayData DisplayInfo;
struct _WinData WindowInfo; struct _WindowData WindowInfo;
void Window_Init(void) { void Window_Init(void) {
display_init(RESOLUTION_320x240, DEPTH_32_BPP, 2, GAMMA_NONE, FILTERS_DISABLED); display_init(RESOLUTION_320x240, DEPTH_32_BPP, 2, GAMMA_NONE, FILTERS_DISABLED);
@ -27,10 +27,10 @@ void Window_Init(void) {
DisplayInfo.ScaleX = 0.5f; DisplayInfo.ScaleX = 0.5f;
DisplayInfo.ScaleY = 0.5f; DisplayInfo.ScaleY = 0.5f;
WindowInfo.Width = DisplayInfo.Width; Window_Main.Width = DisplayInfo.Width;
WindowInfo.Height = DisplayInfo.Height; Window_Main.Height = DisplayInfo.Height;
WindowInfo.Focused = true; Window_Main.Focused = true;
WindowInfo.Exists = true; Window_Main.Exists = true;
Input.Sources = INPUT_SOURCE_GAMEPAD; Input.Sources = INPUT_SOURCE_GAMEPAD;
DisplayInfo.ContentOffsetX = 10; DisplayInfo.ContentOffsetX = 10;
@ -39,7 +39,15 @@ void Window_Init(void) {
// change defaults to make more sense for N64 // change defaults to make more sense for N64
cc_uint8* binds = (cc_uint8*)KeyBind_GamepadDefaults; cc_uint8* binds = (cc_uint8*)KeyBind_GamepadDefaults;
binds[KEYBIND_INVENTORY] = CCPAD_Z; binds[KEYBIND_INVENTORY] = CCPAD_B;
binds[KEYBIND_PLACE_BLOCK] = CCPAD_Z;
binds[KEYBIND_HOTBAR_RIGHT] = CCPAD_L;
binds[KEYBIND_DELETE_BLOCK] = CCPAD_R;
binds[KEYBIND_FORWARD] = CCPAD_CUP;
binds[KEYBIND_BACK] = CCPAD_CDOWN;
binds[KEYBIND_LEFT] = CCPAD_CLEFT;
binds[KEYBIND_RIGHT] = CCPAD_CRIGHT;
} }
void Window_Free(void) { } void Window_Free(void) { }

View File

@ -25,7 +25,7 @@ static cc_bool launcherMode;
static char padBuf[256] __attribute__((aligned(64))); static char padBuf[256] __attribute__((aligned(64)));
struct _DisplayData DisplayInfo; struct _DisplayData DisplayInfo;
struct _WinData WindowInfo; struct _WindowData WindowInfo;
void Window_Init(void) { void Window_Init(void) {
DisplayInfo.Width = 640; DisplayInfo.Width = 640;
@ -34,10 +34,10 @@ void Window_Init(void) {
DisplayInfo.ScaleX = 1; DisplayInfo.ScaleX = 1;
DisplayInfo.ScaleY = 1; DisplayInfo.ScaleY = 1;
WindowInfo.Width = DisplayInfo.Width; Window_Main.Width = DisplayInfo.Width;
WindowInfo.Height = DisplayInfo.Height; Window_Main.Height = DisplayInfo.Height;
WindowInfo.Focused = true; Window_Main.Focused = true;
WindowInfo.Exists = true; Window_Main.Exists = true;
Input.Sources = INPUT_SOURCE_GAMEPAD; Input.Sources = INPUT_SOURCE_GAMEPAD;
DisplayInfo.ContentOffsetX = 10; DisplayInfo.ContentOffsetX = 10;

View File

@ -24,12 +24,12 @@ static KbData kb_data;
static KbConfig kb_config; static KbConfig kb_config;
struct _DisplayData DisplayInfo; struct _DisplayData DisplayInfo;
struct _WinData WindowInfo; struct _WindowData WindowInfo;
static void sysutil_callback(u64 status, u64 param, void* usrdata) { static void sysutil_callback(u64 status, u64 param, void* usrdata) {
switch (status) { switch (status) {
case SYSUTIL_EXIT_GAME: case SYSUTIL_EXIT_GAME:
WindowInfo.Exists = false; Window_Main.Exists = false;
Window_RequestClose(); Window_RequestClose();
break; break;
} }
@ -50,10 +50,10 @@ void Window_Init(void) {
DisplayInfo.ScaleX = 1; DisplayInfo.ScaleX = 1;
DisplayInfo.ScaleY = 1; DisplayInfo.ScaleY = 1;
WindowInfo.Width = resolution.width; Window_Main.Width = resolution.width;
WindowInfo.Height = resolution.height; Window_Main.Height = resolution.height;
WindowInfo.Focused = true; Window_Main.Focused = true;
WindowInfo.Exists = true; Window_Main.Exists = true;
Input.Sources = INPUT_SOURCE_GAMEPAD; Input.Sources = INPUT_SOURCE_GAMEPAD;
DisplayInfo.ContentOffsetX = 20; DisplayInfo.ContentOffsetX = 20;

View File

@ -20,7 +20,7 @@
static cc_bool launcherMode; static cc_bool launcherMode;
struct _DisplayData DisplayInfo; struct _DisplayData DisplayInfo;
struct _WinData WindowInfo; struct _WindowData WindowInfo;
void Window_Init(void) { void Window_Init(void) {
DisplayInfo.Width = SCREEN_WIDTH; DisplayInfo.Width = SCREEN_WIDTH;
@ -29,10 +29,10 @@ void Window_Init(void) {
DisplayInfo.ScaleX = 1; DisplayInfo.ScaleX = 1;
DisplayInfo.ScaleY = 1; DisplayInfo.ScaleY = 1;
WindowInfo.Width = SCREEN_WIDTH; Window_Main.Width = SCREEN_WIDTH;
WindowInfo.Height = SCREEN_HEIGHT; Window_Main.Height = SCREEN_HEIGHT;
WindowInfo.Focused = true; Window_Main.Focused = true;
WindowInfo.Exists = true; Window_Main.Exists = true;
Input.Sources = INPUT_SOURCE_GAMEPAD; Input.Sources = INPUT_SOURCE_GAMEPAD;
sceCtrlSetSamplingCycle(0); sceCtrlSetSamplingCycle(0);

View File

@ -17,7 +17,7 @@ static cc_bool launcherMode;
static SceTouchPanelInfo frontPanel; static SceTouchPanelInfo frontPanel;
struct _DisplayData DisplayInfo; struct _DisplayData DisplayInfo;
struct _WinData WindowInfo; struct _WindowData WindowInfo;
#define DISPLAY_WIDTH 960 #define DISPLAY_WIDTH 960
#define DISPLAY_HEIGHT 544 #define DISPLAY_HEIGHT 544
@ -37,10 +37,10 @@ void Window_Init(void) {
DisplayInfo.ScaleX = 1; DisplayInfo.ScaleX = 1;
DisplayInfo.ScaleY = 1; DisplayInfo.ScaleY = 1;
WindowInfo.Width = DISPLAY_WIDTH; Window_Main.Width = DISPLAY_WIDTH;
WindowInfo.Height = DISPLAY_HEIGHT; Window_Main.Height = DISPLAY_HEIGHT;
WindowInfo.Focused = true; Window_Main.Focused = true;
WindowInfo.Exists = true; Window_Main.Exists = true;
Input.Sources = INPUT_SOURCE_GAMEPAD; Input.Sources = INPUT_SOURCE_GAMEPAD;
sceCtrlSetSamplingMode(SCE_CTRL_MODE_ANALOG); sceCtrlSetSamplingMode(SCE_CTRL_MODE_ANALOG);

View File

@ -12,7 +12,7 @@ static SDL_Window* win_handle;
#error "Some features are missing from the SDL backend. If possible, it is recommended that you use a native windowing backend instead" #error "Some features are missing from the SDL backend. If possible, it is recommended that you use a native windowing backend instead"
static void RefreshWindowBounds(void) { static void RefreshWindowBounds(void) {
SDL_GetWindowSize(win_handle, &WindowInfo.Width, &WindowInfo.Height); SDL_GetWindowSize(win_handle, &Window_Main.Width, &Window_Main.Height);
} }
static void Window_SDLFail(const char* place) { static void Window_SDLFail(const char* place) {
@ -49,8 +49,8 @@ static void DoCreateWindow(int width, int height, int flags) {
if (!win_handle) Window_SDLFail("creating window"); if (!win_handle) Window_SDLFail("creating window");
RefreshWindowBounds(); RefreshWindowBounds();
WindowInfo.Exists = true; Window_Main.Exists = true;
WindowInfo.Handle = win_handle; Window_Main.Handle = win_handle;
/* TODO grab using SDL_SetWindowGrab? seems to be unnecessary on Linux at least */ /* TODO grab using SDL_SetWindowGrab? seems to be unnecessary on Linux at least */
} }
void Window_Create2D(int width, int height) { DoCreateWindow(width, height, 0); } void Window_Create2D(int width, int height) { DoCreateWindow(width, height, 0); }
@ -217,11 +217,11 @@ static void OnWindowEvent(const SDL_Event* e) {
Event_RaiseVoid(&WindowEvents.StateChanged); Event_RaiseVoid(&WindowEvents.StateChanged);
break; break;
case SDL_WINDOWEVENT_FOCUS_GAINED: case SDL_WINDOWEVENT_FOCUS_GAINED:
WindowInfo.Focused = true; Window_Main.Focused = true;
Event_RaiseVoid(&WindowEvents.FocusChanged); Event_RaiseVoid(&WindowEvents.FocusChanged);
break; break;
case SDL_WINDOWEVENT_FOCUS_LOST: case SDL_WINDOWEVENT_FOCUS_LOST:
WindowInfo.Focused = false; Window_Main.Focused = false;
Event_RaiseVoid(&WindowEvents.FocusChanged); Event_RaiseVoid(&WindowEvents.FocusChanged);
break; break;
case SDL_WINDOWEVENT_CLOSE: case SDL_WINDOWEVENT_CLOSE:
@ -254,7 +254,7 @@ void Window_ProcessEvents(double delta) {
OnWindowEvent(&e); break; OnWindowEvent(&e); break;
case SDL_QUIT: case SDL_QUIT:
WindowInfo.Exists = false; Window_Main.Exists = false;
Event_RaiseVoid(&WindowEvents.Closing); Event_RaiseVoid(&WindowEvents.Closing);
SDL_DestroyWindow(win_handle); SDL_DestroyWindow(win_handle);
break; break;

View File

@ -23,10 +23,10 @@ static int GetScreenHeight(void) { return RawDpiScale(interop_ScreenHeight()); }
static void UpdateWindowBounds(void) { static void UpdateWindowBounds(void) {
int width = interop_CanvasWidth(); int width = interop_CanvasWidth();
int height = interop_CanvasHeight(); int height = interop_CanvasHeight();
if (width == WindowInfo.Width && height == WindowInfo.Height) return; if (width == Window_Main.Width && height == Window_Main.Height) return;
WindowInfo.Width = width; Window_Main.Width = width;
WindowInfo.Height = height; Window_Main.Height = height;
Event_RaiseVoid(&WindowEvents.Resized); Event_RaiseVoid(&WindowEvents.Resized);
} }
@ -74,8 +74,8 @@ static void RescaleXY(int* x, int* y) {
emscripten_get_element_css_size("#canvas", &css_width, &css_height); emscripten_get_element_css_size("#canvas", &css_width, &css_height);
if (css_width && css_height) { if (css_width && css_height) {
*x = (int)(*x * WindowInfo.Width / css_width ); *x = (int)(*x * Window_Main.Width / css_width );
*y = (int)(*y * WindowInfo.Height / css_height); *y = (int)(*y * Window_Main.Height / css_height);
} else { } else {
/* If css width or height is 0, something is bogus */ /* If css width or height is 0, something is bogus */
/* Better to avoid divsision by 0 in that case though */ /* Better to avoid divsision by 0 in that case though */
@ -105,8 +105,8 @@ static EM_BOOL OnTouchStart(int type, const EmscriptenTouchEvent* ev, void* data
/* Because we return true to cancel default browser behaviour, sometimes we also */ /* Because we return true to cancel default browser behaviour, sometimes we also */
/* end up preventing the default 'focus gained' behaviour from occurring */ /* end up preventing the default 'focus gained' behaviour from occurring */
/* So manually activate focus as a workaround */ /* So manually activate focus as a workaround */
if (!WindowInfo.Focused) { if (!Window_Main.Focused) {
WindowInfo.Focused = true; Window_Main.Focused = true;
Event_RaiseVoid(&WindowEvents.FocusChanged); Event_RaiseVoid(&WindowEvents.FocusChanged);
} }
@ -157,7 +157,7 @@ static EM_BOOL OnTouchEnd(int type, const EmscriptenTouchEvent* ev, void* data)
} }
static EM_BOOL OnFocus(int type, const EmscriptenFocusEvent* ev, void* data) { static EM_BOOL OnFocus(int type, const EmscriptenFocusEvent* ev, void* data) {
WindowInfo.Focused = type == EMSCRIPTEN_EVENT_FOCUS; Window_Main.Focused = type == EMSCRIPTEN_EVENT_FOCUS;
Event_RaiseVoid(&WindowEvents.FocusChanged); Event_RaiseVoid(&WindowEvents.FocusChanged);
return true; return true;
} }
@ -189,9 +189,9 @@ static const char* OnBeforeUnload(int type, const void* ev, void *data) {
static EM_BOOL OnVisibilityChanged(int eventType, const EmscriptenVisibilityChangeEvent* ev, void* data) { static EM_BOOL OnVisibilityChanged(int eventType, const EmscriptenVisibilityChangeEvent* ev, void* data) {
cc_bool inactive = ev->visibilityState == EMSCRIPTEN_VISIBILITY_HIDDEN; cc_bool inactive = ev->visibilityState == EMSCRIPTEN_VISIBILITY_HIDDEN;
if (WindowInfo.Inactive == inactive) return false; if (Window_Main.Inactive == inactive) return false;
WindowInfo.Inactive = inactive; Window_Main.Inactive = inactive;
Event_RaiseVoid(&WindowEvents.InactiveChanged); Event_RaiseVoid(&WindowEvents.InactiveChanged);
return false; return false;
} }
@ -387,7 +387,7 @@ void Window_Init(void) {
/* as the chat/send butons are positioned at the top of the canvas - they */ /* as the chat/send butons are positioned at the top of the canvas - they */
/* get pushed offscreen and can't be used at all anymore. So handle this */ /* get pushed offscreen and can't be used at all anymore. So handle this */
/* case specially by positioning them at the bottom instead for iOS. */ /* case specially by positioning them at the bottom instead for iOS. */
WindowInfo.SoftKeyboard = is_ios ? SOFT_KEYBOARD_SHIFT : SOFT_KEYBOARD_RESIZE; Window_Main.SoftKeyboard = is_ios ? SOFT_KEYBOARD_SHIFT : SOFT_KEYBOARD_RESIZE;
/* Let the webpage know it needs to force a mobile layout */ /* Let the webpage know it needs to force a mobile layout */
if (!Input_TouchMode) return; if (!Input_TouchMode) return;
@ -398,12 +398,12 @@ void Window_Free(void) { }
extern void interop_InitContainer(void); extern void interop_InitContainer(void);
static void DoCreateWindow(void) { static void DoCreateWindow(void) {
WindowInfo.Exists = true; Window_Main.Exists = true;
WindowInfo.Focused = true; Window_Main.Focused = true;
HookEvents(); HookEvents();
/* Let the webpage decide on initial bounds */ /* Let the webpage decide on initial bounds */
WindowInfo.Width = interop_CanvasWidth(); Window_Main.Width = interop_CanvasWidth();
WindowInfo.Height = interop_CanvasHeight(); Window_Main.Height = interop_CanvasHeight();
interop_InitContainer(); interop_InitContainer();
} }
void Window_Create2D(int width, int height) { DoCreateWindow(); } void Window_Create2D(int width, int height) { DoCreateWindow(); }
@ -501,7 +501,7 @@ void Window_SetSize(int width, int height) {
} }
void Window_RequestClose(void) { void Window_RequestClose(void) {
WindowInfo.Exists = false; Window_Main.Exists = false;
Event_RaiseVoid(&WindowEvents.Closing); Event_RaiseVoid(&WindowEvents.Closing);
/* If the game is closed while in fullscreen, the last rendered frame stays */ /* If the game is closed while in fullscreen, the last rendered frame stays */
/* shown in fullscreen, but the game can't be interacted with anymore */ /* shown in fullscreen, but the game can't be interacted with anymore */
@ -516,7 +516,7 @@ void Window_RequestClose(void) {
extern void interop_RequestCanvasResize(void); extern void interop_RequestCanvasResize(void);
static void ProcessPendingResize(void) { static void ProcessPendingResize(void) {
if (!WindowInfo.Exists) return; if (!Window_Main.Exists) return;
if (Window_GetWindowState() == WINDOW_STATE_FULLSCREEN) { if (Window_GetWindowState() == WINDOW_STATE_FULLSCREEN) {
SetFullscreenBounds(); SetFullscreenBounds();

View File

@ -92,8 +92,8 @@ static void RefreshWindowBounds(void) {
win_totalHeight = Rect_Height(rect); win_totalHeight = Rect_Height(rect);
GetClientRect(win_handle, &rect); GetClientRect(win_handle, &rect);
WindowInfo.Width = Rect_Width(rect); Window_Main.Width = Rect_Width(rect);
WindowInfo.Height = Rect_Height(rect); Window_Main.Height = Rect_Height(rect);
/* GetClientRect always returns 0,0 for left,top (see MSDN) */ /* GetClientRect always returns 0,0 for left,top (see MSDN) */
ClientToScreen(win_handle, &topLeft); ClientToScreen(win_handle, &topLeft);
@ -113,7 +113,7 @@ static LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wPara
switch (message) { switch (message) {
case WM_ACTIVATE: case WM_ACTIVATE:
WindowInfo.Focused = LOWORD(wParam) != 0; Window_Main.Focused = LOWORD(wParam) != 0;
Event_RaiseVoid(&WindowEvents.FocusChanged); Event_RaiseVoid(&WindowEvents.FocusChanged);
break; break;
@ -256,12 +256,12 @@ static LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wPara
case WM_CLOSE: case WM_CLOSE:
Event_RaiseVoid(&WindowEvents.Closing); Event_RaiseVoid(&WindowEvents.Closing);
if (WindowInfo.Exists) DestroyWindow(win_handle); if (Window_Main.Exists) DestroyWindow(win_handle);
WindowInfo.Exists = false; Window_Main.Exists = false;
break; break;
case WM_DESTROY: case WM_DESTROY:
WindowInfo.Exists = false; Window_Main.Exists = false;
UnregisterClassW(CC_WIN_CLASSNAME, win_instance); UnregisterClassW(CC_WIN_CLASSNAME, win_instance);
if (win_DC) ReleaseDC(win_handle, win_DC); if (win_DC) ReleaseDC(win_handle, win_DC);
@ -365,8 +365,8 @@ static void DoCreateWindow(int width, int height) {
win_DC = GetDC(win_handle); win_DC = GetDC(win_handle);
if (!win_DC) Logger_Abort2(GetLastError(), "Failed to get device context"); if (!win_DC) Logger_Abort2(GetLastError(), "Failed to get device context");
WindowInfo.Exists = true; Window_Main.Exists = true;
WindowInfo.Handle = win_handle; Window_Main.Handle = win_handle;
grabCursor = Options_GetBool(OPT_GRAB_CURSOR, false); grabCursor = Options_GetBool(OPT_GRAB_CURSOR, false);
} }
void Window_Create2D(int width, int height) { DoCreateWindow(width, height); } void Window_Create2D(int width, int height) { DoCreateWindow(width, height); }
@ -529,7 +529,7 @@ void Window_ProcessEvents(double delta) {
foreground = GetForegroundWindow(); foreground = GetForegroundWindow();
if (foreground) { if (foreground) {
WindowInfo.Focused = foreground == win_handle; Window_Main.Focused = foreground == win_handle;
} }
} }

View File

@ -193,9 +193,9 @@ static void RegisterAtoms(void) {
} }
static void RefreshWindowBounds(int width, int height) { static void RefreshWindowBounds(int width, int height) {
if (width != WindowInfo.Width || height != WindowInfo.Height) { if (width != Window_Main.Width || height != Window_Main.Height) {
WindowInfo.Width = width; Window_Main.Width = width;
WindowInfo.Height = height; Window_Main.Height = height;
Event_RaiseVoid(&WindowEvents.Resized); Event_RaiseVoid(&WindowEvents.Resized);
} }
} }
@ -332,8 +332,8 @@ static void DoCreateWindow(int width, int height) {
XkbSetDetectableAutoRepeat(win_display, true, &supported); XkbSetDetectableAutoRepeat(win_display, true, &supported);
RefreshWindowBounds(width, height); RefreshWindowBounds(width, height);
WindowInfo.Exists = true; Window_Main.Exists = true;
WindowInfo.Handle = (void*)win_handle; Window_Main.Handle = (void*)win_handle;
grabCursor = Options_GetBool(OPT_GRAB_CURSOR, false); grabCursor = Options_GetBool(OPT_GRAB_CURSOR, false);
/* So right name appears in e.g. Ubuntu Unity launchbar */ /* So right name appears in e.g. Ubuntu Unity launchbar */
@ -345,7 +345,7 @@ static void DoCreateWindow(int width, int height) {
/* Check for focus initially, in case WM doesn't send a FocusIn event */ /* Check for focus initially, in case WM doesn't send a FocusIn event */
XGetInputFocus(win_display, &focus, &focusRevert); XGetInputFocus(win_display, &focus, &focusRevert);
if (focus == win_handle) WindowInfo.Focused = true; if (focus == win_handle) Window_Main.Focused = true;
} }
void Window_Create2D(int width, int height) { DoCreateWindow(width, height); } void Window_Create2D(int width, int height) { DoCreateWindow(width, height); }
void Window_Create3D(int width, int height) { DoCreateWindow(width, height); } void Window_Create3D(int width, int height) { DoCreateWindow(width, height); }
@ -508,7 +508,7 @@ static void HandleWMDestroy(void) {
/* sync and discard all events queued */ /* sync and discard all events queued */
XSync(win_display, true); XSync(win_display, true);
XDestroyWindow(win_display, win_handle); XDestroyWindow(win_display, win_handle);
WindowInfo.Exists = false; Window_Main.Exists = false;
} }
static void HandleWMPing(XEvent* e) { static void HandleWMPing(XEvent* e) {
@ -524,7 +524,7 @@ void Window_ProcessEvents(double delta) {
int focusRevert; int focusRevert;
int i, btn, key, status; int i, btn, key, status;
while (WindowInfo.Exists) { while (Window_Main.Exists) {
if (!XCheckIfEvent(win_display, &e, FilterEvent, (XPointer)win_handle)) break; if (!XCheckIfEvent(win_display, &e, FilterEvent, (XPointer)win_handle)) break;
if (XFilterEvent(&e, None) == True) continue; if (XFilterEvent(&e, None) == True) continue;
@ -541,7 +541,7 @@ void Window_ProcessEvents(double delta) {
case DestroyNotify: case DestroyNotify:
Platform_LogConst("Window destroyed"); Platform_LogConst("Window destroyed");
WindowInfo.Exists = false; Window_Main.Exists = false;
break; break;
case ConfigureNotify: case ConfigureNotify:
@ -555,14 +555,14 @@ void Window_ProcessEvents(double delta) {
case LeaveNotify: case LeaveNotify:
XGetInputFocus(win_display, &focus, &focusRevert); XGetInputFocus(win_display, &focus, &focusRevert);
if (focus == PointerRoot) { if (focus == PointerRoot) {
WindowInfo.Focused = false; Event_RaiseVoid(&WindowEvents.FocusChanged); Window_Main.Focused = false; Event_RaiseVoid(&WindowEvents.FocusChanged);
} }
break; break;
case EnterNotify: case EnterNotify:
XGetInputFocus(win_display, &focus, &focusRevert); XGetInputFocus(win_display, &focus, &focusRevert);
if (focus == PointerRoot) { if (focus == PointerRoot) {
WindowInfo.Focused = true; Event_RaiseVoid(&WindowEvents.FocusChanged); Window_Main.Focused = true; Event_RaiseVoid(&WindowEvents.FocusChanged);
} }
break; break;
@ -621,10 +621,10 @@ void Window_ProcessEvents(double delta) {
/* Don't lose focus when another app grabs key or mouse */ /* Don't lose focus when another app grabs key or mouse */
if (e.xfocus.mode == NotifyGrab || e.xfocus.mode == NotifyUngrab) break; if (e.xfocus.mode == NotifyGrab || e.xfocus.mode == NotifyUngrab) break;
WindowInfo.Focused = e.type == FocusIn; Window_Main.Focused = e.type == FocusIn;
Event_RaiseVoid(&WindowEvents.FocusChanged); Event_RaiseVoid(&WindowEvents.FocusChanged);
/* TODO: Keep track of keyboard when focus is lost */ /* TODO: Keep track of keyboard when focus is lost */
if (!WindowInfo.Focused) Input_Clear(); if (!Window_Main.Focused) Input_Clear();
break; break;
case MappingNotify: case MappingNotify:

View File

@ -19,7 +19,7 @@ static xid_dev_t* xid_ctrl;
static xid_gamepad_in gp_state; static xid_gamepad_in gp_state;
struct _DisplayData DisplayInfo; struct _DisplayData DisplayInfo;
struct _WinData WindowInfo; struct _WindowData WindowInfo;
// TODO No idea if this even works // TODO No idea if this even works
static void OnDataReceived(UTR_T* utr) { static void OnDataReceived(UTR_T* utr) {
@ -66,10 +66,10 @@ void Window_Init(void) {
DisplayInfo.ScaleX = 1; DisplayInfo.ScaleX = 1;
DisplayInfo.ScaleY = 1; DisplayInfo.ScaleY = 1;
WindowInfo.Width = mode.width; Window_Main.Width = mode.width;
WindowInfo.Height = mode.height; Window_Main.Height = mode.height;
WindowInfo.Focused = true; Window_Main.Focused = true;
WindowInfo.Exists = true; Window_Main.Exists = true;
Input.Sources = INPUT_SOURCE_GAMEPAD; Input.Sources = INPUT_SOURCE_GAMEPAD;
DisplayInfo.ContentOffsetX = 10; DisplayInfo.ContentOffsetX = 10;

View File

@ -17,7 +17,7 @@
static cc_bool launcherMode; static cc_bool launcherMode;
struct _DisplayData DisplayInfo; struct _DisplayData DisplayInfo;
struct _WinData WindowInfo; struct _WindowData WindowInfo;
// https://github.com/Free60Project/libxenon/blob/71a411cddfc26c9ccade08d054d87180c359797a/libxenon/drivers/console/console.c#L47 // https://github.com/Free60Project/libxenon/blob/71a411cddfc26c9ccade08d054d87180c359797a/libxenon/drivers/console/console.c#L47
struct ati_info { struct ati_info {
@ -37,10 +37,10 @@ void Window_Init(void) {
DisplayInfo.ScaleX = 1; DisplayInfo.ScaleX = 1;
DisplayInfo.ScaleY = 1; DisplayInfo.ScaleY = 1;
WindowInfo.Width = ai->width; Window_Main.Width = ai->width;
WindowInfo.Height = ai->height; Window_Main.Height = ai->height;
WindowInfo.Focused = true; Window_Main.Focused = true;
WindowInfo.Exists = true; Window_Main.Exists = true;
Input.Sources = INPUT_SOURCE_GAMEPAD; Input.Sources = INPUT_SOURCE_GAMEPAD;

View File

@ -5,7 +5,7 @@
#include "Platform.h" #include "Platform.h"
struct _DisplayData DisplayInfo; struct _DisplayData DisplayInfo;
struct _WinData WindowInfo; struct _WindowData WindowInfo;
#define Display_CentreX(width) (DisplayInfo.x + (DisplayInfo.Width - width) / 2) #define Display_CentreX(width) (DisplayInfo.x + (DisplayInfo.Width - width) / 2)
#define Display_CentreY(height) (DisplayInfo.y + (DisplayInfo.Height - height) / 2) #define Display_CentreY(height) (DisplayInfo.y + (DisplayInfo.Height - height) / 2)
@ -27,13 +27,13 @@ static void Cursor_SetVisible(cc_bool visible) {
} }
static void CentreMousePosition(void) { static void CentreMousePosition(void) {
Cursor_SetPosition(WindowInfo.Width / 2, WindowInfo.Height / 2); Cursor_SetPosition(Window_Main.Width / 2, Window_Main.Height / 2);
/* Fixes issues with large DPI displays on Windows >= 8.0. */ /* Fixes issues with large DPI displays on Windows >= 8.0. */
Cursor_GetRawPos(&cursorPrevX, &cursorPrevY); Cursor_GetRawPos(&cursorPrevX, &cursorPrevY);
} }
static void RegrabMouse(void) { static void RegrabMouse(void) {
if (!WindowInfo.Focused || !WindowInfo.Exists) return; if (!Window_Main.Focused || !Window_Main.Exists) return;
CentreMousePosition(); CentreMousePosition();
} }
@ -108,7 +108,7 @@ static EGLConfig ctx_config;
static EGLint ctx_numConfig; static EGLint ctx_numConfig;
static void GLContext_InitSurface(void) { static void GLContext_InitSurface(void) {
void* window = WindowInfo.Handle; void* window = Window_Main.Handle;
if (!window) return; /* window not created or lost */ if (!window) return; /* window not created or lost */
ctx_surface = eglCreateWindowSurface(ctx_display, ctx_config, window, NULL); ctx_surface = eglCreateWindowSurface(ctx_display, ctx_config, window, NULL);

View File

@ -404,12 +404,12 @@ static void DoCreateWindow(int width, int height) {
BRect frame(x, y, x + width - 1, y + height - 1); BRect frame(x, y, x + width - 1, y + height - 1);
win_handle = new CC_BWindow(frame); win_handle = new CC_BWindow(frame);
WindowInfo.Exists = true; Window_Main.Exists = true;
WindowInfo.Handle = win_handle; Window_Main.Handle = win_handle;
frame = win_handle->Bounds(); frame = win_handle->Bounds();
WindowInfo.Width = frame.IntegerWidth() + 1; Window_Main.Width = frame.IntegerWidth() + 1;
WindowInfo.Height = frame.IntegerHeight() + 1; Window_Main.Height = frame.IntegerHeight() + 1;
} }
void Window_Create2D(int width, int height) { void Window_Create2D(int width, int height) {
@ -574,19 +574,19 @@ void Window_ProcessEvents(double delta) {
Event_RaiseInt(&InputEvents.Press, event.v1.i32); Event_RaiseInt(&InputEvents.Press, event.v1.i32);
break; break;
case CC_WIN_RESIZED: case CC_WIN_RESIZED:
WindowInfo.Width = event.v1.i32; Window_Main.Width = event.v1.i32;
WindowInfo.Height = event.v2.i32; Window_Main.Height = event.v2.i32;
Event_RaiseVoid(&WindowEvents.Resized); Event_RaiseVoid(&WindowEvents.Resized);
break; break;
case CC_WIN_FOCUS: case CC_WIN_FOCUS:
WindowInfo.Focused = event.v1.i32; Window_Main.Focused = event.v1.i32;
Event_RaiseVoid(&WindowEvents.FocusChanged); Event_RaiseVoid(&WindowEvents.FocusChanged);
break; break;
case CC_WIN_REDRAW: case CC_WIN_REDRAW:
Event_RaiseVoid(&WindowEvents.RedrawNeeded); Event_RaiseVoid(&WindowEvents.RedrawNeeded);
break; break;
case CC_WIN_QUIT: case CC_WIN_QUIT:
WindowInfo.Exists = false; Window_Main.Exists = false;
Event_RaiseVoid(&WindowEvents.Closing); Event_RaiseVoid(&WindowEvents.Closing);
break; break;
} }

View File

@ -90,7 +90,7 @@ static cc_bool GetMouseCoords(int* x, int* y) {
*x = (int)loc.x - windowX; *x = (int)loc.x - windowX;
*y = (DisplayInfo.Height - (int)loc.y) - windowY; *y = (DisplayInfo.Height - (int)loc.y) - windowY;
// TODO: this seems to be off by 1 // TODO: this seems to be off by 1
return *x >= 0 && *y >= 0 && *x < WindowInfo.Width && *y < WindowInfo.Height; return *x >= 0 && *y >= 0 && *x < Window_Main.Width && *y < Window_Main.Height;
} }
static void ProcessRawMouseMovement(NSEvent* ev) { static void ProcessRawMouseMovement(NSEvent* ev) {
@ -223,8 +223,8 @@ static void RefreshWindowBounds(void) {
windowY = (int)rect.origin.y; // usually 0 windowY = (int)rect.origin.y; // usually 0
// TODO is it correct to use display bounds and not just 0? // TODO is it correct to use display bounds and not just 0?
WindowInfo.Width = (int)rect.size.width; Window_Main.Width = (int)rect.size.width;
WindowInfo.Height = (int)rect.size.height; Window_Main.Height = (int)rect.size.height;
return; return;
} }
@ -241,8 +241,8 @@ static void RefreshWindowBounds(void) {
windowX = (int)win.origin.x + (int)view.origin.x; windowX = (int)win.origin.x + (int)view.origin.x;
windowY = DisplayInfo.Height - ((int)win.origin.y + (int)win.size.height) + viewY; windowY = DisplayInfo.Height - ((int)win.origin.y + (int)win.size.height) + viewY;
WindowInfo.Width = (int)view.size.width; Window_Main.Width = (int)view.size.width;
WindowInfo.Height = (int)view.size.height; Window_Main.Height = (int)view.size.height;
} }
@interface CCWindow : NSWindow { } @interface CCWindow : NSWindow { }
@ -266,12 +266,12 @@ static void RefreshWindowBounds(void) {
} }
- (void)windowDidBecomeKey:(NSNotification *)notification { - (void)windowDidBecomeKey:(NSNotification *)notification {
WindowInfo.Focused = true; Window_Main.Focused = true;
Event_RaiseVoid(&WindowEvents.FocusChanged); Event_RaiseVoid(&WindowEvents.FocusChanged);
} }
- (void)windowDidResignKey:(NSNotification *)notification { - (void)windowDidResignKey:(NSNotification *)notification {
WindowInfo.Focused = false; Window_Main.Focused = false;
Event_RaiseVoid(&WindowEvents.FocusChanged); Event_RaiseVoid(&WindowEvents.FocusChanged);
} }
@ -284,7 +284,7 @@ static void RefreshWindowBounds(void) {
} }
- (void)windowWillClose:(NSNotification *)notification { - (void)windowWillClose:(NSNotification *)notification {
WindowInfo.Exists = false; Window_Main.Exists = false;
Event_RaiseVoid(&WindowEvents.Closing); Event_RaiseVoid(&WindowEvents.Closing);
} }
@end @end
@ -366,8 +366,8 @@ static void DoCreateWindow(int width, int height) {
[winHandle setAcceptsMouseMovedEvents:YES]; [winHandle setAcceptsMouseMovedEvents:YES];
Window_CommonCreate(); Window_CommonCreate();
WindowInfo.Exists = true; Window_Main.Exists = true;
WindowInfo.Handle = winHandle; Window_Main.Handle = winHandle;
// CGAssociateMouseAndMouseCursorPosition implicitly grabs cursor // CGAssociateMouseAndMouseCursorPosition implicitly grabs cursor
del = [CCWindowDelegate alloc]; del = [CCWindowDelegate alloc];
@ -427,9 +427,9 @@ void Window_SetSize(int width, int height) {
// Can't use setContentSize:, because that resizes from the bottom left corner // Can't use setContentSize:, because that resizes from the bottom left corner
NSRect rect = [winHandle frame]; NSRect rect = [winHandle frame];
rect.origin.y += WindowInfo.Height - height; rect.origin.y += Window_Main.Height - height;
rect.size.width += width - WindowInfo.Width; rect.size.width += width - Window_Main.Width;
rect.size.height += height - WindowInfo.Height; rect.size.height += height - Window_Main.Height;
[winHandle setFrame:rect display:YES]; [winHandle setFrame:rect display:YES];
} }
@ -692,8 +692,8 @@ static void DoDrawFramebuffer(NSRect dirty) {
// TODO: Only update changed bit.. // TODO: Only update changed bit..
rect.origin.x = 0; rect.origin.y = 0; rect.origin.x = 0; rect.origin.y = 0;
rect.size.width = WindowInfo.Width; rect.size.width = Window_Main.Width;
rect.size.height = WindowInfo.Height; rect.size.height = Window_Main.Height;
// TODO: REPLACE THIS AWFUL HACK // TODO: REPLACE THIS AWFUL HACK
provider = CGDataProviderCreateWithData(NULL, fb_bmp.scan0, provider = CGDataProviderCreateWithData(NULL, fb_bmp.scan0,
@ -712,7 +712,7 @@ static void DoDrawFramebuffer(NSRect dirty) {
void Window_DrawFramebuffer(Rect2D r) { void Window_DrawFramebuffer(Rect2D r) {
NSRect rect; NSRect rect;
rect.origin.x = r.x; rect.origin.x = r.x;
rect.origin.y = WindowInfo.Height - r.y - r.Height; rect.origin.y = Window_Main.Height - r.y - r.Height;
rect.size.width = r.Width; rect.size.width = r.Width;
rect.size.height = r.Height; rect.size.height = r.Height;

View File

@ -118,8 +118,8 @@ static CGRect GetViewFrame(void) {
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator { - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator {
// viewWillTransitionToSize:withTransitionCoordinator - iOS 8.0 // viewWillTransitionToSize:withTransitionCoordinator - iOS 8.0
WindowInfo.Width = size.width; Window_Main.Width = size.width;
WindowInfo.Height = size.height; Window_Main.Height = size.height;
Event_RaiseVoid(&WindowEvents.Resized); Event_RaiseVoid(&WindowEvents.Resized);
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
@ -239,7 +239,7 @@ static UITextField* kb_widget;
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
Platform_LogConst("INACTIVE"); Platform_LogConst("INACTIVE");
WindowInfo.Focused = false; Window_Main.Focused = false;
Event_RaiseVoid(&WindowEvents.FocusChanged); Event_RaiseVoid(&WindowEvents.FocusChanged);
} }
@ -260,7 +260,7 @@ static UITextField* kb_widget;
// applicationDidBecomeActive - iOS 2.0 // applicationDidBecomeActive - iOS 2.0
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
Platform_LogConst("ACTIVE"); Platform_LogConst("ACTIVE");
WindowInfo.Focused = true; Window_Main.Focused = true;
Event_RaiseVoid(&WindowEvents.FocusChanged); Event_RaiseVoid(&WindowEvents.FocusChanged);
} }
@ -371,9 +371,9 @@ void Window_SetTitle(const cc_string* title) {
} }
void Window_Init(void) { void Window_Init(void) {
//WindowInfo.SoftKeyboard = SOFT_KEYBOARD_RESIZE; //Window_Main.SoftKeyboard = SOFT_KEYBOARD_RESIZE;
// keyboard now shifts up // keyboard now shifts up
WindowInfo.SoftKeyboard = SOFT_KEYBOARD_SHIFT; Window_Main.SoftKeyboard = SOFT_KEYBOARD_SHIFT;
Input_SetTouchMode(true); Input_SetTouchMode(true);
Input.Sources = INPUT_SOURCE_NORMAL; Input.Sources = INPUT_SOURCE_NORMAL;
@ -399,9 +399,9 @@ static CGRect DoCreateWindow(void) {
win_handle.rootViewController = cc_controller; win_handle.rootViewController = cc_controller;
win_handle.backgroundColor = CalcBackgroundColor(); win_handle.backgroundColor = CalcBackgroundColor();
WindowInfo.Exists = true; Window_Main.Exists = true;
WindowInfo.Width = bounds.size.width; Window_Main.Width = bounds.size.width;
WindowInfo.Height = bounds.size.height; Window_Main.Height = bounds.size.height;
NSNotificationCenter* notifications = NSNotificationCenter.defaultCenter; NSNotificationCenter* notifications = NSNotificationCenter.defaultCenter;
[notifications addObserver:cc_controller selector:@selector(keyboardDidShow:) name:UIKeyboardWillShowNotification object:nil]; [notifications addObserver:cc_controller selector:@selector(keyboardDidShow:) name:UIKeyboardWillShowNotification object:nil];
@ -415,7 +415,7 @@ void Window_Show(void) {
} }
void Window_RequestClose(void) { void Window_RequestClose(void) {
WindowInfo.Exists = false; Window_Main.Exists = false;
Event_RaiseVoid(&WindowEvents.Closing); Event_RaiseVoid(&WindowEvents.Closing);
} }
@ -670,15 +670,15 @@ static void CreateFramebuffer(void) {
glGenRenderbuffers(1, &depth_renderbuffer); glGenRenderbuffers(1, &depth_renderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, depth_renderbuffer); glBindRenderbuffer(GL_RENDERBUFFER, depth_renderbuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24_OES, WindowInfo.Width, WindowInfo.Height); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24_OES, Window_Main.Width, Window_Main.Height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth_renderbuffer); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth_renderbuffer);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE) if (status != GL_FRAMEBUFFER_COMPLETE)
Logger_Abort2(status, "Failed to create renderbuffer"); Logger_Abort2(status, "Failed to create renderbuffer");
fb_width = WindowInfo.Width; fb_width = Window_Main.Width;
fb_height = WindowInfo.Height; fb_height = Window_Main.Height;
} }
void GLContext_Create(void) { void GLContext_Create(void) {
@ -698,15 +698,15 @@ static void GLContext_OnLayout(void) {
CAEAGLLayer* layer = (CAEAGLLayer*)view_handle.layer; CAEAGLLayer* layer = (CAEAGLLayer*)view_handle.layer;
// only resize buffers when absolutely have to // only resize buffers when absolutely have to
if (fb_width == WindowInfo.Width && fb_height == WindowInfo.Height) return; if (fb_width == Window_Main.Width && fb_height == Window_Main.Height) return;
fb_width = WindowInfo.Width; fb_width = Window_Main.Width;
fb_height = WindowInfo.Height; fb_height = Window_Main.Height;
glBindRenderbuffer(GL_RENDERBUFFER, color_renderbuffer); glBindRenderbuffer(GL_RENDERBUFFER, color_renderbuffer);
[ctx_handle renderbufferStorage:GL_RENDERBUFFER fromDrawable:layer]; [ctx_handle renderbufferStorage:GL_RENDERBUFFER fromDrawable:layer];
glBindRenderbuffer(GL_RENDERBUFFER, depth_renderbuffer); glBindRenderbuffer(GL_RENDERBUFFER, depth_renderbuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24_OES, WindowInfo.Width, WindowInfo.Height); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24_OES, Window_Main.Width, Window_Main.Height);
} }
void GLContext_Free(void) { void GLContext_Free(void) {
@ -1295,8 +1295,8 @@ void LBackend_FreeFramebuffer(void) { }
void LBackend_Redraw(void) { void LBackend_Redraw(void) {
struct Context2D ctx; struct Context2D ctx;
struct Bitmap bmp; struct Bitmap bmp;
bmp.width = max(WindowInfo.Width, 1); bmp.width = max(Window_Main.Width, 1);
bmp.height = max(WindowInfo.Height, 1); bmp.height = max(Window_Main.Height, 1);
bmp.scan0 = (BitmapCol*)Mem_Alloc(bmp.width * bmp.height, 4, "window pixels"); bmp.scan0 = (BitmapCol*)Mem_Alloc(bmp.width * bmp.height, 4, "window pixels");
Context2D_Wrap(&ctx, &bmp); Context2D_Wrap(&ctx, &bmp);
@ -1640,10 +1640,10 @@ static void LBackend_LayoutDimensions(struct LWidget* w, CGRect* r) {
switch (l->type) switch (l->type)
{ {
case LLAYOUT_WIDTH: case LLAYOUT_WIDTH:
r->size.width = WindowInfo.Width - (int)r->origin.x - Display_ScaleX(l->offset); r->size.width = Window_Main.Width - (int)r->origin.x - Display_ScaleX(l->offset);
break; break;
case LLAYOUT_HEIGHT: case LLAYOUT_HEIGHT:
r->size.height = WindowInfo.Height - (int)r->origin.y - Display_ScaleY(l->offset); r->size.height = Window_Main.Height - (int)r->origin.y - Display_ScaleY(l->offset);
break; break;
} }
l++; l++;
@ -1657,8 +1657,8 @@ void LBackend_LayoutWidget(struct LWidget* w) {
int width = (int)r.size.width; int width = (int)r.size.width;
int height = (int)r.size.height; int height = (int)r.size.height;
r.origin.x = Gui_CalcPos(l[0].type & 0xFF, Display_ScaleX(l[0].offset), width, WindowInfo.Width); r.origin.x = Gui_CalcPos(l[0].type & 0xFF, Display_ScaleX(l[0].offset), width, Window_Main.Width);
r.origin.y = Gui_CalcPos(l[1].type & 0xFF, Display_ScaleY(l[1].offset), height, WindowInfo.Height); r.origin.y = Gui_CalcPos(l[1].type & 0xFF, Display_ScaleY(l[1].offset), height, Window_Main.Height);
// e.g. Table widget needs adjusts width/height based on window // e.g. Table widget needs adjusts width/height based on window
if (l[1].type & LLAYOUT_EXTRA) if (l[1].type & LLAYOUT_EXTRA)