public Entry Lookup(VectorInt3 pos) { int mapX = pos.X / _mapGranularity; int mapY = pos.Y / _mapGranularity; if (mapX < 0 || mapY < 0 || mapX >= _map.GetLength(2) || mapY >= _map.GetLength(1)) { return(null); } List <Entry> candidates = _map[pos.Z, mapY, mapX]; foreach (Entry candidate in candidates) { if ((pos.X >= candidate.Pos.X) && (pos.Y >= candidate.Pos.Y)) { VectorInt2 size = candidate.Texture.To - candidate.Texture.From; if ((pos.X < (candidate.Pos.X + size.X)) && (pos.Y < (candidate.Pos.Y + size.Y))) { return(candidate); } } } return(null); }
/// <summary> /// Tokenizes a VectorInt3. /// </summary> /// <param name="vector">The VectorInt3 instance to tokenize.</param> /// <param name="prefix">Prefix for token names. If the prefix is "Position" then the tokens "Position", "PositionX", "PositionY", and "PositionZ" will be created.</param> protected void TokenizeVectorInt3(VectorInt3 vector, string prefix) { this.tokens[prefix] = $"X:{vector.x} Y:{vector.y} Z:{vector.z}"; this.tokens[prefix + 'X'] = vector.x.ToString(); this.tokens[prefix + 'Y'] = vector.y.ToString(); this.tokens[prefix + 'Z'] = vector.z.ToString(); }
public void PushRoomsMoved(List <Room> rooms, VectorInt3 delta) { if (delta != VectorInt3.Zero) { Push(new MoveRoomsUndoInstance(this, rooms, delta)); } }
private VectorInt3?AllocateTexture(RenderingTexture texture) { if (texture.To.X < texture.From.X || texture.To.Y < texture.From.Y) { throw new ArgumentOutOfRangeException(); // Avoid totally currupted texture allocator state. } for (int i = 0; i < Pages.Length; ++i) { VectorInt2?allocatedPos = Pages[i].Packer.TryAdd(VectorInt2.Max((texture.To - texture.From) + new VectorInt2(2), VectorInt2.One)); if (allocatedPos != null) { VectorInt3 pos = new VectorInt3(allocatedPos.Value.X, allocatedPos.Value.Y, i); if (texture.To.X == texture.From.X || texture.To.Y == texture.From.Y) { UploadTexture(ImageC.CreateNew(1, 1), pos); // Attempt to handle this situation } else { UploadTexture(texture, pos); } AvailableTextures.Add(texture, pos + new VectorInt3(1, 1, 0)); return(pos + new VectorInt3(1, 1, 0)); } } return(null); }
public static VectorInt3 Loop(VectorInt3 val, VectorInt3 min, VectorInt3 max) { if (val.x > max.x) { val.x = min.x; } if (val.y > max.y) { val.y = min.y; } if (val.z > max.z) { val.z = min.z; } if (val.x < min.x) { val.x = max.x; } if (val.y < min.y) { val.y = max.y; } if (val.z < min.z) { val.z = max.z; } return(val); }
private State getOut() { StateWithEventMap swem = new StateWithEventMap(); swem.addAction("enter", delegate(FSMEvent evt){ GameObject go = (GameObject)(evt.obj); VectorInt3 point = this._buoy.position2cell(go.transform.position); if (point != this._buoy.point) { this._buoy.point = point; } return("in"); }); swem.addAction("stay", delegate(FSMEvent evt) { GameObject go = (GameObject)(evt.obj); VectorInt3 point = this._buoy.position2cell(go.transform.position); if (point != this._buoy.point) { this._buoy.point = point; } ; return("in"); }); return(swem); }
void BlockSearch(IStructure str) { //in my test case, the y is off by 128 VectorInt3 minWorld = new VectorInt3( str.MinPos.x, str.MinPos.y + 128, str.MinPos.z); VectorInt3 maxWorld = new VectorInt3( str.MaxPos.x, str.MaxPos.y + 128, str.MaxPos.z); for (int x = minWorld.x; x <= maxWorld.x; x++) { for (int y = minWorld.y; y <= maxWorld.y; y++) { for (int z = minWorld.z; z <= maxWorld.z; z++) { IBlock bl = str.GetBlock(x, y, z); mAPI.Log("Block at " + x + ", " + y + ", " + z + " custom name: " + bl.CustomName + ", Damage: " + bl.GetDamage() + ", HitPoints: " + bl.GetHitPoints()); } } } }
private bool UpdateRoomPosition(Vector2 newRoomPos, Room roomReference, bool moveRooms) { VectorInt2 newRoomPosInt = VectorInt2.FromRounded(newRoomPos); VectorInt2 roomMovement = newRoomPosInt - roomReference.SectorPos; if (roomMovement != new VectorInt2()) { if (EditorActions.CheckForLockedRooms(this, _roomsToMove)) { _roomMouseClicked = null; } else { var delta = new VectorInt3(roomMovement.X, 0, roomMovement.Y); if (roomMovement.X != 0 || roomMovement.Y != 0) { _overallDelta += delta; if (moveRooms) { EditorActions.MoveRooms(delta, _roomsToMove, true); return(true); } } } } return(false); }
public Cube getCube(VectorInt3 position) { if (_cubes.ContainsKey(position)) { return(_cubes [position]); } return(null); }
public TeleporterData(IStructure structure, VectorInt3 pos) : base(structure, pos) { _teleporter = GetDevice() as ITeleporter; if (_teleporter != null) { _targetData = _teleporter.TargetData; } }
public static ulong CompressUvw(VectorInt3 position, Vector2 textureScaling, Vector2 uv, uint highestBits = 0) { uint blendMode2 = Math.Min(highestBits, 15); uint x = (uint)((position.X + uv.X) * textureScaling.X); uint y = (uint)((position.Y + uv.Y) * textureScaling.Y); return(x | ((ulong)y << 24) | ((ulong)position.Z << 48) | ((ulong)blendMode2 << 60)); }
public void Write(VectorInt3 value) { if (_ptr > _endPtrWithSafetyMarging) { Flush(); } WriteUnchecked(value.X); WriteUnchecked(value.Y); WriteUnchecked(value.Z); }
public override unsafe void RenderSprites(RenderingTextureAllocator textureAllocator, bool linearFilter, params Sprite[] sprites) { Vector2 textureScaling = new Vector2(16777216.0f) / new Vector2(textureAllocator.Size.X, textureAllocator.Size.Y); // Build vertex buffer int vertexCount = sprites.Length * 6; int bufferSize = vertexCount * (sizeof(Vector2) + sizeof(ulong)); fixed(byte *data = new byte[bufferSize]) { Vector2 *positions = (Vector2 *)(data); ulong * uvws = (ulong *)(data + vertexCount * sizeof(Vector2)); // Setup vertices int count = sprites.Length; for (int i = 0; i < count; ++i) { Sprite sprite = sprites[i]; VectorInt3 texPos = textureAllocator.Get(sprite.Texture); VectorInt2 texSize = sprite.Texture.To - sprite.Texture.From; positions[i * 6 + 0] = sprite.Pos00; positions[i * 6 + 2] = positions[i * 6 + 3] = sprite.Pos10; positions[i * 6 + 1] = positions[i * 6 + 4] = sprite.Pos01; positions[i * 6 + 5] = sprite.Pos11; uvws[i * 6 + 1] = uvws[i * 6 + 4] = Dx11RenderingDevice.CompressUvw(texPos, textureScaling, new Vector2(0.5f, 0.5f)); uvws[i * 6 + 5] = Dx11RenderingDevice.CompressUvw(texPos, textureScaling, new Vector2(texSize.X - 0.5f, 0.5f)); uvws[i * 6 + 0] = Dx11RenderingDevice.CompressUvw(texPos, textureScaling, new Vector2(0.5f, texSize.Y - 0.5f)); uvws[i * 6 + 2] = uvws[i * 6 + 3] = Dx11RenderingDevice.CompressUvw(texPos, textureScaling, new Vector2(texSize.X - 0.5f, texSize.Y - 0.5f)); } // Create GPU resources using (var VertexBuffer = new Buffer(Device.Device, new IntPtr(data), new BufferDescription(bufferSize, ResourceUsage.Immutable, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0))) { var VertexBufferBindings = new VertexBufferBinding[] { new VertexBufferBinding(VertexBuffer, sizeof(Vector2), (int)((byte *)positions - data)), new VertexBufferBinding(VertexBuffer, sizeof(ulong), (int)((byte *)uvws - data)) }; // Render Bind(); Device.SpriteShader.Apply(Device.Context); Device.Context.PixelShader.SetSampler(0, linearFilter ? Device.SamplerDefault : Device.SamplerRoundToNearest); Device.Context.PixelShader.SetShaderResources(0, ((Dx11RenderingTextureAllocator)(textureAllocator)).TextureView); Device.Context.InputAssembler.SetVertexBuffers(0, VertexBufferBindings); Device.Context.OutputMerger.SetDepthStencilState(Device.DepthStencilNoZBuffer); // Render Device.Context.Draw(vertexCount, 0); // Reset state Device.Context.OutputMerger.SetDepthStencilState(Device.DepthStencilDefault); } } }
public DeviceLock(IPlayfield playfield, IStructure structure, VectorInt3 position) { var witherror = false; try { if (ScriptExecQueue.Iteration % EmpyrionScripting.Configuration.Current.DeviceLockOnlyAllowedEveryXCycles != 0) { return; } if (playfield.IsStructureDeviceLocked(structure.Id, position)) { return; } var lockkey = $"{structure.Id}#{position.x}#{position.y}#{position.z}"; var e = new AutoResetEvent(false); playfield.LockStructureDevice(structure.Id, position, true, (s) => { if (witherror) { Log($"Lock:Callback:Error {playfield.Name} {structure.Id} {position}", LogLevel.Debug); playfield.LockStructureDevice(structure.Id, position, false, null); } else { Success = s; e.Set(); } }); witherror = !e.WaitOne(10000); if (witherror) { Log($"Lock:WaitOne:Error {playfield.Name} {structure.Id} {position}", LogLevel.Debug); } if (Success) { unlockAction = () => { e.Reset(); playfield.LockStructureDevice(structure.Id, position, false, (s) => e.Set()); if (!e.WaitOne(10000)) { Log($"Unlock:Timeout {playfield.Name} {structure.Id} {position}", LogLevel.Debug); } } } ; } catch (Exception error) { witherror = true; throw new Exception($"DeviceLock:failed on Playfield:{playfield?.Name} at Id:{structure.Id} on {position} with: {error}"); } }
public static void LockDeviceHelper(TextWriter output, object rootObject, HelperOptions options, dynamic context, object[] arguments) { if (arguments.Length != 2 && arguments.Length != 4) { throw new HandlebarsException("{{lockdevice structure device|x y z}} helper must have two or four argument: @root (structure) (device)|(x) (y) (z)"); } var root = rootObject as IScriptRootData; var S = arguments[0] as IStructureData; VectorInt3 position; if (!root.IsElevatedScript) { throw new HandlebarsException("{{lockdevice}} only allowed in elevated scripts"); } if (!root.DeviceLockAllowed) { Log($"LockDevice: NoLockAllowed({root.ScriptId}): {root.CycleCounter} % {EmpyrionScripting.Configuration.Current.DeviceLockOnlyAllowedEveryXCycles}", LogLevel.Debug); return; } if (arguments.Length == 2) { var block = arguments[1] as BlockData; position = block?.Position ?? new VectorInt3(); } else { int.TryParse(arguments[1].ToString(), out var x); int.TryParse(arguments[2].ToString(), out var y); int.TryParse(arguments[3].ToString(), out var z); position = new VectorInt3(x, y, z); } try { using (var locked = CreateDeviceLock(root, root.GetCurrentPlayfield(), S.E?.S.GetCurrent(), position)) { if (locked.Success) { options.Template(output, context as object); } else { options.Inverse(output, context as object); } } } catch (Exception error) { if (!CsScriptFunctions.FunctionNeedsMainThread(error, root)) { output.Write("{{lockdevice}} error " + EmpyrionScripting.ErrorFilter(error)); } } }
// Use this for initialization void Awake() { shipArray = new Block[gridSize, gridSize, gridSize]; ResetArray(); shipObjects = new GameObject[gridSize, gridSize, gridSize]; cursorPos = new VectorInt3(gridSize / 2, gridSize / 2, gridSize / 2); grid.localPosition = new Vector3(0f, -(gridSize / 2), 0.0f); MoveCursor(new VectorInt3(0, 0, 0)); }
public void setup(VectorInt3 position, Color color, float unit) { Debug.Log(unit); position_ = position; this.transform.localPosition = new Vector3(position.x * unit, position.y * unit, position.z * unit); color_ = color; this.transform.localScale = Vector3.one * unit; }
static float VecDistance(VectorInt3 a, VectorInt3 b) { int x = a.x - b.x; int y = a.y - b.y; int z = a.z - b.z; int lenSQ = (x * x) + (y * y) + (z * z); return((float)Math.Sqrt(lenSQ)); }
public void setup(VectorInt3 offset, float unit) { unit_ = unit; //Debug.Log ("offset" + offset); this.transform.localPosition = new Vector3(-((float)(offset.x) - 1f) / 2f * unit_, -((float)(offset.y) - 1f) / 2f * unit_, -((float)(offset.z) - 1f) / 2f * unit_); //this.transform.localPosition = new Vector3() }
public override void brush(VectorInt3 point, Building building) { // Debug.Log ("Add"); Debug.Log("!!" + point); Cube cube = building.getCube(point); if (cube == null) { building.addCube(point, Color.red); } }
private void RotateCursor(VectorInt3 direction) { /* cursorRotation += direction; * cursorRotation = VectorInt3.Loop( cursorRotation, new VectorInt3( 0, 0, 0 ), new VectorInt3( 3, 3, 3 ) ); * cursor.localEulerAngles = new Vector3( cursorRotation.y * 90.0f, cursorRotation.x * 90.0f, 0.0f );*/ cursor.Rotate(Vector3.up, 90f * direction.x, Space.World); cursor.Rotate(Vector3.right, 90f * direction.y, Space.World); Vector3 angles = cursor.localEulerAngles; cursorRotation = new VectorInt3(Mathf.RoundToInt(angles.x), Mathf.RoundToInt(angles.y), Mathf.RoundToInt(angles.z)); }
public RenderingTextureAllocator(RenderingDevice device, Description description) { logger.Info("Rendering texture allocated of size \"" + description.Size + "\"."); Pages = new TexturePage[description.Size.Z]; for (int i = 0; i < description.Size.Z; ++i) { Pages[i] = new TexturePage(new VectorInt2(description.Size.X, description.Size.Y)); } Size = description.Size; }
public BlockData(IStructure structure, VectorInt3 pos) { _structure = structure; _block = structure?.GetBlock(pos); _device = structure?.GetDevice <IDevice>(pos); Position = pos; if (_device is IContainer c) { Device = new ContainerData(c); } }
public MoveRoomsUndoInstance(EditorUndoManager parent, List <Room> rooms, VectorInt3 delta) : base(parent, null) { Delta = -delta; Rooms = rooms; Rooms.ForEach(room => Sizes.Add(room, room.SectorSize)); Valid = () => Rooms != null && Rooms.All(room => room != null && room.ExistsInLevel && !room.Locked) && Rooms.All(room => !Parent.Editor.Level.GetConnectedRooms(room).Except(Rooms).Any()) && Rooms.All(room => Sizes.ContainsKey(room) && room.SectorSize == Sizes[room]); UndoAction = () => EditorActions.MoveRooms(Delta, Rooms, true); RedoInstance = () => new MoveRoomsUndoInstance(Parent, Rooms, Delta); }
public override void brush(VectorInt3 point, Building building) { // Debug.Log ("Add"); Cube cube = building.getCube(point); Debug.Log("@@@@" + point); if (cube != null) { Debug.Log("@@@@"); building.removeCube(point); } }
public VectorInt3 position2cell(Vector3 position) { Vector3 o = new Vector3((size_.x * unit_), (size_.y * unit_), (size_.z * unit_)) / 2.0f + position - this.gameObject.transform.parent.position; VectorInt3 cell = new VectorInt3(Mathf.FloorToInt(o.x / unit_), Mathf.FloorToInt(o.y / unit_), Mathf.FloorToInt(o.z / unit_)); cell.x = Mathf.Max(cell.x, 0); cell.y = Mathf.Max(cell.y, 0); cell.z = Mathf.Max(cell.z, 0); cell.x = Mathf.Min(cell.x, 5 - 1); cell.y = Mathf.Min(cell.y, 3 - 1); cell.z = Mathf.Min(cell.z, 4 - 1); return(cell); }
private VectorInt3 position2cell(Vector3 position) { Vector3 o = _box.size / 2 + position - this.gameObject.transform.position; VectorInt3 cell = new VectorInt3(Mathf.FloorToInt(o.x / _unit), Mathf.FloorToInt(o.y / _unit), Mathf.FloorToInt(o.z / _unit)); cell.x = Mathf.Max(cell.x, 0); cell.y = Mathf.Max(cell.y, 0); cell.z = Mathf.Max(cell.z, 0); cell.x = Mathf.Min(cell.x, 5 - 1); cell.y = Mathf.Min(cell.y, 3 - 1); cell.z = Mathf.Min(cell.z, 4 - 1); return(cell); }
private VectorInt3 UpdateQuickAccess(ref RenderingTexture texture, VectorInt3 result) { if (LastUsedTextureIndex == 0) { QuickAccessTexture1 = new KeyValuePair <RenderingTexture, VectorInt3>(texture, result); LastUsedTextureIndex = 1; } else { QuickAccessTexture0 = new KeyValuePair <RenderingTexture, VectorInt3>(texture, result); LastUsedTextureIndex = 0; } return(result); }
public void removeCube(VectorInt3 point) { Debug.Log(point); //_cubes. Cube cube = null; if (_cubes.ContainsKey(point)) { cube = _cubes [point]; _cubes.Remove(point); cube.gameObject.SetActive(false); } }
private State getIn() { StateWithEventMap swem = new StateWithEventMap(); swem.onStart += delegate { if (drawing_ && brush_) { brush_.brush(this._buoy.point, this._buinding); } _buoy.open(); }; swem.onOver += delegate { _buoy.close(); }; swem.addAction("drawing", delegate(FSMEvent evt) { if (drawing_ && this.brush_ != null) { this.brush_.brush(this._buoy.point, this._buinding); } }); swem.addAction("brush", delegate(FSMEvent evt) { // Debug.Log("!!!!!!DSFDSF"); if (drawing_ && this.brush_ != null) { this.brush_.brush(this._buoy.point, this._buinding); } }); swem.addAction("exit", "out"); swem.addAction("stay", delegate(FSMEvent evt) { // Debug.Log(drawing_+ this.brush_.gameObject.name); GameObject go = (GameObject)(evt.obj); VectorInt3 point = this._buoy.position2cell(go.transform.position); if (point != this._buoy.point) { this._buoy.point = point; if (drawing_ && this.brush_ != null) { this.brush_.brush(point, this._buinding); } } }); return(swem); }