Misc + made a more controlled digital zoom

Trying to get digital zoom to closer target levels that would match specific even font sizes

Various other changes from iterating on VEFontCache
This commit is contained in:
2024-06-29 22:36:22 -04:00
parent a9ddd7668f
commit 597c88c6b7
14 changed files with 4960 additions and 71 deletions

View File

@ -69,7 +69,7 @@ startup :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem
// Setup Persistent Slabs & String Cache
{
// alignment := uint(mem.DEFAULT_ALIGNMENT)
alignment := uint(16)
alignment := uint(64)
policy_ptr := & default_slab_policy
push( policy_ptr, SlabSizeClass { 128 * Kilobyte, 1 * Kilobyte, alignment })
@ -88,9 +88,9 @@ startup :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem
push( policy_ptr, SlabSizeClass { 16 * Megabyte, 16 * Megabyte, alignment })
push( policy_ptr, SlabSizeClass { 32 * Megabyte, 32 * Megabyte, alignment })
push( policy_ptr, SlabSizeClass { 64 * Megabyte, 64 * Megabyte, alignment })
// push( policy_ptr, SlabSizeClass { 128 * Megabyte, 128 * Megabyte, alignment })
// push( policy_ptr, SlabSizeClass { 256 * Megabyte, 256 * Megabyte, alignment })
// push( policy_ptr, SlabSizeClass { 512 * Megabyte, 512 * Megabyte, alignment })
push( policy_ptr, SlabSizeClass { 128 * Megabyte, 128 * Megabyte, alignment })
push( policy_ptr, SlabSizeClass { 256 * Megabyte, 256 * Megabyte, alignment })
push( policy_ptr, SlabSizeClass { 512 * Megabyte, 512 * Megabyte, alignment })
alloc_error : AllocatorError
persistent_slab, alloc_error = slab_init( policy_ptr, allocator = persistent_allocator(), dbg_name = Persistent_Slab_DBG_Name, enable_mem_tracking = false )
@ -137,11 +137,12 @@ startup :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem
resolution_height = 600
refresh_rate = 0
cam_min_zoom = 0.10
cam_min_zoom = 0.025
cam_max_zoom = 5.0
cam_zoom_mode = .Smooth
cam_zoom_mode = .Digital
cam_zoom_smooth_snappiness = 4.0
cam_zoom_sensitivity_digital = 0.05
cam_zoom_sensitivity_digital = 0.25
cam_zoom_scroll_delta_scale = 0.25
cam_zoom_sensitivity_smooth = 2.0
engine_refresh_hz = 0
@ -252,7 +253,10 @@ startup :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem
// Setup sokol_gp
{
desc := sokol_gp.Desc {}
desc := sokol_gp.Desc {
max_vertices = 2 * Mega + 640 * Kilo,
max_commands = 1 * Mega,
}
sokol_gp.setup(desc)
verify( cast(b32) sokol_gp.is_valid(), "Failed to setup sokol gp (graphics painter)" )
}
@ -329,7 +333,9 @@ startup :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem
}
// debug.path_lorem = str_fmt("C:/projects/SectrPrototype/examples/Lorem Ipsum (197).txt", allocator = persistent_slab_allocator())
debug.path_lorem = str_fmt("C:/projects/SectrPrototype/examples/Lorem Ipsum (1022).txt", allocator = persistent_slab_allocator())
// debug.path_lorem = str_fmt("C:/projects/SectrPrototype/examples/Lorem Ipsum (1022).txt", allocator = persistent_slab_allocator())
// debug.path_lorem = str_fmt("C:/projects/SectrPrototype/examples/sokol_gp.h", allocator = persistent_slab_allocator())
debug.path_lorem = str_fmt("C:/projects/SectrPrototype/examples/ve_fontcache.h", allocator = persistent_slab_allocator())
alloc_error : AllocatorError; success : bool
debug.lorem_content, success = os.read_entire_file( debug.path_lorem, persistent_slab_allocator() )
@ -502,8 +508,8 @@ tick_work_frame :: #force_inline proc( host_delta_time_ms : f64 ) -> b32
// rl.PollInputEvents()
debug.draw_ui_box_bounds_points = false
debug.draw_ui_padding_bounds = false
debug.draw_ui_content_bounds = false
debug.draw_ui_padding_bounds = false
debug.draw_ui_content_bounds = false
// config.engine_refresh_hz = 165

View File

