Physics optional
This commit is contained in:
@@ -78,18 +78,19 @@ Entity :: struct {
|
||||
renderable: Renderable;
|
||||
animator: Animator; @DontSerialize
|
||||
|
||||
#if PHYSICS {
|
||||
// Physics
|
||||
physx_handle: PhysX_Handle;
|
||||
velocity: Vector3;
|
||||
|
||||
// End physics
|
||||
}
|
||||
|
||||
#if NETWORKING {
|
||||
#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
|
||||
|
||||
@@ -22,7 +22,9 @@ Scene :: struct {
|
||||
|
||||
mode: Engine_Mode;
|
||||
|
||||
#if PHYSICS {
|
||||
physx_scene: PhysX_Scene;
|
||||
}
|
||||
|
||||
using custom_fields: _Custom_Scene_Fields;
|
||||
}
|
||||
|
||||
13
module.jai
13
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();
|
||||
|
||||
#if PHYSICS {
|
||||
init_physx();
|
||||
}
|
||||
|
||||
#if EDITOR {
|
||||
init_editor();
|
||||
@@ -158,12 +161,15 @@ coven_run :: (game_update_proc: (float), game_editor_update_proc: (float), game_
|
||||
if engine.current_scene != null && !engine.paused {
|
||||
update_animators(clamped_dt);
|
||||
|
||||
#if PHYSICS {
|
||||
pre_physx_sync(engine.current_scene);
|
||||
tick_physx(*engine.current_scene.physx_scene, clamped_dt);
|
||||
post_physx_sync(engine.current_scene);
|
||||
|
||||
// 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
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user