mirror of
https://github.com/MaddyThorson/StrawberryBF.git
synced 2024-11-25 16:18:56 +08:00
Sprite loading progress
This commit is contained in:
parent
a2f5f157fc
commit
6bfc6c7721
|
@ -247,10 +247,10 @@ namespace Strawberry
|
|||
{
|
||||
let path = scope String();
|
||||
file.GetFilePath(path);
|
||||
|
||||
let sprite = new [Friend]Sprite(path);
|
||||
|
||||
path.Remove(0, ContentRoot.Length + 8);
|
||||
path.Remove(0, ContentRoot.Length + 9);
|
||||
path.RemoveFromEnd(4);
|
||||
Sprites.Add(new String(path), sprite);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,12 +33,13 @@ namespace Strawberry
|
|||
|
||||
public readonly String Path;
|
||||
|
||||
public int Width { get; private set; }
|
||||
public int Height { get; private set; }
|
||||
|
||||
private Frame[] frames;
|
||||
private List<Layer> layers;
|
||||
private List<Tag> tags;
|
||||
private List<Slice> slices;
|
||||
private int width;
|
||||
private int height;
|
||||
private Modes mode;
|
||||
|
||||
private this(String path)
|
||||
|
@ -53,6 +54,11 @@ namespace Strawberry
|
|||
Unload();
|
||||
}
|
||||
|
||||
public Frame this[int index]
|
||||
{
|
||||
get => frames[index];
|
||||
}
|
||||
|
||||
private void Unload()
|
||||
{
|
||||
for (let f in frames)
|
||||
|
@ -125,8 +131,8 @@ namespace Strawberry
|
|||
|
||||
// Frame Count / Width / Height / Color Mode
|
||||
frames = new Frame[WORD()];
|
||||
width = WORD();
|
||||
height = WORD();
|
||||
Width = WORD();
|
||||
Height = WORD();
|
||||
mode = (Modes)(WORD() / 8);
|
||||
|
||||
// Other Info, Ignored
|
||||
|
@ -148,13 +154,13 @@ namespace Strawberry
|
|||
|
||||
// Body
|
||||
{
|
||||
var temp = scope:: uint8[width * height * (int)mode];
|
||||
var temp = scope:: uint8[Width * Height * (int)mode];
|
||||
let palette = scope:: Color[256];
|
||||
HasUserData last = null;
|
||||
|
||||
for (int i = 0; i < frames.Count; i++)
|
||||
{
|
||||
let frame = new Frame(width, height);
|
||||
let frame = new Frame(Width, Height);
|
||||
frames[i] = frame;
|
||||
|
||||
int64 frameStart, frameEnd;
|
||||
|
@ -257,7 +263,7 @@ namespace Strawberry
|
|||
else if (celType == 1)
|
||||
{
|
||||
var linkFrame = frames[WORD()];
|
||||
var linkCel = linkFrame.Cels[frame.Cels.Count];
|
||||
var linkCel = linkFrame.[Friend]cels[frame.[Friend]cels.Count];
|
||||
|
||||
width = linkCel.Width;
|
||||
height = linkCel.Height;
|
||||
|
@ -279,7 +285,7 @@ namespace Strawberry
|
|||
if (cel.Layer.Visible)
|
||||
CelToFrame(frame, cel);
|
||||
|
||||
frame.Cels.Add(cel);
|
||||
frame.[Friend]cels.Add(cel);
|
||||
}
|
||||
// PALETTE CHUNK
|
||||
else if (chunkType == Chunks.Palette)
|
||||
|
@ -418,12 +424,12 @@ namespace Strawberry
|
|||
if (cel.Layer.BlendMode < BlendModes.Count)
|
||||
blend = BlendModes[cel.Layer.BlendMode];
|
||||
|
||||
for (int sx = Math.Max(0, -cel.X), int right = Math.Min(cel.Width, width - cel.X); sx < right; sx++)
|
||||
for (int sx = Math.Max(0, -cel.X), int right = Math.Min(cel.Width, Width - cel.X); sx < right; sx++)
|
||||
{
|
||||
int dx = cel.X + sx;
|
||||
int dy = cel.Y * width;
|
||||
int dy = cel.Y * Width;
|
||||
|
||||
for (int sy = Math.Max(0, -cel.Y), int bottom = Math.Min(cel.Height, height - cel.Y); sy < bottom; sy++, dy += width)
|
||||
for (int sy = Math.Max(0, -cel.Y), int bottom = Math.Min(cel.Height, Height - cel.Y); sy < bottom; sy++, dy += Width)
|
||||
{
|
||||
if (dx + dy >= 0 && dx + dy < pxLen)
|
||||
blend(frame.Pixels, (dx + dy) * 4, cel.Pixels[sx + sy * cel.Width], opacity);
|
||||
|
@ -433,14 +439,15 @@ namespace Strawberry
|
|||
|
||||
// Data
|
||||
|
||||
private class Frame
|
||||
public class Frame
|
||||
{
|
||||
public SDL.Texture* Texture;
|
||||
public float Duration;
|
||||
public List<Cel> Cels;
|
||||
public uint8* Pixels;
|
||||
public int32 PixelsLength;
|
||||
|
||||
private List<Cel> cels;
|
||||
|
||||
public this(int w, int h)
|
||||
{
|
||||
Texture = SDL.CreateTexture(Game.Renderer, (uint32)SDL.PIXELFORMAT_ARGB8888, (int32)SDL.TextureAccess.Static, (int32)w, (int32)h);
|
||||
|
@ -449,14 +456,14 @@ namespace Strawberry
|
|||
SDL.LockTexture(Texture, null, out ptr, out PixelsLength);
|
||||
Pixels = (uint8*)ptr;
|
||||
|
||||
Cels = new List<Cel>();
|
||||
cels = new List<Cel>();
|
||||
}
|
||||
|
||||
public ~this()
|
||||
{
|
||||
for (let c in Cels)
|
||||
for (let c in cels)
|
||||
delete c;
|
||||
delete Cels;
|
||||
delete cels;
|
||||
|
||||
SDL.DestroyTexture(Texture);
|
||||
}
|
||||
|
|
|
@ -36,5 +36,13 @@ namespace Strawberry
|
|||
SDL.SetRenderDrawColor(Game.Renderer, color.R, color.G, color.B, color.A);
|
||||
SDL.RenderDrawLine(Game.Renderer, (int32)fromn.X, (int32)fromn.Y, (int32)ton.X, (int32)ton.Y);
|
||||
}
|
||||
|
||||
static public void Sprite(Sprite sprite, int frame, Point position)
|
||||
{
|
||||
SDL.Rect src = Strawberry.Rect(0, 0, sprite.Width, sprite.Height);
|
||||
SDL.Rect dst = Strawberry.Rect(position.X, position.Y, sprite.Width, sprite.Height);
|
||||
|
||||
SDL.RenderCopy(Game.Renderer, sprite[frame].Texture, &src, &dst);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -166,5 +166,10 @@ namespace Strawberry
|
|||
{
|
||||
return Rect(a.X * b.X, a.Y * b.Y, a.Width * b.X, a.Height * b.Y);
|
||||
}
|
||||
|
||||
static public implicit operator SDL2.SDL.Rect(Rect r)
|
||||
{
|
||||
return SDL2.SDL.Rect((int32)r.X, (int32)r.Y, (int32)r.Width, (int32)r.Height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user