Code Monkey home page Code Monkey logo

client-unity's People

Contributors

valkyrienyanko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

bmjoy

client-unity's Issues

Communicating Between 2 Threads

The client has 2 threads, the unity thread and the enet thread. ENet must run on its own separate thread otherwise it will clog up the unity thread. The need for doing Unity related things during ENet specific events like when a packet has been received or a connection event occurs has risen.

Consider the following code to communicate from enet thread to unity thread.

public class UnityInstruction 
{
    public UnityInstructionOpcode Opcode { get; set; }
    public List<object> Data { get; set; }

    public UnityInstruction(UnityInstructionOpcode opcode) 
    {
        Opcode = opcode;
        Data = new List<object>();
    }

    public void Write(object obj) 
    {
        Data.Add(obj);
    }
}

public enum UnityInstructionOpcode
{
    LoadSceneForDisconnectTimeout,
    LoadMainScene,
    LogMessage,
    ServerResponseMessage,
    NotifyUserOfTimeout,
    UpdateGoldText,
    LoginSuccess
}
// ENet Thread
var instruction = new UnityInstruction(UnityInstructionOpcode.ServerResponseMessage);
instruction.Write($"Version mismatch. Server ver. {serverVersion} Client ver. {clientVersion}");

unityInstructions.Enqueue(instruction);
// Unity Thread
while (unityInstructions.TryDequeue(out UnityInstruction result)) 
{
    switch (result.Opcode) 
    {
        case UnityInstructionOpcode.ServerResponseMessage:
            loginScript.loginFeedbackText.text = (string)result.Data[0];
            break;
    }
}

The above works just fine. My question is, is there a better way about doing this?

UpdateUI Coroutine Does Not Start Again

Steps to Reproduce

  1. Connect client to server (notice the message spam of the number 100 in console)
  2. Stop server
  3. Wait for the client to timeout to the login screen
  4. Start server
  5. Login the client
  6. Notice the UILoop isn't running now (notice the message spam of the number 100 is no longer being logged)

Question about Unity Input and ENet Thread Safety

Since ENet is generally said not to be thread safe, should Peer be defined in the scope of the ENet thread worker? If this is the case how would one do peer.Send(...) inside Unity's Update() loop? Below can be seen the current method for using peer.Send(...) as one defined Peer outside the scope of the thread worker.

https://github.com/Kittens-Rise-Up/client/blob/5bf0b7ab36ff53b09e5eb3fbb2aec008158cccc5/Assets/Scripts/ENetClient.cs#L22

https://github.com/Kittens-Rise-Up/client/blob/5bf0b7ab36ff53b09e5eb3fbb2aec008158cccc5/Assets/Scripts/ENetClient.cs#L105-L112

https://github.com/Kittens-Rise-Up/client/blob/5bf0b7ab36ff53b09e5eb3fbb2aec008158cccc5/Assets/Scripts/ENetClient.cs#L114-L120

UI: Terminal Output Issues / QoL Requests

Dragging

You can only drag the terminal output vertically if you are grabbing the text. You should be able to grab from anywhere and move the terminal output up and down.

Snap to Bottom

If you drag the terminal output up, it will not snap back to the bottom as this has not been implemented yet.

image

Console Warning: Failed to load XML documentation

Sometimes this warning pops up in the console, I have no idea why.

