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 - foobarbaz

Pages: [1] 2 3 4
1
General discussions / Re: Fun times with C++ reflection and tuples
« on: February 25, 2014, 09:26:19 pm »
It is pretty beautiful. Sweet. I really wish C++ supported real compile-time reflection on regular objects. Although, I know D already does :P

2
General discussions / Re: Fun times with C++ reflection and tuples
« on: February 25, 2014, 07:21:04 pm »
Pythonistas, get your hands off from C++!!!  :)

Hehe it doesn't hurt performance the way python does I promise!

You might be interested in my project Aurora, especially the Tuple metaprogramming file and the Named Tuple macros :)

Your Aurora NamedTuple looks pretty cool. If you can iterate over those members (even if it's at compile time with recursive templates), then that's exactly what I want. Is that possible?

I just threw this together for fun, I don't really think it's usable yet, but maybe it could be prettied up with some macros :P Also, without the compiler optimizations, the low performance scares me.

Here's some classes:
struct Foo
{
    std::string str;
    int i;
};

std::ostream& operator<<(std::ostream& left, const Foo& right)
{
    return left << "str: " << right.str << ", " << "i: " << right.i;
}

struct Test : public Reflectable<struct name,      std::string,
                                 struct health,    int,
                                 struct foo,       Foo>
{
};
 

And a little sample processor to iterate through members:

class SamplePrinter
{
    public:
        /// \brief Int serialization
        void operator () (int x)
        {
            std::cout << "int: " << x << std::endl;
        }

        /// \brief Float serialization
        void operator () (float x)
        {
            std::cout << "float: " << x << std::endl;
        }

        /// \brief Double serialization
        void operator () (double x)
        {
            std::cout << "double: " << x << std::endl;
        }

        /// \brief String serialization
        void operator () (const std::string& x)
        {
            std::cout << "string: " << x << std::endl;
        }

        /// \brief The generic case
        template <typename X>
        void operator () (const X& x)
        {
            std::cout << "other: " << x << std::endl;
        }

    private:
};
 

And Using the stuff
Test test;
test.get<name>() = "bob";
test.get<health>() = 42;
test.get<foo>().str = "hello";
test.get<foo>().i = 24;

test.iterate(SamplePrinter());
 

I'm also pondering how you could make a macro to automatically set up references to the tuple members as public member variables, allowing you to access the variables with regular syntax. The benchmark shows that reference access is a little slower than regular tuple access with compiler optimizations on, though.

3
General discussions / Fun times with C++ reflection and tuples
« on: February 25, 2014, 06:52:46 am »
Hey guys, I scourged the interwebs today stealing everybody's code and put this little demo together.

The whole system is based off of C++11's std::tuple.

What started this furious rampage was me trying to get automatic serialization that could go beyond primitive types. I want to have custom encoding for custom objects. Until C++10923812093809 whatever comes out with compile-time reflection, I made this. Lemme know what you guys think (i.e. probably its complete garbage).

Link: https://github.com/tedsta/Reflectable

I stole code from these places so far:

http://stackoverflow.com/a/13066078
http://stackoverflow.com/a/6894436

Check the readme for some benchmarks. Don't know exactly what those compiler optimizations do.

4
Graphics / Re: Interpolating between 2 sf::Transforms
« on: February 23, 2014, 11:23:01 pm »
tedsta, maybe you should show a complete example that seems to jitter. Because in my experience I have never seen any issues when omitting the interpolation part of that game loop.

It's very subtle, and becomes more noticeable as the actual framerate gets lower. You can play around with the framerate cap and with and without smoothing. Maybe I've just gone crazy and my eyes deceive me, but I think the smoothing helps :P

#include <SFML/System/Vector2.hpp>
#include <SFML/Window/Keyboard.hpp>
#include <SFML/Window/Event.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/RectangleShape.hpp>

const float lockStep = 1.f/60.f;

void step(sf::Vector2f& state, const float dt);

int main()
{
    // Setup the window
    sf::RenderWindow window;
    window.create(sf::VideoMode(800, 600), "SFML Lockstep Example");

    // Player states
    sf::Vector2f oldState;
    sf::Vector2f curState;

    // Player object
    sf::RectangleShape player(sf::Vector2f(32, 32));
    player.setFillColor(sf::Color::Red);

    // Delta time stuff
    sf::Clock dtClock;
    float dtAccum = 0.f;

    // Main loop
    while (window.isOpen())
    {
        // Framerate cap
        while (dtClock.getElapsedTime().asSeconds() < 1.f/50.f);

        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        // Calculate dt
        float dt = dtClock.restart().asSeconds();

        // Add to the dt accumulator
        dtAccum += dt;

        // While there's unsimulated time
        while (dtAccum >= lockStep)
        {
            dtAccum -= lockStep;
            oldState = curState;
            step(curState, lockStep);
        }

        float accumStepRatio = dtAccum / lockStep;

        sf::Vector2f state = curState*accumStepRatio + oldState*(1.f - accumStepRatio);

        // Smoothed state
        player.setPosition(state);

        // Non smoothed
        //player.setPosition(curState);

        window.clear(sf::Color::Black);
        window.draw(player);
        window.display();
    }

    return 0;
}

void step(sf::Vector2f& state, const float dt)
{
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::W))
        state.y -= 100.f*dt;
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::S))
        state.y += 100.f*dt;
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A))
        state.x -= 100.f*dt;
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::D))
        state.x += 100.f*dt;
}
 

