예제 #1
0
void FactoredStatesMap::remove(unsigned int factorIndex, State *removeState)
{
	if (factorIndex < 0 || factorIndex >= factoredStates.size()) {
		throw StateException();
	} else if (std::find(factoredStates[factorIndex].begin(), factoredStates[factorIndex].end(),
			removeState) == factoredStates[factorIndex].end()) {
		throw StateException();
	}

	factoredStates[factorIndex].erase(
			std::remove(factoredStates[factorIndex].begin(), factoredStates[factorIndex].end(), removeState),
			factoredStates[factorIndex].end());
	delete removeState;
}
예제 #2
0
void FactoredStatesMap::add_factor(const std::vector<State *> &newStates)
{
	if (newStates.size() == 0) {
		throw StateException();
	}

	for (const State *state : newStates) {
		if (state == nullptr) {
			throw StateException();
		}
	}

	factoredStates.push_back(newStates);
}
예제 #3
0
파일: State.cpp 프로젝트: argenos/Menge
		void State::enter( Agents::BaseAgent * agent ) {
			for ( size_t i = 0; i < actions_.size(); ++i ) {
				actions_[i]->onEnter( agent );
			}

			Goal * goal = 0x0;
			try {
				goal = _goalSelector->assignGoal( agent );
			} catch ( GoalSelectorException ) {
				logger << Logger::ERR_MSG << "State " << _name << " was unable to assign a goal to agent " << agent->_id << ".";
				throw StateException();
			}

			_goalLock.lockWrite();
			_goals[ agent->_id ] = goal;
			_goalLock.releaseWrite();

			_velComponent->onEnter( agent );
			for ( size_t i = 0; i < transitions_.size(); ++i ) {
				transitions_[i]->onEnter( agent );
			}

			//velmodifiers
			for ( size_t i = 0; i < velModifiers_.size(); ++i ) {
				velModifiers_[i]->onEnter( agent );
			}
		}
예제 #4
0
State *FactoredState::get(unsigned int index)
{
	if (index < 0 || index >= states.size()) {
		throw StateException();
	}
	return states[index];
}
예제 #5
0
State *StatesMap::get(unsigned int hash)
{
	try {
		return states.at(hash);
	} catch (const std::out_of_range &err) {
		throw StateException();
	}
}
예제 #6
0
const uint8_t TupleState::m_build_variant_current() const
{
  if (!mBuildVariant)
  {
    throw StateException("No tuple variants for building ready");
  }
  return mBuildVariant - 1;
}
예제 #7
0
const uint8_t TupleState::m_parse_variant_current() const
{
  if (!mParseVariant)
  {
    throw StateException("No tuple variants for parsing ready");
  }
  return mParseVariant - 1;
}
예제 #8
0
void FactoredStatesMap::add(unsigned int factorIndex, State *newState)
{
	if (factorIndex < 0 || factorIndex >= factoredStates.size()) {
		throw StateException();
	}

	factoredStates[factorIndex].push_back(newState);
}
예제 #9
0
State &FactoredState::operator=(State &other)
{
    FactoredState *s = dynamic_cast<FactoredState *> (&other);
    if (s == nullptr) {
    	throw StateException();
    }
	states = s->states;
	return *this;
}
예제 #10
0
State *FactoredStatesMap::get(unsigned int factorIndex, unsigned int stateIndex)
{
	if (factorIndex < 0 || factorIndex >= factoredStates.size() ||
			stateIndex < 0 || stateIndex >= factoredStates[factorIndex].size()) {
		throw StateException();
	}

	return factoredStates[factorIndex][stateIndex];
}
예제 #11
0
void StatesMap::remove(State *removeState)
{
	// Ensure that the element exists in the hash before removing it.
	std::unordered_map<unsigned int, State *>::const_iterator result = states.find(removeState->hash_value());
	if (result == states.end()) {
		throw StateException();
	}

	states.erase(removeState->hash_value());
	delete removeState;
}
예제 #12
0
void FactoredStatesMap::set(unsigned int factorIndex, const std::vector<State *> &newStates)
{
	if (factorIndex < 0 || factorIndex >= factoredStates.size() || newStates.size() == 0) {
		throw StateException();
	}

	// Delete the current factor's states list.
	for (State *state : factoredStates[factorIndex]) {
		delete state;
	}
	factoredStates[factorIndex].clear();

	factoredStates[factorIndex] = newStates;
}
예제 #13
0
void FactoredStatesMap::update()
{
	// Throw an error if one factor is not defined.
	for (std::vector<State *> &factor : factoredStates) {
		if (factor.size() == 0) {
			throw StateException();
		}
	}

	states.clear();

	std::vector<State *> create;
	update_step(create, 0);
}
예제 #14
0
파일: game.cpp 프로젝트: gemini14/Typhon
	Game::Game(std::shared_ptr<Engine> engine) :
	FSMState(engine), 
