Skip to content

Commit 607b56c

Browse files
committed
Introduce coin batching
1 parent 4b780f9 commit 607b56c

13 files changed

Lines changed: 352 additions & 489 deletions

File tree

actors/coin/geo.inc.c

Lines changed: 112 additions & 112 deletions
Large diffs are not rendered by default.

actors/coin/model.inc.c

Lines changed: 61 additions & 305 deletions
Large diffs are not rendered by default.

actors/common1.h

Lines changed: 19 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -35,59 +35,31 @@ extern const GeoLayout red_coin_no_shadow_geo[];
3535
extern const GeoLayout silver_coin_geo[];
3636
extern const GeoLayout silver_coin_no_shadow_geo[];
3737

38-
extern const Gfx coin_seg3_dl_yellow_0[];
39-
extern const Gfx coin_seg3_dl_yellow_22_5[];
40-
extern const Gfx coin_seg3_dl_yellow_45[];
41-
extern const Gfx coin_seg3_dl_yellow_67_5[];
42-
extern const Gfx coin_seg3_dl_yellow_90[];
43-
extern const Gfx coin_seg3_dl_yellow_67_5_r[];
44-
extern const Gfx coin_seg3_dl_yellow_45_r[];
45-
extern const Gfx coin_seg3_dl_yellow_22_5_r[];
38+
extern const Gfx coin_seg3_dl_0[];
39+
extern const Gfx coin_seg3_dl_22_5[];
40+
extern const Gfx coin_seg3_dl_45[];
41+
extern const Gfx coin_seg3_dl_67_5[];
42+
extern const Gfx coin_seg3_dl_90[];
4643

47-
extern const Gfx coin_seg3_dl_blue_0[];
48-
extern const Gfx coin_seg3_dl_blue_22_5[];
49-
extern const Gfx coin_seg3_dl_blue_45[];
50-
extern const Gfx coin_seg3_dl_blue_67_5[];
51-
extern const Gfx coin_seg3_dl_blue_90[];
52-
extern const Gfx coin_seg3_dl_blue_67_5_r[];
53-
extern const Gfx coin_seg3_dl_blue_45_r[];
54-
extern const Gfx coin_seg3_dl_blue_22_5_r[];
44+
extern const Gfx coin_seg3_dl_secret_draw[];
5545

56-
extern const Gfx coin_seg3_dl_red_0[];
57-
extern const Gfx coin_seg3_dl_red_22_5[];
58-
extern const Gfx coin_seg3_dl_red_45[];
59-
extern const Gfx coin_seg3_dl_red_67_5[];
60-
extern const Gfx coin_seg3_dl_red_90[];
61-
extern const Gfx coin_seg3_dl_red_67_5_r[];
62-
extern const Gfx coin_seg3_dl_red_45_r[];
63-
extern const Gfx coin_seg3_dl_red_22_5_r[];
64-
65-
extern const Gfx coin_seg3_dl_secret_0[];
66-
extern const Gfx coin_seg3_dl_secret_22_5[];
67-
extern const Gfx coin_seg3_dl_secret_45[];
68-
extern const Gfx coin_seg3_dl_secret_67_5[];
69-
extern const Gfx coin_seg3_dl_secret_90[];
70-
extern const Gfx coin_seg3_dl_secret_67_5_r[];
71-
extern const Gfx coin_seg3_dl_secret_45_r[];
72-
extern const Gfx coin_seg3_dl_secret_22_5_r[];
46+
extern const Gfx coin_seg3_dl_yellow_draw_r[];
47+
extern const Gfx coin_seg3_dl_blue_draw_r[];
48+
extern const Gfx coin_seg3_dl_red_draw_r[];
49+
extern const Gfx coin_seg3_dl_secret_draw_r[];
7350

