Hi,
I've spent lots of time figuring out a good terminal system for my game. But I sort of found lately a memory leak. Seems every time I send a page clear, the framerates go down... (!) So I figured, maybe my code contains a leak. So I copy/pasted it here so I could get a visu idea of wether this is good practice coding or not.
Function clear_term_screen(page_num% = 9, chars% = 1, colors% = 1, attrs% = 1, fonts% = 1)
If page_num = 9 Then page_num = term\current_page
term\page[page_num]\cursor_col = 0
term\page[page_num]\cursor_row = 0
Local disp_end% = term\page[page_num]\cols * term\page[page_num]\rows - 4
Local t_color_clear% = term\page[page_num]\cls_t_color Shl 24 + term\page[page_num]\cls_t_color Shl 16 + term\page[page_num]\cls_t_color Shl 8 + term\page[page_num]\cls_t_color
Local b_color_clear% = term\page[page_num]\cls_b_color Shl 24 + term\page[page_num]\cls_b_color Shl 16 + term\page[page_num]\cls_b_color Shl 8 + term\page[page_num]\cls_b_color
Local char_clear% = term\page[page_num]\cls_char Shl 24 + term\page[page_num]\cls_char Shl 16 + term\page[page_num]\cls_char Shl 8 + term\page[page_num]\cls_char
Local attr_clear% = term\page[page_num]\cls_attr Shl 24 + term\page[page_num]\cls_attr Shl 16 + term\page[page_num]\cls_attr Shl 8 + term\page[page_num]\cls_attr
Local font_clear% = term\page[page_num]\cls_font Shl 24 + term\page[page_num]\cls_font Shl 16 + term\page[page_num]\cls_font Shl 8 + term\page[page_num]\cls_font
For disp% = 0 To disp_end Step 4
If colors Then PokeInt term\page[page_num]\t_color_table, disp, t_color_clear ;text color palette id's
If colors Then PokeInt term\page[page_num]\b_color_table, disp, b_color_clear ;background color palette id's
If chars Then PokeInt term\page[page_num]\text_table, disp, char_clear ;text
If attrs Then PokeInt term\page[page_num]\attr_table, disp, attr_clear ;character attributes
If fonts Then PokeInt term\page[page_num]\font_table, disp, font_clear ;font id's and sizes
Next
End Function
These tables, are initialized as follows:
term\page[page_num]\text_table = CreateBank(term\page[page_num]\cols * term\page[page_num]\rows)
term\page[page_num]\t_color_table = CreateBank(term\page[page_num]\cols * term\page[page_num]\rows)
term\page[page_num]\b_color_table = CreateBank(term\page[page_num]\cols * term\page[page_num]\rows)
term\page[page_num]\attr_table = CreateBank(term\page[page_num]\cols * term\page[page_num]\rows)
term\page[page_num]\font_table = CreateBank(term\page[page_num]\cols * term\page[page_num]\rows)
Any hint appreciated.
BTW, what happens is, when I start the terminal, I get decent 750+ fps. The first clear I do (cls command in console calls this function), as all of them, will blank the page nicely. Yet, the framerates go down. Every clear page I do drops the fps by 50, up to a point where I get around 400 fps, and then it stops dropping fps! So I'm rather intrigued on how this could be possible. There are no fancy tricks as to wether I change pages, or change some pointer/size values. It's just a simple and clean bank init routine really.
|