Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source2gen/include/sdk/interfaces/tier0/IMemAlloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class IMemAlloc {
}
};

extern IMemAlloc* GetMemAlloc();
extern "C" __declspec(dllimport) IMemAlloc* GetMemAlloc();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__declspec is a microsoft-specific attribute. This code would not work on linux.

Would really love to put this under a macro, but for now we have only one use case so we can just inline it.

Suggested change
extern "C" __declspec(dllimport) IMemAlloc* GetMemAlloc();
#if defined(_WIN64) || defined(_WIN32)
extern "C" __declspec(dllimport) IMemAlloc* GetMemAlloc();
#else
extern "C" IMemAlloc* GetMemAlloc();
#endif


#if defined(_MSC_VER)
#pragma warning(pop)
Expand Down
24 changes: 19 additions & 5 deletions source2gen/src/startup/startup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ namespace source2_gen {
}
}

const auto global_scope = sdk::g_schema->GlobalTypeScope();
auto current_enums = global_scope->GetEnumBindings();
for (auto el : current_enums.GetElements()) {
auto& dump{dumped_modules.emplace(el->m_pszModule, unique_module_dump{}).first->second};
dump.enums.emplace(el->m_pszName, el);
}

auto current_classes = global_scope->GetClassBindings();
for (auto el : current_classes.GetElements()) {
auto& dump{dumped_modules.emplace(el->m_pszModule, unique_module_dump{}).first->second};
dump.classes.emplace(el->m_pszName, el);
}

Comment on lines +92 to +104
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a huge fan of code repetition here. How about making a lambda that takes a pointer to CSchemaSystemTypeScope and does this processing so that we can just call lambda in the loop and for the global scope?

std::unordered_map<std::string, module_dump> result{};

for (const auto& [module_name, unique_dump] : dumped_modules) {
Expand Down Expand Up @@ -150,8 +163,8 @@ namespace source2_gen {
}

[[nodiscard]]
constexpr std::string_view GetStaticSdkName(source2_gen::Language language) {
using enum source2_gen::Language;
constexpr std::string_view GetStaticSdkName(Language language) {
using enum Language;
switch (language) {
case cpp:
return "cpp";
Expand Down Expand Up @@ -237,16 +250,17 @@ namespace source2_gen {
}

// @note: @es3n1n: Obtaining type scopes and generating sdk
const auto type_scopes = sdk::g_schema->GetTypeScopes();
Copy link
Collaborator

@es3n1n es3n1n May 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you remove const?

auto type_scopes = sdk::g_schema->GetTypeScopes();
assert(type_scopes.Count() > 0 && "sdk is outdated");


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

const std::unordered_map all_modules = CollectModules(std::span{type_scopes.m_pElements, static_cast<std::size_t>(type_scopes.m_Size)});

sdk::GeneratorCache cache{};
std::unordered_set<std::filesystem::path> generated_files{};

for (const auto& [module_name, dump] : all_modules) {
const auto result = sdk::GenerateTypeScopeSdk(options, cache, module_name, dump.enums, dump.classes);
const auto result = GenerateTypeScopeSdk(options, cache, module_name, dump.enums, dump.classes);
std::ranges::move(result.generated_files, std::inserter(generated_files, generated_files.end()));
}

Expand All @@ -256,7 +270,7 @@ namespace source2_gen {
std::filesystem::copy(FindSdkStatic(options), kOutDirName,
std::filesystem::copy_options::recursive | std::filesystem::copy_options::overwrite_existing);

if (options.emit_language == source2_gen::Language::c_ida) {
if (options.emit_language == Language::c_ida) {
PostProcessCIDA(generated_files);
}

Expand Down