zoukankan      html  css  js  c++  java
  • 游戏版本比较的算法[ZZ]

    在游戏开发和维护过程中,客户端都是不断更新的,伴随着每一次的更新,都会发布
    一个更新补丁包来对旧的客户端进行更新,来使其变成新的客户端,补丁包应该包含
    更新成新客户端的最少量资源(最大量资源就是整个新的客户端覆盖旧的)
    更新程序通过读一个更新脚本,对旧的客户端进行文件添加,文件覆盖,文件删除等
    操作来更新旧的客户端,当更新量比较少比较简单的情况下,更新脚本可以资源整理
    人员自己写,但当更新量太大,资源多而杂的情况下,手写更新脚本就变得极容易出
    错了,所以有必要开发一个工具自动查找两个版本的差异,自动生成更新脚本。
    比较的方法:
    假设有两个文件夹A,和文件夹B,A是旧的客户端,B是新的客户端,需要通过算法来
    找出两个文件夹的差异,并生成脚本,此脚本即明确的表明一些操作能将A变成B的过
    程。
    1.遍历A文件夹中的所有文件名,包括子目录,储存到O中去
    2.遍历B文件夹中的所有文件名,包括子目录,储存到N中去
    3.找出需要添加到旧版本中的文件:
    通过遍历N中每个文件,查询是否在O中存在,如果不存在的文件则为需要添加的文
    ,储存到FA中去。
    4.找出旧版本中需要删除的文件:
    通过遍历O中每个文件,查询是否在N中存在,如果不存在则表示此文件需要删除,
    并储存到FD中去。
    5.找出旧版本中需要覆盖的文件:
    通过遍历N中每个文件,找出在O中也同样存在此文件,这里把游戏用的资源包排除掉,
    它们将在后面的操作中检测并更新,如果找到的两个相同的文件,比较文件内容只要
    一个字节的内容不相同,则说明旧的版本中的此文件需要被新的版本中的文件覆盖掉
    6.游戏资源包的更新操作:
    通过遍历N中的每个为游戏资源包类型的文件,并查找O中是否
    同样存在此文件,如果存在再比较两个内容是否相同,如果有一个字节不相同就表示内
    容不同,则跳入下面包的更新操作中去。
    a. 遍历旧包内的所有文件,储存到PO中
    b. 遍历新包内的所有文件,储存到PN中
    c. 找出旧包内需要添加的文件:
       通过遍历PN中每个文件,找出在PO中没有的,储存到PA中去。
    d. 找出旧包内需要删除的文件:
       通过遍历PO中每个文件,找出在PN中没有的,储存到PD中去。
    e. 找出旧包内需要覆盖的文件:
       通过遍历PO中每个文件,如果PN中也存在此文件,如果他们之间有一个字节不相同
       则表示旧包内的此文件需要覆盖掉,储存到PR中去。
    通过上面的过程,两个文件夹的差异已经找出来了,这时就可以根据差异信息生成更新脚本,
    同时把旧版本需要添加,覆盖,包内需要添加,覆盖的文件抽取出来,生成资源包。
    下面截图是我写的一个版本比较工具的截图:

    uploads/200803/21_153511_vctools.jpg

    最后需要添加和替换的资源全部复制到resource目录下去
    生成的更新脚本类似如下:

    <VersionCompare>
      <Version Old="1.0" New="1.1" />
      <Resource Path="./resource/" />
      <UpdateActions>
        <FileActions>
          <Add From="0.dat" To="SkyBox/NewPictures/anc_elephantear1.PNG" />
          <Add From="1.dat" To="SkyBox/NewTexts/Apple.txt" />
          <Add From="2.dat" To="SkyBox/NewTexts/Pear.txt" />
          <Add From="3.dat" To="SkyBox/NewTexts/Orange.Txt" />
          <Add From="4.dat" To="TerrainMaterial/GoodLcuk.doc" />
          <Add From="5.dat" To="WaterColour/半兽人.mp3" />
          <Add From="6.dat" To="ABc1.sgp" />
          <Delete Where="SkyBox/bm00500SkyBox_BK.jpg" />
          <Delete Where="ShadowLayer/TerrainBlock16.tga" />
          <Delete Where="ShadowLayer/TerrainBlock36.tga" />
          <Delete Where="ShadowLayer/TerrainBlock44.tga" />
          <Delete Where="ShadowLayer/TerrainBlock63.tga" />
          <Replace From="7.dat" ToReplace="00500.xml" />
          <Replace From="8.dat" ToReplace="ShadowLayer/TerrainBlock46.tga" />
          <Replace From="9.dat" ToReplace="SkyBox/SkyBox.material" />
          <Replace From="10.dat" ToReplace="TerrainMaterial/TerrainMaterials.material" />
          <Replace From="11.dat" ToReplace="WaterColour/WaterColour_bm00500.tga" />
        </FileActions>
        <PackageActions Package="ShadowLayer/abc1.sgp">
          <Add From="12.dat" To="复件 skybox/terrainblock7.tga" />
          <Delete Where="00002.dat" />
          <Delete Where="00002.dat.addons" />
          <Delete Where="00002.xml.bak" />
          <Delete Where="bf00002.xml.bak" />
          <Replace From="13.dat" ToReplace="aaa.xml" />
          <Replace From="14.dat" ToReplace="skybox/lava_01.tga" />
          <Replace From="15.dat" ToReplace="skybox/skybox.material" />
          <Replace From="16.dat" ToReplace="复件 skybox/skybox.material" />
        </PackageActions>
        <PackageActions Package="SkyBox/abc1.sgp">
          <Add From="17.dat" To="shadowlayer/bm00500skybox_bk.jpg" />
          <Delete Where="skybox/bf00002skybox_bk.dds" />
          <Delete Where="skybox/bf00002skybox_dn.dds" />
          <Delete Where="skybox/bf00002skybox_fr.dds" />
          <Delete Where="skybox/bf00002skybox_lf.dds" />
          <Delete Where="skybox/bf00002skybox_rt.dds" />
          <Delete Where="skybox/bf00002skybox_up.dds" />
          <Delete Where="skybox/lava_01.tga" />
          <Delete Where="skybox/skybox.material" />
          <Delete Where="skybox/thumbs.db" />
          <Replace From="18.dat" ToReplace="aaa.xml" />
          <Replace From="19.dat" ToReplace="复件 skybox/skybox.material" />
        </PackageActions>
        <PackageActions Package="TerrainMaterial/abc1.sgp">
          <Add From="20.dat" To="新建文件夹/bm00500terrain.jpg" />
          <Delete Where="watercolour/bf00002wateredge.dds" />
          <Replace From="21.dat" ToReplace="aaa.xml" />
          <Replace From="22.dat" ToReplace="skybox/lava_01.tga" />
          <Replace From="23.dat" ToReplace="skybox/skybox.material" />
          <Replace From="24.dat" ToReplace="复件 skybox/skybox.material" />
        </PackageActions>
        <PackageActions Package="WaterColour/abc1.sgp">
          <Add From="25.dat" To="skybox/watercolour_bm00500.tga" />
          <Delete Where="shadowlayer/shadowlayer.rar" />
          <Delete Where="shadowlayer/terrainblock0.tga" />
          <Delete Where="shadowlayer/terrainblock1.tga" />
          <Delete Where="shadowlayer/terrainblock10.tga" />
          <Delete Where="shadowlayer/terrainblock11.tga" />
          <Delete Where="shadowlayer/terrainblock12.tga" />
          <Delete Where="shadowlayer/terrainblock13.tga" />
          <Delete Where="shadowlayer/terrainblock14.tga" />
          <Delete Where="shadowlayer/terrainblock15.tga" />
          <Delete Where="shadowlayer/terrainblock16.tga" />
          <Delete Where="shadowlayer/terrainblock17.tga" />
          <Delete Where="shadowlayer/terrainblock18.tga" />
          <Delete Where="shadowlayer/terrainblock19.tga" />
          <Delete Where="shadowlayer/terrainblock2.tga" />
          <Delete Where="shadowlayer/terrainblock20.tga" />
          <Delete Where="shadowlayer/terrainblock21.tga" />
          <Delete Where="shadowlayer/terrainblock22.tga" />
          <Delete Where="shadowlayer/terrainblock23.tga" />
          <Delete Where="shadowlayer/terrainblock24.tga" />
          <Delete Where="shadowlayer/terrainblock25.tga" />
          <Delete Where="shadowlayer/terrainblock26.tga" />
          <Delete Where="shadowlayer/terrainblock27.tga" />
          <Delete Where="shadowlayer/terrainblock28.tga" />
          <Delete Where="shadowlayer/terrainblock29.tga" />
          <Delete Where="shadowlayer/terrainblock3.tga" />
          <Delete Where="shadowlayer/terrainblock30.tga" />
          <Delete Where="shadowlayer/terrainblock31.tga" />
          <Delete Where="shadowlayer/terrainblock32.tga" />
          <Delete Where="shadowlayer/terrainblock33.tga" />
          <Delete Where="shadowlayer/terrainblock34.tga" />
          <Delete Where="shadowlayer/terrainblock35.tga" />
          <Delete Where="shadowlayer/terrainblock36.tga" />
          <Delete Where="shadowlayer/terrainblock37.tga" />
          <Delete Where="shadowlayer/terrainblock38.tga" />
          <Delete Where="shadowlayer/terrainblock39.tga" />
          <Delete Where="shadowlayer/terrainblock4.tga" />
          <Delete Where="shadowlayer/terrainblock40.tga" />
          <Delete Where="shadowlayer/terrainblock41.tga" />
          <Delete Where="shadowlayer/terrainblock42.tga" />
          <Delete Where="shadowlayer/terrainblock43.tga" />
          <Delete Where="shadowlayer/terrainblock44.tga" />
          <Delete Where="shadowlayer/terrainblock45.tga" />
          <Delete Where="shadowlayer/terrainblock46.tga" />
          <Delete Where="shadowlayer/terrainblock47.tga" />
          <Delete Where="shadowlayer/terrainblock48.tga" />
          <Delete Where="shadowlayer/terrainblock49.tga" />
          <Delete Where="shadowlayer/terrainblock5.tga" />
          <Delete Where="shadowlayer/terrainblock50.tga" />
          <Delete Where="shadowlayer/terrainblock51.tga" />
          <Delete Where="shadowlayer/terrainblock52.tga" />
          <Delete Where="shadowlayer/terrainblock53.tga" />
          <Delete Where="shadowlayer/terrainblock54.tga" />
          <Delete Where="shadowlayer/terrainblock55.tga" />
          <Delete Where="shadowlayer/terrainblock56.tga" />
          <Delete Where="shadowlayer/terrainblock57.tga" />
          <Delete Where="shadowlayer/terrainblock58.tga" />
          <Delete Where="shadowlayer/terrainblock59.tga" />
          <Delete Where="shadowlayer/terrainblock6.tga" />
          <Delete Where="shadowlayer/terrainblock60.tga" />
          <Delete Where="shadowlayer/terrainblock61.tga" />
          <Delete Where="shadowlayer/terrainblock62.tga" />
          <Delete Where="shadowlayer/terrainblock63.tga" />
          <Delete Where="shadowlayer/terrainblock7.tga" />
          <Delete Where="shadowlayer/terrainblock8.tga" />
          <Delete Where="shadowlayer/terrainblock9.tga" />
          <Replace From="26.dat" ToReplace="aaa.xml" />
          <Replace From="27.dat" ToReplace="skybox/lava_01.tga" />
          <Replace From="28.dat" ToReplace="skybox/skybox.material" />
          <Replace From="29.dat" ToReplace="复件 skybox/skybox.material" />
        </PackageActions>
      </UpdateActions>
    </VersionCompare>

    www.azure.com.cn

    我最擅长从零开始创造世界,所以从来不怕失败,它最多也就让我一无所有。
  • 相关阅读:
    原生js可爱糖果数字时间特效
    jQuery绑定事件的四种方式
    jQuery选择器总结
    正则表达式
    this对象
    网页瀑布流效果实现的几种方式
    关于DOM
    SparkSQL读写外部数据源--数据分区
    SparkSQL读写外部数据源-通过jdbc读写mysql数据库
    SparkSQL读写外部数据源-基本操作load和save
  • 原文地址:https://www.cnblogs.com/flying_bat/p/1264300.html
Copyright © 2011-2022 走看看