From ce044f37007365f231a0d74fb2fa8f5c2012fcd1 Mon Sep 17 00:00:00 2001
From: zeromus <zeromus@users.noreply.github.com>
Date: Fri, 6 Jan 2017 16:53:46 -0600
Subject: [PATCH] remove rewind code completely (it wasnt hooked up to the UI
 and it was worthless anyway)

---
 desmume/src/frontend/windows/hotkey.cpp | 14 ------
 desmume/src/frontend/windows/hotkey.h   |  2 -
 desmume/src/frontend/windows/main.cpp   | 17 -------
 desmume/src/frontend/windows/resource.h |  1 -
 desmume/src/saves.cpp                   | 63 -------------------------
 desmume/src/saves.h                     |  3 --
 6 files changed, 100 deletions(-)

diff --git a/desmume/src/frontend/windows/hotkey.cpp b/desmume/src/frontend/windows/hotkey.cpp
index 7c61f0da0..a8227ab6b 100644
--- a/desmume/src/frontend/windows/hotkey.cpp
+++ b/desmume/src/frontend/windows/hotkey.cpp
@@ -384,12 +384,6 @@ void HK_PlayMovie(int, bool justPressed)
 		Replay_LoadMovie();
 }
 
-bool rewinding = false;
-
-void HK_RewindKeyDown(int, bool justPressed) {rewinding = true;}
-
-void HK_RewindKeyUp(int){rewinding = false;}
-
 void HK_RecordMovie(int, bool justPressed) 
 {
 	if (romloaded)
@@ -817,14 +811,6 @@ void InitCustomKeys (SCustomKeys *keys)
 	keys->TurboStart.page = HOTKEY_PAGE_TURBO;
 	keys->TurboStart.key = NULL;
 
-	// Movie/Tools page -----------------------------------------
-	keys->Rewind.handleKeyDown = HK_RewindKeyDown;
-	keys->Rewind.handleKeyUp = HK_RewindKeyUp;
-	keys->Rewind.code = "Rewind";
-	keys->Rewind.name = STRW(ID_LABEL_HK25);
-	keys->Rewind.page = HOTKEY_PAGE_MOVIE;
-	keys->Rewind.key = NULL;
-
 	keys->NewLuaScript.handleKeyDown = HK_NewLuaScriptDown;
 	keys->NewLuaScript.code = "NewLuaScript";
 	keys->NewLuaScript.name = STRW(ID_LABEL_HK26);
diff --git a/desmume/src/frontend/windows/hotkey.h b/desmume/src/frontend/windows/hotkey.h
index 6c46ab99b..102987ae3 100644
--- a/desmume/src/frontend/windows/hotkey.h
+++ b/desmume/src/frontend/windows/hotkey.h
@@ -92,8 +92,6 @@ struct SCustomKeys
 
 	SCustomKey RecordWAV, RecordAVI;
 
-	SCustomKey Rewind;
-
 	SCustomKey NewLuaScript, CloseLuaScripts, MostRecentLuaScript;
 
 	SCustomKey ToggleFrameCounter;
diff --git a/desmume/src/frontend/windows/main.cpp b/desmume/src/frontend/windows/main.cpp
index f9f90e32c..639cec4d5 100644
--- a/desmume/src/frontend/windows/main.cpp
+++ b/desmume/src/frontend/windows/main.cpp
@@ -513,7 +513,6 @@ int lastskiprate=0;
 int emu_paused = 0;
 bool frameAdvance = false;
 bool continuousframeAdvancing = false;
-bool staterewindingenabled = false;
 
 unsigned short windowSize = 0;
 
@@ -2187,16 +2186,6 @@ static void StepRunLoop_Core()
 	inFrameBoundary = true;
 	DRV_AviVideoUpdate();
 
-	extern bool rewinding;
-
-	if (staterewindingenabled) {
-
-		if(rewinding)
-			dorewind();
-		else
-			rewindsave();
-	}
-
 	CallRegisteredLuaFunctions(LUACALL_AFTEREMULATION);
 	ServiceDisplayThreadInvocations();
 }
@@ -4579,8 +4568,6 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
 			MainWindow->checkMenu(IDM_RENDER_4XBRZ, video.currentfilter == video._4XBRZ );
 			MainWindow->checkMenu(IDM_RENDER_5XBRZ, video.currentfilter == video._5XBRZ );
 
