Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (Quad, VoroneTZ, 1 invisible), 648 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, 11honza11, ccorrea, sakolin, rajesh7827
19046 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Latency of value assignment in loop with wait #462391
09/26/16 17:45
09/26/16 17:45
Joined: Sep 2009
Posts: 993
Budapest
Aku_Aku Offline OP
User
Aku_Aku  Offline OP
User

Joined: Sep 2009
Posts: 993
Budapest
I tried to make a code that is able to move a panel with mouse drag.
I was surprised when turned out there is a latency of value assignment in loop with wait.
Here is a sample code:
Code:
function drag_panel(PANEL* inPanel) {
	int old_x;
	int old_y;
	int dif_x,  dif_y;
	diag("\ndrag_panel");
	old_x = mouse_cursor.x;
	old_y = mouse_cursor.y;
	while(mouse_left) {
		diag_var("\nold_x:%4.0f", old_x);
		diag_var("\nold_y:%4.0f", old_y);
		dif_x = mouse_cursor.x - old_x;
		dif_y = mouse_cursor.y - old_y;
		if(0 != dif_x || 0 != dif_y) {
			old_x = mouse_cursor.x;
			old_y = mouse_cursor.y;
			diag_var("\nmouse_pos.x:%4.0f", mouse_cursor.x);
			diag_var("\nmouse_pos.y:%4.0f", mouse_cursor.y);
			inPanel.pos_x += dif_x;
			inPanel.pos_y += dif_y;
			diag_var("\nnew old_x:%4.0f", old_x);
			diag_var("\nnew old_y:%4.0f", old_y);
		}
		wait(1);
	}
}


The content of the old_x and the old_y variables will be changed after 15-30 frames. It is strange.
I read the wait documentation, but i can't find out why the heck is working this way..
What is the reason? What should be the solution?
What a pity, lite-c has no option to declare volatile variables.

Re: Latency of value assignment in loop with wait [Re: Aku_Aku] #462402
09/27/16 16:03
09/27/16 16:03
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
What do you mean with 15-30 frames delay? How are you measuring that delay?
Or do you mean the visible delay when you drag a panel - assuming you use the Windows mouse pointer and not mouse_map?


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Latency of value assignment in loop with wait [Re: Superku] #462418
09/28/16 18:38
09/28/16 18:38
Joined: Sep 2009
Posts: 993
Budapest
Aku_Aku Offline OP
User
Aku_Aku  Offline OP
User

Joined: Sep 2009
Posts: 993
Budapest
I opened the acklog.txt file.
I saw in there, if the mouse_cursor position was changed,
my loop 15-30 times run while the new position value appeared as the value in variable, where that should displayed at the first run.
So i ment the delay is this: the variable should show the new position value at the first run of the cycle, not after 15-30.
Please assume that, i used the mouse_cursor as it can be see in the code. By the way this thing impacts visually not on the pointer, that was ok, but on the panel that i tried to move, that moved like a fool.

Re: Latency of value assignment in loop with wait [Re: Superku] #462419
09/28/16 18:53
09/28/16 18:53
Joined: Sep 2009
Posts: 993
Budapest
Aku_Aku Offline OP
User
Aku_Aku  Offline OP
User

Joined: Sep 2009
Posts: 993
Budapest
For the record, here is the well working code:
Code:
function drag_panel(PANEL* inPanel) {
	int old_x;
	int old_y;
	int dif_x,  dif_y;
	diag("\ndrag_panel");
	old_x = inPanel.pos_x - mouse_cursor.x;
	old_y = inPanel.pos_y - mouse_cursor.y;
	while(mouse_left) {
		diag_var("\nold_x:%4.0f", old_x);
		diag_var("\nold_y:%4.0f", old_y);
		dif_x = inPanel.pos_x - mouse_cursor.x - old_x;
		dif_y = inPanel.pos_y - mouse_cursor.y - old_y;
		if(0 != dif_x || 0 != dif_y) {
			diag_var("\nmouse_pos.x:%4.0f", mouse_cursor.x);
			diag_var("\nmouse_pos.y:%4.0f", mouse_cursor.y);
			inPanel.pos_x += dif_x;
			inPanel.pos_y += dif_y;
			diag_var("\ndif_x:%4.0f", dif_x);
			diag_var("\ndif_y:%4.0f", dif_y);
		}
		wait(1);
	}
}


You can see old_x is computed only one time, before the start of the loop.
So, it can be reused again and again because it wouldn't changed while the cycle runs.

Re: Latency of value assignment in loop with wait [Re: Aku_Aku] #462431
09/29/16 10:55
09/29/16 10:55
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
I was asking for the mouse pointer/ mouse_map because there is a visible delay between the Windows (!) mouse pointer, the white arrow or "hand", and the in-game mouse_cursor/_map positions.
When you only use the former and don't set mouse_map instead, this can lead to a visible delay between the mouse cursor and the window that's being dragged, especially on low framerates.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Latency of value assignment in loop with wait [Re: Superku] #462437
09/29/16 18:56
09/29/16 18:56
Joined: Sep 2009
Posts: 993
Budapest
Aku_Aku Offline OP
User
Aku_Aku  Offline OP
User

Joined: Sep 2009
Posts: 993
Budapest
OK i understand you. Thank for your helping will.
But the latency was manifested in the value assignment.

Re: Latency of value assignment in loop with wait [Re: Aku_Aku] #462438
09/29/16 19:09
09/29/16 19:09
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
To be honest, I don't really believe that there's any latency when assigning values.
If you write "var x = y;" then after this line of code has been executed x has the same value as y. I don't see how there can be any delay.. programming like that just wouldn't make any sense.

If I had to guess it's diag_var() causing some delay.

Last edited by Kartoffel; 09/29/16 19:11.

POTATO-MAN saves the day! - Random
Re: Latency of value assignment in loop with wait [Re: Kartoffel] #462439
09/29/16 19:18
09/29/16 19:18
Joined: Sep 2009
Posts: 993
Budapest
Aku_Aku Offline OP
User
Aku_Aku  Offline OP
User

Joined: Sep 2009
Posts: 993
Budapest
Quote from the Online Manual.
A remark in the description of the wait statement:
Quote:
While a function is waiting, all other functions - including the calling function - continue to run in parallel, so all global variables and all pointers except my and you can possibly change during the wait time. !! While the content of local variables is preserved, their addresses change after every wait() because the function runs every time in a different stack frame.

Please concentrate on the part that deals with local variables.
I think that could be the reason. Or a glitch in the Acknex engine.
Who knows?
Finally, you have the option to try out, in your own code. Or try with my code that i attached in my opening post.

Last edited by Aku_Aku; 09/29/16 19:20.
Re: Latency of value assignment in loop with wait [Re: Aku_Aku] #462440
09/29/16 20:06
09/29/16 20:06
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Well as long as I'm not misinterpreting that quote, this only applies to local pointers. However, in your code you're not using any pointers confused
Have you tried it with something other than diag_var (like DEBUG_VAR, for example)?

Last edited by Kartoffel; 09/29/16 20:07.

POTATO-MAN saves the day! - Random
Re: Latency of value assignment in loop with wait [Re: Kartoffel] #462442
09/29/16 22:57
09/29/16 22:57
Joined: Sep 2009
Posts: 993
Budapest
Aku_Aku Offline OP
User
Aku_Aku  Offline OP
User

Joined: Sep 2009
Posts: 993
Budapest
I think the "local variables" are not only pointers...

Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1