static OutputToInputMap createDimensionMap(const Dimension& outputSize,
    const Dimension& inputSize, const Dimension& inputStride)
{
    size_t inputIndex = 0;
    size_t inputRemainder = inputSize.front();

    OutputToInputMap map;

    for(size_t outputIndex = 0; outputIndex < outputSize.size(); ++outputIndex)
    {
        InputMap localMap;

        size_t outputDimSize = outputSize[outputIndex];

        while(outputDimSize > inputRemainder)
        {
            if(inputRemainder > 1)
            {
                localMap.push_back(inputIndex);
            }

            ++inputIndex;
            inputRemainder *= inputSize[inputIndex];
        }

        localMap.push_back(inputIndex);
        inputRemainder /= outputDimSize;

        map.push_back(localMap);
    }

    return map;
}
Exemplo n.º 2
0
void InputManager::waitForKeys(int key, const InputSource & source){
    InputMap<int> wait;
    wait.set(key, 0, false, 1);
    InputManager::waitForRelease(wait, source, 1);
    InputManager::waitForPress(wait, source, 1);
    InputManager::waitForRelease(wait, source, 1);
}
Exemplo n.º 3
0
void Demo::processInput()
{
	InputMap *input = InputMap::getInstance();

	if(input->verifyIfWasPressed(InputMap::KT_ESC))
	{
		quitApp();
	}
}
Exemplo n.º 4
0
static void checkFullscreen(){
    InputMap<int> input;
    input.set(Keyboard::Key_F11, 0, true, 5);
    std::vector<InputMap<int>::InputEvent> events = InputManager::getEvents(input, InputSource(true));

    for (std::vector<InputMap<int>::InputEvent>::iterator it = events.begin(); it != events.end(); it++){
        InputMap<int>::InputEvent event = *it;

        if (!event.enabled){
            continue;
        }

        if (event.out == 5){
            changeScreenMode();
        }
    }
}
Exemplo n.º 5
0
static void testAxisBindings() {
	InputMap * inputMap;
	
	inputMap = InputMap_create();
	verifyAxisNotBound(inputMap, ATOM("a"), 0, 0, 0, 1.0f, 0.0f, __LINE__);
	verifyAxisNotBound(inputMap, ATOM("a"), 0, 0, 1, 1.0f, 0.0f, __LINE__);
	verifyAxisNotBound(inputMap, ATOM("a"), 1, 1, 1, 1.0f, 0.0f, __LINE__);
	verifyAxisNotBound(inputMap, ATOM("b"), 0, 0, 0, 1.0f, 0.0f, __LINE__);
	
	inputMap->bindAxis(inputMap, ATOM("a"), 0, 0, 0, 1.0f, 0.0f);
	verifyAxisBound(inputMap, ATOM("a"), 0, 0, 0, 1.0f, 0.0f, __LINE__);
	
	inputMap->bindAxis(inputMap, ATOM("a"), 0, 0, 1, 1.0f, 0.0f);
	verifyAxisBound(inputMap, ATOM("a"), 0, 0, 0, 1.0f, 0.0f, __LINE__);
	verifyAxisBound(inputMap, ATOM("a"), 0, 0, 1, 1.0f, 0.0f, __LINE__);
	
	inputMap->bindAxis(inputMap, ATOM("a"), 0, 0, 1, 0.5f, 0.0f);
	verifyAxisBound(inputMap, ATOM("a"), 0, 0, 0, 1.0f, 0.0f, __LINE__);
	verifyAxisBound(inputMap, ATOM("a"), 0, 0, 1, 0.5f, 0.0f, __LINE__);
	TestCase_assert(!isAxisBound(inputMap, ATOM("a"), 0, 0, 1, 1.0f, 0.0f), "Expected false but got true");
	
	inputMap->bindAxis(inputMap, ATOM("a"), 0, 0, 1, 0.5f, 0.5f);
	verifyAxisBound(inputMap, ATOM("a"), 0, 0, 0, 1.0f, 0.0f, __LINE__);
	verifyAxisBound(inputMap, ATOM("a"), 0, 0, 1, 0.5f, 0.5f, __LINE__);
	TestCase_assert(!isAxisBound(inputMap, ATOM("a"), 0, 0, 1, 0.5f, 0.0f), "Expected false but got true");
	
	inputMap->bindAxis(inputMap, ATOM("a"), 0, 0, 1, 0.5f, 0.5f);
	verifyAxisBound(inputMap, ATOM("a"), 0, 0, 0, 1.0f, 0.0f, __LINE__);
	verifyAxisBound(inputMap, ATOM("a"), 0, 0, 1, 0.5f, 0.5f, __LINE__);
	verifyAxisBound(inputMap, ATOM("a"), 0, 0, 1, 0.5f, 0.5f, __LINE__);
	
	inputMap->bindAxis(inputMap, ATOM("a"), 1, 1, 1, 1.0f, 0.0f);
	verifyAxisBound(inputMap, ATOM("a"), 0, 0, 0, 1.0f, 0.0f, __LINE__);
	verifyAxisBound(inputMap, ATOM("a"), 0, 0, 1, 0.5f, 0.5f, __LINE__);
	verifyAxisBound(inputMap, ATOM("a"), 0, 0, 1, 0.5f, 0.5f, __LINE__);
	verifyAxisBound(inputMap, ATOM("a"), 1, 1, 1, 1.0f, 0.0f, __LINE__);
	
	inputMap->bindAxis(inputMap, ATOM("b"), 0, 0, 0, 1.0f, 0.0f);
	verifyAxisBound(inputMap, ATOM("a"), 0, 0, 0, 1.0f, 0.0f, __LINE__);
	verifyAxisBound(inputMap, ATOM("a"), 0, 0, 1, 0.5f, 0.5f, __LINE__);
	verifyAxisBound(inputMap, ATOM("a"), 0, 0, 1, 0.5f, 0.5f, __LINE__);
	verifyAxisBound(inputMap, ATOM("a"), 1, 1, 1, 1.0f, 0.0f, __LINE__);
	verifyAxisBound(inputMap, ATOM("b"), 0, 0, 0, 1.0f, 0.0f, __LINE__);
	
	inputMap->unbindAxis(inputMap, ATOM("a"), 0, 0, 0);
	verifyAxisNotBound(inputMap, ATOM("a"), 0, 0, 0, 1.0f, 0.0f, __LINE__);
	verifyAxisBound(inputMap, ATOM("a"), 0, 0, 1, 0.5f, 0.5f, __LINE__);
	verifyAxisBound(inputMap, ATOM("a"), 0, 0, 1, 0.5f, 0.5f, __LINE__);
	verifyAxisBound(inputMap, ATOM("a"), 1, 1, 1, 1.0f, 0.0f, __LINE__);
	verifyAxisBound(inputMap, ATOM("b"), 0, 0, 0, 1.0f, 0.0f, __LINE__);
}
Exemplo n.º 6
0
/** \fn ChannelBase::StoreInputChannels(const InputMap&)
 *  \brief Sets starting channel for the each input in the input map.
 *  \param input Map from cardinputid to input params.
 */
