[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

斜面へ植林の修正コード


> ・PlantedMtVoxelを使わず、既存のMountainVoxelに木を持たせるようにする
> ・描画速度の問題に対応するため、オプションで樹木描画をON/OFF出来るようにする

ということで、結構修正個所が多岐にわたりました。
以下にdiffを示します。よろしくお願いします。

※ForestVoxelはMountainVoxelに統合したため、ForestVoxel.csは不要になります

Index: ForestBuilder.cs
===================================================================
RCS file: /cvsroot/freetrain/FreeTrain/plugins/org.kohsuke.freetrain.land.forest/src/ForestBuilder.cs,v
retrieving revision 1.5
diff -u -r1.5 ForestBuilder.cs
--- ForestBuilder.cs	26 Jun 2003 15:02:34 -0000	1.5
+++ ForestBuilder.cs	26 Jul 2003 02:41:05 -0000
@@ -9,6 +9,7 @@
 using freetrain.controllers;
 using freetrain.framework.graphics;
 using freetrain.framework.plugin;
+using freetrain.world.terrain;
 using freetrain.views;
 
 namespace freetrain.world.land.forest
@@ -66,6 +67,18 @@
 
 		private static readonly Random rnd = new Random();
 
+		private static new bool canBeBuilt(Location loc) 
+		{
+			if( World.world.getGroundLevel(loc) != loc.z ) 
+			{
+				return false;
+			}
+			else if(!World.world.isReusable(loc))
+			{
+				return (World.world[loc] is MountainVoxel );
+			}
+			else return true;
+		}
 
 		/// <summary>
 		/// Gets the land that should be used to fill (x,y) within [x1,y1]-[x2,y2] (inclusive).
@@ -75,11 +88,19 @@
 				for( int y=y1; y<=y2; y++ ) {
 					Location loc = new Location(x,y,z);
 
-					if( ForestVoxel.canBeBuilt(loc) ) {
+					if( canBeBuilt(loc) ) 
+					{
 						byte[] patterns = createRandomTrees();
-						if( patterns.Length!=0 )
-							new ForestVoxel( loc, this, patterns );
-					}
+						if( patterns.Length!=0 ) 
+						{
+							MountainVoxel v;
+							if( World.world[loc] is MountainVoxel ) 
+								v = (MountainVoxel)World.world[loc];
+							else
+								v = new MountainVoxel( loc, 0,0,0,0 );
+							v.setTrees(ground, sprites, patterns,price);
+						}
+					} 
 				}
 			}
 		}

Index: Bulldozer.cs
===================================================================
RCS file: /cvsroot/freetrain/FreeTrain/core/contributions/land/Bulldozer.cs,v
retrieving revision 1.3
diff -u -r1.3 Bulldozer.cs
--- Bulldozer.cs	27 Mar 2003 01:56:12 -0000	1.3
+++ Bulldozer.cs	26 Jul 2003 02:46:56 -0000
@@ -9,6 +9,7 @@
 using freetrain.framework;
 using freetrain.views;
 using freetrain.world;
+using freetrain.world.terrain;
 using freetrain.world.land;
 
 namespace freetrain.contributions.land
@@ -34,6 +35,11 @@
 				for( int y=loc1.y; y<=loc2.y; y++ ) {
 					if( World.world.isReusable(x,y,z) && World.world[x,y,z]!=null )
 						World.world.remove(x,y,z);
+					else if(World.world[x,y,z] is MountainVoxel)
+					{
+						MountainVoxel v = (MountainVoxel)World.world[x,y,z];
+						v.removeTrees();
+					}
 				}
 			}
 		}


