Added C# Point entities + automatic export of FGD entities

This commit is contained in:
Antoine Pilote
2024-09-01 19:37:05 -04:00
parent f59a7e931f
commit 63712edc6d
21 changed files with 534 additions and 479 deletions

View File

@@ -234,6 +234,7 @@ namespace Nuake {
for (auto e : brushView)
{
BSPBrushComponent& brushComponent = brushView.get<BSPBrushComponent>(e);
auto targets = brushComponent.Targets;
if (brushComponent.TargetName == target)
{
Entity entity = { (entt::entity)(e), scene.get() };
@@ -345,6 +346,29 @@ namespace Nuake {
}
}
float CameraGetFOV(int entityId)
{
Entity entity = { (entt::entity)(entityId), Engine::GetCurrentScene().get() };
if (entity.IsValid() && entity.HasComponent<CameraComponent>())
{
auto& component = entity.GetComponent<CameraComponent>();
return component.CameraInstance->Fov;
}
}
void CameraSetFOV(int entityId, float fov)
{
float safeFov = glm::clamp(fov, 1.0f, 180.0f);
Entity entity = { (entt::entity)(entityId), Engine::GetCurrentScene().get() };
if (entity.IsValid() && entity.HasComponent<CameraComponent>())
{
auto& component = entity.GetComponent<CameraComponent>();
component.CameraInstance->Fov = safeFov;
}
}
void MoveAndSlide(int entityId, float vx, float vy, float vz)
{
Entity entity = { (entt::entity)(entityId), Engine::GetCurrentScene().get() };
@@ -432,6 +456,30 @@ namespace Nuake {
return {};
}
bool AudioEmitterGetIsPlaying(int entityId)
{
Entity entity = Entity((entt::entity)(entityId), Engine::GetCurrentScene().get());
if (entity.IsValid() && entity.HasComponent<AudioEmitterComponent>())
{
auto& audioEmitter = entity.GetComponent<AudioEmitterComponent>();
return audioEmitter.IsPlaying;
}
return false;
}
void AudioEmitterSetIsPlaying(int entityId, Coral::Bool32 isPlaying)
{
Entity entity = Entity((entt::entity)(entityId), Engine::GetCurrentScene().get());
if (entity.IsValid() && entity.HasComponent<AudioEmitterComponent>())
{
auto& audioEmitter = entity.GetComponent<AudioEmitterComponent>();
audioEmitter.IsPlaying = isPlaying;
}
}
void Nuake::SceneNetAPI::RegisterMethods()
{
// Entity
@@ -443,6 +491,7 @@ namespace Nuake {
RegisterMethod("Entity.EntityIsValidIcall", &EntityIsValid);
RegisterMethod("Entity.EntityGetTargetsIcall", &EntityGetTargets);
RegisterMethod("Entity.EntityGetTargetIcall", &EntityGetTarget);
// Prefab
RegisterMethod("Prefab.PrefabInstanceIcall", &PrefabInstance);
@@ -465,6 +514,8 @@ namespace Nuake {
// Camera
RegisterMethod("CameraComponent.GetDirectionIcall", &CameraGetDirection);
RegisterMethod("CameraComponent.GetCameraFOVIcall", &CameraGetFOV);
RegisterMethod("CameraComponent.SetCameraFOVIcall", &CameraSetFOV);
// Character Controller
RegisterMethod("CharacterControllerComponent.MoveAndSlideIcall", &MoveAndSlide);
@@ -475,6 +526,10 @@ namespace Nuake {
// Navigation Mesh
RegisterMethod("NavMeshVolumeComponent.FindPathIcall", &NavMeshComponentFindPath);
// Audio Emitter
RegisterMethod("AudioEmitterComponent.GetIsPlayingIcall", &AudioEmitterGetIsPlaying);
RegisterMethod("AudioEmitterComponent.SetIsPlayingIcall", &AudioEmitterSetIsPlaying);
}
}

View File

@@ -95,26 +95,38 @@ namespace Nuake
{
auto lineCharNums = String::Split(numbersString[0], ',');
int lineNum = std::stoi(lineCharNums[0]);
int charNum = std::stoi(lineCharNums[1]);
// error message
std::string errMesg = "";
int i = 0;
for (auto s : String::Split(line, ':'))
if (lineCharNums.size() == 1)
{
if (i >= 3)
{
errMesg += s;
}
i++;
CompilationError compilationError;
compilationError.message = "";
compilationError.file = filePath;
compilationError.line = 0;
errors.push_back(compilationError);
}
else
{
int lineNum = std::stoi(lineCharNums[0]);
int charNum = std::stoi(lineCharNums[1]);
CompilationError compilationError;
compilationError.message = errMesg;
compilationError.file = filePath;
compilationError.line = lineNum;
errors.push_back(compilationError);
// error message
std::string errMesg = "";
int i = 0;
for (auto s : String::Split(line, ':'))
{
if (i >= 3)
{
errMesg += s;
}
i++;
}
CompilationError compilationError;
compilationError.message = errMesg;
compilationError.file = filePath;
compilationError.line = lineNum;
errors.push_back(compilationError);
}
}
}
@@ -173,6 +185,7 @@ namespace Nuake
}
Coral::GC::Collect();
Coral::GC::WaitForPendingFinalizers();
GetHostInstance()->UnloadAssemblyLoadContext(m_LoadContext);
@@ -298,23 +311,33 @@ namespace Nuake
m_PrefabType = m_GameAssembly.GetType("Nuake.Net.Prefab");
auto& exposedFieldAttributeType = m_GameAssembly.GetType("Nuake.Net.ExposedAttribute");
auto& brushScriptAttributeType = m_GameAssembly.GetType("Nuake.Net.BrushScript");
auto& pointScriptAttributeType = m_GameAssembly.GetType("Nuake.Net.PointScript");
for (auto& type : m_GameAssembly.GetTypes())
{
// Brush
bool isBrushScript = false;
std::string brushDescription;
bool isTrigger = false;
// Point
bool isPointScript = false;
std::string pointDescription;
for (auto& attribute : type->GetAttributes())
{
if (attribute.GetType() != brushScriptAttributeType)
if (attribute.GetType() == brushScriptAttributeType)
{
continue;
brushDescription = attribute.GetFieldValue<Coral::String>("Description");
isTrigger = attribute.GetFieldValue<Coral::Bool32>("IsTrigger");
isBrushScript = true;
}
brushDescription = attribute.GetFieldValue<Coral::String>("Description");
isTrigger = attribute.GetFieldValue<Coral::Bool32>("IsTrigger");
isBrushScript = true;
if (attribute.GetType() == pointScriptAttributeType)
{
pointDescription = attribute.GetFieldValue<Coral::String>("Description");
isPointScript = true;
}
}
const std::string baseTypeName = std::string(type->GetBaseType().GetFullName());
@@ -395,6 +418,11 @@ namespace Nuake
m_BrushEntityTypes[shortenedTypeName] = gameScriptObject;
}
if (isPointScript)
{
gameScriptObject.Description = pointDescription;
m_PointEntityTypes[shortenedTypeName] = gameScriptObject;
}
m_GameEntityTypes[shortenedTypeName] = gameScriptObject;
}
}

View File

@@ -50,6 +50,7 @@ namespace Nuake {
bool isTrigger = false;
std::string Description = "";
AABB aabb = AABB({0, 0, 0}, { 1, 1, 1 });
};
struct CompilationError
@@ -86,6 +87,7 @@ namespace Nuake {
// This is a map that contains all the instances of entity scripts.
std::unordered_map<std::string, NetGameScriptObject> m_GameEntityTypes;
std::unordered_map<std::string, NetGameScriptObject> m_BrushEntityTypes;
std::unordered_map<std::string, NetGameScriptObject> m_PointEntityTypes;
std::unordered_map<uint32_t, Coral::ManagedObject> m_EntityToManagedObjects;
ScriptingEngineNet();
@@ -126,6 +128,7 @@ namespace Nuake {
Coral::ManagedAssembly GetNuakeAssembly() const { return m_NuakeAssembly; }
std::unordered_map<std::string, NetGameScriptObject> GetBrushEntities() const { return m_BrushEntityTypes; }
std::unordered_map<std::string, NetGameScriptObject> GetPointEntities() const { return m_PointEntityTypes; }
private:
std::string GenerateGUID();
};