/*
     * public byte[] _data;
     * int _length;
     *
     * public DataBuffer(int length)
     * {
     * _data = new byte[length+4];
     * _length = length;
     * }
     *
     * public DataBuffer(byte[] data)
     * {
     * _data = data;
     * _length = data.Length;
     * }
     *
     * public int Size()
     * {
     * return _length;
     * }
     *
     * public void Discard()
     * {
     * if (_data != null)
     * {
     *  _data = null;
     *  _length = 0;
     * }
     * }
     *
     * public void PokeByte(int addr, int value)
     * {
     * _data[addr] = (byte)value;
     * }
     *
     * public void PokeShort(int addr, int value)
     * {
     * Array.Copy(System.BitConverter.GetBytes((short)value), 0, _data, addr, 2);
     * }
     *
     * public void PokeInt(int addr, int value)
     * {
     * Array.Copy(System.BitConverter.GetBytes(value), 0, _data, addr, 4);
     * }
     *
     * public void PokeFloat(int addr, float value)
     * {
     * Array.Copy(System.BitConverter.GetBytes(value), 0, _data, addr, 4);
     * }
     *
     * public int PeekByte(int addr)
     * {
     * return (int)_data[addr];
     * }
     *
     * public int PeekShort(int addr)
     * {
     * return (int)System.BitConverter.ToInt16(_data, addr);
     * }
     *
     * public int PeekInt(int addr)
     * {
     * return System.BitConverter.ToInt32(_data, addr);
     * }
     *
     * public float PeekFloat(int addr)
     * {
     * return (float)System.BitConverter.ToSingle(_data, addr);
     * }
     *
     * public static DataBuffer Create(int length)
     * {
     * return new DataBuffer(length);
     * }
     */


    public static void LoadImageData(BBDataBuffer buffer, string path, int[] info)
    {
        var texture = BBXnaGame.XnaGame().LoadTexture2D(path);

        if (texture == null)
        {
            info[0] = 0; return;
        }                                                //new BBDataBuffer(0);}

        int bytes = 4;

        Console.WriteLine("textureformat " + texture.Format.ToString() + " " + path);

        if (texture.Format != SurfaceFormat.Color)
        {
            bytes = 3;
        }

        int size = texture.Width * texture.Height * bytes;

        info[0] = texture.Width;
        info[1] = texture.Height;

        //** assume new buffer since it a cast instance
        //buffer = new BBDataBuffer();
        buffer._New(size);
        texture.GetData <byte>(buffer._data, 0, size);
    }
Exemple #2
0
    public int Read( BBDataBuffer buffer,int offset,int count )
    {
        if( _stream==null ) return 0;

        try{
            int n=_stream.Read( buffer._data,offset,count );
            _position+=n;
            return n;
        }catch( IOException ex ){
        }
        return 0;
    }
Exemple #3
0
    public int Write( BBDataBuffer buffer,int offset,int count )
    {
        if( _stream==null ) return 0;

        try{
            _stream.Write( buffer._data,offset,count );
            _position+=count;
            if( _position>_length ) _length=_position;
            return count;
        }catch( IOException ex ){
        }
        return 0;
    }
Exemple #4
0
    public override int Read(BBDataBuffer buffer, int offset, int count)
    {
        if (_stream == null)
        {
            return(0);
        }

        try{
            int n = _stream.Read(buffer._data, offset, count);
            _position += n;
            return(n);
        }catch (IOException ex) {
        }
        return(0);
    }
    public override int Read(BBDataBuffer buffer, int offset, int count)
    {
        if (input == null)
            return 0;

        try
        {
            return input.Read(buffer._data, offset, count);
        }
        catch (IOException ex)
        {
        }

        return 0;
    }
    public override int Write( BBDataBuffer buffer,int offset,int count )
    {
        if (output == null)
            return 0;

        try
        {
            output.Write(buffer._data, offset, count);

            return count;
        }
        catch (IOException ex)
        {
        }

        return 0;
    }
    /*
    public byte[] _data;
    int _length;

    public DataBuffer(int length)
    {
        _data = new byte[length+4];
        _length = length;
    }

    public DataBuffer(byte[] data)
    {
        _data = data;
        _length = data.Length;
    }

    public int Size()
    {
        return _length;
    }

    public void Discard()
    {
        if (_data != null)
        {
            _data = null;
            _length = 0;
        }
    }

    public void PokeByte(int addr, int value)
    {
        _data[addr] = (byte)value;
    }

    public void PokeShort(int addr, int value)
    {
        Array.Copy(System.BitConverter.GetBytes((short)value), 0, _data, addr, 2);
    }

    public void PokeInt(int addr, int value)
    {
        Array.Copy(System.BitConverter.GetBytes(value), 0, _data, addr, 4);
    }

    public void PokeFloat(int addr, float value)
    {
        Array.Copy(System.BitConverter.GetBytes(value), 0, _data, addr, 4);
    }

    public int PeekByte(int addr)
    {
        return (int)_data[addr];
    }

    public int PeekShort(int addr)
    {
        return (int)System.BitConverter.ToInt16(_data, addr);
    }

    public int PeekInt(int addr)
    {
        return System.BitConverter.ToInt32(_data, addr);
    }

    public float PeekFloat(int addr)
    {
        return (float)System.BitConverter.ToSingle(_data, addr);
    }

    public static DataBuffer Create(int length)
    {
        return new DataBuffer(length);
    }
    */
    public static void LoadImageData(BBDataBuffer buffer, string path, int[] info)
    {
        var texture = MonkeyData.LoadTexture2D(path, gxtkApp.game.Content);
        if (texture==null) {info[0]=0; return; } //new BBDataBuffer(0);}

        int size = texture.Width * texture.Height * 4;

        info[0] = texture.Width;
        info[1] = texture.Height;

        //** assume new buffer since it a cast instance
        //buffer = new BBDataBuffer();
        buffer._New(size);
        texture.GetData<byte>(buffer._data, 0, size);

        //buffer = buffer2;
        //return buffer;
    }
