From d565580fab2be4e12bb6d1a3ad798e6fa0e5cf66 Mon Sep 17 00:00:00 2001 From: Bernhard Strobl <52598728+bernhardstrobl@users.noreply.github.com> Date: Fri, 9 Dec 2022 14:30:54 +0100 Subject: [PATCH] Move lighting data to flash Makes RAM consumption for larger worlds more predictable --- Blender/pico3d_blender_exporter.py | 4 +-- chunk_data.h | 44 +++++++++++++++--------------- engine/render_globals.h | 2 +- engine/render_lighting.cpp | 2 +- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Blender/pico3d_blender_exporter.py b/Blender/pico3d_blender_exporter.py index e8dacc3..5f8596c 100644 --- a/Blender/pico3d_blender_exporter.py +++ b/Blender/pico3d_blender_exporter.py @@ -569,7 +569,7 @@ def generate_lights(self, context): fixed_point_factor = context.scene.fixed_point_factor lights = '' - chunk_lights = 'struct chunk_lighting chunk_lights[' + str(world_size_x) + '][' + str(world_size_y) + '] = {' + chunk_lights = 'const struct chunk_lighting chunk_lights[' + str(world_size_x) + '][' + str(world_size_y) + '] = {' chunk_light_data = '' @@ -608,7 +608,7 @@ def generate_lights(self, context): #write out light information for that chunk if (light_count > 0): - chunk_light_data += 'struct light lights_' + str(x) + '_' + str(y) + '[' + str(light_count) + '] = {' + light_data + '};\n' + chunk_light_data += 'const struct light lights_' + str(x) + '_' + str(y) + '[' + str(light_count) + '] = {' + light_data + '};\n' chunk_lights += '{' + str(light_count) + ', ' + 'lights_' + str(x) + '_' + str(y) + '}' else: chunk_lights += '{0, NULL}' diff --git a/chunk_data.h b/chunk_data.h index 2fb2ded..fa97e4c 100644 --- a/chunk_data.h +++ b/chunk_data.h @@ -6182,29 +6182,29 @@ struct texture chunk_texture_list[11] = {{32, 0, 0, texture0}, {32, 0, 0, texture8}, {32, 0, 0, texture9}, {32, 0, 0, texture10}}; -struct light lights_0_4[1] = {{-52610,3487,-16584}}; -struct light lights_1_1[1] = {{-46605,8919,-43803}}; -struct light lights_1_2[1] = {{-49841,6168,-30955}}; -struct light lights_1_3[1] = {{-44624,12437,-23313}}; -struct light lights_1_5[1] = {{-42158,4804,-1527}}; -struct light lights_1_6[1] = {{-49209,4804,5727}}; -struct light lights_1_7[1] = {{-41948,4804,11493}}; -struct light lights_2_1[1] = {{-36197,3567,-50205}}; -struct light lights_2_6[1] = {{-35515,6256,4518}}; -struct light lights_2_7[1] = {{-32061,4838,18537}}; -struct light lights_2_8[1] = {{-38616,4838,28471}}; -struct light lights_2_9[1] = {{-33019,4838,38831}}; -struct light lights_2_10[1] = {{-38953,4838,50340}}; -struct light lights_3_1[1] = {{-25117,8328,-43793}}; -struct light lights_3_2[1] = {{-26009,15195,-38549}}; -struct light lights_3_3[1] = {{-22167,8031,-21032}}; -struct light lights_3_4[2] = {{-28239,16250,-16556}, +const struct light lights_0_4[1] = {{-52610,3487,-16584}}; +const struct light lights_1_1[1] = {{-46605,8919,-43803}}; +const struct light lights_1_2[1] = {{-49841,6168,-30955}}; +const struct light lights_1_3[1] = {{-44624,12437,-23313}}; +const struct light lights_1_5[1] = {{-42158,4804,-1527}}; +const struct light lights_1_6[1] = {{-49209,4804,5727}}; +const struct light lights_1_7[1] = {{-41948,4804,11493}}; +const struct light lights_2_1[1] = {{-36197,3567,-50205}}; +const struct light lights_2_6[1] = {{-35515,6256,4518}}; +const struct light lights_2_7[1] = {{-32061,4838,18537}}; +const struct light lights_2_8[1] = {{-38616,4838,28471}}; +const struct light lights_2_9[1] = {{-33019,4838,38831}}; +const struct light lights_2_10[1] = {{-38953,4838,50340}}; +const struct light lights_3_1[1] = {{-25117,8328,-43793}}; +const struct light lights_3_2[1] = {{-26009,15195,-38549}}; +const struct light lights_3_3[1] = {{-22167,8031,-21032}}; +const struct light lights_3_4[2] = {{-28239,16250,-16556}, {-29301,4952,-10770}}; -struct light lights_3_5[1] = {{-29301,4952,-941}}; -struct light lights_3_7[1] = {{-29721,4838,11386}}; -struct light lights_4_6[1] = {{-11391,4952,1068}}; -struct light lights_10_2[1] = {{46080,5785,-35840}}; -struct chunk_lighting chunk_lights[12][12] = {{{0, NULL},{0, NULL},{0, NULL},{0, NULL},{1, lights_0_4},{0, NULL},{0, NULL},{0, NULL},{0, NULL},{0, NULL},{0, NULL},{0, NULL}}, +const struct light lights_3_5[1] = {{-29301,4952,-941}}; +const struct light lights_3_7[1] = {{-29721,4838,11386}}; +const struct light lights_4_6[1] = {{-11391,4952,1068}}; +const struct light lights_10_2[1] = {{46080,5785,-35840}}; +const struct chunk_lighting chunk_lights[12][12] = {{{0, NULL},{0, NULL},{0, NULL},{0, NULL},{1, lights_0_4},{0, NULL},{0, NULL},{0, NULL},{0, NULL},{0, NULL},{0, NULL},{0, NULL}}, {{0, NULL},{1, lights_1_1},{1, lights_1_2},{1, lights_1_3},{0, NULL},{1, lights_1_5},{1, lights_1_6},{1, lights_1_7},{0, NULL},{0, NULL},{0, NULL},{0, NULL}}, {{0, NULL},{1, lights_2_1},{0, NULL},{0, NULL},{0, NULL},{0, NULL},{1, lights_2_6},{1, lights_2_7},{1, lights_2_8},{1, lights_2_9},{1, lights_2_10},{0, NULL}}, {{0, NULL},{1, lights_3_1},{1, lights_3_2},{1, lights_3_3},{2, lights_3_4},{1, lights_3_5},{0, NULL},{1, lights_3_7},{0, NULL},{0, NULL},{0, NULL},{0, NULL}}, diff --git a/engine/render_globals.h b/engine/render_globals.h index 5dab637..eb7ce72 100644 --- a/engine/render_globals.h +++ b/engine/render_globals.h @@ -129,7 +129,7 @@ struct light { //lights in a chunk struct chunk_lighting { int32_t number; - struct light *lights; + const struct light *lights; }; diff --git a/engine/render_lighting.cpp b/engine/render_lighting.cpp index 0d8d20d..4a1fe0e 100644 --- a/engine/render_lighting.cpp +++ b/engine/render_lighting.cpp @@ -2,7 +2,7 @@ //every vertex is compared to the chunk it is in and the neighbouring chunks in a 3x3 fashion -int32_t process_lighting(struct light &light, vertex_32 &vertex, color_t &color) { +int32_t process_lighting(const struct light &light, vertex_32 &vertex, color_t &color) { if (((light.position.x - vertex.x) * (light.position.x - vertex.x)) + ((light.position.y - vertex.y) * (light.position.y - vertex.y)) +