Beispiel #1
0
    public void InitPlanet(List <StarInfo> initList)
    {
        //init log
        if (SYS_Logger.Direct.logging)
        {
            foreach (StarInfo starInfo in initList)
            {
                Debug.LogWarning("[Gen]BayerID : " + starInfo.sID + " , BayerName : " + starInfo.sName + " , Type : " + starInfo.sType.ToString() + " , Location : " + starInfo.sPos);
            }
        }

        //gen star
        foreach (StarInfo starInfo in initList)
        {
            PlanetEntity objGen = Instantiate(pfbPlanet).GetComponent <PlanetEntity>();
            objGen.transform.SetParent(entityGroup);
            objGen.transform.localPosition = new Vector3(starInfo.sPos.x * scaleRate, starInfo.sPos.y * scaleRate, 0);
            objGen.name = starInfo.sName;

            if (starInfo.sType == StarType.Check)
            {
                objGen.Regist(starInfo, matPlanets[Random.Range(0, matPlanets.Count)], Random.Range(0.75f, 1.5f), Random.Range(0, 3) == 2);
            }
            else
            {
                objGen.Regist(starInfo, matPlanets[Random.Range(0, matPlanets.Count)], Random.Range(1, 1.75f), Random.Range(0, 3) == 2);
                tgtPlanet = objGen;
            }

            UI_Navigator.Direct.Regist(objGen);
            planets.Add(objGen);
        }
    }
Beispiel #2
0
    public void Regist(PlanetEntity entity)
    {
        UI_NavigateHint objGen = Instantiate(nvPfb).GetComponent <UI_NavigateHint>();

        objGen.transform.SetParent(transform);
        objGen.Regist(entity);
    }
 private void OnSignalDestroy()
 {
     property.SetColor("_color", onWaterColor);
     Destroy(this.holding.gameObject);
     Destroy(this.radiusSphereInstance);
     this.holding = null;
 }
Beispiel #4
0
    void Update()
    {
        if (SYS_SpaceManager.Direct.planets.Count > 0)
        {
            PlanetEntity lowestPlanet = null;

            foreach (PlanetEntity planet in SYS_SpaceManager.Direct.planets)
            {
                if (planet.info.sType == StarType.Check && planet.transform.position.y > SYS_ShipController.Direct.transform.position.y)
                {
                    float shipDis = Vector2.Distance(planet.transform.position, SYS_ShipController.Direct.transform.position);

                    if (lowestPlanet != null)
                    {
                        if (shipDis < Vector2.Distance(lowestPlanet.transform.position, SYS_ShipController.Direct.transform.position) && shipDis > closeDis)
                        {
                            if (shipDis < Vector2.Distance(SYS_SpaceManager.Direct.tgtPlanet.transform.position, SYS_ShipController.Direct.transform.position))
                            {
                                lowestPlanet = planet;
                            }
                        }
                    }
                    else if (shipDis > closeDis)
                    {
                        if (shipDis < Vector2.Distance(SYS_SpaceManager.Direct.tgtPlanet.transform.position, SYS_ShipController.Direct.transform.position))
                        {
                            lowestPlanet = planet;
                        }
                    }
                }
            }

            nextPlanet = lowestPlanet;
        }
    }
        private void CreatePlanets()
        {
            if (LevelMetadata.Planets == null)
            {
                return;
            }

            var position = LevelMetadata.Position;

            foreach (var planetMeta in LevelMetadata.Planets)
            {
                var modelName = planetMeta.Model;

                var prop = GTAUtil.CreateProp(modelName, position);

                if (prop == null)
                {
                    continue;
                }

                prop.Rotation = planetMeta.Rotation;

                var planetEntity = new PlanetEntity(prop, planetMeta);

                Planets.Add(planetEntity);
            }
        }
Beispiel #6
0
    public void Update()
    {
        if (!this.generator.Loaded())
        {
            return;
        }
        if (this.electricity > 0)
        {
            while (this.lowElectricityQueue.Count > 0)
            {
                PlanetEntity e = this.lowElectricityQueue.Pop();

                if (!this.lowPopulationQueue.Contains(e))
                {
                    e.StartRunning();
                }
            }
        }

        if (this.activeWorkers < this.population)
        {
            while (this.lowPopulationQueue.Count > 0 && this.activeWorkers < this.population)
            {
                PlanetEntity e = this.lowPopulationQueue.Pop();
                e.AddWorkers(this.population - this.activeWorkers >= e.entityData.activeWorkersRequirement ? e.entityData.activeWorkersRequirement : this.population - this.activeWorkers);
                this.activeWorkers += e.ActiveWorkers;

                if (!this.lowElectricityQueue.Contains(e))
                {
                    e.StartRunning();
                }
            }
        }
    }