void ChannelBase::StoreInputChannels(const InputMap &inputs)
{
    MSqlQuery query(MSqlQuery::InitCon());
    InputMap::const_iterator it = inputs.begin();
    for (; it != inputs.end(); ++it)
    {
        if ((*it)->name.isEmpty() || (*it)->startChanNum.isEmpty())
            continue;

        query.prepare(
            "UPDATE cardinput "
            "SET startchan = :STARTCHAN "
            "WHERE cardinputid = :CARDINPUTID");
        query.bindValue(":STARTCHAN",   (*it)->startChanNum);
        query.bindValue(":CARDINPUTID", it.key());

        if (!query.exec() || !query.isActive())
            MythDB::DBError("StoreInputChannels", query);
    }
}
Exemplo n.º 7
0
static void testButtonBindings() {
	InputMap * inputMap;
	
	inputMap = InputMap_create();
	verifyButtonNotBound(inputMap, ATOM("a"), 0, 0, 0, __LINE__);
	verifyButtonNotBound(inputMap, ATOM("a"), 0, 0, 1, __LINE__);
	verifyButtonNotBound(inputMap, ATOM("a"), 1, 1, 1, __LINE__);
	verifyButtonNotBound(inputMap, ATOM("b"), 0, 0, 0, __LINE__);
	
	inputMap->bindButton(inputMap, ATOM("a"), 0, 0, 0);
	verifyButtonBound(inputMap, ATOM("a"), 0, 0, 0, __LINE__);
	
	inputMap->bindButton(inputMap, ATOM("a"), 0, 0, 1);
	verifyButtonBound(inputMap, ATOM("a"), 0, 0, 0, __LINE__);
	verifyButtonBound(inputMap, ATOM("a"), 0, 0, 1, __LINE__);
	
	inputMap->bindButton(inputMap, ATOM("a"), 1, 1, 1);
	verifyButtonBound(inputMap, ATOM("a"), 0, 0, 0, __LINE__);
	verifyButtonBound(inputMap, ATOM("a"), 0, 0, 1, __LINE__);
	verifyButtonBound(inputMap, ATOM("a"), 1, 1, 1, __LINE__);
	
	inputMap->bindButton(inputMap, ATOM("b"), 0, 0, 0);
	verifyButtonBound(inputMap, ATOM("a"), 0, 0, 0, __LINE__);
	verifyButtonBound(inputMap, ATOM("a"), 0, 0, 1, __LINE__);
	verifyButtonBound(inputMap, ATOM("a"), 1, 1, 1, __LINE__);
	verifyButtonBound(inputMap, ATOM("b"), 0, 0, 0, __LINE__);
	
	inputMap->unbindButton(inputMap, ATOM("a"), 0, 0, 0);
	verifyButtonNotBound(inputMap, ATOM("a"), 0, 0, 0, __LINE__);
	verifyButtonBound(inputMap, ATOM("a"), 0, 0, 1, __LINE__);
	verifyButtonBound(inputMap, ATOM("a"), 1, 1, 1, __LINE__);
	verifyButtonBound(inputMap, ATOM("b"), 0, 0, 0, __LINE__);
}
Exemplo n.º 8
0
static void testKeyboardBindings() {
	InputMap * inputMap;
	
	inputMap = InputMap_create();
	verifyKeyNotBound(inputMap, ATOM("a"), 1, 3, __LINE__);
	verifyKeyNotBound(inputMap, ATOM("b"), 1, 2, __LINE__);
	
	inputMap->bindKey(inputMap, ATOM("a"), 1, 3);
	verifyKeyBound(inputMap, ATOM("a"), 1, 3, __LINE__);
	
	inputMap->bindKey(inputMap, ATOM("a"), 1, 2);
	verifyKeyBound(inputMap, ATOM("a"), 1, 2, __LINE__);
	TestCase_assert(!isKeyBound(inputMap, ATOM("a"), 1, 3), "Expected false but got true");
	
	inputMap->bindKey(inputMap, ATOM("a"), 2, 4);
	verifyKeyBound(inputMap, ATOM("a"), 1, 2, __LINE__);
	verifyKeyBound(inputMap, ATOM("a"), 2, 4, __LINE__);
	
	inputMap->bindKey(inputMap, ATOM("b"), 1, 2);
	verifyKeyBound(inputMap, ATOM("a"), 1, 2, __LINE__);
	verifyKeyBound(inputMap, ATOM("a"), 2, 4, __LINE__);
	verifyKeyBound(inputMap, ATOM("b"), 1, 2, __LINE__);
	
	inputMap->unbindKey(inputMap, ATOM("a"), 1);
	verifyKeyNotBound(inputMap, ATOM("a"), 1, 2, __LINE__);
	verifyKeyBound(inputMap, ATOM("a"), 2, 4, __LINE__);
	verifyKeyBound(inputMap, ATOM("b"), 1, 2, __LINE__);
}
Exemplo n.º 9
0
static void testKeyModifierBindings() {
	InputMap * inputMap;
	
	inputMap = InputMap_create();
	verifyKeyModifierNotBound(inputMap, ATOM("a"), 1, __LINE__);
	verifyKeyModifierNotBound(inputMap, ATOM("b"), 2, __LINE__);
	
	inputMap->bindKeyModifier(inputMap, ATOM("a"), 1);
	verifyKeyModifierBound(inputMap, ATOM("a"), 1, __LINE__);
	
	inputMap->bindKeyModifier(inputMap, ATOM("a"), 4);
	verifyKeyModifierBound(inputMap, ATOM("a"), 1, __LINE__);
	verifyKeyModifierBound(inputMap, ATOM("a"), 4, __LINE__);
	
	inputMap->bindKeyModifier(inputMap, ATOM("b"), 2);
	verifyKeyModifierBound(inputMap, ATOM("a"), 1, __LINE__);
	verifyKeyModifierBound(inputMap, ATOM("a"), 4, __LINE__);
	verifyKeyModifierBound(inputMap, ATOM("b"), 2, __LINE__);
	
	inputMap->unbindKeyModifier(inputMap, ATOM("a"), 1);
	verifyKeyModifierNotBound(inputMap, ATOM("a"), 1, __LINE__);
	verifyKeyModifierBound(inputMap, ATOM("a"), 4, __LINE__);
	verifyKeyModifierBound(inputMap, ATOM("b"), 2, __LINE__);
}
Exemplo n.º 10
0
int main(int argc, char ** argv){
    if (argc > 1){
        Global::InitConditions conditions;
        Global::init(conditions);
        
        Global::setDebug(0);
        std::string file = argv[1];

        Paintown::Mod::loadDefaultMod();
        
        InputManager manager;
        Graphics::Bitmap screen(*Graphics::getScreenBuffer());
        Util::Parameter<Graphics::Bitmap*> use(Graphics::screenParameter, &screen);
        Keyboard::pushRepeatState(true);
        
        InputMap<Keys> input;
        input.set(Keyboard::Key_ESC, 0, true, Esc);
        input.set(Keyboard::Key_ENTER, 0, true, Enter);
        input.set(Keyboard::Key_UP, 0, true, Up);
        input.set(Keyboard::Key_DOWN, 0, true, Down);
        input.set(Keyboard::Key_LEFT, 0, true, Left);
        input.set(Keyboard::Key_RIGHT, 0, true, Right);
       
        try {
            
            Filesystem::AbsolutePath path(file);
            CharacterSelect select(path);
            
            Logic logic(input, select);
            Draw draw(select);

            Util::standardLoop(logic, draw);
            
        } catch (const LoadException & ex){
            Global::debug(0) << "Problem loading file [" << file << "]. Reason: " << ex.getTrace() << std::endl;
        } catch (const TokenException & ex){
            Global::debug(0) << "Problem parsing file [" << file << "]. Reason: " << ex.getTrace() << std::endl;
        }
        
    } else {
        std::cout << "Usage: ./" << argv[0] << " select-screen.txt" << std::endl;
    }
    return 0;
}
Exemplo n.º 11
0
////////////////////////////////////////////////////////////
///Entrypoint of application 
//////////////////////////////////////////////////////////// 
int main()
{
	gui.setScale(16);
	gui.m_debug = true;


	bool updateGUI = true;

	registerInputs();

	// Create the main window 
	sf::RenderWindow window(sf::VideoMode(g_screenW, g_screenH, 32), "Tower Of Hanoi");

	// Start game loop 
	while (window.isOpen())
	{
		// Process events 
		sf::Event Event;
		while (window.pollEvent(Event))
		{
			// Close window : exit 
			if (Event.type == sf::Event::Closed)
				window.close();

			// Escape key : exit 
			if ((Event.type == sf::Event::KeyPressed) && ((Event.key.code == g_keyboard.Escape) || (Event.key.code == g_keyboard.BackSpace)/*Alt+F4 support here*/))
				window.close();

#pragma region Input
		//Update all keys
		for (InputMap::iterator mStart = buttons.begin(), mIter = mStart, mEnd = buttons.end(); mIter != mEnd; ++mIter)
		{
 			mIter->second.update();
		}

		//Check all keys, take actions, figure out if we need to update the GUI
		if (*buttons[LEFT])			{ updateGUI = game.moveLeft(); }
		if (*buttons[RIGHT])		{ updateGUI = game.moveRight(); }
		if (*buttons[UP])			{ updateGUI = game.moveUp(); }
		if (*buttons[DOWN])			{ updateGUI = game.moveDown(); }
		if (*buttons[ACTION])		{ updateGUI = game.actionButton(); }
		
		if (*buttons[SCALEUP])		{ updateGUI = gui.setScale(gui.getScale() + 1); }
		if (*buttons[SCALEDOWN])	{ updateGUI = gui.setScale(gui.getScale() - 1); }
		
		if (*buttons[NUM0])			{ updateGUI = game.returnDisc(); }
		if (*buttons[NUM1])			{ updateGUI = game.handleDisc(0); }
		if (*buttons[NUM2])			{ updateGUI = game.handleDisc(1); }
		if (*buttons[NUM3])			{ updateGUI = game.handleDisc(2); }
		if (*buttons[NUM4])			{ updateGUI = game.handleDisc(3); }
		if (*buttons[NUM5])			{ updateGUI = game.handleDisc(4); }
		if (*buttons[NUM6])			{ updateGUI = game.handleDisc(5); }
		if (*buttons[NUM7])			{ updateGUI = game.handleDisc(6); }
		if (*buttons[NUM8])			{ updateGUI = game.handleDisc(7); }
		if (*buttons[NUM9])			{ updateGUI = game.handleDisc(8); }
#pragma endregion
		}

		// Draw loop
		if (updateGUI)
		{
			window.clear(g_clearCol);
			gui.drawGame(window, game);
			window.display();
			updateGUI = false;
		}
	}

	return EXIT_SUCCESS;
}
Exemplo n.º 12
0
void doBackground(const std::string &file, const std::string &section){
    Mugen::Background background = Mugen::Background(Filesystem::AbsolutePath(file), section);
    Graphics::Bitmap workArea(320,240);
    Graphics::Bitmap screen(640,480);
    
    double runCounter = 0;
    Global::speed_counter4 = 0;
    Global::second_counter = 0;
    int game_time = 100;
    
    // Set game keys temporary
    InputMap<int> gameInput;
    gameInput.set(Keyboard::Key_ESC, 10, true, 0);
    gameInput.set(Keyboard::Key_UP, 1, false, 1);
    gameInput.set(Keyboard::Key_DOWN, 1, false, 2);
    gameInput.set(Keyboard::Key_LEFT, 1, false, 3);
    gameInput.set(Keyboard::Key_RIGHT, 1, false, 4);
    gameInput.set(Keyboard::Key_F1, 10, true, 5);
    gameInput.set(Keyboard::Key_LSHIFT, 1, false, 6);
    
    bool done = false;

    Mugen::Point camera;
    
    while ( ! done ){
    
	bool draw = false;
	
	if ( Global::speed_counter4 > 0 ){
	    draw = true;
	    runCounter += Global::speed_counter4 * Global::ticksPerSecond(60);
	    while ( runCounter >= 1.0 ){
		runCounter -= 1;
		// Key handler
		InputManager::poll();
		
                /*
		InputMap<int>::Output out = InputManager::getMap(gameInput);
		if (out[0]){
		    done = true;
		}

                int speed = 1;
                if (out[6]){
                    speed = 10;
                }

                if (out[1]){
		    camera.y -= speed;
		}
                if (out[2]){
		    camera.y += speed;
		}
                if (out[3]){
		    camera.x -= speed;
		}
                if (out[4]){
		    camera.x += speed;
		}
                if (out[5]){
                    // Reset camera
                    camera.x = camera.y = 0;
                }
                */
		
		// Backgrounds
		background.act();
	    }
	    
	    Global::speed_counter4 = 0;
	}
		
	while ( Global::second_counter > 0 ){
	    game_time--;
	    Global::second_counter--;
	    if ( game_time < 0 ){
		    game_time = 0;
	    }
	}

	if ( draw ){
	    // render backgrounds
	    background.renderBackground(camera.x, camera.y, workArea);
	    
	    // render Foregrounds
	    background.renderForeground(camera.x, camera.y, workArea);

            // This is a reminder of where the current 0,0 position is
            workArea.vLine(0,160,240,Graphics::makeColor(0,255,0));
            Font::getDefaultFont().printf( 5, 0, Graphics::makeColor(255,0,0), workArea, "Camera X: %i",0, camera.x );
            Font::getDefaultFont().printf( 5, 10, Graphics::makeColor(255,0,0), workArea, "Camera Y: %i",0, camera.y );
	    
	    // Finally render to screen
	    workArea.Stretch(screen);
	    screen.BlitToScreen();
	}

	while ( Global::speed_counter4 < 1 ){
		PaintownUtil::rest( 1 );
	}
    }
}
Exemplo n.º 13
0
int main(int argc, char ** argv){
    if (argc > 1){
        Global::InitConditions conditions;
        Global::init(conditions);
        
        Global::setDebug(0);
        std::string file = argv[1];
        
        InputManager manager;
        Graphics::Bitmap screen(*Graphics::getScreenBuffer());
        Util::Parameter<Graphics::Bitmap*> use(Graphics::screenParameter, &screen);
        Keyboard::pushRepeatState(true);
        
        InputMap<Keys> input;
        input.set(Keyboard::Key_ESC, 0, true, Esc);
        input.set(Keyboard::Key_ENTER, 0, true, Enter);
        input.set(Keyboard::Key_UP, 0, true, Up);
        input.set(Keyboard::Key_DOWN, 0, true, Down);
        input.set(Keyboard::Key_LEFT, 0, true, Left);
        input.set(Keyboard::Key_RIGHT, 0, true, Right);
        input.set(Keyboard::Key_S, 0, true, S);
        input.set(Keyboard::Key_P, 0, true, P);
        input.set(Keyboard::Key_R, 0, true, R);
        input.set(Keyboard::Key_SPACE, 0, true, SpaceBar);
        input.set(Keyboard::Key_1, 0, true, Key1);
        input.set(Keyboard::Key_2, 0, true, Key2);
        input.set(Keyboard::Key_3, 0, true, Key3);
        input.set(Keyboard::Key_4, 0, true, Key4);
        input.set(Keyboard::Key_5, 0, true, Key5);
        input.set(Keyboard::Key_6, 0, true, Key6);
       
        try {
            
            CutSceneTool cutscene(file);
            
            Logic logic(input, cutscene);
            Draw draw(cutscene);

            Util::standardLoop(logic, draw);
            
        } catch (const LoadException & ex){
            Global::debug(0) << "Problem loading file [" << file << "]. Reason: " << ex.getTrace() << std::endl;
        } catch (const TokenException & ex){
            Global::debug(0) << "Problem parsing file [" << file << "]. Reason: " << ex.getTrace() << std::endl;
        } catch (const Storage::NotFound & ex){
            Global::debug(0) << "Couldn't find file. Reason: " << ex.getTrace() << std::endl;
        }
        
    } else {
        std::cout << "Usage: ./" << argv[0] << " cutscene.txt" << std::endl;
    }
    return 0;
}
Exemplo n.º 14
0
static void testSerialization() {
	InputMap inputMap;
	TestSerializationContext * context;
	jmp_buf jmpEnv;
	
	context = TestSerializationContext_create(&jmpEnv);
	if (setjmp(jmpEnv) != 0) {
		TestCase_assert(false, "%s", context->error);
	}
	
	InputMap_init(&inputMap);
	
	context->expectCall(context, context->beginStructure, "input_map");
	context->expectCall(context, context->writeUInt16, "format_version", INPUT_MAP_SERIALIZATION_FORMAT_VERSION);
	context->expectCall(context, context->beginArray, "keyboard_bindings");
	context->expectCall(context, context->endArray);
	context->expectCall(context, context->beginArray, "gamepad_maps");
	context->expectCall(context, context->endArray);
	context->expectCall(context, context->endStructure);
	
	InputMap_serialize(&inputMap, context);
	
	context->finish(context);
	context->dispose(context);
	inputMap.dispose(&inputMap);
	
	context = TestSerializationContext_create(&jmpEnv);
	if (setjmp(jmpEnv) != 0) {
		TestCase_assert(false, "%s", context->error);
	}
	
	InputMap_init(&inputMap);
	inputMap.bindKey(&inputMap, ATOM("a"), 1, 2);
	inputMap.bindKey(&inputMap, ATOM("b"), 3, 4);
	inputMap.bindButton(&inputMap, ATOM("a"), 1, 2, 3);
	inputMap.bindButton(&inputMap, ATOM("b"), 1, 2, 4);
	inputMap.bindButton(&inputMap, ATOM("c"), 4, 5, 6);
	inputMap.bindAxis(&inputMap, ATOM("a"), 1, 2, 3, 0.5f, 0.5f);
	inputMap.bindAxis(&inputMap, ATOM("b"), 1, 2, 4, 0.5f, 0.5f);
	inputMap.bindAxis(&inputMap, ATOM("c"), 4, 5, 6, 1.0f, 0.0f);
	
	context->expectCall(context, context->beginStructure, "input_map");
		context->expectCall(context, context->writeUInt16, "format_version", INPUT_MAP_SERIALIZATION_FORMAT_VERSION);
		context->expectCall(context, context->beginArray, "keyboard_bindings");
			context->expectCall(context, context->beginStructure, NULL);
				context->expectCall(context, context->writeString, "action", "a");
				context->expectCall(context, context->writeUInt32, "key_code", 1);
				context->expectCall(context, context->writeUInt32, "char_code", 2);
			context->expectCall(context, context->endStructure);
			context->expectCall(context, context->beginStructure, NULL);
				context->expectCall(context, context->writeString, "action", "b");
				context->expectCall(context, context->writeUInt32, "key_code", 3);
				context->expectCall(context, context->writeUInt32, "char_code", 4);
			context->expectCall(context, context->endStructure);
		context->expectCall(context, context->endArray);
		context->expectCall(context, context->beginArray, "gamepad_maps");
			context->expectCall(context, context->beginStructure, NULL);
				context->expectCall(context, context->writeInt32, "vendor_id", 1);
				context->expectCall(context, context->writeInt32, "product_id", 2);
				context->expectCall(context, context->beginDictionary, "button_bindings");
					context->expectCall(context, context->writeUInt32, "a", 3);
					context->expectCall(context, context->writeUInt32, "b", 4);
				context->expectCall(context, context->endDictionary);
				context->expectCall(context, context->beginArray, "axis_bindings");
					context->expectCall(context, context->beginStructure, NULL);
						context->expectCall(context, context->writeString, "action", "a");
						context->expectCall(context, context->writeUInt32, "axis_id", 3);
						context->expectCall(context, context->writeFloat, "trigger_threshold", 0.5f);
						context->expectCall(context, context->writeFloat, "release_threshold", 0.5f);
					context->expectCall(context, context->endStructure);
					context->expectCall(context, context->beginStructure, NULL);
						context->expectCall(context, context->writeString, "action", "b");
						context->expectCall(context, context->writeUInt32, "axis_id", 4);
						context->expectCall(context, context->writeFloat, "trigger_threshold", 0.5f);
						context->expectCall(context, context->writeFloat, "release_threshold", 0.5f);
					context->expectCall(context, context->endStructure);
				context->expectCall(context, context->endArray);
			context->expectCall(context, context->endStructure);
			context->expectCall(context, context->beginStructure, NULL);
				context->expectCall(context, context->writeInt32, "vendor_id", 4);
				context->expectCall(context, context->writeInt32, "product_id", 5);
				context->expectCall(context, context->beginDictionary, "button_bindings");
					context->expectCall(context, context->writeUInt32, "c", 6);
				context->expectCall(context, context->endDictionary);
				context->expectCall(context, context->beginArray, "axis_bindings");
					context->expectCall(context, context->beginStructure, NULL);
						context->expectCall(context, context->writeString, "action", "c");
						context->expectCall(context, context->writeUInt32, "axis_id", 6);
						context->expectCall(context, context->writeFloat, "trigger_threshold", 1.0f);
						context->expectCall(context, context->writeFloat, "release_threshold", 0.0f);
					context->expectCall(context, context->endStructure);
				context->expectCall(context, context->endArray);
			context->expectCall(context, context->endStructure);
		context->expectCall(context, context->endArray);
	context->expectCall(context, context->endStructure);
	
	InputMap_serialize(&inputMap, context);
	
	context->finish(context);
	context->dispose(context);
	inputMap.dispose(&inputMap);
}
Exemplo n.º 15
0
static InputMap<Keys> getKeys(){
    InputMap<Keys> input;
    input.set(Keyboard::Key_F1, 10, false, F1);
    input.set(Keyboard::Key_F2, 10, false, F2);
    input.set(Keyboard::Key_F3, 10, false, F3);
    input.set(Keyboard::Key_F4, 10, false, F4);
    input.set(Keyboard::Key_F5, 10, false, F5);
    input.set(Keyboard::Key_F6, 10, false, F6);
    input.set(Keyboard::Key_F7, 10, false, F7);
    input.set(Keyboard::Key_F8, 10, false, F8);
    input.set(Keyboard::Key_F9, 10, false, F9);
    input.set(Keyboard::Key_F10, 10, false, F10);
    input.set(Keyboard::Key_F11, 10, false, F11);
    input.set(Keyboard::Key_F12, 10, false, F12);
    input.set(Keyboard::Key_ESC, 10, false, Esc);
    input.set(Keyboard::Key_ENTER, 10, false, Enter);
    input.set(Keyboard::Key_UP, 10, false, Up);
    input.set(Keyboard::Key_DOWN, 10, false, Down);
    input.set(Keyboard::Key_LEFT, 10, false, Left);
    input.set(Keyboard::Key_RIGHT, 10, false, Right);
    input.set(Keyboard::Key_SPACE, 10, false, Space);
    input.set(Keyboard::Key_PGUP, 10, false, PageUp);
    input.set(Keyboard::Key_PGDN, 10, false, PageDown);
    input.set(Keyboard::Key_M, Action1);
    input.set(Keyboard::Key_P, Action2);
    
    return input;
}
Exemplo n.º 16
0
{
	ButtonA,
	ButtonStart = ButtonA,
	ButtonB,
	ButtonC,
	ButtonD,
	ButtonE,
	ButtonF,
	ButtonG,
	ButtonCount
};

