Skip to content

Commit

Permalink
pthread bugs fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
julesgrc0 committed Feb 16, 2024
1 parent 99ad208 commit 4f5f486
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 86 deletions.
1 change: 1 addition & 0 deletions android/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ android {
release {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
signingConfig = signingConfigs.getByName("debug")
}
}
compileOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@


import android.app.NativeActivity;
import android.os.Build;
import android.os.Bundle;
import android.widget.Toast;
import android.view.WindowManager;


public class MainActivity extends NativeActivity {
Expand All @@ -14,5 +15,10 @@ public class MainActivity extends NativeActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
}
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
}
}
3 changes: 1 addition & 2 deletions src/core/bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ w_bridge *create_bridge() {
td->handle = CreateThread(NULL, 0, &update_bridge, td, 0, NULL);
if (td->handle == INVALID_HANDLE_VALUE)
#else
td->handle = pthread_create(&td->handle, NULL, &update_bridge, td);
if (td->handle == 0)
if (pthread_create(&td->handle, NULL, &update_bridge, td) != 0)
#endif // _WIN32
{
LOG("failed to create bridge thread");
Expand Down
7 changes: 2 additions & 5 deletions src/core/state.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,13 @@ w_config *load_config()
#endif // !__ANDROID__

cfg->fullscreen = 1;
cfg->vsync = 0;
cfg->msaa4x = 1;
#ifdef __ANDROID__
cfg->vsync = 1;
#else
cfg->vsync = 0;
#endif

cfg->max_fps = 0;
cfg->height = 0;
cfg->width = 0;

#if defined(_DEBUG) && !defined(__ANDROID__)
cfg->fullscreen = 0;
cfg->height = 720;
Expand Down
6 changes: 6 additions & 0 deletions src/screen/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ void game_screen(w_state *state) {
};

w_bridge *td = create_bridge();
if(td == NULL) return;

w_blockbreaker *bb = create_blockbreaker(state, td->chunk_view, td->camera);
if(bb == NULL) {
destroy_bridge(td);
return;
}
while (!WindowShouldClose() && td->is_active) {
update_keyboard(td->keyboard);

Expand Down
72 changes: 39 additions & 33 deletions src/screen/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,55 +58,61 @@ void menu_screen(w_state *state) {
(Vector2){0, title_text->font_size + 10}),
(char *)TextFormat("made by @julesgrc0 - %s", WISPY_VERSION), 20, WHITE);

float move = 0.f;
while (!WindowShouldClose() && is_active) {
while (!WindowShouldClose() && is_active) {

camera.target.x += sinf(GetTime() * 0.05) * 100.0f * GetFrameTime();
camera.target.y += cosf(GetTime() * 0.05) * 100.0f * GetFrameTime();

update_chunkview(view, grp, get_camera_view(&camera));
update_chunkview_lighting(
view, Vector2Add(camera.target, (Vector2){RENDER_W / 2, RENDER_H / 2}),
DEFAULT_LIGHT_RADIUS * 0.75);

BeginTextureMode(state->render);
ClearBackground(BLACK);
DrawRectangleGradientV(0, 0, RENDER_W, RENDER_H, (Color){66, 135, 245, 255},
(Color){142, 184, 250, 255});
BeginMode2D(camera);
for (unsigned int i = 0; i < view->textures_len; i++) {
DrawTexturePro(block_textures[view->blocks[i].block.type - 1],
view->blocks[i].src, view->blocks[i].dst, VEC_ZERO, 0,
view->blocks[i].light);
}
EndMode2D();

EndTextureMode();
view, Vector2Add(camera.target, (Vector2){RENDER_W / 2, RENDER_H / 2}),
DEFAULT_LIGHT_RADIUS * 0.75);

BeginTextureMode(state->render);
ClearBackground(BLACK);
DrawRectangleGradientV(0, 0, RENDER_W, RENDER_H, (Color){66, 135, 245, 255},
(Color){142, 184, 250, 255});
BeginMode2D(camera);
for (unsigned int i = 0; i < view->textures_len; i++) {
DrawTexturePro(block_textures[view->blocks[i].block.type - 1],
view->blocks[i].src, view->blocks[i].dst, VEC_ZERO, 0,
view->blocks[i].light);
}
EndMode2D();

EndTextureMode();

BeginDrawing();
ClearBackground(BLACK);
BeginShaderMode(blurShader);
DrawTexturePro(state->render.texture, state->src_rnd, state->dest_rnd,
VEC_ZERO, 0.0f, WHITE);
EndShaderMode();

#ifndef __ANDROID__
BeginShaderMode(blurShader);
#endif

DrawTexturePro(state->render.texture, state->src_rnd, state->dest_rnd,
VEC_ZERO, 0.0f, WHITE);

#ifndef __ANDROID__
EndShaderMode();
#endif

DrawRectangleLinesEx(
(Rectangle){0, 0, ctx->render_size.x, ctx->render_size.y}, 5,
Fade(BLACK, 0.9));
(Rectangle){0, 0, ctx->render_size.x, ctx->render_size.y}, 5,
Fade(BLACK, 0.9));

if (update_button(play_button)) {
is_active = false;
}
if (update_button(setting_button)) {
// TODO: Implement settings screen
if (update_button(play_button)) {
is_active = false;
}
if (update_button(exit_button)) {
state->state = FS_EXIT;
break;
if (update_button(setting_button)) {
// TODO: Implement settings screen
}
if (update_button(exit_button)) {
state->state = FS_EXIT;
break;
}

update_text(title_text);
update_text(credit_text);

EndDrawing();
}

Expand Down
2 changes: 1 addition & 1 deletion src/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
#elif __linux__
#define MAX_PATH 260

#include <pthread.h>
#include <unistd.h>
#include <pthread.h>

#elif __ANDROID__

Expand Down
4 changes: 1 addition & 3 deletions src/terrain/chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ w_chunk *create_chunk(unsigned int position, bool thread) {
chunk->handle = CreateThread(NULL, 0, &create_chunk_thread, chunk, 0, 0);
if (chunk->handle == INVALID_HANDLE_VALUE)
#else
chunk->handle =
pthread_create(&chunk->handle, NULL, &create_chunk_thread, chunk);
if (chunk->handle == 0)
if (pthread_create(&chunk->handle, NULL, &create_chunk_thread, chunk) != 0)
#endif // _WIN32
{
LOG("failed to create chunk thread");
Expand Down
Loading

0 comments on commit 4f5f486

Please sign in to comment.