Skip to content

Commit

Permalink
Merge pull request #2 from Daft-Freak/pre-32blit-refactoring
Browse files Browse the repository at this point in the history
Most of my changes
  • Loading branch information
bernhardstrobl authored Dec 9, 2023
2 parents ed73beb + 51717ea commit e769860
Show file tree
Hide file tree
Showing 36 changed files with 6,918 additions and 6,851 deletions.
95 changes: 57 additions & 38 deletions Blender/pico3d_blender_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
}

import bpy
from os import path

class Pico3dPanel(bpy.types.Panel):
bl_idname = 'VIEW3D_PT_pico3d_panel'
Expand Down Expand Up @@ -98,7 +99,7 @@ def execute(self, context): # execute() is called when running the operat
mesh = bpy.data.meshes[meshname]



output = self.generate_vertices(context, mesh, modelname, 1000, False) + '\n'

#output += self.generate_textures()
Expand All @@ -119,44 +120,50 @@ def execute(self, context): # execute() is called when running the operat

world_size_x = context.scene.world_size_x
world_size_y = context.scene.world_size_y

chunk_output = 'const struct chunk_flash lod0_chunks[WORLD_SIZE_X][WORLD_SIZE_Y] = {\n'


header_output = ''
src_output = f'#include "{path.basename(file_path)}.h"\n#include "engine/render_globals.h"\n#include "engine/chunk_globals.h"\n'

# world size
header_output += '#define WORLD_SIZE_X ' + str(world_size_x) + '\n#define WORLD_SIZE_Y ' + str(world_size_y) + '\n'

#First do lod0
max_triangles = context.scene.lod0_triangle_limit

chunk_output = self.export_chunks(context, 0, max_triangles)

file_output += '#define WORLD_SIZE_X ' + str(world_size_x) + '\n#define WORLD_SIZE_Y ' + str(world_size_y) + '\n'
file_output += chunk_output + '\n'
#print(triangle_output)
#print(chunk_output)


#reset values
chunk_output = 'const struct chunk_flash lod1_chunks[WORLD_SIZE_X][WORLD_SIZE_Y] = {\n'


chunk_decl, chunk_impl = self.export_chunks(context, 0, max_triangles)
header_output += chunk_decl
src_output += chunk_impl + '\n'

#Then do lod1
max_triangles = context.scene.lod1_triangle_limit

chunk_decl, chunk_impl = self.export_chunks(context, 1, max_triangles)
header_output += chunk_decl
src_output += chunk_impl + '\n'

# textures and lights


chunk_output = self.export_chunks(context, 1, max_triangles) + '\n'

chunk_output += self.generate_textures() + '\n'
textures_decl, textures_impl = self.generate_textures()


chunk_output += self.generate_lights(context)
lights_decl, lights_impl = self.generate_lights(context)

header_output += textures_decl + '\n' + lights_decl
src_output += textures_impl + '\n' +lights_impl

file_output += chunk_output
#print(triangle_output)
#print(chunk_output)

if (file_path == ''):
print(file_output)
print(header_output)
print(src_output)
else:
f = open(file_path, "w")
f.write(file_output)
f = open(file_path + '.h', "w")
f.write(header_output)
f.close()

f = open(file_path + '.cpp', "w")
f.write(src_output)
f.close()


Expand Down Expand Up @@ -471,10 +478,15 @@ def export_chunks(self, context, lod, max_triangles):
world_size_y = context.scene.world_size_y

repeat_chunk_list = []

chunk_decl = f'const struct chunk lod{lod}_chunks[WORLD_SIZE_X][WORLD_SIZE_Y]'

decl_output = f'extern {chunk_decl};\n'

chunk_output = 'const struct chunk lod' + str(lod) + '_chunks[WORLD_SIZE_X][WORLD_SIZE_Y] = {\n'
chunk_output = f'{chunk_decl} = {{\n'

triangle_output = ''


for x in range(world_size_x):

Expand All @@ -493,8 +505,8 @@ def export_chunks(self, context, lod, max_triangles):


triangle_output += self.generate_vertices(context, mesh, modelname, max_triangles, True) + "\n"


if y == world_size_y - 1:
chunk_output += '{' + modelname.upper() + ', 0, ' + modelname + '}\n'
else:
Expand Down Expand Up @@ -538,26 +550,31 @@ def export_chunks(self, context, lod, max_triangles):
chunk_output = triangle_output + chunk_output + '};'


return chunk_output
return decl_output, chunk_output



def generate_textures(self):

texture_count = len(self.textures)
var_decl = f'struct texture chunk_texture_list[{texture_count}]'

textures_decl = f'extern {var_decl};'

