Skip to content

Commit

Permalink
[Engine] Misc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDushan committed May 5, 2024
1 parent 035d3dd commit 0184c99
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 34 deletions.
3 changes: 2 additions & 1 deletion src/engine/client/clientParse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,8 @@ void idClientParseSystemLocal::ParseGamestate(msg_t *msg) {
i = msgToFuncSystem->ReadShort(msg);

if(i < 0 || i >= MAX_CONFIGSTRINGS) {
common->Error(ERR_DROP, "configstring > MAX_CONFIGSTRINGS");
common->Error(ERR_DROP,
"idClientParseSystemLocal::ParseGamestate: bad index %i", i);
}

s = msgToFuncSystem->ReadBigString(msg);
Expand Down
2 changes: 1 addition & 1 deletion src/engine/framework/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ idFileSystemLocal::FileForHandle
================
*/
FILE *idFileSystemLocal::FileForHandle(fileHandle_t f) {
if(f < 0 || f > MAX_FILE_HANDLES) {
if(f < 0 || f >= MAX_FILE_HANDLES) {
common->Error(ERR_DROP,
"idFileSystemLocal::FileForHandle: %d out of range",
f);
Expand Down
32 changes: 21 additions & 11 deletions src/engine/qcommon/q_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -937,20 +937,30 @@ void AxisCopy( vec3_t in[3], vec3_t out[3] )

void ProjectPointOnPlane( vec3_t dst, const vec3_t p, const vec3_t normal )
{
float32 d;
vec3_t n;
float32 inv_denom;
float32 d, inv_denom;
vec3_t n;

inv_denom = DotProduct( normal, normal );

if (inv_denom)
{
inv_denom = 1.0f / inv_denom;

d = DotProduct( normal, p ) * inv_denom;

inv_denom = 1.0F / DotProduct( normal, normal );
d = DotProduct( normal, p ) * inv_denom;
n[0] = normal[0] * inv_denom;
n[1] = normal[1] * inv_denom;
n[2] = normal[2] * inv_denom;

n[0] = normal[0] * inv_denom;
n[1] = normal[1] * inv_denom;
n[2] = normal[2] * inv_denom;
dst[0] = p[0] - d * n[0];
dst[1] = p[1] - d * n[1];
dst[2] = p[2] - d * n[2];

dst[0] = p[0] - d * n[0];
dst[1] = p[1] - d * n[1];
dst[2] = p[2] - d * n[2];
}
else
{
VectorClear(dst);
}
}

/*
Expand Down
1 change: 0 additions & 1 deletion src/engine/qcommon/q_shared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1647,7 +1647,6 @@ enum gamestate_t {

#define MAX_LOCATIONS 64
#define MAX_MODELS 256 // these are sent over the net as 8 bits
#define MAX_SOUNDS 256 // so they cannot be blindly increased
#define MAX_GAME_SHADERS 64
#define MAX_GAME_PARTICLE_SYSTEMS 64
#define MAX_HOSTNAME_LENGTH 80 // max length of a host name
Expand Down
36 changes: 20 additions & 16 deletions src/engine/renderSystem/r_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,8 @@ void RB_BeginDrawingView(void) {
if(glRefConfig.framebufferObject) {
FBO_t *fbo = backEnd.viewParms.targetFbo;

// FIXME: HUGE HACK: render to the screen fbo if we've already postprocessed the frame and aren't drawing more world
// drawing more world check is in case of double renders, such as skyportals
if(fbo == nullptr && !(backEnd.framePostProcessed &&
(backEnd.refdef.rdflags & RDF_NOWORLDMODEL))) {
if(fbo == nullptr && (!r_postProcess->integer ||
!(backEnd.refdef.rdflags & RDF_NOWORLDMODEL))) {
fbo = tr.renderFbo;
}

Expand Down Expand Up @@ -729,9 +727,8 @@ void idRenderSystemLocal::DrawStretchRaw(sint x, sint y, sint w, sint h,
end - start);
}

// FIXME: HUGE hack
if(glRefConfig.framebufferObject) {
FBO_Bind(backEnd.framePostProcessed ? nullptr : tr.renderFbo);
FBO_Bind(r_postProcess->integer ? nullptr : tr.renderFbo);
}

RB_SetGL2D();
Expand Down Expand Up @@ -846,7 +843,7 @@ const void *RB_StretchPic(const void *data) {

// FIXME: HUGE hack
if(glRefConfig.framebufferObject) {
FBO_Bind(backEnd.framePostProcessed ? nullptr : tr.renderFbo);
FBO_Bind(r_postProcess->integer ? nullptr : tr.renderFbo);
}

RB_SetGL2D();
Expand Down Expand Up @@ -1312,6 +1309,13 @@ const void *RB_DrawSurfs(const void *data) {
if(cubemap && cubemap->image) {
qglGenerateTextureMipmapEXT(cubemap->image->texnum, GL_TEXTURE_CUBE_MAP);
}

// FIXME? backEnd.viewParms doesn't get properly initialized for 2D drawing.
// r_cubeMapping 1 generates cubemaps with R_RenderCubemapSide()
// and sets isMirror = qtrue. Clear it here to prevent it from leaking
// to 2D drawing and causing the loading screen to be culled.
backEnd.viewParms.isMirror = false;
backEnd.viewParms.flags = 0;
}

return (const void *)(cmd + 1);
Expand Down Expand Up @@ -1344,6 +1348,13 @@ const void *RB_DrawBuffer(const void *data) {
if(r_clear->integer) {
qglClearColor(1, 0, 0.5, 1);
qglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

if(glRefConfig.framebufferObject && tr.renderFbo) {
FBO_Bind(tr.renderFbo);

qglClearColor(1, 0, 0.5, 1);
qglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
}

return (const void *)(cmd + 1);
Expand Down Expand Up @@ -1456,11 +1467,7 @@ const void *RB_ClearDepth(const void *data) {
}

if(glRefConfig.framebufferObject) {
if(!tr.renderFbo || backEnd.framePostProcessed) {
FBO_Bind(nullptr);
} else {
FBO_Bind(tr.renderFbo);
}
FBO_Bind(tr.renderFbo);
}

qglClear(GL_DEPTH_BUFFER_BIT);
Expand Down Expand Up @@ -1511,7 +1518,7 @@ const void *RB_SwapBuffers(const void *data) {
}

if(glRefConfig.framebufferObject) {
if(!backEnd.framePostProcessed) {
if(!r_postProcess->integer) {
if(tr.renderFbo) {
FBO_FastBlit(tr.renderFbo, nullptr, nullptr, nullptr, GL_COLOR_BUFFER_BIT,
GL_NEAREST);
Expand All @@ -1527,7 +1534,6 @@ const void *RB_SwapBuffers(const void *data) {

GLimp_EndFrame();

backEnd.framePostProcessed = false;
backEnd.projection2D = false;

glState.finishCalled = false;
Expand Down Expand Up @@ -1914,8 +1920,6 @@ const void *RB_PostProcess(const void *data) {

#endif

backEnd.framePostProcessed = true;

return (const void *)(cmd + 1);
}

Expand Down
3 changes: 3 additions & 0 deletions src/engine/renderSystem/r_fbo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ void FBO_CreateBuffer(FBO_t *fbo, sint format, sint index,

if(absent) {
qglGenRenderbuffers(1, pRenderBuffer);

// workaround AMD Windows driver requiring bind to create renderbuffer
GL_BindRenderbuffer(*pRenderBuffer);
}

qglNamedRenderbufferStorageEXT(*pRenderBuffer, format, fbo->width,
Expand Down
1 change: 1 addition & 0 deletions src/engine/renderSystem/r_glimp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ static sint GLimp_SetMode(sint mode, bool fullscreen, bool noborder,
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, perChannelColorBits);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, perChannelColorBits);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, perChannelColorBits);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, perChannelColorBits);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, testDepthBits);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, testStencilBits);

Expand Down
1 change: 0 additions & 1 deletion src/engine/renderSystem/r_local.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1551,7 +1551,6 @@ typedef struct {

FBO_t *last2DFBO;
bool colorMask[4];
bool framePostProcessed;
bool depthFill;
} backEndState_t;

Expand Down
2 changes: 1 addition & 1 deletion src/engine/soundSystem/sndSystem_dma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ void SOrig_StartSound(vec3_t origin, sint entityNum, sint entchannel,
return;
}

if(!origin && (entityNum < 0 || entityNum > MAX_GENTITIES)) {
if(!origin && (entityNum < 0 || entityNum >= MAX_GENTITIES)) {
common->Error(ERR_DROP, "S_StartSound: bad entitynum %i", entityNum);
}

Expand Down
16 changes: 15 additions & 1 deletion src/engine/soundSystemAL/sndSystemAL_buffers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,22 @@ sfxHandle_t idAudioOpenALSystemLocal::buf_find(pointer filename) {
sfxHandle_t sfx = -1;
sint i;

if(!filename) {
trap_Error(ERR_FATAL, "Sound name is NULL");
}

if(!filename[0]) {
trap_Printf(PRINT_ALL, "WARNING: Sound name is empty\n");
return 0;
}

if(::strlen(filename) >= MAX_QPATH) {
trap_Printf(PRINT_ALL, "WARNING: Sound name is too long: %s\n", filename);
return 0;
}

for(i = 0; i < MAX_SFX; i++) {
if(!strcmp(knownSfx[i].filename, filename)) {
if(!::strcmp(knownSfx[i].filename, filename)) {
sfx = i;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/engine/soundSystemAL/sndSystemAL_sources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ Entity position management
*/
void idAudioOpenALSystemLocal::UpdateEntityPosition(sint entityNum,
const vec3_t origin) {
if(entityNum < 0 || entityNum > MAX_GENTITIES) {
if(entityNum < 0 || entityNum >= MAX_GENTITIES) {
trap_Error(ERR_DROP, "S_UpdateEntityPosition: bad entitynum %i",
entityNum);
}
Expand Down

0 comments on commit 0184c99

Please sign in to comment.