diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..9deab0ab7 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "stdlib.h": "c" + } +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 851ae3ad7..3d487c840 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,29 @@ project(craft) FILE(GLOB SOURCE_FILES src/*.c) +# +#find_package(OpenAL REQUIRED) +#include_directories(${ALUT_INCLUDE_DIR}) +#include_directories(${OPENAL_INCLUDE_DIR}) +#target_link_libraries(craft ${ALUT_LIBRARY}) +#target_link_libraries(craft ${OPENAL_LIBRARY}) +#add_definitions("-DHAVE_OPENAL=1") + +#arget_link_libraries(/usr/include/AL/alut.h) +#link_directories(${OPEN}) +#include_directories(${OPENAL_INCLUDE_DIR}) +#target_link_libraries(${OPENAL_LIBRARY}) +#target_link_libraries(craft /usr/local/include/AL/alut.h) +#et(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++) +#set(CMAKE_C_FLAGS " ${CMAKE_C_FLAGS} --libs=freealut") +#set(GCC_COVERAGE_COMPILE_FLAGS "-lopenal -lm") +#set(GCC_COVERAGE_LINK_FLAGS "-lopenal -lm") +#add_compile_options(--libs=freealut) +#add_definitions(-lopenal -lm) + +#add_subdirectory(/usr/include/AL/) + + add_executable( craft ${SOURCE_FILES} @@ -39,7 +62,7 @@ if(APPLE) endif() if(UNIX) - target_link_libraries(craft dl glfw + target_link_libraries(craft dl glfw ${GLFW_LIBRARIES} ${CURL_LIBRARIES}) endif() @@ -47,3 +70,10 @@ if(MINGW) target_link_libraries(craft ws2_32.lib glfw ${GLFW_LIBRARIES} ${CURL_LIBRARIES}) endif() + +find_package(OpenAL REQUIRED) +include_directories(${ALUT_INCLUDE_DIR}) +include_directories(${OPENAL_INCLUDE_DIR}) +target_link_libraries(craft ${ALUT_LIBRARY}) +target_link_libraries(craft ${OPENAL_LIBRARY}) +add_definitions("-DHAVE_OPENAL=1") \ No newline at end of file diff --git a/deps/glfw/examples/particles b/deps/glfw/examples/particles new file mode 100755 index 000000000..25f936988 Binary files /dev/null and b/deps/glfw/examples/particles differ diff --git a/deps/glfw/src/glfw3Config.cmake b/deps/glfw/src/glfw3Config.cmake new file mode 100644 index 000000000..f41a722a2 --- /dev/null +++ b/deps/glfw/src/glfw3Config.cmake @@ -0,0 +1,29 @@ +# - Config file for the glfw3 package +# It defines the following variables +# GLFW3_INCLUDE_DIR, the path where GLFW headers are located +# GLFW3_LIBRARY_DIR, folder in which the GLFW library is located +# GLFW3_LIBRARY, library to link against to use GLFW + +set(GLFW3_VERSION "3.1.2") + + +####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() ####### +####### Any changes to this file will be overwritten by the next CMake run #### +####### The input file was glfw3Config.cmake.in ######## + +get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE) + +macro(set_and_check _var _file) + set(${_var} "${_file}") + if(NOT EXISTS "${_file}") + message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !") + endif() +endmacro() + +#################################################################################### + +set_and_check(GLFW3_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include") +set_and_check(GLFW3_LIBRARY_DIR "${PACKAGE_PREFIX_DIR}/lib") + +find_library(GLFW3_LIBRARY "glfw3" HINTS ${GLFW3_LIBRARY_DIR}) + diff --git a/deps/glfw/src/glfw3ConfigVersion.cmake b/deps/glfw/src/glfw3ConfigVersion.cmake new file mode 100644 index 000000000..c949894dd --- /dev/null +++ b/deps/glfw/src/glfw3ConfigVersion.cmake @@ -0,0 +1,51 @@ +# This is a basic version file for the Config-mode of find_package(). +# It is used by write_basic_package_version_file() as input file for configure_file() +# to create a version-file which can be installed along a config.cmake file. +# +# The created file sets PACKAGE_VERSION_EXACT if the current version string and +# the requested version string are exactly the same and it sets +# PACKAGE_VERSION_COMPATIBLE if the current version is >= requested version, +# but only if the requested major version is the same as the current one. +# The variable CVF_VERSION must be set before calling configure_file(). + + +set(PACKAGE_VERSION "3.1.2") + +if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) + set(PACKAGE_VERSION_COMPATIBLE FALSE) +else() + + if("3.1.2" MATCHES "^([0-9]+)\\.") + set(CVF_VERSION_MAJOR "${CMAKE_MATCH_1}") + else() + set(CVF_VERSION_MAJOR "3.1.2") + endif() + + if(PACKAGE_FIND_VERSION_MAJOR STREQUAL CVF_VERSION_MAJOR) + set(PACKAGE_VERSION_COMPATIBLE TRUE) + else() + set(PACKAGE_VERSION_COMPATIBLE FALSE) + endif() + + if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION) + set(PACKAGE_VERSION_EXACT TRUE) + endif() +endif() + + +# if the installed project requested no architecture check, don't perform the check +if("FALSE") + return() +endif() + +# if the installed or the using project don't have CMAKE_SIZEOF_VOID_P set, ignore it: +if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "8" STREQUAL "") + return() +endif() + +# check that the installed version has the same 32/64bit-ness as the one which is currently searching: +if(NOT CMAKE_SIZEOF_VOID_P STREQUAL "8") + math(EXPR installedBits "8 * 8") + set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)") + set(PACKAGE_VERSION_UNSUITABLE TRUE) +endif() diff --git a/deps/glfw/src/glfw_config.h b/deps/glfw/src/glfw_config.h new file mode 100644 index 000000000..dd3ef5448 --- /dev/null +++ b/deps/glfw/src/glfw_config.h @@ -0,0 +1,81 @@ +//======================================================================== +// GLFW 3.1 - www.glfw.org +//------------------------------------------------------------------------ +// Copyright (c) 2010 Camilla Berglund +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would +// be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not +// be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source +// distribution. +// +//======================================================================== +// As glfw_config.h.in, this file is used by CMake to produce the +// glfw_config.h configuration header file. If you are adding a feature +// requiring conditional compilation, this is where to add the macro. +//======================================================================== +// As glfw_config.h, this file defines compile-time option macros for a +// specific platform and development environment. If you are using the +// GLFW CMake files, modify glfw_config.h.in instead of this file. If you +// are using your own build system, make this file define the appropriate +// macros in whatever way is suitable. +//======================================================================== + +// Define this to 1 if building GLFW for X11 +#define _GLFW_X11 +// Define this to 1 if building GLFW for Win32 +/* #undef _GLFW_WIN32 */ +// Define this to 1 if building GLFW for Cocoa +/* #undef _GLFW_COCOA */ +// Define this to 1 if building GLFW for Wayland +/* #undef _GLFW_WAYLAND */ +// Define this to 1 if building GLFW for Mir +/* #undef _GLFW_MIR */ + +// Define this to 1 if building GLFW for EGL +/* #undef _GLFW_EGL */ +// Define this to 1 if building GLFW for GLX +#define _GLFW_GLX +// Define this to 1 if building GLFW for WGL +/* #undef _GLFW_WGL */ +// Define this to 1 if building GLFW for NSGL +/* #undef _GLFW_NSGL */ + +// Define this to 1 if building as a shared library / dynamic library / DLL +/* #undef _GLFW_BUILD_DLL */ + +// Define this to 1 to force use of high-performance GPU on hybrid systems +/* #undef _GLFW_USE_HYBRID_HPG */ + +// Define this to 1 if the XInput X11 extension is available +#define _GLFW_HAS_XINPUT +// Define this to 1 if the Xxf86vm X11 extension is available +#define _GLFW_HAS_XF86VM + +// Define this to 1 if glfwInit should change the current directory +/* #undef _GLFW_USE_CHDIR */ +// Define this to 1 if glfwCreateWindow should populate the menu bar +/* #undef _GLFW_USE_MENUBAR */ +// Define this to 1 if windows should use full resolution on Retina displays +/* #undef _GLFW_USE_RETINA */ + +// Define this to 1 if using OpenGL as the client library +#define _GLFW_USE_OPENGL +// Define this to 1 if using OpenGL ES 1.1 as the client library +/* #undef _GLFW_USE_GLESV1 */ +// Define this to 1 if using OpenGL ES 2.0 as the client library +/* #undef _GLFW_USE_GLESV2 */ + diff --git a/deps/glfw/tests/cursor b/deps/glfw/tests/cursor new file mode 100755 index 000000000..fbbca16e1 Binary files /dev/null and b/deps/glfw/tests/cursor differ diff --git a/deps/glfw/tests/empty b/deps/glfw/tests/empty new file mode 100755 index 000000000..3c39b887d Binary files /dev/null and b/deps/glfw/tests/empty differ diff --git a/deps/glfw/tests/monitors b/deps/glfw/tests/monitors new file mode 100755 index 000000000..ad4f135ca Binary files /dev/null and b/deps/glfw/tests/monitors differ diff --git a/deps/glfw/tests/msaa b/deps/glfw/tests/msaa new file mode 100755 index 000000000..0d815c704 Binary files /dev/null and b/deps/glfw/tests/msaa differ diff --git a/install_manifest.txt b/install_manifest.txt new file mode 100644 index 000000000..6bdd79e60 --- /dev/null +++ b/install_manifest.txt @@ -0,0 +1,8 @@ +/usr/local/include/GLFW/glfw3.h +/usr/local/include/GLFW/glfw3native.h +/usr/local/lib/cmake/glfw/glfw3Config.cmake +/usr/local/lib/cmake/glfw/glfw3ConfigVersion.cmake +/usr/local/lib/cmake/glfw/glfwTargets.cmake +/usr/local/lib/cmake/glfw/glfwTargets-noconfig.cmake +/usr/local/lib/pkgconfig/glfw3.pc +/usr/local/lib/libglfw3.a \ No newline at end of file diff --git a/src/config.h b/src/config.h index 599bbc181..5d6a36c36 100644 --- a/src/config.h +++ b/src/config.h @@ -4,7 +4,7 @@ // app parameters #define DEBUG 0 #define FULLSCREEN 0 -#define WINDOW_WIDTH 1024 +#define WINDOW_WIDTH 1080 #define WINDOW_HEIGHT 768 #define VSYNC 1 #define SCROLL_THRESHOLD 0.1 @@ -37,12 +37,16 @@ #define CRAFT_KEY_OBSERVE_INSET 'P' #define CRAFT_KEY_ITEM_NEXT 'E' #define CRAFT_KEY_ITEM_PREV 'R' -#define CRAFT_KEY_ZOOM GLFW_KEY_LEFT_SHIFT +#define CRAFT_KEY_ZOOM 'Q' +#define CRAFT_KEY_SPRINT GLFW_MOD_SHIFT +#define CRAFT_KEY_END GLFW_KEY_ESCAPE #define CRAFT_KEY_ORTHO 'F' #define CRAFT_KEY_CHAT 't' #define CRAFT_KEY_COMMAND '/' #define CRAFT_KEY_SIGN '`' +// controller keys + // advanced parameters #define CREATE_CHUNK_RADIUS 10 #define RENDER_CHUNK_RADIUS 10 diff --git a/src/linux_sound.c b/src/linux_sound.c new file mode 100644 index 000000000..35b24d9c8 --- /dev/null +++ b/src/linux_sound.c @@ -0,0 +1,11 @@ +void walkSoundStart(){ + system("pkill -CONT play &"); +} + +void walkSoundStop(){ + system("pkill -STOP play &"); +} + +void walkSoundInit(){ + system("play -q ./step_sound.wav repeat 99999 &"); +} \ No newline at end of file diff --git a/src/main.c b/src/main.c index a0b622861..3d86427b8 100644 --- a/src/main.c +++ b/src/main.c @@ -20,6 +20,11 @@ #include "util.h" #include "world.h" +#include +//#include "al.h" +#include +#include + #define MAX_CHUNKS 8192 #define MAX_PLAYERS 128 #define WORKERS 4 @@ -2408,7 +2413,7 @@ void handle_mouse_input() { } } -void handle_movement(double dt) { +void handle_movement(double dt, ALuint *walk_buffer, clock_t *walk_timestamp) { static float dy = 0; State *s = &g->players->state; int sz = 0; @@ -2417,7 +2422,25 @@ void handle_movement(double dt) { float m = dt * 1.0; g->ortho = glfwGetKey(g->window, CRAFT_KEY_ORTHO) ? 64 : 0; g->fov = glfwGetKey(g->window, CRAFT_KEY_ZOOM) ? 15 : 65; - if (glfwGetKey(g->window, CRAFT_KEY_FORWARD)) sz--; + if (glfwGetKey(g->window, CRAFT_KEY_FORWARD)){ + ALuint walk; + ALuint state = AL_FALSE; + + + alGetError(); + + //buffer = alutCreateBufferFromFile("step_sound.wav"); + alGenSources(1, &walk); + alSourcei(walk, AL_BUFFER, *walk_buffer); + if(clock() > (*walk_timestamp+CLOCKS_PER_SEC) ){ + //alSourcePlay(walk); + system("pkill -CONT play &"); + *walk_timestamp = clock(); + } + sz--; + } else { + system("pkill -STOP play &"); + } if (glfwGetKey(g->window, CRAFT_KEY_BACKWARD)) sz++; if (glfwGetKey(g->window, CRAFT_KEY_LEFT)) sx--; if (glfwGetKey(g->window, CRAFT_KEY_RIGHT)) sx++; @@ -2584,7 +2607,32 @@ void reset_model() { } int main(int argc, char **argv) { - // INITIALIZATION // + ALuint ambient_buffer, ambient, walk; + ALuint state = AL_TRUE; + + // Initialize the environment + alutInit(0, NULL); + + alGetError(); + ALuint walk_buffer = alutCreateBufferFromFile("step_sound.wav"); + //Ambient sound prep and play + ambient_buffer = alutCreateBufferFromFile("test.wav"); + alGenSources(1, &ambient); + alSourcei(ambient, AL_BUFFER, ambient_buffer); + alSourcei(ambient, AL_LOOPING, AL_TRUE); + alSourcePlay(ambient); + //alGetSourcei(ambient, AL_SOURCE_STATE, &state); + system("play -q ./step_sound.wav repeat 99999 &"); + system("pkill -STOP play &"); + + clock_t walk_timestamp = clock(); + + /*//Walk sound prep + buffer = alutCreateBufferFromFile("../step_sound.wav"); + alGenSources(1, &ambient); + alSourcei(ambient, AL_BUFFER, buffer); + alGetSourcei(ambient, AL_SOURCE_STATE, &state); +*/ curl_global_init(CURL_GLOBAL_DEFAULT); srand(time(NULL)); rand(); @@ -2797,7 +2845,7 @@ int main(int argc, char **argv) { handle_mouse_input(); // HANDLE MOVEMENT // - handle_movement(dt); + handle_movement(dt, &walk_buffer, &walk_timestamp); // HANDLE DATA FROM SERVER // char *buffer = client_recv(); @@ -2957,6 +3005,7 @@ int main(int argc, char **argv) { delete_all_players(); } + alutExit(); glfwTerminate(); curl_global_cleanup(); return 0; diff --git a/step_sound.wav b/step_sound.wav new file mode 100644 index 000000000..054d8df42 Binary files /dev/null and b/step_sound.wav differ diff --git a/test.wav b/test.wav new file mode 100644 index 000000000..47842ede0 Binary files /dev/null and b/test.wav differ