commit fb3157c55dd8bdae9d13cac00a633e789d33851b Author: MitchellHansen Date: Thu Mar 30 23:28:25 2017 -0700 init diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..76acfe7 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,39 @@ +# Check versions +message(STATUS "CMake version: ${CMAKE_VERSION}") +cmake_minimum_required(VERSION 3.1) + +# Set the project name +set(PNAME Mandlebrot) +project(${PNAME}) + +# Set up variables, and find SFML +if (WIN32) + set(SFML_ROOT root CACHE STRING "User specified path") + set(SFML_INCLUDE_DIR ${SFML_ROOT}/include) +endif() + +set(SFML_COMPONENTS graphics window system network audio) +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}) +find_package(SFML 2.1 COMPONENTS ${SFML_COMPONENTS} REQUIRED) +message(STATUS "SFML found: ${SFML_FOUND}") + +# Include the directories for SFML's headers +include_directories(${SFML_INCLUDE_DIR}) +include_directories(include) + +# Glob all thr sources into their values +file(GLOB_RECURSE SOURCES "src/*.cpp") +file(GLOB_RECURSE HEADERS "include/*.h" "include/*.hpp") + +add_executable(${PNAME} ${SOURCES} ${HEADERS}) + +# Link CL, GL, and SFML +target_link_libraries (${PNAME} ${SFML_LIBRARIES} ${SFML_DEPENDENCIES}) + +if (NOT WIN32) + target_link_libraries (${PNAME} -lpthread) +endif() + +# Setup to use C++14 +set_property(TARGET ${PNAME} PROPERTY CXX_STANDARD 14) + diff --git a/FindSFML.cmake b/FindSFML.cmake new file mode 100644 index 0000000..9acf23d --- /dev/null +++ b/FindSFML.cmake @@ -0,0 +1,369 @@ +# This script locates the SFML library +# ------------------------------------ +# +# Usage +# ----- +# +# When you try to locate the SFML libraries, you must specify which modules you want to use (system, window, graphics, network, audio, main). +# If none is given, the SFML_LIBRARIES variable will be empty and you'll end up linking to nothing. +# example: +# find_package(SFML COMPONENTS graphics window system) # find the graphics, window and system modules +# +# You can enforce a specific version, either MAJOR.MINOR or only MAJOR. +# If nothing is specified, the version won't be checked (i.e. any version will be accepted). +# example: +# find_package(SFML COMPONENTS ...) # no specific version required +# find_package(SFML 2 COMPONENTS ...) # any 2.x version +# find_package(SFML 2.4 COMPONENTS ...) # version 2.4 or greater +# +# By default, the dynamic libraries of SFML will be found. To find the static ones instead, +# you must set the SFML_STATIC_LIBRARIES variable to TRUE before calling find_package(SFML ...). +# Since you have to link yourself all the SFML dependencies when you link it statically, the following +# additional variables are defined: SFML_XXX_DEPENDENCIES and SFML_DEPENDENCIES (see their detailed +# description below). +# In case of static linking, the SFML_STATIC macro will also be defined by this script. +# example: +# set(SFML_STATIC_LIBRARIES TRUE) +# find_package(SFML 2 COMPONENTS network system) +# +# On Mac OS X if SFML_STATIC_LIBRARIES is not set to TRUE then by default CMake will search for frameworks unless +# CMAKE_FIND_FRAMEWORK is set to "NEVER" for example. Please refer to CMake documentation for more details. +# Moreover, keep in mind that SFML frameworks are only available as release libraries unlike dylibs which +# are available for both release and debug modes. +# +# If SFML is not installed in a standard path, you can use the SFML_ROOT CMake (or environment) variable +# to tell CMake where SFML is. +# +# Output +# ------ +# +# This script defines the following variables: +# - For each specified module XXX (system, window, graphics, network, audio, main): +# - SFML_XXX_LIBRARY_DEBUG: the name of the debug library of the xxx module (set to SFML_XXX_LIBRARY_RELEASE is no debug version is found) +# - SFML_XXX_LIBRARY_RELEASE: the name of the release library of the xxx module (set to SFML_XXX_LIBRARY_DEBUG is no release version is found) +# - SFML_XXX_LIBRARY: the name of the library to link to for the xxx module (includes both debug and optimized names if necessary) +# - SFML_XXX_FOUND: true if either the debug or release library of the xxx module is found +# - SFML_XXX_DEPENDENCIES: the list of libraries the module depends on, in case of static linking +# - SFML_LIBRARIES: the list of all libraries corresponding to the required modules +# - SFML_FOUND: true if all the required modules are found +# - SFML_INCLUDE_DIR: the path where SFML headers are located (the directory containing the SFML/Config.hpp file) +# - SFML_DEPENDENCIES: the list of libraries SFML depends on, in case of static linking +# +# example: +# find_package(SFML 2 COMPONENTS system window graphics audio REQUIRED) +# include_directories(${SFML_INCLUDE_DIR}) +# add_executable(myapp ...) +# target_link_libraries(myapp ${SFML_LIBRARIES}) + +# define the SFML_STATIC macro if static build was chosen +if(SFML_STATIC_LIBRARIES) + add_definitions(-DSFML_STATIC) +endif() + +# define the list of search paths for headers and libraries +set(FIND_SFML_PATHS + ${SFML_ROOT} + $ENV{SFML_ROOT} + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw + /opt/local + /opt/csw + /opt) + +# find the SFML include directory +find_path(SFML_INCLUDE_DIR SFML/Config.hpp + PATH_SUFFIXES include + PATHS ${FIND_SFML_PATHS}) + +# check the version number +set(SFML_VERSION_OK TRUE) +if(SFML_FIND_VERSION AND SFML_INCLUDE_DIR) + # extract the major and minor version numbers from SFML/Config.hpp + # we have to handle framework a little bit differently: + if("${SFML_INCLUDE_DIR}" MATCHES "SFML.framework") + set(SFML_CONFIG_HPP_INPUT "${SFML_INCLUDE_DIR}/Headers/Config.hpp") + else() + set(SFML_CONFIG_HPP_INPUT "${SFML_INCLUDE_DIR}/SFML/Config.hpp") + endif() + FILE(READ "${SFML_CONFIG_HPP_INPUT}" SFML_CONFIG_HPP_CONTENTS) + STRING(REGEX REPLACE ".*#define SFML_VERSION_MAJOR ([0-9]+).*" "\\1" SFML_VERSION_MAJOR "${SFML_CONFIG_HPP_CONTENTS}") + STRING(REGEX REPLACE ".*#define SFML_VERSION_MINOR ([0-9]+).*" "\\1" SFML_VERSION_MINOR "${SFML_CONFIG_HPP_CONTENTS}") + STRING(REGEX REPLACE ".*#define SFML_VERSION_PATCH ([0-9]+).*" "\\1" SFML_VERSION_PATCH "${SFML_CONFIG_HPP_CONTENTS}") + if (NOT "${SFML_VERSION_PATCH}" MATCHES "^[0-9]+$") + set(SFML_VERSION_PATCH 0) + endif() + math(EXPR SFML_REQUESTED_VERSION "${SFML_FIND_VERSION_MAJOR} * 10000 + ${SFML_FIND_VERSION_MINOR} * 100 + ${SFML_FIND_VERSION_PATCH}") + + # if we could extract them, compare with the requested version number + if (SFML_VERSION_MAJOR) + # transform version numbers to an integer + math(EXPR SFML_VERSION "${SFML_VERSION_MAJOR} * 10000 + ${SFML_VERSION_MINOR} * 100 + ${SFML_VERSION_PATCH}") + + # compare them + if(SFML_VERSION LESS SFML_REQUESTED_VERSION) + set(SFML_VERSION_OK FALSE) + endif() + else() + # SFML version is < 2.0 + if (SFML_REQUESTED_VERSION GREATER 10900) + set(SFML_VERSION_OK FALSE) + set(SFML_VERSION_MAJOR 1) + set(SFML_VERSION_MINOR x) + set(SFML_VERSION_PATCH x) + endif() + endif() +endif() + +# find the requested modules +set(SFML_FOUND TRUE) # will be set to false if one of the required modules is not found +foreach(FIND_SFML_COMPONENT ${SFML_FIND_COMPONENTS}) + string(TOLOWER ${FIND_SFML_COMPONENT} FIND_SFML_COMPONENT_LOWER) + string(TOUPPER ${FIND_SFML_COMPONENT} FIND_SFML_COMPONENT_UPPER) + set(FIND_SFML_COMPONENT_NAME sfml-${FIND_SFML_COMPONENT_LOWER}) + + # no suffix for sfml-main, it is always a static library + if(FIND_SFML_COMPONENT_LOWER STREQUAL "main") + # release library + find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE + NAMES ${FIND_SFML_COMPONENT_NAME} + PATH_SUFFIXES lib64 lib + PATHS ${FIND_SFML_PATHS}) + + # debug library + find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG + NAMES ${FIND_SFML_COMPONENT_NAME}-d + PATH_SUFFIXES lib64 lib + PATHS ${FIND_SFML_PATHS}) + else() + # static release library + find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_RELEASE + NAMES ${FIND_SFML_COMPONENT_NAME}-s + PATH_SUFFIXES lib64 lib + PATHS ${FIND_SFML_PATHS}) + + # static debug library + find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_DEBUG + NAMES ${FIND_SFML_COMPONENT_NAME}-s-d + PATH_SUFFIXES lib64 lib + PATHS ${FIND_SFML_PATHS}) + + # dynamic release library + find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_RELEASE + NAMES ${FIND_SFML_COMPONENT_NAME} + PATH_SUFFIXES lib64 lib + PATHS ${FIND_SFML_PATHS}) + + # dynamic debug library + find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_DEBUG + NAMES ${FIND_SFML_COMPONENT_NAME}-d + PATH_SUFFIXES lib64 lib + PATHS ${FIND_SFML_PATHS}) + + # choose the entries that fit the requested link type + if(SFML_STATIC_LIBRARIES) + if(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_RELEASE) + set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_RELEASE}) + endif() + if(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_DEBUG) + set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_DEBUG}) + endif() + else() + if(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_RELEASE) + set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_RELEASE}) + endif() + if(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_DEBUG) + set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_DEBUG}) + endif() + endif() + endif() + + if (SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG OR SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE) + # library found + set(SFML_${FIND_SFML_COMPONENT_UPPER}_FOUND TRUE) + + # if both are found, set SFML_XXX_LIBRARY to contain both + if (SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG AND SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE) + set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY debug ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG} + optimized ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE}) + endif() + + # if only one debug/release variant is found, set the other to be equal to the found one + if (SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG AND NOT SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE) + # debug and not release + set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG}) + set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG}) + endif() + if (SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE AND NOT SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG) + # release and not debug + set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE}) + set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE}) + endif() + else() + # library not found + set(SFML_FOUND FALSE) + set(SFML_${FIND_SFML_COMPONENT_UPPER}_FOUND FALSE) + set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY "") + set(FIND_SFML_MISSING "${FIND_SFML_MISSING} SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY") + endif() + + # mark as advanced + MARK_AS_ADVANCED(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY + SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE + SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG + SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_RELEASE + SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_DEBUG + SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_RELEASE + SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_DEBUG) + + # add to the global list of libraries + set(SFML_LIBRARIES ${SFML_LIBRARIES} "${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY}") +endforeach() + +# in case of static linking, we must also define the list of all the dependencies of SFML libraries +if(SFML_STATIC_LIBRARIES) + + # detect the OS + if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + set(FIND_SFML_OS_WINDOWS 1) + elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + set(FIND_SFML_OS_LINUX 1) + elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") + set(FIND_SFML_OS_FREEBSD 1) + elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + set(FIND_SFML_OS_MACOSX 1) + endif() + + # start with an empty list + set(SFML_DEPENDENCIES) + set(FIND_SFML_DEPENDENCIES_NOTFOUND) + + # macro that searches for a 3rd-party library + macro(find_sfml_dependency output friendlyname) + # No lookup in environment variables (PATH on Windows), as they may contain wrong library versions + find_library(${output} NAMES ${ARGN} PATHS ${FIND_SFML_PATHS} PATH_SUFFIXES lib NO_SYSTEM_ENVIRONMENT_PATH) + if(${${output}} STREQUAL "${output}-NOTFOUND") + unset(output) + set(FIND_SFML_DEPENDENCIES_NOTFOUND "${FIND_SFML_DEPENDENCIES_NOTFOUND} ${friendlyname}") + endif() + endmacro() + + # sfml-system + list(FIND SFML_FIND_COMPONENTS "system" FIND_SFML_SYSTEM_COMPONENT) + if(NOT ${FIND_SFML_SYSTEM_COMPONENT} EQUAL -1) + + # update the list -- these are only system libraries, no need to find them + if(FIND_SFML_OS_LINUX OR FIND_SFML_OS_FREEBSD OR FIND_SFML_OS_MACOSX) + set(SFML_SYSTEM_DEPENDENCIES "pthread") + endif() + if(FIND_SFML_OS_LINUX) + set(SFML_SYSTEM_DEPENDENCIES ${SFML_SYSTEM_DEPENDENCIES} "rt") + endif() + if(FIND_SFML_OS_WINDOWS) + set(SFML_SYSTEM_DEPENDENCIES "winmm") + endif() + set(SFML_DEPENDENCIES ${SFML_SYSTEM_DEPENDENCIES} ${SFML_DEPENDENCIES}) + endif() + + # sfml-network + list(FIND SFML_FIND_COMPONENTS "network" FIND_SFML_NETWORK_COMPONENT) + if(NOT ${FIND_SFML_NETWORK_COMPONENT} EQUAL -1) + + # update the list -- these are only system libraries, no need to find them + if(FIND_SFML_OS_WINDOWS) + set(SFML_NETWORK_DEPENDENCIES "ws2_32") + endif() + set(SFML_DEPENDENCIES ${SFML_NETWORK_DEPENDENCIES} ${SFML_DEPENDENCIES}) + endif() + + # sfml-window + list(FIND SFML_FIND_COMPONENTS "window" FIND_SFML_WINDOW_COMPONENT) + if(NOT ${FIND_SFML_WINDOW_COMPONENT} EQUAL -1) + + # find libraries + if(FIND_SFML_OS_LINUX OR FIND_SFML_OS_FREEBSD) + find_sfml_dependency(X11_LIBRARY "X11" X11) + find_sfml_dependency(LIBXCB_LIBRARIES "XCB" xcb libxcb) + find_sfml_dependency(X11_XCB_LIBRARY "X11-xcb" X11-xcb libX11-xcb) + find_sfml_dependency(XCB_RANDR_LIBRARY "xcb-randr" xcb-randr libxcb-randr) + find_sfml_dependency(XCB_IMAGE_LIBRARY "xcb-image" xcb-image libxcb-image) + endif() + + if(FIND_SFML_OS_LINUX) + find_sfml_dependency(UDEV_LIBRARIES "UDev" udev libudev) + endif() + + # update the list + if(FIND_SFML_OS_WINDOWS) + set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "opengl32" "winmm" "gdi32") + elseif(FIND_SFML_OS_LINUX) + set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "GL" ${X11_LIBRARY} ${LIBXCB_LIBRARIES} ${X11_XCB_LIBRARY} ${XCB_RANDR_LIBRARY} ${XCB_IMAGE_LIBRARY} ${UDEV_LIBRARIES}) + elseif(FIND_SFML_OS_FREEBSD) + set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "GL" ${X11_LIBRARY} ${LIBXCB_LIBRARIES} ${X11_XCB_LIBRARY} ${XCB_RANDR_LIBRARY} ${XCB_IMAGE_LIBRARY} "usbhid") + elseif(FIND_SFML_OS_MACOSX) + set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "-framework OpenGL -framework Foundation -framework AppKit -framework IOKit -framework Carbon") + endif() + set(SFML_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} ${SFML_DEPENDENCIES}) + endif() + + # sfml-graphics + list(FIND SFML_FIND_COMPONENTS "graphics" FIND_SFML_GRAPHICS_COMPONENT) + if(NOT ${FIND_SFML_GRAPHICS_COMPONENT} EQUAL -1) + + # find libraries + find_sfml_dependency(FREETYPE_LIBRARY "FreeType" freetype) + find_sfml_dependency(JPEG_LIBRARY "libjpeg" jpeg) + + # update the list + set(SFML_GRAPHICS_DEPENDENCIES ${FREETYPE_LIBRARY} ${JPEG_LIBRARY}) + set(SFML_DEPENDENCIES ${SFML_GRAPHICS_DEPENDENCIES} ${SFML_DEPENDENCIES}) + endif() + + # sfml-audio + list(FIND SFML_FIND_COMPONENTS "audio" FIND_SFML_AUDIO_COMPONENT) + if(NOT ${FIND_SFML_AUDIO_COMPONENT} EQUAL -1) + + # find libraries + find_sfml_dependency(OPENAL_LIBRARY "OpenAL" openal openal32) + find_sfml_dependency(OGG_LIBRARY "Ogg" ogg) + find_sfml_dependency(VORBIS_LIBRARY "Vorbis" vorbis) + find_sfml_dependency(VORBISFILE_LIBRARY "VorbisFile" vorbisfile) + find_sfml_dependency(VORBISENC_LIBRARY "VorbisEnc" vorbisenc) + find_sfml_dependency(FLAC_LIBRARY "FLAC" FLAC) + + # update the list + set(SFML_AUDIO_DEPENDENCIES ${OPENAL_LIBRARY} ${FLAC_LIBRARY} ${VORBISENC_LIBRARY} ${VORBISFILE_LIBRARY} ${VORBIS_LIBRARY} ${OGG_LIBRARY}) + set(SFML_DEPENDENCIES ${SFML_DEPENDENCIES} ${SFML_AUDIO_DEPENDENCIES}) + endif() + +endif() + +# handle errors +if(NOT SFML_VERSION_OK) + # SFML version not ok + set(FIND_SFML_ERROR "SFML found but version too low (requested: ${SFML_FIND_VERSION}, found: ${SFML_VERSION_MAJOR}.${SFML_VERSION_MINOR}.${SFML_VERSION_PATCH})") + set(SFML_FOUND FALSE) +elseif(SFML_STATIC_LIBRARIES AND FIND_SFML_DEPENDENCIES_NOTFOUND) + set(FIND_SFML_ERROR "SFML found but some of its dependencies are missing (${FIND_SFML_DEPENDENCIES_NOTFOUND})") + set(SFML_FOUND FALSE) +elseif(NOT SFML_FOUND) + # include directory or library not found + set(FIND_SFML_ERROR "Could NOT find SFML (missing: ${FIND_SFML_MISSING})") +endif() +if (NOT SFML_FOUND) + if(SFML_FIND_REQUIRED) + # fatal error + message(FATAL_ERROR ${FIND_SFML_ERROR}) + elseif(NOT SFML_FIND_QUIETLY) + # error but continue + message("${FIND_SFML_ERROR}") + endif() +endif() + +# handle success +if(SFML_FOUND AND NOT SFML_FIND_QUIETLY) + message(STATUS "Found SFML ${SFML_VERSION_MAJOR}.${SFML_VERSION_MINOR}.${SFML_VERSION_PATCH} in ${SFML_INCLUDE_DIR}") +endif() + diff --git a/assets/fonts/Arial.ttf b/assets/fonts/Arial.ttf new file mode 100644 index 0000000..ab68fb1 Binary files /dev/null and b/assets/fonts/Arial.ttf differ diff --git a/assets/fonts/Arial_Bold.ttf b/assets/fonts/Arial_Bold.ttf new file mode 100644 index 0000000..940e255 Binary files /dev/null and b/assets/fonts/Arial_Bold.ttf differ diff --git a/assets/fonts/Arial_Bold_Italic.ttf b/assets/fonts/Arial_Bold_Italic.ttf new file mode 100644 index 0000000..52fd177 Binary files /dev/null and b/assets/fonts/Arial_Bold_Italic.ttf differ diff --git a/assets/fonts/Arial_Italic.ttf b/assets/fonts/Arial_Italic.ttf new file mode 100644 index 0000000..eac8b35 Binary files /dev/null and b/assets/fonts/Arial_Italic.ttf differ diff --git a/assets/fonts/unifont.ttf b/assets/fonts/unifont.ttf new file mode 100644 index 0000000..ec875c5 Binary files /dev/null and b/assets/fonts/unifont.ttf differ diff --git a/assets/sfml-icon-small.png b/assets/sfml-icon-small.png new file mode 100644 index 0000000..10aa70b Binary files /dev/null and b/assets/sfml-icon-small.png differ diff --git a/include/Vector4.hpp b/include/Vector4.hpp new file mode 100644 index 0000000..c47e9fc --- /dev/null +++ b/include/Vector4.hpp @@ -0,0 +1,479 @@ +//////////////////////////////////////////////////////////// +// +// This is a small addition to the SFML sf::Vector templates which +// adds a sf::Vector4(f, i, u) +// +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2016 Laurent Gomila (laurent@sfml-dev.org) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_VECTOR4_H +#define SFML_VECTOR4_H + +namespace sf { + //////////////////////////////////////////////////////////// + /// \brief Utility template class for manipulating + /// 2-dimensional vectors + /// + //////////////////////////////////////////////////////////// + template + class Vector4 { + public: + + //////////////////////////////////////////////////////////// + /// \brief Default constructor + /// + /// Creates a Vector4(0, 0). + /// + //////////////////////////////////////////////////////////// + Vector4(); + + //////////////////////////////////////////////////////////// + /// \brief Construct the vector from its coordinates + /// + /// \param X X coordinate + /// \param Y Y coordinate + /// + //////////////////////////////////////////////////////////// + Vector4(T X, T Y, T Z, T W); + + //////////////////////////////////////////////////////////// + /// \brief Construct the vector from another type of vector + /// + /// This constructor doesn't replace the copy constructor, + /// it's called only when U != T. + /// A call to this constructor will fail to compile if U + /// is not convertible to T. + /// + /// \param vector Vector to convert + /// + //////////////////////////////////////////////////////////// + template + explicit Vector4(const Vector4& vector); + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + T x; ///< X coordinate of the vector + T y; ///< Y coordinate of the vector + T z; ///< Z coordinate of the vector + T w; ///< W coordinate of the vector + }; + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of unary operator - + /// + /// \param right Vector to negate + /// + /// \return Memberwise opposite of the vector + /// + //////////////////////////////////////////////////////////// + template + Vector4 operator -(const Vector4& right); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator += + /// + /// This operator performs a memberwise addition of both vectors, + /// and assigns the result to \a left. + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a vector) + /// + /// \return Reference to \a left + /// + //////////////////////////////////////////////////////////// + template + Vector4& operator +=(Vector4& left, const Vector4& right); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator -= + /// + /// This operator performs a memberwise subtraction of both vectors, + /// and assigns the result to \a left. + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a vector) + /// + /// \return Reference to \a left + /// + //////////////////////////////////////////////////////////// + template + Vector4& operator -=(Vector4& left, const Vector4& right); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator + + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a vector) + /// + /// \return Memberwise addition of both vectors + /// + //////////////////////////////////////////////////////////// + template + Vector4 operator +(const Vector4& left, const Vector4& right); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator - + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a vector) + /// + /// \return Memberwise subtraction of both vectors + /// + //////////////////////////////////////////////////////////// + template + Vector4 operator -(const Vector4& left, const Vector4& right); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator * + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a scalar value) + /// + /// \return Memberwise multiplication by \a right + /// + //////////////////////////////////////////////////////////// + template + Vector4 operator *(const Vector4& left, T right); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator * + /// + /// \param left Left operand (a scalar value) + /// \param right Right operand (a vector) + /// + /// \return Memberwise multiplication by \a left + /// + //////////////////////////////////////////////////////////// + template + Vector4 operator *(T left, const Vector4& right); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator *= + /// + /// This operator performs a memberwise multiplication by \a right, + /// and assigns the result to \a left. + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a scalar value) + /// + /// \return Reference to \a left + /// + //////////////////////////////////////////////////////////// + template + Vector4& operator *=(Vector4& left, T right); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator / + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a scalar value) + /// + /// \return Memberwise division by \a right + /// + //////////////////////////////////////////////////////////// + template + Vector4 operator /(const Vector4& left, T right); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator /= + /// + /// This operator performs a memberwise division by \a right, + /// and assigns the result to \a left. + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a scalar value) + /// + /// \return Reference to \a left + /// + //////////////////////////////////////////////////////////// + template + Vector4& operator /=(Vector4& left, T right); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator == + /// + /// This operator compares strict equality between two vectors. + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a vector) + /// + /// \return True if \a left is equal to \a right + /// + //////////////////////////////////////////////////////////// + template + bool operator ==(const Vector4& left, const Vector4& right); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator != + /// + /// This operator compares strict difference between two vectors. + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a vector) + /// + /// \return True if \a left is not equal to \a right + /// + //////////////////////////////////////////////////////////// + template + bool operator !=(const Vector4& left, const Vector4& right); + + + + //////////////////////////////////////////////////////////// + template + inline Vector4::Vector4() : + x(0), + y(0), + z(0), + w(0){ + + } + + + //////////////////////////////////////////////////////////// + template + inline Vector4::Vector4(T X, T Y, T Z, T W) : + x(X), + y(Y), + z(Z), + w(W) { + + } + + + //////////////////////////////////////////////////////////// + template + template + inline Vector4::Vector4(const Vector4& vector) : + x(static_cast(vector.x)), + y(static_cast(vector.y)), + z(static_cast(vector.z)), + w(static_cast(vector.w)) { + } + + + //////////////////////////////////////////////////////////// + template + inline Vector4 operator -(const Vector4& right) { + return Vector4( + -right.x, + -right.y, + -right.z, + -right.w + ); + } + + + //////////////////////////////////////////////////////////// + template + inline Vector4& operator +=(Vector4& left, const Vector4& right) { + left.x += right.x; + left.y += right.y; + left.z += right.z; + left.w += right.w; + + return left; + } + + + //////////////////////////////////////////////////////////// + template + inline Vector4& operator -=(Vector4& left, const Vector4& right) { + left.x -= right.x; + left.y -= right.y; + left.z -= right.z; + left.w -= right.w; + + return left; + } + + + //////////////////////////////////////////////////////////// + template + inline Vector4 operator +(const Vector4& left, const Vector4& right) { + return Vector4( + left.x + right.x, + left.y + right.y, + left.z + right.z, + left.w + right.w + ); + } + + + //////////////////////////////////////////////////////////// + template + inline Vector4 operator -(const Vector4& left, const Vector4& right) { + return Vector4( + left.x - right.x, + left.y - right.y, + left.z - right.z, + left.w - right.w + ); + } + + + //////////////////////////////////////////////////////////// + template + inline Vector4 operator *(const Vector4& left, T right) { + return Vector4( + left.x * right, + left.y * right, + left.z * right, + left.w * right + ); + } + + + //////////////////////////////////////////////////////////// + template + inline Vector4 operator *(T left, const Vector4& right) { + return Vector4( + right.x * left, + right.y * left, + right.z * left, + right.w * left + ); + } + + + //////////////////////////////////////////////////////////// + template + inline Vector4& operator *=(Vector4& left, T right) { + left.x *= right; + left.y *= right; + left.z *= right; + left.w *= right; + + return left; + } + + + //////////////////////////////////////////////////////////// + template + inline Vector4 operator /(const Vector4& left, T right) { + return Vector4( + left.x / right, + left.y / right, + left.z / right, + left.w / right + ); + } + + + //////////////////////////////////////////////////////////// + template + inline Vector4& operator /=(Vector4& left, T right) { + left.x /= right; + left.y /= right; + left.z /= right; + left.w /= right; + + return left; + } + + + //////////////////////////////////////////////////////////// + template + inline bool operator ==(const Vector4& left, const Vector4& right) { + return + (left.x == right.x) && + (left.y == right.y) && + (left.z == right.z) && + (left.w == right.w);; + } + + + //////////////////////////////////////////////////////////// + template + inline bool operator !=(const Vector4& left, const Vector4& right) { + return + (left.x != right.x) || + (left.y != right.y) || + (left.z != right.z) || + (left.w != right.w); + } + + // Define the most common types + typedef Vector4 Vector4i; + typedef Vector4 Vector4u; + typedef Vector4 Vector4f; + +} // namespace sf + + +#endif // SFML_Vector4_HPP + + + //////////////////////////////////////////////////////////// + /// \class sf::Vector4 + /// \ingroup system + /// + /// sf::Vector4 is a simple class that defines a mathematical + /// vector with two coordinates (x and y). It can be used to + /// represent anything that has two dimensions: a size, a point, + /// a velocity, etc. + /// + /// The template parameter T is the type of the coordinates. It + /// can be any type that supports arithmetic operations (+, -, /, *) + /// and comparisons (==, !=), for example int or float. + /// + /// You generally don't have to care about the templated form (sf::Vector4), + /// the most common specializations have special typedefs: + /// \li sf::Vector4 is sf::Vector4f + /// \li sf::Vector4 is sf::Vector4i + /// \li sf::Vector4 is sf::Vector4u + /// + /// The sf::Vector4 class has a small and simple interface, its x and y members + /// can be accessed directly (there are no accessors like setX(), getX()) and it + /// contains no mathematical function like dot product, cross product, length, etc. + /// + /// Usage example: + /// \code + /// sf::Vector4f v1(16.5f, 24.f); + /// v1.x = 18.2f; + /// float y = v1.y; + /// + /// sf::Vector4f v2 = v1 * 5.f; + /// sf::Vector4 + /// v3 = v1 + v2; + /// + /// bool different = (v2 != v3); + /// \endcode + /// + /// Note: for 3-dimensional vectors, see sf::Vector3. + /// + //////////////////////////////////////////////////////////// diff --git a/include/util.hpp b/include/util.hpp new file mode 100644 index 0000000..ecce740 --- /dev/null +++ b/include/util.hpp @@ -0,0 +1,331 @@ +#pragma once +#include +#include +#include "Vector4.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +const double PI = 3.141592653589793238463; +const float PI_F = 3.14159265358979f; + +struct fps_counter { +public: + fps_counter() : + backdrop(sf::Vector2f(200, 100)), vertex_array(sf::LinesStrip) { + + backdrop.setFillColor(sf::Color(0x0000003F)); + + if(!f.loadFromFile("../assets/fonts/Arial.ttf")){ + std::cout << "couldn't find the fall back Arial font in ../assets/fonts/" << std::endl; + } else { + t.setFont(f); + t.setCharacterSize(18); + t.setColor(sf::Color::White); + } + } + + void frame(double delta_time){ + // Apply 100 units of smoothing + if (frame_count == 100){ + frame_count = 0; + fps_average = 0; + } + frame_count++; + fps_average += (delta_time - fps_average) / frame_count; + } + + void flip_units() { + if (milliseconds) + milliseconds = false; + else + milliseconds = true; + } + + void draw(sf::RenderWindow *r){ + + r->draw(backdrop); + + if (vertex_position == 200) + vertex_position = 0; + + sf::Vector2f origin = backdrop.getPosition(); + sf::Vector2f point = origin + sf::Vector2f(vertex_position, backdrop.getSize().y - (1.0/fps_average)); + + if (vertex_array.getVertexCount() < 200) + vertex_array.append(sf::Vertex(point, sf::Color::Red)); + else + vertex_array[vertex_position] = sf::Vertex(point, sf::Color::Red); + + r->draw(vertex_array); + + vertex_position++; + + std::string out; + + if (milliseconds) + out = std::to_string(fps_average); + else + out = std::to_string(floor(1 / fps_average)); + + t.setString(out); + + + + r->draw(t); + } + +private: + + sf::RectangleShape backdrop; + sf::VertexArray vertex_array; + + sf::Font f; + sf::Text t; + + int frame_count = 0; + double fps_average = 0; + bool milliseconds = false; + + int vertex_position = 0; +}; + +struct debug_text { +public: + debug_text(int slot, int pixel_spacing, void* data_, std::string prefix_) : data(data_), prefix(prefix_) { + if (!f.loadFromFile("../assets/fonts/Arial.ttf")) { + std::cout << "couldn't find the fall back Arial font in ../assets/fonts/" << std::endl; + } + else { + t.setFont(f); + t.setCharacterSize(20); + t.setPosition(static_cast(20), static_cast(slot * pixel_spacing)); + } + + } + + void draw(sf::RenderWindow *r) { + t.setString(prefix + std::to_string(*(float*)data)); + r->draw(t); + } + +private: + void* data; + std::string prefix; + sf::Font f; + sf::Text t; + +}; + +inline sf::Vector3f SphereToCart(sf::Vector2f i) { + + auto r = sf::Vector3f( + (1 * sin(i.y) * cos(i.x)), + (1 * sin(i.y) * sin(i.x)), + (1 * cos(i.y)) + ); + return r; +}; + +inline sf::Vector3f SphereToCart(sf::Vector3f i) { + + auto r = sf::Vector3f( + (i.x * sin(i.z) * cos(i.y)), + (i.x * sin(i.z) * sin(i.y)), + (i.x * cos(i.z)) + ); + return r; +}; + + +inline sf::Vector3f CartToSphere(sf::Vector3f in) { + + auto r = sf::Vector3f( + sqrt(in.x * in.x + in.y * in.y + in.z * in.z), + atan(in.y / in.x), + atan(sqrt(in.x * in.x + in.y * in.y) / in.z) + ); + return r; +}; + +inline sf::Vector2f CartToNormalizedSphere(sf::Vector3f in) { + + auto r = sf::Vector2f( + atan2(sqrt(in.x * in.x + in.y * in.y), in.z), + atan2(in.y, in.x) + ); + + return r; +} + +inline sf::Vector3f FixOrigin(sf::Vector3f base, sf::Vector3f head) { + return head - base; +} + + +inline sf::Vector3f Normalize(sf::Vector3f in) { + + float multiplier = sqrt(in.x * in.x + in.y * in.y + in.z * in.z); + auto r = sf::Vector3f( + in.x / multiplier, + in.y / multiplier, + in.z / multiplier + ); + return r; + +} + + +inline float DotProduct(sf::Vector3f a, sf::Vector3f b){ + return a.x * b.x + a.y * b.y + a.z * b.z; +} + +inline float Magnitude(sf::Vector3f in){ + return sqrt(in.x * in.x + in.y * in.y + in.z * in.z); +} + +inline float AngleBetweenVectors(sf::Vector3f a, sf::Vector3f b){ + return acos(DotProduct(a, b) / (Magnitude(a) * Magnitude(b))); +} + +inline float DistanceBetweenPoints(sf::Vector3f a, sf::Vector3f b) { + return sqrt(DotProduct(a, b)); +} + +inline float DegreesToRadians(float in) { + return static_cast(in * PI / 180.0f); +} + +inline float RadiansToDegrees(float in) { + return static_cast(in * 180.0f / PI); +} + +inline std::string read_file(std::string file_name){ + std::ifstream input_file(file_name); + + if (!input_file.is_open()){ + std::cout << file_name << " could not be opened" << std::endl; + return ""; + } + + std::stringstream buf; + buf << input_file.rdbuf(); + input_file.close(); + return buf.str(); +} + +inline void PrettyPrintUINT64(uint64_t i, std::stringstream* ss) { + + *ss << "[" << std::bitset<15>(i) << "]"; + *ss << "[" << std::bitset<1>(i >> 15) << "]"; + *ss << "[" << std::bitset<8>(i >> 16) << "]"; + *ss << "[" << std::bitset<8>(i >> 24) << "]"; + *ss << "[" << std::bitset<32>(i >> 32) << "]"; + +} + +inline void PrettyPrintUINT64(uint64_t i) { + + std::cout << "[" << std::bitset<15>(i) << "]"; + std::cout << "[" << std::bitset<1>(i >> 15) << "]"; + std::cout << "[" << std::bitset<8>(i >> 16) << "]"; + std::cout << "[" << std::bitset<8>(i >> 24) << "]"; + std::cout << "[" << std::bitset<32>(i >> 32) << "]" << std::endl; + +} + +inline void DumpLog(std::stringstream* ss, std::string file_name) { + + std::ofstream log_file; + log_file.open(file_name); + + log_file << ss->str(); + + log_file.close(); + +} + +inline std::string sfml_get_input(sf::RenderWindow *window) { + + std::stringstream ss; + + sf::Event event; + while (window->pollEvent(event)) { + if (event.type == sf::Event::TextEntered) { + ss << event.text.unicode; + } + + else if (event.type == sf::Event::KeyPressed) { + if (event.key.code == sf::Keyboard::Return) { + return ss.str(); + } + } + } +} + +inline std::vector sfml_get_float_input(sf::RenderWindow *window) { + + std::stringstream ss; + + sf::Event event; + while (true) { + + if (window->pollEvent(event)) { + + if (event.type == sf::Event::TextEntered) { + if (event.text.unicode > 47 && event.text.unicode < 58 || event.text.unicode == 32) + ss << static_cast(event.text.unicode); + } + + else if (event.type == sf::Event::KeyPressed) { + + if (event.key.code == sf::Keyboard::Return) { + break; + } + } + } + } + + std::istream_iterator begin(ss); + std::istream_iterator end; + std::vector vstrings(begin, end); + + std::vector ret; + + for (auto i: vstrings) { + ret.push_back(std::stof(i)); + } + + return ret; + +} + +inline int count_bits(int32_t v) { + + v = v - ((v >> 1) & 0x55555555); // reuse input as temporary + v = (v & 0x33333333) + ((v >> 2) & 0x33333333); // temp + return (((v + (v >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24; // count +} + +inline int count_bits(int64_t v) { + + int32_t left = (int32_t)(v); + int32_t right = (int32_t)(v >> 32); + + left = left - ((left >> 1) & 0x55555555); // reuse input as temporary + left = (left & 0x33333333) + ((left >> 2) & 0x33333333); // temp + left = ((left + (left >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; // count + + right = right - ((right >> 1) & 0x55555555); // reuse input as temporary + right = (right & 0x33333333) + ((right >> 2) & 0x33333333); // temp + right = ((right + (right >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; // count + + return left + right; +} diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..5ad998b --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,137 @@ + +#include +#include +#include +#include +#include "util.hpp" +#include +#include + +float elap_time() { + static std::chrono::time_point start; + static bool started = false; + + if (!started) { + start = std::chrono::system_clock::now(); + started = true; + } + + std::chrono::time_point now = std::chrono::system_clock::now(); + std::chrono::duration elapsed_time = now - start; + return static_cast(elapsed_time.count()); +} + +const int WINDOW_X = 1920; +const int WINDOW_Y = 1080; + +float scale(float valueIn, float origMin, float origMax, float scaledMin, float scaledMax) { + return ((scaledMax - scaledMin) * (valueIn - origMin) / (origMax - origMin)) + scaledMin; +} + +void func(int id, int count, sf::Uint8* pixels) { + + for (int pixel_x = 0; pixel_x < WINDOW_X; pixel_x++) { + + for (int pixel_y = (WINDOW_Y * ((float)id / count)); pixel_y < (WINDOW_Y * ((float)(id + 1) / count)); pixel_y++) { + + float y0 = scale(pixel_y, 0, WINDOW_Y, -1.0f, 1.0f); + float x0 = scale(pixel_x, 0, WINDOW_X, -2.0f, 1.0f); + + float x = 0.0; + float y = 0.0; + + int iteration_count = 0; + int interation_threshold = 1000; + + while (pow(x, 2) + pow(y, 2) < pow(2, 2) && iteration_count < interation_threshold) { + float x_temp = pow(x, 2) - pow(y, 2) + x0; + y = 2 * x * y + y0; + x = x_temp; + iteration_count++; + } + + sf::Color c(0, 0, scale(iteration_count, 0, 1000, 0, 255), 255); + int val = scale(iteration_count, 0, 1000, 0, pow(2, 24)); + + pixels[(pixel_y * WINDOW_X + pixel_x) * 4 + 0] = val & 0xff; + pixels[(pixel_y * WINDOW_X + pixel_x) * 4 + 1] = (val >> 8) & 0xff; + pixels[(pixel_y * WINDOW_X + pixel_x) * 4 + 2] = (val >> 16) & 0xff; + pixels[(pixel_y * WINDOW_X + pixel_x) * 4 + 3] = 200; + //memcpy(&pixels[(pixel_y * pixel_x + pixel_y) * 4], (void*)&c, sizeof(c)); + } + } +} + +int main() { + + std::mt19937 rng(time(NULL)); + std::uniform_int_distribution rgen(100, 400); + + sf::RenderWindow window(sf::VideoMode(WINDOW_X, WINDOW_Y), "quick-sfml-template"); + window.setFramerateLimit(60); + + + float physic_step = 0.166f; + float physic_time = 0.0f; + + double frame_time = 0.0, elapsed_time = 0.0, delta_time = 0.0, accumulator_time = 0.0, current_time = 0.0; + fps_counter fps; + + sf::Uint8 *pixels = new sf::Uint8[WINDOW_X * WINDOW_Y * 4]; + + sf::Sprite viewport_sprite; + sf::Texture viewport_texture; + viewport_texture.create(WINDOW_X, WINDOW_Y); + viewport_texture.update(pixels); + viewport_sprite.setTexture(viewport_texture); + + + std::vector thread_pool; + + for (int i = 0; i < 10; i++) { + thread_pool.emplace_back(std::thread(func, i, 10, pixels)); + } + + for (auto &t: thread_pool) { + t.join(); + } + + viewport_texture.update(pixels); + + while (window.isOpen()) + { + sf::Event event; // Handle input + while (window.pollEvent(event)) { + if (event.type == sf::Event::Closed) { + window.close(); + } + } + + elapsed_time = elap_time(); // Handle time + delta_time = elapsed_time - current_time; + current_time = elapsed_time; + if (delta_time > 0.02f) + delta_time = 0.02f; + accumulator_time += delta_time; + + while (accumulator_time >= physic_step) { // While the frame has sim time, update + + accumulator_time -= physic_step; + physic_time += physic_step; + + // Do physics at 60fps + } + + window.clear(sf::Color::White); + + window.draw(viewport_sprite); + + fps.draw(&window); + fps.frame(delta_time); + + window.display(); + + } + return 0; + +} \ No newline at end of file