From 2d4cec0cb637e4af2d8954e6ed10336552a627e9 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 15 Feb 2015 11:26:31 -0300 Subject: [PATCH 1/4] fix return value of slide and reflect closes #1311 --- core/variant_call.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 3f2800494d9..50a60390e57 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -1263,8 +1263,8 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl ADDFUNC1(VECTOR2,VECTOR2,Vector2,snapped,VECTOR2,"by",varray()); ADDFUNC0(VECTOR2,REAL,Vector2,get_aspect,varray()); ADDFUNC1(VECTOR2,REAL,Vector2,dot,VECTOR2,"with",varray()); - ADDFUNC1(VECTOR2,REAL,Vector2,slide,VECTOR2,"vec",varray()); - ADDFUNC1(VECTOR2,REAL,Vector2,reflect,VECTOR2,"vec",varray()); + ADDFUNC1(VECTOR2,VECTOR2,Vector2,slide,VECTOR2,"vec",varray()); + ADDFUNC1(VECTOR2,VECTOR2,Vector2,reflect,VECTOR2,"vec",varray()); //ADDFUNC1(VECTOR2,REAL,Vector2,cross,VECTOR2,"with",varray()); ADDFUNC0(RECT2,REAL,Rect2,get_area,varray()); From 4333aa240c68f22b235981bed56d11a592fdfd1d Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 15 Feb 2015 12:38:25 -0300 Subject: [PATCH 2/4] Godot UI is quick and snappy again! Changed linked listed sort to use auxiliary memory this fixes user interface performance issues. --- core/list.h | 56 +++++++++++++++++++++++++++++++++++++++++-- scene/gui/control.cpp | 2 ++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/core/list.h b/core/list.h index f581feb7356..0e4ba71ac49 100644 --- a/core/list.h +++ b/core/list.h @@ -30,7 +30,7 @@ #define GLOBALS_LIST_H #include "os/memory.h" - +#include "sort.h" /** * Generic Templatized Linked List Implementation. @@ -551,7 +551,7 @@ public: } template - void sort_custom() { + void sort_custom_inplace() { if(size()<2) return; @@ -603,6 +603,58 @@ public: _data->last=to; } + template + struct AuxiliaryComparator { + + C compare; + _FORCE_INLINE_ bool operator()(const Element *A,const Element* B) const { + + return compare(A->value,B->value); + } + }; + + template + void sort_custom() { + + //this version uses auxiliary memory for speed. + //if you don't want to use auxiliary memory, use the in_place version + + int s = size(); + if(s<2) + return; + + + Element **aux_buffer = memnew_arr(Element*,s); + + int idx=0; + for(Element *E=front();E;E=E->next_ptr) { + + aux_buffer[idx]=E; + idx++; + } + + SortArray > sort; + sort.sort(aux_buffer,s); + + _data->first=aux_buffer[0]; + aux_buffer[0]->prev_ptr=NULL; + aux_buffer[0]->next_ptr=aux_buffer[1]; + + _data->last=aux_buffer[s-1]; + aux_buffer[s-1]->prev_ptr=aux_buffer[s-2]; + aux_buffer[s-1]->next_ptr=NULL; + + for(int i=1;iprev_ptr=aux_buffer[i-1]; + aux_buffer[i]->next_ptr=aux_buffer[i+1]; + + } + + memdelete_arr(aux_buffer); + } + + /** * copy constructor for the list */ diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 4d32c7ea9a3..a8070be91d0 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -2267,8 +2267,10 @@ void Control::_window_sort_subwindows() { if (!window->subwindow_order_dirty) return; + window->modal_stack.sort_custom(); window->subwindows.sort_custom(); + window->subwindow_order_dirty=false; } From 2478935f9654de9b516f61a43e1b0e0f0d97fb26 Mon Sep 17 00:00:00 2001 From: Felix Laurie von Massenbach Date: Sun, 15 Feb 2015 18:09:11 +0000 Subject: [PATCH 3/4] Fix a shadow declaration. --- core/list.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/list.h b/core/list.h index 0e4ba71ac49..ef30e43d216 100644 --- a/core/list.h +++ b/core/list.h @@ -607,9 +607,9 @@ public: struct AuxiliaryComparator { C compare; - _FORCE_INLINE_ bool operator()(const Element *A,const Element* B) const { + _FORCE_INLINE_ bool operator()(const Element *a,const Element* b) const { - return compare(A->value,B->value); + return compare(a->value,b->value); } }; From 2bea642583efeb68886e71950384f297f2d7ee12 Mon Sep 17 00:00:00 2001 From: reduz Date: Mon, 16 Feb 2015 14:45:11 -0300 Subject: [PATCH 4/4] -Some more work on 2D Lights (NOT FUNCTIONAL YET!) --- scene/2d/light_2d.cpp | 182 ++++++++++++++++++++++++ scene/2d/light_2d.h | 80 +++++++++++ scene/register_scene_types.cpp | 2 + servers/visual/rasterizer.h | 33 +++++ servers/visual/visual_server_raster.cpp | 51 ++++++- servers/visual/visual_server_raster.h | 2 + tools/editor/icons/icon_light_2d.png | Bin 0 -> 342 bytes 7 files changed, 349 insertions(+), 1 deletion(-) create mode 100644 scene/2d/light_2d.cpp create mode 100644 scene/2d/light_2d.h create mode 100644 tools/editor/icons/icon_light_2d.png diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp new file mode 100644 index 00000000000..073e3a16457 --- /dev/null +++ b/scene/2d/light_2d.cpp @@ -0,0 +1,182 @@ +#include "light_2d.h" +#include "servers/visual_server.h" + +void Light2D::set_enabled( bool p_enabled) { + + VS::get_singleton()->canvas_light_set_enabled(canvas_light,p_enabled); + enabled=p_enabled; +} + +bool Light2D::is_enabled() const { + + return enabled; +} + +void Light2D::set_texture( const Ref& p_texture) { + + texture=p_texture; + if (texture.is_valid()) + VS::get_singleton()->canvas_light_set_texture(canvas_light,texture->get_rid()); + else + VS::get_singleton()->canvas_light_set_texture(canvas_light,RID()); +} + +Ref Light2D::get_texture() const { + + return texture; +} + +void Light2D::set_texture_offset( const Vector2& p_offset) { + + texture_offset=p_offset; + VS::get_singleton()->canvas_light_set_texture_offset(canvas_light,texture_offset); +} + +Vector2 Light2D::get_texture_offset() const { + + return texture_offset; +} + +void Light2D::set_color( const Color& p_color) { + + color=p_color; + VS::get_singleton()->canvas_light_set_color(canvas_light,color); + +} +Color Light2D::get_color() const { + + return color; +} + +void Light2D::set_height( float p_height) { + + height=p_height; + VS::get_singleton()->canvas_light_set_height(canvas_light,height); + +} +float Light2D::get_height() const { + + return height; +} + +void Light2D::set_z_range_min( int p_min_z) { + + z_min=p_min_z; + VS::get_singleton()->canvas_light_set_z_range(canvas_light,z_min,z_max); + +} +int Light2D::get_z_range_min() const { + + return z_min; +} + +void Light2D::set_z_range_max( int p_max_z) { + + z_max=p_max_z; + VS::get_singleton()->canvas_light_set_z_range(canvas_light,z_min,z_max); + +} +int Light2D::get_z_range_max() const { + + return z_max; +} + +void Light2D::set_item_mask( int p_mask) { + + item_mask=p_mask; + VS::get_singleton()->canvas_light_set_item_mask(canvas_light,item_mask); + +} + +int Light2D::get_item_mask() const { + + return item_mask; +} + +void Light2D::set_blend_mode( LightBlendMode p_blend_mode ) { + + blend_mode=p_blend_mode; + VS::get_singleton()->canvas_light_set_blend_mode(canvas_light,VS::CanvasLightBlendMode(blend_mode)); +} + +Light2D::LightBlendMode Light2D::get_blend_mode() const { + + return blend_mode; +} + +void Light2D::set_shadow_enabled( bool p_enabled) { + + shadow=p_enabled; + VS::get_singleton()->canvas_light_set_shadow_enabled(canvas_light,shadow); + +} +bool Light2D::is_shadow_enabled() const { + + return shadow; +} + +void Light2D::_bind_methods() { + + + ObjectTypeDB::bind_method(_MD("set_enabled","enabled"),&Light2D::set_enabled); + ObjectTypeDB::bind_method(_MD("is_enabled"),&Light2D::is_enabled); + + ObjectTypeDB::bind_method(_MD("set_texture","texture"),&Light2D::set_texture); + ObjectTypeDB::bind_method(_MD("get_texture"),&Light2D::get_texture); + + ObjectTypeDB::bind_method(_MD("set_texture_offset","texture_offset"),&Light2D::set_texture_offset); + ObjectTypeDB::bind_method(_MD("get_texture_offset"),&Light2D::get_texture_offset); + + ObjectTypeDB::bind_method(_MD("set_color","color"),&Light2D::set_color); + ObjectTypeDB::bind_method(_MD("get_color"),&Light2D::get_color); + + ObjectTypeDB::bind_method(_MD("set_height","height"),&Light2D::set_height); + ObjectTypeDB::bind_method(_MD("get_height"),&Light2D::get_height); + + ObjectTypeDB::bind_method(_MD("set_z_range_min","z"),&Light2D::set_z_range_min); + ObjectTypeDB::bind_method(_MD("get_z_range_min"),&Light2D::get_z_range_min); + + ObjectTypeDB::bind_method(_MD("set_z_range_max","z"),&Light2D::set_z_range_max); + ObjectTypeDB::bind_method(_MD("get_z_range_max"),&Light2D::get_z_range_max); + + ObjectTypeDB::bind_method(_MD("set_item_mask","item_mask"),&Light2D::set_item_mask); + ObjectTypeDB::bind_method(_MD("get_item_mask"),&Light2D::get_item_mask); + + ObjectTypeDB::bind_method(_MD("set_blend_mode","blend_mode"),&Light2D::set_blend_mode); + ObjectTypeDB::bind_method(_MD("get_blend_mode"),&Light2D::get_blend_mode); + + ObjectTypeDB::bind_method(_MD("set_shadow_enabled","enabled"),&Light2D::set_shadow_enabled); + ObjectTypeDB::bind_method(_MD("is_shadow_enabled"),&Light2D::is_shadow_enabled); + + ADD_PROPERTY( PropertyInfo(Variant::BOOL,"enabled"),_SCS("set_enabled"),_SCS("is_enabled")); + ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"texture",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),_SCS("set_texture"),_SCS("get_texture")); + ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"texture_offset"),_SCS("set_texture_offset"),_SCS("get_texture_offset")); + ADD_PROPERTY( PropertyInfo(Variant::COLOR,"color"),_SCS("set_color"),_SCS("get_color")); + ADD_PROPERTY( PropertyInfo(Variant::REAL,"height"),_SCS("set_height"),_SCS("get_height")); + ADD_PROPERTY( PropertyInfo(Variant::INT,"z_range_min",PROPERTY_HINT_RANGE,itos(VS::CANVAS_ITEM_Z_MIN)+","+itos(VS::CANVAS_ITEM_Z_MAX)+",1"),_SCS("set_z_range_min"),_SCS("get_z_range_min")); + ADD_PROPERTY( PropertyInfo(Variant::INT,"z_range_max",PROPERTY_HINT_RANGE,itos(VS::CANVAS_ITEM_Z_MIN)+","+itos(VS::CANVAS_ITEM_Z_MAX)+",1"),_SCS("set_z_range_max"),_SCS("get_z_range_max")); + ADD_PROPERTY( PropertyInfo(Variant::INT,"item_mask",PROPERTY_HINT_ALL_FLAGS),_SCS("set_item_mask"),_SCS("get_item_mask")); + ADD_PROPERTY( PropertyInfo(Variant::INT,"blend_mode",PROPERTY_HINT_ENUM,"Add,Sub,Mul,Dodge,Burn,Lighten,Darken,Overlay,Screen"),_SCS("set_blend_mode"),_SCS("get_blend_mode")); + ADD_PROPERTY( PropertyInfo(Variant::BOOL,"shadow_enabled"),_SCS("set_shadow_enabled"),_SCS("is_shadow_enabled")); + + +} + +Light2D::Light2D() { + + canvas_light=VisualServer::get_singleton()->canvas_light_create(); + enabled=true; + shadow=false; + color=Color(1,1,1); + height=0; + z_min=-1024; + z_max=1024; + item_mask=1; + blend_mode=LIGHT_BLEND_ADD; + +} + +Light2D::~Light2D() { + + VisualServer::get_singleton()->free(canvas_light); +} diff --git a/scene/2d/light_2d.h b/scene/2d/light_2d.h new file mode 100644 index 00000000000..ac8d587ea7c --- /dev/null +++ b/scene/2d/light_2d.h @@ -0,0 +1,80 @@ +#ifndef LIGHT_2D_H +#define LIGHT_2D_H + +#include "scene/2d/node_2d.h" + +class Light2D : public Node2D { + + OBJ_TYPE(Light2D,Node2D); +public: + + enum LightBlendMode { + LIGHT_BLEND_ADD, + LIGHT_BLEND_SUB, + LIGHT_BLEND_MULTIPLY, + LIGHT_BLEND_DODGE, + LIGHT_BLEND_BURN, + LIGHT_BLEND_LIGHTEN, + LIGHT_BLEND_DARKEN, + LIGHT_BLEND_OVERLAY, + LIGHT_BLEND_SCREEN, + }; + +private: + RID canvas_light; + bool enabled; + bool shadow; + Color color; + float height; + int z_min; + int z_max; + int item_mask; + LightBlendMode blend_mode; + Ref texture; + Vector2 texture_offset; + +protected: + + static void _bind_methods(); +public: + + + void set_enabled( bool p_enabled); + bool is_enabled() const; + + void set_texture( const Ref& p_texture); + Ref get_texture() const; + + void set_texture_offset( const Vector2& p_offset); + Vector2 get_texture_offset() const; + + void set_color( const Color& p_color); + Color get_color() const; + + void set_height( float p_height); + float get_height() const; + + void set_z_range_min( int p_min_z); + int get_z_range_min() const; + + void set_z_range_max( int p_max_z); + int get_z_range_max() const; + + void set_item_mask( int p_mask); + int get_item_mask() const; + + void set_blend_mode( LightBlendMode p_blend_mode ); + LightBlendMode get_blend_mode() const; + + void set_shadow_enabled( bool p_enabled); + bool is_shadow_enabled() const; + + + Light2D(); + ~Light2D(); +}; + + +VARIANT_ENUM_CAST(Light2D::LightBlendMode); + +#endif // LIGHT_2D_H diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index 9600469e8a6..89ce164ce9e 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -79,6 +79,7 @@ #include "scene/resources/video_stream.h" #include "scene/2d/particles_2d.h" #include "scene/2d/path_2d.h" +#include "scene/2d/light_2d.h" #include "scene/2d/canvas_item.h" #include "scene/2d/sprite.h" @@ -472,6 +473,7 @@ void register_scene_types() { ObjectTypeDB::register_type(); ObjectTypeDB::register_type(); ObjectTypeDB::register_type(); + ObjectTypeDB::register_type(); ObjectTypeDB::register_type(); ObjectTypeDB::set_type_enabled("CollisionShape2D",false); diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h index 92c7b8ac14d..63ebdbc34a8 100644 --- a/servers/visual/rasterizer.h +++ b/servers/visual/rasterizer.h @@ -567,6 +567,39 @@ public: CANVAS_RECT_FLIP_V=8 }; + + struct CanvasLight { + + bool enabled; + bool shadow; + Color color; + Matrix32 xform; + float height; + int z_min; + int z_max; + int item_mask; + VS::CanvasLightBlendMode blend_mode; + RID texture; + void *texture_cache; // implementation dependent + Vector2 texture_offset; + + CanvasLight *next_ptr; + + CanvasLight() { + enabled=true; + shadow=false; + color=Color(1,1,1); + height=0; + z_min=-1024; + z_max=1024; + item_mask=1; + blend_mode=VS::CANVAS_LIGHT_BLEND_ADD; + texture_cache=NULL; + next_ptr=NULL; + } + }; + + struct CanvasItem { struct Command { diff --git a/servers/visual/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp index fc32702a127..e8fa319f11a 100644 --- a/servers/visual/visual_server_raster.cpp +++ b/servers/visual/visual_server_raster.cpp @@ -3823,60 +3823,100 @@ void VisualServerRaster::canvas_item_raise(RID p_item) { RID VisualServerRaster::canvas_light_create() { - return RID(); + Rasterizer::CanvasLight *clight = memnew( Rasterizer::CanvasLight ); + return canvas_light_owner.make_rid(clight); } void VisualServerRaster::canvas_light_attach_to_canvas(RID p_light,RID p_canvas){ + Rasterizer::CanvasLight *clight = canvas_light_owner.get(p_light); + ERR_FAIL_COND(!clight); + } void VisualServerRaster::canvas_light_set_enabled(RID p_light, bool p_enabled){ + Rasterizer::CanvasLight *clight = canvas_light_owner.get(p_light); + ERR_FAIL_COND(!clight); + clight->enabled=p_enabled; } void VisualServerRaster::canvas_light_set_transform(RID p_light, const Matrix32& p_transform){ + Rasterizer::CanvasLight *clight = canvas_light_owner.get(p_light); + ERR_FAIL_COND(!clight); + clight->xform=p_transform; } void VisualServerRaster::canvas_light_set_texture(RID p_light, RID p_texture){ + Rasterizer::CanvasLight *clight = canvas_light_owner.get(p_light); + ERR_FAIL_COND(!clight); + clight->texture=p_texture; } void VisualServerRaster::canvas_light_set_texture_offset(RID p_light, const Vector2& p_offset){ + Rasterizer::CanvasLight *clight = canvas_light_owner.get(p_light); + ERR_FAIL_COND(!clight); + clight->texture_offset=p_offset; } void VisualServerRaster::canvas_light_set_color(RID p_light, const Color& p_color){ + Rasterizer::CanvasLight *clight = canvas_light_owner.get(p_light); + ERR_FAIL_COND(!clight); + clight->color=p_color; + } void VisualServerRaster::canvas_light_set_height(RID p_light, float p_height){ + Rasterizer::CanvasLight *clight = canvas_light_owner.get(p_light); + ERR_FAIL_COND(!clight); + clight->height=p_height; } void VisualServerRaster::canvas_light_set_z_range(RID p_light, int p_min_z,int p_max_z){ + Rasterizer::CanvasLight *clight = canvas_light_owner.get(p_light); + ERR_FAIL_COND(!clight); + clight->z_min=p_min_z; + clight->z_max=p_max_z; } void VisualServerRaster::canvas_light_set_item_mask(RID p_light, int p_mask){ + Rasterizer::CanvasLight *clight = canvas_light_owner.get(p_light); + ERR_FAIL_COND(!clight); + clight->item_mask=p_mask; } void VisualServerRaster::canvas_light_set_blend_mode(RID p_light, CanvasLightBlendMode p_blend_mode){ + Rasterizer::CanvasLight *clight = canvas_light_owner.get(p_light); + ERR_FAIL_COND(!clight); + clight->blend_mode=p_blend_mode; } void VisualServerRaster::canvas_light_set_shadow_enabled(RID p_light, bool p_enabled){ + Rasterizer::CanvasLight *clight = canvas_light_owner.get(p_light); + ERR_FAIL_COND(!clight); + clight->shadow=p_enabled; } void VisualServerRaster::canvas_light_set_shadow_buffer_size(RID p_light, int p_size){ + Rasterizer::CanvasLight *clight = canvas_light_owner.get(p_light); + ERR_FAIL_COND(!clight); } void VisualServerRaster::canvas_light_set_shadow_filter(RID p_light, int p_size){ + Rasterizer::CanvasLight *clight = canvas_light_owner.get(p_light); + ERR_FAIL_COND(!clight); } @@ -4186,6 +4226,15 @@ void VisualServerRaster::free( RID p_rid ) { canvas_item_owner.free( p_rid ); memdelete( canvas_item ); + + } else if (canvas_light_owner.owns(p_rid)) { + + Rasterizer::CanvasLight *canvas_light = canvas_light_owner.get(p_rid); + ERR_FAIL_COND(!canvas_light); + + canvas_light_owner.free( p_rid ); + memdelete( canvas_light ); + } else if (scenario_owner.owns(p_rid)) { Scenario *scenario=scenario_owner.get(p_rid); diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index 57032ab441d..c15b6ebb262 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -440,6 +440,8 @@ class VisualServerRaster : public VisualServer { }; + RID_Owner canvas_light_owner; + struct Viewport { diff --git a/tools/editor/icons/icon_light_2d.png b/tools/editor/icons/icon_light_2d.png new file mode 100644 index 0000000000000000000000000000000000000000..9162b33090336c63df6165a0a4c0765464941165 GIT binary patch literal 342 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmP~lYjs(zfI5qPN2|ZPZ!4!i_^WA4gHu61z0a^KbiMJ zqk$_hxNt(p;sWL@hefU;TTBGqA26Aecv!OVHnn9r?l$R5kvy-aymN;A=W_s^tue$EbQ}i#TS{!gzniFziv99#wFUyYH z?)sxQ!!wvUUGxpJGpqc^y}b*LmM%y*5W3Rp)}a}d^R@(THaIR@XZ(hJb!<9A|4{?$ zJL*NZw;4RpjehyecF#4PEsga%PAuCOe?^VctZgTe~DWM4fr^biU literal 0 HcmV?d00001