Skip to content

Commit

Permalink
Merge pull request #31 from Im-Rises/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Im-Rises authored Apr 12, 2024
2 parents 13ff6e3 + 7749baf commit 5af0c81
Show file tree
Hide file tree
Showing 22 changed files with 364 additions and 299 deletions.
17 changes: 10 additions & 7 deletions .github/workflows/cmake-vcpkg-emscripten-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,20 @@ jobs:
- name: Create build directory
run: mkdir build

- name: Configure CMake
run: emcmake cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=${EMSDK}/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DVCPKG_TARGET_TRIPLET=wasm32-emscripten "-DCMAKE_EXE_LINKER_FLAGS=-s USE_GLFW=3 -s FULL_ES3=1 -s WASM=1 -s EXPORTED_RUNTIME_METHODS=[ccall] -s ALLOW_MEMORY_GROWTH=1 -s EXPORTED_FUNCTIONS=[_main,_malloc,_free] --preload-file ../../Chip8Games --preload-file ../../shaders --preload-file ../../fonts" -DCMAKE_BUILD_TYPE=Release
# - name: Configure CMake
# run: emcmake cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=${EMSDK}/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DVCPKG_TARGET_TRIPLET=wasm32-emscripten "-DCMAKE_EXE_LINKER_FLAGS=-s USE_GLFW=3 -s FULL_ES3=1 -s WASM=1 -s EXPORTED_RUNTIME_METHODS=[ccall] -s ALLOW_MEMORY_GROWTH=1 -s EXPORTED_FUNCTIONS=[_main,_malloc,_free] --preload-file ../../Chip8Games --preload-file ../../shaders --preload-file ../../fonts" -DCMAKE_BUILD_TYPE=Release
#
# - name: Build
# run: emmake make -C build

- name: Build
run: emmake make -C build
- name: Configure and build with CMake
run: ./build-wasm.sh buildWasm

- name: Copy artefacts to web folder
run: |
cp build/Chip8topia/Chip8topia.js web/
cp build/Chip8topia/Chip8topia.wasm web/
cp build/Chip8topia/Chip8topia.data web/
cp buildWasm/Chip8topia/Chip8topia.js web/
cp buildWasm/Chip8topia/Chip8topia.wasm web/
cp buildWasm/Chip8topia/Chip8topia.data web/
- name: Setup Pages
uses: actions/configure-pages@v3
Expand Down
13 changes: 8 additions & 5 deletions .github/workflows/cmake-vcpkg-emscripten.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ jobs:
- name: Create build directory
run: mkdir build

- name: Configure CMake
run: emcmake cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=${EMSDK}/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DVCPKG_TARGET_TRIPLET=wasm32-emscripten "-DCMAKE_EXE_LINKER_FLAGS=-s USE_GLFW=3 -s FULL_ES3=1 -s WASM=1 -s EXPORTED_RUNTIME_METHODS=[ccall] -s ALLOW_MEMORY_GROWTH=1 -s EXPORTED_FUNCTIONS=[_main,_malloc,_free] --preload-file ../../Chip8Games --preload-file ../../shaders --preload-file ../../fonts" -DCMAKE_BUILD_TYPE=Release

- name: Build
run: emmake make -C build
# - name: Configure CMake
# run: emcmake cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=${EMSDK}/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DVCPKG_TARGET_TRIPLET=wasm32-emscripten "-DCMAKE_EXE_LINKER_FLAGS=-s USE_GLFW=3 -s FULL_ES3=1 -s WASM=1 -s EXPORTED_RUNTIME_METHODS=[ccall] -s ALLOW_MEMORY_GROWTH=1 -s EXPORTED_FUNCTIONS=[_main,_malloc,_free] --preload-file ../../Chip8Games --preload-file ../../shaders --preload-file ../../fonts" -DCMAKE_BUILD_TYPE=Release
#
# - name: Build
# run: emmake make -C build

