Skip to content

Commit

Permalink
Initial port
Browse files Browse the repository at this point in the history
  • Loading branch information
lousyphreak committed Aug 2, 2024
1 parent 3aa051c commit 44687ce
Show file tree
Hide file tree
Showing 75 changed files with 15,763 additions and 58 deletions.
137 changes: 111 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
cmake_minimum_required(VERSION 3.11 FATAL_ERROR)

# Print a message that using the Makefiles is recommended.
message(NOTICE: " The CMakeLists.txt is unmaintained. Use the Makefile if possible.")
Expand Down Expand Up @@ -46,6 +46,7 @@ else() # GCC/clang/mingw
# -fwrapv -> Make signed integer overflows defined
# -fvisibility=hidden -> Force defaultsymbol visibility to hidden
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fno-strict-aliasing -fwrapv -fvisibility=hidden")
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__FLOAT_HACK__")

# Use -O2 as maximum optimization level. -O3 has it's problems with yquake2.
string(REPLACE "-O3" "-O2" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
Expand Down Expand Up @@ -189,11 +190,15 @@ 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(${CMAKE_SYSTEM_NAME} MATCHES "CafeOS")
add_definitions(-D__DISABLE_IPV6__)
else()
# 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 @@ -238,30 +243,32 @@ if(${OPENAL_SUPPORT})
endif()
endif()

# General linker flags.
if(NOT MSVC)
list(APPEND yquake2LinkerFlags m)
endif()
list(APPEND yquake2LinkerFlags ${CMAKE_DL_LIBS})

if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
if(!MSVC)
list(APPEND yquake2LinkerFlags "-static-libgcc")
if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "CafeOS")
# General linker flags.
if(NOT MSVC)
list(APPEND yquake2LinkerFlags m)
endif()
else()
if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Haiku")
list(APPEND yquake2LinkerFlags "-rdynamic")
list(APPEND yquake2LinkerFlags ${CMAKE_DL_LIBS})

if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
if(!MSVC)
list(APPEND yquake2LinkerFlags "-static-libgcc")
endif()
else()
list(APPEND yquake2LinkerFlags "-lnetwork")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
list(APPEND yquake2LinkerFlags "-lsocket -lnsl")
if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Haiku")
list(APPEND yquake2LinkerFlags "-rdynamic")
else()
list(APPEND yquake2LinkerFlags "-lnetwork")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
list(APPEND yquake2LinkerFlags "-lsocket -lnsl")
endif()
endif()
endif()

if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD" AND NOT WIN32)
list(APPEND yquake2LinkerFlags "-Wl,--no-undefined")
if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD" AND NOT WIN32)
list(APPEND yquake2LinkerFlags "-Wl,--no-undefined")
endif()
endif()

# With all of those libraries and user defined paths
Expand Down Expand Up @@ -311,6 +318,13 @@ set(Backends-Windows-Source
${BACKENDS_SRC_DIR}/windows/shared/hunk.c
)

set(Backends-WiiU-Source
${BACKENDS_SRC_DIR}/wiiu/main.c
${BACKENDS_SRC_DIR}/wiiu/network.c
${BACKENDS_SRC_DIR}/wiiu/system.c
${BACKENDS_SRC_DIR}/wiiu/shared/hunk.c
)

set(Backends-Windows-Header
${BACKENDS_SRC_DIR}/windows/header/resource.h
)
Expand All @@ -323,10 +337,17 @@ set(REF-Unix-Source
${BACKENDS_SRC_DIR}/unix/shared/hunk.c
)

set(REF-WiiU-Source
${BACKENDS_SRC_DIR}/wiiu/shared/hunk.c
)

# Set the nessesary platform specific source
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(Platform-Specific-Source ${Backends-Windows-Source} ${Backends-Windows-Header})
set(REF-Platform-Specific-Source ${REF-Windows-Source})
elseif(${CMAKE_SYSTEM_NAME} MATCHES "CafeOS")
set(Platform-Specific-Source ${Backends-WiiU-Source})
set(REF-Platform-Specific-Source ${REF-WiiU-Source})
else()
set(Platform-Specific-Source ${Backends-Unix-Source})
set(REF-Platform-Specific-Source ${REF-Unix-Source})
Expand Down Expand Up @@ -700,6 +721,33 @@ set(SOFT-Header
${COMMON_SRC_DIR}/header/shared.h
)


