Platform: Documentation improvements.

This commit is contained in:
Marco Cawthorne 2023-08-21 08:39:54 -07:00
parent 225039f71f
commit 9871e93a10
Signed by: eukara
GPG Key ID: CE2032F0A2882A22
7 changed files with 113 additions and 32 deletions

View File

@ -117,6 +117,7 @@ m_init(void)
registercommand("map_background");
registercommand("menu_musicstart");
registercommand("richpresence_dump");
registercommand("platformRefreshUpdates");
Font_Load("fonts/fontcon.font", font_console);
Font_Load("fonts/menu_label.font", font_label);
@ -408,6 +409,9 @@ m_consolecommand(string cmd)
localcmd(sprintf("maxplayers 2\nset coop 1\nset sv_background 1\nmap %s\n",
argv(1)));
break;
case "platformRefreshUpdates":
Updates_RefreshState();
break;
default:
return (0);
}

View File

@ -66,7 +66,7 @@ CModList::Draw(void)
[0,0,0], 1.0f);
visible = floor(m_size[1] / 29);
visible = bound(0, visible, gameinfo_count - 1);
visible = bound(0, visible, GameLibrary_GetGameCount() - 1);
pos = m_y;
for (int i = m_scroll; i <= (visible + m_scroll); i++) {
@ -145,7 +145,7 @@ CModList::Input(float type, float x, float y, float devid)
int pos[2];
visible = floor(m_size[1] / 29);
visible = bound(0, visible, gameinfo_count - 1);
visible = bound(0, visible, GameLibrary_GetGameCount() - 1);
pos[0] = m_x;
pos[1] = m_y;

View File

@ -14,6 +14,40 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*! @file gamelibrary.h
@brief Game library parsing and querying of metadata.
The GameLibrary concerns itself with everything around what a game is,
how to install, activate and deactivate it. Mods are included in this,
so we'll proceed calling them 'games' or 'custom games'.
A game can be installed through two primary means:
- Manual install, like from a .zip or some installer or archive
- Engine package manager install, through our own user interface
And between these, they can come with different metadata/manifests.
It assumed that every game has either a FTE Manifest description,
a gameinfo.txt (Source Engine format) or liblist.gam (GoldSrc format)
that describes various aspects of the game. Like which version it is, what
map will be loaded when you press 'New Game' and so on.
If that info is not available, some placeholder data will be used instead.
However, games installed via the package manager will at least for the
custom game menus not use the on-disk manifest file, but information
provided by the package manager. Once you switch into said game everything
within will be pulled from a file on disk, such as a liblist.gam or gameinfo.txt.
The menu needs to call GameLibrary_Init() once for parsing the currently running
game its own metadata. If you want to index custom games, aka mods, you need
to do so with GameLibrary_InitCustom() afterwards.
Because indexing mods can take a very long time depending on the amount
that is stored on disk, you may want to call GameLibrary_InitCustom() at
a later time.
*/
typedef enum
{
GAMEINFO_TITLE, /**< (string) The title of the game. E.g. "Action Game" */
@ -56,8 +90,9 @@ void GameLibrary_Deactivate(void);
bool GameLibrary_IsInstalling(void);
/** Returns a 0-100% value of game install progress, tracking across multiple packages. */
float GameLibrary_InstallProgress(void);
/** Return the ID for the currently activate game. */
/** Returns the total amount of games currently available. */
int GameLibrary_GetGameCount(void);
/** Return the ID for the currently active game. */
int GameLibrary_GetCurrentGame(void);
/** Retrieves fields for a given game. See gameInfo_t for a list of fields you can query. */
__variant GameLibrary_GetGameInfo(int, gameInfo_t);
@ -73,6 +108,7 @@ typedef enum
GAMEINFO_PACKAGE,
} gi_type;
#ifndef DOXYGEN
typedef struct
{
string game;
@ -105,4 +141,5 @@ typedef struct
} gameinfo_t;
int gameinfo_count;
gameinfo_t *games;
gameinfo_t *games;
#endif

View File

@ -14,29 +14,6 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* The GameLibrary concerns itself with everything around what a game is,
how to install, activate and deactivate them. Mods are included in this,
so I'll proceed calling them 'games' or 'custom games'.
A game can be installed through two primary means:
- Manual install, like from a .zip or some installer or archive
- Engine package manager install, through our own user interface
And between these, they can come with different metadata/manifests.
It assumed that every game has either a FTE Manifest description,
a gameinfo.txt (Source Engine format) or liblist.gam (GoldSrc format)
that describes various aspects of the game. Like which version it is, what
map will be loaded when you press 'New Game' and so on.
If that info is not available, some placeholder data will be used instead.
However, games installed via the package manager will at least for the
custom game menus not use the on-disk manifest file, but information
provided by the package manager. Once you switch into said game everything
within will be pulled from a file on disk, such as a liblist.gam or gameinfo.txt.
*/
int g_iModInstallCache;
string g_strModInstallCache;
@ -766,6 +743,12 @@ GameLibrary_GetCurrentGame(void)
return gameinfo_current;
}
int
GameLibrary_GetGameCount(void)
{
return gameinfo_count;
}
__variant
GameLibrary_GetInfo(gameInfo_t infoType)
{

View File

@ -14,6 +14,21 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*! @file maplibrary.h
@brief Map library parsing and querying of metadata.
Menus need to be aware of what levels aka maps are available for modes like
multiplayer. The MapLibrary is by configured to only parse levels from the
current game directory (much like GoldSrc) and optionally can blacklist
maps based on a variety of criteria which may be configurable at some point
in time.
The menu needs to call MapLibrary_Init() at least once, after which you can
query the total amount of maps that are available via MapLibrary_GetMapCount().
You can then iterate over the individual entries with MapLibrary_GetInfo().
*/
typedef enum
{
MAPINFO_NAME, /**< (string) Name of the map. E.g. e1m1 */

View File

@ -14,6 +14,22 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*! @file updates.h
@brief Game and content update handler functions.
The updater is an abstraction of the engine its own package manager.
Not all packages the engine offers are related to the game you're currently
running. Therefore we offer our own API within Nuclide to deal with game updates.
You want to call Updates_Init() once, after which Updates_GetUpdaterStatus() should be queried to determine when the Updater is ready. That is not necessary, but it might be helpful to throw up a loading screen while that is returning UPDATER_PENDING.
Once Updates_GetUpdaterStatus() reports UPDATER_INITIALIZED, you can expect the loading to be fully done.
The function Updates_GetPackageCount() will report the total amount of update packages available for the game. These are not 'new' updates, they contain every package associated with the game that can and should be installed and kept updated.
Use Updates_GetInfo() to retrieve metadata about individual packages.
*/
/** Different types you can pass to `Updates_GetInfo(...)` to learn details about a given Update entry. */
typedef enum
{
@ -85,4 +101,6 @@ bool Updates_Remove(int);
/** Mark an update as pending uninstallation. May return true/false if it succeeded in marking the package. */
bool Updates_Destroy(int);
/** Apply all pending changes to packages. May return true/false if it succeeded in doing so. */
bool Updates_ApplyPendingChanges(void);
bool Updates_ApplyPendingChanges(void);
/** Called by the console command `platformRefreshUpdates`, which your menu needs to implement. Otherwise you will not see pending changes reflected in your menu interface. */
void Updates_RefreshState(void);

View File

@ -218,8 +218,6 @@ Updates_GetInfo(int packageID, updateType_t fieldType)
return __NULL__;
}
Updates_RefreshStateValues(packageID);
switch (fieldType) {
case UPDATE_NAME:
return (string)updates[packageID].name;
@ -338,6 +336,7 @@ Updates_Toggle(int packageID)
}
break;
}
localcmd(sprintf("platformRefreshUpdates %i\n", packageID));
return true;
}
@ -351,6 +350,7 @@ Updates_Install(int packageID)
}
localcmd(sprintf("pkg add %s\n", updates[packageID].name));
localcmd(sprintf("platformRefreshUpdates %i\n", packageID));
print(sprintf("Marking package %s for install.\n", updates[packageID].title));
return true;
}
@ -364,6 +364,7 @@ Updates_Remove(int packageID)
}
localcmd(sprintf("pkg rem %s\n", updates[packageID].name));
localcmd(sprintf("platformRefreshUpdates %i\n", packageID));
print(sprintf("Marking package %s for 'removal'.\n", updates[packageID].title));
return true;
}
@ -377,6 +378,7 @@ Updates_Destroy(int packageID)
}
localcmd(sprintf("pkg del %s\n", updates[packageID].name));
localcmd(sprintf("platformRefreshUpdates %i\n", packageID));
print(sprintf("Marking package %s for 'deletion'.\n", updates[packageID].title));
return true;
}
@ -390,15 +392,37 @@ Updates_ApplyPendingChanges(void)
return true;
}
/* I hate having to put this in, but because we can only interact with the
engine its own package manager via console commands (they are delayed as
as result) we cannot query the result of our `pkg` commands right after
calling them via localcmd(). Therefore menus need to implement the console
command `platformRefreshUpdates` which calls this very function below.
All in the hopes of improving performance just a tiny bit. */
void
Updates_RefreshState(void)
{
/* at least try to be a bit clever about it. */
if (argv(0) == "platformRefreshUpdates") {
Updates_RefreshStateValues((int)stof(argv(1)));
return;
}
/* just force refresh them all otherwise. */
for (int i = 0i; i < g_platform_update_count; i++) {
Updates_RefreshStateValues(i);
}
}
void
Updater_URI_Callback(float id, float code, string data, int resourcebytes)
{
/* game does not have a recommended package listing remotely? make something up. */
if (code == 404) {
string gameDir = cvar_string("fs_game");
games[GameLibrary_GetCurrentGame()].pkgname = strcat("cg_", gameDir, ";game_", gameDir, ";");
} else {
print(sprintf("URI: %d %d %S %i\n", id, code, data, resourcebytes));
//print(sprintf("URI: %d %d %S %i\n", id, code, data, resourcebytes));
games[GameLibrary_GetCurrentGame()].pkgname = data;
}