Пример #1
0
		public override bool React( ref VoxelRef self, double tick )
		{
			NearVoxelRef near_below; VoxelRef.GetNearBelowVoxelRef( out near_below, ref self );
			//Log.log( "Reacting water... {0} {1} {2} {3} {4} {5} {6}"
			//	, self.x, self.y, self.z 
			//	, self.Offset, near_below.Offset
			//	, self.Type.properties.Type
			//	, near_below.Type != null?near_below.Type.properties.Type.ToString() :"NoBelow"
			//	);
			if( near_below.Sector != null 
				&& near_below.Type.properties.Is_CanBeReplacedBy_Water )
			{
				//Log.log( "Swap below..." );
				World.Swap( ref self, ref near_below, VoxelSector.ModifiedFieldFlags.UNIMPORTANT );
				near_below.Sector.ModifTracker.Set( near_below.Offset );

				return true;
			}

			// Eau qui coule. Flowing water.
			{
				NearVoxelRef near_left, near_right, near_ahead, near_behind;
				VoxelRef.GetNearLeftVoxelRef( out near_left  , ref self );
				VoxelRef.GetNearRightVoxelRef( out near_right, ref self );
				VoxelRef.GetNearAheadVoxelRef( out near_ahead, ref self );
				VoxelRef.GetNearBehindVoxelRef( out near_behind, ref self );

				int vCount = 0, WaveCount = 0;
				int j;

				bool DirEn0, DirEn1, DirEn2, DirEn3;
				bool WaveDirEn0, WaveDirEn1, WaveDirEn2, WaveDirEn3;

				//self.GetVoxelRefs( out St, out Offsets, true );
				//self.GetVoxelRefs( out nearby, true );


				// Test if we can fall downward
				//cx = x+1 ; cy = y ; cz = z+1; SecondaryOffset[i] = If_x[cx]+If_y[cy]+If_z[cz];St[i] = SectorTable[ Of_x[cx] + Of_y[cy] + Of_z[cz] ]; Vp[i] = &St[i]->Data[ SecondaryOffset[i] ].Data;

				if( near_left.Sector != null &&
					near_left.Type.properties.Is_CanBeReplacedBy_Water )
				{
					VoxelRef.GetNearBelowVoxelRef( out near_below, ref near_left );
					if( near_below.Type != null && near_below.Type.properties.Is_CanBeReplacedBy_Water )
					{ DirEn0 = true; vCount++; }
					else DirEn0 = false;
					WaveCount++; WaveDirEn0 = true;
				}
				else { DirEn0 = false; WaveDirEn0 = false; }

				if( near_right.Sector != null &&
					near_right.Type.properties.Is_CanBeReplacedBy_Water )
				{
					VoxelRef.GetNearBelowVoxelRef( out near_below, ref near_right );
					if( near_below.Type != null && near_below.Type.properties.Is_CanBeReplacedBy_Water )
					{ DirEn1 = true; vCount++; }
					else DirEn1 = false;
					WaveCount++; WaveDirEn1 = true;
				}
				else { DirEn1 = false; WaveDirEn1 = false; }

				if( near_ahead.Sector != null &&
					near_ahead.Type.properties.Is_CanBeReplacedBy_Water )
				{
					VoxelRef.GetNearBelowVoxelRef( out near_below, ref near_ahead );
					if( near_below.Type != null && near_below.Type.properties.Is_CanBeReplacedBy_Water )
					{ DirEn2 = true; vCount++; }
					else DirEn2 = false;
					WaveCount++; WaveDirEn2 = true;
				}
				else { DirEn2 = false; WaveDirEn2 = false; }

				if( near_behind.Sector != null &&
					near_behind.Type.properties.Is_CanBeReplacedBy_Water )
				{
					VoxelRef.GetNearBelowVoxelRef( out near_below, ref near_behind );
					if( near_below.Type != null && near_below.Type.properties.Is_CanBeReplacedBy_Water )
					{ DirEn3 = true; vCount++; }
					else DirEn3 = false;
					WaveCount++; WaveDirEn3 = true;
				}
				else { DirEn3 = false; WaveDirEn3 = false; }

				if( vCount > 0 )
				{
					j = ( VoxelReactor.Random.GetEntropy(2, false) % vCount ) + 1;
					//Log.log( "Reacting Entropy {0} {1}", vCount, j );
					if( DirEn0 )
					{
						j--; if( j == 0 )
						{
							//Log.log( "swap left" );
							World.Swap( ref self, ref near_left, VoxelSector.ModifiedFieldFlags.UNIMPORTANT );
							near_left.Sector.ModifTracker.Set( near_left.Offset );
							return true;
						}
					}
					if( DirEn1 )
					{
						j--; if( j == 0 )
						{
							//Log.log( "swap right" );
							World.Swap( ref self, ref near_right, VoxelSector.ModifiedFieldFlags.UNIMPORTANT );
							near_right.Sector.ModifTracker.Set( near_right.Offset );
							return true;
						}
					}
					if( DirEn2 )
					{
						j--; if( j == 0 )
						{
							//Log.log( "swap ahead" );
							World.Swap( ref self, ref near_ahead, VoxelSector.ModifiedFieldFlags.UNIMPORTANT );
							near_ahead.Sector.ModifTracker.Set( near_ahead.Offset );
							return true;
						}
					}
					if( DirEn3 )
					{
						j--; if( j == 0 )
						{
							//Log.log( "swap behind" );
							World.Swap( ref self, ref near_behind, VoxelSector.ModifiedFieldFlags.UNIMPORTANT );
							near_behind.Sector.ModifTracker.Set( near_behind.Offset );
							return true;
						}
					}
				}
				else if( WaveCount > 0 && WaveCount < 4 )
				{
					j = ( VoxelReactor.Random.GetEntropy( 2, false ) % WaveCount ) + 1;
					//Log.log( "Reacting Wave {0} {1}", WaveCount, j );
					if( WaveDirEn0 )
					{
						//Log.log( "swap left 0" );
						j--; if( j == 0 )
						{
							World.Swap( ref self, ref near_left, VoxelSector.ModifiedFieldFlags.UNIMPORTANT );
							near_left.Sector.ModifTracker.Set( near_left.Offset );
							return true;
						}
					}
					if( WaveDirEn1 )
					{
						//Log.log( "swap right 1" );
						j--; if( j == 0 )
						{
							World.Swap( ref self, ref near_right, VoxelSector.ModifiedFieldFlags.UNIMPORTANT );
							near_right.Sector.ModifTracker.Set( near_right.Offset );
							return true;
						}
					}
					if( WaveDirEn2 )
					{
						//Log.log( "swap ahead {0} {1}", World, near_ahead.Sector );
						j--; if( j == 0 )
						{
							//Log.log( "going to swap....." );
							World.Swap( ref self, ref near_ahead, VoxelSector.ModifiedFieldFlags.UNIMPORTANT );
							//Log.log( "... {0}", near_ahead.Sector.ModifTracker );
							near_ahead.Sector.ModifTracker.Set( near_ahead.Offset );
							return true;
						}
					}
					if( WaveDirEn3 )
					{
						//Log.log( "swap behind" );
						j--; if( j == 0 )
						{
							World.Swap( ref self, ref near_behind, VoxelSector.ModifiedFieldFlags.UNIMPORTANT );
							near_behind.Sector.ModifTracker.Set( near_behind.Offset );							
							return true;
						}
					}
				}
			}
			return false;
		}
