Пример #1
0
/////////////////////////////
//	DeSerialize
//	 -Translate the data in the buffer into relevant data for this object
void Player::DeSerialize(char * _buffer)
{
	Transform * playerT = (Transform*)GetComponent(C_TRANSFORM);
	InputController * playerI = (InputController*)GetComponent(C_INPUT);

	// Read ID
	unsigned int id = 0;
	memcpy(&id, &_buffer[0], sizeof(id));
	m_uiID = id;

	// Read X
	int x = 0;
	memcpy(&x, &_buffer[4], sizeof(x));
	playerT->SetX(x);

	// Read Y
	int y = 0;
	memcpy(&y, &_buffer[8], sizeof(y));
	playerT->SetY(y);

	// Read input controller's ID
	unsigned int inputID = 0;// playerI->GetID();
	memcpy(&inputID, &_buffer[12], sizeof(inputID));
	playerI->SetID(inputID);

	m_pGame->SetRefresh(true);
}
Пример #2
0
/////////////////////////////
//	Initialize
//	 -Startup
void Player::Initialize()
{
	Transform * transform = new Transform;
	transform->SetX(0);
	transform->SetY(0);
	transform->SetOwner(this);
	AddComponent((Component*)transform);

	Sprite * sprite = new Sprite;
	sprite->SetVisible(true);
	sprite->SetCharacter('P');
	sprite->SetOwner(this);
	AddComponent((Component*)sprite);

	InputController * controller = new InputController;
	controller->SetOwner(this);
	AddComponent((Component*)controller);

	NetworkView * nwView = new NetworkView;
	nwView->SetOwner(this);
	nwView->RegisterForMessage(ID_NWV_UPDATE_POSITION);
	AddComponent((Component*)nwView);

	m_uiID = 0;

	InitializeComponents();

}
Пример #3
0
/////////////////////////////
//	Update
//	 -Main loop
void Player::Update()
{
	Transform * playerT = (Transform*)GetComponent(C_TRANSFORM);

	InputController * input = (InputController*)GetComponent(C_INPUT);
	bool changedInput = false;
	if (input->GetKeyDown('W'))
	{
		playerT->SetY(playerT->GetY() - 1);
		changedInput = true;
	}
	if (input->GetKeyDown('A'))
	{
		playerT->SetX(playerT->GetX() - 1);
		changedInput = true;
	}
	if (input->GetKeyDown('S'))
	{
		playerT->SetY(playerT->GetY() + 1);
		changedInput = true;
	}
	if (input->GetKeyDown('D'))
	{
		playerT->SetX(playerT->GetX() + 1);
		changedInput = true;
	}

	if (changedInput)
	{
		NetworkView * nwView = (NetworkView*)GetComponent(C_NETWORK);
		nwView->UpdatePositionMessage(playerT->GetX(), playerT->GetY());
	}

	UpdateComponents();
}
Пример #4
0
bool Button::ButtonClicked(InputController &ic, D3DGraphics &gfx )
{
	Vec2 mPos = ic.GetMousePos();
	bool clicked = false;
	c = gfx.FILLCOLOR_XRGB(255, 255, 255);
	if( (X < mPos.x && mPos.x < X2) && (Y < mPos.y && mPos.y < Y2 ))
	{
		c = gfx.FILLCOLOR_XRGB(255, 0, 255);
		clicked = ic.LeftButtonClicked();
	}
	return clicked;
}
Пример #5
0
void addWaypointInbetween()
{
	btAlignedObjectArray<Waypoint*>* wayList = entManager->getWaypointList();
	int prevIndex = getClosestWaypoint();
	if (prevIndex == -1)
		return;
	/*else if (prevIndex == wayList->size()-1)
	{
		createWaypoint();
		return;
	}*/
	Car* c = entManager->getCar(0);
	

	btTransform wayPointT1 = c->physicsObject->getWorldTransform();
	
	Waypoint* previousWay = wayList->at(prevIndex);		
	int nextIndex = previousWay->getWaypointList().at(0)->getIndex();
	previousWay->removeWaypointFromList(wayList->at(nextIndex)->getIndex());
	
	entManager->createWaypoint("model/waypoint.obj", wayPointT1);
	
	Waypoint* newWay = wayList->at(wayList->size()-1);
	if (wayList->size()>1)
	{
		previousWay->addNextWaypoint(newWay);
		newWay->addNextWaypoint(wayList->at(nextIndex));
	}
	newWay->setThrottle(controller1.getTriggers());
}
Пример #6
0
void PlayerState::step(float dt)
{
    GameState::step(dt);
    g_fpsCamera.update(dt);
    s_input.update(dt);

    float axis[2] = { 0, 0 };
    LocomotionInput input = { dt, 0, 0 };

    hkQsTransform t;
    t.setIdentity();

    hkVector4 dir;
    hkVector4 fwd;
    fwd.set(0, 0, 1, 0);
    hkVector4 up;
    up.set(0, 1, 0, 0);

    hkQuaternion rstOut;
    hkSimdFloat32 angle_out = 0;

    dir.setRotatedDir(t.m_rotation, fwd);

    hkVector4 cam_dir;
    const float *from = g_camera.m_eye;
    const float *to = g_camera.m_at;
    cam_dir.set(from[0] - to[0], 0, from[2] - to[2]);
    cam_dir.normalize3();

    Actor *a = g_actorWorld.get_actor(m_player);

    float camera_angle = hkMath::atan2(cam_dir.getSimdAt(0), cam_dir.getSimdAt(2)) - HK_REAL_PI;
    camera_angle = clamp_angle(camera_angle);

    float input_angle = s_input.m_leftAngle;
    float character_angle = get_up_axis_angle(a->m_transform.m_rotation);
    float angle_diff = input_angle + camera_angle - character_angle;
    angle_diff = clamp_angle(angle_diff);

    input.m_desireAngle = input_angle + camera_angle;
    input.m_dt = dt;
    input.m_moveVec = s_input.m_leftInput[2];

    s_locomotion.m_turnSpeed = 4.0f;
    update_locomotion(&s_locomotion, input, m_player);

    g_debugDrawMgr.add_text(RGBCOLOR(125,100,200),
        "input_angle=%f camera_angle=%f character_angle=%f angle_diff=%f",
        input_angle * HK_FLOAT_RAD_TO_DEG,
        camera_angle * HK_FLOAT_RAD_TO_DEG,
        character_angle * HK_FLOAT_RAD_TO_DEG,
        angle_diff * HK_FLOAT_RAD_TO_DEG);

    debug_draw_locomotion(&s_locomotion, m_player);
    step_debug_ctrl(dt);

    g_debugDrawMgr.add_grid(20, 5, RGBCOLOR(175,175,175), true);
    g_debugDrawMgr.add_axis(hkQsTransform::getIdentity(), 2);
}
Пример #7
0
/**
* Set an interaction mode for the surface.
* @param mode :: A new mode.
*/
void ProjectionSurface::setInteractionMode(int mode) {
  if (mode < 0 || mode >= m_inputControllers.size()) {
    throw std::logic_error("Invalid interaction mode requested.");
  }
  if (mode == m_interactionMode)
    return;
  InputController *controller = m_inputControllers[m_interactionMode];
  if (!controller)
    throw std::logic_error("Input controller doesn't exist.");
  controller->onDisabled();
  m_interactionMode = mode;
  controller = m_inputControllers[m_interactionMode];
  if (!controller)
    throw std::logic_error("Input controller doesn't exist.");
  controller->onEnabled();
  if (mode != DrawRegularMode && mode != DrawFreeMode) {
    m_maskShapes.deselectAll();
    foreach (PeakOverlay *po, m_peakShapes) { po->deselectAll(); }
  }
Пример #8
0
static void testInit() {
	InputRecorder inputRecorder, * inputRecorderPtr;
	InputController * inputController;
	const char * tempFilePath;
	int tempFD;
	
	inputController = InputController_create(NULL, NULL);
	
	memset(&inputRecorder, 0x00, sizeof(InputRecorder));
	InputRecorder_initWithMemwriteOutput(&inputRecorder, NULL, NULL, 0);
	verifyInit(&inputRecorder, NULL, NULL, __LINE__);
	inputRecorder.dispose(&inputRecorder);
	
	memset(&inputRecorder, 0xFF, sizeof(InputRecorder));
	InputRecorder_initWithMemwriteOutput(&inputRecorder, inputController, NULL, 0);
	verifyInit(&inputRecorder, inputController, NULL, __LINE__);
	inputRecorder.dispose(&inputRecorder);
	
	inputRecorderPtr = InputRecorder_createWithMemwriteOutput(NULL, NULL, 0);
	verifyInit(inputRecorderPtr, NULL, NULL, __LINE__);
	inputRecorderPtr->dispose(inputRecorderPtr);
	
	tempFilePath = temporaryFilePath("tmpXXXXXX", &tempFD);
	close(tempFD);
	
	memset(&inputRecorder, 0x00, sizeof(InputRecorder));
	InputRecorder_initWithFileOutput(&inputRecorder, NULL, NULL, 0, tempFilePath);
	verifyInit(&inputRecorder, NULL, tempFilePath, __LINE__);
	inputRecorder.dispose(&inputRecorder);
	
	memset(&inputRecorder, 0xFF, sizeof(InputRecorder));
	InputRecorder_initWithFileOutput(&inputRecorder, inputController, NULL, 0, tempFilePath);
	verifyInit(&inputRecorder, inputController, tempFilePath, __LINE__);
	inputRecorder.dispose(&inputRecorder);
	
	inputRecorderPtr = InputRecorder_createWithFileOutput(NULL, NULL, 0, tempFilePath);
	verifyInit(inputRecorderPtr, NULL, tempFilePath, __LINE__);
	inputRecorderPtr->dispose(inputRecorderPtr);
	
	inputController->dispose(inputController);
	unlink(tempFilePath);
}
Пример #9
0
static void testMemwriteRecording() {
	InputRecorder * inputRecorder;
	InputController * inputController;
	
	inputController = InputController_create(NULL, NULL);
	
	inputRecorder = InputRecorder_createWithMemwriteOutput(inputController, NULL, 0);
	TestCase_assert(inputRecorder->memwriteContext.length == 8, "Expected 8 but got " SIZE_T_FORMAT, inputRecorder->memwriteContext.length);
	TestCase_assert(!memcmp(inputRecorder->memwriteContext.data, "\x00\x00\x00\x00\x00\x00\x00\x00", 8), "Expected 0000 00000000 0000 but got %02X%02X %02X%02X%02X%02X %02X%02X", ((unsigned char *) inputRecorder->memwriteContext.data)[0], ((unsigned char *) inputRecorder->memwriteContext.data)[1], ((unsigned char *) inputRecorder->memwriteContext.data)[2], ((unsigned char *) inputRecorder->memwriteContext.data)[3], ((unsigned char *) inputRecorder->memwriteContext.data)[4], ((unsigned char *) inputRecorder->memwriteContext.data)[5], ((unsigned char *) inputRecorder->memwriteContext.data)[6], ((unsigned char *) inputRecorder->memwriteContext.data)[7]);
	InputRecorder_dispose(inputRecorder);
	
	inputRecorder = InputRecorder_createWithMemwriteOutput(inputController, "abcd", 4);
	TestCase_assert(inputRecorder->memwriteContext.length == 12, "Expected 12 but got " SIZE_T_FORMAT, inputRecorder->memwriteContext.length);
	TestCase_assert(!memcmp(inputRecorder->memwriteContext.data, "\x00\x00\x04\x00\x00\x00""abcd\x00\x00", 12), "Expected 0000 04000000 61626364 0000 but got %02X%02X %02X%02X%02X%02X %02X%02X%02X%02X %02X%02X", ((unsigned char *) inputRecorder->memwriteContext.data)[0], ((unsigned char *) inputRecorder->memwriteContext.data)[1], ((unsigned char *) inputRecorder->memwriteContext.data)[2], ((unsigned char *) inputRecorder->memwriteContext.data)[3], ((unsigned char *) inputRecorder->memwriteContext.data)[4], ((unsigned char *) inputRecorder->memwriteContext.data)[5], ((unsigned char *) inputRecorder->memwriteContext.data)[6], ((unsigned char *) inputRecorder->memwriteContext.data)[7], ((unsigned char *) inputRecorder->memwriteContext.data)[8], ((unsigned char *) inputRecorder->memwriteContext.data)[9], ((unsigned char *) inputRecorder->memwriteContext.data)[10], ((unsigned char *) inputRecorder->memwriteContext.data)[11]);
	InputRecorder_dispose(inputRecorder);
	
	InputController_dispose(inputController);
	inputController = InputController_create(NULL, "a", "bc", NULL);
	
	inputRecorder = InputRecorder_createWithMemwriteOutput(inputController, NULL, 0);
	TestCase_assert(inputRecorder->memwriteContext.length == 13, "Expected 13 but got " SIZE_T_FORMAT, inputRecorder->memwriteContext.length);
	TestCase_assert(!memcmp(inputRecorder->memwriteContext.data, "\x00\x00\x00\x00\x00\x00\x02\x00""a\x00""bc\x00", 13), "Expected 0000 00000000 0200 6100 626300 but got %02X%02X %02X%02X%02X%02X %02X%02X %02X%02X %02X%02X%02X", ((unsigned char *) inputRecorder->memwriteContext.data)[0], ((unsigned char *) inputRecorder->memwriteContext.data)[1], ((unsigned char *) inputRecorder->memwriteContext.data)[2], ((unsigned char *) inputRecorder->memwriteContext.data)[3], ((unsigned char *) inputRecorder->memwriteContext.data)[4], ((unsigned char *) inputRecorder->memwriteContext.data)[5], ((unsigned char *) inputRecorder->memwriteContext.data)[6], ((unsigned char *) inputRecorder->memwriteContext.data)[7], ((unsigned char *) inputRecorder->memwriteContext.data)[8], ((unsigned char *) inputRecorder->memwriteContext.data)[9], ((unsigned char *) inputRecorder->memwriteContext.data)[10], ((unsigned char *) inputRecorder->memwriteContext.data)[11], ((unsigned char *) inputRecorder->memwriteContext.data)[12]);
	
	inputController->triggerAction(inputController, ATOM("a"));
	TestCase_assert(inputRecorder->memwriteContext.length == 19, "Expected 19 but got " SIZE_T_FORMAT, inputRecorder->memwriteContext.length);
	TestCase_assert(!memcmp(inputRecorder->memwriteContext.data + 13, "\x00\x00\x00\x00\x00\x00", 6), "Expected 00000000 0000 but got %02X%02X%02X%02X %02X%02X", ((unsigned char *) inputRecorder->memwriteContext.data)[13], ((unsigned char *) inputRecorder->memwriteContext.data)[14], ((unsigned char *) inputRecorder->memwriteContext.data)[15], ((unsigned char *) inputRecorder->memwriteContext.data)[16], ((unsigned char *) inputRecorder->memwriteContext.data)[17], ((unsigned char *) inputRecorder->memwriteContext.data)[18]);
	
	InputRecorder_nextFrame(inputRecorder);
	inputController->triggerAction(inputController, ATOM("bc"));
	TestCase_assert(inputRecorder->memwriteContext.length == 25, "Expected 25 but got " SIZE_T_FORMAT, inputRecorder->memwriteContext.length);
	TestCase_assert(!memcmp(inputRecorder->memwriteContext.data + 19, "\x01\x00\x00\x00\x01\x00", 6), "Expected 01000000 0100 but got %02X%02X%02X%02X %02X%02X", ((unsigned char *) inputRecorder->memwriteContext.data)[19], ((unsigned char *) inputRecorder->memwriteContext.data)[20], ((unsigned char *) inputRecorder->memwriteContext.data)[21], ((unsigned char *) inputRecorder->memwriteContext.data)[22], ((unsigned char *) inputRecorder->memwriteContext.data)[23], ((unsigned char *) inputRecorder->memwriteContext.data)[24]);
	
	InputRecorder_nextFrame(inputRecorder);
	InputRecorder_nextFrame(inputRecorder);
	InputRecorder_nextFrame(inputRecorder);
	inputController->releaseAction(inputController, ATOM("bc"));
	TestCase_assert(inputRecorder->memwriteContext.length == 31, "Expected 31 but got " SIZE_T_FORMAT, inputRecorder->memwriteContext.length);
	TestCase_assert(!memcmp(inputRecorder->memwriteContext.data + 25, "\x03\x00\x00\x00\x01\x00", 6), "Expected 03000000 0100 but got %02X%02X%02X%02X %02X%02X", ((unsigned char *) inputRecorder->memwriteContext.data)[25], ((unsigned char *) inputRecorder->memwriteContext.data)[26], ((unsigned char *) inputRecorder->memwriteContext.data)[27], ((unsigned char *) inputRecorder->memwriteContext.data)[28], ((unsigned char *) inputRecorder->memwriteContext.data)[29], ((unsigned char *) inputRecorder->memwriteContext.data)[30]);
	
	InputRecorder_dispose(inputRecorder);
	InputController_dispose(inputController);
}
Пример #10
0
void floatingWaypoint(){
	btAlignedObjectArray<Waypoint*>* wayList = entManager->getWaypointList();
	Car* c = entManager->getCar(0);
	btTransform wayPointT1 = c->physicsObject->getWorldTransform();	
	entManager->createWaypoint("model/waypoint.obj", wayPointT1);	
	Waypoint* newWay = wayList->at(wayList->size()-1);
	newWay->setThrottle(controller1.getTriggers());
	Waypoint* prevWay = wayList->at(waypointIndex1);
	prevWay->addNextWaypoint(newWay);
	waypointIndex1 = newWay->getIndex();
}
Пример #11
0
// JS 24 Apr 12
int HeadsUp::update()
{
   // Point to the input controller
   InputController *inpCtrl = Game.inpCtrl;

   // Check for enter press only if not in play
   if(!Game.inPlay)
   {
      // Valid pointer to input controller checking for enter press
      if(inpCtrl && inpCtrl->pressedEnter())
      {
         // Change the state of the game to be in play.
         Game.inPlay = true;
         // Play game start sound
         Game.sndId = qeSndPlay(snd[SDR_INDX_STR_END_GAME].name);
      } // if
   } // if

   return 0;
} // HeadsUp::update()
Пример #12
0
/////////////////////////////
//	Serialize
//	 -Turn all relevant data about this object into a char buffer
void Player::Serialize(char * _buffer)
{
	Transform * playerT = (Transform*)GetComponent(C_TRANSFORM);
	InputController * playerI = (InputController*)GetComponent(C_INPUT);

	// Write ID
	unsigned int id = m_uiID;
	memcpy(&_buffer[0], &id, sizeof(id));

	// Write X
	int x = playerT->GetX();
	memcpy(&_buffer[4], &x, sizeof(x));

	// Write Y
	int y = playerT->GetY();
	memcpy(&_buffer[8], &y, sizeof(y));

	// Write input controller's ID
	unsigned int inputID = playerI->GetID();
	memcpy(&_buffer[12], &inputID, sizeof(inputID));
}
Пример #13
0
//Dynamic creation of waypoints
void createWaypoint(){
	btAlignedObjectArray<Waypoint*>* wayList = entManager->getWaypointList();
	Car* c = entManager->getCar(0);
	//btScalar a = c->getTangent().angle(btVector3(1,0,0));
//	btTransform wayPointT1 = btTransform(btQuaternion(btVector3(0,1,0),a),entManager->getCar(0)->getPosition() + btVector3(0,3,0));
	btTransform wayPointT1 = c->physicsObject->getWorldTransform();
	//btTransform wayPointT1 = btTransform(btQuaternion(0, 0, 0, 1),entManager->getCar(0)->getPosition() + btVector3(0,3,0));
	Waypoint* previousWay;
	if (wayList->size()>0)
	{
		previousWay = wayList->at(wayList->size()-1);
		previousWay->removeWaypointFromList(wayList->at(0)->getIndex());
	}
	entManager->createWaypoint("model/waypoint.obj", wayPointT1);
	
	Waypoint* newWay = wayList->at(wayList->size()-1);
	if (wayList->size()>1)
	{
		previousWay->addNextWaypoint(newWay);
		newWay->addNextWaypoint(wayList->at(0));
	}
	newWay->setThrottle(controller1.getTriggers());
}
Пример #14
0
static void testActionTriggers() {
    InputController * inputController;

    actionDownCallCount = actionUpCallCount = 0;
    inputController = InputController_create(NULL, "a", "b", NULL);
    EventDispatcher_registerForEvent(inputController->eventDispatcher, ATOM(INPUT_CONTROLLER_EVENT_ACTION_DOWN), actionDown, NULL);
    EventDispatcher_registerForEvent(inputController->eventDispatcher, ATOM(INPUT_CONTROLLER_EVENT_ACTION_UP), actionUp, NULL);

    lastActionID = NULL;
    TestCase_assert(!InputController_isActionTriggered(inputController, ATOM("a")), "Expected false but got true");
    inputController->triggerAction(inputController, ATOM("a"));
    TestCase_assert(actionDownCallCount == 1, "Expected 1 but got %u", actionDownCallCount);
    TestCase_assert(lastActionID == ATOM("a"), "Expected \"a\" (%p) but got \"%s\" (%p)", ATOM("a"), lastActionID, lastActionID);
    TestCase_assert(InputController_isActionTriggered(inputController, ATOM("a")), "Expected true but got false");

    inputController->triggerAction(inputController, ATOM("a"));
    TestCase_assert(actionDownCallCount == 1, "Expected 1 but got %u", actionDownCallCount);
    TestCase_assert(InputController_isActionTriggered(inputController, ATOM("a")), "Expected true but got false");

    lastActionID = NULL;
    inputController->releaseAction(inputController, ATOM("a"));
    TestCase_assert(actionUpCallCount == 1, "Expected 1 but got %u", actionUpCallCount);
    TestCase_assert(lastActionID == ATOM("a"), "Expected \"a\" (%p) but got \"%s\" (%p)", ATOM("a"), lastActionID, lastActionID);
    TestCase_assert(!InputController_isActionTriggered(inputController, ATOM("a")), "Expected false but got true");

    lastActionID = NULL;
    inputController->triggerAction(inputController, ATOM("a"));
    TestCase_assert(actionDownCallCount == 2, "Expected 2 but got %u", actionDownCallCount);
    TestCase_assert(lastActionID == ATOM("a"), "Expected \"a\" (%p) but got \"%s\" (%p)", ATOM("a"), lastActionID, lastActionID);
    TestCase_assert(InputController_isActionTriggered(inputController, ATOM("a")), "Expected true but got false");

    lastActionID = NULL;
    TestCase_assert(!InputController_isActionTriggered(inputController, ATOM("b")), "Expected false but got true");
    inputController->triggerAction(inputController, ATOM("b"));
    TestCase_assert(actionDownCallCount == 3, "Expected 3 but got %u", actionDownCallCount);
    TestCase_assert(lastActionID == ATOM("b"), "Expected \"b\" (%p) but got \"%s\" (%p)", ATOM("b"), lastActionID, lastActionID);
    TestCase_assert(InputController_isActionTriggered(inputController, ATOM("b")), "Expected true but got false");

    InputController_dispose(inputController);
}
Пример #15
0
static void testFileRecording() {
	InputRecorder * inputRecorder;
	InputController * inputController;
	const char * tempFilePath;
	int tempFD;
	unsigned char * fileContents;
	size_t fileLength;
	
	inputController = InputController_create(NULL, NULL);
	tempFilePath = temporaryFilePath("tmpXXXXXX", &tempFD);
	close(tempFD);
	
	inputRecorder = InputRecorder_createWithFileOutput(inputController, NULL, 0, tempFilePath);
	fileContents = readFileSimple(tempFilePath, &fileLength);
	TestCase_assert(fileContents != NULL, "Expected non-NULL but got NULL");
	TestCase_assert(fileLength == 8, "Expected 8 but got " SIZE_T_FORMAT, fileLength);
	TestCase_assert(!memcmp(fileContents, "\x00\x00\x00\x00\x00\x00\x00\x00", 8), "Expected 0000 00000000 0000 but got %02X%02X %02X%02X%02X%02X %02X%02X", fileContents[0], fileContents[1], fileContents[2], fileContents[3], fileContents[4], fileContents[5], fileContents[6], fileContents[7]);
	free(fileContents);
	inputRecorder->dispose(inputRecorder);
	
	inputRecorder = InputRecorder_createWithFileOutput(inputController, "abcd", 4, tempFilePath);
	fileContents = readFileSimple(tempFilePath, &fileLength);
	TestCase_assert(fileContents != NULL, "Expected non-NULL but got NULL");
	TestCase_assert(fileLength == 12, "Expected 12 but got " SIZE_T_FORMAT, fileLength);
	TestCase_assert(!memcmp(fileContents, "\x00\x00\x04\x00\x00\x00""abcd\x00\x00", 12), "Expected 0000 04000000 61626364 0000 but got %02X%02X %02X%02X%02X%02X %02X%02X%02X%02X %02X%02X", fileContents[0], fileContents[1], fileContents[2], fileContents[3], fileContents[4], fileContents[5], fileContents[6], fileContents[7], fileContents[8], fileContents[9], fileContents[10], fileContents[11]);
	free(fileContents);
	inputRecorder->dispose(inputRecorder);
	
	inputController->dispose(inputController);
	inputController = InputController_create(NULL, "a", "bc", NULL);
	
	inputRecorder = InputRecorder_createWithFileOutput(inputController, NULL, 0, tempFilePath);
	fileContents = readFileSimple(tempFilePath, &fileLength);
	TestCase_assert(fileContents != NULL, "Expected non-NULL but got NULL");
	TestCase_assert(fileLength == 13, "Expected 13 but got " SIZE_T_FORMAT, fileLength);
	TestCase_assert(!memcmp(fileContents, "\x00\x00\x00\x00\x00\x00\x02\x00""a\x00""bc\x00", 13), "Expected 0000 00000000 0200 6100 626300 but got %02X%02X %02X%02X%02X%02X %02X%02X %02X%02X %02X%02X%02X", fileContents[0], fileContents[1], fileContents[2], fileContents[3], fileContents[4], fileContents[5], fileContents[6], fileContents[7], fileContents[8], fileContents[9], fileContents[10], fileContents[11], fileContents[12]);
	free(fileContents);
	
	inputController->triggerAction(inputController, ATOM("a"));
	fileContents = readFileSimple(tempFilePath, &fileLength);
	TestCase_assert(fileContents != NULL, "Expected non-NULL but got NULL");
	TestCase_assert(fileLength == 19, "Expected 19 but got " SIZE_T_FORMAT, fileLength);
	TestCase_assert(!memcmp(fileContents + 13, "\x00\x00\x00\x00\x00\x00", 6), "Expected 00000000 0000 but got %02X%02X%02X%02X %02X%02X", fileContents[13], fileContents[14], fileContents[15], fileContents[16], fileContents[17], fileContents[18]);
	free(fileContents);
	
	inputRecorder->nextFrame(inputRecorder);
	inputController->triggerAction(inputController, ATOM("bc"));
	fileContents = readFileSimple(tempFilePath, &fileLength);
	TestCase_assert(fileContents != NULL, "Expected non-NULL but got NULL");
	TestCase_assert(fileLength == 25, "Expected 25 but got " SIZE_T_FORMAT, fileLength);
	TestCase_assert(!memcmp(fileContents + 19, "\x01\x00\x00\x00\x01\x00", 6), "Expected 01000000 0100 but got %02X%02X%02X%02X %02X%02X", fileContents[19], fileContents[20], fileContents[21], fileContents[22], fileContents[23], fileContents[24]);
	free(fileContents);
	
	inputRecorder->nextFrame(inputRecorder);
	inputRecorder->nextFrame(inputRecorder);
	inputRecorder->nextFrame(inputRecorder);
	inputController->releaseAction(inputController, ATOM("bc"));
	fileContents = readFileSimple(tempFilePath, &fileLength);
	TestCase_assert(fileContents != NULL, "Expected non-NULL but got NULL");
	TestCase_assert(fileLength == 31, "Expected 31 but got " SIZE_T_FORMAT, fileLength);
	TestCase_assert(!memcmp(fileContents + 25, "\x03\x00\x00\x00\x01\x00", 6), "Expected 03000000 0100 but got %02X%02X%02X%02X %02X%02X", fileContents[25], fileContents[26], fileContents[27], fileContents[28], fileContents[29], fileContents[30]);
	free(fileContents);
	
	inputRecorder->dispose(inputRecorder);
	inputController->dispose(inputController);
	unlink(tempFilePath);
}
Пример #16
0
LRESULT CALLBACK LVEditWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch (uMsg)
	{
	case WM_KEYDOWN:
	{
		switch (wParam)
		{
		//focus가 edit일 때 스크롤
		case VK_PRIOR:
			scroll += 50;
			InvalidateRect(hwndMain, &rt, TRUE);
			break;
		case VK_NEXT:
			scroll -= 50;
			InvalidateRect(hwndMain, &rt, TRUE);
			break;

		case VK_RETURN:
		{
			scroll = 0;
			ret.clear();
			//ret.shrink_to_fit();
			images.clear();
			imageSize.clear();
			threads.clear();
			// get current text
			int textLength = (int)SendMessage(hWnd, WM_GETTEXTLENGTH, 0, 0) + 1;
			SendMessage(hWnd, WM_GETTEXT, (WPARAM)textLength, (LPARAM)str);
			printf("enter!\n");
			
			// Input Control
			string usrInput(str);
			curState = userInterface.getState(usrInput);
			if (curState == HELPSTATE)
			{
				ret.push_back(userInterface.getHelpText());
			}
			else if (curState == GOSTATE || curState == BACKSTATE || curState == FORWARDSTATE || curState == HOMESTATE)
			{
				hyperLinkMap.clear();
				string uri = userInterface.getURI();
				getDataFromServer(uri);
			}
			else if (curState == REFRESHSTATE)
			{
				string uri = userInterface.getURI();
				getDataFromServer(uri);
			}
			else if (curState == LSSTATE)
			{
				vector<string> urilist = userInterface.getURIList();				
				for (unsigned int p = 0; p < urilist.size(); p++)
				{
					ret.push_back(urilist[p]);
				}
			}
			else if (curState == HGOSTATE)
			{
				string getKey = userInterface.getUserHyperLinkText();
				string hyperURI = "";
				hyperURI = hyperLinkMap.find(getKey)->second;
				if (hyperURI != "")
				{
					userInterface.pushHyperLinkURI(hyperURI);
				}
				getDataFromServer(hyperURI);
			}
			else if (curState == NOTVALIDSTATE)
			{
				ret.push_back("명령어를 잘못 입력하셨습니다\n");
			}
			else if (curState == FILESTATE)
			{
				string filename = userInterface.getFileName();
				int threadNum = userInterface.getthreadNum();
				// DLL 실행
				cout << "dll " << endl;
				auto_ptr<FileSearch> searcher(new FileSearch(hwndMain, rt));
				searcher->search(filename, threadNum);
				//ret.push_back("명령어를 잘못 입력하셨습니다\n");
			}
			if(curState != FILESTATE)
				InvalidateRect(hwndMain, &rt, TRUE);
			break;
		}
		case VK_BACK:
		{
			break;
		}
		}
		break;
	}
	}
	return CallWindowProc(origLVEditWndProc, hWnd, uMsg, wParam, lParam);
}
Пример #17
0
// JFL 22 Jul 09
// JS 21 Apr 12; Added court, paddles, and ball objects
// JS 22 Apr 12; Added many object and collision resolution
// JS 24 Apr 12; Implemented winning condition
int gameMainLoop()
{
   int errorCode = 0; // in case functions return errors

   // Game object pointers
   Camera *cam;
   HeadsUp *hud;
   InputController *inpCtrl;
   Court *court;
   Paddle *paddles[NUM_PLYRS];
   Ball *ball;
   CollisionController *collCtrl;

   //
   // UPDATE
   //

   // Get input from Keyboard and QE
   if(inpCtrl = Game.inpCtrl)
   {
      inpCtrl->update();
   } // if

   // Update state of the HUD
   if(hud = Game.hud)
   {
      hud->update();
   } // if

   // Only update game-playing state if currently in play
   if(Game.inPlay)
   {      
      // Check collisions
      if(collCtrl = Game.collCtrl)
      {
         collCtrl->update();
      } // if
      
      // Update and resolve paddles
      for(int i=0; i<NUM_PLYRS; i++)
      {
         if(paddles[i] = Game.paddles[i])
         {
            errorCode = paddles[i]->update();
            // Print error if any
            if (errorCode != 0)
            {
               qePrintf("**Error: Paddle%d's *inpCtrl invalid!", i);
            } // if
            // Resolve collision of the paddles
            if(collCtrl && errorCode == 0)
            {
               if(collCtrl->phw[i])
               {
                  errorCode = collCtrl->resolvePaddle(i);
                  // Print error if any
                  if (errorCode != 0)
                  {
                     qePrintf("**CollCtrl's *xyzPad%d invalid!", i);
                  } // if
               } // if
            } // if
         } // if
      } // for

      // Update and resolve ball
      if(ball = Game.ball)
      {
         ball->update();
         // Resolve collision of ball
         if(collCtrl)
         {
            if(collCtrl->bhp[IDNX_PLY_1] ||  // After hitting Player1
               collCtrl->bhp[IDNX_PLY_2] ||  // After hitting Player2
               collCtrl->bhhw ||             // After hitting horizontal walls
               collCtrl->bhbw)               // After hitting side walls
            {
               errorCode = collCtrl->resolveBall();
               // Print error if any
               if (errorCode != 0)
               {
                  qePrintf("**CollCtrl's *xyzBal invalid!");
               } // if
            } // if
         } // if
      } // if ball
   } // if inPlay

   //
   // WIN CONDITION CHECK
   //

   // Check to see if the game is over (If someone gets 3 points)
   if(Game.scores[IDNX_PLY_1] == 3 || Game.scores[IDNX_PLY_2] == 3)
   {
      // Not the first game anymore, regardless
      Game.firstGame = false;
      // Game is not in play anymore (until game is restarted)
      Game.inPlay = false;
      // Play game end sound
      Game.sndId = qeSndPlay(snd[SDR_INDX_STR_END_GAME].name);
      
      // Manage scores of each paddle
      for(int i=0; i<NUM_PLYRS; i++)
      {
         // Record last scores
         Game.lastScores[i] = Game.scores[i];

         // Clear scores, to prevent this routine from running concurrently
         Game.scores[i] = 0;
      } // for 
   } // if

   //
   // RESET CONDITONS
   //

   // Implement soft reset (spacebar)
   if(inpCtrl && inpCtrl->pressedSpace())
   {
      // Play game end sound
      Game.sndId = qeSndPlay(snd[SDR_INDX_STR_END_GAME].name);

      // Reposition ball's position
      if(ball = Game.ball)
      {
         ball->xyz.x = 0;
         ball->xyz.z = 0;
      } // if
      
      // Pause game very briefly
      qeSleep(0.5);

      // Manage scores of each paddle
      for(int i=0; i<NUM_PLYRS; i++)
      {
         // Record last scores
         Game.lastScores[i] = Game.scores[i];

         // Clear scores, to prevent this routine from running concurrently
         Game.scores[i] = 0;

         // Reset the z-position of each paddle
         if(paddles[i] = Game.paddles[i])
         {
            paddles[i]->xyz.z = PADDLE_INIT_Z;
         } // if
      } // for 

      // Skip rest of game loop
      goto END_RESET;

   } // if

   // Implement hard reset (pressing "1")
   if(inpCtrl && inpCtrl->pressedOne())
   {
      // Play game end sound
      Game.sndId = qeSndPlay(snd[SDR_INDX_STR_END_GAME].name);

      // Pause game
      qeSleep(1.5);

      // Reinitialize game
      gameFinal();
      gameInit();
      gameSetup();

      // Skip rest of game loop
      goto END_RESET;
   } // if

   //
   // DRAW
   //

   // DRAW 3D

   // set 3D camera
   if((cam=Game.cam) && !(qeInpButton(QEINPBUTTON_ZERO)&2))
   {
      cam->apply(); // set the camera
   } // if

   // DRAW COURT, PADDLES, BALL

   // Draw court
   if(court=Game.court)
   {
      court->draw();
   } // if

   // Draw paddles
   for(int i=0; i<NUM_PLYRS; i++)
   {
      if(paddles[i] = Game.paddles[i])
      {
         paddles[i]->draw();
      } // if
   } // for

   // Draw ball
   if(ball=Game.ball)
   {
      ball->draw();
   } // if

   // DRAW HUD

   qefnSysCamBitmap(); // set camera (also turns off depth testing)

   if((hud=Game.hud))
   {
      hud->draw();
   } // if

END_RESET:

    return 0;
} // gameMainLoop()