Exemple #1
0
def generic_consend_test(server, port):
    s = socket()
    data = Buffer("hello world")
    s.connect((server, port))
    data.make_buffer_sendable()
    s.send(data.get_buf())
    s.close()
def emulated_sleep(time_slice, direction):
    global active
    active = True

    global current_dir
    current_dir = direction

    global kill_flag
    kill_flag = False

    Buffer.set(direction)
    start = time.time()

    while not kill_flag:
        stop = time.time()
        if stop - start >= time_slice:
            break

    stop = time.time()

    run_time = stop - start

    print('Served time:', int(run_time), 'seconds')

    global rem_time
    global rem_dir

    if run_time + 5 < time_slice:
        rem_time = time_slice - run_time
        rem_dir = direction

    global emergency
    emergency = False
    active = False
Exemple #3
0
 def __init__(self, settings, input_stream=None, output_stream=None):
     self.settings = settings
     self.input_stream = input_stream
     self.output_stream = output_stream
     self.carr_buffer = Buffer.Buffer(self.settings.CHUNK)
     self.mod_buffer = Buffer.Buffer(self.settings.CHUNK)
     self.output_buffer = Buffer.Buffer(self.settings.CHUNK)
     self.carrier_threshold = -40
Exemple #4
0
 def __init__(self):
     self.relations = {}
     self.selection_algorithms = ['scanning', 'binary', 'indexed']
     self.buf_size = 512
     self.blk_size = 64
     self.buffer = Buffer(self.buf_size, self.blk_size)
     self.tree = ''
     self.routing_table_join = {'nested_loop_join', 'sort_merge_join', 'hash_join'}
Exemple #5
0
def drop_table(table_name: str):
    time_start = time.time()
    Catalog.not_exists_table(table_name)
    Catalog.drop_table(table_name)
    Buffer.drop_table(table_name)
    Index.delete_table(table_name)
    time_end = time.time()
    print("Successfully drop table '%s', time elapsed : %fs." %
          (table_name, time_end - time_start))
Exemple #6
0
def create_table(table_name: str, attributes: list, pk: str):
    time_start = time.time()
    Catalog.exists_table(table_name)
    Index.create_table(table_name)
    Catalog.create_table(table_name, attributes, pk)
    Buffer.create_table(table_name)
    time_end = time.time()
    print("Successfully create table '%s', time elapsed : %fs." %
          (table_name, time_end - time_start))
Exemple #7
0
    def run(self):
        global barrier

        print "Starting " + self.name
        #Init the packet
        UDP_IP_RX = "192.168.240.3"
        UDP_IP_TX = "192.168.240.1"
        UDP_PORT = 30444

        MESSAGE1 = "Calling HTPA series devices"
        MESSAGE2 = "Bind HTPA series device"
        MESSAGE3 = "M"
        MESSAGE4 = "k"
        MESSAGE5 = "t"
        MSG = [MESSAGE1,MESSAGE2,MESSAGE3,MESSAGE4,MESSAGE5]

        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
        sock.bind((UDP_IP_RX, UDP_PORT))
        sock.settimeout(0.25)

        data = []
        buffer = []
        i = 0
        while True:
            try:
                data = sock.recv(2048) # buffer size is 1024 bytes
            except:
                data = [] 
            
            if len(data) != 0 :
                #print "received message len:", len(data)
                if len(data) == 1058 :
                    buffer = data
                elif len(data) == 1054:
                    buffer = buffer + data

                    buffer = swap(listReduce(buffer))

                    Buffer.setBuffer(buffer)

                    print "Grid", len(buffer)
                    print buffer[0]

                    barrierLock.acquire()
                    barrier = True
                    barrierLock.release()

                elif len(data) < 1000 :
                    print "received message len:", len(data)
                    print "received message :", data
            else :
                if i < len(MSG):
                    print "Sending  message:", MSG[i]
                    sock.sendto(MSG[i], (UDP_IP_TX, UDP_PORT))
                    i = i + 1
                    time.sleep(1)
    def processAlgorithm(self, progress):
        layer = dataobjects.getObjectFromUri(self.getParameterValue(self.INPUT))
        dissolve = self.getParameterValue(self.DISSOLVE)
        field = self.getParameterValue(self.FIELD)
        segments = int(self.getParameterValue(self.SEGMENTS))

        writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(
            layer.pendingFields().toList(), QGis.WKBPolygon, layer.crs())

        buff.buffering(progress, writer, 0, field, True, layer, dissolve,
                       segments)
