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

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

0 Members and 2 Guests are viewing this topic.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Thor C++ Library – An SFML extension
« Reply #150 on: December 14, 2011, 12:02:06 pm »
Quote
I have already thought about some kind of "manual" clock. That is, two classes like thor::StopWatch and thor::Timer, but instead of basing on sf::Clock, they have an Update(float dt) function and accumulate a member variable.

Does this really need a class? Obviously, it won't require Start/Stop/Reset methods, so basically a simple variable can do the job.
Code: [Select]
float accumulatedTime = 0;

while (running)
{
    if (!paused)
        accumulatedTime += elapsedTime;
}

And it doesn't solve the problem, it's just shifted to the calculation of elapsedTime.

Quote
I'd like to know if it's possible to handle this correctly, maybe with a class that get the OS ticks rather than real elapsed time.

I think that using a timing function that calculates the CPU time rather than the real time would be enough. According to the OgreTimer implementation that I saw this morning, std::clock() behaves likes this.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Thor C++ Library – An SFML extension
« Reply #151 on: December 16, 2011, 10:21:31 pm »
Quote from: "Laurent"
Does this really need a class?
Not necessarily, but with its encapsulation it provides protection against accidental modifications, and it allows convenient methods to set/get different time units. Plus, code gets more expressive with meaningful method names.

Quote from: "Laurent"
And it doesn't solve the problem, it's just shifted to the calculation of elapsedTime.
This is true. Does sf::RenderWindow::GetFrameTime() use sf::Clock internally? In this case, how can one get the "real" frame time (e.g. without the time the window is moved/resized, or the computer is in standby mode)?

Quote from: "Laurent"
According to the OgreTimer implementation that I saw this morning, std::clock() behaves likes this.
The problem with the standard clocks is that they're unprecise (or at least, the standard doesn't require high resolution). Maybe, Boost.DateTime is an alternative. But I don't like its complexity...
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 #152 on: December 16, 2011, 11:39:21 pm »
Quote
Does sf::RenderWindow::GetFrameTime() use sf::Clock internally?

Yes.

Quote
In this case, how can one get the "real" frame time (e.g. without the time the window is moved/resized, or the computer is in standby mode)?

You can't. I don't think that you can magically skip these things, you have to detect and handle them one by one.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Thor C++ Library – An SFML extension
« Reply #153 on: December 17, 2011, 12:01:18 am »
Okay. For a workaround, one can also cheat and set an upper limit for the frame time. This could also be handled automatically by a class.

Maybe one class is enough, something like thor::ManualClock with a basic sf::Clock-like interface. The ultimative flexibility could be achived by making thor::StopWatch and thor::Timer templates and by letting them choose the underlying clock. But this becomes too complicated very fast.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
Thor C++ Library – An SFML extension
« Reply #154 on: December 17, 2011, 11:15:03 am »
Quote from: "Nexus"
The problem with the standard clocks is that they're unprecise (or at least, the standard doesn't require high resolution).

Could you tell more about this? Why do you say it's not precise?
Want to play movies in your SFML application? Check out sfeMovie!

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Thor C++ Library – An SFML extension
« Reply #155 on: December 17, 2011, 03:48:25 pm »
The precision of std::clock() depends on CLOCKS_PER_SEC, which is usually about 1000, so one can't measure less than one millisecond. It may be good for many use cases, but standard clocks don't offer high-resolution measuring like sf::Clock does.

I have also come across Boost.Chrono, it looks more suitable for time measuring than Boost.DateTime. And, it is part of the C++11 standard, in the header <chrono> :)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Haikarainen

  • Guest
Thor C++ Library – An SFML extension
« Reply #156 on: December 17, 2011, 08:15:37 pm »
I found a problem.

Was setting up my development environment on my new laptop, downloaded latest SFML2, CMake, SVN and Thor1.1, and after setting up SFML successfully and creating cbp-files to build thor, I get compiler errors.

You're trying to include
Code: [Select]
#include <SFML/Graphics/Transformable.hpp>
#include <SFML/Graphics/ConvexShape.hpp>


probably others as well, these files aren't present on the lastest git of SFML.

Is this known? Should I D/L 1.0 instead?


Thanks

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Thor C++ Library – An SFML extension
« Reply #157 on: December 17, 2011, 08:45:16 pm »
You need the 'drawables' branch of SFML 2, not the master one.
Laurent Gomila - SFML developer

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
Thor C++ Library – An SFML extension
« Reply #158 on: December 18, 2011, 03:01:40 pm »
Quote from: "Nexus"
The precision of std::clock() depends on CLOCKS_PER_SEC, which is usually about 1000, so one can't measure less than one millisecond. It may be good for many use cases, but standard clocks don't offer high-resolution measuring like sf::Clock does.

Well.. we'd need to check the value for the other OSs but starting from Mac OS X 10.5 CLOCKS_PER_SEC is defined as 1000000. Thus you can measure up to one microsecond.

Quote from: "Nexus"
I have also come across Boost.Chrono, it looks more suitable for time measuring than Boost.DateTime. And, it is part of the C++11 standard, in the header <chrono> :)

Boost.Chrono.. humm.. I'll have a look at it. Thanks :)
Want to play movies in your SFML application? Check out sfeMovie!

flackez

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • http://flack.ez.lv
Thor C++ Library – An SFML extension
« Reply #159 on: December 19, 2011, 09:36:00 am »
Hello :)

I try to compile thor from svn (r71) with latest sfml from git on archlinux x64 and got this error...

