Esempio n. 1
0
        bool WriteFrame(Frame a_frame)
        {
            if (!m_internalClient.IsConnected)
            {
                InternalConsole.AddMessage("Failed to write to disconnected stream");
            }

            try
            {
                m_internalClient.WriteToStream(a_frame.ToBytes());

                return(true);
            }
            catch (IOException e)
            {
                InternalConsole.Error(string.Format("Discord Client: Failed to write frame: IOException: {0}", e.Message));
            }
            catch (ObjectDisposedException)
            {
                InternalConsole.Error("Discord Client: Failed to write frame: Disposed");
            }
            catch (InvalidOperationException)
            {
                InternalConsole.Error("Discord Client: Invalid Operaion when writing frame");
            }

            return(false);
        }
Esempio n. 2
0
        public void ModifyObject()
        {
            m_handle = GL.CreateProgram();

            PixelShader    pixelShader    = m_program.PixelShader;
            GeometryShader geometryShader = m_program.GeometryShader;
            VertexShader   vertexShader   = m_program.VertexShader;

            if (pixelShader != null)
            {
                GL.AttachShader(m_handle, ((OpenTKPixelShader)pixelShader.InternalObject).Handle);
            }
            if (geometryShader != null)
            {
                GL.AttachShader(m_handle, ((OpenTKGeometryShader)geometryShader.InternalObject).Handle);
            }
            if (vertexShader != null)
            {
                GL.AttachShader(m_handle, ((OpenTKVertexShader)vertexShader.InternalObject).Handle);
            }

            GL.LinkProgram(m_handle);

#if DEBUG_INFO
            string info;
            GL.GetProgramInfoLog(m_handle, out info);

            if (!string.IsNullOrEmpty(info))
            {
                InternalConsole.AddMessage(info, InternalConsole.e_Alert.Warning);
            }
#endif
        }
Esempio n. 3
0
        public static Canvas LoadGUI(string a_filename, IFileSystem a_fileSystem, Pipeline a_pipeline)
        {
            if (a_fileSystem != null)
            {
                Stream stream;
                if (a_fileSystem.Load(a_filename, out stream))
                {
                    XmlDocument xmlDocument = new XmlDocument();
                    xmlDocument.Load(stream);

                    Canvas canv = Load(xmlDocument, a_fileSystem, a_pipeline);

                    if (canv != null)
                    {
                        canv.m_fileSystem = a_fileSystem;
                    }

                    return(canv);
                }
                else
                {
                    InternalConsole.Error("Cannot access canvas file");
                }
            }
            else
            {
                InternalConsole.Error("No filesystem to load from for canvas");
            }

            return(null);
        }
Esempio n. 4
0
        void Error(IntPtr a_errorStr)
        {
            string str = Marshal.PtrToStringAnsi(a_errorStr);

            if (!string.IsNullOrEmpty(str))
            {
                InternalConsole.Error(str);
            }
        }
Esempio n. 5
0
        public static void GLError(string a_error)
        {
            ErrorCode error = GL.GetError();

            if (error != ErrorCode.NoError)
            {
                InternalConsole.AddMessage(a_error + error.ToString(), InternalConsole.e_Alert.Error);
            }
        }
Esempio n. 6
0
        public Device()
        {
            if (m_activeDevice == null)
            {
                m_activeDevice = this;
            }

            InitContext();

            InternalConsole.AddMessage(string.Format("Init OpenAL: Version: {0}, Vendor {1}, Renderer {2}", AL.Get(ALGetString.Version), AL.Get(ALGetString.Vendor), AL.Get(ALGetString.Renderer)));
        }
Esempio n. 7
0
        void ProcessCommandQueue()
        {
            if (m_state != e_RPCState.Connected)
            {
                return;
            }

            bool     write   = m_commandQueue.Count > 0;
            ICommand command = null;

            while (write && m_internalClient.IsConnected)
            {
                command = m_commandQueue.Peek();

                if (command is CloseCommand)
                {
                    m_state = e_RPCState.Disconnected;

                    if (!WriteFrame(new Frame(Frame.e_OpCode.Close, new Handshake()
                    {
                        Version = m_version, ClientID = m_clientID
                    })))
                    {
                        InternalConsole.Error("Discord Client: Handwave Failed");
                    }

                    return;
                }
                else
                {
                    IPayload payload = command.PreparePayload(m_nounce++);

                    Frame frame = new Frame();

                    if (!m_shutdown)
                    {
                        frame.OpCode = Frame.e_OpCode.Frame;
                        frame.SetObject(payload);

                        WriteFrame(frame);
                    }
                }

                m_commandQueue.Dequeue();
                write = m_commandQueue.Count > 0;
            }
        }
