Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"stdlib.h": "c"
}
}
32 changes: 31 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -39,11 +62,18 @@ if(APPLE)
endif()

if(UNIX)
target_link_libraries(craft dl glfw
target_link_libraries(craft dl glfw
${GLFW_LIBRARIES} ${CURL_LIBRARIES})
endif()

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")
Binary file added deps/glfw/examples/particles
Binary file not shown.
29 changes: 29 additions & 0 deletions deps/glfw/src/glfw3Config.cmake
Original file line number Diff line number Diff line change
@@ -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})

51 changes: 51 additions & 0 deletions deps/glfw/src/glfw3ConfigVersion.cmake
Original file line number Diff line number Diff line change
@@ -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()
81 changes: 81 additions & 0 deletions deps/glfw/src/glfw_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//========================================================================
// GLFW 3.1 - www.glfw.org
//------------------------------------------------------------------------
// Copyright (c) 2010 Camilla Berglund <elmindreda@elmindreda.org>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would
// be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
//========================================================================
// 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 */

Binary file added deps/glfw/tests/cursor
Binary file not shown.
Binary file added deps/glfw/tests/empty
Binary file not shown.
Binary file added deps/glfw/tests/monitors
Binary file not shown.
Binary file added deps/glfw/tests/msaa
Binary file not shown.
8 changes: 8 additions & 0 deletions install_manifest.txt
Original file line number Diff line number Diff line change
@@ -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
8 changes: 6 additions & 2 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/linux_sound.c
Original file line number Diff line number Diff line change
@@ -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 &");
}
57 changes: 53 additions & 4 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
#include "util.h"
#include "world.h"

#include <AL/al.h>
//#include "al.h"
#include <AL/alc.h>
#include <AL/alut.h>

#define MAX_CHUNKS 8192
#define MAX_PLAYERS 128
#define WORKERS 4
Expand Down Expand Up @@ -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;
Expand All @@ -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++;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -2957,6 +3005,7 @@ int main(int argc, char **argv) {
delete_all_players();
}

alutExit();
glfwTerminate();
curl_global_cleanup();
return 0;
Expand Down
Binary file added step_sound.wav
Binary file not shown.
Binary file added test.wav
Binary file not shown.