protected override void Load() { //0=128M,1=256M,2=512M,3=1KM. 8.8 reverted SceneMan.MaxLod = ((int)SystemSettingData.Instance.TerrainLevel); PeGrassSystem.Refresh(SystemSettingData.Instance.GrassDensity, (int)SystemSettingData.Instance.GrassLod); base.Load(); }
void Awake() { if (_self == null) { _self = this; } else { Debug.LogError("the Grass system is already exist"); } scene = gameObject.GetComponent <RGScene>(); }
void Update() { PeGrassSystem.SetWaveTexture(GrassWaveRenderer.RenderTarget); if (GrassWaveRenderer.RenderTarget != null) { Vector4 wave_center = Vector4.zero; if (Pathea.PeCreature.Instance.mainPlayer == null) { Vector3 pos = GrassWaveRenderer.transform.position; wave_center = new Vector4(pos.x, pos.z, GrassWaveRenderer.RenderTarget.width, GrassWaveRenderer.RenderTarget.height); } else { PeTrans trans = Pathea.PeCreature.Instance.mainPlayer.peTrans; GrassWaveRenderer.FollowTrans = trans.trans; Vector3 pos = GrassWaveRenderer.transform.position; wave_center = new Vector4(pos.x, pos.z, GrassWaveRenderer.RenderTarget.width, GrassWaveRenderer.RenderTarget.height); } PeGrassSystem.SetWaveCenter(wave_center); } }
/// <summary> /// voxel modify check event before really undo and redo. Call by BSVoxelModify /// </summary> bool OnCheckVoxelModify(int opType, IntVector3[] indexes, BSVoxel[] voxels, BSVoxel[] oldvoxels, EBSBrushMode mode, IBSDataSource ds) { if (IsGod) { return(true); } if (Pathea.PeCreature.Instance.mainPlayer == null) { return(false); } bool result = true; if (mode == EBSBrushMode.Add) { Dictionary <int, int> items = new Dictionary <int, int>(); // Calculate the needed items; int adder = 1; foreach (BSVoxel voxel in voxels) { int id = 0; if (ds == BuildingMan.Blocks) { if (voxel.IsExtendable()) { if (!voxel.IsExtendableRoot()) { id = GetBlockItemProtoID((byte)(voxel.materialType >> 2)); adder = 1; } else { adder = 0; } } else { id = GetBlockItemProtoID(voxel.materialType); } } else if (ds == BuildingMan.Voxels) { id = GetVoxelItemProtoID(voxel.materialType); } if (id <= 0) { continue; } if (id != 0) { if (items.ContainsKey(id)) { items[id] += adder; } else { items.Add(id, adder); } } } _costsItems = items; float divisor = 1.0f; if (ds == BuildingMan.Blocks) { divisor = (float)(1 << BSBlock45Data.s_ScaleInverted); } // Has player enough items ? Pathea.PackageCmpt pkg = Pathea.PeCreature.Instance.mainPlayer.GetCmpt <Pathea.PackageCmpt>(); _playerItems.Clear(); foreach (KeyValuePair <int, int> kvp in items) { _playerItems.Add(kvp.Key, pkg.GetItemCount(kvp.Key)); if (pkg.GetItemCount(kvp.Key) < Mathf.CeilToInt(kvp.Value / divisor)) { result = false; } } // now delete if (result) { if (GameConfig.IsMultiMode) { if (null == PlayerNetwork.mainPlayer) { return(false); } if (!Pathea.PeGameMgr.IsMultiCoop && VArtifactUtil.IsInTownBallArea(PlayerNetwork.mainPlayer._pos)) { new PeTipMsg(PELocalization.GetString(8000864), PeTipMsg.EMsgLevel.Warning); return(false); } //if (!PlayerNetwork.OnLimitBoundsCheck(brushBound)) //{ // new PeTipMsg(PELocalization.GetString(8000864), PeTipMsg.EMsgLevel.Warning); // return false; //} PlayerNetwork.mainPlayer.RequestRedo(opType, indexes, oldvoxels, voxels, mode, ds.DataType, ds.Scale); DigTerrainManager.BlockClearGrass(ds, indexes); return(true); } else { string debug_log = ""; foreach (KeyValuePair <int, int> kvp in items) { if (pkg.Destory(kvp.Key, Mathf.CeilToInt(kvp.Value / divisor))) { debug_log += "\r\n Rmove Item from player package ID[" + kvp.Key.ToString() + "]" + " count - " + kvp.Value.ToString(); } } if (ds == BuildingMan.Blocks) { for (int i = 0; i < indexes.Length; i++) { Vector3 pos = new Vector3(indexes[i].x * ds.Scale, indexes[i].y * ds.Scale, indexes[i].z * ds.Scale) - ds.Offset; PeGrassSystem.DeleteAtPos(pos); PeGrassSystem.DeleteAtPos(new Vector3(pos.x, pos.y - 1, pos.z)); //PeGrassSystem.DeleteAtPos(new Vector3(pos.x, pos.y + 1, pos.z)); } } else if (ds == BuildingMan.Voxels) { for (int i = 0; i < indexes.Length; i++) { Vector3 pos = new Vector3(indexes[i].x, indexes[i].y, indexes[i].z); PeGrassSystem.DeleteAtPos(pos); PeGrassSystem.DeleteAtPos(new Vector3(pos.x, pos.y - 1, pos.z)); //PeGrassSystem.DeleteAtPos(new Vector3(pos.x, pos.y + 1, pos.z)); } } //Debug.LogWarning(debug_log); } } else { new PeTipMsg(PELocalization.GetString(821000001), PeTipMsg.EMsgLevel.Warning); } } else if (mode == EBSBrushMode.Subtract) { Dictionary <int, int> items = new Dictionary <int, int>(); // Calculate the needed items; int adder = 1; foreach (BSVoxel voxel in oldvoxels) { int id = 0; if (ds == BuildingMan.Blocks) { if (voxel.IsExtendable()) { if (!voxel.IsExtendableRoot()) { id = GetBlockItemProtoID((byte)(voxel.materialType >> 2)); adder = 1; } else { adder = 0; } } else { if (!BuildingMan.Blocks.VoxelIsZero(voxel, 0)) { id = GetBlockItemProtoID((byte)(voxel.materialType)); } } } else if (ds == BuildingMan.Voxels) { if (!BuildingMan.Voxels.VoxelIsZero(voxel, 1)) { id = GetVoxelItemProtoID(voxel.materialType); } } if (id <= 0) { continue; } if (items.ContainsKey(id)) { items[id] += adder; } else { items.Add(id, adder); } } float divisor = 1.0f; if (ds == BuildingMan.Blocks) { divisor = (float)(1 << BSBlock45Data.s_ScaleInverted); } // Has player enough package ? Pathea.PlayerPackageCmpt pkg = Pathea.PeCreature.Instance.mainPlayer.GetCmpt <Pathea.PlayerPackageCmpt>(); MaterialItem[] array = new MaterialItem[items.Count]; int i = 0; foreach (KeyValuePair <int, int> kvp in items) { array[i] = new MaterialItem() { protoId = kvp.Key, count = Mathf.FloorToInt(kvp.Value / divisor) }; i++; } result = pkg.package.CanAdd(array); // Really add if (result) { if (GameConfig.IsMultiMode) { if (null == PlayerNetwork.mainPlayer) { return(false); } //if (!PlayerNetwork.OnLimitBoundsCheck(brushBound)) //{ // new PeTipMsg(PELocalization.GetString(8000864), PeTipMsg.EMsgLevel.Warning); // return false; //} PlayerNetwork.mainPlayer.RequestRedo(opType, indexes, oldvoxels, voxels, mode, ds.DataType, ds.Scale); return(true); } else { string debug_log = ""; foreach (MaterialItem mi in array) { if (mi.count != 0) { pkg.Add(mi.protoId, mi.count); } debug_log += "Add Item from player package ID[" + mi.protoId.ToString() + "]" + " count - " + mi.count.ToString() + "\r\n"; } Debug.LogWarning(debug_log); } } } if (result) { if (onVoxelMotify != null) { onVoxelMotify(indexes, voxels, oldvoxels, mode, ds); } } return(result); }
protected override void Load() { SceneMan.MaxLod = (int)SystemSettingData.Instance.RandomTerrainLevel; PeGrassSystem.Refresh(SystemSettingData.Instance.GrassDensity, (int)SystemSettingData.Instance.GrassLod); base.Load(); }
protected void ClearSubterrain() { if (null == itemBounds) { return; } if (PeGameMgr.IsMulti) { List <Vector3> grassPos = new List <Vector3>(); Bounds selfBounds = itemBounds.worldBounds; Vector3 minPos = selfBounds.min - subTerrainClearRadius * Vector3.one; Vector3 maxPos = selfBounds.max + subTerrainClearRadius * Vector3.one; for (float _x = minPos.x; _x <= maxPos.x; ++_x) { for (float _y = minPos.y; _y <= maxPos.y; ++_y) { for (float _z = minPos.z; _z <= maxPos.z; ++_z) { Vector3 pos = new Vector3(Mathf.RoundToInt(_x), Mathf.RoundToInt(_y), Mathf.RoundToInt(_z)); Vector3 outPos; if (PeGrassSystem.DeleteAtPos(pos, out outPos)) { grassPos.Add(outPos); } } } } if (grassPos.Count == 0) { return; } byte[] grassData = PETools.Serialize.Export((w) => { w.Write(grassPos.Count); for (int i = 0; i < grassPos.Count; i++) { BufferHelper.Serialize(w, grassPos[i]); } }); if (null != PlayerNetwork.mainPlayer) { PlayerNetwork.mainPlayer.RPCServer(EPacketType.PT_InGame_ClearGrass, grassData); } } else { Bounds selfBounds = itemBounds.worldBounds; Vector3 minPos = selfBounds.min - subTerrainClearRadius * Vector3.one; Vector3 maxPos = selfBounds.max + subTerrainClearRadius * Vector3.one; for (float _x = minPos.x; _x <= maxPos.x; ++_x) { for (float _y = minPos.y; _y <= maxPos.y; ++_y) { for (float _z = minPos.z; _z <= maxPos.z; ++_z) { PeGrassSystem.DeleteAtPos(new Vector3(Mathf.RoundToInt(_x), Mathf.RoundToInt(_y), Mathf.RoundToInt(_z))); } } } } }
public void ApplyVideo() { XmlDocument xmlDoc = new XmlDocument(); try{ using (FileStream fs = new FileStream(mFilepath, FileMode.Open, FileAccess.Read, FileShare.Read)) { xmlDoc.Load(fs); } }catch (Exception e) { GameLog.HandleIOException(e, GameLog.EIOFileType.Settings); xmlDoc = new XmlDocument(); } XmlElement findNode = (XmlElement)xmlDoc.DocumentElement.SelectSingleNode("QualityLevel"); if (null == findNode) { findNode = xmlDoc.CreateElement("QualityLevel"); xmlDoc.DocumentElement.AppendChild(findNode); } findNode.SetAttribute("Index", mQualityLevel.ToString()); findNode = (XmlElement)xmlDoc.DocumentElement.SelectSingleNode("GLSetting"); if (null == findNode) { findNode = xmlDoc.CreateElement("GLSetting"); xmlDoc.DocumentElement.AppendChild(findNode); } findNode.SetAttribute("value", GLSetting); findNode = (XmlElement)xmlDoc.DocumentElement.SelectSingleNode("LightCount"); if (null == findNode) { findNode = xmlDoc.CreateElement("LightCount"); xmlDoc.DocumentElement.AppendChild(findNode); } findNode.SetAttribute("Index", mLightCount.ToString()); findNode = (XmlElement)xmlDoc.DocumentElement.SelectSingleNode("AnisotropicFiltering"); if (null == findNode) { findNode = xmlDoc.CreateElement("AnisotropicFiltering"); xmlDoc.DocumentElement.AppendChild(findNode); } findNode.SetAttribute("Index", mAnisotropicFiltering.ToString()); findNode = (XmlElement)xmlDoc.DocumentElement.SelectSingleNode("AntiAliasing"); if (null == findNode) { findNode = xmlDoc.CreateElement("AntiAliasing"); xmlDoc.DocumentElement.AppendChild(findNode); } findNode.SetAttribute("Index", mAntiAliasing.ToString()); findNode = (XmlElement)xmlDoc.DocumentElement.SelectSingleNode("ShadowProjection"); if (null == findNode) { findNode = xmlDoc.CreateElement("ShadowProjection"); xmlDoc.DocumentElement.AppendChild(findNode); } findNode.SetAttribute("Index", mShadowProjection.ToString()); findNode = (XmlElement)xmlDoc.DocumentElement.SelectSingleNode("ShadowDistance"); if (null == findNode) { findNode = xmlDoc.CreateElement("ShadowDistance"); xmlDoc.DocumentElement.AppendChild(findNode); } findNode.SetAttribute("Index", mShadowDistance.ToString()); findNode = (XmlElement)xmlDoc.DocumentElement.SelectSingleNode("ShadowCascades"); if (null == findNode) { findNode = xmlDoc.CreateElement("ShadowCascades"); xmlDoc.DocumentElement.AppendChild(findNode); } findNode.SetAttribute("Index", mShadowCascades.ToString()); findNode = (XmlElement)xmlDoc.DocumentElement.SelectSingleNode("mWaterReflection"); if (null == findNode) { findNode = xmlDoc.CreateElement("mWaterReflection"); xmlDoc.DocumentElement.AppendChild(findNode); } findNode.SetAttribute("Index", mWaterReflection.ToString()); findNode = (XmlElement)xmlDoc.DocumentElement.SelectSingleNode("WaterRefraction"); if (null == findNode) { findNode = xmlDoc.CreateElement("WaterRefraction"); xmlDoc.DocumentElement.AppendChild(findNode); } findNode.SetAttribute("Index", WaterRefraction.ToString()); findNode = (XmlElement)xmlDoc.DocumentElement.SelectSingleNode("WaterDepth"); if (null == findNode) { findNode = xmlDoc.CreateElement("WaterDepth"); xmlDoc.DocumentElement.AppendChild(findNode); } findNode.SetAttribute("Index", WaterDepth.ToString()); findNode = (XmlElement)xmlDoc.DocumentElement.SelectSingleNode("GrassDensity"); if (null == findNode) { findNode = xmlDoc.CreateElement("GrassDensity"); xmlDoc.DocumentElement.AppendChild(findNode); } findNode.SetAttribute("Index", GrassDensity.ToString()); findNode = (XmlElement)xmlDoc.DocumentElement.SelectSingleNode("GrassLod"); if (null == findNode) { findNode = xmlDoc.CreateElement("GrassLod"); xmlDoc.DocumentElement.AppendChild(findNode); } findNode.SetAttribute("Index", ((int)mGrassLod).ToString()); findNode = (XmlElement)xmlDoc.DocumentElement.SelectSingleNode("Terrain"); if (null == findNode) { findNode = xmlDoc.CreateElement("Terrain"); xmlDoc.DocumentElement.AppendChild(findNode); } findNode.SetAttribute("Index", TerrainLevel.ToString()); findNode = (XmlElement)xmlDoc.DocumentElement.SelectSingleNode("RandomTerrain"); if (null == findNode) { findNode = xmlDoc.CreateElement("RandomTerrain"); xmlDoc.DocumentElement.AppendChild(findNode); } findNode.SetAttribute("Index", RandomTerrainLevel.ToString()); findNode = (XmlElement)xmlDoc.DocumentElement.SelectSingleNode("DepthBlur"); if (null == findNode) { findNode = xmlDoc.CreateElement("DepthBlur"); xmlDoc.DocumentElement.AppendChild(findNode); } findNode.SetAttribute("value", mDepthBlur.ToString()); findNode = (XmlElement)xmlDoc.DocumentElement.SelectSingleNode("SSAO"); if (null == findNode) { findNode = xmlDoc.CreateElement("SSAO"); xmlDoc.DocumentElement.AppendChild(findNode); } findNode.SetAttribute("value", mSSAO.ToString()); findNode = (XmlElement)xmlDoc.DocumentElement.SelectSingleNode("SyncCount"); if (null == findNode) { findNode = xmlDoc.CreateElement("SyncCount"); xmlDoc.DocumentElement.AppendChild(findNode); } findNode.SetAttribute("value", SyncCount.ToString()); ResetVSync(); findNode = (XmlElement)xmlDoc.DocumentElement.SelectSingleNode("Tree"); if (null == findNode) { findNode = xmlDoc.CreateElement("Tree"); xmlDoc.DocumentElement.AppendChild(findNode); } findNode.SetAttribute("Index", mTreeLevel.ToString()); // GrassMgr.RefreshSettings(GrassDensity, (int)GrassLod); findNode = (XmlElement)xmlDoc.DocumentElement.SelectSingleNode("HDREffect"); if (null == findNode) { findNode = xmlDoc.CreateElement("HDREffect"); xmlDoc.DocumentElement.AppendChild(findNode); } findNode.SetAttribute("Index", HDREffect.ToString()); findNode = (XmlElement)xmlDoc.DocumentElement.SelectSingleNode("FastLightingMode"); if (null == findNode) { findNode = xmlDoc.CreateElement("FastLightingMode"); xmlDoc.DocumentElement.AppendChild(findNode); } //mFastLightingMode = true; findNode.SetAttribute("Index", mFastLightingMode.ToString()); switch (mQualityLevel) { case 0: QualitySettings.SetQualityLevel(0); #if Win32Ver TerrainLevel = 0; #else TerrainLevel = 1; //increase from 128M to 256M for bug 502857 #endif RandomTerrainLevel = 0; mTreeLevel = 1; HDREffect = false; break; case 1: QualitySettings.SetQualityLevel(1); TerrainLevel = 1; //increase from 128M to 256M for bug 502857 RandomTerrainLevel = 0; mTreeLevel = 1; HDREffect = false; break; case 2: QualitySettings.SetQualityLevel(2); TerrainLevel = 1; RandomTerrainLevel = 1; mTreeLevel = 1; HDREffect = false; break; case 3: QualitySettings.SetQualityLevel(3); TerrainLevel = 2; RandomTerrainLevel = 1; mTreeLevel = 3; HDREffect = true; break; case 4: QualitySettings.SetQualityLevel(4); TerrainLevel = 3; RandomTerrainLevel = 2; mTreeLevel = 4; HDREffect = true; break; case 5: QualitySettings.SetQualityLevel(5); TerrainLevel = 3; RandomTerrainLevel = 2; mTreeLevel = 5; HDREffect = true; break; case 6: QualitySettings.SetQualityLevel(3); // for Ubuntu with AMD card, larger than 3 will cause game select GL_FBCONFIG 47/55 which can not render defered-render cam QualitySettings.pixelLightCount = mLightCount; switch (mAnisotropicFiltering) { case 0: QualitySettings.anisotropicFiltering = AnisotropicFiltering.Disable; break; case 1: QualitySettings.anisotropicFiltering = AnisotropicFiltering.Enable; break; case 2: QualitySettings.anisotropicFiltering = AnisotropicFiltering.ForceEnable; break; } QualitySettings.antiAliasing = (mAntiAliasing > 0)? 4 : 0; QualitySettings.shadowProjection = (mShadowProjection == 1)? ShadowProjection.StableFit :ShadowProjection.CloseFit; switch (mShadowDistance) { case 0: QualitySettings.shadowDistance = 1; break; case 1: QualitySettings.shadowDistance = 50; break; case 2: QualitySettings.shadowDistance = 100; break; case 3: QualitySettings.shadowDistance = 200; break; case 4: QualitySettings.shadowDistance = 400; break; } switch (mShadowCascades) { case 0: QualitySettings.shadowCascades = 0; break; case 1: QualitySettings.shadowCascades = 2; break; case 2: QualitySettings.shadowCascades = 4; break; } break; } PeGrassSystem.Refresh(GrassDensity, (int)GrassLod); PECameraMan.ApplySysSetting(); try{ using (FileStream fs = new FileStream(mFilepath, FileMode.Create, FileAccess.Write, FileShare.None)) { xmlDoc.Save(fs); } }catch (Exception e) { GameLog.HandleIOException(e, GameLog.EIOFileType.Settings); } }