void initOgreForMeshLoading()
{
	Path p;
	const std::string meshPath = p.Get(ID::P_GRAPHICS_MESHES);

	Ogre::Root* root = new Ogre::Root("", "", p.Get(ID::P_LOGS) + "OgreMeshLoad.log");
	new Ogre::DefaultHardwareBufferManager();
	Ogre::ResourceGroupManager::getSingleton().addResourceLocation(meshPath, "FileSystem");
	Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();	
}
MainState::MainState(GameHandle handle, Event::Lane& lane) :
State(lane),
mPlayer(NULL_HANDLE),
mEnvironment(new Environment),
mLane(lane)
{
	Path p;

	std::string level = p.Get(ID::P_SCRIPTS_LEVELS) + "spaceinvaders/";
	std::string def = p.Get(ID::P_SCRIPTS_LEVELS) + "default/";

	LevelConfig lc;

	lc.mModules.push_back(def + "Object.xml");
	lc.mAdapters.push_back(def + "Adapter.xml");
	lc.mConcepts.push_back(def + "Concept.xml");
	lc.mProperties.push_back(def + "Value.xml");

	lc.mModules.push_back(level + "Object.xml");
	lc.mAdapters.push_back(level + "Adapter.xml");
	lc.mConcepts.push_back(level + "Concept.xml");
	lc.mProperties.push_back(level + "Value.xml");

	using BFG::Property::ValueId;

	PluginId spId = ValueId::ENGINE_PLUGIN_ID;
	PluginId sipId = BFG::Property::generatePluginId<PluginId>();

	boost::shared_ptr<BFG::SpacePlugin> sp(new BFG::SpacePlugin(spId));
	boost::shared_ptr<SiPlugin> sip(new SiPlugin(sipId));

	mPluginMap.insert(sp);
	mPluginMap.insert(sip);

	boost::shared_ptr<GameObjectFactory> gof;
	gof.reset(new GameObjectFactory(mLane, lc, mPluginMap, mEnvironment, handle));

	mSector.reset(new Sector(mLane, 1, "SpaceInvaderSector", gof));

	// Init Controller

	BFG::Controller_::ActionMapT actions;
	actions[A_SHIP_AXIS_Y] = "A_SHIP_AXIS_Y";
	actions[A_SHIP_FIRE]   = "A_SHIP_FIRE";
	actions[A_QUIT]        = "A_QUIT";
	actions[A_FPS]         = "A_FPS";
	BFG::Controller_::sendActionsToController(mLane, actions);

	const std::string config_path = p.Expand("SpaceInvaders.xml");
	const std::string state_name = "SpaceInvaders";

	BFG::View::WindowAttributes wa;
	BFG::View::queryWindowAttributes(wa);

	//! \todo Verify usage of generateHandle() here.
	Controller_::StateInsertion si(config_path, state_name, generateHandle(), true, wa);

	mLane.emit(ID::CE_LOAD_STATE, si);

	// ---

	View::SkyCreation sc("sky02");
	mLane.emit(ID::VE_SET_SKY, sc, handle);

	ObjectParameter op;
	mPlayer = generateHandle();
	op.mHandle = mPlayer;
	op.mName = "The Hero's Mighty Ship";
	op.mType = "Ship";
	op.mLocation = v3(0.0f, -NEGATIVE_SHIP_Y_POSITION, OBJECT_Z_POSITION); // - 5.0f); // + SPECIAL_PACKER_MESH_OFFSET);
	fromAngleAxis(op.mLocation.orientation, -90.0f * (float) DEG2RAD, v3::UNIT_X);
	
	boost::shared_ptr<GameObject> player = gof->createGameObject(op);
	mSector->addObject(player);

	mInvaderGeneral.reset(new InvaderGeneral(lane.createSubLane(), mEnvironment));
	mHumanGeneral.reset(new HumanGeneral(lane.createSubLane(), mEnvironment));

	mLane.connect(A_SHIP_AXIS_Y, this, &MainState::onAxisY);
	mLane.connect(A_FPS, this, &MainState::onFps);
	mLane.connectV(A_SHIP_FIRE, this, &MainState::onShipFire);
	mLane.connect(A_QUIT, this, &MainState::onQuit);
}
int main( int argc, const char* argv[] ) try
{
	bool server = false;
	if  (argc == 2)
		server = true;
	else if (argc == 3)
		server = false;
	else
	{
		std::cerr << "For Server use: bfgNetworkTest <Port>\nFor Client use: bfgNetworkTest <IP> <Port>\n";
		BFG::Base::pause();
		return 0;
	}

	Event::Synchronizer synchronizer;
	Event::Lane lane(synchronizer, 100);

	if (server)
	{
		u16 port = 0;

		if (!from_string(port, argv[1], std::dec))
		{
			std::cerr << "Port not a number: " << argv[1] << std::endl;
			BFG::Base::pause();
			return 0;
		}

		Path p;
		Base::Logger::Init(Base::Logger::SL_DEBUG, p.Get(ID::P_LOGS) + "/NetworkServerTest.log");

		dbglog << "Starting as Server";


		int mode(BFG_SERVER); // casting problem
		lane.addEntry<Network::Main>(mode);

		synchronizer.start();
		
		boost::this_thread::sleep(boost::posix_time::milliseconds(500));

		lane.emit(ID::NE_LISTEN, port);

		Base::pause();
		dbglog << "Good bye";
	}
	else
	{
		std::string ip(argv[1]);
		std::string port(argv[2]);

		Path p;
		Base::Logger::Init(Base::Logger::SL_DEBUG, p.Get(ID::P_LOGS) + "/NetworkClientTest.log");

		dbglog << "Starting as Client";

		int mode(BFG_CLIENT);
		lane.addEntry<Network::Main>(mode);
		synchronizer.start();

		boost::this_thread::sleep(boost::posix_time::milliseconds(500));

		Network::EndpointT payload = make_tuple(stringToArray<128>(ip), stringToArray<128>(port));

		lane.emit(ID::NE_CONNECT, payload);
		networkEventTest(lane);

		Base::pause();
		dbglog << "Good bye";
	}
		
	// Give EventSystem some time to stop all loops
	boost::this_thread::sleep(boost::posix_time::milliseconds(500));
	synchronizer.finish();

}
catch (std::exception& ex)
{
	showException(ex.what());
}
catch (...)
{
	showException("Unknown exception");
}
Exemple #4
0
LevelMine::LevelMine(unique_ptr<Game> & game, const unique_ptr<PlayerTransfer> & playerTransfer) : Level(game, playerTransfer) {
	mName = LevelName::Mine;

	LoadLocalization("mine.loc");

	mPlayer->mYaw.SetTarget(180.0f);

	LoadSceneFromFile("data/maps/mine.scene");

	mPlayer->SetPosition(GetUniqueObject("PlayerPosition")->GetPosition());

	Vector3 placePos = GetUniqueObject("PlayerPosition")->GetPosition();
	Vector3 playerPos = mPlayer->GetCurrentPosition();

	mPlayer->GetHUD()->SetObjective(mLocalization.GetString("objective1"));

	AddInteractiveObject("Note", make_shared<InteractiveObject>(GetUniqueObject("Note1")), [this] { mPlayer->GetInventory()->AddReadedNote(mLocalization.GetString("note1Desc"), mLocalization.GetString("note1")); });
	AddInteractiveObject("Note", make_shared<InteractiveObject>(GetUniqueObject("Note2")), [this] { mPlayer->GetInventory()->AddReadedNote(mLocalization.GetString("note2Desc"), mLocalization.GetString("note2")); });
	AddInteractiveObject("Note", make_shared<InteractiveObject>(GetUniqueObject("Note3")), [this] { mPlayer->GetInventory()->AddReadedNote(mLocalization.GetString("note3Desc"), mLocalization.GetString("note3")); });
	AddInteractiveObject("Note", make_shared<InteractiveObject>(GetUniqueObject("Note4")), [this] { mPlayer->GetInventory()->AddReadedNote(mLocalization.GetString("note4Desc"), mLocalization.GetString("note4")); });
	AddInteractiveObject("Note", make_shared<InteractiveObject>(GetUniqueObject("Note5")), [this] { mPlayer->GetInventory()->AddReadedNote(mLocalization.GetString("note5Desc"), mLocalization.GetString("note5")); });
	AddInteractiveObject("Note", make_shared<InteractiveObject>(GetUniqueObject("Note6")), [this] { mPlayer->GetInventory()->AddReadedNote(mLocalization.GetString("note6Desc"), mLocalization.GetString("note6")); });
	AddInteractiveObject("Note", make_shared<InteractiveObject>(GetUniqueObject("Note7")), [this] { mPlayer->GetInventory()->AddReadedNote(mLocalization.GetString("note7Desc"), mLocalization.GetString("note7")); });
	AddInteractiveObject("Note", make_shared<InteractiveObject>(GetUniqueObject("Note8")), [this] { mPlayer->GetInventory()->AddReadedNote(mLocalization.GetString("note8Desc"), mLocalization.GetString("note8")); });

	mStoneFallZone = GetUniqueObject("StoneFallZone");

	mNewLevelZone = GetUniqueObject("NewLevel");

	auto soundSystem = mGame->GetEngine()->GetSoundSystem();

	soundSystem->SetReverbPreset(ReverbPreset::Cave);

	AddSound(mMusic = soundSystem->LoadMusic("data/music/chapter2.ogg"));

	mConcreteWall = GetUniqueObject("ConcreteWall");
	mDeathZone = GetUniqueObject("DeadZone");
	mDetonator = GetUniqueObject("Detonator");

	AddSound(mAlertSound = soundSystem->LoadSound3D("data/sounds/alert.ogg"));
	mAlertSound->Attach(mDetonator);

	AddSound(mExplosionSound = soundSystem->LoadSound3D("data/sounds/blast.ogg"));
	mExplosionSound->SetReferenceDistance(10);

	mDetonatorActivated = 0;

	mExplosionFlashAnimator = 0;

	// Create detonator places
	AddItemPlace(mDetonatorPlace[0] = make_shared<ItemPlace>(GetUniqueObject("DetonatorPlace1"), Item::Type::Explosives));
	AddItemPlace(mDetonatorPlace[1] = make_shared<ItemPlace>(GetUniqueObject("DetonatorPlace2"), Item::Type::Explosives));
	AddItemPlace(mDetonatorPlace[2] = make_shared<ItemPlace>(GetUniqueObject("DetonatorPlace3"), Item::Type::Explosives));
	AddItemPlace(mDetonatorPlace[3] = make_shared<ItemPlace>(GetUniqueObject("DetonatorPlace4"), Item::Type::Explosives));

	mWireModels[0] = GetUniqueObject("WireModel1");
	mWireModels[1] = GetUniqueObject("WireModel2");
	mWireModels[2] = GetUniqueObject("WireModel3");
	mWireModels[3] = GetUniqueObject("WireModel4");

	mDetonatorModels[0] = GetUniqueObject("DetonatorModel1");
	mDetonatorModels[1] = GetUniqueObject("DetonatorModel2");
	mDetonatorModels[2] = GetUniqueObject("DetonatorModel3");
	mDetonatorModels[3] = GetUniqueObject("DetonatorModel4");

	mExplosivesModels[0] = GetUniqueObject("ExplosivesModel1");
	mExplosivesModels[1] = GetUniqueObject("ExplosivesModel2");
	mExplosivesModels[2] = GetUniqueObject("ExplosivesModel3");
	mExplosivesModels[3] = GetUniqueObject("ExplosivesModel4");

	mFindItemsZone = GetUniqueObject("FindItemsZone");

	AddAmbientSound(soundSystem->LoadSound3D("data/sounds/ambient/mine/ambientmine1.ogg"));
	AddAmbientSound(soundSystem->LoadSound3D("data/sounds/ambient/mine/ambientmine2.ogg"));
	AddAmbientSound(soundSystem->LoadSound3D("data/sounds/ambient/mine/ambientmine3.ogg"));
	AddAmbientSound(soundSystem->LoadSound3D("data/sounds/ambient/mine/ambientmine4.ogg"));
	AddAmbientSound(soundSystem->LoadSound3D("data/sounds/ambient/mine/ambientmine5.ogg"));

	mExplosionTimer = ITimer::Create();
	mBeepSoundTimer = ITimer::Create();
	mBeepSoundTiming = 1.0f;

	CreateItems();

	mReadyExplosivesCount = 0;

	MakeLadder("LadderBegin", "LadderEnd", "LadderEnter", "LadderBeginLeavePoint", "LadderEndLeavePoint");
	MakeDoor("Door1", 90);
	MakeDoor("Door3", 90);
	MakeDoor("DoorToAdministration", 90);
	MakeDoor("Door6", 90);
	MakeDoor("DoorToDirectorsOffice", 90);
	MakeDoor("DoorToResearchFacility", 90);

	MakeKeypad("Keypad1", "Keypad1Key0", "Keypad1Key1", "Keypad1Key2", "Keypad1Key3", "Keypad1Key4", "Keypad1Key5", "Keypad1Key6", "Keypad1Key7", "Keypad1Key8", "Keypad1Key9", "Keypad1KeyCancel", MakeDoor("StorageDoor", 90), "7854");
	MakeKeypad("Keypad2", "Keypad2Key0", "Keypad2Key1", "Keypad2Key2", "Keypad2Key3", "Keypad2Key4", "Keypad2Key5", "Keypad2Key6", "Keypad2Key7", "Keypad2Key8", "Keypad2Key9", "Keypad2KeyCancel", MakeDoor("DoorToResearchFacility", 90), "1689");
	MakeKeypad("Keypad3", "Keypad3Key0", "Keypad3Key1", "Keypad3Key2", "Keypad3Key3", "Keypad3Key4", "Keypad3Key5", "Keypad3Key6", "Keypad3Key7", "Keypad3Key8", "Keypad3Key9", "Keypad3KeyCancel", MakeDoor("DoorMedical", 90), "9632");

	mMusic->Play();

	mStages["ConcreteWallExp"] = false;
	mStages["FindObjectObjectiveSet"] = false;
	mStages["FoundObjectsForExplosion"] = false;

	// create paths
	const char * ways[] = {
		"WayA", "WayB", "WayC", "WayD", "WayE", "WayF", "WayG",
		"WayH", "WayI", "WayJ", "WayK"
	};
	Path p;
	for(auto w : ways) {
		p += Path(mScene, w);
	}

	p.Get("WayB1")->AddEdge(p.Get("WayA004"));
	p.Get("WayC1")->AddEdge(p.Get("WayA019"));
	p.Get("WayD1")->AddEdge(p.Get("WayA019"));
	p.Get("WayE1")->AddEdge(p.Get("WayA040"));
	p.Get("WayF1")->AddEdge(p.Get("WayA042"));
	p.Get("WayF009")->AddEdge(p.Get("WayG1"));
	p.Get("WayH1")->AddEdge(p.Get("WayA059"));
	p.Get("WayI1")->AddEdge(p.Get("WayA097"));
	p.Get("WayJ1")->AddEdge(p.Get("WayA073"));
	p.Get("WayK1")->AddEdge(p.Get("WayA027"));

	vector<shared_ptr<GraphVertex>> patrolPoints = {
		p.Get("WayA1"), p.Get("WayC024"), p.Get("WayB012"),
		p.Get("WayB012"), p.Get("WayD003"), p.Get("WayK005"),
		p.Get("WayE006"), p.Get("WayF019"), p.Get("WayG007"),
		p.Get("WayH010"), p.Get("WayA110"), p.Get("WayI009")
	};

	mEnemy = make_unique<Enemy>(mGame, p.mVertexList, patrolPoints);
	mEnemy->SetPosition(GetUniqueObject("EnemyPosition")->GetPosition());

	mExplosivesDummy[0] = GetUniqueObject("ExplosivesModel5");
	mExplosivesDummy[1] = GetUniqueObject("ExplosivesModel6");
	mExplosivesDummy[2] = GetUniqueObject("ExplosivesModel7");
	mExplosivesDummy[3] = GetUniqueObject("ExplosivesModel8");

	mExplodedWall = GetUniqueObject("ConcreteWallExploded");
	mExplodedWall->Hide();

	mExplosionFlashPosition = GetUniqueObject("ExplosionFlash");

	mPlayer->GetInventory()->RemoveItem(Item::Type::Crowbar, 1);

	DoneInitialization();
}