예제 #1
0
void Settings::checkCommandLineOptions(int argc, char *argv[])
{
	// check if --help occurs, overrides the rest
	for (int i=1; i < argc; ++i )
	{
		std::string sw = argv[i];
		if ( sw == "--help" )
		{
			createHelpInfo();
			std::cout << helpinfo.str() << std::endl;
			exit(0);
		}
	}

	// decode arguments
	int optind=1;
	while ((optind < argc)) //  && (argv[optind][0]=='-')
	{
		if ( argv[optind][0]=='-' )
		{
			std::string sw = argv[optind];

			if ( sw=="--profile" )
			{
				if ( argv[++optind] )
					loadProfile(argv[optind]);
				else
					BE_ERROR("::SETTINGS --profile expects a filename");
			}

			else
			{
				parseH.reset();
				if ( parseH.beginMatchesStrip( "--", sw ) )
				{
					sw.append(" ");
					std::string purecmd = parseH.returnUntillStrip( ' ', sw );

					if ( isCVar(purecmd) )
					{
						if ( argv[++optind] )
						{
							if ( !setCVar(purecmd, argv[optind]) )
								BE_ERROR("::SETTINGS error: could not set cvar '" << purecmd << "', value '" << argv[optind] << "'");
						}
						else
							BE_ERROR("::SETTINGS error: option '" << purecmd << "' expects an argument");
					}
					else
						BE_LOG( "warning: unknown commandline option: '" << purecmd << "'" );
				}
			}
		}
		++optind;
	}
 
	if ( optind < argc )
		BE_LOG( "warning: unknown commandline option: '" << argv[optind] << "'" );
}
예제 #2
0
void PhysXPhysics::AddShape(Actor* pActor, PxGeometry* geometry, float density, const std::string& physicsMaterial, bool gravityEnabled, float linearDamping, float angularDamping, const std::string& bodyType)
{
	BE_ASSERT(pActor);
	ActorId actorId = pActor->GetId();
	BE_ASSERTf(m_actorRigidBodyMap.find(actorId) == m_actorRigidBodyMap.end(), "Actor with more than one rigidbody");

	Mat4x4 transform = Mat4x4::g_Identity;
	
	TransformComponent* pTransformComponent = pActor->GetComponent<TransformComponent>(TransformComponent::g_Name);

	if (pTransformComponent)
	{
		transform = pTransformComponent->GetTransform();
	}
	else 
	{
		//Doesnt work without transform
		BE_ERROR("Actor %s PhysicsComponent requires Shape to have Transform Component: %d", actorId);
		return;
	}

	PhysicsMaterialData material(LookupMaterialData(physicsMaterial));
	PxMaterial* mat = m_pPhysicsSdk->createMaterial(material.m_friction, material.m_friction, material.m_restitution);

	Vec3 translation, scale;
	Quaternion rotation;
	
	bool ok = transform.Decompose(translation, rotation, scale);
	PxQuat pxRot;
	PxVec3 pxLoc;
	Vec3ToPxVec(translation, &pxLoc);
	QuaternionToPxQuat(rotation, &pxRot);
	PxTransform t(pxLoc, pxRot);

	if (bodyType == "Dynamic")
	{
		PxRigidDynamic* body = PxCreateDynamic(*m_pPhysicsSdk, t, *geometry, *mat, density);
		body->setActorFlag(PxActorFlag::eDISABLE_GRAVITY, !gravityEnabled);
		PxRigidBodyExt::updateMassAndInertia(*body, density);
		body->setLinearDamping(linearDamping);
		body->setAngularDamping(angularDamping);
		m_pScene->addActor(*body);

		m_actorRigidBodyMap[actorId] = body;
		m_rigidBodyActorMap[body] = actorId;
	}
	else
	{
		BE_ERROR("[Physics] BodyType not supported: %s", bodyType.c_str());
		return;
	}
}
예제 #3
0
IGamePhysics* CreateGamePhysics(EPhysicsEngine engineType)
{
	IGamePhysics* gamePhysics;

	switch (engineType) {
#ifdef USE_PHYSX
	case EPhysicsEngine::BE_PHYSICS_PHYSX:
		gamePhysics = BE_NEW PhysXPhysics;
		break;
#endif
#ifdef USE_BOMBASTPHYSICS
	case EPhysicsEngine::BE_PHYSICS_BOMBAST:
		gamePhysics = BE_NEW BombastPhysics;
		break;
#endif
	default:
		BE_ERROR("Invalid Physics Engine Type %i used for CreateGamePhysics", engineType);
		return nullptr;
	}

	if (gamePhysics && !gamePhysics->VInitialize())
	{
		SAFE_DELETE(gamePhysics);
	}

	return gamePhysics;
}
예제 #4
0
bool PhysXPhysics::VInitialize()
{
	VLoadPhysicsConfigXml();
	int version = PX_PHYSICS_VERSION;
	m_pFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, m_allocatorCallback, m_errorCallback);
	m_pPhysicsSdk = PxCreatePhysics(PX_PHYSICS_VERSION, *m_pFoundation, PxTolerancesScale(), true);

	if (!m_pPhysicsSdk)
	{
		BE_ERROR("Error Creating PhysX device.");
		return false;
	}

	PxSceneDesc sceneDesc(m_pPhysicsSdk->getTolerancesScale());

	sceneDesc.gravity = PxVec3(0.0f, -9.81f, 0.0f); //Set Gravity
	m_pDispatcher = PxDefaultCpuDispatcherCreate(2);
	sceneDesc.cpuDispatcher = m_pDispatcher;
	sceneDesc.filterShader = PxDefaultSimulationFilterShader;

	m_pScene = m_pPhysicsSdk->createScene(sceneDesc);