@ -258,7 +258,7 @@ render_mode_screenspace :: proc( screen_extent : Extents2, screen_ui : ^UI_State
}
if true {
state.config.font_size_canvas_scalar = 2
state.config.font_size_canvas_scalar = 1.5
zoom_adjust_size := 16 * state.project.workspace.cam.zoom
over_sample := f32(state.config.font_size_canvas_scalar)
debug_text("font_size_canvas_scalar: %v", config.font_size_canvas_scalar)

View File

@ -153,6 +153,65 @@ update :: proc( delta_time : f64 ) -> b32
//region 2D Camera Manual Nav
// TODO(Ed): This should be per workspace view
{
Digial_Zoom_Snap_Levels := []f32{
0.025, // 0.4px (not practical for text, but allows extreme zoom out)
0.03125, // 0.5px
0.0375, // 0.6px
0.04375, // 0.7px
0.05, // 0.8px
0.05625, // 0.9px
0.0625, // 1px
0.075, // 1.2px
0.0875, // 1.4px
0.1, // 1.6px
0.1125, // 1.8px
0.125, // 2px (first practical font size)
0.15, //
0.20, //
0.25, // 4px
0.375, // 6px
0.5, // 8px
0.625, // 10px
0.75, // 12px
0.875, // 14px
1.0, // 16px (base size)
1.125, // 18px
1.25, // 20px
1.375, // 22px
1.5, // 24px
1.625, // 26px
1.75, // 28px
1.875, // 30px
2.0, // 32px
2.125, // 34px
2.25, // 36px
2.375, // 38px
2.5, // 40px
2.625, // 42px
2.75, // 44px
2.875, // 46px
3.0, // 48px
3.125, // 50px
3.25, // 52px
3.375, // 54px
3.5, // 56px
3.625, // 58px
3.75, // 60px
3.875, // 62px
4.0, // 64px
4.125, // 66px
4.25, // 68px
4.375, // 70px
4.5, // 72px
4.625, // 74px
4.75, // 76px
4.875, // 78px
5.0, // 80px
}
Min_Zoom := Digial_Zoom_Snap_Levels[ 0 ]
Max_zoom := Digial_Zoom_Snap_Levels[ len(Digial_Zoom_Snap_Levels) - 1 ]
// profile("Camera Manual Nav")
digital_move_speed : f32 = 1000.0
@ -160,11 +219,30 @@ update :: proc( delta_time : f64 ) -> b32
workspace.zoom_target = cam.zoom
}
// config.cam_max_zoom = 10
// config.cam_min_zoom = 0.05
// config.cam_zoom_sensitivity_digital = 0.05
// config.cam_zoom_sensitivity_smooth = 2.0
// config.cam_zoom_mode = .Smooth
binary_search_closest :: proc(arr: []f32, target: f32) -> int
{
low, high := 0, len(arr) - 1
for low <= high {
mid := (low + high) / 2
if arr[ mid ] == target do return mid
else if arr[ mid ] < target do low = mid + 1
else do high = mid - 1
}
if low == 0 do return 0
if low == len(arr) do return len(arr) - 1
if abs(arr[low-1] - target) < abs(arr[low] - target) {
return low - 1
}
return low
}
find_closest_zoom_index :: proc(zoom: f32, levels : []f32) -> int {
return clamp(binary_search_closest(levels, zoom), 0, len(levels) - 1)
}
switch config.cam_zoom_mode
{
case .Smooth:
@ -177,9 +255,26 @@ update :: proc( delta_time : f64 ) -> b32
cam.zoom += (workspace.zoom_target - cam.zoom) * lerp_factor * f32(delta_time)
cam.zoom = clamp(cam.zoom, config.cam_min_zoom, config.cam_max_zoom) // Ensure cam.zoom stays within bounds
case .Digital:
zoom_delta := clamp(input.mouse.scroll.y, -1, 1) * config.cam_zoom_sensitivity_digital
workspace.zoom_target = clamp(workspace.zoom_target + zoom_delta, config.cam_min_zoom, config.cam_max_zoom)
cam.zoom = workspace.zoom_target
zoom_delta := input.mouse.scroll.y
if zoom_delta != 0 {
current_index := find_closest_zoom_index(cam.zoom, Digial_Zoom_Snap_Levels)
scroll_speed := max(1, abs(zoom_delta) * config.cam_zoom_scroll_delta_scale) // Adjust this factor to control sensitivity
target_index := current_index
if zoom_delta > 0 {
target_index = min(len(Digial_Zoom_Snap_Levels) - 1, current_index + int(scroll_speed))
} else if zoom_delta < 0 {
target_index = max(0, current_index - int(scroll_speed))
}
if target_index != current_index {
workspace.zoom_target = Digial_Zoom_Snap_Levels[target_index]
}
}
// Smooth transition to target zoom
cam.zoom = lerp(cam.zoom, workspace.zoom_target, cast(f32) config.cam_zoom_sensitivity_digital)
}
move_velocity : Vec2 = {