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

Author Topic: Thor C++ Library – An SFML extension  (Read 126859 times)

0 Members and 1 Guest are viewing this topic.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Thor C++ Library – An SFML extension
« on: April 18, 2011, 11:34:24 pm »



[Edit] This post is outdated. Please use now this thread to discuss about the next version of Thor.

Good evening,

I would like to present a project I have been working on the last time. Thor is an open-source C++ library which provides extensions of SFML. There have been a lot of feature requests in the forum that were either too high level or out of scope for integration into SFML. Nevertheless, some of them are very useful in game and multimedia programming. That is why I have implemented some of them, hoping that SFML users can benefit from the functionality.

Thor is completely free to use, like SFML it is licensed under zlib/libpng.


Features

The Thor C++ library comes with the following small modules:

Vectors
- 2D Vector algebra functions: Dot product, compute length and angles, ...
- 3D Vector algebra functions: Dot and cross product, compute length and angles, ...
- PolarVector: 2D vector class that stores polar coordinates

Geometry
- Zone class hierarchy for geometric figures
- Base classes for positionable, rotatable and scalable objects

Particles
- ParticleSystem class based on sf::Image, stores and manages particles (lifetime, transformations, color, ...)
- Customizable Emitter and Affector classes

Events
- SfmlEventSystem class to handle SFML events via callbacks
- EventSystem template for user-defined events

Resources
- ResourceManager class template that allows safe and easy loading, storage and access to resources
- ResourcePtr provides shared access to resources
- Predefined helper classes for SFML resources like sf::Image

Multimedia
- ConcaveShape class: As an extension to sf::Shape, it works with concave shapes
- Arrow class to visualize vectors
- Color blending and simple construction of color gradients
- String conversion functions for a few SFML classes like sf::Vector

Time
- StopWatch class: Wrapper around sf::Clock for pausable clocks
- Timer class: Countdown mechanism
- TriggeringTimer class: Countdown invoking callbacks at expiration

Tools
- SingleDispatcher: Dynamic dispatch to unary functions
- DoubleDispatcher: Dynamic dispatch to binary functions (multimethods)
- Other utility like foreach macros

SmartPtr
- ScopedPtr: Local RAII smart pointer
- MovedPtr: Movable smart pointer implementation
- CopiedPtr: Smart pointer with deep copy semantics

Math
- Generalization of trigonometry functions
- Random number generator based on TR1
- Delaunay triangulation


Download

You can download version 1.0 directly on my homepage. You will also find tutorials and the API documentation there. I use CMake to build the source code, but I also supply precompiled binaries for some configurations. Note that the library bases on the newest Git revisions of SFML 2.

In the next days, I am going to setup an SVN repository so that you are able to follow the development of the Thor C++ library.


Outlook

I try to improve the library continuously, so I appreciate feedback, be it bug reports, feature requests or general discussions. Let me know what you like to be part of Thor, and I can think about it. One of the tasks I am planning to implement in near future is a design that allows easy animations with sf::Sprite, another example is a Z buffer.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Thor C++ Library – An SFML extension
« Reply #1 on: April 18, 2011, 11:55:28 pm »
Very nice project :)

I'll try to have a deeper look at it when I have some free time.

It will also make my life much easier:
Quote
User X: "can you please implement xxx in SFML?"
Laurent: "no way... but ask Nexus"

:mrgreen:
Laurent Gomila - SFML developer

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Thor C++ Library – An SFML extension
« Reply #2 on: April 19, 2011, 10:46:54 am »
Just wondering if you want to extend it with some threading utilities? I'll soon be done with my "extension" or whatever you'd like to call it. It includes synchronization between threads, Thread pool and Job management.

Currently only got Job management left.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

WitchD0ctor

  • Full Member
  • ***
  • Posts: 100
    • View Profile
    • http://www.teleforce-blogspot.com
Thor C++ Library – An SFML extension
« Reply #3 on: April 19, 2011, 11:52:00 am »
Not gonna lie, that triangulation demo was really sexy.
would be really useful for creating box2d shapes!
John Carmack can Divide by zer0.

phoekz

  • Newbie
  • *
  • Posts: 14
    • View Profile
Thor C++ Library – An SFML extension
« Reply #4 on: April 19, 2011, 12:18:51 pm »
Definitely going to use this in my project, going to love particles and more functional clock/timer. It looks fairly simple even for a beginner. Going to toy around with this tonight :D.

