Skip to content

Commit

Permalink
save chunk state + update terrain system
Browse files Browse the repository at this point in the history
  • Loading branch information
julesgrc0 committed Mar 16, 2024
1 parent cb2c31d commit 37d196e
Show file tree
Hide file tree
Showing 26 changed files with 478 additions and 178 deletions.
Binary file modified android/app/src/main/assets/resource.pack
Binary file not shown.
18 changes: 14 additions & 4 deletions android/app/src/main/java/com/julesgrc0/wispy/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@


import android.app.NativeActivity;
import android.content.pm.ActivityInfo;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;



public class MainActivity extends NativeActivity {
static {
System.loadLibrary("main");
Expand All @@ -21,10 +21,20 @@ protected void onCreate(Bundle 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);
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED

);
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
View.SYSTEM_UI_FLAG_IMMERSIVE
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
);
}
}
71 changes: 43 additions & 28 deletions src/core/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,56 @@ w_config *load_config() {
if (cfg == NULL)
return NULL;

char *config_path = malloc(MAX_PATH * 2);
char *config_path = malloc(PATH_LENGTH);
if (config_path == NULL)
return NULL;

config_path[0] = 0;
strcat(config_path, GetApplicationDirectory());
strcat(config_path, CONFIG_NAME);

if (FileExists(config_path)) {
char *data = LoadFileText(config_path);
if (data == NULL) {
char *config_data = LoadFileText(config_path);
if (config_data == NULL) {
free(config_path);
free(cfg);
return NULL;
}
json_object *root = json_tokener_parse(data);

json_object *root = json_tokener_parse(config_data);
if (root == NULL) {
free(data);
free(config_path);
free(cfg);
UnloadFileText(config_data);
return NULL;
}

json_object *js_fullscreen = json_object_object_get(root, "fullscreen");
json_object *js_msaa4x = json_object_object_get(root, "msaa4x");
json_object *js_vsync = json_object_object_get(root, "vsync");
json_object *js_width = json_object_object_get(root, "width");
json_object *js_height = json_object_object_get(root, "height");
json_object *js_max_fps = json_object_object_get(root, "max_fps");

cfg->fullscreen = (unsigned int)json_object_get_uint64(js_fullscreen);
cfg->msaa4x = (unsigned int)json_object_get_uint64(js_msaa4x);
cfg->vsync = (unsigned int)json_object_get_uint64(js_vsync);
cfg->width = (unsigned int)json_object_get_uint64(js_width);
cfg->height = (unsigned int)json_object_get_uint64(js_height);
cfg->max_fps = (unsigned int)json_object_get_uint64(js_max_fps);

json_object_put(js_fullscreen);


json_object *js_msaa4x = json_object_object_get(root, "msaa4x");
cfg->msaa4x = (unsigned int)json_object_get_uint64(js_msaa4x);
json_object_put(js_msaa4x);

json_object *js_vsync = json_object_object_get(root, "vsync");
cfg->vsync = (unsigned int)json_object_get_uint64(js_vsync);
json_object_put(js_vsync);

json_object *js_width = json_object_object_get(root, "width");
cfg->width = (unsigned int)json_object_get_uint64(js_width);
json_object_put(js_width);

json_object *js_height = json_object_object_get(root, "height");
cfg->height = (unsigned int)json_object_get_uint64(js_height);
json_object_put(js_height);

json_object *js_max_fps = json_object_object_get(root, "max_fps");
cfg->max_fps = (unsigned int)json_object_get_uint64(js_max_fps);
json_object_put(js_max_fps);

json_object_put(root);
free(data);
UnloadFileText(config_data);
} else {
memset(cfg, 0, sizeof(w_config));
cfg->fullscreen = 1;
Expand All @@ -70,7 +75,7 @@ w_config *load_config() {
}

void save_config(w_config *config) {
char *config_path = malloc(MAX_PATH * 2);
char *config_path = malloc(PATH_LENGTH);
if (config_path == NULL)
return;

Expand All @@ -85,23 +90,33 @@ void save_config(w_config *config) {
}

json_object *js_fullscreen = json_object_new_uint64(config->fullscreen);
json_object *js_msaa4x = json_object_new_uint64(config->msaa4x);
json_object *js_vsync = json_object_new_uint64(config->vsync);
json_object *js_width = json_object_new_uint64(config->width);
json_object *js_height = json_object_new_uint64(config->height);
json_object *js_max_fps = json_object_new_uint64(config->max_fps);

json_object_object_add(root, "fullscreen", js_fullscreen);

json_object *js_msaa4x = json_object_new_uint64(config->msaa4x);
json_object_object_add(root, "msaa4x", js_msaa4x);

json_object *js_vsync = json_object_new_uint64(config->vsync);
json_object_object_add(root, "vsync", js_vsync);

json_object *js_width = json_object_new_uint64(config->width);
json_object_object_add(root, "width", js_width);

json_object *js_height = json_object_new_uint64(config->height);
json_object_object_add(root, "height", js_height);

json_object *js_max_fps = json_object_new_uint64(config->max_fps);
json_object_object_add(root, "max_fps", js_max_fps);

const char *data =
json_object_to_json_string_ext(root, JSON_C_TO_STRING_PRETTY);
json_object_to_json_string_ext(root, JSON_C_TO_STRING_PRETTY_TAB);
SaveFileText(config_path, (char *)data);
json_object_put(root);

json_object_put(js_fullscreen);
json_object_put(js_msaa4x);
json_object_put(js_vsync);
json_object_put(js_width);
json_object_put(js_height);
json_object_put(js_max_fps);
json_object_put(root);
free(config_path);
}
7 changes: 4 additions & 3 deletions src/core/utils/camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ void destroy_camera(w_camera *camera) {
LOG("camera (null) already destroyed");
return;
}
if (camera->matrix != NULL) {
free(camera->matrix);
}
free(camera);
}

Expand Down Expand Up @@ -119,7 +122,5 @@ void begin_camera(w_camera *camera) {
rlLoadIdentity();
rlMultMatrixf(camera->matrix);
}
void end_camera() {
EndMode2D();
}
void end_camera() { EndMode2D(); }
#endif
17 changes: 0 additions & 17 deletions src/gui/action.h

This file was deleted.

24 changes: 12 additions & 12 deletions src/gui/action.c → src/gui/iconbutton.c
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#include "action.h"
#include "iconbutton.h"

w_guiaction *create_action(w_guicontext *ctx, Vector2 position, float size,
w_guiiconbutton *create_iconbutton(w_guicontext *ctx, Vector2 position, float size,
Texture texture) {
w_guiaction *action = malloc(sizeof(w_guiaction));
if (action == NULL)
w_guiiconbutton *iconbutton = malloc(sizeof(w_guiiconbutton));
if (iconbutton == NULL)
return NULL;
memset(action, 0, sizeof(w_guiaction));
action->ctx = ctx;
action->position = Vector2SubtractValue(position, size);
action->size = size;
action->icon = texture;
memset(iconbutton, 0, sizeof(w_guiiconbutton));
iconbutton->ctx = ctx;
iconbutton->position = Vector2SubtractValue(position, size);
iconbutton->size = size;
iconbutton->icon = texture;

return action;
return iconbutton;
}

bool update_action(w_guiaction *act) {
bool update_iconbutton(w_guiiconbutton *act) {
#if defined(WISPY_ANDROID)
bool clicked = check_collision_touch(act->position, act->size);
#else
Expand All @@ -36,7 +36,7 @@ bool update_action(w_guiaction *act) {
return clicked;
}

void destroy_action(w_guiaction *act) {
void destroy_iconbutton(w_guiiconbutton *act) {
if (act) {
free(act);
}
Expand Down
17 changes: 17 additions & 0 deletions src/gui/iconbutton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once
#include "../core/controls.h"
#include "../stdafx.h"
#include "gui.h"

typedef struct w_guiiconbutton {
Vector2 position;
Texture icon;
float size;
w_guicontext *ctx;

} w_guiiconbutton;

w_guiiconbutton *create_iconbutton(w_guicontext *ctx, Vector2 position, float size,
Texture texture);
bool update_iconbutton(w_guiiconbutton *act);
void destroy_iconbutton(w_guiiconbutton *act);
33 changes: 16 additions & 17 deletions src/screens/game/bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@ w_bridge *create_bridge() {
}
memset(td, 0, sizeof(w_bridge));

td->chunk_group = create_chunkgroup(CHUNK_GROUP_MID_LEN);
if (td->chunk_group == NULL) {
td->terrain = create_terrain(CHUNK_GROUP_MID_LEN);
if (td->terrain == NULL) {
destroy_bridge(td);
return NULL;
}

td->chunk_view = create_chunkview(td->chunk_group->chunks[0]);
if (td->chunk_view == NULL) {
destroy_bridge(td);
return NULL;
}

td->player = create_player(td->chunk_group->position);
td->player = create_player(td->terrain->group->position);
if (td->player == NULL) {
destroy_bridge(td);
return NULL;
Expand Down Expand Up @@ -89,8 +83,7 @@ void destroy_bridge(w_bridge *td) {
#endif

destroy_controls(td->ctrl);
destroy_chunkgroup(td->chunk_group);
destroy_chunkview(td->chunk_view);
destroy_terrain(td->terrain);
destroy_player(td->player);
destroy_camera(td->camera);

Expand All @@ -99,7 +92,7 @@ void destroy_bridge(w_bridge *td) {

void physics_update_bridge(w_bridge *td) {

check_player_collision_vel(td->player, td->chunk_view);
check_player_collision_vel(td->player, td->terrain->view);
Vector2 next_position =
Vector2Scale(td->player->velocity, PHYSICS_TICK * PLAYER_SPEED);

Expand All @@ -119,19 +112,25 @@ void physics_update_bridge(w_bridge *td) {

void update_bridge(w_bridge *td) {
if (td->ctrl->key != 0 ||
#if defined(WISPY_ANDROID)
#if defined(WISPY_ANDROID)
!Vector2Equals(td->camera->target_position, td->camera->position) ||
#else
#else
!Vector2Equals(td->camera->target_position, get_camera_vec(td->camera)) ||
#endif
#endif
td->force_update) {

if (!update_chunkview(td->chunk_view, td->chunk_group, td->camera)) {
if (!update_chunkview(td->terrain->view, td->terrain->group, td->camera,
#if defined(WISPY_ANDROID)
update_renderblock
#else
update_renderblock_threadsafe
#endif
)) {
LOG("failed to update chunk view");
td->is_active = false;
return;
}
update_chunkview_lighting(td->chunk_view, get_player_center(td->player),
update_chunkview_lighting(td->terrain->view, get_player_center(td->player),
RENDER_CUBE_COUNT * CUBE_W);
td->force_update = false;
}
Expand Down
7 changes: 2 additions & 5 deletions src/screens/game/bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
#include "../../stdafx.h"
#include "../../entities/player.h"
#include "../../terrain/block.h"
#include "../../terrain/chunk.h"
#include "../../terrain/chunk_group.h"
#include "../../terrain/chunk_view.h"
#include "../../terrain/terrain.h"

#include "../../core/utils/camera.h"
#include "../../core/controls.h"
Expand All @@ -15,8 +13,7 @@ typedef struct w_bridge {
bool is_active;
bool force_update;

w_chunkgroup *chunk_group;
w_chunkview *chunk_view;
w_terrain* terrain;
w_controls *ctrl;

w_player *player;
Expand Down
Loading

0 comments on commit 37d196e

Please sign in to comment.