示例#1
0
void ViewSelectSpawn::updateSpawnList()
{
	GameDocument * pDoc = (GameDocument *)document();
	ASSERT( pDoc );
	UniverseContext * pContext = pDoc->context();
	ASSERT( pContext );

	int myFaction = pDoc->factionId();
	int highlighted = m_pListSpawn->highlighted();
	int selected = m_pListSpawn->selected();

	// reset the update time
	m_UpdateSpawnList = 1.0f;
	// remove all items from the list
	m_pListSpawn->removeAllItems();
	// release our spawn list
	m_Spawn.release();

	// make a list of all spawn positions in alpha order
	for(int i=0;i<pContext->zoneCount();i++)
	{
		NodeZone * pZone = pContext->zone( i );
		for(int j=0;j<pZone->childCount();j++)
		{
			Noun * pSpawn = NULL;

			BaseNode * pChild = pZone->child(j);
			if ( dynamic_cast<NounPlanet *>( pChild ) )
			{
				NounPlanet * pPlanet = (NounPlanet *)pChild;
				if ( pPlanet->factionId() == myFaction && (pPlanet->flags() & NounPlanet::FLAG_HAS_SHIPYARD) != 0 )
					pSpawn = pPlanet;
			}
			else if ( dynamic_cast<NounJumpGate *>( pChild ) )
			{
				NounJumpGate * pGate = (NounJumpGate *)pChild;
				if ( pGate->factionId() == myFaction )
					pSpawn = pGate;
			}

			if ( pSpawn != NULL )
			{
				// add item to list
				m_pListSpawn->addItem( pSpawn->name() );
				// add to internal list
				m_Spawn.push( pSpawn );
			}
		}
	}

	// restore the currently highlighted item
	m_pListSpawn->setHighlighted( highlighted );
	m_pListSpawn->setSelected( selected );
}
示例#2
0
	bool deserialize(UniverseContext& ctx, InputBlob& serializer) override
	{
		SerializedEngineHeader header;
		serializer.read(header);
		if (header.m_magic != SERIALIZED_ENGINE_MAGIC)
		{
			g_log_error.log("engine") << "Wrong or corrupted file";
			return false;
		}
		if (header.m_version > SerializedEngineVersion::LATEST)
		{
			g_log_error.log("engine") << "Unsupported version";
			return false;
		}
		if (!hasSerializedPlugins(serializer))
		{
			return false;
		}
		if (header.m_version > SerializedEngineVersion::SCENE_VERSION_CHECK &&
			!hasSupportedSceneVersions(serializer, ctx))
		{
			return false;
		}

		m_path_manager.deserialize(serializer);
		ctx.m_universe->deserialize(serializer);

		if (header.m_version <= SerializedEngineVersion::HIERARCHY_COMPONENT)
		{
			ctx.getScene(HIERARCHY_HASH)->deserialize(serializer, 0);
		}

		m_plugin_manager->deserialize(serializer);
		int32 scene_count;
		serializer.read(scene_count);
		for (int i = 0; i < scene_count; ++i)
		{
			char tmp[32];
			serializer.readString(tmp, sizeof(tmp));
			IScene* scene = ctx.getScene(crc32(tmp));
			int scene_version = -1;
			if (header.m_version > SerializedEngineVersion::SCENE_VERSION)
			{
				serializer.read(scene_version);
			}
			scene->deserialize(serializer, scene_version);
		}
		m_path_manager.clear();
		return true;
	}
示例#3
0
	virtual bool deserialize(UniverseContext& ctx,
							 InputBlob& serializer) override
	{
		SerializedEngineHeader header;
		serializer.read(header);
		if (header.m_magic != SERIALIZED_ENGINE_MAGIC)
		{
			g_log_error.log("engine") << "Wrong or corrupted file";
			return false;
		}
		if (header.m_version > SerializedEngineVersion::LATEST)
		{
			g_log_error.log("engine") << "Unsupported version";
			return false;
		}
		if (!hasSerializedPlugins(serializer))
		{
			return false;
		}
		g_path_manager.deserialize(serializer);
		ctx.m_universe->deserialize(serializer);
		ctx.m_hierarchy->deserialize(serializer);
		m_plugin_manager->deserialize(serializer);
		int32_t scene_count;
		serializer.read(scene_count);
		for (int i = 0; i < scene_count; ++i)
		{
			char tmp[32];
			serializer.readString(tmp, sizeof(tmp));
			IScene* scene = ctx.getScene(crc32(tmp));
			scene->deserialize(serializer);
		}
		g_path_manager.clear();
		return true;
	}
示例#4
0
	bool hasSupportedSceneVersions(InputBlob& serializer, UniverseContext& ctx)
	{
		int32 count;
		serializer.read(count);
		for (int i = 0; i < count; ++i)
		{
			uint32 hash;
			serializer.read(hash);
			auto* scene = ctx.getScene(hash);
			int version;
			serializer.read(version);
			if (version > scene->getVersion())
			{
				g_log_error.log("engine") << "Plugin " << scene->getPlugin().getName() << " is too old";
				return false;
			}
		}
		return true;
	}