7451
#else
75-
extern const Gfx coin_seg3_sub_dl_begin[];
76-
extern const Gfx coin_seg3_sub_dl_end[];
77-
extern const Gfx coin_seg3_dl_yellow_front[];
78-
extern const Gfx coin_seg3_dl_yellow_tilt_right[];
79-
extern const Gfx coin_seg3_dl_yellow_side[];
80-
extern const Gfx coin_seg3_dl_yellow_tilt_left[];
81-
extern const Gfx coin_seg3_dl_blue_front[];
82-
extern const Gfx coin_seg3_dl_blue_tilt_right[];
83-
extern const Gfx coin_seg3_dl_blue_side[];
84-
extern const Gfx coin_seg3_dl_blue_tilt_left[];
85-
extern const Gfx coin_seg3_dl_red_front[];
86-
extern const Gfx coin_seg3_dl_red_tilt_right[];
87-
extern const Gfx coin_seg3_dl_red_side[];
88-
extern const Gfx coin_seg3_dl_red_tilt_left[];
52+
extern const Gfx coin_seg3_dl_front[];
53+
extern const Gfx coin_seg3_dl_tilt_right[];
54+
extern const Gfx coin_seg3_dl_side[];
55+
extern const Gfx coin_seg3_dl_tilt_left[];
8956
#endif
9057

58+
extern const Gfx coin_seg3_dl_yellow_draw[];
59+
extern const Gfx coin_seg3_dl_blue_draw[];
60+
extern const Gfx coin_seg3_dl_red_draw[];
61+
extern const Gfx coin_seg3_dl_end[];
62+
9163
// dirt
9264
extern const GeoLayout dirt_animation_geo[];
9365
extern const GeoLayout cartoon_star_geo[];

