Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/rheit/zdoom
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Oelckers committed Sep 17, 2016
2 parents 80c1baa + 476b727 commit 6b4aee2
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 28 deletions.
66 changes: 60 additions & 6 deletions src/c_cmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -923,10 +923,21 @@ static bool IsActorACountItem(AActor *mo)
return mo->IsKindOf(RUNTIME_CLASS(AInventory)) && mo->flags&MF_SPECIAL && mo->flags&MF_COUNTITEM;
}

static void PrintFilteredActorList(const ActorTypeChecker IsActorType, const char *FilterName)
// [SP] for all actors
static bool IsActor(AActor *mo)
{
if (mo->IsKindOf(RUNTIME_CLASS(AInventory)))
return static_cast<AInventory *>(mo)->Owner == NULL; // [SP] Exclude inventory-owned items
else
return true;
}

// [SP] modified - now allows showing count only, new arg must be passed. Also now still counts regardless, if lists are printed.
static void PrintFilteredActorList(const ActorTypeChecker IsActorType, const char *FilterName, bool countOnly)
{
AActor *mo;
const PClass *FilterClass = NULL;
int counter = 0;

if (FilterName != NULL)
{
Expand All @@ -943,10 +954,32 @@ static void PrintFilteredActorList(const ActorTypeChecker IsActorType, const cha
{
if ((FilterClass == NULL || mo->IsA(FilterClass)) && IsActorType(mo))
{
Printf ("%s at (%f,%f,%f)\n",
mo->GetClass()->TypeName.GetChars(), mo->X(), mo->Y(), mo->Z());
counter++;
if (!countOnly)
Printf ("%s at (%f,%f,%f)\n",
mo->GetClass()->TypeName.GetChars(), mo->X(), mo->Y(), mo->Z());
}
}
Printf("%i match(s) found.\n", counter);
}

//-----------------------------------------------------------------------------
//
//
//
//-----------------------------------------------------------------------------
CCMD(actorlist) // [SP] print all actors (this can get quite big?)
{
if (CheckCheatmode ()) return;

PrintFilteredActorList(IsActor, argv.argc() > 1 ? argv[1] : NULL, false);
}

CCMD(actornum) // [SP] count all actors
{
if (CheckCheatmode ()) return;

PrintFilteredActorList(IsActor, argv.argc() > 1 ? argv[1] : NULL, true);
}

//-----------------------------------------------------------------------------
Expand All @@ -958,7 +991,14 @@ CCMD(monster)
{
if (CheckCheatmode ()) return;

PrintFilteredActorList(IsActorAMonster, argv.argc() > 1 ? argv[1] : NULL);
PrintFilteredActorList(IsActorAMonster, argv.argc() > 1 ? argv[1] : NULL, false);
}

CCMD(monsternum) // [SP] count monsters
{
if (CheckCheatmode ()) return;

PrintFilteredActorList(IsActorAMonster, argv.argc() > 1 ? argv[1] : NULL, true);
}

//-----------------------------------------------------------------------------
Expand All @@ -970,7 +1010,14 @@ CCMD(items)
{
if (CheckCheatmode ()) return;

PrintFilteredActorList(IsActorAnItem, argv.argc() > 1 ? argv[1] : NULL);
PrintFilteredActorList(IsActorAnItem, argv.argc() > 1 ? argv[1] : NULL, false);
}

CCMD(itemsnum) // [SP] # of any items
{
if (CheckCheatmode ()) return;

PrintFilteredActorList(IsActorAnItem, argv.argc() > 1 ? argv[1] : NULL, true);
}

//-----------------------------------------------------------------------------
Expand All @@ -982,7 +1029,14 @@ CCMD(countitems)
{
if (CheckCheatmode ()) return;

PrintFilteredActorList(IsActorACountItem, argv.argc() > 1 ? argv[1] : NULL);
PrintFilteredActorList(IsActorACountItem, argv.argc() > 1 ? argv[1] : NULL, false);
}

CCMD(countitemsnum) // [SP] # of counted items
{
if (CheckCheatmode ()) return;

PrintFilteredActorList(IsActorACountItem, argv.argc() > 1 ? argv[1] : NULL, true);
}

//-----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/g_shared/shared_hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ void DrawHUD()
}
else
{
if (CheckRatio(SCREENWIDTH, SCREENHEIGHT) == 4)
if (AspectTallerThanWide(WidescreenRatio))
{
hudheight = hudwidth * 30 / AspectMultiplier(WidescreenRatio); // BaseRatioSizes is inverted for this mode
}
Expand Down
24 changes: 12 additions & 12 deletions src/menu/videomenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ CUSTOM_CVAR (Int, menu_screenratios, -1, CVAR_ARCHIVE)
}
else
{
BuildModesList (SCREENWIDTH, SCREENHEIGHT, DisplayBits);
BuildModesList (screen->VideoWidth, screen->VideoHeight, DisplayBits);
}
}