Index: MountainVoxel.cs
===================================================================
RCS file: /cvsroot/freetrain/FreeTrain/core/world/terrain/MountainVoxel.cs,v
retrieving revision 1.23
diff -u -r1.23 MountainVoxel.cs
--- MountainVoxel.cs	9 May 2003 01:34:06 -0000	1.23
+++ MountainVoxel.cs	26 Jul 2003 02:35:02 -0000
@@ -14,7 +14,13 @@
 	[Serializable]
 	public class MountainVoxel : AbstractVoxelImpl, Entity
 	{
-		public MountainVoxel( Location loc, byte hNE, byte hSE, byte hSW, byte hNW ) : base(loc) {
+		private Sprite[] patterns;
+		private Sprite ground;
+		private byte[] indices;
+		private int treePrice;
+
+		public MountainVoxel( Location loc, byte hNE, byte hSE, byte hSW, byte hNW ) : base(loc) 
+		{
 
 			Debug.Assert( 0<=hNE && hNE<=4 );
 			Debug.Assert( 0<=hSE && hSE<=4 );
@@ -137,7 +143,7 @@
 
 		public event EventHandler onEntityRemoved;
 
-		public int entityValue { get { return 0; } }
+		public int entityValue { get { return 0 + treePrice; } }
 
 		#endregion
 
@@ -154,22 +160,38 @@
 			}
 		}
 
-		public override void draw( DrawContext display, Point pt, int heightCutDiff ) {
+		public override void draw( DrawContext display, Point pt, int heightCutDiff ) 
+		{
+			drawGround(display,pt,heightCutDiff);
+			if( patterns != null && !Core.options.hideTrees)
+				drawTrees(display,pt,heightCutDiff);
+		}
+
+		private void drawGround(DrawContext display, Point pt, int heightCutDiff ) 
+		{
 			Point basePt = pt;
 			World world = World.world;
 
-			if( heightCutDiff==0 ) {
+			if( heightCutDiff==0 ) 
+			{
 				ResourceUtil.emptyChip.drawShape( display.surface, pt, 
 					isUnderWater ? waterColors[3] : currentMountainColors[3] );
 				return;
 			}
 
+			if( isFlattened ) 
+			{
+				if( ground != null )
+					ground.draw( display.surface, pt );
+				return;
+			}
+
 			pt.Y -= getHeight(0)*4;	// apply offset
 
 			// compute target colors
 			Color[] dstColors = new Color[]{
-				selectColor(),
-				mapColor(isUnderWater?Color.Navy:currentMountainColors[0]) };
+						selectColor(),
+						mapColor(isUnderWater?Color.Navy:currentMountainColors[0]) };
 
 			int tdiff = (getHeight(0)-getHeight(2)+4);
 			int umax = Math.Min(tdiff+2,6);
@@ -180,10 +202,12 @@
 			int ldiff = (getHeight(0)-getHeight(3)+2);
 			bool vflip;
 
-			if( ldiff < tdiff-ldiff ) {
+			if( ldiff < tdiff-ldiff ) 
+			{
 				vflip = true;
 				ldiff = tdiff-ldiff;
-			} else
+			} 
+			else
 				vflip = false;
 			int lidx = (umax-ldiff);
 
@@ -195,18 +219,20 @@
 				// left cliff
 				Location neighbor = location+Direction.WEST;
 				if(!(world[neighbor] is MountainVoxel)
-				&& getHeight(2)+getHeight(3)>0
-				&& world.getGroundLevel(neighbor) <= world.getGroundLevel(location) )
+					&& getHeight(2)+getHeight(3)>0
+					&& world.getGroundLevel(neighbor) <= world.getGroundLevel(location) )
 					cliff[0,getHeight(3),getHeight(2)].draw( display.surface, basePt );
 			}
 
 
 			// right half
 			int rdiff = (getHeight(0)-getHeight(1)+2);
-			if( rdiff < tdiff-rdiff ) {
+			if( rdiff < tdiff-rdiff ) 
+			{
 				vflip = true;
 				rdiff = tdiff-rdiff;
-			} else 
+			} 
+			else 
 				vflip = false;
 			int ridx = (umax-rdiff);
 
@@ -220,13 +246,29 @@
 				// right cliff
 				Location neighbor = location+Direction.SOUTH;
 				if(!(world[neighbor] is MountainVoxel)
-				&& getHeight(2)+getHeight(1)>0
-				&& world.getGroundLevel(neighbor) <= world.getGroundLevel(location) )
+					&& getHeight(2)+getHeight(1)>0
+					&& world.getGroundLevel(neighbor) <= world.getGroundLevel(location) )
 					cliff[1,getHeight(2),getHeight(1)].draw( display.surface, basePt );
 			}
+		}
 
+		private void drawTrees(DrawContext display, Point pt, int heightCutDiff)
+		{
+			int h = getHeight(Direction.NORTHEAST)-getHeight(Direction.SOUTHWEST);
+			//int w = getHeight(Direction.NORTHWEST)-getHeight(Direction.SOUTHEAST);
+			if( h > 0)
+			{
+				for( int i=0; i<indices.Length; i+=3 )
+					patterns[ indices[i+2] ].draw( display.surface,
+						new Point( pt.X+indices[i+0], pt.Y+indices[i+1]*(h+4)/4-8 ) );
+			}
+			else
+			{
+				for( int i=0; i<indices.Length; i+=3 )
+					patterns[ indices[i+2] ].draw( display.surface,
+						new Point( pt.X+indices[i+0], pt.Y+indices[i+1]*(h+4)/4+2 ) );
+			}
 		}
-		
 		private static readonly Color[] srcColors = new Color[]{ Color.White, Color.Black };
 
 
@@ -329,7 +371,32 @@
 		public static MountainVoxel get( Location loc ) {
 			return World.world[loc] as MountainVoxel;
 		}
+		
+		public void setTrees(Sprite ground, Sprite[] trees, byte[] indices, int price) 
+		{
+			this.ground = ground;
+			patterns = trees;
+			this.indices = indices;
+			treePrice = price;
+		}
 
+		public void removeTrees()
+		{
+			ground = null;
+			patterns = null;
+			indices = null;
+			treePrice = 0;
+		}
+		
+		public bool hasTrees 
+		{
+			get {return patterns!=null; }
+		}
+
+		public void flatten() 
+		{
+			heightData=0;
+		}
 
 		#region cliff
 		private static Sprite[,,] cliff = new Sprite[2/*0:S,1:W*/,5/*lHeight*/,5/*rHeight*/];


