Exemple #1
0
    public void ClickWatcherCycleTargetNext()
    {
        TrophicSlot slotRef = uiManagerRef.worldSpiritHubUI.selectedWorldSpiritSlot;  // ************* TEMP!!!!!!!!!

        if (slotRef.id == KnowledgeMapId.Plants)
        {
            VegetationManager veggieRef = simulationManager.vegetationManager;
            veggieRef.selectedPlantParticleIndex++;

            if (veggieRef.selectedPlantParticleIndex > veggieRef.plantParticlesCBuffer.count - 1)
            {
                veggieRef.selectedPlantParticleIndex = 0;
                veggieRef.isPlantParticleSelected    = true; // ???
            }
        }
        else if (slotRef.id == KnowledgeMapId.Microbes)
        {
            ZooplanktonManager zoopRef = simulationManager.zooplanktonManager;
            zoopRef.selectedAnimalParticleIndex++;
            if (zoopRef.selectedAnimalParticleIndex > zoopRef.animalParticlesCBuffer.count - 1)
            {
                zoopRef.selectedAnimalParticleIndex = 0;
                zoopRef.isAnimalParticleSelected    = true; // ???
            }
        }
        else if (slotRef.id == KnowledgeMapId.Animals)
        {
            //ClickNextAgent();
        }
    }
    public void Tick(VegetationManager vegetationManagerRef)
    {
        computeShaderFluidSim.SetFloat("_Time", Time.time);
        computeShaderFluidSim.SetFloat("_ForceMagnitude", forceMultiplier);
        computeShaderFluidSim.SetFloat("_Viscosity", viscosity);
        computeShaderFluidSim.SetFloat("_Damping", damping);
        computeShaderFluidSim.SetFloat("_MapSize", SimulationManager._MapSize);
        computeShaderFluidSim.SetFloat("_ColorRefreshAmount", colorRefreshBackgroundMultiplier);

        // Lerp towards sourceTexture color:
        //RefreshColor(vegetationManagerRef);

        // ADVECTION:::::
        Advection(velocityPressureDivergenceMain, velocityPressureDivergenceSwap);
        //Graphics.Blit(velocityB, velocityA); // TEMP! slow...

        // ******************** TEMPORARY!!! BRING THIS BACK OR REPLACE WITH Texture-based approach!!!! *******
        VelocityInjectionPoints(velocityPressureDivergenceSwap, velocityPressureDivergenceMain);

        // VISCOUS DIFFUSION:::::

        /*int numViscousDiffusionIter = 8;
         * for(int i = 0; i < numViscousDiffusionIter; i++) {
         *  if(i % 2 == 0) {
         *      ViscousDiffusion(velocityA, velocityB);
         *  }
         *  else {
         *      ViscousDiffusion(velocityB, velocityA);
         *  }
         * }*/
        // if #iter is even, then velA will hold latest values, so no need to Blit():

        // DIVERGENCE:::::
        VelocityDivergence(velocityPressureDivergenceMain, velocityPressureDivergenceSwap);  // calculate velocity divergence

        // PRESSURE JACOBI:::::
        //InitializePressure();  // zeroes out initial pressure guess // doesn't seem to produce great results
        int numPressureJacobiIter = 64;

        for (int i = 0; i < numPressureJacobiIter; i++)
        {
            if (i % 2 == 0)
            {
                PressureJacobi(velocityPressureDivergenceSwap, velocityPressureDivergenceMain);
            }
            else
            {
                PressureJacobi(velocityPressureDivergenceMain, velocityPressureDivergenceSwap);
            }
        }

        // SUBTRACT GRADIENT:::::
        SubtractGradient(velocityPressureDivergenceSwap, velocityPressureDivergenceMain);
        //Graphics.Blit(velocityPressureDivergenceSwap, velocityPressureDivergenceMain); // TEMP! slow...

        //SimFloatyBits();
        //SimRipples();
        //SimTrailDots();
    }
        public bool CheckCollision(Stone stone)
        {
            Client client = GetClientList().FirstOrDefault(c => !c.Leprechaun.IsInvulnerable && c.Leprechaun != stone.Mushroom.Owner && c.Leprechaun.Intersects(stone));

            if (client != null)
            {
                client.Send(new NetworkPacketStoneHit());
            }

            return(client != null || VegetationManager.IntersectsAny(stone) || stone.Position.Y < Terrain.GetHeight(stone.Position).Y);
        }