TEST_CASE("InputMap/create", "")
{
	InputManager manager;
	InputMap map(manager, "testmap");

	REQUIRE(&manager == &map.GetManager());
	REQUIRE(map.GetName());
	REQUIRE(strcmp(map.GetName(), "testmap") == 0);

	for (int b = ButtonStart; b < ButtonCount; ++b)
	{
		REQUIRE(!map.IsMapped(b));
	}

	InputMap map2(manager);
	REQUIRE(!map2.GetName());
}

TEST_CASE("InputMap/map_bool", "")
Exemplo n.º 17
0
vector<Input::PaintownInput> Player::fillKeyCache(){
    /*
    acts += 1;
    if (acts > GLOBAL_KEY_DELAY){
        if (!key_cache.empty()){
            key_cache.pop_front();
        }

        acts = 0;
    }
    */

    InputMap<Input::PaintownInput> input;
    InputSource useSource(true);
    if (source != NULL){
        useSource = *source;
    }

    int facing = getFacing();
    /* set up keyboard */
    if (useSource.useKeyboard()){
        enum Input::PaintownInput all[] = {Input::Forward, Input::Back, Input::Up, Input::Down, Input::Attack1, Input::Attack2, Input::Attack3, Input::Attack4, Input::Attack5, Input::Attack6, Input::Jump, Input::Grab};
        for (vector<int>::const_iterator it = useSource.getKeyboard().begin(); it != useSource.getKeyboard().end(); it++){
            for (unsigned int i = 0; i < sizeof(all) / sizeof(Input::PaintownInput); i++){
                input.set(getKey(*it, all[i], facing), 0, false, all[i]);
            }
        }
    }

    /* set up joystick */
    if (useSource.useJoystick()){
        enum Input::PaintownInput all[] = {Input::Forward, Input::Back, Input::Up, Input::Down, Input::Attack1, Input::Attack2, Input::Attack3, Input::Attack4, Input::Attack5, Input::Attack6, Input::Jump, Input::Grab};

        for (unsigned int i = 0; i < sizeof(all) / sizeof(Input::PaintownInput); i++){
            input.set(getJoystickKey( all[i], facing), 0, false, all[i]);
        }
    }

    acts += 1;

    // keyHold.back = false;

    vector<InputMap<Input::PaintownInput>::InputEvent> events = InputManager::getEvents(input, useSource);
    for (vector<InputMap<Input::PaintownInput>::InputEvent>::iterator it = events.begin(); it != events.end(); it++){
        InputMap<Input::PaintownInput>::InputEvent event = *it;

        /*
        switch (event.out){
            case Input::Forward: keyHold.forward = event.enabled; break;
            case Input::Back: keyHold.back = event.enabled; break;
            case Input::Up: keyHold.up = event.enabled; break;
            case Input::Down: keyHold.down = event.enabled; break;
            default: break;
        }
        */

        if (!event.enabled){
            continue;
        }

        key_cache.push_back(event.out);
        
        acts = 0;
    }

    while (key_cache.size() > KEY_CACHE_SIZE){
        key_cache.pop_front();
    }

    if (acts > GLOBAL_KEY_DELAY){
        key_cache.clear();
    }
        
    InputMap<Input::PaintownInput> inputHold;

    /* normalize such that forward is left */
    int facingHold = FACING_LEFT;
    enum Input::PaintownInput allHold[] = {Input::Forward, Input::Back, Input::Up, Input::Down};
    for (unsigned int i = 0; i < sizeof(allHold) / sizeof(Input::PaintownInput); i++){
        for (vector<int>::const_iterator it = useSource.getKeyboard().begin(); it != useSource.getKeyboard().end(); it++){
            inputHold.set(getKey(*it, allHold[i], facingHold), 0, false, allHold[i]);
        }

        if (useSource.useJoystick()){
            inputHold.set(getJoystickKey(allHold[i], facingHold), 0, false, allHold[i]);
        }
    }

    vector<InputMap<Input::PaintownInput>::InputEvent> eventsHold = InputManager::getEvents(inputHold, useSource);
    for (vector<InputMap<Input::PaintownInput>::InputEvent>::iterator it = eventsHold.begin(); it != eventsHold.end(); it++){
        InputMap<Input::PaintownInput>::InputEvent event = *it;

        switch (event.out){
            case Input::Forward: keyHold.left = event.enabled; break;
            case Input::Back: keyHold.right = event.enabled; break;
            case Input::Up: keyHold.up = event.enabled; break;
            case Input::Down: keyHold.down = event.enabled; break;
            default: break;
        }
    }

    vector<Input::PaintownInput> real_input;
    if (keyHold.up){
        real_input.push_back(Input::Up);
    }
    if (keyHold.down){
        real_input.push_back(Input::Down);
    }
    if (keyHold.left){
        if (getFacing() == FACING_LEFT){
            real_input.push_back(Input::Forward);
        } else {
            real_input.push_back(Input::Back);
        }
    }
    if (keyHold.right){
        if (getFacing() == FACING_LEFT){
            real_input.push_back(Input::Back);
        } else {
            real_input.push_back(Input::Forward);
        }
        // keyHold.forward = true;
    }

    return real_input;
}