Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
2c25791
Add batch event processing in lime/sdl
aprothman May 15, 2019
5cf919b
BatchUpdate return value indicates inactive status
aprothman May 16, 2019
42588f4
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman May 18, 2019
f8a24e9
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman May 30, 2019
39655f2
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Jun 6, 2019
7da63d6
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Jun 10, 2019
a0cafe6
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Jun 19, 2019
7642af1
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Jul 1, 2019
7096a62
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Jul 5, 2019
29e7ef0
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Jul 11, 2019
738620e
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Jul 12, 2019
52e5533
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Jul 12, 2019
2062e67
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Jul 16, 2019
de8ce02
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Jul 28, 2019
7da7b20
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Jul 30, 2019
eb46c60
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Aug 2, 2019
1ed381b
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Aug 6, 2019
6e3eb7a
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Aug 12, 2019
06787bd
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Aug 18, 2019
927c3d2
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Aug 19, 2019
5370b0e
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Aug 23, 2019
25f7e1f
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Sep 1, 2019
1536841
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Sep 5, 2019
554c5b1
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Sep 5, 2019
3828a3c
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Sep 11, 2019
aae3e87
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Sep 16, 2019
5a0086c
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Sep 20, 2019
4fdb0da
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Sep 26, 2019
7214637
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Oct 3, 2019
7aa5d66
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Oct 9, 2019
e13b739
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Oct 14, 2019
d7714b3
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Nov 5, 2019
c8a9091
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Nov 7, 2019
070ccd6
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Nov 20, 2019
34ce82b
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Nov 29, 2019
cc584e2
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Dec 9, 2019
41161ce
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Jan 2, 2020
d115773
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Feb 12, 2020
a392a96
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Mar 11, 2020
08580e6
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Mar 25, 2020
89ebb52
Committed sub-repos sdl and tinyfiledialogs
aprothman Mar 25, 2020
63af378
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Apr 1, 2020
6d4b16e
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman May 14, 2020
0155599
Committed submodule updates
aprothman Jun 12, 2020
bcfb730
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Jun 22, 2020
b998562
Restricted garbage collection during BatchUpdate()
aprothman Jun 23, 2020
70d850a
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Jul 2, 2020
0d94959
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Jul 11, 2020
04fb1e0
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Jul 22, 2020
f088e44
Added mouse move filtering during BatchUpdate
aprothman Jul 22, 2020
74c1fd4
Merge branch 'develop' of github.com:openfl/lime into BatchUpdate
aprothman Aug 19, 2020
982c990
Merge branch 'develop' into BatchUpdate
player-03 Sep 1, 2025
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
106 changes: 101 additions & 5 deletions project/src/backend/sdl/SDLApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ namespace lime {
lastUpdate = 0;
nextUpdate = 0;

eventQueue = NULL;
queueLength = 0;
queueMaxLength = 0;
isGCBlocking = false;

ApplicationEvent applicationEvent;
ClipboardEvent clipboardEvent;
DropEvent dropEvent;
Expand Down Expand Up @@ -80,7 +85,12 @@ namespace lime {

SDLApplication::~SDLApplication () {


if (NULL != eventQueue) {
SDL_free (eventQueue);
eventQueue = NULL;
queueMaxLength = 0;
queueLength = 0;
}

}

Expand Down Expand Up @@ -332,6 +342,8 @@ namespace lime {
lastUpdate = SDL_GetTicks ();
nextUpdate = lastUpdate;

while (20 == BatchUpdate(20));

}


Expand Down Expand Up @@ -827,7 +839,6 @@ namespace lime {

static SDL_TimerID timerID = 0;
bool timerActive = false;
bool firstTime = true;

Uint32 OnTimer (Uint32 interval, void *) {

Expand Down Expand Up @@ -857,9 +868,7 @@ namespace lime {

#if (!defined (IPHONE) && !defined (EMSCRIPTEN))

if (active && (firstTime || WaitEvent (&event))) {

firstTime = false;
if (active && WaitEvent (&event)) {

HandleEvent (&event);
event.type = -1;
Expand Down Expand Up @@ -912,6 +921,83 @@ namespace lime {
}


int SDLApplication::BatchUpdate (int numEvents) {

SDL_Event* mouseMoved = NULL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well move this down to where it's used.


if (!active) {
return -1;
}

queueLength = numEvents;

if (queueLength > queueMaxLength) {

if (NULL != eventQueue) {
SDL_free (eventQueue);
}

eventQueue = reinterpret_cast<SDL_Event*> (SDL_malloc (queueLength * sizeof (SDL_Event)));
if (NULL == eventQueue) {
queueLength = 0;
queueMaxLength = 0;
} else {
queueMaxLength = queueLength;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like queueMaxLength is the wrong name if you can just increase it. From the name, I'd expect excess events to be discarded or something.

Actually, what is the queueLength variable even for? It stores the last value of numEvents, but it's never needed outside this function. We could have queueLength do what queueMaxLength is currently doing, and use numEvents as the number of events. (That is, find and replace "queueLength" → "numEvents", then replace "queueMaxLength" → "queueLength".)

}
}

int numPending = GetPendingEvents (eventQueue, queueLength);

// only allow GC free objects while we're handling events
if (isGCBlocking) System::GCExitBlocking ();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said elsewhere, this seems disruptive. Maybe it's appropriate, but the comment doesn't do a good job of explaining why.

isGCBlocking = false;

int nextEvent;
for (nextEvent = 0; nextEvent < numPending; ++nextEvent) {

if (SDL_MOUSEMOTION == eventQueue[nextEvent].type) {
// we'll only handle the last motion event in the batch
mouseMoved = &eventQueue[nextEvent];
} else {
HandleEvent (&eventQueue[nextEvent]);
eventQueue[nextEvent].type = -1;
if (!active) {
return -1;
}
}
}

// handle the mouse motion event if there is one this batch
if (NULL != mouseMoved) {
HandleEvent (mouseMoved);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said elsewhere, I'm not a fan of doing this out of order. It could get skipped if the above loop returns. Another approach would be to add a second loop above the first:

for (nextEvent = 0; nextEvent < numPending; ++nextEvent) {
    if (eventQueue[nextEvent].type == SDL_MOUSEMOTION) {
        if (mouseMoved != NULL) mouseMoved->type = -1;
        mouseMoved = &eventQueue[nextEvent];
    }
}

This will set all but the final mouse moved event's type to -1. Then the main loop would skip over those events, and execute all >= 0 events in the right order.

mouseMoved->type = -1;
}

currentUpdate = SDL_GetTicks ();

#if (!defined (IPHONE) && !defined (EMSCRIPTEN))

if (currentUpdate >= nextUpdate) {

SDL_RemoveTimer (timerID);
OnTimer (0, 0);

} else if (!timerActive) {

timerActive = true;
timerID = SDL_AddTimer (nextUpdate - currentUpdate, OnTimer, 0);

}

if (!isGCBlocking) System::GCEnterBlocking ();
isGCBlocking = true;

#endif

return nextEvent;
}


void SDLApplication::UpdateFrame () {

#ifdef EMSCRIPTEN
Expand Down Expand Up @@ -978,6 +1064,16 @@ namespace lime {

}


int SDLApplication::GetPendingEvents (SDL_Event* events, int maxEvents)
{
SDL_PumpEvents ();

int numEvents = SDL_PeepEvents (events, maxEvents, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT);

return numEvents;
}


Application* CreateApplication () {

Expand Down
6 changes: 6 additions & 0 deletions project/src/backend/sdl/SDLApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace lime {
virtual int Quit ();
virtual void SetFrameRate (double frameRate);
virtual bool Update ();
virtual int BatchUpdate(int numEvents);

void RegisterWindow (SDLWindow *window);

Expand All @@ -51,13 +52,18 @@ namespace lime {
void ProcessTouchEvent (SDL_Event* event);
void ProcessWindowEvent (SDL_Event* event);
int WaitEvent (SDL_Event* event);
int GetPendingEvents (SDL_Event* event, int NumEvents);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the argument be int maxEvents to match the implementation?


static void UpdateFrame ();
static void UpdateFrame (void*);

static SDLApplication* currentApplication;

bool active;
SDL_Event* eventQueue;
int queueLength;
int queueMaxLength;
bool isGCBlocking;
ApplicationEvent applicationEvent;
ClipboardEvent clipboardEvent;
Uint32 currentUpdate;
Expand Down
Loading