#ifdef ENABLE_PHYSX_PVD
	ConnectPVD();
#endif
	
	return true;
}
예제 #5
0
const int* Settings::getCVarPtr(const std::string& name)
{
	CVar* cvar = cvarlist[name];
	if ( cvar )
		return cvar->getIntValuePointer();
	else
		BE_ERROR("::SETTINGS error unknown cvar: " << name);
}
예제 #6
0
const std::string& Settings::getCVarS(const std::string& name)
{
	CVar* cvar = cvarlist[name];
	if ( cvar )
		return cvar->getStringValue();
	else
		BE_ERROR("::SETTINGS error unknown cvar: " << name);
}
예제 #7
0
void Settings::loadProfile(const std::string& filename)
{
	m_logDebug << "::SETTINGS loading from '" << filename << "'\n";

	BeFile befileProfile;
	if ( m_filesystem.load( befileProfile, filename ) )
	{
		std::string line;
		while ( befileProfile.getLine(line) )
		{
			parseH.reset();
			// trim spaces and comment lines
			parseH.trimWhitespaces(line);
			parseH.removeCommentlines(line);

			if ( !line.empty() )
			{
				std::string sw = parseH.returnUntillStrip( ' ', line );
				if ( !sw.empty() )
				{
					if ( isCVar(sw) )
					{
						while ( parseH.beginMatchesStrip( " ", line ) ) {};
						std::string arg = parseH.returnUntillStrip( ' ', line );
						if ( !setCVar(sw, arg) )
							BE_ERROR("::SETTINGS could not set cvar '" << sw <<  "', value '" << arg <<  "'");
					}
					else
						m_logDebug << "::SETTINGS warning: unknown option in profile '" << sw << "'\n";
				}
				else
					BE_ERROR("::SETTINGS error: Option without an argument '" << line);
			}
		}
	}
	else
		m_logDebug << "::SETTINGS warning: cannot open profile '" << filename << "'\n";
}
예제 #8
0
void RealtimeProcess::VOnInit()
{
	Process::VOnInit();
	m_hThread = CreateThread(NULL, 0, ThreadProc, this, 0, &m_threadId);

	if (m_hThread == NULL)
	{
		BE_ERROR("Could not Create Thread!");
		Fail();
		return;
	}

	SetThreadPriority(m_hThread, m_threadPriority);
}
예제 #9
0
bool EventManager::VAddListener(const EventListenerDelegate& eventDelegate, const EventType& type)
{
	EventListenerList& eventListenerList = m_eventListeners[type];
	for (auto it = eventListenerList.begin(); it != eventListenerList.end(); it++)
	{
		if(eventDelegate == (*it))
		{
			BE_ERROR("Attempting To Double-Register Delegete");
			return false;
		}
	}

	eventListenerList.push_back(eventDelegate);

	return true;
}
예제 #10
0
bool GraphicsManager::Initialize(HWND hwnd)
{
	bool result;
	
	Renderer renderImpl = GetRendererImpl();
	if (renderImpl == Renderer_D3D11)
	{
		m_pRenderer = BE_NEW D3DClass11;
	}
	
	if (!m_pRenderer)
	{
		BE_ERROR("Failed to create Renderer");
		return false;
	}

	if (!m_pRenderer->VInitialize(g_pApp->m_options.m_screenSize.x, g_pApp->m_options.m_screenSize.y, g_pApp->m_options.m_bVsync, hwnd, g_pApp->m_options.m_bFullscreen, 1000.0f, 0.1f))
	{
		BE_ERROR("Could not initialize Renderer");
		return FALSE;
	}

	m_pShaderManager = BE_NEW ShaderManager;
	if (!m_pShaderManager)
	{
		BE_ERROR("Could not Allocate the ShaderManager Object!");
		return false;
	}

	result = m_pShaderManager->Initialize(m_pRenderer);
	if (!result)
	{
		BE_ERROR("Could not initialize the ShaderManager Object!");
		return FALSE;
	}

	m_pDeferredRenderingManager = BE_NEW DeferredRenderingManager;
	if (!m_pDeferredRenderingManager)
	{
		BE_ERROR("Could not allocate the Deferred Buffers");
		return false;
	}

	Point screenSize = g_pApp->GetScreenSize();
	result = m_pDeferredRenderingManager->Initialize(m_pRenderer->GetDevice(), screenSize.GetX(), screenSize.GetY());
	if (!result)
	{
		BE_ERROR("Could not initialize the Deferred Buffers");
		return false;
	}

	return true;
}
예제 #11
0
bool EventManager::VQueueEvent(const EventDataPtr& pEvent)
{
	BE_ASSERT(m_activeQueue >= 0);
	BE_ASSERT(m_activeQueue < EVENTMANAGER_NUM_QUEUES);

	if (!pEvent)
	{
		BE_ERROR("Invalid Event in VQueueEvent()");
		return false;
	}

	auto findIt = m_eventListeners.find(pEvent->VGetEventType());
	if (findIt != m_eventListeners.end())
	{
		m_queues[m_activeQueue].push_back(pEvent);
		return true;
	}
	else
	{
		return false;
	}
}
예제 #12
0
HumanView::HumanView(IRenderer* renderer)
{
	m_pProcessManager = BE_NEW ProcessManager;
	m_pDebugManager = BE_NEW DebugManager;

	m_pKeyboardHandler = nullptr;
	m_pMouseHandler = nullptr;

	m_mouseRadius = 1;
	m_viewId = be_InvalidGameViewId;

	RegisterAllDelegates();
	m_coreGameState = CGS_Initializing;

	m_runFullSpeed = true;

	if (renderer)
	{
		m_pScene = BE_NEW ScreenElementScene(renderer);

		Frustum frustum;
		frustum.Init(BE_PI / 4.0f, 1.0f, 1.0f, 100.0f);
		m_pCamera = BE_NEW CameraNode(&Mat4x4::g_Identity, frustum);
		BE_ASSERTf(m_pScene && m_pCamera, "Out of Memory");

		m_pScene->VAddChild(INVALID_ACTOR_ID, m_pCamera);
		m_pScene->SetCamera(m_pCamera);
	}

	bool result;
	result = m_pDebugManager->Initialize(this);
	if (!result)
	{
		BE_ERROR("Failed to Initialze DebugManager");
	}
}
예제 #13
0
void Settings::loadProfile(const std::string& filename)
{
	//m_logDebug << "::SETTINGS loading from '" << filename << "'\n";
	BE_LOG("::SETTINGS loading from '" << filename << "'");


	BeFile befileProfile;
	if ( m_filesystem.load( befileProfile, filename ) )
	{
		// update profilename
		unsigned found = filename.find_last_of("/\\");
		std::string file;
		//strip path
		if ( found != std::string::npos ) {
			file = filename.substr(found+1);
		}
		else {
			// no path, all are file
			file = filename;
		}
		//strip ".pro"
		found = file.rfind(".pro");
		if (found != std::string::npos ) {
			m_profileName = file.erase(found);
		}
		else {
			m_profileName = file;
		}
		BE_LOG( "profile name is updated to '" << m_profileName << "'" );
		
		std::string line;
		while ( befileProfile.getLine(line) )
		{
			parseH.reset();
			// trim spaces and comment lines
			parseH.trimWhitespaces(line);
			parseH.removeCommentlines(line);

			if ( !line.empty() )
			{
				std::string sw = parseH.returnUntillStrip( ' ', line );
				if ( !sw.empty() )
				{
					if ( isCVar(sw) )
					{
						while ( parseH.beginMatchesStrip( " ", line ) ) {};
						std::string arg = parseH.returnUntillStrip( ' ', line );
						if ( !setCVar(sw, arg) )
							BE_ERROR("::SETTINGS could not set cvar '" << sw <<  "', value '" << arg <<  "'");
					}
					else
						BE_LOG( "warning: unknown option in profile '" << sw << "'" );
				}
				else
					BE_ERROR("::SETTINGS error: Option without an argument '" << line);
			}
		}
	}
	else
		BE_LOG( "warning: cannot open profile '" << filename << "'" );
}
예제 #14
0
bool EventManager::VUpdate(unsigned long maxMs)
{
	unsigned long curMs = GetTickCount();
	unsigned long computedMaxMs = (maxMs == IEventManager::kINFINITE ? IEventManager::kINFINITE : curMs + maxMs);

	EventDataPtr pRealtimeEvent;
	while (m_realtimeEventQueue.try_pop(pRealtimeEvent))
	{
		VQueueEvent(pRealtimeEvent);

		curMs = GetTickCount();
		if (maxMs != IEventManager::kINFINITE)
		{
			if (curMs >= computedMaxMs) {
				BE_ERROR("Realtime Proccess is spamming Event Manager!");
			}
		}
	}

	int queueToProcess = m_activeQueue;
	m_activeQueue = (m_activeQueue + 1) % EVENTMANAGER_NUM_QUEUES;
	m_queues[m_activeQueue].clear();

	while (!m_queues[queueToProcess].empty())
	{
		EventDataPtr pEvent = m_queues[queueToProcess].front();
		m_queues[queueToProcess].pop_front();

		const EventType& eventType = pEvent->VGetEventType();

		auto findIt = m_eventListeners.find(eventType);
		if (findIt != m_eventListeners.end())
		{
			const EventListenerList& eventListeners = findIt->second;

			for (auto it = eventListeners.begin(); it != eventListeners.end(); it++)
			{
				EventListenerDelegate listener = (*it);
				listener(pEvent);
			}
		}

		curMs = GetTickCount();
		if (maxMs != IEventManager::kINFINITE && curMs >= computedMaxMs)
		{
			//Abort, ran out of time
			break;
		}
	}

	//If couldnt process all, push remaining to new active queue
	bool queueFlushed = m_queues[queueToProcess].empty();
	if (!queueFlushed)
	{
		while (!m_queues[queueToProcess].empty())
		{
			EventDataPtr pEvent = m_queues[queueToProcess].back();
			m_queues[queueToProcess].pop_back();
			m_queues[m_activeQueue].push_front(pEvent);
		}
	}

	return queueFlushed;
}
bool MultiTextureShader::InitializeShader(ID3D11Device* device, std::string vertexShaderPath, std::string pixelShaderPath)
{
	HRESULT result;
	D3D11_INPUT_ELEMENT_DESC polygonLayout[2];
	unsigned int numElements;
	D3D11_BUFFER_DESC matrixBufferDesc;
	D3D11_SAMPLER_DESC samplerDesc;

	Resource vertexShaderResource(vertexShaderPath.c_str());
	ResourceHandle* pVertexResHandle = g_pApp->m_pResourceCache->GetHandle(&vertexShaderResource);

	result = device->CreateVertexShader(pVertexResHandle->Buffer(), pVertexResHandle->Size(), nullptr, &m_pVertexShader);
	if (FAILED(result))
	{
		BE_ERROR("Failed to create vertex shader");

		return false;
	}

	Resource pixelShaderResource(pixelShaderPath.c_str());
	ResourceHandle* pPixelResHandle = g_pApp->m_pResourceCache->GetHandle(&pixelShaderResource);

	result = device->CreatePixelShader(pPixelResHandle->Buffer(), pPixelResHandle->Size(), nullptr, &m_pPixelShader);
	if (FAILED(result))
	{
		BE_ERROR("Failed to create Pixel shader");

		return false;
	}

	polygonLayout[0].SemanticName = "POSITION";
	polygonLayout[0].SemanticIndex = 0;
	polygonLayout[0].Format = DXGI_FORMAT_R32G32B32_FLOAT;
	polygonLayout[0].InputSlot = 0;
	polygonLayout[0].AlignedByteOffset = 0;
	polygonLayout[0].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
	polygonLayout[0].InstanceDataStepRate = 0;

	polygonLayout[1].SemanticName = "TEXCOORD";
	polygonLayout[1].SemanticIndex = 0;
	polygonLayout[1].Format = DXGI_FORMAT_R32G32_FLOAT;
	polygonLayout[1].InputSlot = 0;
	polygonLayout[1].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
	polygonLayout[1].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
	polygonLayout[1].InstanceDataStepRate = 0;

	numElements = sizeof(polygonLayout) / sizeof(polygonLayout[0]);

	result = device->CreateInputLayout(polygonLayout, numElements, pVertexResHandle->Buffer(), pVertexResHandle->Size(), &m_pLayout);
	if (FAILED(result))
	{
		return false;
	}

	matrixBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
	matrixBufferDesc.ByteWidth = sizeof(MatrixBufferType);
	matrixBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
	matrixBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
	matrixBufferDesc.MiscFlags = 0;
	matrixBufferDesc.StructureByteStride = 0;

	result = device->CreateBuffer(&matrixBufferDesc, NULL, &m_pMatrixBuffer);
	if (FAILED(result))
	{
		return false;
	}

	samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
	samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
	samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
	samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
	samplerDesc.MipLODBias = 0.0f;
	samplerDesc.MaxAnisotropy = 1;
	samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
	samplerDesc.BorderColor[0] = 0;
	samplerDesc.BorderColor[1] = 0;
	samplerDesc.BorderColor[2] = 0;
	samplerDesc.BorderColor[3] = 0;
	samplerDesc.MinLOD = 0;
	samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;

	result = device->CreateSamplerState(&samplerDesc, &m_pSampleState);
	if (FAILED(result))
	{
		return false;
	}

	return true;
}