Added PropDataProcessor. This will enable scene to PropData conversion to be easily scriptable. Added an api for it into PropUtils.

This commit is contained in:
Relintai 2020-07-02 17:57:11 +02:00
parent 8258fb7cfa
commit d1a782c37c
7 changed files with 184 additions and 0 deletions

1
SCsub
View File

@ -22,6 +22,7 @@ sources = [
"props/prop_data_prop.cpp",
"props/prop_data_entity.cpp",
"processor/prop_data_processor.cpp",
"clutter/ground_clutter.cpp",
"clutter/ground_clutter_foliage.cpp",

View File

@ -18,6 +18,8 @@ def get_doc_classes():
"PropDataScene",
"PropData",
"PropDataProcessor",
"GroundClutterFoliage",
"GroundClutter",

View File

@ -0,0 +1,57 @@
/*
Copyright (c) 2019-2020 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "prop_data_processor.h"
#include "scene/3d/spatial.h"
bool PropDataProcessor::handles(Node *node) {
return call("_handles", node);
}
void PropDataProcessor::process(Ref<PropData> prop_data, Node *node, const Transform &transform) {
call("_process", prop_data, node, transform);
}
bool PropDataProcessor::_handles(Node *node) {
return false;
}
void PropDataProcessor::_process(Ref<PropData> prop_data, Node *node, const Transform &transform) {
}
PropDataProcessor::PropDataProcessor() {
}
PropDataProcessor::~PropDataProcessor() {
}
void PropDataProcessor::_bind_methods() {
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::BOOL, "handles"), "_handles"));
BIND_VMETHOD(MethodInfo("_process",
PropertyInfo(Variant::OBJECT, "prop_data", PROPERTY_HINT_RESOURCE_TYPE, "PropData"),
PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node"),
PropertyInfo(Variant::TRANSFORM, "transform")));
ClassDB::bind_method(D_METHOD("handles", "node"), &PropDataProcessor::handles);
ClassDB::bind_method(D_METHOD("process", "prop_data", "node", "transform"), &PropDataProcessor::process);
ClassDB::bind_method(D_METHOD("_handles", "node"), &PropDataProcessor::_handles);
ClassDB::bind_method(D_METHOD("_process", "prop_data", "node", "transform"), &PropDataProcessor::_process);
}

View File

@ -0,0 +1,51 @@
/*
Copyright (c) 2019-2020 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef PROP_DATA_PROCESSOR_H
#define PROP_DATA_PROCESSOR_H
#include "core/math/transform.h"
#include "core/math/vector3.h"
#include "core/reference.h"
#include "../props/prop_data.h"
class Spatial;
class PropDataProcessor : public Reference {
GDCLASS(PropDataProcessor, Reference);
public:
bool handles(Node *node);
void process(Ref<PropData> prop_data, Node *node, const Transform &transform);
virtual bool _handles(Node *node);
virtual void _process(Ref<PropData> prop_data, Node *node, const Transform &transform);
PropDataProcessor();
~PropDataProcessor();
protected:
static void _bind_methods();
};
#endif

View File

@ -43,6 +43,8 @@ SOFTWARE.
#include "./editor/prop_editor_plugin.h"
#include "processor/prop_data_processor.h"
static PropUtils *prop_utils = NULL;
void register_props_types() {
@ -54,6 +56,8 @@ void register_props_types() {
ClassDB::register_class<PropDataProp>();
ClassDB::register_class<PropDataEntity>();
ClassDB::register_class<PropDataProcessor>();
ClassDB::register_class<GroundClutter>();
ClassDB::register_class<GroundClutterFoliage>();

View File

@ -22,9 +22,11 @@ SOFTWARE.
#include "prop_utils.h"
#include "../processor/prop_data_processor.h"
#include "../props/prop_data.h"
PropUtils *PropUtils::_instance;
Vector<Ref<PropDataProcessor> > PropUtils::_processors;
PropUtils *PropUtils::get_singleton() {
return _instance;
@ -34,14 +36,65 @@ Ref<PropData> PropUtils::convert_tree(Node *root) {
return Ref<PropData>();
}
int PropUtils::add_processor(const Ref<PropDataProcessor> &processor) {
PropUtils::_processors.push_back(processor);
return PropUtils::_processors.size() - 1;
}
Ref<PropDataProcessor> PropUtils::get_processor(const int index) {
ERR_FAIL_INDEX_V(index, PropUtils::_processors.size(), Ref<PropDataProcessor>());
return PropUtils::_processors[index];
}
void PropUtils::swap_processors(const int index1, const int index2) {
ERR_FAIL_INDEX(index1, PropUtils::_processors.size());
ERR_FAIL_INDEX(index2, PropUtils::_processors.size());
Ref<PropDataProcessor> a = PropUtils::_processors.get(index1);
PropUtils::_processors.set(index1, PropUtils::_processors.get(index2));
PropUtils::_processors.set(index2, a);
}
void PropUtils::remove_processor(const int index) {
ERR_FAIL_INDEX(index, PropUtils::_processors.size());
PropUtils::_processors.remove(index);
}
int PropUtils::get_processor_count() {
return PropUtils::_processors.size();
}
PropUtils::PropUtils() {
_instance = this;
}
PropUtils::~PropUtils() {
_instance = NULL;
PropUtils::_processors.clear();
}
void PropUtils::_bind_methods() {
ClassDB::bind_method(D_METHOD("convert_tree", "root"), &PropUtils::convert_tree);
ClassDB::bind_method(D_METHOD("add_processor", "processor"), &PropUtils::_add_processor_bind);
ClassDB::bind_method(D_METHOD("get_processor", "index"), &PropUtils::_get_processor_bind);
ClassDB::bind_method(D_METHOD("swap_processors", "index1", "index2"), &PropUtils::_swap_processors_bind);
ClassDB::bind_method(D_METHOD("remove_processor", "index"), &PropUtils::_remove_processor_bind);
ClassDB::bind_method(D_METHOD("get_processor_count"), &PropUtils::_get_processor_count_bind);
}
int PropUtils::_add_processor_bind(const Ref<PropDataProcessor> &processor) {
return PropUtils::add_processor(processor);
}
Ref<PropDataProcessor> PropUtils::_get_processor_bind(const int index) {
return PropUtils::get_processor(index);
}
void PropUtils::_swap_processors_bind(const int index1, const int index2) {
PropUtils::swap_processors(index1, index2);
}
void PropUtils::_remove_processor_bind(const int index) {
PropUtils::remove_processor(index);
}
int PropUtils::_get_processor_count_bind() {
return PropUtils::get_processor_count();
}

View File

@ -25,8 +25,11 @@ SOFTWARE.
#include "core/object.h"
#include "core/vector.h"
#include "core/reference.h"
class PropDataProcessor;
class PropData;
class PropUtils : public Object {
@ -37,6 +40,12 @@ public:
Ref<PropData> convert_tree(Node *root);
static int add_processor(const Ref<PropDataProcessor> &processor);
static Ref<PropDataProcessor> get_processor(const int index);
static void swap_processors(const int index1, const int index2);
static void remove_processor(const int index);
static int get_processor_count();
PropUtils();
~PropUtils();
@ -44,6 +53,13 @@ protected:
static void _bind_methods();
private:
int _add_processor_bind(const Ref<PropDataProcessor> &processor);
Ref<PropDataProcessor> _get_processor_bind(const int index);
void _swap_processors_bind(const int index1, const int index2);
void _remove_processor_bind(const int index);
int _get_processor_count_bind();
static Vector<Ref<PropDataProcessor> > _processors;
static PropUtils *_instance;
};