From cb51ecc11996746f5a32e94e6e65e82023f2b308 Mon Sep 17 00:00:00 2001 From: Antoine Pilote Date: Tue, 24 Oct 2023 23:45:28 -0400 Subject: [PATCH] C++ .Net module API update --- .../src/Scripting/NetModules/SceneNetAPI.cpp | 85 +++++++++++++++---- 1 file changed, 68 insertions(+), 17 deletions(-) diff --git a/Nuake/src/Scripting/NetModules/SceneNetAPI.cpp b/Nuake/src/Scripting/NetModules/SceneNetAPI.cpp index 5cbc8904..1bbe5e9e 100644 --- a/Nuake/src/Scripting/NetModules/SceneNetAPI.cpp +++ b/Nuake/src/Scripting/NetModules/SceneNetAPI.cpp @@ -2,23 +2,27 @@ #include "Engine.h" #include "src/Scene/Entities/Entity.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "src/Scene/Components/ParentComponent.h" +#include "src/Scene/Components/PrefabComponent.h" +#include "src/Scene/Components/CameraComponent.h" +#include "src/Scene/Components/AudioEmitterComponent.h" +#include "src/Scene/Components/ModelComponent.h" +#include "src/Scene/Components/SkinnedModelComponent.h" +#include "src/Scene/Components/BoneComponent.h" +#include "src/Scene/Components/BoxCollider.h" +#include "src/Scene/Components/SphereCollider.h" +#include "src/Scene/Components/CapsuleColliderComponent.h" +#include "src/Scene/Components/CylinderColliderComponent.h" +#include "src/Scene/Components/MeshCollider.h" +#include "src/Scene/Components/CharacterControllerComponent.h" +#include "src/Scene/Components/ParticleEmitterComponent.h" +#include "src/Scene/Components/BSPBrushComponent.h" +#include "src/Scene/Components/SpriteComponent.h" +#include "src/Scene/Components/QuakeMap.h" + +#include "src/Physics/PhysicsManager.h" + +#include namespace Nuake { @@ -123,6 +127,48 @@ namespace Nuake { } } + Coral::NativeArray CameraGetDirection(int entityId) + { + Entity entity = { (entt::entity)(entityId), Engine::GetCurrentScene().get() }; + + if (entity.IsValid() && entity.HasComponent()) + { + auto& component = entity.GetComponent(); + const Vector3 camDirection = component.CameraInstance->GetDirection(); + return { camDirection.x, camDirection.y, camDirection.z }; + } + } + + void MoveAndSlide(int entityId, float vx, float vy, float vz) + { + Entity entity = { (entt::entity)(entityId), Engine::GetCurrentScene().get() }; + + if (entity.IsValid() && entity.HasComponent()) + { + auto& component = entity.GetComponent(); + + if (std::isnan(vx) || std::isnan(vy) || std::isnan(vz)) + { + return; // Log message here? invalid input + } + + component.GetCharacterController()->MoveAndSlide({ vx, vy, vz }); + } + } + + bool IsOnGround(int entityId) + { + Entity entity = Entity((entt::entity)(entityId), Engine::GetCurrentScene().get()); + + if (entity.IsValid() && entity.HasComponent()) + { + auto& characterController = entity.GetComponent(); + return PhysicsManager::Get().GetWorld()->IsCharacterGrounded(entity); + } + + return false; + } + void Nuake::SceneNetAPI::RegisterMethods() { RegisterMethod("Entity.EntityHasComponentIcall", &EntityHasComponent); @@ -131,6 +177,11 @@ namespace Nuake { // Components RegisterMethod("TransformComponent.SetPositionIcall", &TransformSetPosition); RegisterMethod("TransformComponent.RotateIcall", &TransformRotate); + + RegisterMethod("CameraComponent.GetDirectionIcall", &CameraGetDirection); + + RegisterMethod("CharacterControllerComponent.MoveAndSlideIcall", &MoveAndSlide); + RegisterMethod("CharacterControllerComponent.IsOnGroundIcall", &IsOnGround); } }