Skip to content
Open
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Tools
*.a
viewer
mc2
text_tool
text_tool/text_tool
.ycm_extra_conf.py
.ycm_extra_conf.pyc
*.ico
Expand All @@ -48,6 +48,7 @@ tmp/
dump/
test_code/
test_sound/
cmake/sdl2
# Source repository should not track built resources
*.fst

Expand Down
58 changes: 52 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
cmake_minimum_required (VERSION 3.10)
cmake_minimum_required (VERSION 3.14)
# select GLVND versus legacy OpenGL libraries
cmake_policy(SET CMP0072 NEW) # cmake --help-policy CMP0072
project(mc2)

include(CMakeToolsHelpers OPTIONAL)
# Load the URLs for the SDL2 cmake modules and the MC2 data repo
include(MC2Repos REQUIRED)

# Set a default build type for single-configuration
# CMake generators if no build type is set.
Expand Down Expand Up @@ -51,6 +53,37 @@ endif()
add_definitions(-DUSE_ASSEMBLER_CODE=0)
add_definitions(-DLINUX_BUILD)

find_package(Git REQUIRED)

if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/sdl2")
message(STATUS "Found cmake SDL package dir")
else()
# The SDL2 cmake package directory is missing, so clone it from a repo
message(STATUS "Cloning from ${SDL2_CMAKE_MODULE_REPO}")
execute_process(COMMAND ${GIT_EXECUTABLE} clone ${SDL2_CMAKE_MODULE_REPO} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/sdl2
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_CLONE_RESULT )
if(NOT GIT_CLONE_RESULT EQUAL "0")
message(FATAL_ERROR "git clone of repo failed with ${GIT_CLONE_RESULT}, please clone manually")
endif()
endif()

# Check for MC2 data dir next to the MC2 dir. If not there, clone it from a repo
get_filename_component(MC2_DATA_PATH "../mc2srcdata" ABSOLUTE)
if(EXISTS "${MC2_DATA_PATH}")
message(STATUS "Found MC2 data dir")
else()
# The MechCommander 2 data directory is missing so clone from a repo
message(STATUS "Cloning from ${MC2_DATA_REPO}")
execute_process(COMMAND ${GIT_EXECUTABLE} clone ${MC2_DATA_REPO} ${MC2_DATA_PATH}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/..
RESULT_VARIABLE GIT_CLONE_RESULT )
if(NOT GIT_CLONE_RESULT EQUAL "0")
message(FATAL_ERROR "git clone of MC2 data repo failed with ${GIT_CLONE_RESULT}, please clone manually")
endif()
endif()


find_package(SDL2 REQUIRED)
find_package(SDL2_mixer REQUIRED)
#required by text_tool
Expand All @@ -74,6 +107,16 @@ get_filename_component(COM_PATH2 "./GameOS/gameos" ABSOLUTE)

set(COMMON_INCLUDE_DIRS ${COM_PATH1} ${COM_PATH2})

include_directories(${COMMON_INCLUDE_DIRS} "./mclib" "./gui" "./code" "./netlib")

# Build the MC2 resource shared object and after the build completes, copy to the build dir
add_subdirectory("./res" "./out/res")

# Build the data and text tools for converting the MC2 data and after the build completes, copy to the data dir
add_subdirectory("./data_tools" "./out/data_tools")
add_subdirectory("./text_tool" "./out/text_tool")


add_subdirectory("./mclib/" "./out/mclib")
add_subdirectory("./mclib/mlr" "./out/mclib/mlr")
add_subdirectory("./mclib/gosfx" "./out/mclib/gosfx")
Expand Down Expand Up @@ -176,7 +219,6 @@ set(SOURCES
)


include_directories(${COMMON_INCLUDE_DIRS} "./mclib" "./gui" "./code" "./netlib")

if(NOT WIN32)
set(ADDITIONAL_LIBS dl)
Expand All @@ -188,9 +230,13 @@ endif()


add_executable(mc2 ${SOURCES} ${MAIN_SRC})
target_link_libraries(mc2 mclib gosfx mlr stuff gui gameos gameos_main windows ZLIB::ZLIB SDL2::Main GLEW::GLEW SDL2::Mixer ${ADDITIONAL_LIBS} OpenGL::GL)
target_link_libraries(mc2 mc2res mclib gosfx mlr stuff gui gameos gameos_main windows ZLIB::ZLIB SDL2::Main GLEW::GLEW SDL2::Mixer ${ADDITIONAL_LIBS} OpenGL::GL)

