Exemplo n.º 1
0
int createEntityWithSize(const char* entityResource, LuaPlus::LuaObject luaPosition, LuaPlus::LuaObject luaSize)
{
	if(!luaPosition.IsTable())
	{
		CORE_LOG("LUA", "Invalid position object passed to create_entity.");
		return INVALID_ENTITY_ID;
	}

	if(!luaSize.IsTable())
	{
		CORE_LOG("LUA", "Invalid size object passed to create_entity.");
		return INVALID_ENTITY_ID;
	}

	sf::Vector2f position = tableToVec2<sf::Vector2f>(luaPosition);
	sf::Vector2f size = tableToVec2<sf::Vector2f>(luaSize);

	artemis::Entity& entity = WorldLocator::getObject()->createEntity();

	// Create entity
	if(!EntityFactory::get().loadFromFile(entityResource, entity))
	{
		CORE_ERROR("Failed to load entity from file: " + std::string(entityResource));
		return INVALID_ENTITY_ID;
	}

	Transform* pTransform = safeGetComponent<Transform>(&entity);

	if(!pTransform)
	{
		entity.addComponent(new Transform(position.x, position.y));
	}
	else 
	{
		pTransform->position = position;
	}

	// Get physics comp
	DynamicBody* pDynamicBody = safeGetComponent<DynamicBody>(&entity);

	if(pDynamicBody)
	{
		// Set dimensions, will be initialized later
		pDynamicBody->setDimensions(size.x, size.y);
	}
	else
	{
		entity.addComponent(new DynamicBody(size.x, size.y));
	}

	// commit entity changes
	entity.refresh();

	CORE_LOG("LUA", "Created entity from: " + std::string(entityResource));

	return entity.getId();
}
Exemplo n.º 2
0
    // /////////////////////////////////////////////////////////////////
    //
    // /////////////////////////////////////////////////////////////////
    bool SetColorFromLua(const LuaPlus::LuaObject &colorData, Vector4 &color)
    {
        if(!colorData.IsTable()) {
            return (false);
        }

        LuaPlus::LuaObject rData = colorData["r"];
        LuaPlus::LuaObject gData = colorData["g"];
        LuaPlus::LuaObject bData = colorData["b"];
        LuaPlus::LuaObject aData = colorData["a"];

        if(!rData.IsNumber() || !gData.IsNumber() || !bData.IsNumber() || !aData.IsNumber()) {
            return (false);
        }

        F32 r = static_cast<F32>(rData.GetNumber());
        F32 g = static_cast<F32>(gData.GetNumber());
        F32 b = static_cast<F32>(bData.GetNumber());
        F32 a = static_cast<F32>(aData.GetNumber());
        Clamp<F32>(r, 0.0f, 1.0f);
        Clamp<F32>(g, 0.0f, 1.0f);
        Clamp<F32>(b, 0.0f, 1.0f);
        Clamp<F32>(a, 0.0f, 1.0f);
        color.Set(r, g, b, a);

        return (true);
    }
