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


C++ Body::GetType方法代码示例

本文整理汇总了C++中Body::GetType方法的典型用法代码示例。如果您正苦于以下问题:C++ Body::GetType方法的具体用法?C++ Body::GetType怎么用?C++ Body::GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Body的用法示例。


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

示例1: CreateModel

void OnSolver::CreateModel(){
  // delete old model
  DeleteModel();

  // clear system body IDs (primer for traversal algorithm)
  system->ClearBodyIDs();
  

  // error check for inertial frame
  Body* sysbasebody = system->bodies.GetHeadElement()->value;
  if( sysbasebody->GetType() != INERTIALFRAME ){
    cerr << "ERROR: inertial frame not at head of bodies list" << endl;
    exit(1);
  }

  // setup the O(n) spanning tree
  numbodies = inertialframe.RecursiveSetup( (InertialFrame*) sysbasebody );
  if(!numbodies){
    cerr << "ERROR: unable to create O(n) model" << endl;
    exit(1);
  }
  
  
  
  bodyarray = new OnBody* [numbodies];
  
  CreateTopologyArray(0,&inertialframe);	  
  
  CreateStateMatrixMaps();  
}
开发者ID:BrianMoths,项目名称:lammps,代码行数:30,代码来源:onsolver.cpp

示例2: Update

bool Tweaker::Update()
{
	if(s_isInit && s_enabled) {
		if(s_monitorMode && Pi::player) {
			Body* nt = Pi::player->GetNavTarget();
			Body* ct = Pi::player->GetCombatTarget();
			//Body* target = nt != nullptr ? nt : ct; // Prioritize navtarget over combat target
			Body* target = ct != nullptr ? ct : nt; // Prioritize combattarget since we only care about ships now
			// Check if target changed
			if(target != s_monitorCurrentTarget) {
				// Target changed.
				// Remove active monitor if necessary
				if( s_activeMonitor && target && s_monitorCurrentTarget &&
				    target->GetType() == s_monitorCurrentTarget->GetType()) 
				{
					// Keep the same monitor
				} else {
					// Change monitor
					TwDeleteBar(s_activeMonitor);
					s_activeMonitor = nullptr;
					if(target) { // Only add new monitor if there is a valid target
						s_activeMonitor = CreateMonitor(target);
					}
				}
				s_monitorCurrentTarget = target;
			}
			// Updated monitors
			UpdateMonitor(target);
		}
		return true;
	} else {
		return false;
	}
}
开发者ID:MeteoricGames,项目名称:pioneer,代码行数:34,代码来源:Tweaker.cpp

示例3: InvalidGameStartLocation

Game::Game(const SystemPath &path, double time) :
	m_galaxy(GalaxyGenerator::Create()),
	m_time(time),
	m_state(STATE_NORMAL),
	m_wantHyperspace(false),
	m_timeAccel(TIMEACCEL_1X),
	m_requestedTimeAccel(TIMEACCEL_1X),
	m_forceTimeAccel(false)
{
	// Now that we have a Galaxy, check the starting location
	if (!path.IsBodyPath())
		throw InvalidGameStartLocation("SystemPath is not a body path");
	RefCountedPtr<const Sector> s = m_galaxy->GetSector(path);
	if (size_t(path.systemIndex) >= s->m_systems.size()) {
		char buf[128];
		std::sprintf(buf, "System %u in sector <%d,%d,%d> does not exist",
			unsigned(path.systemIndex), int(path.sectorX), int(path.sectorY), int(path.sectorZ));
		throw InvalidGameStartLocation(std::string(buf));
	}
	RefCountedPtr<StarSystem> sys = m_galaxy->GetStarSystem(path);
	if (path.bodyIndex >= sys->GetNumBodies()) {
		char buf[256];
		std::sprintf(buf, "Body %d in system <%d,%d,%d : %d ('%s')> does not exist", unsigned(path.bodyIndex),
			int(path.sectorX), int(path.sectorY), int(path.sectorZ), unsigned(path.systemIndex), sys->GetName().c_str());
		throw InvalidGameStartLocation(std::string(buf));
	}

	m_space.reset(new Space(this, m_galaxy, path));

	Body *b = m_space->FindBodyForPath(&path);
	assert(b);

	m_player.reset(new Player("kanara"));

	m_space->AddBody(m_player.get());

	m_player->SetFrame(b->GetFrame());

	if (b->GetType() == Object::SPACESTATION) {
		m_player->SetDockedWith(static_cast<SpaceStation*>(b), 0);
	} else {
		const SystemBody *sbody = b->GetSystemBody();
		m_player->SetPosition(vector3d(0, 1.5*sbody->GetRadius(), 0));
		m_player->SetVelocity(vector3d(0,0,0));
	}
	Polit::Init(m_galaxy);

	CreateViews();

	EmitPauseState(IsPaused());
}
开发者ID:ZeframCochrane,项目名称:pioneer,代码行数:51,代码来源:Game.cpp

