diff options
-rw-r--r-- | bin/tests/test_math.cpp | 1 | ||||
-rw-r--r-- | core/math/math_funcs.cpp | 36 | ||||
-rw-r--r-- | core/math/math_funcs.h | 2 | ||||
-rw-r--r-- | doc/base/classes.xml | 6 | ||||
-rw-r--r-- | drivers/gles2/rasterizer_gles2.cpp | 11 | ||||
-rw-r--r-- | modules/gdscript/gd_functions.cpp | 2 | ||||
-rw-r--r-- | platform/windows/os_windows.cpp | 2 | ||||
-rw-r--r-- | scene/gui/spin_box.cpp | 2 | ||||
-rw-r--r-- | scene/gui/tree.cpp | 8 |
9 files changed, 42 insertions, 28 deletions
diff --git a/bin/tests/test_math.cpp b/bin/tests/test_math.cpp index 8e08969fa4..4b686e8af8 100644 --- a/bin/tests/test_math.cpp +++ b/bin/tests/test_math.cpp @@ -113,6 +113,7 @@ uint32_t ihash3( uint32_t a) MainLoop* test() { + print_line(itos(Math::step_decimals( 0.0001 ))); return NULL; { diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp index 0fbd031214..64615fe6b4 100644 --- a/core/math/math_funcs.cpp +++ b/core/math/math_funcs.cpp @@ -206,25 +206,29 @@ double Math::ceil(double p_x) { return ::ceil(p_x); } -int Math::decimals(double p_step) { - - int max=4; - double llimit = Math::pow(0.1,max); - double ulimit = 1.0-llimit; - int i=0; - while( max) { - - float d = absf(p_step) - Math::floor(absf(p_step)); +int Math::step_decimals(double p_step) { + + static const int maxn=9; + static const double sd[maxn]={ + 0.9999, // somehow compensate for floating point error + 0.09999, + 0.009999, + 0.0009999, + 0.00009999, + 0.000009999, + 0.0000009999, + 0.00000009999, + 0.000000009999 + }; - if (d<llimit || d>ulimit) - break; - p_step*=10.0; - max--; - i++; + double as=absf(p_step); + for(int i=0;i<maxn;i++) { + if (as>=sd[i]) { + return i; + } } - return i; - + return maxn; } double Math::ease(double p_x, double p_c) { diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index 2e1b9c989e..fc76d96b2e 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -66,7 +66,7 @@ public: static double floor(double p_x); static double ceil(double p_x); static double ease(double p_x, double p_c); - static int decimals(double p_step); + static int step_decimals(double p_step); static double stepify(double p_value,double p_step); static void seed(uint32_t x=0); static void randomize(); diff --git a/doc/base/classes.xml b/doc/base/classes.xml index d70b11b5ae..d741dbbb65 100644 --- a/doc/base/classes.xml +++ b/doc/base/classes.xml @@ -12264,7 +12264,7 @@ file.open("user://save_game.dat", file.WRITE) file.store_string(content) file.close() - + func load(): var file = File.new() file.open("user://save_game.dat", file.READ) @@ -15692,7 +15692,7 @@ </brief_description> <description> </description> - ImmediateGeometry is a node used for displaying simple geometry created from code, very similar to how glBegin() and glEnd() worked in old versions of OpenGL (1.x). + ImmediateGeometry is a node used for displaying simple geometry created from code, very similar to how glBegin() and glEnd() worked in old versions of OpenGL (1.x). Simply call [method begin()], and add vertices. For custom vertex colors, uvs, normal, etc. call one of the set_ functions below before adding each vertex. When done, call [method end] Calls to begin/end are accumulative and all geometry is added together. To clear all the geometry, call [method clear]. If a material override is set, and this material contains a texture, it's possible to override the texture used in this material for every begin/end set of calls. @@ -42401,7 +42401,7 @@ Because it is easy to get it wrong, here is a quick usage example: [codeblock] var tween = get_node("Tween") - tween.interpolate_property(get_node("Node2D_to_move"), "transform/pos", Vector2(0,0), Vector2(100,100), Tween.TRANS_LINEAR, Tween.EASE_IN_OUT) + tween.interpolate_property(get_node("Node2D_to_move"), "transform/pos", Vector2(0,0), Vector2(100,100), 1, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT) tween.start() [/codeblock] Some of the methods of this class require a property name. You can get the property name by hovering over the property in the inspector of the editor. diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index 4cd97a7f6a..ba93a26a2d 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -10788,8 +10788,17 @@ void RasterizerGLES2::init() { if (OS::get_singleton()->is_stdout_verbose()) { print_line(String("GLES2: Using GLEW ") + (const char*) glewGetString(GLEW_VERSION)); } -#endif + // Check for GL 2.1 compatibility, if not bail out + if (!glewIsSupported("GL_VERSION_2_1")) { + ERR_PRINT("Your system's graphic drivers seem not to support OpenGL 2.1 / GLES 2.0, sorry :(\n" + "Try a drivers update, buy a new GPU or try software rendering on Linux; Godot will now crash with a segmentation fault."); + OS::get_singleton()->alert("Your system's graphic drivers seem not to support OpenGL 2.1 / GLES 2.0, sorry :(\n" + "Godot Engine will self-destruct as soon as you acknowledge this error message.", + "Fatal error: Insufficient OpenGL / GLES drivers"); + // TODO: If it's even possible, we should stop the execution without segfault and memory leaks :) + } +#endif diff --git a/modules/gdscript/gd_functions.cpp b/modules/gdscript/gd_functions.cpp index b9815a5efd..a565e866d0 100644 --- a/modules/gdscript/gd_functions.cpp +++ b/modules/gdscript/gd_functions.cpp @@ -304,7 +304,7 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va case MATH_DECIMALS: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::decimals(*p_args[0]); + r_ret=Math::step_decimals(*p_args[0]); } break; case MATH_STEPIFY: { VALIDATE_ARG_COUNT(2); diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index a3858fe641..571277f91e 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -1343,7 +1343,7 @@ void OS_Windows::vprint(const char* p_format, va_list p_list, bool p_stderr) { void OS_Windows::alert(const String& p_alert,const String& p_title) { if (!is_no_window_mode_enabled()) - MessageBoxW(NULL,p_alert.c_str(),p_title.c_str(),MB_OK|MB_ICONEXCLAMATION); + MessageBoxW(NULL, p_alert.c_str(), p_title.c_str(), MB_OK | MB_ICONEXCLAMATION | MB_TASKMODAL); else print_line("ALERT: "+p_alert); } diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp index 2b64d36a81..98e1a32aef 100644 --- a/scene/gui/spin_box.cpp +++ b/scene/gui/spin_box.cpp @@ -39,7 +39,7 @@ Size2 SpinBox::get_minimum_size() const { void SpinBox::_value_changed(double) { - String value = String::num(get_val(),Math::decimals(get_step())); + String value = String::num(get_val(),Math::step_decimals(get_step())); if (prefix!="") value=prefix+" "+value; if (suffix!="") diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 82459ba0ab..487f62ed44 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -1179,8 +1179,8 @@ int Tree::draw_item(const Point2i& p_pos,const Point2& p_draw_ofs, const Size2& Ref<Texture> updown = cache.updown; - //String valtext = String::num( p_item->cells[i].val, Math::decimals( p_item->cells[i].step ) ); - String valtext = rtos( p_item->cells[i].val ); + String valtext = String::num( p_item->cells[i].val, Math::step_decimals( p_item->cells[i].step ) ); + //String valtext = rtos( p_item->cells[i].val ); font->draw( ci, text_pos, valtext, col, item_rect.size.x-updown->get_width()); if (!p_item->cells[i].editable) @@ -1746,7 +1746,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_ } else { - editor_text=String::num( p_item->cells[col].val, Math::decimals( p_item->cells[col].step ) ); + editor_text=String::num( p_item->cells[col].val, Math::step_decimals( p_item->cells[col].step ) ); if (select_mode==SELECT_MULTI && get_tree()->get_last_event_id() == focus_in_id) bring_up_editor=false; @@ -2521,7 +2521,7 @@ bool Tree::edit_selected() { text_editor->set_pos( textedpos ); text_editor->set_size( rect.size); text_editor->clear(); - text_editor->set_text( c.mode==TreeItem::CELL_MODE_STRING?c.text:rtos(c.val) ); + text_editor->set_text( c.mode==TreeItem::CELL_MODE_STRING?c.text:String::num( c.val, Math::step_decimals( c.step ) ) ); text_editor->select_all(); if (c.mode==TreeItem::CELL_MODE_RANGE || c.mode==TreeItem::CELL_MODE_RANGE_EXPRESSION ) { |