Skip to content

Commit b5a4d89

Browse files
author
Marek
committed
Speed optimization - try2
1 parent 731e1df commit b5a4d89

File tree

4 files changed

+48
-18
lines changed

4 files changed

+48
-18
lines changed

blit.c

+18-9
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ unsigned char *screen2;
2727
unsigned char *screen2_old;
2828
#endif
2929

30-
30+
char *line_buf;
3131

3232
/* attributes:
3333
lower 4 bits=foreground
@@ -46,6 +46,8 @@ unsigned char *screen2_a_old;
4646
/* requires SCREEN_X and SCREEN_Y as screen size */
4747
void init_blit(void)
4848
{
49+
line_buf=mem_alloc(SCREEN_X);
50+
if (!line_buf){ERROR("Not enough memory!\n");EXIT(1);}
4951
screen=mem_alloc(SCREEN_X*SCREEN_Y);
5052
if (!screen){ERROR("Not enough memory!\n");EXIT(1);}
5153
screen_a=mem_alloc(SCREEN_X*SCREEN_Y);
@@ -79,6 +81,7 @@ void init_blit(void)
7981

8082
void shutdown_blit(void)
8183
{
84+
mem_free(line_buf);
8285
mem_free(screen);
8386
mem_free(screen_a);
8487
mem_free(screen_old);
@@ -105,6 +108,8 @@ void clear_screen(void)
105108
void resize_screen(void)
106109
{
107110
c_get_size(&SCREEN_X,&SCREEN_Y);
111+
line_buf=mem_realloc(line_buf,SCREEN_X);
112+
if (!line_buf){ERROR("Not enough memory!\n");EXIT(1);}
108113
screen=mem_realloc(screen,SCREEN_X*SCREEN_Y);
109114
if (!screen){ERROR("Not enough memory!\n");EXIT(1);}
110115
screen_a=mem_realloc(screen_a,SCREEN_X*SCREEN_Y);
@@ -188,8 +193,8 @@ void print2screen(int x,int y,unsigned char color,char *message)
188193
#endif
189194
blit_screen(unsigned char ignore_bg)
190195
{
191-
int x,y;
192-
int yof;
196+
int x,y,s;
197+
int yof, off;
193198
unsigned char a;
194199
int changed=1;
195200
int status_flag;
@@ -228,9 +233,9 @@ blit_screen(unsigned char ignore_bg)
228233
changed=1;
229234

230235
a=(last_color^attribute);
231-
status_flag= (!!(a&7))| /* foreground */
232-
(((a>>3)&1)<<1)| /* foreground highlight */
233-
((!!((a>>4)&7))<<2); /* background */
236+
status_flag= !!(a&0x07) | /* foreground */
237+
((a&0x08)>>2) | /* foreground highlight */
238+
(!!(a&0x70)<<2);/* background */
234239

235240
switch(status_flag) /* what changed: */
236241
{
@@ -262,9 +267,13 @@ blit_screen(unsigned char ignore_bg)
262267
c_setcolor_3b_bg(attribute,attribute>>4);
263268
break;
264269
}
265-
266-
last_color=attribute;
267-
c_putc(sc[x+SCREEN_X*y]?sc[x+SCREEN_X*y]:32);
270+
/* draw bigger pieces to screen */
271+
line_buf[x] = sc[off = x + yof] ? : 32;
272+
for (s = x++; x < SCREEN_X && at[off = x + yof] == attribute &&
273+
at_old[off] == attribute_old; x++)
274+
line_buf[x] = sc[off] ? : 32;
275+
last_color = attribute;
276+
c_print_l(line_buf + s, x---s);
268277
}
269278
}
270279
memcpy(sc_old,sc,SCREEN_X*SCREEN_Y);

console.c

+20-6
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,11 @@ my_putc(char c)
5858

5959

6060
#ifdef HAVE_INLINE
61-
inline void
62-
#else
63-
void
61+
inline
6462
#endif
65-
my_print(char *str)
63+
void my_print_l(char *str, int l)
6664
{
6765
#ifdef SCREEN_BUFFERING
68-
int l=strlen(str);
69-
7066
if (screen_buffer_pos+l>screen_buffer_size)
7167
{
7268
while(screen_buffer_pos+l>screen_buffer_size)
@@ -81,6 +77,19 @@ my_print(char *str)
8177
#endif
8278
}
8379

80+
#ifdef HAVE_INLINE
81+
inline
82+
#endif
83+
void my_print(char *str)
84+
{
85+
my_print_l(str,
86+
#ifdef SCREEN_BUFFERING
87+
strlen(str)
88+
#else
89+
0
90+
#endif
91+
);
92+
}
8493

8594
void c_refresh(void)
8695
{
@@ -227,6 +236,11 @@ void c_print(char * text)
227236
my_print(text);
228237
}
229238

239+
void c_print_l(char * text, int len)
240+
{
241+
my_print_l(text, len);
242+
}
243+
230244

231245
/* print char on the cursor position */
232246
void c_putc(char c)

console.h

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ extern void c_init(int w,int h);
1515
extern void c_shutdown(void);
1616
extern void c_cls(void);
1717
extern void c_print(char *text);
18+
extern void c_print_l(char *text, int len);
1819
extern void c_putc(char c);
1920
extern void c_goto(int x, int y);
2021
extern void c_clear(int x1,int y1,int x2, int y2);

xinterface.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,11 @@ void c_setcolor_3b(unsigned char a)
280280
}
281281

282282
/* print on the cursor position */
283-
void c_print(char *text)
283+
#ifdef HAVE_INLINE
284+
inline
285+
#endif
286+
void c_print_l(char *text, int l)
284287
{
285-
int l = strlen(text);
286-
287288
XSetForeground(display,gc,(x_color[x_current_color]).pixel);
288289
XSetBackground(display,gc,(x_color[x_current_bgcolor]).pixel);
289290
XDrawImageString(
@@ -302,6 +303,11 @@ void c_print(char *text)
302303
x_current_x+=l;
303304
}
304305

306+
void c_print(char *text)
307+
{
308+
c_print_l(text, strlen(text));
309+
}
310+
305311
/* print char on the cursor position */
306312
void c_putc(char c)
307313
{

0 commit comments

Comments
 (0)