Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Most of my changes #2

Merged
merged 28 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c61d763
Move the debugging defines to CMake/global
Daft-Freak Aug 1, 2023
81c98c9
Avoid defining variables in logic_globals.h
Daft-Freak Aug 1, 2023
1188fee
Avoid defining variables in render_globals.h
Daft-Freak Aug 1, 2023
3389e71
Delete some dead code from render_math, make the rest inline
Daft-Freak Aug 1, 2023
5db6da2
Avoid defining variables in chunk_globals.h
Daft-Freak Aug 1, 2023
06d70d3
Make GAMESCOM define an option
Daft-Freak Aug 1, 2023
442fa82
Avoid including all the game sources in main.cpp
Daft-Freak Aug 1, 2023
f6ea4a0
Output header+source file from exporter
Daft-Freak Aug 2, 2023
44b7972
Regen chunk_data
Daft-Freak Aug 2, 2023
6578328
Avoid including all the engine sources in main.cpp
Daft-Freak Aug 2, 2023
1868228
Remove fb global
Daft-Freak Aug 3, 2023
68e0337
Move multicore bits out of render_rasterize
Daft-Freak Aug 3, 2023
06690ce
Move sync code to main
Daft-Freak Aug 3, 2023
6d0b2f4
Remove picosystem sdk include in render_math.h
Daft-Freak Aug 3, 2023
c0eb0f8
Pull some frambuffer bits out of render_rasterize
Daft-Freak Aug 3, 2023
a3edc79
HACK: comment out render_math mat_debug funcs
Daft-Freak Aug 3, 2023
3953f79
Avoid picosystem sdk include in render_globals.h
Daft-Freak Aug 3, 2023
958a487
Pull timing out of render_rasterize and remove picosystem include
Daft-Freak Aug 3, 2023
efdadbb
Move collision detection out of render_camera
Daft-Freak Aug 3, 2023
4eea148
Move chunk "physics" out of engine
Daft-Freak Aug 3, 2023
a0fe36a
Remove player_area check from render_lighting
Daft-Freak Aug 3, 2023
ece6423
Remove daylight decl and make it static
Daft-Freak Aug 4, 2023
ff79528
Fix atan narrowing
Daft-Freak Aug 4, 2023
4a706c2
Use alignas for zbuffer
Daft-Freak Aug 4, 2023
db284c8
drop triangles with z=0
Daft-Freak Aug 5, 2023
0c17f73
Early out if triangle has 0 area
Daft-Freak Aug 5, 2023
814f4d5
Early out if w == 0 in culling code
Daft-Freak Aug 5, 2023
51717ea
Avoid a divide in rasterise
Daft-Freak Aug 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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