Added a quick printout of the hardware info. Running into a problem choosing between platforms, going to abstract CL out into it's own class and hide all that logic

master
MitchellHansen 8 years ago
parent 3c9b39f682
commit edd8075afb

94
.gitignore vendored

@ -1,47 +1,47 @@
# Compiled source # # Compiled source #
################### ###################
*.com *.com
*.class *.class
*.dll *.dll
*.exe *.exe
*.o *.o
*.so *.so
# Packages # # Packages #
############ ############
# it's better to unpack these files and commit the raw source # it's better to unpack these files and commit the raw source
# git has its own built in compression methods # git has its own built in compression methods
*.7z *.7z
*.dmg *.dmg
*.gz *.gz
*.iso *.iso
*.jar *.jar
*.rar *.rar
*.tar *.tar
*.zip *.zip
# Logs and databases # # Logs and databases #
###################### ######################
*.log *.log
*.sql *.sql
*.sqlite *.sqlite
# OS generated files # # OS generated files #
###################### ######################
.DS_Store .DS_Store
.DS_Store? .DS_Store?
._* ._*
.Spotlight-V100 .Spotlight-V100
.Trashes .Trashes
ehthumbs.db ehthumbs.db
Thumbs.db Thumbs.db
# CMake Generated Files # # CMake Generated Files #
######################### #########################
CMakeCache.txt CMakeCache.txt
CMakeFiles CMakeFiles
CMakeScripts CMakeScripts
Makefile Makefile
cmake_install.cmake cmake_install.cmake
install_manifest.txt install_manifest.txt
CTestTestfile.cmake CTestTestfile.cmake

@ -1,41 +1,41 @@
# Check versions # Check versions
message(STATUS "CMake version: ${CMAKE_VERSION}") message(STATUS "CMake version: ${CMAKE_VERSION}")
cmake_minimum_required(VERSION 3.1) cmake_minimum_required(VERSION 3.1)
# Set the project name # Set the project name
set(PNAME Game) set(PNAME Game)
project(${PNAME}) project(${PNAME})
# Set up variables, and find SFML # Set up variables, and find SFML
#set(SFML_ROOT root CACHE STRING "User specified path") #set(SFML_ROOT root CACHE STRING "User specified path")
set(SFML_COMPONENTS graphics window system network audio) set(SFML_COMPONENTS graphics window system network audio)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
find_package(SFML 2.1 COMPONENTS ${SFML_COMPONENTS} REQUIRED) find_package(SFML 2.1 COMPONENTS ${SFML_COMPONENTS} REQUIRED)
message(STATUS "SFML found: ${SFML_FOUND}") message(STATUS "SFML found: ${SFML_FOUND}")
# Find OpenCL # Find OpenCL
find_package( OpenCL REQUIRED ) find_package( OpenCL REQUIRED )
message(STATUS "OpenCL found: ${OPENCL_FOUND}") message(STATUS "OpenCL found: ${OPENCL_FOUND}")
# Find OpenGL # Find OpenGL
find_package( OpenGL REQUIRED) find_package( OpenGL REQUIRED)
message(STATUS "OpenGL found: ${OPENGL_FOUND}") message(STATUS "OpenGL found: ${OPENGL_FOUND}")
# Include the directories for the main program, GL, CL and SFML's headers # Include the directories for the main program, GL, CL and SFML's headers
include_directories(${SFML_INCLUDE_DIR}) include_directories(${SFML_INCLUDE_DIR})
include_directories(${OpenCL_INCLUDE_DIRS}) include_directories(${OpenCL_INCLUDE_DIRS})
include_directories(${OpenGL_INCLUDE_DIRS}) include_directories(${OpenGL_INCLUDE_DIRS})
include_directories(include) include_directories(include)
# Set the .cpp sources # Set the .cpp sources
file(GLOB SOURCES "src/*.cpp") file(GLOB SOURCES "src/*.cpp")
add_executable(${PNAME} ${SOURCES}) add_executable(${PNAME} ${SOURCES})
# Link CL, GL, and SFML # Link CL, GL, and SFML
target_link_libraries (${PNAME} ${SFML_LIBRARIES} ${SFML_DEPENDENCIES}) target_link_libraries (${PNAME} ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})
target_link_libraries (${PNAME} ${OpenCL_LIBRARY}) target_link_libraries (${PNAME} ${OpenCL_LIBRARY})
target_link_libraries (${PNAME} ${OPENGL_LIBRARIES}) target_link_libraries (${PNAME} ${OPENGL_LIBRARIES})
# Setup to use C++11 # Setup to use C++11
set_property(TARGET ${PNAME} PROPERTY CXX_STANDARD 11) # Use C++11 set_property(TARGET ${PNAME} PROPERTY CXX_STANDARD 11) # Use C++11

