diff --git a/Nuake/src/Physics/DynamicWorld.cpp b/Nuake/src/Physics/DynamicWorld.cpp index 3f74e4a7..2b4e9766 100644 --- a/Nuake/src/Physics/DynamicWorld.cpp +++ b/Nuake/src/Physics/DynamicWorld.cpp @@ -400,23 +400,15 @@ namespace Nuake bodySettings.mMassPropertiesOverride.mMass = mass; } - if (rb->GetEntity().GetID() == 0) + if (int entityId = rb->GetEntity().GetHandle(); rb->GetEntity().IsValid()) { - Logger::Log("Entity with ID 0 detected. Name: " + rb->GetEntity().GetComponent().Name, "DEBUG"); + bodySettings.mUserData = rb->GetEntity().GetHandle(); + + // Create the actual rigid body + JPH::BodyID body = _JoltBodyInterface->CreateAndAddBody(bodySettings, JPH::EActivation::Activate); // Note that if we run out of bodies this can return nullptr + uint32_t bodyIndex = (uint32_t)body.GetIndexAndSequenceNumber(); + _registeredBodies.push_back(bodyIndex); } - - int entityId = rb->GetEntity().GetHandle(); - - if (entityId == 0) - { - Logger::Log("ERROR"); - } - - bodySettings.mUserData = entityId; - // Create the actual rigid body - JPH::BodyID body = _JoltBodyInterface->CreateAndAddBody(bodySettings, JPH::EActivation::Activate); // Note that if we run out of bodies this can return nullptr - uint32_t bodyIndex = (uint32_t)body.GetIndexAndSequenceNumber(); - _registeredBodies.push_back(bodyIndex); } void DynamicWorld::AddGhostbody(Ref gb) @@ -501,7 +493,9 @@ namespace Nuake if (newPosition != currentPosition || currentRotation != newRotation) { std::string name = entity.GetComponent().Name; + _JoltBodyInterface->SetPositionAndRotation(bodyId, newPosition, newRotation, JPH::EActivation::DontActivate); + //_JoltBodyInterface->MoveKinematic(bodyId, newPosition, newRotation, 0.0f); } } } diff --git a/Nuake/src/Scene/Components/NetScriptComponent.h b/Nuake/src/Scene/Components/NetScriptComponent.h index 6def9531..bda833a9 100644 --- a/Nuake/src/Scene/Components/NetScriptComponent.h +++ b/Nuake/src/Scene/Components/NetScriptComponent.h @@ -169,8 +169,11 @@ namespace Nuake { exposedVar.DefaultValue = (bool)exposedVarJson["DefaultValue"]; break; case NetScriptExposedVarType::Float: - exposedVar.Value = (float)exposedVarJson["Value"]; - exposedVar.DefaultValue = (float)exposedVarJson["DefaultValue"]; + if (exposedVarJson.contains("Value")) + { + exposedVar.Value = (float)exposedVarJson["Value"]; + } + exposedVar.DefaultValue = 0.0f; break; case NetScriptExposedVarType::Double: exposedVar.Value = (double)exposedVarJson["Value"]; @@ -183,8 +186,8 @@ namespace Nuake { break; } case NetScriptExposedVarType::String: - exposedVar.Value = (std::string)exposedVarJson["Value"]; - exposedVar.DefaultValue = (std::string)exposedVarJson["DefaultValue"]; + //exposedVar.Value = (std::string)exposedVarJson["Value"]; + //exposedVar.DefaultValue = (std::string)exposedVarJson["DefaultValue"]; break; case NetScriptExposedVarType::Vector2: { diff --git a/Nuake/src/Scene/Systems/PhysicsSystem.cpp b/Nuake/src/Scene/Systems/PhysicsSystem.cpp index 5b29450c..400843b0 100644 --- a/Nuake/src/Scene/Systems/PhysicsSystem.cpp +++ b/Nuake/src/Scene/Systems/PhysicsSystem.cpp @@ -131,6 +131,7 @@ namespace Nuake const Quat& startRotation = transformComponent.GetGlobalRotation(); const auto collisionShape = CreateRef(hull); + auto rigidBody = CreateRef(0.0f, startPosition, startRotation, startTransform, collisionShape, entity); brushComponent.Rigidbody.push_back(rigidBody); rigidBody->SetIsTrigger(brushComponent.IsTrigger); @@ -321,6 +322,7 @@ namespace Nuake } Ref shape; + bool hasValidShape = true; if (entity.HasComponent()) { const auto& capsuleColliderComponent = entity.GetComponent(); @@ -343,7 +345,9 @@ namespace Nuake } else { - continue; + hasValidShape = false; + Logger::Log("No shape was provided for character controller. Default one was provided.", "physics", WARNING); + shape = CreateRef(1.0f, 0.5f); } Physics::CharacterControllerSettings settings diff --git a/Nuake/src/Scene/Systems/QuakeMapBuilder.cpp b/Nuake/src/Scene/Systems/QuakeMapBuilder.cpp index a70cfdde..8fb21cb8 100644 --- a/Nuake/src/Scene/Systems/QuakeMapBuilder.cpp +++ b/Nuake/src/Scene/Systems/QuakeMapBuilder.cpp @@ -244,6 +244,8 @@ namespace Nuake { TransformComponent& transformComponent = brushEntity.GetComponent(); BSPBrushComponent& bsp = brushEntity.AddComponent(); + std::map> m_Materials; + bsp.IsSolid = !fgdBrush.IsTrigger; bsp.IsTransparent = !fgdBrush.Visible; bsp.IsFunc = true; @@ -298,6 +300,37 @@ namespace Nuake { texture->width = tex->GetWidth(); } + Ref currentMaterial; + if (std::string(texture->name) != "__TB_empty") + { + std::string path = FileSystem::Root + "Textures/" + std::string(texture->name) + ".png"; + + if (const std::string materialPath = "Materials/" + std::string(texture->name) + ".material"; + FileSystem::FileExists(materialPath)) + { + Ref material = ResourceLoader::LoadMaterial(materialPath); + m_Materials[path] = material; + } + else + { + if (m_Materials.find(path) == m_Materials.end()) + { + m_Materials[path] = MaterialManager::Get()->GetMaterial(path); + } + } + + currentMaterial = m_Materials[path]; + texture->height = currentMaterial->m_Albedo->GetHeight(); + texture->width = currentMaterial->m_Albedo->GetWidth(); + } + else + { + continue; + + currentMaterial = MaterialManager::Get()->GetMaterial("resources/Textures/default/Default.png"); + texture->height = texture->width = 1; + } + face_geometry* face_geo_inst = &brush_inst->faces[f]; for (int i = 0; i < face_geo_inst->vertex_count; ++i) @@ -344,8 +377,7 @@ namespace Nuake { if (std::string(texture->name) != "__TB_empty") { - Ref material = MaterialManager::Get()->GetMaterial(lastTexturePath); - mesh->SetMaterial(material); + mesh->SetMaterial(currentMaterial); } bsp.Meshes.push_back(mesh); diff --git a/Nuake/src/Scripting/NetModules/SceneNetAPI.cpp b/Nuake/src/Scripting/NetModules/SceneNetAPI.cpp index ad9d02ba..748e25bc 100644 --- a/Nuake/src/Scripting/NetModules/SceneNetAPI.cpp +++ b/Nuake/src/Scripting/NetModules/SceneNetAPI.cpp @@ -126,7 +126,7 @@ namespace Nuake { return false; } - switch (static_cast(componentEnumValue)) + switch (static_cast(componentType)) { case PARENT: return entity.HasComponent(); case NAME: return entity.HasComponent(); diff --git a/Nuake/src/Scripting/ScriptingEngineNet.cpp b/Nuake/src/Scripting/ScriptingEngineNet.cpp index e9d9ea43..5c4f0b09 100644 --- a/Nuake/src/Scripting/ScriptingEngineNet.cpp +++ b/Nuake/src/Scripting/ScriptingEngineNet.cpp @@ -280,7 +280,7 @@ namespace Nuake { if (!m_IsInitialized) { - Initialize(); + return; } const std::string sanitizedProjectName = String::Sanitize(project->Name); @@ -522,6 +522,11 @@ namespace Nuake // Override with user values set in the editor. for (auto& exposedVarUserValue : component.ExposedVar) { + if (!exposedVarUserValue.Value.has_value()) + { + continue; + } + if (exposedVarUserValue.Type == NetScriptExposedVarType::String) { std::string stringValue = std::any_cast(exposedVarUserValue.Value); diff --git a/NuakeNet/src/Entity.cs b/NuakeNet/src/Entity.cs index f266ff32..3c0320d2 100644 --- a/NuakeNet/src/Entity.cs +++ b/NuakeNet/src/Entity.cs @@ -201,7 +201,7 @@ namespace Nuake.Net return (T?)Activator.CreateInstance(typeof(T), ECSHandle); } - return null; + throw new Exception("Component not found: " + typeof(T).GetType().Name); } public T? GetEntity(string path) where T : Entity diff --git a/NuakeNet/src/main.cs b/NuakeNet/src/main.cs index 51cfd080..f90fcd0b 100644 --- a/NuakeNet/src/main.cs +++ b/NuakeNet/src/main.cs @@ -49,6 +49,19 @@ namespace Nuake.Net } } + [AttributeUsage(AttributeTargets.Class)] + public sealed class PointScript : Attribute + { + public string Description = ""; + public bool IsTrigger = false; + + public PointScript(string description = "") + { + Description = description; + IsTrigger = isTrigger; + } + } + public class Debug { internal static unsafe delegate*