This commit is contained in:
2026-03-05 01:42:40 +03:00
parent 2815369bb8
commit 4290e99c61
31 changed files with 2285 additions and 99 deletions

View File

@@ -30,21 +30,19 @@ void engineWarning(const char* msg)
LuaPlus::LuaObject engineCreateEntity(const char* classname)
{
LuaPlus::LuaObject entityObject;
entityObject.AssignNewTable(GetLuaState());
Entity* entity = static_cast<Entity*>(g_game->Lua_CreateEntity(classname));
SDL_assert_always(entity);
//GameObject* entity = (GameObject*)g_entityManager->createEntity(classname);
//entity->init_from_lua(entityObject);
//entity->init();
return entityObject;
return entity->GetLuaObject();
}
void engineAddEntityToWorld(LuaPlus::LuaObject& object)
{
LuaPlus::LuaObject cppclass = object["__cpp_entity"];
LuaPlus::LuaObject cppclass = object["__object"];
SDL_assert_always(cppclass.IsLightUserdata());
// todo
Entity* entity = static_cast<Entity*>(cppclass.GetLightUserdata());
g_world->AddEntity(entity);
}
void registerEngine()
@@ -108,6 +106,11 @@ void initializeEntityPrototypesFromLua()
prototype.m_description = description.ToString();
g_prototypes.push_back(prototype);
// get a prototype
LuaObject prototypeTable = GetLuaState().GetGlobal(luaname.ToString());
SDL_assert_always(!prototypeTable.IsNil());
prototypeTable.SetObject("__index", prototypeTable);
/*for (LuaTableIterator it2(entityTable); it2; it2.Next()) {
Logger::Msg("%s", it2.GetValue().ToString());
@@ -180,9 +183,9 @@ void Game::LoadLevelXML(const char* mapname)
// std::map<std::string, std::string> properties;
for (pugi::xml_node entity : doc.child("Level").child("Entities").children("Entity")) {
pugi::xml_attribute entityname = entity.attribute("name");
pugi::xml_attribute classname = entity.attribute("classname");
for (pugi::xml_node entitynode : doc.child("Level").child("Entities").children("Entity")) {
pugi::xml_attribute entityname = entitynode.attribute("name");
pugi::xml_attribute classname = entitynode.attribute("classname");
if (classname.empty()) {
if (!entityname.empty()) {
@@ -199,6 +202,16 @@ void Game::LoadLevelXML(const char* mapname)
if (!entity)
entity = g_entityManager->CreateEntity(classname.as_string());
pugi::xml_node position = entitynode.child("Position");
if (position)
{
float x = position.attribute("x").as_float();
float y = position.attribute("y").as_float();
float z = position.attribute("z").as_float();
entity->SetPosition(glm::vec3(x, y, z));
}
//IEntityBase* entity = g_entityManager->CreateEntity(classname.as_string());
g_world->AddEntity(entity);
}
@@ -235,7 +248,7 @@ IEntityBase* Game::Lua_CreateEntity(const char* classname)
// get a prototype
LuaObject prototype = GetLuaState().GetGlobal(pluaprototype->m_luaname.c_str());
SDL_assert_always(!prototype.IsNil());
prototype.SetObject("__index", prototype);
//prototype.SetObject("__index", prototype);
// generate table
LuaObject factory = GetLuaState().GetGlobal("g_factory");