@ -1,369 +1,369 @@
# This script locates the SFML library # This script locates the SFML library
# ------------------------------------ # ------------------------------------
# #
# Usage # Usage
# ----- # -----
# #
# When you try to locate the SFML libraries, you must specify which modules you want to use (system, window, graphics, network, audio, main). # 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. # If none is given, the SFML_LIBRARIES variable will be empty and you'll end up linking to nothing.
# example: # example:
# find_package(SFML COMPONENTS graphics window system) # find the graphics, window and system modules # 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. # 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). # If nothing is specified, the version won't be checked (i.e. any version will be accepted).
# example: # example:
# find_package(SFML COMPONENTS ...) # no specific version required # find_package(SFML COMPONENTS ...) # no specific version required
# find_package(SFML 2 COMPONENTS ...) # any 2.x version # find_package(SFML 2 COMPONENTS ...) # any 2.x version
# find_package(SFML 2.4 COMPONENTS ...) # version 2.4 or greater # 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, # 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 ...). # 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 # 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 # additional variables are defined: SFML_XXX_DEPENDENCIES and SFML_DEPENDENCIES (see their detailed
# description below). # description below).
# In case of static linking, the SFML_STATIC macro will also be defined by this script. # In case of static linking, the SFML_STATIC macro will also be defined by this script.
# example: # example:
# set(SFML_STATIC_LIBRARIES TRUE) # set(SFML_STATIC_LIBRARIES TRUE)
# find_package(SFML 2 COMPONENTS network system) # 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 # 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. # 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 # Moreover, keep in mind that SFML frameworks are only available as release libraries unlike dylibs which
# are available for both release and debug modes. # 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 # 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. # to tell CMake where SFML is.
# #
# Output # Output
# ------ # ------
# #
# This script defines the following variables: # This script defines the following variables:
# - For each specified module XXX (system, window, graphics, network, audio, main): # - 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_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_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_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_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_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_LIBRARIES: the list of all libraries corresponding to the required modules
# - SFML_FOUND: true if all the required modules are found # - 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_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 # - SFML_DEPENDENCIES: the list of libraries SFML depends on, in case of static linking
# #
# example: # example:
# find_package(SFML 2 COMPONENTS system window graphics audio REQUIRED) # find_package(SFML 2 COMPONENTS system window graphics audio REQUIRED)
# include_directories(${SFML_INCLUDE_DIR}) # include_directories(${SFML_INCLUDE_DIR})
# add_executable(myapp ...) # add_executable(myapp ...)
# target_link_libraries(myapp ${SFML_LIBRARIES}) # target_link_libraries(myapp ${SFML_LIBRARIES})
# define the SFML_STATIC macro if static build was chosen # define the SFML_STATIC macro if static build was chosen
if(SFML_STATIC_LIBRARIES) if(SFML_STATIC_LIBRARIES)
add_definitions(-DSFML_STATIC) add_definitions(-DSFML_STATIC)
endif() endif()
# define the list of search paths for headers and libraries # define the list of search paths for headers and libraries
set(FIND_SFML_PATHS set(FIND_SFML_PATHS
${SFML_ROOT} ${SFML_ROOT}
$ENV{SFML_ROOT} $ENV{SFML_ROOT}
~/Library/Frameworks ~/Library/Frameworks
/Library/Frameworks /Library/Frameworks
/usr/local /usr/local
/usr /usr
/sw /sw
/opt/local /opt/local
/opt/csw /opt/csw
/opt) /opt)
# find the SFML include directory # find the SFML include directory
find_path(SFML_INCLUDE_DIR SFML/Config.hpp find_path(SFML_INCLUDE_DIR SFML/Config.hpp
PATH_SUFFIXES include PATH_SUFFIXES include
PATHS ${FIND_SFML_PATHS}) PATHS ${FIND_SFML_PATHS})
# check the version number # check the version number
set(SFML_VERSION_OK TRUE) set(SFML_VERSION_OK TRUE)
if(SFML_FIND_VERSION AND SFML_INCLUDE_DIR) if(SFML_FIND_VERSION AND SFML_INCLUDE_DIR)
# extract the major and minor version numbers from SFML/Config.hpp # extract the major and minor version numbers from SFML/Config.hpp
# we have to handle framework a little bit differently: # we have to handle framework a little bit differently:
if("${SFML_INCLUDE_DIR}" MATCHES "SFML.framework") if("${SFML_INCLUDE_DIR}" MATCHES "SFML.framework")
set(SFML_CONFIG_HPP_INPUT "${SFML_INCLUDE_DIR}/Headers/Config.hpp") set(SFML_CONFIG_HPP_INPUT "${SFML_INCLUDE_DIR}/Headers/Config.hpp")
else() else()
set(SFML_CONFIG_HPP_INPUT "${SFML_INCLUDE_DIR}/SFML/Config.hpp") set(SFML_CONFIG_HPP_INPUT "${SFML_INCLUDE_DIR}/SFML/Config.hpp")
endif() endif()
FILE(READ "${SFML_CONFIG_HPP_INPUT}" SFML_CONFIG_HPP_CONTENTS) 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_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_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}") 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]+$") if (NOT "${SFML_VERSION_PATCH}" MATCHES "^[0-9]+$")
set(SFML_VERSION_PATCH 0) set(SFML_VERSION_PATCH 0)
endif() endif()
math(EXPR SFML_REQUESTED_VERSION "${SFML_FIND_VERSION_MAJOR} * 10000 + ${SFML_FIND_VERSION_MINOR} * 100 + ${SFML_FIND_VERSION_PATCH}") 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 we could extract them, compare with the requested version number
if (SFML_VERSION_MAJOR) if (SFML_VERSION_MAJOR)
# transform version numbers to an integer # transform version numbers to an integer
math(EXPR SFML_VERSION "${SFML_VERSION_MAJOR} * 10000 + ${SFML_VERSION_MINOR} * 100 + ${SFML_VERSION_PATCH}") math(EXPR SFML_VERSION "${SFML_VERSION_MAJOR} * 10000 + ${SFML_VERSION_MINOR} * 100 + ${SFML_VERSION_PATCH}")
# compare them # compare them
if(SFML_VERSION LESS SFML_REQUESTED_VERSION) if(SFML_VERSION LESS SFML_REQUESTED_VERSION)
set(SFML_VERSION_OK FALSE) set(SFML_VERSION_OK FALSE)
endif() endif()
else() else()
# SFML version is < 2.0 # SFML version is < 2.0
if (SFML_REQUESTED_VERSION GREATER 10900) if (SFML_REQUESTED_VERSION GREATER 10900)
set(SFML_VERSION_OK FALSE) set(SFML_VERSION_OK FALSE)
set(SFML_VERSION_MAJOR 1) set(SFML_VERSION_MAJOR 1)
set(SFML_VERSION_MINOR x) set(SFML_VERSION_MINOR x)
set(SFML_VERSION_PATCH x) set(SFML_VERSION_PATCH x)
endif() endif()
endif() endif()
endif() endif()
# find the requested modules # find the requested modules
set(SFML_FOUND TRUE) # will be set to false if one of the required modules is not found 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}) foreach(FIND_SFML_COMPONENT ${SFML_FIND_COMPONENTS})
string(TOLOWER ${FIND_SFML_COMPONENT} FIND_SFML_COMPONENT_LOWER) string(TOLOWER ${FIND_SFML_COMPONENT} FIND_SFML_COMPONENT_LOWER)
string(TOUPPER ${FIND_SFML_COMPONENT} FIND_SFML_COMPONENT_UPPER) string(TOUPPER ${FIND_SFML_COMPONENT} FIND_SFML_COMPONENT_UPPER)
set(FIND_SFML_COMPONENT_NAME sfml-${FIND_SFML_COMPONENT_LOWER}) set(FIND_SFML_COMPONENT_NAME sfml-${FIND_SFML_COMPONENT_LOWER})
# no suffix for sfml-main, it is always a static library # no suffix for sfml-main, it is always a static library
if(FIND_SFML_COMPONENT_LOWER STREQUAL "main") if(FIND_SFML_COMPONENT_LOWER STREQUAL "main")
# release library # release library
find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE
NAMES ${FIND_SFML_COMPONENT_NAME} NAMES ${FIND_SFML_COMPONENT_NAME}
PATH_SUFFIXES lib64 lib PATH_SUFFIXES lib64 lib
PATHS ${FIND_SFML_PATHS}) PATHS ${FIND_SFML_PATHS})
# debug library # debug library
find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG
NAMES ${FIND_SFML_COMPONENT_NAME}-d NAMES ${FIND_SFML_COMPONENT_NAME}-d
PATH_SUFFIXES lib64 lib PATH_SUFFIXES lib64 lib
PATHS ${FIND_SFML_PATHS}) PATHS ${FIND_SFML_PATHS})
else() else()
# static release library # static release library
find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_RELEASE find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_RELEASE
NAMES ${FIND_SFML_COMPONENT_NAME}-s NAMES ${FIND_SFML_COMPONENT_NAME}-s
PATH_SUFFIXES lib64 lib PATH_SUFFIXES lib64 lib
PATHS ${FIND_SFML_PATHS}) PATHS ${FIND_SFML_PATHS})
# static debug library # static debug library
find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_DEBUG find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_DEBUG
NAMES ${FIND_SFML_COMPONENT_NAME}-s-d NAMES ${FIND_SFML_COMPONENT_NAME}-s-d
PATH_SUFFIXES lib64 lib PATH_SUFFIXES lib64 lib
PATHS ${FIND_SFML_PATHS}) PATHS ${FIND_SFML_PATHS})
# dynamic release library # dynamic release library
find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_RELEASE find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_RELEASE
NAMES ${FIND_SFML_COMPONENT_NAME} NAMES ${FIND_SFML_COMPONENT_NAME}
PATH_SUFFIXES lib64 lib PATH_SUFFIXES lib64 lib
PATHS ${FIND_SFML_PATHS}) PATHS ${FIND_SFML_PATHS})
# dynamic debug library # dynamic debug library
find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_DEBUG find_library(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_DEBUG
NAMES ${FIND_SFML_COMPONENT_NAME}-d NAMES ${FIND_SFML_COMPONENT_NAME}-d
PATH_SUFFIXES lib64 lib PATH_SUFFIXES lib64 lib
PATHS ${FIND_SFML_PATHS}) PATHS ${FIND_SFML_PATHS})
# choose the entries that fit the requested link type # choose the entries that fit the requested link type
if(SFML_STATIC_LIBRARIES) if(SFML_STATIC_LIBRARIES)
if(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_RELEASE) 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}) set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_RELEASE})
endif() endif()
if(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_DEBUG) 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}) set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_DEBUG})
endif() endif()
else() else()
if(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_RELEASE) 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}) set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_RELEASE})
endif() endif()
if(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_DEBUG) 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}) set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_DEBUG})
endif() endif()
endif() endif()
endif() endif()
if (SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG OR SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE) if (SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG OR SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE)
# library found # library found
set(SFML_${FIND_SFML_COMPONENT_UPPER}_FOUND TRUE) set(SFML_${FIND_SFML_COMPONENT_UPPER}_FOUND TRUE)
# if both are found, set SFML_XXX_LIBRARY to contain both # 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) 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} set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY debug ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG}
optimized ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE}) optimized ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE})
endif() endif()
# if only one debug/release variant is found, set the other to be equal to the found one # 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) if (SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG AND NOT SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE)
# debug and not 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_RELEASE ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG})
set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG}) set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG})
endif() endif()
if (SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE AND NOT SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG) if (SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE AND NOT SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG)
# release and not 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_DEBUG ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE})
set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE}) set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY ${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE})
endif() endif()
else() else()
# library not found # library not found
set(SFML_FOUND FALSE) set(SFML_FOUND FALSE)
set(SFML_${FIND_SFML_COMPONENT_UPPER}_FOUND FALSE) set(SFML_${FIND_SFML_COMPONENT_UPPER}_FOUND FALSE)
set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY "") set(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY "")
set(FIND_SFML_MISSING "${FIND_SFML_MISSING} SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY") set(FIND_SFML_MISSING "${FIND_SFML_MISSING} SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY")
endif() endif()
# mark as advanced # mark as advanced
MARK_AS_ADVANCED(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY MARK_AS_ADVANCED(SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY
SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_RELEASE
SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DEBUG
SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_RELEASE SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_RELEASE
SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_DEBUG SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_STATIC_DEBUG
SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_RELEASE SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_RELEASE
SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_DEBUG) SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY_DYNAMIC_DEBUG)
# add to the global list of libraries # add to the global list of libraries
set(SFML_LIBRARIES ${SFML_LIBRARIES} "${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY}") set(SFML_LIBRARIES ${SFML_LIBRARIES} "${SFML_${FIND_SFML_COMPONENT_UPPER}_LIBRARY}")
endforeach() endforeach()
# in case of static linking, we must also define the list of all the dependencies of SFML libraries # in case of static linking, we must also define the list of all the dependencies of SFML libraries
if(SFML_STATIC_LIBRARIES) if(SFML_STATIC_LIBRARIES)
# detect the OS # detect the OS
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(FIND_SFML_OS_WINDOWS 1) set(FIND_SFML_OS_WINDOWS 1)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(FIND_SFML_OS_LINUX 1) set(FIND_SFML_OS_LINUX 1)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
set(FIND_SFML_OS_FREEBSD 1) set(FIND_SFML_OS_FREEBSD 1)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(FIND_SFML_OS_MACOSX 1) set(FIND_SFML_OS_MACOSX 1)
endif() endif()
# start with an empty list # start with an empty list
set(SFML_DEPENDENCIES) set(SFML_DEPENDENCIES)
set(FIND_SFML_DEPENDENCIES_NOTFOUND) set(FIND_SFML_DEPENDENCIES_NOTFOUND)
# macro that searches for a 3rd-party library # macro that searches for a 3rd-party library
macro(find_sfml_dependency output friendlyname) macro(find_sfml_dependency output friendlyname)
# No lookup in environment variables (PATH on Windows), as they may contain wrong library versions # 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) find_library(${output} NAMES ${ARGN} PATHS ${FIND_SFML_PATHS} PATH_SUFFIXES lib NO_SYSTEM_ENVIRONMENT_PATH)
if(${${output}} STREQUAL "${output}-NOTFOUND") if(${${output}} STREQUAL "${output}-NOTFOUND")
unset(output) unset(output)
set(FIND_SFML_DEPENDENCIES_NOTFOUND "${FIND_SFML_DEPENDENCIES_NOTFOUND} ${friendlyname}") set(FIND_SFML_DEPENDENCIES_NOTFOUND "${FIND_SFML_DEPENDENCIES_NOTFOUND} ${friendlyname}")
endif() endif()
endmacro() endmacro()
# sfml-system # sfml-system
list(FIND SFML_FIND_COMPONENTS "system" FIND_SFML_SYSTEM_COMPONENT) list(FIND SFML_FIND_COMPONENTS "system" FIND_SFML_SYSTEM_COMPONENT)
if(NOT ${FIND_SFML_SYSTEM_COMPONENT} EQUAL -1) if(NOT ${FIND_SFML_SYSTEM_COMPONENT} EQUAL -1)
# update the list -- these are only system libraries, no need to find them # 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) if(FIND_SFML_OS_LINUX OR FIND_SFML_OS_FREEBSD OR FIND_SFML_OS_MACOSX)
set(SFML_SYSTEM_DEPENDENCIES "pthread") set(SFML_SYSTEM_DEPENDENCIES "pthread")
endif() endif()
if(FIND_SFML_OS_LINUX) if(FIND_SFML_OS_LINUX)
set(SFML_SYSTEM_DEPENDENCIES ${SFML_SYSTEM_DEPENDENCIES} "rt") set(SFML_SYSTEM_DEPENDENCIES ${SFML_SYSTEM_DEPENDENCIES} "rt")
endif() endif()
if(FIND_SFML_OS_WINDOWS) if(FIND_SFML_OS_WINDOWS)
set(SFML_SYSTEM_DEPENDENCIES "winmm") set(SFML_SYSTEM_DEPENDENCIES "winmm")
endif() endif()
set(SFML_DEPENDENCIES ${SFML_SYSTEM_DEPENDENCIES} ${SFML_DEPENDENCIES}) set(SFML_DEPENDENCIES ${SFML_SYSTEM_DEPENDENCIES} ${SFML_DEPENDENCIES})
endif() endif()
# sfml-network # sfml-network
list(FIND SFML_FIND_COMPONENTS "network" FIND_SFML_NETWORK_COMPONENT) list(FIND SFML_FIND_COMPONENTS "network" FIND_SFML_NETWORK_COMPONENT)
if(NOT ${FIND_SFML_NETWORK_COMPONENT} EQUAL -1) if(NOT ${FIND_SFML_NETWORK_COMPONENT} EQUAL -1)
# update the list -- these are only system libraries, no need to find them # update the list -- these are only system libraries, no need to find them
if(FIND_SFML_OS_WINDOWS) if(FIND_SFML_OS_WINDOWS)
set(SFML_NETWORK_DEPENDENCIES "ws2_32") set(SFML_NETWORK_DEPENDENCIES "ws2_32")
endif() endif()
set(SFML_DEPENDENCIES ${SFML_NETWORK_DEPENDENCIES} ${SFML_DEPENDENCIES}) set(SFML_DEPENDENCIES ${SFML_NETWORK_DEPENDENCIES} ${SFML_DEPENDENCIES})
endif() endif()
# sfml-window # sfml-window
list(FIND SFML_FIND_COMPONENTS "window" FIND_SFML_WINDOW_COMPONENT) list(FIND SFML_FIND_COMPONENTS "window" FIND_SFML_WINDOW_COMPONENT)
if(NOT ${FIND_SFML_WINDOW_COMPONENT} EQUAL -1) if(NOT ${FIND_SFML_WINDOW_COMPONENT} EQUAL -1)
# find libraries # find libraries
if(FIND_SFML_OS_LINUX OR FIND_SFML_OS_FREEBSD) if(FIND_SFML_OS_LINUX OR FIND_SFML_OS_FREEBSD)
find_sfml_dependency(X11_LIBRARY "X11" X11) find_sfml_dependency(X11_LIBRARY "X11" X11)
find_sfml_dependency(LIBXCB_LIBRARIES "XCB" xcb libxcb) find_sfml_dependency(LIBXCB_LIBRARIES "XCB" xcb libxcb)
find_sfml_dependency(X11_XCB_LIBRARY "X11-xcb" X11-xcb libX11-xcb) 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_RANDR_LIBRARY "xcb-randr" xcb-randr libxcb-randr)
find_sfml_dependency(XCB_IMAGE_LIBRARY "xcb-image" xcb-image libxcb-image) find_sfml_dependency(XCB_IMAGE_LIBRARY "xcb-image" xcb-image libxcb-image)
endif() endif()
if(FIND_SFML_OS_LINUX) if(FIND_SFML_OS_LINUX)
find_sfml_dependency(UDEV_LIBRARIES "UDev" udev libudev) find_sfml_dependency(UDEV_LIBRARIES "UDev" udev libudev)
endif() endif()
# update the list # update the list
if(FIND_SFML_OS_WINDOWS) if(FIND_SFML_OS_WINDOWS)
set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "opengl32" "winmm" "gdi32") set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "opengl32" "winmm" "gdi32")
elseif(FIND_SFML_OS_LINUX) 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}) 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) 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") 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) elseif(FIND_SFML_OS_MACOSX)
set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "-framework OpenGL -framework Foundation -framework AppKit -framework IOKit -framework Carbon") set(SFML_WINDOW_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} "-framework OpenGL -framework Foundation -framework AppKit -framework IOKit -framework Carbon")
endif() endif()
set(SFML_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} ${SFML_DEPENDENCIES}) set(SFML_DEPENDENCIES ${SFML_WINDOW_DEPENDENCIES} ${SFML_DEPENDENCIES})
endif() endif()
# sfml-graphics # sfml-graphics
list(FIND SFML_FIND_COMPONENTS "graphics" FIND_SFML_GRAPHICS_COMPONENT) list(FIND SFML_FIND_COMPONENTS "graphics" FIND_SFML_GRAPHICS_COMPONENT)
if(NOT ${FIND_SFML_GRAPHICS_COMPONENT} EQUAL -1) if(NOT ${FIND_SFML_GRAPHICS_COMPONENT} EQUAL -1)
# find libraries # find libraries
find_sfml_dependency(FREETYPE_LIBRARY "FreeType" freetype) find_sfml_dependency(FREETYPE_LIBRARY "FreeType" freetype)
find_sfml_dependency(JPEG_LIBRARY "libjpeg" jpeg) find_sfml_dependency(JPEG_LIBRARY "libjpeg" jpeg)
# update the list # update the list
set(SFML_GRAPHICS_DEPENDENCIES ${FREETYPE_LIBRARY} ${JPEG_LIBRARY}) set(SFML_GRAPHICS_DEPENDENCIES ${FREETYPE_LIBRARY} ${JPEG_LIBRARY})
set(SFML_DEPENDENCIES ${SFML_GRAPHICS_DEPENDENCIES} ${SFML_DEPENDENCIES}) set(SFML_DEPENDENCIES ${SFML_GRAPHICS_DEPENDENCIES} ${SFML_DEPENDENCIES})
endif() endif()
# sfml-audio # sfml-audio
list(FIND SFML_FIND_COMPONENTS "audio" FIND_SFML_AUDIO_COMPONENT) list(FIND SFML_FIND_COMPONENTS "audio" FIND_SFML_AUDIO_COMPONENT)
if(NOT ${FIND_SFML_AUDIO_COMPONENT} EQUAL -1) if(NOT ${FIND_SFML_AUDIO_COMPONENT} EQUAL -1)
# find libraries # find libraries
find_sfml_dependency(OPENAL_LIBRARY "OpenAL" openal openal32) find_sfml_dependency(OPENAL_LIBRARY "OpenAL" openal openal32)
find_sfml_dependency(OGG_LIBRARY "Ogg" ogg) find_sfml_dependency(OGG_LIBRARY "Ogg" ogg)
find_sfml_dependency(VORBIS_LIBRARY "Vorbis" vorbis) find_sfml_dependency(VORBIS_LIBRARY "Vorbis" vorbis)
find_sfml_dependency(VORBISFILE_LIBRARY "VorbisFile" vorbisfile) find_sfml_dependency(VORBISFILE_LIBRARY "VorbisFile" vorbisfile)
find_sfml_dependency(VORBISENC_LIBRARY "VorbisEnc" vorbisenc) find_sfml_dependency(VORBISENC_LIBRARY "VorbisEnc" vorbisenc)
find_sfml_dependency(FLAC_LIBRARY "FLAC" FLAC) find_sfml_dependency(FLAC_LIBRARY "FLAC" FLAC)
# update the list # update the list
set(SFML_AUDIO_DEPENDENCIES ${OPENAL_LIBRARY} ${FLAC_LIBRARY} ${VORBISENC_LIBRARY} ${VORBISFILE_LIBRARY} ${VORBIS_LIBRARY} ${OGG_LIBRARY}) set(SFML_AUDIO_DEPENDENCIES ${OPENAL_LIBRARY} ${FLAC_LIBRARY} ${VORBISENC_LIBRARY} ${VORBISFILE_LIBRARY} ${VORBIS_LIBRARY} ${OGG_LIBRARY})
set(SFML_DEPENDENCIES ${SFML_DEPENDENCIES} ${SFML_AUDIO_DEPENDENCIES}) set(SFML_DEPENDENCIES ${SFML_DEPENDENCIES} ${SFML_AUDIO_DEPENDENCIES})
endif() endif()
endif() endif()
# handle errors # handle errors
if(NOT SFML_VERSION_OK) if(NOT SFML_VERSION_OK)
# SFML version not 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(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) set(SFML_FOUND FALSE)
elseif(SFML_STATIC_LIBRARIES AND FIND_SFML_DEPENDENCIES_NOTFOUND) 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(FIND_SFML_ERROR "SFML found but some of its dependencies are missing (${FIND_SFML_DEPENDENCIES_NOTFOUND})")
set(SFML_FOUND FALSE) set(SFML_FOUND FALSE)
elseif(NOT SFML_FOUND) elseif(NOT SFML_FOUND)
# include directory or library not found # include directory or library not found
set(FIND_SFML_ERROR "Could NOT find SFML (missing: ${FIND_SFML_MISSING})") set(FIND_SFML_ERROR "Could NOT find SFML (missing: ${FIND_SFML_MISSING})")
endif() endif()
if (NOT SFML_FOUND) if (NOT SFML_FOUND)
if(SFML_FIND_REQUIRED) if(SFML_FIND_REQUIRED)
# fatal error # fatal error
message(FATAL_ERROR ${FIND_SFML_ERROR}) message(FATAL_ERROR ${FIND_SFML_ERROR})
elseif(NOT SFML_FIND_QUIETLY) elseif(NOT SFML_FIND_QUIETLY)
# error but continue # error but continue
message("${FIND_SFML_ERROR}") message("${FIND_SFML_ERROR}")
endif() endif()
endif() endif()
# handle success # handle success
if(SFML_FOUND AND NOT SFML_FIND_QUIETLY) 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}") message(STATUS "Found SFML ${SFML_VERSION_MAJOR}.${SFML_VERSION_MINOR}.${SFML_VERSION_PATCH} in ${SFML_INCLUDE_DIR}")
endif() endif()

