Set items to static
Set items to static and call the json load only once.inventory_pr
parent
7853451b01
commit
fb31aef9b2
|
@ -0,0 +1,5 @@
|
||||||
|
#include "steam_inventory.h"
|
||||||
|
|
||||||
|
std::once_flag Steam_Inventory::items_loading;
|
||||||
|
std::atomic_bool Steam_Inventory::items_loaded(false);
|
||||||
|
std::map<SteamItemDef_t, std::map<std::string, std::string>> Steam_Inventory::items;
|
|
@ -46,7 +46,9 @@ class Steam_Inventory :
|
||||||
|
|
||||||
std::vector<struct Steam_Inventory_Requests> inventory_requests;
|
std::vector<struct Steam_Inventory_Requests> inventory_requests;
|
||||||
|
|
||||||
std::map<SteamItemDef_t, std::map<std::string, std::string>> items;
|
static std::once_flag items_loading;
|
||||||
|
static std::atomic_bool items_loaded;
|
||||||
|
static std::map<SteamItemDef_t, std::map<std::string, std::string>> items;
|
||||||
// Like typedefs
|
// Like typedefs
|
||||||
using item_iterator = std::map<SteamItemDef_t, std::map<std::string, std::string>>::iterator;
|
using item_iterator = std::map<SteamItemDef_t, std::map<std::string, std::string>>::iterator;
|
||||||
using attr_iterator = std::map<std::string, std::string>::iterator;
|
using attr_iterator = std::map<std::string, std::string>::iterator;
|
||||||
|
@ -58,8 +60,6 @@ class Steam_Inventory :
|
||||||
// Or find a server somewhere to hold the data for us then cache on local settings.
|
// Or find a server somewhere to hold the data for us then cache on local settings.
|
||||||
bool need_load_definitions = true;
|
bool need_load_definitions = true;
|
||||||
|
|
||||||
std::atomic_bool items_loaded;
|
|
||||||
|
|
||||||
struct Steam_Inventory_Requests* new_inventory_result(const SteamItemInstanceID_t* pInstanceIDs = NULL, uint32 unCountInstanceIDs = 0)
|
struct Steam_Inventory_Requests* new_inventory_result(const SteamItemInstanceID_t* pInstanceIDs = NULL, uint32 unCountInstanceIDs = 0)
|
||||||
{
|
{
|
||||||
static SteamInventoryResult_t result;
|
static SteamInventoryResult_t result;
|
||||||
|
@ -91,11 +91,13 @@ public:
|
||||||
|
|
||||||
Steam_Inventory(class Settings *settings, class SteamCallResults *callback_results, class SteamCallBacks *callbacks)
|
Steam_Inventory(class Settings *settings, class SteamCallResults *callback_results, class SteamCallBacks *callbacks)
|
||||||
{
|
{
|
||||||
std::string items_db_file(Local_Storage::get_game_settings_path() + "items.json");
|
std::call_once(items_loading, [&]()
|
||||||
PRINT_DEBUG("Items file path: %s\n", items_db_file.c_str());
|
{
|
||||||
items_loaded = false;
|
std::string items_db_file(Local_Storage::get_game_settings_path() + "items.json");
|
||||||
std::thread items_load_thread(read_items_db, items_db_file, &items, &items_loaded);
|
PRINT_DEBUG("Items file path: %s\n", items_db_file.c_str());
|
||||||
items_load_thread.detach();
|
std::thread items_load_thread(read_items_db, items_db_file, &items, &items_loaded);
|
||||||
|
items_load_thread.detach();
|
||||||
|
});
|
||||||
|
|
||||||
this->settings = settings;
|
this->settings = settings;
|
||||||
this->callbacks = callbacks;
|
this->callbacks = callbacks;
|
||||||
|
@ -815,4 +817,4 @@ bool SubmitUpdateProperties( SteamInventoryUpdateHandle_t handle, SteamInventory
|
||||||
PRINT_DEBUG("SubmitUpdateProperties\n");
|
PRINT_DEBUG("SubmitUpdateProperties\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
Loading…
Reference in New Issue