Beispiel #7
0
    public void PlaceMine(Vector3 point)
    {
        PlanetEntity obj = GameObject.Instantiate(mine, point, Quaternion.identity);

        obj.transform.SetParent(planet.transform);
        obj.RotateTowardsPlanet(planet);
        obj.PlaceOnPlanet(planet, point);
    }
Beispiel #8
0
 public void Reset()
 {
     foreach (Transform child in entityGroup)
     {
         Destroy(child.gameObject);
     }
     planets   = new List <PlanetEntity>();
     tgtPlanet = null;
 }
    public void PlaceObject(ObjectPlacerListener listener, EntityName entity, UnityAction onPlace)
    {
        this.listener = listener;
        this.listener.OnCancelListener(OnSignalDestroy);
        PlanetEntity e = PrefabData.Instance.GetEntity(entity);

        HoldPlanetEntity(e);
        this.onPlace = onPlace;
    }
Beispiel #10
0
 public ResourceGenerator(Planet planet, PlanetEntity mine, PlanetEntity tree, NoiseSettings noiseSettigns)
 {
     this.settings = new NoiseSettings();
     this.settings.baseRoughness = 3f;
     this.settings.numLayers     = 2f;
     this.settings.strength      = 2f;
     this.settings.persistance   = 1.6f;
     this.settings.center        = planet.transform.position;
     this.tree   = tree;
     this.planet = planet;
     this.mine   = mine;
 }
Beispiel #11
0
        private void OnEntitySpawnItemSelected(object sender, NativeMenuItemEventArgs e)
        {
            if (e.MenuItem.Tag is string model)
            {
                var prop = GTAUtil.CreateProp(model, activateLevelMetadata.Position);

                if (prop != null)
                {
                    var spawnOffset = CameraManager.LevelEditorCamera.Direction * 1500;

                    var spawnPos = CameraManager.LevelEditorCamera.Position + spawnOffset;

                    var planetMeta = new Planet
                    {
                        Model  = model,
                        Offset = spawnPos - activateLevelMetadata.Position,
                    };

                    if (activateLevelMetadata.Planets == null)
                    {
                        activateLevelMetadata.Planets = new List <Planet>();
                    }

                    activateLevelMetadata.Planets.Add(planetMeta);

                    if (activateLevel.PropManager.Planets == null)
                    {
                        activateLevel.PropManager.Planets = new List <PlanetEntity>();
                    }

                    var planetEntity = new PlanetEntity(prop, planetMeta);

                    activateLevel.PropManager.Planets.Add(planetEntity);

                    var menu = CreateMenuForObject(planetMeta, model);

                    menu.Init();

                    MenuManager.NativeMenuManager.AddMenu(menu);

                    MenuManager.NativeMenuManager.CloseAllMenus();

                    menu.Visible = true;

                    AddEditMenuBinding(planetEntity, menu);

                    InitEntityDatabase();
                }
            }
        }
Beispiel #12
0
 private static Planet ConvertToPlanet(PlanetEntity entity)
 {
     return(new Planet
     {
         Name = entity.Name,
         DistanceFromSun = entity.DistanceFromSun,
         Mass = entity.Mass,
         Diameter = entity.Diameter,
         LengthOfDay = entity.LengthOfDay,
         OrbitalPeriod = entity.OrbitalPeriod,
         OrbitalVelocity = entity.OrbitalVelocity,
         ImageUrl = entity.ImageUrl
     });
 }