add_subdirectory("./res" "./out/res")
add_subdirectory("./data_tools" "./out/data_tools")
add_subdirectory("./text_tool" "./out/text_tool")
add_subdirectory("./Viewer" "./out/Viewer")

add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/shaders
${CMAKE_CURRENT_BINARY_DIR}/shaders )

2 changes: 2 additions & 0 deletions MC2Repos
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
set(SDL2_CMAKE_MODULE_REPO "https://gitlab.com/aminosbh/sdl2-cmake-modules.git")
set(MC2_DATA_REPO "https://github.com/igough/mc2srcdata.git")
47 changes: 46 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,50 @@ Once everything in place, you can launch build scripts as described in correspon
Building on Linux
=================

You, probably already know hot to do it. If not, please, see windows building section, the process is quite similar.
Dependencies
------------
Apt based distros:
```
sudo apt install libsdl2-dev, libsdl2-mixer-dev, libsdl2-ttf-dev, libsdl2-mixer-dev, zlib1g-dev, libglew-dev
```

Build steps
-----------
The build process has been reworked to reduce the number of steps and chance of failure. It handles building and moving data and resources into the correct locations at the right time and cloning repositories as required. The game is build in the ```mc2/build64``` directory.

You only need to clone the mc2 directory and the build process will clone the data directory and SDL2 cmake modules for you the first time you run the build process. The mc2 and mc2srcdata projects will be cloned side by side and the build process relies on this. The top level directory structure will look like :

```
some-empty-directory
|
+---mc2
\---mc2srcdata
```

From an empty directory issue the following commands.

```
git clone https://github.com/alariq/mc2.git
cd mc2
```

Edit MC2Repos to make sure the git repositories are set to which git repository you want to clone them from. Whoever user's mc2 project that you cloned, set the value for the ```MC2_DATA_REPO``` to be that same user. eg. If you cloned **alariq**'s mc2 from ```https://github.com/alariq/mc2```, then set MC2_DATA_REPO to ```https://github.com/alariq/mc2srcdata```.

```
mkdir build64
cd build64
cmake -DCMAKE_LIBRARY_ARCHITECTURE=x64 ..
make all

cd ../../mc2srcdata/build_scripts
make all BUILD_PLATFORM=linux
./copy_assets.sh

```

Running on Linux
----------------
```
cd ../../mc2/build64
./mc2
```
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions code/infowindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ void InfoWindow::init( FitIniFile& file )
char SkillText[32];
for (int i = 0; i < 7; i++ )
{
sprintf( SkillText, "Skill%ld", i );
sprintf( SkillText, "Skill%d", i );
skillInfos[i].init( file, SkillText ,ControlGui::hiResOffsetX, ControlGui::hiResOffsetY);

}
Expand Down Expand Up @@ -623,8 +623,8 @@ void InfoWindow::drawScrollingStuff()

char disabledCount[60][2];
long ammo[60];
char ranges[60];
char names[60];// sebi: changed long to char
byte ranges[60];
byte names[60];// igough: changed char to unsigned 8 bit since the value can be over 127, which causes a negative index
memset( disabledCount, 0, sizeof( char ) * 60 * 2);

// sebi: ORIG BUG FIX memory owerwrite fix fow win64 build: sizeof(long) < sizeof(char*)!
Expand All @@ -643,7 +643,7 @@ void InfoWindow::drawScrollingStuff()

for (long curWeapon = pUnit->numOther; curWeapon < (pUnit->numOther + pUnit->numWeapons); curWeapon++)
{
char nName = pUnit->inventory[curWeapon].masterID;
byte nName = pUnit->inventory[curWeapon].masterID;
bool bFound = 0;
for ( int j = 0; j < i; j++ )
{
Expand Down Expand Up @@ -760,7 +760,7 @@ void InfoWindow::drawScrollingStuff()
//memset( names, 0, sizeof( char* ) * 60 );
MemSet(names, 0);

char count[4];
byte count[4];
count[0] = pUnit->ecm;
count[1] = pUnit->probe;
count[2] = pUnit->jumpJets;
Expand Down Expand Up @@ -995,7 +995,7 @@ void InfoWindow::drawSkillBar( int skill, float yVal, float height )
}

char buffer[32];
sprintf( buffer, "%ld", skill );
sprintf( buffer, "%d", skill );
componentFont.render( buffer, SKILLRIGHT+2, yVal, SCROLLLEFT - SKILLRIGHT - 2, SKILLHEIGHT, 0xff005392, 0, 0 );
}

