Skip to content

Commit

Permalink
Remaster merge commit '42d5958d'
Browse files Browse the repository at this point in the history
  • Loading branch information
0lvin committed Nov 23, 2024
2 parents 319c3a8 + 42d5958 commit 10866e7
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 32 deletions.
35 changes: 29 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ option(CURL_SUPPORT "cURL support" ON)
option(OPENAL_SUPPORT "OpenAL support" ON)
option(SYSTEMWIDE_SUPPORT "Enable systemwide installation of game assets" OFF)
option(SDL3_SUPPORT "Build against SDL 3 instead of SDL2" OFF)
option(GL1_RENDERER "Build the GL3 renderer" ON)
option(GL3_RENDERER "Build the GL3 renderer" ON)
option(GLES1_RENDERER "Build the GLES1 renderer" OFF)
option(GLES3_RENDERER "Build the GLES3 renderer" ON)
option(SOFT_RENDERER "Build the software renderer" ON)

set(SYSTEMDIR "" CACHE STRING "Override the system default directory")

Expand Down Expand Up @@ -189,11 +194,13 @@ else()
list(APPEND yquake2SDLLinkerFlags ${SDL2_LIBRARY})
endif()

# We need an OpenGL implementation.
set(OpenGL_GL_PREFERENCE GLVND)
find_package(OpenGL REQUIRED)
list(APPEND yquake2IncludeDirectories ${OPENGL_INCLUDE_DIR})
list(APPEND yquake2OpenGLLinkerFlags ${OPENGL_LIBRARIES})
if(GL1_RENDERER)
# We need an OpenGL implementation.
set(OpenGL_GL_PREFERENCE GLVND)
find_package(OpenGL REQUIRED)
list(APPEND yquake2IncludeDirectories ${OPENGL_INCLUDE_DIR})
list(APPEND yquake2OpenGLLinkerFlags ${OPENGL_LIBRARIES})
endif()

# backtrace lookup
# Some systems like Linux has it within the libc some like the BSD, Haiku ...
Expand Down Expand Up @@ -852,6 +859,8 @@ else() # single-config, like normal Makefiles
endif()
target_link_libraries(game ${yquake2LinkerFlags})

if(${GL1_RENDERER})