Beispiel #13
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            skybox = new Skybox("Textures/Background1", Content);

            spriteFont = Content.Load <SpriteFont>("Fonts/Font1");

            gameManager.RegisterModel(EntityType.Asteroid, new GameModel(GraphicsDevice, Content, "Models/asteroid"));
            //gameManager.RegisterModel(EntityType.Player, new GameModel(GraphicsDevice, Content, "Models/Ship"));
            gameManager.RegisterModel(EntityType.PlanetEarth, new GameModel(GraphicsDevice, Content, "Models/earth"));

            ShipEntity playerEntity = new ShipEntity(this, new Sphere(new BEPUutilities.Vector3(0, 10, 350), 1, 100));

            playerEntity.SetScale(0.001f);
            cameraTarget = gameManager.RegisterEntity(playerEntity);

            PlanetEntity earthEntity = new PlanetEntity(this, EntityType.PlanetEarth, new Sphere(new BEPUutilities.Vector3(0, 0, -200), 225));

            earthEntity.SetScale(50f);
            earthEntity.PhysicsEntity.AngularVelocity = MathConverter.Convert(new Vector3(0.005f, 0.001f, 0.001f));
            earthEntity.PhysicsEntity.AngularDamping  = 0f;
            gameManager.RegisterEntity(earthEntity);

            inputManager = new InputManager(this, gameManager, playerEntity);

            GenerateAsteroids();

            textureRearviewMirror          = Content.Load <Texture2D>("Textures/rearviewmirror");
            textureRearviewMirrorMask      = Content.Load <Texture2D>("Textures/rearviewmirror_mask");
            textureSideviewMirrorLeft      = Content.Load <Texture2D>("Textures/sideviewmirrorleft");
            textureSideviewMirrorLeftMask  = Content.Load <Texture2D>("Textures/sideviewmirrorleft_mask");
            textureSideviewMirrorRight     = Content.Load <Texture2D>("Textures/sideviewmirrorright");
            textureSideviewMirrorRightMask = Content.Load <Texture2D>("Textures/sideviewmirrorright_mask");

            rearviewMirrorMask      = new Color[textureRearviewMirrorMask.Width * textureRearviewMirrorMask.Height];
            sideviewMirrorLeftMask  = new Color[textureSideviewMirrorLeftMask.Width * textureSideviewMirrorLeftMask.Height];
            sideviewMirrorRightMask = new Color[textureSideviewMirrorRightMask.Width * textureSideviewMirrorRightMask.Height];
            textureRearviewMirrorMask.GetData(rearviewMirrorMask);
            textureSideviewMirrorLeftMask.GetData(sideviewMirrorLeftMask);
            textureSideviewMirrorRightMask.GetData(sideviewMirrorRightMask);

            starfield = new Starfield(this, spriteBatch, Window.ClientBounds.Width, Window.ClientBounds.Height);

            InitializeCamera();
        }
Beispiel #14
0
    public void HoldPlanetEntity(PlanetEntity planetEntity)
    {
        this.holding = Instantiate(planetEntity);
        this.holding.transform.position = Vector3.zero;
        //this.holding.transform.localScale = Vector3.one;
        this.holding.transform.rotation = Quaternion.identity;
        this.holding.transform.SetParent(this.transform);

        property.SetColor("_color", onWaterColor);
        this.radiusSphereInstance = Instantiate(this.radiusSpherePrefab);
        sphereCollision           = radiusSphereInstance.GetComponent <SphereCollisionHandler>();
        sphereCollision.setHolding(this.holding.gameObject);
        this.radiusSphereInstance.transform.position   = Vector3.zero;
        this.radiusSphereInstance.transform.rotation   = Quaternion.identity;
        this.radiusSphereInstance.transform.localScale = new Vector3(planetEntity.sphereRadius, 1, planetEntity.sphereRadius);
        this.radiusSphereInstance.GetComponent <MeshRenderer>().SetPropertyBlock(property);
        this.radiusSphereInstance.transform.SetParent(this.transform);
    }
Beispiel #15
0
    void Update()
    {
        if (TargetPlanet == null)
        {
            TargetPlanet = GameObject.FindObjectOfType <PlanetEntity>();
        }

        if (Application.isPlaying)
        {
            Zoom  += Input.GetAxis("Mouse ScrollWheel") * 10.0f;
            View  += new Vector2(Input.GetAxis("MoveX") * 0.1f, Input.GetAxis("MoveZ") * 0.1f);
            View.y = Mathf.Clamp(View.y, 0.001f, Mathf.PI - 0.001f);
        }

        Shader.SetGlobalVector("_SunlightPos", GameObject.Find("Sun").transform.position);

        float zoom = Zoom * Mathf.Sin(View.y);

        transform.position = TargetPlanet.transform.position + new Vector3(Mathf.Sin(View.x) * zoom, Mathf.Cos(View.y) * Zoom, Mathf.Cos(View.x) * zoom);
        transform.LookAt(TargetPlanet.transform.position, Vector3.up);
    }
