Jump to content
zorrobyte

ZBE_Cache AI & Vehicle caching script/addon

Recommended Posts

ZBE_Caching

License:

ZBE_Caching by Zorrobyte is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Based on a work at https://bitbucket.org/zorrobyte/zbe_cache.

https://creativecommons.org/licenses/by-sa/4.0/

Features:

  • Caches AI, all but teamleader so group still moves (tested: 25%+ FPS gain DUWS)
  • Caches empty vehicles (tested: 2385 vehicles 4 FPS no cache, 49 FPS cache)
  • Uncaches AI for players and other enemy AI groups
  • Compatible with virtually every addon and script (including HETMAN/HAL, bCombat, ASR_AI)
  • Per group/vehicle FSM which is performance friendly and fast
  • Enable/Disable caching for a specific group at anytime
  • Cached AI units in group are setPOS(moved) to TL's position so they can still receive damage from artillery, bombs, etc
  • Units that die while cached are uncached and removed from the caching loop
  • If the group leader dies while group is cached, the next group leader is uncached
  • Cached empty vehicles can still receive damage and display damage/explosions
  • Useful RPT/hintSilent debug option

Requirements:

Addon NO LONGER requires CBA as of v4.4b

Addon and script now work the same as of v4.4b. Run script in mission or use addon on server only.

Changelog:

v4.6a

  • Improved performance of sleep state condition to minimize operations per frame

v4.6

  • Moved functions from FSM to zbe_functions.sqf with compilefinal
  • Empty vehicle scanning set to 15 second sleep (instead of 5)
  • Fixed cached AI and vehicle debug counts by using simulationEnabled (100% accurate now)
  • Fixed Error 0 elements provided, 3 expected setPOS RPT spam
  • Moved switchableUnits + playableUnits array to 15 second main.sqf loop instead of in FSM
  • Added _trandomc/u variable in FSM for a randomized FSM sleep for less concurrent calculations
  • Minimized evaluations for zbe_setPosLight/Full
  • Fixed empty vehicle FSM as was using True conditions instead of conditions
  • Fixed next leader uncache condition as was missing variable to set the new leader in the FSM causing it to loop constantly
  • Removing dead is now higher priority in FSM

v4.5c

  • Edited count vehicles to count "real vehicles" (discarding odd objects in the map) - Thanks to Zriel
  • Introduced zbe_mapSide for counting nearentities in vehicles, boats and air...better performance in small maps (even in Altis, Original 0.095594MS vs NEW 0.0928986MS with 585 cars) - Thanks to Zriel
  • Synced changes between Addon and Script version so they are now identical
  • Tweaked sleep time between FSM state checking to combat suspected CPS drop
  • FSM now immediately exits for NULL groups

v4.5b

  • Readded hideobjectglobal as if not when hits FPS limiter then cached units will glitch around
  • Fixed empty vehicle arrays, now FSM only runs one time per vehicle instead of spamming FSM loops constantly
  • Tabbed files
  • Fixed allVehicle count
  • Slight debug hint change

V4.4c

  • Added per vehicle type caching distance setting (Car,Air,Boat)
  • Fixed missing }; for script version
  • Don't forget to update userconfig if using addon!

v4.4b

  • Changed setPosASL back to setPos so units don't uncache outside buildings unexpectedly thanks to Zriel
  • Improved debug readability thanks to whiztler
  • Changed debug loop condition thanks to Pepe Hal
  • Removed "Dedicated/Client" FSM segementation and now only using a single FSM for all as setPOS ran from multiple machines causes mayhem thanks to Zriel
  • Stopped calling for map center's POS every loop thanks to Pepe Hal
  • Empty vehicle caching is now called from isServer using enableSimulationGlobal
  • Removed hideObject as no longer needed as units setPos to leader when cached
  • Changed zbe_centerPOS function to one time call instead of function
  • ZBE_Caching to ZBE_Cache for consistency
  • There is now no difference between the addon vs script version and addon only needs to be ran on server
  • CBA is no longer required, ever

v4.4a

  • Fixed next leader uncache loop, was repeating indefinitely in some cases