include/geo_commands.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ enum GeoLayoutCommands {
5858
/*0x1E*/ GEO_CMD_NOP_1E,
5959
/*0x1F*/ GEO_CMD_NOP_1F,
6060
/*0x20*/ GEO_CMD_NODE_CULLING_RADIUS,
61+
/*0x21*/ GEO_CMD_NODE_BATCH_DISPLAY_LIST,
6162

6263
GEO_CMD_COUNT,
6364
};
@@ -360,6 +361,10 @@ enum GeoLayoutCommands {
360361
CMD_BBH(GEO_CMD_NODE_DISPLAY_LIST, layer, 0x0000), \
361362
CMD_PTR(displayList)
362363

364+
#define GEO_BATCH_DISPLAY_LIST(layer, batch, displayList) \
365+
CMD_BBH(GEO_CMD_NODE_BATCH_DISPLAY_LIST, layer, batch), \
366+
CMD_PTR(displayList)
367+
363368
/**
364369
* 0x16: Create shadow scene graph node
365370
* 0x01: unused

include/sm64.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,29 @@ enum RenderLayers {
7777
LAYER_COUNT
7878
};
7979

80+
#ifdef IA8_30FPS_COINS
81+
#define BATCH_COIN_COUNT 5
82+
#else
83+
#define BATCH_COIN_COUNT 4
84+
#endif
85+
86+
enum BatchAlpha {
87+
#if SILHOUETTE
88+
BATCH_ALPHA_COUNT,
89+
};
90+
91+
enum BatchSilhouetteAlpha {
92+
#endif
93+
BATCH_OCCLUDE_SILHOUETTE_ALPHA_COIN_FIRST,
94+
BATCH_OCCLUDE_SILHOUETTE_ALPHA_COIN_LAST = BATCH_OCCLUDE_SILHOUETTE_ALPHA_COIN_FIRST + BATCH_COIN_COUNT - 1,
95+
96+
#if SILHOUETTE
97+
BATCH_OCCLUDE_SILHOUETTE_ALPHA_COUNT,
98+
#else
99+
BATCH_ALPHA_COUNT,
100+
#endif
101+
};
102+
80103
enum BatchTransparentDecal {
81104
BATCH_TRANSPARENT_DECAL_SHADOW_CIRCLE,
82105
BATCH_TRANSPARENT_DECAL_SHADOW_SQUARE,

src/engine/batch_list.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "batch_list.h"
22

3+
#include "actors/common1.h"
34
#include "game/segment2.h"
45

56
static const struct BatchDisplayLists BatchesTransparentDecal[] = {
@@ -14,6 +15,31 @@ static const struct BatchDisplayLists BatchesCLD[] = {
1415
};
1516
STATIC_ASSERT(BATCH_CLD_COUNT == sizeof(BatchesCLD) / sizeof(*BatchesCLD), "Mismatch in CLD batch count");
1617

18+
static const struct BatchDisplayLists BatchesAlpha[] = {
19+
#if SILHOUETTE
20+
};
21+
static const struct BatchDisplayLists BatchesOccludeSilhouetteAlpha[] = {
22+
#endif
23+
24+
#ifdef IA8_30FPS_COINS
25+
[ BATCH_OCCLUDE_SILHOUETTE_ALPHA_COIN_FIRST + 0 ] = { coin_seg3_dl_0 , coin_seg3_dl_end },
26+
[ BATCH_OCCLUDE_SILHOUETTE_ALPHA_COIN_FIRST + 1 ] = { coin_seg3_dl_22_5 , coin_seg3_dl_end },
27+
[ BATCH_OCCLUDE_SILHOUETTE_ALPHA_COIN_FIRST + 2 ] = { coin_seg3_dl_45 , coin_seg3_dl_end },
28+
[ BATCH_OCCLUDE_SILHOUETTE_ALPHA_COIN_FIRST + 3 ] = { coin_seg3_dl_67_5 , coin_seg3_dl_end },
29+
[ BATCH_OCCLUDE_SILHOUETTE_ALPHA_COIN_FIRST + 4 ] = { coin_seg3_dl_90 , coin_seg3_dl_end },
30+
#else
31+
[ BATCH_OCCLUDE_SILHOUETTE_ALPHA_COIN_FIRST + 0 ] = { coin_seg3_dl_front , coin_seg3_dl_end },
32+
[ BATCH_OCCLUDE_SILHOUETTE_ALPHA_COIN_FIRST + 1 ] = { coin_seg3_dl_tilt_right, coin_seg3_dl_end },
33+
[ BATCH_OCCLUDE_SILHOUETTE_ALPHA_COIN_FIRST + 2 ] = { coin_seg3_dl_side , coin_seg3_dl_end },
34+
[ BATCH_OCCLUDE_SILHOUETTE_ALPHA_COIN_FIRST + 3 ] = { coin_seg3_dl_tilt_left , coin_seg3_dl_end },
35+
#endif
36+
};
37+
38+
STATIC_ASSERT(BATCH_ALPHA_COUNT == sizeof(BatchesAlpha) / sizeof(*BatchesAlpha), "Mismatch in alpha batch count");
39+
#if SILHOUETTE
40+
STATIC_ASSERT(BATCH_OCCLUDE_SILHOUETTE_ALPHA_COUNT == sizeof(BatchesOccludeSilhouetteAlpha) / sizeof(*BatchesOccludeSilhouetteAlpha), "Mismatch in occlude silhouette alpha batch count");
41+
#endif
42+
1743
static inline struct BatchArray* batch_array_alloc(struct AllocOnlyPool *pool, int count, const struct BatchDisplayLists* dls) {
1844
struct BatchArray* batches = alloc_only_pool_alloc(pool, sizeof(struct BatchArray) + count * sizeof(struct DisplayListLinks));
1945
batches->count = count;
@@ -28,3 +54,13 @@ struct BatchArray* batch_list_objects_alloc_xlu_decal(struct AllocOnlyPool *pool
2854
struct BatchArray* batch_list_objects_alloc_cld(struct AllocOnlyPool *pool) {
2955
return batch_array_alloc(pool, BATCH_CLD_COUNT, BatchesCLD);
3056
}
57+
58+
struct BatchArray* batch_list_objects_alloc_alpha(struct AllocOnlyPool *pool) {
59+
return batch_array_alloc(pool, BATCH_ALPHA_COUNT, BatchesAlpha);
60+
}
61+
62+
#if SILHOUETTE
63+
struct BatchArray* batch_list_objects_alloc_occlude_silhouette_alpha(struct AllocOnlyPool *pool) {
64+
return batch_array_alloc(pool, BATCH_OCCLUDE_SILHOUETTE_ALPHA_COUNT, BatchesOccludeSilhouetteAlpha);
65+
}
66+
#endif

src/engine/batch_list.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@
55

66
struct BatchArray* batch_list_objects_alloc_xlu_decal(struct AllocOnlyPool *pool);
77
struct BatchArray* batch_list_objects_alloc_cld(struct AllocOnlyPool *pool);
8+
struct BatchArray* batch_list_objects_alloc_alpha(struct AllocOnlyPool *pool);
9+
struct BatchArray* batch_list_objects_alloc_occlude_silhouette_alpha(struct AllocOnlyPool *pool);
810

911
static inline struct BatchArray* batch_list_objects_alloc(struct AllocOnlyPool *pool, enum RenderLayers layer) {
1012
switch (layer) {
1113
case LAYER_TRANSPARENT_DECAL:
1214
return batch_list_objects_alloc_xlu_decal(pool);
1315
case LAYER_CLD:
1416
return batch_list_objects_alloc_cld(pool);
17+
case LAYER_ALPHA:
18+
return batch_list_objects_alloc_alpha(pool);
19+
#if SILHOUETTE
20+
case LAYER_OCCLUDE_SILHOUETTE_ALPHA:
21+
return batch_list_objects_alloc_occlude_silhouette_alpha(pool);
22+
#endif
1523
default:
1624
return 0;
1725
}

src/engine/geo_layout.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ GeoLayoutCommandProc GeoLayoutJumpTable[] = {
4343
/*GEO_CMD_NOP_1E */ geo_layout_cmd_nop2,
4444
/*GEO_CMD_NOP_1F */ geo_layout_cmd_nop3,
4545
/*GEO_CMD_NODE_CULLING_RADIUS */ geo_layout_cmd_node_culling_radius,
46+
/*GEO_CMD_NODE_BATCH_DISPLAY_LIST */ geo_layout_cmd_node_batch_display_list,
4647
};
4748