Exemplo n.º 3
0
bool LoadScene(const std::string &sceneName)
{
	std::string fullPath;
	fullPath = "Scenes/";
	fullPath += sceneName;
	fullPath += ".lua";

	LuaPlus::LuaStateAuto state;
	state = LuaPlus::LuaState::Create();
	
	int retVal = state->DoFile(fullPath.c_str());
	_ASSERT(retVal==0);

	LuaPlus::LuaObject meshList = state->GetGlobals()["MeshList"];
	_ASSERT(meshList.IsTable());

	int numMeshes = meshList.GetCount();
	for(int meshIndex=1;meshIndex <= meshList.GetCount(); meshIndex++)
	{
		LuaPlus::LuaObject meshObj = meshList[meshIndex];
		LuaPlus::LuaObject nameObj = meshObj["Name"];
		_ASSERT(nameObj.IsString());

		std::string meshName = nameObj.GetString();

		MeshManager::GetInstance().Load(meshName,meshObj);
		Instance *inst = InstanceManager::GetInstance().CreateInstance(meshName);
		inst->SetMeshName(meshName);

	}

	return true;
}
Exemplo n.º 4
0
// ****************************************************************************
// ****************************************************************************
Instance * InstanceManager::Load(const std::string &name)
{
	Instance *inst = Get(name);
	if(inst != NULL)
		return inst;

	std::string fullPath = "Meshes/";
	fullPath += name;
	fullPath += ".lua";

	LuaPlus::LuaState *state = LuaPlus::LuaState::Create();
	_ASSERT(state != NULL);
	
	int retVal = state->DoFile(fullPath.c_str());
	_ASSERT(retVal == 0);

	LuaPlus::LuaObject shaderObj = state->GetGlobals()["MeshList"];
	_ASSERT(shaderObj.IsTable());

	inst = new Instance;
	_ASSERT(inst != NULL);

	m_database[name] = inst;
	return inst;

}
Exemplo n.º 5
0
int ant::InternalLuaScriptExports::createActor( const char* actorArchetype, LuaPlus::LuaObject luaPosition, LuaPlus::LuaObject luaRotation )
{
	if (!luaPosition.IsTable())
	{
		GCC_ERROR("Invalid object passed to createActor(); type = " + std::string(luaPosition.TypeName()));
		return INVALID_ACTOR_ID;
	}

	if (!luaRotation.IsNumber())
	{
		GCC_ERROR("Invalid object passed to createActor(); type = " + std::string(luaRotation.TypeName()));
		return INVALID_ACTOR_ID;
	}

	sf::Vector2f pos(luaPosition["x"].GetFloat(), luaPosition["y"].GetFloat());
	ant::Real rot = luaRotation.GetFloat();

	TiXmlElement *overloads = NULL;
	ActorStrongPtr actor = ant::ISFMLApp::getApp()->getGameLogic()->createActor(actorArchetype, overloads, &pos, &rot);

	if (actor)
	{
		shared_ptr<EvtData_New_Actor> pNewActorEvent(GCC_NEW EvtData_New_Actor(actor->getId()));
		IEventManager::instance()->queueEvent(pNewActorEvent);
		return actor->getId();
	}

	return INVALID_ACTOR_ID;
}
Exemplo n.º 6
0
void InternalScriptExports::ApplyTorque(LuaPlus::LuaObject axisLua, float force, int actorId)
{
    if (axisLua.IsTable())
    {
        Vec3 axis(axisLua["x"].GetFloat(), axisLua["y"].GetFloat(), axisLua["z"].GetFloat());
		g_pApp->m_pGame->VGetGamePhysics()->VApplyTorque(axis, force, actorId);
		return;
    }
    GCC_ERROR("Invalid object passed to ApplyTorque(); type = " + std::string(axisLua.TypeName()));
}
// apply force to an object from lua
void LuaInternalScriptExports::ApplyForce(LuaPlus::LuaObject normalDirectionLua, float force, int gameObjectId)
{
	if (normalDirectionLua.IsTable())
	{
		Vec3 normalDir(normalDirectionLua["x"].GetFloat(), normalDirectionLua["y"].GetFloat(), normalDirectionLua["z"].GetFloat());
		g_pApp->m_pGame->GetGamePhysics()->ApplyForce(normalDir, force, gameObjectId);
		return;
	}
	CB_ERROR("Invalid object passed to ApplyForce(). Type = " + std::string(normalDirectionLua.TypeName()));
}
Exemplo n.º 8
0
float InternalScriptExports::GetYRotationFromVector(LuaPlus::LuaObject vec3)
{
    if (vec3.IsTable())
    {
        Vec3 lookAt(vec3["x"].GetFloat(), vec3["y"].GetFloat(), vec3["z"].GetFloat());
        return ::GetYRotationFromVector(lookAt);
    }

    GCC_ERROR("Invalid object passed to GetYRotationFromVector(); type = " + std::string(vec3.TypeName()));
    return 0;
}
// get the y rotation in radians from a lua vec3
float LuaInternalScriptExports::GetYRotationFromVector(LuaPlus::LuaObject vec3)
{
	// make sure vec3 is a table
	if (vec3.IsTable())
	{
		Vec3 lookAt(vec3["x"].GetFloat(), vec3["y"].GetFloat(), vec3["z"].GetFloat());
		// use the GetYRotationFromVector from math.h
		return ::GetYRotationFromVector(lookAt);
	}

	CB_ERROR("Invalid object passed to GetYRotationFromVector(); type = " + std::string(vec3.TypeName()));
	return 0;
}
Exemplo n.º 10
0
//---------------------------------------------------------------------------------------------------------------------
// This function is called to register an event type with the script to link them.  The simplest way to do this is 
// with the REGISTER_SCRIPT_EVENT() macro, which calls this function.
//---------------------------------------------------------------------------------------------------------------------
void ScriptEvent::RegisterEventTypeWithScript(const char* key, EventType type)
{
	// get or create the EventType table
	LuaPlus::LuaObject eventTypeTable = LuaStateManager::Get()->GetGlobalVars().GetByName("EventType");
	if (eventTypeTable.IsNil())
		eventTypeTable = LuaStateManager::Get()->GetGlobalVars().CreateTable("EventType");

	// error checking
	GCC_ASSERT(eventTypeTable.IsTable());
	GCC_ASSERT(eventTypeTable[key].IsNil());
	
	// add the entry
	eventTypeTable.SetNumber(key, (double)type);
}
// create a game object from lua
int LuaInternalScriptExports::CreateGameObject(const char* objectArchetype, LuaPlus::LuaObject luaPosition, LuaPlus::LuaObject luaYawPitchRoll)
{
	// lua position must be a table
	if (!luaPosition.IsTable())
	{
		CB_ERROR("Invalid object passed to CreateGameObject(). Type = " + std::string(luaPosition.TypeName()));
		return INVALID_GAMEOBJECT_ID;
	}
	// lua yawPitchRoll must be a table
	if (!luaYawPitchRoll.IsTable())
	{
		CB_ERROR("Invalid object passed to CreateGameObject(). Type = " + std::string(luaYawPitchRoll.TypeName()));
		return INVALID_GAMEOBJECT_ID;
	}

	Vec3 position(luaPosition["x"].GetFloat(), luaPosition["y"].GetFloat(), luaPosition["z"].GetFloat());
	Vec3 yawPitchRoll(luaYawPitchRoll["x"].GetFloat(), luaYawPitchRoll["y"].GetFloat(), luaYawPitchRoll["z"].GetFloat());
	// build the transform for the object
	Mat4x4 transform;
	transform.BuildYawPitchRoll(yawPitchRoll.x, yawPitchRoll.y, yawPitchRoll.z);
	transform.SetPosition(position);

	// create the object
	TiXmlElement* overloads = nullptr;
	StrongGameObjectPtr pObject = g_pApp->m_pGame->CreateGameObject(objectArchetype, overloads, &transform);

	// fire the new object created event
	if (pObject)
	{
		shared_ptr<Event_NewGameObject> pNewObjectEvent(CB_NEW Event_NewGameObject(pObject->GetId()));
		IEventManager::Get()->QueueEvent(pNewObjectEvent);
		return pObject->GetId();
	}

	return INVALID_GAMEOBJECT_ID;
}
Exemplo n.º 12
0
 // /////////////////////////////////////////////////////////////////
 //
 // /////////////////////////////////////////////////////////////////
 void LuaStateManager::IdentifyLuaObjectType(LuaPlus::LuaObject &objToTest)
 {
     assert(!objToTest.IsNil() && "Nil!");
     assert(!objToTest.IsBoolean() && "Boolean!");
     assert(!objToTest.IsCFunction() && "C-Function!");
     assert(!objToTest.IsFunction() && "Function!");
     assert(!objToTest.IsInteger() && "Integer!");
     assert(!objToTest.IsLightUserData() && "Light User Data!");
     assert(!objToTest.IsNone() && "None!");
     assert(!objToTest.IsNumber() && "Number!");
     assert(!objToTest.IsString() && "String!");
     assert(!objToTest.IsTable() && "Table!");
     assert(!objToTest.IsUserData() && "User Data!");
     assert(!objToTest.IsWString() && "Wide String!");
     assert(0 && "UNKNOWN!");
 }
