Upd
This commit is contained in:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user