Example #1
0
void Body2DSW::call_queries() {


	if (fi_callback) {

		Physics2DDirectBodyStateSW *dbs = Physics2DDirectBodyStateSW::singleton;
		dbs->body=this;

		Variant v=dbs;
		const Variant *vp[2]={&v,&fi_callback->callback_udata};


		Object *obj = ObjectDB::get_instance(fi_callback->id);
		if (!obj) {

			set_force_integration_callback(0,StringName());
		} else {
			Variant::CallError ce;			
			if (fi_callback->callback_udata.get_type()) {

				obj->call(fi_callback->method,vp,2,ce);

			} else {
				obj->call(fi_callback->method,vp,1,ce);
			}
		}


	}

}
void TestSwigModule::testBuild()
{
    i->reset();

    ts::A *a = new ts::A();
    Object pa = build<ts::A *>(a, true);
    CPPUNIT_ASSERT_EQUAL(7, extract<int>(pa.call("getValue")));

    i->getNamespace()["a"] = pa;
    i->runString("a.setValue(84)\n");

    CPPUNIT_ASSERT_EQUAL(true, extract<bool>(i->evaluate("a.this.own()")));
    CPPUNIT_ASSERT_EQUAL(84, extract<int>(pa.call("getValue")));
    CPPUNIT_ASSERT_EQUAL(84, extract<int>(i->evaluate("a.getValue()")));
}
Example #3
0
Variant& Tween::_get_initial_val(InterpolateData& p_data) {

	switch(p_data.type) {
		case INTER_PROPERTY:
		case INTER_METHOD:
		case FOLLOW_PROPERTY:
		case FOLLOW_METHOD:
			return p_data.initial_val;

		case TARGETING_PROPERTY:
		case TARGETING_METHOD: {

				Object *object = ObjectDB::get_instance(p_data.target_id);
				ERR_FAIL_COND_V(object == NULL,p_data.initial_val);

				static Variant initial_val;
				if(p_data.type == TARGETING_PROPERTY) {

					bool valid = false;
					initial_val = object->get(p_data.target_key, &valid);
					ERR_FAIL_COND_V(!valid,p_data.initial_val);
				} else {

					Variant::CallError error;
					initial_val = object->call(p_data.target_key, NULL, 0, error);
					ERR_FAIL_COND_V(error.error != Variant::CallError::CALL_OK,p_data.initial_val);
				}
				return initial_val;
			}
			break;
	}
	return p_data.delta_val;
}
Example #4
0
void VisualServerRaster::draw(bool p_swap_buffers) {

	changes = 0;

	VSG::rasterizer->begin_frame();

	VSG::scene->update_dirty_instances(); //update scene stuff

	VSG::viewport->draw_viewports();
	VSG::scene->render_probes();
	_draw_margins();
	VSG::rasterizer->end_frame(p_swap_buffers);

	while (frame_drawn_callbacks.front()) {

		Object *obj = ObjectDB::get_instance(frame_drawn_callbacks.front()->get().object);
		if (obj) {
			Variant::CallError ce;
			const Variant *v = &frame_drawn_callbacks.front()->get().param;
			obj->call(frame_drawn_callbacks.front()->get().method, &v, 1, ce);
			if (ce.error != Variant::CallError::CALL_OK) {
				String err = Variant::get_call_error_text(obj, frame_drawn_callbacks.front()->get().method, &v, 1, ce);
				ERR_PRINTS("Error calling frame drawn function: " + err);
			}
		}

		frame_drawn_callbacks.pop_front();
	}

	emit_signal("frame_drawn_in_thread");
}
Example #5
0
void VisualServerRaster::draw(bool p_swap_buffers, double frame_step) {

	//needs to be done before changes is reset to 0, to not force the editor to redraw
	VS::get_singleton()->emit_signal("frame_pre_draw");

	changes = 0;

	VSG::rasterizer->begin_frame(frame_step);

	VSG::scene->update_dirty_instances(); //update scene stuff

	VSG::viewport->draw_viewports();
	VSG::scene->render_probes();
	_draw_margins();
	VSG::rasterizer->end_frame(p_swap_buffers);

	while (frame_drawn_callbacks.front()) {

		Object *obj = ObjectDB::get_instance(frame_drawn_callbacks.front()->get().object);
		if (obj) {
			Variant::CallError ce;
			const Variant *v = &frame_drawn_callbacks.front()->get().param;
			obj->call(frame_drawn_callbacks.front()->get().method, &v, 1, ce);
			if (ce.error != Variant::CallError::CALL_OK) {
				String err = Variant::get_call_error_text(obj, frame_drawn_callbacks.front()->get().method, &v, 1, ce);
				ERR_PRINTS("Error calling frame drawn function: " + err);
			}
		}

		frame_drawn_callbacks.pop_front();
	}
	VS::get_singleton()->emit_signal("frame_post_draw");
}
Example #6
0
void EventQueue::flush_events() {

	uint32_t read_pos = 0;

	while (read_pos < buffer_end) {

		Event *event = (Event *)&event_buffer[read_pos];
		Variant *args = (Variant *)(event + 1);
		Object *obj = ObjectDB::get_instance(event->instance_ID);

		if (obj) {
			// events don't expect a return value
			obj->call(event->method,
					(event->args >= 1) ? args[0] : Variant(),
					(event->args >= 2) ? args[1] : Variant(),
					(event->args >= 3) ? args[2] : Variant(),
					(event->args >= 4) ? args[3] : Variant(),
					(event->args >= 5) ? args[4] : Variant());
		}

		if (event->args >= 1) args[0].~Variant();
		if (event->args >= 2) args[1].~Variant();
		if (event->args >= 3) args[2].~Variant();
		if (event->args >= 4) args[3].~Variant();
		if (event->args >= 5) args[4].~Variant();
		event->~Event();

		read_pos += sizeof(Event) + sizeof(Variant) * event->args;
	}

	buffer_end = 0; // reset buffer
}
     void TestCommand::callOnRecursiveStructure()
     {
       InternalMessage(
         "Kernel",
         "Kernel::Test::TestCommand::callOnRecursiveStructure entering") ;
       {
         // create a model
         std::auto_ptr<Model> model(new Model()) ;
 
         // fill the model
         Object* object = model->createObject() ;
         Trait1* trait1 = new Trait1() ;
         object->addTrait(trait1) ;
 
         Object* object2 = object->createObject() ;
         object2->addTrait(new CommandDelegator()) ;
         object2->addTrait(new Trait3()) ;
         object2->getTrait<CommandDelegator>()->addDelegate(object) ;
         
         CPPUNIT_ASSERT(! object->call("unexisting function")) ;
       }
       
       InternalMessage(
         "Kernel",
         "Kernel::Test::TestCommand::callOnRecursiveStructure leaving") ;
     }
