Skip to content

Commit

Permalink
Merge branch 'main' of github.com:X-R-G-B/B-luga
Browse files Browse the repository at this point in the history
  • Loading branch information
TTENSHII committed Nov 4, 2023
2 parents f669b2b + 15db902 commit fccd412
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ namespace Raylib {
InitWindow(width, height, title.c_str());
}

static void setWindowSize(int width, int height)
{
SetWindowSize(width, height);
}

bool Window::windowShouldClose()
{
return WindowShouldClose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ namespace Raylib {
public:
static void initWindow(int width, int height, const std::string &title);

static void setWindowSize(int width, int height);

static bool windowShouldClose();

static void closeWindow();
Expand Down
18 changes: 10 additions & 8 deletions libs/B-luga-graphics/src/RaylibImpl/Graphics/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@ namespace Raylib {

::Texture2D &TextureManagerImpl::getTexture(const std::string &path)
{
std::lock_guard<std::mutex> lock(_mutex);
preloadTexture(path);
auto fileName = PathResolver::resolve(path);
return loadTexture(path);
}

return _textures[fileName];
::Texture2D &TextureManagerImpl::loadTexture(const std::string &path)
{
std::lock_guard<std::mutex> lock(_mutex);
if (_textures.find(path) == _textures.end()) {
_textures[path] = LoadTexture(path.c_str());
}
return _textures[path];
}

void TextureManagerImpl::preloadTexture(const std::string &path)
{
std::lock_guard<std::mutex> lock(_mutex);
auto fileName = PathResolver::resolve(path);

if (_textures.find(fileName) == _textures.end()) {
_textures[fileName] = LoadTexture(fileName.c_str());
}
loadTexture(fileName);
}

void TextureManagerImpl::unloadTextures()
Expand Down
1 change: 1 addition & 0 deletions libs/B-luga-graphics/src/RaylibImpl/Graphics/Graphics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ namespace Raylib {
private:
std::map<std::string, ::Texture2D> _textures;
std::mutex _mutex;
::Texture2D &loadTexture(const std::string &path);
};

class SpriteImpl : public Sprite {
Expand Down
25 changes: 11 additions & 14 deletions libs/B-luga/include/B-luga/Json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ class Json {

void registerJsonFile(const std::string &path)
{
getJsonData(path);
const std::string path_resolved = PathResolver::resolve(path);

if (_jsonDatas.find(path_resolved) == _jsonDatas.end()) {
_jsonDatas.insert({path_resolved, loadJsonData(path_resolved)});
}
}

template <typename T>
Expand All @@ -49,7 +53,8 @@ class Json {
template <typename T>
T getDataByJsonType(const std::string &dataType, const std::string &index)
{
nlohmann::json finalData = getJsonData(dataType);
const std::string path_resolved = PathResolver::resolve(dataType);
nlohmann::json finalData(_jsonDatas[path_resolved]);

finalData = finalData[index];
if (finalData == nullptr) {
Expand All @@ -62,14 +67,16 @@ class Json {

nlohmann::json getDataByJsonType(const std::string &dataType)
{
nlohmann::json data = getJsonData(dataType);
const std::string path_resolved = PathResolver::resolve(dataType);
nlohmann::json data(_jsonDatas[path_resolved]);

return (data);
}

nlohmann::basic_json<> getDataByJsonType(const std::string &dataType, const std::string &index)
{
nlohmann::basic_json<> finalData = getJsonData(dataType);
const std::string path_resolved = PathResolver::resolve(dataType);
nlohmann::basic_json<> finalData(_jsonDatas[path_resolved]);

finalData = finalData[index];
if (finalData == nullptr) {
Expand Down Expand Up @@ -226,15 +233,5 @@ class Json {
return jsonData;
}

nlohmann::json getJsonData(const std::string &path)
{
const std::string path_resolved = PathResolver::resolve(path);

if (_jsonDatas.find(path_resolved) == _jsonDatas.end()) {
_jsonDatas.insert({path_resolved, loadJsonData(path_resolved)});
}
return _jsonDatas[path_resolved];
}

std::unordered_map<std::string, nlohmann::json> _jsonDatas;
};

0 comments on commit fccd412

Please sign in to comment.