@ -1 +1 @@
#How to Build #How to Build

@ -1,138 +1,138 @@
#pragma once #pragma once
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>
#include <list> #include <list>
class Curses { class Curses {
public: public:
struct Slot { struct Slot {
Slot(wchar_t unicode_value_, Slot(wchar_t unicode_value_,
sf::Color font_color_, sf::Color font_color_,
sf::Color backfill_color_) : sf::Color backfill_color_) :
unicode_value(unicode_value_), unicode_value(unicode_value_),
font_color(font_color_), font_color(font_color_),
backfill_color(backfill_color_) backfill_color(backfill_color_)
{}; {};
wchar_t unicode_value; wchar_t unicode_value;
sf::Color font_color; sf::Color font_color;
sf::Color backfill_color; sf::Color backfill_color;
}; };
struct Tile { struct Tile {
public: public:
Tile(sf::Vector2i position_) : Tile(sf::Vector2i position_) :
blank_standby(L'\u0020', sf::Color::Transparent, sf::Color::Black), blank_standby(L'\u0020', sf::Color::Transparent, sf::Color::Black),
position(position_) position(position_)
{ }; { };
private: private:
Slot blank_standby; Slot blank_standby;
int index = 0; // What index in the vector are we. Backbone for blinking and scrolling int index = 0; // What index in the vector are we. Backbone for blinking and scrolling
int ratio_counter = 0; // Secondary counter to hold index positions for (ratio) length of time int ratio_counter = 0; // Secondary counter to hold index positions for (ratio) length of time
int ratio_value = 0; int ratio_value = 0;
std::vector<Slot> slot_stack; // The icon that aligns with the index std::vector<Slot> slot_stack; // The icon that aligns with the index
sf::Vector2i position; // Position of the text, and backfill sf::Vector2i position; // Position of the text, and backfill
public: public:
void set_ratio(int ratio_) { void set_ratio(int ratio_) {
ratio_value = ratio_; ratio_value = ratio_;
} }
sf::Vector2i getPosition() const { sf::Vector2i getPosition() const {
return position; return position;
} }
void push_back(Slot s) { void push_back(Slot s) {
slot_stack.push_back(s); slot_stack.push_back(s);
} }
void clear_and_set(Slot s) { void clear_and_set(Slot s) {
slot_stack.clear(); slot_stack.clear();
slot_stack.push_back(s); slot_stack.push_back(s);
} }
void clear() { void clear() {
slot_stack.clear(); slot_stack.clear();
} }
sf::Color current_font_color() { sf::Color current_font_color() {
if (slot_stack.size() > 0) if (slot_stack.size() > 0)
return slot_stack.at(index).font_color; return slot_stack.at(index).font_color;
else else
return blank_standby.font_color; return blank_standby.font_color;
} }
sf::Color current_backfill_color() { sf::Color current_backfill_color() {
if (slot_stack.size() > 0) if (slot_stack.size() > 0)
return slot_stack.at(index).backfill_color; return slot_stack.at(index).backfill_color;
else else
return blank_standby.backfill_color; return blank_standby.backfill_color;
} }
wchar_t current_unicode_value() { wchar_t current_unicode_value() {
if (slot_stack.size() > 0) if (slot_stack.size() > 0)
return slot_stack.at(index).unicode_value; return slot_stack.at(index).unicode_value;
else else
return blank_standby.unicode_value; return blank_standby.unicode_value;
} }
void inc_index() { void inc_index() {
if (index >= slot_stack.size() - 1) { if (index >= slot_stack.size() - 1) {
index = 0; index = 0;
} }
else if (ratio_counter == ratio_value) { else if (ratio_counter == ratio_value) {
ratio_counter = 0; ratio_counter = 0;
index++; index++;
} }
else else
ratio_counter++; ratio_counter++;
} }
}; };
Curses(sf::Vector2i tile_size_, sf::Vector2i grid_dimensions); Curses(sf::Vector2i tile_size_, sf::Vector2i grid_dimensions);
~Curses(); ~Curses();
void Update(double delta_time_); void Update(double delta_time_);
void Render(); void Render();
void setTile(Tile tile_); void setTile(Tile tile_);
void setTiles(std::vector<Tile> tiles_); // Can be seperate, non-adjacent tiles void setTiles(std::vector<Tile> tiles_); // Can be seperate, non-adjacent tiles
void Clear(); void Clear();
Tile* getTile(sf::Vector2i position_); Tile* getTile(sf::Vector2i position_);
std::vector<Curses::Tile*> getTiles(sf::Vector2i start_, sf::Vector2i end_); std::vector<Curses::Tile*> getTiles(sf::Vector2i start_, sf::Vector2i end_);
void ResizeTiles(sf::Vector2i size_); void ResizeTiles(sf::Vector2i size_);
void ResizeTileGrid(sf::Vector2i grid_dimensions_); void ResizeTileGrid(sf::Vector2i grid_dimensions_);
void setBlink(int ratio_, sf::Vector2i position_); void setBlink(int ratio_, sf::Vector2i position_);
void setScroll(int ratio_, sf::Vector2i start_, sf::Vector2i end_); void setScroll(int ratio_, sf::Vector2i start_, sf::Vector2i end_);
void setScroll(int ratio_, sf::Vector2i start_, std::list<Slot> tiles_); void setScroll(int ratio_, sf::Vector2i start_, std::list<Slot> tiles_);
private: private:
sf::Vector2i grid_dimensions; sf::Vector2i grid_dimensions;
sf::Vector2i tile_pixel_dimensions; sf::Vector2i tile_pixel_dimensions;
sf::RenderWindow window; sf::RenderWindow window;
std::vector<Tile> tiles; std::vector<Tile> tiles;
sf::Font font; sf::Font font;
int multi_to_linear(sf::Vector2i position_) const; int multi_to_linear(sf::Vector2i position_) const;
sf::Vector2i linear_to_multi(int position_) const; sf::Vector2i linear_to_multi(int position_) const;
void set_tile_ratio(int ratio_, sf::Vector2i tile_position_); void set_tile_ratio(int ratio_, sf::Vector2i tile_position_);
void append_slots(sf::Vector2i start_, std::list<Slot> values_); void append_slots(sf::Vector2i start_, std::list<Slot> values_);
}; };

@ -1,46 +1,46 @@
#pragma once #pragma once
#include <SFML/System/Vector3.hpp> #include <SFML/System/Vector3.hpp>
#include <SFML/System/Vector2.hpp> #include <SFML/System/Vector2.hpp>
#include <SFML/Graphics/Color.hpp> #include <SFML/Graphics/Color.hpp>
#include <random> #include <random>
class Map { class Map {
public: public:
Map(sf::Vector3i dim) { Map(sf::Vector3i dim) {
list = new char[dim.x * dim.y * dim.z]; list = new char[dim.x * dim.y * dim.z];
for (int i = 0; i < dim.x * dim.y * dim.x; i++) { for (int i = 0; i < dim.x * dim.y * dim.x; i++) {
list[i] = 0; list[i] = 0;
} }
for (int x = 0; x < dim.x; x++) { for (int x = 0; x < dim.x; x++) {
for (int y = 0; y < dim.y; y++) { for (int y = 0; y < dim.y; y++) {
for (int z = 0; z < dim.z; z++) { for (int z = 0; z < dim.z; z++) {
if (rand() % 100 < 1) if (rand() % 100 < 1)
list[x + dim.x * (y + dim.z * z)] = rand() % 6; list[x + dim.x * (y + dim.z * z)] = rand() % 6;
else else
list[x + dim.x * (y + dim.z * z)] = 0; list[x + dim.x * (y + dim.z * z)] = 0;
} }
} }
} }
dimensions = dim; dimensions = dim;
global_light = sf::Vector3f(0.2, 0.4, 1); global_light = sf::Vector3f(0.2, 0.4, 1);
} }
~Map() { ~Map() {
} }
sf::Vector3i getDimensions(); sf::Vector3i getDimensions();
char *list; char *list;
sf::Vector3i dimensions; sf::Vector3i dimensions;
void moveLight(sf::Vector2f in); void moveLight(sf::Vector2f in);
sf::Vector3f global_light; sf::Vector3f global_light;
protected: protected:
private: private:
}; };

@ -1,46 +1,46 @@
#pragma once #pragma once
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>
#include <iostream> #include <iostream>
#include "Map.h" #include "Map.h"
class Ray { class Ray {
private: private:
// The Tail of the vector // The Tail of the vector
sf::Vector3<float> origin; sf::Vector3<float> origin;
// Direction / Length of the vector // Direction / Length of the vector
sf::Vector3<float> direction; sf::Vector3<float> direction;
// The incrementing points at which T intersects int(X, Y, Z) points // The incrementing points at which T intersects int(X, Y, Z) points
sf::Vector3<float> intersection_t; sf::Vector3<float> intersection_t;
// The speed at which the ray climbs. // The speed at which the ray climbs.
// Take the slope of the line (1 / cartesian.x/y/z) = delta_t.x/y/z // Take the slope of the line (1 / cartesian.x/y/z) = delta_t.x/y/z
sf::Vector3<float> delta_t; sf::Vector3<float> delta_t;
// The 3d voxel position the ray is currently at // The 3d voxel position the ray is currently at
sf::Vector3<int> voxel; sf::Vector3<int> voxel;
// The 2d pixel coordinate // The 2d pixel coordinate
sf::Vector2<int> pixel; sf::Vector2<int> pixel;
// Reference to the voxel map // Reference to the voxel map
Map *map; Map *map;
// The dimensions of the voxel map // The dimensions of the voxel map
sf::Vector3<int> dimensions; sf::Vector3<int> dimensions;
public: public:
Ray( Ray(
Map *m, Map *m,
sf::Vector2<int> resolution, sf::Vector2<int> resolution,
sf::Vector2<int> pixel, sf::Vector2<int> pixel,
sf::Vector3<float> camera_position, sf::Vector3<float> camera_position,
sf::Vector3<float> ray_direction sf::Vector3<float> ray_direction
); );
sf::Color Cast(); sf::Color Cast();
}; };

@ -1,46 +1,46 @@
#pragma once #pragma once
#include <SFML/System/Vector3.hpp> #include <SFML/System/Vector3.hpp>
#include <SFML/System/Vector2.hpp> #include <SFML/System/Vector2.hpp>
#include <Map.h> #include <Map.h>
class RayCaster { class RayCaster {
public: public:
RayCaster(Map *map, RayCaster(Map *map,
sf::Vector3<int> map_dimensions, sf::Vector3<int> map_dimensions,
sf::Vector2<int> viewport_resolution); sf::Vector2<int> viewport_resolution);
~RayCaster(); ~RayCaster();
void setFOV(float fov); void setFOV(float fov);
void setResolution(sf::Vector2<int> resolution); void setResolution(sf::Vector2<int> resolution);
sf::Color* CastRays(sf::Vector3<float> camera_direction, sf::Vector3<float> camera_position); sf::Color* CastRays(sf::Vector3<float> camera_direction, sf::Vector3<float> camera_position);
void moveCamera(sf::Vector2f v); void moveCamera(sf::Vector2f v);
private: private:
sf::Vector3<int> map_dimensions; sf::Vector3<int> map_dimensions;
Map *map; Map *map;
// The XY resolution of the viewport // The XY resolution of the viewport
sf::Vector2<int> resolution; sf::Vector2<int> resolution;
// The pixel array, maybe do RBGA? Are there even 4 byte data types? // The pixel array, maybe do RBGA? Are there even 4 byte data types?
sf::Color *image; sf::Color *image;
// The direction of the camera in POLAR coordinates // The direction of the camera in POLAR coordinates
sf::Vector3<float> camera_direction; sf::Vector3<float> camera_direction;
// Convert the polar coordinates to CARTESIAN // Convert the polar coordinates to CARTESIAN
sf::Vector3<float> camera_direction_cartesian; sf::Vector3<float> camera_direction_cartesian;
// The world-space position of the camera // The world-space position of the camera
sf::Vector3<float> camera_position; sf::Vector3<float> camera_position;
// The distance in units the view plane is from the iris point // The distance in units the view plane is from the iris point
int view_plane_distance = 200; int view_plane_distance = 200;
// Precalculated values for the view plane rays // Precalculated values for the view plane rays
sf::Vector3f *view_plane_vectors; sf::Vector3f *view_plane_vectors;
}; };

