Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Im-Rises committed Mar 13, 2024
1 parent 9e938f8 commit b01ee80
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
17 changes: 9 additions & 8 deletions Chip8topia/Chip8topia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ Chip8topia::Chip8topia() : m_window(nullptr) {
Chip8topia::~Chip8topia() = default;

auto Chip8topia::run() -> int {
if (init() != 0)
auto initErrorCode = init();
if (initErrorCode != 0)
{
return 1;
return initErrorCode;
}

auto lastTime = std::chrono::high_resolution_clock::now();
Expand Down Expand Up @@ -91,7 +92,7 @@ auto Chip8topia::run() -> int {

cleanup();

return 0;
return SUCCESS_CODE;
}

#ifndef __EMSCRIPTEN__
Expand All @@ -104,7 +105,7 @@ auto Chip8topia::init() -> int {
glfwSetErrorCallback(glfw_error_callback);
if (glfwInit() == 0)
{
return 1;
return GLFW_INIT_ERROR_CODE;
}

#if defined(__EMSCRIPTEN__)
Expand All @@ -129,7 +130,7 @@ auto Chip8topia::init() -> int {
m_window = glfwCreateWindow(m_currentWidth, m_currentHeight, PROJECT_NAME, nullptr, nullptr);
if (m_window == nullptr)
{
return 1;
return WINDOW_INIT_ERROR_CODE;
}
glfwMakeContextCurrent(m_window);
glfwSwapInterval(m_isTurboMode ? 0 : 1); // 0 = no vsync, 1 = vsync
Expand All @@ -147,7 +148,7 @@ auto Chip8topia::init() -> int {
if (gladLoadGLLoader(reinterpret_cast<GLADloadproc>(glfwGetProcAddress)) == 0)
{
spdlog::error("Failed to initialize OpenGL loader");
return 1;
return GLAD_INIT_ERROR_CODE;
}
#endif

Expand Down Expand Up @@ -191,7 +192,7 @@ auto Chip8topia::init() -> int {
#else
std::cerr << "Could not find font awesome file: " << FONT_ICON_FILE_NAME_FAS << '\n';
#endif
return 1;
return FONT_AWESOME_INIT_ERROR_CODE;
}

static const ImWchar iconsRanges[] = { ICON_MIN_FA, ICON_MAX_16_FA, 0 };
Expand Down Expand Up @@ -231,7 +232,7 @@ auto Chip8topia::init() -> int {
std::cout << "Chip8topia initialized successfully" << '\n';
#endif

return 0;
return SUCCESS_CODE;
}

void Chip8topia::cleanup() {
Expand Down
5 changes: 5 additions & 0 deletions Chip8topia/Chip8topia.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ It was made to allow video games to be more easily programmed for said computers

// static constexpr ImVec4 CLEAR_COLOR = ImVec4(0.45F, 0.55F, 0.60F, 1.00F);
private:
static constexpr auto SUCCESS_CODE = 0;
static constexpr auto GLFW_INIT_ERROR_CODE = 1;
static constexpr auto WINDOW_INIT_ERROR_CODE = 2;
static constexpr auto GLAD_INIT_ERROR_CODE = 3;
static constexpr auto FONT_AWESOME_INIT_ERROR_CODE = 4;
#if !defined(BUILD_RELEASE)
static constexpr auto DEBUG_ROM_PATH = "trash/8-scrolling.ch8";
#endif
Expand Down

0 comments on commit b01ee80

Please sign in to comment.