Example #8
0
void UndoRedo::_process_operation_list(List<Operation>::Element *E) {

	for (;E;E=E->next()) {

		Operation &op=E->get();

		Object *obj = ObjectDB::get_instance(op.object);
		if (!obj) {
			//corruption
			clear_history();
			ERR_FAIL_COND(!obj);

		}
		switch(op.type) {

			case Operation::TYPE_METHOD: {

				obj->call(op.name,VARIANT_ARGS_FROM_ARRAY(op.args));
			} break;
			case Operation::TYPE_PROPERTY: {

				obj->set(op.name,op.args[0]);
			} break;
			case Operation::TYPE_REFERENCE: {
				//do nothing
			} break;

		}
	}
}
Example #9
0
void EditorAddonLibrary::_image_request_completed(int p_status, int p_code, const StringArray& headers, const ByteArray& p_data,int p_queue_id) {

	ERR_FAIL_COND( !image_queue.has(p_queue_id) );

	if (p_status==HTTPRequest::RESULT_SUCCESS) {


		print_line("GOT IMAGE YAY!");
		Object *obj = ObjectDB::get_instance(image_queue[p_queue_id].target);

		if (obj) {
			int len=p_data.size();
			ByteArray::Read r=p_data.read();

			Image image(r.ptr(),len);
			if (!image.empty()) {
				Ref<ImageTexture> tex;
				tex.instance();
				tex->create_from_image(image);

				obj->call("set_image",image_queue[p_queue_id].image_type,image_queue[p_queue_id].image_index,tex);
			}
		}
	} else {
		WARN_PRINTS("Error getting PNG file for asset id "+itos(image_queue[p_queue_id].asset_id));
	}

	image_queue[p_queue_id].request->queue_delete();;
	image_queue.erase(p_queue_id);

	_update_image_queue();

}
Example #10
0
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_callobject(JNIEnv * env, jobject p_obj, jint ID, jstring method, jobjectArray params) {

	Object* obj = ObjectDB::get_instance(ID);
	ERR_FAIL_COND(!obj);

	int res = env->PushLocalFrame(16);
	ERR_FAIL_COND(res!=0);

	String str_method = env->GetStringUTFChars( method, NULL );


	int count = env->GetArrayLength(params);
	Variant* vlist = (Variant*)alloca(sizeof(Variant) * count);
	Variant** vptr = (Variant**)alloca(sizeof(Variant*) * count);
	for (int i=0; i<count; i++) {

		jobject obj = env->GetObjectArrayElement(params, i);
		Variant v;
		if (obj)
			v=_jobject_to_variant(env, obj);
		memnew_placement(&vlist[i], Variant);
		vlist[i] = v;
		vptr[i] = &vlist[i];
		env->DeleteLocalRef(obj);

	};

	Variant::CallError err;
	obj->call(str_method, (const Variant**)vptr, count, err);
	// something

	env->PopLocalFrame(NULL);

};
Example #11
0
void RigidBodyBullet::dispatch_callbacks() {
	/// The check isTransformChanged is necessary in order to call integrated forces only when the first transform is sent
	if ((btBody->isActive() || previousActiveState != btBody->isActive()) && force_integration_callback && isTransformChanged) {

		if (omit_forces_integration)
			btBody->clearForces();

		BulletPhysicsDirectBodyState *bodyDirect = BulletPhysicsDirectBodyState::get_singleton(this);

		Variant variantBodyDirect = bodyDirect;

		Object *obj = ObjectDB::get_instance(force_integration_callback->id);
		if (!obj) {
			// Remove integration callback
			set_force_integration_callback(0, StringName());
		} else {
			const Variant *vp[2] = { &variantBodyDirect, &force_integration_callback->udata };

			Variant::CallError responseCallError;
			int argc = (force_integration_callback->udata.get_type() == Variant::NIL) ? 1 : 2;
			obj->call(force_integration_callback->method, vp, argc, responseCallError);
		}
	}

	if (isScratchedSpaceOverrideModificator || 0 < countGravityPointSpaces) {
		isScratchedSpaceOverrideModificator = false;
		reload_space_override_modificator();
	}

	/// Lock axis
	btBody->setLinearVelocity(btBody->getLinearVelocity() * btBody->getLinearFactor());
	btBody->setAngularVelocity(btBody->getAngularVelocity() * btBody->getAngularFactor());

	previousActiveState = btBody->isActive();
}
Example #12
0
Object *CreateDialog::instance_selected() {

	TreeItem *selected = search_options->get_selected();
	if (selected) {

		String custom = selected->get_metadata(0);
		if (custom != String()) {
			if (EditorNode::get_editor_data().get_custom_types().has(custom)) {

				for (int i = 0; i < EditorNode::get_editor_data().get_custom_types()[custom].size(); i++) {
					if (EditorNode::get_editor_data().get_custom_types()[custom][i].name == selected->get_text(0)) {
						Ref<Texture> icon = EditorNode::get_editor_data().get_custom_types()[custom][i].icon;
						Ref<Script> script = EditorNode::get_editor_data().get_custom_types()[custom][i].script;
						String name = selected->get_text(0);

						Object *ob = ObjectTypeDB::instance(custom);
						ERR_FAIL_COND_V(!ob, NULL);
						if (ob->is_type("Node")) {
							ob->call("set_name", name);
						}
						ob->set_script(script.get_ref_ptr());
						if (icon.is_valid())
							ob->set_meta("_editor_icon", icon);
						return ob;
					}
				}
			}
		} else {
			return ObjectTypeDB::instance(selected->get_text(0));
		}
	}

	return NULL;
}
Example #13
0
	_FORCE_INLINE_ bool operator()(const Variant &p_l, const Variant &p_r) const {

		const Variant *args[2] = { &p_l, &p_r };
		Variant::CallError err;
		bool res = obj->call(func, args, 2, err);
		if (err.error != Variant::CallError::CALL_OK)
			res = false;
		return res;
	}
