Skip to content

Commit abe1cfe

Browse files
committed
Initial commit
0 parents  commit abe1cfe

24 files changed

+778
-0
lines changed

CMakeLists.txt

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
cmake_minimum_required(VERSION 3.2)
2+
3+
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Build type")
4+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
5+
6+
project(Stronghold)
7+
set(Stronghold_VERSION, 0.0.1)
8+
9+
include_directories(src)
10+
11+
find_package(SDL2 REQUIRED)
12+
if(NOT SDL2_FOUND)
13+
message(FATAL_ERROR "SDL2 has to be installed!")
14+
endif(NOT SDL2_FOUND)
15+
include_directories(${SDL2_INCLUDE_DIR})
16+
17+
set(Boost_USE_STATIC_LIBS OFF)
18+
set(Boost_USE_MULTITHREADED ON)
19+
set(Boost_USE_STATIC_RUNTIME OFF)
20+
find_package(Boost 1.45.0 COMPONENTS system thread)
21+
22+
if(Boost_FOUND)
23+
include_directories(${Boost_INCLUDE_DIRS})
24+
else(Boost_FOUND)
25+
message(FATAL_ERROR "Boost has to be installed!")
26+
endif(Boost_FOUND)
27+
28+
file(GLOB_RECURSE SOURCES src/*.cpp)
29+
30+
if(MSVC)
31+
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
32+
endif()
33+
34+
add_executable(Stronghold ${SOURCES})
35+
add_definitions(-Wall -Wextra -pedantic-errors -Ofast)
36+
set_target_properties(Stronghold PROPERTIES
37+
CXX_STANDARD 11
38+
CXX_STANDARD_REQUIRED YES
39+
CXX_EXTENSIONS NO
40+
)
41+
42+
target_link_libraries(Stronghold ${SDL2_LIBRARY} ${Boost_LIBRARIES})

cmake/FindSDL2.cmake

+249
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
# - Find SDL2
2+
# Find the SDL2 headers and libraries
3+
#
4+
# SDL2::SDL2 - Imported target to use for building a library
5+
# SDL2::SDL2main - Imported interface target to use if you want SDL and SDLmain.
6+
# SDL2_FOUND - True if SDL2 was found.
7+
# SDL2_DYNAMIC - If we found a DLL version of SDL (meaning you might want to copy a DLL from SDL2::SDL2)
8+
#
9+
# Original Author:
10+
# 2015 Ryan Pavlik <[email protected]> <[email protected]>
11+
#
12+
# Copyright Sensics, Inc. 2015.
13+
# Distributed under the Boost Software License, Version 1.0.
14+
# (See accompanying file LICENSE_1_0.txt or copy at
15+
# http://www.boost.org/LICENSE_1_0.txt)
16+
17+
# Set up architectures (for windows) and prefixes (for mingw builds)
18+
if(WIN32)
19+
if(MINGW)
20+
include(MinGWSearchPathExtras OPTIONAL)
21+
if(MINGWSEARCH_TARGET_TRIPLE)
22+
set(SDL2_PREFIX ${MINGWSEARCH_TARGET_TRIPLE})
23+
endif()
24+
endif()
25+
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
26+
set(SDL2_LIB_PATH_SUFFIX lib/x64)
27+
if(NOT MSVC AND NOT SDL2_PREFIX)
28+
set(SDL2_PREFIX x86_64-w64-mingw32)
29+
endif()
30+
else()
31+
set(SDL2_LIB_PATH_SUFFIX lib/x86)
32+
if(NOT MSVC AND NOT SDL2_PREFIX)
33+
set(SDL2_PREFIX i686-w64-mingw32)
34+
endif()
35+
endif()
36+
endif()
37+
38+
if(SDL2_PREFIX)
39+
set(SDL2_ORIGPREFIXPATH ${CMAKE_PREFIX_PATH})
40+
if(SDL2_ROOT_DIR)
41+
list(APPEND CMAKE_PREFIX_PATH "${SDL2_ROOT_DIR}")
42+
endif()
43+
if(CMAKE_PREFIX_PATH)
44+
foreach(_prefix ${CMAKE_PREFIX_PATH})
45+
list(APPEND CMAKE_PREFIX_PATH "${_prefix}/${SDL2_PREFIX}")
46+
endforeach()
47+
endif()
48+
if(MINGWSEARCH_PREFIXES)
49+
list(APPEND CMAKE_PREFIX_PATH ${MINGWSEARCH_PREFIXES})
50+
endif()
51+
endif()
52+
53+
# Invoke pkgconfig for hints
54+
find_package(PkgConfig QUIET)
55+
set(SDL2_INCLUDE_HINTS)
56+
set(SDL2_LIB_HINTS)
57+
if(PKG_CONFIG_FOUND)
58+
pkg_search_module(SDL2PC QUIET sdl2)
59+
if(SDL2PC_INCLUDE_DIRS)
60+
set(SDL2_INCLUDE_HINTS ${SDL2PC_INCLUDE_DIRS})
61+
endif()
62+
if(SDL2PC_LIBRARY_DIRS)
63+
set(SDL2_LIB_HINTS ${SDL2PC_LIBRARY_DIRS})
64+
endif()
65+
endif()
66+
67+
include(FindPackageHandleStandardArgs)
68+
69+
find_library(SDL2_LIBRARY
70+
NAMES
71+
SDL2
72+
HINTS
73+
${SDL2_LIB_HINTS}
74+
PATHS
75+
${SDL2_ROOT_DIR}
76+
ENV SDL2DIR
77+
PATH_SUFFIXES lib SDL2 ${SDL2_LIB_PATH_SUFFIX})
78+
79+
set(_sdl2_framework FALSE)
80+
# Some special-casing if we've found/been given a framework.
81+
# Handles whether we're given the library inside the framework or the framework itself.
82+
if(APPLE AND "${SDL2_LIBRARY}" MATCHES "(/[^/]+)*.framework(/.*)?$")
83+
set(_sdl2_framework TRUE)
84+
set(SDL2_FRAMEWORK "${SDL2_LIBRARY}")
85+
# Move up in the directory tree as required to get the framework directory.
86+
while("${SDL2_FRAMEWORK}" MATCHES "(/[^/]+)*.framework(/.*)$" AND NOT "${SDL2_FRAMEWORK}" MATCHES "(/[^/]+)*.framework$")
87+
get_filename_component(SDL2_FRAMEWORK "${SDL2_FRAMEWORK}" DIRECTORY)
88+
endwhile()
89+
if("${SDL2_FRAMEWORK}" MATCHES "(/[^/]+)*.framework$")
90+
set(SDL2_FRAMEWORK_NAME ${CMAKE_MATCH_1})
91+
# If we found a framework, do a search for the header ahead of time that will be more likely to get the framework header.
92+
find_path(SDL2_INCLUDE_DIR
93+
NAMES
94+
SDL_haptic.h # this file was introduced with SDL2
95+
HINTS
96+
"${SDL2_FRAMEWORK}/Headers/")
97+
else()
98+
# For some reason we couldn't get the framework directory itself.
99+
# Shouldn't happen, but might if something is weird.
100+
unset(SDL2_FRAMEWORK)
101+
endif()
102+
endif()
103+
104+
find_path(SDL2_INCLUDE_DIR
105+
NAMES
106+
SDL_haptic.h # this file was introduced with SDL2
107+
HINTS
108+
${SDL2_INCLUDE_HINTS}
109+
PATHS
110+
${SDL2_ROOT_DIR}
111+
ENV SDL2DIR
112+
PATH_SUFFIXES include include/sdl2 include/SDL2 SDL2)
113+
114+
if(WIN32 AND SDL2_LIBRARY)
115+
find_file(SDL2_RUNTIME_LIBRARY
116+
NAMES
117+
SDL2.dll
118+
libSDL2.dll
119+
HINTS
120+
${SDL2_LIB_HINTS}
121+
PATHS
122+
${SDL2_ROOT_DIR}
123+
ENV SDL2DIR
124+
PATH_SUFFIXES bin lib ${SDL2_LIB_PATH_SUFFIX})
125+
endif()
126+
127+
128+
if(WIN32 OR ANDROID OR IOS OR (APPLE AND NOT _sdl2_framework))
129+
set(SDL2_EXTRA_REQUIRED SDL2_SDLMAIN_LIBRARY)
130+
find_library(SDL2_SDLMAIN_LIBRARY
131+
NAMES
132+
SDL2main
133+
PATHS
134+
${SDL2_ROOT_DIR}
135+
ENV SDL2DIR
136+
PATH_SUFFIXES lib ${SDL2_LIB_PATH_SUFFIX})
137+
endif()
138+
139+
if(MINGW AND NOT SDL2PC_FOUND)
140+
find_library(SDL2_MINGW_LIBRARY mingw32)
141+
find_library(SDL2_MWINDOWS_LIBRARY mwindows)
142+
endif()
143+
144+
if(SDL2_PREFIX)
145+
# Restore things the way they used to be.
146+
set(CMAKE_PREFIX_PATH ${SDL2_ORIGPREFIXPATH})
147+
endif()
148+
149+
# handle the QUIETLY and REQUIRED arguments and set QUATLIB_FOUND to TRUE if
150+
# all listed variables are TRUE
151+
include(FindPackageHandleStandardArgs)
152+
find_package_handle_standard_args(SDL2
153+
DEFAULT_MSG
154+
SDL2_LIBRARY
155+
SDL2_INCLUDE_DIR
156+
${SDL2_EXTRA_REQUIRED})
157+
158+
if(SDL2_FOUND)
159+
if(NOT TARGET SDL2::SDL2)
160+
# Create SDL2::SDL2
161+
if(WIN32 AND SDL2_RUNTIME_LIBRARY)
162+
set(SDL2_DYNAMIC TRUE)
163+
add_library(SDL2::SDL2 SHARED IMPORTED)
164+
set_target_properties(SDL2::SDL2
165+
PROPERTIES
166+
IMPORTED_IMPLIB "${SDL2_LIBRARY}"
167+
IMPORTED_LOCATION "${SDL2_RUNTIME_LIBRARY}"
168+
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}"
169+
)
170+
else()
171+
add_library(SDL2::SDL2 UNKNOWN IMPORTED)
172+
if(SDL2_FRAMEWORK AND SDL2_FRAMEWORK_NAME)
173+
# Handle the case that SDL2 is a framework and we were able to decompose it above.
174+
set_target_properties(SDL2::SDL2 PROPERTIES
175+
IMPORTED_LOCATION "${SDL2_FRAMEWORK}/${SDL2_FRAMEWORK_NAME}")
176+
elseif(_sdl2_framework AND SDL2_LIBRARY MATCHES "(/[^/]+)*.framework$")
177+
# Handle the case that SDL2 is a framework and SDL_LIBRARY is just the framework itself.
178+
179+
# This takes the basename of the framework, without the extension,
180+
# and sets it (as a child of the framework) as the imported location for the target.
181+
# This is the library symlink inside of the framework.
182+
set_target_properties(SDL2::SDL2 PROPERTIES
183+
IMPORTED_LOCATION "${SDL2_LIBRARY}/${CMAKE_MATCH_1}")
184+
else()
185+
# Handle non-frameworks (including non-Mac), as well as the case that we're given the library inside of the framework
186+
set_target_properties(SDL2::SDL2 PROPERTIES
187+
IMPORTED_LOCATION "${SDL2_LIBRARY}")
188+
endif()
189+
set_target_properties(SDL2::SDL2
190+
PROPERTIES
191+
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}"
192+
)
193+
endif()
194+
195+
if(APPLE)
196+
# Need Cocoa here, is always a framework
197+
find_library(SDL2_COCOA_LIBRARY Cocoa)
198+
list(APPEND SDL2_EXTRA_REQUIRED SDL2_COCOA_LIBRARY)
199+
if(SDL2_COCOA_LIBRARY)
200+
set_target_properties(SDL2::SDL2 PROPERTIES
201+
IMPORTED_LINK_INTERFACE_LIBRARIES ${SDL2_COCOA_LIBRARY})
202+
endif()
203+
endif()
204+
205+
206+
# Compute what to do with SDL2main
207+
set(SDL2MAIN_LIBRARIES SDL2::SDL2)
208+
add_library(SDL2::SDL2main INTERFACE IMPORTED)
209+
if(SDL2_SDLMAIN_LIBRARY)
210+
add_library(SDL2::SDL2main_real STATIC IMPORTED)
211+
set_target_properties(SDL2::SDL2main_real
212+
PROPERTIES
213+
IMPORTED_LOCATION "${SDL2_SDLMAIN_LIBRARY}")
214+
set(SDL2MAIN_LIBRARIES SDL2::SDL2main_real ${SDL2MAIN_LIBRARIES})
215+
endif()
216+
if(MINGW)
217+
# MinGW requires some additional libraries to appear earlier in the link line.
218+
if(SDL2PC_LIBRARIES)
219+
# Use pkgconfig-suggested extra libraries if available.
220+
list(REMOVE_ITEM SDL2PC_LIBRARIES SDL2main SDL2)
221+
set(SDL2MAIN_LIBRARIES ${SDL2PC_LIBRARIES} ${SDL2MAIN_LIBRARIES})
222+
else()
223+
# fall back to extra libraries specified in pkg-config in
224+
# an official binary distro of SDL2 for MinGW I downloaded
225+
if(SDL2_MINGW_LIBRARY)
226+
set(SDL2MAIN_LIBRARIES ${SDL2_MINGW_LIBRARY} ${SDL2MAIN_LIBRARIES})
227+
endif()
228+
if(SDL2_MWINDOWS_LIBRARY)
229+
set(SDL2MAIN_LIBRARIES ${SDL2_MWINDOWS_LIBRARY} ${SDL2MAIN_LIBRARIES})
230+
endif()
231+
endif()
232+
set_target_properties(SDL2::SDL2main
233+
PROPERTIES
234+
INTERFACE_COMPILE_DEFINITIONS "main=SDL_main")
235+
endif()
236+
set_target_properties(SDL2::SDL2main
237+
PROPERTIES
238+
INTERFACE_LINK_LIBRARIES "${SDL2MAIN_LIBRARIES}")
239+
endif()
240+
mark_as_advanced(SDL2_ROOT_DIR)
241+
endif()
242+
243+
mark_as_advanced(SDL2_LIBRARY
244+
SDL2_RUNTIME_LIBRARY
245+
SDL2_INCLUDE_DIR
246+
SDL2_SDLMAIN_LIBRARY
247+
SDL2_COCOA_LIBRARY
248+
SDL2_MINGW_LIBRARY
249+
SDL2_MWINDOWS_LIBRARY)

data/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!.gitignore

src/Config.h

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
3+
#define OPENSH_VERSION_MAJOR 0
4+
#define OPENSH_VERSION_MINOR 1
5+
#define OPENSH_VERSION_STRING "0.1"

src/Display.cpp

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#include <Display.h>
2+
3+
using namespace OpenSH::Game;
4+
using namespace OpenSH::System;
5+
6+
Display::Display() {
7+
SDL_Init(SDL_INIT_EVERYTHING);
8+
}
9+
10+
Display::~Display() {
11+
SDL_Quit();
12+
}
13+
14+
void Display::OpenWindowed(std::string title, int width, int height) {
15+
window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_SHOWN | SDL_WINDOW_INPUT_FOCUS);
16+
if(!window) {
17+
Logger::LogToConsole("Unable to create SDL2 window!", Logger::ERROR);
18+
Logger::LogToConsole(SDL_GetError(), Logger::WARNING);
19+
}
20+
21+
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
22+
if(!renderer) {
23+
Logger::LogToConsole("Unable to create SDL2 renderer!", Logger::ERROR);
24+
Logger::LogToConsole(SDL_GetError(), Logger::WARNING);
25+
}
26+
27+
open = true;
28+
}
29+
30+
void Display::Fullscreen() {
31+
int err = SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
32+
if(err < 0) {
33+
Logger::LogToConsole("Unable to switch to fullscreen!", Logger::WARNING);
34+
Logger::LogToConsole(SDL_GetError(), Logger::WARNING);
35+
}
36+
}
37+
38+
void Display::Close() {
39+
SDL_DestroyWindow(window);
40+
}
41+
42+
void Display::Update() {
43+
SDL_RenderPresent(renderer);
44+
45+
SDL_Delay(10);
46+
47+
while(SDL_PollEvent(&event) != 0) {
48+
if(event.type == SDL_QUIT) {
49+
open = false;
50+
}
51+
}
52+
}
53+
54+
void Display::Clear() {
55+
SDL_RenderClear(renderer);
56+
}
57+
58+
bool Display::IsOpen() {
59+
return open;
60+
}
61+
62+
SDL_Renderer *Display::GetRenderer() {
63+
return renderer;
64+
}

0 commit comments

Comments
 (0)