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

Pages: [1]
1
C / Re: CSFML program structure
« on: February 11, 2017, 05:25:09 pm »
Laurent, thank you for answer! And special thanks for SFML, it perfect lib, people like you are worthy of admiration.  ;)

I assume you're forced to (for work or school maybe?).

No, it only research interest. I like C, and i try to use it with different libraries, discover new in language.

C allows variable declaration in the middle of blocks since 1999 (the C99 standard).

The standard C library provides nothing to ease the use of lists or arrays. But there are many source codes or libraries that can help, just pick one and use it.

Ok, Thanks! It very helpful for me.

2
C / CSFML program structure
« on: February 11, 2017, 08:30:09 am »
Hello! I'm use SFML along C++ and i  think it very pretty library to game dev. But i'm interested in use C binding, but i'm know C language not as good as C++ and i have few little questions. Sorry if it very stupid, but i want to understand.

So, first of all it is sfVector2f. For example, in SFML we have a choice - in sf::CircleShape of move method or setPosition method put only Vector2f:

    sf::RectangleShape gun(sf::Vector2f(10.f, 50.f));
    gun.setOrigin(sf::Vector2f(5.f, 45.f));
 

or 2 floats:

        bullet.setPosition(x, y);
        bullet.setOrigin(2,2);
 

In CSFML only sfVector2f in everywere? I forced to declared many vectors for size, for positions and other to setting my sprite or primitive:

    sfVector2f vec  = { 10, 10 };
    sfVector2f vec2 = { 30, 30 };

    // ...another many many definitions of vectors to other things in my program

    sfRectangleShape_setSize(shape, vec);
    sfRectangleShape_setPosition(shape, vec2);
 

Or exist any simple way to do it? I tryed coding like this:

    sfRectangleShape_setSize(shape, (sfVector2f) {10, 10});
 

But i think this code is ugly.  :-\

Second question - is memory allocation to many objects in programm. For example. In C++ i use std::list array to store my objects:

    std::list<Bullet *> bullet_list;

    // ...

    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
    {
        if (fireTimer.getElapsedTime().asMilliseconds() > 200)
        {
            Bullet *bullet = new Bullet(gun.getPosition().x,
                                        gun.getPosition().y,
                                        gun.getRotation());
            bullet_list.push_back(bullet);
            fireTimer.restart();
        }
    }

    // ...

    for (auto i=bullet_list.begin(); i != bullet_list.end();)
    {
        Bullet *b = *i;

        // some actions with object

        if (!b->life) {
            i=bullet_list.erase(i);
            delete b;
        } else ++i;
    }
 

So easy and no one problems. May be i bad know C, but i'm no have idea how to do some one like this in C :) May be something wrong to design the program so and possible make it another? And it is possible to code applications and games in C and CSFML like a C++ and SFML? Thank you.

Pages: [1]
anything