Ejemplo n.º 1
0
mono::object CScriptbind_Entity::SpawnEntity(EntitySpawnParams monoParams, bool bAutoInit, SMonoEntityInfo &entityInfo)
{
	const char *className = ToCryString(monoParams.sClass);

	if(IEntityClass *pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(className))
	{
		SEntitySpawnParams spawnParams;
		spawnParams.pClass = pClass;
		spawnParams.sName = ToCryString(monoParams.sName);

		spawnParams.nFlags = monoParams.flags | ENTITY_FLAG_NO_SAVE;
		spawnParams.vPosition = monoParams.pos;
		spawnParams.qRotation = monoParams.rot;
		spawnParams.vScale = monoParams.scale;

		if(IEntity *pEntity = gEnv->pEntitySystem->SpawnEntity(spawnParams, bAutoInit))
		{
			entityInfo.pEntity = pEntity;
			entityInfo.id = pEntity->GetId();

			if(IGameObject *pGameObject = gEnv->pGameFramework->GetGameObject(spawnParams.id))
			{
				if(CMonoEntityExtension *pEntity = static_cast<CMonoEntityExtension *>(pGameObject->QueryExtension(className)))
					return pEntity->GetScript()->GetManagedObject();
			}
		}
	}

	return nullptr;
}
Ejemplo n.º 2
0
int CScriptbind_Entity::LoadLight(IEntity *pEntity, int slot, SMonoLightParams params)
{
	CDLight light;

	if(const char *spec = ToCryString(params.specularCubemap))
	{
		if(strcmp(spec, ""))
			light.SetSpecularCubemap(gEnv->pRenderer->EF_LoadTexture(spec));
	}
	if(const char *diff = ToCryString(params.diffuseCubemap))
	{
		if(strcmp(diff, ""))
			light.SetDiffuseCubemap(gEnv->pRenderer->EF_LoadTexture(diff));
	}
	if(const char *lightImage = ToCryString(params.lightImage))
	{
		if(strcmp(lightImage, ""))
			light.m_pLightImage = gEnv->pRenderer->EF_LoadTexture(lightImage);
	}
	if(const char *lightAttenMap = ToCryString(params.lightAttenMap))
	{
		if(strcmp(lightAttenMap, ""))
			light.SetLightAttenMap(gEnv->pRenderer->EF_LoadTexture(lightAttenMap));
	}

	light.SetLightColor(params.color);
	light.SetPosition(params.origin);

	light.SetShadowBiasParams(params.shadowBias, params.shadowSlopeBias);

	light.m_fRadius = params.radius;
	light.SetSpecularMult(params.specularMultiplier);

	light.m_fHDRDynamic = params.hdrDynamic;

	light.m_fAnimSpeed = params.animSpeed;
	light.m_fCoronaScale = params.coronaScale;
	light.m_fCoronaIntensity = params.coronaIntensity;
	light.m_fCoronaDistSizeFactor = params.coronaDistSizeFactor;
	light.m_fCoronaDistIntensityFactor = params.coronaDistIntensityFactor;

	light.m_fShaftSrcSize = params.shaftSrcSize;
	light.m_fShaftLength = params.shaftLength;
	light.m_fShaftBrightness = params.shaftBrightness;
	light.m_fShaftBlendFactor = params.shaftBlendFactor;
	light.m_fShaftDecayFactor = params.shaftDecayFactor;

	light.m_fLightFrustumAngle = params.lightFrustumAngle;

	light.m_fShadowUpdateMinRadius = params.shadowUpdateMinRadius;
	light.m_nShadowUpdateRatio = params.shadowUpdateRatio;


	light.m_nLightStyle = params.lightStyle;
	light.m_nLightPhase = params.lightPhase;
	light.m_nPostEffect = params.postEffect;
	light.m_ShadowChanMask = params.shadowChanMask;

	return pEntity->LoadLight(slot, &light);
}
Ejemplo n.º 3
0
SMonoActorInfo CActorSystem::CreateActor(int channelId, mono::string name, mono::string className, Vec3 pos, Quat rot, Vec3 scale)
{
	const char *sClassName = ToCryString(className);

	if(IActor *pActor = gEnv->pGameFramework->GetIActorSystem()->CreateActor(channelId, ToCryString(name), sClassName, pos, rot, scale))
		return SMonoActorInfo(pActor);

	return SMonoActorInfo();
}
Ejemplo n.º 4
0
void CScriptbind_CrySerialize::ValueString(ISerialize *ser, mono::string name, mono::string &str, int policy)
{
	TSerialize serialize = TSerialize(ser);
	if(!ser->IsReading())
		serialize.Value(ToCryString(name), ToCryString(str), policy);
	else
	{
		string cryStr;
		serialize.Value(ToCryString(name), cryStr, policy);
		str = ToMonoString(cryStr.c_str());
	}
}
Ejemplo n.º 5
0
int CScriptbind_Console::GetCVarInt(mono::string name)
{
	if(ICVar *pCVar = gEnv->pConsole->GetCVar(ToCryString(name)))
		return pCVar->GetIVal();

	return 0;
}
Ejemplo n.º 6
0
mono::string CScriptbind_Console::GetCVarString(mono::string name)
{
	if(ICVar *pCVar = gEnv->pConsole->GetCVar(ToCryString(name)))
		return (mono::string )ToMonoString(pCVar->GetString());

	return (mono::string )ToMonoString("");
}
Ejemplo n.º 7
0
void CScriptbind_CrySerialize::ValueVec3(ISerialize *ser, mono::string name, Vec3 &obj, mono::string policy)
{
	int iPolicy = ConvertPolicy(policy);

	TSerialize serialize = TSerialize(ser);
	serialize.Value(ToCryString(name), obj, iPolicy);
}
Ejemplo n.º 8
0
mono::object CScriptbind_Entity::GetEntitiesByClass(mono::string _class)
{
	IEntityClass *pDesiredClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(ToCryString(_class));

	std::vector<EntityId> classEntities;

	IEntityItPtr pIt = gEnv->pEntitySystem->GetEntityIterator();
	pIt->MoveFirst();

	while(!pIt->IsEnd())
	{
		if(IEntity *pEntity = pIt->Next())
		{
			if(pEntity->GetClass() == pDesiredClass)
				classEntities.push_back(pEntity->GetId());
		}
	}

	if(classEntities.size()<1)
		return nullptr;

	IMonoClass *pEntityIdClass = g_pScriptSystem->GetCryBraryAssembly()->GetClass("EntityId");

	IMonoArray *pArray = CreateMonoArray(classEntities.size());

	for(auto it = classEntities.begin(); it != classEntities.end(); ++it)
		pArray->Insert(pEntityIdClass->BoxObject(&mono::entityId(*it)));

	return pArray->GetManagedObject();
}
Ejemplo n.º 9
0
EntityId CScriptbind_Entity::FindEntity(mono::string name)
{
	if(IEntity *pEntity = gEnv->pEntitySystem->FindEntityByName(ToCryString(name)))
		return pEntity->GetId();

	return 0;
}
Ejemplo n.º 10
0
IAttachment *CScriptbind_Entity::GetAttachmentByName(IEntity *pEnt, mono::string name, int slot)
{
	if(auto pAttachmentManager = GetAttachmentManager(pEnt, slot))
		return pAttachmentManager->GetInterfaceByName(ToCryString(name));

	return nullptr;
}
Ejemplo n.º 11
0
int CScriptbind_Renderer::LoadTexture(mono::string texturePath)
{
	if(ITexture *pTexture = gEnv->pRenderer->EF_LoadTexture(ToCryString(texturePath)))
		return pTexture->GetTextureID();

	return -1;
}
Ejemplo n.º 12
0
mono::object CScriptbind_ScriptTable::CallMethod(IScriptTable *pScriptTable, mono::string methodName, mono::object params)
{
	HSCRIPTFUNCTION scriptFunction = 0;
    if (pScriptTable && pScriptTable->GetValue(ToCryString(methodName), scriptFunction))
	{
		if(!gEnv->pScriptSystem->BeginCall(scriptFunction))
			return nullptr;

		IMonoArray *pArgs = *params;

		gEnv->pScriptSystem->PushFuncParam(pScriptTable);

		for(int i = 0; i < pArgs->GetSize(); i++)
		{
			auto anyValue = GetAnyValue(pArgs->GetItem(i));
			gEnv->pScriptSystem->PushFuncParamAny(anyValue);
		}

		ScriptAnyValue ret;
		gEnv->pScriptSystem->EndCallAny(ret);
		auto result = ToMonoObject(ret);

		gEnv->pScriptSystem->ReleaseFunc(scriptFunction);
		return result;
    }

	return nullptr;
}
Ejemplo n.º 13
0
float CScriptbind_Console::GetCVarFloat(mono::string name)
{
	if(ICVar *pCVar = gEnv->pConsole->GetCVar(ToCryString(name)))
		return pCVar->GetFVal();

	return 0.0f;
}
Ejemplo n.º 14
0
bool CScriptbind_Console::HasCVar(mono::string name)
{
	if(ICVar *pCVar = gEnv->pConsole->GetCVar(ToCryString(name)))
		return true;

	return false;
}
Ejemplo n.º 15
0
void CMonoFlowNode::GetConfiguration(SFlowNodeConfig &config)
{
	CRY_ASSERT(m_pScript);

	if(mono::object result = m_pScript->CallMethod("GetNodeConfig"))
	{
		IMonoObject *pResult = *result;

		SMonoNodeConfig monoConfig = pResult->Unbox<SMonoNodeConfig>();

		config.nFlags |= monoConfig.flags;
		config.sDescription = _HELP(ToCryString(monoConfig.description));
		config.SetCategory(monoConfig.category);

		m_flags = config.nFlags;

		m_cloneType = monoConfig.cloneType;

		// Ports
		IMonoArray *pInputPorts = *monoConfig.inputs;
		int numInputs = pInputPorts->GetSize();

		auto pInputs = new SInputPortConfig[numInputs + 1];

		for(int i = 0; i < numInputs; i++)
		{
			IMonoObject *pInputObject = *pInputPorts->GetItem(i);
			pInputs[i] = pInputObject->Unbox<SMonoInputPortConfig>().Convert();
			SAFE_RELEASE(pInputObject);
		}

		SInputPortConfig nullInputPortConfig = {0};
		pInputs[numInputs] = nullInputPortConfig;

		config.pInputPorts = pInputs;

		SAFE_RELEASE(pInputPorts);

		IMonoArray *pOutputPorts = *monoConfig.outputs;
		int numOutputs = pOutputPorts->GetSize();

		auto pOutputs = new SOutputPortConfig[numOutputs + 1];

		for(int i = 0; i < numOutputs; i++)
		{
			IMonoObject *pOutputObject = *pOutputPorts->GetItem(i);
			pOutputs[i] = pOutputObject->Unbox<SMonoOutputPortConfig>().Convert();
			SAFE_RELEASE(pOutputObject);
		}

		SOutputPortConfig nullOutputPortConfig = {0};
		pOutputs[numOutputs] = nullOutputPortConfig;

		config.pOutputPorts = pOutputs;

		SAFE_RELEASE(pOutputPorts);
		SAFE_RELEASE(pResult);
	}
}
Ejemplo n.º 16
0
mono::object CScriptbind_ScriptTable::GetValue(IScriptTable *pScriptTable, mono::string keyName)
{
	ScriptAnyValue anyValue;
	if(pScriptTable->GetValueAny(ToCryString(keyName), anyValue))
		return ToMonoObject(anyValue);

	return nullptr;
}
Ejemplo n.º 17
0
IScriptTable *CScriptbind_ScriptTable::GetSubScriptTable(IScriptTable *pScriptTable, mono::string subTableName)
{
	ScriptAnyValue anyValue;
	if(pScriptTable->GetValueAny(ToCryString(subTableName), anyValue))
		return anyValue.table;

	return nullptr;
}
Ejemplo n.º 18
0
CFrameProfiler *CScriptbind_Debug::CreateFrameProfiler(mono::string methodName)
{
	CFrameProfiler *pFrameProfiler = new CFrameProfiler(GetISystem(), ToCryString(methodName), PROFILE_SCRIPT);

	m_frameProfilers.push_back(pFrameProfiler);

	return pFrameProfiler;
}
Ejemplo n.º 19
0
mono::object CScriptbind_Entity::SpawnEntity(EntitySpawnParams monoParams, bool bAutoInit, SMonoEntityInfo &entityInfo)
{
	const char *className = ToCryString(monoParams.sClass);

	if(IEntityClass *pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(className))
	{
		SEntitySpawnParams spawnParams;
		spawnParams.pClass = pClass;
		spawnParams.sName = ToCryString(monoParams.sName);

		spawnParams.nFlags = monoParams.flags | ENTITY_FLAG_NO_SAVE;
		spawnParams.vPosition = monoParams.pos;
		spawnParams.qRotation = monoParams.rot;
		spawnParams.vScale = monoParams.scale;

		if(IEntity *pEntity = gEnv->pEntitySystem->SpawnEntity(spawnParams, bAutoInit))
		{
			entityInfo.pEntity = pEntity;
			entityInfo.id = pEntity->GetId();

			if(IGameObject *pGameObject = static_cast<CScriptSystem *>(GetMonoScriptSystem())->GetIGameFramework()->GetGameObject(spawnParams.id))
			{
				if(CMonoEntityExtension *pEntityExtension = static_cast<CMonoEntityExtension *>(pGameObject->QueryExtension(className)))
					return pEntityExtension->GetScript()->GetManagedObject();
				else
				{
					MonoWarning("[CryMono] Spawned entity of class %s with id %i, but game object extension query failed!", className, pEntity->GetId());

					auto extensionId = static_cast<CScriptSystem *>(GetMonoScriptSystem())->GetIGameFramework()->GetIGameObjectSystem()->GetID(className);
					if(extensionId == IGameObjectSystem::InvalidExtensionID)
						MonoWarning("[CryMono] IGameObjectSystem::GetId returned invalid id for extension %s", className);

					return nullptr;
				}
			}
			else
			{
				MonoWarning("[CryMono] Spawned entity of class %s with id %i, but game object was null!", className, pEntity->GetId());
				return nullptr;
			}
		}
	}

	return nullptr;
}
Ejemplo n.º 20
0
SMonoActorInfo CScriptbind_ActorSystem::CreateActor(int channelId, mono::string name, mono::string className, Vec3 pos, Quat rot, Vec3 scale)
{
	const char *sClassName = ToCryString(className);

	if(IActor *pActor = static_cast<CScriptSystem *>(GetMonoScriptSystem())->GetIGameFramework()->GetIActorSystem()->CreateActor(channelId, ToCryString(name), sClassName, pos, rot, scale))
		return SMonoActorInfo(pActor);

	return SMonoActorInfo();
}
Ejemplo n.º 21
0
void CActorSystem::RegisterActorClass(mono::string name, bool isNative)
{
	const char *className = ToCryString(name);

	if(!isNative)
		gEnv->pGameFramework->RegisterFactory(className, (CActor *)0, false, (CActor *)0);

	m_monoActorClasses.insert(TActorClasses::value_type(className, isNative ? EMonoActorType_Native : EMonoActorType_Managed));
}
Ejemplo n.º 22
0
bool CScriptbind_ScriptTable::ExecuteBuffer(mono::string mBuffer)
{
	if(IScriptSystem *pScriptSystem = gEnv->pSystem->GetIScriptSystem())
	{
		const char *buffer = ToCryString(mBuffer);
		return pScriptSystem->ExecuteBuffer(buffer + 1, strlen(buffer) - 1);
	}

	return false;
}
Ejemplo n.º 23
0
int CScriptbind_Entity::LoadLight(IEntity *pEntity, int slot, SMonoLightParams params)
{
	CDLight light;

	if(const char *spec = ToCryString(params.specularCubemap))
	{
		if(strcmp(spec, ""))
			light.SetSpecularCubemap(gEnv->pRenderer->EF_LoadTexture(spec));
	}
	if(const char *diff = ToCryString(params.diffuseCubemap))
	{
		if(strcmp(diff, ""))
			light.SetDiffuseCubemap(gEnv->pRenderer->EF_LoadTexture(diff));
	}
	if(const char *lightImage = ToCryString(params.lightImage))
	{
		if(strcmp(lightImage, ""))
			light.m_pLightImage = gEnv->pRenderer->EF_LoadTexture(lightImage);
	}

	light.SetLightColor(params.color);
	light.SetPosition(params.origin);

	light.SetShadowBiasParams(params.shadowBias, params.shadowSlopeBias);

	light.m_fRadius = params.radius;
	light.SetSpecularMult(params.specularMultiplier);

	light.m_fHDRDynamic = params.hdrDynamic;

	light.m_fLightFrustumAngle = params.lightFrustumAngle;

	light.m_fShadowUpdateMinRadius = params.shadowUpdateMinRadius;
	light.m_nShadowUpdateRatio = params.shadowUpdateRatio;


	light.m_nLightStyle = params.lightStyle;
	light.m_nLightPhase = params.lightPhase;
	light.m_ShadowChanMask = params.shadowChanMask;

	return pEntity->LoadLight(slot, &light);
}
Ejemplo n.º 24
0
CCGFAttachment *CScriptbind_Entity::BindAttachmentToCGF(IAttachment *pAttachment, mono::string cgf, IMaterial *pMaterial)
{
	pAttachment->ClearBinding();

	CCGFAttachment *pCGFAttachment = new CCGFAttachment();
	pCGFAttachment->pObj = gEnv->p3DEngine->LoadStatObj(ToCryString(cgf));
	pCGFAttachment->SetReplacementMaterial(pMaterial);

	pAttachment->AddBinding(pCGFAttachment);

	return pCGFAttachment;
}
Ejemplo n.º 25
0
void CScriptbind_Entity::SetJointAbsolute(IEntity *pEntity, mono::string jointName, int characterSlot, QuatT absolute)
{
	if(ICharacterInstance *pCharacter = pEntity->GetCharacter(characterSlot))
	{
		if(ISkeletonPose *pSkeletonPose = pCharacter->GetISkeletonPose())
		{
			int16 id = pSkeletonPose->GetJointIDByName(ToCryString(jointName));
			if(id > -1)
				pSkeletonPose->SetAbsJointByID(id, absolute);
		}
	}
}
Ejemplo n.º 26
0
//-----------------------------------------------------------------------------
void CScriptbind_GameRules::RegisterGameMode(mono::string gamemode)
{
	if(IGameFramework *pGameFramework = static_cast<CScriptSystem *>(GetMonoScriptSystem())->GetIGameFramework())
	{
		if(IGameRulesSystem *pGameRulesSystem = pGameFramework->GetIGameRulesSystem())
		{
			const char *gameModeStr = ToCryString(gamemode);

			if(!pGameRulesSystem->HaveGameRules(gameModeStr))
				pGameRulesSystem->RegisterGameRules(gameModeStr, "GameRules");
		}
	}
}
Ejemplo n.º 27
0
const char *CEntityPropertyHandler::GetProperty(IEntity *pIEntity, int index) const
{
	if (IGameObject *pGameObject = static_cast<CScriptSystem *>(GetMonoScriptSystem())->GetIGameFramework()->GetGameObject(pIEntity->GetId()))
	{
		if(CMonoEntityExtension *pEntity = static_cast<CMonoEntityExtension *>(pGameObject->QueryExtension(pIEntity->GetClass()->GetName())))
		{
			if(mono::object result = pEntity->GetScript()->CallMethod("GetPropertyValue", m_pProperties[index].info.name))
				return ToCryString((mono::string)result);
		}
	}

	return "";
}
Ejemplo n.º 28
0
void CScriptbind_ActorSystem::RemoteInvocation(EntityId entityId, EntityId targetId, mono::string methodName, mono::object args, ERMInvocation target, int channelId)
{
	CRY_ASSERT(entityId != 0);

	IGameObject *pGameObject = static_cast<CScriptSystem *>(GetMonoScriptSystem())->GetIGameFramework()->GetGameObject(entityId);
	CRY_ASSERT(pGameObject);

	CMonoEntityExtension::RMIParams params(args, ToCryString(methodName), targetId);

	if(target & eRMI_ToServer)
		pGameObject->InvokeRMI(CMonoActor::SvScriptRMI(), params, target, channelId);
	else
		pGameObject->InvokeRMI(CMonoActor::ClScriptRMI(), params, target, channelId);
}
Ejemplo n.º 29
0
void CScriptbind_Entity::RemoteInvocation(EntityId entityId, EntityId targetId, mono::string methodName, mono::object args, ERMInvocation target, int channelId)
{
	CRY_ASSERT(entityId != 0);

	IGameObject *pGameObject = gEnv->pGameFramework->GetGameObject(entityId);
	CRY_ASSERT(pGameObject);

	CMonoEntityExtension::RMIParams params(*args, ToCryString(methodName), targetId);

	if(target & eRMI_ToServer)
		pGameObject->InvokeRMI(CMonoEntityExtension::SvScriptRMI(), params, target, channelId);
	else
		pGameObject->InvokeRMI(CMonoEntityExtension::ClScriptRMI(), params, target, channelId);
}
Ejemplo n.º 30
0
QuatT CScriptbind_Entity::GetJointRelativeDefault(IEntity *pEntity, mono::string jointName, int characterSlot)
{
	if(ICharacterInstance *pCharacter = pEntity->GetCharacter(characterSlot))
	{
		if(ISkeletonPose *pSkeletonPose = pCharacter->GetISkeletonPose())
		{
			int16 id = pSkeletonPose->GetJointIDByName(ToCryString(jointName));
			if(id > -1)
				return pSkeletonPose->GetDefaultRelJointByID(id);
		}
	}

	return QuatT();
}