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:
m_TargetEye: 3
m_HDR: 0
m_AllowMSAA: 1
m_AllowDynamicResolution: 0
m_ForceIntoRT: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022
m_StereoMirrorMode: 0
--- !u!54 &5496038
Rigidbody:
m_ObjectHideFlags: 1
......
......@@ -93,11 +93,11 @@ Camera:
m_TargetEye: 3
m_HDR: 0
m_AllowMSAA: 1
m_AllowDynamicResolution: 0
m_ForceIntoRT: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022
m_StereoMirrorMode: 0
--- !u!54 &5484482
Rigidbody:
m_ObjectHideFlags: 1
......
......@@ -117,9 +117,18 @@ public class CardDescription : Servant
if (gameObject != null)
{
underSprite.height = Screen.height + 4;
int offset = 0;
// 暴力适配 ios 刘海屏
if (Screen.safeArea.x > 0)
{
offset = 66;
}
iTween.MoveTo(
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
);
resizer.gameObject.GetComponent<BoxCollider>().enabled = true;
......
......@@ -40,6 +40,7 @@ public static class TcpHelper
networkStream = tcpClient.GetStream();
Thread t = new Thread(receiver);
t.Start();
StartSendThread();
CtosMessage_PlayerInfo(name);
if (pswString == "L")
{
......@@ -88,33 +89,64 @@ public static class TcpHelper
public static void addDateJumoLine(byte[] data)
{
Monitor.Enter(datas);
try
lock (datasLock)
{
datas.Add(data);
datas.Enqueue(data);
}
catch (System.Exception e)
{
UnityEngine.Debug.Log(e);
}
Monitor.Exit(datas);
}
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()
{
byte[][] packets = null;
lock (datasLock)
{
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
{
MemoryStream memoryStream = new MemoryStream(datas[i]);
MemoryStream memoryStream = new MemoryStream(packets[i]);
BinaryReader r = new BinaryReader(memoryStream);
var ms = (StocMessage)(r.ReadByte());
switch (ms)
......@@ -201,9 +233,6 @@ public static class TcpHelper
// Program.DEBUGLOG(e);
}
}
datas.Clear();
Monitor.Exit(datas);
}
}
if (onDisConnected == true)
{
......@@ -227,6 +256,8 @@ public static class TcpHelper
}
tcpClient = null;
StopSendThread();
if (Program.I().ocgcore.isShowed == false)
{
if (Program.I().menu.isShowed == false)
......@@ -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);
t.Start(message);
if (sendQueue.Count > 0)
{
pkg = sendQueue.Dequeue();
}
}
static object locker = new object();
static void sender(object o)
if (pkg != null)
{
try
{
lock (locker)
{
Package message = (Package)o;
byte[] data = message.Data.get();
byte[] data = pkg.Data.get();
MemoryStream memstream = new MemoryStream();
BinaryWriter b = new BinaryWriter(memstream);
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);
byte[] s = memstream.ToArray();
tcpClient.Client.Send(s);
......@@ -291,6 +327,23 @@ public static class TcpHelper
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)
{
......
......@@ -93,7 +93,7 @@ public class SelectServer : WindowServantSP
}
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";
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