Rename spawn sync object Lua function

This commit is contained in:
MysterD 2022-02-22 23:50:12 -08:00
parent bbeec3c707
commit e94d002114
4 changed files with 31 additions and 18 deletions

View file

@ -454,7 +454,7 @@
<br />
- smlua_obj_utils.h
- [spawn_object_sync](#spawn_object_sync)
- [spawn_sync_object](#spawn_sync_object)
<br />
@ -8030,10 +8030,10 @@
<br />
## [spawn_object_sync](#spawn_object_sync)
## [spawn_sync_object](#spawn_sync_object)
### Lua Example
`local ObjectValue = spawn_object_sync(behaviorId, modelId, x, y, z, objSetupFunction)`
`local ObjectValue = spawn_sync_object(behaviorId, modelId, x, y, z, objSetupFunction)`
### Parameters
| Field | Type |
@ -8043,13 +8043,13 @@
| x | number |
| y | number |
| z | number |
| objSetupFunction | LuaFunction([Object](structs.md#Object)) |
| objSetupFunction | LuaFunction() |
### Returns
[Object](structs.md#Object)
### C Prototype
`struct Object* spawn_object_sync(enum BehaviorId behaviorId, enum ModelExtendedId modelId, f32 x, f32 y, f32 z, LuaFunction objSetupFunction);`
`struct Object* spawn_sync_object(enum BehaviorId behaviorId, enum ModelExtendedId modelId, f32 x, f32 y, f32 z, LuaFunction objSetupFunction);`
[:arrow_up_small:](#)

View file

@ -5286,7 +5286,7 @@ int smlua_func_save_file_get_total_star_count(lua_State* L) {
// smlua_obj_utils.h //
///////////////////////
int smlua_func_spawn_object_sync(lua_State* L) {
int smlua_func_spawn_sync_object(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 6)) { return 0; }
int behaviorId = smlua_to_integer(L, 1);
@ -5302,7 +5302,7 @@ int smlua_func_spawn_object_sync(lua_State* L) {
LuaFunction objSetupFunction = smlua_to_lua_function(L, 6);
if (!gSmLuaConvertSuccess) { return 0; }
smlua_push_object(L, LOT_OBJECT, spawn_object_sync(behaviorId, modelId, x, y, z, objSetupFunction));
smlua_push_object(L, LOT_OBJECT, spawn_sync_object(behaviorId, modelId, x, y, z, objSetupFunction));
return 1;
}
@ -6121,7 +6121,7 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "save_file_get_total_star_count", smlua_func_save_file_get_total_star_count);
// smlua_obj_utils.h
smlua_bind_function(L, "spawn_object_sync", smlua_func_spawn_object_sync);
smlua_bind_function(L, "spawn_sync_object", smlua_func_spawn_sync_object);
// sound_init.h
smlua_bind_function(L, "disable_background_sound", smlua_func_disable_background_sound);

View file

@ -8,8 +8,7 @@
#include "smlua_model_utils.h"
#include "pc/debuglog.h"
struct Object* spawn_object_sync(enum BehaviorId behaviorId, enum ModelExtendedId modelId, f32 x, f32 y, f32 z, LuaFunction objSetupFunction) {
static struct Object* spawn_object_internal(enum BehaviorId behaviorId, enum ModelExtendedId modelId, f32 x, f32 y, f32 z, LuaFunction objSetupFunction, bool doSync) {
const BehaviorScript* behavior = get_behavior_from_id(behaviorId);
if (behavior == NULL) {
LOG_ERROR("failed to find behavior %u", behaviorId);
@ -28,7 +27,7 @@ struct Object* spawn_object_sync(enum BehaviorId behaviorId, enum ModelExtendedI
return NULL;
}
if (!network_set_sync_id(obj)) {
if (doSync && !network_set_sync_id(obj)) {
obj->activeFlags = ACTIVE_FLAG_DEACTIVATED;
LOG_ERROR("failed to set sync id");
return NULL;
@ -54,13 +53,24 @@ struct Object* spawn_object_sync(enum BehaviorId behaviorId, enum ModelExtendedI
}
}
struct SyncObject* so = &gSyncObjects[obj->oSyncID];
so->extendedModelId = modelId;
so->o = obj;
if (doSync) {
struct SyncObject* so = &gSyncObjects[obj->oSyncID];
so->extendedModelId = modelId;
so->o = obj;
struct Object* spawn_objects[] = { obj };
u32 models[] = { loadedModelId };
network_send_spawn_objects(spawn_objects, models, 1);
struct Object* spawn_objects[] = { obj };
u32 models[] = { loadedModelId };
network_send_spawn_objects(spawn_objects, models, 1);
}
return obj;
}
struct Object* spawn_sync_object(enum BehaviorId behaviorId, enum ModelExtendedId modelId, f32 x, f32 y, f32 z, LuaFunction objSetupFunction) {
spawn_object_internal(behaviorId, modelId, x, y, z, objSetupFunction, true);
}
// this is too dangerous for now
struct Object* spawn_non_sync_object(enum BehaviorId behaviorId, enum ModelExtendedId modelId, f32 x, f32 y, f32 z) {
spawn_object_internal(behaviorId, modelId, x, y, z, 0, false);
}

View file

@ -4,6 +4,9 @@
#include "behavior_table.h"
#include "smlua_model_utils.h"
struct Object* spawn_object_sync(enum BehaviorId behaviorId, enum ModelExtendedId modelId, f32 x, f32 y, f32 z, LuaFunction objSetupFunction);
struct Object* spawn_sync_object(enum BehaviorId behaviorId, enum ModelExtendedId modelId, f32 x, f32 y, f32 z, LuaFunction objSetupFunction);
// this is too dangerous for now
//struct Object* spawn_non_sync_object(enum BehaviorId behaviorId, enum ModelExtendedId modelId, f32 x, f32 y, f32 z);
#endif