示例#1
0
 public static void Go()
 {
     AssetManager.isServerOnly = true;
     FileSystemManager.Initialize();
     MasterLog.Initialize();
     SettingsHandler.Initialize();
 }
示例#2
0
 public static void Go()
 {
     World.Mode = MagicalLifeAPI.Networking.EngineMode.ServerOnly;
     AssetManager.isServerOnly = true;
     FileSystemManager.Initialize();
     MasterLog.Initialize();
     SettingsHandler.Initialize();
 }
示例#3
0
        private static void Main()
        {
            FileSystemManager.Initialize();
            MasterLog.Initialize();

            using (Game1 game = new Game1())
            {
                game.Run();
            }
        }
示例#4
0
 public void TestInitialize()
 {
     if (!this.Initialized)
     {
         MasterLog.Initialize();
         Loader load = new Loader();
         string msg  = string.Empty;
         SettingsManager.Initialize();
         FileSystemManager.Initialize();
         load.LoadAll(ref msg, new List <IGameLoader>
         {
             new ProtoTypeLoader(),
             new ProtoManager(),
         });
         this.Initialized = true;
     }
 }
示例#5
0
        static void Main(string[] args)
        {
            //Serializer.Test();
            //DisposeHandle.Test();

            MasterLog.Initialize("log_config.xml", (msg) => Console.WriteLine(msg));

            GameConfig         cfg_total = GameConfig.ReadConfig("game_config.xml");
            GameInstanceConifg cfg_local = cfg_total.clientConfig;

            IPAddress myIP = GameConfig.GetIP(cfg_total);

            Aggregator all = new Aggregator(myIP, init => new World(init, null));

            bool myServer = cfg_total.startServer && all.host.MyAddress.Port == GlobalHost.nStartPort;

            if (myServer)
            {
                cfg_local = cfg_total.serverConfig;
            }

            all.myClient.onServerReadyHook = () =>
            {
                if (cfg_local.validate)
                {
                    all.myClient.Validate();
                }

                if (cfg_local.aiPlayers > 0)
                {
                    for (int i = 0; i < cfg_local.aiPlayers; ++i)
                    {
                        NewAiPlayer(all);
                    }
                    all.myClient.NewWorld(new Point(0, 0));
                }
            };

            MeshConnect(all, cfg_total, myIP);

            if (myServer)
            {
                all.StartServer(cfg_total.serverSpawnDensity);
            }

            all.sync.Start();

            InputProcessor inputProc = new InputProcessor(all.sync.GetAsDelegate());

            inputProc.commands.Add("connect", (param) => all.ParamConnect(param, myIP));

            inputProc.commands.Add("server", (param) =>
            {
                all.StartServer(cfg_total.serverSpawnDensity);
            });

            inputProc.commands.Add("player", (param) =>
            {
                NewAiPlayer(all);
            });

            inputProc.commands.Add("world", (param) =>
            {
                all.myClient.NewWorld(new Point(0, 0));
            });

            inputProc.commands.Add("validate", (param) =>
            {
                all.myClient.Validate();
            });

            inputProc.commands.Add("spawn", (param) =>
            {
                all.SpawnAll();
            });

            inputProc.commands.Add("draw", (param) =>
            {
                World w = all.myClient.worlds.TryGetWorld(new Point(0, 0));
                MyAssert.Assert(w != null);
                ThreadManager.NewThread(() => RepeatedAction(all.sync.GetAsDelegate(),
                                                             () => WorldTools.ConsoleOut(w), 500),
                                        () => { }, "console drawer");
            });

            inputProc.commands.Add("status", (param) =>
            {
                Log.Console(all.GetStats());
            });

            inputProc.commands.Add("threads", (param) =>
            {
                Log.Console(ThreadManager.Status());
            });

            inputProc.commands.Add("disengage", (param) =>
            {
                all.Disengage();
            });

            inputProc.commands.Add("exit", (param) =>
            {
                all.host.Close();
                System.Threading.Thread.Sleep(100);
                ThreadManager.Terminate();
                System.Threading.Thread.Sleep(100);
                all.sync.Add(null);
            });

            while (true)
            {
                string sInput = Console.ReadLine();
                var    param  = new List <string>(sInput.Split(' '));
                if (!param.Any())
                {
                    continue;
                }
                string sCommand = param.First();
                param.RemoveRange(0, 1);
                inputProc.Process(sCommand, param);

                if (sCommand == "exit")
                {
                    break;
                }
            }
        }
示例#6
0
    // Use this for initialization
    void Start()
    {
        MasterLog.Initialize("log_config.xml", msg => Debug.Log(msg));

        GameConfig         cfg       = GameConfig.ReadConfig("unity_config.xml");
        GameInstanceConifg cfg_local = cfg.clientConfig;

        IPAddress myIP = GameConfig.GetIP(cfg);

        Action <Guid, GameObject> updateCameraAction = (id, obj) =>
        {
            if (id == me)
            {
                UpdateCamera(obj);
            }
        };

        Action <WorldDraw> onWorldDestruction = wd =>
        {
            MyAssert.Assert(worlds.Contains(wd));
            worlds.Remove(wd);
        };

        Func <WorldInitializer, World> newWorldCreation = (init) =>
        {
            bool isOwnedByUs = all.worldValidators.ContainsKey(init.info.position);

            WorldDraw wd = new WorldDraw(init, isOwnedByUs, updateCameraAction, onWorldDestruction);

            bool conflict = worlds.Where(w => w.Position == wd.Position).Any();
            MyAssert.Assert(!conflict);
            worlds.Add(wd);

            return(wd);
        };

        all = new Aggregator(myIP, newWorldCreation);

        bool myServer = cfg.startServer && all.host.MyAddress.Port == GlobalHost.nStartPort;

        if (myServer)
        {
            cfg_local = cfg.serverConfig;
        }

        Program.MeshConnect(all, cfg, myIP);

        all.myClient.onServerReadyHook = () =>
        {
            if (cfg_local.validate)
            {
                all.myClient.Validate();
            }

            if (!myServer && cfg_local.aiPlayers > 0)
            {
                for (int i = 0; i < cfg_local.aiPlayers; ++i)
                {
                    Program.NewAiPlayer(all);
                }
            }

            all.myClient.NewWorld(new Point(0, 0));

            me = Guid.NewGuid();
            Log.Console("Player {0}", me);
            all.myClient.NewMyPlayer(me);
        };

        all.onNewPlayerAgentHook = (pa) =>
        {
            if (pa.Info.id == me)
            {
                myAgent = pa;

                pa.onDataHook = (pd) =>
                {
                    bool newData = (myData == null);

                    myData = pd;

                    if (newData)
                    {
                        TrySpawn();
                    }
                };
            }
        };

        if (myServer)
        {
            all.StartServer(cfg.serverSpawnDensity);
        }

        var light = gameObject.AddComponent <Light>();

        light.type      = LightType.Point;
        light.range     = cameraDistance * 1.5f;
        light.intensity = 5;

        //camera.isOrthoGraphic = true;
        //camera.orthographicSize = 10;

        Application.runInBackground = true;
    }