Initial commit
This commit is contained in:
commit
194b40d1ee
8
.clang-format
Normal file
8
.clang-format
Normal file
@ -0,0 +1,8 @@
|
||||
BasedOnStyle: Chromium
|
||||
IndentWidth: 4
|
||||
SortIncludes: false
|
||||
|
||||
Language: Cpp
|
||||
# Force pointers to the type for C++.
|
||||
DerivePointerAlignment: false
|
||||
PointerAlignment: Left
|
18
.clangd
Normal file
18
.clangd
Normal file
@ -0,0 +1,18 @@
|
||||
Diagnostics:
|
||||
ClangTidy:
|
||||
Add: [
|
||||
modernize*,
|
||||
bugprone*,
|
||||
performance*,
|
||||
readability*
|
||||
]
|
||||
Remove: [
|
||||
modernize-use-trailing-return-type,
|
||||
modernize-avoid-c-arrays,
|
||||
readability-magic-numbers,
|
||||
readability-implicit-bool-conversion,
|
||||
readability-identifier-length
|
||||
]
|
||||
|
||||
Completion:
|
||||
AllScopes: Yes
|
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
/build
|
||||
/.cache
|
||||
**/.DS_Store
|
16
.vscode/c_cpp_properties.json
vendored
Normal file
16
.vscode/c_cpp_properties.json
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Mac",
|
||||
"includePath": ["${workspaceFolder}/**", "/opt/homebrew/include"],
|
||||
"defines": [],
|
||||
"macFrameworkPath": [
|
||||
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
|
||||
],
|
||||
"compilerPath": "/usr/bin/clang",
|
||||
"cStandard": "c17",
|
||||
"cppStandard": "c++17"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
9
.vscode/extensions.json
vendored
Normal file
9
.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"recommendations": [
|
||||
"llvm-vs-code-extensions.vscode-clangd",
|
||||
"ms-vscode.cpptools-extension-pack",
|
||||
"vadimcn.vscode-lldb",
|
||||
"fabiospampinato.vscode-statusbar-debugger",
|
||||
"runarsf.platform-settings"
|
||||
]
|
||||
}
|
14
.vscode/launch.json
vendored
Normal file
14
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"name": "Homd Engine Debug",
|
||||
"preLaunchTask": "CMake: build",
|
||||
"program": "${workspaceFolder}/build/HomdEngine",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}/build"
|
||||
}
|
||||
]
|
||||
}
|
31
.vscode/settings.json
vendored
Normal file
31
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
{
|
||||
"C_Cpp.intelliSenseEngine": "disabled",
|
||||
"cmake.statusbar.advanced": {
|
||||
"debug": {
|
||||
"visibility": "hidden"
|
||||
},
|
||||
"buildTarget": {
|
||||
"visibility": "hidden"
|
||||
},
|
||||
"launchTarget": {
|
||||
"visibility": "hidden"
|
||||
},
|
||||
"kit": {
|
||||
"visibility": "hidden"
|
||||
}
|
||||
},
|
||||
"clangd.arguments": ["--compile-commands-dir=build"],
|
||||
"editor.formatOnSave": true,
|
||||
"platformSettings.autoLoad": true,
|
||||
"search.exclude": {
|
||||
"**/build": true
|
||||
},
|
||||
"platformSettings.platforms": {
|
||||
"win32": {
|
||||
"nodes": {
|
||||
"cmake.cmakePath": "C:\\msys64\\clang64\\bin\\cmake",
|
||||
"clangd.path": "C:\\msys64\\clang64\\bin\\clangd.exe"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
40
.vscode/tasks.json
vendored
Normal file
40
.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
{
|
||||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||
// for the documentation about the tasks.json format
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"type": "cmake",
|
||||
"label": "CMake: configure",
|
||||
"command": "configure",
|
||||
"problemMatcher": [],
|
||||
"detail": "CMake template configure task",
|
||||
"presentation": {
|
||||
"echo": true,
|
||||
"reveal": "always",
|
||||
"focus": false,
|
||||
"panel": "shared",
|
||||
"showReuseMessage": true,
|
||||
"clear": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "cmake",
|
||||
"label": "CMake: build",
|
||||
"command": "build",
|
||||
"targets": ["all"],
|
||||
"group": "build",
|
||||
"problemMatcher": [],
|
||||
"detail": "CMake template build task",
|
||||
"dependsOn": ["CMake: configure"],
|
||||
"presentation": {
|
||||
"echo": true,
|
||||
"reveal": "always",
|
||||
"focus": false,
|
||||
"panel": "shared",
|
||||
"showReuseMessage": true,
|
||||
"clear": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
127
CMakeLists.txt
Normal file
127
CMakeLists.txt
Normal file
@ -0,0 +1,127 @@
|
||||
# Copyright (c) 2023, Furkan Mudanyali <fmudanyali@icloud.com>
|
||||
# All rights reserved
|
||||
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
project(HomdEngine)
|
||||
|
||||
SET(CMAKE_CXX_STANDARD 17)
|
||||
SET(CMAKE_EXPORT_COMPILE_COMMANDS 1)
|
||||
# Change this if youre using other environments than MSYS2 CLANG64
|
||||
# or it is in a different path.
|
||||
SET(win_environment "C:/msys64/clang64")
|
||||
|
||||
# Set compiler to clang++
|
||||
IF(WIN32)
|
||||
SET(CMAKE_CXX_COMPILER "${win_environment}/bin/clang++")
|
||||
ELSE()
|
||||
SET(CMAKE_CXX_COMPILER "/usr/bin/clang++")
|
||||
ENDIF()
|
||||
|
||||
# Apple M1 does not support -march=native in clang version 14 and before.
|
||||
IF(APPLE AND CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64")
|
||||
SET(arch_flags "-mcpu=apple-m1 -mtune=native")
|
||||
ELSE()
|
||||
SET(arch_flags "-march=native -mtune=native")
|
||||
ENDIF()
|
||||
|
||||
# Whether to optimize or leave debugging information depending on
|
||||
# build type
|
||||
IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
SET(LINK_FLAGS "${debug_linker}")
|
||||
SET(optimize_flags "-Og -g3 -ffunction-sections -fdata-sections")
|
||||
ELSE()
|
||||
SET(optimize_flags "-O3 -ffast-math")
|
||||
ENDIF()
|
||||
|
||||
# Needed for ImGui under Windows, also have to rename main() to wmain()
|
||||
# in main.cpp
|
||||
IF(WIN32)
|
||||
SET(win_flags "-municode")
|
||||
ENDIF()
|
||||
|
||||
# Dead code stripping in the linker part
|
||||
SET(debug_linker "-Wl,-dead_strip")
|
||||
|
||||
# Enable all kinds of warnings and treat them as errors for a better code
|
||||
# Some warnings are disabled to prevent making changes on dependencies.
|
||||
SET(warn_flags "\
|
||||
-Wall\
|
||||
-fno-common\
|
||||
-Wextra\
|
||||
-Werror\
|
||||
-Wshadow\
|
||||
-Wformat=2\
|
||||
-Wundef\
|
||||
-Wno-unused-parameter\
|
||||
-Wno-sign-conversion\
|
||||
-Wno-conversion\
|
||||
-Wno-format-nonliteral\
|
||||
")
|
||||
|
||||
# Put all the flags we have gathered
|
||||
SET(CMAKE_CXX_FLAGS
|
||||
"${arch_flags} ${optimize_flags} ${warn_flags} ${win_flags}"
|
||||
)
|
||||
|
||||
# The main project files
|
||||
SET(SOURCE_FILES
|
||||
src/game/game.cpp
|
||||
|
||||
src/input/input.cpp
|
||||
|
||||
src/scene/scene.cpp
|
||||
|
||||
src/window/window.cpp
|
||||
|
||||
src/main.cpp
|
||||
)
|
||||
|
||||
# /SDL2 and /opencv4 are for using same imports
|
||||
# under all environments.
|
||||
IF(APPLE)
|
||||
SET(includes
|
||||
# M1 Mac with Homebrew
|
||||
"/opt/homebrew/include"
|
||||
# Intel Mac with Homebrew / Macports
|
||||
"/opt/local/include"
|
||||
)
|
||||
SET(links
|
||||
# M1 Mac with Homebrew
|
||||
"/opt/homebrew/lib"
|
||||
# Intel Mac with Homebrew / Macports
|
||||
"/opt/local/lib"
|
||||
)
|
||||
ENDIF()
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src"
|
||||
${includes}
|
||||
)
|
||||
|
||||
LINK_DIRECTORIES(
|
||||
${links}
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(HomdEngine
|
||||
${SOURCE_FILES}
|
||||
)
|
||||
|
||||
IF(WIN32)
|
||||
SET(win32_link -mwindows, -mconsole)
|
||||
ENDIF()
|
||||
|
||||
TARGET_LINK_LIBRARIES(HomdEngine
|
||||
sdl2
|
||||
${win32_link}
|
||||
)
|
||||
|
||||
# To profile the debug build of the application using Instruments
|
||||
# under macOS, we need to replace its signature to allow profiling.
|
||||
IF(APPLE AND CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
ADD_CUSTOM_COMMAND(
|
||||
TARGET GlandMiner POST_BUILD
|
||||
COMMAND /usr/bin/codesign -s -
|
||||
--entitlements ${CMAKE_SOURCE_DIR}/debug.entitlements
|
||||
-f ${CMAKE_CURRENT_BINARY_DIR}/HomdEngine
|
||||
)
|
||||
ENDIF()
|
8
debug.entitlements
Normal file
8
debug.entitlements
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.security.get-task-allow</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
26
src/game/game.cpp
Normal file
26
src/game/game.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright (c) 2023, Furkan Mudanyali <fmudanyali@icloud.com>
|
||||
* All rights reserved
|
||||
*/
|
||||
|
||||
#include <game/game.h>
|
||||
#include <scene/scene.h>
|
||||
|
||||
Game::Game() {
|
||||
this->pWindow = new Window(this);
|
||||
this->pInput = new Input(this);
|
||||
this->scenes.push(new Scene);
|
||||
}
|
||||
|
||||
void Game::loop() {
|
||||
while (!this->done && !this->scenes.empty()) {
|
||||
this->pWindow->updateDimensions();
|
||||
this->done = this->pInput->pollEvent();
|
||||
|
||||
if (this->scenes.top()->destroy) {
|
||||
delete this->scenes.top();
|
||||
this->scenes.pop();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
29
src/game/game.h
Normal file
29
src/game/game.h
Normal file
@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Copyright (c) 2023, Furkan Mudanyali <fmudanyali@icloud.com>
|
||||
* All rights reserved
|
||||
*/
|
||||
|
||||
#ifndef _HOMD_GAME
|
||||
#define _HOMD_GAME
|
||||
|
||||
#include <window/window.h>
|
||||
#include <input/input.h>
|
||||
#include <stack>
|
||||
|
||||
class Scene;
|
||||
|
||||
class Game {
|
||||
bool done = false;
|
||||
std::stack<Scene*> scenes;
|
||||
|
||||
public:
|
||||
Window* pWindow;
|
||||
Input* pInput;
|
||||
|
||||
Game();
|
||||
~Game() = default;
|
||||
|
||||
void loop();
|
||||
};
|
||||
|
||||
#endif
|
24
src/input/input.cpp
Normal file
24
src/input/input.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Copyright (c) 2023, Furkan Mudanyali <fmudanyali@icloud.com>
|
||||
* All rights reserved
|
||||
*/
|
||||
|
||||
#include <input/input.h>
|
||||
#include <game/game.h>
|
||||
|
||||
Input::Input(Game* pGame) {
|
||||
this->game = pGame;
|
||||
}
|
||||
|
||||
bool Input::pollEvent() {
|
||||
while (SDL_PollEvent(&this->event)) {
|
||||
switch (event.type) {
|
||||
case SDL_QUIT:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return event.type == SDL_WINDOWEVENT &&
|
||||
event.window.event == SDL_WINDOWEVENT_CLOSE &&
|
||||
event.window.windowID ==
|
||||
SDL_GetWindowID(this->game->pWindow->window);
|
||||
}
|
24
src/input/input.h
Normal file
24
src/input/input.h
Normal file
@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Copyright (c) 2023, Furkan Mudanyali <fmudanyali@icloud.com>
|
||||
* All rights reserved
|
||||
*/
|
||||
|
||||
#ifndef _HOMD_INPUT
|
||||
#define _HOMD_INPUT
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_events.h>
|
||||
|
||||
class Game;
|
||||
|
||||
class Input {
|
||||
Game* game = nullptr;
|
||||
SDL_Event event;
|
||||
|
||||
public:
|
||||
Input(Game*);
|
||||
~Input() = default;
|
||||
bool pollEvent();
|
||||
};
|
||||
|
||||
#endif
|
16
src/main.cpp
Normal file
16
src/main.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Copyright (c) 2023, Furkan Mudanyali <fmudanyali@icloud.com>
|
||||
* All rights reserved
|
||||
*/
|
||||
|
||||
#include <game/game.h>
|
||||
|
||||
#ifdef __WIN32
|
||||
int wmain(int argc, char** argv) {
|
||||
#else
|
||||
int main(int argc, char** argv) {
|
||||
#endif
|
||||
auto* game = new Game;
|
||||
game->loop();
|
||||
return 0;
|
||||
}
|
6
src/scene/scene.cpp
Normal file
6
src/scene/scene.cpp
Normal file
@ -0,0 +1,6 @@
|
||||
/**
|
||||
* Copyright (c) 2023, Furkan Mudanyali <fmudanyali@icloud.com>
|
||||
* All rights reserved
|
||||
*/
|
||||
|
||||
#include <scene/scene.h>
|
16
src/scene/scene.h
Normal file
16
src/scene/scene.h
Normal file
@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Copyright (c) 2023, Furkan Mudanyali <fmudanyali@icloud.com>
|
||||
* All rights reserved
|
||||
*/
|
||||
|
||||
#ifndef _HOMD_SCENE
|
||||
#define _HOMD_SCENE
|
||||
|
||||
class Scene {
|
||||
public:
|
||||
bool destroy = false;
|
||||
Scene() = default;
|
||||
~Scene() = default;
|
||||
};
|
||||
|
||||
#endif
|
34
src/window/window.cpp
Normal file
34
src/window/window.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Copyright (c) 2023, Furkan Mudanyali <fmudanyali@icloud.com>
|
||||
* All rights reserved
|
||||
*/
|
||||
|
||||
#include <window/window.h>
|
||||
|
||||
Window::Window(Game* pGame) {
|
||||
this->game = pGame;
|
||||
if (SDL_Init(SDL_FLAGS) != 0) {
|
||||
throw SDL_GetError();
|
||||
}
|
||||
|
||||
this->window = SDL_CreateWindow(WINDOW_TITLE, SDL_WINDOWPOS_CENTERED,
|
||||
SDL_WINDOWPOS_CENTERED, WINDOW_INITIAL_W,
|
||||
WINDOW_INITIAL_H, SDL_WINDOW_FLAGS);
|
||||
}
|
||||
|
||||
Window::~Window() {
|
||||
SDL_DestroyWindow(this->window);
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
void Window::updateDimensions() {
|
||||
SDL_GL_GetDrawableSize(this->window, &this->width, &this->height);
|
||||
}
|
||||
|
||||
int Window::getWidth() const {
|
||||
return this->width;
|
||||
}
|
||||
|
||||
int Window::getHeight() const {
|
||||
return this->height;
|
||||
}
|
37
src/window/window.h
Normal file
37
src/window/window.h
Normal file
@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright (c) 2023, Furkan Mudanyali <fmudanyali@icloud.com>
|
||||
* All rights reserved
|
||||
*/
|
||||
|
||||
#ifndef _HOMD_WINDOW
|
||||
#define _HOMD_WINDOW
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_video.h>
|
||||
|
||||
#define SDL_FLAGS SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER
|
||||
#define SDL_WINDOW_FLAGS \
|
||||
SDL_WINDOW_OPENGL | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_MAXIMIZED
|
||||
|
||||
#define WINDOW_TITLE "Homd Engine"
|
||||
#define WINDOW_INITIAL_W 960
|
||||
#define WINDOW_INITIAL_H 540
|
||||
|
||||
class Game;
|
||||
|
||||
class Window {
|
||||
Game* game;
|
||||
int width;
|
||||
int height;
|
||||
|
||||
public:
|
||||
SDL_Window* window;
|
||||
|
||||
Window(Game*);
|
||||
~Window();
|
||||
void updateDimensions();
|
||||
[[nodiscard]] int getWidth() const;
|
||||
[[nodiscard]] int getHeight() const;
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user