Skip to content
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
14 changes: 8 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ endif()

project(commando LANGUAGES C CXX)

list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")

# This file handles extra settings wanted/needed for different compilers.
include(cmake/compilers.cmake)
include(compilers)

# Set where the build results will end up
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" CACHE PATH "Where to output archives")
Expand Down Expand Up @@ -49,27 +51,27 @@ endif()
include(FetchContent)

if(W3D_BUILD_OPTION_FFMPEG)
include(cmake/ffmpeg.cmake)
include(ffmpeg)
endif()

# Find/Add build dependencies and stubs.
# Only 32bit Windows can make use of these APIs as the libraries shipped with the game.
if(WIN32)
include(cmake/miles.cmake)
include(miles)

# Do we want to build with bink for video decoding?
option(W3D_BUILD_OPTION_BINK "Build with bink." ON)
add_feature_info(BinkBuild W3D_BUILD_OPTION_BINK "Build Renegade with Bink")

if(W3D_BUILD_OPTION_BINK)
include(cmake/bink.cmake)
include(bink)
target_compile_definitions(binkstub INTERFACE W3D_HAS_BINK)
endif()

include(cmake/dx9.cmake)
include(dx9)
endif()

include(cmake/gamespy.cmake)
include(gamespy)

# Add main build targets
add_subdirectory(Code)
Expand Down
21 changes: 6 additions & 15 deletions Code/Tools/LevelEdit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ set(LEVELEDIT_SRC
VisStatsDialog.cpp
VisualOptionsDialog.cpp
VisWindowDialog.cpp
VSSClass.cpp
#VSSClass.cpp
WaypathDefinition.cpp
WaypathInfoPage.cpp
WaypathNode.cpp
Expand Down Expand Up @@ -408,7 +408,7 @@ set(LEVELEDIT_SRC
VisStatsDialog.h
VisualOptionsDialog.h
VisWindowDialog.h
VSSClass.h
#VSSClass.h
WaypathDefinition.h
WaypathInfoPage.h
WaypathNode.h
Expand All @@ -419,8 +419,11 @@ set(LEVELEDIT_SRC
ZoneEditDialog.h
ZoneInfoPage.h
ZoneNode.h
LevelEdit.rc
)

include(crunch)

# Targets to build.
add_executable(leveledit WIN32)

Expand All @@ -434,6 +437,7 @@ target_include_directories(leveledit PRIVATE
)

target_link_libraries(leveledit PRIVATE
crnlib
winmm
wsock32
shlwapi
Expand All @@ -458,17 +462,4 @@ target_link_libraries(leveledit PRIVATE
combate
)

if(WIN32)
target_link_options(leveledit PRIVATE /NODEFAULTLIB:libci.lib /NODEFAULTLIB:libc.lib)
add_custom_command(
OUTPUT VSS.h VSS_i.c
COMMAND midl.exe "${CMAKE_CURRENT_SOURCE_DIR}\\VSS.IDL" /header VSS.h
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS "${CMAKE_CURRENT_LIST_DIR}/VSS.IDL"
VERBATIM
)

target_sources(leveledit PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/VSS_i.c LevelEdit.rc)
endif()

target_sources(leveledit PRIVATE ${LEVELEDIT_SRC})
4 changes: 3 additions & 1 deletion Code/Tools/LevelEdit/FileMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@
#include "presetmgr.h"
#include "spawnernode.h"
#include "wwstring.h"
#include "vssclass.h"
#include "assetdatabase.h"
#include "editorbuild.h"
#include "assetpackagemgr.h"
#include "mixfiledatabase.h"

#ifndef PUBLIC_EDITOR_VER
#include "vssclass.h"
#endif


////////////////////////////////////////////////////////////////////////
Expand Down
84 changes: 26 additions & 58 deletions Code/Tools/LevelEdit/TGAToDXT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

#include "StdAfx.h"
//#include "NvDXTLib.h"
#include "Targa.h"
#include "TGAToDXT.H"
#include <crnlib.h>
#include <io.h>
#include <stdlib.h>
#include <stdlib.h>

// Singletons.
TGAToDXTClass _TGAToDXTConverter;
Expand All @@ -52,11 +52,10 @@ TGAToDXTClass _TGAToDXTConverter;
///////////////////////////////////////////////////////////////////////////////
TGAToDXTClass::TGAToDXTClass()
: WriteTimePtr (NULL),
Buffer(NULL),
BufferSize (1024),
BufferCount (0)
{
Buffer = new unsigned char [BufferSize];
ASSERT (Buffer != NULL);
}


Expand All @@ -67,8 +66,6 @@ TGAToDXTClass::TGAToDXTClass()
///////////////////////////////////////////////////////////////////////////////
TGAToDXTClass::~TGAToDXTClass()
{
// Clean-up.
delete [] Buffer;
}


Expand Down Expand Up @@ -102,64 +99,31 @@ bool TGAToDXTClass::Convert (const char *inputpathname, const char *outputpathna
validsize = (targa.Header.Width >= 4) && (targa.Header.Height >= 4);
validaspect = ((float) MAX (targa.Header.Width, targa.Header.Height)) / ((float) MIN (targa.Header.Width, targa.Header.Height)) <= 8.0f;
if (validbitdepth && validsize && validaspect) {

unsigned char *byte;
HRESULT errorcode;
crn_comp_params comp_params;
comp_params.m_width = targa.Header.Width;
comp_params.m_height = targa.Header.Height;
comp_params.set_flag(cCRNCompFlagHierarchical, false);
comp_params.m_file_type = cCRNFileTypeDDS;
comp_params.m_format = targa.Header.PixelDepth == 32 ? cCRNFmtDXT5 : cCRNFmtDXT1;

targa.YFlip();
comp_params.m_pImages[0][0] = reinterpret_cast<crn_uint32 *>(targa.GetImage());

// If TGA has an alpha channel...
if (targa.Header.PixelDepth == 32) {

// Analyse the alpha channel and ignore it if it contains redundant data (ie. is either all black or all white).
byte = (unsigned char*) targa.GetImage();
if ((*(byte + 3) == 0x00) || (*(byte + 3) == 0xff)) {

const unsigned char alpha = *(byte + 3);

redundantalpha = true;
for (unsigned p = 0; p < ((unsigned) targa.Header.Width) * ((unsigned) targa.Header.Height); p++) {
redundantalpha &= (*(byte + 3) == alpha);
byte += 4;
}
}

if (!redundantalpha) {
errorcode = E_NOTIMPL;
//errorcode = ::nvDXTcompress ((unsigned char*) targa.GetImage(), targa.Header.Width, targa.Header.Height, TF_DXT5, true, false, 4);

} else {

unsigned char *nonalphaimage, *nonalphabyte;

// Remove the alpha channel and swizel the pixel data.
nonalphaimage = new unsigned char [3 * ((unsigned) targa.Header.Width) * ((unsigned) targa.Header.Height)];
nonalphabyte = nonalphaimage;

byte = (unsigned char*) targa.GetImage();
for (unsigned p = 0; p < ((unsigned) targa.Header.Width) * ((unsigned) targa.Header.Height); p++) {

*(nonalphabyte + 0) = *(byte + 0);
*(nonalphabyte + 1) = *(byte + 1);
*(nonalphabyte + 2) = *(byte + 2);
nonalphabyte += 3;
byte += 4;
}

errorcode = E_NOTIMPL;
//errorcode = ::nvDXTcompress (nonalphaimage, targa.Header.Width, targa.Header.Height, TF_DXT1, true, false, 3);
delete [] nonalphaimage;
}

} else {
errorcode = E_NOTIMPL;
//errorcode = ::nvDXTcompress ((unsigned char*) targa.GetImage(), targa.Header.Width, targa.Header.Height, TF_DXT1, true, false, 3);
}
crn_mipmap_params mip_params;
// mip_params.m_gamma_filtering = true;
mip_params.m_mode = cCRNMipModeGenerateMips;
mip_params.m_min_mip_size = 4;

crn_uint32 output_file_size;
void *output_file_data = crn_compress(comp_params, mip_params, output_file_size);
// Was the image compressed successfully?
// NOTE: Any image that does not have power of 2 dimensions will not be compressed.
if (errorcode >= 0) {
if (output_file_data) {
Buffer = static_cast<unsigned char *>(output_file_data);
BufferCount = output_file_size;
Write (outputpathname);
Buffer = NULL;
crn_free_block(output_file_data);
success = true;
}
}
Expand All @@ -176,10 +140,14 @@ bool TGAToDXTClass::Convert (const char *inputpathname, const char *outputpathna
///////////////////////////////////////////////////////////////////////////////
void TGAToDXTClass::Write (const char *outputpathname)
{
if (!Buffer) {
return;
}

HANDLE hfile;
DWORD bytecountwritten;

hfile = ::CreateFile (outputpathname, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0L, NULL);
hfile = ::CreateFileA (outputpathname, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0L, NULL);
if (hfile != INVALID_HANDLE_VALUE) {
LockFile (hfile, 0, 0, BufferCount, 0);
WriteFile (hfile, Buffer, BufferCount, &bytecountwritten, NULL);
Expand Down
2 changes: 1 addition & 1 deletion Code/Tools/LevelEdit/editorbuild.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
// built with the public "mod" functionality or the in-house tool
// functionality.
//
//#define PUBLIC_EDITOR_VER
#define PUBLIC_EDITOR_VER



Expand Down
94 changes: 94 additions & 0 deletions cmake/crunch.cmake
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of adding a new .cmake file, should we instead add a (custom) vcpkg build script for this project? since we're using vcpkg already(as part of the FFMPEG PR). Mixing both vcpkg and the FetchContent doesn't seem like a great idea.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't that require vcpkg on all platforms then? I'd rather rely on platforms package management systems where possible and give developers the ability to use alternative methods for providing required dependencies rather than making vcpkg a hard requirement. The other option is to vendor it into our source tree.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vcpkg is cross-platform(I've never used it on Linux though), so that shouldn't be an issue. The (potential) problem that I see with using the platform package management is that the platform may not have the correct version of a dependency, so you might need to build dependencies anyway. At least with vcpkg we can also package up prebuilt dependencies so that you don't need to build everything all the time.

From my (somewhat limited) use of vcpkg, it should be optional - unless you explicitly tell cmake to use the packages from vcpkg, it will look on your system.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point. Could do a find call and fall back to fetching and building if its not found I guess?

Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
FetchContent_Populate(
crunch
GIT_REPOSITORY https://github.com/BinomialLLC/crunch.git
GIT_TAG 36479bc697be19168daafbf15f47f3c60ccec004
)

set(CRNLIB_SOURCES
${crunch_SOURCE_DIR}/crnlib/crn_arealist.cpp
${crunch_SOURCE_DIR}/crnlib/crn_assert.cpp
${crunch_SOURCE_DIR}/crnlib/crn_checksum.cpp
${crunch_SOURCE_DIR}/crnlib/crn_colorized_console.cpp
${crunch_SOURCE_DIR}/crnlib/crn_command_line_params.cpp
${crunch_SOURCE_DIR}/crnlib/crn_comp.cpp
${crunch_SOURCE_DIR}/crnlib/crn_console.cpp
${crunch_SOURCE_DIR}/crnlib/crn_core.cpp
${crunch_SOURCE_DIR}/crnlib/crn_data_stream.cpp
${crunch_SOURCE_DIR}/crnlib/crn_dds_comp.cpp
${crunch_SOURCE_DIR}/crnlib/crn_decomp.cpp
${crunch_SOURCE_DIR}/crnlib/crn_dxt.cpp
${crunch_SOURCE_DIR}/crnlib/crn_dxt1.cpp
${crunch_SOURCE_DIR}/crnlib/crn_dxt5a.cpp
${crunch_SOURCE_DIR}/crnlib/crn_dxt_endpoint_refiner.cpp
${crunch_SOURCE_DIR}/crnlib/crn_dxt_fast.cpp
${crunch_SOURCE_DIR}/crnlib/crn_dxt_hc.cpp
${crunch_SOURCE_DIR}/crnlib/crn_dxt_hc_common.cpp
${crunch_SOURCE_DIR}/crnlib/crn_dxt_image.cpp
${crunch_SOURCE_DIR}/crnlib/crn_dynamic_string.cpp
${crunch_SOURCE_DIR}/crnlib/crn_etc.cpp
${crunch_SOURCE_DIR}/crnlib/crn_file_utils.cpp
${crunch_SOURCE_DIR}/crnlib/crn_find_files.cpp
${crunch_SOURCE_DIR}/crnlib/crn_hash.cpp
${crunch_SOURCE_DIR}/crnlib/crn_hash_map.cpp
${crunch_SOURCE_DIR}/crnlib/crn_huffman_codes.cpp
${crunch_SOURCE_DIR}/crnlib/crn_image_utils.cpp
${crunch_SOURCE_DIR}/crnlib/crn_jpgd.cpp
${crunch_SOURCE_DIR}/crnlib/crn_jpge.cpp
${crunch_SOURCE_DIR}/crnlib/crn_ktx_texture.cpp
${crunch_SOURCE_DIR}/crnlib/crn_lzma_codec.cpp
${crunch_SOURCE_DIR}/crnlib/crn_math.cpp
${crunch_SOURCE_DIR}/crnlib/crn_mem.cpp
${crunch_SOURCE_DIR}/crnlib/crn_miniz.cpp
${crunch_SOURCE_DIR}/crnlib/crn_mipmapped_texture.cpp
${crunch_SOURCE_DIR}/crnlib/crn_pixel_format.cpp
${crunch_SOURCE_DIR}/crnlib/crn_platform.cpp
${crunch_SOURCE_DIR}/crnlib/crn_prefix_coding.cpp
${crunch_SOURCE_DIR}/crnlib/crn_qdxt1.cpp
${crunch_SOURCE_DIR}/crnlib/crn_qdxt5.cpp
${crunch_SOURCE_DIR}/crnlib/crn_rand.cpp
${crunch_SOURCE_DIR}/crnlib/crn_resample_filters.cpp
${crunch_SOURCE_DIR}/crnlib/crn_resampler.cpp
${crunch_SOURCE_DIR}/crnlib/crn_rg_etc1.cpp
${crunch_SOURCE_DIR}/crnlib/crn_ryg_dxt.cpp
${crunch_SOURCE_DIR}/crnlib/crn_sparse_bit_array.cpp
${crunch_SOURCE_DIR}/crnlib/crn_stb_image.cpp
${crunch_SOURCE_DIR}/crnlib/crn_strutils.cpp
${crunch_SOURCE_DIR}/crnlib/crn_symbol_codec.cpp
${crunch_SOURCE_DIR}/crnlib/crn_texture_comp.cpp
${crunch_SOURCE_DIR}/crnlib/crn_texture_conversion.cpp
${crunch_SOURCE_DIR}/crnlib/crn_texture_file_types.cpp
${crunch_SOURCE_DIR}/crnlib/crn_threaded_resampler.cpp
${crunch_SOURCE_DIR}/crnlib/crn_threading_pthreads.cpp
$<$<PLATFORM_ID:Windows>:${crunch_SOURCE_DIR}/crnlib/crn_threading_win32.cpp>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: What's required for crunch to build on Linux/macOS?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I based it on BinomialLLC/crunch#46 which I am assuming builds on linux as well as windows? The makefile provided just ommits the win32 specific files.

${crunch_SOURCE_DIR}/crnlib/crn_timer.cpp
${crunch_SOURCE_DIR}/crnlib/crn_utils.cpp
${crunch_SOURCE_DIR}/crnlib/crn_value.cpp
${crunch_SOURCE_DIR}/crnlib/crn_vector.cpp
${crunch_SOURCE_DIR}/crnlib/crn_zeng.cpp
${crunch_SOURCE_DIR}/crnlib/crnlib.cpp
${crunch_SOURCE_DIR}/crnlib/lzma_7zBuf.cpp
${crunch_SOURCE_DIR}/crnlib/lzma_7zBuf2.cpp
${crunch_SOURCE_DIR}/crnlib/lzma_7zCrc.cpp
${crunch_SOURCE_DIR}/crnlib/lzma_7zFile.cpp
${crunch_SOURCE_DIR}/crnlib/lzma_7zStream.cpp
${crunch_SOURCE_DIR}/crnlib/lzma_Alloc.cpp
${crunch_SOURCE_DIR}/crnlib/lzma_Bcj2.cpp
${crunch_SOURCE_DIR}/crnlib/lzma_Bra.cpp
${crunch_SOURCE_DIR}/crnlib/lzma_Bra86.cpp
${crunch_SOURCE_DIR}/crnlib/lzma_BraIA64.cpp
${crunch_SOURCE_DIR}/crnlib/lzma_LzFind.cpp
$<$<PLATFORM_ID:Windows>:${crunch_SOURCE_DIR}/crnlib/lzma_LzFindMt.cpp>
${crunch_SOURCE_DIR}/crnlib/lzma_LzmaDec.cpp
${crunch_SOURCE_DIR}/crnlib/lzma_LzmaEnc.cpp
${crunch_SOURCE_DIR}/crnlib/lzma_LzmaLib.cpp
$<$<PLATFORM_ID:Windows>:${crunch_SOURCE_DIR}/crnlib/lzma_Threads.cpp>
)

add_library(crnlib STATIC ${CRNLIB_SOURCES})
target_include_directories(crnlib
PUBLIC
$<BUILD_INTERFACE:
${crunch_SOURCE_DIR}/crnlib
${crunch_SOURCE_DIR}/inc
>
)