EDIT:

Also becomes more noticeable as speed increases. Try upping the speed to 200 pixels per second.

5
Graphics / Re: Interpolating between 2 sf::Transforms
« on: February 23, 2014, 09:53:45 pm »
What you can do, is extract affine transforms like translation, rotation and scale, interpolate them, and recompose them to a new transform matrix.

That's what I was afraid of. I'll have to recalculate the global transforms of all entities that moved and all of their children every frame. But I suppose I have to bite the bullet.

Thanks

6
Graphics / Interpolating between 2 sf::Transforms
« on: February 23, 2014, 09:22:04 pm »
Hi guys,

Is it possible to interpolate between 2 sf::Transform objects? I'm trying to implement the smoothing for my locked time step http://gafferongames.com/game-physics/fix-your-timestep/. I have had the locked time step there for a while, but the visual jitter is really bothering me now :P.

This would be trivial in a system where entities cannot be parented to each other, but in my case you can parent transforms, so I have a calculated global transform for every entity, and would like to interpolate between the current global transform and the previous one.

Is it possible to interpolate between 2 sf::Transform objects? If so, any hints as to how you'd do it?
Thanks in advance

EDIT:

Woops, I meant to post this in graphics, if Laurent wants to move it :P

7
General / Re: Peer code review on EventManager
« on: February 22, 2014, 11:42:19 am »
Codeblocks auto generates those header guards. I'll fix them, thanks for the info. I hope I can reconfigure the way codeblocks does it.

Thanks nexus for the std::type_index tip, looks good.

Nano is a simple signal implementation: https://code.google.com/p/nano-signal-slot/

After looking at std::function, it does look like the Nano::signal is overkill. Although, it does make removing listeners really easy. I guess the signal would basically do all the heavy lifting for me? Anyway, I updated the code to use std::function, it does look simpler. But this std::placeholder business confuses me.

Thanks for the input guys.


8
General / Peer code review on EventManager
« on: February 22, 2014, 04:49:08 am »
So today I revamped my EventManager to use signals. The client code is a lot cleaner I think :D

I haven't finished it yet (still need to remove listeners, more unit tests, etc.), but I was hoping I could get some peer code review. Go ahead and tear it apart :P

Teh codez
https://github.com/tedsta/Fission/blob/master/include/Fission/Core/EventManager.h

The unit test
https://github.com/tedsta/Fission/blob/master/src/Fission/Tests/TestEventManager.cpp

I'm concerned about efficiency, whether or not I should be using RTTI, and code cleanliness. I guess whether or not I'm doing things "right."

Have at me!
Thanks in advance.

9
General / Re: RAII and object ownership
« on: February 05, 2014, 12:01:07 am »
I know many of you are sticklers for RAII.
I'm probably the worst of them, especially after my article ;D

I was hoping you'd respond to this, and that was actually one of the first articles I read on RAII :P

What you should try instead is to use the factory functions as much as possible, e.g. std::make_unique() in C++14.
fooMgr.addFoo(std::make_unique<FooBazz>());

One possibility is also to use the emplacement idiom combined with perfect forwarding (I hope I got the syntax right):
template <typename... Args>
void addFoo(Args&&... args)
{
    mFoos.emplace_back(std::forward<Args>(args)...);
}

fooMgr.addFoo<FooBazz>();

Wow, thanks for that! :D This fixes so many things. I can see that the implementation of std::make_unique uses the template magic in your emplacement example. Since C++14 isn't available to me yet, I'll make a little make_unique while I wait for Codeblocks to have a C++14 flag. I'm far too lazy to set up codeblocks with the new gcc on all my machines ;) This is about the time I wish I was more of a linux junkie who likes to write C++ code in VIM and compile on the command line.

But anyway, thanks Nexus, your reply solves soooo much smelly code I have in my project.

10
General / [solved] RAII and object ownership
« on: February 04, 2014, 10:40:33 pm »
I've been trying to grasp RAII, and understand that all resources should be wrapped in an object. When the object is constructed, the resource is initialized. When the object goes out of scope, the resource is deinitialized. I hope my understanding is correct. I know many of you are sticklers for RAII.

Free store memory is a resource, and thus it has to be wrapped in an object. This is a smart pointer, which ensures the memory is released when the owner smart pointer object goes out of scope. This makes a lot of extra ugly typing everywhere.

So my question is this: Can I use a bare new operator to pass a new object to a manager class that will act as it's owner? Would that acceptably follow RAII?

What I want:

class Foo
{
    public:
        virtual void dog() = 0;
};

class FooBazz : public Foo
{
    public:
        void dog(){}
};

class FooManager
{
    public:
        void addFoo(Foo* foo)
        {
            mFoos.push_back(std::move(std::unique_ptr<Foo*>(foo)));
        }

    private:
        std::vector<std::unique_ptr<Foo>> mFoos;
};

void initStuff(FooManager& fooMgr)
{
    fooMgr.addFoo(new FooBazz);
}
 

What I'm trying to avoid:

void initStuff(FooManager& fooMgr)
{
    std::unique_ptr<Foo> foo(new FooBazz);
    fooMgr.addFoo(foo);
}
 

My justification for the former is that you can imply that fooMgr assumes ownership of the object since it is not wrapped in a smart pointer. This is analogous to the way you can pass raw pointers as parameters into functions knowing the function is not responsible for the pointer (I've seen this done in RAII code). Also, if I as a forgetful programmer forget to assume ownership of the Foo object, my program will have bugs regardless of whether or not I wrapped it in a std::unique_ptr in initStuff(). A smart pointer would go out of scope, and the FooBazz I passed would be invalid memory later in the program. Without a smart pointer, it'd be a memory leak.

What do you guys think?

11
System / Re: Footprint size of sf::Mutex
« on: January 11, 2014, 03:22:58 am »
Is it possible to find out how many bytes an sf::Mutex takes up on each platform?

On Unix systems sf::Mutex contains a pthread_mutex_t object which size should be 40bytes.
On win32 systems it contain a CRITICAL_SECTION object which has 24bytes.


AlexAUT

Derp. Thanks!

Don't make it multi-threading, especially if you have very little experience with it.
If you lock the entities when they are being used, will in the end create a non parallel game with a huge overhead, due to costant locking and releasing.

The goal of parallel programming is to split the processing into independent tasks, that way they can run in parallel. If you however have complex relations between entities, you'll have to pause one task and wait for another to finish. If the system is really complex you might end up just with one entity being processed at a time, which in turn equals the original system, except that you now how to take care of all the split up, locking, waiting, etc. And then you'd also have to prove that your system can't run into deadlocks or starvation problems.

If you were thinking about write rendering an updating in parallel, you'd have to make sure that all the entities have been processed correctly, otherwise you'd end up with some entities at the old and some at the new position.
And you'd thus lock everything, which will again create a sequential aplication (update() wait() render()).

If you want to write stuff in parallel, you should lear the details first, then implement the game sequentially and at the end let some tasks run in parallel to optimize. ;)