Beispiel #16
0
    public void Show(PlanetEntity entity)
    {
        if (inst == null)
        {
            inst = PanelInstance.CreateInstance <PanelInstanceObject>(PanelName.PANEL_OBJECT_INFO).GetComponent();
        }

        inst.title.SetText(entity.entityData.name);
        inst.description.SetText(entity.entityData.description);

        if (entity.entityData.canSell)
        {
            this.inst.sellAmount.gameObject.SetActive(true);
            this.inst.sellButton.gameObject.SetActive(true);

            inst.sellAmount.SetText("$ " + (entity.entityData.cost * ConstMultiplier.MONEY).ToString());
            inst.sellButton.ClearEvents();
            inst.sellButton.RegisterOnClickEvent(() =>
            {
                if (entity.gameObject == null)
                {
                    return;
                }

                Player.Instance.money += entity.entityData.cost * ConstMultiplier.MONEY;
                Object.Destroy(entity.gameObject);
                this.inst.gameObject.SetActive(false);
            });
        }
        else
        {
            this.inst.sellAmount.gameObject.SetActive(false);
            this.inst.sellButton.gameObject.SetActive(false);
        }

        ShowEntityInfo(entity);
        inst.closer.SetUIVisible(true);
    }
Beispiel #17
0
 // Update is called once per frame
 void Update()
 {
     if (EventSystem.current.IsPointerOverGameObject())
     {
         return;
     }
     ray = this.mainCamera.ScreenPointToRay(Input.mousePosition);
     if (Input.GetMouseButtonUp(0) && Physics.Raycast(ray, out hit, Mathf.Infinity, ~(1 << 8) | (1 << 8)))
     {
         if (hit.transform.gameObject.layer == 8)
         {
             //info.ShowEntity(hit.transform.gameObject.GetComponent<PlanetEntity>().entityData);
             PlanetEntity e = hit.transform.gameObject.GetComponent <PlanetEntity>();
             if (e != null && e.HasPlaced)
             {
                 PanelManager.Get <PanelObjectInfo>().Show(e);
             }
         }
         else
         {
             PanelManager.Get <PanelObjectInfo>().Hide();
         }
     }
 }
Beispiel #18
0
    private void ShowEntityInfo(PlanetEntity entity)
    {
        inst.info.text = "";
        if (entity.entityData.electricity != 0)
        {
            string prefix = entity.entityData.electricity > 0 ? "+" : "";
            string color  = entity.entityData.electricity < 0 ? "#FF0000" : "#00FF00";
            inst.info.text += $"<sprite=0> Electricity: <color={color}>{prefix}{entity.entityData.electricity} ({entity.ActiveStatus})</color>\n";
        }

        if (entity.entityData.pollution != 0)
        {
            string prefix = entity.entityData.pollution > 0 ? "+" : "";
            string color  = entity.entityData.pollution > 0 ? "#FF0000" : "#00FF00";
            inst.info.text += $"<sprite=1> Pollution: <color={color}>{prefix}{entity.entityData.pollution}\n</color>";
        }

        if (entity.entityData.activeWorkersRequirement > 0)
        {
            inst.info.text += $"<sprite=3> Worker capacity: <color=#FFFFFF>{entity.ActiveWorkers} / {entity.entityData.activeWorkersRequirement}\n</color>";
        }

        if (entity.entityData.populationIncrease != 0)
        {
            string prefix = entity.entityData.populationIncrease > 0 ? "+" : "";
            string color  = entity.entityData.populationIncrease < 0 ? "#FF0000" : "#00FF00";
            inst.info.text += $"<sprite=2> Increases population by: <color={color}>{prefix}{entity.entityData.populationIncrease}\n</color>";
        }

        if (entity.entityData.happiness != 0)
        {
            string prefix = entity.entityData.happiness > 0 ? "+" : "";
            string color  = entity.entityData.happiness < 0 ? "#FF0000" : "#00FF00";
            inst.info.text += $"<sprite=2> Happiness: <color={color}>{prefix}{entity.entityData.happiness}\n</color>";
        }
    }
Beispiel #19
0
 public void Add(PlanetEntity entity)
 {
     this.entities.Add(entity);
 }
Beispiel #20
0
 public void Regist(PlanetEntity entity)
 {
     this.entity = entity;
     UpdateHint();
 }
