/
Mr.Stalin
/
FOnline-Engine
Обзор
Документация
Войти
/
Mr.Stalin
/
FOnline-Engine
Код
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Source/Tools/AngelScriptBaker.cpp
154 строки
5 KB
cvet
Non const locals (#190)
24 июл 2026, 10:46
Не верифицирован
24 июл 2026, 10:46
4883d25
Код
Авторство
О чём код?
// __________ ___ ______ _ // / ____/ __ \____ / (_)___ ___ / ____/___ ____ _(_)___ ___ // / /_ / / / / __ \/ / / __ \/ _ \ / __/ / __ \/ __ `/ / __ \/ _ ` // / __/ / /_/ / / / / / / / / / __/ / /___/ / / / /_/ / / / / / __/ // /_/ \____/_/ /_/_/_/_/ /_/\___/ /_____/_/ /_/\__, /_/_/ /_/\___/ // /____/ // FOnline Engine // https://fonline.ru // https://github.com/cvet/fonline // // MIT License // // Copyright (c) 2006 - 2026, Anton Tsvetinskiy aka cvet <cvet@tut.by> // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // #include "AngelScriptBaker.h" #if FO_ANGELSCRIPT_SCRIPTING #include "AngelScriptScripting.h" #include "Application.h" FO_BEGIN_NAMESPACE AngelScriptBaker::AngelScriptBaker(shared_ptr<BakingContext> ctx) : BaseBaker(std::move(ctx), NAME) { FO_STACK_TRACE_ENTRY(); } AngelScriptBaker::~AngelScriptBaker() { FO_STACK_TRACE_ENTRY(); } void AngelScriptBaker::BakeFiles(const FileCollection& files, string_view target_path) const { FO_STACK_TRACE_ENTRY(); if (!target_path.empty() && !strex(target_path).get_file_extension().starts_with("fos-")) { return; } // Collect files vector<File> filtered_files; uint64_t max_write_time = 0; for (const auto& file_header : files) { string ext = strex(file_header.GetPath()).get_file_extension(); if (ext != "fos") { continue; } max_write_time = std::max(max_write_time, file_header.GetWriteTime()); filtered_files.emplace_back(File::Load(file_header)); } if (filtered_files.empty()) { return; } bool bake_server = !_context->BakeChecker || _context->BakeChecker(_context->PackName + ".fos-bin-server", max_write_time); bool bake_client = !_context->BakeChecker || _context->BakeChecker(_context->PackName + ".fos-bin-client", max_write_time); bool bake_mapper = !_context->BakeChecker || _context->BakeChecker(_context->PackName + ".fos-bin-mapper", max_write_time); if (!bake_server && !bake_client && !bake_mapper) { return; } // Process files vector<std::future<void>> file_bakings; mutex messages_locker; unordered_set<string> messages; auto message_callback = [&](string_view message) { scoped_lock lock {messages_locker}; if (messages.contains(message)) { return; } messages.emplace(message); WriteLog(message); }; if (bake_server) { file_bakings.emplace_back(run_async(GetAsyncMode(), "BakeAngelScript-Server", [&] { auto engine = BakerServerEngine(*_context->BakedFiles); auto data = CompileAngelScript(&engine, *_context->Settings, filtered_files, message_callback); _context->WriteData(_context->PackName + ".fos-bin-server", data); })); } if (bake_client) { file_bakings.emplace_back(run_async(GetAsyncMode(), "BakeAngelScript-Client", [&] { auto engine = BakerClientEngine(*_context->BakedFiles); auto data = CompileAngelScript(&engine, *_context->Settings, filtered_files, message_callback); _context->WriteData(_context->PackName + ".fos-bin-client", data); })); } if (bake_mapper) { file_bakings.emplace_back(run_async(GetAsyncMode(), "BakeAngelScript-Mapper", [&] { auto engine = BakerMapperEngine(*_context->BakedFiles); auto data = CompileAngelScript(&engine, *_context->Settings, filtered_files, message_callback); _context->WriteData(_context->PackName + ".fos-bin-mapper", data); })); } size_t errors = 0; for (auto& file_baking : file_bakings) { try { file_baking.get(); } catch (const ScriptCompilerException& ex) { WriteLog("AngelScript compile error: {}", ex.what()); errors++; } catch (const std::exception& ex) { if (_context->ForceSyncMode.value_or(false)) { throw; } WriteLog("AngelScript error: {}", ex.what()); errors++; } } if (errors != 0) { throw AngelScriptBakerException("Errors during scripts compilation"); } } FO_END_NAMESPACE #endif