Huge refactor, Adding more code to engine from the game

This commit is contained in:
sam
2026-03-19 22:32:26 +05:45
parent 493338d91b
commit 09941e3e1d
10 changed files with 799 additions and 39 deletions
+52 -21
View File
@@ -1,4 +1,4 @@
package ion
package edit2d
import b2 "vendor:box2d"
import "core:fmt"
@@ -12,30 +12,13 @@ static_index_global :: struct
offset : b2.Vec2,
}
//DropProc :: #type proc "c" (window: WindowHandle, count: c.int, paths: [^]cstring)
/*
This file contains code to handle box2d stuffs of the game code
Don't put game's logic here
*/
engine_world :: struct
{
world_id : b2.WorldId,
//This in engine code?
static_indexes : map[static_index]int `cbor:"-"`,
relations : map[^static_index][dynamic]static_index_global `cbor:"-"`,
relations_serializeable : map[ static_index][dynamic]static_index_global,
/*
Seems okay to put the joint defs in engine rather than in game because
we don't add more attributes in joints in the game
Can be changed later without requireing refactor
*/
revolute_joint_defs : [dynamic]revolt_joint_def,
distant_joint_defs : [dynamic]distance_joint_def,
joints : [dynamic]b2.JointId `cbor:"-"`,
}
engine_entity_flags_enum :: enum u64 {
POLYGON_IS_BOX,
@@ -75,6 +58,32 @@ engine_entity_def :: struct {
link_length_array : [dynamic]b2.Vec2,
}
default_engine_entity_def :: proc() -> engine_entity_def
{
ret : engine_entity_def
ret.body_def = b2.DefaultBodyDef()
ret.shape_def = b2.DefaultShapeDef()
ret.shape_type = .polygonShape
ret.scale = 1
ret.centers = {{-10, 0}, {10, 0}}
ret.size = {2, 2}
ret.radius = 10
ret.body_count = 10
ret.rev_joint = b2.DefaultRevoluteJointDef()
//for dynamic polygon
vs : [4]b2.Vec2 = {
{-1.0, -1.0},
{-1.0, 1.0},
{1.0, 1.0},
{1.0, -1.0},
}
ret.is_loop = true
for v in vs do append(&ret.vertices, v)
return ret
}
compare_engine_entity_def :: proc(a, b : engine_entity_def) -> bool
{
@@ -118,6 +127,7 @@ engine_entity :: struct {
joints : [dynamic]b2.JointId,
entity_flags : engine_entity_flags,
index : ^static_index,
joint_id : b2.JointId,
}
@@ -259,7 +269,11 @@ engine_entity_single_body :: proc(def : ^engine_entity_def, world_id: b2.WorldId
return new_entity
}
engine_create_chain_shape :: proc(def : ^engine_entity_def, world_id: b2.WorldId, index : i32) -> engine_entity
engine_create_chain_shape :: proc(
def : ^engine_entity_def,
world_id : b2.WorldId,
index : i32
) -> engine_entity
{
joint_def := def.rev_joint
orig_pos := def.body_def.position
@@ -296,6 +310,23 @@ engine_create_chain_shape :: proc(def : ^engine_entity_def, world_id: b2.WorldId
}
engine_create_entity :: proc(
def : ^engine_entity_def,
world_id : b2.WorldId,
index : i32
) -> engine_entity
{
if .CHAIN not_in def.entity_flags
{
return engine_entity_single_body(def, world_id, index)
}
else
{
return engine_create_chain_shape(def, world_id, index)
}
}