mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-25 06:47:19 +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 * tail;
|
||||
struct ll_item * pos;
|
||||
unsigned int count;
|
||||
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_tail(struct ll * list, void ** data);
|
||||
|
||||
bool ll_walk (struct ll * list, void ** data);
|
||||
|
||||
#define ll_lock(ll) LG_LOCK((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;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
--list->count;
|
||||
@ -87,8 +77,6 @@ static inline void ll_removeNL(struct ll * list, struct ll_item * item)
|
||||
|
||||
if (item->next)
|
||||
item->next->prev = item->prev;
|
||||
|
||||
list->pos = NULL;
|
||||
}
|
||||
|
||||
static inline bool ll_removeData(struct ll * list, void * match)
|
||||
|
@ -164,18 +164,20 @@ void egl_modelRender(EGL_Model * model)
|
||||
|
||||
/* buffer the verticies */
|
||||
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);
|
||||
offset += sizeof(GLfloat) * fl->count * 3;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
offset += sizeof(GLfloat) * fl->count * 2;
|
||||
}
|
||||
ll_unlock(model->verticies);
|
||||
|
||||
/* set up vertex arrays in the VAO */
|
||||
glEnableVertexAttribArray(0);
|
||||
@ -199,11 +201,13 @@ void egl_modelRender(EGL_Model * model)
|
||||
/* draw the arrays */
|
||||
GLint offset = 0;
|
||||
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);
|
||||
offset += fl->count;
|
||||
}
|
||||
ll_unlock(model->verticies);
|
||||
|
||||
/* unbind and cleanup */
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
@ -66,15 +66,20 @@ bool app_isOverlayMode(void)
|
||||
if (g_state.overlayInput)
|
||||
return true;
|
||||
|
||||
bool result = false;
|
||||
struct Overlay * overlay;
|
||||
for (ll_reset(g_state.overlays);
|
||||
ll_walk(g_state.overlays, (void **)&overlay); )
|
||||
ll_lock(g_state.overlays);
|
||||
ll_forEachNL(g_state.overlays, item, 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)
|
||||
@ -725,8 +730,8 @@ void app_registerOverlay(const struct LG_OverlayOps * ops, const void * params)
|
||||
void app_initOverlays(void)
|
||||
{
|
||||
struct Overlay * overlay;
|
||||
for (ll_reset(g_state.overlays);
|
||||
ll_walk(g_state.overlays, (void **)&overlay); )
|
||||
ll_lock(g_state.overlays);
|
||||
ll_forEachNL(g_state.overlays, item, overlay)
|
||||
{
|
||||
if (!overlay->ops->init(&overlay->udata, overlay->params))
|
||||
{
|
||||
@ -734,6 +739,7 @@ void app_initOverlays(void)
|
||||
overlay->ops = NULL;
|
||||
}
|
||||
}
|
||||
ll_unlock(g_state.overlays);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
struct Overlay * overlay;
|
||||
|
||||
if (app_isOverlayMode())
|
||||
return true;
|
||||
|
||||
for (ll_reset(g_state.overlays);
|
||||
ll_walk(g_state.overlays, (void **)&overlay); )
|
||||
bool result = false;
|
||||
struct Overlay * overlay;
|
||||
ll_lock(g_state.overlays);
|
||||
ll_forEachNL(g_state.overlays, item, overlay)
|
||||
{
|
||||
if (!overlay->ops->needs_render)
|
||||
continue;
|
||||
|
||||
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)
|
||||
@ -832,8 +842,8 @@ render_again:
|
||||
const bool msgModal = overlayMsg_modal();
|
||||
|
||||
// render the overlays
|
||||
for (ll_reset(g_state.overlays);
|
||||
ll_walk(g_state.overlays, (void **)&overlay); )
|
||||
ll_lock(g_state.overlays);
|
||||
ll_forEachNL(g_state.overlays, item, overlay)
|
||||
{
|
||||
if (msgModal && overlay->ops != &LGOverlayMsg)
|
||||
continue;
|
||||
@ -875,6 +885,7 @@ render_again:
|
||||
memcpy(overlay->lastRects, buffer, sizeof(struct Rect) * written);
|
||||
overlay->lastRectCount = written;
|
||||
}
|
||||
ll_unlock(g_state.overlays);
|
||||
|
||||
if (overlayMode)
|
||||
{
|
||||
|
@ -29,7 +29,6 @@ struct ll * ll_new(void)
|
||||
struct ll * list = malloc(sizeof(*list));
|
||||
list->head = NULL;
|
||||
list->tail = NULL;
|
||||
list->pos = NULL;
|
||||
list->count = 0;
|
||||
LG_LOCK_INIT(list->lock);
|
||||
return list;
|
||||
@ -119,33 +118,3 @@ bool ll_peek_tail(struct ll * list, void ** data)
|
||||
|
||||
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;
|
||||
struct Overlay * overlay;
|
||||
for (ll_reset(g_state.overlays);
|
||||
ll_walk(g_state.overlays, (void **)&overlay); )
|
||||
ll_lock(g_state.overlays);
|
||||
ll_forEachNL(g_state.overlays, item, overlay)
|
||||
{
|
||||
if (overlay->ops->tick && overlay->ops->tick(overlay->udata, tickCount))
|
||||
needsRender = true;
|
||||
}
|
||||
ll_unlock(g_state.overlays);
|
||||
|
||||
if (needsRender)
|
||||
app_invalidateWindow(false);
|
||||
|
@ -182,7 +182,8 @@ static int config_render(void * udata, bool interactive, struct Rect * windowRec
|
||||
|
||||
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))
|
||||
continue;
|
||||
@ -191,10 +192,12 @@ static int config_render(void * udata, bool interactive, struct Rect * windowRec
|
||||
cb->callback(cb->udata, &id);
|
||||
igPopID();
|
||||
}
|
||||
ll_unlock(cfg.callbacks);
|
||||
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))
|
||||
continue;
|
||||
@ -204,6 +207,7 @@ static int config_render(void * udata, bool interactive, struct Rect * windowRec
|
||||
igPopID();
|
||||
igEndTabItem();
|
||||
}
|
||||
ll_unlock(cfg.tabCallbacks);
|
||||
|
||||
igEndTabBar();
|
||||
|
||||
|
@ -53,11 +53,13 @@ static void configCallback(void * udata, int * id)
|
||||
igBeginTable("split", 2, 0, (ImVec2){}, 0);
|
||||
|
||||
GraphHandle graph;
|
||||
for (ll_reset(gs.graphs); ll_walk(gs.graphs, (void **)&graph); )
|
||||
ll_lock(gs.graphs);
|
||||
ll_forEachNL(gs.graphs, item, graph)
|
||||
{
|
||||
igTableNextColumn();
|
||||
igCheckbox(graph->name, &graph->enabled);
|
||||
}
|
||||
ll_unlock(gs.graphs);
|
||||
|
||||
igEndTable();
|
||||
}
|
||||
@ -127,9 +129,12 @@ static int graphs_render(void * udata, bool interactive,
|
||||
|
||||
GraphHandle graph;
|
||||
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)
|
||||
++graphCount;
|
||||
}
|
||||
|
||||
ImVec2 pos = {0.0f, 0.0f};
|
||||
igSetNextWindowBgAlpha(0.4f);
|
||||
@ -152,7 +157,7 @@ static int graphs_render(void * udata, bool interactive,
|
||||
const float height = (winSize.y / graphCount)
|
||||
- igGetStyle()->ItemSpacing.y;
|
||||
|
||||
for (ll_reset(gs.graphs); ll_walk(gs.graphs, (void **)&graph); )
|
||||
ll_forEachNL(gs.graphs, item, graph)
|
||||
{
|
||||
if (!graph->enabled)
|
||||
continue;
|
||||
@ -182,6 +187,7 @@ static int graphs_render(void * udata, bool interactive,
|
||||
(ImVec2){ winSize.x, height },
|
||||
sizeof(float));
|
||||
};
|
||||
ll_unlock(gs.graphs);
|
||||
|
||||
overlayGetImGuiRect(windowRects);
|
||||
igEnd();
|
||||
@ -217,6 +223,8 @@ void overlayGraph_iterate(void (*callback)(GraphHandle handle, const char * name
|
||||
bool * enabled, void * udata), void * udata)
|
||||
{
|
||||
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);
|
||||
ll_unlock(gs.graphs);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user