mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-12-03 11:13:44 +01:00
Merge pull request #20219 from hrydgard/more-minor-fixes
Init/shutdown UPnP with the app, not each game. Also minor fixes and cleanups
This commit is contained in:
9 files changed
+51
-39
No files matched your search
+6
-25
@@ -414,25 +414,6 @@ void InitLocalhostIP() {
|
||||
isLocalServer = (!strcasecmp(serverStr.c_str(), "localhost") || serverStr.find("127.") == 0);
|
||||
}
|
||||
|
||||
static bool __PlatformNetInit() {
|
||||
#ifdef _WIN32
|
||||
WSADATA wsaData;
|
||||
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
|
||||
// TODO: log
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool __PlatformNetShutdown() {
|
||||
#ifdef _WIN32
|
||||
return WSACleanup() == 0;
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void __ApctlState(u64 userdata, int cyclesLate) {
|
||||
SceUID threadID = userdata >> 32;
|
||||
int uid = (int)(userdata & 0xFFFFFFFF);
|
||||
@@ -514,9 +495,10 @@ void __NetInit() {
|
||||
getLocalMac(&mac);
|
||||
INFO_LOG(Log::sceNet, "LocalHost IP will be %s [%s]", ip2str(g_localhostIP.in.sin_addr).c_str(), mac2str(&mac).c_str());
|
||||
|
||||
__PlatformNetInit();
|
||||
// TODO: May be we should initialize & cleanup somewhere else than here for PortManager to be used as general purpose for whatever port forwarding PPSSPP needed
|
||||
__UPnPInit();
|
||||
// For libretro we don't have a better place. On other platforms, we just init/shutdown it with the rest of the emu (NativeInit / NativeShutdown).
|
||||
#ifdef __LIBRETRO__
|
||||
__UPnPInit(2000);
|
||||
#endif
|
||||
|
||||
__ResetInitNetLib();
|
||||
__NetApctlInit();
|
||||
@@ -541,10 +523,9 @@ void __NetShutdown() {
|
||||
__NetApctlShutdown();
|
||||
__ResetInitNetLib();
|
||||
|
||||
// Since PortManager supposed to be general purpose for whatever port forwarding PPSSPP needed, may be we shouldn't clear & restore ports in here? it will be cleared and restored by PortManager's destructor when exiting PPSSPP anyway
|
||||
#ifdef __LIBRETRO__
|
||||
__UPnPShutdown();
|
||||
|
||||
__PlatformNetShutdown();
|
||||
#endif
|
||||
|
||||
free(dummyPeekBuf64k);
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ FileLoader *ConstructFileLoader(const Path &filename) {
|
||||
}
|
||||
|
||||
// TODO : improve, look in the file more
|
||||
// Does not take ownership.
|
||||
IdentifiedFileType Identify_File(FileLoader *fileLoader, std::string *errorString) {
|
||||
errorString->clear();
|
||||
if (fileLoader == nullptr) {
|
||||
|
||||
@@ -52,6 +52,7 @@
|
||||
|
||||
GameManager g_GameManager;
|
||||
|
||||
// Close the return value with ZipClose (if non-null, of course).
|
||||
struct zip *ZipOpenPath(Path fileName) {
|
||||
int error = 0;
|
||||
// Need to special case for content URI here, similar to OpenCFile.
|
||||
@@ -73,7 +74,8 @@ struct zip *ZipOpenPath(Path fileName) {
|
||||
}
|
||||
|
||||
void ZipClose(struct zip *z) {
|
||||
zip_close(z);
|
||||
if (z)
|
||||
zip_close(z);
|
||||
}
|
||||
|
||||
GameManager::GameManager() {
|
||||
|
||||
@@ -523,10 +523,10 @@ int upnpService(const unsigned int timeout) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void __UPnPInit(const unsigned int timeout) {
|
||||
void __UPnPInit(const int timeout_ms) {
|
||||
if (!upnpServiceRunning) {
|
||||
upnpServiceRunning = true;
|
||||
upnpServiceThread = std::thread(upnpService, timeout);
|
||||
upnpServiceThread = std::thread(upnpService, timeout_ms);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ private:
|
||||
|
||||
extern PortManager g_PortManager;
|
||||
|
||||
void __UPnPInit(const unsigned int timeout = 2000);
|
||||
void __UPnPInit(const int timeout_ms);
|
||||
void __UPnPShutdown();
|
||||
|
||||
// Add a port & protocol (TCP, UDP or vendor-defined) to map for forwarding (intport = 0 : same as [external] port)
|
||||
|
||||
@@ -63,6 +63,18 @@ enum class OpType {
|
||||
Done,
|
||||
};
|
||||
|
||||
static const char *OpTypeToString(OpType type) {
|
||||
switch (type) {
|
||||
case OpType::None: return "None";
|
||||
case OpType::UpdateStallAddr: return "UpdateStallAddr";
|
||||
case OpType::EnqueueList: return "EnqueueList";
|
||||
case OpType::ListSync: return "ListSync";
|
||||
case OpType::ReapplyGfxState: return "ReapplyGfxState";
|
||||
case OpType::Done: return "Done";
|
||||
default: return "N/A";
|
||||
}
|
||||
}
|
||||
|
||||
struct Operation {
|
||||
OpType type;
|
||||
u32 listID; // also listPC in EnqueueList
|
||||
@@ -79,7 +91,7 @@ static std::vector<u8> lastExecPushbuf;
|
||||
static std::thread replayThread;
|
||||
|
||||
static std::mutex opStartLock;
|
||||
static std::condition_variable opStartWait;
|
||||
static std::condition_variable g_condOpStartWait;
|
||||
|
||||
static std::mutex opFinishLock;
|
||||
static std::condition_variable opFinishWait;
|
||||
@@ -95,7 +107,7 @@ u32 ExecuteOnMain(Operation opToExec) {
|
||||
g_opToExec = opToExec;
|
||||
g_retVal = 0;
|
||||
g_opDone = false;
|
||||
opStartWait.notify_one();
|
||||
g_condOpStartWait.notify_one();
|
||||
}
|
||||
|
||||
// now wait for completion. At that point, noone cares about g_opToExec anymore, and we can safely
|
||||
@@ -888,6 +900,17 @@ static u32 LoadReplay(const std::string &filename) {
|
||||
}
|
||||
|
||||
void Replay_Unload() {
|
||||
// We might be paused inside a replay - in this case, the thread is still running and we need to tell it to stop.
|
||||
if (replayThread.joinable()) {
|
||||
{
|
||||
std::unique_lock<std::mutex> waitLock(opFinishLock);
|
||||
// Just override the next op to bail.
|
||||
g_opToExec = Operation{ OpType::Done };
|
||||
opFinishWait.notify_one();
|
||||
}
|
||||
replayThread.join();
|
||||
}
|
||||
|
||||
_dbg_assert_(!replayThread.joinable());
|
||||
|
||||
lastExecFilename.clear();
|
||||
@@ -967,7 +990,7 @@ ReplayResult RunMountedReplay(const std::string &filename) {
|
||||
// OK, now wait for and perform the desired action.
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(opStartLock);
|
||||
opStartWait.wait(lock, []() { return g_opToExec.type != OpType::None; });
|
||||
g_condOpStartWait.wait(lock, []() { return g_opToExec.type != OpType::None; });
|
||||
}
|
||||
|
||||
switch (g_opToExec.type) {
|
||||
|
||||
@@ -59,7 +59,7 @@ void InstallZipScreen::CreateViews() {
|
||||
std::string shortFilename = zipPath_.GetFilename();
|
||||
|
||||
// TODO: Do in the background?
|
||||
struct zip *z = ZipOpenPath(zipPath_);
|
||||
struct zip *zipFile = ZipOpenPath(zipPath_);
|
||||
|
||||
bool showDeleteCheckbox = false;
|
||||
returnToHomebrew_ = false;
|
||||
@@ -71,8 +71,8 @@ void InstallZipScreen::CreateViews() {
|
||||
|
||||
std::vector<Path> destOptions;
|
||||
|
||||
if (z) {
|
||||
DetectZipFileContents(z, &zipFileInfo_); // Even if this fails, it sets zipInfo->contents.
|
||||
if (zipFile) {
|
||||
DetectZipFileContents(zipFile, &zipFileInfo_); // Even if this fails, it sets zipInfo->contents.
|
||||
if (zipFileInfo_.contents == ZipFileContents::ISO_FILE || zipFileInfo_.contents == ZipFileContents::PSP_GAME_DIR) {
|
||||
std::string_view question = iz->T("Install game from ZIP file?");
|
||||
|
||||
@@ -120,7 +120,7 @@ void InstallZipScreen::CreateViews() {
|
||||
leftColumn->Add(new TextView(zipFileInfo_.gameTitle + ": " + zipFileInfo_.savedataDir));
|
||||
|
||||
Path savedataDir = GetSysDirectory(DIRECTORY_SAVEDATA);
|
||||
bool overwrite = !CanExtractWithoutOverwrite(z, savedataDir, 50);
|
||||
bool overwrite = !CanExtractWithoutOverwrite(zipFile, savedataDir, 50);
|
||||
|
||||
destFolders_.push_back(savedataDir);
|
||||
|
||||
@@ -163,6 +163,7 @@ void InstallZipScreen::CreateViews() {
|
||||
} else {
|
||||
leftColumn->Add(new TextView(iz->T("Zip file does not contain PSP software"), ALIGN_LEFT, false, new AnchorLayoutParams(10, 10, NONE, NONE)));
|
||||
}
|
||||
ZipClose(zipFile);
|
||||
} else {
|
||||
leftColumn->Add(new TextView(er->T("The file is not a valid zip file"), ALIGN_LEFT, false, new AnchorLayoutParams(10, 10, NONE, NONE)));
|
||||
}
|
||||
|
||||
+2
-3
@@ -77,14 +77,13 @@ bool MainScreen::showHomebrewTab = false;
|
||||
|
||||
bool LaunchFile(ScreenManager *screenManager, const Path &path) {
|
||||
// Depending on the file type, we don't want to launch EmuScreen at all.
|
||||
auto loader = ConstructFileLoader(path);
|
||||
std::unique_ptr<FileLoader> loader(ConstructFileLoader(path));
|
||||
if (!loader) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string errorString;
|
||||
IdentifiedFileType type = Identify_File(loader, &errorString);
|
||||
delete loader;
|
||||
IdentifiedFileType type = Identify_File(loader.get(), &errorString);
|
||||
|
||||
switch (type) {
|
||||
case IdentifiedFileType::ARCHIVE_ZIP:
|
||||
|
||||
@@ -339,6 +339,9 @@ static void ClearFailedGPUBackends() {
|
||||
void NativeInit(int argc, const char *argv[], const char *savegame_dir, const char *external_dir, const char *cache_dir) {
|
||||
net::Init(); // This needs to happen before we load the config. So on Windows we also run it in Main. It's fine to call multiple times.
|
||||
|
||||
// Probably an excessive timeout. it only causes delays on shutdown, though.
|
||||
__UPnPInit(2000);
|
||||
|
||||
ShaderTranslationInit();
|
||||
|
||||
g_threadManager.Init(cpu_info.num_cores, cpu_info.logical_cpu_count);
|
||||
@@ -1499,6 +1502,8 @@ void NativeShutdown() {
|
||||
System_ExitApp();
|
||||
#endif
|
||||
|
||||
__UPnPShutdown();
|
||||
|
||||
g_PortManager.Shutdown();
|
||||
|
||||
net::Shutdown();
|
||||
|
||||
Reference in new issue
Block a user