Removed unneeded pool data structures

This commit is contained in:
Synthasmagoria 2026-07-30 22:56:27 +02:00
commit 7949c1ca5d
4 changed files with 45 additions and 108 deletions

View file

@ -1,44 +0,0 @@
package main
import "libraries/fixed_pool"
Field :: struct($T: typeid) {
value: f32,
input: FieldInput,
}
FIELD_BYTE_COUNT :: 32
FieldInput :: [FIELD_BYTE_COUNT]byte
FieldPool :: struct($T: typeid) {
values: fixed_pool.Pool(T),
inputs: fixed_pool.Pool(FieldInput),
}
field_input_as_cstring :: proc(field_input: ^FieldInput) -> cstring {
return cstring(&field_input[0])
}
field_pool_get :: proc(pool: ^FieldPool($T), count: int) -> (values: []T, inputs: []FieldInput) {
return fixed_pool.get(&pool.values, count), fixed_pool.get(&pool.inputs, count)
}
field_pool_clear :: proc(pool: ^FieldPool($T)) {
fixed_pool.clear(&pool.values)
fixed_pool.clear(&pool.inputs)
}
field_pool_init :: proc(pool: ^FieldPool($T), capacity: int, allocator := context.allocator) {
fixed_pool.init(&pool.values, capacity, allocator)
fixed_pool.init(&pool.inputs, capacity, allocator)
}
field_pool_free_range :: proc(pool: ^FieldPool($T), from: int, count: int) {
fixed_pool.free_range(&pool.values, from, count)
fixed_pool.free_range(&pool.inputs, from, count)
}
field_pool_get_allocated_elems :: proc(pool: ^FieldPool($T)) -> #soa[]Field(T) {
values := fixed_pool.get_allocated_elems(pool.values)
fields := fixed_pool.get_allocated_elems(pool.inputs)
return soa_zip(value = values, input = fields)
}

View file

@ -1,50 +0,0 @@
package adb_pool
Pool :: struct($T: typeid) {
pool: []T,
usage: int,
}
init :: proc(pool: ^Pool($T), capacity: int, allocator := context.allocator) {
pool.pool = make([]T, capacity, allocator)
pool.usage = 0
}
elems_available :: proc(pool: ^Pool($T), capacity: int) -> bool {
return pool.usage + count <= pool.capacity
}
capacity :: proc(pool: Pool($T)) -> int {
return len(pool.pool)
}
get :: proc(pool: ^Pool($T), count: int) -> []T {
range_to := pool.usage + count
assert(range_to <= len(pool.pool), "pool.get count reaches outside preallocated size")
elements := pool.pool[pool.usage:]
pool.usage += count
return elements
}
usage :: proc(pool: Pool($T)) -> int {
return pool.usage
}
get_allocated_elements :: proc(pool: Pool($T)) -> []T {
return pool.pool[:pool.usage]
}
clear :: proc(pool: ^Pool($T)) {
pool.usage = 0
}
free_range :: proc(pool: ^Pool($T), from, count: int) {
assert(count > 0, "Cannot free zero or negative count")
to := from + count
assert(to < pool.usage, "Cannot free beyond usage")
mem.copy(&pool.pool[from], &pool.pool[to], (pool.usage - to) * size_of(T))
}
raw_data :: proc(pool: ^Pool) -> rawptr {
return raw_data(pool.pool)
}

View file