示例#5
0
void ViewEngineering::onRender( RenderContext & context, const RectInt & window )
{
	GameDocument * pDoc = (GameDocument *)document();
	if ( pDoc == NULL )
		return;

	UniverseContext * pContext = pDoc->context();
	ASSERT( pContext );
	NounShip * pShip = pDoc->ship();
	ASSERT( pShip );

	// get the time elapsed
	float t = context.elapsed();
	// calculate the distance from the ship based upon it's radius
	float cameraDistance = pShip->radius() * 2.5f;
	// calculate the camera frame and position
	Matrix33 cameraFrame( pShip->frame() );
	cameraFrame.rotate( PI / 4, ViewGame::s_CameraTime * (PI / 4), 0 );
	Vector3	cameraPosition( pShip->worldPosition() - (cameraFrame.k * cameraDistance) );

	if ( ViewGame::s_CameraTime < CAMERA_SNAP_TIME )
	{
		// if ship is moving, keep it from jumping around while the camera is animating
		if ( m_Adjust )
		{
			Vector3 position( pShip->worldPosition() );
			Vector3 adjust( position - m_AdjustPosition );
			m_AdjustPosition = position;

			ViewGame::s_CameraPosition += adjust;
		}
		else
		{
			m_AdjustPosition = pShip->worldPosition();
			m_Adjust = true;
		}

		float d = ViewGame::s_CameraTime / CAMERA_SNAP_TIME;
		// move the camera
		Vector3 deltaPosition( cameraPosition - ViewGame::s_CameraPosition );
		ViewGame::s_CameraPosition += deltaPosition * d;

		// update the camera frame
		ViewGame::s_CameraFrame.i += (cameraFrame.i - ViewGame::s_CameraFrame.i) * d;
		ViewGame::s_CameraFrame.j += (cameraFrame.j - ViewGame::s_CameraFrame.j) * d;
		ViewGame::s_CameraFrame.k += (cameraFrame.k - ViewGame::s_CameraFrame.k) * d;
		ViewGame::s_CameraFrame.orthoNormalizeXY();
	}
	else
	{
		// animation is over, snap directly to the desired frame/position
		ViewGame::s_CameraFrame = cameraFrame;
		ViewGame::s_CameraPosition = cameraPosition;
		m_Adjust = false;
	}

	m_UpdateStatus += t;
	if ( m_UpdateStatus > 1.0f )
	{
		m_UpdateStatus = 0.0f;

		// update the ship status
		String shipStatus;
		shipStatus += String().format("Hull:<X;75;Color;ff00ffff>%d%%</Color>\n", int(pShip->damageRatioInv() * 100) );
		shipStatus += String().format("Energy:<X;75;Color;ff00ffff>%d / %d</Color>\n", pShip->energy(), pShip->maxEnergy() );
		shipStatus += String().format("Velocity:<X;75;Color;ff00ffff>%.1f / %.1f</Color>\n", pShip->velocity(), pShip->maxVelocity() );
		shipStatus += String().format("Signature:<X;75;Color;ff00ffff>%.1f</Color>\n", pShip->signature() );

		shipStatus += "\nSYSTEMS:\n";

		// display armor status
		for(int i=0;i<pShip->childCount();i++)
			if ( WidgetCast<GadgetArmor>( pShip->child(i) ) )
			{
				GadgetArmor * pArmor = (GadgetArmor *)pShip->child(i);
				shipStatus += String().format("%s<X;100>%d%%\n", 
					pArmor->nounContext()->name(), 
					(pArmor->armor() * 100 ) / pArmor->strength() );
			}
		// display shield status
		for(i=0;i<pShip->childCount();i++)
			if ( WidgetCast<GadgetShield>( pShip->child(i) ) )
			{
				GadgetShield * pShield = (GadgetShield *)pShip->child(i);
				shipStatus += String().format("%s<X;100>%d%%\n", 
					pShield->nounContext()->name(), 
					(pShield->charge() * 100 ) / pShield->maxCharge() );
			}

		for(i=0;i<pShip->childCount();i++)
			if ( WidgetCast<NounGadget>( pShip->child(i) ) )
			{
				NounGadget * pGadget = (NounGadget *)pShip->child(i);
				if ( WidgetCast<GadgetArmor>( pGadget ) )
					continue;
				if ( WidgetCast<GadgetShield>( pGadget ) )
					continue;
				
				shipStatus += String().format("%s<X;100>%d%%\n", 
					pGadget->nounContext()->name(), 
					int( pGadget->damageRatioInv() * 100 ) );
			}

		m_pShipStatus->setText( shipStatus );
	}
	
	if ( m_pLayoutRepair->visible() )
	{
		for(int i=0;i<pShip->repairCount();i++)
			GetButton<ButtonGadget>( m_pRepairQueue, i )->setGadget( pShip->repair( i ) );

		// remove excess buttons
		m_pRepairQueue->cullChildren( pShip->repairCount() );
	}

	//----------------------------------------------------------------------------

	// update the active zone
	pContext->setActiveZone( ViewGame::s_CameraPosition );

	// create our render context
	RenderContext engineeringContext( context );
	engineeringContext.setPosition( ViewGame::s_CameraPosition );
	engineeringContext.setFrame(  ViewGame::s_CameraFrame );
	engineeringContext.setTime( pContext->tick() * TICK_DURATION_S );

	//----------------------------------------------------------------------------

	// render the universe
	pContext->render( engineeringContext, 
		~ViewGame::s_CameraFrame, ViewGame::s_CameraFrame * (-ViewGame::s_CameraPosition) );
}