Exemple #9
0
    def processAlgorithm(self, progress):
        layer = dataobjects.getObjectFromUri(self.getParameterValue(
            self.INPUT))
        dissolve = self.getParameterValue(self.DISSOLVE)
        field = self.getParameterValue(self.FIELD)
        segments = int(self.getParameterValue(self.SEGMENTS))

        writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(
            layer.pendingFields().toList(), QGis.WKBPolygon, layer.crs())

        buff.buffering(progress, writer, 0, field, True, layer, dissolve,
                       segments)
def makeStars():
    starPoints = []
    for i in range(3 * globs.numStars):
        starPoints.append(random.uniform(-1, 1))
    buff = Buffer(array.array("f", starPoints))

    tmp = array.array("I", [0])
    glGenVertexArrays(1, tmp)
    starVao = tmp[0]
    glBindVertexArray(starVao)
    buff.bind(GL_ARRAY_BUFFER)
    glEnableVertexAttribArray(0)
    glVertexAttribPointer(0, 3, GL_FLOAT, False, 3 * 4, 0)
    glBindVertexArray(0)
    return starVao
Exemple #11
0
    def put_code(self, output):
        code = output['utility_code_def']
        proto = output['utility_code_proto']

        proto.put(Buffer.dedent("""\
                static __Pyx_memviewslice %s(const __Pyx_memviewslice from_mvs); /* proto */
        """ % self.copy_func_name))

        copy_contents_name = get_copy_contents_name(self.from_memview, self.to_memview)

        if self.to_memview.is_c_contig:
            mode = 'c'
            contig_flag = memview_c_contiguous
        elif self.to_memview.is_f_contig:
            mode = 'fortran'
            contig_flag = memview_f_contiguous

        C = dict(
            context,
            copy_name=self.copy_func_name,
            mode=mode,
            sizeof_dtype="sizeof(%s)" % self.from_memview.dtype.declaration_code(''),
            contig_flag=contig_flag,
            copy_contents_name=copy_contents_name
        )

        _, copy_code = TempitaUtilityCode.load_as_string(
                    "MemviewSliceCopyTemplate",
                    from_file="MemoryView_C.c",
                    context=C)
        code.put(copy_code)
Exemple #12
0
 def startChatTo(self, username):
     addr = self.requestPort(username)
     if addr is None:
         return False
     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     buff = Buffer.Buffer(self.lock)
     if username in self.message_list_dict:
         service = Service_client.Service_client(
             s,
             buff,
             self.message_list_dict[username],
             self.username,
             peer=username,
             ip=self.ip)
         self.buff_dict[username] = service.buffer
     else:
         message_list = GUII.Message_list(self.chatui.Message_box_frame)
         service = Service_client.Service_client(s,
                                                 buff,
                                                 message_list,
                                                 self.username,
                                                 peer=username,
                                                 ip=self.ip)
         self.buff_dict[username] = service.buffer
         self.message_list_dict[username] = service.message_list
     print(addr)
     service.connectTo(addr)
     service.start()
     self.chatui.update()
     return True
Exemple #13
0
    def put_code(self, output):
        code = output['utility_code_def']
        proto = output['utility_code_proto']

        proto.put(
            Buffer.dedent("""\
                static __Pyx_memviewslice %s(const __Pyx_memviewslice from_mvs); /* proto */
        """ % self.copy_func_name))

        copy_contents_name = get_copy_contents_name(self.from_memview,
                                                    self.to_memview)

        if self.to_memview.is_c_contig:
            mode = 'c'
            contig_flag = memview_c_contiguous
        elif self.to_memview.is_f_contig:
            mode = 'fortran'
            contig_flag = memview_f_contiguous

        C = dict(context,
                 copy_name=self.copy_func_name,
                 mode=mode,
                 sizeof_dtype="sizeof(%s)" %
                 self.from_memview.dtype.declaration_code(''),
                 contig_flag=contig_flag,
                 copy_contents_name=copy_contents_name)

        _, copy_code = UtilityCode.load_as_string("MemviewSliceCopyTemplate",
                                                  from_file="MemoryView_C.c",
                                                  context=C)
        code.put(copy_code)