Пример #2
0
		//internal virtual uint Interface_PushBlock_Push( VoxelLocation DestLocation, ushort VoxelType, uint Count ) { return ( 0 ); }
		//internal virtual uint Interface_PushBlock_PushTest( VoxelLocation DestLocation, ushort VoxelType, uint Count ) { return ( Count ); }
		//internal virtual uint Interface_PushBlock_Pull( VoxelLocation DestLocation, out ushort VoxelType, uint Count ) { VoxelType = 0; return ( 0 ); }
		//internal virtual uint Interface_PushBlock_PullTest( VoxelLocation DestLocation, out ushort VoxelType, uint Count ) { VoxelType = 0; return ( 0 ); }

		// Squirrel interface
		//public virtual bool Interface_GetInfo( VoxelLocation VLoc, uint InfoNum, ZVar Out ) { return ( false ); }
		//public virtual bool Interface_GetInfoDoc( uint InfoNum, uint DocType, ZVar Out ) { return ( false ); }
		//public virtual bool Interface_SetInfo( VoxelLocation VLoc, uint InfoNum, ZVar In ) { return ( false ); }
		//internal virtual void GetBlockInformations( VoxelLocation DestLocation, string Infos ) { return; }

		// When an active voxel should be processed. Note some voxels use "direct" faster way.
		//public virtual void ActiveProcess( ActiveVoxelInterface AvData ) { };

		public virtual bool React( ref VoxelRef self, double tick ) { return false; }
Пример #3
0
 public override bool React( ref VoxelRef self, double tick )
 {    	
 	return false;
 }