Esempio n. 8
0
            public void ModifyObject()
            {
                int shader = GL.CreateShader(ShaderType.VertexShader);

                GL.ShaderSource(shader, m_source);
                GL.CompileShader(shader);

                m_shader.Handle = shader;
#if DEBUG_INFO
                string info = GL.GetShaderInfoLog(shader);

                if (info != string.Empty)
                {
                    InternalConsole.AddMessage(info, InternalConsole.e_Alert.Warning);
                }
#endif
            }
Esempio n. 9
0
        void ProcessEvent(EventPayload a_event)
        {
            if (a_event.Event.HasValue && a_event.Event == EventPayload.e_ServerEvent.Error)
            {
                ErrorMessage error = a_event.GetObject <ErrorMessage>();

                InternalConsole.Error(string.Format("Discord responded with error: ({0}) {1}", error.ErrorCode, error.Message));

                EnqueueMessage(error);
            }

            if (m_state == e_RPCState.Connecting)
            {
                if (a_event.Command == e_Command.Dispatch && a_event.Event.HasValue && a_event.Event.Value == EventPayload.e_ServerEvent.Ready)
                {
                    m_state = e_RPCState.Connected;

                    ReadyMessage ready = a_event.GetObject <ReadyMessage>();

                    m_config = ready.Configuration;

                    User user = ready.User;

                    user.Configuration = ready.Configuration;

                    ready.User = user;
                    m_user     = user;

                    EnqueueMessage(ready);

                    return;
                }
            }

            // TODO: Implement Connected Commands
            if (m_state == e_RPCState.Connected)
            {
                switch (a_event.Command)
                {
                case e_Command.Dispatch:
                {
                    break;
                }
                }
            }
        }
Esempio n. 10
0
        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;
            }
        }
Esempio n. 11
0
        void EndRead(IAsyncResult a_callback)
        {
            int bytes = -1;

            try
            {
                bytes = m_stream.EndRead(a_callback);
            }
            catch (IOException)
            {
                InternalConsole.Error("Discord Client: Attempted to read from closed pipe");

                return;
            }
            catch (ObjectDisposedException)
            {
                InternalConsole.Error("Discord Client: Attempted to end reading from a disposed pipe");

                return;
            }
            catch (NullReferenceException)
            {
                InternalConsole.Error("Discord Client: Attempted to connect to null pipe");

                return;
            }

            if (bytes > 0)
            {
                Frame frame = Frame.FromBytes(m_buffer);

                if (frame != null)
                {
                    Client.EnqueueFrame(frame);
                }
            }

            if (m_stream.IsConnected)
            {
                BeginRead();
            }
        }
Esempio n. 12
0
        void Disposal()
        {
            while (!m_disposalQueue.IsEmpty)
            {
                IRenderObject obj;

                if (!m_disposalQueue.TryDequeue(out obj))
                {
                    InternalConsole.AddMessage("Graphics: Diposal Dequeue Failed", InternalConsole.e_Alert.Error);

                    return;
                }

                obj.RemoveObject(m_drawingObjects, m_updateRenderers);

#if DEBUG_INFO
                Pipeline.GLError("Graphics: Disposal: ");
#endif
            }
        }
Esempio n. 13
0
        void Disposal()
        {
            while (!m_disposalQueue.IsEmpty)
            {
                IGraphicsObject obj;

                if (!m_disposalQueue.TryDequeue(out obj))
                {
                    InternalConsole.AddMessage("Pipeline: Disposal Dequeue Failed", InternalConsole.e_Alert.Warning);

                    return;
                }

                obj.DisposeObject();

#if DEBUG_INFO
                Pipeline.GLError("Pipeline: Disposal: ");
#endif
            }
        }
Esempio n. 14
0
        public override bool AttemptConnection(string a_pipe)
        {
            m_socket          = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);
            m_socket.Blocking = false;

            UnixEndPoint endPoint = new UnixEndPoint(string.Format("{0}/{1}", m_envPath, a_pipe));

            try
            {
                m_socket.Connect(endPoint);
            }
            catch (Exception e)
            {
                InternalConsole.Error(string.Format("Failed to connect to {0}: {1}", a_pipe, e.Message));

                return(false);
            }

            return(true);
        }