Exemple #14
0
def main():
    """"
    Test functionality
    """
    _buffer_ = Buffer.Buffer(4)

    threads = []

    for i in range(3):
        _aux_ = Producer.Producer(_buffer_)
        threads.append(_aux_)

    for i in range(5):
        _aux_ = Consumer.Consumer(30, _buffer_)
        threads.append(_aux_)

    for i in range(8):
        threads[i].start()

    for i in range(8):
        threads[i].join()

    Consumer.Consumer._ans_.sort(key=lambda x: x[1])
    print map(lambda x: x[0], Consumer.Consumer._ans_)
    print _buffer_._check_ans_
Exemple #15
0
def insert(table_name: str, values: list):
    time_start = time.time()
    Catalog.not_exists_table(table_name)
    Catalog.check_types_of_table(table_name, values)
    linenum = Buffer.insert_record(table_name, values)
    Index.insert_into_table(table_name, values, linenum)
    time_end = time.time()
    print(" time elapsed : %fs." % (time_end - time_start))
def main():
    # Read the inputs from the file
    buf_size, num_pkts, packets = read_input('./testcases.txt')

    # Create the packet buffer
    buffer = Buffer.Buffer(buf_size)

    # Process the packets
    process_packets(buffer, packets)
 def readBlob(self, fp, name):
     line = fp.readline().decode()
     assert line.startswith(name)
     lst = line.split()
     numbytes = int(lst[1])
     blob = fp.read(numbytes)
     fp.readline()
     B = Buffer(blob)
     return B
Exemple #18
0
def delete(table_name: str, where: list = None):
    time_start = time.time()
    Catalog.not_exists_table(table_name)
    Catalog.check_select_statement(table_name, ['*'], where)  # 从insert中借用的方法
    col = Catalog.get_column_dic(table_name)
    pklist = Buffer.delete_record(table_name, col, where)
    Index.delete_from_table(table_name, pklist)
    time_end = time.time()
    print(" time elapsed : %fs." % (time_end - time_start))
 def getBlob(self, fp, tag):
     line = fp.readline().decode()
     lst = line.split()
     assert lst[0] == tag
     numbytes = int(lst[1])
     B = fp.read(numbytes)
     buf = Buffer(B)
     fp.readline()  # discard empty line
     return buf
Exemple #20
0
def main():
    global ROW
    global COLUMN

    Buffer.initBuffer(ROW * COLUMN)

    grid = Grid(ROW,COLUMN)

    Udp.init()

    app = wx.App()
    frame = wx.Frame(None, -1, 'TestFrame.py')

    box = Box(frame, -1, grid, grid.updateBuffer)

    box.timer.Start(10)  # Frame Rate 5 miliseconds

    box.Draw(grid,X_COORD,Y_COORD,BOX_WIDTH,BOX_HEIGHT)
     
    frame.Show(True)
    app.MainLoop()
def bindVao(vArray, iArray=None):
    vBuff = Buffer.Buffer(vArray)
    # GenerateVAO
    tmp = array.array("I", [0])
    glGenVertexArrays(1, tmp)
    vao = tmp[0]
    glBindVertexArray(vao)

    # Tell GL about buffer layout and use the buffer
    # Bind index buffer to point at vertexbuffers indicies if available
    if iArray != None and len(iArray) != 0:
        ibuff = Buffer.Buffer(iArray)
        ibuff.bind(GL_ELEMENT_ARRAY_BUFFER)

    vBuff.bind(GL_ARRAY_BUFFER)

    glEnableVertexAttribArray(0)

    # which pipe, items per vertex, type per item, auto-normalize, data size per item in bytes, start in buffer
    # numPoints = len(arrayOfPoints)
    glVertexAttribPointer(0, 2, GL_FLOAT, False, 2 * 4, 0)