@ -1,139 +1,139 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// //
// SFML - Simple and Fast Multimedia Library // SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2016 Laurent Gomila (laurent@sfml-dev.org) // Copyright (C) 2007-2016 Laurent Gomila (laurent@sfml-dev.org)
// //
// This software is provided 'as-is', without any express or implied warranty. // 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. // 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, // Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely, // including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions: // subject to the following restrictions:
// //
// 1. The origin of this software must not be misrepresented; // 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software. // you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment // If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required. // in the product documentation would be appreciated but is not required.
// //
// 2. Altered source versions must be plainly marked as such, // 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software. // and must not be misrepresented as being the original software.
// //
// 3. This notice may not be removed or altered from any source distribution. // 3. This notice may not be removed or altered from any source distribution.
// //
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#ifndef GAME_VECTOR3_H #ifndef GAME_VECTOR3_H
#define GAME_VECTOR3_H #define GAME_VECTOR3_H
template <typename T> template <typename T>
class Vector3 class Vector3
{ {
public: public:
// Default constructor // Default constructor
// Creates a Vector3(0, 0, 0). // Creates a Vector3(0, 0, 0).
Vector3(); Vector3();
// Construct the vector from its coordinates // Construct the vector from its coordinates
Vector3(T X, T Y, T Z); Vector3(T X, T Y, T Z);
// Construct the vector from another type of vector // Construct the vector from another type of vector
// This constructor doesn't replace the copy constructor, // This constructor doesn't replace the copy constructor,
// it's called only when U != T. // it's called only when U != T.
// A call to this constructor will fail to compile if U // A call to this constructor will fail to compile if U
// is not convertible to T. // is not convertible to T.
template <typename U> template <typename U>
explicit Vector3(const Vector3<U>& vector); explicit Vector3(const Vector3<U>& vector);
// Member data // Member data
T x; T x;
T y; T y;
T z; T z;
}; };
// Vector3 // Vector3
// Overload of unary operator - // Overload of unary operator -
// left Vector to negate // left Vector to negate
// Memberwise opposite of the vector // Memberwise opposite of the vector
template <typename T> template <typename T>
Vector3<T> operator -(const Vector3<T>& left); Vector3<T> operator -(const Vector3<T>& left);
// Overload of binary operator += // Overload of binary operator +=
// This operator performs a memberwise addition of both vectors, // This operator performs a memberwise addition of both vectors,
// and assigns the result to left. // and assigns the result to left.
// returns Reference to left // returns Reference to left
template <typename T> template <typename T>
Vector3<T>& operator +=(Vector3<T>& left, const Vector3<T>& right); Vector3<T>& operator +=(Vector3<T>& left, const Vector3<T>& right);
// Overload of binary operator -= // Overload of binary operator -=
// This operator performs a memberwise subtraction of both vectors, // This operator performs a memberwise subtraction of both vectors,
// and assigns the result to left. // and assigns the result to left.
// returns Reference to left // returns Reference to left
template <typename T> template <typename T>
Vector3<T>& operator -=(Vector3<T>& left, const Vector3<T>& right); Vector3<T>& operator -=(Vector3<T>& left, const Vector3<T>& right);
// Overload of binary operator + // Overload of binary operator +
// returns Memberwise addition of both vectors // returns Memberwise addition of both vectors
template <typename T> template <typename T>
Vector3<T> operator +(const Vector3<T>& left, const Vector3<T>& right); Vector3<T> operator +(const Vector3<T>& left, const Vector3<T>& right);
// Overload of binary operator - // Overload of binary operator -
// returns Memberwise subtraction of both vectors // returns Memberwise subtraction of both vectors
template <typename T> template <typename T>
Vector3<T> operator -(const Vector3<T>& left, const Vector3<T>& right); Vector3<T> operator -(const Vector3<T>& left, const Vector3<T>& right);
// Overload of binary operator * // Overload of binary operator *
// returns Memberwise multiplication by right // returns Memberwise multiplication by right
template <typename T> template <typename T>
Vector3<T> operator *(const Vector3<T>& left, T right); Vector3<T> operator *(const Vector3<T>& left, T right);
// Overload of binary operator * // Overload of binary operator *
// returns Memberwise multiplication by left // returns Memberwise multiplication by left
template <typename T> template <typename T>
Vector3<T> operator *(T left, const Vector3<T>& right); Vector3<T> operator *(T left, const Vector3<T>& right);
// Overload of binary operator *= // Overload of binary operator *=
// This operator performs a memberwise multiplication by right, // This operator performs a memberwise multiplication by right,
// and assigns the result to left. // and assigns the result to left.
// returns Reference to left // returns Reference to left
template <typename T> template <typename T>
Vector3<T>& operator *=(Vector3<T>& left, T right); Vector3<T>& operator *=(Vector3<T>& left, T right);
// Overload of binary operator / // Overload of binary operator /
// returns Memberwise division by right // returns Memberwise division by right
template <typename T> template <typename T>
Vector3<T> operator /(const Vector3<T>& left, T right); Vector3<T> operator /(const Vector3<T>& left, T right);
// Overload of binary operator /= // Overload of binary operator /=
// This operator performs a memberwise division by right, // This operator performs a memberwise division by right,
// and assigns the result to left. // and assigns the result to left.
// returns Reference to left // returns Reference to left
template <typename T> template <typename T>
Vector3<T>& operator /=(Vector3<T>& left, T right); Vector3<T>& operator /=(Vector3<T>& left, T right);
// Overload of binary operator == // Overload of binary operator ==
// This operator compares strict equality between two vectors. // This operator compares strict equality between two vectors.
// returns True if left is equal to right // returns True if left is equal to right
template <typename T> template <typename T>
bool operator ==(const Vector3<T>& left, const Vector3<T>& right); bool operator ==(const Vector3<T>& left, const Vector3<T>& right);
// Overload of binary operator != // Overload of binary operator !=
// This operator compares strict difference between two vectors. // This operator compares strict difference between two vectors.
// returns True if left is not equal to right // returns True if left is not equal to right
template <typename T> template <typename T>
bool operator !=(const Vector3<T>& left, const Vector3<T>& right); bool operator !=(const Vector3<T>& left, const Vector3<T>& right);
#include <SFML/System/Vector3.inl> #include <SFML/System/Vector3.inl>
// Define the most common types // Define the most common types
typedef Vector3<int> Vector3i; typedef Vector3<int> Vector3i;
typedef Vector3<float> Vector3f; typedef Vector3<float> Vector3f;
#endif #endif

@ -1,90 +1,90 @@
#pragma once #pragma once
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>
#include <iostream> #include <iostream>
#include <math.h> #include <math.h>
const double PI = 3.141592653589793238463; const double PI = 3.141592653589793238463;
const float PI_F = 3.14159265358979f; const float PI_F = 3.14159265358979f;
struct fps_counter { struct fps_counter {
public: public:
fps_counter(){ fps_counter(){
if(!f.loadFromFile("../assets/fonts/Arial.ttf")){ if(!f.loadFromFile("../assets/fonts/Arial.ttf")){
std::cout << "couldn't find the fall back Arial font in ../assets/fonts/" << std::endl; std::cout << "couldn't find the fall back Arial font in ../assets/fonts/" << std::endl;
} else { } else {
t.setFont(f); t.setFont(f);
} }
} }
void frame(double delta_time){ void frame(double delta_time){
frame_count++; frame_count++;
fps_average += (delta_time - fps_average) / frame_count; fps_average += (delta_time - fps_average) / frame_count;
} }
void draw(sf::RenderWindow *r){ void draw(sf::RenderWindow *r){
t.setString(std::to_string(fps_average)); t.setString(std::to_string(fps_average));
r->draw(t); r->draw(t);
} }
private: private:
sf::Font f; sf::Font f;
sf::Text t; sf::Text t;
int frame_count = 0; int frame_count = 0;
double fps_average = 0; double fps_average = 0;
}; };
inline sf::Vector3f SphereToCart(sf::Vector3f i) { inline sf::Vector3f SphereToCart(sf::Vector3f i) {
auto r = sf::Vector3f( auto r = sf::Vector3f(
(i.x * sin(i.z) * cos(i.y)), (i.x * sin(i.z) * cos(i.y)),
(i.x * sin(i.z) * sin(i.y)), (i.x * sin(i.z) * sin(i.y)),
(i.x * cos(i.z)) (i.x * cos(i.z))
); );
return r; return r;
}; };
inline sf::Vector3f CartToSphere(sf::Vector3f in) { inline sf::Vector3f CartToSphere(sf::Vector3f in) {
auto r = sf::Vector3f( auto r = sf::Vector3f(
sqrt(in.x * in.x + in.y * in.y + in.z * in.z), sqrt(in.x * in.x + in.y * in.y + in.z * in.z),
atan(in.y / in.x), atan(in.y / in.x),
atan(sqrt(in.x * in.x + in.y * in.y) / in.z) atan(sqrt(in.x * in.x + in.y * in.y) / in.z)
); );
return r; return r;
}; };
inline sf::Vector3f Normalize(sf::Vector3f in) { inline sf::Vector3f Normalize(sf::Vector3f in) {
float multiplier = sqrt(in.x * in.x + in.y * in.y + in.z * in.z); float multiplier = sqrt(in.x * in.x + in.y * in.y + in.z * in.z);
auto r = sf::Vector3f( auto r = sf::Vector3f(
in.x / multiplier, in.x / multiplier,
in.y / multiplier, in.y / multiplier,
in.z / multiplier in.z / multiplier
); );
return r; return r;
} }
inline float DotProduct(sf::Vector3f a, sf::Vector3f b){ inline float DotProduct(sf::Vector3f a, sf::Vector3f b){
return a.x * b.x + a.y * b.y + a.z * b.z; return a.x * b.x + a.y * b.y + a.z * b.z;
} }
inline float Magnitude(sf::Vector3f in){ inline float Magnitude(sf::Vector3f in){
return sqrt(in.x * in.x + in.y * in.y + in.z * in.z); return sqrt(in.x * in.x + in.y * in.y + in.z * in.z);
} }
inline float AngleBetweenVectors(sf::Vector3f a, sf::Vector3f b){ inline float AngleBetweenVectors(sf::Vector3f a, sf::Vector3f b){
return acos(DotProduct(a, b) / (Magnitude(a) * Magnitude(b))); return acos(DotProduct(a, b) / (Magnitude(a) * Magnitude(b)));
} }
inline float DegreesToRadians(float in) { inline float DegreesToRadians(float in) {
return in * PI / 180.0f; return in * PI / 180.0f;
} }
inline float RadiansToDegrees(float in) { inline float RadiansToDegrees(float in) {
return in * 180.0f / PI; return in * 180.0f / PI;
} }

@ -1,32 +1,32 @@
__constant sampler_t sampler = __constant sampler_t sampler =
CLK_NORMALIZED_COORDS_FALSE CLK_NORMALIZED_COORDS_FALSE
| CLK_ADDRESS_CLAMP_TO_EDGE | CLK_ADDRESS_CLAMP_TO_EDGE
| CLK_FILTER_NEAREST; | CLK_FILTER_NEAREST;
__constant int FILTER_SIZE = 10; __constant int FILTER_SIZE = 10;
float FilterValue (__constant const float* filterWeights, float FilterValue (__constant const float* filterWeights,
const int x, const int y) const int x, const int y)
{ {
return filterWeights[(x+FILTER_SIZE) + (y+FILTER_SIZE)*(FILTER_SIZE*2 + 1)]; return filterWeights[(x+FILTER_SIZE) + (y+FILTER_SIZE)*(FILTER_SIZE*2 + 1)];
} }
__kernel void Filter ( __kernel void Filter (
__read_only image2d_t input, __read_only image2d_t input,
__constant float* filterWeights, __constant float* filterWeights,
__write_only image2d_t output) __write_only image2d_t output)
{ {
const int2 pos = {get_global_id(0), get_global_id(1)}; const int2 pos = {get_global_id(0), get_global_id(1)};
float4 sum = (float4)(0.0f); float4 sum = (float4)(0.0f);
for(int y = -FILTER_SIZE; y <= FILTER_SIZE; y++) { for(int y = -FILTER_SIZE; y <= FILTER_SIZE; y++) {
for(int x = -FILTER_SIZE; x <= FILTER_SIZE; x++) { for(int x = -FILTER_SIZE; x <= FILTER_SIZE; x++) {
sum += FilterValue(filterWeights, x, y) sum += FilterValue(filterWeights, x, y)
* read_imagef(input, sampler, pos + (int2)(x,y)); * read_imagef(input, sampler, pos + (int2)(x,y));
} }
} }
write_imagef (output, (int2)(pos.x, pos.y), sum); write_imagef (output, (int2)(pos.x, pos.y), sum);
} }

@ -1,47 +1,47 @@
CL_SUCCESS 0 CL_SUCCESS 0
CL_DEVICE_NOT_FOUND -1 CL_DEVICE_NOT_FOUND -1
CL_DEVICE_NOT_AVAILABLE -2 CL_DEVICE_NOT_AVAILABLE -2
CL_COMPILER_NOT_AVAILABLE -3 CL_COMPILER_NOT_AVAILABLE -3
CL_MEM_OBJECT_ALLOCATION_FAILURE -4 CL_MEM_OBJECT_ALLOCATION_FAILURE -4
CL_OUT_OF_RESOURCES -5 CL_OUT_OF_RESOURCES -5
CL_OUT_OF_HOST_MEMORY -6 CL_OUT_OF_HOST_MEMORY -6
CL_PROFILING_INFO_NOT_AVAILABLE -7 CL_PROFILING_INFO_NOT_AVAILABLE -7
CL_MEM_COPY_OVERLAP -8 CL_MEM_COPY_OVERLAP -8
CL_IMAGE_FORMAT_MISMATCH -9 CL_IMAGE_FORMAT_MISMATCH -9
CL_IMAGE_FORMAT_NOT_SUPPORTED -10 CL_IMAGE_FORMAT_NOT_SUPPORTED -10
CL_BUILD_PROGRAM_FAILURE -11 CL_BUILD_PROGRAM_FAILURE -11
CL_MAP_FAILURE -12 CL_MAP_FAILURE -12
CL_INVALID_VALUE -30 CL_INVALID_VALUE -30
CL_INVALID_DEVICE_TYPE -31 CL_INVALID_DEVICE_TYPE -31
CL_INVALID_PLATFORM -32 CL_INVALID_PLATFORM -32
CL_INVALID_DEVICE -33 CL_INVALID_DEVICE -33
CL_INVALID_CONTEXT -34 CL_INVALID_CONTEXT -34
CL_INVALID_QUEUE_PROPERTIES -35 CL_INVALID_QUEUE_PROPERTIES -35
CL_INVALID_COMMAND_QUEUE -36 CL_INVALID_COMMAND_QUEUE -36
CL_INVALID_HOST_PTR -37 CL_INVALID_HOST_PTR -37
CL_INVALID_MEM_OBJECT -38 CL_INVALID_MEM_OBJECT -38
CL_INVALID_IMAGE_FORMAT_DESCRIPTOR -39 CL_INVALID_IMAGE_FORMAT_DESCRIPTOR -39
CL_INVALID_IMAGE_SIZE -40 CL_INVALID_IMAGE_SIZE -40
CL_INVALID_SAMPLER -41 CL_INVALID_SAMPLER -41
CL_INVALID_BINARY -42 CL_INVALID_BINARY -42
CL_INVALID_BUILD_OPTIONS -43 CL_INVALID_BUILD_OPTIONS -43
CL_INVALID_PROGRAM -44 CL_INVALID_PROGRAM -44
CL_INVALID_PROGRAM_EXECUTABLE -45 CL_INVALID_PROGRAM_EXECUTABLE -45
CL_INVALID_KERNEL_NAME -46 CL_INVALID_KERNEL_NAME -46
CL_INVALID_KERNEL_DEFINITION -47 CL_INVALID_KERNEL_DEFINITION -47
CL_INVALID_KERNEL -48 CL_INVALID_KERNEL -48
CL_INVALID_ARG_INDEX -49 CL_INVALID_ARG_INDEX -49
CL_INVALID_ARG_VALUE -50 CL_INVALID_ARG_VALUE -50
CL_INVALID_ARG_SIZE -51 CL_INVALID_ARG_SIZE -51
CL_INVALID_KERNEL_ARGS -52 CL_INVALID_KERNEL_ARGS -52
CL_INVALID_WORK_DIMENSION -53 CL_INVALID_WORK_DIMENSION -53
CL_INVALID_WORK_GROUP_SIZE -54 CL_INVALID_WORK_GROUP_SIZE -54
CL_INVALID_WORK_ITEM_SIZE -55 CL_INVALID_WORK_ITEM_SIZE -55
CL_INVALID_GLOBAL_OFFSET -56 CL_INVALID_GLOBAL_OFFSET -56
CL_INVALID_EVENT_WAIT_LIST -57 CL_INVALID_EVENT_WAIT_LIST -57
CL_INVALID_EVENT -58 CL_INVALID_EVENT -58
CL_INVALID_OPERATION -59 CL_INVALID_OPERATION -59
CL_INVALID_GL_OBJECT -60 CL_INVALID_GL_OBJECT -60
CL_INVALID_BUFFER_SIZE -61 CL_INVALID_BUFFER_SIZE -61
CL_INVALID_MIP_LEVEL -62 CL_INVALID_MIP_LEVEL -62

