added raspi to build

This commit is contained in:
Peter Slattery 2022-05-13 04:45:40 -07:00
parent 6edb2a6d56
commit 1e04ec5bae
17 changed files with 749 additions and 99 deletions

View File

@ -1,3 +1,3 @@
SCRIPT_REL_DIR=$(dirname "${BASH_SOURCE[0]}") SCRIPT_REL_DIR=$(dirname "${BASH_SOURCE[0]}")
$SCRIPT_REL_DIR/build_.sh debug osx arm64 $SCRIPT_REL_DIR/build_.sh debug raspi arm64
# $SCRIPT_REL_DIR/build_.sh debug wasm intel # $SCRIPT_REL_DIR/build_.sh debug wasm intel

View File

@ -16,6 +16,7 @@ print_usage () {
echo " win32" echo " win32"
echo " osx" echo " osx"
echo " wasm" echo " wasm"
echo " raspi"
echo echo
echo "Arch Options: (architecture)" echo "Arch Options: (architecture)"
echo " intel (valid with Platform Win32 and OSX) (default)" echo " intel (valid with Platform Win32 and OSX) (default)"
@ -84,6 +85,7 @@ popdir
Compiler_win32="cl" Compiler_win32="cl"
Compiler_osx="clang" Compiler_osx="clang"
Compiler_raspi="clang"
WasiSdk="/c/drive/apps/wasi-sdk" WasiSdk="/c/drive/apps/wasi-sdk"
Compiler_wasm="$WasiSdk/bin/clang++" Compiler_wasm="$WasiSdk/bin/clang++"
Compiler_linux="clang++" Compiler_linux="clang++"
@ -94,6 +96,7 @@ PlatformEntry_win32="src_v2/platform/win32/lumenarium_first_win32.cpp"
PlatformEntry_osx="src_v2/platform/osx/lumenarium_first_osx.c" PlatformEntry_osx="src_v2/platform/osx/lumenarium_first_osx.c"
PlatformEntry_wasm="src_v2/platform/wasm/lumenarium_first_wasm.cpp" PlatformEntry_wasm="src_v2/platform/wasm/lumenarium_first_wasm.cpp"
PlatformEntry_linux="src_v2/platform/linux/lumenarium_first_linux.cpp" PlatformEntry_linux="src_v2/platform/linux/lumenarium_first_linux.cpp"
PlatformEntry_raspi="src_v2/platform/raspi/lumenarium_first_raspi.c"
# Intermediate Outputs # Intermediate Outputs
@ -101,6 +104,7 @@ CompilerOutput_win32="lumenarium.o"
CompilerOutput_osx="lumenarium" CompilerOutput_osx="lumenarium"
CompilerOutput_wasm="lumenarium.wasm" CompilerOutput_wasm="lumenarium.wasm"
CompilerOutput_linux="" CompilerOutput_linux=""
CompilerOutput_raspi="lumenarium"
# Executables # Executables
@ -108,6 +112,7 @@ LinkerOutput_win32="lumenarium.exe"
LinkerOutput_osx="lumenarium" LinkerOutput_osx="lumenarium"
LinkerOutput_wasm="lumenarium.wasm" LinkerOutput_wasm="lumenarium.wasm"
LinkerOutput_linux="" LinkerOutput_linux=""
LinkerOutput_raspi="lumenarium"
# Wasm Sys Root # Wasm Sys Root
WasmSysRoot="${PROJECT_PATH}/src_v2/platform/wasm/sysroot/" WasmSysRoot="${PROJECT_PATH}/src_v2/platform/wasm/sysroot/"
@ -140,6 +145,9 @@ CompilerFlags_wasm+=" -Wl,--export-all" #
CompilerFlags_linux="" CompilerFlags_linux=""
CompilerFlags_raspi="--target=arm-linux-gnueabihf" #target
CompilerFlags_DEBUG_win32="" CompilerFlags_DEBUG_win32=""
CompilerFlags_DEBUG_win32+=" -Od" # CompilerFlags_DEBUG_win32+=" -Od" #
CompilerFlags_DEBUG_win32+=" -Zi" # CompilerFlags_DEBUG_win32+=" -Zi" #
@ -172,6 +180,7 @@ LinkerFlags_wasm+=" --export-dynamic" #
LinkerFlags_wasm+=" --unresolved-symbols=import-functions" # LinkerFlags_wasm+=" --unresolved-symbols=import-functions" #
LinkerFlags_linux="" LinkerFlags_linux=""
LinkerFlags_raspi="-fuse-ld=lld"
LinkerFlags_DEBUG="-debug" LinkerFlags_DEBUG="-debug"
LinkerFlags_PROD="" LinkerFlags_PROD=""
@ -184,6 +193,7 @@ LinkerLibs_win32="user32.lib kernel32.lib gdi32.lib opengl32.lib"
LinkerLibs_osx="-framework OpenGL -framework Cocoa -framework IOKit ${PROJECT_PATH}/src_v2/libs/glfw_osx/lib-universal/libglfw3.a" LinkerLibs_osx="-framework OpenGL -framework Cocoa -framework IOKit ${PROJECT_PATH}/src_v2/libs/glfw_osx/lib-universal/libglfw3.a"
LinkerLibs_wasm="" LinkerLibs_wasm=""
LinkerLibs_linux="" LinkerLibs_linux=""
LinkerLibs_raspi=""
# -------------------------------------------- # --------------------------------------------
# Varible Selection # Varible Selection
@ -241,6 +251,15 @@ then
LinkerFlags=$LinkerFlags_linux LinkerFlags=$LinkerFlags_linux
LinkerLibs=$LinkerLibs_linux LinkerLibs=$LinkerLibs_linux
elif [ "${PLATFORM}" == "raspi" ]
then
Compiler=$Compiler_raspi
PlatformEntry=$PlatformEntry_raspi
CompilerFlags=$CompilerFlags_raspi
CompilerOutput=$CompilerOutput_raspi
LinkerOutput=$LinkerOutput_raspi
LinkerFlags=$LinkerFlags_raspi
LinkerLibs=$LinkerLibs_raspi
else else
echo "Attempting to build for an unknown platform: ${PLATFORM}" echo "Attempting to build for an unknown platform: ${PLATFORM}"
print_usage print_usage

Binary file not shown.

View File

@ -96,10 +96,26 @@ typedef double r64;
# define min(a,b) ((a) > (b) ? (b) : (a)) # define min(a,b) ((a) > (b) ? (b) : (a))
#endif #endif
#define lerp(a,t,b) (a) + ((1.0f - (t)) * (b)) #define lerp(a,t,b) (a) + ((b - a) * (t))
#define clamp(r0,v,r1) min((r1),max((r0),(v))) #define clamp(r0,v,r1) min((r1),max((r0),(v)))
#define lerp_clamp(a,t,b) clamp((a),lerp((a),(t),(b)),(b)) #define lerp_clamp(a,t,b) clamp((a),lerp((a),(t),(b)),(b))
internal r32
remap_r32(r32 v, r32 old_min, r32 old_max, r32 new_min, r32 new_max)
{
r32 result = (v - old_min) / (old_max - old_min);
result = (result * (new_max - new_min)) + new_min;
return result;
}
internal r64
remap_r64(r64 v, r64 old_min, r64 old_max, r64 new_min, r64 new_max)
{
r64 result = (v - old_min) / (old_max - old_min);
result = (result * (new_max - new_min)) + new_min;
return result;
}
internal u32 internal u32
round_up_to_pow2_u32(u32 v) round_up_to_pow2_u32(u32 v)
{ {

View File

@ -3,7 +3,7 @@ internal void
edr_render_begin(App_State* state) edr_render_begin(App_State* state)
{ {
Graphics_Frame_Desc desc = {}; Graphics_Frame_Desc desc = {};
desc.clear_color = (v4){ 0.1f, 0.1f, 0.1f, 1 }; desc.clear_color = (v4){ 0.0f, 0.0f, 0.0f, 1 };
desc.viewport_min = (v2){ 0, 0 }; desc.viewport_min = (v2){ 0, 0 };
v2 wd = state->editor->window_dim; v2 wd = state->editor->window_dim;
v2 cs = state->editor->content_scale; v2 cs = state->editor->content_scale;

View File

@ -112,11 +112,11 @@ ed_sculpture_visualizer(App_State* state)
// TODO(PS): TEMPORARY CAMERA CODE // TODO(PS): TEMPORARY CAMERA CODE
cam_theta += 0.01f; cam_theta += 0.01f;
r32 cam_r = 50; r32 cam_r = 50;
//v3 camera_pos = (v3){sinf(cam_theta) * cam_r, 25, cosf(cam_theta) * cam_r};
v3 camera_pos = (v3){ 0, -4.9, -cam_r }; v3 camera_pos = (v3){ 0, -4.9, -cam_r };
//camera_pos = (v3){sinf(cam_theta) * cam_r, -4.9f, cosf(cam_theta) * cam_r};
r32 aspect = view_dim.x / view_dim.y; r32 aspect = view_dim.x / view_dim.y;
m44 proj = HMM_Perspective(72.0, aspect, 0.01f, 500); m44 proj = HMM_Perspective(72.0, aspect, 0.01f, 500);
m44 view = HMM_LookAt(camera_pos, (v3){0,0,0}, (v3){0,1,0}); m44 view = HMM_LookAt(camera_pos, (v3){0,2,0}, (v3){0,1,0});
shader_bind(ed->sculpture_shd); shader_bind(ed->sculpture_shd);
set_uniform(ed->sculpture_shd, 0, HMM_MultiplyMat4(proj, view)); set_uniform(ed->sculpture_shd, 0, HMM_MultiplyMat4(proj, view));

View File

@ -22,91 +22,7 @@ en_frame_prepare(App_State* state)
global r32 tt = 0; global r32 tt = 0;
r32 #include "../user_space/incenter_patterns.c"
curve_ease_in_out(r32 t)
{
r32 tc = clamp(0, t, 1);
r32 theta = (tc * r32_pi) - (r32_pi / 2.0f);
r32 s = sinf(theta);
r32 result = 0.5f + (s / 2.0f);
return result;
}
#define incenter_pos_to_unit(p) (v4){ ((p.x / 6.0f) + 0.5f), ((p.y / 6.0f) + 0.5f), ((p.z / 6.0f) + 0.5f), 1.0f }
void
test_pattern(Assembly_Pixel_Buffer pixels)
{
for (u32 j = 0; j < pixels.len; j++)
{
v4 p = pixels.positions[j];
pixels.pixels[j].r = (u8)(((sinf((5 * tt) + (p.x * 10)) + 1) * 0.5f) * 255);
pixels.pixels[j].b = (u8)(((sinf((5 * tt) + (p.z * 10)) + 1) * 0.5f) * 255);
}
}
void
pattern_debug(Assembly_Pixel_Buffer pixels)
{
r32 scale = 6;
r32 offset = 0;
for (u32 j = 0; j < pixels.len; j++)
{
v4 p = pixels.positions[j];
v4 pp = incenter_pos_to_unit(p);
pixels.pixels[j].r = pp.x * 255;
pixels.pixels[j].g = pp.y * 255;
pixels.pixels[j].b = pp.z * 255;
}
}
void
grow_pattern_sphere_function(Assembly_Pixel_Buffer pixels, v4 center, r32 radius, r32 falloff)
{
for (u32 j = 0; j < pixels.len; j++)
{
v4 p = incenter_pos_to_unit(pixels.positions[j]);
r32 d0 = HMM_LengthVec4(HMM_SubtractVec4(p, center));
r32 d1 = falloff - fabsf(d0 - radius);
r32 b = d1 / falloff;
v3 color = {
.x = 0.5f + 0.5f * sinf(p.x * r32_tau * 4.313f + tt * 0.53f),
.y = 0.5f + 0.5f * cosf(0.2314f + p.y * r32_tau * 3.915f + tt * 0.5f),
.z = 0.2f + 0.8f * p.z,
};
v3 color_b = HMM_MultiplyVec3f(color, b);
pixels.pixels[j].r = color_b.x * 255;
pixels.pixels[j].g = color_b.y * 255;
pixels.pixels[j].b = color_b.z * 255;
}
}
void
grow_pattern(Assembly_Pixel_Buffer pixels)
{
v4 center = (v4){};
r32 radius = 0;
r32 falloff = 0;
//phase 1 - light up to center
if (tt < 8)
{
r32 height = -0.2f + curve_ease_in_out(tt / 6) * 0.5f;
center = (v4){ 0.5f, 0.2f + height, 0.5f, 1 };
radius = 0.1f;
falloff = 0.2f;
}
else if (tt >= 8)
{
r32 t = (tt - 8) / 5;
center = (v4){ 0.5f, 0.5f, 0.5f, 1 };
radius = 0.1f + curve_ease_in_out(t) * 0.27f;
falloff = 0.2 - (curve_ease_in_out(t) * 0.1f);
}
grow_pattern_sphere_function(pixels, center, radius, falloff);
}
internal void internal void
en_frame(App_State* state) en_frame(App_State* state)
@ -127,7 +43,9 @@ en_frame(App_State* state)
for (u32 i = 0; i < assemblies.len; i++) for (u32 i = 0; i < assemblies.len; i++)
{ {
Assembly_Pixel_Buffer pixels = assemblies.pixel_buffers[i]; Assembly_Pixel_Buffer pixels = assemblies.pixel_buffers[i];
grow_pattern(pixels); //grow_pattern(pixels);
//pattern_color(pixels, 0, 0, 0);
pattern_demo(pixels);
} }
/////////////////////////////////////// ///////////////////////////////////////

View File

@ -15,6 +15,8 @@ global Allocator* global_scratch_; // gets reset at frame boundaries
#define scratch_release(ident) allocator_scratch_end(&ident) #define scratch_release(ident) allocator_scratch_end(&ident)
#include "lumenarium_bsp.h" #include "lumenarium_bsp.h"
#include "patterns/patterns_math.h"
// Engine // Engine
typedef struct Assembly_Strip Assembly_Strip; typedef struct Assembly_Strip Assembly_Strip;
typedef struct Assembly_Pixel_Buffer Assembly_Pixel_Buffer; typedef struct Assembly_Pixel_Buffer Assembly_Pixel_Buffer;

View File

@ -0,0 +1,222 @@
#ifndef PATTERNS_MATH_H
#define PATTERNS_MATH_H
r32 fractf(r32 v) { r64 int_part = 0; return (r32)modf((r64)v, &int_part); }
r32
pm_smoothstep_r32(r32 t)
{
r32 r = (t * t * (3 - (2 * t)));
return r;
}
r32
pm_smoothstep_range_r32(r32 t, r32 min, r32 max)
{
r32 tt = pm_smoothstep_r32(t);
r32 r = lerp(min, tt, max);
return r;
}
v3
pm_smoothstep_v3(v3 p)
{
v3 result = {
.x = pm_smoothstep_r32(p.x),
.y = pm_smoothstep_r32(p.y),
.z = pm_smoothstep_r32(p.z),
};
return result;
}
///// vector extensions
v2 pm_abs_v2(v2 v) { return (v2){ .x = fabsf(v.x), .y = fabsf(v.y) }; }
v3 pm_abs_v3(v3 v) { return (v3){ .x = fabsf(v.x), .y = fabsf(v.y), .z = fabsf(v.z) }; }
v4 pm_abs_v4(v4 v) { return (v4){ .x = fabsf(v.x), .y = fabsf(v.y), .z = fabsf(v.z), .w = fabsf(v.w) }; }
v2 pm_floor_v2(v2 v) { return (v2){ .x = floorf(v.x), .y = floorf(v.y) }; }
v3 pm_floor_v3(v3 v) { return (v3){ .x = floorf(v.x), .y = floorf(v.y), .z = floorf(v.z) }; }
v4 pm_floor_v4(v4 v) { return (v4){ .x = floorf(v.x), .y = floorf(v.y), .z = floorf(v.z), .w = floorf(v.w) }; }
v2 pm_fract_v2(v2 v) { return (v2){ .x = fractf(v.x), .y = fractf(v.y) }; }
v3 pm_fract_v3(v3 v) { return (v3){ .x = fractf(v.x), .y = fractf(v.y), .z = fractf(v.z) }; }
v4 pm_fract_v4(v4 v) { return (v4){ .x = fractf(v.x), .y = fractf(v.y), .z = fractf(v.z), .w = fractf(v.w) }; }
v2 pm_sin_v2(v2 v) { return (v2){ .x = sinf(v.x), .y = sinf(v.y) }; }
v3 pm_sin_v3(v3 v) { return (v3){ .x = sinf(v.x), .y = sinf(v.y), .z = sinf(v.z) }; }
v4 pm_sin_v4(v4 v) { return (v4){ .x = sinf(v.x), .y = sinf(v.y), .z = sinf(v.z), .w = sinf(v.w) }; }
v2 pm_cos_v2(v2 v) { return (v2){ .x = cosf(v.x), .y = cosf(v.y) }; }
v3 pm_cos_v3(v3 v) { return (v3){ .x = cosf(v.x), .y = cosf(v.y), .z = cosf(v.z) }; }
v4 pm_cos_v4(v4 v) { return (v4){ .x = cosf(v.x), .y = cosf(v.y), .z = cosf(v.z), .w = cosf(v.w) }; }
////// hash functions
r32
pm_hash_v2_to_r32(v2 p)
{
v2 r = HMM_MultiplyVec2f(p, 0.3183099f);
r = pm_fract_v2(r);
r = HMM_MultiplyVec2f(r, 50);
r32 result = fractf(r.x * r.y * (r.x + r.y));
return result;
}
r32
pm_hash_r32_to_r32(r32 n)
{
return fractf(n * 17 * fractf(n * 0.3183099f));
}
v2
pm_hash_r32_to_v2(r32 n)
{
v2 a = pm_sin_v2((v2){ n, n + 1.0f });
v2 b = HMM_MultiplyVec2(a, (v2){ 43758.5453123f, 22578.1459123f });
v2 r = pm_fract_v2(b);
return r;
}
v2
pm_hash_v2_to_v2(v2 p)
{
v2 k = (v2){ 0.3183099f, 0.3678794f };
v2 kp = (v2){k.y, k.x};
v2 r0 = HMM_MultiplyVec2(p, k);
v2 r1 = HMM_AddVec2(r0, kp);
r32 f = 16.0f * fractf(p.x * p.y * (p.x + p.y));
v2 r2 = HMM_MultiplyVec2f(k, f);
v2 r3 = pm_fract_v2(r2);
return r3;
}
v3
pm_hash_v2_to_v3(v2 p)
{
v3 q = (v3){
.x = HMM_DotVec2(p, (v2){127.1f, 311.7f}),
.y = HMM_DotVec2(p, (v2){267.5f, 183.3f}),
.z = HMM_DotVec2(p, (v2){419.2f, 371.9f})
};
v3 r0 = pm_sin_v3(q);
v3 r1 = HMM_MultiplyVec3f(r0, 43758.5453f);
v3 r2 = pm_fract_v3(r1);
return r2;
}
r32
pm_hash_v3_to_r32(v3 p)
{
v3 p0 = HMM_MultiplyVec3f(p, 0.3183099f);
v3 p1 = HMM_AddVec3(p0, (v3){ 0.1f, 0.1f, 0.1f });
v3 p2 = pm_fract_v3(p1);
v3 p3 = HMM_MultiplyVec3f(p, 17.0f);
r32 r0 = fractf(p3.x * p3.y * p3.z * (p3.x + p3.y + p3.z));
return r0;
}
r32
pm_random_v2_to_r32(v2 n)
{
v2 v = (v2){ 12.9898f, 4.1414f };
r32 r0 = HMM_DotVec2(n, v);
r32 r1 = sinf(r0);
r32 r2 = fractf(r1 * 43758.5453);
return r2;
}
internal r32
pm_noise_v3_to_r32(v3 p)
{
p = pm_abs_v3(p);
v3 p_fl = pm_floor_v3(p);
v3 p_fr = pm_fract_v3(p);
v3 f = pm_smoothstep_v3(p_fr);
v3 p_fl_0 = p_fl;
v3 p_fl_1 = HMM_AddVec3(p_fl, (v3){1, 0, 0});
v3 p_fl_2 = HMM_AddVec3(p_fl, (v3){0, 1, 0});
v3 p_fl_3 = HMM_AddVec3(p_fl, (v3){1, 1, 0});
v3 p_fl_4 = HMM_AddVec3(p_fl, (v3){0, 0, 1});
v3 p_fl_5 = HMM_AddVec3(p_fl, (v3){1, 0, 1});
v3 p_fl_6 = HMM_AddVec3(p_fl, (v3){0, 1, 1});
v3 p_fl_7 = HMM_AddVec3(p_fl, (v3){1, 1, 1});
r32 h0 = pm_hash_v3_to_r32(p_fl_0);
r32 h1 = pm_hash_v3_to_r32(p_fl_1);
r32 h2 = pm_hash_v3_to_r32(p_fl_2);
r32 h3 = pm_hash_v3_to_r32(p_fl_3);
r32 h4 = pm_hash_v3_to_r32(p_fl_4);
r32 h5 = pm_hash_v3_to_r32(p_fl_5);
r32 h6 = pm_hash_v3_to_r32(p_fl_6);
r32 h7 = pm_hash_v3_to_r32(p_fl_7);
r32 result = lerp(f.z,
lerp(
lerp(h0, f.x, h1),
f.y,
lerp(h2, f.x, h3)
),
lerp(
lerp(h4, f.x, h5),
f.y,
lerp(h6, f.x, h7)
)
);
assert(result >= 0 && result <= 1);
return result;
}
internal r32
pm_fmb_3d(v3 p, r32 t)
{
v3 ts = (v3){t, t, t};
r32 tsin = sinf(t);
v3 tv = (v3){tsin, tsin, tsin};
v3 pp = p;
r32 f = 0.0;
v3 pp0 = HMM_AddVec3(pp, ts);
v3 pp1 = HMM_SubtractVec3(pp, ts);
f += 0.500000f * pm_noise_v3_to_r32(pp0); pp = HMM_MultiplyVec3f(pp, 2.02);
f += 0.300000f * pm_noise_v3_to_r32(pp1); pp = HMM_MultiplyVec3f(pp, 2.03);
f += 0.125000f * pm_noise_v3_to_r32(pp); pp = HMM_MultiplyVec3f(pp, 2.01);
f += 0.062500f * pm_noise_v3_to_r32(pp0); pp = HMM_MultiplyVec3f(pp, 2.04);
r32 d = 0.9875f;
f = f / d;
return f;
}
// internal r32
// pm_voronoise(v2 p, r32 u, r32 v)
// {
// r32 k = 1.0f + 63.0f + powf(1.0f - v, 6.0f);
// v2 i = pm_floor_v2(p);
// v2 f = pm_fract_v2(p);
// v2 a = (v2){0, 0};
// for (s32 y = -2; y <= 2; y++)
// {
// for (s32 x = -2; x <= 2; x++)
// {
// v2 g = (v2){(r32)x, (r32)y};
// v2 hi = HMM_AddVec2(g, i);
// v3 h = pm_hash_v2_to_v3(hi);
// v3 o = HMM_MultiplyVec3(h, (v3){ u, u, 1.0f });
// v2 d0 = HMM_SubtractVec2(g, f);
// v2 d1 = HMM_AddVec2(d0, o.XY);
// r32 d1m = HMM_LengthVec2(d1);
// r32 w = powf(1.0f - pm_smoothstep_range_r32(d1m, 0.0f, 1.414f), k);
// a = HMM_AddVec2(a, (v2){o.z * w, w});
// }
// }
// return a.x / a.y;
// }
#endif // PATTERNS_MATH_H

View File

@ -0,0 +1,66 @@
#ifndef LUMENARIUM_LINUX_FILE_H
#define LUMENARIUM_LINUX_FILE_H 1
File_Async_Job_System
os_file_jobs_init()
{
}
File_Handle
os_file_open(String path, File_Access_Flags flags_access, File_Create_Flags flags_create)
{
invalid_code_path;
}
void
os_file_close(File_Handle file_handle)
{
invalid_code_path;
}
File_Info
os_file_get_info(File_Handle file_handle, Allocator* allocator)
{
invalid_code_path;
}
Data
os_file_read_all(File_Handle file_handle, Allocator* allocator)
{
invalid_code_path;
}
bool
os_file_write_all(File_Handle file_handle, Data file_data)
{
invalid_code_path;
}
String
os_get_exe_path(Allocator* allocator)
{
invalid_code_path;
}
bool
os_pwd_set(String path)
{
invalid_code_path;
}
File_Info_List
os_dir_enum(String path, Platform_Enum_Dir_Flags flags, Allocator* allocator)
{
invalid_code_path;
}
void
os_file_async_work_on_job(File_Async_Job* job)
{
}
#endif // LUMENARIUM_LINUX_FILE_H

View File

@ -0,0 +1,58 @@
#ifndef LUMENARIUM_LINUX_MEMORY_H
#define LUMENARIUM_LINUX_MEMORY_H 1
global u64 linux_page_size_cache_ = 0;
// https://stackoverflow.com/questions/3351940/detecting-the-memory-page-size
u64
os_page_size()
{
if (linux_page_size_cache_ == 0)
{
long page_size = sysconf(_SC_PAGE_SIZE);
linux_page_size_cache_ = (u64)page_size;
}
return linux_page_size_cache_;
}
size_t
linux_round_to_page_size(uint64_t size)
{
uint64_t rem = size % linux_page_size_cache_;
if (rem != 0 || size < linux_page_size_cache_)
{
uint64_t grow = linux_page_size_cache_ - rem;
size += grow;
}
return (size_t)size;
}
u8*
os_mem_reserve(u64 size)
{
size_t size_cvt = linux_round_to_page_size(size);
uint8_t* result = (uint8_t*)malloc(size_cvt);
return result;
}
u8*
os_mem_commit(u8* base, u64 size)
{
return base;
}
bool
os_mem_decommit(u8* base, u64 size)
{
return 1; // true
}
bool
os_mem_release(u8* base, u64 size)
{
free(base);
return 1; // true
}
#endif // LUMENARIUM_LINUX_MEMORY_H

View File

@ -0,0 +1,73 @@
#ifndef LUMENARIUM_LINUX_NETWORK_H
#define LUMENARIUM_LINUX_NETWORK_H 1
Socket_Handle
os_socket_create(s32 domain, s32 type, s32 protocol)
{
invalid_code_path;
return Socket_Handle{0};
}
bool
os_socket_bind()
{
invalid_code_path;
return false;
}
bool
os_socket_connect()
{
invalid_code_path;
return false;
}
bool
os_socket_close()
{
invalid_code_path;
return false;
}
Data
os_socket_recv()
{
invalid_code_path;
return Data{};
}
s32
os_socket_set_listening()
{
invalid_code_path;
return 0;
}
s32
os_socket_send()
{
invalid_code_path;
return 0;
}
s32
os_socket_send_to(Socket_Handle handle, u32 addr, u32 port, Data data, s32 flags)
{
invalid_code_path;
return 0;
}
s32
os_socket_set_opt(Socket_Handle handle, int level, int option_name, u8* option_value, s32 option_len)
{
invalid_code_path;
return 0;
}
void
open_sockets_init()
{
invalid_code_path;
}
#endif // LUMENARIUM_LINUX_NETWORK_H

View File

@ -0,0 +1,32 @@
#ifndef LUMENARIUM_RASPI_THREADS_H
#define LUMENARIUM_RASPI_THREADS_H 1
Thread_Handle
os_thread_begin(Thread_Proc* proc, u8* user_data)
{
invalid_code_path;
return Thread_Handle{0};
}
void
os_thread_end(Thread_Handle thread_handle)
{
invalid_code_path;
}
u32
os_interlocked_increment(volatile u32* value)
{
invalid_code_path;
return 0;
}
u32
os_interlocked_cmp_exchg(volatile u32* dest, u32 new_value, u32 old_value)
{
invalid_code_path;
return 0;
}
#endif // LUMENARIUM_RASPI_THREADS_H

View File

@ -0,0 +1,16 @@
#ifndef LUMENARIUM_LINUX_TIME_H
#define LUMENARIUM_LINUX_TIME_H 1
Ticks
os_get_ticks()
{
invalid_code_path;
}
r64
os_get_ticks_per_second()
{
invalid_code_path;
}
#endif // LUMENARIUM_LINUX_TIME_H

View File

@ -0,0 +1,11 @@
#if 0
# include "../linux/lumenarium_linux_memory.h"
#endif
#include <stdio.h>
int main (int arg_count, char** args)
{
printf("Hi there\n");
return 0;
}

View File

@ -0,0 +1,208 @@
r32
curve_ease_in_out(r32 t)
{
r32 tc = clamp(0, t, 1);
r32 theta = (tc * r32_pi) - (r32_pi / 2.0f);
r32 s = sinf(theta);
r32 result = 0.5f + (s / 2.0f);
return result;
}
#define incenter_pos_to_unit(p) (v4){ ((p.x / 6.0f) + 0.5f), ((p.y / 6.0f) + 0.5f), ((p.z / 6.0f) + 0.5f), 1.0f }
void
test_pattern(Assembly_Pixel_Buffer pixels)
{
for (u32 j = 0; j < pixels.len; j++)
{
v4 p = pixels.positions[j];
pixels.pixels[j].r = (u8)(((sinf((5 * tt) + (p.x * 10)) + 1) * 0.5f) * 255);
pixels.pixels[j].b = (u8)(((sinf((5 * tt) + (p.z * 10)) + 1) * 0.5f) * 255);
}
}
void
pattern_debug(Assembly_Pixel_Buffer pixels)
{
r32 scale = 6;
r32 offset = 0;
for (u32 j = 0; j < pixels.len; j++)
{
v4 p = pixels.positions[j];
v4 pp = incenter_pos_to_unit(p);
pixels.pixels[j].r = pp.x * 255;
pixels.pixels[j].g = pp.y * 255;
pixels.pixels[j].b = pp.z * 255;
}
}
Assembly_Pixel
color_v3_to_assembly_pixel(v3 c)
{
return (Assembly_Pixel){
.r = (u8)(c.x * 255),
.g = (u8)(c.y * 255),
.b = (u8)(c.z * 255),
};
}
u8
u8_add_safe(u8 a, u8 b)
{
u8 r = a + b;
if (r < a || r < b) r = 255;
return r;
}
Assembly_Pixel
assembly_pixel_add(Assembly_Pixel a, Assembly_Pixel b)
{
Assembly_Pixel result = {
.r = u8_add_safe(a.r, b.r),
.g = u8_add_safe(a.g, b.g),
.b = u8_add_safe(a.b, b.b),
};
return result;
}
void
sun_center(Assembly_Pixel_Buffer pixels, v4 center, r32 radius, r32 falloff)
{
for (u32 j = 0; j < pixels.len; j++)
{
v4 p = incenter_pos_to_unit(pixels.positions[j]);
r32 d0 = HMM_LengthVec4(HMM_SubtractVec4(p, center));
r32 d1 = falloff - fabsf(d0 - (radius + (0.02f * sinf(tt))));
r32 b = d1 / falloff;
if (b > 0)
{
v3 p0 = pixels.positions[j].xyz;
v3 p1 = HMM_AddVec3(p0, (v3){ tt, -tt, 0 });
v3 color = {
.x = remap_r32(pm_fmb_3d(p0, tt), 0, 1, 0.5, 1),
.y = remap_r32(pm_noise_v3_to_r32(p1), 0, 1, 0, 0.3f),
.z = 0,
};
Assembly_Pixel cc = color_v3_to_assembly_pixel(color);
v3 color_b = HMM_MultiplyVec3f(color, b);
Assembly_Pixel color_0 = color_v3_to_assembly_pixel(color_b);
Assembly_Pixel color_1 = assembly_pixel_add(color_0, pixels.pixels[j]);
pixels.pixels[j] = color_1;
}
}
}
void
grow_pattern_sphere_function(Assembly_Pixel_Buffer pixels, v4 center, r32 radius, r32 falloff)
{
for (u32 j = 0; j < pixels.len; j++)
{
v4 p = incenter_pos_to_unit(pixels.positions[j]);
r32 d0 = HMM_LengthVec4(HMM_SubtractVec4(p, center));
r32 d1 = falloff - fabsf(d0 - (radius + (0.02f * sinf(tt))));
r32 b = d1 / falloff;
v3 color = {
.x = 0.5f + 0.5f * sinf(p.x * r32_tau * 4.313f + tt * 1.3f),
.y = 0.5f + 0.5f * cosf(0.2314f + p.y * r32_tau * 3.915f + tt),
.z = 0.2f + 0.8f * p.z,
};
v3 color_b = HMM_MultiplyVec3f(color, b);
Assembly_Pixel color_0 = color_v3_to_assembly_pixel(color_b);
Assembly_Pixel color_1 = assembly_pixel_add(color_0, pixels.pixels[j]);
pixels.pixels[j] = color_1;
}
}
void
grow_pattern(Assembly_Pixel_Buffer pixels, r32 time)
{
v4 center = (v4){};
r32 radius = 0;
r32 falloff = 0;
//phase 1 - light up to center
if (time < 6)
{
r32 height = -0.2f + curve_ease_in_out(time / 4) * 0.5f;
center = (v4){ 0.5f, 0.2f + height, 0.5f, 1 };
radius = lerp(0.01f, (time / 6), 0.05f);
falloff = 0.1f;
}
else if (time >= 6)
{
r32 t = (time - 6) / 4;
center = (v4){ 0.5f, 0.5f, 0.5f, 1 };
radius = 0.05f + curve_ease_in_out(t) * 0.4f;
falloff = 0.1f - (curve_ease_in_out(t) * 0.05f);
}
grow_pattern_sphere_function(pixels, center, radius, falloff);
}
void
pattern_color(Assembly_Pixel_Buffer pixels, u8 r, u8 g, u8 b)
{
for (u32 j = 0; j < pixels.len; j++)
{
pixels.pixels[j].r = r;
pixels.pixels[j].g = g;
pixels.pixels[j].b = b;
}
}
void
pattern_blink(Assembly_Pixel_Buffer pixels)
{
r32 t0 = clamp(0, tt, 1.5f) / 1.5f;
r32 t1 = pm_smoothstep_r32(t0);
r32 t2 = t1 * 0.43f;
v4 center = (v4){
.x = 0.5f,
.y = t2,
.z = 0.5f,
.w = 1,
};
r32 o = remap_r32(sinf(tt), -1, 1, 0.0015f, 0.002f);
for (u32 i = 0; i < pixels.len; i++)
{
v4 p = incenter_pos_to_unit(pixels.positions[i]);
v2 ho = (v2){ .x = fabsf(p.x - 0.5f), .y = fabsf(p.z - 0.5f) };
r32 dh = HMM_LengthVec2(ho);
if (p.y < center.y && dh < 0.01f)
{
pixels.pixels[i].r = 0;
pixels.pixels[i].g = 128;
pixels.pixels[i].b = 255;
}
}
grow_pattern_sphere_function(pixels, center, o, 0.01f);
}
void
pattern_demo(Assembly_Pixel_Buffer pixels)
{
pattern_color(pixels, 255, 255, 255); // reset
return;
r32 sun_limit = 5;
if (tt < sun_limit)
{
r32 r = 0.1f;
if (tt > (sun_limit - 1))
{
r32 ttt = tt - (sun_limit - 1);
r = lerp(0.1f, ttt, 0.0f);
}
sun_center(pixels, (v4){0.5f, 0.5f, 0.5f, 1}, r, r);
}
pattern_blink(pixels);
r32 grow_delay = 2;
if (tt > grow_delay)
{
grow_pattern(pixels, tt - grow_delay);
}
}

View File

@ -31,29 +31,38 @@ incenter_init(App_State* state)
ah, ah,
vertical_strip, vertical_strip,
start_p, start_p,
(v3){0, INCENTER_FEET(-6.5f), 0}, (v3){0, INCENTER_FEET(-4.5f), 0},
123 123
); );
r32 radius = INCENTER_FEET(10); r32 radius = INCENTER_FEET(10);
Random_Series rand = random_series_create(hash_djb2_cstr_to_u32("slfalksdjf")); Random_Series rand = random_series_create(hash_djb2_cstr_to_u32("slfsaassdjf"));
for (u32 i = 0; i < 40; i++) u32 i = 0;
while (i < 40)
//for (u32 i = 0; i < 40; i++)
{ {
Assembly_Strip* strip = assembly_add_strip(&state->assemblies, ah, 123);
strip->output_kind = OutputData_NetworkSACN;
strip->sacn_universe = i;
r32 theta = random_series_next_unilateral(&rand) * r32_tau; r32 theta = random_series_next_unilateral(&rand) * r32_tau;
r32 phi = random_series_next_unilateral(&rand) * r32_tau; r32 phi = random_series_next_unilateral(&rand) * r32_tau;
// spherical to cartesian conversion // spherical to cartesian conversion
v3 end_p = { v3 end_p = {
radius * sinf(phi) * cosf(theta), radius * sinf(phi) * cosf(theta),
radius * sinf(phi) * sinf(theta), radius * sinf(phi) * sinf(theta),
radius * cosf(phi) radius * cosf(phi)
}; };
r32 down = HMM_DotVec3(HMM_NormalizeVec3(end_p), (v3){0, -1, 0});
if (down > 0.7f || down < -0.9f) continue;
Assembly_Strip* strip = assembly_add_strip(&state->assemblies, ah, 123);
strip->output_kind = OutputData_NetworkSACN;
strip->sacn_universe = i;
assembly_strip_create_leds(&state->assemblies, ah, strip, start_p, end_p, 123); assembly_strip_create_leds(&state->assemblies, ah, strip, start_p, end_p, 123);
i++;
} }
r32 rad = 0.05f; r32 rad = 0.05f;