Skip to content

Commit

Permalink
Fix inflexible chunk size
Browse files Browse the repository at this point in the history
Chunk size should now be customizable depending on use case.
  • Loading branch information
bernhardstrobl committed Dec 27, 2023
1 parent e769860 commit a0ebe8c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 3 additions & 1 deletion engine/chunk_globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
//#define WORLD_SIZE_X 12 //amount of chunks in x orientation
//#define WORLD_SIZE_Y 12 //amount of chunks in y orientation

#define CHUNK_SIZE (FIXED_POINT_FACTOR * 10) //10 meter size per chunk
#define CHUNK_UNITS 10 //10 meter size per chunk (max is around 64)

#define CHUNK_SIZE (FIXED_POINT_FACTOR * CHUNK_UNITS) //Total fixed point representation of one chunk
//starting location of chunks in world coordinates
#define CHUNK_OFFSET_X (-(WORLD_SIZE_X * CHUNK_SIZE) / 2)
#define CHUNK_OFFSET_Y (-(WORLD_SIZE_Y * CHUNK_SIZE) / 2)
Expand Down
9 changes: 5 additions & 4 deletions engine/render_camera.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "render_globals.h"
#include "chunk_globals.h"
#include "render_math.h"

float camera_position[3] = {0.0, 0.0, 0.0};
Expand Down Expand Up @@ -120,12 +121,12 @@ void render_view_projection() {
float old_position_z = camera_position[2];

//calculate and update needed global offsets
global_offset_x = camera_position[0] / 10;
global_offset_z = camera_position[2] / 10;
global_offset_x = camera_position[0] / CHUNK_UNITS;
global_offset_z = camera_position[2] / CHUNK_UNITS;

//we update the camera position to the new one and move the camera
camera_position[0] -= global_offset_x * 10;
camera_position[2] -= global_offset_z * 10;
camera_position[0] -= global_offset_x * CHUNK_UNITS;
camera_position[2] -= global_offset_z * CHUNK_UNITS;

update_camera();

Expand Down
1 change: 0 additions & 1 deletion game/logic_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ void display_menu() {
#else
if (demo_progress < 2500) {
text("Pico3D Engine", 28, 20);
text("by: Bernhard Strobl", 10, 30);
}

if ((demo_progress / 32) % 2 == 0) {
Expand Down

0 comments on commit a0ebe8c

Please sign in to comment.