Skip to content

Commit

Permalink
- refined wall sprite check so that orthogonally aligned sprites are …
Browse files Browse the repository at this point in the history
…only aligned to orthogonal walls.

Here even the slightest deviation can create problems.
  • Loading branch information
coelckers committed Aug 3, 2022
1 parent cac54d4 commit 7debab7
Show file tree
Hide file tree
Showing 17 changed files with 233 additions and 41 deletions.
10 changes: 5 additions & 5 deletions source/common/engine/sc_man.h
Expand Up @@ -12,27 +12,27 @@ struct VersionInfo
uint16_t minor;
uint32_t revision;

bool operator <=(const VersionInfo& o) const
constexpr bool operator <=(const VersionInfo& o) const
{
return o.major > this->major || (o.major == this->major && o.minor > this->minor) || (o.major == this->major && o.minor == this->minor && o.revision >= this->revision);
}
bool operator >=(const VersionInfo& o) const
constexpr bool operator >=(const VersionInfo& o) const
{
return o.major < this->major || (o.major == this->major && o.minor < this->minor) || (o.major == this->major && o.minor == this->minor && o.revision <= this->revision);
}
bool operator > (const VersionInfo& o) const
constexpr bool operator > (const VersionInfo& o) const
{
return o.major < this->major || (o.major == this->major && o.minor < this->minor) || (o.major == this->major && o.minor == this->minor && o.revision < this->revision);
}
bool operator < (const VersionInfo& o) const
constexpr bool operator < (const VersionInfo& o) const
{
return o.major > this->major || (o.major == this->major && o.minor > this->minor) || (o.major == this->major && o.minor == this->minor && o.revision > this->revision);
}
void operator=(const char* string);
};

// Cannot be a constructor because Lemon would puke on it.
inline VersionInfo MakeVersion(unsigned int ma, unsigned int mi, unsigned int re = 0)
constexpr VersionInfo MakeVersion(unsigned int ma, unsigned int mi, unsigned int re = 0)
{
return{ (uint16_t)ma, (uint16_t)mi, (uint32_t)re };
}
Expand Down
1 change: 1 addition & 0 deletions source/common/rendering/gl/gl_framebuffer.cpp
Expand Up @@ -484,6 +484,7 @@ void OpenGLFrameBuffer::SetSaveBuffers(bool yes)
void OpenGLFrameBuffer::BeginFrame()
{
SetViewportRects(nullptr);
mViewpoints->Clear();
if (GLRenderer != nullptr)
GLRenderer->BeginFrame();
}
Expand Down
14 changes: 11 additions & 3 deletions source/common/rendering/gl_load/gl_interface.cpp
Expand Up @@ -44,7 +44,8 @@

static TArray<FString> m_Extensions;
RenderContext gl;
static double realglversion; // this is public so the statistics code can access it.
static double realglversion;
static bool bindless;

//==========================================================================
//
Expand Down Expand Up @@ -156,7 +157,7 @@ void gl_LoadExtensions()
#ifdef _WIN32
if (strstr(gl.vendorstring, "ATI Tech"))
{
gl.flags |= RFL_NO_CLIP_PLANES; // gl_ClipDistance is horribly broken on ATI GL3 drivers for Windows. (TBD: Relegate to vintage build? Maybe after the next survey.)
gl.flags |= RFL_NO_CLIP_PLANES; // gl_ClipDistance is horribly broken on ATI GL3 drivers for Windows.
}
#endif
gl.glslversion = 3.31f; // Force GLSL down to 3.3.
Expand Down Expand Up @@ -201,6 +202,8 @@ void gl_LoadExtensions()

glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl.max_texturesize);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

bindless = CheckExtension("GL_ARB_bindless_texture");
}

//==========================================================================
Expand Down Expand Up @@ -247,9 +250,14 @@ void gl_PrintStartupLog()
}
}

void setGlVersion(double glv)
{
realglversion = glv;
}

