Skip to content

Commit

Permalink
feat: port API helper funcs from other clibs
Browse files Browse the repository at this point in the history
  • Loading branch information
qudix committed Sep 17, 2024
1 parent 7e246e9 commit 8499204
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
7 changes: 4 additions & 3 deletions include/SFSE/API.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ namespace SFSE

void RegisterForAPIInitEvent(const std::function<void()>& a_fn);

std::string_view GetPluginName() noexcept;
std::string_view GetPluginAuthor() noexcept;
REL::Version GetPluginVersion() noexcept;

PluginHandle GetPluginHandle() noexcept;

const TrampolineInterface* GetTrampolineInterface() noexcept;

const MessagingInterface* GetMessagingInterface() noexcept;

const MenuInterface* GetMenuInterface() noexcept;

const TaskInterface* GetTaskInterface() noexcept;

Trampoline& GetTrampoline();
Expand Down
33 changes: 30 additions & 3 deletions src/SFSE/API.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ namespace SFSE
return singleton;
}

std::string_view pluginName{};
std::string_view pluginAuthor{};
REL::Version pluginVersion{};

PluginHandle pluginHandle{ static_cast<PluginHandle>(-1) };

TrampolineInterface* trampolineInterface{};
Expand Down Expand Up @@ -55,15 +59,23 @@ namespace SFSE
{
stl_assert(a_intfc, "interface is null"sv);

if (a_log)
log::init();

(void)REL::Module::get();

auto& storage = detail::APIStorage::get();
const auto& intfc = *a_intfc;

const std::scoped_lock l(storage.apiLock);
if (const auto pluginVersionData = PluginVersionData::GetSingleton()) {
storage.pluginName = pluginVersionData->GetPluginName();
storage.pluginAuthor = pluginVersionData->GetAuthorName();
storage.pluginVersion = pluginVersionData->GetPluginVersion();
}

if (a_log) {
log::init();
log::info("{} v{}", GetPluginName(), GetPluginVersion());
}

if (!storage.apiInit) {
storage.pluginHandle = intfc.GetPluginHandle();

Expand Down Expand Up @@ -96,6 +108,21 @@ namespace SFSE
a_fn();
}

std::string_view GetPluginName() noexcept
{
return detail::APIStorage::get().pluginName;
}

std::string_view GetPluginAuthor() noexcept
{
return detail::APIStorage::get().pluginAuthor;
}

REL::Version GetPluginVersion() noexcept
{
return detail::APIStorage::get().pluginVersion;
}

PluginHandle GetPluginHandle() noexcept
{
return detail::APIStorage::get().pluginHandle;
Expand Down
5 changes: 2 additions & 3 deletions src/SFSE/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@ namespace SFSE::log
if (!path)
return;

const auto data = PluginVersionData::GetSingleton();
*path /= std::format("{}.log", data->GetPluginName());
*path /= std::format("{}.log", SFSE::GetPluginName());

std::vector<spdlog::sink_ptr> sinks{
std::make_shared<spdlog::sinks::basic_file_sink_mt>(path->string(), true),
std::make_shared<spdlog::sinks::msvc_sink_mt>()
};

auto logger = std::make_shared<spdlog::logger>("Global", sinks.begin(), sinks.end());
auto logger = std::make_shared<spdlog::logger>("global", sinks.begin(), sinks.end());
#ifndef NDEBUG
logger->set_level(spdlog::level::debug);
logger->flush_on(spdlog::level::debug);
Expand Down

0 comments on commit 8499204

Please sign in to comment.