Exemple #22
0
    def __init__(self, sizeOfBuffer, numberOfCores, numberOfThreads,
                 timeQuantum, contextSwitchTime):
        Buffer.Buffer.initBufferCount()
        self.buffer = Buffer.Buffer(sizeOfBuffer)
        self.numberOfCores = numberOfCores
        self.cores = []

        for y in list(range(numberOfCores)):
            self.cores.append(Core.Core(y, 0))

        self.threadPool = ThreadPool.ThreadPool(numberOfThreads)
        self.timeQuantum = timeQuantum
        self.contextSwitchTime = contextSwitchTime
    def setupUniforms(prog):
        tmp = array.array("I", [0])
        glGetProgramiv(prog, GL_ACTIVE_UNIFORMS, tmp)
        numuniforms = tmp[0]
        uniformsToQuery = array.array("I", range(numuniforms))
        offsets = array.array("I", [0] * numuniforms)
        sizes = array.array("I", [0] * numuniforms)
        types = array.array("I", [0] * numuniforms)
        glGetActiveUniformsiv(prog, numuniforms, uniformsToQuery,
                              GL_UNIFORM_OFFSET, offsets)
        glGetActiveUniformsiv(prog, numuniforms, uniformsToQuery,
                              GL_UNIFORM_SIZE, sizes)
        glGetActiveUniformsiv(prog, numuniforms, uniformsToQuery,
                              GL_UNIFORM_TYPE, types)

        sizeForType = {
            GL_FLOAT_VEC4: 4 * 4,
            GL_FLOAT_VEC3: 3 * 4,
            GL_FLOAT_VEC2: 2 * 4,
            GL_FLOAT: 1 * 4,
            GL_INT: 1 * 4,
            GL_FLOAT_MAT4: 4 * 16,
            GL_FLOAT_MAT3: 3 * 16,
            GL_FLOAT_MAT2: 2 * 16
        }

        nameBytes = bytearray(256)
        Program.totalUniformBytes = 0
        for i in range(numuniforms):
            glGetActiveUniformName(prog, i, len(nameBytes), tmp, nameBytes)
            nameLen = tmp[0]
            name = nameBytes[:nameLen].decode()
            if offsets[i] != 0xffffffff:
                assert sizes[i] == 1 or types[i] == GL_FLOAT_VEC4
                numBytes = sizeForType[types[i]] * sizes[i]
                Program.uniforms[name] = (offsets[i], numBytes, types[i],
                                          sizes[i])
                end = offsets[i] + numBytes
                if end > Program.totalUniformBytes:
                    Program.totalUniformBytes = end
        #create_string_buffer is inside the ctypes package
        Program.uboBackingMemory = create_string_buffer(
            Program.totalUniformBytes)
        #addressof is from ctypes too
        Program.uboBackingAddress = addressof(Program.uboBackingMemory)
        Program.ubo = Buffer(data=None,
                             size=Program.totalUniformBytes,
                             usage=GL_DYNAMIC_DRAW)

        Program.ubo.bindBase(GL_UNIFORM_BUFFER, 0)
Exemple #24
0
def setup(pointArray):
    glEnable(GL_MULTISAMPLE)
    glClearColor(0, 0, 0, 1.0)

    my_buffer = Buffer(pointArray)#array.array("f", [0, 0]))
    # GenerateVAO
    tmp = array.array("I", [0])
    glGenVertexArrays(1, tmp)
    vao = tmp[0]
    glBindVertexArray(vao)

    # Tell GL about buffer layout and use the buffer
    my_buffer.bind(GL_ARRAY_BUFFER)
    glEnableVertexAttribArray(0)
    # which pipe, items per vertex, type per item, auto-normalize, data size per item in bytes, start in buffer
    # numPoints = len(arrayOfPoints)
    glVertexAttribPointer(0, 2, GL_FLOAT, False, 2 * 4, 0)

    # unbind
    # glBindVertexArray(0)

    prog = Program("vs.txt", "fs.txt")
    prog.use()
Exemple #25
0
def RunSatellite():

    # Add the FOR loops first

    buffer = Buffer.Buffer(10)
    buff = buffer.getBuffer()

    satellie = Satellite.Satellite(buff, 10)
    satellie.start()

    satellie.join()

    receiver = Receiver.Receiver(buff, 10)
    receiver.start()

    receiver.join()