Пример #4
0
		public static void GetNearAheadVoxelRef( out NearVoxelRef that, ref VoxelRef self )
		{
			that.Sector = self.Sector;
			that.Offset = self.Offset;
				if( ( that.Offset & ( VoxelSector.ZVOXELBLOCMASK_Z << ( VoxelSector.ZVOXELBLOCSHIFT_X + VoxelSector.ZVOXELBLOCSHIFT_Y ) ) ) != ( VoxelSector.ZVOXELBLOCMASK_Z << ( VoxelSector.ZVOXELBLOCSHIFT_X + VoxelSector.ZVOXELBLOCSHIFT_Y ) ) )
					that.Offset += VoxelSector.ZVOXELBLOCSIZE_Y * VoxelSector.ZVOXELBLOCSIZE_X;
				else
				{
					that.Sector = self.Sector.near_sectors[(int)VoxelSector.RelativeVoxelOrds.AHEAD - 1];
					if( that.Sector != null )
						that.Offset -= ( VoxelSector.ZVOXELBLOCSIZE_X * VoxelSector.ZVOXELBLOCSIZE_Y * ( VoxelSector.ZVOXELBLOCSIZE_Z - 2 ) );
				}
			if( that.Sector != null )
			{
				that.Type = self.VoxelTypeManager.VoxelTable[that.Sector.Data.Data[that.Offset]];
				that.VoxelExtension = that.Sector.Data.OtherInfos[that.Offset];
			}
			else
			{
				that.Type = null;
				that.VoxelExtension = null;
			}
		}
Пример #5
0
		public static void GetNearBelowVoxelRef( out NearVoxelRef that, ref VoxelRef self )
		{
			that.Sector = self.Sector;
			that.Offset = self.Offset;
				if( ( that.Offset & ( VoxelSector.ZVOXELBLOCMASK_Y ) ) != 0 )
					that.Offset--;
				else
				{
					that.Sector = self.Sector.near_sectors[(int)VoxelSector.RelativeVoxelOrds.BELOW - 1];
					if( that.Sector != null )
						that.Offset += ( VoxelSector.ZVOXELBLOCSIZE_Y - 2 );
				}
			if( that.Sector != null )
			{
				that.Type = self.VoxelTypeManager.VoxelTable[that.Sector.Data.Data[that.Offset]];
				that.VoxelExtension = that.Sector.Data.OtherInfos[that.Offset];
			}
			else
			{
				that.Type = null;
				that.VoxelExtension = null;
			}
		}
