Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vsync property to windows for native targets #1698

Open
wants to merge 6 commits into
base: 8.2.0-Dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions project/include/ui/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ namespace lime {
virtual void SetTextInputRect (Rectangle *rect) = 0;
virtual const char* SetTitle (const char* title) = 0;
virtual bool SetVisible (bool visible) = 0;
virtual bool SetVSync (bool vsync) = 0;
virtual void WarpMouse (int x, int y) = 0;

Application* currentApplication;
Expand Down
18 changes: 18 additions & 0 deletions project/src/ExternalInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3845,6 +3845,22 @@ namespace lime {
}


bool lime_window_set_vsync (value window, bool vsync) {

Window* targetWindow = (Window*)val_data(window);
return targetWindow->SetVSync (vsync);

}


HL_PRIM bool HL_NAME(hl_window_set_vsync) (HL_CFFIPointer* window, bool vsync) {

Window* targetWindow = (Window*)window->ptr;
return targetWindow->SetVSync (vsync);

}


void lime_window_warp_mouse (value window, int x, int y) {

Window* targetWindow = (Window*)val_data (window);
Expand Down Expand Up @@ -4069,6 +4085,7 @@ namespace lime {
DEFINE_PRIME2v (lime_window_set_text_input_rect);
DEFINE_PRIME2 (lime_window_set_title);
DEFINE_PRIME2 (lime_window_set_visible);
DEFINE_PRIME2 (lime_window_set_vsync);
DEFINE_PRIME3v (lime_window_warp_mouse);
DEFINE_PRIME1 (lime_window_get_opacity);
DEFINE_PRIME2v (lime_window_set_opacity);
Expand Down Expand Up @@ -4258,6 +4275,7 @@ namespace lime {
DEFINE_HL_PRIM (_VOID, hl_window_set_text_input_rect, _TCFFIPOINTER _TRECTANGLE);
DEFINE_HL_PRIM (_STRING, hl_window_set_title, _TCFFIPOINTER _STRING);
DEFINE_HL_PRIM (_BOOL, hl_window_set_visible, _TCFFIPOINTER _BOOL);
DEFINE_HL_PRIM (_BOOL, hl_window_set_vsync, _TCFFIPOINTER _BOOL);
DEFINE_HL_PRIM (_VOID, hl_window_warp_mouse, _TCFFIPOINTER _I32 _I32);
DEFINE_HL_PRIM (_F64, hl_window_get_opacity, _TCFFIPOINTER);
DEFINE_HL_PRIM (_VOID, hl_window_set_opacity, _TCFFIPOINTER _F64);
Expand Down
8 changes: 8 additions & 0 deletions project/src/backend/sdl/SDLWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,14 @@ namespace lime {

}

bool SDLWindow::SetVSync (bool vsync) {

SDL_GL_SetSwapInterval(vsync ? 1 : 0);

return vsync;

}


void SDLWindow::WarpMouse (int x, int y) {

Expand Down
1 change: 1 addition & 0 deletions project/src/backend/sdl/SDLWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ namespace lime {
virtual void SetTextInputRect (Rectangle *rect);
virtual const char* SetTitle (const char* title);
virtual bool SetVisible (bool visible);
virtual bool SetVSync (bool vsync);
virtual void WarpMouse (int x, int y);
SDL_Renderer* sdlRenderer;
SDL_Texture* sdlTexture;
Expand Down
5 changes: 5 additions & 0 deletions src/lime/_internal/backend/flash/FlashWindow.hx
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,11 @@ class FlashWindow
return value;
}

public function setVSync(value:Bool):Bool
{
return false;
}

public function setVisible(value:Bool):Bool
{
return value;
Expand Down
5 changes: 5 additions & 0 deletions src/lime/_internal/backend/html5/HTML5Window.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,11 @@ class HTML5Window
return value;
}

public function setVSync(value:Bool):Bool
{
return false;
}

public function setVisible(value:Bool):Bool
{
return value;
Expand Down
10 changes: 10 additions & 0 deletions src/lime/_internal/backend/native/NativeCFFI.hx
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ class NativeCFFI

@:cffi private static function lime_window_set_visible(handle:Dynamic, visible:Bool):Bool;

@:cffi private static function lime_window_set_vsync(handle:Dynamic, vsync:Bool):Bool;

@:cffi private static function lime_window_warp_mouse(handle:Dynamic, x:Int, y:Int):Void;

@:cffi private static function lime_window_event_manager_register(callback:Dynamic, eventObject:Dynamic):Void;
Expand Down Expand Up @@ -618,6 +620,8 @@ class NativeCFFI
false));
private static var lime_window_set_visible = new cpp.Callable<cpp.Object->Bool->Bool>(cpp.Prime._loadPrime("lime", "lime_window_set_visible", "obb",
false));
private static var lime_window_set_vsync = new cpp.Callable<cpp.Object->Bool->Bool>(cpp.Prime._loadPrime("lime", "lime_window_set_vsync", "obb",
false));
private static var lime_window_warp_mouse = new cpp.Callable<cpp.Object->Int->Int->cpp.Object>(cpp.Prime._loadPrime("lime", "lime_window_warp_mouse",
"oiiv", false));
private static var lime_window_event_manager_register = new cpp.Callable<cpp.Object->cpp.Object->cpp.Void>(cpp.Prime._loadPrime("lime",
Expand Down Expand Up @@ -777,6 +781,7 @@ class NativeCFFI
private static var lime_window_set_text_input_rect = CFFI.load("lime", "lime_window_set_text_input_rect", 2);
private static var lime_window_set_title = CFFI.load("lime", "lime_window_set_title", 2);
private static var lime_window_set_visible = CFFI.load("lime", "lime_window_set_visible", 2);
private static var lime_window_set_vsync = CFFI.load("lime", "lime_window_set_vsync", 2);
private static var lime_window_warp_mouse = CFFI.load("lime", "lime_window_warp_mouse", 3);
private static var lime_window_event_manager_register = CFFI.load("lime", "lime_window_event_manager_register", 2);
private static var lime_zlib_compress = CFFI.load("lime", "lime_zlib_compress", 2);
Expand Down Expand Up @@ -1388,6 +1393,11 @@ class NativeCFFI
return false;
}

@:hlNative("lime", "hl_window_set_vsync") private static function lime_window_set_vsync(handle:CFFIPointer, vsync:Bool):Bool
{
return false;
}

@:hlNative("lime", "hl_window_warp_mouse") private static function lime_window_warp_mouse(handle:CFFIPointer, x:Int, y:Int):Void {}

@:hlNative("lime", "hl_window_get_opacity") private static function lime_window_get_opacity(handle:CFFIPointer):Float { return 0.0; }
Expand Down
12 changes: 12 additions & 0 deletions src/lime/_internal/backend/native/NativeWindow.hx
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,18 @@ class NativeWindow
return value;
}

public function setVSync(value:Bool):Bool
{
if (handle != null)
{
#if (!macro && lime_cffi)
return NativeCFFI.lime_window_set_vsync(handle, value);
#end
}

return value;
}

public function warpMouse(x:Int, y:Int):Void
{
#if (!macro && lime_cffi)
Expand Down
13 changes: 13 additions & 0 deletions src/lime/ui/Window.hx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class Window
public var textInputEnabled(get, set):Bool;
public var title(get, set):String;
public var visible(get, set):Bool;
public var vsync(get, set):Bool;
public var width(get, set):Int;
public var x(get, set):Int;
public var y(get, set):Int;
Expand All @@ -117,6 +118,7 @@ class Window
@:noCompletion private var __scale:Float;
@:noCompletion private var __title:String;
@:noCompletion private var __visible:Bool;
@:noCompletion private var __vsync:Bool;
@:noCompletion private var __width:Int;
@:noCompletion private var __x:Int;
@:noCompletion private var __y:Int;
Expand Down Expand Up @@ -168,6 +170,7 @@ class Window
__height = 0;
__fullscreen = false;
__scale = 1;
__vsync = ((__attributes.context != null && Reflect.hasField(__attributes.context, "vsync")) ? __attributes.context.vsync : false);
__x = 0;
__y = 0;
__title = Reflect.hasField(__attributes, "title") ? __attributes.title : "";
Expand Down Expand Up @@ -687,6 +690,16 @@ class Window
return __visible;
}

@:noCompletion private inline function get_vsync():Bool
{
return __vsync;
}

@:noCompletion private inline function set_vsync(value:Bool):Bool
{
return __vsync = __backend.setVSync(value);
}

@:noCompletion private inline function get_width():Int
{
return __width;
Expand Down