@ -1,187 +1,187 @@
#pragma once #pragma once
#include "Curses.h" #include "Curses.h"
#include <iostream> #include <iostream>
#include <list> #include <list>
Curses::Curses(sf::Vector2i tile_size_, sf::Vector2i grid_dimensions_) : Curses::Curses(sf::Vector2i tile_size_, sf::Vector2i grid_dimensions_) :
window(sf::VideoMode(tile_size_.x * grid_dimensions_.x, tile_size_.y * grid_dimensions_.y), "SimpleFML Curses"), window(sf::VideoMode(tile_size_.x * grid_dimensions_.x, tile_size_.y * grid_dimensions_.y), "SimpleFML Curses"),
grid_dimensions(grid_dimensions_), grid_dimensions(grid_dimensions_),
tile_pixel_dimensions(tile_size_){ tile_pixel_dimensions(tile_size_){
font.loadFromFile("unifont.ttf"); font.loadFromFile("unifont.ttf");
for (int y = 0; y < grid_dimensions_.y; y++) { for (int y = 0; y < grid_dimensions_.y; y++) {
for (int x = 0 ; x < grid_dimensions_.x; x++) { for (int x = 0 ; x < grid_dimensions_.x; x++) {
tiles.emplace_back(Tile(sf::Vector2i(x, y))); tiles.emplace_back(Tile(sf::Vector2i(x, y)));
// L'\u0020' = space char // L'\u0020' = space char
} }
} }
// Set screen values to increasing unicode chars // Set screen values to increasing unicode chars
/*wchar_t char_ind = L'\u0041'; /*wchar_t char_ind = L'\u0041';
for (int i = 0; i < tiles.size(); i++) { for (int i = 0; i < tiles.size(); i++) {
tiles.at(i).push_clear(char_ind++, sf::Color::White, sf::Color::Black); tiles.at(i).push_clear(char_ind++, sf::Color::White, sf::Color::Black);
}*/ }*/
} }
Curses::~Curses() { Curses::~Curses() {
} }
void Curses::Update(double delta_time_) { void Curses::Update(double delta_time_) {
for (Tile &tile : tiles) { for (Tile &tile : tiles) {
tile.inc_index(); tile.inc_index();
} }
sf::Event event; sf::Event event;
while (window.pollEvent(event)) { while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) if (event.type == sf::Event::Closed)
window.close(); window.close();
} }
} }
void Curses::Render() { void Curses::Render() {
window.clear(); window.clear();
sf::Texture font_texture = font.getTexture(tile_pixel_dimensions.x); sf::Texture font_texture = font.getTexture(tile_pixel_dimensions.x);
// Draw text and backfills // Draw text and backfills
sf::VertexArray backfill_v_arr(sf::Quads, grid_dimensions.x * grid_dimensions.y * 4); sf::VertexArray backfill_v_arr(sf::Quads, grid_dimensions.x * grid_dimensions.y * 4);
sf::VertexArray font_v_arr(sf::Quads, grid_dimensions.x * grid_dimensions.y * 4); sf::VertexArray font_v_arr(sf::Quads, grid_dimensions.x * grid_dimensions.y * 4);
int tile_index = 0; int tile_index = 0;
for (int i = 0; i < backfill_v_arr.getVertexCount(); i += 4) { for (int i = 0; i < backfill_v_arr.getVertexCount(); i += 4) {
Tile* tile = &tiles.at(tile_index); Tile* tile = &tiles.at(tile_index);
sf::Glyph glyph = font.getGlyph(tile->current_unicode_value(), tile_pixel_dimensions.x, false); sf::Glyph glyph = font.getGlyph(tile->current_unicode_value(), tile_pixel_dimensions.x, false);
// Backfill the tile with the specified backfill color // Backfill the tile with the specified backfill color
backfill_v_arr[i + 0].position = sf::Vector2f(tile->getPosition().x * tile_pixel_dimensions.x, tile->getPosition().y * tile_pixel_dimensions.y); backfill_v_arr[i + 0].position = sf::Vector2f(tile->getPosition().x * tile_pixel_dimensions.x, tile->getPosition().y * tile_pixel_dimensions.y);
backfill_v_arr[i + 1].position = sf::Vector2f(tile->getPosition().x * tile_pixel_dimensions.x + tile_pixel_dimensions.x, tile->getPosition().y * tile_pixel_dimensions.y); backfill_v_arr[i + 1].position = sf::Vector2f(tile->getPosition().x * tile_pixel_dimensions.x + tile_pixel_dimensions.x, tile->getPosition().y * tile_pixel_dimensions.y);
backfill_v_arr[i + 2].position = sf::Vector2f(tile->getPosition().x * tile_pixel_dimensions.x + tile_pixel_dimensions.x, tile->getPosition().y * tile_pixel_dimensions.y + tile_pixel_dimensions.y); backfill_v_arr[i + 2].position = sf::Vector2f(tile->getPosition().x * tile_pixel_dimensions.x + tile_pixel_dimensions.x, tile->getPosition().y * tile_pixel_dimensions.y + tile_pixel_dimensions.y);
backfill_v_arr[i + 3].position = sf::Vector2f(tile->getPosition().x * tile_pixel_dimensions.x, tile->getPosition().y * tile_pixel_dimensions.y + tile_pixel_dimensions.y); backfill_v_arr[i + 3].position = sf::Vector2f(tile->getPosition().x * tile_pixel_dimensions.x, tile->getPosition().y * tile_pixel_dimensions.y + tile_pixel_dimensions.y);
backfill_v_arr[i + 0].color = tile->current_backfill_color(); backfill_v_arr[i + 0].color = tile->current_backfill_color();
backfill_v_arr[i + 1].color = tile->current_backfill_color(); backfill_v_arr[i + 1].color = tile->current_backfill_color();
backfill_v_arr[i + 2].color = tile->current_backfill_color(); backfill_v_arr[i + 2].color = tile->current_backfill_color();
backfill_v_arr[i + 3].color = tile->current_backfill_color(); backfill_v_arr[i + 3].color = tile->current_backfill_color();
// Draw the font with the correct size, texture location, window location, and color // Draw the font with the correct size, texture location, window location, and color
font_v_arr[i + 0].position = sf::Vector2f(tile->getPosition().x * tile_pixel_dimensions.x, tile->getPosition().y * tile_pixel_dimensions.y); font_v_arr[i + 0].position = sf::Vector2f(tile->getPosition().x * tile_pixel_dimensions.x, tile->getPosition().y * tile_pixel_dimensions.y);
font_v_arr[i + 1].position = sf::Vector2f(tile->getPosition().x * tile_pixel_dimensions.x + glyph.textureRect.width, tile->getPosition().y * tile_pixel_dimensions.y); font_v_arr[i + 1].position = sf::Vector2f(tile->getPosition().x * tile_pixel_dimensions.x + glyph.textureRect.width, tile->getPosition().y * tile_pixel_dimensions.y);
font_v_arr[i + 2].position = sf::Vector2f(tile->getPosition().x * tile_pixel_dimensions.x + glyph.textureRect.width, tile->getPosition().y * tile_pixel_dimensions.y + glyph.textureRect.height); font_v_arr[i + 2].position = sf::Vector2f(tile->getPosition().x * tile_pixel_dimensions.x + glyph.textureRect.width, tile->getPosition().y * tile_pixel_dimensions.y + glyph.textureRect.height);
font_v_arr[i + 3].position = sf::Vector2f(tile->getPosition().x * tile_pixel_dimensions.x, tile->getPosition().y * tile_pixel_dimensions.y + glyph.textureRect.height); font_v_arr[i + 3].position = sf::Vector2f(tile->getPosition().x * tile_pixel_dimensions.x, tile->getPosition().y * tile_pixel_dimensions.y + glyph.textureRect.height);
// Make the letter appear in the center of the tile by applying an offset // Make the letter appear in the center of the tile by applying an offset
sf::Vector2f position_offset = sf::Vector2f(tile_pixel_dimensions.x / 4, tile_pixel_dimensions.y / 4); sf::Vector2f position_offset = sf::Vector2f(tile_pixel_dimensions.x / 4, tile_pixel_dimensions.y / 4);
font_v_arr[i + 0].position += position_offset; font_v_arr[i + 0].position += position_offset;
font_v_arr[i + 1].position += position_offset; font_v_arr[i + 1].position += position_offset;
font_v_arr[i + 2].position += position_offset; font_v_arr[i + 2].position += position_offset;
font_v_arr[i + 3].position += position_offset; font_v_arr[i + 3].position += position_offset;
font_v_arr[i + 0].texCoords = sf::Vector2f(glyph.textureRect.left, glyph.textureRect.top); font_v_arr[i + 0].texCoords = sf::Vector2f(glyph.textureRect.left, glyph.textureRect.top);
font_v_arr[i + 1].texCoords = sf::Vector2f(glyph.textureRect.width + glyph.textureRect.left, glyph.textureRect.top); font_v_arr[i + 1].texCoords = sf::Vector2f(glyph.textureRect.width + glyph.textureRect.left, glyph.textureRect.top);
font_v_arr[i + 2].texCoords = sf::Vector2f(glyph.textureRect.width + glyph.textureRect.left, glyph.textureRect.top + glyph.textureRect.height); font_v_arr[i + 2].texCoords = sf::Vector2f(glyph.textureRect.width + glyph.textureRect.left, glyph.textureRect.top + glyph.textureRect.height);
font_v_arr[i + 3].texCoords = sf::Vector2f(glyph.textureRect.left, glyph.textureRect.top + glyph.textureRect.height); font_v_arr[i + 3].texCoords = sf::Vector2f(glyph.textureRect.left, glyph.textureRect.top + glyph.textureRect.height);
font_v_arr[i + 0].color = tile->current_font_color(); font_v_arr[i + 0].color = tile->current_font_color();
font_v_arr[i + 1].color = tile->current_font_color(); font_v_arr[i + 1].color = tile->current_font_color();
font_v_arr[i + 2].color = tile->current_font_color(); font_v_arr[i + 2].color = tile->current_font_color();
font_v_arr[i + 3].color = tile->current_font_color(); font_v_arr[i + 3].color = tile->current_font_color();
tile_index++; tile_index++;
} }
window.draw(backfill_v_arr); window.draw(backfill_v_arr);
window.draw(font_v_arr, &font_texture); window.draw(font_v_arr, &font_texture);
window.display(); window.display();
} }
void Curses::setTile(Tile tile_) { void Curses::setTile(Tile tile_) {
tiles.at(multi_to_linear(tile_.getPosition())) = tile_; tiles.at(multi_to_linear(tile_.getPosition())) = tile_;
} }
void Curses::setTiles(std::vector<Tile> tiles_) { void Curses::setTiles(std::vector<Tile> tiles_) {
for (Tile tile: tiles_) { for (Tile tile: tiles_) {
tiles.at(multi_to_linear(tile.getPosition())) = tile; tiles.at(multi_to_linear(tile.getPosition())) = tile;
} }
} }
void Curses::Clear() { void Curses::Clear() {
for (Tile &tile : tiles) { for (Tile &tile : tiles) {
tile.clear(); tile.clear();
} }
} }
Curses::Tile* Curses::getTile(sf::Vector2i position_) { Curses::Tile* Curses::getTile(sf::Vector2i position_) {
return &tiles.at(multi_to_linear(position_)); return &tiles.at(multi_to_linear(position_));
} }
std::vector<Curses::Tile*> Curses::getTiles(sf::Vector2i start_, sf::Vector2i end_) { std::vector<Curses::Tile*> Curses::getTiles(sf::Vector2i start_, sf::Vector2i end_) {
std::vector<Curses::Tile*> ret; std::vector<Curses::Tile*> ret;
for (int i = multi_to_linear(start_); i < multi_to_linear(end_); i++) { for (int i = multi_to_linear(start_); i < multi_to_linear(end_); i++) {
ret.push_back(&tiles.at(i)); ret.push_back(&tiles.at(i));
} }
return ret; return ret;
} }
void Curses::setScroll(int ratio_, sf::Vector2i start_, std::list<Slot> scroll_text_) { void Curses::setScroll(int ratio_, sf::Vector2i start_, std::list<Slot> scroll_text_) {
// Scrolling and it's scroll ratio is faux implemented by // Scrolling and it's scroll ratio is faux implemented by
// essentially stacking values and repeating them to slow the scroll down // essentially stacking values and repeating them to slow the scroll down
for (int i = 0; i < scroll_text_.size(); i++) { for (int i = 0; i < scroll_text_.size(); i++) {
append_slots(start_, scroll_text_); append_slots(start_, scroll_text_);
scroll_text_.push_back(scroll_text_.front()); scroll_text_.push_back(scroll_text_.front());
scroll_text_.pop_front(); scroll_text_.pop_front();
} }
} }
void Curses::set_tile_ratio(int ratio_, sf::Vector2i tile_position_) { void Curses::set_tile_ratio(int ratio_, sf::Vector2i tile_position_) {
getTile(tile_position_)->set_ratio(ratio_); getTile(tile_position_)->set_ratio(ratio_);
} }
void Curses::append_slots(sf::Vector2i start_, std::list<Slot> values_) void Curses::append_slots(sf::Vector2i start_, std::list<Slot> values_)
{ {
std::vector<Tile*> tiles = getTiles(start_, std::vector<Tile*> tiles = getTiles(start_,
sf::Vector2i((values_.size() + start_.x) % grid_dimensions.x, sf::Vector2i((values_.size() + start_.x) % grid_dimensions.x,
(values_.size() + start_.x) / grid_dimensions.x + start_.y)); (values_.size() + start_.x) / grid_dimensions.x + start_.y));
if (tiles.size() != values_.size()) { if (tiles.size() != values_.size()) {
std::cout << "Values did not match up to slots when appending\n"; std::cout << "Values did not match up to slots when appending\n";
return; return;
} }
std::list<Slot>::iterator beg_slot_it = values_.begin(); std::list<Slot>::iterator beg_slot_it = values_.begin();
std::list<Slot>::iterator end_slot_it = values_.end(); std::list<Slot>::iterator end_slot_it = values_.end();
std::list<Slot>::iterator slot_it; std::list<Slot>::iterator slot_it;
std::vector<Tile*>::iterator beg_tile_it = tiles.begin(); std::vector<Tile*>::iterator beg_tile_it = tiles.begin();
std::vector<Tile*>::iterator end_tile_it = tiles.end(); std::vector<Tile*>::iterator end_tile_it = tiles.end();
std::vector<Tile*>::iterator tile_it; std::vector<Tile*>::iterator tile_it;
for (slot_it = beg_slot_it, tile_it = beg_tile_it; for (slot_it = beg_slot_it, tile_it = beg_tile_it;
(slot_it != end_slot_it) && (tile_it != end_tile_it); (slot_it != end_slot_it) && (tile_it != end_tile_it);
++slot_it, ++tile_it) { ++slot_it, ++tile_it) {
Tile* t = *tile_it; Tile* t = *tile_it;
t->push_back(*slot_it); t->push_back(*slot_it);
} }
} }
sf::Vector2i Curses::linear_to_multi(int position_) const { sf::Vector2i Curses::linear_to_multi(int position_) const {
return sf::Vector2i(position_ % grid_dimensions.x, position_ / grid_dimensions.x); return sf::Vector2i(position_ % grid_dimensions.x, position_ / grid_dimensions.x);
} }
int Curses::multi_to_linear(sf::Vector2i position_) const { int Curses::multi_to_linear(sf::Vector2i position_) const {
return position_.y * grid_dimensions.x + position_.x; return position_.y * grid_dimensions.x + position_.x;
} }