#ifndef WIN32
		serverPID(0),
#endif
		connectedToServer(false), network(nullptr), levelManager(new LevelManager(engine))
	{
		callbacks['D'] = &Game::Disconnect;
		callbacks['L'] = &Game::LevelAction;

		if (engine->clientIsServer)
		{
			// create child process to run the server (if this client is the
			// one chosen to run the server)
#ifdef WIN32

			memset(&startupInfo, 0, sizeof startupInfo);
			memset(&procInfo, 0, sizeof procInfo);
			startupInfo.cb = sizeof startupInfo;
			std::string temp("TyphonServer ");
			temp += *engine->lobbyList;
			temp += " " + boost::lexical_cast<string>(GetNetworkIP(engine->serverIP));
			LPSTR argLine = const_cast<char*>(temp.c_str());

			int result;
#ifdef WIN64
#ifdef DEBUG // 64-bit build, Debug
			result = CreateProcess("../../bin/Server/Win64/Debug/TyphonServer64.exe", argLine, 
				nullptr, nullptr, true, CREATE_NEW_CONSOLE, nullptr, nullptr,
				&startupInfo, &procInfo);
#else // 64-bit build, Release
			result = CreateProcess("../../bin/Server/Win64/Release/TyphonServer64.exe", argLine, 
				nullptr, nullptr, true, CREATE_NEW_CONSOLE, nullptr, nullptr,
				&startupInfo, &procInfo);
#endif
#elif defined(WIN32)
#ifdef DEBUG // 32-bit build, Debug
			result = CreateProcess("../../bin/Server/Win32/Debug/TyphonServer32.exe", argLine, 
				nullptr, nullptr, true, CREATE_NEW_CONSOLE, nullptr, nullptr,
				&startupInfo, &procInfo);
#else // 32-bit build, Release
			result = CreateProcess("../../bin/Server/Win32/Release/TyphonServer32.exe", argLine, 
				nullptr, nullptr, true, CREATE_NEW_CONSOLE, nullptr, nullptr,
				&startupInfo, &procInfo);
#endif
#endif
			if(!result)
			{
				throw StateException("Error creating server process.\n");
			}
			//else
			//{
			//	auto waitResult = WaitForInputIdle(procInfo.hProcess, INFINITE);
			//}
#endif
#ifndef WIN32 // Linux
			std::unique_ptr<char[]> lobbyList(new char[engine->lobbyList->length() + 1]);
			strcpy(lobbyList.get(), engine->lobbyList->c_str());
			string server(boost::lexical_cast<string>(GetNetworkIP(engine->serverIP)));
			std::unique_ptr<char[]> serverAddr(new char[server.length() + 1]);
			strcpy(serverAddr.get(), server.c_str());
			char * const argList[] = { "TyphonServer", *lobbyList, *serverAddr, nullptr };

			serverPID = fork();
			if (serverPID == -1)
			{
				throw StateException("Error forking client.\n");
			}
			else if (serverPID == 0)
			{
				// this is the child
				// run the server program, sending the names & IPs
				// of the players as an argument


				// TODO Important -- these paths MUST be adjusted for final release
#ifdef DEBUG
				execvp("../../bin/Server/Linux/TyphonServer_D", argList);
#else
				execvp("../../bin/Server/Linux/TyphonServer", argList);
#endif
				// if we reach this point, something went wrong (exec doesn't return
				// otherwise)
				perror("execvp");
				Log("Exec call to create server failed.");
				throw StateException("Error exec'ing server.\n");
			}

			// if we reached this point, we're the parent
#endif
		}

		network.reset(Typhon::GetNetwork(Typhon::ENETCLIENT, PORT_NUMBER, &engine->serverIP));
		if (!network)
		{
			// TODO: Add some kind of notification if user can't initially connect
			throw StateException(
				"Error starting up network code (could not allocate or incompatible system).\n");
		}
		// set the level manager's network
		levelManager->network = network;
		
		connectedToServer = reinterpret_cast<NetworkENetClient*>(network.get())->ConnectToServer();
		if(!connectedToServer)
		{
			engine->eventQueue.push(FSM::RET_TO_LOBBY_FROM_GAME);
		}
	}