Esempio n. 15
0
        void Input()
        {
            while (!m_inputQueue.IsEmpty)
            {
                IGraphicsObject obj;

                if (!m_inputQueue.TryDequeue(out obj))
                {
                    InternalConsole.AddMessage("Pipeline: Input Dequeue Failed", InternalConsole.e_Alert.Warning);

                    return;
                }

                obj.ModifyObject();

#if DEBUG_INFO
                Pipeline.GLError("Pipeline: Input: ");
#endif
            }
        }
Esempio n. 16
0
        void Input()
        {
            while (!m_inputQueue.IsEmpty)
            {
                IRenderObject obj;

                if (!m_inputQueue.TryDequeue(out obj))
                {
                    InternalConsole.AddMessage("Graphics: Input Dequeue Failed", InternalConsole.e_Alert.Error);

                    return;
                }

                obj.AddObject(m_drawingObjects, m_updateRenderers);

#if DEBUG_INFO
                Pipeline.GLError("Graphics: Input: ");
#endif
            }
        }
Esempio n. 17
0
        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);
                }
            }
        }
Esempio n. 18
0
        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);
                }
            }
        }
Esempio n. 19
0
        public override bool AttemptConnection(string a_pipe)
        {
            try
            {
                m_stream = new NamedPipeClientStream(".", a_pipe, PipeDirection.InOut, PipeOptions.Asynchronous);
                m_stream.Connect(1000);

                do
                {
                    Thread.Sleep(10);
                }while (!m_stream.IsConnected);

                InternalConsole.AddMessage(string.Format("Connected: {0}", a_pipe));

                return(true);
            }
            catch (Exception e)
            {
                InternalConsole.Error(string.Format("Failed to connect to {0}: {1}", a_pipe, e.Message));
            }

            return(false);
        }
Esempio n. 20
0
        static void Main(string[] args)
        {
            InternalConsole.Init();

            while (true)
            {
                Console.Write(_consoleChars);
                var line = Console.ReadLine();

                if (line == null)
                {
                    continue;
                }

                if (!string.IsNullOrWhiteSpace(line) && line.Trim().Equals("quit", StringComparison.OrdinalIgnoreCase))
                {
                    break;
                }

                if (!string.IsNullOrWhiteSpace(line) && line.Trim().Equals("cls", StringComparison.OrdinalIgnoreCase))
                {
                    Console.Clear();
                    continue;
                }

                if (line.Trim().Equals("car status", StringComparison.OrdinalIgnoreCase))
                {
                    Console.WriteLine($"");
                    Console.WriteLine($"CAR STATUS");
                    Console.WriteLine($"Angle: {Car.Angle}");
                    Console.WriteLine($"Speed: {Car.Speed}");
                    Console.WriteLine($"X: {Car.X}");
                    Console.WriteLine($"X: {Car.Y}");
                    Console.WriteLine($"");
                }
            }
        }
Esempio n. 21
0
        public override void BeginRead()
        {
            if (!m_socket.Connected)
            {
                return;
            }

            try
            {
                byte[] buffer = new byte[1024 * 16];

                SocketAsyncEventArgs eventArgs = new SocketAsyncEventArgs();
                eventArgs.SetBuffer(buffer, 0, buffer.Length);
                eventArgs.Completed += new EventHandler <SocketAsyncEventArgs>(EndRead);

                m_socket.ReceiveAsync(eventArgs);
            }
            catch (Exception e)
            {
                InternalConsole.Error(string.Format("Discord Client: Reading socket: {0}", e.Message));

                return;
            }
        }
Esempio n. 22
0
        public override void BeginRead()
        {
            if (!m_stream.IsConnected)
            {
                return;
            }

            try
            {
                m_stream.BeginRead(m_buffer, 0, m_buffer.Length, EndRead, m_stream.IsConnected);
            }
            catch (ObjectDisposedException)
            {
                InternalConsole.Error("Discord Client: Attempted to read from disposed stream");

                return;
            }
            catch (InvalidOperationException)
            {
                InternalConsole.Error("Discord Client: Attempted to read from closed pipe");

                return;
            }
        }
