diff options
| author | ayuanx <ayuanx@gmail.com> | 2010-02-03 02:54:31 +0000 |
|---|---|---|
| committer | ayuanx <ayuanx@gmail.com> | 2010-02-03 02:54:31 +0000 |
| commit | fb4f0edb85823deebaa63dcd6b8389fc1e800984 (patch) | |
| tree | d7aad7db20a00bb48c8388cbe92842be0f940b5c /Source/Plugins/Plugin_nJoy_SDL/Src/ReRecording.cpp | |
| parent | e17c872d8f6f81aeac79076faa6a55d1f9b05e78 (diff) | |
Falcon4ever prefers to keep a standalone code copy of nJoy in repository.
Nakee, please make a branch/tag after release so that the code of nJoy will be saved as a standalone plugin
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4998 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Plugins/Plugin_nJoy_SDL/Src/ReRecording.cpp')
| -rw-r--r-- | Source/Plugins/Plugin_nJoy_SDL/Src/ReRecording.cpp | 196 |
1 files changed, 196 insertions, 0 deletions
diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/ReRecording.cpp b/Source/Plugins/Plugin_nJoy_SDL/Src/ReRecording.cpp new file mode 100644 index 0000000000..6a2bfeea1e --- /dev/null +++ b/Source/Plugins/Plugin_nJoy_SDL/Src/ReRecording.cpp @@ -0,0 +1,196 @@ +
+// Project description
+// -------------------
+// Name: nJoy
+// Description: A Dolphin Compatible Input Plugin
+//
+// Author: Falcon4ever (nJoy@falcon4ever.com)
+// Site: www.multigesture.net
+// Copyright (C) 2003 Dolphin Project.
+//
+
+//
+// Licensetype: GNU General Public License (GPL)
+//
+// 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/
+//
+
+
+
+
+// File description
+/* ---------
+
+Rerecording options
+
+////////////////////////*/
+
+
+
+// Include
+// ---------
+#include "nJoy.h"
+#include "FileUtil.h"
+#include "ChunkFile.h"
+
+// TODO :
+// This is pretty much useless now with the TAS features right ?
+
+#ifdef RERECORDING
+
+
+namespace Recording
+{
+
+
+
+// Definitions
+// -------------
+// Pre defined maxium storage limit
+#define RECORD_SIZE (1024 * 128)
+SPADStatus RecordBuffer[RECORD_SIZE];
+int count = 0;
+
+
+
+
+
+// Recording functions
+// -------------
+void RecordInput(const SPADStatus& _rPADStatus)
+{
+ if (count >= RECORD_SIZE) return;
+ RecordBuffer[count++] = _rPADStatus;
+
+ // Logging
+ //u8 TmpData[sizeof(SPADStatus)];
+ //memcpy(TmpData, &RecordBuffer[count - 1], sizeof(SPADStatus));
+ //Console::Print("RecordInput(%i): %s\n", count, ArrayToString(TmpData, sizeof(SPADStatus), 0, 30).c_str());
+
+ // Auto save every ten seconds
+ if (count % (60 * 10) == 0) Save();
+}
+
+const SPADStatus& Play()
+{
+ // Logging
+ //Console::Print("PlayRecord(%i)\n", count);
+ if (count >= RECORD_SIZE)
+ {
+ // Todo: Make the recording size unlimited?
+ //PanicAlert("The recording reached its end");
+ return(RecordBuffer[0]);
+ }
+ return(RecordBuffer[count++]);
+}
+
+void Load()
+{
+ FILE* pStream = fopen("pad-record.bin", "rb");
+
+ if (pStream != NULL)
+ {
+ fread(RecordBuffer, 1, RECORD_SIZE * sizeof(SPADStatus), pStream);
+ fclose(pStream);
+ }
+ else
+ {
+ PanicAlert("SimplePad: Could not open pad-record.bin");
+ }
+
+ //Console::Print("LoadRecord()");
+}
+
+void Save()
+{
+ // Open the file in a way that clears all old data
+ FILE* pStream = fopen("pad-record.bin", "wb");
+
+ if (pStream != NULL)
+ {
+ fwrite(RecordBuffer, 1, RECORD_SIZE * sizeof(SPADStatus), pStream);
+ fclose(pStream);
+ }
+ else
+ {
+ PanicAlert("NJoy: Could not save pad-record.bin");
+ }
+ //PanicAlert("SaveRecord()");
+ //Console::Print("SaveRecord()");
+}
+
+
+
+
+void Initialize()
+{
+ // -------------------------------------------
+ // Rerecording
+ // ----------------------
+ #ifdef RERECORDING
+ /* Check if we are starting the pad to record the input, and an old file exists. In that case ask
+ if we really want to start the recording and eventually overwrite the file */
+ if (g_Config.bRecording && File::Exists("pad-record.bin"))
+ {
+ if (!AskYesNo("An old version of '%s' aleady exists in your Dolphin directory. You can"
+ " now make a copy of it before you start a new recording and overwrite the file."
+ " Select Yes to continue and overwrite the file. Select No to turn off the input"
+ " recording and continue without recording anything.",
+ "pad-record.bin"))
+ {
+ // Turn off recording and continue
+ g_Config.bRecording = false;
+ }
+ }
+
+ // Load recorded input if we are to play it back, otherwise begin with a blank recording
+ if (g_Config.bPlayback) Recording::Load();
+ #endif
+ // ----------------------
+}
+
+
+void ShutDown()
+{
+ // Save recording
+ if (g_Config.bRecording) Recording::Save();
+ // Reset the counter
+ count = 0;
+}
+
+void DoState(unsigned char **ptr, int mode)
+{
+ // Load or save the counter
+ PointerWrap p(ptr, mode);
+ p.Do(count);
+
+ //Console::Print("count: %i\n", count);
+
+ // Update the frame counter for the sake of the status bar
+ if (mode == PointerWrap::MODE_READ)
+ {
+ #ifdef _WIN32
+ // This only works when rendering to the main window, I think
+ PostMessage(GetParent(g_PADInitialize->hWnd), WM_USER, INPUT_FRAME_COUNTER, count);
+ #endif
+ }
+}
+
+
+} // Recording
+
+
+#endif // RERECORDING
\ No newline at end of file |
