Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frames are skipping #21

Closed
JuniorDjjr opened this issue Dec 6, 2021 · 11 comments
Closed

Frames are skipping #21

JuniorDjjr opened this issue Dec 6, 2021 · 11 comments
Labels
type:bug Something isn't working

Comments

@JuniorDjjr
Copy link

https://youtu.be/_crRD00DPIM

The movement should be smooth, after all, I'm using wait 0.

{$cleo}
0000:

while true
    wait 0      

    if 0C00: key_pressed 89 //y
    then
        04C4: store_coords_to 11@ 12@ 13@ from_actor $PLAYER_ACTOR with_offset 0.0 1.0 0.0
        00A1: put_actor $PLAYER_ACTOR at 11@ 12@ 13@
    end  
    if 0C00: key_pressed 72 //h
    then
        04C4: store_coords_to 11@ 12@ 13@ from_actor $PLAYER_ACTOR with_offset 0.0 -1.0 0.0
        00A1: put_actor $PLAYER_ACTOR at 11@ 12@ 13@
    end
    
end
@x87
Copy link
Contributor

x87 commented Dec 6, 2021

Does it happen when you run the same script in main.scm?

(note that 0C00 won't work in main.scm, but you can use widget keys for testing)

@JuniorDjjr
Copy link
Author

I haven't tested it, but now I better understand the cause of the problem.

Try making 100 copies of this line:
04C4: store_coords_to 11@ 12@ 13@ from_actor $PLAYER_ACTOR with_offset 0.0 1.0 0.0
And hold Y.
The script will be slower to process, as a result, it takes around 3 seconds to process the loop and take effect.

It's like a lazy processing, I don't know. The longer the script, the longer it takes to process. Quickly takes a matter of seconds.

@x87
Copy link
Contributor

x87 commented Dec 6, 2021

this is expected, no? the game runs scripts in the main loop, which means while it executes opcodes it can't render a new frame. this is why we have wait command to put the script on hold and let the game finish rendering the frame. the more opcodes you add in between wait commands, the slower things are.

@JuniorDjjr
Copy link
Author

JuniorDjjr commented Dec 6, 2021

But that's not how script execution works, just when "wait" is read the next game frame is executed.
You can loop 10,000 commands, the game will never skip frames.

This is for PC:

{$cleo}
0000:

while true
    wait 0
    
    if 0AB0:   is_key_pressed 89 //y, PC opcode
    then
        0@ = 0
        while 0@ < 10000
            0@ += 1
            0099: 1@ = random_int_in_ranges_0_to_32767 // just to make it slower
        end
        04C4: store_coords_to 11@ 12@ 13@ from_actor $PLAYER_ACTOR with_offset 0.0 -10.0 0.0
        00A1: put_actor $PLAYER_ACTOR at 11@ 12@ 13@
    end
    
end

I lowered this script to only 1,000 iterations, tested it on SA:DE, pressed Y and the game ran for over 1 minute until it took effect. One possibility is that each command read, is executed 1 "wait 0" (roughly saying, to understand it). This script above would take more than 10 minutes to take effect in SA:DE.

@x87
Copy link
Contributor

x87 commented Dec 6, 2021

Can you test the same on pure main.scm?

@JuniorDjjr
Copy link
Author

It works correctly on main.scm, the movement is smooth.
Using this stripped from Zaz:

DEFINE OBJECTS  1
DEFINE OBJECT (dummyobject) // This is an unused object. You can put anything here.

DEFINE MISSIONS  0

DEFINE EXTERNAL_SCRIPTS  -1

DEFINE UNKNOWN_EMPTY_SEGMENT  0

DEFINE UNKNOWN_THREADS_MEMORY  0

//-------------MAIN---------------


:MAIN_1
03A4: name_thread 'MAIN'
016A: fade  0 (in)  0 ms
042C: set_total_missions_to  0
030D: set_total_mission_points_to  0
01F0: set_max_wanted_level_to  6
0111: set_wasted_busted_check_to  0 (disabled)
00C0: set_current_time  23  0

04E4: unknown_refresh_game_renderer_at  2494.5 -1668.5
03CB: set_camera  2494.5 -1668.5 13.4
0053: $PLAYER_CHAR = create_player #NULL at  2494.5 -1668.5 13.4
07AF: $PLAYER_GROUP = player $PLAYER_CHAR group
01F5: $PLAYER_ACTOR = create_emulated_actor_from_player $PLAYER_CHAR
0173: set_actor $PLAYER_ACTOR z_angle_to  7.0
0373: set_camera_directly_behind_player
070D: $PLAYER_CHAR
0629: change_stat  181 (islands unlocked) to  4  // integer see statdisp.dat
01B6: set_weather  1
04BB: select_interior  0  // select render area
01B4: set_player $PLAYER_CHAR frozen_state  1 (unfrozen)
01B7: release_weather
016C: restart_if_wasted at  2494.5 -1668.5 13.4 angle  180.0 unknown  0
016D: restart_if_busted at  2494.5 -1668.5 13.4 angle  180.0 unknown  0
016A: fade  1 (out)  1000 ms
0001: wait  100 ms
03E6: remove_text_box
0180: set_on_mission_flag_to $ONMISSION // Note: your missions have to use the variable defined here

:MAIN_3
0001: wait 0 ms

0@ = 0
while 0@ < 100
    0@ += 1
    0099: 1@ = random_int_in_ranges_0_to_32767 // just to make it slower
end

04C4: store_coords_to 11@ 12@ 13@ from_actor $PLAYER_ACTOR with_offset 0.0 10.0 0.0
00A1: put_actor $PLAYER_ACTOR at 11@ 12@ 13@

        
0002: jump @MAIN_3

@x87
Copy link
Contributor

x87 commented Dec 6, 2021

I can confirm the player movement is smooth on main.scm and jerking on cleo. I will look into what may cause it

@x87 x87 added the type:bug Something isn't working label Dec 6, 2021
@XMDS
Copy link
Member

XMDS commented Dec 7, 2021

Remove wait 0 and it will become faster. I mentioned this problem before, but there is no time to study in these two days.

@x87
Copy link
Contributor

x87 commented Dec 7, 2021

@XMDS Loops must have wait command. It's actually a CLEO bug and a critical one, I must say.

@JuniorDjjr thanks for providing a test script and hinting the main.scm behavior. I was able to identify and fix the problem. Check the new dev build on discord.

@JuniorDjjr
Copy link
Author

It's working perfectly now, I was able to create a free camera mod without any problems.

Taking the advantage, a minor issue: 007B: in Sanny Builder for "SA Mobile" is written = instead of +=

@x87
Copy link
Contributor

x87 commented Dec 9, 2021

fixed in 0.8.3

@x87 x87 closed this as completed Dec 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants