dogot c++ plugin example
- User
dogot c++ plugin example
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
dogot c++ plugin example
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
The following is a simple example of a C++ plugin for Dogot (Godot Engine). In this example, we will create a C++ plugin that adds a GDNative node that prints "Hello, C++!" when _process() is called.
Note that for this example, you must have the Godot C++ headers setup and GDNativeLibrary resource configured to link the plugin with Godot. An excellent tutorial for setting up a Godot C++ project can be found here.
hello_cpp.h:#ifndef HELLO_CPP_H
#define HELLO_CPP_H
#include <Godot.hpp>
#include <Node.hpp>
namespace godot {
class HelloCpp : public Node {
GODOT_CLASS(HelloCpp, Node)
public:
static void _register_methods();
HelloCpp();
~HelloCpp();
void _init();
void _process(float delta);
};
}
#endif // HELLO_CPP_H
hello_cpp.cpp:#include "hello_cpp.h"
using namespace godot;
void HelloCpp::_register_methods() {
register_method("_process", &HelloCpp::_process);
}
HelloCpp::HelloCpp() {
}
HelloCpp::~HelloCpp() {
}
void HelloCpp::_init() {
}
void HelloCpp::_process(float delta) {
Godot::print("Hello, C++!");
}
init.cpp to initialize the plugin:#include <Godot.hpp>
#include <Engine.hpp>
#include "hello_cpp.h"
using namespace godot;
extern "C" void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *o) {
godot::Godot::gdnative_init(o);
}
extern "C" void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_options *o) {
godot::Godot::gdnative_terminate(o);
}
extern "C" void GDN_EXPORT godot_nativescript_init(void *handle) {
godot::Godot::nativescript_init(handle);
godot::register_class<godot::HelloCpp>();
}
SConstruct file and running scons platform=<your_platform>:import os
env = Environment()
# Change os according to your platform
env.Append(CPPPATH=['/path/to/godot-cpp/include', '/path/to/godot-cpp/include/core', '/path/to/godot-cpp/include/gen', '/path/to/godot-cpp/godot_headers'])
# Change extension according to your platform
env.Append(LIBPATH=['/path/to/godot-cpp/bin'])
env.Append(LIBS=['godot-cpp.<your_platform>.<debug|release>.<shared|static>'])
env.Append(CPPFLAGS=['-std=c++14'])
if os.name == 'posix':
env.Append(CPPFLAGS=['-fPIC'])
env.SharedLibrary(target="hello_cpp", source=['hello_cpp.cpp', 'init.cpp'])
GDNativeLibrary resource in Godot project:[gd_resource type="GDNativeLibrary" load_steps=1 format=2]
[ext_resource path="res://libhello_cpp.so" type="DynamicLibrary" id=1]
[resource]
path.unix = ExtResource( 1 )
Now, when HelloCpp is attached to a Node in a Godot scene and the game is run, the console will print "Hello, C++!" once every frame. This demonstrates a basic Godot C++ plugin example that utilizes GDNative.