修复一些拉取rom列表的bug #80

Merged
sin365 merged 5 commits from Alienjack/AxibugEmuOnline:master into master 2025-01-06 20:31:47 +08:00
10 changed files with 254 additions and 230 deletions

View File

@ -13,7 +13,7 @@ namespace AxibugEmuOnline.Client
void Pause(); void Pause();
void Resume(); void Resume();
void SetupScheme(); void SetupScheme();
void StartGame(RomFile romFile); MsgBool StartGame(RomFile romFile);
void DoReset(); void DoReset();
IControllerSetuper GetControllerSetuper(); IControllerSetuper GetControllerSetuper();

View File

@ -56,19 +56,27 @@ namespace AxibugEmuOnline.Client.Manager
break; break;
} }
m_emuCore.StartGame(romFile); var result = m_emuCore.StartGame(romFile);
LaunchUI.Instance.HideMainMenu(); if (result)
InGameUI.Instance.Show(romFile, m_emuCore); {
LaunchUI.Instance.HideMainMenu();
InGameUI.Instance.Show(romFile, m_emuCore);
m_emuCore.SetupScheme(); m_emuCore.SetupScheme();
m_controllerSetuper = m_emuCore.GetControllerSetuper(); m_controllerSetuper = m_emuCore.GetControllerSetuper();
//自动分配0号手柄到0号手柄位 //自动分配0号手柄到0号手柄位
m_controllerSetuper.SetConnect(con0ToSlot: 0); m_controllerSetuper.SetConnect(con0ToSlot: 0);
Eventer.Instance.PostEvent(EEvent.OnControllerConnectChanged); Eventer.Instance.PostEvent(EEvent.OnControllerConnectChanged);
Eventer.Instance.RegisterEvent(EEvent.OnRoomSlotDataChanged, OnSlotDataChanged); Eventer.Instance.RegisterEvent(EEvent.OnRoomSlotDataChanged, OnSlotDataChanged);
}
else
{
StopGame();
OverlayManager.PopTip(result);
}
} }
private void OnSlotDataChanged() private void OnSlotDataChanged()

View File

