diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 42a6018..ad217fe 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -28,77 +28,43 @@
-
+
+
+
-
+
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
@@ -115,10 +81,6 @@
-
-
-
-
@@ -138,33 +100,33 @@
- {
- "keyToString": {
- "CMake Application.quakespasm.executor": "Run",
- "CidrDebugProfileConversion": "true",
- "ModuleVcsDetector.initialDetectionPerformed": "true",
- "RunOnceActivity.RadMigrateCodeStyle": "true",
- "RunOnceActivity.ShowReadmeOnStart": "true",
- "RunOnceActivity.cidr.known.project.marker": "true",
- "RunOnceActivity.git.unshallow": "true",
- "RunOnceActivity.readMode.enableVisualFormatting": "true",
- "RunOnceActivity.typescript.service.memoryLimit.init": "true",
- "SHARE_PROJECT_CONFIGURATION_FILES": "true",
- "cf.first.check.clang-format": "false",
- "cidr.known.project.marker": "true",
- "codeWithMe.voiceChat.enabledByDefault": "false",
- "git-widget-placeholder": "master",
- "last_opened_file_path": "/home/iikorni/Downloads/quakespasm-0.96.3/cmake-build-debug/id1",
- "node.js.detected.package.eslint": "true",
- "node.js.detected.package.jshint": "true",
- "node.js.detected.package.tslint": "true",
- "node.js.selected.package.eslint": "(autodetect)",
- "node.js.selected.package.jshint": "",
- "node.js.selected.package.tslint": "(autodetect)",
- "nodejs_package_manager_path": "npm",
- "settings.editor.selected.configurable": "language.cpp.clang-tidy"
+
+}]]>
@@ -226,7 +188,8 @@
-
+
+
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 14cc516..0110a52 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -7,7 +7,8 @@ find_package(SDL)
find_package(SDL_net)
find_package(OpenGL)
-add_executable(quakespasm Quake/bgmusic.cpp Quake/cd_sdl.cpp Quake/cfgfile.cpp Quake/chase.cpp Quake/cl_demo.cpp Quake/cl_input.cpp Quake/cl_main.cpp Quake/cl_parse.cpp Quake/cl_tent.cpp Quake/cmd.cpp Quake/common.cpp Quake/console.cpp Quake/crc.cpp Quake/convar.cpp Quake/gl_draw.cpp Quake/gl_fog.cpp Quake/gl_mesh.cpp Quake/gl_model.cpp Quake/gl_refrag.cpp Quake/gl_rlight.cpp Quake/gl_rmain.cpp Quake/gl_rmisc.cpp Quake/gl_screen.cpp Quake/gl_sky.cpp Quake/gl_texmgr.cpp Quake/gl_vidsdl.cpp Quake/gl_warp.cpp Quake/host.cpp Quake/host_cmd.cpp Quake/image.cpp Quake/in_sdl.cpp Quake/keys.cpp Quake/main_sdl.cpp Quake/mathlib.cpp Quake/menu.cpp Quake/miniz.cpp Quake/net_bsd.cpp Quake/net_dgrm.cpp Quake/net_loop.cpp Quake/net_main.cpp Quake/net_udp.cpp Quake/pl_linux.cpp Quake/pr_cmds.cpp Quake/pr_edict.cpp Quake/pr_exec.cpp Quake/r_alias.cpp Quake/r_brush.cpp Quake/r_part.cpp Quake/r_sprite.cpp Quake/r_world.cpp Quake/sbar.cpp Quake/snd_codec.cpp Quake/snd_dma.cpp Quake/snd_flac.cpp Quake/snd_mem.cpp Quake/snd_mikmod.cpp Quake/snd_mix.cpp Quake/snd_modplug.cpp Quake/snd_mp3.cpp Quake/snd_mp3tag.cpp Quake/snd_mpg123.cpp Quake/snd_opus.cpp Quake/snd_sdl.cpp Quake/snd_umx.cpp Quake/snd_vorbis.cpp Quake/snd_wave.cpp Quake/snd_xmp.cpp Quake/strlcat.cpp Quake/strlcpy.cpp Quake/sv_main.cpp Quake/sv_move.cpp Quake/sv_phys.cpp Quake/sv_user.cpp Quake/sys_sdl_unix.cpp Quake/view.cpp Quake/wad.cpp Quake/world.cpp Quake/zone.cpp )
+add_executable(quakespasm Quake/bgmusic.cpp Quake/cd_sdl.cpp Quake/cfgfile.cpp Quake/chase.cpp Quake/cl_demo.cpp Quake/cl_input.cpp Quake/cl_main.cpp Quake/cl_parse.cpp Quake/cl_tent.cpp Quake/cmd.cpp Quake/common.cpp Quake/console.cpp Quake/crc.cpp Quake/convar.cpp Quake/gl_draw.cpp Quake/gl_fog.cpp Quake/gl_mesh.cpp Quake/gl_model.cpp Quake/gl_refrag.cpp Quake/gl_rlight.cpp Quake/gl_rmain.cpp Quake/gl_rmisc.cpp Quake/gl_screen.cpp Quake/gl_sky.cpp Quake/gl_texmgr.cpp Quake/gl_vidsdl.cpp Quake/gl_warp.cpp Quake/host.cpp Quake/host_cmd.cpp Quake/image.cpp Quake/in_sdl.cpp Quake/keys.cpp Quake/main_sdl.cpp Quake/mathlib.cpp Quake/menu.cpp Quake/miniz.cpp Quake/net_bsd.cpp Quake/net_dgrm.cpp Quake/net_loop.cpp Quake/net_main.cpp Quake/net_udp.cpp Quake/pl_linux.cpp Quake/pr_cmds.cpp Quake/pr_edict.cpp Quake/pr_exec.cpp Quake/r_alias.cpp Quake/r_brush.cpp Quake/r_part.cpp Quake/r_sprite.cpp Quake/r_world.cpp Quake/sbar.cpp Quake/snd_codec.cpp Quake/snd_dma.cpp Quake/snd_flac.cpp Quake/snd_mem.cpp Quake/snd_mikmod.cpp Quake/snd_mix.cpp Quake/snd_modplug.cpp Quake/snd_mp3.cpp Quake/snd_mp3tag.cpp Quake/snd_mpg123.cpp Quake/snd_opus.cpp Quake/snd_sdl.cpp Quake/snd_umx.cpp Quake/snd_vorbis.cpp Quake/snd_wave.cpp Quake/snd_xmp.cpp Quake/strlcat.cpp Quake/strlcpy.cpp Quake/sv_main.cpp Quake/sv_move.cpp Quake/sv_phys.cpp Quake/sv_user.cpp Quake/sys_sdl_unix.cpp Quake/view.cpp Quake/wad.cpp Quake/world.cpp Quake/zone.cpp
+ Quake/net_msg.cpp)
target_link_libraries(quakespasm OpenGL::GL)
target_link_libraries(quakespasm SDL::SDL)
diff --git a/Quake/bgmusic.cpp b/Quake/bgmusic.cpp
index 9c5ca5f..4212129 100644
--- a/Quake/bgmusic.cpp
+++ b/Quake/bgmusic.cpp
@@ -35,11 +35,11 @@
#define CDRIPTYPE(x) (((x) & CDRIP_TYPES) != 0)
namespace music {
- bool bgmloop;
- convar bgm_extmusic{"bgm_extmusic", "1", {.archive = true}};
+ bool looping;
+ convar extmusic{"bgm_extmusic", "1", {.archive = true}};
namespace {
- snd_stream_t *bgmstream = nullptr;
+ snd_stream_t *stream = nullptr;
bool no_extmusic = false;
float old_volume = -1.0f;
@@ -125,17 +125,17 @@ namespace music {
if (command::argc() == 2) {
if (q_strcasecmp(command::argv(1)->c_str(), "0") == 0 ||
q_strcasecmp(command::argv(1)->c_str(), "off") == 0)
- bgmloop = false;
+ looping = false;
else if (q_strcasecmp(command::argv(1)->c_str(), "1") == 0 ||
q_strcasecmp(command::argv(1)->c_str(), "on") == 0)
- bgmloop = true;
+ looping = true;
else if (q_strcasecmp(command::argv(1)->c_str(), "toggle") == 0)
- bgmloop = !bgmloop;
+ looping = !looping;
- if (bgmstream) bgmstream->loop = bgmloop;
+ if (stream) stream->loop = looping;
}
- if (bgmloop)
+ if (looping)
console::info("Music will be looped\n");
else
console::info("Music will not be looped\n");
@@ -148,8 +148,8 @@ namespace music {
void _jump() {
if (command::argc() != 2) {
console::info("music_jump \n");
- } else if (bgmstream) {
- S_CodecJumpToOrder(bgmstream, static_cast(std::strtol(command::argv(1)->c_str(), nullptr, 10)));
+ } else if (stream) {
+ S_CodecJumpToOrder(stream, static_cast(std::strtol(command::argv(1)->c_str(), nullptr, 10)));
}
}
@@ -170,8 +170,8 @@ namespace music {
/* not supported in quake */
break;
case player_kind::streamer:
- bgmstream = S_CodecOpenStreamType(tmp, handler.type, bgmloop);
- if (bgmstream)
+ stream = S_CodecOpenStreamType(tmp, handler.type, looping);
+ if (stream)
return; /* success */
break;
case player_kind::none:
@@ -191,7 +191,7 @@ namespace music {
int fileBytes;
byte raw[16384];
- if (bgmstream->status != STREAM_PLAY) {
+ if (stream->status != STREAM_PLAY) {
return;
}
@@ -209,42 +209,42 @@ namespace music {
bufferSamples = MAX_RAW_SAMPLES - (s_rawend - paintedtime);
/* decide how much data needs to be read from the file */
- fileSamples = bufferSamples * bgmstream->info.rate / shm->speed;
+ fileSamples = bufferSamples * stream->info.rate / shm->speed;
if (!fileSamples)
return;
/* our max buffer size */
- fileBytes = fileSamples * (bgmstream->info.width * bgmstream->info.channels);
+ fileBytes = fileSamples * (stream->info.width * stream->info.channels);
if (fileBytes > (int) sizeof(raw)) {
fileBytes = (int) sizeof(raw);
fileSamples = fileBytes /
- (bgmstream->info.width * bgmstream->info.channels);
+ (stream->info.width * stream->info.channels);
}
/* Read */
- res = S_CodecReadStream(bgmstream, fileBytes, raw);
+ res = S_CodecReadStream(stream, fileBytes, raw);
if (res < fileBytes) {
fileBytes = res;
- fileSamples = res / (bgmstream->info.width * bgmstream->info.channels);
+ fileSamples = res / (stream->info.width * stream->info.channels);
}
if (res > 0) /* data: add to raw buffer */
{
- S_RawSamples(fileSamples, bgmstream->info.rate,
- bgmstream->info.width,
- bgmstream->info.channels,
+ S_RawSamples(fileSamples, stream->info.rate,
+ stream->info.width,
+ stream->info.channels,
raw, bgmvolume.value);
did_rewind = false;
} else if (res == 0) /* EOF */
{
- if (bgmloop) {
+ if (looping) {
if (did_rewind) {
console::info("Stream keeps returning EOF.\n");
stop();
return;
}
- res = S_CodecRewindStream(bgmstream);
+ res = S_CodecRewindStream(stream);
if (res != 0) {
console::info("Stream seek error (%i), stopping.\n", res);
stop();
@@ -266,7 +266,7 @@ namespace music {
}
void init() {
- bgm_extmusic.inscribe();
+ extmusic.inscribe();
command::add("music", _play);
command::add("music_pause", _pause);
command::add("music_resume", _resume);
@@ -277,7 +277,7 @@ namespace music {
if (common::check_param("-noextmusic").has_value())
no_extmusic = true;
- bgmloop = true;
+ looping = true;
for (auto i = 0; wanted_handlers[i].type != CODECTYPE_NONE; i++) {
switch (wanted_handlers[i].player) {
@@ -341,8 +341,8 @@ namespace music {
/* not supported in quake */
break;
case player_kind::streamer:
- bgmstream = S_CodecOpenStreamType(tmp, chosen->type, bgmloop);
- if (bgmstream)
+ stream = S_CodecOpenStreamType(tmp, chosen->type, looping);
+ if (stream)
return; /* success */
break;
case player_kind::none:
@@ -354,10 +354,10 @@ namespace music {
}
void stop() {
- if (bgmstream) {
- bgmstream->status = STREAM_NONE;
- S_CodecCloseStream(bgmstream);
- bgmstream = nullptr;
+ if (stream) {
+ stream->status = STREAM_NONE;
+ S_CodecCloseStream(stream);
+ stream = nullptr;
s_rawend = 0;
}
}
@@ -370,25 +370,25 @@ namespace music {
bgmvolume.set("1");
old_volume = bgmvolume.value;
}
- if (bgmstream)
+ if (stream)
update_stream();
}
void pause() {
- if (bgmstream) {
- if (bgmstream->status == STREAM_PLAY)
- bgmstream->status = STREAM_PAUSE;
+ if (stream) {
+ if (stream->status == STREAM_PLAY)
+ stream->status = STREAM_PAUSE;
}
}
void resume() {
- if (bgmstream) {
- if (bgmstream->status == STREAM_PAUSE)
- bgmstream->status = STREAM_PLAY;
+ if (stream) {
+ if (stream->status == STREAM_PAUSE)
+ stream->status = STREAM_PLAY;
}
}
- void play_cd_track(const byte track, const bool looping) {
+ void play_cd_track(const byte track, const bool should_loop) {
/* instead of searching by the order of music_handlers, do so by
* the order of searchpath priority: the file from the searchpath
* with the highest path_id is most likely from our own gamedir
@@ -400,14 +400,14 @@ namespace music {
unsigned int path_id;
stop();
- if (CDAudio_Play(track, looping) == 0) {
+ if (CDAudio_Play(track, should_loop) == 0) {
return; /* success */
}
if (active_handlers.empty())
return; // We obviously can't play anything without handlers.
- if (no_extmusic || bgm_extmusic.value == 0.0)
+ if (no_extmusic || extmusic.value == 0.0)
return;
unsigned int prev_id = 0;
@@ -437,8 +437,8 @@ namespace music {
else {
q_snprintf(tmp, sizeof(tmp), "%s/track%02d.%s",
MUSIC_DIRNAME, static_cast(track), ext);
- bgmstream = S_CodecOpenStreamType(tmp, type, bgmloop);
- if (!bgmstream)
+ stream = S_CodecOpenStreamType(tmp, type, should_loop);
+ if (!stream)
console::info("Couldn't handle music file %s\n", tmp);
}
}
diff --git a/Quake/bgmusic.hpp b/Quake/bgmusic.hpp
index 1c32869..3c77c3a 100644
--- a/Quake/bgmusic.hpp
+++ b/Quake/bgmusic.hpp
@@ -26,8 +26,8 @@
#pragma once
namespace music {
- extern bool bgmloop;
- extern convar bgm_extmusic;
+ extern bool looping;
+ extern convar extmusic;
void init();
@@ -43,5 +43,5 @@ namespace music {
void resume();
- void play_cd_track(byte track, bool looping);
+ void play_cd_track(byte track, bool should_loop);
}
diff --git a/Quake/cl_demo.cpp b/Quake/cl_demo.cpp
index f4d26ce..f86efe8 100644
--- a/Quake/cl_demo.cpp
+++ b/Quake/cl_demo.cpp
@@ -24,7 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "quakedef.hpp"
-static void CL_FinishTimeDemo (void);
+static void CL_FinishTimeDemo(void);
/*
==============================================================================
@@ -40,19 +40,18 @@ read from the demo file.
*/
// from ProQuake: space to fill out the demo header for record at any time
-static byte *demo_head;
-static int *demo_head_sizes;
+static byte *demo_head;
+static int *demo_head_sizes;
/*
==============
CL_ClearSignons
==============
*/
-void CL_ClearSignons (void)
-{
- VEC_CLEAR (demo_head);
- VEC_CLEAR (demo_head_sizes);
- cls.signon = 0;
+void CL_ClearSignons(void) {
+ VEC_CLEAR(demo_head);
+ VEC_CLEAR(demo_head_sizes);
+ cls.signon = 0;
}
/*
@@ -62,19 +61,18 @@ CL_StopPlayback
Called when a demo file runs out, or the user starts a game
==============
*/
-void CL_StopPlayback (void)
-{
- if (!cls.demoplayback)
- return;
+void CL_StopPlayback(void) {
+ if (!cls.demoplayback)
+ return;
- fclose (cls.demofile);
- cls.demoplayback = false;
- cls.demopaused = false;
- cls.demofile = NULL;
- cls.state = ca_disconnected;
+ fclose(cls.demofile);
+ cls.demoplayback = false;
+ cls.demopaused = false;
+ cls.demofile = NULL;
+ cls.state = ca_disconnected;
- if (cls.timedemo)
- CL_FinishTimeDemo ();
+ if (cls.timedemo)
+ CL_FinishTimeDemo();
}
/*
@@ -84,71 +82,65 @@ CL_WriteDemoMessage
Dumps the current net message, prefixed by the length and view angles
====================
*/
-static void CL_WriteDemoMessage (void)
-{
- int len;
- int i;
- float f;
+static void CL_WriteDemoMessage(void) {
+ int len;
+ int i;
+ float f;
- len = LittleLong (net_message.cursize);
- fwrite (&len, 4, 1, cls.demofile);
- for (i = 0; i < 3; i++)
- {
- f = LittleFloat (cl.viewangles[i]);
- fwrite (&f, 4, 1, cls.demofile);
- }
- fwrite (net_message.data, net_message.cursize, 1, cls.demofile);
- fflush (cls.demofile);
+ len = LittleLong(net_message.size());
+ fwrite(&len, 4, 1, cls.demofile);
+ for (i = 0; i < 3; i++) {
+ f = LittleFloat(cl.viewangles[i]);
+ fwrite(&f, 4, 1, cls.demofile);
+ }
+ fwrite(net_message.data(), net_message.size(), 1, cls.demofile);
+ fflush(cls.demofile);
}
-static int CL_GetDemoMessage (void)
-{
- int r, i;
- float f;
+static int CL_GetDemoMessage(void) {
+ int r, i;
+ float f;
- if (cls.demopaused)
- return 0;
+ if (cls.demopaused)
+ return 0;
- // decide if it is time to grab the next message
- if (cls.signon == SIGNONS) // always grab until fully connected
- {
- if (cls.timedemo)
- {
- if (host_framecount == cls.td_lastframe)
- return 0; // already read this frame's message
- cls.td_lastframe = host_framecount;
- // if this is the second frame, grab the real td_starttime
- // so the bogus time on the first frame doesn't count
- if (host_framecount == cls.td_startframe + 1)
- cls.td_starttime = realtime;
- }
- else if (/* cl.time > 0 && */ cl.time <= cl.mtime[0])
- {
- return 0; // don't need another message yet
- }
- }
+ // decide if it is time to grab the next message
+ if (cls.signon == SIGNONS) // always grab until fully connected
+ {
+ if (cls.timedemo) {
+ if (host_framecount == cls.td_lastframe)
+ return 0; // already read this frame's message
+ cls.td_lastframe = host_framecount;
+ // if this is the second frame, grab the real td_starttime
+ // so the bogus time on the first frame doesn't count
+ if (host_framecount == cls.td_startframe + 1)
+ cls.td_starttime = realtime;
+ } else if (/* cl.time > 0 && */ cl.time <= cl.mtime[0]) {
+ return 0; // don't need another message yet
+ }
+ }
-// get the next message
- if (! fread(&net_message.cursize, 4, 1, cls.demofile))
- Sys_Error ("Demo read error");
- VectorCopy (cl.mviewangles[0], cl.mviewangles[1]);
- for (i = 0 ; i < 3 ; i++)
- {
- r = fread (&f, 4, 1, cls.demofile);
- cl.mviewangles[0][i] = LittleFloat (f);
- }
+ // get the next message
+ int msgsize;
+ if (!fread(&msgsize, 4, 1, cls.demofile))
+ Sys_Error("Demo read error");
+ VectorCopy(cl.mviewangles[0], cl.mviewangles[1]);
+ for (i = 0; i < 3; i++) {
+ r = fread(&f, 4, 1, cls.demofile);
+ cl.mviewangles[0][i] = LittleFloat(f);
+ }
- net_message.cursize = LittleLong (net_message.cursize);
- if (net_message.cursize > MAX_MSGLEN)
- Sys_Error ("Demo message > MAX_MSGLEN");
- r = fread (net_message.data, net_message.cursize, 1, cls.demofile);
- if (r != 1)
- {
- CL_StopPlayback ();
- return 0;
- }
+ if (msgsize > MAX_MSGLEN)
+ Sys_Error("Demo message > MAX_MSGLEN");
+ std::uint8_t buf[msgsize];
+ r = fread(&buf, msgsize, 1, cls.demofile);
+ net_message.write(buf, msgsize);
+ if (r != 1) {
+ CL_StopPlayback();
+ return 0;
+ }
- return 1;
+ return 1;
}
/*
@@ -158,39 +150,36 @@ CL_GetMessage
Handles recording and playback of demos, on top of NET_ code
====================
*/
-int CL_GetMessage (void)
-{
- int r;
+int CL_GetMessage(void) {
+ int r;
- if (cls.demoplayback)
- return CL_GetDemoMessage ();
+ if (cls.demoplayback)
+ return CL_GetDemoMessage();
- while (1)
- {
- r = NET_GetMessage (cls.netcon);
+ while (1) {
+ r = NET_GetMessage(cls.netcon);
- if (r != 1 && r != 2)
- return r;
+ if (r != 1 && r != 2)
+ return r;
- // discard nop keepalive message
- if (net_message.cursize == 1 && net_message.data[0] == svc_nop)
- console::info ("<-- server to client keepalive\n");
- else
- break;
- }
+ // discard nop keepalive message
+ if (net_message.size() == 1 && net_message.data()[0] == svc_nop)
+ console::info("<-- server to client keepalive\n");
+ else
+ break;
+ }
- if (cls.demorecording)
- CL_WriteDemoMessage ();
+ if (cls.demorecording)
+ CL_WriteDemoMessage();
- if (cls.signon < 2)
- {
- // record messages before full connection, so that a
- // demo record can happen after connection is done
- Vec_Append ((void**)&demo_head, 1, net_message.data, net_message.cursize);
- VEC_PUSH (demo_head_sizes, net_message.cursize);
- }
+ if (cls.signon < 2) {
+ // record messages before full connection, so that a
+ // demo record can happen after connection is done
+ Vec_Append((void **) &demo_head, 1, net_message.data(), net_message.size());
+ VEC_PUSH(demo_head_sizes, net_message.size());
+ }
- return r;
+ return r;
}
@@ -201,30 +190,28 @@ CL_Stop_f
stop recording a demo
====================
*/
-void CL_Stop_f (void)
-{
- if (command::last_source != command::source::command)
- return;
+void CL_Stop_f(void) {
+ if (command::last_source != command::source::command)
+ return;
- if (!cls.demorecording)
- {
- console::info ("Not recording a demo.\n");
- return;
- }
+ if (!cls.demorecording) {
+ console::info("Not recording a demo.\n");
+ return;
+ }
-// write a disconnect message to the demo file
- SZ_Clear (&net_message);
- MSG_WriteByte (&net_message, svc_disconnect);
- CL_WriteDemoMessage ();
+ // write a disconnect message to the demo file
+ net_message.clear();
+ net_message.write_byte(svc_disconnect);
+ CL_WriteDemoMessage();
-// finish up
- fclose (cls.demofile);
- cls.demofile = NULL;
- cls.demorecording = false;
- console::info ("Completed demo\n");
-
-// ericw -- update demo tab-completion list
- DemoList_Rebuild ();
+ // finish up
+ fclose(cls.demofile);
+ cls.demofile = NULL;
+ cls.demorecording = false;
+ console::info("Completed demo\n");
+
+ // ericw -- update demo tab-completion list
+ DemoList_Rebuild();
}
/*
@@ -234,162 +221,143 @@ CL_Record_f
record