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

make the game faster when player sleep near the tree #73590

Merged
merged 2 commits into from
May 10, 2024

Conversation

GuardianDll
Copy link
Member

Summary

None

Purpose of change

fix #73552

Describe the solution

Apply suggested fix

Testing

Compiled, slept afar from tree
image
slept near the tree
image
booted up unedited version of the game, sleept near the tree, dropped it because it was like 1:1 real time to game time ratio

Additional context

Pure magic to me ngl

Co-authored-by: RenechCDDA <84619419+RenechCDDA@users.noreply.github.com>
@fairyarmadillo
Copy link
Contributor

fairyarmadillo commented May 8, 2024

I think the intention with the cache weirdness was to ensure that vision radius changed as soon as the player crouched or went prone next to a piece of cover, as these actions don't take any time. It would be inappropriate for them to only update one second later after the player passed a turn or something.

I don't have time to compile your PR to test it but you may want to make sure that's still working as intended.

@github-actions github-actions bot added [C++] Changes (can be) made in C++. Previously named `Code` <Bugfix> This is a fix for a bug (or closes open issue) labels May 8, 2024
@GuardianDll
Copy link
Member Author

i just tested, and no, even in vanilla, vision cache is invalidated one move after going prone:
Vanilla:
GIF 08-05-2024 22-44-46
This PR:
GIF 08-05-2024 22-46-33

@fairyarmadillo
Copy link
Contributor

Thanks for checking for me. That's a separate issue then, and not something that matters for this PR.

I swear it used to happen on the same turn.

@github-actions github-actions bot added astyled astyled PR, label is assigned by github actions json-styled JSON lint passed, label assigned by github actions labels May 8, 2024
@IdleSol
Copy link

IdleSol commented May 8, 2024

You may have already seen it. The topic offered another solution to the problem. More precisely, they added a condition for checking.

@GuardianDll
Copy link
Member Author

actually i did miss the second Ren suggestion, i'll check it now

@Brambor Brambor added the Code: Performance Performance boosting code (CPU, memory, etc.) label May 8, 2024
@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label May 9, 2024
@RenechCDDA
Copy link
Member

RenechCDDA commented May 9, 2024

Per #73552 (comment) my safer suggestion was flawed as the static was never reassigned. Let's try this one more time!

index bbe88a5b40..aa07232763 100644
--- a/src/lightmap.cpp
+++ b/src/lightmap.cpp
@@ -212,6 +212,7 @@ bool map::build_vision_transparency_cache( const int zlev )
     bool low_profile = player_character.has_effect( effect_quadruped_full ) &&
                        player_character.is_running();
     bool is_prone = player_character.is_prone();
+    static move_mode_id previous_move_mode = player_character.current_movement_mode();
 
     for( const tripoint &loc : points_in_radius( p, 1 ) ) {
         if( loc == p ) {
@@ -219,8 +220,12 @@ bool map::build_vision_transparency_cache( const int zlev )
             vision_transparency_cache[p.x][p.y] = LIGHT_TRANSPARENCY_OPEN_AIR;
         } else if( ( is_crouching || is_prone || low_profile ) && coverage( loc ) >= 30 ) {
             // If we're crouching or prone behind an obstacle, we can't see past it.
-            vision_transparency_cache[loc.x][loc.y] = LIGHT_TRANSPARENCY_SOLID;
-            dirty = true;
+            if( vision_transparency_cache[loc.x][loc.y] != LIGHT_TRANSPARENCY_SOLID ||
+                previous_move_mode != player_character.current_movement_mode() ) {
+                previous_move_mode = player_character.current_movement_mode();
+                vision_transparency_cache[loc.x][loc.y] = LIGHT_TRANSPARENCY_SOLID;
+                dirty = true;
+            }
         }
     }
 

@IdleSol
Copy link

IdleSol commented May 9, 2024

You update the value previous_move_mode 21+ times per game turn.

@GuardianDll
Copy link
Member Author

i'll compile and test it later

@GuardianDll GuardianDll marked this pull request as draft May 9, 2024 12:05
@GuardianDll
Copy link
Member Author

@RenechCDDA nope, third attempt do not resolve the bug either
image

@RenechCDDA
Copy link
Member

@RenechCDDA nope, third attempt do not resolve the bug either

Here's what I get on master:
image

and after applying the patch:
image

@RenechCDDA
Copy link
Member

Profiling before:
image

And after:
image

And you might think our additions inside map::build_vision_transparency_cache are themselves a problem. Nope! It's all the memcpy.
image

@GuardianDll
Copy link
Member Author

Do you mean something is wrong with my test method or compiling?

@RenechCDDA
Copy link
Member

I would absolutely ask you to double-check what code you compiled, maybe even do a fresh rebuild to be 200% sure there's no compiler junk going on.

@GuardianDll GuardianDll marked this pull request as ready for review May 10, 2024 19:51
@GuardianDll
Copy link
Member Author

After complete rebuild confirmed the suggestion worsk as expected
image

@I-am-Erk
Copy link
Member

This is the one we discussed on discord right? Kevin didn't seem to think it was a problem, and it's passing the test, so let's see what happen, and if someone set up us the bomb.

@I-am-Erk I-am-Erk merged commit 0c564ce into CleverRaven:master May 10, 2024
23 of 33 checks passed
@GuardianDll GuardianDll deleted the tree_sleep branch May 11, 2024 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Code: Performance Performance boosting code (CPU, memory, etc.) json-styled JSON lint passed, label assigned by github actions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Trying to fall asleep next to a tree is incredibly slow, but waiting is not
6 participants