mirror of
https://github.com/dborth/snes9xgx.git
synced 2024-11-27 21:14:21 +01:00
more stable threading, file IO corrections, inline video functions
This commit is contained in:
parent
0695e04b42
commit
911881421b
@ -481,30 +481,32 @@ LoadFile (char * rbuffer, char *filepath, u32 length, int method, bool silent)
|
||||
else
|
||||
{
|
||||
struct stat fileinfo;
|
||||
fstat(file->_file, &fileinfo);
|
||||
size = fileinfo.st_size;
|
||||
|
||||
memcpy (rbuffer, zipbuffer, readsize); // copy what we already read
|
||||
|
||||
u32 offset = readsize;
|
||||
u32 nextread = 0;
|
||||
while(offset < size)
|
||||
if(fstat(file->_file, &fileinfo) == 0)
|
||||
{
|
||||
if(size - offset > 1024*512) nextread = 1024*512;
|
||||
else nextread = size-offset;
|
||||
ShowProgress ("Loading...", offset, size);
|
||||
readsize = fread (rbuffer + offset, 1, nextread, file); // read in next chunk
|
||||
size = fileinfo.st_size;
|
||||
|
||||
if(readsize <= 0 || readsize > nextread)
|
||||
break; // read failure
|
||||
memcpy (rbuffer, zipbuffer, readsize); // copy what we already read
|
||||
|
||||
if(readsize > 0)
|
||||
offset += readsize;
|
||||
u32 offset = readsize;
|
||||
u32 nextread = 0;
|
||||
while(offset < size)
|
||||
{
|
||||
if(size - offset > 1024*512) nextread = 1024*512;
|
||||
else nextread = size-offset;
|
||||
ShowProgress ("Loading...", offset, size);
|
||||
readsize = fread (rbuffer + offset, 1, nextread, file); // read in next chunk
|
||||
|
||||
if(readsize <= 0 || readsize > nextread)
|
||||
break; // read failure
|
||||
|
||||
if(readsize > 0)
|
||||
offset += readsize;
|
||||
}
|
||||
CancelAction();
|
||||
|
||||
if(offset != size) // # bytes read doesn't match # expected
|
||||
size = 0;
|
||||
}
|
||||
CancelAction();
|
||||
|
||||
if(offset != size) // # bytes read doesn't match # expected
|
||||
size = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +57,8 @@ extern "C" {
|
||||
#include "gui/gui.h"
|
||||
#include "menu.h"
|
||||
|
||||
#define THREAD_SLEEP 100
|
||||
|
||||
#ifdef HW_RVL
|
||||
static GuiImageData * pointer[4];
|
||||
#endif
|
||||
@ -117,7 +119,7 @@ HaltGui()
|
||||
|
||||
// wait for thread to finish
|
||||
while(!LWP_ThreadIsSuspended(guithread))
|
||||
usleep(50);
|
||||
usleep(THREAD_SLEEP);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -212,7 +214,7 @@ WindowPrompt(const char *title, const char *msg, const char *btn1Label, const ch
|
||||
|
||||
while(choice == -1)
|
||||
{
|
||||
VIDEO_WaitVSync();
|
||||
usleep(THREAD_SLEEP);
|
||||
|
||||
if(btn1.GetState() == STATE_CLICKED)
|
||||
choice = 1;
|
||||
@ -221,7 +223,7 @@ WindowPrompt(const char *title, const char *msg, const char *btn1Label, const ch
|
||||
}
|
||||
|
||||
promptWindow.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 50);
|
||||
while(promptWindow.GetEffect() > 0) usleep(50);
|
||||
while(promptWindow.GetEffect() > 0) usleep(THREAD_SLEEP);
|
||||
HaltGui();
|
||||
mainWindow->Remove(&promptWindow);
|
||||
mainWindow->SetState(STATE_DEFAULT);
|
||||
@ -322,6 +324,7 @@ UpdateGUI (void *arg)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
usleep(THREAD_SLEEP);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@ -411,7 +414,7 @@ ProgressWindow(char *title, char *msg)
|
||||
|
||||
while(showProgress)
|
||||
{
|
||||
VIDEO_WaitVSync();
|
||||
usleep(20000);
|
||||
|
||||
if(showProgress == 1)
|
||||
{
|
||||
@ -444,6 +447,7 @@ static void * ProgressThread (void *arg)
|
||||
LWP_SuspendThread (progressthread);
|
||||
|
||||
ProgressWindow(progressTitle, progressMsg);
|
||||
usleep(THREAD_SLEEP);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@ -474,7 +478,7 @@ CancelAction()
|
||||
|
||||
// wait for thread to finish
|
||||
while(!LWP_ThreadIsSuspended(progressthread))
|
||||
usleep(50);
|
||||
usleep(THREAD_SLEEP);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -629,7 +633,7 @@ static void OnScreenKeyboard(char * var, u32 maxlen)
|
||||
|
||||
while(save == -1)
|
||||
{
|
||||
VIDEO_WaitVSync();
|
||||
usleep(THREAD_SLEEP);
|
||||
|
||||
if(okBtn.GetState() == STATE_CLICKED)
|
||||
save = 1;
|
||||
@ -722,7 +726,7 @@ SettingWindow(const char * title, GuiWindow * w)
|
||||
|
||||
while(save == -1)
|
||||
{
|
||||
VIDEO_WaitVSync();
|
||||
usleep(THREAD_SLEEP);
|
||||
|
||||
if(okBtn.GetState() == STATE_CLICKED)
|
||||
save = 1;
|
||||
@ -857,6 +861,7 @@ static void WindowCredits(void * ptr)
|
||||
if(userInput[i].wpad.btns_d || userInput[i].pad.btns_d)
|
||||
exit = true;
|
||||
}
|
||||
usleep(THREAD_SLEEP);
|
||||
}
|
||||
|
||||
// clear buttons pressed
|
||||
@ -971,7 +976,7 @@ static int MenuGameSelection()
|
||||
|
||||
while(menu == MENU_NONE)
|
||||
{
|
||||
VIDEO_WaitVSync();
|
||||
usleep(THREAD_SLEEP);
|
||||
|
||||
// update gameWindow based on arrow buttons
|
||||
// set MENU_EXIT if A button pressed on a game
|
||||
@ -1340,7 +1345,7 @@ static int MenuGame()
|
||||
|
||||
while(menu == MENU_NONE)
|
||||
{
|
||||
VIDEO_WaitVSync();
|
||||
usleep(THREAD_SLEEP);
|
||||
|
||||
#ifdef HW_RVL
|
||||
int level;
|
||||
@ -1629,7 +1634,7 @@ static int MenuGameSaves(int action)
|
||||
|
||||
while(menu == MENU_NONE)
|
||||
{
|
||||
VIDEO_WaitVSync ();
|
||||
usleep(THREAD_SLEEP);
|
||||
|
||||
ret = saveBrowser.GetClickedSave();
|
||||
|
||||
@ -1876,7 +1881,7 @@ static int MenuGameSettings()
|
||||
|
||||
while(menu == MENU_NONE)
|
||||
{
|
||||
VIDEO_WaitVSync ();
|
||||
usleep(THREAD_SLEEP);
|
||||
|
||||
if(mappingBtn.GetState() == STATE_CLICKED)
|
||||
{
|
||||
@ -1990,7 +1995,7 @@ static int MenuGameCheats()
|
||||
|
||||
while(menu == MENU_NONE)
|
||||
{
|
||||
VIDEO_WaitVSync ();
|
||||
usleep(THREAD_SLEEP);
|
||||
|
||||
for(i=0; i < Cheat.num_cheats; i++)
|
||||
sprintf (options.value[i], "%s", Cheat.c[i].enabled == true ? "On" : "Off");
|
||||
@ -2139,7 +2144,7 @@ static int MenuSettingsMappings()
|
||||
|
||||
while(menu == MENU_NONE)
|
||||
{
|
||||
VIDEO_WaitVSync ();
|
||||
usleep(THREAD_SLEEP);
|
||||
|
||||
if(snesBtn.GetState() == STATE_CLICKED)
|
||||
{
|
||||
@ -2313,7 +2318,7 @@ static int MenuSettingsMappingsController()
|
||||
|
||||
while(menu == MENU_NONE)
|
||||
{
|
||||
VIDEO_WaitVSync ();
|
||||
usleep(THREAD_SLEEP);
|
||||
|
||||
if(wiimoteBtn.GetState() == STATE_CLICKED)
|
||||
{
|
||||
@ -2413,7 +2418,7 @@ ButtonMappingWindow()
|
||||
|
||||
while(pressed == 0)
|
||||
{
|
||||
VIDEO_WaitVSync();
|
||||
usleep(THREAD_SLEEP);
|
||||
|
||||
if(mapMenuCtrl == CTRLR_GCPAD)
|
||||
{
|
||||
@ -2572,7 +2577,7 @@ static int MenuSettingsMappingsMap()
|
||||
|
||||
while(menu == MENU_NONE)
|
||||
{
|
||||
VIDEO_WaitVSync ();
|
||||
usleep(THREAD_SLEEP);
|
||||
|
||||
for(i=0; i < options.length; i++)
|
||||
{
|
||||
@ -2878,7 +2883,7 @@ static int MenuSettingsVideo()
|
||||
|
||||
while(menu == MENU_NONE)
|
||||
{
|
||||
VIDEO_WaitVSync ();
|
||||
usleep(THREAD_SLEEP);
|
||||
|
||||
// don't allow original render mode if progressive video mode detected
|
||||
if (GCSettings.render==0 && progressive)
|
||||
@ -3092,7 +3097,7 @@ static int MenuSettings()
|
||||
|
||||
while(menu == MENU_NONE)
|
||||
{
|
||||
VIDEO_WaitVSync ();
|
||||
usleep(THREAD_SLEEP);
|
||||
|
||||
if(savingBtn.GetState() == STATE_CLICKED)
|
||||
{
|
||||
@ -3197,7 +3202,7 @@ static int MenuSettingsFile()
|
||||
|
||||
while(menu == MENU_NONE)
|
||||
{
|
||||
VIDEO_WaitVSync ();
|
||||
usleep(THREAD_SLEEP);
|
||||
|
||||
// some load/save methods are not implemented - here's where we skip them
|
||||
// they need to be skipped in the order they were enumerated in snes9xGX.h
|
||||
@ -3378,7 +3383,7 @@ static int MenuSettingsMenu()
|
||||
|
||||
while(menu == MENU_NONE)
|
||||
{
|
||||
VIDEO_WaitVSync ();
|
||||
usleep(THREAD_SLEEP);
|
||||
|
||||
#ifdef HW_RVL
|
||||
if (GCSettings.ExitAction == 1)
|
||||
@ -3512,7 +3517,7 @@ static int MenuSettingsNetwork()
|
||||
|
||||
while(menu == MENU_NONE)
|
||||
{
|
||||
VIDEO_WaitVSync ();
|
||||
usleep(THREAD_SLEEP);
|
||||
|
||||
strncpy (options.value[0], GCSettings.smbip, 15);
|
||||
strncpy (options.value[1], GCSettings.smbshare, 19);
|
||||
@ -3689,6 +3694,7 @@ MainMenu (int menu)
|
||||
break;
|
||||
}
|
||||
lastMenu = currentMenu;
|
||||
usleep(THREAD_SLEEP);
|
||||
}
|
||||
|
||||
#ifdef HW_RVL
|
||||
|
@ -313,7 +313,7 @@ InitVideoThread ()
|
||||
* Stock code to copy the GX buffer to the current display mode.
|
||||
* Also increments the frameticker, as it's called for each vb.
|
||||
***************************************************************************/
|
||||
static void
|
||||
static inline void
|
||||
copy_to_xfb (u32 arg)
|
||||
{
|
||||
if (copynow == GX_TRUE)
|
||||
@ -329,7 +329,7 @@ copy_to_xfb (u32 arg)
|
||||
/****************************************************************************
|
||||
* Scaler Support Functions
|
||||
***************************************************************************/
|
||||
static void
|
||||
static inline void
|
||||
draw_init ()
|
||||
{
|
||||
GX_ClearVtxDesc ();
|
||||
@ -358,7 +358,7 @@ draw_init ()
|
||||
GX_InvVtxCache (); // update vertex cache
|
||||
}
|
||||
|
||||
static void
|
||||
static inline void
|
||||
draw_vert (u8 pos, u8 c, f32 s, f32 t)
|
||||
{
|
||||
GX_Position1x8 (pos);
|
||||
@ -366,7 +366,7 @@ draw_vert (u8 pos, u8 c, f32 s, f32 t)
|
||||
GX_TexCoord2f32 (s, t);
|
||||
}
|
||||
|
||||
static void
|
||||
static inline void
|
||||
draw_square (Mtx v)
|
||||
{
|
||||
Mtx m; // model matrix.
|
||||
@ -460,7 +460,7 @@ UpdatePadsCB ()
|
||||
*
|
||||
* - modified for a buffer with an offset (border)
|
||||
****************************************************************************/
|
||||
static void
|
||||
static inline void
|
||||
MakeTexture (const void *src, void *dst, s32 width, s32 height)
|
||||
{
|
||||
register u32 tmp0 = 0, tmp1 = 0, tmp2 = 0, tmp3 = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user