mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-12 17:17:09 -04:00
WIP on avoiding calling Window_SetRenderScreen so often
This commit is contained in:
parent
7d3bdb7f53
commit
e91cc7cfd8
28
src/Gui.c
28
src/Gui.c
@ -143,16 +143,12 @@ void Gui_LayoutAll(void) {
|
||||
struct Screen* s;
|
||||
int i;
|
||||
|
||||
enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN);
|
||||
|
||||
for (i = 0; i < Gui.ScreensCount; i++)
|
||||
{
|
||||
s = Gui_Screens[i];
|
||||
s->VTABLE->Layout(s);
|
||||
s->dirty = true;
|
||||
}
|
||||
|
||||
Window_3DS_SetRenderScreen(scr);
|
||||
}
|
||||
|
||||
void Gui_RefreshAll(void) {
|
||||
@ -162,14 +158,10 @@ void Gui_RefreshAll(void) {
|
||||
}
|
||||
|
||||
void Gui_Refresh(struct Screen* s) {
|
||||
enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN);
|
||||
|
||||
s->VTABLE->ContextLost(s);
|
||||
s->VTABLE->ContextRecreated(s);
|
||||
s->VTABLE->Layout(s);
|
||||
s->dirty = true;
|
||||
|
||||
Window_3DS_SetRenderScreen(scr);
|
||||
}
|
||||
|
||||
static void Gui_AddCore(struct Screen* s, int priority) {
|
||||
@ -193,12 +185,12 @@ static void Gui_AddCore(struct Screen* s, int priority) {
|
||||
priorities[i] = priority;
|
||||
Gui.ScreensCount++;
|
||||
|
||||
enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN);
|
||||
|
||||
s->dirty = true;
|
||||
s->VTABLE->Init(s);
|
||||
s->VTABLE->ContextRecreated(s);
|
||||
s->VTABLE->Layout(s);
|
||||
|
||||
enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN);
|
||||
|
||||
/* for selecting active button etc */
|
||||
for (i = 0; i < Pointers_Count; i++)
|
||||
@ -409,8 +401,18 @@ void Widget_SetLocation(void* widget, cc_uint8 horAnchor, cc_uint8 verAnchor, in
|
||||
|
||||
void Widget_CalcPosition(void* widget) {
|
||||
struct Widget* w = (struct Widget*)widget;
|
||||
w->x = Gui_CalcPos(w->horAnchor, w->xOffset, w->width , Window_Main.Width );
|
||||
w->y = Gui_CalcPos(w->verAnchor, w->yOffset, w->height, Window_Main.Height);
|
||||
int windowWidth, windowHeight;
|
||||
|
||||
#ifdef CC_BUILD_DUALSCREEN
|
||||
windowWidth = (w->flags & WIDGET_FLAG_MAINSCREEN) ? Window_Main.Width : Window_Alt.Width;
|
||||
windowHeight = (w->flags & WIDGET_FLAG_MAINSCREEN) ? Window_Main.Height : Window_Alt.Height;
|
||||
#else
|
||||
windowWidth = Window_Main.Width;
|
||||
windowHeight = Window_Main.Height;
|
||||
#endif
|
||||
|
||||
w->x = Gui_CalcPos(w->horAnchor, w->xOffset, w->width , windowWidth );
|
||||
w->y = Gui_CalcPos(w->verAnchor, w->yOffset, w->height, windowHeight);
|
||||
}
|
||||
|
||||
void Widget_Reset(void* widget) {
|
||||
@ -689,4 +691,4 @@ struct IGameComponent Gui_Component = {
|
||||
OnReset, /* Reset */
|
||||
NULL, /* OnNewMap */
|
||||
NULL, /* OnNewMapLoaded */
|
||||
};
|
||||
};
|
10
src/Gui.h
10
src/Gui.h
@ -173,6 +173,14 @@ struct WidgetVTABLE {
|
||||
#define WIDGET_FLAG_DISABLED 0x01
|
||||
/* Whether a widget can be selected via up/down */
|
||||
#define WIDGET_FLAG_SELECTABLE 0x02
|
||||
/* Whether for dual screen builds, this widget still appears on */
|
||||
/* the main game screen instead of the dedicated UI screen */
|
||||
#define WIDGET_FLAG_MAINSCREEN 0x04
|
||||
#ifdef CC_BUILD_DUALSCREEN
|
||||
#define Window_UI Window_Alt
|
||||
#else
|
||||
#define Window_UI Window_Main
|
||||
#endif
|
||||
|
||||
/* Represents an individual 2D gui component. */
|
||||
struct Widget { Widget_Body };
|
||||
@ -270,4 +278,4 @@ void TextAtlas_AddInt(struct TextAtlas* atlas, int value, struct VertexTextured*
|
||||
#define Widget_BuildMesh(widget, vertices) (widget)->VTABLE->BuildMesh(widget, vertices)
|
||||
#define Widget_Render2(widget, offset) (widget)->VTABLE->Render2(widget, offset)
|
||||
#define Widget_Layout(widget) (widget)->VTABLE->Reposition(widget)
|
||||
#endif
|
||||
#endif
|
16
src/Menus.c
16
src/Menus.c
@ -994,13 +994,13 @@ static void EditHotkeyScreen_Update(void* screen, double delta) {
|
||||
static void EditHotkeyScreen_Layout(void* screen) {
|
||||
struct EditHotkeyScreen* s = (struct EditHotkeyScreen*)screen;
|
||||
s->barWidth = Display_ScaleX(500);
|
||||
s->barX = Gui_CalcPos(ANCHOR_CENTRE, 0, s->barWidth, Window_Main.Width);
|
||||
s->barX = Gui_CalcPos(ANCHOR_CENTRE, 0, s->barWidth, Window_UI.Width);
|
||||
s->barHeight = Display_ScaleY(2);
|
||||
|
||||
s->barY[0] = Gui_CalcPos(ANCHOR_CENTRE, Display_ScaleY(-65),
|
||||
s->barHeight, Window_Main.Height);
|
||||
s->barHeight, Window_UI.Height);
|
||||
s->barY[1] = Gui_CalcPos(ANCHOR_CENTRE, Display_ScaleY( 45),
|
||||
s->barHeight, Window_Main.Height);
|
||||
s->barHeight, Window_UI.Height);
|
||||
|
||||
Widget_SetLocation(&s->btns[0], ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -150);
|
||||
Widget_SetLocation(&s->btns[1], ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -100);
|
||||
@ -2458,7 +2458,7 @@ static void MenuOptionsScreen_LayoutExtHelp(struct MenuOptionsScreen* s) {
|
||||
Widget_SetLocation(&s->extHelp, ANCHOR_MIN, ANCHOR_CENTRE_MIN, 0, 100);
|
||||
/* If use centre align above, then each line in extended help gets */
|
||||
/* centered aligned separately - which is not the desired behaviour. */
|
||||
s->extHelp.xOffset = Window_Main.Width / 2 - s->extHelp.width / 2;
|
||||
s->extHelp.xOffset = Window_UI.Width / 2 - s->extHelp.width / 2;
|
||||
Widget_Layout(&s->extHelp);
|
||||
}
|
||||
|
||||
@ -3551,12 +3551,12 @@ static void TexIdsOverlay_Layout(void* screen) {
|
||||
struct TexIdsOverlay* s = (struct TexIdsOverlay*)screen;
|
||||
int size;
|
||||
|
||||
size = Window_Main.Height / ATLAS2D_TILES_PER_ROW;
|
||||
size = Window_UI.Height / ATLAS2D_TILES_PER_ROW;
|
||||
size = (size / 8) * 8;
|
||||
Math_Clamp(size, 8, 40);
|
||||
|
||||
s->xOffset = Gui_CalcPos(ANCHOR_CENTRE, 0, size * Atlas2D.RowsCount, Window_Main.Width);
|
||||
s->yOffset = Gui_CalcPos(ANCHOR_CENTRE, 0, size * ATLAS2D_TILES_PER_ROW, Window_Main.Height);
|
||||
s->xOffset = Gui_CalcPos(ANCHOR_CENTRE, 0, size * Atlas2D.RowsCount, Window_UI.Width);
|
||||
s->yOffset = Gui_CalcPos(ANCHOR_CENTRE, 0, size * ATLAS2D_TILES_PER_ROW, Window_UI.Height);
|
||||
s->tileSize = size;
|
||||
|
||||
/* Can't use vertical centreing here */
|
||||
@ -4401,4 +4401,4 @@ void TouchMoreScreen_Show(void) {
|
||||
|
||||
Gui_Add((struct Screen*)s, GUI_PRIORITY_TOUCHMORE);
|
||||
}
|
||||
#endif
|
||||
#endif
|
@ -202,11 +202,9 @@ static void HUDScreen_ContextRecreated(void* screen) {
|
||||
}
|
||||
|
||||
static int HUDScreen_LayoutHotbar(void) {
|
||||
enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN);
|
||||
struct HUDScreen* s = &HUDScreen_Instance;
|
||||
s->hotbar.scale = Gui_GetHotbarScale();
|
||||
Widget_Layout(&s->hotbar);
|
||||
Window_3DS_SetRenderScreen(scr);
|
||||
return s->hotbar.height;
|
||||
}
|
||||
|
||||
@ -294,6 +292,10 @@ static void HUDScreen_Init(void* screen) {
|
||||
HotbarWidget_Create(&s->hotbar);
|
||||
TextWidget_Init(&s->line1);
|
||||
TextWidget_Init(&s->line2);
|
||||
|
||||
s->hotbar.flags |= WIDGET_FLAG_MAINSCREEN;
|
||||
s->line1.flags |= WIDGET_FLAG_MAINSCREEN;
|
||||
s->line2.flags |= WIDGET_FLAG_MAINSCREEN;
|
||||
|
||||
Event_Register_(&UserEvents.HacksStateChanged, s, HUDScreen_HacksChanged);
|
||||
Event_Register_(&TextureEvents.AtlasChanged, s, HUDScreen_NeedRedrawing);
|
||||
@ -339,17 +341,14 @@ static void HUDScreen_BuildCrosshairsMesh(struct VertexTextured** ptr) {
|
||||
/* Only top quarter of icons.png is used */
|
||||
static struct Texture tex = { 0, Tex_Rect(0,0,0,0), Tex_UV(0.0f,0.0f, 15/256.0f,15/64.0f) };
|
||||
int extent;
|
||||
enum Screen3DS scr = Window_3DS_SetRenderScreen(TOP_SCREEN);
|
||||
|
||||
extent = (int)(CH_EXTENT * Gui_Scale(Window_Main.Height / 480.0f));
|
||||
tex.x = (Window_Main.Width / 2) - extent;
|
||||
tex.y = (Window_Main.Height / 2) - extent;
|
||||
extent = (int)(CH_EXTENT * Gui_Scale(Window_UI.Height / 480.0f));
|
||||
tex.x = (Window_UI.Width / 2) - extent;
|
||||
tex.y = (Window_UI.Height / 2) - extent;
|
||||
|
||||
tex.Width = extent * 2;
|
||||
tex.Height = extent * 2;
|
||||
Gfx_Make2DQuad(&tex, PACKEDCOL_WHITE, ptr);
|
||||
|
||||
Window_3DS_SetRenderScreen(scr);
|
||||
}
|
||||
|
||||
static void HUDScreen_BuildMesh(void* screen) {
|
||||
@ -504,8 +503,6 @@ static void TabListOverlay_Layout(void* screen) {
|
||||
int i, x, y, width = 0, height = 0;
|
||||
int columns = Math_CeilDiv(s->usedCount, LIST_NAMES_PER_COLUMN);
|
||||
|
||||
enum Screen3DS scr = Window_3DS_SetRenderScreen(TOP_SCREEN);
|
||||
|
||||
for (i = 0; i < columns; i++)
|
||||
{
|
||||
width += TabListOverlay_GetColumnWidth(s, i);
|
||||
@ -521,9 +518,9 @@ static void TabListOverlay_Layout(void* screen) {
|
||||
width += paddingX * 2;
|
||||
height += paddingY * 2;
|
||||
|
||||
y = Window_Main.Height / 4 - height / 2;
|
||||
s->x = Gui_CalcPos(ANCHOR_CENTRE, 0, width , Window_Main.Width );
|
||||
s->y = Gui_CalcPos(ANCHOR_CENTRE, -max(0, y), height, Window_Main.Height);
|
||||
y = Window_UI.Height / 4 - height / 2;
|
||||
s->x = Gui_CalcPos(ANCHOR_CENTRE, 0, width , Window_UI.Width );
|
||||
s->y = Gui_CalcPos(ANCHOR_CENTRE, -max(0, y), height, Window_UI.Height);
|
||||
|
||||
x = s->x + paddingX;
|
||||
y = s->y + paddingY;
|
||||
@ -542,8 +539,6 @@ static void TabListOverlay_Layout(void* screen) {
|
||||
s->title.horAnchor = ANCHOR_CENTRE;
|
||||
s->title.yOffset = s->y + paddingY / 2;
|
||||
Widget_Layout(&s->title);
|
||||
|
||||
Window_3DS_SetRenderScreen(scr);
|
||||
}
|
||||
|
||||
static void TabListOverlay_AddName(struct TabListOverlay* s, EntityID id, int index) {
|
||||
@ -906,11 +901,11 @@ static void ChatScreen_UpdateChatYOffsets(struct ChatScreen* s) {
|
||||
|
||||
y = min(s->input.base.y, Gui_HUD->hotbar.y);
|
||||
y -= s->input.base.yOffset; /* add some padding */
|
||||
s->altText.yOffset = Window_Main.Height - y;
|
||||
s->altText.yOffset = Window_UI.Height - y;
|
||||
Widget_Layout(&s->altText);
|
||||
|
||||
pad = s->altText.active ? 5 : 10;
|
||||
s->clientStatus.yOffset = Window_Main.Height - s->altText.y + pad;
|
||||
s->clientStatus.yOffset = Window_UI.Height - s->altText.y + pad;
|
||||
Widget_Layout(&s->clientStatus);
|
||||
s->chat.yOffset = s->clientStatus.yOffset + s->clientStatus.height;
|
||||
Widget_Layout(&s->chat);
|
||||
@ -1239,8 +1234,6 @@ static void ChatScreen_BuildMesh(void* screen) {
|
||||
}
|
||||
|
||||
static void ChatScreen_Layout(void* screen) {
|
||||
enum Screen3DS scr = Window_3DS_SetRenderScreen(TOP_SCREEN);
|
||||
|
||||
struct ChatScreen* s = (struct ChatScreen*)screen;
|
||||
if (ChatScreen_ChatUpdateFont(s)) ChatScreen_Redraw(s);
|
||||
|
||||
@ -1260,19 +1253,17 @@ static void ChatScreen_Layout(void* screen) {
|
||||
Widget_Layout(&s->bottomRight);
|
||||
|
||||
Widget_SetLocation(&s->announcement, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 0);
|
||||
s->announcement.yOffset = -Window_Main.Height / 4;
|
||||
s->announcement.yOffset = -Window_UI.Height / 4;
|
||||
Widget_Layout(&s->announcement);
|
||||
|
||||
Widget_SetLocation(&s->bigAnnouncement, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 0);
|
||||
s->bigAnnouncement.yOffset = -Window_Main.Height / 16;
|
||||
s->bigAnnouncement.yOffset = -Window_UI.Height / 16;
|
||||
Widget_Layout(&s->bigAnnouncement);
|
||||
|
||||
Widget_SetLocation(&s->smallAnnouncement, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 0);
|
||||
s->smallAnnouncement.yOffset = Window_Main.Height / 20;
|
||||
s->smallAnnouncement.yOffset = Window_UI.Height / 20;
|
||||
Widget_Layout(&s->smallAnnouncement);
|
||||
|
||||
Window_3DS_SetRenderScreen(scr);
|
||||
|
||||
#ifdef CC_BUILD_TOUCH
|
||||
if (Window_Main.SoftKeyboard == SOFT_KEYBOARD_SHIFT) {
|
||||
Widget_SetLocation(&s->send, ANCHOR_MAX, ANCHOR_MAX, 10, 60);
|
||||
@ -1471,6 +1462,19 @@ static void ChatScreen_Init(void* screen) {
|
||||
Event_Register_(&ChatEvents.ColCodeChanged, s, ChatScreen_ColCodeChanged);
|
||||
|
||||
s->maxVertices = ChatScreen_CalcMaxVertices(s);
|
||||
|
||||
/* For dual screen builds, chat is still rendered on the main game screen */
|
||||
s->input.base.flags |= WIDGET_FLAG_MAINSCREEN;
|
||||
s->altText.flags |= WIDGET_FLAG_MAINSCREEN;
|
||||
s->status.flags |= WIDGET_FLAG_MAINSCREEN;
|
||||
s->bottomRight.flags |= WIDGET_FLAG_MAINSCREEN;
|
||||
s->chat.flags |= WIDGET_FLAG_MAINSCREEN;
|
||||
s->clientStatus.flags |= WIDGET_FLAG_MAINSCREEN;
|
||||
|
||||
s->bottomRight.flags |= WIDGET_FLAG_MAINSCREEN;
|
||||
s->announcement.flags |= WIDGET_FLAG_MAINSCREEN;
|
||||
s->bigAnnouncement.flags |= WIDGET_FLAG_MAINSCREEN;
|
||||
s->smallAnnouncement.flags |= WIDGET_FLAG_MAINSCREEN;
|
||||
|
||||
#ifdef CC_BUILD_TOUCH
|
||||
ButtonWidget_Init(&s->send, 100, NULL);
|
||||
@ -1802,7 +1806,7 @@ static void LoadingScreen_SetMessage(struct LoadingScreen* s) {
|
||||
}
|
||||
|
||||
static void LoadingScreen_CalcMaxVertices(struct LoadingScreen* s) {
|
||||
s->rows = Math_CeilDiv(Window_Main.Height, LOADING_TILE_SIZE);
|
||||
s->rows = Math_CeilDiv(Window_UI.Height, LOADING_TILE_SIZE);
|
||||
s->maxVertices = Screen_CalcDefaultMaxVertices(s) + s->rows * 4;
|
||||
}
|
||||
|
||||
@ -1814,9 +1818,9 @@ static void LoadingScreen_Layout(void* screen) {
|
||||
y = Display_ScaleY(34);
|
||||
|
||||
s->progWidth = Display_ScaleX(200);
|
||||
s->progX = Gui_CalcPos(ANCHOR_CENTRE, 0, s->progWidth, Window_Main.Width);
|
||||
s->progX = Gui_CalcPos(ANCHOR_CENTRE, 0, s->progWidth, Window_UI.Width);
|
||||
s->progHeight = Display_ScaleY(4);
|
||||
s->progY = Gui_CalcPos(ANCHOR_CENTRE, y, s->progHeight, Window_Main.Height);
|
||||
s->progY = Gui_CalcPos(ANCHOR_CENTRE, y, s->progHeight, Window_UI.Height);
|
||||
|
||||
oldRows = s->rows;
|
||||
LoadingScreen_CalcMaxVertices(s);
|
||||
@ -1850,9 +1854,9 @@ static void LoadingScreen_BuildMesh(void* screen) {
|
||||
ptr = &data;
|
||||
|
||||
loc = Block_Tex(BLOCK_DIRT, FACE_YMAX);
|
||||
Tex_SetRect(tex, 0,0, Window_Main.Width,LOADING_TILE_SIZE);
|
||||
Tex_SetRect(tex, 0,0, Window_UI.Width,LOADING_TILE_SIZE);
|
||||
tex.uv = Atlas1D_TexRec(loc, 1, &atlasIndex);
|
||||
tex.uv.U2 = (float)Window_Main.Width / LOADING_TILE_SIZE;
|
||||
tex.uv.U2 = (float)Window_UI.Width / LOADING_TILE_SIZE;
|
||||
|
||||
for (i = 0; i < s->rows; i++) {
|
||||
tex.y = i * LOADING_TILE_SIZE;
|
||||
@ -2460,4 +2464,4 @@ void TouchScreen_Show(void) {
|
||||
if (!Input_TouchMode) return;
|
||||
Gui_Add((struct Screen*)s, GUI_PRIORITY_TOUCH);
|
||||
}
|
||||
#endif
|
||||
#endif
|
@ -2792,4 +2792,4 @@ void ThumbstickWidget_GetMovement(struct ThumbstickWidget* w, float* xMoving, fl
|
||||
if (dirs & DIR_YMIN) *zMoving -= 1;
|
||||
if (dirs & DIR_YMAX) *zMoving += 1;
|
||||
}
|
||||
#endif
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user