Skip to content

Commit 9311824

Browse files
author
Steal
committed
VSync 구현
1 parent 6732d2d commit 9311824

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

Layered2D/Extensions/RawEx.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Drawing;
1+
using SkiaSharp;
2+
using System.Drawing;
23
using static Layered2D.Interop.UnsafeNativeMethods;
34

45
namespace Layered2D
@@ -14,5 +15,15 @@ public static RawPoint ToRawPoint(this Point point)
1415
{
1516
return new RawPoint(point.X, point.Y);
1617
}
18+
19+
public static RawSize ToRawSize(this SKSize size)
20+
{
21+
return new RawSize((int)size.Width, (int)size.Height);
22+
}
23+
24+
public static RawPoint ToRawPoint(this SKPoint point)
25+
{
26+
return new RawPoint((int)point.X, (int)point.Y);
27+
}
1728
}
1829
}

Layered2D/Nuget/Layered2D 0.0.1/Layered2D.nuspec

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
<package >
33
<metadata>
44
<id>Layered2D</id>
5-
<version>0.0.1</version>
5+
<version>0.1.0</version>
66
<title>Layered2D</title>
77
<authors>Steal</authors>
88
<owners>Steal</owners>
9-
<licenseUrl>https://github.com/steai/layered2d</licenseUrl>
10-
<projectUrl>https://github.com/steai/layered2d</projectUrl>
11-
<iconUrl></iconUrl>
9+
<licenseUrl>https://github.com/Layered2D/Layered2D/blob/master/LICENSE</licenseUrl>
10+
<projectUrl>https://github.com/Layered2D/Layered2D</projectUrl>
11+
<iconUrl>https://raw.githubusercontent.com/Layered2D/Layered2D/master/Logo/512x512.png</iconUrl>
1212
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1313
<description>Layered 2D Rendering with SkiaSharp.</description>
1414
<releaseNotes>Simple layered rendering with SkiaSharp.</releaseNotes>
Binary file not shown.

Layered2D/Windows/LayeredWindow.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
using SkiaSharp;
66

77
using WS = Layered2D.Interop.UnsafeNativeMethods.WindowStyles;
8+
using System.Threading;
9+
using SkiaSharp.Views.Desktop;
810

911
namespace Layered2D.Windows
1012
{
@@ -69,6 +71,12 @@ public Size NativeSize
6971
}
7072
}
7173

74+
public new SKPoint Location
75+
{
76+
get { return base.Location.ToSKPoint(); }
77+
set { base.Location = new Point((int)value.X, (int)value.Y); }
78+
}
79+
7280
private bool isLoaded = false;
7381
public bool IsLoaded
7482
{
@@ -90,6 +98,20 @@ public bool HitVisible
9098
UpdateHitVisible();
9199
}
92100
}
101+
102+
int fixedFrame = 60;
103+
public int FixedFrame
104+
{
105+
get
106+
{
107+
return fixedFrame;
108+
}
109+
set
110+
{
111+
fixedFrame = value;
112+
frameAccurate = 1000d / (value + 0.5d);
113+
}
114+
}
93115
#endregion
94116

95117
#region [ Resources ]
@@ -100,6 +122,9 @@ public bool HitVisible
100122
LayeredContext context;
101123

102124
SKSize resolution = new SKSize(-1, -1);
125+
126+
double frameAccurate = 1000d / 60;
127+
DateTime frameTime;
103128
#endregion
104129

105130
#region [ Initializer ]
@@ -146,6 +171,8 @@ protected override void CreateHandle()
146171

147172
// ready
148173
isLoaded = true;
174+
175+
frameTime = DateTime.Now;
149176
}
150177

151178
#endregion
@@ -209,6 +236,14 @@ private void SetResolutionCore()
209236
#region [ Render ]
210237
public void Render()
211238
{
239+
if (FixedFrame > 0)
240+
{
241+
if (frameTime > DateTime.Now)
242+
return;
243+
244+
frameTime = frameTime.Add(TimeSpan.FromMilliseconds(frameAccurate));
245+
}
246+
212247
context.Clear();
213248

214249
OnRender(context);

0 commit comments

Comments
 (0)