Jump to content
Jab

[Java] [Performance] - RNG Mod

Recommended Posts

In light of the 32 build and playing various challenges and additions to the game, I noticed some performance issues on my end, due to my aging computer. 

 

Fortunately, I found a method to somewhat alleviate some of the processing load of the game through something called a RNG, (Random-Number Generator). This is what gives Project Zomboid a nice randomness in the way things work throughout the game, from lighting, to zombie spawning, to zombie reactions, to the damage you inflict on things. 

 

What Project Zomboid uses is a high-level RNG, which not only gives a less predictable output, but also in a more encrypted manner. These kinds of RNGs work best in high-level security password / account management, Gambling game websites, or other needs that require less prediction. 

 

What I've learned is that these really high level RNGs, (although less predictable and more true to random), is that they take a lot more to process than your medium or low RNGs. These are costly to performance on realtime calculations if used frequently.

 

I did some research back in build 30 on what RNGs work best in a situation such as a game like Project Zomboid, and have found the XORShift 128 algorithm to hold the most ground when it comes to medium-level RNGs. 

 

So I went ahead and replaced the RNG that Project Zomboid uses with an implementation of this RNG. I personally noticed some positive results from this experiment in Build 30. When I experienced performance issues when playing the "Opening Hours" challenge in Build 32, I decided to test it again. I still noticed the same results. 

 

For me, it felt like the rendering was smoother, and the world simulation was more fluid, with less jolting.

 

So in light of all of this, I decided to package this very simple modification to the game and allow others to try it out for themselves.

 

Feel free to try this out and tell me what you think.

 

One thing to note Is that there might be simulation differences between this random and the random used in the multiplayer simulation. When I played with this mod on build 30 servers, It was raining for me, when it was not for other players. This may be due to a simple RNG difference. No problem though.

 

If you install this mod, please be sure to copy your 'zombie' folder in your main PZ folder. The mod is JAVA, so this affect the game's direct code, not like LUA.

 

Let me know how this feels. I'd like to see if this improves the performance. I'm curious.

 

 

P.S. For transparency: Here's the class model I implemented for you tech-savy people who want to see how this algorithm works. It's neat. (This class involves no code from the game directly, so this is not showing, exposing, or infringing on the game's code's rights.) 

 

Code: https://raw.githubusercontent.com/JabJabJab/SledgeHammer/master/src/com/badlogic/gdx/math/RandomXS128.java?token=ABAbyfyCPK5t0Cfyrphcw3mYYC4ZTR2nks5VeNfLwA%3D%3D

 

 

Download: https://dl.dropboxusercontent.com/u/31589881/Zomboid/rngmod.zip

Share this post


Link to post
Share on other sites

Let's get technical - it's a PRNG as far as RNGs go. (The P is for pseudo, in any algorithms course you'll lose marks for claiming proper randomness, when it's not)  ;)

 

Good stuff on the 'mod' though, it'll be interesting to see how many people feel a performance change with this!

Share this post


Link to post
Share on other sites

Is the RNG also for the item spawns (Location, Amount)?

 

Anything that uses this random implementation in the entire game, will be using the one I replaced the original one with. 

 

I haven't noticed anything beyond multiplayer rain different, (but there may be more.) I would say that this mod is best fit for single-player experience / performance upgrade, because it's all calculated on your end. :) 

Share this post


Link to post
Share on other sites

Noting the lighting issues discussed in the mondoid this week, I have re-tested this mod, and it still works for build 33.

 

I notice a difference in the lighting system. It works smoother for me.

 

Let me know if this mod makes a difference for you. I'm quite curious.

 

 

(This mod uses a a much faster PRNG than the game, decreasing calculation time in any code that uses random calculation with the currently-used PRNG)

Share this post


Link to post
Share on other sites

I seems to work fine on 34.28 (haven't encounter stutter so far) , although I hadn't test it long enough, because it produced lots of repeated errors:

 

-----------------------------------------
STACK TRACE
-----------------------------------------
Callframe at: se.krka.kahlua.integration.expose.MultiLuaJavaInvoker@2b321921
function: null -- file: MusicChoices.lua line # 85
function: trigger -- file: SadisticMusicDirector.lua line # 81
function: tick -- file: SadisticMusicDirector.lua line # 11
function: tick -- file: SadisticAIDirector.lua line # 42
function: update -- file: SadisticAIDirector.lua line # 270
function: run -- file: SadisticAIDirector.lua line # 313
Caused by: java.lang.IllegalArgumentException: n must be positive
	at zombie.core.RandomXS128.nextLong(RandomXS128.java:158)
	at zombie.core.RandomXS128.nextInt(RandomXS128.java:139)
	at zombie.core.Rand.Next(Rand.java:29)
	at zombie.Lua.LuaManager$GlobalObject.ZombRand(LuaManager.java:3240)
	... 21 more

 

 

Edited by curi0
Remove unrelated errors

Share this post


Link to post
Share on other sites
9 hours ago, curi0 said:

I seems to work fine on 34.28 (haven't encounter stutter so far) , although I hadn't test it long enough, because it produced lots of repeated errors:

 


-----------------------------------------
STACK TRACE
-----------------------------------------
Callframe at: se.krka.kahlua.integration.expose.MultiLuaJavaInvoker@2b321921
function: null -- file: MusicChoices.lua line # 85
function: trigger -- file: SadisticMusicDirector.lua line # 81
function: tick -- file: SadisticMusicDirector.lua line # 11
function: tick -- file: SadisticAIDirector.lua line # 42
function: update -- file: SadisticAIDirector.lua line # 270
function: run -- file: SadisticAIDirector.lua line # 313
Caused by: java.lang.IllegalArgumentException: n must be positive
	at zombie.core.RandomXS128.nextLong(RandomXS128.java:158)
	at zombie.core.RandomXS128.nextInt(RandomXS128.java:139)
	at zombie.core.Rand.Next(Rand.java:29)
	at zombie.Lua.LuaManager$GlobalObject.ZombRand(LuaManager.java:3240)
	... 21 more

 

 

 

Yeah this mod is out of date. I'll need to update.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...