Expand Down
6 changes: 5 additions & 1 deletion code/mechcmd2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2655,7 +2655,11 @@ void __stdcall GetGameOSEnvironment(const char* CommandLine )
Environment.allowMultipleApps = false;
Environment.dontClearRegistry = true;

Environment.checkCDForFiles = true;
// New code was added to handle JPG versions of the burning files. Unfortunately, these JPG files are NOT included in the textures directory.
// if checkCDForFiles is set to true, then an attempt to load the burning textures from JPGs will continually retry and
// ask to insert the CD. If set to false, when the .JPG is not found, the load will fail and fallback to loading the .TGA
// versions which are included in textures.fst
Environment.checkCDForFiles = false;

if (useSound)
{
Expand Down
28 changes: 28 additions & 0 deletions data_tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
cmake_minimum_required (VERSION 3.14)
project(data_tools)

set(MAKEFST_SOURCES "makefst.cpp")
set(PAK_SOURCES "pak.cpp" "common.hpp")
set(ASECONV_SOURCES "aseconv.cpp" "common.hpp")
Expand All @@ -17,3 +20,28 @@ target_link_libraries(aseconv mclib gosfx mlr stuff gameos windows ZLIB::ZLIB SD
add_executable(makersp ${MAKERSP_SOURCES})
target_link_libraries(makersp mclib stuff gameos windows ZLIB::ZLIB SDL2::Main ${ADDITIONAL_LIBS})

add_custom_command(
TARGET makefst POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_BINARY_DIR}/makefst
${MC2_DATA_PATH}/build_scripts/)

add_custom_command(
TARGET pak POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_BINARY_DIR}/pak
${MC2_DATA_PATH}/build_scripts/)

add_custom_command(
TARGET aseconv POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_BINARY_DIR}/aseconv
${MC2_DATA_PATH}/build_scripts/)

add_custom_command(
TARGET makersp POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_BINARY_DIR}/makersp
${MC2_DATA_PATH}/build_scripts/)