4849
struct GraphNode gObjParentGraphNode;
@@ -751,6 +752,15 @@ void geo_layout_cmd_node_culling_radius(void) {
751752
gGeoLayoutCommand += 0x04 << CMD_SIZE_SHIFT;
752753
}
753754

755+
void geo_layout_cmd_node_batch_display_list(void) {
756+
s32 drawingLayer = cur_geo_cmd_u8(0x01);
757+
s32 batch = cur_geo_cmd_s16(0x02);
758+
void *displayList = cur_geo_cmd_ptr(0x04);
759+
struct GraphNodeBatchDisplayList *graphNode = init_graph_node_batch_display_list(gGraphNodePool, NULL, displayList, drawingLayer, batch);
760+
register_scene_graph_node(&graphNode->node);
761+
gGeoLayoutCommand += 0x08 << CMD_SIZE_SHIFT;
762+
}
763+
754764
struct GraphNode *process_geo_layout(struct AllocOnlyPool *pool, void *segptr) {
755765
// set by register_scene_graph_node when gCurGraphNodeIndex is 0
756766
// and gCurRootGraphNode is NULL

src/engine/geo_layout.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ void geo_layout_cmd_nop(void);
8282
void geo_layout_cmd_copy_view(void);
8383
void geo_layout_cmd_node_held_obj(void);
8484
void geo_layout_cmd_node_culling_radius(void);
85+
void geo_layout_cmd_node_batch_display_list(void);
8586

8687
struct GraphNode *process_geo_layout(struct AllocOnlyPool *pool, void *segptr);
8788

src/engine/graph_node.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,21 @@ struct GraphNodeHeldObject *init_graph_node_held_object(struct AllocOnlyPool *po
530530
return graphNode;
531531
}
532532

533+
struct GraphNodeBatchDisplayList* init_graph_node_batch_display_list(struct AllocOnlyPool *pool, struct GraphNodeBatchDisplayList *graphNode, void *displayList, s32 drawingLayer, s32 batch) {
534+
if (pool != NULL) {
535+
graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodeBatchDisplayList));
536+
}
537+
538+
if (graphNode != NULL) {
539+
init_scene_graph_node_links(&graphNode->node, GRAPH_NODE_TYPE_BATCH_DISPLAY_LIST);
540+
SET_GRAPH_NODE_LAYER(graphNode->node.flags, drawingLayer);
541+
graphNode->displayList = displayList;
542+
graphNode->batch = batch;
543+
}
544+
545+
return graphNode;
546+
}
547+
533548
/**
534549
* Adds 'childNode' to the end of the list children from 'parent'
535550
*/

0 commit comments

Comments
 (0)