Skip to content

Commit

Permalink
Move lighting data to flash
Browse files Browse the repository at this point in the history
Makes RAM consumption for larger worlds more predictable
  • Loading branch information
bernhardstrobl committed Dec 9, 2022
1 parent 795e4ad commit d565580
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions Blender/pico3d_blender_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''

Expand Down Expand Up @@ -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}'
Expand Down
44 changes: 22 additions & 22 deletions chunk_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -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}},
Expand Down
2 changes: 1 addition & 1 deletion engine/render_globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ struct light {
//lights in a chunk
struct chunk_lighting {
int32_t number;
struct light *lights;
const struct light *lights;
};


Expand Down
2 changes: 1 addition & 1 deletion engine/render_lighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) +
Expand Down

0 comments on commit d565580

Please sign in to comment.