std::pair<double, bool> gl_getInfo()
{
// gl_ARB_bindless_texture is the closest we can get to determine Vulkan support from OpenGL.
// This isn't foolproof because Intel doesn't support it but for NVidia and AMD support of this extension means Vulkan support.
return std::make_pair(realglversion, CheckExtension("GL_ARB_bindless_texture"));
return std::make_pair(realglversion, bindless);
}
1 change: 1 addition & 0 deletions source/common/rendering/gles/gles_framebuffer.cpp
Expand Up @@ -369,6 +369,7 @@ void OpenGLFrameBuffer::WaitForCommands(bool finish)
void OpenGLFrameBuffer::BeginFrame()
{
SetViewportRects(nullptr);
mViewpoints->Clear();
if (GLRenderer != nullptr)
GLRenderer->BeginFrame();
}
Expand Down
1 change: 1 addition & 0 deletions source/common/rendering/gles/gles_framebuffer.h
Expand Up @@ -22,6 +22,7 @@ class OpenGLFrameBuffer : public SystemGLFrameBuffer
explicit OpenGLFrameBuffer() {}
OpenGLFrameBuffer(void *hMonitor, bool fullscreen) ;
~OpenGLFrameBuffer();
int Backend() override { return 0; }

void InitializeState() override;
void Update() override;
Expand Down
5 changes: 5 additions & 0 deletions source/common/rendering/gles/gles_system.cpp
Expand Up @@ -9,6 +9,7 @@ CVAR(Bool, gles_use_mapped_buffer, false, 0);
CVAR(Bool, gles_force_glsl_v100, false, 0);
CVAR(Int, gles_max_lights_per_surface, 32, 0);
EXTERN_CVAR(Bool, gl_customshader);
void setGlVersion(double glv);


#if USE_GLES2
Expand Down Expand Up @@ -191,5 +192,9 @@ namespace OpenGLESRenderer
#endif

gles.numlightvectors = (gles.maxlights * LIGHT_VEC4_NUM);

const char* glversion = (const char*)glGetString(GL_VERSION);
setGlVersion( strtod(glversion, NULL));

}
}
Expand Up @@ -117,11 +117,16 @@ int HWViewpointBuffer::SetViewpoint(FRenderState &di, HWViewpointUniforms *vp)

