- adapted the breakable stuff interface in Duke to Texture IDs.

This commit is contained in:
Christoph Oelckers 2022-12-08 22:49:02 +01:00
parent f3e652da84
commit ee8b685fe2
5 changed files with 53 additions and 41 deletions

View file

@ -358,29 +358,29 @@ void FMapInfoParser::ParseBreakWall()
sc.MustGetStringName("{"); sc.MustGetStringName("{");
while (!sc.CheckString("}")) while (!sc.CheckString("}"))
{ {
int basetile = -1; FTextureID basetile = FNullTextureID();
int breaktile = -1; FTextureID breaktile = FNullTextureID();
int flags = 0; int flags = 0;
FSoundID sound = NO_SOUND; FSoundID sound = NO_SOUND;
VMFunction* handler = nullptr; VMFunction* handler = nullptr;
sc.MustGetString(); sc.MustGetString();
FString basename = sc.String; // save for printing error messages. FString basename = sc.String; // save for printing error messages.
basetile = tileForName(sc.String); basetile = TexMan.CheckForTexture(sc.String, ETextureType::Any);
if (basetile < 0) if (!basetile.isValid())
{ {
sc.ScriptMessage("Unknown texture '%s' in breakwall definition", sc.String, basetile); sc.ScriptMessage("Unknown texture '%s' in breakwall definition", sc.String);
SkipToNext(); SkipToNext();
} }
ParseAssign(); ParseAssign();
sc.MustGetString(); sc.MustGetString();
breaktile = tileForName(sc.String); breaktile = TexMan.CheckForTexture(sc.String, ETextureType::Any);
if (*sc.String && breaktile < 0) sc.ScriptMessage("Unknown texture '%s' in breakwall definition", sc.String, breaktile); if (*sc.String && !breaktile.isValid()) sc.ScriptMessage("Unknown texture '%s' in breakwall definition", sc.String);
if (sc.CheckString(",")) if (sc.CheckString(","))
{ {
sc.MustGetString(); sc.MustGetString();
sound = S_FindSound(sc.String); sound = S_FindSound(sc.String);
if (*sc.String && !sound.isvalid()) Printf(TEXTCOLOR_RED "Unknown sound '%s' in definition for breakable wall '5s'\n", basename.GetChars()); if (*sc.String && !sound.isvalid()) sc.ScriptMessage("Unknown sound '%s' in definition for breakable wall '5s'\n", basename.GetChars());
auto saved = sc.SavePos(); auto saved = sc.SavePos();
if (sc.CheckString(",")) if (sc.CheckString(","))
@ -407,7 +407,7 @@ void FMapInfoParser::ParseBreakWall()
} }
} }
} }
breakWallMap.Insert(basetile, { breaktile, sound, handler, flags }); breakWallMap.Insert(basetile.GetIndex(), {breaktile, sound, handler, flags});
} }
} }
@ -423,29 +423,29 @@ void FMapInfoParser::ParseBreakCeiling()
sc.MustGetStringName("{"); sc.MustGetStringName("{");
while (!sc.CheckString("}")) while (!sc.CheckString("}"))
{ {
int basetile = -1; FTextureID basetile = FNullTextureID();
int breaktile = -1; FTextureID breaktile = FNullTextureID();
int flags = 0; int flags = 0;
FSoundID sound = NO_SOUND; FSoundID sound = NO_SOUND;
VMFunction* handler = nullptr; VMFunction* handler = nullptr;
sc.MustGetString(); sc.MustGetString();
FString basename = sc.String; // save for printing error messages. FString basename = sc.String; // save for printing error messages.
basetile = tileForName(sc.String); basetile = TexMan.CheckForTexture(sc.String, ETextureType::Any);
if (basetile < 0) if (!basetile.isValid())
{ {
sc.ScriptMessage("Unknown texture '%s' in breakceiling definition", sc.String, basetile); sc.ScriptMessage("Unknown texture '%s' in breakceiling definition", sc.String);
SkipToNext(); SkipToNext();
} }
ParseAssign(); ParseAssign();
sc.MustGetString(); sc.MustGetString();
breaktile = tileForName(sc.String); breaktile = TexMan.CheckForTexture(sc.String, ETextureType::Any);
if (*sc.String && breaktile < 0) sc.ScriptMessage("Unknown texture '%s' in breakceiling definition", sc.String, breaktile); if (*sc.String && !breaktile.isValid()) sc.ScriptMessage("Unknown texture '%s' in breakceiling definition", sc.String);
if (sc.CheckString(",")) if (sc.CheckString(","))
{ {
sc.MustGetString(); sc.MustGetString();
sound = S_FindSound(sc.String); sound = S_FindSound(sc.String);
if (*sc.String && !sound.isvalid()) Printf(TEXTCOLOR_RED "Unknown sound '%s' in definition for breakable ceiling '5s'\n", basename.GetChars()); if (*sc.String && !sound.isvalid()) sc.ScriptMessage("Unknown sound '%s' in definition for breakable ceiling '5s'\n", basename.GetChars());
auto saved = sc.SavePos(); auto saved = sc.SavePos();
if (sc.CheckString(",")) if (sc.CheckString(","))
@ -472,7 +472,7 @@ void FMapInfoParser::ParseBreakCeiling()
} }
} }
} }
breakCeilingMap.Insert(basetile, { breaktile, sound, handler, flags }); breakCeilingMap.Insert(basetile.GetIndex(), {breaktile, sound, handler, flags});
} }
} }