Пример #6
0
		static int ForEachVoxel( VoxelWorld World, ref VoxelRef v1, ref VoxelRef v2, ForEachCallback f, bool not_zero )
		{
			if( v1.Sector == null || v2.Sector == null )
				return not_zero ? 1 : 0;
			int v1x = v1.x + ( v1.Sector.Pos_x << VoxelSector.ZVOXELBLOCSHIFT_X );
			int v1y = v1.y + ( v1.Sector.Pos_y << VoxelSector.ZVOXELBLOCSHIFT_Y );
			int v1z = v1.z + ( v1.Sector.Pos_z << VoxelSector.ZVOXELBLOCSHIFT_Z );
			int v2x = v2.x + ( v2.Sector.Pos_x << VoxelSector.ZVOXELBLOCSHIFT_X );
			int v2y = v2.y + ( v2.Sector.Pos_y << VoxelSector.ZVOXELBLOCSHIFT_Y );
			int v2z = v2.z + ( v2.Sector.Pos_z << VoxelSector.ZVOXELBLOCSHIFT_Z );
			int del_x = v2x - v1x;
			int del_y = v2y - v1y;
			int del_z = v2z - v1z;
			int abs_x = del_x < 0 ? -del_x : del_x;
			int abs_y = del_y < 0 ? -del_y : del_y;
			int abs_z = del_z < 0 ? -del_z : del_z;
			// cannot use iterate if either end is undefined.
			if( del_x != 0 )
			{
				if( del_y != 0 )
				{
					if( del_z != 0 )
					{
						if( abs_x > abs_y || ( abs_z > abs_y ) )
						{
							if( abs_z > abs_x )
							{
								// z is longest path
								int erry = -abs_z / 2;
								int errx = -abs_z / 2;
								int incy = del_y < 0 ? -1 : 1;
								int incx = del_x < 0 ? -1 : 1;
								int incz = del_z < 0 ? -1 : 1;
								{
									int x = v1x;
									int y = v1y;
									for( int z = v1z + incz; z != v2z; z += incz )
									{
										errx += abs_x;
										if( errx > 0 )
										{
											errx -= abs_z;
											x += incx;
										}
										erry += abs_y;
										if( erry > 0 )
										{
											erry -= abs_z;
											y += incy;
										}
										{
											int val;
											VoxelRef v;
											if( World.GetVoxelRef( out v, x, y, z ) )
											{
												val = f( ref v );
												if( ( !not_zero && val != 0 ) || ( not_zero && val == 0 ) )
													return val;
											}
										}
									}
								}
							}
							else
							{
								// x is longest.
								int erry = -abs_x / 2;
								int errz = -abs_x / 2;
								int incy = del_y < 0 ? -1 : 1;
								int incx = del_x < 0 ? -1 : 1;
								int incz = del_z < 0 ? -1 : 1;
								{
									int y = v1y;
									int z = v1z;
									for( int x = v1x + incx; x != v2x; x += incx )
									{
										errz += abs_z;
										if( errz > 0 )
										{
											errz -= abs_x;
											z += incx;
										}
										erry += abs_y;
										if( erry > 0 )
										{
											erry -= abs_x;
											y += incy;
										}
										{
											int val;
											VoxelRef v;
											if( World.GetVoxelRef( out v, x, y, z ) )
											{
												val = f( ref v );
												if( ( !not_zero && val != 0 ) || ( not_zero && val == 0 ) )
													return val;
											}
										}
									}
								}
							}
						}
						else
						{
							// y is longest.
							int errx = -abs_y / 2;
							int errz = -abs_y / 2;
							int incy = del_y < 0 ? -1 : 1;
							int incx = del_x < 0 ? -1 : 1;
							int incz = del_z < 0 ? -1 : 1;
							{
								int x = v1x;
								int z = v1x;
								for( int y = v1y + incy; y != v2y; y += incy )
								{
									errx += abs_x;
									if( errx > 0 )
									{
										errx -= abs_y;
										x += incx;
									}
									errz += abs_z;
									if( errz > 0 )
									{
										errz -= abs_y;
										z += incz;
									}
									{
										int val;
										VoxelRef v;
										if( World.GetVoxelRef( out v, x, y, z ) )
										{
											val = f( ref v );
											if( ( !not_zero && val != 0 ) || ( not_zero && val == 0 ) )
												return val;
										}
									}
								}
							}
						}
					}
					else
					{
						// z is constant
						if( abs_x > abs_y )
						{
							// x is longest
							int erry = -abs_x / 2;
							int incy = del_y < 0 ? -1 : 1;
							int incx = del_x < 0 ? -1 : 1;
							{
								int y = v1y;
								int z = v1z;
								for( int x = v1x + incx; x != v2x; x += incx )
								{
									erry += abs_y;
									if( erry > 0 )
									{
										erry -= abs_x;
										y += incy;
									}
									{
										int val;
										VoxelRef v;
										if( World.GetVoxelRef( out v, x, y, z ) )
										{
											val = f( ref v );
											if( ( !not_zero && val != 0 ) || ( not_zero && val == 0 ) )
												return val;
										}
									}
								}
							}
						}
						else
						{
							// y is longest.
							int errx = -abs_y / 2;
							int incy = del_y < 0 ? -1 : 1;
							int incx = del_x < 0 ? -1 : 1;
							// z is longest path
							{
								int x = v1x;
								int z = v1x;
								for( int y = v1y + incy; y != v2y; y += incy )
								{
									errx += abs_x;
									if( errx > 0 )
									{
										errx -= abs_y;
										x += incx;
									}
									{
										int val;
										VoxelRef v;
										if( World.GetVoxelRef( out v, x, y, z ) )
										{
											val = f( ref v );
											if( ( !not_zero && val != 0 ) || ( not_zero && val == 0 ) )
												return val;
										}
									}
								}
							}
						}
					}
				}
				else
				{
					if( del_z != 0 )
					{
						if( abs_x > abs_z )
						{
							// x is longest.
							int errz = -abs_x / 2;
							int incx = del_x < 0 ? -1 : 1;
							int incz = del_z < 0 ? -1 : 1;
							{
								int y = v1y;
								int z = v1z;
								for( int x = v1x + incx; x != v2x; x += incx )
								{
									errz += abs_z;
									if( errz > 0 )
									{
										errz -= abs_x;
										z += incx;
									}
									{
										int val;
										VoxelRef v;
										if( World.GetVoxelRef( out v, x, y, z ) )
										{
											val = f( ref v );
											if( ( !not_zero && val != 0 ) || ( not_zero && val == 0 ) )
												return val;
										}
									}
								}
							}
						}
						else
						{
							// z is longest path
							int errx = -abs_z / 2;
							int incx = del_x < 0 ? -1 : 1;
							int incz = del_z < 0 ? -1 : 1;
							{
								int x = v1x;
								int y = v1y;
								for( int z = v1z + incz; z != v2z; z += incz )
								{
									errx += abs_x;
									if( errx > 0 )
									{
										errx -= abs_z;
										x += incx;
									}
									{
										int val;
										VoxelRef v;
										if( World.GetVoxelRef( out v, x, y, z ) )
										{
											val = f( ref v );
											if( ( !not_zero && val != 0 ) || ( not_zero && val == 0 ) )
												return val;
										}
									}
								}
							}
						}
					}
					else
					{
						// x is only changing.
						int incx = del_x < 0 ? -1 : 1;
						for( int x = v1x + incx; x != v2x; x += incx )
						{
							int val;
							VoxelRef v;
							if( World.GetVoxelRef( out v, x, v1y, v1z ) )
							{
								val = f( ref v );
								if( ( !not_zero && val != 0 ) || ( not_zero && val == 0 ) )
									return val;
							}
						}
					}
				}
			}
			else
			{
				if( del_y != 0 )
				{
					if( del_z != 0 )
					{
						if( abs_y > abs_z )
						{
							// y is longest.
							int errz = -abs_y / 2;
							int incy = del_y < 0 ? -1 : 1;
							int incz = del_z < 0 ? -1 : 1;
							{
								int x = v1x;
								int z = v1x;
								for( int y = v1y + incy; y != v2y; y += incy )
								{
									errz += abs_z;
									if( errz > 0 )
									{
										errz -= abs_y;
										z += incz;
									}
									{
										int val;
										VoxelRef v;
										if( World.GetVoxelRef( out v, x, y, z ) )
										{
											val = f( ref v );
											if( ( !not_zero && val != 0 ) || ( not_zero && val == 0 ) )
												return val;
										}
									}
								}
							}
						}
						else
						{
							// z is longest path
							int erry = -abs_z / 2;
							int incy = del_y < 0 ? -1 : 1;
							int incz = del_z < 0 ? -1 : 1;
							{
								int x = v1x;
								int y = v1y;
								for( int z = v1z + incz; z != v2z; z += incz )
								{
									erry += abs_y;
									if( erry > 0 )
									{
										erry -= abs_z;
										y += incy;
									}
									{
										int val;
										VoxelRef v;
										if( World.GetVoxelRef( out v, x, y, z ) )
										{
											val = f( ref v );
											if( ( !not_zero && val != 0 ) || ( not_zero && val == 0 ) )
												return val;
										}
									}
								}
							}
						}
					}
					else
					{
						// no del_x, no del_z
						// y is only changing.
						int incy = del_y < 0 ? -1 : 1;
						for( int y = v1y + incy; y != v2y; y += incy )
						{
							int val;
							VoxelRef v;
							if( World.GetVoxelRef( out v, v1x, y, v1z ) )
							{
								val = f( ref v );
								if( ( !not_zero && val != 0 ) || ( not_zero && val == 0 ) )
									return val;
							}
						}
					}
				}
				else
				{
					// no del_x, no del_y...
					if( del_z != 0 )
					{
						if( del_z > 0 )
							for( int z = v1z + 1; z < v2z; z++ )
							{
								int val;
								VoxelRef v;
								if( World.GetVoxelRef( out v, v1x, v1y, z ) )
								{
									val = f( ref v );
									if( ( !not_zero && val != 0 ) || ( not_zero && val == 0 ) )
										return val;
								}
							}
						else
							for( int z = v2z + 1; z < v1z; z++ )
							{
								int val;
								VoxelRef v;
								if( World.GetVoxelRef( out v, v1x, v1y, z ) )
								{
									val = f( ref v );
									if( ( !not_zero && val != 0 ) || ( not_zero && val == 0 ) )
										return val;
								}
							}

					}
					else
					{
						// no delta diff, nothing to do.
					}
				}
			}
			return not_zero ? 1 : 0;
		}