# Build the GL1 dynamic library
add_library(ref_gl1 MODULE ${GL1-Source} ${GL1-Header} ${REF-Platform-Specific-Source})
set_target_properties(ref_gl1 PROPERTIES
Expand All @@ -866,6 +875,10 @@ if(SDL3_SUPPORT)
target_link_libraries(ref_gl1 SDL3::SDL3)
endif()

endif()

if(${GL3_RENDERER})

# Build the GL3 dynamic library
add_library(ref_gl3 MODULE ${GL3-Source} ${Glad-GL3-Source} ${GL3-Header} ${Glad-GL3-Header} ${REF-Platform-Specific-Source})
set_target_properties(ref_gl3 PROPERTIES
Expand All @@ -880,6 +893,10 @@ if(SDL3_SUPPORT)
target_link_libraries(ref_gl3 SDL3::SDL3)
endif()

endif()

if(${GLES3_RENDERER})

# Build the GLES3 dynamic library
add_library(ref_gles3 MODULE ${GL3-Source} ${Glad-GLES3-Source} ${GL3-Header} ${Glad-GLES3-Header} ${REF-Platform-Specific-Source})
set_target_properties(ref_gles3 PROPERTIES
Expand All @@ -896,6 +913,10 @@ if(SDL3_SUPPORT)
target_link_libraries(ref_gles3 SDL3::SDL3)
endif()

endif()

if(${SOFT_RENDERER})

# Build the soft renderer dynamic library
add_library(ref_soft MODULE ${SOFT-Source} ${SOFT-Header} ${REF-Platform-Specific-Source})
set_target_properties(ref_soft PROPERTIES
Expand All @@ -909,7 +930,9 @@ if(SDL3_SUPPORT)
target_link_libraries(ref_soft SDL3::SDL3)
endif()

if(FALSE)
endif()

if(${GLES1_RENDERER})

# Build the GLES1 dynamic library
add_library(ref_gles1 MODULE ${GL1-Source} ${Glad-GLES1-Source} ${GL1-Header} ${Glad-GLES1-Header} ${REF-Platform-Specific-Source})
Expand Down
35 changes: 32 additions & 3 deletions src/backends/generic/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "../../common/header/shared.h"
#include "../../common/header/common.h"

#if defined(__linux) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__sun)
#if defined(__linux) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__sun) || defined(__APPLE__)
#include <unistd.h> // readlink(), amongst others
#endif

Expand All @@ -40,6 +40,7 @@

#ifdef _WIN32
#include <windows.h> // GetModuleFileNameA()
#include <wchar.h> // _wgetcwd()
#endif

#ifdef __APPLE__
Expand Down Expand Up @@ -146,6 +147,31 @@ static void SetExecutablePath(char* exePath)
#endif
}

qboolean Sys_GetCwd(char *buf, size_t size)
{
#ifdef _WIN32
WCHAR wpath[PATH_MAX];
DWORD len;

if (_wgetcwd(wpath, PATH_MAX) == NULL)
{
return false;
}
len = WideCharToMultiByte(CP_UTF8, 0, wpath, -1, buf, size, NULL, NULL);
if (len <= 0 || len == size)
{
return false;
}
#else
if (getcwd(buf, size) == NULL)
{
return false;
}
#endif
return Q_strlcat(buf, "/", size) == 1;
}


const char *Sys_GetBinaryDir(void)
{
static char exeDir[PATH_MAX] = {0};
Expand All @@ -157,8 +183,11 @@ const char *Sys_GetBinaryDir(void)
SetExecutablePath(exeDir);

if (exeDir[0] == '\0') {
Com_Printf("Couldn't determine executable path. Using ./ instead.\n");
Q_strlcpy(exeDir, "./", sizeof(exeDir));
if (Sys_GetCwd(exeDir, sizeof(exeDir)) == false)
{
Q_strlcpy(exeDir, "./", sizeof(exeDir));
}
Com_Printf("Couldn't determine executable path. Using %s instead.\n", exeDir);
} else {
// cut off executable name
char *lastSlash = strrchr(exeDir, '/');
Expand Down
17 changes: 16 additions & 1 deletion src/client/refresh/soft/sw_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1909,6 +1909,10 @@ RE_InitContext(void *win)
SDL_SetRenderVSync(renderer, 1);
#else
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if(!renderer)
{
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE | SDL_RENDERER_PRESENTVSYNC);
}
#endif
}
else
Expand All @@ -1917,8 +1921,16 @@ RE_InitContext(void *win)
renderer = SDL_CreateRenderer(window, NULL);
#else
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
if(!renderer)
{
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE);
}
#endif
}
if(!renderer) {
Com_Printf("Can't create renderer: %s\n", SDL_GetError());
return false;
}

/* Select the color for drawing. It is set to black here. */
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
Expand Down Expand Up @@ -1964,7 +1976,10 @@ RE_InitContext(void *win)
#endif
SDL_TEXTUREACCESS_STREAMING,
vid_buffer_width, vid_buffer_height);

if(!texture) {
Com_Printf("Can't create texture: %s\n", SDL_GetError());
return false;
}
R_InitGraphics(vid_buffer_width, vid_buffer_height);
SWimp_CreateRender(vid_buffer_width, vid_buffer_height);

