Beispiel #1
0
        static void IocBind(WorldParameters param)
        {
            _worldParameters = param;

            if (string.IsNullOrEmpty(_settingsManager.Settings.DatabasePath))
            {
                _settingsManager.Settings.DatabasePath = Path.Combine(XmlSettingsManager.GetFilePath("", SettingsStorage.ApplicationData), "Server", "MultiPlayer", param.Seed.ToString(), "ServerWorld.db");
            }

            Console.WriteLine("Database path is " + _settingsManager.Settings.DatabasePath);

            _sqLiteStorageManager = new SqliteStorageManager(_settingsManager.Settings.DatabasePath, null, param);

            IWorldProcessor          processor = null;
            IEntitySpawningControler entitySpawningControler = null;

            switch (param.Configuration.WorldProcessor)
            {
            case WorldConfiguration.WorldProcessors.Flat:
                processor = new FlatWorldProcessor();
                break;

            case WorldConfiguration.WorldProcessors.Utopia:
                processor = new UtopiaProcessor(param, _serverFactory, new LandscapeBufferManager());
                entitySpawningControler = new UtopiaEntitySpawningControler((UtopiaWorldConfiguration)param.Configuration);
                break;

            default:
                break;
            }

            _worldGenerator = new WorldGenerator(param, processor);
            _worldGenerator.EntitySpawningControler = entitySpawningControler;
        }
Beispiel #2
0
        public void InitSinglePlayerServer(WorldParameters worldParam)
        {
            if (Server != null)
            {
                throw new InvalidOperationException("Already initialized");
            }

            _worldParam = worldParam;

            _serverFactory        = new EntityFactory();
            _serverFactory.Config = _worldParam.Configuration;
            var dbPath = Path.Combine(_vars.ApplicationDataPath, "Server", "Singleplayer", worldParam.WorldName, "ServerWorld.db");

            logger.Info("Local world db path is {0}", dbPath);

            _serverSqliteStorageSinglePlayer = new SqliteStorageManager(dbPath, _serverFactory, worldParam);
            _serverSqliteStorageSinglePlayer.Register("local", "qwe123".GetSHA1Hash(), UserRole.Administrator);

            var settings = new XmlSettingsManager <ServerSettings>(@"Server\localServer.config");

            settings.Load();
            settings.Save();

            //Utopia New Landscape Test

            IWorldProcessor          processor = null;
            IEntitySpawningControler entitySpawningControler = null;

            switch (worldParam.Configuration.WorldProcessor)
            {
            case WorldConfiguration.WorldProcessors.Flat:
                processor = new FlatWorldProcessor();
                break;

            case WorldConfiguration.WorldProcessors.Utopia:
                processor = new UtopiaProcessor(worldParam, _serverFactory, _landscapeEntityManager);
                entitySpawningControler = new UtopiaEntitySpawningControler((UtopiaWorldConfiguration)worldParam.Configuration);
                break;

            default:
                break;
            }

            var worldGenerator = new WorldGenerator(worldParam, processor);

            worldGenerator.EntitySpawningControler = entitySpawningControler;

            //Old s33m3 landscape
            //IWorldProcessor processor1 = new s33m3WorldProcessor(worldParam);
            //IWorldProcessor processor2 = new LandscapeLayersProcessor(worldParam, _serverFactory);
            //var worldGenerator = new WorldGenerator(worldParam, processor1, processor2);

            //Vlad Generator
            //var planProcessor = new PlanWorldProcessor(wp, _serverFactory);
            //var worldGenerator = new WorldGenerator(wp, planProcessor);
            settings.Settings.ChunksCountLimit = 1024 * 3; // better use viewRange * viewRange * 3

            var port = 4815;

            while (!TcpConnectionListener.IsPortFree(port))
            {
                port++;
            }
            settings.Settings.ServerPort = port;

            _server = new ServerCore(settings, worldGenerator, _serverSqliteStorageSinglePlayer, _serverSqliteStorageSinglePlayer, _serverSqliteStorageSinglePlayer, _serverSqliteStorageSinglePlayer, _serverFactory, worldParam);
            _serverFactory.LandscapeManager     = Server.LandscapeManager;
            _serverFactory.DynamicEntityManager = Server.AreaManager;
            _serverFactory.GlobalStateManager   = Server.GlobalStateManager;
            _serverFactory.ScheduleManager      = Server.Scheduler;
            _serverFactory.ServerSide           = true;

            _server.Initialize();

            Server.ConnectionManager.LocalMode = true;
            Server.ConnectionManager.Listen();
            Server.LoginManager.PlayerEntityNeeded  += LoginManagerPlayerEntityNeeded;
            Server.LoginManager.GenerationParameters = default(Utopia.Shared.World.PlanGenerator.GenerationParameters); // planProcessor.WorldPlan.Parameters;
            Server.Clock.SetCurrentTimeOfDay(UtopiaTimeSpan.FromHours(12));
        }
