feat: added section activators for optimization

main
Sara 2025-01-05 23:33:12 +01:00
parent 37afae2071
commit 8daa709aa7
3 changed files with 44 additions and 0 deletions

View File

@ -12,6 +12,7 @@
#include "camera_effects.hpp"
#include "camera_effect_source.hpp"
#include "artillery_target.hpp"
#include "section_activator.hpp"
using namespace godot;
@ -28,6 +29,7 @@ void initialize_gdextension_types(ModuleInitializationLevel p_level)
GDREGISTER_CLASS(CameraEffects);
GDREGISTER_RUNTIME_CLASS(CameraEffectSource);
GDREGISTER_RUNTIME_CLASS(ArtilleryTarget);
GDREGISTER_RUNTIME_CLASS(SectionActivator);
}
extern "C"

26
src/section_activator.cpp Normal file
View File

@ -0,0 +1,26 @@
#include "section_activator.hpp"
#include "player.hpp"
void SectionActivator::_bind_methods() {
}
void SectionActivator::_enter_tree() {
this->connect("body_entered", callable_mp(this, &SectionActivator::_on_body_entered));
this->connect("body_exited", callable_mp(this, &SectionActivator::_on_body_exited));
this->set_visible(false);
this->set_process(false);
}
void SectionActivator::_on_body_entered(gd::Node *node) {
if(gd::Object::cast_to<Player>(node)) {
this->set_visible(true);
this->set_process(false);
}
}
void SectionActivator::_on_body_exited(gd::Node *node) {
if(gd::Object::cast_to<Player>(node)) {
this->set_visible(false);
this->set_process(false);
}
}

16
src/section_activator.hpp Normal file
View File

@ -0,0 +1,16 @@
#ifndef SECTION_ACTIVATOR_HPP
#define SECTION_ACTIVATOR_HPP
#include <godot_cpp/classes/area3d.hpp>
namespace gd = godot;
class SectionActivator : public gd::Area3D {
GDCLASS(SectionActivator, gd::Area3D);
static void _bind_methods();
public:
virtual void _enter_tree() override;
void _on_body_entered(gd::Node *node);
void _on_body_exited(gd::Node *node);
};
#endif // !SECTION_ACTIVATOR_HPP