Exemple #4
0
 private void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
     }
     else
     {
         Destroy(gameObject);
     }
 }
    public void Tick(TrophicLayersManager trophicLayersManager, VegetationManager veggieManager)
    {
        float nutrientsProduced            = 0f;
        float decomposersTotalProductivity = 0f;

        if (trophicLayersManager.IsLayerOn(KnowledgeMapId.Decomposers))
        {
            float decomposersOxygenMask   = Mathf.Clamp01(curGlobalOxygen * settings.environmentSettings._DecomposersOxygenMask);
            float decomposersDetritusMask = Mathf.Clamp01(curGlobalDetritus * settings.environmentSettings._DecomposersDetritusMask);
            decomposersTotalProductivity = curGlobalDecomposers * settings.environmentSettings._BaseDecompositionRate * decomposersOxygenMask * decomposersDetritusMask;

            detritusRemovedByDecomposersLastFrame = decomposersTotalProductivity;
            curGlobalDetritus -= decomposersTotalProductivity;

            nutrientsProduced = decomposersTotalProductivity * settings.environmentSettings._DetritusToNutrientsEfficiency;
            nutrientsProducedByDecomposersLastFrame = nutrientsProduced;
        }

        // waste from algaeReservoir???
        //curGlobalDetritus += wasteProducedByAlgaeReservoirLastFrame;
        curGlobalDetritus += wasteProducedByAnimalParticlesLastFrame;   // will have to add these inputs into the resourceGrid sim texture
        curGlobalDetritus += wasteProducedByPlantParticlesLastFrame;
        curGlobalDetritus += wasteProducedByAgentsLastFrame;
        curGlobalDetritus  = Mathf.Max(0f, curGlobalDetritus); // cap at 0f
        curGlobalDetritus  = Mathf.Min(curGlobalDetritus, 1000f);

        curGlobalNutrients += nutrientsProduced;
        //curGlobalNutrients -= algaeReservoirGrowth;
        curGlobalNutrients -= nutrientsUsedByPlantParticlesLastFrame;
        curGlobalNutrients  = Mathf.Max(0f, curGlobalNutrients); // cap at 0f
        curGlobalNutrients  = Mathf.Min(curGlobalNutrients, 1000f);

        // ***** TEMP!!!!!
        curGlobalNutrients      = veggieManager.curGlobalNutrientGridValues.x;
        curGlobalDetritus       = veggieManager.curGlobalNutrientGridValues.y + wasteProducedByAgentsLastFrame + wasteProducedByAnimalParticlesLastFrame;
        curGlobalDecomposers    = veggieManager.curGlobalNutrientGridValues.z;
        curGlobalAlgaeReservoir = veggieManager.curGlobalNutrientGridValues.w;
        //oxygenUsedByAgentsLastFrame
        curTotalMass = curGlobalNutrients + curGlobalDetritus + curGlobalDecomposers + curGlobalAlgaeReservoir;
    }
        public Server()
        {
            Clients           = new ConcurrentDictionary <byte, Client>(Config.MaxPlayers + 1, Config.MaxPlayers);
            Terrain           = new Terrain();
            VegetationManager = new VegetationManager(Terrain);
            ItemsManager      = new ItemsManager(this);
            PigAI             = new PigAI(this);
            MushroomAI        = new MushroomAI(this);
            TrapManager       = new TrapManager();

            try
            {
                var server = new Socket(AddressFamily.Unspecified, Config.SocketType, Config.ProtocolType);

                server.Bind(new IPEndPoint(IPAddress.Any, Config.Port));
                server.Listen(Config.Backlog);

                Console.WriteLine("Server started. Waiting for Clients...");

                new Thread(PigAI.Start).Start();
                new Thread(MushroomAI.Start).Start();

                while (true)
                {
                    Socket socket = server.Accept();

                    byte playerId = 0;

                    while (Clients.Keys.Contains(playerId))
                    {
                        playerId++;
                    }

                    if (playerId > Config.MaxPlayers)
                    {
                        continue;
                    }

                    var newClient = new Client(this, socket, playerId);

                    foreach (Client client in Clients.Values)
                    {
                        newClient.Send(new NetworkPacketAddPlayer(client.PlayerId, Config.PlayerColors[client.PlayerId], Config.RainbowPositions[client.PlayerId]));
                    }

                    Send(new NetworkPacketAddPlayer(newClient.PlayerId, Config.PlayerColors[newClient.PlayerId], Config.RainbowPositions[newClient.PlayerId]));

                    while (!Clients.TryAdd(playerId, newClient))
                    {
                        Thread.Sleep(1);
                    }

                    new Thread(newClient.Start).Start();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.ReadKey();
        }