Exemplo n.º 13
0
LuaPlus::LuaObject ant::LuaStateManager::createPath( const std::string& path, bool ignoreLastElement /*= false*/ )
{
	StringVec splitPath;
	Split(path,splitPath, '.');
	if (ignoreLastElement)
	{
		splitPath.pop_back();
	}

	LuaPlus::LuaObject context = getGlobalVars();
	for (auto it = splitPath.begin() ; it != splitPath.end() ; it++)
	{
		// Is the context valid?
		if (context.IsNil())
		{
			GCC_ERROR("Something broke in CreatePath(); bailing out (element == " + (*it) + ")");
			return context;  // this will be nil
		}

		// grab whatever exists for this element
		const std::string& element = (*it);
		LuaPlus::LuaObject curr = context.GetByName(element.c_str());

		if (!curr.IsTable())
		{
			// if the element is not a table and not nil, we clobber it
			if (!curr.IsNil())
			{
				GCC_WARNING("Overwriting element '" + element + "' in table");
				context.SetNil(element.c_str());
			}

			// element is either nil or was clobbered so add the new table
			context.CreateTable(element.c_str());
		}

		context = context.GetByName(element.c_str());
	}

	// We have created a complete path here
	return context;
}
Exemplo n.º 14
0
    // /////////////////////////////////////////////////////////////////
    //
    // /////////////////////////////////////////////////////////////////
    SliderControl::SliderControl(const LuaPlus::LuaObject &widgetScriptData, \
                                 boost::shared_ptr<ModelViewProjStackManager> mvpStackManPtr, \
                                 const boost::shared_ptr<GLSLShader> shaderFlatObj, \
                                 const boost::shared_ptr<GLSLShader> shaderTexObj, \
                                 boost::shared_ptr<FTFont> fontPtr, \
                                 const ScreenElementId id) throw(GameException &)\