Code: [Select]
Found SFML: /usr/local/include
-- SFML and OpenGL found.
-- Configuring done
-- Generating done
-- Build files have been written to: /local/buildpkg/sfml-thor/src/trunk
[  3%] Building CXX object src/CMakeFiles/thor.dir/Arrow.cpp.o
In file included from /local/buildpkg/sfml-thor/src/trunk/src/Arrow.cpp:26:0:
/local/buildpkg/sfml-thor/src/trunk/include/Thor/Multimedia/Arrow.hpp:35:43: fatal error: SFML/Graphics/Transformable.hpp: No such file or directory
compilation terminated.
make[2]: *** [src/CMakeFiles/thor.dir/Arrow.cpp.o] Error 1
make[1]: *** [src/CMakeFiles/thor.dir/all] Error 2
make: *** [all] Error 2
==> ERROR: A failure occurred in build().
    Aborting...


it seem like no file Transformable.hpp anymore in latest sfml build.  :D

edit: how i miss that above post lol :shock:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Thor C++ Library – An SFML extension
« Reply #160 on: December 19, 2011, 09:39:47 am »
The answer is three posts above... ;)
Laurent Gomila - SFML developer

excrulon

  • Newbie
  • *
  • Posts: 12
    • View Profile
Thor C++ Library – An SFML extension
« Reply #161 on: January 01, 2012, 08:40:31 am »
I can't get cmake working with this. I read previous posts in the first few pages of this thread but it didn't help. Also read the tutorial on your site. I've installed SFML, and it's in c:\program files\sfml and my FindSFML.cmake is in C:\Program Files\SFML\cmake\Modules. CMake has two similar variables to set -- SFMLDIR and SFML_DIR. SFML_DIR keeps getting reset to have the value of SFML_DIR-NOTFOUND but SFMLDIR doesn't. I just checked out the latest version of thor from trunk. I get this error no matter what I do:

CMake Warning at CMakeLists.txt:86 (find_package):
  Could not find module FindSFML.cmake or a configuration file for package
  SFML.

  Adjust CMAKE_MODULE_PATH to find FindSFML.cmake or set SFML_DIR to the
  directory containing a CMake configuration file for SFML.  The file will
  have one of the following names:

    SFMLConfig.cmake
    sfml-config.cmake



CMake Error at CMakeLists.txt:92 (message):
  SFML directory not found.  Set SFMLDIR to SFML's top-level path (containing
  "include" and "lib" directories).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Thor C++ Library – An SFML extension
« Reply #162 on: January 01, 2012, 10:21:44 am »
You must either copy FindSFML.cmake to <CMake install>/share/cmake-2.8/Modules, or set CMAKE_MODULE_PATH to "C:\Program Files\SFML\cmake\Modules".
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Thor C++ Library – An SFML extension
« Reply #163 on: January 08, 2012, 12:02:52 am »
On the future of Thor

As Laurent announced to change SFML's naming convention, I have to decide how to continue with Thor. Since Thor and SFML have a similar API (some SFML classes are inherited by Thor or have the same member functions) and the former is officially an extension of the latter, it is standing to reason that I need to adapt the new convention.

I want to exploit this opportunity to improve the general API in Thor and to break some other interfaces. Ideas I have had so far:
  • Simplification of the whole smart pointer module
    • MovedPtr is doomed. I remove this class template, because it is an error-prone and inefficient workaround to emulate move semantics in C++98.
    • CopiedPtr becomes smarter and more flexible: I plan to add support for separate cloner/deleter functors (instead of the compile-time policies) and derived-to-base conversions.
    • ScopedPtr is either removed or changed to a CopiedPtr, but without cloner functors in order to remain noncopyable.
  • Resources and ownership
    • Replace thor::ResourcePtr with std::tr1::shared_ptr. Currently it is only a wrapper anyway, the change to shared_ptr allows people to work with standard library classes and to reduces dependencies.
    • I must decide how classes depending on resources hold them. There are two extremes: Simple pointers and reliance on the user to keep resources alive, or overall reference counting with shared_ptr. Involved resource customers are ParticleSystem, FrameAnimation, BigSprite.
  • General reorganization
    • Rename some classes with too general names or move them in a separate namespace. I'm thinking of Vertex (specific to triangulation), Connection (specific to events) and maybe the Geometry classes. This preserves the ability to introduce new classes (for example for network connections) without API breaks.
    • Reorder modules. I'm not completely happy with Geometry, Multimedia and Math; their application fields are blurry. I have no clue yet, ideas are welcome!
    • I have even considered to split parts of the Tools module, which are not directly connected to multimedia programming, into a separate library. This concerns smart pointers, dynamic dispatchers, the NonCopyable base class and foreach macros. Doing so would render this functionality more interesting for people that don't use SFML. It would still be used by Thor.
    • Possibly C++11 features (optional or unconditional). Implementation as well as usage gets easier and more efficient. Rvalue references for the smart pointers are a popular example.
Please tell me what you think about those points. I'm also open to other suggestions regarding the API. What do you find unintuitive? Are there things you consider unnecessary/useless? Don't hesitate to post your opinions, unfortunately I recently receive only few feedback from the people using Thor. I'm happy about all inputs, even if you yourself don't use my library.

Concerning the addition of new features, I will wait until a stable code base is established. If you have ideas, please still mention them, this allows me to plan more exactly and to make future integration easier.

Perhaps I am going to release a version 1.1 with the current API, if there are people wishing it.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

N1ghtly

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
Thor C++ Library – An SFML extension
« Reply #164 on: January 09, 2012, 06:24:16 pm »
Does the the latest Thor version work with the latest Git snapshot yet?