Esempio n. 23
0
        void PopulateElements(XmlNode a_node, Element a_parent)
        {
            if (a_node.NodeType == XmlNodeType.Comment)
            {
                return;
            }

            Type type = Type.GetType(a_node.Name);

            if (type == null)
            {
                type = Type.GetType("Erde.Graphics.GUI." + a_node.Name);

                if (type == null)
                {
                    InternalConsole.Error("Canvas: Invalid Element Type: " + a_node.Name);

                    return;
                }
            }

            MethodInfo methodInfo = type.GetMethod("Create", BindingFlags.Static | BindingFlags.NonPublic);

            Element element = methodInfo.Invoke(null, new object[] { a_node, m_fileSystem, m_pipeline }) as Element;

            if (element != null)
            {
                foreach (XmlAttribute att in a_node.Attributes)
                {
                    switch (att.Name.ToLower())
                    {
                    case "visible":
                    {
                        element.Visible = bool.Parse(att.Value);

                        break;
                    }

                    case "width":
                    {
                        Vector2 size = element.Size;
                        size.X       = float.Parse(att.Value);
                        element.Size = size;

                        break;
                    }

                    case "height":
                    {
                        Vector2 size = element.Size;
                        size.Y       = float.Parse(att.Value);
                        element.Size = size;

                        break;
                    }

                    case "xpos":
                    {
                        Vector2 pos = element.Position;
                        pos.X            = float.Parse(att.Value);
                        element.Position = pos;

                        break;
                    }

                    case "ypos":
                    {
                        Vector2 pos = element.Position;
                        pos.Y            = float.Parse(att.Value);
                        element.Position = pos;

                        break;
                    }

                    case "xlock":
                    {
                        for (int i = 0; i < (int)e_XLockMode.End; ++i)
                        {
                            e_XLockMode lockMode = (e_XLockMode)i;

                            if (lockMode.ToString().ToLower() == att.Value.ToLower())
                            {
                                element.XLockMode = lockMode;

                                break;
                            }
                        }

                        break;
                    }

                    case "ylock":
                    {
                        for (int i = 0; i < (int)e_YLockMode.End; ++i)
                        {
                            e_YLockMode lockMode = (e_YLockMode)i;

                            if (lockMode.ToString().ToLower() == att.Value.ToLower())
                            {
                                element.YLockMode = lockMode;

                                break;
                            }
                        }

                        break;
                    }

                    case "name":
                    {
                        if (!string.IsNullOrEmpty(att.Value))
                        {
                            m_namedElements.Add(att.Value, element);
                        }

                        break;
                    }

                    case "onhover":
                    {
                        string[] vals = att.Value.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);

                        if (vals.Length > 1)
                        {
                            Element.Interaction dele = GetAssemblyFunction(vals[0].TrimEnd(), vals[1].TrimEnd());
                            if (dele != null)
                            {
                                element.Hover += dele;
                            }
                        }

                        break;
                    }

                    case "onnormal":
                    {
                        string[] vals = att.Value.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);

                        if (vals.Length > 1)
                        {
                            Element.Interaction dele = GetAssemblyFunction(vals[0].TrimEnd(), vals[1].TrimEnd());
                            if (dele != null)
                            {
                                element.Normal += dele;
                            }
                        }

                        break;
                    }

                    case "onclick":
                    {
                        string[] vals = att.Value.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);

                        if (vals.Length > 1)
                        {
                            Element.Interaction dele = GetAssemblyFunction(vals[0].TrimEnd(), vals[1].TrimEnd());
                            if (dele != null)
                            {
                                element.Click += dele;
                            }
                        }

                        break;
                    }

                    case "onrelease":
                    {
                        string[] vals = att.Value.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);

                        if (vals.Length > 1)
                        {
                            Element.Interaction dele = GetAssemblyFunction(vals[0].TrimEnd(), vals[1].TrimEnd());
                            if (dele != null)
                            {
                                element.Release += dele;
                            }
                        }

                        break;
                    }

                    case "submenu":
                    {
                        element.SubMenuDirectory = att.Value;

                        break;
                    }
                    }
                }

                m_elements.Add(element);

                foreach (XmlNode node in a_node.ChildNodes)
                {
                    PopulateElements(node, element);
                }

                if (a_parent != null)
                {
                    element.Parent = a_parent;
                }

                element.State = Element.e_State.Normal;
                if (element.Normal != null)
                {
                    element.Normal.Invoke(this, element);
                }
            }
        }
Esempio n. 24
0
        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;
        }
Esempio n. 25
0
 void Awake()
 {
     instance         = this;
     consoleLocalRect = consoleRect;
 }
Esempio n. 26
0
        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);
            }
        }