示例4: l_body_is_hyperspace_cloud

static int l_body_is_hyperspace_cloud(lua_State *l)
{
	Body *body = LuaObject<Body>::CheckFromLua(1);
	LuaPush<bool>(l, body->GetType() == Object::Type::HYPERSPACECLOUD);
	return 1;
}
开发者ID:Zordey,项目名称:pioneer,代码行数:6,代码来源:LuaBody.cpp

示例5: l_body_is_ship

static int l_body_is_ship(lua_State *l)
{
	Body *body = LuaObject<Body>::CheckFromLua(1);
	LuaPush<bool>(l, body->GetType() == Object::Type::SHIP);
	return 1;
}
开发者ID:Zordey,项目名称:pioneer,代码行数:6,代码来源:LuaBody.cpp

示例6: l_body_is_cargo_container

static int l_body_is_cargo_container(lua_State *l)
{
	Body *body = LuaObject<Body>::CheckFromLua(1);
	LuaPush<bool>(l, body->GetType() == Object::Type::CARGOBODY);
	return 1;
}
开发者ID:Zordey,项目名称:pioneer,代码行数:6,代码来源:LuaBody.cpp

示例7: l_body_is_missile

static int l_body_is_missile(lua_State *l)
{
	Body *body = LuaObject<Body>::CheckFromLua(1);
	LuaPush<bool>(l, body->GetType() == Object::Type::MISSILE);
	return 1;
}
开发者ID:Zordey,项目名称:pioneer,代码行数:6,代码来源:LuaBody.cpp

示例8: Solve


//.........这里部分代码省略.........
		glm::vec2 translation = h * v;
		if (glm::dot(translation, translation) > maxTranslationSquared)
		{
			real32 ratio = maxTranslation / translation.length();
			v *= ratio;
		}

		real32 rotation = h * w;
		if (rotation * rotation > maxRotationSquared)
		{
			real32 ratio = maxRotation / glm::abs(rotation);
			w *= ratio;
		}

		// Integrate
		c += h * v;
		a += h * w;

		m_positions[i].c = c;
		m_positions[i].a = a;
		m_velocities[i].v = v;
		m_velocities[i].w = w;
	}

	// Solve position constraints
	captureTimer = Services::getPlatform()->getTime();
	bool positionSolved = false;
	for (s32 i = 0; i < step.positionIterations; ++i)
	{
		bool contactsOkay = contactSolver.SolvePositionConstraints();

		bool jointsOkay = true;
		for (s32 i = 0; i < m_jointCount; ++i)
		{
			bool jointOkay = m_joints[i]->SolvePositionConstraints(solverData);
			jointsOkay = jointsOkay && jointOkay;
		}

		if (contactsOkay && jointsOkay)
		{
			// Exit early if the position errors are small.
			positionSolved = true;
			break;
		}
	}

	// Copy state buffers back to the bodies
	for (s32 i = 0; i < m_bodyCount; ++i)
	{
		Body* body = m_bodies[i];
		body->m_sweep.c = m_positions[i].c;
		body->m_sweep.a = m_positions[i].a;
		body->m_linearVelocity = m_velocities[i].v;
		body->m_angularVelocity = m_velocities[i].w;
		body->SynchronizeTransform2D();
	}

	profile->solvePosition = Services::getPlatform()->getTime()-captureTimer;

	Report(contactSolver.m_velocityConstraints);

	if (allowSleep)
	{
		real32 minSleepTime = FLT_MAX;

		const real32 linTolSqr = linearSleepTolerance * linearSleepTolerance;
		const real32 angTolSqr = angularSleepTolerance * angularSleepTolerance;

		for (s32 i = 0; i < m_bodyCount; ++i)
		{
			Body* b = m_bodies[i];
			if (b->GetType() == staticBody)
			{
				continue;
			}

			if ((b->m_flags & Body::autoSleepFlag) == 0 ||
				b->m_angularVelocity * b->m_angularVelocity > angTolSqr ||
				glm::dot(b->m_linearVelocity, b->m_linearVelocity) > linTolSqr)
			{
				b->m_sleepTime = 0.0f;
				minSleepTime = 0.0f;
			}
			else
			{
				b->m_sleepTime += h;
				minSleepTime = glm::min(minSleepTime, b->m_sleepTime);
			}
		}

		if (minSleepTime >= timeToSleep && positionSolved)
		{
			for (s32 i = 0; i < m_bodyCount; ++i)
			{
				Body* b = m_bodies[i];
				b->SetAwake(false);
			}
		}
	}
}
开发者ID:BreakEngine,项目名称:Break-0.1,代码行数:101,代码来源:BodyIsland.cpp