:
    ControlWidget(widgetScriptData, mvpStackManPtr, shaderFlatObj, shaderTexObj, fontPtr, id)
    , m_sliderPos(0.5f)
    , m_sliderButPtr()
    , m_sliderLineBatch()
    , m_sliding(false)
    , m_eventTypeId(0)
    , m_lineColor(0.0f, 0.0f, 0.0f, 1.0f)
    {
        SetLuaSliderPosition(widgetScriptData.GetByName("SliderPosition"));
        SetLuaEventId(widgetScriptData.GetByName("EventTypeId"));
        std::string buttonTableName;
        LuaPlus::LuaObject tableName = widgetScriptData.GetByName("ButtonTableId");
        if(tableName.IsString()) {
            LuaPlus::LuaObject buttonData = widgetScriptData.GetByName(tableName.GetString());
            if(buttonData.IsTable()) {
                m_sliderButPtr.reset(GCC_NEW ButtonControl(buttonData, mvpStackManPtr, shaderFlatObj, shaderTexObj, fontPtr, 0));
                m_sliderButPtr->VSetPosition(CalculateButtonPositionFromSlider());
                m_sliderButPtr->VSetText("");
                m_sliderButPtr->VSetWidth(GetProjectedButtonWidth());
                m_sliderButPtr->VSetHeight(GetProjectedButtonHeight());
                m_sliderButPtr->VSetVisible(VIsVisible());
                m_sliderButPtr->VSetEnabled(VIsEnabled());
                m_sliderButPtr->SetSendEvent(false);
            } else {
                GF_LOG_TRACE_ERR("SliderControl::SliderControl()", "Creation of scripted slider button failed.  Creating default button");
                CreateDefaultButton(VGetColor(), mvpStackManPtr, fontPtr, shaderFlatObj, shaderTexObj, VIsVisible(), VIsEnabled());
            }
        } else {
            GF_LOG_TRACE_ERR("SliderControl::SliderControl()", "Missing slider button information from script so creating default button");
            CreateDefaultButton(VGetColor(), mvpStackManPtr, fontPtr, shaderFlatObj, shaderTexObj, VIsVisible(), VIsEnabled());
        }

        RebuildSliderLine();
    }
Exemplo n.º 15
0
    // /////////////////////////////////////////////////////////////////
    //
    // /////////////////////////////////////////////////////////////////
    bool SetVector3FromLua(const LuaPlus::LuaObject &dirData, Vector3 &direction)
    {
        if(!dirData.IsTable()) {
            return (false);
        }

        LuaPlus::LuaObject xData = dirData["x"];
        LuaPlus::LuaObject yData = dirData["y"];
        LuaPlus::LuaObject zData = dirData["z"];

        if(!xData.IsNumber() || !yData.IsNumber() || !zData.IsNumber()) {
            return (false);
        }

        F32 x = static_cast<F32>(xData.GetNumber());
        F32 y = static_cast<F32>(yData.GetNumber());
        F32 z = static_cast<F32>(zData.GetNumber());
        direction.Set(x, y, z);

        return (true);
    }
Exemplo n.º 16
0
    // /////////////////////////////////////////////////////////////////
    //
    // /////////////////////////////////////////////////////////////////
    bool SetPoint3FromLua(const LuaPlus::LuaObject &posData, Point3 &position)
    {
        if(!posData.IsTable()) {
            return (false);
        }

        LuaPlus::LuaObject xData = posData["x"];
        LuaPlus::LuaObject yData = posData["y"];
        LuaPlus::LuaObject zData = posData["z"];

        if(!xData.IsNumber() || !yData.IsNumber() || !zData.IsNumber()) {
            return (false);
        }

        F32 x = static_cast<F32>(xData.GetNumber());
        F32 y = static_cast<F32>(yData.GetNumber());
        F32 z = static_cast<F32>(zData.GetNumber());
        position.Set(x, y, z);

        return (true);
    }