Beispiel #21
0
    public void Update()
    {
        if (EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }
        if (this.holding == null)
        {
            return;
        }

        RaycastHit hit;
        Ray        ray = this.mainCamera.ScreenPointToRay(Input.mousePosition);

        if (Input.GetKeyUp(KeyCode.Escape))
        {
            DestroyHolding();
            return;
        }
        if (Physics.Raycast(ray, out hit, Mathf.Infinity, ~(1 << 8)))
        {
            bool ignorewaterCheck = false;
            if (hit.transform.gameObject.tag.Equals("PlanetSide") && hit.transform.parent.gameObject.Equals(this.gameObject))
            {
                if (this.holding.GetComponent <Mine>() != null)
                {
                    Collider[] hits = Physics.OverlapSphere(hit.point, 0.1f);
                    foreach (var h in hits)
                    {
                        if (h.transform.CompareTag("Vespene"))
                        {
                            //Fulhack
                            property.SetColor("_color", onLandColor);
                            this.radiusSphereInstance.GetComponent <MeshRenderer>().SetPropertyBlock(property);
                            this.holding.transform.position = h.transform.position;
                            this.holding.RotateTowardsPlanet(this.instance);
                            this.radiusSphereInstance.transform.position = this.holding.transform.position;
                            this.radiusSphereInstance.transform.rotation = this.holding.transform.rotation;

                            if (Input.GetMouseButton(0))
                            {
                                Vector3 p = hit.point + this.holding.transform.up * holding.colliderHeight * 0.5f;
                                this.holding.PlaceOnPlanet(instance, this.holding.transform.position);
                                Destroy(h.gameObject);
                                UI.Instance.ShowWorldText("+5 xp", p, new Color(238 / 256f, 130 / 256f, 238 / 256f));
                                UI.Instance.ShowWorldText("-" + this.holding.entityData.cost + " money", p, Color.red, 1);
                                this.holding = null;
                                this.listener.SignalOnPlace();
                                Destroy(this.radiusSphereInstance);
                                this.listener.SignalOnPlace();
                                this.onPlace?.Invoke();
                                return;
                            }

                            return;
                        }
                        else
                        {
                            property.SetColor("_color", onWaterColor);
                            this.radiusSphereInstance.GetComponent <MeshRenderer>().SetPropertyBlock(property);
                        }
                    }

                    ignorewaterCheck = true;
                    this.holding.transform.position = hit.point + this.holding.transform.up * holding.colliderHeight * 0.5f;
                    this.radiusSphereInstance.transform.position = this.holding.transform.position;
                    this.holding.RotateTowardsPlanet(this.instance);
                    this.radiusSphereInstance.transform.rotation = this.holding.transform.rotation;
                    return;
                }

                this.holding.RotateTowardsPlanet(this.instance);
                this.radiusSphereInstance.transform.rotation = this.holding.transform.rotation;
                Vector3 point = hit.point + this.holding.transform.up * holding.colliderHeight * 0.5f;

                if (!ignorewaterCheck)
                {
                    float min        = planetGenerator.getMinMax().Min;
                    float max        = planetGenerator.getMinMax().Max;
                    float waterRange = min + 5 / 256f;
                    if (Vector3.Distance(point, this.transform.position) <= waterRange || sphereCollision.isColliding())
                    {
                        if (!onWater)
                        {
                            property.SetColor("_color", onWaterColor);
                            this.radiusSphereInstance.GetComponent <MeshRenderer>().SetPropertyBlock(property);
                        }
                        onWater = true;
                    }
                    else
                    {
                        if (onWater)
                        {
                            property.SetColor("_color", onLandColor);
                            this.radiusSphereInstance.GetComponent <MeshRenderer>().SetPropertyBlock(property);
                        }

                        onWater = false;
                    }
                }
                this.holding.transform.position = point;
                this.radiusSphereInstance.transform.position = this.holding.transform.position;
                if (Input.GetMouseButton(0) && !onWater)
                {
                    this.holding.PlaceOnPlanet(instance, point);
                    UI.Instance.ShowWorldText("+5 xp", point, new Color(238 / 256f, 130 / 256f, 238 / 256f));
                    UI.Instance.ShowWorldText("-" + this.holding.entityData.cost + " money", point, Color.red, 1);
                    this.holding = null;
                    this.listener.SignalOnPlace();
                    Destroy(this.radiusSphereInstance);
                    this.listener.SignalOnPlace();
                    this.onPlace?.Invoke();
                }
            }
        }
        else
        {
            this.holding.transform.position = Vector3.zero;
            if (Input.GetMouseButton(0))
            {
                DestroyHolding();
            }
        }
    }
