MCPcopy Create free account
hub / github.com/crownengine/crown / refresh

Method refresh

src/device/device.cpp:959–1073  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

957}
958
959void Device::refresh(const char *json)
960{
961#if CROWN_CAN_RELOAD
962 TempAllocator4096 ta;
963 JsonObject obj(ta);
964 JsonArray list(ta);
965 DynamicString type(ta);
966 sjson::parse(obj, json);
967
968 bool refresh_lua = false;
969 sjson::parse_array(list, obj["list"]);
970 for (u32 i = 0; i < array::size(list); ++i) {
971 DynamicString resource(ta);
972 sjson::parse_string(resource, list[i]);
973
974 const char *type = resource_type(resource.c_str());
975 const u32 len = resource_name_length(type, resource.c_str());
976
977 StringId64 resource_type(type);
978 StringId64 resource_name(resource.c_str(), len);
979 bool is_type_reloadable = resource_type == RESOURCE_TYPE_SCRIPT
980 || resource_type == RESOURCE_TYPE_TEXTURE
981 || resource_type == RESOURCE_TYPE_SHADER
982 || resource_type == RESOURCE_TYPE_FONT
983 || resource_type == RESOURCE_TYPE_MATERIAL
984 || resource_type == RESOURCE_TYPE_MESH
985 || resource_type == RESOURCE_TYPE_RENDER_CONFIG
986 || resource_type == RESOURCE_TYPE_SOUND
987 || resource_type == RESOURCE_TYPE_SPRITE
988 || resource_type == RESOURCE_TYPE_SPRITE_ANIMATION
989 || resource_type == RESOURCE_TYPE_UNIT
990 || resource_type == RESOURCE_TYPE_STATE_MACHINE
991 ;
992
993 if (is_type_reloadable && _resource_manager->can_get(resource_type, resource_name)) {
994 const void *old_resource = _resource_manager->get(resource_type, resource_name);
995 const void *new_resource = _resource_manager->reload(resource_type, resource_name);
996
997 if (resource_type == RESOURCE_TYPE_SCRIPT) {
998 refresh_lua = true;
999 } else if (resource_type == RESOURCE_TYPE_TEXTURE) {
1000 _material_manager->reload_textures((TextureResource *)old_resource, (TextureResource *)new_resource);
1001 } else if (resource_type == RESOURCE_TYPE_SHADER) {
1002 _pipeline->reload_shaders((ShaderResource *)old_resource, (ShaderResource *)new_resource);
1003 _material_manager->reload_shaders((ShaderResource *)old_resource, (ShaderResource *)new_resource);
1004 } else if (resource_type == RESOURCE_TYPE_MATERIAL) {
1005 ListNode *cur;
1006 list_for_each(cur, &_worlds)
1007 {
1008 World *w = (World *)container_of(cur, World, _node);
1009 w->reload_materials((MaterialResource *)old_resource, (MaterialResource *)new_resource);
1010 }
1011 } else if (resource_type == RESOURCE_TYPE_MESH) {
1012 ListNode *cur;
1013 list_for_each(cur, &_worlds)
1014 {
1015 World *w = (World *)container_of(cur, World, _node);
1016 w->_render_world->reload_meshes((MeshResource *)old_resource, (MeshResource *)new_resource);

Callers 1

device_message_refreshFunction · 0.80

Calls 15

merged_render_settingsFunction · 0.85
can_getMethod · 0.80
reload_meshesMethod · 0.80
reload_spritesMethod · 0.80
reload_unitsMethod · 0.80
parseFunction · 0.50
parse_arrayFunction · 0.50
sizeFunction · 0.50
parse_stringFunction · 0.50
c_strMethod · 0.45
getMethod · 0.45
reloadMethod · 0.45

Tested by

no test coverage detected