Exemplo n.º 17
0
int createEntity(const char* entityResource, LuaPlus::LuaObject luaPosition)
{
    if(!luaPosition.IsTable())
    {
        CORE_LOG("LUA", "Invalid position object passed to create_entity function. Must be a table");
        return INVALID_ENTITY_ID;
    }

	sf::Vector2f position = tableToVec2<sf::Vector2f>(luaPosition);

    artemis::Entity& entity = WorldLocator::getObject()->createEntity();

    // Create entity
    if(!EntityFactory::get().loadFromFile(entityResource, entity))
    {
        CORE_ERROR("Failed to load entity from file: " + std::string(entityResource));
        return INVALID_ENTITY_ID;
    }

    Transform* transformComp = safeGetComponent<Transform>(&entity);

    if(!transformComp)
    {
        // Create new transform component if it doesn't exist
        entity.addComponent(new Transform(position.x, position.y));
    }
	else
	{
		CORE_DEBUG("Overriding transform with lua object");

		transformComp->position = position;
	}

    // Commit entity changes
    entity.refresh();

    CORE_LOG("LUA", "Created entity from: " + std::string(entityResource));

    return entity.getId();
}
Exemplo n.º 18
0
    // /////////////////////////////////////////////////////////////////
    //
    // /////////////////////////////////////////////////////////////////
    void ListButtonControl::SetLuaTextList(const LuaPlus::LuaObject &table)
    {
        bool error = true;
        if(table.IsTable()) {
            I64 size = table.GetTableCount();
            // LUA table indices start at 1!!
            for(I64 i = 1; i <= size; ++i) {
                LuaPlus::LuaObject currTable = table[i];
                if(currTable.IsString()) {
                    error = false;
                    m_list.push_back(std::string(currTable.GetString()));
                }
            }

        }

#if DEBUG
        if(error) {
            GF_LOG_TRACE_ERR("ListButtonControl::SetLuaTextList()", "No List of text strings got from lua data");
        }
#endif
    }
