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

Enhance multiple base directory usage #628

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ if(FORCE_PORTABLE_INSTALL)
set(CMAKE_INSTALL_LIBDIR ".")
set(CMAKE_INSTALL_DATADIR ".")
set(CMAKE_INSTALL_DOCDIR ".")

set(D3_DATADIR "${CMAKE_INSTALL_DATADIR}")
else()
set(CMAKE_INSTALL_DATADIR "${CMAKE_INSTALL_DATADIR}/Descent3")
# On system install files will go into /usr/share/Descent3
set(D3_DATADIR "${CMAKE_INSTALL_FULL_DATADIR}/Descent3")
Lgt2x marked this conversation as resolved.
Show resolved Hide resolved
endif()

if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
Expand Down
6 changes: 6 additions & 0 deletions Descent3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,12 @@ if(WIN32)
)
endif()

configure_file(
${CMAKE_SOURCE_DIR}/lib/d3_platform_path.h.in
${CMAKE_BINARY_DIR}/lib/d3_platform_path.h
@ONLY
)

if(UNIX AND NOT APPLE)
set(PLATFORM_LIBS m ${CMAKE_DL_LIBS})
endif()
Expand Down
10 changes: 5 additions & 5 deletions Descent3/audiotaunts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

#include <cstdlib>
#include <cstring>
#include <filesystem>

#include "debug.h"
#include "pserror.h"
#include "audiotaunts.h"
#include "cfile.h"
Expand Down Expand Up @@ -92,7 +92,7 @@ void taunt_SetDelayTime(float t) { Audio_taunt_delay_time = t; }
// taunt_PlayTauntFile
//
// Given a path to an .osf file, it will play it
bool taunt_PlayTauntFile(const char *filename) {
bool taunt_PlayTauntFile(const std::filesystem::path &filename) {
if (!Audio_taunts_enabled)
return false;

Expand All @@ -113,7 +113,7 @@ bool taunt_PlayPlayerTaunt(int pnum, int index) {
}

if ((NetPlayers[pnum].flags & NPF_CONNECTED) && (NetPlayers[pnum].sequence == NETSEQ_PLAYING)) {
char fullpath[_MAX_PATH];
std::filesystem::path fullpath;
char *file;
switch (index) {
case 0:
Expand All @@ -130,10 +130,10 @@ bool taunt_PlayPlayerTaunt(int pnum, int index) {
break;
}

ddio_MakePath(fullpath, LocalCustomSoundsDir, file, NULL);
fullpath = LocalCustomSoundsDir / file;

if (!cfexist(fullpath)) {
LOG_WARNING.printf("TAUNT: file %s doesn't exist (pnum=%d)", fullpath, pnum);
LOG_WARNING.printf("TAUNT: file %s doesn't exist (pnum=%d)", fullpath.u8string().c_str(), pnum);
return false;
}

Expand Down
4 changes: 3 additions & 1 deletion Descent3/audiotaunts.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
#ifndef __AUDIO_TAUNT_H_
#define __AUDIO_TAUNT_H_

#include <filesystem>

extern bool Audio_taunts_enabled;

// Error codes:
Expand Down Expand Up @@ -82,7 +84,7 @@ bool taunt_ImportWave(const char *wave_filename, const char *outputfilename);
// taunt_PlayTauntFile
//
// Given a path to an .osf file, it will play it
bool taunt_PlayTauntFile(const char *filename);
bool taunt_PlayTauntFile(const std::filesystem::path &filename);

// taunt_PlayPlayerTaunt
//
Expand Down
8 changes: 6 additions & 2 deletions Descent3/d3movie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,16 @@ void mve_SetRenderProperties(int16_t x, int16_t y, int16_t w, int16_t h, rendere
// plays a movie using the current screen.
int mve_PlayMovie(const std::filesystem::path &pMovieName, oeApplication *pApp) {
#ifndef NO_MOVIES
// first, find that movie..
// first, find that movie.
std::filesystem::path real_name = cf_LocatePath("movies" / pMovieName);
if (real_name.empty()) {
LOG_ERROR << "MOVIE: File " << pMovieName << " not found, skipping playback";
return MVELIB_FILE_ERROR;
}
// open movie file.
FILE *hFile = fopen(real_name.u8string().c_str(), "rb");
if (hFile == nullptr) {
LOG_ERROR.printf("MOVIE: Unable to open %s", real_name.u8string().c_str());
LOG_ERROR << "MOVIE: Unable to open " << pMovieName;
return MVELIB_FILE_ERROR;
}

Expand Down
44 changes: 28 additions & 16 deletions Descent3/demofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@
#include <filesystem>

#include "cfile.h"
#include "ddio.h"
#include "objinfo.h"
#include "ship.h"
#include "ui.h"
Expand Down Expand Up @@ -357,30 +358,41 @@ void DemoToggleRecording() {
// hand coded 128 because long filenames were failing in cfopen(which called fopen, which failed on very
// long filenames. instead of printing a message out to the user, just don't allow filenames that long)
if (DoEditDialog(TXT_DEMOFILENAME, szfile, 128)) {
if (stricmp(szfile + (strlen(szfile) - 4), ".dem") != 0) {
strcat(szfile, ".dem");
std::filesystem::path demo_directory = cf_GetWritableBaseDirectory() / "demo";

std::error_code ec;
std::filesystem::create_directories(demo_directory, ec);
if (ec) {
LOG_ERROR << "Failed to create " << demo_directory << " directory. Unable to create demo file!";
AddBlinkingHUDMessage(TXT_DEMOCANTCREATE);
Demo_fname.clear();
return;
}
Demo_fname = cf_GetWritableBaseDirectory() / "demo" / szfile;
LOG_INFO.printf("Saving demo to file: %s", Demo_fname.u8string().c_str());

Demo_fname = demo_directory / szfile;
Demo_fname.replace_extension(".dem");

LOG_INFO << "Saving demo to file " << Demo_fname;
// Try to create the file
Demo_cfp = cfopen(Demo_fname, "wb");
if (Demo_cfp) {
// Setup the demo variables
if (!(Game_mode & GM_MULTI)) {
MultiBuildMatchTables();
}
// Male sure we write the player info the first frame
Demo_last_pinfo = timer_GetTime() - (DEMO_PINFO_UPDATE * 2);
Demo_flags = DF_RECORDING;
// Write the header
DemoWriteHeader();
DemoStartNewFrame();
} else {
if (!Demo_cfp) {
// cfopen failed
LOG_ERROR << "Unable to create demo file!";
AddBlinkingHUDMessage(TXT_DEMOCANTCREATE);
Demo_fname.clear();
return;
}

// Set up the demo variables
if (!(Game_mode & GM_MULTI)) {
MultiBuildMatchTables();
}
// Male sure we write the player info the first frame
Demo_last_pinfo = timer_GetTime() - (DEMO_PINFO_UPDATE * 2);
Demo_flags = DF_RECORDING;
// Write the header
DemoWriteHeader();
DemoStartNewFrame();
}
}

Expand Down
2 changes: 0 additions & 2 deletions Descent3/descent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -707,5 +707,3 @@ void D3DebugResumeHandler() {
}

#endif

void RenderBlankScreen();
Loading
Loading