コード例 #1
0
ファイル: CNetGame.cpp プロジェクト: trisz404/OpenSAMP-WIP
void CNetGame::Process()
{
	float fElapsedTime = GetElapsedTime();

	UpdateNetwork();

	if(this->gameState == 1) 
	{	
		if(this->playerPool) this->playerPool->Process(fElapsedTime);
		if(this->vehiclePool) this->vehiclePool->Process(fElapsedTime);
		if(this->objectPool) this->objectPool->Process(fElapsedTime);
		if(this->gamemodeManager) this->gamemodeManager->Frame(fElapsedTime);
		if(this->scriptTimerManager) this->scriptTimerManager->Process((uint32_t)(fElapsedTime * 1000.0f));
		if(this->scriptHttpManager) this->scriptHttpManager->Process();

		if ( __ElementFactory ) __ElementFactory->Process ( fElapsedTime );
	} 
	else if(this->gameState == 2) 
	{
		fRestartWaitTime += fElapsedTime;
		if(fRestartWaitTime > 12.0f)
		{
			ReInitWhenRestarting();
		}
	}

	if (__Console->GetBoolVar("announce"))
		MasterServerAnnounce(fElapsedTime);

	__Plugins->DoProcessTick();

	#ifndef WIN32
		this->elapsedTime += (double)fElapsedTime;
	#endif
}
コード例 #2
0
ファイル: rpi.cpp プロジェクト: lstopar/HomeDevelopment
bool TRf24Radio::Send(const uint16& NodeAddr, const uchar& Command, const TMem& Buff) {
	bool ReceivedAck = false;

	try {
		Notify->OnNotifyFmt(ntInfo, "Sending message to node %d ...", NodeAddr);

		RF24NetworkHeader Header(NodeAddr, Command);

		TRpiUtil::SetMaxPriority();

		uint16 From;
		uchar Type;
		TMem Payload;	Payload.Gen(PAYLOAD_LEN);

		TLock Lock(CriticalSection);

		int RetryN = 0;
		while (!ReceivedAck && RetryN < RETRY_COUNT) {
			if (RetryN > 0) {
				Notify->OnNotifyFmt(ntInfo, "Re-sending message, count %d", RetryN);
			}

			// write the message
			_Send(Header, Buff);

			// wait for an ACK
			const uint64 StartTm = TTm::GetCurUniMSecs();
			while (!ReceivedAck && TTm::GetCurUniMSecs() - StartTm < ACK_TIMEOUT) {
				UpdateNetwork();

				while (Read(From, Type, Payload)) {
					if (Type == REQUEST_ACK) {
						if (From != NodeAddr) {
							Notify->OnNotifyFmt(ntWarn, "WTF!? received ACK from incorrect node, expected: %u, got: %u", NodeAddr, From);
						} else {
							Notify->OnNotifyFmt(ntInfo, "Received ack from node %u", NodeAddr);
							ReceivedAck = true;
						}
					} else {
						ReadThread.AddToQueue(TMsgInfo(From, Type, Payload));
					}
				}
			}

			RetryN++;
		}

		TRpiUtil::SetDefaultPriority();
	} catch (const PExcept& Except) {
		Notify->OnNotifyFmt(TNotifyType::ntErr, "Exception when sending!");
		TRpiUtil::SetDefaultPriority();
		return false;
	}

	if (!ReceivedAck) {
		Notify->OnNotifyFmt(ntInfo, "Failed to send message!");
	}

	return ReceivedAck;
}
コード例 #3
0
/* backpropagtation algorithm */
void Backpropagation (int* input, int* targetOutput)
{
	int i = 0;
	float **hiddenDelta, *outputDelta;

	/* allocate output, hiddendelta and outputdelta */
	hiddenDelta = (float **)calloc(numHiddenLayers, sizeof(float *));
	outputDelta = (float *)calloc(numOutputNodes, sizeof(float));

	for(i = 0; i < numHiddenLayers; i++)
	{
		hiddenDelta[i] = (float *)calloc(neuronsPerLayer,  sizeof(float));
	}

	ForwardPropagation (input, outputOutputs);

	CalcDelta(targetOutput,
			hiddenDelta,
			outputDelta);

	UpdateNetwork(hiddenDelta, outputDelta, input);


	for(i = 0; i < numHiddenLayers; i++)
	{
		free(hiddenDelta[i]);
	}

	free(hiddenDelta);
	free(outputDelta);

	return;
}
コード例 #4
0
ファイル: clientarea.cpp プロジェクト: kuroyuki/QTNodes
void ClientArea::BindNetwork(){

    dojoPtr->CreateSensor(&Sensor1, 2,1);
    dojoPtr->CreateActuator(&Actuator1, 2,3);
    dojoPtr->DeleteNode(2,2);

    UpdateNetwork(bitMask);
}
コード例 #5
0
ファイル: netgame.cpp プロジェクト: jovazxc/samp
void CNetGame::Process()
{
	float fElapsedTime = GetElapsedTime();

	UpdateNetwork();

	//if (IsACEnabled())
		//CAntiCheat::Process();

	if(m_iGameState == GAMESTATE_RUNNING) 
	{
		if(m_pPlayerPool) m_pPlayerPool->Process(fElapsedTime);
		if(m_pVehiclePool) m_pVehiclePool->Process(fElapsedTime);
		if(m_pObjectPool) m_pObjectPool->Process(fElapsedTime);
		if(m_pGameMode) m_pGameMode->Frame(fElapsedTime);
		if(m_pScriptTimers) m_pScriptTimers->Process((DWORD)(fElapsedTime * 1000.0f));
	
	} 
	else if(m_iGameState == GAMESTATE_RESTARTING) 
	{
		fRestartWaitTime += fElapsedTime;
		if(fRestartWaitTime > 12.0f) // wait 12 seconds, then restart
		{
			ReInitWhenRestarting();
		}
	}

	if (pConsole->GetBoolVariable("announce")) {
		// Announce the server to the master
		MasterServerAnnounce(fElapsedTime);
	}

	// Execute the tick event for loaded plugins
	pPlugins->DoProcessTick();
	
	#ifndef WIN32
		m_dElapsedTime += (double)fElapsedTime;
	#endif
}
コード例 #6
0
ファイル: CNetworkModule.cpp プロジェクト: WD32/maf2mp
void CNetworkModule::Pulse( void )
{
	// Is the game not loaded?
	if( !pCore->IsGameLoaded() )
		return;

	// Are we disconnected from the network?
	if( GetNetworkState() == NETSTATE_DISCONNECTED )
		return;

	// Process the network
	UpdateNetwork ();

	// Are we connected?
	if( IsConnected() )
	{
		// Pulse the player manager
		pCore->GetPlayerManager()->Pulse ();

		// Pulse the vehicle manager
		pCore->GetVehicleManager()->Pulse ();
	}
}
コード例 #7
0
void CNetworkManager::Pulse()
{
	// Is the game not loaded?
	if(!g_pCore->IsGameLoaded())
		return;

	// Are we disconnected from the network?
	if(GetNetworkState() == NETSTATE_DISCONNECTED)
		return;

	// Should we try connecting again?
	if(GetNetworkState() == NETSTATE_TIMEOUT && ((unsigned short)SharedUtility::GetTime() - m_uiLastConnectionTry) >= NETWORK_TIMEOUT)
	{
		// Attempt to reconnect
		Connect(m_strIp, m_usPort, m_strPass);

		// Set the network state
		SetNetworkState(NETSTATE_CONNECTING);

		// Set the last connection try
		m_uiLastConnectionTry = (unsigned int)SharedUtility::GetTime();
	}

	// Process the network
	UpdateNetwork();

	// Are we connected?
	if(IsConnected())
	{
		// Pulse the player manager
		g_pCore->GetGame()->GetPlayerManager()->Pulse();

		// Pulse the vehicle manager
		g_pCore->GetGame()->GetVehicleManager()->Pulse();
	}
}
コード例 #8
0
ファイル: main.cpp プロジェクト: S3n20/RakSAMP
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
	srand((unsigned int)GetTickCount());

	// load up settings
	if(!LoadSettings())
	{
		Log("Failed to load settings");
		getchar();
		return 0;
	}

	if(settings.iConsole)
		SetUpConsole();
	else
	{
		SetUpWindow(hInstance);
		Sleep(500); // wait a bit for the dialog to create
	}

	// RCON mode
	if(settings.runMode == RUNMODE_RCON)
	{
		if(RCONReceiveLoop())
		{
			if(flLog != NULL)
			{
				fclose(flLog);
				flLog = NULL;
			}

			return 0;
		}
	}	

	// set up networking
	pRakClient = RakNetworkFactory::GetRakClientInterface();
	if(pRakClient == NULL)
		return 0;

	pRakClient->SetMTUSize(576);

	resetPools(1, 0);
	RegisterRPCs(pRakClient);

	SYSTEMTIME time;
	GetLocalTime(&time);
	if(settings.iConsole)
	{
		Log(" ");
		Log("* ===================================================== *");
		Log("  RakSAMP " RAKSAMP_VERSION " initialized on %02d/%02d/%02d %02d:%02d:%02d",
			time.wDay, time.wMonth, time.wYear, time.wHour, time.wMinute, time.wSecond);
		Log("  Authors: " AUTHOR "");
		Log("* ===================================================== *");
		Log(" ");
	}

	char szInfo[400];
	char szLastInfo[400];
	
	int iLastMoney = iMoney;
	int iLastDrunkLevel = iDrunkLevel;

	int iLastStatsUpdate = GetTickCount();
	
	while(1)
	{
		UpdateNetwork(pRakClient);

		if(settings.bSpam)
			sampSpam();

		if (settings.bFakeKill)
			sampFakeKill();

		if (settings.bLag)
			sampLag();

		if (settings.bJoinFlood)
			sampJoinFlood();

		if (settings.bChatFlood)
			sampChatFlood();

		if (settings.bClassFlood)
			sampClassFlood();

		processPulsator();
		processBulletFlood();

		if (!iConnectionRequested)
		{
			if(!iGettingNewName)
				sampConnect(settings.server.szAddr, settings.server.iPort, settings.server.szNickname, settings.server.szPassword, pRakClient);
			else
				sampConnect(settings.server.szAddr, settings.server.iPort, g_szNickName, settings.server.szPassword, pRakClient);

			iConnectionRequested = 1;
		}

		if (iAreWeConnected && iGameInited)
		{
			static DWORD dwLastInfoUpdate = GetTickCount();
			if(dwLastInfoUpdate && dwLastInfoUpdate < (GetTickCount() - 1000))
			{
				char szHealthText[16], szArmourText[16];

				if(settings.fPlayerHealth > 200.0f)
					sprintf_s(szHealthText, sizeof(szHealthText), "N/A");
				else
					sprintf_s(szHealthText, sizeof(szHealthText), "%.2f", settings.fPlayerHealth);

				if(settings.fPlayerArmour > 200.0f)
					sprintf_s(szArmourText, sizeof(szArmourText), "N/A");
				else
					sprintf_s(szArmourText, sizeof(szArmourText), "%.2f", settings.fPlayerArmour);

				sprintf_s(szInfo, 400, "Hostname: %s     Players: %d     Ping: %d     Authors: %s\nHealth: %s     Armour: %s     Skin: %d     X: %.4f     Y: %.4f     Z: %.4f     Rotation: %.4f",
				g_szHostName, getPlayerCount(), playerInfo[g_myPlayerID].dwPing, AUTHOR, szHealthText, szArmourText, iLocalPlayerSkin, settings.fNormalModePos[0], settings.fNormalModePos[1], settings.fNormalModePos[2], settings.fNormalModeRot);
				
				if(strcmp(szInfo, szLastInfo) != 0)
				{
					SetWindowText(texthwnd, szInfo);
					sprintf_s(szLastInfo, szInfo);
				}
			}

			if (settings.iUpdateStats)
			{
				if((GetTickCount() - iLastStatsUpdate >= 1000) || iMoney != iLastMoney || iDrunkLevel != iLastDrunkLevel)
				{
					RakNet::BitStream bsSend;

					bsSend.Write((BYTE)ID_STATS_UPDATE);

					iDrunkLevel -= (rand() % settings.iMaxFPS + settings.iMinFPS);

					if(iDrunkLevel < 0)
						iDrunkLevel = 0;

					bsSend.Write(iMoney);
					bsSend.Write(iDrunkLevel);

					pRakClient->Send(&bsSend, HIGH_PRIORITY, RELIABLE, 0);

					iLastMoney = iMoney;
					iLastDrunkLevel = iDrunkLevel;

					iLastStatsUpdate = GetTickCount();
				}
			}

			if(settings.runMode == RUNMODE_BARE)
				goto bare;

			if(!iSpawned)
			{
				if(settings.iManualSpawn != 0)
				{
					if(!iNotificationDisplayedBeforeSpawn)
					{
						sampRequestClass(settings.iClassID);
						
						Log("Please write !spawn into the console when you're ready to spawn.");

						iNotificationDisplayedBeforeSpawn = 1;
					}
				}
				else
				{
					sampRequestClass(settings.iClassID);
					sampSpawn();

					iSpawned = 1;
					iNotificationDisplayedBeforeSpawn = 1;
				}
			}
			else
			{
				if(settings.runMode == RUNMODE_STILL)
				{
					// Nothing left to do. :-)
				}

				if(settings.runMode == RUNMODE_NORMAL)
				{
					if(settings.AutoGotoCP && settings.CurrentCheckpoint.bActive)
					{
						settings.fNormalModePos[0] = settings.CurrentCheckpoint.fPosition[0];
						settings.fNormalModePos[1] = settings.CurrentCheckpoint.fPosition[1];
						settings.fNormalModePos[2] = settings.CurrentCheckpoint.fPosition[2];
					}

					onFootUpdateAtNormalPos();
				}

				// Run autorun commands
				if(settings.iAutorun)
				{
					if(dwAutoRunTick && dwAutoRunTick < (GetTickCount() - 2000))
					{
						static int autorun;
						if(!autorun)
						{
							Log("Loading autorun...");
							for(int i = 0; i < MAX_AUTORUN_CMDS; i++)
								if(settings.autoRunCMDs[i].iExists)
									RunCommand(settings.autoRunCMDs[i].szCMD, 1);

							autorun = 1;
						}
					}
				}

				// Following player mode.
				if(settings.runMode == RUNMODE_FOLLOWPLAYER)
				{
					PLAYERID copyingID = getPlayerIDFromPlayerName(settings.szFollowingPlayerName);
					if(copyingID != (PLAYERID)-1)
						onFootUpdateFollow(copyingID);
				}

				// Following a player with a vehicle mode.
				if(settings.runMode == RUNMODE_FOLLOWPLAYERSVEHICLE)
				{
					PLAYERID copyingID = getPlayerIDFromPlayerName(settings.szFollowingPlayerName);
					if(copyingID != (PLAYERID)-1)
						inCarUpdateFollow(copyingID, (VEHICLEID)settings.iFollowingWithVehicleID);
				}

			}
		}

bare:;
		Sleep(30);
	}

	if(flLog != NULL)
	{
		fclose(flLog);
		flLog = NULL;
	}

	if(flTextDrawsLog != NULL)
	{
		fclose(flTextDrawsLog);
		flTextDrawsLog = NULL;
	}

	return 0;
}
コード例 #9
0
void CNetworkModule::Pulse(void)
{
	// Update the network
	UpdateNetwork();
}
コード例 #10
0
ファイル: TheGame.cpp プロジェクト: Pappskiva/TicTacToe
bool TheGame::Update()
{
	m_exit = false;
	SDL_Event e;
	//Handle events on queue
	while (SDL_PollEvent(&e) != 0)
	{
		//User requests quit
		if (e.type == SDL_QUIT)
		{
			m_exit = true;
			Network::GetInstance()->SendDisconnectMessage();
		}
	}
	UpdateNetwork(e);
	if (gameHasStarter)
	{
		m_GameBoard->Update(m_screen, &e);
	}
	else
	{
		m_GameBoard->SetAllToDefault();
	}

	if (m_ExitButton->IsClicked(m_screen, &e))
	{
		m_exit = true;
		Network::GetInstance()->SendDisconnectMessage();
	}
	if (Network::GetInstance()->VictoryState() == 1)
		SDL_BlitSurface(m_crossVictorySign, NULL, m_screen, &m_VictorySignRect);
	else if (Network::GetInstance()->VictoryState() == 0)
		SDL_BlitSurface(m_circleVictorySign, NULL, m_screen, &m_VictorySignRect);


	if (Network::GetInstance()->GetState() != 0 && Network::GetInstance()->VictoryState() == 2)
	{
		if (Network::GetInstance()->MyTurn())
		{
			SDL_BlitSurface(m_circleTurnSign, NULL, m_screen, &m_VictorySignRect);
		}
		else
		{
			SDL_BlitSurface(m_crossTurnSign, NULL, m_screen, &m_VictorySignRect);
		}
	}



	SDL_UpdateWindowSurface(m_window);
	if (Network::GetInstance()->StartDisconnect())
	{
		Network::GetInstance()->Shutdown();
	}

	if (m_exit)
	{
		Network::GetInstance()->Shutdown();
	}
	return m_exit;
}
コード例 #11
0
ファイル: WorldMapLayer.cpp プロジェクト: RuWhyNot/thewe
void WorldMapLayer::UpdateMapElements()
{
	UpdateTowns();
	UpdateCells();
	UpdateNetwork();
}