Skip to content

Commit

Permalink
Merge branch 'feature/nohavok' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
FoolHen committed Feb 11, 2023
2 parents df0b4cc + 3939425 commit 39bbac7
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,12 @@ export default class HierarchyComponent extends EditorComponent {
this.existingParents.get(parentId)!.push(entry);
} else {
// Entry does not have a parent.
const rootId = gameObject.origin === GAMEOBJECT_ORIGIN.VANILLA ? 'vanilla_root' : 'custom_root';
const rootId =
gameObject.origin === GAMEOBJECT_ORIGIN.VANILLA ||
gameObject.origin == GAMEOBJECT_ORIGIN.NOHAVOK
? 'vanilla_root'
: 'custom_root';
if (!this.existingParents.has(rootId)) {
this.existingParents.set(rootId, []);
}
Expand Down
3 changes: 2 additions & 1 deletion WebUI/src/script/types/Enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export enum MOUSE_BUTTONS {
export enum GAMEOBJECT_ORIGIN {
VANILLA = 1,
CUSTOM = 2,
CUSTOM_CHILD = 3
CUSTOM_CHILD = 3,
NOHAVOK = 4,
}

export enum KEYCODE {
Expand Down
12 changes: 6 additions & 6 deletions ext/Server/FBSettingsManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ local m_Logger = Logger("FBSettingsManager", false)
local function _modifyClientTimeoutSettings(p_Instance)
p_Instance = ClientSettings(p_Instance)
p_Instance:MakeWritable()
p_Instance.loadedTimeout = ME_CONFIG.LOADING_TIMEOUT
p_Instance.loadingTimeout = ME_CONFIG.LOADING_TIMEOUT
p_Instance.ingameTimeout = ME_CONFIG.LOADING_TIMEOUT
p_Instance.loadedTimeout = math.max(ME_CONFIG.LOADING_TIMEOUT, p_Instance.loadedTimeout or 0)
p_Instance.loadingTimeout = math.max(ME_CONFIG.LOADING_TIMEOUT, p_Instance.loadingTimeout or 0)
p_Instance.ingameTimeout = math.max(ME_CONFIG.LOADING_TIMEOUT, p_Instance.ingameTimeout or 0)
m_Logger:Write("Changed ClientSettings")
end

local function _modifyServerTimeoutSettings(p_Instance)
p_Instance = ServerSettings(p_Instance)
p_Instance:MakeWritable()
p_Instance.loadingTimeout = ME_CONFIG.LOADING_TIMEOUT
p_Instance.ingameTimeout = ME_CONFIG.LOADING_TIMEOUT
p_Instance.timeoutTime = ME_CONFIG.LOADING_TIMEOUT
p_Instance.loadingTimeout = math.max(ME_CONFIG.LOADING_TIMEOUT, p_Instance.loadingTimeout or 0)
p_Instance.ingameTimeout = math.max(ME_CONFIG.LOADING_TIMEOUT, p_Instance.ingameTimeout or 0)
p_Instance.timeoutTime = math.max(ME_CONFIG.LOADING_TIMEOUT, p_Instance.timeoutTime or 0)
m_Logger:Write("Changed ServerSettings")
end

Expand Down
5 changes: 3 additions & 2 deletions ext/Server/ProjectManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,9 @@ function ProjectManager:CreateAndExecuteImitationCommands(p_ProjectSaveData)

local s_Command

-- Vanilla objects are handled in maploader
if l_GameObjectSaveData.origin == GameObjectOriginType.Vanilla then
-- Vanilla and nohavok objects are handled in levelloader
if l_GameObjectSaveData.origin == GameObjectOriginType.Vanilla or
l_GameObjectSaveData.origin == GameObjectOriginType.NoHavok then
if l_GameObjectSaveData.isDeleted then
s_Command = {
guid = s_Guid,
Expand Down
3 changes: 2 additions & 1 deletion ext/Shared/Enums/Enums.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ RaycastType = {
GameObjectOriginType = {
Vanilla = 1,
Custom = 2,
CustomChild = 3
CustomChild = 3,
NoHavok = 4
}

---@class EditorMode
Expand Down
3 changes: 2 additions & 1 deletion ext/Shared/Modules/CommandActions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ function CommandActions:UndeleteGameObject(p_Command, p_UpdatePass)

m_Logger:Write("UndeleteGameObject with guid " .. p_Command.gameObjectTransferData.guid)

if SanitizeEnum(p_Command.gameObjectTransferData.origin) ~= GameObjectOriginType.Vanilla then
if SanitizeEnum(p_Command.gameObjectTransferData.origin) == GameObjectOriginType.Custom or
SanitizeEnum(p_Command.gameObjectTransferData.origin) == GameObjectOriginType.CustomChild then
return CommandActions:SpawnGameObject(p_Command, p_UpdatePass)
end

Expand Down
70 changes: 46 additions & 24 deletions ext/Shared/Modules/GameObjectManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ end
---@param p_Overrides table
function GameObjectManager:InvokeBlueprintSpawn(p_GameObjectGuid, p_SenderName, p_BlueprintPartitionGuid, p_BlueprintInstanceGuid, p_ParentData, p_LinearTransform, p_Variation, p_IsPreviewSpawn, p_Overrides)
if p_BlueprintPartitionGuid == nil or
p_BlueprintInstanceGuid == nil or
p_LinearTransform == nil then
p_BlueprintInstanceGuid == nil or
p_LinearTransform == nil then
m_Logger:Error('InvokeBlueprintSpawn: One or more parameters are nil.')

return false
Expand All @@ -68,7 +68,7 @@ function GameObjectManager:InvokeBlueprintSpawn(p_GameObjectGuid, p_SenderName,
if p_IsPreviewSpawn == false then
self.m_PendingCustomBlueprintGuids[p_BlueprintInstanceGuid] = { customGuid = p_GameObjectGuid, creatorName = p_SenderName, parentData = p_ParentData, overrides = p_Overrides }
else
local s_PreviewSpawnParentData = GameObjectParentData{
local s_PreviewSpawnParentData = GameObjectParentData {
guid = EMPTY_GUID, -- Root
typeName = "previewSpawn",
}
Expand Down Expand Up @@ -154,10 +154,10 @@ function GameObjectManager:OnEntityCreateFromBlueprint(p_HookCtx, p_Blueprint, p
end

---@type GameObject
local s_GameObject = GameObject{
local s_GameObject = GameObject {
guid = GenerateTempGuid(), -- we set a tempGuid, it will later be set to a vanilla or custom guid
name = s_Blueprint.name,
parentData = GameObjectParentData{},
parentData = GameObjectParentData {},
transform = p_Transform,
variation = s_Variation,
origin = GameObjectOriginType.Vanilla,
Expand Down Expand Up @@ -210,7 +210,7 @@ function GameObjectManager:OnEntityCreateFromBlueprint(p_HookCtx, p_Blueprint, p
end
else
if s_PendingCustomBlueprintInfo == nil then
m_Logger:Write('Found vanilla object without parent. Name: '..tostring(s_Blueprint.name)..', Guid: '..tostring(s_Blueprint.instanceGuid)) -- TODO: do we need to add these objects?
m_Logger:Write('Found vanilla object without parent. Name: ' .. tostring(s_Blueprint.name) .. ', Guid: ' .. tostring(s_Blueprint.instanceGuid)) -- TODO: do we need to add these objects?
-- Ignore, these are usually weapons and soldier entities, which we dont support (at least for now)
self:ResolveRootObject(s_GameObject, s_PendingCustomBlueprintInfo)
else
Expand Down Expand Up @@ -251,7 +251,7 @@ function GameObjectManager:OnEntityCreateFromBlueprint(p_HookCtx, p_Blueprint, p
---vvvv This is children to parent / bottom to top vvvv

-- Custom object have to be manually initialized.
if not s_GameObject.origin == GameObjectOriginType.Vanilla then
if s_GameObject.origin == GameObjectOriginType.Custom or s_GameObject.origin == GameObjectOriginType.CustomChild then
for _, l_Entity in pairs(s_EntityBus.entities) do
-- TODO: find out if the blueprint is client or server only and init in correct realm, maybe Realm_ClientAndServer otherwise.
l_Entity:Init(self.m_Realm, true)
Expand All @@ -272,7 +272,7 @@ function GameObjectManager:OnEntityCreateFromBlueprint(p_HookCtx, p_Blueprint, p
s_GameEntity = self.m_PendingEntities[l_Entity.instanceId]
if s_GameEntity == nil then
---@type GameEntity
s_GameEntity = GameEntity{
s_GameEntity = GameEntity {
entity = l_Entity,
instanceId = l_Entity.instanceId,
typeName = l_Entity.typeInfo.name,
Expand Down Expand Up @@ -318,9 +318,9 @@ function GameObjectManager:OnEntityCreateFromBlueprint(p_HookCtx, p_Blueprint, p
-- TODO: update blueprint data with the correct realm if its client or server only
if self.m_Realm == Realm.Realm_Server then
m_Logger:Write(s_UnresolvedRODCount .. ' client-only gameobjects weren\'t resolved')
-- for l_Guid, l_Value in pairs(self.m_ReferenceObjectDatas) do
-- m_Logger:Write(tostring(l_Guid) .. ', '..l_Value.typeName)
-- end
-- for l_Guid, l_Value in pairs(self.m_ReferenceObjectDatas) do
-- m_Logger:Write(tostring(l_Guid) .. ', '..l_Value.typeName)
-- end
elseif self.m_Realm == Realm.Realm_Client then
m_Logger:Write(s_UnresolvedRODCount .. ' server-only gameobjects weren\'t resolved')
-- for l_Guid, l_Value in pairs(self.m_ReferenceObjectDatas) do
Expand Down Expand Up @@ -361,29 +361,37 @@ function GameObjectManager:ResolveRootObject(p_GameObject, p_PendingInfo)
self.m_GameObjects[tostring(p_GameObject.guid)] = nil -- Remove temp guid from array

if p_PendingInfo then -- We spawned this custom entitybus
p_GameObject.parentData = GameObjectParentData{
p_GameObject.parentData = GameObjectParentData {
guid = p_PendingInfo.parentData.guid,
typeName = p_PendingInfo.parentData.typeName,
primaryInstanceGuid = p_PendingInfo.parentData.primaryInstanceGuid,
partitionGuid = p_PendingInfo.parentData.partitionGuid
}
p_GameObject.guid = Guid(p_PendingInfo.customGuid)
p_GameObject.origin = GameObjectOriginType.Custom
else -- This is a vanilla root object
p_GameObject.guid = self:GetVanillaGuid(p_GameObject.name, p_GameObject.transform.trans)
p_GameObject.origin = GameObjectOriginType.Vanilla
else

--table.insert(self.m_VanillaGameObjectGuids, p_GameObject.guid)
self.m_VanillaGameObjectGuids[tostring(p_GameObject.guid)] = p_GameObject.guid
if string.find(p_GameObject.blueprintCtrRef.name:lower(), "nohavok") then
local s_BundleName = p_GameObject.blueprintCtrRef.name:gsub('NoHavok_', '')
p_GameObject.origin = GameObjectOriginType.NoHavok
-- No parent data, add the bundle name as an offset and use a predefined havok guid
p_GameObject.guid = self:GetNoHavokGuid(HAVOK_GUID, s_BundleName .. '/' .. p_GameObject.name, p_GameObject.transform.trans)
else
-- This is a vanilla root object
p_GameObject.guid = self:GetVanillaGuid(p_GameObject.name, p_GameObject.transform.trans)
p_GameObject.origin = GameObjectOriginType.Vanilla

--table.insert(self.m_VanillaGameObjectGuids, p_GameObject.guid)
self.m_VanillaGameObjectGuids[tostring(p_GameObject.guid)] = p_GameObject.guid
end
end

self.m_GameObjects[tostring(p_GameObject.guid)] = p_GameObject
end

function GameObjectManager:ResolveChildObject(p_GameObject, p_ParentGameObject)
-- This is a child of either a custom gameObject or a vanilla gameObject, find the parent!
p_GameObject.parentData = GameObjectParentData{
p_GameObject.parentData = GameObjectParentData {
guid = p_ParentGameObject.guid,
typeName = p_ParentGameObject.blueprintCtrRef.typeName,
primaryInstanceGuid = p_ParentGameObject.blueprintCtrRef.instanceGuid,
Expand All @@ -401,6 +409,8 @@ function GameObjectManager:ResolveChildObject(p_GameObject, p_ParentGameObject)
p_GameObject.guid = self:GetVanillaGuid(p_GameObject.name, p_GameObject.transform.trans)
--table.insert(self.m_VanillaGameObjectGuids, p_GameObject.guid)
self.m_VanillaGameObjectGuids[tostring(p_GameObject.guid)] = p_GameObject.guid
elseif p_GameObject.origin == GameObjectOriginType.NoHavok then
p_GameObject.guid = self:GetNoHavokGuid(p_GameObject.parentData.guid, p_GameObject.name, p_GameObject.transform.trans)
else
local i = 1
local s_CustomGuid
Expand Down Expand Up @@ -457,6 +467,18 @@ function GameObjectManager:GetVanillaGuid(p_Name, p_Transform)
return s_VanillaGuid
end

function GameObjectManager:GetNoHavokGuid(p_ParentGuid, p_Name, p_Transform)
local s_NewGuid = GenerateNoHavokGuid(p_ParentGuid, p_Name, p_Transform, 0)
local s_Increment = 1

while self.m_GameObjects[tostring(s_NewGuid)] ~= nil do
s_NewGuid = GenerateNoHavokGuid(p_ParentGuid, p_Name, p_Transform, s_Increment)
s_Increment = s_Increment + 1
end

return s_NewGuid
end

function GameObjectManager:DeleteGameObject(p_Guid)
local s_GameObject = self.m_GameObjects[tostring(p_Guid)]

Expand All @@ -470,7 +492,7 @@ function GameObjectManager:DeleteGameObject(p_Guid)
return true
end

if s_GameObject.origin == GameObjectOriginType.Vanilla then
if s_GameObject.origin == GameObjectOriginType.Vanilla or s_GameObject.origin == GameObjectOriginType.NoHavok then
s_GameObject:MarkAsDeleted()
else
s_GameObject:Destroy()
Expand All @@ -492,7 +514,7 @@ function GameObjectManager:UndeleteGameObject(p_Guid)
m_Logger:Error("GameObject was not marked as deleted before undeleting: " .. p_Guid)
return false
end
if s_GameObject.origin ~= GameObjectOriginType.Vanilla then
if s_GameObject.origin ~= GameObjectOriginType.Vanilla and s_GameObject.origin ~= GameObjectOriginType.NoHavok then
m_Logger:Error("GameObject was not a vanilla object " .. p_Guid)
return false
end
Expand Down Expand Up @@ -572,7 +594,7 @@ function GameObjectManager:OnEntityCreate(p_Hook, p_EntityData, p_Transform)
end

---@type GameEntity
s_GameEntity = GameEntity{
s_GameEntity = GameEntity {
entity = s_Entity,
instanceId = s_Entity.instanceId,
typeName = s_Entity.typeInfo.name,
Expand Down Expand Up @@ -600,9 +622,9 @@ function GameObjectManager:OnEntityCreate(p_Hook, p_EntityData, p_Transform)

-- Set custom objects' entities enabled by default. This can't be done in CreateEntitiesFromBlueprint, for
-- some reason it doesn't work
if s_PendingGameObject.origin ~= GameObjectOriginType.Vanilla and
(s_Entity:Is('GameEntity') or s_Entity:Is('EffectEntity')) and
s_Entity.typeInfo.name ~= "ServerVehicleEntity" then
if (s_PendingGameObject.origin == GameObjectOriginType.Custom or s_PendingGameObject.origin == GameObjectOriginType.CustomChild) and
(s_Entity:Is('GameEntity') or s_Entity:Is('EffectEntity')) and
s_Entity.typeInfo.name ~= "ServerVehicleEntity" then
-- Small delay before firing an event, otherwise it may crash
Timer:Simple(0.2, function()
s_GameEntity:Enable()
Expand Down
8 changes: 4 additions & 4 deletions ext/Shared/Types/GameObject.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function GameObject:SetField(p_FieldName, p_NewValue, p_AutoModified)
end

function GameObject:IsUserModified()
if self.origin ~= GameObjectOriginType.Vanilla then
if self.origin == GameObjectOriginType.Custom or self.origin == GameObjectOriginType.CustomChild then
return true
end

Expand Down Expand Up @@ -107,7 +107,7 @@ function GameObject:Enable(p_AutoModified)
end

function GameObject:MarkAsDeleted(p_AutoModified)
if self.origin ~= GameObjectOriginType.Vanilla then
if self.origin == GameObjectOriginType.Custom or self.origin == GameObjectOriginType.CustomChild then
m_Logger:Error("Cant delete a non-vanilla object, use destroy instead")
return
end
Expand All @@ -130,7 +130,7 @@ function GameObject:MarkAsDeleted(p_AutoModified)
end

function GameObject:MarkAsUndeleted(p_AutoModified)
if self.origin ~= GameObjectOriginType.Vanilla then
if self.origin == GameObjectOriginType.Custom or self.origin == GameObjectOriginType.CustomChild then
m_Logger:Error("Cant undelete a non-vanilla object, use spawn instead")
return
end
Expand All @@ -153,7 +153,7 @@ function GameObject:MarkAsUndeleted(p_AutoModified)
end

function GameObject:Destroy() -- this will effectively destroy all entities and childentities. the gameobject becomes useless and needs to be dereferenced
if self.origin == GameObjectOriginType.Vanilla then
if self.origin == GameObjectOriginType.Vanilla or self.origin == GameObjectOriginType.NoHavok then
m_Logger:Error("Cant destroy vanilla object, use disable instead")
return
end
Expand Down
Loading

0 comments on commit 39bbac7

Please sign in to comment.