Failed to load XML documentation:
System.Threading.ThreadAbortException
  at System.Xml.XmlTextReaderImpl+NodeData.SetNamedNode (System.Xml.XmlNodeType type, System.String localName, System.String prefix, System.String nameWPrefix) [0x00007] in <0f9699188f0c414ea6fb5557f5c16d15>:0 
  at System.Xml.XmlTextReaderImpl.AddAttribute (System.String localName, System.String prefix, System.String nameWPrefix) [0x0001e] in <0f9699188f0c414ea6fb5557f5c16d15>:0 
  at System.Xml.XmlTextReaderImpl.AddAttribute (System.Int32 endNamePos, System.Int32 colonPos) [0x0003b] in <0f9699188f0c414ea6fb5557f5c16d15>:0 
  at System.Xml.XmlTextReaderImpl.ParseAttributes () [0x00263] in <0f9699188f0c414ea6fb5557f5c16d15>:0 
  at System.Xml.XmlTextReaderImpl.ParseElement () [0x001df] in <0f9699188f0c414ea6fb5557f5c16d15>:0 
  at System.Xml.XmlTextReaderImpl.ParseElementContent () [0x0016f] in <0f9699188f0c414ea6fb5557f5c16d15>:0 
  at System.Xml.XmlTextReaderImpl.Read () [0x00085] in <0f9699188f0c414ea6fb5557f5c16d15>:0 
  at System.Xml.Linq.XContainer.ReadContentFrom (System.Xml.XmlReader r) [0x00201] in <a9ef27d60e3144519c0741b6584ba229>:0 
  at System.Xml.Linq.XContainer.ReadContentFrom (System.Xml.XmlReader r, System.Xml.Linq.LoadOptions o) [0x00005] in <a9ef27d60e3144519c0741b6584ba229>:0 
  at System.Xml.Linq.XDocument.Load (System.Xml.XmlReader reader, System.Xml.Linq.LoadOptions options) [0x00080] in <a9ef27d60e3144519c0741b6584ba229>:0 
  at System.Xml.Linq.XDocument.Load (System.String uri, System.Xml.Linq.LoadOptions options) [0x0000f] in <a9ef27d60e3144519c0741b6584ba229>:0 
  at System.Xml.Linq.XDocument.Load (System.String uri) [0x00000] in <a9ef27d60e3144519c0741b6584ba229>:0 
  at Unity.VisualScripting.XmlDocumentation.GetDocumentationUncached (System.Reflection.Assembly assembly) [0x00094] in C:\Users\VALK-DESKTOP\Documents\Unity Projects\Kittens Rise Up\client\Library\PackageCache\[email protected]\Editor\VisualScripting.Core\Documentation\XmlDocumentation.cs:132 
UnityEngine.Debug:LogWarning (object)
Unity.VisualScripting.XmlDocumentation:GetDocumentationUncached (System.Reflection.Assembly) (at Library/PackageCache/[email protected]/Editor/VisualScripting.Core/Documentation/XmlDocumentation.cs:136)
Unity.VisualScripting.XmlDocumentation:BackgroundWork () (at Library/PackageCache/[email protected]/Editor/VisualScripting.Core/Documentation/XmlDocumentation.cs:49)
System.Reflection.MethodBase:Invoke (object,object[])
Unity.VisualScripting.BackgroundWorker/<>c__DisplayClass0_0:<.cctor>b__3 () (at Library/PackageCache/[email protected]/Editor/VisualScripting.Core/Threading/BackgroundWorker.cs:82)
Unity.VisualScripting.BackgroundWorker:Work () (at Library/PackageCache/[email protected]/Editor/VisualScripting.Core/Threading/BackgroundWorker.cs:157)
System.Threading.ThreadHelper:ThreadStart ()

UILoop Coroutine Does Not End on Timeout to Server

The UILoop coroutine should be stopped when the player times out from the server.

The client player gold / other simulation values should be reset as well.

The terminal feedback window should be cleared as well.

Communicating Dynamic Data Lengths Between 2 Threads

A need for communicating data with unpredictable length has risen.

I need to be able to send gold and structureHut data or sometimes just gold or sometimes just structureHut data alone. This will get even messier when new resources and structures are added in the future.

Solution 1

Data looks like the following...

opcode, data, opcode, data, opcode, data, ....

Each opcode describes what each data is in the list.

Solution 2

Data looks like the following...

opcode, data, data, data
opcode, data, data
opcode, data, data, data, data

This solution would require many combinations of opcodes. For e.g. goldHut if wanting to send data info about gold and huts or gold opcode if just wanting to send data about gold. This is really messy.

UI: text_ServerResponse width is not dynamic

text_ServerResponse width is set to 600, ideally this should be set dynamically so it fills the entire screen however the Vertical Layout Group component is constantly resetting the anchor preset to the top left. (text_ServerResponse should retain its position in the vertical layout while stretching its width to the full monitor width)

image
image
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.