set(WiiU-Source
${REF_SRC_DIR}/wiiu/wiiu_draw.c
${REF_SRC_DIR}/wiiu/wiiu_dynbuffers.c
${REF_SRC_DIR}/wiiu/wiiu_framebuffer.c
${REF_SRC_DIR}/wiiu/wiiu_image.c
${REF_SRC_DIR}/wiiu/wiiu_light.c
${REF_SRC_DIR}/wiiu/wiiu_lightmap.c
${REF_SRC_DIR}/wiiu/wiiu_main.c
${REF_SRC_DIR}/wiiu/wiiu_mesh.c
${REF_SRC_DIR}/wiiu/wiiu_misc.c
${REF_SRC_DIR}/wiiu/wiiu_model.c
${REF_SRC_DIR}/wiiu/wiiu_sdl.c
${REF_SRC_DIR}/wiiu/wiiu_state.c
${REF_SRC_DIR}/wiiu/wiiu_surf.c
${REF_SRC_DIR}/wiiu/wiiu_warp.c
${REF_SRC_DIR}/wiiu/wiiu_shaders.c
${REF_SRC_DIR}/files/models.c
${REF_SRC_DIR}/files/pcx.c
${REF_SRC_DIR}/files/stb.c
${REF_SRC_DIR}/files/surf.c
${REF_SRC_DIR}/files/wal.c
${REF_SRC_DIR}/files/pvs.c
${COMMON_SRC_DIR}/shared/shared.c
${COMMON_SRC_DIR}/md4.c
)

# Main Quake 2 executable

if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
Expand Down Expand Up @@ -727,6 +775,23 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
)
add_executable(quake2 WIN32 ${Wrapper-Source})
set_target_properties(quake2 PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/release)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "CafeOS")
add_executable(quake2 ${Client-Source} ${Client-SDL-Source} ${Client-Header}
${Platform-Specific-Source} ${Backends-Generic-Source} ${WiiU-Source} ${Game-Source} ${Game-Header})
set_target_properties(quake2 PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/release
)
target_link_libraries(quake2 ${yquake2LinkerFlags} ${yquake2ClientLinkerFlags}
${yquake2SDLLinkerFlags} ${yquake2ZLibLinkerFlags} ${SDL2_LIBRARIES})
if(SDL3_SUPPORT)
target_link_libraries(quake2 SDL3::SDL3)
endif()

include("src/client/refresh/wiiu/shader_compile.cmake")

if(${CMAKE_SYSTEM_NAME} MATCHES "CafeOS")
wut_create_rpx(quake2)
endif()
else()
add_executable(quake2 ${Client-Source} ${Client-SDL-Source} ${Client-Header}
${Platform-Specific-Source} ${Backends-Generic-Source})
Expand All @@ -740,6 +805,26 @@ else()
endif()
endif()

if(${CMAKE_SYSTEM_NAME} MATCHES "CafeOS")
# # Build the GL3 dynamic library
# add_executable(ref_wiiu ${WiiU-Source} ${REF-Platform-Specific-Source})
# set_target_properties(ref_wiiu PROPERTIES
# PREFIX ""
# LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/release
# RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/release
# SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX}
# )
# target_include_directories(ref_wiiu PRIVATE ${CMAKE_SOURCE_DIR}/src/client/refresh/gl3/glad/include)
# target_link_libraries(ref_wiiu ${yquake2LinkerFlags} ${yquake2SDLLinkerFlags})
# if(SDL3_SUPPORT)
# target_link_libraries(ref_wiiu SDL3::SDL3)
# endif()
# wut_create_rpl(ref_wiiu)

# No support for all the rest of the binaries so we exit here
return()
endif()

# Quake 2 Dedicated Server
add_executable(q2ded ${Server-Source} ${Server-Header} ${Platform-Specific-Source}
${Backends-Generic-Source})
Expand Down
125 changes: 105 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,111 @@
# Yamagi Quake II
# wiiuQuake2

Yamagi Quake II is an enhanced client for id Software's Quake
II with focus on offline and coop gameplay. Both the gameplay and the graphics
are unchanged, but many bugs in the last official release were fixed and some
nice to have features like widescreen support and a modern OpenGL 3.2 renderer
were added. Unlike most other Quake II source ports Yamagi Quake II is fully 64-bit
clean. It works perfectly on modern processors and operating systems. Yamagi
Quake II runs on nearly all common platforms; including FreeBSD, Linux, NetBSD,
OpenBSD, Windows and macOS (experimental).
This port is based on yquake2, and the gl3 renderer. It runs the main game stable
(startup demo loop for hours), allows switching mods (ONLY during the intro video).
Currently it only runs at ~20fps (rarely hitting 30) during the demo loop on the
console, and 60fps on Cemu with the CPU interpreter.

This code is built upon Icculus Quake II, which itself is based on Quake II
3.21. Yamagi Quake II is released under the terms of the GPL version 2. See the
LICENSE file for further information.
Built with 100% open source tools, tested with Cemu and on real hardware.

## Documentation
## Installing

Before asking any question, read through the documentation! The current
version can be found here: [doc/010_index.md](doc/010_index.md)
Install the Quake 2 data files to your sdcard "quake2" folder, and the wuhb to "wiiu/apps":

## Releases
```
sdcard
| - quake2
| | - baseq2
| | | - pak0.pak
| | | - <other files>
| | - rogue (optional)
| | | - pak0.pak
| | | - <other files>
| | - xatrix (optional)
| | | - pak0.pak
| | | - <other files>
| - wiiu
| - apps
| - quake2.wuhb
```

