mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 02:15:43 -04:00
use a timer on mac for smoother updates
This commit is contained in:
parent
b614a05a12
commit
865ea20789
@ -74,7 +74,8 @@ P3DInstance(P3D_request_ready_func *func, void *user_data) :
|
|||||||
_shared_mmap_size = 0;
|
_shared_mmap_size = 0;
|
||||||
_swbuffer = NULL;
|
_swbuffer = NULL;
|
||||||
_reversed_buffer = NULL;
|
_reversed_buffer = NULL;
|
||||||
_mouse_active = false;
|
_mouse_active = true;
|
||||||
|
_frame_timer = NULL;
|
||||||
#endif // __APPLE__
|
#endif // __APPLE__
|
||||||
|
|
||||||
// Set some initial properties.
|
// Set some initial properties.
|
||||||
@ -110,6 +111,11 @@ P3DInstance::
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
|
if (_frame_timer != NULL) {
|
||||||
|
CFRunLoopTimerInvalidate(_frame_timer);
|
||||||
|
CFRelease(_frame_timer);
|
||||||
|
}
|
||||||
|
|
||||||
if (_swbuffer != NULL) {
|
if (_swbuffer != NULL) {
|
||||||
SubprocessWindowBuffer::destroy_buffer(_shared_fd, _shared_mmap_size,
|
SubprocessWindowBuffer::destroy_buffer(_shared_fd, _shared_mmap_size,
|
||||||
_shared_filename, _swbuffer);
|
_shared_filename, _swbuffer);
|
||||||
@ -510,17 +516,6 @@ handle_event(P3D_event_data event) {
|
|||||||
bool keep_event = false;
|
bool keep_event = false;
|
||||||
|
|
||||||
switch (er->what) {
|
switch (er->what) {
|
||||||
case nullEvent:
|
|
||||||
// We appear to get this event pretty frequently when nothing else
|
|
||||||
// is going on. Great; we'll take advantage of it to request a
|
|
||||||
// refresh, which will cause updateEvt to be triggered (if the
|
|
||||||
// instance is still onscreen).
|
|
||||||
if (_instance_window_opened && _swbuffer != NULL && _swbuffer->ready_for_read()) {
|
|
||||||
request_refresh();
|
|
||||||
}
|
|
||||||
keep_event = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case mouseDown:
|
case mouseDown:
|
||||||
case mouseUp:
|
case mouseUp:
|
||||||
{
|
{
|
||||||
@ -828,6 +823,18 @@ handle_notify_request(const string &message) {
|
|||||||
delete _splash_window;
|
delete _splash_window;
|
||||||
_splash_window = NULL;
|
_splash_window = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
// Start a timer to update the frame repeatedly. This seems to be
|
||||||
|
// steadier than waiting for nullEvent.
|
||||||
|
CFRunLoopTimerContext timer_context;
|
||||||
|
memset(&timer_context, 0, sizeof(timer_context));
|
||||||
|
timer_context.info = this;
|
||||||
|
_frame_timer = CFRunLoopTimerCreate
|
||||||
|
(NULL, 0, 1.0 / 60.0, 0, 0, timer_callback, &timer_context);
|
||||||
|
CFRunLoopRef run_loop = CFRunLoopGetCurrent();
|
||||||
|
CFRunLoopAddTimer(run_loop, _frame_timer, kCFRunLoopCommonModes);
|
||||||
|
#endif // __APPLE__
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1163,6 +1170,22 @@ add_modifier_flags(unsigned int &swb_flags, int modifiers) {
|
|||||||
#endif // __APPLE__
|
#endif // __APPLE__
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: P3DInstance::timer_callback
|
||||||
|
// Access: Private
|
||||||
|
// Description: OSX only: this callback is associated with a
|
||||||
|
// CFRunLoopTimer, to be called periodically for
|
||||||
|
// updating the frame.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void P3DInstance::
|
||||||
|
timer_callback(CFRunLoopTimerRef timer, void *info) {
|
||||||
|
P3DInstance *self = (P3DInstance *)info;
|
||||||
|
self->request_refresh();
|
||||||
|
//self->paint_window();
|
||||||
|
}
|
||||||
|
#endif // __APPLE__
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: P3DInstance::SplashDownload::Constructor
|
// Function: P3DInstance::SplashDownload::Constructor
|
||||||
// Access: Public
|
// Access: Public
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
#include "subprocessWindowBuffer.h"
|
#include "subprocessWindowBuffer.h"
|
||||||
|
#include <CoreFoundation/CoreFoundation.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <deque>
|
#include <deque>
|
||||||
@ -110,6 +111,10 @@ private:
|
|||||||
void paint_window();
|
void paint_window();
|
||||||
void add_modifier_flags(unsigned int &swb_flags, int modifiers);
|
void add_modifier_flags(unsigned int &swb_flags, int modifiers);
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
static void timer_callback(CFRunLoopTimerRef timer, void *info);
|
||||||
|
#endif // __APPLE__
|
||||||
|
|
||||||
P3D_request_ready_func *_func;
|
P3D_request_ready_func *_func;
|
||||||
P3D_object *_browser_script_object;
|
P3D_object *_browser_script_object;
|
||||||
P3DToplevelObject *_panda_script_object;
|
P3DToplevelObject *_panda_script_object;
|
||||||
@ -137,6 +142,8 @@ private:
|
|||||||
SubprocessWindowBuffer *_swbuffer;
|
SubprocessWindowBuffer *_swbuffer;
|
||||||
char *_reversed_buffer;
|
char *_reversed_buffer;
|
||||||
bool _mouse_active;
|
bool _mouse_active;
|
||||||
|
|
||||||
|
CFRunLoopTimerRef _frame_timer;
|
||||||
#endif // __APPLE__
|
#endif // __APPLE__
|
||||||
|
|
||||||
P3DSplashWindow *_splash_window;
|
P3DSplashWindow *_splash_window;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user