Exemple #26
0
    def __init__(self, fontname, size):
        if Text.prog == None:
            Text.prog = Program("TextVertexShader.txt",
                                "TextFragmentShader.txt")

        self.txt = "temp"
        self.samp = Sampler()
        self.font = TTF_OpenFont(
            os.path.join("assets", fontname).encode(), size)
        open(os.path.join("assets", fontname))
        vbuff = Buffer(array.array("f", [0, 0, 1, 0, 1, 1, 0, 1]))
        ibuff = Buffer(array.array("I", [0, 1, 2, 0, 2, 3]))
        tmp = array.array("I", [0])
        glGenVertexArrays(1, tmp)
        self.vao = tmp[0]
        glBindVertexArray(self.vao)
        ibuff.bind(GL_ELEMENT_ARRAY_BUFFER)
        vbuff.bind(GL_ARRAY_BUFFER)
        glEnableVertexAttribArray(0)
        glVertexAttribPointer(0, 2, GL_FLOAT, False, 2 * 4, 0)
        glBindVertexArray(0)
        self.tex = DataTexture2DArray(1, 1, 1, array.array("B", [0, 0, 0, 0]))
        self.textQuadSize = vec2(0, 0)
        self.pos = vec2(0, 0)
        self.dirty = False
        surf1p = TTF_RenderUTF8_Blended(self.font, self.txt.encode(),
                                        SDL_Color(255, 255, 255, 255))
        surf2p = SDL_ConvertSurfaceFormat(surf1p, SDL_PIXELFORMAT_ABGR8888, 0)
        w = surf2p.contents.w
        h = surf2p.contents.h
        pitch = surf2p.contents.pitch
        if pitch != w * 4:
            print("Uh Oh!", pitch, w)
        pix = surf2p.contents.pixels
        B = string_at(pix, pitch * h)
        self.tex.setData(w, h, 1, B)
        SDL_FreeSurface(surf2p)
        SDL_FreeSurface(surf1p)
        self.textQuadSize = vec2(w, h)
        self.dirty = False

        Program.setUniform("textPosInPixels", self.pos)
        Program.setUniform("textQuadSizeInPixels", self.textQuadSize)
        Program.updateUniforms()
Exemple #27
0
def select(table_name: str, attributes: list, where: list = None):
    time_start = time.time()
    Catalog.not_exists_table(table_name)
    Catalog.check_select_statement(table_name, attributes, where)
    #Index.select_from_table(table_name, attributes, where)
    col_dic = Catalog.get_column_dic(table_name)
    results = Buffer.find_record(table_name, col_dic, where)
    numlist = []
    if attributes == ['*']:
        attributes = list(col_dic.keys())
        numlist = list(col_dic.values())
    else:
        for att in attributes:
            numlist.append(col_dic[att])

    print_select(attributes, numlist, results)
    time_end = time.time()
    print(" time elapsed : %fs." % (time_end - time_start))
 def __init__(self, fontname, size):
     if Text.prog == None:
         Text.prog = Program("textvs.txt", "textfs.txt")
         TTF_Init()
     self.font = TTF_OpenFont(
         os.path.join("assets", fontname).encode(), size)
     vbuff = Buffer(array.array("f", [0, 0, 1, 0, 1, 1, 0, 1]))
     ibuff = Buffer(array.array("I", [0, 1, 2, 0, 2, 3]))
     tmp = array.array("I", [0])
     glGenVertexArrays(1, tmp)
     self.vao = tmp[0]
     glBindVertexArray(self.vao)
     ibuff.bind(GL_ELEMENT_ARRAY_BUFFER)
     vbuff.bind(GL_ARRAY_BUFFER)
     glEnableVertexAttribArray(0)
     glVertexAttribPointer(0, 2, GL_FLOAT, False, 2 * 4, 0)
     glBindVertexArray(0)
     self.tex = DataTexture2DArray(1, 1, 1, array.array("B", [0, 0, 0, 0]))
     self.textQuadSize = vec2(0, 0)
     self.pos = vec2(0, 0)
     self.dirty = False
Exemple #29
0
 def recv_traffic(self):
     print "Receiving client: ",str(self.client.getpeername())
     current_length = 0
     data_buf = Buffer()
     while self.listen and self.client:
         try:
             self.conn_lock.acquire()
             #print "Looping...."
             # will read the initial packet
             if current_length > 0:
                 t = self.client.recv(current_length)
                 current_length -= len(t)
                 data_buf.append(t)
             elif current_length == 0:
                 # clear buffer and wait
                 # for new pkt
                 #print "Data buffer was reset, recv'ing a new buf"
                 data_buf.append(self.client.recv(4))
                 current_length = data_buf.read_int() - 4
                 print "Recieved the current length %x"%(current_length+4)
             if current_length == 0 and len(data_buf) > 0:
                 print "Handling the following pkt: %s"%(repr(data_buf.get_buf()))
                 self.handle_recv(data_buf)
                 data_buf = Buffer()
             self.conn_lock.release()
         except timeout:
             if self.conn_lock.locked():
                 self.conn_lock.release()
             print "Timeout occured on the client"
             pass
         except Exception, e:
             if self.conn_lock.locked():
                 self.conn_lock.release()
             if str(sys.exc_info()[1]).find("Errno 10035") > -1:
                 pass
             else:
                 print "Exception Type: %s"%(str(sys.exc_info()[0]))
                 print "Exception Message: %s"%(str(sys.exc_info()[1]))
                 raise e
