mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 18:45:23 -04:00
don't pointlessly use Random_Range with 0 min, use Random_Next instead
This commit is contained in:
parent
15079ee79f
commit
aa345a5c5f
@ -569,7 +569,7 @@ static struct Sound* Soundboard_PickRandom(struct Soundboard* board, uint8_t typ
|
|||||||
group = Soundboard_Find(board, &name);
|
group = Soundboard_Find(board, &name);
|
||||||
if (!group) return NULL;
|
if (!group) return NULL;
|
||||||
|
|
||||||
idx = Random_Range(&board->Rnd, 0, group->Count);
|
idx = Random_Next(&board->Rnd, group->Count);
|
||||||
return &group->Sounds[idx];
|
return &group->Sounds[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -840,7 +840,7 @@ static void Music_RunLoop(void) {
|
|||||||
Audio_Open(&music_out, AUDIO_MAX_BUFFERS);
|
Audio_Open(&music_out, AUDIO_MAX_BUFFERS);
|
||||||
|
|
||||||
while (!music_pendingStop && count) {
|
while (!music_pendingStop && count) {
|
||||||
idx = Random_Range(&rnd, 0, count);
|
idx = Random_Next(&rnd, count);
|
||||||
file = StringsBuffer_UNSAFE_Get(&files, musicFiles[idx]);
|
file = StringsBuffer_UNSAFE_Get(&files, musicFiles[idx]);
|
||||||
|
|
||||||
String_InitArray(path, pathBuffer);
|
String_InitArray(path, pathBuffer);
|
||||||
@ -860,7 +860,7 @@ static void Music_RunLoop(void) {
|
|||||||
if (res) { Logger_Warn2(res, "closing", &path); break; }
|
if (res) { Logger_Warn2(res, "closing", &path); break; }
|
||||||
|
|
||||||
if (music_pendingStop) break;
|
if (music_pendingStop) break;
|
||||||
delay = 1000 * 120 + Random_Range(&rnd, 0, 1000 * 300);
|
delay = 120 * 1000 + Random_Next(&rnd, 300 * 1000);
|
||||||
Waitable_WaitFor(music_waitable, delay);
|
Waitable_WaitFor(music_waitable, delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -977,6 +977,9 @@ void Http_UrlEncodeUtf8(String* dst, const String* src) {
|
|||||||
*-----------------------------------------------------Http component------------------------------------------------------*
|
*-----------------------------------------------------Http component------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
static void Http_Init(void) {
|
static void Http_Init(void) {
|
||||||
|
#ifdef CC_BUILD_ANDROID
|
||||||
|
if (workerThread) return;
|
||||||
|
#endif
|
||||||
ScheduledTask_Add(30, Http_CleanCacheTask);
|
ScheduledTask_Add(30, Http_CleanCacheTask);
|
||||||
RequestList_Init(&pendingReqs);
|
RequestList_Init(&pendingReqs);
|
||||||
RequestList_Init(&processedReqs);
|
RequestList_Init(&processedReqs);
|
||||||
|
@ -419,7 +419,7 @@ void Particles_BreakBlockEffect(IVec3 coords, BlockID old, BlockID now) {
|
|||||||
p->rec = rec;
|
p->rec = rec;
|
||||||
p->texLoc = loc;
|
p->texLoc = loc;
|
||||||
p->block = old;
|
p->block = old;
|
||||||
type = Random_Range(&rnd, 0, 30);
|
type = Random_Next(&rnd, 30);
|
||||||
p->base.size = (uint8_t)(type >= 28 ? 12 : (type >= 25 ? 10 : 8));
|
p->base.size = (uint8_t)(type >= 28 ? 12 : (type >= 25 ? 10 : 8));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -447,7 +447,7 @@ void Particles_RainSnowEffect(Vec3 pos) {
|
|||||||
Vec3_Add(&pos, &origin, &offset);
|
Vec3_Add(&pos, &origin, &offset);
|
||||||
Particle_Reset(&p->base, pos, velocity, 40.0f);
|
Particle_Reset(&p->base, pos, velocity, 40.0f);
|
||||||
|
|
||||||
type = Random_Range(&rnd, 0, 30);
|
type = Random_Next(&rnd, 30);
|
||||||
p->base.size = (uint8_t)(type >= 28 ? 2 : (type >= 25 ? 4 : 3));
|
p->base.size = (uint8_t)(type >= 28 ? 2 : (type >= 25 ? 4 : 3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1126,7 +1126,7 @@ static void Font_DirCallback(const String* path, void* obj) {
|
|||||||
/* Completely skip windows .FON files */
|
/* Completely skip windows .FON files */
|
||||||
if (String_CaselessEnds(path, &fonExt)) return;
|
if (String_CaselessEnds(path, &fonExt)) return;
|
||||||
|
|
||||||
/* If font is already known good, skip it */
|
/* If font is already known, skip it */
|
||||||
for (i = 0; i < font_list.entries.count; i++) {
|
for (i = 0; i < font_list.entries.count; i++) {
|
||||||
entry = StringsBuffer_UNSAFE_Get(&font_list.entries, i);
|
entry = StringsBuffer_UNSAFE_Get(&font_list.entries, i);
|
||||||
String_UNSAFE_Separate(&entry, font_list.separator, &name, &value);
|
String_UNSAFE_Separate(&entry, font_list.separator, &name, &value);
|
||||||
|
@ -2274,7 +2274,7 @@ static int TextGroupWidget_NextUrl(char* chars, int charsLen, int i) {
|
|||||||
return charsLen;
|
return charsLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int TextGroupWidget_UrlEnd(char* chars, int charsLen, int32_t* begs, int begsLen, int i) {
|
static int TextGroupWidget_UrlEnd(char* chars, int charsLen, int* begs, int begsLen, int i) {
|
||||||
int start = i, j;
|
int start = i, j;
|
||||||
int next, left;
|
int next, left;
|
||||||
bool isBeg;
|
bool isBeg;
|
||||||
|
27
src/Window.c
27
src/Window.c
@ -2772,7 +2772,7 @@ static void Window_RefreshBounds(void) {
|
|||||||
Event_RaiseVoid(&WindowEvents.Resized);
|
Event_RaiseVoid(&WindowEvents.Resized);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Key Window_MapKey(int32_t code) {
|
static Key Window_MapKey(int code) {
|
||||||
if (code >= AKEYCODE_0 && code <= AKEYCODE_9) return (code - AKEYCODE_0) + '0';
|
if (code >= AKEYCODE_0 && code <= AKEYCODE_9) return (code - AKEYCODE_0) + '0';
|
||||||
if (code >= AKEYCODE_A && code <= AKEYCODE_Z) return (code - AKEYCODE_A) + 'A';
|
if (code >= AKEYCODE_A && code <= AKEYCODE_Z) return (code - AKEYCODE_A) + 'A';
|
||||||
if (code >= AKEYCODE_F1 && code <= AKEYCODE_F12) return (code - AKEYCODE_F1) + KEY_F1;
|
if (code >= AKEYCODE_F1 && code <= AKEYCODE_F12) return (code - AKEYCODE_F1) + KEY_F1;
|
||||||
@ -3056,7 +3056,7 @@ void Window_DrawFramebuffer(Rect2D r) {
|
|||||||
uint32_t* src;
|
uint32_t* src;
|
||||||
uint32_t* dst;
|
uint32_t* dst;
|
||||||
ARect b;
|
ARect b;
|
||||||
int32_t y, res, size;
|
int y, res, size;
|
||||||
|
|
||||||
Platform_LogConst("DRAW_RAW");
|
Platform_LogConst("DRAW_RAW");
|
||||||
/* window not created yet */
|
/* window not created yet */
|
||||||
@ -3070,9 +3070,9 @@ void Window_DrawFramebuffer(Rect2D r) {
|
|||||||
if (res) Logger_Abort2(res, "Locking window pixels");
|
if (res) Logger_Abort2(res, "Locking window pixels");
|
||||||
Platform_Log4("ADJUS: %i,%i - %i,%i", &b.left, &b.top, &b.right, &b.bottom);
|
Platform_Log4("ADJUS: %i,%i - %i,%i", &b.left, &b.top, &b.right, &b.bottom);
|
||||||
|
|
||||||
int32_t width = ANativeWindow_getWidth(win_handle);
|
int width = ANativeWindow_getWidth(win_handle);
|
||||||
int32_t height = ANativeWindow_getHeight(win_handle);
|
int height = ANativeWindow_getHeight(win_handle);
|
||||||
int32_t format = ANativeWindow_getFormat(win_handle);
|
int format = ANativeWindow_getFormat(win_handle);
|
||||||
|
|
||||||
Platform_Log3("WIN SIZE: %i,%i %i", &width, &height, &format);
|
Platform_Log3("WIN SIZE: %i,%i %i", &width, &height, &format);
|
||||||
Platform_Log4("BUF SIZE: %i,%i %i/%i", &buffer.width, &buffer.height, &buffer.format, &buffer.stride);
|
Platform_Log4("BUF SIZE: %i,%i %i/%i", &buffer.width, &buffer.height, &buffer.format, &buffer.stride);
|
||||||
@ -3562,10 +3562,13 @@ static EGLint ctx_numConfig;
|
|||||||
static void GLContext_InitSurface(void) {
|
static void GLContext_InitSurface(void) {
|
||||||
if (!win_handle) return; /* window not created or lost */
|
if (!win_handle) return; /* window not created or lost */
|
||||||
ctx_surface = eglCreateWindowSurface(ctx_display, ctx_config, win_handle, NULL);
|
ctx_surface = eglCreateWindowSurface(ctx_display, ctx_config, win_handle, NULL);
|
||||||
|
|
||||||
|
if (!ctx_surface) return;
|
||||||
eglMakeCurrent(ctx_display, ctx_surface, ctx_surface, ctx_context);
|
eglMakeCurrent(ctx_display, ctx_surface, ctx_surface, ctx_context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void GLContext_FreeSurface(void) {
|
static void GLContext_FreeSurface(void) {
|
||||||
|
if (!ctx_surface) return;
|
||||||
eglMakeCurrent(ctx_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
eglMakeCurrent(ctx_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||||
eglDestroySurface(ctx_display, ctx_surface);
|
eglDestroySurface(ctx_display, ctx_surface);
|
||||||
ctx_surface = NULL;
|
ctx_surface = NULL;
|
||||||
@ -3602,6 +3605,7 @@ void GLContext_Update(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool GLContext_TryRestore(void) {
|
bool GLContext_TryRestore(void) {
|
||||||
|
GLContext_FreeSurface();
|
||||||
GLContext_InitSurface();
|
GLContext_InitSurface();
|
||||||
return ctx_surface != NULL;
|
return ctx_surface != NULL;
|
||||||
}
|
}
|
||||||
@ -3617,8 +3621,19 @@ void* GLContext_GetAddress(const char* function) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool GLContext_SwapBuffers(void) {
|
bool GLContext_SwapBuffers(void) {
|
||||||
|
EGLint err;
|
||||||
if (!ctx_surface) return false;
|
if (!ctx_surface) return false;
|
||||||
eglSwapBuffers(ctx_display, ctx_surface);
|
if (eglSwapBuffers(ctx_display, ctx_surface)) return true;
|
||||||
|
|
||||||
|
err = eglGetError();
|
||||||
|
/* We get EGL_BAD_SURFACE if the window surface is destroyed on android */
|
||||||
|
/* TODO: Maybe detect from the SurfaceDestroyed event handler instead */
|
||||||
|
if (err == EGL_BAD_SURFACE) {
|
||||||
|
GLContext_FreeSurface(); return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TODO: figure out how to handle other errors */
|
||||||
|
Logger_Abort2(err, "Failed to swap buffers");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user