Browse Source

Fix Cmake files to select correct engine, upgrade icons etc (#24)

* Fix Cmake files to select correct engine, upgrade icons etc

Signed-off-by: Potter <[email protected]>
Pip Potter 3 năm trước cách đây
mục cha
commit
49fe45a4cc

+ 2 - 1
CMakeLists.txt

@@ -20,11 +20,12 @@ endfunction()
 
 if(NOT PROJECT_NAME)
     cmake_minimum_required(VERSION 3.19)
+    include(cmake/CompilerSettings.cmake)
     project(NetSoakTest
         LANGUAGES C CXX
         VERSION 1.0.0.0
     )
-    include(EngineFinder.cmake OPTIONAL)
+    include(cmake/EngineFinder.cmake OPTIONAL)
     find_package(o3de REQUIRED)
     o3de_initialize()
     add_vs_debugger_arguments()

+ 0 - 53
EngineFinder.cmake

@@ -1,53 +0,0 @@
-# {BEGIN_LICENSE}
-#
-# Copyright (c) Contributors to the Open 3D Engine Project.
-# For complete copyright and license terms please see the LICENSE at the root of this distribution.
-#
-# SPDX-License-Identifier: Apache-2.0 OR MIT
-#
-#
-# {END_LICENSE}
-
-# This file is copied during engine registration. Edits to this file will be lost next
-# time a registration happens.
-include_guard()
-
-# Read the engine name from the project_json file
-file(READ ${CMAKE_CURRENT_LIST_DIR}/project.json project_json)
-string(JSON LY_ENGINE_NAME_TO_USE ERROR_VARIABLE json_error GET ${project_json} engine)
-if(json_error)
-    message(FATAL_ERROR "Unable to read key 'engine' from 'project.json', error: ${json_error}")
-endif()
-
-# Read the list of paths from ~.o3de/o3de_manifest.json
-file(TO_CMAKE_PATH "$ENV{USERPROFILE}" home_directory) # Windows
-if((NOT home_directory) OR (NOT EXISTS ${home_directory}))
-    file(TO_CMAKE_PATH "$ENV{HOME}" home_directory)# Unix
-endif()
-
-if (NOT home_directory)
-    message(FATAL_ERROR "Cannot find user home directory, the o3de manifest cannot be found")
-endif()
-# Set manifest path to path in the user home directory
-set(manifest_path ${home_directory}/.o3de/o3de_manifest.json)
-
-if(EXISTS ${manifest_path})
-    file(READ ${manifest_path} manifest_json)
-    string(JSON engines_count ERROR_VARIABLE json_error LENGTH ${manifest_json} engines)
-    if(json_error)
-        message(FATAL_ERROR "Unable to read key 'engines' from '${manifest_path}', error: ${json_error}")
-    endif()
-    math(EXPR engines_count "${engines_count}-1")
-    foreach(engine_path_index RANGE ${engines_count})
-        string(JSON engine_path ERROR_VARIABLE json_error GET ${manifest_json} engines ${engine_path_index})
-        if(${json_error})
-            message(FATAL_ERROR "Unable to read engines[${engine_path_index}] '${manifest_path}', error: ${json_error}")
-        endif()
-        list(APPEND CMAKE_MODULE_PATH "${engine_path}/cmake")
-    endforeach()
-endif()
-
-
-
-
-

+ 8 - 9
Gem/Code/Source/NetSoakTestSystemComponent.cpp

@@ -93,8 +93,8 @@ namespace NetSoakTest
     static const AZStd::string_view s_networkInterfaceName("NetSoakNetworkInterface");
     static const AZStd::string_view s_loopbackInterfaceName("NetSoakLoopbackInterface");
 
-    AZ_CVAR(AZ::TimeMs, soak_latencyms, AZ::TimeMs(0), nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "Simulated connection quality latency");
-    AZ_CVAR(AZ::TimeMs, soak_variancems, AZ::TimeMs(0), nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "Simulated connection quality variance");
+    AZ_CVAR(AZ::TimeMs, soak_latencyms, AZ::Time::ZeroTimeMs, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "Simulated connection quality latency");
+    AZ_CVAR(AZ::TimeMs, soak_variancems, AZ::Time::ZeroTimeMs, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "Simulated connection quality variance");
     AZ_CVAR(uint16_t, soak_losspercentage, 0, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "Simulated connection quality packet drop rate");
     AZ_CVAR(AZ::CVarFixedString, soak_serveraddr, AZ::CVarFixedString("127.0.0.1"), nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "The address of the server or host to connect to");
     AZ_CVAR(uint16_t, soak_port, 33450, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "The port that this soak test will bind to for game traffic");
@@ -103,7 +103,7 @@ namespace NetSoakTest
 
     void NetSoakTestSystemComponent::Reflect(AZ::ReflectContext* context)
     {
-        if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
+        if (auto serialize = azrtti_cast<AZ::SerializeContext*>(context))
         {
             serialize->Class<NetSoakTestSystemComponent, AZ::Component>()
                 ->Version(0)
@@ -176,7 +176,7 @@ namespace NetSoakTest
 
     void NetSoakTestSystemComponent::OnTick(float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time)
     {
-        [[maybe_unused]] AZ::TimeMs elapsedMs = aznumeric_cast<AZ::TimeMs>(aznumeric_cast<int64_t>(deltaTime / 1000.0f));
+        [[maybe_unused]] auto elapsedMs = aznumeric_cast<AZ::TimeMs>(aznumeric_cast<int64_t>(deltaTime / 1000.0f));
 
         NetSoakTestPackets::Small packet;
 
@@ -184,11 +184,11 @@ namespace NetSoakTest
         {
             connection.SendReliablePacket(packet);
 
-            uint32_t rand_int = rand();
+            const uint32_t rand_int = rand();
             if (rand_int % 10 == 1)
             {
                 NetSoakTest::TestNetworkBuffer buffer = NetSoakTest::TestNetworkBuffer(NetSoakTest::MassiveBuffer);
-                NetSoakTestPackets::Large* large = new NetSoakTestPackets::Large(buffer);
+                const NetSoakTestPackets::Large* large = new NetSoakTestPackets::Large(buffer);
                 connection.SendReliablePacket(*large);
                 delete large;
             }
@@ -199,7 +199,7 @@ namespace NetSoakTest
                 unreliable.SetSmallDatum(2);
                 connection.SendUnreliablePacket(unreliable);
             }
-            
+
         };
 
         m_networkInterface->GetConnectionSet().VisitConnections(visitor);
@@ -259,7 +259,6 @@ namespace NetSoakTest
 
     void NetSoakTestSystemComponent::OnPacketLost([[maybe_unused]] IConnection* connection, [[maybe_unused]] PacketId packetId)
     {
-        ;
     }
 
     void NetSoakTestSystemComponent::OnDisconnect(IConnection* connection, [[maybe_unused]] DisconnectReason reason, [[maybe_unused]] AzNetworking::TerminationEndpoint endpoint)
@@ -273,7 +272,7 @@ namespace NetSoakTest
         networkInterfaces.push_back(AZ::Interface<INetworking>::Get()->RetrieveNetworkInterface(AZ::Name(s_networkInterfaceName)));
         networkInterfaces.push_back(AZ::Interface<INetworking>::Get()->RetrieveNetworkInterface(AZ::Name(s_loopbackInterfaceName)));
 
-        for (auto& networkInterface : networkInterfaces)
+        for (const auto& networkInterface : networkInterfaces)
         {
             const char* protocol = networkInterface->GetType() == ProtocolType::Tcp ? "Tcp" : "Udp";
             const char* trustZone = networkInterface->GetTrustZone() == TrustZone::ExternalClientToServer ? "ExternalClientToServer" : "InternalServerToServer";

+ 1 - 1
Gem/Code/Source/NetSoakTestTypes.h

@@ -24,7 +24,7 @@ namespace NetSoakTest
         constexpr char hexchar[] = "0123456789ABCDEF";
 
         TestNetworkBuffer rBuffer;
-        for (int i = 0; i < TestSize; ++i)
+        for (size_t i = 0; i < TestSize; ++i)
         {
             rBuffer.append(1, hexchar[i % (sizeof(hexchar) - 1)]);
         }

+ 0 - 3
Gem/Resources/CryEngineLogoLauncher.bmp

@@ -1,3 +0,0 @@
-version https://git-lfs.github.com/spec/v1
-oid sha256:cf6d56fe4c367d39bd78500dd34332fcad57ad41241768b52781dbdb60ddd972
-size 347568

+ 2 - 2
Gem/Resources/GameSDK.ico

@@ -1,3 +1,3 @@
 version https://git-lfs.github.com/spec/v1
-oid sha256:d717f77fe01f45df934a61bbc215e5322447d21e16f3cebcf2a02f148178f266
-size 106449
+oid sha256:ba0704efd586fee72b3d45b19163a1b67cd5594bcbf57cb28d796e2919502aba
+size 148143

+ 3 - 0
Gem/Resources/LegacyLogoLauncher.bmp

@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:ef3584c695998fd5f2d137148a11f68602523c817af5d18fdd6c56b0b5278a6c
+size 462760

+ 5 - 4
README.md

@@ -96,14 +96,14 @@ If you have a Git credential helper configured, you should not be prompted for y
 
 ## Running the Project
 
-Run the netsoak ServerLauncher with the relevant options (see below). It is strongly recommended to use --rhi=null when launching NetSoakTest.ServerLauncher
-
-To pass command line values when launching the executable the format is ```--<command>=<value>```
+Run the netsoak ServerLauncher with the relevant comand line values (see full options below), using the format is ```--<command>=<value>```
 
 ``` 
-NetSoakTest.ServerLauncher --soak_mode=loopback --rhi=null 
+NetSoakTest.ServerLauncher --soak_mode=loopback 
 ```
 
+When running tests, you can use the [debug console](https://www.o3de.org/docs/user-guide/appendix/cvars/debugging/#using-console-debug-views) and the `DumpSoakStats` command to see point-in-time stats from the test. The test will run indefinitely until such point it is terminated.
+
 Note: All O3DE projects generate a GameLauncher and a ServerLauncher. NetSoakTest does not utilize its GameLauncher by design.
 
 ### Options
@@ -118,6 +118,7 @@ Note: All O3DE projects generate a GameLauncher and a ServerLauncher. NetSoakTes
 | soak_port | The port that this soak test will bind to for game traffic | 33450 |
 | soak_protocol | Soak test protocol (TCP or UDP) | udp | 
 | soak_mode | The operating mode for the soak test, options are loopback, client or host. `Loopback` has two connection within the application feed traffic to each other in a loop. `Client` expects to connect to a server hosted at soak_serveraddr. `Host` hosts a server for clients to connect to | Loopback | 
+| DumpSoakStats | Dump snapshot of soak test networking stats to console | N/A|
 
 Other networking features such as Compression or DTLS/TLS can be enabled/disabled in the same way they would be in a production environment. For example:
 

+ 13 - 0
cmake/CompilerSettings.cmake

@@ -0,0 +1,13 @@
+#
+# Copyright (c) Contributors to the Open 3D Engine Project.
+# For complete copyright and license terms please see the LICENSE at the root of this distribution.
+#
+# SPDX-License-Identifier: Apache-2.0 OR MIT
+#
+#
+
+# File to tweak compiler settings before compiler detection happens (before project() is called)
+# We dont have PAL enabled at this point, so we can only use pure-CMake variables
+if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux")
+    include(cmake/Platform/Linux/CompilerSettings_linux.cmake)
+endif()

+ 91 - 0
cmake/EngineFinder.cmake

@@ -0,0 +1,91 @@
+#
+# Copyright (c) Contributors to the Open 3D Engine Project.
+# For complete copyright and license terms please see the LICENSE at the root of this distribution.
+#
+# SPDX-License-Identifier: Apache-2.0 OR MIT
+#
+#
+
+# This file is copied during engine registration. Edits to this file will be lost next
+# time a registration happens.
+
+include_guard()
+
+# Read the engine name from the project_json file
+file(READ ${CMAKE_CURRENT_SOURCE_DIR}/project.json project_json)
+set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/project.json)
+
+string(JSON LY_ENGINE_NAME_TO_USE ERROR_VARIABLE json_error GET ${project_json} engine)
+if(json_error)
+    message(FATAL_ERROR "Unable to read key 'engine' from 'project.json'\nError: ${json_error}")
+endif()
+
+if(CMAKE_MODULE_PATH)
+    foreach(module_path ${CMAKE_MODULE_PATH})
+        if(EXISTS ${module_path}/Findo3de.cmake)
+            file(READ ${module_path}/../engine.json engine_json)
+            string(JSON engine_name ERROR_VARIABLE json_error GET ${engine_json} engine_name)
+            if(json_error)
+                message(FATAL_ERROR "Unable to read key 'engine_name' from 'engine.json'\nError: ${json_error}")
+            endif()
+            if(LY_ENGINE_NAME_TO_USE STREQUAL engine_name)
+                return() # Engine being forced through CMAKE_MODULE_PATH
+            endif()
+        endif()
+    endforeach()
+endif()
+
+if(DEFINED ENV{USERPROFILE} AND EXISTS $ENV{USERPROFILE})
+    set(manifest_path $ENV{USERPROFILE}/.o3de/o3de_manifest.json) # Windows
+else()
+    set(manifest_path $ENV{HOME}/.o3de/o3de_manifest.json) # Unix
+endif()
+
+set(registration_error [=[
+Engine registration is required before configuring a project.
+Run 'scripts/o3de register --this-engine' from the engine root.
+]=])
+
+# Read the ~/.o3de/o3de_manifest.json file and look through the 'engines_path' object.
+# Find a key that matches LY_ENGINE_NAME_TO_USE and use that as the engine path.
+if(EXISTS ${manifest_path})
+    file(READ ${manifest_path} manifest_json)
+    set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${manifest_path})
+
+    string(JSON engines_path_count ERROR_VARIABLE json_error LENGTH ${manifest_json} engines_path)
+    if(json_error)
+        message(FATAL_ERROR "Unable to read key 'engines_path' from '${manifest_path}'\nError: ${json_error}\n${registration_error}")
+    endif()
+
+    string(JSON engines_path_type ERROR_VARIABLE json_error TYPE ${manifest_json} engines_path)
+    if(json_error OR NOT ${engines_path_type} STREQUAL "OBJECT")
+        message(FATAL_ERROR "Type of 'engines_path' in '${manifest_path}' is not a JSON Object\nError: ${json_error}")
+    endif()
+
+    math(EXPR engines_path_count "${engines_path_count}-1")
+    foreach(engine_path_index RANGE ${engines_path_count})
+        string(JSON engine_name ERROR_VARIABLE json_error MEMBER ${manifest_json} engines_path ${engine_path_index})
+        if(json_error)
+            message(FATAL_ERROR "Unable to read 'engines_path/${engine_path_index}' from '${manifest_path}'\nError: ${json_error}")
+        endif()
+
+        if(LY_ENGINE_NAME_TO_USE STREQUAL engine_name)
+            string(JSON engine_path ERROR_VARIABLE json_error GET ${manifest_json} engines_path ${engine_name})
+            if(json_error)
+                message(FATAL_ERROR "Unable to read value from 'engines_path/${engine_name}'\nError: ${json_error}")
+            endif()
+
+            if(engine_path)
+                list(APPEND CMAKE_MODULE_PATH "${engine_path}/cmake")
+                return()
+            endif()
+        endif()
+    endforeach()
+    
+    message(FATAL_ERROR "The project.json uses engine name '${LY_ENGINE_NAME_TO_USE}' but no engine with that name has been registered.\n${registration_error}")
+else()
+    # If the user is passing CMAKE_MODULE_PATH we assume thats where we will find the engine
+    if(NOT CMAKE_MODULE_PATH)
+        message(FATAL_ERROR "O3DE Manifest file not found.\n${registration_error}")
+    endif()
+endif()

+ 34 - 0
cmake/Platform/Linux/CompilerSettings_linux.cmake

@@ -0,0 +1,34 @@
+#
+# Copyright (c) Contributors to the Open 3D Engine Project.
+# For complete copyright and license terms please see the LICENSE at the root of this distribution.
+#
+# SPDX-License-Identifier: Apache-2.0 OR MIT
+#
+#
+
+if(NOT CMAKE_C_COMPILER AND NOT CMAKE_CXX_COMPILER AND NOT "$ENV{CC}" AND NOT "$ENV{CXX}")
+    set(path_search
+        /bin
+        /usr/bin
+        /usr/local/bin
+        /sbin
+        /usr/sbin
+        /usr/local/sbin
+    )
+    list(TRANSFORM path_search APPEND "/clang-[0-9]*")
+    file(GLOB clang_versions ${path_search})
+    if(clang_versions)
+        # Find and pick the highest installed version
+        list(SORT clang_versions COMPARE NATURAL)
+        list(GET clang_versions 0 clang_higher_version_path)
+        string(REGEX MATCH "clang-([0-9.]*)" clang_higher_version ${clang_higher_version_path})
+        if(CMAKE_MATCH_1)
+            set(CMAKE_C_COMPILER clang-${CMAKE_MATCH_1})
+            set(CMAKE_CXX_COMPILER clang++-${CMAKE_MATCH_1})
+        else()
+            message(FATAL_ERROR "Clang not found, please install clang")
+        endif()
+    else()
+        message(FATAL_ERROR "Clang not found, please install clang")
+    endif()
+endif()

+ 2 - 2
preview.png

@@ -1,3 +1,3 @@
 version https://git-lfs.github.com/spec/v1
-oid sha256:a18fae4040a22d2bb359a8ca642b97bb8f6468eeb52e2826b3b029bd8f1350b6
-size 5466
+oid sha256:76f4b96078a6140ef3442116946e09b33b53b4c20f662803eddd503f5c7e3b08
+size 5590