@ -1,73 +1,73 @@
#pragma once #pragma once
#include "Map.h" #include "Map.h"
#include <iostream> #include <iostream>
#include <SFML/System/Vector3.hpp> #include <SFML/System/Vector3.hpp>
#include <SFML/System/Vector2.hpp> #include <SFML/System/Vector2.hpp>
#include "util.hpp" #include "util.hpp"
sf::Vector3i Map::getDimensions() { sf::Vector3i Map::getDimensions() {
return dimensions; return dimensions;
} }
void Map::moveLight(sf::Vector2f in) { void Map::moveLight(sf::Vector2f in) {
sf::Vector3f light_spherical = CartToSphere(global_light); sf::Vector3f light_spherical = CartToSphere(global_light);
light_spherical.y += in.y; light_spherical.y += in.y;
light_spherical.x += in.x; light_spherical.x += in.x;
global_light = SphereToCart(light_spherical); global_light = SphereToCart(light_spherical);
return; return;
} }
//void Map::GenerateFloor(){ //void Map::GenerateFloor(){
//} //}

@ -1,159 +1,159 @@
#pragma once #pragma once
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>
#include <iostream> #include <iostream>
#include "Map.h" #include "Map.h"
#include <Ray.h> #include <Ray.h>
#include "util.hpp" #include "util.hpp"
Ray::Ray( Ray::Ray(
Map *map, Map *map,
sf::Vector2<int> resolution, sf::Vector2<int> resolution,
sf::Vector2<int> pixel, sf::Vector2<int> pixel,
sf::Vector3<float> camera_position, sf::Vector3<float> camera_position,
sf::Vector3<float> ray_direction) { sf::Vector3<float> ray_direction) {
this->pixel = pixel; this->pixel = pixel;
this->map = map; this->map = map;
origin = camera_position; origin = camera_position;
direction = ray_direction; direction = ray_direction;
dimensions = map->getDimensions(); dimensions = map->getDimensions();
} }
sf::Color Ray::Cast() { sf::Color Ray::Cast() {
// Setup the voxel step based on what direction the ray is pointing // Setup the voxel step based on what direction the ray is pointing
sf::Vector3<int> voxel_step(1, 1, 1); sf::Vector3<int> voxel_step(1, 1, 1);
voxel_step.x *= (direction.x > 0) - (direction.x < 0); voxel_step.x *= (direction.x > 0) - (direction.x < 0);
voxel_step.y *= (direction.y > 0) - (direction.y < 0); voxel_step.y *= (direction.y > 0) - (direction.y < 0);
voxel_step.z *= (direction.z > 0) - (direction.z < 0); voxel_step.z *= (direction.z > 0) - (direction.z < 0);
// Setup the voxel coords from the camera origin // Setup the voxel coords from the camera origin
voxel = sf::Vector3<int>( voxel = sf::Vector3<int>(
floorf(origin.x), floorf(origin.x),
floorf(origin.y), floorf(origin.y),
floorf(origin.z) floorf(origin.z)
); );
// Delta T is the units a ray must travel along an axis in order to // Delta T is the units a ray must travel along an axis in order to
// traverse an integer split // traverse an integer split
delta_t = sf::Vector3<float>( delta_t = sf::Vector3<float>(
fabsf(1.0f / direction.x), fabsf(1.0f / direction.x),
fabsf(1.0f / direction.y), fabsf(1.0f / direction.y),
fabsf(1.0f / direction.z) fabsf(1.0f / direction.z)
); );
// Intersection T is the collection of the next intersection points // Intersection T is the collection of the next intersection points
// for all 3 axis XYZ. // for all 3 axis XYZ.
intersection_t = sf::Vector3<float>( intersection_t = sf::Vector3<float>(
delta_t.x, delta_t.x,
delta_t.y, delta_t.y,
delta_t.z delta_t.z
); );
int dist = 0; int dist = 0;
int face = -1; int face = -1;
// X:0, Y:1, Z:2 // X:0, Y:1, Z:2
// Andrew Woo's raycasting algo // Andrew Woo's raycasting algo
do { do {
if ((intersection_t.x) < (intersection_t.y)) { if ((intersection_t.x) < (intersection_t.y)) {
if ((intersection_t.x) < (intersection_t.z)) { if ((intersection_t.x) < (intersection_t.z)) {
face = 0; face = 0;
voxel.x += voxel_step.x; voxel.x += voxel_step.x;
intersection_t.x = intersection_t.x + delta_t.x; intersection_t.x = intersection_t.x + delta_t.x;
} else { } else {
face = 2; face = 2;
voxel.z += voxel_step.z; voxel.z += voxel_step.z;
intersection_t.z = intersection_t.z + delta_t.z; intersection_t.z = intersection_t.z + delta_t.z;
} }
} else { } else {
if ((intersection_t.y) < (intersection_t.z)) { if ((intersection_t.y) < (intersection_t.z)) {
face = 1; face = 1;
voxel.y += voxel_step.y; voxel.y += voxel_step.y;
intersection_t.y = intersection_t.y + delta_t.y; intersection_t.y = intersection_t.y + delta_t.y;
} else { } else {
face = 2; face = 2;
voxel.z += voxel_step.z; voxel.z += voxel_step.z;
intersection_t.z = intersection_t.z + delta_t.z; intersection_t.z = intersection_t.z + delta_t.z;
} }
} }
// If the ray went out of bounds // If the ray went out of bounds
if (voxel.z >= dimensions.z) { if (voxel.z >= dimensions.z) {
return sf::Color(172, 245, 251, 200); return sf::Color(172, 245, 251, 200);
} }
if (voxel.x >= dimensions.x) { if (voxel.x >= dimensions.x) {
return sf::Color(172, 245, 251, 200); return sf::Color(172, 245, 251, 200);
} }
if (voxel.y >= dimensions.x) { if (voxel.y >= dimensions.x) {
return sf::Color(172, 245, 251, 200); return sf::Color(172, 245, 251, 200);
} }
if (voxel.x < 0) { if (voxel.x < 0) {
return sf::Color(172, 245, 251, 200); return sf::Color(172, 245, 251, 200);
} }
if (voxel.y < 0) { if (voxel.y < 0) {
return sf::Color(172, 245, 251, 200); return sf::Color(172, 245, 251, 200);
} }
if (voxel.z < 0) { if (voxel.z < 0) {
return sf::Color(172, 245, 251, 200); return sf::Color(172, 245, 251, 200);
} }
// If we hit a voxel // If we hit a voxel
int index = voxel.x + dimensions.x * (voxel.y + dimensions.z * voxel.z); int index = voxel.x + dimensions.x * (voxel.y + dimensions.z * voxel.z);
int voxel_data = map->list[index]; int voxel_data = map->list[index];
float alpha = 0; float alpha = 0;
if (face == 0) { if (face == 0) {
alpha = AngleBetweenVectors(sf::Vector3f(1, 0, 0), map->global_light); alpha = AngleBetweenVectors(sf::Vector3f(1, 0, 0), map->global_light);
alpha = fmod(alpha, 0.785) * 2; alpha = fmod(alpha, 0.785) * 2;
} else if (face == 1) { } else if (face == 1) {
alpha = AngleBetweenVectors(sf::Vector3f(0, 1, 0), map->global_light); alpha = AngleBetweenVectors(sf::Vector3f(0, 1, 0), map->global_light);
alpha = fmod(alpha, 0.785) * 2; alpha = fmod(alpha, 0.785) * 2;
} else if (face == 2){ } else if (face == 2){
//alpha = 1.57 / 2; //alpha = 1.57 / 2;
alpha = AngleBetweenVectors(sf::Vector3f(0, 0, 1), map->global_light); alpha = AngleBetweenVectors(sf::Vector3f(0, 0, 1), map->global_light);
alpha = fmod(alpha, 0.785) * 2; alpha = fmod(alpha, 0.785) * 2;
} }
alpha *= 162; alpha *= 162;
switch (voxel_data) { switch (voxel_data) {
case 1: case 1:
// AngleBew0 - 1.57 * 162 = 0 - 255 // AngleBew0 - 1.57 * 162 = 0 - 255
return sf::Color(255, 0, 0, alpha); return sf::Color(255, 0, 0, alpha);
case 2: case 2:
return sf::Color(255, 10, 0, alpha); return sf::Color(255, 10, 0, alpha);
case 3: case 3:
return sf::Color(255, 0, 255, alpha); return sf::Color(255, 0, 255, alpha);
case 4: case 4:
return sf::Color(80, 0, 150, alpha); return sf::Color(80, 0, 150, alpha);
case 5: case 5:
return sf::Color(255, 120, 255, alpha); return sf::Color(255, 120, 255, alpha);
case 6: case 6:
return sf::Color(150, 80, 220, alpha); return sf::Color(150, 80, 220, alpha);
} }
dist++; dist++;
} while (dist < 200); } while (dist < 200);
// Ray timeout color // Ray timeout color
return sf::Color::Cyan; return sf::Color::Cyan;
} }

@ -1,110 +1,110 @@
#include "RayCaster.h" #include "RayCaster.h"
#include <util.hpp> #include <util.hpp>
#include <Ray.h> #include <Ray.h>
RayCaster::RayCaster( RayCaster::RayCaster(
Map *map, Map *map,
sf::Vector3<int> map_dimensions, sf::Vector3<int> map_dimensions,
sf::Vector2<int> viewport_resolution ) { sf::Vector2<int> viewport_resolution ) {
// Override values // Override values
//this.map_dimensions = new Vector3<int> (50, 50, 50); //this.map_dimensions = new Vector3<int> (50, 50, 50);
//this.resolution = new Vector2<int> (200, 200); //this.resolution = new Vector2<int> (200, 200);
//this.camera_direction = new Vector3<float> (1f, 0f, .8f); //this.camera_direction = new Vector3<float> (1f, 0f, .8f);
//this.camera_position = new Vector3<float> (1, 10, 10); //this.camera_position = new Vector3<float> (1, 10, 10);
this->map_dimensions = map_dimensions; this->map_dimensions = map_dimensions;
this->map = map; this->map = map;
resolution = viewport_resolution; resolution = viewport_resolution;
image = new sf::Color[resolution.x * resolution.y]; image = new sf::Color[resolution.x * resolution.y];
// Calculate the view plane vectors // Calculate the view plane vectors
// Because casting to individual pixels causes barrel distortion, // Because casting to individual pixels causes barrel distortion,
// Get the radian increments // Get the radian increments
// Set the camera origin // Set the camera origin
// Rotate the ray by the specified pixel * increment // Rotate the ray by the specified pixel * increment
double y_increment_radians = DegreesToRadians(50.0 / resolution.y); double y_increment_radians = DegreesToRadians(50.0 / resolution.y);
double x_increment_radians = DegreesToRadians(80.0 / resolution.x); double x_increment_radians = DegreesToRadians(80.0 / resolution.x);
view_plane_vectors = new sf::Vector3f[resolution.x * resolution.y]; view_plane_vectors = new sf::Vector3f[resolution.x * resolution.y];
for (int y = -resolution.y / 2 ; y < resolution.y / 2; y++) { for (int y = -resolution.y / 2 ; y < resolution.y / 2; y++) {
for (int x = -resolution.x / 2; x < resolution.x / 2; x++) { for (int x = -resolution.x / 2; x < resolution.x / 2; x++) {
// The base ray direction to slew from // The base ray direction to slew from
sf::Vector3f ray(1, 0, 0); sf::Vector3f ray(1, 0, 0);
// Y axis, pitch // Y axis, pitch
ray = sf::Vector3f( ray = sf::Vector3f(
ray.z * sin(y_increment_radians * y) + ray.x * cos(y_increment_radians * y), ray.z * sin(y_increment_radians * y) + ray.x * cos(y_increment_radians * y),
ray.y, ray.y,
ray.z * cos(y_increment_radians * y) - ray.x * sin(y_increment_radians * y) ray.z * cos(y_increment_radians * y) - ray.x * sin(y_increment_radians * y)
); );
// Z axis, yaw // Z axis, yaw
ray = sf::Vector3f( ray = sf::Vector3f(
ray.x * cos(x_increment_radians * x) - ray.y * sin(x_increment_radians * x), ray.x * cos(x_increment_radians * x) - ray.y * sin(x_increment_radians * x),
ray.x * sin(x_increment_radians * x) + ray.y * cos(x_increment_radians * x), ray.x * sin(x_increment_radians * x) + ray.y * cos(x_increment_radians * x),
ray.z ray.z
); );
int index = (x + resolution.x / 2) + resolution.x * (y + resolution.y / 2); int index = (x + resolution.x / 2) + resolution.x * (y + resolution.y / 2);
view_plane_vectors[index] = Normalize(ray); view_plane_vectors[index] = Normalize(ray);
} }
} }
} }
RayCaster::~RayCaster() { RayCaster::~RayCaster() {
delete image; delete image;
delete view_plane_vectors; delete view_plane_vectors;
} }
sf::Color* RayCaster::CastRays(sf::Vector3<float> camera_direction, sf::Vector3<float> camera_position) { sf::Color* RayCaster::CastRays(sf::Vector3<float> camera_direction, sf::Vector3<float> camera_position) {
// Setup the camera for this cast // Setup the camera for this cast
this->camera_direction = camera_direction; this->camera_direction = camera_direction;
camera_direction_cartesian = Normalize(SphereToCart(camera_direction)); camera_direction_cartesian = Normalize(SphereToCart(camera_direction));
this->camera_position = camera_position; this->camera_position = camera_position;
// Start the loop at the top left, scan right and work down // Start the loop at the top left, scan right and work down
for (int y = 0; y < resolution.y; y++) { for (int y = 0; y < resolution.y; y++) {
for (int x = 0; x < resolution.x; x++) { for (int x = 0; x < resolution.x; x++) {
// Get the ray at the base direction // Get the ray at the base direction
sf::Vector3f ray = view_plane_vectors[x + resolution.x * y]; sf::Vector3f ray = view_plane_vectors[x + resolution.x * y];
// Rotate it to the correct pitch and yaw // Rotate it to the correct pitch and yaw
// Y axis, pitch // Y axis, pitch
ray = sf::Vector3f( ray = sf::Vector3f(
ray.z * sin(camera_direction.y) + ray.x * cos(camera_direction.y), ray.z * sin(camera_direction.y) + ray.x * cos(camera_direction.y),
ray.y, ray.y,
ray.z * cos(camera_direction.y) - ray.x * sin(camera_direction.y) ray.z * cos(camera_direction.y) - ray.x * sin(camera_direction.y)
); );
// Z axis, yaw // Z axis, yaw
ray = sf::Vector3f( ray = sf::Vector3f(
ray.x * cos(camera_direction.z) - ray.y * sin(camera_direction.z), ray.x * cos(camera_direction.z) - ray.y * sin(camera_direction.z),
ray.x * sin(camera_direction.z) + ray.y * cos(camera_direction.z), ray.x * sin(camera_direction.z) + ray.y * cos(camera_direction.z),
ray.z ray.z
); );
// Setup the ray // Setup the ray
Ray r(map, resolution, sf::Vector2i(x, y), camera_position, ray); Ray r(map, resolution, sf::Vector2i(x, y), camera_position, ray);
// Cast it and assign its return value // Cast it and assign its return value
image[x + resolution.x * y] = r.Cast(); image[x + resolution.x * y] = r.Cast();
} }
} }
return image; return image;
} }
void RayCaster::moveCamera(sf::Vector2f v) { void RayCaster::moveCamera(sf::Vector2f v) {
camera_direction.y += v.x; camera_direction.y += v.x;
camera_direction.z += v.y; camera_direction.z += v.y;
} }

