void Handshake() { InternalConsole.AddMessage("Attempting Discord Handshake"); if (m_state != e_RPCState.Disconnected) { InternalConsole.Warning("Discord Client: State must be disconnected to handshake"); return; } if (WriteFrame(new Frame(Frame.e_OpCode.Handshake, new Handshake() { Version = m_version, ClientID = m_clientID }))) { m_state = e_RPCState.Connecting; } }
void Disposal() { while (!m_disposalQueue.IsEmpty) { IPObject pObject; if (!m_disposalQueue.TryDequeue(out pObject)) { InternalConsole.Warning("Physics Engine: Failed to dequeue for disposal"); return; } pObject.DisposeObject(); CollisionObject collisionObject = pObject as CollisionObject; if (collisionObject != null && m_collisionObjects.Contains(collisionObject)) { m_collisionObjects.Remove(collisionObject); } } }
void Input() { while (!m_inputQueue.IsEmpty) { IPObject pObject; if (!m_inputQueue.TryDequeue(out pObject)) { InternalConsole.Warning("Physics Engine: Failed to dequeue for writing"); return; } pObject.ModifyObject(); CollisionObject collisionObject = pObject as CollisionObject; if (collisionObject != null && !m_collisionObjects.Contains(collisionObject)) { m_collisionObjects.Add(collisionObject); } } }
void DiscordLoop() { bool connected = false; m_join = false; for (int i = 0; i < 10; ++i) { if (AttemptConnection(i)) { connected = true; break; } if (m_shutdown) { break; } } if (!connected) { InternalConsole.Error("Failed to connect to Discord"); m_shutdown = true; } else { m_internalClient.BeginRead(); EnqueueMessage(new ConnectionEstablishedMessage(m_connectedPipe)); Handshake(); while (!m_shutdown) { Frame frame; if (ReadFrame(out frame)) { switch (frame.OpCode) { case Frame.e_OpCode.Close: { ClosePayload close = frame.GetObject <ClosePayload>(); InternalConsole.AddMessage("Discord Client Remotely Terminated"); EnqueueMessage(new CloseMessage(close.Code, close.Reason)); m_shutdown = true; break; } case Frame.e_OpCode.Ping: { WriteFrame(new Frame(Frame.e_OpCode.Pong, frame.Data)); break; } case Frame.e_OpCode.Pong: { InternalConsole.Warning("Got a pong from Discord?"); break; } case Frame.e_OpCode.Frame: { if (m_shutdown) { break; } if (frame.Data == null) { InternalConsole.Error("Discord Client: No data in frame"); } EventPayload response = frame.GetObject <EventPayload>(); ProcessEvent(response); break; } default: { InternalConsole.Error("Discord Client: Invalid Operation"); m_shutdown = true; break; } } } ProcessCommandQueue(); } ProcessCommandQueue(); } m_join = true; }
public OBJLoader(string a_fileName, IFileSystem a_fileSystem) { m_vertices = new List <Vertex>(); m_indices = new List <uint>(); byte[] bytes; if (a_fileSystem.Load(a_fileName, out bytes)) { string[] lines = Encoding.UTF8.GetString(bytes).Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries); List <Vector3> vertexPosition = new List <Vector3>(); List <Vector3> vertexNormal = new List <Vector3>(); List <Vector2> vertexTextureCoords = new List <Vector2>(); Dictionary <Vertex, uint> vertexLookup = new Dictionary <Vertex, uint>(); float lengthSqr = 0.0f; foreach (string line in lines) { string l = line.ToLower(); int index = l.IndexOf(' '); string data = l.Substring(index + 1, l.Length - (index + 1)); switch (l.Substring(0, index)) { case "#": case "o": { break; } case "v": { Vector3 vertex = Vector3.Zero; string[] strings = data.Split(' '); vertex.X = float.Parse(strings[0]); vertex.Y = float.Parse(strings[1]); vertex.Z = float.Parse(strings[2]); lengthSqr = Math.Max(lengthSqr, vertex.LengthSquared); vertexPosition.Add(vertex); break; } case "vn": { Vector3 vertex = Vector3.Zero; string[] strings = data.Split(' '); vertex.X = float.Parse(strings[0]); vertex.Y = float.Parse(strings[1]); vertex.Z = float.Parse(strings[2]); vertexNormal.Add(vertex); break; } case "vt": { Vector2 vertex = Vector2.Zero; string[] strings = data.Split(' '); vertex.X = float.Parse(strings[0]); vertex.Y = 1 - float.Parse(strings[1]); vertexTextureCoords.Add(vertex); break; } case "f": { string[] strings = data.Split(' '); foreach (string s in strings) { string[] ind = s.Split('/'); Vertex vert = new Vertex() { Position = new Vector4(vertexPosition[int.Parse(ind[0]) - 1], 1) }; if (ind.Length == 2) { if (s.Count(f => f == '/') == 2) { vert.Normal = vertexNormal[int.Parse(ind[1]) - 1]; } else { vert.TexCoords = vertexTextureCoords[int.Parse(ind[1]) - 1]; } } else { vert.TexCoords = vertexTextureCoords[int.Parse(ind[1]) - 1]; vert.Normal = vertexNormal[int.Parse(ind[2]) - 1]; } uint val = 0; if (!vertexLookup.TryGetValue(vert, out val)) { m_vertices.Add(vert); val = (ushort)(m_vertices.Count - 1); vertexLookup.Add(vert, val); } m_indices.Add(val); } break; } } } m_length = (float)Math.Sqrt(lengthSqr); } else { InternalConsole.Warning("Failed to Load: " + a_fileName); } }