Implement am scaling, following and grid lines. Map sectors loaded onto IPU.

This commit is contained in:
jndean
2022-09-05 16:14:52 +00:00
parent 2a04c2d52d
commit 716e5867ec
7 changed files with 233 additions and 43 deletions

View File

@@ -1164,9 +1164,10 @@ void AM_Drawer(void) {
IPU_AM_Drawer() ;
// AM_clearFB(BACKGROUND); // ON IPU
if (grid)
AM_drawGrid(GRIDCOLORS);
// Commented out lines are done on IPU instead
// AM_clearFB(BACKGROUND);
// if (grid)
// AM_drawGrid(GRIDCOLORS);
AM_drawWalls();
AM_drawPlayers();
if (cheating == 2)

View File

@@ -213,6 +213,51 @@ cheatseq_t cheat_amap = CHEAT("iddt", 0);
static boolean stopped = true;
//
//
//
void AM_activateNewScale(void) {
m_x += m_w / 2;
m_y += m_h / 2;
m_w = FTOM(f_w);
m_h = FTOM(f_h);
m_x -= m_w / 2;
m_y -= m_h / 2;
m_x2 = m_x + m_w;
m_y2 = m_y + m_h;
}
//
//
//
void AM_saveScaleAndLoc(void) {
old_m_x = m_x;
old_m_y = m_y;
old_m_w = m_w;
old_m_h = m_h;
}
//
//
//
void AM_restoreScaleAndLoc(void) {
m_w = old_m_w;
m_h = old_m_h;
if (!followplayer) {
m_x = old_m_x;
m_y = old_m_y;
} else {
m_x = am_playerpos.x - m_w / 2;
m_y = am_playerpos.y - m_h / 2;
}
m_x2 = m_x + m_w;
m_y2 = m_y + m_h;
// Change the scaling multipliers
scale_mtof = FixedDiv(f_w << FRACBITS, m_w);
scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
}
//
// Determines bounding box of all vertices,
@@ -365,7 +410,6 @@ void AM_LevelInit(void) {
void AM_Stop(void) {
// static event_t st_notify = {0, ev_keyup, AM_MSGEXITED, 0}; // LATER
ipuprint("Stopping automap");
// AM_unloadPics(); // JOSEF
automapactive = false;
// ST_Responder(&st_notify); // LATER
@@ -391,6 +435,24 @@ void AM_Start(void) {
ipuprint("Starting automap");
}
//
// set the window scale to the maximum size
//
void AM_minOutWindowScale(void) {
scale_mtof = min_scale_mtof;
scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
AM_activateNewScale();
}
//
// set the window scale to the minimum size
//
void AM_maxOutWindowScale(void) {
scale_mtof = max_scale_mtof;
scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
AM_activateNewScale();
}
//
// Handle events (user inputs) in automap mode
//
@@ -402,7 +464,7 @@ boolean AM_Responder(event_t *ev) {
int key;
rc = false;
/* LATER
/* JOSEF: No Joystick support
if (ev->type == ev_joystick && joybautomap >= 0 &&
(ev->data1 & (1 << joybautomap)) != 0) {
joywait = I_GetTime() + 5;
@@ -434,7 +496,6 @@ boolean AM_Responder(event_t *ev) {
if (key == key_map_east) // pan right
{
/* LATER
if (!followplayer)
m_paninc.x = FTOM(F_PANINC);
else
@@ -465,14 +526,11 @@ boolean AM_Responder(event_t *ev) {
{
mtof_zoommul = M_ZOOMIN;
ftom_zoommul = M_ZOOMOUT;
*/
} else if (key == key_map_toggle) {
bigstate = 0;
viewactive = true;
AM_Stop();
}
/* LATER
else if (key == key_map_maxzoom) {
} else if (key == key_map_maxzoom) {
bigstate = !bigstate;
if (bigstate) {
AM_saveScaleAndLoc();
@@ -482,17 +540,23 @@ boolean AM_Responder(event_t *ev) {
} else if (key == key_map_follow) {
followplayer = !followplayer;
f_oldloc.x = INT_MAX;
/* LATER
if (followplayer)
plr->message = (AMSTR_FOLLOWON);
else
plr->message = (AMSTR_FOLLOWOFF);
*/
} else if (key == key_map_grid) {
grid = !grid;
/* LATER
if (grid)
plr->message = (AMSTR_GRIDON);
else
plr->message = (AMSTR_GRIDOFF);
} else if (key == key_map_mark) {
*/
}
/* LATER
else if (key == key_map_mark) {
M_snprintf(buffer, sizeof(buffer), "%s %d", (AMSTR_MARKEDSPOT),
markpointnum);
plr->message = buffer;
@@ -509,6 +573,7 @@ boolean AM_Responder(event_t *ev) {
rc = false;
cheating = (cheating + 1) % 3;
}
*/
} else if (ev->type == ev_keyup) {
rc = false;
key = ev->data1;
@@ -529,25 +594,56 @@ boolean AM_Responder(event_t *ev) {
mtof_zoommul = FRACUNIT;
ftom_zoommul = FRACUNIT;
}
*/
}
if (bigstate) {} // DELETEME JOSEF prevent no unused var
return rc;
}
//
// Zooming
//
void AM_changeWindowScale(void) {
// Change the scaling multipliers
scale_mtof = FixedMul(scale_mtof, mtof_zoommul);
scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
if (scale_mtof < min_scale_mtof)
AM_minOutWindowScale();
else if (scale_mtof > max_scale_mtof)
AM_maxOutWindowScale();
else
AM_activateNewScale();
}
//
//
//
void AM_doFollowPlayer(void) {
if (f_oldloc.x != am_playerpos.x || f_oldloc.y != am_playerpos.y) {
m_x = FTOM(MTOF(am_playerpos.x)) - m_w / 2;
m_y = FTOM(MTOF(am_playerpos.y)) - m_h / 2;
m_x2 = m_x + m_w;
m_y2 = m_y + m_h;
f_oldloc.x = am_playerpos.x;
f_oldloc.y = am_playerpos.y;
// m_x = FTOM(MTOF(plr->mo->x - m_w/2));
// m_y = FTOM(MTOF(plr->mo->y - m_h/2));
// m_x = plr->mo->x - m_w/2;
// m_y = plr->mo->y - m_h/2;
}
}
//
// Updates on Game Tick
//
void AM_Ticker(void) {
// ipuprint("TICK!\n");
if (!automapactive)
return;
amclock++;
/* LATER
if (followplayer)
AM_doFollowPlayer();
@@ -560,8 +656,6 @@ void AM_Ticker(void) {
if (m_paninc.x || m_paninc.y)
AM_changeWindowLoc();
*/
// Update light level
// AM_updateLightLev(); // NOT JOSEF
}
@@ -764,18 +858,57 @@ void AM_drawMline(mline_t *ml, int color) {
AM_drawFline(&fl, color); // draws it on frame buffer using fb coords
}
//
// Draws flat (floor/ceiling tile) aligned grid lines.
//
void AM_drawGrid(int color) {
fixed_t x, y;
fixed_t start, end;
mline_t ml;
// Figure out start of vertical gridlines
start = m_x;
if ((start - bmaporgx) % (MAPBLOCKUNITS << FRACBITS))
start += (MAPBLOCKUNITS << FRACBITS) -
((start - bmaporgx) % (MAPBLOCKUNITS << FRACBITS));
end = m_x + m_w;
// draw vertical gridlines
ml.a.y = m_y;
ml.b.y = m_y + m_h;
for (x = start; x < end; x += (MAPBLOCKUNITS << FRACBITS)) {
ml.a.x = x;
ml.b.x = x;
AM_drawMline(&ml, color);
}
// Figure out start of horizontal gridlines
start = m_y;
if ((start - bmaporgy) % (MAPBLOCKUNITS << FRACBITS))
start += (MAPBLOCKUNITS << FRACBITS) -
((start - bmaporgy) % (MAPBLOCKUNITS << FRACBITS));
end = m_y + m_h;
// draw horizontal gridlines
ml.a.x = m_x;
ml.b.x = m_x + m_w;
for (y = start; y < end; y += (MAPBLOCKUNITS << FRACBITS)) {
ml.a.y = y;
ml.b.y = y;
AM_drawMline(&ml, color);
}
}
void AM_Drawer(pixel_t* fb_tensor) {
fb = fb_tensor; // JOSEF
// if (!automapactive) // LATER
// return;
if (!automapactive)
return;
AM_clearFB(BACKGROUND);
// if (grid) // LATER
// AM_drawGrid(GRIDCOLORS);
if (grid)
AM_drawGrid(GRIDCOLORS);
// mline_t ln = {{0, 0}, {10<< FRACBITS, 20<< FRACBITS}};

View File

@@ -20,7 +20,7 @@
#ifndef __I_SWAP__
#define __I_SWAP__
#include "SDL2/SDL_endian.h"
// #include "SDL2/SDL_endian.h" // JOSEF
// Endianess handling.
// WAD files are stored little endian.
@@ -30,14 +30,15 @@
// These are deliberately cast to signed values; this is the behaviour
// of the macros in the original source and some code relies on it.
#define SHORT(x) ((signed short) SDL_SwapLE16(x))
#define LONG(x) ((signed int) SDL_SwapLE32(x))
// #define SHORT(x) ((signed short) SDL_SwapLE16(x)) // JOSEF
// #define LONG(x) ((signed int) SDL_SwapLE32(x)) // JOSEF
#define SHORT(x) ((signed short) x)
// Defines for checking the endianness of the system.
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
#define SYS_BIG_ENDIAN
#endif
// #if SDL_BYTEORDER == SDL_BIG_ENDIAN
// #define SYS_BIG_ENDIAN
// #endif
#endif

View File

@@ -1,6 +1,7 @@
#include "d_mode.h"
#include "doomstat.h"
#include "i_swap.h"
#include "r_defs.h"
#include "p_local.h"
@@ -72,7 +73,7 @@ mapthing_t *deathmatch_p;
mapthing_t playerstarts[MAXPLAYERS];
//
// P_LoadVertexes
//
void P_LoadVertexes(const unsigned char *buf) {
@@ -102,20 +103,54 @@ void P_LoadVertexes(const unsigned char *buf) {
li->y = ml->y << FRACBITS;
}
ipuprint("numvertexes: ");
ipuprintnum(numvertexes);
ipuprint(", 1x: ");
ipuprintnum(vertexes[0].x);
ipuprint(", -1y: ");
ipuprintnum(vertexes[numvertexes-1].y);
ipuprint("\n");
// Free buffer memory.
// JOSEF: W_ReleaseLumpNum(lump);
requestedlumpnum = gamelumpnum + ML_SECTORS;
}
//
// P_LoadSectors
//
void P_LoadSectors(const unsigned char *buf) {
byte *data;
int i;
mapsector_t *ms;
sector_t *ss;
int lumplen = ((int*)buf)[0];
numsectors = lumplen / sizeof(mapsector_t);
sectors = IPU_level_malloc(numsectors * sizeof(sector_t));
memset(sectors, 0, numsectors * sizeof(sector_t));
ms = (mapsector_t *)(&buf[sizeof(int)]);
ss = sectors;
for (i = 0; i < numsectors; i++, ss++, ms++) {
ss->floorheight = SHORT(ms->floorheight) << FRACBITS;
ss->ceilingheight = SHORT(ms->ceilingheight) << FRACBITS;
// ss->floorpic = R_FlatNumForName(ms->floorpic); // LATER
// ss->ceilingpic = R_FlatNumForName(ms->ceilingpic); // LATER
ss->lightlevel = SHORT(ms->lightlevel);
ss->special = SHORT(ms->special);
ss->tag = SHORT(ms->tag);
ss->thinglist = NULL;
}
ipuprint("numsectors: ");
ipuprintnum(numsectors);
ipuprint(", floor0: ");
ipuprintnum(sectors[0].floorheight);
ipuprint(", ceil0: ");
ipuprintnum(sectors[0].ceilingheight);
ipuprint(", floor-1: ");
ipuprintnum(sectors[numsectors-1].floorheight);
ipuprint(", ceil-1: ");
ipuprintnum(sectors[numsectors-1].ceilingheight);
ipuprint("\n");
requestedlumpnum = gamelumpnum + ML_SIDEDEFS;
}
//
// P_SetupLevel

View File

@@ -7,6 +7,7 @@ extern "C" {
void P_SetupLevel_pt0(void);
void P_LoadBlockMap(const unsigned char *buf);
void P_LoadVertexes(const unsigned char *buf);
void P_LoadSectors(const unsigned char *buf);
};
@@ -42,3 +43,15 @@ class P_LoadVertexes_Vertex : public poplar::Vertex {
return true;
}
};
class P_LoadSectors_Vertex : public poplar::Vertex {
poplar::Input<poplar::Vector<unsigned char>> lumpBuf;
poplar::Output<int> lumpNum;
public:
bool compute() {
P_LoadSectors(&lumpBuf[0]);
*lumpNum = requestedlumpnum;
return true;
}
};

