Create the main window

This commit is contained in:
JackCarterSmith 2024-09-14 16:28:15 +02:00
parent 09f1e8a7ed
commit ed206fb71d
Signed by: JackCarterSmith
GPG Key ID: 832E52F4E23F8F24
7 changed files with 149 additions and 39 deletions

8
.gitignore vendored
View File

@ -46,12 +46,7 @@ CTestTestfile.cmake
_deps _deps
# ---> VisualStudioCode # ---> VisualStudioCode
.vscode/* .vscode/
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets
.cmake/ .cmake/
.vsconan/ .vsconan/
@ -61,5 +56,6 @@ _deps
# Built Visual Studio Code Extensions # Built Visual Studio Code Extensions
*.vsix *.vsix
bin/
build/ build/
CMakeUserPresets.json CMakeUserPresets.json

View File

@ -6,6 +6,19 @@
cmake_minimum_required(VERSION 3.23) cmake_minimum_required(VERSION 3.23)
cmake_policy(VERSION 3.23) cmake_policy(VERSION 3.23)
if(NOT DEFINED PROJECT_BINARY_DIR)
set(PROJECT_BINARY_DIR ".")
endif()
if(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Wall")
endif()
set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
# define project # define project
project(ProtoTank VERSION 0.1.0 DESCRIPTION "Arcade 80s-style game with tanks" LANGUAGES C;CXX) project(ProtoTank VERSION 0.1.0 DESCRIPTION "Arcade 80s-style game with tanks" LANGUAGES C;CXX)
#configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/config.h @ONLY) #configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/config.h @ONLY)
@ -24,6 +37,7 @@ include(srcs.list)
# targets declarations # targets declarations
add_executable(${PROJECT_NAME} ${MAIN_SCRS} ${UTILS_SCRS} ${MISC_SCRS} ${GAME_SCRS} ${GRAPHS_SCRS} ${SOUNDS_SCRS}) add_executable(${PROJECT_NAME} ${MAIN_SCRS} ${UTILS_SCRS} ${MISC_SCRS} ${GAME_SCRS} ${GRAPHS_SCRS} ${SOUNDS_SCRS})
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 17) set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 17)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_NAME}-v${PROJECT_VERSION}) set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_NAME}-v${PROJECT_VERSION})
if(MSVC) if(MSVC)
# msvc does not append 'lib' - do it here to have consistent name # msvc does not append 'lib' - do it here to have consistent name

View File

@ -0,0 +1,60 @@
#include "Game.hpp"
#include <SFML/Window/ContextSettings.hpp>
#include <SFML/Window/Event.hpp>
using std::make_shared;
using std::make_unique;
Game::Game(bool dbg) : gbDbgModeEnabled(dbg) {
InitWindows();
if (gbDbgModeEnabled)
gDbgUI = make_unique<DebugUI>();
}
void Game::InitWindows() {
// Create default game window
sf::ContextSettings sWindowSettings;
sWindowSettings.depthBits = 0;
sWindowSettings.stencilBits = 0;
sWindowSettings.antialiasingLevel = 8;
sWindowSettings.sRgbCapable = true;
gMainWindow = make_shared<sf::RenderWindow>(
sf::VideoMode(1080, 720), "ProtoTank",
(sf::Style::Close | sf::Style::Titlebar),
sWindowSettings
);
gMainWindow->setVerticalSyncEnabled(false);
gMainWindow->setFramerateLimit(60);
gMainWindow->setKeyRepeatEnabled(false);
gMainWindow->setMouseCursorVisible(true);
}
GAME_STATUS Game::Update() {
gLoopTimer.restart();
sf::Event event;
while (gMainWindow->pollEvent(event)) {
if (event.type == sf::Event::Closed)
gMainWindow->close();
}
/*
auto ticks = static_cast<int32_t>(mLoopTimer.getElapsedTime().asMilliseconds());
gTicksMonitoring.push_back(ticks);
double cpuUsage = std::accumulate(gTicksMonitoring.begin(), gTicksMonitoring.end(), 0) / gTicksMonitoring.size();
*/
if (gMainWindow->isOpen())
return GAME_RUNNING;
else
return GAME_QUIT;
}
void Game::Render() {
gMainWindow->clear();
//gDbgUI->UpdateDebugData(gMainWindow);
gMainWindow->display();
}

