Bladeren bron

A few tweaks and Qt5 package fix, adding JS Profiler::BeginBlock support and TypeScript decl

Josh Engebretson 8 jaren geleden
bovenliggende
commit
d826df8983

+ 3 - 0
Script/Packages/Atomic/Core.json

@@ -45,6 +45,9 @@
 			"subscribeToEvent(sender:AObject, eventType:string, callback:(data: any) => void);",
 			"subscribeToEvent(eventMetaData:Atomic.EventMetaData);",
 			"subscribeToEvent(sender:AObject, eventMetaData:Atomic.EventMetaData);"
+		],
+		"Profiler" : [
+			"beginBlock(name:string, filename:string, line:number, argb?:number, status?:Atomic.ProfilerBlockStatus );"
 		]
 	},
 	"haxe_decl" : {

+ 2 - 2
Source/Atomic/Core/Profiler.cpp

@@ -130,7 +130,7 @@ bool Profiler::GetEventProfilingEnabled() const
     return enableEventProfiling_;
 }
 
-void Profiler::BeginBlock(const char* name, const char* file, int line, unsigned int color, unsigned char status)
+void Profiler::BeginBlock(const char* name, const char* file, int line, unsigned int argb, unsigned char status)
 {
 #if ATOMIC_PROFILING
     // Line used as starting hash value for efficiency.
@@ -142,7 +142,7 @@ void Profiler::BeginBlock(const char* name, const char* file, int line, unsigned
     {
         String uniqueName = ToString("%s:%d", file, line);
         desc = ::profiler::registerDescription((::profiler::EasyBlockStatus)status, uniqueName.CString(), name, file,
-                                               line, ::profiler::BLOCK_TYPE_BLOCK, color, true);
+                                               line, ::profiler::BLOCK_TYPE_BLOCK, argb, true);
     }
     else
         desc = it->second_;

+ 52 - 0
Source/AtomicJS/Javascript/JSCore.cpp

@@ -21,6 +21,7 @@
 //
 
 #include <Atomic/Core/ProcessUtils.h>
+#include <Atomic/Core/Profiler.h>
 
 #include "JSCore.h"
 #include "JSEventHelper.h"
@@ -224,6 +225,51 @@ static int Atomic_GetArguments(duk_context* ctx)
 
 }
 
+static int Profiler_BeginBlock(duk_context* ctx)
+{
+
+#if ATOMIC_PROFILING
+    // Get the Profiler instance
+    duk_push_this(ctx);
+    Profiler* profiler = js_to_class_instance<Profiler>(ctx, -1, 0);
+    duk_pop(ctx);
+
+    // early out, this should never happen
+    if (!profiler)
+    {
+        return 0;
+    }
+
+    // get the number of args
+    duk_idx_t top = duk_get_top(ctx);
+
+    // we need at least 3
+    if ( top < 3)
+    {
+        return 0;
+    }
+
+    // parse args
+    const char* name = duk_require_string(ctx, 0);
+    const char* filename = duk_require_string(ctx, 1);
+    int line = duk_require_number(ctx, 2);
+    unsigned argb = (top > 3) ? (unsigned) duk_require_number(ctx, 3) : PROFILER_COLOR_DEFAULT;
+    unsigned char status = (top > 4) ? (unsigned) duk_require_number(ctx, 4) : ProfilerBlockStatus::ON;
+
+    profiler->BeginBlock(name, filename, line, argb, status);
+
+#else
+    static bool warned = false;
+    if (!warned)
+    {
+        warned = true;
+        ATOMIC_LOGWARNING("Engine is built without profiler support.");
+    }
+#endif
+
+    return 0;
+}
+
 void jsapi_init_core(JSVM* vm)
 {
     duk_context* ctx = vm->GetJSContext();
@@ -241,6 +287,12 @@ void jsapi_init_core(JSVM* vm)
     duk_push_c_function(ctx, Object_SendEvent, DUK_VARARGS);
     duk_put_prop_string(ctx, -2, "sendEvent");
     duk_pop(ctx); // pop AObject prototype
+
+    js_class_get_prototype(ctx, "Atomic", "Profiler");
+    duk_push_c_function(ctx, Profiler_BeginBlock, DUK_VARARGS);
+    duk_put_prop_string(ctx, -2, "beginBlock");
+    duk_pop(ctx); // pop Profiler prototype
+
 }
 
 }

+ 10 - 1
Source/ThirdParty/easy_profiler/CMakeLists.txt

@@ -7,6 +7,9 @@ set(EASY_PROGRAM_VERSION_PATCH 0)
 set(EASY_PRODUCT_VERSION_STRING "${EASY_PROGRAM_VERSION_MAJOR}.${EASY_PROGRAM_VERSION_MINOR}.${EASY_PROGRAM_VERSION_PATCH}")
 
 # ATOMIC BEGIN
+
+find_package(Qt5Widgets)
+
 set(EASY_OPTION_LIB_STATIC ON CACHE BOOL "" FORCE)
 set(EASY_OPTION_PREDEFINED_COLORS ON CACHE BOOL "" FORCE)
 set(EASY_PROFILER_NO_SAMPLES ON CACHE BOOL "" FORCE)
@@ -30,7 +33,13 @@ macro(easy_define_target_option TARGET SOURCE_OPTION TARGET_DEFINITION)
 endmacro()
 
 add_subdirectory(easy_profiler_core)
-add_subdirectory(profiler_gui)
+
+# ATOMIC BEGIN
+# Only include the Qt client if on we're building desktop platform and Qt5 was found on system
+if (ATOMIC_DESKTOP AND Qt5Widgets_FOUND)
+    add_subdirectory(profiler_gui)
+endif()
+#ATOMIC END
 
 if (NOT EASY_PROFILER_NO_SAMPLES)
     add_subdirectory(sample)

+ 2 - 1
Source/ThirdParty/easy_profiler/easy_profiler_core/CMakeLists.txt

@@ -217,7 +217,8 @@ install(
 )
 endif ()
 
-if (MSVC)
+# If we're on MSVC, we need a /MD version of the easy profiler library to link with Qt
+if (MSVC AND Qt5Widgets_FOUND)
     add_library(easy_profiler_md ${EASY_OPTION_LIB_TYPE} ${SOURCES} resources.rc)
     foreach(prop COMPILE_DEFINITIONS COMPILE_OPTIONS CXX_STANDARD CXX_STANDARD_REQUIRED INCLUDE_DIRECTORIES INTERFACE_COMPILE_DEFINITIONS INTERFACE_COMPILE_OPTIONS INTERFACE_INCLUDE_DIRECTORIES INTERFACE_LINK_LIBRARIES)
         get_target_property(val easy_profiler ${prop})

+ 5 - 2
Source/ThirdParty/easy_profiler/profiler_gui/CMakeLists.txt

@@ -4,9 +4,12 @@ set(CMAKE_AUTOMOC ON)
 set(CMAKE_AUTORCC ON)
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 
-find_package(Qt5Widgets)
+# ATOMIC BEGIN
+# moved to easy profiler root CMake, to avoid duplicate checks
+# find_package(Qt5Widgets)
+# ATOMIC END
 
-if (NOT Qt5Widgets_FOUND)
+if (Qt5Widgets_FOUND)
     if (NOT("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") AND WIN32)
         set(APPLICATION_PLATFORM WIN32)
     endif ()