当前位置: 首页>>代码示例>>C++>>正文


C++ ServerActiveObject类代码示例

本文整理汇总了C++中ServerActiveObject的典型用法代码示例。如果您正苦于以下问题:C++ ServerActiveObject类的具体用法?C++ ServerActiveObject怎么用?C++ ServerActiveObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ServerActiveObject类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: checkobject

// set_animation(self, frame_range, frame_speed, frame_blend)
int ObjectRef::l_set_animation(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *co = getobject(ref);
	if(co == NULL) return 0;
	// Do it
	v2f frames = v2f(1, 1);
	if(!lua_isnil(L, 2))
		frames = read_v2f(L, 2);
	float frame_speed = 15;
	if(!lua_isnil(L, 3))
		frame_speed = lua_tonumber(L, 3);
	float frame_blend = 0;
	if(!lua_isnil(L, 4))
		frame_blend = lua_tonumber(L, 4);
	co->setAnimation(frames, frame_speed, frame_blend);
	return 0;
}
开发者ID:Nate-Devv,项目名称:freeminer,代码行数:20,代码来源:l_object.cpp

示例2: checkobject

// set_bone_position(self, std::string bone, v3f position, v3f rotation)
int ObjectRef::l_set_bone_position(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *co = getobject(ref);
	if (co == NULL) return 0;
	// Do it
	std::string bone;
	if (!lua_isnil(L, 2))
		bone = readParam<std::string>(L, 2);
	v3f position = v3f(0, 0, 0);
	if (!lua_isnil(L, 3))
		position = check_v3f(L, 3);
	v3f rotation = v3f(0, 0, 0);
	if (!lua_isnil(L, 4))
		rotation = check_v3f(L, 4);
	co->setBonePosition(bone, position, rotation);
	return 0;
}
开发者ID:rubenwardy,项目名称:minetest,代码行数:20,代码来源:l_object.cpp

示例3: checkobject

// get_bone_position(self, bone)
int ObjectRef::l_get_bone_position(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *co = getobject(ref);
	if (co == NULL)
		return 0;
	// Do it
	std::string bone = "";
	if (!lua_isnil(L, 2))
		bone = lua_tostring(L, 2);

	v3f position = v3f(0, 0, 0);
	v3f rotation = v3f(0, 0, 0);
	co->getBonePosition(bone, &position, &rotation);

	push_v3f(L, position);
	push_v3f(L, rotation);
	return 2;
}
开发者ID:hondalyfe88,项目名称:MultiCraft,代码行数:21,代码来源:l_object.cpp

示例4: checkobject

// set_detach(self)
int ObjectRef::l_set_detach(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	GET_ENV_PTR;

	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *co = getobject(ref);
	if (co == NULL)
		return 0;

	int parent_id = 0;
	std::string bone = "";
	v3f position;
	v3f rotation;
	co->getAttachment(&parent_id, &bone, &position, &rotation);
	ServerActiveObject *parent = NULL;
	if (parent_id)
		parent = env->getActiveObject(parent_id);

	// Do it
	co->setAttachment(0, "", v3f(0,0,0), v3f(0,0,0));
	if (parent != NULL)
		parent->removeAttachmentChild(co->getId());
	return 0;
}
开发者ID:prodigeni,项目名称:freeminer,代码行数:26,代码来源:l_object.cpp

示例5: intToFloat

/*
	Finds out what objects have been removed from
	inside a radius around a position
*/
void ServerEnvironment::getRemovedActiveObjects(v3s16 pos, s16 radius,
		core::map<u16, bool> &current_objects,
		core::map<u16, bool> &removed_objects)
{
	v3f pos_f = intToFloat(pos, BS);
	f32 radius_f = radius * BS;
	/*
		Go through current_objects; object is removed if:
		- object is not found in m_active_objects (this is actually an
		  error condition; objects should be set m_removed=true and removed
		  only after all clients have been informed about removal), or
		- object has m_removed=true, or
		- object is too far away
	*/
	for(core::map<u16, bool>::Iterator
			i = current_objects.getIterator();
			i.atEnd()==false; i++)
	{
		u16 id = i.getNode()->getKey();
		ServerActiveObject *object = getActiveObject(id);
		if(object == NULL)
		{
			dstream<<"WARNING: ServerEnvironment::getRemovedActiveObjects():"
					<<" object in current_objects is NULL"<<std::endl;
		}
		else if(object->m_removed == false)
		{
			f32 distance_f = object->getBasePosition().getDistanceFrom(pos_f);
			/*dstream<<"removed == false"
					<<"distance_f = "<<distance_f
					<<", radius_f = "<<radius_f<<std::endl;*/
			if(distance_f < radius_f)
			{
				// Not removed
				continue;
			}
		}
		removed_objects.insert(id, false);
	}
}
开发者ID:MarkTraceur,项目名称:minetest-delta,代码行数:44,代码来源:environment.cpp

