Gamecache API

From WarCraft3

Jump to: navigation, search

The Gamecache API was originally written to allow progress to be saved between different campaign maps. A gamecache is created with InitGameCache, subsequent calls with the same campaignFile string will return the same gamecache.

Contents

Code

common.j

// Creates a new or reads in an existing game cache file stored
// in the current campaign profile dir
//
native  ReloadGameCachesFromDisk takes nothing returns boolean

native  InitGameCache   takes string campaignFile returns gamecache
native  SaveGameCache   takes gamecache whichCache returns boolean

native  StoreInteger    takes gamecache cache, string missionKey, string key, integer value returns nothing
native  StoreReal       takes gamecache cache, string missionKey, string key, real value returns nothing
native  StoreBoolean    takes gamecache cache, string missionKey, string key, boolean value returns nothing
native  StoreUnit       takes gamecache cache, string missionKey, string key, unit whichUnit returns boolean
native  StoreString     takes gamecache cache, string missionKey, string key, string value returns boolean

native SyncStoredInteger        takes gamecache cache, string missionKey, string key returns nothing
native SyncStoredReal           takes gamecache cache, string missionKey, string key returns nothing
native SyncStoredBoolean        takes gamecache cache, string missionKey, string key returns nothing
native SyncStoredUnit           takes gamecache cache, string missionKey, string key returns nothing
native SyncStoredString         takes gamecache cache, string missionKey, string key returns nothing

// Will return 0 if the specified value's data is not found in the cache
native  GetStoredInteger        takes gamecache cache, string missionKey, string key returns integer
native  GetStoredReal           takes gamecache cache, string missionKey, string key returns real
native  GetStoredBoolean        takes gamecache cache, string missionKey, string key returns boolean
native  GetStoredString         takes gamecache cache, string missionKey, string key returns string
native  RestoreUnit             takes gamecache cache, string missionKey, string key, player forWhichPlayer, real x, real y, real facing returns unit

native  HaveStoredInteger        takes gamecache cache, string missionKey, string key returns boolean
native  HaveStoredReal           takes gamecache cache, string missionKey, string key returns boolean
native  HaveStoredBoolean        takes gamecache cache, string missionKey, string key returns boolean
native  HaveStoredUnit           takes gamecache cache, string missionKey, string key returns boolean
native  HaveStoredString         takes gamecache cache, string missionKey, string key returns boolean

native  FlushGameCache          takes gamecache cache returns nothing
native  FlushStoredMission      takes gamecache cache, string missionKey returns nothing
native  FlushStoredInteger      takes gamecache cache, string missionKey, string key returns nothing
native  FlushStoredReal         takes gamecache cache, string missionKey, string key returns nothing
native  FlushStoredBoolean      takes gamecache cache, string missionKey, string key returns nothing
native  FlushStoredUnit         takes gamecache cache, string missionKey, string key returns nothing
native  FlushStoredString       takes gamecache cache, string missionKey, string key returns nothing
Confused? Jass help forum!

Single Player vs. Multiplayer

Gamecaches are designed for transferring data between maps in a campaign, by storing data on the hard disk. In multi-player games however, the data is never stored on the hard disk, making online campaigns and saving/loading data between games impossible. However, because gamecaches still work in multi-player games (storing data in the memory, rather than the hard disk) they can be useful in Attachment Systems. Hashtables, introduced in patch 1.24, deprecates the use of gamecache in multiplayer games for most practical usages.

Bugs

InitGameCache leak

Each call to InitGameCache increases the memory usage even when no new gamecache is created, the only way to reclaim this memory is to flush the gamecache or save it to disk.

See also: http://www.wc3c.net/showthread.php?t=68385

Limit of 256 gamecaches

You can't have more than 256 gamecaches (files) at once, when you have InitGameCache will return null when you try to create a new gamecache. This issue is greatly magnified by the following bugs:

  • Flushing a gamecache doesn't remove it completely, hence you can't decrease the number of gamecaches in-game.
  • After flushing a gamecache, initiating a new gamecache with the same name increases the gamecache count again.
  • When playing single player, all gamecaches saved for that profile will be loaded when starting the game.
  • When saving a gamecache, all other gamecaches in the game will also be saved.

When the limit is hit the only way to recover is to ask the player to delete the campaigns.w3v in his profile folder or create a new profile.

See also: http://wwww.wc3jass.com/viewtopic.php?t=2334

Related

Personal tools