Exemplo n.º 19
0
//---------------------------------------------------------------------------------------------------------------------
// This function registers all the ScriptExports functions with the scripting system.  It is called in 
// Application::Init().
//---------------------------------------------------------------------------------------------------------------------
void ScriptExports::Register(void)
{
	LuaPlus::LuaObject globals = LuaStateManager::Get()->GetGlobalVars();

	// init	
	InternalScriptExports::Init();

	// resource loading
	globals.RegisterDirect("LoadAndExecuteScriptResource", &InternalScriptExports::LoadAndExecuteScriptResource);

	// actors
	globals.RegisterDirect("CreateActor", &InternalScriptExports::CreateActor);

	// event system
	globals.RegisterDirect("RegisterEventListener", &InternalScriptExports::RegisterEventListener);
	globals.RegisterDirect("RemoveEventListener", &InternalScriptExports::RemoveEventListener);
	globals.RegisterDirect("QueueEvent", &InternalScriptExports::QueueEvent);
	globals.RegisterDirect("TriggerEvent", &InternalScriptExports::TriggerEvent);
	
	// process system
	globals.RegisterDirect("AttachProcess", &InternalScriptExports::AttachScriptProcess);

    // math
    LuaPlus::LuaObject mathTable = globals.GetByName("GccMath");
    GCC_ASSERT(mathTable.IsTable());
    mathTable.RegisterDirect("GetYRotationFromVector", &InternalScriptExports::GetYRotationFromVector);
    mathTable.RegisterDirect("WrapPi", &InternalScriptExports::WrapPi);
    mathTable.RegisterDirect("GetVectorFromRotation", &InternalScriptExports::GetVectorFromRotation);
	
	// misc
	globals.RegisterDirect("Log", &InternalScriptExports::LuaLog);
    globals.RegisterDirect("GetTickCount", &InternalScriptExports::GetTickCount);

	// Physics
	globals.RegisterDirect("ApplyForce", &InternalScriptExports::ApplyForce);
	globals.RegisterDirect("ApplyTorque", &InternalScriptExports::ApplyTorque);
}
//=============================================================
//	C Functions for registering C++ functions to Lua script
//=============================================================
void LuaScriptExports::Register()
{
	LuaPlus::LuaObject globals = LuaStateManager::Get()->GetGlobalVars();

	// init
	LuaInternalScriptExports::Init();

	// resource loading
	globals.RegisterDirect("LoadAndExecuteScriptResource", &LuaInternalScriptExports::LoadAndExecuteScriptResource);

	// gameobjects
	globals.RegisterDirect("CreateObject", &LuaInternalScriptExports::CreateGameObject);

	// events
	globals.RegisterDirect("RegisterEventListener", &LuaInternalScriptExports::RegisterEventListener);
	globals.RegisterDirect("RemoveEventListener", &LuaInternalScriptExports::RemoveEventListener);
	globals.RegisterDirect("QueueEvent", &LuaInternalScriptExports::QueueEvent);
	globals.RegisterDirect("TriggerEvent", &LuaInternalScriptExports::TriggerEvent);

	// processes
	globals.RegisterDirect("AttachProcess", &LuaInternalScriptExports::AttachScriptProcess);

	// math (these are registered to GccMath, not global
	LuaPlus::LuaObject mathTable = globals.GetByName("GccMath");
	CB_ASSERT(mathTable.IsTable());
	mathTable.RegisterDirect("GetYRotationFromVector", &LuaInternalScriptExports::GetYRotationFromVector);
	mathTable.RegisterDirect("WrapPi", &LuaInternalScriptExports::WrapPi);
	mathTable.RegisterDirect("GetVectorFromRotation", &LuaInternalScriptExports::GetVectorFromRotation);

	// misc
	globals.RegisterDirect("Log", &LuaInternalScriptExports::LuaLog);
	globals.RegisterDirect("GetTickCount", &LuaInternalScriptExports::GetTickCount);

	// physics
	globals.RegisterDirect("ApplyForce", &LuaInternalScriptExports::ApplyForce);
	globals.RegisterDirect("ApplyTorque", &LuaInternalScriptExports::ApplyTorque);
}
Exemplo n.º 21
0
void LuaManager::PrintTable(LuaPlus::LuaObject table, bool recursive)
{
	if(table.IsNil())
	{
		if(!recursive)
			GLIB_LOG("LuaManager", "null table");
		return;
	}

	if(!recursive)
		GLIB_LOG("LuaManager", "PrintTable()");

	cout << (!recursive ? "--\n" : "{ ");

	bool noMembers = true;
	for(LuaPlus::LuaTableIterator iter(table); iter; iter.Next())
	{
		noMembers = false;

		LuaPlus::LuaObject key = iter.GetKey();
		LuaPlus::LuaObject value = iter.GetValue();

		cout << key.ToString() << ": ";
		if(value.IsFunction())
			cout << "function" << "\n";
		else if(value.IsTable())
			PrintTable(value, true);
		else if(value.IsLightUserData())
			cout << "light user data" << "\n";
		else
			cout << value.ToString() << ", ";
	}

	cout << (!recursive ? "\n--" : "}");
	cout << endl;
}
Exemplo n.º 22
0
	// /////////////////////////////////////////////////////////////////
	// 
	// /////////////////////////////////////////////////////////////////
	bool TableActorParams::VInit(LuaPlus::LuaObject srcData, TErrorMessageList &errorMessages)
	{
		if (!Pool3dActorParams::VInit(srcData, errorMessages))
		{
			return (false);
		}

		VSetType(AT_Table);

		// Table Panels data.
		LuaPlus::LuaObject obj = srcData["FrontPanelMeshName"];
		if(obj.IsString())
		{
			SetFrontPanelMeshName(obj.GetString());
		}
		obj = srcData["SidePanelMeshName"];
		if(obj.IsString())
		{
			SetSidePanelMeshName(obj.GetString());
		}
		obj = srcData["PanelTextureName"];
		if(obj.IsString())
		{
			SetPanelTextureName(obj.GetString());
		}
		obj = srcData["PanelMaterial"];
		if(obj.IsTable())
		{
			GameColor tmp;
			if(SetColorFromLua(obj["Ambient"], tmp))
			{
				m_panelMaterial.SetAmbient(tmp);
			}
			if(SetColorFromLua(obj["Diffuse"], tmp))
			{
				m_panelMaterial.SetDiffuse(tmp);
			}
			if(SetColorFromLua(obj["Specular"], tmp))
			{
				m_panelMaterial.SetSpecular(tmp);
			}
			if(SetColorFromLua(obj["Emissive"], tmp))
			{
				m_panelMaterial.SetEmissive(tmp);
			}
			F32 tmp2;
			if(SetFloatFromLua(obj["Shininess"], tmp2))
			{
				m_panelMaterial.SetSpecularPower(tmp2);
			}
		}

		// Table pockets data.
		obj = srcData["MiddlePocketMeshName"];
		if(obj.IsString())
		{
			SetMiddlePocketMeshName(obj.GetString());
		}
		obj = srcData["CornerPocketMeshName"];
		if(obj.IsString())
		{
			SetCornerPocketMeshName(obj.GetString());
		}
		obj = srcData["PocketMaterial"];
		if(obj.IsTable())
		{
			GameColor tmp;
			if(SetColorFromLua(obj["Ambient"], tmp))
			{
				m_pocketsMaterial.SetAmbient(tmp);
			}
			if(SetColorFromLua(obj["Diffuse"], tmp))
			{
				m_pocketsMaterial.SetDiffuse(tmp);
			}
			if(SetColorFromLua(obj["Specular"], tmp))
			{
				m_pocketsMaterial.SetSpecular(tmp);
			}
			if(SetColorFromLua(obj["Emissive"], tmp))
			{
				m_pocketsMaterial.SetEmissive(tmp);
			}
			F32 tmp2;
			if(SetFloatFromLua(obj["Shininess"], tmp2))
			{
				m_pocketsMaterial.SetSpecularPower(tmp2);
			}
		}
		obj = srcData["PocketTexture"];
		if(obj.IsString())
		{
			SetPocketTextureName(obj.GetString());
		}

		obj = srcData["Width"];
		if(obj.IsNumber())
		{
			SetFloatFromLua(obj, m_width);
		}
		obj = srcData["Height"];
		if(obj.IsNumber())
		{
			SetFloatFromLua(obj, m_height);
		}
		obj = srcData["Depth"];
		if(obj.IsNumber())
		{
			SetFloatFromLua(obj, m_depth);
		}
		obj = srcData["PocketRadius"];
		if(obj.IsNumber())
		{
			SetFloatFromLua(obj, m_pocketRadius);
		}

		obj = srcData["TopLeftPocketTriggerPos"];
		if(obj.IsTable())
		{
			SetPoint3FromLua(obj, m_tlpTriggerPos);
		}
		obj = srcData["TopLeftPocketTriggerId"];
		if(obj.IsInteger())
		{
			SetIntFromLua(obj, m_tlPocketId);
		}
		obj = srcData["TopRightPocketTriggerPos"];
		if(obj.IsTable())
		{
			SetPoint3FromLua(obj, m_trpTriggerPos);
		}
		obj = srcData["TopRightPocketTriggerId"];
		if(obj.IsInteger())
		{
			SetIntFromLua(obj, m_trPocketId);
		}
		obj = srcData["BottomLeftPocketTriggerPos"];
		if(obj.IsTable())
		{
			SetPoint3FromLua(obj, m_blpTriggerPos);
		}
		obj = srcData["BottomLeftPocketTriggerId"];
		if(obj.IsInteger())
		{
			SetIntFromLua(obj, m_blPocketId);
		}
		obj = srcData["BottomRightPocketTriggerPos"];
		if(obj.IsTable())
		{
			SetPoint3FromLua(obj, m_brpTriggerPos);
		}
		obj = srcData["BottomRightPocketTriggerId"];
		if(obj.IsInteger())
		{
			SetIntFromLua(obj, m_brPocketId);
		}
		obj = srcData["MiddleLeftPocketTriggerPos"];
		if(obj.IsTable())
		{
			SetPoint3FromLua(obj, m_mlpTriggerPos);
		}
		obj = srcData["MiddleLeftPocketTriggerId"];
		if(obj.IsInteger())
		{
			SetIntFromLua(obj, m_mlPocketId);
		}
		obj = srcData["MiddleRightPocketTriggerPos"];
		if(obj.IsTable())
		{
			SetPoint3FromLua(obj, m_mrpTriggerPos);
		}
		obj = srcData["MiddleRightPocketTriggerId"];
		if(obj.IsInteger())
		{
			SetIntFromLua(obj, m_mrPocketId);
		}

		return (true);
	}
