2009-08-07 16:03:57 +00:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
2009-08-08 01:39:56 +00:00
|
|
|
#include "OnFrame.h"
|
|
|
|
|
2009-08-07 16:03:57 +00:00
|
|
|
#include "Core.h"
|
|
|
|
#include "PluginManager.h"
|
2009-08-08 05:47:08 +00:00
|
|
|
#include "Thread.h"
|
2009-08-20 23:31:48 +00:00
|
|
|
#include "FileUtil.h"
|
2009-08-08 05:47:08 +00:00
|
|
|
|
|
|
|
Common::CriticalSection cs_frameSkip;
|
2009-08-07 16:03:57 +00:00
|
|
|
|
|
|
|
namespace Frame {
|
|
|
|
|
|
|
|
bool g_bFrameStep = false;
|
|
|
|
bool g_bAutoFire = false;
|
|
|
|
u32 g_autoFirstKey = 0, g_autoSecondKey = 0;
|
|
|
|
bool g_bFirstKey = true;
|
2009-08-20 23:31:48 +00:00
|
|
|
PlayMode g_playMode = MODE_NONE;
|
2009-08-07 16:03:57 +00:00
|
|
|
|
2009-08-08 05:47:08 +00:00
|
|
|
int g_framesToSkip = 0, g_frameSkipCounter = 0;
|
2009-08-08 01:39:56 +00:00
|
|
|
|
2009-08-20 23:31:48 +00:00
|
|
|
int g_numPads = 0;
|
|
|
|
ControllerState *g_padStates;
|
|
|
|
FILE *g_recordfd = NULL;
|
|
|
|
|
|
|
|
u64 g_frameCounter = 0;
|
|
|
|
|
2009-08-07 16:03:57 +00:00
|
|
|
void FrameUpdate() {
|
2009-08-12 16:42:51 +00:00
|
|
|
|
2009-08-20 23:31:48 +00:00
|
|
|
g_frameCounter++;
|
2009-08-12 16:42:51 +00:00
|
|
|
|
2009-08-08 05:47:08 +00:00
|
|
|
if (g_bFrameStep)
|
2009-08-07 16:03:57 +00:00
|
|
|
Core::SetState(Core::CORE_PAUSE);
|
|
|
|
|
2009-08-12 16:42:51 +00:00
|
|
|
FrameSkipping();
|
|
|
|
|
2009-08-08 05:47:08 +00:00
|
|
|
if (g_bAutoFire)
|
2009-08-07 16:03:57 +00:00
|
|
|
g_bFirstKey = !g_bFirstKey;
|
2009-08-08 01:39:56 +00:00
|
|
|
|
2009-08-20 23:31:48 +00:00
|
|
|
if(IsRecordingInput()) {
|
|
|
|
|
|
|
|
// Dump all controllers' states for this frame
|
|
|
|
fwrite(g_padStates, sizeof(ControllerState), g_numPads, g_recordfd);
|
|
|
|
|
|
|
|
} else if(IsPlayingInput()) {
|
|
|
|
// TODO
|
|
|
|
}
|
2009-08-08 01:39:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetFrameSkipping(unsigned int framesToSkip) {
|
2009-08-08 05:47:08 +00:00
|
|
|
cs_frameSkip.Enter();
|
|
|
|
|
2009-08-08 01:39:56 +00:00
|
|
|
g_framesToSkip = (int)framesToSkip;
|
|
|
|
g_frameSkipCounter = 0;
|
2009-08-08 05:47:08 +00:00
|
|
|
|
|
|
|
cs_frameSkip.Leave();
|
2009-08-08 01:39:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int FrameSkippingFactor() {
|
|
|
|
return g_framesToSkip;
|
2009-08-07 16:03:57 +00:00
|
|
|
}
|
|
|
|
|
2009-08-08 05:47:08 +00:00
|
|
|
void SetAutoHold(bool bEnabled, u32 keyToHold)
|
|
|
|
{
|
2009-08-07 16:03:57 +00:00
|
|
|
g_bAutoFire = bEnabled;
|
2009-08-08 05:47:08 +00:00
|
|
|
if (bEnabled)
|
2009-08-07 16:03:57 +00:00
|
|
|
g_autoFirstKey = g_autoSecondKey = keyToHold;
|
|
|
|
else
|
|
|
|
g_autoFirstKey = g_autoSecondKey = 0;
|
|
|
|
}
|
|
|
|
|
2009-08-08 05:47:08 +00:00
|
|
|
void SetAutoFire(bool bEnabled, u32 keyOne, u32 keyTwo)
|
|
|
|
{
|
2009-08-07 16:03:57 +00:00
|
|
|
g_bAutoFire = bEnabled;
|
2009-08-08 05:47:08 +00:00
|
|
|
if (bEnabled) {
|
2009-08-07 16:03:57 +00:00
|
|
|
g_autoFirstKey = keyOne;
|
|
|
|
g_autoSecondKey = keyTwo;
|
|
|
|
} else
|
|
|
|
g_autoFirstKey = g_autoSecondKey = 0;
|
|
|
|
|
|
|
|
g_bFirstKey = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsAutoFiring() {
|
|
|
|
return g_bAutoFire;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetFrameStepping(bool bEnabled) {
|
|
|
|
g_bFrameStep = bEnabled;
|
|
|
|
}
|
|
|
|
|
2009-08-20 23:31:48 +00:00
|
|
|
void ModifyController(SPADStatus *PadStatus, int controllerID)
|
2009-08-08 05:47:08 +00:00
|
|
|
{
|
2009-08-20 23:31:48 +00:00
|
|
|
if(controllerID < 0)
|
|
|
|
return;
|
|
|
|
|
2009-08-07 16:03:57 +00:00
|
|
|
u32 keyToPress = (g_bFirstKey) ? g_autoFirstKey : g_autoSecondKey;
|
|
|
|
|
2009-08-08 05:47:08 +00:00
|
|
|
if (!keyToPress)
|
2009-08-07 16:03:57 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
PadStatus->button |= keyToPress;
|
|
|
|
|
|
|
|
switch(keyToPress) {
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
|
|
|
|
case PAD_BUTTON_A:
|
|
|
|
PadStatus->analogA = 255;
|
|
|
|
break;
|
|
|
|
case PAD_BUTTON_B:
|
|
|
|
PadStatus->analogB = 255;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PAD_TRIGGER_L:
|
|
|
|
PadStatus->triggerLeft = 255;
|
|
|
|
break;
|
|
|
|
case PAD_TRIGGER_R:
|
|
|
|
PadStatus->triggerRight = 255;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-08-08 05:47:08 +00:00
|
|
|
void FrameSkipping()
|
|
|
|
{
|
|
|
|
cs_frameSkip.Enter();
|
|
|
|
|
2009-08-08 01:39:56 +00:00
|
|
|
g_frameSkipCounter++;
|
2009-08-12 16:42:51 +00:00
|
|
|
if (g_frameSkipCounter > g_framesToSkip || Core::report_slow(g_frameSkipCounter) == false)
|
2009-08-08 01:39:56 +00:00
|
|
|
g_frameSkipCounter = 0;
|
|
|
|
|
|
|
|
CPluginManager::GetInstance().GetVideo()->Video_SetRendering(!g_frameSkipCounter);
|
2009-08-08 05:47:08 +00:00
|
|
|
|
|
|
|
cs_frameSkip.Leave();
|
2009-08-08 01:39:56 +00:00
|
|
|
}
|
|
|
|
|
2009-08-20 23:31:48 +00:00
|
|
|
bool IsRecordingInput()
|
|
|
|
{
|
|
|
|
return (g_playMode == MODE_RECORDING);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsPlayingInput()
|
|
|
|
{
|
|
|
|
return (g_playMode == MODE_PLAYING);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Add BeginRecordingFromSavestate
|
|
|
|
void BeginRecordingInput(const char *filename, int controllers)
|
|
|
|
{
|
|
|
|
if(!filename || g_playMode != MODE_NONE || g_recordfd)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(File::Exists(filename))
|
|
|
|
File::Delete(filename);
|
|
|
|
|
|
|
|
g_recordfd = fopen(filename, "wb+");
|
|
|
|
if(!g_recordfd) {
|
|
|
|
PanicAlert("Error opening file %s for recording", filename);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write initial empty header
|
|
|
|
DTMHeader dummy;
|
|
|
|
fwrite(&dummy, sizeof(DTMHeader), 1, g_recordfd);
|
|
|
|
|
|
|
|
g_numPads = controllers;
|
|
|
|
g_padStates = new ControllerState[controllers];
|
|
|
|
|
|
|
|
g_frameCounter = 0;
|
|
|
|
|
|
|
|
g_playMode = MODE_RECORDING;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EndRecordingInput()
|
|
|
|
{
|
|
|
|
rewind(g_recordfd);
|
|
|
|
|
|
|
|
// Create the real header now and write it
|
|
|
|
DTMHeader header;
|
|
|
|
memset(&header, 0, sizeof(DTMHeader));
|
|
|
|
|
|
|
|
header.bWii = Core::g_CoreStartupParameter.bWii;
|
|
|
|
strncpy((char *)header.gameID, Core::g_CoreStartupParameter.GetUniqueID().c_str(), 6);
|
|
|
|
header.numControllers = g_numPads;
|
|
|
|
|
|
|
|
header.bFromSaveState = false; // TODO: add the case where it's true
|
|
|
|
header.frameCount = g_frameCounter;
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
header.lagCount = 0;
|
|
|
|
header.uniqueID = 0;
|
|
|
|
header.numRerecords = 0;
|
|
|
|
header.author;
|
|
|
|
header.videoPlugin;
|
|
|
|
header.audioPlugin;
|
|
|
|
header.padPlugin;
|
|
|
|
|
|
|
|
|
|
|
|
fwrite(&header, sizeof(DTMHeader), 1, g_recordfd);
|
|
|
|
|
|
|
|
fclose(g_recordfd);
|
|
|
|
g_recordfd = NULL;
|
|
|
|
|
|
|
|
delete[] g_padStates;
|
|
|
|
|
|
|
|
g_playMode = MODE_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RecordInput(SPADStatus *PadStatus, int controllerID)
|
|
|
|
{
|
|
|
|
if(!IsRecordingInput() || controllerID >= g_numPads || controllerID < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_padStates[controllerID].A = ((PadStatus->button & PAD_BUTTON_A) != 0);
|
|
|
|
g_padStates[controllerID].B = ((PadStatus->button & PAD_BUTTON_B) != 0);
|
|
|
|
g_padStates[controllerID].X = ((PadStatus->button & PAD_BUTTON_X) != 0);
|
|
|
|
g_padStates[controllerID].Y = ((PadStatus->button & PAD_BUTTON_Y) != 0);
|
|
|
|
g_padStates[controllerID].Z = ((PadStatus->button & PAD_TRIGGER_Z) != 0);
|
|
|
|
g_padStates[controllerID].Start = ((PadStatus->button & PAD_BUTTON_START) != 0);
|
|
|
|
|
|
|
|
g_padStates[controllerID].DPadUp = ((PadStatus->button & PAD_BUTTON_UP) != 0);
|
|
|
|
g_padStates[controllerID].DPadDown = ((PadStatus->button & PAD_BUTTON_DOWN) != 0);
|
|
|
|
g_padStates[controllerID].DPadLeft = ((PadStatus->button & PAD_BUTTON_LEFT) != 0);
|
|
|
|
g_padStates[controllerID].DPadRight = ((PadStatus->button & PAD_BUTTON_RIGHT) != 0);
|
|
|
|
|
|
|
|
g_padStates[controllerID].L = PadStatus->triggerLeft;
|
|
|
|
g_padStates[controllerID].R = PadStatus->triggerRight;
|
|
|
|
|
|
|
|
g_padStates[controllerID].AnalogStickX = PadStatus->stickX;
|
|
|
|
g_padStates[controllerID].AnalogStickY = PadStatus->stickY;
|
|
|
|
|
|
|
|
g_padStates[controllerID].CStickX = PadStatus->substickX;
|
|
|
|
g_padStates[controllerID].CStickY = PadStatus->substickY;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayInput(const char *filename)
|
|
|
|
{
|
|
|
|
// TODO: Implement
|
|
|
|
// TODO: Add the play from savestate case
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayController(SPADStatus *PadStatus, int controllerID)
|
|
|
|
{
|
|
|
|
// TODO: Implement
|
|
|
|
if(!IsPlayingInput() || controllerID >= g_numPads || controllerID < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-08-07 16:03:57 +00:00
|
|
|
};
|