Skip to content

Commit 92af2ef

Browse files
committed
Added Scripting Dependency to Game-Lib
Removed unused Character Controller code Reduced Target Highlight Intensity from 1.50 to 1.25 Fixed an issue where CameraSaves would fail to load Implemented Handling for CreatureInfo Cheat Command Fixed an issue where Text Max Width would incorrectly fail to calculate when Text already had newlines Improved GameConsole Command suggestions sorting Improved ModelLoader with respect to loading order and reporting loading progress Updated all scripts to match the new event data structure Implemented new Zenith Scripting Functionality Added a global Zenith State Added Scripting EventHandler, all events are registered through a "RegisterEvent" lua function now Removed the Concept of LuaEventHandlerBase and LuaSystemBase Added Scripting ZenithUtil to simplify fetching the Global Zenith Updated Submodule Engine
1 parent 4238bbf commit 92af2ef

File tree

83 files changed

+1830
-5243
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1830
-5243
lines changed

Source/Game-Lib/Game-Lib.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- Dependencies are order sensitive on Linux, keep that in mind when adding new dependencies.
2-
local mod = Solution.Util.CreateModuleTable("Game-Lib", { "renderer", "fileformat", "gameplay", "input", "meta", "luau-analysis", "luau-compiler", "luau-vm", "luau-codegen", "enkits", "utfcpp", "base64", "jolt" })
2+
local mod = Solution.Util.CreateModuleTable("Game-Lib", { "renderer", "fileformat", "scripting", "gameplay", "input", "meta", "luau-analysis", "luau-compiler", "luau-vm", "luau-codegen", "enkits", "utfcpp", "base64", "jolt" })
33