Exemplo n.º 23
0
	// /////////////////////////////////////////////////////////////////
	// 
	// /////////////////////////////////////////////////////////////////
	bool Pool3dActorParams::VInit(LuaPlus::LuaObject srcData, TErrorMessageList &errorMessages)
	{
		if (!ActorParams::VInit(srcData, errorMessages))
		{
			return (false);
		}

		std::string tempStr;

		if(srcData["TextureName"].IsString())
		{
			if(!SetStringFromLua(srcData["TextureName"], tempStr))
			{
				return (false);
			}
			SetTextureName(tempStr);
		}

		if(srcData["ShaderName"].IsString())
		{
			if(!SetStringFromLua(srcData["ShaderName"], tempStr))
			{
				return (false);
			}
			SetShaderName(tempStr);
		}

		if(srcData["MeshName"].IsString())
		{
			if(!SetStringFromLua(srcData["MeshName"], tempStr))
			{
				return (false);
			}
			SetMeshName(tempStr);
		}

		LuaPlus::LuaObject materialTable = srcData["Material"];
		if(materialTable.IsTable())
		{
			GameColor tmpColor;

			if(materialTable["Ambient"].IsTable())
			{
				if(!SetColorFromLua(materialTable["Ambient"], tmpColor))
				{
					return (false);
				}
				m_material.SetAmbient(tmpColor);
			}

			if(materialTable["Diffuse"].IsTable())
			{
				if(!SetColorFromLua(materialTable["Diffuse"], tmpColor))
				{
					return (false);
				}
				m_material.SetDiffuse(tmpColor);
				// Don't forget to set the actors color to the same value as its diffuse color!
				VSetColor(tmpColor);
			}

			if(materialTable["Specular"].IsTable())
			{
				if(!SetColorFromLua(materialTable["Specular"], tmpColor))
				{
					return (false);
				}
				m_material.SetSpecular(tmpColor);
			}

			if(materialTable["Emissive"].IsTable())
			{
				if(!SetColorFromLua(materialTable["Emissive"], tmpColor))
				{
					return (false);
				}
				m_material.SetEmissive(tmpColor);
			}

			F32 number = 0.0f;
			if(materialTable["Shininess"].IsNumber())
			{
				if(!SetFloatFromLua(materialTable["Shininess"], number))
				{
					return (false);
				}
				m_material.SetSpecularPower(number);
			}
		}

		LuaPlus::LuaObject physicsTable = srcData["PhysicsInformation"];
		if(physicsTable.IsTable())
		{
			if(physicsTable["Restitution"].IsNumber() && !SetFloatFromLua(physicsTable["Restitution"], m_physicsInfo.m_restitution))
			{
				return (false);
			}
			if(physicsTable["Friction"].IsNumber() && !SetFloatFromLua(physicsTable["Friction"], m_physicsInfo.m_friction))
			{
				return (false);
			}
			if(physicsTable["Density"].IsNumber() && !SetFloatFromLua(physicsTable["Density"], m_physicsInfo.m_density))
			{
				return (false);
			}
			if(physicsTable["LinearDamping"].IsNumber() && !SetFloatFromLua(physicsTable["LinearDamping"], m_physicsInfo.m_linearDamping))
			{
				return (false);
			}
			if(physicsTable["AngularDamping"].IsNumber() && !SetFloatFromLua(physicsTable["AngularDamping"], m_physicsInfo.m_angularDamping))
			{
				return (false);
			}
		}

		return (true);
	}
