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

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

0 Members and 1 Guest are viewing this topic.

AlexxanderX

  • Full Member
  • ***
  • Posts: 128
    • View Profile
    • AlexanderX
Re: Thor 2.0
« Reply #330 on: April 05, 2014, 09:43:03 am »
I want to say Nexus that you did a great job :D
But when try to compile I get those erros and I think are not related to my code:
obj/Game.o: In function `thor::MultiResourceCache::MultiResourceCache()':
Game.cpp:(.text+0x9c): multiple definition of `thor::MultiResourceCache::MultiResourceCache()'
obj/Entity.o:Entity.cpp:(.text+0x114): first defined here
obj/Game.o: In function `thor::MultiResourceCache::MultiResourceCache()':
Game.cpp:(.text+0x9c): multiple definition of `thor::MultiResourceCache::MultiResourceCache()'
obj/Entity.o:Entity.cpp:(.text+0x114): first defined here
obj/Game.o: In function `thor::MultiResourceCache::MultiResourceCache(thor::MultiResourceCache&&)':
Game.cpp:(.text+0xcc): multiple definition of `thor::MultiResourceCache::MultiResourceCache(thor::MultiResourceCache&&)'
obj/Entity.o:Entity.cpp:(.text+0x144): first defined here
obj/Game.o: In function `thor::MultiResourceCache::MultiResourceCache(thor::MultiResourceCache&&)':
Game.cpp:(.text+0xcc): multiple definition of `thor::MultiResourceCache::MultiResourceCache(thor::MultiResourceCache&&)'
obj/Entity.o:Entity.cpp:(.text+0x144): first defined here
obj/Game.o: In function `thor::MultiResourceCache::operator=(thor::MultiResourceCache&&)':
Game.cpp:(.text+0x118): multiple definition of `thor::MultiResourceCache::operator=(thor::MultiResourceCache&&)'
obj/Entity.o:Entity.cpp:(.text+0x190): first defined here
... and more more erros like those
 
Here you can find my blog and tutorials about SFML - http://alexanderx.net/ (died...) - http://web.archive.org/web/20160110002847/http://alexanderx.net/

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Thor 2.0
« Reply #331 on: April 05, 2014, 10:10:13 am »
The Resources example that also uses thor::MultiResourceCache builds fine at me, so can you show a minimal complete example (you should always do that)? You're not including the .inl file directly or mixing two versions, are you?
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
Re: Thor 2.0
« Reply #332 on: April 05, 2014, 10:39:16 am »
Nexus, I think your MultiResourceCache constructors and operator= miss the "inline" keyword.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Thor 2.0
« Reply #333 on: April 05, 2014, 10:50:08 am »
Ah exactly! They're not templates. Thanks a lot :)

Edit: Fixed now.
« Last Edit: April 05, 2014, 02:27:18 pm by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10817
    • View Profile
    • development blog
    • Email
Re: Thor 2.0
« Reply #334 on: April 11, 2014, 08:58:53 am »
While compiling Thor for the Nightly Builds, the 64 bit version of Visual Studio spit out the following two errors (yeah not gonna bother translating them :P):
Thor\src\ParticleSystem.cpp(92) : warning C4267: 'return': Konvertierung von 'size_t' nach 'unsigned int', Datenverlust möglich
Thor\examples\Fireworks.cpp(39) : warning C4267: 'Argument': Konvertierung von 'size_t' nach 'unsigned int', Datenverlust möglich
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Thor 2.0
« Reply #335 on: April 11, 2014, 10:16:32 am »
Thanks! That problem of mixing types is inherent to C++, and it's unfortunate that there is no clean solution, you always end up casting in some places.

There are mostly three unsigned integer types applicable in Thor, I think it would make sense to use them as follows:
  • sf::Uint32: when fixed size is required (networking, low-level API)
  • std::size_t: Number of elements, array sizes, indices, offsets
  • unsigned int: Pixel coordinates