Beispiel #3
0
        private void GameplayComponentsCreation()
        {
            _vars.DisposeGameComponents = true;

            var clientSideworldParam = _ioc.Get <ServerComponent>().GameInformations.WorldParameter;

            var clientFactory = _ioc.Get <EntityFactory>("Client");

            clientFactory.Config = clientSideworldParam.Configuration;

            var      landscapeEntityManager = _ioc.Get <LandscapeBufferManager>();
            FileInfo fi         = new FileInfo(_vars.LocalDataBasePath);
            string   bufferPath = Path.Combine(fi.Directory.FullName, "LandscapeBuffer.proto");

            landscapeEntityManager.SetBufferPath(bufferPath);
            landscapeEntityManager.LoadBuffer();

            IWorldProcessor processor = null;

            switch (clientSideworldParam.Configuration.WorldProcessor)
            {
            case WorldConfiguration.WorldProcessors.Flat:
                processor = new FlatWorldProcessor();
                break;

            case WorldConfiguration.WorldProcessors.Utopia:
                processor = new UtopiaProcessor(clientSideworldParam, _ioc.Get <EntityFactory>("Client"), landscapeEntityManager);
                break;

            default:
                break;
            }

            _ioc.Rebind <WorldConfiguration>().ToConstant(clientSideworldParam.Configuration);

            var worldGenerator = new WorldGenerator(clientSideworldParam, processor);

            _ioc.Rebind <WorldGenerator>().ToConstant(worldGenerator).InSingletonScope();
            _ioc.Rebind <WorldParameters>().ToConstant(clientSideworldParam);

            var commonResources = _ioc.Get <SandboxCommonResources>();

            commonResources.LoadInventoryImages(_ioc.Get <D3DEngine>());

            // be careful with initialization order
            var serverComponent       = _ioc.Get <ServerComponent>();
            var worldFocusManager     = _ioc.Get <WorldFocusManager>();
            var wordParameters        = _ioc.Get <WorldParameters>();
            var visualWorldParameters = _ioc.Get <VisualWorldParameters>(
                new ConstructorArgument("visibleChunkInWorld", new Vector2I(ClientSettings.Current.Settings.GraphicalParameters.WorldSize, ClientSettings.Current.Settings.GraphicalParameters.WorldSize)),
                new ConstructorArgument("player", serverComponent.Player));

            var firstPersonCamera = _ioc.Get <ICameraFocused>("FirstPCamera");
            var thirdPersonCamera = _ioc.Get <ICameraFocused>("ThirdPCamera");
            var cameraManager     = _ioc.Get <CameraManager <ICameraFocused> >(new ConstructorArgument("camera", firstPersonCamera));

            cameraManager.RegisterNewCamera(thirdPersonCamera);

            var timerManager        = _ioc.Get <TimerManager>();
            var inputsManager       = _ioc.Get <InputsManager>();
            var guiManager          = _ioc.Get <GuiManager>();
            var iconFactory         = _ioc.Get <IconFactory>();
            var gameClock           = _ioc.Get <IClock>();
            var chunkStorageManager = _ioc.Get <IChunkStorageManager>(new ConstructorArgument("forceNew", false), new ConstructorArgument("fileName", _vars.LocalDataBasePath));

            var inventory = _ioc.Get <InventoryComponent>();
            var windrose  = _ioc.Get <WindRoseComponent>();

            inventory.PlayerInventoryWindow    = _ioc.Get <PlayerInventory>();
            inventory.ContainerInventoryWindow = _ioc.Get <ContainerInventory>();

            var skyBackBuffer = _ioc.Get <StaggingBackBuffer>("SkyBuffer");

            skyBackBuffer.DrawOrders.UpdateIndex(0, 50, "SkyBuffer");

            var chat    = _ioc.Get <ChatComponent>();
            var hud     = _ioc.Get <Hud>();
            var stars   = _ioc.Get <IDrawableComponent>("Stars");
            var clouds  = _ioc.Get <IDrawableComponent>("Clouds");
            var skyDome = _ioc.Get <ISkyDome>();
            var weather = _ioc.Get <IWeather>();

            var solidCubeMeshFactory      = _ioc.Get <ICubeMeshFactory>("SolidCubeMeshFactory");
            var liquidCubeMeshFactory     = _ioc.Get <ICubeMeshFactory>("LiquidCubeMeshFactory");
            var singleArrayChunkContainer = _ioc.Get <SingleArrayChunkContainer>();
            var landscapeManager          = _ioc.Get <ILandscapeManager2D>();
            var lightingManager           = _ioc.Get <ILightingManager>();
            var chunkMeshManager          = _ioc.Get <IChunkMeshManager>();
            var worldChunks              = _ioc.Get <IWorldChunks>();
            var worldShadowMap           = ClientSettings.Current.Settings.GraphicalParameters.ShadowMap ? _ioc.Get <WorldShadowMap>() : null;
            var chunksWrapper            = _ioc.Get <IChunksWrapper>();
            var fadeComponent            = _ioc.Get <FadeComponent>();
            var pickingRenderer          = _ioc.Get <IPickingRenderer>();
            var playerEntityManager      = (PlayerEntityManager)_ioc.Get <IPlayerManager>();
            var selectedBlocksRenderer   = _ioc.Get <SelectedBlocksRenderer>();
            var chunkEntityImpactManager = _ioc.Get <IChunkEntityImpactManager>();
            var entityPickingManager     = _ioc.Get <IEntityCollisionManager>();
            var dynamicEntityManager     = _ioc.Get <IVisualDynamicEntityManager>();
            var voxelMeshFactory         = _ioc.Get <VoxelMeshFactory>();
            var sharedFrameCB            = _ioc.Get <SharedFrameCB>();
            var itemMessageTranslator    = _ioc.Get <ItemMessageTranslator>();
            var entityMessageTranslator  = _ioc.Get <EntityMessageTranslator>();
            var soundManager             = _ioc.Get <GameSoundManager>();
            var voxelModelManager        = _ioc.Get <VoxelModelManager>();
            var toolRenderer             = _ioc.Get <FirstPersonToolRenderer>();
            var particuleEngine          = _ioc.Get <UtopiaParticuleEngine>();
            var ghostedRenderer          = _ioc.Get <GhostedEntityRenderer>();
            var crafting            = _ioc.Get <CraftingComponent>();
            var charSelection       = _ioc.Get <CharacterSelectionComponent>();
            var inventoryEvents     = _ioc.Get <InventoryEventComponent>();
            var cracksRenderer      = _ioc.Get <CracksRenderer>();
            var postEffectComponent = _ioc.Get <PostEffectComponent>();

            //Assign the various Post Processing effect to the component
            //Ghost PostEffect
            IPostEffect ghost = new PostEffectGhost()
            {
                Name = "Dead"
            };

            postEffectComponent.RegisteredEffects.Add(ghost.Name, ghost);

            landscapeManager.EntityFactory    = clientFactory;
            playerEntityManager.HasMouseFocus = true;
            cameraManager.SetCamerasPlugin(playerEntityManager);
            ((ThirdPersonCameraWithFocus)thirdPersonCamera).CheckCamera += worldChunks.ValidatePosition;
            chunkEntityImpactManager.LateInitialization(serverComponent, singleArrayChunkContainer, worldChunks, chunkStorageManager, lightingManager, visualWorldParameters);

            clientFactory.DynamicEntityManager = _ioc.Get <IVisualDynamicEntityManager>();
            clientFactory.GlobalStateManager   = _ioc.Get <IGlobalStateManager>();

            //Late Inject PlayerCharacter into VisualWorldParameters
            var c = clouds as Clouds;

            if (c != null)
            {
                c.LateInitialization(sharedFrameCB);
            }

            LoadMissingModels(clientSideworldParam.Configuration, voxelModelManager);

            AddComponent(cameraManager);
            AddComponent(serverComponent);
            AddComponent(inputsManager);
            AddComponent(iconFactory);
            AddComponent(timerManager);
            AddComponent(skyBackBuffer);
            AddComponent(playerEntityManager);
            AddComponent(dynamicEntityManager);
            AddComponent(hud);
            AddComponent(guiManager);
            AddComponent(pickingRenderer);
            AddComponent(inventory);
            AddComponent(windrose);
            AddComponent(chat);
            AddComponent(skyDome);
            AddComponent(gameClock);
            AddComponent(weather);
            AddComponent(worldChunks);
            AddComponent(sharedFrameCB);
            AddComponent(soundManager);
            AddComponent(voxelModelManager);
            AddComponent(toolRenderer);
            AddComponent(fadeComponent);
            AddComponent(particuleEngine);
            AddComponent(ghostedRenderer);
            AddComponent(crafting);
            AddComponent(inventoryEvents);
            AddComponent(cracksRenderer);
            AddComponent(charSelection);
            AddComponent(postEffectComponent);

            if (ClientSettings.Current.Settings.GraphicalParameters.ShadowMap)
            {
                AddComponent(worldShadowMap);
            }

            //Will start the initialization of the newly added Components on the states, and Activate them
            StatesManager.ActivateGameStateAsync(this);

            worldChunks.LoadComplete += worldChunks_LoadComplete;

            var engine = _ioc.Get <D3DEngine>();

            inputsManager.MouseManager.MouseCapture = true;
        }