示例9: l_body_is_more_important_than

static int l_body_is_more_important_than(lua_State *l)
{
	Body *body = LuaObject<Body>::CheckFromLua(1);
	Body *other = LuaObject<Body>::CheckFromLua(2);

	// compare body and other
	// push true if body is "more important" than other
	// the most important body is shown on the hud and
	// bodies are sorted by importance in menus

	if(body == other)
	{
		LuaPush<bool>(l, false);
		return 1;
	}

	Object::Type a = body->GetType();
	const SystemBody *sb_a = body->GetSystemBody();
	bool a_gas_giant = sb_a && sb_a->GetSuperType() == SystemBody::SUPERTYPE_GAS_GIANT;
	bool a_planet = sb_a && sb_a->IsPlanet();
	bool a_moon = sb_a && sb_a->IsMoon();

	Object::Type b = other->GetType();
	const SystemBody *sb_b = other->GetSystemBody();
	bool b_gas_giant = sb_b && sb_b->GetSuperType() == SystemBody::SUPERTYPE_GAS_GIANT;
	bool b_planet = sb_b && sb_b->IsPlanet();
	bool b_moon = sb_b && sb_b->IsMoon();

	bool result = false;

	// if type is the same, just sort alphabetically
	// planets are different, because moons are
	// less important (but don't have their own type)
	if(a == b && a != Object::Type::PLANET) result = body->GetLabel() < other->GetLabel();
	// a star is larger than any other object
	else if(a == Object::Type::STAR) result = true;
	// any (non-star) object is smaller than a star
	else if(b == Object::Type::STAR) result = false;
	// a gas giant is larger than anything but a star,
	// but remember to keep total order in mind: if both are
	// gas giants, order alphabetically
	else if(a_gas_giant) result = !b_gas_giant || body->GetLabel() < other->GetLabel();
	// any (non-star, non-gas giant) object is smaller than a gas giant
	else if(b_gas_giant) result = false;
	// between two planets or moons, alphabetic
	else if(a_planet && b_planet) result = body->GetLabel() < other->GetLabel();
	else if(a_moon && b_moon) result = body->GetLabel() < other->GetLabel();
	// a planet is larger than any non-planet
	else if(a_planet) result = true;
	// a non-planet is smaller than any planet
	else if(b_planet) result = false;
	// a moon is larger than any non-moon
	else if(a_moon) result = true;
	// a non-moon is smaller than any moon
	else if(b_moon) result = false;
	// spacestation > city > ship > hyperspace cloud > cargo body > missile > projectile
	else if(a == Object::Type::SPACESTATION) result = true;
	else if(b == Object::Type::SPACESTATION) result = false;
    else if(a == Object::Type::CITYONPLANET) result = true;
    else if(b == Object::Type::CITYONPLANET) result = false;
	else if(a == Object::Type::SHIP) result = true;
	else if(b == Object::Type::SHIP) result = false;
	else if(a == Object::Type::HYPERSPACECLOUD) result = true;
	else if(b == Object::Type::HYPERSPACECLOUD) result = false;
	else if(a == Object::Type::CARGOBODY) result = true;
	else if(b == Object::Type::CARGOBODY) result = false;
	else if(a == Object::Type::MISSILE) result = true;
	else if(b == Object::Type::MISSILE) result = false;
	else if(a == Object::Type::PROJECTILE) result = true;
	else if(b == Object::Type::PROJECTILE) result = false;
	else Error("don't know how to compare %i and %i\n", a, b);

	LuaPush<bool>(l, result);
	return 1;
}
开发者ID:irigi,项目名称:pioneer,代码行数:75,代码来源:LuaBody.cpp