Exemple #8
0
    public override int Write(BBDataBuffer buffer, int offset, int count)
    {
        if (_stream == null)
        {
            return(0);
        }

        try{
            _stream.Write(buffer._data, offset, count);
            _position += count;
            if (_position > _length)
            {
                _length = _position;
            }
            return(count);
        }catch (IOException ex) {
        }
        return(0);
    }
Exemple #9
0
    /*
    public byte[] _data;
    int _length;

    public DataBuffer(int length)
    {
        _data = new byte[length+4];
        _length = length;
    }

    public DataBuffer(byte[] data)
    {
        _data = data;
        _length = data.Length;
    }

    public int Size()
    {
        return _length;
    }

    public void Discard()
    {
        if (_data != null)
        {
            _data = null;
            _length = 0;
        }
    }

    public void PokeByte(int addr, int value)
    {
        _data[addr] = (byte)value;
    }

    public void PokeShort(int addr, int value)
    {
        Array.Copy(System.BitConverter.GetBytes((short)value), 0, _data, addr, 2);
    }

    public void PokeInt(int addr, int value)
    {
        Array.Copy(System.BitConverter.GetBytes(value), 0, _data, addr, 4);
    }

    public void PokeFloat(int addr, float value)
    {
        Array.Copy(System.BitConverter.GetBytes(value), 0, _data, addr, 4);
    }

    public int PeekByte(int addr)
    {
        return (int)_data[addr];
    }

    public int PeekShort(int addr)
    {
        return (int)System.BitConverter.ToInt16(_data, addr);
    }

    public int PeekInt(int addr)
    {
        return System.BitConverter.ToInt32(_data, addr);
    }

    public float PeekFloat(int addr)
    {
        return (float)System.BitConverter.ToSingle(_data, addr);
    }

    public static DataBuffer Create(int length)
    {
        return new DataBuffer(length);
    }
    */
    public static void LoadImageData(BBDataBuffer buffer, string path, int[] info)
    {
        var texture = MonkeyData.LoadTexture2D(path, gxtkApp.game.Content);
        if (texture==null) {info[0]=0; return; } //new BBDataBuffer(0);}

        int bytes = 4;
        Console.WriteLine("textureformat "+texture.Format.ToString()+" "+path);

        if (texture.Format != SurfaceFormat.Color) {

            bytes = 3;
        }

        int size = texture.Width * texture.Height * bytes;

        info[0] = texture.Width;
        info[1] = texture.Height;

        //** assume new buffer since it a cast instance
        //buffer = new BBDataBuffer();
        buffer._New(size);
        texture.GetData<byte>(buffer._data, 0, size);
    }
Exemple #10
0
 public virtual int Write(BBDataBuffer buffer, int offset, int count)
 {
     return(0);
 }
Exemple #11
0
 public virtual int Write( BBDataBuffer buffer,int offset,int count )
 {
     return 0;
 }
    public int Read(BBDataBuffer buffer, int offset, int count)
    {
        if(_state != 1) return 0;

        return socket.Receive(buffer._data, offset, count, 0);
    }
    public int Write(BBDataBuffer buffer, int offset, int count)
    {
        if(_state != 1) return 0;

        bool blockingState = socket.Blocking;
        int result = 0;

        try
        {
            socket.Blocking = false;
            result = socket.Send(buffer._data, offset, count, 0);
            //bb_std_lang.Print("Connected!");
        }
        catch(System.Net.Sockets.SocketException e)
        {
            // 10035 == WSAEWOULDBLOCK
            if (e.NativeErrorCode.Equals(10035))
            {
                bb_std_lang.Print("Still Connected, but the Send would block");
            }
            else
            {
                bb_std_lang.Print("Disconnected: error code {" + e.NativeErrorCode + "}!");
                _state = 2;
            }
        }
        finally
        {
            socket.Blocking = blockingState;
        }

        return result;
    }