void HWViewpointBuffer::Clear()
{
bool needNewPipeline = mUploadIndex > 0; // Clear might be called multiple times before any actual rendering

mUploadIndex = 0;
mClipPlaneInfo.Clear();

mPipelinePos++;
mPipelinePos %= mPipelineNbr;
if (needNewPipeline)
{
mPipelinePos++;
mPipelinePos %= mPipelineNbr;
}

mBuffer = mBufferPipeline[mPipelinePos];
}
Expand Down
1 change: 1 addition & 0 deletions source/common/rendering/vulkan/system/vk_framebuffer.cpp
Expand Up @@ -419,6 +419,7 @@ TArray<uint8_t> VulkanFrameBuffer::GetScreenshotBuffer(int &pitch, ESSType &colo
void VulkanFrameBuffer::BeginFrame()
{
SetViewportRects(nullptr);
mViewpoints->Clear();
mCommands->BeginFrame();
mTextureManager->BeginFrame();
mScreenBuffers->BeginFrame(screen->mScreenViewport.width, screen->mScreenViewport.height, screen->mSceneViewport.width, screen->mSceneViewport.height);
Expand Down
85 changes: 80 additions & 5 deletions source/common/scripting/backend/codegen.cpp
Expand Up @@ -104,8 +104,8 @@ FCompileContext::FCompileContext(PNamespace *cg, PFunction *fnc, PPrototype *ret
if (fnc != nullptr) Class = fnc->OwningClass;
}

FCompileContext::FCompileContext(PNamespace *cg, PContainerType *cls, bool fromdecorate)
: ReturnProto(nullptr), Function(nullptr), Class(cls), FromDecorate(fromdecorate), StateIndex(-1), StateCount(0), Lump(-1), CurGlobals(cg)
FCompileContext::FCompileContext(PNamespace *cg, PContainerType *cls, bool fromdecorate, const VersionInfo& info)
: ReturnProto(nullptr), Function(nullptr), Class(cls), FromDecorate(fromdecorate), StateIndex(-1), StateCount(0), Lump(-1), CurGlobals(cg), Version(info)
{
}

Expand Down Expand Up @@ -2678,13 +2678,26 @@ FxBinary::~FxBinary()
//
//==========================================================================

bool FxBinary::Promote(FCompileContext &ctx, bool forceint)
bool FxBinary::Promote(FCompileContext &ctx, bool forceint, bool shiftop)
{
// math operations of unsigned ints results in an unsigned int. (16 and 8 bit values never get here, they get promoted to regular ints elsewhere already.)
if (left->ValueType == TypeUInt32 && right->ValueType == TypeUInt32)
{
ValueType = TypeUInt32;
}
// If one side is an unsigned 32-bit int and the other side is a signed 32-bit int, the signed side is implicitly converted to unsigned,
else if (!ctx.FromDecorate && left->ValueType == TypeUInt32 && right->ValueType == TypeSInt32 && !shiftop && ctx.Version >= MakeVersion(4, 9, 0))
{
right = new FxIntCast(right, false, false, true);
right = right->Resolve(ctx);
ValueType = TypeUInt32;
}
else if (!ctx.FromDecorate && left->ValueType == TypeSInt32 && right->ValueType == TypeUInt32 && !shiftop && ctx.Version >= MakeVersion(4, 9, 0))
{
left = new FxIntCast(left, false, false, true);
left = left->Resolve(ctx);
ValueType = TypeUInt32;
}
else if (left->IsInteger() && right->IsInteger())
{
ValueType = TypeSInt32; // Addition and subtraction forces all integer-derived types to signed int.
Expand Down Expand Up @@ -2728,6 +2741,15 @@ bool FxBinary::Promote(FCompileContext &ctx, bool forceint)
delete this;
return false;
}

// shift operators are different: The left operand defines the type and the right operand must always be made unsigned
if (shiftop)
{
ValueType = left->ValueType == TypeUInt32 ? TypeUInt32 : TypeSInt32;
right = new FxIntCast(right, false, false, true);
right = right->Resolve(ctx);
}

return true;
}

Expand Down Expand Up @@ -3324,6 +3346,59 @@ FxExpression *FxCompareRel::Resolve(FCompileContext& ctx)
}
else if (left->IsNumeric() && right->IsNumeric())
{
if (left->IsInteger() && right->IsInteger())
{
if (ctx.Version >= MakeVersion(4, 9, 0))
{
// We need to do more checks here to catch problem cases.
if (left->ValueType == TypeUInt32 && right->ValueType == TypeSInt32)
{
if (left->isConstant() && !right->isConstant())
{
auto val = static_cast<FxConstant*>(left)->GetValue().GetUInt();
if (val > INT_MAX)
{
ScriptPosition.Message(MSG_WARNING, "Comparison of signed value with out of range unsigned constant");
}
}
else if (right->isConstant() && !left->isConstant())
{
auto val = static_cast<FxConstant*>(right)->GetValue().GetInt();
if (val < 0)
{
ScriptPosition.Message(MSG_WARNING, "Comparison of unsigned value with negative constant");
}
}
else if (!left->isConstant() && !right->isConstant())
{
ScriptPosition.Message(MSG_WARNING, "Comparison between signed and unsigned value");
}
}
else if (left->ValueType == TypeSInt32 && right->ValueType == TypeUInt32)
{
if (left->isConstant() && !right->isConstant())
{
auto val = static_cast<FxConstant*>(left)->GetValue().GetInt();
if (val < 0)
{
ScriptPosition.Message(MSG_WARNING, "Comparison of unsigned value with negative constant");
}
}
else if (right->isConstant() && !left->isConstant())
{
auto val = static_cast<FxConstant*>(right)->GetValue().GetUInt();
if (val > INT_MAX)
{
ScriptPosition.Message(MSG_WARNING, "Comparison of signed value with out of range unsigned constant");
}
}
else if (!left->isConstant() && !right->isConstant())
{
ScriptPosition.Message(MSG_WARNING, "Comparison between signed and unsigned value");
}
}
}
}
Promote(ctx);
}
else
Expand Down Expand Up @@ -3929,7 +4004,7 @@ FxExpression *FxShift::Resolve(FCompileContext& ctx)

if (left->IsNumeric() && right->IsNumeric())
{
if (!Promote(ctx, true)) return nullptr;
if (!Promote(ctx, true, true)) return nullptr;
if ((left->ValueType == TypeUInt32 && ctx.Version >= MakeVersion(3, 7)) && Operator == TK_RShift) Operator = TK_URShift;
}
else
Expand Down Expand Up @@ -8233,7 +8308,7 @@ FxExpression *FxMemberFunctionCall::Resolve(FCompileContext& ctx)
member->membervar = newfield;
Self = nullptr;
delete this;
member->ValueType = TypeUInt32;
member->ValueType = TypeSInt32;
return member;
}
else
Expand Down
4 changes: 2 additions & 2 deletions source/common/scripting/backend/codegen.h
Expand Up @@ -93,7 +93,7 @@ struct FCompileContext
FString VersionString;