Пример #7
0
		public static void GetNearRightVoxelRef( out NearVoxelRef that, ref VoxelRef self )
		{
			that.Sector = self.Sector;
			that.Offset = self.Offset;
				if( ( that.Offset & ( VoxelSector.ZVOXELBLOCMASK_X << VoxelSector.ZVOXELBLOCSHIFT_Y ) ) != VoxelSector.ZVOXELBLOCMASK_X << VoxelSector.ZVOXELBLOCSHIFT_Y )
					that.Offset += VoxelSector.ZVOXELBLOCSIZE_Y;
				else
				{
					that.Sector = self.Sector.near_sectors[(int)VoxelSector.RelativeVoxelOrds.RIGHT - 1];
					if( that.Sector != null )
						that.Offset -= VoxelSector.ZVOXELBLOCSIZE_Y * ( VoxelSector.ZVOXELBLOCSIZE_X - 2 );
				}
			if( that.Sector != null )
			{
				that.Type = self.VoxelTypeManager.VoxelTable[that.Sector.Data.Data[that.Offset]];
				that.VoxelExtension = that.Sector.Data.OtherInfos[that.Offset];
			}
			else
			{
				that.Type = null;
				that.VoxelExtension = null;
			}
		}
Пример #8
0
		public static void GetNearVoxelRef( out VoxelRef that, ref VoxelRef self, VoxelSector.RelativeVoxelOrds direction )
		{
			that = self;
			switch( direction )
			{
			default:
				throw new NotImplementedException( "Creating voxel ref " + direction + " is not implemented " );
				break;
			case VoxelSector.RelativeVoxelOrds.LEFT:
				that.wx--;
				if( that.x > 0 )
				{
					that.x--;
					that.Offset -= that.Sector.Size_y;
				}
				else
				{
					that.Sector = self.Sector.near_sectors[(int)direction - 1];
					if( that.Sector != null )
					{
						that.x = (byte)( that.Sector.Size_x - 1 );
						that.Offset += that.Sector.Size_y * ( that.Sector.Size_x - 2 );
					}
				}
				break;
			case VoxelSector.RelativeVoxelOrds.RIGHT:
				that.wx++;
				if( that.x < (that.Sector.Size_x-1 ) )
				{
					that.x++;
					that.Offset += that.Sector.Size_y;
				}
				else
				{
					that.Sector = self.Sector.near_sectors[(int)direction - 1];
					if( that.Sector != null )
					{
						that.x = 0;
						that.Offset -= that.Sector.Size_y * ( that.Sector.Size_x - 2 );
					}
				}
				break;
			case VoxelSector.RelativeVoxelOrds.BEHIND:
				that.wz--;
				if( that.z > 0 )
				{
					that.z--;
					that.Offset -= that.Sector.Size_y*that.Sector.Size_x;
				}
				else
				{
					that.Sector = self.Sector.near_sectors[(int)direction - 1];
					if( that.Sector != null )
					{
						that.z = (byte)( that.Sector.Size_z - 1 );
						that.Offset += ( that.Sector.Size_x * that.Sector.Size_y * ( that.Sector.Size_z - 2 ) );
					}
				}
				break;
			case VoxelSector.RelativeVoxelOrds.AHEAD:
				that.wz++;
				if( that.z < ( that.Sector.Size_z - 1 ) )
				{
					that.z++;
					that.Offset += that.Sector.Size_y*that.Sector.Size_x;
				}
				else
				{
					that.Sector = self.Sector.near_sectors[(int)direction - 1];
					if( that.Sector != null )
					{
						that.z = 0;
						that.Offset -= ( that.Sector.Size_x * that.Sector.Size_y * ( that.Sector.Size_z - 2 ) );
					}
				}
				break;
			case VoxelSector.RelativeVoxelOrds.BELOW:
				that.wy--;
				if( that.y > 0 )
				{
					that.y--;
					that.Offset--;
				}
				else
				{
					that.Sector = self.Sector.near_sectors[(int)direction - 1];
					if( that.Sector != null )
					{
						that.y = (byte)( that.Sector.Size_y - 1 );
						that.Offset += ( that.Sector.Size_y - 2 );
					}
				}
				break;
			case VoxelSector.RelativeVoxelOrds.ABOVE:
				that.wy++;
				if( that.y < ( that.Sector.Size_y - 1 ) )
				{
					that.y++;
					that.Offset++;
				}
				else
				{
					that.Sector = self.Sector.near_sectors[(int)direction - 1];
					if( that.Sector != null )
					{
						that.y = 0;
						that.Offset -= ( that.Sector.Size_y - 2 );
					}
				}
				break;
			}
			if( that.Sector != null )
			{
				that.Type = that.VoxelTypeManager.VoxelTable[that.Sector.Data.Data[that.Offset]];
				that.VoxelExtension = that.Sector.Data.OtherInfos[that.Offset];
			}
			else
			{
				that.Type = null;
				that.VoxelExtension = null;
			}
		}
