Merge branch 'issue1199' into 'next'

Bring back WRITETHINGS, with custom filename and UDMF support!

See merge request STJr/SRB2!2339
This commit is contained in:
sphere 2024-02-25 23:36:20 +00:00
commit 6d02f1823e
5 changed files with 91 additions and 56 deletions

View file

@ -1432,14 +1432,22 @@ void OP_ObjectplaceMovement(player_t *player)
// //
// Objectplace related commands. // Objectplace related commands.
// //
/*void Command_Writethings_f(void) void Command_Writethings_f(void)
{ {
REQUIRE_INLEVEL; REQUIRE_INLEVEL;
REQUIRE_SINGLEPLAYER; REQUIRE_SINGLEPLAYER;
REQUIRE_OBJECTPLACE; REQUIRE_OBJECTPLACE;
P_WriteThings(); if (COM_Argc() > 1)
}*/ {
P_WriteThings(COM_Argv(1));
}
else
{
CONS_Printf(M_GetText("writethings <filename>: write out map things to a file, .txt or .lmp automatically appended.\n"));
return;
}
}
void Command_ObjectPlace_f(void) void Command_ObjectPlace_f(void)
{ {

View file

@ -26,7 +26,7 @@ void cht_Init(void);
// ObjectPlace // ObjectPlace
// //
void Command_ObjectPlace_f(void); void Command_ObjectPlace_f(void);
//void Command_Writethings_f(void); void Command_Writethings_f(void);
extern consvar_t cv_opflags, cv_ophoopflags, cv_mapthingnum, cv_speed; extern consvar_t cv_opflags, cv_ophoopflags, cv_mapthingnum, cv_speed;
//extern consvar_t cv_snapto, cv_grid; //extern consvar_t cv_snapto, cv_grid;

View file

@ -913,7 +913,7 @@ void D_RegisterClientCommands(void)
// ingame object placing // ingame object placing
COM_AddCommand("objectplace", Command_ObjectPlace_f, COM_LUA); COM_AddCommand("objectplace", Command_ObjectPlace_f, COM_LUA);
//COM_AddCommand("writethings", Command_Writethings_f); COM_AddCommand("writethings", Command_Writethings_f, COM_LUA);
CV_RegisterVar(&cv_speed); CV_RegisterVar(&cv_speed);
CV_RegisterVar(&cv_opflags); CV_RegisterVar(&cv_opflags);
CV_RegisterVar(&cv_ophoopflags); CV_RegisterVar(&cv_ophoopflags);

View file

@ -877,14 +877,32 @@ static void P_SpawnMapThings(boolean spawnemblems)
P_SpawnEmeraldHunt(); P_SpawnEmeraldHunt();
} }
static void P_WriteTextmap_Things(FILE *f, const mapthing_t *wmapthings); // proto
// Experimental groovy write function! // Experimental groovy write function!
/*void P_WriteThings(void) void P_WriteThings(const char *filepath)
{ {
size_t i, length; size_t i, length;
mapthing_t *mt; mapthing_t *mt;
UINT8 *savebuffer, *savebuf_p; UINT8 *savebuffer, *savebuf_p;
INT16 temp; INT16 temp;
if (udmf)
{
FILE *f = fopen(va("%s.txt", filepath), "w");
if (!f)
{
CONS_Alert(CONS_ERROR, M_GetText("Couldn't write to file %s\n"), filepath);
return;
}
P_WriteTextmap_Things(f, mapthings);
fclose(f);
CONS_Printf(M_GetText("%s.txt saved.\n"), filepath);
return;
}
savebuf_p = savebuffer = (UINT8 *)malloc(nummapthings * sizeof (mapthing_t)); savebuf_p = savebuffer = (UINT8 *)malloc(nummapthings * sizeof (mapthing_t));
if (!savebuf_p) if (!savebuf_p)
@ -908,12 +926,12 @@ static void P_SpawnMapThings(boolean spawnemblems)
length = savebuf_p - savebuffer; length = savebuf_p - savebuffer;
FIL_WriteFile(va("newthings%d.lmp", gamemap), savebuffer, length); FIL_WriteFile(va("%s.lmp", filepath), savebuffer, length);
free(savebuffer); free(savebuffer);
savebuf_p = NULL; savebuf_p = NULL;
CONS_Printf(M_GetText("newthings%d.lmp saved.\n"), gamemap); CONS_Printf(M_GetText("%s.lmp saved.\n"), filepath);
}*/ }
// //
// MAP LOADING FUNCTIONS // MAP LOADING FUNCTIONS
@ -2150,6 +2168,60 @@ typedef struct
mapthing_t *angleanchor; mapthing_t *angleanchor;
} sectorspecialthings_t; } sectorspecialthings_t;
static void P_WriteTextmap_Things(FILE *f, const mapthing_t *wmapthings)
{
size_t i, j;
mtag_t firsttag;
// Actual writing
for (i = 0; i < nummapthings; i++)
{
fprintf(f, "thing // %s\n", sizeu1(i));
fprintf(f, "{\n");
firsttag = Tag_FGet(&wmapthings[i].tags);
if (firsttag != 0)
fprintf(f, "id = %d;\n", firsttag);
if (wmapthings[i].tags.count > 1)
{
fprintf(f, "moreids = \"");
for (j = 1; j < wmapthings[i].tags.count; j++)
{
if (j > 1)
fprintf(f, " ");
fprintf(f, "%d", wmapthings[i].tags.tags[j]);
}
fprintf(f, "\";\n");
}
fprintf(f, "x = %d;\n", wmapthings[i].x);
fprintf(f, "y = %d;\n", wmapthings[i].y);
if (wmapthings[i].z != 0)
fprintf(f, "height = %d;\n", wmapthings[i].z);
fprintf(f, "angle = %d;\n", wmapthings[i].angle);
if (wmapthings[i].pitch != 0)
fprintf(f, "pitch = %d;\n", wmapthings[i].pitch);
if (wmapthings[i].roll != 0)
fprintf(f, "roll = %d;\n", wmapthings[i].roll);
if (wmapthings[i].type != 0)
fprintf(f, "type = %d;\n", wmapthings[i].type);
if (wmapthings[i].spritexscale != FRACUNIT)
fprintf(f, "scalex = %f;\n", FIXED_TO_FLOAT(wmapthings[i].spritexscale));
if (wmapthings[i].spriteyscale != FRACUNIT)
fprintf(f, "scaley = %f;\n", FIXED_TO_FLOAT(wmapthings[i].spriteyscale));
if (wmapthings[i].scale != FRACUNIT)
fprintf(f, "mobjscale = %f;\n", FIXED_TO_FLOAT(wmapthings[i].scale));
if (wmapthings[i].options & MTF_OBJECTFLIP)
fprintf(f, "flip = true;\n");
for (j = 0; j < NUMMAPTHINGARGS; j++)
if (wmapthings[i].args[j] != 0)
fprintf(f, "arg%s = %d;\n", sizeu1(j), wmapthings[i].args[j]);
for (j = 0; j < NUMMAPTHINGSTRINGARGS; j++)
if (mapthings[i].stringargs[j])
fprintf(f, "stringarg%s = \"%s\";\n", sizeu1(j), mapthings[i].stringargs[j]);
fprintf(f, "}\n");
fprintf(f, "\n");
}
}
static void P_WriteTextmap(void) static void P_WriteTextmap(void)
{ {
size_t i, j; size_t i, j;
@ -2417,52 +2489,7 @@ static void P_WriteTextmap(void)
} }
fprintf(f, "namespace = \"srb2\";\n"); fprintf(f, "namespace = \"srb2\";\n");
for (i = 0; i < nummapthings; i++) P_WriteTextmap_Things(f, wmapthings);
{
fprintf(f, "thing // %s\n", sizeu1(i));
fprintf(f, "{\n");
firsttag = Tag_FGet(&wmapthings[i].tags);
if (firsttag != 0)
fprintf(f, "id = %d;\n", firsttag);
if (wmapthings[i].tags.count > 1)
{
fprintf(f, "moreids = \"");
for (j = 1; j < wmapthings[i].tags.count; j++)
{
if (j > 1)
fprintf(f, " ");
fprintf(f, "%d", wmapthings[i].tags.tags[j]);
}
fprintf(f, "\";\n");
}
fprintf(f, "x = %d;\n", wmapthings[i].x);
fprintf(f, "y = %d;\n", wmapthings[i].y);
if (wmapthings[i].z != 0)
fprintf(f, "height = %d;\n", wmapthings[i].z);
fprintf(f, "angle = %d;\n", wmapthings[i].angle);
if (wmapthings[i].pitch != 0)
fprintf(f, "pitch = %d;\n", wmapthings[i].pitch);
if (wmapthings[i].roll != 0)
fprintf(f, "roll = %d;\n", wmapthings[i].roll);
if (wmapthings[i].type != 0)
fprintf(f, "type = %d;\n", wmapthings[i].type);
if (wmapthings[i].spritexscale != FRACUNIT)
fprintf(f, "scalex = %f;\n", FIXED_TO_FLOAT(wmapthings[i].spritexscale));
if (wmapthings[i].spriteyscale != FRACUNIT)
fprintf(f, "scaley = %f;\n", FIXED_TO_FLOAT(wmapthings[i].spriteyscale));
if (wmapthings[i].scale != FRACUNIT)
fprintf(f, "mobjscale = %f;\n", FIXED_TO_FLOAT(wmapthings[i].scale));
if (wmapthings[i].options & MTF_OBJECTFLIP)
fprintf(f, "flip = true;\n");
for (j = 0; j < NUMMAPTHINGARGS; j++)
if (wmapthings[i].args[j] != 0)
fprintf(f, "arg%s = %d;\n", sizeu1(j), wmapthings[i].args[j]);
for (j = 0; j < NUMMAPTHINGSTRINGARGS; j++)
if (mapthings[i].stringargs[j])
fprintf(f, "stringarg%s = \"%s\";\n", sizeu1(j), mapthings[i].stringargs[j]);
fprintf(f, "}\n");
fprintf(f, "\n");
}
for (i = 0; i < numvertexes; i++) for (i = 0; i < numvertexes; i++)
{ {

View file

@ -71,7 +71,7 @@ boolean P_AddFolder(const char *folderpath);
boolean P_RunSOC(const char *socfilename); boolean P_RunSOC(const char *socfilename);
void P_LoadSoundsRange(UINT16 wadnum, UINT16 first, UINT16 num); void P_LoadSoundsRange(UINT16 wadnum, UINT16 first, UINT16 num);
void P_LoadMusicsRange(UINT16 wadnum, UINT16 first, UINT16 num); void P_LoadMusicsRange(UINT16 wadnum, UINT16 first, UINT16 num);
//void P_WriteThings(void); void P_WriteThings(const char *filepath);
size_t P_PrecacheLevelFlats(void); size_t P_PrecacheLevelFlats(void);
void P_AllocMapHeader(INT16 i); void P_AllocMapHeader(INT16 i);