Removed some of the modules.
8
modules/broken_seals_module/.gitignore
vendored
@ -1,8 +0,0 @@
|
||||
.import
|
||||
*.d
|
||||
*.o
|
||||
*.meta
|
||||
*.obj
|
||||
*.pyc
|
||||
*.bc
|
||||
*.os
|
@ -1,19 +0,0 @@
|
||||
Copyright (c) 2020-2023 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.
|
@ -1,25 +0,0 @@
|
||||
import os
|
||||
|
||||
Import('env')
|
||||
|
||||
module_env = env.Clone()
|
||||
|
||||
sources = [
|
||||
|
||||
"register_types.cpp",
|
||||
|
||||
"biome_terrain_generator.cpp",
|
||||
]
|
||||
|
||||
if ARGUMENTS.get('custom_modules_shared', 'no') == 'yes':
|
||||
# Shared lib compilation
|
||||
module_env.Append(CCFLAGS=['-fPIC'])
|
||||
module_env['LIBS'] = []
|
||||
shared_lib = module_env.SharedLibrary(target='#bin/broken_seals_module', source=sources)
|
||||
shared_lib_shim = shared_lib[0].name.rsplit('.', 1)[0]
|
||||
env.Append(LIBS=[shared_lib_shim])
|
||||
env.Append(LIBPATH=['#bin'])
|
||||
else:
|
||||
# Static compilation
|
||||
module_env.add_source_files(env.modules_sources, sources)
|
||||
|
@ -1,137 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2020-2023 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 "biome_terrain_generator.h"
|
||||
|
||||
#include "core/config/engine.h"
|
||||
|
||||
#include "core/math/math_funcs.h"
|
||||
|
||||
#include "modules/modules_enabled.gen.h"
|
||||
|
||||
#ifdef MODULE_VOXELMAN_ENABLED
|
||||
#include "../voxelman/world/default/voxel_chunk_default.h"
|
||||
#include "../voxelman/world/voxel_chunk.h"
|
||||
#endif
|
||||
|
||||
#include "../entity_spell_system/singletons/ess.h"
|
||||
#include "../entity_spell_system/spawners/ess_entity_spawner.h"
|
||||
#include "../opensimplex/open_simplex_noise.h"
|
||||
|
||||
int BiomeTerrainGenerator::get_current_seed() {
|
||||
return _current_seed;
|
||||
}
|
||||
void BiomeTerrainGenerator::set_current_seed(int value) {
|
||||
_current_seed = value;
|
||||
}
|
||||
|
||||
#ifdef MODULE_VOXELMAN_ENABLED
|
||||
void BiomeTerrainGenerator::generate_simple_terrarin(Ref<VoxelChunk> chunk, bool spawn_mobs) {
|
||||
Ref<OpenSimplexNoise> noise;
|
||||
noise.instance();
|
||||
noise->set_seed(10 * get_current_seed());
|
||||
noise->set_octaves(4);
|
||||
noise->set_period(280.0);
|
||||
noise->set_persistence(0.8);
|
||||
|
||||
Ref<OpenSimplexNoise> terr_noise;
|
||||
terr_noise.instance();
|
||||
terr_noise->set_seed(10 * 321 + 112 * get_current_seed());
|
||||
terr_noise->set_octaves(4);
|
||||
terr_noise->set_period(90.0);
|
||||
terr_noise->set_persistence(0.9);
|
||||
|
||||
Ref<OpenSimplexNoise> det_noise;
|
||||
det_noise.instance();
|
||||
det_noise->set_seed(10 * 3231 + 112 * get_current_seed());
|
||||
det_noise->set_octaves(6);
|
||||
det_noise->set_period(80.0);
|
||||
det_noise->set_persistence(0.3);
|
||||
|
||||
for (int x = -chunk->get_margin_start(); x < chunk->get_size_x() + chunk->get_margin_end(); ++x) {
|
||||
for (int z = -chunk->get_margin_start(); z < chunk->get_size_z() + chunk->get_margin_end(); ++z) {
|
||||
float val = noise->get_noise_2d(x + (chunk->get_position_x() * chunk->get_size_x()), z + (chunk->get_position_z() * chunk->get_size_z()));
|
||||
val *= val;
|
||||
val *= 200.0;
|
||||
val += 2.0;
|
||||
|
||||
float tv = terr_noise->get_noise_2d(x + (chunk->get_position_x() * chunk->get_size_x()), z + (chunk->get_position_z() * chunk->get_size_z()));
|
||||
tv *= tv * tv * tv;
|
||||
val += tv * 2.0;
|
||||
|
||||
float dval = noise->get_noise_2d(x + (chunk->get_position_x() * chunk->get_size_x()), z + (chunk->get_position_z() * chunk->get_size_z()));
|
||||
|
||||
val += dval * 6.0;
|
||||
|
||||
int v = (int(val));
|
||||
|
||||
v -= chunk->get_position_y() * (chunk->get_size_y());
|
||||
|
||||
if (v > chunk->get_size_y() + chunk->get_margin_end())
|
||||
v = chunk->get_size_y() + chunk->get_margin_end();
|
||||
|
||||
for (int y = -chunk->get_margin_start(); y < v; y++) {
|
||||
Math::seed(x + (chunk->get_position_x() * chunk->get_size_x()) + z + (chunk->get_position_z() * chunk->get_size_z()) + y + (chunk->get_position_y() * chunk->get_size_y()));
|
||||
|
||||
if (v < 2)
|
||||
chunk->set_voxel(1, x, y, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
|
||||
else if (v == 2)
|
||||
chunk->set_voxel(3, x, y, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
|
||||
else
|
||||
chunk->set_voxel(2, x, y, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
|
||||
|
||||
float val2 = (val - static_cast<int>(val)) * 4.0;
|
||||
val2 = static_cast<int>(val2);
|
||||
val2 /= 4.0;
|
||||
|
||||
chunk->set_voxel(static_cast<int>(255.0 * val2), x, y, z, VoxelChunkDefault::DEFAULT_CHANNEL_ISOLEVEL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//if (!Engine::get_singleton()->is_editor_hint() && chunk->get_position_y() == 0 && spawn_mobs) {
|
||||
// Vector3 v = Vector3(chunk->get_position_x() * chunk->get_size_x() * chunk->get_voxel_scale() + chunk->get_size_x() / 2,
|
||||
// (chunk->get_position_y() + 1) * chunk->get_size_y() * chunk->get_voxel_scale(),
|
||||
// chunk->get_position_z()) *
|
||||
// (chunk->get_size_z() * chunk->get_voxel_scale() + chunk->get_size_z() / 2);
|
||||
//
|
||||
// ESS::get_singleton()->get_entity_spawner()->call("spawn_mob", 0, Math::rand() % 3, v);
|
||||
// }
|
||||
}
|
||||
#endif
|
||||
|
||||
BiomeTerrainGenerator::BiomeTerrainGenerator() {
|
||||
_current_seed = 0;
|
||||
}
|
||||
|
||||
BiomeTerrainGenerator::~BiomeTerrainGenerator() {
|
||||
}
|
||||
|
||||
void BiomeTerrainGenerator::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_current_seed"), &BiomeTerrainGenerator::get_current_seed);
|
||||
ClassDB::bind_method(D_METHOD("set_current_seed", "value"), &BiomeTerrainGenerator::set_current_seed);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "current_seed"), "set_current_seed", "get_current_seed");
|
||||
|
||||
#ifdef MODULE_VOXELMAN_ENABLED
|
||||
ClassDB::bind_method(D_METHOD("generate_simple_terrarin", "chunk", "spawn_mobs"), &BiomeTerrainGenerator::generate_simple_terrarin);
|
||||
#endif
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
#ifndef BIOME_TERRAIN_GENERATOR_H
|
||||
#define BIOME_TERRAIN_GENERATOR_H
|
||||
/*
|
||||
Copyright (c) 2020-2023 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 "core/object/reference.h"
|
||||
|
||||
#include "modules/modules_enabled.gen.h"
|
||||
|
||||
#ifdef MODULE_VOXELMAN_ENABLED
|
||||
class VoxelChunk;
|
||||
#endif
|
||||
|
||||
class BiomeTerrainGenerator : public Reference {
|
||||
GDCLASS(BiomeTerrainGenerator, Reference);
|
||||
|
||||
public:
|
||||
int get_current_seed();
|
||||
void set_current_seed(int value);
|
||||
|
||||
#ifdef MODULE_VOXELMAN_ENABLED
|
||||
void generate_simple_terrarin(Ref<VoxelChunk> chunk, bool spawn_mobs);
|
||||
#endif
|
||||
|
||||
BiomeTerrainGenerator();
|
||||
~BiomeTerrainGenerator();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
int _current_seed;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,17 +0,0 @@
|
||||
|
||||
def can_build(env, platform):
|
||||
return True
|
||||
|
||||
|
||||
def configure(env):
|
||||
pass
|
||||
|
||||
|
||||
def get_doc_classes():
|
||||
return [
|
||||
"BiomeTerrainGenerator",
|
||||
]
|
||||
|
||||
def get_doc_path():
|
||||
return "doc_classes"
|
||||
|
@ -1,24 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="BiomeTerrainGenerator" inherits="Reference" version="4.2">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
<method name="generate_simple_terrarin">
|
||||
<return type="void" />
|
||||
<argument index="0" name="chunk" type="VoxelChunk" />
|
||||
<argument index="1" name="spawn_mobs" type="bool" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="current_seed" type="int" setter="set_current_seed" getter="get_current_seed" default="0">
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,36 +0,0 @@
|
||||
#include "register_types.h"
|
||||
|
||||
/*
|
||||
|
||||
Copyright (c) 2020-2023 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 "biome_terrain_generator.h"
|
||||
|
||||
void register_broken_seals_module_types(ModuleRegistrationLevel p_level) {
|
||||
if (p_level == MODULE_REGISTRATION_LEVEL_SCENE) {
|
||||
ClassDB::register_class<BiomeTerrainGenerator>();
|
||||
}
|
||||
}
|
||||
|
||||
void unregister_broken_seals_module_types(ModuleRegistrationLevel p_level) {
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
#ifndef BROKEN_SEALS_MODULE_REGISTER_TYPES_H
|
||||
#define BROKEN_SEALS_MODULE_REGISTER_TYPES_H
|
||||
|
||||
/*
|
||||
|
||||
Copyright (c) 2020-2023 Péter Magyar
|
||||
Copyright(c) 2017-2020 Mattias Edlund
|
||||
|
||||
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 "modules/register_module_types.h"
|
||||
|
||||
void register_broken_seals_module_types(ModuleRegistrationLevel p_level);
|
||||
void unregister_broken_seals_module_types(ModuleRegistrationLevel p_level);
|
||||
|
||||
#endif
|
@ -1,12 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
Import("env")
|
||||
Import("env_modules")
|
||||
|
||||
env_gdscript = env_modules.Clone()
|
||||
|
||||
env_gdscript.add_source_files(env.modules_sources, "*.cpp")
|
||||
|
||||
if env["tools"]:
|
||||
env_gdscript.add_source_files(env.modules_sources, "./editor/*.cpp")
|
||||
|
@ -1,22 +0,0 @@
|
||||
|
||||
def can_build(env, platform):
|
||||
return True
|
||||
|
||||
def configure(env):
|
||||
pass
|
||||
|
||||
|
||||
def get_doc_classes():
|
||||
return [
|
||||
"@CScript",
|
||||
"CScript",
|
||||
]
|
||||
|
||||
|
||||
def get_doc_path():
|
||||
return "doc_classes"
|
||||
|
||||
|
||||
def is_enabled():
|
||||
# The module is disabled by default.
|
||||
return False
|
@ -1,555 +0,0 @@
|
||||
#ifndef CSCRIPT_H
|
||||
#define CSCRIPT_H
|
||||
/*************************************************************************/
|
||||
/* gdscript.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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 "core/io/resource_loader.h"
|
||||
#include "core/io/resource_saver.h"
|
||||
#include "core/object/script_language.h"
|
||||
#include "cscript_function.h"
|
||||
|
||||
class CScriptNativeClass : public Reference {
|
||||
GDCLASS(CScriptNativeClass, Reference);
|
||||
|
||||
StringName name;
|
||||
|
||||
protected:
|
||||
bool _get(const StringName &p_name, Variant &r_ret) const;
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
_FORCE_INLINE_ const StringName &get_name() const { return name; }
|
||||
Variant _new();
|
||||
Object *instance();
|
||||
CScriptNativeClass(const StringName &p_name);
|
||||
};
|
||||
|
||||
class CScript : public Script {
|
||||
GDCLASS(CScript, Script);
|
||||
bool tool;
|
||||
bool valid;
|
||||
|
||||
struct MemberInfo {
|
||||
int index;
|
||||
StringName setter;
|
||||
StringName getter;
|
||||
CScriptDataType data_type;
|
||||
};
|
||||
|
||||
friend class CScriptInstance;
|
||||
friend class CScriptFunction;
|
||||
friend class CScriptCompiler;
|
||||
friend class CScriptFunctions;
|
||||
friend class CScriptLanguage;
|
||||
|
||||
Ref<CScriptNativeClass> native;
|
||||
Ref<CScript> base;
|
||||
CScript *_base; //fast pointer access
|
||||
CScript *_owner; //for subclasses
|
||||
|
||||
RBSet<StringName> members; //members are just indices to the instanced script.
|
||||
RBMap<StringName, Variant> constants;
|
||||
RBMap<StringName, CScriptFunction *> member_functions;
|
||||
RBMap<StringName, MemberInfo> member_indices; //members are just indices to the instanced script.
|
||||
RBMap<StringName, Ref<CScript>> subclasses;
|
||||
RBMap<StringName, Vector<StringName>> _signals;
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
||||
RBMap<StringName, int> member_lines;
|
||||
|
||||
RBMap<StringName, Variant> member_default_values;
|
||||
|
||||
List<PropertyInfo> members_cache;
|
||||
RBMap<StringName, Variant> member_default_values_cache;
|
||||
Ref<CScript> base_cache;
|
||||
RBSet<ObjectID> inheriters_cache;
|
||||
bool source_changed_cache;
|
||||
bool placeholder_fallback_enabled;
|
||||
void _update_exports_values(RBMap<StringName, Variant> &values, List<PropertyInfo> &propnames);
|
||||
|
||||
#endif
|
||||
RBMap<StringName, PropertyInfo> member_info;
|
||||
|
||||
CScriptFunction *initializer; //direct pointer to _init , faster to locate
|
||||
|
||||
int subclass_count;
|
||||
RBSet<Object *> instances;
|
||||
//exported members
|
||||
String source;
|
||||
String path;
|
||||
String name;
|
||||
String fully_qualified_name;
|
||||
SelfList<CScript> script_list;
|
||||
|
||||
CScriptInstance *_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, bool p_isref, Variant::CallError &r_error);
|
||||
|
||||
void _set_subclass_path(Ref<CScript> &p_sc, const String &p_path);
|
||||
String _get_debug_path() const;
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
RBSet<PlaceHolderScriptInstance *> placeholders;
|
||||
//void _update_placeholder(PlaceHolderScriptInstance *p_placeholder);
|
||||
virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder);
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
|
||||
RBMap<ObjectID, List<Pair<StringName, Variant>>> pending_reload_state;
|
||||
|
||||
#endif
|
||||
|
||||
bool _update_exports(bool *r_err = nullptr, bool p_recursive_call = false, PlaceHolderScriptInstance *p_instance_to_update = nullptr);
|
||||
|
||||
void _save_orphaned_subclasses();
|
||||
|
||||
protected:
|
||||
bool _get(const StringName &p_name, Variant &r_ret) const;
|
||||
bool _set(const StringName &p_name, const Variant &p_value);
|
||||
void _get_property_list(List<PropertyInfo> *p_properties) const;
|
||||
|
||||
Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error);
|
||||
//void call_multilevel(const StringName& p_method,const Variant** p_args,int p_argcount);
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
virtual bool is_valid() const {
|
||||
return valid;
|
||||
}
|
||||
|
||||
bool inherits_script(const Ref<Script> &p_script) const;
|
||||
|
||||
const RBMap<StringName, Ref<CScript>> &get_subclasses() const {
|
||||
return subclasses;
|
||||
}
|
||||
const RBMap<StringName, Variant> &get_constants() const {
|
||||
return constants;
|
||||
}
|
||||
const RBSet<StringName> &get_members() const {
|
||||
return members;
|
||||
}
|
||||
const CScriptDataType &get_member_type(const StringName &p_member) const {
|
||||
CRASH_COND(!member_indices.has(p_member));
|
||||
return member_indices[p_member].data_type;
|
||||
}
|
||||
const RBMap<StringName, CScriptFunction *> &get_member_functions() const {
|
||||
return member_functions;
|
||||
}
|
||||
const Ref<CScriptNativeClass> &get_native() const {
|
||||
return native;
|
||||
}
|
||||
const String &get_script_class_name() const {
|
||||
return name;
|
||||
}
|
||||
|
||||
virtual bool has_script_signal(const StringName &p_signal) const;
|
||||
virtual void get_script_signal_list(List<MethodInfo> *r_signals) const;
|
||||
|
||||
bool is_tool() const {
|
||||
return tool;
|
||||
}
|
||||
Ref<CScript> get_base() const;
|
||||
|
||||
const RBMap<StringName, MemberInfo> &debug_get_member_indices() const {
|
||||
return member_indices;
|
||||
}
|
||||
const RBMap<StringName, CScriptFunction *> &debug_get_member_functions() const; //this is debug only
|
||||
StringName debug_get_member_by_index(int p_idx) const;
|
||||
|
||||
Variant _new(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
|
||||
virtual bool can_instance() const;
|
||||
|
||||
virtual Ref<Script> get_base_script() const;
|
||||
|
||||
virtual StringName get_instance_base_type() const; // this may not work in all scripts, will return empty if so
|
||||
virtual ScriptInstance *instance_create(Object *p_this);
|
||||
virtual PlaceHolderScriptInstance *placeholder_instance_create(Object *p_this);
|
||||
virtual bool instance_has(const Object *p_this) const;
|
||||
|
||||
virtual bool has_source_code() const;
|
||||
virtual String get_source_code() const;
|
||||
virtual void set_source_code(const String &p_code);
|
||||
virtual void update_exports();
|
||||
|
||||
virtual Error reload(bool p_keep_state = false);
|
||||
|
||||
void set_script_path(const String &p_path) {
|
||||
path = p_path;
|
||||
} //because subclasses need a path too...
|
||||
Error load_source_code(const String &p_path);
|
||||
Error load_byte_code(const String &p_path);
|
||||
|
||||
Vector<uint8_t> get_as_byte_code() const;
|
||||
|
||||
bool get_property_default_value(const StringName &p_property, Variant &r_value) const;
|
||||
|
||||
virtual void get_script_method_list(List<MethodInfo> *p_list) const;
|
||||
virtual bool has_method(const StringName &p_method) const;
|
||||
virtual MethodInfo get_method_info(const StringName &p_method) const;
|
||||
|
||||
virtual void get_script_property_list(List<PropertyInfo> *p_list) const;
|
||||
|
||||
virtual ScriptLanguage *get_language() const;
|
||||
|
||||
virtual int get_member_line(const StringName &p_member) const {
|
||||
#ifdef TOOLS_ENABLED
|
||||
if (member_lines.has(p_member)) {
|
||||
return member_lines[p_member];
|
||||
}
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
virtual void get_constants(RBMap<StringName, Variant> *p_constants);
|
||||
virtual void get_members(RBSet<StringName> *p_members);
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
virtual bool is_placeholder_fallback_enabled() const {
|
||||
return placeholder_fallback_enabled;
|
||||
}
|
||||
#endif
|
||||
|
||||
CScript();
|
||||
~CScript();
|
||||
};
|
||||
|
||||
class CScriptInstance : public ScriptInstance {
|
||||
friend class CScript;
|
||||
friend class CScriptFunction;
|
||||
friend class CScriptFunctions;
|
||||
friend class CScriptCompiler;
|
||||
|
||||
Object *owner;
|
||||
Ref<CScript> script;
|
||||
#ifdef DEBUG_ENABLED
|
||||
RBMap<StringName, int> member_indices_cache; //used only for hot script reloading
|
||||
#endif
|
||||
Vector<Variant> members;
|
||||
bool base_ref;
|
||||
|
||||
void _ml_call_reversed(CScript *sptr, const StringName &p_method, const Variant **p_args, int p_argcount);
|
||||
|
||||
public:
|
||||
virtual Object *get_owner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
virtual bool set(const StringName &p_name, const Variant &p_value);
|
||||
virtual bool get(const StringName &p_name, Variant &r_ret) const;
|
||||
virtual void get_property_list(List<PropertyInfo> *p_properties) const;
|
||||
virtual Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid = nullptr) const;
|
||||
|
||||
virtual void get_method_list(List<MethodInfo> *p_list) const;
|
||||
virtual bool has_method(const StringName &p_method) const;
|
||||
virtual Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error);
|
||||
virtual void call_multilevel(const StringName &p_method, const Variant **p_args, int p_argcount);
|
||||
virtual void call_multilevel_reversed(const StringName &p_method, const Variant **p_args, int p_argcount);
|
||||
|
||||
Variant debug_get_member_by_index(int p_idx) const {
|
||||
return members[p_idx];
|
||||
}
|
||||
|
||||
virtual void notification(int p_notification);
|
||||
String to_string(bool *r_valid);
|
||||
|
||||
virtual Ref<Script> get_script() const;
|
||||
|
||||
virtual ScriptLanguage *get_language();
|
||||
|
||||
void reload_members();
|
||||
|
||||
CScriptInstance();
|
||||
~CScriptInstance();
|
||||
};
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
struct CScriptWarning {
|
||||
enum Code {
|
||||
UNASSIGNED_VARIABLE, // Variable used but never assigned
|
||||
UNASSIGNED_VARIABLE_OP_ASSIGN, // Variable never assigned but used in an assignment operation (+=, *=, etc)
|
||||
UNUSED_VARIABLE, // Local variable is declared but never used
|
||||
SHADOWED_VARIABLE, // Variable name shadowed by other variable
|
||||
UNUSED_CLASS_VARIABLE, // Class variable is declared but never used in the file
|
||||
UNUSED_ARGUMENT, // Function argument is never used
|
||||
UNREACHABLE_CODE, // Code after a return statement
|
||||
STANDALONE_EXPRESSION, // Expression not assigned to a variable
|
||||
VOID_ASSIGNMENT, // Function returns void but it's assigned to a variable
|
||||
NARROWING_CONVERSION, // Float value into an integer slot, precision is lost
|
||||
VARIABLE_CONFLICTS_FUNCTION, // Variable has the same name of a function
|
||||
FUNCTION_CONFLICTS_VARIABLE, // Function has the same name of a variable
|
||||
FUNCTION_CONFLICTS_CONSTANT, // Function has the same name of a constant
|
||||
INCOMPATIBLE_TERNARY, // Possible values of a ternary if are not mutually compatible
|
||||
UNUSED_SIGNAL, // Signal is defined but never emitted
|
||||
RETURN_VALUE_DISCARDED, // Function call returns something but the value isn't used
|
||||
PROPERTY_USED_AS_FUNCTION, // Function not found, but there's a property with the same name
|
||||
CONSTANT_USED_AS_FUNCTION, // Function not found, but there's a constant with the same name
|
||||
FUNCTION_USED_AS_PROPERTY, // Property not found, but there's a function with the same name
|
||||
INTEGER_DIVISION, // Integer divide by integer, decimal part is discarded
|
||||
UNSAFE_PROPERTY_ACCESS, // Property not found in the detected type (but can be in subtypes)
|
||||
UNSAFE_METHOD_ACCESS, // Function not found in the detected type (but can be in subtypes)
|
||||
UNSAFE_CAST, // Cast used in an unknown type
|
||||
UNSAFE_CALL_ARGUMENT, // Function call argument is of a supertype of the require argument
|
||||
DEPRECATED_KEYWORD, // The keyword is deprecated and should be replaced
|
||||
STANDALONE_TERNARY, // Return value of ternary expression is discarded
|
||||
EXPORT_HINT_TYPE_MISTMATCH, // The type of the variable's default value doesn't match its export hint
|
||||
WARNING_MAX,
|
||||
} code;
|
||||
Vector<String> symbols;
|
||||
int line;
|
||||
|
||||
String get_name() const;
|
||||
String get_message() const;
|
||||
static String get_name_from_code(Code p_code);
|
||||
static Code get_code_from_name(const String &p_name);
|
||||
|
||||
CScriptWarning() :
|
||||
code(WARNING_MAX),
|
||||
line(-1) {}
|
||||
};
|
||||
#endif // DEBUG_ENABLED
|
||||
|
||||
class CScriptLanguage : public ScriptLanguage {
|
||||
static CScriptLanguage *singleton;
|
||||
|
||||
Variant *_global_array;
|
||||
Vector<Variant> global_array;
|
||||
RBMap<StringName, int> globals;
|
||||
RBMap<StringName, Variant> named_globals;
|
||||
|
||||
struct CallLevel {
|
||||
Variant *stack;
|
||||
CScriptFunction *function;
|
||||
CScriptInstance *instance;
|
||||
int *ip;
|
||||
int *line;
|
||||
};
|
||||
|
||||
int _debug_parse_err_line;
|
||||
String _debug_parse_err_file;
|
||||
String _debug_error;
|
||||
int _debug_call_stack_pos;
|
||||
int _debug_max_call_stack;
|
||||
CallLevel *_call_stack;
|
||||
|
||||
void _add_global(const StringName &p_name, const Variant &p_value);
|
||||
|
||||
friend class CScriptInstance;
|
||||
|
||||
Mutex lock;
|
||||
|
||||
friend class CScript;
|
||||
|
||||
SelfList<CScript>::List script_list;
|
||||
friend class CScriptFunction;
|
||||
|
||||
SelfList<CScriptFunction>::List function_list;
|
||||
bool profiling;
|
||||
uint64_t script_frame_time;
|
||||
|
||||
RBMap<String, ObjectID> orphan_subclasses;
|
||||
|
||||
public:
|
||||
int calls;
|
||||
|
||||
bool debug_break(const String &p_error, bool p_allow_continue = true);
|
||||
bool debug_break_parse(const String &p_file, int p_line, const String &p_error);
|
||||
|
||||
_FORCE_INLINE_ void enter_function(CScriptInstance *p_instance, CScriptFunction *p_function, Variant *p_stack, int *p_ip, int *p_line) {
|
||||
if (Thread::get_main_id() != Thread::get_caller_id()) {
|
||||
return; //no support for other threads than main for now
|
||||
}
|
||||
|
||||
if (ScriptDebugger::get_singleton()->get_lines_left() > 0 && ScriptDebugger::get_singleton()->get_depth() >= 0) {
|
||||
ScriptDebugger::get_singleton()->set_depth(ScriptDebugger::get_singleton()->get_depth() + 1);
|
||||
}
|
||||
|
||||
if (_debug_call_stack_pos >= _debug_max_call_stack) {
|
||||
//stack overflow
|
||||
_debug_error = "Stack Overflow (Stack Size: " + itos(_debug_max_call_stack) + ")";
|
||||
ScriptDebugger::get_singleton()->debug(this);
|
||||
return;
|
||||
}
|
||||
|
||||
_call_stack[_debug_call_stack_pos].stack = p_stack;
|
||||
_call_stack[_debug_call_stack_pos].instance = p_instance;
|
||||
_call_stack[_debug_call_stack_pos].function = p_function;
|
||||
_call_stack[_debug_call_stack_pos].ip = p_ip;
|
||||
_call_stack[_debug_call_stack_pos].line = p_line;
|
||||
_debug_call_stack_pos++;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ void exit_function() {
|
||||
if (Thread::get_main_id() != Thread::get_caller_id()) {
|
||||
return; //no support for other threads than main for now
|
||||
}
|
||||
|
||||
if (ScriptDebugger::get_singleton()->get_lines_left() > 0 && ScriptDebugger::get_singleton()->get_depth() >= 0) {
|
||||
ScriptDebugger::get_singleton()->set_depth(ScriptDebugger::get_singleton()->get_depth() - 1);
|
||||
}
|
||||
|
||||
if (_debug_call_stack_pos == 0) {
|
||||
_debug_error = "Stack Underflow (Engine Bug)";
|
||||
ScriptDebugger::get_singleton()->debug(this);
|
||||
return;
|
||||
}
|
||||
|
||||
_debug_call_stack_pos--;
|
||||
}
|
||||
|
||||
virtual Vector<StackInfo> debug_get_current_stack_info() {
|
||||
if (Thread::get_main_id() != Thread::get_caller_id()) {
|
||||
return Vector<StackInfo>();
|
||||
}
|
||||
|
||||
Vector<StackInfo> csi;
|
||||
csi.resize(_debug_call_stack_pos);
|
||||
for (int i = 0; i < _debug_call_stack_pos; i++) {
|
||||
csi.write[_debug_call_stack_pos - i - 1].line = _call_stack[i].line ? *_call_stack[i].line : 0;
|
||||
if (_call_stack[i].function) {
|
||||
csi.write[_debug_call_stack_pos - i - 1].func = _call_stack[i].function->get_name();
|
||||
csi.write[_debug_call_stack_pos - i - 1].file = _call_stack[i].function->get_script()->get_path();
|
||||
}
|
||||
}
|
||||
return csi;
|
||||
}
|
||||
|
||||
struct {
|
||||
StringName _init;
|
||||
StringName _notification;
|
||||
StringName _set;
|
||||
StringName _get;
|
||||
StringName _get_property_list;
|
||||
StringName _script_source;
|
||||
|
||||
} strings;
|
||||
|
||||
_FORCE_INLINE_ int get_global_array_size() const { return global_array.size(); }
|
||||
_FORCE_INLINE_ Variant *get_global_array() { return _global_array; }
|
||||
_FORCE_INLINE_ const RBMap<StringName, int> &get_global_map() const { return globals; }
|
||||
_FORCE_INLINE_ const RBMap<StringName, Variant> &get_named_globals_map() const { return named_globals; }
|
||||
|
||||
_FORCE_INLINE_ static CScriptLanguage *get_singleton() { return singleton; }
|
||||
|
||||
virtual String get_name() const;
|
||||
|
||||
/* LANGUAGE FUNCTIONS */
|
||||
virtual void init();
|
||||
virtual String get_type() const;
|
||||
virtual String get_extension() const;
|
||||
virtual Error execute_file(const String &p_path);
|
||||
virtual void finish();
|
||||
|
||||
/* EDITOR FUNCTIONS */
|
||||
virtual void get_reserved_words(List<String> *p_words) const;
|
||||
virtual bool is_control_flow_keyword(String p_keywords) const;
|
||||
virtual void get_comment_delimiters(List<String> *p_delimiters) const;
|
||||
virtual void get_string_delimiters(List<String> *p_delimiters) const;
|
||||
virtual String _get_processed_template(const String &p_template, const String &p_base_class_name) const;
|
||||
virtual Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const;
|
||||
virtual bool is_using_templates();
|
||||
virtual void make_template(const String &p_class_name, const String &p_base_class_name, Ref<Script> &p_script);
|
||||
virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path = "", List<String> *r_functions = nullptr, List<ScriptLanguage::Warning> *r_warnings = nullptr, RBSet<int> *r_safe_lines = nullptr) const;
|
||||
virtual Script *create_script() const;
|
||||
virtual bool has_named_classes() const;
|
||||
virtual bool supports_builtin_mode() const;
|
||||
virtual bool can_inherit_from_file() { return true; }
|
||||
virtual int find_function(const String &p_function, const String &p_code) const;
|
||||
virtual String make_function(const String &p_class, const String &p_name, const PoolStringArray &p_args) const;
|
||||
virtual Error complete_code(const String &p_code, const String &p_path, Object *p_owner, List<ScriptCodeCompletionOption> *r_options, bool &r_forced, String &r_call_hint);
|
||||
#ifdef TOOLS_ENABLED
|
||||
virtual Error lookup_code(const String &p_code, const String &p_symbol, const String &p_path, Object *p_owner, LookupResult &r_result);
|
||||
#endif
|
||||
virtual String _get_indentation() const;
|
||||
virtual void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const;
|
||||
virtual void add_global_constant(const StringName &p_variable, const Variant &p_value);
|
||||
virtual void add_named_global_constant(const StringName &p_name, const Variant &p_value);
|
||||
virtual void remove_named_global_constant(const StringName &p_name);
|
||||
|
||||
/* DEBUGGER FUNCTIONS */
|
||||
|
||||
virtual String debug_get_error() const;
|
||||
virtual int debug_get_stack_level_count() const;
|
||||
virtual int debug_get_stack_level_line(int p_level) const;
|
||||
virtual String debug_get_stack_level_function(int p_level) const;
|
||||
virtual String debug_get_stack_level_source(int p_level) const;
|
||||
virtual void debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1);
|
||||
virtual void debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1);
|
||||
virtual ScriptInstance *debug_get_stack_level_instance(int p_level);
|
||||
virtual void debug_get_globals(List<String> *p_globals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1);
|
||||
virtual String debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems = -1, int p_max_depth = -1);
|
||||
|
||||
virtual void reload_all_scripts();
|
||||
virtual void reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload);
|
||||
|
||||
virtual void frame();
|
||||
|
||||
virtual void get_public_functions(List<MethodInfo> *p_functions) const;
|
||||
virtual void get_public_constants(List<Pair<String, Variant>> *p_constants) const;
|
||||
|
||||
virtual void profiling_start();
|
||||
virtual void profiling_stop();
|
||||
|
||||
virtual int profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max);
|
||||
virtual int profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max);
|
||||
|
||||
/* LOADER FUNCTIONS */
|
||||
|
||||
virtual void get_recognized_extensions(List<String> *p_extensions) const;
|
||||
|
||||
/* GLOBAL CLASSES */
|
||||
|
||||
virtual bool handles_global_class_type(const String &p_type) const;
|
||||
virtual String get_global_class_name(const String &p_path, String *r_base_type = nullptr, String *r_icon_path = nullptr) const;
|
||||
|
||||
void add_orphan_subclass(const String &p_qualified_name, const ObjectID &p_subclass);
|
||||
Ref<CScript> get_orphan_subclass(const String &p_qualified_name);
|
||||
|
||||
CScriptLanguage();
|
||||
~CScriptLanguage();
|
||||
};
|
||||
|
||||
class ResourceFormatLoaderCScript : public ResourceFormatLoader {
|
||||
public:
|
||||
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL, bool p_no_subresource_cache = false);
|
||||
virtual void get_recognized_extensions(List<String> *p_extensions) const;
|
||||
virtual bool handles_type(const String &p_type) const;
|
||||
virtual String get_resource_type(const String &p_path) const;
|
||||
virtual void get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types = false);
|
||||
};
|
||||
|
||||
class ResourceFormatSaverCScript : public ResourceFormatSaver {
|
||||
public:
|
||||
virtual Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0);
|
||||
virtual void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const;
|
||||
virtual bool recognize(const RES &p_resource) const;
|
||||
};
|
||||
|
||||
#endif // CSCRIPT_H
|
@ -1,169 +0,0 @@
|
||||
#ifndef CSCRIPT_COMPILER_H
|
||||
#define CSCRIPT_COMPILER_H
|
||||
/*************************************************************************/
|
||||
/* gdscript_compiler.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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 "core/containers/rb_set.h"
|
||||
#include "cscript.h"
|
||||
#include "cscript_parser.h"
|
||||
|
||||
class CScriptCompiler {
|
||||
const CScriptParser *parser;
|
||||
RBSet<CScript *> parsed_classes;
|
||||
RBSet<CScript *> parsing_classes;
|
||||
CScript *main_script;
|
||||
struct CodeGen {
|
||||
CScript *script;
|
||||
const CScriptParser::ClassNode *class_node;
|
||||
const CScriptParser::FunctionNode *function_node;
|
||||
bool debug_stack;
|
||||
|
||||
List<RBMap<StringName, int>> stack_id_stack;
|
||||
RBMap<StringName, int> stack_identifiers;
|
||||
|
||||
List<CScriptFunction::StackDebug> stack_debug;
|
||||
List<RBMap<StringName, int>> block_identifier_stack;
|
||||
RBMap<StringName, int> block_identifiers;
|
||||
|
||||
void add_stack_identifier(const StringName &p_id, int p_stackpos) {
|
||||
stack_identifiers[p_id] = p_stackpos;
|
||||
if (debug_stack) {
|
||||
block_identifiers[p_id] = p_stackpos;
|
||||
CScriptFunction::StackDebug sd;
|
||||
sd.added = true;
|
||||
sd.line = current_line;
|
||||
sd.identifier = p_id;
|
||||
sd.pos = p_stackpos;
|
||||
stack_debug.push_back(sd);
|
||||
}
|
||||
}
|
||||
|
||||
void push_stack_identifiers() {
|
||||
stack_id_stack.push_back(stack_identifiers);
|
||||
if (debug_stack) {
|
||||
block_identifier_stack.push_back(block_identifiers);
|
||||
block_identifiers.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void pop_stack_identifiers() {
|
||||
stack_identifiers = stack_id_stack.back()->get();
|
||||
stack_id_stack.pop_back();
|
||||
|
||||
if (debug_stack) {
|
||||
for (RBMap<StringName, int>::Element *E = block_identifiers.front(); E; E = E->next()) {
|
||||
CScriptFunction::StackDebug sd;
|
||||
sd.added = false;
|
||||
sd.identifier = E->key();
|
||||
sd.line = current_line;
|
||||
sd.pos = E->get();
|
||||
stack_debug.push_back(sd);
|
||||
}
|
||||
block_identifiers = block_identifier_stack.back()->get();
|
||||
block_identifier_stack.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
HashMap<Variant, int, VariantHasher, VariantComparator> constant_map;
|
||||
RBMap<StringName, int> name_map;
|
||||
#ifdef TOOLS_ENABLED
|
||||
Vector<StringName> named_globals;
|
||||
#endif
|
||||
|
||||
int get_name_map_pos(const StringName &p_identifier) {
|
||||
int ret;
|
||||
if (!name_map.has(p_identifier)) {
|
||||
ret = name_map.size();
|
||||
name_map[p_identifier] = ret;
|
||||
} else {
|
||||
ret = name_map[p_identifier];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int get_constant_pos(const Variant &p_constant) {
|
||||
if (constant_map.has(p_constant)) {
|
||||
return constant_map[p_constant];
|
||||
}
|
||||
int pos = constant_map.size();
|
||||
constant_map[p_constant] = pos;
|
||||
return pos;
|
||||
}
|
||||
|
||||
Vector<int> opcodes;
|
||||
void alloc_stack(int p_level) {
|
||||
if (p_level >= stack_max) {
|
||||
stack_max = p_level + 1;
|
||||
}
|
||||
}
|
||||
void alloc_call(int p_params) {
|
||||
if (p_params >= call_max) {
|
||||
call_max = p_params;
|
||||
}
|
||||
}
|
||||
|
||||
int current_line;
|
||||
int stack_max;
|
||||
int call_max;
|
||||
};
|
||||
|
||||
bool _is_class_member_property(CodeGen &codegen, const StringName &p_name);
|
||||
bool _is_class_member_property(CScript *owner, const StringName &p_name);
|
||||
|
||||
void _set_error(const String &p_error, const CScriptParser::Node *p_node);
|
||||
|
||||
bool _create_unary_operator(CodeGen &codegen, const CScriptParser::OperatorNode *on, Variant::Operator op, int p_stack_level);
|
||||
bool _create_binary_operator(CodeGen &codegen, const CScriptParser::OperatorNode *on, Variant::Operator op, int p_stack_level, bool p_initializer = false, int p_index_addr = 0);
|
||||
|
||||
CScriptDataType _gdtype_from_datatype(const CScriptParser::DataType &p_datatype, CScript *p_owner = nullptr) const;
|
||||
|
||||
int _parse_assign_right_expression(CodeGen &codegen, const CScriptParser::OperatorNode *p_expression, int p_stack_level, int p_index_addr = 0);
|
||||
int _parse_expression(CodeGen &codegen, const CScriptParser::Node *p_expression, int p_stack_level, bool p_root = false, bool p_initializer = false, int p_index_addr = 0);
|
||||
Error _parse_block(CodeGen &codegen, const CScriptParser::BlockNode *p_block, int p_stack_level = 0, int p_break_addr = -1, int p_continue_addr = -1);
|
||||
Error _parse_function(CScript *p_script, const CScriptParser::ClassNode *p_class, const CScriptParser::FunctionNode *p_func, bool p_for_ready = false);
|
||||
Error _parse_class_level(CScript *p_script, const CScriptParser::ClassNode *p_class, bool p_keep_state);
|
||||
Error _parse_class_blocks(CScript *p_script, const CScriptParser::ClassNode *p_class, bool p_keep_state);
|
||||
void _make_scripts(CScript *p_script, const CScriptParser::ClassNode *p_class, bool p_keep_state);
|
||||
int err_line;
|
||||
int err_column;
|
||||
StringName source;
|
||||
String error;
|
||||
|
||||
public:
|
||||
Error compile(const CScriptParser *p_parser, CScript *p_script, bool p_keep_state = false);
|
||||
|
||||
String get_error() const;
|
||||
int get_error_line() const;
|
||||
int get_error_column() const;
|
||||
|
||||
CScriptCompiler();
|
||||
};
|
||||
|
||||
#endif // CSCRIPT_COMPILER_H
|
@ -1,358 +0,0 @@
|
||||
#ifndef CSCRIPT_FUNCTION_H
|
||||
#define CSCRIPT_FUNCTION_H
|
||||
/*************************************************************************/
|
||||
/* gdscript_function.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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 "core/os/thread.h"
|
||||
#include "core/containers/pair.h"
|
||||
#include "core/object/reference.h"
|
||||
#include "core/object/script_language.h"
|
||||
#include "core/containers/self_list.h"
|
||||
#include "core/string/string_name.h"
|
||||
#include "core/variant/variant.h"
|
||||
|
||||
class CScriptInstance;
|
||||
class CScript;
|
||||
|
||||
struct CScriptDataType {
|
||||
bool has_type;
|
||||
enum {
|
||||
UNINITIALIZED,
|
||||
BUILTIN,
|
||||
NATIVE,
|
||||
SCRIPT,
|
||||
CSCRIPT,
|
||||
} kind;
|
||||
Variant::Type builtin_type;
|
||||
StringName native_type;
|
||||
Script *script_type;
|
||||
Ref<Script> script_type_ref;
|
||||
|
||||
bool is_type(const Variant &p_variant, bool p_allow_implicit_conversion = false) const {
|
||||
if (!has_type) {
|
||||
return true; // Can't type check
|
||||
}
|
||||
|
||||
switch (kind) {
|
||||
case UNINITIALIZED:
|
||||
break;
|
||||
case BUILTIN: {
|
||||
Variant::Type var_type = p_variant.get_type();
|
||||
bool valid = builtin_type == var_type;
|
||||
if (!valid && p_allow_implicit_conversion) {
|
||||
valid = Variant::can_convert_strict(var_type, builtin_type);
|
||||
}
|
||||
return valid;
|
||||
} break;
|
||||
case NATIVE: {
|
||||
if (p_variant.get_type() == Variant::NIL) {
|
||||
return true;
|
||||
}
|
||||
if (p_variant.get_type() != Variant::OBJECT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Object *obj = p_variant.operator Object *();
|
||||
if (!obj) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ClassDB::is_parent_class(obj->get_class_name(), native_type)) {
|
||||
// Try with underscore prefix
|
||||
StringName underscore_native_type = "_" + native_type;
|
||||
if (!ClassDB::is_parent_class(obj->get_class_name(), underscore_native_type)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} break;
|
||||
case SCRIPT:
|
||||
case CSCRIPT: {
|
||||
if (p_variant.get_type() == Variant::NIL) {
|
||||
return true;
|
||||
}
|
||||
if (p_variant.get_type() != Variant::OBJECT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Object *obj = p_variant.operator Object *();
|
||||
if (!obj) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Ref<Script> base = obj && obj->get_script_instance() ? obj->get_script_instance()->get_script() : nullptr;
|
||||
bool valid = false;
|
||||
while (base.is_valid()) {
|
||||
if (base == script_type) {
|
||||
valid = true;
|
||||
break;
|
||||
}
|
||||
base = base->get_base_script();
|
||||
}
|
||||
return valid;
|
||||
} break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
operator PropertyInfo() const {
|
||||
PropertyInfo info;
|
||||
if (has_type) {
|
||||
switch (kind) {
|
||||
case UNINITIALIZED:
|
||||
break;
|
||||
case BUILTIN: {
|
||||
info.type = builtin_type;
|
||||
} break;
|
||||
case NATIVE: {
|
||||
info.type = Variant::OBJECT;
|
||||
info.class_name = native_type;
|
||||
} break;
|
||||
case SCRIPT:
|
||||
case CSCRIPT: {
|
||||
info.type = Variant::OBJECT;
|
||||
info.class_name = script_type->get_instance_base_type();
|
||||
} break;
|
||||
}
|
||||
} else {
|
||||
info.type = Variant::NIL;
|
||||
info.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
CScriptDataType() :
|
||||
has_type(false),
|
||||
kind(UNINITIALIZED),
|
||||
builtin_type(Variant::NIL),
|
||||
script_type(nullptr) {}
|
||||
};
|
||||
|
||||
class CScriptFunction {
|
||||
public:
|
||||
enum Opcode {
|
||||
OPCODE_OPERATOR,
|
||||
OPCODE_EXTENDS_TEST,
|
||||
OPCODE_IS_BUILTIN,
|
||||
OPCODE_SET,
|
||||
OPCODE_GET,
|
||||
OPCODE_SET_NAMED,
|
||||
OPCODE_GET_NAMED,
|
||||
OPCODE_SET_MEMBER,
|
||||
OPCODE_GET_MEMBER,
|
||||
OPCODE_ASSIGN,
|
||||
OPCODE_ASSIGN_TRUE,
|
||||
OPCODE_ASSIGN_FALSE,
|
||||
OPCODE_ASSIGN_TYPED_BUILTIN,
|
||||
OPCODE_ASSIGN_TYPED_NATIVE,
|
||||
OPCODE_ASSIGN_TYPED_SCRIPT,
|
||||
OPCODE_CAST_TO_BUILTIN,
|
||||
OPCODE_CAST_TO_NATIVE,
|
||||
OPCODE_CAST_TO_SCRIPT,
|
||||
OPCODE_CONSTRUCT, //only for basic types!!
|
||||
OPCODE_CONSTRUCT_ARRAY,
|
||||
OPCODE_CONSTRUCT_DICTIONARY,
|
||||
OPCODE_CALL,
|
||||
OPCODE_CALL_RETURN,
|
||||
OPCODE_CALL_BUILT_IN,
|
||||
OPCODE_CALL_SELF,
|
||||
OPCODE_CALL_SELF_BASE,
|
||||
OPCODE_JUMP,
|
||||
OPCODE_JUMP_IF,
|
||||
OPCODE_JUMP_IF_NOT,
|
||||
OPCODE_JUMP_TO_DEF_ARGUMENT,
|
||||
OPCODE_RETURN,
|
||||
OPCODE_ITERATE_BEGIN,
|
||||
OPCODE_ITERATE,
|
||||
OPCODE_ASSERT,
|
||||
OPCODE_BREAKPOINT,
|
||||
OPCODE_LINE,
|
||||
OPCODE_END
|
||||
};
|
||||
|
||||
enum Address {
|
||||
ADDR_BITS = 24,
|
||||
ADDR_MASK = ((1 << ADDR_BITS) - 1),
|
||||
ADDR_TYPE_MASK = ~ADDR_MASK,
|
||||
ADDR_TYPE_SELF = 0,
|
||||
ADDR_TYPE_CLASS = 1,
|
||||
ADDR_TYPE_MEMBER = 2,
|
||||
ADDR_TYPE_CLASS_CONSTANT = 3,
|
||||
ADDR_TYPE_LOCAL_CONSTANT = 4,
|
||||
ADDR_TYPE_STACK = 5,
|
||||
ADDR_TYPE_STACK_VARIABLE = 6,
|
||||
ADDR_TYPE_GLOBAL = 7,
|
||||
ADDR_TYPE_NAMED_GLOBAL = 8,
|
||||
ADDR_TYPE_NIL = 9
|
||||
};
|
||||
|
||||
struct StackDebug {
|
||||
int line;
|
||||
int pos;
|
||||
bool added;
|
||||
StringName identifier;
|
||||
};
|
||||
|
||||
private:
|
||||
friend class CScriptCompiler;
|
||||
|
||||
StringName source;
|
||||
|
||||
mutable Variant nil;
|
||||
mutable Variant *_constants_ptr;
|
||||
int _constant_count;
|
||||
const StringName *_global_names_ptr;
|
||||
int _global_names_count;
|
||||
#ifdef TOOLS_ENABLED
|
||||
const StringName *_named_globals_ptr;
|
||||
int _named_globals_count;
|
||||
#endif
|
||||
const int *_default_arg_ptr;
|
||||
int _default_arg_count;
|
||||
const int *_code_ptr;
|
||||
int _code_size;
|
||||
int _argument_count;
|
||||
int _stack_size;
|
||||
int _call_size;
|
||||
int _initial_line;
|
||||
bool _static;
|
||||
|
||||
CScript *_script;
|
||||
|
||||
StringName name;
|
||||
Vector<Variant> constants;
|
||||
Vector<StringName> global_names;
|
||||
#ifdef TOOLS_ENABLED
|
||||
Vector<StringName> named_globals;
|
||||
#endif
|
||||
Vector<int> default_arguments;
|
||||
Vector<int> code;
|
||||
Vector<CScriptDataType> argument_types;
|
||||
CScriptDataType return_type;
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
Vector<StringName> arg_names;
|
||||
#endif
|
||||
|
||||
List<StackDebug> stack_debug;
|
||||
|
||||
_FORCE_INLINE_ Variant *_get_variant(int p_address, CScriptInstance *p_instance, CScript *p_script, Variant &self, Variant &static_ref, Variant *p_stack, String &r_error) const;
|
||||
_FORCE_INLINE_ String _get_call_error(const Variant::CallError &p_err, const String &p_where, const Variant **argptrs) const;
|
||||
|
||||
friend class CScriptLanguage;
|
||||
|
||||
SelfList<CScriptFunction> function_list;
|
||||
#ifdef DEBUG_ENABLED
|
||||
CharString func_cname;
|
||||
const char *_func_cname;
|
||||
|
||||
struct Profile {
|
||||
StringName signature;
|
||||
uint64_t call_count;
|
||||
uint64_t self_time;
|
||||
uint64_t total_time;
|
||||
uint64_t frame_call_count;
|
||||
uint64_t frame_self_time;
|
||||
uint64_t frame_total_time;
|
||||
uint64_t last_frame_call_count;
|
||||
uint64_t last_frame_self_time;
|
||||
uint64_t last_frame_total_time;
|
||||
} profile;
|
||||
|
||||
#endif
|
||||
|
||||
public:
|
||||
struct CallState {
|
||||
CScript *script;
|
||||
CScriptInstance *instance;
|
||||
#ifdef DEBUG_ENABLED
|
||||
StringName function_name;
|
||||
String script_path;
|
||||
#endif
|
||||
Vector<uint8_t> stack;
|
||||
int stack_size;
|
||||
Variant self;
|
||||
uint32_t alloca_size;
|
||||
int ip;
|
||||
int line;
|
||||
int defarg;
|
||||
Variant result;
|
||||
};
|
||||
|
||||
_FORCE_INLINE_ bool is_static() const {
|
||||
return _static;
|
||||
}
|
||||
|
||||
const int *get_code() const; //used for debug
|
||||
int get_code_size() const;
|
||||
Variant get_constant(int p_idx) const;
|
||||
StringName get_global_name(int p_idx) const;
|
||||
StringName get_name() const;
|
||||
int get_max_stack_size() const;
|
||||
int get_default_argument_count() const;
|
||||
int get_default_argument_addr(int p_idx) const;
|
||||
CScriptDataType get_return_type() const;
|
||||
CScriptDataType get_argument_type(int p_idx) const;
|
||||
CScript *get_script() const {
|
||||
return _script;
|
||||
}
|
||||
StringName get_source() const {
|
||||
return source;
|
||||
}
|
||||
|
||||
void debug_get_stack_member_state(int p_line, List<Pair<StringName, int>> *r_stackvars) const;
|
||||
|
||||
_FORCE_INLINE_ bool is_empty() const {
|
||||
return _code_size == 0;
|
||||
}
|
||||
|
||||
int get_argument_count() const {
|
||||
return _argument_count;
|
||||
}
|
||||
StringName get_argument_name(int p_idx) const {
|
||||
#ifdef TOOLS_ENABLED
|
||||
ERR_FAIL_INDEX_V(p_idx, arg_names.size(), StringName());
|
||||
return arg_names[p_idx];
|
||||
#else
|
||||
return StringName();
|
||||
#endif
|
||||
}
|
||||
Variant get_default_argument(int p_idx) const {
|
||||
ERR_FAIL_INDEX_V(p_idx, default_arguments.size(), Variant());
|
||||
return default_arguments[p_idx];
|
||||
}
|
||||
|
||||
Variant call(CScriptInstance *p_instance, const Variant **p_args, int p_argcount, Variant::CallError &r_err);
|
||||
|
||||
CScriptFunction();
|
||||
~CScriptFunction();
|
||||
};
|
||||
|
||||
#endif // CSCRIPT_FUNCTION_H
|
@ -1,138 +0,0 @@
|
||||
#ifndef CSCRIPT_FUNCTIONS_H
|
||||
#define CSCRIPT_FUNCTIONS_H
|
||||
/*************************************************************************/
|
||||
/* gdscript_functions.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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 "core/variant/variant.h"
|
||||
|
||||
class CScriptFunctions {
|
||||
public:
|
||||
enum Function {
|
||||
MATH_SIN,
|
||||
MATH_COS,
|
||||
MATH_TAN,
|
||||
MATH_SINH,
|
||||
MATH_COSH,
|
||||
MATH_TANH,
|
||||
MATH_ASIN,
|
||||
MATH_ACOS,
|
||||
MATH_ATAN,
|
||||
MATH_ATAN2,
|
||||
MATH_SQRT,
|
||||
MATH_FMOD,
|
||||
MATH_FPOSMOD,
|
||||
MATH_POSMOD,
|
||||
MATH_FLOOR,
|
||||
MATH_CEIL,
|
||||
MATH_ROUND,
|
||||
MATH_ABS,
|
||||
MATH_SIGN,
|
||||
MATH_POW,
|
||||
MATH_LOG,
|
||||
MATH_EXP,
|
||||
MATH_ISNAN,
|
||||
MATH_ISINF,
|
||||
MATH_ISEQUALAPPROX,
|
||||
MATH_ISZEROAPPROX,
|
||||
MATH_EASE,
|
||||
MATH_DECIMALS,
|
||||
MATH_STEP_DECIMALS,
|
||||
MATH_STEPIFY,
|
||||
MATH_LERP,
|
||||
MATH_LERP_ANGLE,
|
||||
MATH_INVERSE_LERP,
|
||||
MATH_RANGE_LERP,
|
||||
MATH_SMOOTHSTEP,
|
||||
MATH_MOVE_TOWARD,
|
||||
MATH_DECTIME,
|
||||
MATH_RANDOMIZE,
|
||||
MATH_RAND,
|
||||
MATH_RANDF,
|
||||
MATH_RANDOM,
|
||||
MATH_SEED,
|
||||
MATH_RANDSEED,
|
||||
MATH_DEG2RAD,
|
||||
MATH_RAD2DEG,
|
||||
MATH_LINEAR2DB,
|
||||
MATH_DB2LINEAR,
|
||||
MATH_POLAR2CARTESIAN,
|
||||
MATH_CARTESIAN2POLAR,
|
||||
MATH_WRAP,
|
||||
MATH_WRAPF,
|
||||
LOGIC_MAX,
|
||||
LOGIC_MIN,
|
||||
LOGIC_CLAMP,
|
||||
LOGIC_NEAREST_PO2,
|
||||
OBJ_WEAKREF,
|
||||
FUNC_FUNCREF,
|
||||
TYPE_CONVERT,
|
||||
TYPE_OF,
|
||||
TYPE_EXISTS,
|
||||
TEXT_CHAR,
|
||||
TEXT_ORD,
|
||||
TEXT_STR,
|
||||
TEXT_PRINT,
|
||||
TEXT_PRINT_TABBED,
|
||||
TEXT_PRINT_SPACED,
|
||||
TEXT_PRINTERR,
|
||||
TEXT_PRINTRAW,
|
||||
TEXT_PRINT_DEBUG,
|
||||
PUSH_ERROR,
|
||||
PUSH_WARNING,
|
||||
VAR_TO_STR,
|
||||
STR_TO_VAR,
|
||||
VAR_TO_BYTES,
|
||||
BYTES_TO_VAR,
|
||||
GEN_RANGE,
|
||||
RESOURCE_LOAD,
|
||||
INST2DICT,
|
||||
DICT2INST,
|
||||
VALIDATE_JSON,
|
||||
PARSE_JSON,
|
||||
TO_JSON,
|
||||
HASH,
|
||||
COLOR8,
|
||||
COLORN,
|
||||
PRINT_STACK,
|
||||
GET_STACK,
|
||||
INSTANCE_FROM_ID,
|
||||
LEN,
|
||||
IS_INSTANCE_VALID,
|
||||
DEEP_EQUAL,
|
||||
FUNC_MAX
|
||||
};
|
||||
|
||||
static const char *get_func_name(Function p_func);
|
||||
static void call(Function p_func, const Variant **p_args, int p_arg_count, Variant &r_ret, Variant::CallError &r_error);
|
||||
static bool is_deterministic(Function p_func);
|
||||
static MethodInfo get_info(Function p_func);
|
||||
};
|
||||
|
||||
#endif // CSCRIPT_FUNCTIONS_H
|
@ -1,688 +0,0 @@
|
||||
#ifndef CSCRIPT_PARSER_H
|
||||
#define CSCRIPT_PARSER_H
|
||||
/*************************************************************************/
|
||||
/* gdscript_parser.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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 "core/containers/rb_map.h"
|
||||
#include "core/object/object.h"
|
||||
#include "core/object/script_language.h"
|
||||
#include "cscript_functions.h"
|
||||
#include "cscript_tokenizer.h"
|
||||
|
||||
struct CScriptDataType;
|
||||
struct CScriptWarning;
|
||||
|
||||
class CScriptParser {
|
||||
public:
|
||||
struct ClassNode;
|
||||
|
||||
struct DataType {
|
||||
enum {
|
||||
BUILTIN,
|
||||
NATIVE,
|
||||
SCRIPT,
|
||||
CSCRIPT,
|
||||
CLASS,
|
||||
UNRESOLVED
|
||||
} kind;
|
||||
|
||||
bool has_type;
|
||||
bool is_constant;
|
||||
bool is_meta_type; // Whether the value can be used as a type
|
||||
bool infer_type;
|
||||
|
||||
Variant::Type builtin_type;
|
||||
StringName native_type;
|
||||
Ref<Script> script_type;
|
||||
ClassNode *class_type;
|
||||
|
||||
String to_string() const;
|
||||
|
||||
bool operator==(const DataType &other) const {
|
||||
if (!has_type || !other.has_type) {
|
||||
return true; // Can be considered equal for parsing purpose
|
||||
}
|
||||
if (kind != other.kind) {
|
||||
return false;
|
||||
}
|
||||
switch (kind) {
|
||||
case BUILTIN: {
|
||||
return builtin_type == other.builtin_type;
|
||||
} break;
|
||||
case NATIVE: {
|
||||
return native_type == other.native_type;
|
||||
} break;
|
||||
case CSCRIPT:
|
||||
case SCRIPT: {
|
||||
return script_type == other.script_type;
|
||||
} break;
|
||||
case CLASS: {
|
||||
return class_type == other.class_type;
|
||||
} break;
|
||||
case UNRESOLVED: {
|
||||
} break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
DataType() :
|
||||
kind(UNRESOLVED),
|
||||
has_type(false),
|
||||
is_constant(false),
|
||||
is_meta_type(false),
|
||||
infer_type(false),
|
||||
builtin_type(Variant::NIL),
|
||||
class_type(nullptr) {}
|
||||
};
|
||||
|
||||
struct Node {
|
||||
enum Type {
|
||||
TYPE_CLASS,
|
||||
TYPE_FUNCTION,
|
||||
TYPE_BUILT_IN_FUNCTION,
|
||||
TYPE_BLOCK,
|
||||
TYPE_IDENTIFIER,
|
||||
TYPE_TYPE,
|
||||
TYPE_CONSTANT,
|
||||
TYPE_ARRAY,
|
||||
TYPE_DICTIONARY,
|
||||
TYPE_SELF,
|
||||
TYPE_OPERATOR,
|
||||
TYPE_CONTROL_FLOW,
|
||||
TYPE_LOCAL_VAR,
|
||||
TYPE_CAST,
|
||||
TYPE_ASSERT,
|
||||
TYPE_BREAKPOINT,
|
||||
TYPE_NEWLINE,
|
||||
};
|
||||
|
||||
Node *next;
|
||||
int line;
|
||||
int column;
|
||||
Type type;
|
||||
|
||||
virtual DataType get_datatype() const { return DataType(); }
|
||||
virtual void set_datatype(const DataType &p_datatype) {}
|
||||
|
||||
virtual ~Node() {}
|
||||
};
|
||||
|
||||
struct FunctionNode;
|
||||
struct BlockNode;
|
||||
struct ConstantNode;
|
||||
struct LocalVarNode;
|
||||
struct OperatorNode;
|
||||
|
||||
struct ClassNode : public Node {
|
||||
bool tool;
|
||||
StringName name;
|
||||
bool extends_used;
|
||||
bool classname_used;
|
||||
StringName extends_file;
|
||||
Vector<StringName> extends_class;
|
||||
DataType base_type;
|
||||
String icon_path;
|
||||
|
||||
struct Member {
|
||||
PropertyInfo _export;
|
||||
#ifdef TOOLS_ENABLED
|
||||
Variant default_value;
|
||||
#endif
|
||||
StringName identifier;
|
||||
DataType data_type;
|
||||
StringName setter;
|
||||
StringName getter;
|
||||
int line;
|
||||
Node *expression;
|
||||
OperatorNode *initial_assignment;
|
||||
int usages;
|
||||
};
|
||||
|
||||
struct Constant {
|
||||
Node *expression;
|
||||
DataType type;
|
||||
};
|
||||
|
||||
struct Signal {
|
||||
StringName name;
|
||||
Vector<StringName> arguments;
|
||||
int emissions;
|
||||
int line;
|
||||
};
|
||||
|
||||
Vector<ClassNode *> subclasses;
|
||||
Vector<Member> variables;
|
||||
RBMap<StringName, Constant> constant_expressions;
|
||||
Vector<FunctionNode *> functions;
|
||||
Vector<FunctionNode *> static_functions;
|
||||
Vector<Signal> _signals;
|
||||
BlockNode *initializer;
|
||||
BlockNode *ready;
|
||||
ClassNode *owner;
|
||||
//Vector<Node*> initializers;
|
||||
int end_line;
|
||||
|
||||
ClassNode() {
|
||||
tool = false;
|
||||
type = TYPE_CLASS;
|
||||
extends_used = false;
|
||||
classname_used = false;
|
||||
end_line = -1;
|
||||
owner = nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
struct FunctionNode : public Node {
|
||||
bool _static;
|
||||
bool has_unreachable_code;
|
||||
StringName name;
|
||||
DataType return_type;
|
||||
Vector<StringName> arguments;
|
||||
Vector<DataType> argument_types;
|
||||
Vector<Node *> default_values;
|
||||
BlockNode *body;
|
||||
#ifdef DEBUG_ENABLED
|
||||
Vector<int> arguments_usage;
|
||||
#endif // DEBUG_ENABLED
|
||||
|
||||
virtual DataType get_datatype() const {
|
||||
return return_type;
|
||||
}
|
||||
virtual void set_datatype(const DataType &p_datatype) {
|
||||
return_type = p_datatype;
|
||||
}
|
||||
int get_required_argument_count() {
|
||||
return arguments.size() - default_values.size();
|
||||
}
|
||||
|
||||
FunctionNode() {
|
||||
type = TYPE_FUNCTION;
|
||||
_static = false;
|
||||
has_unreachable_code = false;
|
||||
}
|
||||
};
|
||||
|
||||
struct BlockNode : public Node {
|
||||
ClassNode *parent_class;
|
||||
BlockNode *parent_block;
|
||||
Vector<Node *> statements;
|
||||
RBMap<StringName, LocalVarNode *> variables;
|
||||
bool has_return = false;
|
||||
bool can_break = false;
|
||||
bool can_continue = false;
|
||||
|
||||
Node *if_condition; //tiny hack to improve code completion on if () blocks
|
||||
|
||||
//the following is useful for code completion
|
||||
List<BlockNode *> sub_blocks;
|
||||
int end_line;
|
||||
BlockNode() {
|
||||
if_condition = nullptr;
|
||||
type = TYPE_BLOCK;
|
||||
end_line = -1;
|
||||
parent_block = nullptr;
|
||||
parent_class = nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
struct TypeNode : public Node {
|
||||
Variant::Type vtype;
|
||||
TypeNode() { type = TYPE_TYPE; }
|
||||
};
|
||||
struct BuiltInFunctionNode : public Node {
|
||||
CScriptFunctions::Function function;
|
||||
BuiltInFunctionNode() { type = TYPE_BUILT_IN_FUNCTION; }
|
||||
};
|
||||
|
||||
struct IdentifierNode : public Node {
|
||||
StringName name;
|
||||
BlockNode *declared_block; // Simplify lookup by checking if it is declared locally
|
||||
DataType datatype;
|
||||
virtual DataType get_datatype() const { return datatype; }
|
||||
virtual void set_datatype(const DataType &p_datatype) { datatype = p_datatype; }
|
||||
IdentifierNode() {
|
||||
type = TYPE_IDENTIFIER;
|
||||
declared_block = nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
struct LocalVarNode : public Node {
|
||||
StringName name;
|
||||
Node *assign;
|
||||
OperatorNode *assign_op;
|
||||
int assignments;
|
||||
int usages;
|
||||
DataType datatype;
|
||||
virtual DataType get_datatype() const { return datatype; }
|
||||
virtual void set_datatype(const DataType &p_datatype) { datatype = p_datatype; }
|
||||
LocalVarNode() {
|
||||
type = TYPE_LOCAL_VAR;
|
||||
assign = nullptr;
|
||||
assign_op = nullptr;
|
||||
assignments = 0;
|
||||
usages = 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct ConstantNode : public Node {
|
||||
Variant value;
|
||||
DataType datatype;
|
||||
virtual DataType get_datatype() const { return datatype; }
|
||||
virtual void set_datatype(const DataType &p_datatype) { datatype = p_datatype; }
|
||||
ConstantNode() { type = TYPE_CONSTANT; }
|
||||
};
|
||||
|
||||
struct ArrayNode : public Node {
|
||||
Vector<Node *> elements;
|
||||
DataType datatype;
|
||||
virtual DataType get_datatype() const { return datatype; }
|
||||
virtual void set_datatype(const DataType &p_datatype) { datatype = p_datatype; }
|
||||
ArrayNode() {
|
||||
type = TYPE_ARRAY;
|
||||
datatype.has_type = true;
|
||||
datatype.kind = DataType::BUILTIN;
|
||||
datatype.builtin_type = Variant::ARRAY;
|
||||
}
|
||||
};
|
||||
|
||||
struct DictionaryNode : public Node {
|
||||
struct Pair {
|
||||
Node *key;
|
||||
Node *value;
|
||||
};
|
||||
|
||||
Vector<Pair> elements;
|
||||
DataType datatype;
|
||||
virtual DataType get_datatype() const { return datatype; }
|
||||
virtual void set_datatype(const DataType &p_datatype) { datatype = p_datatype; }
|
||||
DictionaryNode() {
|
||||
type = TYPE_DICTIONARY;
|
||||
datatype.has_type = true;
|
||||
datatype.kind = DataType::BUILTIN;
|
||||
datatype.builtin_type = Variant::DICTIONARY;
|
||||
}
|
||||
};
|
||||
|
||||
struct SelfNode : public Node {
|
||||
SelfNode() { type = TYPE_SELF; }
|
||||
};
|
||||
|
||||
struct OperatorNode : public Node {
|
||||
enum Operator {
|
||||
//call/constructor operator
|
||||
OP_CALL,
|
||||
OP_PARENT_CALL,
|
||||
OP_IS,
|
||||
OP_IS_BUILTIN,
|
||||
//indexing operator
|
||||
OP_INDEX,
|
||||
OP_INDEX_NAMED,
|
||||
//unary operators
|
||||
OP_NEG,
|
||||
OP_POS,
|
||||
OP_NOT,
|
||||
OP_BIT_INVERT,
|
||||
//binary operators (in precedence order)
|
||||
OP_IN,
|
||||
OP_EQUAL,
|
||||
OP_NOT_EQUAL,
|
||||
OP_LESS,
|
||||
OP_LESS_EQUAL,
|
||||
OP_GREATER,
|
||||
OP_GREATER_EQUAL,
|
||||
OP_AND,
|
||||
OP_OR,
|
||||
OP_ADD,
|
||||
OP_SUB,
|
||||
OP_MUL,
|
||||
OP_DIV,
|
||||
OP_MOD,
|
||||
OP_SHIFT_LEFT,
|
||||
OP_SHIFT_RIGHT,
|
||||
OP_INIT_ASSIGN,
|
||||
OP_ASSIGN,
|
||||
OP_ASSIGN_ADD,
|
||||
OP_ASSIGN_SUB,
|
||||
OP_ASSIGN_MUL,
|
||||
OP_ASSIGN_DIV,
|
||||
OP_ASSIGN_MOD,
|
||||
OP_ASSIGN_SHIFT_LEFT,
|
||||
OP_ASSIGN_SHIFT_RIGHT,
|
||||
OP_ASSIGN_BIT_AND,
|
||||
OP_ASSIGN_BIT_OR,
|
||||
OP_ASSIGN_BIT_XOR,
|
||||
OP_BIT_AND,
|
||||
OP_BIT_OR,
|
||||
OP_BIT_XOR,
|
||||
//ternary operators
|
||||
OP_TERNARY_IF,
|
||||
OP_TERNARY_ELSE,
|
||||
};
|
||||
|
||||
Operator op;
|
||||
|
||||
Vector<Node *> arguments;
|
||||
DataType datatype;
|
||||
virtual DataType get_datatype() const { return datatype; }
|
||||
virtual void set_datatype(const DataType &p_datatype) { datatype = p_datatype; }
|
||||
OperatorNode() { type = TYPE_OPERATOR; }
|
||||
};
|
||||
|
||||
struct PatternNode : public Node {
|
||||
enum PatternType {
|
||||
PT_CONSTANT,
|
||||
PT_BIND,
|
||||
PT_DICTIONARY,
|
||||
PT_ARRAY,
|
||||
PT_IGNORE_REST,
|
||||
PT_WILDCARD
|
||||
};
|
||||
|
||||
PatternType pt_type;
|
||||
|
||||
Node *constant;
|
||||
StringName bind;
|
||||
RBMap<ConstantNode *, PatternNode *> dictionary;
|
||||
Vector<PatternNode *> array;
|
||||
};
|
||||
|
||||
struct PatternBranchNode : public Node {
|
||||
Vector<PatternNode *> patterns;
|
||||
BlockNode *body;
|
||||
};
|
||||
|
||||
struct MatchNode : public Node {
|
||||
Node *val_to_match;
|
||||
Vector<PatternBranchNode *> branches;
|
||||
|
||||
struct CompiledPatternBranch {
|
||||
Node *compiled_pattern;
|
||||
BlockNode *body;
|
||||
};
|
||||
|
||||
Vector<CompiledPatternBranch> compiled_pattern_branches;
|
||||
};
|
||||
|
||||
struct ControlFlowNode : public Node {
|
||||
enum CFType {
|
||||
CF_IF,
|
||||
CF_FOR,
|
||||
CF_WHILE,
|
||||
CF_BREAK,
|
||||
CF_CONTINUE,
|
||||
CF_RETURN,
|
||||
CF_MATCH
|
||||
};
|
||||
|
||||
CFType cf_type;
|
||||
Vector<Node *> arguments;
|
||||
BlockNode *body;
|
||||
BlockNode *body_else;
|
||||
|
||||
MatchNode *match;
|
||||
|
||||
ControlFlowNode *_else; //used for if
|
||||
ControlFlowNode() {
|
||||
type = TYPE_CONTROL_FLOW;
|
||||
cf_type = CF_IF;
|
||||
body = nullptr;
|
||||
body_else = nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
struct CastNode : public Node {
|
||||
Node *source_node;
|
||||
DataType cast_type;
|
||||
DataType return_type;
|
||||
virtual DataType get_datatype() const { return return_type; }
|
||||
virtual void set_datatype(const DataType &p_datatype) { return_type = p_datatype; }
|
||||
CastNode() { type = TYPE_CAST; }
|
||||
};
|
||||
|
||||
struct AssertNode : public Node {
|
||||
Node *condition;
|
||||
Node *message;
|
||||
AssertNode() :
|
||||
condition(nullptr),
|
||||
message(nullptr) {
|
||||
type = TYPE_ASSERT;
|
||||
}
|
||||
};
|
||||
|
||||
struct BreakpointNode : public Node {
|
||||
BreakpointNode() { type = TYPE_BREAKPOINT; }
|
||||
};
|
||||
|
||||
struct NewLineNode : public Node {
|
||||
NewLineNode() { type = TYPE_NEWLINE; }
|
||||
};
|
||||
|
||||
struct Expression {
|
||||
bool is_op;
|
||||
union {
|
||||
OperatorNode::Operator op;
|
||||
Node *node;
|
||||
};
|
||||
};
|
||||
|
||||
enum CompletionType {
|
||||
COMPLETION_NONE,
|
||||
COMPLETION_BUILT_IN_TYPE_CONSTANT,
|
||||
COMPLETION_GET_NODE,
|
||||
COMPLETION_FUNCTION,
|
||||
COMPLETION_IDENTIFIER,
|
||||
COMPLETION_EXTENDS,
|
||||
COMPLETION_PARENT_FUNCTION,
|
||||
COMPLETION_METHOD,
|
||||
COMPLETION_CALL_ARGUMENTS,
|
||||
COMPLETION_RESOURCE_PATH,
|
||||
COMPLETION_INDEX,
|
||||
COMPLETION_VIRTUAL_FUNC,
|
||||
COMPLETION_ASSIGN,
|
||||
COMPLETION_TYPE_HINT,
|
||||
COMPLETION_TYPE_HINT_INDEX,
|
||||
};
|
||||
|
||||
private:
|
||||
CScriptTokenizer *tokenizer;
|
||||
|
||||
Node *head;
|
||||
Node *list;
|
||||
template <class T>
|
||||
T *alloc_node();
|
||||
|
||||
bool validating;
|
||||
bool for_completion;
|
||||
int parenthesis;
|
||||
bool error_set;
|
||||
String error;
|
||||
int error_line;
|
||||
int error_column;
|
||||
bool check_types;
|
||||
bool dependencies_only;
|
||||
List<String> dependencies;
|
||||
#ifdef DEBUG_ENABLED
|
||||
RBSet<int> *safe_lines;
|
||||
#endif // DEBUG_ENABLED
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
List<CScriptWarning> warnings;
|
||||
#endif // DEBUG_ENABLED
|
||||
|
||||
int pending_newline;
|
||||
|
||||
struct IndentLevel {
|
||||
int indent;
|
||||
int tabs;
|
||||
|
||||
bool is_mixed(IndentLevel other) {
|
||||
return (
|
||||
(indent == other.indent && tabs != other.tabs) ||
|
||||
(indent > other.indent && tabs < other.tabs) ||
|
||||
(indent < other.indent && tabs > other.tabs));
|
||||
}
|
||||
|
||||
IndentLevel() :
|
||||
indent(0),
|
||||
tabs(0) {}
|
||||
|
||||
IndentLevel(int p_indent, int p_tabs) :
|
||||
indent(p_indent),
|
||||
tabs(p_tabs) {}
|
||||
};
|
||||
|
||||
List<IndentLevel> indent_level;
|
||||
|
||||
String base_path;
|
||||
String self_path;
|
||||
|
||||
ClassNode *current_class;
|
||||
FunctionNode *current_function;
|
||||
BlockNode *current_block;
|
||||
|
||||
bool _get_completable_identifier(CompletionType p_type, StringName &identifier);
|
||||
void _make_completable_call(int p_arg);
|
||||
|
||||
CompletionType completion_type;
|
||||
StringName completion_cursor;
|
||||
Variant::Type completion_built_in_constant;
|
||||
Node *completion_node;
|
||||
ClassNode *completion_class;
|
||||
FunctionNode *completion_function;
|
||||
BlockNode *completion_block;
|
||||
int completion_line;
|
||||
int completion_argument;
|
||||
bool completion_found;
|
||||
bool completion_ident_is_call;
|
||||
|
||||
PropertyInfo current_export;
|
||||
|
||||
void _set_error(const String &p_error, int p_line = -1, int p_column = -1);
|
||||
#ifdef DEBUG_ENABLED
|
||||
void _add_warning(int p_code, int p_line = -1, const String &p_symbol1 = String(), const String &p_symbol2 = String(), const String &p_symbol3 = String(), const String &p_symbol4 = String());
|
||||
void _add_warning(int p_code, int p_line, const Vector<String> &p_symbols);
|
||||
#endif // DEBUG_ENABLED
|
||||
bool _recover_from_completion();
|
||||
|
||||
bool _parse_arguments(Node *p_parent, Vector<Node *> &p_args, bool p_static, bool p_can_codecomplete = false, bool p_parsing_constant = false);
|
||||
bool _enter_indent_block(BlockNode *p_block = nullptr);
|
||||
bool _parse_newline();
|
||||
Node *_parse_expression(Node *p_parent, bool p_static, bool p_allow_assign = false, bool p_parsing_constant = false);
|
||||
Node *_reduce_expression(Node *p_node, bool p_to_const = false);
|
||||
Node *_parse_and_reduce_expression(Node *p_parent, bool p_static, bool p_reduce_const = false, bool p_allow_assign = false);
|
||||
bool _reduce_export_var_type(Variant &p_value, int p_line = 0);
|
||||
|
||||
PatternNode *_parse_pattern(bool p_static);
|
||||
void _parse_pattern_block(BlockNode *p_block, Vector<PatternBranchNode *> &p_branches, bool p_static);
|
||||
void _transform_match_statment(MatchNode *p_match_statement);
|
||||
void _generate_pattern(PatternNode *p_pattern, Node *p_node_to_match, Node *&p_resulting_node, RBMap<StringName, Node *> &p_bindings);
|
||||
|
||||
void _parse_block(BlockNode *p_block, bool p_static);
|
||||
void _parse_extends(ClassNode *p_class);
|
||||
void _parse_class(ClassNode *p_class);
|
||||
bool _end_statement();
|
||||
void _set_end_statement_error(String p_name);
|
||||
|
||||
void _determine_inheritance(ClassNode *p_class, bool p_recursive = true);
|
||||
bool _parse_type(DataType &r_type, bool p_can_be_void = false);
|
||||
DataType _resolve_type(const DataType &p_source, int p_line);
|
||||
DataType _type_from_variant(const Variant &p_value) const;
|
||||
DataType _type_from_property(const PropertyInfo &p_property, bool p_nil_is_variant = true) const;
|
||||
DataType _type_from_gdtype(const CScriptDataType &p_gdtype) const;
|
||||
DataType _get_operation_type(const Variant::Operator p_op, const DataType &p_a, const DataType &p_b, bool &r_valid) const;
|
||||
Variant::Operator _get_variant_operation(const OperatorNode::Operator &p_op) const;
|
||||
bool _get_function_signature(DataType &p_base_type, const StringName &p_function, DataType &r_return_type, List<DataType> &r_arg_types, int &r_default_arg_count, bool &r_static, bool &r_vararg) const;
|
||||
bool _get_member_type(const DataType &p_base_type, const StringName &p_member, DataType &r_member_type, bool *r_is_const = nullptr) const;
|
||||
bool _is_type_compatible(const DataType &p_container, const DataType &p_expression, bool p_allow_implicit_conversion = false) const;
|
||||
Node *_get_default_value_for_type(const DataType &p_type, int p_line = -1);
|
||||
|
||||
DataType _reduce_node_type(Node *p_node);
|
||||
DataType _reduce_function_call_type(const OperatorNode *p_call);
|
||||
DataType _reduce_identifier_type(const DataType *p_base_type, const StringName &p_identifier, int p_line, bool p_is_indexing);
|
||||
void _check_class_level_types(ClassNode *p_class);
|
||||
void _check_class_blocks_types(ClassNode *p_class);
|
||||
void _check_function_types(FunctionNode *p_function);
|
||||
void _check_block_types(BlockNode *p_block);
|
||||
_FORCE_INLINE_ void _mark_line_as_safe(int p_line) const {
|
||||
#ifdef DEBUG_ENABLED
|
||||
if (safe_lines) {
|
||||
safe_lines->insert(p_line);
|
||||
}
|
||||
#endif // DEBUG_ENABLED
|
||||
}
|
||||
_FORCE_INLINE_ void _mark_line_as_unsafe(int p_line) const {
|
||||
#ifdef DEBUG_ENABLED
|
||||
if (safe_lines) {
|
||||
safe_lines->erase(p_line);
|
||||
}
|
||||
#endif // DEBUG_ENABLED
|
||||
}
|
||||
|
||||
Error _parse(const String &p_base_path);
|
||||
|
||||
public:
|
||||
bool has_error() const;
|
||||
String get_error() const;
|
||||
int get_error_line() const;
|
||||
int get_error_column() const;
|
||||
#ifdef DEBUG_ENABLED
|
||||
const List<CScriptWarning> &get_warnings() const {
|
||||
return warnings;
|
||||
}
|
||||
#endif // DEBUG_ENABLED
|
||||
Error parse(const String &p_code, const String &p_base_path = "", bool p_just_validate = false, const String &p_self_path = "", bool p_for_completion = false, RBSet<int> *r_safe_lines = nullptr, bool p_dependencies_only = false);
|
||||
Error parse_bytecode(const Vector<uint8_t> &p_bytecode, const String &p_base_path = "", const String &p_self_path = "");
|
||||
|
||||
bool is_tool_script() const;
|
||||
const Node *get_parse_tree() const;
|
||||
|
||||
//completion info
|
||||
|
||||
CompletionType get_completion_type();
|
||||
StringName get_completion_cursor();
|
||||
int get_completion_line();
|
||||
Variant::Type get_completion_built_in_constant();
|
||||
Node *get_completion_node();
|
||||
ClassNode *get_completion_class();
|
||||
BlockNode *get_completion_block();
|
||||
FunctionNode *get_completion_function();
|
||||
int get_completion_argument_index();
|
||||
int get_completion_identifier_is_function();
|
||||
|
||||
const List<String> &get_dependencies() const {
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
void clear();
|
||||
CScriptParser();
|
||||
~CScriptParser();
|
||||
};
|
||||
|
||||
#endif // CSCRIPT_PARSER_H
|
@ -1,310 +0,0 @@
|
||||
#ifndef CSCRIPT_TOKENIZER_H
|
||||
#define CSCRIPT_TOKENIZER_H
|
||||
/*************************************************************************/
|
||||
/* gdscript_tokenizer.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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 "core/containers/oa_hash_map.h"
|
||||
#include "core/containers/pair.h"
|
||||
#include "core/containers/vmap.h"
|
||||
#include "core/string/string_name.h"
|
||||
#include "core/string/ustring.h"
|
||||
#include "core/variant/variant.h"
|
||||
#include "cscript_functions.h"
|
||||
|
||||
class CScriptTokenizer {
|
||||
public:
|
||||
enum Token {
|
||||
|
||||
TK_EMPTY,
|
||||
TK_IDENTIFIER,
|
||||
TK_CONSTANT,
|
||||
TK_SELF,
|
||||
TK_BUILT_IN_TYPE,
|
||||
TK_BUILT_IN_FUNC,
|
||||
TK_OP_IN,
|
||||
TK_OP_EQUAL,
|
||||
TK_OP_NOT_EQUAL,
|
||||
TK_OP_LESS,
|
||||
TK_OP_LESS_EQUAL,
|
||||
TK_OP_GREATER,
|
||||
TK_OP_GREATER_EQUAL,
|
||||
TK_OP_AND,
|
||||
TK_OP_OR,
|
||||
TK_OP_NOT,
|
||||
TK_OP_ADD,
|
||||
TK_OP_SUB,
|
||||
TK_OP_MUL,
|
||||
TK_OP_DIV,
|
||||
TK_OP_MOD,
|
||||
TK_OP_SHIFT_LEFT,
|
||||
TK_OP_SHIFT_RIGHT,
|
||||
TK_OP_ASSIGN,
|
||||
TK_OP_ASSIGN_ADD,
|
||||
TK_OP_ASSIGN_SUB,
|
||||
TK_OP_ASSIGN_MUL,
|
||||
TK_OP_ASSIGN_DIV,
|
||||
TK_OP_ASSIGN_MOD,
|
||||
TK_OP_ASSIGN_SHIFT_LEFT,
|
||||
TK_OP_ASSIGN_SHIFT_RIGHT,
|
||||
TK_OP_ASSIGN_BIT_AND,
|
||||
TK_OP_ASSIGN_BIT_OR,
|
||||
TK_OP_ASSIGN_BIT_XOR,
|
||||
TK_OP_BIT_AND,
|
||||
TK_OP_BIT_OR,
|
||||
TK_OP_BIT_XOR,
|
||||
TK_OP_BIT_INVERT,
|
||||
//TK_OP_PLUS_PLUS,
|
||||
//TK_OP_MINUS_MINUS,
|
||||
TK_CF_IF,
|
||||
TK_CF_ELIF,
|
||||
TK_CF_ELSE,
|
||||
TK_CF_FOR,
|
||||
TK_CF_WHILE,
|
||||
TK_CF_BREAK,
|
||||
TK_CF_CONTINUE,
|
||||
TK_CF_PASS,
|
||||
TK_CF_RETURN,
|
||||
TK_CF_MATCH,
|
||||
TK_PR_FUNCTION,
|
||||
TK_PR_CLASS,
|
||||
TK_PR_CLASS_NAME,
|
||||
TK_PR_EXTENDS,
|
||||
TK_PR_IS,
|
||||
TK_PR_ONREADY,
|
||||
TK_PR_TOOL,
|
||||
TK_PR_STATIC,
|
||||
TK_PR_EXPORT,
|
||||
TK_PR_SETGET,
|
||||
TK_PR_CONST,
|
||||
TK_PR_VAR,
|
||||
TK_PR_AS,
|
||||
TK_PR_VOID,
|
||||
TK_PR_ENUM,
|
||||
TK_PR_PRELOAD,
|
||||
TK_PR_ASSERT,
|
||||
TK_PR_SIGNAL,
|
||||
TK_PR_BREAKPOINT,
|
||||
TK_BRACKET_OPEN,
|
||||
TK_BRACKET_CLOSE,
|
||||
TK_CURLY_BRACKET_OPEN,
|
||||
TK_CURLY_BRACKET_CLOSE,
|
||||
TK_PARENTHESIS_OPEN,
|
||||
TK_PARENTHESIS_CLOSE,
|
||||
TK_COMMA,
|
||||
TK_SEMICOLON,
|
||||
TK_PERIOD,
|
||||
TK_QUESTION_MARK,
|
||||
TK_COLON,
|
||||
TK_DOLLAR,
|
||||
TK_FORWARD_ARROW,
|
||||
TK_NEWLINE,
|
||||
TK_CONST_PI,
|
||||
TK_CONST_TAU,
|
||||
TK_WILDCARD,
|
||||
TK_CONST_INF,
|
||||
TK_CONST_NAN,
|
||||
TK_ERROR,
|
||||
TK_EOF,
|
||||
TK_CURSOR, //used for code completion
|
||||
TK_MAX
|
||||
};
|
||||
|
||||
protected:
|
||||
enum StringMode {
|
||||
STRING_SINGLE_QUOTE,
|
||||
STRING_DOUBLE_QUOTE,
|
||||
STRING_MULTILINE
|
||||
};
|
||||
|
||||
static const char *token_names[TK_MAX];
|
||||
|
||||
enum {
|
||||
TOKEN_HASH_TABLE_TYPE_START = 3,
|
||||
TOKEN_HASH_TABLE_BUILTIN_START = TOKEN_HASH_TABLE_TYPE_START + Variant::VARIANT_MAX,
|
||||
TOKEN_HASH_TABLE_KEYWORD_START = TOKEN_HASH_TABLE_BUILTIN_START + CScriptFunctions::FUNC_MAX,
|
||||
};
|
||||
|
||||
static OAHashMap<String, int> *token_hashtable;
|
||||
|
||||
public:
|
||||
static const char *get_token_name(Token p_token);
|
||||
|
||||
static void initialize();
|
||||
static void terminate();
|
||||
|
||||
bool is_token_literal(int p_offset = 0, bool variable_safe = false) const;
|
||||
StringName get_token_literal(int p_offset = 0) const;
|
||||
|
||||
virtual const Variant &get_token_constant(int p_offset = 0) const = 0;
|
||||
virtual Token get_token(int p_offset = 0) const = 0;
|
||||
virtual StringName get_token_identifier(int p_offset = 0) const = 0;
|
||||
virtual CScriptFunctions::Function get_token_built_in_func(int p_offset = 0) const = 0;
|
||||
virtual Variant::Type get_token_type(int p_offset = 0) const = 0;
|
||||
virtual int get_token_line(int p_offset = 0) const = 0;
|
||||
virtual int get_token_column(int p_offset = 0) const = 0;
|
||||
virtual int get_token_line_indent(int p_offset = 0) const = 0;
|
||||
virtual int get_token_line_tab_indent(int p_offset = 0) const = 0;
|
||||
virtual String get_token_error(int p_offset = 0) const = 0;
|
||||
virtual void advance(int p_amount = 1) = 0;
|
||||
#ifdef DEBUG_ENABLED
|
||||
virtual const Vector<Pair<int, String>> &get_warning_skips() const = 0;
|
||||
virtual const RBSet<String> &get_warning_global_skips() const = 0;
|
||||
virtual bool is_ignoring_warnings() const = 0;
|
||||
#endif // DEBUG_ENABLED
|
||||
|
||||
virtual ~CScriptTokenizer() {}
|
||||
};
|
||||
|
||||
class CScriptTokenizerText : public CScriptTokenizer {
|
||||
enum {
|
||||
MAX_LOOKAHEAD = 4,
|
||||
TK_RB_SIZE = MAX_LOOKAHEAD * 2 + 1
|
||||
|
||||
};
|
||||
|
||||
struct TokenData {
|
||||
Token type;
|
||||
StringName identifier; //for identifier types
|
||||
Variant constant; //for constant types
|
||||
union {
|
||||
Variant::Type vtype; //for type types
|
||||
CScriptFunctions::Function func; //function for built in functions
|
||||
int warning_code; //for warning skip
|
||||
};
|
||||
int line, col;
|
||||
TokenData() {
|
||||
type = TK_EMPTY;
|
||||
line = col = 0;
|
||||
vtype = Variant::NIL;
|
||||
}
|
||||
};
|
||||
|
||||
void _make_token(Token p_type);
|
||||
void _make_newline(int p_indentation = 0, int p_tabs = 0);
|
||||
void _make_identifier(const StringName &p_identifier);
|
||||
void _make_built_in_func(CScriptFunctions::Function p_func);
|
||||
void _make_constant(const Variant &p_constant);
|
||||
void _make_type(const Variant::Type &p_type);
|
||||
void _make_error(const String &p_error);
|
||||
|
||||
String code;
|
||||
int len;
|
||||
int code_pos;
|
||||
const CharType *_code;
|
||||
int line;
|
||||
int column;
|
||||
TokenData tk_rb[TK_RB_SIZE * 2 + 1];
|
||||
int tk_rb_pos;
|
||||
String last_error;
|
||||
bool error_flag;
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
Vector<Pair<int, String>> warning_skips;
|
||||
RBSet<String> warning_global_skips;
|
||||
bool ignore_warnings;
|
||||
#endif // DEBUG_ENABLED
|
||||
|
||||
void _advance();
|
||||
bool _parse_identifier(const String &p_str);
|
||||
|
||||
public:
|
||||
void set_code(const String &p_code);
|
||||
virtual Token get_token(int p_offset = 0) const;
|
||||
virtual StringName get_token_identifier(int p_offset = 0) const;
|
||||
virtual CScriptFunctions::Function get_token_built_in_func(int p_offset = 0) const;
|
||||
virtual Variant::Type get_token_type(int p_offset = 0) const;
|
||||
virtual int get_token_line(int p_offset = 0) const;
|
||||
virtual int get_token_column(int p_offset = 0) const;
|
||||
virtual int get_token_line_indent(int p_offset = 0) const;
|
||||
virtual int get_token_line_tab_indent(int p_offset = 0) const;
|
||||
virtual const Variant &get_token_constant(int p_offset = 0) const;
|
||||
virtual String get_token_error(int p_offset = 0) const;
|
||||
virtual void advance(int p_amount = 1);
|
||||
#ifdef DEBUG_ENABLED
|
||||
virtual const Vector<Pair<int, String>> &get_warning_skips() const {
|
||||
return warning_skips;
|
||||
}
|
||||
virtual const RBSet<String> &get_warning_global_skips() const {
|
||||
return warning_global_skips;
|
||||
}
|
||||
virtual bool is_ignoring_warnings() const {
|
||||
return ignore_warnings;
|
||||
}
|
||||
#endif // DEBUG_ENABLED
|
||||
};
|
||||
|
||||
class CScriptTokenizerBuffer : public CScriptTokenizer {
|
||||
enum {
|
||||
|
||||
TOKEN_BYTE_MASK = 0x80,
|
||||
TOKEN_BITS = 8,
|
||||
TOKEN_MASK = (1 << TOKEN_BITS) - 1,
|
||||
TOKEN_LINE_BITS = 24,
|
||||
TOKEN_LINE_MASK = (1 << TOKEN_LINE_BITS) - 1,
|
||||
};
|
||||
|
||||
Vector<StringName> identifiers;
|
||||
Vector<Variant> constants;
|
||||
VMap<uint32_t, uint32_t> lines;
|
||||
Vector<uint32_t> tokens;
|
||||
Variant nil;
|
||||
int token;
|
||||
|
||||
public:
|
||||
Error set_code_buffer(const Vector<uint8_t> &p_buffer);
|
||||
static Vector<uint8_t> parse_code_string(const String &p_code);
|
||||
virtual Token get_token(int p_offset = 0) const;
|
||||
virtual StringName get_token_identifier(int p_offset = 0) const;
|
||||
virtual CScriptFunctions::Function get_token_built_in_func(int p_offset = 0) const;
|
||||
virtual Variant::Type get_token_type(int p_offset = 0) const;
|
||||
virtual int get_token_line(int p_offset = 0) const;
|
||||
virtual int get_token_column(int p_offset = 0) const;
|
||||
virtual int get_token_line_indent(int p_offset = 0) const;
|
||||
virtual int get_token_line_tab_indent(int p_offset = 0) const { return 0; }
|
||||
virtual const Variant &get_token_constant(int p_offset = 0) const;
|
||||
virtual String get_token_error(int p_offset = 0) const;
|
||||
virtual void advance(int p_amount = 1);
|
||||
#ifdef DEBUG_ENABLED
|
||||
virtual const Vector<Pair<int, String>> &get_warning_skips() const {
|
||||
static Vector<Pair<int, String>> v;
|
||||
return v;
|
||||
}
|
||||
virtual const RBSet<String> &get_warning_global_skips() const {
|
||||
static RBSet<String> s;
|
||||
return s;
|
||||
}
|
||||
virtual bool is_ignoring_warnings() const {
|
||||
return true;
|
||||
}
|
||||
#endif // DEBUG_ENABLED
|
||||
CScriptTokenizerBuffer();
|
||||
};
|
||||
|
||||
#endif // CSCRIPT_TOKENIZER_H
|
@ -1,35 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="CScript" inherits="Script" version="4.1">
|
||||
<brief_description>
|
||||
A script implemented in the CScript programming language.
|
||||
</brief_description>
|
||||
<description>
|
||||
A script implemented in the CScript programming language. The script extends the functionality of all objects that instance it.
|
||||
[method new] creates a new instance of the script. [method Object.set_script] extends an existing object, if that object's class matches one of the script's base classes.
|
||||
</description>
|
||||
<tutorials>
|
||||
<link>$DOCS_URL/tutorials/scripting/gdscript/index.md</link>
|
||||
</tutorials>
|
||||
<methods>
|
||||
<method name="get_as_byte_code" qualifiers="const">
|
||||
<return type="PoolByteArray" />
|
||||
<description>
|
||||
Returns byte code for the script source code.
|
||||
</description>
|
||||
</method>
|
||||
<method name="new" qualifiers="vararg">
|
||||
<return type="Variant" />
|
||||
<description>
|
||||
Returns a new instance of the script.
|
||||
For example:
|
||||
[codeblock]
|
||||
var MyClass = load("myclass.gd")
|
||||
var instance = MyClass.new()
|
||||
assert(instance.get_script() == MyClass)
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,610 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* gdscript_highlighter.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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 "cscript_highlighter.h"
|
||||
#include "../cscript.h"
|
||||
#include "../cscript_tokenizer.h"
|
||||
#include "core/config/project_settings.h"
|
||||
#include "editor/editor_settings.h"
|
||||
|
||||
static bool _is_char(CharType c) {
|
||||
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_';
|
||||
}
|
||||
|
||||
static bool _is_hex_symbol(CharType c) {
|
||||
return ((c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'));
|
||||
}
|
||||
|
||||
static bool _is_bin_symbol(CharType c) {
|
||||
return (c == '0' || c == '1');
|
||||
}
|
||||
|
||||
Dictionary CScriptSyntaxHighlighter::_get_line_syntax_highlighting(int p_line) {
|
||||
Dictionary color_map;
|
||||
|
||||
Type next_type = NONE;
|
||||
Type current_type = NONE;
|
||||
Type previous_type = NONE;
|
||||
|
||||
String previous_text = "";
|
||||
int previous_column = 0;
|
||||
|
||||
bool prev_is_char = false;
|
||||
bool prev_is_number = false;
|
||||
bool in_keyword = false;
|
||||
bool in_word = false;
|
||||
bool in_function_name = false;
|
||||
bool in_variable_declaration = false;
|
||||
bool in_function_args = false;
|
||||
bool in_member_variable = false;
|
||||
bool in_node_path = false;
|
||||
bool is_hex_notation = false;
|
||||
bool is_bin_notation = false;
|
||||
bool expect_type = false;
|
||||
Color keyword_color;
|
||||
Color color;
|
||||
|
||||
color_region_cache[p_line] = -1;
|
||||
int in_region = -1;
|
||||
if (p_line != 0) {
|
||||
if (!color_region_cache.has(p_line - 1)) {
|
||||
get_line_syntax_highlighting(p_line - 1);
|
||||
}
|
||||
in_region = color_region_cache[p_line - 1];
|
||||
}
|
||||
|
||||
const String &str = text_edit->get_line(p_line);
|
||||
const int line_length = str.length();
|
||||
Color prev_color;
|
||||
for (int j = 0; j < str.length(); j++) {
|
||||
Dictionary highlighter_info;
|
||||
|
||||
color = font_color;
|
||||
bool is_char = !is_symbol(str[j]);
|
||||
bool is_a_symbol = is_symbol(str[j]);
|
||||
bool is_number = (str[j] >= '0' && str[j] <= '9');
|
||||
|
||||
/* color regions */
|
||||
if (is_a_symbol || in_region != -1) {
|
||||
int from = j;
|
||||
for (; from < line_length; from++) {
|
||||
if (str[from] == '\\') {
|
||||
from++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (from != line_length) {
|
||||
/* check if we are in entering a region */
|
||||
if (in_region == -1) {
|
||||
for (int c = 0; c < color_regions.size(); c++) {
|
||||
/* check there is enough room */
|
||||
int chars_left = line_length - from;
|
||||
int start_key_length = color_regions[c].start_key.length();
|
||||
int end_key_length = color_regions[c].end_key.length();
|
||||
if (chars_left < start_key_length) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* search the line */
|
||||
bool match = true;
|
||||
const CharType *start_key = color_regions[c].start_key.get_data();
|
||||
for (int k = 0; k < start_key_length; k++) {
|
||||
if (start_key[k] != str[from + k]) {
|
||||
match = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!match) {
|
||||
continue;
|
||||
}
|
||||
in_region = c;
|
||||
from += start_key_length;
|
||||
|
||||
/* check if it's the whole line */
|
||||
if (end_key_length == 0 || color_regions[c].line_only || from + end_key_length > line_length) {
|
||||
prev_color = color_regions[in_region].color;
|
||||
highlighter_info["color"] = color_regions[c].color;
|
||||
color_map[j] = highlighter_info;
|
||||
|
||||
j = line_length;
|
||||
if (!color_regions[c].line_only) {
|
||||
color_region_cache[p_line] = c;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (j == line_length) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/* if we are in one find the end key */
|
||||
if (in_region != -1) {
|
||||
/* check there is enough room */
|
||||
int chars_left = line_length - from;
|
||||
int end_key_length = color_regions[in_region].end_key.length();
|
||||
if (chars_left < end_key_length) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* search the line */
|
||||
int region_end_index = -1;
|
||||
const CharType *end_key = color_regions[in_region].start_key.get_data();
|
||||
for (; from < line_length; from++) {
|
||||
if (!is_a_symbol) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (str[from] == '\\') {
|
||||
from++;
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int k = 0; k < end_key_length; k++) {
|
||||
if (end_key[k] == str[from + k]) {
|
||||
region_end_index = from;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (region_end_index != -1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
prev_color = color_regions[in_region].color;
|
||||
highlighter_info["color"] = color_regions[in_region].color;
|
||||
color_map[j] = highlighter_info;
|
||||
|
||||
previous_type = REGION;
|
||||
previous_text = "";
|
||||
previous_column = j;
|
||||
j = from;
|
||||
if (region_end_index == -1) {
|
||||
color_region_cache[p_line] = in_region;
|
||||
}
|
||||
|
||||
in_region = -1;
|
||||
prev_is_char = false;
|
||||
prev_is_number = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// allow ABCDEF in hex notation
|
||||
if (is_hex_notation && (_is_hex_symbol(str[j]) || is_number)) {
|
||||
is_number = true;
|
||||
} else {
|
||||
is_hex_notation = false;
|
||||
}
|
||||
|
||||
// disallow anything not a 0 or 1
|
||||
if (is_bin_notation && (_is_bin_symbol(str[j]))) {
|
||||
is_number = true;
|
||||
} else if (is_bin_notation) {
|
||||
is_bin_notation = false;
|
||||
is_number = false;
|
||||
} else {
|
||||
is_bin_notation = false;
|
||||
}
|
||||
|
||||
// check for dot or underscore or 'x' for hex notation in floating point number or 'e' for scientific notation
|
||||
if ((str[j] == '.' || str[j] == 'x' || str[j] == 'b' || str[j] == '_' || str[j] == 'e') && !in_word && prev_is_number && !is_number) {
|
||||
is_number = true;
|
||||
is_a_symbol = false;
|
||||
is_char = false;
|
||||
|
||||
if (str[j] == 'x' && str[j - 1] == '0') {
|
||||
is_hex_notation = true;
|
||||
} else if (str[j] == 'b' && str[j - 1] == '0') {
|
||||
is_bin_notation = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!in_word && _is_char(str[j]) && !is_number) {
|
||||
in_word = true;
|
||||
}
|
||||
|
||||
if ((in_keyword || in_word) && !is_hex_notation) {
|
||||
is_number = false;
|
||||
}
|
||||
|
||||
if (is_a_symbol && str[j] != '.' && in_word) {
|
||||
in_word = false;
|
||||
}
|
||||
|
||||
if (!is_char) {
|
||||
in_keyword = false;
|
||||
}
|
||||
|
||||
if (!in_keyword && is_char && !prev_is_char) {
|
||||
int to = j;
|
||||
|
||||
while (to < str.length() && !is_symbol(str[to])) {
|
||||
to++;
|
||||
}
|
||||
|
||||
String word = str.substr(j, to - j);
|
||||
Color col = Color();
|
||||
if (keywords.has(word)) {
|
||||
col = keywords[word];
|
||||
} else if (member_keywords.has(word)) {
|
||||
col = member_keywords[word];
|
||||
for (int k = j - 1; k >= 0; k--) {
|
||||
if (str[k] == '.') {
|
||||
col = Color(); //member indexing not allowed
|
||||
break;
|
||||
} else if (str[k] > 32) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (col != Color()) {
|
||||
in_keyword = true;
|
||||
keyword_color = col;
|
||||
}
|
||||
}
|
||||
|
||||
if (!in_function_name && in_word && !in_keyword) {
|
||||
int k = j;
|
||||
while (k < str.length() && !is_symbol(str[k]) && str[k] != '\t' && str[k] != ' ') {
|
||||
k++;
|
||||
}
|
||||
|
||||
// check for space between name and bracket
|
||||
while (k < str.length() && (str[k] == '\t' || str[k] == ' ')) {
|
||||
k++;
|
||||
}
|
||||
|
||||
if (str[k] == '(') {
|
||||
in_function_name = true;
|
||||
} else if (previous_text == CScriptTokenizer::get_token_name(CScriptTokenizer::TK_PR_VAR)) {
|
||||
in_variable_declaration = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!in_function_name && !in_member_variable && !in_keyword && !is_number && in_word) {
|
||||
int k = j;
|
||||
while (k > 0 && !is_symbol(str[k]) && str[k] != '\t' && str[k] != ' ') {
|
||||
k--;
|
||||
}
|
||||
|
||||
if (str[k] == '.') {
|
||||
in_member_variable = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_a_symbol) {
|
||||
if (in_function_name) {
|
||||
in_function_args = true;
|
||||
}
|
||||
|
||||
if (in_function_args && str[j] == ')') {
|
||||
in_function_args = false;
|
||||
}
|
||||
|
||||
if (expect_type && (prev_is_char || str[j] == '=')) {
|
||||
expect_type = false;
|
||||
}
|
||||
|
||||
if (j > 0 && str[j] == '>' && str[j - 1] == '-') {
|
||||
expect_type = true;
|
||||
}
|
||||
|
||||
if (in_variable_declaration || in_function_args) {
|
||||
int k = j;
|
||||
// Skip space
|
||||
while (k < str.length() && (str[k] == '\t' || str[k] == ' ')) {
|
||||
k++;
|
||||
}
|
||||
|
||||
if (str[k] == ':') {
|
||||
// has type hint
|
||||
expect_type = true;
|
||||
}
|
||||
}
|
||||
|
||||
in_variable_declaration = false;
|
||||
in_function_name = false;
|
||||
in_member_variable = false;
|
||||
}
|
||||
|
||||
if (!in_node_path && in_region == -1 && str[j] == '$') {
|
||||
in_node_path = true;
|
||||
} else if (in_region != -1 || (is_a_symbol && str[j] != '/')) {
|
||||
in_node_path = false;
|
||||
}
|
||||
|
||||
if (in_node_path) {
|
||||
next_type = NODE_PATH;
|
||||
color = node_path_color;
|
||||
} else if (in_keyword) {
|
||||
next_type = KEYWORD;
|
||||
color = keyword_color;
|
||||
} else if (in_member_variable) {
|
||||
next_type = MEMBER;
|
||||
color = member_color;
|
||||
} else if (in_function_name) {
|
||||
next_type = FUNCTION;
|
||||
|
||||
if (previous_text == CScriptTokenizer::get_token_name(CScriptTokenizer::TK_PR_FUNCTION)) {
|
||||
color = function_definition_color;
|
||||
} else {
|
||||
color = function_color;
|
||||
}
|
||||
} else if (is_a_symbol) {
|
||||
next_type = SYMBOL;
|
||||
color = symbol_color;
|
||||
} else if (is_number) {
|
||||
next_type = NUMBER;
|
||||
color = number_color;
|
||||
} else if (expect_type) {
|
||||
next_type = TYPE;
|
||||
color = type_color;
|
||||
} else {
|
||||
next_type = IDENTIFIER;
|
||||
}
|
||||
|
||||
if (next_type != current_type) {
|
||||
if (current_type == NONE) {
|
||||
current_type = next_type;
|
||||
} else {
|
||||
previous_type = current_type;
|
||||
current_type = next_type;
|
||||
|
||||
// no need to store regions...
|
||||
if (previous_type == REGION) {
|
||||
previous_text = "";
|
||||
previous_column = j;
|
||||
} else {
|
||||
String text = str.substr(previous_column, j - previous_column).strip_edges();
|
||||
previous_column = j;
|
||||
|
||||
// ignore if just whitespace
|
||||
if (text != "") {
|
||||
previous_text = text;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
prev_is_char = is_char;
|
||||
prev_is_number = is_number;
|
||||
|
||||
if (color != prev_color) {
|
||||
prev_color = color;
|
||||
highlighter_info["color"] = color;
|
||||
color_map[j] = highlighter_info;
|
||||
}
|
||||
}
|
||||
return color_map;
|
||||
}
|
||||
|
||||
String CScriptSyntaxHighlighter::_get_name() const {
|
||||
return "CScript";
|
||||
}
|
||||
|
||||
Array CScriptSyntaxHighlighter::_get_supported_languages() const {
|
||||
Array languages;
|
||||
languages.push_back("CScript");
|
||||
return languages;
|
||||
}
|
||||
|
||||
void CScriptSyntaxHighlighter::_update_cache() {
|
||||
keywords.clear();
|
||||
member_keywords.clear();
|
||||
color_regions.clear();
|
||||
color_region_cache.clear();
|
||||
|
||||
font_color = text_edit->get_theme_color("font_color");
|
||||
symbol_color = EDITOR_GET("text_editor/highlighting/symbol_color");
|
||||
function_color = EDITOR_GET("text_editor/highlighting/function_color");
|
||||
number_color = EDITOR_GET("text_editor/highlighting/number_color");
|
||||
member_color = EDITOR_GET("text_editor/highlighting/member_variable_color");
|
||||
|
||||
/* Engine types. */
|
||||
const Color types_color = EDITOR_GET("text_editor/highlighting/engine_type_color");
|
||||
List<StringName> types;
|
||||
ClassDB::get_class_list(&types);
|
||||
for (List<StringName>::Element *E = types.front(); E; E = E->next()) {
|
||||
String n = E->get();
|
||||
if (n.begins_with("_")) {
|
||||
n = n.substr(1, n.length());
|
||||
}
|
||||
keywords[n] = types_color;
|
||||
}
|
||||
|
||||
/* User types. */
|
||||
const Color usertype_color = EDITOR_GET("text_editor/highlighting/user_type_color");
|
||||
List<StringName> global_classes;
|
||||
ScriptServer::get_global_class_list(&global_classes);
|
||||
for (List<StringName>::Element *E = global_classes.front(); E; E = E->next()) {
|
||||
keywords[String(E->get())] = usertype_color;
|
||||
}
|
||||
|
||||
/* Autoloads. */
|
||||
|
||||
List<PropertyInfo> props;
|
||||
ProjectSettings::get_singleton()->get_property_list(&props);
|
||||
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
|
||||
const PropertyInfo &pi = E->get();
|
||||
|
||||
if (!pi.name.begins_with("autoload/")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String name = pi.name.get_slice("/", 1);
|
||||
String path = ProjectSettings::get_singleton()->get(pi.name);
|
||||
|
||||
if (name.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
bool is_singleton = path.begins_with("*");
|
||||
|
||||
if (is_singleton) {
|
||||
keywords[name] = usertype_color;
|
||||
}
|
||||
}
|
||||
|
||||
const CScriptLanguage *cscript = CScriptLanguage::get_singleton();
|
||||
|
||||
/* Core types. */
|
||||
const Color basetype_color = EDITOR_GET("text_editor/highlighting/base_type_color");
|
||||
List<String> core_types;
|
||||
cscript->get_core_type_words(&core_types);
|
||||
for (List<String>::Element *E = core_types.front(); E; E = E->next()) {
|
||||
keywords[E->get()] = basetype_color;
|
||||
}
|
||||
|
||||
/* Reserved words. */
|
||||
const Color keyword_color = EDITOR_GET("text_editor/highlighting/keyword_color");
|
||||
const Color control_flow_keyword_color = EDITOR_GET("text_editor/highlighting/control_flow_keyword_color");
|
||||
List<String> keyword_list;
|
||||
cscript->get_reserved_words(&keyword_list);
|
||||
for (List<String>::Element *E = keyword_list.front(); E; E = E->next()) {
|
||||
if (cscript->is_control_flow_keyword(E->get())) {
|
||||
keywords[E->get()] = control_flow_keyword_color;
|
||||
} else {
|
||||
keywords[E->get()] = keyword_color;
|
||||
}
|
||||
}
|
||||
|
||||
/* Comments */
|
||||
const Color comment_color = EDITOR_GET("text_editor/highlighting/comment_color");
|
||||
List<String> comments;
|
||||
cscript->get_comment_delimiters(&comments);
|
||||
for (List<String>::Element *E = comments.front(); E; E = E->next()) {
|
||||
String comment = E->get();
|
||||
String beg = comment.get_slice(" ", 0);
|
||||
String end = comment.get_slice_count(" ") > 1 ? comment.get_slice(" ", 1) : String();
|
||||
add_color_region(beg, end, comment_color, end == "");
|
||||
}
|
||||
|
||||
/* Strings */
|
||||
const Color string_color = EDITOR_GET("text_editor/highlighting/string_color");
|
||||
List<String> strings;
|
||||
cscript->get_string_delimiters(&strings);
|
||||
for (List<String>::Element *E = strings.front(); E; E = E->next()) {
|
||||
String string = E->get();
|
||||
String beg = string.get_slice(" ", 0);
|
||||
String end = string.get_slice_count(" ") > 1 ? string.get_slice(" ", 1) : String();
|
||||
add_color_region(beg, end, string_color, end == "");
|
||||
}
|
||||
|
||||
const Ref<Script> script = _get_edited_resource();
|
||||
if (script.is_valid()) {
|
||||
/* Member types. */
|
||||
const Color member_variable_color = EDITOR_GET("text_editor/highlighting/member_variable_color");
|
||||
StringName instance_base = script->get_instance_base_type();
|
||||
if (instance_base != StringName()) {
|
||||
List<PropertyInfo> plist;
|
||||
ClassDB::get_property_list(instance_base, &plist);
|
||||
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
|
||||
String name = E->get().name;
|
||||
if (E->get().usage & PROPERTY_USAGE_CATEGORY || E->get().usage & PROPERTY_USAGE_GROUP) {
|
||||
continue;
|
||||
}
|
||||
if (name.find("/") != -1) {
|
||||
continue;
|
||||
}
|
||||
member_keywords[name] = member_variable_color;
|
||||
}
|
||||
|
||||
List<String> clist;
|
||||
ClassDB::get_integer_constant_list(instance_base, &clist);
|
||||
for (List<String>::Element *E = clist.front(); E; E = E->next()) {
|
||||
member_keywords[E->get()] = member_variable_color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const String text_edit_color_theme = EditorSettings::get_singleton()->get("text_editor/theme/color_theme");
|
||||
const bool default_theme = text_edit_color_theme == "Default";
|
||||
|
||||
if (default_theme || EditorSettings::get_singleton()->is_dark_theme()) {
|
||||
function_definition_color = Color(0.4, 0.9, 1.0);
|
||||
node_path_color = Color(0.39, 0.76, 0.35);
|
||||
} else {
|
||||
function_definition_color = Color(0.0, 0.65, 0.73);
|
||||
node_path_color = Color(0.32, 0.55, 0.29);
|
||||
}
|
||||
|
||||
EDITOR_DEF("text_editor/highlighting/cscript/function_definition_color", function_definition_color);
|
||||
EDITOR_DEF("text_editor/highlighting/cscript/node_path_color", node_path_color);
|
||||
if (text_edit_color_theme == "Adaptive" || default_theme) {
|
||||
EditorSettings::get_singleton()->set_initial_value(
|
||||
"text_editor/highlighting/cscript/function_definition_color",
|
||||
function_definition_color,
|
||||
true);
|
||||
EditorSettings::get_singleton()->set_initial_value(
|
||||
"text_editor/highlighting/cscript/node_path_color",
|
||||
node_path_color,
|
||||
true);
|
||||
}
|
||||
|
||||
function_definition_color = EDITOR_GET("text_editor/highlighting/cscript/function_definition_color");
|
||||
node_path_color = EDITOR_GET("text_editor/highlighting/cscript/node_path_color");
|
||||
type_color = EDITOR_GET("text_editor/highlighting/base_type_color");
|
||||
}
|
||||
|
||||
void CScriptSyntaxHighlighter::add_color_region(const String &p_start_key, const String &p_end_key, const Color &p_color, bool p_line_only) {
|
||||
for (int i = 0; i < p_start_key.length(); i++) {
|
||||
ERR_FAIL_COND_MSG(!is_symbol(p_start_key[i]), "color regions must start with a symbol");
|
||||
}
|
||||
|
||||
if (p_end_key.length() > 0) {
|
||||
for (int i = 0; i < p_end_key.length(); i++) {
|
||||
ERR_FAIL_COND_MSG(!is_symbol(p_end_key[i]), "color regions must end with a symbol");
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < color_regions.size(); i++) {
|
||||
ERR_FAIL_COND_MSG(color_regions[i].start_key == p_start_key, "color region with start key '" + p_start_key + "' already exists.");
|
||||
}
|
||||
|
||||
ColorRegion color_region;
|
||||
color_region.color = p_color;
|
||||
color_region.start_key = p_start_key;
|
||||
color_region.end_key = p_end_key;
|
||||
color_region.line_only = p_line_only;
|
||||
color_regions.push_back(color_region);
|
||||
}
|
||||
|
||||
Ref<EditorSyntaxHighlighter> CScriptSyntaxHighlighter::_create() const {
|
||||
Ref<CScriptSyntaxHighlighter> syntax_highlighter;
|
||||
syntax_highlighter.instance();
|
||||
return syntax_highlighter;
|
||||
}
|
@ -1,88 +0,0 @@
|
||||
#ifndef CSCRIPT_HIGHLIGHTER_H
|
||||
#define CSCRIPT_HIGHLIGHTER_H
|
||||
/*************************************************************************/
|
||||
/* gdscript_highlighter.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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 "editor_modules/editor_code_editor/editor_syntax_highlighter.h"
|
||||
#include "scene/gui/text_edit.h"
|
||||
|
||||
class CScriptSyntaxHighlighter : public EditorSyntaxHighlighter {
|
||||
GDCLASS(CScriptSyntaxHighlighter, EditorSyntaxHighlighter);
|
||||
|
||||
private:
|
||||
struct ColorRegion {
|
||||
Color color;
|
||||
String start_key;
|
||||
String end_key;
|
||||
bool line_only;
|
||||
};
|
||||
Vector<ColorRegion> color_regions;
|
||||
RBMap<int, int> color_region_cache;
|
||||
|
||||
Dictionary keywords;
|
||||
Dictionary member_keywords;
|
||||
|
||||
enum Type {
|
||||
NONE,
|
||||
REGION,
|
||||
NODE_PATH,
|
||||
SYMBOL,
|
||||
NUMBER,
|
||||
FUNCTION,
|
||||
KEYWORD,
|
||||
MEMBER,
|
||||
IDENTIFIER,
|
||||
TYPE,
|
||||
};
|
||||
|
||||
// colours
|
||||
Color font_color;
|
||||
Color symbol_color;
|
||||
Color function_color;
|
||||
Color function_definition_color;
|
||||
Color built_in_type_color;
|
||||
Color number_color;
|
||||
Color member_color;
|
||||
Color node_path_color;
|
||||
Color type_color;
|
||||
|
||||
void add_color_region(const String &p_start_key, const String &p_end_key, const Color &p_color, bool p_line_only = false);
|
||||
|
||||
public:
|
||||
virtual Ref<EditorSyntaxHighlighter> _create() const;
|
||||
|
||||
virtual void _update_cache();
|
||||
virtual Dictionary _get_line_syntax_highlighting(int p_line);
|
||||
|
||||
virtual String _get_name() const;
|
||||
virtual Array _get_supported_languages() const;
|
||||
};
|
||||
|
||||
#endif // CSCRIPT_HIGHLIGHTER_H
|
@ -1,65 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
width="16"
|
||||
height="16"
|
||||
version="1.1"
|
||||
viewBox="0 0 16 16"
|
||||
id="svg6"
|
||||
sodipodi:docname="icon_g_d_script.svg"
|
||||
inkscape:version="1.2 (dc2aedaf03, 2022-05-15)"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg">
|
||||
<defs
|
||||
id="defs10" />
|
||||
<sodipodi:namedview
|
||||
id="namedview8"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:showpageshadow="2"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#d1d1d1"
|
||||
showgrid="false"
|
||||
inkscape:zoom="38.404737"
|
||||
inkscape:cx="10.701805"
|
||||
inkscape:cy="7.2126519"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-height="1023"
|
||||
inkscape:window-x="3840"
|
||||
inkscape:window-y="0"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="svg6" />
|
||||
<g
|
||||
transform="translate(0 -1036.4)"
|
||||
id="g4">
|
||||
<path
|
||||
transform="translate(0 1036.4)"
|
||||
d="m7 1l-0.56445 2.2578a5 5 0 0 0 -0.68945 0.2793l-1.9883-1.1934-1.4141 1.4141 1.1953 1.9941a5 5 0 0 0 -0.28516 0.68555l-2.2539 0.5625v2l2.2578 0.56445a5 5 0 0 0 0.2793 0.6875l-1.1934 1.9902 1.4141 1.4141 1.9941-1.1953a5 5 0 0 0 0.68555 0.28516l0.5625 2.2539h2l0.56445-2.2578a5 5 0 0 0 0.6875 -0.2793l1.9902 1.1934 1.4141-1.4141-1.1953-1.9941a5 5 0 0 0 0.28516 -0.68555l2.2539-0.5625v-2l-2.2578-0.56445a5 5 0 0 0 -0.2793 -0.6875l1.1934-1.9902-1.4141-1.4141-1.9941 1.1953a5 5 0 0 0 -0.68555 -0.28516l-0.5625-2.2539h-2zm1 5a2 2 0 0 1 2 2 2 2 0 0 1 -2 2 2 2 0 0 1 -2 -2 2 2 0 0 1 2 -2z"
|
||||
fill="#e0e0e0"
|
||||
id="path2" />
|
||||
</g>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-style:normal;font-weight:normal;font-size:40px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none"
|
||||
x="9.4249582"
|
||||
y="10.451061"
|
||||
id="text293"><tspan
|
||||
sodipodi:role="line"
|
||||
id="tspan291"
|
||||
x="9.4249582"
|
||||
y="10.451061"></tspan></text>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-style:normal;font-weight:normal;font-size:10.6667px;line-height:1.25;font-family:sans-serif;mix-blend-mode:luminosity;fill:#e0e0e0;fill-opacity:1;stroke:#707070;stroke-width:0.4;stroke-dasharray:none;stroke-opacity:1"
|
||||
x="8.6932192"
|
||||
y="15.296833"
|
||||
id="text504-9"><tspan
|
||||
sodipodi:role="line"
|
||||
id="tspan502-2"
|
||||
x="8.6932192"
|
||||
y="15.296833"
|
||||
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:10.6667px;font-family:'Droid Arabic Kufi';-inkscape-font-specification:'Droid Arabic Kufi Bold';fill:#e0e0e0;fill-opacity:1;stroke:#707070;stroke-width:0.4;stroke-dasharray:none;stroke-opacity:1">C</tspan></text>
|
||||
</svg>
|
Before Width: | Height: | Size: 2.8 KiB |
@ -1,188 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* register_types.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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 "register_types.h"
|
||||
|
||||
#include "core/io/file_access_encrypted.h"
|
||||
#include "core/io/resource_loader.h"
|
||||
#include "core/os/dir_access.h"
|
||||
#include "core/os/file_access.h"
|
||||
#include "cscript.h"
|
||||
#include "cscript_tokenizer.h"
|
||||
|
||||
#include "modules/modules_enabled.gen.h"
|
||||
|
||||
CScriptLanguage *script_language_cscript = nullptr;
|
||||
Ref<ResourceFormatLoaderCScript> resource_loader_cscript;
|
||||
Ref<ResourceFormatSaverCScript> resource_saver_cscript;
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
||||
#include "editor/cscript_highlighter.h"
|
||||
#include "editor/editor_export.h"
|
||||
#include "editor/editor_node.h"
|
||||
#include "editor/editor_settings.h"
|
||||
|
||||
#ifdef MODULE_EDITOR_CODE_EDITOR_ENABLED
|
||||
#include "editor_code_editor/editor_script_editor.h"
|
||||
#endif
|
||||
|
||||
class EditorExportCScript : public EditorExportPlugin {
|
||||
GDCLASS(EditorExportCScript, EditorExportPlugin);
|
||||
|
||||
public:
|
||||
virtual void _export_file(const String &p_path, const String &p_type, const RBSet<String> &p_features) {
|
||||
int script_mode = EditorExportPreset::MODE_SCRIPT_COMPILED;
|
||||
String script_key;
|
||||
|
||||
const Ref<EditorExportPreset> &preset = get_export_preset();
|
||||
|
||||
if (preset.is_valid()) {
|
||||
script_mode = preset->get_script_export_mode();
|
||||
script_key = preset->get_script_encryption_key().to_lower();
|
||||
}
|
||||
|
||||
if (!p_path.ends_with(".cpps") || script_mode == EditorExportPreset::MODE_SCRIPT_TEXT) {
|
||||
return;
|
||||
}
|
||||
|
||||
Vector<uint8_t> file = FileAccess::get_file_as_array(p_path);
|
||||
if (file.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String txt;
|
||||
txt.parse_utf8((const char *)file.ptr(), file.size());
|
||||
file = CScriptTokenizerBuffer::parse_code_string(txt);
|
||||
|
||||
if (!file.empty()) {
|
||||
if (script_mode == EditorExportPreset::MODE_SCRIPT_ENCRYPTED) {
|
||||
String tmp_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("script.cppse");
|
||||
FileAccess *fa = FileAccess::open(tmp_path, FileAccess::WRITE);
|
||||
|
||||
Vector<uint8_t> key;
|
||||
key.resize(32);
|
||||
for (int i = 0; i < 32; i++) {
|
||||
int v = 0;
|
||||
if (i * 2 < script_key.length()) {
|
||||
CharType ct = script_key[i * 2];
|
||||
if (ct >= '0' && ct <= '9') {
|
||||
ct = ct - '0';
|
||||
} else if (ct >= 'a' && ct <= 'f') {
|
||||
ct = 10 + ct - 'a';
|
||||
}
|
||||
v |= ct << 4;
|
||||
}
|
||||
|
||||
if (i * 2 + 1 < script_key.length()) {
|
||||
CharType ct = script_key[i * 2 + 1];
|
||||
if (ct >= '0' && ct <= '9') {
|
||||
ct = ct - '0';
|
||||
} else if (ct >= 'a' && ct <= 'f') {
|
||||
ct = 10 + ct - 'a';
|
||||
}
|
||||
v |= ct;
|
||||
}
|
||||
key.write[i] = v;
|
||||
}
|
||||
FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
|
||||
Error err = fae->open_and_parse(fa, key, FileAccessEncrypted::MODE_WRITE_AES256);
|
||||
|
||||
if (err == OK) {
|
||||
fae->store_buffer(file.ptr(), file.size());
|
||||
}
|
||||
|
||||
memdelete(fae);
|
||||
|
||||
file = FileAccess::get_file_as_array(tmp_path);
|
||||
add_file(p_path.get_basename() + ".cppse", file, true);
|
||||
|
||||
// Clean up temporary file.
|
||||
DirAccess::remove_file_or_error(tmp_path);
|
||||
|
||||
} else {
|
||||
add_file(p_path.get_basename() + ".cppsc", file, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static void _editor_init() {
|
||||
Ref<EditorExportCScript> gd_export;
|
||||
gd_export.instance();
|
||||
EditorExport::get_singleton()->add_export_plugin(gd_export);
|
||||
|
||||
#ifdef MODULE_EDITOR_CODE_EDITOR_ENABLED
|
||||
Ref<CScriptSyntaxHighlighter> cscript_syntax_highlighter;
|
||||
cscript_syntax_highlighter.instance();
|
||||
EditorScriptEditor::get_singleton()->register_syntax_highlighter(cscript_syntax_highlighter);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // TOOLS_ENABLED
|
||||
|
||||
void register_cscript_types(ModuleRegistrationLevel p_level) {
|
||||
if (p_level == MODULE_REGISTRATION_LEVEL_CORE) {
|
||||
script_language_cscript = memnew(CScriptLanguage);
|
||||
ScriptServer::register_language(script_language_cscript);
|
||||
|
||||
resource_loader_cscript.instance();
|
||||
ResourceLoader::add_resource_format_loader(resource_loader_cscript);
|
||||
|
||||
resource_saver_cscript.instance();
|
||||
ResourceSaver::add_resource_format_saver(resource_saver_cscript);
|
||||
}
|
||||
|
||||
if (p_level == MODULE_REGISTRATION_LEVEL_SCENE) {
|
||||
ClassDB::register_class<CScript>();
|
||||
}
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
if (p_level == MODULE_REGISTRATION_LEVEL_EDITOR) {
|
||||
EditorNode::add_init_callback(_editor_init);
|
||||
}
|
||||
#endif // TOOLS_ENABLED
|
||||
}
|
||||
|
||||
void unregister_cscript_types(ModuleRegistrationLevel p_level) {
|
||||
if (p_level == MODULE_REGISTRATION_LEVEL_CORE) {
|
||||
ScriptServer::unregister_language(script_language_cscript);
|
||||
|
||||
if (script_language_cscript) {
|
||||
memdelete(script_language_cscript);
|
||||
}
|
||||
|
||||
ResourceLoader::remove_resource_format_loader(resource_loader_cscript);
|
||||
resource_loader_cscript.unref();
|
||||
|
||||
ResourceSaver::remove_resource_format_saver(resource_saver_cscript);
|
||||
resource_saver_cscript.unref();
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
#ifndef CSCRIPT_REGISTER_TYPES_H
|
||||
#define CSCRIPT_REGISTER_TYPES_H
|
||||
/*************************************************************************/
|
||||
/* register_types.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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 "modules/register_module_types.h"
|
||||
|
||||
void register_cscript_types(ModuleRegistrationLevel p_level);
|
||||
void unregister_cscript_types(ModuleRegistrationLevel p_level);
|
||||
|
||||
#endif // CSCRIPT_REGISTER_TYPES_H
|
@ -1,14 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
Import("env")
|
||||
Import("env_modules")
|
||||
|
||||
env_csg = env_modules.Clone()
|
||||
|
||||
# Godot source files
|
||||
|
||||
env_csg.add_source_files(env.modules_sources, "*.cpp")
|
||||
env_csg.add_source_files(env.modules_sources, "geometry_parser/*.cpp")
|
||||
|
||||
if env["tools"]:
|
||||
env_csg.add_source_files(env.modules_sources, "editor/*.cpp")
|
@ -1,24 +0,0 @@
|
||||
def can_build(env, platform):
|
||||
return True
|
||||
|
||||
|
||||
def configure(env):
|
||||
pass
|
||||
|
||||
|
||||
def get_doc_classes():
|
||||
return [
|
||||
"CSGBox",
|
||||
"CSGCombiner",
|
||||
"CSGCylinder",
|
||||
"CSGMesh",
|
||||
"CSGPolygon",
|
||||
"CSGPrimitive",
|
||||
"CSGShape",
|
||||
"CSGSphere",
|
||||
"CSGTorus",
|
||||
]
|
||||
|
||||
|
||||
def get_doc_path():
|
||||
return "doc_classes"
|
1478
modules/csg/csg.cpp
@ -1,196 +0,0 @@
|
||||
/**************************************************************************/
|
||||
/* csg.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* 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 CSG_H
|
||||
#define CSG_H
|
||||
|
||||
#include "core/containers/list.h"
|
||||
#include "core/containers/rb_map.h"
|
||||
#include "core/math/aabb.h"
|
||||
#include "core/math/plane.h"
|
||||
#include "core/math/transform.h"
|
||||
#include "core/math/vector2.h"
|
||||
#include "core/math/vector3.h"
|
||||
#include "core/containers/oa_hash_map.h"
|
||||
#include "core/containers/pool_vector.h"
|
||||
#include "core/object/reference.h"
|
||||
#include "core/containers/vector.h"
|
||||
#include "scene/resources/material/material.h"
|
||||
#include "scene/resources/mesh/mesh.h"
|
||||
|
||||
struct CSGBrush {
|
||||
struct Face {
|
||||
Vector3 vertices[3];
|
||||
Vector2 uvs[3];
|
||||
AABB aabb;
|
||||
bool smooth;
|
||||
bool invert;
|
||||
int material;
|
||||
};
|
||||
|
||||
Vector<Face> faces;
|
||||
Vector<Ref<Material>> materials;
|
||||
|
||||
inline void _regen_face_aabbs();
|
||||
|
||||
// Create a brush from faces.
|
||||
void build_from_faces(const PoolVector<Vector3> &p_vertices, const PoolVector<Vector2> &p_uvs, const PoolVector<bool> &p_smooth, const PoolVector<Ref<Material>> &p_materials, const PoolVector<bool> &p_invert_faces);
|
||||
void copy_from(const CSGBrush &p_brush, const Transform &p_xform);
|
||||
};
|
||||
|
||||
struct CSGBrushOperation {
|
||||
enum Operation {
|
||||
OPERATION_UNION,
|
||||
OPERATION_INTERSECTION,
|
||||
OPERATION_SUBTRACTION,
|
||||
};
|
||||
|
||||
void merge_brushes(Operation p_operation, const CSGBrush &p_brush_a, const CSGBrush &p_brush_b, CSGBrush &r_merged_brush, float p_vertex_snap);
|
||||
|
||||
struct MeshMerge {
|
||||
struct Face {
|
||||
bool from_b;
|
||||
bool inside;
|
||||
int points[3];
|
||||
Vector2 uvs[3];
|
||||
bool smooth;
|
||||
bool invert;
|
||||
int material_idx;
|
||||
};
|
||||
|
||||
struct FaceBVH {
|
||||
int face;
|
||||
int left;
|
||||
int right;
|
||||
int next;
|
||||
Vector3 center;
|
||||
AABB aabb;
|
||||
};
|
||||
|
||||
struct FaceBVHCmpX {
|
||||
_FORCE_INLINE_ bool operator()(const FaceBVH *p_left, const FaceBVH *p_right) const {
|
||||
return p_left->center.x < p_right->center.x;
|
||||
}
|
||||
};
|
||||
|
||||
struct FaceBVHCmpY {
|
||||
_FORCE_INLINE_ bool operator()(const FaceBVH *p_left, const FaceBVH *p_right) const {
|
||||
return p_left->center.y < p_right->center.y;
|
||||
}
|
||||
};
|
||||
struct FaceBVHCmpZ {
|
||||
_FORCE_INLINE_ bool operator()(const FaceBVH *p_left, const FaceBVH *p_right) const {
|
||||
return p_left->center.z < p_right->center.z;
|
||||
}
|
||||
};
|
||||
|
||||
struct VertexKey {
|
||||
int32_t x, y, z;
|
||||
_FORCE_INLINE_ bool operator<(const VertexKey &p_key) const {
|
||||
if (x == p_key.x) {
|
||||
if (y == p_key.y) {
|
||||
return z < p_key.z;
|
||||
} else {
|
||||
return y < p_key.y;
|
||||
}
|
||||
} else {
|
||||
return x < p_key.x;
|
||||
}
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ bool operator==(const VertexKey &p_key) const {
|
||||
return (x == p_key.x && y == p_key.y && z == p_key.z);
|
||||
}
|
||||
};
|
||||
|
||||
struct VertexKeyHash {
|
||||
static _FORCE_INLINE_ uint32_t hash(const VertexKey &p_vk) {
|
||||
uint32_t h = hash_djb2_one_32(p_vk.x);
|
||||
h = hash_djb2_one_32(p_vk.y, h);
|
||||
h = hash_djb2_one_32(p_vk.z, h);
|
||||
return h;
|
||||
}
|
||||
};
|
||||
|
||||
Vector<Vector3> points;
|
||||
Vector<Face> faces;
|
||||
RBMap<Ref<Material>, int> materials;
|
||||
RBMap<Vector3, int> vertex_map;
|
||||
OAHashMap<VertexKey, int, VertexKeyHash> snap_cache;
|
||||
float vertex_snap;
|
||||
|
||||
inline void _add_distance(List<real_t> &r_intersectionsA, List<real_t> &r_intersectionsB, bool p_from_B, real_t p_distance) const;
|
||||
inline bool _bvh_inside(FaceBVH *facebvhptr, int p_max_depth, int p_bvh_first, int p_face_idx) const;
|
||||
inline int _create_bvh(FaceBVH *facebvhptr, FaceBVH **facebvhptrptr, int p_from, int p_size, int p_depth, int &r_max_depth, int &r_max_alloc);
|
||||
|
||||
void add_face(const Vector3 p_points[3], const Vector2 p_uvs[3], bool p_smooth, bool p_invert, const Ref<Material> &p_material, bool p_from_b);
|
||||
void mark_inside_faces();
|
||||
};
|
||||
|
||||
struct Build2DFaces {
|
||||
struct Vertex2D {
|
||||
Vector2 point;
|
||||
Vector2 uv;
|
||||
};
|
||||
|
||||
struct Face2D {
|
||||
int vertex_idx[3];
|
||||
};
|
||||
|
||||
Vector<Vertex2D> vertices;
|
||||
Vector<Face2D> faces;
|
||||
Plane plane;
|
||||
Transform to_2D;
|
||||
Transform to_3D;
|
||||
float vertex_snap2;
|
||||
|
||||
inline int _get_point_idx(const Vector2 &p_point);
|
||||
inline int _add_vertex(const Vertex2D &p_vertex);
|
||||
inline void _add_vertex_idx_sorted(Vector<int> &r_vertex_indices, int p_new_vertex_index);
|
||||
inline void _merge_faces(const Vector<int> &p_segment_indices);
|
||||
inline void _find_edge_intersections(const Vector2 p_segment_points[2], Vector<int> &r_segment_indices);
|
||||
inline int _insert_point(const Vector2 &p_point);
|
||||
|
||||
void insert(const CSGBrush &p_brush, int p_brush_face);
|
||||
void addFacesToMesh(MeshMerge &r_mesh_merge, bool p_smooth, bool p_invert, const Ref<Material> &p_material, bool p_from_b);
|
||||
|
||||
Build2DFaces() {}
|
||||
Build2DFaces(const CSGBrush &p_brush, int p_brush_face, float p_vertex_snap2);
|
||||
};
|
||||
|
||||
struct Build2DFaceCollection {
|
||||
RBMap<int, Build2DFaces> build2DFacesA;
|
||||
RBMap<int, Build2DFaces> build2DFacesB;
|
||||
};
|
||||
|
||||
void update_faces(const CSGBrush &p_brush_a, const int p_face_idx_a, const CSGBrush &p_brush_b, const int p_face_idx_b, Build2DFaceCollection &p_collection, float p_vertex_snap);
|
||||
};
|
||||
|
||||
#endif // CSG_H
|
@ -1,456 +0,0 @@
|
||||
/**************************************************************************/
|
||||
/* csg_shape.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* 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 CSG_SHAPE_H
|
||||
#define CSG_SHAPE_H
|
||||
|
||||
#define CSGJS_HEADER_ONLY
|
||||
|
||||
#include "csg.h"
|
||||
#include "scene/3d/path.h"
|
||||
#include "scene/3d/visual_instance.h"
|
||||
#include "scene/resources/shapes/concave_polygon_shape.h"
|
||||
#include "thirdparty/misc/mikktspace.h"
|
||||
|
||||
class CSGShape : public GeometryInstance {
|
||||
GDCLASS(CSGShape, GeometryInstance);
|
||||
|
||||
public:
|
||||
enum Operation {
|
||||
OPERATION_UNION,
|
||||
OPERATION_INTERSECTION,
|
||||
OPERATION_SUBTRACTION,
|
||||
|
||||
};
|
||||
|
||||
private:
|
||||
Operation operation;
|
||||
CSGShape *parent_shape;
|
||||
|
||||
CSGBrush *brush;
|
||||
|
||||
AABB node_aabb;
|
||||
|
||||
bool dirty;
|
||||
bool last_visible = false;
|
||||
float snap;
|
||||
|
||||
bool use_collision;
|
||||
uint32_t collision_layer;
|
||||
uint32_t collision_mask;
|
||||
Ref<ConcavePolygonShape> root_collision_shape;
|
||||
RID root_collision_instance;
|
||||
|
||||
bool calculate_tangents;
|
||||
|
||||
Ref<ArrayMesh> root_mesh;
|
||||
|
||||
struct Vector3Hasher {
|
||||
_ALWAYS_INLINE_ uint32_t hash(const Vector3 &p_vec3) const {
|
||||
uint32_t h = hash_djb2_one_float(p_vec3.x);
|
||||
h = hash_djb2_one_float(p_vec3.y, h);
|
||||
h = hash_djb2_one_float(p_vec3.z, h);
|
||||
return h;
|
||||
}
|
||||
};
|
||||
|
||||
struct ShapeUpdateSurface {
|
||||
PoolVector<Vector3> vertices;
|
||||
PoolVector<Vector3> normals;
|
||||
PoolVector<Vector2> uvs;
|
||||
PoolVector<float> tans;
|
||||
Ref<Material> material;
|
||||
int last_added;
|
||||
|
||||
PoolVector<Vector3>::Write verticesw;
|
||||
PoolVector<Vector3>::Write normalsw;
|
||||
PoolVector<Vector2>::Write uvsw;
|
||||
PoolVector<float>::Write tansw;
|
||||
};
|
||||
|
||||
//mikktspace callbacks
|
||||
static int mikktGetNumFaces(const SMikkTSpaceContext *pContext);
|
||||
static int mikktGetNumVerticesOfFace(const SMikkTSpaceContext *pContext, const int iFace);
|
||||
static void mikktGetPosition(const SMikkTSpaceContext *pContext, float fvPosOut[], const int iFace, const int iVert);
|
||||
static void mikktGetNormal(const SMikkTSpaceContext *pContext, float fvNormOut[], const int iFace, const int iVert);
|
||||
static void mikktGetTexCoord(const SMikkTSpaceContext *pContext, float fvTexcOut[], const int iFace, const int iVert);
|
||||
static void mikktSetTSpaceDefault(const SMikkTSpaceContext *pContext, const float fvTangent[], const float fvBiTangent[], const float fMagS, const float fMagT,
|
||||
const tbool bIsOrientationPreserving, const int iFace, const int iVert);
|
||||
|
||||
void _update_shape();
|
||||
void _update_collision_faces();
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
virtual CSGBrush *_build_brush() = 0;
|
||||
void _make_dirty(bool p_parent_removing = false);
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
friend class CSGCombiner;
|
||||
CSGBrush *_get_brush();
|
||||
|
||||
virtual void _validate_property(PropertyInfo &property) const;
|
||||
|
||||
public:
|
||||
Array get_meshes() const;
|
||||
|
||||
void force_update_shape();
|
||||
|
||||
void set_operation(Operation p_operation);
|
||||
Operation get_operation() const;
|
||||
|
||||
virtual PoolVector<Vector3> get_brush_faces();
|
||||
|
||||
virtual AABB get_aabb() const;
|
||||
virtual PoolVector<Face3> get_faces(uint32_t p_usage_flags) const;
|
||||
|
||||
void set_use_collision(bool p_enable);
|
||||
bool is_using_collision() const;
|
||||
|
||||
void set_collision_layer(uint32_t p_layer);
|
||||
uint32_t get_collision_layer() const;
|
||||
|
||||
void set_collision_mask(uint32_t p_mask);
|
||||
uint32_t get_collision_mask() const;
|
||||
|
||||
void set_collision_layer_bit(int p_bit, bool p_value);
|
||||
bool get_collision_layer_bit(int p_bit) const;
|
||||
|
||||
void set_collision_mask_bit(int p_bit, bool p_value);
|
||||
bool get_collision_mask_bit(int p_bit) const;
|
||||
|
||||
void set_snap(float p_snap);
|
||||
float get_snap() const;
|
||||
|
||||
void set_calculate_tangents(bool p_calculate_tangents);
|
||||
bool is_calculating_tangents() const;
|
||||
|
||||
bool is_root_shape() const;
|
||||
CSGShape();
|
||||
~CSGShape();
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(CSGShape::Operation)
|
||||
|
||||
class CSGCombiner : public CSGShape {
|
||||
GDCLASS(CSGCombiner, CSGShape);
|
||||
|
||||
private:
|
||||
virtual CSGBrush *_build_brush();
|
||||
|
||||
public:
|
||||
CSGCombiner();
|
||||
};
|
||||
|
||||
class CSGPrimitive : public CSGShape {
|
||||
GDCLASS(CSGPrimitive, CSGShape);
|
||||
|
||||
protected:
|
||||
bool invert_faces;
|
||||
CSGBrush *_create_brush_from_arrays(const PoolVector<Vector3> &p_vertices, const PoolVector<Vector2> &p_uv, const PoolVector<bool> &p_smooth, const PoolVector<Ref<Material>> &p_materials);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void set_invert_faces(bool p_invert);
|
||||
bool is_inverting_faces();
|
||||
|
||||
CSGPrimitive();
|
||||
};
|
||||
|
||||
class CSGMesh : public CSGPrimitive {
|
||||
GDCLASS(CSGMesh, CSGPrimitive);
|
||||
|
||||
virtual CSGBrush *_build_brush();
|
||||
|
||||
Ref<Mesh> mesh;
|
||||
Ref<Material> material;
|
||||
|
||||
void _mesh_changed();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void set_mesh(const Ref<Mesh> &p_mesh);
|
||||
Ref<Mesh> get_mesh();
|
||||
|
||||
void set_material(const Ref<Material> &p_material);
|
||||
Ref<Material> get_material() const;
|
||||
};
|
||||
|
||||
class CSGSphere : public CSGPrimitive {
|
||||
GDCLASS(CSGSphere, CSGPrimitive);
|
||||
virtual CSGBrush *_build_brush();
|
||||
|
||||
Ref<Material> material;
|
||||
bool smooth_faces;
|
||||
float radius;
|
||||
int radial_segments;
|
||||
int rings;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void set_radius(const float p_radius);
|
||||
float get_radius() const;
|
||||
|
||||
void set_radial_segments(const int p_radial_segments);
|
||||
int get_radial_segments() const;
|
||||
|
||||
void set_rings(const int p_rings);
|
||||
int get_rings() const;
|
||||
|
||||
void set_material(const Ref<Material> &p_material);
|
||||
Ref<Material> get_material() const;
|
||||
|
||||
void set_smooth_faces(bool p_smooth_faces);
|
||||
bool get_smooth_faces() const;
|
||||
|
||||
CSGSphere();
|
||||
};
|
||||
|
||||
class CSGBox : public CSGPrimitive {
|
||||
GDCLASS(CSGBox, CSGPrimitive);
|
||||
virtual CSGBrush *_build_brush();
|
||||
|
||||
Ref<Material> material;
|
||||
float width;
|
||||
float height;
|
||||
float depth;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void set_width(const float p_width);
|
||||
float get_width() const;
|
||||
|
||||
void set_height(const float p_height);
|
||||
float get_height() const;
|
||||
|
||||
void set_depth(const float p_depth);
|
||||
float get_depth() const;
|
||||
|
||||
void set_material(const Ref<Material> &p_material);
|
||||
Ref<Material> get_material() const;
|
||||
|
||||
CSGBox();
|
||||
};
|
||||
|
||||
class CSGCylinder : public CSGPrimitive {
|
||||
GDCLASS(CSGCylinder, CSGPrimitive);
|
||||
virtual CSGBrush *_build_brush();
|
||||
|
||||
Ref<Material> material;
|
||||
float radius;
|
||||
float height;
|
||||
int sides;
|
||||
bool cone;
|
||||
bool smooth_faces;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void set_radius(const float p_radius);
|
||||
float get_radius() const;
|
||||
|
||||
void set_height(const float p_height);
|
||||
float get_height() const;
|
||||
|
||||
void set_sides(const int p_sides);
|
||||
int get_sides() const;
|
||||
|
||||
void set_cone(const bool p_cone);
|
||||
bool is_cone() const;
|
||||
|
||||
void set_smooth_faces(bool p_smooth_faces);
|
||||
bool get_smooth_faces() const;
|
||||
|
||||
void set_material(const Ref<Material> &p_material);
|
||||
Ref<Material> get_material() const;
|
||||
|
||||
CSGCylinder();
|
||||
};
|
||||
|
||||
class CSGTorus : public CSGPrimitive {
|
||||
GDCLASS(CSGTorus, CSGPrimitive);
|
||||
virtual CSGBrush *_build_brush();
|
||||
|
||||
Ref<Material> material;
|
||||
float inner_radius;
|
||||
float outer_radius;
|
||||
int sides;
|
||||
int ring_sides;
|
||||
bool smooth_faces;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void set_inner_radius(const float p_inner_radius);
|
||||
float get_inner_radius() const;
|
||||
|
||||
void set_outer_radius(const float p_outer_radius);
|
||||
float get_outer_radius() const;
|
||||
|
||||
void set_sides(const int p_sides);
|
||||
int get_sides() const;
|
||||
|
||||
void set_ring_sides(const int p_ring_sides);
|
||||
int get_ring_sides() const;
|
||||
|
||||
void set_smooth_faces(bool p_smooth_faces);
|
||||
bool get_smooth_faces() const;
|
||||
|
||||
void set_material(const Ref<Material> &p_material);
|
||||
Ref<Material> get_material() const;
|
||||
|
||||
CSGTorus();
|
||||
};
|
||||
|
||||
class CSGPolygon : public CSGPrimitive {
|
||||
GDCLASS(CSGPolygon, CSGPrimitive);
|
||||
|
||||
public:
|
||||
enum Mode {
|
||||
MODE_DEPTH,
|
||||
MODE_SPIN,
|
||||
MODE_PATH
|
||||
};
|
||||
|
||||
enum PathIntervalType {
|
||||
PATH_INTERVAL_DISTANCE,
|
||||
PATH_INTERVAL_SUBDIVIDE
|
||||
};
|
||||
|
||||
enum PathRotation {
|
||||
PATH_ROTATION_POLYGON,
|
||||
PATH_ROTATION_PATH,
|
||||
PATH_ROTATION_PATH_FOLLOW,
|
||||
};
|
||||
|
||||
private:
|
||||
virtual CSGBrush *_build_brush();
|
||||
|
||||
Vector<Vector2> polygon;
|
||||
Ref<Material> material;
|
||||
|
||||
Mode mode;
|
||||
|
||||
float depth;
|
||||
|
||||
float spin_degrees;
|
||||
int spin_sides;
|
||||
|
||||
NodePath path_node;
|
||||
PathIntervalType path_interval_type;
|
||||
float path_interval;
|
||||
float path_simplify_angle;
|
||||
PathRotation path_rotation;
|
||||
bool path_local;
|
||||
|
||||
Path *path;
|
||||
|
||||
bool smooth_faces;
|
||||
bool path_continuous_u;
|
||||
real_t path_u_distance;
|
||||
bool path_joined;
|
||||
|
||||
bool _is_editable_3d_polygon() const;
|
||||
bool _has_editable_3d_polygon_no_depth() const;
|
||||
|
||||
void _path_changed();
|
||||
void _path_exited();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
virtual void _validate_property(PropertyInfo &property) const;
|
||||
void _notification(int p_what);
|
||||
|
||||
public:
|
||||
void set_polygon(const Vector<Vector2> &p_polygon);
|
||||
Vector<Vector2> get_polygon() const;
|
||||
|
||||
void set_mode(Mode p_mode);
|
||||
Mode get_mode() const;
|
||||
|
||||
void set_depth(float p_depth);
|
||||
float get_depth() const;
|
||||
|
||||
void set_spin_degrees(float p_spin_degrees);
|
||||
float get_spin_degrees() const;
|
||||
|
||||
void set_spin_sides(int p_spin_sides);
|
||||
int get_spin_sides() const;
|
||||
|
||||
void set_path_node(const NodePath &p_path);
|
||||
NodePath get_path_node() const;
|
||||
|
||||
void set_path_interval_type(PathIntervalType p_interval_type);
|
||||
PathIntervalType get_path_interval_type() const;
|
||||
|
||||
void set_path_interval(float p_interval);
|
||||
float get_path_interval() const;
|
||||
|
||||
void set_path_simplify_angle(float p_angle);
|
||||
float get_path_simplify_angle() const;
|
||||
|
||||
void set_path_rotation(PathRotation p_rotation);
|
||||
PathRotation get_path_rotation() const;
|
||||
|
||||
void set_path_local(bool p_enable);
|
||||
bool is_path_local() const;
|
||||
|
||||
void set_path_continuous_u(bool p_enable);
|
||||
bool is_path_continuous_u() const;
|
||||
|
||||
void set_path_u_distance(real_t p_path_u_distance);
|
||||
real_t get_path_u_distance() const;
|
||||
|
||||
void set_path_joined(bool p_enable);
|
||||
bool is_path_joined() const;
|
||||
|
||||
void set_smooth_faces(bool p_smooth_faces);
|
||||
bool get_smooth_faces() const;
|
||||
|
||||
void set_material(const Ref<Material> &p_material);
|
||||
Ref<Material> get_material() const;
|
||||
|
||||
CSGPolygon();
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(CSGPolygon::Mode)
|
||||
VARIANT_ENUM_CAST(CSGPolygon::PathRotation)
|
||||
VARIANT_ENUM_CAST(CSGPolygon::PathIntervalType)
|
||||
|
||||
#endif // CSG_SHAPE_H
|
@ -1,31 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="CSGBox" inherits="CSGPrimitive" version="4.2">
|
||||
<brief_description>
|
||||
A CSG Box shape.
|
||||
</brief_description>
|
||||
<description>
|
||||
This node allows you to create a box for use with the CSG system.
|
||||
[b]Note:[/b] CSG nodes are intended to be used for level prototyping. Creating CSG nodes has a significant CPU cost compared to creating a [MeshInstance] with a [PrimitiveMesh]. Moving a CSG node within another CSG node also has a significant CPU cost, so it should be avoided during gameplay.
|
||||
</description>
|
||||
<tutorials>
|
||||
<link title="Prototyping levels with CSG">$DOCS_URL/tutorials/3d/csg_tools.md</link>
|
||||
</tutorials>
|
||||
<methods>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="depth" type="float" setter="set_depth" getter="get_depth" default="2.0">
|
||||
Depth of the box measured from the center of the box.
|
||||
</member>
|
||||
<member name="height" type="float" setter="set_height" getter="get_height" default="2.0">
|
||||
Height of the box measured from the center of the box.
|
||||
</member>
|
||||
<member name="material" type="Material" setter="set_material" getter="get_material">
|
||||
The material used to render the box.
|
||||
</member>
|
||||
<member name="width" type="float" setter="set_width" getter="get_width" default="2.0">
|
||||
Width of the box measured from the center of the box.
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="CSGCombiner" inherits="CSGShape" version="4.2">
|
||||
<brief_description>
|
||||
A CSG node that allows you to combine other CSG modifiers.
|
||||
</brief_description>
|
||||
<description>
|
||||
For complex arrangements of shapes, it is sometimes needed to add structure to your CSG nodes. The CSGCombiner node allows you to create this structure. The node encapsulates the result of the CSG operations of its children. In this way, it is possible to do operations on one set of shapes that are children of one CSGCombiner node, and a set of separate operations on a second set of shapes that are children of a second CSGCombiner node, and then do an operation that takes the two end results as its input to create the final shape.
|
||||
[b]Note:[/b] CSG nodes are intended to be used for level prototyping. Creating CSG nodes has a significant CPU cost compared to creating a [MeshInstance] with a [PrimitiveMesh]. Moving a CSG node within another CSG node also has a significant CPU cost, so it should be avoided during gameplay.
|
||||
</description>
|
||||
<tutorials>
|
||||
<link title="Prototyping levels with CSG">$DOCS_URL/tutorials/3d/csg_tools.md</link>
|
||||
</tutorials>
|
||||
<methods>
|
||||
</methods>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,37 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="CSGCylinder" inherits="CSGPrimitive" version="4.2">
|
||||
<brief_description>
|
||||
A CSG Cylinder shape.
|
||||
</brief_description>
|
||||
<description>
|
||||
This node allows you to create a cylinder (or cone) for use with the CSG system.
|
||||
[b]Note:[/b] CSG nodes are intended to be used for level prototyping. Creating CSG nodes has a significant CPU cost compared to creating a [MeshInstance] with a [PrimitiveMesh]. Moving a CSG node within another CSG node also has a significant CPU cost, so it should be avoided during gameplay.
|
||||
</description>
|
||||
<tutorials>
|
||||
<link title="Prototyping levels with CSG">$DOCS_URL/tutorials/3d/csg_tools.md</link>
|
||||
</tutorials>
|
||||
<methods>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="cone" type="bool" setter="set_cone" getter="is_cone" default="false">
|
||||
If [code]true[/code] a cone is created, the [member radius] will only apply to one side.
|
||||
</member>
|
||||
<member name="height" type="float" setter="set_height" getter="get_height" default="1.0">
|
||||
The height of the cylinder.
|
||||
</member>
|
||||
<member name="material" type="Material" setter="set_material" getter="get_material">
|
||||
The material used to render the cylinder.
|
||||
</member>
|
||||
<member name="radius" type="float" setter="set_radius" getter="get_radius" default="1.0">
|
||||
The radius of the cylinder.
|
||||
</member>
|
||||
<member name="sides" type="int" setter="set_sides" getter="get_sides" default="8">
|
||||
The number of sides of the cylinder, the higher this number the more detail there will be in the cylinder.
|
||||
</member>
|
||||
<member name="smooth_faces" type="bool" setter="set_smooth_faces" getter="get_smooth_faces" default="true">
|
||||
If [code]true[/code] the normals of the cylinder are set to give a smooth effect making the cylinder seem rounded. If [code]false[/code] the cylinder will have a flat shaded look.
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,26 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="CSGMesh" inherits="CSGPrimitive" version="4.2">
|
||||
<brief_description>
|
||||
A CSG Mesh shape that uses a mesh resource.
|
||||
</brief_description>
|
||||
<description>
|
||||
This CSG node allows you to use any mesh resource as a CSG shape, provided it is closed, does not self-intersect, does not contain internal faces and has no edges that connect to more than two faces. See also [CSGPolygon] for drawing 2D extruded polygons to be used as CSG nodes.
|
||||
[b]Note:[/b] CSG nodes are intended to be used for level prototyping. Creating CSG nodes has a significant CPU cost compared to creating a [MeshInstance] with a [PrimitiveMesh]. Moving a CSG node within another CSG node also has a significant CPU cost, so it should be avoided during gameplay.
|
||||
</description>
|
||||
<tutorials>
|
||||
<link title="Prototyping levels with CSG">$DOCS_URL/tutorials/3d/csg_tools.md</link>
|
||||
</tutorials>
|
||||
<methods>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="material" type="Material" setter="set_material" getter="get_material">
|
||||
The [Material] used in drawing the CSG shape.
|
||||
</member>
|
||||
<member name="mesh" type="Mesh" setter="set_mesh" getter="get_mesh">
|
||||
The [Mesh] resource to use as a CSG shape.
|
||||
[b]Note:[/b] When using an [ArrayMesh], avoid meshes with vertex normals unless a flat shader is required. By default, CSGMesh will ignore the mesh's vertex normals and use a smooth shader calculated using the faces' normals. If a flat shader is required, ensure that all faces' vertex normals are parallel.
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,94 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="CSGPolygon" inherits="CSGPrimitive" version="4.2">
|
||||
<brief_description>
|
||||
Extrudes a 2D polygon shape to create a 3D mesh.
|
||||
</brief_description>
|
||||
<description>
|
||||
An array of 2D points is extruded to quickly and easily create a variety of 3D meshes. See also [CSGMesh] for using 3D meshes as CSG nodes.
|
||||
[b]Note:[/b] CSG nodes are intended to be used for level prototyping. Creating CSG nodes has a significant CPU cost compared to creating a [MeshInstance] with a [PrimitiveMesh]. Moving a CSG node within another CSG node also has a significant CPU cost, so it should be avoided during gameplay.
|
||||
</description>
|
||||
<tutorials>
|
||||
<link title="Prototyping levels with CSG">$DOCS_URL/tutorials/3d/csg_tools.md</link>
|
||||
</tutorials>
|
||||
<methods>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="depth" type="float" setter="set_depth" getter="get_depth" default="1.0">
|
||||
When [member mode] is [constant MODE_DEPTH], the depth of the extrusion.
|
||||
</member>
|
||||
<member name="material" type="Material" setter="set_material" getter="get_material">
|
||||
Material to use for the resulting mesh. The UV maps the top half of the material to the extruded shape (U along the the length of the extrusions and V around the outline of the [member polygon]), the bottom-left quarter to the front end face, and the bottom-right quarter to the back end face.
|
||||
</member>
|
||||
<member name="mode" type="int" setter="set_mode" getter="get_mode" enum="CSGPolygon.Mode" default="0">
|
||||
The [member mode] used to extrude the [member polygon].
|
||||
</member>
|
||||
<member name="path_continuous_u" type="bool" setter="set_path_continuous_u" getter="is_path_continuous_u">
|
||||
When [member mode] is [constant MODE_PATH], by default, the top half of the [member material] is stretched along the entire length of the extruded shape. If [code]false[/code] the top half of the material is repeated every step of the extrusion.
|
||||
</member>
|
||||
<member name="path_interval" type="float" setter="set_path_interval" getter="get_path_interval">
|
||||
When [member mode] is [constant MODE_PATH], the path interval or ratio of path points to extrusions.
|
||||
</member>
|
||||
<member name="path_interval_type" type="int" setter="set_path_interval_type" getter="get_path_interval_type" enum="CSGPolygon.PathIntervalType">
|
||||
When [member mode] is [constant MODE_PATH], this will determine if the interval should be by distance ([constant PATH_INTERVAL_DISTANCE]) or subdivision fractions ([constant PATH_INTERVAL_SUBDIVIDE]).
|
||||
</member>
|
||||
<member name="path_joined" type="bool" setter="set_path_joined" getter="is_path_joined">
|
||||
When [member mode] is [constant MODE_PATH], if [code]true[/code] the ends of the path are joined, by adding an extrusion between the last and first points of the path.
|
||||
</member>
|
||||
<member name="path_local" type="bool" setter="set_path_local" getter="is_path_local">
|
||||
When [member mode] is [constant MODE_PATH], if [code]true[/code] the [Transform] of the [CSGPolygon] is used as the starting point for the extrusions, not the [Transform] of the [member path_node].
|
||||
</member>
|
||||
<member name="path_node" type="NodePath" setter="set_path_node" getter="get_path_node">
|
||||
When [member mode] is [constant MODE_PATH], the location of the [Path] object used to extrude the [member polygon].
|
||||
</member>
|
||||
<member name="path_rotation" type="int" setter="set_path_rotation" getter="get_path_rotation" enum="CSGPolygon.PathRotation">
|
||||
When [member mode] is [constant MODE_PATH], the [enum PathRotation] method used to rotate the [member polygon] as it is extruded.
|
||||
</member>
|
||||
<member name="path_simplify_angle" type="float" setter="set_path_simplify_angle" getter="get_path_simplify_angle">
|
||||
When [member mode] is [constant MODE_PATH], extrusions that are less than this angle, will be merged together to reduce polygon count.
|
||||
</member>
|
||||
<member name="path_u_distance" type="float" setter="set_path_u_distance" getter="get_path_u_distance">
|
||||
When [member mode] is [constant MODE_PATH], this is the distance along the path, in meters, the texture coordinates will tile. When set to 0, texture coordinates will match geometry exactly with no tiling.
|
||||
</member>
|
||||
<member name="polygon" type="PoolVector2Array" setter="set_polygon" getter="get_polygon" default="PoolVector2Array( 0, 0, 0, 1, 1, 1, 1, 0 )">
|
||||
The point array that defines the 2D polygon that is extruded. This can be a convex or concave polygon with 3 or more points. The polygon must [i]not[/i] have any intersecting edges. Otherwise, triangulation will fail and no mesh will be generated.
|
||||
[b]Note:[/b] If only 1 or 2 points are defined in [member polygon], no mesh will be generated.
|
||||
</member>
|
||||
<member name="smooth_faces" type="bool" setter="set_smooth_faces" getter="get_smooth_faces" default="false">
|
||||
If [code]true[/code], applies smooth shading to the extrusions.
|
||||
</member>
|
||||
<member name="spin_degrees" type="float" setter="set_spin_degrees" getter="get_spin_degrees">
|
||||
When [member mode] is [constant MODE_SPIN], the total number of degrees the [member polygon] is rotated when extruding.
|
||||
</member>
|
||||
<member name="spin_sides" type="int" setter="set_spin_sides" getter="get_spin_sides">
|
||||
When [member mode] is [constant MODE_SPIN], the number of extrusions made.
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
<constant name="MODE_DEPTH" value="0" enum="Mode">
|
||||
The [member polygon] shape is extruded along the negative Z axis.
|
||||
</constant>
|
||||
<constant name="MODE_SPIN" value="1" enum="Mode">
|
||||
The [member polygon] shape is extruded by rotating it around the Y axis.
|
||||
</constant>
|
||||
<constant name="MODE_PATH" value="2" enum="Mode">
|
||||
The [member polygon] shape is extruded along the [Path] specified in [member path_node].
|
||||
</constant>
|
||||
<constant name="PATH_ROTATION_POLYGON" value="0" enum="PathRotation">
|
||||
The [member polygon] shape is not rotated.
|
||||
[b]Note:[/b] Requires the path's Z coordinates to continually decrease to ensure viable shapes.
|
||||
</constant>
|
||||
<constant name="PATH_ROTATION_PATH" value="1" enum="PathRotation">
|
||||
The [member polygon] shape is rotated along the path, but it is not rotated around the path axis.
|
||||
[b]Note:[/b] Requires the path's Z coordinates to continually decrease to ensure viable shapes.
|
||||
</constant>
|
||||
<constant name="PATH_ROTATION_PATH_FOLLOW" value="2" enum="PathRotation">
|
||||
The [member polygon] shape follows the path and its rotations around the path axis.
|
||||
</constant>
|
||||
<constant name="PATH_INTERVAL_DISTANCE" value="0" enum="PathIntervalType">
|
||||
When [member mode] is set to [constant MODE_PATH], [member path_interval] will determine the distance, in meters, each interval of the path will extrude.
|
||||
</constant>
|
||||
<constant name="PATH_INTERVAL_SUBDIVIDE" value="1" enum="PathIntervalType">
|
||||
When [member mode] is set to [constant MODE_PATH], [member path_interval] will subdivide the polygons along the path.
|
||||
</constant>
|
||||
</constants>
|
||||
</class>
|
@ -1,22 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="CSGPrimitive" inherits="CSGShape" version="4.2">
|
||||
<brief_description>
|
||||
Base class for CSG primitives.
|
||||
</brief_description>
|
||||
<description>
|
||||
Parent class for various CSG primitives. It contains code and functionality that is common between them. It cannot be used directly. Instead use one of the various classes that inherit from it.
|
||||
[b]Note:[/b] CSG nodes are intended to be used for level prototyping. Creating CSG nodes has a significant CPU cost compared to creating a [MeshInstance] with a [PrimitiveMesh]. Moving a CSG node within another CSG node also has a significant CPU cost, so it should be avoided during gameplay.
|
||||
</description>
|
||||
<tutorials>
|
||||
<link title="Prototyping levels with CSG">$DOCS_URL/tutorials/3d/csg_tools.md</link>
|
||||
</tutorials>
|
||||
<methods>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="invert_faces" type="bool" setter="set_invert_faces" getter="is_inverting_faces" default="false">
|
||||
Invert the faces of the mesh.
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,90 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="CSGShape" inherits="GeometryInstance" version="4.2">
|
||||
<brief_description>
|
||||
The CSG base class.
|
||||
</brief_description>
|
||||
<description>
|
||||
This is the CSG base class that provides CSG operation support to the various CSG nodes in Godot.
|
||||
[b]Note:[/b] CSG nodes are intended to be used for level prototyping. Creating CSG nodes has a significant CPU cost compared to creating a [MeshInstance] with a [PrimitiveMesh]. Moving a CSG node within another CSG node also has a significant CPU cost, so it should be avoided during gameplay.
|
||||
</description>
|
||||
<tutorials>
|
||||
<link title="Prototyping levels with CSG">$DOCS_URL/tutorials/3d/csg_tools.md</link>
|
||||
</tutorials>
|
||||
<methods>
|
||||
<method name="get_collision_layer_bit" qualifiers="const">
|
||||
<return type="bool" />
|
||||
<argument index="0" name="bit" type="int" />
|
||||
<description>
|
||||
Returns an individual bit on the collision mask.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_collision_mask_bit" qualifiers="const">
|
||||
<return type="bool" />
|
||||
<argument index="0" name="bit" type="int" />
|
||||
<description>
|
||||
Returns an individual bit on the collision mask.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_meshes" qualifiers="const">
|
||||
<return type="Array" />
|
||||
<description>
|
||||
Returns an [Array] with two elements, the first is the [Transform] of this node and the second is the root [Mesh] of this node. Only works when this node is the root shape.
|
||||
</description>
|
||||
</method>
|
||||
<method name="is_root_shape" qualifiers="const">
|
||||
<return type="bool" />
|
||||
<description>
|
||||
Returns [code]true[/code] if this is a root shape and is thus the object that is rendered.
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_collision_layer_bit">
|
||||
<return type="void" />
|
||||
<argument index="0" name="bit" type="int" />
|
||||
<argument index="1" name="value" type="bool" />
|
||||
<description>
|
||||
Sets individual bits on the layer mask. Use this if you only need to change one layer's value.
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_collision_mask_bit">
|
||||
<return type="void" />
|
||||
<argument index="0" name="bit" type="int" />
|
||||
<argument index="1" name="value" type="bool" />
|
||||
<description>
|
||||
Sets individual bits on the collision mask. Use this if you only need to change one layer's value.
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="calculate_tangents" type="bool" setter="set_calculate_tangents" getter="is_calculating_tangents" default="true">
|
||||
Calculate tangents for the CSG shape which allows the use of normal maps. This is only applied on the root shape, this setting is ignored on any child.
|
||||
</member>
|
||||
<member name="collision_layer" type="int" setter="set_collision_layer" getter="get_collision_layer" default="1">
|
||||
The physics layers this area is in.
|
||||
Collidable objects can exist in any of 32 different layers. These layers work like a tagging system, and are not visual. A collidable can use these layers to select with which objects it can collide, using the collision_mask property.
|
||||
A contact is detected if object A is in any of the layers that object B scans, or object B is in any layer scanned by object A. See [url=$DOCS_URL/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information.
|
||||
</member>
|
||||
<member name="collision_mask" type="int" setter="set_collision_mask" getter="get_collision_mask" default="1">
|
||||
The physics layers this CSG shape scans for collisions. See [url=$DOCS_URL/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information.
|
||||
</member>
|
||||
<member name="operation" type="int" setter="set_operation" getter="get_operation" enum="CSGShape.Operation" default="0">
|
||||
The operation that is performed on this shape. This is ignored for the first CSG child node as the operation is between this node and the previous child of this nodes parent.
|
||||
</member>
|
||||
<member name="snap" type="float" setter="set_snap" getter="get_snap" default="0.001">
|
||||
Snap makes the mesh snap to a given distance so that the faces of two meshes can be perfectly aligned. A lower value results in greater precision but may be harder to adjust.
|
||||
</member>
|
||||
<member name="use_collision" type="bool" setter="set_use_collision" getter="is_using_collision" default="false">
|
||||
Adds a collision shape to the physics engine for our CSG shape. This will always act like a static body. Note that the collision shape is still active even if the CSG shape itself is hidden.
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
<constant name="OPERATION_UNION" value="0" enum="Operation">
|
||||
Geometry of both primitives is merged, intersecting geometry is removed.
|
||||
</constant>
|
||||
<constant name="OPERATION_INTERSECTION" value="1" enum="Operation">
|
||||
Only intersecting geometry remains, the rest is removed.
|
||||
</constant>
|
||||
<constant name="OPERATION_SUBTRACTION" value="2" enum="Operation">
|
||||
The second shape is subtracted from the first, leaving a dent with its shape.
|
||||
</constant>
|
||||
</constants>
|
||||
</class>
|
@ -1,34 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="CSGSphere" inherits="CSGPrimitive" version="4.2">
|
||||
<brief_description>
|
||||
A CSG Sphere shape.
|
||||
</brief_description>
|
||||
<description>
|
||||
This node allows you to create a sphere for use with the CSG system.
|
||||
[b]Note:[/b] CSG nodes are intended to be used for level prototyping. Creating CSG nodes has a significant CPU cost compared to creating a [MeshInstance] with a [PrimitiveMesh]. Moving a CSG node within another CSG node also has a significant CPU cost, so it should be avoided during gameplay.
|
||||
</description>
|
||||
<tutorials>
|
||||
<link title="Prototyping levels with CSG">$DOCS_URL/tutorials/3d/csg_tools.md</link>
|
||||
</tutorials>
|
||||
<methods>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="material" type="Material" setter="set_material" getter="get_material">
|
||||
The material used to render the sphere.
|
||||
</member>
|
||||
<member name="radial_segments" type="int" setter="set_radial_segments" getter="get_radial_segments" default="12">
|
||||
Number of vertical slices for the sphere.
|
||||
</member>
|
||||
<member name="radius" type="float" setter="set_radius" getter="get_radius" default="1.0">
|
||||
Radius of the sphere.
|
||||
</member>
|
||||
<member name="rings" type="int" setter="set_rings" getter="get_rings" default="6">
|
||||
Number of horizontal slices for the sphere.
|
||||
</member>
|
||||
<member name="smooth_faces" type="bool" setter="set_smooth_faces" getter="get_smooth_faces" default="true">
|
||||
If [code]true[/code] the normals of the sphere are set to give a smooth effect making the sphere seem rounded. If [code]false[/code] the sphere will have a flat shaded look.
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,37 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="CSGTorus" inherits="CSGPrimitive" version="4.2">
|
||||
<brief_description>
|
||||
A CSG Torus shape.
|
||||
</brief_description>
|
||||
<description>
|
||||
This node allows you to create a torus for use with the CSG system.
|
||||
[b]Note:[/b] CSG nodes are intended to be used for level prototyping. Creating CSG nodes has a significant CPU cost compared to creating a [MeshInstance] with a [PrimitiveMesh]. Moving a CSG node within another CSG node also has a significant CPU cost, so it should be avoided during gameplay.
|
||||
</description>
|
||||
<tutorials>
|
||||
<link title="Prototyping levels with CSG">$DOCS_URL/tutorials/3d/csg_tools.md</link>
|
||||
</tutorials>
|
||||
<methods>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="inner_radius" type="float" setter="set_inner_radius" getter="get_inner_radius" default="2.0">
|
||||
The inner radius of the torus.
|
||||
</member>
|
||||
<member name="material" type="Material" setter="set_material" getter="get_material">
|
||||
The material used to render the torus.
|
||||
</member>
|
||||
<member name="outer_radius" type="float" setter="set_outer_radius" getter="get_outer_radius" default="3.0">
|
||||
The outer radius of the torus.
|
||||
</member>
|
||||
<member name="ring_sides" type="int" setter="set_ring_sides" getter="get_ring_sides" default="6">
|
||||
The number of edges each ring of the torus is constructed of.
|
||||
</member>
|
||||
<member name="sides" type="int" setter="set_sides" getter="get_sides" default="8">
|
||||
The number of slices the torus is constructed of.
|
||||
</member>
|
||||
<member name="smooth_faces" type="bool" setter="set_smooth_faces" getter="get_smooth_faces" default="true">
|
||||
If [code]true[/code] the normals of the torus are set to give a smooth effect making the torus seem rounded. If [code]false[/code] the torus will have a flat shaded look.
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,458 +0,0 @@
|
||||
/**************************************************************************/
|
||||
/* csg_gizmos.cpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* 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 "csg_gizmos.h"
|
||||
|
||||
#include "editor/editor_settings.h"
|
||||
#include "scene/3d/camera.h"
|
||||
|
||||
///////////
|
||||
|
||||
CSGShapeSpatialGizmoPlugin::CSGShapeSpatialGizmoPlugin() {
|
||||
Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/csg", Color(0.0, 0.4, 1, 0.15));
|
||||
create_material("shape_union_material", gizmo_color);
|
||||
create_material("shape_union_solid_material", gizmo_color);
|
||||
gizmo_color.invert();
|
||||
create_material("shape_subtraction_material", gizmo_color);
|
||||
create_material("shape_subtraction_solid_material", gizmo_color);
|
||||
gizmo_color.r = 0.95;
|
||||
gizmo_color.g = 0.95;
|
||||
gizmo_color.b = 0.95;
|
||||
create_material("shape_intersection_material", gizmo_color);
|
||||
create_material("shape_intersection_solid_material", gizmo_color);
|
||||
|
||||
create_handle_material("handles");
|
||||
}
|
||||
|
||||
String CSGShapeSpatialGizmoPlugin::get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx, bool p_secondary) const {
|
||||
CSGShape *cs = Object::cast_to<CSGShape>(p_gizmo->get_spatial_node());
|
||||
|
||||
if (Object::cast_to<CSGSphere>(cs)) {
|
||||
return "Radius";
|
||||
}
|
||||
|
||||
if (Object::cast_to<CSGBox>(cs)) {
|
||||
static const char *hname[3] = { "Width", "Height", "Depth" };
|
||||
return hname[p_idx];
|
||||
}
|
||||
|
||||
if (Object::cast_to<CSGCylinder>(cs)) {
|
||||
return p_idx == 0 ? "Radius" : "Height";
|
||||
}
|
||||
|
||||
if (Object::cast_to<CSGTorus>(cs)) {
|
||||
return p_idx == 0 ? "InnerRadius" : "OuterRadius";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
Variant CSGShapeSpatialGizmoPlugin::get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx, bool p_secondary) const {
|
||||
CSGShape *cs = Object::cast_to<CSGShape>(p_gizmo->get_spatial_node());
|
||||
|
||||
if (Object::cast_to<CSGSphere>(cs)) {
|
||||
CSGSphere *s = Object::cast_to<CSGSphere>(cs);
|
||||
return s->get_radius();
|
||||
}
|
||||
|
||||
if (Object::cast_to<CSGBox>(cs)) {
|
||||
CSGBox *s = Object::cast_to<CSGBox>(cs);
|
||||
switch (p_idx) {
|
||||
case 0:
|
||||
return s->get_width();
|
||||
case 1:
|
||||
return s->get_height();
|
||||
case 2:
|
||||
return s->get_depth();
|
||||
}
|
||||
}
|
||||
|
||||
if (Object::cast_to<CSGCylinder>(cs)) {
|
||||
CSGCylinder *s = Object::cast_to<CSGCylinder>(cs);
|
||||
return p_idx == 0 ? s->get_radius() : s->get_height();
|
||||
}
|
||||
|
||||
if (Object::cast_to<CSGTorus>(cs)) {
|
||||
CSGTorus *s = Object::cast_to<CSGTorus>(cs);
|
||||
return p_idx == 0 ? s->get_inner_radius() : s->get_outer_radius();
|
||||
}
|
||||
|
||||
return Variant();
|
||||
}
|
||||
void CSGShapeSpatialGizmoPlugin::set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, bool p_secondary, Camera *p_camera, const Point2 &p_point) {
|
||||
CSGShape *cs = Object::cast_to<CSGShape>(p_gizmo->get_spatial_node());
|
||||
|
||||
Transform gt = cs->get_global_transform();
|
||||
//gt.orthonormalize();
|
||||
Transform gi = gt.affine_inverse();
|
||||
|
||||
Vector3 ray_from = p_camera->project_ray_origin(p_point);
|
||||
Vector3 ray_dir = p_camera->project_ray_normal(p_point);
|
||||
|
||||
Vector3 sg[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 16384) };
|
||||
|
||||
if (Object::cast_to<CSGSphere>(cs)) {
|
||||
CSGSphere *s = Object::cast_to<CSGSphere>(cs);
|
||||
|
||||
Vector3 ra, rb;
|
||||
Geometry::get_closest_points_between_segments(Vector3(), Vector3(4096, 0, 0), sg[0], sg[1], ra, rb);
|
||||
float d = ra.x;
|
||||
if (SpatialEditor::get_singleton()->is_snap_enabled()) {
|
||||
d = Math::stepify(d, SpatialEditor::get_singleton()->get_translate_snap());
|
||||
}
|
||||
|
||||
if (d < 0.001) {
|
||||
d = 0.001;
|
||||
}
|
||||
|
||||
s->set_radius(d);
|
||||
}
|
||||
|
||||
if (Object::cast_to<CSGBox>(cs)) {
|
||||
CSGBox *s = Object::cast_to<CSGBox>(cs);
|
||||
|
||||
Vector3 axis;
|
||||
axis[p_idx] = 1.0;
|
||||
Vector3 ra, rb;
|
||||
Geometry::get_closest_points_between_segments(Vector3(), axis * 4096, sg[0], sg[1], ra, rb);
|
||||
float d = ra[p_idx];
|
||||
|
||||
if (Math::is_nan(d)) {
|
||||
// The handle is perpendicular to the camera.
|
||||
return;
|
||||
}
|
||||
|
||||
if (SpatialEditor::get_singleton()->is_snap_enabled()) {
|
||||
d = Math::stepify(d, SpatialEditor::get_singleton()->get_translate_snap());
|
||||
}
|
||||
|
||||
if (d < 0.001) {
|
||||
d = 0.001;
|
||||
}
|
||||
|
||||
switch (p_idx) {
|
||||
case 0:
|
||||
s->set_width(d * 2);
|
||||
break;
|
||||
case 1:
|
||||
s->set_height(d * 2);
|
||||
break;
|
||||
case 2:
|
||||
s->set_depth(d * 2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (Object::cast_to<CSGCylinder>(cs)) {
|
||||
CSGCylinder *s = Object::cast_to<CSGCylinder>(cs);
|
||||
|
||||
Vector3 axis;
|
||||
axis[p_idx == 0 ? 0 : 1] = 1.0;
|
||||
Vector3 ra, rb;
|
||||
Geometry::get_closest_points_between_segments(Vector3(), axis * 4096, sg[0], sg[1], ra, rb);
|
||||
float d = axis.dot(ra);
|
||||
if (SpatialEditor::get_singleton()->is_snap_enabled()) {
|
||||
d = Math::stepify(d, SpatialEditor::get_singleton()->get_translate_snap());
|
||||
}
|
||||
|
||||
if (d < 0.001) {
|
||||
d = 0.001;
|
||||
}
|
||||
|
||||
if (p_idx == 0) {
|
||||
s->set_radius(d);
|
||||
} else if (p_idx == 1) {
|
||||
s->set_height(d * 2.0);
|
||||
}
|
||||
}
|
||||
|
||||
if (Object::cast_to<CSGTorus>(cs)) {
|
||||
CSGTorus *s = Object::cast_to<CSGTorus>(cs);
|
||||
|
||||
Vector3 axis;
|
||||
axis[0] = 1.0;
|
||||
Vector3 ra, rb;
|
||||
Geometry::get_closest_points_between_segments(Vector3(), axis * 4096, sg[0], sg[1], ra, rb);
|
||||
float d = axis.dot(ra);
|
||||
if (SpatialEditor::get_singleton()->is_snap_enabled()) {
|
||||
d = Math::stepify(d, SpatialEditor::get_singleton()->get_translate_snap());
|
||||
}
|
||||
|
||||
if (d < 0.001) {
|
||||
d = 0.001;
|
||||
}
|
||||
|
||||
if (p_idx == 0) {
|
||||
s->set_inner_radius(d);
|
||||
} else if (p_idx == 1) {
|
||||
s->set_outer_radius(d);
|
||||
}
|
||||
}
|
||||
}
|
||||
void CSGShapeSpatialGizmoPlugin::commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, bool p_secondary, const Variant &p_restore, bool p_cancel) {
|
||||
CSGShape *cs = Object::cast_to<CSGShape>(p_gizmo->get_spatial_node());
|
||||
|
||||
if (Object::cast_to<CSGSphere>(cs)) {
|
||||
CSGSphere *s = Object::cast_to<CSGSphere>(cs);
|
||||
if (p_cancel) {
|
||||
s->set_radius(p_restore);
|
||||
return;
|
||||
}
|
||||
|
||||
UndoRedo *ur = SpatialEditor::get_singleton()->get_undo_redo();
|
||||
ur->create_action(TTR("Change Sphere Shape Radius"));
|
||||
ur->add_do_method(s, "set_radius", s->get_radius());
|
||||
ur->add_undo_method(s, "set_radius", p_restore);
|
||||
ur->commit_action();
|
||||
}
|
||||
|
||||
if (Object::cast_to<CSGBox>(cs)) {
|
||||
CSGBox *s = Object::cast_to<CSGBox>(cs);
|
||||
if (p_cancel) {
|
||||
switch (p_idx) {
|
||||
case 0:
|
||||
s->set_width(p_restore);
|
||||
break;
|
||||
case 1:
|
||||
s->set_height(p_restore);
|
||||
break;
|
||||
case 2:
|
||||
s->set_depth(p_restore);
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
UndoRedo *ur = SpatialEditor::get_singleton()->get_undo_redo();
|
||||
ur->create_action(TTR("Change Box Shape Extents"));
|
||||
static const char *method[3] = { "set_width", "set_height", "set_depth" };
|
||||
float current = 0;
|
||||
switch (p_idx) {
|
||||
case 0:
|
||||
current = s->get_width();
|
||||
break;
|
||||
case 1:
|
||||
current = s->get_height();
|
||||
break;
|
||||
case 2:
|
||||
current = s->get_depth();
|
||||
break;
|
||||
}
|
||||
|
||||
ur->add_do_method(s, method[p_idx], current);
|
||||
ur->add_undo_method(s, method[p_idx], p_restore);
|
||||
ur->commit_action();
|
||||
}
|
||||
|
||||
if (Object::cast_to<CSGCylinder>(cs)) {
|
||||
CSGCylinder *s = Object::cast_to<CSGCylinder>(cs);
|
||||
if (p_cancel) {
|
||||
if (p_idx == 0) {
|
||||
s->set_radius(p_restore);
|
||||
} else {
|
||||
s->set_height(p_restore);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
UndoRedo *ur = SpatialEditor::get_singleton()->get_undo_redo();
|
||||
if (p_idx == 0) {
|
||||
ur->create_action(TTR("Change Cylinder Radius"));
|
||||
ur->add_do_method(s, "set_radius", s->get_radius());
|
||||
ur->add_undo_method(s, "set_radius", p_restore);
|
||||
} else {
|
||||
ur->create_action(TTR("Change Cylinder Height"));
|
||||
ur->add_do_method(s, "set_height", s->get_height());
|
||||
ur->add_undo_method(s, "set_height", p_restore);
|
||||
}
|
||||
|
||||
ur->commit_action();
|
||||
}
|
||||
|
||||
if (Object::cast_to<CSGTorus>(cs)) {
|
||||
CSGTorus *s = Object::cast_to<CSGTorus>(cs);
|
||||
if (p_cancel) {
|
||||
if (p_idx == 0) {
|
||||
s->set_inner_radius(p_restore);
|
||||
} else {
|
||||
s->set_outer_radius(p_restore);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
UndoRedo *ur = SpatialEditor::get_singleton()->get_undo_redo();
|
||||
if (p_idx == 0) {
|
||||
ur->create_action(TTR("Change Torus Inner Radius"));
|
||||
ur->add_do_method(s, "set_inner_radius", s->get_inner_radius());
|
||||
ur->add_undo_method(s, "set_inner_radius", p_restore);
|
||||
} else {
|
||||
ur->create_action(TTR("Change Torus Outer Radius"));
|
||||
ur->add_do_method(s, "set_outer_radius", s->get_outer_radius());
|
||||
ur->add_undo_method(s, "set_outer_radius", p_restore);
|
||||
}
|
||||
|
||||
ur->commit_action();
|
||||
}
|
||||
}
|
||||
bool CSGShapeSpatialGizmoPlugin::has_gizmo(Spatial *p_spatial) {
|
||||
return Object::cast_to<CSGSphere>(p_spatial) || Object::cast_to<CSGBox>(p_spatial) || Object::cast_to<CSGCylinder>(p_spatial) || Object::cast_to<CSGTorus>(p_spatial) || Object::cast_to<CSGMesh>(p_spatial) || Object::cast_to<CSGPolygon>(p_spatial);
|
||||
}
|
||||
|
||||
String CSGShapeSpatialGizmoPlugin::get_gizmo_name() const {
|
||||
return "CSGShapes";
|
||||
}
|
||||
|
||||
int CSGShapeSpatialGizmoPlugin::get_priority() const {
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool CSGShapeSpatialGizmoPlugin::is_selectable_when_hidden() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void CSGShapeSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
|
||||
p_gizmo->clear();
|
||||
|
||||
CSGShape *cs = Object::cast_to<CSGShape>(p_gizmo->get_spatial_node());
|
||||
|
||||
PoolVector<Vector3> faces = cs->get_brush_faces();
|
||||
|
||||
if (faces.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Vector<Vector3> lines;
|
||||
lines.resize(faces.size() * 2);
|
||||
{
|
||||
PoolVector<Vector3>::Read r = faces.read();
|
||||
|
||||
for (int i = 0; i < lines.size(); i += 6) {
|
||||
int f = i / 6;
|
||||
for (int j = 0; j < 3; j++) {
|
||||
int j_n = (j + 1) % 3;
|
||||
lines.write[i + j * 2 + 0] = r[f * 3 + j];
|
||||
lines.write[i + j * 2 + 1] = r[f * 3 + j_n];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ref<Material> material;
|
||||
switch (cs->get_operation()) {
|
||||
case CSGShape::OPERATION_UNION:
|
||||
material = get_material("shape_union_material", p_gizmo);
|
||||
break;
|
||||
case CSGShape::OPERATION_INTERSECTION:
|
||||
material = get_material("shape_intersection_material", p_gizmo);
|
||||
break;
|
||||
case CSGShape::OPERATION_SUBTRACTION:
|
||||
material = get_material("shape_subtraction_material", p_gizmo);
|
||||
break;
|
||||
}
|
||||
|
||||
Ref<Material> handles_material = get_material("handles");
|
||||
|
||||
p_gizmo->add_lines(lines, material);
|
||||
p_gizmo->add_collision_segments(lines);
|
||||
|
||||
if (cs->is_root_shape()) {
|
||||
Array csg_meshes = cs->get_meshes();
|
||||
if (csg_meshes.size() == 2) {
|
||||
Ref<Mesh> csg_mesh = csg_meshes[1];
|
||||
if (csg_mesh.is_valid()) {
|
||||
p_gizmo->add_collision_triangles(csg_mesh->generate_triangle_mesh());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (p_gizmo->is_selected()) {
|
||||
// Draw a translucent representation of the CSG node
|
||||
Ref<ArrayMesh> mesh = memnew(ArrayMesh);
|
||||
Array array;
|
||||
array.resize(Mesh::ARRAY_MAX);
|
||||
array[Mesh::ARRAY_VERTEX] = faces;
|
||||
mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, array);
|
||||
|
||||
Ref<Material> solid_material;
|
||||
switch (cs->get_operation()) {
|
||||
case CSGShape::OPERATION_UNION:
|
||||
solid_material = get_material("shape_union_solid_material", p_gizmo);
|
||||
break;
|
||||
case CSGShape::OPERATION_INTERSECTION:
|
||||
solid_material = get_material("shape_intersection_solid_material", p_gizmo);
|
||||
break;
|
||||
case CSGShape::OPERATION_SUBTRACTION:
|
||||
solid_material = get_material("shape_subtraction_solid_material", p_gizmo);
|
||||
break;
|
||||
}
|
||||
|
||||
p_gizmo->add_mesh(mesh, solid_material);
|
||||
}
|
||||
|
||||
if (Object::cast_to<CSGSphere>(cs)) {
|
||||
CSGSphere *s = Object::cast_to<CSGSphere>(cs);
|
||||
|
||||
float r = s->get_radius();
|
||||
Vector<Vector3> handles;
|
||||
handles.push_back(Vector3(r, 0, 0));
|
||||
p_gizmo->add_handles(handles, handles_material);
|
||||
}
|
||||
|
||||
if (Object::cast_to<CSGBox>(cs)) {
|
||||
CSGBox *s = Object::cast_to<CSGBox>(cs);
|
||||
|
||||
Vector<Vector3> handles;
|
||||
handles.push_back(Vector3(s->get_width() * 0.5, 0, 0));
|
||||
handles.push_back(Vector3(0, s->get_height() * 0.5, 0));
|
||||
handles.push_back(Vector3(0, 0, s->get_depth() * 0.5));
|
||||
p_gizmo->add_handles(handles, handles_material);
|
||||
}
|
||||
|
||||
if (Object::cast_to<CSGCylinder>(cs)) {
|
||||
CSGCylinder *s = Object::cast_to<CSGCylinder>(cs);
|
||||
|
||||
Vector<Vector3> handles;
|
||||
handles.push_back(Vector3(s->get_radius(), 0, 0));
|
||||
handles.push_back(Vector3(0, s->get_height() * 0.5, 0));
|
||||
p_gizmo->add_handles(handles, handles_material);
|
||||
}
|
||||
|
||||
if (Object::cast_to<CSGTorus>(cs)) {
|
||||
CSGTorus *s = Object::cast_to<CSGTorus>(cs);
|
||||
|
||||
Vector<Vector3> handles;
|
||||
handles.push_back(Vector3(s->get_inner_radius(), 0, 0));
|
||||
handles.push_back(Vector3(s->get_outer_radius(), 0, 0));
|
||||
p_gizmo->add_handles(handles, handles_material);
|
||||
}
|
||||
}
|
||||
|
||||
EditorPluginCSG::EditorPluginCSG(EditorNode *p_editor) {
|
||||
Ref<CSGShapeSpatialGizmoPlugin> gizmo_plugin = Ref<CSGShapeSpatialGizmoPlugin>(memnew(CSGShapeSpatialGizmoPlugin));
|
||||
SpatialEditor::get_singleton()->add_gizmo_plugin(gizmo_plugin);
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
/**************************************************************************/
|
||||
/* csg_gizmos.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* 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 CSG_GIZMOS_H
|
||||
#define CSG_GIZMOS_H
|
||||
|
||||
#include "../csg_shape.h"
|
||||
#include "editor/editor_plugin.h"
|
||||
#include "editor/spatial_editor_gizmos.h"
|
||||
|
||||
class CSGShapeSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
|
||||
GDCLASS(CSGShapeSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
|
||||
|
||||
public:
|
||||
bool has_gizmo(Spatial *p_spatial);
|
||||
String get_gizmo_name() const;
|
||||
int get_priority() const;
|
||||
bool is_selectable_when_hidden() const;
|
||||
void redraw(EditorSpatialGizmo *p_gizmo);
|
||||
|
||||
String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx, bool p_secondary) const;
|
||||
Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx, bool p_secondary) const;
|
||||
void set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, bool p_secondary, Camera *p_camera, const Point2 &p_point);
|
||||
void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, bool p_secondary, const Variant &p_restore, bool p_cancel = false);
|
||||
|
||||
CSGShapeSpatialGizmoPlugin();
|
||||
};
|
||||
|
||||
class EditorPluginCSG : public EditorPlugin {
|
||||
GDCLASS(EditorPluginCSG, EditorPlugin);
|
||||
|
||||
public:
|
||||
EditorPluginCSG(EditorNode *p_editor);
|
||||
};
|
||||
|
||||
#endif // CSG_GIZMOS_H
|
@ -1,56 +0,0 @@
|
||||
/**************************************************************************/
|
||||
/* csgshape3d_navigation_geometry_parser_3d.cpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* 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 "csgshape3d_navigation_geometry_parser_3d.h"
|
||||
|
||||
#include "scene/resources/navigation/navigation_mesh.h"
|
||||
#include "scene/resources/navigation/navigation_mesh_source_geometry_data_3d.h"
|
||||
#include "scene/resources/mesh/mesh.h"
|
||||
|
||||
#include "modules/csg/csg_shape.h"
|
||||
|
||||
bool CSGShape3DNavigationGeometryParser3D::parses_node(Node *p_node) {
|
||||
return (Object::cast_to<CSGShape>(p_node) != nullptr);
|
||||
}
|
||||
|
||||
void CSGShape3DNavigationGeometryParser3D::parse_geometry(Node *p_node, Ref<NavigationMesh> p_navigationmesh, Ref<NavigationMeshSourceGeometryData3D> p_source_geometry) {
|
||||
NavigationMesh::ParsedGeometryType parsed_geometry_type = p_navigationmesh->get_parsed_geometry_type();
|
||||
|
||||
if (Object::cast_to<CSGShape>(p_node) && parsed_geometry_type != NavigationMesh::PARSED_GEOMETRY_STATIC_COLLIDERS) {
|
||||
CSGShape *csg_shape = Object::cast_to<CSGShape>(p_node);
|
||||
Array meshes = csg_shape->get_meshes();
|
||||
if (!meshes.empty()) {
|
||||
Ref<Mesh> mesh = meshes[1];
|
||||
if (mesh.is_valid()) {
|
||||
p_source_geometry->add_mesh(mesh, csg_shape->get_global_transform());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
|
||||
#ifndef CSGSHAPE3D_NAVIGATION_GEOMETRY_PARSER_3D_H
|
||||
#define CSGSHAPE3D_NAVIGATION_GEOMETRY_PARSER_3D_H
|
||||
|
||||
/**************************************************************************/
|
||||
/* csgshape3d_navigation_geometry_parser_3d.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* 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 "scene/3d/navigation_geometry_parser_3d.h"
|
||||
|
||||
class CSGShape3DNavigationGeometryParser3D : public NavigationGeometryParser3D {
|
||||
public:
|
||||
virtual bool parses_node(Node *p_node) override;
|
||||
|
||||
virtual void parse_geometry(Node *p_node, Ref<NavigationMesh> p_navigationmesh, Ref<NavigationMeshSourceGeometryData3D> p_source_geometry) override;
|
||||
};
|
||||
|
||||
#endif // CSGSHAPE3D_NAVIGATION_GEOMETRY_PARSER_3D_H
|
@ -1,6 +0,0 @@
|
||||
<svg width="16" height="16" version="1.1" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
|
||||
<g transform="translate(0 -1036.4)">
|
||||
<path transform="translate(0 1036.4)" d="m12 9c-0.55401 0-1 0.44599-1 1v1h2v2h1c0.55401 0 1-0.44599 1-1v-2c0-0.55401-0.44599-1-1-1h-2zm1 4h-2v-2h-1c-0.55401 0-1 0.44599-1 1v2c0 0.55401 0.44599 1 1 1h2c0.55401 0 1-0.44599 1-1v-1z" fill="#84c2ff"/>
|
||||
<path transform="translate(0 1036.4)" d="m8 0.94531-7 3.5v7.2227l7 3.5 0.29492-0.14844c-0.18282-0.30101-0.29492-0.64737-0.29492-1.0195v-2c0-0.72651 0.40824-1.3664 1-1.7168v-1.6699l4-2v1.3867h1c0.36419 0 0.70336 0.10754 1 0.2832v-3.8379zm0 2.1152 3.9395 1.9707-3.9395 1.9688-3.9395-1.9688zm-5 3.5527 4 2v3.9414l-4-2.002z" fill="#fc9c9c" stroke-width="1.0667"/>
|
||||
</g>
|
||||
</svg>
|
Before Width: | Height: | Size: 754 B |
@ -1,6 +0,0 @@
|
||||
<svg width="16" height="16" version="1.1" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
|
||||
<g>
|
||||
<path d="m8 1c-2.7527 0-5 2.2418-5 4.9902v4.0176c0 2.7484 2.2473 4.9922 5 4.9922 0.092943 0 0.18367-0.008623 0.27539-0.013672-0.17055-0.29341-0.27539-0.62792-0.27539-0.98633v-2c0-0.72887 0.41095-1.3691 1.0059-1.7188v-0.28125c0.34771-0.034464 0.68259-0.10691 1.0156-0.19922 0.10394-0.99856 0.95603-1.8008 1.9785-1.8008h1v-2.0098c0-2.7484-2.2473-4.9902-5-4.9902zm-1.0059 2.127v4.8574c-0.66556-0.1047-1.2974-0.37231-1.9941-0.66211v-1.3223c0-1.3474 0.79841-2.4642 1.9941-2.873zm2.0117 0c1.1957 0.4088 1.9941 1.5256 1.9941 2.873v1.3457c-0.68406 0.3054-1.3142 0.57292-1.9941 0.66602v-4.8848zm-4.0059 6.334c0.67836 0.2231 1.3126 0.44599 1.9941 0.52539v2.8848c-1.1957-0.4092-1.9941-1.5237-1.9941-2.8711v-0.53906z" fill="#fc9c9c"/>
|
||||
<path d="m12 9c-0.55401 0-1 0.44599-1 1v1h2v2h1c0.55401 0 1-0.44599 1-1v-2c0-0.55401-0.44599-1-1-1zm1 4h-2v-2h-1c-0.55401 0-1 0.44599-1 1v2c0 0.55401 0.44599 1 1 1h2c0.55401 0 1-0.44599 1-1z" fill="#84c2ff"/>
|
||||
</g>
|
||||
</svg>
|
Before Width: | Height: | Size: 1.0 KiB |
@ -1,8 +0,0 @@
|
||||
<svg width="16" height="16" version="1.1" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
|
||||
<g transform="translate(0 -1036.4)">
|
||||
<path transform="translate(0 1036.4)" d="m12 9c-0.55401 0-1 0.44599-1 1v1h2v2h1c0.55401 0 1-0.44599 1-1v-2c0-0.55401-0.44599-1-1-1h-2zm1 4h-2v-2h-1c-0.55401 0-1 0.44599-1 1v2c0 0.55401 0.44599 1 1 1h2c0.55401 0 1-0.44599 1-1v-1z" fill="#84c2ff"/>
|
||||
<g fill="#fc9c9c">
|
||||
<path transform="translate(0 1036.4)" d="m3 1c-1.1046 0-2 0.89543-2 2h2zm2 0v2h2v-2zm4 0v2h2v-2zm4 0v2h2c0-1.1046-0.89543-2-2-2zm-12 4v2h2v-2zm12 0v2h2v-2zm-12 4v2h2v-2zm0 4c0 1.1046 0.89543 2 2 2v-2zm4 0v2h2v-2z" fill="#fc9c9c"/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
Before Width: | Height: | Size: 649 B |
@ -1,6 +0,0 @@
|
||||
<svg width="16" height="16" version="1.1" viewBox="0 0 14.999999 14.999999" xmlns="http://www.w3.org/2000/svg">
|
||||
<g>
|
||||
<path transform="scale(.9375)" d="m8 1c-1.7469 0-3.328 0.22648-4.5586 0.63672-0.61528 0.20512-1.1471 0.45187-1.5898 0.80078-0.44272 0.34891-0.85156 0.88101-0.85156 1.5625v8c0 0.68149 0.40884 1.2155 0.85156 1.5645 0.44272 0.34891 0.97457 0.59577 1.5898 0.80078 1.2306 0.41024 2.8117 0.63477 4.5586 0.63477 0.095648 0 0.18467-0.008426 0.2793-0.009766-0.1722-0.29446-0.2793-0.62995-0.2793-0.99023v-1c-1.5668 0-2.9867-0.2195-3.9277-0.5332-0.46329-0.15435-0.90474-0.33752-1.0723-0.4668v-5.8125c0.1468 0.058667 0.2835 0.12515 0.44141 0.17773 1.2306 0.41024 2.8117 0.63477 4.5586 0.63477s3.328-0.22453 4.5586-0.63477c0.15791-0.052267 0.29461-0.11864 0.44141-0.17773v1.8125h1c0.36396 0 0.70348 0.10774 1 0.2832v-4.2832c0-0.68149-0.40884-1.2136-0.85156-1.5625-0.44272-0.34891-0.97457-0.59566-1.5898-0.80078-1.2306-0.41024-2.8117-0.63672-4.5586-0.63672zm0 2c1.5668 0 2.9867 0.22145 3.9277 0.53516 0.46368 0.15456 0.80138 0.33741 0.96875 0.4668-0.16752 0.12928-0.50546 0.3105-0.96875 0.46484-0.94102 0.31371-2.361 0.5332-3.9277 0.5332s-2.9867-0.2195-3.9277-0.5332c-0.46329-0.15435-0.80123-0.33556-0.96875-0.46484 0.16737-0.12939 0.50507-0.31224 0.96875-0.4668 0.94102-0.31371 2.361-0.53516 3.9277-0.53516z" fill="#fc9c9c" stroke-width="1.0667"/>
|
||||
<path d="m11.25 8.4375c-0.51938 0-0.9375 0.41812-0.9375 0.9375v0.9375h1.875v1.875h0.9375c0.51938 0 0.9375-0.41812 0.9375-0.9375v-1.875c0-0.51938-0.41812-0.9375-0.9375-0.9375zm0.9375 3.75h-1.875v-1.875h-0.9375c-0.51938 0-0.9375 0.41812-0.9375 0.9375v1.875c0 0.51938 0.41812 0.9375 0.9375 0.9375h1.875c0.51938 0 0.9375-0.41812 0.9375-0.9375z" fill="#84c2ff"/>
|
||||
</g>
|
||||
</svg>
|
Before Width: | Height: | Size: 1.7 KiB |
@ -1,6 +0,0 @@
|
||||
<svg width="16" height="16" version="1.1" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
|
||||
<g>
|
||||
<path d="m3 1c-1.1046 0-2 0.89543-2 2 5.649e-4 0.71397 0.38169 1.3735 1 1.7305v6.541c-0.61771 0.35663-0.99874 1.0152-1 1.7285 0 1.1046 0.89543 2 2 2 0.71397-5.65e-4 1.3735-0.38169 1.7305-1h3.2695v-2h-3.2715c-0.17478-0.30301-0.42598-0.55488-0.72852-0.73047v-5.8555l4.916 4.916c0.31428-0.20669 0.68609-0.33008 1.084-0.33008 0-0.3979 0.12338-0.76971 0.33008-1.084l-4.916-4.916h5.8574c0.17478 0.30301 0.42598 0.55488 0.72852 0.73047v3.2695h2v-3.2715c0.61771-0.35663 0.99874-1.0152 1-1.7285 0-1.1046-0.89543-2-2-2-0.71397 5.648e-4 -1.3735 0.38169-1.7305 1h-6.541c-0.35663-0.61771-1.0152-0.99874-1.7285-1z" fill="#fc9c9c"/>
|
||||
<path d="m12 9c-0.55401 0-1 0.44599-1 1v1h2v2h1c0.55401 0 1-0.44599 1-1v-2c0-0.55401-0.44599-1-1-1zm1 4h-2v-2h-1c-0.55401 0-1 0.44599-1 1v2c0 0.55401 0.44599 1 1 1h2c0.55401 0 1-0.44599 1-1z" fill="#84c2ff"/>
|
||||
</g>
|
||||
</svg>
|
Before Width: | Height: | Size: 941 B |
@ -1,6 +0,0 @@
|
||||
<svg width="16" height="16" version="1.1" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
|
||||
<g transform="translate(0 -1036.4)">
|
||||
<path transform="translate(0 1036.4)" d="m7.9629 1.002c-0.14254 0.00487-0.28238 0.04016-0.41016 0.10352l-6 3c-0.33878 0.16944-0.55276 0.51574-0.55273 0.89453v5.832c-0.105 0.61631 0.37487 1.1768 1 1.168h5v2c2.16e-5 0.67546 0.64487 1.1297 1.2617 0.95898-0.16118-0.28721-0.26172-0.61135-0.26172-0.95898v-2c0-0.72673 0.40794-1.3664 1-1.7168v-1.666l4-2v1.3828h1c0.36397 0 0.70348 0.10774 1 0.2832v-3.2773c6e-6 -0.00195 6e-6 -0.0039094 0-0.0058594 2.6e-5 -0.37879-0.21395-0.72509-0.55273-0.89453l-6-3c-0.15022-0.074574-0.31679-0.11017-0.48438-0.10352zm0.037109 2.1172l3.7637 1.8809-2.7637 1.3809v-1.3809c-5.52e-5 -0.55226-0.44774-0.99994-1-1h-1.7617l1.7617-0.88086zm-5 2.8809h4v4h-4v-4z" color="#000000" color-rendering="auto" dominant-baseline="auto" fill="#fc9c9c" image-rendering="auto" shape-rendering="auto" solid-color="#000000" style="font-feature-settings:normal;font-variant-alternates:normal;font-variant-caps:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-position:normal;isolation:auto;mix-blend-mode:normal;shape-padding:0;text-decoration-color:#000000;text-decoration-line:none;text-decoration-style:solid;text-indent:0;text-orientation:mixed;text-transform:none;white-space:normal"/>
|
||||
<path transform="translate(0 1036.4)" d="m12 9c-0.55401 0-1 0.44599-1 1v1h2v2h1c0.55401 0 1-0.44599 1-1v-2c0-0.55401-0.44599-1-1-1h-2zm1 4h-2v-2h-1c-0.55401 0-1 0.44599-1 1v2c0 0.55401 0.44599 1 1 1h2c0.55401 0 1-0.44599 1-1v-1z" fill="#84c2ff"/>
|
||||
</g>
|
||||
</svg>
|
Before Width: | Height: | Size: 1.6 KiB |
@ -1,6 +0,0 @@
|
||||
<svg width="16" height="16" version="1.1" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
|
||||
<g>
|
||||
<path d="m8 1c-3.8541 0-7 3.1459-7 7 0 3.8542 3.1459 7 7 7 0.093042 0 0.18321-0.01004 0.27539-0.013672-0.17055-0.29341-0.27539-0.62792-0.27539-0.98633v-2c0-0.72673 0.40794-1.3664 1-1.7168v-0.33398c0.34074-0.019259 0.67728-0.069097 1.0156-0.10547 0.083091-1.0187 0.94713-1.8438 1.9844-1.8438h2c0.35841 0 0.69292 0.10484 0.98633 0.27539 0.003633-0.092184 0.013672-0.18235 0.013672-0.27539 0-3.8541-3.1459-7-7-7zm-1 2.0977v4.8711c-1.2931-0.071342-2.6061-0.29819-3.9434-0.69141 0.30081-2.0978 1.8852-3.7665 3.9434-4.1797zm2 0c2.0549 0.41253 3.637 2.0767 3.9414 4.1699-1.3046 0.36677-2.6158 0.60259-3.9414 0.6875v-4.8574zm-5.7793 6.2988c1.2733 0.31892 2.5337 0.50215 3.7793 0.5625v2.9414c-1.8291-0.36719-3.266-1.7339-3.7793-3.5039z" fill="#fc9c9c"/>
|
||||
<path d="m12 9c-0.55401 0-1 0.44599-1 1v1h2v2h1c0.55401 0 1-0.44599 1-1v-2c0-0.55401-0.44599-1-1-1zm1 4h-2v-2h-1c-0.55401 0-1 0.44599-1 1v2c0 0.55401 0.44599 1 1 1h2c0.55401 0 1-0.44599 1-1z" fill="#84c2ff"/>
|
||||
</g>
|
||||
</svg>
|
Before Width: | Height: | Size: 1.0 KiB |
@ -1,6 +0,0 @@
|
||||
<svg width="16" height="16" version="1.1" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
|
||||
<g transform="translate(0 -1036.4)">
|
||||
<path transform="translate(0 1036.4)" d="m8 3c-1.8145 0-3.4691 0.41721-4.7461 1.1621-1.277 0.745-2.2539 1.9082-2.2539 3.3379 0 1.4298 0.9769 2.5949 2.2539 3.3398 1.277 0.7449 2.9316 1.1602 4.7461 1.1602 0-1.0907 0.90931-2 2-2 0-0.080836 0.013744-0.15778 0.023438-0.23633-0.61769 0.14673-1.3008 0.23633-2.0234 0.23633-1.4992 0-2.8437-0.36687-3.7383-0.88867-0.89456-0.5219-1.2617-1.108-1.2617-1.6113 0-0.5032 0.36716-1.0876 1.2617-1.6094 0.89456-0.5219 2.2391-0.89062 3.7383-0.89062s2.8437 0.36872 3.7383 0.89062c0.89456 0.5218 1.2617 1.1062 1.2617 1.6094 0 0.15978-0.053679 0.32822-0.13281 0.5h1.1328c0.32481 0 0.62893 0.088408 0.90234 0.23047 0.057552-0.23582 0.097656-0.47718 0.097656-0.73047 0-1.4297-0.9769-2.5929-2.2539-3.3379-1.277-0.7449-2.9316-1.1621-4.7461-1.1621z" color="#000000" color-rendering="auto" dominant-baseline="auto" fill="#fc9c9c" image-rendering="auto" shape-rendering="auto" solid-color="#000000" style="font-feature-settings:normal;font-variant-alternates:normal;font-variant-caps:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-position:normal;isolation:auto;mix-blend-mode:normal;shape-padding:0;text-decoration-color:#000000;text-decoration-line:none;text-decoration-style:solid;text-indent:0;text-orientation:mixed;text-transform:none;white-space:normal"/>
|
||||
<path transform="translate(0 1036.4)" d="m12 9c-0.55401 0-1 0.44599-1 1v1h2v2h1c0.55401 0 1-0.44599 1-1v-2c0-0.55401-0.44599-1-1-1h-2zm1 4h-2v-2h-1c-0.55401 0-1 0.44599-1 1v2c0 0.55401 0.44599 1 1 1h2c0.55401 0 1-0.44599 1-1v-1z" fill="#84c2ff"/>
|
||||
</g>
|
||||
</svg>
|
Before Width: | Height: | Size: 1.7 KiB |
@ -1,67 +0,0 @@
|
||||
/**************************************************************************/
|
||||
/* register_types.cpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* 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 "register_types.h"
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
#include "./editor/csg_gizmos.h"
|
||||
#endif
|
||||
|
||||
#include "csg_shape.h"
|
||||
|
||||
#include "modules/csg/geometry_parser/csgshape3d_navigation_geometry_parser_3d.h"
|
||||
#include "servers/navigation/navigation_mesh_generator.h"
|
||||
|
||||
void register_csg_types(ModuleRegistrationLevel p_level) {
|
||||
#ifndef _3D_DISABLED
|
||||
if (p_level == MODULE_REGISTRATION_LEVEL_SCENE) {
|
||||
ClassDB::register_virtual_class<CSGShape>();
|
||||
ClassDB::register_virtual_class<CSGPrimitive>();
|
||||
ClassDB::register_class<CSGMesh>();
|
||||
ClassDB::register_class<CSGSphere>();
|
||||
ClassDB::register_class<CSGBox>();
|
||||
ClassDB::register_class<CSGCylinder>();
|
||||
ClassDB::register_class<CSGTorus>();
|
||||
ClassDB::register_class<CSGPolygon>();
|
||||
ClassDB::register_class<CSGCombiner>();
|
||||
|
||||
NavigationMeshGenerator::get_singleton()->register_geometry_parser_3d(memnew(CSGShape3DNavigationGeometryParser3D));
|
||||
}
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
if (p_level == MODULE_REGISTRATION_LEVEL_EDITOR) {
|
||||
EditorPlugins::add_by_type<EditorPluginCSG>();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void unregister_csg_types(ModuleRegistrationLevel p_level) {
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
|
||||
#ifndef CSG_REGISTER_TYPES_H
|
||||
#define CSG_REGISTER_TYPES_H
|
||||
|
||||
/**************************************************************************/
|
||||
/* register_types.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* 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 "modules/register_module_types.h"
|
||||
|
||||
void register_csg_types(ModuleRegistrationLevel p_level);
|
||||
void unregister_csg_types(ModuleRegistrationLevel p_level);
|
||||
|
||||
#endif // CSG_REGISTER_TYPES_H
|
@ -1,32 +0,0 @@
|
||||
import os
|
||||
import version
|
||||
|
||||
Import('env')
|
||||
|
||||
module_env = env.Clone()
|
||||
|
||||
sources = [
|
||||
"register_types.cpp",
|
||||
|
||||
"database.cpp",
|
||||
"database_connection.cpp",
|
||||
"database_manager.cpp",
|
||||
"database_multi_threaded.cpp",
|
||||
"database_single_threaded.cpp",
|
||||
"query_builder.cpp",
|
||||
"query_result.cpp",
|
||||
"table_builder.cpp",
|
||||
]
|
||||
|
||||
if ARGUMENTS.get('custom_modules_shared', 'no') == 'yes':
|
||||
# Shared lib compilation
|
||||
module_env.Append(CCFLAGS=['-fPIC'])
|
||||
module_env['LIBS'] = []
|
||||
shared_lib = module_env.SharedLibrary(target='#bin/database', source=sources)
|
||||
shared_lib_shim = shared_lib[0].name.rsplit('.', 1)[0]
|
||||
env.Append(LIBS=[shared_lib_shim])
|
||||
env.Append(LIBPATH=['#bin'])
|
||||
else:
|
||||
# Static compilation
|
||||
module_env.add_source_files(env.modules_sources, sources)
|
||||
|
@ -1,25 +0,0 @@
|
||||
|
||||
def can_build(env, platform):
|
||||
return True
|
||||
|
||||
|
||||
def configure(env):
|
||||
pass
|
||||
|
||||
|
||||
def get_doc_classes():
|
||||
return [
|
||||
#"",
|
||||
"Database",
|
||||
"DatabaseConnection",
|
||||
"DatabaseManager",
|
||||
"DatabaseMultiThreaded",
|
||||
"DatabaseSingleThreaded",
|
||||
"QueryBuilder",
|
||||
"QueryResult",
|
||||
"TableBuilder",
|
||||
]
|
||||
|
||||
def get_doc_path():
|
||||
return "doc_classes"
|
||||
|
@ -1,41 +0,0 @@
|
||||
#include "database.h"
|
||||
|
||||
#include "database_connection.h"
|
||||
#include "query_builder.h"
|
||||
#include "query_result.h"
|
||||
#include "table_builder.h"
|
||||
|
||||
String Database::get_connection_string() {
|
||||
return _connection_string;
|
||||
}
|
||||
void Database::set_connection_string(const String &val) {
|
||||
_connection_string = val;
|
||||
}
|
||||
|
||||
Ref<DatabaseConnection> Database::get_connection() {
|
||||
return _allocate_connection();
|
||||
}
|
||||
|
||||
Ref<DatabaseConnection> Database::_allocate_connection() {
|
||||
//Ref<DatabaseConnection> dbc;
|
||||
//dbc.instance();
|
||||
//dbc->set_owner(this); //if needed
|
||||
//dbc->database_connect(_connection_string);
|
||||
//return dbc;
|
||||
|
||||
return Ref<DatabaseConnection>();
|
||||
}
|
||||
|
||||
Database::Database() {
|
||||
}
|
||||
|
||||
Database::~Database() {
|
||||
}
|
||||
|
||||
void Database::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_connection_string"), &Database::get_connection_string);
|
||||
ClassDB::bind_method(D_METHOD("set_connection_string", "value"), &Database::set_connection_string);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "connection_string"), "set_connection_string", "get_connection_string");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_connection"), &Database::get_connection);
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
#ifndef DATABASE_H
|
||||
#define DATABASE_H
|
||||
|
||||
#include "core/string/ustring.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
|
||||
class DatabaseConnection;
|
||||
|
||||
class Database : public Reference {
|
||||
GDCLASS(Database, Reference);
|
||||
|
||||
public:
|
||||
String get_connection_string();
|
||||
void set_connection_string(const String &val);
|
||||
|
||||
virtual Ref<DatabaseConnection> get_connection();
|
||||
|
||||
Database();
|
||||
~Database();
|
||||
|
||||
protected:
|
||||
virtual Ref<DatabaseConnection> _allocate_connection();
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
String _connection_string;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,78 +0,0 @@
|
||||
#include "database_connection.h"
|
||||
|
||||
#include "database.h"
|
||||
#include "query_builder.h"
|
||||
#include "query_result.h"
|
||||
#include "table_builder.h"
|
||||
|
||||
void DatabaseConnection::database_connect(const String &connection_str) {
|
||||
}
|
||||
|
||||
Ref<QueryResult> DatabaseConnection::query(const String &query) {
|
||||
return Ref<QueryResult>();
|
||||
}
|
||||
void DatabaseConnection::query_run(const String &query) {
|
||||
}
|
||||
|
||||
Ref<QueryBuilder> DatabaseConnection::get_query_builder() {
|
||||
return Ref<QueryBuilder>(new QueryBuilder());
|
||||
}
|
||||
|
||||
Ref<TableBuilder> DatabaseConnection::get_table_builder() {
|
||||
return Ref<TableBuilder>(new TableBuilder());
|
||||
}
|
||||
|
||||
String DatabaseConnection::escape(const String &str) {
|
||||
return String();
|
||||
}
|
||||
|
||||
void DatabaseConnection::escape_to(const String &str, String *to) {
|
||||
}
|
||||
|
||||
Ref<Database> DatabaseConnection::get_owner() {
|
||||
return Ref<Database>(_owner);
|
||||
}
|
||||
|
||||
int DatabaseConnection::get_table_version(const String &table) {
|
||||
ensure_version_table_exists();
|
||||
|
||||
//get_query_builder()
|
||||
//TODO
|
||||
|
||||
return 0;
|
||||
}
|
||||
void DatabaseConnection::set_table_version(const String &table, const int version) {
|
||||
//TODO
|
||||
}
|
||||
void DatabaseConnection::ensure_version_table_exists() {
|
||||
//TODO
|
||||
}
|
||||
|
||||
void DatabaseConnection::set_owner(Database *owner) {
|
||||
_owner = owner;
|
||||
}
|
||||
|
||||
DatabaseConnection::DatabaseConnection() {
|
||||
_owner = nullptr;
|
||||
}
|
||||
|
||||
DatabaseConnection::~DatabaseConnection() {
|
||||
_owner = nullptr;
|
||||
}
|
||||
|
||||
void DatabaseConnection::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("database_connect", "connection_str"), &DatabaseConnection::database_connect);
|
||||
ClassDB::bind_method(D_METHOD("query", "query"), &DatabaseConnection::query);
|
||||
ClassDB::bind_method(D_METHOD("query_run", "query"), &DatabaseConnection::query_run);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_query_builder"), &DatabaseConnection::get_query_builder);
|
||||
ClassDB::bind_method(D_METHOD("get_table_builder"), &DatabaseConnection::get_table_builder);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("escape", "str"), &DatabaseConnection::escape);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_table_version", "table"), &DatabaseConnection::get_table_version);
|
||||
ClassDB::bind_method(D_METHOD("set_table_version", "table", "version"), &DatabaseConnection::set_table_version);
|
||||
ClassDB::bind_method(D_METHOD("ensure_version_table_exists"), &DatabaseConnection::ensure_version_table_exists);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_owner"), &DatabaseConnection::get_owner);
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
#ifndef DATABASE_CONNECTION_H
|
||||
#define DATABASE_CONNECTION_H
|
||||
|
||||
#include "core/string/ustring.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
|
||||
class QueryBuilder;
|
||||
class TableBuilder;
|
||||
class QueryResult;
|
||||
class Database;
|
||||
|
||||
class DatabaseConnection : public Reference {
|
||||
GDCLASS(DatabaseConnection, Reference);
|
||||
|
||||
public:
|
||||
virtual void database_connect(const String &connection_str);
|
||||
virtual Ref<QueryResult> query(const String &query);
|
||||
virtual void query_run(const String &query);
|
||||
|
||||
virtual Ref<QueryBuilder> get_query_builder();
|
||||
virtual Ref<TableBuilder> get_table_builder();
|
||||
|
||||
virtual String escape(const String &str);
|
||||
virtual void escape_to(const String &str, String *to);
|
||||
|
||||
virtual int get_table_version(const String &table);
|
||||
virtual void set_table_version(const String &table, const int version);
|
||||
virtual void ensure_version_table_exists();
|
||||
|
||||
Ref<Database> get_owner();
|
||||
void set_owner(Database *owner);
|
||||
|
||||
DatabaseConnection();
|
||||
~DatabaseConnection();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
//"WeakRef"
|
||||
//Note: Set this to null if the owner Database gets destroyed!
|
||||
Database *_owner;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,109 +0,0 @@
|
||||
#include "database_manager.h"
|
||||
|
||||
#include "core/object/object.h"
|
||||
#include "database.h"
|
||||
|
||||
Ref<Database> DatabaseManager::get_ddb() {
|
||||
return _ddb;
|
||||
}
|
||||
void DatabaseManager::set_ddb(const Ref<Database> &db) {
|
||||
_ddb = db;
|
||||
emit_signal("default_database_changed", db);
|
||||
}
|
||||
|
||||
void DatabaseManager::add_database(const Ref<Database> &db, bool set_as_default) {
|
||||
ERR_FAIL_COND(!db.is_valid());
|
||||
|
||||
_databases.push_back(db);
|
||||
emit_signal("database_added", db);
|
||||
|
||||
if (set_as_default) {
|
||||
_ddb = db;
|
||||
emit_signal("default_database_changed", db);
|
||||
}
|
||||
}
|
||||
void DatabaseManager::remove_database(const int index, const bool unset_if_default) {
|
||||
ERR_FAIL_INDEX(index, _databases.size());
|
||||
|
||||
Ref<Database> db = _databases[index];
|
||||
|
||||
_databases.remove(index);
|
||||
emit_signal("database_removed", db);
|
||||
|
||||
if (unset_if_default && _ddb == db) {
|
||||
_ddb.unref();
|
||||
emit_signal("default_database_changed", db);
|
||||
}
|
||||
}
|
||||
Ref<Database> DatabaseManager::get_database(const int index) {
|
||||
ERR_FAIL_INDEX_V(index, _databases.size(), Ref<Database>());
|
||||
|
||||
return _databases[index];
|
||||
}
|
||||
int DatabaseManager::get_database_count() {
|
||||
return _databases.size();
|
||||
}
|
||||
|
||||
Vector<Ref<Database>> DatabaseManager::get_databases() {
|
||||
return _databases;
|
||||
}
|
||||
|
||||
Vector<Variant> DatabaseManager::get_databases_bind() {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _databases.size(); i++) {
|
||||
r.push_back(_databases[i].get_ref_ptr());
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
void DatabaseManager::initialized() {
|
||||
emit_signal("initialized");
|
||||
}
|
||||
|
||||
void DatabaseManager::load() {
|
||||
//go thourgh settings, and create all the defined db backends
|
||||
//add them to ProjectSettings
|
||||
}
|
||||
|
||||
void DatabaseManager::migrate(const bool p_clear, const bool p_should_seed, const int p_seed) {
|
||||
emit_signal("migration", p_clear, p_should_seed, p_seed);
|
||||
}
|
||||
|
||||
DatabaseManager *DatabaseManager::get_singleton() {
|
||||
return _instance;
|
||||
}
|
||||
|
||||
DatabaseManager::DatabaseManager() {
|
||||
_instance = this;
|
||||
}
|
||||
|
||||
DatabaseManager::~DatabaseManager() {
|
||||
_instance = nullptr;
|
||||
}
|
||||
|
||||
void DatabaseManager::_bind_methods() {
|
||||
ADD_SIGNAL(MethodInfo("initialized"));
|
||||
ADD_SIGNAL(MethodInfo("migration", PropertyInfo(Variant::BOOL, "clear"), PropertyInfo(Variant::BOOL, "should_seed"), PropertyInfo(Variant::INT, "pseed")));
|
||||
|
||||
ADD_SIGNAL(MethodInfo("default_database_changed", PropertyInfo(Variant::OBJECT, "db", PROPERTY_HINT_RESOURCE_TYPE, "Database")));
|
||||
ADD_SIGNAL(MethodInfo("database_added", PropertyInfo(Variant::OBJECT, "db", PROPERTY_HINT_RESOURCE_TYPE, "Database")));
|
||||
ADD_SIGNAL(MethodInfo("database_removed", PropertyInfo(Variant::OBJECT, "db", PROPERTY_HINT_RESOURCE_TYPE, "Database")));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_ddb"), &DatabaseManager::get_ddb);
|
||||
ClassDB::bind_method(D_METHOD("set_ddb"), &DatabaseManager::set_ddb);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "ddb", PROPERTY_HINT_RESOURCE_TYPE, "Database"), "set_ddb", "get_ddb");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("add_database", "db", "set_as_default"), &DatabaseManager::add_database, true);
|
||||
ClassDB::bind_method(D_METHOD("remove_database", "index", "unset_if_default"), &DatabaseManager::remove_database, true);
|
||||
ClassDB::bind_method(D_METHOD("get_database", "index"), &DatabaseManager::get_database);
|
||||
ClassDB::bind_method(D_METHOD("get_database_count"), &DatabaseManager::get_database_count);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_databases"), &DatabaseManager::get_databases_bind);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("initialized"), &DatabaseManager::initialized);
|
||||
ClassDB::bind_method(D_METHOD("load"), &DatabaseManager::load);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("migrate", "clear", "should_seed", "pseed"), &DatabaseManager::migrate);
|
||||
}
|
||||
|
||||
DatabaseManager *DatabaseManager::_instance = nullptr;
|
@ -1,48 +0,0 @@
|
||||
#ifndef DATABASE_MANAGER_H
|
||||
#define DATABASE_MANAGER_H
|
||||
|
||||
#include "core/object/reference.h"
|
||||
#include "core/string/ustring.h"
|
||||
#include "core/containers/vector.h"
|
||||
|
||||
#include "core/object/object.h"
|
||||
|
||||
class Database;
|
||||
|
||||
class DatabaseManager : public Object {
|
||||
GDCLASS(DatabaseManager, Object);
|
||||
|
||||
public:
|
||||
//ddb = default database
|
||||
Ref<Database> get_ddb();
|
||||
void set_ddb(const Ref<Database> &db);
|
||||
|
||||
void add_database(const Ref<Database> &db, bool set_as_default = true);
|
||||
void remove_database(const int index, const bool unset_if_default = true);
|
||||
Ref<Database> get_database(const int index);
|
||||
int get_database_count();
|
||||
|
||||
Vector<Ref<Database>> get_databases();
|
||||
Vector<Variant> get_databases_bind();
|
||||
|
||||
void initialized();
|
||||
void load();
|
||||
|
||||
void migrate(const bool p_clear, const bool p_should_seed, const int p_seed);
|
||||
|
||||
static DatabaseManager *get_singleton();
|
||||
|
||||
DatabaseManager();
|
||||
~DatabaseManager();
|
||||
|
||||
protected:
|
||||
Vector<Ref<Database>> _databases;
|
||||
Ref<Database> _ddb;
|
||||
|
||||
private:
|
||||
static void _bind_methods();
|
||||
|
||||
static DatabaseManager *_instance;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,60 +0,0 @@
|
||||
#include "database_multi_threaded.h"
|
||||
|
||||
#include "database_connection.h"
|
||||
#include "query_builder.h"
|
||||
#include "query_result.h"
|
||||
#include "table_builder.h"
|
||||
|
||||
Ref<DatabaseConnection> DatabaseMultiThreaded::get_connection() {
|
||||
_connection_map_lock.read_lock();
|
||||
|
||||
Thread::ID tid = Thread::get_caller_id();
|
||||
RBMap<Thread::ID, Ref<DatabaseConnection>>::Element *e;
|
||||
e = _connections.find(tid);
|
||||
|
||||
if (!e) {
|
||||
_connection_map_lock.read_unlock();
|
||||
|
||||
_connection_map_lock.write_lock();
|
||||
Ref<DatabaseConnection> dbc = _allocate_connection();
|
||||
_connections.insert(tid, dbc);
|
||||
_connection_map_lock.write_unlock();
|
||||
|
||||
return dbc;
|
||||
}
|
||||
|
||||
Ref<DatabaseConnection> dbc = e->get();
|
||||
_connection_map_lock.read_unlock();
|
||||
|
||||
return dbc;
|
||||
}
|
||||
|
||||
Ref<DatabaseConnection> DatabaseMultiThreaded::_allocate_connection() {
|
||||
Ref<DatabaseConnection> dbc;
|
||||
dbc.instance();
|
||||
dbc->set_owner(this);
|
||||
dbc->database_connect(_connection_string);
|
||||
return dbc;
|
||||
}
|
||||
|
||||
DatabaseMultiThreaded::DatabaseMultiThreaded() {
|
||||
}
|
||||
|
||||
DatabaseMultiThreaded::~DatabaseMultiThreaded() {
|
||||
_connection_map_lock.write_lock();
|
||||
|
||||
for (RBMap<Thread::ID, Ref<DatabaseConnection>>::Element *e = _connections.front(); e; e = e->next()) {
|
||||
Ref<DatabaseConnection> dbc = e->get();
|
||||
|
||||
if (dbc.is_valid()) {
|
||||
dbc->set_owner(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
_connections.clear();
|
||||
|
||||
_connection_map_lock.write_unlock();
|
||||
}
|
||||
|
||||
void DatabaseMultiThreaded::_bind_methods() {
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
#ifndef DATABASE_MULTI_THREADED_H
|
||||
#define DATABASE_MULTI_THREADED_H
|
||||
|
||||
#include "core/containers/rb_map.h"
|
||||
#include "core/os/rw_lock.h"
|
||||
#include "core/os/thread.h"
|
||||
|
||||
#include "database.h"
|
||||
|
||||
class QueryBuilder;
|
||||
class TableBuilder;
|
||||
class QueryResult;
|
||||
class DatabaseConnection;
|
||||
|
||||
class DatabaseMultiThreaded : public Database {
|
||||
GDCLASS(DatabaseMultiThreaded, Database);
|
||||
|
||||
public:
|
||||
Ref<DatabaseConnection> get_connection();
|
||||
|
||||
DatabaseMultiThreaded();
|
||||
~DatabaseMultiThreaded();
|
||||
|
||||
protected:
|
||||
Ref<DatabaseConnection> _allocate_connection();
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
RWLock _connection_map_lock;
|
||||
RBMap<Thread::ID, Ref<DatabaseConnection>> _connections;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,36 +0,0 @@
|
||||
#include "database_single_threaded.h"
|
||||
|
||||
#include "database_connection.h"
|
||||
#include "query_builder.h"
|
||||
#include "query_result.h"
|
||||
#include "table_builder.h"
|
||||
|
||||
Ref<DatabaseConnection> DatabaseSingleThreaded::get_connection() {
|
||||
if (!_connection.is_valid()) {
|
||||
_connection = _allocate_connection();
|
||||
}
|
||||
|
||||
return _connection;
|
||||
}
|
||||
|
||||
Ref<DatabaseConnection> DatabaseSingleThreaded::_allocate_connection() {
|
||||
Ref<DatabaseConnection> dbc;
|
||||
dbc.instance();
|
||||
dbc->set_owner(this);
|
||||
dbc->database_connect(_connection_string);
|
||||
return dbc;
|
||||
}
|
||||
|
||||
DatabaseSingleThreaded::DatabaseSingleThreaded() {
|
||||
}
|
||||
|
||||
DatabaseSingleThreaded::~DatabaseSingleThreaded() {
|
||||
if (_connection.is_valid()) {
|
||||
_connection->set_owner(nullptr);
|
||||
}
|
||||
|
||||
_connection.unref();
|
||||
}
|
||||
|
||||
void DatabaseSingleThreaded::_bind_methods() {
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
#ifndef DATABASE_SINGLE_THREADED_H
|
||||
#define DATABASE_SINGLE_THREADED_H
|
||||
|
||||
#include "core/string/ustring.h"
|
||||
|
||||
#include "database.h"
|
||||
|
||||
class QueryBuilder;
|
||||
class TableBuilder;
|
||||
class QueryResult;
|
||||
class DatabaseConnection;
|
||||
|
||||
class DatabaseSingleThreaded : public Database {
|
||||
GDCLASS(DatabaseSingleThreaded, Database);
|
||||
|
||||
public:
|
||||
Ref<DatabaseConnection> get_connection();
|
||||
|
||||
DatabaseSingleThreaded();
|
||||
~DatabaseSingleThreaded();
|
||||
|
||||
protected:
|
||||
Ref<DatabaseConnection> _allocate_connection();
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
Ref<DatabaseConnection> _connection;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,22 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="Database" inherits="Reference" version="4.2">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
<method name="get_connection">
|
||||
<return type="DatabaseConnection" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="connection_string" type="String" setter="set_connection_string" getter="get_connection_string" default="""">
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,70 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="DatabaseConnection" inherits="Reference" version="4.2">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
<method name="database_connect">
|
||||
<return type="void" />
|
||||
<argument index="0" name="connection_str" type="String" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="ensure_version_table_exists">
|
||||
<return type="void" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="escape">
|
||||
<return type="String" />
|
||||
<argument index="0" name="str" type="String" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_owner">
|
||||
<return type="Database" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_query_builder">
|
||||
<return type="QueryBuilder" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_table_builder">
|
||||
<return type="TableBuilder" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_table_version">
|
||||
<return type="int" />
|
||||
<argument index="0" name="table" type="String" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="query">
|
||||
<return type="QueryResult" />
|
||||
<argument index="0" name="query" type="String" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="query_run">
|
||||
<return type="void" />
|
||||
<argument index="0" name="query" type="String" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_table_version">
|
||||
<return type="void" />
|
||||
<argument index="0" name="table" type="String" />
|
||||
<argument index="1" name="version" type="int" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,93 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="DatabaseManager" inherits="Object" version="4.2">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
<method name="add_database">
|
||||
<return type="void" />
|
||||
<argument index="0" name="db" type="Database" />
|
||||
<argument index="1" name="set_as_default" type="bool" default="true" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_database">
|
||||
<return type="Database" />
|
||||
<argument index="0" name="index" type="int" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_database_count">
|
||||
<return type="int" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_databases">
|
||||
<return type="Array" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="initialized">
|
||||
<return type="void" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="load">
|
||||
<return type="void" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="migrate">
|
||||
<return type="void" />
|
||||
<argument index="0" name="clear" type="bool" />
|
||||
<argument index="1" name="should_seed" type="bool" />
|
||||
<argument index="2" name="pseed" type="int" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="remove_database">
|
||||
<return type="void" />
|
||||
<argument index="0" name="index" type="int" />
|
||||
<argument index="1" name="unset_if_default" type="bool" default="true" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="ddb" type="Database" setter="set_ddb" getter="get_ddb">
|
||||
</member>
|
||||
</members>
|
||||
<signals>
|
||||
<signal name="database_added">
|
||||
<argument index="0" name="db" type="Database" />
|
||||
<description>
|
||||
</description>
|
||||
</signal>
|
||||
<signal name="database_removed">
|
||||
<argument index="0" name="db" type="Database" />
|
||||
<description>
|
||||
</description>
|
||||
</signal>
|
||||
<signal name="default_database_changed">
|
||||
<argument index="0" name="db" type="Database" />
|
||||
<description>
|
||||
</description>
|
||||
</signal>
|
||||
<signal name="initialized">
|
||||
<description>
|
||||
</description>
|
||||
</signal>
|
||||
<signal name="migration">
|
||||
<argument index="0" name="clear" type="bool" />
|
||||
<argument index="1" name="should_seed" type="bool" />
|
||||
<argument index="2" name="pseed" type="int" />
|
||||
<description>
|
||||
</description>
|
||||
</signal>
|
||||
</signals>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="DatabaseMultiThreaded" inherits="Database" version="4.2">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
</methods>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="DatabaseSingleThreaded" inherits="Database" version="4.2">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
</methods>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,702 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="QueryBuilder" inherits="Reference" version="4.2">
|
||||
<brief_description>
|
||||
A class that helps you with building and running database backend specific sql safely.
|
||||
</brief_description>
|
||||
<description>
|
||||
A class that helps you with building and running database backend specific sql safely.
|
||||
Methods by default use escape on their parameters that can normally contain user input. For performance reasons other variants that don't do this also exist. These are prefixed with 'n'. For example [method select] vs [method nselect]. Don't use these with raw user input, as it will make your application vulnerable to sql injection attacks.
|
||||
It contains helper methods that lets you run the finished query directly See [method run] and [method run_query].
|
||||
You should not allocate this directly, instead get it from you active database connection, like:
|
||||
[codeblock]
|
||||
var conn : DatabaseConnection = DatabaseManager.ddb.get_connection()
|
||||
var qb : QueryBuilder = conn.get_query_builder()
|
||||
[/codeblock]
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
<method name="asc">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="col" type="String" default="""" />
|
||||
<description>
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
if (col.empty()):
|
||||
result += "ASC, "
|
||||
else:
|
||||
result += col + " ASC, "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="begin_transaction">
|
||||
<return type="QueryBuilder" />
|
||||
<description>
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "BEGIN TRANSACTION;"
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="commit">
|
||||
<return type="QueryBuilder" />
|
||||
<description>
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "COMMIT;"
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="corder_by">
|
||||
<return type="QueryBuilder" />
|
||||
<description>
|
||||
Closes the current [code]ORDER BY[/code] statement. (Usually by removing the last [code],[/code]).
|
||||
</description>
|
||||
</method>
|
||||
<method name="cset">
|
||||
<return type="QueryBuilder" />
|
||||
<description>
|
||||
Closes the current [code]SET[/code] statement. (Usually by removing the last [code],[/code]).
|
||||
</description>
|
||||
</method>
|
||||
<method name="cstr">
|
||||
<return type="QueryBuilder" />
|
||||
<description>
|
||||
Closes the current string. (Usually by adding a [code]'[/code]).
|
||||
</description>
|
||||
</method>
|
||||
<method name="cvalues">
|
||||
<return type="QueryBuilder" />
|
||||
<description>
|
||||
Closes the current [code]VALUES[/code] statement. (Usually by replacing the last [code],[/code] with a [code])[/code]).
|
||||
</description>
|
||||
</method>
|
||||
<method name="del">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="params" type="String" default="""" />
|
||||
<description>
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "DELETE FROM " + escape(params) + " "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="desc">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="col" type="String" default="""" />
|
||||
<description>
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
if (col.empty()):
|
||||
result += "DESC, "
|
||||
else:
|
||||
result += col + " DESC, "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="end_command">
|
||||
<return type="QueryBuilder" />
|
||||
<description>
|
||||
Closes the current sql command. (Usually by adding a [code];[/code]).
|
||||
</description>
|
||||
</method>
|
||||
<method name="escape">
|
||||
<return type="String" />
|
||||
<argument index="0" name="param" type="String" />
|
||||
<description>
|
||||
Escapes the given string and returns it. (Using the database connector's escape method.)
|
||||
</description>
|
||||
</method>
|
||||
<method name="ew">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="str" type="String" />
|
||||
<description>
|
||||
(ew = escape write)
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += escape(str)
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="from">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="params" type="String" default="""" />
|
||||
<description>
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "FROM "
|
||||
|
||||
if (!params.empty()):
|
||||
result += escape(params)
|
||||
result += " "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="insert">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="table_name" type="String" default="""" />
|
||||
<argument index="1" name="columns" type="String" default="""" />
|
||||
<description>
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "INSERT INTO ";
|
||||
|
||||
if (!table_name.empty()):
|
||||
result += table_name
|
||||
result += " "
|
||||
|
||||
if (!columns.empty()):
|
||||
result += "("
|
||||
result += columns
|
||||
result += ") "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="land">
|
||||
<return type="QueryBuilder" />
|
||||
<description>
|
||||
(land = logical and)
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "AND "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="like">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="str" type="String" default="""" />
|
||||
<description>
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
if (str.empty()):
|
||||
result += "LIKE "
|
||||
else:
|
||||
result += "LIKE '" + escape(str) + "' "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="limit">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="num" type="int" />
|
||||
<description>
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "LIMIT " + itos(num) + " "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="lor">
|
||||
<return type="QueryBuilder" />
|
||||
<description>
|
||||
(lor = logical or)
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "OR "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="ndel">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="params" type="String" />
|
||||
<description>
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "DELETE FROM " + params + " "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="next_value">
|
||||
<return type="QueryBuilder" />
|
||||
<description>
|
||||
Closes the current [code]VALUES[/code] statement, and then open an another one. (Usually by replacing the last [code],[/code] with [code]"), ("[/code]).
|
||||
</description>
|
||||
</method>
|
||||
<method name="nfrom">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="params" type="String" />
|
||||
<description>
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "FROM "
|
||||
|
||||
if (!params.empty()):
|
||||
result += params + " "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="nl">
|
||||
<return type="QueryBuilder" />
|
||||
<description>
|
||||
Adds a newline. This can help when debugging sql statements. (Usually [code]\n[/code]).
|
||||
</description>
|
||||
</method>
|
||||
<method name="nlike">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="str" type="String" />
|
||||
<description>
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "LIKE '" + str + "' "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="nselect">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="params" type="String" />
|
||||
<description>
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "SELECT " + params + " "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="nsetp">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="col" type="String" />
|
||||
<argument index="1" name="escape_param" type="String" />
|
||||
<description>
|
||||
Add parameters to [code]UPDATE[/code] statements.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += col + "='" + params + "', "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="nupdate">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="params" type="String" />
|
||||
<description>
|
||||
Start an [code]UPDATE[/code] statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "UPDATE " + params + " "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="nval">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="param" type="String" />
|
||||
<description>
|
||||
Add parameters to [code]INSERT INTO[/code] statements.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "'" + param + "', "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="nvalues">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="params_str" type="String" />
|
||||
<description>
|
||||
Adds an unescaped [code]VALUES[/code] statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "VALUES("
|
||||
|
||||
if (!params_str.empty()):
|
||||
result += params_str + ") "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="nwhere">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="params" type="String" />
|
||||
<description>
|
||||
Adds an unescaped [code]WHERE[/code] statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "WHERE "
|
||||
|
||||
if (!params.empty()):
|
||||
result += params + " "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="nwp">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="col" type="String" />
|
||||
<argument index="1" name="escape_param" type="String" />
|
||||
<description>
|
||||
Add an unescaped parameter to [code]WHERE[/code] statements.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += col + "='" + params + "' "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="offset">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="num" type="int" />
|
||||
<description>
|
||||
Adds an [code]OFFSET[/code] statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "OFFSET " + str(num) + " "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="order_by">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="col" type="String" />
|
||||
<description>
|
||||
Adds an [code]ORDER BY[/code] statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
if (col.empty()):
|
||||
result += "ORDER BY "
|
||||
else:
|
||||
result += "ORDER BY " + col + ", "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="order_by_add_col">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="col" type="String" />
|
||||
<description>
|
||||
Adds a column to an [code]ORDER BY[/code] statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += col + ", "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="order_by_asc">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="col" type="String" />
|
||||
<description>
|
||||
Adds an [code]ORDER BY ASC[/code] statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "ORDER BY " + col + " ASC, ";
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="order_by_desc">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="col" type="String" />
|
||||
<description>
|
||||
Adds an [code]ORDER BY DESC[/code] statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "ORDER BY " + col + " DESC, ";
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="prepare">
|
||||
<return type="QueryBuilder" />
|
||||
<description>
|
||||
Part of the unfinished prepared statement api.
|
||||
</description>
|
||||
</method>
|
||||
<method name="reset">
|
||||
<return type="QueryBuilder" />
|
||||
<description>
|
||||
Resets the QueryBuilder.
|
||||
</description>
|
||||
</method>
|
||||
<method name="run">
|
||||
<return type="QueryResult" />
|
||||
<description>
|
||||
Run the query currently stored in the result property.
|
||||
Use this if your query returns values from the database (an you want to read them).
|
||||
</description>
|
||||
</method>
|
||||
<method name="run_query">
|
||||
<return type="void" />
|
||||
<description>
|
||||
Run the query currently stored in the result property.
|
||||
Use this if your query doesn't return values from the database (or you don't want to read them if it does).
|
||||
</description>
|
||||
</method>
|
||||
<method name="select">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="params" type="String" default="""" />
|
||||
<description>
|
||||
Adds a [code]SELECT[/code] statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += SELECT " + escape(params) + " "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="select_last_insert_id">
|
||||
<return type="QueryBuilder" />
|
||||
<description>
|
||||
Adds a statement to select and return the last inserted row's id.
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_paramf">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="index" type="int" />
|
||||
<argument index="1" name="value" type="float" />
|
||||
<description>
|
||||
Part of the unfinished prepared statement api.
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_parami">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="index" type="int" />
|
||||
<argument index="1" name="value" type="int" />
|
||||
<description>
|
||||
Part of the unfinished prepared statement api.
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_params">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="index" type="int" />
|
||||
<argument index="1" name="value" type="String" />
|
||||
<description>
|
||||
Part of the unfinished prepared statement api.
|
||||
</description>
|
||||
</method>
|
||||
<method name="setpb">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="col" type="String" />
|
||||
<argument index="1" name="param" type="bool" />
|
||||
<description>
|
||||
Add a bool parameter to [code]UPDATE[/code] statements.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
if (param):
|
||||
result += col + "=1, "
|
||||
else:
|
||||
result += col + "=0, "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="setpd">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="col" type="String" />
|
||||
<argument index="1" name="param" type="float" />
|
||||
<description>
|
||||
Add a double parameter to [code]UPDATE[/code] statements.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += col + "=" + str(param) + ", "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="setpf">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="col" type="String" />
|
||||
<argument index="1" name="param" type="float" />
|
||||
<description>
|
||||
Add a float parameter to [code]UPDATE[/code] statements.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += col + "=" + str(param) + ", "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="setpi">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="col" type="String" />
|
||||
<argument index="1" name="param" type="int" />
|
||||
<description>
|
||||
Add an int parameter to [code]UPDATE[/code] statements.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += col + "=" + str(param) + ", "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="setps">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="col" type="String" />
|
||||
<argument index="1" name="param" type="String" />
|
||||
<description>
|
||||
Add an escaped string parameter to [code]UPDATE[/code] statements.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += col + "=" + escape(param) + ", "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="sets">
|
||||
<return type="QueryBuilder" />
|
||||
<description>
|
||||
Starts a [code]SET[/code] statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "SET "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="str">
|
||||
<return type="QueryBuilder" />
|
||||
<description>
|
||||
Starts a string. (Usually by adding a [code]'[/code]).
|
||||
</description>
|
||||
</method>
|
||||
<method name="update">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="params" type="String" default="""" />
|
||||
<description>
|
||||
Starts an [code]UPDATE[/code] statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "UPDATE " + escape(params) + " "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="val">
|
||||
<return type="QueryBuilder" />
|
||||
<description>
|
||||
Adds [code]DEFAULT[/code] to a [code]VALUES[/code] statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "DEFAULT, "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="valb">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="param" type="bool" />
|
||||
<description>
|
||||
Add a bool parameter to a [code]VALUES[/code] statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
if (param):
|
||||
result += "1, "
|
||||
else:
|
||||
result += "0, "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="vald">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="param" type="float" />
|
||||
<description>
|
||||
Add a double parameter to a [code]VALUES[/code] statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += str(param) + ", "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="valf">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="param" type="float" />
|
||||
<description>
|
||||
Add a float parameter to a [code]VALUES[/code] statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += str(param) + ", "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="vali">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="param" type="int" />
|
||||
<description>
|
||||
Add an int parameter to a [code]VALUES[/code] statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += str(param) + ", "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="vals">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="param" type="String" />
|
||||
<description>
|
||||
Add an escaped string parameter to a [code]VALUES[/code] statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += escape(param) + ", "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="values">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="params_str" type="String" default="""" />
|
||||
<description>
|
||||
Adds an escaped [code]VALUES[/code] statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "VALUES("
|
||||
|
||||
if (!params_str.empty()):
|
||||
result += escape(params_str) + ") "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="w">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="str" type="String" />
|
||||
<description>
|
||||
(w = write)
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += str
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="where">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="params" type="String" default="""" />
|
||||
<description>
|
||||
Adds an escaped [code]WHERE[/code] statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "WHERE "
|
||||
|
||||
if (!params.empty()):
|
||||
result += escape(params) + " "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="wildcard">
|
||||
<return type="QueryBuilder" />
|
||||
<description>
|
||||
Gets the wildcard character for the given database backend. (Usually [code]%[/code].)
|
||||
</description>
|
||||
</method>
|
||||
<method name="wpb">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="col" type="String" />
|
||||
<argument index="1" name="param" type="bool" />
|
||||
<description>
|
||||
Add a bool parameter to a [code]WHERE[/code] statement. (wpb = where param bool)
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
if (param):
|
||||
result += col + "=1 "
|
||||
else:
|
||||
result += col + "=0 "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="wpi">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="col" type="String" />
|
||||
<argument index="1" name="param" type="int" />
|
||||
<description>
|
||||
Add an int parameter to a [code]WHERE[/code] statement. (wpi = where param int)
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += col + "=" + str(param) + " "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="wps">
|
||||
<return type="QueryBuilder" />
|
||||
<argument index="0" name="col" type="String" />
|
||||
<argument index="1" name="param" type="String" />
|
||||
<description>
|
||||
Add an escaped string parameter to a [code]WHERE[/code] statement. (wps = where param string)
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += col + "='" + escape(param) + "' "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="result" type="String" setter="set_result" getter="get_result" default="""">
|
||||
The current (resulting) sql statement.
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,64 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="QueryResult" inherits="Reference" version="4.2">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
<method name="get_cell">
|
||||
<return type="String" />
|
||||
<argument index="0" name="index" type="int" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_cell_bool">
|
||||
<return type="bool" />
|
||||
<argument index="0" name="index" type="int" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_cell_double">
|
||||
<return type="float" />
|
||||
<argument index="0" name="index" type="int" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_cell_float">
|
||||
<return type="float" />
|
||||
<argument index="0" name="index" type="int" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_cell_int">
|
||||
<return type="int" />
|
||||
<argument index="0" name="index" type="int" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_error_message">
|
||||
<return type="String" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_last_insert_rowid">
|
||||
<return type="int" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="is_cell_null">
|
||||
<return type="bool" />
|
||||
<argument index="0" name="index" type="int" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
<method name="next_row">
|
||||
<return type="bool" />
|
||||
<description>
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,290 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="TableBuilder" inherits="Reference" version="4.2">
|
||||
<brief_description>
|
||||
A class that helps you with building and running database backend specific sql for creating / altering / deleting tables.
|
||||
</brief_description>
|
||||
<description>
|
||||
A class that helps you with building and running database backend specific sql for creating / altering / deleting tables.
|
||||
It contains helper methods that lets you run the finished query directly See [method run] and [method run_query].
|
||||
You should not allocate this directly, instead get it from you active database connection, like:
|
||||
[codeblock]
|
||||
var conn : DatabaseConnection = DatabaseManager.ddb.get_connection()
|
||||
var tb : TableBuilder = conn.get_table_builder()
|
||||
[/codeblock]
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
<method name="auto_increment">
|
||||
<return type="TableBuilder" />
|
||||
<description>
|
||||
Adds an [code]AUTO_INCREMENT[/code] statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "AUTO_INCREMENT "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="ccreate_table">
|
||||
<return type="TableBuilder" />
|
||||
<description>
|
||||
Closes a [code]CREATE TABLE[/code] statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += ");"
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="cdrop_table">
|
||||
<return type="TableBuilder" />
|
||||
<description>
|
||||
Closes a [code]DROP TABLE[/code] statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += ";"
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="create_table">
|
||||
<return type="TableBuilder" />
|
||||
<argument index="0" name="value" type="String" />
|
||||
<description>
|
||||
Adds a [code]CREATE TABLE[/code] statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "CREATE TABLE " + name + " ( "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="date">
|
||||
<return type="TableBuilder" />
|
||||
<argument index="0" name="name" type="String" />
|
||||
<description>
|
||||
Adds a [code]DATE[/code] field statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += name + " DATE "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="defval">
|
||||
<return type="TableBuilder" />
|
||||
<argument index="0" name="val" type="String" />
|
||||
<description>
|
||||
Adds a [code]DEFAULT[/code] statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "DEFAULT '" + val + "'"
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="drop_table">
|
||||
<return type="TableBuilder" />
|
||||
<argument index="0" name="name" type="String" default="""" />
|
||||
<description>
|
||||
Adds a [code]DROP TABLE[/code] statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "DROP TABLE "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="drop_table_if_exists">
|
||||
<return type="TableBuilder" />
|
||||
<argument index="0" name="name" type="String" default="""" />
|
||||
<description>
|
||||
Adds a [code]DROP TABLE IF EXISTS[/code] statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "DROP TABLE IF EXISTS "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="foreign_key">
|
||||
<return type="TableBuilder" />
|
||||
<argument index="0" name="name" type="String" />
|
||||
<description>
|
||||
Adds a [code]FOREIGN KEY[/code] statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "FOREIGN KEY (" + name + ") "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="integer">
|
||||
<return type="TableBuilder" />
|
||||
<argument index="0" name="name" type="String" />
|
||||
<argument index="1" name="length" type="int" default="-1" />
|
||||
<description>
|
||||
Adds an [code]INTEGER[/code] field statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += name + " INTEGER ";
|
||||
|
||||
if (length != -1):
|
||||
result += "(" + str(length) + ") "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="next_row">
|
||||
<return type="TableBuilder" />
|
||||
<description>
|
||||
Go the the next row (field) in the current sql statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += ", "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="not_null">
|
||||
<return type="TableBuilder" />
|
||||
<description>
|
||||
Adds a [code]NOT NULL[/code] statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "NOT NULL "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="null">
|
||||
<return type="TableBuilder" />
|
||||
<description>
|
||||
Adds a [code]NULL[/code] statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "NULL "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="primary_key">
|
||||
<return type="TableBuilder" />
|
||||
<argument index="0" name="name" type="String" default="""" />
|
||||
<description>
|
||||
Adds a [code]PRIMARY KEY[/code] statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += "PRIMARY KEY (" + name + ") "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="real_double">
|
||||
<return type="TableBuilder" />
|
||||
<argument index="0" name="name" type="String" />
|
||||
<argument index="1" name="size" type="int" default="-1" />
|
||||
<argument index="2" name="d" type="int" default="-1" />
|
||||
<description>
|
||||
Adds an [code]DOUBLE[/code] field statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += name + " DOUBLE "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="real_float">
|
||||
<return type="TableBuilder" />
|
||||
<argument index="0" name="name" type="String" />
|
||||
<argument index="1" name="size" type="int" default="-1" />
|
||||
<argument index="2" name="d" type="int" default="-1" />
|
||||
<description>
|
||||
Adds an [code]FLOAT[/code] field statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += name + " FLOAT "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="references">
|
||||
<return type="TableBuilder" />
|
||||
<argument index="0" name="table" type="String" />
|
||||
<argument index="1" name="name" type="String" />
|
||||
<description>
|
||||
result += "REFERENCES " + table + " (" + name + ") ";
|
||||
</description>
|
||||
</method>
|
||||
<method name="run">
|
||||
<return type="QueryResult" />
|
||||
<description>
|
||||
Run the query currently stored in the result property.
|
||||
Use this if your query returns values from the database (an you want to read them).
|
||||
</description>
|
||||
</method>
|
||||
<method name="run_query">
|
||||
<return type="void" />
|
||||
<description>
|
||||
Run the query currently stored in the result property.
|
||||
Use this if your query doesn't return values from the database (or you don't want to read them if it does).
|
||||
</description>
|
||||
</method>
|
||||
<method name="small_integer">
|
||||
<return type="TableBuilder" />
|
||||
<argument index="0" name="name" type="String" />
|
||||
<argument index="1" name="length" type="int" default="-1" />
|
||||
<description>
|
||||
Adds a [code]SMALL INTEGER[/code] field statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += name + " INTEGER("
|
||||
|
||||
if (length == -1):
|
||||
result += "6"
|
||||
else:
|
||||
result += itos(length)
|
||||
|
||||
result += ") "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="text">
|
||||
<return type="TableBuilder" />
|
||||
<argument index="0" name="name" type="String" />
|
||||
<description>
|
||||
Adds a [code]TEXT[/code] field statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += name + " TEXT "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="tiny_integer">
|
||||
<return type="TableBuilder" />
|
||||
<argument index="0" name="name" type="String" />
|
||||
<argument index="1" name="length" type="int" default="-1" />
|
||||
<description>
|
||||
Adds a [code]TINY INTEGER[/code] field statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += name + " INTEGER("
|
||||
|
||||
if (length == -1):
|
||||
result += "4"
|
||||
else:
|
||||
result += itos(length)
|
||||
|
||||
result += ") "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
<method name="varchar">
|
||||
<return type="TableBuilder" />
|
||||
<argument index="0" name="name" type="String" />
|
||||
<argument index="1" name="length" type="int" default="-1" />
|
||||
<description>
|
||||
Adds a [code]VARCHAR[/code] field statement.
|
||||
Equivalent to:
|
||||
[codeblock]
|
||||
result += name + " VARCHAR ";
|
||||
|
||||
if (length != -1):
|
||||
result += "(" + str(length) + ") "
|
||||
[/codeblock]
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
<members>
|
||||
<member name="result" type="String" setter="set_result" getter="get_result" default="""">
|
||||
The current (resulting) sql statement.
|
||||
</member>
|
||||
</members>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,605 +0,0 @@
|
||||
#include "query_builder.h"
|
||||
|
||||
#include "query_result.h"
|
||||
|
||||
String QueryBuilder::get_result() {
|
||||
return query_result;
|
||||
}
|
||||
void QueryBuilder::set_result(const String &val) {
|
||||
query_result = val;
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::select() {
|
||||
return this;
|
||||
}
|
||||
QueryBuilder *QueryBuilder::update() {
|
||||
return this;
|
||||
}
|
||||
QueryBuilder *QueryBuilder::del() {
|
||||
return this;
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::cvalues() {
|
||||
return this;
|
||||
}
|
||||
QueryBuilder *QueryBuilder::next_value() {
|
||||
return this;
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::begin_transaction() {
|
||||
return this;
|
||||
}
|
||||
QueryBuilder *QueryBuilder::commit() {
|
||||
return this;
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::nl() {
|
||||
query_result += "\n";
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::str() {
|
||||
return this;
|
||||
}
|
||||
QueryBuilder *QueryBuilder::cstr() {
|
||||
return this;
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::select(const String ¶ms) {
|
||||
return nselect(escape(params));
|
||||
}
|
||||
QueryBuilder *QueryBuilder::update(const String ¶ms) {
|
||||
return nupdate(escape(params));
|
||||
}
|
||||
QueryBuilder *QueryBuilder::del(const String ¶ms) {
|
||||
return ndel(escape(params));
|
||||
}
|
||||
QueryBuilder *QueryBuilder::where(const String ¶ms) {
|
||||
return nwhere(escape(params));
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::from(const String ¶ms) {
|
||||
return nfrom(escape(params));
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::insert(const String &table_name, const String &columns) {
|
||||
return this;
|
||||
}
|
||||
QueryBuilder *QueryBuilder::values(const String ¶ms_str) {
|
||||
return nvalues(escape(params_str));
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::val() {
|
||||
return this;
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::vals(const String ¶m) {
|
||||
return nval(escape(param));
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::vals(const char *param) {
|
||||
return this;
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::vali(const int param) {
|
||||
return this;
|
||||
}
|
||||
QueryBuilder *QueryBuilder::valb(const bool param) {
|
||||
return this;
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::valf(const float param) {
|
||||
return this;
|
||||
}
|
||||
QueryBuilder *QueryBuilder::vald(const double param) {
|
||||
return this;
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::like(const String &str) {
|
||||
return nlike(escape(str));
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::sets() {
|
||||
return this;
|
||||
}
|
||||
QueryBuilder *QueryBuilder::cset() {
|
||||
return this;
|
||||
}
|
||||
QueryBuilder *QueryBuilder::setps(const String &col, const String ¶m) {
|
||||
return nsetp(col, escape(param));
|
||||
}
|
||||
QueryBuilder *QueryBuilder::setps(const String &col, const char *param) {
|
||||
return this;
|
||||
}
|
||||
QueryBuilder *QueryBuilder::setpi(const String &col, const int param) {
|
||||
return this;
|
||||
}
|
||||
QueryBuilder *QueryBuilder::setpb(const String &col, const bool param) {
|
||||
return this;
|
||||
}
|
||||
QueryBuilder *QueryBuilder::setpf(const String &col, const float param) {
|
||||
return this;
|
||||
}
|
||||
QueryBuilder *QueryBuilder::setpd(const String &col, const double param) {
|
||||
return this;
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::wps(const String &col, const String ¶m) {
|
||||
return nwp(col, escape(param));
|
||||
}
|
||||
QueryBuilder *QueryBuilder::wps(const String &col, const char *param) {
|
||||
return this;
|
||||
}
|
||||
QueryBuilder *QueryBuilder::wpi(const String &col, const int param) {
|
||||
return this;
|
||||
}
|
||||
QueryBuilder *QueryBuilder::wpb(const String &col, const bool param) {
|
||||
return this;
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::nselect(const String ¶ms) {
|
||||
return this;
|
||||
}
|
||||
QueryBuilder *QueryBuilder::nupdate(const String ¶ms) {
|
||||
return this;
|
||||
}
|
||||
QueryBuilder *QueryBuilder::ndel(const String ¶ms) {
|
||||
return this;
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::nwhere(const String ¶ms) {
|
||||
return this;
|
||||
}
|
||||
QueryBuilder *QueryBuilder::nfrom(const String ¶ms) {
|
||||
return this;
|
||||
}
|
||||
QueryBuilder *QueryBuilder::nlike(const String &str) {
|
||||
return this;
|
||||
}
|
||||
QueryBuilder *QueryBuilder::nvalues(const String ¶ms_str) {
|
||||
return this;
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::nval(const String ¶m) {
|
||||
return this;
|
||||
}
|
||||
QueryBuilder *QueryBuilder::nsetp(const String &col, const String &escape_param) {
|
||||
return this;
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::nwp(const String &col, const String &escape_param) {
|
||||
return this;
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::limit(const int num) {
|
||||
return this;
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::offset(const int num) {
|
||||
return this;
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::order_by_asc(const String &col) {
|
||||
query_result += "ORDER BY " + col + " ASC, ";
|
||||
|
||||
return this;
|
||||
}
|
||||
QueryBuilder *QueryBuilder::order_by_desc(const String &col) {
|
||||
query_result += "ORDER BY " + col + " DESC, ";
|
||||
|
||||
return this;
|
||||
}
|
||||
QueryBuilder *QueryBuilder::order_by(const String &col) {
|
||||
if (col.empty()) {
|
||||
query_result += "ORDER BY ";
|
||||
} else {
|
||||
query_result += "ORDER BY " + col + ", ";
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::corder_by() {
|
||||
ERR_FAIL_COND_V(query_result.length() <= 2, this);
|
||||
|
||||
query_result[query_result.length() - 2] = ' ';
|
||||
|
||||
return this;
|
||||
}
|
||||
QueryBuilder *QueryBuilder::order_by_add_col(const String &col) {
|
||||
query_result += col + ", ";
|
||||
|
||||
return this;
|
||||
}
|
||||
QueryBuilder *QueryBuilder::asc(const String &col) {
|
||||
if (col.empty()) {
|
||||
query_result += "ASC, ";
|
||||
} else {
|
||||
query_result += col + " ASC, ";
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
QueryBuilder *QueryBuilder::desc(const String &col) {
|
||||
if (col.empty()) {
|
||||
query_result += "DESC, ";
|
||||
} else {
|
||||
query_result += col + " DESC, ";
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::land() {
|
||||
return this;
|
||||
}
|
||||
QueryBuilder *QueryBuilder::lor() {
|
||||
return this;
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::wildcard() {
|
||||
return this;
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::w(const String &str) {
|
||||
query_result += str;
|
||||
|
||||
return this;
|
||||
}
|
||||
QueryBuilder *QueryBuilder::ew(const String &str) {
|
||||
return w(escape(str));
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::select_last_insert_id() {
|
||||
return this;
|
||||
}
|
||||
|
||||
String QueryBuilder::escape(const String ¶ms) {
|
||||
return params;
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::prepare() {
|
||||
return this;
|
||||
}
|
||||
QueryBuilder *QueryBuilder::set_params(const int index, const String &value) {
|
||||
return this;
|
||||
}
|
||||
QueryBuilder *QueryBuilder::set_parami(const int index, const int value) {
|
||||
return this;
|
||||
}
|
||||
QueryBuilder *QueryBuilder::set_paramf(const int index, const float value) {
|
||||
return this;
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::end_command() {
|
||||
return this;
|
||||
}
|
||||
|
||||
QueryBuilder *QueryBuilder::reset() {
|
||||
query_result = "";
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
Ref<QueryResult> QueryBuilder::run() {
|
||||
return Ref<QueryResult>();
|
||||
}
|
||||
|
||||
void QueryBuilder::run_query() {
|
||||
}
|
||||
|
||||
void QueryBuilder::print() {
|
||||
//printf("%s\n", query_result.get_data());
|
||||
ERR_PRINT(query_result);
|
||||
}
|
||||
|
||||
QueryBuilder::QueryBuilder() {
|
||||
}
|
||||
|
||||
QueryBuilder::~QueryBuilder() {
|
||||
}
|
||||
|
||||
void QueryBuilder::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_result"), &QueryBuilder::get_result);
|
||||
ClassDB::bind_method(D_METHOD("set_result", "value"), &QueryBuilder::set_result);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "result"), "set_result", "get_result");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("cvalues"), &QueryBuilder::_cvalues_bind);
|
||||
ClassDB::bind_method(D_METHOD("next_value"), &QueryBuilder::_next_value_bind);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("begin_transaction"), &QueryBuilder::_begin_transaction_bind);
|
||||
ClassDB::bind_method(D_METHOD("commit"), &QueryBuilder::_commit_bind);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("nl"), &QueryBuilder::_nl_bind);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("str"), &QueryBuilder::_str_bind);
|
||||
ClassDB::bind_method(D_METHOD("cstr"), &QueryBuilder::_cstr_bind);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("select", "params"), &QueryBuilder::_select_bind, "");
|
||||
ClassDB::bind_method(D_METHOD("update", "params"), &QueryBuilder::_update_bind, "");
|
||||
ClassDB::bind_method(D_METHOD("del", "params"), &QueryBuilder::_del_bind, "");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("where", "params"), &QueryBuilder::_where_bind, "");
|
||||
ClassDB::bind_method(D_METHOD("from", "params"), &QueryBuilder::_from_bind, "");
|
||||
ClassDB::bind_method(D_METHOD("insert", "table_name", "columns"), &QueryBuilder::_insert_bind, "", "");
|
||||
ClassDB::bind_method(D_METHOD("values", "params_str"), &QueryBuilder::_values_bind, "");
|
||||
ClassDB::bind_method(D_METHOD("val"), &QueryBuilder::_val_bind);
|
||||
ClassDB::bind_method(D_METHOD("vals", "param"), &QueryBuilder::_vals_bind);
|
||||
ClassDB::bind_method(D_METHOD("vali", "param"), &QueryBuilder::_vali_bind);
|
||||
ClassDB::bind_method(D_METHOD("valb", "param"), &QueryBuilder::_valb_bind);
|
||||
ClassDB::bind_method(D_METHOD("valf", "param"), &QueryBuilder::_valf_bind);
|
||||
ClassDB::bind_method(D_METHOD("vald", "param"), &QueryBuilder::_vald_bind);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("like", "str"), &QueryBuilder::_like_bind, "");
|
||||
ClassDB::bind_method(D_METHOD("sets"), &QueryBuilder::_sets_bind);
|
||||
ClassDB::bind_method(D_METHOD("cset"), &QueryBuilder::_cset_bind);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("setps", "col", "param"), &QueryBuilder::_setps_bind);
|
||||
ClassDB::bind_method(D_METHOD("setpi", "col", "param"), &QueryBuilder::_setpi_bind);
|
||||
ClassDB::bind_method(D_METHOD("setpb", "col", "param"), &QueryBuilder::_setpb_bind);
|
||||
ClassDB::bind_method(D_METHOD("setpf", "col", "param"), &QueryBuilder::_setpf_bind);
|
||||
ClassDB::bind_method(D_METHOD("setpd", "col", "param"), &QueryBuilder::_setpd_bind);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("wps", "col", "param"), &QueryBuilder::_wps_bind);
|
||||
ClassDB::bind_method(D_METHOD("wpi", "col", "param"), &QueryBuilder::_wpi_bind);
|
||||
ClassDB::bind_method(D_METHOD("wpb", "col", "param"), &QueryBuilder::_wpb_bind);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("nselect", "params"), &QueryBuilder::_nselect_bind);
|
||||
ClassDB::bind_method(D_METHOD("nupdate", "params"), &QueryBuilder::_nupdate_bind);
|
||||
ClassDB::bind_method(D_METHOD("ndel", "params"), &QueryBuilder::_ndel_bind);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("nwhere", "params"), &QueryBuilder::_nwhere_bind);
|
||||
ClassDB::bind_method(D_METHOD("nfrom", "params"), &QueryBuilder::_nfrom_bind);
|
||||
ClassDB::bind_method(D_METHOD("nlike", "str"), &QueryBuilder::_nlike_bind);
|
||||
ClassDB::bind_method(D_METHOD("nvalues", "params_str"), &QueryBuilder::_nvalues_bind);
|
||||
ClassDB::bind_method(D_METHOD("nval", "param"), &QueryBuilder::_nval_bind);
|
||||
ClassDB::bind_method(D_METHOD("nsetp", "col", "escape_param"), &QueryBuilder::_nsetp_bind);
|
||||
ClassDB::bind_method(D_METHOD("nwp", "col", "escape_param"), &QueryBuilder::_nwp_bind);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("limit", "num"), &QueryBuilder::_limit_bind);
|
||||
ClassDB::bind_method(D_METHOD("offset", "num"), &QueryBuilder::_offset_bind);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("order_by_asc", "col"), &QueryBuilder::_order_by_asc_bind);
|
||||
ClassDB::bind_method(D_METHOD("order_by_desc", "col"), &QueryBuilder::_order_by_desc_bind);
|
||||
ClassDB::bind_method(D_METHOD("order_by", "col"), &QueryBuilder::_order_by_bind);
|
||||
ClassDB::bind_method(D_METHOD("corder_by"), &QueryBuilder::_corder_by_bind);
|
||||
ClassDB::bind_method(D_METHOD("order_by_add_col", "col"), &QueryBuilder::_order_by_add_col_bind);
|
||||
ClassDB::bind_method(D_METHOD("asc", "col"), &QueryBuilder::_asc_bind, "");
|
||||
ClassDB::bind_method(D_METHOD("desc", "col"), &QueryBuilder::_desc_bind, "");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("land"), &QueryBuilder::_land_bind);
|
||||
ClassDB::bind_method(D_METHOD("lor"), &QueryBuilder::_lor_bind);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("wildcard"), &QueryBuilder::_wildcard_bind);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("w", "str"), &QueryBuilder::_w_bind);
|
||||
ClassDB::bind_method(D_METHOD("ew", "str"), &QueryBuilder::_ew_bind);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("select_last_insert_id"), &QueryBuilder::_select_last_insert_id_bind);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("escape", "param"), &QueryBuilder::escape);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("prepare"), &QueryBuilder::_prepare_bind);
|
||||
ClassDB::bind_method(D_METHOD("set_params", "index", "value"), &QueryBuilder::_set_params_bind);
|
||||
ClassDB::bind_method(D_METHOD("set_parami", "index", "value"), &QueryBuilder::_set_parami_bind);
|
||||
ClassDB::bind_method(D_METHOD("set_paramf", "index", "value"), &QueryBuilder::_set_paramf_bind);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("end_command"), &QueryBuilder::_end_command_bind);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("reset"), &QueryBuilder::_reset_bind);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("run"), &QueryBuilder::run);
|
||||
ClassDB::bind_method(D_METHOD("run_query"), &QueryBuilder::run_query);
|
||||
}
|
||||
|
||||
Ref<QueryBuilder> QueryBuilder::_cvalues_bind() {
|
||||
return Ref<QueryBuilder>(cvalues());
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_next_value_bind() {
|
||||
return Ref<QueryBuilder>(next_value());
|
||||
}
|
||||
|
||||
Ref<QueryBuilder> QueryBuilder::_begin_transaction_bind() {
|
||||
return Ref<QueryBuilder>(begin_transaction());
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_commit_bind() {
|
||||
return Ref<QueryBuilder>(commit());
|
||||
}
|
||||
|
||||
Ref<QueryBuilder> QueryBuilder::_nl_bind() {
|
||||
return Ref<QueryBuilder>(nl());
|
||||
}
|
||||
|
||||
Ref<QueryBuilder> QueryBuilder::_str_bind() {
|
||||
return Ref<QueryBuilder>(str());
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_cstr_bind() {
|
||||
return Ref<QueryBuilder>(cstr());
|
||||
}
|
||||
|
||||
Ref<QueryBuilder> QueryBuilder::_select_bind(const String ¶ms) {
|
||||
return Ref<QueryBuilder>(select(params));
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_update_bind(const String ¶ms) {
|
||||
return Ref<QueryBuilder>(update(params));
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_del_bind(const String ¶ms) {
|
||||
return Ref<QueryBuilder>(del(params));
|
||||
}
|
||||
|
||||
Ref<QueryBuilder> QueryBuilder::_where_bind(const String ¶ms) {
|
||||
return Ref<QueryBuilder>(where(params));
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_from_bind(const String ¶ms) {
|
||||
return Ref<QueryBuilder>(from(params));
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_insert_bind(const String &table_name, const String &columns) {
|
||||
return Ref<QueryBuilder>(insert(table_name, columns));
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_values_bind(const String ¶ms_str) {
|
||||
return Ref<QueryBuilder>(values(params_str));
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_val_bind() {
|
||||
return Ref<QueryBuilder>(val());
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_vals_bind(const String ¶m) {
|
||||
return Ref<QueryBuilder>(vals(param));
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_vali_bind(const int param) {
|
||||
return Ref<QueryBuilder>(vali(param));
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_valb_bind(const bool param) {
|
||||
return Ref<QueryBuilder>(valb(param));
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_valf_bind(const float param) {
|
||||
return Ref<QueryBuilder>(valf(param));
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_vald_bind(const double param) {
|
||||
return Ref<QueryBuilder>(vald(param));
|
||||
}
|
||||
|
||||
Ref<QueryBuilder> QueryBuilder::_like_bind(const String &str) {
|
||||
return Ref<QueryBuilder>(like(str));
|
||||
}
|
||||
|
||||
Ref<QueryBuilder> QueryBuilder::_sets_bind() {
|
||||
return Ref<QueryBuilder>(sets());
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_cset_bind() {
|
||||
return Ref<QueryBuilder>(cset());
|
||||
}
|
||||
|
||||
Ref<QueryBuilder> QueryBuilder::_setps_bind(const String &col, const String ¶m) {
|
||||
return Ref<QueryBuilder>(setps(col, param));
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_setpi_bind(const String &col, const int param) {
|
||||
return Ref<QueryBuilder>(setpi(col, param));
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_setpb_bind(const String &col, const bool param) {
|
||||
return Ref<QueryBuilder>(setpb(col, param));
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_setpf_bind(const String &col, const float param) {
|
||||
return Ref<QueryBuilder>(setpf(col, param));
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_setpd_bind(const String &col, const double param) {
|
||||
return Ref<QueryBuilder>(setpd(col, param));
|
||||
}
|
||||
|
||||
Ref<QueryBuilder> QueryBuilder::_wps_bind(const String &col, const String ¶m) {
|
||||
return Ref<QueryBuilder>(wps(col, param));
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_wpi_bind(const String &col, const int param) {
|
||||
return Ref<QueryBuilder>(wpi(col, param));
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_wpb_bind(const String &col, const bool param) {
|
||||
return Ref<QueryBuilder>(wpb(col, param));
|
||||
}
|
||||
|
||||
Ref<QueryBuilder> QueryBuilder::_nselect_bind(const String ¶ms) {
|
||||
return Ref<QueryBuilder>(nselect(params));
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_nupdate_bind(const String ¶ms) {
|
||||
return Ref<QueryBuilder>(nupdate(params));
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_ndel_bind(const String ¶ms) {
|
||||
return Ref<QueryBuilder>(ndel(params));
|
||||
}
|
||||
|
||||
Ref<QueryBuilder> QueryBuilder::_nwhere_bind(const String ¶ms) {
|
||||
return Ref<QueryBuilder>(nwhere(params));
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_nfrom_bind(const String ¶ms) {
|
||||
return Ref<QueryBuilder>(nfrom(params));
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_nlike_bind(const String &str) {
|
||||
return Ref<QueryBuilder>(nlike(str));
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_nvalues_bind(const String ¶ms_str) {
|
||||
return Ref<QueryBuilder>(nvalues(params_str));
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_nval_bind(const String ¶m) {
|
||||
return Ref<QueryBuilder>(nval(param));
|
||||
}
|
||||
//note col is NOT escaped
|
||||
Ref<QueryBuilder> QueryBuilder::_nsetp_bind(const String &col, const String &escape_param) {
|
||||
return Ref<QueryBuilder>(nsetp(col, escape_param));
|
||||
}
|
||||
//note col is NOT escaped
|
||||
Ref<QueryBuilder> QueryBuilder::_nwp_bind(const String &col, const String &escape_param) {
|
||||
return Ref<QueryBuilder>(nwp(col, escape_param));
|
||||
}
|
||||
|
||||
Ref<QueryBuilder> QueryBuilder::_limit_bind(const int num) {
|
||||
return Ref<QueryBuilder>(limit(num));
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_offset_bind(const int num) {
|
||||
return Ref<QueryBuilder>(offset(num));
|
||||
}
|
||||
|
||||
Ref<QueryBuilder> QueryBuilder::_order_by_asc_bind(const String &col) {
|
||||
return Ref<QueryBuilder>(order_by_asc(col));
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_order_by_desc_bind(const String &col) {
|
||||
return Ref<QueryBuilder>(order_by_desc(col));
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_order_by_bind(const String &col) {
|
||||
return Ref<QueryBuilder>(order_by(col));
|
||||
}
|
||||
|
||||
Ref<QueryBuilder> QueryBuilder::_corder_by_bind() {
|
||||
return Ref<QueryBuilder>(corder_by());
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_order_by_add_col_bind(const String &col) {
|
||||
return Ref<QueryBuilder>(order_by_add_col(col));
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_asc_bind(const String &col) {
|
||||
return Ref<QueryBuilder>(asc(col));
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_desc_bind(const String &col) {
|
||||
return Ref<QueryBuilder>(desc(col));
|
||||
}
|
||||
|
||||
//l=logical (and, or are operators)
|
||||
Ref<QueryBuilder> QueryBuilder::_land_bind() {
|
||||
return Ref<QueryBuilder>(land());
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_lor_bind() {
|
||||
return Ref<QueryBuilder>(lor());
|
||||
}
|
||||
|
||||
Ref<QueryBuilder> QueryBuilder::_wildcard_bind() {
|
||||
return Ref<QueryBuilder>(wildcard());
|
||||
}
|
||||
|
||||
Ref<QueryBuilder> QueryBuilder::_w_bind(const String &str) {
|
||||
return Ref<QueryBuilder>(w(str));
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_ew_bind(const String &str) {
|
||||
return Ref<QueryBuilder>(ew(str));
|
||||
}
|
||||
|
||||
Ref<QueryBuilder> QueryBuilder::_select_last_insert_id_bind() {
|
||||
return Ref<QueryBuilder>(select_last_insert_id());
|
||||
}
|
||||
|
||||
Ref<QueryBuilder> QueryBuilder::_prepare_bind() {
|
||||
return Ref<QueryBuilder>(prepare());
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_set_params_bind(const int index, const String &value) {
|
||||
return Ref<QueryBuilder>(set_params(index, value));
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_set_parami_bind(const int index, const int value) {
|
||||
return Ref<QueryBuilder>(set_parami(index, value));
|
||||
}
|
||||
Ref<QueryBuilder> QueryBuilder::_set_paramf_bind(const int index, const float value) {
|
||||
return Ref<QueryBuilder>(set_paramf(index, value));
|
||||
}
|
||||
|
||||
Ref<QueryBuilder> QueryBuilder::_end_command_bind() {
|
||||
return Ref<QueryBuilder>(end_command());
|
||||
}
|
||||
|
||||
Ref<QueryBuilder> QueryBuilder::_reset_bind() {
|
||||
return Ref<QueryBuilder>(reset());
|
||||
}
|
@ -1,217 +0,0 @@
|
||||
#ifndef QUERY_BUILDER_H
|
||||
#define QUERY_BUILDER_H
|
||||
|
||||
#include "core/string/ustring.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
|
||||
class QueryResult;
|
||||
|
||||
//methods that start with an e escape their params.
|
||||
|
||||
class QueryBuilder : public Reference {
|
||||
GDCLASS(QueryBuilder, Reference);
|
||||
|
||||
public:
|
||||
String get_result();
|
||||
void set_result(const String &val);
|
||||
|
||||
virtual QueryBuilder *select();
|
||||
virtual QueryBuilder *update();
|
||||
virtual QueryBuilder *del();
|
||||
|
||||
virtual QueryBuilder *cvalues();
|
||||
virtual QueryBuilder *next_value();
|
||||
|
||||
virtual QueryBuilder *begin_transaction();
|
||||
virtual QueryBuilder *commit();
|
||||
|
||||
virtual QueryBuilder *nl();
|
||||
|
||||
virtual QueryBuilder *str();
|
||||
virtual QueryBuilder *cstr();
|
||||
|
||||
virtual QueryBuilder *select(const String ¶ms);
|
||||
virtual QueryBuilder *update(const String ¶ms);
|
||||
virtual QueryBuilder *del(const String ¶ms);
|
||||
|
||||
virtual QueryBuilder *where(const String ¶ms = "");
|
||||
virtual QueryBuilder *from(const String ¶ms = "");
|
||||
virtual QueryBuilder *insert(const String &table_name = "", const String &columns = "");
|
||||
virtual QueryBuilder *values(const String ¶ms_str = "");
|
||||
virtual QueryBuilder *val();
|
||||
virtual QueryBuilder *vals(const String ¶m);
|
||||
virtual QueryBuilder *vals(const char *param);
|
||||
virtual QueryBuilder *vali(const int param);
|
||||
virtual QueryBuilder *valb(const bool param);
|
||||
virtual QueryBuilder *valf(const float param);
|
||||
virtual QueryBuilder *vald(const double param);
|
||||
|
||||
virtual QueryBuilder *like(const String &str = "");
|
||||
|
||||
//Object Already has set(), so think of it as set_sql
|
||||
virtual QueryBuilder *sets();
|
||||
virtual QueryBuilder *cset();
|
||||
|
||||
virtual QueryBuilder *setps(const String &col, const String ¶m);
|
||||
virtual QueryBuilder *setps(const String &col, const char *param);
|
||||
virtual QueryBuilder *setpi(const String &col, const int param);
|
||||
virtual QueryBuilder *setpb(const String &col, const bool param);
|
||||
virtual QueryBuilder *setpf(const String &col, const float param);
|
||||
virtual QueryBuilder *setpd(const String &col, const double param);
|
||||
|
||||
virtual QueryBuilder *wps(const String &col, const String ¶m);
|
||||
virtual QueryBuilder *wps(const String &col, const char *param);
|
||||
virtual QueryBuilder *wpi(const String &col, const int param);
|
||||
virtual QueryBuilder *wpb(const String &col, const bool param);
|
||||
|
||||
virtual QueryBuilder *nselect(const String ¶ms);
|
||||
virtual QueryBuilder *nupdate(const String ¶ms);
|
||||
virtual QueryBuilder *ndel(const String ¶ms);
|
||||
|
||||
virtual QueryBuilder *nwhere(const String ¶ms);
|
||||
virtual QueryBuilder *nfrom(const String ¶ms);
|
||||
virtual QueryBuilder *nlike(const String &str);
|
||||
virtual QueryBuilder *nvalues(const String ¶ms_str);
|
||||
virtual QueryBuilder *nval(const String ¶m);
|
||||
//note col is NOT escaped
|
||||
virtual QueryBuilder *nsetp(const String &col, const String &escape_param);
|
||||
//note col is NOT escaped
|
||||
virtual QueryBuilder *nwp(const String &col, const String &escape_param);
|
||||
|
||||
virtual QueryBuilder *limit(const int num);
|
||||
virtual QueryBuilder *offset(const int num);
|
||||
|
||||
virtual QueryBuilder *order_by_asc(const String &col);
|
||||
virtual QueryBuilder *order_by_desc(const String &col);
|
||||
virtual QueryBuilder *order_by(const String &col = "");
|
||||
|
||||
virtual QueryBuilder *corder_by();
|
||||
virtual QueryBuilder *order_by_add_col(const String &col);
|
||||
virtual QueryBuilder *asc(const String &col = "");
|
||||
virtual QueryBuilder *desc(const String &col = "");
|
||||
|
||||
//l=logical (and, or are operators)
|
||||
virtual QueryBuilder *land();
|
||||
virtual QueryBuilder *lor();
|
||||
|
||||
virtual QueryBuilder *wildcard();
|
||||
|
||||
virtual QueryBuilder *w(const String &str);
|
||||
virtual QueryBuilder *ew(const String &str);
|
||||
|
||||
virtual QueryBuilder *select_last_insert_id();
|
||||
|
||||
virtual String escape(const String ¶ms);
|
||||
|
||||
virtual QueryBuilder *prepare();
|
||||
virtual QueryBuilder *set_params(const int index, const String &value);
|
||||
virtual QueryBuilder *set_parami(const int index, const int value);
|
||||
virtual QueryBuilder *set_paramf(const int index, const float value);
|
||||
|
||||
virtual QueryBuilder *end_command();
|
||||
|
||||
virtual QueryBuilder *reset();
|
||||
|
||||
virtual Ref<QueryResult> run();
|
||||
virtual void run_query();
|
||||
|
||||
void print();
|
||||
|
||||
QueryBuilder();
|
||||
virtual ~QueryBuilder();
|
||||
|
||||
String query_result;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
Ref<QueryBuilder> _cvalues_bind();
|
||||
Ref<QueryBuilder> _next_value_bind();
|
||||
|
||||
Ref<QueryBuilder> _begin_transaction_bind();
|
||||
Ref<QueryBuilder> _commit_bind();
|
||||
|
||||
Ref<QueryBuilder> _nl_bind();
|
||||
|
||||
Ref<QueryBuilder> _str_bind();
|
||||
Ref<QueryBuilder> _cstr_bind();
|
||||
|
||||
Ref<QueryBuilder> _select_bind(const String ¶ms);
|
||||
Ref<QueryBuilder> _update_bind(const String ¶ms);
|
||||
Ref<QueryBuilder> _del_bind(const String ¶ms);
|
||||
|
||||
Ref<QueryBuilder> _where_bind(const String ¶ms = "");
|
||||
Ref<QueryBuilder> _from_bind(const String ¶ms = "");
|
||||
Ref<QueryBuilder> _insert_bind(const String &table_name = "", const String &columns = "");
|
||||
Ref<QueryBuilder> _values_bind(const String ¶ms_str = "");
|
||||
Ref<QueryBuilder> _val_bind();
|
||||
Ref<QueryBuilder> _vals_bind(const String ¶m);
|
||||
Ref<QueryBuilder> _vali_bind(const int param);
|
||||
Ref<QueryBuilder> _valb_bind(const bool param);
|
||||
Ref<QueryBuilder> _valf_bind(const float param);
|
||||
Ref<QueryBuilder> _vald_bind(const double param);
|
||||
|
||||
Ref<QueryBuilder> _like_bind(const String &str);
|
||||
|
||||
Ref<QueryBuilder> _sets_bind();
|
||||
Ref<QueryBuilder> _cset_bind();
|
||||
|
||||
Ref<QueryBuilder> _setps_bind(const String &col, const String ¶m);
|
||||
Ref<QueryBuilder> _setpi_bind(const String &col, const int param);
|
||||
Ref<QueryBuilder> _setpb_bind(const String &col, const bool param);
|
||||
Ref<QueryBuilder> _setpf_bind(const String &col, const float param);
|
||||
Ref<QueryBuilder> _setpd_bind(const String &col, const double param);
|
||||
|
||||
Ref<QueryBuilder> _wps_bind(const String &col, const String ¶m);
|
||||
Ref<QueryBuilder> _wpi_bind(const String &col, const int param);
|
||||
Ref<QueryBuilder> _wpb_bind(const String &col, const bool param);
|
||||
|
||||
Ref<QueryBuilder> _nselect_bind(const String ¶ms);
|
||||
Ref<QueryBuilder> _nupdate_bind(const String ¶ms);
|
||||
Ref<QueryBuilder> _ndel_bind(const String ¶ms);
|
||||
|
||||
Ref<QueryBuilder> _nwhere_bind(const String ¶ms);
|
||||
Ref<QueryBuilder> _nfrom_bind(const String ¶ms);
|
||||
Ref<QueryBuilder> _nlike_bind(const String &str);
|
||||
Ref<QueryBuilder> _nvalues_bind(const String ¶ms_str);
|
||||
Ref<QueryBuilder> _nval_bind(const String ¶m);
|
||||
//note col is NOT escaped
|
||||
Ref<QueryBuilder> _nsetp_bind(const String &col, const String &escape_param);
|
||||
//note col is NOT escaped
|
||||
Ref<QueryBuilder> _nwp_bind(const String &col, const String &escape_param);
|
||||
|
||||
Ref<QueryBuilder> _limit_bind(const int num);
|
||||
Ref<QueryBuilder> _offset_bind(const int num);
|
||||
|
||||
Ref<QueryBuilder> _order_by_asc_bind(const String &col);
|
||||
Ref<QueryBuilder> _order_by_desc_bind(const String &col);
|
||||
Ref<QueryBuilder> _order_by_bind(const String &col = "");
|
||||
|
||||
Ref<QueryBuilder> _corder_by_bind();
|
||||
Ref<QueryBuilder> _order_by_add_col_bind(const String &col);
|
||||
Ref<QueryBuilder> _asc_bind(const String &col = "");
|
||||
Ref<QueryBuilder> _desc_bind(const String &col = "");
|
||||
|
||||
//l=logical (and, or are operators)
|
||||
Ref<QueryBuilder> _land_bind();
|
||||
Ref<QueryBuilder> _lor_bind();
|
||||
|
||||
Ref<QueryBuilder> _wildcard_bind();
|
||||
|
||||
Ref<QueryBuilder> _w_bind(const String &str);
|
||||
Ref<QueryBuilder> _ew_bind(const String &str);
|
||||
|
||||
Ref<QueryBuilder> _select_last_insert_id_bind();
|
||||
|
||||
Ref<QueryBuilder> _prepare_bind();
|
||||
Ref<QueryBuilder> _set_params_bind(const int index, const String &value);
|
||||
Ref<QueryBuilder> _set_parami_bind(const int index, const int value);
|
||||
Ref<QueryBuilder> _set_paramf_bind(const int index, const float value);
|
||||
|
||||
Ref<QueryBuilder> _end_command_bind();
|
||||
|
||||
Ref<QueryBuilder> _reset_bind();
|
||||
};
|
||||
|
||||
#endif
|
@ -1,72 +0,0 @@
|
||||
#include "query_result.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
bool QueryResult::next_row() {
|
||||
return false;
|
||||
}
|
||||
|
||||
String QueryResult::get_cell(const int index) {
|
||||
return String();
|
||||
}
|
||||
|
||||
bool QueryResult::get_cell_bool(const int index) {
|
||||
return get_cell_int(index);
|
||||
}
|
||||
|
||||
int QueryResult::get_cell_int(const int index) {
|
||||
if (is_cell_null(index)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return get_cell(index).to_int();
|
||||
}
|
||||
|
||||
float QueryResult::get_cell_float(const int index) {
|
||||
if (is_cell_null(index)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return get_cell(index).to_float();
|
||||
}
|
||||
double QueryResult::get_cell_double(const int index) {
|
||||
if (is_cell_null(index)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return get_cell(index).to_double();
|
||||
}
|
||||
|
||||
bool QueryResult::is_cell_null(const int index) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int QueryResult::get_last_insert_rowid() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
String QueryResult::get_error_message() {
|
||||
return "";
|
||||
}
|
||||
|
||||
QueryResult::QueryResult() {
|
||||
}
|
||||
|
||||
QueryResult::~QueryResult() {
|
||||
}
|
||||
|
||||
void QueryResult::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("next_row"), &QueryResult::next_row);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_cell", "index"), &QueryResult::get_cell);
|
||||
ClassDB::bind_method(D_METHOD("get_cell_bool", "index"), &QueryResult::get_cell_bool);
|
||||
ClassDB::bind_method(D_METHOD("get_cell_int", "index"), &QueryResult::get_cell_int);
|
||||
ClassDB::bind_method(D_METHOD("get_cell_float", "index"), &QueryResult::get_cell_float);
|
||||
ClassDB::bind_method(D_METHOD("get_cell_double", "index"), &QueryResult::get_cell_double);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("is_cell_null", "index"), &QueryResult::is_cell_null);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_last_insert_rowid"), &QueryResult::get_last_insert_rowid);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_error_message"), &QueryResult::get_error_message);
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
#ifndef QUERY_RESULT_H
|
||||
#define QUERY_RESULT_H
|
||||
|
||||
#include "core/string/ustring.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
|
||||
class QueryResult : public Reference {
|
||||
GDCLASS(QueryResult, Reference);
|
||||
|
||||
public:
|
||||
virtual bool next_row();
|
||||
virtual String get_cell(const int index);
|
||||
virtual bool get_cell_bool(const int index);
|
||||
virtual int get_cell_int(const int index);
|
||||
virtual float get_cell_float(const int index);
|
||||
virtual double get_cell_double(const int index);
|
||||
|
||||
virtual bool is_cell_null(const int index);
|
||||
|
||||
virtual int get_last_insert_rowid();
|
||||
|
||||
virtual String get_error_message();
|
||||
|
||||
QueryResult();
|
||||
virtual ~QueryResult();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
};
|
||||
|
||||
#endif
|
@ -1,62 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2023 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 "register_types.h"
|
||||
|
||||
#include "database.h"
|
||||
#include "database_connection.h"
|
||||
#include "database_manager.h"
|
||||
#include "database_multi_threaded.h"
|
||||
#include "database_single_threaded.h"
|
||||
#include "query_builder.h"
|
||||
#include "query_result.h"
|
||||
#include "table_builder.h"
|
||||
|
||||
#include "core/config/engine.h"
|
||||
|
||||
DatabaseManager *_database_manager = nullptr;
|
||||
|
||||
void register_database_types(ModuleRegistrationLevel p_level) {
|
||||
if (p_level == MODULE_REGISTRATION_LEVEL_SINGLETON) {
|
||||
_database_manager = memnew(DatabaseManager);
|
||||
ClassDB::register_class<DatabaseManager>();
|
||||
Engine::get_singleton()->add_singleton(Engine::Singleton("DatabaseManager", DatabaseManager::get_singleton()));
|
||||
}
|
||||
|
||||
if (p_level == MODULE_REGISTRATION_LEVEL_SCENE) {
|
||||
ClassDB::register_class<Database>();
|
||||
ClassDB::register_class<DatabaseConnection>();
|
||||
ClassDB::register_class<DatabaseMultiThreaded>();
|
||||
ClassDB::register_class<DatabaseSingleThreaded>();
|
||||
ClassDB::register_class<QueryBuilder>();
|
||||
ClassDB::register_class<QueryResult>();
|
||||
ClassDB::register_class<TableBuilder>();
|
||||
}
|
||||
}
|
||||
|
||||
void unregister_database_types(ModuleRegistrationLevel p_level) {
|
||||
if (p_level == MODULE_REGISTRATION_LEVEL_SINGLETON) {
|
||||
if (_database_manager) {
|
||||
memdelete(_database_manager);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
#ifndef DATABASE_REGISTER_TYPES_H
|
||||
#define DATABASE_REGISTER_TYPES_H
|
||||
|
||||
/*
|
||||
Copyright (c) 2022-2023 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 "modules/register_module_types.h"
|
||||
|
||||
void register_database_types(ModuleRegistrationLevel p_level);
|
||||
void unregister_database_types(ModuleRegistrationLevel p_level);
|
||||
|
||||
#endif
|
@ -1,220 +0,0 @@
|
||||
#include "table_builder.h"
|
||||
|
||||
#include "core/string/print_string.h"
|
||||
#include "query_result.h"
|
||||
|
||||
String TableBuilder::get_result() {
|
||||
return result;
|
||||
}
|
||||
void TableBuilder::set_result(const String &val) {
|
||||
result = val;
|
||||
}
|
||||
|
||||
TableBuilder *TableBuilder::create_table(const String &name) {
|
||||
return this;
|
||||
}
|
||||
|
||||
TableBuilder *TableBuilder::integer(const String &name, const int length) {
|
||||
return this;
|
||||
}
|
||||
|
||||
TableBuilder *TableBuilder::tiny_integer(const String &name, const int length) {
|
||||
return this;
|
||||
}
|
||||
|
||||
TableBuilder *TableBuilder::small_integer(const String &name, const int length) {
|
||||
return this;
|
||||
}
|
||||
|
||||
TableBuilder *TableBuilder::real_float(const String &name, const int size, const int d) {
|
||||
return this;
|
||||
}
|
||||
|
||||
TableBuilder *TableBuilder::real_double(const String &name, const int size, const int d) {
|
||||
return this;
|
||||
}
|
||||
|
||||
TableBuilder *TableBuilder::date(const String &name) {
|
||||
return this;
|
||||
}
|
||||
|
||||
TableBuilder *TableBuilder::varchar(const String &name, const int length) {
|
||||
return this;
|
||||
}
|
||||
|
||||
TableBuilder *TableBuilder::text(const String &name) {
|
||||
return this;
|
||||
}
|
||||
|
||||
TableBuilder *TableBuilder::not_null() {
|
||||
return this;
|
||||
}
|
||||
|
||||
TableBuilder *TableBuilder::null() {
|
||||
return this;
|
||||
}
|
||||
|
||||
TableBuilder *TableBuilder::defval(const String &val) {
|
||||
return this;
|
||||
}
|
||||
|
||||
TableBuilder *TableBuilder::auto_increment() {
|
||||
return this;
|
||||
}
|
||||
|
||||
TableBuilder *TableBuilder::primary_key(const String &name) {
|
||||
return this;
|
||||
}
|
||||
|
||||
TableBuilder *TableBuilder::next_row() {
|
||||
return this;
|
||||
}
|
||||
|
||||
TableBuilder *TableBuilder::ccreate_table() {
|
||||
return this;
|
||||
}
|
||||
|
||||
TableBuilder *TableBuilder::drop_table_if_exists() {
|
||||
return this;
|
||||
}
|
||||
TableBuilder *TableBuilder::drop_table(const String &name) {
|
||||
return this;
|
||||
}
|
||||
TableBuilder *TableBuilder::drop_table_if_exists(const String &name) {
|
||||
return this;
|
||||
}
|
||||
TableBuilder *TableBuilder::cdrop_table() {
|
||||
return this;
|
||||
}
|
||||
|
||||
TableBuilder *TableBuilder::foreign_key(const String &name) {
|
||||
return this;
|
||||
}
|
||||
TableBuilder *TableBuilder::references(const String &table, const String &name) {
|
||||
return this;
|
||||
}
|
||||
|
||||
Ref<QueryResult> TableBuilder::run() {
|
||||
return Ref<QueryResult>();
|
||||
}
|
||||
|
||||
void TableBuilder::run_query() {
|
||||
}
|
||||
|
||||
void TableBuilder::print() {
|
||||
//printf("%s\n", result.get_data());
|
||||
print_error(result);
|
||||
}
|
||||
|
||||
TableBuilder::TableBuilder() {
|
||||
}
|
||||
|
||||
TableBuilder::~TableBuilder() {
|
||||
}
|
||||
|
||||
void TableBuilder::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_result"), &TableBuilder::get_result);
|
||||
ClassDB::bind_method(D_METHOD("set_result", "value"), &TableBuilder::set_result);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "result"), "set_result", "get_result");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("create_table", "value"), &TableBuilder::_create_table_bind);
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("integer", "name", "length"), &TableBuilder::_integer_bind, -1);
|
||||
ClassDB::bind_method(D_METHOD("tiny_integer", "name", "length"), &TableBuilder::_tiny_integer_bind, -1);
|
||||
ClassDB::bind_method(D_METHOD("small_integer", "name", "length"), &TableBuilder::_small_integer_bind, -1);
|
||||
ClassDB::bind_method(D_METHOD("real_float", "name", "size", "d"), &TableBuilder::_real_float_bind, -1, -1);
|
||||
ClassDB::bind_method(D_METHOD("real_double", "name", "size", "d"), &TableBuilder::_real_double_bind, -1, -1);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("date", "name"), &TableBuilder::_date_bind);
|
||||
ClassDB::bind_method(D_METHOD("varchar", "name", "length"), &TableBuilder::_varchar_bind, -1);
|
||||
ClassDB::bind_method(D_METHOD("text", "name"), &TableBuilder::_text_bind);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("not_null"), &TableBuilder::_not_null_bind);
|
||||
ClassDB::bind_method(D_METHOD("null"), &TableBuilder::_null_bind);
|
||||
ClassDB::bind_method(D_METHOD("defval", "val"), &TableBuilder::_defval_bind);
|
||||
ClassDB::bind_method(D_METHOD("auto_increment"), &TableBuilder::_auto_increment_bind);
|
||||
ClassDB::bind_method(D_METHOD("primary_key", "name"), &TableBuilder::_primary_key_bind, "");
|
||||
ClassDB::bind_method(D_METHOD("next_row"), &TableBuilder::_next_row_bind);
|
||||
ClassDB::bind_method(D_METHOD("ccreate_table"), &TableBuilder::_ccreate_table_bind);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("drop_table", "name"), &TableBuilder::_drop_table_bind, "");
|
||||
ClassDB::bind_method(D_METHOD("drop_table_if_exists", "name"), &TableBuilder::_drop_table_if_exists_bind, "");
|
||||
ClassDB::bind_method(D_METHOD("cdrop_table"), &TableBuilder::_cdrop_table_bind);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("foreign_key", "name"), &TableBuilder::_foreign_key_bind);
|
||||
ClassDB::bind_method(D_METHOD("references", "table", "name"), &TableBuilder::_references_bind);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("run"), &TableBuilder::run);
|
||||
ClassDB::bind_method(D_METHOD("run_query"), &TableBuilder::run_query);
|
||||
}
|
||||
|
||||
Ref<TableBuilder> TableBuilder::_create_table_bind(const String &name) {
|
||||
return Ref<TableBuilder>(create_table(name));
|
||||
}
|
||||
|
||||
Ref<TableBuilder> TableBuilder::_integer_bind(const String &name, const int length) {
|
||||
return Ref<TableBuilder>(integer(name, length));
|
||||
}
|
||||
Ref<TableBuilder> TableBuilder::_tiny_integer_bind(const String &name, const int length) {
|
||||
return Ref<TableBuilder>(tiny_integer(name, length));
|
||||
}
|
||||
Ref<TableBuilder> TableBuilder::_small_integer_bind(const String &name, const int length) {
|
||||
return Ref<TableBuilder>(small_integer(name, length));
|
||||
}
|
||||
Ref<TableBuilder> TableBuilder::_real_float_bind(const String &name, const int size, const int d) {
|
||||
return Ref<TableBuilder>(real_float(name, size, d));
|
||||
}
|
||||
Ref<TableBuilder> TableBuilder::_real_double_bind(const String &name, const int size, const int d) {
|
||||
return Ref<TableBuilder>(real_double(name, size, d));
|
||||
}
|
||||
|
||||
Ref<TableBuilder> TableBuilder::_date_bind(const String &name) {
|
||||
return Ref<TableBuilder>(date(name));
|
||||
}
|
||||
|
||||
Ref<TableBuilder> TableBuilder::_varchar_bind(const String &name, const int length) {
|
||||
return Ref<TableBuilder>(varchar(name, length));
|
||||
}
|
||||
Ref<TableBuilder> TableBuilder::_text_bind(const String &name) {
|
||||
return Ref<TableBuilder>(text(name));
|
||||
}
|
||||
|
||||
Ref<TableBuilder> TableBuilder::_not_null_bind() {
|
||||
return Ref<TableBuilder>(not_null());
|
||||
}
|
||||
Ref<TableBuilder> TableBuilder::_null_bind() {
|
||||
return Ref<TableBuilder>(null());
|
||||
}
|
||||
Ref<TableBuilder> TableBuilder::_defval_bind(const String &val) {
|
||||
return Ref<TableBuilder>(defval(val));
|
||||
}
|
||||
Ref<TableBuilder> TableBuilder::_auto_increment_bind() {
|
||||
return Ref<TableBuilder>(auto_increment());
|
||||
}
|
||||
Ref<TableBuilder> TableBuilder::_primary_key_bind(const String &name) {
|
||||
return Ref<TableBuilder>(primary_key(name));
|
||||
}
|
||||
Ref<TableBuilder> TableBuilder::_next_row_bind() {
|
||||
return Ref<TableBuilder>(next_row());
|
||||
}
|
||||
Ref<TableBuilder> TableBuilder::_ccreate_table_bind() {
|
||||
return Ref<TableBuilder>(ccreate_table());
|
||||
}
|
||||
|
||||
Ref<TableBuilder> TableBuilder::_drop_table_bind(const String &name) {
|
||||
return Ref<TableBuilder>(drop_table(name));
|
||||
}
|
||||
Ref<TableBuilder> TableBuilder::_drop_table_if_exists_bind(const String &name) {
|
||||
return Ref<TableBuilder>(drop_table_if_exists(name));
|
||||
}
|
||||
Ref<TableBuilder> TableBuilder::_cdrop_table_bind() {
|
||||
return Ref<TableBuilder>(cdrop_table());
|
||||
}
|
||||
|
||||
Ref<TableBuilder> TableBuilder::_foreign_key_bind(const String &name) {
|
||||
return Ref<TableBuilder>(foreign_key(name));
|
||||
}
|
||||
Ref<TableBuilder> TableBuilder::_references_bind(const String &table, const String &name) {
|
||||
return Ref<TableBuilder>(references(table, name));
|
||||
}
|
@ -1,88 +0,0 @@
|
||||
#ifndef TABLE_BUILDER_H
|
||||
#define TABLE_BUILDER_H
|
||||
|
||||
#include "core/string/ustring.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
|
||||
class QueryResult;
|
||||
|
||||
class TableBuilder : public Reference {
|
||||
GDCLASS(TableBuilder, Reference);
|
||||
|
||||
public:
|
||||
String get_result();
|
||||
void set_result(const String &val);
|
||||
|
||||
virtual TableBuilder *create_table(const String &name);
|
||||
|
||||
virtual TableBuilder *integer(const String &name, const int length = -1);
|
||||
virtual TableBuilder *tiny_integer(const String &name, const int length = -1);
|
||||
virtual TableBuilder *small_integer(const String &name, const int length = -1);
|
||||
virtual TableBuilder *real_float(const String &name, const int size = -1, const int d = -1);
|
||||
virtual TableBuilder *real_double(const String &name, const int size = -1, const int d = -1);
|
||||
|
||||
virtual TableBuilder *date(const String &name);
|
||||
|
||||
virtual TableBuilder *varchar(const String &name, const int length = -1);
|
||||
virtual TableBuilder *text(const String &name);
|
||||
|
||||
virtual TableBuilder *not_null();
|
||||
virtual TableBuilder *null();
|
||||
virtual TableBuilder *defval(const String &val);
|
||||
virtual TableBuilder *auto_increment();
|
||||
virtual TableBuilder *primary_key(const String &name = "");
|
||||
virtual TableBuilder *next_row();
|
||||
virtual TableBuilder *ccreate_table();
|
||||
|
||||
virtual TableBuilder *drop_table_if_exists();
|
||||
virtual TableBuilder *drop_table(const String &name = "");
|
||||
virtual TableBuilder *drop_table_if_exists(const String &name);
|
||||
virtual TableBuilder *cdrop_table();
|
||||
|
||||
virtual TableBuilder *foreign_key(const String &name);
|
||||
virtual TableBuilder *references(const String &table, const String &name);
|
||||
|
||||
virtual Ref<QueryResult> run();
|
||||
virtual void run_query();
|
||||
|
||||
void print();
|
||||
|
||||
TableBuilder();
|
||||
virtual ~TableBuilder();
|
||||
|
||||
String result;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
Ref<TableBuilder> _create_table_bind(const String &name);
|
||||
|
||||
Ref<TableBuilder> _integer_bind(const String &name, const int length = -1);
|
||||
Ref<TableBuilder> _tiny_integer_bind(const String &name, const int length = -1);
|
||||
Ref<TableBuilder> _small_integer_bind(const String &name, const int length = -1);
|
||||
Ref<TableBuilder> _real_float_bind(const String &name, const int size = -1, const int d = -1);
|
||||
Ref<TableBuilder> _real_double_bind(const String &name, const int size = -1, const int d = -1);
|
||||
|
||||
Ref<TableBuilder> _date_bind(const String &name);
|
||||
|
||||
Ref<TableBuilder> _varchar_bind(const String &name, const int length = -1);
|
||||
Ref<TableBuilder> _text_bind(const String &name);
|
||||
|
||||
Ref<TableBuilder> _not_null_bind();
|
||||
Ref<TableBuilder> _null_bind();
|
||||
Ref<TableBuilder> _defval_bind(const String &val);
|
||||
Ref<TableBuilder> _auto_increment_bind();
|
||||
Ref<TableBuilder> _primary_key_bind(const String &name = "");
|
||||
Ref<TableBuilder> _next_row_bind();
|
||||
Ref<TableBuilder> _ccreate_table_bind();
|
||||
|
||||
Ref<TableBuilder> _drop_table_bind(const String &name = "");
|
||||
Ref<TableBuilder> _drop_table_if_exists_bind(const String &name);
|
||||
Ref<TableBuilder> _cdrop_table_bind();
|
||||
|
||||
Ref<TableBuilder> _foreign_key_bind(const String &name);
|
||||
Ref<TableBuilder> _references_bind(const String &table, const String &name);
|
||||
};
|
||||
|
||||
#endif
|
@ -1,52 +0,0 @@
|
||||
# Exhaustive licensing information for files in the Godot Engine repository
|
||||
# =========================================================================
|
||||
#
|
||||
# This file aims at documenting the copyright and license for every source
|
||||
# file in the Godot Engine repository, and especially outline the files
|
||||
# whose license differs from the MIT/Expat license used by Godot Engine.
|
||||
#
|
||||
# It is written as a machine-readable format following the debian/copyright
|
||||
# specification. Globbing patterns (e.g. "Files: *") mean that they affect
|
||||
# all corresponding files (also recursively in subfolders), apart from those
|
||||
# with a more explicit copyright statement.
|
||||
#
|
||||
# Licenses are given with their debian/copyright short name (or SPDX identifier
|
||||
# if no standard short name exists) and are all included in plain text at the
|
||||
# end of this file (in alphabetical order).
|
||||
#
|
||||
# Disclaimer for thirdparty libraries:
|
||||
# ------------------------------------
|
||||
#
|
||||
# Licensing details for thirdparty libraries in the 'thirdparty/' directory
|
||||
# are given in summarized form, i.e. with only the "main" license described
|
||||
# in the library's license statement. Different licenses of single files or
|
||||
# code snippets in thirdparty libraries are not documented here.
|
||||
# For example:
|
||||
# Files: ./thirdparty/zlib/
|
||||
# Copyright: 1995-2017, Jean-loup Gailly and Mark Adler
|
||||
# License: Zlib
|
||||
# The exact copyright for each file in that library *may* differ, and some
|
||||
# files or code snippets might be distributed under other compatible licenses
|
||||
# (e.g. a public domain dedication), but as far as Godot Engine is concerned
|
||||
# the library is considered as a whole under the Zlib license.
|
||||
#
|
||||
# Nota: When linking dynamically against thirdparty libraries instead of
|
||||
# building them into the Godot binary, you may remove the corresponding
|
||||
# license details from this file.
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
Files: modules/database_sqlite/sqlite/*
|
||||
Comment: SQLite
|
||||
Copyright: Public Domain
|
||||
License: Public Domain (SQLite)
|
||||
|
||||
|
||||
|
||||
License: Public Domain (SQLite)
|
||||
The author disclaims copyright to this source code. In place of
|
||||
a legal notice, here is a blessing:
|
||||
.
|
||||
May you do good and not evil.
|
||||
May you find forgiveness for yourself and forgive others.
|
||||
May you share freely, never taking more than you give.
|
@ -1,45 +0,0 @@
|
||||
|
||||
#Import("env_db")
|
||||
#Import("env")
|
||||
|
||||
#env_db.core_sources = []
|
||||
|
||||
#env_db.add_source_files(env_db.core_sources, "*.cpp")
|
||||
#env_db.core_sources.append("./sqlite/sqlite3.c")
|
||||
|
||||
# Build it all as a library
|
||||
#lib = env_db.add_library("database_sqlite", env_db.core_sources)
|
||||
#env.Prepend(LIBS=[lib])
|
||||
|
||||
|
||||
import os
|
||||
import version
|
||||
|
||||
Import('env')
|
||||
|
||||
module_env = env.Clone()
|
||||
|
||||
sources = [
|
||||
"register_types.cpp",
|
||||
|
||||
"sqlite/sqlite3.c",
|
||||
|
||||
"sqlite3_database.cpp",
|
||||
"sqlite3_connection.cpp",
|
||||
"sqlite3_query_builder.cpp",
|
||||
"sqlite3_query_result.cpp",
|
||||
"sqlite3_table_builder.cpp",
|
||||
]
|
||||
|
||||
if ARGUMENTS.get('custom_modules_shared', 'no') == 'yes':
|
||||
# Shared lib compilation
|
||||
module_env.Append(CCFLAGS=['-fPIC'])
|
||||
module_env['LIBS'] = []
|
||||
shared_lib = module_env.SharedLibrary(target='#bin/database_sqlite', source=sources)
|
||||
shared_lib_shim = shared_lib[0].name.rsplit('.', 1)[0]
|
||||
env.Append(LIBS=[shared_lib_shim])
|
||||
env.Append(LIBPATH=['#bin'])
|
||||
else:
|
||||
# Static compilation
|
||||
module_env.add_source_files(env.modules_sources, sources)
|
||||
|
@ -1,55 +0,0 @@
|
||||
import os
|
||||
import platform
|
||||
import sys
|
||||
|
||||
|
||||
def can_build(env, platform):
|
||||
env.module_add_dependencies("database_sqlite", ["database"], False)
|
||||
|
||||
return True
|
||||
|
||||
def _can_build():
|
||||
|
||||
# if os.name == "posix" or sys.platform == "darwin":
|
||||
# x11_error = os.system("pkg-config --version > /dev/null")
|
||||
# if x11_error:
|
||||
# return False
|
||||
|
||||
# sqlite_error = os.system("pkg-config sqlite3 --modversion --silence-errors > /dev/null ")
|
||||
|
||||
# if sqlite_error:
|
||||
# print("sqlite3 not found!")
|
||||
# return False
|
||||
|
||||
# print("sqlite3 found!")
|
||||
|
||||
# return True
|
||||
|
||||
# #todo
|
||||
# return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def configure(env):
|
||||
pass
|
||||
|
||||
def _configure(env):
|
||||
#env.ParseConfig("pkg-config sqlite3 --cflags --libs")
|
||||
|
||||
#env.Append(CPPDEFINES=[("SQLITE_THREADSAFE", 1)])
|
||||
|
||||
#env.Append(LINKFLAGS=["-ldl"])
|
||||
pass
|
||||
|
||||
|
||||
def get_doc_classes():
|
||||
return [
|
||||
"SQLite3Database",
|
||||
]
|
||||
|
||||
def get_doc_path():
|
||||
return "doc_classes"
|
||||
|
||||
def get_license_file():
|
||||
return "COPYRIGHT.txt"
|
@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="SQLite3Database" inherits="DatabaseSingleThreaded" version="4.2">
|
||||
<brief_description>
|
||||
</brief_description>
|
||||
<description>
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
</methods>
|
||||
<constants>
|
||||
</constants>
|
||||
</class>
|
@ -1,34 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2022-2023 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 "register_types.h"
|
||||
|
||||
#include "sqlite3_database.h"
|
||||
|
||||
void register_database_sqlite_types(ModuleRegistrationLevel p_level) {
|
||||
if (p_level == MODULE_REGISTRATION_LEVEL_SCENE) {
|
||||
ClassDB::register_class<SQLite3Database>();
|
||||
}
|
||||
}
|
||||
|
||||
void unregister_database_sqlite_types(ModuleRegistrationLevel p_level) {
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
#ifndef DATABASE_SQLITE_REGISTER_TYPES_H
|
||||
#define DATABASE_SQLITE_REGISTER_TYPES_H
|
||||
|
||||
/*
|
||||
Copyright (c) 2022-2023 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 "modules/register_module_types.h"
|
||||
|
||||
void register_database_sqlite_types(ModuleRegistrationLevel p_level);
|
||||
void unregister_database_sqlite_types(ModuleRegistrationLevel p_level);
|
||||
|
||||
#endif
|
@ -1,186 +0,0 @@
|
||||
EXPORTS
|
||||
sqlite3_aggregate_context
|
||||
sqlite3_aggregate_count
|
||||
sqlite3_auto_extension
|
||||
sqlite3_backup_finish
|
||||
sqlite3_backup_init
|
||||
sqlite3_backup_pagecount
|
||||
sqlite3_backup_remaining
|
||||
sqlite3_backup_step
|
||||
sqlite3_bind_blob
|
||||
sqlite3_bind_double
|
||||
sqlite3_bind_int
|
||||
sqlite3_bind_int64
|
||||
sqlite3_bind_null
|
||||
sqlite3_bind_parameter_count
|
||||
sqlite3_bind_parameter_index
|
||||
sqlite3_bind_parameter_name
|
||||
sqlite3_bind_text
|
||||
sqlite3_bind_text16
|
||||
sqlite3_bind_value
|
||||
sqlite3_bind_zeroblob
|
||||
sqlite3_blob_bytes
|
||||
sqlite3_blob_close
|
||||
sqlite3_blob_open
|
||||
sqlite3_blob_read
|
||||
sqlite3_blob_write
|
||||
sqlite3_busy_handler
|
||||
sqlite3_busy_timeout
|
||||
sqlite3_changes
|
||||
sqlite3_clear_bindings
|
||||
sqlite3_close
|
||||
sqlite3_collation_needed
|
||||
sqlite3_collation_needed16
|
||||
sqlite3_column_blob
|
||||
sqlite3_column_bytes
|
||||
sqlite3_column_bytes16
|
||||
sqlite3_column_count
|
||||
sqlite3_column_database_name
|
||||
sqlite3_column_database_name16
|
||||
sqlite3_column_decltype
|
||||
sqlite3_column_decltype16
|
||||
sqlite3_column_double
|
||||
sqlite3_column_int
|
||||
sqlite3_column_int64
|
||||
sqlite3_column_name
|
||||
sqlite3_column_name16
|
||||
sqlite3_column_origin_name
|
||||
sqlite3_column_origin_name16
|
||||
sqlite3_column_table_name
|
||||
sqlite3_column_table_name16
|
||||
sqlite3_column_text
|
||||
sqlite3_column_text16
|
||||
sqlite3_column_type
|
||||
sqlite3_column_value
|
||||
sqlite3_commit_hook
|
||||
sqlite3_compileoption_get
|
||||
sqlite3_compileoption_used
|
||||
sqlite3_complete
|
||||
sqlite3_complete16
|
||||
sqlite3_config
|
||||
sqlite3_context_db_handle
|
||||
sqlite3_create_collation
|
||||
sqlite3_create_collation16
|
||||
sqlite3_create_collation_v2
|
||||
sqlite3_create_function
|
||||
sqlite3_create_function16
|
||||
sqlite3_create_module
|
||||
sqlite3_create_module_v2
|
||||
sqlite3_data_count
|
||||
sqlite3_db_config
|
||||
sqlite3_db_handle
|
||||
sqlite3_db_mutex
|
||||
sqlite3_db_status
|
||||
sqlite3_declare_vtab
|
||||
sqlite3_enable_load_extension
|
||||
sqlite3_enable_shared_cache
|
||||
sqlite3_errcode
|
||||
sqlite3_errmsg
|
||||
sqlite3_errmsg16
|
||||
sqlite3_exec
|
||||
sqlite3_expired
|
||||
sqlite3_extended_errcode
|
||||
sqlite3_extended_result_codes
|
||||
sqlite3_file_control
|
||||
sqlite3_finalize
|
||||
sqlite3_free
|
||||
sqlite3_free_table
|
||||
sqlite3_get_autocommit
|
||||
sqlite3_get_auxdata
|
||||
sqlite3_get_table
|
||||
sqlite3_global_recover
|
||||
sqlite3_initialize
|
||||
sqlite3_interrupt
|
||||
sqlite3_last_insert_rowid
|
||||
sqlite3_libversion
|
||||
sqlite3_libversion_number
|
||||
sqlite3_limit
|
||||
sqlite3_load_extension
|
||||
sqlite3_log
|
||||
sqlite3_malloc
|
||||
sqlite3_memory_alarm
|
||||
sqlite3_memory_highwater
|
||||
sqlite3_memory_used
|
||||
sqlite3_mprintf
|
||||
sqlite3_mutex_alloc
|
||||
sqlite3_mutex_enter
|
||||
sqlite3_mutex_free
|
||||
sqlite3_mutex_leave
|
||||
sqlite3_mutex_try
|
||||
sqlite3_next_stmt
|
||||
sqlite3_open
|
||||
sqlite3_open16
|
||||
sqlite3_open_v2
|
||||
sqlite3_os_end
|
||||
sqlite3_os_init
|
||||
sqlite3_overload_function
|
||||
sqlite3_prepare
|
||||
sqlite3_prepare16
|
||||
sqlite3_prepare16_v2
|
||||
sqlite3_prepare_v2
|
||||
sqlite3_profile
|
||||
sqlite3_progress_handler
|
||||
sqlite3_randomness
|
||||
sqlite3_realloc
|
||||
sqlite3_release_memory
|
||||
sqlite3_reset
|
||||
sqlite3_reset_auto_extension
|
||||
sqlite3_result_blob
|
||||
sqlite3_result_double
|
||||
sqlite3_result_error
|
||||
sqlite3_result_error16
|
||||
sqlite3_result_error_code
|
||||
sqlite3_result_error_nomem
|
||||
sqlite3_result_error_toobig
|
||||
sqlite3_result_int
|
||||
sqlite3_result_int64
|
||||
sqlite3_result_null
|
||||
sqlite3_result_text
|
||||
sqlite3_result_text16
|
||||
sqlite3_result_text16be
|
||||
sqlite3_result_text16le
|
||||
sqlite3_result_value
|
||||
sqlite3_result_zeroblob
|
||||
sqlite3_rollback_hook
|
||||
sqlite3_set_authorizer
|
||||
sqlite3_set_auxdata
|
||||
sqlite3_shutdown
|
||||
sqlite3_sleep
|
||||
sqlite3_snprintf
|
||||
sqlite3_soft_heap_limit
|
||||
sqlite3_sourceid
|
||||
sqlite3_sql
|
||||
sqlite3_status
|
||||
sqlite3_step
|
||||
sqlite3_stmt_status
|
||||
sqlite3_strnicmp
|
||||
sqlite3_table_column_metadata
|
||||
sqlite3_test_control
|
||||
sqlite3_thread_cleanup
|
||||
sqlite3_threadsafe
|
||||
sqlite3_total_changes
|
||||
sqlite3_trace
|
||||
sqlite3_transfer_bindings
|
||||
sqlite3_update_hook
|
||||
sqlite3_user_data
|
||||
sqlite3_value_blob
|
||||
sqlite3_value_bytes
|
||||
sqlite3_value_bytes16
|
||||
sqlite3_value_double
|
||||
sqlite3_value_int
|
||||
sqlite3_value_int64
|
||||
sqlite3_value_numeric_type
|
||||
sqlite3_value_text
|
||||
sqlite3_value_text16
|
||||
sqlite3_value_text16be
|
||||
sqlite3_value_text16le
|
||||
sqlite3_value_type
|
||||
sqlite3_version
|
||||
sqlite3_vfs_find
|
||||
sqlite3_vfs_register
|
||||
sqlite3_vfs_unregister
|
||||
sqlite3_vmprintf
|
||||
sqlite3_wal_autocheckpoint
|
||||
sqlite3_wal_checkpoint
|
||||
sqlite3_wal_hook
|
||||
sqlite3_win32_mbcs_to_utf8
|
@ -1,701 +0,0 @@
|
||||
/*
|
||||
** 2006 June 7
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** This header file defines the SQLite interface for use by
|
||||
** shared libraries that want to be imported as extensions into
|
||||
** an SQLite instance. Shared libraries that intend to be loaded
|
||||
** as extensions by SQLite should #include this file instead of
|
||||
** sqlite3.h.
|
||||
*/
|
||||
#ifndef SQLITE3EXT_H
|
||||
#define SQLITE3EXT_H
|
||||
#include "sqlite3.h"
|
||||
|
||||
/*
|
||||
** The following structure holds pointers to all of the SQLite API
|
||||
** routines.
|
||||
**
|
||||
** WARNING: In order to maintain backwards compatibility, add new
|
||||
** interfaces to the end of this structure only. If you insert new
|
||||
** interfaces in the middle of this structure, then older different
|
||||
** versions of SQLite will not be able to load each other's shared
|
||||
** libraries!
|
||||
*/
|
||||
struct sqlite3_api_routines {
|
||||
void * (*aggregate_context)(sqlite3_context*,int nBytes);
|
||||
int (*aggregate_count)(sqlite3_context*);
|
||||
int (*bind_blob)(sqlite3_stmt*,int,const void*,int n,void(*)(void*));
|
||||
int (*bind_double)(sqlite3_stmt*,int,double);
|
||||
int (*bind_int)(sqlite3_stmt*,int,int);
|
||||
int (*bind_int64)(sqlite3_stmt*,int,sqlite_int64);
|
||||
int (*bind_null)(sqlite3_stmt*,int);
|
||||
int (*bind_parameter_count)(sqlite3_stmt*);
|
||||
int (*bind_parameter_index)(sqlite3_stmt*,const char*zName);
|
||||
const char * (*bind_parameter_name)(sqlite3_stmt*,int);
|
||||
int (*bind_text)(sqlite3_stmt*,int,const char*,int n,void(*)(void*));
|
||||
int (*bind_text16)(sqlite3_stmt*,int,const void*,int,void(*)(void*));
|
||||
int (*bind_value)(sqlite3_stmt*,int,const sqlite3_value*);
|
||||
int (*busy_handler)(sqlite3*,int(*)(void*,int),void*);
|
||||
int (*busy_timeout)(sqlite3*,int ms);
|
||||
int (*changes)(sqlite3*);
|
||||
int (*close)(sqlite3*);
|
||||
int (*collation_needed)(sqlite3*,void*,void(*)(void*,sqlite3*,
|
||||
int eTextRep,const char*));
|
||||
int (*collation_needed16)(sqlite3*,void*,void(*)(void*,sqlite3*,
|
||||
int eTextRep,const void*));
|
||||
const void * (*column_blob)(sqlite3_stmt*,int iCol);
|
||||
int (*column_bytes)(sqlite3_stmt*,int iCol);
|
||||
int (*column_bytes16)(sqlite3_stmt*,int iCol);
|
||||
int (*column_count)(sqlite3_stmt*pStmt);
|
||||
const char * (*column_database_name)(sqlite3_stmt*,int);
|
||||
const void * (*column_database_name16)(sqlite3_stmt*,int);
|
||||
const char * (*column_decltype)(sqlite3_stmt*,int i);
|
||||
const void * (*column_decltype16)(sqlite3_stmt*,int);
|
||||
double (*column_double)(sqlite3_stmt*,int iCol);
|
||||
int (*column_int)(sqlite3_stmt*,int iCol);
|
||||
sqlite_int64 (*column_int64)(sqlite3_stmt*,int iCol);
|
||||
const char * (*column_name)(sqlite3_stmt*,int);
|
||||
const void * (*column_name16)(sqlite3_stmt*,int);
|
||||
const char * (*column_origin_name)(sqlite3_stmt*,int);
|
||||
const void * (*column_origin_name16)(sqlite3_stmt*,int);
|
||||
const char * (*column_table_name)(sqlite3_stmt*,int);
|
||||
const void * (*column_table_name16)(sqlite3_stmt*,int);
|
||||
const unsigned char * (*column_text)(sqlite3_stmt*,int iCol);
|
||||
const void * (*column_text16)(sqlite3_stmt*,int iCol);
|
||||
int (*column_type)(sqlite3_stmt*,int iCol);
|
||||
sqlite3_value* (*column_value)(sqlite3_stmt*,int iCol);
|
||||
void * (*commit_hook)(sqlite3*,int(*)(void*),void*);
|
||||
int (*complete)(const char*sql);
|
||||
int (*complete16)(const void*sql);
|
||||
int (*create_collation)(sqlite3*,const char*,int,void*,
|
||||
int(*)(void*,int,const void*,int,const void*));
|
||||
int (*create_collation16)(sqlite3*,const void*,int,void*,
|
||||
int(*)(void*,int,const void*,int,const void*));
|
||||
int (*create_function)(sqlite3*,const char*,int,int,void*,
|
||||
void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
|
||||
void (*xStep)(sqlite3_context*,int,sqlite3_value**),
|
||||
void (*xFinal)(sqlite3_context*));
|
||||
int (*create_function16)(sqlite3*,const void*,int,int,void*,
|
||||
void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
|
||||
void (*xStep)(sqlite3_context*,int,sqlite3_value**),
|
||||
void (*xFinal)(sqlite3_context*));
|
||||
int (*create_module)(sqlite3*,const char*,const sqlite3_module*,void*);
|
||||
int (*data_count)(sqlite3_stmt*pStmt);
|
||||
sqlite3 * (*db_handle)(sqlite3_stmt*);
|
||||
int (*declare_vtab)(sqlite3*,const char*);
|
||||
int (*enable_shared_cache)(int);
|
||||
int (*errcode)(sqlite3*db);
|
||||
const char * (*errmsg)(sqlite3*);
|
||||
const void * (*errmsg16)(sqlite3*);
|
||||
int (*exec)(sqlite3*,const char*,sqlite3_callback,void*,char**);
|
||||
int (*expired)(sqlite3_stmt*);
|
||||
int (*finalize)(sqlite3_stmt*pStmt);
|
||||
void (*free)(void*);
|
||||
void (*free_table)(char**result);
|
||||
int (*get_autocommit)(sqlite3*);
|
||||
void * (*get_auxdata)(sqlite3_context*,int);
|
||||
int (*get_table)(sqlite3*,const char*,char***,int*,int*,char**);
|
||||
int (*global_recover)(void);
|
||||
void (*interruptx)(sqlite3*);
|
||||
sqlite_int64 (*last_insert_rowid)(sqlite3*);
|
||||
const char * (*libversion)(void);
|
||||
int (*libversion_number)(void);
|
||||
void *(*malloc)(int);
|
||||
char * (*mprintf)(const char*,...);
|
||||
int (*open)(const char*,sqlite3**);
|
||||
int (*open16)(const void*,sqlite3**);
|
||||
int (*prepare)(sqlite3*,const char*,int,sqlite3_stmt**,const char**);
|
||||
int (*prepare16)(sqlite3*,const void*,int,sqlite3_stmt**,const void**);
|
||||
void * (*profile)(sqlite3*,void(*)(void*,const char*,sqlite_uint64),void*);
|
||||
void (*progress_handler)(sqlite3*,int,int(*)(void*),void*);
|
||||
void *(*realloc)(void*,int);
|
||||
int (*reset)(sqlite3_stmt*pStmt);
|
||||
void (*result_blob)(sqlite3_context*,const void*,int,void(*)(void*));
|
||||
void (*result_double)(sqlite3_context*,double);
|
||||
void (*result_error)(sqlite3_context*,const char*,int);
|
||||
void (*result_error16)(sqlite3_context*,const void*,int);
|
||||
void (*result_int)(sqlite3_context*,int);
|
||||
void (*result_int64)(sqlite3_context*,sqlite_int64);
|
||||
void (*result_null)(sqlite3_context*);
|
||||
void (*result_text)(sqlite3_context*,const char*,int,void(*)(void*));
|
||||
void (*result_text16)(sqlite3_context*,const void*,int,void(*)(void*));
|
||||
void (*result_text16be)(sqlite3_context*,const void*,int,void(*)(void*));
|
||||
void (*result_text16le)(sqlite3_context*,const void*,int,void(*)(void*));
|
||||
void (*result_value)(sqlite3_context*,sqlite3_value*);
|
||||
void * (*rollback_hook)(sqlite3*,void(*)(void*),void*);
|
||||
int (*set_authorizer)(sqlite3*,int(*)(void*,int,const char*,const char*,
|
||||
const char*,const char*),void*);
|
||||
void (*set_auxdata)(sqlite3_context*,int,void*,void (*)(void*));
|
||||
char * (*xsnprintf)(int,char*,const char*,...);
|
||||
int (*step)(sqlite3_stmt*);
|
||||
int (*table_column_metadata)(sqlite3*,const char*,const char*,const char*,
|
||||
char const**,char const**,int*,int*,int*);
|
||||
void (*thread_cleanup)(void);
|
||||
int (*total_changes)(sqlite3*);
|
||||
void * (*trace)(sqlite3*,void(*xTrace)(void*,const char*),void*);
|
||||
int (*transfer_bindings)(sqlite3_stmt*,sqlite3_stmt*);
|
||||
void * (*update_hook)(sqlite3*,void(*)(void*,int ,char const*,char const*,
|
||||
sqlite_int64),void*);
|
||||
void * (*user_data)(sqlite3_context*);
|
||||
const void * (*value_blob)(sqlite3_value*);
|
||||
int (*value_bytes)(sqlite3_value*);
|
||||
int (*value_bytes16)(sqlite3_value*);
|
||||
double (*value_double)(sqlite3_value*);
|
||||
int (*value_int)(sqlite3_value*);
|
||||
sqlite_int64 (*value_int64)(sqlite3_value*);
|
||||
int (*value_numeric_type)(sqlite3_value*);
|
||||
const unsigned char * (*value_text)(sqlite3_value*);
|
||||
const void * (*value_text16)(sqlite3_value*);
|
||||
const void * (*value_text16be)(sqlite3_value*);
|
||||
const void * (*value_text16le)(sqlite3_value*);
|
||||
int (*value_type)(sqlite3_value*);
|
||||
char *(*vmprintf)(const char*,va_list);
|
||||
/* Added ??? */
|
||||
int (*overload_function)(sqlite3*, const char *zFuncName, int nArg);
|
||||
/* Added by 3.3.13 */
|
||||
int (*prepare_v2)(sqlite3*,const char*,int,sqlite3_stmt**,const char**);
|
||||
int (*prepare16_v2)(sqlite3*,const void*,int,sqlite3_stmt**,const void**);
|
||||
int (*clear_bindings)(sqlite3_stmt*);
|
||||
/* Added by 3.4.1 */
|
||||
int (*create_module_v2)(sqlite3*,const char*,const sqlite3_module*,void*,
|
||||
void (*xDestroy)(void *));
|
||||
/* Added by 3.5.0 */
|
||||
int (*bind_zeroblob)(sqlite3_stmt*,int,int);
|
||||
int (*blob_bytes)(sqlite3_blob*);
|
||||
int (*blob_close)(sqlite3_blob*);
|
||||
int (*blob_open)(sqlite3*,const char*,const char*,const char*,sqlite3_int64,
|
||||
int,sqlite3_blob**);
|
||||
int (*blob_read)(sqlite3_blob*,void*,int,int);
|
||||
int (*blob_write)(sqlite3_blob*,const void*,int,int);
|
||||
int (*create_collation_v2)(sqlite3*,const char*,int,void*,
|
||||
int(*)(void*,int,const void*,int,const void*),
|
||||
void(*)(void*));
|
||||
int (*file_control)(sqlite3*,const char*,int,void*);
|
||||
sqlite3_int64 (*memory_highwater)(int);
|
||||
sqlite3_int64 (*memory_used)(void);
|
||||
sqlite3_mutex *(*mutex_alloc)(int);
|
||||
void (*mutex_enter)(sqlite3_mutex*);
|
||||
void (*mutex_free)(sqlite3_mutex*);
|
||||
void (*mutex_leave)(sqlite3_mutex*);
|
||||
int (*mutex_try)(sqlite3_mutex*);
|
||||
int (*open_v2)(const char*,sqlite3**,int,const char*);
|
||||
int (*release_memory)(int);
|
||||
void (*result_error_nomem)(sqlite3_context*);
|
||||
void (*result_error_toobig)(sqlite3_context*);
|
||||
int (*sleep)(int);
|
||||
void (*soft_heap_limit)(int);
|
||||
sqlite3_vfs *(*vfs_find)(const char*);
|
||||
int (*vfs_register)(sqlite3_vfs*,int);
|
||||
int (*vfs_unregister)(sqlite3_vfs*);
|
||||
int (*xthreadsafe)(void);
|
||||
void (*result_zeroblob)(sqlite3_context*,int);
|
||||
void (*result_error_code)(sqlite3_context*,int);
|
||||
int (*test_control)(int, ...);
|
||||
void (*randomness)(int,void*);
|
||||
sqlite3 *(*context_db_handle)(sqlite3_context*);
|
||||
int (*extended_result_codes)(sqlite3*,int);
|
||||
int (*limit)(sqlite3*,int,int);
|
||||
sqlite3_stmt *(*next_stmt)(sqlite3*,sqlite3_stmt*);
|
||||
const char *(*sql)(sqlite3_stmt*);
|
||||
int (*status)(int,int*,int*,int);
|
||||
int (*backup_finish)(sqlite3_backup*);
|
||||
sqlite3_backup *(*backup_init)(sqlite3*,const char*,sqlite3*,const char*);
|
||||
int (*backup_pagecount)(sqlite3_backup*);
|
||||
int (*backup_remaining)(sqlite3_backup*);
|
||||
int (*backup_step)(sqlite3_backup*,int);
|
||||
const char *(*compileoption_get)(int);
|
||||
int (*compileoption_used)(const char*);
|
||||
int (*create_function_v2)(sqlite3*,const char*,int,int,void*,
|
||||
void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
|
||||
void (*xStep)(sqlite3_context*,int,sqlite3_value**),
|
||||
void (*xFinal)(sqlite3_context*),
|
||||
void(*xDestroy)(void*));
|
||||
int (*db_config)(sqlite3*,int,...);
|
||||
sqlite3_mutex *(*db_mutex)(sqlite3*);
|
||||
int (*db_status)(sqlite3*,int,int*,int*,int);
|
||||
int (*extended_errcode)(sqlite3*);
|
||||
void (*log)(int,const char*,...);
|
||||
sqlite3_int64 (*soft_heap_limit64)(sqlite3_int64);
|
||||
const char *(*sourceid)(void);
|
||||
int (*stmt_status)(sqlite3_stmt*,int,int);
|
||||
int (*strnicmp)(const char*,const char*,int);
|
||||
int (*unlock_notify)(sqlite3*,void(*)(void**,int),void*);
|
||||
int (*wal_autocheckpoint)(sqlite3*,int);
|
||||
int (*wal_checkpoint)(sqlite3*,const char*);
|
||||
void *(*wal_hook)(sqlite3*,int(*)(void*,sqlite3*,const char*,int),void*);
|
||||
int (*blob_reopen)(sqlite3_blob*,sqlite3_int64);
|
||||
int (*vtab_config)(sqlite3*,int op,...);
|
||||
int (*vtab_on_conflict)(sqlite3*);
|
||||
/* Version 3.7.16 and later */
|
||||
int (*close_v2)(sqlite3*);
|
||||
const char *(*db_filename)(sqlite3*,const char*);
|
||||
int (*db_readonly)(sqlite3*,const char*);
|
||||
int (*db_release_memory)(sqlite3*);
|
||||
const char *(*errstr)(int);
|
||||
int (*stmt_busy)(sqlite3_stmt*);
|
||||
int (*stmt_readonly)(sqlite3_stmt*);
|
||||
int (*stricmp)(const char*,const char*);
|
||||
int (*uri_boolean)(const char*,const char*,int);
|
||||
sqlite3_int64 (*uri_int64)(const char*,const char*,sqlite3_int64);
|
||||
const char *(*uri_parameter)(const char*,const char*);
|
||||
char *(*xvsnprintf)(int,char*,const char*,va_list);
|
||||
int (*wal_checkpoint_v2)(sqlite3*,const char*,int,int*,int*);
|
||||
/* Version 3.8.7 and later */
|
||||
int (*auto_extension)(void(*)(void));
|
||||
int (*bind_blob64)(sqlite3_stmt*,int,const void*,sqlite3_uint64,
|
||||
void(*)(void*));
|
||||
int (*bind_text64)(sqlite3_stmt*,int,const char*,sqlite3_uint64,
|
||||
void(*)(void*),unsigned char);
|
||||
int (*cancel_auto_extension)(void(*)(void));
|
||||
int (*load_extension)(sqlite3*,const char*,const char*,char**);
|
||||
void *(*malloc64)(sqlite3_uint64);
|
||||
sqlite3_uint64 (*msize)(void*);
|
||||
void *(*realloc64)(void*,sqlite3_uint64);
|
||||
void (*reset_auto_extension)(void);
|
||||
void (*result_blob64)(sqlite3_context*,const void*,sqlite3_uint64,
|
||||
void(*)(void*));
|
||||
void (*result_text64)(sqlite3_context*,const char*,sqlite3_uint64,
|
||||
void(*)(void*), unsigned char);
|
||||
int (*strglob)(const char*,const char*);
|
||||
/* Version 3.8.11 and later */
|
||||
sqlite3_value *(*value_dup)(const sqlite3_value*);
|
||||
void (*value_free)(sqlite3_value*);
|
||||
int (*result_zeroblob64)(sqlite3_context*,sqlite3_uint64);
|
||||
int (*bind_zeroblob64)(sqlite3_stmt*, int, sqlite3_uint64);
|
||||
/* Version 3.9.0 and later */
|
||||
unsigned int (*value_subtype)(sqlite3_value*);
|
||||
void (*result_subtype)(sqlite3_context*,unsigned int);
|
||||
/* Version 3.10.0 and later */
|
||||
int (*status64)(int,sqlite3_int64*,sqlite3_int64*,int);
|
||||
int (*strlike)(const char*,const char*,unsigned int);
|
||||
int (*db_cacheflush)(sqlite3*);
|
||||
/* Version 3.12.0 and later */
|
||||
int (*system_errno)(sqlite3*);
|
||||
/* Version 3.14.0 and later */
|
||||
int (*trace_v2)(sqlite3*,unsigned,int(*)(unsigned,void*,void*,void*),void*);
|
||||
char *(*expanded_sql)(sqlite3_stmt*);
|
||||
/* Version 3.18.0 and later */
|
||||
void (*set_last_insert_rowid)(sqlite3*,sqlite3_int64);
|
||||
/* Version 3.20.0 and later */
|
||||
int (*prepare_v3)(sqlite3*,const char*,int,unsigned int,
|
||||
sqlite3_stmt**,const char**);
|
||||
int (*prepare16_v3)(sqlite3*,const void*,int,unsigned int,
|
||||
sqlite3_stmt**,const void**);
|
||||
int (*bind_pointer)(sqlite3_stmt*,int,void*,const char*,void(*)(void*));
|
||||
void (*result_pointer)(sqlite3_context*,void*,const char*,void(*)(void*));
|
||||
void *(*value_pointer)(sqlite3_value*,const char*);
|
||||
int (*vtab_nochange)(sqlite3_context*);
|
||||
int (*value_nochange)(sqlite3_value*);
|
||||
const char *(*vtab_collation)(sqlite3_index_info*,int);
|
||||
/* Version 3.24.0 and later */
|
||||
int (*keyword_count)(void);
|
||||
int (*keyword_name)(int,const char**,int*);
|
||||
int (*keyword_check)(const char*,int);
|
||||
sqlite3_str *(*str_new)(sqlite3*);
|
||||
char *(*str_finish)(sqlite3_str*);
|
||||
void (*str_appendf)(sqlite3_str*, const char *zFormat, ...);
|
||||
void (*str_vappendf)(sqlite3_str*, const char *zFormat, va_list);
|
||||
void (*str_append)(sqlite3_str*, const char *zIn, int N);
|
||||
void (*str_appendall)(sqlite3_str*, const char *zIn);
|
||||
void (*str_appendchar)(sqlite3_str*, int N, char C);
|
||||
void (*str_reset)(sqlite3_str*);
|
||||
int (*str_errcode)(sqlite3_str*);
|
||||
int (*str_length)(sqlite3_str*);
|
||||
char *(*str_value)(sqlite3_str*);
|
||||
/* Version 3.25.0 and later */
|
||||
int (*create_window_function)(sqlite3*,const char*,int,int,void*,
|
||||
void (*xStep)(sqlite3_context*,int,sqlite3_value**),
|
||||
void (*xFinal)(sqlite3_context*),
|
||||
void (*xValue)(sqlite3_context*),
|
||||
void (*xInv)(sqlite3_context*,int,sqlite3_value**),
|
||||
void(*xDestroy)(void*));
|
||||
/* Version 3.26.0 and later */
|
||||
const char *(*normalized_sql)(sqlite3_stmt*);
|
||||
/* Version 3.28.0 and later */
|
||||
int (*stmt_isexplain)(sqlite3_stmt*);
|
||||
int (*value_frombind)(sqlite3_value*);
|
||||
/* Version 3.30.0 and later */
|
||||
int (*drop_modules)(sqlite3*,const char**);
|
||||
/* Version 3.31.0 and later */
|
||||
sqlite3_int64 (*hard_heap_limit64)(sqlite3_int64);
|
||||
const char *(*uri_key)(const char*,int);
|
||||
const char *(*filename_database)(const char*);
|
||||
const char *(*filename_journal)(const char*);
|
||||
const char *(*filename_wal)(const char*);
|
||||
/* Version 3.32.0 and later */
|
||||
char *(*create_filename)(const char*,const char*,const char*,
|
||||
int,const char**);
|
||||
void (*free_filename)(char*);
|
||||
sqlite3_file *(*database_file_object)(const char*);
|
||||
/* Version 3.34.0 and later */
|
||||
int (*txn_state)(sqlite3*,const char*);
|
||||
/* Version 3.36.1 and later */
|
||||
sqlite3_int64 (*changes64)(sqlite3*);
|
||||
sqlite3_int64 (*total_changes64)(sqlite3*);
|
||||
/* Version 3.37.0 and later */
|
||||
int (*autovacuum_pages)(sqlite3*,
|
||||
unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int),
|
||||
void*, void(*)(void*));
|
||||
/* Version 3.38.0 and later */
|
||||
int (*error_offset)(sqlite3*);
|
||||
int (*vtab_rhs_value)(sqlite3_index_info*,int,sqlite3_value**);
|
||||
int (*vtab_distinct)(sqlite3_index_info*);
|
||||
int (*vtab_in)(sqlite3_index_info*,int,int);
|
||||
int (*vtab_in_first)(sqlite3_value*,sqlite3_value**);
|
||||
int (*vtab_in_next)(sqlite3_value*,sqlite3_value**);
|
||||
/* Version 3.39.0 and later */
|
||||
int (*deserialize)(sqlite3*,const char*,unsigned char*,
|
||||
sqlite3_int64,sqlite3_int64,unsigned);
|
||||
unsigned char *(*serialize)(sqlite3*,const char *,sqlite3_int64*,
|
||||
unsigned int);
|
||||
const char *(*db_name)(sqlite3*,int);
|
||||
};
|
||||
|
||||
/*
|
||||
** This is the function signature used for all extension entry points. It
|
||||
** is also defined in the file "loadext.c".
|
||||
*/
|
||||
typedef int (*sqlite3_loadext_entry)(
|
||||
sqlite3 *db, /* Handle to the database. */
|
||||
char **pzErrMsg, /* Used to set error string on failure. */
|
||||
const sqlite3_api_routines *pThunk /* Extension API function pointers. */
|
||||
);
|
||||
|
||||
/*
|
||||
** The following macros redefine the API routines so that they are
|
||||
** redirected through the global sqlite3_api structure.
|
||||
**
|
||||
** This header file is also used by the loadext.c source file
|
||||
** (part of the main SQLite library - not an extension) so that
|
||||
** it can get access to the sqlite3_api_routines structure
|
||||
** definition. But the main library does not want to redefine
|
||||
** the API. So the redefinition macros are only valid if the
|
||||
** SQLITE_CORE macros is undefined.
|
||||
*/
|
||||
#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
|
||||
#define sqlite3_aggregate_context sqlite3_api->aggregate_context
|
||||
#ifndef SQLITE_OMIT_DEPRECATED
|
||||
#define sqlite3_aggregate_count sqlite3_api->aggregate_count
|
||||
#endif
|
||||
#define sqlite3_bind_blob sqlite3_api->bind_blob
|
||||
#define sqlite3_bind_double sqlite3_api->bind_double
|
||||
#define sqlite3_bind_int sqlite3_api->bind_int
|
||||
#define sqlite3_bind_int64 sqlite3_api->bind_int64
|
||||
#define sqlite3_bind_null sqlite3_api->bind_null
|
||||
#define sqlite3_bind_parameter_count sqlite3_api->bind_parameter_count
|
||||
#define sqlite3_bind_parameter_index sqlite3_api->bind_parameter_index
|
||||
#define sqlite3_bind_parameter_name sqlite3_api->bind_parameter_name
|
||||
#define sqlite3_bind_text sqlite3_api->bind_text
|
||||
#define sqlite3_bind_text16 sqlite3_api->bind_text16
|
||||
#define sqlite3_bind_value sqlite3_api->bind_value
|
||||
#define sqlite3_busy_handler sqlite3_api->busy_handler
|
||||
#define sqlite3_busy_timeout sqlite3_api->busy_timeout
|
||||
#define sqlite3_changes sqlite3_api->changes
|
||||
#define sqlite3_close sqlite3_api->close
|
||||
#define sqlite3_collation_needed sqlite3_api->collation_needed
|
||||
#define sqlite3_collation_needed16 sqlite3_api->collation_needed16
|
||||
#define sqlite3_column_blob sqlite3_api->column_blob
|
||||
#define sqlite3_column_bytes sqlite3_api->column_bytes
|
||||
#define sqlite3_column_bytes16 sqlite3_api->column_bytes16
|
||||
#define sqlite3_column_count sqlite3_api->column_count
|
||||
#define sqlite3_column_database_name sqlite3_api->column_database_name
|
||||
#define sqlite3_column_database_name16 sqlite3_api->column_database_name16
|
||||
#define sqlite3_column_decltype sqlite3_api->column_decltype
|
||||
#define sqlite3_column_decltype16 sqlite3_api->column_decltype16
|
||||
#define sqlite3_column_double sqlite3_api->column_double
|
||||
#define sqlite3_column_int sqlite3_api->column_int
|
||||
#define sqlite3_column_int64 sqlite3_api->column_int64
|
||||
#define sqlite3_column_name sqlite3_api->column_name
|
||||
#define sqlite3_column_name16 sqlite3_api->column_name16
|
||||
#define sqlite3_column_origin_name sqlite3_api->column_origin_name
|
||||
#define sqlite3_column_origin_name16 sqlite3_api->column_origin_name16
|
||||
#define sqlite3_column_table_name sqlite3_api->column_table_name
|
||||
#define sqlite3_column_table_name16 sqlite3_api->column_table_name16
|
||||
#define sqlite3_column_text sqlite3_api->column_text
|
||||
#define sqlite3_column_text16 sqlite3_api->column_text16
|
||||
#define sqlite3_column_type sqlite3_api->column_type
|
||||
#define sqlite3_column_value sqlite3_api->column_value
|
||||
#define sqlite3_commit_hook sqlite3_api->commit_hook
|
||||
#define sqlite3_complete sqlite3_api->complete
|
||||
#define sqlite3_complete16 sqlite3_api->complete16
|
||||
#define sqlite3_create_collation sqlite3_api->create_collation
|
||||
#define sqlite3_create_collation16 sqlite3_api->create_collation16
|
||||
#define sqlite3_create_function sqlite3_api->create_function
|
||||
#define sqlite3_create_function16 sqlite3_api->create_function16
|
||||
#define sqlite3_create_module sqlite3_api->create_module
|
||||
#define sqlite3_create_module_v2 sqlite3_api->create_module_v2
|
||||
#define sqlite3_data_count sqlite3_api->data_count
|
||||
#define sqlite3_db_handle sqlite3_api->db_handle
|
||||
#define sqlite3_declare_vtab sqlite3_api->declare_vtab
|
||||
#define sqlite3_enable_shared_cache sqlite3_api->enable_shared_cache
|
||||
#define sqlite3_errcode sqlite3_api->errcode
|
||||
#define sqlite3_errmsg sqlite3_api->errmsg
|
||||
#define sqlite3_errmsg16 sqlite3_api->errmsg16
|
||||
#define sqlite3_exec sqlite3_api->exec
|
||||
#ifndef SQLITE_OMIT_DEPRECATED
|
||||
#define sqlite3_expired sqlite3_api->expired
|
||||
#endif
|
||||
#define sqlite3_finalize sqlite3_api->finalize
|
||||
#define sqlite3_free sqlite3_api->free
|
||||
#define sqlite3_free_table sqlite3_api->free_table
|
||||
#define sqlite3_get_autocommit sqlite3_api->get_autocommit
|
||||
#define sqlite3_get_auxdata sqlite3_api->get_auxdata
|
||||
#define sqlite3_get_table sqlite3_api->get_table
|
||||
#ifndef SQLITE_OMIT_DEPRECATED
|
||||
#define sqlite3_global_recover sqlite3_api->global_recover
|
||||
#endif
|
||||
#define sqlite3_interrupt sqlite3_api->interruptx
|
||||
#define sqlite3_last_insert_rowid sqlite3_api->last_insert_rowid
|
||||
#define sqlite3_libversion sqlite3_api->libversion
|
||||
#define sqlite3_libversion_number sqlite3_api->libversion_number
|
||||
#define sqlite3_malloc sqlite3_api->malloc
|
||||
#define sqlite3_mprintf sqlite3_api->mprintf
|
||||
#define sqlite3_open sqlite3_api->open
|
||||
#define sqlite3_open16 sqlite3_api->open16
|
||||
#define sqlite3_prepare sqlite3_api->prepare
|
||||
#define sqlite3_prepare16 sqlite3_api->prepare16
|
||||
#define sqlite3_prepare_v2 sqlite3_api->prepare_v2
|
||||
#define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2
|
||||
#define sqlite3_profile sqlite3_api->profile
|
||||
#define sqlite3_progress_handler sqlite3_api->progress_handler
|
||||
#define sqlite3_realloc sqlite3_api->realloc
|
||||
#define sqlite3_reset sqlite3_api->reset
|
||||
#define sqlite3_result_blob sqlite3_api->result_blob
|
||||
#define sqlite3_result_double sqlite3_api->result_double
|
||||
#define sqlite3_result_error sqlite3_api->result_error
|
||||
#define sqlite3_result_error16 sqlite3_api->result_error16
|
||||
#define sqlite3_result_int sqlite3_api->result_int
|
||||
#define sqlite3_result_int64 sqlite3_api->result_int64
|
||||
#define sqlite3_result_null sqlite3_api->result_null
|
||||
#define sqlite3_result_text sqlite3_api->result_text
|
||||
#define sqlite3_result_text16 sqlite3_api->result_text16
|
||||
#define sqlite3_result_text16be sqlite3_api->result_text16be
|
||||
#define sqlite3_result_text16le sqlite3_api->result_text16le
|
||||
#define sqlite3_result_value sqlite3_api->result_value
|
||||
#define sqlite3_rollback_hook sqlite3_api->rollback_hook
|
||||
#define sqlite3_set_authorizer sqlite3_api->set_authorizer
|
||||
#define sqlite3_set_auxdata sqlite3_api->set_auxdata
|
||||
#define sqlite3_snprintf sqlite3_api->xsnprintf
|
||||
#define sqlite3_step sqlite3_api->step
|
||||
#define sqlite3_table_column_metadata sqlite3_api->table_column_metadata
|
||||
#define sqlite3_thread_cleanup sqlite3_api->thread_cleanup
|
||||
#define sqlite3_total_changes sqlite3_api->total_changes
|
||||
#define sqlite3_trace sqlite3_api->trace
|
||||
#ifndef SQLITE_OMIT_DEPRECATED
|
||||
#define sqlite3_transfer_bindings sqlite3_api->transfer_bindings
|
||||
#endif
|
||||
#define sqlite3_update_hook sqlite3_api->update_hook
|
||||
#define sqlite3_user_data sqlite3_api->user_data
|
||||
#define sqlite3_value_blob sqlite3_api->value_blob
|
||||
#define sqlite3_value_bytes sqlite3_api->value_bytes
|
||||
#define sqlite3_value_bytes16 sqlite3_api->value_bytes16
|
||||
#define sqlite3_value_double sqlite3_api->value_double
|
||||
#define sqlite3_value_int sqlite3_api->value_int
|
||||
#define sqlite3_value_int64 sqlite3_api->value_int64
|
||||
#define sqlite3_value_numeric_type sqlite3_api->value_numeric_type
|
||||
#define sqlite3_value_text sqlite3_api->value_text
|
||||
#define sqlite3_value_text16 sqlite3_api->value_text16
|
||||
#define sqlite3_value_text16be sqlite3_api->value_text16be
|
||||
#define sqlite3_value_text16le sqlite3_api->value_text16le
|
||||
#define sqlite3_value_type sqlite3_api->value_type
|
||||
#define sqlite3_vmprintf sqlite3_api->vmprintf
|
||||
#define sqlite3_vsnprintf sqlite3_api->xvsnprintf
|
||||
#define sqlite3_overload_function sqlite3_api->overload_function
|
||||
#define sqlite3_prepare_v2 sqlite3_api->prepare_v2
|
||||
#define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2
|
||||
#define sqlite3_clear_bindings sqlite3_api->clear_bindings
|
||||
#define sqlite3_bind_zeroblob sqlite3_api->bind_zeroblob
|
||||
#define sqlite3_blob_bytes sqlite3_api->blob_bytes
|
||||
#define sqlite3_blob_close sqlite3_api->blob_close
|
||||
#define sqlite3_blob_open sqlite3_api->blob_open
|
||||
#define sqlite3_blob_read sqlite3_api->blob_read
|
||||
#define sqlite3_blob_write sqlite3_api->blob_write
|
||||
#define sqlite3_create_collation_v2 sqlite3_api->create_collation_v2
|
||||
#define sqlite3_file_control sqlite3_api->file_control
|
||||
#define sqlite3_memory_highwater sqlite3_api->memory_highwater
|
||||
#define sqlite3_memory_used sqlite3_api->memory_used
|
||||
#define sqlite3_mutex_alloc sqlite3_api->mutex_alloc
|
||||
#define sqlite3_mutex_enter sqlite3_api->mutex_enter
|
||||
#define sqlite3_mutex_free sqlite3_api->mutex_free
|
||||
#define sqlite3_mutex_leave sqlite3_api->mutex_leave
|
||||
#define sqlite3_mutex_try sqlite3_api->mutex_try
|
||||
#define sqlite3_open_v2 sqlite3_api->open_v2
|
||||
#define sqlite3_release_memory sqlite3_api->release_memory
|
||||
#define sqlite3_result_error_nomem sqlite3_api->result_error_nomem
|
||||
#define sqlite3_result_error_toobig sqlite3_api->result_error_toobig
|
||||
#define sqlite3_sleep sqlite3_api->sleep
|
||||
#define sqlite3_soft_heap_limit sqlite3_api->soft_heap_limit
|
||||
#define sqlite3_vfs_find sqlite3_api->vfs_find
|
||||
#define sqlite3_vfs_register sqlite3_api->vfs_register
|
||||
#define sqlite3_vfs_unregister sqlite3_api->vfs_unregister
|
||||
#define sqlite3_threadsafe sqlite3_api->xthreadsafe
|
||||
#define sqlite3_result_zeroblob sqlite3_api->result_zeroblob
|
||||
#define sqlite3_result_error_code sqlite3_api->result_error_code
|
||||
#define sqlite3_test_control sqlite3_api->test_control
|
||||
#define sqlite3_randomness sqlite3_api->randomness
|
||||
#define sqlite3_context_db_handle sqlite3_api->context_db_handle
|
||||
#define sqlite3_extended_result_codes sqlite3_api->extended_result_codes
|
||||
#define sqlite3_limit sqlite3_api->limit
|
||||
#define sqlite3_next_stmt sqlite3_api->next_stmt
|
||||
#define sqlite3_sql sqlite3_api->sql
|
||||
#define sqlite3_status sqlite3_api->status
|
||||
#define sqlite3_backup_finish sqlite3_api->backup_finish
|
||||
#define sqlite3_backup_init sqlite3_api->backup_init
|
||||
#define sqlite3_backup_pagecount sqlite3_api->backup_pagecount
|
||||
#define sqlite3_backup_remaining sqlite3_api->backup_remaining
|
||||
#define sqlite3_backup_step sqlite3_api->backup_step
|
||||
#define sqlite3_compileoption_get sqlite3_api->compileoption_get
|
||||
#define sqlite3_compileoption_used sqlite3_api->compileoption_used
|
||||
#define sqlite3_create_function_v2 sqlite3_api->create_function_v2
|
||||
#define sqlite3_db_config sqlite3_api->db_config
|
||||
#define sqlite3_db_mutex sqlite3_api->db_mutex
|
||||
#define sqlite3_db_status sqlite3_api->db_status
|
||||
#define sqlite3_extended_errcode sqlite3_api->extended_errcode
|
||||
#define sqlite3_log sqlite3_api->log
|
||||
#define sqlite3_soft_heap_limit64 sqlite3_api->soft_heap_limit64
|
||||
#define sqlite3_sourceid sqlite3_api->sourceid
|
||||
#define sqlite3_stmt_status sqlite3_api->stmt_status
|
||||
#define sqlite3_strnicmp sqlite3_api->strnicmp
|
||||
#define sqlite3_unlock_notify sqlite3_api->unlock_notify
|
||||
#define sqlite3_wal_autocheckpoint sqlite3_api->wal_autocheckpoint
|
||||
#define sqlite3_wal_checkpoint sqlite3_api->wal_checkpoint
|
||||
#define sqlite3_wal_hook sqlite3_api->wal_hook
|
||||
#define sqlite3_blob_reopen sqlite3_api->blob_reopen
|
||||
#define sqlite3_vtab_config sqlite3_api->vtab_config
|
||||
#define sqlite3_vtab_on_conflict sqlite3_api->vtab_on_conflict
|
||||
/* Version 3.7.16 and later */
|
||||
#define sqlite3_close_v2 sqlite3_api->close_v2
|
||||
#define sqlite3_db_filename sqlite3_api->db_filename
|
||||
#define sqlite3_db_readonly sqlite3_api->db_readonly
|
||||
#define sqlite3_db_release_memory sqlite3_api->db_release_memory
|
||||
#define sqlite3_errstr sqlite3_api->errstr
|
||||
#define sqlite3_stmt_busy sqlite3_api->stmt_busy
|
||||
#define sqlite3_stmt_readonly sqlite3_api->stmt_readonly
|
||||
#define sqlite3_stricmp sqlite3_api->stricmp
|
||||
#define sqlite3_uri_boolean sqlite3_api->uri_boolean
|
||||
#define sqlite3_uri_int64 sqlite3_api->uri_int64
|
||||
#define sqlite3_uri_parameter sqlite3_api->uri_parameter
|
||||
#define sqlite3_uri_vsnprintf sqlite3_api->xvsnprintf
|
||||
#define sqlite3_wal_checkpoint_v2 sqlite3_api->wal_checkpoint_v2
|
||||
/* Version 3.8.7 and later */
|
||||
#define sqlite3_auto_extension sqlite3_api->auto_extension
|
||||
#define sqlite3_bind_blob64 sqlite3_api->bind_blob64
|
||||
#define sqlite3_bind_text64 sqlite3_api->bind_text64
|
||||
#define sqlite3_cancel_auto_extension sqlite3_api->cancel_auto_extension
|
||||
#define sqlite3_load_extension sqlite3_api->load_extension
|
||||
#define sqlite3_malloc64 sqlite3_api->malloc64
|
||||
#define sqlite3_msize sqlite3_api->msize
|
||||
#define sqlite3_realloc64 sqlite3_api->realloc64
|
||||
#define sqlite3_reset_auto_extension sqlite3_api->reset_auto_extension
|
||||
#define sqlite3_result_blob64 sqlite3_api->result_blob64
|
||||
#define sqlite3_result_text64 sqlite3_api->result_text64
|
||||
#define sqlite3_strglob sqlite3_api->strglob
|
||||
/* Version 3.8.11 and later */
|
||||
#define sqlite3_value_dup sqlite3_api->value_dup
|
||||
#define sqlite3_value_free sqlite3_api->value_free
|
||||
#define sqlite3_result_zeroblob64 sqlite3_api->result_zeroblob64
|
||||
#define sqlite3_bind_zeroblob64 sqlite3_api->bind_zeroblob64
|
||||
/* Version 3.9.0 and later */
|
||||
#define sqlite3_value_subtype sqlite3_api->value_subtype
|
||||
#define sqlite3_result_subtype sqlite3_api->result_subtype
|
||||
/* Version 3.10.0 and later */
|
||||
#define sqlite3_status64 sqlite3_api->status64
|
||||
#define sqlite3_strlike sqlite3_api->strlike
|
||||
#define sqlite3_db_cacheflush sqlite3_api->db_cacheflush
|
||||
/* Version 3.12.0 and later */
|
||||
#define sqlite3_system_errno sqlite3_api->system_errno
|
||||
/* Version 3.14.0 and later */
|
||||
#define sqlite3_trace_v2 sqlite3_api->trace_v2
|
||||
#define sqlite3_expanded_sql sqlite3_api->expanded_sql
|
||||
/* Version 3.18.0 and later */
|
||||
#define sqlite3_set_last_insert_rowid sqlite3_api->set_last_insert_rowid
|
||||
/* Version 3.20.0 and later */
|
||||
#define sqlite3_prepare_v3 sqlite3_api->prepare_v3
|
||||
#define sqlite3_prepare16_v3 sqlite3_api->prepare16_v3
|
||||
#define sqlite3_bind_pointer sqlite3_api->bind_pointer
|
||||
#define sqlite3_result_pointer sqlite3_api->result_pointer
|
||||
#define sqlite3_value_pointer sqlite3_api->value_pointer
|
||||
/* Version 3.22.0 and later */
|
||||
#define sqlite3_vtab_nochange sqlite3_api->vtab_nochange
|
||||
#define sqlite3_value_nochange sqlite3_api->value_nochange
|
||||
#define sqlite3_vtab_collation sqlite3_api->vtab_collation
|
||||
/* Version 3.24.0 and later */
|
||||
#define sqlite3_keyword_count sqlite3_api->keyword_count
|
||||
#define sqlite3_keyword_name sqlite3_api->keyword_name
|
||||
#define sqlite3_keyword_check sqlite3_api->keyword_check
|
||||
#define sqlite3_str_new sqlite3_api->str_new
|
||||
#define sqlite3_str_finish sqlite3_api->str_finish
|
||||
#define sqlite3_str_appendf sqlite3_api->str_appendf
|
||||
#define sqlite3_str_vappendf sqlite3_api->str_vappendf
|
||||
#define sqlite3_str_append sqlite3_api->str_append
|
||||
#define sqlite3_str_appendall sqlite3_api->str_appendall
|
||||
#define sqlite3_str_appendchar sqlite3_api->str_appendchar
|
||||
#define sqlite3_str_reset sqlite3_api->str_reset
|
||||
#define sqlite3_str_errcode sqlite3_api->str_errcode
|
||||
#define sqlite3_str_length sqlite3_api->str_length
|
||||
#define sqlite3_str_value sqlite3_api->str_value
|
||||
/* Version 3.25.0 and later */
|
||||
#define sqlite3_create_window_function sqlite3_api->create_window_function
|
||||
/* Version 3.26.0 and later */
|
||||
#define sqlite3_normalized_sql sqlite3_api->normalized_sql
|
||||
/* Version 3.28.0 and later */
|
||||
#define sqlite3_stmt_isexplain sqlite3_api->stmt_isexplain
|
||||
#define sqlite3_value_frombind sqlite3_api->value_frombind
|
||||
/* Version 3.30.0 and later */
|
||||
#define sqlite3_drop_modules sqlite3_api->drop_modules
|
||||
/* Version 3.31.0 and later */
|
||||
#define sqlite3_hard_heap_limit64 sqlite3_api->hard_heap_limit64
|
||||
#define sqlite3_uri_key sqlite3_api->uri_key
|
||||
#define sqlite3_filename_database sqlite3_api->filename_database
|
||||
#define sqlite3_filename_journal sqlite3_api->filename_journal
|
||||
#define sqlite3_filename_wal sqlite3_api->filename_wal
|
||||
/* Version 3.32.0 and later */
|
||||
#define sqlite3_create_filename sqlite3_api->create_filename
|
||||
#define sqlite3_free_filename sqlite3_api->free_filename
|
||||
#define sqlite3_database_file_object sqlite3_api->database_file_object
|
||||
/* Version 3.34.0 and later */
|
||||
#define sqlite3_txn_state sqlite3_api->txn_state
|
||||
/* Version 3.36.1 and later */
|
||||
#define sqlite3_changes64 sqlite3_api->changes64
|
||||
#define sqlite3_total_changes64 sqlite3_api->total_changes64
|
||||
/* Version 3.37.0 and later */
|
||||
#define sqlite3_autovacuum_pages sqlite3_api->autovacuum_pages
|
||||
/* Version 3.38.0 and later */
|
||||
#define sqlite3_error_offset sqlite3_api->error_offset
|
||||
#define sqlite3_vtab_rhs_value sqlite3_api->vtab_rhs_value
|
||||
#define sqlite3_vtab_distinct sqlite3_api->vtab_distinct
|
||||
#define sqlite3_vtab_in sqlite3_api->vtab_in
|
||||
#define sqlite3_vtab_in_first sqlite3_api->vtab_in_first
|
||||
#define sqlite3_vtab_in_next sqlite3_api->vtab_in_next
|
||||
/* Version 3.39.0 and later */
|
||||
#ifndef SQLITE_OMIT_DESERIALIZE
|
||||
#define sqlite3_deserialize sqlite3_api->deserialize
|
||||
#define sqlite3_serialize sqlite3_api->serialize
|
||||
#endif
|
||||
#define sqlite3_db_name sqlite3_api->db_name
|
||||
#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
|
||||
|
||||
#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
|
||||
/* This case when the file really is being compiled as a loadable
|
||||
** extension */
|
||||
# define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api=0;
|
||||
# define SQLITE_EXTENSION_INIT2(v) sqlite3_api=v;
|
||||
# define SQLITE_EXTENSION_INIT3 \
|
||||
extern const sqlite3_api_routines *sqlite3_api;
|
||||
#else
|
||||
/* This case when the file is being statically linked into the
|
||||
** application */
|
||||
# define SQLITE_EXTENSION_INIT1 /*no-op*/
|
||||
# define SQLITE_EXTENSION_INIT2(v) (void)v; /* unused parameter */
|
||||
# define SQLITE_EXTENSION_INIT3 /*no-op*/
|
||||
#endif
|
||||
|
||||
#endif /* SQLITE3EXT_H */
|
@ -1,104 +0,0 @@
|
||||
#include "sqlite3_connection.h"
|
||||
|
||||
#include "core/string/print_string.h"
|
||||
#include "core/string/ustring.h"
|
||||
#include "sqlite3_query_builder.h"
|
||||
#include "sqlite3_query_result.h"
|
||||
#include "sqlite3_table_builder.h"
|
||||
|
||||
#include "./sqlite/sqlite3.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
Ref<QueryBuilder> SQLite3DatabaseConnection::get_query_builder() {
|
||||
Ref<SQLite3QueryBuilder> b;
|
||||
b.instance();
|
||||
b->_connection.reference_ptr(this);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
Ref<TableBuilder> SQLite3DatabaseConnection::get_table_builder() {
|
||||
Ref<SQLite3TableBuilder> b;
|
||||
b.instance();
|
||||
b->_connection.reference_ptr(this);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
void SQLite3DatabaseConnection::database_connect(const String &connection_str) {
|
||||
int ret = sqlite3_config(SQLITE_CONFIG_SERIALIZED);
|
||||
//if (ret != SQLITE_OK) {
|
||||
//ERR_PRINT("SQLITE3 multithreading is not supported!\n");
|
||||
//}
|
||||
|
||||
//CharString cstr = connection_str.ascii();
|
||||
CharString cstr = connection_str.utf8();
|
||||
|
||||
ret = sqlite3_open(cstr.get_data(), &conn);
|
||||
|
||||
if (ret != SQLITE_OK) {
|
||||
ERR_PRINT(vformat("SQLITE3 database_connect failed! code: %d !", ret));
|
||||
}
|
||||
}
|
||||
|
||||
Ref<QueryResult> SQLite3DatabaseConnection::query(const String &query) {
|
||||
Ref<Sqlite3QueryResult> res;
|
||||
res.instance();
|
||||
|
||||
res->query(query, conn);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void SQLite3DatabaseConnection::query_run(const String &query) {
|
||||
char *err_msg;
|
||||
|
||||
CharString q = query.utf8();
|
||||
|
||||
if (sqlite3_exec(conn, q.get_data(), NULL, NULL, &err_msg) != SQLITE_OK) {
|
||||
ERR_PRINT("SQLite3Database::query_run error:");
|
||||
ERR_PRINT("Query: " + query);
|
||||
ERR_PRINT("Error: " + String(err_msg));
|
||||
sqlite3_free(err_msg);
|
||||
}
|
||||
}
|
||||
|
||||
String SQLite3DatabaseConnection::escape(const String &str) {
|
||||
char *ret;
|
||||
|
||||
CharString q = str.utf8();
|
||||
|
||||
ret = sqlite3_mprintf("%q", q.get_data());
|
||||
|
||||
if (ret) {
|
||||
String res(ret);
|
||||
|
||||
sqlite3_free(ret);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
void SQLite3DatabaseConnection::escape_to(const String &str, String *to) {
|
||||
char *ret;
|
||||
|
||||
ret = sqlite3_mprintf("%q", str.utf8().get_data());
|
||||
|
||||
if (ret) {
|
||||
to->operator=(ret);
|
||||
|
||||
sqlite3_free(ret);
|
||||
}
|
||||
}
|
||||
|
||||
SQLite3DatabaseConnection::SQLite3DatabaseConnection() {
|
||||
conn = nullptr;
|
||||
}
|
||||
|
||||
SQLite3DatabaseConnection::~SQLite3DatabaseConnection() {
|
||||
if (conn) {
|
||||
sqlite3_close(conn);
|
||||
}
|
||||
}
|