Problem when using GetWindowPos (screencontrol) without a sleep after SetWindowPos

General FreeBASIC programming questions.
D.J.Peters
Posts: 7667
Joined: May 28, 2005 3:28

Re: Problem when using GetWindowPos (screencontrol) without a sleep after SetWindowPos

Postby D.J.Peters » Dec 30, 2018 12:54

Why do you need to set the window position ?
Do you call it more than once to move the window around with SET_WINDOW_POS ?

Joshy
Tourist Trap
Posts: 2756
Joined: Jun 02, 2015 16:24

Re: Problem when using GetWindowPos (screencontrol) without a sleep after SetWindowPos

Postby Tourist Trap » Dec 30, 2018 13:11

D.J.Peters wrote:Why do you need to set the window position ?
Do you call it more than once to move the window around with SET_WINDOW_POS ?

Joshy

In fact, it was just an idea that I will probably not use. I'm thinking of adding a blob (a big sprite) thanks to the second screen allowed when you call a screenres from a dll. If it's a shaped window, it could be a good foreground big sprite at no cost for the main process. To synchronise the position between the main process screen and the dll screen it would be important to know how to use correctly the screencontrol set and get. That's where I am :)
badidea
Posts: 1354
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Problem when using GetWindowPos (screencontrol) without a sleep after SetWindowPos

Postby badidea » Dec 30, 2018 14:46

Tourist Trap wrote:In fact, it was just an idea that I will probably not use. I'm thinking of adding a blob (a big sprite) thanks to the second screen allowed when you call a screenres from a dll. If it's a shaped window, it could be a good foreground big sprite at no cost for the main process. To synchronise the position between the main process screen and the dll screen it would be important to know how to use correctly the screencontrol set and get. That's where I am :)

I hope you understand what you want, because I don't understand any of the above :-)
But it sounds like you need an fb.image (via ImageCreate).
Tourist Trap
Posts: 2756
Joined: Jun 02, 2015 16:24

Re: Problem when using GetWindowPos (screencontrol) without a sleep after SetWindowPos

Postby Tourist Trap » Dec 30, 2018 15:05

badidea wrote:I hope you understand what you want, because I don't understand any of the above :-)
But it sounds like you need an fb.image (via ImageCreate).

Ahah, in fact I'm using images of course, but I'm justwondering if I wont put too much stuff at screen for my main loop. It's just speculation because I have not my game world ready for testing right now. In any case, we can easily put a second screen to deal with something like weather effect say, or big elements we don't want to blit in the main loop.
You will understand the idea if you jump to this thread:
viewtopic.php?f=8&t=24780&p=221230#p221230

As I said, I don't think I will use the trick for now. But if I had so, the problem with the screencontrol set\get would become annoying.
badidea
Posts: 1354
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Problem when using GetWindowPos (screencontrol) without a sleep after SetWindowPos

Postby badidea » Dec 30, 2018 15:19

I have not read the other topic yet, but made something funny:

Code: Select all

#include "fbgfx.bi"

const as integer SW = 800, SH = 600
screenres SW, SH, 32
var pImageBg = imagecreate(SW * 2, Sh * 2, 0)
var pImageFg = imagecreate(SW * 2, Sh * 2, &h00ff00ff)
dim as integer i, x, y, r
for i = 0 to 99
   x = int(rnd * SW * 2)
   y = int(rnd * SH * 2)
   r = int(rnd * 100) + 20
   circle pImageBg, (x, y), r \ 2, &h0000AA77
   circle pImageFg, (x, y), r, &h000077AA
next
dim as single a
dim as double t = timer
dim as integer fps = 0, lastFps = 0
while not multikey(1)
   x = cos(a) * 200
   y = sin(a) * 200
   screenlock
   put (0, 0), pImageBg, (x + 300, y + 300)-step(SW-1, SH-1), pset
   put (0, 0), pImageFg, (-x + 300, -y + 300)-step(SW-1, SH-1), trans
   locate 1,1: print lastFps
   screenunlock
   a += .005
   fps += 1
   if timer > t + 1 then
      t = timer
      lastFps = fps
      fps = 0
   end if
   sleep 16
