设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 1858|回复: 1
打印 上一主题 下一主题

[已经过期] rmxp4droid Tilemap大家帮忙优化下

[复制链接]

Lv1.梦旅人

梦石
0
星屑
69
在线时间
17 小时
注册时间
2005-11-13
帖子
61
跳转到指定楼层
1
发表于 2013-10-9 00:57:29 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 秒杀 于 2013-10-9 01:10 编辑

近期一直在想办法解决rmxp4droid在大地图卡的问题,经过排除找到问题出在Tilemap上。

以下是rmxp4droid中使用的Tilemap我已经做了一点优化,希望有高人能帮忙优化下,在大地图下能保证不卡就好(现在只要复杂点的地图就会卡)。

关于重写测试的话直接在工程的数据库脚本中加入Tilemap 类就会覆盖,然后rmxp4droid下运行即可。


百度上对TileMap解释:
TileMap高运算速度
与其他许多软件相比,RMXP和RMVX都具有相对较高的TileMap再现速度.据测试,一台中低端电脑可以在大约0.17秒的时间内完成一幅60*60大小地图的再现,而RGE,Java都无法达到这样的速度(C/C++语言处理的除外).

rmxp4droid底层用JAVA实现的,改用C/C++不可能,只能尝试在代码上优化。在PC上测试不出来,在android手机上卡的现象就非常明显了。


另外,640*480分辨率修改的方式不考虑在内.