21 changes: 8 additions & 13 deletions data_tools/makefst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int unpack(const char* fst_file, const char* out_path)
long result = ff->open(fst_file);
if (0 != result) {
if(result == FASTFILE_VERSION) {
SPEW(("DBG", "Wrong fast file version\n"));
fprintf(stderr, "Wrong fast file version\n");
}
PAUSE(("Error opening fast file\n"));
delete ff;
Expand Down Expand Up @@ -68,7 +68,7 @@ int unpack(const char* fst_file, const char* out_path)
long fHandle = ff->openFast(hash, fname);
if(fHandle==-1)
{
SPEW(("DUMP", "Failed to find file: %s in fast file\n", fname));
fprintf( stderr, "DUMP: Failed to find file: %s in fast file\n", fname);
continue;
}

Expand Down Expand Up @@ -97,7 +97,7 @@ int unpack(const char* fst_file, const char* out_path)
{
DWORD err = GetLastError();
if (err == ERROR_ALREADY_EXISTS) {
SPEW(("DBG", "Failed to create directory %s, error code: %d - directory already exists\n", tmp, err));
fprintf( stderr, "DBG: Failed to create directory %s, error code: %d - directory already exists\n", tmp, err);
} else {
PAUSE(("Failed to create directory %s, error code: %d\n", tmp, err));
}
Expand Down Expand Up @@ -136,7 +136,7 @@ int pack(const char* in_path, const char* fst_file, const char* mount, const cha

FastFile out_ff;
if(NO_ERR != out_ff.create(fst_file, b_compress)) {
SPEW(("pack: ", "Failed to create fast file %s\n", fst_file));
fprintf( stderr, "pack: Failed to create fast file %s\n", fst_file);
return -1;
}

Expand All @@ -145,13 +145,11 @@ int pack(const char* in_path, const char* fst_file, const char* mount, const cha

std::queue<char*> dirs2process;
std::queue<char*> files2pack;
size_t num_files2pack = 0;

const char* prefix = in_path;


if(!rsp_file) {

char* findString = new char[1];
strcpy(findString, "");
dirs2process.push(findString);
Expand All @@ -161,7 +159,7 @@ int pack(const char* in_path, const char* fst_file, const char* mount, const cha
char* cur_dir = dirs2process.front();
dirs2process.pop();

SPEW(("Processing dir: ", "%s\n", cur_dir));
fprintf( stdout, "Processing dir: %s\n", cur_dir);

char* cur_search_path = new char[strlen(prefix) + strlen(PATH_SEPARATOR) + strlen(cur_dir) + strlen(PATH_SEPARATOR) + strlen("*") + 1];
if(strlen(cur_dir) > 0) {
Expand All @@ -187,8 +185,7 @@ int pack(const char* in_path, const char* fst_file, const char* mount, const cha
}

files2pack.push(filename);
SPEW(("\t", "%s\n", filename));
num_files2pack++;
printf( "\t%s\n", filename);
} else {
if(strcmp(findResult.cFileName, ".") && strcmp(findResult.cFileName, "..")) {
char* findString = new char[strlen(cur_dir) + strlen(findResult.cFileName) + strlen(PATH_SEPARATOR) + 1];
Expand Down Expand Up @@ -239,14 +236,12 @@ int pack(const char* in_path, const char* fst_file, const char* mount, const cha
strcpy(fname, line);

files2pack.push(fname);

num_files2pack++;
}
fclose(fh);
delete[] line;
}

SPEW(("DBG: ", "Numfiles to pack: %d\n", num_files2pack));
printf( "DBG: Numfiles to pack: %lu\n", files2pack.size() );

size_t filebuf_size = CHUNK_SIZE;
uint8_t* filebuf = new uint8_t[filebuf_size];
Expand Down Expand Up @@ -295,7 +290,7 @@ int pack(const char* in_path, const char* fst_file, const char* mount, const cha
if(mount) {

if (strstr(filename, "pmwbubba.fit")) {
int asdfa = 0;
// int asdfa = 0;
}

S_snprintf(filename_buf, filenamebuf_size, "%s" PATH_SEPARATOR "%s", mount, filename);
Expand Down
2 changes: 1 addition & 1 deletion mclib/terrtxm2.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#define NO_ERR 0
#endif

#define MAX_WATER_DETAIL_TEXTURES 256
#define MAX_WATER_DETAIL_TEXTURES 16

#define TOTAL_COLORMAP_TYPES 5
//---------------------------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions mclib/tgl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2457,6 +2457,11 @@ long TG_Shape::MultiTransformShape (Stuff::Matrix4D *shapeToClip, Stuff::Point3D
}
}

#ifdef ALSO_RENDER_USING_TEX_SHADER
// This piece of code renders mechs and vehicles using the gos_tex_vertex_lighted.vert shader. This is in addition to the same objectes being
// rendered by addTriangle above. This results in a sparkling effect as the 2 renders fight each other as the mechs rotate. This behaviour is
// quite evident with 5 mechs.

// FIXME: this (listOfTypeTriangles[0]) is not correct if model has more than 1 texture!
if (!isSpotlight && !isWindow && !theShape->listOfTextures[theShape->listOfTypeTriangles[0].localTextureHandle].textureAlpha && (alphaValue == 0xff))
{
Expand Down Expand Up @@ -2492,6 +2497,7 @@ long TG_Shape::MultiTransformShape (Stuff::Matrix4D *shapeToClip, Stuff::Point3D
mcTextureManager->addRenderShape(theShape->listOfTextures[theShape->listOfTypeTriangles[0].localTextureHandle].mcTextureNodeIndex, MC2_DRAWSOLID | addFlags);
}
}
#endif

gosASSERT(oneOff || oneOn);

Expand Down
2 changes: 1 addition & 1 deletion mclib/txmmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ void MC_TextureManager::addRenderShape(DWORD nodeId, TG_RenderShape* render_shap

masterTextureNodes[nodeId].hardwareVertexData2->currentShape = shapes;
}
else if (masterTextureNodes[nodeId].vertexData3 &&
else if (masterTextureNodes[nodeId].hardwareVertexData3 &&
masterTextureNodes[nodeId].vertexData3->flags == flags)
{
TG_RenderShape * shapes = masterTextureNodes[nodeId].hardwareVertexData3->currentShape;
Expand Down
Loading