FCompileContext(PNamespace *spc, PFunction *func, PPrototype *ret, bool fromdecorate, int stateindex, int statecount, int lump, const VersionInfo &ver);
FCompileContext(PNamespace *spc, PContainerType *cls, bool fromdecorate); // only to be used to resolve constants!
FCompileContext(PNamespace *spc, PContainerType *cls, bool fromdecorate, const VersionInfo& ver); // only to be used to resolve constants!

PSymbol *FindInClass(FName identifier, PSymbolTable *&symt);
PSymbol *FindInSelfClass(FName identifier, PSymbolTable *&symt);
Expand Down Expand Up @@ -910,7 +910,7 @@ class FxBinary : public FxExpression

FxBinary(int, FxExpression*, FxExpression*);
~FxBinary();
bool Promote(FCompileContext &ctx, bool forceint = false);
bool Promote(FCompileContext &ctx, bool forceint = false, bool shiftop = false);
};

//==========================================================================
Expand Down
4 changes: 4 additions & 0 deletions source/common/scripting/core/types.cpp
Expand Up @@ -334,6 +334,7 @@ void PType::StaticInit()
TypeVector2->moveOp = OP_MOVEV2;
TypeVector2->RegType = REGT_FLOAT;
TypeVector2->RegCount = 2;
TypeVector2->isOrdered = true;

TypeVector3 = new PStruct(NAME_Vector3, nullptr);
TypeVector3->AddField(NAME_X, TypeFloat64);
Expand All @@ -347,6 +348,7 @@ void PType::StaticInit()
TypeVector3->moveOp = OP_MOVEV3;
TypeVector3->RegType = REGT_FLOAT;
TypeVector3->RegCount = 3;
TypeVector3->isOrdered = true;


TypeFVector2 = new PStruct(NAME_FVector2, nullptr);
Expand All @@ -358,6 +360,7 @@ void PType::StaticInit()
TypeFVector2->moveOp = OP_MOVEV2;
TypeFVector2->RegType = REGT_FLOAT;
TypeFVector2->RegCount = 2;
TypeFVector2->isOrdered = true;

TypeFVector3 = new PStruct(NAME_FVector3, nullptr);
TypeFVector3->AddField(NAME_X, TypeFloat32);
Expand All @@ -371,6 +374,7 @@ void PType::StaticInit()
TypeFVector3->moveOp = OP_MOVEV3;
TypeFVector3->RegType = REGT_FLOAT;
TypeFVector3->RegCount = 3;
TypeFVector3->isOrdered = true;

Namespaces.GlobalNamespace->Symbols.AddSymbol(Create<PSymbolType>(NAME_sByte, TypeSInt8));
Namespaces.GlobalNamespace->Symbols.AddSymbol(Create<PSymbolType>(NAME_Byte, TypeUInt8));
Expand Down
1 change: 1 addition & 0 deletions source/common/scripting/core/types.h
Expand Up @@ -537,6 +537,7 @@ class PStruct : public PContainerType
PStruct(FName name, PTypeBase *outer, bool isnative = false);

bool isNative;
bool isOrdered = false;
// Some internal structs require explicit construction and destruction of fields the VM cannot handle directly so use these two functions for it.
VMFunction *mConstructor = nullptr;
VMFunction *mDestructor = nullptr;
Expand Down

0 comments on commit 7debab7

Please sign in to comment.