Added Physics.Raycast and Transform shortcut on entity objects

This commit is contained in:
Antoine Pilote
2024-09-04 22:26:59 -04:00
parent ea97133e94
commit 732e94899c
10 changed files with 148 additions and 107 deletions

View File

@@ -282,21 +282,6 @@ namespace Nuake
const auto& result = PhysicsManager::Get().GetWorld()->Raycast(from, to);
// We multiply by 3 since we have 3 floats per hit result: vector3.
wrenEnsureSlots(vm, static_cast<int>(result.size() * 3));
wrenSetSlotNewList(vm, 0);
uint32_t index = 1;
for (auto& r : result)
{
wrenSetSlotDouble(vm, index, r.WorldPosition.x);
wrenSetSlotDouble(vm, index + 1, r.WorldPosition.y);
wrenSetSlotDouble(vm, index + 2, r.WorldPosition.z);
wrenInsertInList(vm, 0, -1, index);
wrenInsertInList(vm, 0, -1, index + 1);
wrenInsertInList(vm, 0, -1, index + 2);
index += 3;
}
}
static void MoveAndSlide(WrenVM* vm)

View File

@@ -73,6 +73,14 @@ namespace Nuake {
return Coral::Array<float>::New(results);
}
Coral::Array<float> Raycast(float fromX, float fromY, float fromZ, float toX, float toY, float toZ)
{
const Vector3 from = { fromX, fromY, fromZ };
const Vector3 to = { toX, toY, toZ };
auto hits = PhysicsManager::Get().Raycast(from, to);
return ConvertHitsToArray(hits);
}
Coral::Array<float> ShapeCastCapsule(float fromX, float fromY, float fromZ, float toX, float toY, float toZ, CapsuleInternal capsuleInternal)
{
auto capsule = CreateRef<Physics::Capsule>(capsuleInternal.Radius, capsuleInternal.Height);
@@ -104,6 +112,7 @@ namespace Nuake {
RegisterMethod("Debug.DrawShapeCapsuleIcall", &DrawShapeCapsule);
RegisterMethod("Debug.DrawShapeCylinderIcall", &DrawShapeCylinder);
RegisterMethod("Physic.RayCastIcall", &Raycast);
RegisterMethod("Physic.ShapeCastCapsuleIcall", &ShapeCastCapsule);
RegisterMethod("Physic.ShapeCastBoxIcall", &ShapeCastBox);
}

View File

@@ -343,106 +343,109 @@ namespace Nuake
}
}
const std::string baseTypeName = std::string(type->GetBaseType().GetFullName());
if (baseTypeName != "Nuake.Net.Entity")
if (type->GetBaseType())
{
continue;
}
m_BaseEntityType = type->GetBaseType();
auto typeSplits = String::Split(type->GetFullName(), '.');
std::string shortenedTypeName = typeSplits[typeSplits.size() - 1];
NetGameScriptObject gameScriptObject;
gameScriptObject.coralType = type;
gameScriptObject.exposedVars = std::vector<ExposedVar>();
gameScriptObject.Base = baseTypeName;
for (auto& f : type->GetFields())
{
for (auto& a : f.GetAttributes())
const std::string baseTypeName = std::string(type->GetBaseType().GetFullName());
if (baseTypeName != "Nuake.Net.Entity")
{
if (a.GetType() == exposedFieldAttributeType)
continue;
}
m_BaseEntityType = type->GetBaseType();
auto typeSplits = String::Split(type->GetFullName(), '.');
std::string shortenedTypeName = typeSplits[typeSplits.size() - 1];
NetGameScriptObject gameScriptObject;
gameScriptObject.coralType = type;
gameScriptObject.exposedVars = std::vector<ExposedVar>();
gameScriptObject.Base = baseTypeName;
for (auto& f : type->GetFields())
{
for (auto& a : f.GetAttributes())
{
ExposedVar exposedVar;
exposedVar.Name = f.GetName();
auto typeName = f.GetType().GetFullName();
ExposedVarTypes varType = ExposedVarTypes::Unsupported;
bool hasDefaultValue = a.GetFieldValue<Coral::Bool32>("HasDefaultvalue");
if (typeName == "System.Single")
if (a.GetType() == exposedFieldAttributeType)
{
varType = ExposedVarTypes::Float;
ExposedVar exposedVar;
exposedVar.Name = f.GetName();
if (hasDefaultValue)
auto typeName = f.GetType().GetFullName();
ExposedVarTypes varType = ExposedVarTypes::Unsupported;
bool hasDefaultValue = a.GetFieldValue<Coral::Bool32>("HasDefaultvalue");
if (typeName == "System.Single")
{
exposedVar.Value = a.GetFieldValue<float>("DefaultValueInternalFloat");
}
}
else if (typeName == "System.Double")
{
varType = ExposedVarTypes::Double;
}
else if (typeName == "System.String")
{
varType = ExposedVarTypes::String;
varType = ExposedVarTypes::Float;
if (hasDefaultValue)
if (hasDefaultValue)
{
exposedVar.Value = a.GetFieldValue<float>("DefaultValueInternalFloat");
}
}
else if (typeName == "System.Double")
{
exposedVar.Value = a.GetFieldValue<Coral::String>("DefaultValueInternalString");
varType = ExposedVarTypes::Double;
}
}
else if (typeName == "System.Boolean")
{
varType = ExposedVarTypes::Bool;
if (hasDefaultValue)
else if (typeName == "System.String")
{
exposedVar.Value = a.GetFieldValue<Coral::Bool32>("DefaultValueInternalBool");
varType = ExposedVarTypes::String;
if (hasDefaultValue)
{
exposedVar.Value = a.GetFieldValue<Coral::String>("DefaultValueInternalString");
}
}
}
else if (typeName == "System.Numerics.Vector2")
{
varType = ExposedVarTypes::Vector2;
}
else if (typeName == "System.Numerics.Vector3")
{
varType = ExposedVarTypes::Vector3;
}
else if (typeName == "Nuake.Net.Entity")
{
varType = ExposedVarTypes::Entity;
}
else if (typeName == "Nuake.Net.Prefab")
{
varType = ExposedVarTypes::Prefab;
}
else if (typeName == "System.Boolean")
{
varType = ExposedVarTypes::Bool;
if (varType != ExposedVarTypes::Unsupported)
{
exposedVar.Type = varType;
gameScriptObject.exposedVars.push_back(exposedVar);
}
if (hasDefaultValue)
{
exposedVar.Value = a.GetFieldValue<Coral::Bool32>("DefaultValueInternalBool");
}
}
else if (typeName == "System.Numerics.Vector2")
{
varType = ExposedVarTypes::Vector2;
}
else if (typeName == "System.Numerics.Vector3")
{
varType = ExposedVarTypes::Vector3;
}
else if (typeName == "Nuake.Net.Entity")
{
varType = ExposedVarTypes::Entity;
}
else if (typeName == "Nuake.Net.Prefab")
{
varType = ExposedVarTypes::Prefab;
}
Logger::Log("Exposed field detected: " + std::string(f.GetName()) + " of type " + std::string(f.GetType().GetFullName()) );
if (varType != ExposedVarTypes::Unsupported)
{
exposedVar.Type = varType;
gameScriptObject.exposedVars.push_back(exposedVar);
}
Logger::Log("Exposed field detected: " + std::string(f.GetName()) + " of type " + std::string(f.GetType().GetFullName()));
}
}
}
}
// Add to the brush map to retrieve when exporting FGD
if (isBrushScript)
{
gameScriptObject.Description = brushDescription;
gameScriptObject.isTrigger = isTrigger;
m_BrushEntityTypes[shortenedTypeName] = gameScriptObject;
}
// Add to the brush map to retrieve when exporting FGD
if (isBrushScript)
{
gameScriptObject.Description = brushDescription;
gameScriptObject.isTrigger = isTrigger;
m_BrushEntityTypes[shortenedTypeName] = gameScriptObject;
}
if (isPointScript)
{
gameScriptObject.Description = pointDescription;
m_PointEntityTypes[shortenedTypeName] = gameScriptObject;
if (isPointScript)
{
gameScriptObject.Description = pointDescription;
m_PointEntityTypes[shortenedTypeName] = gameScriptObject;
}
m_GameEntityTypes[shortenedTypeName] = gameScriptObject;
}
m_GameEntityTypes[shortenedTypeName] = gameScriptObject;
}
}