Create the main window
This commit is contained in:
parent
09f1e8a7ed
commit
ed206fb71d
8
.gitignore
vendored
8
.gitignore
vendored
@ -46,12 +46,7 @@ CTestTestfile.cmake
|
||||
_deps
|
||||
|
||||
# ---> VisualStudioCode
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
!.vscode/*.code-snippets
|
||||
.vscode/
|
||||
.cmake/
|
||||
.vsconan/
|
||||
|
||||
@ -61,5 +56,6 @@ _deps
|
||||
# Built Visual Studio Code Extensions
|
||||
*.vsix
|
||||
|
||||
bin/
|
||||
build/
|
||||
CMakeUserPresets.json
|
||||
|
@ -6,6 +6,19 @@
|
||||
cmake_minimum_required(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
|
||||
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)
|
||||
@ -24,6 +37,7 @@ include(srcs.list)
|
||||
# targets declarations
|
||||
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_REQUIRED ON)
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_NAME}-v${PROJECT_VERSION})
|
||||
if(MSVC)
|
||||
# msvc does not append 'lib' - do it here to have consistent name
|
||||
|
60
Game.cpp
60
Game.cpp
@ -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();
|
||||
}
|
41
Game.hpp
41
Game.hpp
@ -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;
|
||||
|
||||
};
|
@ -1,29 +1,28 @@
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
//#include <csignal>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include "Game.hpp"
|
||||
|
||||
#ifdef __AVX2__
|
||||
#endif
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
sf::RenderWindow window(sf::VideoMode(480, 240), "ProtoTank");
|
||||
sf::CircleShape shape(100.f);
|
||||
shape.setFillColor(sf::Color::Green);
|
||||
GAME_STATUS status = GAME_INIT;
|
||||
|
||||
while (window.isOpen())
|
||||
{
|
||||
sf::Event event;
|
||||
while (window.pollEvent(event))
|
||||
{
|
||||
if (event.type == sf::Event::Closed)
|
||||
window.close();
|
||||
}
|
||||
cout << "Init game instance" << endl;
|
||||
auto arcadeGame = std::make_unique<Game>(true);
|
||||
|
||||
window.clear();
|
||||
window.draw(shape);
|
||||
window.display();
|
||||
for ( ;; ) {
|
||||
status = arcadeGame->Update();
|
||||
|
||||
if (status == GAME_QUIT)
|
||||
break;
|
||||
|
||||
arcadeGame->Render();
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
@ -44,7 +44,7 @@ class ProtoTank(ConanFile):
|
||||
tc.generate()
|
||||
for dep in self.dependencies.values():
|
||||
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):
|
||||
# copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
|
||||
|
30
srcs.list
30
srcs.list
@ -1,27 +1,27 @@
|
||||
set(MAIN_SCRS
|
||||
ProtoTank.cpp
|
||||
Game.cpp
|
||||
Game.hpp
|
||||
ProtoTank.cpp
|
||||
Game.cpp
|
||||
Game.hpp
|
||||
)
|
||||
set(UTILS_SCRS
|
||||
Engine/Utils/3DMaths.cpp
|
||||
Engine/Utils/3DMaths.hpp
|
||||
Engine/Utils/3DMaths.cpp
|
||||
Engine/Utils/3DMaths.hpp
|
||||
)
|
||||
set(MISC_SCRS
|
||||
Engine/Misc/Console.cpp
|
||||
Engine/Misc/Console.hpp
|
||||
Engine/Misc/Logger.cpp
|
||||
Engine/Misc/Logger.hpp
|
||||
Engine/Misc/Console.cpp
|
||||
Engine/Misc/Console.hpp
|
||||
Engine/Misc/Logger.cpp
|
||||
Engine/Misc/Logger.hpp
|
||||
)
|
||||
set(GAME_SCRS
|
||||
Engine/World/Arena.cpp
|
||||
Engine/World/Player.cpp
|
||||
Engine/World/Tank.cpp
|
||||
Engine/World/Arena.cpp
|
||||
Engine/World/Player.cpp
|
||||
Engine/World/Tank.cpp
|
||||
)
|
||||
set(GRAPHS_SCRS
|
||||
Engine/Graphics/3DGraphics.cpp
|
||||
Engine/Graphics/Camera.cpp
|
||||
Engine/Graphics/UI.cpp
|
||||
Engine/Graphics/3DGraphics.cpp
|
||||
Engine/Graphics/Camera.cpp
|
||||
Engine/Graphics/UI.cpp
|
||||
)
|
||||
set(SOUNDS_SCRS
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user