Example #1
0
int MFInput_Thread(void *)
{
	// poll input at high frequency...
	uint64 freq = MFSystem_GetRTCFrequency();
	uint64 interval = freq / gInputFrequency;

	uint64 now = MFSystem_ReadRTC();
	uint64 nextSample = now + interval;

	while(!bInputTerminate)
	{
		MFThread_LockMutex(gInputMutex);
		bThreadUpdate = true;
		MFInput_Update();
		bThreadUpdate = false;

		// build events
		for(uint32 i=0; i<MFInput_MaxInputID; ++i)
		{
			if(!gDeviceStatus[IDD_Gamepad][i] == IDS_Ready)
				continue;

			for(uint32 j=0; j<GamepadType_Max; ++j)
			{
				if(gNumEvents[IDD_Gamepad][i] >= MaxEvents)
					break;

				MFGamepadState &state = gGamepadStates[i];
				MFGamepadState &prev = gPrevGamepadStates[i];
				if(state.values[j] == prev.values[j])
					continue;

				MFInputEvent &e = gInputEvents[IDD_Gamepad][i][gNumEvents[IDD_Gamepad][i]++];
				e.timestamp = now;
				e.event = MFIE_Change;
				e.input = j;
				e.state = state.values[j];
				e.prevState = prev.values[j];
			}
		}

		MFThread_ReleaseMutex(gInputMutex);

//		uint64 updateTime = MFSystem_ReadRTC();
//		MFDebug_Log(0, MFStr("Input update: %dus", (uint32)((updateTime - now) * 1000000LL / MFSystem_GetRTCFrequency())));

		uint32 ms = (uint32)((nextSample - now) * 1000LL / freq);
		MFThread_Sleep(ms);

		now = MFSystem_ReadRTC();
		do
			nextSample += interval;
		while(now >= nextSample);
	}

	bInputTerminate = false;
	return 0;
}
Example #2
0
void MFCallstack_BeginFrame()
{
    MFCALLSTACK;

    gLastBeginTime = gBeginTime;
    gBeginTime = MFSystem_ReadRTC();
}
Example #3
0
void Timer::Reset()
{
    accumulator = 0;
    lastUpdate = 0;

    lastCall = MFSystem_ReadRTC();

    smoothDeltaF = 1.0f/60.0f;
}
Example #4
0
int GameMain(MFInitParams *pInitParams)
{
	MFRand_Seed((uint32)(MFSystem_ReadRTC() & 0xFFFFFFFF));

	MFSystem_RegisterSystemCallback(MFCB_InitDone, Game_Init);
	MFSystem_RegisterSystemCallback(MFCB_Update, Game_Update);
	MFSystem_RegisterSystemCallback(MFCB_Draw, Game_Draw);
	MFSystem_RegisterSystemCallback(MFCB_Deinit, Game_Deinit);

	pInitFujiFS = MFSystem_RegisterSystemCallback(MFCB_FileSystemInit, Game_InitFilesystem);

	return MFMain(pInitParams);
}
Example #5
0
void Timer::Update()
{
    if(!(flags&Timer_Paused))
    {
        if(fixed)
        {
            lastCall = thisCall;
            thisCall = MFSystem_ReadRTC();

            lastUpdate = accumulator;
            accumulator += freq/fixedFPS;
        }
        else
        {
            lastCall = thisCall;
            thisCall = MFSystem_ReadRTC();

            lastUpdate = accumulator;
            accumulator += (uint64)((thisCall-lastCall)*rate);
        }

        deltaD = (double)(accumulator-lastUpdate)/freq;
        deltaF = (float)deltaD;
        smoothDeltaF = deltaF*RCP_60F + smoothDeltaF*RCP_60F*59.0f;

        if(1)
        {
            double newFPS = 1.0/((double)(thisCall-lastCall)/freq);

            FPS = newFPS*RCP_60 + FPS*RCP_60*59.0;
        }
        else
        {
            FPS = 1.0/((double)(thisCall-lastCall)/freq);
        }
    }
}
Example #6
0
MFCall::~MFCall()
{
#if defined(_MFCALLSTACK_PROFILING)
    if(pFunction)
    {
        uint64 endTime = MFSystem_ReadRTC();
        pFunction->totalTime += endTime - startTime;

        if(pCall)
            pCall->endTime = endTime;
    }
#endif

    --gCallDepth;
}
Example #7
0
void MFCallstack_EndFrame()
{
    MFCALLSTACK;

    // mark the end of the frame
    gEndTime = MFSystem_ReadRTC();

    // take a copy and reset everything
    for(int a=0; a<gNumProfileFunctions; ++a)
    {
        // reset the function
        gpProfiles[a]->totalTime = 0;
        gpProfiles[a]->numCalls = 0;
        gpProfiles[a]->bAdded = false;
    }

    gNumProfileFunctions = 0;
}
Example #8
0
int GameMain(MFInitParams *pInitParams)
{
	MFRand_Seed((uint32)(MFSystem_ReadRTC() & 0xFFFFFFFF));

	Fuji_CreateEngineInstance();

	MFSystem_RegisterSystemCallback(MFCB_InitDone, Game_Init);
	MFSystem_RegisterSystemCallback(MFCB_Update, Game_Update);
	MFSystem_RegisterSystemCallback(MFCB_Draw, Game_Draw);
	MFSystem_RegisterSystemCallback(MFCB_Deinit, Game_Deinit);

	pInitFujiFS = MFSystem_RegisterSystemCallback(MFCB_FileSystemInit, Game_InitFilesystem);

	int r = MFMain(pInitParams);

	Fuji_DestroyEngineInstance();

	return r;
}
Example #9
0
void Timer::Init(Timer *pRefTimer)
{
    accumulator = 0;
    lastUpdate = 0;

    thisCall = lastCall = MFSystem_ReadRTC();
    freq = MFSystem_GetRTCFrequency();

    FPS = 60.0;

    deltaD = 1.0/60.0;
    deltaF = 1.0f/60.0f;
    smoothDeltaF = 1.0f/60.0f;

    rate = 1.0f;

    fixed = false;

    pReferenceTimer = pRefTimer;
}
Example #10
0
void Timer::Pause(bool pause)
{
    if(pause)
    {
        MFFLAG(flags, Timer_Paused);

        deltaD = 0.0;
        deltaF = 0.0f;
        smoothDeltaF = 0.0f;
        FPS = 0.0;
    }
    else
    {
        MFUNFLAG(flags, Timer_Paused);
        thisCall = MFSystem_ReadRTC();

        smoothDeltaF = 1.0f/60.0f;
        FPS = 60.0;
    }
}
Example #11
0
MFCall::MFCall(const char *pFunctionName, MFCallstack_Function *_pFunction)
{
    pCallstack[gCallDepth] = pFunctionName;
    ++gCallDepth;

#if defined(_MFCALLSTACK_PROFILING)
    if(_pFunction && gNumProfileFunctions < gMaxProfileFunctions)
    {
        pFunction = _pFunction;

        if(!_pFunction->bAdded)
        {
            gpProfiles[gNumProfileFunctions] = _pFunction;
            ++gNumProfileFunctions;
        }

        ++_pFunction->numCalls;
        _pFunction->bAdded = true;

        startTime = MFSystem_ReadRTC();

        if(0)//gNumFunctionCalls < gMaxProfileFunctions)
        {
            pCall = &gCalls[gNumFunctionCalls];
            ++gNumFunctionCalls;

            pCall->pFunction = _pFunction;
            pCall->startTime = startTime;
        }
        else
            pCall = NULL;
    }
    else
        pFunction = NULL;
#endif
}
Example #12
0
bool MFModule_InitModules()
{
	uint64 timer = 0;

	for(int a=0; a<gNumModules; ++a)
	{
		uint64 bit = 1ULL << a;

		if(!(gModuleInitComplete & bit) && (gModuleInitComplete & gModules[a].prerequisites) == gModules[a].prerequisites)
		{
			MFInitStatus complete = MFAIC_Failed;
			if((gModules[a].prerequisites & gModuleInitFailed) == 0)
			{
				MFDebug_Message(MFStr("Init %s...", gModules[a].pModuleName));

				timer = MFSystem_ReadRTC();
				complete = gModules[a].pInitFunction();
			}
			else
			{
				// list pre-requisite failures
				if(MFModule_IsModuleInitialised(MFModule_GetBuiltinModuleID(MFBIM_MFString)))
				{
					MFDebug_Message(MFStr("Prerequisite failure"));
				}
			}

			if(complete == MFAIC_Succeeded)
			{
				uint64 initTime = (MFSystem_ReadRTC() - timer) * 1000 / MFSystem_GetRTCFrequency();

				gModuleInitComplete |= bit;

				// if logging is initialised
				MFDebug_Message(MFStr("Init %s complete in %dms", gModules[a].pModuleName, (int)initTime));
			}
			else if(complete == MFAIC_Failed)
			{
				uint64 initTime = (MFSystem_ReadRTC() - timer) * 1000 / MFSystem_GetRTCFrequency();

				gModuleInitComplete |= bit;
				gModuleInitFailed |= bit;

				// if logging is initialised
				MFDebug_Error(MFStr("Init %s FAILED in %dms!", gModules[a].pModuleName, (int)initTime));
			}
		}
	}

	if(gModuleInitComplete == (1ULL << gNumModules) - 1)
	{
		gFujiInitialised = true;

		if(gModuleInitFailed)
		{
			MFDebug_Message("Fuji initialisation completed with errors...");

			// list the failed modules
			//...
		}
		else
		{
			MFDebug_Message("Fuji initialisation complete!");
		}

		MFHeap_Mark();

		// let the game perform any post-init work
		if(pSystemCallbacks[MFCB_InitDone])
			pSystemCallbacks[MFCB_InitDone]();

		// init the timedelta to the moment after initialisation completes
		MFSystem_UpdateTimeDelta();
		return true;
	}

	return false;
}
Example #13
0
void Editor::UpdateInput()
{
	GHScreen::UpdateInput();

	// check for main menu
	if(TestControl(dBCtrl_Edit_Menu, GHCT_Once))
		gMenu.Push();

	if(TestControl(dBCtrl_Edit_PopupMenu, GHCT_Once))
		ShowPopupMenu();

	// check for section jump
	if(TestControl(dBCtrl_Edit_Goto, GHCT_Once))
		gpStringBox->Show(MFTranslation_GetString(pStrings, MENU_GOTO), "", GotoSection);

	// update the editor.
	UpdateEditor();

	// enable/disable half time
	if(TestControl(dBCtrl_Edit_PlaybackRate, GHCT_Once))
	{
		bHalfSpeed.data = (bHalfSpeed.data + 1) % (int)(sizeof(gSpeeds) / sizeof(gSpeeds[0]));

		if(gEditor.pSong->pStream)
			MFSound_SetPlaybackRate(MFSound_GetStreamVoice(gEditor.pSong->pStream), gSpeeds[bHalfSpeed]);
		if(gEditor.pSong->pGuitar)
			MFSound_SetPlaybackRate(MFSound_GetStreamVoice(gEditor.pSong->pGuitar), gSpeeds[bHalfSpeed]);
		if(gEditor.pSong->pBass)
			MFSound_SetPlaybackRate(MFSound_GetStreamVoice(gEditor.pSong->pBass), gSpeeds[bHalfSpeed]);
	}

	// swap modes
	if(TestControl(dBCtrl_Edit_StartPlayback, GHCT_Once) || TestControl(dBCtrl_Edit_RestartPlayback, GHCT_Once))
	{
		gEditor.state = GHPS_Playing;

		gEditor.pSong->CalculateNoteTimes(gEditor.currentStream[0], 0);
		if(gEditor.currentStream[1] != -1)
			gEditor.pSong->CalculateNoteTimes(gEditor.currentStream[1], 0);

		if(TestControl(dBCtrl_Edit_RestartPlayback, GHCT_Once))
		{
			gEditor.playbackStartOffset = 0;
			gEditor.playingTime = 0;
		}
		else
		{
			gEditor.playbackStartOffset = gEditor.offset;
			gEditor.playingTime = gEditor.pSong->CalculateTimeOfTick(gEditor.offset);
		}

		gEditor.pSong->Play(gEditor.playingTime);

		gPlay.scoreKeeper[0].Begin(gEditor.pSong, (GHStreams)gEditor.currentStream[0], 0, gEditor.playingTime);
		if(gEditor.currentStream[1] != -1)
			gPlay.scoreKeeper[1].Begin(gEditor.pSong, (GHStreams)gEditor.currentStream[1], 1, gEditor.playingTime);

		if(gEditor.pSong->pStream || gEditor.pSong->pGuitar || gEditor.pSong->pBass)
		{
			gEditor.playStart = 0;
			gEditor.lastTimestamp = 0;
		}
		else
		{
			gEditor.playStart = MFSystem_ReadRTC();
		}
		gEditor.startTime = gEditor.playingTime;

		bSelecting = false;

		Pop();
		gPlay.Push();
	}
}