Beispiel #1
0
  def feedback(self, screenshot, reward, isEnd):
    resized = PNMImage(80, 60)
    resized.unfilteredStretchFrom(screenshot)
    width = resized.getXSize()
    height = resized.getYSize()
    green = \
      map(lambda i: int(resized.getGreen(i % width, i / width) * 256) % 256, \
          range(0, width * height))
  
    data = struct.pack('IIffIII%sB' % len(green),
                       0xdeadbeef, self.historyFrameCounter,
                       reward, self.velocity,
                       isEnd, width, height, *green)
    
    with self.lock:
      self.bufferFeedback = data
    if isEnd:
      self.signalPlayerReady.clear()
    self.signalGameFeedback.set()

    # Make sure last frame of an episode is processed.
    if isEnd:
      while True:
        if not self.signalPlayerReady.wait(1):
          continue
        break
Beispiel #2
0
 def __map_Colours(self, planet, model, rec, pts=[]):
     col_map_path = planet.colour_map.replace(".","_low.")
     col_map_fn = Filename("{}/maps/{}".format(planet.path, col_map_path))
     col_map = PNMImage()
     col_map.read(col_map_fn)
     _cu_size = col_map.getXSize()-1
     _cv_size = col_map.getYSize()-1
    
     cols = []
     if not pts: pts = model.read("vertex")
     for pt in pts:
         u, v = self.__get_Pt_Uv(pt, _cu_size, _cv_size)
         r = col_map.getRed(u, v)
         g = col_map.getGreen(u, v)
         b = col_map.getBlue(u, v)
         pt_col = (r, g, b, 1)
         cols.append(pt_col)
     model.modify("color", cols)
Beispiel #3
0
    def __map_Colours(self, planet, model, rec, pts=[]):
        col_map_path = planet.colour_map.replace(".", "_low.")
        col_map_fn = Filename("{}/maps/{}".format(planet.path, col_map_path))
        col_map = PNMImage()
        col_map.read(col_map_fn)
        _cu_size = col_map.getXSize() - 1
        _cv_size = col_map.getYSize() - 1

        cols = []
        if not pts: pts = model.read("vertex")
        for pt in pts:
            u, v = self.__get_Pt_Uv(pt, _cu_size, _cv_size)
            r = col_map.getRed(u, v)
            g = col_map.getGreen(u, v)
            b = col_map.getBlue(u, v)
            pt_col = (r, g, b, 1)
            cols.append(pt_col)
        model.modify("color", cols)
Beispiel #4
0
    def paintAvatar(self, entry):
        """ Paints onto an avatar.  Returns true on success, false on
        failure (because there are no avatar pixels under the mouse,
        for instance). """

        # First, we have to render the avatar in its false-color
        # image, to determine which part of its texture is under the
        # mouse.
        if not self.avbuf:
            return False

        #mpos = base.mouseWatcherNode.getMouse()
        mpos = entry.getSurfacePoint(self.player)
        ppos = entry.getSurfacePoint(render)

        self.player.showThrough(BitMask32.bit(1))
        self.avbuf.setActive(True)
        base.graphicsEngine.renderFrame()
        self.player.show(BitMask32.bit(1))
        self.avbuf.setActive(False)

        # Now we have the rendered image in self.avbufTex.
        if not self.avbufTex.hasRamImage():
            print "Weird, no image in avbufTex."
            return False
        p = PNMImage()
        self.avbufTex.store(p)
        ix = int((1 + mpos.getX()) * p.getXSize() * 0.5)
        iy = int((1 - mpos.getY()) * p.getYSize() * 0.5)
        x = 1
        if ix >= 0 and ix < p.getXSize() and iy >= 0 and iy < p.getYSize():
            s = p.getBlue(ix, iy)
            t = p.getGreen(ix, iy)
            x = p.getRed(ix, iy)
        if x > 0.5:
            # Off the avatar.
            return False

        # At point (s, t) on the avatar's map.

        self.__paint(s, t)
        return True