-			MainWindow->checkMenu(IDC_STATEREWINDING, staterewindingenabled == 1 );
-
 			MainWindow->checkMenu(ID_DISPLAYMETHOD_VSYNC, (GetStyle()&DWS_VSYNC)!=0);
 			MainWindow->checkMenu(ID_DISPLAYMETHOD_DIRECTDRAWHW, (GetStyle()&DWS_DDRAW_HW)!=0);
 			MainWindow->checkMenu(ID_DISPLAYMETHOD_DIRECTDRAWSW, (GetStyle()&DWS_DDRAW_SW)!=0);
@@ -5301,10 +5288,6 @@ DOKEYDOWN:
 				WavRecordTo(WAVMODE_USER);
 			break;
 #endif
-		case IDC_STATEREWINDING:
-			if(staterewindingenabled) staterewindingenabled = false;
-			else staterewindingenabled = true;
-			break;
 		case IDM_RENDER_NORMAL:
 			{
 				Lock lock (win_backbuffer_sync);
diff --git a/desmume/src/frontend/windows/resource.h b/desmume/src/frontend/windows/resource.h
index e28210c3f..52e163ce0 100644
--- a/desmume/src/frontend/windows/resource.h
+++ b/desmume/src/frontend/windows/resource.h
@@ -152,7 +152,6 @@
 #define IDC_BROWSELUA                   365
 #define IDD_PATHSETTINGS                366
 #define IDC_ASSOCIATE                   367
-#define IDC_STATEREWINDING              367
 #define IDC_CLOSE_LUA_SCRIPTS           368
 #define IDC_DES_BOX                     402
 #define IDC_R0                          403
diff --git a/desmume/src/saves.cpp b/desmume/src/saves.cpp
index 0d1a35511..060705a51 100644
--- a/desmume/src/saves.cpp
+++ b/desmume/src/saves.cpp
@@ -1301,66 +1301,3 @@ bool savestate_load(const char *file_name)
 
 	return savestate_load(&f);
 }
-
-static std::stack<EMUFILE_MEMORY*> rewindFreeList;
-static std::vector<EMUFILE_MEMORY*> rewindbuffer;
-
-int rewindstates = 16;
-int rewindinterval = 4;
-
-void rewindsave () {
-
-	if(currFrameCounter % rewindinterval)
-		return;
-
-	//printf("rewindsave"); printf("%d%s", currFrameCounter, "\n");
-
-	
-	EMUFILE_MEMORY *ms;
-	if(!rewindFreeList.empty()) {
-		ms = rewindFreeList.top();
-		rewindFreeList.pop();
-	} else {
-		ms = new EMUFILE_MEMORY(1024*1024*12);
-	}
-
-	if(!savestate_save(ms, Z_NO_COMPRESSION))
-		return;
-
-	rewindbuffer.push_back(ms);
-	
-	if((int)rewindbuffer.size() > rewindstates) {
-		delete *rewindbuffer.begin();
-		rewindbuffer.erase(rewindbuffer.begin());
-	}
-}
-
-void dorewind()
-{
-	if(currFrameCounter % rewindinterval)
-		return;
-
-	//printf("rewind\n");
-
-	int size = rewindbuffer.size();
-
-	if(size < 1) {
-		printf("rewind buffer empty\n");
-		return;
-	}
-
-	printf("%d", size);
-
-	EMUFILE_MEMORY* loadms = rewindbuffer[size-1];
-	loadms->fseek(32, SEEK_SET);
-
-	ReadStateChunks(loadms,loadms->size()-32);
-	loadstate();
-
-	if(rewindbuffer.size()>1)
-	{
-		rewindFreeList.push(loadms);
-		rewindbuffer.pop_back();
-	}
-
-}
diff --git a/desmume/src/saves.h b/desmume/src/saves.h
index 47e518ee9..6ffca5247 100644
--- a/desmume/src/saves.h
+++ b/desmume/src/saves.h
@@ -66,7 +66,4 @@ void loadstate_slot(int num);
 bool savestate_load(class EMUFILE* is);
 bool savestate_save(class EMUFILE* outstream, int compressionLevel);
 
-void dorewind();
-void rewindsave();
-
 #endif