summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/bind/core_bind.cpp51
-rw-r--r--core/bind/core_bind.h3
-rw-r--r--core/hash_map.h15
-rw-r--r--core/hashfuncs.h4
-rw-r--r--core/math/geometry.h80
-rw-r--r--core/os/main_loop.h3
-rw-r--r--core/os/os.cpp4
-rw-r--r--core/os/os.h2
-rw-r--r--core/variant.cpp10
9 files changed, 154 insertions, 18 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index fd6a91d125..ec159da00f 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -479,10 +479,54 @@ void _OS::print_all_textures_by_size() {
print_line(E->get().path+" - "+String::humanize_size(E->get().vram)+" ("+E->get().size+") - total:"+String::humanize_size(total) );
total-=E->get().vram;
}
+}
+void _OS::print_resources_by_type(const Vector<String>& p_types) {
+ Map<String,int> type_count;
+
+ List<Ref<Resource> > resources;
+ ResourceCache::get_cached_resources(&resources);
+
+ List<Ref<Resource> > rsrc;
+ ResourceCache::get_cached_resources(&rsrc);
+
+ for (List<Ref<Resource> >::Element *E=rsrc.front();E;E=E->next()) {
+
+ Ref<Resource> r = E->get();
+
+ bool found = false;
+
+ for (int i=0; i<p_types.size(); i++) {
+ if (r->is_type(p_types[i]))
+ found = true;
+ }
+ if (!found)
+ continue;
+
+ if (!type_count.has(r->get_type())) {
+ type_count[r->get_type()]=0;
+ }
+
+
+ type_count[r->get_type()]++;
+
+ print_line(r->get_type()+": "+r->get_path());
+
+ List<String> metas;
+ r->get_meta_list(&metas);
+ for (List<String>::Element* me = metas.front(); me; me = me->next()) {
+ print_line(" "+String(me->get()) + ": " + r->get_meta(me->get()));
+ };
+ }
+
+ for(Map<String,int>::Element *E=type_count.front();E;E=E->next()) {
+
+ print_line(E->key()+" count: "+itos(E->get()));
+ }
+
+};
-}
void _OS::print_all_resources(const String& p_to_file ) {
@@ -509,9 +553,9 @@ float _OS::get_frames_per_second() const {
return OS::get_singleton()->get_frames_per_second();
}
-Error _OS::native_video_play(String p_path) {
+Error _OS::native_video_play(String p_path, float p_volume) {
- return OS::get_singleton()->native_video_play(p_path);
+ return OS::get_singleton()->native_video_play(p_path, p_volume);
};
bool _OS::native_video_is_playing() {
@@ -614,6 +658,7 @@ void _OS::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_frames_per_second"),&_OS::get_frames_per_second);
ObjectTypeDB::bind_method(_MD("print_all_textures_by_size"),&_OS::print_all_textures_by_size);
+ ObjectTypeDB::bind_method(_MD("print_resources_by_type"),&_OS::print_resources_by_type);
ObjectTypeDB::bind_method(_MD("native_video_play"),&_OS::native_video_play);
ObjectTypeDB::bind_method(_MD("native_video_is_playing"),&_OS::native_video_is_playing);
diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h
index f5c94dcf06..18eb594760 100644
--- a/core/bind/core_bind.h
+++ b/core/bind/core_bind.h
@@ -98,7 +98,7 @@ public:
bool is_video_mode_resizable(int p_screen=0) const;
Array get_fullscreen_mode_list(int p_screen=0) const;
- Error native_video_play(String p_path);
+ Error native_video_play(String p_path, float p_volume);
bool native_video_is_playing();
void native_video_pause();
void native_video_stop();
@@ -139,6 +139,7 @@ public:
void print_resources_in_use(bool p_short=false);
void print_all_resources(const String& p_to_file);
void print_all_textures_by_size();
+ void print_resources_by_type(const Vector<String>& p_types);
bool has_touchscreen_ui_hint() const;
diff --git a/core/hash_map.h b/core/hash_map.h
index 02a6600c3b..da8f038490 100644
--- a/core/hash_map.h
+++ b/core/hash_map.h
@@ -285,14 +285,12 @@ public:
}
void set( const Pair& p_pair ) {
-
+
+ Entry *e=NULL;
if (!hash_table)
make_hash_table(); // if no table, make one
else
- check_hash_table(); // perform mantenience routine
-
- /* As said, i want to have only one get_entry */
- Entry *e = const_cast<Entry*>( get_entry(p_pair.key) );
+ e = const_cast<Entry*>( get_entry(p_pair.key) );
/* if we made it up to here, the pair doesn't exist, create and assign */
@@ -301,6 +299,7 @@ public:
e=create_entry(p_pair.key);
if (!e)
return;
+ check_hash_table(); // perform mantenience routine
}
e->pair.data = p_pair.data;
@@ -478,12 +477,11 @@ public:
}
inline TData& operator[](const TKey& p_key ) { //assignment
+ Entry *e=NULL;
if (!hash_table)
make_hash_table(); // if no table, make one
else
- check_hash_table(); // perform mantenience routine
-
- Entry *e = const_cast<Entry*>( get_entry(p_key) );
+ e = const_cast<Entry*>( get_entry(p_key) );
/* if we made it up to here, the pair doesn't exist, create */
if (!e) {
@@ -491,6 +489,7 @@ public:
e=create_entry(p_key);
if (!e)
return *(TData*)NULL; /* panic! */
+ check_hash_table(); // perform mantenience routine
}
return e->pair.data;
diff --git a/core/hashfuncs.h b/core/hashfuncs.h
index 6dae82bc55..3b6715a4cd 100644
--- a/core/hashfuncs.h
+++ b/core/hashfuncs.h
@@ -54,9 +54,9 @@ static inline uint32_t hash_djb2(const char *p_cstr) {
return hash;
}
-static inline uint32_t hash_djb2_buffer(uint8_t *p_buff, int p_len) {
+static inline uint32_t hash_djb2_buffer(const uint8_t *p_buff, int p_len,uint32_t p_prev=5381) {
- uint32_t hash = 5381;
+ uint32_t hash = p_prev;
for(int i=0;i<p_len;i++)
hash = ((hash << 5) + hash) + p_buff[i]; /* hash * 33 + c */
diff --git a/core/math/geometry.h b/core/math/geometry.h
index 826e4697b5..5b21c25bec 100644
--- a/core/math/geometry.h
+++ b/core/math/geometry.h
@@ -695,6 +695,86 @@ public:
}
+
+ static inline Vector<Vector3> clip_polygon(const Vector<Vector3>& polygon,const Plane& p_plane) {
+
+ enum LocationCache {
+ LOC_INSIDE=1,
+ LOC_BOUNDARY=0,
+ LOC_OUTSIDE=-1
+ };
+
+ if (polygon.size()==0)
+ return polygon;
+
+ int *location_cache = (int*)alloca(sizeof(int)*polygon.size());
+ int inside_count = 0;
+ int outside_count = 0;
+
+ for (int a = 0; a < polygon.size(); a++) {
+ //float p_plane.d = (*this) * polygon[a];
+ float dist = p_plane.distance_to(polygon[a]);
+ if (dist <-CMP_POINT_IN_PLANE_EPSILON) {
+ location_cache[a] = LOC_INSIDE;
+ inside_count++;
+ } else {
+ if (dist > CMP_POINT_IN_PLANE_EPSILON) {
+ location_cache[a] = LOC_OUTSIDE;
+ outside_count++;
+ } else {
+ location_cache[a] = LOC_BOUNDARY;
+ }
+ }
+ }
+
+ if (outside_count == 0) {
+
+ return polygon; // no changes
+
+ } else if (inside_count == 0) {
+
+ return Vector<Vector3>(); //empty
+ }
+
+// long count = 0;
+ long previous = polygon.size() - 1;
+
+ Vector<Vector3> clipped;
+
+ for (int index = 0; index < polygon.size(); index++) {
+ int loc = location_cache[index];
+ if (loc == LOC_OUTSIDE) {
+ if (location_cache[previous] == LOC_INSIDE) {
+ const Vector3& v1 = polygon[previous];
+ const Vector3& v2 = polygon[index];
+
+ Vector3 segment= v1 - v2;
+ double den=p_plane.normal.dot( segment );
+ double dist=p_plane.distance_to( v1 ) / den;
+ dist=-dist;
+ clipped.push_back( v1 + segment * dist );
+ }
+ } else {
+ const Vector3& v1 = polygon[index];
+ if ((loc == LOC_INSIDE) && (location_cache[previous] == LOC_OUTSIDE)) {
+ const Vector3& v2 = polygon[previous];
+ Vector3 segment= v1 - v2;
+ double den=p_plane.normal.dot( segment );
+ double dist=p_plane.distance_to( v1 ) / den;
+ dist=-dist;
+ clipped.push_back( v1 + segment * dist );
+ }
+
+ clipped.push_back(v1);
+ }
+
+ previous = index;
+ }
+
+ return clipped;
+ }
+
+
static Vector<int> triangulate_polygon(const Vector<Vector2>& p_polygon) {
Vector<int> triangles;
diff --git a/core/os/main_loop.h b/core/os/main_loop.h
index b84d2841e1..6eb5881175 100644
--- a/core/os/main_loop.h
+++ b/core/os/main_loop.h
@@ -50,7 +50,8 @@ public:
NOTIFICATION_WM_FOCUS_IN = 5,
NOTIFICATION_WM_FOCUS_OUT = 6,
NOTIFICATION_WM_QUIT_REQUEST = 7,
- NOTIFICATION_WM_UNFOCUS_REQUEST = 8
+ NOTIFICATION_WM_UNFOCUS_REQUEST = 8,
+ NOTIFICATION_OS_MEMORY_WARNING = 9,
};
virtual void input_event( const InputEvent& p_event );
diff --git a/core/os/os.cpp b/core/os/os.cpp
index 65d6ed50b2..11290409d5 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -225,7 +225,7 @@ void OS::print_all_resources(String p_to_file) {
void OS::print_resources_in_use(bool p_short) {
- //ResourceCache::dump(NULL,p_short);
+ ResourceCache::dump(NULL,p_short);
}
void OS::dump_resources_to_file(const char* p_file) {
@@ -438,7 +438,7 @@ int OS::get_processor_count() const {
return 1;
}
-Error OS::native_video_play(String p_path) {
+Error OS::native_video_play(String p_path, float p_volume) {
return FAILED;
};
diff --git a/core/os/os.h b/core/os/os.h
index e7fe0cb09e..24e2b4f2d4 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -321,7 +321,7 @@ public:
virtual String get_unique_ID() const;
- virtual Error native_video_play(String p_path);
+ virtual Error native_video_play(String p_path, float p_volume);
virtual bool native_video_is_playing() const;
virtual void native_video_pause();
virtual void native_video_stop();
diff --git a/core/variant.cpp b/core/variant.cpp
index 6b3b25a103..fdb14c0c0f 100644
--- a/core/variant.cpp
+++ b/core/variant.cpp
@@ -1337,6 +1337,10 @@ Variant::operator Matrix3() const {
if (type==MATRIX3)
return *_data._matrix3;
+ else if (type==QUAT)
+ return *reinterpret_cast<const Quat*>(_data._mem);
+ else if (type==TRANSFORM)
+ return _data._transform->basis;
else
return Matrix3();
}
@@ -1345,6 +1349,10 @@ Variant::operator Quat() const {
if (type==QUAT)
return *reinterpret_cast<const Quat*>(_data._mem);
+ else if (type==MATRIX3)
+ return *_data._matrix3;
+ else if (type==TRANSFORM)
+ return _data._transform->basis;
else
return Quat();
}
@@ -1357,6 +1365,8 @@ Variant::operator Transform() const {
return *_data._transform;
else if (type==MATRIX3)
return Transform(*_data._matrix3,Vector3());
+ else if (type==QUAT)
+ return Transform(Matrix3(*reinterpret_cast<const Quat*>(_data._mem)),Vector3());
else
return Transform();
}