Пример #9
0
		public static void GetNearVoxelRef( out NearVoxelRef that, ref VoxelRef self, VoxelSector.RelativeVoxelOrds direction )
		{
			that.Sector = self.Sector;
			that.Offset = self.Offset;
			switch( direction )
			{
			default:
				throw new NotImplementedException( "Creating voxel ref " + direction + " is not implemented " );
				break;
			case VoxelSector.RelativeVoxelOrds.LEFT:
				if( ( that.Offset & ( VoxelSector.ZVOXELBLOCMASK_X << VoxelSector.ZVOXELBLOCSHIFT_Y ) ) != 0 )
					that.Offset -= that.Sector.Size_y;
				else
				{
					that.Sector = self.Sector.near_sectors[(int)direction - 1];
					if( that.Sector != null )
						that.Offset += VoxelSector.ZVOXELBLOCSIZE_Y * ( VoxelSector.ZVOXELBLOCSIZE_X - 2 );
				}
				break;
			case VoxelSector.RelativeVoxelOrds.RIGHT:
				if( ( that.Offset & ( VoxelSector.ZVOXELBLOCMASK_X << VoxelSector.ZVOXELBLOCSHIFT_Y ) ) != VoxelSector.ZVOXELBLOCMASK_X << VoxelSector.ZVOXELBLOCSHIFT_Y )
					that.Offset += VoxelSector.ZVOXELBLOCSIZE_Y;
				else
				{
					that.Sector = self.Sector.near_sectors[(int)direction - 1];
					if( that.Sector != null )
						that.Offset -= VoxelSector.ZVOXELBLOCSIZE_Y * ( VoxelSector.ZVOXELBLOCSIZE_X - 2 );
				}
				break;
			case VoxelSector.RelativeVoxelOrds.BEHIND:
				if( ( that.Offset & ( VoxelSector.ZVOXELBLOCMASK_Z << ( VoxelSector.ZVOXELBLOCSHIFT_X + VoxelSector.ZVOXELBLOCSHIFT_Y ) ) ) != 0 )
					that.Offset -= VoxelSector.ZVOXELBLOCSIZE_Y * VoxelSector.ZVOXELBLOCSIZE_X;
				else
				{
					that.Sector = self.Sector.near_sectors[(int)direction - 1];
					if( that.Sector != null )
						that.Offset += ( VoxelSector.ZVOXELBLOCSIZE_X * VoxelSector.ZVOXELBLOCSIZE_Y * ( VoxelSector.ZVOXELBLOCSIZE_Z - 2 ) );
				}
				break;
			case VoxelSector.RelativeVoxelOrds.AHEAD:
				if( ( that.Offset & ( VoxelSector.ZVOXELBLOCMASK_Z << ( VoxelSector.ZVOXELBLOCSHIFT_X + VoxelSector.ZVOXELBLOCSHIFT_Y ) ) ) != ( VoxelSector.ZVOXELBLOCMASK_Z << ( VoxelSector.ZVOXELBLOCSHIFT_X + VoxelSector.ZVOXELBLOCSHIFT_Y ) ) )
					that.Offset += VoxelSector.ZVOXELBLOCSIZE_Y * VoxelSector.ZVOXELBLOCSIZE_X;
				else
				{
					that.Sector = self.Sector.near_sectors[(int)direction - 1];
					if( that.Sector != null )
						that.Offset -= ( VoxelSector.ZVOXELBLOCSIZE_X * VoxelSector.ZVOXELBLOCSIZE_Y * ( VoxelSector.ZVOXELBLOCSIZE_Z - 2 ) );
				}
				break;
			case VoxelSector.RelativeVoxelOrds.BELOW:
				if( ( that.Offset & ( VoxelSector.ZVOXELBLOCMASK_Y ) ) != 0 )
					that.Offset--;
				else
				{
					that.Sector = self.Sector.near_sectors[(int)direction - 1];
					if( that.Sector != null )
						that.Offset += ( VoxelSector.ZVOXELBLOCSIZE_Y - 2 );
				}
				break;
			case VoxelSector.RelativeVoxelOrds.ABOVE:
				if( ( that.Offset & ( VoxelSector.ZVOXELBLOCMASK_Y ) ) != VoxelSector.ZVOXELBLOCMASK_Y )
					that.Offset++;
				else
				{
					that.Sector = self.Sector.near_sectors[(int)direction - 1];
					if( that.Sector != null )
						that.Offset -= ( VoxelSector.ZVOXELBLOCSIZE_Y - 2 );
				}
				break;
			}
			if( that.Sector != null )
			{
				that.Type = self.VoxelTypeManager.VoxelTable[that.Sector.Data.Data[that.Offset]];
				that.VoxelExtension = that.Sector.Data.OtherInfos[that.Offset];
			}
			else
			{
				that.Type = null;
				that.VoxelExtension = null;
			}
		}
