-----------------------------------------------------------------
Following the little discussion I've started in the announcement channel, I wanted to just show you the part of the code that lags. It takes 20 ms to process in 6.20, and more than 130ms in 6.21. Also note that in 6.21, the CPU fan goes crazy, and I cannot ALT-F4 the game.
My game is drawn on a canvas, and I have implemented "views" which are panels that can be manipulated independently from each other; but the whole screen (terminal) is always updated in full (because one view can affect another one). If you look at screenshots of my game from my signature, you'll see that it doesn't need fancy graphics, that's why I chose to only use canvases (and it's theoretically portable to SB).
Also, the "terminal" is an array of symbol, and each cell depends on the font size. If you increase the font size, everything gets bigger.
The part that is laggy:
Code: Select all
StartDrawing(CanvasOutput(#CANVAS_MAIN))
DrawingFont(FontID(#FONT_MAIN))
; Clear the terminal.
Box(0, 0, OutputWidth(), OutputHeight(), settings\default_colors\terminal_background)
If \shade_opacity > 0
DrawingMode(#PB_2DDrawing_AlphaBlend)
Box(0, 0, OutputWidth(), OutputHeight(), RGBA(0, 0, 0, \shade_opacity))
DrawingMode(#PB_2DDrawing_Default)
EndIf
ForEach \views()
If \views()\visible = #True
DrawView(\views())
EndIf
Next
Code: Select all
Procedure DrawView(*view._View) : With *view
Define fw = settings\font\width
Define fh = settings\font\height
Define width_px = \size\width * fw
Define height_px = \size\height * fh
Define origin_x_px = Riva::GetViewPosXPx(*view)
Define origin_y_px = Riva::GetViewPosYPx(*view)
Define view_bg
Define font_alt_used.b
; Background.
If \background_color = #DEFAULT
view_bg = settings\default_colors\view_background
Else
view_bg = \background_color
EndIf
; Clear the view, either with an image or the view background colour.
If \image_alias$ = ""
If \frame_rounded_px = 0
Box(origin_x_px, origin_y_px, width_px, height_px, view_bg)
Else
RoundBox(origin_x_px, origin_y_px, width_px, height_px, \frame_rounded_px, \frame_rounded_px, view_bg)
EndIf
Else
Define image = terminal\image_store(\image_alias$)\handle
If *view\image_resize = #True And (ImageWidth(image) <> width_px Or ImageHeight(image) <> height_px)
ResizeImage(image, width_px, height_px, terminal\image_store()\resize_mode)
EndIf
DrawAlphaImage(ImageID(image), origin_x_px, origin_y_px, \image_opacity)
EndIf
Define x, y
Define pos._XY
Define *cell._Cell
If \transparent_control_bg = #True
DrawingMode(#PB_2DDrawing_Transparent)
EndIf
For y = 0 To ArraySize(\pages()\grid(), 2)
For x = 0 To ArraySize(\pages()\grid(), 1)
*cell = \pages()\grid(x, y)
If *cell\char$ <> ""
pos\x = (x + Riva::GetViewPosX(*view)) * fw
pos\y = (y + Riva::GetViewPosY(*view)) * fh
If x = \margins\left And *cell\char$ = "─"
; Draw a separator.
; FIXME Will also draw a separator if the first character of any line of any control is "─".
Define color
If *view\frame_color > -1
color = *view\frame_color
Else
If *view = GetActiveView()
color = settings\default_colors\frame_active
Else
color = settings\default_colors\frame_inactive
EndIf
EndIf
Define padding_left = *cell\color_fg
Define padding_right = *cell\color_bg
LineXY(pos\x - (\margins\left * fw) + (padding_left * fw), pos\y + fh/2, (Riva::GetViewPosX(*view) + \size\width - padding_right) * fw - 1, pos\y + fh/2, color)
Continue
EndIf
; EXPERIMENTAL Alternative font.
If font_alt_used = #True And *cell\use_alt_font = #False
DrawingFont(FontID(#FONT_MAIN))
font_alt_used = #False
ElseIf *cell\use_alt_font = #True And font_alt_used = #False
DrawingFont(FontID(#FONT_ALT))
font_alt_used = #True
EndIf
Define cf = *cell\color_fg
Define cb = *cell\color_bg
DrawText(pos\x, pos\y, *cell\char$, cf, cb)
If settings\misc\shadowing_amount > 0
DrawingMode(#PB_2DDrawing_AlphaBlend)
DrawText(pos\x - settings\misc\shadowing_offset, pos\y, *cell\char$, RGBA(Red(cf), Green(cf), Blue(cf), settings\misc\shadowing_amount), 0)
If \transparent_control_bg = #False
DrawingMode(#PB_2DDrawing_Default)
Else
DrawingMode(#PB_2DDrawing_Transparent)
EndIf
EndIf
If *cell\underlined = #True
LineXY(pos\x, pos\y + fh - 1, pos\x + fw - 1, pos\y + fh - 1, cf)
EndIf
EndIf
Next x
Next y
If *view\frame_visible = #True
DrawFrame(*view)
ElseIf ListSize(\pages()) > 1 And IsRequesterOpen() = #False ; Does not draw page numbers when a pop-up is opened.
DrawPaging(*view)
EndIf
; Shade opacity.
If *view\shade_opacity > 0
DrawingMode(#PB_2DDrawing_AlphaBlend)
If *view\shade_opacity_bg = #False
Box(origin_x_px, origin_y_px, width_px, height_px, RGBA(0, 0, 0, *view\shade_opacity))
Else
Box(origin_x_px, origin_y_px, width_px, height_px, RGBA(Red(view_bg), Green(view_bg), Blue(view_bg), *view\shade_opacity))
EndIf
DrawingMode(#PB_2DDrawing_Default)
EndIf
; DBG_DrawGrid(*view) ; DEBUG DrawGrid()
EndWith : EndProcedure
The problem here is I can comment everything out, and things will disappear, so I'm not really able to know what the cause is. If you only leave what is truly essential, which is DrawText(), then it still takes about 70ms to process. So there's definitely something internal that has changed.
I don't know what to do to further test this.