Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[D3] Rewrite fix for BUG-003 #3

Merged
merged 3 commits into from
Dec 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# IDT4 changelog


## [?.?.?] - ????-??-??
### Added
- Borderless mode.

### Fixed
[D3] Bug 003 (OpenAL Deleting attached buffer).


## [1.0.0] - 2022-09-09
### Added
- OpenAL EFX.
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Contents
3.1 Doom 3 (2004)
4. Features
4.1 OpenAL EFX
4.2 Audio limiter
4.2 Audio limiter
4.3 Borderless mode
5. Links


Expand Down Expand Up @@ -120,6 +121,17 @@ New CVARs:
Default value: `0`


4.3 - Borderless mode
=====================

Creates a borderless window of desktop size without changing the display mode.

New CVARs:
- `r_preferBorderless <0|1>`
Tries to use borderless mode if value set to `1` and CVAR `r_fullscreen` set to `1`.
Default value: `0`


5 - Links
=========
- [Dependencies for building](https://github.com/bibendovsky/idt4_dependencies)
17 changes: 16 additions & 1 deletion docs/doom 3 (2004)/bugs/003_openal_deleting_attached_buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ Prerequisites
- Using OpenAL.
- Level transition.

How to reproduce in base game
=============================
1) `set com_purgeAll 1`
2) `map game/mars_city2`
3) Wait for radio transmission.
4) `map game/mars_city1`

How to reproduce in ROE
=======================
1) `set com_purgeAll 1`
2) `map game/erebus6`
3) `teleport func_static_5381`
4) Look to the right and click to exit the level.
5) If next level loaded without an error try `map game/erebus6` one more time.

Symptom
=======
The game stops with an error message in the console "idSoundCache: error unloading data from OpenAL hardware buffer".
Expand All @@ -17,4 +32,4 @@ Reasons

