Skip to content

Commit e226507

Browse files
Batch crosshair draws on PSP backend.
1 parent 6596475 commit e226507

1 file changed

Lines changed: 74 additions & 32 deletions

File tree

source/platform/psp/gu/gu_draw.cpp

Lines changed: 74 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ Draw_FillByColor
11251125
Fills a box of pixels with a single color
11261126
=============
11271127
*/
1128-
void Draw_FillByColor (int x, int y, int w, int h, int r, int g, int b, int a)
1128+
void Draw_FillByColor (int *x, int *y, int *w, int *h, int r, int g, int b, int a)
11291129
{
11301130
unsigned int c = GU_RGBA(r, g, b, a);
11311131

@@ -1134,7 +1134,7 @@ void Draw_FillByColor (int x, int y, int w, int h, int r, int g, int b, int a)
11341134
short x, y, z;
11351135
};
11361136

1137-
vertex* const vertices = static_cast<vertex*>(sceGuGetMemory(sizeof(vertex) * 2));
1137+
vertex* const vertices = static_cast<vertex*>(sceGuGetMemory(sizeof(vertex) * 8));
11381138

11391139
vertices[0].x = x;
11401140
vertices[0].y = y;
@@ -1151,6 +1151,41 @@ void Draw_FillByColor (int x, int y, int w, int h, int r, int g, int b, int a)
11511151
sceGuEnable(GU_TEXTURE_2D);
11521152
}
11531153

1154+
/*
1155+
=============
1156+
Draw_FillByColorBatched
1157+
1158+
Fills multiple boxes of pixels with a single color
1159+
=============
1160+
*/
1161+
void Draw_FillByColorBatched (int *x, int *y, int *w, int *h, int r, int g, int b, int a, int num)
1162+
{
1163+
unsigned int c = GU_RGBA(r, g, b, a);
1164+
1165+
struct vertex
1166+
{
1167+
short x, y, z;
1168+
};
1169+
1170+
vertex* const vertices = static_cast<vertex*>(sceGuGetMemory(sizeof(vertex) * (2 * num)));
1171+
1172+
for (int i = 0; i < num; i++) {
1173+
vertices[i * 2].x = x[i];
1174+
vertices[i * 2].y = y[i];
1175+
vertices[i * 2].z = 0;
1176+
1177+
vertices[i * 2 + 1].x = x[i] + w[i];
1178+
vertices[i * 2 + 1].y = y[i] + h[i];
1179+
vertices[i * 2 + 1].z = 0;
1180+
}
1181+
1182+
sceGuDisable(GU_TEXTURE_2D);
1183+
sceGuColor(c);
1184+
sceGuDrawArray(GU_SPRITES, GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2 * num, 0, vertices);
1185+
sceGuColor(0xffffffff);
1186+
sceGuEnable(GU_TEXTURE_2D);
1187+
}
1188+
11541189
void Draw_Fill (int x, int y, int w, int h, int c)
11551190
{
11561191
struct vertex
@@ -1396,10 +1431,12 @@ void Draw_Crosshair (void)
13961431
Draw_Pic (112, 7, sniper_scope);
13971432

13981433
// And its borders
1399-
Draw_FillByColor(0, 0, 480, 7, 0, 0, 0, 255); // Top
1400-
Draw_FillByColor(0, 263, 480, 9, 0, 0, 0, 255); // Bottom
1401-
Draw_FillByColor(0, 7, 112, 256, 0, 0, 0, 255); // Left
1402-
Draw_FillByColor(368, 7, 112, 256, 0, 0, 0, 255); // Right
1434+
int x[4], y[4], w[4], h[4];
1435+
x[0] = 0; y[0] = 0; w[0] = 480; y[0] = 7; // Top
1436+
x[1] = 0; y[1] = 263; w[1] = 480; y[1] = 9; // Bottom
1437+
x[2] = 0; y[2] = 7; w[2] = 112; y[2] = 256; // Left
1438+
x[3] = 368; y[3] = 7; w[3] = 112; y[3] = 256; // Right
1439+
Draw_FillByColorBatched(x, y, w, h, 0, 0, 0, 255, 4);
14031440
}
14041441

14051442
if (Hitmark_Time > sv.time)
@@ -1441,7 +1478,6 @@ void Draw_Crosshair (void)
14411478
}
14421479
}
14431480

