void HacksComponent::onUpdate(float delta)
{
	Timer* timer;

	for(unsigned int i = 0; i < XKILL_Enums::NROFHACKTYPES; i++)
	{
		for(unsigned int j = 0; j < activeHacks_[i].size(); j++)
		{
			timer = activeHacks_[i][j]->first;

			if(shouldUpdateTimer(activeHacks_[i][j]->second, static_cast<XKILL_Enums::HackType>(i)))
			{
				timer->update(delta);
			}

			if(timer->hasTimerExpired())
			{
				setPlayerAttributeHackFlags(activeHacks_[i][j]->second, nullptr, static_cast<XKILL_Enums::HackType>(i), false);
				SEND_EVENT(&Event_StopSound(XKILL_Enums::Sound::SOUND_JETPACK, itrPlayer.ownerIdAt(activeHacks_[i][j]->second.index())));
				removeIndexFromVector(activeHacks_[i], j);

				DEBUGPRINT("Hack " << Converter::IntToStr(i) << " expired.");
			}
			else
			{
				updateHack(activeHacks_[i][j]->second, static_cast<XKILL_Enums::HackType>(i));
			}
		}
	}
}
int InputManager::checkForNewXInputDevices()
{
	DWORD dwResult;  
	XINPUT_STATE state;
	int nrOfControllersAdded = 0;

	for(int i = nrOfXInputDevices_; i < XUSER_MAX_COUNT; i++)
	{	
		dwResult = 0;
		ZeroMemory(&state, sizeof(XINPUT_STATE));
		dwResult = XInputGetState(i, &state);

		if(dwResult == ERROR_SUCCESS)
		{
			GUID guid;
			ZeroMemory(&guid, sizeof(guid));
			InputDevice* device = new XInputDevice(nrOfXInputDevices_++, guid, "Xbox Controller (non DI)", devices_.size());
			nrOfControllersAdded++;
			devices_.push_back(device);

			SEND_EVENT(&Event_CreateInputDevice(device, device->getInputObjectArray()));
		}
	}

	return nrOfControllersAdded;
}
bool InputManager::InitInput(HWND hWindow, std::string configFilePath)
{
	keyMapper_ = new KeyMapper();
	keyMapper_->init(configFilePath);

	HRESULT result;
	nrOfXInputDevices_ = 0;

	LONG longInstance = GetWindowLong(hWindow, GWL_HINSTANCE);
	HINSTANCE hInstance = (HINSTANCE)(longInstance);

	result = DirectInput8Create(hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&dInput_, NULL);
	if(FAILED(result))
		return false;

	UpdateNumberOfGamepads(hWindow);

	GUID guid;
	memset(&guid, 0, sizeof(guid));
	QTInputDevices* mouseAndKeyboard = new QTInputDevices(guid, "Mouse & Keyboard", devices_.size());
	keyMapper_->getConfigForNewController(mouseAndKeyboard);
	devices_.push_back(mouseAndKeyboard);
	mouseAndKeyboard_ = mouseAndKeyboard;

	SEND_EVENT(&Event_CreateInputDevice(mouseAndKeyboard, mouseAndKeyboard->getInputObjectArray()));


	return true;
}
예제 #4
0
파일: inMenu.cpp 프로젝트: inosms/innocence
bool Menu_Title::VOnEvent(Event& n_event)
{
	if( n_event.GetType() == Event_Type_Input_Key_Down )
	{
		// start animation; if already animated this will do nothing
		m_stripe1.StartAnimation();
		m_stripe2.StartAnimation();

		// handle specific keys:
		Event_Input_Key_Down& tmp_event = dynamic_cast<Event_Input_Key_Down&>(n_event);
		if( tmp_event.m_key == Event_Input_Key::D || tmp_event.m_key == Event_Input_Key::RIGHT )
		{
			m_stripe1.OnKeyRight();
		}
		else if( tmp_event.m_key == Event_Input_Key::A || tmp_event.m_key == Event_Input_Key::LEFT )
		{
			m_stripe1.OnKeyLeft();
		}
		else if( tmp_event.m_key == Event_Input_Key::RETURN && m_stripe1.GetActive() == "New Game")
		{
			RemoveThis();
			SEND_EVENT(Event_LoadLevel,"test.xml");
		}
		return true;
	}
	else if( n_event.GetType() == Event_Type_Input_Mousebutton_Down )
	{
		// TODO: mouse input?
	}
	else if( n_event.GetType() == Event_Type_WindowResize )
	{
		SetStripeMatrices();
	}
	return false;
}
예제 #5
0
void CreateTeamLayer::OnBtnCreate( cocos2d::CCObject* sender )
{
	this->removeFromParentAndCleanup(true);
	EventParam* ep=new EventParam();
	ep->autorelease();
	ep->intParam=11;
	SEND_EVENT(this,PVEEvent::PVEVIEW_ENTERGAMEROOM,ep);
}
예제 #6
0
void MainWindow::wheelEvent( QWheelEvent* e )
{
	int value = 0;
	if(e->delta() > 0)
		value = 1;
	if(e->delta() < 0)
		value = -1;

	SEND_EVENT(&Event_MouseWheel(value));
}
void RenderingComponent::event_WindowResize()
{
	// Get new window size
	Event_GetWindowResolution windowResolution;
	SEND_EVENT(&windowResolution);
	int width = windowResolution.width;
	int height = windowResolution.height;

	// Resize renderer
	renderer_->resize(width, height);
}
예제 #8
0
void MainWindow::event_showMessageBox( Event_ShowMessageBox* e )
{
	// Count errors
	SETTINGS->numErrors++;

	// Turn off fullscreen to prevent freezeup
	SEND_EVENT(&Event_SetFullscreen(false));

	// Show message
	QString message(e->message.c_str());
	QMessageBox::information(0, "Error", message);
}
예제 #9
0
void TIM2_IRQHandler(void)
{
int SR_TMP;
static int compteur=0;

	SR_TMP=TIM2->SR;

		if (SR_TMP&TIM_UIF)
		{
			TIM2->SR = TIM2->SR & ~(TIM_UIF);
			compteur++;
			
			if (compteur>=10)
			{	
				compteur=0;
				SEND_EVENT(PWM_OVERFLOW_EVENT);
			}
		}	
}
bool InputManager::addNewDevice(HWND hWindow, GUID instanceGUID, GUID productGUID, std::string name)
{
	bool deviceAdded = false;

	InputDevice* device;

	if(nrOfXInputDevices_ >= XUSER_MAX_COUNT || !isXInputDevice(&productGUID))
	{
		LPDIRECTINPUTDEVICE8 dInputDevice;
		HRESULT result = dInput_->CreateDevice(instanceGUID, &dInputDevice, NULL);
		if(FAILED(result))
			return false;

		DirectInputDevice* diDevice = new DirectInputDevice(dInputDevice, instanceGUID, name, devices_.size());
		if(diDevice->Init(hWindow))
		{
			devices_.push_back(diDevice);

			device = diDevice;

			deviceAdded = true;
		}
	}
	else
	{
		device = new XInputDevice(nrOfXInputDevices_++, instanceGUID, name, devices_.size());
		devices_.push_back(device);

		deviceAdded = true;
	}

	if(deviceAdded)
	{
		SEND_EVENT(&Event_CreateInputDevice(device, device->getInputObjectArray()));
	}

	return deviceAdded;
}
void PlayerPhysicsObject::handleOutOfBounds()
{
    setGravity(btVector3(0.0f, 0.0f, 0.0f));
    setLinearVelocity(btVector3(0.0f, 0.0f, 0.0f));

    int playerEntityIndex = itrPhysics_3.ownerIdAt(attributeIndex_);
    Entity* playerEntity = itrPhysics_3.ownerAt(attributeIndex_);

    std::vector<int> playerAttributeIndices = playerEntity->getAttributes(ATTRIBUTE_PLAYER);
    for(unsigned int i = 0; i < playerAttributeIndices.size(); i++)
    {
        AttributePtr<Attribute_Player> ptr_player = itrPlayer.at(playerAttributeIndices.at(i));
        AttributePtr<Attribute_Health> playerHealthAttribute = ptr_player->ptr_health;
        if(!ptr_player->detectedAsDead)
        {
            if(!SETTINGS->isNullprocessExecuting)
            {
                ptr_player->priority--; //punish players for falling outside of the level, if the null process is not running
            }
            DEBUGPRINT("Player entity " << playerEntityIndex << " was out of bounds");
            SEND_EVENT(&Event_PlayerDeath(playerAttributeIndices[i]));
        }
    }
}
예제 #12
0
bool MainWindow::eventFilter( QObject* object, QEvent* event )
{
	QEvent::Type type = event->type();

	/*if(type == QEvent::NonClientAreaMouseMove)
	return false;
	if(type == QEvent::WindowTitleChange)
	return false;
	DEBUGPRINT("Event: " << type);*/

	if(type == QEvent::NonClientAreaMouseButtonPress)
	{
		POST_DELAYED_EVENT(new Event(EVENT_WINDOW_FOCUS_CHANGED), 0.0f);
		DEBUGPRINT("Event: NonClientAreaMouseButtonPress"); 
	}

	if(type == QEvent::WindowActivate)
	{
		SEND_EVENT(&Event(EVENT_WINDOW_FOCUS_CHANGED));
		DEBUGPRINT("Event: WindowActivate"); 
	}

	return false;
}
예제 #13
0
void PhysicsObject::removePhysicsAttributeCorrespondingToThisPhysicsObject()
{
	Entity* ownerEntityOfPhysicsAttribute = itrPhysics_.ownerAt(attributeIndex_);
	int entityOwnerId = ownerEntityOfPhysicsAttribute->getID();
	SEND_EVENT(&Event_RemoveEntity(entityOwnerId));
}
예제 #14
0
void MainWindow::keyPressEvent( QKeyEvent* e )
{

	// Toggle mouselock
	if(e->key() == Qt::Key_Alt)
		SEND_EVENT(&Event_SetMouseLock(false));

	
	// Toggle full screen
	if((e->key()==Qt::Key_Return) && (e->modifiers()==Qt::AltModifier))
		slot_toggleFullScreen();

	// Exit program
	if((e->key()==Qt::Key_F4)  && (e->modifiers()==Qt::AltModifier))
		SEND_EVENT(&Event(EVENT_QUIT_TO_DESKTOP));

	// Toggle editor
	if((e->key()==Qt::Key_F1))
		ui.dockWidget->toggleViewAction()->activate(QAction::Trigger);
	
	// Skip menu
	if((e->key()==Qt::Key_F2))
		SEND_EVENT(&Event(EVENT_STARTGAME));

	// Toggle cap fps
	if((e->key()==Qt::Key_F3))
	{
		if(!ui.actionCap_FPS->isChecked())
			ui.actionCap_FPS->setChecked(true);
		else
			ui.actionCap_FPS->setChecked(false);
	}

	// Show debug out print
	if((e->key()==Qt::Key_F5))
	{
		SEND_EVENT(&Event(EVENT_TOGGLE_DEBUG_MESSAGES));
	}
	if((e->key()==Qt::Key_F6))
	{
		SETTINGS->showDebugPhysics = !SETTINGS->showDebugPhysics;
	}

	if((e->key()==Qt::Key_1))
	{
		{Event_PostHudMessage e("Punish them all"); e.receiver = Event_PostHudMessage::RECEIVER_ALL; e.setStyle(Event_PostHudMessage::STYLE_WARNING); SEND_EVENT(&e);}
		{Event_PostHudMessage e("");  e.receiver = Event_PostHudMessage::RECEIVER_ALL; e.setHtmlMessage("","NullProcess", "is executing"); SEND_EVENT(&e);}
	}
	if((e->key()==Qt::Key_2))
	{
		// Post hud messages
		{Event_PostHudMessage e("");  e.receiver = Event_PostHudMessage::RECEIVER_ALL;e.setHtmlMessage("Now running in", "Kernel Mode"); SEND_EVENT(&e);}
		{Event_PostHudMessage e(""); e.receiver = Event_PostHudMessage::RECEIVER_ALL; e.setHtmlMessage("Chosen by Scheduler"); SEND_EVENT(&e);}
		{Event_PostHudMessage e("");  e.receiver = Event_PostHudMessage::RECEIVER_ALL;e.setHtmlMessage("","Blarrghh", "is executing"); e.receiver = Event_PostHudMessage::RECEIVER_ALL_BUT_SUBJECT; SEND_EVENT(&e);}
	}
	if((e->key()==Qt::Key_3))
	{
		Event_PostHudMessage e("");
		e.receiver = Event_PostHudMessage::RECEIVER_ALL;
		e.setStyle(Event_PostHudMessage::STYLE_WARNING);
		e.message = "Punish them all";
		SEND_EVENT(&e);
	}
	if((e->key()==Qt::Key_4))
	{
		Event_PostHudMessage e("");
		e.setHtmlMessage("You terminated", "Blarrhgh", "", "+2 priority");
		e.receiver = Event_PostHudMessage::RECEIVER_ALL;
		SEND_EVENT(&e);
	}
	

	//
	// Menu controls during in-game
	//

	if(GET_STATE() == STATE_DEATHMATCH)
	{
		switch (e->key()) 
		{
		case Qt::Key_Escape:
			SEND_EVENT(&Event(EVENT_ENDGAME));
			break;
		case Qt::Key_F11:
			{
				static bool hideHud = false;
				hideHud = !hideHud;
				SEND_EVENT(&Event_EnableHud(!hideHud));
			}
			break;
		default:
			break;
		}
	}
	
	if(GET_STATE() == STATE_MAINMENU)
	{
		//switch(e->key())
		//{
		//case Qt::Key_Escape:
		//	menu->setAlwaysOnTopAndShow(false);	//check
		//	SEND_EVENT(&Event_EnableMenu(false)); //check
		//	break;
		//default:
		//	break;
		//}
	}
	if(GET_STATE() == STATE_GAMEOVER)
	{
		switch (e->key())
		{
		case Qt::Key_Escape:
			SEND_EVENT(&Event(EVENT_ENDGAME));
			break;
		default:
			break;
		}
	}

	// Inform about key press
	SEND_EVENT(&Event_KeyPress(e->key(), true, (e->key() == Qt::Key::Key_Shift), (e->key() == Qt::Key::Key_Tab)));
}
void PhysicsComponent::onEvent(Event* e)
{
	EventType type = e->getType();
	switch(type)
	{
	case EVENT_ATTRIBUTE_UPDATED: //Removes physics objects when the corresponding physics attribute is removed
	{
		Event_AttributeUpdated* attributeUpdated = static_cast<Event_AttributeUpdated*>(e);
		int attributeIndex = attributeUpdated->index;
		if(attributeUpdated->attributeEnum == ATTRIBUTE_PHYSICS)
		{
			if(attributeUpdated->isDeleted)
			{
				if(attributeIndex < physicsObjects_->size() && physicsObjects_->at(attributeIndex) != nullptr)
				{
  					dynamicsWorld_->removeRigidBody(physicsObjects_->at(attributeIndex));
					delete physicsObjects_->at(attributeIndex);
					physicsObjects_->at(attributeIndex) = nullptr;
				}
				else
				{
					DEBUGPRINT("Mismatch when synchronizing deletion of physics objects with physics attributes");
				}
			}
			else if(attributeUpdated->isCreated)
			{
			}
			else
			{
				itrPhysics.at(attributeIndex)->reloadDataIntoBulletPhysics = true;
			}
		}
		/*else if(attributeUpdated->attributeEnum == ATTRIBUTE_CAMERA)
		{
			if(attributeUpdated->isDeleted)
			{
  				dynamicsWorld_->removeRigidBody(frustumPhysicsObjects_->at(attributeIndex));
				delete frustumPhysicsObjects_->at(attributeIndex);
				frustumPhysicsObjects_->at(attributeIndex) = nullptr;
			}
		}*/
		break;
	}
	case EVENT_MODIFY_PHYSICS_OBJECT:
	{
		Event_ModifyPhysicsObject* modifyPhysicsObject = static_cast<Event_ModifyPhysicsObject*>(e);

		int physicsAttributeIndex = modifyPhysicsObject->ptr_physics.index();
		if(physicsAttributeIndex < physicsObjects_->size() && physicsAttributeIndex > -1)
		{
			PhysicsObject* physicsObject = physicsObjects_->at(physicsAttributeIndex);
			if(physicsObject != NULL)
			{
				//Cast void pointer sent in Event_ModifyPhysicsObject to its expected data type and modify physics object accordingly
				switch(modifyPhysicsObject->modifyWhatDataInPhysicsObjectData)
				{
				case XKILL_Enums::ModifyPhysicsObjectData::GRAVITY:
					{
						Float3* gravity = static_cast<Float3*>(modifyPhysicsObject->data);
						
						physicsObject->setGravity(btVector3(gravity->x, gravity->y, gravity->z));
						break;
					}
				case XKILL_Enums::ModifyPhysicsObjectData::VELOCITY:
					{
						Float3* velocity = static_cast<Float3*>(modifyPhysicsObject->data);
						
						physicsObject->setLinearVelocity(btVector3(velocity->x, velocity->y, velocity->z));
						break;
					}
				case XKILL_Enums::ModifyPhysicsObjectData::VELOCITYPERCENTAGE:
					{
						Float3* velocityPercentage = static_cast<Float3*>(modifyPhysicsObject->data);
						
						btVector3 currentLinearVelocity = physicsObject->getLinearVelocity();
						physicsObject->setLinearVelocity(btVector3(currentLinearVelocity.x()*velocityPercentage->x, currentLinearVelocity.y()*velocityPercentage->y, currentLinearVelocity.z()*velocityPercentage->z));
						break;
					}
				case XKILL_Enums::ModifyPhysicsObjectData::FLAG_STATIC:
					{
						bool* staticPhysicsObject = static_cast<bool*>(modifyPhysicsObject->data);
						
						if(*staticPhysicsObject == true)
						{
							physicsObject->setCollisionFlags(physicsObject->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT);
						}
						else if(*staticPhysicsObject == false)
						{
							physicsObject->setCollisionFlags(physicsObject->getCollisionFlags() & ~ btCollisionObject::CF_STATIC_OBJECT);
						}
						break;
					}
				case XKILL_Enums::ModifyPhysicsObjectData::COLLISIONFILTERMASK:
					{
						/*In order to modify "collisionFilterMask", a physics objects needs to be removed from the Bullet Physics dynamics world and then readded using "addRigidBody", where "collisionFilterMask" is passed as argument.
						Write physics object data to physics attribute, modify "collisionFilterMask", and set the "reloadDataIntoBulletPhysics" flag, and this class will handle the removal and addition of the physics object.*/
						
						short* collisionFilterMaskFromEvent = static_cast<short*>(modifyPhysicsObject->data);

						AttributePtr<Attribute_Physics> ptr_physics = itrPhysics.at(physicsAttributeIndex);
						physicsObject->writeNonSynchronizedPhysicsObjectDataToPhysicsAttribute();
						ptr_physics->collisionFilterMask = *collisionFilterMaskFromEvent;
						ptr_physics->reloadDataIntoBulletPhysics = true;
					}
					break;
				case XKILL_Enums::ModifyPhysicsObjectData::GIVE_IMPULSE:
					{
						Float3* impulseVector = static_cast<Float3*>(modifyPhysicsObject->data);

						btVector3 impulse = convert(*impulseVector);
						physicsObject->applyCentralImpulse(impulse);
						break;
					}
				case XKILL_Enums::ModifyPhysicsObjectData::IF_TRUE_RECALCULATE_LOCAL_INERTIA_ELSE_SET_TO_ZERO:
					{
						bool* recalculateLocalInertia = static_cast<bool*>(modifyPhysicsObject->data);

						btVector3 localInertia = btVector3(0.0f, 0.0f, 0.0f);
						btScalar mass = itrPhysics.at(physicsAttributeIndex)->mass;
						if(*recalculateLocalInertia == true)
						{
							btCollisionShape* collisionShape = physicsObject->getCollisionShape();
							collisionShape->calculateLocalInertia(mass, localInertia);

							physicsObject->setMassProps(mass, localInertia);
							physicsObject->updateInertiaTensor();
						}
						else
						{
							physicsObject->setMassProps(mass, localInertia);
						}

						break;
					}
				}
			}
			else
			{
				ERROR_MESSAGEBOX("Invalid physics attribute id when handling event of type EVENT_MODIFY_PHYSICS_OBJECT, error 1");
			}
		}
		else
		{
			ERROR_MESSAGEBOX("Invalid physics attribute id when handling event of type EVENT_MODIFY_PHYSICS_OBJECT, error 2");
		}
		break;
	}
	case EVENT_CLOSEST_HIT_RAY_CAST:
		{
			Event_ClosestHitRayCast* event_ClosestRayCast = static_cast<Event_ClosestHitRayCast*>(e);
			handleEvent_ClosestRayCast(event_ClosestRayCast);
		break;
		}
	case EVENT_ALL_HITS_RAY_CAST:
		{
			Event_AllHitsRayCast* event_AllHitsRayCast = static_cast<Event_AllHitsRayCast*>(e);
			handleEvent_AllHitsRayCast(event_AllHitsRayCast);
		break;
		}
	case EVENT_LOAD_LEVEL_BULLET:
		CollisionShapes::Instance()->loadCollisionShapes();
		break;
	case EVENT_UNLOAD_LEVEL:
		CollisionShapes::Instance()->unloadCollisionShapes();
		break;
	case EVENT_NULL_PROCESS_STOPPED_EXECUTING:
		{
			//Reset apart-fallen world
			while(itrPhysics.hasNext())
			{
				AttributePtr<Attribute_Physics> ptr_physics = itrPhysics.getNext();
				if(ptr_physics->collisionFilterGroup == XKILL_Enums::PhysicsAttributeType::PROP)
				{
					if(physicsObjects_->at(ptr_physics.index()) != nullptr)
					{
						PropPhysicsObject* propPhysicsObject = static_cast<PropPhysicsObject*>(physicsObjects_->at(ptr_physics.index()));
						
						ptr_physics->collisionFilterGroup = XKILL_Enums::PhysicsAttributeType::WORLD;
						ptr_physics->collisionFilterMask = XKILL_Enums::PhysicsAttributeType::PLAYER | XKILL_Enums::PhysicsAttributeType::PROJECTILE |
							XKILL_Enums::PhysicsAttributeType::FRUSTUM | XKILL_Enums::PhysicsAttributeType::PICKUPABLE |
							XKILL_Enums::PhysicsAttributeType::RAY | XKILL_Enums::PhysicsAttributeType::PROP;

						ptr_physics->ptr_spatial->ptr_position->position = Float3(propPhysicsObject->worldOrigin_.x(),propPhysicsObject->worldOrigin_.y(),propPhysicsObject->worldOrigin_.z());
					
						propPhysicsObject->setCollisionFlags(propPhysicsObject->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT);//check, might not be needed

						ptr_physics->gravity = Float3(0.0f, 0.0f, 0.0f);
						ptr_physics->linearVelocity = Float3(0.0f, 0.0f, 0.0f);
						ptr_physics->mass = 0;
						ptr_physics->collisionResponse = true;

						SEND_EVENT(&Event_ReloadPhysicsAttributeDataIntoBulletPhysics(ptr_physics.index()));
					}
				}
			}
		break;
		}
	case EVENT_RELOAD_PHYSICS_ATTRIBUTE_DATA_INTO_BULLET_PHYSICS:
		{
			Event_ReloadPhysicsAttributeDataIntoBulletPhysics* event_ReloadPhysicsAttributeDataIntoBulletPhysics = static_cast<Event_ReloadPhysicsAttributeDataIntoBulletPhysics*>(e);
			int physicsAttributeId = event_ReloadPhysicsAttributeDataIntoBulletPhysics->physicsAttributeId;
			AttributePtr<Attribute_Physics> ptr_physics = itrPhysics.at(physicsAttributeId);

			ptr_physics->reloadDataIntoBulletPhysics = true;
			synchronizeWithAttributes(ptr_physics, physicsAttributeId);

			break;
		}
	}
}
예제 #16
0
ATTRIBUTES_DECLARE_ALL