I have to have a look at the corresponding places and check what measures would be the lesser evil... I originally planned to have a uniform interface with only unsigned int, but I guess that's not the best idea...
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: Thor 2.0
« Reply #336 on: May 25, 2014, 04:46:46 pm »
Hi!

Is your git hub repository up to date ???

When I try to compile I get this error :

Code: [Select]
/home/laurent/Projets-dev/Projets-c++/ODFAEG/src/odfaeg/Math/distribution.cpp|78|error: could not convert ‘<lambda closure object>odfaeg::Distributions::uniform(sf::Time, sf::Time)::__lambda1{((float)floatMin), ((float)floatMax)}’ from ‘odfaeg::Distributions::uniform(sf::Time, sf::Time)::__lambda1’ to ‘odfaeg::Distribution<sf::Time>’|


Chaore

  • Newbie
  • *
  • Posts: 41
    • View Profile
    • Email
Re: Thor 2.0
« Reply #337 on: May 25, 2014, 05:02:56 pm »
It was working 2 weeks ago so I expect that yes it's up to date.

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: Thor 2.0
« Reply #338 on: May 25, 2014, 05:07:49 pm »
Ok, ok.

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: Thor 2.0
« Reply #339 on: May 26, 2014, 08:44:57 am »
Erf, I just had miss typed the ENABLE_IF macro code. (because I don't want to use aurora, I've something else instead.)

I've a question, what does the macro FOR_EACH does ?

Is it the same that std::for_each ?

You have a bunch of macros in Aurora and I don't understand anything. (because I don't do like you does, I have a class which encapsulate c++ basic function and c++11 functions and a class any to encapsulate constant.)

Some c++11 functionnalities are still too complex for me.

Anyway I don't need to store functions parameters value here so I re-use your code with std::function but it's a bit difficult with your macros. :/

PS : erf it seems that your particule system generate only 2D vectors, I have to modify that.
« Last Edit: May 26, 2014, 08:59:05 am by Lolilolight »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Thor 2.0
« Reply #340 on: May 26, 2014, 09:16:09 am »
The documentation exists for a reason...

No, AURORA_FOREACH emulates range-based for loops. You don't need it for fully C++11 conforming compilers.
« Last Edit: May 26, 2014, 09:19:10 am by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: Thor 2.0
« Reply #341 on: May 26, 2014, 09:36:10 am »
Ha ok so I don't need it, I replaced it by that :

std::for_each (auto& affectorPair : mAffectors)
affectorPair.function(*reader, dt);
 

So you mean that you want to made a code which compile also with non c++11 compilers ?

If it's the case it differs from the mine.
« Last Edit: May 26, 2014, 09:37:52 am by Lolilolight »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Thor 2.0
« Reply #342 on: May 26, 2014, 09:44:26 am »
std::for_each (auto& affectorPair : mAffectors)
Good luck with that 8)

So you mean that you want to made a code which compile also with non c++11 compilers ?
Mainly compilers that only implement a subset of C++11, such as Visual Studio 2010.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: Thor 2.0
« Reply #343 on: May 26, 2014, 10:00:40 am »
I suppose that I have to rewrite all by myself then. :/

If I don't understand the code it'll lead to bugs.

Most of all, your affector seems to use your connexion interface. :/

And I use delegates, so ...

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: Thor 2.0
« Reply #344 on: May 26, 2014, 11:25:21 am »
I got it!

I think I don't need to return an objet of type connexion, so, addAfffector return void, and I replaced AURORA_FOR_EACH by a basic for loop.
I replaced also all sf::Vector2f by sf::Vector3f.

/////////////////////////////////////////////////////////////////////////////////
//
// Thor C++ Library
// Copyright (c) 2011-2014 Jan Haller
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
/////////////////////////////////////////////////////////////////////////////////

#include "../../../include/odfaeg/Physics/particuleSystem.h"