44
Solution.Util.CreateStaticLib(mod.Name, Solution.Projects.Current.BinDir, mod.Dependencies, function()
55
local defines = { "_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS", "_SILENCE_ALL_MS_EXT_DEPRECATION_WARNINGS"}

Source/Game-Lib/Game-Lib/Application/Application.cpp

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@
2121
#include "Game-Lib/Editor/EditorHandler.h"
2222
#include "Game-Lib/Gameplay/GameConsole/GameConsole.h"
2323
#include "Game-Lib/Rendering/GameRenderer.h"
24-
#include "Game-Lib/Scripting/LuaManager.h"
25-
#include "Game-Lib/Scripting/Systems/LuaSystemBase.h"
24+
#include "Game-Lib/Scripting/Handlers/GlobalHandler.h"
25+
#include "Game-Lib/Scripting/Handlers/EventHandler.h"
26+
#include "Game-Lib/Scripting/Handlers/DatabaseHandler.h"
27+
#include "Game-Lib/Scripting/Handlers/UIHandler.h"
28+
#include "Game-Lib/Scripting/Handlers/GameHandler.h"
29+
#include "Game-Lib/Scripting/Handlers/UnitHandler.h"
2630
#include "Game-Lib/Util/ClientDBUtil.h"
2731
#include "Game-Lib/Util/ServiceLocator.h"
2832
#include "Game-Lib/Util/TextureUtil.h"
@@ -34,8 +38,13 @@
3438
#include <Base/Util/DebugHandler.h>
3539
#include <Base/Util/CPUInfo.h>
3640

41+
#include <Meta/Generated/Game/LuaEnum.h>
42+
3743
#include <Network/Client.h>
3844

45+
#include <Scripting/LuaManager.h>
46+
#include <Scripting/Zenith.h>
47+
3948
#include <enkiTS/TaskScheduler.h>
4049
#include <entt/entt.hpp>
4150
#include <imgui/backends/imgui_impl_vulkan.h>
@@ -328,8 +337,22 @@ bool Application::Init()
328337
// Initialize Databases
329338
DatabaseReload();
330339

331-
_luaManager = new Scripting::LuaManager();
332-
ServiceLocator::SetLuaManager(_luaManager);
340+
// Init Lua Manager
341+
{
342+
_luaManager = new Scripting::LuaManager();
343+
ServiceLocator::SetLuaManager(_luaManager);
344+
345+
_luaManager->PrepareToAddLuaHandlers((Scripting::LuaHandlerID)Generated::LuaHandlerTypeEnum::Count);
346+
_luaManager->SetLuaHandler((Scripting::LuaHandlerID)Generated::LuaHandlerTypeEnum::Global, new Scripting::GlobalHandler());
347+
_luaManager->SetLuaHandler((Scripting::LuaHandlerID)Generated::LuaHandlerTypeEnum::Event, new Scripting::EventHandler());
348+
_luaManager->SetLuaHandler((Scripting::LuaHandlerID)Generated::LuaHandlerTypeEnum::Database, new Scripting::Database::DatabaseHandler());
349+
_luaManager->SetLuaHandler((Scripting::LuaHandlerID)Generated::LuaHandlerTypeEnum::UI, new Scripting::UI::UIHandler());
350+
_luaManager->SetLuaHandler((Scripting::LuaHandlerID)Generated::LuaHandlerTypeEnum::Game, new Scripting::Game::GameHandler());
351+
_luaManager->SetLuaHandler((Scripting::LuaHandlerID)Generated::LuaHandlerTypeEnum::Unit, new Scripting::Unit::UnitHandler());
352+
353+
auto globalKey = Scripting::ZenithInfoKey::MakeGlobal(0, 0);
354+
_luaManager->GetZenithStateManager().Add(globalKey);
355+
}
333356
_luaManager->Init();
334357

335358
return true;
@@ -373,7 +396,10 @@ bool Application::Tick(f32 deltaTime)
373396

374397
case MessageInbound::Type::DoString:
375398
{
376-
if (!ServiceLocator::GetLuaManager()->DoString(message.data))
399+
auto key = Scripting::ZenithInfoKey::MakeGlobal(0, 0);
400+
Scripting::Zenith* zenith = _luaManager->GetZenithStateManager().Get(key);
401+
402+
if (!zenith || !_luaManager->DoString(zenith, message.data))
377403
{
378404
NC_LOG_ERROR("Failed to run Lua DoString");
379405
}

Source/Game-Lib/Game-Lib/ECS/Systems/CharacterController.cpp

Lines changed: 1 addition & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ namespace ECS::Systems
273273
if (registry->all_of<Components::Model>(targetEntity))
274274
{
275275
auto& model = registry->get<Components::Model>(targetEntity);
276-
modelLoader->SetModelHighlight(model, 1.5f);
276+
modelLoader->SetModelHighlight(model, 1.25f);
277277
}
278278
}
279279

@@ -374,190 +374,6 @@ namespace ECS::Systems
374374
return true;
375375
});
376376
}
377-
378-
#if USE_CHARACTER_CONTROLLER_V2
379-
void CharacterController::Update(entt::registry& registry, f32 deltaTime)
380-
{
381-
InputManager* inputManager = ServiceLocator::GetInputManager();
382-
KeybindGroup* keybindGroup = inputManager->GetKeybindGroupByHash("CharacterController"_h);
383-
384-
Util::EventUtil::OnEvent<Components::MapLoadedEvent>([&](const Components::MapLoadedEvent& event)
385-
{
386-
InitCharacterController(registry);
387-
});
388-
389-
if (!keybindGroup->IsActive())
390-
return;
391-
392-
entt::registry::context& ctx = registry.ctx();
393-
auto& orbitalCameraSettings = ctx.get<Singletons::OrbitalCameraSettings>();
394-
bool isInputForwardDown = keybindGroup->IsKeybindPressed("Forward"_h) || (orbitalCameraSettings.mouseLeftDown && orbitalCameraSettings.mouseRightDown);
395-
bool isInputBackwardDown = keybindGroup->IsKeybindPressed("Backward"_h);
396-
bool isInputLeftDown = keybindGroup->IsKeybindPressed("Left"_h);
397-
bool isInputRightDown = keybindGroup->IsKeybindPressed("Right"_h);
398-
399-
bool isMovingForward = (isInputForwardDown && !isInputBackwardDown);
400-
bool isMovingBackward = (isInputBackwardDown && !isInputForwardDown);
401-
bool isMovingLeft = (isInputLeftDown && !isInputRightDown);
402-
bool isMovingRight = (isInputRightDown && !isInputLeftDown);
403-
bool isMoving = isMovingForward || isMovingBackward || isMovingLeft || isMovingRight;
404-
405-
auto& characterSingleton = ctx.get<Singletons::CharacterSingleton>();
406-
auto& characterMovementInfo = registry.get<Components::MovementInfo>(characterSingleton.modelEntity);
407-
auto& characterModelTransform = registry.get<Components::Transform>(characterSingleton.modelEntity);
408-
409-
DebugRenderer* debugRenderer = ServiceLocator::GetGameRenderer()->GetDebugRenderer();
410-
auto& transformSystem = TransformSystem::Get(registry);
411-
auto& joltState = ctx.get<Singletons::JoltState>();
412-
static vec3 Gravity = vec3(0.0f, -19.291105f, 0.0f);
413-
414-
quat characterRotation = quat(vec3(characterMovementInfo.pitch, characterMovementInfo.yaw, 0.0f));
415-
transformSystem.SetWorldRotation(characterSingleton.modelEntity, characterRotation);
416-
417-
vec3 characterModelStartPosition = characterModelTransform.GetWorldPosition();
418-
vec3 characterModelEndPosition = characterModelStartPosition;
419-
quat characterModelRotation = characterModelTransform.GetWorldRotation();
420-
421-
vec3 horizontalMoveVector = vec3((isMovingLeft * 1.0f) + (isMovingRight * -1.0f), 0.0f, (isMovingForward * -1.0f) + (isMovingBackward * 1.0f));
422-
vec3 horizontalVelocity = vec3(0.0f);
423-
if (isMoving)
424-
{
425-
horizontalMoveVector = glm::normalize(horizontalMoveVector);
426-
}
427-
428-
bool wasGrounded = characterMovementInfo.movementFlags.grounded;
429-
bool isGrounded = false;
430-
431-
// Check if we are still grounded
432-
if (wasGrounded)
433-
{
434-
vec3 rayStart = characterModelStartPosition + Components::Transform::WORLD_UP;
435-
vec3 rayDirection = -Components::Transform::WORLD_UP * 2.0f;
436-
JPH::RayCastResult hitResult;
437-
438-
if (::Util::Physics::CastRay(joltState.physicsSystem, rayStart, rayDirection, hitResult))
439-
{
440-
if (hitResult.mFraction <= 0.51f)
441-
{
442-
vec3 hitPos = rayStart + (hitResult.mFraction * rayDirection);
443-
444-
characterModelStartPosition = hitPos;
445-
isGrounded = true;
446-
447-
if (isMoving)
448-
{
449-
if (JPH::Body* body = joltState.physicsSystem.GetBodyLockInterface().TryGetBody(hitResult.mBodyID))
450-
{
451-
JPH::Vec3 surfaceNormal = body->GetWorldSpaceSurfaceNormal(hitResult.mSubShapeID2, JPH::Vec3(characterModelStartPosition.x, characterModelStartPosition.y, characterModelStartPosition.z));
452-
vec3 surfaceNormalVec = glm::normalize(vec3(surfaceNormal.GetX(), surfaceNormal.GetY(), surfaceNormal.GetZ()));
453-
454-
vec3 localForward = glm::normalize(characterModelTransform.GetLocalForward());
455-
vec3 rightVec = glm::normalize(glm::cross(surfaceNormalVec, localForward));
456-
vec3 forwardVec = glm::normalize(glm::cross(rightVec, surfaceNormalVec));
457-
458-
// Draw Surface Normal, RightVec, ForwardVec
459-
debugRenderer->DrawLine3D(hitPos, hitPos + surfaceNormalVec, Color::Green);
460-
debugRenderer->DrawLine3D(characterModelStartPosition, characterModelStartPosition + rightVec, Color::Red);
461-
debugRenderer->DrawLine3D(characterModelStartPosition, characterModelStartPosition + forwardVec, Color::Blue);
462-
463-
horizontalVelocity = forwardVec * horizontalMoveVector.z + rightVec * horizontalMoveVector.x;
464-
};
465-
}
466-
}
467-
}
468-
}
469-
470-
if (isGrounded)
471-
{
472-
if (isMoving)
473-
{
474-
vec3 velocity = horizontalVelocity * characterMovementInfo.speed;
475-
vec3 verticalVelocity = vec3(0.0f, 0.0f, 0.0f);
476-
477-
vec3 horizontalMove = velocity * deltaTime;
478-
479-
vec3 rayStart = characterModelStartPosition + Components::Transform::WORLD_UP;
480-
vec3 rayDirection = horizontalMove;
481-
JPH::RayCastResult hitResult;
482-
483-
if (::Util::Physics::CastRay(joltState.physicsSystem, rayStart, rayDirection, hitResult))
484-
{
485-
vec3 hitPos = rayStart + (hitResult.mFraction * rayDirection);
486-
characterModelEndPosition = hitPos;
487-
}
488-
else
489-
{
490-
characterModelEndPosition = characterModelStartPosition + horizontalMove;
491-
}
492-
}
493-
}
494-
else
495-
{
496-
vec3 gravityDirection = Gravity * deltaTime;
497-
498-
JPH::Vec3 start = JPH::Vec3(characterModelStartPosition.x, characterModelStartPosition.y + 1.0f, characterModelStartPosition.z);
499-
JPH::Vec3 direction = JPH::Vec3(gravityDirection.x, gravityDirection.y + -1.0f, gravityDirection.z);
500-
501-
JPH::RRayCast ray(start, direction);
502-
JPH::RayCastResult hit;
503-
504-
if (joltState.physicsSystem.GetNarrowPhaseQuery().CastRay(ray, hit))
505-
{
506-
JPH::Vec3 hitPos = ray.GetPointOnRay(hit.mFraction);
507-
vec3 hitPosition = vec3(hitPos.GetX(), hitPos.GetY(), hitPos.GetZ());
508-
509-
characterModelEndPosition = hitPosition;
510-
isGrounded = true;
511-
}
512-
else
513-
{
514-
characterModelEndPosition = characterModelStartPosition + gravityDirection;
515-
}
516-
}
517-
518-
characterMovementInfo.movementFlags.grounded = isGrounded;
519-
transformSystem.SetWorldPosition(characterSingleton.entity, characterModelEndPosition);
520-
}
521-
522-
void CharacterController::InitCharacterController(entt::registry& registry)
523-
{
524-
entt::registry::context& ctx = registry.ctx();
525-
526-
auto& characterSingleton = ctx.get<Singletons::CharacterSingleton>();
527-
auto& movementInfo = registry.get<Components::MovementInfo>(characterSingleton.modelEntity);
528-
529-
ModelLoader* modelLoader = ServiceLocator::GetGameRenderer()->GetModelLoader();
530-
modelLoader->LoadDisplayIDForEntity(characterSingleton.modelEntity, 50);
531-
532-
MapLoader* mapLoader = ServiceLocator::GetGameRenderer()->GetMapLoader();
533-
JPH::Vec3 newPosition = JPH::Vec3(-1500.0f, 350.0f, 1250.0f);
534-
535-
if (mapLoader->GetCurrentMapID() == std::numeric_limits<u32>().max())
536-
{
537-
newPosition = JPH::Vec3(0.0f, 0.0f, 0.0f);
538-
}
539-
540-
characterSingleton.targetEntity = entt::null;
541-
characterSingleton.positionOrRotationUpdateTimer = 0.0f;
542-
characterSingleton.positionOrRotationIsDirty = true;
543-
characterSingleton.canControlInAir = true;
544-
545-
movementInfo.pitch = 0.0f;
546-
movementInfo.yaw = 0.0f;
547-
movementInfo.speed = 7.1111f;
548-
movementInfo.jumpSpeed = 7.9555f;
549-
movementInfo.gravityModifier = 1.0f;
550-
movementInfo.jumpState = Components::JumpState::None;
551-
552-
auto& transformSystem = ctx.get<TransformSystem>();
553-
auto& orbitalCameraSettings = ctx.get<Singletons::OrbitalCameraSettings>();
554-
555-
transformSystem.ParentEntityTo(characterSingleton.entity, orbitalCameraSettings.entity);
556-
transformSystem.SetLocalPosition(orbitalCameraSettings.entity, orbitalCameraSettings.cameraCurrentZoomOffset);
557-
transformSystem.SetWorldPosition(characterSingleton.entity, vec3(newPosition.GetX(), newPosition.GetY(), newPosition.GetZ()));
558-
}
559-
560-
#else
561377
void CharacterController::Update(entt::registry& registry, f32 deltaTime)
562378
{
563379
ZoneScopedN("ECS::CharacterController::Preprocessing");
@@ -968,5 +784,4 @@ namespace ECS::Systems
968784
characterSingleton.moverEntity = entt::null;
969785
}
970786
}
971-
#endif
972787
}

0 commit comments

Comments
 (0)