Skip to content

preStartGameByDirectoryPath ​

Pre-start a Game (by Local Directory Path) ​

preStartGameByDirectoryPath is the fastest pre-processing interface. It directly loads an already-extracted game resource directory and immediately activates the game's script logic and business flow. By eliminating the time spent on network download and archive extraction, this interface lets the game enter a running state in the background with minimal I/O overhead.

This interface is commonly used for local development and debugging, resource pre-placement (copying from the Assets directory to a private directory), or scenarios where the business side has already implemented its resource management logic.


Method Declaration ​

java
/**
 * Pre-start a game by local game directory path
 *
 * @param directoryPath     directoryPath
 * @param params            Parameter object containing the local directory path and initialization configuration
 * @param listener          Pre-start status listener
 * @return SUDOPGameTask    Task handle, used to manage the pre-started game instance
 */
public static SUDOPGameTask preStartGameByDirectoryPath(String directoryPath, SUDOPGamePackageParams params, SUDOPPreStartGameListener listener) ;

Parameters ​

FieldTypeDescription
directoryPathStringRequired. The absolute path of the game resource folder (the directory must contain entry files such as app.json).

1. SUDOPGamePackageParams ​

Specifies the concrete resource download details:

FieldTypeDescription
versionStringRequired. Game version
fidStringGame package file fingerprint
fidTypeFIDTypeGame package file fingerprint generation method
appGameIDStringRequired. The specified gameID
appCPIDStringThe game developer's CP ID
appGroupIDStringThe game developer's Group ID

2. FIDType ​

Specifies the game package file fingerprint generation method

FieldTypeDescription
MD5enumMD5 algorithm
CRC32enumCRC32 algorithm
SHA1enumSHA1 algorithm
SHA256StrenumingSHA256 algorithm

2. SUDOPPreStartGameListener ​

  • void onSuccess(String gameId, SUDRTGameHandleProvider provider): Pre-start succeeded. The game has completed initialization in the background and executed the first-screen logic.
  • void onFailure(int retCode, String retMsg): Pre-start failed. Common causes: nonexistent directory, missing core configuration file, restricted permissions.

Runtime Behavior ​

  1. Zero extraction overhead: Directly maps the local file system, bypassing the extraction step, greatly reducing instantaneous CPU load.
  2. Full logic activation: After loading the script engine, immediately executes the game's onLoad function, pre-loading the game configuration and establishing a server long connection (if any).
  3. Rendering preparation: Builds the render tree in background memory and prepares the first-screen frame data.
  4. State reuse: When the user formally enters the game, the SDK directly mounts the Surface of this background instance onto the UI view.

Example Code ​

java
String directoryPath = getFilesDir().getAbsolutePath() + "/local_game_storage/game_101/";

SUDOPGamePackageParams params = new SUDOPGamePackageParams();
params.version = "gamePkgVersion";
params.fid = "2e7ca170f33629c7baf4dc430c541c43";
params.fidType = FIDType.MD5;
params.appGameID = "appGameID";
params.appCPID = "Game Developer id";
params.appGroupID = "Game developer group id";

SUDOPGameTask preLoadTask = SUDOP.preStartGameByDirectoryPath(directoryPath, params, new SUDOPPreStartGameListener() {
    @Override
    public void onSuccess(String gameId, SUDRTGameHandleProvider provider) {
        SUDRTGameHandle handle = provider.getGameHandle();
    }
    @Override
    public void onFailure(int retCode, String retMsg) {
    }
});

// If you do not start the game and leave the scene, be sure to destroy the task
// task.destroy();

Notes ​

  • Path completeness: The developer must ensure the file structure inside the folder pointed to by directoryPath is complete.
  • Resource locking: During pre-start, the SDK may occupy some of the file resources in this directory.
  • Memory warning: Although I/O overhead is low, the memory occupied by script execution is the same as other pre-start methods. It is recommended to use it when device memory is sufficient.

The success callback returns SUDRTGameHandleProvider. Call provider.getGameHandle() to obtain the SUDRTGameHandle.