-------------以下は表示設定オプション関連----------------
Index: GlobalOptions.cs
===================================================================
RCS file: /cvsroot/freetrain/FreeTrain/core/framework/GlobalOptions.cs,v
retrieving revision 1.6
diff -u -r1.6 GlobalOptions.cs
--- GlobalOptions.cs	30 Dec 2002 17:10:40 -0000	1.6
+++ GlobalOptions.cs	26 Jul 2003 02:30:29 -0000
@@ -57,7 +57,28 @@
 			}
 		}
 		
-		public new GlobalOptions load() {
+		/// <summary>
+		/// If false, draw trees.
+		/// If true, speed up drawing by ignore drawing trees.
+		/// </summary>
+		private bool _hideTrees = false;
+
+		public bool hideTrees 
+		{
+			get 
+			{
+				return _hideTrees;
+			}
+			set 
+			{
+				if( _hideTrees!=value && world.World.world!=null )
+					world.World.world.onAllVoxelUpdated();	// redraw
+				_hideTrees = value;
+			}
+		}
+
+		public new GlobalOptions load() 
+		{
 			return (GlobalOptions)base.load();
 		}
 
Index: ConfigDialog.cs
===================================================================
RCS file: /cvsroot/freetrain/FreeTrain/core/framework/ConfigDialog.cs,v
retrieving revision 1.4
diff -u -r1.4 ConfigDialog.cs
--- ConfigDialog.cs	25 Dec 2002 02:02:42 -0000	1.4
+++ ConfigDialog.cs	26 Jul 2003 02:30:30 -0000
@@ -3,6 +3,7 @@
 using System.Collections;
 using System.ComponentModel;
 using System.Windows.Forms;
+using freetrain.world;
 
 namespace freetrain.framework
 {
@@ -20,6 +21,7 @@
 		private System.Windows.Forms.TrackBar msgStatusLength;
 		private System.Windows.Forms.CheckBox drawStationNames;
 		private System.Windows.Forms.CheckBox showBoundingBox;
+		private System.Windows.Forms.CheckBox hideTrees;
 
 		private readonly GlobalOptions opts;
 		
@@ -34,6 +36,7 @@
 			msgStatusLength.Value = opts.messageDisplayTime;
 			drawStationNames.Checked = opts.drawStationNames;
 			showBoundingBox.Checked = opts.drawBoundingBox;
+			hideTrees.Checked = opts.hideTrees;
 		}
 
 		protected override void Dispose( bool disposing ) {
@@ -59,6 +62,7 @@
 			this.radioMsgBox = new System.Windows.Forms.RadioButton();
 			this.drawStationNames = new System.Windows.Forms.CheckBox();
 			this.showBoundingBox = new System.Windows.Forms.CheckBox();
+			this.hideTrees = new System.Windows.Forms.CheckBox();
 			this.groupBox1.SuspendLayout();
 			((System.ComponentModel.ISupportInitialize)(this.msgStatusLength)).BeginInit();
 			this.SuspendLayout();
@@ -110,7 +114,7 @@
 			this.msgStatusLength.Location = new System.Drawing.Point(160, 32);
 			this.msgStatusLength.Minimum = 1;
 			this.msgStatusLength.Name = "msgStatusLength";
-			this.msgStatusLength.Size = new System.Drawing.Size(224, 45);
+			this.msgStatusLength.Size = new System.Drawing.Size(224, 42);
 			this.msgStatusLength.TabIndex = 2;
 			this.msgStatusLength.Value = 1;
 			// 
@@ -152,6 +156,15 @@
 			this.showBoundingBox.TabIndex = 4;
 			this.showBoundingBox.Text = "描画範囲を表示(デバッグ)";
 			// 
+			// hideTrees
+			// 
+			this.hideTrees.FlatStyle = System.Windows.Forms.FlatStyle.System;
+			this.hideTrees.Location = new System.Drawing.Point(24, 152);
+			this.hideTrees.Name = "hideTrees";
+			this.hideTrees.Size = new System.Drawing.Size(168, 16);
+			this.hideTrees.TabIndex = 4;
+			this.hideTrees.Text = "樹木の描画を省略";
+			// 
 			// ConfigDialog
 			// 
 			this.AcceptButton = this.buttonOK;
@@ -163,7 +176,8 @@
 																		  this.drawStationNames,
 																		  this.groupBox1,
 																		  this.buttonCancel,
-																		  this.buttonOK});
+																		  this.buttonOK,
+																		  this.hideTrees});
 			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
 			this.MaximizeBox = false;
 			this.MinimizeBox = false;
@@ -187,9 +201,11 @@
 			opts.messageDisplayTime = msgStatusLength.Value;
 			opts.drawStationNames = drawStationNames.Checked;
 			opts.drawBoundingBox = showBoundingBox.Checked;
+			opts.hideTrees = hideTrees.Checked;
 			opts.save();
 			Close();
 		}
+
 
 	}
 }

_______________________________________________
FreeTrain-general mailing list
FreeTrain-general@lists.sourceforge.jp
http://lists.sourceforge.jp/mailman/listinfo/freetrain-general

題名

名前

メッセージ