示例6: checkFloatPos

// get_objects_inside_radius(pos, radius)
int ModApiEnvMod::l_get_objects_inside_radius(lua_State *L)
{
	GET_ENV_PTR;

	// Do it
	v3f pos = checkFloatPos(L, 1);
	float radius = luaL_checknumber(L, 2) * BS;
	std::vector<u16> ids;
	env->getObjectsInsideRadius(ids, pos, radius);
	ScriptApiBase *script = getScriptApiBase(L);
	lua_createtable(L, ids.size(), 0);
	std::vector<u16>::const_iterator iter = ids.begin();
	for(u32 i = 0; iter != ids.end(); ++iter) {
		ServerActiveObject *obj = env->getActiveObject(*iter);
		if (!obj->isGone()) {
			// Insert object reference into table
			script->objectrefGetOrCreate(L, obj);
			lua_rawseti(L, -2, ++i);
		}
	}
	return 1;
}
开发者ID:EXio4,项目名称:minetest,代码行数:23,代码来源:l_env.cpp

示例7: checkobject

// remove(self)
int ObjectRef::l_remove(lua_State *L)
{
	GET_ENV_PTR;

	ObjectRef *ref = checkobject(L, 1);
	ServerActiveObject *co = getobject(ref);
	if (co == NULL)
		return 0;
	if (co->getType() == ACTIVEOBJECT_TYPE_PLAYER)
		return 0;

	const UNORDERED_SET<int> &child_ids = co->getAttachmentChildIds();
	UNORDERED_SET<int>::const_iterator it;
	for (it = child_ids.begin(); it != child_ids.end(); ++it) {
		// Child can be NULL if it was deleted earlier
		if (ServerActiveObject *child = env->getActiveObject(*it))
			child->setAttachment(0, "", v3f(0, 0, 0), v3f(0, 0, 0));
	}

	verbosestream<<"ObjectRef::l_remove(): id="<<co->getId()<<std::endl;
	co->m_removed = true;
	return 0;
}
开发者ID:theDrake,项目名称:minetest,代码行数:24,代码来源:l_object.cpp

示例8: checkobject

// set_attach(self, parent, bone, position, rotation)
int ObjectRef::l_set_attach(lua_State *L)
{
	GET_ENV_PTR;

	ObjectRef *ref = checkobject(L, 1);
	ObjectRef *parent_ref = checkobject(L, 2);
	ServerActiveObject *co = getobject(ref);
	ServerActiveObject *parent = getobject(parent_ref);
	if (co == NULL)
		return 0;
	if (parent == NULL)
		return 0;
	// Do it
	int parent_id = 0;
	std::string bone = "";
	v3f position = v3f(0, 0, 0);
	v3f rotation = v3f(0, 0, 0);
	co->getAttachment(&parent_id, &bone, &position, &rotation);
	if (parent_id) {
		ServerActiveObject *old_parent = env->getActiveObject(parent_id);
		if (old_parent)
		old_parent->removeAttachmentChild(co->getId());
	}

	bone = "";
	if (!lua_isnil(L, 3))
		bone = lua_tostring(L, 3);
	position = v3f(0, 0, 0);
	if (!lua_isnil(L, 4))
		position = read_v3f(L, 4);
	rotation = v3f(0, 0, 0);
	if (!lua_isnil(L, 5))
		rotation = read_v3f(L, 5);
	co->setAttachment(parent->getId(), bone, position, rotation);
	parent->addAttachmentChild(co->getId());
	return 0;
}
开发者ID:Mab879,项目名称:freeminer,代码行数:38,代码来源:l_object.cpp

示例9: DSTACK