Beispiel #22
0
    // Update is called once per frame
    void Update()
    {
        if (!ready)
        {
            return;
        }

        GameObject[] spawners = GameObject.FindGameObjectsWithTag("SpawnPoint");
        foreach (GameObject sp in spawners)
        {
            Vector3    spawnpos = sp.transform.position / 80.0f; //weird huh
            SpawnPoint spoint   = sp.GetComponent <SpawnPoint>();

            if (Time.time - spoint.last_spawn_time > spoint.torrentialness)
            {
                spoint.last_spawn_time = Time.time;
                SpawnParticle(spawnpos);
            }
        }


        //edit the quant grid to set the vector field state
        // if (Input.GetMouseButton(0))
        {
            int kernelHandle = vector_field_editor.FindKernel("CSMain");
            vector_field_editor.SetTexture(kernelHandle, "vector_field", vector_field);

            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            int        state = 0;
            if (Input.GetMouseButton(0))
            {
                state = 1;
            }
            if (Input.GetMouseButton(1))
            {
                state = 2;
            }
            vector_field_editor.SetInt("editing_state", state);

            if (GetComponent <MeshCollider>().Raycast(ray, out hit, 10000.0f))
            {
                //raycast to point on the ground plane to edit at
                Vector3 wpos = hit.point;
                wpos  /= 80.0f;
                wpos  += new Vector3(1.0f, 0.0f, 1.0f);
                wpos  /= 2.0f;
                wpos.x = 1.0f - wpos.x;
                wpos.z = 1.0f - wpos.z;

                Vector2 new_pos = new Vector2(wpos.x, wpos.z);

                Vector2 direction = (new_pos - last_edit_vec_pos);
                direction *= 64.0f;

                //clamp vector length
                float mag = direction.magnitude;
                if (mag > 1.0f)
                {
                    mag = 1.0f;
                }
                //todo - I wanted this to have some amount of user variation, but it sucks atm
                //so I Am making all vector unit vectors
                direction = direction.normalized;

                last_edit_vec_pos = new Vector2(wpos.x, wpos.z);

                vector_field_editor.SetVector("edit_pos", new_pos);
                vector_field_editor.SetVector("edit_vector", direction);

                vector_field_editor.SetInt("frame", frame);
            }

            vector_field_editor.Dispatch(kernelHandle, 128 / 8, 128 / 8, 1);
        }

        //first clear up the particle texture
        {
            int kernelHandle = clear_tex_shader.FindKernel("CSMain");
            clear_tex_shader.SetTexture(kernelHandle, "particle_tex", particle_tex);
            clear_tex_shader.Dispatch(kernelHandle, 4096 / 8, 4096 / 8, 1);
        }

        //clean the quant grid
        {
            int kernelHandle = quant_grid_cleaner.FindKernel("CSMain");
            quant_grid_cleaner.SetTexture(kernelHandle, "particle_tex", quantized_unit_grid);
            quant_grid_cleaner.Dispatch(kernelHandle, 64 / 8, 64 / 8, 1);
        }

        GameObject[] ships    = GameObject.FindGameObjectsWithTag("Cruiser");
        Ship[]       shipdata = new Ship[512];

        for (int i = 0; i < ships.Length; i++)
        {
            shipdata[i].pos = new Vector2(ships[i].transform.position.x / 80.0f, ships[i].transform.position.z / 80.0f);
            //convert ship positions into the normalized shader space...
            shipdata[i].pos          += new Vector2(1.0f, 1.0f);
            shipdata[i].pos          /= 2.0f;
            shipdata[i].pos.x         = 1.0f - shipdata[i].pos.x;
            shipdata[i].pos.y         = 1.0f - shipdata[i].pos.y;
            shipdata[i].aim_pos       = new Vector2(-1.0f, -1.0f);
            shipdata[i].mindist       = 10000.0f;
            shipdata[i].enemy_mindist = 10000.0f;
            shipdata[i].enemy_aimpos  = new Vector2(-1.0f, -1.0f);
            shipdata[i].dealt_damage  = 0.0f;
        }

        GameObject[]      explosions    = GameObject.FindGameObjectsWithTag("Explosion");
        ExplosionStruct[] explosiondata = new ExplosionStruct[512]; //not zero, just make room

        for (int i = 0; i < explosions.Length; i++)
        {
            if (i >= explosiondata.Length) //don't overrun the rwbuffer
            {
                break;
            }

            explosiondata[i].pos   = new Vector2(explosions[i].transform.position.x / 80.0f, explosions[i].transform.position.z / 80.0f);
            explosiondata[i].pos  += new Vector2(1.0f, 1.0f);
            explosiondata[i].pos  /= 2.0f;
            explosiondata[i].pos.x = 1.0f - explosiondata[i].pos.x;
            explosiondata[i].pos.y = 1.0f - explosiondata[i].pos.y;

            explosiondata[i].type = explosions[i].GetComponent <Explosion>().explosion_type;
        }

        GameObject[] planets    = GameObject.FindGameObjectsWithTag("Planet");
        Planet[]     planetdata = new Planet[16];
        for (int i = 0; i < planets.Length; i++)
        {
            planetdata[i].pos = new Vector2(planets[i].transform.position.x / 80.0f, planets[i].transform.position.z / 80.0f);

            //use a specified center for the planet object if set
            PlanetEntity pe = planets[i].GetComponent <PlanetEntity>();
            if (pe.centerobj)
            {
                planetdata[i].pos = new Vector2(planets[i].GetComponent <PlanetEntity>().centerobj.transform.position.x / 80.0f, planets[i].GetComponent <PlanetEntity>().centerobj.transform.position.z / 80.0f);
            }

            planetdata[i].pos         += new Vector2(1.0f, 1.0f);
            planetdata[i].pos         /= 2.0f;
            planetdata[i].pos.x        = 1.0f - planetdata[i].pos.x;
            planetdata[i].pos.y        = 1.0f - planetdata[i].pos.y;
            planetdata[i].dealt_damage = 0.0f;
        }

        ComputeBuffer buffer           = new ComputeBuffer(data.Length, 28);
        ComputeBuffer ships_buffer     = new ComputeBuffer(shipdata.Length, 36);
        ComputeBuffer explosion_buffer = new ComputeBuffer(explosiondata.Length, 12);
        ComputeBuffer planet_buffer    = new ComputeBuffer(planetdata.Length, 16);

        buffer.SetData(data);
        ships_buffer.SetData(shipdata);
        explosion_buffer.SetData(explosiondata);
        planet_buffer.SetData(planetdata);

        int kernel = shader.FindKernel("CSMain");

        shader.SetBuffer(kernel, "dataBuffer", buffer);
        shader.SetBuffer(kernel, "shipBuffer", ships_buffer);
        shader.SetBuffer(kernel, "explosionBuffer", explosion_buffer);
        shader.SetBuffer(kernel, "planetBuffer", planet_buffer);

        shader.SetInt("numShips", ships.Length);
        shader.SetInt("numExplosions", explosions.Length);
        shader.SetInt("numPlanets", planets.Length);

        shader.SetFloat("deltatime", Time.deltaTime);

        shader.SetTexture(kernel, "particle_tex", particle_tex);
        shader.SetTexture(kernel, "quantized_unit_grid", quantized_unit_grid);
        shader.SetTexture(kernel, "vector_field", vector_field);

        shader.SetTexture(kernel, "destroyer_sprite", destroyer_sprite);
        shader.Dispatch(kernel, 512, 1, 1);
        buffer.GetData(data);
        ships_buffer.GetData(shipdata);
        planet_buffer.GetData(planetdata);

        for (int i = 0; i < planets.Length; i++)
        {
            if (planetdata[i].dealt_damage != 0.0f)
            {
                Debug.Log("planet hit! " + planetdata[i].dealt_damage);
                //THIS KEEPS TRIGGERING AN EXCEPTION!
                PlanetEntity pe = planets[i].GetComponent <PlanetEntity>();
                planets[i].GetComponent <PlanetEntity>().taking_damage += planetdata[i].dealt_damage;// -= 1;
            }
        }

        for (int i = 0; i < ships.Length; i++)
        {
            if (shipdata[i].dealt_damage != 0.0f)
            {
                ships[i].GetComponent <HumanShip>().taking_damage += shipdata[i].dealt_damage;// -= 1;
            }
            if (shipdata[i].mindist != 10000.0f)
            {
                ships[i].GetComponent <HumanShip>().valid_Aim = true;
            }
            else
            {
                ships[i].GetComponent <HumanShip>().valid_Aim = false;
            }

            if (shipdata[i].enemy_mindist != 10000.0f)
            {
                ships[i].GetComponent <HumanShip>().valid_Aim_Enemy = true;
            }
            else
            {
                ships[i].GetComponent <HumanShip>().valid_Aim_Enemy = false;
            }

            Vector3 aim_pos = new Vector3(shipdata[i].aim_pos.x, 0.0f, shipdata[i].aim_pos.y);
            aim_pos.x = 1.0f - aim_pos.x;
            aim_pos.z = 1.0f - aim_pos.z;
            aim_pos  *= 2.0f;
            aim_pos  -= new Vector3(1.0f, 0.0f, 1.0f);
            aim_pos  *= 80.0f;

            ships[i].GetComponent <HumanShip>().aim_pos = aim_pos;

            Vector3 enemy_aim_pos = new Vector3(shipdata[i].enemy_aimpos.x, 0.0f, shipdata[i].enemy_aimpos.y);
            enemy_aim_pos.x = 1.0f - enemy_aim_pos.x;
            enemy_aim_pos.z = 1.0f - enemy_aim_pos.z;
            enemy_aim_pos  *= 2.0f;
            enemy_aim_pos  -= new Vector3(1.0f, 0.0f, 1.0f);
            enemy_aim_pos  *= 80.0f;

            ships[i].GetComponent <HumanShip>().enemy_aimpos = enemy_aim_pos;
        }

        buffer.Dispose();
        ships_buffer.Dispose();
        explosion_buffer.Dispose();
        planet_buffer.Dispose();

        GetComponent <Renderer>().material.SetTexture("_ParticleTex", particle_tex);
        GetComponent <Renderer>().material.SetTexture("_QuantizedGrid", quantized_unit_grid);
        GetComponent <Renderer>().material.SetTexture("_VectorField", vector_field);
        frame++;
    }
