Synchronized bouncing fireball spawners

This commit is contained in:
MysterD 2020-09-22 21:37:26 -07:00
parent 47f5e2315e
commit e1cc0aa065
2 changed files with 35 additions and 6 deletions

View file

@ -28,19 +28,37 @@ void bhv_bouncing_fireball_flame_loop(void) {
}
void bhv_bouncing_fireball_loop(void) {
if (!network_sync_object_initialized(o)) {
network_init_object(o, SYNC_DISTANCE_ONLY_EVENTS);
network_init_object_field(o, &o->oAction);
network_init_object_field(o, &o->oPrevAction);
network_init_object_field(o, &o->oTimer);
}
struct Object* player = nearest_player_to_object(o);
int distanceToPlayer = dist_between_objects(o, player);
struct Object *sp2C;
f32 sp28;
switch (o->oAction) {
case 0:
if (o->oDistanceToMario < 2000.0f)
if (distanceToPlayer < 2000.0f)
o->oAction = 1;
break;
case 1:
sp2C = spawn_object(o, MODEL_RED_FLAME, bhvBouncingFireballFlame);
sp28 = (10 - o->oTimer) * 0.5;
obj_scale_xyz(sp2C, sp28, sp28, sp28);
if (o->oTimer == 0)
obj_become_tangible(sp2C);
if (network_owns_object(o)) {
sp2C = spawn_object(o, MODEL_RED_FLAME, bhvBouncingFireballFlame);
sp28 = (10 - o->oTimer) * 0.5;
obj_scale_xyz(sp2C, sp28, sp28, sp28);
if (o->oTimer == 0)
obj_become_tangible(sp2C);
struct Object* spawn_objects[] = { sp2C };
u32 models[] = { MODEL_RED_FLAME };
network_send_spawn_objects(spawn_objects, models, 1);
network_send_object(o);
}
if (o->oTimer > 10)
o->oAction++;
break;

View file

@ -60,6 +60,9 @@ void network_send_spawn_objects(struct Object* objects[], u32 models[], u8 objec
packet_write(&p, &behaviorId, sizeof(enum BehaviorId));
packet_write(&p, &o->activeFlags, sizeof(s16));
packet_write(&p, o->rawData.asU32, sizeof(s32) * 80);
packet_write(&p, &o->header.gfx.scale[0], sizeof(f32));
packet_write(&p, &o->header.gfx.scale[1], sizeof(f32));
packet_write(&p, &o->header.gfx.scale[2], sizeof(f32));
}
network_send(&p);
@ -93,11 +96,15 @@ void network_receive_spawn_objects(struct Packet* p) {
struct Object* spawned[MAX_SPAWN_OBJECTS_PER_PACKET] = { 0 };
for (u8 i = 0; i < objectCount; i++) {
struct SpawnObjectData data = { 0 };
Vec3f scale = { 0 };
packet_read(p, &data.parentId, sizeof(u8));
packet_read(p, &data.model, sizeof(u32));
packet_read(p, &data.behaviorId, sizeof(enum BehaviorId));
packet_read(p, &data.activeFlags, sizeof(s16));
packet_read(p, &data.rawData, sizeof(s32) * 80);
packet_read(p, &scale[0], sizeof(f32));
packet_read(p, &scale[1], sizeof(f32));
packet_read(p, &scale[2], sizeof(f32));
struct Object* parentObj = NULL;
if (data.parentId == (u8)-1) {
@ -126,6 +133,10 @@ void network_receive_spawn_objects(struct Packet* p) {
struct Object* o = spawn_object(parentObj, data.model, behavior);
memcpy(o->rawData.asU32, data.rawData, sizeof(u32) * 80);
o->header.gfx.scale[0] = scale[0];
o->header.gfx.scale[1] = scale[1];
o->header.gfx.scale[2] = scale[2];
// correct the temporary parent with the object itself
if (data.parentId == (u8)-1) { o->parentObj = o; }