//.........这里部分代码省略.........
					}
				}
				/*
					Convert grass into mud if under something else than air
				*/
				if(n.getContent() == CONTENT_GRASS)
				{
					//if(myrand()%20 == 0)
					{
						MapNode n_top = m_map->getNodeNoEx(p+v3s16(0,1,0));
						if(content_features(n_top).air_equivalent == false)
						{
							n.setContent(CONTENT_MUD);
							m_map->addNodeWithEvent(p, n);
						}
					}
				}
				/*
					Rats spawn around regular trees
				*/
				if(n.getContent() == CONTENT_TREE ||
						n.getContent() == CONTENT_JUNGLETREE)
				{
   					if(myrand()%200 == 0 && active_object_count_wider == 0)
					{
						v3s16 p1 = p + v3s16(myrand_range(-2, 2),
								0, myrand_range(-2, 2));
						MapNode n1 = m_map->getNodeNoEx(p1);
						MapNode n1b = m_map->getNodeNoEx(p1+v3s16(0,-1,0));
						if(n1b.getContent() == CONTENT_GRASS &&
								n1.getContent() == CONTENT_AIR)
						{
							v3f pos = intToFloat(p1, BS);
							ServerActiveObject *obj = new RatSAO(this, 0, pos);
							addActiveObject(obj);
						}
					}
			 }
			}
		}
	}
	
	/*
		Step active objects
	*/
	{
		//TimeTaker timer("Step active objects");
		
		// This helps the objects to send data at the same time
		bool send_recommended = false;
		m_send_recommended_timer += dtime;
		if(m_send_recommended_timer > 0.15)
		{
			m_send_recommended_timer = 0;
			send_recommended = true;
		}

		for(core::map<u16, ServerActiveObject*>::Iterator
				i = m_active_objects.getIterator();
				i.atEnd()==false; i++)
		{
			ServerActiveObject* obj = i.getNode()->getValue();
			// Don't step if is to be removed or stored statically
			if(obj->m_removed || obj->m_pending_deactivation)
				continue;
			// Step object
开发者ID:MarkTraceur,项目名称:minetest-delta,代码行数:67,代码来源:environment.cpp

示例10: deactivateFarObjects

/*
	Convert objects that are not in active blocks to static.

	If m_known_by_count != 0, active object is not deleted, but static
	data is still updated.

	If force_delete is set, active object is deleted nevertheless. It
	shall only be set so in the destructor of the environment.
*/
void ServerEnvironment::deactivateFarObjects(bool force_delete)
{
	core::list<u16> objects_to_remove;
	for(core::map<u16, ServerActiveObject*>::Iterator
			i = m_active_objects.getIterator();
			i.atEnd()==false; i++)
	{
		ServerActiveObject* obj = i.getNode()->getValue();
		u16 id = i.getNode()->getKey();
		v3f objectpos = obj->getBasePosition();

		// This shouldn't happen but check it
		if(obj == NULL)
		{
			dstream<<"WARNING: NULL object found in ServerEnvironment"
					<<std::endl;
			assert(0);
			continue;
		}

		// The block in which the object resides in
		v3s16 blockpos_o = getNodeBlockPos(floatToInt(objectpos, BS));
		
		// If block is active, don't remove
		if(m_active_blocks.contains(blockpos_o))
			continue;

		/*
			Update the static data
		*/

		// Delete old static object
		MapBlock *oldblock = NULL;
		if(obj->m_static_exists)
		{
			MapBlock *block = m_map->getBlockNoCreateNoEx
					(obj->m_static_block);
			if(block)
			{
				block->m_static_objects.remove(id);
				oldblock = block;
			}
		}
		// Create new static object
		std::string staticdata = obj->getStaticData();
		StaticObject s_obj(obj->getType(), objectpos, staticdata);
		// Add to the block where the object is located in
		v3s16 blockpos = getNodeBlockPos(floatToInt(objectpos, BS));
		// Get or generate the block
		MapBlock *block = m_map->emergeBlock(blockpos);

		/*MapBlock *block = m_map->getBlockNoCreateNoEx(blockpos);
		if(block == NULL)
		{
			// Block not found. Is the old block still ok?
			if(oldblock)
				block = oldblock;
			// Load from disk or generate
			else
				block = m_map->emergeBlock(blockpos);
		}*/

		if(block)
		{
			block->m_static_objects.insert(0, s_obj);
			block->setChangedFlag();
			obj->m_static_exists = true;
			obj->m_static_block = block->getPos();
		}
		else{
			dstream<<"WARNING: ServerEnv: Could not find or generate "
					<<"a block for storing static object"<<std::endl;
			obj->m_static_exists = false;
			continue;
		}

		/*
			Delete active object if not known by some client,
			else set pending deactivation
		*/

		// If known by some client, don't delete.
		if(obj->m_known_by_count > 0 && force_delete == false)
		{
			obj->m_pending_deactivation = true;
			continue;
		}
		
		/*dstream<<"INFO: Server: Stored static data. Deleting object."
				<<std::endl;*/
		// Delete active object
//.........这里部分代码省略.........
开发者ID:MarkTraceur,项目名称:minetest-delta,代码行数:101,代码来源:environment.cpp

示例11: add_random_objects

/*
	Adds random objects to block, depending on the content of the block
*/
void add_random_objects(MapBlock *block)
{
#if 0
	for(s16 z0=0; z0<MAP_BLOCKSIZE; z0++)
	for(s16 x0=0; x0<MAP_BLOCKSIZE; x0++)
	{
		bool last_node_walkable = false;
		for(s16 y0=0; y0<MAP_BLOCKSIZE; y0++)
		{
			v3s16 p(x0,y0,z0);
			MapNode n = block->getNodeNoEx(p);
			if(n.getContent() == CONTENT_IGNORE)
				continue;
			if(content_features(n).liquid_type != LIQUID_NONE)
				continue;
			if(content_features(n).walkable)
			{
				last_node_walkable = true;
				continue;
			}
			if(last_node_walkable)
			{
				// If block contains light information
				if(content_features(n).param_type == CPT_LIGHT)
				{
					if(n.getLight(LIGHTBANK_DAY) <= 3)
					{
						if(myrand() % 300 == 0)
						{
							v3f pos_f = intToFloat(p+block->getPosRelative(), BS);
							pos_f.Y -= BS*0.4;
							ServerActiveObject *obj = new RatSAO(NULL, 0, pos_f);
							std::string data = obj->getStaticData();
							StaticObject s_obj(obj->getType(),
									obj->getBasePosition(), data);
							// Add some
							block->m_static_objects.insert(0, s_obj);
							block->m_static_objects.insert(0, s_obj);
							block->m_static_objects.insert(0, s_obj);
							block->m_static_objects.insert(0, s_obj);
							block->m_static_objects.insert(0, s_obj);
							block->m_static_objects.insert(0, s_obj);
							delete obj;
						}
						if(myrand() % 1000 == 0)
						{
							v3f pos_f = intToFloat(p+block->getPosRelative(), BS);
							pos_f.Y -= BS*0.4;
							ServerActiveObject *obj = new Oerkki1SAO(NULL,0,pos_f);
							std::string data = obj->getStaticData();
							StaticObject s_obj(obj->getType(),
									obj->getBasePosition(), data);
							// Add one
							block->m_static_objects.insert(0, s_obj);
							delete obj;
						}
					}
				}
			}
			last_node_walkable = false;
		}
	}
	block->setChangedFlag();
#endif
}
开发者ID:WantedGames,项目名称:freeminer,代码行数:68,代码来源:mapgen_v5.cpp

示例12: collisionMoveSimple


//.........这里部分代码省略.........

		/* add object boxes to cinfo */

		std::vector<ActiveObject*> objects;
#ifndef SERVER
		ClientEnvironment *c_env = dynamic_cast<ClientEnvironment*>(env);
		if (c_env != 0) {
			// Calculate distance by speed, add own extent and 1.5m of tolerance
			f32 distance = speed_f->getLength() * dtime +
				box_0.getExtent().getLength() + 1.5f * BS;
			std::vector<DistanceSortedActiveObject> clientobjects;
			c_env->getActiveObjects(*pos_f, distance, clientobjects);

			for (auto &clientobject : clientobjects) {
				// Do collide with everything but itself and the parent CAO
				if (!self || (self != clientobject.obj &&
						self != clientobject.obj->getParent())) {
					objects.push_back((ActiveObject*) clientobject.obj);
				}
			}
		}
		else
#endif
		{
			ServerEnvironment *s_env = dynamic_cast<ServerEnvironment*>(env);
			if (s_env != NULL) {
				// Calculate distance by speed, add own extent and 1.5m of tolerance
				f32 distance = speed_f->getLength() * dtime +
					box_0.getExtent().getLength() + 1.5f * BS;
				std::vector<u16> s_objects;
				s_env->getObjectsInsideRadius(s_objects, *pos_f, distance);

				for (u16 obj_id : s_objects) {
					ServerActiveObject *current = s_env->getActiveObject(obj_id);

					if (!self || (self != current &&
							self != current->getParent())) {
						objects.push_back((ActiveObject*)current);
					}
				}
			}
		}

		for (std::vector<ActiveObject*>::const_iterator iter = objects.begin();
				iter != objects.end(); ++iter) {
			ActiveObject *object = *iter;

			if (object) {
				aabb3f object_collisionbox;
				if (object->getCollisionBox(&object_collisionbox) &&
						object->collideWithObjects()) {
					cinfo.emplace_back(false, true, 0, v3s16(), object_collisionbox);
				}
			}
		}
	} //tt3

	/*
		Collision detection
	*/

	/*
		Collision uncertainty radius
		Make it a bit larger than the maximum distance of movement
	*/
	f32 d = pos_max_d * 1.1f;
开发者ID:Caellian,项目名称:minetest,代码行数:67,代码来源:collision.cpp


注:本文中的ServerActiveObject类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。