From f1e77dc3d9ce929ced9982d07d8fbb53bad5bca3 Mon Sep 17 00:00:00 2001 From: Anton Tarasenko Date: Fri, 29 Oct 2021 03:00:39 +0700 Subject: [PATCH] Refactor to do clean up and use signals/slots I shamefully ended up doing another mega-commit, because a lot of things needed to be redone at once and it was easier that way on me. No one really consistently tracks what I'm doing with these commits anyway. This adds a whole bunch of code to deal with proper clean up for Acedia, so it doesn't crash on map change and also replaces old event/listener system with new signals/slots one. --- sources/Aliases/AliasSource.uc | 7 + .../Commands/BroadcastListener_Commands.uc | 66 --- .../Commands/BuiltInCommands/ACommandTest.uc | 72 +++ sources/Commands/Command.uc | 41 ++ sources/Commands/Commands.uc | 1 + sources/Commands/Commands_Feature.uc | 39 +- sources/Config/AcediaConfig.uc | 10 + sources/CoreService.uc | 264 +++++++++- sources/Data/Collections/AssociativeArray.uc | 113 ++-- sources/Data/Collections/Collection.uc | 2 +- .../Database/Local/LocalDatabaseInstance.uc | 3 + sources/Events/Broadcast/BroadcastEvents.uc | 134 ----- .../Broadcast/BroadcastEventsObserver.uc | 341 ------------- .../Events/Broadcast/BroadcastListenerBase.uc | 175 ------- sources/Events/Events.uc | 161 ------ sources/Events/Listener.uc | 59 --- sources/Events/Mutator/MutatorEvents.uc | 56 -- sources/Events/Mutator/MutatorListenerBase.uc | 47 -- sources/Events/Signal.uc | 36 +- sources/Features/Feature.uc | 23 +- sources/Features/FeatureConfig.uc | 2 +- .../BaseClasses/KillingFloor/KFFrontend.uc | 3 +- .../KillingFloor/Trading/ATradingComponent.uc | 3 + .../KF1Frontend/Trading/KF1_Trader.uc | 2 + .../Trading/KF1_TradingComponent.uc | 2 + sources/Global.uc | 28 + sources/Logger/ConsoleLogger.uc | 6 + sources/Logger/LogMessage.uc | 13 +- sources/Logger/Logger.uc | 23 +- sources/Logger/LoggerAPI.uc | 3 +- sources/Service.uc | 26 +- sources/ServiceAnchor.uc | 25 + sources/Singleton.uc | 9 +- sources/Testing/Service/TestingEvents.uc | 66 --- .../Testing/Service/TestingListenerBase.uc | 34 -- sources/Testing/Service/TestingService.uc | 32 +- sources/Text/JSON/JSONAPI.uc | 2 +- sources/Types/AcediaActor.uc | 17 + sources/Types/AcediaObject.uc | 3 + sources/Unreal/BroadcastsAPI/BroadcastAPI.uc | 398 +++++++++++++++ .../BroadcastsAPI/BroadcastEventsObserver.uc | 483 ++++++++++++++++++ .../Broadcast_OnBroadcastCheck_Signal.uc | 46 ++ .../Events/Broadcast_OnBroadcastCheck_Slot.uc | 41 ++ .../Broadcast_OnHandleLocalizedFor_Signal.uc | 51 ++ .../Broadcast_OnHandleLocalizedFor_Slot.uc | 46 ++ .../Broadcast_OnHandleLocalized_Signal.uc | 50 ++ .../Broadcast_OnHandleLocalized_Slot.uc | 44 ++ .../Broadcast_OnHandleTextFor_Signal.uc | 50 ++ .../Events/Broadcast_OnHandleTextFor_Slot.uc | 45 ++ .../Events/Broadcast_OnHandleText_Signal.uc | 50 ++ .../Events/Broadcast_OnHandleText_Slot.uc | 45 ++ .../Connections}/ConnectionService.uc | 32 +- .../Connections}/Events/Connection_Signal.uc | 0 .../Connections}/Events/Connection_Slot.uc | 0 .../MutatorListener_Connection.uc | 3 +- .../AcediaGameRules.uc | 73 ++- .../Events/GameRules_OnCheckEndGame_Signal.uc | 0 .../Events/GameRules_OnCheckEndGame_Slot.uc | 0 .../Events/GameRules_OnCheckScore_Signal.uc | 3 +- .../Events/GameRules_OnCheckScore_Slot.uc | 0 .../GameRules_OnFindPlayerStart_Signal.uc | 0 .../GameRules_OnFindPlayerStart_Slot.uc | 0 .../GameRules_OnHandleRestartGame_Signal.uc | 0 .../GameRules_OnHandleRestartGame_Slot.uc | 0 .../Events/GameRules_OnNetDamage_Signal.uc | 0 .../Events/GameRules_OnNetDamage_Slot.uc | 0 .../GameRules_OnOverridePickupQuery_Signal.uc | 0 .../GameRules_OnOverridePickupQuery_Slot.uc | 0 .../Events/GameRules_OnPreventDeath_Signal.uc | 51 ++ .../Events/GameRules_OnPreventDeath_Slot.uc | 47 ++ .../Events/GameRules_OnScoreKill_Signal.uc | 38 ++ .../Events/GameRules_OnScoreKill_Slot.uc | 40 ++ .../GameRulesAPI.uc | 131 +++-- .../Mutator_OnCheckReplacement_Signal.uc | 46 ++ .../Events/Mutator_OnCheckReplacement_Slot.uc | 41 ++ .../Events/Mutator_OnMutate_Signal.uc | 38 ++ .../Events/Mutator_OnMutate_Slot.uc | 40 ++ sources/Unreal/MutatorsAPI/MutatorAPI.uc | 92 ++++ sources/Unreal/UnrealAPI.uc | 13 +- sources/Unreal/UnrealService.uc | 53 +- sources/Users/UserDatabase.uc | 7 +- 81 files changed, 2726 insertions(+), 1320 deletions(-) delete mode 100644 sources/Commands/BroadcastListener_Commands.uc create mode 100644 sources/Commands/BuiltInCommands/ACommandTest.uc delete mode 100644 sources/Events/Broadcast/BroadcastEvents.uc delete mode 100644 sources/Events/Broadcast/BroadcastEventsObserver.uc delete mode 100644 sources/Events/Broadcast/BroadcastListenerBase.uc delete mode 100644 sources/Events/Events.uc delete mode 100644 sources/Events/Listener.uc delete mode 100644 sources/Events/Mutator/MutatorEvents.uc delete mode 100644 sources/Events/Mutator/MutatorListenerBase.uc create mode 100644 sources/ServiceAnchor.uc delete mode 100644 sources/Testing/Service/TestingEvents.uc delete mode 100644 sources/Testing/Service/TestingListenerBase.uc create mode 100644 sources/Unreal/BroadcastsAPI/BroadcastAPI.uc create mode 100644 sources/Unreal/BroadcastsAPI/BroadcastEventsObserver.uc create mode 100644 sources/Unreal/BroadcastsAPI/Events/Broadcast_OnBroadcastCheck_Signal.uc create mode 100644 sources/Unreal/BroadcastsAPI/Events/Broadcast_OnBroadcastCheck_Slot.uc create mode 100644 sources/Unreal/BroadcastsAPI/Events/Broadcast_OnHandleLocalizedFor_Signal.uc create mode 100644 sources/Unreal/BroadcastsAPI/Events/Broadcast_OnHandleLocalizedFor_Slot.uc create mode 100644 sources/Unreal/BroadcastsAPI/Events/Broadcast_OnHandleLocalized_Signal.uc create mode 100644 sources/Unreal/BroadcastsAPI/Events/Broadcast_OnHandleLocalized_Slot.uc create mode 100644 sources/Unreal/BroadcastsAPI/Events/Broadcast_OnHandleTextFor_Signal.uc create mode 100644 sources/Unreal/BroadcastsAPI/Events/Broadcast_OnHandleTextFor_Slot.uc create mode 100644 sources/Unreal/BroadcastsAPI/Events/Broadcast_OnHandleText_Signal.uc create mode 100644 sources/Unreal/BroadcastsAPI/Events/Broadcast_OnHandleText_Slot.uc rename sources/{Services/Connection => Unreal/Connections}/ConnectionService.uc (87%) rename sources/{Services/Connection => Unreal/Connections}/Events/Connection_Signal.uc (100%) rename sources/{Services/Connection => Unreal/Connections}/Events/Connection_Slot.uc (100%) rename sources/{Services/Connection => Unreal/Connections}/MutatorListener_Connection.uc (95%) rename sources/Unreal/{GameRules => GameRulesAPI}/AcediaGameRules.uc (65%) rename sources/Unreal/{GameRules => GameRulesAPI}/Events/GameRules_OnCheckEndGame_Signal.uc (100%) rename sources/Unreal/{GameRules => GameRulesAPI}/Events/GameRules_OnCheckEndGame_Slot.uc (100%) rename sources/Unreal/{GameRules => GameRulesAPI}/Events/GameRules_OnCheckScore_Signal.uc (95%) rename sources/Unreal/{GameRules => GameRulesAPI}/Events/GameRules_OnCheckScore_Slot.uc (100%) rename sources/Unreal/{GameRules => GameRulesAPI}/Events/GameRules_OnFindPlayerStart_Signal.uc (100%) rename sources/Unreal/{GameRules => GameRulesAPI}/Events/GameRules_OnFindPlayerStart_Slot.uc (100%) rename sources/Unreal/{GameRules => GameRulesAPI}/Events/GameRules_OnHandleRestartGame_Signal.uc (100%) rename sources/Unreal/{GameRules => GameRulesAPI}/Events/GameRules_OnHandleRestartGame_Slot.uc (100%) rename sources/Unreal/{GameRules => GameRulesAPI}/Events/GameRules_OnNetDamage_Signal.uc (100%) rename sources/Unreal/{GameRules => GameRulesAPI}/Events/GameRules_OnNetDamage_Slot.uc (100%) rename sources/Unreal/{GameRules => GameRulesAPI}/Events/GameRules_OnOverridePickupQuery_Signal.uc (100%) rename sources/Unreal/{GameRules => GameRulesAPI}/Events/GameRules_OnOverridePickupQuery_Slot.uc (100%) create mode 100644 sources/Unreal/GameRulesAPI/Events/GameRules_OnPreventDeath_Signal.uc create mode 100644 sources/Unreal/GameRulesAPI/Events/GameRules_OnPreventDeath_Slot.uc create mode 100644 sources/Unreal/GameRulesAPI/Events/GameRules_OnScoreKill_Signal.uc create mode 100644 sources/Unreal/GameRulesAPI/Events/GameRules_OnScoreKill_Slot.uc rename sources/Unreal/{GameRules => GameRulesAPI}/GameRulesAPI.uc (66%) create mode 100644 sources/Unreal/MutatorsAPI/Events/Mutator_OnCheckReplacement_Signal.uc create mode 100644 sources/Unreal/MutatorsAPI/Events/Mutator_OnCheckReplacement_Slot.uc create mode 100644 sources/Unreal/MutatorsAPI/Events/Mutator_OnMutate_Signal.uc create mode 100644 sources/Unreal/MutatorsAPI/Events/Mutator_OnMutate_Slot.uc create mode 100644 sources/Unreal/MutatorsAPI/MutatorAPI.uc diff --git a/sources/Aliases/AliasSource.uc b/sources/Aliases/AliasSource.uc index 1d6b542..b97bc46 100644 --- a/sources/Aliases/AliasSource.uc +++ b/sources/Aliases/AliasSource.uc @@ -68,6 +68,13 @@ protected function OnCreated() HashValidAliasesFromPerObjectConfig(); } +protected function OnDestroyed() +{ + loadedAliasObjects.length = 0; + _.memory.Free(aliasHash); + aliasHash = none; +} + // Ensures that our `Aliases` class is properly linked with this // source's class. Logs failure otherwise. private final function bool AssertAliasesClassIsOwnedByThisSource() diff --git a/sources/Commands/BroadcastListener_Commands.uc b/sources/Commands/BroadcastListener_Commands.uc deleted file mode 100644 index 458d514..0000000 --- a/sources/Commands/BroadcastListener_Commands.uc +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Overloaded broadcast events listener to catch commands input from - * the in-game chat. - * Copyright 2020 - 2021 Anton Tarasenko - *------------------------------------------------------------------------------ - * This file is part of Acedia. - * - * Acedia is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 3 of the License, or - * (at your option) any later version. - * - * Acedia is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Acedia. If not, see . - */ -class BroadcastListener_Commands extends BroadcastListenerBase - abstract; - -// TODO: reimplement with even to provide `APlayer` in the first place -static function bool HandleText( - Actor sender, - out string message, - optional name messageType) -{ - local Text messageAsText; - local APlayer callerPlayer; - local Parser parser; - local Commands_Feature commandFeature; - local PlayerService service; - // We only want to catch chat messages - // and only if `Commands` feature is active - if (messageType != 'Say') return true; - commandFeature = - Commands_Feature(class'Commands_Feature'.static.GetInstance()); - if (commandFeature == none) return true; - if (!commandFeature.UsingChatInput()) return true; - // We are only interested in messages that start with "!" - parser = __().text.ParseString(message); - if (!parser.Match(P("!")).Ok()) - { - parser.FreeSelf(); - // Convert color tags into colors - messageAsText = __().text.FromFormattedString(message); - message = messageAsText.ToColoredString(,, __().color.White); - messageAsText.FreeSelf(); - return true; - } - // Extract `APlayer` from the `sender` - service = PlayerService(class'PlayerService'.static.Require()); - if (service != none) { - callerPlayer = service.GetPlayer(PlayerController(sender)); - } - // Pass input to command feature - commandFeature.HandleInput(parser, callerPlayer); - parser.FreeSelf(); - return false; -} - -defaultproperties -{ -} \ No newline at end of file diff --git a/sources/Commands/BuiltInCommands/ACommandTest.uc b/sources/Commands/BuiltInCommands/ACommandTest.uc new file mode 100644 index 0000000..731d232 --- /dev/null +++ b/sources/Commands/BuiltInCommands/ACommandTest.uc @@ -0,0 +1,72 @@ +/** + * Command for changing nickname of the player. + * Copyright 2021 Anton Tarasenko + *------------------------------------------------------------------------------ + * This file is part of Acedia. + * + * Acedia is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License, or + * (at your option) any later version. + * + * Acedia is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Acedia. If not, see . + */ +class ACommandTest extends Command; + +protected function BuildData(CommandDataBuilder builder) +{ + builder.Name(P("test")).Summary(P("Tests various stuff. Simply call it.")) + .OptionalParams() + .ParamText(P("option")); +} + +protected function Executed(CommandCall result) +{ + local Parser parser; + local AssociativeArray root; + /*local int i; + local WeaponLocker lol; + local array aaa; + local Text message; + local Timer testTimer; + message = _.text.FromString("Is lobby?" @ _.kf.IsInLobby() @ + "Is pre game?" @ _.kf.IsInPreGame() @ + "Is trader?" @ _.kf.IsTraderActive() @ + "Is wave?" @ _.kf.IsWaveActive() @ + "Is finished?" @ _.kf.IsGameFinished() @ + "Is wipe?" @ _.kf.IsWipe()); + _.console.ForAll().WriteLine(message); + testTimer = Timer(_.memory.Allocate(class'Timer')); + testTimer.SetInterval(result.GetParameters().GetInt(P("add"))); + testTimer.Start(); + testTimer.OnElapsed(self).connect = OnTick; + testTimer.SetAutoReset(true); + for (i = 0; i < 100; i += 1) { + class'WeaponLocker'.default.bCollideWorld = false; + class'WeaponLocker'.default.bBlockActors = false; + lol = WeaponLocker(_.memory.Allocate(class'WeaponLocker')); + aaa[i] = lol; + Log("HUH" @ lol.Destroy()); + class'WeaponLocker'.default.bCollideWorld = true; + class'WeaponLocker'.default.bBlockActors = true; + } + for (i = 0; i < 100; i += 1) { + if (aaa[i] != none) + { + Log("UMBRA" @ aaa[i]); + } + }*/ + parser = _.text.ParseString("{\"innerObject\":{\"my_bool\":true,\"array\":[\"Engine.Actor\",false,null,{\"something \\\"here\\\"\":\"yes\",\"maybe\":0.003},56.6],\"one more\":{\"nope\":324532,\"whatever\":false,\"o rly?\":\"ya rly\"},\"my_int\":-9823452},\"some_var\":-7.32,\"another_var\":\"aye!\"}"); + root = _.json.ParseObjectWith(parser); + result.GetCallerPlayer().Console().WriteLine(_.json.PrettyPrint(root)); +} + +defaultproperties +{ +} \ No newline at end of file diff --git a/sources/Commands/Command.uc b/sources/Commands/Command.uc index 9d3fd1b..80a805b 100644 --- a/sources/Commands/Command.uc +++ b/sources/Commands/Command.uc @@ -165,6 +165,47 @@ protected function Constructor() dataBuilder = none; } +protected function Finalizer() +{ + local int i; + local array subCommands; + local array