Example #14
0
void ScriptDebuggerRemote::_send_object_id(ObjectID p_id) {

	Object *obj = ObjectDB::get_instance(p_id);
	if (!obj)
		return;

	List<PropertyInfo> pinfo;
	obj->get_property_list(&pinfo, true);

	int props_to_send = 0;
	for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {

		if (E->get().usage & (PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CATEGORY)) {
			props_to_send++;
		}
	}

	packet_peer_stream->put_var("message:inspect_object");
	packet_peer_stream->put_var(props_to_send * 5 + 4);
	packet_peer_stream->put_var(p_id);
	packet_peer_stream->put_var(obj->get_class());
	if (obj->is_class("Resource") || obj->is_class("Node"))
		packet_peer_stream->put_var(obj->call("get_path"));
	else
		packet_peer_stream->put_var("");

	packet_peer_stream->put_var(props_to_send);

	for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {

		if (E->get().usage & (PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CATEGORY)) {

			if (E->get().usage & PROPERTY_USAGE_CATEGORY) {
				packet_peer_stream->put_var("*" + E->get().name);
			} else {
				packet_peer_stream->put_var(E->get().name);
			}

			Variant var = obj->get(E->get().name);
			packet_peer_stream->put_var(E->get().type);
			//only send information that can be sent..

			int len = 0; //test how big is this to encode
			encode_variant(var, NULL, len);

			if (len > packet_peer_stream->get_output_buffer_max_size()) { //limit to max size
				packet_peer_stream->put_var(PROPERTY_HINT_OBJECT_TOO_BIG);
				packet_peer_stream->put_var("");
				packet_peer_stream->put_var(Variant());
			} else {
				packet_peer_stream->put_var(E->get().hint);
				packet_peer_stream->put_var(E->get().hint_string);
				packet_peer_stream->put_var(var);
			}
		}
	}
}
Example #15
0
void KJSDebugWin::slotEval()
{
    // Work out which execution state to use. If we're currently in a debugging session,
    // use the current context - otherwise, use the global execution state from the interpreter
    // corresponding to the currently displayed source file.
    ExecState *exec;
    Object thisobj;
    if(m_execStates.isEmpty())
    {
        if(m_sourceSel->currentItem() < 0)
            return;
        SourceFile *sourceFile = m_sourceSelFiles.at(m_sourceSel->currentItem());
        if(!sourceFile->interpreter)
            return;
        exec = sourceFile->interpreter->globalExec();
        thisobj = exec->interpreter()->globalObject();
    }
    else
    {
        exec = m_execStates.top();
        thisobj = exec->context().thisValue();
    }

    // Evaluate the js code from m_evalEdit
    UString code(m_evalEdit->code());
    QString msg;

    KJSCPUGuard guard;
    guard.start();

    Interpreter *interp = exec->interpreter();

    Object obj = Object::dynamicCast(interp->globalObject().get(exec, "eval"));
    List args;
    args.append(String(code));

    m_evalDepth++;
    Value retval = obj.call(exec, thisobj, args);
    m_evalDepth--;
    guard.stop();

    // Print the return value or exception message to the console
    if(exec->hadException())
    {
        Value exc = exec->exception();
        exec->clearException();
        msg = "Exception: " + exc.toString(interp->globalExec()).qstring();
    }
    else
    {
        msg = retval.toString(interp->globalExec()).qstring();
    }

    m_evalEdit->insert(msg + "\n");
    updateContextList();
}
Example #16
0
void Resource::notify_change_to_owners() {

	for (Set<ObjectID>::Element *E = owners.front(); E; E = E->next()) {

		Object *obj = ObjectDB::get_instance(E->get());
		ERR_EXPLAIN("Object was deleted, while still owning a resource");
		ERR_CONTINUE(!obj); //wtf
		//TODO store string
		obj->call("resource_changed", RES(this));
	}
}
Example #17
0
void InspectorDock::_prepare_history() {
	EditorHistory *editor_history = EditorNode::get_singleton()->get_editor_history();

	int history_to = MAX(0, editor_history->get_history_len() - 25);

	history_menu->get_popup()->clear();

	Ref<Texture> base_icon = get_icon("Object", "EditorIcons");
	Set<ObjectID> already;
	for (int i = editor_history->get_history_len() - 1; i >= history_to; i--) {

		ObjectID id = editor_history->get_history_obj(i);
		Object *obj = ObjectDB::get_instance(id);
		if (!obj || already.has(id)) {
			if (history_to > 0) {
				history_to--;
			}
			continue;
		}

		already.insert(id);

		Ref<Texture> icon = get_icon("Object", "EditorIcons");
		if (has_icon(obj->get_class(), "EditorIcons"))
			icon = get_icon(obj->get_class(), "EditorIcons");
		else
			icon = base_icon;

		String text;
		if (Object::cast_to<Resource>(obj)) {
			Resource *r = Object::cast_to<Resource>(obj);
			if (r->get_path().is_resource_file())
				text = r->get_path().get_file();
			else if (r->get_name() != String()) {
				text = r->get_name();
			} else {
				text = r->get_class();
			}
		} else if (Object::cast_to<Node>(obj)) {
			text = Object::cast_to<Node>(obj)->get_name();
		} else if (obj->is_class("ScriptEditorDebuggerInspectedObject")) {
			text = obj->call("get_title");
		} else {
			text = obj->get_class();
		}

		if (i == editor_history->get_history_pos()) {
			text = "[" + text + "]";
		}
		history_menu->get_popup()->add_icon_item(icon, text, i);
	}
}
Example #18
0
bool Tween::_apply_tween_value(InterpolateData& p_data, Variant& value) {

	Object *object = ObjectDB::get_instance(p_data.id);
	ERR_FAIL_COND_V(object == NULL, false);

	switch(p_data.type) {

		case INTER_PROPERTY:
		case FOLLOW_PROPERTY:
		case TARGETING_PROPERTY:
			{
				bool valid = false;
				object->set(p_data.key,value, &valid);
				return valid;
			}

		case INTER_METHOD:
		case FOLLOW_METHOD:
		case TARGETING_METHOD:
			{
				Variant::CallError error;
				if (value.get_type() != Variant::NIL) {
					Variant *arg[1] = { &value };
					object->call(p_data.key, (const Variant **) arg, 1, error);
				} else {
					object->call(p_data.key, NULL, 0, error);
				}

				if(error.error == Variant::CallError::CALL_OK)
					return true;
				return false;
			}

		case INTER_CALLBACK:
			break;
	};
	return true;
}
 void TestCommand::basicTest()
 {
   InternalMessage("Kernel","Kernel::Test::TestCommand::basicTest entering") ;
   /// create a model
   std::auto_ptr<Model> model(new Model()) ;
                               
   //// fill the model
   Object* object = model->createObject() ;
   
   {
     Trait1* trait = new Trait1() ;
     object->addTrait(trait) ;
     
     CPPUNIT_ASSERT(object->call("axis1",10)) ;
     CPPUNIT_ASSERT(trait->getValue()==10) ;
     
     std::set<std::string> commands(object->getCommands()) ;
     
     CPPUNIT_ASSERT(commands.size() == 1) ;
   }        
   
   {
     Trait2* trait = new Trait2() ;
     object->addTrait(trait) ;
     
     CPPUNIT_ASSERT(! trait->isPushed()) ;
     CPPUNIT_ASSERT(object->call("push")) ;
     CPPUNIT_ASSERT(trait->isPushed()) ;
     
     std::set<std::string> commands(object->getCommands()) ;
     CPPUNIT_ASSERT(commands.size() == 3) ;
     
   
   }        
   
   InternalMessage("Kernel","Kernel::Test::TestCommand::basicTest leaving") ;
 }
 void TestCommand::testCommandDelegatorWithTwoDelegates()
 {
   InternalMessage(
     "Kernel",
     "Kernel::Test::TestCommand::testCommandDelegatorWithTwoDelegates entering") ;
   /// create a model
   std::auto_ptr<Model> model(new Model()) ;
                               
   //// fill the model
   Object* object1 = model->createObject() ;
   Trait1* trait1 = new Trait1() ;
   object1->addTrait(trait1) ;
   
   Object* object3 = model->createObject() ;
   Trait2* trait2 = new Trait2() ;
   object3->addTrait(trait2) ;
   
   Object* object = model->createObject() ;
   CommandDelegator* delegator = new CommandDelegator() ;
   object->addTrait(delegator) ;
   
   delegator->addDelegate(object1) ;
   delegator->addDelegate(object3) ;
   
   CPPUNIT_ASSERT(trait1->getValue()==0) ;
   CPPUNIT_ASSERT(object->call("axis1",10)) ;
   CPPUNIT_ASSERT(trait1->getValue()==10) ;
     
   CPPUNIT_ASSERT(! trait2->isPushed()) ;
   CPPUNIT_ASSERT(object->call("push")) ;
   CPPUNIT_ASSERT(trait2->isPushed()) ;
     
   std::set<std::string> commands(object->getCommands()) ;
   CPPUNIT_ASSERT(commands.size() == 3) ;
   
   InternalMessage("Kernel","Kernel::Test::TestCommand::testCommandDelegatorWithTwoDelegates leaving") ;
 }
