Commit 0d5bb492 authored by hex's avatar hex

remove safeGO

parent 83c2db9b
Pipeline #39483 failed
...@@ -1259,24 +1259,24 @@ public class Ocgcore : ServantWithCardDescription ...@@ -1259,24 +1259,24 @@ public class Ocgcore : ServantWithCardDescription
return true; return true;
case GameMessage.Attack: case GameMessage.Attack:
return true; return true;
//case GameMessage.Attack: //case GameMessage.Attack:
// if (Program.I().setting.setting.Vbattle.value) // if (Program.I().setting.setting.Vbattle.value)
// { // {
// return true; // return true;
// } // }
// else // else
// { // {
// return false; // return false;
// } // }
//case GameMessage.Battle: //case GameMessage.Battle:
// if (Program.I().setting.setting.Vbattle.value) // if (Program.I().setting.setting.Vbattle.value)
// { // {
// return false; // return false;
// } // }
// else // else
// { // {
// return true; // return true;
// } // }
} }
return false; return false;
} }
...@@ -5802,7 +5802,7 @@ public class Ocgcore : ServantWithCardDescription ...@@ -5802,7 +5802,7 @@ public class Ocgcore : ServantWithCardDescription
r.ReadByte(); r.ReadByte();
UIHelper.playSound("explode", 0.4f); UIHelper.playSound("explode", 0.4f);
int amount = (int)(Mathf.Clamp(attackCard.get_data().Attack, 0, 3500) * 0.8f); int amount = (int)(Mathf.Clamp(attackCard.get_data().Attack, 0, 3500) * 0.8f);
float duration = (float)amount / 2500f; float duration = (float)amount / 2500f;
float strength = (float)amount / 1500f; float strength = (float)amount / 1500f;
Program.I().main_camera.transform.DOShakePosition(duration, strength); Program.I().main_camera.transform.DOShakePosition(duration, strength);
......
...@@ -1243,55 +1243,40 @@ public class Program : MonoBehaviour ...@@ -1243,55 +1243,40 @@ public class Program : MonoBehaviour
if (GameTextureManager.IsInitialized) if (GameTextureManager.IsInitialized)
{ {
// 1. 实现下载限流 ProcessTextureManagerUpdates();
// 只要当前活跃的下载数小于最大限制,并且队列里有待下载的任务,就启动新的下载。 }
while (_activeDownloads < MAX_CONCURRENT_DOWNLOADS && GameTextureManager.HasDownloadRequests())
{
var request = GameTextureManager.GetNextDownloadRequest();
if (!string.IsNullOrEmpty(request.Url))
{
_activeDownloads++; // 增加活跃下载计数
// 启动下载协程,并传入一个回调,用于在下载结束后减少计数
StartCoroutine(DownloadAndProcessFile(request, () =>
{
_activeDownloads--;
}));
}
}
// 2. 检查并处理纹理创建任务 (分帧处理避免卡顿) fixALLcamerasPreFrame();
int tasksProcessedThisFrame = 0;
int maxTasksPerFrame = 5; // 每帧最多创建5个纹理,防止卡顿
while (GameTextureManager.HasMainThreadTasks() && tasksProcessedThisFrame < maxTasksPerFrame) HandleUnifiedInput();
{
var resource = GameTextureManager.GetNextMainThreadTask(); UpdateRaycast();
if (resource != null)
{ for (int i = 0; i < servants.Count; i++)
GameTextureManager.CreateTextureFromResource(resource); {
tasksProcessedThisFrame++; servants[i].Update();
}
else
{
break;
}
}
} }
TcpHelper.preFrameFunction();
ProcessDelayedTasks();
}
fixALLcamerasPreFrame();
wheelValue = UICamera.GetAxis("Mouse ScrollWheel") * 50; private void UpdateRaycast()
{
pointedGameObject = null; pointedGameObject = null;
pointedCollider = null; pointedCollider = null;
Ray line = Camera.main.ScreenPointToRay(Input.mousePosition);
Vector3 inputPosition = Input.mousePosition;
Ray line = Camera.main.ScreenPointToRay(inputPosition);
RaycastHit hit; RaycastHit hit;
if (Physics.Raycast(line, out hit, (float)1000, rayFilter)) if (Physics.Raycast(line, out hit, 1000f, rayFilter))
{ {
pointedGameObject = hit.collider.gameObject; pointedGameObject = hit.collider.gameObject;
pointedCollider = hit.collider; pointedCollider = hit.collider;
} }
GameObject hoverobject = UICamera.Raycast(Input.mousePosition)
? UICamera.lastHit.collider.gameObject GameObject hoverobject = UICamera.Raycast(inputPosition) ?
: null; UICamera.lastHit.collider.gameObject : null;
if (hoverobject != null) if (hoverobject != null)
{ {
if (hoverobject.layer == 11 || pointedGameObject == null) if (hoverobject.layer == 11 || pointedGameObject == null)
...@@ -1300,34 +1285,79 @@ public class Program : MonoBehaviour ...@@ -1300,34 +1285,79 @@ public class Program : MonoBehaviour
pointedCollider = UICamera.lastHit.collider; pointedCollider = UICamera.lastHit.collider;
} }
} }
}
private void HandleUnifiedInput()
{
wheelValue = UICamera.GetAxis("Mouse ScrollWheel") * 50;
InputGetMouseButtonDown_0 = Input.GetMouseButtonDown(0); InputGetMouseButtonDown_0 = Input.GetMouseButtonDown(0);
InputGetMouseButtonUp_0 = Input.GetMouseButtonUp(0); InputGetMouseButtonUp_0 = Input.GetMouseButtonUp(0);
InputGetMouseButtonDown_1 = Input.GetMouseButtonDown(1); InputGetMouseButtonDown_1 = Input.GetMouseButtonDown(1);
InputGetMouseButtonUp_1 = Input.GetMouseButtonUp(1); InputGetMouseButtonUp_1 = Input.GetMouseButtonUp(1);
InputEnterDown = Input.GetKeyDown(KeyCode.Return); InputEnterDown = Input.GetKeyDown(KeyCode.Return);
InputGetMouseButton_0 = Input.GetMouseButton(0); InputGetMouseButton_0 = Input.GetMouseButton(0);
for (int i = 0; i < servants.Count; i++) }
private void ProcessTextureManagerUpdates()
{
// 1. 实现下载限流
// 只要当前活跃的下载数小于最大限制,并且队列里有待下载的任务,就启动新的下载。
while (_activeDownloads < MAX_CONCURRENT_DOWNLOADS && GameTextureManager.HasDownloadRequests())
{ {
servants[i].Update(); var request = GameTextureManager.GetNextDownloadRequest();
if (!string.IsNullOrEmpty(request.Url))
{
_activeDownloads++; // 增加活跃下载计数
// 启动下载协程,并传入一个回调,用于在下载结束后减少计数
StartCoroutine(DownloadAndProcessFile(request, () =>
{
_activeDownloads--;
}));
}
} }
TcpHelper.preFrameFunction();
// 2. 检查并处理纹理创建任务 (分帧处理避免卡顿)
int tasksProcessedThisFrame = 0;
int maxTasksPerFrame = 5; // 每帧最多创建5个纹理,防止卡顿
while (GameTextureManager.HasMainThreadTasks() && tasksProcessedThisFrame < maxTasksPerFrame)
{
var resource = GameTextureManager.GetNextMainThreadTask();
if (resource != null)
{
GameTextureManager.CreateTextureFromResource(resource);
tasksProcessedThisFrame++;
}
else
{
break;
}
}
}
private void ProcessDelayedTasks()
{
delayedTask remove = null; delayedTask remove = null;
while (true) int maxTasksPerFrame = 5; // 限制每帧处理的延迟任务数量
int processedTasks = 0;
while (processedTasks < maxTasksPerFrame)
{ {
remove = null; remove = null;
for (int i = 0; i < delayedTasks.Count; i++) for (int i = 0; i < delayedTasks.Count; i++)
{ {
if (Program.TimePassed() > delayedTasks[i].timeToBeDone) if (TimePassed() > delayedTasks[i].timeToBeDone)
{ {
remove = delayedTasks[i]; remove = delayedTasks[i];
try try
{ {
remove.act(); remove.act();
} }
catch (System.Exception e) catch (Exception e)
{ {
UnityEngine.Debug.Log(e); Debug.Log(e);
} }
processedTasks++;
break; break;
} }
} }
......
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using DG.Tweening;
using UnityEngine; using UnityEngine;
using YGOSharp.OCGWrapper.Enums; using YGOSharp.OCGWrapper.Enums;
using DG.Tweening;
public class Servant public class Servant
...@@ -57,11 +57,6 @@ public class Servant ...@@ -57,11 +57,6 @@ public class Servant
} }
allGameObjects.Clear(); allGameObjects.Clear();
updateActions_s.Clear(); updateActions_s.Clear();
for (int i = 0; i < delayedTasks.Count; i++)
{
Program.notGo(delayedTasks[i].act);
}
delayedTasks.Clear();
} }
public virtual void fixScreenProblem() public virtual void fixScreenProblem()
...@@ -130,13 +125,13 @@ public class Servant ...@@ -130,13 +125,13 @@ public class Servant
if (toolBar != null) if (toolBar != null)
{ {
Vector3 vectorOfHidedBar_Screen = new Vector3(Screen.width - RightToScreen, -200, 0); Vector3 vectorOfHidedBar_Screen = new Vector3(Screen.width - RightToScreen, -200, 0);
Vector3 targetWorldPosition = Program.camera_main_2d.ScreenToWorldPoint(vectorOfHidedBar_Screen); Vector3 targetWorldPosition = Program.camera_main_2d.ScreenToWorldPoint(vectorOfHidedBar_Screen);
toolBar.transform.DOMove(targetWorldPosition, 0.6f); toolBar.transform.DOMove(targetWorldPosition, 0.6f);
float scaleFactor = Screen.height / 700f; float scaleFactor = Screen.height / 700f;
toolBar.transform.localScale = new Vector3(scaleFactor, scaleFactor, scaleFactor); toolBar.transform.localScale = new Vector3(scaleFactor, scaleFactor, scaleFactor);
var items = toolBar.GetComponentsInChildren<toolShift>(); var items = toolBar.GetComponentsInChildren<toolShift>();
for (int i = 0; i < items.Length; i++) for (int i = 0; i < items.Length; i++)
{ {
...@@ -312,16 +307,6 @@ public class Servant ...@@ -312,16 +307,6 @@ public class Servant
} }
} }
List<Program.delayedTask> delayedTasks = new List<Program.delayedTask>();
public void safeGogo(int delay_, Action act_)
{
Program.go(delay_, act_);
delayedTasks.Add(
new Program.delayedTask { act = act_, timeToBeDone = delay_ + Program.TimePassed() }
);
}
#region remasterMessageSystem #region remasterMessageSystem
public Vector3 centre(bool fix = false) public Vector3 centre(bool fix = false)
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment