gutter_runner/game/physics/shapes.odin

161 lines
4.0 KiB
Odin

package physics
//
// import "core:container/intrusive/list"
// import "game:container/spanpool"
// import "game:halfedge"
// import rl "vendor:raylib"
//
// Shape_Container :: struct {
// shapes: spanpool.Span_Pool(Shape_Instance),
// }
//
// destroy_shape_container :: proc(container: ^Shape_Container) {
// spanpool.destroy_spanpool(&container.shapes)
// }
//
// Shape_Handle :: distinct spanpool.Handle
//
// Shape_Sphere :: struct {
// radius: f32,
// }
//
// Shape_Convex :: struct {
// using mesh: halfedge.Half_Edge_Mesh,
// }
//
// box_to_convex :: proc(box: Shape_Box, allocator := context.allocator) -> (convex: Shape_Convex) {
// vertices := make([]rl.Vector3, 8, context.temp_allocator)
//
// for corner, i in BOX_CORNERS_NORM {
// vertices[i] = corner * box.size
// }
//
// convex.mesh = halfedge.mesh_from_vertex_index_list(vertices, box_indices[:], 4, allocator)
//
// return
// }
//
// Shape_Box :: struct {
// size: rl.Vector3,
// }
//
// Shape_Union :: struct {
// children: Shape_Handle,
// }
//
// Shape_Variant :: union {
// Shape_Sphere,
// Shape_Box,
// Shape_Union,
// }
//
// Shape_Instance :: struct {
// pos: rl.Vector3,
// rot: rl.Quaternion,
// shape: Shape_Variant,
// }
//
// Shape_Desc_Union :: struct {
// children: list.List,
// }
//
// Shape_Desc_Variant :: union {
// Shape_Desc_Union,
// Shape_Sphere,
// Shape_Box,
// }
//
// Shape_Desc :: struct {
// pos: rl.Vector3,
// rot: rl.Quaternion,
// shape: Shape_Desc_Variant,
// using link: list.Node,
// }
//
// shape_desc_add_child :: proc(
// desc: ^Shape_Desc,
// child: Shape_Desc,
// allocator := context.temp_allocator,
// ) {
// union_shape := desc.shape.(Shape_Desc_Union)
//
// allocated_child := new(Shape_Desc, allocator)
// allocated_child^ = child
//
// list.push_back(&union_shape.children, &allocated_child.link)
// }
//
// shape_container_add :: proc(
// c: ^Shape_Container,
// desc: Shape_Desc,
// loc := #caller_location,
// ) -> Shape_Handle {
// root_handle := spanpool.allocate_num(&c.shapes, 1)
// shape_container_add_internal(c, Shape_Handle(root_handle), 0, desc, loc = loc)
// return Shape_Handle(root_handle)
// }
//
// shape_container_free :: proc(c: ^Shape_Container, handle: Shape_Handle, loc := #caller_location) {
// assert(handle.len == 1)
//
// shape_container_free_internal(c, handle, 0, loc = loc)
// spanpool.free(&c.shapes, spanpool.Handle(handle), loc = loc)
// }
//
// shape_container_add_internal :: proc(
// c: ^Shape_Container,
// handle: Shape_Handle,
// idx: i32,
// desc: Shape_Desc,
// loc := #caller_location,
// ) {
// shape_ptr := &spanpool.resolve_slice(&c.shapes, spanpool.Handle(handle))[idx]
// switch s in desc.shape {
// case Shape_Sphere:
// shape_ptr.shape = s
// case Shape_Box:
// shape_ptr.shape = s
// case Shape_Desc_Union:
// child_len: i32
// {
// it := list.iterator_head(s.children, Shape_Desc, "link")
// for child in list.iterate_next(&it) {
// child_len += 1
// }
// }
// {
// children_handle := spanpool.allocate_num(&c.shapes, child_len)
// shape_ptr = &spanpool.resolve_slice(&c.shapes, spanpool.Handle(handle))[idx] // Re-resolve handle because spanpool might have reallocated
//
// shape_ptr.shape = Shape_Union {
// children = Shape_Handle(children_handle),
// }
//
// it := list.iterator_head(s.children, Shape_Desc, "link")
// i: i32
// for child in list.iterate_next(&it) {
// shape_container_add_internal(c, Shape_Handle(children_handle), i, child^)
// i += 1
// }
// }
// }
// }
//
// shape_container_free_internal :: proc(
// c: ^Shape_Container,
// handle: Shape_Handle,
// idx: i32,
// loc := #caller_location,
// ) {
// shape := spanpool.resolve_slice(&c.shapes, spanpool.Handle(handle))[idx]
// switch s in shape.shape {
// case Shape_Box, Shape_Sphere:
// // Nothing to do
// case Shape_Union:
// for i in 0 ..< s.children.len {
// shape_container_free_internal(c, s.children, i)
// }
// spanpool.free(&c.shapes, spanpool.Handle(s.children), loc = loc)
// }
// }