@ -280,6 +280,7 @@ foreign lib {
GuiDropdownBox :: proc(bounds: Rectangle, text: cstring, active: ^c.int, editMode: bool) -> bool --- // Dropdown Box control, returns selected item
GuiSpinner :: proc(bounds: Rectangle, text: cstring, value: ^c.int, minValue, maxValue: c.int, editMode: bool) -> c.int --- // Spinner control, returns selected value
GuiValueBox :: proc(bounds: Rectangle, text: cstring, value: ^c.int, minValue, maxValue: c.int, editMode: bool) -> c.int --- // Value Box control, updates input text with numbers
GuiValueBoxFloat :: proc(bounds: Rectangle, text: cstring, text_value: cstring, value: ^c.float, editMode: bool) -> c.int --- // Value box control for float values
GuiTextBox :: proc(bounds: Rectangle, text: cstring, textSize: c.int, editMode: bool) -> bool --- // Text Box control, updates input text
GuiSlider :: proc(bounds: Rectangle, textLeft: cstring, textRight: cstring, value: ^f32, minValue: f32, maxValue: f32) -> c.int --- // Slider control, returns selected value

View file

@ -2,7 +2,6 @@ package main
import rl "libraries/raylib"
import ui "libraries/snths_ui"
import "libraries/fixed_pool"
import "core:fmt"
FontStyle :: struct {
@ -30,9 +29,17 @@ program_set_message_state :: proc(program: ^Program, message: ProgramMessageType
program: Program
InputFloatField :: [32]byte
MATRIX_POOL_SIZE :: 4096
input_float_field_as_cstring :: proc(field: ^InputFloatField) -> cstring {
return cstring(&field[0])
}
Program :: struct {
ui_context: ui.Context,
matrix_field_pool: FieldPool(f32),
matrix_float_pool: []f32,
matrix_value_string_pool: []InputFloatField,
matrix_count: int,
grid: Grid,
font_style: FontStyle,
@ -46,8 +53,20 @@ Grid :: struct {
zoom: f32,
}
matrix_pool_max :: proc() -> int {
return len(program.matrix_float_pool) / 9
}
matrix_pool_get_mat3 :: proc() -> ^mat3 {
assert(program.matrix_count + 1 < matrix_pool_max(), "Max matrix count exceeded")
mat := cast(^mat3)&program.matrix_float_pool[program.matrix_count * 9]
program.matrix_count += 1
return mat
}
program_init :: proc(allocator := context.allocator) {
field_pool_init(&program.matrix_field_pool, 4096, allocator)
program.matrix_float_pool = make(type_of(program.matrix_float_pool), MATRIX_POOL_SIZE)
program.matrix_value_string_pool = make(type_of(program.matrix_value_string_pool), MATRIX_POOL_SIZE)
program.font_style = {
font = rl.GetFontDefault(),
size = 16.0,
@ -62,8 +81,14 @@ program_init :: proc(allocator := context.allocator) {
}
program_update :: proc() {
if rl.IsKeyPressed(.ENTER) {
matrix_pool_get_mat3()
}
ui_elements := program_build_ui()
program_render_ui(ui_elements)
if rl.IsKeyPressed(.TAB) {
ui.focus_next_element(&program.ui_context)
}
program_render_ui(&program.ui_context, ui_elements)
}
program_build_ui :: proc() -> []ui.Element {
@ -90,30 +115,34 @@ program_build_ui :: proc() -> []ui.Element {
ui.container_begin({ui.Size_Percentage(0.2), ui.Size_PercentageRemainder(1.0)}, container_config)
for i in 0..<program.matrix_count {
container_config := ui.ElementConfiguration{margin = V2_ONE * 4.0, label = fmt.ctprintf("Matrix %d", i)}
container_dimensions := ui.Dimensions {ui.SIZE_AUTO, ui.SIZE_AUTO}
mat := cast(^mat3)&program.matrix_field_pool.values.pool[i * 9]
value_strings := program.matrix_field_pool.inputs.pool[i * 9 : i * 9 + 9]
container_dimensions := ui.Dimensions {ui.Size_Percentage(1.0), ui.Size_Pixels(112.0)}
mat := cast(^mat3)&program.matrix_float_pool[i * 9]
value_strings := program.matrix_value_string_pool[i * 9 : i * 9 + 9]
ui_mat3(mat, value_strings, container_dimensions, container_config)
}
ui.container_end()
return ui.end()
}
ui_mat3 :: proc(mat: ^mat3, value_strings: []FieldInput, dimensions: ui.Dimensions, config: ui.ElementConfiguration) {
ui_mat3 :: proc(mat: ^mat3, value_strings: []InputFloatField, dimensions: ui.Dimensions, config: ui.ElementConfiguration) {
ui.container_begin(dimensions, config)
matrix_input_config := ui.ElementConfiguration {margin = V2_ONE * 4.0}
matrix_input_dimensions := ui.Dimensions {ui.Size_Percentage(1.0 / 3.0), ui.Size_Percentage(1.0 / 3.0)}
#unroll for i in 0..<3 {
ui.input_float(matrix_input_dimensions, matrix_input_config, {value = &mat[i, 0], value_string = field_input_as_cstring(&value_strings[i * 3 + 0])})
data: ui.ElementData_FloatInput
data = {value = &mat[i, 0], value_string = input_float_field_as_cstring(&value_strings[i * 3 + 0])}
ui.input_float(matrix_input_dimensions, matrix_input_config, data)
ui.same_line()
ui.input_float(matrix_input_dimensions, matrix_input_config, {value = &mat[i, 1], value_string = field_input_as_cstring(&value_strings[i * 3 + 1])})
data = {value = &mat[i, 1], value_string = input_float_field_as_cstring(&value_strings[i * 3 + 1])}
ui.input_float(matrix_input_dimensions, matrix_input_config, data)
ui.same_line()
ui.input_float(matrix_input_dimensions, matrix_input_config, {value = &mat[i, 2], value_string = field_input_as_cstring(&value_strings[i * 3 + 2])})
data = {value = &mat[i, 2], value_string = input_float_field_as_cstring(&value_strings[i * 3 + 2])}
ui.input_float(matrix_input_dimensions, matrix_input_config, data)
}
ui.container_end()
}
program_render_ui :: proc(elements: []ui.Element) {
program_render_ui :: proc(ctx: ^ui.Context, elements: []ui.Element) {
for element in elements {
area := rl.Rectangle(element.area)
switch element.type {
@ -126,8 +155,9 @@ program_render_ui :: proc(elements: []ui.Element) {
rl.GuiSlider(area, element.label, "", data.value, data.min, data.max)
case .InputFloat:
data := element.data
str: cstring = " "
rl.GuiTextBox(area, str, i32(len(str) - 1), false)
if rl.GuiValueBoxFloat(area, element.label, data.value_string, data.value, ui.is_element_focused(ctx, element)) == 1 {
ui.focus_element(ctx, element)
}
}
}
}