Fix sync of models on late join

This commit is contained in:
MysterD 2023-05-17 23:32:39 -07:00
parent f53ffcd491
commit 87f076cd26
6 changed files with 39 additions and 10 deletions

View file

@ -77,7 +77,8 @@ struct GraphNode* dynos_model_load_dl(u32* aId, enum ModelPool aModelPool, u8 aL
struct GraphNode* dynos_model_store_geo(u32* aId, enum ModelPool aModelPool, void* aAsset, struct GraphNode* aGraphNode); struct GraphNode* dynos_model_store_geo(u32* aId, enum ModelPool aModelPool, void* aAsset, struct GraphNode* aGraphNode);
struct GraphNode* dynos_model_get_geo(u32 aId); struct GraphNode* dynos_model_get_geo(u32 aId);
void dynos_model_overwrite_slot(u32 srcSlot, u32 dstSlot); void dynos_model_overwrite_slot(u32 srcSlot, u32 dstSlot);
u32 dynos_model_get_id_from_asset(void* asset); u32 dynos_model_get_id_from_asset(void* aAsset);
u32 dynos_model_get_id_from_graph_node(struct GraphNode* aGraphNode);
void dynos_model_clear_pool(enum ModelPool aModelPool); void dynos_model_clear_pool(enum ModelPool aModelPool);
// -- other -- // // -- other -- //

View file

@ -968,6 +968,7 @@ struct GraphNode* DynOS_Model_LoadDl(u32* aId, enum ModelPool aModelPool, u8 aLa
struct GraphNode* DynOS_Model_StoreGeo(u32* aId, enum ModelPool aModelPool, void* aAsset, struct GraphNode* aGraphNode); struct GraphNode* DynOS_Model_StoreGeo(u32* aId, enum ModelPool aModelPool, void* aAsset, struct GraphNode* aGraphNode);
struct GraphNode* DynOS_Model_GetGeo(u32 aId); struct GraphNode* DynOS_Model_GetGeo(u32 aId);
u32 DynOS_Model_GetIdFromAsset(void* asset); u32 DynOS_Model_GetIdFromAsset(void* asset);
u32 DynOS_Model_GetIdFromGraphNode(struct GraphNode* aNode);
void DynOS_Model_OverwriteSlot(u32 srcSlot, u32 dstSlot); void DynOS_Model_OverwriteSlot(u32 srcSlot, u32 dstSlot);
void DynOS_Model_ClearPool(enum ModelPool aModelPool); void DynOS_Model_ClearPool(enum ModelPool aModelPool);
void DynOS_Model_Update(); void DynOS_Model_Update();

View file

@ -237,8 +237,12 @@ struct GraphNode* dynos_model_store_geo(u32* aId, enum ModelPool aModelPool, voi
return DynOS_Model_StoreGeo(aId, aModelPool, aAsset, aGraphNode); return DynOS_Model_StoreGeo(aId, aModelPool, aAsset, aGraphNode);
} }
u32 dynos_model_get_id_from_asset(void* asset) { u32 dynos_model_get_id_from_asset(void* aAsset) {
return DynOS_Model_GetIdFromAsset(asset); return DynOS_Model_GetIdFromAsset(aAsset);
}
u32 dynos_model_get_id_from_graph_node(struct GraphNode* aGraphNode) {
return DynOS_Model_GetIdFromGraphNode(aGraphNode);
} }
void dynos_model_clear_pool(enum ModelPool aModelPool) { void dynos_model_clear_pool(enum ModelPool aModelPool) {

View file

@ -130,7 +130,9 @@ struct GraphNode* DynOS_Model_GetErrorGeo() {
struct GraphNode* DynOS_Model_GetGeo(u32 aId) { struct GraphNode* DynOS_Model_GetGeo(u32 aId) {
if (!aId) { return NULL; } if (!aId) { return NULL; }
if (sOverwriteMap.count(aId)) { aId = sOverwriteMap[aId]; } if (sOverwriteMap.count(aId)) {
aId = sOverwriteMap[aId];
}
if (sIdMap.count(aId) == 0) { if (sIdMap.count(aId) == 0) {
return DynOS_Model_GetErrorGeo(); return DynOS_Model_GetErrorGeo();
@ -144,13 +146,33 @@ struct GraphNode* DynOS_Model_GetGeo(u32 aId) {
return vec.back().graphNode; return vec.back().graphNode;
} }
u32 DynOS_Model_GetIdFromAsset(void* asset) { u32 DynOS_Model_GetIdFromGraphNode(struct GraphNode* aNode) {
if (!asset) { return MODEL_NONE; } u32 lowest = 9999;
for (int i = 0; i < MODEL_POOL_MAX; i++) { for (auto& it : sIdMap) {
if (sAssetMap[i].count(asset)) { if (it.first > lowest) { continue; }
return sAssetMap[i][asset].id; if (!it.second.size() || it.second.empty()) { continue; }
auto& node = it.second.back();
if (aNode == node.graphNode) {
lowest = it.first;
} }
} }
if (lowest < 9999) { return lowest; }
return MODEL_ERROR_MODEL;
}
u32 DynOS_Model_GetIdFromAsset(void* asset) {
if (!asset) { return MODEL_NONE; }
u32 lowest = 9999;
for (int i = 0; i < MODEL_POOL_MAX; i++) {
if (!sAssetMap[i].count(asset)) { continue; }
u32 id = sAssetMap[i][asset].id;
if (id < lowest) { lowest = id; }
if (sOverwriteMap.count(id)) {
id = sOverwriteMap[id];
if (id < lowest) { lowest = id; }
}
}
if (lowest < 9999) { return lowest; }
return MODEL_ERROR_MODEL; return MODEL_ERROR_MODEL;
} }

View file

@ -109,6 +109,7 @@ void gfx_cc_precomp(void) {
gfx_pc_precomp_shader(0x04060401, 0x04000000, 0x04060402, 0x04000b0b, 0x00000000); // 84c6842100596a45 gfx_pc_precomp_shader(0x04060401, 0x04000000, 0x04060402, 0x04000b0b, 0x00000000); // 84c6842100596a45
gfx_pc_precomp_shader(0x04060401, 0x05000000, 0x04060402, 0x05000b0b, 0x00000001); // 1d970841b086b2e6 gfx_pc_precomp_shader(0x04060401, 0x05000000, 0x04060402, 0x05000b0b, 0x00000001); // 1d970841b086b2e6
gfx_pc_precomp_shader(0x01000000, 0x04000000, 0x02000000, 0x04000b0b, 0x00000001); // 410000008f86b2e6 gfx_pc_precomp_shader(0x01000000, 0x04000000, 0x02000000, 0x04000b0b, 0x00000001); // 410000008f86b2e6
gfx_pc_precomp_shader(0x04060401, 0x05000000, 0x04060402, 0x05000b0b, 0x00000009); // 1d970841b086b2ee
sAllowCCPrint = 1; sAllowCCPrint = 1;
} }

View file

@ -102,7 +102,7 @@ void network_send_area(struct NetworkPlayer* toNp) {
// TODO: move find model to a utility file/function // TODO: move find model to a utility file/function
// find model // find model
u32 model = dynos_model_get_id_from_asset(so->o->header.gfx.sharedChild); u32 model = dynos_model_get_id_from_graph_node(so->o->header.gfx.sharedChild);
u32 models[] = { model }; u32 models[] = { model };
network_send_spawn_objects_to(toNp->localIndex, spawn_objects, models, 1); network_send_spawn_objects_to(toNp->localIndex, spawn_objects, models, 1);