//=============================================================
//Windows Functions
//=============================================================
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
				   PSTR szCmdLine, int iCmdShow)
{
	MSG			msg;
	static int	iTickTrigger = 0;
	int			iTickCount;

	if (GameInitialize(hInstance))
	{
		//Initialize the game engine
		if (!GameEngine::GetEngine()->Initialize(iCmdShow))
			return FALSE;

		//Enter the main message loop
		while (TRUE)
		{
			if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
			{
				//Process the message
				if (msg.message == WM_QUIT)
					break;
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
			else
			{
				//Make sure the game engine isn't sleeping
				if (!GameEngine::GetEngine()->GetSleep())
				{
					//Check the tick count to see if a game cycle has elapsed
					iTickCount = GetTickCount();
					if (iTickCount > iTickTrigger)
					{
						iTickTrigger = iTickCount +
							GameEngine::GetEngine()->GetFrameDelay();
						HandleKeys();
						GameCycle();
					}
				}
			}
		}
		return (int)msg.wParam;
	}

	//End the game
	GameEnd();

	return TRUE;
}
示例#2
0
void MainMouseRButtonDown(HWND hwnd, BOOL fDoubleClick, int x, int y, UINT keyFlags)
{
	// Send it to HandleKeys first in case user set a keybind to one
	// of the mouse buttons.
	HandleKeys(0);

	/* See if a module wants to handle mouse click */
	if (ModuleEvent(EVENT_MOUSECLICK, hwnd, fDoubleClick, x, y, keyFlags) == False)
		return;

	switch (state)
	{
	case STATE_GAME:
		GameMouseButtonDown(hwnd, fDoubleClick, x, y, keyFlags);
		break;
	}
}
示例#3
0
void Keyboard::Update(float /*dt*/)
{
	/*for (int j = 0; j < m_currentSize; j++)
	{
		m_toggles[j].CheckToggle();
	}*/
	for (int j = 0; j < m_numKeys; ++j)
	{
		int vKey = m_keys[j];
		Key * key = &m_previousKeyboardState[vKey];
		key->justPressed = false;
	}
	HandleKeys(); //FIRST
	HandleToggles(); //SECOND

	
}
示例#4
0
文件: main.cpp 项目: jmazar/Ogl
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
		switch(msg)
		{
		case WM_KEYDOWN:
			HandleKeys(hwnd, wParam);
			break;
		case WM_CLOSE:
				PostQuitMessage(0);
		break;
		case WM_DESTROY:
				PostQuitMessage(0);
		break;
		default:
				return DefWindowProc(hwnd, msg, wParam, lParam);
		}
		return 0;
}
示例#5
0
// Menu loop
void menuloop()
{
	// Stop sound
	enablesound(0);

	// Update EEPROM
	sceDisplayWaitVblank();
	UIMenu_SaveEEPDisplay_16((uint16_t *)PSP_DrawVideo + ui_offset, 512);
	PSP_Flip();
	PSP_ClearDraw();
	PokeMini_SaveFromCommandLines(0);

	while (emurunning && (UI_Status == UI_STATUS_MENU)) {
		// Slowdown to approx. 60fps
		sceDisplayWaitVblank();

		// Handle keys
		HandleKeys();

		// Process UI
		UIMenu_Process();

		// Screen rendering
		UIMenu_Display_16((uint16_t *)PSP_DrawVideo + ui_offset, 512);

		// Wait VSync & Render (72 Hz)
		PSP_Flip();
		PSP_ClearDraw();
	}

	// Flip and clear again
	PSP_Flip();
	PSP_ClearDraw();

	// Apply configs
	PokeMini_ApplyChanges();
	if (UI_Status == UI_STATUS_EXIT) emurunning = 0;
	else enablesound(CommandLine.sound);
}
示例#6
0
文件: particleed.cpp 项目: zcsk18/HGE
bool FrameFunc()
{
    float		px, py;
    float		dt=hge->Timer_GetDelta();

    // Update

    hge->Input_GetMousePos(&state.mx, &state.my);
    if(hge->Input_GetKeyState(HGEK_RBUTTON)) {
        psx=state.mx;
        psy=state.my;
    }
    else {
        psx=400;
        psy=300;
    }

    if(state.bIFace)
    {
        if(psx > 631) psx=631;
        if(psx < 168) psx=168;
    }

    state.ps->GetPosition(&px, &py);
    state.ps->MoveTo(px+(psx-px)*10*dt, py+(psy-py)*10*dt);
    state.ps->Update(dt);

    if(HandleKeys(hge->Input_GetKey())) return true;

    if(state.bIFace)
    {
        if(DoCommands(gui->Update(dt))) return true;
    }

    GetTextCtrl(CMD_NPARTICLES)->printf("%d", state.ps->GetParticlesAlive());
    GetTextCtrl(CMD_FPS)->printf("%d", hge->Timer_GetFPS());

    return false;
}
示例#7
0
// Main function
int main(int argc, char **argv)
{
	int battimeout = 0;
	char fpstxt[16];

	// Open debug files
	PokeDebugFOut = fopen("dbg_stdout.txt", "w");
	PokeDebugFErr = fopen("dbg_stderr.txt", "w");

	// Init video
	PokeDPrint(POKEMSG_OUT, "%s\n\n", AppName);
	PokeMini_InitDirs(argv[0], NULL);
	CommandLineInit();
	CommandLine.low_battery = 2;	// PSP can report battery status
	CommandLineConfFile("pokemini.cfg", "pokemini_psp.cfg", CustomConf);
	JoystickSetup("PSP", 0, 30000, PSP_KeysNames, 16, PSP_KeysMapping);

	// PSP Init and set screen
	PSP_Init();
	setup_screen();

	// Create emulator and load test roms
	PokeDPrint(POKEMSG_OUT, "Starting emulator...\n");
	PokeMini_Create(POKEMINI_GENSOUND | POKEMINI_AUTOBATT, 0);

	// Setup palette and LCD mode
	PokeMini_VideoPalette_Init(PokeMini_RGB16, 1);
	PokeMini_VideoPalette_Index(CommandLine.palette, CommandLine.custompal, CommandLine.lcdcontrast, CommandLine.lcdbright);
	PokeMini_ApplyChanges();

	// Load stuff
	PokeMini_UseDefaultCallbacks();
	if (!PokeMini_LoadFromCommandLines("Using FreeBIOS", "EEPROM data will be discarded!")) {
		UI_Status = UI_STATUS_MENU;
	}

	// Enable sound & init UI
	PokeDPrint(POKEMSG_OUT, "Running emulator...\n");
	UIMenu_Init();
	enablesound(CommandLine.sound);
	sceCtrlSetSamplingCycle(0);
	sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);

	// Emulator's loop
	u64 tickcurr;
	u64 fpsticknext,fpstickres = (u64)sceRtcGetTickResolution();
	u64 frmticknext, frmtickres = (u64)sceRtcGetTickResolution() / 36;
	sceRtcGetCurrentTick(&tickcurr);
	fpsticknext = tickcurr + fpstickres;
	frmticknext = tickcurr + frmtickres;
	int fps = 72, fpscnt = 0;
	strcpy(fpstxt, "");
	while (emurunning) {
		// Emulate 2 frames
		PokeMini_EmulateFrame();
		PokeMini_EmulateFrame();
		if (RequireSoundSync) {
			while (MinxAudio_SyncWithAudio()) sceKernelDelayThread(1000);
		} else {
			do {
				sceRtcGetCurrentTick(&tickcurr);
				sceKernelDelayThread(1000);
			} while (tickcurr < frmticknext);
			frmticknext = tickcurr + frmtickres;	// Aprox 36 times per sec
		}

		// Screen rendering
		PSP_ClearDraw();
		if (PokeMini_Rumbling) {
			PokeMini_VideoBlit((uint16_t *)PSP_DrawVideo + pm_offset + PokeMini_GenRumbleOffset(512), 512);
		} else {
			PokeMini_VideoBlit((uint16_t *)PSP_DrawVideo + pm_offset, 512);
		}
		LCDDirty = 0;

		// Display FPS counter
		if (clc_displayfps) {
			sceRtcGetCurrentTick(&tickcurr);
			if (tickcurr >= fpsticknext) {
				fpsticknext = tickcurr + fpstickres;
				fps = fpscnt;
				fpscnt = 0;
				sprintf(fpstxt, "%i FPS", fps);
			} else fpscnt++;
			UIDraw_String_16((uint16_t *)PSP_DrawVideo, 512, 4, 4, 10, fpstxt, UI_Font1_Pal16);
		}

		// Handle keys
		HandleKeys();

		// Menu
		if (UI_Status == UI_STATUS_MENU) menuloop();

		// Wait VSync & Render (72 Hz)
		PSP_Flip();

		// Check battery
		if (battimeout <= 0) {
			PokeMini_LowPower(scePowerIsLowBattery());
			battimeout = 600;
		} else battimeout--;
	}

	// Stop sound & free UI
	enablesound(0);
	UIMenu_Destroy();

	// Save Stuff
	PokeMini_SaveFromCommandLines(1);

	// Terminate...
	PokeDPrint(POKEMSG_OUT, "Shutdown emulator...\n");
	PokeMini_VideoPalette_Free();
	PokeMini_Destroy();

	// Close debug files
	fclose(PokeDebugFOut);
	fclose(PokeDebugFErr);

	// PSP Quit
	PSP_Quit();

	return 0;
}
void Process_PressKey()
{
	static int HeartBeatTick = 0;
	char Id;
	char Idx;
	unsigned short ValidConstKey = 0; 
	unsigned short Flag;
	// 一次
	for (Id = 0; Id < PLAYER_COUNT; Id++) {
		if (DownKey[Id] & KeyDownFlag) {
			HandleKeys(Id, DownKey[Id] & KeyDownFlag);
			DownKey[Id] = 0;
		}
	}
	
	// 心跳
	if (GetTick() > HeartBeatTick) {
		HeartBeatTick = GetTick() + 1000;
		ScoreFlag = ALLBITS;
	}
	
	// 常押
	for (Id = 0; Id < PLAYER_COUNT; Id++) {
		if (GetTick() > RecvTick[Id]) {
			RecvTick[Id] = 0;
			continue;
		}
			
		// 处理按键
		if (ConstDownKey[Id] & KeyPressFlag) {
			ValidConstKey = 0;
			Flag = ConstDownKey[Id] & KeyPressFlag;
			while (Flag) {
				Idx = bsr32(Flag);
				Flag &= ~(1<<Idx);
				if (GetTick() > KeyCount[Id][Idx]) {
					KeyCount[Id][Idx] = GetTick() + 100;
					ValidConstKey |= (1<<Idx);
				}
			}
			HandleKeys(Id, ValidConstKey);
		}
	}
	
	// 填充串口消息
	for (Id = 0; Id < COM_PLAYER_COUNT; Id++) {
		for (Idx = 0; Idx < sizeof(pMsgFlags)/sizeof(pMsgFlags[0]); Idx++) {
			if (ReturnWriteCount(Id) < 32) {
				break;
			}
			if (*pMsgFlags[Idx] & (1<<Id)) {
				*pMsgFlags[Idx] &= ~(1<<Id);
				CallBack_SendCom[Idx](Id);
			}
		}
	}
	// 填充USB消息
	for (Id = COM_PLAYER_COUNT; Id < PLAYER_COUNT; Id++) {
		if (!RecvTick[Id]) {
			continue;
		}
		for (Idx = 0; Idx < sizeof(usb_bits)/sizeof(*usb_bits); Idx++) {
			if (*pMsgFlags[Idx] & (1<<Id)) {
				*pMsgFlags[Idx] &= ~(1<<Id);
				SetUSBFlag(usb_bits[Idx], Id);
			}
		}
//		for (Idx = 0; Idx < sizeof(pMsgFlags)/sizeof(pMsgFlags[0]); Idx++) {
//			if (CallBack_SendUSB[Idx] && (*pMsgFlags[Idx] & (1<<Id))) {
//				*pMsgFlags[Idx] &= ~(1<<Id);
//				CallBack_SendUSB[Idx](Id);
//			}
//		}
	}
}
filter_result ClientAgentInputFilter::Filter(BMessage* msg, BHandler** target)
{
	filter_result result(B_DISPATCH_MESSAGE);
	switch (msg->what) {
	case B_MOUSE_MOVED:
		break;

	case B_COPY: {
		int32 start, finish;
		fWindow->fInput->TextView()->GetSelection(&start, &finish);
		if (start == finish) *target = fWindow->fText;
	} break;

	case B_SELECT_ALL: {
		if (fWindow->fInput->TextView()->TextLength() == 0) *target = fWindow->fText;
	} break;

	case B_KEY_DOWN: {
		result = HandleKeys(msg);
	} break;

	case B_MOUSE_UP: {
		if (fHandledDrop) {
			fHandledDrop = false;
			result = B_SKIP_MESSAGE;
		}
	} break;

	case B_MIME_TYPE: {
		if (msg->HasData("text/plain", B_MIME_TYPE)) {
			const char* buffer;
			ssize_t size;

			msg->FindData("text/plain", B_MIME_TYPE, 0, reinterpret_cast<const void**>(&buffer),
						  &size);

			// We copy it, because B_MIME_TYPE
			// might not be \0 terminated

			BString string;

			string.Append(buffer, size);
			HandleDrop(string.String());

			fHandledDrop = true;
			result = B_SKIP_MESSAGE;
		}
	} break;

	case B_SIMPLE_DATA: {
		if (msg->HasRef("refs")) {
			for (int32 i = 0; msg->HasRef("refs", i); ++i) {
				entry_ref ref;

				msg->FindRef("refs", &ref);

				char mime[B_MIME_TYPE_LENGTH];
				BFile file(&ref, B_READ_ONLY);
				BNodeInfo info(&file);
				off_t size;

				if (file.InitCheck() == B_NO_ERROR && file.GetSize(&size) == B_NO_ERROR &&
					info.InitCheck() == B_NO_ERROR && info.GetType(mime) == B_NO_ERROR &&
					strncasecmp(mime, "text/", 5) == 0) {
					char* buffer(new char[size + 1]);

					if (buffer) {
						// Oh baby!
						file.Read(buffer, size);
						buffer[size] = 0;

						HandleDrop(buffer);
						delete[] buffer;
						break;
					}
				}
			}

			// Give the fWindow a chance to handle non
			// text files.  If it's a message window, it'll
			// kick off a dcc send
			fWindow->DroppedFile(msg);
		}
	} break;

	case B_PASTE: {
		// we have our own pasting code so we can catch multiple lines
		BClipboard clipboard("system");
		const char* fText;
		ssize_t textLen;
		BMessage* clip((BMessage*)NULL);

		if (clipboard.Lock()) {
			if ((clip = clipboard.Data()))
				if (clip->FindData("text/plain", B_MIME_TYPE, (const void**)&fText, &textLen) !=
					B_OK) {
					clipboard.Unlock();
					break;
				}
		}

		clipboard.Unlock();
		BString data(fText, textLen);
		HandleDrop(data.String());
		result = B_SKIP_MESSAGE;
	} break;

	case B_MOUSE_WHEEL_CHANGED: {
		// pass this msg to IRCView
		fWindow->fText->MessageReceived(msg);
		result = B_SKIP_MESSAGE;
	} break;

	default: {
		// printf ("FILTER UNHANDLED: ");
		// msg->PrintToStream();
	}

	break;
	}

	return result;
}
示例#10
0
  //--------------------------------------------------------------------------------------
  // Update the view matrix based on user input & elapsed time
  //--------------------------------------------------------------------------------------
  void CFirstPersonCamera::FrameMove( double fElapsedTime )
  {
      if( IsKeyDown( mKeys[CAM_RESET] ) ) {
          Reset();
      }

      if (IsKeyDown(mKeys[CAM_ACCELERATE])) {
        if (mKeyboardMoveScaler < 10000.0) {
          mKeyboardMoveScaler *= 1.2;
        }

        if (mMouseMoveScaler < 10000.0) {
          mMouseMoveScaler *= 1.2;
        }
        //since accelerating shouldn't be done continously, force key up here
        HandleKeys(CAM_ACCELERATE, false);
      }
      if (IsKeyDown(mKeys[CAM_THROTTLE])) {
        if (mKeyboardMoveScaler > 0.1) {
          mKeyboardMoveScaler /= 1.2;
        }

        if (mMouseMoveScaler > 0.1) {
          mMouseMoveScaler /= 1.2;
        }

        HandleKeys(CAM_THROTTLE, false);
      }

      // Get keyboard/mouse/gamepad input
      GetInput( mEnablePositionMovement, ( mActiveButtonMask & mCurrentButtonMask ) || mRotateWithoutButtonDown,
                true, mResetCursorAfterMove );

      // Get amount of velocity based on the keyboard input and drag (if any)
      UpdateVelocity( fElapsedTime );

      // Simple euler method to calculate position delta
      dvec3 vPosDelta = mVelocity * fElapsedTime;

      // If rotating the camera 
      if (mMouseRotates) {
        if( ( mActiveButtonMask & mCurrentButtonMask ) || mRotateWithoutButtonDown) {

            // Update the pitch & yaw angle based on mouse movement
          double fYawDelta = mRotVelocity.x;
          double fPitchDelta = mRotVelocity.y;

            // Invert pitch if requested
            if( mInvertPitch )
                fPitchDelta = -fPitchDelta;

            mCameraPitchAngle -= fPitchDelta;
            mCameraYawAngle -= fYawDelta;

            // Limit pitch to straight up or straight down
            mCameraPitchAngle = std::max( -pi<double>() * 0.499, mCameraPitchAngle );
            mCameraPitchAngle = std::min( +pi<double>() * 0.499, mCameraPitchAngle );
        }
      }

      // Make a rotation matrix based on the camera's yaw & pitch
      dmat4 mCameraRot = yawPitchRoll(mCameraYawAngle, mCameraPitchAngle, 0.0);


      // Transform vectors based on camera's rotation matrix
      dvec3 vWorldUp, vWorldAhead;
      const dvec3 vLocalUp = dvec3( 0, 1, 0 );
      const dvec3 vLocalAhead = dvec3( 0, 0, -1 );

      vWorldUp = Vec3TransformCoord(vLocalUp, mCameraRot);
      vWorldAhead = Vec3TransformCoord(vLocalAhead, mCameraRot);

      // Transform the position delta by the camera's rotation 
      dvec3 vPosDeltaWorld;
      if( !mEnableYAxisMovement )
      {
          // If restricting Y movement, do not include pitch
          // when transforming position delta vector.
          mCameraRot = yawPitchRoll(mCameraYawAngle, 0.0, 0.0 );
      }

      vPosDeltaWorld = Vec3TransformCoord(vPosDelta, mCameraRot );

      // Move the eye position 
      mEye += vPosDeltaWorld;
      if( mClipToBoundary )
          ConstrainToBoundary( &mEye );

      // Update the lookAt position based on the eye position 
      mLookAt = mEye + vWorldAhead;

      // Update the view matrix
      mViewMatrix = lookAt(mEye, mLookAt, vWorldUp );

      mCameraWorld = inverse(mViewMatrix );
  }