Example #1
0
void myPostSyncPreDrawFun()
{
	if (takeScreenshot.getVal())
	{
		gEngine->takeScreenshot();
		takeScreenshot.setVal(false);
	}
}
Example #2
0
void myEncodeFun()
{
	sgct::SharedData::instance()->writeDouble(&curr_time);
    sharedSpeed.setVal(speed);
    sgct::SharedData::instance()->writeFloat(&sharedSpeed);
    sharedTextureOnOff.setVal(use_texture);
    sgct::SharedData::instance()->writeBool(&sharedTextureOnOff);
    sharedClearColor.setVal(glm::vec3(clear_color.x, clear_color.y, clear_color.z));
    sgct::SharedData::instance()->writeObj(&sharedClearColor);
}
Example #3
0
File: main.cpp Project: Risca/sgct
void myPostSyncPreDrawFun()
{
	gEngine->setWireframe(wireframe.getVal());
	gEngine->setDisplayInfoVisibility(info.getVal());
	gEngine->setStatsGraphVisibility(stats.getVal());
	sgct_core::ClusterManager::instance()->getTrackingManagerPtr()->setEnabled(useTracking.getVal());

	if( takeScreenshot.getVal() )
	{
		gEngine->takeScreenshot();
		takeScreenshot.setVal(false);
	}

	if( reloadShaders.getVal() )
	{
		fx.getShaderProgram()->reload();
		reloadShaders.setVal(false);
		sgct::ShaderManager::instance()->reloadShaderProgram("Heightmap");
	}
}
Example #4
0
File: main.cpp Project: Risca/sgct
void keyCallback(int key, int action)
{
    if( gEngine->isMaster() )
    {
        switch( key )
        {
        case SGCT_KEY_R:
            if(action == SGCT_PRESS)
                reloadShader.setVal(true);
            break;
        }
    }
}
Example #5
0
File: main.cpp Project: Risca/sgct
int main( int argc, char* argv[] )
{
	//sgct::MessageHandler::instance()->setNotifyLevel(sgct::MessageHandler::NOTIFY_ALL);
	
	gEngine = new sgct::Engine( argc, argv );
    
    /*imagePaths.addVal( std::pair<std::string, int>("test_00.jpg", IM_JPEG) );
    imagePaths.addVal( std::pair<std::string, int>("test_01.png", IM_PNG) );
    imagePaths.addVal( std::pair<std::string, int>("test_02.jpg", IM_JPEG) );*/

	gEngine->setInitOGLFunction( myInitOGLFun );
	gEngine->setDrawFunction( myDrawFun );
	gEngine->setPreSyncFunction( myPreSyncFun );
	gEngine->setPostSyncPreDrawFunction(myPostSyncPreDrawFun);
	gEngine->setCleanUpFunction( myCleanUpFun );
	gEngine->setKeyboardCallbackFunction(keyCallback);
    gEngine->setContextCreationCallback( contextCreationCallback );
	gEngine->setDropCallbackFunction(myDropCallback);

	if( !gEngine->init( sgct::Engine::OpenGL_3_3_Core_Profile ) )
	{
		delete gEngine;
		return EXIT_FAILURE;
	}
    
    gEngine->setDataTransferCallback(myDataTransferDecoder);
	gEngine->setDataTransferStatusCallback(myDataTransferStatus);
	gEngine->setDataAcknowledgeCallback(myDataTransferAcknowledge);
    //gEngine->setDataTransferCompression(true, 6);

    //sgct::SharedData::instance()->setCompression(true);
	sgct::SharedData::instance()->setEncodeFunction(myEncodeFun);
	sgct::SharedData::instance()->setDecodeFunction(myDecodeFun);

	// Main loop
	gEngine->render();

	running.setVal(false);

	if (loadThread)
	{
		loadThread->join();
		delete loadThread;
	}

	// Clean up
	delete gEngine;

	// Exit program
	exit( EXIT_SUCCESS );
}
Example #6
0
void keyCallback(int key, int action)
{
	if (gEngine->isMaster())
	{
		switch (key)
		{
		case SGCT_KEY_P:
		case SGCT_KEY_F10:
			if (action == SGCT_PRESS)
				takeScreenshot.setVal(true);
			break;
		}
	}
}
Example #7
0
File: main.cpp Project: Risca/sgct
void myDropCallback(int count, const char** paths)
{
	if (gEngine->isMaster())
	{
		std::size_t found;

		//simpy pick the first path to transmit
		std::string tmpStr(paths[0]);

		//transform to lowercase
		std::transform(tmpStr.begin(), tmpStr.end(), tmpStr.begin(), ::tolower);

		found = tmpStr.find(".jpg");
		if (found != std::string::npos)
		{
			imagePaths.addVal(std::pair<std::string, int>(paths[0], IM_JPEG));
			transfer.setVal(true);
			return;
		}

		found = tmpStr.find(".jpeg");
		if (found != std::string::npos)
		{
			imagePaths.addVal(std::pair<std::string, int>(paths[0], IM_JPEG));
			transfer.setVal(true);
			return;
		}

		found = tmpStr.find(".png");
		if (found != std::string::npos)
		{
			imagePaths.addVal(std::pair<std::string, int>(paths[0], IM_PNG));
			transfer.setVal(true);
			return;
		}
	}
}
Example #8
0
File: main.cpp Project: Risca/sgct
void myPostSyncPreDrawFun()
{
    if( reloadShader.getVal() )
    {
        reloadShader.setVal(false); //reset

        sgct::ShaderProgram sp = sgct::ShaderManager::instance()->getShaderProgram( "xform" );
        sp.reload();

        //reset location variables
        sgct::ShaderManager::instance()->bindShaderProgram( "xform" );
        time_loc = sgct::ShaderManager::instance()->getShaderProgram( "xform").getUniformLocation( "curr_time" );
        matrix_loc = sgct::ShaderManager::instance()->getShaderProgram( "xform").getUniformLocation( "MVP" );
        sgct::ShaderManager::instance()->unBindShaderProgram();
    }
}
Example #9
0
File: main.cpp Project: Risca/sgct
void keyCallback(int key, int action)
{
	if( gEngine->isMaster() )
	{
		switch( key )
		{
		case 'S':
			if(action == SGCT_PRESS)
				stats.toggle();
			break;

		case 'I':
			if(action == SGCT_PRESS)
				info.toggle();
			break;

		case 'L':
			if(action == SGCT_PRESS)
				light.toggle();
			break;

		case 'W':
			if(action == SGCT_PRESS)
				wireframe.toggle();
			break;

		case 'Q':
			if(action == SGCT_PRESS)
				gEngine->terminate();
			break;

		case 'P':
		case SGCT_KEY_F10:
			if(action == SGCT_PRESS)
				takeScreenshot.setVal( true );
			break;

		case SGCT_KEY_UP:
			arrowButtons[FORWARD] = ((action == SGCT_REPEAT || action == SGCT_PRESS) ? true : false);
			break;

		case SGCT_KEY_DOWN:
			arrowButtons[BACKWARD] = ((action == SGCT_REPEAT || action == SGCT_PRESS) ? true : false);
			break;
		}
	}
}
Example #10
0
File: main.cpp Project: Risca/sgct
void threadWorker(void *arg)
{
    while (running.getVal())
	{
		//runs only on master
		if (transfer.getVal() && !serverUploadDone.getVal() && !clientsUploadDone.getVal())
        {
			startDataTransfer();
            transfer.setVal(false);
            
            //load texture on master
            uploadTexture();
			serverUploadDone = true;
            
            if(sgct_core::ClusterManager::instance()->getNumberOfNodes() == 1) //no cluster
            {
				clientsUploadDone = true;
            }
        }

		sgct::Engine::sleep(0.1); //ten iteration per second
	}
}
Example #11
0
File: main.cpp Project: Risca/sgct
void myPostSyncPreDrawFun()
{
	gEngine->setWireframe(wireframe.getVal());
	gEngine->setDisplayInfoVisibility(info.getVal());
	gEngine->setStatsGraphVisibility(stats.getVal());

	if( takeScreenshot.getVal() )
	{
		gEngine->takeScreenshot();
		takeScreenshot.setVal(false);
	}

	light.getVal() ? mRootNode->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE) :
		mRootNode->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);

	mSceneTrans->setMatrix(osg::Matrix::rotate( glm::radians(curr_time.getVal() * 8.0), 0.0, 1.0, 0.0));
	mSceneTrans->postMult(osg::Matrix::translate(0.0, -0.1, dist.getVal()));

	//transform to scene transformation from configuration file
	mSceneTrans->postMult( osg::Matrix( glm::value_ptr( gEngine->getModelMatrix() ) ));

	//update the frame stamp in the viewer to sync all
	//time based events in osg
	mFrameStamp->setFrameNumber( gEngine->getCurrentFrameNumber() );
	mFrameStamp->setReferenceTime( curr_time.getVal() );
	mFrameStamp->setSimulationTime( curr_time.getVal() );
	mViewer->setFrameStamp( mFrameStamp.get() );
	mViewer->advance( curr_time.getVal() ); //update

	//traverse if there are any tasks to do
	if (!mViewer->done())
	{
		mViewer->eventTraversal();
		//update travelsal needed for pagelod object like terrain data etc.
		mViewer->updateTraversal();
	}
}
Example #12
0
//! When something from a server extension is received this function is called. Could be position updating  of gameobject, a private message or just a notification. The ["cmd"] parameter of the event that is received  reveals which extension that was spitting out the info. Based on extension this function will do different things.
void NetworkManager::OnSmartFoxExtensionResponse(unsigned long long ptrContext, boost::shared_ptr<BaseEvent> ptrEvent) {
	// get pointer to main frame.
	NetworkManager* ptrMainFrame = (NetworkManager*)ptrContext;

	// Check that we're still alive and running
	if (ptrMainFrame == NULL) {
		return;
	}

	// Get the cmd parameter of the event
	boost::shared_ptr<map<string, boost::shared_ptr<void>>> ptrEventParams = ptrEvent->Params();
	boost::shared_ptr<void> ptrEventParamValueCmd = (*ptrEventParams)["cmd"];
	boost::shared_ptr<string> ptrNotifiedCmd = ((boost::static_pointer_cast<string>)(ptrEventParamValueCmd));


	// check the type of the command
	if (*ptrNotifiedCmd == "PilotEvent") {
		boost::shared_ptr<void> ptrEventParamValueParams = (*ptrEventParams)["params"];
		boost::shared_ptr<ISFSObject> ptrNotifiedISFSObject = ((boost::static_pointer_cast<ISFSObject>)(ptrEventParamValueParams));

		pInputRotX = *(ptrNotifiedISFSObject->GetDouble("sgctRotY"));
		pInputRotZ = *(ptrNotifiedISFSObject->GetDouble("sgctRotX"));

		bool pInputForward = *(ptrNotifiedISFSObject->GetBool("sgctForward"));
		//bool pInputBackward = *(ptrNotifiedISFSObject->GetBool("sgctBackward"));

		accRotX += pInputRotX * accRotVal;
		accRotZ += pInputRotZ * accRotVal;

		if (pInputForward) {
			if (enginePowerup.getVal() <= 0.0 && navigationSpeed < accThrustMax * eInputEngine)
				navigationSpeed += accThrustVal * eInputEngine;
			else if (navigationSpeed < accThrustMax * eInputEngine * 2.0)
				navigationSpeed += accThrustVal * eInputEngine * 2.0;
		}
		//if (pInputBackward && navigationSpeed > -0.1) {
		//	navigationSpeed -= accThrustVal * eInputEngine;
		//}
	}

	if (*ptrNotifiedCmd == "GunnerEvent") {
		boost::shared_ptr<void> ptrEventParamValueParams = (*ptrEventParams)["params"];
		boost::shared_ptr<ISFSObject> ptrNotifiedISFSObject = ((boost::static_pointer_cast<ISFSObject>)(ptrEventParamValueParams));

		gInputRotX = *(ptrNotifiedISFSObject->GetDouble("sgctRotX")) * 3.0;
		gInputRotY = *(ptrNotifiedISFSObject->GetDouble("sgctRotY")) * 3.0;
		bool fire = *(ptrNotifiedISFSObject->GetBool("sgctFire"));

		

		if (fire && fireTimer <= 0.0) {
			//if (gEngine->isMaster())
			soundManager.play("laser", osg::Vec3f(0.0f, 0.0f, 0.0f));
			fireSync.setVal(true);
			fireTimer = fireRate / eInputTurret;
		}
	}
	if (*ptrNotifiedCmd == "EngineerEvent") {
		boost::shared_ptr<void> ptrEventParamValueParams = (*ptrEventParams)["params"];
		boost::shared_ptr<ISFSObject> ptrNotifiedISFSObject = ((boost::static_pointer_cast<ISFSObject>)(ptrEventParamValueParams));

		eInputEngine = ((float)(*(ptrNotifiedISFSObject->GetFloat("sgctEngine"))) * 3 + 0.5);	//	0.5 - 3.5
		eInputShield = 1.0 - 0.75 * ((float)(*(ptrNotifiedISFSObject->GetFloat("sgctShield"))));//	1.0 - 0.25	(percent of damage taken)
		eInputTurret = ((float)(*(ptrNotifiedISFSObject->GetFloat("sgctTurret"))) + 0.5);		//	0.5 - 1.5

	}
	if (*ptrNotifiedCmd == "BenchMarking") {

		boost::shared_ptr<void> ptrEventParamValueParams = (*ptrEventParams)["params"];
		boost::shared_ptr<ISFSObject> ptrNotifiedISFSObject = ((boost::static_pointer_cast<ISFSObject>)(ptrEventParamValueParams));

		double item = *(ptrNotifiedISFSObject->GetDouble("1"));
		double item2 = *(ptrNotifiedISFSObject->GetDouble("2"));
		double item3 = *(ptrNotifiedISFSObject->GetDouble("3"));
		double item4 = *(ptrNotifiedISFSObject->GetDouble("4"));

		end = omp_get_wtime();
		std::cout << "Reply from server, " << static_cast<int>((end - start) * 1000) << "ms." << endl;

		start = omp_get_wtime();
		// send new item 
		if (itemsSent++ < 35 && benchmarkingStarted) {
			boost::shared_ptr<ISFSObject> parameters(new SFSObject());

			parameters->PutDouble("1", 0.923);
			parameters->PutDouble("2", 0.953);
			parameters->PutDouble("3", 0.343);
			parameters->PutDouble("4", 0.523);

			// find our room to send to.
			boost::shared_ptr<Room> lastJoined = ptrMainFrame->m_ptrSmartFox->LastJoinedRoom();

			// Perform extensionrequest
			boost::shared_ptr<IRequest> extRequest(new ExtensionRequest("BenchMarking", parameters, lastJoined));
			ptrMainFrame->m_ptrSmartFox->Send(extRequest);
		}
		else {
			benchmarkingStarted = false;
			itemsSent = 0;
		}
	}
}
Example #13
0
File: main.cpp Project: Risca/sgct
void keyCallback(int key, int action)
{
	if( gEngine->isMaster() )
	{
		switch( key )
		{
		case 'S':
			if(action == SGCT_PRESS)
				stats.toggle();
			break;

		case 'I':
			if(action == SGCT_PRESS)
				info.toggle();
			break;

		case 'W':
			if(action == SGCT_PRESS)
				wireframe.toggle();
			break;

		case 'Q':
			if(action == SGCT_PRESS)
				gEngine->terminate();
			break;

		case 'T':
			if(action == SGCT_PRESS)
				useTracking.toggle();
			break;

		case 'E':
			if(action == SGCT_PRESS)
			{
				glm::dmat4 xform = glm::translate( glm::dmat4(1.0), glm::dvec3(0.0f, 0.0f, 4.0f) );
				sgct_core::ClusterManager::instance()->getDefaultUserPtr()->setTransform(xform);
			}
			break;

		case SGCT_KEY_SPACE:
			if(action == SGCT_PRESS)
				mPause = !mPause;
			break;

		case 'F':
			if(action == SGCT_PRESS)
				for(std::size_t i=0; i<gEngine->getNumberOfWindows(); i++)
				{
					gEngine->getWindowPtr(i)->setUseFXAA( !gEngine->getWindowPtr(i)->useFXAA() );
				}
			break;

		case 'P':
		case SGCT_KEY_F10:
			if(action == SGCT_PRESS)
				takeScreenshot.setVal( true );
			break;

		case 'R':
			if(action == SGCT_PRESS)
				reloadShaders.setVal(true);
			break;
		}
	}
}