Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
[linux] add starts_with+ends_with and use it when textures loading
Browse files Browse the repository at this point in the history
  • Loading branch information
q4a committed May 17, 2022
1 parent 4a73cd1 commit 87cdb7d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/libs/common/include/v_file_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
#include <string>
#include <vector>

inline bool starts_with(const std::string &str, const std::string &prefix)
{
return str.size() >= prefix.size() && 0 == str.compare(0, prefix.size(), prefix);
}

inline bool ends_with(const std::string &str, const std::string &suffix)
{
return str.size() >= suffix.size() && 0 == str.compare(str.size() - suffix.size(), suffix.size(), suffix);
}

class INIFILE;

class VFILE_SERVICE
Expand Down
10 changes: 3 additions & 7 deletions src/libs/renderer/src/s_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1435,13 +1435,9 @@ bool DX9RENDER::TextureLoad(int32_t t)
return false;
}

std::string_view name_sv(Textures[t].name, strlen(Textures[t].name));
auto has_resource_prefix =
std::distance(std::ranges::search(name_sv, "resource\\textures\\"sv, storm::detail::is_iequal{}).begin(),
name_sv.begin()) == 0;
auto has_tx_postfix =
std::distance(std::ranges::search(name_sv, ".tx"sv, storm::detail::is_iequal{}).begin(),
name_sv.end()) == 3;
tolwr(Textures[t].name);
auto has_resource_prefix = starts_with(Textures[t].name, "resource\\textures\\");
auto has_tx_postfix = ends_with(Textures[t].name, ".tx");

sprintf_s(fn, "%s%s%s", has_resource_prefix ? "" : "resource\\textures\\", Textures[t].name, has_tx_postfix ? "" : ".tx");

Expand Down

0 comments on commit 87cdb7d

Please sign in to comment.