Integrate Perfetto with Godot-CPP

This change adds an example on how to integrate Perfetto
with Godot-CPP projects.
pull/830/head
Gergely Kis 2022-09-05 23:11:09 +02:00
parent 02333f8dae
commit bab94a5120
3 changed files with 11 additions and 0 deletions

View File

@ -179,6 +179,7 @@ opts.Add(
) )
opts.Add(BoolVariable("build_library", "Build the godot-cpp library.", True)) opts.Add(BoolVariable("build_library", "Build the godot-cpp library.", True))
opts.Add(PathVariable("perfetto", "Path to the perfetto include directory in the Godot Engine source", None, PathVariable.PathIsDir))
opts.Update(env) opts.Update(env)
Help(opts.GenerateHelpText(env)) Help(opts.GenerateHelpText(env))

View File

@ -6,6 +6,10 @@ env = SConscript("../SConstruct")
env.Append(CPPPATH=['src/']) env.Append(CPPPATH=['src/'])
sources = Glob('src/*.cpp') sources = Glob('src/*.cpp')
if env["perfetto"]:
env.Append(CPPDEFINES=["ENABLE_PERFETTO"])
env.Append(CPPPATH=[env["perfetto"]])
library = env.SharedLibrary( library = env.SharedLibrary(
"bin/libgdexample.{}.{}.{}{}".format( "bin/libgdexample.{}.{}.{}{}".format(
env["platform"], env["target"], env["arch_suffix"], env["SHLIBSUFFIX"] env["platform"], env["target"], env["arch_suffix"], env["SHLIBSUFFIX"]

View File

@ -31,6 +31,8 @@
#include <Godot.hpp> #include <Godot.hpp>
#include <Reference.hpp> #include <Reference.hpp>
#include "godot_profiler.h"
using namespace godot; using namespace godot;
class SimpleClass : public Reference { class SimpleClass : public Reference {
@ -41,15 +43,18 @@ public:
/** `_init` must exist as it is called by Godot. */ /** `_init` must exist as it is called by Godot. */
void _init() { void _init() {
TRACE_EVENT("app_main", "SimpleClass::_init");
_name = String("SimpleClass"); _name = String("SimpleClass");
_value = 0; _value = 0;
} }
void test_void_method() { void test_void_method() {
TRACE_EVENT("app_main", "SimpleClass::test_void_method");
Godot::print("This is test"); Godot::print("This is test");
} }
Variant method(Variant arg) { Variant method(Variant arg) {
TRACE_EVENT("app_main", "SimpleClass::method");
Variant ret; Variant ret;
ret = arg; ret = arg;
@ -57,6 +62,7 @@ public:
} }
static void _register_methods() { static void _register_methods() {
TRACE_EVENT("app_main", "_register_methods");
register_method("method", &SimpleClass::method); register_method("method", &SimpleClass::method);
/** /**