Commit 835e3805 authored by hex's avatar hex

- Fixed a typo in mygo server

- Optimized TCPHelper
- Fixed card description layout on iOS notch screens
parent 1b3f593e
Pipeline #37858 failed
...@@ -93,11 +93,11 @@ Camera: ...@@ -93,11 +93,11 @@ Camera:
m_TargetEye: 3 m_TargetEye: 3
m_HDR: 0 m_HDR: 0
m_AllowMSAA: 1 m_AllowMSAA: 1
m_AllowDynamicResolution: 0
m_ForceIntoRT: 0 m_ForceIntoRT: 0
m_OcclusionCulling: 1 m_OcclusionCulling: 1
m_StereoConvergence: 10 m_StereoConvergence: 10
m_StereoSeparation: 0.022 m_StereoSeparation: 0.022
m_StereoMirrorMode: 0
--- !u!54 &5496038 --- !u!54 &5496038
Rigidbody: Rigidbody:
m_ObjectHideFlags: 1 m_ObjectHideFlags: 1
......
...@@ -93,11 +93,11 @@ Camera: ...@@ -93,11 +93,11 @@ Camera:
m_TargetEye: 3 m_TargetEye: 3
m_HDR: 0 m_HDR: 0
m_AllowMSAA: 1 m_AllowMSAA: 1
m_AllowDynamicResolution: 0
m_ForceIntoRT: 0 m_ForceIntoRT: 0
m_OcclusionCulling: 1 m_OcclusionCulling: 1
m_StereoConvergence: 10 m_StereoConvergence: 10
m_StereoSeparation: 0.022 m_StereoSeparation: 0.022
m_StereoMirrorMode: 0
--- !u!54 &5484482 --- !u!54 &5484482
Rigidbody: Rigidbody:
m_ObjectHideFlags: 1 m_ObjectHideFlags: 1
......
...@@ -117,9 +117,18 @@ public class CardDescription : Servant ...@@ -117,9 +117,18 @@ public class CardDescription : Servant
if (gameObject != null) if (gameObject != null)
{ {
underSprite.height = Screen.height + 4; underSprite.height = Screen.height + 4;
int offset = 0;
// 暴力适配 ios 刘海屏
if (Screen.safeArea.x > 0)
{
offset = 66;
}
iTween.MoveTo( iTween.MoveTo(
gameObject, gameObject,
Program.camera_main_2d.ScreenToWorldPoint(new Vector3(-2, Screen.height / 2, 0)), Program.camera_main_2d.ScreenToWorldPoint(
new Vector3(offset, Screen.height / 2, 0)
),
1.2f 1.2f
); );
resizer.gameObject.GetComponent<BoxCollider>().enabled = true; resizer.gameObject.GetComponent<BoxCollider>().enabled = true;
......
...@@ -40,6 +40,7 @@ public static class TcpHelper ...@@ -40,6 +40,7 @@ public static class TcpHelper
networkStream = tcpClient.GetStream(); networkStream = tcpClient.GetStream();
Thread t = new Thread(receiver); Thread t = new Thread(receiver);
t.Start(); t.Start();
StartSendThread();
CtosMessage_PlayerInfo(name); CtosMessage_PlayerInfo(name);
if (pswString == "L") if (pswString == "L")
{ {
...@@ -88,33 +89,64 @@ public static class TcpHelper ...@@ -88,33 +89,64 @@ public static class TcpHelper
public static void addDateJumoLine(byte[] data) public static void addDateJumoLine(byte[] data)
{ {
Monitor.Enter(datas); lock (datasLock)
try
{ {
datas.Add(data); datas.Enqueue(data);
} }
catch (System.Exception e)
{
UnityEngine.Debug.Log(e);
}
Monitor.Exit(datas);
} }
public static bool onDisConnected = false; public static bool onDisConnected = false;
static List<byte[]> datas = new List<byte[]>(); static Queue<byte[]> datas = new Queue<byte[]>();
static object datasLock = new object();
static object locker = new object();
public static void StartSendThread()
{
if (sendThread == null)
{
sendThreadRunning = true;
sendThread = new Thread(SendThreadFunc);
sendThread.IsBackground = true;
sendThread.Start();
}
}
static void StopSendThread()
{
sendThreadRunning = false;
if (sendThread != null)
{
try
{
if (!sendThread.Join(100))
{
sendThread.Abort();
}
}
catch { }
sendThread = null;
}
}
public static void preFrameFunction() public static void preFrameFunction()
{
byte[][] packets = null;
lock (datasLock)
{ {
if (datas.Count > 0) if (datas.Count > 0)
{ {
if (Monitor.TryEnter(datas)) packets = datas.ToArray();
datas.Clear();
}
}
if (packets != null)
{ {
for (int i = 0; i < datas.Count; i++) for (int i = 0; i < packets.Length; i++)
{ {
try try
{ {
MemoryStream memoryStream = new MemoryStream(datas[i]); MemoryStream memoryStream = new MemoryStream(packets[i]);
BinaryReader r = new BinaryReader(memoryStream); BinaryReader r = new BinaryReader(memoryStream);
var ms = (StocMessage)(r.ReadByte()); var ms = (StocMessage)(r.ReadByte());
switch (ms) switch (ms)
...@@ -201,9 +233,6 @@ public static class TcpHelper ...@@ -201,9 +233,6 @@ public static class TcpHelper
// Program.DEBUGLOG(e); // Program.DEBUGLOG(e);
} }
} }
datas.Clear();
Monitor.Exit(datas);
}
} }
if (onDisConnected == true) if (onDisConnected == true)
{ {
...@@ -227,6 +256,8 @@ public static class TcpHelper ...@@ -227,6 +256,8 @@ public static class TcpHelper
} }
tcpClient = null; tcpClient = null;
StopSendThread();
if (Program.I().ocgcore.isShowed == false) if (Program.I().ocgcore.isShowed == false)
{ {
if (Program.I().menu.isShowed == false) if (Program.I().menu.isShowed == false)
...@@ -257,29 +288,34 @@ public static class TcpHelper ...@@ -257,29 +288,34 @@ public static class TcpHelper
} }
} }
public static void Send(Package message) static Queue<Package> sendQueue = new Queue<Package>();
static object sendLock = new object();
static Thread sendThread = null;
static bool sendThreadRunning = false;
static void SendThreadFunc()
{ {
if (tcpClient != null && tcpClient.Connected) while (sendThreadRunning)
{
Package pkg = null;
lock (sendLock)
{ {
Thread t = new Thread(sender); if (sendQueue.Count > 0)
t.Start(message); {
pkg = sendQueue.Dequeue();
} }
} }
if (pkg != null)
static object locker = new object();
static void sender(object o)
{ {
try try
{ {
lock (locker) lock (locker)
{ {
Package message = (Package)o; byte[] data = pkg.Data.get();
byte[] data = message.Data.get();
MemoryStream memstream = new MemoryStream(); MemoryStream memstream = new MemoryStream();
BinaryWriter b = new BinaryWriter(memstream); BinaryWriter b = new BinaryWriter(memstream);
b.Write(BitConverter.GetBytes((Int16)data.Length + 1), 0, 2); b.Write(BitConverter.GetBytes((Int16)data.Length + 1), 0, 2);
b.Write(BitConverter.GetBytes((byte)message.Fuction), 0, 1); b.Write(BitConverter.GetBytes((byte)pkg.Fuction), 0, 1);
b.Write(data, 0, data.Length); b.Write(data, 0, data.Length);
byte[] s = memstream.ToArray(); byte[] s = memstream.ToArray();
tcpClient.Client.Send(s); tcpClient.Client.Send(s);
...@@ -291,6 +327,23 @@ public static class TcpHelper ...@@ -291,6 +327,23 @@ public static class TcpHelper
Program.DEBUGLOG("onDisConnected 5"); Program.DEBUGLOG("onDisConnected 5");
} }
} }
else
{
Thread.Sleep(2); // 避免空转
}
}
}
public static void Send(Package message)
{
if (tcpClient != null && tcpClient.Connected)
{
lock (sendLock)
{
sendQueue.Enqueue(message);
}
}
}
public static void CtosMessage_Response(byte[] response) public static void CtosMessage_Response(byte[] response)
{ {
......
...@@ -93,7 +93,7 @@ public class SelectServer : WindowServantSP ...@@ -93,7 +93,7 @@ public class SelectServer : WindowServantSP
} }
case "[OCG]MYGO": case "[OCG]MYGO":
{ {
UIHelper.getByName<UIInput>(gameObject, "ip_").value = "mygo.suprepre.pro"; UIHelper.getByName<UIInput>(gameObject, "ip_").value = "mygo.superpre.pro";
UIHelper.getByName<UIInput>(gameObject, "port_").value = "888"; UIHelper.getByName<UIInput>(gameObject, "port_").value = "888";
Config.Set("serversPicker", "[OCG]MYGO"); Config.Set("serversPicker", "[OCG]MYGO");
......
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