The official releases (including Windows binaries) can be found at our
homepage: https://www.yamagi.org/quake2
**Unsupported** preview builds for Windows can be found at
https://deponie.yamagi.org/quake2/misc/
## Building

You need:

- [devkitPro wiiu toolchain](https://github.com/devkitPro/wut)
- (optional, for music playback) ogg libraries for PPC (from the devkiPro pacman)
- [CafeGLSL](https://github.com/Exzap/CafeGLSL) with [PR #3](https://github.com/Exzap/CafeGLSL/pull/3)
or directly from the [fork](https://github.com/Crementif/CafeGLSL/tree/main)
to build the offline GLSL compiler, and installed to `${DEVKITPRO}/tools/bin/glslcompiler.elf`

```sh
mkdir build
cd build
${DEVKITPRO}/portlibs/wiiu/bin/powerpc-eabi-cmake -DCMAKE_BUILD_TYPE=Release ..
make

# package to wuhb format (not yet integrated to the cmake file)
rm -rf content && \
mkdir content && \
mkdir content/shaders && \
cp *.gsh content/shaders/ && \
${DEVKITPRO}/tools/bin/wuhbtool quake2.rpx quake2.wuhb \
--name="Yamagi Quake 2" \
--short-name=YQuake2 \
--content=content \
--icon=../stuff/wiiu/image-icon.png \
--tv-image=../stuff/wiiu/image-tv.png \
--drc-image=../stuff/wiiu/image-drc.png
```

The resulting `quake2.wuhb` can be installed on the sd-card for use in the WiiU, or launched directly by Cemu.
The only other data required is the quake2 data files on the sd-card.

## Bugs

- Switching mods crashes game once a game has been loaded
You can switch while the initial video is played and the demo levels have not yet been loaded

### Cemu Bug

There is a bug in the Cemu PPC recompiler (i think), that causes endian conversion for floats
to fail, if you run into this you can compile with a define `__FLOAT_HACK__` (see in CMakeLists.txt),
or run Cemu with `--force-interpreter`. This also does not affect real hardware.

(Yes, i am preparing a bug report with a minimal repro)

## Added CVars

- **r_lightmaps_unfiltered, r_3D_unfiltered**

similar to r_videos_unfiltered and r_2D_unfiltered, but applied to lightmaps and all 3d content

- **wiiu_debugmips**

replace all textures with a color representing their mip level. can only be set (reliably) before
startup because it does not reload textures

- **wiiu_drc**

copy TV image to DRC (make game playable on WiiU gamepad), has small performance hit

## TODO

- exiting from ingame, exit via HOME button or console shutdown works
- FBO (post effects), has partial implementation
- multisampling, requires reimplementation of WUT gfx implementation
- stencil & scissor (shadows?), requires reimplementation of WUT gfx implementation
- some clear color stuff glClearColor
- round particles, gl_PointCoord always zero, might be some broken state

## (maybe interesting?) things for WiiU devs

Some things in here that i have not yet seen in any other demo, so feel free to "steal".

- Mip-Mapped textures (src/client/refresh/wiiu/gl3_image.c in WiiU_Upload32)

the generation of them is meh, but getting the offsets right was a pain (Cemu + dumping was a great help)

- Copy rendered screen from TV to DRC (src/client/refresh/wiiu/gl3_sdl.c in WiiU_EndFrame)

using a VERY simple shader for downsampling (even with hardcoded resolution)
26 changes: 26 additions & 0 deletions README.yquake2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Yamagi Quake II

Yamagi Quake II is an enhanced client for id Software's Quake
II with focus on offline and coop gameplay. Both the gameplay and the graphics
are unchanged, but many bugs in the last official release were fixed and some
nice to have features like widescreen support and a modern OpenGL 3.2 renderer
were added. Unlike most other Quake II source ports Yamagi Quake II is fully 64-bit
clean. It works perfectly on modern processors and operating systems. Yamagi
Quake II runs on nearly all common platforms; including FreeBSD, Linux, NetBSD,
OpenBSD, Windows and macOS (experimental).

This code is built upon Icculus Quake II, which itself is based on Quake II
3.21. Yamagi Quake II is released under the terms of the GPL version 2. See the
LICENSE file for further information.

## Documentation

Before asking any question, read through the documentation! The current
version can be found here: [doc/010_index.md](doc/010_index.md)

## Releases

The official releases (including Windows binaries) can be found at our
homepage: https://www.yamagi.org/quake2
**Unsupported** preview builds for Windows can be found at
https://deponie.yamagi.org/quake2/misc/
2 changes: 2 additions & 0 deletions src/backends/generic/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ static void SetExecutablePath(char* exePath)
exePath[0] = '\0';
}

#elif defined(__WIIU__)
snprintf(exePath, PATH_MAX, "/vol/external01/quake2");
#else

// Several platforms (for example OpenBSD) donn't provide a
Expand Down
Loading

0 comments on commit 44687ce

Please sign in to comment.