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

Pages: [1]
1
C / Re: sfCircleShape_move
« on: March 11, 2023, 04:33:35 pm »
C++ Builder cannot work directly with MSVS C++ libraries, i.e. these libraries have a namespace. Therefore, only option C can be used. It's strange, of course, but other libraries seem to work without problems,
even the same SDL (I tried it for a long time, but I can try again for the sake of the experiment). But here, everything related to operations with variables does not work as it should (everything is fine in VisualStudio). I don't know what to think. It seems that when calling library functions, the link goes to memory areas where random data is located.

It will probably be easier to write on MSVS :(

2
C / sfCircleShape_move
« on: March 11, 2023, 03:47:37 pm »
Draw a circle, trying to move it.
The sfCircleShape_move function must move the object by the given offset. But the movement goes along the coordinates specified in the parameters of this function, or a generally incomprehensible result
        sfCircleShape *circle = sfCircleShape_create();
        sfCircleShape_setRadius(circle, 20 - 3);
        sfCircleShape_setOutlineThickness(circle, 3);
        sfCircleShape_setOutlineColor(circle, sfBlack);
        sfCircleShape_setFillColor(circle, sfWhite);

        sfVector2f CirclePosOld = {800 / 2, 600 / 2};
        sfCircleShape_setPosition(circle, CirclePosOld) ;

        sfVector2f CirclePosNew = { 50, 50 } ;
        sfCircleShape_move(circle, CirclePosNew );

        float fPosOld_x = CirclePosOld.x ;
        float fPosNew_x = sfCircleShape_getPosition(circle).x ;

        float fPosOld_y = CirclePosOld.y ;
        float fPosNew_y = sfCircleShape_getPosition(circle).y ;

 

Result:


Works:
        sfVector2f CirclePosOld = {800 / 2, 600 / 2};
        sfCircleShape_setPosition(circle, CirclePosOld) ;
        sfVector2f CirclePosNew = {CirclePosOld.x + 50, CirclePosOld.y + 50 } ;
        sfCircleShape_setPosition(circle, CirclePosNew) ;
 


It feels like I'm the only one with the problems.

3
C / Re: How sfClock_getElapsedTime() works ?
« on: March 09, 2023, 12:34:40 pm »
I'm starting to lean towards this too. But, there are other projects where external .dll are used. There are no problems with them. In VS2019, everything also works fine for me (there are only nuances with international fonts). I decided to start with time counters, because. not much can be done without them. And while the results are constantly different. The source of the problem was not found. But this unpredictability does not allow to move on.
The C++ Builder is convenient for me only for the sake of not having to jump between different IDEs.
I will try to figure it out.

4
C / Re: How sfClock_getElapsedTime() works ?
« on: March 08, 2023, 10:40:13 am »
The problem is not even what value is given, but also that it can be different each time if you rearrange the places of the operators or add some code with a time variable. I see this for the first time. Feeling that some garbage from memory gets into these variables.
The same example, marked as working, already shows exorbitant values after 15 minutes.
If I run the same code on SFML, it always works correctly. Therefore, move no further. But for now, this is mostly a problem with variables or functions that work with time.
The second day I try to make these 5 lines of code work correctly.


5
C / How sfClock_getElapsedTime() works ?
« on: March 08, 2023, 08:21:44 am »
I don't understand how the function works. It feels like too little time has passed since the clock was updated, and therefore the counter value is always 0.

       
        float time = sfTime_asSeconds( sfClock_restart(clock) ) ;
        delta_time = sfClock_getElapsedTime(clock) ;
        timer += sfTime_asMicroseconds(delta_time);
 

But timer always 0.

Also:

CSFML:
        sfTime PreviousTime = sfTime_Zero ;
        sfTime  CurrentTime = sfClock_getElapsedTime(clock) ;
        sfTime  FrameTime = CurrentTime - PreviousTime ;
        PreviousTime = CurrentTime ;
        float DeltaTime = sfTime_asMicroseconds(FrameTime) ;
 

Error: [bcc32 Error] main.cpp(76): E2093 'operator-' not implemented in type 'sfTime' for arguments of the same type

SFML:
        sf::Clock clock;
        sf::Time previousTime{ sf::Time::Zero };
        const sf::Time currentTime{ clock.getElapsedTime() };
        const sf::Time frameTime{ currentTime - previousTime };
        previousTime = currentTime;
        const float dt{ frameTime.asSeconds() };
 

Compiles without errors.

What am I doing wrong?

Upd.

Works:
        sfClock *clock = sfClock_create();
        sfTime PreviousTime = sfTime_Zero ;
        sfTime  CurrentTime = sfClock_getElapsedTime(clock) ;
        float DeltaTime = sfTime_asMicroseconds(CurrentTime) -  sfTime_asMicroseconds(PreviousTime) ;
        PreviousTime = CurrentTime ;
 

The problem with the timer occurs if 2 clock sources are declared.

Not works:
        sfClock *clock = sfClock_create();
        sfClock *clock2 = sfClock_create();
        sfTime PreviousTime = sfTime_Zero ;
        sfTime  CurrentTime = sfClock_getElapsedTime(clock) ;
        float DeltaTime = sfTime_asMicroseconds(CurrentTime) -  sfTime_asMicroseconds(PreviousTime) ;
        PreviousTime = CurrentTime ;
 

This is a quest. It's a pity there is no description for CSFML.

6
C / Re: sfTime allways have zero value
« on: March 07, 2023, 01:23:54 am »
I tried to make a small example.
The problem of an empty variable is not clear yet. In a small example, something works. I don't even know why. I will analyze. But even in this small example, a lot of questions arose. Maybe I'm doing something wrong.
1. It is not clear why two identical variables produce a different value.
2. It is not clear how the sfClock_getElapsedTime function works
She's always returns the same value.
It seems that CSFML does not work like SFML ...
I'll test a little more, but I haven't won the time functions yet.
If necessary, I can post the project and the .exe file.


#pragma argsused


#include <Windows.h>
#include <stdio.h>

#pragma hdrstop


#include <SFML/Graphics.h>

#pragma link "csfml-system.lib"
#pragma link "csfml-window.lib"
#pragma link "csfml-graphics.lib"

int main()
{

        sfRenderWindow *window;
        sfVideoMode mode= {800, 600, 32};

        window = sfRenderWindow_create(
                mode ,
                "Test",
                sfResize | sfClose | sfTitlebar | sfClose,
                NULL );

        if (!window) return EXIT_FAILURE ;


        sfFont *font1 = sfFont_createFromFile("resources/sansation.ttf") ;
        sfFont *font2 = sfFont_createFromFile("resources/sansation.ttf") ;
        if (!font1 ) return EXIT_FAILURE;
        if (!font2 ) return EXIT_FAILURE;

        sfText *message1 = sfText_create();
        sfText_setFont(message1, font1);
        sfText_setCharacterSize(message1, 40);
        sfText_setFillColor(message1, sfWhite);

        sfText *message2 = sfText_create();
        sfText_setFont(message2, font2);
        sfText_setCharacterSize(message2, 40);
        sfText_setFillColor(message2, sfWhite);

        sfClock *clock = sfClock_create();
        sfClock_restart(clock) ;


        sfTime test1 = sfMicroseconds(100000);
        sfTime test2 = sfMicroseconds(100000);



        while (sfRenderWindow_isOpen(window) )
        {
                sfEvent event;
                while (sfRenderWindow_pollEvent(window, &event))
                {
                        if ((event.type == sfEvtClosed) ||
                           ((event.type == sfEvtKeyPressed) && (event.key.code == sfKeyEscape)))
                        {
                                sfRenderWindow_close(window);
                                break;
                        }
                }


//      float time = sfTime_asSeconds( sfClock_restart(clock) ) ;  // update timer
//      float ftest1 = time ;

        float ftest1 =  test1.microseconds ;

        char c_test1[10];
        sprintf(c_test1, "%f", ftest1);

        sfVector2f sfTextPos1 = {50.f , 100.f };
        sfText_setPosition(message1, sfTextPos1 );
        sfText_setString(message1,  c_test1 );

        char c_test2[10];
        float  ftest2 = test2.microseconds ;
        sprintf(c_test2, "%f", ftest2);

        sfVector2f sfTextPos2 = {50.f , 150.f };
        sfText_setPosition(message2, sfTextPos2 );
        sfText_setString(message2,  c_test2 );


        sfRenderWindow_clear(window, sfColor_fromRGB(50, 200, 50));
        sfRenderWindow_drawText(window, message1,  NULL);
        sfRenderWindow_drawText(window, message2,  NULL);
        sfRenderWindow_display(window);

         }

        sfClock_destroy(clock);
        sfText_destroy(message1);
        sfText_destroy(message2);
        sfFont_destroy(font1);
        sfFont_destroy(font2);
        sfRenderWindow_destroy(window);

        return EXIT_SUCCESS;
}

 

7
C / Re: sfTime allways have zero value
« on: March 06, 2023, 12:48:13 am »
I think the problem is not in the code itself. I am using C++Builder 11.x. To do this, we need to convert the .lib files to the coff format.
The .lib file is exported from dll. For some reason, the .lib files from the distribution are not being converted.
Maybe there's some problem here.

8
C / Re: sfTime allways have zero value
« on: March 05, 2023, 09:52:54 pm »
Yes. If I try to withdraw these variables, then
And in the debugger and on the screen, the value is 0.
I have not noticed any problems anymore. The remaining variables are displayed correctly.

char c_test[10];
float aaa = test1.microseconds ;
sprintf(c_test, "%f", aaa);
sfText_setString(Show_Message,  c_test );
 

9
C / Re: sfTime allways have zero value
« on: March 05, 2023, 06:26:12 pm »
Ok. 4 variables.

10
C / Re: sfTime allways have zero value
« on: March 05, 2023, 05:57:35 pm »
I'll try to attach the image

11
C / sfTime allways have zero value
« on: March 05, 2023, 04:55:57 pm »
I assign a value to a variable ways, but in the debugger the value is always 0.
In theory, everything should work. Maybe I'm doing something wrong?

sfTime time1 = sfSeconds(0.1f) ;
sfTime time2 = sfMilliseconds(100000);

CSFML 2.5.1
C++ Builder 11.3

Pages: [1]
anything