Exemple #30
0
    def listen_run(self):
        self.listen_socket.listen()
        while self.listen_flag:
            print('accept1')
            conn, addr = self.listen_socket.accept()
            if self.listen_flag:
                buff = Buffer.Buffer(self.lock)
                message_list = GUII.Message_list(self.chatui.Message_box_frame)
                service = Service_client.Service_client(conn,
                                                        buff,
                                                        message_list,
                                                        self.username,
                                                        ip=self.ip)
                self.buff_dict[service.peer] = service.buffer
                if service.peer in self.message_list_dict:
                    service.message_list = self.message_list_dict[service.peer]
                else:
                    self.message_list_dict[service.peer] = service.message_list
                self.chatui.update()
                service.start()

        print('closed')
def evaluate(clientsocket, addr):
    print "Visualisation connected"
    BufferList = Buffer.PiBuffer()
    while True:
        time.sleep(2)
        try:
            evaluatedlist = scannedData.evaluateAll()
            for x in range(len(evaluatedlist)):  # where the server thinks the phones are from raw data
                message = evaluatedlist[x][0] + "," + PiList[evaluatedlist[x][1][0]] + ","
                #print message
                BufferList.addtobuffer(evaluatedlist[x][0], PiList[evaluatedlist[x][1][0]]) # put the data into a buffer , so it can be processed further

            for x in BufferList.evaluate():

                finalmessage = x[0] + "," + x[1] + ","  # and this function returns the mode
                clientsocket.send(finalmessage)         #of those (so 1 rogue data cant go out)
                time.sleep(1)  #my vizualization needs time to process

            scannedData.clearList()
            time.sleep(0.2)

        except IndexError:
            pass
Exemple #32
0
def initialize(path: str):
    Catalog.__initialize__(path)
    Index.__initialize__(path)
    Buffer.__initialize__()
Exemple #33
0
def generic_interact_test(server, port):
    s = socket()
    data = Buffer("hello there\n")
    data.make_buffer_sendable()
    print hex(len(data.get_buf())), hex(data.read_int()),data.get_buf()
    s.connect((server, port))
    s.send(data.get_buf())
    data.reset()
    data.append("Do you have and Grey Poupon?\n")
    data.make_buffer_sendable()
    print hex(len(data.get_buf())), hex(data.read_int()),data.get_buf()
    s.send(data.get_buf())
    buf = s.recv(65535)
    print buf
    bufs = input("Enter a response")
    s.send(bufs)
    s.close()    
Exemple #34
0
def save():
    Catalog.__finalize__()
    Index.__finalize__()
    Buffer.__finalize__()
    print("All tables have been saved.")
Exemple #35
0
def mangle_dtype_name(dtype):
    # a dumb wrapper for now; move Buffer.mangle_dtype_name in here later?
    import Buffer
    return Buffer.mangle_dtype_name(dtype)
Exemple #36
0
def makeSquare(xsz, ysz, flipTextureY):
    vbuff = Buffer(
        array.array("f", [-xsz, -ysz, xsz, -ysz, xsz, ysz, -xsz, ysz]))
    if flipTextureY:
        tbuff = Buffer(array.array("f", [0, 1, 1, 1, 1, 0, 0, 0]))
    else:
        tbuff = Buffer(array.array("f", [0, 0, 1, 0, 1, 1, 0, 1]))
    ibuff = Buffer(array.array("I", [0, 1, 2, 0, 2, 3]))
    tmp = array.array("I", [0])
    glGenVertexArrays(1, tmp)
    vao = tmp[0]
    glBindVertexArray(vao)
    ibuff.bind(GL_ELEMENT_ARRAY_BUFFER)
    vbuff.bind(GL_ARRAY_BUFFER)
    glEnableVertexAttribArray(0)
    glVertexAttribPointer(0, 2, GL_FLOAT, False, 2 * 4, 0)
    tbuff.bind(GL_ARRAY_BUFFER)
    glEnableVertexAttribArray(1)
    glVertexAttribPointer(1, 2, GL_FLOAT, False, 2 * 4, 0)
    glBindVertexArray(0)
    return vao
