2026-02-18 02:05:44 -04:00
|
|
|
#include <config.h>
|
2025-08-03 08:22:45 -04:00
|
|
|
#include <iostream>
|
2025-09-09 12:02:03 -04:00
|
|
|
#include <opts.h>
|
2026-02-22 18:54:56 -04:00
|
|
|
#include <componentThread.h>
|
2024-09-08 01:04:41 +10:00
|
|
|
#include <mind.h>
|
2025-12-26 01:18:39 -04:00
|
|
|
#include <mindThread.h>
|
2025-09-14 22:17:19 -04:00
|
|
|
#include <director/director.h>
|
|
|
|
|
#include <simulator/simulator.h>
|
2025-10-01 18:47:42 -04:00
|
|
|
#include <stimBuffApis/stimBuffApiManager.h>
|
2026-02-22 17:46:27 -04:00
|
|
|
#include <marionette/marionette.h>
|
2025-07-30 09:09:38 -04:00
|
|
|
|
|
|
|
|
namespace smo {
|
|
|
|
|
|
2025-09-03 14:43:00 -04:00
|
|
|
Mind::Mind(void)
|
2026-02-18 02:05:18 -04:00
|
|
|
: sscl::PuppetApplication(
|
2025-12-27 16:21:22 -04:00
|
|
|
std::vector<std::shared_ptr<sscl::PuppetThread>>{
|
2026-02-22 17:46:27 -04:00
|
|
|
std::make_shared<MindThread>(
|
2026-02-22 18:54:56 -04:00
|
|
|
SmoThreadId::DIRECTOR, getThreadName(SmoThreadId::DIRECTOR),
|
2026-02-22 17:46:27 -04:00
|
|
|
sscl::PuppetComponent::defaultPuppetMain, director,
|
|
|
|
|
&MindComponent::preJoltHook),
|
|
|
|
|
std::make_shared<MindThread>(
|
2026-02-22 18:54:56 -04:00
|
|
|
SmoThreadId::SIMULATOR, getThreadName(SmoThreadId::SIMULATOR),
|
2026-02-22 17:46:27 -04:00
|
|
|
sscl::PuppetComponent::defaultPuppetMain, canvas,
|
|
|
|
|
&MindComponent::preJoltHook),
|
|
|
|
|
std::make_shared<MindThread>(
|
|
|
|
|
SmoThreadId::SUBCONSCIOUS,
|
2026-02-22 18:54:56 -04:00
|
|
|
getThreadName(SmoThreadId::SUBCONSCIOUS),
|
2026-02-22 17:46:27 -04:00
|
|
|
sscl::PuppetComponent::defaultPuppetMain, subconscious,
|
|
|
|
|
&MindComponent::preJoltHook),
|
|
|
|
|
std::make_shared<MindThread>(
|
2026-02-22 18:54:56 -04:00
|
|
|
SmoThreadId::BODY, getThreadName(SmoThreadId::BODY),
|
2026-02-22 17:46:27 -04:00
|
|
|
sscl::PuppetComponent::defaultPuppetMain, body,
|
|
|
|
|
&MindComponent::preJoltHook)
|
2025-10-01 11:02:28 -04:00
|
|
|
#ifndef CONFIG_WORLD_USE_BODY_THREAD
|
2026-02-22 17:46:27 -04:00
|
|
|
, std::make_shared<MindThread>(
|
2026-02-22 18:54:56 -04:00
|
|
|
SmoThreadId::WORLD, getThreadName(SmoThreadId::WORLD),
|
2026-02-22 17:46:27 -04:00
|
|
|
sscl::PuppetComponent::defaultPuppetMain, world,
|
|
|
|
|
&MindComponent::preJoltHook)
|
2025-09-14 22:17:19 -04:00
|
|
|
#endif
|
2026-02-18 02:05:44 -04:00
|
|
|
}
|
|
|
|
|
),
|
|
|
|
|
director(*this, componentThreads[SmoThreadId::DIRECTOR - 1]),
|
|
|
|
|
canvas(*this, componentThreads[SmoThreadId::SIMULATOR - 1]),
|
|
|
|
|
subconscious(*this, componentThreads[SmoThreadId::SUBCONSCIOUS - 1]),
|
|
|
|
|
body(*this, componentThreads[SmoThreadId::BODY - 1]),
|
|
|
|
|
world(*this, componentThreads[SmoThreadId::WORLD - 1])
|
2025-09-03 14:43:00 -04:00
|
|
|
{
|
|
|
|
|
}
|
2025-08-10 13:12:17 -04:00
|
|
|
|
2025-09-14 11:07:05 -04:00
|
|
|
std::shared_ptr<MindThread>
|
2025-12-27 16:21:22 -04:00
|
|
|
Mind::getComponentThread(sscl::ThreadId id) const
|
2025-09-03 14:43:00 -04:00
|
|
|
{
|
2025-12-26 01:18:39 -04:00
|
|
|
if (id == SmoThreadId::MRNTT)
|
2025-09-14 11:07:05 -04:00
|
|
|
{
|
|
|
|
|
throw std::runtime_error(
|
|
|
|
|
std::string(__func__) +
|
|
|
|
|
": MRNTT is not a MindThread and cannot be returned by "
|
|
|
|
|
"getComponentThread");
|
|
|
|
|
}
|
2025-09-03 14:43:00 -04:00
|
|
|
|
2026-05-24 16:12:29 -04:00
|
|
|
// Search through the vector for the thread with matching id
|
|
|
|
|
for (auto& thread : componentThreads)
|
2025-12-27 14:01:15 -04:00
|
|
|
{
|
2026-05-24 16:12:29 -04:00
|
|
|
if (thread->id == id) {
|
2025-12-27 14:01:15 -04:00
|
|
|
return std::static_pointer_cast<MindThread>(thread);
|
|
|
|
|
}
|
2026-05-24 16:12:29 -04:00
|
|
|
}
|
2025-09-03 14:43:00 -04:00
|
|
|
|
2026-05-24 16:12:29 -04:00
|
|
|
// Throw exception if no thread found
|
|
|
|
|
throw std::runtime_error(std::string(__func__) +
|
|
|
|
|
": No MindThread found with ID "
|
2025-09-03 14:43:00 -04:00
|
|
|
+ std::to_string(static_cast<int>(id)));
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-14 11:07:05 -04:00
|
|
|
std::shared_ptr<MindThread>
|
2025-09-03 14:43:00 -04:00
|
|
|
Mind::getComponentThread(const std::string& name) const
|
|
|
|
|
{
|
2025-09-14 11:07:05 -04:00
|
|
|
if (name == "mrntt")
|
|
|
|
|
{
|
|
|
|
|
throw std::runtime_error(
|
|
|
|
|
std::string(__func__) +
|
|
|
|
|
": MRNTT is not a MindThread and cannot be returned by "
|
|
|
|
|
"getComponentThread");
|
|
|
|
|
}
|
2025-09-03 14:43:00 -04:00
|
|
|
|
2026-05-24 16:12:29 -04:00
|
|
|
for (auto& thread : componentThreads)
|
2025-12-27 14:01:15 -04:00
|
|
|
{
|
2026-05-24 16:12:29 -04:00
|
|
|
if (thread->name == name) {
|
2025-12-27 14:01:15 -04:00
|
|
|
return std::static_pointer_cast<MindThread>(thread);
|
|
|
|
|
}
|
2025-09-03 14:43:00 -04:00
|
|
|
}
|
|
|
|
|
|
2026-05-24 16:12:29 -04:00
|
|
|
// Throw exception if no thread found
|
|
|
|
|
throw std::runtime_error(std::string(__func__) +
|
|
|
|
|
": No MindThread found with name '" + name + "'");
|
2025-09-03 14:43:00 -04:00
|
|
|
}
|
|
|
|
|
|
2025-09-14 11:07:05 -04:00
|
|
|
std::vector<std::shared_ptr<MindThread>>
|
2025-09-03 14:43:00 -04:00
|
|
|
Mind::getMindThreads() const
|
|
|
|
|
{
|
2025-12-27 14:01:15 -04:00
|
|
|
std::vector<std::shared_ptr<MindThread>> mindThreads;
|
|
|
|
|
mindThreads.reserve(componentThreads.size());
|
|
|
|
|
for (auto& thread : componentThreads) {
|
|
|
|
|
mindThreads.push_back(std::static_pointer_cast<MindThread>(thread));
|
|
|
|
|
}
|
|
|
|
|
return mindThreads;
|
2025-09-03 14:43:00 -04:00
|
|
|
}
|
|
|
|
|
|
2026-06-06 19:24:00 -04:00
|
|
|
mrntt::MrnttViralNonPostingInvokerT<void> Mind::initializeCReq()
|
2025-09-11 20:11:10 -04:00
|
|
|
{
|
2026-05-24 16:12:29 -04:00
|
|
|
try
|
2025-09-15 15:01:26 -04:00
|
|
|
{
|
2026-05-24 16:12:29 -04:00
|
|
|
distributeAndPinThreadsAcrossCpus();
|
2025-09-11 20:11:10 -04:00
|
|
|
}
|
2026-05-24 16:12:29 -04:00
|
|
|
catch (const std::exception& e)
|
2025-09-11 20:11:10 -04:00
|
|
|
{
|
2026-05-24 16:12:29 -04:00
|
|
|
std::cerr << "Salmanoff couldn't distribute the mind threads across "
|
|
|
|
|
"the CPUs, so performance may be suboptimal.\n"
|
|
|
|
|
"Error: " << e.what() << "\n";
|
2025-09-12 16:09:26 -04:00
|
|
|
}
|
|
|
|
|
|
2026-05-24 16:12:29 -04:00
|
|
|
co_await joltAllPuppetThreadsCReq();
|
|
|
|
|
std::cout << "Mrntt: All mind threads JOLTed." << "\n";
|
2025-09-11 20:11:10 -04:00
|
|
|
|
2026-05-24 16:12:29 -04:00
|
|
|
co_await startAllPuppetThreadsCReq();
|
|
|
|
|
std::cout << "Mrntt: All mind threads started." << "\n";
|
2025-09-15 15:01:26 -04:00
|
|
|
|
2026-06-06 19:24:00 -04:00
|
|
|
co_await body.initializeCReq();
|
2026-05-24 16:12:29 -04:00
|
|
|
std::cout << "Mrntt: Body component initialized." << "\n";
|
2025-09-12 16:09:26 -04:00
|
|
|
|
2026-06-06 19:24:00 -04:00
|
|
|
co_return;
|
2026-05-24 16:12:29 -04:00
|
|
|
}
|
2025-09-11 20:11:10 -04:00
|
|
|
|
2026-06-06 19:24:00 -04:00
|
|
|
mrntt::MrnttViralNonPostingInvokerT<void> Mind::finalizeCReq()
|
2025-09-11 20:11:10 -04:00
|
|
|
{
|
2026-06-06 19:24:00 -04:00
|
|
|
co_await body.finalizeCReq();
|
|
|
|
|
std::cout << "Mrntt: Body component finalized." << "\n";
|
2025-09-11 20:11:10 -04:00
|
|
|
|
2026-05-24 16:12:29 -04:00
|
|
|
co_await joltAllPuppetThreadsCReq();
|
|
|
|
|
std::cout << "Mrntt: All mind threads JOLTed for finalization." << "\n";
|
2025-09-11 20:11:10 -04:00
|
|
|
|
2026-05-24 16:12:29 -04:00
|
|
|
co_await exitAllPuppetThreadsCReq();
|
|
|
|
|
std::cout << "Mrntt: All mind threads exited." << "\n";
|
2025-09-11 20:11:10 -04:00
|
|
|
|
2026-06-06 19:24:00 -04:00
|
|
|
co_return;
|
2025-09-12 16:09:26 -04:00
|
|
|
}
|
|
|
|
|
|
2025-07-30 09:09:38 -04:00
|
|
|
} // namespace smo
|