@ -1,4 +1,4 @@
using AxibugEmuOnline.Client.ClientCore; using AxibugEmuOnline.Client.ClientCore;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
@ -12,21 +12,20 @@ namespace AxibugEmuOnline.Client
public string WebHost = "http://emu.axibug.com"; public string WebHost = "http://emu.axibug.com";
public string WebSiteApi => WebHost + "/api"; public string WebSiteApi => WebHost + "/api";
public delegate void GetRomListAPI(Action<Resp_GameList> callback, int page, int pageSize = 10); public delegate void GetRomListAPI(Action<int, Resp_GameList> callback, int page, int pageSize = 10);
public delegate void SearchRomListAPI(Action<Resp_GameList> callback, string searchKey, int page, int pageSize = 10); public delegate void SearchRomListAPI(Action<int, Resp_GameList> callback, string searchKey, int page, int pageSize = 10);
public void GetNesRomList(Action<Resp_GameList> callback, int page, int pageSize = 10) public void GetNesRomList(Action<int, Resp_GameList> callback, int page, int pageSize = 10)
{ {
App.StartCoroutine(GetNesRomListFlow(page, pageSize, callback)); App.StartCoroutine(GetNesRomListFlow(page, pageSize, callback));
} }
public void SearchNesRomList(Action<Resp_GameList> callback, string searchKey, int page, int pageSize = 10) public void SearchNesRomList(Action<int, Resp_GameList> callback, string searchKey, int page, int pageSize = 10)
{ {
App.StartCoroutine(SearchNesRomListFlow(searchKey, page, pageSize, callback)); App.StartCoroutine(SearchNesRomListFlow(searchKey, page, pageSize, callback));
} }
private IEnumerator SearchNesRomListFlow(string searchKey, int page, int pageSize, Action<Resp_GameList> callback) private IEnumerator SearchNesRomListFlow(string searchKey, int page, int pageSize, Action<int, Resp_GameList> callback)
{ {
if (!string.IsNullOrEmpty(searchKey)) if (!string.IsNullOrEmpty(searchKey))
{ {
string oldsearch = searchKey; string oldsearch = searchKey;
@ -48,19 +47,19 @@ namespace AxibugEmuOnline.Client
yield return request.SendWebRequest; yield return request.SendWebRequest;
if (!request.downloadHandler.isDone) if (!request.downloadHandler.isDone)
{ {
callback.Invoke(null); callback.Invoke(page, null);
yield break; yield break;
} }
if (!request.downloadHandler.bHadErr) if (!request.downloadHandler.bHadErr)
{ {
var resp = JsonUtility.FromJson<Resp_GameList>(request.downloadHandler.text); var resp = JsonUtility.FromJson<Resp_GameList>(request.downloadHandler.text);
callback.Invoke(resp); callback.Invoke(page, resp);
yield break; yield break;
} }
App.log.Error(request.downloadHandler.ErrInfo); App.log.Error(request.downloadHandler.ErrInfo);
callback.Invoke(null); callback.Invoke(page, null);
/* /*
UnityWebRequest request = UnityWebRequest.Get($"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}&SearchKey={searchKey}"); UnityWebRequest request = UnityWebRequest.Get($"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}&SearchKey={searchKey}");
@ -73,7 +72,7 @@ namespace AxibugEmuOnline.Client
}*/ }*/
} }
private IEnumerator GetNesRomListFlow(int page, int pageSize, Action<Resp_GameList> callback) private IEnumerator GetNesRomListFlow(int page, int pageSize, Action<int, Resp_GameList> callback)
{ {
string url = $"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}"; string url = $"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}";
App.log.Info($"GetRomList=>{url}"); App.log.Info($"GetRomList=>{url}");
@ -81,7 +80,7 @@ namespace AxibugEmuOnline.Client
yield return request.SendWebRequest; yield return request.SendWebRequest;
if (!request.downloadHandler.isDone) if (!request.downloadHandler.isDone)
{ {
callback.Invoke(null); callback.Invoke(page, null);
yield break; yield break;
} }
@ -89,12 +88,12 @@ namespace AxibugEmuOnline.Client
if (!request.downloadHandler.bHadErr) if (!request.downloadHandler.bHadErr)
{ {
var resp = JsonUtility.FromJson<Resp_GameList>(request.downloadHandler.text); var resp = JsonUtility.FromJson<Resp_GameList>(request.downloadHandler.text);
callback.Invoke(resp); callback.Invoke(page, resp);
yield break; yield break;
} }
App.log.Error(request.downloadHandler.ErrInfo); App.log.Error(request.downloadHandler.ErrInfo);
callback.Invoke(null); callback.Invoke(page, null);
/* /*
UnityWebRequest request = UnityWebRequest.Get($"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}"); UnityWebRequest request = UnityWebRequest.Get($"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}");
yield return request.SendWebRequest(); yield return request.SendWebRequest();

View File

@ -96,11 +96,12 @@ namespace AxibugEmuOnline.Client
if (Path.GetExtension(LocalFilePath).ToLower() == ".zip") if (Path.GetExtension(LocalFilePath).ToLower() == ".zip")
{ {
var zip = new ZipInputStream(new MemoryStream(bytes)); var zip = new ZipInputStream(new MemoryStream(bytes));
var entry = zip.GetNextEntry() as ZipEntry; while (true)
while (entry != null)
{ {
if (!entry.Name.ToLower().EndsWith(".nes")) continue; var currentEntry = zip.GetNextEntry();
if (currentEntry == null) break;
if (!currentEntry.Name.ToLower().EndsWith(".nes")) continue;
var buffer = new byte[1024]; var buffer = new byte[1024];
MemoryStream output = new MemoryStream(); MemoryStream output = new MemoryStream();
@ -126,36 +127,36 @@ namespace AxibugEmuOnline.Client
{ {
downloadRequest = AxiHttpProxy.GetDownLoad($"{App.httpAPI.WebHost}/{webData.url}"); downloadRequest = AxiHttpProxy.GetDownLoad($"{App.httpAPI.WebHost}/{webData.url}");
while (!downloadRequest.downloadHandler.isDone) while (!downloadRequest.downloadHandler.isDone)
{ {
yield return null; yield return null;
Debug.Log($"下载进度:{downloadRequest.downloadHandler.DownLoadPr} ->{downloadRequest.downloadHandler.loadedLenght}/{downloadRequest.downloadHandler.NeedloadedLenght}"); Debug.Log($"下载进度:{downloadRequest.downloadHandler.DownLoadPr} ->{downloadRequest.downloadHandler.loadedLenght}/{downloadRequest.downloadHandler.NeedloadedLenght}");
} }
AxiHttpProxy.ShowAxiHttpDebugInfo(downloadRequest.downloadHandler); AxiHttpProxy.ShowAxiHttpDebugInfo(downloadRequest.downloadHandler);
var request = downloadRequest; var request = downloadRequest;
downloadRequest = null; downloadRequest = null;
if (!request.downloadHandler.bHadErr) if (!request.downloadHandler.bHadErr)
callback(request.downloadHandler.data); callback(request.downloadHandler.data);
else else
callback(null); callback(null);
//downloadRequest = UnityWebRequest.Get($"{App.httpAPI.WebHost}/{webData.url}"); //downloadRequest = UnityWebRequest.Get($"{App.httpAPI.WebHost}/{webData.url}");
//yield return downloadRequest.SendWebRequest(); //yield return downloadRequest.SendWebRequest();
//var request = downloadRequest; //var request = downloadRequest;
//downloadRequest = null; //downloadRequest = null;
//if (request.result != UnityWebRequest.Result.Success) //if (request.result != UnityWebRequest.Result.Success)
//{ //{
// callback(null); // callback(null);
//} //}
//else //else
//{ //{
// callback(request.downloadHandler.data); // callback(request.downloadHandler.data);
//} //}
} }
public void SetWebData(HttpAPI.Resp_RomInfo resp_RomInfo) public void SetWebData(HttpAPI.Resp_RomInfo resp_RomInfo)
{ {

View File

@ -7,160 +7,180 @@ using static AxibugEmuOnline.Client.HttpAPI;
namespace AxibugEmuOnline.Client namespace AxibugEmuOnline.Client
{ {
public class RomLib public class RomLib
{ {
/// <summary> Rom请求,一页的大小 </summary> /// <summary> Rom请求,一页的大小 </summary>
private const int PAGE_SIZE = 10; private const int PAGE_SIZE = 10;
/// <summary> 请求指令 </summary> /// <summary> 请求指令 </summary>
private HashSet<int> FetchPageCmd = new HashSet<int>(); private HashSet<int> FetchPageCmd = new HashSet<int>();
private RomFile[] nesRomFetchList; private RomFile[] nesRomFetchList;
private Dictionary<int, RomFile> nesRomFileIdMapper = new Dictionary<int, RomFile>(); private Dictionary<int, RomFile> nesRomFileIdMapper = new Dictionary<int, RomFile>();
private Dictionary<string, RomFile> nesRomFileNameMapper = new Dictionary<string, RomFile>(); private Dictionary<string, RomFile> nesRomFileNameMapper = new Dictionary<string, RomFile>();
private HttpAPI.GetRomListAPI m_romGetFunc; private HttpAPI.GetRomListAPI m_romGetFunc;
private HttpAPI.SearchRomListAPI m_romSearchFunc; private HttpAPI.SearchRomListAPI m_romSearchFunc;
private EnumSupportEmuPlatform m_platform; private EnumSupportEmuPlatform m_platform;
private string lastSearchKey; private string lastSearchKey;
public RomLib(EnumSupportEmuPlatform platform) public RomLib(EnumSupportEmuPlatform platform)
{ {
m_platform = platform; m_platform = platform;
switch (platform) switch (platform)
{ {
case EnumSupportEmuPlatform.NES: case EnumSupportEmuPlatform.NES:
m_romGetFunc = App.httpAPI.GetNesRomList; m_romGetFunc = App.httpAPI.GetNesRomList;
m_romSearchFunc = App.httpAPI.SearchNesRomList; m_romSearchFunc = App.httpAPI.SearchNesRomList;
break; break;
} }
} }
public RomFile GetExistRom(string fileName) public RomFile GetExistRom(string fileName)
{ {
var res = RomFile.CreateExistRom(m_platform, fileName); var res = RomFile.CreateExistRom(m_platform, fileName);
nesRomFileNameMapper[res.FileName] = res; nesRomFileNameMapper[res.FileName] = res;
return res; return res;
} }
public RomFile GetRomFile(string romFileName) public RomFile GetRomFile(string romFileName)
{ {
RomFile romFile; RomFile romFile;
nesRomFileNameMapper.TryGetValue(romFileName, out romFile); nesRomFileNameMapper.TryGetValue(romFileName, out romFile);
return romFile; return romFile;
} }
/// <summary> 清除所有下载的Rom文件 </summary> /// <summary> 清除所有下载的Rom文件 </summary>
public void ClearRomFile() public void ClearRomFile()
{ {
var path = $"{App.PersistentDataPath}/RemoteRoms/{m_platform}"; var path = $"{App.PersistentDataPath}/RemoteRoms/{m_platform}";
if (Directory.Exists(path)) Directory.Delete(path, true); if (Directory.Exists(path)) Directory.Delete(path, true);
} }
/// <summary> 移除一个已下载的Rom </summary> /// <summary> 移除一个已下载的Rom </summary>
public void RemoveOneRomFile(RomFile romFile) public void RemoveOneRomFile(RomFile romFile)
{ {
if (romFile.RomReady) if (romFile.RomReady)
File.Delete(romFile.LocalFilePath); File.Delete(romFile.LocalFilePath);
} }
/// <summary> /// <summary>
/// 获得所有Rom文件 /// 获得所有Rom文件
/// </summary> /// </summary>
/// <param name="callback"></param> /// <param name="callback"></param>
public void FetchRomCount(Action<RomFile[]> callback, string searchKey = null) public void FetchRomCount(Action<RomFile[]> callback, string searchKey = null)
{ {
lastSearchKey = searchKey; lastSearchKey = searchKey;
if (string.IsNullOrWhiteSpace(searchKey)) if (string.IsNullOrWhiteSpace(searchKey))
{ {
m_romGetFunc((romList) => m_romGetFunc((page, romList) =>
{ {
//TODO 请求失败对于romList为空时的处理 FetchPageCmd.Clear();
nesRomFileIdMapper.Clear();
nesRomFileNameMapper.Clear();
FetchPageCmd.Clear(); if (romList != null)
nesRomFileIdMapper.Clear(); nesRomFetchList = new RomFile[romList.resultAllCount];
nesRomFileNameMapper.Clear(); else
nesRomFetchList = new RomFile[romList.resultAllCount]; nesRomFetchList = new RomFile[0];
for (int i = 0; i < nesRomFetchList.Length; i++)
{
//以后考虑用对象池实例化RomFile
nesRomFetchList[i] = new RomFile(m_platform, i, i / PAGE_SIZE);
}
SaveRomInfoFromWeb(romList);
callback.Invoke(nesRomFetchList); for (int i = 0; i < nesRomFetchList.Length; i++)
}, 0, PAGE_SIZE); {
} //以后考虑用对象池实例化RomFile
else nesRomFetchList[i] = new RomFile(m_platform, i, i / PAGE_SIZE);
{ }
m_romSearchFunc((romList) => SaveRomInfoFromWeb(romList);
{
//TODO 请求失败对于romList为空时的处理
FetchPageCmd.Clear(); callback.Invoke(nesRomFetchList);
nesRomFileIdMapper.Clear(); }, 0, PAGE_SIZE);
nesRomFileNameMapper.Clear(); }
nesRomFetchList = new RomFile[romList.resultAllCount]; else
for (int i = 0; i < nesRomFetchList.Length; i++) {
{ m_romSearchFunc((page, romList) =>
//以后考虑用对象池实例化RomFile {
nesRomFetchList[i] = new RomFile(m_platform, i, i / PAGE_SIZE); FetchPageCmd.Clear();
} nesRomFileIdMapper.Clear();
SaveRomInfoFromWeb(romList); nesRomFileNameMapper.Clear();
callback.Invoke(nesRomFetchList); if (romList != null)
}, searchKey, 0, PAGE_SIZE); nesRomFetchList = new RomFile[romList.resultAllCount];
} else
} nesRomFetchList = new RomFile[0];
public void BeginFetchRomInfo(RomFile romFile) for (int i = 0; i < nesRomFetchList.Length; i++)
{ {
if (romFile.InfoReady) return; //以后考虑用对象池实例化RomFile
nesRomFetchList[i] = new RomFile(m_platform, i, i / PAGE_SIZE);
}
SaveRomInfoFromWeb(romList);
FetchPageCmd.Add(romFile.Page); callback.Invoke(nesRomFetchList);
} }, searchKey, 0, PAGE_SIZE);
}
}
public void ExecuteFetchRomInfo() bool m_needFetch = false;
{ public void BeginFetchRomInfo(RomFile romFile)
if (FetchPageCmd.Count == 0) return; {
if (romFile.InfoReady) return;
foreach (var pageNo in FetchPageCmd) if (FetchPageCmd.Add(romFile.Page))
{ m_needFetch = true;
if (!string.IsNullOrEmpty(lastSearchKey)) }
{
m_romSearchFunc(SaveRomInfoFromWeb, lastSearchKey, pageNo, PAGE_SIZE);
}
else
{
m_romGetFunc(SaveRomInfoFromWeb, pageNo, PAGE_SIZE);
}
}
FetchPageCmd.Clear();
}
private void SaveRomInfoFromWeb(Resp_GameList resp) public void ExecuteFetchRomInfo()
{ {
for (int i = 0; i < resp.gameList.Count; i++) if (FetchPageCmd.Count == 0) return;
{ if (!m_needFetch) return;
var webData = resp.gameList[i];
RomFile targetRomFile = nesRomFetchList[webData.orderid];
targetRomFile.SetWebData(webData); foreach (var pageNo in FetchPageCmd)
nesRomFileIdMapper[webData.id] = nesRomFetchList[webData.orderid]; {
nesRomFileNameMapper[targetRomFile.FileName] = targetRomFile; if (!string.IsNullOrEmpty(lastSearchKey))
} {
} m_romSearchFunc((page, resp) =>
{
FetchPageCmd.Remove(page);
SaveRomInfoFromWeb(resp);
}, lastSearchKey, pageNo, PAGE_SIZE);
}
else
{
m_romGetFunc((page, resp) =>
{
FetchPageCmd.Remove(page);
SaveRomInfoFromWeb(resp);
}, pageNo, PAGE_SIZE);
}
}
public static string CalcHash(byte[] data) m_needFetch = false;
{ }
return Helper.FileMD5Hash(data);
}
public void AddRomFile(RomFile rom) private void SaveRomInfoFromWeb(Resp_GameList resp)
{ {
nesRomFileNameMapper[rom.FileName] = rom; if (resp == null) return;
}
} for (int i = 0; i < resp.gameList.Count; i++)
{
var webData = resp.gameList[i];
RomFile targetRomFile = nesRomFetchList[webData.orderid];
targetRomFile.SetWebData(webData);
nesRomFileIdMapper[webData.id] = nesRomFetchList[webData.orderid];
nesRomFileNameMapper[targetRomFile.FileName] = targetRomFile;
}
}
public static string CalcHash(byte[] data)
{
return Helper.FileMD5Hash(data);
}
public void AddRomFile(RomFile rom)
{
nesRomFileNameMapper[rom.FileName] = rom;
}
}
} }

View File

@ -63,7 +63,7 @@ namespace AxibugEmuOnline.Client
/// <summary> /// <summary>
/// 指定ROM开始游戏 /// 指定ROM开始游戏
/// </summary> /// </summary>
public void StartGame(RomFile rom) public MsgBool StartGame(RomFile rom)
{ {
StopGame(); StopGame();
@ -76,11 +76,13 @@ namespace AxibugEmuOnline.Client
try try
{ {
NesCore = new NES(rom.FileName); NesCore = new NES(rom.FileName);
return true;
} }
catch (Exception ex) catch (Exception ex)
{ {
NesCore = null; NesCore = null;
App.log.Error(ex.ToString()); App.log.Error(ex.ToString());
return ex.Message;
} }
} }

View File

@ -32,8 +32,6 @@
_Power2("Power",Float)=50.0 _Power2("Power",Float)=50.0
_Frequency2("Frequency",Float)=2.1 _Frequency2("Frequency",Float)=2.1
_Speed2("Speed",Float)=0.3 _Speed2("Speed",Float)=0.3
_Gamma("GAMMA",float) = 2.2
} }
SubShader SubShader
@ -154,8 +152,6 @@
float _Frequency2; float _Frequency2;
float _Speed2; float _Speed2;
float _Gamma;
fixed4 frag(v2f IN) : SV_Target fixed4 frag(v2f IN) : SV_Target
{ {
float2 uv= IN.texcoord; float2 uv= IN.texcoord;
@ -200,8 +196,6 @@
clip (fragColor.a - 0.001); clip (fragColor.a - 0.001);
#endif #endif
fragColor = pow(fragColor,1/_Gamma);
return fragColor; return fragColor;
} }

View File

@ -207,7 +207,7 @@ namespace VirtualNes
{ {
for (byte i = 0; i < 8; i++) for (byte i = 0; i < 8; i++)
{ {
SetCRAM_1K_Bank(i, bank * 8 + 1); SetCRAM_1K_Bank(i, bank * 8 + i);
} }
} }

View File

@ -40,7 +40,7 @@ namespace VirtualNes.Core
irq_latch = 0; irq_latch = 0;
irq_clock = 0; irq_clock = 0;
reg[9] = 1; //reg[9] = 1;
SetPROM_32K_Bank(0, 1, PROM_8K_SIZE - 2, PROM_8K_SIZE - 1); SetPROM_32K_Bank(0, 1, PROM_8K_SIZE - 2, PROM_8K_SIZE - 1);
SetVROM_8K_Bank(0); SetVROM_8K_Bank(0);