summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/bind/core_bind.cpp10
-rw-r--r--core/bind/core_bind.h1
-rw-r--r--core/color.cpp14
-rw-r--r--core/color.h18
-rw-r--r--core/command_queue_mt.cpp2
-rw-r--r--core/command_queue_mt.h280
-rw-r--r--core/dvector.h198
-rw-r--r--core/error_macros.h12
-rw-r--r--core/event_queue.cpp54
-rw-r--r--core/event_queue.h10
-rw-r--r--core/globals.cpp26
-rw-r--r--core/globals.h16
-rw-r--r--core/hash_map.h330
-rw-r--r--core/hashfuncs.h8
-rw-r--r--core/image.cpp120
-rw-r--r--core/image.h52
-rw-r--r--core/input_map.cpp7
-rw-r--r--core/io/aes256.h12
-rw-r--r--core/io/fastlz.h26
-rw-r--r--core/io/file_access_buffered.cpp22
-rw-r--r--core/io/file_access_buffered.h6
-rw-r--r--core/io/file_access_network.cpp2
-rw-r--r--core/io/http_client.cpp2
-rw-r--r--core/io/image_loader.cpp28
-rw-r--r--core/io/image_loader.h14
-rw-r--r--core/io/ip.cpp2
-rw-r--r--core/io/marshalls.cpp8
-rw-r--r--core/io/marshalls.h42
-rw-r--r--core/io/packet_peer.cpp6
-rw-r--r--core/io/resource_format_binary.cpp4
-rw-r--r--core/io/resource_format_xml.cpp2
-rw-r--r--core/io/resource_loader.cpp14
-rw-r--r--core/io/resource_loader.h10
-rw-r--r--core/io/resource_saver.cpp26
-rw-r--r--core/io/resource_saver.h10
-rw-r--r--core/list.h52
-rw-r--r--core/map.h284
-rw-r--r--core/math/aabb.h14
-rw-r--r--core/math/bsp_tree.cpp84
-rw-r--r--core/math/bsp_tree.h22
-rw-r--r--core/math/camera_matrix.cpp118
-rw-r--r--core/math/camera_matrix.h16
-rw-r--r--core/math/face3.h4
-rw-r--r--core/math/geometry.cpp328
-rw-r--r--core/math/geometry.h106
-rw-r--r--core/math/math_2d.cpp54
-rw-r--r--core/math/math_2d.h92
-rw-r--r--core/math/math_funcs.cpp20
-rw-r--r--core/math/math_funcs.h16
-rw-r--r--core/math/matrix3.cpp42
-rw-r--r--core/math/matrix3.h32
-rw-r--r--core/math/octree.h406
-rw-r--r--core/math/plane.cpp6
-rw-r--r--core/math/plane.h4
-rw-r--r--core/math/quat.cpp12
-rw-r--r--core/math/quat.h14
-rw-r--r--core/math/transform.cpp24
-rw-r--r--core/math/transform.h62
-rw-r--r--core/method_bind.h12
-rw-r--r--core/object.cpp60
-rw-r--r--core/object_type_db.cpp112
-rw-r--r--core/object_type_db.h30
-rw-r--r--core/os/copymem.cpp2
-rw-r--r--core/os/dir_access.cpp22
-rw-r--r--core/os/dir_access.h12
-rw-r--r--core/os/file_access.cpp90
-rw-r--r--core/os/file_access.h44
-rw-r--r--core/os/input.h2
-rw-r--r--core/os/input_event.cpp24
-rw-r--r--core/os/input_event.h6
-rw-r--r--core/os/keyboard.h20
-rw-r--r--core/os/main_loop.h6
-rw-r--r--core/os/memory.cpp6
-rw-r--r--core/os/memory.h86
-rw-r--r--core/os/memory_pool_dynamic.h8
-rw-r--r--core/os/memory_pool_dynamic_static.cpp84
-rw-r--r--core/os/memory_pool_dynamic_static.h16
-rw-r--r--core/os/memory_pool_static.cpp4
-rw-r--r--core/os/memory_pool_static.h8
-rw-r--r--core/os/mutex.cpp6
-rw-r--r--core/os/mutex.h8
-rw-r--r--core/os/os.h32
-rw-r--r--core/os/semaphore.h8
-rw-r--r--core/os/shell.h2
-rw-r--r--core/os/thread.cpp10
-rw-r--r--core/os/thread.h18
-rw-r--r--core/os/thread_safe.cpp14
-rw-r--r--core/os/thread_safe.h6
-rw-r--r--core/packed_data_container.cpp6
-rw-r--r--core/path_db.cpp86
-rw-r--r--core/path_db.h10
-rw-r--r--core/pool_allocator.cpp202
-rw-r--r--core/pool_allocator.h58
-rw-r--r--core/register_core_types.cpp4
-rw-r--r--core/res_ptr.cpp2
-rw-r--r--core/res_ptr.h2
-rw-r--r--core/resource.cpp28
-rw-r--r--core/resource.h18
-rw-r--r--core/rid.h76
-rw-r--r--core/ring_buffer.h28
-rw-r--r--core/safe_refcount.cpp4
-rw-r--r--core/safe_refcount.h68
-rw-r--r--core/script_language.cpp10
-rw-r--r--core/script_language.h24
-rw-r--r--core/set.h264
-rw-r--r--core/simple_type.h24
-rw-r--r--core/sort.h128
-rw-r--r--core/string_db.cpp104
-rw-r--r--core/string_db.h36
-rw-r--r--core/typedefs.h2
-rw-r--r--core/undo_redo.cpp6
-rw-r--r--core/ustring.cpp228
-rw-r--r--core/ustring.h16
-rw-r--r--core/variant.cpp358
-rw-r--r--core/variant.h52
-rw-r--r--core/variant_op.cpp14
-rw-r--r--core/variant_parser.cpp6
-rw-r--r--core/vector.h94
118 files changed, 2968 insertions, 2954 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index 17f30bc883..d67b93603c 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -1395,6 +1395,15 @@ String _File::get_as_text() const {
}
+
+
+String _File::get_md5(const String& p_path) const {
+
+ return FileAccess::get_md5(p_path);
+
+}
+
+
String _File::get_line() const{
ERR_FAIL_COND_V(!f,String());
@@ -1583,6 +1592,7 @@ void _File::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_buffer","len"),&_File::get_buffer);
ObjectTypeDB::bind_method(_MD("get_line"),&_File::get_line);
ObjectTypeDB::bind_method(_MD("get_as_text"),&_File::get_as_text);
+ ObjectTypeDB::bind_method(_MD("get_md5","path"),&_File::get_md5);
ObjectTypeDB::bind_method(_MD("get_endian_swap"),&_File::get_endian_swap);
ObjectTypeDB::bind_method(_MD("set_endian_swap","enable"),&_File::set_endian_swap);
ObjectTypeDB::bind_method(_MD("get_error:Error"),&_File::get_error);
diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h
index 2fce33e67f..7b3494ebc1 100644
--- a/core/bind/core_bind.h
+++ b/core/bind/core_bind.h
@@ -369,6 +369,7 @@ public:
DVector<uint8_t> get_buffer(int p_length) const; ///< get an array of bytes
String get_line() const;
String get_as_text() const;
+ String get_md5(const String& p_path) const;
/**< use this for files WRITTEN in _big_ endian machines (ie, amiga/mac)
* It's not about the current CPU type but file formats.
diff --git a/core/color.cpp b/core/color.cpp
index 56a550c024..bf9c94462f 100644
--- a/core/color.cpp
+++ b/core/color.cpp
@@ -75,11 +75,11 @@ float Color::get_h() const {
h = 2 + ( b - r ) / delta; // between cyan & yellow
else
h = 4 + ( r - g ) / delta; // between magenta & cyan
-
+
h/=6.0;
if (h<0)
h+=1.0;
-
+
return h;
}
@@ -119,7 +119,7 @@ void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha) {
p_h *=6.0;
p_h = Math::fmod(p_h,6);
i = Math::floor( p_h );
-
+
f = p_h - i;
p = p_v * ( 1 - p_s );
q = p_v * ( 1 - p_s * f );
@@ -136,7 +136,7 @@ void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha) {
g = p_v;
b = p;
break;
- case 2:
+ case 2:
r = p;
g = p_v;
b = t;
@@ -162,8 +162,8 @@ void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha) {
void Color::invert() {
r=1.0-r;
- g=1.0-g;
- b=1.0-b;
+ g=1.0-g;
+ b=1.0-b;
}
void Color::contrast() {
@@ -368,7 +368,7 @@ String Color::to_html(bool p_alpha) const {
float Color::gray() const {
- return (r+g+b)/3.0;
+ return (r+g+b)/3.0;
}
Color::operator String() const {
diff --git a/core/color.h b/core/color.h
index d0a1e8835c..5b671d5f62 100644
--- a/core/color.h
+++ b/core/color.h
@@ -37,13 +37,13 @@
struct Color {
union {
-
+
struct {
float r;
float g;
float b;
float a;
- };
+ };
float components[4];
};
@@ -58,28 +58,28 @@ struct Color {
float get_v() const;
void set_hsv(float p_h, float p_s, float p_v, float p_alpha=1.0);
- _FORCE_INLINE_ float& operator[](int idx) {
+ _FORCE_INLINE_ float& operator[](int idx) {
return components[idx];
}
- _FORCE_INLINE_ const float& operator[](int idx) const {
+ _FORCE_INLINE_ const float& operator[](int idx) const {
return components[idx];
}
-
+
void invert();
void contrast();
Color inverted() const;
Color contrasted() const;
_FORCE_INLINE_ Color linear_interpolate(const Color& p_b, float p_t) const {
-
+
Color res=*this;
-
+
res.r+= (p_t * (p_b.r-r));
res.g+= (p_t * (p_b.g-g));
res.b+= (p_t * (p_b.b-b));
res.a+= (p_t * (p_b.a-a));
-
- return res;
+
+ return res;
}
_FORCE_INLINE_ Color blend(const Color& p_over) const {
diff --git a/core/command_queue_mt.cpp b/core/command_queue_mt.cpp
index a2507b1378..acd3aeddfb 100644
--- a/core/command_queue_mt.cpp
+++ b/core/command_queue_mt.cpp
@@ -76,7 +76,7 @@ CommandQueueMT::SyncSemaphore* CommandQueueMT::_alloc_sync_sem() {
CommandQueueMT::CommandQueueMT(bool p_sync){
read_ptr=0;
- write_ptr=0;
+ write_ptr=0;
mutex = Mutex::create();
for(int i=0;i<SYNC_SEMAPHORES;i++) {
diff --git a/core/command_queue_mt.h b/core/command_queue_mt.h
index 142668f6f6..b1e0066c35 100644
--- a/core/command_queue_mt.h
+++ b/core/command_queue_mt.h
@@ -47,69 +47,69 @@ class CommandQueueMT {
};
struct CommandBase {
-
+
virtual void call()=0;
virtual ~CommandBase() {};
};
-
+
template<class T,class M>
struct Command0 : public CommandBase {
T*instance;
M method;
-
+
virtual void call() { (instance->*method)(); }
};
-
+
template<class T,class M,class P1>
struct Command1 : public CommandBase {
-
+
T*instance;
M method;
typename GetSimpleTypeT<P1>::type_t p1;
-
+
virtual void call() { (instance->*method)(p1); }
};
-
+
template<class T,class M,class P1,class P2>
struct Command2 : public CommandBase {
-
+
T*instance;
M method;
typename GetSimpleTypeT<P1>::type_t p1;
typename GetSimpleTypeT<P2>::type_t p2;
-
+
virtual void call() { (instance->*method)(p1,p2); }
};
template<class T,class M,class P1,class P2,class P3>
struct Command3 : public CommandBase {
-
+
T*instance;
M method;
typename GetSimpleTypeT<P1>::type_t p1;
typename GetSimpleTypeT<P2>::type_t p2;
typename GetSimpleTypeT<P3>::type_t p3;
-
+
virtual void call() { (instance->*method)(p1,p2,p3); }
};
template<class T,class M,class P1,class P2,class P3,class P4>
struct Command4 : public CommandBase {
-
+
T*instance;
M method;
typename GetSimpleTypeT<P1>::type_t p1;
typename GetSimpleTypeT<P2>::type_t p2;
typename GetSimpleTypeT<P3>::type_t p3;
typename GetSimpleTypeT<P4>::type_t p4;
-
+
virtual void call() { (instance->*method)(p1,p2,p3,p4); }
};
template<class T,class M,class P1,class P2,class P3,class P4,class P5>
struct Command5 : public CommandBase {
-
+
T*instance;
M method;
typename GetSimpleTypeT<P1>::type_t p1;
@@ -117,13 +117,13 @@ class CommandQueueMT {
typename GetSimpleTypeT<P3>::type_t p3;
typename GetSimpleTypeT<P4>::type_t p4;
typename GetSimpleTypeT<P5>::type_t p5;
-
+
virtual void call() { (instance->*method)(p1,p2,p3,p4,p5); }
};
template<class T,class M,class P1,class P2,class P3,class P4,class P5,class P6>
struct Command6 : public CommandBase {
-
+
T*instance;
M method;
typename GetSimpleTypeT<P1>::type_t p1;
@@ -132,13 +132,13 @@ class CommandQueueMT {
typename GetSimpleTypeT<P4>::type_t p4;
typename GetSimpleTypeT<P5>::type_t p5;
typename GetSimpleTypeT<P6>::type_t p6;
-
+
virtual void call() { (instance->*method)(p1,p2,p3,p4,p5,p6); }
};
-
+
template<class T,class M,class P1,class P2,class P3,class P4,class P5,class P6,class P7>
struct Command7 : public CommandBase {
-
+
T*instance;
M method;
typename GetSimpleTypeT<P1>::type_t p1;
@@ -148,12 +148,12 @@ class CommandQueueMT {
typename GetSimpleTypeT<P5>::type_t p5;
typename GetSimpleTypeT<P6>::type_t p6;
typename GetSimpleTypeT<P7>::type_t p7;
-
+
virtual void call() { (instance->*method)(p1,p2,p3,p4,p5,p6,p7); }
};
-
+
/* comands that return */
-
+
template<class T,class M,class R>
struct CommandRet0 : public CommandBase {
@@ -161,38 +161,38 @@ class CommandQueueMT {
M method;
R* ret;
SyncSemaphore *sync;
-
+
virtual void call() { *ret = (instance->*method)(); sync->sem->post(); sync->in_use=false; ; }
};
-
+
template<class T,class M,class P1,class R>
struct CommandRet1 : public CommandBase {
-
+
T*instance;
M method;
typename GetSimpleTypeT<P1>::type_t p1;
R* ret;
SyncSemaphore *sync;
-
+
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>
struct CommandRet2 : public CommandBase {
-
+
T*instance;
M method;
typename GetSimpleTypeT<P1>::type_t p1;
typename GetSimpleTypeT<P2>::type_t p2;
R* ret;
SyncSemaphore *sync;
-
+
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>
struct CommandRet3 : public CommandBase {
-
+
T*instance;
M method;
typename GetSimpleTypeT<P1>::type_t p1;
@@ -200,13 +200,13 @@ class CommandQueueMT {
typename GetSimpleTypeT<P3>::type_t p3;
R* ret;
SyncSemaphore *sync;
-
+
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>
struct CommandRet4 : public CommandBase {
-
+
T*instance;
M method;
typename GetSimpleTypeT<P1>::type_t p1;
@@ -215,13 +215,13 @@ class CommandQueueMT {
typename GetSimpleTypeT<P4>::type_t p4;
R* ret;
SyncSemaphore *sync;
-
+
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>
struct CommandRet5 : public CommandBase {
-
+
T*instance;
M method;
typename GetSimpleTypeT<P1>::type_t p1;
@@ -231,13 +231,13 @@ class CommandQueueMT {
typename GetSimpleTypeT<P5>::type_t p5;
R* ret;
SyncSemaphore *sync;
-
+
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>
struct CommandRet6 : public CommandBase {
-
+
T*instance;
M method;
typename GetSimpleTypeT<P1>::type_t p1;
@@ -248,13 +248,13 @@ class CommandQueueMT {
typename GetSimpleTypeT<P6>::type_t p6;
R* ret;
SyncSemaphore *sync;
-
+
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>
struct CommandRet7 : public CommandBase {
-
+
T*instance;
M method;
typename GetSimpleTypeT<P1>::type_t p1;
@@ -266,9 +266,9 @@ class CommandQueueMT {
typename GetSimpleTypeT<P7>::type_t p7;
R* ret;
SyncSemaphore *sync;
-
+
virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4,p5,p6,p7); sync->sem->post(); sync->in_use=false; ; }
- };
+ };
/** commands that don't return but sync */
@@ -392,7 +392,7 @@ class CommandQueueMT {
/***** BASE *******/
- enum {
+ enum {
COMMAND_MEM_SIZE_KB=256,
COMMAND_MEM_SIZE=COMMAND_MEM_SIZE_KB*1024,
SYNC_SEMAPHORES=8
@@ -405,30 +405,30 @@ class CommandQueueMT {
SyncSemaphore sync_sems[SYNC_SEMAPHORES];
Mutex *mutex;
Semaphore *sync;
-
-
+
+
template<class T>
T* allocate() {
-
+
// alloc size is size+T+safeguard
uint32_t alloc_size=sizeof(T)+sizeof(uint32_t);
-
+
tryagain:
-
+
if (write_ptr < read_ptr) {
// behind read_ptr, check that there is room
if ( (read_ptr-write_ptr) <= alloc_size )
return NULL;
} 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;
-
+
if (read_ptr==0) // dont want write_ptr to become read_ptr
return NULL;
-
+
// if this happens, it's a bug
ERR_FAIL_COND_V( (COMMAND_MEM_SIZE-write_ptr) < sizeof(uint32_t), NULL );
// zero means, wrap to begining
@@ -447,147 +447,147 @@ class CommandQueueMT {
T* cmd = memnew_placement( &command_mem[write_ptr], T );
write_ptr+=sizeof(T);
return cmd;
-
+
}
-
+
template<class T>
T* allocate_and_lock() {
-
+
lock();
T* ret;
-
+
while ( (ret=allocate<T>())==NULL ) {
-
+
unlock();
- // sleep a little until fetch happened and some room is made
+ // sleep a little until fetch happened and some room is made
wait_for_flush();
lock();
-
+
}
-
+
return ret;
}
-
-
+
+
bool flush_one() {
-
+
tryagain:
-
+
// tried to read an empty queue
if (read_ptr == write_ptr )
return false;
-
+
uint32_t size = *(uint32_t*)( &command_mem[read_ptr] );
-
+
if (size==0) {
//end of ringbuffer, wrap
read_ptr=0;
goto tryagain;
}
-
+
read_ptr+=sizeof(uint32_t);
-
+
CommandBase *cmd = reinterpret_cast<CommandBase*>( &command_mem[read_ptr] );
-
+
cmd->call();
cmd->~CommandBase();
-
- read_ptr+=size;
+
+ read_ptr+=size;
return true;
}
-
-
+
+
void lock();
void unlock();
void wait_for_flush();
SyncSemaphore* _alloc_sync_sem();
-
-
+
+
public:
/* NORMAL PUSH COMMANDS */
-
+
template<class T, class M>
void push( T * p_instance, M p_method ) {
-
+
Command0<T,M> * cmd = allocate_and_lock< Command0<T,M> >();
-
+
cmd->instance=p_instance;
cmd->method=p_method;
-
+
unlock();
-
+
if (sync) sync->post();
}
template<class T, class M, class P1>
void push( T * p_instance, M p_method, P1 p1 ) {
-
+
Command1<T,M,P1> * cmd = allocate_and_lock< Command1<T,M,P1> >();
-
+
cmd->instance=p_instance;
cmd->method=p_method;
cmd->p1=p1;
-
+
unlock();
-
+
if (sync) sync->post();
}
template<class T, class M, class P1, class P2>
void push( T * p_instance, M p_method, P1 p1, P2 p2 ) {
-
+
Command2<T,M,P1,P2> * cmd = allocate_and_lock< Command2<T,M,P1,P2> >();
-
+
cmd->instance=p_instance;
cmd->method=p_method;
cmd->p1=p1;
cmd->p2=p2;
-
+
unlock();
-
+
if (sync) sync->post();
}
template<class T, class M, class P1, class P2, class P3>
void push( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3 ) {
-
+
Command3<T,M,P1,P2,P3> * cmd = allocate_and_lock< Command3<T,M,P1,P2,P3> >();
-
+
cmd->instance=p_instance;
cmd->method=p_method;
cmd->p1=p1;
cmd->p2=p2;
cmd->p3=p3;
-
+
unlock();
-
+
if (sync) sync->post();
}
template<class T, class M, class P1, class P2, class P3, class P4>
void push( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4 ) {
-
+
Command4<T,M,P1,P2,P3,P4> * cmd = allocate_and_lock< Command4<T,M,P1,P2,P3,P4> >();
-
+
cmd->instance=p_instance;
cmd->method=p_method;
cmd->p1=p1;
cmd->p2=p2;
cmd->p3=p3;
cmd->p4=p4;
-
+
unlock();
-
+
if (sync) sync->post();
}
template<class T, class M, class P1, class P2, class P3, class P4, class P5>
void push( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5 ) {
-
+
Command5<T,M,P1,P2,P3,P4,P5> * cmd = allocate_and_lock< Command5<T,M,P1,P2,P3,P4,P5> >();
-
+
cmd->instance=p_instance;
cmd->method=p_method;
cmd->p1=p1;
@@ -595,17 +595,17 @@ public:
cmd->p3=p3;
cmd->p4=p4;
cmd->p5=p5;
-
+
unlock();
-
+
if (sync) sync->post();
}
template<class T, class M, class P1, class P2, class P3, class P4, class P5, class P6>
void push( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6 ) {
-
+
Command6<T,M,P1,P2,P3,P4,P5,P6> * cmd = allocate_and_lock< Command6<T,M,P1,P2,P3,P4,P5,P6> >();
-
+
cmd->instance=p_instance;
cmd->method=p_method;
cmd->p1=p1;
@@ -614,17 +614,17 @@ public:
cmd->p4=p4;
cmd->p5=p5;
cmd->p6=p6;
-
+
unlock();
-
+
if (sync) sync->post();
}
template<class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7>
void push( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7 ) {
-
+
Command7<T,M,P1,P2,P3,P4,P5,P6,P7> * cmd = allocate_and_lock< Command7<T,M,P1,P2,P3,P4,P5,P6,P7> >();
-
+
cmd->instance=p_instance;
cmd->method=p_method;
cmd->p1=p1;
@@ -634,19 +634,19 @@ public:
cmd->p5=p5;
cmd->p6=p6;
cmd->p7=p7;
-
+
unlock();
-
+
if (sync) sync->post();
}
/*** PUSH AND RET COMMANDS ***/
-
-
+
+
template<class T, class M,class R>
void push_and_ret( T * p_instance, M p_method, R* r_ret) {
-
+
CommandRet0<T,M,R> * cmd = allocate_and_lock< CommandRet0<T,M,R> >();
-
+
cmd->instance=p_instance;
cmd->method=p_method;
cmd->ret=r_ret;
@@ -654,34 +654,34 @@ public:
cmd->sync=ss;
unlock();
-
+
if (sync) sync->post();
ss->sem->wait();
}
template<class T, class M, class P1,class R>
void push_and_ret( T * p_instance, M p_method, P1 p1, R* r_ret) {
-
+
CommandRet1<T,M,P1,R> * cmd = allocate_and_lock< CommandRet1<T,M,P1,R> >();
-
+
cmd->instance=p_instance;
cmd->method=p_method;
cmd->p1=p1;
cmd->ret=r_ret;
SyncSemaphore *ss=_alloc_sync_sem();
cmd->sync=ss;
-
+
unlock();
-
+
if (sync) sync->post();
ss->sem->wait();
}
template<class T, class M, class P1, class P2,class R>
void push_and_ret( T * p_instance, M p_method, P1 p1, P2 p2, R* r_ret) {
-
+
CommandRet2<T,M,P1,P2,R> * cmd = allocate_and_lock< CommandRet2<T,M,P1,P2,R> >();
-
+
cmd->instance=p_instance;
cmd->method=p_method;
cmd->p1=p1;
@@ -691,16 +691,16 @@ public:
cmd->sync=ss;
unlock();
-
+
if (sync) sync->post();
ss->sem->wait();
}
template<class T, class M, class P1, class P2, class P3,class R>
void push_and_ret( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, R* r_ret ) {
-
+
CommandRet3<T,M,P1,P2,P3,R> * cmd = allocate_and_lock< CommandRet3<T,M,P1,P2,P3,R> >();
-
+
cmd->instance=p_instance;
cmd->method=p_method;
cmd->p1=p1;
@@ -711,16 +711,16 @@ public:
cmd->sync=ss;
unlock();
-
+
if (sync) sync->post();
ss->sem->wait();
}
template<class T, class M, class P1, class P2, class P3, class P4,class R>
void push_and_ret( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, R* r_ret ) {
-
+
CommandRet4<T,M,P1,P2,P3,P4,R> * cmd = allocate_and_lock< CommandRet4<T,M,P1,P2,P3,P4,R> >();
-
+
cmd->instance=p_instance;
cmd->method=p_method;
cmd->p1=p1;
@@ -732,16 +732,16 @@ public:
cmd->sync=ss;
unlock();
-
+
if (sync) sync->post();
ss->sem->wait();
}
template<class T, class M, class P1, class P2, class P3, class P4, class P5,class R>
void push_and_ret( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, R* r_ret ) {
-
+
CommandRet5<T,M,P1,P2,P3,P4,P5,R> * cmd = allocate_and_lock< CommandRet5<T,M,P1,P2,P3,P4,P5,R> >();
-
+
cmd->instance=p_instance;
cmd->method=p_method;
cmd->p1=p1;
@@ -754,16 +754,16 @@ public:
cmd->sync=ss;
unlock();
-
+
if (sync) sync->post();
ss->sem->wait();
}
template<class T, class M, class P1, class P2, class P3, class P4, class P5, class P6,class R>
void push_and_ret( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, R* r_ret ) {
-
+
CommandRet6<T,M,P1,P2,P3,P4,P5,P6,R> * cmd = allocate_and_lock< CommandRet6<T,M,P1,P2,P3,P4,P5,P6,R> >();
-
+
cmd->instance=p_instance;
cmd->method=p_method;
cmd->p1=p1;
@@ -777,16 +777,16 @@ public:
cmd->sync=ss;
unlock();
-
+
if (sync) sync->post();
ss->sem->wait();
}
-
+
template<class T, class M, class P1, class P2, class P3, class P4, class P5, class P6,class P7,class R>
void push_and_ret( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6,P7 p7, R* r_ret ) {
-
+
CommandRet7<T,M,P1,P2,P3,P4,P5,P6,P7,R> * cmd = allocate_and_lock< CommandRet7<T,M,P1,P2,P3,P4,P5,P6,P7,R> >();
-
+
cmd->instance=p_instance;
cmd->method=p_method;
cmd->p1=p1;
@@ -801,7 +801,7 @@ public:
cmd->sync=ss;
unlock();
-
+
if (sync) sync->post();
ss->sem->wait();
}
@@ -975,12 +975,12 @@ public:
ERR_FAIL_COND(!sync);
sync->wait();
lock();
- flush_one();
+ flush_one();
unlock();
}
-
+
void flush_all() {
-
+
//ERR_FAIL_COND(sync);
lock();
while (true) {
@@ -990,10 +990,10 @@ public:
}
unlock();
}
-
+
CommandQueueMT(bool p_sync);
~CommandQueueMT();
-
+
};
#endif
diff --git a/core/dvector.h b/core/dvector.h
index 17431b33a6..fbb1fc4824 100644
--- a/core/dvector.h
+++ b/core/dvector.h
@@ -43,18 +43,18 @@ template<class T>
class DVector {
mutable MID mem;
-
-
+
+
void copy_on_write() {
-
+
if (!mem.is_valid())
return;
if (dvector_lock)
dvector_lock->lock();
-
+
MID_Lock lock( mem );
-
+
if ( *(int*)lock.data() == 1 ) {
// one reference, means no refcount changes
@@ -62,114 +62,114 @@ class DVector {
dvector_lock->unlock();
return;
}
-
+
MID new_mem= dynalloc( mem.get_size() );
-
+
if (!new_mem.is_valid()) {
-
+
if (dvector_lock)
dvector_lock->unlock();
- ERR_FAIL_COND( new_mem.is_valid() ); // out of memory
+ ERR_FAIL_COND( new_mem.is_valid() ); // out of memory
}
-
+
MID_Lock dst_lock( new_mem );
-
+
int *rc = (int*)dst_lock.data();
-
+
*rc=1;
-
+
T * dst = (T*)(rc + 1 );
-
+
T * src =(T*) ((int*)lock.data() + 1 );
-
+
int count = (mem.get_size() - sizeof(int)) / sizeof(T);
-
+
for (int i=0;i<count;i++) {
-
+
memnew_placement( &dst[i], T(src[i]) );
}
-
+
(*(int*)lock.data())--;
-
+
// unlock all
dst_lock=MID_Lock();
lock=MID_Lock();
-
+
mem=new_mem;
-
+
if (dvector_lock)
dvector_lock->unlock();
-
+
}
-
+
void reference( const DVector& p_dvector ) {
-
+
unreference();
-
+
if (dvector_lock)
dvector_lock->lock();
-
+
if (!p_dvector.mem.is_valid()) {
-
+
if (dvector_lock)
dvector_lock->unlock();
- return;
+ return;
}
-
+
MID_Lock lock(p_dvector.mem);
-
+
int * rc = (int*)lock.data();
(*rc)++;
-
+
lock = MID_Lock();
mem=p_dvector.mem;
-
+
if (dvector_lock)
dvector_lock->unlock();
-
+
}
-
-
+
+
void unreference() {
-
+
if (dvector_lock)
dvector_lock->lock();
-
+
if (!mem.is_valid()) {
-
+
if (dvector_lock)
dvector_lock->unlock();
- return;
+ return;
}
-
+
MID_Lock lock(mem);
-
+
int * rc = (int*)lock.data();
(*rc)--;
-
+
if (*rc==0) {
// no one else using it, destruct
-
+
T * t= (T*)(rc+1);
int count = (mem.get_size() - sizeof(int)) / sizeof(T);
-
+
for (int i=0;i<count;i++) {
-
+
t[i].~T();
}
-
+
}
-
-
+
+
lock = MID_Lock();
-
+
mem = MID ();
-
+
if (dvector_lock)
dvector_lock->unlock();
-
+
}
-
+
public:
class Read {
@@ -177,10 +177,10 @@ public:
MID_Lock lock;
const T * mem;
public:
-
+
_FORCE_INLINE_ const T& operator[](int p_index) const { return mem[p_index]; }
_FORCE_INLINE_ const T *ptr() const { return mem; }
-
+
Read() { mem=NULL; }
};
@@ -189,32 +189,32 @@ public:
MID_Lock lock;
T * mem;
public:
-
+
_FORCE_INLINE_ T& operator[](int p_index) { return mem[p_index]; }
_FORCE_INLINE_ T *ptr() { return mem; }
-
+
Write() { mem=NULL; }
};
Read read() const {
-
+
Read r;
- if (mem.is_valid()) {
+ if (mem.is_valid()) {
r.lock = MID_Lock( mem );
r.mem = (const T*)((int*)r.lock.data()+1);
}
- return r;
+ return r;
}
Write write() {
-
+
Write w;
if (mem.is_valid()) {
copy_on_write();
w.lock = MID_Lock( mem );
w.mem = (T*)((int*)w.lock.data()+1);
}
- return w;
+ return w;
}
template<class MC>
@@ -280,12 +280,12 @@ public:
bool is_locked() const { return mem.is_locked(); }
-
+
inline const T operator[](int p_index) const;
Error resize(int p_size);
-
-
+
+
void operator=(const DVector& p_dvector) { reference(p_dvector); }
DVector() {}
DVector(const DVector& p_dvector) { reference(p_dvector); }
@@ -308,7 +308,7 @@ T DVector<T>::get(int p_index) const {
template<class T>
void DVector<T>::set(int p_index, const T& p_val) {
- if (p_index<0 || p_index>=size()) {
+ if (p_index<0 || p_index>=size()) {
ERR_FAIL_COND(p_index<0 || p_index>=size());
}
@@ -332,7 +332,7 @@ const T DVector<T>::operator[](int p_index) const {
}
Read r = read();
-
+
return r[p_index];
}
@@ -344,83 +344,83 @@ Error DVector<T>::resize(int p_size) {
dvector_lock->lock();
bool same = p_size==size();
-
+
if (dvector_lock)
dvector_lock->unlock();
- // no further locking is necesary because we are supposed to own the only copy of this (using copy on write)
-
+ // no further locking is necesary because we are supposed to own the only copy of this (using copy on write)
+
if (same)
return OK;
if (p_size == 0 ) {
-
+
unreference();
return OK;
}
copy_on_write(); // make it unique
-
+
ERR_FAIL_COND_V( mem.is_locked(), ERR_LOCKED ); // if after copy on write, memory is locked, fail.
-
+
if (p_size > size() ) {
-
+
int oldsize=size();
-
+
MID_Lock lock;
-
+
if (oldsize==0) {
mem = dynalloc( p_size * sizeof(T) + sizeof(int) );
lock=MID_Lock(mem);
int *rc = ((int*)lock.data());
*rc=1;
-
+
} else {
if (dynrealloc( mem, p_size * sizeof(T) + sizeof(int) )!=OK ) {
-
+
ERR_FAIL_V(ERR_OUT_OF_MEMORY); // out of memory
}
-
- lock=MID_Lock(mem);
+
+ lock=MID_Lock(mem);
}
-
-
-
-
+
+
+
+
T *t = (T*)((int*)lock.data() + 1);
-
+
for (int i=oldsize;i<p_size;i++) {
-
+
memnew_placement(&t[i], T );
}
-
+
lock = MID_Lock(); // clear
} else {
-
+
int oldsize=size();
-
+
MID_Lock lock(mem);
-
-
+
+
T *t = (T*)((int*)lock.data() + 1);
-
+
for (int i=p_size;i<oldsize;i++) {
-
+
t[i].~T();
}
-
+
lock = MID_Lock(); // clear
-
+
if (dynrealloc( mem, p_size * sizeof(T) + sizeof(int) )!=OK ) {
-
- ERR_FAIL_V(ERR_OUT_OF_MEMORY); // wtf error
+
+ ERR_FAIL_V(ERR_OUT_OF_MEMORY); // wtf error
}
-
-
+
+
}
-
+
return OK;
}
diff --git a/core/error_macros.h b/core/error_macros.h
index 47b1de5df3..6d931e899e 100644
--- a/core/error_macros.h
+++ b/core/error_macros.h
@@ -33,12 +33,12 @@
/**
* 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
- * engine can stay working well.
+ * engine can stay working well.
* In most cases, bugs and/or invalid data are not fatal and should never allow a perfectly running application
* to fail or crash.
*/
-/**
+/**
* Pointer to the error macro priting function. Reassign to any function to have errors printed
*/
@@ -136,7 +136,7 @@ extern bool _err_error_exists;
return m_retval; \
}else _err_error_exists=false; } \
-/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
+/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
* the function will exit.
*/
@@ -146,7 +146,7 @@ extern bool _err_error_exists;
return; \
}else _err_error_exists=false; } \
-/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
+/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
* the function will exit.
* This function returns an error value, if returning Error, please select the most
* appropriate error condition from error_macros.h
@@ -158,7 +158,7 @@ extern bool _err_error_exists;
return m_retval; \
}else _err_error_exists=false; } \
-/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
+/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
* the loop will skip to the next iteration.
*/
@@ -168,7 +168,7 @@ extern bool _err_error_exists;
continue;\
} else _err_error_exists=false;} \
-/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
+/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
* the loop will break
*/
diff --git a/core/event_queue.cpp b/core/event_queue.cpp
index 088e80b266..53638c5431 100644
--- a/core/event_queue.cpp
+++ b/core/event_queue.cpp
@@ -43,118 +43,118 @@ Error EventQueue::push_call(uint32_t p_instance_ID, const StringName& p_method,
args=2;
else if (p_arg1.get_type()!=Variant::NIL)
args=1;
- else
+ else
args=0;
-
+
room_needed+=sizeof(Variant)*args;
-
+
ERR_FAIL_COND_V( (buffer_end+room_needed) >= buffer_size , ERR_OUT_OF_MEMORY );
Event * ev = memnew_placement( &event_buffer[ buffer_end ], Event );
ev->args=args;
ev->instance_ID=p_instance_ID;
ev->method=p_method;
-
+
buffer_end+=sizeof(Event);
-
+
if (args>=1) {
-
+
Variant * v = memnew_placement( &event_buffer[ buffer_end ], Variant );
buffer_end+=sizeof(Variant);
*v=p_arg1;
}
if (args>=2) {
-
+
Variant * v = memnew_placement( &event_buffer[ buffer_end ], Variant );
buffer_end+=sizeof(Variant);
*v=p_arg2;
}
if (args>=3) {
-
+
Variant * v = memnew_placement( &event_buffer[ buffer_end ], Variant );
buffer_end+=sizeof(Variant);
*v=p_arg3;
-
+
}
if (args>=4) {
-
+
Variant * v = memnew_placement( &event_buffer[ buffer_end ], Variant );
buffer_end+=sizeof(Variant);
*v=p_arg4;
}
if (args>=5) {
-
+
Variant * v = memnew_placement( &event_buffer[ buffer_end ], Variant );
buffer_end+=sizeof(Variant);
*v=p_arg5;
}
-
+
if (buffer_max_used>buffer_end);
buffer_max_used=buffer_end;
-
+
return OK;
}
void EventQueue::flush_events() {
uint32_t read_pos=0;
-
+
while (read_pos < buffer_end ) {
-
+
Event *event = (Event*)&event_buffer[ read_pos ];
Variant *args= (Variant*)(event+1);
Object *obj = ObjectDB::get_instance(event->instance_ID);
-
- if (obj) {
+
+ if (obj) {
// events don't expect a return value
- obj->call( event->method,
+ obj->call( event->method,
(event->args>=1) ? args[0] : Variant(),
(event->args>=2) ? args[1] : Variant(),
(event->args>=3) ? args[2] : Variant(),
(event->args>=4) ? args[3] : Variant(),
(event->args>=5) ? args[4] : Variant() );
}
-
+
if (event->args>=1) args[0].~Variant();
if (event->args>=2) args[1].~Variant();
if (event->args>=3) args[2].~Variant();
if (event->args>=4) args[3].~Variant();
if (event->args>=5) args[4].~Variant();
event->~Event();
-
+
read_pos+=sizeof(Event)+sizeof(Variant)*event->args;
}
-
+
buffer_end=0; // reset buffer
}
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() {
uint32_t read_pos=0;
-
+
while (read_pos < buffer_end ) {
-
+
Event *event = (Event*)&event_buffer[ read_pos ];
Variant *args= (Variant*)(event+1);
for (int i=0;i<event->args;i++)
args[i].~Variant();
event->~Event();
-
+
read_pos+=sizeof(Event)+sizeof(Variant)*event->args;
}
-
+
memdelete_arr(event_buffer);
event_buffer=NULL;
}
diff --git a/core/event_queue.h b/core/event_queue.h
index af0a4df2b8..99e853fd28 100644
--- a/core/event_queue.h
+++ b/core/event_queue.h
@@ -36,18 +36,18 @@
class EventQueue {
enum {
-
+
DEFAULT_EVENT_QUEUE_SIZE_KB=256
};
struct Event {
-
+
uint32_t instance_ID;
StringName method;
int args;
};
-
-
+
+
uint8_t *event_buffer;
uint32_t buffer_end;
uint32_t buffer_max_used;
@@ -57,7 +57,7 @@ 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();
diff --git a/core/globals.cpp b/core/globals.cpp
index d63f9c1bb4..c0c1171ae6 100644
--- a/core/globals.cpp
+++ b/core/globals.cpp
@@ -40,7 +40,7 @@
Globals *Globals::singleton=NULL;
Globals *Globals::get_singleton() {
-
+
return singleton;
}
@@ -108,7 +108,7 @@ bool Globals::is_persisting(const String& p_name) const {
String Globals::globalize_path(const String& p_path) const {
-
+
if (p_path.begins_with("res://")) {
if (resource_path != "") {
@@ -125,7 +125,7 @@ String Globals::globalize_path(const String& p_path) const {
bool Globals::_set(const StringName& p_name, const Variant& p_value) {
_THREAD_SAFE_METHOD_
-
+
if (p_value.get_type()==Variant::NIL)
props.erase(p_name);
else {
@@ -174,7 +174,7 @@ bool Globals::_get(const StringName& p_name,Variant &r_ret) const {
return false;
r_ret=props[p_name].variant;
return true;
-
+
}
struct _VCSort {
@@ -188,13 +188,13 @@ struct _VCSort {
};
void Globals::_get_property_list(List<PropertyInfo> *p_list) const {
-
+
_THREAD_SAFE_METHOD_
Set<_VCSort> vclist;
-
+
for(Map<StringName,VariantContainer>::Element *E=props.front();E;E=E->next()) {
-
+
const VariantContainer *v=&E->get();
if (v->hide_from_editor)
@@ -250,7 +250,7 @@ bool Globals::_load_resource_pack(const String& p_pack) {
Error Globals::setup(const String& p_path,const String & p_main_pack) {
//an absolute mess of a function, must be cleaned up and reorganized somehow at some point
-
+
//_load_settings(p_path+"/override.cfg");
if (p_main_pack!="") {
@@ -292,7 +292,7 @@ Error Globals::setup(const String& p_path,const String & p_main_pack) {
}
}
-
+
if (FileAccessNetworkClient::get_singleton()) {
@@ -332,7 +332,7 @@ Error Globals::setup(const String& p_path,const String & p_main_pack) {
resource_path = p_path;
} else {
-
+
d->change_dir(p_path);
String candidate = d->get_current_dir();
@@ -395,7 +395,7 @@ Error Globals::setup(const String& p_path,const String & p_main_pack) {
}
bool Globals::has(String p_var) const {
-
+
_THREAD_SAFE_METHOD_
return props.has(p_var);
@@ -1410,7 +1410,7 @@ void Globals::_bind_methods() {
}
Globals::Globals() {
-
+
singleton=this;
last_order=0;
@@ -1531,7 +1531,7 @@ Globals::Globals() {
Globals::~Globals() {
-
+
singleton=NULL;
}
diff --git a/core/globals.h b/core/globals.h
index 8951f5fbd2..68bb859ace 100644
--- a/core/globals.h
+++ b/core/globals.h
@@ -38,7 +38,7 @@
class Globals : public Object {
-
+
OBJ_TYPE( Globals, Object );
_THREAD_SAFE_CLASS_
@@ -77,13 +77,13 @@ 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;
-
+
static Globals *singleton;
-
+
Error _load_settings(const String p_path);
Error _load_settings_binary(const String p_path);
@@ -101,7 +101,7 @@ 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;
@@ -110,13 +110,13 @@ public:
bool is_persisting(const String& p_name) const;
String get_resource_path() const;
-
+
static Globals *get_singleton();
void clear(const String& p_name);
int get_order(const String& p_name) const;
void set_order(const String& p_name, int p_order);
-
+
Error setup(const String& p_path, const String &p_main_pack);
Error save_custom(const String& p_path="",const CustomMap& p_custom=CustomMap(),const Set<String>& p_ignore_masks=Set<String>());
@@ -141,7 +141,7 @@ public:
void set_registering_order(bool p_registering);
- Globals();
+ Globals();
~Globals();
};
diff --git a/core/hash_map.h b/core/hash_map.h
index 33eb25652c..e83710c700 100644
--- a/core/hash_map.h
+++ b/core/hash_map.h
@@ -38,7 +38,7 @@
class HashMapHahserDefault {
public:
-
+
static _FORCE_INLINE_ uint32_t hash(const String &p_string) { return p_string.hash(); }
static _FORCE_INLINE_ uint32_t hash(const char *p_cstr) { return hash_djb2(p_cstr); }
static _FORCE_INLINE_ uint32_t hash(const uint64_t p_int) {
@@ -66,8 +66,8 @@ public:
/**
* @class HashMap
- * @author Juan Linietsky <reduzio@gmail.com>
- *
+ * @author Juan Linietsky <reduzio@gmail.com>
+ *
* Implementation of a standard Hashing HashMap, for quick lookups of Data associated with a Key.
* The implementation provides hashers for the default types, if you need a special kind of hasher, provide
* your own.
@@ -77,213 +77,213 @@ public:
* @param MIN_HASH_TABLE_POWER Miminum size of the hash table, as a power of two. You rarely need to change this parameter.
* @param RELATIONSHIP Relationship at which the hash table is resized. if amount of elements is RELATIONSHIP
* times bigger than the hash table, table is resized to solve this condition. if RELATIONSHIP is zero, table is always MIN_HASH_TABLE_POWER.
- *
+ *
*/
template<class TKey, class TData, class Hasher=HashMapHahserDefault,uint8_t MIN_HASH_TABLE_POWER=3,uint8_t RELATIONSHIP=8>
class HashMap {
-public:
-
+public:
+
struct Pair {
-
+
TKey key;
TData data;
-
+
Pair() {}
Pair(const TKey& p_key, const TData& p_data) { key=p_key; data=p_data; }
};
-
-
-private:
+
+
+private:
struct Entry {
-
+
uint32_t hash;
Entry *next;
Pair pair;
-
+
Entry() { next=0; }
};
-
+
Entry **hash_table;
uint8_t hash_table_power;
uint32_t elements;
-
+
void make_hash_table() {
-
+
ERR_FAIL_COND( hash_table );
-
-
+
+
hash_table = memnew_arr( Entry*, (1<<MIN_HASH_TABLE_POWER) );
-
+
hash_table_power = MIN_HASH_TABLE_POWER;
elements=0;
for (int i=0;i<(1<<MIN_HASH_TABLE_POWER);i++)
hash_table[i]=0;
}
-
+
void erase_hash_table() {
-
+
ERR_FAIL_COND(elements);
-
+
memdelete_arr( hash_table );
hash_table=0;
- hash_table_power=0;
- elements=0;
- }
-
+ hash_table_power=0;
+ elements=0;
+ }
+
void check_hash_table() {
int new_hash_table_power=-1;
-
+
if ((int)elements > ( (1<<hash_table_power) * RELATIONSHIP ) ) {
/* rehash up */
new_hash_table_power=hash_table_power+1;
-
+
while( (int)elements > ( (1<<new_hash_table_power) * RELATIONSHIP ) ) {
-
+
new_hash_table_power++;
}
-
+
} else if ( (hash_table_power>(int)MIN_HASH_TABLE_POWER) && ((int)elements < ( (1<<(hash_table_power-1)) * RELATIONSHIP ) ) ) {
-
+
/* rehash down */
new_hash_table_power=hash_table_power-1;
-
+
while( (int)elements < ( (1<<(new_hash_table_power-1)) * RELATIONSHIP ) ) {
-
+
new_hash_table_power--;
}
-
+
if (new_hash_table_power<(int)MIN_HASH_TABLE_POWER)
new_hash_table_power=MIN_HASH_TABLE_POWER;
}
-
-
+
+
if (new_hash_table_power==-1)
return;
-
+
Entry ** new_hash_table = memnew_arr( Entry*, (1<<new_hash_table_power) );
if (!new_hash_table) {
-
+
ERR_PRINT("Out of Memory");
return;
}
-
+
for (int i=0;i<(1<<new_hash_table_power);i++) {
-
+
new_hash_table[i]=0;
}
-
+
for (int i=0;i<(1<<hash_table_power);i++) {
-
+
while( hash_table[i] ) {
-
+
Entry *se=hash_table[i];
hash_table[i]=se->next;
int new_pos = se->hash & ((1<<new_hash_table_power)-1);
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;
+ hash_table_power=new_hash_table_power;
}
/* I want to have only one function.. */
_FORCE_INLINE_ const Entry * get_entry( const TKey& p_key ) const {
-
+
uint32_t hash = Hasher::hash( p_key );
uint32_t index = hash&((1<<hash_table_power)-1);
-
+
Entry *e = hash_table[index];
-
+
while (e) {
-
+
/* checking hash first avoids comparing key, which may take longer */
if (e->hash == hash && e->pair.key == p_key ) {
-
+
/* the pair exists in this hashtable, so just update data */
return e;
}
-
+
e=e->next;
}
-
+
return NULL;
}
-
+
Entry * create_entry(const TKey& p_key) {
-
+
/* if entry doesn't exist, create it */
Entry *e = memnew( Entry );
ERR_FAIL_COND_V(!e,NULL); /* out of memory */
uint32_t hash = Hasher::hash( p_key );
uint32_t index = hash&((1<<hash_table_power)-1);
- e->next = hash_table[index];
+ e->next = hash_table[index];
e->hash = hash;
e->pair.key=p_key;
-
+
hash_table[index]=e;
elements++;
-
+
return e;
}
-
-
+
+
void copy_from(const HashMap& p_t) {
-
+
if (&p_t==this)
return; /* much less bother with that */
-
+
clear();
-
+
if (!p_t.hash_table || p_t.hash_table_power==0)
return; /* not copying from empty table */
-
+
hash_table = memnew_arr(Entry*,1<<p_t.hash_table_power);
hash_table_power=p_t.hash_table_power;
elements=p_t.elements;
-
+
for (int i=0;i<( 1<<p_t.hash_table_power );i++) {
-
+
hash_table[i]=NULL;
/* elements will be in the reverse order, but it doesn't matter */
-
+
const Entry *e = p_t.hash_table[i];
-
+
while(e) {
-
+
Entry *le = memnew( Entry ); /* local entry */
-
+
*le=*e; /* copy data */
-
+
/* add to list and reassign pointers */
le->next=hash_table[i];
hash_table[i]=le;
-
+
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 ) {
Entry *e=NULL;
@@ -291,63 +291,63 @@ public:
make_hash_table(); // if no table, make one
else
e = const_cast<Entry*>( get_entry(p_pair.key) );
-
+
/* if we made it up to here, the pair doesn't exist, create and assign */
-
+
if (!e) {
-
+
e=create_entry(p_pair.key);
if (!e)
return;
check_hash_table(); // perform mantenience routine
}
-
+
e->pair.data = p_pair.data;
-
+
}
-
-
+
+
bool has( const TKey& p_key ) const {
-
+
return getptr(p_key)!=NULL;
}
-
+
/**
- * Get a key from data, return a const reference.
+ * Get a key from data, return a const reference.
* WARNING: this doesn't check errors, use either getptr and check NULL, or check
* first with has(key)
*/
-
+
const TData& get( const TKey& p_key ) const {
-
+
const TData* res = getptr(p_key);
ERR_FAIL_COND_V(!res,*res);
return *res;
}
-
+
TData& get( const TKey& p_key ) {
-
+
TData* res = getptr(p_key);
ERR_FAIL_COND_V(!res,*res);
return *res;
}
-
+
/**
* Same as get, except it can return NULL when item was not found.
* This is mainly used for speed purposes.
*/
-
+
_FORCE_INLINE_ TData* getptr( const TKey& p_key ) {
-
+
if (!hash_table)
return NULL;
-
+
Entry *e=const_cast<Entry*>(get_entry(p_key ));
-
+
if (e)
return &e->pair.data;
-
+
return NULL;
}
@@ -427,108 +427,108 @@ public:
/**
* Erase an item, return true if erasing was succesful
*/
-
+
bool erase( const TKey& p_key ) {
-
+
if (!hash_table)
return false;
-
+
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) {
-
+
/* checking hash first avoids comparing key, which may take longer */
if (e->hash == hash && e->pair.key == p_key ) {
-
+
if (p) {
-
+
p->next=e->next;
- } else {
+ } else {
//begin of list
hash_table[index]=e->next;
}
-
+
memdelete(e);
elements--;
-
+
if (elements==0)
erase_hash_table();
else
- check_hash_table();
+ check_hash_table();
return true;
}
-
+
p=e;
e=e->next;
}
-
-
+
+
return false;
-
+
}
-
+
inline const TData& operator[](const TKey& p_key) const { //constref
-
+
return get(p_key);
}
inline TData& operator[](const TKey& p_key ) { //assignment
-
+
Entry *e=NULL;
if (!hash_table)
make_hash_table(); // if no table, make one
else
e = const_cast<Entry*>( get_entry(p_key) );
-
+
/* if we made it up to here, the pair doesn't exist, create */
if (!e) {
-
+
e=create_entry(p_key);
if (!e)
return *(TData*)NULL; /* panic! */
check_hash_table(); // perform mantenience routine
}
-
+
return e->pair.data;
-
+
}
-
- /**
- * Get the next key to p_key, and the first key if p_key is null.
+
+ /**
+ * Get the next key to p_key, and the first key if p_key is null.
* Returns a pointer to the next key if found, NULL otherwise.
* Adding/Removing elements while iterating will, of course, have unexpected results, don't do it.
- *
+ *
* Example:
- *
+ *
* const TKey *k=NULL;
- *
+ *
* while( (k=table.next(k)) ) {
- *
+ *
* print( *k );
* }
- *
+ *
*/
const TKey* next(const TKey* p_key) const {
-
+
if (!hash_table) return NULL;
-
+
if (!p_key) { /* get the first key */
-
+
for (int i=0;i<(1<<hash_table_power);i++) {
-
+
if (hash_table[i]) {
return &hash_table[i]->pair.key;
}
}
} else { /* get the next key */
-
+
const Entry *e = get_entry( *p_key );
ERR_FAIL_COND_V( !e, NULL ); /* invalid key supplied */
-
+
if (e->next) {
/* if there is a "next" in the list, return that */
return &e->next->pair.key;
@@ -537,60 +537,60 @@ public:
uint32_t index = e->hash&((1<<hash_table_power)-1);
index++;
for (int i=index;i<(1<<hash_table_power);i++) {
-
+
if (hash_table[i]) {
return &hash_table[i]->pair.key;
}
}
}
-
+
/* nothing found, was at end */
-
+
}
-
-
+
+
return NULL; /* nothing found */
}
-
+
inline unsigned int size() const {
-
+
return elements;
}
-
+
inline bool empty() const {
-
+
return elements==0;
}
-
+
void clear() {
-
+
/* clean up */
if (hash_table) {
for (int i=0;i<(1<<hash_table_power);i++) {
-
+
while (hash_table[i]) {
-
+
Entry *e=hash_table[i];
hash_table[i]=e->next;
memdelete( e );
}
}
-
+
memdelete_arr( hash_table );
}
-
+
hash_table=0;
hash_table_power=0;
- elements=0;
+ elements=0;
}
-
-
+
+
void operator=(const HashMap& p_table) {
-
+
copy_from(p_table);
}
-
- HashMap() {
+
+ HashMap() {
hash_table=NULL;
elements=0;
hash_table_power=0;
@@ -609,18 +609,18 @@ public:
}
}
- HashMap(const HashMap& p_table) {
-
+ HashMap(const HashMap& p_table) {
+
hash_table=NULL;
elements=0;
hash_table_power=0;
-
+
copy_from(p_table);
-
+
}
-
+
~HashMap() {
-
+
clear();
}
diff --git a/core/hashfuncs.h b/core/hashfuncs.h
index c2ed5bd679..a917ee5edb 100644
--- a/core/hashfuncs.h
+++ b/core/hashfuncs.h
@@ -47,10 +47,10 @@ static inline uint32_t hash_djb2(const char *p_cstr) {
const unsigned char* chr=(const unsigned char*)p_cstr;
uint32_t hash = 5381;
uint32_t c;
-
+
while ((c = *chr++))
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
-
+
return hash;
}
@@ -86,7 +86,7 @@ static inline uint32_t make_uint32_t(T p_in) {
T t;
uint32_t _u32;
} _u;
- _u._u32=0;
+ _u._u32=0;
_u.t=p_in;
return _u._u32;
}
@@ -106,7 +106,7 @@ static inline uint64_t make_uint64_t(T p_in) {
uint64_t _u64;
} _u;
_u._u64=0; // in case p_in is smaller
-
+
_u.t=p_in;
return _u._u64;
}
diff --git a/core/image.cpp b/core/image.cpp
index 798fc41f40..184ab70dc4 100644
--- a/core/image.cpp
+++ b/core/image.cpp
@@ -382,7 +382,7 @@ void Image::convert( Format p_new_format ){
Image new_img(width,height,0,p_new_format);
-
+
int len=data.size();
DVector<uint8_t>::Read r = data.read();
@@ -413,7 +413,7 @@ void Image::convert( Format p_new_format ){
w = DVector<uint8_t>::Write();
bool gen_mipmaps=mipmaps>0;
-
+
*this=new_img;
if (gen_mipmaps)
@@ -643,13 +643,13 @@ void Image::resize( int p_width, int p_height, Interpolation p_interpolation ) {
ERR_FAIL_COND(p_height<=0);
ERR_FAIL_COND(p_width>MAX_WIDTH);
ERR_FAIL_COND(p_height>MAX_HEIGHT);
-
+
if (p_width==width && p_height==height)
return;
-
+
Image dst( p_width, p_height, 0, format );
-
+
if (format==FORMAT_INDEXED)
p_interpolation=INTERPOLATE_NEAREST;
@@ -714,34 +714,34 @@ void Image::crop( int p_width, int p_height ) {
ERR_FAIL_COND(p_height<=0);
ERR_FAIL_COND(p_width>MAX_WIDTH);
ERR_FAIL_COND(p_height>MAX_HEIGHT);
-
+
/* to save memory, cropping should be done in-place, however, since this function
will most likely either not be used much, or in critical areas, for now it wont, because
it's a waste of time. */
if (p_width==width && p_height==height)
return;
-
+
Image dst( p_width, p_height,0, format );
-
+
for (int y=0;y<p_height;y++) {
-
+
for (int x=0;x<p_width;x++) {
Color col = (x>=width || y>=height)? Color() : get_pixel(x,y);
dst.put_pixel(x,y,col);
}
}
-
+
if (mipmaps>0)
dst.generate_mipmaps();
*this=dst;
-
+
}
void Image::flip_y() {
-
+
if (!_can_modify(format)) {
ERR_EXPLAIN("Cannot flip_y in indexed, compressed or custom image formats.");
ERR_FAIL();
@@ -756,12 +756,12 @@ void Image::flip_y() {
for (int y=0;y<(height/2);y++) {
-
+
for (int x=0;x<width;x++) {
Color up = get_pixel(x,y);
Color down = get_pixel(x,height-y-1);
-
+
put_pixel(x,y,down);
put_pixel(x,height-y-1,up);
}
@@ -783,12 +783,12 @@ void Image::flip_x() {
clear_mipmaps();;
for (int y=0;y<(height/2);y++) {
-
+
for (int x=0;x<width;x++) {
-
+
Color up = get_pixel(x,y);
Color down = get_pixel(width-x-1,y);
-
+
put_pixel(x,y,down);
put_pixel(width-x-1,y,up);
}
@@ -1040,26 +1040,26 @@ void Image::make_normalmap(float p_height_scale) {
}
ERR_FAIL_COND( empty() );
-
+
Image normalmap(width,height,0, FORMAT_RGB);
/*
for (int y=0;y<height;y++) {
for (int x=0;x<width;x++) {
-
+
float center=get_pixel(x,y).gray()/255.0;
float up=(y>0)?get_pixel(x,y-1).gray()/255.0:center;
float down=(y<(height-1))?get_pixel(x,y+1).gray()/255.0:center;
float left=(x>0)?get_pixel(x-1,y).gray()/255.0:center;
float right=(x<(width-1))?get_pixel(x+1,y).gray()/255.0:center;
-
-
+
+
// uhm, how do i do this? ....
-
+
Color result( (uint8_t)((normal.x+1.0)*127.0), (uint8_t)((normal.y+1.0)*127.0), (uint8_t)((normal.z+1.0)*127.0) );
-
+
normalmap.put_pixel( x, y, result );
}
-
+
}
*/
*this=normalmap;
@@ -1071,14 +1071,14 @@ bool Image::empty() const {
}
DVector<uint8_t> Image::get_data() const {
-
+
return data;
}
void Image::create(int p_width, int p_height, bool p_use_mipmaps,Format p_format) {
- int mm=0;
+ int mm=0;
int size = _get_dst_image_size(p_width,p_height,p_format,mm,p_use_mipmaps?-1:0);
data.resize( size );
{
@@ -1095,7 +1095,7 @@ void Image::create(int p_width, int p_height, bool p_use_mipmaps,Format p_format
}
void Image::create(int p_width, int p_height, int p_mipmaps, Format p_format, const DVector<uint8_t>& p_data) {
-
+
ERR_FAIL_INDEX(p_width-1,MAX_WIDTH);
ERR_FAIL_INDEX(p_height-1,MAX_HEIGHT);
@@ -1108,48 +1108,48 @@ void Image::create(int p_width, int p_height, int p_mipmaps, Format p_format, co
ERR_FAIL_COND(p_data.size()!=size);
}
};
-
+
height=p_height;
width=p_width;
format=p_format;
- data=p_data;
+ data=p_data;
mipmaps=p_mipmaps;
}
void Image::create( const char ** p_xpm ) {
-
+
int size_width,size_height;
int pixelchars=0;
mipmaps=0;
bool has_alpha=false;
-
+
enum Status {
READING_HEADER,
READING_COLORS,
READING_PIXELS,
DONE
};
-
+
Status status = READING_HEADER;
int line=0;
-
+
HashMap<String,Color> colormap;
int colormap_size;
-
+
while (status!=DONE) {
-
+
const char * line_ptr = p_xpm[line];
-
-
+
+
switch (status) {
-
+
case READING_HEADER: {
-
+
String line_str=line_ptr;
line_str.replace("\t"," ");
-
+
size_width=line_str.get_slicec(' ',0).to_int();
size_height=line_str.get_slicec(' ',1).to_int();
colormap_size=line_str.get_slicec(' ',2).to_int();
@@ -1161,10 +1161,10 @@ void Image::create( const char ** p_xpm ) {
status=READING_COLORS;
} break;
case READING_COLORS: {
-
+
String colorstring;
for (int i=0;i<pixelchars;i++) {
-
+
colorstring+=*line_ptr;
line_ptr++;
}
@@ -1175,25 +1175,25 @@ void Image::create( const char ** p_xpm ) {
line_ptr++;
}
if (*line_ptr=='c') {
-
+
line_ptr++;
while (*line_ptr==' ' || *line_ptr=='\t' || *line_ptr==0) {
if (*line_ptr==0)
break;
line_ptr++;
}
-
+
if (*line_ptr=='#') {
line_ptr++;
uint8_t col_r;
uint8_t col_g;
uint8_t col_b;
// uint8_t col_a=255;
-
+
for (int i=0;i<6;i++) {
-
+
char v = line_ptr[i];
-
+
if (v>='0' && v<='9')
v-='0';
else if (v>='A' && v<='F')
@@ -1202,7 +1202,7 @@ void Image::create( const char ** p_xpm ) {
v=(v-'a')+10;
else
break;
-
+
switch(i) {
case 0: col_r=v<<4; break;
case 1: col_r|=v; break;
@@ -1211,48 +1211,48 @@ void Image::create( const char ** p_xpm ) {
case 4: col_b=v<<4; break;
case 5: col_b|=v; break;
};
-
+
}
-
+
// magenta mask
if (col_r==255 && col_g==0 && col_b==255) {
-
+
colormap[colorstring]=Color(0,0,0,0);
has_alpha=true;
} else {
colormap[colorstring]=Color(col_r/255.0,col_g/255.0,col_b/255.0,1.0);
}
-
+
}
}
if (line==colormap_size) {
-
+
status=READING_PIXELS;
create(size_width,size_height,0,has_alpha?FORMAT_RGBA:FORMAT_RGB);
}
} break;
case READING_PIXELS: {
-
+
int y=line-colormap_size-1;
for (int x=0;x<size_width;x++) {
-
+
char pixelstr[6]={0,0,0,0,0,0};
for (int i=0;i<pixelchars;i++)
pixelstr[i]=line_ptr[x*pixelchars+i];
-
+
Color *colorptr = colormap.getptr(pixelstr);
ERR_FAIL_COND(!colorptr);
put_pixel(x,y,*colorptr);
-
+
}
-
+
if (y==(size_height-1))
status=DONE;
} break;
default:{}
}
-
+
line++;
}
}
@@ -2022,7 +2022,7 @@ Image Image::compressed(int p_mode) {
};
Image::Image(const char **p_xpm) {
-
+
width=0;
height=0;
mipmaps=0;
diff --git a/core/image.h b/core/image.h
index aea5dc6438..8f8fff755e 100644
--- a/core/image.h
+++ b/core/image.h
@@ -46,7 +46,7 @@ typedef Error (*SavePNGFunc)(const String &p_path, Image& p_img);
class Image {
- enum {
+ enum {
MAX_WIDTH=16384, // force a limit somehow
MAX_HEIGHT=16384// force a limit somehow
};
@@ -55,12 +55,12 @@ public:
static SavePNGFunc save_png_func;
enum Format {
- FORMAT_GRAYSCALE, ///< one byte per pixel, 0-255
- FORMAT_INTENSITY, ///< one byte per pixel, 0-255
- FORMAT_GRAYSCALE_ALPHA, ///< two bytes per pixel, 0-255. alpha 0-255
- FORMAT_RGB, ///< one byte R, one byte G, one byte B
- FORMAT_RGBA, ///< one byte R, one byte G, one byte B, one byte A
- FORMAT_INDEXED, ///< index byte 0-256, and after image end, 256*3 bytes of palette
+ FORMAT_GRAYSCALE, ///< one byte per pixel, 0-255
+ FORMAT_INTENSITY, ///< one byte per pixel, 0-255
+ FORMAT_GRAYSCALE_ALPHA, ///< two bytes per pixel, 0-255. alpha 0-255
+ FORMAT_RGB, ///< one byte R, one byte G, one byte B
+ FORMAT_RGBA, ///< one byte R, one byte G, one byte B, one byte A
+ FORMAT_INDEXED, ///< index byte 0-256, and after image end, 256*3 bytes of palette
FORMAT_INDEXED_ALPHA, ///< index byte 0-256, and after image end, 256*4 bytes of palette (alpha)
FORMAT_YUV_422,
FORMAT_YUV_444,
@@ -89,7 +89,7 @@ public:
static const char* format_names[FORMAT_MAX];
enum Interpolation {
-
+
INTERPOLATE_NEAREST,
INTERPOLATE_BILINEAR,
INTERPOLATE_CUBIC,
@@ -186,7 +186,7 @@ private:
DVector<uint8_t> data;
int width,height,mipmaps;
-
+
_FORCE_INLINE_ BColor _get_pixel(int p_x,int p_y,const unsigned char *p_data,int p_data_size) const;
_FORCE_INLINE_ BColor _get_pixelw(int p_x,int p_y,int p_width,const unsigned char *p_data,int p_data_size) const;
@@ -207,7 +207,7 @@ public:
int get_width() const; ///< Get image width
int get_height() const; ///< Get image height
int get_mipmaps() const;
-
+
/**
* Get a pixel from the image. for grayscale or indexed formats, use Color::gray to obtain the actual
* value.
@@ -217,7 +217,7 @@ public:
* Set a pixel into the image. for grayscale or indexed formats, a suitable Color constructor.
*/
void put_pixel(int p_x,int p_y, const Color& p_color,int p_mipmap=0); /* alpha and index are averaged */
-
+
/**
* Convert the image to another format, as close as it can be done.
*/
@@ -230,7 +230,7 @@ public:
ret.convert((Format)p_new_format);
return ret;
};
-
+
/**
* Get the current image format.
*/
@@ -243,7 +243,7 @@ public:
/**
* Resize the image, using the prefered interpolation method.
* Indexed-Color images always use INTERPOLATE_NEAREST.
- */
+ */
void resize_to_po2(bool p_square=false);
void resize( int p_width, int p_height, Interpolation p_interpolation=INTERPOLATE_BILINEAR );
@@ -252,22 +252,22 @@ public:
* Crop the image to a specific size, if larger, then the image is filled by black
*/
void crop( int p_width, int p_height );
-
-
+
+
void flip_x();
void flip_y();
/**
- * Generate a mipmap to an image (creates an image 1/4 the size, with averaging of 4->1)
+ * Generate a mipmap to an image (creates an image 1/4 the size, with averaging of 4->1)
*/
Error generate_mipmaps(int p_amount=-1,bool p_keep_existing=false);
void clear_mipmaps();
-
+
/**
* Generate a normal map from a grayscale image
*/
-
+
void make_normalmap(float p_height_scale=1.0);
/**
@@ -276,26 +276,26 @@ public:
void create(int p_width, int p_height, bool p_use_mipmaps, Format p_format);
void create(int p_width, int p_height, int p_mipmaps, Format p_format, const DVector<uint8_t>& p_data);
- void create( const char ** p_xpm );
+ void create( const char ** p_xpm );
/**
* returns true when the image is empty (0,0) in size
*/
bool empty() const;
-
+
DVector<uint8_t> get_data() const;
-
+
Error load(const String& p_path);
Error save_png(const String& p_path);
-
- /**
+
+ /**
* create an empty image
*/
Image();
- /**
+ /**
* create an empty image of a specific size and format
*/
Image(int p_width, int p_height, bool p_use_mipmaps, Format p_format);
- /**
+ /**
* import an image of a specific size and format from a pointer
*/
Image(int p_width, int p_height, int p_mipmaps, Format p_format, const DVector<uint8_t>& p_data);
@@ -313,7 +313,7 @@ public:
uint8_t get_indexed_pixel(int p_x, int p_y,int p_mipmap=0) const;
void set_pallete(const DVector<uint8_t>& p_data);
-
+
static int get_format_pixel_size(Format p_format);
static int get_format_pixel_rshift(Format p_format);
static int get_format_pallete_size(Format p_format);
diff --git a/core/input_map.cpp b/core/input_map.cpp
index d4560a1e1b..5a9b035771 100644
--- a/core/input_map.cpp
+++ b/core/input_map.cpp
@@ -38,7 +38,7 @@ void InputMap::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_action_from_id","id"),&InputMap::get_action_from_id);
ObjectTypeDB::bind_method(_MD("add_action","action"),&InputMap::add_action);
ObjectTypeDB::bind_method(_MD("erase_action","action"),&InputMap::erase_action);
-
+
ObjectTypeDB::bind_method(_MD("action_add_event","action","event"),&InputMap::action_add_event);
ObjectTypeDB::bind_method(_MD("action_has_event","action","event"),&InputMap::action_has_event);
ObjectTypeDB::bind_method(_MD("action_erase_event","action","event"),&InputMap::action_erase_event);
@@ -156,10 +156,7 @@ void InputMap::action_erase_event(const StringName& p_action,const InputEvent& p
List<InputEvent>::Element *E=_find_event(input_map[p_action].inputs,p_event);
if (E)
- return; //already gots
-
- input_map[p_action].inputs.erase(E);
-
+ input_map[p_action].inputs.erase(E);
}
diff --git a/core/io/aes256.h b/core/io/aes256.h
index fabbcf1968..8fcc25a4de 100644
--- a/core/io/aes256.h
+++ b/core/io/aes256.h
@@ -1,6 +1,6 @@
-/*
+/*
* Byte-oriented AES-256 implementation.
-* All lookup tables replaced with 'on the fly' calculations.
+* All lookup tables replaced with 'on the fly' calculations.
*
* Copyright (c) 2007-2009 Ilya O. Levin, http://www.literatecode.com
* Other contributors: Hal Finney
@@ -24,14 +24,14 @@
#include "typedefs.h"
#ifdef __cplusplus
-extern "C" {
+extern "C" {
#endif
typedef struct {
- uint8_t key[32];
- uint8_t enckey[32];
+ uint8_t key[32];
+ uint8_t enckey[32];
uint8_t deckey[32];
- } aes256_context;
+ } aes256_context;
void aes256_init(aes256_context *, uint8_t * /* key */);
diff --git a/core/io/fastlz.h b/core/io/fastlz.h
index f87bc7be31..e5ca8dfc02 100644
--- a/core/io/fastlz.h
+++ b/core/io/fastlz.h
@@ -1,4 +1,4 @@
-/*
+/*
FastLZ - lightning-fast lossless compression library
Copyright (C) 2007 Ariya Hidayat (ariya@kde.org)
@@ -40,11 +40,11 @@ extern "C" {
#endif
/**
- Compress a block of data in the input buffer and returns the size of
- compressed block. The size of input buffer is specified by length. The
+ Compress a block of data in the input buffer and returns the size of
+ compressed block. The size of input buffer is specified by length. The
minimum input buffer size is 16.
- The output buffer must be at least 5% larger than the input buffer
+ The output buffer must be at least 5% larger than the input buffer
and can not be smaller than 66 bytes.
If the input is not compressible, the return value might be larger than
@@ -56,9 +56,9 @@ extern "C" {
int fastlz_compress(const void* input, int length, void* output);
/**
- Decompress a block of compressed data and returns the size of the
- decompressed block. If error occurs, e.g. the compressed data is
- corrupted or the output buffer is not large enough, then 0 (zero)
+ Decompress a block of compressed data and returns the size of the
+ decompressed block. If error occurs, e.g. the compressed data is
+ corrupted or the output buffer is not large enough, then 0 (zero)
will be returned instead.
The input buffer and the output buffer can not overlap.
@@ -67,14 +67,14 @@ int fastlz_compress(const void* input, int length, void* output);
more than what is specified in maxout.
*/
-int fastlz_decompress(const void* input, int length, void* output, int maxout);
+int fastlz_decompress(const void* input, int length, void* output, int maxout);
/**
- Compress a block of data in the input buffer and returns the size of
- compressed block. The size of input buffer is specified by length. The
+ Compress a block of data in the input buffer and returns the size of
+ compressed block. The size of input buffer is specified by length. The
minimum input buffer size is 16.
- The output buffer must be at least 5% larger than the input buffer
+ The output buffer must be at least 5% larger than the input buffer
and can not be smaller than 66 bytes.
If the input is not compressible, the return value might be larger than
@@ -82,14 +82,14 @@ int fastlz_decompress(const void* input, int length, void* output, int maxout);
The input buffer and the output buffer can not overlap.
- Compression level can be specified in parameter level. At the moment,
+ Compression level can be specified in parameter level. At the moment,
only level 1 and level 2 are supported.
Level 1 is the fastest compression and generally useful for short data.
Level 2 is slightly slower but it gives better compression ratio.
Note that the compressed data, regardless of the level, can always be
decompressed using the function fastlz_decompress above.
-*/
+*/
int fastlz_compress_level(int level, const void* input, int length, void* output);
diff --git a/core/io/file_access_buffered.cpp b/core/io/file_access_buffered.cpp
index b38fda3686..e6b01475b6 100644
--- a/core/io/file_access_buffered.cpp
+++ b/core/io/file_access_buffered.cpp
@@ -33,17 +33,17 @@
#include "error_macros.h"
Error FileAccessBuffered::set_error(Error p_error) const {
-
+
return (last_error = p_error);
};
void FileAccessBuffered::set_cache_size(int p_size) {
-
+
cache_size = p_size;
};
int FileAccessBuffered::get_cache_size() {
-
+
return cache_size;
};
@@ -66,27 +66,27 @@ int FileAccessBuffered::cache_data_left() const {
};
void FileAccessBuffered::seek(size_t p_position) {
-
+
file.offset = p_position;
};
void FileAccessBuffered::seek_end(int64_t p_position) {
-
+
file.offset = file.size + p_position;
};
size_t FileAccessBuffered::get_pos() const {
-
+
return file.offset;
};
size_t FileAccessBuffered::get_len() const {
-
+
return file.size;
};
bool FileAccessBuffered::eof_reached() const {
-
+
return file.offset > file.size;
};
@@ -165,12 +165,12 @@ int FileAccessBuffered::get_buffer(uint8_t *p_dest,int p_elements) const {
};
bool FileAccessBuffered::is_open() const {
-
+
return file.open;
};
Error FileAccessBuffered::get_error() const {
-
+
return last_error;
};
@@ -180,5 +180,5 @@ FileAccessBuffered::FileAccessBuffered() {
};
FileAccessBuffered::~FileAccessBuffered(){
-
+
}
diff --git a/core/io/file_access_buffered.h b/core/io/file_access_buffered.h
index 9d405e15f7..058c26b8a9 100644
--- a/core/io/file_access_buffered.h
+++ b/core/io/file_access_buffered.h
@@ -60,9 +60,9 @@ protected:
String name;
int access_flags;
} file;
-
+
mutable struct Cache {
-
+
Vector<uint8_t> buffer;
int offset;
} cache;
@@ -71,7 +71,7 @@ protected:
void set_cache_size(int p_size);
int get_cache_size();
-
+
public:
virtual size_t get_pos() const; ///< get position in the file
diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp
index e63b57533f..a3c839e761 100644
--- a/core/io/file_access_network.cpp
+++ b/core/io/file_access_network.cpp
@@ -217,7 +217,7 @@ Error FileAccessNetworkClient::connect(const String& p_host,int p_port,const Str
return ERR_CANT_CONNECT;
}
- CharString cs = p_password.utf8();
+ CharString cs = p_password.utf8();
put_32(cs.length());
client->put_data((const uint8_t*)cs.ptr(),cs.length());
diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp
index dd53c8f8eb..e0c01c9422 100644
--- a/core/io/http_client.cpp
+++ b/core/io/http_client.cpp
@@ -305,7 +305,7 @@ Error HTTPClient::poll(){
String header = responses[i].strip_edges();
String s = header.to_lower();
if (s.length()==0)
- continue;
+ continue;
if (s.begins_with("content-length:")) {
body_size = s.substr(s.find(":")+1,s.length()).strip_edges().to_int();
body_left=body_size;
diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp
index aa641f00b4..05bad97e90 100644
--- a/core/io/image_loader.cpp
+++ b/core/io/image_loader.cpp
@@ -30,16 +30,16 @@
#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()) {
-
+
if (E->get().nocasecmp_to(p_extension.extension())==0)
return true;
}
-
+
return false;
}
@@ -55,12 +55,12 @@ Error ImageLoader::load_image(String p_file,Image *p_image, FileAccess *p_custom
return err;
}
}
-
+
String extension = p_file.extension();
for (int i=0;i<loader_count;i++) {
-
+
if (!loader[i]->recognize(extension))
continue;
Error err = loader[i]->load_image(p_image,f);
@@ -73,25 +73,25 @@ Error ImageLoader::load_image(String p_file,Image *p_image, FileAccess *p_custom
return err;
}
-
-
+
+
}
print_line("NO LOADER?");
if (!p_custom)
- memdelete(f);
-
+ memdelete(f);
+
return ERR_FILE_UNRECOGNIZED;
}
void ImageLoader::get_recognized_extensions(List<String> *p_extensions) {
-
+
for (int i=0;i<loader_count;i++) {
-
+
loader[i]->get_recognized_extensions(p_extensions);
-
- }
+
+ }
}
bool ImageLoader::recognize(const String& p_extension) {
diff --git a/core/io/image_loader.h b/core/io/image_loader.h
index 3cc6c6cf43..c799837792 100644
--- a/core/io/image_loader.h
+++ b/core/io/image_loader.h
@@ -41,11 +41,11 @@
/**
* @class ImageScanLineLoader
* @author Juan Linietsky <reduzio@gmail.com>
- *
-
+ *
+
*/
class ImageLoader;
-
+
/**
* @class ImageLoader
@@ -60,8 +60,8 @@ 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() {}
};
@@ -79,11 +79,11 @@ 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);
};
diff --git a/core/io/ip.cpp b/core/io/ip.cpp
index b8bd00c2fb..a77aace07f 100644
--- a/core/io/ip.cpp
+++ b/core/io/ip.cpp
@@ -49,7 +49,7 @@ struct _IP_ResolverPrivate {
response = IP_Address();
hostname="";
};
-
+
QueueItem() {
clear();
};
diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp
index 4dccf21d2d..1733aecd46 100644
--- a/core/io/marshalls.cpp
+++ b/core/io/marshalls.cpp
@@ -95,7 +95,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
str.parse_utf8((const char*)buf,strlen);
r_variant=str;
- if (r_len) {
+ if (r_len) {
if (strlen%4)
(*r_len)+=4-strlen%4;
(*r_len)+=4+strlen;
@@ -294,7 +294,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
} break;
case Variant::NODE_PATH: {
- ERR_FAIL_COND_V(len<4,ERR_INVALID_DATA);
+ ERR_FAIL_COND_V(len<4,ERR_INVALID_DATA);
uint32_t strlen = decode_uint32(buf);
if (strlen&0x80000000) {
@@ -1077,7 +1077,7 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
r_len+=data.size()+5*4+pad;
- } break;
+ } break;
/*case Variant::RESOURCE: {
ERR_EXPLAIN("Can't marshallize resources");
@@ -1238,7 +1238,7 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
DVector<uint8_t> data = p_variant;
int datalen=data.size();
int datasize=sizeof(uint8_t);
-
+
if (buf) {
encode_uint32(datalen,buf);
buf+=4;
diff --git a/core/io/marshalls.h b/core/io/marshalls.h
index 7a5b16e8af..6a46e9882a 100644
--- a/core/io/marshalls.h
+++ b/core/io/marshalls.h
@@ -37,7 +37,7 @@
* Miscelaneous helpers for marshalling data types, and encoding
* in an endian independent way
*/
-
+
union MarshallFloat {
@@ -54,22 +54,22 @@ union MarshallDouble {
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;
}
-
+
return sizeof( uint16_t );
}
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;
}
-
+
return sizeof( uint32_t );
}
@@ -85,11 +85,11 @@ static inline unsigned int encode_float(float p_float, uint8_t *p_arr) {
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;
}
-
+
return sizeof(uint64_t);
}
@@ -100,25 +100,25 @@ 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;
-
+
while (*p_string) {
if (p_data) {
-
+
*p_data=(uint8_t)*p_string;
p_data++;
}
p_string++;
len++;
};
-
+
if (p_data) *p_data = 0;
return len+1;
}
@@ -126,35 +126,35 @@ static inline int encode_cstring(const char *p_string, uint8_t * p_data) {
static inline uint16_t decode_uint16(const uint8_t *p_arr) {
uint16_t u=0;
-
+
for (int i=0;i<2;i++) {
-
+
uint16_t b = *p_arr;
b<<=(i*8);
u|=b;
p_arr++;
}
-
+
return u;
}
static inline uint32_t decode_uint32(const uint8_t *p_arr) {
uint32_t u=0;
-
+
for (int i=0;i<4;i++) {
-
+
uint32_t b = *p_arr;
b<<=(i*8);
u|=b;
p_arr++;
}
-
+
return u;
}
static inline float decode_float(const uint8_t *p_arr) {
-
+
MarshallFloat mf;
mf.i = decode_uint32(p_arr);
return mf.f;
@@ -163,15 +163,15 @@ static inline float decode_float(const uint8_t *p_arr) {
static inline uint64_t decode_uint64(const uint8_t *p_arr) {
uint64_t u=0;
-
+
for (int i=0;i<8;i++) {
-
+
uint64_t b = (*p_arr)&0xFF;
b<<=(i*8);
u|=b;
p_arr++;
}
-
+
return u;
}
diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp
index 973a2ec9a5..22b8bc0b39 100644
--- a/core/io/packet_peer.cpp
+++ b/core/io/packet_peer.cpp
@@ -180,10 +180,10 @@ int PacketPeerStream::get_available_packet_count() const {
ring_buffer.copy(lbuf,ofs,4);
uint32_t len = decode_uint32(lbuf);
remaining-=4;
- ofs+=4;
+ ofs+=4;
if (len>remaining)
break;
- remaining-=len;
+ remaining-=len;
ofs+=len;
count++;
}
@@ -201,7 +201,7 @@ Error PacketPeerStream::get_packet(const uint8_t **r_buffer,int &r_buffer_size)
uint8_t lbuf[4];
ring_buffer.copy(lbuf,0,4);
remaining-=4;
- uint32_t len = decode_uint32(lbuf);
+ uint32_t len = decode_uint32(lbuf);
ERR_FAIL_COND_V(remaining<(int)len,ERR_UNAVAILABLE);
ring_buffer.read(lbuf,4); //get rid of first 4 bytes
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index c008c3f9a4..58f3a4df2b 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -378,7 +378,7 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
} break;
case OBJECT_INTERNAL_RESOURCE: {
uint32_t index=f->get_32();
- String path = res_path+"::"+itos(index);
+ String path = res_path+"::"+itos(index);
RES res = ResourceLoader::load(path);
if (res.is_null()) {
WARN_PRINT(String("Couldn't load resource: "+path).utf8().get_data());
@@ -2100,7 +2100,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path,const RES& p_
p.value=E->get()->get(F->get().name);
if ((F->get().usage&PROPERTY_USAGE_STORE_IF_NONZERO && p.value.is_zero())||(F->get().usage&PROPERTY_USAGE_STORE_IF_NONONE && p.value.is_one()) )
continue;
- p.pi=F->get();
+ p.pi=F->get();
rd.properties.push_back(p);
diff --git a/core/io/resource_format_xml.cpp b/core/io/resource_format_xml.cpp
index 03b77a4aab..a42a922baf 100644
--- a/core/io/resource_format_xml.cpp
+++ b/core/io/resource_format_xml.cpp
@@ -1818,7 +1818,7 @@ Error ResourceInteractiveLoaderXML::rename_dependencies(FileAccess *p_f, const S
void ResourceInteractiveLoaderXML::open(FileAccess *p_f) {
- error=OK;
+ error=OK;
lines=1;
f=p_f;
diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp
index 67208b5960..abb1082256 100644
--- a/core/io/resource_loader.cpp
+++ b/core/io/resource_loader.cpp
@@ -49,16 +49,16 @@ Error ResourceInteractiveLoader::wait() {
bool ResourceFormatLoader::recognize(const String& p_extension) const {
-
-
+
+
List<String> extensions;
get_recognized_extensions(&extensions);
for (List<String>::Element *E=extensions.front();E;E=E->next()) {
-
+
if (E->get().nocasecmp_to(p_extension.extension())==0)
return true;
}
-
+
return false;
}
@@ -184,9 +184,9 @@ RES ResourceLoader::load(const String &p_path, const String& p_type_hint, bool p
String extension=remapped_path.extension();
bool found=false;
-
+
for (int i=0;i<loader_count;i++) {
-
+
if (!loader[i]->recognize(extension))
continue;
if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint))
@@ -356,7 +356,7 @@ Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_
}
void ResourceLoader::add_resource_format_loader(ResourceFormatLoader *p_format_loader) {
-
+
ERR_FAIL_COND( loader_count >= MAX_LOADERS );
loader[loader_count++]=p_format_loader;
}
diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h
index fe58303066..6404e6cb13 100644
--- a/core/io/resource_loader.h
+++ b/core/io/resource_loader.h
@@ -47,7 +47,7 @@ public:
virtual Ref<Resource> get_resource()=0;
virtual Error poll()=0;
virtual int get_stage() const=0;
- virtual int get_stage_count() const=0;
+ virtual int get_stage_count() const=0;
virtual Error wait();
ResourceInteractiveLoader() {}
@@ -76,12 +76,12 @@ 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 {
-
+class ResourceLoader {
+
enum {
MAX_LOADERS=64
};
-
+
static ResourceFormatLoader *loader[MAX_LOADERS];
static int loader_count;
static bool timestamp_on_load;
@@ -96,7 +96,7 @@ class ResourceLoader {
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);
static Ref<ResourceImportMetadata> load_import_metadata(const String &p_path);
diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp
index 51020a0285..8d78ecabbf 100644
--- a/core/io/resource_saver.cpp
+++ b/core/io/resource_saver.cpp
@@ -39,30 +39,30 @@ bool ResourceSaver::timestamp_on_save=false;
ResourceSavedCallback ResourceSaver::save_callback=0;
Error ResourceSaver::save(const String &p_path,const RES& p_resource,uint32_t p_flags) {
-
+
String extension=p_path.extension();
Error err=ERR_FILE_UNRECOGNIZED;
for (int i=0;i<saver_count;i++) {
-
+
if (!saver[i]->recognize(p_resource))
continue;
-
+
List<String> extensions;
bool recognized=false;
saver[i]->get_recognized_extensions(p_resource,&extensions);
-
+
for (List<String>::Element *E=extensions.front();E;E=E->next()) {
-
+
if (E->get().nocasecmp_to(extension.extension())==0)
recognized=true;
}
if (!recognized)
continue;
-
+
String old_path=p_resource->get_path();
-
+
String local_path=Globals::get_singleton()->localize_path(p_path);
@@ -92,10 +92,10 @@ Error ResourceSaver::save(const String &p_path,const RES& p_resource,uint32_t p_
return OK;
} else {
-
+
}
}
-
+
return err;
}
@@ -108,16 +108,16 @@ void ResourceSaver::set_save_callback(ResourceSavedCallback 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) {
-
+
ERR_FAIL_COND( saver_count >= MAX_SAVERS );
saver[saver_count++]=p_format_saver;
}
diff --git a/core/io/resource_saver.h b/core/io/resource_saver.h
index 7bc96c1087..97500c46f4 100644
--- a/core/io/resource_saver.h
+++ b/core/io/resource_saver.h
@@ -42,7 +42,7 @@
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;
@@ -52,12 +52,12 @@ public:
typedef void (*ResourceSavedCallback)(const String& p_path);
-class ResourceSaver {
-
+class ResourceSaver {
+
enum {
MAX_SAVERS=64
};
-
+
static ResourceFormatSaver *saver[MAX_SAVERS];
static int saver_count;
static bool timestamp_on_save;
@@ -86,7 +86,7 @@ public:
static void set_save_callback(ResourceSavedCallback p_callback);
-
+
};
diff --git a/core/list.h b/core/list.h
index fbeb653da4..b989f009a9 100644
--- a/core/list.h
+++ b/core/list.h
@@ -245,7 +245,7 @@ public:
_data->first=n;
_data->size_cache++;
-
+
return n;
};
@@ -285,7 +285,7 @@ public:
_data->last=n;
_data->size_cache++;
-
+
return n;
};
@@ -363,30 +363,30 @@ public:
}
void swap(Element* p_A, Element *p_B) {
-
+
ERR_FAIL_COND(!p_A || !p_B);
ERR_FAIL_COND(p_A->data!=_data);
ERR_FAIL_COND(p_B->data!=_data);
-
+
Element* A_prev=p_A->prev_ptr;
Element* A_next=p_A->next_ptr;
-
+
p_A->next_ptr=p_B->next_ptr;
p_A->prev_ptr=p_B->prev_ptr;
-
+
p_B->next_ptr=A_next;
- p_B->prev_ptr=A_prev;
-
+ p_B->prev_ptr=A_prev;
+
if (p_A->prev_ptr)
p_A->prev_ptr->next_ptr=p_A;
if (p_A->next_ptr)
- p_A->next_ptr->prev_ptr=p_A;
-
+ p_A->next_ptr->prev_ptr=p_A;
+
if (p_B->prev_ptr)
p_B->prev_ptr->next_ptr=p_B;
if (p_B->next_ptr)
- p_B->next_ptr->prev_ptr=p_B;
-
+ p_B->next_ptr->prev_ptr=p_B;
+
}
/**
* copy the list
@@ -552,10 +552,10 @@ public:
*/
void sort() {
-
+
sort_custom< Comparator<T> >();
}
-
+
template<class C>
void sort_custom_inplace() {
@@ -565,44 +565,44 @@ public:
Element *from=front();
Element *current=from;
Element *to=from;
-
+
while(current) {
-
+
Element *next=current->next_ptr;
-
+
//disconnect
current->next_ptr=NULL;
-
+
if (from!=current) {
-
+
current->prev_ptr=NULL;
current->next_ptr=from;
-
+
Element *find=from;
C less;
while( find && less(find->value,current->value) ) {
-
+
current->prev_ptr=find;
current->next_ptr=find->next_ptr;
find=find->next_ptr;
}
-
+
if (current->prev_ptr)
current->prev_ptr->next_ptr=current;
else
from=current;
-
+
if (current->next_ptr)
current->next_ptr->prev_ptr=current;
else
to=current;
} else {
-
+
current->prev_ptr=NULL;
current->next_ptr=NULL;
-
+
}
-
+
current=next;
}
_data->first=from;
diff --git a/core/map.h b/core/map.h
index 35dc73df48..81cda1ece2 100644
--- a/core/map.h
+++ b/core/map.h
@@ -39,12 +39,12 @@
template <class K,class V,class C=Comparator<K>,class A=DefaultAllocator>
class Map {
-
- enum Color {
+
+ enum Color {
RED,
BLACK
};
- struct _Data;
+ struct _Data;
public:
class Element {
@@ -66,34 +66,34 @@ public:
public:
const Element *next() const {
-
+
return _next;
}
Element *next() {
-
+
return _next;
}
const Element *prev() const {
-
+
return _prev;
}
Element *prev() {
-
+
return _prev;
}
- const K& key() const {
+ const K& key() const {
return _key;
};
- V& value() {
+ V& value() {
return _value;
};
- const V& value() const {
+ const V& value() const {
return _value;
};
- V& get() {
+ V& get() {
return _value;
};
- const V& get() const {
+ const V& get() const {
return _value;
};
Element() {
@@ -106,15 +106,15 @@ public:
};
};
-
+
private:
struct _Data {
-
+
Element* _root;
Element* _nil;
int size_cache;
-
+
_FORCE_INLINE_ _Data() {
#ifdef GLOBALNIL_DISABLED
_nil = memnew_allocator( Element, A );
@@ -126,7 +126,7 @@ private:
_root=NULL;
size_cache=0;
}
-
+
void _create_root() {
_root = memnew_allocator( Element,A );
@@ -145,23 +145,23 @@ private:
~_Data() {
_free_root();
-
+
#ifdef GLOBALNIL_DISABLED
memdelete_allocator<Element,A>(_nil);
#endif
// memdelete_allocator<Element,A>(_root);
}
};
-
+
_Data _data;
-
+
inline void _set_color(Element *p_node, int p_color) {
-
+
ERR_FAIL_COND( p_node == _data._nil && p_color == RED );
p_node->color=p_color;
}
inline void _rotate_left(Element *p_node) {
-
+
Element *r=p_node->right;
p_node->right=r->left;
if (r->left != _data._nil )
@@ -171,14 +171,14 @@ private:
p_node->parent->left=r;
else
p_node->parent->right=r;
-
+
r->left=p_node;
p_node->parent=r;
-
+
}
-
+
inline void _rotate_right(Element *p_node) {
-
+
Element *l=p_node->left;
p_node->left=l->right;
if (l->right != _data._nil)
@@ -188,25 +188,25 @@ private:
p_node->parent->right=l;
else
p_node->parent->left=l;
-
+
l->right=p_node;
p_node->parent=l;
-
+
}
-
- inline Element* _successor(Element *p_node) const {
-
+
+ inline Element* _successor(Element *p_node) const {
+
Element *node=p_node;
-
+
if (node->right != _data._nil) {
-
+
node=node->right;
while(node->left != _data._nil) { /* returns the minium of the right subtree of node */
node=node->left;
}
return node;
} else {
-
+
while(node == node->parent->right) {
node=node->parent;
}
@@ -215,44 +215,44 @@ private:
return node->parent;
}
}
-
- inline Element* _predecessor(Element *p_node) const {
+
+ inline Element* _predecessor(Element *p_node) const {
Element *node=p_node;
-
+
if (node->left != _data._nil) {
-
+
node=node->left;
while(node->right != _data._nil) { /* returns the minium of the left subtree of node */
node=node->right;
}
return node;
} else {
-
+
while(node == node->parent->left) {
if (node->parent == _data._root)
- return NULL;
+ return NULL;
node=node->parent;
}
return node->parent;
}
}
-
-
+
+
Element *_find(const K& p_key) const {
-
+
Element *node = _data._root->left;
- C less;
-
+ C less;
+
while(node!=_data._nil) {
-
- if (less(p_key,node->_key))
+
+ if (less(p_key,node->_key))
node=node->left;
else if (less(node->_key,p_key))
node=node->right;
else
break; // found
}
-
+
return (node!=_data._nil)?node:NULL;
}
@@ -289,73 +289,73 @@ private:
}
Element *_insert(const K& p_key, bool& r_exists) {
-
+
Element *new_parent=_data._root;
Element *node = _data._root->left;
- C less;
-
+ C less;
+
while (node!=_data._nil) {
-
+
new_parent=node;
-
+
if (less(p_key,node->_key))
node=node->left;
else if (less(node->_key,p_key))
node=node->right;
- else {
+ else {
r_exists=true;
return node;
- }
+ }
}
-
+
Element *new_node = memnew_allocator( Element, A );
-
+
new_node->parent=new_parent;
new_node->right=_data._nil;
new_node->left=_data._nil;
new_node->_key=p_key;
//new_node->data=_data;
if (new_parent==_data._root || less(p_key,new_parent->_key)) {
-
+
new_parent->left=new_node;
} else {
new_parent->right=new_node;
}
-
+
r_exists=false;
-
+
new_node->_next=_successor(new_node);
new_node->_prev=_predecessor(new_node);
if (new_node->_next)
new_node->_next->_prev=new_node;
if (new_node->_prev)
new_node->_prev->_next=new_node;
-
+
return new_node;
}
-
+
Element * _insert_rb(const K& p_key, const V& p_value) {
-
+
bool exists=false;
Element *new_node = _insert(p_key,exists);
-
+
if (new_node) {
new_node->_value=p_value;
}
if (exists)
return new_node;
-
+
Element *node=new_node;
_data.size_cache++;
- while(node->parent->color==RED) {
-
+ while(node->parent->color==RED) {
+
if (node->parent == node->parent->parent->left) {
-
+
Element *aux=node->parent->parent->right;
-
+
if (aux->color==RED) {
_set_color(node->parent,BLACK);
_set_color(aux,BLACK);
@@ -369,10 +369,10 @@ private:
_set_color(node->parent,BLACK);
_set_color(node->parent->parent,RED);
_rotate_right(node->parent->parent);
- }
- } else {
+ }
+ } else {
Element *aux=node->parent->parent->left;
-
+
if (aux->color==RED) {
_set_color(node->parent,BLACK);
_set_color(aux,BLACK);
@@ -386,19 +386,19 @@ private:
_set_color(node->parent,BLACK);
_set_color(node->parent->parent,RED);
_rotate_left(node->parent->parent);
- }
+ }
}
}
_set_color(_data._root->left,BLACK);
- return new_node;
- }
+ return new_node;
+ }
void _erase_fix(Element *p_node) {
-
+
Element *root = _data._root->left;
Element *node=p_node;
-
-
+
+
while( (node->color==BLACK) && (root != node)) {
if (node == node->parent->left) {
Element *aux=node->parent->right;
@@ -408,7 +408,7 @@ private:
_rotate_left(node->parent);
aux=node->parent->right;
}
- if ( (aux->right->color==BLACK) && (aux->left->color==BLACK) ) {
+ if ( (aux->right->color==BLACK) && (aux->left->color==BLACK) ) {
_set_color(aux,RED);
node=node->parent;
} else {
@@ -432,7 +432,7 @@ private:
_rotate_right(node->parent);
aux=node->parent->left;
}
- if ( (aux->right->color==BLACK) && (aux->left->color==BLACK) ) {
+ if ( (aux->right->color==BLACK) && (aux->left->color==BLACK) ) {
_set_color(aux,RED);
node=node->parent;
} else {
@@ -446,24 +446,24 @@ private:
_set_color(node->parent,BLACK);
_set_color(aux->left,BLACK);
_rotate_right(node->parent);
- node=root;
+ node=root;
}
}
}
-
+
_set_color(node,BLACK);
-
+
ERR_FAIL_COND(_data._nil->color!=BLACK);
}
-
+
void _erase(Element *p_node) {
-
-
+
+
Element *rp= ((p_node->left == _data._nil) || (p_node->right == _data._nil)) ? p_node : _successor(p_node);
if (!rp)
rp=_data._nil;
Element *node= (rp->left == _data._nil) ? rp->right : rp->left;
-
+
if (_data._root == (node->parent=rp->parent) ) {
_data._root->left=node;
} else {
@@ -473,47 +473,47 @@ private:
rp->parent->right=node;
}
}
-
- if (rp != p_node) {
-
+
+ if (rp != p_node) {
+
ERR_FAIL_COND( rp == _data._nil );
-
+
if (rp->color==BLACK)
_erase_fix(node);
-
-
+
+
rp->left=p_node->left;
rp->right=p_node->right;
rp->parent=p_node->parent;
rp->color=p_node->color;
p_node->left->parent=rp;
p_node->right->parent=rp;
-
+
if (p_node == p_node->parent->left) {
- p_node->parent->left=rp;
+ p_node->parent->left=rp;
} else {
p_node->parent->right=rp;
}
} else {
- if (p_node->color==BLACK)
+ if (p_node->color==BLACK)
_erase_fix(node);
-
+
}
-
-
+
+
if (p_node->_next)
p_node->_next->_prev=p_node->_prev;
if (p_node->_prev)
p_node->_prev->_next=p_node->_next;
-
+
memdelete_allocator<Element,A>(p_node);
_data.size_cache--;
ERR_FAIL_COND( _data._nil->color==RED );
}
-
-
+
+
void _calculate_depth(Element *p_element,int &max_d,int d) const {
-
+
if (p_element==_data._nil) {
return;
}
@@ -522,23 +522,23 @@ private:
if (d>max_d)
max_d=d;
}
-
+
void _cleanup_tree(Element *p_element) {
-
+
if (p_element==_data._nil)
return;
-
+
_cleanup_tree(p_element->left);
_cleanup_tree(p_element->right);
memdelete_allocator<Element,A>( p_element );
}
-
+
void _copy_from( const Map& p_map) {
-
+
clear();
// not the fastest way, but safeset to write.
for(Element *I=p_map.front();I;I=I->next()) {
-
+
insert(I->key(),I->value());
}
}
@@ -554,7 +554,7 @@ public:
}
Element *find(const K& p_key) {
-
+
if (!_data._root)
return NULL;
Element *res=_find(p_key);
@@ -578,15 +578,15 @@ public:
}
Element *insert(const K& p_key,const V& p_value) {
-
+
if (!_data._root)
_data._create_root();
return _insert_rb(p_key,p_value);
-
+
}
-
+
void erase(Element* p_element) {
-
+
if (!_data._root)
return;
_erase(p_element);
@@ -595,72 +595,72 @@ public:
}
bool erase(const K& p_key) {
-
+
if (!_data._root)
return false;
Element *e=find(p_key);
if (!e)
return false;
- _erase(e);
+ _erase(e);
return true;
}
-
+
bool has(const K& p_key) const {
-
+
if (!_data._root)
return false;
return find(p_key) != NULL;
}
-
+
const V& operator[](const K& p_key) const {
-
+
ERR_FAIL_COND_V(!_data._root, *(V*)NULL); // crash on purpose
const Element *e=find(p_key);
ERR_FAIL_COND_V(!e, *(V*)NULL); // crash on purpose
return e->_value;
}
V& operator[](const K& p_key) {
-
+
if (!_data._root)
_data._create_root();
Element *e=find(p_key);
if (!e)
e=insert(p_key,V());
-
- ERR_FAIL_COND_V(!e, *(V*)NULL); // crash on purpose
+
+ ERR_FAIL_COND_V(!e, *(V*)NULL); // crash on purpose
return e->_value;
}
-
+
Element *front() const {
-
+
if (!_data._root)
return NULL;
Element *e=_data._root->left;
if (e==_data._nil)
return NULL;
-
+
while(e->left!=_data._nil)
e=e->left;
-
+
return e;
}
-
+
Element *back() const {
-
+
if (!_data._root)
return NULL;
Element *e=_data._root->left;
if (e==_data._nil)
return NULL;
-
+
while(e->right!=_data._nil)
e=e->right;
-
+
return e;
}
-
+
inline bool empty() const { return _data.size_cache==0; }
inline int size() const { return _data.size_cache; }
int calculate_depth() const {
@@ -671,9 +671,9 @@ public:
_calculate_depth(_data._root->left,max_d,0);
return max_d;
}
-
+
void clear() {
-
+
if (!_data._root)
return;
_cleanup_tree(_data._root->left);
@@ -682,25 +682,25 @@ public:
_data._nil->parent=_data._nil;
_data._free_root();
}
-
+
void operator=(const Map& p_map) {
-
+
_copy_from( p_map );
}
-
+
Map(const Map& p_map) {
-
+
_copy_from( p_map );
}
_FORCE_INLINE_ Map() {
-
+
}
-
-
+
+
~Map() {
-
- clear();
+
+ clear();
}
};
diff --git a/core/math/aabb.h b/core/math/aabb.h
index 0fada859c0..57fe1b32f5 100644
--- a/core/math/aabb.h
+++ b/core/math/aabb.h
@@ -47,21 +47,21 @@ public:
float get_area() const; /// get area
_FORCE_INLINE_ bool has_no_area() const {
-
+
return (size.x<=CMP_EPSILON || size.y<=CMP_EPSILON || size.z<=CMP_EPSILON);
}
_FORCE_INLINE_ bool has_no_surface() const {
-
+
return (size.x<=CMP_EPSILON && size.y<=CMP_EPSILON && size.z<=CMP_EPSILON);
}
-
+
const Vector3& get_pos() const { return pos; }
void set_pos(const Vector3& p_pos) { pos=p_pos; }
const Vector3& get_size() const { return size; }
void set_size(const Vector3& p_size) { size=p_size; }
-
+
bool operator==(const AABB& p_rval) const;
bool operator!=(const AABB& p_rval) const;
@@ -265,7 +265,7 @@ bool AABB::has_point(const Vector3& p_point) const {
return false;
if (p_point.z>pos.z+size.z)
return false;
-
+
return true;
}
@@ -297,11 +297,11 @@ void AABB::project_range_in_plane(const Plane& p_plane,float &r_min,float& r_max
Vector3 half_extents( size.x * 0.5, size.y * 0.5, size.z * 0.5 );
Vector3 center( pos.x + half_extents.x, pos.y + half_extents.y, pos.z + half_extents.z );
-
+
float length = p_plane.normal.abs().dot(half_extents);
float distance = p_plane.distance_to( center );
r_min = distance - length;
- r_max = distance + length;
+ r_max = distance + length;
}
inline real_t AABB::get_longest_axis_size() const {
diff --git a/core/math/bsp_tree.cpp b/core/math/bsp_tree.cpp
index 0c07b733f0..d16495217c 100644
--- a/core/math/bsp_tree.cpp
+++ b/core/math/bsp_tree.cpp
@@ -66,12 +66,12 @@ Vector<Plane> BSP_Tree::get_planes() const {
return planes;
}
-
+
AABB BSP_Tree::get_aabb() const {
return aabb;
}
-
+
int BSP_Tree::_get_points_inside(int p_node,const Vector3* p_points,int *p_indices, const Vector3& p_center,const Vector3& p_half_extents,int p_indices_count) const {
@@ -245,22 +245,22 @@ bool BSP_Tree::point_is_inside(const Vector3& p_point) const {
if (!aabb.has_point(p_point)) {
return false;
}
-
+
int node_count=nodes.size();
-
+
if (node_count==0) // no nodes!
return false;
-
-
+
+
const Node *nodesptr=&nodes[0];
const Plane *planesptr=&planes[0];
int plane_count=planes.size();
-
+
int idx=node_count-1;
int steps=0;
-
+
while(true) {
-
+
if (idx==OVER_LEAF) {
return false;
}
@@ -268,28 +268,28 @@ bool BSP_Tree::point_is_inside(const Vector3& p_point) const {
return true;
}
-
+
uint16_t plane=nodesptr[ idx ].plane;
#ifdef DEBUG_ENABLED
-
+
ERR_FAIL_INDEX_V( plane, plane_count, false );
#endif
bool over = planesptr[ nodesptr[ idx ].plane ].is_point_over(p_point);
idx = over ? nodes[ idx ].over : nodes[ idx ].under;
-
+
#ifdef DEBUG_ENABLED
-
+
ERR_FAIL_COND_V( idx<MAX_NODES && idx>=node_count, false );
#endif
-
+
steps++;
}
return false;
}
-
-
+
+
static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector<int>& p_indices,float p_tolerance) {
int ic = p_indices.size();
@@ -304,7 +304,7 @@ static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector<int>& p_i
const Face3& f=p_faces[ indices[i] ];
Plane p = f.get_plane();
-
+
int num_over=0,num_under=0,num_spanning=0;
for(int j=0;j<ic;j++) {
@@ -335,17 +335,17 @@ static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector<int>& p_i
num_over++;
else
num_under++;
-
+
}
//double split_cost = num_spanning / (double) face_count;
double relation = Math::abs(num_over-num_under) / (double) ic;
-
+
// being honest, i never found a way to add split cost to the mix in a meaninguful way
// in this engine, also, will likely be ignored anyway
-
+
double plane_cost = /*split_cost +*/ relation;
//printf("plane %i, %i over, %i under, %i spanning, cost is %g\n",i,num_over,num_under,num_spanning,plane_cost);
@@ -360,10 +360,10 @@ static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector<int>& p_i
return best_plane;
}
-
+
static int _bsp_create_node(const Face3 *p_faces,const Vector<int>& p_indices,Vector<Plane> &p_planes, Vector<BSP_Tree::Node> &p_nodes,float p_tolerance) {
-
+
ERR_FAIL_COND_V( p_nodes.size() == BSP_Tree::MAX_NODES, -1 );
// should not reach here
@@ -387,7 +387,7 @@ static int _bsp_create_node(const Face3 *p_faces,const Vector<int>& p_indices,Ve
if (i==divisor_idx)
continue;
-
+
const Face3& f=p_faces[ indices[i] ];
//if (f.get_plane().is_almost_like(divisor_plane))
@@ -416,7 +416,7 @@ static int _bsp_create_node(const Face3 *p_faces,const Vector<int>& p_indices,Ve
}
-
+
uint16_t over_idx=BSP_Tree::OVER_LEAF,under_idx=BSP_Tree::UNDER_LEAF;
if (faces_over.size()>0) { //have facess above?
@@ -434,13 +434,13 @@ static int _bsp_create_node(const Face3 *p_faces,const Vector<int>& p_indices,Ve
}
/* Create the node */
-
+
// find existing divisor plane
int divisor_plane_idx=-1;
-
-
+
+
for (int i=0;i<p_planes.size();i++) {
-
+
if (p_planes[i].is_almost_like( divisor_plane )) {
divisor_plane_idx=i;
break;
@@ -448,22 +448,22 @@ static int _bsp_create_node(const Face3 *p_faces,const Vector<int>& p_indices,Ve
}
if (divisor_plane_idx==-1) {
-
+
ERR_FAIL_COND_V( p_planes.size() == BSP_Tree::MAX_PLANES, -1 );
divisor_plane_idx=p_planes.size();
p_planes.push_back( divisor_plane );
}
-
+
BSP_Tree::Node node;
node.plane=divisor_plane_idx;
node.under=under_idx;
node.over=over_idx;
-
+
p_nodes.push_back(node);
-
+
return p_nodes.size()-1;
}
-
+
BSP_Tree::operator Variant() const {
@@ -563,7 +563,7 @@ BSP_Tree::BSP_Tree(const Variant& p_variant) {
BSP_Tree::BSP_Tree(const DVector<Face3>& p_faces,float p_error_radius) {
// compute aabb
-
+
int face_count=p_faces.size();
DVector<Face3>::Read faces_r=p_faces.read();
const Face3 *facesptr = faces_r.ptr();
@@ -574,26 +574,26 @@ BSP_Tree::BSP_Tree(const DVector<Face3>& p_faces,float p_error_radius) {
Vector<int> indices;
for (int i=0;i<face_count;i++) {
-
+
const Face3& f=facesptr[i];
-
+
if (f.is_degenerate())
continue;
-
+
for (int j=0;j<3;j++) {
-
+
if (first) {
-
+
aabb.pos=f.vertex[0];
first=false;
} else {
-
+
aabb.expand_to(f.vertex[j]);
}
}
indices.push_back(i);
-
+
}
ERR_FAIL_COND( aabb.has_no_area() );
@@ -609,7 +609,7 @@ BSP_Tree::BSP_Tree(const DVector<Face3>& p_faces,float p_error_radius) {
-
+
error_radius=p_error_radius;
}
diff --git a/core/math/bsp_tree.h b/core/math/bsp_tree.h
index a7145f9ff1..2bfc26b51e 100644
--- a/core/math/bsp_tree.h
+++ b/core/math/bsp_tree.h
@@ -43,7 +43,7 @@ class BSP_Tree {
public:
enum {
-
+
UNDER_LEAF=0xFFFF,
OVER_LEAF=0xFFFE,
MAX_NODES=0xFFFE,
@@ -51,22 +51,22 @@ public:
};
struct Node {
-
+
uint16_t plane;
uint16_t under;
uint16_t over;
};
-
-private:
- // thanks to the properties of Vector,
+
+private:
+ // thanks to the properties of Vector,
// this class can be assigned and passed around between threads
// with no cost.
-
+
Vector<Node> nodes;
Vector<Plane> planes;
AABB aabb;
- float error_radius;
+ float error_radius;
int _get_points_inside(int p_node,const Vector3* p_points,int *p_indices, const Vector3& p_center,const Vector3& p_half_extents,int p_indices_count) const;
@@ -79,8 +79,8 @@ public:
Vector<Node> get_nodes() const;
Vector<Plane> get_planes() const;
AABB get_aabb() const;
-
- bool point_is_inside(const Vector3& p_point) const;
+
+ bool point_is_inside(const Vector3& p_point) const;
int get_points_inside(const Vector3* p_points, int p_point_count) const;
template<class T>
bool convex_is_inside(const T& p_convex) const;
@@ -91,8 +91,8 @@ public:
BSP_Tree();
BSP_Tree(const Variant& p_variant);
- BSP_Tree(const DVector<Face3>& p_faces,float p_error_radius=0);
- BSP_Tree(const Vector<Node> &p_nodes, const Vector<Plane> &p_planes, const AABB& p_aabb,float p_error_radius=0);
+ BSP_Tree(const DVector<Face3>& p_faces,float p_error_radius=0);
+ BSP_Tree(const Vector<Node> &p_nodes, const Vector<Plane> &p_planes, const AABB& p_aabb,float p_error_radius=0);
~BSP_Tree();
};
diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp
index 61c8b78e0a..f7dd8839b8 100644
--- a/core/math/camera_matrix.cpp
+++ b/core/math/camera_matrix.cpp
@@ -33,9 +33,9 @@
void CameraMatrix::set_identity() {
for (int i=0;i<4;i++) {
-
+
for (int j=0;j<4;j++) {
-
+
matrix[i][j]=(i==j)?1:0;
}
}
@@ -90,7 +90,7 @@ void CameraMatrix::set_perspective(float p_fovy_degrees, float p_aspect, float p
matrix[2][2] = -(p_z_far + p_z_near) / deltaZ;
matrix[2][3] = -1;
matrix[3][2] = -2 * p_z_near * p_z_far / deltaZ;
- matrix[3][3] = 0;
+ matrix[3][3] = 0;
}
@@ -155,95 +155,95 @@ void CameraMatrix::set_frustum(float p_left, float p_right, float p_bottom, floa
float CameraMatrix::get_z_far() const {
-
- const float * matrix = (const float*)this->matrix;
+
+ const float * matrix = (const float*)this->matrix;
Plane new_plane=Plane(matrix[ 3] - matrix[ 2],
matrix[ 7] - matrix[ 6],
matrix[11] - matrix[10],
matrix[15] - matrix[14]);
-
+
new_plane.normal=-new_plane.normal;
new_plane.normalize();
-
+
return new_plane.d;
}
float CameraMatrix::get_z_near() const {
-
- const float * matrix = (const float*)this->matrix;
+
+ const float * matrix = (const float*)this->matrix;
Plane new_plane=Plane(matrix[ 3] + matrix[ 2],
matrix[ 7] + matrix[ 6],
matrix[11] + matrix[10],
-matrix[15] - matrix[14]);
-
+
new_plane.normalize();
return new_plane.d;
}
void CameraMatrix::get_viewport_size(float& r_width, float& r_height) const {
- const float * matrix = (const float*)this->matrix;
+ const float * matrix = (const float*)this->matrix;
///////--- Near Plane ---///////
Plane near_plane=Plane(matrix[ 3] + matrix[ 2],
matrix[ 7] + matrix[ 6],
matrix[11] + matrix[10],
-matrix[15] - matrix[14]).normalized();
-
+
///////--- Right Plane ---///////
Plane right_plane=Plane(matrix[ 3] - matrix[ 0],
matrix[ 7] - matrix[ 4],
matrix[11] - matrix[ 8],
- matrix[15] + matrix[12]).normalized();
-
+
Plane top_plane=Plane(matrix[ 3] - matrix[ 1],
matrix[ 7] - matrix[ 5],
matrix[11] - matrix[ 9],
-matrix[15] + matrix[13]).normalized();
-
+
Vector3 res;
near_plane.intersect_3(right_plane,top_plane,&res);
-
+
r_width=res.x;
r_height=res.y;
}
bool CameraMatrix::get_endpoints(const Transform& p_transform, Vector3 *p_8points) const {
- const float * matrix = (const float*)this->matrix;
-
+ const float * matrix = (const float*)this->matrix;
+
///////--- Near Plane ---///////
Plane near_plane=Plane(matrix[ 3] + matrix[ 2],
matrix[ 7] + matrix[ 6],
matrix[11] + matrix[10],
-matrix[15] - matrix[14]).normalized();
-
+
///////--- Far Plane ---///////
Plane far_plane=Plane(matrix[ 2] - matrix[ 3],
matrix[ 6] - matrix[ 7],
matrix[10] - matrix[11],
matrix[15] - matrix[14]).normalized();
-
+
///////--- Right Plane ---///////
Plane right_plane=Plane(matrix[ 0] - matrix[ 3],
matrix[ 4] - matrix[ 7],
matrix[8] - matrix[ 11],
- matrix[15] + matrix[12]).normalized();
-
- ///////--- Top Plane ---///////
+
+ ///////--- Top Plane ---///////
Plane top_plane=Plane(matrix[ 1] - matrix[ 3],
matrix[ 5] - matrix[ 7],
matrix[9] - matrix[ 11],
-matrix[15] + matrix[13]).normalized();
-
+
Vector3 near_endpoint;
Vector3 far_endpoint;
-
+
bool res=near_plane.intersect_3(right_plane,top_plane,&near_endpoint);
ERR_FAIL_COND_V(!res,false);
-
+
res=far_plane.intersect_3(right_plane,top_plane,&far_endpoint);
ERR_FAIL_COND_V(!res,false);
-
+
p_8points[0]=p_transform.xform( Vector3( near_endpoint.x, near_endpoint.y, near_endpoint.z ) );
p_8points[1]=p_transform.xform( Vector3( near_endpoint.x,-near_endpoint.y, near_endpoint.z ) );
p_8points[2]=p_transform.xform( Vector3(-near_endpoint.x, near_endpoint.y, near_endpoint.z ) );
@@ -252,7 +252,7 @@ bool CameraMatrix::get_endpoints(const Transform& p_transform, Vector3 *p_8point
p_8points[5]=p_transform.xform( Vector3( far_endpoint.x,-far_endpoint.y, far_endpoint.z ) );
p_8points[6]=p_transform.xform( Vector3(-far_endpoint.x, far_endpoint.y, far_endpoint.z ) );
p_8points[7]=p_transform.xform( Vector3(-far_endpoint.x,-far_endpoint.y, far_endpoint.z ) );
-
+
return true;
}
@@ -263,10 +263,10 @@ Vector<Plane> CameraMatrix::get_projection_planes(const Transform& p_transform)
* http://www.markmorley.com/opengl/frustumculling.html
* http://www2.ravensoft.com/users/ggribb/plane%20extraction.pdf
*/
-
+
Vector<Plane> planes;
-
- const float * matrix = (const float*)this->matrix;
+
+ const float * matrix = (const float*)this->matrix;
Plane new_plane;
@@ -275,7 +275,7 @@ Vector<Plane> CameraMatrix::get_projection_planes(const Transform& p_transform)
matrix[ 7] + matrix[ 6],
matrix[11] + matrix[10],
matrix[15] + matrix[14]);
-
+
new_plane.normal=-new_plane.normal;
new_plane.normalize();
@@ -298,7 +298,7 @@ Vector<Plane> CameraMatrix::get_projection_planes(const Transform& p_transform)
matrix[ 7] + matrix[ 4],
matrix[11] + matrix[ 8],
matrix[15] + matrix[12]);
-
+
new_plane.normal=-new_plane.normal;
new_plane.normalize();
@@ -310,8 +310,8 @@ Vector<Plane> CameraMatrix::get_projection_planes(const Transform& p_transform)
matrix[ 7] - matrix[ 5],
matrix[11] - matrix[ 9],
matrix[15] - matrix[13]);
-
-
+
+
new_plane.normal=-new_plane.normal;
new_plane.normalize();
@@ -324,10 +324,10 @@ Vector<Plane> CameraMatrix::get_projection_planes(const Transform& p_transform)
matrix[11] - matrix[ 8],
matrix[15] - matrix[12]);
-
+
new_plane.normal=-new_plane.normal;
new_plane.normalize();
-
+
planes.push_back( p_transform.xform(new_plane) );
@@ -337,12 +337,12 @@ Vector<Plane> CameraMatrix::get_projection_planes(const Transform& p_transform)
matrix[11] + matrix[ 9],
matrix[15] + matrix[13]);
-
+
new_plane.normal=-new_plane.normal;
new_plane.normalize();
planes.push_back( p_transform.xform(new_plane) );
-
+
return planes;
}
@@ -356,7 +356,7 @@ CameraMatrix CameraMatrix::inverse() const {
}
void CameraMatrix::invert() {
-
+
int i,j,k;
int pvt_i[4], pvt_j[4]; /* Locations of pivot matrix */
float pvt_val; /* Value of current pivot element */
@@ -448,7 +448,7 @@ void CameraMatrix::invert() {
}
}
-
+
}
CameraMatrix::CameraMatrix() {
@@ -475,31 +475,31 @@ CameraMatrix CameraMatrix::operator*(const CameraMatrix& p_matrix) const {
void CameraMatrix::set_light_bias() {
float *m=&matrix[0][0];
-
- m[0]=0.5,
- m[1]=0.0,
- m[2]=0.0,
+
+ m[0]=0.5,
+ m[1]=0.0,
+ m[2]=0.0,
m[3]=0.0,
- m[4]=0.0,
- m[5]=0.5,
- m[6]=0.0,
+ m[4]=0.0,
+ m[5]=0.5,
+ m[6]=0.0,
m[7]=0.0,
- m[8]=0.0,
- m[9]=0.0,
- m[10]=0.5,
+ m[8]=0.0,
+ m[9]=0.0,
+ m[10]=0.5,
m[11]=0.0,
- m[12]=0.5,
- m[13]=0.5,
- m[14]=0.5,
- m[15]=1.0;
-
+ m[12]=0.5,
+ m[13]=0.5,
+ m[14]=0.5,
+ m[15]=1.0;
+
}
CameraMatrix::operator String() const {
String str;
- for (int i=0;i<4;i++)
- for (int j=0;j<4;j++)
+ for (int i=0;i<4;i++)
+ for (int j=0;j<4;j++)
str+=String((j>0)?", ":"\n")+rtos(matrix[i][j]);
return str;
@@ -513,7 +513,7 @@ float CameraMatrix::get_aspect() const {
}
float CameraMatrix::get_fov() const {
- const float * matrix = (const float*)this->matrix;
+ const float * matrix = (const float*)this->matrix;
Plane right_plane=Plane(matrix[ 3] - matrix[ 0],
matrix[ 7] - matrix[ 4],
@@ -588,7 +588,7 @@ CameraMatrix::CameraMatrix(const Transform& p_transform) {
const Transform &tr = p_transform;
float *m=&matrix[0][0];
-
+
m[0]=tr.basis.elements[0][0];
m[1]=tr.basis.elements[1][0];
m[2]=tr.basis.elements[2][0];
@@ -604,7 +604,7 @@ CameraMatrix::CameraMatrix(const Transform& p_transform) {
m[12]=tr.origin.x;
m[13]=tr.origin.y;
m[14]=tr.origin.z;
- m[15]=1.0;
+ m[15]=1.0;
}
CameraMatrix::~CameraMatrix()
diff --git a/core/math/camera_matrix.h b/core/math/camera_matrix.h
index 27500a545e..d192b1fef1 100644
--- a/core/math/camera_matrix.h
+++ b/core/math/camera_matrix.h
@@ -48,8 +48,8 @@ struct CameraMatrix {
};
float matrix[4][4];
-
-
+
+
void set_identity();
void set_zero();
void set_light_bias();
@@ -67,12 +67,12 @@ struct CameraMatrix {
float get_z_near() const;
float get_aspect() const;
float get_fov() const;
-
+
Vector<Plane> get_projection_planes(const Transform& p_transform) const;
-
+
bool get_endpoints(const Transform& p_transform,Vector3 *p_8points) const;
void get_viewport_size(float& r_width, float& r_height) const;
-
+
void invert();
CameraMatrix inverse() const;
@@ -80,15 +80,15 @@ struct CameraMatrix {
Plane xform4(const Plane& p_vec4);
_FORCE_INLINE_ Vector3 xform(const Vector3& p_vec3) const;
-
+
operator String() const;
void scale_translate_to_fit(const AABB& p_aabb);
void make_scale(const Vector3 &p_scale);
operator Transform() const;
- CameraMatrix();
- CameraMatrix(const Transform& p_transform);
+ CameraMatrix();
+ CameraMatrix(const Transform& p_transform);
~CameraMatrix();
};
diff --git a/core/math/face3.h b/core/math/face3.h
index c36fdd1332..bc34be9935 100644
--- a/core/math/face3.h
+++ b/core/math/face3.h
@@ -55,7 +55,7 @@ public:
* @param _epsilon constant used for numerical error rounding, to add "thickness" to the plane (so coplanar points can happen)
* @return amount of faces generated by the split, either 0 (means no split possible), 2 or 3
*/
-
+
int split_by_plane(const Plane& p_plane,Face3 *p_res,bool *p_is_point_over) const;
Plane get_plane(ClockDirection p_dir=CLOCKWISE) const;
@@ -77,7 +77,7 @@ public:
void get_support(const Vector3& p_normal,const Transform& p_transform,Vector3 *p_vertices,int* p_count,int p_max) const;
void project_range(const Vector3& p_normal,const Transform& p_transform,float& r_min, float& r_max) const;
-
+
AABB get_aabb() const {
AABB aabb( vertex[0], Vector3() );
diff --git a/core/math/geometry.cpp b/core/math/geometry.cpp
index 2905d26fe5..5b767212f5 100644
--- a/core/math/geometry.cpp
+++ b/core/math/geometry.cpp
@@ -211,7 +211,7 @@ DVector< DVector< Face3 > > Geometry::separate_objects( DVector< Face3 > p_array
int len = p_array.size();
DVector<Face3>::Read r=p_array.read();
-
+
const Face3* arrayptr = r.ptr();
DVector< _FaceClassify> fc;
@@ -219,7 +219,7 @@ DVector< DVector< Face3 > > Geometry::separate_objects( DVector< Face3 > p_array
fc.resize( len );
DVector< _FaceClassify >::Write fcw=fc.write();
-
+
_FaceClassify * _fcptr = fcw.ptr();
for (int i=0;i<len;i++) {
@@ -278,7 +278,7 @@ DVector< DVector< Face3 > > Geometry::separate_objects( DVector< Face3 > p_array
/*** GEOMETRY WRAPPER ***/
enum _CellFlags {
-
+
_CELL_SOLID=1,
_CELL_EXTERIOR=2,
_CELL_STEP_MASK=0x1C,
@@ -299,7 +299,7 @@ enum _CellFlags {
_CELL_PREV_Z_POS=5<<5,
_CELL_PREV_Z_NEG=6<<5,
_CELL_PREV_FIRST=7<<5,
-
+
};
static inline void _plot_face(uint8_t*** p_cell_status,int x,int y,int z,int len_x,int len_y,int len_z,const Vector3& voxelsize,const Face3& p_face) {
@@ -316,9 +316,9 @@ static inline void _plot_face(uint8_t*** p_cell_status,int x,int y,int z,int len
p_cell_status[x][y][z]=_CELL_SOLID;
return;
}
-
-
-
+
+
+
int div_x=len_x>1?2:1;
int div_y=len_y>1?2:1;
int div_z=len_z>1?2:1;
@@ -343,14 +343,14 @@ static inline void _plot_face(uint8_t*** p_cell_status,int x,int y,int z,int len
int new_len_z;
for (int i=0;i<div_x;i++) {
-
-
+
+
_SPLIT(i,div_x,x,len_x,new_x,new_len_x);
-
+
for (int j=0;j<div_y;j++) {
_SPLIT(j,div_y,y,len_y,new_y,new_len_y);
-
+
for (int k=0;k<div_z;k++) {
_SPLIT(k,div_z,z,len_z,new_z,new_len_z);
@@ -365,39 +365,39 @@ static inline void _mark_outside(uint8_t*** p_cell_status,int x,int y,int z,int
if (p_cell_status[x][y][z]&3)
return; // nothing to do, already used and/or visited
-
+
p_cell_status[x][y][z]=_CELL_PREV_FIRST;
-
+
while(true) {
-
+
uint8_t &c = p_cell_status[x][y][z];
-
+
//printf("at %i,%i,%i\n",x,y,z);
-
- if ( (c&_CELL_STEP_MASK)==_CELL_STEP_NONE) {
+
+ if ( (c&_CELL_STEP_MASK)==_CELL_STEP_NONE) {
/* Haven't been in here, mark as outside */
p_cell_status[x][y][z]|=_CELL_EXTERIOR;
//printf("not marked as anything, marking exterior\n");
}
-
+
//printf("cell step is %i\n",(c&_CELL_STEP_MASK));
-
+
if ( (c&_CELL_STEP_MASK)!=_CELL_STEP_DONE) {
/* if not done, increase step */
c+=1<<2;
//printf("incrementing cell step\n");
}
-
+
if ( (c&_CELL_STEP_MASK)==_CELL_STEP_DONE) {
/* Go back */
//printf("done, going back a cell\n");
-
+
switch(c&_CELL_PREV_MASK) {
case _CELL_PREV_FIRST: {
- //printf("at end, finished marking\n");
+ //printf("at end, finished marking\n");
return;
} break;
- case _CELL_PREV_Y_POS: {
+ case _CELL_PREV_Y_POS: {
y++;
ERR_FAIL_COND(y>=len_y);
} break;
@@ -427,16 +427,16 @@ static inline void _mark_outside(uint8_t*** p_cell_status,int x,int y,int z,int
}
continue;
}
-
+
//printf("attempting new cell!\n");
-
+
int next_x=x,next_y=y,next_z=z;
uint8_t prev=0;
-
+
switch(c&_CELL_STEP_MASK) {
-
+
case _CELL_STEP_Y_POS: {
-
+
next_y++;
prev=_CELL_PREV_Y_NEG;
} break;
@@ -454,32 +454,32 @@ static inline void _mark_outside(uint8_t*** p_cell_status,int x,int y,int z,int
} break;
case _CELL_STEP_Z_POS: {
next_z++;
- prev=_CELL_PREV_Z_NEG;
+ prev=_CELL_PREV_Z_NEG;
} break;
case _CELL_STEP_Z_NEG: {
next_z--;
- prev=_CELL_PREV_Z_POS;
+ prev=_CELL_PREV_Z_POS;
} break;
- default: ERR_FAIL();
-
+ default: ERR_FAIL();
+
}
-
+
//printf("testing if new cell will be ok...!\n");
-
+
if (next_x<0 || next_x>=len_x)
continue;
if (next_y<0 || next_y>=len_y)
continue;
if (next_z<0 || next_z>=len_z)
continue;
-
+
//printf("testing if new cell is traversable\n");
-
+
if (p_cell_status[next_x][next_y][next_z]&3)
continue;
-
+
//printf("move to it\n");
-
+
x=next_x;
y=next_y;
z=next_z;
@@ -488,14 +488,14 @@ static inline void _mark_outside(uint8_t*** p_cell_status,int x,int y,int z,int
}
static inline void _build_faces(uint8_t*** p_cell_status,int x,int y,int z,int len_x,int len_y,int len_z,DVector<Face3>& p_faces) {
-
+
ERR_FAIL_INDEX(x,len_x);
ERR_FAIL_INDEX(y,len_y);
ERR_FAIL_INDEX(z,len_z);
-
+
if (p_cell_status[x][y][z]&_CELL_EXTERIOR)
- return;
-
+ return;
+
/* static const Vector3 vertices[8]={
Vector3(0,0,0),
Vector3(0,0,1),
@@ -510,73 +510,73 @@ static inline void _build_faces(uint8_t*** p_cell_status,int x,int y,int z,int l
#define vert(m_idx) Vector3( (m_idx&4)>>2, (m_idx&2)>>1, m_idx&1 )
static const uint8_t indices[6][4]={
- {7,6,4,5},
+ {7,6,4,5},
{7,3,2,6},
- {7,5,1,3},
- {0,2,3,1},
- {0,1,5,4},
+ {7,5,1,3},
+ {0,2,3,1},
+ {0,1,5,4},
{0,4,6,2},
};
-/*
+/*
- {0,1,2,3},
- {0,1,4,5},
+ {0,1,2,3},
+ {0,1,4,5},
{0,2,4,6},
- {4,5,6,7},
+ {4,5,6,7},
{2,3,7,6},
- {1,3,5,7},
+ {1,3,5,7},
- {0,2,3,1},
- {0,1,5,4},
+ {0,2,3,1},
+ {0,1,5,4},
{0,4,6,2},
- {7,6,4,5},
+ {7,6,4,5},
{7,3,2,6},
- {7,5,1,3},
+ {7,5,1,3},
*/
-
+
for (int i=0;i<6;i++) {
-
+
Vector3 face_points[4];
int disp_x=x+((i%3)==0?((i<3)?1:-1):0);
int disp_y=y+(((i-1)%3)==0?((i<3)?1:-1):0);
int disp_z=z+(((i-2)%3)==0?((i<3)?1:-1):0);
-
+
bool plot=false;
-
+
if (disp_x<0 || disp_x>=len_x)
plot=true;
if (disp_y<0 || disp_y>=len_y)
plot=true;
if (disp_z<0 || disp_z>=len_z)
plot=true;
-
+
if (!plot && (p_cell_status[disp_x][disp_y][disp_z]&_CELL_EXTERIOR))
plot=true;
-
+
if (!plot)
continue;
-
+
for (int j=0;j<4;j++)
face_points[j]=vert( indices[i][j] ) + Vector3(x,y,z);
-
- p_faces.push_back(
- Face3(
+
+ p_faces.push_back(
+ Face3(
face_points[0],
face_points[1],
face_points[2]
)
);
-
- p_faces.push_back(
- Face3(
+
+ p_faces.push_back(
+ Face3(
face_points[2],
face_points[3],
face_points[0]
)
);
-
- }
+
+ }
}
@@ -601,7 +601,7 @@ DVector< Face3 > Geometry::wrap_geometry( DVector< Face3 > p_array,float *p_erro
global_aabb.merge_with( faces[i].get_aabb() );
}
}
-
+
global_aabb.grow_by(0.01); // avoid numerical error
// determine amount of cells in grid axis
@@ -649,7 +649,7 @@ DVector< Face3 > Geometry::wrap_geometry( DVector< Face3 > p_array,float *p_erro
// plot faces into cells
print_line("Wrapper (1/6): Plotting Faces");
-
+
for (int i=0;i<face_count;i++) {
Face3 f=faces[i];
@@ -666,68 +666,68 @@ DVector< Face3 > Geometry::wrap_geometry( DVector< Face3 > p_array,float *p_erro
print_line("Wrapper (2/6) Flood Filling");
for (int i=0;i<div_x;i++) {
-
+
for (int j=0;j<div_y;j++) {
-
+
_mark_outside(cell_status,i,j,0,div_x,div_y,div_z);
_mark_outside(cell_status,i,j,div_z-1,div_x,div_y,div_z);
}
}
-
+
for (int i=0;i<div_z;i++) {
-
+
for (int j=0;j<div_y;j++) {
-
+
_mark_outside(cell_status,0,j,i,div_x,div_y,div_z);
_mark_outside(cell_status,div_x-1,j,i,div_x,div_y,div_z);
}
}
-
+
for (int i=0;i<div_x;i++) {
-
+
for (int j=0;j<div_z;j++) {
-
+
_mark_outside(cell_status,i,0,j,div_x,div_y,div_z);
_mark_outside(cell_status,i,div_y-1,j,div_x,div_y,div_z);
}
}
-
+
// build faces for the inside-outside cell divisors
-
+
print_line("Wrapper (3/6): Building Faces");
DVector<Face3> wrapped_faces;
-
+
for (int i=0;i<div_x;i++) {
-
+
for (int j=0;j<div_y;j++) {
-
+
for (int k=0;k<div_z;k++) {
-
- _build_faces(cell_status,i,j,k,div_x,div_y,div_z,wrapped_faces);
+
+ _build_faces(cell_status,i,j,k,div_x,div_y,div_z,wrapped_faces);
}
}
}
-
+
print_line("Wrapper (4/6): Transforming Back Vertices");
// transform face vertices to global coords
-
+
int wrapped_faces_count=wrapped_faces.size();
DVector<Face3>::Write wrapped_facesw=wrapped_faces.write();
Face3* wrapped_faces_ptr=wrapped_facesw.ptr();
-
+
for(int i=0;i<wrapped_faces_count;i++) {
-
+
for(int j=0;j<3;j++) {
-
+
Vector3& v = wrapped_faces_ptr[i].vertex[j];
v=v*voxelsize;
v+=global_aabb.pos;
}
}
-
- // clean up grid
+
+ // clean up grid
print_line("Wrapper (5/6): Grid Cleanup");
for(int i=0;i<div_x;i++) {
@@ -736,14 +736,14 @@ DVector< Face3 > Geometry::wrap_geometry( DVector< Face3 > p_array,float *p_erro
memdelete_arr( cell_status[i][j] );
}
-
+
memdelete_arr( cell_status[i] );
}
-
+
memdelete_arr(cell_status);
if (p_error)
*p_error=voxelsize.length();
-
+
print_line("Wrapper (6/6): Finished.");
return wrapped_faces;
}
@@ -751,67 +751,67 @@ DVector< Face3 > Geometry::wrap_geometry( DVector< Face3 > p_array,float *p_erro
Geometry::MeshData Geometry::build_convex_mesh(const DVector<Plane> &p_planes) {
MeshData mesh;
-
-
+
+
#define SUBPLANE_SIZE 1024.0
-
+
float subplane_size = 1024.0; // should compute this from the actual plane
for (int i=0;i<p_planes.size();i++) {
-
+
Plane p =p_planes[i];
-
+
Vector3 ref=Vector3(0.0,1.0,0.0);
-
+
if (ABS(p.normal.dot(ref))>0.95)
ref=Vector3(0.0,0.0,1.0); // change axis
-
+
Vector3 right = p.normal.cross(ref).normalized();
Vector3 up = p.normal.cross( right ).normalized();
-
+
Vector< Vector3 > vertices;
-
+
Vector3 center = p.get_any_point();
// make a quad clockwise
vertices.push_back( center - up * subplane_size + right * subplane_size );
vertices.push_back( center - up * subplane_size - right * subplane_size );
vertices.push_back( center + up * subplane_size - right * subplane_size );
vertices.push_back( center + up * subplane_size + right * subplane_size );
-
+
for (int j=0;j<p_planes.size();j++) {
if (j==i)
continue;
-
+
Vector< Vector3 > new_vertices;
Plane clip=p_planes[j];
-
+
if (clip.normal.dot(p.normal)>0.95)
continue;
-
+
if (vertices.size()<3)
break;
-
+
for(int k=0;k<vertices.size();k++) {
-
+
int k_n=(k+1)%vertices.size();
-
+
Vector3 edge0_A=vertices[k];
Vector3 edge1_A=vertices[k_n];
-
+
real_t dist0 = clip.distance_to(edge0_A);
real_t dist1 = clip.distance_to(edge1_A);
-
-
- if ( dist0 <= 0 ) { // behind plane
-
- new_vertices.push_back(vertices[k]);
+
+
+ if ( dist0 <= 0 ) { // behind plane
+
+ new_vertices.push_back(vertices[k]);
}
-
-
+
+
// check for different sides and non coplanar
- if ( (dist0*dist1) < 0) {
-
+ if ( (dist0*dist1) < 0) {
+
// calculate intersection
Vector3 rel = edge1_A - edge0_A;
@@ -822,55 +822,55 @@ Geometry::MeshData Geometry::build_convex_mesh(const DVector<Plane> &p_planes) {
real_t dist=-(clip.normal.dot( edge0_A )-clip.d)/den;
Vector3 inters = edge0_A+rel*dist;
new_vertices.push_back(inters);
- }
+ }
}
-
+
vertices=new_vertices;
}
-
+
if (vertices.size()<3)
continue;
-
-
+
+
//result is a clockwise face
-
+
MeshData::Face face;
-
+
// add face indices
for (int j=0;j<vertices.size();j++) {
-
-
+
+
int idx=-1;
for (int k=0;k<mesh.vertices.size();k++) {
-
+
if (mesh.vertices[k].distance_to(vertices[j])<0.001) {
-
+
idx=k;
break;
}
}
-
+
if (idx==-1) {
-
+
idx=mesh.vertices.size();
mesh.vertices.push_back(vertices[j]);
}
-
+
face.indices.push_back(idx);
}
face.plane=p;
mesh.faces.push_back(face);
-
+
//add edge
-
+
for(int j=0;j<face.indices.size();j++) {
-
+
int a=face.indices[j];
int b=face.indices[(j+1)%face.indices.size()];
-
+
bool found=false;
for(int k=0;k<mesh.edges.size();k++) {
-
+
if (mesh.edges[k].a==a && mesh.edges[k].b==b) {
found=true;
break;
@@ -878,9 +878,9 @@ Geometry::MeshData Geometry::build_convex_mesh(const DVector<Plane> &p_planes) {
if (mesh.edges[k].b==a && mesh.edges[k].a==b) {
found=true;
break;
- }
+ }
}
-
+
if (found)
continue;
MeshData::Edge edge;
@@ -888,8 +888,8 @@ Geometry::MeshData Geometry::build_convex_mesh(const DVector<Plane> &p_planes) {
edge.b=b;
mesh.edges.push_back(edge);
}
-
-
+
+
}
return mesh;
@@ -899,36 +899,36 @@ Geometry::MeshData Geometry::build_convex_mesh(const DVector<Plane> &p_planes) {
DVector<Plane> Geometry::build_box_planes(const Vector3& p_extents) {
DVector<Plane> planes;
-
+
planes.push_back( Plane( Vector3(1,0,0), p_extents.x ) );
planes.push_back( Plane( Vector3(-1,0,0), p_extents.x ) );
planes.push_back( Plane( Vector3(0,1,0), p_extents.y ) );
planes.push_back( Plane( Vector3(0,-1,0), p_extents.y ) );
planes.push_back( Plane( Vector3(0,0,1), p_extents.z ) );
planes.push_back( Plane( Vector3(0,0,-1), p_extents.z ) );
-
+
return planes;
}
DVector<Plane> Geometry::build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis) {
DVector<Plane> planes;
-
+
for (int i=0;i<p_sides;i++) {
-
+
Vector3 normal;
normal[(p_axis+1)%3]=Math::cos(i*(2.0*Math_PI)/p_sides);
normal[(p_axis+2)%3]=Math::sin(i*(2.0*Math_PI)/p_sides);
-
+
planes.push_back( Plane( normal, p_radius ) );
}
-
+
Vector3 axis;
axis[p_axis]=1.0;
-
+
planes.push_back( Plane( axis, p_height*0.5 ) );
planes.push_back( Plane( -axis, p_height*0.5 ) );
-
+
return planes;
}
@@ -972,34 +972,34 @@ DVector<Plane> Geometry::build_sphere_planes(float p_radius, int p_lats,int p_lo
DVector<Plane> Geometry::build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis) {
DVector<Plane> planes;
-
+
Vector3 axis;
axis[p_axis]=1.0;
-
- Vector3 axis_neg;
+
+ Vector3 axis_neg;
axis_neg[(p_axis+1)%3]=1.0;
axis_neg[(p_axis+2)%3]=1.0;
axis_neg[p_axis]=-1.0;
-
+
for (int i=0;i<p_sides;i++) {
-
+
Vector3 normal;
normal[(p_axis+1)%3]=Math::cos(i*(2.0*Math_PI)/p_sides);
normal[(p_axis+2)%3]=Math::sin(i*(2.0*Math_PI)/p_sides);
-
+
planes.push_back( Plane( normal, p_radius ) );
-
+
for (int j=1;j<=p_lats;j++) {
-
+
Vector3 angle = normal.linear_interpolate(axis,j/(float)p_lats).normalized();
Vector3 pos = axis*p_height*0.5 + angle*p_radius;
planes.push_back( Plane( pos, angle ) );
planes.push_back( Plane( pos * axis_neg, angle * axis_neg) );
-
+
}
}
-
+
return planes;
}
diff --git a/core/math/geometry.h b/core/math/geometry.h
index 8370990d6e..b353423851 100644
--- a/core/math/geometry.h
+++ b/core/math/geometry.h
@@ -44,7 +44,7 @@
class Geometry {
Geometry();
public:
-
+
@@ -201,37 +201,37 @@ public:
real_t a =e1.dot(h);
if (a>-CMP_EPSILON && a < CMP_EPSILON) // parallel test
return false;
-
+
real_t f=1.0/a;
-
+
Vector3 s=p_from-p_v0;
real_t u = f * s.dot(h);
-
+
if ( u< 0.0 || u > 1.0)
return false;
-
+
Vector3 q=s.cross(e1);
-
+
real_t v = f * p_dir.dot(q);
-
+
if (v < 0.0 || u + v > 1.0)
return false;
-
- // at this stage we can compute t to find out where
+
+ // at this stage we can compute t to find out where
// the intersection point is on the line
real_t t = f * e2.dot(q);
-
+
if (t > 0.00001) {// ray intersection
if (r_res)
*r_res=p_from+p_dir*t;
return true;
- } else // this means that there is a line intersection
+ } else // this means that there is a line intersection
// but not a ray intersection
return false;
- }
-
+ }
+
static inline bool segment_intersects_triangle( const Vector3& p_from, const Vector3& p_to, const Vector3& p_v0,const Vector3& p_v1,const Vector3& p_v2,Vector3* r_res=0) {
-
+
Vector3 rel=p_to-p_from;
Vector3 e1=p_v1-p_v0;
Vector3 e2=p_v2-p_v0;
@@ -239,34 +239,34 @@ public:
real_t a =e1.dot(h);
if (a>-CMP_EPSILON && a < CMP_EPSILON) // parallel test
return false;
-
+
real_t f=1.0/a;
-
+
Vector3 s=p_from-p_v0;
real_t u = f * s.dot(h);
-
+
if ( u< 0.0 || u > 1.0)
return false;
-
+
Vector3 q=s.cross(e1);
-
+
real_t v = f * rel.dot(q);
-
+
if (v < 0.0 || u + v > 1.0)
return false;
-
- // at this stage we can compute t to find out where
+
+ // at this stage we can compute t to find out where
// the intersection point is on the line
real_t t = f * e2.dot(q);
-
+
if (t > CMP_EPSILON && t<=1.0) {// ray intersection
if (r_res)
*r_res=p_from+rel*t;
return true;
- } else // this means that there is a line intersection
+ } else // this means that there is a line intersection
// but not a ray intersection
return false;
- }
+ }
static inline bool segment_intersects_sphere( const Vector3& p_from, const Vector3& p_to, const Vector3& p_sphere_pos,real_t p_sphere_radius,Vector3* r_res=0,Vector3 *r_norm=0) {
@@ -356,24 +356,24 @@ public:
real_t box_end=size[i];
real_t cmin,cmax;
-
+
if (seg_from < seg_to) {
-
+
if (seg_from > box_end || seg_to < box_begin)
return false;
real_t length=seg_to-seg_from;
cmin = (seg_from < box_begin)?((box_begin - seg_from)/length):0;
cmax = (seg_to > box_end)?((box_end - seg_from)/length):1;
-
+
} else {
-
+
if (seg_to > box_end || seg_from < box_begin)
return false;
real_t length=seg_to-seg_from;
cmin = (seg_from > box_end)?(box_end - seg_from)/length:0;
cmax = (seg_to < box_begin)?(box_begin - seg_from)/length:1;
}
-
+
if (cmin > min) {
min = cmin;
axis=i;
@@ -468,9 +468,9 @@ public:
if (l<1e-10)
return p_segment[0]; // both points are the same, just give any
n/=l;
-
+
float d=n.dot(p);
-
+
if (d<=0.0)
return p_segment[0]; // before first point
else if (d>=l)
@@ -570,27 +570,27 @@ public:
static inline bool point_in_projected_triangle(const Vector3& p_point,const Vector3& p_v1,const Vector3& p_v2,const Vector3& p_v3) {
-
-
- Vector3 face_n = (p_v1-p_v3).cross(p_v1-p_v2);
-
- Vector3 n1 = (p_point-p_v3).cross(p_point-p_v2);
-
+
+
+ Vector3 face_n = (p_v1-p_v3).cross(p_v1-p_v2);
+
+ Vector3 n1 = (p_point-p_v3).cross(p_point-p_v2);
+
if (face_n.dot(n1)<0)
return false;
-
- Vector3 n2 = (p_v1-p_v3).cross(p_v1-p_point);
-
+
+ Vector3 n2 = (p_v1-p_v3).cross(p_v1-p_point);
+
if (face_n.dot(n2)<0)
return false;
-
- Vector3 n3 = (p_v1-p_point).cross(p_v1-p_v2);
-
+
+ Vector3 n3 = (p_v1-p_point).cross(p_v1-p_v2);
+
if (face_n.dot(n3)<0)
return false;
-
+
return true;
-
+
}
static inline bool triangle_sphere_intersection_test(const Vector3 *p_triangle,const Vector3& p_normal,const Vector3& p_sphere_pos, real_t p_sphere_radius,Vector3& r_triangle_contact,Vector3& r_sphere_contact) {
@@ -814,21 +814,21 @@ public:
struct MeshData {
-
+
struct Face {
Plane plane;
Vector<int> indices;
};
-
+
Vector<Face> faces;
-
+
struct Edge {
-
+
int a,b;
};
-
+
Vector<Edge> edges;
-
+
Vector< Vector3 > vertices;
void optimize_vertices();
@@ -927,7 +927,7 @@ public:
static void make_atlas(const Vector<Size2i>& p_rects,Vector<Point2i>& r_result, Size2i& r_size);
-
+
};
diff --git a/core/math/math_2d.cpp b/core/math/math_2d.cpp
index a485125cb4..0e2060008c 100644
--- a/core/math/math_2d.cpp
+++ b/core/math/math_2d.cpp
@@ -45,10 +45,10 @@ float Vector2::length_squared() const {
}
void Vector2::normalize() {
-
+
float l = x*x + y*y;
if (l!=0) {
-
+
l=Math::sqrt(l);
x/=l;
y/=l;
@@ -56,14 +56,14 @@ void Vector2::normalize() {
}
Vector2 Vector2::normalized() const {
-
+
Vector2 v=*this;
v.normalize();
return v;
}
float Vector2::distance_to(const Vector2& p_vector2) const {
-
+
return Math::sqrt( (x-p_vector2.x)*(x-p_vector2.x) + (y-p_vector2.y)*(y-p_vector2.y));
}
@@ -73,7 +73,7 @@ float Vector2::distance_squared_to(const Vector2& p_vector2) const {
}
float Vector2::angle_to(const Vector2& p_vector2) const {
-
+
return Math::atan2( tangent().dot(p_vector2), dot(p_vector2) );
}
@@ -83,7 +83,7 @@ float Vector2::angle_to_point(const Vector2& p_vector2) const {
}
float Vector2::dot(const Vector2& p_other) const {
-
+
return x*p_other.x + y*p_other.y;
}
@@ -99,62 +99,62 @@ Vector2 Vector2::cross(real_t p_other) const {
Vector2 Vector2::operator+(const Vector2& p_v) const {
-
+
return Vector2(x+p_v.x,y+p_v.y);
}
void Vector2::operator+=(const Vector2& p_v) {
-
+
x+=p_v.x; y+=p_v.y;
}
Vector2 Vector2::operator-(const Vector2& p_v) const {
-
+
return Vector2(x-p_v.x,y-p_v.y);
}
void Vector2::operator-=(const Vector2& p_v) {
-
+
x-=p_v.x; y-=p_v.y;
}
Vector2 Vector2::operator*(const Vector2 &p_v1) const {
-
+
return Vector2(x * p_v1.x, y * p_v1.y);
};
Vector2 Vector2::operator*(const float &rvalue) const {
-
+
return Vector2(x * rvalue, y * rvalue);
};
void Vector2::operator*=(const float &rvalue) {
-
+
x *= rvalue; y *= rvalue;
};
Vector2 Vector2::operator/(const Vector2 &p_v1) const {
-
+
return Vector2(x / p_v1.x, y / p_v1.y);
};
Vector2 Vector2::operator/(const float &rvalue) const {
-
+
return Vector2(x / rvalue, y / rvalue);
};
void Vector2::operator/=(const float &rvalue) {
-
+
x /= rvalue; y /= rvalue;
};
Vector2 Vector2::operator-() const {
-
+
return Vector2(-x,-y);
}
bool Vector2::operator==(const Vector2& p_vec2) const {
-
+
return x==p_vec2.x && y==p_vec2.y;
}
bool Vector2::operator!=(const Vector2& p_vec2) const {
-
+
return x!=p_vec2.x || y!=p_vec2.y;
}
Vector2 Vector2::floor() const {
@@ -621,25 +621,25 @@ float Matrix32::basis_determinant() const {
}
Matrix32 Matrix32::interpolate_with(const Matrix32& p_transform, float p_c) const {
-
+
//extract parameters
Vector2 p1 = get_origin();
Vector2 p2 = p_transform.get_origin();
-
+
real_t r1 = get_rotation();
real_t r2 = p_transform.get_rotation();
-
+
Vector2 s1 = get_scale();
Vector2 s2 = p_transform.get_scale();
-
+
//slerp rotation
Vector2 v1(Math::cos(r1), Math::sin(r1));
Vector2 v2(Math::cos(r2), Math::sin(r2));
-
+
real_t dot = v1.dot(v2);
-
+
dot = (dot < -1.0) ? -1.0 : ((dot > 1.0) ? 1.0 : dot); //clamp dot to [-1,1]
-
+
Vector2 v;
if (dot > 0.9995) {
@@ -649,7 +649,7 @@ Matrix32 Matrix32::interpolate_with(const Matrix32& p_transform, float p_c) cons
Vector2 v3 = (v2 - v1*dot).normalized();
v = v1*Math::cos(angle) + v3*Math::sin(angle);
}
-
+
//construct matrix
Matrix32 res(Math::atan2(v.y, v.x), Vector2::linear_interpolate(p1, p2, p_c));
res.scale_basis(Vector2::linear_interpolate(s1, s2, p_c));
diff --git a/core/math/math_2d.h b/core/math/math_2d.h
index 1171364671..ad4655b8f7 100644
--- a/core/math/math_2d.h
+++ b/core/math/math_2d.h
@@ -35,15 +35,15 @@
@author Juan Linietsky <reduzio@gmail.com>
*/
enum Margin {
-
+
MARGIN_LEFT,
MARGIN_TOP,
MARGIN_RIGHT,
- MARGIN_BOTTOM
+ MARGIN_BOTTOM
};
enum Orientation {
-
+
HORIZONTAL,
VERTICAL
};
@@ -63,7 +63,7 @@ enum VAlign {
};
struct Vector2 {
-
+
union {
float x;
float width;
@@ -87,7 +87,7 @@ struct Vector2 {
float length() const;
float length_squared() const;
- float distance_to(const Vector2& p_vector2) const;
+ float distance_to(const Vector2& p_vector2) const;
float distance_squared_to(const Vector2& p_vector2) const;
float angle_to(const Vector2& p_vector2) const;
float angle_to_point(const Vector2& p_vector2) const;
@@ -114,19 +114,19 @@ struct Vector2 {
Vector2 operator-(const Vector2& p_v) const;
void operator-=(const Vector2& p_v);
Vector2 operator*(const Vector2 &p_v1) const;
-
+
Vector2 operator*(const float &rvalue) const;
void operator*=(const float &rvalue);
void operator*=(const Vector2 &rvalue) { *this = *this * rvalue; }
Vector2 operator/(const Vector2 &p_v1) const;
-
+
Vector2 operator/(const float &rvalue) const;
-
+
void operator/=(const float &rvalue);
-
+
Vector2 operator-() const;
-
+
bool operator==(const Vector2& p_vec2) const;
bool operator!=(const Vector2& p_vec2) const;
@@ -151,14 +151,14 @@ struct Vector2 {
return Vector2(y,-x);
}
-
+
Vector2 floor() const;
Vector2 snapped(const Vector2& p_by) const;
float get_aspect() const { return width/height; }
-
+
operator String() const { return String::num(x)+","+String::num(y); }
-
+
_FORCE_INLINE_ Vector2(float p_x,float p_y) { x=p_x; y=p_y; }
_FORCE_INLINE_ Vector2() { x=0; y=0; }
};
@@ -202,7 +202,7 @@ struct Matrix32;
struct Rect2 {
-
+
Point2 pos;
Size2 size;
@@ -213,7 +213,7 @@ struct Rect2 {
float get_area() const { return size.width*size.height; }
- inline bool intersects(const Rect2& p_rect) const {
+ inline bool intersects(const Rect2& p_rect) const {
if ( pos.x >= (p_rect.pos.x + p_rect.size.width) )
return false;
if ( (pos.x+size.width) <= p_rect.pos.x )
@@ -222,7 +222,7 @@ struct Rect2 {
return false;
if ( (pos.y+size.height) <= p_rect.pos.y )
return false;
-
+
return true;
}
@@ -254,73 +254,73 @@ struct Rect2 {
bool intersects_segment(const Point2& p_from, const Point2& p_to, Point2* r_pos=NULL, Point2* r_normal=NULL) const;
inline bool encloses(const Rect2& p_rect) const {
-
+
return (p_rect.pos.x>=pos.x) && (p_rect.pos.y>=pos.y) &&
((p_rect.pos.x+p_rect.size.x)<(pos.x+size.x)) &&
((p_rect.pos.y+p_rect.size.y)<(pos.y+size.y));
-
+
}
-
+
inline bool has_no_area() const {
-
+
return (size.x<=0 || size.y<=0);
-
+
}
inline Rect2 clip(const Rect2& p_rect) const { /// return a clipped rect
-
+
Rect2 new_rect=p_rect;
-
+
if (!intersects( new_rect ))
return Rect2();
-
+
new_rect.pos.x = MAX( p_rect.pos.x , pos.x );
new_rect.pos.y = MAX( p_rect.pos.y , pos.y );
-
+
Point2 p_rect_end=p_rect.pos+p_rect.size;
Point2 end=pos+size;
-
+
new_rect.size.x=MIN(p_rect_end.x,end.x) - new_rect.pos.x;
new_rect.size.y=MIN(p_rect_end.y,end.y) - new_rect.pos.y;
-
+
return new_rect;
}
-
+
inline Rect2 merge(const Rect2& p_rect) const { ///< return a merged rect
-
+
Rect2 new_rect;
-
+
new_rect.pos.x=MIN( p_rect.pos.x , pos.x );
new_rect.pos.y=MIN( p_rect.pos.y , pos.y );
-
-
+
+
new_rect.size.x = MAX( p_rect.pos.x+p_rect.size.x , pos.x+size.x );
new_rect.size.y = MAX( p_rect.pos.y+p_rect.size.y , pos.y+size.y );
-
+
new_rect.size = new_rect.size - new_rect.pos; //make relative again
-
+
return new_rect;
};
inline bool has_point(const Point2& p_point) const {
if (p_point.x < pos.x)
- return false;
+ return false;
if (p_point.y < pos.y)
- return false;
-
+ return false;
+
if (p_point.x >= (pos.x+size.x) )
- return false;
+ return false;
if (p_point.y >= (pos.y+size.y) )
- return false;
-
+ return false;
+
return true;
}
-
+
inline bool no_area() const { return (size.width<=0 || size.height<=0 ); }
-
+
bool operator==(const Rect2& p_rect) const { return pos==p_rect.pos && size==p_rect.size; }
bool operator!=(const Rect2& p_rect) const { return pos!=p_rect.pos || size!=p_rect.size; }
-
+
inline Rect2 grow(real_t p_by) const {
-
+
Rect2 g=*this;
g.pos.x-=p_by;
g.pos.y-=p_by;
@@ -357,9 +357,9 @@ struct Rect2 {
operator String() const { return String(pos)+","+String(size); }
-
+
Rect2() {}
- Rect2( float p_x, float p_y, float p_width, float p_height) { pos=Point2(p_x,p_y); size=Size2( p_width, p_height ); }
+ Rect2( float p_x, float p_y, float p_width, float p_height) { pos=Point2(p_x,p_y); size=Size2( p_width, p_height ); }
Rect2( const Point2& p_pos, const Size2& p_size ) { pos=p_pos; size=p_size; }
};
diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp
index 20d9db3375..07f114725d 100644
--- a/core/math/math_funcs.cpp
+++ b/core/math/math_funcs.cpp
@@ -185,12 +185,12 @@ double Math::fmod(double p_x,double p_y) {
double Math::fposmod(double p_x,double p_y) {
if (p_x>=0) {
-
+
return Math::fmod(p_x,p_y);
-
+
} else {
-
- return p_y-Math::fmod(-p_x,p_y);
+
+ return p_y-Math::fmod(-p_x,p_y);
}
}
@@ -205,7 +205,7 @@ double Math::ceil(double p_x) {
}
int Math::decimals(double p_step) {
-
+
int max=4;
double llimit = Math::pow(0.1,max);
double ulimit = 1.0-llimit;
@@ -220,7 +220,7 @@ int Math::decimals(double p_step) {
max--;
i++;
}
-
+
return i;
}
@@ -251,11 +251,11 @@ double Math::ease(double p_x, double p_c) {
}
double Math::stepify(double p_value,double p_step) {
-
+
if (p_step!=0) {
-
- p_value=floor( p_value / p_step + 0.5 ) * p_step;
- }
+
+ p_value=floor( p_value / p_step + 0.5 ) * p_step;
+ }
return p_value;
}
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index 62890b0371..2e1b9c989e 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -91,25 +91,25 @@ public:
static uint32_t rand();
static double randf();
-
+
static double round(double p_val);
static double random(double from, double to);
-
+
static _FORCE_INLINE_ real_t abs(real_t g) {
-#ifdef REAL_T_IS_DOUBLE
-
- return absd(g);
+#ifdef REAL_T_IS_DOUBLE
+
+ return absd(g);
#else
- return absf(g);
+ return absf(g);
#endif
}
static _FORCE_INLINE_ float absf(float g) {
-
+
union {
float f;
uint32_t i;
@@ -174,7 +174,7 @@ public:
static double pow(double x, double y);
static double log(double x);
static double exp(double x);
-
+
};
diff --git a/core/math/matrix3.cpp b/core/math/matrix3.cpp
index f51da80a83..71e6b62212 100644
--- a/core/math/matrix3.cpp
+++ b/core/math/matrix3.cpp
@@ -62,11 +62,11 @@ void Matrix3::invert() {
real_t det = elements[0][0] * co[0]+
elements[0][1] * co[1]+
elements[0][2] * co[2];
-
+
ERR_FAIL_COND( det == 0 );
real_t s = 1.0/det;
-
- set( co[0]*s, cofac(0, 2, 2, 1) * s, cofac(0, 1, 1, 2) * s,
+
+ set( co[0]*s, cofac(0, 2, 2, 1) * s, cofac(0, 1, 1, 2) * s,
co[1]*s, cofac(0, 0, 2, 2) * s, cofac(0, 2, 1, 0) * s,
co[2]*s, cofac(0, 1, 2, 0) * s, cofac(0, 0, 1, 1) * s );
@@ -148,7 +148,7 @@ Vector3 Matrix3::get_scale() const {
Vector3(elements[0][1],elements[1][1],elements[2][1]).length(),
Vector3(elements[0][2],elements[1][2],elements[2][2]).length()
);
-
+
}
void Matrix3::rotate(const Vector3& p_axis, real_t p_phi) {
@@ -223,7 +223,7 @@ bool Matrix3::operator==(const Matrix3& p_matrix) const {
return false;
}
}
-
+
return true;
}
bool Matrix3::operator!=(const Matrix3& p_matrix) const {
@@ -235,16 +235,16 @@ Matrix3::operator String() const {
String mtx;
for (int i=0;i<3;i++) {
-
+
for (int j=0;j<3;j++) {
-
+
if (i!=0 || j!=0)
mtx+=", ";
-
+
mtx+=rtos( elements[i][j] );
}
}
-
+
return mtx;
}
@@ -255,34 +255,34 @@ Matrix3::operator Quat() const {
real_t trace = m.elements[0][0] + m.elements[1][1] + m.elements[2][2];
real_t temp[4];
-
- if (trace > 0.0)
+
+ if (trace > 0.0)
{
real_t s = Math::sqrt(trace + 1.0);
temp[3]=(s * 0.5);
s = 0.5 / s;
-
+
temp[0]=((m.elements[2][1] - m.elements[1][2]) * s);
temp[1]=((m.elements[0][2] - m.elements[2][0]) * s);
temp[2]=((m.elements[1][0] - m.elements[0][1]) * s);
- }
- else
+ }
+ else
{
int i = m.elements[0][0] < m.elements[1][1] ?
(m.elements[1][1] < m.elements[2][2] ? 2 : 1) :
(m.elements[0][0] < m.elements[2][2] ? 2 : 0);
- int j = (i + 1) % 3;
+ int j = (i + 1) % 3;
int k = (i + 2) % 3;
-
+
real_t s = Math::sqrt(m.elements[i][i] - m.elements[j][j] - m.elements[k][k] + 1.0);
temp[i] = s * 0.5;
s = 0.5 / s;
-
+
temp[3] = (m.elements[k][j] - m.elements[j][k]) * s;
temp[j] = (m.elements[j][i] + m.elements[i][j]) * s;
temp[k] = (m.elements[k][i] + m.elements[i][k]) * s;
}
-
+
return Quat(temp[0],temp[1],temp[2],temp[3]);
}
@@ -439,7 +439,7 @@ void Matrix3::get_axis_and_angle(Vector3 &r_axis,real_t& r_angle) const {
Matrix3::Matrix3(const Vector3& p_euler) {
set_euler( p_euler );
-
+
}
Matrix3::Matrix3(const Quat& p_quat) {
@@ -450,8 +450,8 @@ Matrix3::Matrix3(const Quat& p_quat) {
real_t wx = p_quat.w * xs, wy = p_quat.w * ys, wz = p_quat.w * zs;
real_t xx = p_quat.x * xs, xy = p_quat.x * ys, xz = p_quat.x * zs;
real_t yy = p_quat.y * ys, yz = p_quat.y * zs, zz = p_quat.z * zs;
- set( 1.0 - (yy + zz), xy - wz, xz + wy,
- xy + wz, 1.0 - (xx + zz), yz - wx,
+ set( 1.0 - (yy + zz), xy - wz, xz + wy,
+ xy + wz, 1.0 - (xx + zz), yz - wx,
xz - wy, yz + wx, 1.0 - (xx + yy)) ;
}
diff --git a/core/math/matrix3.h b/core/math/matrix3.h
index 291934b8eb..e514f490f7 100644
--- a/core/math/matrix3.h
+++ b/core/math/matrix3.h
@@ -39,20 +39,20 @@ class Matrix3 {
public:
Vector3 elements[3];
-
+
_FORCE_INLINE_ const Vector3& operator[](int axis) const {
-
+
return elements[axis];
}
_FORCE_INLINE_ Vector3& operator[](int axis) {
-
+
return elements[axis];
}
- void invert();
+ void invert();
void transpose();
-
- Matrix3 inverse() const;
+
+ Matrix3 inverse() const;
Matrix3 transposed() const;
_FORCE_INLINE_ float determinant() const;
@@ -90,7 +90,7 @@ public:
_FORCE_INLINE_ real_t tdotz(const Vector3& v) const {
return elements[0][2] * v[0] + elements[1][2] * v[1] + elements[2][2] * v[2];
}
-
+
bool operator==(const Matrix3& p_matrix) const;
bool operator!=(const Matrix3& p_matrix) const;
@@ -110,7 +110,7 @@ public:
_FORCE_INLINE_ void set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz) {
-
+
elements[0][0]=xx;
elements[0][1]=xy;
elements[0][2]=xz;
@@ -119,15 +119,15 @@ public:
elements[1][2]=yz;
elements[2][0]=zx;
elements[2][1]=zy;
- elements[2][2]=zz;
+ elements[2][2]=zz;
}
_FORCE_INLINE_ Vector3 get_column(int i) const {
-
+
return Vector3(elements[0][i],elements[1][i],elements[2][i]);
}
-
+
_FORCE_INLINE_ Vector3 get_row(int i) const {
-
+
return Vector3(elements[i][0],elements[i][1],elements[i][2]);
}
_FORCE_INLINE_ void set_row(int i, const Vector3& p_row) {
@@ -155,8 +155,8 @@ public:
elements[0].z * m[0].y + elements[1].z * m[1].y + elements[2].z * m[2].y,
elements[0].z * m[0].z + elements[1].z * m[1].z + elements[2].z * m[2].z);
}
- Matrix3(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz) {
-
+ Matrix3(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz) {
+
set(xx, xy, xz, yx, yy, yz, zx, zy, zz);
}
@@ -170,7 +170,7 @@ public:
Matrix3(const Vector3& p_axis, real_t p_phi);
_FORCE_INLINE_ Matrix3() {
-
+
elements[0][0]=1;
elements[0][1]=0;
elements[0][2]=0;
@@ -191,7 +191,7 @@ _FORCE_INLINE_ void Matrix3::operator*=(const Matrix3& p_matrix) {
p_matrix.tdotx(elements[0]), p_matrix.tdoty(elements[0]), p_matrix.tdotz(elements[0]),
p_matrix.tdotx(elements[1]), p_matrix.tdoty(elements[1]), p_matrix.tdotz(elements[1]),
p_matrix.tdotx(elements[2]), p_matrix.tdoty(elements[2]), p_matrix.tdotz(elements[2]));
-
+
}
_FORCE_INLINE_ Matrix3 Matrix3::operator*(const Matrix3& p_matrix) const {
diff --git a/core/math/octree.h b/core/math/octree.h
index 69edf80e09..6080b21680 100644
--- a/core/math/octree.h
+++ b/core/math/octree.h
@@ -52,11 +52,11 @@ public:
typedef void* (*PairCallback)(void*,OctreeElementID, T*,int,OctreeElementID, T*,int);
typedef void (*UnpairCallback)(void*,OctreeElementID, T*,int,OctreeElementID, T*,int,void*);
-private:
+private:
enum {
-
+
NEG=0,
- POS=1,
+ POS=1,
};
enum {
@@ -72,7 +72,7 @@ private:
struct PairKey {
-
+
union {
struct {
OctreeElementID A;
@@ -80,66 +80,66 @@ private:
};
uint64_t key;
};
-
+
_FORCE_INLINE_ bool operator<(const PairKey& p_pair) const {
-
+
return key<p_pair.key;
}
-
+
_FORCE_INLINE_ PairKey( OctreeElementID p_A, OctreeElementID p_B) {
-
+
if (p_A<p_B) {
-
+
A=p_A;
- B=p_B;
+ B=p_B;
} else {
-
+
B=p_A;
A=p_B;
}
}
-
+
_FORCE_INLINE_ PairKey() {}
- };
-
+ };
+
struct Element;
-
+
struct Octant {
-
+
// cached for FAST plane check
AABB aabb;
-
+
uint64_t last_pass;
Octant *parent;
Octant *children[8];
-
+
int children_count; // cache for amount of childrens (fast check for removal)
int parent_index; // cache for parent index (fast check for removal)
-
+
List<Element*,AL> pairable_elements;
List<Element*,AL> elements;
-
+
Octant() {
children_count=0;
parent_index=-1;
last_pass=0;
parent=NULL;
for (int i=0;i<8;i++)
- children[i]=NULL;
+ children[i]=NULL;
}
-
+
~Octant() {
-
+
//for (int i=0;i<8;i++)
// memdelete_notnull(children[i]);
}
};
-
+
struct PairData;
struct Element {
-
+
Octree *octree;
T *userdata;
@@ -147,28 +147,28 @@ private:
bool pairable;
uint32_t pairable_mask;
uint32_t pairable_type;
-
+
uint64_t last_pass;
OctreeElementID _id;
Octant *common_parent;
-
+
AABB aabb;
AABB container_aabb;
List<PairData*,AL> pair_list;
-
+
struct OctantOwner {
-
+
Octant *octant;
typename List<Element*,AL>::Element *E;
- }; // an element can be in max 8 octants
-
+ }; // an element can be in max 8 octants
+
List<OctantOwner,AL> octant_owners;
-
-
+
+
Element() { last_pass=0; _id=0; pairable=false; subindex=0; userdata=0; octree=0; pairable_mask=0; pairable_type=0; common_parent=NULL; }
};
-
+
struct PairData {
@@ -181,15 +181,15 @@ private:
typedef Map<OctreeElementID, Element, Comparator<OctreeElementID>, AL> ElementMap;
typedef Map<PairKey, PairData, Comparator<PairKey>, AL> PairMap;
- ElementMap element_map;
- PairMap pair_map;
+ ElementMap element_map;
+ PairMap pair_map;
PairCallback pair_callback;
UnpairCallback unpair_callback;
void *pair_callback_userdata;
void *unpair_callback_userdata;
-
- OctreeElementID last_element_id;
+
+ OctreeElementID last_element_id;
uint64_t pass;
real_t unit_size;
@@ -231,7 +231,7 @@ private:
if (p_A==p_B || (p_A->userdata==p_B->userdata && p_A->userdata))
return;
-
+
if ( !(p_A->pairable_type&p_B->pairable_mask) &&
!(p_B->pairable_type&p_A->pairable_mask) )
return; // none can pair with none
@@ -253,17 +253,17 @@ private:
// if (pair_callback)
// pair_callback(pair_callback_userdata,p_A->userdata,p_B->userdata);
} else {
-
+
E->get().refcount++;
}
-
+
}
-
+
_FORCE_INLINE_ void _pair_unreference(Element* p_A,Element* p_B) {
-
+
if (p_A==p_B)
return;
-
+
PairKey key(p_A->_id, p_B->_id);
typename PairMap::Element *E=pair_map.find(key);
if (!E) {
@@ -293,7 +293,7 @@ private:
p_B->pair_list.erase( E->get().eB );
pair_map.erase(E);
}
-
+
}
_FORCE_INLINE_ void _element_check_pairs(Element *p_element) {
@@ -341,7 +341,7 @@ private:
void _ensure_valid_root(const AABB& p_aabb);
bool _remove_element_from_octant(Element *p_element,Octant *p_octant,Octant *p_limit=NULL);
void _remove_element(Element *p_element);
- void _pair_element(Element *p_element,Octant *p_octant);
+ void _pair_element(Element *p_element,Octant *p_octant);
void _unpair_element(Element *p_element,Octant *p_octant);
@@ -361,16 +361,16 @@ private:
void _cull_point(Octant *p_octant,const Vector3& p_point,T** p_result_array,int *p_result_idx,int p_result_max,int *p_subindex_array,uint32_t p_mask);
void _remove_tree(Octant *p_octant) {
-
+
if (!p_octant)
return;
for(int i=0;i<8;i++) {
-
+
if (p_octant->children[i])
_remove_tree(p_octant->children[i]);
}
-
+
memdelete_allocator<Octant,AL>(p_octant);
}
public:
@@ -432,24 +432,24 @@ template<class T,bool use_pairs,class AL>
void Octree<T,use_pairs,AL>::_insert_element(Element *p_element,Octant *p_octant) {
float element_size = p_element->aabb.get_longest_axis_size() * 1.01; // avoid precision issues
-
+
if (p_octant->aabb.size.x/OCTREE_DIVISOR < element_size) {
- //if (p_octant->aabb.size.x*0.5 < element_size) {
-
- /* at smallest possible size for the element */
+ //if (p_octant->aabb.size.x*0.5 < element_size) {
+
+ /* at smallest possible size for the element */
typename Element::OctantOwner owner;
owner.octant=p_octant;
-
+
if (use_pairs && p_element->pairable) {
-
+
p_octant->pairable_elements.push_back(p_element);
owner.E = p_octant->pairable_elements.back();
} else {
-
+
p_octant->elements.push_back(p_element);
owner.E = p_octant->elements.back();
}
-
+
p_element->octant_owners.push_back( owner );
if (p_element->common_parent==NULL) {
@@ -461,13 +461,13 @@ void Octree<T,use_pairs,AL>::_insert_element(Element *p_element,Octant *p_octant
if (use_pairs && p_octant->children_count>0) {
-
+
pass++; //elements below this only get ONE reference added
for (int i=0;i<8;i++) {
-
+
if (p_octant->children[i]) {
- _pair_element(p_element,p_octant->children[i]);
+ _pair_element(p_element,p_octant->children[i]);
}
}
}
@@ -477,7 +477,7 @@ void Octree<T,use_pairs,AL>::_insert_element(Element *p_element,Octant *p_octant
bool candidate=p_element->common_parent==NULL;
for (int i=0;i<8;i++) {
-
+
if (p_octant->children[i]) {
/* element exists, go straight to it */
if (p_octant->children[i]->aabb.intersects_inclusive( p_element->aabb ) ) {
@@ -486,20 +486,20 @@ void Octree<T,use_pairs,AL>::_insert_element(Element *p_element,Octant *p_octant
}
} else {
/* check againt AABB where child should be */
-
+
AABB aabb=p_octant->aabb;
aabb.size*=0.5;
-
+
if (i&1)
aabb.pos.x+=aabb.size.x;
if (i&2)
aabb.pos.y+=aabb.size.y;
if (i&4)
aabb.pos.z+=aabb.size.z;
-
+
if (aabb.intersects_inclusive( p_element->aabb) ) {
/* if actually intersects, create the child */
-
+
Octant *child = memnew_allocator( Octant, AL );
p_octant->children[i]=child;
child->parent=p_octant;
@@ -517,14 +517,14 @@ void Octree<T,use_pairs,AL>::_insert_element(Element *p_element,Octant *p_octant
}
}
-
+
if (candidate && splits>1) {
p_element->common_parent=p_octant;
}
-
+
}
-
+
if (use_pairs) {
typename List<Element*,AL>::Element *E=p_octant->pairable_elements.front();
@@ -532,8 +532,8 @@ void Octree<T,use_pairs,AL>::_insert_element(Element *p_element,Octant *p_octant
while(E) {
_pair_reference( p_element,E->get() );
E=E->next();
- }
-
+ }
+
if (p_element->pairable) {
// and always test non-pairable if element is pairable
E=p_octant->elements.front();
@@ -541,9 +541,9 @@ void Octree<T,use_pairs,AL>::_insert_element(Element *p_element,Octant *p_octant
_pair_reference( p_element,E->get() );
E=E->next();
}
- }
+ }
}
-
+
}
@@ -553,35 +553,35 @@ void Octree<T,use_pairs,AL>::_ensure_valid_root(const AABB& p_aabb) {
if (!root) {
// octre is empty
-
+
AABB base( Vector3(), Vector3(1.0,1.0,1.0) * unit_size);
-
+
while ( !base.encloses(p_aabb) ) {
-
+
if ( ABS(base.pos.x+base.size.x) <= ABS(base.pos.x) ) {
/* grow towards positive */
base.size*=2.0;
} else {
- base.pos-=base.size;
+ base.pos-=base.size;
base.size*=2.0;
}
}
-
+
root = memnew_allocator( Octant, AL );
- root->parent=NULL;
- root->parent_index=-1;
+ root->parent=NULL;
+ root->parent_index=-1;
root->aabb=base;
-
+
octant_count++;
-
-
- } else {
-
+
+
+ } else {
+
AABB base=root->aabb;
-
+
while( !base.encloses( p_aabb ) ) {
-
+
if (base.size.x > OCTREE_SIZE_LIMIT) {
ERR_EXPLAIN("Octree upper size limit reeached, does the AABB supplied contain NAN?");
ERR_FAIL();
@@ -590,7 +590,7 @@ void Octree<T,use_pairs,AL>::_ensure_valid_root(const AABB& p_aabb) {
Octant * gp = memnew_allocator( Octant, AL );
octant_count++;
root->parent=gp;
-
+
if ( ABS(base.pos.x+base.size.x) <= ABS(base.pos.x) ) {
/* grow towards positive */
base.size*=2.0;
@@ -598,16 +598,16 @@ void Octree<T,use_pairs,AL>::_ensure_valid_root(const AABB& p_aabb) {
gp->children[0]=root;
root->parent_index=0;
} else {
- base.pos-=base.size;
+ base.pos-=base.size;
base.size*=2.0;
gp->aabb=base;
gp->children[(1<<0)|(1<<1)|(1<<2)]=root; // add at all-positive
root->parent_index=(1<<0)|(1<<1)|(1<<2);
}
-
+
gp->children_count=1;
- root=gp;
- }
+ root=gp;
+ }
}
}
@@ -615,16 +615,16 @@ template<class T,bool use_pairs,class AL>
bool Octree<T,use_pairs,AL>::_remove_element_from_octant(Element *p_element,Octant *p_octant,Octant *p_limit) {
bool octant_removed=false;
-
+
while(true) {
-
+
// check all exit conditions
-
+
if (p_octant==p_limit) // reached limit, nothing to erase, exit
return octant_removed;
-
+
bool unpaired=false;
-
+
if (use_pairs && p_octant->last_pass!=pass) {
// check wether we should unpair stuff
// always test pairable
@@ -644,21 +644,21 @@ bool Octree<T,use_pairs,AL>::_remove_element_from_octant(Element *p_element,Octa
p_octant->last_pass=pass;
unpaired=true;
}
-
+
bool removed=false;
-
+
Octant *parent=p_octant->parent;
-
+
if (p_octant->children_count==0 && p_octant->elements.empty() && p_octant->pairable_elements.empty()) {
-
+
// erase octant
-
+
if (p_octant==root) { // won't have a parent, just erase
-
+
root=NULL;
} else {
ERR_FAIL_INDEX_V(p_octant->parent_index,8,octant_removed);
-
+
parent->children[ p_octant->parent_index ]=NULL;
parent->children_count--;
}
@@ -668,12 +668,12 @@ bool Octree<T,use_pairs,AL>::_remove_element_from_octant(Element *p_element,Octa
removed=true;
octant_removed=true;
}
-
+
if (!removed && !unpaired)
return octant_removed; // no reason to keep going up anymore! was already visited and was not removed
-
+
p_octant=parent;
-
+
}
return octant_removed;
@@ -682,8 +682,8 @@ bool Octree<T,use_pairs,AL>::_remove_element_from_octant(Element *p_element,Octa
template<class T,bool use_pairs,class AL>
void Octree<T,use_pairs,AL>::_unpair_element(Element *p_element,Octant *p_octant) {
-
- // always test pairable
+
+ // always test pairable
typename List<Element*,AL>::Element *E=p_octant->pairable_elements.front();
while(E) {
if (E->get()->last_pass!=pass) { // only remove ONE reference
@@ -692,7 +692,7 @@ void Octree<T,use_pairs,AL>::_unpair_element(Element *p_element,Octant *p_octant
}
E=E->next();
}
-
+
if (p_element->pairable) {
// and always test non-pairable if element is pairable
E=p_octant->elements.front();
@@ -704,14 +704,14 @@ void Octree<T,use_pairs,AL>::_unpair_element(Element *p_element,Octant *p_octant
E=E->next();
}
}
-
+
p_octant->last_pass=pass;
-
+
if (p_octant->children_count==0)
return; // small optimization for leafs
-
+
for (int i=0;i<8;i++) {
-
+
if (p_octant->children[i])
_unpair_element(p_element,p_octant->children[i]);
}
@@ -732,7 +732,7 @@ void Octree<T,use_pairs,AL>::_pair_element(Element *p_element,Octant *p_octant)
}
E=E->next();
}
-
+
if (p_element->pairable) {
// and always test non-pairable if element is pairable
E=p_octant->elements.front();
@@ -745,12 +745,12 @@ void Octree<T,use_pairs,AL>::_pair_element(Element *p_element,Octant *p_octant)
}
}
p_octant->last_pass=pass;
-
+
if (p_octant->children_count==0)
return; // small optimization for leafs
-
+
for (int i=0;i<8;i++) {
-
+
if (p_octant->children[i])
_pair_element(p_element,p_octant->children[i]);
}
@@ -760,13 +760,13 @@ template<class T,bool use_pairs,class AL>
void Octree<T,use_pairs,AL>::_remove_element(Element *p_element) {
pass++; // will do a new pass for this
-
+
typename List< typename Element::OctantOwner,AL >::Element *I=p_element->octant_owners.front();
-
+
/* FIRST remove going up normally */
for(;I;I=I->next()) {
-
+
Octant *o=I->get().octant;
if (!use_pairs) // small speedup
@@ -809,14 +809,14 @@ void Octree<T,use_pairs,AL>::_remove_element(Element *p_element) {
int remaining=p_element->pair_list.size();
//p_element->pair_list.clear();
ERR_FAIL_COND( remaining );
- }
+ }
}
template<class T,bool use_pairs,class AL>
OctreeElementID Octree<T,use_pairs,AL>::create(T* p_userdata, const AABB& p_aabb, int p_subindex,bool p_pairable,uint32_t p_pairable_type,uint32_t p_pairable_mask) {
- // check for AABB validity
+ // check for AABB validity
#ifdef DEBUG_ENABLED
ERR_FAIL_COND_V( p_aabb.pos.x > 1e15 || p_aabb.pos.x < -1e15, 0 );
ERR_FAIL_COND_V( p_aabb.pos.y > 1e15 || p_aabb.pos.y < -1e15, 0 );
@@ -828,12 +828,12 @@ OctreeElementID Octree<T,use_pairs,AL>::create(T* p_userdata, const AABB& p_aabb
ERR_FAIL_COND_V( Math::is_nan(p_aabb.size.y) , 0 );
ERR_FAIL_COND_V( Math::is_nan(p_aabb.size.z) , 0 );
-
+
#endif
typename ElementMap::Element *E = element_map.insert(last_element_id++,
Element());
Element &e = E->get();
-
+
e.aabb=p_aabb;
e.userdata=p_userdata;
e.subindex=p_subindex;
@@ -843,7 +843,7 @@ OctreeElementID Octree<T,use_pairs,AL>::create(T* p_userdata, const AABB& p_aabb
e.pairable_type=p_pairable_type;
e.pairable_mask=p_pairable_mask;
e._id=last_element_id-1;
-
+
if (!e.aabb.has_no_surface()) {
_ensure_valid_root(p_aabb);
_insert_element(&e,root);
@@ -964,7 +964,7 @@ void Octree<T,use_pairs,AL>::move(OctreeElementID p_id, const AABB& p_aabb) {
_insert_element(&e,common_parent); // reinsert from this point
pass++;
-
+
for(typename List<typename Element::OctantOwner,AL>::Element *E=owners.front();E;) {
Octant *o=E->get().octant;
@@ -1018,28 +1018,28 @@ void Octree<T,use_pairs,AL>::set_pairable(OctreeElementID p_id,bool p_pairable,u
typename ElementMap::Element *E = element_map.find(p_id);
ERR_FAIL_COND(!E);
-
+
Element &e = E->get();
if (p_pairable == e.pairable && e.pairable_type==p_pairable_type && e.pairable_mask==p_pairable_mask)
return; // no changes, return
-
+
if (!e.aabb.has_no_surface()) {
_remove_element(&e);
}
-
+
e.pairable=p_pairable;
e.pairable_type=p_pairable_type;
e.pairable_mask=p_pairable_mask;
e.common_parent=NULL;
-
+
if (!e.aabb.has_no_surface()) {
_ensure_valid_root(e.aabb);
_insert_element(&e,root);
if (use_pairs)
_element_check_pairs(&e);
- }
+ }
}
@@ -1048,155 +1048,155 @@ void Octree<T,use_pairs,AL>::erase(OctreeElementID p_id) {
typename ElementMap::Element *E = element_map.find(p_id);
ERR_FAIL_COND(!E);
-
+
Element &e = E->get();
if (!e.aabb.has_no_surface()) {
-
- _remove_element(&e);
+
+ _remove_element(&e);
}
-
+
element_map.erase(p_id);
_optimize();
}
template<class T,bool use_pairs,class AL>
void Octree<T,use_pairs,AL>::_cull_convex(Octant *p_octant,_CullConvexData *p_cull) {
-
+
if (*p_cull->result_idx==p_cull->result_max)
return; //pointless
-
+
if (!p_octant->elements.empty()) {
-
+
typename List< Element*,AL >::Element *I;
I=p_octant->elements.front();
-
+
for(;I;I=I->next()) {
-
+
Element *e=I->get();
-
+
if (e->last_pass==pass || (use_pairs && !(e->pairable_type&p_cull->mask)))
continue;
e->last_pass=pass;
-
+
if (e->aabb.intersects_convex_shape(p_cull->planes,p_cull->plane_count)) {
-
+
if (*p_cull->result_idx<p_cull->result_max) {
p_cull->result_array[*p_cull->result_idx] = e->userdata;
(*p_cull->result_idx)++;
} else {
-
+
return; // pointless to continue
}
}
}
}
-
+
if (use_pairs && !p_octant->pairable_elements.empty()) {
-
+
typename List< Element*,AL >::Element *I;
I=p_octant->pairable_elements.front();
-
+
for(;I;I=I->next()) {
-
+
Element *e=I->get();
-
+
if (e->last_pass==pass || (use_pairs && !(e->pairable_type&p_cull->mask)))
continue;
e->last_pass=pass;
-
+
if (e->aabb.intersects_convex_shape(p_cull->planes,p_cull->plane_count)) {
-
+
if (*p_cull->result_idx<p_cull->result_max) {
p_cull->result_array[*p_cull->result_idx] = e->userdata;
(*p_cull->result_idx)++;
} else {
-
+
return; // pointless to continue
}
}
}
}
-
+
for (int i=0;i<8;i++) {
-
+
if (p_octant->children[i] && p_octant->children[i]->aabb.intersects_convex_shape(p_cull->planes,p_cull->plane_count)) {
_cull_convex(p_octant->children[i],p_cull);
}
- }
+ }
}
template<class T,bool use_pairs,class AL>
void Octree<T,use_pairs,AL>::_cull_AABB(Octant *p_octant,const AABB& p_aabb, T** p_result_array,int *p_result_idx,int p_result_max,int *p_subindex_array,uint32_t p_mask) {
-
+
if (*p_result_idx==p_result_max)
return; //pointless
-
+
if (!p_octant->elements.empty()) {
-
+
typename List< Element*,AL >::Element *I;
I=p_octant->elements.front();
for(;I;I=I->next()) {
-
+
Element *e=I->get();
-
+
if (e->last_pass==pass || (use_pairs && !(e->pairable_type&p_mask)))
continue;
e->last_pass=pass;
-
+
if (p_aabb.intersects_inclusive(e->aabb)) {
-
+
if (*p_result_idx<p_result_max) {
-
+
p_result_array[*p_result_idx] = e->userdata;
if (p_subindex_array)
p_subindex_array[*p_result_idx] = e->subindex;
(*p_result_idx)++;
} else {
-
+
return; // pointless to continue
}
}
}
}
-
+
if (use_pairs && !p_octant->pairable_elements.empty()) {
-
+
typename List< Element*,AL >::Element *I;
I=p_octant->pairable_elements.front();
for(;I;I=I->next()) {
-
+
Element *e=I->get();
-
+
if (e->last_pass==pass || (use_pairs && !(e->pairable_type&p_mask)))
continue;
e->last_pass=pass;
-
+
if (p_aabb.intersects_inclusive(e->aabb)) {
-
+
if (*p_result_idx<p_result_max) {
-
+
p_result_array[*p_result_idx] = e->userdata;
if (p_subindex_array)
p_subindex_array[*p_result_idx] = e->subindex;
(*p_result_idx)++;
} else {
-
+
return; // pointless to continue
}
}
}
- }
+ }
for (int i=0;i<8;i++) {
-
+
if (p_octant->children[i] && p_octant->children[i]->aabb.intersects_inclusive(p_aabb)) {
_cull_AABB(p_octant->children[i],p_aabb, p_result_array,p_result_idx,p_result_max,p_subindex_array,p_mask);
}
- }
+ }
}
@@ -1205,53 +1205,53 @@ void Octree<T,use_pairs,AL>::_cull_segment(Octant *p_octant,const Vector3& p_fro
if (*p_result_idx==p_result_max)
return; //pointless
-
+
if (!p_octant->elements.empty()) {
-
+
typename List< Element*,AL >::Element *I;
I=p_octant->elements.front();
for(;I;I=I->next()) {
-
+
Element *e=I->get();
-
+
if (e->last_pass==pass || (use_pairs && !(e->pairable_type&p_mask)))
continue;
e->last_pass=pass;
-
+
if (e->aabb.intersects_segment(p_from,p_to)) {
-
+
if (*p_result_idx<p_result_max) {
-
+
p_result_array[*p_result_idx] = e->userdata;
if (p_subindex_array)
p_subindex_array[*p_result_idx] = e->subindex;
(*p_result_idx)++;
} else {
-
+
return; // pointless to continue
}
}
}
}
-
+
if (use_pairs && !p_octant->pairable_elements.empty()) {
-
+
typename List< Element*,AL >::Element *I;
I=p_octant->pairable_elements.front();
for(;I;I=I->next()) {
-
+
Element *e=I->get();
-
+
if (e->last_pass==pass || (use_pairs && !(e->pairable_type&p_mask)))
continue;
-
+
e->last_pass=pass;
-
+
if (e->aabb.intersects_segment(p_from,p_to)) {
-
+
if (*p_result_idx<p_result_max) {
-
+
p_result_array[*p_result_idx] = e->userdata;
if (p_subindex_array)
p_subindex_array[*p_result_idx] = e->subindex;
@@ -1259,20 +1259,20 @@ void Octree<T,use_pairs,AL>::_cull_segment(Octant *p_octant,const Vector3& p_fro
(*p_result_idx)++;
} else {
-
+
return; // pointless to continue
}
}
}
}
-
+
for (int i=0;i<8;i++) {
-
+
if (p_octant->children[i] && p_octant->children[i]->aabb.intersects_segment(p_from,p_to)) {
_cull_segment(p_octant->children[i],p_from,p_to, p_result_array,p_result_idx,p_result_max,p_subindex_array,p_mask);
}
- }
+ }
}
@@ -1357,7 +1357,7 @@ int Octree<T,use_pairs,AL>::cull_convex(const Vector<Plane>& p_convex,T** p_resu
if (!root)
return 0;
-
+
int result_count=0;
pass++;
_CullConvexData cdata;
@@ -1367,9 +1367,9 @@ int Octree<T,use_pairs,AL>::cull_convex(const Vector<Plane>& p_convex,T** p_resu
cdata.result_max=p_result_max;
cdata.result_idx=&result_count;
cdata.mask=p_mask;
-
+
_cull_convex(root,&cdata);
-
+
return result_count;
}
@@ -1381,11 +1381,11 @@ int Octree<T,use_pairs,AL>::cull_AABB(const AABB& p_aabb,T** p_result_array,int
if (!root)
return 0;
-
+
int result_count=0;
pass++;
_cull_AABB(root,p_aabb,p_result_array,&result_count,p_result_max,p_subindex_array,p_mask);
-
+
return result_count;
}
@@ -1395,11 +1395,11 @@ int Octree<T,use_pairs,AL>::cull_segment(const Vector3& p_from, const Vector3& p
if (!root)
return 0;
-
+
int result_count=0;
pass++;
_cull_segment(root,p_from,p_to,p_result_array,&result_count,p_result_max,p_subindex_array,p_mask);
-
+
return result_count;
}
@@ -1436,7 +1436,7 @@ void Octree<T,use_pairs,AL>::set_unpair_callback( UnpairCallback p_callback, voi
template<class T,bool use_pairs,class AL>
Octree<T,use_pairs,AL>::Octree(real_t p_unit_size) {
-
+
last_element_id=1;
pass=1;
unit_size=p_unit_size;
diff --git a/core/math/plane.cpp b/core/math/plane.cpp
index d17ce01bec..b29350fe3c 100644
--- a/core/math/plane.cpp
+++ b/core/math/plane.cpp
@@ -50,7 +50,7 @@ void Plane::normalize() {
}
Plane Plane::normalized() const {
-
+
Plane p = *this;
p.normalize();
return p;
@@ -66,12 +66,12 @@ Vector3 Plane::get_any_perpendicular_normal() const {
static const Vector3 p1 = Vector3(1,0,0);
static const Vector3 p2 = Vector3(0,1,0);
Vector3 p;
-
+
if (ABS(normal.dot(p1)) > 0.99) // if too similar to p1
p=p2; // use p2
else
p=p1; // use p1
-
+
p-=normal * normal.dot(p);
p.normalize();
diff --git a/core/math/plane.h b/core/math/plane.h
index d20e63dc47..81a968682e 100644
--- a/core/math/plane.h
+++ b/core/math/plane.h
@@ -62,9 +62,9 @@ public:
bool intersects_segment(Vector3 p_begin, Vector3 p_end, Vector3* p_intersection) const;
_FORCE_INLINE_ Vector3 project(const Vector3& p_point) const {
-
+
return p_point - normal * distance_to(p_point);
- }
+ }
/* misc */
diff --git a/core/math/quat.cpp b/core/math/quat.cpp
index ebc5ec4e65..c6c12129b3 100644
--- a/core/math/quat.cpp
+++ b/core/math/quat.cpp
@@ -30,9 +30,9 @@
#include "print_string.h"
void Quat::set_euler(const Vector3& p_euler) {
- real_t half_yaw = p_euler.x * 0.5;
- real_t half_pitch = p_euler.y * 0.5;
- real_t half_roll = p_euler.z * 0.5;
+ real_t half_yaw = p_euler.x * 0.5;
+ real_t half_pitch = p_euler.y * 0.5;
+ real_t half_roll = p_euler.z * 0.5;
real_t cos_yaw = Math::cos(half_yaw);
real_t sin_yaw = Math::sin(half_yaw);
real_t cos_pitch = Math::cos(half_pitch);
@@ -75,7 +75,7 @@ void Quat::normalize() {
Quat Quat::normalized() const {
return *this / length();
-}
+}
Quat Quat::inverse() const {
return Quat( -x, -y, -z, w );
@@ -252,7 +252,7 @@ Quat Quat::cubic_slerp(const Quat& q, const Quat& prep, const Quat& postq,const
Quat::operator String() const {
- return String::num(x)+","+String::num(y)+","+ String::num(z)+","+ String::num(w);
+ return String::num(x)+","+String::num(y)+","+ String::num(z)+","+ String::num(w);
}
Quat::Quat(const Vector3& axis, const real_t& angle) {
@@ -261,7 +261,7 @@ Quat::Quat(const Vector3& axis, const real_t& angle) {
set(0,0,0,0);
else {
real_t s = Math::sin(-angle * 0.5) / d;
- set(axis.x * s, axis.y * s, axis.z * s,
+ set(axis.x * s, axis.y * s, axis.z * s,
Math::cos(-angle * 0.5));
}
}
diff --git a/core/math/quat.h b/core/math/quat.h
index 738b6946c7..0d206bb3b7 100644
--- a/core/math/quat.h
+++ b/core/math/quat.h
@@ -89,18 +89,18 @@ public:
_FORCE_INLINE_ Quat operator-() const;
_FORCE_INLINE_ Quat operator*(const real_t& s) const;
_FORCE_INLINE_ Quat operator/(const real_t& s) const;
-
+
_FORCE_INLINE_ bool operator==(const Quat& p_quat) const;
_FORCE_INLINE_ bool operator!=(const Quat& p_quat) const;
-
+
operator String() const;
-
+
inline void set( real_t p_x, real_t p_y, real_t p_z, real_t p_w) {
- x=p_x; y=p_y; z=p_z; w=p_w;
+ x=p_x; y=p_y; z=p_z; w=p_w;
}
inline Quat(real_t p_x, real_t p_y, real_t p_z, real_t p_w) {
- x=p_x; y=p_y; z=p_z; w=p_w;
+ x=p_x; y=p_y; z=p_z; w=p_w;
}
Quat(const Vector3& axis, const real_t& angle);
@@ -127,7 +127,7 @@ public:
}
inline Quat() {x=y=z=0; w=1; }
-
+
};
@@ -141,7 +141,7 @@ real_t Quat::length_squared() const {
}
void Quat::operator+=(const Quat& q) {
- x += q.x; y += q.y; z += q.z; w += q.w;
+ x += q.x; y += q.y; z += q.z; w += q.w;
}
void Quat::operator-=(const Quat& q) {
diff --git a/core/math/transform.cpp b/core/math/transform.cpp
index 8371f7e34b..22eb6c4fdd 100644
--- a/core/math/transform.cpp
+++ b/core/math/transform.cpp
@@ -30,7 +30,7 @@
#include "math_funcs.h"
#include "os/copymem.h"
#include "print_string.h"
-
+
void Transform::affine_invert() {
@@ -50,7 +50,7 @@ Transform Transform::affine_inverse() const {
void Transform::invert() {
basis.transpose();
- origin = basis.xform(-origin);
+ origin = basis.xform(-origin);
}
Transform Transform::inverse() const {
@@ -87,30 +87,30 @@ void Transform::set_look_at( const Vector3& p_eye, const Vector3& p_target, cons
// Reference: MESA source code
Vector3 v_x, v_y, v_z;
-
+
/* Make rotation matrix */
-
+
/* Z vector */
v_z = p_eye - p_target;
-
+
v_z.normalize();
-
+
v_y = p_up;
-
+
v_x=v_y.cross(v_z);
-
+
/* Recompute Y = Z cross X */
v_y=v_z.cross(v_x);
-
+
v_x.normalize();
v_y.normalize();
-
+
basis.set_axis(0,v_x);
basis.set_axis(1,v_y);
basis.set_axis(2,v_z);
origin=p_eye;
-
+
}
Transform Transform::interpolate_with(const Transform& p_transform, float p_c) const {
@@ -193,7 +193,7 @@ bool Transform::operator!=(const Transform& p_transform) const {
void Transform::operator*=(const Transform& p_transform) {
origin=xform(p_transform.origin);
- basis*=p_transform.basis;
+ basis*=p_transform.basis;
}
Transform Transform::operator*(const Transform& p_transform) const {
diff --git a/core/math/transform.h b/core/math/transform.h
index bd1247084d..f948a4c919 100644
--- a/core/math/transform.h
+++ b/core/math/transform.h
@@ -40,9 +40,9 @@ public:
Matrix3 basis;
Vector3 origin;
-
- void invert();
- Transform inverse() const;
+
+ void invert();
+ Transform inverse() const;
void affine_invert();
Transform affine_inverse() const;
@@ -76,27 +76,27 @@ public:
_FORCE_INLINE_ Vector3 xform(const Vector3& p_vector) const;
_FORCE_INLINE_ Vector3 xform_inv(const Vector3& p_vector) const;
-
+
_FORCE_INLINE_ Plane xform(const Plane& p_plane) const;
_FORCE_INLINE_ Plane xform_inv(const Plane& p_plane) const;
_FORCE_INLINE_ AABB xform(const AABB& p_aabb) const;
_FORCE_INLINE_ AABB xform_inv(const AABB& p_aabb) const;
-
+
void operator*=(const Transform& p_transform);
Transform operator*(const Transform& p_transform) const;
Transform interpolate_with(const Transform& p_transform, float p_c) const;
-
+
_FORCE_INLINE_ Transform inverse_xform(const Transform& t) const {
-
+
Vector3 v = t.origin - origin;
return Transform(basis.transpose_xform(t.basis),
basis.xform(v));
}
-
+
void set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz,real_t tx, real_t ty, real_t tz) {
-
+
basis.elements[0][0]=xx;
basis.elements[0][1]=xy;
basis.elements[0][2]=xz;
@@ -105,14 +105,14 @@ public:
basis.elements[1][2]=yz;
basis.elements[2][0]=zx;
basis.elements[2][1]=zy;
- basis.elements[2][2]=zz;
+ basis.elements[2][2]=zz;
origin.x=tx;
origin.y=ty;
origin.z=tz;
}
-
+
operator String() const;
-
+
Transform(const Matrix3& p_basis, const Vector3& p_origin=Vector3());
Transform() {}
@@ -128,9 +128,9 @@ _FORCE_INLINE_ Vector3 Transform::xform(const Vector3& p_vector) const {
);
}
_FORCE_INLINE_ Vector3 Transform::xform_inv(const Vector3& p_vector) const {
-
+
Vector3 v = p_vector - origin;
-
+
return Vector3(
(basis.elements[0][0]*v.x ) + ( basis.elements[1][0]*v.y ) + ( basis.elements[2][0]*v.z ),
(basis.elements[0][1]*v.x ) + ( basis.elements[1][1]*v.y ) + ( basis.elements[2][1]*v.z ),
@@ -140,16 +140,16 @@ _FORCE_INLINE_ Vector3 Transform::xform_inv(const Vector3& p_vector) const {
_FORCE_INLINE_ Plane Transform::xform(const Plane& p_plane) const {
-
+
Vector3 point=p_plane.normal*p_plane.d;
Vector3 point_dir=point+p_plane.normal;
point=xform(point);
point_dir=xform(point_dir);
-
+
Vector3 normal=point_dir-point;
normal.normalize();
real_t d=normal.dot(point);
-
+
return Plane(normal,d);
}
@@ -159,11 +159,11 @@ _FORCE_INLINE_ Plane Transform::xform_inv(const Plane& p_plane) const {
Vector3 point_dir=point+p_plane.normal;
xform_inv(point);
xform_inv(point_dir);
-
+
Vector3 normal=point_dir-point;
normal.normalize();
real_t d=normal.dot(point);
-
+
return Plane(normal,d);
}
@@ -199,17 +199,17 @@ _FORCE_INLINE_ AABB Transform::xform(const AABB& p_aabb) const {
Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z+p_aabb.size.z),
Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z)
};
-
-
+
+
AABB ret;
-
+
ret.pos=xform(vertices[0]);
-
+
for (int i=1;i<8;i++) {
-
+
ret.expand_to( xform(vertices[i]) );
}
-
+
return ret;
#endif
@@ -227,17 +227,17 @@ _FORCE_INLINE_ AABB Transform::xform_inv(const AABB& p_aabb) const {
Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z+p_aabb.size.z),
Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z)
};
-
-
+
+
AABB ret;
-
+
ret.pos=xform_inv(vertices[0]);
-
+
for (int i=1;i<8;i++) {
-
+
ret.expand_to( xform_inv(vertices[i]) );
}
-
+
return ret;
}
diff --git a/core/method_bind.h b/core/method_bind.h
index da3d7c1062..48848c5848 100644
--- a/core/method_bind.h
+++ b/core/method_bind.h
@@ -58,8 +58,8 @@ template<class T>
struct VariantCaster {
static _FORCE_INLINE_ T cast(const Variant& p_variant) {
-
- return p_variant;
+
+ return p_variant;
}
};
@@ -67,8 +67,8 @@ template<class T>
struct VariantCaster<T&> {
static _FORCE_INLINE_ T cast(const Variant& p_variant) {
-
- return p_variant;
+
+ return p_variant;
}
};
@@ -76,8 +76,8 @@ template<class T>
struct VariantCaster<const T&> {
static _FORCE_INLINE_ T cast(const Variant& p_variant) {
-
- return p_variant;
+
+ return p_variant;
}
};
diff --git a/core/object.cpp b/core/object.cpp
index c92fc35b24..7bdec06c1b 100644
--- a/core/object.cpp
+++ b/core/object.cpp
@@ -255,7 +255,7 @@ Object::Connection::Connection(const Variant& p_variant) {
bool Object::_predelete() {
-
+
_predelete_ok=1;
notification(NOTIFICATION_PREDELETE,true);
if (_predelete_ok) {
@@ -269,16 +269,16 @@ void Object::_postinitialize() {
_type_ptr=_get_type_namev();
_initialize_typev();
notification(NOTIFICATION_POSTINITIALIZE);
-
+
}
void Object::get_valid_parents_static(List<String> *p_parents) {
-
-
+
+
}
void Object::_get_valid_parents_static(List<String> *p_parents) {
-
-
+
+
}
#if 0
//old style set, deprecated
@@ -286,7 +286,7 @@ void Object::_get_valid_parents_static(List<String> *p_parents) {
void Object::set(const String& p_name, const Variant& p_value) {
_setv(p_name,p_value);
-
+
//if (!_use_builtin_script())
// return;
@@ -303,8 +303,8 @@ void Object::set(const String& p_name, const Variant& p_value) {
} else if (script_instance) {
script_instance->set(p_name,p_value);
}
-
-
+
+
}
#endif
@@ -348,7 +348,7 @@ void Object::set(const StringName& p_name, const Variant& p_value, bool *r_valid
*r_valid=true;
return;
} else {
- //something inside the object... :|
+ //something inside the object... :|
bool success = _setv(p_name,p_value);
if (success) {
if (r_valid)
@@ -420,7 +420,7 @@ Variant Object::get(const String& p_name) const {
Variant ret=_getv(p_name);
if (ret.get_type()!=Variant::NIL)
return ret;
-
+
bool success;
ObjectTypeDB::get_property(const_cast<Object*>(this),p_name,ret,success);
if (success) {
@@ -431,11 +431,11 @@ Variant Object::get(const String& p_name) const {
return metadata;
else if (p_name=="script/script")
return script;
-
+
if (script_instance) {
return script_instance->get(p_name);
}
-
+
return Variant();
}
@@ -449,10 +449,10 @@ void Object::get_property_list(List<PropertyInfo> *p_list,bool p_reversed) const
}
_get_property_listv(p_list,p_reversed);
-
+
if (!_use_builtin_script())
return;
-
+
if (!is_type("Script")) // can still be set, but this is for userfriendlyness
p_list->push_back( PropertyInfo( Variant::OBJECT, "script/script", PROPERTY_HINT_RESOURCE_TYPE, "Script",PROPERTY_USAGE_DEFAULT|PROPERTY_USAGE_STORE_IF_NONZERO));
if (!metadata.empty())
@@ -460,15 +460,15 @@ void Object::get_property_list(List<PropertyInfo> *p_list,bool p_reversed) const
if (script_instance && !p_reversed) {
p_list->push_back( PropertyInfo(Variant::NIL,"Script Variables",PROPERTY_HINT_NONE,String(),PROPERTY_USAGE_CATEGORY));
script_instance->get_property_list(p_list);
- }
-
+ }
+
}
void Object::get_method_list(List<MethodInfo> *p_list) const {
ObjectTypeDB::get_method_list(get_type_name(),p_list);
if (script_instance) {
script_instance->get_method_list(p_list);
- }
+ }
}
@@ -898,22 +898,22 @@ Variant Object::call(const StringName& p_method,const Variant** p_args,int p_arg
void Object::notification(int p_notification,bool p_reversed) {
-
+
_notificationv(p_notification,p_reversed);
-
+
if (script_instance) {
script_instance->notification(p_notification);
}
}
void Object::_changed_callback(Object *p_changed,const char *p_prop) {
-
-
+
+
}
void Object::add_change_receptor( Object *p_receptor ) {
-
+
change_receptors.insert(p_receptor);
}
@@ -941,8 +941,8 @@ void Object::set_script(const RefPtr& p_script) {
memdelete(script_instance);
script_instance=NULL;
}
-
- script=p_script;
+
+ script=p_script;
Ref<Script> s(script);
if (!s.is_null() && s->can_instance() ) {
@@ -1760,7 +1760,7 @@ bool Object::is_edited() const {
#endif
Object::Object() {
-
+
_type_ptr=NULL;
_block_signals=false;
_predelete_ok=0;
@@ -1831,12 +1831,12 @@ Object::~Object() {
bool predelete_handler(Object *p_object) {
-
+
return p_object->_predelete();
}
void postinitialize_handler(Object *p_object) {
-
+
p_object->_postinitialize();
}
@@ -1900,8 +1900,8 @@ void ObjectDB::cleanup() {
GLOBAL_LOCK_FUNCTION;
if (instances.size()) {
-
- WARN_PRINT("ObjectDB Instances still exist!");
+
+ WARN_PRINT("ObjectDB Instances still exist!");
if (OS::get_singleton()->is_stdout_verbose()) {
const uint32_t *K=NULL;
while((K=instances.next(K))) {
diff --git a/core/object_type_db.cpp b/core/object_type_db.cpp
index dd9304f1f9..14b595d61b 100644
--- a/core/object_type_db.cpp
+++ b/core/object_type_db.cpp
@@ -200,37 +200,37 @@ ObjectTypeDB::TypeInfo::TypeInfo() {
disabled=false;
}
ObjectTypeDB::TypeInfo::~TypeInfo() {
-
-
+
+
}
bool ObjectTypeDB::is_type(const StringName &p_type,const StringName& p_inherits) {
-
+
OBJTYPE_LOCK;
-
+
StringName inherits=p_type;
-
+
while (inherits.operator String().length()) {
-
+
if (inherits==p_inherits)
return true;
inherits=type_inherits_from(inherits);
}
-
+
return false;
}
void ObjectTypeDB::get_type_list( List<StringName> *p_types) {
-
+
OBJTYPE_LOCK;
-
+
const StringName *k=NULL;
-
+
while((k=types.next(k))) {
-
+
p_types->push_back(*k);
}
-
+
p_types->sort();
}
@@ -238,11 +238,11 @@ void ObjectTypeDB::get_type_list( List<StringName> *p_types) {
void ObjectTypeDB::get_inheriters_from( const StringName& p_type,List<StringName> *p_types) {
OBJTYPE_LOCK;
-
+
const StringName *k=NULL;
-
+
while((k=types.next(k))) {
-
+
if (*k!=p_type && is_type(*k,p_type))
p_types->push_back(*k);
}
@@ -250,18 +250,18 @@ void ObjectTypeDB::get_inheriters_from( const StringName& p_type,List<StringName
}
StringName ObjectTypeDB::type_inherits_from(const StringName& p_type) {
-
+
OBJTYPE_LOCK;
-
+
TypeInfo *ti = types.getptr(p_type);
ERR_FAIL_COND_V(!ti,"");
return ti->inherits;
}
bool ObjectTypeDB::type_exists(const StringName &p_type) {
-
+
OBJTYPE_LOCK;
- return types.has(p_type);
+ return types.has(p_type);
}
void ObjectTypeDB::add_compatibility_type(const StringName& p_type,const StringName& p_fallback) {
@@ -270,7 +270,7 @@ void ObjectTypeDB::add_compatibility_type(const StringName& p_type,const StringN
}
Object *ObjectTypeDB::instance(const StringName &p_type) {
-
+
TypeInfo *ti;
{
OBJTYPE_LOCK;
@@ -288,9 +288,9 @@ Object *ObjectTypeDB::instance(const StringName &p_type) {
return ti->creation_func();
}
bool ObjectTypeDB::can_instance(const StringName &p_type) {
-
+
OBJTYPE_LOCK;
-
+
TypeInfo *ti = types.getptr(p_type);
ERR_FAIL_COND_V(!ti,false);
return (!ti->disabled && ti->creation_func!=NULL);
@@ -326,11 +326,11 @@ void ObjectTypeDB::get_method_list(StringName p_type,List<MethodInfo> *p_methods
OBJTYPE_LOCK;
-
+
TypeInfo *type=types.getptr(p_type);
-
+
while(type) {
-
+
if (type->disabled) {
if (p_no_inheritance)
@@ -348,14 +348,14 @@ void ObjectTypeDB::get_method_list(StringName p_type,List<MethodInfo> *p_methods
}
for( List<StringName>::Element *E=type->method_order.front();E;E=E->next()) {
-
+
MethodBind *method=type->method_map.get(E->get());
MethodInfo minfo;
minfo.name=E->get();
minfo.id=method->get_method_id();
for (int i=0;i<method->get_argument_count();i++) {
-
+
//Variant::Type t=method->get_argument_type(i);
minfo.arguments.push_back(method->get_argument_info(i));
@@ -386,24 +386,24 @@ void ObjectTypeDB::get_method_list(StringName p_type,List<MethodInfo> *p_methods
#endif
-
+
if (p_no_inheritance)
break;
-
+
type=type->inherits_ptr;
}
-
+
}
MethodBind *ObjectTypeDB::get_method(StringName p_type, StringName p_name) {
OBJTYPE_LOCK;
-
+
TypeInfo *type=types.getptr(p_type);
-
+
while(type) {
-
+
MethodBind **method=type->method_map.getptr(p_name);
if (method && *method)
return *method;
@@ -416,18 +416,18 @@ MethodBind *ObjectTypeDB::get_method(StringName p_type, StringName p_name) {
void ObjectTypeDB::bind_integer_constant(const StringName& p_type, const StringName &p_name, int p_constant) {
OBJTYPE_LOCK;
-
+
TypeInfo *type=types.getptr(p_type);
if (!type) {
ERR_FAIL_COND(!type);
}
-
+
if (type->constant_map.has(p_name)) {
ERR_FAIL();
}
-
+
type->constant_map[p_name]=p_constant;
#ifdef DEBUG_METHODS_ENABLED
type->constant_order.push_back(p_name);
@@ -438,11 +438,11 @@ void ObjectTypeDB::bind_integer_constant(const StringName& p_type, const StringN
void ObjectTypeDB::get_integer_constant_list(const StringName& p_type, List<String> *p_constants, bool p_no_inheritance) {
OBJTYPE_LOCK;
-
+
TypeInfo *type=types.getptr(p_type);
-
+
while(type) {
-
+
#ifdef DEBUG_METHODS_ENABLED
for(List<StringName>::Element *E=type->constant_order.front();E;E=E->next())
p_constants->push_back(E->get());
@@ -456,7 +456,7 @@ void ObjectTypeDB::get_integer_constant_list(const StringName& p_type, List<Stri
#endif
if (p_no_inheritance)
break;
-
+
type=type->inherits_ptr;
}
@@ -466,28 +466,28 @@ void ObjectTypeDB::get_integer_constant_list(const StringName& p_type, List<Stri
int ObjectTypeDB::get_integer_constant(const StringName& p_type, const StringName &p_name, bool *p_success) {
OBJTYPE_LOCK;
-
-
+
+
TypeInfo *type=types.getptr(p_type);
-
+
while(type) {
-
+
int *constant=type->constant_map.getptr(p_name);
if (constant) {
-
+
if (p_success)
*p_success=true;
return *constant;
}
-
+
type=type->inherits_ptr;
}
-
+
if (p_success)
- *p_success=false;
+ *p_success=false;
- return 0;
+ return 0;
}
void ObjectTypeDB::add_signal(StringName p_type,const MethodInfo& p_signal) {
@@ -966,7 +966,7 @@ void ObjectTypeDB::init() {
}
void ObjectTypeDB::cleanup() {
-
+
#ifndef NO_THREADS
@@ -974,19 +974,19 @@ void ObjectTypeDB::cleanup() {
#endif
//OBJTYPE_LOCK; hah not here
-
+
const StringName *k=NULL;
-
+
while((k=types.next(k))) {
-
+
TypeInfo &ti=types[*k];
-
+
const StringName *m=NULL;
while((m=ti.method_map.next(m))) {
-
+
memdelete( ti.method_map[*m] );
}
- }
+ }
types.clear();
resource_base_extensions.clear();
compat_types.clear();
diff --git a/core/object_type_db.h b/core/object_type_db.h
index f6caf14be5..a4896fff81 100644
--- a/core/object_type_db.h
+++ b/core/object_type_db.h
@@ -42,9 +42,9 @@ struct ParamHint {
PropertyHint hint;
String hint_text;
Variant default_val;
-
+
ParamHint(const String& p_name="", PropertyHint p_hint=PROPERTY_HINT_NONE, const String& p_hint_text="",Variant p_default_val=Variant()) {
-
+
name=p_name;
hint=p_hint;
hint_text=p_hint_text;
@@ -73,9 +73,9 @@ struct MethodDefinition {
StringName name;
Vector<StringName> args;
- MethodDefinition() {}
+ MethodDefinition() {}
MethodDefinition(const char *p_name) { name=p_name; }
- MethodDefinition(const StringName& p_name) { name=p_name; }
+ MethodDefinition(const StringName& p_name) { name=p_name; }
};
@@ -109,7 +109,7 @@ static _FORCE_INLINE_ const char* _MD(const char* m_name, ...) { return m_name;
#endif
class ObjectTypeDB {
-
+
struct PropertySetGet {
int index;
@@ -121,7 +121,7 @@ class ObjectTypeDB {
};
struct TypeInfo {
-
+
TypeInfo *inherits_ptr;
HashMap<StringName,MethodBind*,StringNameHasher> method_map;
HashMap<StringName,int,StringNameHasher> constant_map;
@@ -143,12 +143,12 @@ class ObjectTypeDB {
TypeInfo();
~TypeInfo();
};
-
+
template<class T>
static Object *creator() {
return memnew( T );
}
-
+
static Mutex *lock;
static HashMap<StringName,TypeInfo,StringNameHasher> types;
static HashMap<StringName,StringName,StringNameHasher> resource_base_extensions;
@@ -163,8 +163,8 @@ class ObjectTypeDB {
static void _add_type2(const StringName& p_type, 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_type() {
@@ -195,7 +195,7 @@ public:
template<class T>
static void register_type() {
-
+
GLOBAL_LOCK_FUNCTION;
T::initialize_type();
TypeInfo *t=types.getptr(T::get_type_static());
@@ -206,7 +206,7 @@ public:
template<class T>
static void register_virtual_type() {
-
+
GLOBAL_LOCK_FUNCTION;
T::initialize_type();
//nothing
@@ -247,9 +247,9 @@ public:
ParamDef d4=ParamDef(),
ParamDef d5=ParamDef()
) {
-
+
return bind_methodf(METHOD_FLAGS_DEFAULT,p_method_name, p_method, d1,d2,d3,d4,d5);
- }
+ }
@@ -472,7 +472,7 @@ public:
static void add_virtual_method(const StringName& p_type,const MethodInfo& p_method,bool p_virtual=true );
static void get_virtual_methods(const StringName& p_type,List<MethodInfo> * p_methods,bool p_no_inheritance=false );
-
+
static void bind_integer_constant(const StringName& p_type, const StringName &p_name, int p_constant);
static void get_integer_constant_list(const StringName& p_type, List<String> *p_constants, bool p_no_inheritance=false);
static int get_integer_constant(const StringName& p_type, const StringName &p_name, bool *p_success=NULL);
diff --git a/core/os/copymem.cpp b/core/os/copymem.cpp
index 234ca50b45..49f53f1a51 100644
--- a/core/os/copymem.cpp
+++ b/core/os/copymem.cpp
@@ -32,7 +32,7 @@
void movemem_system(void *to, void *from,int amount) {
- memmove(to,from,amount);
+ memmove(to,from,amount);
}
diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp
index 32d66a7408..9a7135913a 100644
--- a/core/os/dir_access.cpp
+++ b/core/os/dir_access.cpp
@@ -344,7 +344,7 @@ DirAccess *DirAccess::open(const String& p_path,Error *r_error) {
}
DirAccess *DirAccess::create(AccessType p_access) {
-
+
DirAccess * da = create_func[p_access]?create_func[p_access]():NULL;
if (da) {
da->_access_type=p_access;
@@ -359,7 +359,7 @@ String DirAccess::get_full_path(const String& p_path,AccessType p_access) {
DirAccess *d=DirAccess::create(p_access);
if (!d)
return p_path;
-
+
d->change_dir(p_path);
String full=d->get_current_dir();
memdelete(d);
@@ -367,31 +367,31 @@ String DirAccess::get_full_path(const String& p_path,AccessType p_access) {
}
Error DirAccess::copy(String p_from,String p_to) {
-
+
//printf("copy %s -> %s\n",p_from.ascii().get_data(),p_to.ascii().get_data());
Error err;
FileAccess *fsrc = FileAccess::open(p_from, FileAccess::READ,&err);
-
+
if (err) {
ERR_FAIL_COND_V( err, err );
}
-
+
FileAccess *fdst = FileAccess::open(p_to, FileAccess::WRITE,&err );
if (err) {
-
+
fsrc->close();
memdelete( fsrc );
ERR_FAIL_COND_V( err, err );
}
-
+
fsrc->seek_end(0);
int size = fsrc->get_pos();
fsrc->seek(0);
err = OK;
while(size--) {
-
+
if (fsrc->get_error()!=OK) {
err= fsrc->get_error();
break;
@@ -400,13 +400,13 @@ Error DirAccess::copy(String p_from,String p_to) {
err= fdst->get_error();
break;
}
-
+
fdst->store_8( fsrc->get_8() );
}
-
+
memdelete(fsrc);
memdelete(fdst);
-
+
return err;
}
diff --git a/core/os/dir_access.h b/core/os/dir_access.h
index e97a065998..7a850ddc6d 100644
--- a/core/os/dir_access.h
+++ b/core/os/dir_access.h
@@ -79,13 +79,13 @@ public:
virtual String get_next()=0;
virtual bool current_is_dir() const=0;
virtual bool current_is_hidden() const=0;
-
- virtual void list_dir_end()=0; ///<
-
+
+ virtual void list_dir_end()=0; ///<
+
virtual int get_drive_count()=0;
virtual String get_drive(int p_drive)=0;
virtual int get_current_drive();
-
+
virtual Error change_dir(String p_dir)=0; ///< can be relative or absolute, return false on success
virtual String get_current_dir()=0; ///< return current dir location
virtual Error make_dir(String p_dir)=0;
@@ -100,7 +100,7 @@ public:
virtual Error copy(String p_from,String p_to);
virtual Error rename(String p_from, String p_to)=0;
virtual Error remove(String p_name)=0;
-
+
static String get_full_path(const String& p_path,AccessType p_access);
static DirAccess *create_for_path(const String& p_path);
@@ -111,7 +111,7 @@ public:
FILE_TYPE_FILE,
FILE_TYPE_DIR,
};
-
+
//virtual DirType get_file_type() const=0;
*/
static DirAccess *create(AccessType p_access);
diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp
index 68c9dee84d..0846ef3eb0 100644
--- a/core/os/file_access.cpp
+++ b/core/os/file_access.cpp
@@ -169,69 +169,69 @@ String FileAccess::fix_path(const String& p_path) const {
return r_path;
} break;
}
-
+
return r_path;
}
/* these are all implemented for ease of porting, then can later be optimized */
uint16_t FileAccess::get_16()const {
-
+
uint16_t res;
uint8_t a,b;
-
+
a=get_8();
b=get_8();
-
+
if (endian_swap) {
-
+
SWAP( a,b );
}
-
+
res=b;
res<<=8;
res|=a;
-
+
return res;
}
uint32_t FileAccess::get_32() const{
-
+
uint32_t res;
uint16_t a,b;
-
+
a=get_16();
b=get_16();
-
+
if (endian_swap) {
-
+
SWAP( a,b );
}
-
+
res=b;
res<<=16;
res|=a;
-
- return res;
+
+ return res;
}
uint64_t FileAccess::get_64()const {
-
+
uint64_t res;
uint32_t a,b;
-
+
a=get_32();
b=get_32();
-
+
if (endian_swap) {
-
+
SWAP( a,b );
}
-
+
res=b;
res<<=32;
res|=a;
-
- return res;
-
+
+ return res;
+
}
float FileAccess::get_float() const {
@@ -262,15 +262,15 @@ String FileAccess::get_line() const {
CharString line;
CharType c=get_8();
-
+
while(!eof_reached()) {
-
+
if (c=='\n' || c=='\0') {
line.push_back(0);
return String::utf8(line.get_data());
} else if (c!='\r')
line.push_back(c);
-
+
c=get_8();
}
line.push_back(0);
@@ -331,7 +331,7 @@ Vector<String> FileAccess::get_csv_line(String delim) const {
int FileAccess::get_buffer(uint8_t *p_dst,int p_length) const{
-
+
int i=0;
for (i=0; i<p_length && !eof_reached(); i++)
p_dst[i]=get_8();
@@ -340,53 +340,53 @@ int FileAccess::get_buffer(uint8_t *p_dst,int p_length) const{
}
void FileAccess::store_16(uint16_t p_dest) {
-
+
uint8_t a,b;
-
+
a=p_dest&0xFF;
b=p_dest>>8;
-
+
if (endian_swap) {
-
+
SWAP( a,b );
}
-
+
store_8(a);
store_8(b);
}
void FileAccess::store_32(uint32_t p_dest) {
-
-
+
+
uint16_t a,b;
-
+
a=p_dest&0xFFFF;
b=p_dest>>16;
-
+
if (endian_swap) {
-
+
SWAP( a,b );
}
-
+
store_16(a);
store_16(b);
-
+
}
void FileAccess::store_64(uint64_t p_dest) {
-
+
uint32_t a,b;
-
+
a=p_dest&0xFFFFFFFF;
b=p_dest>>32;
-
+
if (endian_swap) {
-
+
SWAP( a,b );
}
-
+
store_32(a);
store_32(b);
-
+
}
void FileAccess::store_real(real_t p_real) {
@@ -461,7 +461,7 @@ void FileAccess::store_line(const String& p_line) {
}
void FileAccess::store_buffer(const uint8_t *p_src,int p_length) {
-
+
for (int i=0;i<p_length;i++)
store_8(p_src[i]);
}
diff --git a/core/os/file_access.h b/core/os/file_access.h
index 3249e21ffb..2c894c94eb 100644
--- a/core/os/file_access.h
+++ b/core/os/file_access.h
@@ -80,21 +80,21 @@ public:
READ_WRITE=3,
WRITE_READ=7,
};
-
- virtual void close()=0; ///< close a file
- virtual bool is_open() const=0; ///< true when file is open
- virtual void seek(size_t p_position)=0; ///< seek to a given position
- virtual void seek_end(int64_t p_position=0)=0; ///< seek from the end of file
- virtual size_t get_pos() const=0; ///< get position in the file
- virtual size_t get_len() const=0; ///< get size of the file
+ virtual void close()=0; ///< close a file
+ virtual bool is_open() const=0; ///< true when file is open
- virtual bool eof_reached() const=0; ///< reading passed EOF
+ virtual void seek(size_t p_position)=0; ///< seek to a given position
+ virtual void seek_end(int64_t p_position=0)=0; ///< seek from the end of file
+ virtual size_t get_pos() const=0; ///< get position in the file
+ virtual size_t get_len() const=0; ///< get size of the file
- virtual uint8_t get_8() const=0; ///< get a byte
- virtual uint16_t get_16() const; ///< get 16 bits uint
- virtual uint32_t get_32() const; ///< get 32 bits uint
- virtual uint64_t get_64() const; ///< get 64 bits uint
+ virtual bool eof_reached() const=0; ///< reading passed EOF
+
+ virtual uint8_t get_8() const=0; ///< get a byte
+ virtual uint16_t get_16() const; ///< get 16 bits uint
+ virtual uint32_t get_32() const; ///< get 32 bits uint
+ virtual uint64_t get_64() const; ///< get 64 bits uint
virtual float get_float() const;
virtual double get_double() const;
@@ -103,21 +103,21 @@ public:
virtual int get_buffer(uint8_t *p_dst,int p_length) const; ///< get an array of bytes
virtual String get_line() const;
virtual Vector<String> get_csv_line(String delim=",") const;
-
+
/**< use this for files WRITTEN in _big_ endian machines (ie, amiga/mac)
* It's not about the current CPU type but file formats.
* this flags get reset to false (little endian) on each open
*/
-
+
virtual void set_endian_swap(bool p_swap) { endian_swap=p_swap; }
inline bool get_endian_swap() const { return endian_swap; }
- virtual Error get_error() const=0; ///< get last error
+ virtual Error get_error() const=0; ///< get last error
- virtual void store_8(uint8_t p_dest)=0; ///< store a byte
- virtual void store_16(uint16_t p_dest); ///< store 16 bits uint
- virtual void store_32(uint32_t p_dest); ///< store 32 bits uint
- virtual void store_64(uint64_t p_dest); ///< store 64 bits uint
+ virtual void store_8(uint8_t p_dest)=0; ///< store a byte
+ virtual void store_16(uint16_t p_dest); ///< store 16 bits uint
+ virtual void store_32(uint32_t p_dest); ///< store 32 bits uint
+ virtual void store_64(uint64_t p_dest); ///< store 64 bits uint
virtual void store_float(float p_dest);
virtual void store_double(double p_dest);
@@ -129,9 +129,9 @@ public:
virtual void store_pascal_string(const String& p_string);
virtual String get_pascal_string();
- virtual void store_buffer(const uint8_t *p_src,int p_length); ///< store an array of bytes
-
- virtual bool file_exists(const String& p_name)=0; ///< return true if a file exists
+ virtual void store_buffer(const uint8_t *p_src,int p_length); ///< store an array of bytes
+
+ virtual bool file_exists(const String& p_name)=0; ///< return true if a file exists
virtual Error reopen(const String& p_path, int p_mode_flags); ///< does not change the AccessType
diff --git a/core/os/input.h b/core/os/input.h
index 2dd4496f26..535776f39c 100644
--- a/core/os/input.h
+++ b/core/os/input.h
@@ -55,7 +55,7 @@ public:
static Input *get_singleton();
- virtual bool is_key_pressed(int p_scancode)=0;
+ virtual bool is_key_pressed(int p_scancode)=0;
virtual bool is_mouse_button_pressed(int p_button)=0;
virtual bool is_joy_button_pressed(int p_device, int p_button)=0;
virtual bool is_action_pressed(const StringName& p_action)=0;
diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp
index 3022a56e2a..2d47645a66 100644
--- a/core/os/input_event.cpp
+++ b/core/os/input_event.cpp
@@ -30,7 +30,7 @@
#include "input_map.h"
#include "os/keyboard.h"
/**
- *
+ *
*/
bool InputEvent::operator==(const InputEvent &p_event) const {
@@ -40,15 +40,15 @@ bool InputEvent::operator==(const InputEvent &p_event) const {
InputEvent::operator String() const {
String str="Device "+itos(device)+" ID "+itos(ID)+" ";
-
+
switch(type) {
-
+
case NONE: {
-
+
return "Event: None";
} break;
case KEY: {
-
+
str+= "Event: Key ";
str=str+"Unicode: "+String::chr(key.unicode)+" Scan: "+itos( key.scancode )+" Echo: "+String(key.echo?"True":"False")+" Pressed"+String(key.pressed?"True":"False")+" Mod: ";
if (key.mod.shift)
@@ -59,15 +59,15 @@ InputEvent::operator String() const {
str+="A";
if (key.mod.meta)
str+="M";
-
+
return str;
} break;
case MOUSE_MOTION: {
-
+
str+= "Event: Motion ";
str=str+" Pos: " +itos(mouse_motion.x)+","+itos(mouse_motion.y)+" Rel: "+itos(mouse_motion.relative_x)+","+itos(mouse_motion.relative_y)+" Mask: ";
for (int i=0;i<8;i++) {
-
+
if ((1<<i)&mouse_motion.button_mask)
str+=itos(i+1);
}
@@ -87,7 +87,7 @@ InputEvent::operator String() const {
str+= "Event: Button ";
str=str+"Pressed: "+itos(mouse_button.pressed)+" Pos: " +itos(mouse_button.x)+","+itos(mouse_button.y)+" Button: "+itos(mouse_button.button_index)+" Mask: ";
for (int i=0;i<8;i++) {
-
+
if ((1<<i)&mouse_button.button_mask)
str+=itos(i+1);
}
@@ -102,9 +102,9 @@ InputEvent::operator String() const {
str+="M";
str+=String(" DoubleClick: ")+(mouse_button.doubleclick?"Yes":"No");
-
+
return str;
-
+
} break;
case JOYSTICK_MOTION: {
str+= "Event: JoystickMotion ";
@@ -137,7 +137,7 @@ InputEvent::operator String() const {
} break;
}
-
+
return "";
}
diff --git a/core/os/input_event.h b/core/os/input_event.h
index 36c1556524..0588374790 100644
--- a/core/os/input_event.h
+++ b/core/os/input_event.h
@@ -189,7 +189,7 @@ struct InputModifierState {
struct InputEventKey {
InputModifierState mod;
-
+
bool pressed; /// otherwise release
uint32_t scancode; ///< check keyboard.h , KeyCode enum, without modifier masks
@@ -212,11 +212,11 @@ struct InputEventMouse {
struct InputEventMouseButton : public InputEventMouse {
-
+
int button_index;
bool pressed; //otherwise released
bool doubleclick; //last even less than doubleclick time
-
+
};
struct InputEventMouseMotion : public InputEventMouse {
diff --git a/core/os/keyboard.h b/core/os/keyboard.h
index 0848f8c28e..80472acc09 100644
--- a/core/os/keyboard.h
+++ b/core/os/keyboard.h
@@ -121,7 +121,7 @@ enum KeyList {
KEY_DIRECTION_R=SPKEY | 0x33,
KEY_BACK=SPKEY | 0x40,
KEY_FORWARD=SPKEY | 0x41,
- KEY_STOP=SPKEY | 0x42,
+ KEY_STOP=SPKEY | 0x42,
KEY_REFRESH=SPKEY | 0x43,
KEY_VOLUMEDOWN=SPKEY | 0x44,
KEY_VOLUMEMUTE=SPKEY | 0x45,
@@ -159,11 +159,11 @@ enum KeyList {
KEY_LAUNCHD=SPKEY | 0x65,
KEY_LAUNCHE=SPKEY | 0x66,
KEY_LAUNCHF=SPKEY | 0x67,
-
+
KEY_UNKNOWN=SPKEY | 0xFFFFFF,
-
+
/* PRINTABLE LATIN 1 CODES */
-
+
KEY_SPACE=0x0020,
KEY_EXCLAM=0x0021,
KEY_QUOTEDBL=0x0022,
@@ -297,18 +297,18 @@ enum KeyList {
KEY_YACUTE=0x00DD,
KEY_THORN=0x00DE,
KEY_SSHARP=0x00DF,
-
+
KEY_DIVISION=0x00F7,
KEY_YDIAERESIS=0x00FF,
-
-
+
+
};
enum KeyModifierMask {
-
+
KEY_CODE_MASK=((1<<25)-1), ///< Apply this mask to any keycode to remove modifiers.
- KEY_MODIFIER_MASK=(0xFF<<24), ///< Apply this mask to isolate modifiers.
+ KEY_MODIFIER_MASK=(0xFF<<24), ///< Apply this mask to isolate modifiers.
KEY_MASK_SHIFT = (1<<25),
KEY_MASK_ALT = (1<<26),
KEY_MASK_META = (1<<27),
@@ -322,7 +322,7 @@ enum KeyModifierMask {
KEY_MASK_KPAD = (1<<29),
KEY_MASK_GROUP_SWITCH = (1<<30)
// bit 31 can't be used because variant uses regular 32 bits int as datatype
-
+
};
String keycode_get_string(uint32_t p_code);
diff --git a/core/os/main_loop.h b/core/os/main_loop.h
index 059624dbe4..a34014983e 100644
--- a/core/os/main_loop.h
+++ b/core/os/main_loop.h
@@ -36,7 +36,7 @@
@author Juan Linietsky <reduzio@gmail.com>
*/
class MainLoop : public Object {
-
+
OBJ_TYPE( MainLoop, Object );
OBJ_CATEGORY("Main Loop");
@@ -44,7 +44,7 @@ class MainLoop : public Object {
protected:
static void _bind_methods();
-public:
+public:
enum {
NOTIFICATION_WM_MOUSE_ENTER = 3,
@@ -55,7 +55,7 @@ public:
NOTIFICATION_WM_UNFOCUS_REQUEST = 8,
NOTIFICATION_OS_MEMORY_WARNING = 9,
};
-
+
virtual void input_event( const InputEvent& p_event );
virtual void input_text( const String& p_text );
diff --git a/core/os/memory.cpp b/core/os/memory.cpp
index f7f8fef2b7..c2ff2aa781 100644
--- a/core/os/memory.cpp
+++ b/core/os/memory.cpp
@@ -88,16 +88,16 @@ void Memory::dump_static_mem_to_file(const char* p_file) {
MID Memory::alloc_dynamic(size_t p_bytes, const char *p_descr) {
MemoryPoolDynamic::ID id = MemoryPoolDynamic::get_singleton()->alloc(p_bytes,p_descr);
-
+
return MID(id);
}
Error Memory::realloc_dynamic(MID p_mid,size_t p_bytes) {
MemoryPoolDynamic::ID id = p_mid.data?p_mid.data->id:MemoryPoolDynamic::INVALID_ID;
-
+
if (id==MemoryPoolDynamic::INVALID_ID)
return ERR_INVALID_PARAMETER;
-
+
return MemoryPoolDynamic::get_singleton()->realloc(p_mid, p_bytes);
}
diff --git a/core/os/memory.h b/core/os/memory.h
index 8eb5ceccb6..8257e66851 100644
--- a/core/os/memory.h
+++ b/core/os/memory.h
@@ -42,61 +42,61 @@
class MID {
struct Data {
-
+
SafeRefCount refcount;
MemoryPoolDynamic::ID id;
};
mutable Data *data;
-
+
void unref() {
-
+
if (!data)
return;
if (data->refcount.unref()) {
-
+
if (data->id!=MemoryPoolDynamic::INVALID_ID)
- MemoryPoolDynamic::get_singleton()->free(data->id);
- MemoryPoolStatic::get_singleton()->free(data);
+ MemoryPoolDynamic::get_singleton()->free(data->id);
+ MemoryPoolStatic::get_singleton()->free(data);
}
-
+
data=NULL;
}
-
+
void ref(Data *p_data) {
-
+
if (data==p_data)
return;
unref();
-
+
if (p_data && p_data->refcount.ref())
- data=p_data;
+ data=p_data;
}
-
+
friend class MID_Lock;
inline void lock() {
-
+
if (data && data->id!=MemoryPoolDynamic::INVALID_ID)
MemoryPoolDynamic::get_singleton()->lock(data->id);
}
inline void unlock() {
-
+
if (data && data->id!=MemoryPoolDynamic::INVALID_ID)
MemoryPoolDynamic::get_singleton()->unlock(data->id);
-
+
}
-
+
inline void * get() {
-
+
if (data && data->id!=MemoryPoolDynamic::INVALID_ID)
return MemoryPoolDynamic::get_singleton()->get(data->id);
-
+
return NULL;
}
-
- Error _resize(size_t p_size) {
-
+
+ Error _resize(size_t p_size) {
+
if (p_size==0 && (!data || data->id==MemoryPoolDynamic::INVALID_ID))
return OK;
if (p_size && !data) {
@@ -104,46 +104,46 @@ friend class MID_Lock;
data = (Data*)MemoryPoolStatic::get_singleton()->alloc(sizeof(Data),"MID::Data");
ERR_FAIL_COND_V( !data,ERR_OUT_OF_MEMORY );
data->refcount.init();
- data->id=MemoryPoolDynamic::INVALID_ID;
+ data->id=MemoryPoolDynamic::INVALID_ID;
}
-
+
if (p_size==0 && data && data->id==MemoryPoolDynamic::INVALID_ID) {
-
+
MemoryPoolDynamic::get_singleton()->free(data->id);
data->id=MemoryPoolDynamic::INVALID_ID;
}
-
+
if (p_size>0) {
-
+
if (data->id==MemoryPoolDynamic::INVALID_ID) {
-
+
data->id=MemoryPoolDynamic::get_singleton()->alloc(p_size,"Unnamed MID");
ERR_FAIL_COND_V( data->id==MemoryPoolDynamic::INVALID_ID, ERR_OUT_OF_MEMORY );
} else {
-
+
MemoryPoolDynamic::get_singleton()->realloc(data->id,p_size);
ERR_FAIL_COND_V( data->id==MemoryPoolDynamic::INVALID_ID, ERR_OUT_OF_MEMORY );
-
+
}
- }
-
+ }
+
return OK;
}
friend class Memory;
-
+
MID(MemoryPoolDynamic::ID p_id) {
-
+
data = (Data*)MemoryPoolStatic::get_singleton()->alloc(sizeof(Data),"MID::Data");
data->refcount.init();
data->id=p_id;
}
-public:
+public:
bool is_valid() const { return data; }
operator bool() const { return data; }
-
-
+
+
size_t get_size() const { return (data && data->id!=MemoryPoolDynamic::INVALID_ID) ? MemoryPoolDynamic::get_singleton()->get_size(data->id) : 0; }
Error resize(size_t p_size) { return _resize(p_size); }
inline void operator=(const MID& p_mid) { ref( p_mid.data ); }
@@ -157,7 +157,7 @@ public:
class MID_Lock {
MID mid;
-
+
public:
void *data() { return mid.get(); }
@@ -174,21 +174,21 @@ class Memory{
Memory();
public:
-
+
static void * alloc_static(size_t p_bytes,const char *p_descr="");
static void * realloc_static(void *p_memory,size_t p_bytes);
static void free_static(void *p_ptr);
static size_t get_static_mem_available();
- static size_t get_static_mem_usage();
+ static size_t get_static_mem_usage();
static size_t get_static_mem_max_usage();
static void dump_static_mem_to_file(const char* p_file);
static MID alloc_dynamic(size_t p_bytes, const char *p_descr="");
static Error realloc_dynamic(MID p_mid,size_t p_bytes);
-
+
static size_t get_dynamic_mem_available();
static size_t get_dynamic_mem_usage();
-
+
};
template<class T>
@@ -241,7 +241,7 @@ _ALWAYS_INLINE_ void postinitialize_handler(void *) {}
template<class T>
_ALWAYS_INLINE_ T *_post_initialize(T *p_obj) {
-
+
postinitialize_handler(p_obj);
return p_obj;
}
@@ -272,7 +272,7 @@ _ALWAYS_INLINE_ bool predelete_handler(void *) { return true; }
template<class T>
void memdelete(T *p_class) {
-
+
if (!predelete_handler(p_class))
return; // doesn't want to be deleted
p_class->~T();
diff --git a/core/os/memory_pool_dynamic.h b/core/os/memory_pool_dynamic.h
index 82149bcf5d..70752fb10d 100644
--- a/core/os/memory_pool_dynamic.h
+++ b/core/os/memory_pool_dynamic.h
@@ -40,10 +40,10 @@ friend class Memory;
friend class MID;
enum {
-
+
INVALID_ID=0xFFFFFFFF
};
-
+
static MemoryPoolDynamic* get_singleton();
typedef uint64_t ID;
@@ -55,12 +55,12 @@ friend class MID;
virtual bool is_valid(ID p_id)=0;
virtual size_t get_size(ID p_id) const=0;
virtual const char* get_description(ID p_id) const=0;
-
+
virtual Error lock(ID p_id)=0;
virtual void * get(ID p_ID)=0;
virtual Error unlock(ID p_id)=0;
virtual bool is_locked(ID p_id) const=0;
-
+
virtual size_t get_available_mem() const=0;
virtual size_t get_total_usage() const=0;
diff --git a/core/os/memory_pool_dynamic_static.cpp b/core/os/memory_pool_dynamic_static.cpp
index 894066708e..c047c931ec 100644
--- a/core/os/memory_pool_dynamic_static.cpp
+++ b/core/os/memory_pool_dynamic_static.cpp
@@ -37,10 +37,10 @@ MemoryPoolDynamicStatic::Chunk *MemoryPoolDynamicStatic::get_chunk(ID p_id) {
uint64_t check = p_id/MAX_CHUNKS;
uint64_t idx = p_id%MAX_CHUNKS;
-
+
if (!chunk[idx].mem || chunk[idx].check!=check)
return NULL;
-
+
return &chunk[idx];
}
@@ -49,32 +49,32 @@ const MemoryPoolDynamicStatic::Chunk *MemoryPoolDynamicStatic::get_chunk(ID p_id
uint64_t check = p_id/MAX_CHUNKS;
uint64_t idx = p_id%MAX_CHUNKS;
-
+
if (!chunk[idx].mem || chunk[idx].check!=check)
return NULL;
-
+
return &chunk[idx];
}
MemoryPoolDynamic::ID MemoryPoolDynamicStatic::alloc(size_t p_amount,const char* p_description) {
_THREAD_SAFE_METHOD_
-
+
int idx=-1;
-
+
for (int i=0;i<MAX_CHUNKS;i++) {
-
+
last_alloc++;
if (last_alloc>=MAX_CHUNKS)
last_alloc=0;
-
+
if ( !chunk[last_alloc].mem ) {
-
+
idx=last_alloc;
break;
}
}
-
+
if (idx==-1) {
ERR_EXPLAIN("Out of dynamic Memory IDs");
@@ -86,36 +86,36 @@ MemoryPoolDynamic::ID MemoryPoolDynamicStatic::alloc(size_t p_amount,const char*
chunk[idx].mem = memalloc(p_amount);
if (!chunk[idx].mem)
return INVALID_ID;
-
+
chunk[idx].size=p_amount;
chunk[idx].check=++last_check;
chunk[idx].descr=p_description;
chunk[idx].lock=0;
-
+
total_usage+=p_amount;
if (total_usage>max_usage)
max_usage=total_usage;
-
+
ID id = chunk[idx].check*MAX_CHUNKS + (uint64_t)idx;
-
+
return id;
-
+
}
void MemoryPoolDynamicStatic::free(ID p_id) {
_THREAD_SAFE_METHOD_
-
+
Chunk *c = get_chunk(p_id);
ERR_FAIL_COND(!c);
-
-
+
+
total_usage-=c->size;
memfree(c->mem);
c->mem=0;
-
+
if (c->lock>0) {
-
+
ERR_PRINT("Freed ID Still locked");
}
}
@@ -123,14 +123,14 @@ void MemoryPoolDynamicStatic::free(ID p_id) {
Error MemoryPoolDynamicStatic::realloc(ID p_id, size_t p_amount) {
_THREAD_SAFE_METHOD_
-
+
Chunk *c = get_chunk(p_id);
ERR_FAIL_COND_V(!c,ERR_INVALID_PARAMETER);
ERR_FAIL_COND_V(c->lock > 0 , ERR_LOCKED );
-
-
+
+
void * new_mem = memrealloc(c->mem,p_amount);
-
+
ERR_FAIL_COND_V(!new_mem,ERR_OUT_OF_MEMORY);
total_usage-=c->size;
c->mem=new_mem;
@@ -138,37 +138,37 @@ Error MemoryPoolDynamicStatic::realloc(ID p_id, size_t p_amount) {
total_usage+=c->size;
if (total_usage>max_usage)
max_usage=total_usage;
-
+
return OK;
}
bool MemoryPoolDynamicStatic::is_valid(ID p_id) {
_THREAD_SAFE_METHOD_
-
+
Chunk *c = get_chunk(p_id);
-
+
return c!=NULL;
}
size_t MemoryPoolDynamicStatic::get_size(ID p_id) const {
_THREAD_SAFE_METHOD_
-
+
const Chunk *c = get_chunk(p_id);
ERR_FAIL_COND_V(!c,0);
-
+
return c->size;
-
+
}
const char* MemoryPoolDynamicStatic::get_description(ID p_id) const {
_THREAD_SAFE_METHOD_
-
+
const Chunk *c = get_chunk(p_id);
ERR_FAIL_COND_V(!c,"");
-
+
return c->descr;
}
@@ -177,10 +177,10 @@ const char* MemoryPoolDynamicStatic::get_description(ID p_id) const {
bool MemoryPoolDynamicStatic::is_locked(ID p_id) const {
_THREAD_SAFE_METHOD_
-
+
const Chunk *c = get_chunk(p_id);
ERR_FAIL_COND_V(!c,false);
-
+
return c->lock>0;
}
@@ -188,10 +188,10 @@ bool MemoryPoolDynamicStatic::is_locked(ID p_id) const {
Error MemoryPoolDynamicStatic::lock(ID p_id) {
_THREAD_SAFE_METHOD_
-
+
Chunk *c = get_chunk(p_id);
ERR_FAIL_COND_V(!c,ERR_INVALID_PARAMETER);
-
+
c->lock++;
return OK;
@@ -199,23 +199,23 @@ Error MemoryPoolDynamicStatic::lock(ID p_id) {
void * MemoryPoolDynamicStatic::get(ID p_id) {
_THREAD_SAFE_METHOD_
-
+
const Chunk *c = get_chunk(p_id);
ERR_FAIL_COND_V(!c,NULL);
ERR_FAIL_COND_V( c->lock==0, NULL );
-
+
return c->mem;
}
Error MemoryPoolDynamicStatic::unlock(ID p_id) {
_THREAD_SAFE_METHOD_
-
+
Chunk *c = get_chunk(p_id);
ERR_FAIL_COND_V(!c,ERR_INVALID_PARAMETER);
-
+
ERR_FAIL_COND_V( c->lock<=0, ERR_INVALID_PARAMETER );
c->lock--;
-
+
return OK;
}
@@ -226,7 +226,7 @@ size_t MemoryPoolDynamicStatic::get_available_mem() const {
size_t MemoryPoolDynamicStatic::get_total_usage() const {
_THREAD_SAFE_METHOD_
-
+
return total_usage;
}
diff --git a/core/os/memory_pool_dynamic_static.h b/core/os/memory_pool_dynamic_static.h
index 6177c78de7..a72d39355c 100644
--- a/core/os/memory_pool_dynamic_static.h
+++ b/core/os/memory_pool_dynamic_static.h
@@ -40,19 +40,19 @@ class MemoryPoolDynamicStatic : public MemoryPoolDynamic {
enum {
MAX_CHUNKS=65536
};
-
-
+
+
struct Chunk {
-
+
uint64_t lock;
uint64_t check;
void *mem;
size_t size;
- const char *descr;
-
+ const char *descr;
+
Chunk() { mem=NULL; lock=0; check=0; }
};
-
+
Chunk chunk[MAX_CHUNKS];
uint64_t last_check;
int last_alloc;
@@ -62,14 +62,14 @@ class MemoryPoolDynamicStatic : public MemoryPoolDynamic {
Chunk *get_chunk(ID p_id);
const Chunk *get_chunk(ID p_id) const;
public:
-
+
virtual ID alloc(size_t p_amount,const char* p_description);
virtual void free(ID p_id);
virtual Error realloc(ID p_id, size_t p_amount);
virtual bool is_valid(ID p_id);
virtual size_t get_size(ID p_id) const;
virtual const char* get_description(ID p_id) const;
-
+
virtual bool is_locked(ID p_id) const;
virtual Error lock(ID p_id);
virtual void * get(ID p_ID);
diff --git a/core/os/memory_pool_static.cpp b/core/os/memory_pool_static.cpp
index 321f4d989e..88c2ba3b3e 100644
--- a/core/os/memory_pool_static.cpp
+++ b/core/os/memory_pool_static.cpp
@@ -31,13 +31,13 @@
MemoryPoolStatic *MemoryPoolStatic::singleton=0;
MemoryPoolStatic *MemoryPoolStatic::get_singleton() {
-
+
return singleton;
}
MemoryPoolStatic::MemoryPoolStatic() {
-
+
singleton=this;
}
diff --git a/core/os/memory_pool_static.h b/core/os/memory_pool_static.h
index 2e11b7ded4..f7f60b8df8 100644
--- a/core/os/memory_pool_static.h
+++ b/core/os/memory_pool_static.h
@@ -38,17 +38,17 @@
*/
class MemoryPoolStatic {
private:
-
+
static MemoryPoolStatic *singleton;
public:
-
+
static MemoryPoolStatic *get_singleton();
-
+
virtual void* alloc(size_t p_bytes,const char *p_description)=0; ///< Pointer in p_description shold be to a const char const like "hello"
virtual void* realloc(void * p_memory,size_t p_bytes)=0; ///< Pointer in p_description shold be to a const char const like "hello"
virtual void free(void *p_ptr)=0; ///< Pointer in p_description shold be to a const char const
-
+
virtual size_t get_available_mem() const=0;
virtual size_t get_total_usage()=0;
virtual size_t get_max_usage()=0;
diff --git a/core/os/mutex.cpp b/core/os/mutex.cpp
index 9b379009b9..21400d2ccf 100644
--- a/core/os/mutex.cpp
+++ b/core/os/mutex.cpp
@@ -50,13 +50,13 @@ Mutex::~Mutex() {
Mutex *_global_mutex=NULL;;
void _global_lock() {
-
+
if (_global_mutex)
_global_mutex->lock();
}
void _global_unlock() {
-
+
if (_global_mutex)
- _global_mutex->unlock();
+ _global_mutex->unlock();
}
diff --git a/core/os/mutex.h b/core/os/mutex.h
index f16375aa26..5870171dc7 100644
--- a/core/os/mutex.h
+++ b/core/os/mutex.h
@@ -33,7 +33,7 @@
/**
- * @class Mutex
+ * @class Mutex
* @author Juan Linietsky
* Portable Mutex (thread-safe locking) implementation.
* Mutexes are always recursive ( they don't self-lock in a single thread ).
@@ -43,9 +43,9 @@
class Mutex {
-protected:
+protected:
static Mutex* (*create_func)(bool);
-
+
public:
virtual void lock()=0; ///< Lock the mutex, block if locked by someone else
@@ -53,7 +53,7 @@ public:
virtual Error try_lock()=0; ///< Attempt to lock the mutex, OK on success, ERROR means it can't lock.
static Mutex * create(bool p_recursive=true); ///< Create a mutex
-
+
virtual ~Mutex();
};
diff --git a/core/os/os.h b/core/os/os.h
index a80b81bfa2..65ce44465b 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -71,7 +71,7 @@ public:
RENDER_SEPARATE_THREAD
};
struct VideoMode {
-
+
int width,height;
bool fullscreen;
bool resizable;
@@ -80,33 +80,33 @@ public:
};
protected:
friend class Main;
-
+
RenderThreadMode _render_thread_mode;
// functions used by main to initialize/deintialize the OS
virtual int get_video_driver_count() const=0;
virtual const char * get_video_driver_name(int p_driver) const=0;
-
+
virtual VideoMode get_default_video_mode() const=0;
-
+
virtual int get_audio_driver_count() const=0;
virtual const char * get_audio_driver_name(int p_driver) const=0;
-
+
virtual void initialize_core()=0;
virtual void initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver)=0;
-
- virtual void set_main_loop( MainLoop * p_main_loop )=0;
+
+ virtual void set_main_loop( MainLoop * p_main_loop )=0;
virtual void delete_main_loop()=0;
-
+
virtual void finalize()=0;
virtual void finalize_core()=0;
virtual void set_cmdline(const char* p_execpath, const List<String>& p_args);
void _ensure_data_dir();
-
+
public:
-
+
typedef int64_t ProcessID;
static OS* get_singleton();
@@ -148,7 +148,7 @@ public:
virtual void set_clipboard(const String& p_text);
virtual String get_clipboard() const;
-
+
virtual void set_video_mode(const VideoMode& p_video_mode,int p_screen=0)=0;
virtual VideoMode get_video_mode(int p_screen=0) const=0;
virtual void get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen=0) const=0;
@@ -219,7 +219,7 @@ public:
DAY_FRIDAY,
DAY_SATURDAY
};
-
+
enum Month {
MONTH_JANUARY,
MONTH_FEBRUARY,
@@ -236,7 +236,7 @@ public:
};
struct Date {
-
+
int year;
Month month;
int day;
@@ -245,7 +245,7 @@ public:
};
struct Time {
-
+
int hour;
int min;
int sec;
@@ -262,7 +262,7 @@ public:
virtual uint64_t get_unix_time() const;
virtual uint64_t get_system_time_secs() const;
- virtual void delay_usec(uint32_t p_usec) const=0;
+ virtual void delay_usec(uint32_t p_usec) const=0;
virtual uint64_t get_ticks_usec() const=0;
uint32_t get_ticks_msec() const;
uint64_t get_splash_tick_msec() const;
@@ -412,7 +412,7 @@ public:
virtual void set_context(int p_context);
- OS();
+ OS();
virtual ~OS();
};
diff --git a/core/os/semaphore.h b/core/os/semaphore.h
index b65542ce35..8469408e65 100644
--- a/core/os/semaphore.h
+++ b/core/os/semaphore.h
@@ -35,17 +35,17 @@
@author Juan Linietsky <reduzio@gmail.com>
*/
class Semaphore {
-protected:
+protected:
static Semaphore* (*create_func)();
-
+
public:
virtual Error wait()=0; ///< wait until semaphore has positive value, then decrement and pass
virtual Error post()=0; ///< unlock the semaphore, incrementing the value
virtual int get() const=0; ///< get semaphore value
-
+
static Semaphore * create(); ///< Create a mutex
-
+
virtual ~Semaphore();
};
diff --git a/core/os/shell.h b/core/os/shell.h
index 805dd70301..8b0c286d73 100644
--- a/core/os/shell.h
+++ b/core/os/shell.h
@@ -42,7 +42,7 @@ public:
static Shell * get_singleton();
virtual void execute(String p_path)=0;
-
+
Shell();
virtual ~Shell();
};
diff --git a/core/os/thread.cpp b/core/os/thread.cpp
index f5d984876d..c1ae53074b 100644
--- a/core/os/thread.cpp
+++ b/core/os/thread.cpp
@@ -37,26 +37,26 @@ Error (*Thread::set_name_func)(const String&)=NULL;
Thread::ID Thread::_main_thread_id=0;
Thread::ID Thread::get_caller_ID() {
-
+
if (get_thread_ID_func)
return get_thread_ID_func();
return 0;
}
Thread* Thread::create(ThreadCreateCallback p_callback,void * p_user,const Settings& p_settings) {
-
+
if (create_func) {
-
+
return create_func(p_callback,p_user,p_settings);
}
return NULL;
}
void Thread::wait_to_finish(Thread *p_thread) {
-
+
if (wait_to_finish_func)
wait_to_finish_func(p_thread);
-
+
}
Error Thread::set_name(const String &p_name) {
diff --git a/core/os/thread.h b/core/os/thread.h
index 4fead72b94..7349b83dbc 100644
--- a/core/os/thread.h
+++ b/core/os/thread.h
@@ -41,25 +41,25 @@ typedef void (*ThreadCreateCallback)(void *p_userdata);
class Thread {
public:
-
+
enum Priority {
-
+
PRIORITY_LOW,
PRIORITY_NORMAL,
PRIORITY_HIGH
};
-
+
struct Settings {
-
+
Priority priority;
Settings() { priority=PRIORITY_NORMAL; }
};
-
+
typedef uint64_t ID;
-protected:
+protected:
static Thread* (*create_func)(ThreadCreateCallback p_callback,void *,const Settings&);
static ID (*get_thread_ID_func)();
static void (*wait_to_finish_func)(Thread*);
@@ -72,7 +72,7 @@ protected:
Thread();
public:
-
+
virtual ID get_ID() const=0;
@@ -81,8 +81,8 @@ public:
static ID get_caller_ID(); ///< get the ID of the caller function ID
static void wait_to_finish(Thread *p_thread); ///< waits until thread is finished, and deallocates it.
static Thread * create(ThreadCreateCallback p_callback,void * p_user,const Settings& p_settings=Settings()); ///< Static function to create a thread, will call p_callback
-
-
+
+
virtual ~Thread();
};
diff --git a/core/os/thread_safe.cpp b/core/os/thread_safe.cpp
index f252190504..a742b1144e 100644
--- a/core/os/thread_safe.cpp
+++ b/core/os/thread_safe.cpp
@@ -30,17 +30,17 @@
#include "error_macros.h"
#include "os/memory.h"
-ThreadSafe::ThreadSafe() {
+ThreadSafe::ThreadSafe() {
- mutex = Mutex::create();
+ mutex = Mutex::create();
if (!mutex) {
-
+
WARN_PRINT("THREAD_SAFE defined, but no default mutex type");
}
}
-ThreadSafe::~ThreadSafe() {
-
- if (mutex)
- memdelete( mutex );
+ThreadSafe::~ThreadSafe() {
+
+ if (mutex)
+ memdelete( mutex );
}
diff --git a/core/os/thread_safe.h b/core/os/thread_safe.h
index 793dd88543..1c82cbe704 100644
--- a/core/os/thread_safe.h
+++ b/core/os/thread_safe.h
@@ -42,7 +42,7 @@ public:
ThreadSafe();
~ThreadSafe();
-
+
};
@@ -51,11 +51,11 @@ class ThreadSafeMethod {
const ThreadSafe *_ts;
public:
ThreadSafeMethod(const ThreadSafe *p_ts) {
-
+
_ts=p_ts;
_ts->lock();
}
-
+
~ThreadSafeMethod() { _ts->unlock(); }
};
diff --git a/core/packed_data_container.cpp b/core/packed_data_container.cpp
index dd736502a3..91f886ff4b 100644
--- a/core/packed_data_container.cpp
+++ b/core/packed_data_container.cpp
@@ -182,12 +182,12 @@ Variant PackedDataContainer::_key_at_ofs(uint32_t p_ofs,const Variant& p_key,boo
err=true;
return Variant();
}
-
+
} else if (type==TYPE_DICT) {
uint32_t hash=p_key.hash();
uint32_t len = decode_uint32(r+4);
-
+
bool found=false;
for(int i=0;i<len;i++) {
uint32_t khash=decode_uint32(r+8+i*12+0);
@@ -214,7 +214,7 @@ Variant PackedDataContainer::_key_at_ofs(uint32_t p_ofs,const Variant& p_key,boo
err=true;
return Variant();
}
-
+
}
diff --git a/core/path_db.cpp b/core/path_db.cpp
index d3521fcb23..7545088978 100644
--- a/core/path_db.cpp
+++ b/core/path_db.cpp
@@ -58,17 +58,17 @@ bool NodePath::is_absolute() const {
if (!data)
return false;
-
+
return data->absolute;
-
+
}
int NodePath::get_name_count() const {
if (!data)
return 0;
-
+
return data->path.size();
-
+
}
StringName NodePath::get_name(int p_idx) const {
@@ -103,24 +103,24 @@ StringName NodePath::get_subname(int p_idx) const {
void NodePath::unref() {
if (data && data->refcount.unref()) {
-
+
memdelete(data);
}
data=NULL;
-
+
}
-
+
bool NodePath::operator==(const NodePath& p_path) const {
if (data==p_path.data)
return true;
-
+
if (!data || !p_path.data)
return false;
-
+
if (data->absolute != p_path.data->absolute)
return false;
-
+
if (data->path.size() != p_path.data->path.size())
return false;
@@ -131,7 +131,7 @@ bool NodePath::operator==(const NodePath& p_path) const {
return false;
for (int i=0;i<data->path.size();i++) {
-
+
if (data->path[i]!=p_path.data->path[i])
return false;
}
@@ -148,17 +148,17 @@ bool NodePath::operator!=(const NodePath& p_path) const {
return (!(*this == p_path));
}
-
-
+
+
void NodePath::operator=(const NodePath& p_path) {
if (this==&p_path)
return;
unref();
-
+
if (p_path.data && p_path.data->refcount.ref()) {
-
+
data=p_path.data;
}
}
@@ -167,13 +167,13 @@ NodePath::operator String() const {
if (!data)
return String();
-
+
String ret;
if (data->absolute)
ret="/";
-
+
for (int i=0;i<data->path.size();i++) {
-
+
if (i>0)
ret+="/";
ret+=data->path[i].operator String();
@@ -184,7 +184,7 @@ NodePath::operator String() const {
ret+=":"+data->subpath[i].operator String();
}
- if (data->property.operator String()!="")
+ if (data->property.operator String()!="")
ret+=":"+String(data->property);
return ret;
}
@@ -195,7 +195,7 @@ NodePath::NodePath(const NodePath& p_path) {
data=NULL;
if (p_path.data && p_path.data->refcount.ref()) {
-
+
data=p_path.data;
}
}
@@ -258,17 +258,17 @@ NodePath NodePath::rel_path_to(const NodePath& p_np) const {
NodePath::NodePath(const Vector<StringName>& p_path,bool p_absolute,const String& p_property) {
-
+
data=NULL;
-
+
if (p_path.size()==0)
return;
-
+
data = memnew( Data );
data->refcount.init();
data->absolute=p_absolute;
data->path=p_path;
- data->property=p_property;
+ data->property=p_property;
}
NodePath::NodePath(const Vector<StringName>& p_path,const Vector<StringName>& p_subpath,bool p_absolute,const String& p_property) {
@@ -327,17 +327,17 @@ NodePath::NodePath(const String& p_path) {
String path=p_path;
StringName property;
Vector<StringName> subpath;
-
- int absolute=(path[0]=='/')?1:0;;
+
+ int absolute=(path[0]=='/')?1:0;;
bool valid=false;
bool last_is_slash=true;
int slices=0;
int subpath_pos=path.find(":");
-
+
if (subpath_pos!=-1) {
-
+
int from=subpath_pos+1;
for (int i=from;i<=path.length();i++) {
@@ -362,44 +362,44 @@ NodePath::NodePath(const String& p_path) {
path=path.substr(0,subpath_pos);
}
-
+
for (int i=absolute;i<path.length();i++) {
-
+
if (path[i]=='/') {
-
+
last_is_slash=true;
} else {
-
+
if (last_is_slash)
slices++;
-
+
valid=true;
last_is_slash=false;
}
}
-
+
if (slices==0 && !absolute && !property)
return;
-
+
data = memnew( Data );
data->refcount.init();
data->absolute=absolute?true:false;
data->property=property;
data->subpath=subpath;
-
+
if (slices==0)
return;
- data->path.resize(slices);
+ data->path.resize(slices);
last_is_slash=true;
int from=absolute;
int slice=0;
-
+
for (int i=absolute;i<path.length()+1;i++) {
-
+
if (path[i]=='/' || path[i]==0) {
-
+
if (!last_is_slash) {
-
+
String name=path.substr(from,i-from);
ERR_FAIL_INDEX( slice,data->path.size() );
data->path[slice++]=name;
@@ -410,8 +410,8 @@ NodePath::NodePath(const String& p_path) {
last_is_slash=false;
}
}
-
-
+
+
}
bool NodePath::is_empty() const {
diff --git a/core/path_db.h b/core/path_db.h
index 9c9be65d28..63adb42955 100644
--- a/core/path_db.h
+++ b/core/path_db.h
@@ -41,14 +41,14 @@
class NodePath {
struct Data {
-
+
SafeRefCount refcount;
StringName property;
- Vector<StringName> path;
+ Vector<StringName> path;
Vector<StringName> subpath;
bool absolute;
};
-
+
Data *data;
void unref();
public:
@@ -77,7 +77,7 @@ public:
NodePath get_parent() const;
uint32_t hash() const;
-
+
operator String() const;
bool is_empty() const;
@@ -88,7 +88,7 @@ public:
void simplify();
NodePath simplified() const;
- NodePath(const Vector<StringName>& p_path,bool p_absolute,const String& p_property="");
+ NodePath(const Vector<StringName>& p_path,bool p_absolute,const String& p_property="");
NodePath(const Vector<StringName>& p_path,const Vector<StringName>& p_subpath,bool p_absolute,const String& p_property="");
NodePath(const NodePath& p_path);
NodePath(const String& p_path);
diff --git a/core/pool_allocator.cpp b/core/pool_allocator.cpp
index 23be650fda..849fd75f50 100644
--- a/core/pool_allocator.cpp
+++ b/core/pool_allocator.cpp
@@ -42,11 +42,11 @@ do { \
} while (0);
void PoolAllocator::mt_lock() const {
-
+
}
void PoolAllocator::mt_unlock() const {
-
+
}
@@ -61,7 +61,7 @@ bool PoolAllocator::get_free_entry(EntryArrayPos* p_pos) {
*p_pos=i;
return true;
}
-
+
}
ERR_PRINT("Out of memory Chunks!");
@@ -78,7 +78,7 @@ bool PoolAllocator::get_free_entry(EntryArrayPos* p_pos) {
bool PoolAllocator::find_hole(EntryArrayPos *p_pos, int p_for_size) {
/* position where previous entry ends. Defaults to zero (begin of pool) */
-
+
int prev_entry_end_pos=0;
for (int i=0;i<entry_count;i++) {
@@ -106,16 +106,16 @@ bool PoolAllocator::find_hole(EntryArrayPos *p_pos, int p_for_size) {
*p_pos=entry_count;
return true;
}
-
+
return false;
-
+
}
void PoolAllocator::compact(int p_up_to) {
-
+
uint32_t prev_entry_end_pos=0;
-
+
if (p_up_to<0)
p_up_to=entry_count;
for (int i=0;i<p_up_to;i++) {
@@ -129,16 +129,16 @@ void PoolAllocator::compact(int p_up_to) {
/* if we can compact, do it */
if (hole_size>0 && !entry.lock) {
-
+
COMPACT_CHUNK(entry,prev_entry_end_pos);
-
+
}
-
+
/* prepare for next one */
prev_entry_end_pos=entry_end(entry);
}
-
-
+
+
}
void PoolAllocator::compact_up(int p_from) {
@@ -169,81 +169,81 @@ void PoolAllocator::compact_up(int p_from) {
bool PoolAllocator::find_entry_index(EntryIndicesPos *p_map_pos,Entry *p_entry) {
-
+
EntryArrayPos entry_pos=entry_max;
-
+
for (int i=0;i<entry_count;i++) {
-
+
if (&entry_array[ entry_indices[ i ] ]==p_entry) {
-
+
entry_pos=i;
break;
}
}
-
+
if (entry_pos==entry_max)
return false;
-
+
*p_map_pos=entry_pos;
return true;
-
+
}
PoolAllocator::ID PoolAllocator::alloc(int p_size) {
-
+
ERR_FAIL_COND_V(p_size<1,POOL_ALLOCATOR_INVALID_ID);
#ifdef DEBUG_ENABLED
if (p_size > free_mem) OS::get_singleton()->debug_break();
#endif
ERR_FAIL_COND_V(p_size>free_mem,POOL_ALLOCATOR_INVALID_ID);
-
+
mt_lock();
-
+
if (entry_count==entry_max) {
mt_unlock();
ERR_PRINT("entry_count==entry_max");
return POOL_ALLOCATOR_INVALID_ID;
}
-
-
+
+
int size_to_alloc=aligned(p_size);
-
+
EntryIndicesPos new_entry_indices_pos;
-
+
if (!find_hole(&new_entry_indices_pos, size_to_alloc)) {
/* No hole could be found, try compacting mem */
compact();
/* Then search again */
-
+
if (!find_hole(&new_entry_indices_pos, size_to_alloc)) {
-
+
mt_unlock();
ERR_PRINT("memory can't be compacted further");
- return POOL_ALLOCATOR_INVALID_ID;
+ return POOL_ALLOCATOR_INVALID_ID;
}
}
-
+
EntryArrayPos new_entry_array_pos;
-
+
bool found_free_entry=get_free_entry(&new_entry_array_pos);
-
+
if (!found_free_entry) {
mt_unlock();
ERR_FAIL_COND_V( !found_free_entry , POOL_ALLOCATOR_INVALID_ID );
}
-
+
/* move all entry indices up, make room for this one */
for (int i=entry_count;i>new_entry_indices_pos;i-- ) {
-
+
entry_indices[i]=entry_indices[i-1];
}
-
+
entry_indices[new_entry_indices_pos]=new_entry_array_pos;
-
+
entry_count++;
-
+
Entry &entry=entry_array[ entry_indices[ new_entry_indices_pos ] ];
-
+
entry.len=p_size;
entry.pos=(new_entry_indices_pos==0)?0:entry_end(entry_array[ entry_indices[ new_entry_indices_pos-1 ] ]); //alloc either at begining or end of previous
entry.lock=0;
@@ -251,40 +251,40 @@ PoolAllocator::ID PoolAllocator::alloc(int p_size) {
free_mem-=size_to_alloc;
if (free_mem<free_mem_peak)
free_mem_peak=free_mem;
-
+
ID retval = (entry_indices[ new_entry_indices_pos ]<<CHECK_BITS)|entry.check;
mt_unlock();
//ERR_FAIL_COND_V( (uintptr_t)get(retval)%align != 0, retval );
return retval;
-
+
}
PoolAllocator::Entry * PoolAllocator::get_entry(ID p_mem) {
-
+
unsigned int check=p_mem&CHECK_MASK;
int entry=p_mem>>CHECK_BITS;
ERR_FAIL_INDEX_V(entry,entry_max,NULL);
ERR_FAIL_COND_V(entry_array[entry].check!=check,NULL);
ERR_FAIL_COND_V(entry_array[entry].len==0,NULL);
-
+
return &entry_array[entry];
}
const PoolAllocator::Entry * PoolAllocator::get_entry(ID p_mem) const {
-
+
unsigned int check=p_mem&CHECK_MASK;
int entry=p_mem>>CHECK_BITS;
ERR_FAIL_INDEX_V(entry,entry_max,NULL);
ERR_FAIL_COND_V(entry_array[entry].check!=check,NULL);
ERR_FAIL_COND_V(entry_array[entry].len==0,NULL);
-
+
return &entry_array[entry];
}
void PoolAllocator::free(ID p_mem) {
-
+
mt_lock();
Entry *e=get_entry(p_mem);
if (!e) {
@@ -297,23 +297,23 @@ void PoolAllocator::free(ID p_mem) {
ERR_PRINT("e->lock");
return;
}
-
+
EntryIndicesPos entry_indices_pos;
-
+
bool index_found = find_entry_index(&entry_indices_pos,e);
if (!index_found) {
-
+
mt_unlock();
ERR_FAIL_COND(!index_found);
}
-
-
+
+
for (int i=entry_indices_pos;i<(entry_count-1);i++) {
-
+
entry_indices[ i ] = entry_indices[ i+1 ];
}
-
+
entry_count--;
free_mem+=aligned(e->len);
e->clear();
@@ -327,21 +327,21 @@ int PoolAllocator::get_size(ID p_mem) const {
const Entry *e=get_entry(p_mem);
if (!e) {
-
+
mt_unlock();
ERR_PRINT("!e");
return 0;
}
-
+
size=e->len;
-
+
mt_unlock();
-
+
return size;
-}
+}
Error PoolAllocator::resize(ID p_mem,int p_new_size) {
-
+
mt_lock();
Entry *e=get_entry(p_mem);
@@ -443,18 +443,18 @@ Error PoolAllocator::resize(ID p_mem,int p_new_size) {
Error PoolAllocator::lock(ID p_mem) {
-
+
if (!needs_locking)
return OK;
mt_lock();
Entry *e=get_entry(p_mem);
if (!e) {
-
+
mt_unlock();
ERR_PRINT("!e");
return ERR_INVALID_PARAMETER;
}
- e->lock++;
+ e->lock++;
mt_unlock();
return OK;
}
@@ -480,85 +480,85 @@ bool PoolAllocator::is_locked(ID p_mem) const {
const void *PoolAllocator::get(ID p_mem) const {
if (!needs_locking) {
-
+
const Entry *e=get_entry(p_mem);
ERR_FAIL_COND_V(!e,NULL);
return &pool[e->pos];
-
+
}
-
+
mt_lock();
const Entry *e=get_entry(p_mem);
-
+
if (!e) {
-
+
mt_unlock();
ERR_FAIL_COND_V(!e,NULL);
}
if (e->lock==0) {
-
+
mt_unlock();
ERR_PRINT( "e->lock == 0" );
return NULL;
}
-
+
if (e->pos<0 || (int)e->pos>=pool_size) {
-
+
mt_unlock();
ERR_PRINT("e->pos<0 || e->pos>=pool_size");
return NULL;
}
const void *ptr=&pool[e->pos];
-
+
mt_unlock();
-
+
return ptr;
}
void *PoolAllocator::get(ID p_mem) {
-
+
if (!needs_locking) {
-
+
Entry *e=get_entry(p_mem);
if (!e) {
ERR_FAIL_COND_V(!e,NULL);
};
return &pool[e->pos];
-
+
}
-
+
mt_lock();
Entry *e=get_entry(p_mem);
-
+
if (!e) {
-
+
mt_unlock();
ERR_FAIL_COND_V(!e,NULL);
}
if (e->lock==0) {
-
+
//assert(0);
mt_unlock();
ERR_PRINT( "e->lock == 0" );
return NULL;
}
-
+
if (e->pos<0 || (int)e->pos>=pool_size) {
-
+
mt_unlock();
ERR_PRINT("e->pos<0 || e->pos>=pool_size");
return NULL;
}
void *ptr=&pool[e->pos];
-
+
mt_unlock();
-
+
return ptr;
-
+
}
void PoolAllocator::unlock(ID p_mem) {
-
+
if (!needs_locking)
return;
mt_lock();
@@ -568,7 +568,7 @@ void PoolAllocator::unlock(ID p_mem) {
ERR_PRINT( "e->lock == 0" );
return;
}
- e->lock--;
+ e->lock--;
mt_unlock();
}
@@ -583,34 +583,34 @@ int PoolAllocator::get_free_peak() {
}
int PoolAllocator::get_free_mem() {
-
+
return free_mem;
}
void PoolAllocator::create_pool(void * p_mem,int p_size,int p_max_entries) {
-
+
pool=(uint8_t*)p_mem;
pool_size=p_size;
-
+
entry_array = memnew_arr( Entry, p_max_entries );
entry_indices = memnew_arr( int, p_max_entries );
entry_max = p_max_entries;
entry_count=0;
-
+
free_mem=p_size;
free_mem_peak=p_size;
-
- check_count=0;
+
+ check_count=0;
}
PoolAllocator::PoolAllocator(int p_size,bool p_needs_locking,int p_max_entries) {
-
+
mem_ptr=Memory::alloc_static( p_size,"PoolAllocator()");
ERR_FAIL_COND(!mem_ptr);
align=1;
create_pool(mem_ptr,p_size,p_max_entries);
needs_locking=p_needs_locking;
-
+
}
PoolAllocator::PoolAllocator(void * p_mem,int p_size, int p_align ,bool p_needs_locking,int p_max_entries) {
@@ -626,16 +626,16 @@ PoolAllocator::PoolAllocator(void * p_mem,int p_size, int p_align ,bool p_needs_
p_mem = (void*)mem8;
};
};
-
+
create_pool( p_mem,p_size,p_max_entries);
needs_locking=p_needs_locking;
align=p_align;
- mem_ptr=NULL;
+ mem_ptr=NULL;
}
PoolAllocator::PoolAllocator(int p_align,int p_size,bool p_needs_locking,int p_max_entries) {
-
- ERR_FAIL_COND(p_align<1);
+
+ ERR_FAIL_COND(p_align<1);
mem_ptr=Memory::alloc_static( p_size+p_align,"PoolAllocator()");
uint8_t *mem8=(uint8_t*)mem_ptr;
uint64_t ofs = (uint64_t)mem8;
@@ -647,12 +647,12 @@ PoolAllocator::PoolAllocator(int p_align,int p_size,bool p_needs_locking,int p_m
}
PoolAllocator::~PoolAllocator() {
-
+
if (mem_ptr)
Memory::free_static( mem_ptr );
-
+
memdelete_arr( entry_array );
memdelete_arr( entry_indices );
-
+
}
diff --git a/core/pool_allocator.h b/core/pool_allocator.h
index 2c5920149b..438548bfe4 100644
--- a/core/pool_allocator.h
+++ b/core/pool_allocator.h
@@ -41,66 +41,66 @@
*/
enum {
-
+
POOL_ALLOCATOR_INVALID_ID=-1 ///< default invalid value. use INVALID_ID( id ) to test
};
class PoolAllocator {
-public:
+public:
typedef int ID;
-private:
+private:
enum {
CHECK_BITS=8,
CHECK_LEN=(1<<CHECK_BITS),
CHECK_MASK=CHECK_LEN-1
-
+
};
-
-
+
+
struct Entry {
-
+
unsigned int pos;
unsigned int len;
unsigned int lock;
- unsigned int check;
-
+ unsigned int check;
+
inline void clear() { pos=0; len=0; lock=0; check=0; }
Entry() { clear(); }
};
-
-
+
+
typedef int EntryArrayPos;
typedef int EntryIndicesPos;
-
+
Entry *entry_array;
int *entry_indices;
int entry_max;
int entry_count;
-
+
uint8_t *pool;
void *mem_ptr;
int pool_size;
-
+
int free_mem;
int free_mem_peak;
unsigned int check_count;
int align;
-
+
bool needs_locking;
-
- inline int entry_end(const Entry& p_entry) const {
- return p_entry.pos+aligned(p_entry.len);
+
+ inline int entry_end(const Entry& p_entry) const {
+ return p_entry.pos+aligned(p_entry.len);
}
inline int aligned(int p_size) const {
-
+
int rem=p_size%align;
if (rem)
p_size+=align-rem;
-
+
return p_size;
}
-
+
void compact(int p_up_to=-1);
void compact_up(int p_from=0);
bool get_free_entry(EntryArrayPos* p_pos);
@@ -108,14 +108,14 @@ private:
bool find_entry_index(EntryIndicesPos *p_map_pos,Entry *p_entry);
Entry* get_entry(ID p_mem);
const Entry* get_entry(ID p_mem) const;
-
+
void create_pool(void * p_mem,int p_size,int p_max_entries);
-protected:
+protected:
virtual void mt_lock() const; ///< Reimplement for custom mt locking
virtual void mt_unlock() const; ///< Reimplement for custom mt locking
-
+
public:
-
+
enum {
DEFAULT_MAX_ALLOCS=4096,
};
@@ -124,7 +124,7 @@ public:
void free(ID p_mem); ///< Free allocated memory
Error resize(ID p_mem,int p_new_size); ///< resize a memory chunk
int get_size(ID p_mem) const;
-
+
int get_free_mem(); ///< get free memory
int get_used_mem() const;
int get_free_peak(); ///< get free memory
@@ -134,13 +134,13 @@ public:
const void *get(ID p_mem) const;
void unlock(ID p_mem);
bool is_locked(ID p_mem) const;
-
+
PoolAllocator(int p_size,bool p_needs_locking=false,int p_max_entries=DEFAULT_MAX_ALLOCS);
PoolAllocator(void * p_mem,int p_size, int p_align = 1, bool p_needs_locking=false,int p_max_entries=DEFAULT_MAX_ALLOCS);
PoolAllocator(int p_align,int p_size,bool p_needs_locking=false,int p_max_entries=DEFAULT_MAX_ALLOCS);
-
+
virtual ~PoolAllocator();
-
+
};
#endif
diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp
index 54431cf381..97bd5f2a32 100644
--- a/core/register_core_types.cpp
+++ b/core/register_core_types.cpp
@@ -81,7 +81,7 @@ extern void unregister_variant_methods();
void register_core_types() {
-
+
_global_mutex=Mutex::create();
@@ -92,7 +92,7 @@ void register_core_types() {
CoreStringNames::create();
-
+
resource_format_po = memnew( TranslationLoaderPO );
ResourceLoader::add_resource_format_loader( resource_format_po );
diff --git a/core/res_ptr.cpp b/core/res_ptr.cpp
index 11312b8021..2fada627e7 100644
--- a/core/res_ptr.cpp
+++ b/core/res_ptr.cpp
@@ -53,7 +53,7 @@ RefPtr::RefPtr(const RefPtr& p_other) {
Ref<Resource> *ref = reinterpret_cast<Ref<Resource>*>( &data[0] );
Ref<Resource> *ref_other = reinterpret_cast<Ref<Resource>*>( const_cast<char*>(&p_other.data[0]) );
-
+
*ref = *ref_other;
}
diff --git a/core/res_ptr.h b/core/res_ptr.h
index e1dc66b290..54b74bb113 100644
--- a/core/res_ptr.h
+++ b/core/res_ptr.h
@@ -41,7 +41,7 @@
class ResBase;
class RefPtr {
-friend class ResBase;
+friend class ResBase;
enum {
DATASIZE=sizeof(void*)*4
diff --git a/core/resource.cpp b/core/resource.cpp
index e0706cf541..672e64b1bb 100644
--- a/core/resource.cpp
+++ b/core/resource.cpp
@@ -156,14 +156,14 @@ void Resource::_resource_path_changed() {
}
-
+
void Resource::set_path(const String& p_path, bool p_take_over) {
if (path_cache==p_path)
return;
-
+
if (path_cache!="") {
-
+
ResourceCache::resources.erase(path_cache);
}
@@ -179,19 +179,19 @@ void Resource::set_path(const String& p_path, bool p_take_over) {
}
path_cache=p_path;
-
+
if (path_cache!="") {
-
+
ResourceCache::resources[path_cache]=this;;
}
_change_notify("resource/path");
_resource_path_changed();
-
+
}
String Resource::get_path() const {
-
+
return path_cache;
}
@@ -342,7 +342,7 @@ Resource::Resource() {
Resource::~Resource() {
-
+
if (path_cache!="")
ResourceCache::resources.erase(path_cache);
if (owners.size()) {
@@ -350,12 +350,12 @@ Resource::~Resource() {
}
}
-HashMap<String,Resource*> ResourceCache::resources;
+HashMap<String,Resource*> ResourceCache::resources;
void ResourceCache::clear() {
if (resources.size())
ERR_PRINT("Resources Still in use at Exit!");
-
+
resources.clear();
}
@@ -374,18 +374,18 @@ void ResourceCache::reload_externals() {
bool ResourceCache::has(const String& p_path) {
GLOBAL_LOCK_FUNCTION
-
+
return resources.has(p_path);
}
Resource *ResourceCache::get(const String& p_path) {
-
+
GLOBAL_LOCK_FUNCTION
-
+
Resource **res = resources.getptr(p_path);
if (!res) {
return NULL;
}
-
+
return *res;
}
diff --git a/core/resource.h b/core/resource.h
index f0c86631cc..8bcdd6b4b7 100644
--- a/core/resource.h
+++ b/core/resource.h
@@ -87,7 +87,7 @@ public:
class Resource : public Reference {
-
+
OBJ_TYPE( Resource, Reference );
OBJ_CATEGORY("Resources");
RES_BASE_EXTENSION("res");
@@ -95,8 +95,8 @@ class Resource : public Reference {
Set<ObjectID> owners;
friend class ResBase;
-friend class ResourceCache;
-
+friend class ResourceCache;
+
String name;
String path_cache;
int subindex;
@@ -109,7 +109,7 @@ friend class ResourceCache;
#endif
protected:
-
+
void emit_changed();
void notify_change_to_owners();
@@ -120,7 +120,7 @@ protected:
void _set_path(const String& p_path);
void _take_over_path(const String& p_path);
public:
-
+
virtual bool can_reload_from_file();
virtual void reload_from_file();
@@ -151,7 +151,7 @@ public:
virtual RID get_rid() const; // some resources may offer conversion to RID
- Resource();
+ Resource();
~Resource();
};
@@ -160,11 +160,11 @@ public:
typedef Ref<Resource> RES;
class ResourceCache {
-friend class Resource;
- static HashMap<String,Resource*> resources;
+friend class Resource;
+ static HashMap<String,Resource*> resources;
friend void unregister_core_types();
static void clear();
-public:
+public:
static void reload_externals();
static bool has(const String& p_path);
diff --git a/core/rid.h b/core/rid.h
index 85ae1b15d3..2de6956096 100644
--- a/core/rid.h
+++ b/core/rid.h
@@ -44,19 +44,19 @@ class RID_OwnerBase;
typedef uint32_t ID;
-class RID {
-friend class RID_OwnerBase;
+class RID {
+friend class RID_OwnerBase;
ID _id;
RID_OwnerBase *owner;
public:
_FORCE_INLINE_ ID get_id() const { return _id; }
bool operator==(const RID& p_rid) const {
-
+
return _id==p_rid._id;
}
_FORCE_INLINE_ bool operator<(const RID& p_rid) const {
-
+
return _id < p_rid._id;
}
_FORCE_INLINE_ bool operator<=(const RID& p_rid) const {
@@ -64,11 +64,11 @@ public:
return _id <= p_rid._id;
}
_FORCE_INLINE_ bool operator>(const RID& p_rid) const {
-
+
return _id > p_rid._id;
}
bool operator!=(const RID& p_rid) const {
-
+
return _id!=p_rid._id;
}
_FORCE_INLINE_ bool is_valid() const { return _id>0; }
@@ -91,7 +91,7 @@ friend class RID;
void set_ownage(RID& p_rid) const { p_rid.owner=const_cast<RID_OwnerBase*>(this); }
ID new_ID();
public:
-
+
virtual bool owns(const RID& p_rid) const=0;
virtual void get_owned_list(List<RID> *p_owned) const=0;
@@ -105,67 +105,67 @@ class RID_Owner : public RID_OwnerBase {
public:
typedef void (*ReleaseNotifyFunc)(void*user,T *p_data);
-private:
+private:
Mutex *mutex;
mutable HashMap<ID,T*> id_map;
-
+
public:
RID make_rid(T * p_data) {
-
+
if (thread_safe) {
mutex->lock();
}
-
+
ID id = new_ID();
id_map[id]=p_data;
RID rid;
set_id(rid,id);
set_ownage(rid);
-
+
if (thread_safe) {
mutex->unlock();
}
-
+
return rid;
}
-
+
_FORCE_INLINE_ T * get(const RID& p_rid) {
-
+
if (thread_safe) {
mutex->lock();
}
-
+
T**elem = id_map.getptr(p_rid.get_id());
-
+
if (thread_safe) {
mutex->unlock();
}
ERR_FAIL_COND_V(!elem,NULL);
-
+
return *elem;
}
-
+
virtual bool owns(const RID& p_rid) const {
-
+
if (thread_safe) {
mutex->lock();
}
-
+
T**elem = id_map.getptr(p_rid.get_id());
-
+
if (thread_safe) {
mutex->lock();
}
-
+
return elem!=NULL;
}
-
- virtual void free(RID p_rid) {
-
+
+ virtual void free(RID p_rid) {
+
if (thread_safe) {
mutex->lock();
}
@@ -173,40 +173,40 @@ public:
id_map.erase(p_rid.get_id());
}
virtual void get_owned_list(List<RID> *p_owned) const {
-
+
if (thread_safe) {
mutex->lock();
}
-
+
const ID*id=NULL;
while((id=id_map.next(id))) {
-
+
RID rid;
set_id(rid,*id);
set_ownage(rid);
p_owned->push_back(rid);
-
+
}
-
+
if (thread_safe) {
mutex->lock();
}
}
RID_Owner() {
-
+
if (thread_safe) {
-
+
mutex = Mutex::create();
}
-
+
}
-
-
+
+
~RID_Owner() {
-
+
if (thread_safe) {
-
+
memdelete(mutex);
}
}
diff --git a/core/ring_buffer.h b/core/ring_buffer.h
index 4658ec5e51..7d78fac660 100644
--- a/core/ring_buffer.h
+++ b/core/ring_buffer.h
@@ -38,21 +38,21 @@ class RingBuffer {
int read_pos;
int write_pos;
int size_mask;
-
+
inline int inc(int& p_var, int p_size) {
int ret = p_var;
p_var += p_size;
p_var = p_var&size_mask;
return ret;
};
-
+
public:
T read() {
ERR_FAIL_COND_V(space_left() < 1, T());
return data[inc(read_pos, 1)];
};
-
+
int read(T* p_buf, int p_size, bool p_advance=true) {
int left = data_left();
p_size = MIN(left, p_size);
@@ -76,7 +76,7 @@ public:
};
int copy(T* p_buf, int p_offset, int p_size) {
-
+
int left = data_left();
if ((p_offset+p_size)>left) {
p_size-=left-p_offset;
@@ -106,18 +106,18 @@ public:
inc(read_pos, p_n);
return p_n;
};
-
+
Error write(const T& p_v) {
ERR_FAIL_COND_V( space_left() < 1, FAILED);
data[inc(write_pos, 1)] = p_v;
return OK;
};
-
+
int write(const T* p_buf, int p_size) {
-
+
int left = space_left();
p_size = MIN(left, p_size);
-
+
int pos = write_pos;
int to_write = p_size;
int src = 0;
@@ -126,7 +126,7 @@ public:
int end = pos + to_write;
end = MIN(end, size());
int total = end - pos;
-
+
for (int i=0; i<total; i++) {
data[pos+i] = p_buf[src++];
};
@@ -137,7 +137,7 @@ public:
inc(write_pos, p_size);
return p_size;
};
-
+
inline int space_left() {
int left = read_pos - write_pos;
if (left < 0) {
@@ -151,7 +151,7 @@ public:
inline int data_left() {
return size() - space_left() - 1;
};
-
+
inline int size() {
return data.size();
};
@@ -161,7 +161,7 @@ public:
write_pos = 0;
}
-
+
void resize(int p_power) {
int old_size = size();
int new_size = 1<<p_power;
@@ -176,10 +176,10 @@ public:
read_pos = read_pos & mask;
write_pos = write_pos & mask;
};
-
+
size_mask = mask;
};
-
+
RingBuffer<T>(int p_power=0) {
read_pos = 0;
write_pos = 0;
diff --git a/core/safe_refcount.cpp b/core/safe_refcount.cpp
index 7718e466f2..9736f96f34 100644
--- a/core/safe_refcount.cpp
+++ b/core/safe_refcount.cpp
@@ -40,9 +40,9 @@ long atomic_conditional_increment( register long * pw ) {
while (true) {
long tmp = static_cast< long const volatile& >( *pw );
- if( tmp == 0 )
+ if( tmp == 0 )
return 0; // if zero, can't add to it anymore
- if( InterlockedCompareExchange( pw, tmp + 1, tmp ) == tmp )
+ if( InterlockedCompareExchange( pw, tmp + 1, tmp ) == tmp )
return tmp+1;
}
diff --git a/core/safe_refcount.h b/core/safe_refcount.h
index e5dc854c23..d976458c1d 100644
--- a/core/safe_refcount.h
+++ b/core/safe_refcount.h
@@ -42,15 +42,15 @@ struct SafeRefCount {
int count;
public:
-
+
// destroy() is called when weak_count_ drops to zero.
-
+
bool ref() { //true on success
-
+
if (count==0)
return false;
count++;
-
+
return true;
}
@@ -66,17 +66,17 @@ public:
if (count>0)
count--;
-
+
return count==0;
}
-
+
long get() const { // nothrow
-
+
return static_cast<int const volatile &>( count );
}
-
+
void init(int p_value=1) {
-
+
count=p_value;
};
@@ -105,9 +105,9 @@ static inline int atomic_conditional_increment( volatile int * pw ) {
// int rv = *pw;
// if( rv != 0 ) ++*pw;
// return rv;
-
+
int rv, tmp;
-
+
__asm__
(
"movl %0, %%eax\n\t"
@@ -124,22 +124,22 @@ static inline int atomic_conditional_increment( volatile int * pw ) {
"m"( *pw ): // input (%3)
"cc" // clobbers
);
-
+
return rv;
}
static inline int atomic_decrement( volatile int *pw) {
-
+
// return --(*pw);
-
+
unsigned char rv;
-
+
__asm__
(
"lock\n\t"
"decl %0\n\t"
- "setne %1":
- "=m" (*pw), "=qm" (rv):
+ "setne %1":
+ "=m" (*pw), "=qm" (rv):
"m" (*pw):
"memory"
);
@@ -266,15 +266,15 @@ inline long atomic_conditional_increment( register long * pw )
asm
{
loop:
-
+
lwarx a, 0, pw
cmpwi a, 0
beq store
-
+
addi a, a, 1
-
+
store:
-
+
stwcx. a, 0, pw
bne- loop
}
@@ -288,16 +288,16 @@ inline long atomic_decrement( register long * pw )
register int a;
asm {
-
+
sync
-
+
loop:
-
+
lwarx a, 0, pw
addi a, a, -1
stwcx. a, 0, pw
bne- loop
-
+
isync
}
@@ -338,11 +338,11 @@ struct SafeRefCount {
REFCOUNT_T count;
public:
-
+
// destroy() is called when weak_count_ drops to zero.
-
+
bool ref() { //true on success
-
+
return atomic_conditional_increment( &count ) != 0;
}
@@ -356,17 +356,17 @@ public:
if( atomic_decrement ( &count ) == 0 ) {
return true;
}
-
+
return false;
}
-
+
long get() const { // nothrow
-
+
return static_cast<REFCOUNT_GET_T>( count );
}
-
+
void init(int p_value=1) {
-
+
count=p_value;
};
@@ -376,4 +376,4 @@ public:
#endif // no thread safe
-#endif
+#endif
diff --git a/core/script_language.cpp b/core/script_language.cpp
index 0eac39e7d1..1503418269 100644
--- a/core/script_language.cpp
+++ b/core/script_language.cpp
@@ -61,26 +61,26 @@ void ScriptServer::set_scripting_enabled(bool p_enabled) {
}
bool ScriptServer::is_scripting_enabled() {
-
+
return scripting_enabled;
}
int ScriptServer::get_language_count() {
-
+
return _language_count;
-
+
}
ScriptLanguage* ScriptServer::get_language(int p_idx) {
ERR_FAIL_INDEX_V(p_idx,_language_count,NULL);
-
+
return _languages[p_idx];
}
void ScriptServer::register_language(ScriptLanguage *p_language) {
-
+
ERR_FAIL_COND( _language_count >= MAX_LANGUAGES );
_languages[_language_count++]=p_language;
}
diff --git a/core/script_language.h b/core/script_language.h
index 7e278b8555..1be1aabdab 100644
--- a/core/script_language.h
+++ b/core/script_language.h
@@ -40,15 +40,15 @@ class ScriptLanguage;
class ScriptServer {
enum {
-
+
MAX_LANGUAGES=4
};
-
+
static ScriptLanguage *_languages[MAX_LANGUAGES];
static int _language_count;
static bool scripting_enabled;
-public:
-
+public:
+
static void set_scripting_enabled(bool p_enabled);
static bool is_scripting_enabled();
static int get_language_count();
@@ -76,14 +76,14 @@ protected:
friend class PlaceHolderScriptInstance;
virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder) {}
public:
-
+
virtual bool can_instance() const=0;
virtual StringName get_instance_base_type() const=0; // this may not work in all scripts, will return empty if so
virtual ScriptInstance* instance_create(Object *p_this)=0;
virtual bool instance_has(const Object *p_this) const=0;
-
+
virtual bool has_source_code() const=0;
virtual String get_source_code() const=0;
virtual void set_source_code(const String& p_code)=0;
@@ -102,7 +102,7 @@ public:
virtual void update_exports() {} //editor tool
-
+
Script() {}
};
@@ -148,13 +148,13 @@ class ScriptLanguage {
public:
virtual String get_name() const=0;
-
+
/* LANGUAGE FUNCTIONS */
- virtual void init()=0;
+ virtual void init()=0;
virtual String get_type() const=0;
virtual String get_extension() const=0;
- virtual Error execute_file(const String& p_path) =0;
- virtual void finish()=0;
+ virtual Error execute_file(const String& p_path) =0;
+ virtual void finish()=0;
/* EDITOR FUNCTIONS */
virtual void get_reserved_words(List<String> *p_words) const=0;
@@ -197,7 +197,7 @@ public:
virtual void frame();
- virtual ~ScriptLanguage() {};
+ virtual ~ScriptLanguage() {};
};
extern uint8_t script_encryption_key[32];
diff --git a/core/set.h b/core/set.h
index 808ffe5b36..d4d19129d4 100644
--- a/core/set.h
+++ b/core/set.h
@@ -42,16 +42,16 @@
template <class T,class C=Comparator<T>,class A=DefaultAllocator >
class Set {
-
- enum Color {
+
+ enum Color {
RED,
BLACK
};
- struct _Data;
+ struct _Data;
public:
-
-
+
+
class Element {
private:
@@ -72,18 +72,18 @@ public:
return _next;
}
Element *next() {
-
+
return _next;
}
const Element *prev() const {
-
+
return _prev;
}
Element *prev() {
-
+
return _prev;
}
- const T& get() const {
+ const T& get() const {
return value;
};
Element() {
@@ -96,7 +96,7 @@ public:
};
};
-
+
private:
struct _Data {
@@ -104,7 +104,7 @@ private:
Element* _root;
Element* _nil;
int size_cache;
-
+
_Data() {
#ifdef GLOBALNIL_DISABLED
@@ -119,7 +119,7 @@ private:
size_cache=0;
}
-
+
void _create_root() {
_root = memnew_allocator( Element,A );
@@ -136,7 +136,7 @@ private:
}
~_Data() {
-
+
_free_root();
#ifdef GLOBALNIL_DISABLED
memdelete_allocator<Element,A>(_nil);
@@ -144,16 +144,16 @@ private:
// memdelete_allocator<Element,A>(_root);
}
};
-
+
_Data _data;
-
+
inline void _set_color(Element *p_node, int p_color) {
-
+
ERR_FAIL_COND( p_node == _data._nil && p_color == RED );
p_node->color=p_color;
}
inline void _rotate_left(Element *p_node) {
-
+
Element *r=p_node->right;
p_node->right=r->left;
if (r->left != _data._nil )
@@ -163,14 +163,14 @@ private:
p_node->parent->left=r;
else
p_node->parent->right=r;
-
+
r->left=p_node;
p_node->parent=r;
-
+
}
-
+
inline void _rotate_right(Element *p_node) {
-
+
Element *l=p_node->left;
p_node->left=l->right;
if (l->right != _data._nil)
@@ -180,25 +180,25 @@ private:
p_node->parent->right=l;
else
p_node->parent->left=l;
-
+
l->right=p_node;
p_node->parent=l;
-
+
}
-
- inline Element* _successor(Element *p_node) const {
-
+
+ inline Element* _successor(Element *p_node) const {
+
Element *node=p_node;
-
+
if (node->right != _data._nil) {
-
+
node=node->right;
while(node->left != _data._nil) { /* returns the minium of the right subtree of node */
node=node->left;
}
return node;
} else {
-
+
while(node == node->parent->right) {
node=node->parent;
}
@@ -207,19 +207,19 @@ private:
return node->parent;
}
}
-
- inline Element* _predecessor(Element *p_node) const {
+
+ inline Element* _predecessor(Element *p_node) const {
Element *node=p_node;
-
+
if (node->left != _data._nil) {
-
+
node=node->left;
while(node->right != _data._nil) { /* returns the minium of the left subtree of node */
node=node->right;
}
return node;
} else {
-
+
while(node == node->parent->left) {
if (node->parent == _data._root)
return NULL;
@@ -229,23 +229,23 @@ private:
return node->parent;
}
}
-
-
+
+
Element *_find(const T& p_value) const {
-
+
Element *node = _data._root->left;
- C less;
-
+ C less;
+
while(node!=_data._nil) {
-
- if (less(p_value,node->value))
+
+ if (less(p_value,node->value))
node=node->left;
else if (less(node->value,p_value))
node=node->right;
else
break; // found
}
-
+
return (node!=_data._nil)?node:NULL;
}
@@ -282,68 +282,68 @@ private:
Element *_insert(const T& p_value, bool& r_exists) {
-
+
Element *new_parent=_data._root;
Element *node = _data._root->left;
- C less;
-
+ C less;
+
while (node!=_data._nil) {
-
+
new_parent=node;
-
+
if (less(p_value,node->value))
node=node->left;
else if (less(node->value,p_value))
node=node->right;
- else {
+ else {
r_exists=true;
return node;
- }
+ }
}
-
+
Element *new_node = memnew_allocator( Element,A );
-
+
new_node->parent=new_parent;
new_node->right=_data._nil;
new_node->left=_data._nil;
new_node->value=p_value;
// new_node->data=_data;
if (new_parent==_data._root || less(p_value,new_parent->value)) {
-
+
new_parent->left=new_node;
} else {
new_parent->right=new_node;
}
-
+
r_exists=false;
-
+
new_node->_next=_successor(new_node);
new_node->_prev=_predecessor(new_node);
if (new_node->_next)
new_node->_next->_prev=new_node;
if (new_node->_prev)
new_node->_prev->_next=new_node;
-
+
return new_node;
}
-
+
Element * _insert_rb(const T& p_value) {
-
+
bool exists=false;
Element *new_node = _insert(p_value,exists);
if (exists)
return new_node;
-
+
Element *node=new_node;
_data.size_cache++;
- while(node->parent->color==RED) {
-
+ while(node->parent->color==RED) {
+
if (node->parent == node->parent->parent->left) {
-
+
Element *aux=node->parent->parent->right;
-
+
if (aux->color==RED) {
_set_color(node->parent,BLACK);
_set_color(aux,BLACK);
@@ -357,10 +357,10 @@ private:
_set_color(node->parent,BLACK);
_set_color(node->parent->parent,RED);
_rotate_right(node->parent->parent);
- }
- } else {
+ }
+ } else {
Element *aux=node->parent->parent->left;
-
+
if (aux->color==RED) {
_set_color(node->parent,BLACK);
_set_color(aux,BLACK);
@@ -374,19 +374,19 @@ private:
_set_color(node->parent,BLACK);
_set_color(node->parent->parent,RED);
_rotate_left(node->parent->parent);
- }
+ }
}
}
_set_color(_data._root->left,BLACK);
- return new_node;
- }
+ return new_node;
+ }
void _erase_fix(Element *p_node) {
-
+
Element *root = _data._root->left;
Element *node=p_node;
-
-
+
+
while( (node->color==BLACK) && (root != node)) {
if (node == node->parent->left) {
Element *aux=node->parent->right;
@@ -396,7 +396,7 @@ private:
_rotate_left(node->parent);
aux=node->parent->right;
}
- if ( (aux->right->color==BLACK) && (aux->left->color==BLACK) ) {
+ if ( (aux->right->color==BLACK) && (aux->left->color==BLACK) ) {
_set_color(aux,RED);
node=node->parent;
} else {
@@ -420,7 +420,7 @@ private:
_rotate_right(node->parent);
aux=node->parent->left;
}
- if ( (aux->right->color==BLACK) && (aux->left->color==BLACK) ) {
+ if ( (aux->right->color==BLACK) && (aux->left->color==BLACK) ) {
_set_color(aux,RED);
node=node->parent;
} else {
@@ -434,24 +434,24 @@ private:
_set_color(node->parent,BLACK);
_set_color(aux->left,BLACK);
_rotate_right(node->parent);
- node=root;
+ node=root;
}
}
}
-
+
_set_color(node,BLACK);
-
+
ERR_FAIL_COND(_data._nil->color!=BLACK);
}
-
+
void _erase(Element *p_node) {
-
-
+
+
Element *rp= ((p_node->left == _data._nil) || (p_node->right == _data._nil)) ? p_node : _successor(p_node);
if (!rp)
rp=_data._nil;
Element *node= (rp->left == _data._nil) ? rp->right : rp->left;
-
+
if (_data._root == (node->parent=rp->parent) ) {
_data._root->left=node;
} else {
@@ -461,47 +461,47 @@ private:
rp->parent->right=node;
}
}
-
- if (rp != p_node) {
-
+
+ if (rp != p_node) {
+
ERR_FAIL_COND( rp == _data._nil );
-
+
if (rp->color==BLACK)
_erase_fix(node);
-
-
+
+
rp->left=p_node->left;
rp->right=p_node->right;
rp->parent=p_node->parent;
rp->color=p_node->color;
p_node->left->parent=rp;
p_node->right->parent=rp;
-
+
if (p_node == p_node->parent->left) {
- p_node->parent->left=rp;
+ p_node->parent->left=rp;
} else {
p_node->parent->right=rp;
}
} else {
- if (p_node->color==BLACK)
+ if (p_node->color==BLACK)
_erase_fix(node);
-
+
}
-
-
+
+
if (p_node->_next)
p_node->_next->_prev=p_node->_prev;
if (p_node->_prev)
p_node->_prev->_next=p_node->_next;
-
+
memdelete_allocator<Element,A>(p_node);
_data.size_cache--;
ERR_FAIL_COND( _data._nil->color==RED );
}
-
-
+
+
void _calculate_depth(Element *p_element,int &max_d,int d) const {
-
+
if (p_element==_data._nil) {
return;
}
@@ -510,30 +510,30 @@ private:
if (d>max_d)
max_d=d;
}
-
+
void _cleanup_tree(Element *p_element) {
-
+
if (p_element==_data._nil)
return;
-
+
_cleanup_tree(p_element->left);
_cleanup_tree(p_element->right);
memdelete_allocator<Element,A>( p_element );
}
-
+
void _copy_from( const Set& p_set) {
-
+
clear();
// not the fastest way, but safeset to write.
for(Element *I=p_set.front();I;I=I->next()) {
-
+
insert(I->get());
}
}
public:
const Element *find(const T& p_value) const {
-
+
if (!_data._root)
return NULL;
@@ -542,30 +542,30 @@ public:
}
Element *find(const T& p_value) {
-
+
if (!_data._root)
return NULL;
Element *res=_find(p_value);
return res;
}
-
+
bool has(const T& p_value) const {
-
+
if (!_data._root)
return false;
return find(p_value)!=NULL;
}
-
+
Element *insert(const T& p_value) {
-
+
if (!_data._root)
_data._create_root();
return _insert_rb(p_value);
-
+
}
-
+
void erase(Element* p_element) {
-
+
if (!_data._root)
return;
_erase(p_element);
@@ -574,7 +574,7 @@ public:
}
bool erase(const T& p_value) {
-
+
if (!_data._root)
return false;
Element *e=find(p_value);
@@ -585,32 +585,32 @@ public:
_data._free_root();
return true;
}
-
+
Element *front() const {
-
+
if (!_data._root)
return NULL;
Element *e=_data._root->left;
if (e==_data._nil)
return NULL;
-
+
while(e->left!=_data._nil)
e=e->left;
-
+
return e;
}
-
+
Element *back() const {
-
+
if (!_data._root)
return NULL;
Element *e=_data._root->left;
if (e==_data._nil)
return NULL;
-
+
while(e->right!=_data._nil)
e=e->right;
-
+
return e;
}
@@ -619,7 +619,7 @@ public:
return _lower_bound(p_value);
}
-
+
inline int size() const { return _data.size_cache; }
int calculate_depth() const {
// used for debug mostly
@@ -629,9 +629,9 @@ public:
_calculate_depth(_data._root->left,max_d,0);
return max_d;
}
-
+
void clear() {
-
+
if (!_data._root)
return;
@@ -641,25 +641,25 @@ public:
_data._nil->parent=_data._nil;
_data._free_root();
}
-
+
void operator=(const Set& p_set) {
-
+
_copy_from( p_set );
}
-
+
Set(const Set& p_set) {
-
+
_copy_from( p_set );
}
_FORCE_INLINE_ Set() {
-
+
}
-
-
+
+
~Set() {
-
- clear();
+
+ clear();
}
};
diff --git a/core/simple_type.h b/core/simple_type.h
index 1cc597146e..1754deec71 100644
--- a/core/simple_type.h
+++ b/core/simple_type.h
@@ -33,61 +33,61 @@
template<class T>
struct GetSimpleType {
-
+
T type;
};
template<class T>
struct GetSimpleTypeT {
-
+
typedef T type_t;
};
template<class T>
struct GetSimpleType<T&> {
-
+
T type;
-
+
};
template<class T>
struct GetSimpleTypeT<T&> {
-
+
typedef T type_t;
};
template<class T>
struct GetSimpleType<T const> {
-
+
T type;
_FORCE_INLINE_ GetSimpleType() { }
-
+
};
template<class T>
struct GetSimpleTypeT<T const> {
-
+
typedef T type_t;
};
template<class T>
struct GetSimpleType<const T&> {
-
+
T type;
_FORCE_INLINE_ GetSimpleType() { }
-
+
};
template<class T>
struct GetSimpleType<T*> {
-
+
T *type;
_FORCE_INLINE_ GetSimpleType() { type=NULL; }
};
template<class T>
struct GetSimpleType<const T*> {
-
+
T *type;
_FORCE_INLINE_ GetSimpleType() { type=NULL; }
};
diff --git a/core/sort.h b/core/sort.h
index bd61921c8a..2070065a0d 100644
--- a/core/sort.h
+++ b/core/sort.h
@@ -44,7 +44,7 @@ template<class T, class Comparator=_DefaultComparator<T> >
class SortArray {
enum {
-
+
INTROSORT_TRESHOLD=16
};
@@ -54,7 +54,7 @@ public:
inline const T& median_of_3(const T& a, const T& b, const T& c) const {
-
+
if (compare(a, b))
if (compare(b, c))
return b;
@@ -69,90 +69,90 @@ public:
else
return b;
}
-
-
+
+
inline int bitlog(int n) const {
int k;
- for (k = 0; n != 1; n >>= 1)
+ for (k = 0; n != 1; n >>= 1)
++k;
return k;
}
-
-
+
+
/* Heap / Heapsort functions */
-
+
inline void push_heap(int p_first,int p_hole_idx,int p_top_index,T p_value,T* p_array) const {
-
+
int parent = (p_hole_idx - 1) / 2;
while (p_hole_idx > p_top_index && compare(p_array[p_first + parent], p_value)) {
-
+
p_array[p_first + p_hole_idx] = p_array[p_first + parent];
p_hole_idx = parent;
parent = (p_hole_idx - 1) / 2;
}
- p_array[p_first + p_hole_idx] = p_value;
- }
-
+ p_array[p_first + p_hole_idx] = p_value;
+ }
+
inline void pop_heap(int p_first, int p_last, int p_result, T p_value, T* p_array) const {
-
+
p_array[p_result]=p_array[p_first];
adjust_heap(p_first,0,p_last-p_first,p_value,p_array);
}
inline void pop_heap(int p_first,int p_last,T* p_array) const {
-
+
pop_heap(p_first,p_last-1,p_last-1,p_array[p_last-1],p_array);
}
-
+
inline void adjust_heap(int p_first,int p_hole_idx,int p_len,T p_value,T* p_array) const {
-
-
+
+
int top_index = p_hole_idx;
int second_child = 2 * p_hole_idx + 2;
-
+
while (second_child < p_len) {
-
+
if (compare(p_array[p_first + second_child],p_array[p_first + (second_child - 1)]))
second_child--;
-
+
p_array[p_first + p_hole_idx] = p_array[p_first + second_child];
p_hole_idx = second_child;
second_child = 2 * (second_child + 1);
}
-
+
if (second_child == p_len) {
p_array[p_first + p_hole_idx] = p_array[p_first + (second_child - 1)];
p_hole_idx = second_child - 1;
}
push_heap(p_first, p_hole_idx, top_index, p_value,p_array);
}
-
+
inline void sort_heap(int p_first,int p_last,T* p_array) const {
-
+
while(p_last-p_first > 1) {
-
+
pop_heap(p_first,p_last--,p_array);
}
}
-
+
inline void make_heap(int p_first, int p_last,T* p_array) const {
- if (p_last - p_first < 2)
+ if (p_last - p_first < 2)
return;
int len = p_last - p_first;
int parent = (len - 2)/2;
-
+
while (true) {
adjust_heap(p_first, parent, len, p_array[p_first + parent], p_array);
- if (parent == 0)
+ if (parent == 0)
return;
parent--;
}
}
-
+
inline void partial_sort(int p_first,int p_last,int p_middle,T* p_array) const {
-
+
make_heap(p_first,p_middle,p_array);
- for(int i=p_middle;i<p_last;i++)
+ for(int i=p_middle;i<p_last;i++)
if (compare( p_array[i],p_array[p_first]))
pop_heap(p_first,p_middle,i,p_array[i],p_array);
sort_heap(p_first,p_middle,p_array);
@@ -167,17 +167,17 @@ public:
}
inline int partitioner(int p_first, int p_last, T p_pivot, T* p_array) const {
-
+
while (true) {
- while (compare(p_array[p_first],p_pivot))
+ while (compare(p_array[p_first],p_pivot))
p_first++;
p_last--;
while (compare(p_pivot,p_array[p_last]))
p_last--;
-
+
if (!(p_first < p_last))
return p_first;
-
+
SWAP(p_array[p_first],p_array[p_last]);
p_first++;
}
@@ -186,28 +186,28 @@ public:
inline void introsort(int p_first, int p_last, T* p_array, int p_max_depth) const {
while( p_last - p_first > INTROSORT_TRESHOLD ) {
-
+
if (p_max_depth == 0) {
partial_sort(p_first,p_last,p_last,p_array);
return;
}
-
+
p_max_depth--;
-
- int cut = partitioner(
- p_first,
- p_last,
- median_of_3(
- p_array[p_first],
- p_array[p_first + (p_last-p_first)/2],
+
+ int cut = partitioner(
+ p_first,
+ p_last,
+ median_of_3(
+ p_array[p_first],
+ p_array[p_first + (p_last-p_first)/2],
p_array[p_last-1]
),
p_array
);
-
+
introsort(cut,p_last,p_array,p_max_depth);
p_last=cut;
-
+
}
}
@@ -245,7 +245,7 @@ public:
}
inline void unguarded_linear_insert(int p_last,T p_value,T* p_array) const {
-
+
int next = p_last-1;
while (compare(p_value,p_array[next])) {
p_array[p_last]=p_array[next];
@@ -254,48 +254,48 @@ public:
}
p_array[p_last] = p_value;
}
-
+
inline void linear_insert(int p_first,int p_last,T*p_array) const {
-
+
T val = p_array[p_last];
if (compare(val, p_array[p_first])) {
-
+
for (int i=p_last; i>p_first; i--)
p_array[i]=p_array[i-1];
-
+
p_array[p_first] = val;
} else
- unguarded_linear_insert(p_last, val, p_array);
+ unguarded_linear_insert(p_last, val, p_array);
}
-
+
inline void insertion_sort(int p_first,int p_last,T* p_array) const {
-
+
if (p_first==p_last)
return;
for (int i=p_first+1; i!=p_last ; i++)
linear_insert(p_first,i,p_array);
}
-
+
inline void unguarded_insertion_sort(int p_first,int p_last,T* p_array) const {
-
+
for (int i=p_first; i!=p_last ; i++)
unguarded_linear_insert(i,p_array[i],p_array);
}
-
+
inline void final_insertion_sort(int p_first,int p_last,T* p_array) const {
-
+
if (p_last - p_first > INTROSORT_TRESHOLD) {
insertion_sort(p_first,p_first+INTROSORT_TRESHOLD,p_array);
unguarded_insertion_sort(p_first+INTROSORT_TRESHOLD,p_last,p_array);
} else {
-
+
insertion_sort(p_first,p_last,p_array);
-
- }
+
+ }
}
inline void sort_range(int p_first, int p_last,T* p_array) const {
-
+
if (p_first != p_last) {
introsort(p_first, p_last,p_array,bitlog(p_last - p_first) * 2);
final_insertion_sort(p_first, p_last, p_array);
@@ -303,7 +303,7 @@ public:
}
inline void sort(T* p_array,int p_len) const {
-
+
sort_range(0,p_len,p_array);
}
diff --git a/core/string_db.cpp b/core/string_db.cpp
index 0e953cc326..9a693f88e9 100644
--- a/core/string_db.cpp
+++ b/core/string_db.cpp
@@ -43,23 +43,23 @@ StringName _scs_create(const char *p_chr) {
bool StringName::configured=false;
void StringName::setup() {
-
+
ERR_FAIL_COND(configured);
for(int i=0;i<STRING_TABLE_LEN;i++) {
-
+
_table[i]=NULL;
}
configured=true;
}
void StringName::cleanup() {
-
- _global_lock();
+
+ _global_lock();
int lost_strings=0;
for(int i=0;i<STRING_TABLE_LEN;i++) {
-
+
while(_table[i]) {
-
+
_Data*d=_table[i];
lost_strings++;
if (OS::get_singleton()->is_stdout_verbose()) {
@@ -71,23 +71,23 @@ void StringName::cleanup() {
}
}
- _table[i]=_table[i]->next;
+ _table[i]=_table[i]->next;
memdelete(d);
}
}
if (OS::get_singleton()->is_stdout_verbose() && lost_strings) {
print_line("StringName: "+itos(lost_strings)+" unclaimed string names at exit.");
}
- _global_unlock();
+ _global_unlock();
}
void StringName::unref() {
-
+
ERR_FAIL_COND(!configured);
if (_data && _data->refcount.unref()) {
-
- _global_lock();
+
+ _global_lock();
if (_data->prev) {
_data->prev->next=_data->next;
@@ -97,26 +97,26 @@ void StringName::unref() {
}
_table[_data->idx]=_data->next;
}
-
+
if (_data->next) {
_data->next->prev=_data->prev;
}
memdelete(_data);
- _global_unlock();
+ _global_unlock();
}
-
+
_data=NULL;
-
+
}
bool StringName::operator==(const String& p_name) const {
-
+
if (!_data) {
-
+
return (p_name.length()==0);
}
-
+
return (_data->get_name()==p_name);
}
@@ -131,50 +131,50 @@ bool StringName::operator==(const char* p_name) const {
}
bool StringName::operator!=(const String& p_name) const {
-
+
return !(operator==(p_name));
}
bool StringName::operator!=(const StringName& p_name) const {
-
- // the real magic of all this mess happens here.
+
+ // the real magic of all this mess happens here.
// this is why path comparisons are very fast
return _data!=p_name._data;
-
+
}
void StringName::operator=(const StringName& p_name) {
-
+
if (this==&p_name)
return;
-
+
unref();
-
+
if (p_name._data && p_name._data->refcount.ref()) {
-
- _data = p_name._data;
+
+ _data = p_name._data;
}
}
/* was inlined
StringName::operator String() const {
-
+
if (_data)
return _data->get_name();
-
+
return "";
}
*/
StringName::StringName(const StringName& p_name) {
-
+
ERR_FAIL_COND(!configured);
_data=NULL;
if (p_name._data && p_name._data->refcount.ref()) {
-
- _data = p_name._data;
- }
+
+ _data = p_name._data;
+ }
}
StringName::StringName(const char *p_name) {
@@ -184,17 +184,17 @@ StringName::StringName(const char *p_name) {
ERR_FAIL_COND(!configured);
ERR_FAIL_COND( !p_name || !p_name[0]);
-
- _global_lock();
-
+
+ _global_lock();
+
uint32_t hash = String::hash(p_name);
-
+
uint32_t idx=hash&STRING_TABLE_MASK;
-
+
_data=_table[idx];
-
+
while(_data) {
-
+
// compare hash first
if (_data->hash==hash && _data->get_name()==p_name)
break;
@@ -226,7 +226,7 @@ StringName::StringName(const char *p_name) {
_global_unlock();
-
+
}
StringName::StringName(const StaticCString& p_static_string) {
@@ -268,7 +268,7 @@ StringName::StringName(const StaticCString& p_static_string) {
_data->refcount.init();
_data->hash=hash;
- _data->idx=idx;
+ _data->idx=idx;
_data->cname=p_static_string.ptr;
_data->next=_table[idx];
_data->prev=NULL;
@@ -283,26 +283,26 @@ StringName::StringName(const StaticCString& p_static_string) {
StringName::StringName(const String& p_name) {
-
+
_data=NULL;
ERR_FAIL_COND(!configured);
- _global_lock();
-
+ _global_lock();
+
uint32_t hash = p_name.hash();
-
+
uint32_t idx=hash&STRING_TABLE_MASK;
_data=_table[idx];
-
+
while(_data) {
-
+
if (_data->hash==hash && _data->get_name()==p_name)
break;
_data=_data->next;
}
-
+
if (_data) {
if (_data->refcount.ref()) {
@@ -329,7 +329,7 @@ StringName::StringName(const String& p_name) {
_table[idx]=_data;
_global_unlock();
-
+
}
StringName StringName::search(const char *p_name) {
@@ -435,12 +435,12 @@ StringName StringName::search(const String &p_name) {
StringName::StringName() {
-
+
_data=NULL;
}
StringName::~StringName() {
-
+
unref();
}
diff --git a/core/string_db.h b/core/string_db.h
index f6c6ecefec..43bcccc902 100644
--- a/core/string_db.h
+++ b/core/string_db.h
@@ -46,16 +46,16 @@ struct StaticCString {
class StringName {
-
+
enum {
-
+
STRING_TABLE_BITS=12,
STRING_TABLE_LEN=1<<STRING_TABLE_BITS,
STRING_TABLE_MASK=STRING_TABLE_LEN-1
};
-
- struct _Data {
+
+ struct _Data {
SafeRefCount refcount;
const char* cname;
String name;
@@ -67,32 +67,32 @@ class StringName {
_Data *next;
_Data() { cname=NULL; next=prev=NULL; hash=0; }
};
-
-
+
+
static _Data *_table[STRING_TABLE_LEN];
-
+
_Data *_data;
-
+
union _HashUnion {
-
+
_Data *ptr;
uint32_t hash;
};
-
+
void unref();
friend void register_core_types();
friend void unregister_core_types();
-
+
static void setup();
static void cleanup();
static bool configured;
-
+
StringName(_Data *p_data) { _data=p_data; }
public:
operator const void*() const { return (_data && (_data->cname || !_data->name.empty()))?(void*)1:0; }
-
+
bool operator==(const String& p_name) const;
bool operator==(const char* p_name) const;
bool operator!=(const String& p_name) const;
@@ -101,19 +101,19 @@ public:
return _data<p_name._data;
}
_FORCE_INLINE_ bool operator==(const StringName& p_name) const {
- // the real magic of all this mess happens here.
+ // the real magic of all this mess happens here.
// this is why path comparisons are very fast
return _data==p_name._data;
- }
+ }
_FORCE_INLINE_ uint32_t hash() const {
-
+
if (_data)
return _data->hash;
else
return 0;
}
bool operator!=(const StringName& p_name) const;
-
+
_FORCE_INLINE_ operator String() const {
if (_data) {
@@ -148,7 +148,7 @@ public:
};
struct StringNameHasher {
-
+
static _FORCE_INLINE_ uint32_t hash(const StringName &p_string) { return p_string.hash(); }
};
diff --git a/core/typedefs.h b/core/typedefs.h
index eab0ebc545..5047644692 100644
--- a/core/typedefs.h
+++ b/core/typedefs.h
@@ -270,7 +270,7 @@ void _global_lock();
void _global_unlock();
struct _GlobalLock {
-
+
_GlobalLock() { _global_lock(); }
~_GlobalLock() { _global_unlock(); }
};
diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp
index ecbda1d3fd..d6d32ccaef 100644
--- a/core/undo_redo.cpp
+++ b/core/undo_redo.cpp
@@ -239,7 +239,7 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E) {
case Operation::TYPE_METHOD: {
- obj->call(op.name,VARIANT_ARGS_FROM_ARRAY(op.args));
+ obj->call(op.name,VARIANT_ARGS_FROM_ARRAY(op.args));
#ifdef TOOLS_ENABLED
Resource* res = obj->cast_to<Resource>();
if (res)
@@ -450,10 +450,10 @@ void UndoRedo::_bind_methods() {
ObjectTypeDB::bind_method(_MD("create_action","name","mergeable"),&UndoRedo::create_action, DEFVAL(false) );
ObjectTypeDB::bind_method(_MD("commit_action"),&UndoRedo::commit_action);
-
+
//ObjectTypeDB::bind_method(_MD("add_do_method","p_object", "p_method", "VARIANT_ARG_LIST"),&UndoRedo::add_do_method);
//ObjectTypeDB::bind_method(_MD("add_undo_method","p_object", "p_method", "VARIANT_ARG_LIST"),&UndoRedo::add_undo_method);
-
+
{
MethodInfo mi;
mi.name="add_do_method";
diff --git a/core/ustring.cpp b/core/ustring.cpp
index 1017fc0ca3..a9d0012ebe 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -67,14 +67,14 @@ void String::copy_from(const char *p_cstr) {
len++;
if (len==0) {
-
+
resize(0);
return;
}
-
+
resize(len+1); // include 0
-
+
CharType *dst = this->ptr();
for (int i=0;i<len+1;i++) {
@@ -85,35 +85,35 @@ void String::copy_from(const char *p_cstr) {
}
void String::copy_from(const CharType* p_cstr, int p_clip_to) {
-
+
int len=0;
const CharType *ptr=p_cstr;
while (*(ptr++)!=0)
len++;
-
+
if (p_clip_to>=0 && len>p_clip_to)
len=p_clip_to;
-
+
if (len==0) {
-
+
resize(0);
return;
}
-
+
resize(len+1);
set(len,0);
-
+
CharType *dst = &operator[](0);
-
-
+
+
for (int i=0;i<len;i++) {
-
+
dst[i]=p_cstr[i];
}
}
void String::copy_from(const CharType& p_char) {
-
+
resize(2);
set(0,p_char);
set(1,0);
@@ -126,12 +126,12 @@ bool String::operator==(const String& p_str) const {
return false;
if (empty())
return true;
-
+
int l=length();
-
+
const CharType *src = c_str();
const CharType *dst = p_str.c_str();
-
+
/* Compare char by char */
for (int i=0;i<l;i++) {
@@ -170,19 +170,19 @@ String& String::operator+=(const String &p_str) {
*this=p_str;
return *this;
}
-
+
if (p_str.empty())
return *this;
-
+
int from=length();
-
+
resize( length() + p_str.size() );
-
+
const CharType *src = p_str.c_str();
CharType *dst = &operator[](0);
set( length(), 0 );
-
+
for (int i=0;i<p_str.length();i++)
dst[from+i]=src[i];
@@ -200,11 +200,11 @@ String& String::operator+=(const CharType *p_str) {
String& String::operator+=(CharType p_char) {
-
+
resize( size() ? size() + 1 : 2);
set( length(), 0 );
set( length() -1, p_char );
-
+
return *this;
}
@@ -220,13 +220,13 @@ String& String::operator+=(const char * p_str) {
src_len++;
int from=length();
-
+
resize( from + src_len + 1 );
-
+
CharType *dst = &operator[](0);
-
+
set( length(), 0 );
-
+
for (int i=0;i<src_len;i++)
dst[from+i]=p_str[i];
@@ -283,11 +283,11 @@ bool String::operator==(const char *p_str) const {
return false;
if (empty())
return true;
-
+
int l=length();
-
+
const CharType *dst = c_str();
-
+
/* Compare char by char */
for (int i=0;i<l;i++) {
@@ -312,11 +312,11 @@ bool String::operator==(const CharType *p_str) const {
return false;
if (empty())
return true;
-
+
int l=length();
-
+
const CharType *dst = c_str();
-
+
/* Compare char by char */
for (int i=0;i<l;i++) {
@@ -347,8 +347,8 @@ bool String::operator<(const CharType *p_str) const {
return false;
if (empty())
return true;
-
-
+
+
const CharType *this_str=c_str();
while (true) {
@@ -382,7 +382,7 @@ bool String::operator<(const char *p_str) const {
return false;
if (empty())
return true;
-
+
const CharType *this_str=c_str();
while (true) {
@@ -412,7 +412,7 @@ bool String::operator<(String p_str) const {
return operator<(p_str.c_str());
}
-signed char String::nocasecmp_to(const String &p_str) const {
+signed char String::nocasecmp_to(const String &p_str) const {
if (empty() && p_str.empty())
return 0;
@@ -423,7 +423,7 @@ signed char String::nocasecmp_to(const String &p_str) const {
const CharType *that_str=p_str.c_str();
const CharType *this_str=c_str();
-
+
while (true) {
if (*that_str==0 && *this_str==0)
@@ -445,7 +445,7 @@ signed char String::nocasecmp_to(const String &p_str) const {
}
-signed char String::casecmp_to(const String &p_str) const {
+signed char String::casecmp_to(const String &p_str) const {
if (empty() && p_str.empty())
return 0;
@@ -456,7 +456,7 @@ signed char String::casecmp_to(const String &p_str) const {
const CharType *that_str=p_str.c_str();
const CharType *this_str=c_str();
-
+
while (true) {
if (*that_str==0 && *this_str==0)
@@ -493,17 +493,17 @@ String String::capitalize() const {
String aux=this->replace("_"," ").to_lower();
String cap;
for (int i=0;i<aux.get_slice_count(" ");i++) {
-
+
String slice=aux.get_slicec(' ',i);
if (slice.length()>0) {
-
+
slice[0]=_find_upper(slice[0]);
if (i>0)
cap+=" ";
cap+=slice;
}
}
-
+
return cap;
}
@@ -542,7 +542,7 @@ int String::get_slice_count(String p_splitter) const{
return 0;
if (p_splitter.empty())
return 0;
-
+
int pos=0;
int slices=1;
@@ -559,7 +559,7 @@ String String::get_slice(String p_splitter, int p_slice) const {
if (empty() || p_splitter.empty())
return "";
-
+
int pos=0;
int prev_pos=0;
// int slices=1;
@@ -844,7 +844,7 @@ int String::length() const {
const CharType * String::c_str() const {
static const CharType zero=0;
-
+
return size()?&operator[](0):&zero;
}
@@ -867,10 +867,10 @@ String String::md5(const uint8_t *p_md5) {
}
String String::chr(CharType p_char) {
-
+
CharType c[2]={p_char,0};
return String(c);
-
+
}
String String::num(double p_num,int p_decimals) {
@@ -1014,7 +1014,7 @@ String String::num(double p_num,int p_decimals) {
String decimal;
for (int i=0;i<digit;i++) {
-
+
char num[2]={0,0};
num[0]='0'+dec_int%10;
decimal=num+decimal;
@@ -1200,10 +1200,10 @@ CharString String::ascii(bool p_allow_extended) const {
CharString cs;
cs.resize(size());
-
+
for (int i=0;i<size();i++)
cs[i]=operator[](i);
-
+
return cs;
}
@@ -1608,7 +1608,7 @@ int String::to_int() const {
integer+=c-'0';
} else if (integer==0 && c=='-') {
-
+
sign=-sign;
}
@@ -2207,14 +2207,14 @@ double String::to_double() const {
double exp=0;
double exp_sign=1.0;
int reading=READING_SIGN;
-
+
const CharType *str=&operator[](0);
while(*str && reading!=READING_DONE) {
-
+
CharType c=*(str++);
switch(reading) {
- case READING_SIGN: {
+ case READING_SIGN: {
if (c>='0' && c<='9')
reading=READING_INT;
// let it fallthrough
@@ -2228,26 +2228,26 @@ double String::to_double() const {
} else {
break;
}
- }
+ }
case READING_INT: {
-
+
if (c>='0' && c<='9') {
-
+
integer*=10;
- integer+=c-'0';
- } else if (c=='.') {
+ integer+=c-'0';
+ } else if (c=='.') {
reading=READING_DEC;
} else if (c=='e') {
reading=READING_EXP;
} else {
reading=READING_DONE;
}
-
+
} break;
case READING_DEC: {
-
+
if (c>='0' && c<='9') {
-
+
decimal+=(c-'0')*decimal_mult;
decimal_mult*=0.1;
} else if (c=='e') {
@@ -2255,12 +2255,12 @@ double String::to_double() const {
} else {
reading=READING_DONE;
}
-
+
} break;
case READING_EXP: {
-
+
if (c>='0' && c<='9') {
-
+
exp*=10.0;
exp+=(c-'0');
} else if (c=='-' && exp==0) {
@@ -2274,14 +2274,14 @@ double String::to_double() const {
} break;
}
}
-
+
return sign*(integer+decimal)*Math::pow(10,exp_sign*exp);
#endif
#if 0
double ret=sign*(integer+decimal)*Math::pow(10,exp_sign*exp);
-
+
print_line(*this +" == "+rtos(ret));
return ret;
#endif
@@ -2308,14 +2308,14 @@ String operator+(CharType p_chr, const String& p_str) {
}
uint32_t String::hash(const char* p_cstr) {
-
+
uint32_t hashv = 5381;
uint32_t c;
-
+
while ((c = *p_cstr++))
hashv = ((hashv << 5) + hashv) + c; /* hash * 33 + c */
-
- return hashv;
+
+ return hashv;
}
uint32_t String::hash(const char* p_cstr,int p_len) {
@@ -2348,19 +2348,19 @@ uint32_t String::hash(const CharType* p_cstr) {
}
uint32_t String::hash() const {
-
+
/* simple djb2 hashing */
-
+
const CharType * chr = c_str();
uint32_t hashv = 5381;
uint32_t c;
-
+
while ((c = *chr++))
hashv = ((hashv << 5) + hashv) + c; /* hash * 33 + c */
-
+
return hashv;
-
-
+
+
}
uint64_t String::hash64() const {
@@ -2442,16 +2442,16 @@ String String::substr(int p_from,int p_chars) const{
}
int String::find_last(String p_str) const {
-
+
int pos=-1;
int findfrom=0;
int findres=-1;
while((findres=find(p_str,findfrom))!=-1) {
-
+
pos=findres;
findfrom=pos+1;
}
-
+
return pos;
}
int String::find(String p_str,int p_from) const {
@@ -2708,48 +2708,48 @@ bool String::ends_with(const String& p_string) const {
}
bool String::begins_with(const String& p_string) const {
-
+
if (p_string.length() > length())
return false;
-
+
int l=p_string.length();
if (l==0)
return true;
-
+
const CharType *src=&p_string[0];
const CharType *str=&operator[](0);
-
+
int i = 0;
for (;i<l;i++) {
-
+
if (src[i]!=str[i])
return false;
}
-
+
// only if i == l the p_string matches the beginning
return i == l;
-
+
}
bool String::begins_with(const char* p_string) const {
-
+
int l=length();
if (l==0||!p_string)
return false;
-
+
const CharType *str=&operator[](0);
int i=0;
-
+
while (*p_string && i<l) {
-
+
if (*p_string != str[i])
return false;
i++;
p_string++;
-
+
}
-
+
return *p_string == 0;
-
+
}
@@ -2762,27 +2762,27 @@ static bool _wildcard_match(const CharType* p_pattern, const CharType* p_string,
case '?' :
return *p_string && (*p_string != '.') && _wildcard_match(p_pattern+1, p_string+1,p_case_sensitive);
default :
-
+
return (p_case_sensitive?(*p_string==*p_pattern):(_find_upper(*p_string)==_find_upper(*p_pattern))) && _wildcard_match(p_pattern+1, p_string+1,p_case_sensitive);
- }
+ }
}
bool String::match(const String& p_wildcard) const {
-
+
if (!p_wildcard.length() || !length())
return false;
-
+
return _wildcard_match(p_wildcard.c_str(),c_str(),true);
}
bool String::matchn(const String& p_wildcard) const {
-
+
if (!p_wildcard.length() || !length())
return false;
return _wildcard_match(p_wildcard.c_str(),c_str(),false);
-
+
}
String String::replace(String p_key,String p_with) const {
@@ -2854,7 +2854,7 @@ String String::right(int p_pos) const {
if (p_pos>=size())
return *this;
-
+
if (p_pos<0)
return "";
@@ -2868,26 +2868,26 @@ CharType String::ord_at(int p_idx) const {
}
String String::strip_edges() const {
-
+
int len=length();
int beg=0,end=len;
-
+
for (int i=0;i<length();i++) {
-
+
if (operator[](i)<=32)
beg++;
else
break;
}
-
+
for (int i=(int)(length()-1);i>=0;i--) {
-
+
if (operator[](i)<=32)
end--;
else
break;
}
-
+
if (beg==0 && end==len)
return *this;
@@ -3012,7 +3012,7 @@ String String::humanize_size(size_t p_size) {
int digits=prefix_idx>0?_humanize_digits(p_size/_div):0;
double divisor = prefix_idx>0?_div:1;
-
+
return String::num(p_size/divisor,digits)+prefix[prefix_idx];
}
bool String::is_abs_path() const {
@@ -3587,12 +3587,12 @@ String String::get_file() const {
}
String String::extension() const {
-
+
int pos = find_last(".");
if (pos<0)
return *this;
-
- return substr( pos+1, length() );
+
+ return substr( pos+1, length() );
}
String String::plus_file(const String& p_file) const {
@@ -3749,7 +3749,7 @@ String String::sprintf(const Array& values, bool* error) const {
if (!values[value_index].is_num()) {
return "a number is required";
}
-
+
int64_t value = values[value_index];
int base;
bool capitalize = false;
@@ -3811,7 +3811,7 @@ String String::sprintf(const Array& values, bool* error) const {
formatted += str;
++value_index;
in_format = false;
-
+
break;
}
case 's': { // String
diff --git a/core/ustring.h b/core/ustring.h
index e65103ff99..6310d0a854 100644
--- a/core/ustring.h
+++ b/core/ustring.h
@@ -40,7 +40,7 @@
class CharString : public Vector<char> {
-public:
+public:
int length() const { return size() ? size()-1 : 0; }
const char *get_data() const;
operator const char*() {return get_data();};
@@ -120,7 +120,7 @@ public:
bool match(const String& p_wildcard) const;
bool matchn(const String& p_wildcard) const;
bool begins_with(const String& p_string) const;
- bool begins_with(const char* p_string) const;
+ bool begins_with(const char* p_string) const;
bool ends_with(const String& p_string) const;
String replace_first(String p_key,String p_with) const;
String replace(String p_key,String p_with) const;
@@ -182,17 +182,17 @@ public:
CharString utf8() const;
bool parse_utf8(const char* p_utf8,int p_len=-1); //return true on error
static String utf8(const char* p_utf8,int p_len=-1);
-
+
static uint32_t hash(const CharType* p_str,int p_len); /* hash the string */
static uint32_t hash(const CharType* p_str); /* hash the string */
static uint32_t hash(const char* p_cstr,int p_len); /* hash the string */
static uint32_t hash(const char* p_cstr); /* hash the string */
uint32_t hash() const; /* hash the string */
- uint64_t hash64() const; /* hash the string */
+ uint64_t hash64() const; /* hash the string */
String md5_text() const;
Vector<uint8_t> md5_buffer() const;
- inline bool empty() const { return length() == 0; }
+ inline bool empty() const { return length() == 0; }
// path functions
bool is_abs_path() const;
@@ -213,7 +213,7 @@ public:
String c_unescape() const;
String json_escape() const;
String world_wrap(int p_chars_per_line) const;
-
+
String percent_encode() const;
String percent_decode() const;
@@ -247,9 +247,9 @@ String rtoss(double p_val); //scientific version
struct NoCaseComparator {
-
+
bool operator()(const String& p_a, const String& p_b) const {
-
+
return p_a.nocasecmp_to(p_b)<0;
}
};
diff --git a/core/variant.cpp b/core/variant.cpp
index 1fdbc9f753..527a0d238f 100644
--- a/core/variant.cpp
+++ b/core/variant.cpp
@@ -37,7 +37,7 @@
String Variant::get_type_name(Variant::Type p_type) {
-
+
switch( p_type ) {
case NIL: {
@@ -297,7 +297,7 @@ bool Variant::can_convert(Variant::Type p_type_from,Variant::Type p_type_to) {
valid_types=valid;
- } break;
+ } break;
case COLOR: {
@@ -948,52 +948,52 @@ bool Variant::is_one() const {
void Variant::reference(const Variant& p_variant) {
-
+
if (this == &p_variant)
return;
-
+
clear();
-
+
type=p_variant.type;
-
+
switch( p_variant.type ) {
case NIL: {
-
+
// none
} break;
-
- // atomic types
+
+ // atomic types
case BOOL: {
-
+
_data._bool=p_variant._data._bool;
} break;
case INT: {
-
+
_data._int=p_variant._data._int;
-
+
} break;
case REAL: {
-
+
_data._real=p_variant._data._real;
-
+
} break;
case STRING: {
-
+
memnew_placement( _data._mem, String( *reinterpret_cast<const String*>(p_variant._data._mem) ) );
-
+
} break;
-
+
// math types
-
+
case VECTOR2: {
-
+
memnew_placement( _data._mem, Vector2( *reinterpret_cast<const Vector2*>(p_variant._data._mem) ) );
-
+
} break;
case RECT2: {
-
+
memnew_placement( _data._mem, Rect2( *reinterpret_cast<const Rect2*>(p_variant._data._mem) ) );
-
+
} break;
case MATRIX32: {
@@ -1001,100 +1001,100 @@ void Variant::reference(const Variant& p_variant) {
} break;
case VECTOR3: {
-
+
memnew_placement( _data._mem, Vector3( *reinterpret_cast<const Vector3*>(p_variant._data._mem) ) );
-
+
} break;
case PLANE: {
-
+
memnew_placement( _data._mem, Plane( *reinterpret_cast<const Plane*>(p_variant._data._mem) ) );
-
+
} break;
-/*
+/*
case QUAT: {
-
-
+
+
} break;*/
case _AABB: {
-
+
_data._aabb = memnew( AABB( *p_variant._data._aabb ) );
} break;
case QUAT: {
-
+
memnew_placement( _data._mem, Quat( *reinterpret_cast<const Quat*>(p_variant._data._mem) ) );
-
+
} break;
case MATRIX3: {
-
+
_data._matrix3 = memnew( Matrix3( *p_variant._data._matrix3 ) );
-
+
} break;
case TRANSFORM: {
-
+
_data._transform = memnew( Transform( *p_variant._data._transform ) );
-
+
} break;
-
- // misc types
+
+ // misc types
case COLOR: {
-
+
memnew_placement( _data._mem, Color( *reinterpret_cast<const Color*>(p_variant._data._mem) ) );
-
+
} break;
case IMAGE: {
-
+
_data._image = memnew( Image( *p_variant._data._image ) );
-
+
} break;
case _RID: {
-
+
memnew_placement( _data._mem, RID( *reinterpret_cast<const RID*>(p_variant._data._mem) ) );
} break;
case OBJECT: {
-
+
memnew_placement( _data._mem, ObjData( p_variant._get_obj() ) );
} break;
case NODE_PATH: {
-
+
memnew_placement( _data._mem, NodePath( *reinterpret_cast<const NodePath*>(p_variant._data._mem) ) );
-
+
} break;
case INPUT_EVENT: {
-
+
_data._input_event= memnew( InputEvent( *p_variant._data._input_event ) );
-
+
} break;
case DICTIONARY: {
-
+
memnew_placement( _data._mem, Dictionary( *reinterpret_cast<const Dictionary*>(p_variant._data._mem) ) );
-
+
} break;
case ARRAY: {
-
+
memnew_placement( _data._mem, Array ( *reinterpret_cast<const Array*>(p_variant._data._mem) ) );
-
+
} break;
-
+
// arrays
case RAW_ARRAY: {
-
+
memnew_placement( _data._mem, DVector<uint8_t> ( *reinterpret_cast<const DVector<uint8_t>*>(p_variant._data._mem) ) );
-
+
} break;
case INT_ARRAY: {
-
+
memnew_placement( _data._mem, DVector<int> ( *reinterpret_cast<const DVector<int>*>(p_variant._data._mem) ) );
-
+
} break;
case REAL_ARRAY: {
-
+
memnew_placement( _data._mem, DVector<real_t> ( *reinterpret_cast<const DVector<real_t>*>(p_variant._data._mem) ) );
-
+
} break;
case STRING_ARRAY: {
-
+
memnew_placement( _data._mem, DVector<String> ( *reinterpret_cast<const DVector<String>*>(p_variant._data._mem) ) );
-
+
} break;
case VECTOR2_ARRAY: {
@@ -1102,17 +1102,17 @@ void Variant::reference(const Variant& p_variant) {
} break;
case VECTOR3_ARRAY: {
-
+
memnew_placement( _data._mem, DVector<Vector3> ( *reinterpret_cast<const DVector<Vector3>*>(p_variant._data._mem) ) );
-
+
} break;
case COLOR_ARRAY: {
-
+
memnew_placement( _data._mem, DVector<Color> ( *reinterpret_cast<const DVector<Color>*>(p_variant._data._mem) ) );
-
+
} break;
default: {}
- }
+ }
}
@@ -1135,7 +1135,7 @@ void Variant::clear() {
switch(type) {
case STRING: {
-
+
reinterpret_cast<String*>(_data._mem)->~String();
} break;
/*
@@ -1153,33 +1153,33 @@ void Variant::clear() {
} break;
case _AABB: {
-
+
memdelete( _data._aabb );
-
+
} break;
case MATRIX3: {
-
+
memdelete( _data._matrix3 );
} break;
case TRANSFORM: {
-
+
memdelete( _data._transform );
-
+
} break;
-
- // misc types
+
+ // misc types
case IMAGE: {
-
+
memdelete( _data._image );
-
+
} break;
case NODE_PATH: {
-
+
reinterpret_cast<NodePath*>(_data._mem)->~NodePath();
-
+
} break;
case OBJECT: {
-
+
_get_obj().obj=NULL;
_get_obj().ref.unref();
} break;
@@ -1188,41 +1188,41 @@ void Variant::clear() {
reinterpret_cast<RID*>(_data._mem)->~RID();
} break;
case DICTIONARY: {
-
+
reinterpret_cast<Dictionary*>(_data._mem)->~Dictionary();
-
+
} break;
case ARRAY: {
-
+
reinterpret_cast<Array*>(_data._mem)->~Array();
-
+
} break;
case INPUT_EVENT: {
-
+
memdelete( _data._input_event );
-
+
} break;
-
+
// arrays
case RAW_ARRAY: {
-
+
reinterpret_cast< DVector<uint8_t>* >(_data._mem)->~DVector<uint8_t>();
-
+
} break;
case INT_ARRAY: {
-
+
reinterpret_cast< DVector<int>* >(_data._mem)->~DVector<int>();
-
+
} break;
case REAL_ARRAY: {
-
+
reinterpret_cast< DVector<real_t>* >(_data._mem)->~DVector<real_t>();
-
+
} break;
case STRING_ARRAY: {
-
+
reinterpret_cast< DVector<String>* >(_data._mem)->~DVector<String>();
-
+
} break;
case VECTOR2_ARRAY: {
@@ -1230,55 +1230,55 @@ void Variant::clear() {
} break;
case VECTOR3_ARRAY: {
-
+
reinterpret_cast< DVector<Vector3>* >(_data._mem)->~DVector<Vector3>();
-
+
} break;
case COLOR_ARRAY: {
-
+
reinterpret_cast< DVector<Color>* >(_data._mem)->~DVector<Color>();
-
+
} break;
default: {} /* not needed */
}
-
+
type=NIL;
}
-
+
Variant::operator signed int() const {
switch( type ) {
-
- case NIL: return 0;
+
+ case NIL: return 0;
case BOOL: return _data._bool ? 1 : 0;
case INT: return _data._int;
case REAL: return _data._real;
case STRING: return operator String().to_int();
default: {
-
+
return 0;
- }
+ }
}
-
+
return 0;
}
Variant::operator unsigned int() const {
switch( type ) {
-
- case NIL: return 0;
+
+ case NIL: return 0;
case BOOL: return _data._bool ? 1 : 0;
case INT: return _data._int;
case REAL: return _data._real;
case STRING: return operator String().to_int();
default: {
-
+
return 0;
- }
+ }
}
-
+
return 0;
}
@@ -1380,69 +1380,69 @@ Variant::operator unsigned long() const {
Variant::operator signed short() const {
switch( type ) {
-
- case NIL: return 0;
+
+ case NIL: return 0;
case BOOL: return _data._bool ? 1 : 0;
case INT: return _data._int;
case REAL: return _data._real;
case STRING: return operator String().to_int();
default: {
-
+
return 0;
- }
+ }
}
-
+
return 0;
}
Variant::operator unsigned short() const {
switch( type ) {
-
- case NIL: return 0;
+
+ case NIL: return 0;
case BOOL: return _data._bool ? 1 : 0;
case INT: return _data._int;
case REAL: return _data._real;
case STRING: return operator String().to_int();
default: {
-
+
return 0;
- }
+ }
}
-
+
return 0;
}
Variant::operator signed char() const {
switch( type ) {
-
- case NIL: return 0;
+
+ case NIL: return 0;
case BOOL: return _data._bool ? 1 : 0;
case INT: return _data._int;
case REAL: return _data._real;
case STRING: return operator String().to_int();
default: {
-
+
return 0;
- }
+ }
}
-
+
return 0;
}
Variant::operator unsigned char() const {
switch( type ) {
-
- case NIL: return 0;
+
+ case NIL: return 0;
case BOOL: return _data._bool ? 1 : 0;
case INT: return _data._int;
case REAL: return _data._real;
case STRING: return operator String().to_int();
default: {
-
+
return 0;
- }
+ }
}
-
+
return 0;
}
#ifndef CHARTYPE_16BITS
@@ -1455,40 +1455,40 @@ Variant::operator CharType() const {
Variant::operator float() const {
switch( type ) {
-
- case NIL: return 0;
+
+ case NIL: return 0;
case BOOL: return _data._bool ? 1.0 : 0.0;
case INT: return (float)_data._int;
case REAL: return _data._real;
case STRING: return operator String().to_double();
default: {
-
+
return 0;
- }
+ }
}
-
+
return 0;
}
Variant::operator double() const {
switch( type ) {
-
- case NIL: return 0;
+
+ case NIL: return 0;
case BOOL: return _data._bool ? 1.0 : 0.0;
case INT: return (float)_data._int;
case REAL: return _data._real;
case STRING: return operator String().to_double();
default: {
-
+
return 0;
- }
+ }
}
-
+
return true;
}
Variant::operator StringName() const {
-
+
if (type==NODE_PATH) {
return reinterpret_cast<const NodePath*>(_data._mem)->get_sname();
}
@@ -1509,8 +1509,8 @@ struct _VariantStrPair {
Variant::operator String() const {
switch( type ) {
-
- case NIL: return "";
+
+ case NIL: return "";
case BOOL: return _data._bool ? "True" : "False";
case INT: return String::num(_data._int);
case REAL: return String::num(_data._real);
@@ -1520,7 +1520,7 @@ Variant::operator String() const {
case MATRIX32: return operator Matrix32();
case VECTOR3: return operator Vector3();
case PLANE: return operator Plane();
- //case QUAT:
+ //case QUAT:
case _AABB: return operator AABB();
case QUAT: return operator Quat();
case MATRIX3: return operator Matrix3();
@@ -1529,7 +1529,7 @@ Variant::operator String() const {
case INPUT_EVENT: return operator InputEvent();
case COLOR: return String::num( operator Color().r)+","+String::num( operator Color().g)+","+String::num( operator Color().b)+","+String::num( operator Color().a) ;
case DICTIONARY: {
-
+
const Dictionary &d =*reinterpret_cast<const Dictionary*>(_data._mem);
//const String *K=NULL;
String str;
@@ -1553,15 +1553,15 @@ Variant::operator String() const {
str+=", ";
str+="("+pairs[i].key+":"+pairs[i].value+")";
}
-
+
return str;
} break;
- case VECTOR3_ARRAY: {
-
+ case VECTOR3_ARRAY: {
+
DVector<Vector3> vec = operator DVector<Vector3>();
String str;
for(int i=0;i<vec.size();i++) {
-
+
if (i>0)
str+=", ";
str=str+Variant( vec[i] );
@@ -1634,9 +1634,9 @@ Variant::operator String() const {
} break;
default: {
return "["+get_type_name(type)+"]";
- }
+ }
}
-
+
return "";
}
@@ -1819,7 +1819,7 @@ Variant::operator Control*() const {
}
Variant::operator InputEvent() const {
-
+
if (type==INPUT_EVENT)
return *reinterpret_cast<const InputEvent*>(_data._input_event);
else
@@ -1827,8 +1827,8 @@ Variant::operator InputEvent() const {
}
Variant::operator Dictionary() const {
-
- if (type==DICTIONARY)
+
+ if (type==DICTIONARY)
return *reinterpret_cast<const Dictionary*>(_data._mem);
else
return Dictionary();
@@ -1869,10 +1869,10 @@ inline DA _convert_array_from_variant(const Variant& p_variant) {
}
Variant::operator Array() const {
-
- if (type==ARRAY)
+
+ if (type==ARRAY)
return *reinterpret_cast<const Array*>(_data._mem);
- else
+ else
return _convert_array_from_variant<Array >(*this);
}
@@ -2019,17 +2019,17 @@ Variant::operator Vector<Plane>() const {
}
Variant::operator Vector<Variant>() const {
-
+
Array from=operator Array();
Vector<Variant> to;
int len=from.size();
to.resize(len);
for (int i=0;i<len;i++) {
-
+
to[i]=from[i];
}
return to;
-
+
}
Variant::operator Vector<uint8_t>() const {
@@ -2039,7 +2039,7 @@ Variant::operator Vector<uint8_t>() const {
int len=from.size();
to.resize(len);
for (int i=0;i<len;i++) {
-
+
to[i]=from[i];
}
return to;
@@ -2051,7 +2051,7 @@ Variant::operator Vector<int>() const {
int len=from.size();
to.resize(len);
for (int i=0;i<len;i++) {
-
+
to[i]=from[i];
}
return to;
@@ -2063,7 +2063,7 @@ Variant::operator Vector<real_t>() const {
int len=from.size();
to.resize(len);
for (int i=0;i<len;i++) {
-
+
to[i]=from[i];
}
return to;
@@ -2076,7 +2076,7 @@ Variant::operator Vector<String>() const {
int len=from.size();
to.resize(len);
for (int i=0;i<len;i++) {
-
+
to[i]=from[i];
}
return to;
@@ -2093,7 +2093,7 @@ Variant::operator Vector<Vector3>() const {
DVector<Vector3>::Read r = from.read();
Vector3 *w = &to[0];
for (int i=0;i<len;i++) {
-
+
w[i]=r[i];
}
return to;
@@ -2168,16 +2168,16 @@ Variant::Variant(unsigned int p_int) {
#ifdef NEED_LONG_INT
Variant::Variant(signed long p_int) {
-
+
type=INT;
_data._int=p_int;
-
+
}
Variant::Variant(unsigned long p_int) {
-
+
type=INT;
_data._int=p_int;
-
+
}
#endif
@@ -2232,10 +2232,10 @@ Variant::Variant(double p_double) {
}
Variant::Variant(const StringName& p_string) {
-
+
type=STRING;
memnew_placement( _data._mem, String( p_string.operator String() ) );
-
+
}
Variant::Variant(const String& p_string) {
@@ -2335,9 +2335,9 @@ Variant::Variant(const NodePath& p_node_path) {
}
Variant::Variant(const InputEvent& p_input_event) {
-
+
type=INPUT_EVENT;
- _data._input_event = memnew( InputEvent(p_input_event) );
+ _data._input_event = memnew( InputEvent(p_input_event) );
}
@@ -2367,10 +2367,10 @@ Variant::Variant(const Object* p_object) {
}
Variant::Variant(const Dictionary& p_dictionary) {
-
+
type=DICTIONARY;
memnew_placement( _data._mem, (Dictionary)( p_dictionary) );
-
+
}
Variant::Variant(const Array& p_array) {
@@ -2382,15 +2382,15 @@ Variant::Variant(const Array& p_array) {
Variant::Variant(const DVector<Plane>& p_array) {
-
+
type=ARRAY;
Array *plane_array=memnew_placement( _data._mem, Array );
-
+
plane_array->resize( p_array.size() );
-
+
for (int i=0;i<p_array.size();i++) {
-
+
plane_array->operator [](i)=Variant(p_array[i]);
}
}
diff --git a/core/variant.h b/core/variant.h
index d8813c4937..ed33de6660 100644
--- a/core/variant.h
+++ b/core/variant.h
@@ -75,17 +75,17 @@ class Variant {
public:
enum Type {
-
- NIL,
-
- // atomic types
+
+ NIL,
+
+ // atomic types
BOOL,
INT,
REAL,
STRING,
-
+
// math types
-
+
VECTOR2, // 5
RECT2,
VECTOR3,
@@ -95,17 +95,17 @@ public:
_AABB, //sorry naming convention fail :( not like it's used often
MATRIX3,
TRANSFORM,
-
- // misc types
+
+ // misc types
COLOR,
IMAGE, // 15
NODE_PATH,
_RID,
- OBJECT,
+ OBJECT,
INPUT_EVENT,
DICTIONARY, // 20
ARRAY,
-
+
// arrays
RAW_ARRAY,
INT_ARRAY,
@@ -114,10 +114,10 @@ public:
VECTOR2_ARRAY,
VECTOR3_ARRAY,
COLOR_ARRAY,
-
+
VARIANT_MAX
-
- };
+
+ };
private:
@@ -125,7 +125,7 @@ private:
friend class _VariantCall;
// Variant takes 20 bytes when real_t is float, and 36 if double
// it only allocates extra memory for aabb/matrix.
-
+
Type type;
struct ObjData {
@@ -133,25 +133,25 @@ private:
Object *obj;
RefPtr ref;
};
-
+
_FORCE_INLINE_ ObjData& _get_obj();
_FORCE_INLINE_ const ObjData& _get_obj() const;
union {
-
+
bool _bool;
int _int;
double _real;
Matrix32 *_matrix32;
AABB* _aabb;
Matrix3 *_matrix3;
- Transform *_transform;
+ Transform *_transform;
RefPtr *_resource;
InputEvent *_input_event;
Image *_image;
void *_ptr; //generic pointer
-#ifdef USE_QUAD_VECTORS
+#ifdef USE_QUAD_VECTORS
uint8_t _mem[sizeof(ObjData) > (sizeof(real_t)*5) ? sizeof(ObjData) : (sizeof(real_t)*5)]; // plane uses an extra real
#else
uint8_t _mem[sizeof(ObjData) > (sizeof(real_t)*4) ? sizeof(ObjData) : (sizeof(real_t)*4)];
@@ -172,7 +172,7 @@ public:
template<class T>
static Type get_type_for() {
-
+
GetSimpleType<T> t;
Variant v(t.type);
Type r = v.get_type();
@@ -231,7 +231,7 @@ public:
operator Dictionary() const;
operator Array() const;
-
+
operator DVector<uint8_t>() const;
operator DVector<int>() const;
operator DVector<real_t>() const;
@@ -260,7 +260,7 @@ public:
operator IP_Address() const;
-
+
Variant(bool p_bool);
Variant(signed int p_int); // real one
Variant(unsigned int p_int);
@@ -286,8 +286,8 @@ public:
Variant(const Vector3& p_vector3);
Variant(const Plane& p_plane);
Variant(const AABB& p_aabb);
- Variant(const Quat& p_quat);
- Variant(const Matrix3& p_transform);
+ Variant(const Quat& p_quat);
+ Variant(const Matrix3& p_transform);
Variant(const Matrix32& p_transform);
Variant(const Transform& p_transform);
Variant(const Color& p_color);
@@ -295,10 +295,10 @@ public:
Variant(const NodePath& p_path);
Variant(const RefPtr& p_resource);
Variant(const RID& p_rid);
- Variant(const Object* p_object);
+ Variant(const Object* p_object);
Variant(const InputEvent& p_input_event);
Variant(const Dictionary& p_dictionary);
-
+
Variant(const Array& p_array);
Variant(const DVector<Plane>& p_array); // helper
Variant(const DVector<uint8_t>& p_raw_array);
@@ -309,7 +309,7 @@ public:
Variant(const DVector<Color>& p_color_array);
Variant(const DVector<Face3>& p_face_array);
-
+
Variant(const Vector<Variant>& p_array);
Variant(const Vector<uint8_t>& p_raw_array);
Variant(const Vector<int>& p_int_array);
diff --git a/core/variant_op.cpp b/core/variant_op.cpp
index 5463e1cabb..f03ab43fce 100644
--- a/core/variant_op.cpp
+++ b/core/variant_op.cpp
@@ -662,7 +662,7 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant&
case OP_DIVIDE: {
switch(p_a.type) {
- DEFAULT_OP_FAIL(NIL);
+ DEFAULT_OP_FAIL(NIL);
DEFAULT_OP_NUM(/,BOOL,_bool);
case INT: {
switch(p_b.type) {
@@ -779,7 +779,7 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant&
}
#endif
_RETURN( p_a._data._int % p_b._data._int );
-
+
} else if (p_a.type==STRING) {
const String* format=reinterpret_cast<const String*>(p_a._data._mem);
@@ -2409,7 +2409,7 @@ Variant Variant::get(const Variant& p_index, bool *r_valid) const {
} if (str=="value") {
valid=true;
return ie.joy_motion.axis_value;
- }
+ }
}
if (ie.type==InputEvent::SCREEN_TOUCH) {
@@ -3461,12 +3461,18 @@ void Variant::blend(const Variant& a, const Variant& b, float c, Variant &r_dst)
const Rect2 *rb = reinterpret_cast<const Rect2*>(b._data._mem);
r_dst=Rect2(ra->pos + rb->pos * c, ra->size + rb->size * c);
} return;
- case VECTOR3:{ r_dst=*reinterpret_cast<const Vector2*>(a._data._mem)+*reinterpret_cast<const Vector2*>(b._data._mem)*c; } return;
+ case VECTOR3:{ r_dst=*reinterpret_cast<const Vector3*>(a._data._mem)+*reinterpret_cast<const Vector3*>(b._data._mem)*c; } return;
case _AABB:{
const AABB *ra = reinterpret_cast<const AABB*>(a._data._mem);
const AABB *rb = reinterpret_cast<const AABB*>(b._data._mem);
r_dst=AABB(ra->pos + rb->pos * c, ra->size + rb->size * c);
} return;
+ case QUAT:{
+ Quat empty_rot;
+ const Quat *qa = reinterpret_cast<const Quat*>(a._data._mem);
+ const Quat *qb = reinterpret_cast<const Quat*>(b._data._mem);
+ r_dst=*qa * empty_rot.slerp(*qb,c);
+ } return;
case COLOR:{
const Color *ca = reinterpret_cast<const Color*>(a._data._mem);
const Color *cb = reinterpret_cast<const Color*>(b._data._mem);
diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp
index a3775156ac..8bd1fddfad 100644
--- a/core/variant_parser.cpp
+++ b/core/variant_parser.cpp
@@ -451,7 +451,7 @@ Error VariantParser::_parse_construct(Stream *p_stream,Vector<T>& r_construct,in
if (!first) {
get_token(p_stream,token,line,r_err_str);
if (token.type==TK_COMMA) {
- //do none
+ //do none
} else if (token.type==TK_PARENTHESIS_CLOSE) {
break;
} else {
@@ -1206,7 +1206,7 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
get_token(p_stream,token,line,r_err_str);
if (token.type!=TK_STRING) {
- r_err_str="Expected string";
+ r_err_str="Expected string";
return ERR_PARSE_ERROR;
}
@@ -1676,7 +1676,7 @@ Error VariantParser::_parse_tag(Token& token, Stream *p_stream, int &line, Strin
if (err)
return err;
- r_tag.fields[id]=value;
+ r_tag.fields[id]=value;
}
diff --git a/core/vector.h b/core/vector.h
index 398d7f1bd5..16a09c1ddd 100644
--- a/core/vector.h
+++ b/core/vector.h
@@ -43,30 +43,30 @@ template<class T>
class Vector {
mutable T* _ptr;
-
+
// internal helpers
-
+
_FORCE_INLINE_ SafeRefCount* _get_refcount() const {
-
+
if (!_ptr)
return NULL;
-
+
return reinterpret_cast<SafeRefCount*>((uint8_t*)_ptr-sizeof(int)-sizeof(SafeRefCount));
}
-
+
_FORCE_INLINE_ int* _get_size() const {
-
+
if (!_ptr)
return NULL;
return reinterpret_cast<int*>((uint8_t*)_ptr-sizeof(int));
-
+
}
_FORCE_INLINE_ T* _get_data() const {
-
+
if (!_ptr)
return NULL;
return reinterpret_cast<T*>(_ptr);
-
+
}
_FORCE_INLINE_ size_t _get_alloc_size(size_t p_elements) const {
@@ -88,9 +88,9 @@ class Vector {
return true;
#endif
}
-
+
void _unref(void *p_data);
-
+
void _copy_from(const Vector& p_from);
void _copy_on_write();
public:
@@ -101,18 +101,18 @@ public:
_FORCE_INLINE_ void clear() { resize(0); }
-
+
_FORCE_INLINE_ int size() const {
int* size = _get_size();
if (size)
return *size;
- else
+ else
return 0;
}
_FORCE_INLINE_ bool empty() const { return _ptr == 0; }
Error resize(int p_size);
bool push_back(T p_elem);
-
+
void remove(int p_index);
void erase(const T& p_val) { int idx = find(p_val); if (idx>=0) remove(idx); };
void invert();
@@ -132,7 +132,7 @@ public:
}
_copy_on_write(); // wants to write, so copy on write.
-
+
return _get_data()[p_index];
}
@@ -145,7 +145,7 @@ public:
// no cow needed, since it's reading
return _get_data()[p_index];
}
-
+
Error insert(int p_pos,const T& p_val);
template<class C>
@@ -188,21 +188,21 @@ void Vector<T>::_unref(void *p_data) {
if (!p_data)
return;
-
+
SafeRefCount *src = reinterpret_cast<SafeRefCount*>((uint8_t*)p_data-sizeof(int)-sizeof(SafeRefCount));
-
+
if (!src->unref())
return; // still in use
// clean up
-
+
int *count = (int*)(src+1);
T *data = (T*)(count+1);
-
+
for (int i=0;i<*count;i++) {
- // call destructors
+ // call destructors
data[i].~T();
}
-
+
// free mem
memfree((uint8_t*)p_data-sizeof(int)-sizeof(SafeRefCount));
@@ -213,7 +213,7 @@ void Vector<T>::_copy_on_write() {
if (!_ptr)
return;
-
+
if (_get_refcount()->get() > 1 ) {
/* in use by more than me */
void* mem_new = memalloc(_get_alloc_size(*_get_size()));
@@ -221,15 +221,15 @@ void Vector<T>::_copy_on_write() {
src_new->init();
int * _size = (int*)(src_new+1);
*_size=*_get_size();
-
+
T*_data=(T*)(_size+1);
-
+
// initialize new elements
for (int i=0;i<*_size;i++) {
-
+
memnew_placement(&_data[i], T( _get_data()[i] ) );
}
-
+
_unref(_ptr);
_ptr=_data;
}
@@ -240,11 +240,11 @@ template<class T> template<class T_val>
int Vector<T>::find(const T_val &p_val) const {
int ret = -1;
- if (size() == 0)
+ if (size() == 0)
return ret;
-
+
for (int i=0; i<size(); i++) {
-
+
if (operator[](i) == p_val) {
ret = i;
break;
@@ -261,17 +261,17 @@ Error Vector<T>::resize(int p_size) {
if (p_size==size())
return OK;
-
+
if (p_size==0) {
- // wants to clean up
+ // wants to clean up
_unref(_ptr);
_ptr=NULL;
return OK;
}
-
+
// possibly changing size, copy on write
_copy_on_write();
-
+
size_t alloc_size;
ERR_FAIL_COND_V(!_get_alloc_size_checked(p_size, &alloc_size), ERR_OUT_OF_MEMORY);
@@ -293,16 +293,16 @@ Error Vector<T>::resize(int p_size) {
// construct the newly created elements
T*elems = _get_data();
-
+
for (int i=*_get_size();i<p_size;i++) {
-
+
memnew_placement(&elems[i], T) ;
}
*_get_size()=p_size;
} else if (p_size<size()) {
-
+
// deinitialize no longer needed elements
for (int i=p_size;i<*_get_size();i++) {
@@ -312,11 +312,11 @@ Error Vector<T>::resize(int p_size) {
void *_ptrnew = (T*)memrealloc((uint8_t*)_ptr-sizeof(int)-sizeof(SafeRefCount), alloc_size);
ERR_FAIL_COND_V( !_ptrnew ,ERR_OUT_OF_MEMORY);
-
+
_ptr=(T*)((uint8_t*)_ptrnew+sizeof(int)+sizeof(SafeRefCount));
-
+
*_get_size()=p_size;
-
+
}
return OK;
@@ -325,9 +325,9 @@ Error Vector<T>::resize(int p_size) {
template<class T>
void Vector<T>::invert() {
-
+
for(int i=0;i<size()/2;i++) {
-
+
SWAP( operator[](i), operator[](size()-i-1) );
}
}
@@ -374,13 +374,13 @@ void Vector<T>::_copy_from(const Vector& p_from) {
if (_ptr == p_from._ptr)
return; // self assign, do nothing.
-
+
_unref(_ptr);
_ptr=NULL;
-
+
if (!p_from._ptr)
return; //nothing to do
-
+
if (p_from._get_refcount()->ref()) // could reference
_ptr=p_from._ptr;
@@ -395,13 +395,13 @@ void Vector<T>::operator=(const Vector& p_from) {
template<class T>
Error Vector<T>::insert(int p_pos,const T& p_val) {
-
+
ERR_FAIL_INDEX_V(p_pos,size()+1,ERR_INVALID_PARAMETER);
resize(size()+1);
for (int i=(size()-1);i>p_pos;i--)
set( i, get(i-1) );
set( p_pos, p_val );
-
+
return OK;
}