- name: Configure and build with CMake
run: ./build-wasm.sh buildWasm
2 changes: 1 addition & 1 deletion .github/workflows/cmake-vcpkg-publish-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ jobs:
if: matrix.os == 'windows-latest'
run: |
cp -r ${{ steps.strings.outputs.build-output-dir }}/${{ matrix.executable_name }}/${{ matrix.build_type }}/${{ matrix.executable_name }}${{ matrix.executable_extension }} ${{ github.workspace }}/${{ matrix.executable_name }}-${{ matrix.platform_name }}-v${{ env.APP_VERSION }}
cp -r ${{ steps.strings.outputs.build-output-dir }}/${{ matrix.executable_name }}/${{ matrix.build_type }}/glfw3.dll ${{ github.workspace }}/${{ matrix.executable_name }}-${{ matrix.platform_name }}-v${{ env.APP_VERSION }}
cp -r ${{ steps.strings.outputs.build-output-dir }}/${{ matrix.executable_name }}/${{ matrix.build_type }}/SDL2.dll ${{ github.workspace }}/${{ matrix.executable_name }}-${{ matrix.platform_name }}-v${{ env.APP_VERSION }}
cp -r ${{ steps.strings.outputs.build-output-dir }}/${{ matrix.executable_name }}/${{ matrix.build_type }}/fmt.dll ${{ github.workspace }}/${{ matrix.executable_name }}-${{ matrix.platform_name }}-v${{ env.APP_VERSION }}
- name: Zip artifacts (ubuntu, macos)
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(CHIP8TOPIA_VERSION "2.0.0")
set(CHIP8TOPIA_VERSION "2.0.1")

project("Chip8topia" VERSION ${CHIP8TOPIA_VERSION})
add_subdirectory(${PROJECT_NAME})
Expand Down
27 changes: 15 additions & 12 deletions Chip8topia/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/u
set_target_properties(${PROJECT_NAME} PROPERTIES WIN32_EXECUTABLE $<CONFIG:Release>)

if (NOT EMSCRIPTEN)
find_package(glfw3 CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE glfw)
find_package(sdl2 CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE SDL2::SDL2 SDL2::SDL2main)

find_package(glad CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE glad::glad)
Expand All @@ -39,12 +39,11 @@ if (NOT EMSCRIPTEN)
target_link_libraries(${PROJECT_NAME} PRIVATE ${STB_LIBRARIES})

if (WIN32)
target_link_libraries(${PROJECT_NAME} PUBLIC winmm.lib) # For timer precision (timeBeginPeriod)
target_link_libraries(${PROJECT_NAME} PUBLIC Pdh.lib) # For RAM usage
target_link_libraries(${PROJECT_NAME} PUBLIC psapi.lib) # For CPU usage
endif ()
else ()
target_link_libraries(${PROJECT_NAME} PRIVATE glfw)
target_link_libraries(${PROJECT_NAME} PRIVATE SDL2::SDL2 SDL2::SDL2main)
endif ()

find_package(imgui CONFIG REQUIRED)
Expand All @@ -64,7 +63,7 @@ else ()
target_compile_definitions(${PROJECT_NAME} PRIVATE BUILD_RELEASE)
endif ()

if (TRUE)
if (FALSE)
target_compile_definitions(${PROJECT_NAME} PRIVATE BUILD_PARAM_SAFE)
message("Building with safe parameter")
else ()
Expand All @@ -73,19 +72,23 @@ else ()
endif ()

if (WIN32)
set(PLATFORM_NAME "Windows")
target_compile_definitions(${PROJECT_NAME} PRIVATE PLATFORM_WINDOWS)
target_compile_definitions(${PROJECT_NAME} PRIVATE PLATFORM_NAME="Windows")
target_compile_definitions(${PROJECT_NAME} PRIVATE PLATFORM_NAME="${PLATFORM_NAME}")
elseif (UNIX AND NOT APPLE)
set(PLATFORM_NAME "Linux")
target_compile_definitions(${PROJECT_NAME} PRIVATE PLATFORM_LINUX)
target_compile_definitions(${PROJECT_NAME} PRIVATE PLATFORM_NAME="Linux")
target_compile_definitions(${PROJECT_NAME} PRIVATE PLATFORM_NAME="${PLATFORM_NAME}")
elseif (APPLE)
set(PLATFORM_NAME "MacOS")
target_compile_definitions(${PROJECT_NAME} PRIVATE PLATFORM_MACOS)
target_compile_definitions(${PROJECT_NAME} PRIVATE PLATFORM_NAME="MacOS")
#elseif (EMSCRIPTEN) # Use linux when building for web with emscripten
# target_compile_definitions(${PROJECT_NAME} PRIVATE PLATFORM_WEB)
# target_compile_definitions(${PROJECT_NAME} PRIVATE PLATFORM_NAME="Web")
target_compile_definitions(${PROJECT_NAME} PRIVATE PLATFORM_NAME="${PLATFORM_NAME}")
#elseif (EMSCRIPTEN) # Use linux when building for web with emscripten
# set(PLATFORM_NAME "Web")
# target_compile_definitions(${PROJECT_NAME} PRIVATE PLATFORM_WEB)
# target_compile_definitions(${PROJECT_NAME} PRIVATE PLATFORM_NAME="${PLATFORM_NAME}")
endif ()

