BASIC

Author Topic: 2 Questions NETWEBGET  (Read 3178 times)

Offline Poetronic

  • Mr. Drawsprite
  • **
  • Posts: 98
    • View Profile
2 Questions NETWEBGET
« on: 2012-Aug-02 »
Hi all,

I got two (well, ok, three) more questions which might be very easy to answer for most of you I guess...

1. How can I test if there is an internet connection and is that necessary when using the NETWEBGET command?

2. When I call a PHP-website to save to an online hiscore database, there seems to be a slight delay when jumping back into another game mode. Thereby, the animation that appears when you start the game gets slightly out of sync. What can I do to prevent that from happening?

As always: thank you very much!  :)
ILI-Blocks, my first game ever - please check it out! http://www.glbasic.com/forum/index.php?topic=8654.0

MrTAToad

  • Guest
Re: 2 Questions NETWEBGET
« Reply #1 on: 2012-Aug-02 »
I use this to determine whether an internet connection is available :

Code: GLBasic [Select]
LOCAL webAddresses$[]; DIMDATA webAddresses$[],"www.bbc.co.uk","www.microsoft.com","www.glbasic.com"

                self.isInternetAvailable%=FALSE
                IF SOCK_INIT()
                        FOR loop%=0 TO BOUNDS(webAddresses$[],0)-1
                                socket%=SOCK_TCPCONNECT(webAddresses$[loop%],port%)
                                IF socket%>=0
                                        SOCK_CLOSE(socket%)
                                        self.isInternetAvailable%=TRUE
                                        BREAK
                                ENDIF
                        NEXT

                        SOCK_SHUTDOWN
                ENDIF

2.  You would have to compensate for the time delay and update any animations accordingly unless you use a thread for calculating the animation positions.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10715
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
2 Questions NETWEBGET
« Reply #2 on: 2012-Aug-02 »
2. or use the sock commands instead. See the networking for cowards tutorial.

Offline Poetronic

  • Mr. Drawsprite
  • **
  • Posts: 98
    • View Profile
Re: 2 Questions NETWEBGET
« Reply #3 on: 2012-Aug-02 »
Hi thanks for your replies,

I will take a closer look at your comments right away, but I just noticed that when I move the window, the animations stop, and when I re-focus the window, the animations are totally out of sync? How can I keep that from happening? AUTOPAUSE TRUE doesn't seem to make a difference.

Thx in advance!
ILI-Blocks, my first game ever - please check it out! http://www.glbasic.com/forum/index.php?topic=8654.0

Offline Poetronic

  • Mr. Drawsprite
  • **
  • Posts: 98
    • View Profile
Re: 2 Questions NETWEBGET
« Reply #4 on: 2012-Aug-02 »
Quote
2.  You would have to compensate for the time delay and update any animations accordingly unless you use a thread for calculating the animation positions.

How exactly would I know how much time has passed since I used the NETWEBGET command? Isn't it possible to use the command and then check if it has been successful and THEN change the gamemode back to startscreen or something like that? I mean I don't really understand how the animation keeps getting out of sync in the first place - why does it? Explanations?  :)
ILI-Blocks, my first game ever - please check it out! http://www.glbasic.com/forum/index.php?topic=8654.0

Offline Wampus

  • Prof. Inline
  • *****
  • Posts: 1004
    • View Profile
Re: 2 Questions NETWEBGET
« Reply #5 on: 2012-Aug-02 »
How exactly would I know how much time has passed since I used the NETWEBGET command? Isn't it possible to use the command and then check if it has been successful and THEN change the gamemode back to startscreen or something like that? I mean I don't really understand how the animation keeps getting out of sync in the first place - why does it? Explanations?  :)

You could use a network timestamp of your own choosing, or probably much better (since I assume the app doesn't require sync with a server), use GETTIMERALL() to measure the time taken and adjust accordingly. However, the problem you're having with animation is a strange one and I can only imagine why animation is getting out of sync based on guesses about how you're handling animation.

If you had a small bit of example code you could post that reproduced the problem it would help a lot.

Offline Poetronic

  • Mr. Drawsprite
  • **
  • Posts: 98
    • View Profile
Re: 2 Questions NETWEBGET
« Reply #6 on: 2012-Aug-02 »
Ok, here we go.


Problem is as follows:

The start screen of my game contains a scrolling text made up of an array of letters. The animation is smooth and simple (cf. att. 1). I just call a function inside my game loop in gamestate 0 (which is the startscreen) which animates the letters.

Now when I press the WINDOWS-key in order to change windows (mouse is locked to the window since it is moving the player) and then click on the window and move it a little bit, the animation freezes. But as soon as I release the mouse button and the game is resumed, the text animation is totally broken.

I don't know why that is happening... I thought that a) moving the program window could never cause problems inside the animation loop of the program and b) AUTOPAUSE TRUE would stop the program when it gets out of focus anyway (it does not).

Any form of help is highly appreciated! :)

PS - Perhaps I should have mentioned that the animation speed is based on deltatime.
« Last Edit: 2012-Aug-12 by Poetronic »
ILI-Blocks, my first game ever - please check it out! http://www.glbasic.com/forum/index.php?topic=8654.0

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10715
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
2 Questions NETWEBGET
« Reply #7 on: 2012-Aug-02 »
We need the code that calculates the position of the letters

