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

Author Topic: Thor 2.0 released!  (Read 381625 times)

0 Members and 5 Guests are viewing this topic.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Thor 2.0
« Reply #300 on: January 14, 2014, 12:35:00 am »
I pushed the bugfix.

You are now able to use move semantics. You should prefer it over pointers (never use new/delete!)
// Function that takes argument by value; can be a constructor
void function(thor::Animator<sf::Sprite, std::string> animator);

thor::Animator<sf::Sprite, std::string> animator;
function(std::move(animator)); // transfer ownership to function
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

kingcools

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: Thor 2.0
« Reply #301 on: January 14, 2014, 04:16:52 am »
Great! Well i used a unique_ptr so it wont matter

kingcools

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: Thor 2.0
« Reply #302 on: January 16, 2014, 04:42:06 am »
Hi,

right now i want to create a bullet whenever my animation is at the proper sprite. now i figured the animator class has no "current animation element" sort of function neither an animation time function.
How would you implement a "correct" (== bullet matches shooting animation) bullet creation?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Thor 2.0
« Reply #303 on: January 16, 2014, 09:26:09 am »
I wouldn't make game logics dependent on graphics, rather the other way around: Determine a time, and then set the animation duration and the fire delay accordingly.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

The Terminator

  • Full Member
  • ***
  • Posts: 224
  • Windows and Mac C++ Developer
    • View Profile
Re: Thor 2.0
« Reply #304 on: January 25, 2014, 08:40:18 pm »
Hi Nexus,

I have a quick question regarding sf::TextEntered. Now, with the default SFML polling you can do things like this:

if (event.type == sf::Event::TextEntered)
{
    if (event.text.unicode < 128)
        std::cout << "ASCII character typed: " << static_cast<char>(event.text.unicode) << std::endl;
}

Using Thor's actions, how would I be able to find out what key the user has pressed?

Thanks!
Current Projects:
Technoport

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Thor 2.0
« Reply #305 on: January 26, 2014, 10:51:24 am »
// Callback function that is called when text entered event is triggered
void onTextEntered(const thor::ActionContext<MyAction>& context)
{
        sf::Uint32 character = context.event->text.unicode;
        ...
}

// Action map initialization
thor::ActionMap<MyEnum> map;
map[MyTextAction] = thor::Action(sf::Event::TextEntered);

// Callback registering
thor::ActionMap<MyEnum>::CallbackSystem callbacks;
callbacks.connect(MyTextAction, &onTextEntered);
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

The Terminator

  • Full Member
  • ***
  • Posts: 224
  • Windows and Mac C++ Developer
    • View Profile
Re: Thor 2.0
« Reply #306 on: January 26, 2014, 05:08:54 pm »
// Callback function that is called when text entered event is triggered
void onTextEntered(const thor::ActionContext<MyAction>& context)
{
        sf::Uint32 character = context.event->text.unicode;
        ...
}

// Action map initialization
thor::ActionMap<MyEnum> map;
map[MyTextAction] = thor::Action(sf::Event::TextEntered);

// Callback registering
thor::ActionMap<MyEnum>::CallbackSystem callbacks;
callbacks.connect(MyTextAction, &onTextEntered);

Thanks! I have one more question. Let's say I have the onTextEntered method, but want to change it a little bit:

static void onTextEntered(const thor::ActionContext<User_Input>& context,
                                  const SInputManager& instance);

How would I connect the callback to the system?
Current Projects:
Technoport

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Thor 2.0
« Reply #307 on: January 26, 2014, 05:27:17 pm »
There are multiple possibilities what you can pass to connect().

Functor:
struct Functor
{
    void operator() (const thor::ActionContext<...>& context) const
    {
        SInputManager::onTextEntered(context, instance);
    }

    const SInputManager& instance;
    ...
}

Lambda expression:
[&instance] (const thor::ActionContext<...>& context)
{
    onTextEntered(context, instance);
}

Bind (_1 is in namespace std::placeholders):
std::bind(&SInputManager::onTextEntered, _1, std::cref(instance))

onTextEntered() can also be a non-static member function, you have to adapt the function objects accordingly. I recommend reading more about function objects in C++, they're very powerful.

And don't use those S prefixes for classes, there is really no reason to :(
« Last Edit: January 26, 2014, 05:31:59 pm by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

The Terminator

  • Full Member
  • ***
  • Posts: 224
  • Windows and Mac C++ Developer
    • View Profile
Re: Thor 2.0
« Reply #308 on: January 26, 2014, 06:07:30 pm »
There are multiple possibilities what you can pass to connect().

Functor:
struct Functor
{
    void operator() (const thor::ActionContext<...>& context) const
    {
        SInputManager::onTextEntered(context, instance);
    }

    const SInputManager& instance;
    ...
}

Lambda expression:
[&instance] (const thor::ActionContext<...>& context)
{
    onTextEntered(context, instance);
}

Bind (_1 is in namespace std::placeholders):
std::bind(&SInputManager::onTextEntered, _1, std::cref(instance))

onTextEntered() can also be a non-static member function, you have to adapt the function objects accordingly. I recommend reading more about function objects in C++, they're very powerful.

