Example #1
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 #2
0
void myDecodeFun()
{
	sgct::SharedData::instance()->readDouble(&curr_time);
    sgct::SharedData::instance()->readFloat(&sharedSpeed);
    speed = sharedSpeed.getVal();
    sgct::SharedData::instance()->readBool(&sharedTextureOnOff);
    use_texture = sharedTextureOnOff.getVal();
    sgct::SharedData::instance()->readObj(&sharedClearColor);
    clear_color.x = sharedClearColor.getVal().x;
    clear_color.y = sharedClearColor.getVal().y;
    clear_color.z = sharedClearColor.getVal().z;
}
//! 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;
		}
	}
}