Offline Poetronic

  • Mr. Drawsprite
  • **
  • Posts: 98
    • View Profile
Re: 2 Questions NETWEBGET
« Reply #8 on: 2012-Aug-02 »
Here you go - don't shout at me, I'm just a hobby programmer :)

Code: GLBasic [Select]
FUNCTION ScrollText:
        FOREACH scrl IN ScrList[]

                IF scrl.angle > 205 THEN scrl.direction = 1
                IF scrl.angle < 155 THEN scrl.direction = 0

                IF scrl.x > -ScrlLength AND scrl.x < 641
                        PRINT scrl.letter$,scrl.x,scrl.y
                ENDIF

                IF scrl.x < -ScrlLength+640
                        scrl.x = 641
                        scrl.y = 380
                        scrl.angle = 225
                ENDIF

                IF scrl.x < 641
                        INC scrl.x, COS(scrl.angle)*scrl.speed*dt
                        INC scrl.y, SIN(scrl.angle)*scrl.speed/3*dt
                        IF scrl.direction = 0 THEN INC scrl.angle, 0.035*dt
                        IF scrl.direction = 1 THEN DEC scrl.angle, 0.035*dt
                ENDIF

                IF scrl.x >= 641 THEN DEC scrl.x, scrl.speed*dt // Reset x-coordinates = repeat loop

        NEXT
ENDFUNCTION
« Last Edit: 2012-Aug-02 by Poetronic »
ILI-Blocks, my first game ever - please check it out! http://www.glbasic.com/forum/index.php?topic=8654.0

Offline Poetronic

  • Mr. Drawsprite
  • **
  • Posts: 98
    • View Profile
Re: 2 Questions NETWEBGET
« Reply #9 on: 2012-Aug-02 »
Somehow I don't think that the code is to blame (although it might look a bit naive to some of you guys).

The problem seems to be the way the program window freezes when I move it and loses sync when I release the mouse button. I read that AUTOPAUSE TRUE should stop all animations in the program when the window is out of focus, but it doesn't. There is no difference between using AUTOPAUSE TRUE or FALSE, the behavior of the pogram window stays exactly the same (also when I use ALT+TAB). The program always keeps running in the background.

ILI-Blocks, my first game ever - please check it out! http://www.glbasic.com/forum/index.php?topic=8654.0

Offline Poetronic

  • Mr. Drawsprite
  • **
  • Posts: 98
    • View Profile
Re: 2 Questions NETWEBGET
« Reply #10 on: 2012-Aug-02 »
Ok, I found out why AUTOPAUSE didn't work - I was still in DEBUG mode. But the problem remains the same: losing the animation sync when moving the window...
« Last Edit: 2012-Aug-02 by Poetronic »
ILI-Blocks, my first game ever - please check it out! http://www.glbasic.com/forum/index.php?topic=8654.0

Offline Wampus

  • Prof. Inline
  • *****
  • Posts: 1004
    • View Profile
Re: 2 Questions NETWEBGET
« Reply #11 on: 2012-Aug-02 »
Hmm. AUTOPAUSE TRUE won't freeze the game timers read with GETTIMERALL(). That might be an issue to resolve if you use that command as part of your deltatime calculations. The other issue with deltatime is the dreaded rounding errors that can occur.

What part of your code sets a new value for variable dt? (if I can be so nosy)

Offline Poetronic

  • Mr. Drawsprite
  • **
  • Posts: 98
    • View Profile
Re: 2 Questions NETWEBGET
« Reply #12 on: 2012-Aug-02 »
No need for excuses, you're not nosy at all! On the contrary, I really appreciate your help!

I use the GETTIMER() command as follows:

Code: GLBasic [Select]
WHILE TRUE

        // Here is the game loop

        dt = GETTIMER() // time since last SHOWSCREEN

        SHOWSCREEN

WEND
« Last Edit: 2012-Aug-02 by Poetronic »
ILI-Blocks, my first game ever - please check it out! http://www.glbasic.com/forum/index.php?topic=8654.0

Offline Wampus

  • Prof. Inline
  • *****
  • Posts: 1004
    • View Profile
Re: 2 Questions NETWEBGET
« Reply #13 on: 2012-Aug-02 »
I'm almost certain the problem is the way large values for deltatime are interacting with your code, probably in the Sine and Cosine calculations.

Instead of using dt = GETTIMER() try setting dt = 16.6666, dt = 33.3332 and dt = 8.3333. What you'd want to happen is the animation to speed up or slow down but the positions of the letters to be correct. If the positions of the letters are incorrect then a new routine for dealing with the variable deltatime is needed. If it still looks ok, try setting large values for dt, to see how that goes.

I don't like variable deltatime because of the problems large or tiny values can create with code that doesn't anticipate them or accumulative rounding problems. I've used fixed-step deltatime in the past, which has its problems too but is generally easier to code.

Offline Poetronic

  • Mr. Drawsprite
  • **
  • Posts: 98
    • View Profile
Re: 2 Questions NETWEBGET
« Reply #14 on: 2012-Aug-02 »
Uhm... wouldn't a fixed dt undermine the very concept of frame independent animation?

EDIT: But yeah, it absolutely solves the issue! What am I supposed to do now?
« Last Edit: 2012-Aug-02 by Poetronic »
ILI-Blocks, my first game ever - please check it out! http://www.glbasic.com/forum/index.php?topic=8654.0