And don't use those S prefixes for classes, there is really no reason to :(

I'm going to std::bind route, and the code compiles, but the application crashes right as invokeCallbacks is called. My code:

static void onTextEntered(const thor::ActionContext<User_Input>& context,
                           const SInputManager& instance);

m_callback_system.connect(User_Input::TEXTENTERED, std::bind(&SE::SInputManager::onTextEntered,
                                                                     std::placeholders::_1,
                                                                     std::cref(*this)));

m_user_map.invokeCallbacks(m_callback_system, nullptr);

    void SInputManager::onTextEntered(const thor::ActionContext<User_Input>& context, const SInputManager& instance)
    {
        sf::Uint32 character = context.event->text.unicode;

        m_textEntered += character;
    }
Current Projects:
Technoport

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Thor 2.0
« Reply #309 on: January 27, 2014, 08:18:50 pm »
There's no need to quote the whole post if it's just above ;)

Where does it crash exactly? Please minimize the code and try to debug a bit on your own. If you want me to see the problem, show a minimal and complete example.

Anyway, it would be easier to have a non-static member function, and pass this as the second parameter (first after function name) to std::bind().
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

The Terminator

  • Full Member
  • ***
  • Posts: 224
  • Windows and Mac C++ Developer
    • View Profile
Re: Thor 2.0
« Reply #310 on: January 29, 2014, 09:57:37 pm »
Anyway, it would be easier to have a non-static member function, and pass this as the second parameter (first after function name) to std::bind().

I've been reading a little bit about std::bind and functors. I fully understand functors now, but I'm still having a little bit of trouble with std::bind. I've done exactly what you said (remove static and pass this to connect) but I'm still having some issues. My code:

m_callback_system.connect(User_Input::TEXTENTERED, std::bind(&SE::SInputManager::onTextEntered, *this));

Thanks again!
Current Projects:
Technoport

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Thor 2.0
« Reply #311 on: January 29, 2014, 10:40:07 pm »
You still need _1 as the last argument in std::bind() -- it specifies the thor::ActionContext argument that is forwarded. Furthermore, for member functions you should pass a pointer, not a reference to the object.
std::bind(&SE::SInputManager::onTextEntered, this, _1)

If you struggle at understanding std::bind(), just use lambda expressions.

And have you seen my advice concerning "S" prefixes? ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

pedrolino

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Thor 2.0
« Reply #312 on: January 30, 2014, 02:42:07 pm »
Hello :)
I want to try to use thor, but I have problems :
I tried to use triangulation, but I have a segmentation fault when I call


OutputIterator thor::triangulate   (   InputIterator    verticesBegin, InputIterator    verticesEnd, OutputIterator    trianglesOut )   


To be sure that I did not make mistakes in my code, I tried to compile the triangulation example with my compiler settings : I copy paste the main function in my main.cpp, but keep my CMakeLists.txt as I am used to write it.

So in my opinion the problem is here : I probably forgot an option in my cmake file, but I don't understand cmake enough to find what is wrong in my file compared to the lib file.

So I ask you for help :)

Here is my CMakeLists.txt :

cmake_minimum_required(VERSION 2.6)

#Project name
project(Projet)

SET(CMAKE_CXX_FLAGS "-std=c++11")

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")

find_package(SFML COMPONENTS graphics window system REQUIRED)
find_package(Thor REQUIRED)

include_directories(${SFML_INCLUDE_DIRS})
include_directories(${THOR_INCLUDE_DIRS})

file(
    GLOB_RECURSE
    source_file
    src/*
)

#Executable
add_executable(
    exe
    ${source_file}
)

target_link_libraries(
    exe
    ${SFML_LIBRARIES}
    ${THOR_LIBRARY}
)
 

I hope you will be able to help me, and I apoligize if my question is stupid.

Thank you :)

(And please excuse my english : I am french and I did not practice for a while  :-[)

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Thor 2.0
« Reply #313 on: January 30, 2014, 03:12:19 pm »
You forgot to set the CMAKE_BUILD_TYPE variable. Either set it to "Release" or "Debug" (without quotation marks). You could also try to use THOR_LIBRARY_RELEASE directly instead of THOR_LIBRARY.

If it still doesn't work, can you add the following lines to your CMakeLists script directly after find_package() and show the output?
message("lib sfml [${SFML_LIBRARIES}]")
message("    thor [${THOR_LIBRARY}]")
message("inc sfml [${SFML_INCLUDE_DIRS}]")
message("    thor [${THOR_INCLUDE_DIRS}]")

Does the original Thor configuration work at you (when you build Thor with CMake, choose to build the examples)?
« Last Edit: January 30, 2014, 03:14:11 pm by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

pedrolino

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Thor 2.0
« Reply #314 on: January 30, 2014, 07:56:04 pm »
Hello :)

Quote
Either set it to "Release" or "Debug"

This worked!
Thank you very much.

Quote
Does the original Thor configuration work at you (when you build Thor with CMake, choose to build the examples)?

Yes it works, that's why I thought it was a problem in my CMakeLists script.

Thanks again! :D

 

anything