Exemple #37
0
	def __init__(self,fichero):
		self.__counter=0
		self.__bottom=Bottom(0x00);
		self.__top=Top(0xFF);
		self.__bits=Buffer(fichero)
Exemple #38
0
class Extreme_Interval():
	def __init__(self,fichero):
		self.__counter=0
		self.__bottom=Bottom(0x00);
		self.__top=Top(0xFF);
		self.__bits=Buffer(fichero)
	def __Is_underflow(self):
		return self.__top[:2]=="10" and self.__bottom[:2]=="01"
#		if self.__top>9 and self.__bottom>9:
#			First_digit_top=self.__top/first_digit_base
#			First_digit_bottom=self.__bottom/first_digit_base
#			print self.__top
#			print self.__bottom
#			print "primer digito top: ",First_digit_top
#			print "primer digito bottom",First_digit_bottom
#			dif_in_one= (First_digit_top-First_digit_bottom)==1
#			if dif_in_one: print "ES VERDAD"
#			top_list=",".join(str(self.__top))
#			top_list=top_list.split(",")
#			Second_digit_top=int(top_list[1])
#			bottom_list=",".join(str(self.__bottom))
#			bottom_list=bottom_list.split(",")
#			Second_digit_bottom=int(bottom_list[1])
#			if len(top_list)==len(bottom_list):
#				return Second_digit_top==0 and Second_digit_bottom==9 and dif_in_one
#		return False
	def __Get_list(self,number):
		string=",".join(str(number))
		return string.split(",")
#	def __Shift_extremes(self):
#		top_list=self.__Get_list(self.__top)
#		bottom_list=self.__Get_list(self.__bottom)
#		del top_list[1]
#		del bottom_list[1]
#		top_list.append("9")
#		bottom_list.append("0")
#		self.__top=int("".join(top_list))
#		self.__bottom=int("".join(bottom_list))
	def __Process_Underflow(self):
		while self.__top.Is_Underflow(self.__bottom):
#			print "UNDERFLOW!!!!!!!"
			self.__counter+=1;
			self.__shift()
	def __shift(self):
		self.__top<<1
		self.__bottom<<1
#		if bit_bot==1:
#			self.__bottom-=0x80
#			self.__top-=0x80
#		self.__bottom*=2
#		self.__top*=2
#		self.__top+=1
	def __Store_Partial_result(self):
#		bit_bot=self.__bottom/base_one_MSB;
#		bit_top=self.__top/base_one_MSB;
		
		while self.__top[0]==self.__bottom[0]:
#			print "bit bot ",bit_bot
#			if bit_bot==0: print "SON CERO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
			self.__bits.append(chr(ord("0")+int(self.__top[0])))
			bit_complement=int(bin(~int(self.__top[0]))[-1])
			for i in range(self.__counter):
				self.__bits.append(chr(ord("0")+bit_complement))
			self.__counter=0
#			print "corro 1 lugar"
			self.__shift()
#			print "top: ",int(self.__top)
#			print "bottom: ",int(self.__bottom)

	def Get_length(self):		
		return int(self.__top)-int(self.__bottom)
	def Get_Top(self):
		return int(self.__top)
	def Get_Bottom(self):
		return int(self.__bottom)
	def Set_extremes(self,bottom,top):
		self.__bottom.Set_value(bottom)
		self.__top.Set_value(top)
	def update_bottom(self,value):
#		print "Antes... bottom: ",int(self.__bottom)
#		print value
		self.__bottom+=int(value)
#		print "Despues... bottom: ",int(self.__bottom)
	def update_top(self,my_distance):
#		print "Antes... top: ",int(self.__top)
#		print "Distancia: ",my_distance
#		print "bottom + distancia: =",int(self.__bottom)+int(my_distance)
		self.__top.Set_value(int(self.__bottom)+ int(my_distance))
#		print "Despues... top: ",int(self.__top)
	def normalizate(self):
#		print "top: ",int(self.__top)
#		print "bottom: ",int(self.__bottom)
		self.__Process_Underflow();
		self.__Store_Partial_result();
	def All_data_stored(self):
		return self.__bits.All_data_stored();
	def Bit_padding(self):
		self.__bits.Bit_padding()