View File

@ -0,0 +1,41 @@
#pragma once
#include <vector>
#include <memory>
#include <SFML/System/Clock.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include "Engine/Graphics/DebugUI.hpp"
typedef enum eGameStatus {
GAME_INIT,
GAME_RUNNING,
GAME_QUIT
} GAME_STATUS;
class Game final{
public:
Game(bool dbg) noexcept(false);
~Game() {}
Game(Game&&) = default;
Game& operator= (Game&&) = default;
Game(Game const&) = delete;
Game& operator= (Game const&) = delete;
GAME_STATUS Update();
void Render();
private:
void InitWindows();
bool gbDbgModeEnabled;
std::shared_ptr<sf::RenderWindow> gMainWindow = nullptr;
std::unique_ptr<DebugUI> gDbgUI = nullptr;
sf::Clock gLoopTimer;
std::vector<double> gTicksMonitoring;
};

View File

@ -1,29 +1,28 @@
#include <iostream> #include <iostream>
#include <stdexcept> #include <stdexcept>
//#include <csignal>
#include <vector>
#include <memory>
#include <SFML/Graphics.hpp> #include "Game.hpp"
#ifdef __AVX2__ using std::cout;
#endif using std::endl;
int main(int argc, char** argv) { int main(int argc, char** argv) {
sf::RenderWindow window(sf::VideoMode(480, 240), "ProtoTank"); GAME_STATUS status = GAME_INIT;
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
while (window.isOpen()) cout << "Init game instance" << endl;
{ auto arcadeGame = std::make_unique<Game>(true);
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear(); for ( ;; ) {
window.draw(shape); status = arcadeGame->Update();
window.display();
if (status == GAME_QUIT)
break;
arcadeGame->Render();
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;

View File

@ -44,7 +44,7 @@ class ProtoTank(ConanFile):
tc.generate() tc.generate()
for dep in self.dependencies.values(): for dep in self.dependencies.values():
if self.settings.os == "Windows" and len(dep.cpp_info.bindirs) > 0: if self.settings.os == "Windows" and len(dep.cpp_info.bindirs) > 0:
copy(self, "*.dll", dep.cpp_info.bindirs[0], self.build_folder) copy(self, "*.dll", dep.cpp_info.bindirs[0], self.build_folder + "/bin")
# def package(self): # def package(self):
# copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) # copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))

View File

@ -1,27 +1,27 @@
set(MAIN_SCRS set(MAIN_SCRS
ProtoTank.cpp ProtoTank.cpp
Game.cpp Game.cpp
Game.hpp Game.hpp
) )
set(UTILS_SCRS set(UTILS_SCRS
Engine/Utils/3DMaths.cpp Engine/Utils/3DMaths.cpp
Engine/Utils/3DMaths.hpp Engine/Utils/3DMaths.hpp
) )
set(MISC_SCRS set(MISC_SCRS
Engine/Misc/Console.cpp Engine/Misc/Console.cpp
Engine/Misc/Console.hpp Engine/Misc/Console.hpp
Engine/Misc/Logger.cpp Engine/Misc/Logger.cpp
Engine/Misc/Logger.hpp Engine/Misc/Logger.hpp
) )
set(GAME_SCRS set(GAME_SCRS
Engine/World/Arena.cpp Engine/World/Arena.cpp
Engine/World/Player.cpp Engine/World/Player.cpp
Engine/World/Tank.cpp Engine/World/Tank.cpp
) )
set(GRAPHS_SCRS set(GRAPHS_SCRS
Engine/Graphics/3DGraphics.cpp Engine/Graphics/3DGraphics.cpp
Engine/Graphics/Camera.cpp Engine/Graphics/Camera.cpp
Engine/Graphics/UI.cpp Engine/Graphics/UI.cpp
) )
set(SOUNDS_SCRS set(SOUNDS_SCRS