Пример #10
0
		internal abstract void UpdateCulling( ref VoxelRef Location
									, VoxelSector.ModifiedFieldFlags ImportanceFactor
								);
Пример #11
0
		internal void GetVoxelRefs( out VoxelRef[] result, bool nearOnly = true )
		{
			if( nearOnly )
			{
				result = new VoxelRef[7];
				//result[0] = this;
				GetNearVoxelRef( out result[(int)VoxelSector.RelativeVoxelOrds.LEFT]   ,ref this, VoxelSector.RelativeVoxelOrds.LEFT );
				GetNearVoxelRef( out result[(int)VoxelSector.RelativeVoxelOrds.RIGHT]  ,ref this, VoxelSector.RelativeVoxelOrds.RIGHT );
				GetNearVoxelRef( out result[(int)VoxelSector.RelativeVoxelOrds.AHEAD]  ,ref this, VoxelSector.RelativeVoxelOrds.AHEAD );
				GetNearVoxelRef( out result[(int)VoxelSector.RelativeVoxelOrds.BEHIND] ,ref this, VoxelSector.RelativeVoxelOrds.BEHIND );
				GetNearVoxelRef( out result[(int)VoxelSector.RelativeVoxelOrds.ABOVE]  ,ref this, VoxelSector.RelativeVoxelOrds.ABOVE );
				GetNearVoxelRef( out result[(int)VoxelSector.RelativeVoxelOrds.BELOW]  ,ref this, VoxelSector.RelativeVoxelOrds.BELOW );
			}
			else
			{
				result = new VoxelRef[27];
			}
			
		}
