Exemple #1
0
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;
}
Exemple #2
0
void Display(FunctionQueue *FQ,PathList *PL)
{
    while (!FunctionEmpty(FQ))
    {
        FuncItem *F;
        F = FunctionFirst(FQ);
        
        switch (F->command)
        {
            // Kill command
            case 0:
                Kill(F->unit,F->flag,PL);
                break;
            // Spawn command
            case 1:
                Spawn(F->unit,PL);
                break;
            // DrawMap command
            case 2:
                DrawMap(F->towerList,PL);
                break;
            // DrawMenu command
            case 3:
                DrawMenu();
                break;
            // DrawAvailableUnits command
            case 4:
                DrawAvailableUnits(F->level,F->unitList);
                break;
            // RedrawQueue command
            case 5:
                RedrawQueue(F->unitList);
                break;
            // RedrawResources command
            case 6:
                RedrawResources(F->level);
                break;
            // RedrawHP command
            case 7:
                RedrawHP(F->level);
                break;
            // ClearMap command
            case 8:
                ClearMap();
                break;
            // ClearPrompts command
            case 9:
                ClearPrompts();
                break;
            // ClearMsg command
            case 10:
                ClearMsg();
                break;
            // PrintMsg command
            case 11:
                PrintMsg(F->flag);
                break;
            // StageLose command
            case 12:
                StageLose();
                break;
            // StageWin command
            case 13:
                StageWin();
                break;
            default:
                break;
        }
        
        FunctionDequeue(FQ);
    }
}