mirror of
https://github.com/godotengine/godot.git
synced 2025-10-23 09:53:25 +00:00
A Whole New World (clang-format edition)
I can show you the code Pretty, with proper whitespace Tell me, coder, now when did You last write readable code? I can open your eyes Make you see your bad indent Force you to respect the style The core devs agreed upon A whole new world A new fantastic code format A de facto standard With some sugar Enforced with clang-format A whole new world A dazzling style we all dreamed of And when we read it through It's crystal clear That now we're in a whole new world of code
This commit is contained in:
parent
45438e9918
commit
5dbf1809c6
1318 changed files with 140051 additions and 166004 deletions
|
@ -46,7 +46,6 @@ class BalloonAllocator {
|
|||
uint32_t hand;
|
||||
};
|
||||
|
||||
|
||||
struct Hand {
|
||||
|
||||
int used;
|
||||
|
@ -55,13 +54,9 @@ class BalloonAllocator {
|
|||
Balloon *last;
|
||||
};
|
||||
|
||||
|
||||
Hand hands[MAX_HANDS];
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
||||
void *alloc(size_t p_size) {
|
||||
|
||||
size_t max = (1 << MAX_HANDS);
|
||||
|
@ -69,7 +64,8 @@ public:
|
|||
|
||||
unsigned int hand = 0;
|
||||
|
||||
while(p_size>(size_t)(1<<hand)) ++hand;
|
||||
while (p_size > (size_t)(1 << hand))
|
||||
++hand;
|
||||
|
||||
Hand &h = hands[hand];
|
||||
|
||||
|
@ -167,7 +163,6 @@ public:
|
|||
hands[i].first = NULL;
|
||||
hands[i].last = NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void clear() {
|
||||
|
@ -194,5 +189,4 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // ALLOCATORS_H
|
||||
|
|
|
@ -28,10 +28,10 @@
|
|||
/*************************************************************************/
|
||||
#include "array.h"
|
||||
|
||||
#include "vector.h"
|
||||
#include "hashfuncs.h"
|
||||
#include "variant.h"
|
||||
#include "object.h"
|
||||
#include "variant.h"
|
||||
#include "vector.h"
|
||||
|
||||
struct ArrayPrivate {
|
||||
|
||||
|
@ -55,8 +55,6 @@ void Array::_ref(const Array& p_from) const {
|
|||
_unref();
|
||||
|
||||
_p = p_from._p;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Array::_unref() const {
|
||||
|
@ -70,7 +68,6 @@ void Array::_unref() const {
|
|||
_p = NULL;
|
||||
}
|
||||
|
||||
|
||||
Variant &Array::operator[](int p_idx) {
|
||||
|
||||
return _p->array[p_idx];
|
||||
|
@ -79,7 +76,6 @@ Variant& Array::operator[](int p_idx) {
|
|||
const Variant &Array::operator[](int p_idx) const {
|
||||
|
||||
return _p->array[p_idx];
|
||||
|
||||
}
|
||||
|
||||
int Array::size() const {
|
||||
|
@ -95,7 +91,6 @@ void Array::clear() {
|
|||
_p->array.clear();
|
||||
}
|
||||
|
||||
|
||||
bool Array::operator==(const Array &p_array) const {
|
||||
|
||||
return _p == p_array._p;
|
||||
|
@ -204,7 +199,6 @@ void Array::remove(int p_pos) {
|
|||
_p->array.remove(p_pos);
|
||||
}
|
||||
|
||||
|
||||
void Array::set(int p_idx, const Variant &p_value) {
|
||||
|
||||
operator[](p_idx) = p_value;
|
||||
|
@ -230,7 +224,6 @@ struct _ArrayVariantSort {
|
|||
void Array::sort() {
|
||||
|
||||
_p->array.sort_custom<_ArrayVariantSort>();
|
||||
|
||||
}
|
||||
|
||||
struct _ArrayVariantSortCustom {
|
||||
|
@ -246,7 +239,6 @@ struct _ArrayVariantSortCustom {
|
|||
if (err.error != Variant::CallError::CALL_OK)
|
||||
res = false;
|
||||
return res;
|
||||
|
||||
}
|
||||
};
|
||||
void Array::sort_custom(Object *p_obj, const StringName &p_function) {
|
||||
|
@ -257,7 +249,6 @@ void Array::sort_custom(Object *p_obj,const StringName& p_function){
|
|||
avs.compare.obj = p_obj;
|
||||
avs.compare.func = p_function;
|
||||
avs.sort(_p->array.ptr(), _p->array.size());
|
||||
|
||||
}
|
||||
|
||||
void Array::invert() {
|
||||
|
@ -265,7 +256,6 @@ void Array::invert(){
|
|||
_p->array.invert();
|
||||
}
|
||||
|
||||
|
||||
void Array::push_front(const Variant &p_value) {
|
||||
|
||||
_p->array.insert(0, p_value);
|
||||
|
@ -280,7 +270,6 @@ Variant Array::pop_back(){
|
|||
return ret;
|
||||
}
|
||||
return Variant();
|
||||
|
||||
}
|
||||
|
||||
Variant Array::pop_front() {
|
||||
|
@ -291,21 +280,17 @@ Variant Array::pop_front(){
|
|||
return ret;
|
||||
}
|
||||
return Variant();
|
||||
|
||||
}
|
||||
|
||||
|
||||
Array::Array(const Array &p_from) {
|
||||
|
||||
_p = NULL;
|
||||
_ref(p_from);
|
||||
|
||||
}
|
||||
Array::Array() {
|
||||
|
||||
_p = memnew(ArrayPrivate);
|
||||
_p->refcount.init();
|
||||
|
||||
}
|
||||
Array::~Array() {
|
||||
|
||||
|
|
|
@ -42,7 +42,6 @@ class Array {
|
|||
void _unref() const;
|
||||
|
||||
public:
|
||||
|
||||
Variant &operator[](int p_idx);
|
||||
const Variant &operator[](int p_idx) const;
|
||||
|
||||
|
@ -87,7 +86,6 @@ public:
|
|||
Array(const Array &p_from);
|
||||
Array();
|
||||
~Array();
|
||||
|
||||
};
|
||||
|
||||
#endif // ARRAY_H
|
||||
|
|
|
@ -27,13 +27,13 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "core_bind.h"
|
||||
#include "os/os.h"
|
||||
#include "geometry.h"
|
||||
#include "io/marshalls.h"
|
||||
#include "io/base64.h"
|
||||
#include "core/global_config.h"
|
||||
#include "geometry.h"
|
||||
#include "io/base64.h"
|
||||
#include "io/file_access_encrypted.h"
|
||||
#include "io/marshalls.h"
|
||||
#include "os/keyboard.h"
|
||||
#include "os/os.h"
|
||||
|
||||
/**
|
||||
* Time constants borrowed from loc_time.h
|
||||
|
@ -106,10 +106,8 @@ bool _ResourceLoader::has(const String &p_path) {
|
|||
return ResourceCache::has(local_path);
|
||||
};
|
||||
|
||||
|
||||
void _ResourceLoader::_bind_methods() {
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("load_interactive:ResourceInteractiveLoader", "path", "type_hint"), &_ResourceLoader::load_interactive, DEFVAL(""));
|
||||
ClassDB::bind_method(D_METHOD("load:Resource", "path", "type_hint", "p_no_cache"), &_ResourceLoader::load, DEFVAL(""), DEFVAL(false));
|
||||
ClassDB::bind_method(D_METHOD("get_recognized_extensions_for_type", "type"), &_ResourceLoader::get_recognized_extensions_for_type);
|
||||
|
@ -123,7 +121,6 @@ _ResourceLoader::_ResourceLoader() {
|
|||
singleton = this;
|
||||
}
|
||||
|
||||
|
||||
Error _ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {
|
||||
|
||||
ERR_FAIL_COND_V(p_resource.is_null(), ERR_INVALID_PARAMETER);
|
||||
|
@ -145,7 +142,6 @@ PoolVector<String> _ResourceSaver::get_recognized_extensions(const RES& p_resour
|
|||
|
||||
_ResourceSaver *_ResourceSaver::singleton = NULL;
|
||||
|
||||
|
||||
void _ResourceSaver::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("save", "path", "resource:Resource", "flags"), &_ResourceSaver::save, DEFVAL(0));
|
||||
|
@ -164,10 +160,8 @@ _ResourceSaver::_ResourceSaver() {
|
|||
singleton = this;
|
||||
}
|
||||
|
||||
|
||||
/////////////////OS
|
||||
|
||||
|
||||
Point2 _OS::get_mouse_pos() const {
|
||||
|
||||
return OS::get_singleton()->get_mouse_pos();
|
||||
|
@ -175,7 +169,6 @@ Point2 _OS::get_mouse_pos() const {
|
|||
void _OS::set_window_title(const String &p_title) {
|
||||
|
||||
OS::get_singleton()->set_window_title(p_title);
|
||||
|
||||
}
|
||||
|
||||
int _OS::get_mouse_button_state() const {
|
||||
|
@ -193,13 +186,11 @@ bool _OS::has_touchscreen_ui_hint() const {
|
|||
|
||||
void _OS::set_clipboard(const String &p_text) {
|
||||
|
||||
|
||||
OS::get_singleton()->set_clipboard(p_text);
|
||||
}
|
||||
String _OS::get_clipboard() const {
|
||||
|
||||
return OS::get_singleton()->get_clipboard();
|
||||
|
||||
}
|
||||
|
||||
void _OS::set_video_mode(const Size2 &p_size, bool p_fullscreen, bool p_resizeable, int p_screen) {
|
||||
|
@ -210,25 +201,20 @@ void _OS::set_video_mode(const Size2& p_size, bool p_fullscreen,bool p_resizeabl
|
|||
vm.fullscreen = p_fullscreen;
|
||||
vm.resizable = p_resizeable;
|
||||
OS::get_singleton()->set_video_mode(vm, p_screen);
|
||||
|
||||
|
||||
}
|
||||
Size2 _OS::get_video_mode(int p_screen) const {
|
||||
|
||||
OS::VideoMode vm;
|
||||
vm = OS::get_singleton()->get_video_mode(p_screen);
|
||||
return Size2(vm.width, vm.height);
|
||||
|
||||
}
|
||||
bool _OS::is_video_mode_fullscreen(int p_screen) const {
|
||||
|
||||
OS::VideoMode vm;
|
||||
vm = OS::get_singleton()->get_video_mode(p_screen);
|
||||
return vm.fullscreen;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int _OS::get_screen_count() const {
|
||||
return OS::get_singleton()->get_screen_count();
|
||||
}
|
||||
|
@ -354,7 +340,6 @@ Error _OS::shell_open(String p_uri) {
|
|||
return OS::get_singleton()->shell_open(p_uri);
|
||||
};
|
||||
|
||||
|
||||
int _OS::execute(const String &p_path, const Vector<String> &p_arguments, bool p_blocking, Array p_output) {
|
||||
|
||||
OS::ProcessID pid;
|
||||
|
@ -369,7 +354,6 @@ int _OS::execute(const String& p_path, const Vector<String> & p_arguments, bool
|
|||
return -1;
|
||||
else
|
||||
return pid;
|
||||
|
||||
}
|
||||
Error _OS::kill(int p_pid) {
|
||||
|
||||
|
@ -381,7 +365,6 @@ int _OS::get_process_ID() const {
|
|||
return OS::get_singleton()->get_process_ID();
|
||||
};
|
||||
|
||||
|
||||
bool _OS::has_environment(const String &p_var) const {
|
||||
|
||||
return OS::get_singleton()->has_environment(p_var);
|
||||
|
@ -429,8 +412,6 @@ String _OS::get_model_name() const {
|
|||
return OS::get_singleton()->get_model_name();
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool _OS::is_ok_left_and_cancel_right() const {
|
||||
|
||||
return OS::get_singleton()->get_swap_ok_cancel();
|
||||
|
@ -509,13 +490,11 @@ struct Time {
|
|||
int _OS::get_static_memory_usage() const {
|
||||
|
||||
return OS::get_singleton()->get_static_memory_usage();
|
||||
|
||||
}
|
||||
|
||||
int _OS::get_static_memory_peak_usage() const {
|
||||
|
||||
return OS::get_singleton()->get_static_memory_peak_usage();
|
||||
|
||||
}
|
||||
|
||||
int _OS::get_dynamic_memory_usage() const {
|
||||
|
@ -523,7 +502,6 @@ int _OS::get_dynamic_memory_usage() const{
|
|||
return OS::get_singleton()->get_dynamic_memory_usage();
|
||||
}
|
||||
|
||||
|
||||
void _OS::set_icon(const Image &p_icon) {
|
||||
|
||||
OS::get_singleton()->set_icon(p_icon);
|
||||
|
@ -653,7 +631,6 @@ uint64_t _OS::get_unix_time_from_datetime(Dictionary datetime) const {
|
|||
SECONDS_FROM_MONTHS_PAST_THIS_YEAR +
|
||||
SECONDS_FROM_YEARS_PAST;
|
||||
return epoch;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -768,7 +745,6 @@ bool _OS::can_draw() const {
|
|||
return OS::get_singleton()->can_draw();
|
||||
}
|
||||
|
||||
|
||||
int _OS::get_processor_count() const {
|
||||
|
||||
return OS::get_singleton()->get_processor_count();
|
||||
|
@ -777,7 +753,6 @@ int _OS::get_processor_count() const {
|
|||
bool _OS::is_stdout_verbose() const {
|
||||
|
||||
return OS::get_singleton()->is_stdout_verbose();
|
||||
|
||||
}
|
||||
|
||||
void _OS::dump_memory_to_file(const String &p_file) {
|
||||
|
@ -797,7 +772,6 @@ struct _OSCoreBindImg {
|
|||
|
||||
void _OS::print_all_textures_by_size() {
|
||||
|
||||
|
||||
List<_OSCoreBindImg> imgs;
|
||||
int total = 0;
|
||||
{
|
||||
|
@ -858,10 +832,8 @@ void _OS::print_resources_by_type(const Vector<String>& p_types) {
|
|||
type_count[r->get_class()] = 0;
|
||||
}
|
||||
|
||||
|
||||
type_count[r->get_class()]++;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
bool _OS::has_virtual_keyboard() const {
|
||||
|
@ -932,7 +904,6 @@ bool _OS::is_debug_build() const {
|
|||
#else
|
||||
return false;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void _OS::set_screen_orientation(ScreenOrientation p_orientation) {
|
||||
|
@ -960,8 +931,6 @@ String _OS::get_system_dir(SystemDir p_dir) const {
|
|||
return OS::get_singleton()->get_system_dir(OS::SystemDir(p_dir));
|
||||
}
|
||||
|
||||
|
||||
|
||||
String _OS::get_scancode_string(uint32_t p_code) const {
|
||||
|
||||
return keycode_get_string(p_code);
|
||||
|
@ -997,7 +966,6 @@ void _OS::_bind_methods() {
|
|||
//ClassDB::bind_method(D_METHOD("is_video_mode_resizable","screen"),&_OS::is_video_mode_resizable,DEFVAL(0));
|
||||
//ClassDB::bind_method(D_METHOD("get_fullscreen_mode_list","screen"),&_OS::get_fullscreen_mode_list,DEFVAL(0));
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_screen_count"), &_OS::get_screen_count);
|
||||
ClassDB::bind_method(D_METHOD("get_current_screen"), &_OS::get_current_screen);
|
||||
ClassDB::bind_method(D_METHOD("set_current_screen", "screen"), &_OS::set_current_screen);
|
||||
|
@ -1027,7 +995,6 @@ void _OS::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("set_keep_screen_on", "enabled"), &_OS::set_keep_screen_on);
|
||||
ClassDB::bind_method(D_METHOD("is_keep_screen_on"), &_OS::is_keep_screen_on);
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("has_touchscreen_ui_hint"), &_OS::has_touchscreen_ui_hint);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_window_title", "title"), &_OS::set_window_title);
|
||||
|
@ -1073,7 +1040,6 @@ void _OS::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("get_latin_keyboard_variant"), &_OS::get_latin_keyboard_variant);
|
||||
ClassDB::bind_method(D_METHOD("get_model_name"), &_OS::get_model_name);
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("can_draw"), &_OS::can_draw);
|
||||
ClassDB::bind_method(D_METHOD("is_stdout_verbose"), &_OS::is_stdout_verbose);
|
||||
|
||||
|
@ -1101,7 +1067,6 @@ void _OS::_bind_methods() {
|
|||
|
||||
ClassDB::bind_method(D_METHOD("is_ok_left_and_cancel_right"), &_OS::is_ok_left_and_cancel_right);
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("print_all_textures_by_size"), &_OS::print_all_textures_by_size);
|
||||
ClassDB::bind_method(D_METHOD("print_resources_by_type", "types"), &_OS::print_resources_by_type);
|
||||
|
||||
|
@ -1171,7 +1136,6 @@ void _OS::_bind_methods() {
|
|||
BIND_CONSTANT(POWERSTATE_NO_BATTERY);
|
||||
BIND_CONSTANT(POWERSTATE_CHARGING);
|
||||
BIND_CONSTANT(POWERSTATE_CHARGED);
|
||||
|
||||
}
|
||||
|
||||
_OS::_OS() {
|
||||
|
@ -1179,10 +1143,8 @@ _OS::_OS() {
|
|||
singleton = this;
|
||||
}
|
||||
|
||||
|
||||
///////////////////// GEOMETRY
|
||||
|
||||
|
||||
_Geometry *_Geometry::singleton = NULL;
|
||||
|
||||
_Geometry *_Geometry::get_singleton() {
|
||||
|
@ -1240,7 +1202,6 @@ PoolVector<Vector3> _Geometry::get_closest_points_between_segments(const Vector3
|
|||
r.set(0, r1);
|
||||
r.set(1, r2);
|
||||
return r;
|
||||
|
||||
}
|
||||
Vector2 _Geometry::get_closest_point_to_segment_2d(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b) {
|
||||
|
||||
|
@ -1269,8 +1230,6 @@ Variant _Geometry::ray_intersects_triangle( const Vector3& p_from, const Vector3
|
|||
return res;
|
||||
else
|
||||
return Variant();
|
||||
|
||||
|
||||
}
|
||||
Variant _Geometry::segment_intersects_triangle(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2) {
|
||||
|
||||
|
@ -1279,7 +1238,6 @@ Variant _Geometry::segment_intersects_triangle( const Vector3& p_from, const Vec
|
|||
return res;
|
||||
else
|
||||
return Variant();
|
||||
|
||||
}
|
||||
|
||||
bool _Geometry::point_is_inside_triangle(const Vector2 &s, const Vector2 &a, const Vector2 &b, const Vector2 &c) const {
|
||||
|
@ -1310,7 +1268,6 @@ PoolVector<Vector3> _Geometry::segment_intersects_cylinder( const Vector3& p_fro
|
|||
r.set(0, res);
|
||||
r.set(1, norm);
|
||||
return r;
|
||||
|
||||
}
|
||||
PoolVector<Vector3> _Geometry::segment_intersects_convex(const Vector3 &p_from, const Vector3 &p_to, const Vector<Plane> &p_planes) {
|
||||
|
||||
|
@ -1352,23 +1309,19 @@ Dictionary _Geometry::make_atlas(const Vector<Size2>& p_rects) {
|
|||
r_result.push_back(result[i]);
|
||||
};
|
||||
|
||||
|
||||
ret["points"] = r_result;
|
||||
ret["size"] = r_size;
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
||||
int _Geometry::get_uv84_normal_bit(const Vector3 &p_vector) {
|
||||
|
||||
return Geometry::get_uv84_normal_bit(p_vector);
|
||||
}
|
||||
|
||||
|
||||
void _Geometry::_bind_methods() {
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("build_box_planes", "extents"), &_Geometry::build_box_planes);
|
||||
ClassDB::bind_method(D_METHOD("build_cylinder_planes", "radius", "height", "sides", "axis"), &_Geometry::build_cylinder_planes, DEFVAL(Vector3::AXIS_Z));
|
||||
ClassDB::bind_method(D_METHOD("build_capsule_planes", "radius", "height", "sides", "lats", "axis"), &_Geometry::build_capsule_planes, DEFVAL(Vector3::AXIS_Z));
|
||||
|
@ -1398,16 +1351,12 @@ void _Geometry::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("make_atlas", "sizes"), &_Geometry::make_atlas);
|
||||
}
|
||||
|
||||
|
||||
_Geometry::_Geometry() {
|
||||
singleton = this;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////// FILE
|
||||
|
||||
|
||||
|
||||
Error _File::open_encrypted(const String &p_path, int p_mode_flags, const Vector<uint8_t> &p_key) {
|
||||
|
||||
Error err = open(p_path, p_mode_flags);
|
||||
|
@ -1441,10 +1390,8 @@ Error _File::open_encrypted_pass(const String& p_path, int p_mode_flags,const St
|
|||
|
||||
f = fae;
|
||||
return OK;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Error _File::open(const String &p_path, int p_mode_flags) {
|
||||
|
||||
close();
|
||||
|
@ -1453,7 +1400,6 @@ Error _File::open(const String& p_path, int p_mode_flags) {
|
|||
if (f)
|
||||
f->set_endian_swap(eswap);
|
||||
return err;
|
||||
|
||||
}
|
||||
|
||||
void _File::close() {
|
||||
|
@ -1464,7 +1410,6 @@ void _File::close(){
|
|||
}
|
||||
bool _File::is_open() const {
|
||||
|
||||
|
||||
return f != NULL;
|
||||
}
|
||||
|
||||
|
@ -1472,17 +1417,14 @@ void _File::seek(int64_t p_position){
|
|||
|
||||
ERR_FAIL_COND(!f);
|
||||
f->seek(p_position);
|
||||
|
||||
}
|
||||
void _File::seek_end(int64_t p_position) {
|
||||
|
||||
|
||||
ERR_FAIL_COND(!f);
|
||||
f->seek_end(p_position);
|
||||
}
|
||||
int64_t _File::get_pos() const {
|
||||
|
||||
|
||||
ERR_FAIL_COND_V(!f, 0);
|
||||
return f->get_pos();
|
||||
}
|
||||
|
@ -1503,42 +1445,35 @@ uint8_t _File::get_8() const{
|
|||
|
||||
ERR_FAIL_COND_V(!f, 0);
|
||||
return f->get_8();
|
||||
|
||||
}
|
||||
uint16_t _File::get_16() const {
|
||||
|
||||
ERR_FAIL_COND_V(!f, 0);
|
||||
return f->get_16();
|
||||
|
||||
}
|
||||
uint32_t _File::get_32() const {
|
||||
|
||||
ERR_FAIL_COND_V(!f, 0);
|
||||
return f->get_32();
|
||||
|
||||
}
|
||||
uint64_t _File::get_64() const {
|
||||
|
||||
ERR_FAIL_COND_V(!f, 0);
|
||||
return f->get_64();
|
||||
|
||||
}
|
||||
|
||||
float _File::get_float() const {
|
||||
|
||||
ERR_FAIL_COND_V(!f, 0);
|
||||
return f->get_float();
|
||||
|
||||
}
|
||||
double _File::get_double() const {
|
||||
|
||||
|
||||
ERR_FAIL_COND_V(!f, 0);
|
||||
return f->get_double();
|
||||
}
|
||||
real_t _File::get_real() const {
|
||||
|
||||
|
||||
ERR_FAIL_COND_V(!f, 0);
|
||||
return f->get_real();
|
||||
}
|
||||
|
@ -1563,10 +1498,8 @@ PoolVector<uint8_t> _File::get_buffer(int p_length) const{
|
|||
data.resize(p_length);
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
String _File::get_as_text() const {
|
||||
|
||||
ERR_FAIL_COND_V(!f, String());
|
||||
|
@ -1585,29 +1518,22 @@ String _File::get_as_text() const {
|
|||
f->seek(original_pos);
|
||||
|
||||
return text;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
String _File::get_md5(const String &p_path) const {
|
||||
|
||||
return FileAccess::get_md5(p_path);
|
||||
|
||||
}
|
||||
|
||||
String _File::get_sha256(const String &p_path) const {
|
||||
|
||||
return FileAccess::get_sha256(p_path);
|
||||
|
||||
}
|
||||
|
||||
|
||||
String _File::get_line() const {
|
||||
|
||||
ERR_FAIL_COND_V(!f, String());
|
||||
return f->get_line();
|
||||
|
||||
}
|
||||
|
||||
Vector<String> _File::get_csv_line(String delim) const {
|
||||
|
@ -1622,15 +1548,12 @@ Vector<String> _File::get_csv_line(String delim) const {
|
|||
|
||||
void _File::set_endian_swap(bool p_swap) {
|
||||
|
||||
|
||||
eswap = p_swap;
|
||||
if (f)
|
||||
f->set_endian_swap(p_swap);
|
||||
|
||||
}
|
||||
bool _File::get_endian_swap() {
|
||||
|
||||
|
||||
return eswap;
|
||||
}
|
||||
|
||||
|
@ -1728,8 +1651,6 @@ void _File::store_buffer(const PoolVector<uint8_t>& p_buffer){
|
|||
bool _File::file_exists(const String &p_name) const {
|
||||
|
||||
return FileAccess::exists(p_name);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void _File::store_var(const Variant &p_var) {
|
||||
|
@ -1774,7 +1695,6 @@ uint64_t _File::get_modified_time(const String &p_file) const {
|
|||
|
||||
void _File::_bind_methods() {
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("open_encrypted", "path", "mode_flags", "key"), &_File::open_encrypted);
|
||||
ClassDB::bind_method(D_METHOD("open_encrypted_with_pass", "path", "mode_flags", "pass"), &_File::open_encrypted_pass);
|
||||
|
||||
|
@ -1832,21 +1752,16 @@ _File::_File(){
|
|||
|
||||
f = NULL;
|
||||
eswap = false;
|
||||
|
||||
}
|
||||
|
||||
_File::~_File() {
|
||||
|
||||
if (f)
|
||||
memdelete(f);
|
||||
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
Error _Directory::open(const String &p_path) {
|
||||
Error err;
|
||||
DirAccess *alt = DirAccess::open(p_path, &err);
|
||||
|
@ -1875,9 +1790,7 @@ String _Directory::get_next(){
|
|||
ERR_FAIL_COND_V(!d, "");
|
||||
|
||||
String next = d->get_next();
|
||||
while (next != ""
|
||||
&& ((_list_skip_navigational && (next == "." || next == ".."))
|
||||
|| (_list_skip_hidden && d->current_is_hidden()))) {
|
||||
while (next != "" && ((_list_skip_navigational && (next == "." || next == "..")) || (_list_skip_hidden && d->current_is_hidden()))) {
|
||||
|
||||
next = d->get_next();
|
||||
}
|
||||
|
@ -1928,7 +1841,6 @@ Error _Directory::make_dir(String p_dir){
|
|||
Error err = d->make_dir(p_dir);
|
||||
memdelete(d);
|
||||
return err;
|
||||
|
||||
}
|
||||
return d->make_dir(p_dir);
|
||||
}
|
||||
|
@ -1940,7 +1852,6 @@ Error _Directory::make_dir_recursive(String p_dir){
|
|||
Error err = d->make_dir_recursive(p_dir);
|
||||
memdelete(d);
|
||||
return err;
|
||||
|
||||
}
|
||||
return d->make_dir_recursive(p_dir);
|
||||
}
|
||||
|
@ -1992,7 +1903,6 @@ Error _Directory::rename(String p_from, String p_to){
|
|||
}
|
||||
|
||||
return d->rename(p_from, p_to);
|
||||
|
||||
}
|
||||
Error _Directory::remove(String p_name) {
|
||||
|
||||
|
@ -2009,7 +1919,6 @@ Error _Directory::remove(String p_name){
|
|||
|
||||
void _Directory::_bind_methods() {
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("open:Error", "path"), &_Directory::open);
|
||||
ClassDB::bind_method(D_METHOD("list_dir_begin", "skip_navigational", "skip_hidden"), &_Directory::list_dir_begin, DEFVAL(false), DEFVAL(false));
|
||||
ClassDB::bind_method(D_METHOD("get_next"), &_Directory::get_next);
|
||||
|
@ -2029,7 +1938,6 @@ void _Directory::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("copy:Error", "from", "to"), &_Directory::copy);
|
||||
ClassDB::bind_method(D_METHOD("rename:Error", "from", "to"), &_Directory::rename);
|
||||
ClassDB::bind_method(D_METHOD("remove:Error", "path"), &_Directory::remove);
|
||||
|
||||
}
|
||||
|
||||
_Directory::_Directory() {
|
||||
|
@ -2045,8 +1953,7 @@ _Directory::~_Directory() {
|
|||
|
||||
_Marshalls *_Marshalls::singleton = NULL;
|
||||
|
||||
_Marshalls *_Marshalls::get_singleton()
|
||||
{
|
||||
_Marshalls *_Marshalls::get_singleton() {
|
||||
return singleton;
|
||||
}
|
||||
|
||||
|
@ -2165,7 +2072,6 @@ String _Marshalls::base64_to_utf8(const String& p_str) {
|
|||
return ret;
|
||||
};
|
||||
|
||||
|
||||
void _Marshalls::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("variant_to_base64:String", "variant"), &_Marshalls::variant_to_base64);
|
||||
|
@ -2176,16 +2082,10 @@ void _Marshalls::_bind_methods() {
|
|||
|
||||
ClassDB::bind_method(D_METHOD("utf8_to_base64:String", "utf8_str"), &_Marshalls::utf8_to_base64);
|
||||
ClassDB::bind_method(D_METHOD("base64_to_utf8:String", "base64_str"), &_Marshalls::base64_to_utf8);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
Error _Semaphore::wait() {
|
||||
|
||||
return semaphore->wait();
|
||||
|
@ -2196,15 +2096,12 @@ Error _Semaphore::post() {
|
|||
return semaphore->post();
|
||||
}
|
||||
|
||||
|
||||
void _Semaphore::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("wait:Error"), &_Semaphore::wait);
|
||||
ClassDB::bind_method(D_METHOD("post:Error"), &_Semaphore::post);
|
||||
|
||||
}
|
||||
|
||||
|
||||
_Semaphore::_Semaphore() {
|
||||
|
||||
semaphore = Semaphore::create();
|
||||
|
@ -2215,10 +2112,8 @@ _Semaphore::~_Semaphore(){
|
|||
memdelete(semaphore);
|
||||
}
|
||||
|
||||
|
||||
///////////////
|
||||
|
||||
|
||||
void _Mutex::lock() {
|
||||
|
||||
mutex->lock();
|
||||
|
@ -2239,10 +2134,8 @@ void _Mutex::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("lock"), &_Mutex::lock);
|
||||
ClassDB::bind_method(D_METHOD("try_lock:Error"), &_Mutex::try_lock);
|
||||
ClassDB::bind_method(D_METHOD("unlock"), &_Mutex::unlock);
|
||||
|
||||
}
|
||||
|
||||
|
||||
_Mutex::_Mutex() {
|
||||
|
||||
mutex = Mutex::create();
|
||||
|
@ -2253,11 +2146,8 @@ _Mutex::~_Mutex(){
|
|||
memdelete(mutex);
|
||||
}
|
||||
|
||||
|
||||
///////////////
|
||||
|
||||
|
||||
|
||||
void _Thread::_start_func(void *ud) {
|
||||
|
||||
Ref<_Thread> *tud = (Ref<_Thread> *)ud;
|
||||
|
@ -2292,11 +2182,9 @@ void _Thread::_start_func(void *ud) {
|
|||
default: {}
|
||||
}
|
||||
|
||||
|
||||
ERR_EXPLAIN("Could not call function '" + t->target_method.operator String() + "'' starting thread ID: " + t->get_id() + " Reason: " + reason);
|
||||
ERR_FAIL();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Error _Thread::start(Object *p_instance, const StringName &p_method, const Variant &p_userdata, int p_priority) {
|
||||
|
@ -2306,7 +2194,6 @@ Error _Thread::start(Object *p_instance,const StringName& p_method,const Variant
|
|||
ERR_FAIL_COND_V(p_method == StringName(), ERR_INVALID_PARAMETER);
|
||||
ERR_FAIL_INDEX_V(p_priority, 3, ERR_INVALID_PARAMETER);
|
||||
|
||||
|
||||
ret = Variant();
|
||||
target_method = p_method;
|
||||
target_instance = p_instance;
|
||||
|
@ -2366,7 +2253,6 @@ void _Thread::_bind_methods() {
|
|||
BIND_CONSTANT(PRIORITY_LOW);
|
||||
BIND_CONSTANT(PRIORITY_NORMAL);
|
||||
BIND_CONSTANT(PRIORITY_HIGH);
|
||||
|
||||
}
|
||||
_Thread::_Thread() {
|
||||
|
||||
|
@ -2384,7 +2270,6 @@ _Thread::~_Thread() {
|
|||
}
|
||||
/////////////////////////////////////
|
||||
|
||||
|
||||
PoolStringArray _ClassDB::get_class_list() const {
|
||||
|
||||
List<StringName> classes;
|
||||
|
@ -2398,7 +2283,6 @@ PoolStringArray _ClassDB::get_class_list() const {
|
|||
}
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
PoolStringArray _ClassDB::get_inheriters_from_class(const StringName &p_class) const {
|
||||
|
||||
|
@ -2456,7 +2340,6 @@ Dictionary _ClassDB::get_signal(StringName p_class,StringName p_signal) const {
|
|||
} else {
|
||||
return Dictionary();
|
||||
}
|
||||
|
||||
}
|
||||
Array _ClassDB::get_signal_list(StringName p_class, bool p_no_inheritance) const {
|
||||
|
||||
|
@ -2481,8 +2364,6 @@ Array _ClassDB::get_property_list(StringName p_class, bool p_no_inheritance) con
|
|||
}
|
||||
|
||||
return ret;
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool _ClassDB::has_method(StringName p_class, StringName p_method, bool p_no_inheritance) const {
|
||||
|
@ -2490,7 +2371,6 @@ bool _ClassDB::has_method(StringName p_class,StringName p_method,bool p_no_inher
|
|||
return ClassDB::has_method(p_class, p_method, p_no_inheritance);
|
||||
}
|
||||
|
||||
|
||||
Array _ClassDB::get_method_list(StringName p_class, bool p_no_inheritance) const {
|
||||
|
||||
List<MethodInfo> methods;
|
||||
|
@ -2532,7 +2412,6 @@ int _ClassDB::get_integer_constant(const StringName& p_class, const StringName &
|
|||
int c = ClassDB::get_integer_constant(p_class, p_name, &found);
|
||||
ERR_FAIL_COND_V(!found, 0);
|
||||
return c;
|
||||
|
||||
}
|
||||
StringName _ClassDB::get_category(const StringName &p_node) const {
|
||||
|
||||
|
@ -2571,21 +2450,14 @@ void _ClassDB::_bind_methods() {
|
|||
|
||||
ClassDB::bind_method(D_METHOD("class_get_category", "class"), &_ClassDB::get_category);
|
||||
ClassDB::bind_method(D_METHOD("is_class_enabled", "class"), &_ClassDB::is_class_enabled);
|
||||
|
||||
|
||||
}
|
||||
|
||||
_ClassDB::_ClassDB() {
|
||||
|
||||
|
||||
}
|
||||
_ClassDB::~_ClassDB() {
|
||||
|
||||
|
||||
}
|
||||
///////////////////////////////
|
||||
|
||||
|
||||
void _Engine::set_iterations_per_second(int p_ips) {
|
||||
|
||||
Engine::get_singleton()->set_iterations_per_second(p_ips);
|
||||
|
@ -2593,7 +2465,6 @@ void _Engine::set_iterations_per_second(int p_ips) {
|
|||
int _Engine::get_iterations_per_second() const {
|
||||
|
||||
return Engine::get_singleton()->get_iterations_per_second();
|
||||
|
||||
}
|
||||
|
||||
void _Engine::set_target_fps(int p_fps) {
|
||||
|
@ -2604,8 +2475,6 @@ float _Engine::get_target_fps() const {
|
|||
return Engine::get_singleton()->get_target_fps();
|
||||
}
|
||||
|
||||
|
||||
|
||||
float _Engine::get_frames_per_second() const {
|
||||
|
||||
return Engine::get_singleton()->get_frames_per_second();
|
||||
|
@ -2641,7 +2510,6 @@ Dictionary _Engine::get_version_info() const {
|
|||
return Engine::get_singleton()->get_version_info();
|
||||
}
|
||||
|
||||
|
||||
void _Engine::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_iterations_per_second", "iterations_per_second"), &_Engine::set_iterations_per_second);
|
||||
|
@ -2660,7 +2528,6 @@ void _Engine::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("get_main_loop:MainLoop"), &_Engine::get_main_loop);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_version_info"), &_Engine::get_version_info);
|
||||
|
||||
}
|
||||
|
||||
_Engine *_Engine::singleton = NULL;
|
||||
|
|
|
@ -31,23 +31,20 @@
|
|||
|
||||
#include "io/resource_loader.h"
|
||||
#include "io/resource_saver.h"
|
||||
#include "os/file_access.h"
|
||||
#include "os/dir_access.h"
|
||||
#include "os/thread.h"
|
||||
#include "os/semaphore.h"
|
||||
#include "os/file_access.h"
|
||||
#include "os/power.h"
|
||||
|
||||
#include "os/semaphore.h"
|
||||
#include "os/thread.h"
|
||||
|
||||
class _ResourceLoader : public Object {
|
||||
GDCLASS(_ResourceLoader, Object);
|
||||
|
||||
protected:
|
||||
|
||||
static void _bind_methods();
|
||||
static _ResourceLoader *singleton;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
static _ResourceLoader *get_singleton() { return singleton; }
|
||||
Ref<ResourceInteractiveLoader> load_interactive(const String &p_path, const String &p_type_hint = "");
|
||||
RES load(const String &p_path, const String &p_type_hint = "", bool p_no_cache = false);
|
||||
|
@ -63,11 +60,10 @@ class _ResourceSaver : public Object {
|
|||
GDCLASS(_ResourceSaver, Object);
|
||||
|
||||
protected:
|
||||
|
||||
static void _bind_methods();
|
||||
static _ResourceSaver *singleton;
|
||||
public:
|
||||
|
||||
public:
|
||||
enum SaverFlags {
|
||||
|
||||
FLAG_RELATIVE_PATHS = 1,
|
||||
|
@ -83,7 +79,6 @@ public:
|
|||
Error save(const String &p_path, const RES &p_resource, uint32_t p_flags);
|
||||
PoolVector<String> get_recognized_extensions(const RES &p_resource);
|
||||
|
||||
|
||||
_ResourceSaver();
|
||||
};
|
||||
|
||||
|
@ -93,11 +88,10 @@ class _OS : public Object {
|
|||
GDCLASS(_OS, Object);
|
||||
|
||||
protected:
|
||||
|
||||
static void _bind_methods();
|
||||
static _OS *singleton;
|
||||
public:
|
||||
|
||||
public:
|
||||
enum Weekday {
|
||||
DAY_SUNDAY,
|
||||
DAY_MONDAY,
|
||||
|
@ -129,7 +123,6 @@ public:
|
|||
void set_window_title(const String &p_title);
|
||||
int get_mouse_button_state() const;
|
||||
|
||||
|
||||
void set_clipboard(const String &p_text);
|
||||
String get_clipboard() const;
|
||||
|
||||
|
@ -139,7 +132,6 @@ public:
|
|||
bool is_video_mode_resizable(int p_screen = 0) const;
|
||||
Array get_fullscreen_mode_list(int p_screen = 0) const;
|
||||
|
||||
|
||||
virtual int get_screen_count() const;
|
||||
virtual int get_current_screen() const;
|
||||
virtual void set_current_screen(int p_screen);
|
||||
|
@ -191,7 +183,6 @@ public:
|
|||
|
||||
String get_model_name() const;
|
||||
|
||||
|
||||
void dump_memory_to_file(const String &p_file);
|
||||
void dump_resources_to_file(const String &p_file);
|
||||
|
||||
|
@ -214,7 +205,6 @@ public:
|
|||
bool is_scancode_unicode(uint32_t p_unicode) const;
|
||||
int find_scancode_from_string(const String &p_code) const;
|
||||
|
||||
|
||||
/*
|
||||
struct Date {
|
||||
|
||||
|
@ -289,19 +279,16 @@ public:
|
|||
|
||||
String get_system_dir(SystemDir p_dir) const;
|
||||
|
||||
|
||||
String get_data_dir() const;
|
||||
|
||||
void alert(const String &p_alert, const String &p_title = "ALERT!");
|
||||
|
||||
|
||||
void set_screen_orientation(ScreenOrientation p_orientation);
|
||||
ScreenOrientation get_screen_orientation() const;
|
||||
|
||||
void set_keep_screen_on(bool p_enabled);
|
||||
bool is_keep_screen_on() const;
|
||||
|
||||
|
||||
bool is_ok_left_and_cancel_right() const;
|
||||
|
||||
Error set_thread_name(const String &p_name);
|
||||
|
@ -321,17 +308,16 @@ public:
|
|||
VARIANT_ENUM_CAST(_OS::SystemDir);
|
||||
VARIANT_ENUM_CAST(_OS::ScreenOrientation);
|
||||
|
||||
|
||||
class _Geometry : public Object {
|
||||
|
||||
GDCLASS(_Geometry, Object);
|
||||
|
||||
static _Geometry *singleton;
|
||||
|
||||
protected:
|
||||
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
||||
public:
|
||||
static _Geometry *get_singleton();
|
||||
PoolVector<Plane> build_box_planes(const Vector3 &p_extents);
|
||||
PoolVector<Plane> build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis = Vector3::AXIS_Z);
|
||||
|
@ -360,19 +346,16 @@ public:
|
|||
_Geometry();
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class _File : public Reference {
|
||||
|
||||
GDCLASS(_File, Reference);
|
||||
FileAccess *f;
|
||||
bool eswap;
|
||||
|
||||
protected:
|
||||
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
||||
public:
|
||||
enum ModeFlags {
|
||||
|
||||
READ = 1,
|
||||
|
@ -384,7 +367,6 @@ public:
|
|||
Error open_encrypted(const String &p_path, int p_mode_flags, const Vector<uint8_t> &p_key);
|
||||
Error open_encrypted_pass(const String &p_path, int p_mode_flags, const String &p_pass);
|
||||
|
||||
|
||||
Error open(const String &p_path, int p_mode_flags); ///< open a file
|
||||
void close(); ///< close a file
|
||||
bool is_open() const; ///< true when file is open
|
||||
|
@ -440,7 +422,6 @@ public:
|
|||
|
||||
Vector<String> get_csv_line(String delim = ",") const;
|
||||
|
||||
|
||||
void store_buffer(const PoolVector<uint8_t> &p_buffer); ///< store an array of bytes
|
||||
|
||||
void store_var(const Variant &p_var);
|
||||
|
@ -451,18 +432,17 @@ public:
|
|||
|
||||
_File();
|
||||
virtual ~_File();
|
||||
|
||||
};
|
||||
|
||||
class _Directory : public Reference {
|
||||
|
||||
GDCLASS(_Directory, Reference);
|
||||
DirAccess *d;
|
||||
|
||||
protected:
|
||||
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
||||
public:
|
||||
Error open(const String &p_path);
|
||||
|
||||
Error list_dir_begin(bool p_skip_internal = false, bool p_skip_hidden = false); ///< This starts dir listing
|
||||
|
@ -490,7 +470,6 @@ public:
|
|||
Error rename(String p_from, String p_to);
|
||||
Error remove(String p_name);
|
||||
|
||||
|
||||
_Directory();
|
||||
virtual ~_Directory();
|
||||
|
||||
|
@ -506,12 +485,9 @@ class _Marshalls : public Reference {
|
|||
static _Marshalls *singleton;
|
||||
|
||||
protected:
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
static _Marshalls *get_singleton();
|
||||
|
||||
String variant_to_base64(const Variant &p_var);
|
||||
|
@ -527,15 +503,14 @@ public:
|
|||
~_Marshalls() { singleton = NULL; }
|
||||
};
|
||||
|
||||
|
||||
class _Mutex : public Reference {
|
||||
|
||||
GDCLASS(_Mutex, Reference);
|
||||
Mutex *mutex;
|
||||
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
||||
public:
|
||||
void lock();
|
||||
Error try_lock();
|
||||
void unlock();
|
||||
|
@ -550,8 +525,8 @@ class _Semaphore : public Reference {
|
|||
Semaphore *semaphore;
|
||||
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
||||
public:
|
||||
Error wait();
|
||||
Error post();
|
||||
|
||||
|
@ -564,7 +539,6 @@ class _Thread : public Reference {
|
|||
GDCLASS(_Thread, Reference);
|
||||
|
||||
protected:
|
||||
|
||||
Variant ret;
|
||||
Variant userdata;
|
||||
volatile bool active;
|
||||
|
@ -573,8 +547,8 @@ protected:
|
|||
Thread *thread;
|
||||
static void _bind_methods();
|
||||
static void _start_func(void *ud);
|
||||
public:
|
||||
|
||||
public:
|
||||
enum Priority {
|
||||
|
||||
PRIORITY_LOW,
|
||||
|
@ -597,8 +571,8 @@ class _ClassDB : public Object {
|
|||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
||||
public:
|
||||
PoolStringArray get_class_list() const;
|
||||
PoolStringArray get_inheriters_from_class(const StringName &p_class) const;
|
||||
StringName get_parent_class(const StringName &p_class) const;
|
||||
|
@ -615,7 +589,6 @@ public:
|
|||
|
||||
bool has_method(StringName p_class, StringName p_method, bool p_no_inheritance = false) const;
|
||||
|
||||
|
||||
Array get_method_list(StringName p_class, bool p_no_inheritance = false) const;
|
||||
|
||||
PoolStringArray get_integer_constant_list(const StringName &p_class, bool p_no_inheritance = false) const;
|
||||
|
@ -629,17 +602,14 @@ public:
|
|||
~_ClassDB();
|
||||
};
|
||||
|
||||
|
||||
class _Engine : public Object {
|
||||
GDCLASS(_Engine, Object);
|
||||
|
||||
protected:
|
||||
|
||||
static void _bind_methods();
|
||||
static _Engine *singleton;
|
||||
|
||||
public:
|
||||
|
||||
static _Engine *get_singleton() { return singleton; }
|
||||
void set_iterations_per_second(int p_ips);
|
||||
int get_iterations_per_second() const;
|
||||
|
@ -663,5 +633,4 @@ public:
|
|||
_Engine();
|
||||
};
|
||||
|
||||
|
||||
#endif // CORE_BIND_H
|
||||
|
|
|
@ -44,8 +44,10 @@
|
|||
|
||||
#ifdef DEBUG_METHODS_ENABLED
|
||||
|
||||
ParamDef::ParamDef(const Variant& p_variant) { used=true; val=p_variant; }
|
||||
|
||||
ParamDef::ParamDef(const Variant &p_variant) {
|
||||
used = true;
|
||||
val = p_variant;
|
||||
}
|
||||
|
||||
MethodDefinition D_METHOD(const char *p_name) {
|
||||
|
||||
|
@ -108,7 +110,6 @@ MethodDefinition D_METHOD(const char* p_name,const char *p_arg1,const char *p_ar
|
|||
return md;
|
||||
}
|
||||
|
||||
|
||||
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6) {
|
||||
|
||||
MethodDefinition md;
|
||||
|
@ -189,10 +190,8 @@ MethodDefinition D_METHOD(const char* p_name,const char *p_arg1,const char *p_ar
|
|||
return md;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
ClassDB::APIType ClassDB::current_api = API_CORE;
|
||||
|
||||
void ClassDB::set_current_api(APIType p_api) {
|
||||
|
@ -211,11 +210,8 @@ ClassDB::ClassInfo::ClassInfo() {
|
|||
disabled = false;
|
||||
}
|
||||
ClassDB::ClassInfo::~ClassInfo() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool ClassDB::is_parent_class(const StringName &p_class, const StringName &p_inherits) {
|
||||
|
||||
OBJTYPE_RLOCK;
|
||||
|
@ -245,7 +241,6 @@ void ClassDB::get_class_list( List<StringName> *p_classes) {
|
|||
p_classes->sort();
|
||||
}
|
||||
|
||||
|
||||
void ClassDB::get_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes) {
|
||||
|
||||
OBJTYPE_RLOCK;
|
||||
|
@ -257,7 +252,6 @@ void ClassDB::get_inheriters_from_class( const StringName& p_class,List<StringNa
|
|||
if (*k != p_class && is_parent_class(*k, p_class))
|
||||
p_classes->push_back(*k);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
StringName ClassDB::get_parent_class_nocheck(const StringName &p_class) {
|
||||
|
@ -268,7 +262,6 @@ StringName ClassDB::get_parent_class_nocheck(const StringName& p_class) {
|
|||
if (!ti)
|
||||
return StringName();
|
||||
return ti->inherits;
|
||||
|
||||
}
|
||||
|
||||
StringName ClassDB::get_parent_class(const StringName &p_class) {
|
||||
|
@ -353,11 +346,9 @@ uint64_t ClassDB::get_api_hash(APIType p_api) {
|
|||
}
|
||||
|
||||
hash = hash_djb2_one_64(mb->get_hint_flags(), hash);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{ //constants
|
||||
|
||||
List<StringName> snames;
|
||||
|
@ -378,7 +369,6 @@ uint64_t ClassDB::get_api_hash(APIType p_api) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
{ //signals
|
||||
|
||||
List<StringName> snames;
|
||||
|
@ -422,7 +412,6 @@ uint64_t ClassDB::get_api_hash(APIType p_api) {
|
|||
hash = hash_djb2_one_64(F->get().hash(), hash);
|
||||
hash = hash_djb2_one_64(psg->setter.hash(), hash);
|
||||
hash = hash_djb2_one_64(psg->getter.hash(), hash);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -435,16 +424,12 @@ uint64_t ClassDB::get_api_hash(APIType p_api) {
|
|||
hash = hash_djb2_one_64(F->get().hint_string.hash(), hash);
|
||||
hash = hash_djb2_one_64(F->get().usage, hash);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return hash;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
bool ClassDB::class_exists(const StringName &p_class) {
|
||||
|
@ -486,7 +471,6 @@ bool ClassDB::can_instance(const StringName &p_class) {
|
|||
return (!ti->disabled && ti->creation_func != NULL);
|
||||
}
|
||||
|
||||
|
||||
void ClassDB::_add_class2(const StringName &p_class, const StringName &p_inherits) {
|
||||
|
||||
OBJTYPE_WLOCK;
|
||||
|
@ -509,13 +493,10 @@ void ClassDB::_add_class2(const StringName& p_class, const StringName& p_inherit
|
|||
} else {
|
||||
ti.inherits_ptr = NULL;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void ClassDB::get_method_list(StringName p_class, List<MethodInfo> *p_methods, bool p_no_inheritance) {
|
||||
|
||||
|
||||
OBJTYPE_RLOCK;
|
||||
|
||||
ClassInfo *type = classes.getptr(p_class);
|
||||
|
@ -552,7 +533,6 @@ void ClassDB::get_method_list(StringName p_class,List<MethodInfo> *p_methods,boo
|
|||
minfo.arguments.push_back(method->get_argument_info(i));
|
||||
}
|
||||
|
||||
|
||||
if (method->get_argument_type(-1) != Variant::NIL) {
|
||||
minfo.return_val = method->get_argument_info(-1);
|
||||
}
|
||||
|
@ -561,8 +541,6 @@ void ClassDB::get_method_list(StringName p_class,List<MethodInfo> *p_methods,boo
|
|||
p_methods->push_back(minfo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#else
|
||||
|
||||
const StringName *K = NULL;
|
||||
|
@ -575,7 +553,6 @@ void ClassDB::get_method_list(StringName p_class,List<MethodInfo> *p_methods,boo
|
|||
p_methods->push_back(mi);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
if (p_no_inheritance)
|
||||
|
@ -583,10 +560,8 @@ void ClassDB::get_method_list(StringName p_class,List<MethodInfo> *p_methods,boo
|
|||
|
||||
type = type->inherits_ptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
MethodBind *ClassDB::get_method(StringName p_class, StringName p_name) {
|
||||
|
||||
OBJTYPE_RLOCK;
|
||||
|
@ -603,7 +578,6 @@ MethodBind *ClassDB::get_method(StringName p_class, StringName p_name) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void ClassDB::bind_integer_constant(const StringName &p_class, const StringName &p_name, int p_constant) {
|
||||
|
||||
OBJTYPE_WLOCK;
|
||||
|
@ -623,7 +597,6 @@ void ClassDB::bind_integer_constant(const StringName& p_class, const StringName
|
|||
#ifdef DEBUG_METHODS_ENABLED
|
||||
type->constant_order.push_back(p_name);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void ClassDB::get_integer_constant_list(const StringName &p_class, List<String> *p_constants, bool p_no_inheritance) {
|
||||
|
@ -650,20 +623,16 @@ void ClassDB::get_integer_constant_list(const StringName& p_class, List<String>
|
|||
|
||||
type = type->inherits_ptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
int ClassDB::get_integer_constant(const StringName &p_class, const StringName &p_name, bool *p_success) {
|
||||
|
||||
OBJTYPE_RLOCK;
|
||||
|
||||
|
||||
ClassInfo *type = classes.getptr(p_class);
|
||||
|
||||
while (type) {
|
||||
|
||||
|
||||
int *constant = type->constant_map.getptr(p_name);
|
||||
if (constant) {
|
||||
|
||||
|
@ -702,7 +671,6 @@ void ClassDB::add_signal(StringName p_class,const MethodInfo& p_signal) {
|
|||
#endif
|
||||
|
||||
type->signal_map[sname] = p_signal;
|
||||
|
||||
}
|
||||
|
||||
void ClassDB::get_signal_list(StringName p_class, List<MethodInfo> *p_signals, bool p_no_inheritance) {
|
||||
|
@ -727,8 +695,6 @@ void ClassDB::get_signal_list(StringName p_class,List<MethodInfo> *p_signals,boo
|
|||
|
||||
check = check->inherits_ptr;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool ClassDB::has_signal(StringName p_class, StringName p_signal) {
|
||||
|
@ -763,7 +729,6 @@ bool ClassDB::get_signal(StringName p_class,StringName p_signal,MethodInfo *r_si
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
void ClassDB::add_property_group(StringName p_class, const String &p_name, const String &p_prefix) {
|
||||
|
||||
OBJTYPE_WLOCK;
|
||||
|
@ -775,8 +740,6 @@ void ClassDB::add_property_group(StringName p_class,const String& p_name,const S
|
|||
|
||||
void ClassDB::add_property(StringName p_class, const PropertyInfo &p_pinfo, const StringName &p_setter, const StringName &p_getter, int p_index) {
|
||||
|
||||
|
||||
|
||||
#ifndef NO_THREADS
|
||||
lock->read_lock();
|
||||
#endif
|
||||
|
@ -801,7 +764,6 @@ void ClassDB::add_property(StringName p_class,const PropertyInfo& p_pinfo, const
|
|||
if (mb_set->get_argument_count() != exp_args) {
|
||||
ERR_EXPLAIN("Invalid Function for Setter: " + p_class + "::" + p_setter + " for property: " + p_pinfo.name);
|
||||
ERR_FAIL();
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -822,15 +784,11 @@ void ClassDB::add_property(StringName p_class,const PropertyInfo& p_pinfo, const
|
|||
if (mb_get->get_argument_count() != exp_args) {
|
||||
ERR_EXPLAIN("Invalid Function for Getter: " + p_class + "::" + p_getter + " for property: " + p_pinfo.name);
|
||||
ERR_FAIL();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef DEBUG_METHODS_ENABLED
|
||||
|
||||
if (type->property_setget.has(p_pinfo.name)) {
|
||||
|
@ -852,10 +810,8 @@ void ClassDB::add_property(StringName p_class,const PropertyInfo& p_pinfo, const
|
|||
psg.type = p_pinfo.type;
|
||||
|
||||
type->property_setget[p_pinfo.name] = psg;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ClassDB::get_property_list(StringName p_class, List<PropertyInfo> *p_list, bool p_no_inheritance, const Object *p_validator) {
|
||||
|
||||
OBJTYPE_RLOCK;
|
||||
|
@ -866,7 +822,6 @@ void ClassDB::get_property_list(StringName p_class, List<PropertyInfo> *p_list,
|
|||
|
||||
for (List<PropertyInfo>::Element *E = check->property_list.front(); E; E = E->next()) {
|
||||
|
||||
|
||||
if (p_validator) {
|
||||
PropertyInfo pi = E->get();
|
||||
p_validator->_validate_property(pi);
|
||||
|
@ -880,12 +835,9 @@ void ClassDB::get_property_list(StringName p_class, List<PropertyInfo> *p_list,
|
|||
return;
|
||||
check = check->inherits_ptr;
|
||||
}
|
||||
|
||||
}
|
||||
bool ClassDB::set_property(Object *p_object, const StringName &p_property, const Variant &p_value, bool *r_valid) {
|
||||
|
||||
|
||||
|
||||
ClassInfo *type = classes.getptr(p_object->get_class_name());
|
||||
ClassInfo *check = type;
|
||||
while (check) {
|
||||
|
@ -910,7 +862,6 @@ bool ClassDB::set_property(Object* p_object,const StringName& p_property, const
|
|||
p_object->call(psg->setter, arg, 2, ce);
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
const Variant *arg[1] = { &p_value };
|
||||
if (psg->_setptr) {
|
||||
|
@ -994,7 +945,6 @@ Variant::Type ClassDB::get_property_type(const StringName& p_class, const String
|
|||
*r_is_valid = false;
|
||||
|
||||
return Variant::NIL;
|
||||
|
||||
}
|
||||
|
||||
StringName ClassDB::get_property_setter(StringName p_class, const StringName p_property) {
|
||||
|
@ -1033,7 +983,6 @@ StringName ClassDB::get_property_getter(StringName p_class,const StringName p_pr
|
|||
|
||||
bool ClassDB::has_property(const StringName &p_class, const StringName &p_property, bool p_no_inheritance) {
|
||||
|
||||
|
||||
ClassInfo *type = classes.getptr(p_class);
|
||||
ClassInfo *check = type;
|
||||
while (check) {
|
||||
|
@ -1056,8 +1005,6 @@ void ClassDB::set_method_flags(StringName p_class,StringName p_method,int p_flag
|
|||
ERR_FAIL_COND(!check);
|
||||
ERR_FAIL_COND(!check->method_map.has(p_method));
|
||||
check->method_map[p_method]->set_hint_flags(p_flags);
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool ClassDB::has_method(StringName p_class, StringName p_method, bool p_no_inheritance) {
|
||||
|
@ -1073,7 +1020,6 @@ bool ClassDB::has_method(StringName p_class,StringName p_method,bool p_no_inheri
|
|||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
bool ClassDB::get_setter_and_type_for_property(const StringName &p_class, const StringName &p_prop, StringName &r_class, StringName &r_setter) {
|
||||
|
@ -1092,7 +1038,6 @@ bool ClassDB::get_setter_and_type_for_property(const StringName& p_class, const
|
|||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
#ifdef DEBUG_METHODS_ENABLED
|
||||
|
@ -1103,14 +1048,12 @@ MethodBind* ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind , const
|
|||
StringName mdname = StaticCString::create(method_name);
|
||||
#endif
|
||||
|
||||
|
||||
StringName rettype;
|
||||
if (mdname.operator String().find(":") != -1) {
|
||||
rettype = mdname.operator String().get_slice(":", 1);
|
||||
mdname = mdname.operator String().get_slice(":", 0);
|
||||
}
|
||||
|
||||
|
||||
OBJTYPE_WLOCK;
|
||||
ERR_FAIL_COND_V(!p_bind, NULL);
|
||||
p_bind->set_name(mdname);
|
||||
|
@ -1125,7 +1068,6 @@ MethodBind* ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind , const
|
|||
}
|
||||
#endif
|
||||
|
||||
|
||||
ClassInfo *type = classes.getptr(instance_type);
|
||||
if (!type) {
|
||||
ERR_PRINTS("Couldn't bind method '" + mdname + "' for instance: " + instance_type);
|
||||
|
@ -1146,7 +1088,6 @@ MethodBind* ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind , const
|
|||
#endif
|
||||
type->method_map[mdname] = p_bind;
|
||||
|
||||
|
||||
Vector<Variant> defvals;
|
||||
|
||||
defvals.resize(p_defcount);
|
||||
|
@ -1158,7 +1099,6 @@ MethodBind* ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind , const
|
|||
p_bind->set_default_arguments(defvals);
|
||||
p_bind->set_hint_flags(p_flags);
|
||||
return p_bind;
|
||||
|
||||
}
|
||||
|
||||
void ClassDB::add_virtual_method(const StringName &p_class, const MethodInfo &p_method, bool p_virtual) {
|
||||
|
@ -1173,7 +1113,6 @@ void ClassDB::add_virtual_method(const StringName& p_class, const MethodInfo& p_
|
|||
classes[p_class].virtual_methods.push_back(mi);
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void ClassDB::get_virtual_methods(const StringName &p_class, List<MethodInfo> *p_methods, bool p_no_inheritance) {
|
||||
|
@ -1196,7 +1135,6 @@ void ClassDB::get_virtual_methods(const StringName& p_class, List<MethodInfo> *
|
|||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void ClassDB::set_class_enabled(StringName p_class, bool p_enable) {
|
||||
|
@ -1261,7 +1199,6 @@ void ClassDB::get_extensions_for_type(const StringName& p_class,List<String> *p_
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
RWLock *ClassDB::lock = NULL;
|
||||
|
||||
void ClassDB::init() {
|
||||
|
@ -1274,8 +1211,6 @@ void ClassDB::init() {
|
|||
|
||||
void ClassDB::cleanup() {
|
||||
|
||||
|
||||
|
||||
//OBJTYPE_LOCK; hah not here
|
||||
|
||||
const StringName *k = NULL;
|
||||
|
@ -1298,7 +1233,6 @@ void ClassDB::cleanup() {
|
|||
|
||||
memdelete(lock);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -29,8 +29,8 @@
|
|||
#ifndef CLASS_DB_H
|
||||
#define CLASS_DB_H
|
||||
|
||||
#include "object.h"
|
||||
#include "method_bind.h"
|
||||
#include "object.h"
|
||||
#include "print_string.h"
|
||||
|
||||
/**
|
||||
|
@ -51,7 +51,6 @@ struct ParamHint {
|
|||
hint_text = p_hint_text;
|
||||
default_val = p_default_val;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
struct ParamDef {
|
||||
|
@ -64,14 +63,12 @@ struct ParamDef {
|
|||
//#define DEFVAL( m_defval ) ParamDef(m_defval)
|
||||
#define DEFVAL(m_defval) (m_defval)
|
||||
|
||||
|
||||
//#define SIMPLE_METHODDEF
|
||||
|
||||
#ifdef DEBUG_METHODS_ENABLED
|
||||
|
||||
struct MethodDefinition {
|
||||
|
||||
|
||||
StringName name;
|
||||
Vector<StringName> args;
|
||||
MethodDefinition() {}
|
||||
|
@ -79,8 +76,6 @@ struct MethodDefinition {
|
|||
MethodDefinition(const StringName &p_name) { name = p_name; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
MethodDefinition D_METHOD(const char *p_name);
|
||||
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1);
|
||||
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2);
|
||||
|
@ -99,7 +94,9 @@ MethodDefinition D_METHOD(const char* p_name,const char *p_arg1,const char *p_ar
|
|||
|
||||
#ifdef NO_VARIADIC_MACROS
|
||||
|
||||
static _FORCE_INLINE_ const char* D_METHOD(const char* m_name, ...) { return m_name; }
|
||||
static _FORCE_INLINE_ const char *D_METHOD(const char *m_name, ...) {
|
||||
return m_name;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
|
@ -118,6 +115,7 @@ public:
|
|||
API_EDITOR,
|
||||
API_NONE
|
||||
};
|
||||
|
||||
public:
|
||||
struct PropertySetGet {
|
||||
|
||||
|
@ -145,7 +143,6 @@ public:
|
|||
#endif
|
||||
HashMap<StringName, PropertySetGet, StringNameHasher> property_setget;
|
||||
|
||||
|
||||
StringName inherits;
|
||||
StringName name;
|
||||
bool disabled;
|
||||
|
@ -170,12 +167,11 @@ public:
|
|||
static MethodBind *bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const char *method_name, const Variant **p_defs, int p_defcount);
|
||||
#endif
|
||||
|
||||
|
||||
static APIType current_api;
|
||||
|
||||
static void _add_class2(const StringName &p_class, const StringName &p_inherits);
|
||||
public:
|
||||
|
||||
public:
|
||||
// DO NOT USE THIS!!!!!! NEEDS TO BE PUBLIC BUT DO NOT USE NO MATTER WHAT!!!
|
||||
template <class T>
|
||||
static void _add_class() {
|
||||
|
@ -308,8 +304,10 @@ public:
|
|||
Vector<Variant> defvals;
|
||||
|
||||
#define PARSE_DEFVAL(m_defval) \
|
||||
if (d##m_defval.used) defvals.insert(0,d##m_defval.val);\
|
||||
else goto set_defvals;
|
||||
if (d##m_defval.used) \
|
||||
defvals.insert(0, d##m_defval.val); \
|
||||
else \
|
||||
goto set_defvals;
|
||||
|
||||
|
||||
PARSE_DEFVAL(1);
|
||||
|
@ -363,7 +361,6 @@ public:
|
|||
return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, p_method_name, ptr, 1);
|
||||
}
|
||||
|
||||
|
||||
template <class N, class M>
|
||||
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2) {
|
||||
|
||||
|
@ -434,8 +431,6 @@ public:
|
|||
|
||||
GLOBAL_LOCK_FUNCTION;
|
||||
|
||||
|
||||
|
||||
MethodBind *bind = create_vararg_method_bind(p_method, p_info);
|
||||
ERR_FAIL_COND_V(!bind, NULL);
|
||||
|
||||
|
@ -469,12 +464,9 @@ public:
|
|||
type->method_order.push_back(p_name);
|
||||
#endif
|
||||
|
||||
|
||||
return bind;
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void add_signal(StringName p_class, const MethodInfo &p_signal);
|
||||
static bool has_signal(StringName p_class, StringName p_signal);
|
||||
static bool get_signal(StringName p_class, StringName p_signal, MethodInfo *r_signal);
|
||||
|
@ -490,12 +482,9 @@ public:
|
|||
static StringName get_property_setter(StringName p_class, const StringName p_property);
|
||||
static StringName get_property_getter(StringName p_class, const StringName p_property);
|
||||
|
||||
|
||||
|
||||
static bool has_method(StringName p_class, StringName p_method, bool p_no_inheritance = false);
|
||||
static void set_method_flags(StringName p_class, StringName p_method, int p_flags);
|
||||
|
||||
|
||||
static void get_method_list(StringName p_class, List<MethodInfo> *p_methods, bool p_no_inheritance = false);
|
||||
static MethodBind *get_method(StringName p_class, StringName p_name);
|
||||
|
||||
|
@ -523,7 +512,6 @@ public:
|
|||
static void cleanup();
|
||||
};
|
||||
|
||||
|
||||
#define BIND_CONSTANT(m_constant) \
|
||||
ClassDB::bind_integer_constant(get_class_static(), #m_constant, m_constant);
|
||||
|
||||
|
@ -538,6 +526,4 @@ public:
|
|||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif // CLASS_DB_H
|
||||
|
|
|
@ -28,10 +28,10 @@
|
|||
/*************************************************************************/
|
||||
#include "color.h"
|
||||
|
||||
#include "color_names.inc"
|
||||
#include "map.h"
|
||||
#include "math_funcs.h"
|
||||
#include "print_string.h"
|
||||
#include "map.h"
|
||||
#include "color_names.inc"
|
||||
|
||||
uint32_t Color::to_ARGB32() const {
|
||||
|
||||
|
@ -88,7 +88,6 @@ float Color::get_h() const {
|
|||
|
||||
float Color::get_s() const {
|
||||
|
||||
|
||||
float min = MIN(r, g);
|
||||
min = MIN(min, b);
|
||||
float max = MAX(r, g);
|
||||
|
@ -97,7 +96,6 @@ float Color::get_s() const {
|
|||
float delta = max - min;
|
||||
|
||||
return (max != 0) ? (delta / max) : 0;
|
||||
|
||||
}
|
||||
|
||||
float Color::get_v() const {
|
||||
|
@ -213,11 +211,9 @@ static float _parse_col(const String& p_str, int p_ofs) {
|
|||
ig += v * 16;
|
||||
else
|
||||
ig += v;
|
||||
|
||||
}
|
||||
|
||||
return ig;
|
||||
|
||||
}
|
||||
|
||||
Color Color::inverted() const {
|
||||
|
@ -234,7 +230,6 @@ Color Color::contrasted() const {
|
|||
return c;
|
||||
}
|
||||
|
||||
|
||||
Color Color::html(const String &p_color) {
|
||||
|
||||
String color = p_color;
|
||||
|
@ -327,7 +322,6 @@ bool Color::html_is_valid(const String& p_color) {
|
|||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
Color Color::named(const String &p_name) {
|
||||
|
@ -371,7 +365,6 @@ String _to_hex(float p_val) {
|
|||
}
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
String Color::to_html(bool p_alpha) const {
|
||||
|
@ -383,10 +376,8 @@ String Color::to_html(bool p_alpha) const {
|
|||
if (p_alpha)
|
||||
txt = _to_hex(a) + txt;
|
||||
return txt;
|
||||
|
||||
}
|
||||
|
||||
|
||||
float Color::gray() const {
|
||||
|
||||
return (r + g + b) / 3.0;
|
||||
|
@ -396,5 +387,3 @@ Color::operator String() const {
|
|||
|
||||
return rtos(r) + ", " + rtos(g) + ", " + rtos(b) + ", " + rtos(a);
|
||||
}
|
||||
|
||||
|
||||
|
|
19
core/color.h
19
core/color.h
|
@ -29,8 +29,8 @@
|
|||
#ifndef COLOR_H
|
||||
#define COLOR_H
|
||||
|
||||
#include "ustring.h"
|
||||
#include "math_funcs.h"
|
||||
#include "ustring.h"
|
||||
/**
|
||||
@author Juan Linietsky <reduzio@gmail.com>
|
||||
*/
|
||||
|
@ -84,7 +84,6 @@ struct Color {
|
|||
|
||||
_FORCE_INLINE_ Color blend(const Color &p_over) const {
|
||||
|
||||
|
||||
Color res;
|
||||
float sa = 1.0 - p_over.a;
|
||||
res.a = a * sa + p_over.a;
|
||||
|
@ -104,8 +103,7 @@ struct Color {
|
|||
r < 0.04045 ? r * (1.0 / 12.92) : Math::pow((r + 0.055) * (1.0 / (1 + 0.055)), 2.4),
|
||||
g < 0.04045 ? g * (1.0 / 12.92) : Math::pow((g + 0.055) * (1.0 / (1 + 0.055)), 2.4),
|
||||
b < 0.04045 ? b * (1.0 / 12.92) : Math::pow((b + 0.055) * (1.0 / (1 + 0.055)), 2.4),
|
||||
a
|
||||
);
|
||||
a);
|
||||
}
|
||||
|
||||
static Color hex(uint32_t p_hex);
|
||||
|
@ -121,13 +119,21 @@ struct Color {
|
|||
* No construct parameters, r=0, g=0, b=0. a=255
|
||||
*/
|
||||
_FORCE_INLINE_ Color() {
|
||||
r=0; g=0; b=0; a=1.0;
|
||||
r = 0;
|
||||
g = 0;
|
||||
b = 0;
|
||||
a = 1.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* RGB / RGBA construct parameters. Alpha is optional, but defaults to 1.0
|
||||
*/
|
||||
_FORCE_INLINE_ Color(float p_r,float p_g,float p_b,float p_a=1.0) { r=p_r; g=p_g; b=p_b; a=p_a; }
|
||||
_FORCE_INLINE_ Color(float p_r, float p_g, float p_b, float p_a = 1.0) {
|
||||
r = p_r;
|
||||
g = p_g;
|
||||
b = p_b;
|
||||
a = p_a;
|
||||
}
|
||||
};
|
||||
|
||||
bool Color::operator<(const Color &p_color) const {
|
||||
|
@ -142,7 +148,6 @@ bool Color::operator<(const Color& p_color) const {
|
|||
return g < p_color.g;
|
||||
} else
|
||||
return r < p_color.r;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -73,7 +73,6 @@ CommandQueueMT::SyncSemaphore* CommandQueueMT::_alloc_sync_sem() {
|
|||
return &sync_sems[idx];
|
||||
}
|
||||
|
||||
|
||||
CommandQueueMT::CommandQueueMT(bool p_sync) {
|
||||
|
||||
read_ptr = 0;
|
||||
|
@ -84,8 +83,6 @@ CommandQueueMT::CommandQueueMT(bool p_sync){
|
|||
|
||||
sync_sems[i].sem = Semaphore::create();
|
||||
sync_sems[i].in_use = false;
|
||||
|
||||
|
||||
}
|
||||
if (p_sync)
|
||||
sync = Semaphore::create();
|
||||
|
@ -93,7 +90,6 @@ CommandQueueMT::CommandQueueMT(bool p_sync){
|
|||
sync = NULL;
|
||||
}
|
||||
|
||||
|
||||
CommandQueueMT::~CommandQueueMT() {
|
||||
|
||||
if (sync)
|
||||
|
@ -104,5 +100,3 @@ CommandQueueMT::~CommandQueueMT() {
|
|||
memdelete(sync_sems[i].sem);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -29,11 +29,11 @@
|
|||
#ifndef COMMAND_QUEUE_MT_H
|
||||
#define COMMAND_QUEUE_MT_H
|
||||
|
||||
#include "typedefs.h"
|
||||
#include "os/semaphore.h"
|
||||
#include "os/mutex.h"
|
||||
#include "os/memory.h"
|
||||
#include "os/mutex.h"
|
||||
#include "os/semaphore.h"
|
||||
#include "simple_type.h"
|
||||
#include "typedefs.h"
|
||||
/**
|
||||
@author Juan Linietsky <reduzio@gmail.com>
|
||||
*/
|
||||
|
@ -179,7 +179,11 @@ class CommandQueueMT {
|
|||
R *ret;
|
||||
SyncSemaphore *sync;
|
||||
|
||||
virtual void call() { *ret = (instance->*method)(); sync->sem->post(); sync->in_use=false; }
|
||||
virtual void call() {
|
||||
*ret = (instance->*method)();
|
||||
sync->sem->post();
|
||||
sync->in_use = false;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class M, class P1, class R>
|
||||
|
@ -191,7 +195,11 @@ class CommandQueueMT {
|
|||
R *ret;
|
||||
SyncSemaphore *sync;
|
||||
|
||||
virtual void call() { *ret = (instance->*method)(p1); sync->sem->post(); sync->in_use=false; }
|
||||
virtual void call() {
|
||||
*ret = (instance->*method)(p1);
|
||||
sync->sem->post();
|
||||
sync->in_use = false;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class M, class P1, class P2, class R>
|
||||
|
@ -204,7 +212,11 @@ class CommandQueueMT {
|
|||
R *ret;
|
||||
SyncSemaphore *sync;
|
||||
|
||||
virtual void call() { *ret = (instance->*method)(p1,p2); sync->sem->post(); sync->in_use=false; }
|
||||
virtual void call() {
|
||||
*ret = (instance->*method)(p1, p2);
|
||||
sync->sem->post();
|
||||
sync->in_use = false;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class M, class P1, class P2, class P3, class R>
|
||||
|
@ -218,7 +230,11 @@ class CommandQueueMT {
|
|||
R *ret;
|
||||
SyncSemaphore *sync;
|
||||
|
||||
virtual void call() { *ret = (instance->*method)(p1,p2,p3); sync->sem->post(); sync->in_use=false; }
|
||||
virtual void call() {
|
||||
*ret = (instance->*method)(p1, p2, p3);
|
||||
sync->sem->post();
|
||||
sync->in_use = false;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class M, class P1, class P2, class P3, class P4, class R>
|
||||
|
@ -233,7 +249,11 @@ class CommandQueueMT {
|
|||
R *ret;
|
||||
SyncSemaphore *sync;
|
||||
|
||||
virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4); sync->sem->post(); sync->in_use=false; }
|
||||
virtual void call() {
|
||||
*ret = (instance->*method)(p1, p2, p3, p4);
|
||||
sync->sem->post();
|
||||
sync->in_use = false;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class M, class P1, class P2, class P3, class P4, class P5, class R>
|
||||
|
@ -249,7 +269,11 @@ class CommandQueueMT {
|
|||
R *ret;
|
||||
SyncSemaphore *sync;
|
||||
|
||||
virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4,p5); sync->sem->post(); sync->in_use=false; }
|
||||
virtual void call() {
|
||||
*ret = (instance->*method)(p1, p2, p3, p4, p5);
|
||||
sync->sem->post();
|
||||
sync->in_use = false;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class R>
|
||||
|
@ -266,7 +290,11 @@ class CommandQueueMT {
|
|||
R *ret;
|
||||
SyncSemaphore *sync;
|
||||
|
||||
virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4,p5,p6); sync->sem->post(); sync->in_use=false; }
|
||||
virtual void call() {
|
||||
*ret = (instance->*method)(p1, p2, p3, p4, p5, p6);
|
||||
sync->sem->post();
|
||||
sync->in_use = false;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class R>
|
||||
|
@ -284,7 +312,11 @@ class CommandQueueMT {
|
|||
R *ret;
|
||||
SyncSemaphore *sync;
|
||||
|
||||
virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4,p5,p6,p7); sync->sem->post(); sync->in_use=false; }
|
||||
virtual void call() {
|
||||
*ret = (instance->*method)(p1, p2, p3, p4, p5, p6, p7);
|
||||
sync->sem->post();
|
||||
sync->in_use = false;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class R>
|
||||
|
@ -303,7 +335,11 @@ class CommandQueueMT {
|
|||
R *ret;
|
||||
SyncSemaphore *sync;
|
||||
|
||||
virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4,p5,p6,p7,p8); sync->sem->post(); sync->in_use=false; }
|
||||
virtual void call() {
|
||||
*ret = (instance->*method)(p1, p2, p3, p4, p5, p6, p7, p8);
|
||||
sync->sem->post();
|
||||
sync->in_use = false;
|
||||
}
|
||||
};
|
||||
|
||||
/** commands that don't return but sync */
|
||||
|
@ -318,7 +354,11 @@ class CommandQueueMT {
|
|||
|
||||
SyncSemaphore *sync;
|
||||
|
||||
virtual void call() { (instance->*method)(); sync->sem->post(); sync->in_use=false; }
|
||||
virtual void call() {
|
||||
(instance->*method)();
|
||||
sync->sem->post();
|
||||
sync->in_use = false;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class M, class P1>
|
||||
|
@ -330,7 +370,11 @@ class CommandQueueMT {
|
|||
|
||||
SyncSemaphore *sync;
|
||||
|
||||
virtual void call() { (instance->*method)(p1); sync->sem->post(); sync->in_use=false; }
|
||||
virtual void call() {
|
||||
(instance->*method)(p1);
|
||||
sync->sem->post();
|
||||
sync->in_use = false;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class M, class P1, class P2>
|
||||
|
@ -343,7 +387,11 @@ class CommandQueueMT {
|
|||
|
||||
SyncSemaphore *sync;
|
||||
|
||||
virtual void call() { (instance->*method)(p1,p2); sync->sem->post(); sync->in_use=false; }
|
||||
virtual void call() {
|
||||
(instance->*method)(p1, p2);
|
||||
sync->sem->post();
|
||||
sync->in_use = false;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class M, class P1, class P2, class P3>
|
||||
|
@ -357,7 +405,11 @@ class CommandQueueMT {
|
|||
|
||||
SyncSemaphore *sync;
|
||||
|
||||
virtual void call() { (instance->*method)(p1,p2,p3); sync->sem->post(); sync->in_use=false; }
|
||||
virtual void call() {
|
||||
(instance->*method)(p1, p2, p3);
|
||||
sync->sem->post();
|
||||
sync->in_use = false;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class M, class P1, class P2, class P3, class P4>
|
||||
|
@ -372,7 +424,11 @@ class CommandQueueMT {
|
|||
|
||||
SyncSemaphore *sync;
|
||||
|
||||
virtual void call() { (instance->*method)(p1,p2,p3,p4); sync->sem->post(); sync->in_use=false; }
|
||||
virtual void call() {
|
||||
(instance->*method)(p1, p2, p3, p4);
|
||||
sync->sem->post();
|
||||
sync->in_use = false;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class M, class P1, class P2, class P3, class P4, class P5>
|
||||
|
@ -388,7 +444,11 @@ class CommandQueueMT {
|
|||
|
||||
SyncSemaphore *sync;
|
||||
|
||||
virtual void call() { (instance->*method)(p1,p2,p3,p4,p5); sync->sem->post(); sync->in_use=false; }
|
||||
virtual void call() {
|
||||
(instance->*method)(p1, p2, p3, p4, p5);
|
||||
sync->sem->post();
|
||||
sync->in_use = false;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6>
|
||||
|
@ -405,7 +465,11 @@ class CommandQueueMT {
|
|||
|
||||
SyncSemaphore *sync;
|
||||
|
||||
virtual void call() { (instance->*method)(p1,p2,p3,p4,p5,p6); sync->sem->post(); sync->in_use=false; }
|
||||
virtual void call() {
|
||||
(instance->*method)(p1, p2, p3, p4, p5, p6);
|
||||
sync->sem->post();
|
||||
sync->in_use = false;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7>
|
||||
|
@ -423,7 +487,11 @@ class CommandQueueMT {
|
|||
|
||||
SyncSemaphore *sync;
|
||||
|
||||
virtual void call() { (instance->*method)(p1,p2,p3,p4,p5,p6,p7); sync->sem->post(); sync->in_use=false; }
|
||||
virtual void call() {
|
||||
(instance->*method)(p1, p2, p3, p4, p5, p6, p7);
|
||||
sync->sem->post();
|
||||
sync->in_use = false;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8>
|
||||
|
@ -442,7 +510,11 @@ class CommandQueueMT {
|
|||
|
||||
SyncSemaphore *sync;
|
||||
|
||||
virtual void call() { (instance->*method)(p1,p2,p3,p4,p5,p6,p7,p8); sync->sem->post(); sync->in_use=false; }
|
||||
virtual void call() {
|
||||
(instance->*method)(p1, p2, p3, p4, p5, p6, p7, p8);
|
||||
sync->sem->post();
|
||||
sync->in_use = false;
|
||||
}
|
||||
};
|
||||
|
||||
/***** BASE *******/
|
||||
|
@ -453,7 +525,6 @@ class CommandQueueMT {
|
|||
SYNC_SEMAPHORES = 8
|
||||
};
|
||||
|
||||
|
||||
uint8_t command_mem[COMMAND_MEM_SIZE];
|
||||
uint32_t read_ptr;
|
||||
uint32_t write_ptr;
|
||||
|
@ -461,7 +532,6 @@ class CommandQueueMT {
|
|||
Mutex *mutex;
|
||||
Semaphore *sync;
|
||||
|
||||
|
||||
template <class T>
|
||||
T *allocate() {
|
||||
|
||||
|
@ -477,7 +547,6 @@ class CommandQueueMT {
|
|||
} else if (write_ptr >= read_ptr) {
|
||||
// ahead of read_ptr, check that there is room
|
||||
|
||||
|
||||
if ((COMMAND_MEM_SIZE - write_ptr) < alloc_size + 4) {
|
||||
// no room at the end, wrap down;
|
||||
|
||||
|
@ -502,7 +571,6 @@ class CommandQueueMT {
|
|||
T *cmd = memnew_placement(&command_mem[write_ptr], T);
|
||||
write_ptr += sizeof(T);
|
||||
return cmd;
|
||||
|
||||
}
|
||||
|
||||
template <class T>
|
||||
|
@ -517,13 +585,11 @@ class CommandQueueMT {
|
|||
// sleep a little until fetch happened and some room is made
|
||||
wait_for_flush();
|
||||
lock();
|
||||
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
bool flush_one() {
|
||||
|
||||
tryagain:
|
||||
|
@ -552,15 +618,12 @@ class CommandQueueMT {
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
void lock();
|
||||
void unlock();
|
||||
void wait_for_flush();
|
||||
SyncSemaphore *_alloc_sync_sem();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/* NORMAL PUSH COMMANDS */
|
||||
|
||||
template <class T, class M>
|
||||
|
@ -717,7 +780,6 @@ public:
|
|||
}
|
||||
/*** PUSH AND RET COMMANDS ***/
|
||||
|
||||
|
||||
template <class T, class M, class R>
|
||||
void push_and_ret(T *p_instance, M p_method, R *r_ret) {
|
||||
|
||||
|
@ -907,7 +969,6 @@ public:
|
|||
ss->sem->wait();
|
||||
}
|
||||
|
||||
|
||||
template <class T, class M>
|
||||
void push_and_sync(T *p_instance, M p_method) {
|
||||
|
||||
|
@ -1119,7 +1180,6 @@ public:
|
|||
|
||||
CommandQueueMT(bool p_sync);
|
||||
~CommandQueueMT();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -46,7 +46,6 @@ Redistribution and use in source and binary forms, with or without modification,
|
|||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
/* Our compression codebook, used for compression */
|
||||
static const char *Smaz_cb[241] = {
|
||||
"\002s,\266", "\003had\232\002leW", "\003on \216", "", "\001yS",
|
||||
|
@ -240,7 +239,6 @@ static int smaz_decompress(const char *in, int inlen, char *out, int outlen) {
|
|||
return out - _out;
|
||||
}
|
||||
|
||||
|
||||
/////////// END OF SMAZ /////////////
|
||||
|
||||
struct _PHashTranslationCmp {
|
||||
|
@ -257,7 +255,6 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
|
|||
|
||||
int size = Math::larger_prime(keys.size());
|
||||
|
||||
|
||||
print_line("compressing keys: " + itos(keys.size()));
|
||||
Vector<Vector<Pair<int, CharString> > > buckets;
|
||||
Vector<Map<uint32_t, int> > table;
|
||||
|
@ -308,7 +305,6 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
|
|||
ps.compressed[0] = 0;
|
||||
}
|
||||
|
||||
|
||||
compressed[idx] = ps;
|
||||
total_compression_size += ps.compressed.size();
|
||||
total_string_size += src_s.size();
|
||||
|
@ -347,10 +343,8 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
|
|||
|
||||
hfunc_table[i] = d;
|
||||
bucket_table_size += 2 + b.size() * 4;
|
||||
|
||||
}
|
||||
|
||||
|
||||
print_line("bucket table size: " + itos(bucket_table_size * 4));
|
||||
print_line("hash table size: " + itos(size * 4));
|
||||
|
||||
|
@ -387,7 +381,6 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
|
|||
btw[btindex++] = compressed[E->get()].compressed.size();
|
||||
btw[btindex++] = compressed[E->get()].orig_len;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
print_line("total collisions: " + itos(collisions));
|
||||
|
@ -399,7 +392,6 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
|
|||
memcpy(&cw[compressed[i].offset], compressed[i].compressed.get_data(), compressed[i].compressed.size());
|
||||
}
|
||||
|
||||
|
||||
ERR_FAIL_COND(btindex != bucket_table_size);
|
||||
set_locale(p_from->get_locale());
|
||||
|
||||
|
@ -425,7 +417,6 @@ bool PHashTranslation::_set(const StringName& p_name, const Variant& p_value) {
|
|||
return false;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
bool PHashTranslation::_get(const StringName &p_name, Variant &r_ret) const {
|
||||
|
@ -441,7 +432,6 @@ bool PHashTranslation::_get(const StringName& p_name,Variant &r_ret) const{
|
|||
return false;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
StringName PHashTranslation::get_message(const StringName &p_src_text) const {
|
||||
|
@ -454,7 +444,6 @@ StringName PHashTranslation::get_message(const StringName& p_src_text) const {
|
|||
CharString str = p_src_text.operator String().utf8();
|
||||
uint32_t h = hash(0, str.get_data());
|
||||
|
||||
|
||||
PoolVector<int>::Read htr = hash_table.read();
|
||||
const uint32_t *htptr = (const uint32_t *)&htr[0];
|
||||
PoolVector<int>::Read btr = bucket_table.read();
|
||||
|
@ -485,7 +474,6 @@ StringName PHashTranslation::get_message(const StringName& p_src_text) const {
|
|||
idx = i;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//print_line("bucket pos: "+itos(idx));
|
||||
|
@ -513,23 +501,19 @@ StringName PHashTranslation::get_message(const StringName& p_src_text) const {
|
|||
//print_line("Return: "+rstr);
|
||||
return rstr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void PHashTranslation::_get_property_list(List<PropertyInfo> *p_list) const {
|
||||
|
||||
p_list->push_back(PropertyInfo(Variant::POOL_INT_ARRAY, "hash_table"));
|
||||
p_list->push_back(PropertyInfo(Variant::POOL_INT_ARRAY, "bucket_table"));
|
||||
p_list->push_back(PropertyInfo(Variant::POOL_BYTE_ARRAY, "strings"));
|
||||
p_list->push_back(PropertyInfo(Variant::OBJECT, "load_from", PROPERTY_HINT_RESOURCE_TYPE, "Translation", PROPERTY_USAGE_EDITOR));
|
||||
|
||||
}
|
||||
void PHashTranslation::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("generate", "from:Translation"), &PHashTranslation::generate);
|
||||
}
|
||||
|
||||
PHashTranslation::PHashTranslation()
|
||||
{
|
||||
PHashTranslation::PHashTranslation() {
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ class PHashTranslation : public Translation {
|
|||
|
||||
GDCLASS(PHashTranslation, Translation);
|
||||
|
||||
|
||||
//this translation uses a sort of modified perfect hash algorithm
|
||||
//it requieres hashing strings twice and then does a binary search,
|
||||
//so it's slower, but at the same time it has an extreemly high chance
|
||||
|
@ -46,7 +45,6 @@ class PHashTranslation : public Translation {
|
|||
PoolVector<int> bucket_table;
|
||||
PoolVector<uint8_t> strings;
|
||||
|
||||
|
||||
struct Bucket {
|
||||
|
||||
int size;
|
||||
|
@ -75,15 +73,14 @@ class PHashTranslation : public Translation {
|
|||
|
||||
return d;
|
||||
}
|
||||
protected:
|
||||
|
||||
protected:
|
||||
bool _set(const StringName &p_name, const Variant &p_value);
|
||||
bool _get(const StringName &p_name, Variant &r_ret) const;
|
||||
void _get_property_list(List<PropertyInfo> *p_list) const;
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
|
||||
virtual StringName get_message(const StringName &p_src_text) const; //overridable for other implementations
|
||||
void generate(const Ref<Translation> &p_from);
|
||||
|
||||
|
|
|
@ -43,6 +43,4 @@ CoreStringNames::CoreStringNames() {
|
|||
_iter_next = StaticCString::create("_iter_next");
|
||||
_iter_get = StaticCString::create("_iter_get");
|
||||
get_rid = StaticCString::create("get_rid");
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -39,13 +39,16 @@ friend void unregister_core_types();
|
|||
static CoreStringNames *singleton;
|
||||
|
||||
static void create() { singleton = memnew(CoreStringNames); }
|
||||
static void free() { memdelete( singleton); singleton=NULL; }
|
||||
static void free() {
|
||||
memdelete(singleton);
|
||||
singleton = NULL;
|
||||
}
|
||||
|
||||
CoreStringNames();
|
||||
|
||||
public:
|
||||
_FORCE_INLINE_ static CoreStringNames *get_singleton() { return singleton; }
|
||||
|
||||
|
||||
StringName _free;
|
||||
StringName changed;
|
||||
StringName _meta;
|
||||
|
@ -57,7 +60,6 @@ public:
|
|||
StringName _iter_next;
|
||||
StringName _iter_get;
|
||||
StringName get_rid;
|
||||
|
||||
};
|
||||
|
||||
#endif // SCENE_STRING_NAMES_H
|
||||
|
|
|
@ -36,10 +36,6 @@ struct _DictionaryVariantHash {
|
|||
static _FORCE_INLINE_ uint32_t hash(const Variant &p_variant) { return p_variant.hash(); }
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
struct DictionaryPrivate {
|
||||
|
||||
struct Data {
|
||||
|
@ -50,7 +46,6 @@ struct DictionaryPrivate {
|
|||
SafeRefCount refcount;
|
||||
HashMap<Variant, Data, _DictionaryVariantHash> variant_map;
|
||||
int counter;
|
||||
|
||||
};
|
||||
|
||||
struct DictionaryPrivateSort {
|
||||
|
@ -76,12 +71,10 @@ void Dictionary::get_key_list( List<Variant> *p_keys) const {
|
|||
for (int i = 0; i < count; i++) {
|
||||
p_keys->push_back(pairs[i]->key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Variant &Dictionary::operator[](const Variant &p_key) {
|
||||
|
||||
|
||||
DictionaryPrivate::Data *v = _p->variant_map.getptr(p_key);
|
||||
|
||||
if (!v) {
|
||||
|
@ -90,7 +83,6 @@ Variant& Dictionary::operator[](const Variant& p_key) {
|
|||
d.order = _p->counter++;
|
||||
_p->variant_map[p_key] = d;
|
||||
v = _p->variant_map.getptr(p_key);
|
||||
|
||||
}
|
||||
return v->variant;
|
||||
}
|
||||
|
@ -98,7 +90,6 @@ Variant& Dictionary::operator[](const Variant& p_key) {
|
|||
const Variant &Dictionary::operator[](const Variant &p_key) const {
|
||||
|
||||
return _p->variant_map[p_key].variant;
|
||||
|
||||
}
|
||||
const Variant *Dictionary::getptr(const Variant &p_key) const {
|
||||
|
||||
|
@ -116,8 +107,6 @@ Variant* Dictionary::getptr(const Variant& p_key) {
|
|||
return NULL;
|
||||
else
|
||||
return &v->variant;
|
||||
|
||||
|
||||
}
|
||||
|
||||
Variant Dictionary::get_valid(const Variant &p_key) const {
|
||||
|
@ -129,11 +118,9 @@ Variant Dictionary::get_valid(const Variant& p_key) const {
|
|||
return v->variant;
|
||||
}
|
||||
|
||||
|
||||
int Dictionary::size() const {
|
||||
|
||||
return _p->variant_map.size();
|
||||
|
||||
}
|
||||
bool Dictionary::empty() const {
|
||||
|
||||
|
@ -156,7 +143,6 @@ bool Dictionary::has_all(const Array& p_keys) const {
|
|||
|
||||
void Dictionary::erase(const Variant &p_key) {
|
||||
|
||||
|
||||
_p->variant_map.erase(p_key);
|
||||
}
|
||||
|
||||
|
@ -179,7 +165,6 @@ void Dictionary::_ref(const Dictionary& p_from) const {
|
|||
if (_p)
|
||||
_unref();
|
||||
_p = p_from._p;
|
||||
|
||||
}
|
||||
|
||||
void Dictionary::clear() {
|
||||
|
@ -188,7 +173,6 @@ void Dictionary::clear() {
|
|||
_p->counter = 0;
|
||||
}
|
||||
|
||||
|
||||
void Dictionary::_unref() const {
|
||||
|
||||
ERR_FAIL_COND(!_p);
|
||||
|
@ -196,7 +180,6 @@ void Dictionary::_unref() const {
|
|||
memdelete(_p);
|
||||
}
|
||||
_p = NULL;
|
||||
|
||||
}
|
||||
uint32_t Dictionary::hash() const {
|
||||
|
||||
|
@ -209,10 +192,8 @@ uint32_t Dictionary::hash() const {
|
|||
|
||||
h = hash_djb2_one_32(E->get().hash(), h);
|
||||
h = hash_djb2_one_32(operator[](E->get()).hash(), h);
|
||||
|
||||
}
|
||||
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
|
@ -226,7 +207,6 @@ Array Dictionary::keys() const {
|
|||
karr[idx++] = (*K);
|
||||
}
|
||||
return karr;
|
||||
|
||||
}
|
||||
|
||||
Array Dictionary::values() const {
|
||||
|
@ -269,27 +249,21 @@ Dictionary Dictionary::copy() const {
|
|||
return n;
|
||||
}
|
||||
|
||||
|
||||
void Dictionary::operator=(const Dictionary &p_dictionary) {
|
||||
|
||||
_ref(p_dictionary);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Dictionary::Dictionary(const Dictionary &p_from) {
|
||||
_p = NULL;
|
||||
_ref(p_from);
|
||||
}
|
||||
|
||||
|
||||
Dictionary::Dictionary() {
|
||||
|
||||
_p = memnew(DictionaryPrivate);
|
||||
_p->refcount.init();
|
||||
_p->counter = 0;
|
||||
|
||||
|
||||
}
|
||||
Dictionary::~Dictionary() {
|
||||
|
||||
|
|
|
@ -29,25 +29,21 @@
|
|||
#ifndef DICTIONARY_H
|
||||
#define DICTIONARY_H
|
||||
|
||||
|
||||
#include "list.h"
|
||||
#include "array.h"
|
||||
#include "list.h"
|
||||
#include "ustring.h"
|
||||
class Variant;
|
||||
|
||||
|
||||
struct DictionaryPrivate;
|
||||
|
||||
|
||||
class Dictionary {
|
||||
|
||||
mutable DictionaryPrivate *_p;
|
||||
|
||||
|
||||
void _ref(const Dictionary &p_from) const;
|
||||
void _unref() const;
|
||||
public:
|
||||
|
||||
public:
|
||||
void get_key_list(List<Variant> *p_keys) const;
|
||||
|
||||
Variant &operator[](const Variant &p_key);
|
||||
|
|
|
@ -34,7 +34,6 @@ PoolAllocator *MemoryPool::memory_pool=NULL;
|
|||
uint8_t *MemoryPool::pool_memory = NULL;
|
||||
size_t *MemoryPool::pool_size = NULL;
|
||||
|
||||
|
||||
MemoryPool::Alloc *MemoryPool::allocs = NULL;
|
||||
MemoryPool::Alloc *MemoryPool::free_list = NULL;
|
||||
uint32_t MemoryPool::alloc_count = 0;
|
||||
|
@ -44,7 +43,6 @@ Mutex *MemoryPool::alloc_mutex=NULL;
|
|||
size_t MemoryPool::total_memory = 0;
|
||||
size_t MemoryPool::max_memory = 0;
|
||||
|
||||
|
||||
void MemoryPool::setup(uint32_t p_max_allocs) {
|
||||
|
||||
allocs = memnew_arr(Alloc, p_max_allocs);
|
||||
|
@ -59,7 +57,6 @@ void MemoryPool::setup(uint32_t p_max_allocs) {
|
|||
free_list = &allocs[0];
|
||||
|
||||
alloc_mutex = Mutex::create();
|
||||
|
||||
}
|
||||
|
||||
void MemoryPool::cleanup() {
|
||||
|
@ -69,5 +66,4 @@ void MemoryPool::cleanup() {
|
|||
|
||||
ERR_EXPLAINC("There are still MemoryPool allocs in use at exit!");
|
||||
ERR_FAIL_COND(allocs_used > 0);
|
||||
|
||||
}
|
||||
|
|
|
@ -29,11 +29,11 @@
|
|||
#ifndef DVECTOR_H
|
||||
#define DVECTOR_H
|
||||
|
||||
#include "os/memory.h"
|
||||
#include "os/copymem.h"
|
||||
#include "os/memory.h"
|
||||
#include "os/rw_lock.h"
|
||||
#include "pool_allocator.h"
|
||||
#include "safe_refcount.h"
|
||||
#include "os/rw_lock.h"
|
||||
#include "ustring.h"
|
||||
|
||||
struct MemoryPool {
|
||||
|
@ -44,7 +44,6 @@ struct MemoryPool {
|
|||
static uint8_t *pool_memory;
|
||||
static size_t *pool_size;
|
||||
|
||||
|
||||
struct Alloc {
|
||||
|
||||
SafeRefCount refcount;
|
||||
|
@ -55,10 +54,15 @@ struct MemoryPool {
|
|||
|
||||
Alloc *free_list;
|
||||
|
||||
Alloc() { mem=NULL; lock=0; pool_id=POOL_ALLOCATOR_INVALID_ID; size=0; free_list=NULL; }
|
||||
Alloc() {
|
||||
mem = NULL;
|
||||
lock = 0;
|
||||
pool_id = POOL_ALLOCATOR_INVALID_ID;
|
||||
size = 0;
|
||||
free_list = NULL;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
static Alloc *allocs;
|
||||
static Alloc *free_list;
|
||||
static uint32_t alloc_count;
|
||||
|
@ -67,26 +71,21 @@ struct MemoryPool {
|
|||
static size_t total_memory;
|
||||
static size_t max_memory;
|
||||
|
||||
|
||||
static void setup(uint32_t p_max_allocs = (1 << 16));
|
||||
static void cleanup();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
@author Juan Linietsky <reduzio@gmail.com>
|
||||
*/
|
||||
|
||||
|
||||
template <class T>
|
||||
class PoolVector {
|
||||
|
||||
MemoryPool::Alloc *alloc;
|
||||
|
||||
|
||||
void _copy_on_write() {
|
||||
|
||||
|
||||
if (!alloc)
|
||||
return;
|
||||
|
||||
|
@ -95,7 +94,6 @@ class PoolVector {
|
|||
if (alloc->refcount.get() == 1)
|
||||
return; //nothing to do
|
||||
|
||||
|
||||
//must allocate something
|
||||
|
||||
MemoryPool::alloc_mutex->lock();
|
||||
|
@ -128,10 +126,8 @@ class PoolVector {
|
|||
|
||||
MemoryPool::alloc_mutex->unlock();
|
||||
|
||||
|
||||
if (MemoryPool::memory_pool) {
|
||||
|
||||
|
||||
} else {
|
||||
alloc->mem = memalloc(alloc->size);
|
||||
}
|
||||
|
@ -150,7 +146,6 @@ class PoolVector {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
if (old_alloc->refcount.unref() == true) {
|
||||
//this should never happen but..
|
||||
|
||||
|
@ -169,7 +164,6 @@ class PoolVector {
|
|||
for (int i = 0; i < cur_elements; i++) {
|
||||
elems[i].~T();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (MemoryPool::memory_pool) {
|
||||
|
@ -178,21 +172,17 @@ class PoolVector {
|
|||
//if some resize
|
||||
} else {
|
||||
|
||||
|
||||
memfree(old_alloc->mem);
|
||||
old_alloc->mem = NULL;
|
||||
old_alloc->size = 0;
|
||||
|
||||
|
||||
MemoryPool::alloc_mutex->lock();
|
||||
old_alloc->free_list = MemoryPool::free_list;
|
||||
MemoryPool::free_list = old_alloc;
|
||||
MemoryPool::allocs_used--;
|
||||
MemoryPool::alloc_mutex->unlock();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void _reference(const PoolVector &p_dvector) {
|
||||
|
@ -209,10 +199,8 @@ class PoolVector {
|
|||
if (p_dvector.alloc->refcount.ref()) {
|
||||
alloc = p_dvector.alloc;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void _unreference() {
|
||||
|
||||
if (!alloc)
|
||||
|
@ -233,7 +221,6 @@ class PoolVector {
|
|||
|
||||
w[i].~T();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
|
@ -242,7 +229,6 @@ class PoolVector {
|
|||
MemoryPool::alloc_mutex->unlock();
|
||||
#endif
|
||||
|
||||
|
||||
if (MemoryPool::memory_pool) {
|
||||
//resize memory pool
|
||||
//if none, create
|
||||
|
@ -253,22 +239,20 @@ class PoolVector {
|
|||
alloc->mem = NULL;
|
||||
alloc->size = 0;
|
||||
|
||||
|
||||
MemoryPool::alloc_mutex->lock();
|
||||
alloc->free_list = MemoryPool::free_list;
|
||||
MemoryPool::free_list = alloc;
|
||||
MemoryPool::allocs_used--;
|
||||
MemoryPool::alloc_mutex->unlock();
|
||||
|
||||
}
|
||||
|
||||
alloc = NULL;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
class Access {
|
||||
friend class PoolVector;
|
||||
|
||||
protected:
|
||||
MemoryPool::Alloc *alloc;
|
||||
T *mem;
|
||||
|
@ -288,7 +272,6 @@ public:
|
|||
|
||||
_FORCE_INLINE_ void _unref() {
|
||||
|
||||
|
||||
if (alloc) {
|
||||
if (atomic_decrement(&alloc->lock) == 0) {
|
||||
if (MemoryPool::memory_pool) {
|
||||
|
@ -299,8 +282,6 @@ public:
|
|||
mem = NULL;
|
||||
alloc = NULL;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Access() {
|
||||
|
@ -308,7 +289,6 @@ public:
|
|||
mem = NULL;
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
virtual ~Access() {
|
||||
_unref();
|
||||
|
@ -317,7 +297,6 @@ public:
|
|||
|
||||
class Read : public Access {
|
||||
public:
|
||||
|
||||
_FORCE_INLINE_ const T &operator[](int p_index) const { return this->mem[p_index]; }
|
||||
_FORCE_INLINE_ const T *ptr() const { return this->mem; }
|
||||
|
||||
|
@ -333,13 +312,10 @@ public:
|
|||
}
|
||||
|
||||
Read() {}
|
||||
|
||||
|
||||
};
|
||||
|
||||
class Write : public Access {
|
||||
public:
|
||||
|
||||
_FORCE_INLINE_ T &operator[](int p_index) const { return this->mem[p_index]; }
|
||||
_FORCE_INLINE_ T *ptr() const { return this->mem; }
|
||||
|
||||
|
@ -355,10 +331,8 @@ public:
|
|||
}
|
||||
|
||||
Write() {}
|
||||
|
||||
};
|
||||
|
||||
|
||||
Read read() const {
|
||||
|
||||
Read r;
|
||||
|
@ -366,7 +340,6 @@ public:
|
|||
r._ref(alloc);
|
||||
}
|
||||
return r;
|
||||
|
||||
}
|
||||
Write write() {
|
||||
|
||||
|
@ -381,7 +354,6 @@ public:
|
|||
template <class MC>
|
||||
void fill_with(const MC &p_mc) {
|
||||
|
||||
|
||||
int c = p_mc.size();
|
||||
resize(c);
|
||||
Write w = write();
|
||||
|
@ -392,7 +364,6 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void remove(int p_index) {
|
||||
|
||||
int s = size();
|
||||
|
@ -488,9 +459,11 @@ public:
|
|||
|
||||
void operator=(const PoolVector &p_dvector) { _reference(p_dvector); }
|
||||
PoolVector() { alloc = NULL; }
|
||||
PoolVector(const PoolVector& p_dvector) { alloc=NULL; _reference(p_dvector); }
|
||||
PoolVector(const PoolVector &p_dvector) {
|
||||
alloc = NULL;
|
||||
_reference(p_dvector);
|
||||
}
|
||||
~PoolVector() { _unreference(); }
|
||||
|
||||
};
|
||||
|
||||
template <class T>
|
||||
|
@ -536,11 +509,9 @@ const T PoolVector<T>::operator[](int p_index) const {
|
|||
return r[p_index];
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
Error PoolVector<T>::resize(int p_size) {
|
||||
|
||||
|
||||
if (alloc == NULL) {
|
||||
|
||||
if (p_size == 0)
|
||||
|
@ -593,7 +564,6 @@ Error PoolVector<T>::resize(int p_size) {
|
|||
MemoryPool::alloc_mutex->unlock();
|
||||
#endif
|
||||
|
||||
|
||||
int cur_elements = alloc->size / sizeof(T);
|
||||
|
||||
if (p_size > cur_elements) {
|
||||
|
@ -620,7 +590,6 @@ Error PoolVector<T>::resize(int p_size) {
|
|||
memnew_placement(&w[i], T);
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
{
|
||||
|
@ -629,7 +598,6 @@ Error PoolVector<T>::resize(int p_size) {
|
|||
|
||||
w[i].~T();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (MemoryPool::memory_pool) {
|
||||
|
@ -654,7 +622,6 @@ Error PoolVector<T>::resize(int p_size) {
|
|||
alloc->size = new_size;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
|
|
@ -95,15 +95,13 @@ Dictionary Engine::get_version_info() const {
|
|||
return dict;
|
||||
}
|
||||
|
||||
|
||||
Engine *Engine::singleton = NULL;
|
||||
|
||||
Engine *Engine::get_singleton() {
|
||||
return singleton;
|
||||
}
|
||||
|
||||
Engine::Engine()
|
||||
{
|
||||
Engine::Engine() {
|
||||
|
||||
singleton = this;
|
||||
frames_drawn = 0;
|
||||
|
|
|
@ -29,10 +29,10 @@
|
|||
#ifndef ENGINE_H
|
||||
#define ENGINE_H
|
||||
|
||||
#include "ustring.h"
|
||||
#include "list.h"
|
||||
#include "vector.h"
|
||||
#include "os/main_loop.h"
|
||||
#include "ustring.h"
|
||||
#include "vector.h"
|
||||
|
||||
class Engine {
|
||||
|
||||
|
@ -52,8 +52,8 @@ friend class Main;
|
|||
bool _in_fixed;
|
||||
|
||||
static Engine *singleton;
|
||||
public:
|
||||
|
||||
public:
|
||||
static Engine *get_singleton();
|
||||
|
||||
virtual void set_iterations_per_second(int p_ips);
|
||||
|
|
|
@ -90,7 +90,4 @@ enum Error {
|
|||
ERR_WTF = ERR_OMFG_THIS_IS_VERY_VERY_BAD ///< short version of the above
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
|
||||
#include "os/os.h"
|
||||
|
||||
|
||||
bool _err_error_exists = false;
|
||||
|
||||
static ErrorHandlerList *error_handler_list = NULL;
|
||||
|
@ -72,17 +71,13 @@ void remove_error_handler(ErrorHandlerList *p_handler) {
|
|||
}
|
||||
prev = l;
|
||||
l = l->next;
|
||||
|
||||
}
|
||||
|
||||
_global_unlock();
|
||||
|
||||
}
|
||||
|
||||
void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, ErrorHandlerType p_type) {
|
||||
|
||||
|
||||
|
||||
OS::get_singleton()->print_error(p_function, p_file, p_line, p_error, _err_error_exists ? OS::get_singleton()->get_last_error() : "", (OS::ErrorType)p_type);
|
||||
|
||||
_global_lock();
|
||||
|
@ -99,5 +94,4 @@ void _err_print_error(const char* p_function, const char* p_file,int p_line,cons
|
|||
OS::get_singleton()->clear_last_error();
|
||||
_err_error_exists = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
#ifndef ERROR_MACROS_H
|
||||
#define ERROR_MACROS_H
|
||||
|
||||
|
||||
/**
|
||||
* Error macros. Unlike exceptions and asserts, these macros try to mantain consistency and stability
|
||||
* inside the code. It is recommended to always return processable data, so in case of an error, the
|
||||
|
@ -64,7 +63,11 @@ struct ErrorHandlerList {
|
|||
|
||||
ErrorHandlerList *next;
|
||||
|
||||
ErrorHandlerList() { errfunc=0; next=0; userdata=0; }
|
||||
ErrorHandlerList() {
|
||||
errfunc = 0;
|
||||
next = 0;
|
||||
userdata = 0;
|
||||
}
|
||||
};
|
||||
|
||||
void add_error_handler(ErrorHandlerList *p_handler);
|
||||
|
@ -86,8 +89,16 @@ extern bool _err_error_exists;
|
|||
#ifdef DEBUG_ENABLED
|
||||
/** Print a warning string.
|
||||
*/
|
||||
#define ERR_EXPLAINC(m_reason) {_err_set_last_error(m_reason); _err_error_exists=true;}
|
||||
#define ERR_EXPLAIN(m_string) {_err_set_last_error(String(m_string).utf8().get_data()); _err_error_exists=true;}
|
||||
#define ERR_EXPLAINC(m_reason) \
|
||||
{ \
|
||||
_err_set_last_error(m_reason); \
|
||||
_err_error_exists = true; \
|
||||
}
|
||||
#define ERR_EXPLAIN(m_string) \
|
||||
{ \
|
||||
_err_set_last_error(String(m_string).utf8().get_data()); \
|
||||
_err_error_exists = true; \
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
|
@ -104,10 +115,13 @@ extern bool _err_error_exists;
|
|||
#endif
|
||||
|
||||
#define ERR_FAIL_INDEX(m_index, m_size) \
|
||||
do {if ((m_index)<0 || (m_index)>=(m_size)) { \
|
||||
do { \
|
||||
if ((m_index) < 0 || (m_index) >= (m_size)) { \
|
||||
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Index " _STR(m_index) " out of size (" _STR(m_size) ")."); \
|
||||
return; \
|
||||
} else _err_error_exists=false; } while(0); \
|
||||
} else \
|
||||
_err_error_exists = false; \
|
||||
} while (0);
|
||||
|
||||
/** An index has failed if m_index<0 or m_index >=m_size, the function exists.
|
||||
* This function returns an error value, if returning Error, please select the most
|
||||
|
@ -115,37 +129,48 @@ extern bool _err_error_exists;
|
|||
*/
|
||||
|
||||
#define ERR_FAIL_INDEX_V(m_index, m_size, m_retval) \
|
||||
do {if ((m_index)<0 || (m_index)>=(m_size)) { \
|
||||
do { \
|
||||
if ((m_index) < 0 || (m_index) >= (m_size)) { \
|
||||
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Index " _STR(m_index) " out of size (" _STR(m_size) ")."); \
|
||||
return m_retval; \
|
||||
} else _err_error_exists=false;} while (0);
|
||||
} else \
|
||||
_err_error_exists = false; \
|
||||
} while (0);
|
||||
|
||||
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
|
||||
* the function will exit.
|
||||
*/
|
||||
|
||||
#define ERR_FAIL_NULL(m_param) \
|
||||
{ if ( !m_param ) { \
|
||||
{ \
|
||||
if (!m_param) { \
|
||||
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter ' " _STR(m_param) " ' is null."); \
|
||||
return; \
|
||||
}else _err_error_exists=false; } \
|
||||
|
||||
} else \
|
||||
_err_error_exists = false; \
|
||||
}
|
||||
|
||||
#define ERR_FAIL_NULL_V(m_param, m_retval) \
|
||||
{ if ( !m_param ) { \
|
||||
{ \
|
||||
if (!m_param) { \
|
||||
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter ' " _STR(m_param) " ' is null."); \
|
||||
return m_retval; \
|
||||
}else _err_error_exists=false; } \
|
||||
} else \
|
||||
_err_error_exists = false; \
|
||||
}
|
||||
|
||||
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
|
||||
* the function will exit.
|
||||
*/
|
||||
|
||||
#define ERR_FAIL_COND(m_cond) \
|
||||
{ if ( m_cond ) { \
|
||||
{ \
|
||||
if (m_cond) { \
|
||||
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true."); \
|
||||
return; \
|
||||
}else _err_error_exists=false; } \
|
||||
} else \
|
||||
_err_error_exists = false; \
|
||||
}
|
||||
|
||||
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
|
||||
* the function will exit.
|
||||
|
@ -154,30 +179,39 @@ extern bool _err_error_exists;
|
|||
*/
|
||||
|
||||
#define ERR_FAIL_COND_V(m_cond, m_retval) \
|
||||
{ if ( m_cond ) { \
|
||||
{ \
|
||||
if (m_cond) { \
|
||||
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. returned: " _STR(m_retval)); \
|
||||
return m_retval; \
|
||||
}else _err_error_exists=false; } \
|
||||
} else \
|
||||
_err_error_exists = false; \
|
||||
}
|
||||
|
||||
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
|
||||
* the loop will skip to the next iteration.
|
||||
*/
|
||||
|
||||
#define ERR_CONTINUE(m_cond) \
|
||||
{ if ( m_cond ) { \
|
||||
{ \
|
||||
if (m_cond) { \
|
||||
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. Continuing..:"); \
|
||||
continue; \
|
||||
} else _err_error_exists=false;} \
|
||||
} else \
|
||||
_err_error_exists = false; \
|
||||
}
|
||||
|
||||
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
|
||||
* the loop will break
|
||||
*/
|
||||
|
||||
#define ERR_BREAK(m_cond) \
|
||||
{ if ( m_cond ) { \
|
||||
{ \
|
||||
if (m_cond) { \
|
||||
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. Breaking..:"); \
|
||||
break; \
|
||||
} else _err_error_exists=false;} \
|
||||
} else \
|
||||
_err_error_exists = false; \
|
||||
}
|
||||
|
||||
/** Print an error string and return
|
||||
*/
|
||||
|
@ -187,7 +221,7 @@ extern bool _err_error_exists;
|
|||
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/Function Failed."); \
|
||||
_err_error_exists = false; \
|
||||
return; \
|
||||
} \
|
||||
}
|
||||
|
||||
/** Print an error string and return with value
|
||||
*/
|
||||
|
@ -197,7 +231,7 @@ extern bool _err_error_exists;
|
|||
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/Function Failed, returning: " __STR(m_value)); \
|
||||
_err_error_exists = false; \
|
||||
return m_value; \
|
||||
} \
|
||||
}
|
||||
|
||||
/** Print an error string.
|
||||
*/
|
||||
|
@ -206,13 +240,13 @@ extern bool _err_error_exists;
|
|||
{ \
|
||||
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string); \
|
||||
_err_error_exists = false; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define ERR_PRINTS(m_string) \
|
||||
{ \
|
||||
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, String(m_string).utf8().get_data()); \
|
||||
_err_error_exists = false; \
|
||||
} \
|
||||
}
|
||||
|
||||
/** Print a warning string.
|
||||
*/
|
||||
|
@ -221,13 +255,12 @@ extern bool _err_error_exists;
|
|||
{ \
|
||||
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string, ERR_HANDLER_WARNING); \
|
||||
_err_error_exists = false; \
|
||||
} \
|
||||
|
||||
}
|
||||
|
||||
#define WARN_PRINTS(m_string) \
|
||||
{ \
|
||||
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, String(m_string).utf8().get_data(), ERR_HANDLER_WARNING); \
|
||||
_err_error_exists = false; \
|
||||
} \
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
/*************************************************************************/
|
||||
#include "event_queue.h"
|
||||
|
||||
|
||||
Error EventQueue::push_call(uint32_t p_instance_ID, const StringName &p_method, VARIANT_ARG_DECLARE) {
|
||||
|
||||
uint8_t room_needed = sizeof(Event);
|
||||
|
@ -75,7 +74,6 @@ Error EventQueue::push_call(uint32_t p_instance_ID, const StringName& p_method,
|
|||
Variant *v = memnew_placement(&event_buffer[buffer_end], Variant);
|
||||
buffer_end += sizeof(Variant);
|
||||
*v = p_arg3;
|
||||
|
||||
}
|
||||
|
||||
if (args >= 4) {
|
||||
|
@ -133,12 +131,10 @@ void EventQueue::flush_events() {
|
|||
|
||||
EventQueue::EventQueue(uint32_t p_buffer_size) {
|
||||
|
||||
|
||||
buffer_end = 0;
|
||||
buffer_max_used = 0;
|
||||
buffer_size = p_buffer_size;
|
||||
event_buffer = memnew_arr(uint8_t, buffer_size);
|
||||
|
||||
}
|
||||
EventQueue::~EventQueue() {
|
||||
|
||||
|
@ -158,4 +154,3 @@ EventQueue::~EventQueue() {
|
|||
memdelete_arr(event_buffer);
|
||||
event_buffer = NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,20 +47,17 @@ class EventQueue {
|
|||
int args;
|
||||
};
|
||||
|
||||
|
||||
uint8_t *event_buffer;
|
||||
uint32_t buffer_end;
|
||||
uint32_t buffer_max_used;
|
||||
uint32_t buffer_size;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
Error push_call(uint32_t p_instance_ID, const StringName &p_method, VARIANT_ARG_LIST);
|
||||
void flush_events();
|
||||
|
||||
EventQueue(uint32_t p_buffer_size = DEFAULT_EVENT_QUEUE_SIZE_KB * 1024);
|
||||
~EventQueue();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -42,7 +42,6 @@ Variant FuncRef::call_func(const Variant** p_args, int p_argcount, Variant::Call
|
|||
}
|
||||
|
||||
return obj->call(function, p_args, p_argcount, r_error);
|
||||
|
||||
}
|
||||
|
||||
void FuncRef::set_instance(Object *p_obj) {
|
||||
|
@ -62,17 +61,13 @@ void FuncRef::_bind_methods() {
|
|||
mi.name = "call_func";
|
||||
Vector<Variant> defargs;
|
||||
ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "call_func:Variant", &FuncRef::call_func, mi, defargs);
|
||||
|
||||
}
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_instance", "instance"), &FuncRef::set_instance);
|
||||
ClassDB::bind_method(D_METHOD("set_function", "name"), &FuncRef::set_function);
|
||||
|
||||
}
|
||||
|
||||
|
||||
FuncRef::FuncRef() {
|
||||
|
||||
id = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,10 +38,9 @@ class FuncRef : public Reference{
|
|||
StringName function;
|
||||
|
||||
protected:
|
||||
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
||||
public:
|
||||
Variant call_func(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
|
||||
void set_instance(Object *p_obj);
|
||||
void set_function(const StringName &p_func);
|
||||
|
|
|
@ -28,14 +28,14 @@
|
|||
/*************************************************************************/
|
||||
#include "global_config.h"
|
||||
|
||||
#include "bind/core_bind.h"
|
||||
#include "io/file_access_network.h"
|
||||
#include "io/file_access_pack.h"
|
||||
#include "io/marshalls.h"
|
||||
#include "os/dir_access.h"
|
||||
#include "os/file_access.h"
|
||||
#include "os/keyboard.h"
|
||||
#include "io/marshalls.h"
|
||||
#include "bind/core_bind.h"
|
||||
#include "os/os.h"
|
||||
#include "io/file_access_pack.h"
|
||||
#include "io/file_access_network.h"
|
||||
#include "variant_parser.h"
|
||||
|
||||
#define FORMAT_VERSION 3
|
||||
|
@ -61,7 +61,6 @@ String GlobalConfig::localize_path(const String& p_path) const {
|
|||
(p_path.is_abs_path() && !p_path.begins_with(resource_path)))
|
||||
return p_path.simplify_path();
|
||||
|
||||
|
||||
DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
||||
|
||||
String path = p_path.replace("\\", "/").simplify_path();
|
||||
|
@ -87,7 +86,6 @@ String GlobalConfig::localize_path(const String& p_path) const {
|
|||
return "res://" + path;
|
||||
};
|
||||
|
||||
|
||||
String parent = path.substr(0, sep);
|
||||
|
||||
String plocal = localize_path(parent);
|
||||
|
@ -96,7 +94,6 @@ String GlobalConfig::localize_path(const String& p_path) const {
|
|||
};
|
||||
return plocal + path.substr(sep, path.size() - sep);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
void GlobalConfig::set_initial_value(const String &p_name, const Variant &p_value) {
|
||||
|
@ -105,7 +102,6 @@ void GlobalConfig::set_initial_value(const String& p_name, const Variant & p_val
|
|||
props[p_name].initial = p_value;
|
||||
}
|
||||
|
||||
|
||||
String GlobalConfig::globalize_path(const String &p_path) const {
|
||||
|
||||
if (p_path.begins_with("res://")) {
|
||||
|
@ -120,12 +116,10 @@ String GlobalConfig::globalize_path(const String& p_path) const {
|
|||
return p_path;
|
||||
}
|
||||
|
||||
|
||||
bool GlobalConfig::_set(const StringName &p_name, const Variant &p_value) {
|
||||
|
||||
_THREAD_SAFE_METHOD_
|
||||
|
||||
|
||||
if (p_value.get_type() == Variant::NIL)
|
||||
props.erase(p_name);
|
||||
else {
|
||||
|
@ -161,7 +155,6 @@ bool GlobalConfig::_set(const StringName& p_name, const Variant& p_value) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -176,7 +169,6 @@ bool GlobalConfig::_get(const StringName& p_name,Variant &r_ret) const {
|
|||
}
|
||||
r_ret = props[p_name].variant;
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
struct _VCSort {
|
||||
|
@ -226,8 +218,6 @@ void GlobalConfig::_get_property_list(List<PropertyInfo> *p_list) const {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool GlobalConfig::_load_resource_pack(const String &p_pack) {
|
||||
|
||||
if (PackedData::get_singleton()->is_disabled())
|
||||
|
@ -254,7 +244,6 @@ Error GlobalConfig::setup(const String& p_path,const String & p_main_pack) {
|
|||
if (_load_settings("res://godot.cfg") == OK || _load_settings_binary("res://godot.cfb") == OK) {
|
||||
|
||||
_load_settings("res://override.cfg");
|
||||
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
@ -272,33 +261,25 @@ Error GlobalConfig::setup(const String& p_path,const String & p_main_pack) {
|
|||
if (_load_settings("res://godot.cfg") == OK || _load_settings_binary("res://godot.cfb") == OK) {
|
||||
//load override from location of the main pack
|
||||
_load_settings(p_main_pack.get_base_dir().plus_file("override.cfg"));
|
||||
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
||||
}
|
||||
|
||||
//Attempt with execname.pck
|
||||
if (exec_path != "") {
|
||||
|
||||
|
||||
if (_load_resource_pack(exec_path.get_basename() + ".pck")) {
|
||||
|
||||
if (_load_settings("res://godot.cfg") == OK || _load_settings_binary("res://godot.cfb") == OK) {
|
||||
//load override from location of executable
|
||||
_load_settings(exec_path.get_base_dir().plus_file("override.cfg"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//Try to use the filesystem for files, according to OS. (only Android -when reading from pck- and iOS use this)
|
||||
if (OS::get_singleton()->get_resource_dir() != "") {
|
||||
//OS will call Globals->get_resource_path which will be empty if not overriden!
|
||||
|
@ -313,7 +294,6 @@ Error GlobalConfig::setup(const String& p_path,const String & p_main_pack) {
|
|||
|
||||
if (_load_settings("res://godot.cfg") == OK || _load_settings_binary("res://godot.cfb") == OK) {
|
||||
_load_settings("res://override.cfg");
|
||||
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
@ -347,7 +327,6 @@ Error GlobalConfig::setup(const String& p_path,const String & p_main_pack) {
|
|||
current_dir = d->get_current_dir();
|
||||
}
|
||||
|
||||
|
||||
resource_path = candidate;
|
||||
resource_path = resource_path.replace("\\", "/"); // windows path to unix path just in case
|
||||
memdelete(d);
|
||||
|
@ -368,7 +347,6 @@ bool GlobalConfig::has(String p_var) const {
|
|||
return props.has(p_var);
|
||||
}
|
||||
|
||||
|
||||
void GlobalConfig::set_registering_order(bool p_enable) {
|
||||
|
||||
registering_order = p_enable;
|
||||
|
@ -382,7 +360,6 @@ Error GlobalConfig::_load_settings_binary(const String p_path) {
|
|||
return err;
|
||||
}
|
||||
|
||||
|
||||
uint8_t hdr[4];
|
||||
f->get_buffer(hdr, 4);
|
||||
if (hdr[0] != 'E' || hdr[1] != 'C' || hdr[2] != 'F' || hdr[3] != 'G') {
|
||||
|
@ -415,18 +392,14 @@ Error GlobalConfig::_load_settings_binary(const String p_path) {
|
|||
ERR_EXPLAIN("Error decoding property: " + key);
|
||||
ERR_CONTINUE(err != OK);
|
||||
set(key, value);
|
||||
|
||||
}
|
||||
|
||||
set_registering_order(true);
|
||||
|
||||
|
||||
return OK;
|
||||
}
|
||||
Error GlobalConfig::_load_settings(const String p_path) {
|
||||
|
||||
|
||||
|
||||
Error err;
|
||||
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
|
||||
|
||||
|
@ -455,8 +428,7 @@ Error GlobalConfig::_load_settings(const String p_path) {
|
|||
if (err == ERR_FILE_EOF) {
|
||||
memdelete(f);
|
||||
return OK;
|
||||
}
|
||||
else if (err!=OK) {
|
||||
} else if (err != OK) {
|
||||
ERR_PRINTS("GlobalConfig::load - " + p_path + ":" + itos(lines) + " error: " + error_text);
|
||||
memdelete(f);
|
||||
return err;
|
||||
|
@ -469,7 +441,6 @@ Error GlobalConfig::_load_settings(const String p_path) {
|
|||
memdelete(f);
|
||||
ERR_FAIL_COND_V(config_version > FORMAT_VERSION, ERR_FILE_CANT_OPEN);
|
||||
}
|
||||
|
||||
}
|
||||
set(section + "/" + assign, value);
|
||||
} else if (next_tag.name != String()) {
|
||||
|
@ -480,18 +451,14 @@ Error GlobalConfig::_load_settings(const String p_path) {
|
|||
memdelete(f);
|
||||
|
||||
return OK;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int GlobalConfig::get_order(const String &p_name) const {
|
||||
|
||||
ERR_FAIL_COND_V(!props.has(p_name), -1);
|
||||
return props[p_name].order;
|
||||
}
|
||||
|
||||
|
||||
void GlobalConfig::set_order(const String &p_name, int p_order) {
|
||||
|
||||
ERR_FAIL_COND(!props.has(p_name));
|
||||
|
@ -511,7 +478,6 @@ Error GlobalConfig::save() {
|
|||
|
||||
Error GlobalConfig::_save_settings_binary(const String &p_file, const Map<String, List<String> > &props, const CustomMap &p_custom) {
|
||||
|
||||
|
||||
Error err;
|
||||
FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err);
|
||||
if (err != OK) {
|
||||
|
@ -535,7 +501,6 @@ Error GlobalConfig::_save_settings_binary(const String& p_file,const Map<String,
|
|||
|
||||
file->store_32(count); //store how many properties are saved
|
||||
|
||||
|
||||
for (Map<String, List<String> >::Element *E = props.front(); E; E = E->next()) {
|
||||
|
||||
for (List<String>::Element *F = E->get().front(); F; F = F->next()) {
|
||||
|
@ -573,11 +538,9 @@ Error GlobalConfig::_save_settings_binary(const String& p_file,const Map<String,
|
|||
file->close();
|
||||
memdelete(file);
|
||||
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
Error GlobalConfig::_save_settings_text(const String &p_file, const Map<String, List<String> > &props, const CustomMap &p_custom) {
|
||||
|
||||
Error err;
|
||||
|
@ -590,7 +553,6 @@ Error GlobalConfig::_save_settings_text(const String& p_file,const Map<String,Li
|
|||
|
||||
file->store_string("config_version=" + itos(FORMAT_VERSION) + "\n");
|
||||
|
||||
|
||||
for (Map<String, List<String> >::Element *E = props.front(); E; E = E->next()) {
|
||||
|
||||
if (E != props.front())
|
||||
|
@ -609,11 +571,9 @@ Error GlobalConfig::_save_settings_text(const String& p_file,const Map<String,Li
|
|||
else
|
||||
value = get(key);
|
||||
|
||||
|
||||
String vstr;
|
||||
VariantWriter::write_to_string(value, vstr);
|
||||
file->store_string(F->get() + "=" + vstr + "\n");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -665,13 +625,11 @@ Error GlobalConfig::save_custom(const String& p_path,const CustomMap& p_custom,c
|
|||
if (v->variant == v->initial)
|
||||
continue;
|
||||
|
||||
|
||||
vclist.insert(vc);
|
||||
}
|
||||
|
||||
for (const Map<String, Variant>::Element *E = p_custom.front(); E; E = E->next()) {
|
||||
|
||||
|
||||
_VCSort vc;
|
||||
vc.name = E->key();
|
||||
vc.order = 0xFFFFFFF;
|
||||
|
@ -699,8 +657,6 @@ Error GlobalConfig::save_custom(const String& p_path,const CustomMap& p_custom,c
|
|||
props[category].push_back(name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (p_path.ends_with(".cfg"))
|
||||
return _save_settings_text(p_path, props, p_custom);
|
||||
else if (p_path.ends_with(".cfb"))
|
||||
|
@ -763,7 +719,6 @@ Variant _GLOBAL_DEF( const String& p_var, const Variant& p_default) {
|
|||
GlobalConfig::get_singleton()->set(p_var, p_default);
|
||||
GlobalConfig::get_singleton()->set_initial_value(p_var, p_default);
|
||||
return p_default;
|
||||
|
||||
}
|
||||
|
||||
void GlobalConfig::add_singleton(const Singleton &p_singleton) {
|
||||
|
@ -774,13 +729,11 @@ void GlobalConfig::add_singleton(const Singleton &p_singleton) {
|
|||
|
||||
Object *GlobalConfig::get_singleton_object(const String &p_name) const {
|
||||
|
||||
|
||||
const Map<StringName, Object *>::Element *E = singleton_ptrs.find(p_name);
|
||||
if (!E)
|
||||
return NULL;
|
||||
else
|
||||
return E->get();
|
||||
|
||||
};
|
||||
|
||||
bool GlobalConfig::has_singleton(const String &p_name) const {
|
||||
|
@ -810,7 +763,6 @@ Vector<String> GlobalConfig::get_optimizer_presets() const {
|
|||
names.sort();
|
||||
|
||||
return names;
|
||||
|
||||
}
|
||||
|
||||
void GlobalConfig::_add_property_info_bind(const Dictionary &p_info) {
|
||||
|
@ -837,7 +789,6 @@ void GlobalConfig::set_custom_property_info(const String& p_prop,const PropertyI
|
|||
ERR_FAIL_COND(!props.has(p_prop));
|
||||
custom_prop_info[p_prop] = p_info;
|
||||
custom_prop_info[p_prop].name = p_prop;
|
||||
|
||||
}
|
||||
|
||||
void GlobalConfig::set_disable_platform_override(bool p_disable) {
|
||||
|
@ -856,7 +807,6 @@ bool GlobalConfig::property_can_revert(const String& p_name) {
|
|||
return false;
|
||||
|
||||
return props[p_name].initial != props[p_name].variant;
|
||||
|
||||
}
|
||||
|
||||
Variant GlobalConfig::property_get_revert(const String &p_name) {
|
||||
|
@ -885,25 +835,21 @@ void GlobalConfig::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("property_get_revert", "name"), &GlobalConfig::property_get_revert);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("save_custom", "file"), &GlobalConfig::_save_custom_bnd);
|
||||
|
||||
}
|
||||
|
||||
GlobalConfig::GlobalConfig() {
|
||||
|
||||
|
||||
singleton = this;
|
||||
last_order = 0;
|
||||
disable_platform_override = false;
|
||||
registering_order = true;
|
||||
|
||||
|
||||
Array va;
|
||||
InputEvent key;
|
||||
key.type = InputEvent::KEY;
|
||||
InputEvent joyb;
|
||||
joyb.type = InputEvent::JOYPAD_BUTTON;
|
||||
|
||||
|
||||
GLOBAL_DEF("application/name", "");
|
||||
GLOBAL_DEF("application/main_scene", "");
|
||||
custom_prop_info["application/main_scene"] = PropertyInfo(Variant::STRING, "application/main_scene", PROPERTY_HINT_FILE, "tscn,scn,xscn,xml,res");
|
||||
|
@ -911,7 +857,6 @@ GlobalConfig::GlobalConfig() {
|
|||
GLOBAL_DEF("application/disable_stderr", false);
|
||||
GLOBAL_DEF("application/use_shared_user_dir", true);
|
||||
|
||||
|
||||
key.key.scancode = KEY_RETURN;
|
||||
va.push_back(key);
|
||||
key.key.scancode = KEY_ENTER;
|
||||
|
@ -985,7 +930,6 @@ GlobalConfig::GlobalConfig() {
|
|||
GLOBAL_DEF("input/ui_down", va);
|
||||
input_presets.push_back("input/ui_down");
|
||||
|
||||
|
||||
va = Array();
|
||||
key.key.scancode = KEY_PAGEUP;
|
||||
va.push_back(key);
|
||||
|
@ -1000,7 +944,6 @@ GlobalConfig::GlobalConfig() {
|
|||
|
||||
//GLOBAL_DEF("display/handheld/orientation", "landscape");
|
||||
|
||||
|
||||
custom_prop_info["display/handheld/orientation"] = PropertyInfo(Variant::STRING, "display/handheld/orientation", PROPERTY_HINT_ENUM, "landscape,portrait,reverse_landscape,reverse_portrait,sensor_landscape,sensor_portrait,sensor");
|
||||
custom_prop_info["rendering/threads/thread_model"] = PropertyInfo(Variant::INT, "rendering/threads/thread_model", PROPERTY_HINT_ENUM, "Single-Unsafe,Single-Safe,Multi-Threaded");
|
||||
custom_prop_info["physics/2d/thread_model"] = PropertyInfo(Variant::INT, "physics/2d/thread_model", PROPERTY_HINT_ENUM, "Single-Unsafe,Single-Safe,Multi-Threaded");
|
||||
|
@ -1009,10 +952,7 @@ GlobalConfig::GlobalConfig() {
|
|||
using_datapack = false;
|
||||
}
|
||||
|
||||
|
||||
GlobalConfig::~GlobalConfig() {
|
||||
|
||||
singleton = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -30,30 +30,30 @@
|
|||
#define GLOBAL_CONFIG_H
|
||||
|
||||
#include "object.h"
|
||||
#include "set.h"
|
||||
#include "os/thread_safe.h"
|
||||
#include "set.h"
|
||||
/**
|
||||
@author Juan Linietsky <reduzio@gmail.com>
|
||||
*/
|
||||
|
||||
|
||||
class GlobalConfig : public Object {
|
||||
|
||||
GDCLASS(GlobalConfig, Object);
|
||||
_THREAD_SAFE_CLASS_
|
||||
|
||||
public:
|
||||
|
||||
typedef Map<String, Variant> CustomMap;
|
||||
|
||||
struct Singleton {
|
||||
StringName name;
|
||||
Object *ptr;
|
||||
Singleton(const StringName& p_name=StringName(), Object *p_ptr=NULL) { name=p_name; ptr=p_ptr; }
|
||||
Singleton(const StringName &p_name = StringName(), Object *p_ptr = NULL) {
|
||||
name = p_name;
|
||||
ptr = p_ptr;
|
||||
}
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
enum {
|
||||
NO_ORDER_BASE = 1 << 18
|
||||
};
|
||||
|
@ -65,8 +65,19 @@ protected:
|
|||
Variant initial;
|
||||
bool hide_from_editor;
|
||||
bool overrided;
|
||||
VariantContainer(){ order=0; hide_from_editor=false; persist=false; overrided=false; }
|
||||
VariantContainer(const Variant& p_variant, int p_order, bool p_persist=false) { variant=p_variant; order=p_order; hide_from_editor=false; persist=p_persist; overrided=false; }
|
||||
VariantContainer() {
|
||||
order = 0;
|
||||
hide_from_editor = false;
|
||||
persist = false;
|
||||
overrided = false;
|
||||
}
|
||||
VariantContainer(const Variant &p_variant, int p_order, bool p_persist = false) {
|
||||
variant = p_variant;
|
||||
order = p_order;
|
||||
hide_from_editor = false;
|
||||
persist = p_persist;
|
||||
overrided = false;
|
||||
}
|
||||
};
|
||||
|
||||
bool registering_order;
|
||||
|
@ -78,7 +89,6 @@ protected:
|
|||
bool using_datapack;
|
||||
List<String> input_presets;
|
||||
|
||||
|
||||
bool _set(const StringName &p_name, const Variant &p_value);
|
||||
bool _get(const StringName &p_name, Variant &r_ret) const;
|
||||
void _get_property_list(List<PropertyInfo> *p_list) const;
|
||||
|
@ -101,16 +111,13 @@ protected:
|
|||
void _add_property_info_bind(const Dictionary &p_info);
|
||||
|
||||
protected:
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
|
||||
|
||||
bool has(String p_var) const;
|
||||
String localize_path(const String &p_path) const;
|
||||
String globalize_path(const String &p_path) const;
|
||||
|
||||
|
||||
void set_initial_value(const String &p_name, const Variant &p_value);
|
||||
bool property_can_revert(const String &p_name);
|
||||
Variant property_get_revert(const String &p_name);
|
||||
|
@ -149,7 +156,6 @@ public:
|
|||
|
||||
GlobalConfig();
|
||||
~GlobalConfig();
|
||||
|
||||
};
|
||||
|
||||
//not a macro any longer
|
||||
|
|
|
@ -28,9 +28,9 @@
|
|||
/*************************************************************************/
|
||||
#include "global_constants.h"
|
||||
|
||||
#include "variant.h"
|
||||
#include "os/keyboard.h"
|
||||
#include "object.h"
|
||||
#include "os/keyboard.h"
|
||||
#include "variant.h"
|
||||
|
||||
struct _GlobalConstant {
|
||||
|
||||
|
@ -38,8 +38,8 @@ struct _GlobalConstant {
|
|||
int value;
|
||||
};
|
||||
|
||||
#define BIND_GLOBAL_CONSTANT(m_constant) {#m_constant,m_constant}
|
||||
|
||||
#define BIND_GLOBAL_CONSTANT(m_constant) \
|
||||
{ #m_constant, m_constant }
|
||||
|
||||
static _GlobalConstant _global_constants[] = {
|
||||
|
||||
|
@ -409,7 +409,6 @@ static _GlobalConstant _global_constants[]={
|
|||
BIND_GLOBAL_CONSTANT(JOY_ANALOG_L2),
|
||||
BIND_GLOBAL_CONSTANT(JOY_ANALOG_R2),
|
||||
|
||||
|
||||
// error list
|
||||
|
||||
BIND_GLOBAL_CONSTANT(OK),
|
||||
|
@ -455,7 +454,6 @@ static _GlobalConstant _global_constants[]={
|
|||
BIND_GLOBAL_CONSTANT(ERR_BUG), ///< a bug in the software certainly happened ), due to a double check failing or unexpected behavior.
|
||||
BIND_GLOBAL_CONSTANT(ERR_WTF),
|
||||
|
||||
|
||||
BIND_GLOBAL_CONSTANT(PROPERTY_HINT_NONE),
|
||||
BIND_GLOBAL_CONSTANT(PROPERTY_HINT_RANGE),
|
||||
BIND_GLOBAL_CONSTANT(PROPERTY_HINT_EXP_RANGE),
|
||||
|
@ -480,7 +478,6 @@ static _GlobalConstant _global_constants[]={
|
|||
BIND_GLOBAL_CONSTANT(PROPERTY_HINT_IMAGE_COMPRESS_LOSSY),
|
||||
BIND_GLOBAL_CONSTANT(PROPERTY_HINT_IMAGE_COMPRESS_LOSSLESS),
|
||||
|
||||
|
||||
BIND_GLOBAL_CONSTANT(PROPERTY_USAGE_STORAGE),
|
||||
BIND_GLOBAL_CONSTANT(PROPERTY_USAGE_EDITOR),
|
||||
BIND_GLOBAL_CONSTANT(PROPERTY_USAGE_NETWORK),
|
||||
|
@ -550,7 +547,6 @@ int GlobalConstants::get_global_constant_count() {
|
|||
while (_global_constants[i].name)
|
||||
i++;
|
||||
return i;
|
||||
|
||||
}
|
||||
|
||||
const char *GlobalConstants::get_global_constant_name(int p_idx) {
|
||||
|
@ -562,5 +558,3 @@ int GlobalConstants::get_global_constant_value(int p_idx) {
|
|||
|
||||
return _global_constants[p_idx].value;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -29,10 +29,8 @@
|
|||
#ifndef GLOBAL_CONSTANTS_H
|
||||
#define GLOBAL_CONSTANTS_H
|
||||
|
||||
|
||||
class GlobalConstants {
|
||||
public:
|
||||
|
||||
static int get_global_constant_count();
|
||||
static const char *get_global_constant_name(int p_idx);
|
||||
static int get_global_constant_value(int p_idx);
|
||||
|
|
|
@ -29,12 +29,12 @@
|
|||
#ifndef HASH_MAP_H
|
||||
#define HASH_MAP_H
|
||||
|
||||
#include "hashfuncs.h"
|
||||
#include "math_funcs.h"
|
||||
#include "error_macros.h"
|
||||
#include "ustring.h"
|
||||
#include "os/memory.h"
|
||||
#include "hashfuncs.h"
|
||||
#include "list.h"
|
||||
#include "math_funcs.h"
|
||||
#include "os/memory.h"
|
||||
#include "ustring.h"
|
||||
|
||||
struct HashMapHasherDefault {
|
||||
static _FORCE_INLINE_ uint32_t hash(const String &p_string) { return p_string.hash(); }
|
||||
|
@ -89,17 +89,18 @@ struct HashMapComparatorDefault {
|
|||
template <class TKey, class TData, class Hasher = HashMapHasherDefault, class Comparator = HashMapComparatorDefault<TKey>, uint8_t MIN_HASH_TABLE_POWER = 3, uint8_t RELATIONSHIP = 8>
|
||||
class HashMap {
|
||||
public:
|
||||
|
||||
struct Pair {
|
||||
|
||||
TKey key;
|
||||
TData data;
|
||||
|
||||
Pair() {}
|
||||
Pair(const TKey& p_key, const TData& p_data) { key=p_key; data=p_data; }
|
||||
Pair(const TKey &p_key, const TData &p_data) {
|
||||
key = p_key;
|
||||
data = p_data;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
private:
|
||||
struct Entry {
|
||||
|
||||
|
@ -118,7 +119,6 @@ private:
|
|||
|
||||
ERR_FAIL_COND(hash_table);
|
||||
|
||||
|
||||
hash_table = memnew_arr(Entry *, (1 << MIN_HASH_TABLE_POWER));
|
||||
|
||||
hash_table_power = MIN_HASH_TABLE_POWER;
|
||||
|
@ -164,7 +164,6 @@ private:
|
|||
new_hash_table_power = MIN_HASH_TABLE_POWER;
|
||||
}
|
||||
|
||||
|
||||
if (new_hash_table_power == -1)
|
||||
return;
|
||||
|
||||
|
@ -190,14 +189,12 @@ private:
|
|||
se->next = new_hash_table[new_pos];
|
||||
new_hash_table[new_pos] = se;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (hash_table)
|
||||
memdelete_arr(hash_table);
|
||||
hash_table = new_hash_table;
|
||||
hash_table_power = new_hash_table_power;
|
||||
|
||||
}
|
||||
|
||||
/* I want to have only one function.. */
|
||||
|
@ -240,7 +237,6 @@ private:
|
|||
return e;
|
||||
}
|
||||
|
||||
|
||||
void copy_from(const HashMap &p_t) {
|
||||
|
||||
if (&p_t == this)
|
||||
|
@ -273,19 +269,13 @@ private:
|
|||
|
||||
e = e->next;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
public:
|
||||
|
||||
|
||||
void set(const TKey &p_key, const TData &p_data) {
|
||||
|
||||
set(Pair(p_key, p_data));
|
||||
|
||||
}
|
||||
|
||||
void set(const Pair &p_pair) {
|
||||
|
@ -307,10 +297,8 @@ public:
|
|||
}
|
||||
|
||||
e->pair.data = p_pair.data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool has(const TKey &p_key) const {
|
||||
|
||||
return getptr(p_key) != NULL;
|
||||
|
@ -341,7 +329,6 @@ public:
|
|||
* This is mainly used for speed purposes.
|
||||
*/
|
||||
|
||||
|
||||
_FORCE_INLINE_ TData *getptr(const TKey &p_key) {
|
||||
|
||||
if (!hash_table)
|
||||
|
@ -353,7 +340,6 @@ public:
|
|||
return &e->pair.data;
|
||||
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ const TData *getptr(const TKey &p_key) const {
|
||||
|
@ -367,7 +353,6 @@ public:
|
|||
return &e->pair.data;
|
||||
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -427,7 +412,6 @@ public:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Erase an item, return true if erasing was succesful
|
||||
*/
|
||||
|
@ -440,7 +424,6 @@ public:
|
|||
uint32_t hash = Hasher::hash(p_key);
|
||||
uint32_t index = hash & ((1 << hash_table_power) - 1);
|
||||
|
||||
|
||||
Entry *e = hash_table[index];
|
||||
Entry *p = NULL;
|
||||
while (e) {
|
||||
|
@ -470,9 +453,7 @@ public:
|
|||
e = e->next;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
inline const TData &operator[](const TKey &p_key) const { //constref
|
||||
|
@ -497,7 +478,6 @@ public:
|
|||
}
|
||||
|
||||
return e->pair.data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -549,10 +529,8 @@ public:
|
|||
}
|
||||
|
||||
/* nothing found, was at end */
|
||||
|
||||
}
|
||||
|
||||
|
||||
return NULL; /* nothing found */
|
||||
}
|
||||
|
||||
|
@ -588,7 +566,6 @@ public:
|
|||
elements = 0;
|
||||
}
|
||||
|
||||
|
||||
void operator=(const HashMap &p_table) {
|
||||
|
||||
copy_from(p_table);
|
||||
|
@ -634,7 +611,6 @@ public:
|
|||
hash_table_power = 0;
|
||||
|
||||
copy_from(p_table);
|
||||
|
||||
}
|
||||
|
||||
~HashMap() {
|
||||
|
@ -643,6 +619,4 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -29,15 +29,14 @@
|
|||
#ifndef HASHFUNCS_H
|
||||
#define HASHFUNCS_H
|
||||
|
||||
#include "math_funcs.h"
|
||||
#include "math_defs.h"
|
||||
#include "math_funcs.h"
|
||||
#include "typedefs.h"
|
||||
|
||||
/**
|
||||
* Hashing functions
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* DJB2 Hash function
|
||||
* @param C String
|
||||
|
@ -128,13 +127,11 @@ static inline uint32_t make_uint32_t(T p_in) {
|
|||
return _u._u32;
|
||||
}
|
||||
|
||||
|
||||
static inline uint64_t hash_djb2_one_64(uint64_t p_in, uint64_t p_prev = 5381) {
|
||||
|
||||
return ((p_prev << 5) + p_prev) + p_in;
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
static inline uint64_t make_uint64_t(T p_in) {
|
||||
|
||||
|
@ -148,6 +145,4 @@ static inline uint64_t make_uint64_t(T p_in) {
|
|||
return _u._u64;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -31,8 +31,13 @@
|
|||
|
||||
#include "core/helper/math_fieldwise.h"
|
||||
|
||||
#define SETUP_TYPE(m_type) m_type source=p_source; m_type target=p_target;
|
||||
#define TRY_TRANSFER_FIELD(m_name,m_member) if (p_field==m_name) { target.m_member=source.m_member; }
|
||||
#define SETUP_TYPE(m_type) \
|
||||
m_type source = p_source; \
|
||||
m_type target = p_target;
|
||||
#define TRY_TRANSFER_FIELD(m_name, m_member) \
|
||||
if (p_field == m_name) { \
|
||||
target.m_member = source.m_member; \
|
||||
}
|
||||
|
||||
Variant fieldwise_assign(const Variant &p_target, const Variant &p_source, const String &p_field) {
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
class ValueEvaluator : public Object {
|
||||
|
||||
GDCLASS(ValueEvaluator, Object);
|
||||
|
||||
public:
|
||||
virtual double eval(const String &p_text) {
|
||||
return p_text.to_double();
|
||||
|
|
200
core/image.cpp
200
core/image.cpp
|
@ -28,15 +28,14 @@
|
|||
/*************************************************************************/
|
||||
#include "image.h"
|
||||
|
||||
#include "hash_map.h"
|
||||
#include "core/io/image_loader.h"
|
||||
#include "core/os/copymem.h"
|
||||
#include "hash_map.h"
|
||||
#include "hq2x.h"
|
||||
#include "print_string.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
const char *Image::format_names[Image::FORMAT_MAX] = {
|
||||
"Lum8", //luminance
|
||||
"LumAlpha8", //luminance-alpha
|
||||
|
@ -80,10 +79,8 @@ const char* Image::format_names[Image::FORMAT_MAX]={
|
|||
|
||||
SavePNGFunc Image::save_png_func = NULL;
|
||||
|
||||
|
||||
void Image::_put_pixelb(int p_x, int p_y, uint32_t p_pixelsize, uint8_t *p_dst, const uint8_t *p_src) {
|
||||
|
||||
|
||||
uint32_t ofs = (p_y * width + p_x) * p_pixelsize;
|
||||
|
||||
for (uint32_t i = 0; i < p_pixelsize; i++) {
|
||||
|
@ -98,60 +95,73 @@ void Image::_get_pixelb(int p_x,int p_y, uint32_t p_pixelsize,const uint8_t *p_
|
|||
for (uint32_t i = 0; i < p_pixelsize; i++) {
|
||||
p_dst[ofs] = p_src[ofs + i];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
int Image::get_format_pixel_size(Format p_format) {
|
||||
|
||||
switch (p_format) {
|
||||
case FORMAT_L8: return 1; //luminance
|
||||
case FORMAT_LA8: return 2; //luminance-alpha
|
||||
case FORMAT_L8:
|
||||
return 1; //luminance
|
||||
case FORMAT_LA8:
|
||||
return 2; //luminance-alpha
|
||||
case FORMAT_R8: return 1;
|
||||
case FORMAT_RG8: return 2;
|
||||
case FORMAT_RGB8: return 3;
|
||||
case FORMAT_RGBA8: return 4;
|
||||
case FORMAT_RGB565: return 2; //16 bit
|
||||
case FORMAT_RGB565:
|
||||
return 2; //16 bit
|
||||
case FORMAT_RGBA4444: return 2;
|
||||
case FORMAT_RGBA5551: return 2;
|
||||
case FORMAT_RF: return 4; //float
|
||||
case FORMAT_RF:
|
||||
return 4; //float
|
||||
case FORMAT_RGF: return 8;
|
||||
case FORMAT_RGBF: return 12;
|
||||
case FORMAT_RGBAF: return 16;
|
||||
case FORMAT_RH: return 2; //half float
|
||||
case FORMAT_RH:
|
||||
return 2; //half float
|
||||
case FORMAT_RGH: return 4;
|
||||
case FORMAT_RGBH: return 8;
|
||||
case FORMAT_RGBAH: return 12;
|
||||
case FORMAT_DXT1: return 1; //s3tc bc1
|
||||
case FORMAT_DXT3: return 1; //bc2
|
||||
case FORMAT_DXT5: return 1; //bc3
|
||||
case FORMAT_ATI1: return 1; //bc4
|
||||
case FORMAT_ATI2: return 1; //bc5
|
||||
case FORMAT_BPTC_RGBA: return 1; //btpc bc6h
|
||||
case FORMAT_BPTC_RGBF: return 1; //float /
|
||||
case FORMAT_BPTC_RGBFU: return 1; //unsigned float
|
||||
case FORMAT_PVRTC2: return 1; //pvrtc
|
||||
case FORMAT_DXT1:
|
||||
return 1; //s3tc bc1
|
||||
case FORMAT_DXT3:
|
||||
return 1; //bc2
|
||||
case FORMAT_DXT5:
|
||||
return 1; //bc3
|
||||
case FORMAT_ATI1:
|
||||
return 1; //bc4
|
||||
case FORMAT_ATI2:
|
||||
return 1; //bc5
|
||||
case FORMAT_BPTC_RGBA:
|
||||
return 1; //btpc bc6h
|
||||
case FORMAT_BPTC_RGBF:
|
||||
return 1; //float /
|
||||
case FORMAT_BPTC_RGBFU:
|
||||
return 1; //unsigned float
|
||||
case FORMAT_PVRTC2:
|
||||
return 1; //pvrtc
|
||||
case FORMAT_PVRTC2A: return 1;
|
||||
case FORMAT_PVRTC4: return 1;
|
||||
case FORMAT_PVRTC4A: return 1;
|
||||
case FORMAT_ETC: return 1; //etc1
|
||||
case FORMAT_ETC2_R11: return 1; //etc2
|
||||
case FORMAT_ETC2_R11S: return 1; //signed: return 1; NOT srgb.
|
||||
case FORMAT_ETC:
|
||||
return 1; //etc1
|
||||
case FORMAT_ETC2_R11:
|
||||
return 1; //etc2
|
||||
case FORMAT_ETC2_R11S:
|
||||
return 1; //signed: return 1; NOT srgb.
|
||||
case FORMAT_ETC2_RG11: return 1;
|
||||
case FORMAT_ETC2_RG11S: return 1;
|
||||
case FORMAT_ETC2_RGB8: return 1;
|
||||
case FORMAT_ETC2_RGBA8: return 1;
|
||||
case FORMAT_ETC2_RGB8A1: return 1;
|
||||
case FORMAT_MAX: {}
|
||||
|
||||
|
||||
case FORMAT_MAX: {
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Image::get_format_min_pixel_size(Format p_format, int &r_w, int &r_h) {
|
||||
|
||||
|
||||
switch (p_format) {
|
||||
case FORMAT_DXT1: //s3tc bc1
|
||||
case FORMAT_DXT3: //bc2
|
||||
|
@ -204,10 +214,8 @@ void Image::get_format_min_pixel_size(Format p_format,int &r_w, int &r_h) {
|
|||
r_h = 1;
|
||||
} break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
int Image::get_format_pixel_rshift(Format p_format) {
|
||||
|
||||
if (p_format == FORMAT_DXT1 || p_format == FORMAT_ATI1 || p_format == FORMAT_PVRTC4 || p_format == FORMAT_PVRTC4A || p_format == FORMAT_ETC || p_format == FORMAT_ETC2_R11 || p_format == FORMAT_ETC2_R11S || p_format == FORMAT_ETC2_RGB8 || p_format == FORMAT_ETC2_RGB8A1)
|
||||
|
@ -218,7 +226,6 @@ int Image::get_format_pixel_rshift(Format p_format) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void Image::_get_mipmap_offset_and_size(int p_mipmap, int &r_offset, int &r_width, int &r_height) const {
|
||||
|
||||
int w = width;
|
||||
|
@ -260,19 +267,16 @@ void Image::get_mipmap_offset_and_size(int p_mipmap,int &r_ofs, int &r_size) con
|
|||
_get_mipmap_offset_and_size(p_mipmap + 1, ofs2, w, h);
|
||||
r_ofs = ofs;
|
||||
r_size = ofs2 - ofs;
|
||||
|
||||
}
|
||||
|
||||
void Image::get_mipmap_offset_size_and_dimensions(int p_mipmap, int &r_ofs, int &r_size, int &w, int &h) const {
|
||||
|
||||
|
||||
int ofs;
|
||||
_get_mipmap_offset_and_size(p_mipmap, ofs, w, h);
|
||||
int ofs2, w2, h2;
|
||||
_get_mipmap_offset_and_size(p_mipmap + 1, ofs2, w2, h2);
|
||||
r_ofs = ofs;
|
||||
r_size = ofs2 - ofs;
|
||||
|
||||
}
|
||||
|
||||
int Image::get_width() const {
|
||||
|
@ -298,13 +302,10 @@ int Image::get_mipmap_count() const {
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//using template generates perfectly optimized code due to constant expression reduction and unused variable removal present in all compilers
|
||||
template <uint32_t read_bytes, bool read_alpha, uint32_t write_bytes, bool write_alpha, bool read_gray, bool write_gray>
|
||||
static void _convert(int p_width, int p_height, const uint8_t *p_src, uint8_t *p_dst) {
|
||||
|
||||
|
||||
|
||||
for (int y = 0; y < p_height; y++) {
|
||||
for (int x = 0; x < p_width; x++) {
|
||||
|
||||
|
@ -341,10 +342,8 @@ static void _convert( int p_width,int p_height,const uint8_t* p_src,uint8_t* p_d
|
|||
if (write_alpha) {
|
||||
wofs[write_bytes] = rgba[3];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Image::convert(Format p_new_format) {
|
||||
|
@ -355,14 +354,12 @@ void Image::convert( Format p_new_format ){
|
|||
if (p_new_format == format)
|
||||
return;
|
||||
|
||||
|
||||
if (format >= FORMAT_RGB565 || p_new_format >= FORMAT_RGB565) {
|
||||
|
||||
ERR_EXPLAIN("Cannot convert to <-> from non byte formats.");
|
||||
ERR_FAIL();
|
||||
}
|
||||
|
||||
|
||||
Image new_img(width, height, 0, p_new_format);
|
||||
|
||||
//int len=data.size();
|
||||
|
@ -407,10 +404,8 @@ void Image::convert( Format p_new_format ){
|
|||
case FORMAT_RGBA8 | (FORMAT_R8 << 8): _convert<3, true, 1, false, false, false>(width, height, rptr, wptr); break;
|
||||
case FORMAT_RGBA8 | (FORMAT_RG8 << 8): _convert<3, true, 2, false, false, false>(width, height, rptr, wptr); break;
|
||||
case FORMAT_RGBA8 | (FORMAT_RGB8 << 8): _convert<3, true, 3, false, false, false>(width, height, rptr, wptr); break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
r = PoolVector<uint8_t>::Read();
|
||||
w = PoolVector<uint8_t>::Write();
|
||||
|
||||
|
@ -422,7 +417,6 @@ void Image::convert( Format p_new_format ){
|
|||
|
||||
if (gen_mipmaps)
|
||||
generate_mipmaps();
|
||||
|
||||
}
|
||||
|
||||
Image::Format Image::get_format() const {
|
||||
|
@ -441,14 +435,12 @@ static double _bicubic_interp_kernel( double x ) {
|
|||
else if (x < 2)
|
||||
bc = ((-0.5 * x + 2.5) * x - 4) * x + 2;
|
||||
|
||||
|
||||
return bc;
|
||||
}
|
||||
|
||||
template <int CC>
|
||||
static void _scale_cubic(const uint8_t *p_src, uint8_t *p_dst, uint32_t p_src_width, uint32_t p_src_height, uint32_t p_dst_width, uint32_t p_dst_height) {
|
||||
|
||||
|
||||
// get source image size
|
||||
int width = p_src_width;
|
||||
int height = p_src_height;
|
||||
|
@ -484,8 +476,6 @@ static void _scale_cubic(const uint8_t* p_src, uint8_t* p_dst, uint32_t p_src_wi
|
|||
color[i] = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
for (int n = -1; n < 3; n++) {
|
||||
// get Y cooefficient
|
||||
k1 = _bicubic_interp_kernel(dy - (double)n);
|
||||
|
@ -523,9 +513,6 @@ static void _scale_cubic(const uint8_t* p_src, uint8_t* p_dst, uint32_t p_src_wi
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template <int CC>
|
||||
static void _scale_bilinear(const uint8_t *p_src, uint8_t *p_dst, uint32_t p_src_width, uint32_t p_src_height, uint32_t p_dst_width, uint32_t p_dst_height) {
|
||||
|
||||
|
@ -542,7 +529,6 @@ static void _scale_bilinear(const uint8_t* p_src, uint8_t* p_dst, uint32_t p_src
|
|||
uint32_t src_yofs_frac = src_yofs_up_fp & FRAC_MASK;
|
||||
uint32_t src_yofs_up = src_yofs_up_fp >> FRAC_BITS;
|
||||
|
||||
|
||||
uint32_t src_yofs_down = (i + 1) * p_src_height / p_dst_height;
|
||||
if (src_yofs_down >= p_src_height)
|
||||
src_yofs_down = p_src_height - 1;
|
||||
|
@ -582,11 +568,9 @@ static void _scale_bilinear(const uint8_t* p_src, uint8_t* p_dst, uint32_t p_src
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
template <int CC>
|
||||
static void _scale_nearest(const uint8_t *p_src, uint8_t *p_dst, uint32_t p_src_width, uint32_t p_src_height, uint32_t p_dst_width, uint32_t p_dst_height) {
|
||||
|
||||
|
||||
for (uint32_t i = 0; i < p_dst_height; i++) {
|
||||
|
||||
uint32_t src_yofs = i * p_src_height / p_dst_height;
|
||||
|
@ -606,7 +590,6 @@ static void _scale_nearest(const uint8_t* p_src, uint8_t* p_dst, uint32_t p_src_
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void Image::resize_to_po2(bool p_square) {
|
||||
|
||||
if (!_can_modify(format)) {
|
||||
|
@ -634,7 +617,6 @@ Image Image::resized( int p_width, int p_height, int p_interpolation ) {
|
|||
return ret;
|
||||
};
|
||||
|
||||
|
||||
void Image::resize(int p_width, int p_height, Interpolation p_interpolation) {
|
||||
|
||||
if (!_can_modify(format)) {
|
||||
|
@ -647,7 +629,6 @@ void Image::resize( int p_width, int p_height, Interpolation p_interpolation ) {
|
|||
ERR_FAIL_COND(p_width > MAX_WIDTH);
|
||||
ERR_FAIL_COND(p_height > MAX_HEIGHT);
|
||||
|
||||
|
||||
if (p_width == width && p_height == height)
|
||||
return;
|
||||
|
||||
|
@ -659,7 +640,6 @@ void Image::resize( int p_width, int p_height, Interpolation p_interpolation ) {
|
|||
PoolVector<uint8_t>::Write w = dst.data.write();
|
||||
unsigned char *w_ptr = w.ptr();
|
||||
|
||||
|
||||
switch (p_interpolation) {
|
||||
|
||||
case INTERPOLATE_NEAREST: {
|
||||
|
@ -691,8 +671,6 @@ void Image::resize( int p_width, int p_height, Interpolation p_interpolation ) {
|
|||
}
|
||||
|
||||
} break;
|
||||
|
||||
|
||||
}
|
||||
|
||||
r = PoolVector<uint8_t>::Read();
|
||||
|
@ -741,17 +719,14 @@ void Image::crop( int p_width, int p_height ) {
|
|||
_get_pixelb(x, y, pixel_size, r.ptr(), pdata);
|
||||
}
|
||||
|
||||
|
||||
dst._put_pixelb(x, y, pixel_size, w.ptr(), pdata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (mipmaps > 0)
|
||||
dst.generate_mipmaps();
|
||||
*this = dst;
|
||||
|
||||
}
|
||||
|
||||
void Image::flip_y() {
|
||||
|
@ -766,8 +741,6 @@ void Image::flip_y() {
|
|||
if (gm)
|
||||
clear_mipmaps();
|
||||
|
||||
|
||||
|
||||
{
|
||||
PoolVector<uint8_t>::Write w = data.write();
|
||||
uint8_t up[16];
|
||||
|
@ -778,21 +751,17 @@ void Image::flip_y() {
|
|||
|
||||
for (int x = 0; x < width; x++) {
|
||||
|
||||
|
||||
_get_pixelb(x, y, pixel_size, w.ptr(), up);
|
||||
_get_pixelb(x, height - y - 1, pixel_size, w.ptr(), down);
|
||||
|
||||
_put_pixelb(x, height - y - 1, pixel_size, w.ptr(), up);
|
||||
_put_pixelb(x, y, pixel_size, w.ptr(), down);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (gm)
|
||||
generate_mipmaps();
|
||||
|
||||
}
|
||||
|
||||
void Image::flip_x() {
|
||||
|
@ -806,7 +775,6 @@ void Image::flip_x() {
|
|||
if (gm)
|
||||
clear_mipmaps();
|
||||
|
||||
|
||||
{
|
||||
PoolVector<uint8_t>::Write w = data.write();
|
||||
uint8_t up[16];
|
||||
|
@ -817,20 +785,17 @@ void Image::flip_x() {
|
|||
|
||||
for (int x = 0; x < width; x++) {
|
||||
|
||||
|
||||
_get_pixelb(x, y, pixel_size, w.ptr(), up);
|
||||
_get_pixelb(width - x - 1, y, pixel_size, w.ptr(), down);
|
||||
|
||||
_put_pixelb(width - x - 1, y, pixel_size, w.ptr(), up);
|
||||
_put_pixelb(x, y, pixel_size, w.ptr(), down);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (gm)
|
||||
generate_mipmaps();
|
||||
|
||||
}
|
||||
|
||||
int Image::_get_dst_image_size(int p_width, int p_height, Format p_format, int &r_mipmaps, int p_mipmaps) {
|
||||
|
@ -892,7 +857,6 @@ static void _generate_po2_mipmap(const uint8_t* p_src, uint8_t* p_dst, uint32_t
|
|||
uint8_t *dst_ptr = &p_dst[i * dst_w * CC];
|
||||
uint32_t count = dst_w;
|
||||
|
||||
|
||||
while (count--) {
|
||||
|
||||
for (int j = 0; j < CC; j++) {
|
||||
|
@ -903,7 +867,6 @@ static void _generate_po2_mipmap(const uint8_t* p_src, uint8_t* p_dst, uint32_t
|
|||
val += rdown_ptr[j];
|
||||
val += rdown_ptr[j + CC];
|
||||
dst_ptr[j] = val >> 2;
|
||||
|
||||
}
|
||||
|
||||
dst_ptr += CC;
|
||||
|
@ -913,7 +876,6 @@ static void _generate_po2_mipmap(const uint8_t* p_src, uint8_t* p_dst, uint32_t
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void Image::expand_x2_hq2x() {
|
||||
|
||||
ERR_FAIL_COND(!_can_modify(format));
|
||||
|
@ -935,29 +897,24 @@ void Image::expand_x2_hq2x() {
|
|||
PoolVector<uint8_t>::Write w = dest.write();
|
||||
|
||||
hq2x_resize((const uint32_t *)r.ptr(), width, height, (uint32_t *)w.ptr());
|
||||
|
||||
}
|
||||
|
||||
width *= 2;
|
||||
height *= 2;
|
||||
data = dest;
|
||||
|
||||
|
||||
if (current != FORMAT_RGBA8)
|
||||
convert(current);
|
||||
|
||||
if (mipmaps) {
|
||||
generate_mipmaps();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Image::shrink_x2() {
|
||||
|
||||
ERR_FAIL_COND(data.size() == 0);
|
||||
|
||||
|
||||
|
||||
if (mipmaps) {
|
||||
|
||||
//just use the lower mipmap as base and copy all
|
||||
|
@ -968,7 +925,6 @@ void Image::shrink_x2() {
|
|||
int new_size = data.size() - ofs;
|
||||
new_img.resize(new_size);
|
||||
|
||||
|
||||
{
|
||||
PoolVector<uint8_t>::Write w = new_img.write();
|
||||
PoolVector<uint8_t>::Read r = data.read();
|
||||
|
@ -1007,7 +963,6 @@ void Image::shrink_x2() {
|
|||
width /= 2;
|
||||
height /= 2;
|
||||
data = new_img;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1016,7 +971,6 @@ Error Image::generate_mipmaps() {
|
|||
if (!_can_modify(format)) {
|
||||
ERR_EXPLAIN("Cannot generate mipmaps in indexed, compressed or custom image formats.");
|
||||
ERR_FAIL_V(ERR_UNAVAILABLE);
|
||||
|
||||
}
|
||||
|
||||
ERR_FAIL_COND_V(width == 0 || height == 0, ERR_UNCONFIGURED);
|
||||
|
@ -1038,11 +992,9 @@ Error Image::generate_mipmaps() {
|
|||
|
||||
for (int i = 1; i < mmcount; i++) {
|
||||
|
||||
|
||||
int ofs, w, h;
|
||||
_get_mipmap_offset_and_size(i, ofs, w, h);
|
||||
|
||||
|
||||
switch (format) {
|
||||
|
||||
case FORMAT_L8:
|
||||
|
@ -1059,7 +1011,6 @@ Error Image::generate_mipmaps() {
|
|||
prev_h = h;
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
//use slow code..
|
||||
|
||||
|
@ -1070,7 +1021,6 @@ Error Image::generate_mipmaps() {
|
|||
|
||||
for (int i = 1; i < mmcount; i++) {
|
||||
|
||||
|
||||
int ofs, w, h;
|
||||
_get_mipmap_offset_and_size(i, ofs, w, h);
|
||||
|
||||
|
@ -1089,9 +1039,6 @@ Error Image::generate_mipmaps() {
|
|||
prev_w = w;
|
||||
prev_h = h;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
mipmaps = true;
|
||||
|
@ -1112,10 +1059,8 @@ void Image::clear_mipmaps() {
|
|||
data.resize(ofs);
|
||||
|
||||
mipmaps = false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool Image::empty() const {
|
||||
|
||||
return (data.size() == 0);
|
||||
|
@ -1128,7 +1073,6 @@ PoolVector<uint8_t> Image::get_data() const {
|
|||
|
||||
void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_format) {
|
||||
|
||||
|
||||
int mm = 0;
|
||||
int size = _get_dst_image_size(p_width, p_height, p_format, mm, p_use_mipmaps ? -1 : 0);
|
||||
data.resize(size);
|
||||
|
@ -1141,8 +1085,6 @@ void Image::create(int p_width, int p_height, bool p_use_mipmaps,Format p_format
|
|||
height = p_height;
|
||||
mipmaps = p_use_mipmaps;
|
||||
format = p_format;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const PoolVector<uint8_t> &p_data) {
|
||||
|
@ -1165,10 +1107,8 @@ void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_forma
|
|||
mipmaps = p_use_mipmaps;
|
||||
}
|
||||
|
||||
|
||||
void Image::create(const char **p_xpm) {
|
||||
|
||||
|
||||
int size_width, size_height;
|
||||
int pixelchars = 0;
|
||||
mipmaps = false;
|
||||
|
@ -1193,7 +1133,6 @@ void Image::create( const char ** p_xpm ) {
|
|||
|
||||
const char *line_ptr = p_xpm[line];
|
||||
|
||||
|
||||
switch (status) {
|
||||
|
||||
case READING_HEADER: {
|
||||
|
@ -1262,7 +1201,6 @@ void Image::create( const char ** p_xpm ) {
|
|||
case 4: col_b = v << 4; break;
|
||||
case 5: col_b |= v; break;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
// magenta mask
|
||||
|
@ -1274,7 +1212,6 @@ void Image::create( const char ** p_xpm ) {
|
|||
|
||||
colormap[colorstring] = Color(col_r / 255.0, col_g / 255.0, col_b / 255.0, 1.0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (line == colormap_size) {
|
||||
|
@ -1301,7 +1238,6 @@ void Image::create( const char ** p_xpm ) {
|
|||
pixel[i] = CLAMP((*colorptr)[i] * 255, 0, 255);
|
||||
}
|
||||
_put_pixelb(x, y, pixel_size, w.ptr(), pixel);
|
||||
|
||||
}
|
||||
|
||||
if (y == (size_height - 1))
|
||||
|
@ -1338,7 +1274,6 @@ void Image::create( const char ** p_xpm ) {
|
|||
} \
|
||||
}
|
||||
|
||||
|
||||
bool Image::is_invisible() const {
|
||||
|
||||
if (format == FORMAT_L8 ||
|
||||
|
@ -1350,7 +1285,6 @@ bool Image::is_invisible() const {
|
|||
if (len == 0)
|
||||
return true;
|
||||
|
||||
|
||||
int w, h;
|
||||
_get_mipmap_offset_and_size(1, len, w, h);
|
||||
|
||||
|
@ -1363,7 +1297,6 @@ bool Image::is_invisible() const {
|
|||
|
||||
case FORMAT_LA8: {
|
||||
|
||||
|
||||
for (int i = 0; i < (len >> 1); i++) {
|
||||
DETECT_NON_ALPHA(data_ptr[(i << 1) + 1]);
|
||||
}
|
||||
|
@ -1391,7 +1324,6 @@ bool Image::is_invisible() const {
|
|||
|
||||
Image::AlphaMode Image::detect_alpha() const {
|
||||
|
||||
|
||||
int len = data.size();
|
||||
|
||||
if (len == 0)
|
||||
|
@ -1410,7 +1342,6 @@ Image::AlphaMode Image::detect_alpha() const {
|
|||
|
||||
case FORMAT_LA8: {
|
||||
|
||||
|
||||
for (int i = 0; i < (len >> 1); i++) {
|
||||
DETECT_ALPHA(data_ptr[(i << 1) + 1]);
|
||||
}
|
||||
|
@ -1438,7 +1369,6 @@ Image::AlphaMode Image::detect_alpha() const {
|
|||
return ALPHA_BIT;
|
||||
else
|
||||
return ALPHA_NONE;
|
||||
|
||||
}
|
||||
|
||||
Error Image::load(const String &p_path) {
|
||||
|
@ -1464,14 +1394,10 @@ bool Image::operator==(const Image& p_image) const {
|
|||
return r.ptr() == pr.ptr();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int Image::get_image_data_size(int p_width, int p_height, Format p_format, int p_mipmaps) {
|
||||
|
||||
int mm;
|
||||
return _get_dst_image_size(p_width, p_height, p_format, mm, p_mipmaps);
|
||||
|
||||
}
|
||||
|
||||
int Image::get_image_required_mipmaps(int p_width, int p_height, Format p_format) {
|
||||
|
@ -1479,16 +1405,10 @@ int Image::get_image_required_mipmaps(int p_width, int p_height, Format p_format
|
|||
int mm;
|
||||
_get_dst_image_size(p_width, p_height, p_format, mm, -1);
|
||||
return mm;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Error Image::_decompress_bc() {
|
||||
|
||||
|
||||
int wd = width, ht = height;
|
||||
if (wd % 4 != 0) {
|
||||
wd += 4 - (wd % 4);
|
||||
|
@ -1497,7 +1417,6 @@ Error Image::_decompress_bc() {
|
|||
ht += 4 - (ht % 4);
|
||||
}
|
||||
|
||||
|
||||
int mm;
|
||||
int size = _get_dst_image_size(wd, ht, FORMAT_RGBA8, mm);
|
||||
|
||||
|
@ -1530,7 +1449,6 @@ Error Image::_decompress_bc() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
for (int j = 0; j < len; j++) {
|
||||
|
||||
const uint8_t *src = &r[rofs + j * 8];
|
||||
|
@ -1584,13 +1502,11 @@ Error Image::_decompress_bc() {
|
|||
dst[idx + 3] = table[block & 0x3][3];
|
||||
block >>= 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
rofs += len * 8;
|
||||
wofs += wd * ht * 4;
|
||||
|
||||
|
||||
wd /= 2;
|
||||
ht /= 2;
|
||||
|
||||
|
@ -1609,7 +1525,6 @@ Error Image::_decompress_bc() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
for (int j = 0; j < len; j++) {
|
||||
|
||||
const uint8_t *src = &r[rofs + j * 16];
|
||||
|
@ -1630,7 +1545,6 @@ Error Image::_decompress_bc() {
|
|||
ablock <<= 8;
|
||||
ablock |= src[6];
|
||||
|
||||
|
||||
uint16_t col_a = src[8 + 1];
|
||||
col_a <<= 8;
|
||||
col_a |= src[8 + 0];
|
||||
|
@ -1677,13 +1591,11 @@ Error Image::_decompress_bc() {
|
|||
block >>= 2;
|
||||
ablock >>= 4;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
rofs += len * 16;
|
||||
wofs += wd * ht * 4;
|
||||
|
||||
|
||||
wd /= 2;
|
||||
ht /= 2;
|
||||
|
||||
|
@ -1702,8 +1614,6 @@ Error Image::_decompress_bc() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
for (int j = 0; j < len; j++) {
|
||||
|
||||
const uint8_t *src = &r[rofs + j * 16];
|
||||
|
@ -1745,10 +1655,8 @@ Error Image::_decompress_bc() {
|
|||
atable[5] = (int(a_start) * 0 + int(a_end) * 5) / 5;
|
||||
atable[6] = 0;
|
||||
atable[7] = 255;
|
||||
|
||||
}
|
||||
|
||||
|
||||
uint16_t col_a = src[8 + 1];
|
||||
col_a <<= 8;
|
||||
col_a |= src[8 + 0];
|
||||
|
@ -1772,7 +1680,6 @@ Error Image::_decompress_bc() {
|
|||
table[3][1] = (int(table[0][1]) + int(table[1][1]) * 2) / 3;
|
||||
table[3][2] = (int(table[0][2]) + int(table[1][2]) * 2) / 3;
|
||||
|
||||
|
||||
uint32_t block = src[4 + 8];
|
||||
block <<= 8;
|
||||
block |= src[5 + 8];
|
||||
|
@ -1785,8 +1692,6 @@ Error Image::_decompress_bc() {
|
|||
int x = (j % (wd / 4)) * 4;
|
||||
int pixofs = (y * wd + x) * 4;
|
||||
|
||||
|
||||
|
||||
for (int k = 0; k < 16; k++) {
|
||||
uint8_t alpha = ablock & 0x7;
|
||||
int idx = pixofs + ofs_table[k];
|
||||
|
@ -1797,20 +1702,17 @@ Error Image::_decompress_bc() {
|
|||
block >>= 2;
|
||||
ablock >>= 3;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
rofs += len * 16;
|
||||
wofs += wd * ht * 4;
|
||||
|
||||
|
||||
wd /= 2;
|
||||
ht /= 2;
|
||||
|
||||
} break;
|
||||
default: {}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
w = PoolVector<uint8_t>::Write();
|
||||
|
@ -1832,7 +1734,6 @@ bool Image::is_compressed() const {
|
|||
return format >= FORMAT_RGB565;
|
||||
}
|
||||
|
||||
|
||||
Image Image::decompressed() const {
|
||||
|
||||
Image img = *this;
|
||||
|
@ -1855,7 +1756,6 @@ Error Image::decompress() {
|
|||
return OK;
|
||||
}
|
||||
|
||||
|
||||
Error Image::compress(CompressMode p_mode) {
|
||||
|
||||
switch (p_mode) {
|
||||
|
@ -1892,7 +1792,6 @@ Error Image::compress(CompressMode p_mode) {
|
|||
} break;
|
||||
}
|
||||
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
@ -1914,7 +1813,6 @@ Image::Image(const char **p_xpm) {
|
|||
create(p_xpm);
|
||||
}
|
||||
|
||||
|
||||
Image::Image(int p_width, int p_height, bool p_use_mipmaps, Format p_format) {
|
||||
|
||||
width = 0;
|
||||
|
@ -1923,7 +1821,6 @@ Image::Image(int p_width, int p_height,bool p_use_mipmaps, Format p_format) {
|
|||
format = FORMAT_L8;
|
||||
|
||||
create(p_width, p_height, p_use_mipmaps, p_format);
|
||||
|
||||
}
|
||||
|
||||
Image::Image(int p_width, int p_height, bool p_mipmaps, Format p_format, const PoolVector<uint8_t> &p_data) {
|
||||
|
@ -1934,10 +1831,8 @@ Image::Image(int p_width, int p_height, bool p_mipmaps, Format p_format, const P
|
|||
format = FORMAT_L8;
|
||||
|
||||
create(p_width, p_height, p_mipmaps, p_format, p_data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Rect2 Image::get_used_rect() const {
|
||||
|
||||
if (format != FORMAT_LA8 && format != FORMAT_RGBA8)
|
||||
|
@ -1958,7 +1853,6 @@ Rect2 Image::get_used_rect() const {
|
|||
for (int j = 0; j < height; j++) {
|
||||
for (int i = 0; i < width; i++) {
|
||||
|
||||
|
||||
bool opaque = rptr[(j * width + i) * ps + (ps - 1)] > 2;
|
||||
if (!opaque)
|
||||
continue;
|
||||
|
@ -1977,10 +1871,8 @@ Rect2 Image::get_used_rect() const {
|
|||
return Rect2();
|
||||
else
|
||||
return Rect2(minx, miny, maxx - minx + 1, maxy - miny + 1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Image Image::get_rect(const Rect2 &p_area) const {
|
||||
|
||||
Image img(p_area.size.x, p_area.size.y, mipmaps, format);
|
||||
|
@ -1997,7 +1889,6 @@ void Image::blit_rect(const Image& p_src, const Rect2& p_src_rect,const Point2&
|
|||
ERR_FAIL_COND(srcdsize == 0);
|
||||
ERR_FAIL_COND(format != p_src.format);
|
||||
|
||||
|
||||
Rect2i local_src_rect = Rect2i(0, 0, width, height).clip(Rect2i(p_dest + p_src_rect.pos, p_src_rect.size));
|
||||
|
||||
if (local_src_rect.size.x <= 0 || local_src_rect.size.y <= 0)
|
||||
|
@ -2014,7 +1905,6 @@ void Image::blit_rect(const Image& p_src, const Rect2& p_src_rect,const Point2&
|
|||
|
||||
for (int i = 0; i < src_rect.size.y; i++) {
|
||||
|
||||
|
||||
for (int j = 0; j < src_rect.size.x; j++) {
|
||||
|
||||
int src_x = src_rect.pos.x + j;
|
||||
|
@ -2031,10 +1921,8 @@ void Image::blit_rect(const Image& p_src, const Rect2& p_src_rect,const Point2&
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Image (*Image::_png_mem_loader_func)(const uint8_t *, int) = NULL;
|
||||
Image (*Image::_jpg_mem_loader_func)(const uint8_t *, int) = NULL;
|
||||
|
||||
|
@ -2058,8 +1946,6 @@ void Image::set_compress_bc_func(void (*p_compress_func)(Image *)) {
|
|||
_image_compress_bc_func = p_compress_func;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Image::normalmap_to_xy() {
|
||||
|
||||
convert(Image::FORMAT_RGBA8);
|
||||
|
@ -2087,7 +1973,6 @@ void Image::srgb_to_linear() {
|
|||
|
||||
static const uint8_t srgb2lin[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 22, 22, 23, 23, 24, 24, 25, 26, 26, 27, 27, 28, 29, 29, 30, 31, 31, 32, 33, 33, 34, 35, 36, 36, 37, 38, 38, 39, 40, 41, 42, 42, 43, 44, 45, 46, 47, 47, 48, 49, 50, 51, 52, 53, 54, 55, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 70, 71, 72, 73, 74, 75, 76, 77, 78, 80, 81, 82, 83, 84, 85, 87, 88, 89, 90, 92, 93, 94, 95, 97, 98, 99, 101, 102, 103, 105, 106, 107, 109, 110, 112, 113, 114, 116, 117, 119, 120, 122, 123, 125, 126, 128, 129, 131, 132, 134, 135, 137, 139, 140, 142, 144, 145, 147, 148, 150, 152, 153, 155, 157, 159, 160, 162, 164, 166, 167, 169, 171, 173, 175, 176, 178, 180, 182, 184, 186, 188, 190, 192, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 218, 220, 222, 224, 226, 228, 230, 232, 235, 237, 239, 241, 243, 245, 248, 250, 252 };
|
||||
|
||||
|
||||
ERR_FAIL_COND(format != FORMAT_RGB8 && format != FORMAT_RGBA8);
|
||||
|
||||
if (format == FORMAT_RGBA8) {
|
||||
|
@ -2116,7 +2001,6 @@ void Image::srgb_to_linear() {
|
|||
data_ptr[(i * 3) + 2] = srgb2lin[data_ptr[(i * 3) + 2]];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Image::premultiply_alpha() {
|
||||
|
@ -2130,7 +2014,6 @@ void Image::premultiply_alpha() {
|
|||
PoolVector<uint8_t>::Write wp = data.write();
|
||||
unsigned char *data_ptr = wp.ptr();
|
||||
|
||||
|
||||
for (int i = 0; i < height; i++) {
|
||||
for (int j = 0; j < width; j++) {
|
||||
|
||||
|
@ -2174,7 +2057,6 @@ void Image::fix_alpha_edges() {
|
|||
int closest_dist = max_dist;
|
||||
uint8_t closest_color[3];
|
||||
|
||||
|
||||
int from_x = MAX(0, j - max_radius);
|
||||
int to_x = MIN(width - 1, j + max_radius);
|
||||
int from_y = MAX(0, i - max_radius);
|
||||
|
@ -2197,21 +2079,17 @@ void Image::fix_alpha_edges() {
|
|||
closest_color[0] = rp[0];
|
||||
closest_color[1] = rp[1];
|
||||
closest_color[2] = rp[2];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (closest_dist != max_dist) {
|
||||
|
||||
wptr[0] = closest_color[0];
|
||||
wptr[1] = closest_color[1];
|
||||
wptr[2] = closest_color[2];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
String Image::get_format_name(Format p_format) {
|
||||
|
@ -2234,7 +2112,6 @@ Image::Image(const uint8_t* p_mem_png_jpg, int p_len) {
|
|||
if (empty() && _jpg_mem_loader_func) {
|
||||
*this = _jpg_mem_loader_func(p_mem_png_jpg, p_len);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Image::Image() {
|
||||
|
@ -2246,7 +2123,4 @@ Image::Image() {
|
|||
}
|
||||
|
||||
Image::~Image() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
17
core/image.h
17
core/image.h
|
@ -29,8 +29,8 @@
|
|||
#ifndef IMAGE_H
|
||||
#define IMAGE_H
|
||||
|
||||
#include "dvector.h"
|
||||
#include "color.h"
|
||||
#include "dvector.h"
|
||||
#include "math_2d.h"
|
||||
/**
|
||||
* @author Juan Linietsky <reduzio@gmail.com>
|
||||
|
@ -50,8 +50,8 @@ class Image {
|
|||
MAX_WIDTH = 16384, // force a limit somehow
|
||||
MAX_HEIGHT = 16384 // force a limit somehow
|
||||
};
|
||||
public:
|
||||
|
||||
public:
|
||||
static SavePNGFunc save_png_func;
|
||||
|
||||
enum Format {
|
||||
|
@ -127,8 +127,8 @@ public:
|
|||
static Image (*lossy_unpacker)(const PoolVector<uint8_t> &p_buffer);
|
||||
static PoolVector<uint8_t> (*lossless_packer)(const Image &p_image);
|
||||
static Image (*lossless_unpacker)(const PoolVector<uint8_t> &p_buffer);
|
||||
private:
|
||||
|
||||
private:
|
||||
Format format;
|
||||
PoolVector<uint8_t> data;
|
||||
int width, height;
|
||||
|
@ -139,14 +139,10 @@ private:
|
|||
static int _get_dst_image_size(int p_width, int p_height, Format p_format, int &r_mipmaps, int p_mipmaps = -1);
|
||||
bool _can_modify(Format p_format) const;
|
||||
|
||||
|
||||
_FORCE_INLINE_ void _put_pixelb(int p_x, int p_y, uint32_t p_pixelsize, uint8_t *p_dst, const uint8_t *p_src);
|
||||
_FORCE_INLINE_ void _get_pixelb(int p_x, int p_y, uint32_t p_pixelsize, const uint8_t *p_src, uint8_t *p_dst);
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
int get_width() const; ///< Get image width
|
||||
int get_height() const; ///< Get image height
|
||||
bool has_mipmaps() const;
|
||||
|
@ -189,7 +185,6 @@ public:
|
|||
*/
|
||||
void crop(int p_width, int p_height);
|
||||
|
||||
|
||||
void flip_x();
|
||||
void flip_y();
|
||||
|
||||
|
@ -200,8 +195,6 @@ public:
|
|||
|
||||
void clear_mipmaps();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create a new image of a given size and format. Current image will be lost
|
||||
*/
|
||||
|
@ -241,7 +234,6 @@ public:
|
|||
AlphaMode detect_alpha() const;
|
||||
bool is_invisible() const;
|
||||
|
||||
|
||||
static int get_format_pixel_size(Format p_format);
|
||||
static int get_format_pixel_rshift(Format p_format);
|
||||
static void get_format_min_pixel_size(Format p_format, int &r_w, int &r_h);
|
||||
|
@ -249,7 +241,6 @@ public:
|
|||
static int get_image_data_size(int p_width, int p_height, Format p_format, int p_mipmaps = 0);
|
||||
static int get_image_required_mipmaps(int p_width, int p_height, Format p_format);
|
||||
|
||||
|
||||
bool operator==(const Image &p_image) const;
|
||||
|
||||
enum CompressMode {
|
||||
|
@ -283,8 +274,6 @@ public:
|
|||
Image(const uint8_t *p_mem_png_jpg, int p_len = -1);
|
||||
Image(const char **p_xpm);
|
||||
~Image();
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -48,10 +48,8 @@ void InputMap::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("get_action_list", "action"), &InputMap::_get_action_list);
|
||||
ClassDB::bind_method(D_METHOD("event_is_action", "event", "action"), &InputMap::event_is_action);
|
||||
ClassDB::bind_method(D_METHOD("load_from_globals"), &InputMap::load_from_globals);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void InputMap::add_action(const StringName &p_action) {
|
||||
|
||||
ERR_FAIL_COND(input_map.has(p_action));
|
||||
|
@ -60,8 +58,6 @@ void InputMap::add_action(const StringName& p_action) {
|
|||
input_map[p_action].id = last_id;
|
||||
input_id_map[last_id] = p_action;
|
||||
last_id++;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void InputMap::erase_action(const StringName &p_action) {
|
||||
|
@ -69,7 +65,6 @@ void InputMap::erase_action(const StringName& p_action) {
|
|||
ERR_FAIL_COND(!input_map.has(p_action));
|
||||
input_id_map.erase(input_map[p_action].id);
|
||||
input_map.erase(p_action);
|
||||
|
||||
}
|
||||
|
||||
StringName InputMap::get_action_from_id(int p_id) const {
|
||||
|
@ -153,11 +148,9 @@ List<InputEvent>::Element *InputMap::_find_event(List<InputEvent> &p_list,const
|
|||
return E;
|
||||
}
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
bool InputMap::has_action(const StringName &p_action) const {
|
||||
|
||||
return input_map.has(p_action);
|
||||
|
@ -171,10 +164,8 @@ void InputMap::action_add_event(const StringName& p_action,const InputEvent& p_e
|
|||
return; //already gots
|
||||
|
||||
input_map[p_action].inputs.push_back(p_event);
|
||||
|
||||
}
|
||||
|
||||
|
||||
int InputMap::get_action_id(const StringName &p_action) const {
|
||||
|
||||
ERR_FAIL_COND_V(!input_map.has(p_action), -1);
|
||||
|
@ -185,7 +176,6 @@ bool InputMap::action_has_event(const StringName& p_action,const InputEvent& p_e
|
|||
|
||||
ERR_FAIL_COND_V(!input_map.has(p_action), false);
|
||||
return (_find_event(input_map[p_action].inputs, p_event) != NULL);
|
||||
|
||||
}
|
||||
|
||||
void InputMap::action_erase_event(const StringName &p_action, const InputEvent &p_event) {
|
||||
|
@ -197,7 +187,6 @@ void InputMap::action_erase_event(const StringName& p_action,const InputEvent& p
|
|||
input_map[p_action].inputs.erase(E);
|
||||
}
|
||||
|
||||
|
||||
Array InputMap::_get_action_list(const StringName &p_action) {
|
||||
|
||||
Array ret;
|
||||
|
@ -210,7 +199,6 @@ Array InputMap::_get_action_list(const StringName& p_action) {
|
|||
}
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
const List<InputEvent> *InputMap::get_action_list(const StringName &p_action) {
|
||||
|
@ -224,7 +212,6 @@ const List<InputEvent> *InputMap::get_action_list(const StringName& p_action) {
|
|||
|
||||
bool InputMap::event_is_action(const InputEvent &p_event, const StringName &p_action) const {
|
||||
|
||||
|
||||
Map<StringName, Action>::Element *E = input_map.find(p_action);
|
||||
if (!E) {
|
||||
ERR_EXPLAIN("Request for nonexistent InputMap action: " + String(p_action));
|
||||
|
@ -268,11 +255,8 @@ void InputMap::load_from_globals() {
|
|||
if (ie.type == InputEvent::NONE)
|
||||
continue;
|
||||
action_add_event(name, ie);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void InputMap::load_default() {
|
||||
|
@ -322,7 +306,6 @@ void InputMap::load_default() {
|
|||
key.key.scancode = KEY_DOWN;
|
||||
action_add_event("ui_down", key);
|
||||
|
||||
|
||||
add_action("ui_page_up");
|
||||
key.key.scancode = KEY_PAGEUP;
|
||||
action_add_event("ui_page_up", key);
|
||||
|
@ -332,8 +315,6 @@ void InputMap::load_default() {
|
|||
action_add_event("ui_page_down", key);
|
||||
|
||||
//set("display/handheld/orientation", "landscape");
|
||||
|
||||
|
||||
}
|
||||
|
||||
InputMap::InputMap() {
|
||||
|
|
|
@ -29,17 +29,18 @@
|
|||
#ifndef INPUT_MAP_H
|
||||
#define INPUT_MAP_H
|
||||
|
||||
|
||||
#include "object.h"
|
||||
|
||||
class InputMap : public Object {
|
||||
|
||||
GDCLASS(InputMap, Object);
|
||||
|
||||
public:
|
||||
struct Action {
|
||||
int id;
|
||||
List<InputEvent> inputs;
|
||||
};
|
||||
|
||||
private:
|
||||
static InputMap *singleton;
|
||||
|
||||
|
@ -52,13 +53,11 @@ private:
|
|||
Array _get_actions();
|
||||
|
||||
protected:
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
|
||||
static _FORCE_INLINE_ InputMap *get_singleton() { return singleton; }
|
||||
|
||||
|
||||
bool has_action(const StringName &p_action) const;
|
||||
int get_action_id(const StringName &p_action) const;
|
||||
StringName get_action_from_id(int p_id) const;
|
||||
|
|
|
@ -26,9 +26,9 @@
|
|||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "zlib.h"
|
||||
#include "os/copymem.h"
|
||||
#include "compression.h"
|
||||
#include "os/copymem.h"
|
||||
#include "zlib.h"
|
||||
|
||||
#include "fastlz.h"
|
||||
#include "zip_io.h"
|
||||
|
@ -83,7 +83,6 @@ int Compression::get_max_compressed_buffer_size(int p_src_size,Mode p_mode){
|
|||
switch (p_mode) {
|
||||
case MODE_FASTLZ: {
|
||||
|
||||
|
||||
int ss = p_src_size + p_src_size * 6 / 100;
|
||||
if (ss < 66)
|
||||
ss = 66;
|
||||
|
@ -106,11 +105,8 @@ int Compression::get_max_compressed_buffer_size(int p_src_size,Mode p_mode){
|
|||
}
|
||||
|
||||
ERR_FAIL_V(-1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int Compression::decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p_src, int p_src_size, Mode p_mode) {
|
||||
|
||||
switch (p_mode) {
|
||||
|
|
|
@ -31,16 +31,13 @@
|
|||
|
||||
#include "typedefs.h"
|
||||
|
||||
class Compression
|
||||
{
|
||||
class Compression {
|
||||
public:
|
||||
|
||||
enum Mode {
|
||||
MODE_FASTLZ,
|
||||
MODE_DEFLATE
|
||||
};
|
||||
|
||||
|
||||
static int compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size, Mode p_mode = MODE_FASTLZ);
|
||||
static int get_max_compressed_buffer_size(int p_src_size, Mode p_mode = MODE_FASTLZ);
|
||||
static int decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p_src, int p_src_size, Mode p_mode = MODE_FASTLZ);
|
||||
|
@ -48,6 +45,4 @@ public:
|
|||
Compression();
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // COMPRESSION_H
|
||||
|
|
|
@ -27,8 +27,8 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "config_file.h"
|
||||
#include "os/keyboard.h"
|
||||
#include "os/file_access.h"
|
||||
#include "os/keyboard.h"
|
||||
#include "variant_parser.h"
|
||||
|
||||
PoolStringArray ConfigFile::_get_sections() const {
|
||||
|
@ -59,10 +59,8 @@ PoolStringArray ConfigFile::_get_section_keys(const String& p_section) const{
|
|||
}
|
||||
|
||||
return arr;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ConfigFile::set_value(const String &p_section, const String &p_key, const Variant &p_value) {
|
||||
|
||||
if (p_value.get_type() == Variant::NIL) {
|
||||
|
@ -80,16 +78,13 @@ void ConfigFile::set_value(const String& p_section, const String& p_key, const V
|
|||
}
|
||||
|
||||
values[p_section][p_key] = p_value;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Variant ConfigFile::get_value(const String &p_section, const String &p_key, Variant p_default) const {
|
||||
|
||||
ERR_FAIL_COND_V(!values.has(p_section), p_default);
|
||||
ERR_FAIL_COND_V(!values[p_section].has(p_key), p_default);
|
||||
return values[p_section][p_key];
|
||||
|
||||
}
|
||||
|
||||
bool ConfigFile::has_section(const String &p_section) const {
|
||||
|
@ -116,7 +111,6 @@ void ConfigFile::get_section_keys(const String& p_section,List<String> *r_keys)
|
|||
for (const Map<String, Variant>::Element *E = values[p_section].front(); E; E = E->next()) {
|
||||
r_keys->push_back(E->key());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ConfigFile::erase_section(const String &p_section) {
|
||||
|
@ -135,7 +129,6 @@ Error ConfigFile::save(const String& p_path){
|
|||
return err;
|
||||
}
|
||||
|
||||
|
||||
for (Map<String, Map<String, Variant> >::Element *E = values.front(); E; E = E->next()) {
|
||||
|
||||
if (E != values.front())
|
||||
|
@ -155,7 +148,6 @@ Error ConfigFile::save(const String& p_path){
|
|||
return OK;
|
||||
}
|
||||
|
||||
|
||||
Error ConfigFile::load(const String &p_path) {
|
||||
|
||||
Error err;
|
||||
|
@ -186,8 +178,7 @@ Error ConfigFile::load(const String& p_path) {
|
|||
if (err == ERR_FILE_EOF) {
|
||||
memdelete(f);
|
||||
return OK;
|
||||
}
|
||||
else if (err!=OK) {
|
||||
} else if (err != OK) {
|
||||
ERR_PRINTS("ConfgFile::load - " + p_path + ":" + itos(lines) + " error: " + error_text);
|
||||
memdelete(f);
|
||||
return err;
|
||||
|
@ -205,8 +196,6 @@ Error ConfigFile::load(const String& p_path) {
|
|||
return OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ConfigFile::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_value", "section", "key", "value"), &ConfigFile::set_value);
|
||||
|
@ -222,10 +211,7 @@ void ConfigFile::_bind_methods(){
|
|||
|
||||
ClassDB::bind_method(D_METHOD("load:Error", "path"), &ConfigFile::load);
|
||||
ClassDB::bind_method(D_METHOD("save:Error", "path"), &ConfigFile::save);
|
||||
|
||||
}
|
||||
|
||||
|
||||
ConfigFile::ConfigFile()
|
||||
{
|
||||
ConfigFile::ConfigFile() {
|
||||
}
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
|
||||
#include "reference.h"
|
||||
|
||||
|
||||
class ConfigFile : public Reference {
|
||||
|
||||
GDCLASS(ConfigFile, Reference);
|
||||
|
@ -40,11 +39,11 @@ class ConfigFile : public Reference {
|
|||
|
||||
PoolStringArray _get_sections() const;
|
||||
PoolStringArray _get_section_keys(const String &p_section) const;
|
||||
|
||||
protected:
|
||||
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
||||
public:
|
||||
void set_value(const String &p_section, const String &p_key, const Variant &p_value);
|
||||
Variant get_value(const String &p_section, const String &p_key, Variant p_default = Variant()) const;
|
||||
|
||||
|
|
|
@ -135,7 +135,6 @@ int FileAccessBuffered::get_buffer(uint8_t *p_dest,int p_elements) const {
|
|||
return total_read;
|
||||
};
|
||||
|
||||
|
||||
int to_read = p_elements;
|
||||
int total_read = 0;
|
||||
while (to_read > 0) {
|
||||
|
@ -180,5 +179,4 @@ FileAccessBuffered::FileAccessBuffered() {
|
|||
};
|
||||
|
||||
FileAccessBuffered::~FileAccessBuffered() {
|
||||
|
||||
}
|
||||
|
|
|
@ -42,14 +42,12 @@ public:
|
|||
};
|
||||
|
||||
private:
|
||||
|
||||
int cache_size;
|
||||
|
||||
int cache_data_left() const;
|
||||
mutable Error last_error;
|
||||
|
||||
protected:
|
||||
|
||||
Error set_error(Error p_error) const;
|
||||
|
||||
mutable struct File {
|
||||
|
@ -73,7 +71,6 @@ protected:
|
|||
int get_cache_size();
|
||||
|
||||
public:
|
||||
|
||||
virtual size_t get_pos() const; ///< get position in the file
|
||||
virtual size_t get_len() const; ///< get size of the file
|
||||
|
||||
|
@ -94,4 +91,3 @@ public:
|
|||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -75,8 +75,6 @@ protected:
|
|||
};
|
||||
|
||||
public:
|
||||
|
||||
|
||||
void store_8(uint8_t p_dest) {
|
||||
|
||||
f.store_8(p_dest);
|
||||
|
@ -140,9 +138,7 @@ public:
|
|||
|
||||
FileAccessBufferedFA(){
|
||||
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
#endif // FILE_ACCESS_BUFFERED_FA_H
|
||||
|
|
|
@ -40,10 +40,8 @@ void FileAccessCompressed::configure(const String& p_magic, Compression::Mode p_
|
|||
|
||||
cmode = p_mode;
|
||||
block_size = p_block_size;
|
||||
|
||||
}
|
||||
|
||||
|
||||
#define WRITE_FIT(m_bytes) \
|
||||
{ \
|
||||
if (write_pos + (m_bytes) > write_max) { \
|
||||
|
@ -56,10 +54,8 @@ if (write_max > write_buffer_size) {\
|
|||
} \
|
||||
}
|
||||
|
||||
|
||||
Error FileAccessCompressed::open_after_magic(FileAccess *p_base) {
|
||||
|
||||
|
||||
f = p_base;
|
||||
cmode = (Compression::Mode)f->get_32();
|
||||
block_size = f->get_32();
|
||||
|
@ -75,8 +71,6 @@ Error FileAccessCompressed::open_after_magic(FileAccess *p_base) {
|
|||
acc_ofs += rb.csize;
|
||||
max_bs = MAX(max_bs, rb.csize);
|
||||
read_blocks.push_back(rb);
|
||||
|
||||
|
||||
}
|
||||
|
||||
comp_buffer.resize(max_bs);
|
||||
|
@ -93,7 +87,6 @@ Error FileAccessCompressed::open_after_magic(FileAccess *p_base) {
|
|||
read_pos = 0;
|
||||
|
||||
return OK;
|
||||
|
||||
}
|
||||
|
||||
Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) {
|
||||
|
@ -103,7 +96,6 @@ Error FileAccessCompressed::_open(const String& p_path, int p_mode_flags){
|
|||
if (f)
|
||||
close();
|
||||
|
||||
|
||||
Error err;
|
||||
f = FileAccess::open(p_path, p_mode_flags, &err);
|
||||
if (err != OK) {
|
||||
|
@ -123,8 +115,6 @@ Error FileAccessCompressed::_open(const String& p_path, int p_mode_flags){
|
|||
write_max = 0;
|
||||
write_ptr = buffer.ptr();
|
||||
|
||||
|
||||
|
||||
//don't store anything else unless it's done saving!
|
||||
} else {
|
||||
|
||||
|
@ -138,18 +128,15 @@ Error FileAccessCompressed::_open(const String& p_path, int p_mode_flags){
|
|||
}
|
||||
|
||||
open_after_magic(f);
|
||||
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
||||
}
|
||||
void FileAccessCompressed::close() {
|
||||
|
||||
if (!f)
|
||||
return;
|
||||
|
||||
|
||||
if (writing) {
|
||||
//save block table and all compressed blocks
|
||||
|
||||
|
@ -164,7 +151,6 @@ void FileAccessCompressed::close(){
|
|||
f->store_32(0); //compressed sizes, will update later
|
||||
}
|
||||
|
||||
|
||||
Vector<int> block_sizes;
|
||||
for (int i = 0; i < bc; i++) {
|
||||
|
||||
|
@ -189,7 +175,6 @@ void FileAccessCompressed::close(){
|
|||
|
||||
} else {
|
||||
|
||||
|
||||
comp_buffer.clear();
|
||||
buffer.clear();
|
||||
read_blocks.clear();
|
||||
|
@ -197,7 +182,6 @@ void FileAccessCompressed::close(){
|
|||
|
||||
memdelete(f);
|
||||
f = NULL;
|
||||
|
||||
}
|
||||
|
||||
bool FileAccessCompressed::is_open() const {
|
||||
|
@ -236,7 +220,6 @@ void FileAccessCompressed::seek(size_t p_position){
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void FileAccessCompressed::seek_end(int64_t p_position) {
|
||||
|
||||
ERR_FAIL_COND(!f);
|
||||
|
@ -246,10 +229,7 @@ void FileAccessCompressed::seek_end(int64_t p_position){
|
|||
} else {
|
||||
|
||||
seek(read_total + p_position);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
size_t FileAccessCompressed::get_pos() const {
|
||||
|
||||
|
@ -261,7 +241,6 @@ size_t FileAccessCompressed::get_pos() const{
|
|||
|
||||
return read_block * block_size + read_pos;
|
||||
}
|
||||
|
||||
}
|
||||
size_t FileAccessCompressed::get_len() const {
|
||||
|
||||
|
@ -315,7 +294,6 @@ uint8_t FileAccessCompressed::get_8() const{
|
|||
}
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
int FileAccessCompressed::get_buffer(uint8_t *p_dst, int p_length) const {
|
||||
|
||||
|
@ -327,10 +305,8 @@ int FileAccessCompressed::get_buffer(uint8_t *p_dst, int p_length) const{
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < p_length; i++) {
|
||||
|
||||
|
||||
p_dst[i] = read_ptr[read_pos];
|
||||
read_pos++;
|
||||
if (read_pos >= read_block_size) {
|
||||
|
@ -349,14 +325,11 @@ int FileAccessCompressed::get_buffer(uint8_t *p_dst, int p_length) const{
|
|||
if (i < p_length - 1)
|
||||
read_eof = true;
|
||||
return i;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return p_length;
|
||||
|
||||
}
|
||||
|
||||
Error FileAccessCompressed::get_error() const {
|
||||
|
@ -371,7 +344,6 @@ void FileAccessCompressed::store_8(uint8_t p_dest){
|
|||
|
||||
WRITE_FIT(1);
|
||||
write_ptr[write_pos++] = p_dest;
|
||||
|
||||
}
|
||||
|
||||
bool FileAccessCompressed::file_exists(const String &p_name) {
|
||||
|
@ -410,12 +382,10 @@ FileAccessCompressed::FileAccessCompressed() {
|
|||
read_block_count = 0;
|
||||
read_block_size = 0;
|
||||
read_pos = 0;
|
||||
|
||||
}
|
||||
|
||||
FileAccessCompressed::~FileAccessCompressed() {
|
||||
|
||||
if (f)
|
||||
close();
|
||||
|
||||
}
|
||||
|
|
|
@ -58,14 +58,11 @@ class FileAccessCompressed : public FileAccess {
|
|||
Vector<ReadBlock> read_blocks;
|
||||
int read_total;
|
||||
|
||||
|
||||
|
||||
|
||||
String magic;
|
||||
mutable Vector<uint8_t> buffer;
|
||||
FileAccess *f;
|
||||
public:
|
||||
|
||||
public:
|
||||
void configure(const String &p_magic, Compression::Mode p_mode = Compression::MODE_FASTLZ, int p_block_size = 4096);
|
||||
|
||||
Error open_after_magic(FileAccess *p_base);
|
||||
|
@ -92,10 +89,8 @@ public:
|
|||
|
||||
virtual uint64_t _get_modified_time(const String &p_file);
|
||||
|
||||
|
||||
FileAccessCompressed();
|
||||
virtual ~FileAccessCompressed();
|
||||
|
||||
};
|
||||
|
||||
#endif // FILE_ACCESS_COMPRESSED_H
|
||||
|
|
|
@ -96,10 +96,8 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base,const Vector<uint8_
|
|||
MD5Update(&md5, data.ptr(), data.size());
|
||||
MD5Final(&md5);
|
||||
|
||||
|
||||
ERR_FAIL_COND_V(String::md5(md5.digest) != String::md5(md5d), ERR_FILE_CORRUPT);
|
||||
|
||||
|
||||
file = p_base;
|
||||
}
|
||||
|
||||
|
@ -108,7 +106,6 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base,const Vector<uint8_
|
|||
|
||||
Error FileAccessEncrypted::open_and_parse_password(FileAccess *p_base, const String &p_key, Mode p_mode) {
|
||||
|
||||
|
||||
String cs = p_key.md5_text();
|
||||
ERR_FAIL_COND_V(cs.length() != 32, ERR_INVALID_PARAMETER);
|
||||
Vector<uint8_t> key;
|
||||
|
@ -121,8 +118,6 @@ Error FileAccessEncrypted::open_and_parse_password(FileAccess *p_base,const Stri
|
|||
return open_and_parse(p_base, key, p_mode);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Error FileAccessEncrypted::_open(const String &p_path, int p_mode_flags) {
|
||||
|
||||
return OK;
|
||||
|
@ -164,7 +159,6 @@ void FileAccessEncrypted::close() {
|
|||
file->store_32(COMP_MAGIC);
|
||||
file->store_32(mode);
|
||||
|
||||
|
||||
file->store_buffer(md5.digest, 16);
|
||||
file->store_64(data.size());
|
||||
|
||||
|
@ -181,9 +175,6 @@ void FileAccessEncrypted::close() {
|
|||
data.clear();
|
||||
file = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool FileAccessEncrypted::is_open() const {
|
||||
|
@ -198,10 +189,8 @@ void FileAccessEncrypted::seek(size_t p_position){
|
|||
|
||||
pos = p_position;
|
||||
eofed = false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void FileAccessEncrypted::seek_end(int64_t p_position) {
|
||||
|
||||
seek(data.size() + p_position);
|
||||
|
@ -231,7 +220,6 @@ uint8_t FileAccessEncrypted::get_8() const{
|
|||
uint8_t b = data[pos];
|
||||
pos++;
|
||||
return b;
|
||||
|
||||
}
|
||||
int FileAccessEncrypted::get_buffer(uint8_t *p_dst, int p_length) const {
|
||||
|
||||
|
@ -247,7 +235,6 @@ int FileAccessEncrypted::get_buffer(uint8_t *p_dst, int p_length) const{
|
|||
eofed = true;
|
||||
}
|
||||
|
||||
|
||||
return to_copy;
|
||||
}
|
||||
|
||||
|
@ -277,7 +264,6 @@ void FileAccessEncrypted::store_buffer(const uint8_t *p_src,int p_length) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void FileAccessEncrypted::store_8(uint8_t p_dest) {
|
||||
|
||||
ERR_FAIL_COND(!writing);
|
||||
|
@ -302,7 +288,6 @@ bool FileAccessEncrypted::file_exists(const String& p_name){
|
|||
|
||||
uint64_t FileAccessEncrypted::_get_modified_time(const String &p_file) {
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -315,7 +300,6 @@ FileAccessEncrypted::FileAccessEncrypted() {
|
|||
writing = false;
|
||||
}
|
||||
|
||||
|
||||
FileAccessEncrypted::~FileAccessEncrypted() {
|
||||
|
||||
if (file)
|
||||
|
|
|
@ -29,12 +29,10 @@
|
|||
#ifndef FILE_ACCESS_ENCRYPTED_H
|
||||
#define FILE_ACCESS_ENCRYPTED_H
|
||||
|
||||
|
||||
#include "os/file_access.h"
|
||||
|
||||
class FileAccessEncrypted : public FileAccess {
|
||||
public:
|
||||
|
||||
enum Mode {
|
||||
MODE_READ,
|
||||
MODE_WRITE_AES256,
|
||||
|
@ -42,8 +40,6 @@ public:
|
|||
};
|
||||
|
||||
private:
|
||||
|
||||
|
||||
Mode mode;
|
||||
Vector<uint8_t> key;
|
||||
bool writing;
|
||||
|
@ -54,12 +50,7 @@ private:
|
|||
mutable size_t pos;
|
||||
mutable bool eofed;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
Error open_and_parse(FileAccess *p_base, const Vector<uint8_t> &p_key, Mode p_mode);
|
||||
Error open_and_parse_password(FileAccess *p_base, const String &p_key, Mode p_mode);
|
||||
|
||||
|
|
|
@ -28,10 +28,10 @@
|
|||
/*************************************************************************/
|
||||
#include "file_access_memory.h"
|
||||
|
||||
#include "os/dir_access.h"
|
||||
#include "os/copymem.h"
|
||||
#include "global_config.h"
|
||||
#include "map.h"
|
||||
#include "os/copymem.h"
|
||||
#include "os/dir_access.h"
|
||||
|
||||
static Map<String, Vector<uint8_t> > *files = NULL;
|
||||
|
||||
|
@ -59,7 +59,6 @@ void FileAccessMemory::cleanup() {
|
|||
memdelete(files);
|
||||
}
|
||||
|
||||
|
||||
FileAccess *FileAccessMemory::create() {
|
||||
|
||||
return memnew(FileAccessMemory);
|
||||
|
@ -73,7 +72,6 @@ bool FileAccessMemory::file_exists(const String& p_name) {
|
|||
return files && (files->find(name) != NULL);
|
||||
}
|
||||
|
||||
|
||||
Error FileAccessMemory::open_custom(const uint8_t *p_data, int p_len) {
|
||||
|
||||
data = (uint8_t *)p_data;
|
||||
|
|
|
@ -40,7 +40,6 @@ class FileAccessMemory : public FileAccess {
|
|||
static FileAccess *create();
|
||||
|
||||
public:
|
||||
|
||||
static void register_file(String p_name, Vector<uint8_t> p_data);
|
||||
static void cleanup();
|
||||
|
||||
|
@ -69,8 +68,6 @@ public:
|
|||
|
||||
virtual uint64_t _get_modified_time(const String &p_file) { return 0; }
|
||||
|
||||
|
||||
|
||||
FileAccessMemory();
|
||||
};
|
||||
|
||||
|
|
|
@ -27,19 +27,16 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "file_access_network.h"
|
||||
#include "marshalls.h"
|
||||
#include "global_config.h"
|
||||
#include "os/os.h"
|
||||
#include "io/ip.h"
|
||||
|
||||
|
||||
#include "marshalls.h"
|
||||
#include "os/os.h"
|
||||
|
||||
//#define DEBUG_PRINT(m_p) print_line(m_p)
|
||||
//#define DEBUG_TIME(m_what) printf("MS: %s - %lli\n",m_what,OS::get_singleton()->get_ticks_usec());
|
||||
#define DEBUG_PRINT(m_p)
|
||||
#define DEBUG_TIME(m_what)
|
||||
|
||||
|
||||
void FileAccessNetworkClient::lock_mutex() {
|
||||
|
||||
mutex->lock();
|
||||
|
@ -50,7 +47,6 @@ void FileAccessNetworkClient::unlock_mutex() {
|
|||
|
||||
lockcount--;
|
||||
mutex->unlock();
|
||||
|
||||
}
|
||||
|
||||
void FileAccessNetworkClient::put_32(int p_32) {
|
||||
|
@ -67,7 +63,6 @@ void FileAccessNetworkClient::put_64(int64_t p_64) {
|
|||
encode_uint64(p_64, buf);
|
||||
client->put_data(buf, 8);
|
||||
DEBUG_PRINT("put64: " + itos(p_64));
|
||||
|
||||
}
|
||||
|
||||
int FileAccessNetworkClient::get_32() {
|
||||
|
@ -75,7 +70,6 @@ int FileAccessNetworkClient::get_32() {
|
|||
uint8_t buf[4];
|
||||
client->get_data(buf, 4);
|
||||
return decode_uint32(buf);
|
||||
|
||||
}
|
||||
|
||||
int64_t FileAccessNetworkClient::get_64() {
|
||||
|
@ -83,7 +77,6 @@ int64_t FileAccessNetworkClient::get_64() {
|
|||
uint8_t buf[8];
|
||||
client->get_data(buf, 8);
|
||||
return decode_uint64(buf);
|
||||
|
||||
}
|
||||
|
||||
void FileAccessNetworkClient::_thread_func() {
|
||||
|
@ -128,12 +121,10 @@ void FileAccessNetworkClient::_thread_func() {
|
|||
if (accesses.has(id))
|
||||
fa = accesses[id];
|
||||
|
||||
|
||||
switch (response) {
|
||||
|
||||
case FileAccessNetwork::RESPONSE_OPEN: {
|
||||
|
||||
|
||||
DEBUG_TIME("sem_open");
|
||||
int status = get_32();
|
||||
if (status != OK) {
|
||||
|
@ -145,7 +136,6 @@ void FileAccessNetworkClient::_thread_func() {
|
|||
|
||||
fa->sem->post();
|
||||
|
||||
|
||||
} break;
|
||||
case FileAccessNetwork::RESPONSE_DATA: {
|
||||
|
||||
|
@ -162,29 +152,22 @@ void FileAccessNetworkClient::_thread_func() {
|
|||
} break;
|
||||
case FileAccessNetwork::RESPONSE_FILE_EXISTS: {
|
||||
|
||||
|
||||
int status = get_32();
|
||||
fa->exists_modtime = status != 0;
|
||||
fa->sem->post();
|
||||
|
||||
|
||||
|
||||
} break;
|
||||
case FileAccessNetwork::RESPONSE_GET_MODTIME: {
|
||||
|
||||
|
||||
uint64_t status = get_64();
|
||||
fa->exists_modtime = status;
|
||||
fa->sem->post();
|
||||
|
||||
} break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
unlock_mutex();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void FileAccessNetworkClient::_thread_func(void *s) {
|
||||
|
@ -192,7 +175,6 @@ void FileAccessNetworkClient::_thread_func(void *s) {
|
|||
FileAccessNetworkClient *self = (FileAccessNetworkClient *)s;
|
||||
|
||||
self->_thread_func();
|
||||
|
||||
}
|
||||
|
||||
Error FileAccessNetworkClient::connect(const String &p_host, int p_port, const String &p_password) {
|
||||
|
@ -234,7 +216,6 @@ Error FileAccessNetworkClient::connect(const String& p_host,int p_port,const Str
|
|||
|
||||
FileAccessNetworkClient *FileAccessNetworkClient::singleton = NULL;
|
||||
|
||||
|
||||
FileAccessNetworkClient::FileAccessNetworkClient() {
|
||||
|
||||
thread = NULL;
|
||||
|
@ -260,13 +241,10 @@ FileAccessNetworkClient::~FileAccessNetworkClient() {
|
|||
memdelete(blockrequest_mutex);
|
||||
memdelete(mutex);
|
||||
memdelete(sem);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void FileAccessNetwork::_set_block(size_t p_offset, const Vector<uint8_t> &p_block) {
|
||||
|
||||
|
||||
int page = p_offset / page_size;
|
||||
ERR_FAIL_INDEX(page, pages.size());
|
||||
if (page < pages.size() - 1) {
|
||||
|
@ -286,7 +264,6 @@ void FileAccessNetwork::_set_block(size_t p_offset,const Vector<uint8_t>& p_bloc
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void FileAccessNetwork::_respond(size_t p_len, Error p_status) {
|
||||
|
||||
DEBUG_PRINT("GOT RESPONSE - len: " + itos(p_len) + " status: " + itos(p_status));
|
||||
|
@ -297,10 +274,6 @@ void FileAccessNetwork::_respond(size_t p_len,Error p_status) {
|
|||
total_size = p_len;
|
||||
int pc = ((total_size - 1) / page_size) + 1;
|
||||
pages.resize(pc);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Error FileAccessNetwork::_open(const String &p_path, int p_mode_flags) {
|
||||
|
@ -352,8 +325,6 @@ void FileAccessNetwork::close(){
|
|||
pages.clear();
|
||||
opened = false;
|
||||
nc->unlock_mutex();
|
||||
|
||||
|
||||
}
|
||||
bool FileAccessNetwork::is_open() const {
|
||||
|
||||
|
@ -375,7 +346,6 @@ void FileAccessNetwork::seek(size_t p_position){
|
|||
void FileAccessNetwork::seek_end(int64_t p_position) {
|
||||
|
||||
seek(total_size + p_position);
|
||||
|
||||
}
|
||||
size_t FileAccessNetwork::get_pos() const {
|
||||
|
||||
|
@ -399,17 +369,14 @@ uint8_t FileAccessNetwork::get_8() const{
|
|||
uint8_t v;
|
||||
get_buffer(&v, 1);
|
||||
return v;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void FileAccessNetwork::_queue_page(int p_page) const {
|
||||
|
||||
if (p_page >= pages.size())
|
||||
return;
|
||||
if (pages[p_page].buffer.empty() && !pages[p_page].queued) {
|
||||
|
||||
|
||||
FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
|
||||
|
||||
nc->blockrequest_mutex->lock();
|
||||
|
@ -424,7 +391,6 @@ void FileAccessNetwork::_queue_page(int p_page) const {
|
|||
nc->sem->post();
|
||||
DEBUG_PRINT("queued " + itos(p_page));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const {
|
||||
|
@ -507,7 +473,6 @@ bool FileAccessNetwork::file_exists(const String& p_path){
|
|||
sem->wait();
|
||||
|
||||
return exists_modtime != 0;
|
||||
|
||||
}
|
||||
|
||||
uint64_t FileAccessNetwork::_get_modified_time(const String &p_file) {
|
||||
|
@ -525,7 +490,6 @@ uint64_t FileAccessNetwork::_get_modified_time(const String& p_file){
|
|||
sem->wait();
|
||||
|
||||
return exists_modtime;
|
||||
|
||||
}
|
||||
|
||||
void FileAccessNetwork::configure() {
|
||||
|
@ -533,7 +497,6 @@ void FileAccessNetwork::configure() {
|
|||
GLOBAL_DEF("network/remote_fs/page_size", 65536);
|
||||
GLOBAL_DEF("network/remote_fs/page_read_ahead", 4);
|
||||
GLOBAL_DEF("network/remote_fs/max_pages", 20);
|
||||
|
||||
}
|
||||
|
||||
FileAccessNetwork::FileAccessNetwork() {
|
||||
|
@ -555,8 +518,6 @@ FileAccessNetwork::FileAccessNetwork() {
|
|||
last_activity_val = 0;
|
||||
waiting_on_page = -1;
|
||||
last_page = -1;
|
||||
|
||||
|
||||
}
|
||||
|
||||
FileAccessNetwork::~FileAccessNetwork() {
|
||||
|
@ -571,5 +532,4 @@ FileAccessNetwork::~FileAccessNetwork() {
|
|||
id = nc->last_id++;
|
||||
nc->accesses.erase(id);
|
||||
nc->unlock_mutex();
|
||||
|
||||
}
|
||||
|
|
|
@ -29,16 +29,15 @@
|
|||
#ifndef FILE_ACCESS_NETWORK_H
|
||||
#define FILE_ACCESS_NETWORK_H
|
||||
|
||||
#include "io/stream_peer_tcp.h"
|
||||
#include "os/file_access.h"
|
||||
#include "os/semaphore.h"
|
||||
#include "os/thread.h"
|
||||
#include "io/stream_peer_tcp.h"
|
||||
|
||||
class FileAccessNetwork;
|
||||
|
||||
class FileAccessNetworkClient {
|
||||
|
||||
|
||||
struct BlockRequest {
|
||||
|
||||
int id;
|
||||
|
@ -76,14 +75,12 @@ friend class FileAccessNetwork;
|
|||
static FileAccessNetworkClient *singleton;
|
||||
|
||||
public:
|
||||
|
||||
static FileAccessNetworkClient *get_singleton() { return singleton; }
|
||||
|
||||
Error connect(const String &p_host, int p_port, const String &p_password = "");
|
||||
|
||||
FileAccessNetworkClient();
|
||||
~FileAccessNetworkClient();
|
||||
|
||||
};
|
||||
|
||||
class FileAccessNetwork : public FileAccess {
|
||||
|
@ -109,7 +106,10 @@ class FileAccessNetwork : public FileAccess {
|
|||
int activity;
|
||||
bool queued;
|
||||
Vector<uint8_t> buffer;
|
||||
Page() { activity=0; queued=false; }
|
||||
Page() {
|
||||
activity = 0;
|
||||
queued = false;
|
||||
}
|
||||
};
|
||||
|
||||
mutable Vector<Page> pages;
|
||||
|
@ -123,7 +123,6 @@ friend class FileAccessNetworkClient;
|
|||
void _set_block(size_t p_offset, const Vector<uint8_t> &p_block);
|
||||
|
||||
public:
|
||||
|
||||
enum Command {
|
||||
COMMAND_OPEN_FILE,
|
||||
COMMAND_READ_BLOCK,
|
||||
|
@ -139,7 +138,6 @@ public:
|
|||
RESPONSE_GET_MODTIME,
|
||||
};
|
||||
|
||||
|
||||
virtual Error _open(const String &p_path, int p_mode_flags); ///< open a file
|
||||
virtual void close(); ///< close a file
|
||||
virtual bool is_open() const; ///< true when file is open
|
||||
|
|
|
@ -124,7 +124,6 @@ PackedData::~PackedData() {
|
|||
_free_packed_dirs(root);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
bool PackedSourcePCK::try_open_pack(const String &p_path) {
|
||||
|
@ -149,7 +148,6 @@ bool PackedSourcePCK::try_open_pack(const String& p_path) {
|
|||
}
|
||||
f->seek(f->get_pos() - 12);
|
||||
|
||||
|
||||
uint64_t ds = f->get_64();
|
||||
f->seek(f->get_pos() - ds - 8);
|
||||
|
||||
|
@ -159,7 +157,6 @@ bool PackedSourcePCK::try_open_pack(const String& p_path) {
|
|||
memdelete(f);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
uint32_t version = f->get_32();
|
||||
|
@ -207,7 +204,6 @@ FileAccess* PackedSourcePCK::get_file(const String &p_path, PackedData::PackedFi
|
|||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
Error FileAccessPack::_open(const String &p_path, int p_mode_flags) {
|
||||
|
||||
ERR_FAIL_V(ERR_UNAVAILABLE);
|
||||
|
@ -238,7 +234,6 @@ void FileAccessPack::seek(size_t p_position){
|
|||
void FileAccessPack::seek_end(int64_t p_position) {
|
||||
|
||||
seek(pf.size + p_position);
|
||||
|
||||
}
|
||||
size_t FileAccessPack::get_pos() const {
|
||||
|
||||
|
@ -265,7 +260,6 @@ uint8_t FileAccessPack::get_8() const {
|
|||
return f->get_8();
|
||||
}
|
||||
|
||||
|
||||
int FileAccessPack::get_buffer(uint8_t *p_dst, int p_length) const {
|
||||
|
||||
if (eof)
|
||||
|
@ -301,13 +295,11 @@ Error FileAccessPack::get_error() const {
|
|||
void FileAccessPack::store_8(uint8_t p_dest) {
|
||||
|
||||
ERR_FAIL();
|
||||
|
||||
}
|
||||
|
||||
void FileAccessPack::store_buffer(const uint8_t *p_src, int p_length) {
|
||||
|
||||
ERR_FAIL();
|
||||
|
||||
}
|
||||
|
||||
bool FileAccessPack::file_exists(const String &p_name) {
|
||||
|
@ -315,7 +307,6 @@ bool FileAccessPack::file_exists(const String& p_name) {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
FileAccessPack::FileAccessPack(const String &p_path, const PackedData::PackedFile &p_file) {
|
||||
|
||||
pf = p_file;
|
||||
|
@ -334,15 +325,12 @@ FileAccessPack::~FileAccessPack() {
|
|||
memdelete(f);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// DIR ACCESS
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
Error DirAccessPack::list_dir_begin() {
|
||||
|
||||
|
||||
list_dirs.clear();
|
||||
list_files.clear();
|
||||
|
||||
|
@ -447,8 +435,6 @@ Error DirAccessPack::change_dir(String p_dir) {
|
|||
current = pd;
|
||||
|
||||
return OK;
|
||||
|
||||
|
||||
}
|
||||
|
||||
String DirAccessPack::get_current_dir() {
|
||||
|
@ -463,7 +449,6 @@ String DirAccessPack::get_current_dir() {
|
|||
}
|
||||
|
||||
return "res://" + p;
|
||||
|
||||
}
|
||||
|
||||
bool DirAccessPack::file_exists(String p_file) {
|
||||
|
@ -484,12 +469,10 @@ Error DirAccessPack::make_dir(String p_dir){
|
|||
Error DirAccessPack::rename(String p_from, String p_to) {
|
||||
|
||||
return ERR_UNAVAILABLE;
|
||||
|
||||
}
|
||||
Error DirAccessPack::remove(String p_name) {
|
||||
|
||||
return ERR_UNAVAILABLE;
|
||||
|
||||
}
|
||||
|
||||
size_t DirAccessPack::get_space_left() {
|
||||
|
@ -504,8 +487,4 @@ DirAccessPack::DirAccessPack() {
|
|||
}
|
||||
|
||||
DirAccessPack::~DirAccessPack() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -29,10 +29,10 @@
|
|||
#ifndef FILE_ACCESS_PACK_H
|
||||
#define FILE_ACCESS_PACK_H
|
||||
|
||||
#include "os/file_access.h"
|
||||
#include "os/dir_access.h"
|
||||
#include "map.h"
|
||||
#include "list.h"
|
||||
#include "map.h"
|
||||
#include "os/dir_access.h"
|
||||
#include "os/file_access.h"
|
||||
#include "print_string.h"
|
||||
|
||||
class PackSource;
|
||||
|
@ -99,7 +99,6 @@ private:
|
|||
void _free_packed_dirs(PackedDir *p_dir);
|
||||
|
||||
public:
|
||||
|
||||
void add_pack_source(PackSource *p_source);
|
||||
void add_path(const String &pkg_path, const String &path, uint64_t ofs, uint64_t size, const uint8_t *p_md5, PackSource *p_src); // for PackSource
|
||||
|
||||
|
@ -119,7 +118,6 @@ public:
|
|||
class PackSource {
|
||||
|
||||
public:
|
||||
|
||||
virtual bool try_open_pack(const String &p_path) = 0;
|
||||
virtual FileAccess *get_file(const String &p_path, PackedData::PackedFile *p_file) = 0;
|
||||
virtual ~PackSource() {}
|
||||
|
@ -128,12 +126,10 @@ public:
|
|||
class PackedSourcePCK : public PackSource {
|
||||
|
||||
public:
|
||||
|
||||
virtual bool try_open_pack(const String &p_path);
|
||||
virtual FileAccess *get_file(const String &p_path, PackedData::PackedFile *p_file);
|
||||
};
|
||||
|
||||
|
||||
class FileAccessPack : public FileAccess {
|
||||
|
||||
PackedData::PackedFile pf;
|
||||
|
@ -146,8 +142,6 @@ class FileAccessPack : public FileAccess {
|
|||
virtual uint64_t _get_modified_time(const String &p_file) { return 0; }
|
||||
|
||||
public:
|
||||
|
||||
|
||||
virtual void close();
|
||||
virtual bool is_open() const;
|
||||
|
||||
|
@ -160,7 +154,6 @@ public:
|
|||
|
||||
virtual uint8_t get_8() const;
|
||||
|
||||
|
||||
virtual int get_buffer(uint8_t *p_dst, int p_length) const;
|
||||
|
||||
virtual void set_endian_swap(bool p_swap);
|
||||
|
@ -173,12 +166,10 @@ public:
|
|||
|
||||
virtual bool file_exists(const String &p_name);
|
||||
|
||||
|
||||
FileAccessPack(const String &p_path, const PackedData::PackedFile &p_file);
|
||||
~FileAccessPack();
|
||||
};
|
||||
|
||||
|
||||
FileAccess *PackedData::try_open_path(const String &p_path) {
|
||||
|
||||
//print_line("try open path " + p_path);
|
||||
|
@ -197,10 +188,8 @@ bool PackedData::has_path(const String& p_path) {
|
|||
return files.has(PathMD5(p_path.md5_buffer()));
|
||||
}
|
||||
|
||||
|
||||
class DirAccessPack : public DirAccess {
|
||||
|
||||
|
||||
PackedData::PackedDir *current;
|
||||
|
||||
List<String> list_dirs;
|
||||
|
@ -208,7 +197,6 @@ class DirAccessPack : public DirAccess {
|
|||
bool cdir;
|
||||
|
||||
public:
|
||||
|
||||
virtual Error list_dir_begin();
|
||||
virtual String get_next();
|
||||
virtual bool current_is_dir() const;
|
||||
|
@ -221,7 +209,6 @@ public:
|
|||
virtual Error change_dir(String p_dir);
|
||||
virtual String get_current_dir();
|
||||
|
||||
|
||||
virtual bool file_exists(String p_file);
|
||||
virtual bool dir_exists(String p_dir);
|
||||
|
||||
|
@ -234,8 +221,6 @@ public:
|
|||
|
||||
DirAccessPack();
|
||||
~DirAccessPack();
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // FILE_ACCESS_PACK_H
|
||||
|
|
|
@ -30,8 +30,8 @@
|
|||
|
||||
#include "file_access_zip.h"
|
||||
|
||||
#include "core/os/file_access.h"
|
||||
#include "core/os/copymem.h"
|
||||
#include "core/os/file_access.h"
|
||||
|
||||
ZipArchive *ZipArchive::instance = NULL;
|
||||
|
||||
|
@ -47,7 +47,6 @@ static void* godot_open(void* data, const char* p_fname, int mode) {
|
|||
f->open(p_fname, FileAccess::READ);
|
||||
|
||||
return f->is_open() ? data : NULL;
|
||||
|
||||
};
|
||||
|
||||
static uLong godot_read(void *data, void *fdata, void *buf, uLong size) {
|
||||
|
@ -62,7 +61,6 @@ static uLong godot_write(voidpf opaque, voidpf stream, const void* buf, uLong si
|
|||
return 0;
|
||||
};
|
||||
|
||||
|
||||
static long godot_tell(voidpf opaque, voidpf stream) {
|
||||
|
||||
FileAccess *f = (FileAccess *)opaque;
|
||||
|
@ -90,7 +88,6 @@ static long godot_seek(voidpf opaque, voidpf stream, uLong offset, int origin) {
|
|||
return 0;
|
||||
};
|
||||
|
||||
|
||||
static int godot_close(voidpf opaque, voidpf stream) {
|
||||
|
||||
FileAccess *f = (FileAccess *)opaque;
|
||||
|
@ -233,7 +230,6 @@ FileAccess* ZipArchive::get_file(const String& p_path, PackedData::PackedFile* p
|
|||
return memnew(FileAccessZip(p_path, *p_file));
|
||||
};
|
||||
|
||||
|
||||
ZipArchive *ZipArchive::get_singleton() {
|
||||
|
||||
if (instance == NULL) {
|
||||
|
@ -261,7 +257,6 @@ ZipArchive::~ZipArchive() {
|
|||
packages.clear();
|
||||
};
|
||||
|
||||
|
||||
Error FileAccessZip::_open(const String &p_path, int p_mode_flags) {
|
||||
|
||||
close();
|
||||
|
@ -368,7 +363,6 @@ bool FileAccessZip::file_exists(const String& p_name) {
|
|||
return false;
|
||||
};
|
||||
|
||||
|
||||
FileAccessZip::FileAccessZip(const String &p_path, const PackedData::PackedFile &p_file) {
|
||||
|
||||
zfile = NULL;
|
||||
|
|
|
@ -31,15 +31,14 @@
|
|||
#ifndef FILE_ACCESS_Zip_H
|
||||
#define FILE_ACCESS_Zip_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "core/io/file_access_pack.h"
|
||||
#include "unzip.h"
|
||||
#include "map.h"
|
||||
#include "unzip.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
class ZipArchive : public PackSource {
|
||||
|
||||
public:
|
||||
|
||||
struct File {
|
||||
|
||||
int package;
|
||||
|
@ -50,9 +49,7 @@ public:
|
|||
};
|
||||
};
|
||||
|
||||
|
||||
private:
|
||||
|
||||
struct Package {
|
||||
String filename;
|
||||
unzFile zfile;
|
||||
|
@ -66,7 +63,6 @@ private:
|
|||
FileAccess::CreateFunc fa_create_func;
|
||||
|
||||
public:
|
||||
|
||||
void close_handle(unzFile p_file) const;
|
||||
unzFile get_file_handle(String p_file) const;
|
||||
|
||||
|
@ -83,7 +79,6 @@ public:
|
|||
~ZipArchive();
|
||||
};
|
||||
|
||||
|
||||
class FileAccessZip : public FileAccess {
|
||||
|
||||
unzFile zfile;
|
||||
|
@ -94,7 +89,6 @@ class FileAccessZip : public FileAccess {
|
|||
ZipArchive *archive;
|
||||
|
||||
public:
|
||||
|
||||
virtual Error _open(const String &p_path, int p_mode_flags); ///< open a file
|
||||
virtual void close(); ///< close a file
|
||||
virtual bool is_open() const; ///< true when file is open
|
||||
|
|
|
@ -43,13 +43,10 @@ Error HTTPClient::connect_to_host(const String &p_host, int p_port, bool p_ssl,b
|
|||
conn_host = conn_host.replace_first("https://", "");
|
||||
}
|
||||
|
||||
|
||||
ssl = p_ssl;
|
||||
ssl_verify_host = p_verify_host;
|
||||
connection = tcp_connection;
|
||||
|
||||
|
||||
|
||||
if (conn_host.is_valid_ip_address()) {
|
||||
//is ip
|
||||
Error err = tcp_connection->connect_to_host(IP_Address(conn_host), p_port);
|
||||
|
@ -63,7 +60,6 @@ Error HTTPClient::connect_to_host(const String &p_host, int p_port, bool p_ssl,b
|
|||
//is hostname
|
||||
resolving = IP::get_singleton()->resolve_hostname_queue_item(conn_host);
|
||||
status = STATUS_RESOLVING;
|
||||
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
@ -74,7 +70,6 @@ void HTTPClient::set_connection(const Ref<StreamPeer>& p_connection){
|
|||
close();
|
||||
connection = p_connection;
|
||||
status = STATUS_CONNECTED;
|
||||
|
||||
}
|
||||
|
||||
Ref<StreamPeer> HTTPClient::get_connection() const {
|
||||
|
@ -88,7 +83,6 @@ Error HTTPClient::request_raw( Method p_method, const String& p_url, const Vecto
|
|||
ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_INVALID_PARAMETER);
|
||||
ERR_FAIL_COND_V(connection.is_null(), ERR_INVALID_DATA);
|
||||
|
||||
|
||||
static const char *_methods[METHOD_MAX] = {
|
||||
"GET",
|
||||
"HEAD",
|
||||
|
@ -97,7 +91,8 @@ Error HTTPClient::request_raw( Method p_method, const String& p_url, const Vecto
|
|||
"DELETE",
|
||||
"OPTIONS",
|
||||
"TRACE",
|
||||
"CONNECT"};
|
||||
"CONNECT"
|
||||
};
|
||||
|
||||
String request = String(_methods[p_method]) + " " + p_url + " HTTP/1.1\r\n";
|
||||
request += "Host: " + conn_host + ":" + itos(conn_port) + "\r\n";
|
||||
|
@ -143,7 +138,6 @@ Error HTTPClient::request( Method p_method, const String& p_url, const Vector<St
|
|||
ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_INVALID_PARAMETER);
|
||||
ERR_FAIL_COND_V(connection.is_null(), ERR_INVALID_DATA);
|
||||
|
||||
|
||||
static const char *_methods[METHOD_MAX] = {
|
||||
"GET",
|
||||
"HEAD",
|
||||
|
@ -152,7 +146,8 @@ Error HTTPClient::request( Method p_method, const String& p_url, const Vector<St
|
|||
"DELETE",
|
||||
"OPTIONS",
|
||||
"TRACE",
|
||||
"CONNECT"};
|
||||
"CONNECT"
|
||||
};
|
||||
|
||||
String request = String(_methods[p_method]) + " " + p_url + " HTTP/1.1\r\n";
|
||||
request += "Host: " + conn_host + ":" + itos(conn_port) + "\r\n";
|
||||
|
@ -223,7 +218,6 @@ Error HTTPClient::get_response_headers(List<String> *r_response) {
|
|||
return OK;
|
||||
}
|
||||
|
||||
|
||||
void HTTPClient::close() {
|
||||
|
||||
if (tcp_connection->get_status() != StreamPeerTCP::STATUS_NONE)
|
||||
|
@ -235,7 +229,6 @@ void HTTPClient::close(){
|
|||
|
||||
IP::get_singleton()->erase_resolve_item(resolving);
|
||||
resolving = IP::RESOLVER_INVALID_ID;
|
||||
|
||||
}
|
||||
|
||||
response_headers.clear();
|
||||
|
@ -246,18 +239,17 @@ void HTTPClient::close(){
|
|||
response_num = 0;
|
||||
}
|
||||
|
||||
|
||||
Error HTTPClient::poll() {
|
||||
|
||||
switch (status) {
|
||||
|
||||
|
||||
case STATUS_RESOLVING: {
|
||||
ERR_FAIL_COND_V(resolving == IP::RESOLVER_INVALID_ID, ERR_BUG);
|
||||
|
||||
IP::ResolverStatus rstatus = IP::get_singleton()->get_resolve_item_status(resolving);
|
||||
switch (rstatus) {
|
||||
case IP::RESOLVER_STATUS_WAITING: return OK; //still resolving
|
||||
case IP::RESOLVER_STATUS_WAITING:
|
||||
return OK; //still resolving
|
||||
|
||||
case IP::RESOLVER_STATUS_DONE: {
|
||||
|
||||
|
@ -281,7 +273,6 @@ Error HTTPClient::poll(){
|
|||
status = STATUS_CANT_RESOLVE;
|
||||
return ERR_CANT_RESOLVE;
|
||||
} break;
|
||||
|
||||
}
|
||||
} break;
|
||||
case STATUS_CONNECTING: {
|
||||
|
@ -322,7 +313,6 @@ Error HTTPClient::poll(){
|
|||
} break;
|
||||
case STATUS_REQUESTING: {
|
||||
|
||||
|
||||
while (true) {
|
||||
uint8_t byte;
|
||||
int rec = 0;
|
||||
|
@ -340,9 +330,7 @@ Error HTTPClient::poll(){
|
|||
int rs = response_str.size();
|
||||
if (
|
||||
(rs >= 2 && response_str[rs - 2] == '\n' && response_str[rs - 1] == '\n') ||
|
||||
(rs>=4 && response_str[rs-4]=='\r' && response_str[rs-3]=='\n' && response_str[rs-2]=='\r' && response_str[rs-1]=='\n')
|
||||
) {
|
||||
|
||||
(rs >= 4 && response_str[rs - 4] == '\r' && response_str[rs - 3] == '\n' && response_str[rs - 2] == '\r' && response_str[rs - 1] == '\n')) {
|
||||
|
||||
//end of response, parse.
|
||||
response_str.push_back(0);
|
||||
|
@ -375,7 +363,6 @@ Error HTTPClient::poll(){
|
|||
if (encoding == "chunked") {
|
||||
chunked = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (i == 0 && responses[i].begins_with("HTTP")) {
|
||||
|
@ -386,7 +373,6 @@ Error HTTPClient::poll(){
|
|||
|
||||
response_headers.push_back(header);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (body_size == 0 && !chunked) {
|
||||
|
@ -415,11 +401,9 @@ Error HTTPClient::poll(){
|
|||
} break;
|
||||
}
|
||||
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
Dictionary HTTPClient::_get_response_headers_as_dictionary() {
|
||||
|
||||
List<String> rh;
|
||||
|
@ -433,7 +417,6 @@ Dictionary HTTPClient::_get_response_headers_as_dictionary() {
|
|||
String key = s.substr(0, sp).strip_edges();
|
||||
String value = s.substr(sp + 1, s.length()).strip_edges();
|
||||
ret[key] = value;
|
||||
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -509,7 +492,6 @@ PoolByteArray HTTPClient::read_response_body_chunk() {
|
|||
status = STATUS_CONNECTION_ERROR;
|
||||
return PoolByteArray();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (len == 0) {
|
||||
|
@ -521,7 +503,6 @@ PoolByteArray HTTPClient::read_response_body_chunk() {
|
|||
|
||||
chunk_left = len + 2;
|
||||
chunk.resize(chunk_left);
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
|
@ -549,7 +530,6 @@ PoolByteArray HTTPClient::read_response_body_chunk() {
|
|||
chunk.clear();
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -582,10 +562,8 @@ PoolByteArray HTTPClient::read_response_body_chunk() {
|
|||
status = STATUS_CONNECTED;
|
||||
}
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (err != OK) {
|
||||
close();
|
||||
if (err == ERR_FILE_EOF) {
|
||||
|
@ -605,7 +583,6 @@ PoolByteArray HTTPClient::read_response_body_chunk() {
|
|||
|
||||
HTTPClient::Status HTTPClient::get_status() const {
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
@ -662,7 +639,6 @@ void HTTPClient::_bind_methods() {
|
|||
|
||||
ClassDB::bind_method(D_METHOD("query_string_from_dict:String", "fields"), &HTTPClient::query_string_from_dict);
|
||||
|
||||
|
||||
BIND_CONSTANT(METHOD_GET);
|
||||
BIND_CONSTANT(METHOD_HEAD);
|
||||
BIND_CONSTANT(METHOD_POST);
|
||||
|
@ -684,7 +660,6 @@ void HTTPClient::_bind_methods() {
|
|||
BIND_CONSTANT(STATUS_CONNECTION_ERROR);
|
||||
BIND_CONSTANT(STATUS_SSL_HANDSHAKE_ERROR);
|
||||
|
||||
|
||||
BIND_CONSTANT(RESPONSE_CONTINUE);
|
||||
BIND_CONSTANT(RESPONSE_SWITCHING_PROTOCOLS);
|
||||
BIND_CONSTANT(RESPONSE_PROCESSING);
|
||||
|
@ -742,7 +717,6 @@ void HTTPClient::_bind_methods() {
|
|||
BIND_CONSTANT(RESPONSE_HTTP_VERSION_NOT_SUPPORTED);
|
||||
BIND_CONSTANT(RESPONSE_INSUFFICIENT_STORAGE);
|
||||
BIND_CONSTANT(RESPONSE_NOT_EXTENDED);
|
||||
|
||||
}
|
||||
|
||||
void HTTPClient::set_read_chunk_size(int p_size) {
|
||||
|
@ -777,7 +751,4 @@ HTTPClient::HTTPClient(){
|
|||
}
|
||||
|
||||
HTTPClient::~HTTPClient() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -29,17 +29,16 @@
|
|||
#ifndef HTTP_CLIENT_H
|
||||
#define HTTP_CLIENT_H
|
||||
|
||||
#include "io/ip.h"
|
||||
#include "io/stream_peer.h"
|
||||
#include "io/stream_peer_tcp.h"
|
||||
#include "io/ip.h"
|
||||
#include "reference.h"
|
||||
|
||||
|
||||
class HTTPClient : public Reference {
|
||||
|
||||
GDCLASS(HTTPClient, Reference);
|
||||
public:
|
||||
|
||||
public:
|
||||
enum ResponseCode {
|
||||
|
||||
// 1xx informational
|
||||
|
@ -131,7 +130,6 @@ public:
|
|||
};
|
||||
|
||||
private:
|
||||
|
||||
Status status;
|
||||
IP::ResolverID resolving;
|
||||
int conn_port;
|
||||
|
@ -162,8 +160,6 @@ private:
|
|||
Error _get_http_data(uint8_t *p_buffer, int p_bytes, int &r_received);
|
||||
|
||||
public:
|
||||
|
||||
|
||||
//Error connect_and_get(const String& p_url,bool p_verify_host=true); //connects to a full url and perform request
|
||||
Error connect_to_host(const String &p_host, int p_port, bool p_ssl = false, bool p_verify_host = true);
|
||||
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
#include "print_string.h"
|
||||
bool ImageFormatLoader::recognize(const String &p_extension) const {
|
||||
|
||||
|
||||
List<String> extensions;
|
||||
get_recognized_extensions(&extensions);
|
||||
for (List<String>::Element *E = extensions.front(); E; E = E->next()) {
|
||||
|
@ -45,7 +44,6 @@ bool ImageFormatLoader::recognize(const String& p_extension) const {
|
|||
|
||||
Error ImageLoader::load_image(String p_file, Image *p_image, FileAccess *p_custom) {
|
||||
|
||||
|
||||
FileAccess *f = p_custom;
|
||||
if (!f) {
|
||||
Error err;
|
||||
|
@ -58,7 +56,6 @@ Error ImageLoader::load_image(String p_file,Image *p_image, FileAccess *p_custom
|
|||
|
||||
String extension = p_file.get_extension();
|
||||
|
||||
|
||||
for (int i = 0; i < loader_count; i++) {
|
||||
|
||||
if (!loader[i]->recognize(extension))
|
||||
|
@ -67,21 +64,17 @@ Error ImageLoader::load_image(String p_file,Image *p_image, FileAccess *p_custom
|
|||
|
||||
if (err != ERR_FILE_UNRECOGNIZED) {
|
||||
|
||||
|
||||
if (!p_custom)
|
||||
memdelete(f);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (!p_custom)
|
||||
memdelete(f);
|
||||
|
||||
return ERR_FILE_UNRECOGNIZED;
|
||||
|
||||
}
|
||||
|
||||
void ImageLoader::get_recognized_extensions(List<String> *p_extensions) {
|
||||
|
@ -89,7 +82,6 @@ void ImageLoader::get_recognized_extensions(List<String> *p_extensions) {
|
|||
for (int i = 0; i < loader_count; i++) {
|
||||
|
||||
loader[i]->get_recognized_extensions(p_extensions);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,7 +91,6 @@ bool ImageLoader::recognize(const String& p_extension) {
|
|||
|
||||
if (loader[i]->recognize(p_extension))
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -113,6 +104,3 @@ void ImageLoader::add_image_format_loader(ImageFormatLoader *p_loader) {
|
|||
ERR_FAIL_COND(loader_count >= MAX_LOADERS);
|
||||
loader[loader_count++] = p_loader;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -30,14 +30,13 @@
|
|||
#define IMAGE_LOADER_H
|
||||
|
||||
#include "image.h"
|
||||
#include "ustring.h"
|
||||
#include "os/file_access.h"
|
||||
#include "list.h"
|
||||
#include "os/file_access.h"
|
||||
#include "ustring.h"
|
||||
/**
|
||||
@author Juan Linietsky <reduzio@gmail.com>
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @class ImageScanLineLoader
|
||||
* @author Juan Linietsky <reduzio@gmail.com>
|
||||
|
@ -46,22 +45,20 @@
|
|||
*/
|
||||
class ImageLoader;
|
||||
|
||||
|
||||
/**
|
||||
* @class ImageLoader
|
||||
* Base Class and singleton for loading images from disk
|
||||
* Can load images in one go, or by scanline
|
||||
*/
|
||||
|
||||
|
||||
class ImageFormatLoader {
|
||||
friend class ImageLoader;
|
||||
|
||||
protected:
|
||||
virtual Error load_image(Image *p_image, FileAccess *p_fileaccess) = 0;
|
||||
virtual void get_recognized_extensions(List<String> *p_extensions) const = 0;
|
||||
bool recognize(const String &p_extension) const;
|
||||
|
||||
|
||||
public:
|
||||
virtual ~ImageFormatLoader() {}
|
||||
};
|
||||
|
@ -76,16 +73,12 @@ class ImageLoader {
|
|||
static int loader_count;
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
public:
|
||||
|
||||
static Error load_image(String p_file, Image *p_image, FileAccess *p_custom = NULL);
|
||||
static void get_recognized_extensions(List<String> *p_extensions);
|
||||
static bool recognize(const String &p_extension);
|
||||
|
||||
static void add_image_format_loader(ImageFormatLoader *p_loader);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -27,15 +27,14 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "ip.h"
|
||||
#include "os/thread.h"
|
||||
#include "os/semaphore.h"
|
||||
#include "hash_map.h"
|
||||
#include "os/semaphore.h"
|
||||
#include "os/thread.h"
|
||||
|
||||
VARIANT_ENUM_CAST(IP::ResolverStatus);
|
||||
|
||||
/************* RESOLVER ******************/
|
||||
|
||||
|
||||
struct _IP_ResolverPrivate {
|
||||
|
||||
struct QueueItem {
|
||||
|
@ -86,11 +85,9 @@ struct _IP_ResolverPrivate {
|
|||
queue[i].status = IP::RESOLVER_STATUS_ERROR;
|
||||
else
|
||||
queue[i].status = IP::RESOLVER_STATUS_DONE;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void _thread_function(void *self) {
|
||||
|
||||
_IP_ResolverPrivate *ipr = (_IP_ResolverPrivate *)self;
|
||||
|
@ -100,9 +97,7 @@ struct _IP_ResolverPrivate {
|
|||
ipr->sem->wait();
|
||||
GLOBAL_LOCK_FUNCTION;
|
||||
ipr->resolve_queues();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
HashMap<String, IP_Address> cache;
|
||||
|
@ -110,11 +105,8 @@ struct _IP_ResolverPrivate {
|
|||
static String get_cache_key(String p_hostname, IP::Type p_type) {
|
||||
return itos(p_type) + p_hostname;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
IP_Address IP::resolve_hostname(const String &p_hostname, IP::Type p_type) {
|
||||
|
||||
GLOBAL_LOCK_FUNCTION;
|
||||
|
@ -126,7 +118,6 @@ IP_Address IP::resolve_hostname(const String& p_hostname, IP::Type p_type) {
|
|||
IP_Address res = _resolve_hostname(p_hostname, p_type);
|
||||
resolver->cache[key] = res;
|
||||
return res;
|
||||
|
||||
}
|
||||
IP::ResolverID IP::resolve_hostname_queue_item(const String &p_hostname, IP::Type p_type) {
|
||||
|
||||
|
@ -165,7 +156,6 @@ IP::ResolverStatus IP::get_resolve_item_status(ResolverID p_id) const {
|
|||
ERR_FAIL_COND_V(resolver->queue[p_id].status == IP::RESOLVER_STATUS_NONE, IP::RESOLVER_STATUS_NONE);
|
||||
|
||||
return resolver->queue[p_id].status;
|
||||
|
||||
}
|
||||
IP_Address IP::get_resolve_item_address(ResolverID p_id) const {
|
||||
|
||||
|
@ -178,9 +168,7 @@ IP_Address IP::get_resolve_item_address(ResolverID p_id) const {
|
|||
ERR_FAIL_COND_V(resolver->queue[p_id].status != IP::RESOLVER_STATUS_DONE, IP_Address());
|
||||
}
|
||||
|
||||
|
||||
return resolver->queue[p_id].response;
|
||||
|
||||
}
|
||||
void IP::erase_resolve_item(ResolverID p_id) {
|
||||
|
||||
|
@ -189,7 +177,6 @@ void IP::erase_resolve_item(ResolverID p_id) {
|
|||
GLOBAL_LOCK_FUNCTION;
|
||||
|
||||
resolver->queue[p_id].status = IP::RESOLVER_STATUS_NONE;
|
||||
|
||||
}
|
||||
|
||||
void IP::clear_cache(const String &p_hostname) {
|
||||
|
@ -240,7 +227,6 @@ void IP::_bind_methods() {
|
|||
BIND_CONSTANT(TYPE_ANY);
|
||||
}
|
||||
|
||||
|
||||
IP *IP::singleton = NULL;
|
||||
|
||||
IP *IP::get_singleton() {
|
||||
|
@ -248,7 +234,6 @@ IP* IP::get_singleton() {
|
|||
return singleton;
|
||||
}
|
||||
|
||||
|
||||
IP *(*IP::_create)() = NULL;
|
||||
|
||||
IP *IP::create() {
|
||||
|
@ -283,8 +268,6 @@ IP::IP() {
|
|||
resolver->sem = NULL;
|
||||
resolver->thread = NULL;
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
IP::~IP() {
|
||||
|
@ -300,5 +283,4 @@ IP::~IP() {
|
|||
memdelete(resolver);
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
|
16
core/io/ip.h
16
core/io/ip.h
|
@ -29,17 +29,16 @@
|
|||
#ifndef IP_H
|
||||
#define IP_H
|
||||
|
||||
|
||||
#include "os/os.h"
|
||||
#include "io/ip_address.h"
|
||||
#include "os/os.h"
|
||||
|
||||
struct _IP_ResolverPrivate;
|
||||
|
||||
class IP : public Object {
|
||||
GDCLASS(IP, Object);
|
||||
OBJ_CATEGORY("Networking");
|
||||
public:
|
||||
|
||||
public:
|
||||
enum ResolverStatus {
|
||||
|
||||
RESOLVER_STATUS_NONE,
|
||||
|
@ -61,15 +60,12 @@ public:
|
|||
RESOLVER_INVALID_ID = -1
|
||||
};
|
||||
|
||||
|
||||
typedef int ResolverID;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
_IP_ResolverPrivate *resolver;
|
||||
protected:
|
||||
|
||||
protected:
|
||||
static IP *singleton;
|
||||
static void _bind_methods();
|
||||
|
||||
|
@ -77,10 +73,8 @@ protected:
|
|||
Array _get_local_addresses() const;
|
||||
|
||||
static IP *(*_create)();
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
IP_Address resolve_hostname(const String &p_hostname, Type p_type = TYPE_ANY);
|
||||
// async resolver hostname
|
||||
ResolverID resolve_hostname_queue_item(const String &p_hostname, Type p_type = TYPE_ANY);
|
||||
|
@ -97,8 +91,6 @@ public:
|
|||
|
||||
IP();
|
||||
~IP();
|
||||
|
||||
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(IP::Type);
|
||||
|
|
|
@ -33,8 +33,8 @@ IP_Address::operator Variant() const {
|
|||
return operator String();
|
||||
}*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
IP_Address::operator String() const {
|
||||
|
||||
|
@ -149,7 +149,6 @@ void IP_Address::_parse_ipv6(const String& p_string) {
|
|||
_parse_hex(p_string, parts[i], (uint8_t *)&(field16[idx++]));
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
void IP_Address::_parse_ipv4(const String &p_string, int p_start, uint8_t *p_ret) {
|
||||
|
@ -255,5 +254,4 @@ IP_Address::IP_Address(uint32_t p_a,uint32_t p_b,uint32_t p_c,uint32_t p_d, bool
|
|||
_32_to_buf(&field8[8], p_c);
|
||||
_32_to_buf(&field8[12], p_d);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
struct IP_Address {
|
||||
|
||||
private:
|
||||
|
||||
union {
|
||||
uint8_t field8[16];
|
||||
uint16_t field16[8];
|
||||
|
@ -83,6 +82,4 @@ public:
|
|||
IP_Address() { clear(); }
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // IP_ADDRESS_H
|
||||
|
|
|
@ -42,8 +42,6 @@ const char * JSON::tk_name[TK_MAX] = {
|
|||
"EOF",
|
||||
};
|
||||
|
||||
|
||||
|
||||
String JSON::_print_var(const Variant &p_var) {
|
||||
|
||||
switch (p_var.get_type()) {
|
||||
|
@ -87,9 +85,7 @@ String JSON::_print_var(const Variant& p_var) {
|
|||
return s;
|
||||
};
|
||||
default: return "\"" + String(p_var).json_escape() + "\"";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
String JSON::print(const Variant &p_var) {
|
||||
|
@ -97,7 +93,6 @@ String JSON::print(const Variant& p_var) {
|
|||
return _print_var(p_var);
|
||||
}
|
||||
|
||||
|
||||
Error JSON::_get_token(const CharType *p_str, int &idx, int p_len, Token &r_token, int &line, String &r_err_str) {
|
||||
|
||||
while (p_len > 0) {
|
||||
|
@ -180,7 +175,6 @@ Error JSON::_get_token(const CharType *p_str, int &idx, int p_len, Token& r_toke
|
|||
case 'u': {
|
||||
//hexnumbarh - oct is deprecated
|
||||
|
||||
|
||||
for (int j = 0; j < 4; j++) {
|
||||
CharType c = p_str[idx + j + 1];
|
||||
if (c == 0) {
|
||||
|
@ -208,12 +202,9 @@ Error JSON::_get_token(const CharType *p_str, int &idx, int p_len, Token& r_toke
|
|||
|
||||
res <<= 4;
|
||||
res |= v;
|
||||
|
||||
|
||||
}
|
||||
idx += 4; //will add at the end anyway
|
||||
|
||||
|
||||
} break;
|
||||
//case '\"': res='\"'; break;
|
||||
//case '\\': res='\\'; break;
|
||||
|
@ -274,18 +265,14 @@ Error JSON::_get_token(const CharType *p_str, int &idx, int p_len, Token& r_toke
|
|||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Error JSON::_parse_value(Variant &value, Token &token, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str) {
|
||||
|
||||
|
||||
if (token.type == TK_CURLY_BRACKET_OPEN) {
|
||||
|
||||
Dictionary d;
|
||||
|
@ -334,13 +321,11 @@ Error JSON::_parse_value(Variant &value,Token& token,const CharType *p_str,int &
|
|||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
|
||||
|
||||
Error JSON::_parse_array(Array &array, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str) {
|
||||
|
||||
Token token;
|
||||
bool need_comma = false;
|
||||
|
||||
|
||||
while (index < p_len) {
|
||||
|
||||
Error err = _get_token(p_str, index, p_len, token, line, r_err_str);
|
||||
|
@ -371,11 +356,9 @@ Error JSON::_parse_array(Array &array,const CharType *p_str,int &index, int p_le
|
|||
|
||||
array.push_back(v);
|
||||
need_comma = true;
|
||||
|
||||
}
|
||||
|
||||
return ERR_PARSE_ERROR;
|
||||
|
||||
}
|
||||
|
||||
Error JSON::_parse_object(Dictionary &object, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str) {
|
||||
|
@ -385,10 +368,8 @@ Error JSON::_parse_object(Dictionary &object,const CharType *p_str,int &index, i
|
|||
Token token;
|
||||
bool need_comma = false;
|
||||
|
||||
|
||||
while (index < p_len) {
|
||||
|
||||
|
||||
if (at_key) {
|
||||
|
||||
Error err = _get_token(p_str, index, p_len, token, line, r_err_str);
|
||||
|
@ -414,7 +395,6 @@ Error JSON::_parse_object(Dictionary &object,const CharType *p_str,int &index, i
|
|||
|
||||
if (token.type != TK_STRING) {
|
||||
|
||||
|
||||
r_err_str = "Expected key";
|
||||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
|
@ -431,7 +411,6 @@ Error JSON::_parse_object(Dictionary &object,const CharType *p_str,int &index, i
|
|||
at_key = false;
|
||||
} else {
|
||||
|
||||
|
||||
Error err = _get_token(p_str, index, p_len, token, line, r_err_str);
|
||||
if (err != OK)
|
||||
return err;
|
||||
|
@ -449,10 +428,8 @@ Error JSON::_parse_object(Dictionary &object,const CharType *p_str,int &index, i
|
|||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
|
||||
|
||||
Error JSON::parse(const String &p_json, Variant &r_ret, String &r_err_str, int &r_err_line) {
|
||||
|
||||
|
||||
const CharType *str = p_json.ptr();
|
||||
int idx = 0;
|
||||
int len = p_json.length();
|
||||
|
@ -467,8 +444,4 @@ Error JSON::parse(const String& p_json, Variant &r_ret, String &r_err_str, int &
|
|||
err = _parse_value(r_ret, token, str, idx, len, r_err_line, r_err_str);
|
||||
|
||||
return err;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -29,11 +29,8 @@
|
|||
#ifndef JSON_H
|
||||
#define JSON_H
|
||||
|
||||
|
||||
|
||||
#include "variant.h"
|
||||
|
||||
|
||||
class JSON {
|
||||
|
||||
enum TokenType {
|
||||
|
|
|
@ -27,11 +27,10 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "marshalls.h"
|
||||
#include "print_string.h"
|
||||
#include "os/keyboard.h"
|
||||
#include "print_string.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#define ENCODE_MASK 0xFF
|
||||
#define ENCODE_FLAG_64 1 << 16
|
||||
|
||||
|
@ -45,7 +44,6 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
|
|||
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
|
||||
}
|
||||
|
||||
|
||||
uint32_t type = decode_uint32(buf);
|
||||
|
||||
ERR_FAIL_COND_V((type & ENCODE_MASK) >= Variant::VARIANT_MAX, ERR_INVALID_DATA);
|
||||
|
@ -119,7 +117,6 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
|
|||
if (strlen % 4)
|
||||
(*r_len) += 4 - strlen % 4;
|
||||
(*r_len) += 4 + strlen;
|
||||
|
||||
}
|
||||
|
||||
} break;
|
||||
|
@ -298,8 +295,6 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
|
|||
copymem(&wr[0], &buf[20], datalen);
|
||||
wr = PoolVector<uint8_t>::Write();
|
||||
|
||||
|
||||
|
||||
img = Image(w, h, mipmaps, fmt, data);
|
||||
}
|
||||
|
||||
|
@ -338,7 +333,6 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
|
|||
if (r_len)
|
||||
(*r_len) += 12;
|
||||
|
||||
|
||||
for (int i = 0; i < total; i++) {
|
||||
|
||||
ERR_FAIL_COND_V((int)len < 4, ERR_INVALID_DATA);
|
||||
|
@ -356,7 +350,6 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
|
|||
String str;
|
||||
str.parse_utf8((const char *)buf, strlen);
|
||||
|
||||
|
||||
if (i < namecount)
|
||||
names.push_back(str);
|
||||
else if (i < namecount + subnamecount)
|
||||
|
@ -369,7 +362,6 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
|
|||
|
||||
if (r_len)
|
||||
(*r_len) += 4 + strlen + pad;
|
||||
|
||||
}
|
||||
|
||||
r_variant = NodePath(names, subnames, flags & 1, prop);
|
||||
|
@ -381,7 +373,6 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
|
|||
len -= 4;
|
||||
ERR_FAIL_COND_V((int)strlen > len, ERR_INVALID_DATA);
|
||||
|
||||
|
||||
String str;
|
||||
str.parse_utf8((const char *)buf, strlen);
|
||||
|
||||
|
@ -403,7 +394,6 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
|
|||
} break;
|
||||
case Variant::OBJECT: {
|
||||
|
||||
|
||||
r_variant = (Object *)NULL;
|
||||
} break;
|
||||
case Variant::INPUT_EVENT: {
|
||||
|
@ -434,7 +424,6 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
|
|||
if (r_len)
|
||||
(*r_len) += 8;
|
||||
|
||||
|
||||
} break;
|
||||
case InputEvent::MOUSE_BUTTON: {
|
||||
|
||||
|
@ -544,7 +533,6 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
|
|||
|
||||
r_variant = varr;
|
||||
|
||||
|
||||
} break;
|
||||
|
||||
// arrays
|
||||
|
@ -556,7 +544,6 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
|
|||
len -= 4;
|
||||
ERR_FAIL_COND_V((int)count > len, ERR_INVALID_DATA);
|
||||
|
||||
|
||||
PoolVector<uint8_t> data;
|
||||
|
||||
if (count) {
|
||||
|
@ -578,8 +565,6 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
|
|||
(*r_len) += 4 + count;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} break;
|
||||
case Variant::POOL_INT_ARRAY: {
|
||||
|
||||
|
@ -635,7 +620,6 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
|
|||
(*r_len) += 4 + count * sizeof(float);
|
||||
}
|
||||
|
||||
|
||||
} break;
|
||||
case Variant::POOL_STRING_ARRAY: {
|
||||
|
||||
|
@ -679,12 +663,10 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
|
|||
(*r_len) += pad;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
r_variant = strings;
|
||||
|
||||
|
||||
} break;
|
||||
case Variant::POOL_VECTOR2_ARRAY: {
|
||||
|
||||
|
@ -708,7 +690,6 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
|
|||
|
||||
w[i].x = decode_float(buf + i * 4 * 2 + 4 * 0);
|
||||
w[i].y = decode_float(buf + i * 4 * 2 + 4 * 1);
|
||||
|
||||
}
|
||||
|
||||
int adv = 4 * 2 * count;
|
||||
|
@ -717,7 +698,6 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
|
|||
(*r_len) += adv;
|
||||
len -= adv;
|
||||
buf += adv;
|
||||
|
||||
}
|
||||
|
||||
r_variant = varray;
|
||||
|
@ -746,7 +726,6 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
|
|||
w[i].x = decode_float(buf + i * 4 * 3 + 4 * 0);
|
||||
w[i].y = decode_float(buf + i * 4 * 3 + 4 * 1);
|
||||
w[i].z = decode_float(buf + i * 4 * 3 + 4 * 2);
|
||||
|
||||
}
|
||||
|
||||
int adv = 4 * 3 * count;
|
||||
|
@ -755,7 +734,6 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
|
|||
(*r_len) += adv;
|
||||
len -= adv;
|
||||
buf += adv;
|
||||
|
||||
}
|
||||
|
||||
r_variant = varray;
|
||||
|
@ -785,7 +763,6 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
|
|||
w[i].g = decode_float(buf + i * 4 * 4 + 4 * 1);
|
||||
w[i].b = decode_float(buf + i * 4 * 4 + 4 * 2);
|
||||
w[i].a = decode_float(buf + i * 4 * 4 + 4 * 3);
|
||||
|
||||
}
|
||||
|
||||
int adv = 4 * 4 * count;
|
||||
|
@ -794,7 +771,6 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
|
|||
(*r_len) += adv;
|
||||
len -= adv;
|
||||
buf += adv;
|
||||
|
||||
}
|
||||
|
||||
r_variant = carray;
|
||||
|
@ -891,7 +867,6 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
|
|||
r_len += 4;
|
||||
}
|
||||
|
||||
|
||||
} break;
|
||||
case Variant::NODE_PATH: {
|
||||
|
||||
|
@ -941,14 +916,12 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
|
|||
buf += pad + utf8.length();
|
||||
}
|
||||
|
||||
|
||||
r_len += 4 + utf8.length() + pad;
|
||||
}
|
||||
|
||||
} break;
|
||||
case Variant::STRING: {
|
||||
|
||||
|
||||
CharString utf8 = p_variant.operator String().utf8();
|
||||
|
||||
if (buf) {
|
||||
|
@ -970,7 +943,6 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
|
|||
Vector2 v2 = p_variant;
|
||||
encode_float(v2.x, &buf[0]);
|
||||
encode_float(v2.y, &buf[4]);
|
||||
|
||||
}
|
||||
|
||||
r_len += 2 * 4;
|
||||
|
@ -1012,7 +984,6 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
r_len += 6 * 4;
|
||||
|
||||
} break;
|
||||
|
@ -1056,7 +1027,6 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
|
|||
|
||||
r_len += 6 * 4;
|
||||
|
||||
|
||||
} break;
|
||||
case Variant::BASIS: {
|
||||
|
||||
|
@ -1070,7 +1040,6 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
r_len += 9 * 4;
|
||||
|
||||
} break;
|
||||
|
@ -1088,8 +1057,6 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
|
|||
encode_float(val.origin.x, &buf[36]);
|
||||
encode_float(val.origin.y, &buf[40]);
|
||||
encode_float(val.origin.z, &buf[44]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
r_len += 12 * 4;
|
||||
|
@ -1142,11 +1109,9 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
|
|||
case Variant::_RID:
|
||||
case Variant::OBJECT: {
|
||||
|
||||
|
||||
} break;
|
||||
case Variant::INPUT_EVENT: {
|
||||
|
||||
|
||||
InputEvent ie = p_variant;
|
||||
|
||||
if (buf) {
|
||||
|
@ -1220,7 +1185,6 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
|
|||
encode_uint32(llen, &buf[8]);
|
||||
r_len += llen;
|
||||
|
||||
|
||||
// not supported
|
||||
} break;
|
||||
case Variant::DICTIONARY: {
|
||||
|
@ -1236,7 +1200,6 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
|
|||
List<Variant> keys;
|
||||
d.get_key_list(&keys);
|
||||
|
||||
|
||||
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
|
||||
|
||||
/*
|
||||
|
@ -1287,7 +1250,6 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
|
|||
buf += len;
|
||||
}
|
||||
|
||||
|
||||
} break;
|
||||
// arrays
|
||||
case Variant::POOL_BYTE_ARRAY: {
|
||||
|
@ -1301,7 +1263,6 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
|
|||
buf += 4;
|
||||
PoolVector<uint8_t>::Read r = data.read();
|
||||
copymem(buf, &r[0], datalen * datasize);
|
||||
|
||||
}
|
||||
|
||||
r_len += 4 + datalen * datasize;
|
||||
|
@ -1321,7 +1282,6 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
|
|||
PoolVector<int>::Read r = data.read();
|
||||
for (int i = 0; i < datalen; i++)
|
||||
encode_uint32(r[i], &buf[i * datasize]);
|
||||
|
||||
}
|
||||
|
||||
r_len += 4 + datalen * datasize;
|
||||
|
@ -1339,7 +1299,6 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
|
|||
PoolVector<real_t>::Read r = data.read();
|
||||
for (int i = 0; i < datalen; i++)
|
||||
encode_float(r[i], &buf[i * datasize]);
|
||||
|
||||
}
|
||||
|
||||
r_len += 4 + datalen * datasize;
|
||||
|
@ -1347,7 +1306,6 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
|
|||
} break;
|
||||
case Variant::POOL_STRING_ARRAY: {
|
||||
|
||||
|
||||
PoolVector<String> data = p_variant;
|
||||
int len = data.size();
|
||||
|
||||
|
@ -1360,7 +1318,6 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
|
|||
|
||||
for (int i = 0; i < len; i++) {
|
||||
|
||||
|
||||
CharString utf8 = data.get(i).utf8();
|
||||
|
||||
if (buf) {
|
||||
|
@ -1400,7 +1357,6 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
|
|||
encode_float(v.x, &buf[0]);
|
||||
encode_float(v.y, &buf[4]);
|
||||
buf += 4 * 2;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1429,7 +1385,6 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
|
|||
encode_float(v.y, &buf[4]);
|
||||
encode_float(v.z, &buf[8]);
|
||||
buf += 4 * 3;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1454,7 +1409,6 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
|
|||
|
||||
Color c = data.get(i);
|
||||
|
||||
|
||||
encode_float(c.r, &buf[0]);
|
||||
encode_float(c.g, &buf[4]);
|
||||
encode_float(c.b, &buf[8]);
|
||||
|
@ -1470,7 +1424,4 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
|
|||
}
|
||||
|
||||
return OK;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -38,7 +38,6 @@
|
|||
* in an endian independent way
|
||||
*/
|
||||
|
||||
|
||||
union MarshallFloat {
|
||||
|
||||
uint32_t i; ///< int
|
||||
|
@ -56,7 +55,8 @@ static inline unsigned int encode_uint16(uint16_t p_uint, uint8_t *p_arr) {
|
|||
for (int i = 0; i < 2; i++) {
|
||||
|
||||
*p_arr = p_uint & 0xFF;
|
||||
p_arr++; p_uint>>=8;
|
||||
p_arr++;
|
||||
p_uint >>= 8;
|
||||
}
|
||||
|
||||
return sizeof(uint16_t);
|
||||
|
@ -67,7 +67,8 @@ static inline unsigned int encode_uint32(uint32_t p_uint, uint8_t *p_arr) {
|
|||
for (int i = 0; i < 4; i++) {
|
||||
|
||||
*p_arr = p_uint & 0xFF;
|
||||
p_arr++; p_uint>>=8;
|
||||
p_arr++;
|
||||
p_uint >>= 8;
|
||||
}
|
||||
|
||||
return sizeof(uint32_t);
|
||||
|
@ -87,7 +88,8 @@ static inline unsigned int encode_uint64(uint64_t p_uint, uint8_t *p_arr) {
|
|||
for (int i = 0; i < 8; i++) {
|
||||
|
||||
*p_arr = p_uint & 0xFF;
|
||||
p_arr++; p_uint>>=8;
|
||||
p_arr++;
|
||||
p_uint >>= 8;
|
||||
}
|
||||
|
||||
return sizeof(uint64_t);
|
||||
|
@ -100,10 +102,8 @@ static inline unsigned int encode_double(double p_double, uint8_t *p_arr) {
|
|||
encode_uint64(md.l, p_arr);
|
||||
|
||||
return sizeof(uint64_t);
|
||||
|
||||
}
|
||||
|
||||
|
||||
static inline int encode_cstring(const char *p_string, uint8_t *p_data) {
|
||||
|
||||
int len = 0;
|
||||
|
@ -180,10 +180,8 @@ static inline double decode_double(const uint8_t *p_arr) {
|
|||
MarshallDouble md;
|
||||
md.l = decode_uint64(p_arr);
|
||||
return md.d;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len = NULL);
|
||||
Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len);
|
||||
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
/*************************************************************************/
|
||||
#include "networked_multiplayer_peer.h"
|
||||
|
||||
|
||||
void NetworkedMultiplayerPeer::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_transfer_mode", "mode"), &NetworkedMultiplayerPeer::set_transfer_mode);
|
||||
|
@ -55,7 +54,6 @@ void NetworkedMultiplayerPeer::_bind_methods() {
|
|||
BIND_CONSTANT(TARGET_PEER_BROADCAST);
|
||||
BIND_CONSTANT(TARGET_PEER_SERVER);
|
||||
|
||||
|
||||
ADD_SIGNAL(MethodInfo("peer_connected", PropertyInfo(Variant::INT, "id")));
|
||||
ADD_SIGNAL(MethodInfo("peer_disconnected", PropertyInfo(Variant::INT, "id")));
|
||||
ADD_SIGNAL(MethodInfo("server_disconnected"));
|
||||
|
@ -64,6 +62,4 @@ void NetworkedMultiplayerPeer::_bind_methods() {
|
|||
}
|
||||
|
||||
NetworkedMultiplayerPeer::NetworkedMultiplayerPeer() {
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -37,8 +37,8 @@ class NetworkedMultiplayerPeer : public PacketPeer {
|
|||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
||||
public:
|
||||
enum {
|
||||
TARGET_PEER_BROADCAST = 0,
|
||||
TARGET_PEER_SERVER = 1
|
||||
|
@ -55,7 +55,6 @@ public:
|
|||
CONNECTION_CONNECTED,
|
||||
};
|
||||
|
||||
|
||||
virtual void set_transfer_mode(TransferMode p_mode) = 0;
|
||||
virtual void set_target_peer(int p_peer_id) = 0;
|
||||
|
||||
|
@ -70,7 +69,6 @@ public:
|
|||
virtual void set_refuse_new_connections(bool p_enable) = 0;
|
||||
virtual bool is_refusing_new_connections() const = 0;
|
||||
|
||||
|
||||
virtual ConnectionStatus get_connection_status() const = 0;
|
||||
|
||||
NetworkedMultiplayerPeer();
|
||||
|
|
|
@ -28,12 +28,10 @@
|
|||
/*************************************************************************/
|
||||
#include "packet_peer.h"
|
||||
|
||||
#include "io/marshalls.h"
|
||||
#include "global_config.h"
|
||||
#include "io/marshalls.h"
|
||||
/* helpers / binders */
|
||||
|
||||
|
||||
|
||||
PacketPeer::PacketPeer() {
|
||||
|
||||
last_get_error = OK;
|
||||
|
@ -56,7 +54,6 @@ Error PacketPeer::get_packet_buffer(PoolVector<uint8_t> &r_buffer) const {
|
|||
w[i] = buffer[i];
|
||||
|
||||
return OK;
|
||||
|
||||
}
|
||||
|
||||
Error PacketPeer::put_packet_buffer(const PoolVector<uint8_t> &p_buffer) {
|
||||
|
@ -67,7 +64,6 @@ Error PacketPeer::put_packet_buffer(const PoolVector<uint8_t> &p_buffer) {
|
|||
|
||||
PoolVector<uint8_t>::Read r = p_buffer.read();
|
||||
return put_packet(&r[0], len);
|
||||
|
||||
}
|
||||
|
||||
Error PacketPeer::get_var(Variant &r_variant) const {
|
||||
|
@ -79,7 +75,6 @@ Error PacketPeer::get_var(Variant &r_variant) const {
|
|||
return err;
|
||||
|
||||
return decode_variant(r_variant, buffer, buffer_size);
|
||||
|
||||
}
|
||||
|
||||
Error PacketPeer::put_var(const Variant &p_packet) {
|
||||
|
@ -98,7 +93,6 @@ Error PacketPeer::put_var(const Variant& p_packet) {
|
|||
ERR_FAIL_COND_V(err, err);
|
||||
|
||||
return put_packet(buf, len);
|
||||
|
||||
}
|
||||
|
||||
Variant PacketPeer::_bnd_get_var() const {
|
||||
|
@ -123,7 +117,6 @@ Error PacketPeer::_get_packet_error() const {
|
|||
return last_get_error;
|
||||
}
|
||||
|
||||
|
||||
void PacketPeer::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_var:Variant"), &PacketPeer::_bnd_get_var);
|
||||
|
@ -136,7 +129,6 @@ void PacketPeer::_bind_methods() {
|
|||
|
||||
/***************/
|
||||
|
||||
|
||||
void PacketPeerStream::_set_stream_peer(REF p_peer) {
|
||||
|
||||
ERR_FAIL_COND(p_peer.is_null());
|
||||
|
@ -210,7 +202,6 @@ Error PacketPeerStream::get_packet(const uint8_t **r_buffer,int &r_buffer_size)
|
|||
*r_buffer = &temp_buffer[0];
|
||||
r_buffer_size = len;
|
||||
return OK;
|
||||
|
||||
}
|
||||
|
||||
Error PacketPeerStream::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
|
||||
|
@ -237,7 +228,6 @@ Error PacketPeerStream::put_packet(const uint8_t *p_buffer,int p_buffer_size) {
|
|||
|
||||
int PacketPeerStream::get_max_packet_size() const {
|
||||
|
||||
|
||||
return temp_buffer.size();
|
||||
}
|
||||
|
||||
|
@ -259,17 +249,12 @@ void PacketPeerStream::set_input_buffer_max_size(int p_max_size) {
|
|||
ERR_FAIL_COND(ring_buffer.data_left());
|
||||
ring_buffer.resize(nearest_shift(p_max_size + 4));
|
||||
temp_buffer.resize(nearest_power_of_2(p_max_size + 4));
|
||||
|
||||
}
|
||||
|
||||
PacketPeerStream::PacketPeerStream() {
|
||||
|
||||
|
||||
int rbsize = GLOBAL_GET("network/packets/packet_stream_peer_max_buffer_po2");
|
||||
|
||||
|
||||
ring_buffer.resize(rbsize);
|
||||
temp_buffer.resize(1 << rbsize);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -29,8 +29,8 @@
|
|||
#ifndef PACKET_PEER_H
|
||||
#define PACKET_PEER_H
|
||||
|
||||
#include "object.h"
|
||||
#include "io/stream_peer.h"
|
||||
#include "object.h"
|
||||
#include "ring_buffer.h"
|
||||
class PacketPeer : public Reference {
|
||||
|
||||
|
@ -41,16 +41,13 @@ class PacketPeer : public Reference {
|
|||
|
||||
static void _bind_methods();
|
||||
|
||||
|
||||
Error _put_packet(const PoolVector<uint8_t> &p_buffer);
|
||||
PoolVector<uint8_t> _get_packet() const;
|
||||
Error _get_packet_error() const;
|
||||
|
||||
|
||||
mutable Error last_get_error;
|
||||
|
||||
public:
|
||||
|
||||
virtual int get_available_packet_count() const = 0;
|
||||
virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) const = 0; ///< buffer is GONE after next get_packet
|
||||
virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size) = 0;
|
||||
|
@ -80,25 +77,21 @@ class PacketPeerStream : public PacketPeer {
|
|||
mutable Vector<uint8_t> temp_buffer;
|
||||
|
||||
Error _poll_buffer() const;
|
||||
protected:
|
||||
|
||||
protected:
|
||||
void _set_stream_peer(REF p_peer);
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
||||
public:
|
||||
virtual int get_available_packet_count() const;
|
||||
virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) const;
|
||||
virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size);
|
||||
|
||||
virtual int get_max_packet_size() const;
|
||||
|
||||
|
||||
|
||||
void set_stream_peer(const Ref<StreamPeer> &p_peer);
|
||||
void set_input_buffer_max_size(int p_max_size);
|
||||
PacketPeerStream();
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // PACKET_STREAM_H
|
||||
|
|
|
@ -61,8 +61,6 @@ void PacketPeerUDP::_bind_methods() {
|
|||
//ClassDB::bind_method(D_METHOD("get_packet_address"),&PacketPeerUDP::_get_packet_address);
|
||||
ClassDB::bind_method(D_METHOD("get_packet_port"), &PacketPeerUDP::get_packet_port);
|
||||
ClassDB::bind_method(D_METHOD("set_dest_address", "host", "port"), &PacketPeerUDP::_set_dest_address);
|
||||
|
||||
|
||||
}
|
||||
|
||||
Ref<PacketPeerUDP> PacketPeerUDP::create_ref() {
|
||||
|
@ -79,7 +77,5 @@ PacketPeerUDP* PacketPeerUDP::create() {
|
|||
return _create();
|
||||
}
|
||||
|
||||
PacketPeerUDP::PacketPeerUDP()
|
||||
{
|
||||
|
||||
PacketPeerUDP::PacketPeerUDP() {
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
#ifndef PACKET_PEER_UDP_H
|
||||
#define PACKET_PEER_UDP_H
|
||||
|
||||
|
||||
#include "io/ip.h"
|
||||
#include "io/packet_peer.h"
|
||||
|
||||
|
@ -37,7 +36,6 @@ class PacketPeerUDP : public PacketPeer {
|
|||
GDCLASS(PacketPeerUDP, PacketPeer);
|
||||
|
||||
protected:
|
||||
|
||||
static PacketPeerUDP *(*_create)();
|
||||
static void _bind_methods();
|
||||
|
||||
|
@ -46,7 +44,6 @@ protected:
|
|||
Error _set_dest_address(const String &p_address, int p_port);
|
||||
|
||||
public:
|
||||
|
||||
virtual Error listen(int p_port, IP_Address p_bind_address = IP_Address("*"), int p_recv_buffer_size = 65536) = 0;
|
||||
virtual void close() = 0;
|
||||
virtual Error wait() = 0;
|
||||
|
@ -55,7 +52,6 @@ public:
|
|||
virtual int get_packet_port() const = 0;
|
||||
virtual void set_dest_address(const IP_Address &p_address, int p_port) = 0;
|
||||
|
||||
|
||||
static Ref<PacketPeerUDP> create_ref();
|
||||
static PacketPeerUDP *create();
|
||||
|
||||
|
|
|
@ -57,7 +57,6 @@ void PCKPacker::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("flush", "verbose"), &PCKPacker::flush);
|
||||
};
|
||||
|
||||
|
||||
Error PCKPacker::pck_start(const String &p_file, int p_alignment) {
|
||||
|
||||
file = FileAccess::open(p_file, FileAccess::WRITE);
|
||||
|
@ -130,7 +129,6 @@ Error PCKPacker::flush(bool p_verbose) {
|
|||
file->store_32(0);
|
||||
};
|
||||
|
||||
|
||||
uint64_t ofs = file->get_pos();
|
||||
ofs = _align(ofs, alignment);
|
||||
|
||||
|
|
|
@ -53,7 +53,6 @@ public:
|
|||
Error add_file(const String &p_file, const String &p_src);
|
||||
Error flush(bool p_verbose = false);
|
||||
|
||||
|
||||
PCKPacker();
|
||||
~PCKPacker();
|
||||
};
|
||||
|
|
|
@ -26,16 +26,15 @@
|
|||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "version.h"
|
||||
#include "resource_format_binary.h"
|
||||
#include "global_config.h"
|
||||
#include "io/file_access_compressed.h"
|
||||
#include "io/marshalls.h"
|
||||
#include "os/dir_access.h"
|
||||
#include "version.h"
|
||||
//#define print_bl(m_what) print_line(m_what)
|
||||
#define print_bl(m_what)
|
||||
|
||||
|
||||
enum {
|
||||
|
||||
//numbering must be different from variant, in case new variant types are added (variant must be always contiguous for jumptable optimization)
|
||||
|
@ -84,10 +83,8 @@ enum {
|
|||
FORMAT_VERSION = 2,
|
||||
FORMAT_VERSION_CAN_RENAME_DEPS = 1
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
void ResourceInteractiveLoaderBinary::_advance_padding(uint32_t p_len) {
|
||||
|
||||
uint32_t extra = 4 - (p_len % 4);
|
||||
|
@ -95,10 +92,8 @@ void ResourceInteractiveLoaderBinary::_advance_padding(uint32_t p_len) {
|
|||
for (uint32_t i = 0; i < extra; i++)
|
||||
f->get_8(); //pad to 32
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
StringName ResourceInteractiveLoaderBinary::_get_string() {
|
||||
|
||||
uint32_t id = f->get_32();
|
||||
|
@ -116,16 +111,13 @@ StringName ResourceInteractiveLoaderBinary::_get_string() {
|
|||
}
|
||||
|
||||
return string_map[id];
|
||||
|
||||
}
|
||||
|
||||
Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
|
||||
|
||||
|
||||
uint32_t type = f->get_32();
|
||||
print_bl("find property of type: " + itos(type));
|
||||
|
||||
|
||||
switch (type) {
|
||||
|
||||
case VARIANT_NIL: {
|
||||
|
@ -268,7 +260,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
|
|||
} break;
|
||||
case VARIANT_IMAGE: {
|
||||
|
||||
|
||||
uint32_t encoding = f->get_32();
|
||||
if (encoding == IMAGE_ENCODING_EMPTY) {
|
||||
r_v = Variant();
|
||||
|
@ -290,7 +281,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
|
|||
return ERR_PARSE_ERROR;
|
||||
}
|
||||
|
||||
|
||||
Image::Format fmt = Image::Format(format & format_version_mask); //if format changes, we can add a compatibility bit on top
|
||||
|
||||
uint32_t datalen = f->get_32();
|
||||
|
@ -332,9 +322,7 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
|
|||
}
|
||||
_advance_padding(data.size());
|
||||
|
||||
|
||||
r_v = img;
|
||||
|
||||
}
|
||||
|
||||
} break;
|
||||
|
@ -350,7 +338,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
|
|||
absolute = subname_count & 0x8000;
|
||||
subname_count &= 0x7FFF;
|
||||
|
||||
|
||||
for (int i = 0; i < name_count; i++)
|
||||
names.push_back(_get_string());
|
||||
for (uint32_t i = 0; i < subname_count; i++)
|
||||
|
@ -396,7 +383,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
|
|||
if (path.find("://") == -1 && path.is_rel_path()) {
|
||||
// path is relative to file being loaded, so convert to a resource path
|
||||
path = GlobalConfig::get_singleton()->localize_path(res_path.get_base_dir().plus_file(path));
|
||||
|
||||
}
|
||||
|
||||
if (remaps.find(path)) {
|
||||
|
@ -426,7 +412,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
|
|||
if (path.find("://") == -1 && path.is_rel_path()) {
|
||||
// path is relative to file being loaded, so convert to a resource path
|
||||
path = GlobalConfig::get_singleton()->localize_path(res_path.get_base_dir().plus_file(path));
|
||||
|
||||
}
|
||||
|
||||
RES res = ResourceLoader::load(path, type);
|
||||
|
@ -437,7 +422,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
|
|||
r_v = res;
|
||||
}
|
||||
|
||||
|
||||
} break;
|
||||
default: {
|
||||
|
||||
|
@ -551,7 +535,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
|
|||
w = PoolVector<String>::Write();
|
||||
r_v = array;
|
||||
|
||||
|
||||
} break;
|
||||
case VARIANT_VECTOR2_ARRAY: {
|
||||
|
||||
|
@ -642,13 +625,9 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
|
|||
} break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return OK; //never reach anyway
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ResourceInteractiveLoaderBinary::set_local_path(const String &p_local_path) {
|
||||
|
||||
res_path = p_local_path;
|
||||
|
@ -656,7 +635,6 @@ void ResourceInteractiveLoaderBinary::set_local_path(const String& p_local_path)
|
|||
|
||||
Ref<Resource> ResourceInteractiveLoaderBinary::get_resource() {
|
||||
|
||||
|
||||
return resource;
|
||||
}
|
||||
Error ResourceInteractiveLoaderBinary::poll() {
|
||||
|
@ -664,7 +642,6 @@ Error ResourceInteractiveLoaderBinary::poll(){
|
|||
if (error != OK)
|
||||
return error;
|
||||
|
||||
|
||||
int s = stage;
|
||||
|
||||
if (s < external_resources.size()) {
|
||||
|
@ -698,7 +675,6 @@ Error ResourceInteractiveLoaderBinary::poll(){
|
|||
|
||||
s -= external_resources.size();
|
||||
|
||||
|
||||
if (s >= internal_resources.size()) {
|
||||
|
||||
error = ERR_BUG;
|
||||
|
@ -711,8 +687,6 @@ Error ResourceInteractiveLoaderBinary::poll(){
|
|||
String path;
|
||||
int subindex = 0;
|
||||
|
||||
|
||||
|
||||
if (!main) {
|
||||
|
||||
path = internal_resources[s].path;
|
||||
|
@ -722,8 +696,6 @@ Error ResourceInteractiveLoaderBinary::poll(){
|
|||
path = res_path + "::" + path;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (ResourceCache::has(path)) {
|
||||
//already loaded, don't do anything
|
||||
stage++;
|
||||
|
@ -802,7 +774,6 @@ Error ResourceInteractiveLoaderBinary::poll(){
|
|||
}
|
||||
|
||||
return OK;
|
||||
|
||||
}
|
||||
int ResourceInteractiveLoaderBinary::get_stage() const {
|
||||
|
||||
|
@ -813,16 +784,13 @@ int ResourceInteractiveLoaderBinary::get_stage_count() const {
|
|||
return external_resources.size() + internal_resources.size();
|
||||
}
|
||||
|
||||
|
||||
static void save_ustring(FileAccess *f, const String &p_string) {
|
||||
|
||||
|
||||
CharString utf8 = p_string.utf8();
|
||||
f->store_32(utf8.length() + 1);
|
||||
f->store_buffer((const uint8_t *)utf8.get_data(), utf8.length() + 1);
|
||||
}
|
||||
|
||||
|
||||
static String get_ustring(FileAccess *f) {
|
||||
|
||||
int len = f->get_32();
|
||||
|
@ -848,8 +816,6 @@ String ResourceInteractiveLoaderBinary::get_unicode_string() {
|
|||
return s;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ResourceInteractiveLoaderBinary::get_dependencies(FileAccess *p_f, List<String> *p_dependencies, bool p_add_types) {
|
||||
|
||||
open(p_f);
|
||||
|
@ -866,15 +832,10 @@ void ResourceInteractiveLoaderBinary::get_dependencies(FileAccess *p_f,List<Stri
|
|||
|
||||
p_dependencies->push_back(dep);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) {
|
||||
|
||||
|
||||
error = OK;
|
||||
|
||||
f = p_f;
|
||||
|
@ -921,7 +882,6 @@ void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) {
|
|||
f->close();
|
||||
ERR_EXPLAIN("File Format '" + itos(FORMAT_VERSION) + "." + itos(ver_major) + "." + itos(ver_minor) + "' is too new! Please upgrade to a a new engine version: " + local_path);
|
||||
ERR_FAIL();
|
||||
|
||||
}
|
||||
|
||||
type = get_unicode_string();
|
||||
|
@ -949,7 +909,6 @@ void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) {
|
|||
er.type = get_unicode_string();
|
||||
er.path = get_unicode_string();
|
||||
external_resources.push_back(er);
|
||||
|
||||
}
|
||||
|
||||
//see if the exporter has different set of external resources for more efficient loading
|
||||
|
@ -979,21 +938,18 @@ void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) {
|
|||
|
||||
print_bl("int resources: " + itos(int_resources_size));
|
||||
|
||||
|
||||
if (f->eof_reached()) {
|
||||
|
||||
error = ERR_FILE_CORRUPT;
|
||||
ERR_EXPLAIN("Premature End Of File: " + local_path);
|
||||
ERR_FAIL();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
String ResourceInteractiveLoaderBinary::recognize(FileAccess *p_f) {
|
||||
|
||||
error = OK;
|
||||
|
||||
|
||||
f = p_f;
|
||||
uint8_t header[4];
|
||||
f->get_buffer(header, 4);
|
||||
|
@ -1050,7 +1006,6 @@ ResourceInteractiveLoaderBinary::~ResourceInteractiveLoaderBinary() {
|
|||
memdelete(f);
|
||||
}
|
||||
|
||||
|
||||
Ref<ResourceInteractiveLoader> ResourceFormatLoaderBinary::load_interactive(const String &p_path, Error *r_error) {
|
||||
|
||||
if (r_error)
|
||||
|
@ -1070,7 +1025,6 @@ Ref<ResourceInteractiveLoader> ResourceFormatLoaderBinary::load_interactive(cons
|
|||
//ria->set_local_path( Globals::get_singleton()->localize_path(p_path) );
|
||||
ria->open(f);
|
||||
|
||||
|
||||
return ria;
|
||||
}
|
||||
|
||||
|
@ -1090,7 +1044,6 @@ void ResourceFormatLoaderBinary::get_recognized_extensions_for_type(const String
|
|||
String ext = E->get().to_lower();
|
||||
p_extensions->push_back(ext);
|
||||
}
|
||||
|
||||
}
|
||||
void ResourceFormatLoaderBinary::get_recognized_extensions(List<String> *p_extensions) const {
|
||||
|
||||
|
@ -1102,16 +1055,13 @@ void ResourceFormatLoaderBinary::get_recognized_extensions(List<String> *p_exten
|
|||
String ext = E->get().to_lower();
|
||||
p_extensions->push_back(ext);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool ResourceFormatLoaderBinary::handles_type(const String &p_type) const {
|
||||
|
||||
|
||||
return true; //handles all
|
||||
}
|
||||
|
||||
|
||||
void ResourceFormatLoaderBinary::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) {
|
||||
|
||||
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
|
||||
|
@ -1126,10 +1076,8 @@ void ResourceFormatLoaderBinary::get_dependencies(const String& p_path,List<Stri
|
|||
|
||||
Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, const Map<String, String> &p_map) {
|
||||
|
||||
|
||||
//Error error=OK;
|
||||
|
||||
|
||||
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
|
||||
ERR_FAIL_COND_V(!f, ERR_CANT_OPEN);
|
||||
|
||||
|
@ -1156,7 +1104,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path,const
|
|||
|
||||
fw = facw;
|
||||
|
||||
|
||||
} else if (header[0] != 'R' || header[1] != 'S' || header[2] != 'R' || header[3] != 'C') {
|
||||
//not normal
|
||||
|
||||
|
@ -1233,7 +1180,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path,const
|
|||
memdelete(fw);
|
||||
ERR_EXPLAIN("File Format '" + itos(FORMAT_VERSION) + "." + itos(ver_major) + "." + itos(ver_minor) + "' is too new! Please upgrade to a a new engine version: " + local_path);
|
||||
ERR_FAIL_V(ERR_FILE_UNRECOGNIZED);
|
||||
|
||||
}
|
||||
|
||||
fw->store_32(VERSION_MAJOR); //current version
|
||||
|
@ -1242,7 +1188,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path,const
|
|||
|
||||
save_ustring(fw, get_ustring(f)); //type
|
||||
|
||||
|
||||
size_t md_ofs = f->get_pos();
|
||||
size_t importmd_ofs = f->get_64();
|
||||
fw->store_64(0); //metadata offset
|
||||
|
@ -1277,7 +1222,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path,const
|
|||
relative = true;
|
||||
}
|
||||
|
||||
|
||||
if (p_map.has(path)) {
|
||||
String np = p_map[path];
|
||||
path = np;
|
||||
|
@ -1300,7 +1244,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path,const
|
|||
|
||||
for (uint32_t i = 0; i < int_resources_size; i++) {
|
||||
|
||||
|
||||
String path = get_ustring(f);
|
||||
uint64_t offset = f->get_64();
|
||||
save_ustring(fw, path);
|
||||
|
@ -1319,7 +1262,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path,const
|
|||
fw->seek(md_ofs);
|
||||
fw->store_64(importmd_ofs + size_diff);
|
||||
|
||||
|
||||
memdelete(f);
|
||||
memdelete(fw);
|
||||
|
||||
|
@ -1334,7 +1276,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path,const
|
|||
return OK;
|
||||
}
|
||||
|
||||
|
||||
String ResourceFormatLoaderBinary::get_resource_type(const String &p_path) const {
|
||||
|
||||
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
|
||||
|
@ -1348,17 +1289,12 @@ String ResourceFormatLoaderBinary::get_resource_type(const String &p_path) const
|
|||
//ria->set_local_path( Globals::get_singleton()->localize_path(p_path) );
|
||||
String r = ria->recognize(f);
|
||||
return r;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
void ResourceFormatSaverBinaryInstance::_pad_buffer(int p_bytes) {
|
||||
|
||||
int extra = 4 - (p_bytes % 4);
|
||||
|
@ -1366,10 +1302,8 @@ void ResourceFormatSaverBinaryInstance::_pad_buffer(int p_bytes) {
|
|||
for (int i = 0; i < extra; i++)
|
||||
f->store_8(0); //pad to 32
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ResourceFormatSaverBinaryInstance::write_variant(const Variant &p_property, const PropertyInfo &p_hint) {
|
||||
|
||||
switch (p_property.get_type()) {
|
||||
|
@ -1396,13 +1330,11 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
|
|||
f->store_32(VARIANT_INT);
|
||||
int val = p_property;
|
||||
f->store_32(int32_t(val));
|
||||
|
||||
}
|
||||
|
||||
} break;
|
||||
case Variant::REAL: {
|
||||
|
||||
|
||||
double d = p_property;
|
||||
float fl = d;
|
||||
if (double(fl) != d) {
|
||||
|
@ -1412,7 +1344,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
|
|||
|
||||
f->store_32(VARIANT_REAL);
|
||||
f->store_real(fl);
|
||||
|
||||
}
|
||||
|
||||
} break;
|
||||
|
@ -1560,7 +1491,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
|
|||
|
||||
} else if (p_hint.hint == PROPERTY_HINT_IMAGE_COMPRESS_LOSSLESS && Image::lossless_packer) {
|
||||
encoding = IMAGE_ENCODING_LOSSLESS;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1568,7 +1498,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
|
|||
|
||||
if (encoding == IMAGE_ENCODING_RAW) {
|
||||
|
||||
|
||||
f->store_32(val.get_width());
|
||||
f->store_32(val.get_height());
|
||||
f->store_32(val.has_mipmaps());
|
||||
|
@ -1587,7 +1516,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
|
|||
|
||||
} else if (encoding == IMAGE_ENCODING_LOSSLESS) {
|
||||
data = Image::lossless_packer(val);
|
||||
|
||||
}
|
||||
|
||||
int ds = data.size();
|
||||
|
@ -1597,7 +1525,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
|
|||
f->store_buffer(r.ptr(), ds);
|
||||
|
||||
_pad_buffer(ds);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1649,7 +1576,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
|
|||
//internal resource
|
||||
}
|
||||
|
||||
|
||||
} break;
|
||||
case Variant::INPUT_EVENT: {
|
||||
|
||||
|
@ -1678,7 +1604,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
|
|||
write_variant(d[E->get()]);
|
||||
}
|
||||
|
||||
|
||||
} break;
|
||||
case Variant::ARRAY: {
|
||||
|
||||
|
@ -1787,14 +1712,11 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant, bool p_main) {
|
||||
|
||||
|
||||
switch (p_variant.get_type()) {
|
||||
case Variant::OBJECT: {
|
||||
|
||||
|
||||
RES res = p_variant.operator RefPtr();
|
||||
|
||||
if (res.is_null() || external_resources.has(res))
|
||||
|
@ -1806,7 +1728,6 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant& p_variant
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
if (resource_set.has(res))
|
||||
return;
|
||||
|
||||
|
@ -1860,12 +1781,10 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant& p_variant
|
|||
get_string_index(np.get_subname(i));
|
||||
get_string_index(np.get_property());
|
||||
|
||||
|
||||
} break;
|
||||
|
||||
default: {}
|
||||
}
|
||||
|
||||
}
|
||||
#if 0
|
||||
Error ResourceFormatSaverBinary::_save_obj(const Object *p_object,SavedObject *so) {
|
||||
|
@ -1918,7 +1837,6 @@ Error ResourceFormatSaverBinary::save(const Object *p_object,const Variant &p_me
|
|||
|
||||
void ResourceFormatSaverBinaryInstance::save_unicode_string(const String &p_string) {
|
||||
|
||||
|
||||
CharString utf8 = p_string.utf8();
|
||||
f->store_32(utf8.length() + 1);
|
||||
f->store_buffer((const uint8_t *)utf8.get_data(), utf8.length() + 1);
|
||||
|
@ -1935,7 +1853,6 @@ int ResourceFormatSaverBinaryInstance::get_string_index(const String& p_string)
|
|||
return strings.size() - 1;
|
||||
}
|
||||
|
||||
|
||||
Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {
|
||||
|
||||
Error err;
|
||||
|
@ -1951,11 +1868,9 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path,const RES& p_
|
|||
f = FileAccess::open(p_path, FileAccess::WRITE, &err);
|
||||
}
|
||||
|
||||
|
||||
ERR_FAIL_COND_V(err, err);
|
||||
FileAccessRef _fref(f);
|
||||
|
||||
|
||||
relative_paths = p_flags & ResourceSaver::FLAG_RELATIVE_PATHS;
|
||||
skip_editor = p_flags & ResourceSaver::FLAG_OMIT_EDITOR_PROPERTIES;
|
||||
bundle_resources = p_flags & ResourceSaver::FLAG_BUNDLE_RESOURCES;
|
||||
|
@ -1999,16 +1914,12 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path,const RES& p_
|
|||
for (int i = 0; i < 14; i++)
|
||||
f->store_32(0); // reserved
|
||||
|
||||
|
||||
List<ResourceData> resources;
|
||||
|
||||
|
||||
{
|
||||
|
||||
|
||||
for (List<RES>::Element *E = saved_resources.front(); E; E = E->next()) {
|
||||
|
||||
|
||||
ResourceData &rd = resources.push_back(ResourceData())->get();
|
||||
rd.type = E->get()->get_class();
|
||||
|
||||
|
@ -2028,16 +1939,11 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path,const RES& p_
|
|||
p.pi = F->get();
|
||||
|
||||
rd.properties.push_back(p);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
f->store_32(strings.size()); //string table size
|
||||
for (int i = 0; i < strings.size(); i++) {
|
||||
//print_bl("saving string: "+strings[i]);
|
||||
|
@ -2078,13 +1984,10 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path,const RES& p_
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
for (List<RES>::Element *E = saved_resources.front(); E; E = E->next()) {
|
||||
|
||||
|
||||
RES r = E->get();
|
||||
if (r->get_path() == "" || r->get_path().find("::") != -1) {
|
||||
if (r->get_subindex() == 0) {
|
||||
|
@ -2095,7 +1998,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path,const RES& p_
|
|||
|
||||
r->set_subindex(new_subindex);
|
||||
used_indices.insert(new_subindex);
|
||||
|
||||
}
|
||||
|
||||
save_unicode_string("local://" + itos(r->get_subindex()));
|
||||
|
@ -2130,7 +2032,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path,const RES& p_
|
|||
f->store_32(p.name_idx);
|
||||
write_variant(p.value, F->get().pi);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (int i = 0; i < ofs_table.size(); i++) {
|
||||
|
@ -2140,7 +2041,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path,const RES& p_
|
|||
|
||||
f->seek_end();
|
||||
|
||||
|
||||
f->store_buffer((const uint8_t *)"RSRC", 4); //magic at end
|
||||
|
||||
if (f->get_error() != OK && f->get_error() != ERR_FILE_EOF) {
|
||||
|
@ -2150,26 +2050,19 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path,const RES& p_
|
|||
|
||||
f->close();
|
||||
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Error ResourceFormatSaverBinary::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {
|
||||
|
||||
|
||||
String local_path = GlobalConfig::get_singleton()->localize_path(p_path);
|
||||
ResourceFormatSaverBinaryInstance saver;
|
||||
return saver.save(local_path, p_resource, p_flags);
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool ResourceFormatSaverBinary::recognize(const RES &p_resource) const {
|
||||
|
||||
return true; //all recognized
|
||||
|
||||
}
|
||||
|
||||
void ResourceFormatSaverBinary::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const {
|
||||
|
@ -2178,7 +2071,6 @@ void ResourceFormatSaverBinary::get_recognized_extensions(const RES& p_resource,
|
|||
p_extensions->push_back(base);
|
||||
if (base != "res")
|
||||
p_extensions->push_back("res");
|
||||
|
||||
}
|
||||
|
||||
ResourceFormatSaverBinary *ResourceFormatSaverBinary::singleton = NULL;
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
#include "io/resource_saver.h"
|
||||
#include "os/file_access.h"
|
||||
|
||||
|
||||
class ResourceInteractiveLoaderBinary : public ResourceInteractiveLoader {
|
||||
|
||||
String local_path;
|
||||
|
@ -43,7 +42,6 @@ class ResourceInteractiveLoaderBinary : public ResourceInteractiveLoader {
|
|||
|
||||
FileAccess *f;
|
||||
|
||||
|
||||
bool endian_swap;
|
||||
bool use_real64;
|
||||
uint64_t importmd_ofs;
|
||||
|
@ -80,11 +78,9 @@ class ResourceInteractiveLoaderBinary : public ResourceInteractiveLoader {
|
|||
|
||||
friend class ResourceFormatLoaderBinary;
|
||||
|
||||
|
||||
Error parse_variant(Variant &r_v);
|
||||
|
||||
public:
|
||||
|
||||
virtual void set_local_path(const String &p_local_path);
|
||||
virtual Ref<Resource> get_resource();
|
||||
virtual Error poll();
|
||||
|
@ -96,15 +92,12 @@ public:
|
|||
String recognize(FileAccess *p_f);
|
||||
void get_dependencies(FileAccess *p_f, List<String> *p_dependencies, bool p_add_types);
|
||||
|
||||
|
||||
ResourceInteractiveLoaderBinary();
|
||||
~ResourceInteractiveLoaderBinary();
|
||||
|
||||
};
|
||||
|
||||
class ResourceFormatLoaderBinary : public ResourceFormatLoader {
|
||||
public:
|
||||
|
||||
virtual Ref<ResourceInteractiveLoader> load_interactive(const String &p_path, Error *r_error = NULL);
|
||||
virtual void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const;
|
||||
virtual void get_recognized_extensions(List<String> *p_extensions) const;
|
||||
|
@ -112,19 +105,12 @@ public:
|
|||
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);
|
||||
virtual Error rename_dependencies(const String &p_path, const Map<String, String> &p_map);
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class ResourceFormatSaverBinaryInstance {
|
||||
|
||||
String local_path;
|
||||
|
||||
|
||||
bool relative_paths;
|
||||
bool bundle_resources;
|
||||
bool skip_editor;
|
||||
|
@ -137,16 +123,13 @@ class ResourceFormatSaverBinaryInstance {
|
|||
Map<StringName, int> string_map;
|
||||
Vector<StringName> strings;
|
||||
|
||||
|
||||
Map<RES, int> external_resources;
|
||||
List<RES> saved_resources;
|
||||
|
||||
|
||||
struct Property {
|
||||
int name_idx;
|
||||
Variant value;
|
||||
PropertyInfo pi;
|
||||
|
||||
};
|
||||
|
||||
struct ResourceData {
|
||||
|
@ -155,29 +138,19 @@ class ResourceFormatSaverBinaryInstance {
|
|||
List<Property> properties;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
void _pad_buffer(int p_bytes);
|
||||
void write_variant(const Variant &p_property, const PropertyInfo &p_hint = PropertyInfo());
|
||||
void _find_resources(const Variant &p_variant, bool p_main = false);
|
||||
void save_unicode_string(const String &p_string);
|
||||
int get_string_index(const String &p_string);
|
||||
|
||||
public:
|
||||
|
||||
|
||||
Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0);
|
||||
};
|
||||
|
||||
|
||||
|
||||
class ResourceFormatSaverBinary : public ResourceFormatSaver {
|
||||
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
||||
static ResourceFormatSaverBinary *singleton;
|
||||
virtual Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0);
|
||||
virtual bool recognize(const RES &p_resource) const;
|
||||
|
@ -186,5 +159,4 @@ public:
|
|||
ResourceFormatSaverBinary();
|
||||
};
|
||||
|
||||
|
||||
#endif // RESOURCE_FORMAT_BINARY_H
|
||||
|
|
|
@ -28,8 +28,8 @@
|
|||
/*************************************************************************/
|
||||
#include "resource_import.h"
|
||||
|
||||
#include "variant_parser.h"
|
||||
#include "os/os.h"
|
||||
#include "variant_parser.h"
|
||||
|
||||
Error ResourceFormatImporter::_get_path_and_type(const String &p_path, PathAndType &r_path_and_type) const {
|
||||
|
||||
|
@ -58,8 +58,7 @@ Error ResourceFormatImporter::_get_path_and_type(const String& p_path, PathAndTy
|
|||
if (err == ERR_FILE_EOF) {
|
||||
memdelete(f);
|
||||
return OK;
|
||||
}
|
||||
else if (err!=OK) {
|
||||
} else if (err != OK) {
|
||||
ERR_PRINTS("ResourceFormatImporter::load - " + p_path + ".import:" + itos(lines) + " error: " + error_text);
|
||||
memdelete(f);
|
||||
return err;
|
||||
|
@ -89,10 +88,8 @@ Error ResourceFormatImporter::_get_path_and_type(const String& p_path, PathAndTy
|
|||
return ERR_FILE_CORRUPT;
|
||||
}
|
||||
return OK;
|
||||
|
||||
}
|
||||
|
||||
|
||||
RES ResourceFormatImporter::load(const String &p_path, const String &p_original_path, Error *r_error) {
|
||||
|
||||
PathAndType pat;
|
||||
|
@ -106,7 +103,6 @@ RES ResourceFormatImporter::load(const String &p_path,const String& p_original_p
|
|||
return RES();
|
||||
}
|
||||
|
||||
|
||||
RES res = ResourceLoader::load(pat.path, pat.type, false, r_error);
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
@ -117,7 +113,6 @@ RES ResourceFormatImporter::load(const String &p_path,const String& p_original_p
|
|||
#endif
|
||||
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
void ResourceFormatImporter::get_recognized_extensions(List<String> *p_extensions) const {
|
||||
|
@ -166,7 +161,6 @@ void ResourceFormatImporter::get_recognized_extensions_for_type(const String& p_
|
|||
bool ResourceFormatImporter::recognize_path(const String &p_path, const String &p_for_type) const {
|
||||
|
||||
return FileAccess::exists(p_path + ".import");
|
||||
|
||||
}
|
||||
|
||||
bool ResourceFormatImporter::can_be_imported(const String &p_path) const {
|
||||
|
@ -174,7 +168,6 @@ bool ResourceFormatImporter::can_be_imported(const String& p_path) const {
|
|||
return ResourceFormatLoader::recognize_path(p_path);
|
||||
}
|
||||
|
||||
|
||||
bool ResourceFormatImporter::handles_type(const String &p_type) const {
|
||||
|
||||
for (Set<Ref<ResourceImporter> >::Element *E = importers.front(); E; E = E->next()) {
|
||||
|
@ -184,13 +177,11 @@ bool ResourceFormatImporter::handles_type(const String& p_type) const {
|
|||
continue;
|
||||
if (ClassDB::is_parent_class(res_type, p_type))
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
String ResourceFormatImporter::get_internal_resource_path(const String &p_path) const {
|
||||
|
||||
PathAndType pat;
|
||||
|
@ -241,7 +232,6 @@ Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_name(const String&
|
|||
return Ref<ResourceImporter>();
|
||||
}
|
||||
|
||||
|
||||
void ResourceFormatImporter::get_importers_for_extension(const String &p_extension, List<Ref<ResourceImporter> > *r_importers) {
|
||||
|
||||
for (Set<Ref<ResourceImporter> >::Element *E = importers.front(); E; E = E->next()) {
|
||||
|
@ -257,7 +247,6 @@ void ResourceFormatImporter::get_importers_for_extension(const String& p_extensi
|
|||
|
||||
Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_extension(const String &p_extension) {
|
||||
|
||||
|
||||
Ref<ResourceImporter> importer;
|
||||
float priority = 0;
|
||||
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
#ifndef RESOURCE_IMPORT_H
|
||||
#define RESOURCE_IMPORT_H
|
||||
|
||||
|
||||
#include "io/resource_loader.h"
|
||||
class ResourceImporter;
|
||||
|
||||
|
@ -40,14 +39,13 @@ class ResourceFormatImporter : public ResourceFormatLoader {
|
|||
String type;
|
||||
};
|
||||
|
||||
|
||||
Error _get_path_and_type(const String &p_path, PathAndType &r_path_and_type) const;
|
||||
|
||||
static ResourceFormatImporter *singleton;
|
||||
|
||||
Set<Ref<ResourceImporter> > importers;
|
||||
public:
|
||||
|
||||
public:
|
||||
static ResourceFormatImporter *get_singleton() { return singleton; }
|
||||
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL);
|
||||
virtual void get_recognized_extensions(List<String> *p_extensions) const;
|
||||
|
@ -70,7 +68,6 @@ public:
|
|||
ResourceFormatImporter();
|
||||
};
|
||||
|
||||
|
||||
class ResourceImporter : public Reference {
|
||||
|
||||
GDCLASS(ResourceImporter, Reference)
|
||||
|
@ -86,20 +83,20 @@ public:
|
|||
PropertyInfo option;
|
||||
Variant default_value;
|
||||
|
||||
ImportOption(const PropertyInfo& p_info,const Variant& p_default) { option=p_info; default_value=p_default; }
|
||||
ImportOption(const PropertyInfo &p_info, const Variant &p_default) {
|
||||
option = p_info;
|
||||
default_value = p_default;
|
||||
}
|
||||
ImportOption() {}
|
||||
};
|
||||
|
||||
|
||||
virtual int get_preset_count() const { return 0; }
|
||||
virtual String get_preset_name(int p_idx) const { return String(); }
|
||||
|
||||
virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const = 0;
|
||||
virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const = 0;
|
||||
|
||||
|
||||
virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL) = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif // RESOURCE_IMPORT_H
|
||||
|
|
|
@ -27,16 +27,15 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "resource_loader.h"
|
||||
#include "print_string.h"
|
||||
#include "global_config.h"
|
||||
#include "path_remap.h"
|
||||
#include "os/file_access.h"
|
||||
#include "os/os.h"
|
||||
#include "path_remap.h"
|
||||
#include "print_string.h"
|
||||
ResourceFormatLoader *ResourceLoader::loader[MAX_LOADERS];
|
||||
|
||||
int ResourceLoader::loader_count = 0;
|
||||
|
||||
|
||||
Error ResourceInteractiveLoader::wait() {
|
||||
|
||||
Error err = poll();
|
||||
|
@ -49,7 +48,6 @@ Error ResourceInteractiveLoader::wait() {
|
|||
|
||||
bool ResourceFormatLoader::recognize_path(const String &p_path, const String &p_for_type) const {
|
||||
|
||||
|
||||
String extension = p_path.get_extension();
|
||||
|
||||
List<String> extensions;
|
||||
|
@ -61,16 +59,13 @@ bool ResourceFormatLoader::recognize_path(const String& p_path,const String& p_f
|
|||
|
||||
for (List<String>::Element *E = extensions.front(); E; E = E->next()) {
|
||||
|
||||
|
||||
if (E->get().nocasecmp_to(extension) == 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ResourceFormatLoader::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const {
|
||||
|
||||
if (p_type == "" || handles_type(p_type))
|
||||
|
@ -82,7 +77,6 @@ void ResourceLoader::get_recognized_extensions_for_type(const String& p_type,Lis
|
|||
for (int i = 0; i < loader_count; i++) {
|
||||
loader[i]->get_recognized_extensions_for_type(p_type, p_extensions);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ResourceInteractiveLoader::_bind_methods() {
|
||||
|
@ -97,11 +91,12 @@ void ResourceInteractiveLoader::_bind_methods() {
|
|||
class ResourceInteractiveLoaderDefault : public ResourceInteractiveLoader {
|
||||
|
||||
GDCLASS(ResourceInteractiveLoaderDefault, ResourceInteractiveLoader);
|
||||
public:
|
||||
|
||||
public:
|
||||
Ref<Resource> resource;
|
||||
|
||||
virtual void set_local_path(const String& p_local_path) { /*scene->set_filename(p_local_path);*/ }
|
||||
virtual void set_local_path(const String &p_local_path) { /*scene->set_filename(p_local_path);*/
|
||||
}
|
||||
virtual Ref<Resource> get_resource() { return resource; }
|
||||
virtual Error poll() { return ERR_FILE_EOF; }
|
||||
virtual int get_stage() const { return 1; }
|
||||
|
@ -110,8 +105,6 @@ public:
|
|||
ResourceInteractiveLoaderDefault() {}
|
||||
};
|
||||
|
||||
|
||||
|
||||
Ref<ResourceInteractiveLoader> ResourceFormatLoader::load_interactive(const String &p_path, Error *r_error) {
|
||||
|
||||
//either this
|
||||
|
@ -126,7 +119,6 @@ Ref<ResourceInteractiveLoader> ResourceFormatLoader::load_interactive(const Stri
|
|||
|
||||
RES ResourceFormatLoader::load(const String &p_path, const String &p_original_path, Error *r_error) {
|
||||
|
||||
|
||||
String path = p_path;
|
||||
|
||||
//or this must be implemented
|
||||
|
@ -152,7 +144,6 @@ RES ResourceFormatLoader::load(const String &p_path, const String& p_original_pa
|
|||
}
|
||||
|
||||
return RES();
|
||||
|
||||
}
|
||||
|
||||
void ResourceFormatLoader::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) {
|
||||
|
@ -160,10 +151,8 @@ void ResourceFormatLoader::get_dependencies(const String& p_path, List<String> *
|
|||
//do nothing by default
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////
|
||||
|
||||
|
||||
RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p_no_cache, Error *r_error) {
|
||||
|
||||
if (r_error)
|
||||
|
@ -175,7 +164,6 @@ RES ResourceLoader::load(const String &p_path, const String& p_type_hint, bool p
|
|||
else
|
||||
local_path = GlobalConfig::get_singleton()->localize_path(p_path);
|
||||
|
||||
|
||||
ERR_FAIL_COND_V(local_path == "", RES());
|
||||
|
||||
if (!p_no_cache && ResourceCache::has(local_path)) {
|
||||
|
@ -225,11 +213,8 @@ RES ResourceLoader::load(const String &p_path, const String& p_type_hint, bool p
|
|||
return RES();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_path, const String &p_type_hint, bool p_no_cache, Error *r_error) {
|
||||
|
||||
|
||||
if (r_error)
|
||||
*r_error = ERR_CANT_OPEN;
|
||||
|
||||
|
@ -239,11 +224,8 @@ Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_
|
|||
else
|
||||
local_path = GlobalConfig::get_singleton()->localize_path(p_path);
|
||||
|
||||
|
||||
ERR_FAIL_COND_V(local_path == "", Ref<ResourceInteractiveLoader>());
|
||||
|
||||
|
||||
|
||||
if (!p_no_cache && ResourceCache::has(local_path)) {
|
||||
|
||||
if (OS::get_singleton()->is_stdout_verbose())
|
||||
|
@ -282,7 +264,6 @@ Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_
|
|||
}
|
||||
ERR_FAIL_V(Ref<ResourceInteractiveLoader>());
|
||||
return Ref<ResourceInteractiveLoader>();
|
||||
|
||||
}
|
||||
|
||||
void ResourceLoader::add_resource_format_loader(ResourceFormatLoader *p_format_loader, bool p_at_front) {
|
||||
|
@ -301,7 +282,6 @@ void ResourceLoader::add_resource_format_loader(ResourceFormatLoader *p_format_l
|
|||
|
||||
void ResourceLoader::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) {
|
||||
|
||||
|
||||
String local_path;
|
||||
if (p_path.is_rel_path())
|
||||
local_path = "res://" + p_path;
|
||||
|
@ -318,20 +298,17 @@ void ResourceLoader::get_dependencies(const String& p_path, List<String> *p_depe
|
|||
*/
|
||||
|
||||
loader[i]->get_dependencies(local_path, p_dependencies, p_add_types);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Error ResourceLoader::rename_dependencies(const String &p_path, const Map<String, String> &p_map) {
|
||||
|
||||
|
||||
String local_path;
|
||||
if (p_path.is_rel_path())
|
||||
local_path = "res://" + p_path;
|
||||
else
|
||||
local_path = GlobalConfig::get_singleton()->localize_path(p_path);
|
||||
|
||||
|
||||
for (int i = 0; i < loader_count; i++) {
|
||||
|
||||
if (!loader[i]->recognize_path(local_path))
|
||||
|
@ -342,15 +319,11 @@ Error ResourceLoader::rename_dependencies(const String &p_path,const Map<String,
|
|||
*/
|
||||
|
||||
return loader[i]->rename_dependencies(local_path, p_map);
|
||||
|
||||
}
|
||||
|
||||
return OK; // ??
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
String ResourceLoader::get_resource_type(const String &p_path) {
|
||||
|
||||
String local_path;
|
||||
|
@ -359,7 +332,6 @@ String ResourceLoader::get_resource_type(const String &p_path) {
|
|||
else
|
||||
local_path = GlobalConfig::get_singleton()->localize_path(p_path);
|
||||
|
||||
|
||||
for (int i = 0; i < loader_count; i++) {
|
||||
|
||||
String result = loader[i]->get_resource_type(local_path);
|
||||
|
@ -368,7 +340,6 @@ String ResourceLoader::get_resource_type(const String &p_path) {
|
|||
}
|
||||
|
||||
return "";
|
||||
|
||||
}
|
||||
ResourceLoadErrorNotify ResourceLoader::err_notify = NULL;
|
||||
void *ResourceLoader::err_notify_ud = NULL;
|
||||
|
@ -378,4 +349,3 @@ void *ResourceLoader::dep_err_notify_ud=NULL;
|
|||
|
||||
bool ResourceLoader::abort_on_missing_resource = true;
|
||||
bool ResourceLoader::timestamp_on_load = false;
|
||||
|
||||
|
|
|
@ -38,11 +38,11 @@
|
|||
class ResourceInteractiveLoader : public Reference {
|
||||
|
||||
GDCLASS(ResourceInteractiveLoader, Reference);
|
||||
|
||||
protected:
|
||||
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
||||
public:
|
||||
virtual void set_local_path(const String &p_local_path) = 0;
|
||||
virtual Ref<Resource> get_resource() = 0;
|
||||
virtual Error poll() = 0;
|
||||
|
@ -53,10 +53,8 @@ public:
|
|||
ResourceInteractiveLoader() {}
|
||||
};
|
||||
|
||||
|
||||
class ResourceFormatLoader {
|
||||
public:
|
||||
|
||||
virtual Ref<ResourceInteractiveLoader> load_interactive(const String &p_path, Error *r_error = NULL);
|
||||
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL);
|
||||
virtual void get_recognized_extensions(List<String> *p_extensions) const = 0;
|
||||
|
@ -70,11 +68,9 @@ public:
|
|||
virtual ~ResourceFormatLoader() {}
|
||||
};
|
||||
|
||||
|
||||
typedef void (*ResourceLoadErrorNotify)(void *p_ud, const String &p_text);
|
||||
typedef void (*DependencyErrorNotify)(void *p_ud, const String &p_loading, const String &p_which, const String &p_type);
|
||||
|
||||
|
||||
class ResourceLoader {
|
||||
|
||||
enum {
|
||||
|
@ -92,9 +88,6 @@ class ResourceLoader {
|
|||
static bool abort_on_missing_resource;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
static Ref<ResourceInteractiveLoader> load_interactive(const String &p_path, const String &p_type_hint = "", bool p_no_cache = false, Error *r_error = NULL);
|
||||
static RES load(const String &p_path, const String &p_type_hint = "", bool p_no_cache = false, Error *r_error = NULL);
|
||||
|
||||
|
@ -106,17 +99,24 @@ public:
|
|||
|
||||
static void set_timestamp_on_load(bool p_timestamp) { timestamp_on_load = p_timestamp; }
|
||||
|
||||
static void notify_load_error(const String& p_err) { if (err_notify) err_notify(err_notify_ud,p_err); }
|
||||
static void set_error_notify_func(void* p_ud,ResourceLoadErrorNotify p_err_notify) { err_notify=p_err_notify; err_notify_ud=p_ud;}
|
||||
|
||||
static void notify_dependency_error(const String& p_path,const String& p_dependency,const String& p_type) { if (dep_err_notify) dep_err_notify(dep_err_notify_ud,p_path,p_dependency,p_type); }
|
||||
static void set_dependency_error_notify_func(void* p_ud,DependencyErrorNotify p_err_notify) { dep_err_notify=p_err_notify; dep_err_notify_ud=p_ud;}
|
||||
static void notify_load_error(const String &p_err) {
|
||||
if (err_notify) err_notify(err_notify_ud, p_err);
|
||||
}
|
||||
static void set_error_notify_func(void *p_ud, ResourceLoadErrorNotify p_err_notify) {
|
||||
err_notify = p_err_notify;
|
||||
err_notify_ud = p_ud;
|
||||
}
|
||||
|
||||
static void notify_dependency_error(const String &p_path, const String &p_dependency, const String &p_type) {
|
||||
if (dep_err_notify) dep_err_notify(dep_err_notify_ud, p_path, p_dependency, p_type);
|
||||
}
|
||||
static void set_dependency_error_notify_func(void *p_ud, DependencyErrorNotify p_err_notify) {
|
||||
dep_err_notify = p_err_notify;
|
||||
dep_err_notify_ud = p_ud;
|
||||
}
|
||||
|
||||
static void set_abort_on_missing_resources(bool p_abort) { abort_on_missing_resource = p_abort; }
|
||||
static bool get_abort_on_missing_resources() { return abort_on_missing_resource; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -29,8 +29,8 @@
|
|||
#include "resource_saver.h"
|
||||
#include "global_config.h"
|
||||
#include "os/file_access.h"
|
||||
#include "script_language.h"
|
||||
#include "resource_loader.h"
|
||||
#include "script_language.h"
|
||||
|
||||
ResourceFormatSaver *ResourceSaver::saver[MAX_SAVERS];
|
||||
|
||||
|
@ -63,7 +63,6 @@ Error ResourceSaver::save(const String &p_path,const RES& p_resource,uint32_t p_
|
|||
|
||||
String old_path = p_resource->get_path();
|
||||
|
||||
|
||||
String local_path = GlobalConfig::get_singleton()->localize_path(p_path);
|
||||
|
||||
RES rwcopy = p_resource;
|
||||
|
@ -92,28 +91,23 @@ Error ResourceSaver::save(const String &p_path,const RES& p_resource,uint32_t p_
|
|||
|
||||
return OK;
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
void ResourceSaver::set_save_callback(ResourceSavedCallback p_callback) {
|
||||
|
||||
save_callback = p_callback;
|
||||
}
|
||||
|
||||
|
||||
void ResourceSaver::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) {
|
||||
|
||||
|
||||
for (int i = 0; i < saver_count; i++) {
|
||||
|
||||
saver[i]->get_recognized_extensions(p_resource, p_extensions);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ResourceSaver::add_resource_format_saver(ResourceFormatSaver *p_format_saver, bool p_at_front) {
|
||||
|
@ -129,9 +123,4 @@ void ResourceSaver::add_resource_format_saver(ResourceFormatSaver *p_format_save
|
|||
} else {
|
||||
saver[saver_count++] = p_format_saver;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -35,14 +35,8 @@
|
|||
@author Juan Linietsky <reduzio@gmail.com>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class ResourceFormatSaver {
|
||||
public:
|
||||
|
||||
virtual Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0) = 0;
|
||||
virtual bool recognize(const RES &p_resource) const = 0;
|
||||
virtual void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const = 0;
|
||||
|
@ -63,9 +57,7 @@ class ResourceSaver {
|
|||
static bool timestamp_on_save;
|
||||
static ResourceSavedCallback save_callback;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
enum SaverFlags {
|
||||
|
||||
FLAG_RELATIVE_PATHS = 1,
|
||||
|
@ -77,17 +69,12 @@ public:
|
|||
FLAG_REPLACE_SUBRESOURCE_PATHS = 64,
|
||||
};
|
||||
|
||||
|
||||
static Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0);
|
||||
static void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions);
|
||||
static void add_resource_format_saver(ResourceFormatSaver *p_format_saver, bool p_at_front = false);
|
||||
|
||||
static void set_timestamp_on_save(bool p_timestamp) { timestamp_on_save = p_timestamp; }
|
||||
static void set_save_callback(ResourceSavedCallback p_callback);
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -61,7 +61,6 @@ Array StreamPeer::_put_partial_data(const PoolVector<uint8_t>& p_data) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Array StreamPeer::_get_data(int p_bytes) {
|
||||
|
||||
Array ret;
|
||||
|
@ -81,7 +80,6 @@ Array StreamPeer::_get_data(int p_bytes) {
|
|||
ret.push_back(err);
|
||||
ret.push_back(data);
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
Array StreamPeer::_get_partial_data(int p_bytes) {
|
||||
|
@ -112,7 +110,6 @@ Array StreamPeer::_get_partial_data(int p_bytes) {
|
|||
ret.push_back(err);
|
||||
ret.push_back(data);
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
void StreamPeer::set_big_endian(bool p_enable) {
|
||||
|
@ -125,10 +122,8 @@ bool StreamPeer::is_big_endian_enabled() const {
|
|||
return big_endian;
|
||||
}
|
||||
|
||||
|
||||
void StreamPeer::put_u8(uint8_t p_val) {
|
||||
put_data((const uint8_t *)&p_val, 1);
|
||||
|
||||
}
|
||||
|
||||
void StreamPeer::put_8(int8_t p_val) {
|
||||
|
@ -143,7 +138,6 @@ void StreamPeer::put_u16(uint16_t p_val){
|
|||
uint8_t buf[2];
|
||||
encode_uint16(p_val, buf);
|
||||
put_data(buf, 2);
|
||||
|
||||
}
|
||||
void StreamPeer::put_16(int16_t p_val) {
|
||||
|
||||
|
@ -153,7 +147,6 @@ void StreamPeer::put_16(int16_t p_val){
|
|||
uint8_t buf[2];
|
||||
encode_uint16(p_val, buf);
|
||||
put_data(buf, 2);
|
||||
|
||||
}
|
||||
void StreamPeer::put_u32(uint32_t p_val) {
|
||||
|
||||
|
@ -163,7 +156,6 @@ void StreamPeer::put_u32(uint32_t p_val){
|
|||
uint8_t buf[4];
|
||||
encode_uint32(p_val, buf);
|
||||
put_data(buf, 4);
|
||||
|
||||
}
|
||||
void StreamPeer::put_32(int32_t p_val) {
|
||||
|
||||
|
@ -173,7 +165,6 @@ void StreamPeer::put_32(int32_t p_val){
|
|||
uint8_t buf[4];
|
||||
encode_uint32(p_val, buf);
|
||||
put_data(buf, 4);
|
||||
|
||||
}
|
||||
void StreamPeer::put_u64(uint64_t p_val) {
|
||||
|
||||
|
@ -183,7 +174,6 @@ void StreamPeer::put_u64(uint64_t p_val){
|
|||
uint8_t buf[8];
|
||||
encode_uint64(p_val, buf);
|
||||
put_data(buf, 8);
|
||||
|
||||
}
|
||||
void StreamPeer::put_64(int64_t p_val) {
|
||||
|
||||
|
@ -193,7 +183,6 @@ void StreamPeer::put_64(int64_t p_val){
|
|||
uint8_t buf[8];
|
||||
encode_uint64(p_val, buf);
|
||||
put_data(buf, 8);
|
||||
|
||||
}
|
||||
void StreamPeer::put_float(float p_val) {
|
||||
|
||||
|
@ -206,7 +195,6 @@ void StreamPeer::put_float(float p_val){
|
|||
}
|
||||
|
||||
put_data(buf, 4);
|
||||
|
||||
}
|
||||
void StreamPeer::put_double(double p_val) {
|
||||
|
||||
|
@ -217,14 +205,12 @@ void StreamPeer::put_double(double p_val){
|
|||
*p64 = BSWAP64(*p64);
|
||||
}
|
||||
put_data(buf, 8);
|
||||
|
||||
}
|
||||
void StreamPeer::put_utf8_string(const String &p_string) {
|
||||
|
||||
CharString cs = p_string.utf8();
|
||||
put_u32(p_string.length());
|
||||
put_data((const uint8_t *)cs.get_data(), cs.length());
|
||||
|
||||
}
|
||||
void StreamPeer::put_var(const Variant &p_variant) {
|
||||
|
||||
|
@ -235,8 +221,6 @@ void StreamPeer::put_var(const Variant& p_variant){
|
|||
put_32(len);
|
||||
encode_variant(p_variant, buf.ptr(), len);
|
||||
put_data(buf.ptr(), buf.size());
|
||||
|
||||
|
||||
}
|
||||
|
||||
uint8_t StreamPeer::get_u8() {
|
||||
|
@ -250,7 +234,6 @@ int8_t StreamPeer::get_8(){
|
|||
uint8_t buf[1];
|
||||
get_data(buf, 1);
|
||||
return buf[0];
|
||||
|
||||
}
|
||||
uint16_t StreamPeer::get_u16() {
|
||||
|
||||
|
@ -261,7 +244,6 @@ uint16_t StreamPeer::get_u16(){
|
|||
r = BSWAP16(r);
|
||||
}
|
||||
return r;
|
||||
|
||||
}
|
||||
int16_t StreamPeer::get_16() {
|
||||
|
||||
|
@ -272,7 +254,6 @@ int16_t StreamPeer::get_16(){
|
|||
r = BSWAP16(r);
|
||||
}
|
||||
return r;
|
||||
|
||||
}
|
||||
uint32_t StreamPeer::get_u32() {
|
||||
|
||||
|
@ -283,7 +264,6 @@ uint32_t StreamPeer::get_u32(){
|
|||
r = BSWAP32(r);
|
||||
}
|
||||
return r;
|
||||
|
||||
}
|
||||
int32_t StreamPeer::get_32() {
|
||||
|
||||
|
@ -294,7 +274,6 @@ int32_t StreamPeer::get_32(){
|
|||
r = BSWAP32(r);
|
||||
}
|
||||
return r;
|
||||
|
||||
}
|
||||
uint64_t StreamPeer::get_u64() {
|
||||
|
||||
|
@ -305,7 +284,6 @@ uint64_t StreamPeer::get_u64(){
|
|||
r = BSWAP64(r);
|
||||
}
|
||||
return r;
|
||||
|
||||
}
|
||||
int64_t StreamPeer::get_64() {
|
||||
|
||||
|
@ -316,7 +294,6 @@ int64_t StreamPeer::get_64(){
|
|||
r = BSWAP64(r);
|
||||
}
|
||||
return r;
|
||||
|
||||
}
|
||||
float StreamPeer::get_float() {
|
||||
|
||||
|
@ -342,7 +319,6 @@ float StreamPeer::get_double(){
|
|||
}
|
||||
|
||||
return decode_double(buf);
|
||||
|
||||
}
|
||||
String StreamPeer::get_string(int p_bytes) {
|
||||
|
||||
|
@ -355,7 +331,6 @@ String StreamPeer::get_string(int p_bytes){
|
|||
ERR_FAIL_COND_V(err != OK, String());
|
||||
buf[p_bytes] = 0;
|
||||
return buf.ptr();
|
||||
|
||||
}
|
||||
String StreamPeer::get_utf8_string(int p_bytes) {
|
||||
|
||||
|
@ -370,7 +345,6 @@ String StreamPeer::get_utf8_string(int p_bytes){
|
|||
String ret;
|
||||
ret.parse_utf8((const char *)buf.ptr(), buf.size());
|
||||
return ret;
|
||||
|
||||
}
|
||||
Variant StreamPeer::get_var() {
|
||||
|
||||
|
@ -386,7 +360,6 @@ Variant StreamPeer::get_var(){
|
|||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void StreamPeer::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("put_data", "data"), &StreamPeer::_put_data);
|
||||
|
@ -429,7 +402,6 @@ void StreamPeer::_bind_methods() {
|
|||
}
|
||||
////////////////////////////////
|
||||
|
||||
|
||||
void StreamPeerBuffer::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("seek", "pos"), &StreamPeerBuffer::seek);
|
||||
|
@ -440,10 +412,8 @@ void StreamPeerBuffer::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("get_data_array"), &StreamPeerBuffer::get_data_array);
|
||||
ClassDB::bind_method(D_METHOD("clear"), &StreamPeerBuffer::clear);
|
||||
ClassDB::bind_method(D_METHOD("duplicate:StreamPeerBuffer"), &StreamPeerBuffer::duplicate);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Error StreamPeerBuffer::put_data(const uint8_t *p_data, int p_bytes) {
|
||||
|
||||
if (p_bytes <= 0)
|
||||
|
@ -451,7 +421,6 @@ Error StreamPeerBuffer::put_data(const uint8_t* p_data,int p_bytes) {
|
|||
|
||||
if (pointer + p_bytes > data.size()) {
|
||||
data.resize(pointer + p_bytes);
|
||||
|
||||
}
|
||||
|
||||
PoolVector<uint8_t>::Write w = data.write();
|
||||
|
@ -475,11 +444,9 @@ Error StreamPeerBuffer::get_data(uint8_t* p_buffer, int p_bytes){
|
|||
return ERR_INVALID_PARAMETER;
|
||||
|
||||
return OK;
|
||||
|
||||
}
|
||||
Error StreamPeerBuffer::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received) {
|
||||
|
||||
|
||||
if (pointer + p_bytes > data.size()) {
|
||||
r_received = data.size() - pointer;
|
||||
if (r_received <= 0) {
|
||||
|
@ -533,14 +500,12 @@ PoolVector<uint8_t> StreamPeerBuffer::get_data_array() const{
|
|||
return data;
|
||||
}
|
||||
|
||||
|
||||
void StreamPeerBuffer::clear() {
|
||||
|
||||
data.resize(0);
|
||||
pointer = 0;
|
||||
}
|
||||
|
||||
|
||||
Ref<StreamPeerBuffer> StreamPeerBuffer::duplicate() const {
|
||||
|
||||
Ref<StreamPeerBuffer> spb;
|
||||
|
@ -549,7 +514,6 @@ Ref<StreamPeerBuffer> StreamPeerBuffer::duplicate() const {
|
|||
return spb;
|
||||
}
|
||||
|
||||
|
||||
StreamPeerBuffer::StreamPeerBuffer() {
|
||||
|
||||
pointer = 0;
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
class StreamPeer : public Reference {
|
||||
GDCLASS(StreamPeer, Reference);
|
||||
OBJ_CATEGORY("Networking");
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
|
@ -47,7 +48,6 @@ protected:
|
|||
bool big_endian;
|
||||
|
||||
public:
|
||||
|
||||
virtual Error put_data(const uint8_t *p_data, int p_bytes) = 0; ///< put a whole chunk of data, blocking until it sent
|
||||
virtual Error put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent) = 0; ///< put as much data as possible, without blocking.
|
||||
|
||||
|
@ -86,21 +86,19 @@ public:
|
|||
String get_utf8_string(int p_bytes);
|
||||
Variant get_var();
|
||||
|
||||
|
||||
|
||||
StreamPeer() { big_endian = false; }
|
||||
};
|
||||
|
||||
|
||||
class StreamPeerBuffer : public StreamPeer {
|
||||
|
||||
GDCLASS(StreamPeerBuffer, StreamPeer);
|
||||
|
||||
PoolVector<uint8_t> data;
|
||||
int pointer;
|
||||
protected:
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
Error put_data(const uint8_t *p_data, int p_bytes);
|
||||
Error put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent);
|
||||
|
@ -115,7 +113,6 @@ public:
|
|||
int get_pos() const;
|
||||
void resize(int p_size);
|
||||
|
||||
|
||||
void set_data_array(const PoolVector<uint8_t> &p_data);
|
||||
PoolVector<uint8_t> get_data_array() const;
|
||||
|
||||
|
@ -126,5 +123,4 @@ public:
|
|||
StreamPeerBuffer();
|
||||
};
|
||||
|
||||
|
||||
#endif // STREAM_PEER_H
|
||||
|
|
|
@ -28,19 +28,13 @@
|
|||
/*************************************************************************/
|
||||
#include "stream_peer_ssl.h"
|
||||
|
||||
|
||||
StreamPeerSSL *(*StreamPeerSSL::_create)() = NULL;
|
||||
|
||||
|
||||
|
||||
|
||||
StreamPeerSSL *StreamPeerSSL::create() {
|
||||
|
||||
return _create();
|
||||
}
|
||||
|
||||
|
||||
|
||||
StreamPeerSSL::LoadCertsFromMemory StreamPeerSSL::load_certs_func = NULL;
|
||||
bool StreamPeerSSL::available = false;
|
||||
bool StreamPeerSSL::initialize_certs = true;
|
||||
|
@ -56,7 +50,6 @@ bool StreamPeerSSL::is_available() {
|
|||
|
||||
void StreamPeerSSL::_bind_methods() {
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("accept_stream:Error", "stream:StreamPeer"), &StreamPeerSSL::accept_stream);
|
||||
ClassDB::bind_method(D_METHOD("connect_to_stream:Error", "stream:StreamPeer", "validate_certs", "for_hostname"), &StreamPeerSSL::connect_to_stream, DEFVAL(false), DEFVAL(String()));
|
||||
ClassDB::bind_method(D_METHOD("get_status"), &StreamPeerSSL::get_status);
|
||||
|
@ -65,9 +58,7 @@ void StreamPeerSSL::_bind_methods() {
|
|||
BIND_CONSTANT(STATUS_CONNECTED);
|
||||
BIND_CONSTANT(STATUS_ERROR_NO_CERTIFICATE);
|
||||
BIND_CONSTANT(STATUS_ERROR_HOSTNAME_MISMATCH);
|
||||
|
||||
}
|
||||
|
||||
StreamPeerSSL::StreamPeerSSL()
|
||||
{
|
||||
StreamPeerSSL::StreamPeerSSL() {
|
||||
}
|
||||
|
|
|
@ -33,9 +33,10 @@
|
|||
|
||||
class StreamPeerSSL : public StreamPeer {
|
||||
GDCLASS(StreamPeerSSL, StreamPeer);
|
||||
public:
|
||||
|
||||
public:
|
||||
typedef void (*LoadCertsFromMemory)(const PoolByteArray &p_certs);
|
||||
|
||||
protected:
|
||||
static StreamPeerSSL *(*_create)();
|
||||
static void _bind_methods();
|
||||
|
@ -43,13 +44,10 @@ protected:
|
|||
static LoadCertsFromMemory load_certs_func;
|
||||
static bool available;
|
||||
|
||||
|
||||
friend class Main;
|
||||
static bool initialize_certs;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
enum Status {
|
||||
STATUS_DISCONNECTED,
|
||||
STATUS_CONNECTED,
|
||||
|
|
|
@ -58,7 +58,6 @@ void StreamPeerTCP::_bind_methods() {
|
|||
BIND_CONSTANT(STATUS_CONNECTING);
|
||||
BIND_CONSTANT(STATUS_CONNECTED);
|
||||
BIND_CONSTANT(STATUS_ERROR);
|
||||
|
||||
}
|
||||
|
||||
Ref<StreamPeerTCP> StreamPeerTCP::create_ref() {
|
||||
|
@ -76,10 +75,8 @@ StreamPeerTCP* StreamPeerTCP::create() {
|
|||
}
|
||||
|
||||
StreamPeerTCP::StreamPeerTCP() {
|
||||
|
||||
}
|
||||
|
||||
StreamPeerTCP::~StreamPeerTCP(){
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -31,8 +31,8 @@
|
|||
|
||||
#include "stream_peer.h"
|
||||
|
||||
#include "ip_address.h"
|
||||
#include "io/ip.h"
|
||||
#include "ip_address.h"
|
||||
|
||||
class StreamPeerTCP : public StreamPeer {
|
||||
|
||||
|
@ -40,7 +40,6 @@ class StreamPeerTCP : public StreamPeer {
|
|||
OBJ_CATEGORY("Networking");
|
||||
|
||||
public:
|
||||
|
||||
enum Status {
|
||||
|
||||
STATUS_NONE,
|
||||
|
@ -50,13 +49,11 @@ public:
|
|||
};
|
||||
|
||||
protected:
|
||||
|
||||
virtual Error _connect(const String &p_address, int p_port);
|
||||
static StreamPeerTCP *(*_create)();
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
|
||||
virtual Error connect_to_host(const IP_Address &p_host, uint16_t p_port) = 0;
|
||||
|
||||
//read/write from streampeer
|
||||
|
|
|
@ -50,11 +50,7 @@ void TCP_Server::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("is_connection_available"), &TCP_Server::is_connection_available);
|
||||
ClassDB::bind_method(D_METHOD("take_connection"), &TCP_Server::take_connection);
|
||||
ClassDB::bind_method(D_METHOD("stop"), &TCP_Server::stop);
|
||||
|
||||
}
|
||||
|
||||
|
||||
TCP_Server::TCP_Server()
|
||||
{
|
||||
|
||||
TCP_Server::TCP_Server() {
|
||||
}
|
||||
|
|
|
@ -29,21 +29,21 @@
|
|||
#ifndef TCP_SERVER_H
|
||||
#define TCP_SERVER_H
|
||||
|
||||
#include "io/stream_peer.h"
|
||||
#include "io/ip.h"
|
||||
#include "io/stream_peer.h"
|
||||
#include "stream_peer_tcp.h"
|
||||
|
||||
class TCP_Server : public Reference {
|
||||
|
||||
GDCLASS(TCP_Server, Reference);
|
||||
protected:
|
||||
|
||||
protected:
|
||||
static TCP_Server *(*_create)();
|
||||
|
||||
//bind helper
|
||||
static void _bind_methods();
|
||||
public:
|
||||
|
||||
public:
|
||||
virtual Error listen(uint16_t p_port, const IP_Address p_bind_address = IP_Address("*")) = 0;
|
||||
virtual bool is_connection_available() const = 0;
|
||||
virtual Ref<StreamPeerTCP> take_connection() = 0;
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
#include "os/file_access.h"
|
||||
#include "translation.h"
|
||||
|
||||
|
||||
RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error, const String &p_path) {
|
||||
|
||||
enum Status {
|
||||
|
@ -118,7 +117,6 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error, const S
|
|||
//not a string? failure!
|
||||
ERR_EXPLAIN(p_path + ":" + itos(line) + " Invalid line '" + l + "' while parsing: ");
|
||||
ERR_FAIL_V(RES());
|
||||
|
||||
}
|
||||
|
||||
l = l.substr(1, l.length());
|
||||
|
@ -140,7 +138,6 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error, const S
|
|||
l = l.substr(0, end_pos);
|
||||
l = l.c_unescape();
|
||||
|
||||
|
||||
if (status == STATUS_READING_ID)
|
||||
msg_id += l;
|
||||
else
|
||||
|
@ -149,7 +146,6 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error, const S
|
|||
line++;
|
||||
}
|
||||
|
||||
|
||||
f->close();
|
||||
memdelete(f);
|
||||
|
||||
|
@ -187,9 +183,7 @@ RES TranslationLoaderPO::load(const String &p_path, const String& p_original_pat
|
|||
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
|
||||
ERR_FAIL_COND_V(!f, RES());
|
||||
|
||||
|
||||
return load_translation(f, r_error);
|
||||
|
||||
}
|
||||
|
||||
void TranslationLoaderPO::get_recognized_extensions(List<String> *p_extensions) const {
|
||||
|
@ -209,6 +203,5 @@ String TranslationLoaderPO::get_resource_type(const String &p_path) const {
|
|||
return "";
|
||||
}
|
||||
|
||||
TranslationLoaderPO::TranslationLoaderPO()
|
||||
{
|
||||
TranslationLoaderPO::TranslationLoaderPO() {
|
||||
}
|
||||
|
|
|
@ -30,18 +30,16 @@
|
|||
#define TRANSLATION_LOADER_PO_H
|
||||
|
||||
#include "io/resource_loader.h"
|
||||
#include "translation.h"
|
||||
#include "os/file_access.h"
|
||||
#include "translation.h"
|
||||
class TranslationLoaderPO : public ResourceFormatLoader {
|
||||
public:
|
||||
|
||||
static RES load_translation(FileAccess *f, Error *r_error, const String &p_path = String());
|
||||
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL);
|
||||
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;
|
||||
|
||||
|
||||
TranslationLoaderPO();
|
||||
};
|
||||
|
||||
|
|
|
@ -43,7 +43,6 @@ static bool _equalsn(const CharType* str1, const CharType* str2, int len) {
|
|||
return (i == len) || (str1[i] == 0 && str2[i] == 0);
|
||||
}
|
||||
|
||||
|
||||
String XMLParser::_replace_special_characters(const String &origstr) {
|
||||
|
||||
int pos = origstr.find("&");
|
||||
|
@ -58,25 +57,20 @@ String XMLParser::_replace_special_characters(const String& origstr) {
|
|||
// check if it is one of the special characters
|
||||
|
||||
int specialChar = -1;
|
||||
for (int i=0; i<(int)special_characters.size(); ++i)
|
||||
{
|
||||
for (int i = 0; i < (int)special_characters.size(); ++i) {
|
||||
const CharType *p = &origstr[pos] + 1;
|
||||
|
||||
if (_equalsn(&special_characters[i][1], p, special_characters[i].length()-1))
|
||||
{
|
||||
if (_equalsn(&special_characters[i][1], p, special_characters[i].length() - 1)) {
|
||||
specialChar = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (specialChar != -1)
|
||||
{
|
||||
if (specialChar != -1) {
|
||||
newstr += (origstr.substr(oldPos, pos - oldPos));
|
||||
newstr += (special_characters[specialChar][0]);
|
||||
pos += special_characters[specialChar].length();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
newstr += (origstr.substr(oldPos, pos - oldPos + 1));
|
||||
pos += 1;
|
||||
}
|
||||
|
@ -92,19 +86,15 @@ String XMLParser::_replace_special_characters(const String& origstr) {
|
|||
return newstr;
|
||||
}
|
||||
|
||||
|
||||
static inline bool _is_white_space(char c)
|
||||
{
|
||||
static inline bool _is_white_space(char c) {
|
||||
return (c == ' ' || c == '\t' || c == '\n' || c == '\r');
|
||||
}
|
||||
|
||||
|
||||
//! sets the state that text was found. Returns true if set should be set
|
||||
bool XMLParser::_set_text(char *start, char *end) {
|
||||
// check if text is more than 2 characters, and if not, check if there is
|
||||
// only white space, so that this text won't be reported
|
||||
if (end - start < 3)
|
||||
{
|
||||
if (end - start < 3) {
|
||||
char *p = start;
|
||||
for (; p != end; ++p)
|
||||
if (!_is_white_space(*p))
|
||||
|
@ -162,8 +152,7 @@ bool XMLParser::_parse_cdata() {
|
|||
|
||||
// skip '<![CDATA['
|
||||
int count = 0;
|
||||
while( *P && count<8 )
|
||||
{
|
||||
while (*P && count < 8) {
|
||||
++P;
|
||||
++count;
|
||||
}
|
||||
|
@ -178,8 +167,7 @@ bool XMLParser::_parse_cdata() {
|
|||
while (*P && !cDataEnd) {
|
||||
if (*P == '>' &&
|
||||
(*(P - 1) == ']') &&
|
||||
(*(P-2) == ']'))
|
||||
{
|
||||
(*(P - 2) == ']')) {
|
||||
cDataEnd = P - 2;
|
||||
}
|
||||
|
||||
|
@ -207,12 +195,10 @@ void XMLParser::_parse_comment() {
|
|||
int count = 1;
|
||||
|
||||
// move until end of comment reached
|
||||
while(count)
|
||||
{
|
||||
while (count) {
|
||||
if (*P == '>')
|
||||
--count;
|
||||
else
|
||||
if (*P == '<')
|
||||
else if (*P == '<')
|
||||
++count;
|
||||
|
||||
++P;
|
||||
|
@ -224,7 +210,6 @@ void XMLParser::_parse_comment() {
|
|||
#ifdef DEBUG_XML
|
||||
print_line("XML COMMENT: " + node_name);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void XMLParser::_parse_opening_xml_element() {
|
||||
|
@ -243,14 +228,11 @@ void XMLParser::_parse_opening_xml_element() {
|
|||
const char *endName = P;
|
||||
|
||||
// find attributes
|
||||
while(*P != '>')
|
||||
{
|
||||
while (*P != '>') {
|
||||
if (_is_white_space(*P))
|
||||
++P;
|
||||
else
|
||||
{
|
||||
if (*P != '/')
|
||||
{
|
||||
else {
|
||||
if (*P != '/') {
|
||||
// we've got an attribute
|
||||
|
||||
// read the attribute names
|
||||
|
@ -293,9 +275,7 @@ void XMLParser::_parse_opening_xml_element() {
|
|||
|
||||
attr.value = _replace_special_characters(s);
|
||||
attributes.push_back(attr);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// tag is closed directly
|
||||
++P;
|
||||
node_empty = true;
|
||||
|
@ -305,8 +285,7 @@ void XMLParser::_parse_opening_xml_element() {
|
|||
}
|
||||
|
||||
// check if this tag is closing directly
|
||||
if (endName > startName && *(endName-1) == '/')
|
||||
{
|
||||
if (endName > startName && *(endName - 1) == '/') {
|
||||
// directly closing tag
|
||||
node_empty = true;
|
||||
endName--;
|
||||
|
@ -320,7 +299,6 @@ void XMLParser::_parse_opening_xml_element() {
|
|||
++P;
|
||||
}
|
||||
|
||||
|
||||
void XMLParser::_parse_current_node() {
|
||||
|
||||
char *start = P;
|
||||
|
@ -333,8 +311,7 @@ void XMLParser::_parse_current_node() {
|
|||
if (!*P)
|
||||
return;
|
||||
|
||||
if (P - start > 0)
|
||||
{
|
||||
if (P - start > 0) {
|
||||
// we found some text, store it
|
||||
if (_set_text(start, P))
|
||||
return;
|
||||
|
@ -343,8 +320,7 @@ void XMLParser::_parse_current_node() {
|
|||
++P;
|
||||
|
||||
// based on current token, parse and report next element
|
||||
switch(*P)
|
||||
{
|
||||
switch (*P) {
|
||||
case '/':
|
||||
_parse_closing_xml_element();
|
||||
break;
|
||||
|
@ -361,7 +337,6 @@ void XMLParser::_parse_current_node() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
uint64_t XMLParser::get_node_offset() const {
|
||||
|
||||
return node_offset;
|
||||
|
@ -404,16 +379,12 @@ void XMLParser::_bind_methods() {
|
|||
BIND_CONSTANT(NODE_COMMENT);
|
||||
BIND_CONSTANT(NODE_CDATA);
|
||||
BIND_CONSTANT(NODE_UNKNOWN);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
Error XMLParser::read() {
|
||||
|
||||
// if not end reached, parse the node
|
||||
if (P && (P - data) < length - 1 && *P != 0)
|
||||
{
|
||||
if (P && (P - data) < length - 1 && *P != 0) {
|
||||
_parse_current_node();
|
||||
return OK;
|
||||
}
|
||||
|
@ -473,7 +444,6 @@ String XMLParser::get_attribute_value(const String& p_name) const {
|
|||
}
|
||||
ERR_FAIL_COND_V(idx < 0, "");
|
||||
return attributes[idx].value;
|
||||
|
||||
}
|
||||
|
||||
String XMLParser::get_attribute_value_safe(const String &p_name) const {
|
||||
|
@ -489,7 +459,6 @@ String XMLParser::get_attribute_value_safe(const String& p_name) const {
|
|||
if (idx < 0)
|
||||
return "";
|
||||
return attributes[idx].value;
|
||||
|
||||
}
|
||||
bool XMLParser::is_empty() const {
|
||||
|
||||
|
@ -506,7 +475,6 @@ Error XMLParser::open_buffer(const Vector<uint8_t>& p_buffer) {
|
|||
data[length] = 0;
|
||||
P = data;
|
||||
return OK;
|
||||
|
||||
}
|
||||
|
||||
Error XMLParser::open(const String &p_path) {
|
||||
|
@ -529,7 +497,6 @@ Error XMLParser::open(const String& p_path) {
|
|||
memdelete(file);
|
||||
|
||||
return OK;
|
||||
|
||||
}
|
||||
|
||||
void XMLParser::skip_section() {
|
||||
|
@ -541,18 +508,13 @@ void XMLParser::skip_section() {
|
|||
// read until we've reached the last element in this section
|
||||
int tagcount = 1;
|
||||
|
||||
while(tagcount && read()==OK)
|
||||
{
|
||||
while (tagcount && read() == OK) {
|
||||
if (get_node_type() == XMLParser::NODE_ELEMENT &&
|
||||
!is_empty())
|
||||
{
|
||||
!is_empty()) {
|
||||
++tagcount;
|
||||
}
|
||||
else
|
||||
if (get_node_type() == XMLParser::NODE_ELEMENT_END)
|
||||
} else if (get_node_type() == XMLParser::NODE_ELEMENT_END)
|
||||
--tagcount;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void XMLParser::close() {
|
||||
|
@ -581,12 +543,9 @@ XMLParser::XMLParser() {
|
|||
special_characters.push_back(">gt;");
|
||||
special_characters.push_back("\"quot;");
|
||||
special_characters.push_back("'apos;");
|
||||
|
||||
|
||||
}
|
||||
XMLParser::~XMLParser() {
|
||||
|
||||
|
||||
if (data)
|
||||
memdelete_arr(data);
|
||||
}
|
||||
|
|
|
@ -29,10 +29,10 @@
|
|||
#ifndef XML_PARSER_H
|
||||
#define XML_PARSER_H
|
||||
|
||||
#include "ustring.h"
|
||||
#include "vector.h"
|
||||
#include "os/file_access.h"
|
||||
#include "reference.h"
|
||||
#include "ustring.h"
|
||||
#include "vector.h"
|
||||
|
||||
/*
|
||||
Based on irrXML (see their zlib license). Added mainly for compatibility with their Collada loader.
|
||||
|
@ -41,6 +41,7 @@
|
|||
class XMLParser : public Reference {
|
||||
|
||||
GDCLASS(XMLParser, Reference);
|
||||
|
||||
public:
|
||||
//! Enumeration of all supported source text file formats
|
||||
enum SourceFormat {
|
||||
|
@ -63,7 +64,6 @@ public:
|
|||
};
|
||||
|
||||
private:
|
||||
|
||||
char *data;
|
||||
char *P;
|
||||
int length;
|
||||
|
@ -93,8 +93,6 @@ private:
|
|||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
|
||||
|
||||
Error read();
|
||||
NodeType get_node_type();
|
||||
String get_node_name() const;
|
||||
|
@ -122,4 +120,3 @@ public:
|
|||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -29,11 +29,10 @@
|
|||
#ifndef ZIP_IO_H
|
||||
#define ZIP_IO_H
|
||||
|
||||
#include "io/zip.h"
|
||||
#include "io/unzip.h"
|
||||
#include "os/file_access.h"
|
||||
#include "io/zip.h"
|
||||
#include "os/copymem.h"
|
||||
|
||||
#include "os/file_access.h"
|
||||
|
||||
static void *zipio_open(void *data, const char *p_fname, int mode) {
|
||||
|
||||
|
@ -53,14 +52,12 @@ static void* zipio_open(void* data, const char* p_fname, int mode) {
|
|||
return NULL;
|
||||
|
||||
return data;
|
||||
|
||||
};
|
||||
|
||||
static uLong zipio_read(void *data, void *fdata, void *buf, uLong size) {
|
||||
|
||||
FileAccess *f = *(FileAccess **)data;
|
||||
return f->get_buffer((uint8_t *)buf, size);
|
||||
|
||||
};
|
||||
|
||||
static uLong zipio_write(voidpf opaque, voidpf stream, const void *buf, uLong size) {
|
||||
|
@ -70,7 +67,6 @@ static uLong zipio_write(voidpf opaque, voidpf stream, const void* buf, uLong si
|
|||
return size;
|
||||
};
|
||||
|
||||
|
||||
static long zipio_tell(voidpf opaque, voidpf stream) {
|
||||
|
||||
FileAccess *f = *(FileAccess **)opaque;
|
||||
|
@ -114,8 +110,6 @@ static int zipio_testerror(voidpf opaque, voidpf stream) {
|
|||
return (f && f->get_error() != OK) ? 1 : 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
static voidpf zipio_alloc(voidpf opaque, uInt items, uInt size) {
|
||||
|
||||
voidpf ptr = memalloc(items * size);
|
||||
|
@ -123,13 +117,11 @@ static voidpf zipio_alloc(voidpf opaque, uInt items, uInt size) {
|
|||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
static void zipio_free(voidpf opaque, voidpf address) {
|
||||
|
||||
memfree(address);
|
||||
}
|
||||
|
||||
|
||||
static zlib_filefunc_def zipio_create_io_from_file(FileAccess **p_file) {
|
||||
|
||||
zlib_filefunc_def io;
|
||||
|
@ -146,6 +138,4 @@ static zlib_filefunc_def zipio_create_io_from_file(FileAccess **p_file) {
|
|||
return io;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // ZIP_IO_H
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue