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.


Topics - foobarbaz

Pages: [1]
1
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.

2
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

3
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.

4
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?

5
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?

6
SFML projects / Rewrite of SFML in Google's Golang
« on: September 21, 2013, 10:46:23 pm »
Hey all! So I changed my name (I'm DrSuperSocks, but tedsta includes my actual name (Teddy), is shorter, and a 19-year-old shouldn't have an alias that sounds like a 13-year-old's).

EDIT:

I originally posted my whole game engine, which uses a rewrite of the Graphics module of SFML I did. But I realize now that my game engine isn't relevant to any of you, and the only thing I was really showing off was my rewrite of SFML. So, here is my rewrite of SFML in Golang. It took 3 days to write the code, then another 3 or 4 days to get the code to actually work ;) Parts of it still feel clunky, as C++ doesn't translate perfectly to Golang. The two biggest issues are the lack of const reference and inheritance.

So far, I've only rewritten a good chunk of the graphics module. That may be as far as I go, unless I need more features out of SFML.

Check it out here: https://github.com/tedsta/gosfml

PS: There are existing SFML bindings for Go, which I was originally using, but I wanted to be able to touch the variables in primitives, like Vector2.

7
Hi, all, I'm just wondering if it is necessary to check if graphics are actually on the screen before trying to render them? I have a lot of sprites and sf::VertexArrays in my game, and the vast majority of them aren't on the screen at any given time, so does SFML automatically handle this? Or is this something I should do on my own? The game doesn't lag at all, but I figure that I might as well optimize everything that I can.

8
Feature requests / Vector Math Functions
« on: May 08, 2013, 07:32:34 am »
Hey all, I think Vector math functions (normalize, magnitude, rotation, etc.) are important for any game developer, so I think they'd be a good addition to SFML. Right now, every time I get the latest SFML, I have to go back and add in those functions to the Vector2 class. Sure, it only takes a few seconds, but if everyone is using them (and I have sure used these in just about every game I have ever made), why not just include them? I searched the forum a bit, and found that Vector math had already been discussed, but the link provided is dead.

We have already had a discussion about vector functions (-> Link)...

I understand that Vector2 is an abstracted class, but, honestly, who uses Vector2 for anything other than math? I know both Ogre3D and Irrlicht provide extensive math helper functions for their Vector classes.

        Vector2<T>& normalize()
        {
                float length = (float)(x*x + y*y);
                if (length == 0.f)
                        return *this;
                length = sqrt ( 1.f/length );
                x = (T)(x * length);
                y = (T)(y * length);
                return *this;
        }

        Vector2<T>& rotateBy(float degrees, const Vector2<T>& center=Vector2<T>())
        {
                degrees *= 3.14159f/180.f;
                const float cs = cos(degrees);
                const float sn = sin(degrees);

                x -= center.x;
                y -= center.y;

                T nx = (T)(x*cs - y*sn);
                T ny = (T)(x*sn + y*cs);

        x = nx;
        y = ny;

                x += center.x;
                y += center.y;
                return *this;
        }

    // returns trig angle
        float getAngle() const
        {
                if (y == 0)
                        return x < 0 ? 180 : 0;
                else if (x == 0)
                        return y < 0 ? 270 : 90;

                if ( y > 0)
                        if (x > 0)
                                return atan(y/x) * 180.f/3.14159f;
                        else
                                return 180.0-atan(y/-x) * 180.f/3.14159f;
                else
                        if (x > 0)
                                return 360.0-atan(-y/x) * 180.f/3.14159f;
                        else
                                return 180.0+atan(-y/-x) * 180.f/3.14159f;
        }

        float getLength()
        {
            return sqrt(x*x + y*y);
        }
 

9
General / Screen coordinate and world coordinate troubles
« on: April 23, 2013, 06:08:39 am »
Hey all, I'm having problems converting between screen and world coordinates when zooming my views. Everything has been going smoothly up until I added zooming. As long as I don't zoom in or out, I can rotate and move the camera and still have proper world/screen coordinate conversions. Also, it seems when I zoom, it scales things about the top left of the screen rather than the center even though I set the center of the view to the center of the screen.

My questions are these: How do I zoom relative to the center of the screen instead of the top left corner? And how do I properly convert screen coordinates to world coordinates and vice versa when scaling is involved?

Edit: Actually, it seems like the zooming is about the lower right hand corner o.0 and it doesn't change no matter what I set the center of the view to.

View code:

mView.setCenter(mRenderWindow->getSize().x/2, mRenderWindow->getSize().y/2);
mView.setRotation(-mCameraRotation);
mView.zoom(mCameraZoom);
mRenderWindow->setView(mView);
 

Coordinate conversion code:

sf::Vector2f RenderingManager::screenToWorld(sf::Vector2f screenPos)
{
    screenPos -= getCameraScreenOffset();
    screenPos *= mCameraZoom;
    screenPos += getCameraScreenOffset();

    sf::Vector2f worldPos = screenPos-getCameraScreenOffset();
    worldPos.x = worldPos.x/mPTU;
    worldPos.y = -worldPos.y/mPTU;
    worldPos.rotateBy(getCameraRotation(), getCameraPosition());

    return worldPos;
}

sf::Vector2f RenderingManager::worldToScreen(sf::Vector2f worldPos)
{
    sf::Vector2f screenPos = worldPos;

    screenPos -= getGame()->getRenderingManager()->getCameraPosition();
    screenPos /= mCameraZoom;
    screenPos += getGame()->getRenderingManager()->getCameraPosition();

    screenPos.rotateBy(-getCameraRotation(), getCameraPosition());
    screenPos.x *= mPTU;
    screenPos.y *= -mPTU;
    screenPos += getCameraScreenOffset();

    return screenPos;
}
 

Thanks for your time.

10
SFML projects / Fission - A simple, object-component based game engine
« on: April 17, 2013, 11:26:57 pm »
.

11
Graphics / sf::Shape Texture Coordinates
« on: April 12, 2013, 03:06:51 am »
Hi, I'm writing a game that procedurally generates 2D planets. Right now, the entire planet is rendered onto a massive texture, which is fine when there is only one planet. I know, though, that I will be having problems when I have 100 planets. To get around this, instead of generating the planet's texture, I want to store polygons to render in OpenGL, but to do this, I need to be able to set texture coordinates from a source texture. I saw that texturing an sf::Shape is possible in the documentation, but couldn't find a way to set texture coordinates. Is there a way? Or am I going to have to dive into the OpenGL documentation and render my planets without SFML's help?

Thanks for your time!

Pages: [1]
anything