1444-
int x_value, y_value;
14451481
int x_center, y_center;
14461482
int crosshair_offset;
14471483

@@ -1461,26 +1497,29 @@ void Draw_Crosshair (void)
14611497
}
14621498

14631499
crosshair_offset_step += (crosshair_offset - crosshair_offset_step) * 0.5;
1464-
1500+
1501+
int x[4], y[4], w[4], h[4];
14651502
// Left
1466-
x_value = x_center - crosshair_offset_step;
1467-
y_value = y_center;
1468-
Draw_FillByColor(x_value, y_value, 3, 1, 255, (int)col, (int)col, (int)crosshair_opacity);
1503+
x[0] = x_center - crosshair_offset_step;
1504+
y[0] = y_center;
1505+
w[0] = 3; h[0] = 1;
14691506

14701507
// Right
1471-
x_value = x_center + crosshair_offset_step - 3;
1472-
y_value = y_center;
1473-
Draw_FillByColor(x_value, y_value, 3, 1, 255, (int)col, (int)col, (int)crosshair_opacity);
1508+
x[1] = x_center + crosshair_offset_step - 3;
1509+
y[1] = y_center;
1510+
w[1] = 3; h[1] = 1;
14741511

14751512
// Top
1476-
x_value = x_center;
1477-
y_value = y_center - crosshair_offset_step;
1478-
Draw_FillByColor(x_value, y_value, 1, 3, 255, (int)col, (int)col, (int)crosshair_opacity);
1513+
x[2] = x_center;
1514+
y[2] = y_center - crosshair_offset_step;
1515+
w[2] = 1; h[2] = 3;
14791516

14801517
// Bottom
1481-
x_value = x_center;
1482-
y_value = y_center + crosshair_offset_step - 3;
1483-
Draw_FillByColor(x_value, y_value, 1, 3, 255, (int)col, (int)col, (int)crosshair_opacity);
1518+
x[3] = x_center;
1519+
y[3] = y_center + crosshair_offset_step - 3;
1520+
w[3] = 1; h[3] = 3;
1521+
1522+
Draw_FillByColorBatched(x, y, w, h, 255, (int)col, (int)col, (int)crosshair_opacity, 4);
14841523
}
14851524
// Area of Effect (o)
14861525
else if (crosshair.value == 2) {
@@ -1505,25 +1544,28 @@ void Draw_Crosshair (void)
15051544
crosshair_offset = 12 + cur_spread;
15061545
crosshair_offset_step += (crosshair_offset - crosshair_offset_step) * 0.5;
15071546

1547+
int x[4], y[4], w[4], h[4];
15081548
// Left
1509-
x_value = x_center - crosshair_offset_step;
1510-
y_value = y_center;
1511-
Draw_FillByColor(x_value, y_value, 3, 1, 255, 255, 255, 255);
1549+
x[0] = x_center - crosshair_offset_step;
1550+
y[0] = y_center;
1551+
w[0] = 3; h[0] = 1;
15121552

15131553
// Right
1514-
x_value = x_center + crosshair_offset_step - 2;
1515-
y_value = y_center;
1516-
Draw_FillByColor(x_value, y_value, 3, 1, 255, 255, 255, 255);
1554+
x[1] = x_center + crosshair_offset_step - 2;
1555+
y[1] = y_center;
1556+
w[1] = 3; h[1] = 1;
15171557

15181558
// Top
1519-
x_value = x_center;
1520-
y_value = y_center - crosshair_offset_step;
1521-
Draw_FillByColor(x_value, y_value, 1, 3, 255, 255, 255, 255);
1559+
x[2] = x_center;
1560+
y[2] = y_center - crosshair_offset_step;
1561+
w[2] = 1; h[2] = 3;
15221562

15231563
// Bottom
1524-
x_value = x_center;
1525-
y_value = y_center + crosshair_offset_step - 3;
1526-
Draw_FillByColor(x_value, y_value, 1, 3, 255, 255, 255, 255);
1564+
x[3] = x_center;
1565+
y[3] = y_center + crosshair_offset_step - 3;
1566+
w[3] = 1; h[3] = 3;
1567+
1568+
Draw_FillByColorBatched(x, y, w, h, 255, 255, 255, 255, 4);
15271569
}
15281570
}
15291571

0 commit comments

Comments
 (0)