Physx/PhysxWorldManager.cs
2023-07-31 13:55:44 +08:00

86 lines
2.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MagicPhysX; // for enable Extension Methods.
using MagicPhysX.Toolkit;
using PhysX;
using static MagicPhysX.NativeMethods; // recommend to use C API.
namespace Physx
{
public unsafe struct PhysxWorldManager
{
public PhysxWorldManager()
{
//TODO 后续根据实际业务来写
//stamp_ = KG_GetTimeStamp();
stamp_ = 0;
physx_world_manager_.Clear();
}
//virtual ~PhysxWorldManager();
bool AddPhysxWorld(UInt64 area_id)
{
var itl = physx_world_manager_.ContainsKey(area_id);
if (itl = true)
return false;
var physx_world = new PhysxWorld();
// physx_world
if (physx_world.Equals(default(PhysxWorld)) == false)
return false;
physx_world.OnInit();
//physx_world_manager_.Add< area_id, physx_world});
physx_world_manager_.Add(area_id, (nint)(&physx_world));
return true;
}
PhysxWorld* GetPhysxWorld(UInt64 area_id)
{
nint ret = 0;
if (physx_world_manager_.TryGetValue(area_id, out ret))
{
return (PhysxWorld*)(ret.ToPointer());
}
return null;
}
bool AddActorToPhysxWorld(UInt64 area_id, PxRigidActor* obj)
{
var physx_world = GetPhysxWorld(area_id);
if (physx_world == null)
{
return false;
}
physx_world->AddActorToDaynamicWorld(obj);
return true;
}
bool PickUpActorFromPhysxWorld(UInt64 area_id, PxRigidActor* obj)
{
var physx_world = GetPhysxWorld(area_id);
if (physx_world == null)
{
return false;
}
physx_world->PickUpActor(obj);
return true;
}
//暂不实现 业务代码
//bool SwitchPhysxWorld(KScene* scene, UInt64 cur_area_id, UInt64 to_area_id, KHero* hero)
//{
//}
//bool UpdatePhysxWorld(KScene* secene)
//{
// return false;
//}
bool HasPhysxWorld()
{
return physx_world_manager_.Count() > 0;
}
Dictionary<UInt64, IntPtr> physx_world_manager_;
UInt64 stamp_;
}
}