RUBY 代码复制
  1. class CustomTilemapAutotiles
  2.   attr_accessor :changed
  3.   def initialize
  4.    @changed=true
  5.    @tiles=[nil,nil,nil,nil,nil,nil,nil]
  6.   end
  7.   def []=(i,value)
  8.    @tiles[i]=value
  9.    @changed=true
  10.   end
  11.   def [](i)
  12.    return @tiles[i]
  13.   end
  14. end
  15.  
  16. class Tilemap
  17. #Animated_Autotiles_Frames = 15
  18. Animated_Autotiles_Frames = 999999
  19.   Autotiles = [
  20.     [ [27, 28, 33, 34], [ 5, 28, 33, 34], [27,  6, 33, 34], [ 5,  6, 33, 34],
  21.       [27, 28, 33, 12], [ 5, 28, 33, 12], [27,  6, 33, 12], [ 5,  6, 33, 12] ],
  22.     [ [27, 28, 11, 34], [ 5, 28, 11, 34], [27,  6, 11, 34], [ 5,  6, 11, 34],
  23.       [27, 28, 11, 12], [ 5, 28, 11, 12], [27,  6, 11, 12], [ 5,  6, 11, 12] ],
  24.     [ [25, 26, 31, 32], [25,  6, 31, 32], [25, 26, 31, 12], [25,  6, 31, 12],
  25.       [15, 16, 21, 22], [15, 16, 21, 12], [15, 16, 11, 22], [15, 16, 11, 12] ],
  26.     [ [29, 30, 35, 36], [29, 30, 11, 36], [ 5, 30, 35, 36], [ 5, 30, 11, 36],
  27.       [39, 40, 45, 46], [ 5, 40, 45, 46], [39,  6, 45, 46], [ 5,  6, 45, 46] ],
  28.     [ [25, 30, 31, 36], [15, 16, 45, 46], [13, 14, 19, 20], [13, 14, 19, 12],
  29.       [17, 18, 23, 24], [17, 18, 11, 24], [41, 42, 47, 48], [ 5, 42, 47, 48] ],
  30.     [ [37, 38, 43, 44], [37,  6, 43, 44], [13, 18, 19, 24], [13, 14, 43, 44],
  31.       [37, 42, 43, 48], [17, 18, 47, 48], [13, 18, 43, 48], [ 1,  2,  7,  8] ]
  32.   ]
  33.   FlashOpacity=[100,90,80,70,80,90]
  34.   attr_reader :tileset
  35.   attr_reader :autotiles
  36.   attr_reader :map_data
  37.   attr_accessor :flash_data
  38.   attr_accessor :priorities
  39.   attr_reader :visible
  40.   attr_accessor :ox
  41.   attr_accessor :oy
  42.   attr_reader :viewport
  43.   def initialize(viewport)
  44.     @tileset    = nil  # Refers to Map Tileset Name
  45.     @autotiles  = CustomTilemapAutotiles.new
  46.     @map_data   = nil  # Refers to 3D Array Of Tile Settings
  47.     @flash_data = nil  # Refers to 3D Array of Tile Flashdata
  48.     @priorities = nil  # Refers to Tileset Priorities
  49.     @visible    = true # Refers to Tileset Visibleness
  50.     @ox         = 0    # Bitmap Offsets
  51.     @oy         = 0    # bitmap Offsets
  52.     @plane       = false
  53.     @selfviewport=Viewport.new(0,0,640,480)
  54.     @viewport=viewport ? viewport : @selfviewport
  55.     @tiles=[]
  56.     @autotileInfo=[]
  57.     @regularTileInfo=[]
  58.     @oldOx=0
  59.     @oldOy=0
  60.     @layer0=Sprite.new(viewport)
  61.     @layer0.visible=true
  62.     @nowshown=false
  63.     @layer0.bitmap=Bitmap.new(@viewport.rect.width*1.5,@viewport.rect.height*1.5)
  64.     @flash=nil
  65.     @layer0.ox=0
  66.     @layer0.oy=0
  67.     @oxLayer0=0
  68.     @oyLayer0=0
  69.     @oxFlash=0
  70.     @oyFlash=0
  71.     @layer0.z=0
  72.     @priotiles=[]
  73.     @prioautotiles=[]
  74.     @autosprites=[]
  75.     @framecount=[]
  76.     @tilesetChanged=true
  77.     @flashChanged=false
  78.     @firsttime=true
  79.     @disposed=false
  80.     @usedsprites=false
  81.     @layer0clip=true
  82.     @firsttimeflash=true
  83.     @fullyrefreshed=false
  84.     @fullyrefreshedautos=false
  85.   end
  86.   def disposed?
  87.    return @disposed
  88.   end
  89.   def flash_data=(value)
  90.    @flash_data=value
  91.    @flashChanged=true   
  92.   end
  93.   def update
  94.    # if @autotiles.changed
  95.   #    refresh_autotiles
  96.    #   repaintAutotiles
  97.    # end
  98.    # if @flashChanged
  99.    #   refresh_flash
  100.    # end
  101.    # if @tilesetChanged
  102.    #   refresh_tileset
  103.    # end
  104.    # if @flash
  105.   #   @flash.opacity=FlashOpacity[(Graphics.frame_count/2) % 6]
  106.   #  end
  107.     if !(@oldOx==@ox && @oldOy==@oy &&
  108.            !@tilesetChanged &&
  109.            !@autotiles.changed)
  110.       refresh
  111.     end
  112.    # if (Graphics.frame_count % Animated_Autotiles_Frames == 0) || @nowshown
  113.    #   repaintAutotiles
  114.    #   refresh(true)
  115.    # end
  116.     @nowshown=false
  117.     @autotiles.changed=false
  118.     @tilesetChanged=false
  119.   end
  120. def priorities=(value)
  121.   @priorities=value
  122.   @tilesetChanged=true
  123. end
  124. def tileset=(value)
  125.   @tileset=value
  126.   @tilesetChanged=true
  127. end
  128. def shown?
  129.    return false if !@visible
  130.    ysize=@map_data.ysize
  131.    xsize=@map_data.xsize
  132.    xStart=(@ox/32)-1
  133.    xEnd=((@ox+@viewport.rect.width)/32)+1
  134.    yStart=(@oy/32)-1
  135.    yEnd=((@oy+@viewport.rect.height)/32)+1
  136.    xStart=0 if xStart<0
  137.    xStart=xsize-1 if xStart>=xsize
  138.    xEnd=0 if xEnd<0
  139.    xEnd=xsize-1 if xEnd>=xsize
  140.    yStart=0 if yStart<0
  141.    yStart=ysize-1 if yStart>=ysize
  142.    yEnd=0 if yEnd<0
  143.    yEnd=ysize-1 if yEnd>=ysize
  144.    return (xStart<xEnd && yStart<yEnd)
  145. end
  146. def dispose
  147. return if disposed?
  148. @help.dispose if @help
  149. @help=nil
  150. i=0;len=@autotileInfo.length;while i<len
  151.   if @autotileInfo[i]
  152.      @autotileInfo[i].dispose
  153.      @autotileInfo[i]=nil
  154.   end
  155.   i+=1
  156. end
  157. i=0;len=@regularTileInfo.length;while i<len
  158.   if @regularTileInfo[i]
  159.      @regularTileInfo[i].dispose
  160.      @regularTileInfo[i]=nil
  161.   end
  162.   i+=1
  163. end
  164. i=0;len=@tiles.length;while i<len
  165.   @tiles[i].dispose
  166.   @tiles[i]=nil
  167.   i+=2
  168. end
  169. i=0;len=@autosprites.length;while i<len
  170.   @autosprites[i].dispose
  171.   @autosprites[i]=nil
  172.   i+=2
  173. end
  174. if @layer0
  175.   @layer0.bitmap.dispose if !@layer0.disposed?
  176.   @layer0.bitmap=nil if !@layer0.disposed?
  177.   @layer0.dispose
  178.   @layer0=nil
  179. end
  180. if @flash
  181.   @flash.bitmap.dispose if !@flash.disposed?
  182.   @flash.bitmap=nil if !@flash.disposed?
  183.   @flash.dispose
  184.   @flash=nil
  185. end
  186. for i in 0...7
  187.   self.autotiles[i]=nil
  188. end
  189. @tiles.clear
  190. @autosprites.clear
  191. @autotileInfo.clear
  192. @regularTileInfo.clear
  193. @tilemap=nil
  194. @tileset=nil
  195. @priorities=nil
  196. @selfviewport.dispose
  197. @selfviewport=nil
  198. @disposed=true
  199. end
  200.  
  201. def bltAutotile(bitmap,x,y,id,frame)
  202.   return if frame<0
  203.   autotile=@autotiles[id/48-1]
  204.   return if !autotile
  205.   if autotile.height==32
  206.     anim=frame*32
  207.     src_rect=Rect.new(anim,0,32,32)
  208.     bitmap.blt(x,y,autotile,src_rect)
  209.   else
  210.     anim=frame*96
  211.     id%=48
  212.     tiles = Autotiles[id>>3][id&7]
  213.     src=Rect.new(0,0,0,0)
  214.     for i in 0...4
  215.       tile_position = tiles[i] - 1
  216.       src.set(tile_position % 6 * 16 + anim,
  217.        tile_position / 6 * 16, 16, 16)
  218.       bitmap.blt(i%2*16+x,i/2*16+y, autotile, src)
  219.     end
  220.   end
  221. end
  222.  
  223. def autotileNumFrames(id)
  224.   autotile=@autotiles[id/48-1]
  225.   return 0 if !autotile || autotile.disposed?
  226.   frames=1
  227.   if autotile.height==32
  228.    frames=autotile.width/32
  229.   else
  230.    frames=autotile.width/96
  231.   end
  232.   return frames
  233. end
  234.  
  235. def autotileFrame(id)
  236.   autotile=@autotiles[id/48-1]
  237.   return -1 if !autotile || autotile.disposed?
  238.   frames=1
  239.   if autotile.height==32
  240.    frames=autotile.width/32
  241.   else
  242.    frames=autotile.width/96
  243.   end
  244.   return (Graphics.frame_count/Animated_Autotiles_Frames)%frames
  245. end
  246.  
  247. def repaintAutotiles
  248. for i in [email]0...@autotileInfo.length[/email]
  249.   next if !@autotileInfo[i]
  250.   frame=autotileFrame(i)
  251.   bltAutotile(@autotileInfo[i],0,0,i,frame)
  252. end
  253. end
  254.  
  255. def getAutotile(sprite,id)
  256.   anim=autotileFrame(id)
  257.   return if anim<0
  258.   bitmap=@autotileInfo[id]
  259.   if !bitmap
  260.     bitmap=Bitmap.new(32,32)
  261.     bltAutotile(bitmap,0,0,id,anim)
  262.     @autotileInfo[id]=bitmap
  263.   end
  264.   sprite.bitmap=bitmap if !sprite.equal?(bitmap) || sprite.bitmap!=bitmap
  265. end
  266.  
  267. def getRegularTile(sprite,id)
  268. if false
  269.   sprite.bitmap=@tileset if !sprite.equal?(@tileset) || sprite.bitmap!=@tileset
  270.   sprite.src_rect.set((id - 384) % 8 * 32, (id - 384) / 8 * 32,32,32)
  271. else
  272.   bitmap=@regularTileInfo[id]
  273.   if !bitmap
  274.    bitmap=Bitmap.new(32,32)
  275.    rect=Rect.new((id - 384) % 8 * 32, (id - 384) / 8 * 32,32,32)
  276.    bitmap.blt(0,0,@tileset,rect)
  277.    @regularTileInfo[id]=bitmap
  278.   end
  279.   sprite.bitmap=bitmap if !sprite.equal?(bitmap) || sprite.bitmap!=bitmap
  280. end
  281. end
  282.  
  283. def addTile(tiles,count,xpos,ypos,id)
  284.    if id>=384
  285.      if count>=tiles.length
  286.         sprite=Sprite.new(@viewport)
  287.       tiles.push(sprite,0)
  288.      else
  289.       sprite=tiles[count]
  290.       tiles[count+1]=0
  291.      end
  292.      sprite.visible=@visible
  293.      sprite.x=xpos
  294.      sprite.y=ypos
  295.      getRegularTile(sprite,id)
  296.      spriteZ=(@priorities[id]==0||!@priorities[id]) ? 0 : ypos+@priorities[id]*32+32
  297.      sprite.z=spriteZ
  298.      count+=2
  299.    else
  300.      if count>=tiles.length
  301.          sprite=Sprite.new(@viewport)
  302.       tiles.push(sprite,1)
  303.      else
  304.       sprite=tiles[count]
  305.       tiles[count+1]=1
  306.      end
  307.      sprite.visible=@visible
  308.      sprite.x=xpos
  309.      sprite.y=ypos
  310.      getAutotile(sprite,id)
  311.      spriteZ=(@priorities[id]==0||!@priorities[id]) ? 0 : ypos+@priorities[id]*32+32
  312.      sprite.z=spriteZ
  313.      count+=2
  314.    end
  315.    return count
  316. end
  317.  
  318. def refresh_tileset
  319. i=0;len=@regularTileInfo.length;while i<len
  320.   if @regularTileInfo[i]
  321.      @regularTileInfo[i].dispose
  322.      @regularTileInfo[i]=nil
  323.   end
  324.   i+=1
  325. end
  326. @regularTileInfo.clear
  327. @priotiles.clear
  328. ysize=@map_data.ysize
  329. xsize=@map_data.xsize
  330. zsize=@map_data.zsize
  331. if xsize>100 || ysize>100
  332.   @fullyrefreshed=false
  333. else
  334.   for z in 0...zsize
  335.    for y in 0...ysize
  336.     for x in 0...xsize
  337.      id = @map_data[x, y, z]
  338.      next if id==0 || !@priorities[id]
  339.      next if @priorities[id]==0
  340.      @priotiles.push([x,y,z,id])
  341.     end
  342.    end
  343.   end
  344.   @fullyrefreshed=true
  345. end
  346. end
  347.  
  348. def refresh_flash
  349. if @flash_data && !@flash
  350.   @flash=Sprite.new(viewport)
  351.   @flash.visible=true
  352.   @flash.z=1
  353.   @flash.blend_type=1
  354.   @flash.bitmap=Bitmap.new(@viewport.rect.width*1.5,@viewport.rect.height*1.5)
  355.   @firsttimeflash=true
  356. elsif !@flash_data && @flash
  357.   @flash.bitmap.dispose if @flash.bitmap
  358.   @flash.dispose
  359.   @flash=nil
  360.   @firsttimeflash=false
  361. end
  362. end
  363.  
  364. def refresh_autotiles
  365. i=0;len=@autotileInfo.length;while i<len
  366.   if @autotileInfo[i]
  367.      @autotileInfo[i].dispose
  368.      @autotileInfo[i]=nil
  369.   end
  370.   i+=1
  371. end
  372. i=0;len=@autosprites.length;while i<len
  373.   if @autosprites[i]
  374.      @autosprites[i].dispose
  375.      @autosprites[i]=nil
  376.   end
  377.   i+=2
  378. end
  379. @autosprites.clear
  380. @autotileInfo.clear
  381. @prioautotiles.clear
  382. hasanimated=false
  383. for i in 0...7
  384.   numframes=autotileNumFrames(48*(i+1))
  385.   hasanimated=true if numframes>=2
  386.   @framecount[i]=numframes
  387. end
  388. if hasanimated
  389.   ysize=@map_data.ysize
  390.   xsize=@map_data.xsize
  391.   zsize=@map_data.zsize
  392.   if xsize>100 || ysize>100
  393.     @fullyrefreshedautos=false
  394.   else
  395.     for y in 0...ysize
  396.      for x in 0...xsize
  397.       haveautotile=false
  398.       for z in 0...zsize
  399.        id = @map_data[x, y, z]
  400.        next if id==0 || id>=384 || @priorities[id]!=0 || !@priorities[id]
  401.        next if @framecount[id/48-1]<2
  402.        haveautotile=true
  403.        break
  404.       end
  405.       @prioautotiles.push([x,y]) if haveautotile
  406.      end
  407.     end
  408.     @fullyrefreshedautos=true
  409.   end
  410. else
  411.   @fullyrefreshedautos=true
  412. end
  413. end
  414.  
  415. def map_data=(value)
  416. @map_data=value
  417. @tilesetChanged=true
  418. end
  419.  
  420. def refreshFlashSprite
  421. return if ![url=home.php?mod=space&uid=14082]@Flash[/url] || @flash_data.nil?
  422. ptX=@ox-@oxFlash
  423. ptY=@oy-@oyFlash
  424. if !@firsttimeflash && !@usedsprites &&
  425.     ptX>=0 && ptX+@viewport.rect.width<=@flash.bitmap.width &&
  426.     ptY>=0 && ptY+@viewport.rect.height<=@flash.bitmap.height
  427.   @flash.ox=0
  428.   @flash.oy=0
  429.   @flash.src_rect.set(ptX.round,ptY.round,
  430.      @viewport.rect.width,@viewport.rect.height)
  431.   return
  432. end
  433. width=@flash.bitmap.width
  434. height=@flash.bitmap.height
  435. bitmap=@flash.bitmap
  436. ysize=@map_data.ysize
  437. xsize=@map_data.xsize
  438. zsize=@map_data.zsize
  439. @firsttimeflash=false
  440. @oxFlash=@ox-(width>>2)
  441. @oyFlash=@oy-(height>>2)
  442. @flash.ox=0
  443. @flash.oy=0
  444. @flash.src_rect.set(width>>2,height>>2,
  445.      @viewport.rect.width,@viewport.rect.height)
  446. @flash.bitmap.clear
  447. @oxFlash=@oxFlash.floor
  448. @oyFlash=@oyFlash.floor
  449. xStart=(@oxFlash>>5)
  450. xStart=0 if xStart<0
  451. yStart=(@oyFlash>>5)
  452. yStart=0 if yStart<0
  453. xEnd=xStart+(width>>5)+1
  454. yEnd=yStart+(height>>5)+1
  455. xEnd=xsize if xEnd>=xsize
  456. yEnd=ysize if yEnd>=ysize
  457. if xStart<xEnd && yStart<yEnd
  458.   yrange=yStart...yEnd
  459.   xrange=xStart...xEnd
  460.   tmpcolor=Color.new(0,0,0,0)
  461.   for y in yrange
  462.    ypos=(y<<5)-@oyFlash
  463.    for x in xrange
  464.      xpos=(x<<5)-@oxFlash
  465.      id = @flash_data[x, y, 0]
  466.      r=(id>>8)&15
  467.      g=(id>>4)&15
  468.      b=(id)&15
  469.      tmpcolor.set(r*16,g*16,b*16)
  470.      bitmap.fill_rect(xpos,ypos,32,32,tmpcolor)
  471.    end
  472.   end
  473. end
  474. end
  475.  
  476.  
  477. def refreshLayer0(autotiles=false)
  478. ptX=@ox-@oxLayer0
  479. ptY=@oy-@oyLayer0
  480. if !autotiles && !@firsttime && !@usedsprites &&
  481.     ptX>=0 && ptX+@viewport.rect.width<=@layer0.bitmap.width &&
  482.     ptY>=0 && ptY+@viewport.rect.height<=@layer0.bitmap.height
  483.   if @layer0clip
  484.    @layer0.ox=0
  485.    @layer0.oy=0
  486.    @layer0.src_rect.set(ptX.round,ptY.round,
  487.      @viewport.rect.width,@viewport.rect.height)
  488.   else
  489.    @layer0.ox=ptX.round
  490.    @layer0.oy=ptY.round
  491.    @layer0.src_rect.set(0,0,@layer0.bitmap.width,@layer0.bitmap.height)
  492.   end
  493.   return true
  494. end
  495. width=@layer0.bitmap.width
  496. height=@layer0.bitmap.height
  497. bitmap=@layer0.bitmap
  498. ysize=@map_data.ysize
  499. xsize=@map_data.xsize
  500. zsize=@map_data.zsize
  501. if autotiles
  502.   return true if @fullyrefreshedautos && @prioautotiles.length==0
  503.   return true if !shown?
  504.   xStart=(@oxLayer0>>5)
  505.   xStart=0 if xStart<0
  506.   yStart=(@oyLayer0>>5)
  507.   yStart=0 if yStart<0
  508.   xEnd=xStart+(width>>5)+1
  509.   yEnd=yStart+(height>>5)+1
  510.   xEnd=xsize if xEnd>xsize
  511.   yEnd=ysize if yEnd>ysize
  512.   return true if xStart>=xEnd || yStart>=yEnd
  513.   trans=Color.new(0,0,0,0)
  514.   temprect=Rect.new(0,0,0,0)
  515.   tilerect=Rect.new(0,0,32,32)
  516.   range=0...zsize
  517.   overallcount=0
  518.   count=0
  519.   if !@fullyrefreshedautos
  520.    for y in yStart..yEnd
  521.     for x in xStart..xEnd
  522.      haveautotile=false
  523.      for z in range
  524.       id = @map_data[x, y, z]
  525.       next if id<48 || id>=384 || @priorities[id]!=0 || !@priorities[id]
  526.       next if @framecount[id/48-1]<2
  527.       haveautotile=true
  528.       break
  529.      end
  530.      next if !haveautotile
  531.      overallcount+=1
  532.      xpos=(x<<5)-@oxLayer0
  533.      ypos=(y<<5)-@oyLayer0
  534.      bitmap.fill_rect(xpos,ypos,0,0,trans) if overallcount<=2000
  535.      for z in range
  536.       id = @map_data[x,y,z]
  537.       next if id<48 || @priorities[id]!=0 || !@priorities[id]
  538.       if overallcount>2000
  539.        count=addTile(@autosprites,count,xpos,ypos,id)
  540.        next
  541.       elsif id>=384
  542.        temprect.set((id - 384) % 8 * 32, (id - 384) / 8 * 32,32,32)
  543.        bitmap.blt(xpos,ypos,@tileset,temprect)
  544.       else
  545.        tilebitmap=@autotileInfo[id]
  546.        if !tilebitmap
  547.         anim=autotileFrame(id)
  548.         next if anim<0
  549.         tilebitmap=Bitmap.new(32,32)
  550.         bltAutotile(tilebitmap,0,0,id,anim)
  551.         @autotileInfo[id]=tilebitmap
  552.        end
  553.        bitmap.blt(xpos,ypos,tilebitmap,tilerect)
  554.       end
  555.      end
  556.     end
  557.    end
  558.   else
  559.    for tile in @prioautotiles
  560.     x=tile[0]
  561.     y=tile[1]
  562.     next if x<xStart||x>xEnd
  563.     next if y<yStart||y>yEnd
  564.     overallcount+=1
  565.     xpos=(x<<5)-@oxLayer0
  566.     ypos=(y<<5)-@oyLayer0
  567.     bitmap.fill_rect(xpos,ypos,0,0,trans) if overallcount<=2000
  568.     for z in range
  569.      id = @map_data[x,y,z]
  570.      next if id<48 || @priorities[id]!=0 || !@priorities[id]
  571.      if overallcount>2000
  572.       count=addTile(@autosprites,count,xpos,ypos,id)
  573.       next
  574.      elsif id>=384
  575.       temprect.set((id - 384) % 8 * 32, (id - 384) / 8 * 32,32,32)
  576.       bitmap.blt(xpos,ypos,@tileset,temprect)
  577.      else
  578.       tilebitmap=@autotileInfo[id]
  579.       if !tilebitmap
  580.         anim=autotileFrame(id)
  581.         next if anim<0
  582.         tilebitmap=Bitmap.new(32,32)
  583.         bltAutotile(tilebitmap,0,0,id,anim)
  584.         @autotileInfo[id]=tilebitmap
  585.       end
  586.       bitmap.blt(xpos,ypos,tilebitmap,tilerect)
  587.      end
  588.     end
  589.    end
  590.   end
  591.   Graphics.frame_reset if overallcount>2000
  592.   @usedsprites=false
  593.   return true
  594. end
  595. return false if @usedsprites
  596. @firsttime=false
  597. @oxLayer0=@ox-(width>>2)
  598. @oyLayer0=@oy-(height>>2)
  599. if @layer0clip
  600.   @layer0.ox=0
  601.   @layer0.oy=0
  602.   @layer0.src_rect.set(width>>2,height>>2,
  603.      @viewport.rect.width,@viewport.rect.height)
  604. else
  605.   @layer0.ox=(width>>2)
  606.   @layer0.oy=(height>>2)
  607. end
  608. @layer0.bitmap.clear
  609. @oxLayer0=@oxLayer0.floor
  610. @oyLayer0=@oyLayer0.floor
  611. xStart=(@oxLayer0>>5)
  612. xStart=0 if xStart<0
  613. yStart=(@oyLayer0>>5)
  614. yStart=0 if yStart<0
  615. xEnd=xStart+(width>>5)+1
  616. yEnd=yStart+(height>>5)+1
  617. xEnd=xsize if xEnd>=xsize
  618. yEnd=ysize if yEnd>=ysize
  619. if xStart<xEnd && yStart<yEnd
  620.   tmprect=Rect.new(0,0,0,0)
  621.   yrange=yStart...yEnd
  622.   xrange=xStart...xEnd
  623.   for z in 0...zsize
  624.    for y in yrange
  625.     ypos=(y<<5)-@oyLayer0
  626.     for x in xrange
  627.      xpos=(x<<5)-@oxLayer0
  628.      id = @map_data[x, y, z]
  629.      next if id==0 || @priorities[id]!=0 || !@priorities[id]
  630.      if id>=384
  631.        tmprect.set((id - 384) % 8 * 32, (id - 384) / 8 * 32,32,32)
  632.        bitmap.blt(xpos,ypos,@tileset,tmprect)
  633.      else
  634.        frame=autotileFrame(id)
  635.        bltAutotile(bitmap,xpos,ypos,id,frame)
  636.      end
  637.     end
  638.    end
  639.   end
  640.   Graphics.frame_reset
  641. end
  642. return true
  643. end
  644. def getResizeFactor
  645.   return $ResizeFactor ? $ResizeFactor : 1.0
  646. end
  647. def ox=(val)
  648.    val=(val*getResizeFactor).to_i
  649.    val=(val/getResizeFactor).to_i
  650.    wasshown=self.shown?
  651.    @ox=val.floor
  652.    @nowshown=(!wasshown && self.shown?)
  653. end
  654. def oy=(val)
  655.    val=(val*getResizeFactor).to_i
  656.    val=(val/getResizeFactor).to_i
  657.    wasshown=self.shown?
  658.    @oy=val.floor
  659.    @nowshown=(!wasshown && self.shown?)
  660. end
  661. def visible=(val)
  662.    wasshown=@visible
  663.    @visible=val
  664.    @nowshown=(!wasshown && val)
  665. end
  666. def refresh(autotiles=false)
  667. @oldOx=@ox
  668. @oldOy=@oy
  669. usesprites=false
  670. if @layer0
  671.   @layer0.visible=@visible
  672.   usesprites=!refreshLayer0(autotiles)
  673.   if autotiles && !usesprites
  674.    return
  675.   end
  676. else
  677.   usesprites=true
  678. end
  679. refreshFlashSprite
  680. vpx=@viewport.rect.x
  681. vpy=@viewport.rect.y
  682. vpr=@viewport.rect.width+vpx
  683. vpb=@viewport.rect.height+vpy
  684. xsize=@map_data.xsize
  685. ysize=@map_data.ysize
  686. minX=(@ox/32)-1
  687. maxX=((@ox+@viewport.rect.width)/32)+1
  688. minY=(@oy/32)-1
  689. maxY=((@oy+@viewport.rect.height)/32)+1
  690. minX=0 if minX<0
  691. minX=xsize-1 if minX>=xsize
  692. maxX=0 if maxX<0
  693. maxX=xsize-1 if maxX>=xsize
  694. minY=0 if minY<0
  695. minY=ysize-1 if minY>=ysize
  696. maxY=0 if maxY<0
  697. maxY=ysize-1 if maxY>=ysize
  698. count=0
  699. if minX<maxX && minY<maxY
  700.   @usedsprites=usesprites || @usedsprites
  701.   if @layer0
  702.    @layer0.visible=false if usesprites
  703.   end
  704.   if @fullyrefreshed
  705.    for prio in @priotiles
  706.     next if prio[0]<minX||prio[0]>maxX
  707.     next if prio[1]<minY||prio[1]>maxY
  708.     id=prio[3]
  709.     xpos=(prio[0]<<5)-@ox
  710.     ypos=(prio[1]<<5)-@oy
  711.     count=addTile(@tiles,count,xpos,ypos,id)
  712.    end
  713.   else
  714.    for z in [email]0...@map_data.zsize[/email]
  715.     for y in minY..maxY
  716.      for x in minX..maxX
  717.       id = @map_data[x, y, z]
  718.       next if id==0 || !@priorities[id]
  719.       next if @priorities[id]==0
  720.       xpos=(x<<5)-@ox
  721.       ypos=(y<<5)-@oy
  722.       count=addTile(@tiles,count,xpos,ypos,id)
  723.      end
  724.     end
  725.    end
  726.   end
  727. end
  728. if count<@tiles.length
  729.   bigchange=(count<=(@tiles.length*2/3)) && (@tiles.length*2/3)>25
  730.   j=count;len=@tiles.length;while j<len
  731.    sprite=@tiles[j]
  732.    @tiles[j+1]=-1
  733.    if bigchange
  734.     sprite.dispose
  735.     @tiles[j]=nil
  736.     @tiles[j+1]=nil
  737.    elsif !@tiles[j].disposed?
  738.     sprite.visible=false if sprite.visible
  739.    end
  740.    j+=2
  741.   end
  742.   @tiles.compact! if bigchange
  743. end
  744. end
  745.  
  746. end
   

Lv4.逐梦者

梦石
0
星屑
7981
在线时间
1183 小时
注册时间
2007-7-29
帖子
2055
2
发表于 2013-10-12 00:50:54 | 只看该作者
为何不从新写一个库?反而要用脚本?这样不等于在模拟中运算么?效率有限啊。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-9-30 01:44

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表