From 23691e77c20a0a55b0627adf597dd41f33dc7d27 Mon Sep 17 00:00:00 2001 From: wonkyhonky2024 Date: Wed, 14 May 2025 22:29:33 +0100 Subject: [PATCH] a LOT of time wasted fighting with dlls again --- Content/LinacLab/MyMyUserWidget.uasset | 4 +- Content/LinacLab/vt100_Blueprint.uasset | 4 +- .../Source/hstherac25/Private/Therac.h | 2 +- .../Private/TheracAdapterComponent.cpp | 40 ++++++++--- .../Source/hstherac25/Private/hstherac25.cpp | 9 +-- .../Public/TheracAdapterComponent.h | 56 ++++++++++++++-- .../Source/hstherac25/Public/hstherac25.h | 2 +- .../Source/hstherac25/hstherac25.Build.cs | 66 +++++++++---------- Source/MyProject.Target.cs | 13 ++-- Source/MyProject/MyProject.Build.cs | 26 ++++---- Source/MyProject/Private/MyUserWidget.cpp | 2 +- Source/MyProject/Public/MyUserWidget.h | 4 +- Source/MyProjectEditor.Target.cs | 13 ++-- 13 files changed, 153 insertions(+), 88 deletions(-) diff --git a/Content/LinacLab/MyMyUserWidget.uasset b/Content/LinacLab/MyMyUserWidget.uasset index e056ba3..457bc63 100644 --- a/Content/LinacLab/MyMyUserWidget.uasset +++ b/Content/LinacLab/MyMyUserWidget.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:eb52982872141a34f03496b36f5502683c0d3c6aa5a7af2ecc72eefcfffc557a -size 156573 +oid sha256:4218b148bc2380facdae32795e3add31987f3f2467c99d7e1b65782fc49e26ff +size 157511 diff --git a/Content/LinacLab/vt100_Blueprint.uasset b/Content/LinacLab/vt100_Blueprint.uasset index 6dc2d00..948af7a 100644 --- a/Content/LinacLab/vt100_Blueprint.uasset +++ b/Content/LinacLab/vt100_Blueprint.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8805e9a37b46bc5f899a2bc385afd1f98a47f8d92d3ddac42fb77c5165eb6efb -size 158294 +oid sha256:dc3c09594dc815ba26c8d7443a34d843beca39d3312eabb83f4a9316e1c28ee9 +size 232334 diff --git a/Plugins/hstherac25/Source/hstherac25/Private/Therac.h b/Plugins/hstherac25/Source/hstherac25/Private/Therac.h index e7dbe5d..4c7e326 100644 --- a/Plugins/hstherac25/Source/hstherac25/Private/Therac.h +++ b/Plugins/hstherac25/Source/hstherac25/Private/Therac.h @@ -1,4 +1,4 @@ -#pragma once + #include typedef enum ExtCallType { diff --git a/Plugins/hstherac25/Source/hstherac25/Private/TheracAdapterComponent.cpp b/Plugins/hstherac25/Source/hstherac25/Private/TheracAdapterComponent.cpp index aa09e05..88a3cb1 100644 --- a/Plugins/hstherac25/Source/hstherac25/Private/TheracAdapterComponent.cpp +++ b/Plugins/hstherac25/Source/hstherac25/Private/TheracAdapterComponent.cpp @@ -7,12 +7,9 @@ #include #include #include -#include #include #include -#define LOCTEXT_NAMESPACE "TheracAdapter" - // Sets default values for this component's properties UTheracAdapterComponent::UTheracAdapterComponent() { // Set this component to be initialized when the game starts, and to be ticked @@ -41,18 +38,25 @@ void UTheracAdapterComponent::UpdateSimulator( ); } +void UTheracAdapterComponent::WrapSimulatorCall( + EExtCallType ext_call_type, + EBeamType beam_type, + ECollimatorPosition collimator_position, + int32 beam_energy +) {} + // Called when the game starts void UTheracAdapterComponent::BeginPlay() { - /* + FString BaseDir = IPluginManager::Get().FindPlugin("hstherac25")->GetBaseDir(); FString LibraryPath = - FPaths::Combine(*BaseDir, TEXT("Source/hstherac-hs/HSdll.dll")); + FPaths::Combine(*BaseDir, TEXT("Source/hstherac-hs/hstherac25.dll")); + + simulatorLibraryHandle = !LibraryPath.IsEmpty() + ? FPlatformProcess::GetDllHandle(*LibraryPath) + : nullptr; - auto simulatorLibraryHandle = - !LibraryPath.IsEmpty() ? FPlatformProcess::GetDllHandle(*LibraryPath) - : nullptr; - */ Super::BeginPlay(); wrappedComms = start_machine(); std::map hng = { @@ -66,9 +70,27 @@ void UTheracAdapterComponent::BeginPlay() { for (auto & [hnng, hnnng] : hng) { compMap.Add(hnng, hnnng); } + ExtCallTypeMap.Add("R", EExtCallType::ExtCallReset); + ExtCallTypeMap.Add("P", EExtCallType::ExtCallProceed); + + BeamTypeMap.Add("X", EBeamType::BeamTypeXRay); + BeamTypeMap.Add("E", EBeamType::BeamTypeElectron); + + CollimatorPositionMap.Add("X", ECollimatorPosition::CollimatorPositionXRay); + CollimatorPositionMap.Add( + "E", + ECollimatorPosition::CollimatorPositionElectronBeam + ); + // ... } +void UTheracAdapterComponent::shutdownSimulator() { + kill_machine(); + FPlatformProcess::FreeDllHandle(simulatorLibraryHandle); + simulatorLibraryHandle = nullptr; +} + // Called every frame void UTheracAdapterComponent::TickComponent( float DeltaTime, diff --git a/Plugins/hstherac25/Source/hstherac25/Private/hstherac25.cpp b/Plugins/hstherac25/Source/hstherac25/Private/hstherac25.cpp index 6d6105f..f14d506 100644 --- a/Plugins/hstherac25/Source/hstherac25/Private/hstherac25.cpp +++ b/Plugins/hstherac25/Source/hstherac25/Private/hstherac25.cpp @@ -13,13 +13,13 @@ void Fhstherac25Module::StartupModule() { // This code will execute after your module is loaded into memory; the exact // timing is specified in the .uplugin file per-module - + /* // Get the base directory of this plugin FString BaseDir = IPluginManager::Get().FindPlugin("hstherac25")->GetBaseDir(); // Add on the relative location of the third party dll and load it - FString LibraryPath; +/ FString LibraryPath; #if PLATFORM_WINDOWS LibraryPath = FPaths::Combine(*BaseDir, TEXT("Source/hstherac-hs/HSdll.dll")); @@ -55,6 +55,7 @@ void Fhstherac25Module::StartupModule() { ) ); } + */ } void Fhstherac25Module::ShutdownModule() { @@ -63,8 +64,8 @@ void Fhstherac25Module::ShutdownModule() { // unloading the module. // Free the dll handle - FPlatformProcess::FreeDllHandle(simulatorLibraryHandle); - simulatorLibraryHandle = nullptr; + // FPlatformProcess::FreeDllHandle(simulatorLibraryHandle); + // simulatorLibraryHandle = nullptr; } #undef LOCTEXT_NAMESPACE diff --git a/Plugins/hstherac25/Source/hstherac25/Public/TheracAdapterComponent.h b/Plugins/hstherac25/Source/hstherac25/Public/TheracAdapterComponent.h index f565948..010368e 100644 --- a/Plugins/hstherac25/Source/hstherac25/Public/TheracAdapterComponent.h +++ b/Plugins/hstherac25/Source/hstherac25/Public/TheracAdapterComponent.h @@ -5,10 +5,33 @@ #include "Components/ActorComponent.h" #include "CoreMinimal.h" #include +// #include +// #include #include #include "TheracAdapterComponent.generated.h" +UENUM() +enum class EBeamType : uint8 { + BeamTypeXRay = 1, + BeamTypeElectron, +}; + +UENUM() +enum class ECollimatorPosition : uint8 { + CollimatorPositionXRay = 1, + CollimatorPositionElectronBeam, +}; + +UENUM() +enum class EExtCallType : uint8 { + ExtCallSendMEOS = 1, + ExtCallToggleDatentComplete, + ExtCallToggleEditingTakingPlace, + ExtCallReset, + ExtCallProceed +}; + UCLASS( BlueprintType, ClassGroup = (Custom), @@ -22,6 +45,16 @@ class HSTHERAC25_API UTheracAdapterComponent : public UActorComponent { TMap compMap; + void * simulatorLibraryHandle; + + void UpdateSimulator( + ExtCallType ect, + HsStablePtr wrapped_comms = nullptr, + BeamType beam_type = BeamTypeUndefined, + CollimatorPosition collimator_position = CollimatorPositionUndefined, + HsInt beam_energy = 25000 + ); + public: // Sets default values for this component's properties UTheracAdapterComponent(); @@ -46,17 +79,28 @@ public: UPROPERTY(BlueprintReadOnly, VisibleAnywhere) FText BeamEnergy; - void UpdateSimulator( - ExtCallType ect, - HsStablePtr wrapped_comms = nullptr, - BeamType beam_type = BeamTypeUndefined, - CollimatorPosition collimator_position = CollimatorPositionUndefined, - HsInt beam_energy = 25000 + UPROPERTY(BlueprintReadOnly, VisibleAnywhere) + TMap BeamTypeMap; + + UPROPERTY(BlueprintReadOnly, VisibleAnywhere) + TMap ExtCallTypeMap; + + UPROPERTY(BlueprintReadOnly, VisibleAnywhere) + TMap CollimatorPositionMap; + + UFUNCTION(BlueprintCallable) + void WrapSimulatorCall( + EExtCallType ext_call_type, + EBeamType beam_type = EBeamType::BeamTypeXRay, + ECollimatorPosition collimator_position = + ECollimatorPosition::CollimatorPositionXRay, + int32 beam_energy = 25000 ); protected: // Called when the game starts virtual void BeginPlay() override; + void shutdownSimulator(); public: // Called every frame diff --git a/Plugins/hstherac25/Source/hstherac25/Public/hstherac25.h b/Plugins/hstherac25/Source/hstherac25/Public/hstherac25.h index a7a5d44..559ff41 100644 --- a/Plugins/hstherac25/Source/hstherac25/Public/hstherac25.h +++ b/Plugins/hstherac25/Source/hstherac25/Public/hstherac25.h @@ -12,5 +12,5 @@ public: private: /** Handle to the test dll we will load */ - void * simulatorLibraryHandle; + // void * simulatorLibraryHandle; }; diff --git a/Plugins/hstherac25/Source/hstherac25/hstherac25.Build.cs b/Plugins/hstherac25/Source/hstherac25/hstherac25.Build.cs index 5141c18..e88d502 100644 --- a/Plugins/hstherac25/Source/hstherac25/hstherac25.Build.cs +++ b/Plugins/hstherac25/Source/hstherac25/hstherac25.Build.cs @@ -5,65 +5,65 @@ using System.IO; public class hstherac25 : ModuleRules { - public hstherac25(ReadOnlyTargetRules Target) : base(Target) - { - PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs; + public hstherac25(ReadOnlyTargetRules Target) : base(Target) + { + PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs; - PublicIncludePaths.AddRange( - new string[] { + PublicIncludePaths.AddRange( + new string[] { // ... add public include paths required here ... "C:/ghcup/ghc/9.6.7/include", - } - ); + } + ); - PrivateIncludePaths.AddRange( - new string[] { - "C:/ghcup/ghc/9.6.7/include", + PrivateIncludePaths.AddRange( + new string[] { + "C:/ghcup/ghc/9.6.7/include", // "C:/ghcup/ghc/9.6.7/include", // "${workspaceFolder}/Plugins/hstherac25/Source/hstherac-hs/csrc", -// "${workspaceFolder}/Plugins/hstherac25/Source/hstherac-hs/dist-newstyle/build/x86_64-windows/ghc-9.6.7/hstherac25-0.1.0.0/build" +// Path.Combine(ModuleDirectory,"../hstherac-hs/dist-newstyle/build/x86_64-windows/ghc-9.6.7/hstherac25-0.1.0.0/build"), // ... add other private include paths required here ... } - ); + ); - PublicDependencyModuleNames.AddRange( - new string[] - { - "Core", - "MathCore", - "Projects", + PublicDependencyModuleNames.AddRange( + new string[] + { + "Core", + "MathCore", + "Projects", "CoreUObject", - "Engine", - "UMG", - "AudioMixerCore", - "InputCore" + "Engine", + "UMG", + "AudioMixerCore", + "InputCore" // ... add other public dependencies that you statically link with here ... } - ); + ); - PrivateDependencyModuleNames.AddRange( - new string[] - { + PrivateDependencyModuleNames.AddRange( + new string[] + { "Slate", "SlateCore" // ... add private dependencies that you statically link with here ... } - ); + ); - DynamicallyLoadedModuleNames.AddRange( - new string[] - { + DynamicallyLoadedModuleNames.AddRange( + new string[] + { // ... add any modules that your module loads dynamically here ... } - ); - PublicAdditionalLibraries.Add(Path.Combine(ModuleDirectory, "../hstherac-hs", "HSdll.dll.a")); - RuntimeDependencies.Add(Path.Combine(PluginDirectory, "Source/hstherac-hs/HSdll.dll")); + ); + PublicAdditionalLibraries.Add(Path.Combine(ModuleDirectory, "../hstherac-hs", "hstherac25.dll.a")); + RuntimeDependencies.Add(Path.Combine(ModuleDirectory, "../hstherac-hs/hstherac25.dll")); } } diff --git a/Source/MyProject.Target.cs b/Source/MyProject.Target.cs index 96bc1db..3f83387 100644 --- a/Source/MyProject.Target.cs +++ b/Source/MyProject.Target.cs @@ -1,15 +1,14 @@ // Fill out your copyright notice in the Description page of Project Settings. using UnrealBuildTool; -using System.Collections.Generic; public class MyProjectTarget : TargetRules { - public MyProjectTarget(TargetInfo Target) : base(Target) - { - Type = TargetType.Game; - DefaultBuildSettings = BuildSettingsVersion.V5; + public MyProjectTarget(TargetInfo Target) : base(Target) + { + Type = TargetType.Game; + DefaultBuildSettings = BuildSettingsVersion.V5; - ExtraModuleNames.AddRange( new string[] { "MyProject" } ); - } + ExtraModuleNames.AddRange(new string[] { "MyProject", "hstherac25" }); + } } diff --git a/Source/MyProject/MyProject.Build.cs b/Source/MyProject/MyProject.Build.cs index 149295a..1f5f2f5 100644 --- a/Source/MyProject/MyProject.Build.cs +++ b/Source/MyProject/MyProject.Build.cs @@ -4,20 +4,20 @@ using UnrealBuildTool; public class MyProject : ModuleRules { - public MyProject(ReadOnlyTargetRules Target) : base(Target) - { - PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; - - PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "UMG" }); + public MyProject(ReadOnlyTargetRules Target) : base(Target) + { + PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; - PrivateDependencyModuleNames.AddRange(new string[] { }); + PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "UMG" }); - // Uncomment if you are using Slate UI - PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" }); - - // Uncomment if you are using online features - // PrivateDependencyModuleNames.Add("OnlineSubsystem"); + PrivateDependencyModuleNames.AddRange(new string[] { }); - // To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true - } + // Uncomment if you are using Slate UI + PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore", "hstherac25" }); + + // Uncomment if you are using online features + // PrivateDependencyModuleNames.Add("OnlineSubsystem"); + + // To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true + } } diff --git a/Source/MyProject/Private/MyUserWidget.cpp b/Source/MyProject/Private/MyUserWidget.cpp index 6d85d4e..a58469e 100644 --- a/Source/MyProject/Private/MyUserWidget.cpp +++ b/Source/MyProject/Private/MyUserWidget.cpp @@ -16,7 +16,7 @@ void UMyUserWidget::NativeOnInitialized() { CR_TextBlock, ColX_TextBlock, ColY_TextBlock, - WR_TextBlock, + WN_TextBlock, AN_TextBlock }; for (auto * n : arcaneNumbers) { diff --git a/Source/MyProject/Public/MyUserWidget.h b/Source/MyProject/Public/MyUserWidget.h index fe7881e..5d24dc7 100644 --- a/Source/MyProject/Public/MyUserWidget.h +++ b/Source/MyProject/Public/MyUserWidget.h @@ -40,10 +40,10 @@ class MYPROJECT_API UMyUserWidget : public UUserWidget { UTextBlock * ColY_TextBlock; UPROPERTY(meta = (BindWidget)) - UTextBlock * WR_TextBlock; + UTextBlock * WN_TextBlock; UPROPERTY(meta = (BindWidget)) UTextBlock * AN_TextBlock; - void NativeOnInitialized() override; + void NativeOnInitialized() override; }; diff --git a/Source/MyProjectEditor.Target.cs b/Source/MyProjectEditor.Target.cs index 328b288..2157b13 100644 --- a/Source/MyProjectEditor.Target.cs +++ b/Source/MyProjectEditor.Target.cs @@ -1,15 +1,14 @@ // Fill out your copyright notice in the Description page of Project Settings. using UnrealBuildTool; -using System.Collections.Generic; public class MyProjectEditorTarget : TargetRules { - public MyProjectEditorTarget(TargetInfo Target) : base(Target) - { - Type = TargetType.Editor; - DefaultBuildSettings = BuildSettingsVersion.V5; + public MyProjectEditorTarget(TargetInfo Target) : base(Target) + { + Type = TargetType.Editor; + DefaultBuildSettings = BuildSettingsVersion.V5; - ExtraModuleNames.AddRange( new string[] { "MyProject" } ); - } + ExtraModuleNames.AddRange(new string[] { "MyProject", "hstherac25" }); + } }