Fix bug in names where same string could get interned twice, some easy optimizations
This commit is contained in:
parent
5d9d321695
commit
56f1eb1d15
@ -68,13 +68,18 @@ from_string :: proc(str: string) -> Name {
|
|||||||
existing: Name
|
existing: Name
|
||||||
ok: bool
|
ok: bool
|
||||||
{
|
{
|
||||||
sync.atomic_rw_mutex_shared_guard(&global_container.lock)
|
sync.guard(&global_container.lock)
|
||||||
existing, ok = global_container.names_lookup[str]
|
existing, ok = global_container.names_lookup[str]
|
||||||
}
|
}
|
||||||
if ok {
|
if ok {
|
||||||
return existing
|
return existing
|
||||||
} else {
|
} else {
|
||||||
sync.atomic_rw_mutex_guard(&global_container.lock)
|
sync.guard(&global_container.lock)
|
||||||
|
|
||||||
|
existing, ok = global_container.names_lookup[str]
|
||||||
|
if ok {
|
||||||
|
return existing
|
||||||
|
}
|
||||||
|
|
||||||
new_str := strings.clone_to_cstring(
|
new_str := strings.clone_to_cstring(
|
||||||
str,
|
str,
|
||||||
@ -93,7 +98,7 @@ from_cstring :: proc(str: cstring) -> Name {
|
|||||||
|
|
||||||
to_string :: proc(name: Name) -> string {
|
to_string :: proc(name: Name) -> string {
|
||||||
tracy.Zone()
|
tracy.Zone()
|
||||||
sync.atomic_rw_mutex_shared_guard(&global_container.lock)
|
sync.guard(&global_container.lock)
|
||||||
return global_container.names_array[name]
|
return global_container.names_array[name]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import "core:log"
|
|||||||
import "core:sync/chan"
|
import "core:sync/chan"
|
||||||
import "core:thread"
|
import "core:thread"
|
||||||
import "libs:physfs"
|
import "libs:physfs"
|
||||||
|
import "libs:tracy"
|
||||||
|
|
||||||
ASSET_WATCHER_OPS_BUFFER :: 256
|
ASSET_WATCHER_OPS_BUFFER :: 256
|
||||||
|
|
||||||
@ -78,6 +79,8 @@ modtime_watcher_next :: proc(watcher: ^Asset_Modtime_Watcher) -> (asset: Watcher
|
|||||||
|
|
||||||
@(private = "file")
|
@(private = "file")
|
||||||
modtime_watcher_thread_proc :: proc(t: ^thread.Thread) {
|
modtime_watcher_thread_proc :: proc(t: ^thread.Thread) {
|
||||||
|
tracy.SetThreadName("Asset Watcher")
|
||||||
|
|
||||||
watcher := cast(^Asset_Modtime_Watcher)t.data
|
watcher := cast(^Asset_Modtime_Watcher)t.data
|
||||||
|
|
||||||
log.debugf("watcher thread")
|
log.debugf("watcher thread")
|
||||||
|
@ -116,7 +116,6 @@ World :: struct {
|
|||||||
track: Track,
|
track: Track,
|
||||||
physics_scene: physics.Scene,
|
physics_scene: physics.Scene,
|
||||||
pause: bool,
|
pause: bool,
|
||||||
car_com: rl.Vector3,
|
|
||||||
car_handle: physics.Body_Handle,
|
car_handle: physics.Body_Handle,
|
||||||
engine_handle: physics.Engine_Handle,
|
engine_handle: physics.Engine_Handle,
|
||||||
debug_state: Debug_Draw_State,
|
debug_state: Debug_Draw_State,
|
||||||
@ -134,7 +133,6 @@ copy_world :: proc(dst, src: ^World) {
|
|||||||
scene_copy(&dst.main_scene, &src.main_scene)
|
scene_copy(&dst.main_scene, &src.main_scene)
|
||||||
dst.player_pos = src.player_pos
|
dst.player_pos = src.player_pos
|
||||||
dst.pause = src.pause
|
dst.pause = src.pause
|
||||||
dst.car_com = src.car_com
|
|
||||||
dst.car_handle = src.car_handle
|
dst.car_handle = src.car_handle
|
||||||
dst.engine_handle = src.engine_handle
|
dst.engine_handle = src.engine_handle
|
||||||
dst.debug_state = src.debug_state
|
dst.debug_state = src.debug_state
|
||||||
@ -436,10 +434,6 @@ World_Update_Config :: struct {
|
|||||||
update_world :: proc(world: ^World, dt: f32, config: World_Update_Config) {
|
update_world :: proc(world: ^World, dt: f32, config: World_Update_Config) {
|
||||||
|
|
||||||
if !world.pause {
|
if !world.pause {
|
||||||
car_model := assets.get_model(&g_mem.assetman, "assets/ice_cream_truck.glb")
|
|
||||||
car_bounds := rl.GetModelBoundingBox(car_model)
|
|
||||||
world.car_com = (car_bounds.min + car_bounds.max) / 2
|
|
||||||
|
|
||||||
if true {
|
if true {
|
||||||
physics.immediate_body(
|
physics.immediate_body(
|
||||||
&world.physics_scene,
|
&world.physics_scene,
|
||||||
|
@ -279,7 +279,6 @@ copy_mesh :: proc(
|
|||||||
|
|
||||||
|
|
||||||
transform_mesh :: proc(mesh: ^Half_Edge_Mesh, mat: lg.Matrix4f32) {
|
transform_mesh :: proc(mesh: ^Half_Edge_Mesh, mat: lg.Matrix4f32) {
|
||||||
tracy.Zone()
|
|
||||||
mesh_center_avg_factor := 1.0 / f32(len(mesh.vertices))
|
mesh_center_avg_factor := 1.0 / f32(len(mesh.vertices))
|
||||||
new_center: Vec3
|
new_center: Vec3
|
||||||
for i in 0 ..< len(mesh.vertices) {
|
for i in 0 ..< len(mesh.vertices) {
|
||||||
|
@ -568,6 +568,7 @@ find_new_contacts :: proc(
|
|||||||
|
|
||||||
num_contacts_found := 0
|
num_contacts_found := 0
|
||||||
for leaf_node in bvh.iterator_intersect_leaf_next(&it) {
|
for leaf_node in bvh.iterator_intersect_leaf_next(&it) {
|
||||||
|
tracy.ZoneN("intersect_bvh_node")
|
||||||
for j in 0 ..< leaf_node.prim_len {
|
for j in 0 ..< leaf_node.prim_len {
|
||||||
level_geom_handle := index_to_level_geom(
|
level_geom_handle := index_to_level_geom(
|
||||||
int(
|
int(
|
||||||
@ -581,29 +582,33 @@ find_new_contacts :: proc(
|
|||||||
sim_cache,
|
sim_cache,
|
||||||
level_geom_handle,
|
level_geom_handle,
|
||||||
)
|
)
|
||||||
|
body_aabb_in_Level_geom_space := aabb_inv_transform(
|
||||||
|
body_aabb,
|
||||||
|
level_geom.x,
|
||||||
|
level_geom.q,
|
||||||
|
)
|
||||||
blas_it := bvh.iterator_intersect_leaf_aabb(
|
blas_it := bvh.iterator_intersect_leaf_aabb(
|
||||||
&blas,
|
&blas,
|
||||||
aabb_inv_transform(body_aabb, level_geom.x, level_geom.q),
|
body_aabb_in_Level_geom_space,
|
||||||
)
|
)
|
||||||
for blas_leaf_node in bvh.iterator_intersect_leaf_next(&blas_it) {
|
for blas_leaf_node in bvh.iterator_intersect_leaf_next(&blas_it) {
|
||||||
for k in 0 ..< blas_leaf_node.prim_len {
|
for k in 0 ..< blas_leaf_node.prim_len {
|
||||||
tri_idx := int(
|
tri_idx := int(
|
||||||
blas.primitives[blas_leaf_node.child_or_prim_start + k],
|
blas.primitives[blas_leaf_node.child_or_prim_start + k],
|
||||||
)
|
)
|
||||||
tri := get_transformed_triangle(
|
tri := get_triangle(vertices, indices, tri_idx)
|
||||||
vertices,
|
|
||||||
indices,
|
|
||||||
tri_idx,
|
|
||||||
level_geom.x,
|
|
||||||
level_geom.q,
|
|
||||||
)
|
|
||||||
prim_aabb := get_triangle_aabb(tri)
|
prim_aabb := get_triangle_aabb(tri)
|
||||||
|
|
||||||
if bvh.test_aabb_vs_aabb(body_aabb, prim_aabb) {
|
if bvh.test_aabb_vs_aabb(
|
||||||
|
body_aabb_in_Level_geom_space,
|
||||||
|
prim_aabb,
|
||||||
|
) {
|
||||||
|
tracy.ZoneN("body_vs_level_geom")
|
||||||
|
|
||||||
shapes_it := shapes_iterator(sim_state, body.shape)
|
shapes_it := shapes_iterator(sim_state, body.shape)
|
||||||
for shape in shapes_iterator_next(&shapes_it) {
|
for shape in shapes_iterator_next(&shapes_it) {
|
||||||
|
tracy.ZoneN("body_shape_vs_level_geom")
|
||||||
|
|
||||||
shape_idx := shapes_it.counter - 1
|
shape_idx := shapes_it.counter - 1
|
||||||
shape_aabb := shape_get_aabb(shape^)
|
shape_aabb := shape_get_aabb(shape^)
|
||||||
shape_aabb = body_transform_shape_aabb(
|
shape_aabb = body_transform_shape_aabb(
|
||||||
@ -614,6 +619,11 @@ find_new_contacts :: proc(
|
|||||||
min = shape_aabb.center - shape_aabb.extent,
|
min = shape_aabb.center - shape_aabb.extent,
|
||||||
max = shape_aabb.center + shape_aabb.extent,
|
max = shape_aabb.center + shape_aabb.extent,
|
||||||
}
|
}
|
||||||
|
bvh_shape_aabb = aabb_inv_transform(
|
||||||
|
bvh_shape_aabb,
|
||||||
|
level_geom.x,
|
||||||
|
level_geom.q,
|
||||||
|
)
|
||||||
|
|
||||||
pair := make_contact_pair_body_level(
|
pair := make_contact_pair_body_level(
|
||||||
index_to_body_handle(int(body_idx)),
|
index_to_body_handle(int(body_idx)),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user