zoukankan      html  css  js  c++  java
  • 存档系统研究

      UDN上有一篇文章解析了存档系统,这里我解析一下存档系统是怎么工作的。所谓存档系统首先要解决的问题便是在1.游戏退出后能存储游戏的指定数据 2.是在游戏载入时载入当时指定的存储数据。

      这篇示例演示一个Actor的存储。

    1.  一种Actor类,这是要存储的对象,将该对象用控制台放置在特定的位置。以后存储和加载该类。  

    class CubeMemory extends Actor;


    defaultproperties
    {
    begin object class=DynamicLightEnvironmentComponent name=MyLight
    bEnabled=true
    end object
    Components.add(MyLight)

    begin Object class=StaticMeshComponent name=MyMesh
    LightEnvironment=MyLight
    end object
    Components.add(MyMesh)
    }

      以上定义了一个CubeMemory Actor。

    2.一个存储状态类GameState,该状态负责存储以及加载游戏中的参数,这里将具有的CubeMemory以及自身的位置存储在一个数组中。

    class GameState extends Object;

    struct GameObjectStruct
    {
    local actor Reference; //Cube
    local vector Location; //Cube location
    };

    var array<GameObjectStruct> GameObject; //global save

    function AddCube(CubeMemory cube)
    {
    local GameObjectStruct GOS;
    GOS.Location=cube.Location;
    GOS.Reference=cube.;

    GameObject.AddItem(GOS);
    }

    //save self in the bin
    function SaveObject(string path)
    {
    class'Engine'.static.BasicSaveObject(self,path,true,1);
    }


    //Load self in the bin
    function LoadObject(string path)
    {
    class'Engine'.Static.BasicLoadObject(self,path,true,1);
    }



    defaultproperties
    {
    }


    3.GameInfo类是负责加载和存储游戏执行的类

    class AntGame extends GameInfo dependson(GameState);

    var GameState CurrentGameState;

    event PostLogin(PlayerController NewPlayer)
    {
    super.PostLogin(NewPlayer);
    CurrentGameState=new class'GameState'
    }

    exec function SpawnCube(float X,float Y,float Z)
    {
    local MemoryCube cube;
    local vector CubeLocation;

    CubeLocation.x=x;
    CubeLocation.y=y;
    CubeLocation.z=z;

    Cube=Spawn(class'MemoryCube',,,Location);

    CurrentGameState.CubeAdd(cube);
    }

    exec function SaveGame()
    {
    CurrentGameState.SaveObject("SaveGame.bin");
    }


    exec function Loadgame()
    {
    local GameObjectStruct GOS;
    CurrentGameState.LoadObject("SaveGame.bin");
       foreach CurrentGameState.GameObject(GOS)
    {
       GOS.Reference=spawn(class'MemoryCube',,,GOS.Location); 
    }
         
    }

      以上便完成了存储系统。

     

  • 相关阅读:
    一次郁闷的项目部署经历
    一道面试题的求解
    一次惨痛的教训
    小地方,大郁闷001
    WPF相对资源的访问
    VS2008安装时提示磁盘空间不够的解决办法
    WPFSlider 控件的使用
    关于asp.net大文件上传和进度条实现的学习(1)
    DataList的一次分页困惑
    关于android的XML的解析
  • 原文地址:https://www.cnblogs.com/NEOCSL/p/2410915.html
Copyright © 2011-2022 走看看