v4.4

  • Epicly faster performance! Rewrote cache and uncache conditions to be 25x faster. Now CPS is almost native to FPS (no more script lag). 144 groups 1153AI with 59.8CPS/60FPS
  • Bumped -1 auto FPS values to 16 dedi 31 client for a target of 15/30
  • Players continue to uncache always within distance set but now AI only uncache for other AI groups IF they are aware of each other (using findNearestEnemy). This keeps AI cached if they have nothing to shoot at and will lead to more overall AI being cached in AIvsAI missions
  • Cache FSM now exits for player led AI groups

v4.3

  • *Critical* FSM would not exit due to FSM condition states hating OR (||) and would loop forever causing poor performance over time and setPOS errors
  • Added debug switches for cache start/stop/unit died while cached/synced TL. Baretail Arma's RPT file in \AppData\Local\Arma 3\*.rpt

v4.2

  • Removed _orgSpeedMode (cleanup)
  • SetPosATL to SetPos for RPT spam fix (Client: Object 14:32 (type Type_89) not found.)
  • Resolved disableAI issue (did nothing) as was not implemented properly for dedicated server
  • zbe_vehicleCaching.fsm now uses 500ms delay between checking conditions for less load
  • Script version no longer uses enableSimulationGlobal/hideObjectGlobal to save packets as it is assumed it will be running on all localities. (Addon version still uses global commands so only the server can run addon, addon still doesn't do empty vehicle caching unless clients run addon as well)
  • Updated empty vehicle caching to 1000m until per vehicletype distance is added

v4.1

  • ZBE_Cache no longer uses setSpeedMode, the AI in your missions will proceed as your waypoints intend.
  • Changed setPos to setPos formationposition so group leaders move full speed (if speedMode "Normal"/"Full").
  • Changed zbe_setPos to zbe_setPosLight and zbe_SetPosFull. Light setPos formationPosition, Full setPos formationPosition with 3 second allowdamage false so units don't die on inclines when uncached.
  • zbe_aiCachingDedicated.fsm now uses disableai commands for additional performance savings. Client/Listen server does not as disableai can break animations
  • As a note if ran as an addon on server only, client's won't use empty vehicle caching. If your mission intends to have more than 100 empty vehicles, I strongly recommend using the script version

v4

  • Created new directory and rewrote from scratch
  • Caching now works per group using FSMs instead of iterating through allGroups array
  • Added back addon version (requires CBA)

Working on:

  • setPOS "resolution", user can set percentage from 0-100 to dictate how often cached units get moved to group leader per cycle as setPOS is global and sends packets.
  • Per vehicle type caching distance as 150m is good for cars but bad for planes (as ejecting units will mid air "freeze" aircraft) - done
  • Switch from spawn/scriptDone wait to native FSM wait by using FSM native command "time" - done for all FSM
  • Object caching FSM for ammoboxes, weapons, etc
  • Addon version without CBA requirement by using preInit = 1; in config.cpp - done

Installation for Addon version:

1. UnZIP @ZBE_Cache into Arma 3 directory

2. Move userconfig folder into Arma 3 directory (\Arma 3\@ZBE_Cache\userconfig -> \Arma 3\userconfig

3. Set desired options in userconfig (\Arma 3\userconfig\zbe_cache\zbe_cache.hpp)

4. Play the game

Installation for script version:

1. Extract contents of \@ZBE_Cache\zbe_cache_script_version to your mission folder. Do not overwrite your existing init.sqf if asked.

2. Open \@ZBE_Cache\zbe_cache_script_version\init.sqf and copy contents into \Documents\Arma 3\missions\missionName\init.sqf file.

3. Set desired options for ZBE_Cache in \Documents\Arma 3\missions\missionName\init.sqf.

Disable/Enable group caching:

Example for unit init from editor: (group this) setVariable ["zbe_cacheDisabled",true]

Broken down: *groupName* setVariable ["zbe_cacheDisabled",*true/false*]

Minimum FPS limiter:

Prevents AI from uncaching if FPS is below desired FPS. Even while the uncaching is being limited, the next group leader will uncache if the group leader dies.

Extras:

zbe_clientObjectDrawAuto.fsm is an experimental FSM to auto set client objectDrawDistance based on FPS and no higher than aiCachingRange so players will never see AI uncache. Please vote here if you would like this feature: http://feedback.arma3.com/view.php?id=21746

Community feedback:

The way the script works now is pretty impressive. I get stable 50 fps with approx 150-200 ai, before it dropped to around 35. And as I said, it is possible for me to give DAC ai custom weapons since I don't need to reduce groups. DAC for a3 in it's current state gives AI vanilla weapons when respawns them near their group leader. So only the group leader stays with custom weapon =) - Alexander

A3 Feedback Tickets resolved in relation

I first found that Physx wasn't disabled for enablesimulation false and was fixed:

http://feedback.arma3.com/view.php?id=18451

I then found AI enableimulation false wasn't good as it could be and was improved:

http://feedback.arma3.com/view.php?id=18734[/center]

Testing

"ZBE 144 Groups, 1145 Units, 17 NoCacheFPS, 51 CachedFPS, 59 DeletedFPS"

C_Offroad_01_F drops FPS to 28 no ZBE_Cache vs 59 FPS ZBE_Cache (600+/- spawned)

DWUS (http://www.armaholic.com/page.php?id=21816) 20%+/- FPS improvement

Here is a (lower quality, sorry) video showing how it works. I'll come up with a better video at some point.

http://youtu.be/ZF8RLjSl_tU

Known issues

Units inside vehicle do not cache due to A3 bug: A3 Issue Tracker

Report issues here

Download and Homepage

https://bitbucket.org/zorrobyte/zbe_cache/downloads

Edited by zorrobyte
  • Like 3
  • Thanks 1

Share this post


Link to post
Share on other sites

New mod v0.1 available at withSIX. Download now by clicking:

@zbe_cache.png

@ zorrobyte ;

Soon you will be able to manage the promo pages of your content on our web platform and publish new content yourself.

To do so, please hit 'this is me' button on the page while logged in and you will get connected to your work.

For now you can send new content or releases our way through withsix.wetransfer.com or add your notification at getsatisfaction.withsix.com.

Share this post


Link to post
Share on other sites
Guest

Release frontpaged on the Armaholic homepage.

================================================

We have also "connected" these pages to your account on Armaholic.

This means in the future you will be able to maintain these pages yourself if you wish to do so. Once this new feature is ready we will contact you about it and explain how things work and what options you have.

When you have any questions already feel free to PM or email me!

Share this post


Link to post
Share on other sites

Congratulations, will check it for sure.

Share this post


Link to post
Share on other sites

Will this have a positive impact in SP also? I usually create my own missions with editor.

Share this post


Link to post
Share on other sites

A couple of questions.

1. What does it mean to recompile a mission. I make missions all the time and I have never come across that sentence. Is it difficult to do?

2. I am confused about the installation. So, if I am playing another person's single player mission and want your mod, would I only have to enable the pbo file (@zbe..)? or do I need the pbo (@zbe) and the addon-version folder inside the @zbe folder as well?

3. Lastly, what does your parameter represent: [1000,true,150]execvm "ZBE_Caching\main.sqf"? I presume the 1st is for the distance

Share this post


Link to post
Share on other sites

Seems really interesting with few test i made, its always a good idea to cache unit or vehicle for some optimisation. The problem is when your mission already have some unit "freezed", your mod defreeze them and its a bit annoying :s. This disableAI "MOVE" in the init of unit seem to be deactivated when decached. Could you check if a unit is already cached by the mission maker and dont include them in the cycle ?

I've tested the mod version for the moment, and if i understand correctly if all clients on a multiplayer mission run the mod version it will work as the script version ?

"Addon version will not cache vehicles on clients unless also ran on clients" i'm not sure i've correcly understand this ^^.

Otherwise really good job a nice addition to my set of mod :p.

Share this post


Link to post
Share on other sites

Today me and a friend tried this out and after almost 2 hours of gameplay my friend's player led group got cached for some reason. He was unable to issue any order to his AI's. Nevertheless it's a very good script!

Share this post


Link to post
Share on other sites
Did he die and get TPd away from them on respawn ?

No, he did not die. He was issuing a get in order for 3 AI's that were standing directly in front of him into a HEMTT ambulance with an AI driver that also belonged to his group.

Share this post


Link to post
Share on other sites

I am still confused about the included folders in the download. Do i have to put them (when using Addon version) on a specific path?

Share this post


Link to post
Share on other sites

I'm slightly embarrassed to say this, but I'm not sure I have this working right. Could someone explain the proper execution of the script version? I have the init.sqf file and ZBE_Caching folder in the mission folder, and have created a trigger with the following ON ACT field:

nul = [] execVM "main.sqf";

Some messages related to the ZBE script appear when the mission starts, which makes me think it's working. When the trigger is a 50x50 ellipse set for BLUFOR and I start as a BLUFOR outside the trigger area, the OPFOR are still visible and very active. When I switch to Civilian and an AI BLUFOR is off in the distance with both of us outside the trigger area, the OPFOR are also still visible and active.

Can anyone tell what I'm doing wrong? Am I supposed to tweak the script? Are the OPFOR supposed to be inside or outside the trigger area? Is the trigger area supposed to be larger or smaller? Does the trigger have to be BLUFOR present? How far do the BLUFOR need to be in order for the OPFOR to be cached?

-----

EDIT: okay, I figured it out: the value in the init.sqf is in fact a distance. So, if a player (trigger doesn't care if it's BLUFOR, Civilian, whatever) is outside that distance, units within the trigger radius are cached. By lowering the distance from 1000 to 10 I was able to observe the caching. Other observations:

1. When I added vehicles like an off-road and an an armored unit to the group of infantry, the vehicles were not cached. Not sure why?

2. When a group is uncached it is always in formation, even if the unit is set to NONE for formations. Is there any way to specifically place units so they appear where they were placed in the editor? If you ungroup them, they all become team leaders, and TLs are never cached.

Edited by diehardfc

Share this post


Link to post
Share on other sites

Zorrobyte,

It would be possible to cache units placed after the mission started? I mean, If I spawn units using MCC, they won`t be cached.

Share this post


Link to post
Share on other sites

I finally have this script working well, and it's proven quite useful. Thanks very much for the hard work, Zorrobyte. I was wondering if there was a way to tell the script not to count AI groups within the cache distance? For example, I have a cache distance of 350 meters. I also have two enemy groups that are within 200 meters of each other. The team leaders don't have line of sight to each other. I'd like their teams to remain cached until a player is within 350 meters. When the teams uncache, they'll spot each other and start fighting. The goal, of course, is to have the fight in full swing when the players come up on it. Unfortunately, because the two teams are less than 350 meters away, they are causing each other to become uncached. Can this script accomplish that or should I look for a different solution? Thanks in advance for any assistance!

Share this post


Link to post
Share on other sites

Drop the @zbe_cache into your Arma 3 folder then the @zbe_cache/userconfig/zbe_cache into your Arma 3/userconfig folder.

The zbe_cache_addon_version is the source of the @zbe_cache.pbo

The zbe_cache_script_version is for missions as a script version (no mod or CBA)

Haven't been able to work on Arma lately.

Share this post


Link to post
Share on other sites

I'm sorry I am confused, does this cache idle units or all units out of A certáin rangé?

Share this post


Link to post
Share on other sites

All units except team leaders (like DAC's caching)

This caching script/addon enablesimulation false & hideobject true all AI units but Team Leaders if players are not within X distance OR enemy AI units are not within X distance. Also empty vehicles are enablesimulation false if no unit near (including AI)

Share this post


Link to post
Share on other sites

Picked this up again - it's getting cold outside and I need a hobby. So far, easy fixes such as players no longer get cached (ever) and I'm using lazy evaluation for condition checks. I may go script only from this point on for this module, as maximum benefit is if all is running it (server and clients) and because I'm a bit lazy.

A straight up 1km (or whatever you set it to) cache distance between players <-> AI and AI <-> AI works but I've been thinking about adding a Line of Sight (LOS) check for AI <-> AI caching. If a player is on the other side of the map and two AI groups uncache at 999 meters proximity but are on opposing sides of a hill or in an urban area, it seems wasteful. Something like a 250m hard uncache distance (testing needs to be done to check for average AI engagement distance) for AI <-> AI interactions but also uncaches if AI has line of sight on other enemy AI (for snipers and such, open terrain) seems more optimized. LOS script could be CPU load heavy though, I've yet to test but I'd only run it within a certain meter radius of group, on team leaders only.

As ZBE_Cache can auto sync the next TL, a check could be implemented to check if the TL can walk. I'd like to "simulate" bleedout (kill the TL if non ambulatory) if no enemy/player unit near to help keep the group mobile (as another unit chosen from group will uncache and take over as TL). It is unknown if medics can auto heal other teammates now (by A3 or script) but even so, wouldn't work as the medic in group is cached. This needs to be added as an option as some may want their groups realistic and crawling around the rest of the mission as non ambulatory. Instead, maybe I'll check the whole group to see if they can walk and "heal" them only so much as to let them walk again as to not slow down the group, who knows (could be a crude simulation of group/squad first aid).

I'd like to add a diagFPS (server/client FPS) averager loop (over 30 seconds?) and choose to force groups to be cached if FPS is lower than X (15 for MP/25 for SP?) for AI<->AI interactions. Even cached groups with uncache distance overridden (group will not uncache even if within uncache range for AI<->AI if FPS too low), the TLs will fight each other solo, uncaching the next unit if the TL dies and so on until one of the groups is dead. If a player isn't around, no one is the wiser that a 6 vs 6 AI fight took place actually was fought 1v1. This functionality would only be used as a last resort to keep the server playable, not as a general rule.

It's a fine line, I've thought several times about how to manage unplayable server FPS such as if a server gets overloaded by spawning too much AI then delete some groups until FPS improves. However, it'd only be managing the symptoms of a larger issue, an unoptimized mission/slow server/etc. Ultimately it isn't in scope of this module to be deleting units/change the mission.

Share this post


Link to post
Share on other sites

Some unique problems in A3 so far. When a vehicle is grouped with units outside the vehicle and the units get cached but not the driver, the vehicle will stay put until the units are uncached. FIXED with help from Wolfenswan as he pointed out the "Driver" - "driver" bug: http://feedback.arma3.com/view.php?id=19242

Additionally, I added lazy evalulation, debug switches and player NEVER gets cached/teleported now. Once I get the cached group speed figured out, I'll release next version.

**EDIT**

If a unit is enablesimulation false && hideobject true and is outside vehicle, they are hidden and do not simulate as expected. The moment they are moved into cargo they are unhidden and begin simulation again. This is true even if you run enablesimulation && hideobject again when units are in vehicle, they simply will not halt simulation or hide (up to and including shooting from vehicle).

Tested commands that do not work on units mounted in vehicles (MH-9 Hummingbird tested in this case):

_x disableAI "TARGET";

_x disableAI "AUTOTARGET";

_x disableAI "MOVE";

_x disableAI "ANIM";

_x disableAI "FSM";

_x enableSimulation false;

_x allowDamage false;

_x hideobject true;

Ticket filed: http://feedback.arma3.com/view.php?id=21702

Edited by zorrobyte

Share this post


Link to post
Share on other sites

ZBE_Cache V3 is released.

Changelog:

Script only version for inclusion into missions

No addon requirements (no more CBA)

Players are no longer cached or teleported in any circumstances

ZBE_Debug expanded to include more debug features

Lazy evalulation used more often

Manned vehicles now move as expected when cached due to "Driver" -> "driver" change, thanks to Wolfenswan

How to use:

Drop ZBE_Cache into root of mission directory (missions\missionname.stratis)

Copy contents of init.sqf from script folder to mission's init.sqf

Known Issue(s):

Units inside vehicle do not cache due to A3 bug: http://feedback.arma3.com/view.php?id=21702

Download Link

Edited by zorrobyte

Share this post


Link to post
Share on other sites
Guest

Thank you very much for sending us the update :cool:

New version frontpaged on the Armaholic homepage.

================================================

We have also "connected" these pages to your account on Armaholic.

This means soon you will be able to maintain these pages yourself if you wish to do so. Once this new feature is ready we will contact you about it and explain how things work and what options you have.

When you have any questions already feel free to PM or email me!

Share this post


Link to post
Share on other sites

So this script works with MCC/Zeus and AI Script/mods like ASR_AI / Gaja / Upsmon?

Share this post


Link to post
Share on other sites

Thanks zorrobyte for this script!

Anything that can help performances is more than welcome. ;)

I gave it a try last night and it seems to be working flawlessly!

EDIT : One small advice though, you could make your loops run even faster by using "pushback" whenever you need to add a new element to an array.

According to the wiki, the speed gain is up to 11843% (!) ;D

Edited by Pepe Hal

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×