Example #21
0
Variant& Tween::_get_delta_val(InterpolateData& p_data) {

	switch(p_data.type) {
		case INTER_PROPERTY:
		case INTER_METHOD:
			return p_data.delta_val;

		case FOLLOW_PROPERTY:
		case FOLLOW_METHOD: {

				Object *target = ObjectDB::get_instance(p_data.target_id);
				ERR_FAIL_COND_V(target == NULL,p_data.initial_val);

				Variant final_val;

				if(p_data.type == FOLLOW_PROPERTY) {

					bool valid = false;
					final_val = target->get(p_data.target_key, &valid);
					ERR_FAIL_COND_V(!valid,p_data.initial_val);
				} else {

					Variant::CallError error;
					final_val = target->call(p_data.target_key, NULL, 0, error);
					ERR_FAIL_COND_V(error.error != Variant::CallError::CALL_OK,p_data.initial_val);
				}

				// convert INT to REAL is better for interpolaters
				if(final_val.get_type() == Variant::INT) final_val = final_val.operator real_t();
				_calc_delta_val(p_data.initial_val, final_val, p_data.delta_val);
				return p_data.delta_val;
			}
			break;

		case TARGETING_PROPERTY:
		case TARGETING_METHOD: {

				Variant initial_val = _get_initial_val(p_data);
				// convert INT to REAL is better for interpolaters
				if(initial_val.get_type() == Variant::INT) initial_val = initial_val.operator real_t();

				//_calc_delta_val(p_data.initial_val, p_data.final_val, p_data.delta_val);
				_calc_delta_val(initial_val, p_data.final_val, p_data.delta_val);
				return p_data.delta_val;
			}
			break;
	}
	return p_data.initial_val;
}
Example #22
0
void UndoRedo::_process_operation_list(List<Operation>::Element *E) {

	for (;E;E=E->next()) {

		Operation &op=E->get();

		Object *obj = ObjectDB::get_instance(op.object);
		if (!obj) {
			//corruption
			clear_history();
			ERR_FAIL_COND(!obj);

		}

		switch(op.type) {

			case Operation::TYPE_METHOD: {

				obj->call(op.name,VARIANT_ARGS_FROM_ARRAY(op.args));				
#ifdef TOOLS_ENABLED
				Resource* res = obj->cast_to<Resource>();
				if (res)
					res->set_edited(true);

#endif

				if (method_callback) {
					method_callback(method_callbck_ud,obj,op.name,VARIANT_ARGS_FROM_ARRAY(op.args));
				}
			} break;
			case Operation::TYPE_PROPERTY: {

				obj->set(op.name,op.args[0]);
#ifdef TOOLS_ENABLED
				Resource* res = obj->cast_to<Resource>();
				if (res)
					res->set_edited(true);
#endif
				if (property_callback) {
					property_callback(prop_callback_ud,obj,op.name,op.args[0]);
				}
			} break;
			case Operation::TYPE_REFERENCE: {
				//do nothing
			} break;

		}
	}
}
Example #23
0
Variant FuncRef::call_func(const Variant **p_args, int p_argcount, Variant::CallError &r_error) {

	if (id == 0) {
		r_error.error = Variant::CallError::CALL_ERROR_INSTANCE_IS_NULL;
		return Variant();
	}
	Object *obj = ObjectDB::get_instance(id);

	if (!obj) {
		r_error.error = Variant::CallError::CALL_ERROR_INSTANCE_IS_NULL;
		return Variant();
	}

	return obj->call(function, p_args, p_argcount, r_error);
}
Example #24
0
void AreaBullet::call_event(CollisionObjectBullet *p_otherObject, PhysicsServer::AreaBodyStatus p_status) {

	InOutEventCallback &event = eventsCallbacks[static_cast<int>(p_otherObject->getType())];
	Object *areaGodoObject = ObjectDB::get_instance(event.event_callback_id);

	if (!areaGodoObject) {
		event.event_callback_id = 0;
		return;
	}

	call_event_res[0] = p_status;
	call_event_res[1] = p_otherObject->get_self(); // Other body
	call_event_res[2] = p_otherObject->get_instance_id(); // instance ID
	call_event_res[3] = 0; // other_body_shape ID
	call_event_res[4] = 0; // self_shape ID

	Variant::CallError outResp;
	areaGodoObject->call(event.event_callback_method, (const Variant **)call_event_res_ptr, 5, outResp);
}
Example #25
0
	// evaluate()
	//
	Object *CallExpression::evaluate_( Interpreter *interpreter, Scope *scope )
	{

		// evaluate the expression to be called
		Object *baseValue = base_->evaluate( interpreter, scope ); // new reference
		if ( !baseValue )
			return 0; // error already set

        // evaluate parameters
		List *parameters = new List; // new reference
		ExpressionList::iterator i, iEnd = parameters_->end();
		for ( i = parameters_->begin(); i != iEnd; ++i )
		{

			Object *parameterValue = ( *i )->evaluate( interpreter, scope ); // new reference
			if ( !parameterValue )
			{

                // clean up
				baseValue->decRef();
				parameters->decRef();

				return 0; // error already set
			}

			parameters->append( parameterValue ); // takes reference
			parameterValue->decRef();
		}

        // function calls happen in their own scope
        Scope functionScope( interpreter->getGlobalScope() );

		// make the call - if an error occurs, result will be 0
		Object *result = baseValue->call( interpreter, &functionScope, parameters, "" ); // new reference

		// clean up
		baseValue->decRef();
		parameters->decRef();

		return result;
	}
      void TestCommand::callUnexistingCommand()
      {
        InternalMessage(
          "Kernel",
          "Kernel::Test::TestCommand::callUnexistingCommand entering") ;
        // create a model
        std::auto_ptr<Model> model(new Model()) ;

        // fill the model
        Object* object = model->createObject() ;
        Trait1* trait1 = new Trait1() ;
        object->addTrait(trait1) ;

        Object* object2 = object->createObject() ;
        object2->addTrait(new Trait2()) ;
        object2->addTrait(new Trait3()) ;
        
        CPPUNIT_ASSERT(! object->call("unexisting function")) ;
        InternalMessage(
          "Kernel",
          "Kernel::Test::TestCommand::callUnexistingCommand leaving") ;
      }