wend

with sleep 1, I get ~470 fps, so at 60 fps enough time for other stuff.
Tourist Trap
Posts: 2756
Joined: Jun 02, 2015 16:24

Re: Problem when using GetWindowPos (screencontrol) without a sleep after SetWindowPos

Postby Tourist Trap » Dec 30, 2018 15:49

badidea wrote:with sleep 1, I get ~470 fps, so at 60 fps enough time for other stuff.

With sleep 1, I get 65 fps here ..
badidea
Posts: 1354
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Problem when using GetWindowPos (screencontrol) without a sleep after SetWindowPos

Postby badidea » Dec 30, 2018 16:24

Tourist Trap wrote:
badidea wrote:with sleep 1, I get ~470 fps, so at 60 fps enough time for other stuff.

With sleep 1, I get 65 fps here ..

Probably because your OS does not do sleep 1 by default but 15.6 ms.
It can be changed, see e.g.: viewtopic.php?f=15&t=27219&start=15#p255498 and https://docs.microsoft.com/en-us/window ... eginperiod
Tourist Trap
Posts: 2756
Joined: Jun 02, 2015 16:24

Re: Problem when using GetWindowPos (screencontrol) without a sleep after SetWindowPos

Postby Tourist Trap » Dec 30, 2018 16:51

badidea wrote:
Tourist Trap wrote:
badidea wrote:with sleep 1, I get ~470 fps, so at 60 fps enough time for other stuff.

With sleep 1, I get 65 fps here ..

Probably because your OS does not do sleep 1 by default but 15.6 ms.
It can be changed, see e.g.: viewtopic.php?f=15&t=27219&start=15#p255498 and https://docs.microsoft.com/en-us/window ... eginperiod

Oh thank you! I missed that. So now sleep 1 is meaning about 480 fps. Not bad.
Weirdly, if I use 999 rather than 99 circles before the loop, I loose 100 fps...
When I use 99999 , this means not black color left, my fps is again around 500.
badidea
Posts: 1354
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Problem when using GetWindowPos (screencontrol) without a sleep after SetWindowPos

Postby badidea » Dec 30, 2018 17:00

Tourist Trap wrote:Weirdly, if I use 999 rather than 99 circles before the loop, I loose 100 fps...
When I use 99999 , this means not black color left, my fps is again around 500.

I don't see a large difference here.
The put pImageFg using 'transparency' will be a bit slower I think, more to draw. But that does not explain the 99999 case.
Tourist Trap
Posts: 2756
Joined: Jun 02, 2015 16:24

Re: Problem when using GetWindowPos (screencontrol) without a sleep after SetWindowPos

Postby Tourist Trap » Dec 30, 2018 17:09

badidea wrote:The put pImageFg using 'transparency' will be a bit slower I think, more to draw. But I don't see a large difference here.

Right, if I pset all, I can reach 600 now. Really interesting.
badidea wrote:But that does not explain the 99999 case.

No it's understandable. Too much circle son no room left for transparency. That's the case with a little number of circles that shouldn't be so fast. This, I don't see why with trans.
badidea
Posts: 1354
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Problem when using GetWindowPos (screencontrol) without a sleep after SetWindowPos

Postby badidea » Dec 30, 2018 17:49

I don't know. The main point is that with sleep 1 and 500 fps, the cpu (1 core) is 50% sleeping, 50% active.
This is confirmed by my system monitor, although the cores seem to take turns here.
At 60 fps, the drawing load would be less then 10% leaving enough cpu power for other stuff.
A custom version of put, using a screenPtr and imagePtr, will probably be even faster.
Flipping screen pages might improve speed some more. Less stuff needed between screenlock/unlock.

Return to “General”

Who is online

Users browsing this forum: No registered users and 1 guest