示例10: SavedGameCorruptException


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

				Sint32 sectorY = strtol(pos, const_cast<char**>(&end), 0);
				if (pos == end) throw SavedGameCorruptException();
				pos = end+1; // skip newline

				Sint32 sectorZ = strtol(pos, const_cast<char**>(&end), 0);
				if (pos == end) throw SavedGameCorruptException();
				pos = end+1; // skip newline

				Uint32 systemNum = strtoul(pos, const_cast<char**>(&end), 0);
				if (pos == end) throw SavedGameCorruptException();
				pos = end+1; // skip newline

				Uint32 sbodyId = strtoul(pos, const_cast<char**>(&end), 0);
				if (pos == end) throw SavedGameCorruptException();
				pos = end+1; // skip newline

				SystemPath *sbp = new SystemPath(sectorX, sectorY, sectorZ, systemNum, sbodyId);
				LuaSystemPath::PushToLuaGC(sbp);

				break;
			}

			if (len == 4 && strncmp(pos, "Body", 4) == 0) {
				pos = end;

				Uint32 n = strtoul(pos, const_cast<char**>(&end), 0);
				if (pos == end) throw SavedGameCorruptException();
				pos = end+1; // skip newline

				Body *body = Pi::game->GetSpace()->GetBodyByIndex(n);
				if (pos == end) throw SavedGameCorruptException();

				switch (body->GetType()) {
					case Object::BODY:
						LuaBody::PushToLua(body);
						break;
					case Object::SHIP:
						LuaShip::PushToLua(dynamic_cast<Ship*>(body));
						break;
					case Object::SPACESTATION:
						LuaSpaceStation::PushToLua(dynamic_cast<SpaceStation*>(body));
						break;
					case Object::PLANET:
						LuaPlanet::PushToLua(dynamic_cast<Planet*>(body));
						break;
					case Object::STAR:
						LuaStar::PushToLua(dynamic_cast<Star*>(body));
						break;
					case Object::PLAYER:
						LuaPlayer::PushToLua(dynamic_cast<Player*>(body));
						break;
					default:
						throw SavedGameCorruptException();
				}

				break;
			}

			throw SavedGameCorruptException();
		}

		case 'o': {
			const char *end = strchr(pos, '\n');
			if (!end) throw SavedGameCorruptException();
			int len = end - pos;
开发者ID:Metamartian,项目名称:pioneer,代码行数:67,代码来源:LuaSerializer.cpp

示例11: SavedGameCorruptException

const char *LuaSerializer::unpickle(lua_State *l, const char *pos)
{
	LUA_DEBUG_START(l);

	char type = *pos++;

	switch (type) {

		case 'f': {
			char *end;
			double f = strtod(pos, &end);
			if (pos == end) throw SavedGameCorruptException();
			lua_pushnumber(l, f);
			pos = end+1; // skip newline
			break;
		}

		case 'b': {
			if (*pos != '0' && *pos != '1') throw SavedGameCorruptException();
			bool b = (*pos == '0') ? false : true;
			lua_pushboolean(l, b);
			pos++;
			break;
		}

		case 's': {
			char *end;
			int len = strtod(pos, &end);
			if (pos == end) throw SavedGameCorruptException();
			end++; // skip newline
			lua_pushlstring(l, end, len);
			pos = end + len;
			break;
		}
			
		case 't': {
			lua_newtable(l);
			while (*pos != 'n') {
				pos = unpickle(l, pos);
				pos = unpickle(l, pos);
				lua_rawset(l, -3);
			}
			pos++;
			break;
		}

		case 'u': {
			const char *end = strchr(pos, '\n');
			if (!end) throw SavedGameCorruptException();
			int len = end - pos;
			end++; // skip newline

			if (len == 10 && strncmp(pos, "SystemPath", 10) == 0) {
				pos = end;

				Sint32 sectorX = strtol(pos, const_cast<char**>(&end), 0);
				if (pos == end) throw SavedGameCorruptException();
				pos = end+1; // skip newline

				Sint32 sectorY = strtol(pos, const_cast<char**>(&end), 0);
				if (pos == end) throw SavedGameCorruptException();
				pos = end+1; // skip newline

				Sint32 sectorZ = strtol(pos, const_cast<char**>(&end), 0);
				if (pos == end) throw SavedGameCorruptException();
				pos = end+1; // skip newline

				Sint32 systemNum = strtol(pos, const_cast<char**>(&end), 0);
				if (pos == end) throw SavedGameCorruptException();
				pos = end+1; // skip newline

				Sint32 sbodyId = strtol(pos, const_cast<char**>(&end), 0);
				if (pos == end) throw SavedGameCorruptException();
				pos = end+1; // skip newline

				SystemPath *sbp = new SystemPath(sectorX, sectorY, sectorZ, systemNum, sbodyId);
				LuaSystemPath::PushToLuaGC(sbp);

				break;
			}

			if (len == 4 && strncmp(pos, "Body", 4) == 0) {
				pos = end;

				int n = strtol(pos, const_cast<char**>(&end), 0);
				if (pos == end) throw SavedGameCorruptException();
				pos = end+1; // skip newline

				Body *body = Serializer::LookupBody(n);
				if (pos == end) throw SavedGameCorruptException();

				switch (body->GetType()) {
					case Object::BODY:
						LuaBody::PushToLua(body);
						break;
					case Object::SHIP:
						LuaShip::PushToLua(dynamic_cast<Ship*>(body));
						break;
					case Object::SPACESTATION:
						LuaSpaceStation::PushToLua(dynamic_cast<SpaceStation*>(body));
//.........这里部分代码省略.........
开发者ID:GAlexx,项目名称:pioneer,代码行数:101,代码来源:LuaSerializer.cpp


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