jsuarez/extra/embyr_deprecated/embyr/modules.py [486:567]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      self.makeMaps()
      self.tileSz = 16
      self.RED   = np.array(Defaults.RED)
      self.GREEN = np.array(Defaults.GREEN)
      self.BLUE  = np.array(Defaults.BLUE)

   def render(self):
      ents = [e.server for e in self.realm.desciples.values()]
      self.updateMaps(ents)
      maps = self.maps
      maps = maps + 15*[0*maps[0]]
      maps = maps[:16]
      mapv1 = np.vstack(maps[:4])
      mapv2 = np.vstack(maps[4:8])
      mapv3 = np.vstack(maps[8:12])
      mapv4 = np.vstack(maps[12:16])
      maps = np.hstack((mapv1, mapv2, mapv3, mapv4))

      maps = maps.astype(np.uint8)
      #maps = pygame.pixelcopy.make_surface(maps)
      #valCrop, txSz = embyr.mapCrop(self, maps,
      #      self.tileSz, trans)
      #txSz = embyr.mipKey(txSz, self.mipLevels)
      embyr.renderMap(self, maps, int(1.7*self.tileSz))
      return self.surf

   def updateMaps(self, ents):
      for ent in ents:
         attack = ent.attack.action
         #targ   = ent.attack.args
         targ = ent.targ
         if targ is None or targ.damage is None:
            continue
         idx    = ent.colorInd
         if idx >= 16:
            continue
         entr, entc = ent.attkPos
         targr, targc = ent.targPos
         r = self.MAPCENT + targr - entr
         c = self.MAPCENT + targc - entc

         if issubclass(attack, action.Melee):
            self.counts[idx][r, c, 0] += 1
         elif issubclass(attack, action.Range):
            self.counts[idx][r, c, 1] += 1
         elif issubclass(attack, action.Mage):
            self.counts[idx][r, c, 2] += 1

         rgb = self.counts[idx][r, c]
         normSum = np.sum(rgb)
         redVal   = self.RED   * rgb[0] / normSum 
         greenVal = self.GREEN * rgb[1] / normSum 
         blueVal  = self.BLUE  * rgb[2] / normSum 
         color = (redVal + greenVal + blueVal).astype(np.uint8)
         self.maps[idx][r, c] = color
         #colorIdx = np.argmax(self.counts[idx][r, c])
         #self.maps[idx][r, c] = self.colors[colorIdx]
 
   def makeMaps(self):
      self.NMAPS = 16#self.config.NPOP
      self.MAPCENT = 4 #self.config.STIM
      self.MAPSZ = 2*self.MAPCENT + 1

      self.maps = []
      self.counts = []
      for idx in range(self.NMAPS):
         self.maps.append(np.zeros((self.MAPSZ, self.MAPSZ, 3)))
         self.counts.append(np.zeros((self.MAPSZ, self.MAPSZ, 3)))


   def renderEnts(self, trans):
      self.reset()
      R, C = self.env.shape
      offs, txSz = embyr.offsets(self, R, C, self.tileSz, trans)
      txSz = embyr.mipKey(txSz, self.mipLevels)
      minH, _, minW, _ = offs
      self.sprites.render(self, (minH, minW), txSz, self.iso)
      return self.surf

   def refresh(self, trans, iso):
      self.iso = iso
      return self.render(None, trans, keyframe=False)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



jsuarez/extra/embyr_deprecated/embyr2d/modules.py [508:590]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      self.makeMaps()
      self.tileSz = 16
      self.RED   = np.array(Defaults.RED)
      self.GREEN = np.array(Defaults.GREEN)
      self.BLUE  = np.array(Defaults.BLUE)

   def render(self):
      ents = [e.server for e in self.realm.desciples.values()]
      self.updateMaps(ents)
      maps = self.maps
      maps = maps + 15*[0*maps[0]]
      maps = maps[:16]
      mapv1 = np.vstack(maps[:4])
      mapv2 = np.vstack(maps[4:8])
      mapv3 = np.vstack(maps[8:12])
      mapv4 = np.vstack(maps[12:16])
      maps = np.hstack((mapv1, mapv2, mapv3, mapv4))

      maps = maps.astype(np.uint8)
      #maps = pygame.pixelcopy.make_surface(maps)
      #valCrop, txSz = embyr.mapCrop(self, maps,
      #      self.tileSz, trans)
      #txSz = embyr.mipKey(txSz, self.mipLevels)
      embyr.renderMap(self, maps, int(1.7*self.tileSz))
      return self.surf

   def updateMaps(self, ents):
      for ent in ents:
         attack = ent.attack.action
         #targ   = ent.attack.args
         targ = ent.targ
         if targ is None or targ.damage is None:
            continue
         idx    = ent.colorInd
         if idx >= 16:
            continue
         entr, entc = ent.attkPos
         targr, targc = ent.targPos
         r = self.MAPCENT + targr - entr
         c = self.MAPCENT + targc - entc

         if issubclass(attack, action.Melee):
            self.counts[idx][r, c, 0] += 1
         elif issubclass(attack, action.Range):
            self.counts[idx][r, c, 1] += 1
         elif issubclass(attack, action.Mage):
            self.counts[idx][r, c, 2] += 1

         rgb = self.counts[idx][r, c]
         normSum = np.sum(rgb)
         redVal   = self.RED   * rgb[0] / normSum 
         greenVal = self.GREEN * rgb[1] / normSum 
         blueVal  = self.BLUE  * rgb[2] / normSum 
         color = (redVal + greenVal + blueVal).astype(np.uint8)
         self.maps[idx][r, c] = color
         #colorIdx = np.argmax(self.counts[idx][r, c])
         #self.maps[idx][r, c] = self.colors[colorIdx]
 
   def makeMaps(self):
      self.NMAPS = 16#self.config.NPOP
      self.MAPCENT = 4 #self.config.STIM
      self.MAPSZ = 2*self.MAPCENT + 1

      self.maps = []
      self.counts = []
      for idx in range(self.NMAPS):
         self.maps.append(np.zeros((self.MAPSZ, self.MAPSZ, 3)))
         self.counts.append(np.zeros((self.MAPSZ, self.MAPSZ, 3)))


   def renderEnts(self, trans):
      self.reset()
      R, C = self.env.shape
      offs, txSz = embyr.offsets(self, R, C, self.tileSz, trans)
      txSz = embyr.mipKey(txSz, self.mipLevels)
      minH, _, minW, _ = offs
      self.sprites.render(self, (minH, minW), txSz, self.iso)
      return self.surf
 

   def refresh(self, trans, iso):
      self.iso = iso
      return self.render(None, trans, keyframe=False)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