Hubert

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Thor C++ Library – An SFML extension
« Reply #5 on: April 19, 2011, 02:38:17 pm »
Thanks you so much.  :o
A lot a usefull things that I'm going to use in my projet.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Thor C++ Library – An SFML extension
« Reply #6 on: April 19, 2011, 05:15:50 pm »
I'm glad that you find it useful :)

Quote from: "Groogy"
Just wondering if you want to extend it with some threading utilities?
Probably not, at least not in near future. I'd rather like to concentrate on improving and extending the current modules for now. Also, my own experience with multithreading is pretty limited ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

xazax

  • Guest
Thor C++ Library – An SFML extension
« Reply #7 on: April 19, 2011, 08:09:58 pm »
I always missed some extended vector functionality :). I hope there is a chance to backport some of those features to core SFML.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Thor C++ Library – An SFML extension
« Reply #8 on: April 19, 2011, 11:38:34 pm »
Quote from: "xazax"
I always missed some extended vector functionality :)
A lot of people did (including myself), so Thor seemed to be a good opportunity ;)

By the way, the SVN repository is now online, the URL of the trunk is http://www.bromeon.ch/svn/thor/trunk.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

xazax

  • Guest
Thor C++ Library – An SFML extension
« Reply #9 on: April 25, 2011, 05:59:01 pm »
Nice one, thank you very much.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Thor C++ Library – An SFML extension
« Reply #10 on: April 25, 2011, 08:12:09 pm »
In the meantime, I have implemented parts of a new event action system. This allows the dynamic mapping from arbitrary identifiers to specific keys, and combinations of them using OR and AND operators.

You can get the code via SVN. Here is an example:
Code: [Select]
#include <Thor/Events.hpp>
#include <SFML/Window.hpp>
#include <iostream>
#include <string>

int main()
{
// Create window, set initial settings
sf::Window window(sf::VideoMode(400, 300), "Thor Action Demo");
window.SetFramerateLimit(20);
window.EnableKeyRepeat(false);

// Create action map: std::string -> thor::Action
using thor::Action;
thor::ActionMap<std::string> map(window.GetInput());

// Run: Press one of the Shift keys and R (realtime input)
map["run"] = (Action(sf::Key::LShift) || Action(sf::Key::RShift)) && Action(sf::Key::R);

// Shoot: Press S or release D (single events)
map["shoot"] = Action(sf::Key::S, Action::PressOnce) || Action(sf::Key::D, Action::ReleaseOnce);

// Leave: Press escape
map["quit"] = Action(sf::Key::Escape, Action::PressOnce);

while (window.IsOpened())
{
// Clear temporarily pushed events
map.ClearEvents();

// Handle events
sf::Event event;
while (window.PollEvent(event))
map.PushEvent(event);

// Check which actions are active
if (map.IsActive("run"))
std::cout << ".";
if (map.IsActive("shoot"))
std::cout << "*";
if (map.IsActive("quit"))
return 0;

window.Display();
}
}

I am going to add support for mouse and joystick. What do you think about it?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Thor C++ Library – An SFML extension
« Reply #11 on: April 25, 2011, 08:48:02 pm »
Looks really good so far, I like the API.

But you shouldn't use const char* keys. Comparisons should fail, since it compares the pointer values and not the actual strings. std::string would be better. If it works, I guess it's only because your compiler uses the same memory area for two occurences of the same string literal.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Thor C++ Library – An SFML extension
« Reply #12 on: April 25, 2011, 08:59:14 pm »
I first had std::string, and somehow I thought char pointers would be enough (don't ask why :)). But you are of course right, thanks for the hint. I have fixed it.

By the way, mouse and joystick are now supported. I'd like to hear some feed-back concerning the API and functionality!
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

WitchD0ctor

  • Full Member
  • ***
  • Posts: 100
    • View Profile
    • http://www.teleforce-blogspot.com
Thor C++ Library – An SFML extension
« Reply #13 on: April 26, 2011, 04:10:39 am »
wow, those Action Events are looking real tasty.
John Carmack can Divide by zer0.

Astrof

  • Full Member
  • ***
  • Posts: 135
    • View Profile
Thor C++ Library – An SFML extension
« Reply #14 on: April 30, 2011, 02:08:17 am »
whoa NICE! I haven't looked into SFML for like...two years or so? But wanted to get back into a mini project or two.  Love the inclusion of the particle engine.  

So I haven't looked into it too much yet (don't shoot me) but was wondering, so the triangulation ties in with box2D? My previous project died because something was wrong with wither box2D or the Spark particle engine that I was using.

 

anything