#if there are no textures to be added, exit
if (len(self.texture_list) == 0):
#print('no textures to be added')
return 'struct texture chunk_texture_list[0] = {};'
return textures_decl, f'{var_decl} = {{}};'


texture_count = len(self.textures)
self.texture_list = 'struct texture chunk_texture_list[' + str(texture_count) + '] = {' + self.texture_list + '};'

self.texture_list = f'{var_decl} = {{' + self.texture_list + '};'

#print(self.texture_data)
#print(self.texture_list)

output = self.texture_data + self.texture_list

return output
return textures_decl, output



Expand All @@ -568,8 +585,10 @@ def generate_lights(self, context):

fixed_point_factor = context.scene.fixed_point_factor

lights = ''
chunk_lights = 'const struct chunk_lighting chunk_lights[' + str(world_size_x) + '][' + str(world_size_y) + '] = {'
var_decl = f'const struct chunk_lighting chunk_lights[{world_size_x}][{world_size_y}]'

decl_output = f'extern {var_decl};\n'
chunk_lights = f'{var_decl} = {{'

chunk_light_data = ''

Expand Down Expand Up @@ -628,7 +647,7 @@ def generate_lights(self, context):
output = chunk_light_data + chunk_lights
#print(chunk_light_data)
#print(chunk_lights)
return output
return decl_output, output



Expand Down
57 changes: 57 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,77 @@ project(pico32 C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

option(GAMESCOM "Build gamescom version" OFF)

# Initialize the Pico SDK
pico_sdk_init()

# Find the PicoSystem SDK
find_package(PICOSYSTEM REQUIRED)

set(GLOBAL_DEFINES)

if(GAMESCOM)
list(APPEND GLOBAL_DEFINES GAMESCOM) #enables tweaks for a gamescom version with peace loving balloons instead of zombies
set(ZOMBIE_SOURCES
game/gamescom/logic_balloon.cpp
game/gamescom/logic_shoot_balloon.cpp
)
else()
set(ZOMBIE_SOURCES
game/logic_shoot.cpp
game/logic_zombies.cpp
)
endif()

#Comment out/in defines if needed (for debugging)
#list(APPEND GLOBAL_DEFINES SKIP_START) #skips the starting splash/menu and goes straight into normal gameplay (menu = 0)
#list(APPEND GLOBAL_DEFINES FREE_ROAM) #set to ignore chunk physics for player
#list(APPEND GLOBAL_DEFINES DEBUG_SHADERS) #debug shaders are those with shader_id >= 250
#list(APPEND GLOBAL_DEFINES NO_GLOBAL_OFFSET) #disables using a global offset to move triangles and camera closer to origin

#Defines for performance profiling
#list(APPEND GLOBAL_DEFINES DEBUG_INFO) #adds information on core times and triangle counts in the main menu
#list(APPEND GLOBAL_DEFINES NO_NPCS) #disable all npcs including Zombies
#list(APPEND GLOBAL_DEFINES RASTERIZER_IN_FLASH) #puts the render_rasterize function for core 1 into flash instead of scratch RAM
#list(APPEND GLOBAL_DEFINES FRAME_COUNTER) #tallies frametimes for performance analysis
#list(APPEND GLOBAL_DEFINES CONTENTION_COUNTER) #enables counters for RAM contention on the 4 main banks
#list(APPEND GLOBAL_DEFINES CPU_LED_LOAD) #CPU load on LED (Core1: Green-40fps, Yellow-20fps, Red-10fps), blue if core 0 overloaded (logic too slow)
#list(APPEND GLOBAL_DEFINES BENCHMARK) #starts a benchmark recording average frametime and rough fps counter (takes 3 minutes!)

picosystem_executable(
pico3d
main.cpp
chunk_data.cpp

engine/render_camera.cpp
engine/render_chunk.cpp
engine/render_clipping.cpp
engine/render_culling.cpp
engine/render_lighting.cpp
engine/render_model.cpp
engine/render_rasterize.cpp
engine/render_triangle.cpp

game/logic_day_night_cycle.cpp
game/logic_demo.cpp
game/logic_events.cpp
game/logic_gate.cpp
game/logic_grass.cpp
game/logic_info_text.cpp
game/logic_input.cpp
game/logic_menu.cpp
game/logic_npc.cpp
game/logic_physics.cpp
game/logic_quest_npcs.cpp
game/logic_random.cpp
${ZOMBIE_SOURCES}
)


pixel_double(pico3d)
disable_startup_logo(pico3d)
no_spritesheet(pico3d)
target_compile_definitions(pico3d PUBLIC ${GLOBAL_DEFINES})
target_compile_definitions(pico3d PUBLIC PICO_DIVIDER_IN_RAM=1)
target_link_libraries(pico3d pico_multicore)
Loading

0 comments on commit e769860

Please sign in to comment.