Expand Down
4 changes: 3 additions & 1 deletion src/client/vid/glimp_sdl2.c
Original file line number Diff line number Diff line change
Expand Up @@ -720,13 +720,15 @@ GLimp_ShutdownGraphics(void)
void
GLimp_GrabInput(qboolean grab)
{
static qboolean seen_error = false;
if(window != NULL)
{
SDL_SetWindowGrab(window, grab ? SDL_TRUE : SDL_FALSE);
}

if(SDL_SetRelativeMouseMode(grab ? SDL_TRUE : SDL_FALSE) < 0)
if(SDL_SetRelativeMouseMode(grab ? SDL_TRUE : SDL_FALSE) < 0 && !seen_error)
{
seen_error = true;
Com_Printf("WARNING: Setting Relative Mousemode failed, reason: %s\n", SDL_GetError());
Com_Printf(" You should probably update to SDL 2.0.3 or newer!\n");
}
Expand Down
6 changes: 3 additions & 3 deletions src/common/cmdparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ Cmd_CompleteMapCommand(const char *partial)
{
char **mapNames;
int i, j, k, nbMatches, len, nMaps;
char *mapName;
char *mapName, *lastsep;
char *pmatch[1024];
qboolean partialFillContinue = true;

Expand All @@ -921,9 +921,9 @@ Cmd_CompleteMapCommand(const char *partial)

for (i = 0; i < nMaps - 1; i++)
{
if (strrchr(mapNames[i], '/'))
if ((lastsep = strrchr(mapNames[i], '/')))
{
mapName = strrchr(mapNames[i], '/') + 1;
mapName = lastsep + 1;
}
else
{
Expand Down
41 changes: 40 additions & 1 deletion src/game/g_monster.c
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,15 @@ void MG_CheckInGround (edict_t *self)
qboolean
monster_start(edict_t *self)
{
if ((deathmatch->value == 1) && !((int)sv_cheats->value & self_spawn))
float scale;
int i;

if (!self)
{
return false;
}

if (deathmatch->value && !((int)sv_cheats->value & self_spawn))
{
G_FreeEdict(self);
return false;
Expand Down Expand Up @@ -772,6 +780,37 @@ monster_start(edict_t *self)
self->monsterinfo.checkattack = M_CheckAttack;
}

scale = 0;

for (i = 0; i < 3; i++)
{
if (!self->s.scale[i])
{
/* fix empty scale */
self->s.scale[i] = 1.0f;
}

scale += self->s.scale[i];
}

scale /= 3;

/* non default scale */
if (scale != 1.0)
{
int i;

self->monsterinfo.scale *= scale;
self->mass *= scale;


for (i = 0; i < 3; i++)
{
self->mins[i] *= self->s.scale[i];
self->maxs[i] *= self->s.scale[i];
}
}

VectorCopy(self->s.origin, self->s.old_origin);

if (st.item)
Expand Down
47 changes: 33 additions & 14 deletions src/game/g_spawn.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,24 @@ static dynamicentity_t *dynamicentities;
static int ndynamicentities;
static int nstaticentities;

static void
DynamicSpawnSetScale(edict_t *self)
{
/* copy to other parts if zero */
if (!st.scale[1])
{
st.scale[1] = st.scale[0];
}

if (!st.scale[2])
{
st.scale[2] = st.scale[0];
}

/* Copy to entity scale field */
VectorCopy(st.scale, self->s.scale);
}

static void
DynamicSpawnUpdate(edict_t *self, dynamicentity_t *data)
{
Expand Down Expand Up @@ -116,19 +134,7 @@ DynamicSpawnUpdate(edict_t *self, dynamicentity_t *data)
/* has updated scale */
if (st.scale[0] || st.scale[1] || st.scale[2])
{
/* copy to other parts if zero */
if (!st.scale[1])
{
st.scale[1] = st.scale[0];
}

if (!st.scale[2])
{
st.scale[2] = st.scale[0];
}

/* Copy to entity scale field */
VectorCopy(st.scale, self->s.scale);
DynamicSpawnSetScale(self);
}
else
{
Expand Down Expand Up @@ -288,6 +294,7 @@ ED_CallSpawn(edict_t *ent)
return;
}

/* check item spawn functions */
if((item = IsItem(ent)))
{
SpawnItem(ent, item);
Expand All @@ -307,6 +314,19 @@ ED_CallSpawn(edict_t *ent)
}
}

/* No dynamic description */
if (dyn_id < 0)
{
if (st.scale[0])
{
DynamicSpawnSetScale(ent);
}
else
{
VectorSet(ent->s.scale, 1.0, 1.0, 1.0);
}
}

/* check normal spawn functions */
s = StaticSpawnSearch(ent->classname);
if (s)
Expand Down Expand Up @@ -1478,7 +1498,6 @@ DynamicSpawnInit(void)
* max attenuation
*/


/* Fix path */
Q_replacebackslash(dynamicentities[curr_pos].model_path);

Expand Down
6 changes: 3 additions & 3 deletions src/server/sv_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,17 +325,17 @@ SV_ListMaps_f(void)
char **userMapNames;
int nUserMaps = 0;
int i;
char* mapName;
char* mapName, *lastsep;

Com_Printf("\n");

if ((userMapNames = FS_ListFiles2("maps/*.bsp", &nUserMaps, 0, 0)) != NULL)
{
for (i = 0; i < nUserMaps - 1; i++)
{
if (strrchr(userMapNames[i], '/'))
if ((lastsep = strrchr(userMapNames[i], '/')))
{
mapName = strrchr(userMapNames[i], '/') + 1;
mapName = lastsep + 1;
}
else
{
Expand Down

0 comments on commit 10866e7

Please sign in to comment.