Some refactoring. Added a define for the default callresult/callback timeout.

This commit is contained in:
Mr_Goldberg 2020-06-20 21:14:37 -04:00
parent 25d53b6542
commit beffb89bda
No known key found for this signature in database
GPG Key ID: 8597D87419DEF278
2 changed files with 22 additions and 13 deletions

View File

@ -191,6 +191,19 @@ std::string get_lib_path() {
} }
#endif #endif
std::string get_full_lib_path()
{
std::string program_path;
#if defined(STEAM_WIN32)
char DllPath[MAX_PATH] = {0};
GetModuleFileName((HINSTANCE)&__ImageBase, DllPath, _countof(DllPath));
program_path = DllPath;
#else
program_path = get_lib_path();
#endif
return program_path;
}
std::string get_full_program_path() std::string get_full_program_path()
{ {
std::string env_program_path = get_env_variable("SteamAppPath"); std::string env_program_path = get_env_variable("SteamAppPath");
@ -203,15 +216,8 @@ std::string get_full_program_path()
} }
std::string program_path; std::string program_path;
#if defined(STEAM_WIN32) program_path = get_full_lib_path();
char DllPath[MAX_PATH] = {0}; return program_path.substr(0, program_path.rfind(PATH_SEPARATOR)).append(PATH_SEPARATOR);
GetModuleFileName((HINSTANCE)&__ImageBase, DllPath, _countof(DllPath));
program_path = DllPath;
#else
program_path = get_lib_path();
#endif
program_path = program_path.substr(0, program_path.rfind(PATH_SEPARATOR)).append(PATH_SEPARATOR);
return program_path;
} }
std::string get_current_path() std::string get_current_path()

View File

@ -161,10 +161,13 @@ CSteamID generate_steam_id_user();
CSteamID generate_steam_id_server(); CSteamID generate_steam_id_server();
CSteamID generate_steam_id_anonserver(); CSteamID generate_steam_id_anonserver();
CSteamID generate_steam_id_lobby(); CSteamID generate_steam_id_lobby();
std::string get_full_lib_path();
std::string get_full_program_path(); std::string get_full_program_path();
std::string get_current_path(); std::string get_current_path();
std::string canonical_path(std::string path); std::string canonical_path(std::string path);
#define DEFAULT_CB_TIMEOUT 0.002
class SteamCallResults { class SteamCallResults {
std::vector<struct Steam_Call_Result> callresults; std::vector<struct Steam_Call_Result> callresults;
std::vector<class CCallbackBase *> completed_callbacks; std::vector<class CCallbackBase *> completed_callbacks;
@ -238,7 +241,7 @@ public:
} }
} }
SteamAPICall_t addCallResult(SteamAPICall_t api_call, int iCallback, void *result, unsigned int size, double timeout=0.0, bool run_call_completed_cb=true) { SteamAPICall_t addCallResult(SteamAPICall_t api_call, int iCallback, void *result, unsigned int size, double timeout=DEFAULT_CB_TIMEOUT, bool run_call_completed_cb=true) {
auto cb_result = std::find_if(callresults.begin(), callresults.end(), [api_call](struct Steam_Call_Result const& item) { return item.api_call == api_call; }); auto cb_result = std::find_if(callresults.begin(), callresults.end(), [api_call](struct Steam_Call_Result const& item) { return item.api_call == api_call; });
if (cb_result != callresults.end()) { if (cb_result != callresults.end()) {
if (cb_result->reserved) { if (cb_result->reserved) {
@ -266,7 +269,7 @@ public:
return callresults.back().api_call; return callresults.back().api_call;
} }
SteamAPICall_t addCallResult(int iCallback, void *result, unsigned int size, double timeout=0.0, bool run_call_completed_cb=true) { SteamAPICall_t addCallResult(int iCallback, void *result, unsigned int size, double timeout=DEFAULT_CB_TIMEOUT, bool run_call_completed_cb=true) {
return addCallResult(generate_steam_api_call_id(), iCallback, result, size, timeout, run_call_completed_cb); return addCallResult(generate_steam_api_call_id(), iCallback, result, size, timeout, run_call_completed_cb);
} }
@ -419,11 +422,11 @@ public:
} }
void addCBResult(int iCallback, void *result, unsigned int size) { void addCBResult(int iCallback, void *result, unsigned int size) {
addCBResult(iCallback, result, size, 0.0, false); addCBResult(iCallback, result, size, DEFAULT_CB_TIMEOUT, false);
} }
void addCBResult(int iCallback, void *result, unsigned int size, bool dont_post_if_already) { void addCBResult(int iCallback, void *result, unsigned int size, bool dont_post_if_already) {
addCBResult(iCallback, result, size, 0.0, dont_post_if_already); addCBResult(iCallback, result, size, DEFAULT_CB_TIMEOUT, dont_post_if_already);
} }
void addCBResult(int iCallback, void *result, unsigned int size, double timeout) { void addCBResult(int iCallback, void *result, unsigned int size, double timeout) {