@ -1,95 +1,121 @@
#ifdef linux #pragma once
#include <cstdio>
#elif defined _WIN32 #include <cstring>
#include <CL/cl_ext.h>
#elif defined TARGET_OS_MAC #include <iostream>
# include <GL/glew.h> #include <vector>
# include <OpenGL/OpenGL.h>
# include <OpenCL/opencl.h> #ifdef linux
#endif
#elif defined _WIN32
int IsExtensionSupported( #elif defined TARGET_OS_MAC
const char* support_str, # include <GL/glew.h>
const char* ext_string, # include <OpenGL/OpenGL.h>
size_t ext_buffer_size) { # include <OpenCL/opencl.h>
#endif
size_t offset = 0;
const char* space_substr = strnstr(ext_string + offset, " ", ext_buffer_size - offset);
#ifdef TARGET_OS_MAC
size_t space_pos = space_substr ? space_substr - ext_string : 0; int IsExtensionSupported(
const char* support_str,
while (space_pos < ext_buffer_size) { const char* ext_string,
size_t ext_buffer_size) {
if( strncmp(support_str, ext_string + offset, space_pos) == 0 ) {
// Device supports requested extension! size_t offset = 0;
printf("Info: Found extension support %s!\n", support_str);
return 1; const char* space_substr = strnstr(ext_string + offset, " ", ext_buffer_size - offset);
}
size_t space_pos = space_substr ? space_substr - ext_string : 0;
// Keep searching -- skip to next token string
offset = space_pos + 1; while (space_pos < ext_buffer_size) {
space_substr = strnstr(ext_string + offset, " ", ext_buffer_size - offset);
space_pos = space_substr ? space_substr - ext_string : 0; if( strncmp(support_str, ext_string + offset, space_pos) == 0 ) {
} // Device supports requested extension!
printf("Info: Found extension support %s!\n", support_str);
printf("Warning: Extension not supported %s!\n", support_str); return 1;
return 0; }
}
// Keep searching -- skip to next token string
int test_for_gl_cl_sharing() { offset = space_pos + 1;
space_substr = strnstr(ext_string + offset, " ", ext_buffer_size - offset);
space_pos = space_substr ? space_substr - ext_string : 0;
int err = 0; }
#if defined (__APPLE__) || defined(MACOSX)
static const char *CL_GL_SHARING_EXT = "cl_APPLE_gl_sharing"; std::cout << "Warning: Extension not supported " << support_str << std::endl;
#else return 0;
static const char* CL_GL_SHARING_EXT = "cl_khr_gl_sharing"; }
#endif #endif
cl_uint num_devices, i; inline int test_for_gl_cl_sharing() {
clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, 0, NULL, &num_devices);
cl_device_id *devices = (cl_device_id *) calloc(sizeof(cl_device_id), num_devices); int err = 0;
clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, num_devices, devices, NULL);
#if defined (__APPLE__) || defined(MACOSX)
// Get string containing supported device extensions static const char *CL_GL_SHARING_EXT = "cl_APPLE_gl_sharing";
size_t ext_size = 1024; #else
char *ext_string = (char *) malloc(ext_size); static const char* CL_GL_SHARING_EXT = "cl_khr_gl_sharing";
err = clGetDeviceInfo(devices[0], CL_DEVICE_EXTENSIONS, ext_size, ext_string, &ext_size); #endif
free(devices); cl_uint num_devices;
clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, 0, NULL, &num_devices);
// Search for GL support in extension string (space delimited)
int supported = IsExtensionSupported(CL_GL_SHARING_EXT, ext_string, ext_size); cl_device_id *devices = (cl_device_id *) calloc(sizeof(cl_device_id), num_devices);
if (supported) { clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, num_devices, devices, NULL);
// Device supports context sharing with OpenGL
printf("Found GL Sharing Support!\n"); // Get string containing supported device extensions
return 1; size_t ext_size = 1024;
} char *ext_string = (char *) malloc(ext_size);
return -1; err = clGetDeviceInfo(devices[0], CL_DEVICE_EXTENSIONS, ext_size, ext_string, &ext_size);
}
free(devices);
int query_platform_devices() { // Search for GL support in extension string (space delimited)
// From stackoverflow, gets and lists the compute devices //int supported = IsExtensionSupported(CL_GL_SHARING_EXT, ext_string, ext_size);
cl_uint num_devices, i; int supported = 0;
clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, 0, NULL, &num_devices); if (supported) {
// Device supports context sharing with OpenGL
cl_device_id *devices = (cl_device_id *) calloc(sizeof(cl_device_id), num_devices); printf("Found GL Sharing Support!\n");
clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, num_devices, devices, NULL); return 1;
}
char buf[128]; return -1;
for (i = 0; i < num_devices; i++) { }
clGetDeviceInfo(devices[i], CL_DEVICE_NAME, 128, buf, NULL);
fprintf(stdout, "Device %s supports ", buf);
inline int query_platform_devices() {
clGetDeviceInfo(devices[i], CL_DEVICE_VERSION, 128, buf, NULL);
fprintf(stdout, "%s\n", buf); int error = 0;
} // Get the number of platforms
cl_uint platform_count = 0;
free(devices); clGetPlatformIDs(0, nullptr, &platform_count);
return 1; // Fetch the platforms
std::vector<cl_platform_id> platformIds(platform_count);
clGetPlatformIDs(platform_count, platformIds.data(), nullptr);
for (unsigned int q = 0; q < platform_count; q++) {
// From stackoverflow, gets and lists the compute devices
cl_uint num_devices, i;
error = clGetDeviceIDs(platformIds[q], CL_DEVICE_TYPE_ALL, 0, NULL, &num_devices);
cl_device_id *devices = (cl_device_id *)calloc(sizeof(cl_device_id), num_devices);
error = clGetDeviceIDs(platformIds[q], CL_DEVICE_TYPE_ALL, num_devices, devices, NULL);
char buf[128];
for (i = 0; i < num_devices; i++) {
clGetDeviceInfo(devices[i], CL_DEVICE_NAME, 128, buf, NULL);
fprintf(stdout, "Device %s supports ", buf);
clGetDeviceInfo(devices[i], CL_DEVICE_VERSION, 128, buf, NULL);
fprintf(stdout, "%s\n", buf);
}
free(devices);
}
return 1;
} }

@ -1,5 +1,5 @@
// //
// Created by Mitchell Hansen on 8/7/16. // Created by Mitchell Hansen on 8/7/16.
// //
#include "Vector3.h" #include "Vector3.h"