target_compile_definitions(${PROJECT_NAME} PRIVATE PROJECT_CPP_VERSION="${CMAKE_CXX_STANDARD}")

message("Building ${PROJECT_NAME} for ${PLATFORM_NAME} with C++${CMAKE_CXX_STANDARD} on ${CMAKE_SYSTEM_NAME}")
message("Building ${PROJECT_NAME} for ${PLATFORM_NAME} with C++${CMAKE_CXX_STANDARD} on ${CMAKE_SYSTEM_NAME}")
4 changes: 2 additions & 2 deletions Chip8topia/Chip8Emulator/Chip8CoreBase/Chip8CoreBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ enum class Chip8Frequency : uint32
Freq24000000Hz = 24000000 // 24MHz for Alien-Inv8sion
};

// TODO: make clock private and call it in a non virtual function with a try catch block for safety
// Replace all call to input handler in cpu etc... to a throw exception
// TODO: make clock private and call it in a non public virtual function ClockCore which will call the cock method in a try catch block for safety.
// This way we will remove the dependency to the InputHandler in the Cpu and throw error.

// class CpuBase;
class Input;
Expand Down
8 changes: 4 additions & 4 deletions Chip8topia/Chip8Emulator/Chip8Emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Chip8Emulator::Chip8Emulator() : m_breakpoints{},
#else
m_core(std::make_unique<XoChipCore>(DEFAULT_FREQUENCY)),
#endif
m_accumulator(0.0F),
// m_accumulator(0.0F),
m_isRomLoaded(false),
// m_isTurboMode(false),
m_isBreak(false),
Expand Down Expand Up @@ -73,7 +73,7 @@ void Chip8Emulator::restart()
{
m_core->reset();
m_videoEmulation.reset();
m_accumulator = 0.0F;
// m_accumulator = 0.0F;
m_errorTriggered = false;
}

Expand Down Expand Up @@ -102,11 +102,11 @@ void Chip8Emulator::update(const float deltaTime)
}
else
{
m_accumulator += deltaTime;
// m_accumulator += deltaTime;

// if (m_isTurboMode || m_accumulator >= 1.0F / Chip8Core::SCREEN_AND_TIMERS_FREQUENCY)
// {
m_accumulator = 0.0F;
// m_accumulator = 0.0F;
bool screenUpdated = false;
while (!screenUpdated && !m_isBreak && !m_errorTriggered)
{
Expand Down
2 changes: 1 addition & 1 deletion Chip8topia/Chip8Emulator/Chip8Emulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Chip8Emulator
Chip8VideoEmulation m_videoEmulation;
// Chip8SoundEmulation m_soundEmulation;

float m_accumulator;
// float m_accumulator;
bool m_isRomLoaded;
// bool m_isTurboMode;
bool m_isBreak;
Expand Down
20 changes: 19 additions & 1 deletion Chip8topia/Chip8Emulator/Chip8Emulator/Chip8SoundEmulation.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
#include "Chip8SoundEmulation.h"

void Chip8SoundEmulation::update(const float deltaTime) {
#include <sdl.h>
#include "../Chip8CoreBase/Chip8CoreBase.h"

void Chip8SoundEmulation::update(Chip8CoreBase* chip8Core)
{
// // get ST
// const auto st = chip8Core->getCpu()->getST();
//
// // if ST > 0, play sound
// if (st > 0)
// {
// // play sound
// SDL_PauseAudio(0);
// }
// else
// {
// // pause sound
// SDL_PauseAudio(1);
// }
}
8 changes: 4 additions & 4 deletions Chip8topia/Chip8Emulator/Chip8Emulator/Chip8SoundEmulation.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

// Handle webaudio and openal sound drawing

class Chip8SoundEmulation {
class Chip8CoreBase;
class Chip8SoundEmulation
{
public:
void update(const float deltaTime);
void update(Chip8CoreBase* chip8Core);
};
Loading

0 comments on commit 5af0c81

Please sign in to comment.