Example #27
0
void AreaSW::call_queries() {

	if (monitor_callback_id && !monitored_bodies.empty()) {

		Variant res[5];
		Variant *resptr[5];
		for(int i=0;i<5;i++)
			resptr[i]=&res[i];

		Object *obj = ObjectDB::get_instance(monitor_callback_id);
		if (!obj) {
			monitored_bodies.clear();
			monitor_callback_id=0;
			return;
		}



		for (Map<BodyKey,BodyState>::Element *E=monitored_bodies.front();E;E=E->next()) {

			if (E->get().state==0)
				continue; //nothing happened

			res[0]=E->get().state>0 ? PhysicsServer::AREA_BODY_ADDED : PhysicsServer::AREA_BODY_REMOVED;
			res[1]=E->key().rid;
			res[2]=E->key().instance_id;
			res[3]=E->key().body_shape;
			res[4]=E->key().area_shape;

			Variant::CallError ce;
			obj->call(monitor_callback_method,(const Variant**)resptr,5,ce);
		}
	}

	monitored_bodies.clear();

	//get_space()->area_remove_from_monitor_query_list(&monitor_query_list);

}
Example #28
0
Object *EditorData::instance_custom_type(const String &p_type, const String &p_inherits) {

	if (get_custom_types().has(p_inherits)) {

		for (int i = 0; i < get_custom_types()[p_inherits].size(); i++) {
			if (get_custom_types()[p_inherits][i].name == p_type) {
				Ref<Texture> icon = get_custom_types()[p_inherits][i].icon;
				Ref<Script> script = get_custom_types()[p_inherits][i].script;

				Object *ob = ClassDB::instance(p_inherits);
				ERR_FAIL_COND_V(!ob, NULL);
				if (ob->is_class("Node")) {
					ob->call("set_name", p_type);
				}
				ob->set_script(script.get_ref_ptr());
				if (icon.is_valid())
					ob->set_meta("_editor_icon", icon);
				return ob;
			}
		}
	}

	return NULL;
}
Example #29
0
void UndoRedo::_process_operation_list(List<Operation>::Element *E) {

	for (; E; E = E->next()) {

		Operation &op = E->get();

		Object *obj = ObjectDB::get_instance(op.object);
		if (!obj) {
			//corruption
			clear_history();
			ERR_FAIL_COND(!obj);
		}

		switch (op.type) {

			case Operation::TYPE_METHOD: {

				Vector<const Variant *> argptrs;
				argptrs.resize(VARIANT_ARG_MAX);
				int argc = 0;

				for (int i = 0; i < VARIANT_ARG_MAX; i++) {
					if (op.args[i].get_type() == Variant::NIL) {
						break;
					}
					argptrs.write[i] = &op.args[i];
					argc++;
				}
				argptrs.resize(argc);

				Variant::CallError ce;
				obj->call(op.name, (const Variant **)argptrs.ptr(), argc, ce);
				if (ce.error != Variant::CallError::CALL_OK) {
					ERR_PRINTS("Error calling method from signal '" + String(op.name) + "': " + Variant::get_call_error_text(obj, op.name, (const Variant **)argptrs.ptr(), argc, ce));
				}
#ifdef TOOLS_ENABLED
				Resource *res = Object::cast_to<Resource>(obj);
				if (res)
					res->set_edited(true);

#endif

				if (method_callback) {
					method_callback(method_callbck_ud, obj, op.name, VARIANT_ARGS_FROM_ARRAY(op.args));
				}
			} break;
			case Operation::TYPE_PROPERTY: {

				obj->set(op.name, op.args[0]);
#ifdef TOOLS_ENABLED
				Resource *res = Object::cast_to<Resource>(obj);
				if (res)
					res->set_edited(true);
#endif
				if (property_callback) {
					property_callback(prop_callback_ud, obj, op.name, op.args[0]);
				}
			} break;
			case Operation::TYPE_REFERENCE: {
				//do nothing
			} break;
		}
	}
}
Example #30
0
void Tween::_tween_process(float p_delta) {

	_process_pending_commands();

	if (speed_scale == 0)
		return;
	p_delta *= speed_scale;

	pending_update ++;
	// if repeat and all interpolates was finished then reset all interpolates
	if(repeat) {
		bool all_finished = true;

		for(List<InterpolateData>::Element *E=interpolates.front();E;E=E->next()) {

			InterpolateData& data = E->get();

			if(!data.finish) {
				all_finished = false;
				break;
			}
		}

		if(all_finished)
			reset_all();
	}

	for(List<InterpolateData>::Element *E=interpolates.front();E;E=E->next()) {

		InterpolateData& data = E->get();
		if(!data.active || data.finish)
			continue;

		Object *object = ObjectDB::get_instance(data.id);
		if(object == NULL)
			continue;

		bool prev_delaying = data.elapsed <= data.delay;
		data.elapsed += p_delta;
		if(data.elapsed < data.delay)
			continue;
		else if(prev_delaying) {

			emit_signal("tween_start",object,data.key);
			_apply_tween_value(data, data.initial_val);
		}

		if(data.elapsed > (data.delay + data.times_in_sec)) {

			data.elapsed = data.delay + data.times_in_sec;
			data.finish = true;
		}

		switch(data.type)
		{
		case INTER_PROPERTY:
		case INTER_METHOD:
			break;
		case INTER_CALLBACK:
			if(data.finish) {

				Variant::CallError error;
				if (data.call_deferred) {

					switch (data.args) {
					case 0:
						object->call_deferred(data.key); break;
					case 1:
						object->call_deferred(data.key, data.arg[0]); break;
					case 2:
						object->call_deferred(data.key, data.arg[0], data.arg[1]); break;
					case 3:
						object->call_deferred(data.key, data.arg[0], data.arg[1], data.arg[2]); break;
					case 4:
						object->call_deferred(data.key, data.arg[0], data.arg[1], data.arg[2], data.arg[3]); break;
					case 5:
						object->call_deferred(data.key, data.arg[0], data.arg[1], data.arg[2], data.arg[3], data.arg[4]); break;
					}

				}
				else {
					Variant *arg[5] = {
						&data.arg[0],
						&data.arg[1],
						&data.arg[2],
						&data.arg[3],
						&data.arg[4],
					};
					object->call(data.key, (const Variant **) arg, data.args, error);
				}
			}
			continue;
		}

		Variant result = _run_equation(data);
		emit_signal("tween_step",object,data.key,data.elapsed,result);

		_apply_tween_value(data, result);

		if (data.finish) {
			emit_signal("tween_complete",object,data.key);
			// not repeat mode, remove completed action
			if (!repeat)
				call_deferred("remove", object, data.key);
		}
	}
	pending_update --;
}