Beispiel #23
0
 internal TestDBProxy WithPlanetEntity(PlanetEntity planetEntity)
 {
     _planets.Insert(planetEntity);
     return(this);
 }
Beispiel #24
0
        private void CommandReceived(CommandReader cr)
        {
            Commands cmd = cr.ReadCommand();

            if (cmd == Commands.UpdateEntity)
            {
                int        entityID   = cr.ReadData <int>();
                EntityType entityType = (EntityType)cr.ReadData <byte>();
                Matrix     world      = cr.ReadMatrix();
                Vector3    scale      = cr.ReadVector3();

                PhysicsShape physicsShape    = (PhysicsShape)cr.ReadData <byte>();
                float        radius          = cr.ReadData <float>();
                float        angularDamping  = cr.ReadData <float>();
                float        linearDamping   = cr.ReadData <float>();
                Vector3      angularVelocity = cr.ReadVector3();
                Vector3      linearVelocity  = cr.ReadVector3();

                GameEntity entity = gameManager.GetEntity(entityID);
                if (entity == null)
                {
                    lock (gameManager)
                    {
                        if (entityType == EntityType.PlanetEarth)
                        {
                            entity = new PlanetEntity(this, entityType, new Sphere(MathConverter.Convert(world.Translation), radius));
                        }
                        else
                        {
                            entity = new GameEntity(this, entityType, new Sphere(MathConverter.Convert(world.Translation), radius));
                        }
                        entity.ID = entityID;
                        gameManager.RegisterEntity(entity);
                    }
                }
                else
                {
                    entity.SetScale(scale.X, scale.Y, scale.Z);
                    entity.PhysicsEntity.AngularDamping  = angularDamping;
                    entity.PhysicsEntity.LinearDamping   = linearDamping;
                    entity.PhysicsEntity.AngularVelocity = MathConverter.Convert(angularVelocity);
                    entity.PhysicsEntity.LinearVelocity  = MathConverter.Convert(linearVelocity);
                    entity.PhysicsEntity.WorldTransform  = MathConverter.Convert(world);
                    //BEPUutilities.Matrix.
                    //entity.World = world;
                    //entity.PhysicsEntity.WorldTransform = new BEPUutilities.Matrix(world.M11, world.M12, world.M13, world.M14, world.M21, world.M22, world.M23, world.M24, world.M31, world.M32, world.M33, world.M34, world.M41, world.M42, world.M43, world.M44);
                }
                if (entityType == EntityType.Player)
                {
                    cameraTarget = entity;
                }

                /*
                 * ServerEntity entity = ServerEntities.ContainsKey(entityID) ? ServerEntities[entityID] : null;
                 * if (entity == null)
                 * {
                 *  entity = new ServerEntity() { ID = entityID, EntityType = entityType, World = world, Model = GetModel(entityType) };
                 *  if (entity.Model != null) entity.BoneTransforms = new Matrix[entity.Model.Bones.Count];
                 *  ServerEntities.Add(entityID, entity);
                 *  ServerEntityIDs.Add(entityID);
                 *  if (entityType == EntityType.Player) CameraTarget = entity;
                 * }
                 * else entity.World = world;
                 */
            }
        }
Beispiel #25
0
 public void QueueEntityForLowElectricityActivation(PlanetEntity entity)
 {
     this.lowElectricityQueue.Push(entity);
 }
Beispiel #26
0
 public void QueueEntityForLowPopulationActivation(PlanetEntity entity)
 {
     this.lowPopulationQueue.Push(entity);
 }