MainWindow::MainWindow()
{
	QWidget::installEventFilter(this);
	menu = NULL;
	gameWidget = NULL;

	// Create console
//#ifdef XKILL_DEBUG
	AllocConsole();
	SetConsoleTitle(L"Debug console");
	int hConHandle;
	long lStdHandle;
	FILE *fp;   // redirect unbuffered STDOUT to the console
	lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
	hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
	fp = _fdopen( hConHandle, "w" );
	*stdout = *fp;
	setvbuf( stdout, NULL, _IONBF, 0 );
//#endif

	// Init iterators
	ATTRIBUTES_INIT_ALL;

	// subscribe to events
	SUBSCRIBE_TO_EVENT(this, EVENT_SHOW_FULLSCREEN);
	SUBSCRIBE_TO_EVENT(this, EVENT_SHOW_MESSAGEBOX);
	SUBSCRIBE_TO_EVENT(this, EVENT_QUIT_TO_DESKTOP);

	// create UI generated from XML file
	ui.setupUi(this);
	ui.mainToolBar->hide();
	MainWindow::setWindowTitle("XKILL");
	resize(1000, 600);
	QWidget::setAttribute(Qt::WA_PaintOnScreen);

	// init game
	gameWidget = new GameWidget(this);
	this->setCentralWidget(gameWidget);

	// init tools
	new Menu_Editor(ui, this);
	menu = new Menu_Main(this);
	
	// setup signals and slots
	connect(ui.actionFullscreen,			SIGNAL(triggered()),					this,			SLOT(slot_toggleFullScreen()));
	connect(ui.actionCap_FPS,				SIGNAL(toggled(bool)),					gameWidget,		SLOT(slot_toggleCapFPS(bool)));
	ui.actionCap_FPS->setChecked(true);
	connect(ui.actionQuit,					SIGNAL(triggered()),					this,			SLOT(close()));
	connect(gameWidget,						SIGNAL(signal_fpsChanged(QString)),		this,			SLOT(slot_setTitle(QString)));
	connect(gameWidget,						SIGNAL(signal_fpsChanged(QString)),		this,			SLOT(slot_setTitle(QString)));

	// Listen to incomming event
	this->installEventFilter(this);

	slot_toggleFullScreen();			//Fullscreen
	// DEBUG build specific settings (setAlwaysOnTopAndShow(false) is set in Menu_Main2::Menu_Main2() if DEBUG)
#if defined(DEBUG) || defined(_DEBUG)
	slot_toggleFullScreen();			//Windowed
	SEND_EVENT(&Event(EVENT_STARTGAME));//Skips menu in DEBUG
#endif
}
예제 #17
0
void MainWindow::keyReleaseEvent( QKeyEvent* e )
{
	// Inform about key release
	SEND_EVENT(&Event_KeyPress(e->key(), false, (e->key() == Qt::Key::Key_Shift), (e->key() == Qt::Key::Key_Tab)));
}
void InputComponent::handleInput(float delta)
{
	delta = SETTINGS->trueDeltaTime;

	while(itrPlayer.hasNext())
	{
		AttributePtr<Attribute_Player> ptr_player = itrPlayer.getNext();

		if(ptr_player->ptr_inputDevice.isEmpty())
			continue;

		InputDevice* device = ptr_player->ptr_inputDevice->device;
		AttributePtr<Attribute_Input> input = ptr_player->ptr_input;

		if(device == nullptr)
			continue;

		device->setSensitivityModifier(device->getFloatValue(InputAction::ACTION_F_LOW_SENSITIVITY, delta));
		if(device->getBoolValue(InputAction::ACTION_B_LOW_SENSITIVITY))
			device->setSensitivityModifier(0.5f);

		input->position.x = device->getFloatValue(InputAction::ACTION_F_WALK_LR, delta);
		input->position.y = device->getFloatValue(InputAction::ACTION_F_WALK_FB, delta);
		//input->rotation.x = device->getFloatValue(InputAction::ACTION_F_LOOK_LR, delta, true);
		//input->rotation.y = device->getFloatValue(InputAction::ACTION_F_LOOK_UD, delta, true);

		Float2 rot = device->getFormattedFloatPair(InputAction::ACTION_F_LOOK_LR, InputAction::ACTION_F_LOOK_UD, delta, true);
		input->rotation.x = rot.x;
		input->rotation.y = rot.y;

		input->fire =					device->getBoolValue(InputAction::ACTION_B_FIRE);
		input->firePressed =			device->getBoolPressed(InputAction::ACTION_B_FIRE);

		input->jetpack =				device->getBoolValue(InputAction::ACTION_B_JUMP_JETPACK);
		input->jump =					device->getBoolPressed(InputAction::ACTION_B_JUMP_JETPACK);

		input->changeAmmunitionType = 0;
		if(device->getBoolReleased(InputAction::ACTION_B_NEXT_AMMUNITIONTYPE))
			input->changeAmmunitionType++;
		if(device->getBoolReleased(InputAction::ACTION_B_PREV_AMMUNITIONTYPE))
			input->changeAmmunitionType--;

		input->changeFiringMode = 0;
		if(device->getBoolReleased(InputAction::ACTION_B_NEXT_FIRINGMODE))
			input->changeFiringMode++;
		if(device->getBoolReleased(InputAction::ACTION_B_PREV_FIRINGMODE))
			input->changeFiringMode--;

		if(ptr_player->jetHackPair.first) // if jethack active
		{
			if(device->getBoolPressed(InputAction::ACTION_B_JUMP_JETPACK))
			{
				SEND_EVENT(&Event_PlaySound(XKILL_Enums::Sound::SOUND_JETPACK, itrPlayer.ownerIdAt(ptr_player.index()), ptr_player->ptr_render->ptr_spatial->ptr_position->position, false));
			}
			else if(device->getBoolReleased(InputAction::ACTION_B_JUMP_JETPACK))
			{
				SEND_EVENT(&Event_StopSound(XKILL_Enums::Sound::SOUND_JETPACK, itrPlayer.ownerIdAt(ptr_player.index())));
			}
		}

		input->sprint =	device->getBoolValue(InputAction::ACTION_B_SPRINT);

		input->reload =	device->getBoolPressed(InputAction::ACTION_B_RELOAD);

		if(!ptr_player->detectedAsDead)
		{
			ptr_player->showScoreboard = device->getBoolValue(InputAction::ACTION_B_SHOW_SCOREBOARD);
		}

		if(device->getBoolValue(InputAction::ACTION_B_TIME_SPEED_UP))
		{
			SETTINGS->setTimeScale(SETTINGS->timeScale() + delta);
		}
		if(device->getBoolValue(InputAction::ACTION_B_TIME_SPEED_DOWN))
		{
			SETTINGS->setTimeScale(SETTINGS->timeScale() - delta);
		}


		//if(device->getBoolReleased(InputAction::ACTION_B_TOGGLE_MUTE_SOUND))
		//	SEND_EVENT(&Event_PlaySound(-1, true));

		if(device->getBoolReleased(InputAction::ACTION_B_RUMBLE_ON))
		{
			Event_Rumble* er = new Event_Rumble(itrPlayer.ownerId(), true, 100.0f, 1.0f, 1.0f);
			EventManager::getInstance()->sendEvent(er);
			delete er;
		}

		if(device->getBoolReleased(InputAction::ACTION_B_RUMBLE_OFF))
		{
			Event_Rumble* er = new Event_Rumble(itrPlayer.ownerId(), false, 100.0f, 0.0f, 0.0f);
			EventManager::getInstance()->sendEvent(er);
			delete er;
		}

		if(device->getBoolValue(InputAction::ACTION_B_WALK_FORWARD))
			input->position.y = 1.0f;
															
		if(device->getBoolValue(InputAction::ACTION_B_WALK_LEFT))
			input->position.x = -1.0f;
		
		if(device->getBoolValue(InputAction::ACTION_B_WALK_BACKWARD))
			input->position.y = -1.0f;
		
		if(device->getBoolValue(InputAction::ACTION_B_WALK_RIGHT))
			input->position.x = 1.0f;

		if(device->getBoolValue(InputAction::ACTION_B_LOOK_UP))
			input->rotation.y = -1.0f * delta;
															
		if(device->getBoolValue(InputAction::ACTION_B_LOOK_LEFT))
			input->rotation.x = -1.0f * delta;
		
		if(device->getBoolValue(InputAction::ACTION_B_LOOK_DOWN))
			input->rotation.y = 1.0f * delta;
		
		if(device->getBoolValue(InputAction::ACTION_B_LOOK_RIGHT))
			input->rotation.x = 1.0f * delta;

		normalizeVector(input->position.x, input->position.y);	// Normalize walk vector, the character shouldn't move faster than set speed

		if(device->GetType() == device->QT_INPUT_DEVICE) // Need to update QT devices since they're event based
		{
			QTInputDevices* qtDevice = static_cast<QTInputDevices*>(device);

			qtDevice->setAxesToZero();
			qtDevice->updateButtons();
			qtDevice->updateScroll();
		}
	}
}
예제 #19
0
void TIM4_IRQHandler (void)
{
	TIM4->SR = 0;

	SEND_EVENT(PWM_OVERFLOW_EVENT);
}