diff --git a/.gitignore b/.gitignore index f4334a5..0a373d1 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ Saved *.sln *.suo *.xcodeproj -*.xcworkspace \ No newline at end of file +*.xcworkspace +.idea diff --git a/Config/DefaultEditor.ini b/Config/DefaultEditor.ini index e69de29..8b13789 100644 --- a/Config/DefaultEditor.ini +++ b/Config/DefaultEditor.ini @@ -0,0 +1 @@ + diff --git a/Config/DefaultEngine.ini b/Config/DefaultEngine.ini index 34ddd35..c752d1d 100644 --- a/Config/DefaultEngine.ini +++ b/Config/DefaultEngine.ini @@ -2,7 +2,7 @@ [/Script/EngineSettings.GameMapsSettings] GameDefaultMap=/Engine/Maps/Templates/Template_Default.Template_Default - +EditorStartupMap=/Game/Maps/ShipTest.ShipTest [/Script/HardwareTargeting.HardwareTargetingSettings] TargetedHardwareClass=Desktop @@ -15,3 +15,6 @@ AppliedDefaultGraphicsPerformance=Maximum +ActiveGameNameRedirects=(OldGameName="/Script/TP_Blank",NewGameName="/Script/SeaOfCrooks") +ActiveClassRedirects=(OldClassName="TP_BlankGameModeBase",NewClassName="SeaOfCrooksGameModeBase") +[/Script/PythonScriptPlugin.PythonScriptPluginSettings] +bRemoteExecution=True + diff --git a/Content/Core/BP_TestGameMode.uasset b/Content/Core/BP_TestGameMode.uasset new file mode 100644 index 0000000..6bed780 --- /dev/null +++ b/Content/Core/BP_TestGameMode.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c71f5f5d1fa24eaf8ec36ed307b2f2e06a29dc8aeb650493c90422705cf66b79 +size 18601 diff --git a/Content/Core/BP_TestGameState.uasset b/Content/Core/BP_TestGameState.uasset new file mode 100644 index 0000000..b850a65 --- /dev/null +++ b/Content/Core/BP_TestGameState.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3c4245743f4d2c76ddc84e0db99121a141597974032e40388095fc16f9d6d891 +size 18462 diff --git a/Content/Environment/BP_TestOcean.uasset b/Content/Environment/BP_TestOcean.uasset new file mode 100644 index 0000000..c7f3ef3 --- /dev/null +++ b/Content/Environment/BP_TestOcean.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:18945ec5b74b3f515aef8b31d293d3be44295fcd512448da1ad47f27d9534e84 +size 107579 diff --git a/Content/Environment/Materials/M_Ocean.uasset b/Content/Environment/Materials/M_Ocean.uasset new file mode 100644 index 0000000..aea5b16 --- /dev/null +++ b/Content/Environment/Materials/M_Ocean.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5dadd1899cfa811f8397a37261c461fad688741fe5a421f8541557250159f9c8 +size 98991 diff --git a/Content/Environment/Materials/M_Sand.uasset b/Content/Environment/Materials/M_Sand.uasset new file mode 100644 index 0000000..b341261 --- /dev/null +++ b/Content/Environment/Materials/M_Sand.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2979e41afee738beafafe7d846a618f1f96c997508f80afc407a99047ae64c54 +size 79384 diff --git a/Content/Maps/ShipTest.umap b/Content/Maps/ShipTest.umap new file mode 100644 index 0000000..d31f447 --- /dev/null +++ b/Content/Maps/ShipTest.umap @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:70d24d41060d4aaebe649f1f5e4ae25000b41052d7c44e6748389f6da2e267fd +size 632371 diff --git a/Content/Maps/ShipTest_BuiltData.uasset b/Content/Maps/ShipTest_BuiltData.uasset new file mode 100644 index 0000000..1e0f422 --- /dev/null +++ b/Content/Maps/ShipTest_BuiltData.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4bd7969f79741ee62a1e0db1b8dea4e972b520cc7b04de6984bfcefba9e98a37 +size 1328744 diff --git a/Content/Ships/BP_Ship.uasset b/Content/Ships/BP_Ship.uasset new file mode 100644 index 0000000..1bf32cc --- /dev/null +++ b/Content/Ships/BP_Ship.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bd67a875ba5fd86bb7d8ecef03ff163764cc892f65de7385e82d271c0a020311 +size 2128 diff --git a/Content/Ships/BP_TestShip.uasset b/Content/Ships/BP_TestShip.uasset new file mode 100644 index 0000000..59236a3 --- /dev/null +++ b/Content/Ships/BP_TestShip.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1cecd53636894d9e62cf397d89bd0bae39c87d0c40e8dee8959e70d01a53b1ca +size 93925 diff --git a/Content/Ships/Ship_Dark/_defaultMat.uasset b/Content/Ships/Ship_Dark/_defaultMat.uasset new file mode 100644 index 0000000..7cb06c6 --- /dev/null +++ b/Content/Ships/Ship_Dark/_defaultMat.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f6124e235b71c165dd26a6883a23a16d38f20b343a3870dfa3c457bf423863dc +size 78766 diff --git a/Content/Ships/Ship_Dark/iron.uasset b/Content/Ships/Ship_Dark/iron.uasset new file mode 100644 index 0000000..9cf5548 --- /dev/null +++ b/Content/Ships/Ship_Dark/iron.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:69f8ea155cbed312cecebee26791dc796cb7ed6593ad87fb70f0057bb13c2445 +size 83821 diff --git a/Content/Ships/Ship_Dark/ship_dark_cannon_front.uasset b/Content/Ships/Ship_Dark/ship_dark_cannon_front.uasset new file mode 100644 index 0000000..a391233 --- /dev/null +++ b/Content/Ships/Ship_Dark/ship_dark_cannon_front.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:447ba6d0c2587000898538d72a8a3aee4bfaacad2fbba6b750c4682e64af511d +size 92228 diff --git a/Content/Ships/Ship_Dark/ship_dark_cannon_front1.uasset b/Content/Ships/Ship_Dark/ship_dark_cannon_front1.uasset new file mode 100644 index 0000000..c0dfc00 --- /dev/null +++ b/Content/Ships/Ship_Dark/ship_dark_cannon_front1.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fd72447d6322f61b82900cbc53c881834fd6d5ec2e402ededea2a83ad0e4f48d +size 114893 diff --git a/Content/Ships/Ship_Dark/ship_dark_cannon_left.uasset b/Content/Ships/Ship_Dark/ship_dark_cannon_left.uasset new file mode 100644 index 0000000..fe506cc --- /dev/null +++ b/Content/Ships/Ship_Dark/ship_dark_cannon_left.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5013e42d3ea264cb4c41cfccad33f4b227246b814f26e0d57a5b20719f970a0b +size 91960 diff --git a/Content/Ships/Ship_Dark/ship_dark_cannon_left2.uasset b/Content/Ships/Ship_Dark/ship_dark_cannon_left2.uasset new file mode 100644 index 0000000..4715b19 --- /dev/null +++ b/Content/Ships/Ship_Dark/ship_dark_cannon_left2.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:73490c868d812126e2239fa26e4d0b074ffd6f83c9e19b582abdb79ba346f1c2 +size 117266 diff --git a/Content/Ships/Ship_Dark/ship_dark_cannon_left3.uasset b/Content/Ships/Ship_Dark/ship_dark_cannon_left3.uasset new file mode 100644 index 0000000..7ef92c6 --- /dev/null +++ b/Content/Ships/Ship_Dark/ship_dark_cannon_left3.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1c55f501da6b8f978021bc6a718e60bea1b8ea40953237209eadd12dbacf2280 +size 93238 diff --git a/Content/Ships/Ship_Dark/ship_dark_cannon_left4.uasset b/Content/Ships/Ship_Dark/ship_dark_cannon_left4.uasset new file mode 100644 index 0000000..d15e5b9 --- /dev/null +++ b/Content/Ships/Ship_Dark/ship_dark_cannon_left4.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:11f42419e204c1c365c9bb6f1c6055c5f415c488ae36ae3047400b7924789769 +size 87418 diff --git a/Content/Ships/Ship_Dark/ship_dark_cannon_left5.uasset b/Content/Ships/Ship_Dark/ship_dark_cannon_left5.uasset new file mode 100644 index 0000000..8241191 --- /dev/null +++ b/Content/Ships/Ship_Dark/ship_dark_cannon_left5.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8afeeba8381074080e9e9b20d6871480091498493941f06a4b1331fb23fd4b4e +size 93244 diff --git a/Content/Ships/Ship_Dark/ship_dark_cannon_left6.uasset b/Content/Ships/Ship_Dark/ship_dark_cannon_left6.uasset new file mode 100644 index 0000000..a6e78f6 --- /dev/null +++ b/Content/Ships/Ship_Dark/ship_dark_cannon_left6.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2643c8cf61beb5a000c231d269cfa136c87ff4f03df1689050117534dee39dbe +size 87417 diff --git a/Content/Ships/Ship_Dark/ship_dark_cannon_right.uasset b/Content/Ships/Ship_Dark/ship_dark_cannon_right.uasset new file mode 100644 index 0000000..594a2dc --- /dev/null +++ b/Content/Ships/Ship_Dark/ship_dark_cannon_right.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3c4f4ac4eb89c26fed80f52863f5b58425008b9ec5b7f1ef10e997a49856ecb5 +size 90753 diff --git a/Content/Ships/Ship_Dark/ship_dark_cannon_right10.uasset b/Content/Ships/Ship_Dark/ship_dark_cannon_right10.uasset new file mode 100644 index 0000000..f8a549e --- /dev/null +++ b/Content/Ships/Ship_Dark/ship_dark_cannon_right10.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6bbee0ffbadef418141e8676a5296684157b565707f9b128d33b7e3eec0da540 +size 87406 diff --git a/Content/Ships/Ship_Dark/ship_dark_cannon_right11.uasset b/Content/Ships/Ship_Dark/ship_dark_cannon_right11.uasset new file mode 100644 index 0000000..b5b61ac --- /dev/null +++ b/Content/Ships/Ship_Dark/ship_dark_cannon_right11.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5e0d769f6dcc72380e54ad350b308da50c690180a2b41a0d7e749519d039e80c +size 93185 diff --git a/Content/Ships/Ship_Dark/ship_dark_cannon_right7.uasset b/Content/Ships/Ship_Dark/ship_dark_cannon_right7.uasset new file mode 100644 index 0000000..3496ef9 --- /dev/null +++ b/Content/Ships/Ship_Dark/ship_dark_cannon_right7.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4f5b3d97447cc991219bf05d8e4b0a29c2026f976c68a1303214ea1df3184502 +size 114524 diff --git a/Content/Ships/Ship_Dark/ship_dark_cannon_right8.uasset b/Content/Ships/Ship_Dark/ship_dark_cannon_right8.uasset new file mode 100644 index 0000000..6cf4a42 --- /dev/null +++ b/Content/Ships/Ship_Dark/ship_dark_cannon_right8.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bed6e04a819ff6b5071281bbdf4b5277c890f706358e41c1134bb2169eb7d855 +size 87387 diff --git a/Content/Ships/Ship_Dark/ship_dark_cannon_right9.uasset b/Content/Ships/Ship_Dark/ship_dark_cannon_right9.uasset new file mode 100644 index 0000000..5a2f821 --- /dev/null +++ b/Content/Ships/Ship_Dark/ship_dark_cannon_right9.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:59ddf4bceefd065f545eab311b300b46f15277bd5b3da301e6bbddd00497ffe0 +size 93283 diff --git a/Content/Ships/Ship_Dark/ship_dark_sail_back.uasset b/Content/Ships/Ship_Dark/ship_dark_sail_back.uasset new file mode 100644 index 0000000..71f90d9 --- /dev/null +++ b/Content/Ships/Ship_Dark/ship_dark_sail_back.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:93680f3550b74b4d7790e8809ff6dc60a1c10ed7d31573db29e32b89a45786ac +size 102342 diff --git a/Content/Ships/Ship_Dark/ship_dark_sail_front.uasset b/Content/Ships/Ship_Dark/ship_dark_sail_front.uasset new file mode 100644 index 0000000..e775b98 --- /dev/null +++ b/Content/Ships/Ship_Dark/ship_dark_sail_front.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7fcd9d04efc0d08d721429b8b01f7722be2cb39ff155e765aca71fc9ee4278b1 +size 100907 diff --git a/Content/Ships/Ship_Dark/ship_dark_sail_middle.uasset b/Content/Ships/Ship_Dark/ship_dark_sail_middle.uasset new file mode 100644 index 0000000..d512cb6 --- /dev/null +++ b/Content/Ships/Ship_Dark/ship_dark_sail_middle.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b68d9977f5b15ee0cdd32fcaff7ef59fe7b5839fa7c051ca2046369c2604f127 +size 103366 diff --git a/Content/Ships/Ship_Dark/ship_dark_ship_dark_8angles.uasset b/Content/Ships/Ship_Dark/ship_dark_ship_dark_8angles.uasset new file mode 100644 index 0000000..9fb155c --- /dev/null +++ b/Content/Ships/Ship_Dark/ship_dark_ship_dark_8angles.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d4a08cd49ea8f93fb83bf47be09edbabc1f3e05c9823f1bcee8c5297ecce5e98 +size 197065 diff --git a/Content/Ships/Ship_Dark/ship_dark_steering.uasset b/Content/Ships/Ship_Dark/ship_dark_steering.uasset new file mode 100644 index 0000000..4202647 --- /dev/null +++ b/Content/Ships/Ship_Dark/ship_dark_steering.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:14008bde20012cf7848cd1240a69d78b5948c0e2bc1aaf1f44ba064009f45ea8 +size 140126 diff --git a/Content/Ships/Ship_Dark/window.uasset b/Content/Ships/Ship_Dark/window.uasset new file mode 100644 index 0000000..6da9aa3 --- /dev/null +++ b/Content/Ships/Ship_Dark/window.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bcf901f30064314a1d88518fc3d3db91a18c3964121b53323111556f8bc61c28 +size 80140 diff --git a/Content/Ships/Ship_Dark/wood.uasset b/Content/Ships/Ship_Dark/wood.uasset new file mode 100644 index 0000000..b97c582 --- /dev/null +++ b/Content/Ships/Ship_Dark/wood.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cc3d2ad4a5415fd88ac86baab58d5f9722e0d41c73c49568d32e5e2224844e4b +size 83386 diff --git a/Content/Ships/Ship_Dark/woodDark.uasset b/Content/Ships/Ship_Dark/woodDark.uasset new file mode 100644 index 0000000..615baa4 --- /dev/null +++ b/Content/Ships/Ship_Dark/woodDark.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:50c9bdfa6d1ce8cc1ceffe315d362e83e729f1e03958796f9951e6cb96485ded +size 85518 diff --git a/Content/Test/Plane.uasset b/Content/Test/Plane.uasset new file mode 100644 index 0000000..28302d5 --- /dev/null +++ b/Content/Test/Plane.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b5c9d65a9b566e1fa994f94b047bb2dc4397b7e163425c4df2249350ad946a2e +size 98430 diff --git a/SeaOfCrooks.uproject b/SeaOfCrooks.uproject index 0ec59b4..d68f5b3 100644 --- a/SeaOfCrooks.uproject +++ b/SeaOfCrooks.uproject @@ -7,7 +7,20 @@ { "Name": "SeaOfCrooks", "Type": "Runtime", - "LoadingPhase": "Default" + "LoadingPhase": "Default", + "AdditionalDependencies": [ + "Engine" + ] + } + ], + "Plugins": [ + { + "Name": "PythonScriptPlugin", + "Enabled": true + }, + { + "Name": "EditorScriptingUtilities", + "Enabled": true } ] } \ No newline at end of file diff --git a/Source/SeaOfCrooks/Private/Components/BuoyancyComponent.cpp b/Source/SeaOfCrooks/Private/Components/BuoyancyComponent.cpp new file mode 100644 index 0000000..89cac4e --- /dev/null +++ b/Source/SeaOfCrooks/Private/Components/BuoyancyComponent.cpp @@ -0,0 +1,223 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#include "Components/BuoyancyComponent.h" + +#include "DrawDebugHelpers.h" +#include "StaticMeshResources.h" +#include "Game/SOCGameState.h" + +static int32 DebugBuoyancy = 0; +FAutoConsoleVariableRef CVARDebugProtagonistDrawing(TEXT("SOC.DebugBuoyancy"), + DebugBuoyancy, + TEXT("Print debug information about buoyancy component"), + ECVF_Cheat); + +// Sets default values for this component's properties +UBuoyancyComponent::UBuoyancyComponent() +{ + // Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features + // off to improve performance if you don't need them. + PrimaryComponentTick.bCanEverTick = true; + + // ... +} + + +// Called when the game starts +void UBuoyancyComponent::BeginPlay() +{ + Super::BeginPlay(); + + // ... + UStaticMeshComponent* MeshComp = Cast(GetOwner()->GetRootComponent()); + VolumeMesh = MeshComp->GetStaticMesh(); + + SubmergedTriangles = TArray(); + SubmergedTriangles.SetNum(GetNumTriangles(), false); +} + + +// Called every frame +void UBuoyancyComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) +{ + Super::TickComponent(DeltaTime, TickType, ThisTickFunction); + + SubmergedTriangles.Empty(); + + // determine height of vertices above or below surface of water + ASOCGameState* State = Cast(GetWorld()->GetGameState()); + AOcean* Ocean = nullptr; + if(State) + { + Ocean = State->GetOcean(); + } + + if(Ocean) + { + TArray Vertices = GetVertexPositions(); + for(int idx = 0; idx < Vertices.Num(); idx++) + { + Vertices[idx].CalculateDepth(Ocean->GetOceanHeight()); + } + TArray Indices = GetTriangleIndices(); + + TArray Triangles; + for(int idx = 0; idx < Indices.Num(); idx += 3) + { + FVertexData V1 = Vertices[Indices[idx]]; + FVertexData V2 = Vertices[Indices[idx + 1]]; + FVertexData V3 = Vertices[Indices[idx + 2]]; + + if(V1.Depth < 0.0f || V2.Depth < 0.0f || V3.Depth < 0.0f) + { + FTriangleData temp(V1, V2, V3); + Triangles.Add(temp); + FVector Center = (V1.Position + V2.Position + V3.Position) / 3.0f; + if(DebugBuoyancy) + DrawDebugSphere(GetWorld(), Center, 5.0f, 12, FColor::Yellow, false, 0.0f, 0, 1.0f); + } + } + + ProcessTriangles(Triangles); + + if(DebugBuoyancy) + { + FString DebugMsg = FString::Printf(TEXT("Num Submerged Triangles: %d\nNum Generated Triangles: %d"), + Triangles.Num(), SubmergedTriangles.Num()); + GEngine->AddOnScreenDebugMessage(-1, 0.0f, FColor::Cyan, DebugMsg); + + for (auto Triangle : SubmergedTriangles) + { + DrawDebugSphere(GetWorld(), Triangle.Highest.Position, 2.0f, 12, FColor::Red, + false, 0.0f, 0, 1.0f); + DrawDebugSphere(GetWorld(), Triangle.Middle.Position, 2.0f, 12, FColor::Red, + false, 0.0f, 0, 1.0f); + DrawDebugSphere(GetWorld(), Triangle.Lowest.Position, 2.0f, 12, FColor::Red, + false, 0.0f, 0, 1.0f); + } + } + } +} + +int32 UBuoyancyComponent::GetNumTriangles() +{ + int32 result = 0; + if(!VolumeMesh || !VolumeMesh->RenderData) + { + return result; + } + + if(VolumeMesh->RenderData->LODResources.Num() > 0) + { + result = VolumeMesh->RenderData->LODResources[0].GetNumTriangles(); + } + return result; +} + +TArray UBuoyancyComponent::GetVertexPositions() +{ + TArray VertexPositions = TArray(); + + if(!VolumeMesh || !VolumeMesh->RenderData) + { + return VertexPositions; + } + + if(VolumeMesh->RenderData->LODResources.Num() > 0) + { + FPositionVertexBuffer* VertexBuffer = &VolumeMesh->RenderData->LODResources[0].VertexBuffers.PositionVertexBuffer; + if(VertexBuffer) + { + for(uint32 idx = 0; idx < VertexBuffer->GetNumVertices(); idx++) + { + // convert asset space vertex position to world space + FVector WorldSpaceVertexPos = GetOwner()->GetActorLocation() + GetOwner()->GetTransform().TransformVector(VertexBuffer->VertexPosition(idx)); + FVertexData temp; + temp.Position = WorldSpaceVertexPos; + VertexPositions.Add(temp); + } + } + } + return VertexPositions; +} + +TArray UBuoyancyComponent::GetTriangleIndices() +{ + TArray Indices = TArray(); + + if(!VolumeMesh || !VolumeMesh->RenderData) // return empty array + { + return Indices; + } + + if(VolumeMesh->RenderData->LODResources.Num() > 0) + { + FRawStaticIndexBuffer* IndexBuffer = &VolumeMesh->RenderData->LODResources[0].IndexBuffer; + if(IndexBuffer) + { + for(int idx = 0; idx < IndexBuffer->GetNumIndices(); idx++) + { + Indices.Add(IndexBuffer->GetIndex(idx)); + } + } + } + return Indices; +} + +void UBuoyancyComponent::ProcessTriangles(TArray& Triangles) +{ + for (auto Triangle : Triangles) + { + int32 NumSubmergedVertices = Triangle.GetNumSubmergedVertices(); + if(NumSubmergedVertices == 3) // completely submerged so add as is + { + SubmergedTriangles.Add(Triangle); + } + else if (NumSubmergedVertices == 2) + { + FVector H = Triangle.Highest.Position; + FVector M = Triangle.Middle.Position; + FVector L = Triangle.Lowest.Position; + float hH = Triangle.Highest.Depth; + float hM = Triangle.Middle.Depth; + float hL = Triangle.Lowest.Depth; + + FVector MH = H - M; + float tM = -hL/(hH - hL); + FVector MIM = tM * MH; + FVector IM = MIM + M; + + FVector LH = H - L; + float tL = -hL/(hH - hL); + FVector LIL = tL * LH; + FVector IL = LIL + L; + + SubmergedTriangles.Add(FTriangleData(IM, IL, L)); + SubmergedTriangles.Add(FTriangleData(M, IM, L)); + } + else if (NumSubmergedVertices == 1) + { + FVector H = Triangle.Highest.Position; + FVector M = Triangle.Middle.Position; + FVector L = Triangle.Lowest.Position; + float hH = Triangle.Highest.Depth; + float hM = Triangle.Middle.Depth; + float hL = Triangle.Lowest.Depth; + + FVector LM = M - L; + float tM = -hL/(hM - hL); + FVector LJM = tM * LM; + FVector JM = LJM + L; + + FVector LH = H - L; + float tH = -hL/(hH - hL); + FVector LJH = tH * LH; + FVector JH = LJH + L; + + SubmergedTriangles.Add(FTriangleData(JH, JM, L)); + } + } +} + + + diff --git a/Source/SeaOfCrooks/Private/Game/SOCGameModeBase.cpp b/Source/SeaOfCrooks/Private/Game/SOCGameModeBase.cpp new file mode 100644 index 0000000..231dc28 --- /dev/null +++ b/Source/SeaOfCrooks/Private/Game/SOCGameModeBase.cpp @@ -0,0 +1,25 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "Game/SOCGameModeBase.h" +#include "Game/SOCGameState.h" + +ASOCGameModeBase::ASOCGameModeBase() +{ + GameStateClass = ASOCGameState::StaticClass(); +} + +void ASOCGameModeBase::StartPlay() +{ + Super::StartPlay(); + + ASOCGameState* State = Cast(GameState); + if(State) + { + FActorSpawnParameters SpawnParams; + SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; + SpawnParams.Owner = State; + State->SetOcean(GetWorld()->SpawnActor(OceanClass, + FVector::ZeroVector, FRotator::ZeroRotator, SpawnParams)); + } +} diff --git a/Source/SeaOfCrooks/Private/Game/SOCGameState.cpp b/Source/SeaOfCrooks/Private/Game/SOCGameState.cpp new file mode 100644 index 0000000..4cf8a92 --- /dev/null +++ b/Source/SeaOfCrooks/Private/Game/SOCGameState.cpp @@ -0,0 +1,14 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "Game/SOCGameState.h" + +AOcean* ASOCGameState::GetOcean() +{ + return Ocean; +} + +void ASOCGameState::SetOcean(AOcean* NewOcean) +{ + Ocean = NewOcean; +} diff --git a/Source/SeaOfCrooks/Private/Ocean.cpp b/Source/SeaOfCrooks/Private/Ocean.cpp new file mode 100644 index 0000000..5fe0455 --- /dev/null +++ b/Source/SeaOfCrooks/Private/Ocean.cpp @@ -0,0 +1,41 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "Ocean.h" + +// Sets default values +AOcean::AOcean() +{ + // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. + PrimaryActorTick.bCanEverTick = true; + + OceanMesh = CreateDefaultSubobject(TEXT("OceanMesh")); + OceanMesh->SetupAttachment(RootComponent); + + OceanMesh->SetCollisionEnabled(ECollisionEnabled::NoCollision); +} + +float AOcean::GetOceanHeight() +{ + /** + * For now assume a completely flat static ocean. + * Once we get into procedural ocean and wave generation we will want to be able to pass in a world X and Y position + * and have this function return the height of the ocean at that location + */ + return GetActorLocation().Z; +} + +// Called when the game starts or when spawned +void AOcean::BeginPlay() +{ + Super::BeginPlay(); + +} + +// Called every frame +void AOcean::Tick(float DeltaTime) +{ + Super::Tick(DeltaTime); + +} + diff --git a/Source/SeaOfCrooks/Private/ShipBase.cpp b/Source/SeaOfCrooks/Private/ShipBase.cpp new file mode 100644 index 0000000..5b512d8 --- /dev/null +++ b/Source/SeaOfCrooks/Private/ShipBase.cpp @@ -0,0 +1,38 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "ShipBase.h" + +// Sets default values +AShipBase::AShipBase() +{ + // Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it. + PrimaryActorTick.bCanEverTick = true; + + ShipMesh = CreateDefaultSubobject(TEXT("ShipMesh")); + ShipMesh->SetupAttachment(RootComponent); + + BuoyancyComp = CreateDefaultSubobject(TEXT("BuoyancyComponent")); +} + +// Called when the game starts or when spawned +void AShipBase::BeginPlay() +{ + Super::BeginPlay(); + +} + +// Called every frame +void AShipBase::Tick(float DeltaTime) +{ + Super::Tick(DeltaTime); + +} + +// Called to bind functionality to input +void AShipBase::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) +{ + Super::SetupPlayerInputComponent(PlayerInputComponent); + +} + diff --git a/Source/SeaOfCrooks/Public/Components/BuoyancyComponent.h b/Source/SeaOfCrooks/Public/Components/BuoyancyComponent.h new file mode 100644 index 0000000..a79512e --- /dev/null +++ b/Source/SeaOfCrooks/Public/Components/BuoyancyComponent.h @@ -0,0 +1,116 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Components/ActorComponent.h" +#include "BuoyancyComponent.generated.h" + +USTRUCT() +struct FVertexData +{ + GENERATED_BODY() + + FVector Position; + // depth of the vertex above the surface of the water + // negative value means the vertex is submerged + float Depth; + + int32 Index; + + FVertexData() {} + + FVertexData(FVector Position) + { + this->Position = Position; + Depth = 0.0f; + } + + FVertexData(FVector Position, float Depth) + { + this->Position = Position; + this->Depth = Depth; + } + + void CalculateDepth(float SurfaceHeight) + { + Depth = Position.Z - SurfaceHeight; + } + + bool operator< (const FVertexData& rhs) const + { + return this->Depth < rhs.Depth; + } +}; + +USTRUCT() +struct FTriangleData +{ + GENERATED_BODY() + + FVertexData Highest; + FVertexData Middle; + FVertexData Lowest; + + FTriangleData() {} + + FTriangleData(FVertexData V1, FVertexData V2, FVertexData V3) + { + TArray Vertices = {V1, V2, V3}; + Vertices.Sort(); + Lowest = Vertices[0]; + Middle = Vertices[1]; + Highest = Vertices[2]; + } + + int32 GetNumSubmergedVertices() + { + int32 result = 0; + if(Highest.Depth < 0.0f) + { + result++; + } + if(Middle.Depth < 0.0f) + { + result++; + } + if(Lowest.Depth < 0.0f) + { + result++; + } + return result; + } +}; + +UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) +class SEAOFCROOKS_API UBuoyancyComponent : public UActorComponent +{ + GENERATED_BODY() + +public: + // Sets default values for this component's properties + UBuoyancyComponent(); + +protected: + UPROPERTY(BlueprintReadOnly) + UStaticMesh* VolumeMesh; + + UPROPERTY() + TArray SubmergedTriangles; + + // Called when the game starts + virtual void BeginPlay() override; + +public: + // Called every frame + virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; + +private: + int32 GetNumTriangles(); + + TArray GetVertexPositions(); + + TArray GetTriangleIndices(); + + void ProcessTriangles(TArray& Triangles); +}; diff --git a/Source/SeaOfCrooks/Public/Game/SOCGameModeBase.h b/Source/SeaOfCrooks/Public/Game/SOCGameModeBase.h new file mode 100644 index 0000000..c9cef5f --- /dev/null +++ b/Source/SeaOfCrooks/Public/Game/SOCGameModeBase.h @@ -0,0 +1,27 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" + +#include "Ocean.h" +#include "GameFramework/GameMode.h" +#include "SOCGameModeBase.generated.h" + +/** + * + */ +UCLASS() +class SEAOFCROOKS_API ASOCGameModeBase : public AGameMode +{ + GENERATED_BODY() + +public: + ASOCGameModeBase(); + +protected: + UPROPERTY(EditDefaultsOnly, Category="Ocean") + TSubclassOf OceanClass; + + virtual void StartPlay() override; +}; diff --git a/Source/SeaOfCrooks/Public/Game/SOCGameState.h b/Source/SeaOfCrooks/Public/Game/SOCGameState.h new file mode 100644 index 0000000..e196593 --- /dev/null +++ b/Source/SeaOfCrooks/Public/Game/SOCGameState.h @@ -0,0 +1,26 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" + +#include "Ocean.h" +#include "GameFramework/GameState.h" +#include "SOCGameState.generated.h" + +/** + * + */ +UCLASS() +class SEAOFCROOKS_API ASOCGameState : public AGameState +{ + GENERATED_BODY() + +public: + AOcean* GetOcean(); + + void SetOcean(AOcean* NewOcean); +protected: + UPROPERTY() + AOcean* Ocean; +}; diff --git a/Source/SeaOfCrooks/Public/Ocean.h b/Source/SeaOfCrooks/Public/Ocean.h new file mode 100644 index 0000000..2361fc6 --- /dev/null +++ b/Source/SeaOfCrooks/Public/Ocean.h @@ -0,0 +1,31 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/Actor.h" +#include "Ocean.generated.h" + +UCLASS() +class SEAOFCROOKS_API AOcean : public AActor +{ + GENERATED_BODY() + +public: + // Sets default values for this actor's properties + AOcean(); + + float GetOceanHeight(); + +protected: + UPROPERTY(EditDefaultsOnly, Category="Components") + UStaticMeshComponent* OceanMesh; + + // Called when the game starts or when spawned + virtual void BeginPlay() override; + +public: + // Called every frame + virtual void Tick(float DeltaTime) override; + +}; diff --git a/Source/SeaOfCrooks/Public/ShipBase.h b/Source/SeaOfCrooks/Public/ShipBase.h new file mode 100644 index 0000000..52b9439 --- /dev/null +++ b/Source/SeaOfCrooks/Public/ShipBase.h @@ -0,0 +1,36 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/Pawn.h" +#include "Components/BuoyancyComponent.h" +#include "ShipBase.generated.h" + +UCLASS() +class SEAOFCROOKS_API AShipBase : public APawn +{ + GENERATED_BODY() + +public: + // Sets default values for this pawn's properties + AShipBase(); + +protected: + UPROPERTY(EditDefaultsOnly, Category="Components") + UStaticMeshComponent* ShipMesh; + + UPROPERTY(EditDefaultsOnly, Category="Components") + UBuoyancyComponent* BuoyancyComp; + + // Called when the game starts or when spawned + virtual void BeginPlay() override; + +public: + // Called every frame + virtual void Tick(float DeltaTime) override; + + // Called to bind functionality to input + virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; + +}; diff --git a/Source/SeaOfCrooks/SeaOfCrooks.Build.cs b/Source/SeaOfCrooks/SeaOfCrooks.Build.cs index 96241f4..d38dcf4 100644 --- a/Source/SeaOfCrooks/SeaOfCrooks.Build.cs +++ b/Source/SeaOfCrooks/SeaOfCrooks.Build.cs @@ -8,7 +8,7 @@ public class SeaOfCrooks : ModuleRules { PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; - PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" }); + PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "RenderCore", "RHI" }); PrivateDependencyModuleNames.AddRange(new string[] { }); diff --git a/Source/SeaOfCrooks/SeaOfCrooksGameModeBase.cpp b/Source/SeaOfCrooks/SeaOfCrooksGameModeBase.cpp deleted file mode 100644 index c0a0429..0000000 --- a/Source/SeaOfCrooks/SeaOfCrooksGameModeBase.cpp +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright Epic Games, Inc. All Rights Reserved. - - -#include "SeaOfCrooksGameModeBase.h" - diff --git a/Source/SeaOfCrooks/SeaOfCrooksGameModeBase.h b/Source/SeaOfCrooks/SeaOfCrooksGameModeBase.h deleted file mode 100644 index 725ec12..0000000 --- a/Source/SeaOfCrooks/SeaOfCrooksGameModeBase.h +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright Epic Games, Inc. All Rights Reserved. - -#pragma once - -#include "CoreMinimal.h" -#include "GameFramework/GameModeBase.h" -#include "SeaOfCrooksGameModeBase.generated.h" - -/** - * - */ -UCLASS() -class SEAOFCROOKS_API ASeaOfCrooksGameModeBase : public AGameModeBase -{ - GENERATED_BODY() - -};