mirror of
https://github.com/ZDoom/Raze.git
synced 2024-11-15 17:01:28 +00:00
This may be my worst commit ever.
git-svn-id: https://svn.eduke32.com/eduke32@7814 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
e49e8f4cd6
commit
36bde42d8c
4 changed files with 112 additions and 1 deletions
|
@ -228,6 +228,8 @@ typedef struct {
|
|||
|
||||
int8_t menutitle_pal, slidebar_palselected, slidebar_paldisabled;
|
||||
|
||||
int32_t last_stateless_level, last_stateless_volume; // strictly internal
|
||||
|
||||
struct {
|
||||
int32_t AutoAim;
|
||||
int32_t ShowWeapons;
|
||||
|
|
|
@ -5631,3 +5631,91 @@ HORIZONLY:;
|
|||
|
||||
P_ProcessWeapon(playerNum);
|
||||
}
|
||||
|
||||
|
||||
#define SJSON_IMPLEMENT
|
||||
#include "sjson.h"
|
||||
|
||||
int portableBackupSave(const char *path)
|
||||
{
|
||||
if (!FURY)
|
||||
return 0;
|
||||
|
||||
char fn[BMAX_PATH];
|
||||
|
||||
if (G_ModDirSnprintf(fn, sizeof(fn), "%s.ext", path))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
sjson_context* ctx = sjson_create_context(0, 0, NULL);
|
||||
if (!ctx)
|
||||
{
|
||||
buildprint("Could not create sjson_context\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
sjson_node* root = sjson_mkobject(ctx);
|
||||
|
||||
sjson_node * players = sjson_mkarray(ctx);
|
||||
|
||||
// sjson_put_string(ctx, root, "map", currentboardfilename);
|
||||
sjson_put_int(ctx, root, "volume", ud.last_stateless_volume);
|
||||
sjson_put_int(ctx, root, "level", ud.last_stateless_level);
|
||||
sjson_put_int(ctx, root, "skill", ud.player_skill);
|
||||
|
||||
for (int TRAVERSE_CONNECT(p))
|
||||
{
|
||||
playerdata_t const * playerData = &g_player[p];
|
||||
DukePlayer_t const * ps = playerData->ps;
|
||||
auto pSprite = (uspritetype const *)&sprite[ps->i];
|
||||
|
||||
sjson_node * player = sjson_mkobject(ctx);
|
||||
sjson_append_element(players, player);
|
||||
sjson_put_int(ctx, player, "extra", pSprite->extra);
|
||||
|
||||
sjson_node * gotweapon = sjson_put_array(ctx, player, "gotweapon");
|
||||
for (int w = 0; w < MAX_WEAPONS; ++w)
|
||||
sjson_append_element(gotweapon, sjson_mkbool(ctx, !!(ps->gotweapon & (1<<w))));
|
||||
|
||||
int ammo_amount[MAX_WEAPONS];
|
||||
for (int w = 0; w < MAX_WEAPONS; ++w)
|
||||
ammo_amount[w] = ps->ammo_amount[w];
|
||||
sjson_put_ints(ctx, player, "ammo_amount", ammo_amount, MAX_WEAPONS);
|
||||
|
||||
int inv_amount[GET_MAX];
|
||||
for (int i = 0; i < GET_MAX; ++i)
|
||||
inv_amount[i] = ps->inv_amount[i];
|
||||
sjson_put_ints(ctx, player, "inv_amount", inv_amount, GET_MAX);
|
||||
|
||||
sjson_put_int(ctx, player, "curr_weapon", ps->curr_weapon);
|
||||
sjson_put_int(ctx, player, "subweapon", ps->subweapon);
|
||||
sjson_put_int(ctx, player, "inven_icon", ps->inven_icon);
|
||||
}
|
||||
|
||||
sjson_append_member(ctx, root, "players", players);
|
||||
|
||||
char errmsg[256];
|
||||
if (!sjson_check(root, errmsg))
|
||||
{
|
||||
buildprint(errmsg, "\n");
|
||||
sjson_destroy_context(ctx);
|
||||
return 1;
|
||||
}
|
||||
|
||||
char* encoded = sjson_stringify(ctx, root, " ");
|
||||
|
||||
buildvfs_FILE fil = buildvfs_fopen_write(fn);
|
||||
if (!fil)
|
||||
{
|
||||
sjson_destroy_context(ctx);
|
||||
return 1;
|
||||
}
|
||||
|
||||
buildvfs_fwrite(encoded, strlen(encoded), 1, fil);
|
||||
buildvfs_fclose(fil);
|
||||
|
||||
sjson_destroy_context(ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1807,6 +1807,23 @@ void G_SetupFilenameBasedMusic(char *nameBuf, const char *fileName, int levelNum
|
|||
realloc_copy(&g_mapInfo[levelNum].musicfn, usermapMusic);
|
||||
}
|
||||
|
||||
static void G_CheckIfStateless()
|
||||
{
|
||||
for (bssize_t i = 0; i < (MAXVOLUMES * MAXLEVELS); i++)
|
||||
{
|
||||
map_t *const pMapInfo = &g_mapInfo[i];
|
||||
if (pMapInfo->savedstate != nullptr)
|
||||
{
|
||||
// buildprint("G_CheckIfStateless: no ", ud.volume_number, " ", ud.level_number, "\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// buildprint("G_CheckIfStateless: yes ", ud.volume_number, " ", ud.level_number, "\n");
|
||||
ud.last_stateless_volume = ud.volume_number;
|
||||
ud.last_stateless_level = ud.level_number;
|
||||
}
|
||||
|
||||
int G_EnterLevel(int gameMode)
|
||||
{
|
||||
vote_map = vote_episode = voting = -1;
|
||||
|
@ -2017,6 +2034,8 @@ int G_EnterLevel(int gameMode)
|
|||
|
||||
Bmemcpy(currentboardfilename, boardfilename, BMAX_PATH);
|
||||
|
||||
G_CheckIfStateless();
|
||||
|
||||
for (int TRAVERSE_CONNECT(i))
|
||||
{
|
||||
if (!VM_OnEventWithReturn(EVENT_ENTERLEVEL, g_player[i].ps->i, i, 0))
|
||||
|
|
|
@ -548,6 +548,9 @@ int32_t G_SavePlayer(savebrief_t & sv, bool isAutoSave)
|
|||
|
||||
VM_OnEvent(EVENT_SAVEGAME, g_player[screenpeek].ps->i, screenpeek);
|
||||
|
||||
extern int portableBackupSave(const char *);
|
||||
portableBackupSave(sv.path);
|
||||
|
||||
// SAVE!
|
||||
sv_saveandmakesnapshot(fil, sv.name, 0, 0, 0, 0, isAutoSave);
|
||||
|
||||
|
@ -2297,4 +2300,3 @@ static void postloadplayer(int32_t savegamep)
|
|||
}
|
||||
|
||||
////////// END GENERIC SAVING/LOADING SYSTEM //////////
|
||||
|
||||
|
|
Loading…
Reference in a new issue