I am implementing a semi- scientifically correct dynamic weather system in bp only, converting everything back to bp
Edit: Scratch all … For performance reasons I will have to move all the heavy code to c++, and expose the controlling logic to bp. While a .7 second c++ loop, vs a 2 second bp loop is not bad, since needs to run real time every second, wont work. Also considering the major speed improvements I made (2 sec per loop) to get to run fast in blueprints can also be transfered to c++, so hopefully I can get to run .2 seconds per 1 second of simulation, so there is room for everything else.
using .2 of a second for a fully dynamic and scientifically semi-acurate weather system is not a bad deal.
Edit: c++ code now runs .35 ~ .38 sec loops
[ATTACH=JSON]{“data-align”:“none”,“data-size”:“medium”,“data-tempid”:“temp_130010_1519075049667_801”}[/ATTACH]
Edit!!! now at .2 sec loops!!!:
< - - - - - Yes, thats 100 seconds of weather simulation done in 20!
Edit : .18 seconds per 1 second of weather simulation, i’m starting to lean into micro optimizations, so its time to move on! (5 year old computer anyways, should perform great!)
Pics or it didn’t happen:
As you can tell its loop/math/array heavy, but there were MANY optimizations I made to do in bp.
-
Math expression nodes are your friend for heavy math in BP
-
Array variables that were accessed more than 2x per loop were given a variable (saved a few million get/set iterations!)
-
Since we are using a 3D->FlatArray, everything is coded with “Array Indexes” aka pointers, the original code, calculated the array column index EVERY SINGLE TIME a get or set to the array was done, I removed all of them and setup “precomputed” indexes that only ran 1x per loop, vs hundreds per loop
-
Code that didn’t do anything was removed (really… there were a few spots that NEVER hit a break-point)
-
Variables in loops that were set with a value from an array, and used only once… removed (1 get is cheaper than get/set/get)
-
Removed 8+ loops:
-
3 of the 4 major loops used a xloop -> yloop -> zloop setup, but I realized, the calculated “array index” ended up being sequential, so I used a single loop in place.
-
The 4th major loop does , but has moments where it calls (x-1, y, z), in which case there is a “torridial” function that wraps the columns and rows (can’t have negative indexes!) so there is limited optimizing here…
-
There were values calculated and then a conditional that would set the value again, those were reversed, as we should check n set before blindly calculating… 1x check n set vs 1x set, check, and maybe set again)
-
Direct references were used everywhere, to reduce overhead of copies
Each major loop totals to about 5200, so about 28,000 loops in total per ONE “second” of simulation
When all is said and done, the end user shall not have to worry about anything, but setting the time/day/lat/long. Which is already used by the project time manager… everything else will be in a nested blueprint, so there is no clutter when working with the blueprint.
Just added a picture of the updated Step1, notice the use of math expressions, the removal of two loops,and how much cleaner looks (Not to mention the editor no longer lags for a few seconds over trivial changes like it used to when inside function)