Пример #12
0
		internal abstract bool SetVoxel_WithCullingUpdate( ushort VoxelValue
							, VoxelSector.ModifiedFieldFlags ImportanceFactor
							, bool CreateExtension
							, ref VoxelRef Location );
Пример #13
0
		internal bool SetVoxel_WithCullingUpdate( int x, int y, int z, ushort VoxelValue, VoxelSector.ModifiedFieldFlags ImportanceFactor
			, bool CreateExtension, out VoxelRef Location )
		{
			int sx = x >> VoxelSector.ZVOXELBLOCSHIFT_X;
			int sy = y >> VoxelSector.ZVOXELBLOCSHIFT_X;
			int sz = z >> VoxelSector.ZVOXELBLOCSHIFT_X;
			Location.World = this;
			Location.wx = x;
			Location.wy = y;
			Location.wz = z;
			Location.Sector = FindSector( sx, sy, sz );
			Location.Offset = (uint)( ( Location.y = (byte)( y & VoxelSector.ZVOXELBLOCMASK_Y ) )
				+ ( Location.x = (byte)( x & VoxelSector.ZVOXELBLOCMASK_X ) ) * Location.Sector.Size_y
				+ ( Location.z = (byte)( z & VoxelSector.ZVOXELBLOCMASK_Z ) ) * Location.Sector.Size_y * Location.Sector.Size_x );
			Location.Sector.SetCube( Location.x, Location.y, Location.z, VoxelValue );
			Location.Sector.Flag_IsModified |= ImportanceFactor;
			Location.Sector.Culler.CullSingleVoxel( Location.Sector, Location.Offset );
			Location.VoxelTypeManager = VoxelTypeManager;
			Location.Type = VoxelTypeManager.VoxelTable[VoxelValue];
			Location.VoxelExtension = null;
			return true;
		}
Пример #14
0
		public void Swap( ref VoxelRef self, VoxelSector.RelativeVoxelOrds direction, VoxelSector.ModifiedFieldFlags importance )
		{
			VoxelRef other; VoxelRef.GetNearVoxelRef( out other, ref self, direction );
			Swap( ref self, ref other, importance );
		}
Пример #15
0
		public void Swap( ref VoxelRef self, ref NearVoxelRef other, VoxelSector.ModifiedFieldFlags importance )
		{
			ushort selfType = self.Type.properties.Type;// Sector.Data.Data[self.Offset];
			VoxelExtension selfOtherInfo = self.VoxelExtension;//Sector.Data.OtherInfos[self.Offset];
			ushort otherType = other.Type.properties.Type;//Sector.Data.Data[other.Offset];
			VoxelExtension otherOtherInfo = other.VoxelExtension;//.Sector.Data.OtherInfos[other.Offset];

			self.Sector.Data.Data[self.Offset] = otherType;
			self.Sector.Data.OtherInfos[self.Offset] = otherOtherInfo;
			other.Sector.Data.Data[other.Offset] = selfType;
			other.Sector.Data.OtherInfos[other.Offset] = selfOtherInfo;

			self.Sector.Culler.CullSingleVoxel( self.Sector, self.Offset );
			other.Sector.Culler.CullSingleVoxel( other.Sector, other.Offset );
			self.Sector.Flag_IsModified |= importance;
			other.Sector.Flag_IsModified |= importance;
		}
Пример #16
0
		public bool GetVoxelRef( out VoxelRef result, int x, int y, int z )
		{
			result.Sector = FindSector( x >> VoxelSector.ZVOXELBLOCSHIFT_X, y >> VoxelSector.ZVOXELBLOCSHIFT_Y, z >> VoxelSector.ZVOXELBLOCSHIFT_Z );
			result.wx = x;
			result.wy = y;
			result.wz = z;
			result.Offset = (uint)( ( result.y = (byte)( y & VoxelSector.ZVOXELBLOCMASK_Y ) )
				   + ( ( result.x = (byte)( x & VoxelSector.ZVOXELBLOCMASK_X ) ) << VoxelSector.ZVOXELBLOCSHIFT_Y )
				   + ( ( result.z = (byte)( z & VoxelSector.ZVOXELBLOCMASK_Z ) ) << ( VoxelSector.ZVOXELBLOCSHIFT_Y + VoxelSector.ZVOXELBLOCSHIFT_X ) ) );

			result.World = this;
			result.VoxelTypeManager = VoxelTypeManager;
			if( result.Sector == null )
			{
				result.Type = null;
				result.VoxelExtension = null;
				return false;
			}
			result.Type = VoxelTypeManager[result.Sector.Data.Data[result.Offset]];
			result.VoxelExtension = result.Sector.Data.OtherInfos[result.Offset];

			return true;
		}