mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-22 13:37:22 +00:00
[client] all: remove ll_walk
and migrate over to ll_forEachNL
This commit is contained in:
parent
b99e1ea38e
commit
1851002fc1
@ -36,7 +36,6 @@ struct ll
|
|||||||
{
|
{
|
||||||
struct ll_item * head;
|
struct ll_item * head;
|
||||||
struct ll_item * tail;
|
struct ll_item * tail;
|
||||||
struct ll_item * pos;
|
|
||||||
unsigned int count;
|
unsigned int count;
|
||||||
LG_Lock lock;
|
LG_Lock lock;
|
||||||
};
|
};
|
||||||
@ -48,8 +47,6 @@ bool ll_shift (struct ll * list, void ** data);
|
|||||||
bool ll_peek_head(struct ll * list, void ** data);
|
bool ll_peek_head(struct ll * list, void ** data);
|
||||||
bool ll_peek_tail(struct ll * list, void ** data);
|
bool ll_peek_tail(struct ll * list, void ** data);
|
||||||
|
|
||||||
bool ll_walk (struct ll * list, void ** data);
|
|
||||||
|
|
||||||
#define ll_lock(ll) LG_LOCK((ll)->lock)
|
#define ll_lock(ll) LG_LOCK((ll)->lock)
|
||||||
#define ll_unlock(ll) LG_UNLOCK((ll)->lock)
|
#define ll_unlock(ll) LG_UNLOCK((ll)->lock)
|
||||||
|
|
||||||
@ -65,13 +62,6 @@ static inline unsigned int ll_count(struct ll * list)
|
|||||||
return list->count;
|
return list->count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void ll_reset (struct ll * list)
|
|
||||||
{
|
|
||||||
LG_LOCK(list->lock);
|
|
||||||
list->pos = NULL;
|
|
||||||
LG_UNLOCK(list->lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void ll_removeNL(struct ll * list, struct ll_item * item)
|
static inline void ll_removeNL(struct ll * list, struct ll_item * item)
|
||||||
{
|
{
|
||||||
--list->count;
|
--list->count;
|
||||||
@ -87,8 +77,6 @@ static inline void ll_removeNL(struct ll * list, struct ll_item * item)
|
|||||||
|
|
||||||
if (item->next)
|
if (item->next)
|
||||||
item->next->prev = item->prev;
|
item->next->prev = item->prev;
|
||||||
|
|
||||||
list->pos = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool ll_removeData(struct ll * list, void * match)
|
static inline bool ll_removeData(struct ll * list, void * match)
|
||||||
|
@ -164,18 +164,20 @@ void egl_modelRender(EGL_Model * model)
|
|||||||
|
|
||||||
/* buffer the verticies */
|
/* buffer the verticies */
|
||||||
struct FloatList * fl;
|
struct FloatList * fl;
|
||||||
for(ll_reset(model->verticies); ll_walk(model->verticies, (void **)&fl);)
|
ll_lock(model->verticies);
|
||||||
|
ll_forEachNL(model->verticies, item, fl)
|
||||||
{
|
{
|
||||||
glBufferSubData(GL_ARRAY_BUFFER, offset, sizeof(GLfloat) * fl->count * 3, fl->v);
|
glBufferSubData(GL_ARRAY_BUFFER, offset, sizeof(GLfloat) * fl->count * 3, fl->v);
|
||||||
offset += sizeof(GLfloat) * fl->count * 3;
|
offset += sizeof(GLfloat) * fl->count * 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* buffer the uvs */
|
/* buffer the uvs */
|
||||||
for(ll_reset(model->verticies); ll_walk(model->verticies, (void **)&fl);)
|
ll_forEachNL(model->verticies, item, fl)
|
||||||
{
|
{
|
||||||
glBufferSubData(GL_ARRAY_BUFFER, offset, sizeof(GLfloat) * fl->count * 2, fl->u);
|
glBufferSubData(GL_ARRAY_BUFFER, offset, sizeof(GLfloat) * fl->count * 2, fl->u);
|
||||||
offset += sizeof(GLfloat) * fl->count * 2;
|
offset += sizeof(GLfloat) * fl->count * 2;
|
||||||
}
|
}
|
||||||
|
ll_unlock(model->verticies);
|
||||||
|
|
||||||
/* set up vertex arrays in the VAO */
|
/* set up vertex arrays in the VAO */
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
@ -199,11 +201,13 @@ void egl_modelRender(EGL_Model * model)
|
|||||||
/* draw the arrays */
|
/* draw the arrays */
|
||||||
GLint offset = 0;
|
GLint offset = 0;
|
||||||
struct FloatList * fl;
|
struct FloatList * fl;
|
||||||
for(ll_reset(model->verticies); ll_walk(model->verticies, (void **)&fl);)
|
ll_lock(model->verticies);
|
||||||
|
ll_forEachNL(model->verticies, item, fl)
|
||||||
{
|
{
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, offset, fl->count);
|
glDrawArrays(GL_TRIANGLE_STRIP, offset, fl->count);
|
||||||
offset += fl->count;
|
offset += fl->count;
|
||||||
}
|
}
|
||||||
|
ll_unlock(model->verticies);
|
||||||
|
|
||||||
/* unbind and cleanup */
|
/* unbind and cleanup */
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
@ -66,15 +66,20 @@ bool app_isOverlayMode(void)
|
|||||||
if (g_state.overlayInput)
|
if (g_state.overlayInput)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
bool result = false;
|
||||||
struct Overlay * overlay;
|
struct Overlay * overlay;
|
||||||
for (ll_reset(g_state.overlays);
|
ll_lock(g_state.overlays);
|
||||||
ll_walk(g_state.overlays, (void **)&overlay); )
|
ll_forEachNL(g_state.overlays, item, overlay)
|
||||||
{
|
{
|
||||||
if (overlay->ops->needs_overlay && overlay->ops->needs_overlay(overlay))
|
if (overlay->ops->needs_overlay && overlay->ops->needs_overlay(overlay))
|
||||||
return true;
|
{
|
||||||
|
result = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
ll_unlock(g_state.overlays);
|
||||||
|
|
||||||
return false;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void app_updateCursorPos(double x, double y)
|
void app_updateCursorPos(double x, double y)
|
||||||
@ -725,8 +730,8 @@ void app_registerOverlay(const struct LG_OverlayOps * ops, const void * params)
|
|||||||
void app_initOverlays(void)
|
void app_initOverlays(void)
|
||||||
{
|
{
|
||||||
struct Overlay * overlay;
|
struct Overlay * overlay;
|
||||||
for (ll_reset(g_state.overlays);
|
ll_lock(g_state.overlays);
|
||||||
ll_walk(g_state.overlays, (void **)&overlay); )
|
ll_forEachNL(g_state.overlays, item, overlay)
|
||||||
{
|
{
|
||||||
if (!overlay->ops->init(&overlay->udata, overlay->params))
|
if (!overlay->ops->init(&overlay->udata, overlay->params))
|
||||||
{
|
{
|
||||||
@ -734,6 +739,7 @@ void app_initOverlays(void)
|
|||||||
overlay->ops = NULL;
|
overlay->ops = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ll_unlock(g_state.overlays);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void mergeRect(struct Rect * dest, const struct Rect * a, const struct Rect * b)
|
static inline void mergeRect(struct Rect * dest, const struct Rect * a, const struct Rect * b)
|
||||||
@ -778,22 +784,26 @@ static inline LG_DSPointer mapImGuiCursor(ImGuiMouseCursor cursor)
|
|||||||
|
|
||||||
bool app_overlayNeedsRender(void)
|
bool app_overlayNeedsRender(void)
|
||||||
{
|
{
|
||||||
struct Overlay * overlay;
|
|
||||||
|
|
||||||
if (app_isOverlayMode())
|
if (app_isOverlayMode())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
for (ll_reset(g_state.overlays);
|
bool result = false;
|
||||||
ll_walk(g_state.overlays, (void **)&overlay); )
|
struct Overlay * overlay;
|
||||||
|
ll_lock(g_state.overlays);
|
||||||
|
ll_forEachNL(g_state.overlays, item, overlay)
|
||||||
{
|
{
|
||||||
if (!overlay->ops->needs_render)
|
if (!overlay->ops->needs_render)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (overlay->ops->needs_render(overlay->udata, false))
|
if (overlay->ops->needs_render(overlay->udata, false))
|
||||||
return true;
|
{
|
||||||
|
result = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
ll_unlock(g_state.overlays);
|
||||||
|
|
||||||
return false;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_renderOverlay(struct Rect * rects, int maxRects)
|
int app_renderOverlay(struct Rect * rects, int maxRects)
|
||||||
@ -832,8 +842,8 @@ render_again:
|
|||||||
const bool msgModal = overlayMsg_modal();
|
const bool msgModal = overlayMsg_modal();
|
||||||
|
|
||||||
// render the overlays
|
// render the overlays
|
||||||
for (ll_reset(g_state.overlays);
|
ll_lock(g_state.overlays);
|
||||||
ll_walk(g_state.overlays, (void **)&overlay); )
|
ll_forEachNL(g_state.overlays, item, overlay)
|
||||||
{
|
{
|
||||||
if (msgModal && overlay->ops != &LGOverlayMsg)
|
if (msgModal && overlay->ops != &LGOverlayMsg)
|
||||||
continue;
|
continue;
|
||||||
@ -875,6 +885,7 @@ render_again:
|
|||||||
memcpy(overlay->lastRects, buffer, sizeof(struct Rect) * written);
|
memcpy(overlay->lastRects, buffer, sizeof(struct Rect) * written);
|
||||||
overlay->lastRectCount = written;
|
overlay->lastRectCount = written;
|
||||||
}
|
}
|
||||||
|
ll_unlock(g_state.overlays);
|
||||||
|
|
||||||
if (overlayMode)
|
if (overlayMode)
|
||||||
{
|
{
|
||||||
|
@ -29,7 +29,6 @@ struct ll * ll_new(void)
|
|||||||
struct ll * list = malloc(sizeof(*list));
|
struct ll * list = malloc(sizeof(*list));
|
||||||
list->head = NULL;
|
list->head = NULL;
|
||||||
list->tail = NULL;
|
list->tail = NULL;
|
||||||
list->pos = NULL;
|
|
||||||
list->count = 0;
|
list->count = 0;
|
||||||
LG_LOCK_INIT(list->lock);
|
LG_LOCK_INIT(list->lock);
|
||||||
return list;
|
return list;
|
||||||
@ -119,33 +118,3 @@ bool ll_peek_tail(struct ll * list, void ** data)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ll_walk(struct ll * list, void ** data)
|
|
||||||
{
|
|
||||||
LG_LOCK(list->lock);
|
|
||||||
|
|
||||||
if (!list->pos)
|
|
||||||
{
|
|
||||||
if (!list->head)
|
|
||||||
{
|
|
||||||
LG_UNLOCK(list->lock);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
list->pos = list->head;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!list->pos->next)
|
|
||||||
{
|
|
||||||
LG_UNLOCK(list->lock);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
list->pos = list->pos->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
*data = list->pos->data;
|
|
||||||
LG_UNLOCK(list->lock);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
@ -145,12 +145,13 @@ static bool tickTimerFn(void * unused)
|
|||||||
|
|
||||||
bool needsRender = false;
|
bool needsRender = false;
|
||||||
struct Overlay * overlay;
|
struct Overlay * overlay;
|
||||||
for (ll_reset(g_state.overlays);
|
ll_lock(g_state.overlays);
|
||||||
ll_walk(g_state.overlays, (void **)&overlay); )
|
ll_forEachNL(g_state.overlays, item, overlay)
|
||||||
{
|
{
|
||||||
if (overlay->ops->tick && overlay->ops->tick(overlay->udata, tickCount))
|
if (overlay->ops->tick && overlay->ops->tick(overlay->udata, tickCount))
|
||||||
needsRender = true;
|
needsRender = true;
|
||||||
}
|
}
|
||||||
|
ll_unlock(g_state.overlays);
|
||||||
|
|
||||||
if (needsRender)
|
if (needsRender)
|
||||||
app_invalidateWindow(false);
|
app_invalidateWindow(false);
|
||||||
|
@ -182,7 +182,8 @@ static int config_render(void * udata, bool interactive, struct Rect * windowRec
|
|||||||
|
|
||||||
if (igBeginTabItem("Settings", NULL, 0))
|
if (igBeginTabItem("Settings", NULL, 0))
|
||||||
{
|
{
|
||||||
for (ll_reset(cfg.callbacks); ll_walk(cfg.callbacks, (void **)&cb); )
|
ll_lock(cfg.callbacks);
|
||||||
|
ll_forEachNL(cfg.callbacks, item, cb)
|
||||||
{
|
{
|
||||||
if (!igCollapsingHeader_BoolPtr(cb->title, NULL, 0))
|
if (!igCollapsingHeader_BoolPtr(cb->title, NULL, 0))
|
||||||
continue;
|
continue;
|
||||||
@ -191,10 +192,12 @@ static int config_render(void * udata, bool interactive, struct Rect * windowRec
|
|||||||
cb->callback(cb->udata, &id);
|
cb->callback(cb->udata, &id);
|
||||||
igPopID();
|
igPopID();
|
||||||
}
|
}
|
||||||
|
ll_unlock(cfg.callbacks);
|
||||||
igEndTabItem();
|
igEndTabItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ll_reset(cfg.tabCallbacks); ll_walk(cfg.tabCallbacks, (void **)&cb); )
|
ll_lock(cfg.tabCallbacks);
|
||||||
|
ll_forEachNL(cfg.tabCallbacks, item, cb)
|
||||||
{
|
{
|
||||||
if (!igBeginTabItem(cb->title, NULL, 0))
|
if (!igBeginTabItem(cb->title, NULL, 0))
|
||||||
continue;
|
continue;
|
||||||
@ -204,6 +207,7 @@ static int config_render(void * udata, bool interactive, struct Rect * windowRec
|
|||||||
igPopID();
|
igPopID();
|
||||||
igEndTabItem();
|
igEndTabItem();
|
||||||
}
|
}
|
||||||
|
ll_unlock(cfg.tabCallbacks);
|
||||||
|
|
||||||
igEndTabBar();
|
igEndTabBar();
|
||||||
|
|
||||||
|
@ -53,11 +53,13 @@ static void configCallback(void * udata, int * id)
|
|||||||
igBeginTable("split", 2, 0, (ImVec2){}, 0);
|
igBeginTable("split", 2, 0, (ImVec2){}, 0);
|
||||||
|
|
||||||
GraphHandle graph;
|
GraphHandle graph;
|
||||||
for (ll_reset(gs.graphs); ll_walk(gs.graphs, (void **)&graph); )
|
ll_lock(gs.graphs);
|
||||||
|
ll_forEachNL(gs.graphs, item, graph)
|
||||||
{
|
{
|
||||||
igTableNextColumn();
|
igTableNextColumn();
|
||||||
igCheckbox(graph->name, &graph->enabled);
|
igCheckbox(graph->name, &graph->enabled);
|
||||||
}
|
}
|
||||||
|
ll_unlock(gs.graphs);
|
||||||
|
|
||||||
igEndTable();
|
igEndTable();
|
||||||
}
|
}
|
||||||
@ -127,9 +129,12 @@ static int graphs_render(void * udata, bool interactive,
|
|||||||
|
|
||||||
GraphHandle graph;
|
GraphHandle graph;
|
||||||
int graphCount = 0;
|
int graphCount = 0;
|
||||||
for (ll_reset(gs.graphs); ll_walk(gs.graphs, (void **)&graph); )
|
ll_lock(gs.graphs);
|
||||||
|
ll_forEachNL(gs.graphs, item, graph)
|
||||||
|
{
|
||||||
if (graph->enabled)
|
if (graph->enabled)
|
||||||
++graphCount;
|
++graphCount;
|
||||||
|
}
|
||||||
|
|
||||||
ImVec2 pos = {0.0f, 0.0f};
|
ImVec2 pos = {0.0f, 0.0f};
|
||||||
igSetNextWindowBgAlpha(0.4f);
|
igSetNextWindowBgAlpha(0.4f);
|
||||||
@ -152,7 +157,7 @@ static int graphs_render(void * udata, bool interactive,
|
|||||||
const float height = (winSize.y / graphCount)
|
const float height = (winSize.y / graphCount)
|
||||||
- igGetStyle()->ItemSpacing.y;
|
- igGetStyle()->ItemSpacing.y;
|
||||||
|
|
||||||
for (ll_reset(gs.graphs); ll_walk(gs.graphs, (void **)&graph); )
|
ll_forEachNL(gs.graphs, item, graph)
|
||||||
{
|
{
|
||||||
if (!graph->enabled)
|
if (!graph->enabled)
|
||||||
continue;
|
continue;
|
||||||
@ -182,6 +187,7 @@ static int graphs_render(void * udata, bool interactive,
|
|||||||
(ImVec2){ winSize.x, height },
|
(ImVec2){ winSize.x, height },
|
||||||
sizeof(float));
|
sizeof(float));
|
||||||
};
|
};
|
||||||
|
ll_unlock(gs.graphs);
|
||||||
|
|
||||||
overlayGetImGuiRect(windowRects);
|
overlayGetImGuiRect(windowRects);
|
||||||
igEnd();
|
igEnd();
|
||||||
@ -217,6 +223,8 @@ void overlayGraph_iterate(void (*callback)(GraphHandle handle, const char * name
|
|||||||
bool * enabled, void * udata), void * udata)
|
bool * enabled, void * udata), void * udata)
|
||||||
{
|
{
|
||||||
GraphHandle graph;
|
GraphHandle graph;
|
||||||
for (ll_reset(gs.graphs); ll_walk(gs.graphs, (void **)&graph); )
|
ll_lock(gs.graphs);
|
||||||
|
ll_forEachNL(gs.graphs, item, graph)
|
||||||
callback(graph, graph->name, &graph->enabled, udata);
|
callback(graph, graph->name, &graph->enabled, udata);
|
||||||
|
ll_unlock(gs.graphs);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user