コード例 #1
0
void
addRemoteChecksum(NetConnection *conn, BattleFrameCounter frameNr,
		Checksum checksum) {
	ChecksumBuffer *cb;
	
	assert(frameNr <= battleFrameCount + getBattleInputDelay() + 1);
	assert(frameNr + getBattleInputDelay() >= battleFrameCount);

	cb = NetConnection_getChecksumBuffer(conn);
	ChecksumBuffer_addChecksum(cb, frameNr, checksum);
}
コード例 #2
0
void
initChecksumBuffers(void) {
	size_t player;

	for (player = 0; player < NETPLAY_NUM_PLAYERS; player++)
	{
		NetConnection *conn;
		ChecksumBuffer *cb;

		conn = netConnections[player];
		if (conn == NULL)
			continue;

		cb = NetConnection_getChecksumBuffer(conn);
		ChecksumBuffer_init(cb, getBattleInputDelay(),
				NETPLAY_CHECKSUM_INTERVAL);
	}

	ChecksumBuffer_init(&localChecksumBuffer, getBattleInputDelay(),
			NETPLAY_CHECKSUM_INTERVAL);
}
コード例 #3
0
ファイル: battle.c プロジェクト: jurchik/project6014
static BOOLEAN
DoBattle (BATTLE_STATE *bs)
{
	extern UWORD nth_frame;
	RECT r;
	BYTE battle_speed;

	SetMenuSounds (MENU_SOUND_NONE, MENU_SOUND_NONE);

#if defined (NETPLAY) && defined (NETPLAY_CHECKSUM)
	if (getNumNetConnections() > 0 &&
			battleFrameCount % NETPLAY_CHECKSUM_INTERVAL == 0)
	{
		crc_State state;
		Checksum checksum;

		crc_init(&state);
		crc_processState (&state);
		checksum = (Checksum) crc_finish (&state);

		Netplay_NotifyAll_checksum ((uint32) battleFrameCount,
				(uint32) checksum);
		flushPacketQueues ();
		addLocalChecksum (battleFrameCount, checksum);
	}
#endif
	ProcessInput ();
			// Also calls NetInput()
#if defined (NETPLAY) && defined (NETPLAY_CHECKSUM)
	if (getNumNetConnections() > 0)
	{
		size_t delay = getBattleInputDelay();

		if (battleFrameCount >= delay
				&& (battleFrameCount - delay) % NETPLAY_CHECKSUM_INTERVAL == 0)
		{
			if (!(GLOBAL (CurrentActivity) & CHECK_ABORT))
			{
				if (!verifyChecksums (battleFrameCount - delay)) {
					GLOBAL(CurrentActivity) |= CHECK_ABORT;
					resetConnections (ResetReason_syncLoss);
				}
			}
		}
	}
#endif

	LockMutex (GraphicsLock);
	if (bs->first_time)
	{
		r.corner.x = SIS_ORG_X;
		r.corner.y = SIS_ORG_Y;
		r.extent.width = SIS_SCREEN_WIDTH;
		r.extent.height = SIS_SCREEN_HEIGHT;
		SetTransitionSource (&r);
	}
	BatchGraphics ();

	// Call the callback function, if set
	if (bs->frame_cb)
		bs->frame_cb ();

	RedrawQueue (TRUE);

	if (bs->first_time)
	{
		bs->first_time = FALSE;
		ScreenTransition (3, &r);
	}
	UnbatchGraphics ();
	UnlockMutex (GraphicsLock);
	if ((!(GLOBAL (CurrentActivity) & IN_BATTLE)) ||
			(GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD)))
	{
		return FALSE;
	}

	battle_speed = HIBYTE (nth_frame);
	if (battle_speed == (BYTE)~0)
	{	// maximum speed, nothing rendered at all
		TaskSwitch ();
	}
	else
	{
		SleepThreadUntil (bs->NextTime
				+ BATTLE_FRAME_RATE / (battle_speed + 1));
		bs->NextTime = GetTimeCounter ();
	}

	if ((GLOBAL (CurrentActivity) & IN_BATTLE) == 0)
		return FALSE;

#ifdef NETPLAY
	battleFrameCount++;
#endif
	return TRUE;
}