Threads and tasks

This commit is contained in:
2026-01-29 15:28:50 +03:00
parent 4cf0ea5321
commit da4c1fee0e
21 changed files with 1464 additions and 558 deletions

View File

@@ -2,6 +2,8 @@
#define __ITEMS_H__
#include <OgreMeshLodGenerator.h>
#include <flecs.h>
#include "Components.h"
#include "GameData.h"
namespace ECS
{
namespace Items

View File

@@ -19,6 +19,7 @@
#include "LuaData.h"
#include "PlayerActionModule.h"
#include "CharacterManagerModule.h"
#include "CharacterAIModule.h"
#include "items.h"
#include "town.h"
@@ -2095,7 +2096,69 @@ bool editNPCs(nlohmann::json &npcs)
ImGui::Text("NPC");
int id = 0;
for (auto &npc : npcs) {
ImGui::Text("%s", npc["lastName"].get<Ogre::String>().c_str());
static char firstName[64] = { 0 };
static char lastName[64] = { 0 };
static char nickName[64] = { 0 };
static char tags[256] = { 0 };
if (npc.find("firstName") == npc.end())
npc["firstName"] = "";
if (npc.find("lastName") == npc.end())
npc["lastName"] = "";
if (npc.find("nickName") == npc.end())
npc["nickName"] = "";
if (npc.find("tags") == npc.end())
npc["tags"] = "";
if (npc.find("sex") == npc.end())
npc["sex"] = 1;
strncpy(firstName, npc["firstName"].get<Ogre::String>().c_str(),
sizeof(firstName));
strncpy(lastName, npc["lastName"].get<Ogre::String>().c_str(),
sizeof(lastName));
strncpy(nickName, npc["nickName"].get<Ogre::String>().c_str(),
sizeof(lastName));
strncpy(tags, npc["tags"].get<Ogre::String>().c_str(),
sizeof(tags));
ImGui::InputText(
("Last name##" + Ogre::StringConverter::toString(id))
.c_str(),
lastName, sizeof(lastName));
if (ImGui::IsItemDeactivatedAfterEdit()) {
npc["lastName"] = Ogre::String(lastName);
changed = true;
}
ImGui::InputText(
("First name##" + Ogre::StringConverter::toString(id))
.c_str(),
firstName, sizeof(firstName));
if (ImGui::IsItemDeactivatedAfterEdit()) {
npc["firstName"] = Ogre::String(firstName);
changed = true;
}
ImGui::InputText(
("Nickname##" + Ogre::StringConverter::toString(id))
.c_str(),
nickName, sizeof(nickName));
if (ImGui::IsItemDeactivatedAfterEdit()) {
npc["nickName"] = Ogre::String(nickName);
changed = true;
}
ImGui::InputText(
("Tags##" + Ogre::StringConverter::toString(id)).c_str(),
tags, sizeof(tags));
if (ImGui::IsItemDeactivatedAfterEdit()) {
npc["tags"] = Ogre::String(tags);
changed = true;
}
int selection = npc["sex"].get<int>();
const char *items[] = { "Male", "Female" };
if (ImGui::Combo(("Sex##" + Ogre::StringConverter::toString(id))
.c_str(),
&selection, items, 2))
npc["sex"] = selection;
if (ImGui::SmallButton(
("Spawn##" + Ogre::StringConverter::toString(id))
.c_str())) {
@@ -2121,33 +2184,36 @@ bool editNPCs(nlohmann::json &npcs)
}
id++;
}
ImGui::Text("New NPC");
static char lastName[64] = { 0 };
ImGui::InputText("Last name", lastName, sizeof(lastName));
static char firstName[64] = { 0 };
ImGui::InputText("First name", firstName, sizeof(firstName));
static char tags[256] = { 0 };
ImGui::InputText("Tags", tags, sizeof(firstName));
static int selection = 0;
const char *items[] = { "Male", "Female" };
ImGui::Combo("Sex", &selection, items, 2);
if (ImGui::SmallButton("Add NPC")) {
nlohmann::json npc;
npc["lastName"] = Ogre::String(lastName);
npc["firstName"] = Ogre::String(firstName);
npc["tags"] = Ogre::String(tags);
Ogre::Vector3 npcPosition =
ECS::get<EditorGizmo>().sceneNode->_getDerivedPosition();
Ogre::Quaternion npcOrientation =
ECS::get<EditorGizmo>()
.sceneNode->_getDerivedOrientation();
to_json(npc["position"], npcPosition);
to_json(npc["orientation"], npcOrientation);
npc["sex"] = selection;
npc["health"] = 100;
npc["stamina"] = 100;
npcs.push_back(npc);
changed = true;
{
ImGui::Text("New NPC");
static char lastName[64] = { 0 };
ImGui::InputText("Last name", lastName, sizeof(lastName));
static char firstName[64] = { 0 };
ImGui::InputText("First name", firstName, sizeof(firstName));
static char tags[256] = { 0 };
ImGui::InputText("Tags", tags, sizeof(tags));
static int selection = 0;
const char *items[] = { "Male", "Female" };
ImGui::Combo("Sex", &selection, items, 2);
if (ImGui::SmallButton("Add NPC")) {
nlohmann::json npc;
npc["lastName"] = Ogre::String(lastName);
npc["firstName"] = Ogre::String(firstName);
npc["tags"] = Ogre::String(tags);
Ogre::Vector3 npcPosition =
ECS::get<EditorGizmo>()
.sceneNode->_getDerivedPosition();
Ogre::Quaternion npcOrientation =
ECS::get<EditorGizmo>()
.sceneNode->_getDerivedOrientation();
to_json(npc["position"], npcPosition);
to_json(npc["orientation"], npcOrientation);
npc["sex"] = selection;
npc["health"] = 100;
npc["stamina"] = 100;
npcs.push_back(npc);
changed = true;
}
}
ImGui::Separator();
return changed;
@@ -5509,6 +5575,8 @@ struct TownDecorateFurniture : TownTask {
Ogre::Vector3::
UNIT_Y));
node->attachObject(ent);
ent->setRenderingDistance(
60.0f);
addStaticBodyMesh(
e, mesh,
worldCenterPosition +
@@ -5857,6 +5925,11 @@ void createTown(flecs::entity e, Ogre::SceneNode *sceneNode,
});
});
registerTownNPCs(e);
if (ECS::get().entity<CharacterAIModule>().is_valid())
if (ECS::get().has<CharacterAIModule>()) {
ECS::get_mut<CharacterAIModule>().createAI(e);
ECS::modified<CharacterAIModule>();
}
}
}
}