wip move to new uniffi language binding
This commit is contained in:
parent
f7a5d8f823
commit
53cbdd8440
30 changed files with 211 additions and 187 deletions
|
@ -88,13 +88,13 @@ internal sealed class CollideBullets : ITickStep
|
|||
|
||||
pixel = pixel.GetPixelRelative(-4, -4);
|
||||
for (short dx = 0; dx < _explosiveSprite.Width; dx++)
|
||||
for (short dy = 0; dy < _explosiveSprite.Height; dy++)
|
||||
{
|
||||
if (!_explosiveSprite[dx, dy].HasValue)
|
||||
continue;
|
||||
for (short dy = 0; dy < _explosiveSprite.Height; dy++)
|
||||
{
|
||||
if (!_explosiveSprite[dx, dy].HasValue)
|
||||
continue;
|
||||
|
||||
Core(pixel.GetPixelRelative(dx, dy));
|
||||
}
|
||||
Core(pixel.GetPixelRelative(dx, dy));
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
|
|
|
@ -10,22 +10,22 @@ internal sealed class EmptyTileFinder(
|
|||
var maxMinDistance = 0d;
|
||||
TilePosition spawnTile = default;
|
||||
for (ushort x = 1; x < MapService.TilesPerRow - 1; x++)
|
||||
for (ushort y = 1; y < MapService.TilesPerColumn - 1; y++)
|
||||
{
|
||||
var tile = new TilePosition(x, y);
|
||||
if (mapService.Current.IsWall(tile))
|
||||
continue;
|
||||
for (ushort y = 1; y < MapService.TilesPerColumn - 1; y++)
|
||||
{
|
||||
var tile = new TilePosition(x, y);
|
||||
if (mapService.Current.IsWall(tile))
|
||||
continue;
|
||||
|
||||
var tilePixelCenter = tile.GetCenter().ToFloatPosition();
|
||||
var minDistance = entityManager.AllEntities
|
||||
.Select(entity => entity.Position.Distance(tilePixelCenter))
|
||||
.Aggregate(double.MaxValue, Math.Min);
|
||||
if (minDistance <= maxMinDistance)
|
||||
continue;
|
||||
var tilePixelCenter = tile.GetCenter().ToFloatPosition();
|
||||
var minDistance = entityManager.AllEntities
|
||||
.Select(entity => entity.Position.Distance(tilePixelCenter))
|
||||
.Aggregate(double.MaxValue, Math.Min);
|
||||
if (minDistance <= maxMinDistance)
|
||||
continue;
|
||||
|
||||
maxMinDistance = minDistance;
|
||||
spawnTile = tile;
|
||||
}
|
||||
maxMinDistance = minDistance;
|
||||
spawnTile = tile;
|
||||
}
|
||||
|
||||
return spawnTile;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ internal sealed class Map(string name, bool[,] walls)
|
|||
{
|
||||
public string Name => name;
|
||||
|
||||
public bool IsWall(int x, int y) => walls[x, y];
|
||||
public bool IsWall(ulong x, ulong y) => walls[x, y];
|
||||
|
||||
public bool IsWall(PixelPosition position) => walls[position.X, position.Y];
|
||||
|
||||
|
@ -12,12 +12,12 @@ internal sealed class Map(string name, bool[,] walls)
|
|||
{
|
||||
var pixel = position.ToPixelPosition();
|
||||
|
||||
for (short dx = 0; dx < MapService.TileSize; dx++)
|
||||
for (short dy = 0; dy < MapService.TileSize; dy++)
|
||||
{
|
||||
if (IsWall(pixel.GetPixelRelative(dx, dy)))
|
||||
return true;
|
||||
}
|
||||
for (long dx = 0; dx < (long)MapService.TileSize; dx++)
|
||||
for (long dy = 0; dy < (long)MapService.TileSize; dy++)
|
||||
{
|
||||
if (IsWall(pixel.GetPixelRelative(dx, dy)))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ internal sealed class MapEntityManager(
|
|||
{
|
||||
Rotation = Random.Shared.NextDouble(),
|
||||
MaxBullets = _rules.MagazineSize,
|
||||
BulletStats =new BulletStats(_rules.BulletSpeed, 0, false, false)
|
||||
BulletStats = new BulletStats(_rules.BulletSpeed, 0, false, false)
|
||||
};
|
||||
_playerTanks[player] = tank;
|
||||
logger.LogInformation("Tank added for player {}", player.Name);
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using ServicePoint;
|
||||
using TanksServer.Graphics;
|
||||
|
||||
namespace TanksServer.GameLogic;
|
||||
|
||||
internal sealed class MapService
|
||||
{
|
||||
public const ushort TilesPerRow = 44;
|
||||
public const ushort TilesPerColumn = 20;
|
||||
public const ushort TileSize = 8;
|
||||
public const ushort PixelsPerRow = TilesPerRow * TileSize;
|
||||
public const ushort PixelsPerColumn = TilesPerColumn * TileSize;
|
||||
public const ulong TilesPerRow = 44;
|
||||
public const ulong TilesPerColumn = 20;
|
||||
public const ulong TileSize = 8;
|
||||
public const ulong PixelsPerRow = TilesPerRow * TileSize;
|
||||
public const ulong PixelsPerColumn = TilesPerColumn * TileSize;
|
||||
|
||||
private readonly ConcurrentDictionary<string, MapPrototype> _mapPrototypes = new();
|
||||
private readonly ConcurrentDictionary<string, Bitmap> _mapPreviews = new();
|
||||
|
|
|
@ -68,13 +68,13 @@ internal sealed class MoveTanks(
|
|||
{
|
||||
var (topLeft, _) = newPosition.GetBoundsForCenter(MapService.TileSize);
|
||||
|
||||
for (short y = 0; y < MapService.TileSize; y++)
|
||||
for (short x = 0; x < MapService.TileSize; x++)
|
||||
{
|
||||
var pixelToCheck = topLeft.GetPixelRelative(x, y);
|
||||
if (map.Current.IsWall(pixelToCheck))
|
||||
return true;
|
||||
}
|
||||
for (ulong y = 0; y < MapService.TileSize; y++)
|
||||
for (ulong x = 0; x < MapService.TileSize; x++)
|
||||
{
|
||||
var pixelToCheck = topLeft.GetPixelRelative((long)x, (long)y);
|
||||
if (map.Current.IsWall(pixelToCheck))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ internal sealed class SpriteMapPrototype : MapPrototype
|
|||
|
||||
public SpriteMapPrototype(string name, Sprite sprite)
|
||||
{
|
||||
if (sprite.Width != MapService.PixelsPerRow || sprite.Height != MapService.PixelsPerColumn)
|
||||
if ((ulong)sprite.Width != MapService.PixelsPerRow || (ulong)sprite.Height != MapService.PixelsPerColumn)
|
||||
throw new FileLoadException($"invalid image size in file {Name}");
|
||||
|
||||
Name = name;
|
||||
|
|
|
@ -8,7 +8,7 @@ internal sealed class TextMapPrototype : MapPrototype
|
|||
|
||||
public TextMapPrototype(string name, string text)
|
||||
{
|
||||
if (text.Length != MapService.TilesPerColumn * MapService.TilesPerRow)
|
||||
if ((ulong)text.Length != MapService.TilesPerColumn * MapService.TilesPerRow)
|
||||
throw new ArgumentException($"cannot load map {name}: invalid length");
|
||||
Name = name;
|
||||
Text = text;
|
||||
|
@ -19,20 +19,20 @@ internal sealed class TextMapPrototype : MapPrototype
|
|||
{
|
||||
var walls = new bool[MapService.PixelsPerRow, MapService.PixelsPerColumn];
|
||||
|
||||
for (ushort tileX = 0; tileX < MapService.TilesPerRow; tileX++)
|
||||
for (ushort tileY = 0; tileY < MapService.TilesPerColumn; tileY++)
|
||||
{
|
||||
var tile = new TilePosition(tileX, tileY);
|
||||
if (Text[tileX + tileY * MapService.TilesPerRow] != '#')
|
||||
continue;
|
||||
|
||||
for (byte pixelInTileX = 0; pixelInTileX < MapService.TileSize; pixelInTileX++)
|
||||
for (byte pixelInTileY = 0; pixelInTileY < MapService.TileSize; pixelInTileY++)
|
||||
for (ulong tileX = 0; tileX < MapService.TilesPerRow; tileX++)
|
||||
for (ulong tileY = 0; tileY < MapService.TilesPerColumn; tileY++)
|
||||
{
|
||||
var (x, y) = tile.ToPixelPosition().GetPixelRelative(pixelInTileX, pixelInTileY);
|
||||
walls[x, y] = true;
|
||||
var tile = new TilePosition(tileX, tileY);
|
||||
if (Text[(int)(tileX + tileY * MapService.TilesPerRow)] != '#')
|
||||
continue;
|
||||
|
||||
for (byte pixelInTileX = 0; pixelInTileX < MapService.TileSize; pixelInTileX++)
|
||||
for (byte pixelInTileY = 0; pixelInTileY < MapService.TileSize; pixelInTileY++)
|
||||
{
|
||||
var (x, y) = tile.ToPixelPosition().GetPixelRelative(pixelInTileX, pixelInTileY);
|
||||
walls[x, y] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new Map(Name, walls);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue