Skip to content

Commit ccf8820

Browse files
RaydanOMGrartdeell
authored andcommitted
Now returning pointer to node instead of actual jobject for optimized removal
1 parent 78285f3 commit ccf8820

3 files changed

Lines changed: 37 additions & 32 deletions

File tree

app_pojavlauncher/src/main/jni/egl_bridge.c

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <GL/osmesa.h>
1414
#include "ctxbridges/osmesa_loader.h"
1515
#include "driver_helper/nsbypass.h"
16+
#include <android/log.h>
1617

1718
#ifdef GLES_TEST
1819
#include <GLES2/gl2.h>
@@ -272,7 +273,7 @@ EXTERNAL_API void pojavSwapInterval(int interval) {
272273
br_swap_interval(interval);
273274
}
274275

275-
EXTERNAL_API void* pojavCreateCursor(GLFWimage* image, int xhot, int yhot) {
276+
EXTERNAL_API LinkedListNode* pojavCreateCursor(GLFWimage* image, int xhot, int yhot) {
276277
if(image == NULL) {
277278
printf("Passed image is null!\n");
278279
return NULL;
@@ -294,43 +295,25 @@ EXTERNAL_API void* pojavCreateCursor(GLFWimage* image, int xhot, int yhot) {
294295
(*env)->DeleteLocalRef(env, cursor);
295296
(*env)->DeleteLocalRef(env, buffer);
296297

297-
linkedlist_append(pojav_environ->cursors, globalCursor);
298-
return globalCursor;
298+
return linkedlist_append(pojav_environ->cursors, globalCursor);
299299
}
300300

301-
EXTERNAL_API void pojavSetCursor(__attribute__((unused)) void* window, jobject cursor) {
301+
EXTERNAL_API void pojavSetCursor(__attribute__((unused)) void* window, LinkedListNode* cursor) {
302+
jobject value = NULL;
303+
if(cursor) value = cursor->value;
302304
TRY_ATTACH_ENV(env, pojav_environ->dalvikJavaVMPtr, "failed to attach env from pojavSetCursor!\n", return;);
303-
(*env)->CallStaticVoidMethod(env, pojav_environ->bridgeClazz, pojav_environ->method_setCursor, cursor);
305+
(*env)->CallStaticVoidMethod(env, pojav_environ->bridgeClazz, pojav_environ->method_setCursor, value);
304306
}
305307

306-
EXTERNAL_API void pojavDestroyCursor(jobject cursor) {
307-
if(cursor == NULL) {
308+
EXTERNAL_API void pojavDestroyCursor(LinkedListNode* cursor) {
309+
if(cursor == NULL || cursor->value == NULL) {
308310
printf("Passed cursor to pojavDestroyCursor is null!\n");
309311
return;
310312
}
311313

312314
TRY_ATTACH_ENV(env, pojav_environ->dalvikJavaVMPtr, "failed to attach env from pojavDestroyCursor!\n", return;);
313-
(*env)->CallStaticVoidMethod(env, pojav_environ->bridgeClazz, pojav_environ->method_removeCursor, cursor);
315+
(*env)->CallStaticVoidMethod(env, pojav_environ->bridgeClazz, pojav_environ->method_removeCursor, cursor->value);
314316

315-
LinkedListNode* current = pojav_environ->cursors->first;
316-
LinkedListNode* prev = NULL;
317-
318-
while (current) {
319-
if (current->value == cursor) {
320-
if (prev == NULL) {
321-
pojav_environ->cursors->first = current->next;
322-
} else {
323-
prev->next = current->next;
324-
}
325-
if (current == pojav_environ->cursors->last) {
326-
pojav_environ->cursors->last = prev;
327-
}
328-
329-
(*env)->DeleteGlobalRef(env, current->value);
330-
free(current);
331-
break;
332-
}
333-
prev = current;
334-
current = current->next;
335-
}
317+
(*env)->DeleteGlobalRef(env, cursor->value);
318+
linkedlist_remove(pojav_environ->cursors, cursor);
336319
}

app_pojavlauncher/src/main/jni/linkedlist.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,36 @@ LinkedList* linkedlist_init() {
1212
return list;
1313
}
1414

15-
void linkedlist_append(LinkedList* list, void* value) {
15+
LinkedListNode *linkedlist_append(LinkedList* list, void* value) {
1616
LinkedListNode* node = malloc(sizeof(LinkedListNode));
1717
node->value = value;
1818
node->next = NULL;
19+
node->prev = list->last;
1920

2021
if (list->last) {
2122
list->last->next = node;
2223
} else {
2324
list->first = node;
2425
}
2526
list->last = node;
27+
28+
return node;
29+
}
30+
31+
void linkedlist_remove(LinkedList* list, LinkedListNode* node) {
32+
if (node->prev) {
33+
node->prev->next = node->next;
34+
} else {
35+
list->first = node->next;
36+
}
37+
38+
if (node->next) {
39+
node->next->prev = node->prev;
40+
} else {
41+
list->last = node->prev;
42+
}
43+
44+
node->next = NULL;
45+
node->prev = NULL;
46+
free(node);
2647
}

app_pojavlauncher/src/main/jni/linkedlist.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
typedef struct LinkedListNode {
99
void* value;
1010
struct LinkedListNode* next;
11+
struct LinkedListNode* prev;
1112
} LinkedListNode;
1213

1314
typedef struct {
@@ -16,7 +17,7 @@ typedef struct {
1617
} LinkedList;
1718

1819
LinkedList* linkedlist_init();
19-
void linkedlist_append(LinkedList* list, void* value);
20-
void linkedlist_free(LinkedList* list);
20+
LinkedListNode *linkedlist_append(LinkedList* list, void* value);
21+
void linkedlist_remove(LinkedList* list, LinkedListNode* node);
2122

2223
#endif //POJAVLAUNCHER_LINKEDLIST_H

0 commit comments

Comments
 (0)