Exemplo n.º 24
-4
int InternalScriptExports::CreateActor(const char* actorArchetype, LuaPlus::LuaObject luaPosition, LuaPlus::LuaObject luaYawPitchRoll)
{

    if (!luaPosition.IsTable())
    {
	    GCC_ERROR("Invalid object passed to CreateActor(); type = " + std::string(luaPosition.TypeName()));
		return INVALID_ACTOR_ID;
	}

    if (!luaYawPitchRoll.IsTable())
    {
	    GCC_ERROR("Invalid object passed to CreateActor(); type = " + std::string(luaYawPitchRoll.TypeName()));
		return INVALID_ACTOR_ID;
	}

	Vec3 pos(luaPosition["x"].GetFloat(), luaPosition["y"].GetFloat(), luaPosition["z"].GetFloat());
	Vec3 ypr(luaYawPitchRoll["x"].GetFloat(), luaYawPitchRoll["y"].GetFloat(), luaYawPitchRoll["z"].GetFloat());

	Mat4x4 initialTransform;
	initialTransform.BuildYawPitchRoll(ypr.x, ypr.y, ypr.z);
	initialTransform.SetPosition(pos);

	TiXmlElement *overloads = NULL;
	StrongActorPtr pActor = g_pApp->m_pGame->VCreateActor(actorArchetype, overloads, &initialTransform);

	if (pActor)
	{
		shared_ptr<EvtData_New_Actor> pNewActorEvent(GCC_NEW EvtData_New_Actor(pActor->GetId()));
		IEventManager::Get()->VQueueEvent(pNewActorEvent);
		return pActor->GetId();
	}

	return INVALID_ACTOR_ID;
}