@ -1,415 +1,464 @@
#include <iostream> #include <iostream>
#include <chrono> #include <chrono>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>
#include <GL/glew.h> #include <GL/glew.h>
#ifdef linux #ifdef linux
#include <CL/cl.h> #include <CL/cl.h>
#include <CL/opencl.h> #include <CL/opencl.h>
#elif defined _WIN32 #elif defined _WIN32
#include <CL/cl.h> #include <CL/cl_gl.h>
#include <CL/opencl.h> #include <CL/cl.h>
#include <windows.h> #include <CL/opencl.h>
#include <windows.h>
#elif defined TARGET_OS_MAC
# include <OpenGL/OpenGL.h> #elif defined TARGET_OS_MAC
# include <OpenCL/opencl.h> # include <OpenGL/OpenGL.h>
# include <OpenCL/opencl.h>
#endif
#endif
#include "Map.h" #include "TestPlatform.cpp"
#include "Curses.h" #include "Map.h"
#include "util.hpp" #include "Curses.h"
#include "RayCaster.h" #include "util.hpp"
#include "RayCaster.h"
const int WINDOW_X = 150; const int WINDOW_X = 150;
const int WINDOW_Y = 150; const int WINDOW_Y = 150;
std::string read_file(std::string file_name){ std::string read_file(std::string file_name){
std::ifstream input_file(file_name); std::ifstream input_file(file_name);
if (!input_file.is_open()){ if (!input_file.is_open()){
std::cout << file_name << " could not be opened" << std::endl; std::cout << file_name << " could not be opened" << std::endl;
return nullptr; return nullptr;
} }
std::stringstream buf; std::stringstream buf;
buf << input_file.rdbuf(); buf << input_file.rdbuf();
return buf.str(); return buf.str();
} }
int main(){ int main(){
char buffer[256];
char *val = getcwd(buffer, sizeof(buffer)); int error = 0;
if (val) {
std::cout << buffer << std::endl; // ===================================================================== //
} // ==== Opencl setup
// ===================================================================== //
// ==== Opencl setup // Get the number of platforms
cl_uint platform_count = 0;
int error = 0; clGetPlatformIDs(0, nullptr, &platform_count);
// Get the number of platforms // Fetch the platforms
cl_uint platformIdCount = 0; std::vector<cl_platform_id> platformIds(platform_count);
clGetPlatformIDs(0, nullptr, &platformIdCount); clGetPlatformIDs(platform_count, platformIds.data(), nullptr);
// Fetch the platforms
std::vector<cl_platform_id> platformIds (platformIdCount);
clGetPlatformIDs(platformIdCount, platformIds.data(), nullptr); // Print out this machines info
std::cout << "============ Hardware info =================" << std::endl;
// get the number of devices, fetch them, choose the first one
cl_uint deviceIdCount = 0; for (unsigned int i = 0; i < platform_count; i++) {
std::vector<cl_device_id> deviceIds;
// Try to get a GPU first std::cout << "--Platform: " << i << std::endl;
error = clGetDeviceIDs (platformIds [0], CL_DEVICE_TYPE_GPU, 0, nullptr,
&deviceIdCount); char platform[128];
char version[128];
if (deviceIdCount == 0) {
std::cout << "couldn't aquire a GPU, falling back to CPU" << std::endl; clGetPlatformInfo(platformIds[i], CL_PLATFORM_NAME, 128, platform, NULL);
error = clGetDeviceIDs(platformIds[0], CL_DEVICE_TYPE_CPU, 0, nullptr, &deviceIdCount); clGetPlatformInfo(platformIds[i], CL_PLATFORM_VERSION, 128, version, NULL);
deviceIds.resize(deviceIdCount);
error = clGetDeviceIDs(platformIds[0], CL_DEVICE_TYPE_CPU, deviceIdCount, deviceIds.data(), NULL); std::cout << platform << "\n";
} else { std::cout << version << "\n\n";
std::cout << "aquired GPU cl target" << std::endl;
deviceIds.resize(deviceIdCount); // get the number of devices, fetch them, choose the first one
clGetDeviceIDs (platformIds[0], CL_DEVICE_TYPE_GPU, deviceIdCount, deviceIds.data (), nullptr); cl_uint deviceIdCount = 0;
} error = clGetDeviceIDs(platformIds[i], CL_DEVICE_TYPE_ALL, 0, nullptr, &deviceIdCount);
if (error != 0){ std::vector<cl_device_id> deviceIds(deviceIdCount);
std::cout << "Err: clGetDeviceIDs returned: " << error << std::endl;
return error; for (int q = 0; q < deviceIdCount; q++) {
}
std::cout << "++++Device " << q << std::endl;
// Hurray for standards! error = clGetDeviceIDs(platformIds[i], CL_DEVICE_TYPE_ALL, deviceIdCount, deviceIds.data(), NULL);
// Setup the context properties to grab the current GL context
#ifdef linux clGetDeviceInfo(deviceIds[q], CL_DEVICE_NAME, 128, platform, NULL);
cl_context_properties context_properties[] = { clGetDeviceInfo(deviceIds[q], CL_DEVICE_VERSION, 128, version, NULL);
CL_GL_CONTEXT_KHR, (cl_context_properties) glXGetCurrentContext(),
CL_GLX_DISPLAY_KHR, (cl_context_properties) glXGetCurrentDisplay(), std::cout << platform << "\n";
CL_CONTEXT_PLATFORM, (cl_context_properties) platform, std::cout << version << "\n\n";
0
}; }
}
#elif defined _WIN32
cl_context_properties context_properties[] = { std::cout << "============================================" << std::endl;
CL_GL_CONTEXT_KHR, (cl_context_properties) wglGetCurrentContext(),
CL_WGL_HDC_KHR, (cl_context_properties) wglGetCurrentDC(), cl_uint deviceIdCount = 0;
CL_CONTEXT_PLATFORM, (cl_context_properties) platform, std::vector<cl_device_id> deviceIds;
0
}; // Try to get a GPU first
error = clGetDeviceIDs(platformIds[1], CL_DEVICE_TYPE_GPU, 0, nullptr,
#elif defined TARGET_OS_MAC &deviceIdCount);
CGLContextObj glContext = CGLGetCurrentContext();
CGLShareGroupObj shareGroup = CGLGetShareGroup(glContext);
cl_context_properties context_properties[] = { if (deviceIdCount == 0) {
CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE, std::cout << "couldn't acquire a GPU, falling back to CPU" << std::endl;
(cl_context_properties)shareGroup, error = clGetDeviceIDs(platformIds[1], CL_DEVICE_TYPE_CPU, 0, nullptr, &deviceIdCount);
0 deviceIds.resize(deviceIdCount);
}; error = clGetDeviceIDs(platformIds[1], CL_DEVICE_TYPE_CPU, deviceIdCount, deviceIds.data(), NULL);
} else {
#endif std::cout << "acquired GPU cl target" << std::endl;
deviceIds.resize(deviceIdCount);
// Create our shared context clGetDeviceIDs (platformIds[1], CL_DEVICE_TYPE_GPU, deviceIdCount, deviceIds.data (), nullptr);
auto context = clCreateContext( }
context_properties,
deviceIdCount,
deviceIds.data(),
nullptr, nullptr, if (error != 0){
&error std::cout << "Err: clGetDeviceIDs returned: " << error << std::endl;
); return error;
}
if (error != 0){
std::cout << "Err: clCreateContext returned: " << error << std::endl; // Hurray for standards!
return error; // Setup the context properties to grab the current GL context
} #ifdef linux
cl_context_properties context_properties[] = {
// And the cl command queue CL_GL_CONTEXT_KHR, (cl_context_properties) glXGetCurrentContext(),
auto commandQueue = clCreateCommandQueue(context, deviceIds[0], 0, &error); CL_GLX_DISPLAY_KHR, (cl_context_properties) glXGetCurrentDisplay(),
CL_CONTEXT_PLATFORM, (cl_context_properties) platform,
if (error != 0){ 0
std::cout << "Err: clCreateCommandQueue returned: " << error << std::endl; };
return error;
} #elif defined _WIN32
//cl_context_properties context_properties[] = {
// At this point the shared GL/CL context is up and running // CL_CONTEXT_PLATFORM, (cl_context_properties) platformIds[0],
// ====================================================================== // // CL_GL_CONTEXT_KHR, (cl_context_properties) wglGetCurrentContext(),
// ========== Kernel setup & compilation // CL_WGL_HDC_KHR, (cl_context_properties) wglGetCurrentDC(),
// 0
// Load in the kernel, and c stringify it //};
std::string kernel_source; HGLRC hGLRC = wglGetCurrentContext();
kernel_source = read_file("../kernels/kernel.txt"); HDC hDC = wglGetCurrentDC();
const char* kernel_source_c_str = kernel_source.c_str(); cl_context_properties context_properties[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)platformIds[1], CL_GL_CONTEXT_KHR, (cl_context_properties)hGLRC, CL_WGL_HDC_KHR, (cl_context_properties)hDC, 0 };
size_t kernel_source_size = strlen(kernel_source_c_str);
#elif defined TARGET_OS_MAC
// Load the source into CL's data structure CGLContextObj glContext = CGLGetCurrentContext();
cl_program kernel_program = clCreateProgramWithSource( CGLShareGroupObj shareGroup = CGLGetShareGroup(glContext);
context, 1, cl_context_properties context_properties[] = {
&kernel_source_c_str, CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE,
&kernel_source_size, &error (cl_context_properties)shareGroup,
); 0
};
if (error != 0){
std::cout << "Err: clCreateProgramWithSource returned: " << error << std::endl; #endif
return error;
} // Create our shared context
auto context = clCreateContext(
context_properties,
// Try and build the program 1,
error = clBuildProgram(kernel_program, 1, &deviceIds[0], NULL, NULL, NULL); &deviceIds[0],
nullptr, nullptr,
// Check to see if it errored out &error
if (error == CL_BUILD_PROGRAM_FAILURE){ );
// Get the size of the queued log
size_t log_size; //cl_device_id devices[32];
clGetProgramBuildInfo(kernel_program, deviceIds[0], CL_PROGRAM_BUILD_LOG, 0, NULL, &log_size); //size_t size;
char *log = new char[log_size]; //clGetGLContextInfoKHR(context_properties, CL_DEVICES_FOR_GL_CONTEXT_KHR,
// 32 * sizeof(cl_device_id), devices, &size);
// Grab the log
clGetProgramBuildInfo(kernel_program, deviceIds[0], CL_PROGRAM_BUILD_LOG, log_size, log, NULL); if (error != 0){
std::cout << "Err: clCreateContext returned: " << error << std::endl;
return error;
std::cout << "Err: clBuildProgram returned: " << error << std::endl; }
std::cout << log << std::endl;
return error; // And the cl command queue
} auto commandQueue = clCreateCommandQueue(context, deviceIds[0], 0, &error);
// Done initializing the kernel if (error != 0){
cl_kernel finished_kernel = clCreateKernel(kernel_program, "kernel_name", &error); std::cout << "Err: clCreateCommandQueue returned: " << error << std::endl;
return error;
if (error != 0){ }
std::cout << "Err: clCreateKernel returned: " << error << std::endl;
return error; // At this point the shared GL/CL context is up and running
} // ====================================================================== //
// ========== Kernel setup & compilation
};
// Load in the kernel, and c stringify it
std::string kernel_source;
kernel_source = read_file("../kernels/kernel.txt");
const char* kernel_source_c_str = kernel_source.c_str();
size_t kernel_source_size = strlen(kernel_source_c_str);
float elap_time(){
static std::chrono::time_point<std::chrono::system_clock> start; // Load the source into CL's data structure
static bool started = false; cl_program kernel_program = clCreateProgramWithSource(
context, 1,
if (!started){ &kernel_source_c_str,
start = std::chrono::system_clock::now(); &kernel_source_size, &error
started = true; );
}
if (error != 0){
std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now(); std::cout << "Err: clCreateProgramWithSource returned: " << error << std::endl;
std::chrono::duration<double> elapsed_time = now - start; return error;
return elapsed_time.count(); }
}
sf::Sprite window_sprite; // Try and build the program
sf::Texture window_texture; error = clBuildProgram(kernel_program, 1, &deviceIds[0], NULL, NULL, NULL);
// Y: -1.57 is straight up // Check to see if it errored out
// Y: 1.57 is straight down if (error == CL_BUILD_PROGRAM_FAILURE){
void test_ray_reflection(){ // Get the size of the queued log
size_t log_size;
sf::Vector3f r(0.588, -0.78, -0.196); clGetProgramBuildInfo(kernel_program, deviceIds[0], CL_PROGRAM_BUILD_LOG, 0, NULL, &log_size);
sf::Vector3f i(0, 0.928, 0.37); char *log = new char[log_size];
// is this needed? free spin but bounded 0 < z < pi // Grab the log
if (i.z > PI) clGetProgramBuildInfo(kernel_program, deviceIds[0], CL_PROGRAM_BUILD_LOG, log_size, log, NULL);
i.z -= PI;
else if (i.z < 0)
i.z += PI; std::cout << "Err: clBuildProgram returned: " << error << std::endl;
std::cout << log << std::endl;
std::cout << AngleBetweenVectors(r, i); return error;
}
// Done initializing the kernel
return; cl_kernel finished_kernel = clCreateKernel(kernel_program, "kernel_name", &error);
}
if (error != 0){
int main0() { std::cout << "Err: clCreateKernel returned: " << error << std::endl;
return error;
// Initialize the render window }
Curses curse(sf::Vector2i(5, 5), sf::Vector2i(WINDOW_X, WINDOW_Y));
sf::RenderWindow window(sf::VideoMode(WINDOW_X, WINDOW_Y), "SFML"); };
// The step size in milliseconds between calls to Update()
// Lets set it to 16.6 milliseonds (60FPS)
float step_size = 0.0166f;
float elap_time(){
// Timekeeping values for the loop static std::chrono::time_point<std::chrono::system_clock> start;
double frame_time = 0.0, static bool started = false;
elapsed_time = 0.0,
delta_time = 0.0, if (!started){
accumulator_time = 0.0, start = std::chrono::system_clock::now();
current_time = 0.0; started = true;
}
fps_counter fps;
std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now();
// ============================= RAYCASTER SETUP ================================== std::chrono::duration<double> elapsed_time = now - start;
return elapsed_time.count();
// Setup the sprite and texture }
window_texture.create(WINDOW_X, WINDOW_Y);
window_sprite.setPosition(0, 0); sf::Sprite window_sprite;
sf::Texture window_texture;
// State values
sf::Vector3i map_dim(100, 100, 100); // Y: -1.57 is straight up
sf::Vector2i view_res(WINDOW_X, WINDOW_Y); // Y: 1.57 is straight down
sf::Vector3f cam_dir(1.0f, 0.0f, 1.57f);
sf::Vector3f cam_pos(50, 50, 50); void test_ray_reflection(){
sf::Vector3f cam_vec(0, 0, 0);
Map* map = new Map(map_dim); sf::Vector3f r(0.588, -0.78, -0.196);
RayCaster ray_caster(map, map_dim, view_res); sf::Vector3f i(0, 0.928, 0.37);
// is this needed? free spin but bounded 0 < z < pi
// =============================================================================== if (i.z > PI)
i.z -= PI;
// Mouse capture else if (i.z < 0)
sf::Vector2i deltas; i.z += PI;
sf::Vector2i fixed(window.getSize());
bool mouse_enabled = true; std::cout << AngleBetweenVectors(r, i);
while (window.isOpen()) {
// Poll for events from the user return;
sf::Event event; }
while (window.pollEvent(event)) {
int main0() {
// If the user tries to exit the application via the GUI
if (event.type == sf::Event::Closed) // Initialize the render window
window.close(); Curses curse(sf::Vector2i(5, 5), sf::Vector2i(WINDOW_X, WINDOW_Y));
} sf::RenderWindow window(sf::VideoMode(WINDOW_X, WINDOW_Y), "SFML");
cam_vec.x = 0;
cam_vec.y = 0;
cam_vec.z = 0; // The step size in milliseconds between calls to Update()
// Lets set it to 16.6 milliseonds (60FPS)
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Q)) { float step_size = 0.0166f;
cam_vec.z = 1;
} // Timekeeping values for the loop
if (sf::Keyboard::isKeyPressed(sf::Keyboard::E)) { double frame_time = 0.0,
cam_vec.z = -1; elapsed_time = 0.0,
} delta_time = 0.0,
if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)) { accumulator_time = 0.0,
cam_vec.y = 1; current_time = 0.0;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)) { fps_counter fps;
cam_vec.y = -1;
} // ============================= RAYCASTER SETUP ==================================
if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
cam_vec.x = 1; // Setup the sprite and texture
} window_texture.create(WINDOW_X, WINDOW_Y);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) { window_sprite.setPosition(0, 0);
cam_vec.x = -1;
} // State values
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { sf::Vector3i map_dim(100, 100, 100);
cam_dir.z = -0.1f; sf::Vector2i view_res(WINDOW_X, WINDOW_Y);
} sf::Vector3f cam_dir(1.0f, 0.0f, 1.57f);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { sf::Vector3f cam_pos(50, 50, 50);
cam_vec.z = +0.1f; sf::Vector3f cam_vec(0, 0, 0);
} Map* map = new Map(map_dim);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { RayCaster ray_caster(map, map_dim, view_res);
cam_vec.y = +0.1f;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) { // ===============================================================================
cam_vec.y = -0.1f;
} // Mouse capture
sf::Vector2i deltas;
deltas = fixed - sf::Mouse::getPosition(); sf::Vector2i fixed(window.getSize());
if (deltas != sf::Vector2i(0, 0) && mouse_enabled == true) { bool mouse_enabled = true;
// Mouse movement while (window.isOpen()) {
sf::Mouse::setPosition(fixed);
cam_dir.y -= deltas.y / 300.0f; // Poll for events from the user
cam_dir.z -= deltas.x / 300.0f; sf::Event event;
} while (window.pollEvent(event)) {
cam_pos.x += cam_vec.x / 1.0; // If the user tries to exit the application via the GUI
cam_pos.y += cam_vec.y / 1.0; if (event.type == sf::Event::Closed)
cam_pos.z += cam_vec.z / 1.0; window.close();
}
// if (cam_vec.x > 0.0f)
// cam_vec.x -= 0.1; cam_vec.x = 0;
// else if (cam_vec.x < 0.0f) cam_vec.y = 0;
// cam_vec.x += 0.1; cam_vec.z = 0;
//
// if (cam_vec.y > 0.0f) if (sf::Keyboard::isKeyPressed(sf::Keyboard::Q)) {
// cam_vec.y -= 0.1; cam_vec.z = 1;
// else if (cam_vec.y < 0.0f) }
// cam_vec.y += 0.1; if (sf::Keyboard::isKeyPressed(sf::Keyboard::E)) {
// cam_vec.z = -1;
// if (cam_vec.z > 0.0f) }
// cam_vec.z -= 0.1; if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)) {
// else if (cam_vec.z < 0.0f) cam_vec.y = 1;
// cam_vec.z += 0.1; }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)) {
std::cout << cam_vec.x << " : " << cam_vec.y << " : " << cam_vec.z << std::endl; cam_vec.y = -1;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
// Time keeping cam_vec.x = 1;
elapsed_time = elap_time(); }
delta_time = elapsed_time - current_time; if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
current_time = elapsed_time; cam_vec.x = -1;
if (delta_time > 0.2f) }
delta_time = 0.2f; if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
accumulator_time += delta_time; cam_dir.z = -0.1f;
while ((accumulator_time - step_size) >= step_size) { }
accumulator_time -= step_size; if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
cam_vec.z = +0.1f;
}
// Update cycle if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
curse.Update(delta_time); cam_vec.y = +0.1f;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
} cam_vec.y = -0.1f;
}
// Fps cycle
// map->moveLight(sf::Vector2f(0.3, 0)); deltas = fixed - sf::Mouse::getPosition();
if (deltas != sf::Vector2i(0, 0) && mouse_enabled == true) {
window.clear(sf::Color::Black);
// Mouse movement
// Cast the rays and get the image sf::Mouse::setPosition(fixed);
sf::Color* pixel_colors = ray_caster.CastRays(cam_dir, cam_pos); cam_dir.y -= deltas.y / 300.0f;
cam_dir.z -= deltas.x / 300.0f;
for (int i = 0; i < WINDOW_X * WINDOW_Y; i++) { }
Curses::Tile t(sf::Vector2i(i % WINDOW_X, i / WINDOW_X)); cam_pos.x += cam_vec.x / 1.0;
Curses::Slot s(L'\u0045', pixel_colors[i], sf::Color::Black); cam_pos.y += cam_vec.y / 1.0;
t.push_back(s); cam_pos.z += cam_vec.z / 1.0;
curse.setTile(t);
// if (cam_vec.x > 0.0f)
} // cam_vec.x -= 0.1;
// else if (cam_vec.x < 0.0f)
// cam_vec.x += 0.1;
// Cast it to an array of Uint8's //
auto out = (sf::Uint8*)pixel_colors; // if (cam_vec.y > 0.0f)
// cam_vec.y -= 0.1;
window_texture.update(out); // else if (cam_vec.y < 0.0f)
window_sprite.setTexture(window_texture); // cam_vec.y += 0.1;
window.draw(window_sprite); //
// if (cam_vec.z > 0.0f)
// cam_vec.z -= 0.1;
curse.Render(); // else if (cam_vec.z < 0.0f)
// cam_vec.z += 0.1;
// Give the frame counter the frame time and draw the average frame time
fps.frame(delta_time); std::cout << cam_vec.x << " : " << cam_vec.y << " : " << cam_vec.z << std::endl;
fps.draw(&window);
window.display(); // Time keeping
elapsed_time = elap_time();
delta_time = elapsed_time - current_time;
current_time = elapsed_time;
} if (delta_time > 0.2f)
return 0; delta_time = 0.2f;
accumulator_time += delta_time;
} while ((accumulator_time - step_size) >= step_size) {
accumulator_time -= step_size;
// Update cycle
curse.Update(delta_time);
}
// Fps cycle
// map->moveLight(sf::Vector2f(0.3, 0));
window.clear(sf::Color::Black);
// Cast the rays and get the image
sf::Color* pixel_colors = ray_caster.CastRays(cam_dir, cam_pos);
for (int i = 0; i < WINDOW_X * WINDOW_Y; i++) {
Curses::Tile t(sf::Vector2i(i % WINDOW_X, i / WINDOW_X));
Curses::Slot s(L'\u0045', pixel_colors[i], sf::Color::Black);
t.push_back(s);
curse.setTile(t);
}
// Cast it to an array of Uint8's
auto out = (sf::Uint8*)pixel_colors;
window_texture.update(out);
window_sprite.setTexture(window_texture);
window.draw(window_sprite);
curse.Render();
// Give the frame counter the frame time and draw the average frame time
fps.frame(delta_time);
fps.draw(&window);
window.display();
}
return 0;
}

Loading…
Cancel
Save