aboutsummaryrefslogtreecommitdiff
path: root/main/tests
diff options
context:
space:
mode:
authorRémi Verschelde2017-03-19 00:36:26 +0100
committerRémi Verschelde2017-03-19 00:36:26 +0100
commitf8db8a3faa30b71dca33ced38be16d3f93f43e8a (patch)
tree3b798318132cca7eccfbca5818ab55656a2896d7 /main/tests
parent1d418afe863c9e553b69174ce63aef203c46d2f0 (diff)
downloadgodot-f8db8a3faa30b71dca33ced38be16d3f93f43e8a.tar.gz
godot-f8db8a3faa30b71dca33ced38be16d3f93f43e8a.tar.zst
godot-f8db8a3faa30b71dca33ced38be16d3f93f43e8a.zip
Bring that Whole New World to the Old Continent too
Applies the clang-format style to the 2.1 branch as done for master in 5dbf1809c6e3e905b94b8764e99491e608122261.
Diffstat (limited to '')
-rw-r--r--main/tests/test_containers.cpp18
-rw-r--r--main/tests/test_containers.h3
-rw-r--r--main/tests/test_detailer.cpp98
-rw-r--r--main/tests/test_detailer.h4
-rw-r--r--main/tests/test_gdscript.cpp985
-rw-r--r--main/tests/test_gdscript.h3
-rw-r--r--main/tests/test_gui.cpp213
-rw-r--r--main/tests/test_gui.h4
-rw-r--r--main/tests/test_image.cpp25
-rw-r--r--main/tests/test_image.h3
-rw-r--r--main/tests/test_io.cpp53
-rw-r--r--main/tests/test_io.h3
-rw-r--r--main/tests/test_main.cpp76
-rw-r--r--main/tests/test_main.h9
-rw-r--r--main/tests/test_math.cpp242
-rw-r--r--main/tests/test_math.h3
-rw-r--r--main/tests/test_misc.cpp217
-rw-r--r--main/tests/test_misc.h3
-rw-r--r--main/tests/test_particles.cpp49
-rw-r--r--main/tests/test_particles.h3
-rw-r--r--main/tests/test_physics.cpp396
-rw-r--r--main/tests/test_physics.h3
-rw-r--r--main/tests/test_physics_2d.cpp301
-rw-r--r--main/tests/test_physics_2d.h4
-rw-r--r--main/tests/test_python.cpp3
-rw-r--r--main/tests/test_python.h1
-rw-r--r--main/tests/test_render.cpp130
-rw-r--r--main/tests/test_render.h3
-rw-r--r--main/tests/test_shader_lang.cpp190
-rw-r--r--main/tests/test_shader_lang.h3
-rw-r--r--main/tests/test_sound.cpp35
-rw-r--r--main/tests/test_sound.h3
-rw-r--r--main/tests/test_string.cpp271
-rw-r--r--main/tests/test_string.h8
34 files changed, 1522 insertions, 1843 deletions
diff --git a/main/tests/test_containers.cpp b/main/tests/test_containers.cpp
index 4bc297d0b..746a9188a 100644
--- a/main/tests/test_containers.cpp
+++ b/main/tests/test_containers.cpp
@@ -28,19 +28,18 @@
/*************************************************************************/
#include "test_containers.h"
#include "dvector.h"
-#include "set.h"
-#include "print_string.h"
#include "math_funcs.h"
+#include "print_string.h"
#include "servers/visual/default_mouse_cursor.xpm"
+#include "set.h"
-#include "variant.h"
-#include "list.h"
#include "image.h"
+#include "list.h"
+#include "variant.h"
namespace TestContainers {
-MainLoop * test() {
-
+MainLoop *test() {
/*
HashMap<int,int> int_map;
@@ -52,15 +51,14 @@ MainLoop * test() {
}
*/
-
{
-// static const int size = 16;
+ // static const int size = 16;
Image img;
img.create(default_mouse_cursor_xpm);
{
- for (int i=0; i<8; i++) {
+ for (int i = 0; i < 8; i++) {
Image mipmap;
//img.make_mipmap(mipmap);
@@ -68,7 +66,6 @@ MainLoop * test() {
if (img.get_width() <= 4) break;
};
};
-
};
#if 0
@@ -103,5 +100,4 @@ MainLoop * test() {
return NULL;
}
-
}
diff --git a/main/tests/test_containers.h b/main/tests/test_containers.h
index 72d5c0ff7..c33c0167e 100644
--- a/main/tests/test_containers.h
+++ b/main/tests/test_containers.h
@@ -36,8 +36,7 @@
namespace TestContainers {
-MainLoop * test();
-
+MainLoop *test();
}
#endif
diff --git a/main/tests/test_detailer.cpp b/main/tests/test_detailer.cpp
index 5dba7c3f7..1f2be80c3 100644
--- a/main/tests/test_detailer.cpp
+++ b/main/tests/test_detailer.cpp
@@ -27,15 +27,14 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "test_detailer.h"
-#include "servers/visual_server.h"
-#include "os/main_loop.h"
+#include "geometry.h"
#include "math_funcs.h"
+#include "os/main_loop.h"
#include "print_string.h"
-#include "geometry.h"
#include "quick_hull.h"
+#include "servers/visual_server.h"
namespace TestMultiMesh {
-
class TestMainLoop : public MainLoop {
RID instance;
@@ -47,16 +46,15 @@ class TestMainLoop : public MainLoop {
#define MULTIMESH_COUNT 1500
- float ofs_x,ofs_y;
+ float ofs_x, ofs_y;
bool quit;
-public:
-
+public:
virtual void _update_qh() {
- VisualServer *vs=VisualServer::get_singleton();
+ VisualServer *vs = VisualServer::get_singleton();
Vector<Vector3> vts;
-/*
+ /*
static const int s = 20;
for(int i=0;i<s;i++) {
@@ -83,7 +81,7 @@ public:
vts.push_back(Vector3(0,-1,0));
vts.push_back(Vector3(1,0,0));
vts.push_back(Vector3(-1,0,0));*/
-/*
+ /*
vts.push_back(Vector3(1,1,1));
vts.push_back(Vector3(1,-1,1));
vts.push_back(Vector3(-1,1,1));
@@ -94,19 +92,16 @@ public:
vts.push_back(Vector3(-1,-1,-1));
*/
-
- DVector<Plane> convex_planes = Geometry::build_cylinder_planes(0.5,0.7,4,Vector3::AXIS_Z);
+ DVector<Plane> convex_planes = Geometry::build_cylinder_planes(0.5, 0.7, 4, Vector3::AXIS_Z);
Geometry::MeshData convex_data = Geometry::build_convex_mesh(convex_planes);
- vts=convex_data.vertices;
+ vts = convex_data.vertices;
Geometry::MeshData md;
- Error err = QuickHull::build(vts,md);
- print_line("ERR: "+itos(err));
-
- vs->mesh_remove_surface(mesh,0);
- vs->mesh_add_surface_from_mesh_data(mesh,md);
-
+ Error err = QuickHull::build(vts, md);
+ print_line("ERR: " + itos(err));
+ vs->mesh_remove_surface(mesh, 0);
+ vs->mesh_add_surface_from_mesh_data(mesh, md);
//vs->scenario_set_debug(scenario,VS::SCENARIO_DEBUG_WIREFRAME);
@@ -118,71 +113,64 @@ public:
RID tcmat = vs->mesh_surface_get_material(test_cube,0);
vs->material_set_shader(tcmat,sm);
*/
-
}
- virtual void input_event(const InputEvent& p_event) {
+ virtual void input_event(const InputEvent &p_event) {
- if (p_event.type==InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask&4) {
+ if (p_event.type == InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask & 4) {
- ofs_x+=p_event.mouse_motion.relative_y/200.0;
- ofs_y+=p_event.mouse_motion.relative_x/200.0;
+ ofs_x += p_event.mouse_motion.relative_y / 200.0;
+ ofs_y += p_event.mouse_motion.relative_x / 200.0;
}
- if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.pressed && p_event.mouse_button.button_index==1) {
+ if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.pressed && p_event.mouse_button.button_index == 1) {
QuickHull::debug_stop_after++;
_update_qh();
}
- if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.pressed && p_event.mouse_button.button_index==2) {
+ if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.pressed && p_event.mouse_button.button_index == 2) {
- if (QuickHull::debug_stop_after>0)
+ if (QuickHull::debug_stop_after > 0)
QuickHull::debug_stop_after--;
_update_qh();
}
-
-
}
virtual void request_quit() {
- quit=true;
+ quit = true;
}
-
-
virtual void init() {
- VisualServer *vs=VisualServer::get_singleton();
-
+ VisualServer *vs = VisualServer::get_singleton();
mesh = vs->mesh_create();
scenario = vs->scenario_create();
- QuickHull::debug_stop_after=0;
+ QuickHull::debug_stop_after = 0;
_update_qh();
- instance = vs->instance_create2(mesh,scenario);
+ instance = vs->instance_create2(mesh, scenario);
camera = vs->camera_create();
-
- vs->camera_set_perspective( camera, 60.0,0.1, 100.0 );
+ vs->camera_set_perspective(camera, 60.0, 0.1, 100.0);
viewport = vs->viewport_create();
- vs->viewport_attach_camera( viewport, camera );
+ vs->viewport_attach_camera(viewport, camera);
vs->viewport_attach_to_screen(viewport);
- vs->viewport_set_scenario( viewport, scenario );
+ vs->viewport_set_scenario(viewport, scenario);
- vs->camera_set_transform(camera, Transform( Matrix3(), Vector3(0,0,2 ) ) );
+ vs->camera_set_transform(camera, Transform(Matrix3(), Vector3(0, 0, 2)));
- RID lightaux = vs->light_create( VisualServer::LIGHT_DIRECTIONAL );
+ RID lightaux = vs->light_create(VisualServer::LIGHT_DIRECTIONAL);
//vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_AMBIENT, Color(0.3,0.3,0.3) );
- light = vs->instance_create2( lightaux,scenario );
- vs->instance_set_transform(light,Transform(Matrix3(Vector3(0.1,0.4,0.7).normalized(),0.9)));
+ light = vs->instance_create2(lightaux, scenario);
+ vs->instance_set_transform(light, Transform(Matrix3(Vector3(0.1, 0.4, 0.7).normalized(), 0.9)));
- ofs_x=0;
- ofs_y=0;
- quit=false;
+ ofs_x = 0;
+ ofs_y = 0;
+ quit = false;
}
virtual bool idle(float p_time) {
@@ -191,27 +179,23 @@ public:
virtual bool iteration(float p_time) {
- VisualServer *vs=VisualServer::get_singleton();
+ VisualServer *vs = VisualServer::get_singleton();
Transform tr_camera;
- tr_camera.rotate( Vector3(0,1,0), ofs_y );
- tr_camera.rotate( Vector3(1,0,0),ofs_x );
- tr_camera.translate(0,0,10);
+ tr_camera.rotate(Vector3(0, 1, 0), ofs_y);
+ tr_camera.rotate(Vector3(1, 0, 0), ofs_x);
+ tr_camera.translate(0, 0, 10);
- vs->camera_set_transform( camera, tr_camera );
+ vs->camera_set_transform(camera, tr_camera);
return quit;
}
virtual void finish() {
-
}
-
};
-MainLoop* test() {
+MainLoop *test() {
return memnew(TestMainLoop);
-
}
-
}
diff --git a/main/tests/test_detailer.h b/main/tests/test_detailer.h
index 597e088ca..ad69ca77c 100644
--- a/main/tests/test_detailer.h
+++ b/main/tests/test_detailer.h
@@ -36,9 +36,7 @@
namespace TestMultiMesh {
-MainLoop* test();
-
+MainLoop *test();
}
-
#endif
diff --git a/main/tests/test_gdscript.cpp b/main/tests/test_gdscript.cpp
index c4b770aa7..57db04d7f 100644
--- a/main/tests/test_gdscript.cpp
+++ b/main/tests/test_gdscript.cpp
@@ -28,47 +28,44 @@
/*************************************************************************/
#include "test_gdscript.h"
-
+#include "os/file_access.h"
#include "os/main_loop.h"
#include "os/os.h"
-#include "os/file_access.h"
#ifdef GDSCRIPT_ENABLED
-#include "modules/gdscript/gd_tokenizer.h"
-#include "modules/gdscript/gd_parser.h"
#include "modules/gdscript/gd_compiler.h"
+#include "modules/gdscript/gd_parser.h"
#include "modules/gdscript/gd_script.h"
-
+#include "modules/gdscript/gd_tokenizer.h"
namespace TestGDScript {
-
-static void _print_indent(int p_ident,const String& p_text) {
+static void _print_indent(int p_ident, const String &p_text) {
String txt;
- for(int i=0;i<p_ident;i++) {
- txt+='\t';
+ for (int i = 0; i < p_ident; i++) {
+ txt += '\t';
}
- print_line(txt+p_text);
+ print_line(txt + p_text);
}
static String _parser_extends(const GDParser::ClassNode *p_class) {
- String txt="extends ";
- if (String(p_class->extends_file)!="") {
- txt+="\""+p_class->extends_file+"\"";
+ String txt = "extends ";
+ if (String(p_class->extends_file) != "") {
+ txt += "\"" + p_class->extends_file + "\"";
if (p_class->extends_class.size())
- txt+=".";
+ txt += ".";
}
- for(int i=0;i<p_class->extends_class.size();i++) {
+ for (int i = 0; i < p_class->extends_class.size(); i++) {
- if (i!=0)
- txt+=".";
+ if (i != 0)
+ txt += ".";
- txt+=p_class->extends_class[i];
+ txt += p_class->extends_class[i];
}
return txt;
@@ -77,152 +74,221 @@ static String _parser_extends(const GDParser::ClassNode *p_class) {
static String _parser_expr(const GDParser::Node *p_expr) {
String txt;
- switch(p_expr->type) {
+ switch (p_expr->type) {
case GDParser::Node::TYPE_IDENTIFIER: {
const GDParser::IdentifierNode *id_node = static_cast<const GDParser::IdentifierNode *>(p_expr);
- txt=id_node->name;
+ txt = id_node->name;
} break;
case GDParser::Node::TYPE_CONSTANT: {
const GDParser::ConstantNode *c_node = static_cast<const GDParser::ConstantNode *>(p_expr);
- if (c_node->value.get_type()==Variant::STRING)
- txt="\""+String(c_node->value)+"\"";
+ if (c_node->value.get_type() == Variant::STRING)
+ txt = "\"" + String(c_node->value) + "\"";
else
- txt=c_node->value;
+ txt = c_node->value;
} break;
case GDParser::Node::TYPE_SELF: {
- txt="self";
+ txt = "self";
} break;
case GDParser::Node::TYPE_ARRAY: {
const GDParser::ArrayNode *arr_node = static_cast<const GDParser::ArrayNode *>(p_expr);
- txt+="[";
- for(int i=0;i<arr_node->elements.size();i++) {
+ txt += "[";
+ for (int i = 0; i < arr_node->elements.size(); i++) {
- if (i>0)
- txt+=", ";
- txt+=_parser_expr(arr_node->elements[i]);
+ if (i > 0)
+ txt += ", ";
+ txt += _parser_expr(arr_node->elements[i]);
}
- txt+="]";
+ txt += "]";
} break;
case GDParser::Node::TYPE_DICTIONARY: {
const GDParser::DictionaryNode *dict_node = static_cast<const GDParser::DictionaryNode *>(p_expr);
- txt+="{";
- for(int i=0;i<dict_node->elements.size();i++) {
+ txt += "{";
+ for (int i = 0; i < dict_node->elements.size(); i++) {
- if (i>0)
- txt+=", ";
+ if (i > 0)
+ txt += ", ";
const GDParser::DictionaryNode::Pair &p = dict_node->elements[i];
- txt+=_parser_expr(p.key);
- txt+=":";
- txt+=_parser_expr(p.value);
+ txt += _parser_expr(p.key);
+ txt += ":";
+ txt += _parser_expr(p.value);
}
- txt+="}";
+ txt += "}";
} break;
case GDParser::Node::TYPE_OPERATOR: {
const GDParser::OperatorNode *c_node = static_cast<const GDParser::OperatorNode *>(p_expr);
- switch(c_node->op) {
+ switch (c_node->op) {
case GDParser::OperatorNode::OP_PARENT_CALL:
- txt+=".";
+ txt += ".";
case GDParser::OperatorNode::OP_CALL: {
- ERR_FAIL_COND_V(c_node->arguments.size()<1,"");
+ ERR_FAIL_COND_V(c_node->arguments.size() < 1, "");
String func_name;
const GDParser::Node *nfunc = c_node->arguments[0];
- int arg_ofs=0;
- if (nfunc->type==GDParser::Node::TYPE_BUILT_IN_FUNCTION) {
+ int arg_ofs = 0;
+ if (nfunc->type == GDParser::Node::TYPE_BUILT_IN_FUNCTION) {
const GDParser::BuiltInFunctionNode *bif_node = static_cast<const GDParser::BuiltInFunctionNode *>(nfunc);
- func_name=GDFunctions::get_func_name(bif_node->function);
- arg_ofs=1;
- } else if (nfunc->type==GDParser::Node::TYPE_TYPE) {
+ func_name = GDFunctions::get_func_name(bif_node->function);
+ arg_ofs = 1;
+ } else if (nfunc->type == GDParser::Node::TYPE_TYPE) {
const GDParser::TypeNode *t_node = static_cast<const GDParser::TypeNode *>(nfunc);
- func_name=Variant::get_type_name(t_node->vtype);
- arg_ofs=1;
+ func_name = Variant::get_type_name(t_node->vtype);
+ arg_ofs = 1;
} else {
- ERR_FAIL_COND_V(c_node->arguments.size()<2,"");
+ ERR_FAIL_COND_V(c_node->arguments.size() < 2, "");
nfunc = c_node->arguments[1];
- ERR_FAIL_COND_V(nfunc->type!=GDParser::Node::TYPE_IDENTIFIER,"");
+ ERR_FAIL_COND_V(nfunc->type != GDParser::Node::TYPE_IDENTIFIER, "");
- if (c_node->arguments[0]->type!=GDParser::Node::TYPE_SELF)
- func_name=_parser_expr(c_node->arguments[0])+".";
+ if (c_node->arguments[0]->type != GDParser::Node::TYPE_SELF)
+ func_name = _parser_expr(c_node->arguments[0]) + ".";
- func_name+=_parser_expr(nfunc);
- arg_ofs=2;
+ func_name += _parser_expr(nfunc);
+ arg_ofs = 2;
}
- txt+=func_name+"(";
+ txt += func_name + "(";
- for(int i=arg_ofs;i<c_node->arguments.size();i++) {
+ for (int i = arg_ofs; i < c_node->arguments.size(); i++) {
- const GDParser::Node *arg=c_node->arguments[i];
- if (i>arg_ofs)
- txt+=", ";
- txt+=_parser_expr(arg);
+ const GDParser::Node *arg = c_node->arguments[i];
+ if (i > arg_ofs)
+ txt += ", ";
+ txt += _parser_expr(arg);
}
- txt+=")";
+ txt += ")";
} break;
case GDParser::OperatorNode::OP_INDEX: {
- ERR_FAIL_COND_V(c_node->arguments.size()!=2,"");
+ ERR_FAIL_COND_V(c_node->arguments.size() != 2, "");
//index with []
- txt=_parser_expr(c_node->arguments[0])+"["+_parser_expr(c_node->arguments[1])+"]";
+ txt = _parser_expr(c_node->arguments[0]) + "[" + _parser_expr(c_node->arguments[1]) + "]";
} break;
case GDParser::OperatorNode::OP_INDEX_NAMED: {
- ERR_FAIL_COND_V(c_node->arguments.size()!=2,"");
+ ERR_FAIL_COND_V(c_node->arguments.size() != 2, "");
- txt=_parser_expr(c_node->arguments[0])+"."+_parser_expr(c_node->arguments[1]);
+ txt = _parser_expr(c_node->arguments[0]) + "." + _parser_expr(c_node->arguments[1]);
} break;
- case GDParser::OperatorNode::OP_NEG: { txt="-"+_parser_expr(c_node->arguments[0]); } break;
- case GDParser::OperatorNode::OP_NOT: { txt="not "+_parser_expr(c_node->arguments[0]); } break;
- case GDParser::OperatorNode::OP_BIT_INVERT: { txt="~"+_parser_expr(c_node->arguments[0]); } break;
- case GDParser::OperatorNode::OP_PREINC: {} break;
- case GDParser::OperatorNode::OP_PREDEC: {} break;
- case GDParser::OperatorNode::OP_INC: {} break;
- case GDParser::OperatorNode::OP_DEC: {} break;
- case GDParser::OperatorNode::OP_IN: { txt=_parser_expr(c_node->arguments[0])+" in "+_parser_expr(c_node->arguments[1]); } break;
- case GDParser::OperatorNode::OP_EQUAL: { txt=_parser_expr(c_node->arguments[0])+"=="+_parser_expr(c_node->arguments[1]); } break;
- case GDParser::OperatorNode::OP_NOT_EQUAL: { txt=_parser_expr(c_node->arguments[0])+"!="+_parser_expr(c_node->arguments[1]); } break;
- case GDParser::OperatorNode::OP_LESS: { txt=_parser_expr(c_node->arguments[0])+"<"+_parser_expr(c_node->arguments[1]); } break;
- case GDParser::OperatorNode::OP_LESS_EQUAL: { txt=_parser_expr(c_node->arguments[0])+"<="+_parser_expr(c_node->arguments[1]); } break;
- case GDParser::OperatorNode::OP_GREATER: { txt=_parser_expr(c_node->arguments[0])+">"+_parser_expr(c_node->arguments[1]); } break;
- case GDParser::OperatorNode::OP_GREATER_EQUAL: { txt=_parser_expr(c_node->arguments[0])+">="+_parser_expr(c_node->arguments[1]); } break;
- case GDParser::OperatorNode::OP_AND: { txt=_parser_expr(c_node->arguments[0])+" and "+_parser_expr(c_node->arguments[1]); } break;
- case GDParser::OperatorNode::OP_OR: { txt=_parser_expr(c_node->arguments[0])+" or "+_parser_expr(c_node->arguments[1]); } break;
- case GDParser::OperatorNode::OP_ADD: { txt=_parser_expr(c_node->arguments[0])+"+"+_parser_expr(c_node->arguments[1]); } break;
- case GDParser::OperatorNode::OP_SUB: { txt=_parser_expr(c_node->arguments[0])+"-"+_parser_expr(c_node->arguments[1]); } break;
- case GDParser::OperatorNode::OP_MUL: { txt=_parser_expr(c_node->arguments[0])+"*"+_parser_expr(c_node->arguments[1]); } break;
- case GDParser::OperatorNode::OP_DIV: { txt=_parser_expr(c_node->arguments[0])+"/"+_parser_expr(c_node->arguments[1]); } break;
- case GDParser::OperatorNode::OP_MOD: { txt=_parser_expr(c_node->arguments[0])+"%"+_parser_expr(c_node->arguments[1]); } break;
- case GDParser::OperatorNode::OP_SHIFT_LEFT: { txt=_parser_expr(c_node->arguments[0])+"<<"+_parser_expr(c_node->arguments[1]); } break;
- case GDParser::OperatorNode::OP_SHIFT_RIGHT: { txt=_parser_expr(c_node->arguments[0])+">>"+_parser_expr(c_node->arguments[1]); } break;
- case GDParser::OperatorNode::OP_ASSIGN: { txt=_parser_expr(c_node->arguments[0])+"="+_parser_expr(c_node->arguments[1]); } break;
- case GDParser::OperatorNode::OP_ASSIGN_ADD: { txt=_parser_expr(c_node->arguments[0])+"+="+_parser_expr(c_node->arguments[1]); } break;
- case GDParser::OperatorNode::OP_ASSIGN_SUB: { txt=_parser_expr(c_node->arguments[0])+"-="+_parser_expr(c_node->arguments[1]); } break;
- case GDParser::OperatorNode::OP_ASSIGN_MUL: { txt=_parser_expr(c_node->arguments[0])+"*="+_parser_expr(c_node->arguments[1]); } break;
- case GDParser::OperatorNode::OP_ASSIGN_DIV: { txt=_parser_expr(c_node->arguments[0])+"/="+_parser_expr(c_node->arguments[1]); } break;
- case GDParser::OperatorNode::OP_ASSIGN_MOD: { txt=_parser_expr(c_node->arguments[0])+"%="+_parser_expr(c_node->arguments[1]); } break;
- case GDParser::OperatorNode::OP_ASSIGN_SHIFT_LEFT:{ txt=_parser_expr(c_node->arguments[0])+"<<="+_parser_expr(c_node->arguments[1]); } break;
- case GDParser::OperatorNode::OP_ASSIGN_SHIFT_RIGHT: { txt=_parser_expr(c_node->arguments[0])+">>="+_parser_expr(c_node->arguments[1]); } break;
- case GDParser::OperatorNode::OP_ASSIGN_BIT_AND: { txt=_parser_expr(c_node->arguments[0])+"&="+_parser_expr(c_node->arguments[1]); } break;
- case GDParser::OperatorNode::OP_ASSIGN_BIT_OR: { txt=_parser_expr(c_node->arguments[0])+"|="+_parser_expr(c_node->arguments[1]); } break;
- case GDParser::OperatorNode::OP_ASSIGN_BIT_XOR: { txt=_parser_expr(c_node->arguments[0])+"^="+_parser_expr(c_node->arguments[1]); } break;
- case GDParser::OperatorNode::OP_BIT_AND: { txt=_parser_expr(c_node->arguments[0])+"&"+_parser_expr(c_node->arguments[1]); } break;
- case GDParser::OperatorNode::OP_BIT_OR: { txt=_parser_expr(c_node->arguments[0])+"|"+_parser_expr(c_node->arguments[1]); } break;
- case GDParser::OperatorNode::OP_BIT_XOR: { txt=_parser_expr(c_node->arguments[0])+"^"+_parser_expr(c_node->arguments[1]); } break;
-
+ case GDParser::OperatorNode::OP_NEG: {
+ txt = "-" + _parser_expr(c_node->arguments[0]);
+ } break;
+ case GDParser::OperatorNode::OP_NOT: {
+ txt = "not " + _parser_expr(c_node->arguments[0]);
+ } break;
+ case GDParser::OperatorNode::OP_BIT_INVERT: {
+ txt = "~" + _parser_expr(c_node->arguments[0]);
+ } break;
+ case GDParser::OperatorNode::OP_PREINC: {
+ } break;
+ case GDParser::OperatorNode::OP_PREDEC: {
+ } break;
+ case GDParser::OperatorNode::OP_INC: {
+ } break;
+ case GDParser::OperatorNode::OP_DEC: {
+ } break;
+ case GDParser::OperatorNode::OP_IN: {
+ txt = _parser_expr(c_node->arguments[0]) + " in " + _parser_expr(c_node->arguments[1]);
+ } break;
+ case GDParser::OperatorNode::OP_EQUAL: {
+ txt = _parser_expr(c_node->arguments[0]) + "==" + _parser_expr(c_node->arguments[1]);
+ } break;
+ case GDParser::OperatorNode::OP_NOT_EQUAL: {
+ txt = _parser_expr(c_node->arguments[0]) + "!=" + _parser_expr(c_node->arguments[1]);
+ } break;
+ case GDParser::OperatorNode::OP_LESS: {
+ txt = _parser_expr(c_node->arguments[0]) + "<" + _parser_expr(c_node->arguments[1]);
+ } break;
+ case GDParser::OperatorNode::OP_LESS_EQUAL: {
+ txt = _parser_expr(c_node->arguments[0]) + "<=" + _parser_expr(c_node->arguments[1]);
+ } break;
+ case GDParser::OperatorNode::OP_GREATER: {
+ txt = _parser_expr(c_node->arguments[0]) + ">" + _parser_expr(c_node->arguments[1]);
+ } break;
+ case GDParser::OperatorNode::OP_GREATER_EQUAL: {
+ txt = _parser_expr(c_node->arguments[0]) + ">=" + _parser_expr(c_node->arguments[1]);
+ } break;
+ case GDParser::OperatorNode::OP_AND: {
+ txt = _parser_expr(c_node->arguments[0]) + " and " + _parser_expr(c_node->arguments[1]);
+ } break;
+ case GDParser::OperatorNode::OP_OR: {
+ txt = _parser_expr(c_node->arguments[0]) + " or " + _parser_expr(c_node->arguments[1]);
+ } break;
+ case GDParser::OperatorNode::OP_ADD: {
+ txt = _parser_expr(c_node->arguments[0]) + "+" + _parser_expr(c_node->arguments[1]);
+ } break;
+ case GDParser::OperatorNode::OP_SUB: {
+ txt = _parser_expr(c_node->arguments[0]) + "-" + _parser_expr(c_node->arguments[1]);
+ } break;
+ case GDParser::OperatorNode::OP_MUL: {
+ txt = _parser_expr(c_node->arguments[0]) + "*" + _parser_expr(c_node->arguments[1]);
+ } break;
+ case GDParser::OperatorNode::OP_DIV: {
+ txt = _parser_expr(c_node->arguments[0]) + "/" + _parser_expr(c_node->arguments[1]);
+ } break;
+ case GDParser::OperatorNode::OP_MOD: {
+ txt = _parser_expr(c_node->arguments[0]) + "%" + _parser_expr(c_node->arguments[1]);
+ } break;
+ case GDParser::OperatorNode::OP_SHIFT_LEFT: {
+ txt = _parser_expr(c_node->arguments[0]) + "<<" + _parser_expr(c_node->arguments[1]);
+ } break;
+ case GDParser::OperatorNode::OP_SHIFT_RIGHT: {
+ txt = _parser_expr(c_node->arguments[0]) + ">>" + _parser_expr(c_node->arguments[1]);
+ } break;
+ case GDParser::OperatorNode::OP_ASSIGN: {
+ txt = _parser_expr(c_node->arguments[0]) + "=" + _parser_expr(c_node->arguments[1]);
+ } break;
+ case GDParser::OperatorNode::OP_ASSIGN_ADD: {
+ txt = _parser_expr(c_node->arguments[0]) + "+=" + _parser_expr(c_node->arguments[1]);
+ } break;
+ case GDParser::OperatorNode::OP_ASSIGN_SUB: {
+ txt = _parser_expr(c_node->arguments[0]) + "-=" + _parser_expr(c_node->arguments[1]);
+ } break;
+ case GDParser::OperatorNode::OP_ASSIGN_MUL: {
+ txt = _parser_expr(c_node->arguments[0]) + "*=" + _parser_expr(c_node->arguments[1]);
+ } break;
+ case GDParser::OperatorNode::OP_ASSIGN_DIV: {
+ txt = _parser_expr(c_node->arguments[0]) + "/=" + _parser_expr(c_node->arguments[1]);
+ } break;
+ case GDParser::OperatorNode::OP_ASSIGN_MOD: {
+ txt = _parser_expr(c_node->arguments[0]) + "%=" + _parser_expr(c_node->arguments[1]);
+ } break;
+ case GDParser::OperatorNode::OP_ASSIGN_SHIFT_LEFT: {
+ txt = _parser_expr(c_node->arguments[0]) + "<<=" + _parser_expr(c_node->arguments[1]);
+ } break;
+ case GDParser::OperatorNode::OP_ASSIGN_SHIFT_RIGHT: {
+ txt = _parser_expr(c_node->arguments[0]) + ">>=" + _parser_expr(c_node->arguments[1]);
+ } break;
+ case GDParser::OperatorNode::OP_ASSIGN_BIT_AND: {
+ txt = _parser_expr(c_node->arguments[0]) + "&=" + _parser_expr(c_node->arguments[1]);
+ } break;
+ case GDParser::OperatorNode::OP_ASSIGN_BIT_OR: {
+ txt = _parser_expr(c_node->arguments[0]) + "|=" + _parser_expr(c_node->arguments[1]);
+ } break;
+ case GDParser::OperatorNode::OP_ASSIGN_BIT_XOR: {
+ txt = _parser_expr(c_node->arguments[0]) + "^=" + _parser_expr(c_node->arguments[1]);
+ } break;
+ case GDParser::OperatorNode::OP_BIT_AND: {
+ txt = _parser_expr(c_node->arguments[0]) + "&" + _parser_expr(c_node->arguments[1]);
+ } break;
+ case GDParser::OperatorNode::OP_BIT_OR: {
+ txt = _parser_expr(c_node->arguments[0]) + "|" + _parser_expr(c_node->arguments[1]);
+ } break;
+ case GDParser::OperatorNode::OP_BIT_XOR: {
+ txt = _parser_expr(c_node->arguments[0]) + "^" + _parser_expr(c_node->arguments[1]);
+ } break;
}
} break;
@@ -232,71 +298,68 @@ static String _parser_expr(const GDParser::Node *p_expr) {
} break;
default: {
- String error="Parser bug at "+itos(p_expr->line)+", invalid expression type: "+itos(p_expr->type);
+ String error = "Parser bug at " + itos(p_expr->line) + ", invalid expression type: " + itos(p_expr->type);
ERR_EXPLAIN(error);
ERR_FAIL_V("");
-
}
-
}
return txt;
//return "("+txt+")";
}
+static void _parser_show_block(const GDParser::BlockNode *p_block, int p_indent) {
-static void _parser_show_block(const GDParser::BlockNode *p_block,int p_indent) {
-
- for(int i=0;i<p_block->statements.size();i++) {
+ for (int i = 0; i < p_block->statements.size(); i++) {
- const GDParser::Node *statement=p_block->statements[i];
+ const GDParser::Node *statement = p_block->statements[i];
- switch(statement->type) {
+ switch (statement->type) {
case GDParser::Node::TYPE_CONTROL_FLOW: {
const GDParser::ControlFlowNode *cf_node = static_cast<const GDParser::ControlFlowNode *>(statement);
- switch(cf_node->cf_type) {
+ switch (cf_node->cf_type) {
case GDParser::ControlFlowNode::CF_IF: {
- ERR_FAIL_COND(cf_node->arguments.size()!=1);
+ ERR_FAIL_COND(cf_node->arguments.size() != 1);
String txt;
- txt+="if ";
- txt+=_parser_expr(cf_node->arguments[0]);
- txt+=":";
- _print_indent(p_indent,txt);
+ txt += "if ";
+ txt += _parser_expr(cf_node->arguments[0]);
+ txt += ":";
+ _print_indent(p_indent, txt);
ERR_FAIL_COND(!cf_node->body);
- _parser_show_block(cf_node->body,p_indent+1);
+ _parser_show_block(cf_node->body, p_indent + 1);
if (cf_node->body_else) {
- _print_indent(p_indent,"else:");
- _parser_show_block(cf_node->body_else,p_indent+1);
+ _print_indent(p_indent, "else:");
+ _parser_show_block(cf_node->body_else, p_indent + 1);
}
} break;
case GDParser::ControlFlowNode::CF_FOR: {
- ERR_FAIL_COND(cf_node->arguments.size()!=2);
+ ERR_FAIL_COND(cf_node->arguments.size() != 2);
String txt;
- txt+="for ";
- txt+=_parser_expr(cf_node->arguments[0]);
- txt+=" in ";
- txt+=_parser_expr(cf_node->arguments[1]);
- txt+=":";
- _print_indent(p_indent,txt);
+ txt += "for ";
+ txt += _parser_expr(cf_node->arguments[0]);
+ txt += " in ";
+ txt += _parser_expr(cf_node->arguments[1]);
+ txt += ":";
+ _print_indent(p_indent, txt);
ERR_FAIL_COND(!cf_node->body);
- _parser_show_block(cf_node->body,p_indent+1);
+ _parser_show_block(cf_node->body, p_indent + 1);
} break;
case GDParser::ControlFlowNode::CF_WHILE: {
- ERR_FAIL_COND(cf_node->arguments.size()!=1);
+ ERR_FAIL_COND(cf_node->arguments.size() != 1);
String txt;
- txt+="while ";
- txt+=_parser_expr(cf_node->arguments[0]);
- txt+=":";
- _print_indent(p_indent,txt);
+ txt += "while ";
+ txt += _parser_expr(cf_node->arguments[0]);
+ txt += ":";
+ _print_indent(p_indent, txt);
ERR_FAIL_COND(!cf_node->body);
- _parser_show_block(cf_node->body,p_indent+1);
+ _parser_show_block(cf_node->body, p_indent + 1);
} break;
case GDParser::ControlFlowNode::CF_SWITCH: {
@@ -304,18 +367,18 @@ static void _parser_show_block(const GDParser::BlockNode *p_block,int p_indent)
} break;
case GDParser::ControlFlowNode::CF_CONTINUE: {
- _print_indent(p_indent,"continue");
+ _print_indent(p_indent, "continue");
} break;
case GDParser::ControlFlowNode::CF_BREAK: {
- _print_indent(p_indent,"break");
+ _print_indent(p_indent, "break");
} break;
case GDParser::ControlFlowNode::CF_RETURN: {
if (cf_node->arguments.size())
- _print_indent(p_indent,"return "+_parser_expr(cf_node->arguments[0]));
+ _print_indent(p_indent, "return " + _parser_expr(cf_node->arguments[0]));
else
- _print_indent(p_indent,"return ");
+ _print_indent(p_indent, "return ");
} break;
}
@@ -323,121 +386,110 @@ static void _parser_show_block(const GDParser::BlockNode *p_block,int p_indent)
case GDParser::Node::TYPE_LOCAL_VAR: {
const GDParser::LocalVarNode *lv_node = static_cast<const GDParser::LocalVarNode *>(statement);
- _print_indent(p_indent,"var "+String(lv_node->name));
+ _print_indent(p_indent, "var " + String(lv_node->name));
} break;
default: {
//expression i guess
- _print_indent(p_indent,_parser_expr(statement));
-
+ _print_indent(p_indent, _parser_expr(statement));
}
}
}
}
-static void _parser_show_function(const GDParser::FunctionNode *p_func,int p_indent,GDParser::BlockNode *p_initializer=NULL) {
+static void _parser_show_function(const GDParser::FunctionNode *p_func, int p_indent, GDParser::BlockNode *p_initializer = NULL) {
String txt;
if (p_func->_static)
- txt="static ";
- txt+="func ";
- if (p_func->name=="") // initializer
- txt+="[built-in-initializer]";
+ txt = "static ";
+ txt += "func ";
+ if (p_func->name == "") // initializer
+ txt += "[built-in-initializer]";
else
- txt+=String(p_func->name);
- txt+="(";
+ txt += String(p_func->name);
+ txt += "(";
- for(int i=0;i<p_func->arguments.size();i++) {
+ for (int i = 0; i < p_func->arguments.size(); i++) {
- if (i!=0)
- txt+=", ";
- txt+="var "+String(p_func->arguments[i]);
- if (i>=(p_func->arguments.size()-p_func->default_values.size())) {
+ if (i != 0)
+ txt += ", ";
+ txt += "var " + String(p_func->arguments[i]);
+ if (i >= (p_func->arguments.size() - p_func->default_values.size())) {
int defarg = i - (p_func->arguments.size() - p_func->default_values.size());
- txt+="=";
- txt+=_parser_expr(p_func->default_values[defarg]);
+ txt += "=";
+ txt += _parser_expr(p_func->default_values[defarg]);
}
}
- txt+=")";
+ txt += ")";
//todo constructor check!
- txt+=":";
+ txt += ":";
- _print_indent(p_indent,txt);
+ _print_indent(p_indent, txt);
if (p_initializer)
- _parser_show_block(p_initializer,p_indent+1);
- _parser_show_block(p_func->body,p_indent+1);
+ _parser_show_block(p_initializer, p_indent + 1);
+ _parser_show_block(p_func->body, p_indent + 1);
}
-static void _parser_show_class(const GDParser::ClassNode *p_class,int p_indent,const Vector<String>& p_code) {
+static void _parser_show_class(const GDParser::ClassNode *p_class, int p_indent, const Vector<String> &p_code) {
- if (p_indent==0 && (String(p_class->extends_file)!="" || p_class->extends_class.size())) {
+ if (p_indent == 0 && (String(p_class->extends_file) != "" || p_class->extends_class.size())) {
- _print_indent(p_indent,_parser_extends(p_class));
+ _print_indent(p_indent, _parser_extends(p_class));
print_line("\n");
-
}
- for(int i=0;i<p_class->subclasses.size();i++) {
-
+ for (int i = 0; i < p_class->subclasses.size(); i++) {
- const GDParser::ClassNode *subclass=p_class->subclasses[i];
- String line="class "+subclass->name;
- if (String(subclass->extends_file)!="" || subclass->extends_class.size())
- line+=" "+_parser_extends(subclass);
- line+=":";
- _print_indent(p_indent,line);
- _parser_show_class(subclass,p_indent+1,p_code);
+ const GDParser::ClassNode *subclass = p_class->subclasses[i];
+ String line = "class " + subclass->name;
+ if (String(subclass->extends_file) != "" || subclass->extends_class.size())
+ line += " " + _parser_extends(subclass);
+ line += ":";
+ _print_indent(p_indent, line);
+ _parser_show_class(subclass, p_indent + 1, p_code);
print_line("\n");
}
+ for (int i = 0; i < p_class->constant_expressions.size(); i++) {
- for(int i=0;i<p_class->constant_expressions.size();i++) {
-
- const GDParser::ClassNode::Constant &constant=p_class->constant_expressions[i];
- _print_indent(p_indent,"const "+String(constant.identifier)+"="+_parser_expr(constant.expression));
+ const GDParser::ClassNode::Constant &constant = p_class->constant_expressions[i];
+ _print_indent(p_indent, "const " + String(constant.identifier) + "=" + _parser_expr(constant.expression));
}
+ for (int i = 0; i < p_class->variables.size(); i++) {
- for(int i=0;i<p_class->variables.size();i++) {
-
- const GDParser::ClassNode::Member &m=p_class->variables[i];
-
- _print_indent(p_indent,"var "+String(m.identifier));
+ const GDParser::ClassNode::Member &m = p_class->variables[i];
+ _print_indent(p_indent, "var " + String(m.identifier));
}
print_line("\n");
- for(int i=0;i<p_class->static_functions.size();i++) {
+ for (int i = 0; i < p_class->static_functions.size(); i++) {
- _parser_show_function(p_class->static_functions[i],p_indent);
+ _parser_show_function(p_class->static_functions[i], p_indent);
print_line("\n");
-
}
- for(int i=0;i<p_class->functions.size();i++) {
+ for (int i = 0; i < p_class->functions.size(); i++) {
- if (String(p_class->functions[i]->name)=="_init") {
- _parser_show_function(p_class->functions[i],p_indent,p_class->initializer);
+ if (String(p_class->functions[i]->name) == "_init") {
+ _parser_show_function(p_class->functions[i], p_indent, p_class->initializer);
} else
- _parser_show_function(p_class->functions[i],p_indent);
+ _parser_show_function(p_class->functions[i], p_indent);
print_line("\n");
-
}
//_parser_show_function(p_class->initializer,p_indent);
print_line("\n");
-
-
}
+static String _disassemble_addr(const Ref<GDScript> &p_script, const GDFunction &func, int p_addr) {
-static String _disassemble_addr(const Ref<GDScript>& p_script,const GDFunction& func, int p_addr) {
+ int addr = p_addr & GDFunction::ADDR_MASK;
- int addr=p_addr&GDFunction::ADDR_MASK;
-
- switch(p_addr>>GDFunction::ADDR_BITS) {
+ switch (p_addr >> GDFunction::ADDR_BITS) {
case GDFunction::ADDR_TYPE_SELF: {
return "self";
@@ -447,412 +499,396 @@ static String _disassemble_addr(const Ref<GDScript>& p_script,const GDFunction&
} break;
case GDFunction::ADDR_TYPE_MEMBER: {
- return "member("+p_script->debug_get_member_by_index(addr)+")";
+ return "member(" + p_script->debug_get_member_by_index(addr) + ")";
} break;
case GDFunction::ADDR_TYPE_CLASS_CONSTANT: {
- return "class_const("+func.get_global_name(addr)+")";
+ return "class_const(" + func.get_global_name(addr) + ")";
} break;
case GDFunction::ADDR_TYPE_LOCAL_CONSTANT: {
- Variant v=func.get_constant(addr);
+ Variant v = func.get_constant(addr);
String txt;
- if (v.get_type()==Variant::STRING || v.get_type()==Variant::NODE_PATH)
- txt="\""+String(v)+"\"";
+ if (v.get_type() == Variant::STRING || v.get_type() == Variant::NODE_PATH)
+ txt = "\"" + String(v) + "\"";
else
- txt=v;
- return "const("+txt+")";
+ txt = v;
+ return "const(" + txt + ")";
} break;
case GDFunction::ADDR_TYPE_STACK: {
- return "stack("+itos(addr)+")";
+ return "stack(" + itos(addr) + ")";
} break;
case GDFunction::ADDR_TYPE_STACK_VARIABLE: {
- return "var_stack("+itos(addr)+")";
+ return "var_stack(" + itos(addr) + ")";
} break;
case GDFunction::ADDR_TYPE_GLOBAL: {
- return "global("+func.get_global_name(addr)+")";
+ return "global(" + func.get_global_name(addr) + ")";
} break;
case GDFunction::ADDR_TYPE_NIL: {
return "nil";
} break;
-
}
return "<err>";
}
-static void _disassemble_class(const Ref<GDScript>& p_class,const Vector<String>& p_code) {
-
+static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String> &p_code) {
- const Map<StringName,GDFunction*>& mf = p_class->debug_get_member_functions();
+ const Map<StringName, GDFunction *> &mf = p_class->debug_get_member_functions();
- for(const Map<StringName,GDFunction*>::Element *E=mf.front();E;E=E->next()) {
+ for (const Map<StringName, GDFunction *>::Element *E = mf.front(); E; E = E->next()) {
-
- const GDFunction &func=*E->get();
+ const GDFunction &func = *E->get();
const int *code = func.get_code();
- int codelen=func.get_code_size();
+ int codelen = func.get_code_size();
String defargs;
if (func.get_default_argument_count()) {
- defargs="defarg at: ";
- for(int i=0;i<func.get_default_argument_count();i++) {
+ defargs = "defarg at: ";
+ for (int i = 0; i < func.get_default_argument_count(); i++) {
- if (i>0)
- defargs+=",";
- defargs+=itos(func.get_default_argument_addr(i));
+ if (i > 0)
+ defargs += ",";
+ defargs += itos(func.get_default_argument_addr(i));
}
- defargs+=" ";
+ defargs += " ";
}
- print_line("== function "+String(func.get_name())+"() :: stack size: "+itos(func.get_max_stack_size())+" "+defargs+"==");
-
-#define DADDR(m_ip) (_disassemble_addr(p_class,func,code[ip+m_ip]))
+ print_line("== function " + String(func.get_name()) + "() :: stack size: " + itos(func.get_max_stack_size()) + " " + defargs + "==");
- for(int ip=0;ip<codelen;) {
+#define DADDR(m_ip) (_disassemble_addr(p_class, func, code[ip + m_ip]))
+ for (int ip = 0; ip < codelen;) {
- int incr=0;
- String txt=itos(ip)+" ";
+ int incr = 0;
+ String txt = itos(ip) + " ";
- switch(code[ip]) {
+ switch (code[ip]) {
case GDFunction::OPCODE_OPERATOR: {
- int op = code[ip+1];
- txt+="op ";
+ int op = code[ip + 1];
+ txt += "op ";
String opname = Variant::get_operator_name(Variant::Operator(op));
- txt+=DADDR(4);
- txt+=" = ";
- txt+=DADDR(2);
- txt+=" "+opname+" ";
- txt+=DADDR(3);
- incr+=5;
+ txt += DADDR(4);
+ txt += " = ";
+ txt += DADDR(2);
+ txt += " " + opname + " ";
+ txt += DADDR(3);
+ incr += 5;
} break;
case GDFunction::OPCODE_SET: {
- txt+="set ";
- txt+=DADDR(1);
- txt+="[";
- txt+=DADDR(2);
- txt+="]=";
- txt+=DADDR(3);
- incr+=4;
+ txt += "set ";
+ txt += DADDR(1);
+ txt += "[";
+ txt += DADDR(2);
+ txt += "]=";
+ txt += DADDR(3);
+ incr += 4;
} break;
case GDFunction::OPCODE_GET: {
- txt+=" get ";
- txt+=DADDR(3);
- txt+="=";
- txt+=DADDR(1);
- txt+="[";
- txt+=DADDR(2);
- txt+="]";
- incr+=4;
+ txt += " get ";
+ txt += DADDR(3);
+ txt += "=";
+ txt += DADDR(1);
+ txt += "[";
+ txt += DADDR(2);
+ txt += "]";
+ incr += 4;
} break;
case GDFunction::OPCODE_SET_NAMED: {
- txt+=" set_named ";
- txt+=DADDR(1);
- txt+="[\"";
- txt+=func.get_global_name(code[ip+2]);
- txt+="\"]=";
- txt+=DADDR(3);
- incr+=4;
-
+ txt += " set_named ";
+ txt += DADDR(1);
+ txt += "[\"";
+ txt += func.get_global_name(code[ip + 2]);
+ txt += "\"]=";
+ txt += DADDR(3);
+ incr += 4;
} break;
case GDFunction::OPCODE_GET_NAMED: {
- txt+=" get_named ";
- txt+=DADDR(3);
- txt+="=";
- txt+=DADDR(1);
- txt+="[\"";
- txt+=func.get_global_name(code[ip+2]);
- txt+="\"]";
- incr+=4;
+ txt += " get_named ";
+ txt += DADDR(3);
+ txt += "=";
+ txt += DADDR(1);
+ txt += "[\"";
+ txt += func.get_global_name(code[ip + 2]);
+ txt += "\"]";
+ incr += 4;
} break;
case GDFunction::OPCODE_ASSIGN: {
- txt+=" assign ";
- txt+=DADDR(1);
- txt+="=";
- txt+=DADDR(2);
- incr+=3;
-
+ txt += " assign ";
+ txt += DADDR(1);
+ txt += "=";
+ txt += DADDR(2);
+ incr += 3;
} break;
case GDFunction::OPCODE_ASSIGN_TRUE: {
- txt+=" assign ";
- txt+=DADDR(1);
- txt+="= true";
- incr+=2;
+ txt += " assign ";
+ txt += DADDR(1);
+ txt += "= true";
+ incr += 2;
} break;
case GDFunction::OPCODE_ASSIGN_FALSE: {
- txt+=" assign ";
- txt+=DADDR(1);
- txt+="= false";
- incr+=2;
+ txt += " assign ";
+ txt += DADDR(1);
+ txt += "= false";
+ incr += 2;
} break;
case GDFunction::OPCODE_CONSTRUCT: {
- Variant::Type t=Variant::Type(code[ip+1]);
- int argc=code[ip+2];
+ Variant::Type t = Variant::Type(code[ip + 1]);
+ int argc = code[ip + 2];
- txt+=" construct ";
- txt+=DADDR(3+argc);
- txt+=" = ";
+ txt += " construct ";
+ txt += DADDR(3 + argc);
+ txt += " = ";
- txt+=Variant::get_type_name(t)+"(";
- for(int i=0;i<argc;i++) {
+ txt += Variant::get_type_name(t) + "(";
+ for (int i = 0; i < argc; i++) {
- if (i>0)
- txt+=", ";
- txt+=DADDR(i+3);
+ if (i > 0)
+ txt += ", ";
+ txt += DADDR(i + 3);
}
- txt+=")";
+ txt += ")";
- incr=4+argc;
+ incr = 4 + argc;
} break;
case GDFunction::OPCODE_CONSTRUCT_ARRAY: {
- int argc=code[ip+1];
- txt+=" make_array ";
- txt+=DADDR(2+argc);
- txt+=" = [ ";
+ int argc = code[ip + 1];
+ txt += " make_array ";
+ txt += DADDR(2 + argc);
+ txt += " = [ ";
- for(int i=0;i<argc;i++) {
- if (i>0)
- txt+=", ";
- txt+=DADDR(2+i);
+ for (int i = 0; i < argc; i++) {
+ if (i > 0)
+ txt += ", ";
+ txt += DADDR(2 + i);
}
- txt+="]";
+ txt += "]";
- incr+=3+argc;
+ incr += 3 + argc;
} break;
case GDFunction::OPCODE_CONSTRUCT_DICTIONARY: {
- int argc=code[ip+1];
- txt+=" make_dict ";
- txt+=DADDR(2+argc*2);
- txt+=" = { ";
+ int argc = code[ip + 1];
+ txt += " make_dict ";
+ txt += DADDR(2 + argc * 2);
+ txt += " = { ";
- for(int i=0;i<argc;i++) {
- if (i>0)
- txt+=", ";
- txt+=DADDR(2+i*2+0);
- txt+=":";
- txt+=DADDR(2+i*2+1);
+ for (int i = 0; i < argc; i++) {
+ if (i > 0)
+ txt += ", ";
+ txt += DADDR(2 + i * 2 + 0);
+ txt += ":";
+ txt += DADDR(2 + i * 2 + 1);
}
- txt+="}";
+ txt += "}";
- incr+=3+argc*2;
+ incr += 3 + argc * 2;
} break;
case GDFunction::OPCODE_CALL:
case GDFunction::OPCODE_CALL_RETURN: {
- bool ret=code[ip]==GDFunction::OPCODE_CALL_RETURN;
+ bool ret = code[ip] == GDFunction::OPCODE_CALL_RETURN;
if (ret)
- txt+=" call-ret ";
+ txt += " call-ret ";
else
- txt+=" call ";
-
+ txt += " call ";
- int argc=code[ip+1];
+ int argc = code[ip + 1];
if (ret) {
- txt+=DADDR(4+argc)+"=";
+ txt += DADDR(4 + argc) + "=";
}
- txt+=DADDR(2)+".";
- txt+=String(func.get_global_name(code[ip+3]));
- txt+="(";
+ txt += DADDR(2) + ".";
+ txt += String(func.get_global_name(code[ip + 3]));
+ txt += "(";
- for(int i=0;i<argc;i++) {
- if (i>0)
- txt+=", ";
- txt+=DADDR(4+i);
+ for (int i = 0; i < argc; i++) {
+ if (i > 0)
+ txt += ", ";
+ txt += DADDR(4 + i);
}
- txt+=")";
-
+ txt += ")";
- incr=5+argc;
+ incr = 5 + argc;
} break;
case GDFunction::OPCODE_CALL_BUILT_IN: {
- txt+=" call-built-in ";
+ txt += " call-built-in ";
- int argc=code[ip+2];
- txt+=DADDR(3+argc)+"=";
+ int argc = code[ip + 2];
+ txt += DADDR(3 + argc) + "=";
- txt+=GDFunctions::get_func_name(GDFunctions::Function(code[ip+1]));
- txt+="(";
+ txt += GDFunctions::get_func_name(GDFunctions::Function(code[ip + 1]));
+ txt += "(";
- for(int i=0;i<argc;i++) {
- if (i>0)
- txt+=", ";
- txt+=DADDR(3+i);
+ for (int i = 0; i < argc; i++) {
+ if (i > 0)
+ txt += ", ";
+ txt += DADDR(3 + i);
}
- txt+=")";
+ txt += ")";
-
- incr=4+argc;
+ incr = 4 + argc;
} break;
case GDFunction::OPCODE_CALL_SELF_BASE: {
- txt+=" call-self-base ";
+ txt += " call-self-base ";
- int argc=code[ip+2];
- txt+=DADDR(3+argc)+"=";
+ int argc = code[ip + 2];
+ txt += DADDR(3 + argc) + "=";
- txt+=func.get_global_name(code[ip+1]);
- txt+="(";
+ txt += func.get_global_name(code[ip + 1]);
+ txt += "(";
- for(int i=0;i<argc;i++) {
- if (i>0)
- txt+=", ";
- txt+=DADDR(3+i);
+ for (int i = 0; i < argc; i++) {
+ if (i > 0)
+ txt += ", ";
+ txt += DADDR(3 + i);
}
- txt+=")";
-
+ txt += ")";
- incr=4+argc;
+ incr = 4 + argc;
} break;
case GDFunction::OPCODE_YIELD: {
- txt+=" yield ";
- incr=1;
+ txt += " yield ";
+ incr = 1;
} break;
case GDFunction::OPCODE_YIELD_SIGNAL: {
- txt+=" yield_signal ";
- txt+=DADDR(1);
- txt+=",";
- txt+=DADDR(2);
- incr=3;
+ txt += " yield_signal ";
+ txt += DADDR(1);
+ txt += ",";
+ txt += DADDR(2);
+ incr = 3;
} break;
case GDFunction::OPCODE_YIELD_RESUME: {
- txt+=" yield resume: ";
- txt+=DADDR(1);
- incr=2;
+ txt += " yield resume: ";
+ txt += DADDR(1);
+ incr = 2;
} break;
case GDFunction::OPCODE_JUMP: {
- txt+=" jump ";
- txt+=itos(code[ip+1]);
+ txt += " jump ";
+ txt += itos(code[ip + 1]);
- incr=2;
+ incr = 2;
} break;
case GDFunction::OPCODE_JUMP_IF: {
+ txt += " jump-if ";
+ txt += DADDR(1);
+ txt += " to ";
+ txt += itos(code[ip + 2]);
- txt+=" jump-if ";
- txt+=DADDR(1);
- txt+=" to ";
- txt+=itos(code[ip+2]);
-
- incr=3;
+ incr = 3;
} break;
case GDFunction::OPCODE_JUMP_IF_NOT: {
+ txt += " jump-if-not ";
+ txt += DADDR(1);
+ txt += " to ";
+ txt += itos(code[ip + 2]);
- txt+=" jump-if-not ";
- txt+=DADDR(1);
- txt+=" to ";
- txt+=itos(code[ip+2]);
-
- incr=3;
+ incr = 3;
} break;
case GDFunction::OPCODE_JUMP_TO_DEF_ARGUMENT: {
-
- txt+=" jump-to-default-argument ";
- incr=1;
+ txt += " jump-to-default-argument ";
+ incr = 1;
} break;
case GDFunction::OPCODE_RETURN: {
- txt+=" return ";
- txt+=DADDR(1);
+ txt += " return ";
+ txt += DADDR(1);
- incr=2;
+ incr = 2;
} break;
case GDFunction::OPCODE_ITERATE_BEGIN: {
- txt+=" for-init "+DADDR(4)+" in "+DADDR(2)+" counter "+DADDR(1)+" end "+itos(code[ip+3]);
- incr+=5;
+ txt += " for-init " + DADDR(4) + " in " + DADDR(2) + " counter " + DADDR(1) + " end " + itos(code[ip + 3]);
+ incr += 5;
} break;
case GDFunction::OPCODE_ITERATE: {
- txt+=" for-loop "+DADDR(4)+" in "+DADDR(2)+" counter "+DADDR(1)+" end "+itos(code[ip+3]);
- incr+=5;
+ txt += " for-loop " + DADDR(4) + " in " + DADDR(2) + " counter " + DADDR(1) + " end " + itos(code[ip + 3]);
+ incr += 5;
} break;
case GDFunction::OPCODE_LINE: {
-
-
- int line = code[ip+1]-1;
- if (line>=0 && line <p_code.size())
- txt="\n"+itos(line+1)+": "+p_code[line]+"\n";
+ int line = code[ip + 1] - 1;
+ if (line >= 0 && line < p_code.size())
+ txt = "\n" + itos(line + 1) + ": " + p_code[line] + "\n";
else
- txt="";
- incr+=2;
+ txt = "";
+ incr += 2;
} break;
case GDFunction::OPCODE_END: {
- txt+=" end";
- incr+=1;
+ txt += " end";
+ incr += 1;
} break;
case GDFunction::OPCODE_ASSERT: {
- txt+=" assert ";
- txt+=DADDR(1);
- incr+=2;
+ txt += " assert ";
+ txt += DADDR(1);
+ incr += 2;
} break;
-
}
- if (incr==0) {
+ if (incr == 0) {
- ERR_EXPLAIN("unhandled opcode: "+itos(code[ip]));
- ERR_BREAK(incr==0);
+ ERR_EXPLAIN("unhandled opcode: " + itos(code[ip]));
+ ERR_BREAK(incr == 0);
}
- ip+=incr;
- if (txt!="")
+ ip += incr;
+ if (txt != "")
print_line(txt);
}
}
}
-MainLoop* test(TestType p_test) {
+MainLoop *test(TestType p_test) {
List<String> cmdlargs = OS::get_singleton()->get_cmdline_args();
@@ -863,153 +899,137 @@ MainLoop* test(TestType p_test) {
String test = cmdlargs.back()->get();
- FileAccess *fa = FileAccess::open(test,FileAccess::READ);
+ FileAccess *fa = FileAccess::open(test, FileAccess::READ);
if (!fa) {
- ERR_EXPLAIN("Could not open file: "+test);
+ ERR_EXPLAIN("Could not open file: " + test);
ERR_FAIL_V(NULL);
}
-
Vector<uint8_t> buf;
int flen = fa->get_len();
- buf.resize(fa->get_len()+1);
- fa->get_buffer(&buf[0],flen);
- buf[flen]=0;
+ buf.resize(fa->get_len() + 1);
+ fa->get_buffer(&buf[0], flen);
+ buf[flen] = 0;
String code;
- code.parse_utf8((const char*)&buf[0]);
+ code.parse_utf8((const char *)&buf[0]);
Vector<String> lines;
- int last=0;
+ int last = 0;
- for(int i=0;i<=code.length();i++) {
+ for (int i = 0; i <= code.length(); i++) {
- if (code[i]=='\n' || code[i]==0) {
+ if (code[i] == '\n' || code[i] == 0) {
- lines.push_back(code.substr(last,i-last));
- last=i+1;
+ lines.push_back(code.substr(last, i - last));
+ last = i + 1;
}
}
-
- if (p_test==TEST_TOKENIZER) {
+ if (p_test == TEST_TOKENIZER) {
GDTokenizerText tk;
tk.set_code(code);
- int line=-1;
- while(tk.get_token()!=GDTokenizer::TK_EOF) {
-
+ int line = -1;
+ while (tk.get_token() != GDTokenizer::TK_EOF) {
String text;
- if (tk.get_token()==GDTokenizer::TK_IDENTIFIER)
- text="'"+tk.get_token_identifier()+"' (identifier)";
- else if (tk.get_token()==GDTokenizer::TK_CONSTANT) {
- Variant c= tk.get_token_constant();
- if (c.get_type()==Variant::STRING)
- text="\""+String(c)+"\"";
+ if (tk.get_token() == GDTokenizer::TK_IDENTIFIER)
+ text = "'" + tk.get_token_identifier() + "' (identifier)";
+ else if (tk.get_token() == GDTokenizer::TK_CONSTANT) {
+ Variant c = tk.get_token_constant();
+ if (c.get_type() == Variant::STRING)
+ text = "\"" + String(c) + "\"";
else
- text=c;
+ text = c;
- text=text+" ("+Variant::get_type_name(c.get_type())+" constant)";
- } else if (tk.get_token()==GDTokenizer::TK_ERROR)
- text="ERROR: "+tk.get_token_error();
- else if (tk.get_token()==GDTokenizer::TK_NEWLINE)
- text="newline ("+itos(tk.get_token_line())+") + indent: "+itos(tk.get_token_line_indent());
- else if (tk.get_token()==GDTokenizer::TK_BUILT_IN_FUNC)
- text="'"+String(GDFunctions::get_func_name(tk.get_token_built_in_func()))+"' (built-in function)";
+ text = text + " (" + Variant::get_type_name(c.get_type()) + " constant)";
+ } else if (tk.get_token() == GDTokenizer::TK_ERROR)
+ text = "ERROR: " + tk.get_token_error();
+ else if (tk.get_token() == GDTokenizer::TK_NEWLINE)
+ text = "newline (" + itos(tk.get_token_line()) + ") + indent: " + itos(tk.get_token_line_indent());
+ else if (tk.get_token() == GDTokenizer::TK_BUILT_IN_FUNC)
+ text = "'" + String(GDFunctions::get_func_name(tk.get_token_built_in_func())) + "' (built-in function)";
else
- text=tk.get_token_name(tk.get_token());
-
+ text = tk.get_token_name(tk.get_token());
- if (tk.get_token_line()!=line) {
- int from=line+1;
+ if (tk.get_token_line() != line) {
+ int from = line + 1;
line = tk.get_token_line();
- for(int i=from;i<=line;i++) {
- int l=i-1;
- if (l>=0 && l<lines.size()) {
- print_line("\n"+itos(i)+": "+lines[l]+"\n");
+ for (int i = from; i <= line; i++) {
+ int l = i - 1;
+ if (l >= 0 && l < lines.size()) {
+ print_line("\n" + itos(i) + ": " + lines[l] + "\n");
}
}
}
- print_line("\t("+itos(tk.get_token_column())+"): "+text);
+ print_line("\t(" + itos(tk.get_token_column()) + "): " + text);
tk.advance();
-
}
}
- if (p_test==TEST_PARSER) {
-
+ if (p_test == TEST_PARSER) {
GDParser parser;
Error err = parser.parse(code);
if (err) {
- print_line("Parse Error:\n"+itos(parser.get_error_line())+":"+itos(parser.get_error_column())+":"+parser.get_error());
+ print_line("Parse Error:\n" + itos(parser.get_error_line()) + ":" + itos(parser.get_error_column()) + ":" + parser.get_error());
memdelete(fa);
return NULL;
-
}
- const GDParser::Node* root = parser.get_parse_tree();
- ERR_FAIL_COND_V(root->type!=GDParser::Node::TYPE_CLASS,NULL);
- const GDParser::ClassNode *cnode=static_cast<const GDParser::ClassNode*>(root);
-
- _parser_show_class(cnode,0,lines);
+ const GDParser::Node *root = parser.get_parse_tree();
+ ERR_FAIL_COND_V(root->type != GDParser::Node::TYPE_CLASS, NULL);
+ const GDParser::ClassNode *cnode = static_cast<const GDParser::ClassNode *>(root);
+ _parser_show_class(cnode, 0, lines);
}
- if (p_test==TEST_COMPILER) {
-
+ if (p_test == TEST_COMPILER) {
GDParser parser;
Error err = parser.parse(code);
if (err) {
- print_line("Parse Error:\n"+itos(parser.get_error_line())+":"+itos(parser.get_error_column())+":"+parser.get_error());
+ print_line("Parse Error:\n" + itos(parser.get_error_line()) + ":" + itos(parser.get_error_column()) + ":" + parser.get_error());
memdelete(fa);
return NULL;
-
}
- GDScript *script = memnew( GDScript );
+ GDScript *script = memnew(GDScript);
GDCompiler gdc;
- err = gdc.compile(&parser,script);
+ err = gdc.compile(&parser, script);
if (err) {
- print_line("Compile Error:\n"+itos(gdc.get_error_line())+":"+itos(gdc.get_error_column())+":"+gdc.get_error());
+ print_line("Compile Error:\n" + itos(gdc.get_error_line()) + ":" + itos(gdc.get_error_column()) + ":" + gdc.get_error());
memdelete(script);
return NULL;
-
}
+ Ref<GDScript> gds = Ref<GDScript>(script);
- Ref<GDScript> gds =Ref<GDScript>( script );
-
- Ref<GDScript> current=gds;
+ Ref<GDScript> current = gds;
- while(current.is_valid()) {
+ while (current.is_valid()) {
print_line("** CLASS **");
- _disassemble_class(current,lines);
+ _disassemble_class(current, lines);
- current=current->get_base();
+ current = current->get_base();
}
-
-
-
- } else if (p_test==TEST_BYTECODE) {
+ } else if (p_test == TEST_BYTECODE) {
Vector<uint8_t> buf = GDTokenizerBuffer::parse_code_string(code);
- String dst = test.basename()+".gdc";
- FileAccess *fw = FileAccess::open(dst,FileAccess::WRITE);
- fw->store_buffer(buf.ptr(),buf.size());
+ String dst = test.basename() + ".gdc";
+ FileAccess *fw = FileAccess::open(dst, FileAccess::WRITE);
+ fw->store_buffer(buf.ptr(), buf.size());
memdelete(fw);
}
-
#if 0
Parser parser;
Error err = parser.parse(code);
@@ -1020,20 +1040,17 @@ MainLoop* test(TestType p_test) {
}
#endif
-
-
memdelete(fa);
return NULL;
}
-
}
#else
namespace TestGDScript {
-MainLoop* test(TestType p_test) {
+MainLoop *test(TestType p_test) {
return NULL;
}
diff --git a/main/tests/test_gdscript.h b/main/tests/test_gdscript.h
index 225654e2a..3b1ca98ed 100644
--- a/main/tests/test_gdscript.h
+++ b/main/tests/test_gdscript.h
@@ -40,8 +40,7 @@ enum TestType {
TEST_BYTECODE,
};
-MainLoop* test(TestType p_type);
-
+MainLoop *test(TestType p_type);
}
#endif // TEST_GDSCRIPT_H
diff --git a/main/tests/test_gui.cpp b/main/tests/test_gui.cpp
index f7e8191c4..34927f4d6 100644
--- a/main/tests/test_gui.cpp
+++ b/main/tests/test_gui.cpp
@@ -30,51 +30,46 @@
#include "test_gui.h"
-#include "scene/main/scene_main_loop.h"
+#include "io/image_loader.h"
#include "os/os.h"
-#include "scene/gui/control.h"
+#include "print_string.h"
+#include "scene/2d/sprite.h"
#include "scene/gui/button.h"
+#include "scene/gui/control.h"
#include "scene/gui/label.h"
#include "scene/gui/line_edit.h"
-#include "scene/gui/scroll_bar.h"
-#include "scene/gui/popup_menu.h"
-#include "scene/gui/option_button.h"
-#include "scene/gui/spin_box.h"
#include "scene/gui/menu_button.h"
-#include "scene/gui/progress_bar.h"
+#include "scene/gui/option_button.h"
#include "scene/gui/panel.h"
-#include "scene/gui/tab_container.h"
-#include "scene/gui/tree.h"
+#include "scene/gui/popup_menu.h"
+#include "scene/gui/progress_bar.h"
#include "scene/gui/rich_text_label.h"
+#include "scene/gui/scroll_bar.h"
+#include "scene/gui/spin_box.h"
+#include "scene/gui/tab_container.h"
#include "scene/gui/texture_frame.h"
-#include "io/image_loader.h"
-#include "print_string.h"
-#include "scene/2d/sprite.h"
+#include "scene/gui/tree.h"
+#include "scene/main/scene_main_loop.h"
-#include "scene/main/viewport.h"
#include "scene/3d/camera.h"
#include "scene/3d/test_cube.h"
+#include "scene/main/viewport.h"
namespace TestGUI {
-
class TestMainLoop : public SceneTree {
-
Control *control;
public:
-
virtual void request_quit() {
quit();
-
}
virtual void init() {
SceneTree::init();
-
#if 0
@@ -105,35 +100,33 @@ public:
return;
#endif
- Panel * frame = memnew( Panel );
- frame->set_anchor( MARGIN_RIGHT, Control::ANCHOR_END );
- frame->set_anchor( MARGIN_BOTTOM, Control::ANCHOR_END );
- frame->set_end( Point2(0,0) );
+ Panel *frame = memnew(Panel);
+ frame->set_anchor(MARGIN_RIGHT, Control::ANCHOR_END);
+ frame->set_anchor(MARGIN_BOTTOM, Control::ANCHOR_END);
+ frame->set_end(Point2(0, 0));
- Ref<Theme> t = memnew( Theme );
+ Ref<Theme> t = memnew(Theme);
frame->set_theme(t);
- get_root()->add_child( frame );
+ get_root()->add_child(frame);
- Label *label = memnew( Label );
+ Label *label = memnew(Label);
- label->set_pos( Point2( 80,90 ) );
- label->set_size( Point2( 170,80 ) );
- label->set_align( Label::ALIGN_FILL );
+ label->set_pos(Point2(80, 90));
+ label->set_size(Point2(170, 80));
+ label->set_align(Label::ALIGN_FILL);
//label->set_text("There");
label->set_text("There was once upon a time a beautiful unicorn that loved to play with little girls...");
frame->add_child(label);
- Button *button = memnew( Button );
+ Button *button = memnew(Button);
- button->set_pos( Point2( 20,20 ) );
- button->set_size( Point2( 1,1 ) );
+ button->set_pos(Point2(20, 20));
+ button->set_size(Point2(1, 1));
button->set_text("This is a biggie button");
-
- frame->add_child( button );
-
+ frame->add_child(button);
#if 0
Sprite *tf = memnew( Sprite );
@@ -154,90 +147,85 @@ public:
return;
#endif
- Tree * tree = memnew( Tree );
+ Tree *tree = memnew(Tree);
tree->set_columns(2);
- tree->set_pos( Point2( 230,210 ) );
- tree->set_size( Point2( 150,250 ) );
-
+ tree->set_pos(Point2(230, 210));
+ tree->set_size(Point2(150, 250));
TreeItem *item = tree->create_item();
- item->set_editable(0,true);
- item->set_text(0,"root");
- item = tree->create_item( tree->get_root() );
+ item->set_editable(0, true);
+ item->set_text(0, "root");
+ item = tree->create_item(tree->get_root());
item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
- item->set_editable(0,true);
- item->set_text(0,"check");
+ item->set_editable(0, true);
+ item->set_text(0, "check");
item->set_cell_mode(1, TreeItem::CELL_MODE_CHECK);
- item->set_editable(1,true);
- item->set_text(1,"check2");
- item = tree->create_item( tree->get_root() );
+ item->set_editable(1, true);
+ item->set_text(1, "check2");
+ item = tree->create_item(tree->get_root());
item->set_cell_mode(0, TreeItem::CELL_MODE_RANGE);
- item->set_editable(0,true);
- item->set_range_config(0,0,20,0.1);
- item->set_range(0,2);
- item->add_button(0,Theme::get_default()->get_icon("folder","FileDialog"));
+ item->set_editable(0, true);
+ item->set_range_config(0, 0, 20, 0.1);
+ item->set_range(0, 2);
+ item->add_button(0, Theme::get_default()->get_icon("folder", "FileDialog"));
item->set_cell_mode(1, TreeItem::CELL_MODE_RANGE);
- item->set_editable(1,true);
- item->set_range_config(1,0,20,0.1);
- item->set_range(1,3);
+ item->set_editable(1, true);
+ item->set_range_config(1, 0, 20, 0.1);
+ item->set_range(1, 3);
- item = tree->create_item( tree->get_root() );
+ item = tree->create_item(tree->get_root());
item->set_cell_mode(0, TreeItem::CELL_MODE_RANGE);
- item->set_editable(0,true);
- item->set_text(0,"Have,Many,Several,Options!");
- item->set_range(0,2);
+ item->set_editable(0, true);
+ item->set_text(0, "Have,Many,Several,Options!");
+ item->set_range(0, 2);
- item = tree->create_item( item );
- item->set_editable(0,true);
- item->set_text(0,"Gershwin!");
+ item = tree->create_item(item);
+ item->set_editable(0, true);
+ item->set_text(0, "Gershwin!");
frame->add_child(tree);
//control = memnew( Control );
//root->add_child( control );
+ LineEdit *line_edit = memnew(LineEdit);
-
- LineEdit *line_edit = memnew( LineEdit );
-
- line_edit->set_pos( Point2( 30,190 ) );
- line_edit->set_size( Point2( 180,1 ) );
+ line_edit->set_pos(Point2(30, 190));
+ line_edit->set_size(Point2(180, 1));
frame->add_child(line_edit);
- HScrollBar *hscroll = memnew( HScrollBar );
+ HScrollBar *hscroll = memnew(HScrollBar);
- hscroll->set_pos( Point2( 30,290 ) );
- hscroll->set_size( Point2( 180,1 ) );
+ hscroll->set_pos(Point2(30, 290));
+ hscroll->set_size(Point2(180, 1));
hscroll->set_max(10);
hscroll->set_page(4);
frame->add_child(hscroll);
+ SpinBox *spin = memnew(SpinBox);
-
- SpinBox *spin = memnew( SpinBox );
-
- spin->set_pos( Point2( 30,260 ) );
- spin->set_size( Point2( 120,1 ) );
+ spin->set_pos(Point2(30, 260));
+ spin->set_size(Point2(120, 1));
frame->add_child(spin);
hscroll->share(spin);
- ProgressBar *progress = memnew( ProgressBar );
+ ProgressBar *progress = memnew(ProgressBar);
- progress->set_pos( Point2( 30,330 ) );
- progress->set_size( Point2( 120,1 ) );
+ progress->set_pos(Point2(30, 330));
+ progress->set_size(Point2(120, 1));
frame->add_child(progress);
hscroll->share(progress);
- MenuButton *menu_button = memnew( MenuButton );
+ MenuButton *menu_button = memnew(MenuButton);
menu_button->set_text("I'm a menu!");
- menu_button->set_pos( Point2( 30,380 ) );
- menu_button->set_size( Point2( 1,1 ) );
+ menu_button->set_pos(Point2(30, 380));
+ menu_button->set_size(Point2(1, 1));
frame->add_child(menu_button);
@@ -248,15 +236,15 @@ public:
popup->add_separator();
popup->add_item("Popup");
popup->add_check_item("Check Popup");
- popup->set_item_checked(4,true);
+ popup->set_item_checked(4, true);
- OptionButton *options = memnew( OptionButton );
+ OptionButton *options = memnew(OptionButton);
options->add_item("Hello, testing");
options->add_item("My Dearest");
- options->set_pos( Point2( 230,180 ) );
- options->set_size( Point2( 1,1 ) );
+ options->set_pos(Point2(230, 180));
+ options->set_size(Point2(1, 1));
frame->add_child(options);
@@ -290,32 +278,30 @@ public:
frame->add_child(tree);
*/
+ RichTextLabel *richtext = memnew(RichTextLabel);
- RichTextLabel *richtext = memnew( RichTextLabel );
-
- richtext->set_pos( Point2( 600,210 ) );
- richtext->set_size( Point2( 180,250 ) );
- richtext->set_anchor_and_margin(MARGIN_RIGHT,Control::ANCHOR_END,20);
+ richtext->set_pos(Point2(600, 210));
+ richtext->set_size(Point2(180, 250));
+ richtext->set_anchor_and_margin(MARGIN_RIGHT, Control::ANCHOR_END, 20);
frame->add_child(richtext);
-
richtext->add_text("Hello, My Friends!\n\nWelcome to the amazing world of ");
richtext->add_newline();
richtext->add_newline();
- richtext->push_color(Color(1,0.5,0.5));
+ richtext->push_color(Color(1, 0.5, 0.5));
richtext->add_text("leprechauns");
richtext->pop();
richtext->add_text(" and ");
- richtext->push_color(Color(0,1.0,0.5));
+ richtext->push_color(Color(0, 1.0, 0.5));
richtext->add_text("faeries.\n");
richtext->pop();
richtext->add_text("In this new episode, we will attemp to ");
- richtext->push_font(richtext->get_font("mono_font","Fonts"));
- richtext->push_color(Color(0.7,0.5,1.0));
+ richtext->push_font(richtext->get_font("mono_font", "Fonts"));
+ richtext->push_color(Color(0.7, 0.5, 1.0));
richtext->add_text("deliver something nice");
richtext->pop();
richtext->pop();
@@ -333,70 +319,61 @@ public:
richtext->add_text("of the rich text label for huge text (not like this text will really be huge but, you know).\nAs long as it is so long that it will work nicely for a test/demo, then it's welcomed in my book...\nChanging subject, the day is cloudy today and I'm wondering if I'll get che chance to travel somewhere nice. Sometimes, watching the clouds from satellite images may give a nice insight about how pressure zones in our planet work, althogh it also makes it pretty obvious to see why most weather forecasts get it wrong so often.\nClouds are so difficult to predict!\nBut it's pretty cool how our civilization has adapted to having water falling from the sky each time it rains...");
//richtext->add_text("Hello!\nGorgeous..");
-
//richtext->push_meta("http://www.scrollingcapabilities.xz");
///richtext->add_text("Hello!\n");
//richtext->pop();
- richtext->set_anchor(MARGIN_RIGHT,Control::ANCHOR_END);
+ richtext->set_anchor(MARGIN_RIGHT, Control::ANCHOR_END);
+ TabContainer *tabc = memnew(TabContainer);
- TabContainer * tabc = memnew( TabContainer );
-
- Control *ctl= memnew( Control );
+ Control *ctl = memnew(Control);
ctl->set_name("tab 1");
tabc->add_child(ctl);
- ctl= memnew( Control );
+ ctl = memnew(Control);
ctl->set_name("tab 2");
tabc->add_child(ctl);
- label = memnew( Label );
+ label = memnew(Label);
label->set_text("Some Label");
- label->set_pos( Point2(20,20) );
+ label->set_pos(Point2(20, 20));
ctl->add_child(label);
- ctl= memnew( Control );
+ ctl = memnew(Control);
ctl->set_name("tab 3");
- button = memnew( Button );
+ button = memnew(Button);
button->set_text("Some Button");
- button->set_pos( Point2(30,50) );
+ button->set_pos(Point2(30, 50));
ctl->add_child(button);
tabc->add_child(ctl);
frame->add_child(tabc);
- tabc->set_pos( Point2( 400,210 ) );
- tabc->set_size( Point2( 180,250 ) );
-
+ tabc->set_pos(Point2(400, 210));
+ tabc->set_size(Point2(180, 250));
- Ref<ImageTexture> text = memnew( ImageTexture );
+ Ref<ImageTexture> text = memnew(ImageTexture);
text->load("test_data/concave.png");
- Sprite* sprite = memnew(Sprite);
+ Sprite *sprite = memnew(Sprite);
sprite->set_texture(text);
sprite->set_pos(Point2(300, 300));
frame->add_child(sprite);
sprite->show();
- Sprite* sprite2 = memnew(Sprite);
+ Sprite *sprite2 = memnew(Sprite);
sprite->set_texture(text);
sprite->add_child(sprite2);
sprite2->set_pos(Point2(50, 50));
sprite2->show();
}
-
-
-
};
+MainLoop *test() {
-MainLoop* test() {
-
-
- return memnew( TestMainLoop );
+ return memnew(TestMainLoop);
}
-
}
#endif
diff --git a/main/tests/test_gui.h b/main/tests/test_gui.h
index 5526320b0..aef3eefb9 100644
--- a/main/tests/test_gui.h
+++ b/main/tests/test_gui.h
@@ -36,9 +36,7 @@
*/
namespace TestGUI {
-MainLoop* test();
-
+MainLoop *test();
}
-
#endif
diff --git a/main/tests/test_image.cpp b/main/tests/test_image.cpp
index bf9851cf0..5ed210bc9 100644
--- a/main/tests/test_image.cpp
+++ b/main/tests/test_image.cpp
@@ -27,25 +27,23 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "test_image.h"
-#include "os/main_loop.h"
+#include "io/image_loader.h"
#include "math_funcs.h"
+#include "os/main_loop.h"
#include "print_string.h"
-#include "io/image_loader.h"
namespace TestImage {
-
class TestMainLoop : public MainLoop {
bool quit;
-public:
- virtual void input_event(const InputEvent& p_event) {
-
+public:
+ virtual void input_event(const InputEvent &p_event) {
}
virtual void init() {
- quit=false;
+ quit = false;
}
virtual bool iteration(float p_time) {
@@ -57,21 +55,16 @@ public:
}
virtual void finish() {
-
}
-
};
-
-MainLoop* test() {
+MainLoop *test() {
Image img;
- ImageLoader::load_image("as1.png",&img);
-
- img.resize(512,512);
+ ImageLoader::load_image("as1.png", &img);
- return memnew( TestMainLoop );
+ img.resize(512, 512);
+ return memnew(TestMainLoop);
}
-
}
diff --git a/main/tests/test_image.h b/main/tests/test_image.h
index 09b33e799..e1974125e 100644
--- a/main/tests/test_image.h
+++ b/main/tests/test_image.h
@@ -37,8 +37,7 @@
namespace TestImage {
-MainLoop* test();
-
+MainLoop *test();
}
#endif
diff --git a/main/tests/test_io.cpp b/main/tests/test_io.cpp
index a8e8d7d0f..cc6b92070 100644
--- a/main/tests/test_io.cpp
+++ b/main/tests/test_io.cpp
@@ -30,31 +30,25 @@
#ifdef MINIZIP_ENABLED
-
-
-#include "os/main_loop.h"
-#include "os/os.h"
-#include "scene/resources/texture.h"
-#include "print_string.h"
+#include "core/globals.h"
#include "io/resource_loader.h"
#include "io/resource_saver.h"
#include "os/dir_access.h"
-#include "core/globals.h"
+#include "os/main_loop.h"
+#include "os/os.h"
+#include "print_string.h"
+#include "scene/resources/texture.h"
#include "io/file_access_memory.h"
namespace TestIO {
-
class TestMainLoop : public MainLoop {
-
bool quit;
public:
- virtual void input_event(const InputEvent& p_event) {
-
-
+ virtual void input_event(const InputEvent &p_event) {
}
virtual bool idle(float p_time) {
return false;
@@ -62,53 +56,48 @@ public:
virtual void request_quit() {
- quit=true;
-
+ quit = true;
}
virtual void init() {
- quit=true;
+ quit = true;
}
virtual bool iteration(float p_time) {
return quit;
}
virtual void finish() {
-
}
-
-
};
-
-MainLoop* test() {
+MainLoop *test() {
print_line("this is test io");
- DirAccess* da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
+ DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
da->change_dir(".");
- print_line("Opening current dir "+ da->get_current_dir());
+ print_line("Opening current dir " + da->get_current_dir());
String entry;
da->list_dir_begin();
- while ( (entry = da->get_next()) != "") {
+ while ((entry = da->get_next()) != "") {
- print_line("entry "+entry+" is dir: " + Variant(da->current_is_dir()));
+ print_line("entry " + entry + " is dir: " + Variant(da->current_is_dir()));
};
da->list_dir_end();
RES texture = ResourceLoader::load("test_data/rock.png");
ERR_FAIL_COND_V(texture.is_null(), NULL);
- ResourceSaver::save("test_data/rock.xml",texture);
+ ResourceSaver::save("test_data/rock.xml", texture);
print_line("localize paths");
print_line(Globals::get_singleton()->localize_path("algo.xml"));
print_line(Globals::get_singleton()->localize_path("c:\\windows\\algo.xml"));
- print_line(Globals::get_singleton()->localize_path(Globals::get_singleton()->get_resource_path()+"/something/something.xml"));
+ print_line(Globals::get_singleton()->localize_path(Globals::get_singleton()->get_resource_path() + "/something/something.xml"));
print_line(Globals::get_singleton()->localize_path("somedir/algo.xml"));
{
- FileAccess* z = FileAccess::open("test_data/archive.zip", FileAccess::READ);
+ FileAccess *z = FileAccess::open("test_data/archive.zip", FileAccess::READ);
int len = z->get_len();
Vector<uint8_t> zip;
zip.resize(len);
@@ -186,23 +175,17 @@ MainLoop* test() {
print_line("test done");
-
- return memnew( TestMainLoop );
-
+ return memnew(TestMainLoop);
}
-
}
#else
namespace TestIO {
-
-MainLoop* test() {
+MainLoop *test() {
return NULL;
}
-
}
#endif
-
diff --git a/main/tests/test_io.h b/main/tests/test_io.h
index c839590ab..9b23eab12 100644
--- a/main/tests/test_io.h
+++ b/main/tests/test_io.h
@@ -37,8 +37,7 @@
namespace TestIO {
-MainLoop* test();
-
+MainLoop *test();
}
#endif
diff --git a/main/tests/test_main.cpp b/main/tests/test_main.cpp
index 363aede96..4c2857b5c 100644
--- a/main/tests/test_main.cpp
+++ b/main/tests/test_main.cpp
@@ -31,27 +31,26 @@
#ifdef DEBUG_ENABLED
-#include "test_string.h"
#include "test_containers.h"
-#include "test_math.h"
+#include "test_detailer.h"
+#include "test_gdscript.h"
#include "test_gui.h"
-#include "test_render.h"
-#include "test_sound.h"
+#include "test_image.h"
+#include "test_io.h"
+#include "test_math.h"
#include "test_misc.h"
+#include "test_particles.h"
#include "test_physics.h"
#include "test_physics_2d.h"
#include "test_python.h"
-#include "test_io.h"
-#include "test_particles.h"
-#include "test_detailer.h"
+#include "test_render.h"
#include "test_shader_lang.h"
-#include "test_gdscript.h"
-#include "test_image.h"
-
+#include "test_sound.h"
+#include "test_string.h"
-const char ** tests_get_names() {
+const char **tests_get_names() {
- static const char* test_names[]={
+ static const char *test_names[] = {
"string",
"containers",
"math",
@@ -68,109 +67,108 @@ const char ** tests_get_names() {
return test_names;
}
-MainLoop* test_main(String p_test,const List<String>& p_args) {
+MainLoop *test_main(String p_test, const List<String> &p_args) {
-
- if (p_test=="string") {
+ if (p_test == "string") {
return TestString::test();
}
- if (p_test=="containers") {
+ if (p_test == "containers") {
return TestContainers::test();
}
- if (p_test=="math") {
+ if (p_test == "math") {
return TestMath::test();
}
- if (p_test=="physics") {
+ if (p_test == "physics") {
return TestPhysics::test();
}
- if (p_test=="physics_2d") {
+ if (p_test == "physics_2d") {
return TestPhysics2D::test();
}
- if (p_test=="misc") {
+ if (p_test == "misc") {
return TestMisc::test();
}
- if (p_test=="render") {
+ if (p_test == "render") {
return TestRender::test();
}
- #ifndef _3D_DISABLED
- if (p_test=="gui") {
+#ifndef _3D_DISABLED
+ if (p_test == "gui") {
return TestGUI::test();
}
- #endif
+#endif
- if (p_test=="sound") {
+ if (p_test == "sound") {
return TestSound::test();
}
- if (p_test=="io") {
+ if (p_test == "io") {
return TestIO::test();
}
- if (p_test=="particles") {
+ if (p_test == "particles") {
return TestParticles::test();
}
- if (p_test=="multimesh") {
+ if (p_test == "multimesh") {
return TestMultiMesh::test();
}
- if (p_test=="shaderlang") {
+ if (p_test == "shaderlang") {
return TestShaderLang::test();
}
- if (p_test=="gd_tokenizer") {
+ if (p_test == "gd_tokenizer") {
return TestGDScript::test(TestGDScript::TEST_TOKENIZER);
}
- if (p_test=="gd_parser") {
+ if (p_test == "gd_parser") {
return TestGDScript::test(TestGDScript::TEST_PARSER);
}
- if (p_test=="gd_compiler") {
+ if (p_test == "gd_compiler") {
return TestGDScript::test(TestGDScript::TEST_COMPILER);
}
- if (p_test=="gd_bytecode") {
+ if (p_test == "gd_bytecode") {
return TestGDScript::test(TestGDScript::TEST_BYTECODE);
}
- if (p_test=="image") {
+ if (p_test == "image") {
return TestImage::test();
}
- if (p_test=="detailer") {
+ if (p_test == "detailer") {
return TestMultiMesh::test();
}
#ifdef PYTHON_ENABLED
- if (p_test=="python") {
+ if (p_test == "python") {
return TestPython::test();
}
@@ -181,16 +179,16 @@ MainLoop* test_main(String p_test,const List<String>& p_args) {
#else
-const char ** tests_get_names() {
+const char **tests_get_names() {
- static const char* test_names[]={
+ static const char *test_names[] = {
NULL
};
return test_names;
}
-MainLoop* test_main(String p_test,const List<String>& p_args) {
+MainLoop *test_main(String p_test, const List<String> &p_args) {
return NULL;
}
diff --git a/main/tests/test_main.h b/main/tests/test_main.h
index c8d571a7d..89c35b2cc 100644
--- a/main/tests/test_main.h
+++ b/main/tests/test_main.h
@@ -29,13 +29,10 @@
#ifndef TEST_MAIN_H
#define TEST_MAIN_H
-#include "ustring.h"
#include "list.h"
+#include "ustring.h"
-const char ** tests_get_names();
-MainLoop* test_main(String p_test,const List<String>& p_args);
-
+const char **tests_get_names();
+MainLoop *test_main(String p_test, const List<String> &p_args);
#endif
-
-
diff --git a/main/tests/test_math.cpp b/main/tests/test_math.cpp
index 4b686e8af..e760d1ec7 100644
--- a/main/tests/test_math.cpp
+++ b/main/tests/test_math.cpp
@@ -27,38 +27,35 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "test_math.h"
-#include "ustring.h"
-#include "print_string.h"
-#include "transform.h"
-#include "matrix3.h"
-#include "math_funcs.h"
#include "camera_matrix.h"
-#include "scene/main/node.h"
-#include "variant.h"
-#include "servers/visual/shader_language.h"
+#include "math_funcs.h"
+#include "matrix3.h"
#include "os/keyboard.h"
+#include "os/os.h"
+#include "print_string.h"
+#include "scene/main/node.h"
#include "scene/resources/texture.h"
+#include "servers/visual/shader_language.h"
+#include "transform.h"
+#include "ustring.h"
+#include "variant.h"
#include "vmap.h"
-#include "os/os.h"
#include "method_ptrcall.h"
namespace TestMath {
-
void test_vec(Plane p_vec) {
-
CameraMatrix cm;
- cm.set_perspective(45,1,0,100);
- Plane v0=cm.xform4(p_vec);
-
- print_line("out: "+v0);
- v0.normal.z = (v0.d/100.0 *2.0-1.0) * v0.d;
- print_line("out_F: "+v0);
+ cm.set_perspective(45, 1, 0, 100);
+ Plane v0 = cm.xform4(p_vec);
+ print_line("out: " + v0);
+ v0.normal.z = (v0.d / 100.0 * 2.0 - 1.0) * v0.d;
+ print_line("out_F: " + v0);
-/*v0: 0, 0, -0.1, 0.1
+ /*v0: 0, 0, -0.1, 0.1
v1: 0, 0, 0, 0.1
fix: 0, 0, 0, 0.1
v0: 0, 0, 1.302803, 1.5
@@ -74,46 +71,39 @@ v0: 0, 0, 100, 100
v1: 0, 0, 100, 100
fix: 0, 0, 100, 100
*/
-
-
}
-uint32_t ihash( uint32_t a)
-{
- a = (a+0x7ed55d16) + (a<<12);
- a = (a^0xc761c23c) ^ (a>>19);
- a = (a+0x165667b1) + (a<<5);
- a = (a+0xd3a2646c) ^ (a<<9);
- a = (a+0xfd7046c5) + (a<<3);
- a = (a^0xb55a4f09) ^ (a>>16);
- return a;
+uint32_t ihash(uint32_t a) {
+ a = (a + 0x7ed55d16) + (a << 12);
+ a = (a ^ 0xc761c23c) ^ (a >> 19);
+ a = (a + 0x165667b1) + (a << 5);
+ a = (a + 0xd3a2646c) ^ (a << 9);
+ a = (a + 0xfd7046c5) + (a << 3);
+ a = (a ^ 0xb55a4f09) ^ (a >> 16);
+ return a;
}
-uint32_t ihash2( uint32_t a) {
- a = (a ^ 61) ^ (a >> 16);
- a = a + (a << 3);
- a = a ^ (a >> 4);
- a = a * 0x27d4eb2d;
- a = a ^ (a >> 15);
- return a;
+uint32_t ihash2(uint32_t a) {
+ a = (a ^ 61) ^ (a >> 16);
+ a = a + (a << 3);
+ a = a ^ (a >> 4);
+ a = a * 0x27d4eb2d;
+ a = a ^ (a >> 15);
+ return a;
}
-uint32_t ihash3( uint32_t a)
-{
- a = (a+0x479ab41d) + (a<<8);
- a = (a^0xe4aa10ce) ^ (a>>5);
- a = (a+0x9942f0a6) - (a<<14);
- a = (a^0x5aedd67d) ^ (a>>3);
- a = (a+0x17bea992) + (a<<7);
- return a;
+uint32_t ihash3(uint32_t a) {
+ a = (a + 0x479ab41d) + (a << 8);
+ a = (a ^ 0xe4aa10ce) ^ (a >> 5);
+ a = (a + 0x9942f0a6) - (a << 14);
+ a = (a ^ 0x5aedd67d) ^ (a >> 3);
+ a = (a + 0x17bea992) + (a << 7);
+ return a;
}
+MainLoop *test() {
-
-
-MainLoop* test() {
-
- print_line(itos(Math::step_decimals( 0.0001 )));
+ print_line(itos(Math::step_decimals(0.0001)));
return NULL;
{
@@ -122,35 +112,33 @@ MainLoop* test() {
List<StringName> tl;
ObjectTypeDB::get_type_list(&tl);
-
- for (List<StringName>::Element *E=tl.front();E;E=E->next()) {
+ for (List<StringName>::Element *E = tl.front(); E; E = E->next()) {
Vector<uint8_t> m5b = E->get().operator String().md5_buffer();
hashes.push_back(hashes.size());
-
}
//hashes.resize(50);
- for(int i=nearest_shift(hashes.size());i<20;i++) {
+ for (int i = nearest_shift(hashes.size()); i < 20; i++) {
- bool success=true;
- for(int s=0;s<10000;s++) {
+ bool success = true;
+ for (int s = 0; s < 10000; s++) {
Set<uint32_t> existing;
- success=true;
+ success = true;
- for(int j=0;j<hashes.size();j++) {
+ for (int j = 0; j < hashes.size(); j++) {
- uint32_t eh = ihash2(ihash3(hashes[j]+ihash(s)+s))&((1<<i)-1);
+ uint32_t eh = ihash2(ihash3(hashes[j] + ihash(s) + s)) & ((1 << i) - 1);
if (existing.has(eh)) {
- success=false;
+ success = false;
break;
}
existing.insert(eh);
}
if (success) {
- print_line("success at "+itos(i)+"/"+itos(nearest_shift(hashes.size()))+" shift "+itos(s));
+ print_line("success at " + itos(i) + "/" + itos(nearest_shift(hashes.size())) + " shift " + itos(s));
break;
}
}
@@ -160,47 +148,42 @@ MainLoop* test() {
print_line("DONE");
-
-
return NULL;
}
{
-
- // print_line("NUM: "+itos(237641278346127));
- print_line("NUM: "+itos(-128));
+ // print_line("NUM: "+itos(237641278346127));
+ print_line("NUM: " + itos(-128));
return NULL;
-
}
-
{
- Vector3 v(1,2,3);
+ Vector3 v(1, 2, 3);
v.normalize();
- float a=0.3;
+ float a = 0.3;
//Quat q(v,a);
- Matrix3 m(v,a);
+ Matrix3 m(v, a);
- Vector3 v2(7,3,1);
+ Vector3 v2(7, 3, 1);
v2.normalize();
- float a2=0.8;
+ float a2 = 0.8;
//Quat q(v,a);
- Matrix3 m2(v2,a2);
+ Matrix3 m2(v2, a2);
- Quat q=m;
- Quat q2=m2;
+ Quat q = m;
+ Quat q2 = m2;
Matrix3 m3 = m.inverse() * m2;
- Quat q3 = (q.inverse() * q2);//.normalized();
+ Quat q3 = (q.inverse() * q2); //.normalized();
print_line(Quat(m3));
print_line(q3);
- print_line("before v: "+v+" a: "+rtos(a));
- q.get_axis_and_angle(v,a);
- print_line("after v: "+v+" a: "+rtos(a));
+ print_line("before v: " + v + " a: " + rtos(a));
+ q.get_axis_and_angle(v, a);
+ print_line("after v: " + v + " a: " + rtos(a));
}
return NULL;
@@ -208,98 +191,91 @@ MainLoop* test() {
List<String> args;
args.push_back("-l");
- Error err = OS::get_singleton()->execute("/bin/ls",args,true,NULL,&ret);
- print_line("error: "+itos(err));
+ Error err = OS::get_singleton()->execute("/bin/ls", args, true, NULL, &ret);
+ print_line("error: " + itos(err));
print_line(ret);
return NULL;
Matrix3 m3;
- m3.rotate(Vector3(1,0,0),0.2);
- m3.rotate(Vector3(0,1,0),1.77);
- m3.rotate(Vector3(0,0,1),212);
+ m3.rotate(Vector3(1, 0, 0), 0.2);
+ m3.rotate(Vector3(0, 1, 0), 1.77);
+ m3.rotate(Vector3(0, 0, 1), 212);
Matrix3 m32;
m32.set_euler(m3.get_euler());
- print_line("ELEULEEEEEEEEEEEEEEEEEER: "+m3.get_euler()+" vs "+m32.get_euler());
-
+ print_line("ELEULEEEEEEEEEEEEEEEEEER: " + m3.get_euler() + " vs " + m32.get_euler());
return NULL;
{
Dictionary d;
- d["momo"]=1;
- Dictionary b=d;
- b["44"]=4;
+ d["momo"] = 1;
+ Dictionary b = d;
+ b["44"] = 4;
}
-
-
return NULL;
- print_line("inters: "+rtos(Geometry::segment_intersects_circle(Vector2(-5,0),Vector2(-2,0),Vector2(),1.0)));
-
+ print_line("inters: " + rtos(Geometry::segment_intersects_circle(Vector2(-5, 0), Vector2(-2, 0), Vector2(), 1.0)));
-
- print_line("cross: "+Vector3(1,2,3).cross(Vector3(4,5,7)));
- print_line("dot: "+rtos(Vector3(1,2,3).dot(Vector3(4,5,7))));
- print_line("abs: "+Vector3(-1,2,-3).abs());
- print_line("distance_to: "+rtos(Vector3(1,2,3).distance_to(Vector3(4,5,7))));
- print_line("distance_squared_to: "+rtos(Vector3(1,2,3).distance_squared_to(Vector3(4,5,7))));
- print_line("plus: "+(Vector3(1,2,3)+Vector3(Vector3(4,5,7))));
- print_line("minus: "+(Vector3(1,2,3)-Vector3(Vector3(4,5,7))));
- print_line("mul: "+(Vector3(1,2,3)*Vector3(Vector3(4,5,7))));
- print_line("div: "+(Vector3(1,2,3)/Vector3(Vector3(4,5,7))));
- print_line("mul scalar: "+(Vector3(1,2,3)*2));
- print_line("premul scalar: "+(2*Vector3(1,2,3)));
- print_line("div scalar: "+(Vector3(1,2,3)/3.0));
- print_line("length: "+rtos(Vector3(1,2,3).length()));
- print_line("length squared: "+rtos(Vector3(1,2,3).length_squared()));
- print_line("normalized: "+Vector3(1,2,3).normalized());
- print_line("inverse: "+Vector3(1,2,3).inverse());
+ print_line("cross: " + Vector3(1, 2, 3).cross(Vector3(4, 5, 7)));
+ print_line("dot: " + rtos(Vector3(1, 2, 3).dot(Vector3(4, 5, 7))));
+ print_line("abs: " + Vector3(-1, 2, -3).abs());
+ print_line("distance_to: " + rtos(Vector3(1, 2, 3).distance_to(Vector3(4, 5, 7))));
+ print_line("distance_squared_to: " + rtos(Vector3(1, 2, 3).distance_squared_to(Vector3(4, 5, 7))));
+ print_line("plus: " + (Vector3(1, 2, 3) + Vector3(Vector3(4, 5, 7))));
+ print_line("minus: " + (Vector3(1, 2, 3) - Vector3(Vector3(4, 5, 7))));
+ print_line("mul: " + (Vector3(1, 2, 3) * Vector3(Vector3(4, 5, 7))));
+ print_line("div: " + (Vector3(1, 2, 3) / Vector3(Vector3(4, 5, 7))));
+ print_line("mul scalar: " + (Vector3(1, 2, 3) * 2));
+ print_line("premul scalar: " + (2 * Vector3(1, 2, 3)));
+ print_line("div scalar: " + (Vector3(1, 2, 3) / 3.0));
+ print_line("length: " + rtos(Vector3(1, 2, 3).length()));
+ print_line("length squared: " + rtos(Vector3(1, 2, 3).length_squared()));
+ print_line("normalized: " + Vector3(1, 2, 3).normalized());
+ print_line("inverse: " + Vector3(1, 2, 3).inverse());
{
- Vector3 v(4,5,7);
+ Vector3 v(4, 5, 7);
v.normalize();
- print_line("normalize: "+v);
+ print_line("normalize: " + v);
}
{
- Vector3 v(4,5,7);
- v+=Vector3(1,2,3);
- print_line("+=: "+v);
+ Vector3 v(4, 5, 7);
+ v += Vector3(1, 2, 3);
+ print_line("+=: " + v);
}
{
- Vector3 v(4,5,7);
- v-=Vector3(1,2,3);
- print_line("-=: "+v);
+ Vector3 v(4, 5, 7);
+ v -= Vector3(1, 2, 3);
+ print_line("-=: " + v);
}
{
- Vector3 v(4,5,7);
- v*=Vector3(1,2,3);
- print_line("*=: "+v);
+ Vector3 v(4, 5, 7);
+ v *= Vector3(1, 2, 3);
+ print_line("*=: " + v);
}
{
- Vector3 v(4,5,7);
- v/=Vector3(1,2,3);
- print_line("/=: "+v);
+ Vector3 v(4, 5, 7);
+ v /= Vector3(1, 2, 3);
+ print_line("/=: " + v);
}
{
- Vector3 v(4,5,7);
- v*=2.0;
- print_line("scalar *=: "+v);
+ Vector3 v(4, 5, 7);
+ v *= 2.0;
+ print_line("scalar *=: " + v);
}
{
- Vector3 v(4,5,7);
- v/=2.0;
- print_line("scalar /=: "+v);
+ Vector3 v(4, 5, 7);
+ v /= 2.0;
+ print_line("scalar /=: " + v);
}
-
-
#if 0
print_line(String("C:\\momo\\.\\popo\\..\\gongo").simplify_path());
print_line(String("res://../popo/..//gongo").simplify_path());
@@ -381,7 +357,5 @@ MainLoop* test() {
#endif
return NULL;
-
}
-
}
diff --git a/main/tests/test_math.h b/main/tests/test_math.h
index 492c3a183..af1d6db6f 100644
--- a/main/tests/test_math.h
+++ b/main/tests/test_math.h
@@ -33,8 +33,7 @@
namespace TestMath {
-MainLoop* test();
-
+MainLoop *test();
}
#endif
diff --git a/main/tests/test_misc.cpp b/main/tests/test_misc.cpp
index 68564c62b..9133f31fa 100644
--- a/main/tests/test_misc.cpp
+++ b/main/tests/test_misc.cpp
@@ -27,16 +27,14 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "test_misc.h"
-#include "servers/visual_server.h"
-#include "os/main_loop.h"
#include "math_funcs.h"
+#include "os/main_loop.h"
#include "print_string.h"
-
+#include "servers/visual_server.h"
namespace TestMisc {
-struct ConvexTestResult
-{
+struct ConvexTestResult {
Vector3 edgeA[2];
Vector3 edgeB[2];
@@ -65,13 +63,10 @@ struct ConvexTestResult
neSwap(contactA, contactB);
contactNormal *= -1.0f;
}*/
- bool ComputerEdgeContactPoint2(float & au, float & bu);
+ bool ComputerEdgeContactPoint2(float &au, float &bu);
};
-
-
-bool ConvexTestResult::ComputerEdgeContactPoint2(float & au, float & bu)
-{
+bool ConvexTestResult::ComputerEdgeContactPoint2(float &au, float &bu) {
float d1343, d4321, d1321, d4343, d2121;
float numer, denom;
@@ -83,16 +78,14 @@ bool ConvexTestResult::ComputerEdgeContactPoint2(float & au, float & bu)
p13 = (edgeA[0]) - (edgeB[0]);
p43 = (edgeB[1]) - (edgeB[0]);
- if ( p43.length_squared() < CMP_EPSILON2 )
- {
+ if (p43.length_squared() < CMP_EPSILON2) {
valid = false;
goto ComputerEdgeContactPoint2_Exit;
}
p21 = (edgeA[1]) - (edgeA[0]);
- if ( p21.length_squared()<CMP_EPSILON2 )
- {
+ if (p21.length_squared() < CMP_EPSILON2) {
valid = false;
goto ComputerEdgeContactPoint2_Exit;
}
@@ -105,8 +98,7 @@ bool ConvexTestResult::ComputerEdgeContactPoint2(float & au, float & bu)
denom = d2121 * d4343 - d4321 * d4321;
- if (ABS(denom) < CMP_EPSILON)
- {
+ if (ABS(denom) < CMP_EPSILON) {
valid = false;
goto ComputerEdgeContactPoint2_Exit;
@@ -116,16 +108,11 @@ bool ConvexTestResult::ComputerEdgeContactPoint2(float & au, float & bu)
au = numer / denom;
bu = (d1343 + d4321 * (au)) / d4343;
- if (au < 0.0f || au >= 1.0f)
- {
+ if (au < 0.0f || au >= 1.0f) {
valid = false;
- }
- else if (bu < 0.0f || bu >= 1.0f)
- {
+ } else if (bu < 0.0f || bu >= 1.0f) {
valid = false;
- }
- else
- {
+ } else {
valid = true;
}
{
@@ -158,7 +145,6 @@ struct neCollisionResult {
Vector3 contactB;
};
-
struct TConvex {
float radius;
@@ -167,14 +153,13 @@ struct TConvex {
float CylinderHalfHeight() const { return half_height; }
};
-float GetDistanceFromLine2(Vector3 v, Vector3 & project, const Vector3 & pointA, const Vector3 & pointB)
-{
+float GetDistanceFromLine2(Vector3 v, Vector3 &project, const Vector3 &pointA, const Vector3 &pointB) {
Vector3 ba = pointB - pointA;
float len = ba.length();
- if (len<CMP_EPSILON)
- ba=Vector3();
+ if (len < CMP_EPSILON)
+ ba = Vector3();
else
ba *= 1.0f / len;
@@ -189,12 +174,11 @@ float GetDistanceFromLine2(Vector3 v, Vector3 & project, const Vector3 & pointA,
return diff.length();
}
-void TestCylinderVertEdge(neCollisionResult & result, Vector3 & edgeA1, Vector3 & edgeA2, Vector3 & vertB,
- TConvex & cA, TConvex & cB, Transform & transA, Transform & transB, bool flip)
-{
+void TestCylinderVertEdge(neCollisionResult &result, Vector3 &edgeA1, Vector3 &edgeA2, Vector3 &vertB,
+ TConvex &cA, TConvex &cB, Transform &transA, Transform &transB, bool flip) {
Vector3 project;
- float dist = GetDistanceFromLine2(vertB,project, edgeA1, edgeA2);
+ float dist = GetDistanceFromLine2(vertB, project, edgeA1, edgeA2);
float depth = cA.CylinderRadius() + cB.CylinderRadius() - dist;
@@ -208,18 +192,15 @@ void TestCylinderVertEdge(neCollisionResult & result, Vector3 & edgeA1, Vector3
result.depth = depth;
- if (!flip)
- {
- result.collisionFrame.set_axis(2,(project - vertB).normalized());
+ if (!flip) {
+ result.collisionFrame.set_axis(2, (project - vertB).normalized());
result.contactA = project - result.collisionFrame.get_axis(2) * cA.CylinderRadius();
result.contactB = vertB + result.collisionFrame.get_axis(2) * cB.CylinderRadius();
- }
- else
- {
+ } else {
- result.collisionFrame.set_axis(2,(vertB - project).normalized());
+ result.collisionFrame.set_axis(2, (vertB - project).normalized());
result.contactA = vertB - result.collisionFrame.get_axis(2) * cB.CylinderRadius();
@@ -227,9 +208,8 @@ void TestCylinderVertEdge(neCollisionResult & result, Vector3 & edgeA1, Vector3
}
}
-void TestCylinderVertVert(neCollisionResult & result, Vector3 & vertA, Vector3 & vertB,
- TConvex & cA, TConvex & cB, Transform & transA, Transform & transB)
-{
+void TestCylinderVertVert(neCollisionResult &result, Vector3 &vertA, Vector3 &vertB,
+ TConvex &cA, TConvex &cB, Transform &transA, Transform &transB) {
Vector3 diff = vertA - vertB;
float dist = diff.length();
@@ -253,17 +233,16 @@ void TestCylinderVertVert(neCollisionResult & result, Vector3 & vertA, Vector3 &
result.contactB = vertB + result.collisionFrame.get_axis(2) * cB.CylinderRadius();
}
-void Cylinder2CylinderTest(neCollisionResult & result, TConvex & cA, Transform & transA, TConvex & cB, Transform & transB)
-{
+void Cylinder2CylinderTest(neCollisionResult &result, TConvex &cA, Transform &transA, TConvex &cB, Transform &transB) {
result.penetrate = false;
Vector3 dir = transA.basis.get_axis(1).cross(transB.basis.get_axis(1));
float len = dir.length();
-// bool isParallel = len<CMP_EPSILON;
+ // bool isParallel = len<CMP_EPSILON;
-// int doVertCheck = 0;
+ // int doVertCheck = 0;
ConvexTestResult cr;
@@ -272,16 +251,14 @@ void Cylinder2CylinderTest(neCollisionResult & result, TConvex & cA, Transform &
cr.edgeB[0] = transB.origin + transB.basis.get_axis(1) * cB.CylinderHalfHeight();
cr.edgeB[1] = transB.origin - transB.basis.get_axis(1) * cB.CylinderHalfHeight();
-// float dot = transA.basis.get_axis(1).dot(transB.basis.get_axis(1));
+ // float dot = transA.basis.get_axis(1).dot(transB.basis.get_axis(1));
- if (len>CMP_EPSILON)
- {
+ if (len > CMP_EPSILON) {
float au, bu;
cr.ComputerEdgeContactPoint2(au, bu);
- if (cr.valid)
- {
+ if (cr.valid) {
float depth = cA.CylinderRadius() + cB.CylinderRadius() - cr.depth;
if (depth <= 0.0f)
@@ -291,7 +268,7 @@ void Cylinder2CylinderTest(neCollisionResult & result, TConvex & cA, Transform &
result.penetrate = true;
- result.collisionFrame.set_axis(2, (cr.contactA - cr.contactB)*(1.0f / cr.depth));
+ result.collisionFrame.set_axis(2, (cr.contactA - cr.contactB) * (1.0f / cr.depth));
result.contactA = cr.contactA - result.collisionFrame.get_axis(2) * cA.CylinderRadius();
@@ -304,51 +281,38 @@ void Cylinder2CylinderTest(neCollisionResult & result, TConvex & cA, Transform &
int i;
- for (i = 0; i < 2; i++)
- {
+ for (i = 0; i < 2; i++) {
//project onto edge b
Vector3 diff = cr.edgeA[i] - cr.edgeB[1];
float dot = diff.dot(transB.basis.get_axis(1));
- if (dot < 0.0f)
- {
+ if (dot < 0.0f) {
TestCylinderVertVert(result, cr.edgeA[i], cr.edgeB[1], cA, cB, transA, transB);
- }
- else if (dot > (2.0f * cB.CylinderHalfHeight()))
- {
+ } else if (dot > (2.0f * cB.CylinderHalfHeight())) {
TestCylinderVertVert(result, cr.edgeA[i], cr.edgeB[0], cA, cB, transA, transB);
- }
- else
- {
+ } else {
TestCylinderVertEdge(result, cr.edgeB[0], cr.edgeB[1], cr.edgeA[i], cB, cA, transB, transA, true);
}
}
- for (i = 0; i < 2; i++)
- {
+ for (i = 0; i < 2; i++) {
//project onto edge b
Vector3 diff = cr.edgeB[i] - cr.edgeA[1];
float dot = diff.dot(transA.basis.get_axis(1));
- if (dot < 0.0f)
- {
+ if (dot < 0.0f) {
TestCylinderVertVert(result, cr.edgeB[i], cr.edgeA[1], cA, cB, transA, transB);
- }
- else if (dot > (2.0f * cB.CylinderHalfHeight()))
- {
+ } else if (dot > (2.0f * cB.CylinderHalfHeight())) {
TestCylinderVertVert(result, cr.edgeB[i], cr.edgeA[0], cA, cB, transA, transB);
- }
- else
- {
+ } else {
TestCylinderVertEdge(result, cr.edgeA[0], cr.edgeA[1], cr.edgeB[i], cA, cB, transA, transB, false);
}
}
}
-
class TestMainLoop : public MainLoop {
RID meshA;
@@ -365,61 +329,61 @@ class TestMainLoop : public MainLoop {
Transform rot_b;
bool quit;
+
public:
- virtual void input_event(const InputEvent& p_event) {
+ virtual void input_event(const InputEvent &p_event) {
- if (p_event.type==InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask&BUTTON_MASK_LEFT) {
+ if (p_event.type == InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask & BUTTON_MASK_LEFT) {
- rot_b.origin.y+=-p_event.mouse_motion.relative_y/100.0;
- rot_b.origin.x+=p_event.mouse_motion.relative_x/100.0;
+ rot_b.origin.y += -p_event.mouse_motion.relative_y / 100.0;
+ rot_b.origin.x += p_event.mouse_motion.relative_x / 100.0;
}
- if (p_event.type==InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask&BUTTON_MASK_MIDDLE) {
+ if (p_event.type == InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask & BUTTON_MASK_MIDDLE) {
//rot_b.origin.x+=-p_event.mouse_motion.relative_y/100.0;
- rot_b.origin.z+=p_event.mouse_motion.relative_x/100.0;
+ rot_b.origin.z += p_event.mouse_motion.relative_x / 100.0;
}
- if (p_event.type==InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask&BUTTON_MASK_RIGHT) {
+ if (p_event.type == InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask & BUTTON_MASK_RIGHT) {
- float rot_x=-p_event.mouse_motion.relative_y/100.0;
- float rot_y=p_event.mouse_motion.relative_x/100.0;
- rot_b.basis = rot_b.basis * Matrix3(Vector3(1,0,0),rot_x) * Matrix3(Vector3(0,1,0),rot_y);
+ float rot_x = -p_event.mouse_motion.relative_y / 100.0;
+ float rot_y = p_event.mouse_motion.relative_x / 100.0;
+ rot_b.basis = rot_b.basis * Matrix3(Vector3(1, 0, 0), rot_x) * Matrix3(Vector3(0, 1, 0), rot_y);
}
-
}
virtual void request_quit() {
- quit=true;
+ quit = true;
}
virtual void init() {
- VisualServer *vs=VisualServer::get_singleton();
+ VisualServer *vs = VisualServer::get_singleton();
camera = vs->camera_create();
viewport = vs->viewport_create();
vs->viewport_attach_to_screen(viewport);
- vs->viewport_attach_camera( viewport, camera );
- vs->camera_set_transform(camera, Transform( Matrix3(), Vector3(0,0,3 ) ) );
+ vs->viewport_attach_camera(viewport, camera);
+ vs->camera_set_transform(camera, Transform(Matrix3(), Vector3(0, 0, 3)));
/* CONVEX SHAPE */
- DVector<Plane> cylinder_planes = Geometry::build_cylinder_planes(0.5,2,9,Vector3::AXIS_Y);
+ DVector<Plane> cylinder_planes = Geometry::build_cylinder_planes(0.5, 2, 9, Vector3::AXIS_Y);
RID cylinder_material = vs->fixed_material_create();
- vs->fixed_material_set_param( cylinder_material, VisualServer::FIXED_MATERIAL_PARAM_DIFFUSE, Color(0.8,0.2,0.9));
- vs->material_set_flag( cylinder_material, VisualServer::MATERIAL_FLAG_ONTOP,true);
+ vs->fixed_material_set_param(cylinder_material, VisualServer::FIXED_MATERIAL_PARAM_DIFFUSE, Color(0.8, 0.2, 0.9));
+ vs->material_set_flag(cylinder_material, VisualServer::MATERIAL_FLAG_ONTOP, true);
//vs->material_set_flag( cylinder_material, VisualServer::MATERIAL_FLAG_WIREFRAME,true);
- vs->material_set_flag( cylinder_material, VisualServer::MATERIAL_FLAG_DOUBLE_SIDED,true);
- vs->material_set_flag( cylinder_material, VisualServer::MATERIAL_FLAG_UNSHADED,true);
+ vs->material_set_flag(cylinder_material, VisualServer::MATERIAL_FLAG_DOUBLE_SIDED, true);
+ vs->material_set_flag(cylinder_material, VisualServer::MATERIAL_FLAG_UNSHADED, true);
RID cylinder_mesh = vs->mesh_create();
Geometry::MeshData cylinder_data = Geometry::build_convex_mesh(cylinder_planes);
- vs->mesh_add_surface_from_mesh_data(cylinder_mesh,cylinder_data);
- vs->mesh_surface_set_material( cylinder_mesh, 0, cylinder_material );
+ vs->mesh_add_surface_from_mesh_data(cylinder_mesh, cylinder_data);
+ vs->mesh_surface_set_material(cylinder_mesh, 0, cylinder_material);
- meshA=vs->instance_create2(cylinder_mesh,scenario);
- meshB=vs->instance_create2(cylinder_mesh,scenario);
- boxA=vs->instance_create2(vs->get_test_cube(),scenario);
- boxB=vs->instance_create2(vs->get_test_cube(),scenario);
+ meshA = vs->instance_create2(cylinder_mesh, scenario);
+ meshB = vs->instance_create2(cylinder_mesh, scenario);
+ boxA = vs->instance_create2(vs->get_test_cube(), scenario);
+ boxB = vs->instance_create2(vs->get_test_cube(), scenario);
/*
RID lightaux = vs->light_create( VisualServer::LIGHT_OMNI );
@@ -428,72 +392,59 @@ public:
vs->light_set_var( lightaux, VisualServer::LIGHT_VAR_ENERGY, 1.5 );
light = vs->instance_create2( lightaux );
*/
- RID lightaux = vs->light_create( VisualServer::LIGHT_DIRECTIONAL );
+ RID lightaux = vs->light_create(VisualServer::LIGHT_DIRECTIONAL);
//vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_AMBIENT, Color(0.0,0.0,0.0) );
//vs->light_set_shadow( lightaux, true );
- RID light = vs->instance_create2( lightaux,scenario );
+ RID light = vs->instance_create2(lightaux, scenario);
//rot_a=Transform(Matrix3(Vector3(1,0,0),Math_PI/2.0),Vector3());
- rot_b=Transform(Matrix3(),Vector3(2,0,0));
+ rot_b = Transform(Matrix3(), Vector3(2, 0, 0));
//rot_x=0;
//rot_y=0;
- quit=false;
+ quit = false;
}
virtual bool idle(float p_time) {
- VisualServer *vs=VisualServer::get_singleton();
-
- vs->instance_set_transform(meshA,rot_a);
- vs->instance_set_transform(meshB,rot_b);
+ VisualServer *vs = VisualServer::get_singleton();
+ vs->instance_set_transform(meshA, rot_a);
+ vs->instance_set_transform(meshB, rot_b);
neCollisionResult res;
TConvex a;
- a.radius=0.5;
- a.half_height=1;
- Cylinder2CylinderTest(res,a,rot_a,a,rot_b);
+ a.radius = 0.5;
+ a.half_height = 1;
+ Cylinder2CylinderTest(res, a, rot_a, a, rot_b);
if (res.penetrate) {
Matrix3 scale;
- scale.scale(Vector3(0.1,0.1,0.1));
- vs->instance_set_transform(boxA,Transform(scale,res.contactA));
- vs->instance_set_transform(boxB,Transform(scale,res.contactB));
- print_line("depth: "+rtos(res.depth));
- } else {
+ scale.scale(Vector3(0.1, 0.1, 0.1));
+ vs->instance_set_transform(boxA, Transform(scale, res.contactA));
+ vs->instance_set_transform(boxB, Transform(scale, res.contactB));
+ print_line("depth: " + rtos(res.depth));
+ } else {
Matrix3 scale;
scale.scale(Vector3());
- vs->instance_set_transform(boxA,Transform(scale,res.contactA));
- vs->instance_set_transform(boxB,Transform(scale,res.contactB));
-
+ vs->instance_set_transform(boxA, Transform(scale, res.contactA));
+ vs->instance_set_transform(boxB, Transform(scale, res.contactB));
}
- print_line("collided: "+itos(res.penetrate));
+ print_line("collided: " + itos(res.penetrate));
return false;
}
-
virtual bool iteration(float p_time) {
-
-
return quit;
}
virtual void finish() {
-
}
-
};
+MainLoop *test() {
-MainLoop* test() {
-
- return memnew( TestMainLoop );
-
+ return memnew(TestMainLoop);
}
-
}
-
-
-
diff --git a/main/tests/test_misc.h b/main/tests/test_misc.h
index 55608f6a0..fe8f960ec 100644
--- a/main/tests/test_misc.h
+++ b/main/tests/test_misc.h
@@ -33,8 +33,7 @@
namespace TestMisc {
-MainLoop* test();
-
+MainLoop *test();
}
#endif
diff --git a/main/tests/test_particles.cpp b/main/tests/test_particles.cpp
index 23a4b9e63..b57dea9f0 100644
--- a/main/tests/test_particles.cpp
+++ b/main/tests/test_particles.cpp
@@ -27,14 +27,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "test_particles.h"
-#include "servers/visual_server.h"
-#include "os/main_loop.h"
#include "math_funcs.h"
+#include "os/main_loop.h"
#include "print_string.h"
+#include "servers/visual_server.h"
namespace TestParticles {
-
class TestMainLoop : public MainLoop {
RID particles;
@@ -55,30 +54,28 @@ class TestMainLoop : public MainLoop {
float ofs;
bool quit;
-public:
- virtual void input_event(const InputEvent& p_event) {
-
+public:
+ virtual void input_event(const InputEvent &p_event) {
}
virtual void request_quit() {
- quit=true;
+ quit = true;
}
virtual void init() {
- VisualServer *vs=VisualServer::get_singleton();
+ VisualServer *vs = VisualServer::get_singleton();
particles = vs->particles_create();
- vs->particles_set_amount(particles,1000);
-
- instance = vs->instance_create2(particles,scenario);
+ vs->particles_set_amount(particles, 1000);
+ instance = vs->instance_create2(particles, scenario);
camera = vs->camera_create();
-// vs->camera_set_perspective( camera, 60.0,0.1, 100.0 );
+ // vs->camera_set_perspective( camera, 60.0,0.1, 100.0 );
viewport = vs->viewport_create();
- vs->viewport_attach_camera( viewport, camera );
- vs->camera_set_transform(camera, Transform( Matrix3(), Vector3(0,0,20 ) ) );
+ vs->viewport_attach_camera(viewport, camera);
+ vs->camera_set_transform(camera, Transform(Matrix3(), Vector3(0, 0, 20)));
/*
RID lightaux = vs->light_create( VisualServer::LIGHT_OMNI );
vs->light_set_var( lightaux, VisualServer::LIGHT_VAR_RADIUS, 80 );
@@ -86,36 +83,30 @@ public:
vs->light_set_var( lightaux, VisualServer::LIGHT_VAR_ENERGY, 1.5 );
light = vs->instance_create2( lightaux );
*/
- RID lightaux = vs->light_create( VisualServer::LIGHT_DIRECTIONAL );
- // vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_AMBIENT, Color(0.0,0.0,0.0) );
- light = vs->instance_create2( lightaux, scenario );
+ RID lightaux = vs->light_create(VisualServer::LIGHT_DIRECTIONAL);
+ // vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_AMBIENT, Color(0.0,0.0,0.0) );
+ light = vs->instance_create2(lightaux, scenario);
- ofs=0;
- quit=false;
+ ofs = 0;
+ quit = false;
}
virtual bool idle(float p_time) {
return false;
}
-
virtual bool iteration(float p_time) {
-// VisualServer *vs=VisualServer::get_singleton();
+ // VisualServer *vs=VisualServer::get_singleton();
- ofs+=p_time;
+ ofs += p_time;
return quit;
}
virtual void finish() {
-
}
-
};
+MainLoop *test() {
-MainLoop* test() {
-
- return memnew( TestMainLoop );
-
+ return memnew(TestMainLoop);
}
-
}
diff --git a/main/tests/test_particles.h b/main/tests/test_particles.h
index e95637a4e..08b8e7322 100644
--- a/main/tests/test_particles.h
+++ b/main/tests/test_particles.h
@@ -36,8 +36,7 @@
namespace TestParticles {
-MainLoop* test();
-
+MainLoop *test();
}
#endif
diff --git a/main/tests/test_physics.cpp b/main/tests/test_physics.cpp
index 932ce47c5..be7d78fc6 100644
--- a/main/tests/test_physics.cpp
+++ b/main/tests/test_physics.cpp
@@ -28,19 +28,18 @@
/*************************************************************************/
#include "test_physics.h"
-
-#include "servers/visual_server.h"
-#include "servers/physics_server.h"
-#include "os/main_loop.h"
-#include "math_funcs.h"
-#include "print_string.h"
#include "map.h"
+#include "math_funcs.h"
+#include "os/main_loop.h"
#include "os/os.h"
+#include "print_string.h"
#include "quick_hull.h"
+#include "servers/physics_server.h"
+#include "servers/visual_server.h"
class TestPhysicsMainLoop : public MainLoop {
- OBJ_TYPE( TestPhysicsMainLoop, MainLoop );
+ OBJ_TYPE(TestPhysicsMainLoop, MainLoop);
enum {
LINK_COUNT = 20,
@@ -58,161 +57,156 @@ class TestPhysicsMainLoop : public MainLoop {
RID character;
- float ofs_x,ofs_y;
+ float ofs_x, ofs_y;
Point2 joy_direction;
List<RID> bodies;
- Map<PhysicsServer::ShapeType,RID> type_shape_map;
- Map<PhysicsServer::ShapeType,RID> type_mesh_map;
+ Map<PhysicsServer::ShapeType, RID> type_shape_map;
+ Map<PhysicsServer::ShapeType, RID> type_mesh_map;
void body_changed_transform(Object *p_state, RID p_visual_instance) {
- PhysicsDirectBodyState *state = (PhysicsDirectBodyState*)p_state;
- VisualServer *vs=VisualServer::get_singleton();
- Transform t=state->get_transform();
+ PhysicsDirectBodyState *state = (PhysicsDirectBodyState *)p_state;
+ VisualServer *vs = VisualServer::get_singleton();
+ Transform t = state->get_transform();
//t.basis.scale( Vector3(1.0,0.5,0.2) );
- vs->instance_set_transform(p_visual_instance,t);
+ vs->instance_set_transform(p_visual_instance, t);
}
bool quit;
protected:
-
static void _bind_methods() {
- ObjectTypeDB::bind_method("body_changed_transform",&TestPhysicsMainLoop::body_changed_transform);
+ ObjectTypeDB::bind_method("body_changed_transform", &TestPhysicsMainLoop::body_changed_transform);
}
- RID create_body(PhysicsServer::ShapeType p_shape, PhysicsServer::BodyMode p_body,const Transform p_location,bool p_active_default=true,const Transform&p_shape_xform=Transform()) {
+ RID create_body(PhysicsServer::ShapeType p_shape, PhysicsServer::BodyMode p_body, const Transform p_location, bool p_active_default = true, const Transform &p_shape_xform = Transform()) {
- VisualServer *vs=VisualServer::get_singleton();
- PhysicsServer * ps = PhysicsServer::get_singleton();
+ VisualServer *vs = VisualServer::get_singleton();
+ PhysicsServer *ps = PhysicsServer::get_singleton();
- RID mesh_instance = vs->instance_create2(type_mesh_map[p_shape],scenario);
- RID body = ps->body_create(p_body,!p_active_default);
- ps->body_set_space(body,space);
- ps->body_set_param(body,PhysicsServer::BODY_PARAM_BOUNCE,0.0);
+ RID mesh_instance = vs->instance_create2(type_mesh_map[p_shape], scenario);
+ RID body = ps->body_create(p_body, !p_active_default);
+ ps->body_set_space(body, space);
+ ps->body_set_param(body, PhysicsServer::BODY_PARAM_BOUNCE, 0.0);
//todo set space
- ps->body_add_shape(body,type_shape_map[p_shape]);
- ps->body_set_force_integration_callback(body,this,"body_changed_transform",mesh_instance);
+ ps->body_add_shape(body, type_shape_map[p_shape]);
+ ps->body_set_force_integration_callback(body, this, "body_changed_transform", mesh_instance);
- ps->body_set_state( body, PhysicsServer::BODY_STATE_TRANSFORM,p_location);
+ ps->body_set_state(body, PhysicsServer::BODY_STATE_TRANSFORM, p_location);
bodies.push_back(body);
- if (p_body==PhysicsServer::BODY_MODE_STATIC) {
+ if (p_body == PhysicsServer::BODY_MODE_STATIC) {
- vs->instance_set_transform(mesh_instance,p_location);
+ vs->instance_set_transform(mesh_instance, p_location);
}
return body;
}
- RID create_static_plane(const Plane& p_plane) {
+ RID create_static_plane(const Plane &p_plane) {
- PhysicsServer * ps = PhysicsServer::get_singleton();
+ PhysicsServer *ps = PhysicsServer::get_singleton();
RID plane_shape = ps->shape_create(PhysicsServer::SHAPE_PLANE);
- ps->shape_set_data( plane_shape, p_plane );
+ ps->shape_set_data(plane_shape, p_plane);
- RID b = ps->body_create( PhysicsServer::BODY_MODE_STATIC );
- ps->body_set_space(b,space);
+ RID b = ps->body_create(PhysicsServer::BODY_MODE_STATIC);
+ ps->body_set_space(b, space);
//todo set space
ps->body_add_shape(b, plane_shape);
return b;
-
}
- void configure_body(RID p_body,float p_mass, float p_friction, float p_bounce) {
-
- PhysicsServer * ps = PhysicsServer::get_singleton();
- ps->body_set_param( p_body, PhysicsServer::BODY_PARAM_MASS, p_mass );
- ps->body_set_param( p_body, PhysicsServer::BODY_PARAM_FRICTION, p_friction );
- ps->body_set_param( p_body, PhysicsServer::BODY_PARAM_BOUNCE, p_bounce );
+ void configure_body(RID p_body, float p_mass, float p_friction, float p_bounce) {
+ PhysicsServer *ps = PhysicsServer::get_singleton();
+ ps->body_set_param(p_body, PhysicsServer::BODY_PARAM_MASS, p_mass);
+ ps->body_set_param(p_body, PhysicsServer::BODY_PARAM_FRICTION, p_friction);
+ ps->body_set_param(p_body, PhysicsServer::BODY_PARAM_BOUNCE, p_bounce);
}
void init_shapes() {
- VisualServer *vs=VisualServer::get_singleton();
- PhysicsServer * ps = PhysicsServer::get_singleton();
+ VisualServer *vs = VisualServer::get_singleton();
+ PhysicsServer *ps = PhysicsServer::get_singleton();
/* SPHERE SHAPE */
- RID sphere_mesh = vs->make_sphere_mesh(10,20,0.5);
+ RID sphere_mesh = vs->make_sphere_mesh(10, 20, 0.5);
RID sphere_material = vs->fixed_material_create();
//vs->material_set_flag( sphere_material, VisualServer::MATERIAL_FLAG_WIREFRAME, true );
- vs->fixed_material_set_param( sphere_material, VisualServer::FIXED_MATERIAL_PARAM_DIFFUSE, Color(0.7,0.8,3.0) );
- vs->mesh_surface_set_material( sphere_mesh, 0, sphere_material );
- type_mesh_map[PhysicsServer::SHAPE_SPHERE]=sphere_mesh;
+ vs->fixed_material_set_param(sphere_material, VisualServer::FIXED_MATERIAL_PARAM_DIFFUSE, Color(0.7, 0.8, 3.0));
+ vs->mesh_surface_set_material(sphere_mesh, 0, sphere_material);
+ type_mesh_map[PhysicsServer::SHAPE_SPHERE] = sphere_mesh;
- RID sphere_shape=ps->shape_create(PhysicsServer::SHAPE_SPHERE);
- ps->shape_set_data( sphere_shape, 0.5 );
- type_shape_map[PhysicsServer::SHAPE_SPHERE]=sphere_shape;
+ RID sphere_shape = ps->shape_create(PhysicsServer::SHAPE_SPHERE);
+ ps->shape_set_data(sphere_shape, 0.5);
+ type_shape_map[PhysicsServer::SHAPE_SPHERE] = sphere_shape;
/* BOX SHAPE */
- DVector<Plane> box_planes = Geometry::build_box_planes(Vector3(0.5,0.5,0.5));
+ DVector<Plane> box_planes = Geometry::build_box_planes(Vector3(0.5, 0.5, 0.5));
RID box_material = vs->fixed_material_create();
- vs->fixed_material_set_param( box_material, VisualServer::FIXED_MATERIAL_PARAM_DIFFUSE, Color(1.0,0.2,0.2) );
+ vs->fixed_material_set_param(box_material, VisualServer::FIXED_MATERIAL_PARAM_DIFFUSE, Color(1.0, 0.2, 0.2));
RID box_mesh = vs->mesh_create();
Geometry::MeshData box_data = Geometry::build_convex_mesh(box_planes);
- vs->mesh_add_surface_from_mesh_data(box_mesh,box_data);
- vs->mesh_surface_set_material( box_mesh, 0, box_material );
- type_mesh_map[PhysicsServer::SHAPE_BOX]=box_mesh;
-
- RID box_shape=ps->shape_create(PhysicsServer::SHAPE_BOX);
- ps->shape_set_data( box_shape, Vector3(0.5,0.5,0.5) );
- type_shape_map[PhysicsServer::SHAPE_BOX]=box_shape;
+ vs->mesh_add_surface_from_mesh_data(box_mesh, box_data);
+ vs->mesh_surface_set_material(box_mesh, 0, box_material);
+ type_mesh_map[PhysicsServer::SHAPE_BOX] = box_mesh;
+ RID box_shape = ps->shape_create(PhysicsServer::SHAPE_BOX);
+ ps->shape_set_data(box_shape, Vector3(0.5, 0.5, 0.5));
+ type_shape_map[PhysicsServer::SHAPE_BOX] = box_shape;
/* CAPSULE SHAPE */
- DVector<Plane> capsule_planes = Geometry::build_capsule_planes(0.5,0.7,12,Vector3::AXIS_Z);
+ DVector<Plane> capsule_planes = Geometry::build_capsule_planes(0.5, 0.7, 12, Vector3::AXIS_Z);
RID capsule_material = vs->fixed_material_create();
- vs->fixed_material_set_param( capsule_material, VisualServer::FIXED_MATERIAL_PARAM_DIFFUSE, Color(0.3,0.4,1.0) );
+ vs->fixed_material_set_param(capsule_material, VisualServer::FIXED_MATERIAL_PARAM_DIFFUSE, Color(0.3, 0.4, 1.0));
RID capsule_mesh = vs->mesh_create();
Geometry::MeshData capsule_data = Geometry::build_convex_mesh(capsule_planes);
- vs->mesh_add_surface_from_mesh_data(capsule_mesh,capsule_data);
- vs->mesh_surface_set_material( capsule_mesh, 0, capsule_material );
- type_mesh_map[PhysicsServer::SHAPE_CAPSULE]=capsule_mesh;
+ vs->mesh_add_surface_from_mesh_data(capsule_mesh, capsule_data);
+ vs->mesh_surface_set_material(capsule_mesh, 0, capsule_material);
+ type_mesh_map[PhysicsServer::SHAPE_CAPSULE] = capsule_mesh;
- RID capsule_shape=ps->shape_create(PhysicsServer::SHAPE_CAPSULE);
+ RID capsule_shape = ps->shape_create(PhysicsServer::SHAPE_CAPSULE);
Dictionary capsule_params;
- capsule_params["radius"]=0.5;
- capsule_params["height"]=1.4;
- ps->shape_set_data( capsule_shape, capsule_params );
- type_shape_map[PhysicsServer::SHAPE_CAPSULE]=capsule_shape;
+ capsule_params["radius"] = 0.5;
+ capsule_params["height"] = 1.4;
+ ps->shape_set_data(capsule_shape, capsule_params);
+ type_shape_map[PhysicsServer::SHAPE_CAPSULE] = capsule_shape;
/* CONVEX SHAPE */
- DVector<Plane> convex_planes = Geometry::build_cylinder_planes(0.5,0.7,5,Vector3::AXIS_Z);
+ DVector<Plane> convex_planes = Geometry::build_cylinder_planes(0.5, 0.7, 5, Vector3::AXIS_Z);
RID convex_material = vs->fixed_material_create();
- vs->fixed_material_set_param( convex_material, VisualServer::FIXED_MATERIAL_PARAM_DIFFUSE, Color(0.8,0.2,0.9));
+ vs->fixed_material_set_param(convex_material, VisualServer::FIXED_MATERIAL_PARAM_DIFFUSE, Color(0.8, 0.2, 0.9));
RID convex_mesh = vs->mesh_create();
Geometry::MeshData convex_data = Geometry::build_convex_mesh(convex_planes);
- QuickHull::build(convex_data.vertices,convex_data);
- vs->mesh_add_surface_from_mesh_data(convex_mesh,convex_data);
- vs->mesh_surface_set_material( convex_mesh, 0, convex_material );
- type_mesh_map[PhysicsServer::SHAPE_CONVEX_POLYGON]=convex_mesh;
-
- RID convex_shape=ps->shape_create(PhysicsServer::SHAPE_CONVEX_POLYGON);
- ps->shape_set_data( convex_shape, convex_data.vertices );
- type_shape_map[PhysicsServer::SHAPE_CONVEX_POLYGON]=convex_shape;
+ QuickHull::build(convex_data.vertices, convex_data);
+ vs->mesh_add_surface_from_mesh_data(convex_mesh, convex_data);
+ vs->mesh_surface_set_material(convex_mesh, 0, convex_material);
+ type_mesh_map[PhysicsServer::SHAPE_CONVEX_POLYGON] = convex_mesh;
+ RID convex_shape = ps->shape_create(PhysicsServer::SHAPE_CONVEX_POLYGON);
+ ps->shape_set_data(convex_shape, convex_data.vertices);
+ type_shape_map[PhysicsServer::SHAPE_CONVEX_POLYGON] = convex_shape;
}
- void make_trimesh(Vector<Vector3> p_faces,const Transform& p_xform=Transform()) {
+ void make_trimesh(Vector<Vector3> p_faces, const Transform &p_xform = Transform()) {
- VisualServer *vs=VisualServer::get_singleton();
- PhysicsServer * ps = PhysicsServer::get_singleton();
+ VisualServer *vs = VisualServer::get_singleton();
+ PhysicsServer *ps = PhysicsServer::get_singleton();
RID trimesh_shape = ps->shape_create(PhysicsServer::SHAPE_CONCAVE_POLYGON);
ps->shape_set_data(trimesh_shape, p_faces);
- p_faces=ps->shape_get_data(trimesh_shape); // optimized one
+ p_faces = ps->shape_get_data(trimesh_shape); // optimized one
Vector<Vector3> normals; // for drawing
- for (int i=0;i<p_faces.size()/3;i++) {
+ for (int i = 0; i < p_faces.size() / 3; i++) {
- Plane p( p_faces[i*3+0],p_faces[i*3+1], p_faces[i*3+2] );
+ Plane p(p_faces[i * 3 + 0], p_faces[i * 3 + 1], p_faces[i * 3 + 2]);
normals.push_back(p.normal);
normals.push_back(p.normal);
normals.push_back(p.normal);
@@ -221,97 +215,88 @@ protected:
RID trimesh_mesh = vs->mesh_create();
Array d;
d.resize(VS::ARRAY_MAX);
- d[VS::ARRAY_VERTEX]=p_faces;
- d[VS::ARRAY_NORMAL]=normals;
- vs->mesh_add_surface(trimesh_mesh, VS::PRIMITIVE_TRIANGLES, d );
+ d[VS::ARRAY_VERTEX] = p_faces;
+ d[VS::ARRAY_NORMAL] = normals;
+ vs->mesh_add_surface(trimesh_mesh, VS::PRIMITIVE_TRIANGLES, d);
RID trimesh_mat = vs->fixed_material_create();
- vs->fixed_material_set_param( trimesh_mat, VisualServer::FIXED_MATERIAL_PARAM_DIFFUSE, Color(1.0,0.5,0.8));
+ vs->fixed_material_set_param(trimesh_mat, VisualServer::FIXED_MATERIAL_PARAM_DIFFUSE, Color(1.0, 0.5, 0.8));
//vs->material_set_flag( trimesh_mat, VisualServer::MATERIAL_FLAG_UNSHADED,true);
- vs->mesh_surface_set_material( trimesh_mesh, 0, trimesh_mat );
-
- RID triins = vs->instance_create2(trimesh_mesh,scenario);
+ vs->mesh_surface_set_material(trimesh_mesh, 0, trimesh_mat);
+ RID triins = vs->instance_create2(trimesh_mesh, scenario);
- RID tribody = ps->body_create( PhysicsServer::BODY_MODE_STATIC);
- ps->body_set_space(tribody,space);
+ RID tribody = ps->body_create(PhysicsServer::BODY_MODE_STATIC);
+ ps->body_set_space(tribody, space);
//todo set space
ps->body_add_shape(tribody, trimesh_shape);
Transform tritrans = p_xform;
- ps->body_set_state( tribody, PhysicsServer::BODY_STATE_TRANSFORM, tritrans );
- vs->instance_set_transform( triins, tritrans );
+ ps->body_set_state(tribody, PhysicsServer::BODY_STATE_TRANSFORM, tritrans);
+ vs->instance_set_transform(triins, tritrans);
//RID trimesh_material = vs->fixed_material_create();
//vs->material_generate( trimesh_material, Color(0.2,0.4,0.6) );
//vs->mesh_surface_set_material( trimesh_mesh, 0, trimesh_material );
-
}
- void make_grid(int p_width,int p_height,float p_cellsize,float p_cellheight,const Transform& p_xform=Transform()) {
+ void make_grid(int p_width, int p_height, float p_cellsize, float p_cellheight, const Transform &p_xform = Transform()) {
- Vector< Vector< float > > grid;
+ Vector<Vector<float> > grid;
grid.resize(p_width);
- for (int i=0;i<p_width;i++) {
+ for (int i = 0; i < p_width; i++) {
grid[i].resize(p_height);
- for (int j=0;j<p_height;j++) {
+ for (int j = 0; j < p_height; j++) {
- grid[i][j]=1.0+Math::random(-p_cellheight, p_cellheight );
+ grid[i][j] = 1.0 + Math::random(-p_cellheight, p_cellheight);
}
}
Vector<Vector3> faces;
- for (int i=1;i<p_width;i++) {
-
- for (int j=1;j<p_height;j++) {
-
+ for (int i = 1; i < p_width; i++) {
-#define MAKE_VERTEX(m_x,m_z)\
- faces.push_back( Vector3( (m_x-p_width/2)*p_cellsize, grid[m_x][m_z], (m_z-p_height/2)*p_cellsize ) )
+ for (int j = 1; j < p_height; j++) {
- MAKE_VERTEX(i,j-1);
- MAKE_VERTEX(i,j);
- MAKE_VERTEX(i-1,j);
+#define MAKE_VERTEX(m_x, m_z) \
+ faces.push_back(Vector3((m_x - p_width / 2) * p_cellsize, grid[m_x][m_z], (m_z - p_height / 2) * p_cellsize))
- MAKE_VERTEX(i-1,j-1);
- MAKE_VERTEX(i,j-1);
- MAKE_VERTEX(i-1,j);
+ MAKE_VERTEX(i, j - 1);
+ MAKE_VERTEX(i, j);
+ MAKE_VERTEX(i - 1, j);
+ MAKE_VERTEX(i - 1, j - 1);
+ MAKE_VERTEX(i, j - 1);
+ MAKE_VERTEX(i - 1, j);
}
}
- make_trimesh(faces,p_xform);
-
+ make_trimesh(faces, p_xform);
}
-
public:
- virtual void input_event(const InputEvent& p_event) {
-
- if (p_event.type==InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask&4) {
+ virtual void input_event(const InputEvent &p_event) {
- ofs_y-=p_event.mouse_motion.relative_y/200.0;
- ofs_x+=p_event.mouse_motion.relative_x/200.0;
+ if (p_event.type == InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask & 4) {
+ ofs_y -= p_event.mouse_motion.relative_y / 200.0;
+ ofs_x += p_event.mouse_motion.relative_x / 200.0;
}
- if (p_event.type==InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask&1) {
+ if (p_event.type == InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask & 1) {
- float y=-p_event.mouse_motion.relative_y/20.0;
- float x=p_event.mouse_motion.relative_x/20.0;
+ float y = -p_event.mouse_motion.relative_y / 20.0;
+ float x = p_event.mouse_motion.relative_x / 20.0;
if (mover.is_valid()) {
+ PhysicsServer *ps = PhysicsServer::get_singleton();
+ Transform t = ps->body_get_state(mover, PhysicsServer::BODY_STATE_TRANSFORM);
+ t.origin += Vector3(x, y, 0);
- PhysicsServer * ps = PhysicsServer::get_singleton();
- Transform t = ps->body_get_state(mover,PhysicsServer::BODY_STATE_TRANSFORM);
- t.origin+=Vector3(x,y,0);
-
- ps->body_set_state(mover,PhysicsServer::BODY_STATE_TRANSFORM,t);
+ ps->body_set_state(mover, PhysicsServer::BODY_STATE_TRANSFORM, t);
}
-
}
if (p_event.type == InputEvent::JOYSTICK_MOTION) {
@@ -330,55 +315,52 @@ public:
virtual void request_quit() {
- quit=true;
+ quit = true;
}
virtual void init() {
- ofs_x=ofs_y=0;
+ ofs_x = ofs_y = 0;
init_shapes();
PhysicsServer *ps = PhysicsServer::get_singleton();
- space=ps->space_create();
- ps->space_set_active(space,true);
+ space = ps->space_create();
+ ps->space_set_active(space, true);
- VisualServer *vs=VisualServer::get_singleton();
+ VisualServer *vs = VisualServer::get_singleton();
/* LIGHT */
- RID lightaux = vs->light_create( VisualServer::LIGHT_DIRECTIONAL );
+ RID lightaux = vs->light_create(VisualServer::LIGHT_DIRECTIONAL);
//vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_AMBIENT, Color(0.0,0.0,0.0) );
scenario = vs->scenario_create();
- vs->light_set_shadow(lightaux,true);
- light = vs->instance_create2( lightaux,scenario );
+ vs->light_set_shadow(lightaux, true);
+ light = vs->instance_create2(lightaux, scenario);
Transform t;
- t.rotate(Vector3(1.0,0,0),0.6);
- vs->instance_set_transform(light,t);
-
-
+ t.rotate(Vector3(1.0, 0, 0), 0.6);
+ vs->instance_set_transform(light, t);
/* CAMERA */
camera = vs->camera_create();
RID viewport = vs->viewport_create();
- vs->viewport_attach_camera( viewport, camera );
+ vs->viewport_attach_camera(viewport, camera);
vs->viewport_attach_to_screen(viewport);
- vs->viewport_set_scenario( viewport, scenario );
+ vs->viewport_set_scenario(viewport, scenario);
- vs->camera_set_perspective(camera,60,0.1,40.0);
- vs->camera_set_transform(camera,Transform( Matrix3(), Vector3(0,9,12)));
+ vs->camera_set_perspective(camera, 60, 0.1, 40.0);
+ vs->camera_set_transform(camera, Transform(Matrix3(), Vector3(0, 9, 12)));
//vs->scenario_set_debug(scenario,VS::SCENARIO_DEBUG_WIREFRAME);
Transform gxf;
- gxf.basis.scale(Vector3(1.4,0.4,1.4));
- gxf.origin=Vector3(-2,1,-2);
- make_grid(5,5,2.5,1,gxf);
- // create_body(PhysicsServer::SHAPE_BOX,PhysicsServer::BODY_MODE_STATIC,gxf);
+ gxf.basis.scale(Vector3(1.4, 0.4, 1.4));
+ gxf.origin = Vector3(-2, 1, -2);
+ make_grid(5, 5, 2.5, 1, gxf);
+ // create_body(PhysicsServer::SHAPE_BOX,PhysicsServer::BODY_MODE_STATIC,gxf);
//create_static_plane( Plane( Vector3(0,1,0), -2) );
-// test_joint();
+ // test_joint();
test_fall();
//test_joint();
-
-/*
+ /*
Vector<Vector3> faces;
faces.push_back( Vector3(10,0,-5) );
faces.push_back( Vector3(0,0,10) );
@@ -386,7 +368,7 @@ public:
make_trimesh(faces);
*/
/* Make Trimesh */
- quit=false;
+ quit = false;
return;
#if 0
@@ -408,9 +390,8 @@ public:
for (int j=1;j<GRID_SIZE;j++) {
-
-#define MAKE_VERTEX(m_x,m_z)\
- faces.push_back( Vector3( m_x-GRID_SIZE/2.0, grid[m_x][m_z], m_z-GRID_SIZE/2.0 )*3.0 )
+#define MAKE_VERTEX(m_x, m_z) \
+ faces.push_back(Vector3(m_x - GRID_SIZE / 2.0, grid[m_x][m_z], m_z - GRID_SIZE / 2.0) * 3.0)
MAKE_VERTEX(i,j-1);
MAKE_VERTEX(i,j);
@@ -466,24 +447,22 @@ public:
if (mover) {
static float joy_speed = 10;
- PhysicsServer * ps = PhysicsServer::get_singleton();
- Transform t = ps->body_get_state(mover,PhysicsServer::BODY_STATE_TRANSFORM);
- t.origin+=Vector3(joy_speed * joy_direction.x * p_time, -joy_speed * joy_direction.y * p_time,0);
- ps->body_set_state(mover,PhysicsServer::BODY_STATE_TRANSFORM,t);
+ PhysicsServer *ps = PhysicsServer::get_singleton();
+ Transform t = ps->body_get_state(mover, PhysicsServer::BODY_STATE_TRANSFORM);
+ t.origin += Vector3(joy_speed * joy_direction.x * p_time, -joy_speed * joy_direction.y * p_time, 0);
+ ps->body_set_state(mover, PhysicsServer::BODY_STATE_TRANSFORM, t);
};
-
Transform cameratr;
- cameratr.rotate(Vector3(0,1,0),ofs_x);
- cameratr.rotate(Vector3(1,0,0),-ofs_y);
- cameratr.translate(Vector3(0,2,8));
- VisualServer *vs=VisualServer::get_singleton();
- vs->camera_set_transform(camera,cameratr);
+ cameratr.rotate(Vector3(0, 1, 0), ofs_x);
+ cameratr.rotate(Vector3(1, 0, 0), -ofs_y);
+ cameratr.translate(Vector3(0, 2, 8));
+ VisualServer *vs = VisualServer::get_singleton();
+ vs->camera_set_transform(camera, cameratr);
return quit;
}
virtual void finish() {
-
}
void test_joint() {
@@ -543,120 +522,97 @@ public:
void test_character() {
- VisualServer *vs=VisualServer::get_singleton();
- PhysicsServer * ps = PhysicsServer::get_singleton();
-
+ VisualServer *vs = VisualServer::get_singleton();
+ PhysicsServer *ps = PhysicsServer::get_singleton();
- DVector<Plane> capsule_planes = Geometry::build_capsule_planes(0.5,1,12,5,Vector3::AXIS_Y);
+ DVector<Plane> capsule_planes = Geometry::build_capsule_planes(0.5, 1, 12, 5, Vector3::AXIS_Y);
RID capsule_material = vs->fixed_material_create();
- vs->fixed_material_set_param( capsule_material, VisualServer::FIXED_MATERIAL_PARAM_DIFFUSE, Color(1,1,1) );
-
+ vs->fixed_material_set_param(capsule_material, VisualServer::FIXED_MATERIAL_PARAM_DIFFUSE, Color(1, 1, 1));
RID capsule_mesh = vs->mesh_create();
Geometry::MeshData capsule_data = Geometry::build_convex_mesh(capsule_planes);
- vs->mesh_add_surface_from_mesh_data(capsule_mesh,capsule_data);
- vs->mesh_surface_set_material( capsule_mesh, 0, capsule_material );
- type_mesh_map[PhysicsServer::SHAPE_CAPSULE]=capsule_mesh;
+ vs->mesh_add_surface_from_mesh_data(capsule_mesh, capsule_data);
+ vs->mesh_surface_set_material(capsule_mesh, 0, capsule_material);
+ type_mesh_map[PhysicsServer::SHAPE_CAPSULE] = capsule_mesh;
- RID capsule_shape=ps->shape_create(PhysicsServer::SHAPE_CAPSULE);
+ RID capsule_shape = ps->shape_create(PhysicsServer::SHAPE_CAPSULE);
Dictionary capsule_params;
- capsule_params["radius"]=0.5;
- capsule_params["height"]=1;
+ capsule_params["radius"] = 0.5;
+ capsule_params["height"] = 1;
Transform shape_xform;
- shape_xform.rotate(Vector3(1,0,0),Math_PI/2.0);
+ shape_xform.rotate(Vector3(1, 0, 0), Math_PI / 2.0);
//shape_xform.origin=Vector3(1,1,1);
- ps->shape_set_data( capsule_shape, capsule_params);
-
+ ps->shape_set_data(capsule_shape, capsule_params);
- RID mesh_instance = vs->instance_create2(capsule_mesh,scenario);
+ RID mesh_instance = vs->instance_create2(capsule_mesh, scenario);
character = ps->body_create(PhysicsServer::BODY_MODE_CHARACTER);
- ps->body_set_space(character,space);
+ ps->body_set_space(character, space);
//todo add space
- ps->body_add_shape(character,capsule_shape);
-
- ps->body_set_force_integration_callback(character,this,"body_changed_transform",mesh_instance);
+ ps->body_add_shape(character, capsule_shape);
+ ps->body_set_force_integration_callback(character, this, "body_changed_transform", mesh_instance);
- ps->body_set_state( character, PhysicsServer::BODY_STATE_TRANSFORM,Transform(Matrix3(),Vector3(-2,5,-2)));
+ ps->body_set_state(character, PhysicsServer::BODY_STATE_TRANSFORM, Transform(Matrix3(), Vector3(-2, 5, -2)));
bodies.push_back(character);
-
-
}
void test_fall() {
+ for (int i = 0; i < 35; i++) {
- for (int i=0;i<35;i++) {
-
- static const PhysicsServer::ShapeType shape_idx[]={
+ static const PhysicsServer::ShapeType shape_idx[] = {
PhysicsServer::SHAPE_CAPSULE,
PhysicsServer::SHAPE_BOX,
PhysicsServer::SHAPE_SPHERE,
PhysicsServer::SHAPE_CONVEX_POLYGON
};
- PhysicsServer::ShapeType type=shape_idx[i%4];
+ PhysicsServer::ShapeType type = shape_idx[i % 4];
//type=PhysicsServer::SHAPE_CONVEX_POLYGON;
Transform t;
- t.origin=Vector3(0.0*i,3.5+1.1*i,0.7+0.0*i);
+ t.origin = Vector3(0.0 * i, 3.5 + 1.1 * i, 0.7 + 0.0 * i);
//t.origin=Vector3(-0.7+0.0*i,0.5+4.1*i,0);
- t.basis.rotate(Vector3(0.2,-1,0),Math_PI/2*0.6);
+ t.basis.rotate(Vector3(0.2, -1, 0), Math_PI / 2 * 0.6);
//t.basis.rotate(Vector3(0,-1,0),Math_PI/4*i);
//t.basis.rotate(Vector3(0,-1,0),Math_PI/4*i);
//t.basis.rotate(Vector3(-1,0,0),Math_PI/4*i);
-
- RID b = create_body(type,PhysicsServer::BODY_MODE_RIGID,t);
+ RID b = create_body(type, PhysicsServer::BODY_MODE_RIGID, t);
//RID b = create_body(type,i==0?PhysicsServer::BODY_MODE_STATIC:PhysicsServer::BODY_MODE_RIGID,t);
-
}
- create_static_plane( Plane( Vector3(0,1,0), -1) );
+ create_static_plane(Plane(Vector3(0, 1, 0), -1));
-
-/*
+ /*
create_static_plane( Plane( Vector3(1,0,0), -2) );
create_static_plane( Plane( Vector3(-1,0,0), -2) );
create_static_plane( Plane( Vector3(0,0,1), -2) );
create_static_plane( Plane( Vector3(0,0,-1), -2) );
*/
-
-
}
void test_activate() {
- create_body(PhysicsServer::SHAPE_BOX,PhysicsServer::BODY_MODE_RIGID,Transform(Matrix3(),Vector3(0,2,0)),true);
+ create_body(PhysicsServer::SHAPE_BOX, PhysicsServer::BODY_MODE_RIGID, Transform(Matrix3(), Vector3(0, 2, 0)), true);
//create_body(PhysicsServer::SHAPE_SPHERE,PhysicsServer::BODY_MODE_RIGID,Transform(Matrix3(),Vector3(0,6,0)),true);
- create_static_plane( Plane( Vector3(0,1,0), -1) );
-
+ create_static_plane(Plane(Vector3(0, 1, 0), -1));
}
-
virtual bool idle(float p_time) {
return false;
}
-
-
-
-
-
-
TestPhysicsMainLoop() {
-
}
};
namespace TestPhysics {
-MainLoop* test() {
-
- return memnew( TestPhysicsMainLoop );
+MainLoop *test() {
+ return memnew(TestPhysicsMainLoop);
}
-
}
diff --git a/main/tests/test_physics.h b/main/tests/test_physics.h
index 5b6a54f2d..50ac7f1f3 100644
--- a/main/tests/test_physics.h
+++ b/main/tests/test_physics.h
@@ -37,8 +37,7 @@
namespace TestPhysics {
-MainLoop* test();
-
+MainLoop *test();
}
#endif
diff --git a/main/tests/test_physics_2d.cpp b/main/tests/test_physics_2d.cpp
index c5fb73499..1a541cf1f 100644
--- a/main/tests/test_physics_2d.cpp
+++ b/main/tests/test_physics_2d.cpp
@@ -27,23 +27,21 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "test_physics_2d.h"
-#include "servers/visual_server.h"
-#include "servers/physics_2d_server.h"
+#include "map.h"
#include "os/main_loop.h"
+#include "os/os.h"
#include "print_string.h"
-#include "map.h"
#include "scene/resources/texture.h"
-#include "os/os.h"
+#include "servers/physics_2d_server.h"
+#include "servers/visual_server.h"
-static const unsigned char convex_png[]={
-0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x40,0x0,0x0,0x0,0x40,0x8,0x6,0x0,0x0,0x0,0xaa,0x69,0x71,0xde,0x0,0x0,0x0,0x1,0x73,0x52,0x47,0x42,0x0,0xae,0xce,0x1c,0xe9,0x0,0x0,0x0,0x6,0x62,0x4b,0x47,0x44,0x0,0x0,0x0,0x0,0x0,0x0,0xf9,0x43,0xbb,0x7f,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xdb,0x6,0xa,0x3,0x13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,0xc5,0xa2,0xf1,0xbe,0x50,0x6e,0xa,0x66,0x18,0x26,0x31,0x36,0x36,0x96,0x65,0x59,0x36,0x29,0x49,0x92,0xb7,0xbd,0xbd,0xfd,0x9f,0x72,0xda,0xf9,0xd1,0x1,0xa8,0x1,0x93,0xcf,0xe7,0xa9,0x93,0x93,0x13,0x1b,0x4d,0xd3,0x9f,0xb,0x82,0x60,0xf5,0x7a,0xbd,0xd9,0x54,0x2a,0xe5,0xcc,0x64,0x32,0xe,0xb9,0x6e,0xb9,0x16,0x8c,0x31,0x2e,0xda,0x6c,0xb6,0xc8,0xd0,0xd0,0x10,0x65,0xb3,0xd9,0x92,0x95,0xa8,0x6e,0xc5,0x0,0xa8,0xe9,0x96,0x68,0x34,0x6a,0xdd,0xdf,0xdf,0x6f,0x76,0xb9,0x5c,0x9f,0x89,0xa2,0x58,0xbf,0xb8,0xb8,0x8,0x26,0x93,0x29,0x3b,0x3c,0x3c,0x8c,0xed,0x76,0x7b,0xd2,0x68,0x34,0xfe,0xd0,0xd8,0xd8,0x98,0xae,0xb6,0xe0,0x8a,0x1,0x50,0xb,0xe6,0xa9,0x5,0xbf,0x9c,0x97,0xf3,0xff,0xf3,0x2f,0x6a,0x82,0x7f,0xf6,0x4e,0xca,0x1b,0xf5,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
+static const unsigned char convex_png[] = {
+ 0x89, 0x50, 0x4e, 0x47, 0xd, 0xa, 0x1a, 0xa, 0x0, 0x0, 0x0, 0xd, 0x49, 0x48, 0x44, 0x52, 0x0, 0x0, 0x0, 0x40, 0x0, 0x0, 0x0, 0x40, 0x8, 0x6, 0x0, 0x0, 0x0, 0xaa, 0x69, 0x71, 0xde, 0x0, 0x0, 0x0, 0x1, 0x73, 0x52, 0x47, 0x42, 0x0, 0xae, 0xce, 0x1c, 0xe9, 0x0, 0x0, 0x0, 0x6, 0x62, 0x4b, 0x47, 0x44, 0x0, 0x0, 0x0, 0x0, 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xe6, 0xa9, 0x5, 0xbf, 0x9c, 0x97, 0xf3, 0xff, 0xf3, 0x2f, 0x6a, 0x82, 0x7f, 0xf6, 0x4e, 0xca, 0x1b, 0xf5, 0x0, 0x0, 0x0, 0x0, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
};
-
class TestPhysics2DMainLoop : public MainLoop {
- OBJ_TYPE( TestPhysics2DMainLoop, MainLoop );
-
+ OBJ_TYPE(TestPhysics2DMainLoop, MainLoop);
RID circle_img;
RID circle_shape;
@@ -53,8 +51,7 @@ class TestPhysics2DMainLoop : public MainLoop {
RID ray_query;
Matrix32 view_xform;
- Vector2 ray_from,ray_to;
-
+ Vector2 ray_from, ray_to;
struct BodyShapeData {
@@ -62,10 +59,8 @@ class TestPhysics2DMainLoop : public MainLoop {
RID shape;
};
-
BodyShapeData body_shape_data[6];
-
void _create_body_shape_data() {
VisualServer *vs = VisualServer::get_singleton();
Physics2DServer *ps = Physics2DServer::get_singleton();
@@ -75,53 +70,51 @@ class TestPhysics2DMainLoop : public MainLoop {
{
DVector<uint8_t> pixels;
- pixels.resize(32*2*2);
- for(int i=0;i<2;i++) {
+ pixels.resize(32 * 2 * 2);
+ for (int i = 0; i < 2; i++) {
- for(int j=0;j<32;j++) {
+ for (int j = 0; j < 32; j++) {
- pixels.set(i*32*2+j*2+0,(j==0)?255:0);
- pixels.set(i*32*2+j*2+1,255);
+ pixels.set(i * 32 * 2 + j * 2 + 0, (j == 0) ? 255 : 0);
+ pixels.set(i * 32 * 2 + j * 2 + 1, 255);
}
}
- Image image(32,2,0,Image::FORMAT_GRAYSCALE_ALPHA,pixels);
+ Image image(32, 2, 0, Image::FORMAT_GRAYSCALE_ALPHA, pixels);
- body_shape_data[Physics2DServer::SHAPE_SEGMENT].image=vs->texture_create_from_image(image);
+ body_shape_data[Physics2DServer::SHAPE_SEGMENT].image = vs->texture_create_from_image(image);
RID segment_shape = ps->shape_create(Physics2DServer::SHAPE_SEGMENT);
- Rect2 sg(Point2(-16,0),Point2(16,0));
- ps->shape_set_data(segment_shape,sg);
+ Rect2 sg(Point2(-16, 0), Point2(16, 0));
+ ps->shape_set_data(segment_shape, sg);
body_shape_data[Physics2DServer::SHAPE_SEGMENT].shape = segment_shape;
-
}
// CIRCLE
{
DVector<uint8_t> pixels;
- pixels.resize(32*32*2);
- for(int i=0;i<32;i++) {
+ pixels.resize(32 * 32 * 2);
+ for (int i = 0; i < 32; i++) {
- for(int j=0;j<32;j++) {
+ for (int j = 0; j < 32; j++) {
- bool black=Vector2(i-16,j-16).length_squared() < 16*16;
+ bool black = Vector2(i - 16, j - 16).length_squared() < 16 * 16;
- pixels.set(i*32*2+j*2+0,(i==16 || j==16)?255:0);
- pixels.set(i*32*2+j*2+1,black?255:0);
+ pixels.set(i * 32 * 2 + j * 2 + 0, (i == 16 || j == 16) ? 255 : 0);
+ pixels.set(i * 32 * 2 + j * 2 + 1, black ? 255 : 0);
}
}
- Image image(32,32,0,Image::FORMAT_GRAYSCALE_ALPHA,pixels);
+ Image image(32, 32, 0, Image::FORMAT_GRAYSCALE_ALPHA, pixels);
- body_shape_data[Physics2DServer::SHAPE_CIRCLE].image=vs->texture_create_from_image(image);
+ body_shape_data[Physics2DServer::SHAPE_CIRCLE].image = vs->texture_create_from_image(image);
RID circle_shape = ps->shape_create(Physics2DServer::SHAPE_CIRCLE);
- ps->shape_set_data(circle_shape,16);
+ ps->shape_set_data(circle_shape, 16);
body_shape_data[Physics2DServer::SHAPE_CIRCLE].shape = circle_shape;
-
}
// BOX
@@ -129,165 +122,149 @@ class TestPhysics2DMainLoop : public MainLoop {
{
DVector<uint8_t> pixels;
- pixels.resize(32*32*2);
- for(int i=0;i<32;i++) {
+ pixels.resize(32 * 32 * 2);
+ for (int i = 0; i < 32; i++) {
- for(int j=0;j<32;j++) {
+ for (int j = 0; j < 32; j++) {
- bool black=i>0 && i<31 && j>0 && j<31;
+ bool black = i > 0 && i < 31 && j > 0 && j < 31;
- pixels.set(i*32*2+j*2+0,black?0:255);
- pixels.set(i*32*2+j*2+1,255);
+ pixels.set(i * 32 * 2 + j * 2 + 0, black ? 0 : 255);
+ pixels.set(i * 32 * 2 + j * 2 + 1, 255);
}
}
- Image image(32,32,0,Image::FORMAT_GRAYSCALE_ALPHA,pixels);
+ Image image(32, 32, 0, Image::FORMAT_GRAYSCALE_ALPHA, pixels);
- body_shape_data[Physics2DServer::SHAPE_RECTANGLE].image=vs->texture_create_from_image(image);
+ body_shape_data[Physics2DServer::SHAPE_RECTANGLE].image = vs->texture_create_from_image(image);
RID rectangle_shape = ps->shape_create(Physics2DServer::SHAPE_RECTANGLE);
- ps->shape_set_data(rectangle_shape,Vector2(16,16));
+ ps->shape_set_data(rectangle_shape, Vector2(16, 16));
body_shape_data[Physics2DServer::SHAPE_RECTANGLE].shape = rectangle_shape;
-
}
-
// CAPSULE
{
DVector<uint8_t> pixels;
- pixels.resize(32*64*2);
- for(int i=0;i<64;i++) {
-
- for(int j=0;j<32;j++) {
+ pixels.resize(32 * 64 * 2);
+ for (int i = 0; i < 64; i++) {
+ for (int j = 0; j < 32; j++) {
- int si = i>48 ? i - 32 : (i<16 ? i : 16);
- bool black=Vector2(si-16,j-16).length_squared() < 16*16;
-
- pixels.set(i*32*2+j*2+0,(i==16 || j==16 || i==48)?255:0);
- pixels.set(i*32*2+j*2+1,black?255:0);
+ int si = i > 48 ? i - 32 : (i < 16 ? i : 16);
+ bool black = Vector2(si - 16, j - 16).length_squared() < 16 * 16;
+ pixels.set(i * 32 * 2 + j * 2 + 0, (i == 16 || j == 16 || i == 48) ? 255 : 0);
+ pixels.set(i * 32 * 2 + j * 2 + 1, black ? 255 : 0);
}
}
- Image image(32,64,0,Image::FORMAT_GRAYSCALE_ALPHA,pixels);
+ Image image(32, 64, 0, Image::FORMAT_GRAYSCALE_ALPHA, pixels);
- body_shape_data[Physics2DServer::SHAPE_CAPSULE].image=vs->texture_create_from_image(image);
+ body_shape_data[Physics2DServer::SHAPE_CAPSULE].image = vs->texture_create_from_image(image);
RID capsule_shape = ps->shape_create(Physics2DServer::SHAPE_CAPSULE);
- ps->shape_set_data(capsule_shape,Vector2(16,32));
+ ps->shape_set_data(capsule_shape, Vector2(16, 32));
body_shape_data[Physics2DServer::SHAPE_CAPSULE].shape = capsule_shape;
-
}
// CONVEX
{
-
Image image(convex_png);
- body_shape_data[Physics2DServer::SHAPE_CUSTOM+1].image=vs->texture_create_from_image(image);
+ body_shape_data[Physics2DServer::SHAPE_CUSTOM + 1].image = vs->texture_create_from_image(image);
RID convex_polygon_shape = ps->shape_create(Physics2DServer::SHAPE_CONVEX_POLYGON);
DVector<Vector2> arr;
- Point2 sb(32,32);
- arr.push_back(Point2(20,3)-sb);
- arr.push_back(Point2(58,23)-sb);
- arr.push_back(Point2(55,54)-sb);
- arr.push_back(Point2(27,60)-sb);
- arr.push_back(Point2(5,56)-sb);
- arr.push_back(Point2(4,20)-sb);
- arr.push_back(Point2(11,7)-sb);
- ps->shape_set_data(convex_polygon_shape,arr);
-
- body_shape_data[Physics2DServer::SHAPE_CUSTOM+1].shape = convex_polygon_shape;
+ Point2 sb(32, 32);
+ arr.push_back(Point2(20, 3) - sb);
+ arr.push_back(Point2(58, 23) - sb);
+ arr.push_back(Point2(55, 54) - sb);
+ arr.push_back(Point2(27, 60) - sb);
+ arr.push_back(Point2(5, 56) - sb);
+ arr.push_back(Point2(4, 20) - sb);
+ arr.push_back(Point2(11, 7) - sb);
+ ps->shape_set_data(convex_polygon_shape, arr);
+ body_shape_data[Physics2DServer::SHAPE_CUSTOM + 1].shape = convex_polygon_shape;
}
-
-
}
-
-
-
void _do_ray_query() {
-// Physics2DServer *ps = Physics2DServer::get_singleton();
- // ps->query_intersection_segment(ray_query,ray_from,ray_to);
-
+ // Physics2DServer *ps = Physics2DServer::get_singleton();
+ // ps->query_intersection_segment(ray_query,ray_from,ray_to);
}
protected:
+ void input_event(const InputEvent &p_event) {
+ if (p_event.type == InputEvent::MOUSE_BUTTON) {
- void input_event(const InputEvent& p_event) {
-
- if (p_event.type==InputEvent::MOUSE_BUTTON) {
-
- const InputEventMouseButton &mb=p_event.mouse_button;
+ const InputEventMouseButton &mb = p_event.mouse_button;
if (mb.pressed) {
- Point2 p( mb.x, mb.y );
+ Point2 p(mb.x, mb.y);
- if (mb.button_index==1) {
- ray_to=p;
+ if (mb.button_index == 1) {
+ ray_to = p;
_do_ray_query();
- } else if (mb.button_index==2) {
- ray_from=p;
+ } else if (mb.button_index == 2) {
+ ray_from = p;
_do_ray_query();
}
-
}
}
- if (p_event.type==InputEvent::MOUSE_MOTION) {
+ if (p_event.type == InputEvent::MOUSE_MOTION) {
- const InputEventMouseMotion &mm=p_event.mouse_motion;
+ const InputEventMouseMotion &mm = p_event.mouse_motion;
- Point2 p( mm.x, mm.y );
+ Point2 p(mm.x, mm.y);
- if (mm.button_mask&BUTTON_MASK_LEFT) {
- ray_to=p;
+ if (mm.button_mask & BUTTON_MASK_LEFT) {
+ ray_to = p;
_do_ray_query();
- } else if (mm.button_mask&BUTTON_MASK_RIGHT) {
- ray_from=p;
+ } else if (mm.button_mask & BUTTON_MASK_RIGHT) {
+ ray_from = p;
_do_ray_query();
}
}
}
- RID _add_body(Physics2DServer::ShapeType p_shape, const Matrix32& p_xform) {
+ RID _add_body(Physics2DServer::ShapeType p_shape, const Matrix32 &p_xform) {
VisualServer *vs = VisualServer::get_singleton();
Physics2DServer *ps = Physics2DServer::get_singleton();
RID body = ps->body_create();
- ps->body_add_shape(body,body_shape_data[p_shape].shape);
- ps->body_set_space(body,space);
- ps->body_set_continuous_collision_detection_mode(body,Physics2DServer::CCD_MODE_CAST_SHAPE);
- ps->body_set_state(body,Physics2DServer::BODY_STATE_TRANSFORM,p_xform);
+ ps->body_add_shape(body, body_shape_data[p_shape].shape);
+ ps->body_set_space(body, space);
+ ps->body_set_continuous_collision_detection_mode(body, Physics2DServer::CCD_MODE_CAST_SHAPE);
+ ps->body_set_state(body, Physics2DServer::BODY_STATE_TRANSFORM, p_xform);
-// print_line("add body with xform: "+p_xform);
+ // print_line("add body with xform: "+p_xform);
RID sprite = vs->canvas_item_create();
- vs->canvas_item_set_parent(sprite,canvas);
- vs->canvas_item_set_transform(sprite,p_xform);
- Size2 imgsize( vs->texture_get_width(body_shape_data[p_shape].image),vs->texture_get_height(body_shape_data[p_shape].image) );
- vs->canvas_item_add_texture_rect(sprite,Rect2(-imgsize/2.0,imgsize),body_shape_data[p_shape].image);
+ vs->canvas_item_set_parent(sprite, canvas);
+ vs->canvas_item_set_transform(sprite, p_xform);
+ Size2 imgsize(vs->texture_get_width(body_shape_data[p_shape].image), vs->texture_get_height(body_shape_data[p_shape].image));
+ vs->canvas_item_add_texture_rect(sprite, Rect2(-imgsize / 2.0, imgsize), body_shape_data[p_shape].image);
- ps->body_set_force_integration_callback(body,this,"_body_moved",sprite);
-// RID q = ps->query_create(this,"_body_moved",sprite);
-// ps->query_body_state(q,body);
+ ps->body_set_force_integration_callback(body, this, "_body_moved", sprite);
+ // RID q = ps->query_create(this,"_body_moved",sprite);
+ // ps->query_body_state(q,body);
return body;
}
- void _add_plane(const Vector2& p_normal, real_t p_d) {
+ void _add_plane(const Vector2 &p_normal, real_t p_d) {
Physics2DServer *ps = Physics2DServer::get_singleton();
@@ -296,111 +273,98 @@ protected:
arr.push_back(p_d);
RID plane = ps->shape_create(Physics2DServer::SHAPE_LINE);
- ps->shape_set_data(plane,arr);
+ ps->shape_set_data(plane, arr);
RID plane_body = ps->body_create(Physics2DServer::BODY_MODE_STATIC);
- ps->body_set_space(plane_body,space);
- ps->body_add_shape(plane_body,plane);
-
+ ps->body_set_space(plane_body, space);
+ ps->body_add_shape(plane_body, plane);
}
- void _add_concave(const Vector<Vector2>& p_points,const Matrix32& p_xform=Matrix32()) {
+ void _add_concave(const Vector<Vector2> &p_points, const Matrix32 &p_xform = Matrix32()) {
Physics2DServer *ps = Physics2DServer::get_singleton();
VisualServer *vs = VisualServer::get_singleton();
RID concave = ps->shape_create(Physics2DServer::SHAPE_CONCAVE_POLYGON);
- ps->shape_set_data(concave,p_points);
+ ps->shape_set_data(concave, p_points);
RID body = ps->body_create(Physics2DServer::BODY_MODE_STATIC);
- ps->body_set_space(body,space);
- ps->body_add_shape(body,concave);
- ps->body_set_state(body,Physics2DServer::BODY_STATE_TRANSFORM,p_xform);
-
+ ps->body_set_space(body, space);
+ ps->body_add_shape(body, concave);
+ ps->body_set_state(body, Physics2DServer::BODY_STATE_TRANSFORM, p_xform);
RID sprite = vs->canvas_item_create();
- vs->canvas_item_set_parent(sprite,canvas);
- vs->canvas_item_set_transform(sprite,p_xform);
- for(int i=0;i<p_points.size();i+=2) {
- vs->canvas_item_add_line(sprite,p_points[i],p_points[i+1],Color(0,0,0),2);
+ vs->canvas_item_set_parent(sprite, canvas);
+ vs->canvas_item_set_transform(sprite, p_xform);
+ for (int i = 0; i < p_points.size(); i += 2) {
+ vs->canvas_item_add_line(sprite, p_points[i], p_points[i + 1], Color(0, 0, 0), 2);
}
-
}
- void _body_moved(Object *p_state,RID p_sprite) {
- Physics2DDirectBodyState *state=(Physics2DDirectBodyState *)p_state;
- VisualServer::get_singleton()->canvas_item_set_transform(p_sprite,state->get_transform());
+ void _body_moved(Object *p_state, RID p_sprite) {
+ Physics2DDirectBodyState *state = (Physics2DDirectBodyState *)p_state;
+ VisualServer::get_singleton()->canvas_item_set_transform(p_sprite, state->get_transform());
}
- void _ray_query_callback(const RID& p_rid, ObjectID p_id, int p_shape, const Vector2& p_point, const Vector2& p_normal) {
-
+ void _ray_query_callback(const RID &p_rid, ObjectID p_id, int p_shape, const Vector2 &p_point, const Vector2 &p_normal) {
Vector2 ray_end;
if (p_rid.is_valid()) {
- ray_end=p_point;
+ ray_end = p_point;
} else {
- ray_end=ray_to;
+ ray_end = ray_to;
}
VisualServer *vs = VisualServer::get_singleton();
vs->canvas_item_clear(ray);
- vs->canvas_item_add_line(ray,ray_from,ray_end,p_rid.is_valid()?Color(0,1,0.4):Color(1,0.4,0),2);
+ vs->canvas_item_add_line(ray, ray_from, ray_end, p_rid.is_valid() ? Color(0, 1, 0.4) : Color(1, 0.4, 0), 2);
if (p_rid.is_valid())
- vs->canvas_item_add_line(ray,ray_end,ray_end+p_normal*20,p_rid.is_valid()?Color(0,1,0.4):Color(1,0.4,0),2);
-
+ vs->canvas_item_add_line(ray, ray_end, ray_end + p_normal * 20, p_rid.is_valid() ? Color(0, 1, 0.4) : Color(1, 0.4, 0), 2);
}
static void _bind_methods() {
-
- ObjectTypeDB::bind_method(_MD("_body_moved"),&TestPhysics2DMainLoop::_body_moved);
- ObjectTypeDB::bind_method(_MD("_ray_query_callback"),&TestPhysics2DMainLoop::_ray_query_callback);
+ ObjectTypeDB::bind_method(_MD("_body_moved"), &TestPhysics2DMainLoop::_body_moved);
+ ObjectTypeDB::bind_method(_MD("_ray_query_callback"), &TestPhysics2DMainLoop::_ray_query_callback);
}
-
public:
-
-
-
virtual void init() {
VisualServer *vs = VisualServer::get_singleton();
Physics2DServer *ps = Physics2DServer::get_singleton();
-
-
- space=ps->space_create();
- ps->space_set_active(space,true);
+ space = ps->space_create();
+ ps->space_set_active(space, true);
ps->set_active(true);
- ps->area_set_param(space,Physics2DServer::AREA_PARAM_GRAVITY_VECTOR,Vector2(0,1));
- ps->area_set_param(space,Physics2DServer::AREA_PARAM_GRAVITY,98);
+ ps->area_set_param(space, Physics2DServer::AREA_PARAM_GRAVITY_VECTOR, Vector2(0, 1));
+ ps->area_set_param(space, Physics2DServer::AREA_PARAM_GRAVITY, 98);
{
RID vp = vs->viewport_create();
canvas = vs->canvas_create();
- vs->viewport_attach_canvas(vp,canvas);
+ vs->viewport_attach_canvas(vp, canvas);
vs->viewport_attach_to_screen(vp);
Matrix32 smaller;
//smaller.scale(Vector2(0.6,0.6));
//smaller.elements[2]=Vector2(100,0);
//view_xform = smaller;
- vs->viewport_set_canvas_transform(vp,canvas,view_xform);
-
+ vs->viewport_set_canvas_transform(vp, canvas, view_xform);
}
ray = vs->canvas_item_create();
- vs->canvas_item_set_parent(ray,canvas);
+ vs->canvas_item_set_parent(ray, canvas);
//ray_query = ps->query_create(this,"_ray_query_callback",Variant());
//ps->query_intersection(ray_query,space);
_create_body_shape_data();
- for(int i=0;i<32;i++) {
+ for (int i = 0; i < 32; i++) {
- Physics2DServer::ShapeType types[4]={
+ Physics2DServer::ShapeType types[4] = {
Physics2DServer::SHAPE_CIRCLE,
Physics2DServer::SHAPE_CAPSULE,
Physics2DServer::SHAPE_RECTANGLE,
@@ -408,9 +372,9 @@ public:
};
- Physics2DServer::ShapeType type = types[i%4];
-// type=Physics2DServer::SHAPE_SEGMENT;
- RID b = _add_body(type,Matrix32(i*0.8,Point2(152+i*40,100-40*i)));
+ Physics2DServer::ShapeType type = types[i % 4];
+ // type=Physics2DServer::SHAPE_SEGMENT;
+ RID b = _add_body(type, Matrix32(i * 0.8, Point2(152 + i * 40, 100 - 40 * i)));
//if (i==0)
// ps->body_set_mode(b,Physics2DServer::BODY_MODE_STATIC);
}
@@ -421,47 +385,36 @@ public:
Point2 prev;
Vector<Point2> parr;
- for(int i=0;i<30;i++) {
+ for (int i = 0; i < 30; i++) {
- Point2 p(i*60,Math::randf() * 70+340);
- if (i>0) {
+ Point2 p(i * 60, Math::randf() * 70 + 340);
+ if (i > 0) {
parr.push_back(prev);
parr.push_back(p);
}
- prev=p;
+ prev = p;
}
_add_concave(parr);
//_add_plane(Vector2(0.0,-1).normalized(),-300);
//_add_plane(Vector2(1,0).normalized(),50);
//_add_plane(Vector2(-1,0).normalized(),-600);
-
}
virtual bool idle(float p_time) {
-
return false;
}
virtual void finish() {
-
-
}
-
TestPhysics2DMainLoop() {}
-
};
-
namespace TestPhysics2D {
+MainLoop *test() {
-MainLoop* test() {
-
-
- return memnew( TestPhysics2DMainLoop );
+ return memnew(TestPhysics2DMainLoop);
}
-
-
}
diff --git a/main/tests/test_physics_2d.h b/main/tests/test_physics_2d.h
index e2eb1f402..a3db9b08a 100644
--- a/main/tests/test_physics_2d.h
+++ b/main/tests/test_physics_2d.h
@@ -29,13 +29,11 @@
#ifndef TEST_PHYSICS_2D_H
#define TEST_PHYSICS_2D_H
-
#include "os/main_loop.h"
namespace TestPhysics2D {
-MainLoop* test();
-
+MainLoop *test();
}
#endif // TEST_PHYSICS_2D_H
diff --git a/main/tests/test_python.cpp b/main/tests/test_python.cpp
index f4a3d7a3a..b71995dd3 100644
--- a/main/tests/test_python.cpp
+++ b/main/tests/test_python.cpp
@@ -47,10 +47,7 @@ void test() {
PyRun_SimpleString("b=Moch();\n");
PyRun_SimpleString("b.mooch();\n");
PyRun_SimpleString("b.meis();\n");
-
-
}
-
}
#endif
diff --git a/main/tests/test_python.h b/main/tests/test_python.h
index 77e9603fe..b0d263796 100644
--- a/main/tests/test_python.h
+++ b/main/tests/test_python.h
@@ -36,7 +36,6 @@
namespace TestPython {
void test();
-
}
#endif
diff --git a/main/tests/test_render.cpp b/main/tests/test_render.cpp
index 9c3a287af..b36c5a2f0 100644
--- a/main/tests/test_render.cpp
+++ b/main/tests/test_render.cpp
@@ -27,22 +27,20 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "test_render.h"
-#include "servers/visual_server.h"
-#include "os/main_loop.h"
#include "math_funcs.h"
-#include "print_string.h"
+#include "os/keyboard.h"
+#include "os/main_loop.h"
#include "os/os.h"
+#include "print_string.h"
#include "quick_hull.h"
-#include "os/keyboard.h"
+#include "servers/visual_server.h"
#define OBJECT_COUNT 50
namespace TestRender {
-
class TestMainLoop : public MainLoop {
-
RID test_cube;
RID instance;
RID camera;
@@ -61,37 +59,30 @@ class TestMainLoop : public MainLoop {
float ofs;
bool quit;
-protected:
-
+protected:
public:
- virtual void input_event(const InputEvent& p_event) {
+ virtual void input_event(const InputEvent &p_event) {
- if (p_event.type==InputEvent::KEY && p_event.key.pressed)
- quit=true;
+ if (p_event.type == InputEvent::KEY && p_event.key.pressed)
+ quit = true;
}
virtual void init() {
-
print_line("INITIALIZING TEST RENDER");
- VisualServer *vs=VisualServer::get_singleton();
+ VisualServer *vs = VisualServer::get_singleton();
test_cube = vs->get_test_cube();
scenario = vs->scenario_create();
-
-
-
-
-
Vector<Vector3> vts;
-/*
+ /*
DVector<Plane> sp = Geometry::build_sphere_planes(2,5,5);
Geometry::MeshData md2 = Geometry::build_convex_mesh(sp);
vts=md2.vertices;
*/
-/*
+ /*
static const int s = 20;
for(int i=0;i<s;i++) {
@@ -117,20 +108,20 @@ public:
vts.push_back(Vector3(1,0,0));
vts.push_back(Vector3(-1,0,0));*/
- vts.push_back(Vector3(1,1,1));
- vts.push_back(Vector3(1,-1,1));
- vts.push_back(Vector3(-1,1,1));
- vts.push_back(Vector3(-1,-1,1));
- vts.push_back(Vector3(1,1,-1));
- vts.push_back(Vector3(1,-1,-1));
- vts.push_back(Vector3(-1,1,-1));
- vts.push_back(Vector3(-1,-1,-1));
+ vts.push_back(Vector3(1, 1, 1));
+ vts.push_back(Vector3(1, -1, 1));
+ vts.push_back(Vector3(-1, 1, 1));
+ vts.push_back(Vector3(-1, -1, 1));
+ vts.push_back(Vector3(1, 1, -1));
+ vts.push_back(Vector3(1, -1, -1));
+ vts.push_back(Vector3(-1, 1, -1));
+ vts.push_back(Vector3(-1, -1, -1));
Geometry::MeshData md;
- Error err = QuickHull::build(vts,md);
- print_line("ERR: "+itos(err));
+ Error err = QuickHull::build(vts, md);
+ print_line("ERR: " + itos(err));
test_cube = vs->mesh_create();
- vs->mesh_add_surface_from_mesh_data(test_cube,md);
+ vs->mesh_add_surface_from_mesh_data(test_cube, md);
//vs->scenario_set_debug(scenario,VS::SCENARIO_DEBUG_WIREFRAME);
/*
@@ -142,43 +133,38 @@ public:
vs->material_set_shader(tcmat,sm);
*/
-
List<String> cmdline = OS::get_singleton()->get_cmdline_args();
int object_count = OBJECT_COUNT;
- if (cmdline.size() > 0 && cmdline[cmdline.size()-1].to_int()) {
- object_count = cmdline[cmdline.size()-1].to_int();
+ if (cmdline.size() > 0 && cmdline[cmdline.size() - 1].to_int()) {
+ object_count = cmdline[cmdline.size() - 1].to_int();
};
- for (int i=0;i<object_count;i++) {
+ for (int i = 0; i < object_count; i++) {
InstanceInfo ii;
+ ii.instance = vs->instance_create2(test_cube, scenario);
- ii.instance = vs->instance_create2( test_cube, scenario );
-
-
- ii.base.translate( Math::random(-20,20), Math::random(-20,20),Math::random(-20,18) );
- ii.base.rotate( Vector3(0,1,0), Math::randf() * Math_PI );
- ii.base.rotate( Vector3(1,0,0), Math::randf() * Math_PI );
- vs->instance_set_transform( ii.instance, ii.base );
+ ii.base.translate(Math::random(-20, 20), Math::random(-20, 20), Math::random(-20, 18));
+ ii.base.rotate(Vector3(0, 1, 0), Math::randf() * Math_PI);
+ ii.base.rotate(Vector3(1, 0, 0), Math::randf() * Math_PI);
+ vs->instance_set_transform(ii.instance, ii.base);
- ii.rot_axis = Vector3( Math::random(-1,1), Math::random(-1,1), Math::random(-1,1) ).normalized();
+ ii.rot_axis = Vector3(Math::random(-1, 1), Math::random(-1, 1), Math::random(-1, 1)).normalized();
instances.push_back(ii);
-
}
camera = vs->camera_create();
-// vs->camera_set_perspective( camera, 60.0,0.1, 100.0 );
+ // vs->camera_set_perspective( camera, 60.0,0.1, 100.0 );
viewport = vs->viewport_create();
vs->viewport_attach_to_screen(viewport);
- vs->viewport_attach_camera( viewport, camera );
- vs->viewport_set_scenario( viewport, scenario );
- vs->camera_set_transform(camera, Transform( Matrix3(), Vector3(0,3,30 ) ) );
- vs->camera_set_perspective( camera, 60, 0.1, 1000);
-
+ vs->viewport_attach_camera(viewport, camera);
+ vs->viewport_set_scenario(viewport, scenario);
+ vs->camera_set_transform(camera, Transform(Matrix3(), Vector3(0, 3, 30)));
+ vs->camera_set_perspective(camera, 60, 0.1, 1000);
/*
RID lightaux = vs->light_create( VisualServer::LIGHT_OMNI );
@@ -190,47 +176,47 @@ public:
RID lightaux;
//*
- lightaux = vs->light_create( VisualServer::LIGHT_DIRECTIONAL );
+ lightaux = vs->light_create(VisualServer::LIGHT_DIRECTIONAL);
//vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_AMBIENT, Color(0.0,0.0,0.0) );
- vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_DIFFUSE, Color(1.0,1.0,1.0) );
+ vs->light_set_color(lightaux, VisualServer::LIGHT_COLOR_DIFFUSE, Color(1.0, 1.0, 1.0));
//vs->light_set_shadow( lightaux, true );
- light = vs->instance_create2( lightaux, scenario );
+ light = vs->instance_create2(lightaux, scenario);
Transform lla;
//lla.set_look_at(Vector3(),Vector3(1,-1,1),Vector3(0,1,0));
- lla.set_look_at(Vector3(),Vector3(-0.000000,-0.836026,-0.548690),Vector3(0,1,0));
+ lla.set_look_at(Vector3(), Vector3(-0.000000, -0.836026, -0.548690), Vector3(0, 1, 0));
- vs->instance_set_transform( light, lla );
+ vs->instance_set_transform(light, lla);
// */
//*
- lightaux = vs->light_create( VisualServer::LIGHT_OMNI );
-// vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_AMBIENT, Color(0.0,0.0,1.0) );
- vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_DIFFUSE, Color(1.0,1.0,0.0) );
- vs->light_set_param( lightaux, VisualServer::LIGHT_PARAM_RADIUS, 4 );
- vs->light_set_param( lightaux, VisualServer::LIGHT_PARAM_ENERGY, 8 );
+ lightaux = vs->light_create(VisualServer::LIGHT_OMNI);
+ // vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_AMBIENT, Color(0.0,0.0,1.0) );
+ vs->light_set_color(lightaux, VisualServer::LIGHT_COLOR_DIFFUSE, Color(1.0, 1.0, 0.0));
+ vs->light_set_param(lightaux, VisualServer::LIGHT_PARAM_RADIUS, 4);
+ vs->light_set_param(lightaux, VisualServer::LIGHT_PARAM_ENERGY, 8);
//vs->light_set_shadow( lightaux, true );
//light = vs->instance_create( lightaux );
// */
- ofs=0;
- quit=false;
+ ofs = 0;
+ quit = false;
}
virtual bool iteration(float p_time) {
- VisualServer *vs=VisualServer::get_singleton();
+ VisualServer *vs = VisualServer::get_singleton();
//Transform t;
//t.rotate(Vector3(0, 1, 0), ofs);
//t.translate(Vector3(0,0,20 ));
//vs->camera_set_transform(camera, t);
- ofs+=p_time*0.05;
+ ofs += p_time * 0.05;
//return quit;
- for(List<InstanceInfo>::Element *E=instances.front();E;E=E->next()) {
+ for (List<InstanceInfo>::Element *E = instances.front(); E; E = E->next()) {
- Transform pre( Matrix3(E->get().rot_axis, ofs), Vector3() );
- vs->instance_set_transform( E->get().instance, pre * E->get().base );
+ Transform pre(Matrix3(E->get().rot_axis, ofs), Vector3());
+ vs->instance_set_transform(E->get().instance, pre * E->get().base);
/*
if( !E->next() ) {
@@ -246,18 +232,12 @@ public:
return quit;
}
-
virtual void finish() {
-
}
-
};
+MainLoop *test() {
-MainLoop* test() {
-
- return memnew( TestMainLoop );
-
+ return memnew(TestMainLoop);
}
-
}
diff --git a/main/tests/test_render.h b/main/tests/test_render.h
index 6993e75b9..c78a1d064 100644
--- a/main/tests/test_render.h
+++ b/main/tests/test_render.h
@@ -37,8 +37,7 @@
namespace TestRender {
-MainLoop* test();
-
+MainLoop *test();
}
#endif
diff --git a/main/tests/test_shader_lang.cpp b/main/tests/test_shader_lang.cpp
index 9c0075c47..e85a002ed 100644
--- a/main/tests/test_shader_lang.cpp
+++ b/main/tests/test_shader_lang.cpp
@@ -28,28 +28,25 @@
/*************************************************************************/
#include "test_shader_lang.h"
-
+#include "os/file_access.h"
#include "os/main_loop.h"
#include "os/os.h"
-#include "os/file_access.h"
+#include "drivers/gles2/shader_compiler_gles2.h"
+#include "print_string.h"
#include "scene/gui/control.h"
#include "scene/gui/text_edit.h"
-#include "print_string.h"
#include "servers/visual/shader_language.h"
-#include "drivers/gles2/shader_compiler_gles2.h"
-
typedef ShaderLanguage SL;
namespace TestShaderLang {
-
static String _mktab(int p_level) {
String tb;
- for(int i=0;i<p_level;i++) {
- tb+="\t";
+ for (int i = 0; i < p_level; i++) {
+ tb += "\t";
}
return tb;
@@ -57,7 +54,7 @@ static String _mktab(int p_level) {
static String _typestr(SL::DataType p_type) {
- switch(p_type) {
+ switch (p_type) {
case SL::TYPE_VOID: return "void";
case SL::TYPE_BOOL: return "bool";
@@ -77,7 +74,7 @@ static String _typestr(SL::DataType p_type) {
static String _opstr(SL::Operator p_op) {
- switch(p_op) {
+ switch (p_op) {
case SL::OP_ASSIGN: return "=";
case SL::OP_ADD: return "+";
case SL::OP_SUB: return "-";
@@ -103,97 +100,108 @@ static String _opstr(SL::Operator p_op) {
return "";
}
-static String dump_node_code(SL::Node *p_node,int p_level) {
+static String dump_node_code(SL::Node *p_node, int p_level) {
String code;
- switch(p_node->type) {
+ switch (p_node->type) {
case SL::Node::TYPE_PROGRAM: {
- SL::ProgramNode *pnode=(SL::ProgramNode*)p_node;
-
- for(Map<StringName,SL::Uniform>::Element *E=pnode->uniforms.front();E;E=E->next()) {
+ SL::ProgramNode *pnode = (SL::ProgramNode *)p_node;
- String ucode="uniform ";
- ucode+=_typestr(E->get().type)+"="+String(E->get().default_value)+"\n";
- code+=ucode;
+ for (Map<StringName, SL::Uniform>::Element *E = pnode->uniforms.front(); E; E = E->next()) {
+ String ucode = "uniform ";
+ ucode += _typestr(E->get().type) + "=" + String(E->get().default_value) + "\n";
+ code += ucode;
}
- for(int i=0;i<pnode->functions.size();i++) {
+ for (int i = 0; i < pnode->functions.size(); i++) {
- SL::FunctionNode *fnode=pnode->functions[i].function;
+ SL::FunctionNode *fnode = pnode->functions[i].function;
String header;
- header=_typestr(fnode->return_type)+" "+fnode->name+"(";
- for(int i=0;i<fnode->arguments.size();i++) {
+ header = _typestr(fnode->return_type) + " " + fnode->name + "(";
+ for (int i = 0; i < fnode->arguments.size(); i++) {
- if (i>0)
- header+=", ";
- header+=_typestr(fnode->arguments[i].type)+" "+fnode->arguments[i].name;
+ if (i > 0)
+ header += ", ";
+ header += _typestr(fnode->arguments[i].type) + " " + fnode->arguments[i].name;
}
- header+=") {\n";
- code+=header;
- code+=dump_node_code(fnode->body,p_level+1);
- code+="}\n";
+ header += ") {\n";
+ code += header;
+ code += dump_node_code(fnode->body, p_level + 1);
+ code += "}\n";
}
- code+=dump_node_code(pnode->body,p_level);
+ code += dump_node_code(pnode->body, p_level);
} break;
case SL::Node::TYPE_FUNCTION: {
} break;
case SL::Node::TYPE_BLOCK: {
- SL::BlockNode *bnode=(SL::BlockNode*)p_node;
+ SL::BlockNode *bnode = (SL::BlockNode *)p_node;
//variables
- for(Map<StringName,SL::DataType>::Element *E=bnode->variables.front();E;E=E->next()) {
+ for (Map<StringName, SL::DataType>::Element *E = bnode->variables.front(); E; E = E->next()) {
- code+=_mktab(p_level)+_typestr(E->value())+" "+E->key()+";\n";
+ code += _mktab(p_level) + _typestr(E->value()) + " " + E->key() + ";\n";
}
- for(int i=0;i<bnode->statements.size();i++) {
+ for (int i = 0; i < bnode->statements.size(); i++) {
- code+=_mktab(p_level)+dump_node_code(bnode->statements[i],p_level)+";\n";
+ code += _mktab(p_level) + dump_node_code(bnode->statements[i], p_level) + ";\n";
}
-
} break;
case SL::Node::TYPE_VARIABLE: {
- SL::VariableNode *vnode=(SL::VariableNode*)p_node;
- code=vnode->name;
+ SL::VariableNode *vnode = (SL::VariableNode *)p_node;
+ code = vnode->name;
} break;
case SL::Node::TYPE_CONSTANT: {
- SL::ConstantNode *cnode=(SL::ConstantNode*)p_node;
- switch(cnode->datatype) {
-
+ SL::ConstantNode *cnode = (SL::ConstantNode *)p_node;
+ switch (cnode->datatype) {
- case SL::TYPE_BOOL: code=cnode->value.operator bool()?"true":"false"; break;
- case SL::TYPE_FLOAT: code=cnode->value; break;
- case SL::TYPE_VEC2: { Vector2 v = cnode->value; code="vec2("+rtos(v.x)+", "+rtos(v.y)+")"; } break;
- case SL::TYPE_VEC3: { Vector3 v = cnode->value; code="vec3("+rtos(v.x)+", "+rtos(v.y)+", "+rtos(v.z)+")"; } break;
- case SL::TYPE_VEC4: { Plane v = cnode->value; code="vec4("+rtos(v.normal.x)+", "+rtos(v.normal.y)+", "+rtos(v.normal.z)+", "+rtos(v.d)+")"; } break;
- case SL::TYPE_MAT3: { Matrix3 x = cnode->value; code="mat3( vec3("+rtos(x.get_axis(0).x)+", "+rtos(x.get_axis(0).y)+", "+rtos(x.get_axis(0).z)+"), vec3("+rtos(x.get_axis(1).x)+", "+rtos(x.get_axis(1).y)+", "+rtos(x.get_axis(1).z)+"), vec3("+rtos(x.get_axis(2).x)+", "+rtos(x.get_axis(2).y)+", "+rtos(x.get_axis(2).z)+"))"; } break;
- case SL::TYPE_MAT4: { Transform x = cnode->value; code="mat4( vec3("+rtos(x.basis.get_axis(0).x)+", "+rtos(x.basis.get_axis(0).y)+", "+rtos(x.basis.get_axis(0).z)+"), vec3("+rtos(x.basis.get_axis(1).x)+", "+rtos(x.basis.get_axis(1).y)+", "+rtos(x.basis.get_axis(1).z)+"), vec3("+rtos(x.basis.get_axis(2).x)+", "+rtos(x.basis.get_axis(2).y)+", "+rtos(x.basis.get_axis(2).z)+"), vec3("+rtos(x.origin.x)+", "+rtos(x.origin.y)+", "+rtos(x.origin.z)+"))"; } break;
- default: code="<error: "+Variant::get_type_name(cnode->value.get_type())+" ("+itos(cnode->datatype)+">";
+ case SL::TYPE_BOOL: code = cnode->value.operator bool() ? "true" : "false"; break;
+ case SL::TYPE_FLOAT: code = cnode->value; break;
+ case SL::TYPE_VEC2: {
+ Vector2 v = cnode->value;
+ code = "vec2(" + rtos(v.x) + ", " + rtos(v.y) + ")";
+ } break;
+ case SL::TYPE_VEC3: {
+ Vector3 v = cnode->value;
+ code = "vec3(" + rtos(v.x) + ", " + rtos(v.y) + ", " + rtos(v.z) + ")";
+ } break;
+ case SL::TYPE_VEC4: {
+ Plane v = cnode->value;
+ code = "vec4(" + rtos(v.normal.x) + ", " + rtos(v.normal.y) + ", " + rtos(v.normal.z) + ", " + rtos(v.d) + ")";
+ } break;
+ case SL::TYPE_MAT3: {
+ Matrix3 x = cnode->value;
+ code = "mat3( vec3(" + rtos(x.get_axis(0).x) + ", " + rtos(x.get_axis(0).y) + ", " + rtos(x.get_axis(0).z) + "), vec3(" + rtos(x.get_axis(1).x) + ", " + rtos(x.get_axis(1).y) + ", " + rtos(x.get_axis(1).z) + "), vec3(" + rtos(x.get_axis(2).x) + ", " + rtos(x.get_axis(2).y) + ", " + rtos(x.get_axis(2).z) + "))";
+ } break;
+ case SL::TYPE_MAT4: {
+ Transform x = cnode->value;
+ code = "mat4( vec3(" + rtos(x.basis.get_axis(0).x) + ", " + rtos(x.basis.get_axis(0).y) + ", " + rtos(x.basis.get_axis(0).z) + "), vec3(" + rtos(x.basis.get_axis(1).x) + ", " + rtos(x.basis.get_axis(1).y) + ", " + rtos(x.basis.get_axis(1).z) + "), vec3(" + rtos(x.basis.get_axis(2).x) + ", " + rtos(x.basis.get_axis(2).y) + ", " + rtos(x.basis.get_axis(2).z) + "), vec3(" + rtos(x.origin.x) + ", " + rtos(x.origin.y) + ", " + rtos(x.origin.z) + "))";
+ } break;
+ default: code = "<error: " + Variant::get_type_name(cnode->value.get_type()) + " (" + itos(cnode->datatype) + ">";
}
} break;
case SL::Node::TYPE_OPERATOR: {
- SL::OperatorNode *onode=(SL::OperatorNode*)p_node;
-
+ SL::OperatorNode *onode = (SL::OperatorNode *)p_node;
- switch(onode->op) {
+ switch (onode->op) {
case SL::OP_ASSIGN:
case SL::OP_ASSIGN_ADD:
case SL::OP_ASSIGN_SUB:
case SL::OP_ASSIGN_MUL:
case SL::OP_ASSIGN_DIV:
- code=dump_node_code(onode->arguments[0],p_level)+_opstr(onode->op)+dump_node_code(onode->arguments[1],p_level);
+ code = dump_node_code(onode->arguments[0], p_level) + _opstr(onode->op) + dump_node_code(onode->arguments[1], p_level);
break;
case SL::OP_ADD:
@@ -209,75 +217,71 @@ static String dump_node_code(SL::Node *p_node,int p_level) {
case SL::OP_CMP_OR:
case SL::OP_CMP_AND:
- code="("+dump_node_code(onode->arguments[0],p_level)+_opstr(onode->op)+dump_node_code(onode->arguments[1],p_level)+")";
+ code = "(" + dump_node_code(onode->arguments[0], p_level) + _opstr(onode->op) + dump_node_code(onode->arguments[1], p_level) + ")";
break;
case SL::OP_NEG:
case SL::OP_NOT:
- code=_opstr(onode->op)+dump_node_code(onode->arguments[0],p_level);
+ code = _opstr(onode->op) + dump_node_code(onode->arguments[0], p_level);
break;
case SL::OP_CALL:
case SL::OP_CONSTRUCT:
- code=dump_node_code(onode->arguments[0],p_level)+"(";
- for(int i=1;i<onode->arguments.size();i++) {
- if (i>1)
- code+=", ";
- code+=dump_node_code(onode->arguments[i],p_level);
+ code = dump_node_code(onode->arguments[0], p_level) + "(";
+ for (int i = 1; i < onode->arguments.size(); i++) {
+ if (i > 1)
+ code += ", ";
+ code += dump_node_code(onode->arguments[i], p_level);
}
- code+=")";
+ code += ")";
break;
default: {}
}
} break;
case SL::Node::TYPE_CONTROL_FLOW: {
- SL::ControlFlowNode *cfnode=(SL::ControlFlowNode*)p_node;
- if (cfnode->flow_op==SL::FLOW_OP_IF) {
+ SL::ControlFlowNode *cfnode = (SL::ControlFlowNode *)p_node;
+ if (cfnode->flow_op == SL::FLOW_OP_IF) {
- code+="if ("+dump_node_code(cfnode->statements[0],p_level)+") {\n";
- code+=dump_node_code(cfnode->statements[1],p_level+1);
- if (cfnode->statements.size()==3) {
+ code += "if (" + dump_node_code(cfnode->statements[0], p_level) + ") {\n";
+ code += dump_node_code(cfnode->statements[1], p_level + 1);
+ if (cfnode->statements.size() == 3) {
- code+="} else {\n";
- code+=dump_node_code(cfnode->statements[2],p_level+1);
+ code += "} else {\n";
+ code += dump_node_code(cfnode->statements[2], p_level + 1);
}
- code+="}\n";
+ code += "}\n";
- } else if (cfnode->flow_op==SL::FLOW_OP_RETURN) {
+ } else if (cfnode->flow_op == SL::FLOW_OP_RETURN) {
if (cfnode->statements.size()) {
- code="return "+dump_node_code(cfnode->statements[0],p_level);
+ code = "return " + dump_node_code(cfnode->statements[0], p_level);
} else {
- code="return";
+ code = "return";
}
}
} break;
case SL::Node::TYPE_MEMBER: {
- SL::MemberNode *mnode=(SL::MemberNode*)p_node;
- code=dump_node_code(mnode->owner,p_level)+"."+mnode->name;
+ SL::MemberNode *mnode = (SL::MemberNode *)p_node;
+ code = dump_node_code(mnode->owner, p_level) + "." + mnode->name;
} break;
}
return code;
-
}
-static Error recreate_code(void *p_str,SL::ProgramNode *p_program) {
+static Error recreate_code(void *p_str, SL::ProgramNode *p_program) {
print_line("recr");
- String *str=(String*)p_str;
+ String *str = (String *)p_str;
- *str=dump_node_code(p_program,0);
+ *str = dump_node_code(p_program, 0);
return OK;
-
-
}
-
-MainLoop* test() {
+MainLoop *test() {
List<String> cmdlargs = OS::get_singleton()->get_cmdline_args();
@@ -288,7 +292,7 @@ MainLoop* test() {
String test = cmdlargs.back()->get();
- FileAccess *fa = FileAccess::open(test,FileAccess::READ);
+ FileAccess *fa = FileAccess::open(test, FileAccess::READ);
if (!fa) {
ERR_FAIL_V(NULL);
@@ -296,45 +300,43 @@ MainLoop* test() {
String code;
- while(true) {
+ while (true) {
CharType c = fa->get_8();
if (fa->eof_reached())
break;
- code+=c;
+ code += c;
}
int errline;
int errcol;
String error;
print_line(SL::lex_debug(code));
- Error err = SL::compile(code,ShaderLanguage::SHADER_MATERIAL_FRAGMENT,NULL,NULL,&error,&errline,&errcol);
+ Error err = SL::compile(code, ShaderLanguage::SHADER_MATERIAL_FRAGMENT, NULL, NULL, &error, &errline, &errcol);
if (err) {
- print_line("Error: "+itos(errline)+":"+itos(errcol)+" "+error);
+ print_line("Error: " + itos(errline) + ":" + itos(errcol) + " " + error);
return NULL;
}
print_line("Compile OK! - pretty printing");
String rcode;
- err = SL::compile(code,ShaderLanguage::SHADER_MATERIAL_FRAGMENT,recreate_code,&rcode,&error,&errline,&errcol);
+ err = SL::compile(code, ShaderLanguage::SHADER_MATERIAL_FRAGMENT, recreate_code, &rcode, &error, &errline, &errcol);
if (!err) {
print_line(rcode);
}
ShaderCompilerGLES2 comp;
- String codeline,globalsline;
+ String codeline, globalsline;
SL::VarInfo vi;
- vi.name="mongs";
- vi.type=SL::TYPE_VEC3;
-
+ vi.name = "mongs";
+ vi.type = SL::TYPE_VEC3;
ShaderCompilerGLES2::Flags fl;
- comp.compile(code,ShaderLanguage::SHADER_MATERIAL_FRAGMENT,codeline,globalsline,fl);
+ comp.compile(code, ShaderLanguage::SHADER_MATERIAL_FRAGMENT, codeline, globalsline, fl);
return NULL;
}
-
}
diff --git a/main/tests/test_shader_lang.h b/main/tests/test_shader_lang.h
index f129fb224..cac78fb13 100644
--- a/main/tests/test_shader_lang.h
+++ b/main/tests/test_shader_lang.h
@@ -33,8 +33,7 @@
namespace TestShaderLang {
-MainLoop* test();
-
+MainLoop *test();
}
#endif // TEST_SHADER_LANG_H
diff --git a/main/tests/test_sound.cpp b/main/tests/test_sound.cpp
index 44cc117e0..07b78a207 100644
--- a/main/tests/test_sound.cpp
+++ b/main/tests/test_sound.cpp
@@ -27,69 +27,58 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "test_sound.h"
-#include "servers/visual_server.h"
-#include "os/main_loop.h"
-#include "math_funcs.h"
-#include "scene/resources/sample.h"
#include "io/resource_loader.h"
+#include "math_funcs.h"
+#include "os/main_loop.h"
+#include "os/os.h"
#include "print_string.h"
+#include "scene/resources/sample.h"
#include "servers/audio_server.h"
-#include "os/os.h"
+#include "servers/visual_server.h"
namespace TestSound {
-
class TestMainLoop : public MainLoop {
bool quit;
Ref<Sample> sample;
public:
- virtual void input_event(const InputEvent& p_event) {
-
-
+ virtual void input_event(const InputEvent &p_event) {
}
virtual void request_quit() {
- quit=true;
+ quit = true;
}
virtual void init() {
List<String> cmdline = OS::get_singleton()->get_cmdline_args();
- quit=false;
+ quit = false;
if (cmdline.size()) {
- sample=ResourceLoader::load(cmdline.back()->get());
+ sample = ResourceLoader::load(cmdline.back()->get());
ERR_FAIL_COND(sample.is_null());
print_line("Sample loaded OK");
}
RID voice = AudioServer::get_singleton()->voice_create();
- AudioServer::get_singleton()->voice_play( voice, sample->get_rid() );
-
-
+ AudioServer::get_singleton()->voice_play(voice, sample->get_rid());
}
virtual bool idle(float p_time) {
return false;
}
-
virtual bool iteration(float p_time) {
return quit;
}
virtual void finish() {
-
}
-
};
+MainLoop *test() {
-MainLoop* test() {
-
- return memnew( TestMainLoop );
-
+ return memnew(TestMainLoop);
}
-
}
diff --git a/main/tests/test_sound.h b/main/tests/test_sound.h
index 91b87a226..18d08ced2 100644
--- a/main/tests/test_sound.h
+++ b/main/tests/test_sound.h
@@ -33,8 +33,7 @@
namespace TestSound {
-MainLoop* test();
-
+MainLoop *test();
}
#endif // TEST_SOUND_H
diff --git a/main/tests/test_string.cpp b/main/tests/test_string.cpp
index 4496b9400..4f01bc256 100644
--- a/main/tests/test_string.cpp
+++ b/main/tests/test_string.cpp
@@ -29,10 +29,10 @@
#include "ustring.h"
#include <wchar.h>
//#include "math_funcs.h"
-#include <stdio.h>
-#include "os/os.h"
-#include "drivers/nrex/regex.h"
#include "core/io/ip_address.h"
+#include "drivers/nrex/regex.h"
+#include "os/os.h"
+#include <stdio.h>
#include "test_string.h"
@@ -45,10 +45,9 @@ bool test_1() {
String s = "Hello";
OS::get_singleton()->print("\tExpected: Hello\n");
- OS::get_singleton()->print("\tResulted: %ls\n",s.c_str());
-
- return (wcscmp(s.c_str(),L"Hello")==0);
+ OS::get_singleton()->print("\tResulted: %ls\n", s.c_str());
+ return (wcscmp(s.c_str(), L"Hello") == 0);
}
bool test_2() {
@@ -59,10 +58,9 @@ bool test_2() {
String t = s;
OS::get_singleton()->print("\tExpected: Dolly\n");
- OS::get_singleton()->print("\tResulted: %ls\n",t.c_str());
-
- return (wcscmp(t.c_str(),L"Dolly")==0);
+ OS::get_singleton()->print("\tResulted: %ls\n", t.c_str());
+ return (wcscmp(t.c_str(), L"Dolly") == 0);
}
bool test_3() {
@@ -73,10 +71,9 @@ bool test_3() {
String t(s);
OS::get_singleton()->print("\tExpected: Sheep\n");
- OS::get_singleton()->print("\tResulted: %ls\n",t.c_str());
-
- return (wcscmp(t.c_str(),L"Sheep")==0);
+ OS::get_singleton()->print("\tResulted: %ls\n", t.c_str());
+ return (wcscmp(t.c_str(), L"Sheep") == 0);
}
bool test_4() {
@@ -86,10 +83,9 @@ bool test_4() {
String s(L"Give me");
OS::get_singleton()->print("\tExpected: Give me\n");
- OS::get_singleton()->print("\tResulted: %ls\n",s.c_str());
-
- return (wcscmp(s.c_str(),L"Give me")==0);
+ OS::get_singleton()->print("\tResulted: %ls\n", s.c_str());
+ return (wcscmp(s.c_str(), L"Give me") == 0);
}
bool test_5() {
@@ -99,89 +95,81 @@ bool test_5() {
String s(L"Wool");
OS::get_singleton()->print("\tExpected: Wool\n");
- OS::get_singleton()->print("\tResulted: %ls\n",s.c_str());
-
- return (wcscmp(s.c_str(),L"Wool")==0);
+ OS::get_singleton()->print("\tResulted: %ls\n", s.c_str());
+ return (wcscmp(s.c_str(), L"Wool") == 0);
}
bool test_6() {
OS::get_singleton()->print("\n\nTest 6: comparisons (equal)\n");
-
- String s="Test Compare";
+ String s = "Test Compare";
OS::get_singleton()->print("\tComparing to \"Test Compare\"\n");
- if (! ( s=="Test Compare" ) )
+ if (!(s == "Test Compare"))
return false;
- if (! ( s==L"Test Compare" ) )
+ if (!(s == L"Test Compare"))
return false;
- if (! ( s==String("Test Compare") ) )
+ if (!(s == String("Test Compare")))
return false;
return true;
-
}
bool test_7() {
OS::get_singleton()->print("\n\nTest 7: comparisons (unequal)\n");
-
- String s="Test Compare";
+ String s = "Test Compare";
OS::get_singleton()->print("\tComparing to \"Test Compare\"\n");
- if (! ( s!="Peanut" ) )
+ if (!(s != "Peanut"))
return false;
- if (! ( s!=L"Coconut" ) )
+ if (!(s != L"Coconut"))
return false;
- if (! ( s!=String("Butter") ) )
+ if (!(s != String("Butter")))
return false;
return true;
-
}
bool test_8() {
OS::get_singleton()->print("\n\nTest 8: comparisons (operator<)\n");
-
- String s="Bees";
+ String s = "Bees";
OS::get_singleton()->print("\tComparing to \"Bees\"\n");
- if ( ! (s < "Elephant") )
+ if (!(s < "Elephant"))
return false;
- if ( s < L"Amber" )
+ if (s < L"Amber")
return false;
- if ( s < String("Beatrix") )
+ if (s < String("Beatrix"))
return false;
return true;
-
}
bool test_9() {
OS::get_singleton()->print("\n\nTest 9: Concatenation\n");
-
String s;
- s+="Have";
- s+=' ';
- s+='a';
- s+=String(" ");
+ s += "Have";
+ s += ' ';
+ s += 'a';
+ s += String(" ");
s = s + L"Nice";
s = s + " ";
s = s + String("Day");
@@ -189,14 +177,13 @@ bool test_9() {
OS::get_singleton()->print("\tComparing to \"Have a Nice Day\"\n");
return (s == "Have a Nice Day");
-
}
bool test_10() {
OS::get_singleton()->print("\n\nTest 10: Misc funcs (size/length/empty/etc)\n");
- if (! String("").empty())
+ if (!String("").empty())
return false;
if (String("Mellon").size() != 7)
@@ -206,44 +193,39 @@ bool test_10() {
return false;
return true;
-
}
-
bool test_11() {
OS::get_singleton()->print("\n\nTest 11: Operator[]\n");
- String a="Kugar Sane";
+ String a = "Kugar Sane";
- a[0]='S';
- a[6]='C';
+ a[0] = 'S';
+ a[6] = 'C';
if (a != "Sugar Cane")
return false;
- if (a[1]!='u')
+ if (a[1] != 'u')
return false;
return true;
-
}
bool test_12() {
OS::get_singleton()->print("\n\nTest 12: case functions\n");
-
- String a="MoMoNgA";
+ String a = "MoMoNgA";
if (a.to_upper() != "MOMONGA")
return false;
- if (a.nocasecmp_to("momonga")!=0)
+ if (a.nocasecmp_to("momonga") != 0)
return false;
return true;
-
}
bool test_13() {
@@ -252,16 +234,15 @@ bool test_13() {
/* how can i embed UTF in here? */
- static const CharType ustr[] = { 0x304A , 0x360F, 0x3088, 0x3046, 0 };
-// static const wchar_t ustr[] = { 'P', 0xCE, 'p',0xD3, 0 };
- String s=ustr;
+ static const CharType ustr[] = { 0x304A, 0x360F, 0x3088, 0x3046, 0 };
+ // static const wchar_t ustr[] = { 'P', 0xCE, 'p',0xD3, 0 };
+ String s = ustr;
- OS::get_singleton()->print("\tUnicode: %ls\n",ustr);
- s.parse_utf8( s.utf8().get_data() );
- OS::get_singleton()->print("\tConvert/Parse UTF8: %ls\n",s.c_str());
-
- return (s==ustr);
+ OS::get_singleton()->print("\tUnicode: %ls\n", ustr);
+ s.parse_utf8(s.utf8().get_data());
+ OS::get_singleton()->print("\tConvert/Parse UTF8: %ls\n", s.c_str());
+ return (s == ustr);
}
bool test_14() {
@@ -269,195 +250,180 @@ bool test_14() {
OS::get_singleton()->print("\n\nTest 14: ASCII\n");
String s = L"Primero Leche";
- OS::get_singleton()->print("\tAscii: %s\n",s.ascii().get_data());
-
- String t=s.ascii().get_data();
- return (s==t);
+ OS::get_singleton()->print("\tAscii: %s\n", s.ascii().get_data());
+ String t = s.ascii().get_data();
+ return (s == t);
}
bool test_15() {
OS::get_singleton()->print("\n\nTest 15: substr\n");
- String s="Killer Baby";
- OS::get_singleton()->print("\tsubstr(3,4) of \"%ls\" is \"%ls\"\n",s.c_str(),s.substr(3,4).c_str());
-
- return (s.substr(3,4)=="ler ");
+ String s = "Killer Baby";
+ OS::get_singleton()->print("\tsubstr(3,4) of \"%ls\" is \"%ls\"\n", s.c_str(), s.substr(3, 4).c_str());
+ return (s.substr(3, 4) == "ler ");
}
bool test_16() {
OS::get_singleton()->print("\n\nTest 16: find\n");
- String s="Pretty Woman";
- OS::get_singleton()->print("\tString: %ls\n",s.c_str());
- OS::get_singleton()->print("\t\"tty\" is at %i pos.\n",s.find("tty"));
- OS::get_singleton()->print("\t\"Revenge of the Monster Truck\" is at %i pos.\n",s.find("Revenge of the Monster Truck"));
+ String s = "Pretty Woman";
+ OS::get_singleton()->print("\tString: %ls\n", s.c_str());
+ OS::get_singleton()->print("\t\"tty\" is at %i pos.\n", s.find("tty"));
+ OS::get_singleton()->print("\t\"Revenge of the Monster Truck\" is at %i pos.\n", s.find("Revenge of the Monster Truck"));
- if (s.find("tty")!=3)
+ if (s.find("tty") != 3)
return false;
- if (s.find("Revenge of the Monster Truck")!=-1)
+ if (s.find("Revenge of the Monster Truck") != -1)
return false;
return true;
-
}
bool test_17() {
OS::get_singleton()->print("\n\nTest 17: find no case\n");
- String s="Pretty Whale";
- OS::get_singleton()->print("\tString: %ls\n",s.c_str());
- OS::get_singleton()->print("\t\"WHA\" is at %i pos.\n",s.findn("WHA"));
- OS::get_singleton()->print("\t\"Revenge of the Monster SawFish\" is at %i pos.\n",s.findn("Revenge of the Monster Truck"));
+ String s = "Pretty Whale";
+ OS::get_singleton()->print("\tString: %ls\n", s.c_str());
+ OS::get_singleton()->print("\t\"WHA\" is at %i pos.\n", s.findn("WHA"));
+ OS::get_singleton()->print("\t\"Revenge of the Monster SawFish\" is at %i pos.\n", s.findn("Revenge of the Monster Truck"));
- if (s.findn("WHA")!=7)
+ if (s.findn("WHA") != 7)
return false;
- if (s.findn("Revenge of the Monster SawFish")!=-1)
+ if (s.findn("Revenge of the Monster SawFish") != -1)
return false;
return true;
-
}
bool test_18() {
OS::get_singleton()->print("\n\nTest 18: find no case\n");
- String s="Pretty Whale";
- OS::get_singleton()->print("\tString: %ls\n",s.c_str());
- OS::get_singleton()->print("\t\"WHA\" is at %i pos.\n",s.findn("WHA"));
- OS::get_singleton()->print("\t\"Revenge of the Monster SawFish\" is at %i pos.\n",s.findn("Revenge of the Monster Truck"));
+ String s = "Pretty Whale";
+ OS::get_singleton()->print("\tString: %ls\n", s.c_str());
+ OS::get_singleton()->print("\t\"WHA\" is at %i pos.\n", s.findn("WHA"));
+ OS::get_singleton()->print("\t\"Revenge of the Monster SawFish\" is at %i pos.\n", s.findn("Revenge of the Monster Truck"));
- if (s.findn("WHA")!=7)
+ if (s.findn("WHA") != 7)
return false;
- if (s.findn("Revenge of the Monster SawFish")!=-1)
+ if (s.findn("Revenge of the Monster SawFish") != -1)
return false;
return true;
-
}
bool test_19() {
OS::get_singleton()->print("\n\nTest 19: Search & replace\n");
- String s="Happy Birthday, Anna!";
- OS::get_singleton()->print("\tString: %ls\n",s.c_str());
+ String s = "Happy Birthday, Anna!";
+ OS::get_singleton()->print("\tString: %ls\n", s.c_str());
- s=s.replace("Birthday","Halloween");
- OS::get_singleton()->print("\tReplaced Birthday/Halloween: %ls.\n",s.c_str());
-
- return (s=="Happy Halloween, Anna!");
+ s = s.replace("Birthday", "Halloween");
+ OS::get_singleton()->print("\tReplaced Birthday/Halloween: %ls.\n", s.c_str());
+ return (s == "Happy Halloween, Anna!");
}
bool test_20() {
OS::get_singleton()->print("\n\nTest 20: Insertion\n");
- String s="Who is Frederic?";
-
- OS::get_singleton()->print("\tString: %ls\n",s.c_str());
- s=s.insert( s.find("?")," Chopin" );
- OS::get_singleton()->print("\tInserted Chopin: %ls.\n",s.c_str());
+ String s = "Who is Frederic?";
- return (s=="Who is Frederic Chopin?");
+ OS::get_singleton()->print("\tString: %ls\n", s.c_str());
+ s = s.insert(s.find("?"), " Chopin");
+ OS::get_singleton()->print("\tInserted Chopin: %ls.\n", s.c_str());
+ return (s == "Who is Frederic Chopin?");
}
bool test_21() {
OS::get_singleton()->print("\n\nTest 21: Number -> String\n");
- OS::get_singleton()->print("\tPi is %f\n",33.141593);
- OS::get_singleton()->print("\tPi String is %ls\n",String::num(3.141593).c_str());
-
- return String::num(3.141593)=="3.141593";
+ OS::get_singleton()->print("\tPi is %f\n", 33.141593);
+ OS::get_singleton()->print("\tPi String is %ls\n", String::num(3.141593).c_str());
+ return String::num(3.141593) == "3.141593";
}
bool test_22() {
OS::get_singleton()->print("\n\nTest 22: String -> Int\n");
- static const char* nums[4]={ "1237461283", "- 22", "0", " - 1123412" };
- static const int num[4]={ 1237461283, -22, 0, -1123412 };
+ static const char *nums[4] = { "1237461283", "- 22", "0", " - 1123412" };
+ static const int num[4] = { 1237461283, -22, 0, -1123412 };
- for (int i=0;i<4;i++) {
- OS::get_singleton()->print("\tString: \"%s\" as Int is %i\n",nums[i],String(nums[i]).to_int());
+ for (int i = 0; i < 4; i++) {
+ OS::get_singleton()->print("\tString: \"%s\" as Int is %i\n", nums[i], String(nums[i]).to_int());
- if (String(nums[i]).to_int()!=num[i])
+ if (String(nums[i]).to_int() != num[i])
return false;
}
return true;
-
}
bool test_23() {
OS::get_singleton()->print("\n\nTest 23: String -> Float\n");
- static const char* nums[4]={ "-12348298412.2", "0.05", "2.0002", " -0.0001" };
- static const double num[4]={ -12348298412.2, 0.05, 2.0002, -0.0001 };
+ static const char *nums[4] = { "-12348298412.2", "0.05", "2.0002", " -0.0001" };
+ static const double num[4] = { -12348298412.2, 0.05, 2.0002, -0.0001 };
- for (int i=0;i<4;i++) {
- OS::get_singleton()->print("\tString: \"%s\" as Float is %f\n",nums[i],String(nums[i]).to_double());
+ for (int i = 0; i < 4; i++) {
+ OS::get_singleton()->print("\tString: \"%s\" as Float is %f\n", nums[i], String(nums[i]).to_double());
- if ( ABS(String(nums[i]).to_double()-num[i])>0.00001)
+ if (ABS(String(nums[i]).to_double() - num[i]) > 0.00001)
return false;
}
return true;
-
}
-
bool test_24() {
OS::get_singleton()->print("\n\nTest 24: Slicing\n");
- String s="Mars,Jupiter,Saturn,Uranus";
-
- const char*slices[4]={"Mars","Jupiter","Saturn","Uranus"};
+ String s = "Mars,Jupiter,Saturn,Uranus";
- OS::get_singleton()->print("\tSlicing \"%ls\" by \"%s\"..\n",s.c_str(),",");
+ const char *slices[4] = { "Mars", "Jupiter", "Saturn", "Uranus" };
- for (int i=0;i<s.get_slice_count(",");i++) {
+ OS::get_singleton()->print("\tSlicing \"%ls\" by \"%s\"..\n", s.c_str(), ",");
- OS::get_singleton()->print("\t\t%i- %ls\n",i+1,s.get_slice(",",i).c_str());
+ for (int i = 0; i < s.get_slice_count(","); i++) {
+ OS::get_singleton()->print("\t\t%i- %ls\n", i + 1, s.get_slice(",", i).c_str());
- if (s.get_slice(",",i)!=slices[i])
+ if (s.get_slice(",", i) != slices[i])
return false;
}
return true;
-
}
bool test_25() {
OS::get_singleton()->print("\n\nTest 25: Erasing\n");
- String s="Josephine is such a cute girl!";
+ String s = "Josephine is such a cute girl!";
- OS::get_singleton()->print("\tString: %ls\n",s.c_str());
+ OS::get_singleton()->print("\tString: %ls\n", s.c_str());
OS::get_singleton()->print("\tRemoving \"cute\"\n");
- s.erase(s.find("cute "),String("cute ").length());
- OS::get_singleton()->print("\tResult: %ls\n",s.c_str());
-
-
- return (s=="Josephine is such a girl!");
+ s.erase(s.find("cute "), String("cute ").length());
+ OS::get_singleton()->print("\tResult: %ls\n", s.c_str());
+ return (s == "Josephine is such a girl!");
}
bool test_26() {
@@ -466,19 +432,18 @@ bool test_26() {
RegEx regexp("(.*):(.*)");
int res = regexp.find("name:password");
- printf("\tmatch: %s\n", (res>=0)?"true":"false");
+ printf("\tmatch: %s\n", (res >= 0) ? "true" : "false");
printf("\t%i captures:\n", regexp.get_capture_count());
- for (int i = 0; i<regexp.get_capture_count(); i++)
- {
+ for (int i = 0; i < regexp.get_capture_count(); i++) {
printf("%ls\n", regexp.get_capture(i).c_str());
}
- return (res>=0);
+ return (res >= 0);
};
struct test_27_data {
- char const * data;
- char const * begin;
+ char const *data;
+ char const *begin;
bool expected;
};
@@ -486,13 +451,13 @@ bool test_27() {
OS::get_singleton()->print("\n\nTest 27: begins_with\n");
test_27_data tc[] = {
- {"res://foobar", "res://", true},
- {"res", "res://", false},
- {"abc", "abc", true}
+ { "res://foobar", "res://", true },
+ { "res", "res://", false },
+ { "abc", "abc", true }
};
size_t count = sizeof(tc) / sizeof(tc[0]);
bool state = true;
- for (size_t i = 0;state && i < count; ++i) {
+ for (size_t i = 0; state && i < count; ++i) {
String s = tc[i].data;
state = s.begins_with(tc[i].begin) == tc[i].expected;
if (state) {
@@ -507,7 +472,6 @@ bool test_27() {
return state;
};
-
bool test_28() {
OS::get_singleton()->print("\n\nTest 28: sprintf\n");
@@ -937,22 +901,22 @@ TestFunc test_funcs[] = {
};
-MainLoop* test() {
+MainLoop *test() {
/** A character length != wchar_t may be forced, so the tests wont work */
- ERR_FAIL_COND_V( sizeof(CharType) != sizeof(wchar_t), NULL );
+ ERR_FAIL_COND_V(sizeof(CharType) != sizeof(wchar_t), NULL);
- int count=0;
- int passed=0;
+ int count = 0;
+ int passed = 0;
- while(true) {
+ while (true) {
if (!test_funcs[count])
break;
- bool pass=test_funcs[count]();
+ bool pass = test_funcs[count]();
if (pass)
passed++;
- OS::get_singleton()->print("\t%s\n",pass?"PASS":"FAILED");
+ OS::get_singleton()->print("\t%s\n", pass ? "PASS" : "FAILED");
count++;
}
@@ -966,5 +930,4 @@ MainLoop* test() {
return NULL;
}
-
}
diff --git a/main/tests/test_string.h b/main/tests/test_string.h
index 7b3cd9a01..0c66c0f93 100644
--- a/main/tests/test_string.h
+++ b/main/tests/test_string.h
@@ -29,16 +29,12 @@
#ifndef TEST_STRING_H
#define TEST_STRING_H
-#include "ustring.h"
#include "os/main_loop.h"
+#include "ustring.h"
namespace TestString {
-MainLoop* test();
-
+MainLoop *test();
}
-
#endif
-
-