#include "../../../include/odfaeg/Graphics/renderWindow.h"
#include "../../../include/odfaeg/Graphics/texture.h"

#include <algorithm>
#include <array>
#include <cmath>
#include <cassert>


namespace odfaeg
{
namespace
{

// Erases emitter/affector at itr from ctr, if its time has expired. itr will point to the next element.
template <class Container>
void incrementCheckExpiry(Container& ctr, typename Container::iterator& itr, sf::Time dt)
{
// itr->second is the remaining time of the emitter/affector.
// Time::Zero means infinite time (no removal).
if (itr->timeUntilRemoval != sf::Time::Zero && (itr->timeUntilRemoval -= dt) <= sf::Time::Zero)
itr = ctr.erase(itr);
else
++itr;
}

sf::IntRect getFullRect(const Texture& texture)
{
return sf::IntRect(0, 0, texture.getSize().x, texture.getSize().y);
}

} // namespace

// ---------------------------------------------------------------------------------------------------------------------------


ParticleSystem::ParticleSystem()
: mParticles()
, mAffectors()
, mEmitters()
, mTexture(nullptr)
, mTextureRects()
, mVertices(sf::Quads)
, mNeedsVertexUpdate(true)
, mQuads()
, mNeedsQuadUpdate(true)
{
}

void ParticleSystem::setTexture(const Texture& texture)
{
mTexture = &texture;
mNeedsQuadUpdate = true;
}

unsigned int ParticleSystem::addTextureRect(const sf::IntRect& textureRect)
{
mTextureRects.push_back(textureRect);
mNeedsQuadUpdate = true;

return mTextureRects.size() - 1;
}

void ParticleSystem::swap(ParticleSystem& other)
{
// Use ADL
using std::swap;

swap(mParticles,        other.mParticles);
swap(mAffectors,        other.mAffectors);
swap(mEmitters, other.mEmitters);
swap(mTexture,  other.mTexture);
swap(mTextureRects,     other.mTextureRects);
swap(mVertices, other.mVertices);
swap(mNeedsVertexUpdate,        other.mNeedsVertexUpdate);
swap(mQuads,    other.mQuads);
swap(mNeedsQuadUpdate,  other.mNeedsQuadUpdate);
}

void ParticleSystem::addAffector(std::function<void(Particle&, sf::Time)> affector)
{
    addAffector(std::move(affector), sf::Time::Zero);
}

void ParticleSystem::addAffector(std::function<void(Particle&, sf::Time)> affector, sf::Time timeUntilRemoval)
{
    mAffectors.push_back( Affector(std::move(affector), timeUntilRemoval) );
}

void ParticleSystem::clearAffectors()
{
mAffectors.clear();
}

void ParticleSystem::addEmitter(std::function<void(EmissionInterface&, sf::Time)> emitter)
{
    addEmitter(emitter, sf::Time::Zero);
}

void ParticleSystem::addEmitter(std::function<void(EmissionInterface&, sf::Time)> emitter, sf::Time timeUntilRemoval)
{
    mEmitters.push_back( Emitter(std::move(emitter), timeUntilRemoval) );
}

void ParticleSystem::clearEmitters()
{
mEmitters.clear();
}

void ParticleSystem::update(sf::Time dt)
{
// Invalidate stored vertices
mNeedsVertexUpdate = true;

// Emit new particles and remove expiring emitters
for (EmitterContainer::iterator itr = mEmitters.begin(); itr != mEmitters.end(); )
{
itr->function(*this, dt);
incrementCheckExpiry(mEmitters, itr, dt);
}

// Affect existing particles
ParticleContainer::iterator writer = mParticles.begin();
for (ParticleContainer::iterator reader = mParticles.begin(); reader != mParticles.end(); ++reader)
{
// Apply movement and decrease lifetime
updateParticle(*reader, dt);

// If current particle is not dead
if (reader->passedLifetime < reader->totalLifetime)
{
// Only apply affectors to living particles
AffectorContainer::iterator it;
for (it = mAffectors.begin(); it < mAffectors.end(); it++) {
    it->function(*reader, dt);
}
// Go ahead
*writer++ = *reader;
}
}

// Remove particles dying this frame
mParticles.erase(writer, mParticles.end());

// Remove affectors expiring this frame
for (AffectorContainer::iterator itr = mAffectors.begin(); itr != mAffectors.end(); )
{
incrementCheckExpiry(mAffectors, itr, dt);
}
}

void ParticleSystem::clearParticles()
{
mParticles.clear();
}

void ParticleSystem::draw(RenderTarget& target, RenderStates states) const
{
// Check cached rectangles
if (mNeedsQuadUpdate)
{
computeQuads();
mNeedsQuadUpdate = false;
}

// Check cached vertices
if (mNeedsVertexUpdate)
{
computeVertices();
mNeedsVertexUpdate = false;
}

// Draw the vertex array with our texture
states.texture = mTexture;
target.draw(mVertices, states);
}

void ParticleSystem::emitParticle(const Particle& particle)
{
mParticles.push_back(particle);
}

void ParticleSystem::updateParticle(Particle& particle, sf::Time dt)
{
particle.passedLifetime += dt;

particle.position += dt.asSeconds() * particle.velocity;
particle.rotation += dt.asSeconds() * particle.rotationSpeed;
}

void ParticleSystem::computeVertices() const
{
// Clear vertex array (keeps memory allocated)
mVertices.clear();

// Fill vertex array
ParticleContainer::const_iterator it;
for(it = mParticles.begin(); it < mParticles.end(); it++)
{
TransformMatrix transform;
transform.setTranslation(Vec3f(it->position.x, it->position.y, it->position.z));
transform.setRotation(it->rotation);
transform.setScale(Vec3f(it->scale.x, it->scale.y, it->scale.z));

// Ensure valid index -- if this fails, you have not called addTextureRect() enough times, or p.textureIndex is simply wrong
assert(it->textureIndex == 0 || it->textureIndex < mTextureRects.size());

const auto& quad = mQuads[it->textureIndex];
for (unsigned int i = 0; i < 4; ++i)
{
Vertex vertex;
Vec3f pos = transform.transform(Vec3f(quad[i].position.x, quad[i].position.y,quad[i].position.z));
vertex.position = sf::Vector3f(pos.x, pos.y, pos.z);
vertex.texCoords = quad[i].texCoords;
vertex.color = it->color;

mVertices.append(vertex);
}
}
}

void ParticleSystem::computeQuads() const
{
// Ensure setTexture() has been called
assert(mTexture);

// No texture rects: Use full texture, cache single rectangle
if (mTextureRects.empty())
{
mQuads.resize(1);
computeQuad(mQuads[0], getFullRect(*mTexture));
}

// Specified texture rects: Cache every one
else
{
mQuads.resize(mTextureRects.size());
for (std::size_t i = 0; i < mTextureRects.size(); ++i)
computeQuad(mQuads[i], mTextureRects[i]);
}
}

void ParticleSystem::computeQuad(Quad& quad, const sf::IntRect& textureRect) const
{
sf::FloatRect rect(textureRect);

quad[0].texCoords = sf::Vector2f(rect.left, rect.top);
quad[1].texCoords = sf::Vector2f(rect.left + rect.width, rect.top);
quad[2].texCoords = sf::Vector2f(rect.left + rect.width, rect.top + rect.height);
quad[3].texCoords = sf::Vector2f(rect.left, rect.top + rect.height);

quad[0].position = sf::Vector3f(-rect.width, -rect.height, 0) / 2.f;
quad[1].position = sf::Vector3f( rect.width, -rect.height, 0) / 2.f;
quad[2].position = sf::Vector3f( rect.width, rect.height, 0) / 2.f;
quad[3].position = sf::Vector3f(-rect.width, rect.height, 0) / 2.f;
}

} // namespace thor