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:
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.