View file

@ -57,7 +57,7 @@ inline SpawnMap spawnMap;
struct BreakWallRec struct BreakWallRec
{ {
int brokentex; FTextureID brokentex;
FSoundID breaksound; FSoundID breaksound;
VMFunction* handler; VMFunction* handler;
int flags; int flags;

View file

@ -496,9 +496,11 @@ DEFINE_ACTION_FUNCTION_NATIVE(_sectortype, checktexture, sector_checktexture)
void sector_settexturename(sectortype* sec, int place, int intname) void sector_settexturename(sectortype* sec, int place, int intname)
{ {
if (!sec) ThrowAbortException(X_READ_NIL, nullptr); if (!sec) ThrowAbortException(X_READ_NIL, nullptr);
int tilenum = tileForName(FName(ENamedName(intname)).GetChars()); FTextureID texid = TexMan.CheckForTexture(FName(ENamedName(intname)).GetChars(), ETextureType::Any);
(place == 0 ? sec->ceilingpicnum : sec->floorpicnum) = tilenum; if (place == 0) sec->setceilingtexture(texid);
else sec->setfloortexture(texid);
} }
DEFINE_ACTION_FUNCTION_NATIVE(_sectortype, settexturename, sector_settexturename) DEFINE_ACTION_FUNCTION_NATIVE(_sectortype, settexturename, sector_settexturename)
{ {
PARAM_SELF_STRUCT_PROLOGUE(sectortype); PARAM_SELF_STRUCT_PROLOGUE(sectortype);
@ -508,12 +510,15 @@ DEFINE_ACTION_FUNCTION_NATIVE(_sectortype, settexturename, sector_settexturename
return 0; return 0;
} }
// This is declared as TextureID but for now receives a tilenum void sector_settexture(sectortype* sec, int place, int inttexid)
void sector_settexture(sectortype* sec, int place, int tilenum)
{ {
if (!sec) ThrowAbortException(X_READ_NIL, nullptr); if (!sec) ThrowAbortException(X_READ_NIL, nullptr);
(place == 0 ? sec->ceilingpicnum : sec->floorpicnum) = tilenum;
FSetTextureID texid(inttexid);
if (place == 0) sec->setceilingtexture(texid);
else sec->setfloortexture(texid);
} }
DEFINE_ACTION_FUNCTION_NATIVE(_sectortype, settexture, sector_settexture) DEFINE_ACTION_FUNCTION_NATIVE(_sectortype, settexture, sector_settexture)
{ {
PARAM_SELF_STRUCT_PROLOGUE(sectortype); PARAM_SELF_STRUCT_PROLOGUE(sectortype);
@ -724,9 +729,11 @@ DEFINE_ACTION_FUNCTION_NATIVE(_walltype, twosided, wall_twosided)
void wall_settexturename(walltype* sec, int place, int intname) void wall_settexturename(walltype* sec, int place, int intname)
{ {
if (!sec) ThrowAbortException(X_READ_NIL, nullptr); if (!sec) ThrowAbortException(X_READ_NIL, nullptr);
int tilenum = tileForName(FName(ENamedName(intname)).GetChars()); FTextureID texid = TexMan.CheckForTexture(FName(ENamedName(intname)).GetChars(), ETextureType::Any);
(place ? sec->overpicnum : sec->wallpicnum) = tilenum; if (place == 0) sec->setwalltexture(texid);
else sec->setovertexture(texid);
} }
DEFINE_ACTION_FUNCTION_NATIVE(_walltype, settexturename, wall_settexturename) DEFINE_ACTION_FUNCTION_NATIVE(_walltype, settexturename, wall_settexturename)
{ {
PARAM_SELF_STRUCT_PROLOGUE(walltype); PARAM_SELF_STRUCT_PROLOGUE(walltype);
@ -736,11 +743,13 @@ DEFINE_ACTION_FUNCTION_NATIVE(_walltype, settexturename, wall_settexturename)
return 0; return 0;
} }
// This is declared as TextureID but for now receives a tilenum void wall_settexture(walltype* sec, int place, int inttexid)
void wall_settexture(walltype* sec, int place, int tilenum)
{ {
if (!sec) ThrowAbortException(X_READ_NIL, nullptr); if (!sec) ThrowAbortException(X_READ_NIL, nullptr);
(place ? sec->overpicnum : sec->wallpicnum) = tilenum;
FSetTextureID texid(inttexid);
if (place == 0) sec->setwalltexture(texid);
else sec->setovertexture(texid);
} }
DEFINE_ACTION_FUNCTION_NATIVE(_walltype, settexture, wall_settexture) DEFINE_ACTION_FUNCTION_NATIVE(_walltype, settexture, wall_settexture)
{ {

View file

@ -2696,10 +2696,12 @@ void handle_se128(DDukeActor *actor)
} }
// else return; // else return;
wal->overpicnum++; auto data = breakWallMap.CheckKey(wal->overtexture().GetIndex());
FTextureID newtex = data? data->brokentex : FNullTextureID();
wal->setovertexture(newtex);
auto nextwal = wal->nextWall(); auto nextwal = wal->nextWall();
if (nextwal) if (nextwal)
nextwal->overpicnum++; nextwal->setovertexture(newtex);
if (actor->temp_data[0] < actor->temp_data[1]) actor->temp_data[0]++; if (actor->temp_data[0] < actor->temp_data[1]) actor->temp_data[0]++;
else else

View file

@ -1283,34 +1283,35 @@ void checkhitwall(DDukeActor* spr, walltype* wal, const DVector3& pos)
return; return;
} }
auto handler = [=](const BreakWallRec* data, int16_t* pic) auto handler = [=](const BreakWallRec* data) ->bool
{ {
if (!data->handler) if (!data->handler)
{ {
*pic = data->brokentex;
S_PlayActorSound(data->breaksound, spr); S_PlayActorSound(data->breaksound, spr);
return true;
} }
else else
{ {
VMValue args[7] = { wal, data->brokentex, data->breaksound.index(), spr, pos.X, pos.Y, pos.Z }; VMValue args[7] = { wal, data->brokentex.GetIndex(), data->breaksound.index(), spr, pos.X, pos.Y, pos.Z};
VMCall(data->handler, args, 7, nullptr, 0); VMCall(data->handler, args, 7, nullptr, 0);
} }
return false;
}; };
if (wal->twoSided() && wal->nextSector()->floorz > pos.Z && wal->nextSector()->floorz - wal->nextSector()->ceilingz) if (wal->twoSided() && wal->nextSector()->floorz > pos.Z && wal->nextSector()->floorz - wal->nextSector()->ceilingz)
{ {
auto data = breakWallMap.CheckKey(wal->overpicnum); auto data = breakWallMap.CheckKey(wal->overtexture().GetIndex());
if (data && (data->flags & 1) && (!(data->flags & 2) || wal->cstat & CSTAT_WALL_MASKED)) if (data && (data->flags & 1) && (!(data->flags & 2) || wal->cstat & CSTAT_WALL_MASKED))
{ {
handler(data, &wal->overpicnum); if (handler(data)) wal->setovertexture(data->brokentex);
} }
} }
auto data = breakWallMap.CheckKey(wal->wallpicnum); auto data = breakWallMap.CheckKey(wal->walltexture().GetIndex());
if (data && !(data->flags & 1)) if (data && !(data->flags & 1))
{ {
handler(data, &wal->wallpicnum); if (handler(data)) wal->setwalltexture(data->brokentex);
} }
} }
@ -1322,17 +1323,17 @@ void checkhitwall(DDukeActor* spr, walltype* wal, const DVector3& pos)
bool checkhitceiling(sectortype* sectp) bool checkhitceiling(sectortype* sectp)
{ {
auto data = breakCeilingMap.CheckKey(sectp->ceilingpicnum); auto data = breakCeilingMap.CheckKey(sectp->ceilingtexture().GetIndex());
if (data && !(data->flags & 1)) if (data && !(data->flags & 1))
{ {
if (!data->handler) if (!data->handler)
{ {
sectp->ceilingpicnum = data->brokentex; sectp->setceilingtexture(data->brokentex);
S_PlayActorSound(data->breaksound, ps[screenpeek].GetActor()); // this is nonsense but what the original code did. S_PlayActorSound(data->breaksound, ps[screenpeek].GetActor()); // this is nonsense but what the original code did.
} }
else else
{ {
VMValue args[7] = { sectp, data->brokentex, data->breaksound.index() }; VMValue args[7] = { sectp, data->brokentex.GetIndex(), data->breaksound.index()};
VMCall(data->handler, args, 3, nullptr, 0); VMCall(data->handler, args, 3, nullptr, 0);
} }
if (data->flags & 1) if (data->flags & 1)