Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Whittler

Pages: [1]
1
General discussions / Review of simple Input Manager.
« on: August 05, 2019, 09:20:51 pm »
Hello! ;)
I am during my first project in SFML in which I decided to create some kind of game engine that I can use in my future games. I made an action manager which has its members marked as static.

.hpp file:
#include "Input/input.hpp"

#include <unordered_map>

namespace WhitE {

class ActionManager
{
public:
        static void addAction(const std::string&, sf::Keyboard::Key);
        static void addAction(const std::string&, std::vector<sf::Keyboard::Key>);

        static void deleteAction(const std::string& actionName);
        static bool isActionPressed(const std::string& actionName);
        static bool isMouseButtonPressed(sf::Mouse::Button);

private:
        inline static Input mInput;
        inline static std::unordered_map<std::string, std::vector<sf::Keyboard::Key>> mKeyboardMap;
};

}
 

.cpp file:
#include "Input/actionManager.hpp"
#include "Logger/logs.hpp"

namespace WhitE {

void ActionManager::addAction(const std::string& actionName, sf::Keyboard::Key key)
{
        mKeyboardMap.insert(std::make_pair(actionName, std::vector<sf::Keyboard::Key> {key}));

        WE_LOG_INFO(actionName + " action was added to the manager.");
}

void ActionManager::addAction(const std::string& actionName, std::vector<sf::Keyboard::Key> keys)
{
        mKeyboardMap.insert(std::make_pair(actionName, keys));
}

void ActionManager::deleteAction(const std::string& actionName)
{
        if (mKeyboardMap.find(actionName) != mKeyboardMap.end())
                mKeyboardMap.erase(actionName);
        else
                WE_LOG_WARNING("WhitE: Key of map cannot be found!");
}

bool ActionManager::isActionPressed(const std::string& actionName)
{
        auto keys = mKeyboardMap.at(actionName);
        for (const auto& key : keys)
        {
                if (mInput.isKeyPressed(key))
                        return true;
        }
}

bool ActionManager::isMouseButtonPressed(sf::Mouse::Button button)
{
        return mInput.isMouseButtonPressed(button) ? true : false;
}

}
 

And then I've got a simple class which handles real-time input
#include "Input/actionManager.hpp"

#include <SFML/Window.hpp>

namespace WhitE {

class Input
{
private:
        bool isKeyPressed(sf::Keyboard::Key key) { return sf::Keyboard::isKeyPressed(key); }
        bool isMouseButtonPressed(sf::Mouse::Button button) { return sf::Mouse::isButtonPressed(button); }

        friend class ActionManager;
};

}
 

My question is if it even makes sense? In case of checking input I'd need to type "if(ActionManager::isActionPressed("someAction")) doSomeStuff" which is not the most convinient style but I have no idea how it could be rearranged. Any help would be appreciated.

2
Audio / Re: Audio module, linker errors while static linking.
« on: July 05, 2019, 11:11:07 pm »
You may be right :o sorry for being gone but I am on the Holidays right now so I can't even check my dependencies but I hope that is the case and I'll make it work. I'll reply as soon as I'm home.

EDIT: Yea - that was the case. I must have been really tired while checking the list. :/ Anyway it worked after added openal32.lib. Sorry for problem.

3
Audio / Re: Audio module, linker errors while static linking.
« on: June 29, 2019, 03:22:19 pm »
Yee, I know. I just mentioned these from Audio module. These are the ones I've got:
sfml-system-s-d.lib
sfml-audio-s-d.lib
sfml-graphics-s-d.lib
sfml-window-s-d.lib
opengl32.lib
freetype.lib
winmm.lib
gdi32.lib
flac.lib
ogg.lib
vorbis.lib
vorbisenc.lib
vorbisfile.lib

4
Audio / Audio module, linker errors while static linking.
« on: June 29, 2019, 02:32:59 am »
Hi ;)
I linked SFML statically today and wanted to check if everything's okay. I thought that it's great but tested audio module in the end. It turned out that in Debug mode it doesn't work, even though in Release it's totally okay.
I linked all needed libraries - flac.lib, ogg.lib, openal32.lib, sfml-system-s-d.lib, vorbis.lib, vorbisfile.lib and vorbisenc.lib.

Here are a few of linker errors:
https://cdn1.imggmi.com/uploads/2019/6/29/ca5ba6a76e42d8d3cbb644b8eec3db93-full.jpg

Pages: [1]