Expand Down Expand Up @@ -139,7 +139,7 @@ class DVideoModeMenu : public DOptionMenu

DVideoModeMenu()
{
SetModesMenu (SCREENWIDTH, SCREENHEIGHT, DisplayBits);
SetModesMenu (screen->VideoWidth, screen->VideoHeight, DisplayBits);
}

bool MenuEvent(int mkey, bool fromcontroller)
Expand All @@ -163,13 +163,13 @@ class DVideoModeMenu : public DOptionMenu
{
if (!GetSelectedSize (&NewWidth, &NewHeight))
{
NewWidth = SCREENWIDTH;
NewHeight = SCREENHEIGHT;
NewWidth = screen->VideoWidth;
NewHeight = screen->VideoHeight;
}
else
{
OldWidth = SCREENWIDTH;
OldHeight = SCREENHEIGHT;
OldWidth = screen->VideoWidth;
OldHeight = screen->VideoHeight;
OldBits = DisplayBits;
NewBits = BitTranslate[DummyDepthCvar];
setmodeneeded = true;
Expand Down Expand Up @@ -297,11 +297,11 @@ void M_RestoreMode ()
void M_SetDefaultMode ()
{
// Make current resolution the default
vid_defwidth = SCREENWIDTH;
vid_defheight = SCREENHEIGHT;
vid_defwidth = screen->VideoWidth;
vid_defheight = screen->VideoHeight;
vid_defbits = DisplayBits;
testingmode = 0;
SetModesMenu (SCREENWIDTH, SCREENHEIGHT, DisplayBits);
SetModesMenu (screen->VideoWidth, screen->VideoHeight, DisplayBits);
}


Expand All @@ -314,7 +314,7 @@ void M_SetDefaultMode ()

void M_RefreshModesList ()
{
BuildModesList (SCREENWIDTH, SCREENHEIGHT, DisplayBits);
BuildModesList (screen->VideoWidth, screen->VideoHeight, DisplayBits);
}

void M_InitVideoModesMenu ()
Expand Down Expand Up @@ -385,8 +385,8 @@ void M_SetVideoMode()
{
if (!GetSelectedSize (&NewWidth, &NewHeight))
{
NewWidth = SCREENWIDTH;
NewHeight = SCREENHEIGHT;
NewWidth = screen->VideoWidth;
NewHeight = screen->VideoHeight;
}
else
{
Expand Down
4 changes: 4 additions & 0 deletions src/v_video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,9 @@ DFrameBuffer::DFrameBuffer (int width, int height)
{
LastMS = LastSec = FrameCount = LastCount = LastTic = 0;
Accel2D = false;

VideoWidth = width;
VideoHeight = height;
}

//==========================================================================
Expand Down Expand Up @@ -1352,6 +1355,7 @@ void V_OutputResized (int width, int height)
{
StatusBar->ScreenSizeChanged();
}
C_NewModeAdjust();
}

void V_CalcCleanFacs (int designwidth, int designheight, int realwidth, int realheight, int *cleanx, int *cleany, int *_cx1, int *_cx2)
Expand Down
4 changes: 4 additions & 0 deletions src/v_video.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,10 @@ class DFrameBuffer : public DSimpleCanvas
virtual bool Is8BitMode() = 0;
#endif

// The original size of the framebuffer as selected in the video menu.
int VideoWidth = 0;
int VideoHeight = 0;

protected:
void DrawRateStuff ();
void CopyFromBuff (BYTE *src, int srcPitch, int width, int height, BYTE *dest);
Expand Down
9 changes: 9 additions & 0 deletions src/zscript/vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ enum
ATAG_RNG, // pointer to FRandom
};

enum EVMAbortException
{
X_READ_NIL,
X_WRITE_NIL,
X_TOO_MANY_TRIES,
X_ARRAY_OUT_OF_BOUNDS,
X_DIVISION_BY_ZERO,
};

class VMFunction : public DObject
{
DECLARE_ABSTRACT_CLASS(VMFunction, DObject);
Expand Down
10 changes: 1 addition & 9 deletions src/zscript/vmexec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#define ASSERTKA(x) assert(sfunc != NULL && (unsigned)(x) < sfunc->NumKonstA)
#define ASSERTKS(x) assert(sfunc != NULL && (unsigned)(x) < sfunc->NumKonstS)

#define THROW(x)
#define THROW(x) throw(EVMAbortException(x))

#define CMPJMP(test) \
if ((test) == (a & CMP_CHECK)) { \
Expand All @@ -54,14 +54,6 @@
pc += 1; \
}

enum
{
X_READ_NIL,
X_WRITE_NIL,
X_TOO_MANY_TRIES,
X_ARRAY_OUT_OF_BOUNDS
};

#define GETADDR(a,o,x) \
if (a == NULL) { THROW(x); } \
ptr = (VM_SBYTE *)a + o
Expand Down
40 changes: 40 additions & 0 deletions src/zscript/vmexec.h
Original file line number Diff line number Diff line change
Expand Up @@ -786,27 +786,51 @@ static int Exec(VMFrameStack *stack, const VMOP *pc, VMReturn *ret, int numret)

OP(DIV_RR):
ASSERTD(a); ASSERTD(B); ASSERTD(C);
if (reg.d[C] == 0)
{
THROW(X_DIVISION_BY_ZERO);
}
reg.d[a] = reg.d[B] / reg.d[C];
NEXTOP;
OP(DIV_RK):
ASSERTD(a); ASSERTD(B); ASSERTKD(C);
if (konstd[C] == 0)
{
THROW(X_DIVISION_BY_ZERO);
}
reg.d[a] = reg.d[B] / konstd[C];
NEXTOP;
OP(DIV_KR):
ASSERTD(a); ASSERTKD(B); ASSERTD(C);
if (reg.d[C] == 0)
{
THROW(X_DIVISION_BY_ZERO);
}
reg.d[a] = konstd[B] / reg.d[C];
NEXTOP;

OP(MOD_RR):
ASSERTD(a); ASSERTD(B); ASSERTD(C);
if (reg.d[C] == 0)
{
THROW(X_DIVISION_BY_ZERO);
}
reg.d[a] = reg.d[B] % reg.d[C];
NEXTOP;
OP(MOD_RK):
ASSERTD(a); ASSERTD(B); ASSERTKD(C);
if (konstd[C] == 0)
{
THROW(X_DIVISION_BY_ZERO);
}
reg.d[a] = reg.d[B] % konstd[C];
NEXTOP;
OP(MOD_KR):
ASSERTD(a); ASSERTKD(B); ASSERTD(C);
if (reg.d[C] == 0)
{
THROW(X_DIVISION_BY_ZERO);
}
reg.d[a] = konstd[B] % reg.d[C];
NEXTOP;

Expand Down Expand Up @@ -981,21 +1005,37 @@ static int Exec(VMFrameStack *stack, const VMOP *pc, VMReturn *ret, int numret)

OP(DIVF_RR):
ASSERTF(a); ASSERTF(B); ASSERTF(C);
if (reg.f[C] == 0.)
{
THROW(X_DIVISION_BY_ZERO);
}
reg.f[a] = reg.f[B] / reg.f[C];
NEXTOP;
OP(DIVF_RK):
ASSERTF(a); ASSERTF(B); ASSERTKF(C);
if (konstf[C] == 0.)
{
THROW(X_DIVISION_BY_ZERO);
}
reg.f[a] = reg.f[B] / konstf[C];
NEXTOP;
OP(DIVF_KR):
ASSERTF(a); ASSERTKF(B); ASSERTF(C);
if (reg.f[C] == 0.)
{
THROW(X_DIVISION_BY_ZERO);
}
reg.f[a] = konstf[B] / reg.f[C];
NEXTOP;

OP(MODF_RR):
ASSERTF(a); ASSERTF(B); ASSERTF(C);
fb = reg.f[B]; fc = reg.f[C];
Do_MODF:
if (fc == 0.)
{
THROW(X_DIVISION_BY_ZERO);
}
reg.f[a] = luai_nummod(fb, fc);
NEXTOP;
OP(MODF_RK):
Expand Down
38 changes: 38 additions & 0 deletions src/zscript/vmframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,44 @@ int VMFrameStack::Call(VMFunction *func, VMValue *params, int numparams, VMRetur
}
throw;
}
catch (EVMAbortException exception)
{
if (allocated)
{
PopFrame();
}
if (trap != nullptr)
{
*trap = nullptr;
}

Printf("VM execution aborted: ");
switch (exception)
{
case X_READ_NIL:
Printf("tried to read from address zero.");
break;

case X_WRITE_NIL:
Printf("tried to write to address zero.");
break;

case X_TOO_MANY_TRIES:
Printf("too many try-catch blocks.");
break;

case X_ARRAY_OUT_OF_BOUNDS:
Printf("array access out of bounds.");
break;

case X_DIVISION_BY_ZERO:
Printf("division by zero.");
break;
}
Printf("\n");

return -1;
}
catch (...)
{
if (allocated)
Expand Down

0 comments on commit 6b4aee2

Please sign in to comment.