View File

@@ -139,6 +139,12 @@ void IpuDoom::buildIpuGraph() {
m_ipuGraph.setTileMapping(vtx, 0);
m_ipuGraph.setPerfEstimate(vtx, 100);
poplar::ComputeSet P_LoadSectors_CS = m_ipuGraph.addComputeSet("P_LoadSectors_CS");
vtx = m_ipuGraph.addVertex(P_LoadSectors_CS, "P_LoadSectors_Vertex", {
{"lumpNum", m_lumpNum}, {"lumpBuf", m_lumpBuf}});
m_ipuGraph.setTileMapping(vtx, 0);
m_ipuGraph.setPerfEstimate(vtx, 100);
poplar::program::Sequence G_DoLoadLevel_prog({
poplar::program::Copy(miscValuesStream, m_miscValuesBuf),
@@ -150,9 +156,10 @@ void IpuDoom::buildIpuGraph() {
poplar::program::Copy(m_lumpNum, lumpNumStream),
poplar::program::Copy(lumpBufStream, m_lumpBuf),
poplar::program::Execute(P_LoadVertexes_CS),
poplar::program::Copy(m_lumpNum, lumpNumStream),
poplar::program::Copy(lumpBufStream, m_lumpBuf),
poplar::program::Execute(P_LoadSectors_CS),
GetPrintbuf_prog,
// poplar::program::Copy(lumpStream, m_lumpBuf),
// poplar::program::Execute(IPU_UnpackLineDefs_CS),
});
// ---------------- G_Ticker --------------//

View File

@@ -137,9 +137,6 @@ void P_LoadVertexes(int lump) {
li->y = SHORT(ml->y) << FRACBITS;
}
printf("[CPU] numvertexes: %d, 1x: %d, -1y:%d\n",
numvertexes, vertexes[0].x, vertexes[numvertexes-1].y);
// Free buffer memory.
W_ReleaseLumpNum(lump);
}
@@ -276,6 +273,9 @@ void P_LoadSectors(int lump) {
ss->thinglist = NULL;
}
printf("[CPU] numsectors: %d, floor0: %d, ceil0: %d, floor-1: %d, ceil-1: %d\n",
numsectors, sectors[0].floorheight, sectors[0].ceilingheight, sectors[numsectors-1].floorheight, sectors[numsectors-1].ceilingheight);
W_ReleaseLumpNum(lump);
}