Solution
========
In the method `idSoundSample::PurgeSoundSample` (snd_cache.cpp) call idSoundChannel::ALStop for all channels using this AL buffer.
In the method `idSoundSample::PurgeSoundSample` (snd_cache.cpp) call idSoundChannel::ALStop for all sources using this AL buffer.
37 changes: 37 additions & 0 deletions neo/renderer/RenderSystem_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,15 @@ idCVar r_materialOverride( "r_materialOverride", "", CVAR_RENDERER, "overrides a

idCVar r_debugRenderToTexture( "r_debugRenderToTexture", "0", CVAR_RENDERER | CVAR_INTEGER, "" );

// IDT4-D3-FEATURE-BORDERLESS
#ifndef IDT4_VANILLA
idCVar r_prefer_borderless_cvar(
"r_preferBorderless",
"0",
CVAR_RENDERER | CVAR_ARCHIVE | CVAR_BOOL,
"Prefer borderless mode over the full screen exclusive one.");
#endif

void ( APIENTRY * qglMultiTexCoord2fARB )( GLenum texture, GLfloat s, GLfloat t );
void ( APIENTRY * qglMultiTexCoord2fvARB )( GLenum texture, GLfloat *st );
void ( APIENTRY * qglActiveTextureARB )( GLenum texture );
Expand Down Expand Up @@ -637,13 +646,37 @@ void R_InitOpenGL( void ) {
// set the parameters we are trying
R_GetModeInfo( &glConfig.vidWidth, &glConfig.vidHeight, r_mode.GetInteger() );

// IDT4-D3-FEATURE-BORDERLESS
#ifndef IDT4_VANILLA
bool prefer_borderless = false;

if (r_fullscreen.GetBool() && r_prefer_borderless_cvar.GetBool())
{
int desktop_width = 0;
int desktop_height = 0;
const bool found_desktop_size = glimp_get_desktop_size(desktop_width, desktop_height);

if (found_desktop_size)
{
prefer_borderless = true;
glConfig.vidWidth = desktop_width;
glConfig.vidHeight = desktop_height;
}
}
#endif

parms.width = glConfig.vidWidth;
parms.height = glConfig.vidHeight;
parms.fullScreen = r_fullscreen.GetBool();
parms.displayHz = r_displayRefresh.GetInteger();
parms.multiSamples = r_multiSamples.GetInteger();
parms.stereo = false;

// IDT4-D3-FEATURE-BORDERLESS
#ifndef IDT4_VANILLA
parms.prefer_borderless = prefer_borderless;
#endif

if ( GLimp_Init( parms ) ) {
// it worked
break;
Expand Down Expand Up @@ -1938,6 +1971,10 @@ void R_VidRestart_f( const idCmdArgs &args ) {
parms.displayHz = r_displayRefresh.GetInteger();
parms.multiSamples = r_multiSamples.GetInteger();
parms.stereo = false;
// IDT4-D3-FEATURE-BORDERLESS
#ifndef IDT4_VANILLA
parms.prefer_borderless = r_prefer_borderless_cvar.GetBool();
#endif
GLimp_SetScreenParms( parms );
}

Expand Down
13 changes: 13 additions & 0 deletions neo/renderer/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,11 @@ extern idCVar r_materialOverride; // override all materials

extern idCVar r_debugRenderToTexture;

// IDT4-D3-FEATURE-BORDERLESS
#ifndef IDT4_VANILLA
extern idCVar r_prefer_borderless_cvar;
#endif

/*
====================================================================

Expand Down Expand Up @@ -1074,6 +1079,10 @@ typedef struct {
bool stereo;
int displayHz;
int multiSamples;
// IDT4-D3-FEATURE-BORDERLESS
#ifndef IDT4_VANILLA
bool prefer_borderless;
#endif
} glimpParms_t;

bool GLimp_Init( glimpParms_t parms );
Expand Down Expand Up @@ -1121,6 +1130,10 @@ void GLimp_DeactivateContext( void );

void GLimp_EnableLogging( bool enable );

// IDT4-D3-FEATURE-BORDERLESS
#ifndef IDT4_VANILLA
bool glimp_get_desktop_size(int& width, int& height);
#endif

/*
====================================================================
Expand Down
14 changes: 9 additions & 5 deletions neo/sound/snd_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,11 +646,15 @@ void idSoundSample::PurgeSoundSample() {
{
openalSource_t& openalSource = soundSystemLocal.openalSources[i];

if (!openalSource.inUse ||
openalSource.chan == NULL ||
openalSource.chan->leadinSample == NULL ||
openalSource.chan->leadinSample->openalBuffer == AL_NONE ||
openalSource.chan->leadinSample->openalBuffer != openalBuffer)
if (!openalSource.inUse || openalSource.chan == NULL)
{
continue;
}

ALint al_current_buffer = AL_NONE;
alGetSourcei(openalSource.handle, AL_BUFFER, &al_current_buffer);

if (openalBuffer != static_cast<ALuint>(al_current_buffer))
{
continue;
}
Expand Down
56 changes: 56 additions & 0 deletions neo/sys/win32/win_glimp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,15 @@ static bool GLW_CreateWindow( glimpParms_t parms ) {
exstyle = WS_EX_TOPMOST;
stylebits = WS_POPUP|WS_VISIBLE|WS_SYSMENU;

// IDT4-D3-FEATURE-BORDERLESS
#ifndef IDT4_VANILLA
if (parms.prefer_borderless)
{
exstyle = 0;
stylebits = WS_POPUP | WS_VISIBLE;
}
#endif

x = 0;
y = 0;
w = parms.width;
Expand Down Expand Up @@ -677,6 +686,13 @@ GLW_SetFullScreen
===================
*/
static bool GLW_SetFullScreen( glimpParms_t parms ) {
// IDT4-D3-FEATURE-BORDERLESS
#ifndef IDT4_VANILLA
if (parms.prefer_borderless)
{
return ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL;
}
#endif
#if 0
// for some reason, bounds checker claims that windows is
// writing past the bounds of dm in the get display frequency call
Expand Down Expand Up @@ -884,6 +900,14 @@ bool GLimp_SetScreenParms( glimpParms_t parms ) {
if ( parms.fullScreen ) {
exstyle = WS_EX_TOPMOST;
stylebits = WS_POPUP|WS_VISIBLE|WS_SYSMENU;
// IDT4-D3-FEATURE-BORDERLESS
#ifndef IDT4_VANILLA
if (parms.prefer_borderless)
{
exstyle = 0;
stylebits = WS_POPUP | WS_VISIBLE;
}
#endif
SetWindowLong( win32.hWnd, GWL_STYLE, stylebits );
SetWindowLong( win32.hWnd, GWL_EXSTYLE, exstyle );
dm.dmPelsWidth = parms.width;
Expand Down Expand Up @@ -929,8 +953,40 @@ bool GLimp_SetScreenParms( glimpParms_t parms ) {
SetWindowLong( win32.hWnd, GWL_EXSTYLE, exstyle );
common->Printf( "%i %i %i %i\n", x, y, w, h );
}
// IDT4-D3-FEATURE-BORDERLESS
#ifndef IDT4_VANILLA
bool ret = false;

if (parms.fullScreen && parms.prefer_borderless)
{
ret = (ChangeDisplaySettingsW(NULL, 0) == DISP_CHANGE_SUCCESSFUL);

SetWindowPos(
win32.hWnd,
HWND_TOPMOST,
x,
y,
w,
h,
SWP_NOSIZE | SWP_NOMOVE);
}
else
{
ret = (ChangeDisplaySettingsA(&dm, parms.fullScreen ? CDS_FULLSCREEN : 0) == DISP_CHANGE_SUCCESSFUL);

SetWindowPos(
win32.hWnd,
parms.fullScreen ? HWND_TOPMOST : HWND_NOTOPMOST,
x,
y,
w,
h,
parms.fullScreen ? SWP_NOSIZE | SWP_NOMOVE : SWP_SHOWWINDOW);
}
#else
bool ret = ( ChangeDisplaySettings( &dm, parms.fullScreen ? CDS_FULLSCREEN : 0 ) == DISP_CHANGE_SUCCESSFUL );
SetWindowPos( win32.hWnd, parms.fullScreen ? HWND_TOPMOST : HWND_NOTOPMOST, x, y, w, h, parms.fullScreen ? SWP_NOSIZE | SWP_NOMOVE : SWP_SHOWWINDOW );
#endif
return ret;
}

Expand Down
27 changes: 27 additions & 0 deletions neo/sys/win32/win_qgl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2809,3 +2809,30 @@ void GLimp_EnableLogging( bool enable ) {
qglViewport = dllViewport ;
}
}

// IDT4-D3-FEATURE-BORDERLESS
#ifndef IDT4_VANILLA
bool glimp_get_desktop_size(int& width, int& height)
{
const HWND desktop_window = GetDesktopWindow();
const HDC hdc = GetDC(desktop_window);

if (hdc == NULL)
{
return false;
}

const int horzres = GetDeviceCaps(hdc, HORZRES);
const int vertres = GetDeviceCaps(hdc, VERTRES);
ReleaseDC(desktop_window, hdc);

if (horzres <= 0 || vertres <= 0)
{
return false;
}

width = horzres;
height = vertres;
return true;
}
#endif