With so many entities, it is highly unlikely that the same entity will be processed by multiple systems at any given time. Since all logic goes in systems, and systems can only communicate via thread-safe events, I think it might be feasible.

Given that 1 million windows CRITICAL_SECTIONs lock and unlock operations takes only 23.5 nanoseconds, I think the mutex overhead will be negligible. http://preshing.com/20111124/always-use-a-lightweight-mutex/

And finally, I'm just experimenting, having fun, and learning. Besides, someone has to at least attempt it ;)

12
System / Footprint size of sf::Mutex
« on: January 11, 2014, 01:45:09 am »
Hey all,

I'm working on an implementation of the Entity System design. I'm trying to make it multithreaded - so each system runs in its own thread.

- Systems process entities that have the required components attached to them.
- Components only store data and contain no, or very minimal helper logic.
- Systems running in different threads could access the same entity at the same time, which doesn't end well.

To solve this, I'm thinking I could give each entity instance a mutex, and when a system begins processing the entity, its mutex will lock until the processing is done. My game requires potentially 100k active entities on the client, and around a million on the server.

Is it possible to find out how many bytes an sf::Mutex takes up on each platform?

13
SFML projects / Re: operation bloodshed - (WIP)
« on: October 22, 2013, 02:18:14 pm »
This just continues to get more epic. Keep up the awesome work, man!

14
SFML projects / Re: Rewrite of SFML in Google's Golang
« on: October 22, 2013, 02:12:09 pm »
Thanks! I like feeling cool  8)

SFML is only used for graphics because I was just toying around at first, and forgot to implement SFML's events/input. Good point. I'll try to get that done soon. I also need to benchmark this against the SFML Go bindings https://github.com/drhodes/go-sfml. I'll post the results back here.

If anyone knows of Spine, that recently kickstarted 2D skeletal animation software, I got it working with my game engine as well. Haven't committed yet, but you can expect it in a few days after I apply the polish. A big round of applause to the guy who wrote this (https://github.com/ajhager/spine), he did a fantastic job adapting the C spine runtime. I'm hoping I can convince the spine devs to officially support Go.

I was pretty busy this weekend, but I finally got around to writing that pong sample.
https://github.com/tedsta/gosfml/blob/master/examples/pong/main.go

After a few more days of dev, we've decided to most likely push forward with Go. A big reason we were thinking about switching was also because my friend is in the final interview stages with Microsoft, where he'll be working with C++. But we got our 4th and final member on the team, and he votes Go, which makes the vote for Go win 3 to 1.

I'll be writing a short tutorial on how to set up gosfml sometime this week, as installing go-gl and go-glfw3 is a huge pain on Windows, and a little easier on Linux.

15
SFML projects / Re: Rewrite of SFML in Google's Golang
« on: October 18, 2013, 10:22:18 pm »
Oh, I didn't realize people cared, I haven't checked the forums in a while. Haha.

I'd totally be down to write a pong example, I'll do that this weekend. Also, if you want to see how I'm personally using it, the rendering portion of my engine uses it: https://github.com/tedsta/fission/tree/master/rendering. I'm writing a game in Go to see if it's suitable for game development. So far it's been alright, but I'm heavily considering switching back to C++ as two of my buddies at the university just joined the team, and we all main in C++, so having them try to learn a new language might not be so effective. At first I was just toying around, but the game quickly evolved into something we actually want to finish.

Pages: [1] 2 3 4
anything