diff --git a/core/entity.jai b/core/entity.jai index afa60ff..cdf04ce 100644 --- a/core/entity.jai +++ b/core/entity.jai @@ -78,18 +78,19 @@ Entity :: struct { renderable: Renderable; animator: Animator; @DontSerialize - // Physics - physx_handle: PhysX_Handle; - velocity: Vector3; + #if PHYSICS { + // Physics + physx_handle: PhysX_Handle; + velocity: Vector3; + // End physics + } - // End physics - -#if NETWORKING { - remote_id: Entity_Id; @DontSerialize - client_id: Client_Id; @DontSerialize - is_proxy: bool; @DontSerialize - last_replication_time: float; @DontSerialize -} + #if NETWORKING { + remote_id: Entity_Id; @DontSerialize + client_id: Client_Id; @DontSerialize + is_proxy: bool; @DontSerialize + last_replication_time: float; @DontSerialize + } _locator: Bucket_Locator; @DontSerialize scene: *Scene; @DontSerialize diff --git a/core/mesh_entity.jai b/core/mesh_entity.jai index e72773f..9048314 100644 --- a/core/mesh_entity.jai +++ b/core/mesh_entity.jai @@ -40,4 +40,4 @@ find_all_mesh_entities :: () { path := "../assets/models/level_design/"; visit_files(path, true, *mesh_entity_files, mesh_entity_visitor); -} \ No newline at end of file +} diff --git a/core/scene.jai b/core/scene.jai index 493d15d..dd28dae 100644 --- a/core/scene.jai +++ b/core/scene.jai @@ -22,7 +22,9 @@ Scene :: struct { mode: Engine_Mode; - physx_scene: PhysX_Scene; + #if PHYSICS { + physx_scene: PhysX_Scene; + } using custom_fields: _Custom_Scene_Fields; } diff --git a/module.jai b/module.jai index 5744dc6..0ac5cca 100644 --- a/module.jai +++ b/module.jai @@ -1,4 +1,4 @@ -#module_parameters(WITH_EDITOR := true, WITH_NETWORKING := false, action_type : Type, entity_fields: Type, scene_fields: Type); +#module_parameters(WITH_EDITOR := true, WITH_NETWORKING := false, WITH_PHYSICS := false, action_type : Type, entity_fields: Type, scene_fields: Type); // TODO: Add a fallback, if none we're specified _Custom_Entity_Fields :: entity_fields; @@ -8,6 +8,7 @@ Action :: action_type; EDITOR :: WITH_EDITOR; DEBUG :: true; NETWORKING :: WITH_NETWORKING; +PHYSICS :: WITH_PHYSICS; #if EDITOR { //#load "../editor/scene_editor.jai"; @@ -83,7 +84,9 @@ coven_init :: (window_title: string, window_width: u32, window_height: u32, full init_audio_system(); init_console(); - init_physx(); + #if PHYSICS { + init_physx(); + } #if EDITOR { init_editor(); @@ -158,11 +161,14 @@ coven_run :: (game_update_proc: (float), game_editor_update_proc: (float), game_ if engine.current_scene != null && !engine.paused { update_animators(clamped_dt); - pre_physx_sync(engine.current_scene); - tick_physx(*engine.current_scene.physx_scene, clamped_dt); - post_physx_sync(engine.current_scene); + #if PHYSICS { + pre_physx_sync(engine.current_scene); + tick_physx(*engine.current_scene.physx_scene, clamped_dt); + post_physx_sync(engine.current_scene); - game_update_post_physics_proc(clamped_dt); + // TODO: Move this out into engine.procs + game_update_post_physics_proc(clamped_dt); + } } } else { game_editor_update_proc(clamped_dt); @@ -214,6 +220,10 @@ switch_engine_mode :: (to_mode: Engine_Mode) { } } +#if PHYSICS { + #load "physics/physx.jai"; +} + #if NETWORKING { #load "networking/networking.jai"; } @@ -238,7 +248,6 @@ switch_engine_mode :: (to_mode: Engine_Mode) { #load "core/console.jai"; #load "audio/audio.jai"; #load "core/fps.jai"; -#load "physics/physx.jai"; #scope_export diff --git a/physics/physx.jai b/physics/physx.jai index beb47f3..6893bb4 100644 --- a/physics/physx.jai +++ b/physics/physx.jai @@ -1,4 +1,4 @@ -PHYSX_TEST :: false; PHYSX_DEFAULT_SHAPE_FLAGS :: cast(u8)(PhysX.PxShapeFlags.Visualization | PhysX.PxShapeFlags.SceneQueryShape | PhysX.PxShapeFlags.SimulationShape); +PHYSX_DEFAULT_SHAPE_FLAGS :: cast(u8)(PhysX.PxShapeFlags.Visualization | PhysX.PxShapeFlags.SceneQueryShape | PhysX.PxShapeFlags.SimulationShape); PhysX_Handle :: #type, distinct u32; @@ -116,6 +116,38 @@ post_physx_sync :: (game_scene: *Scene) { } } + +add_physx_sphere :: (entity: *Entity, radius: float) -> PhysX_Handle { + geo := PhysX.PxSphereGeometry_new(radius); + + transform := PhysX.PxTransform_new(*entity.transform.position); + actor := PhysX.PxPhysics_createRigidDynamic(physics, *transform); + //PhysX.PxRigidDynamic_setRigidDynamicLockFlag(actor, xx PhysX.PxRigidDynamicLockFlags.LockAngularX, true); + //PhysX.PxRigidDynamic_setRigidDynamicLockFlag(actor, xx PhysX.PxRigidDynamicLockFlags.LockAngularY, true); + //PhysX.PxRigidDynamic_setRigidDynamicLockFlag(actor, xx PhysX.PxRigidDynamicLockFlags.LockAngularZ, true); + + material := PhysX.PxPhysics_createMaterial(physics, 0.1, 0.1, 0.5); + + //PhysX.PxMaterial_setRestitutionCombineMode(material,1); // Turn off restitution no matter the other material + + shape := PhysX.PxPhysics_createShape(physics, *geo, material, false, PHYSX_DEFAULT_SHAPE_FLAGS); + PhysX.PxRigidActor_attachShape(actor, shape); + + PhysX.PxRigidBodyExt_updateMassAndInertia(actor, 0.1, null, false); + PhysX.PxScene_addActor(entity.scene.physx_scene.scene, actor, null); + + PhysX.PxShape_release(shape); + PhysX.PxBase_release(material); + + physics_actor : PhysX_Actor; + physics_actor.type = .DYNAMIC; + physics_actor.sync_rotation_from_physx = true; + physics_actor.dynamic = actor; + + entity.physx_handle = parray_add(*entity.scene.physx_scene.actors, physics_actor); + return entity.physx_handle; +} + add_physx_capsule :: (entity: *Entity, half_height: float, radius: float) -> PhysX_Handle { geo := PhysX.PxCapsuleGeometry_new(radius, half_height-radius); @@ -145,8 +177,7 @@ add_physx_capsule :: (entity: *Entity, half_height: float, radius: float) -> Phy PhysX.PxScene_addActor(entity.scene.physx_scene.scene, actor, null); PhysX.PxShape_release(shape); - // @Incomplete - //PhysX.PxMaterial_release(material); + PhysX.PxBase_release(material); physics_actor : PhysX_Actor; physics_actor.type = .DYNAMIC;