Skip to content

Commit 0e796e9

Browse files
authored
Add ConsumeEntityEvent to Blackholio C++ and C# modules (#4675)
This resolves an issue found while testing C# module behavior against the Blackholio demo in an unrelated PR. # Description of Changes Updates the C# and C++ server modules for the Blackholio demo, to reflect changes made to the Rust module in #4217 This is needed if testing against Blackholio using either the C# or C++, or else the `ConsumeEntityEvent` will be missing from the generated client bindings. # API and ABI breaking changes Not API or ABI breaking. # Expected complexity level and risk 1 # Testing - [X] Tested Unity Blackholio demo using the C# module - [X] Tested Unity Blackholio demo using the C++ module
1 parent 4f84ad9 commit 0e796e9

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

  • demo/Blackholio

demo/Blackholio/server-cpp/spacetimedb/src/lib.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@ SPACETIMEDB_TABLE(CircleRecombineTimer, circle_recombine_timer, Private)
177177
FIELD_PrimaryKeyAutoInc(circle_recombine_timer, scheduled_id)
178178
SPACETIMEDB_SCHEDULE(circle_recombine_timer, 1, circle_recombine)
179179

180+
struct ConsumeEntityEvent {
181+
int32_t consumed_entity_id;
182+
int32_t consumer_entity_id;
183+
};
184+
SPACETIMEDB_STRUCT(ConsumeEntityEvent, consumed_entity_id, consumer_entity_id)
185+
SPACETIMEDB_TABLE(ConsumeEntityEvent, consume_entity_event, Public, true)
186+
180187
struct ConsumeEntityTimer {
181188
uint64_t scheduled_id;
182189
ScheduleAt scheduled_at;
@@ -594,6 +601,12 @@ SPACETIMEDB_REDUCER(consume_entity, ReducerContext ctx, ConsumeEntityTimer reque
594601
Entity consumed_entity = consumed_opt.value();
595602
Entity consumer_entity = consumer_opt.value();
596603
consumer_entity.mass += consumed_entity.mass;
604+
605+
ConsumeEntityEvent consume_event{
606+
consumed_entity.entity_id,
607+
consumer_entity.entity_id
608+
};
609+
ctx.db[consume_entity_event].insert(consume_event);
597610

598611
auto destroy_result = destroy_entity(ctx, consumed_entity.entity_id);
599612
if (destroy_result.is_err()) {

demo/Blackholio/server-csharp/Lib.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ public partial struct CircleRecombineTimer
101101
public ScheduleAt scheduled_at;
102102
public int player_id;
103103
}
104+
105+
[Table(Accessor = "consume_entity_event", Public = true, Event = true)]
106+
public partial struct ConsumeEntityEvent
107+
{
108+
public int consumed_entity_id;
109+
public int consumer_entity_id;
110+
}
104111

105112
[Table(Accessor = "consume_entity_timer", Scheduled = nameof(ConsumeEntity), ScheduledAt = nameof(scheduled_at))]
106113
public partial struct ConsumeEntityTimer
@@ -433,6 +440,12 @@ public static void ConsumeEntity(ReducerContext ctx, ConsumeEntityTimer request)
433440
{
434441
var consumed_entity = ctx.Db.entity.entity_id.Find(request.consumed_entity_id) ?? throw new Exception("Consumed entity doesn't exist");
435442
var consumer_entity = ctx.Db.entity.entity_id.Find(request.consumer_entity_id) ?? throw new Exception("Consumer entity doesn't exist");
443+
444+
ctx.Db.consume_entity_event.Insert(new ConsumeEntityEvent
445+
{
446+
consumed_entity_id = consumed_entity.entity_id,
447+
consumer_entity_id = consumer_entity.entity_id
448+
});
436449

437450
consumer_entity.mass += consumed_entity.mass;
438451
DestroyEntity(ctx, consumed_entity.entity_id);

0 commit comments

Comments
 (0)