commit
18fcf3f141
@ -7,29 +7,40 @@ file(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
|
|||||||
add_executable(${PROJECT_NAME} ${HEADERS} ${SOURCES})
|
add_executable(${PROJECT_NAME} ${HEADERS} ${SOURCES})
|
||||||
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
|
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
|
||||||
|
|
||||||
option(VE_USE_SYSTEM_LIBS "Use system installed libraries" ON)
|
if(MSVC)
|
||||||
|
target_compile_options(${PROJECT_NAME} PRIVATE /W4)
|
||||||
|
else()
|
||||||
|
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra
|
||||||
|
# additional warnings
|
||||||
|
-Wformat-nonliteral -Wcast-align
|
||||||
|
-Wpointer-arith -Winline -Wundef
|
||||||
|
-Wwrite-strings -Wno-unused-parameter)
|
||||||
|
endif()
|
||||||
|
|
||||||
find_package(OpenGL REQUIRED)
|
find_package(OpenGL REQUIRED)
|
||||||
find_package(GLEW REQUIRED)
|
find_package(GLEW REQUIRED)
|
||||||
find_package(OpenAL REQUIRED)
|
find_package(OpenAL REQUIRED)
|
||||||
find_package(PNG REQUIRED)
|
|
||||||
|
if (WIN32)
|
||||||
|
set(PNGLIB spng)
|
||||||
|
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libs/glfw)
|
||||||
|
else()
|
||||||
|
find_package(PNG REQUIRED)
|
||||||
|
set(PNGLIB PNG::PNG)
|
||||||
|
endif(WIN32)
|
||||||
|
|
||||||
set(LIBS "")
|
set(LIBS "")
|
||||||
if(NOT VE_USE_SYSTEM_LIBS)
|
|
||||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libs/glfw)
|
|
||||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libs/glm)
|
|
||||||
set(LIBS glm)
|
|
||||||
else()
|
|
||||||
find_package(glfw3 REQUIRED)
|
|
||||||
find_package(glm REQUIRED)
|
|
||||||
endif(NOT VE_USE_SYSTEM_LIBS)
|
|
||||||
|
|
||||||
if(UNIX)
|
if(UNIX)
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
set(LIBS ${LIBS} Threads::Threads)
|
set(LIBS ${LIBS} Threads::Threads)
|
||||||
endif(UNIX)
|
endif(UNIX)
|
||||||
|
|
||||||
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||||
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -no-pie")
|
||||||
|
endif()
|
||||||
|
|
||||||
target_link_libraries(${PROJECT_NAME} ${LIBS} glfw OpenGL::GL ${OPENAL_LIBRARY} GLEW::GLEW PNG::PNG)
|
|
||||||
|
target_link_libraries(${PROJECT_NAME} ${LIBS} glfw OpenGL::GL ${OPENAL_LIBRARY} GLEW::GLEW ${PNGLIB})
|
||||||
|
|
||||||
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/res DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/build)
|
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/res DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/build)
|
||||||
|
|||||||
@ -1,82 +0,0 @@
|
|||||||
################################################################################
|
|
||||||
# Automatically-generated file. Do not edit!
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
-include ../makefile.init
|
|
||||||
|
|
||||||
RM := rm -rf
|
|
||||||
|
|
||||||
# All of the sources participating in the build are defined here
|
|
||||||
-include sources.mk
|
|
||||||
-include src/world/subdir.mk
|
|
||||||
-include src/window/subdir.mk
|
|
||||||
-include src/voxels/subdir.mk
|
|
||||||
-include src/physics/subdir.mk
|
|
||||||
-include src/objects/subdir.mk
|
|
||||||
-include src/loaders/subdir.mk
|
|
||||||
-include src/lighting/subdir.mk
|
|
||||||
-include src/graphics/subdir.mk
|
|
||||||
-include src/files/subdir.mk
|
|
||||||
-include src/audio/subdir.mk
|
|
||||||
-include src/subdir.mk
|
|
||||||
-include subdir.mk
|
|
||||||
-include objects.mk
|
|
||||||
|
|
||||||
ifneq ($(MAKECMDGOALS),clean)
|
|
||||||
ifneq ($(strip $(CC_DEPS)),)
|
|
||||||
-include $(CC_DEPS)
|
|
||||||
endif
|
|
||||||
ifneq ($(strip $(C++_DEPS)),)
|
|
||||||
-include $(C++_DEPS)
|
|
||||||
endif
|
|
||||||
ifneq ($(strip $(C_UPPER_DEPS)),)
|
|
||||||
-include $(C_UPPER_DEPS)
|
|
||||||
endif
|
|
||||||
ifneq ($(strip $(CXX_DEPS)),)
|
|
||||||
-include $(CXX_DEPS)
|
|
||||||
endif
|
|
||||||
ifneq ($(strip $(C_DEPS)),)
|
|
||||||
-include $(C_DEPS)
|
|
||||||
endif
|
|
||||||
ifneq ($(strip $(CPP_DEPS)),)
|
|
||||||
-include $(CPP_DEPS)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
-include ../makefile.defs
|
|
||||||
|
|
||||||
OPTIONAL_TOOL_DEPS := \
|
|
||||||
$(wildcard ../makefile.defs) \
|
|
||||||
$(wildcard ../makefile.init) \
|
|
||||||
$(wildcard ../makefile.targets) \
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_ARTIFACT_NAME := voxel_engine
|
|
||||||
BUILD_ARTIFACT_EXTENSION :=
|
|
||||||
BUILD_ARTIFACT_PREFIX :=
|
|
||||||
BUILD_ARTIFACT := $(BUILD_ARTIFACT_PREFIX)$(BUILD_ARTIFACT_NAME)$(if $(BUILD_ARTIFACT_EXTENSION),.$(BUILD_ARTIFACT_EXTENSION),)
|
|
||||||
|
|
||||||
# Add inputs and outputs from these tool invocations to the build variables
|
|
||||||
|
|
||||||
# All Target
|
|
||||||
all: main-build
|
|
||||||
|
|
||||||
# Main-build Target
|
|
||||||
main-build: voxel_engine
|
|
||||||
|
|
||||||
# Tool invocations
|
|
||||||
voxel_engine: $(OBJS) $(USER_OBJS) makefile objects.mk $(OPTIONAL_TOOL_DEPS)
|
|
||||||
@echo 'Building target: $@'
|
|
||||||
@echo 'Invoking: Cross G++ Linker'
|
|
||||||
g++ -pthread -o "voxel_engine" $(OBJS) $(USER_OBJS) $(LIBS)
|
|
||||||
@echo 'Finished building target: $@'
|
|
||||||
@echo ' '
|
|
||||||
|
|
||||||
# Other Targets
|
|
||||||
clean:
|
|
||||||
-$(RM) $(CC_DEPS)$(C++_DEPS)$(EXECUTABLES)$(OBJS)$(C_UPPER_DEPS)$(CXX_DEPS)$(C_DEPS)$(CPP_DEPS) voxel_engine
|
|
||||||
-@echo ' '
|
|
||||||
|
|
||||||
.PHONY: all clean dependents main-build
|
|
||||||
|
|
||||||
-include ../makefile.targets
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
################################################################################
|
|
||||||
# Automatically-generated file. Do not edit!
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
USER_OBJS :=
|
|
||||||
|
|
||||||
LIBS := -lglfw -lpng -lGL -lGLEW -lstdc++fs -lopenal
|
|
||||||
|
|
||||||
@ -1,37 +0,0 @@
|
|||||||
################################################################################
|
|
||||||
# Automatically-generated file. Do not edit!
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
C_UPPER_SRCS :=
|
|
||||||
CXX_SRCS :=
|
|
||||||
C++_SRCS :=
|
|
||||||
OBJ_SRCS :=
|
|
||||||
CC_SRCS :=
|
|
||||||
ASM_SRCS :=
|
|
||||||
C_SRCS :=
|
|
||||||
CPP_SRCS :=
|
|
||||||
O_SRCS :=
|
|
||||||
S_UPPER_SRCS :=
|
|
||||||
CC_DEPS :=
|
|
||||||
C++_DEPS :=
|
|
||||||
EXECUTABLES :=
|
|
||||||
OBJS :=
|
|
||||||
C_UPPER_DEPS :=
|
|
||||||
CXX_DEPS :=
|
|
||||||
C_DEPS :=
|
|
||||||
CPP_DEPS :=
|
|
||||||
|
|
||||||
# Every subdirectory with source files must be described here
|
|
||||||
SUBDIRS := \
|
|
||||||
src \
|
|
||||||
src/audio \
|
|
||||||
src/files \
|
|
||||||
src/graphics \
|
|
||||||
src/lighting \
|
|
||||||
src/loaders \
|
|
||||||
src/objects \
|
|
||||||
src/physics \
|
|
||||||
src/voxels \
|
|
||||||
src/window \
|
|
||||||
src/world \
|
|
||||||
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
################################################################################
|
|
||||||
# Automatically-generated file. Do not edit!
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
# Add inputs and outputs from these tool invocations to the build variables
|
|
||||||
CPP_SRCS += \
|
|
||||||
../src/audio/Audio.cpp \
|
|
||||||
../src/audio/audioutil.cpp
|
|
||||||
|
|
||||||
OBJS += \
|
|
||||||
./src/audio/Audio.o \
|
|
||||||
./src/audio/audioutil.o
|
|
||||||
|
|
||||||
CPP_DEPS += \
|
|
||||||
./src/audio/Audio.d \
|
|
||||||
./src/audio/audioutil.d
|
|
||||||
|
|
||||||
|
|
||||||
# Each subdirectory must supply rules for building sources it contributes
|
|
||||||
src/audio/%.o: ../src/audio/%.cpp src/audio/subdir.mk
|
|
||||||
@echo 'Building file: $<'
|
|
||||||
@echo 'Invoking: Cross G++ Compiler'
|
|
||||||
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
|
|
||||||
@echo 'Finished building: $<'
|
|
||||||
@echo ' '
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
################################################################################
|
|
||||||
# Automatically-generated file. Do not edit!
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
# Add inputs and outputs from these tool invocations to the build variables
|
|
||||||
CPP_SRCS += \
|
|
||||||
../src/files/WorldFiles.cpp \
|
|
||||||
../src/files/files.cpp
|
|
||||||
|
|
||||||
OBJS += \
|
|
||||||
./src/files/WorldFiles.o \
|
|
||||||
./src/files/files.o
|
|
||||||
|
|
||||||
CPP_DEPS += \
|
|
||||||
./src/files/WorldFiles.d \
|
|
||||||
./src/files/files.d
|
|
||||||
|
|
||||||
|
|
||||||
# Each subdirectory must supply rules for building sources it contributes
|
|
||||||
src/files/%.o: ../src/files/%.cpp src/files/subdir.mk
|
|
||||||
@echo 'Building file: $<'
|
|
||||||
@echo 'Invoking: Cross G++ Compiler'
|
|
||||||
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
|
|
||||||
@echo 'Finished building: $<'
|
|
||||||
@echo ' '
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,54 +0,0 @@
|
|||||||
################################################################################
|
|
||||||
# Automatically-generated file. Do not edit!
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
# Add inputs and outputs from these tool invocations to the build variables
|
|
||||||
CPP_SRCS += \
|
|
||||||
../src/graphics/Batch2D.cpp \
|
|
||||||
../src/graphics/Batch3D.cpp \
|
|
||||||
../src/graphics/Font.cpp \
|
|
||||||
../src/graphics/LineBatch.cpp \
|
|
||||||
../src/graphics/Mesh.cpp \
|
|
||||||
../src/graphics/Shader.cpp \
|
|
||||||
../src/graphics/Texture.cpp \
|
|
||||||
../src/graphics/Sprite.cpp \
|
|
||||||
../src/graphics/UVRegion.cpp \
|
|
||||||
../src/graphics/Framebuffer.cpp \
|
|
||||||
../src/graphics/VoxelRenderer.cpp
|
|
||||||
|
|
||||||
OBJS += \
|
|
||||||
./src/graphics/Batch2D.o \
|
|
||||||
./src/graphics/Batch3D.o \
|
|
||||||
./src/graphics/Font.o \
|
|
||||||
./src/graphics/LineBatch.o \
|
|
||||||
./src/graphics/Mesh.o \
|
|
||||||
./src/graphics/Shader.o \
|
|
||||||
./src/graphics/Texture.o \
|
|
||||||
./src/graphics/Sprite.o \
|
|
||||||
./src/graphics/UVRegion.o \
|
|
||||||
./src/graphics/Framebuffer.o \
|
|
||||||
./src/graphics/VoxelRenderer.o
|
|
||||||
|
|
||||||
CPP_DEPS += \
|
|
||||||
./src/graphics/Batch2D.d \
|
|
||||||
./src/graphics/Batch3D.d \
|
|
||||||
./src/graphics/Font.d \
|
|
||||||
./src/graphics/LineBatch.d \
|
|
||||||
./src/graphics/Mesh.d \
|
|
||||||
./src/graphics/Shader.d \
|
|
||||||
./src/graphics/Texture.d \
|
|
||||||
./src/graphics/Sprite.d \
|
|
||||||
./src/graphics/UVRegion.d \
|
|
||||||
./src/graphics/Framebuffer.d \
|
|
||||||
./src/graphics/VoxelRenderer.d
|
|
||||||
|
|
||||||
|
|
||||||
# Each subdirectory must supply rules for building sources it contributes
|
|
||||||
src/graphics/%.o: ../src/graphics/%.cpp src/graphics/subdir.mk
|
|
||||||
@echo 'Building file: $<'
|
|
||||||
@echo 'Invoking: Cross G++ Compiler'
|
|
||||||
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
|
|
||||||
@echo 'Finished building: $<'
|
|
||||||
@echo ' '
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
################################################################################
|
|
||||||
# Automatically-generated file. Do not edit!
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
# Add inputs and outputs from these tool invocations to the build variables
|
|
||||||
CPP_SRCS += \
|
|
||||||
../src/lighting/LightSolver.cpp \
|
|
||||||
../src/lighting/Lighting.cpp \
|
|
||||||
../src/lighting/Lightmap.cpp
|
|
||||||
|
|
||||||
OBJS += \
|
|
||||||
./src/lighting/LightSolver.o \
|
|
||||||
./src/lighting/Lighting.o \
|
|
||||||
./src/lighting/Lightmap.o
|
|
||||||
|
|
||||||
CPP_DEPS += \
|
|
||||||
./src/lighting/LightSolver.d \
|
|
||||||
./src/lighting/Lighting.d \
|
|
||||||
./src/lighting/Lightmap.d
|
|
||||||
|
|
||||||
|
|
||||||
# Each subdirectory must supply rules for building sources it contributes
|
|
||||||
src/lighting/%.o: ../src/lighting/%.cpp src/lighting/subdir.mk
|
|
||||||
@echo 'Building file: $<'
|
|
||||||
@echo 'Invoking: Cross G++ Compiler'
|
|
||||||
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
|
|
||||||
@echo 'Finished building: $<'
|
|
||||||
@echo ' '
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
################################################################################
|
|
||||||
# Automatically-generated file. Do not edit!
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
# Add inputs and outputs from these tool invocations to the build variables
|
|
||||||
CPP_SRCS += \
|
|
||||||
../src/loaders/png_loading.cpp
|
|
||||||
|
|
||||||
OBJS += \
|
|
||||||
./src/loaders/png_loading.o
|
|
||||||
|
|
||||||
CPP_DEPS += \
|
|
||||||
./src/loaders/png_loading.d
|
|
||||||
|
|
||||||
|
|
||||||
# Each subdirectory must supply rules for building sources it contributes
|
|
||||||
src/loaders/%.o: ../src/loaders/%.cpp src/loaders/subdir.mk
|
|
||||||
@echo 'Building file: $<'
|
|
||||||
@echo 'Invoking: Cross G++ Compiler'
|
|
||||||
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
|
|
||||||
@echo 'Finished building: $<'
|
|
||||||
@echo ' '
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
################################################################################
|
|
||||||
# Automatically-generated file. Do not edit!
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
# Add inputs and outputs from these tool invocations to the build variables
|
|
||||||
CPP_SRCS += \
|
|
||||||
../src/objects/Player.cpp
|
|
||||||
|
|
||||||
OBJS += \
|
|
||||||
./src/objects/Player.o
|
|
||||||
|
|
||||||
CPP_DEPS += \
|
|
||||||
./src/objects/Player.d
|
|
||||||
|
|
||||||
|
|
||||||
# Each subdirectory must supply rules for building sources it contributes
|
|
||||||
src/objects/%.o: ../src/objects/%.cpp src/objects/subdir.mk
|
|
||||||
@echo 'Building file: $<'
|
|
||||||
@echo 'Invoking: Cross G++ Compiler'
|
|
||||||
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
|
|
||||||
@echo 'Finished building: $<'
|
|
||||||
@echo ' '
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
################################################################################
|
|
||||||
# Automatically-generated file. Do not edit!
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
# Add inputs and outputs from these tool invocations to the build variables
|
|
||||||
CPP_SRCS += \
|
|
||||||
../src/physics/Hitbox.cpp \
|
|
||||||
../src/physics/PhysicsSolver.cpp
|
|
||||||
|
|
||||||
OBJS += \
|
|
||||||
./src/physics/Hitbox.o \
|
|
||||||
./src/physics/PhysicsSolver.o
|
|
||||||
|
|
||||||
CPP_DEPS += \
|
|
||||||
./src/physics/Hitbox.d \
|
|
||||||
./src/physics/PhysicsSolver.d
|
|
||||||
|
|
||||||
|
|
||||||
# Each subdirectory must supply rules for building sources it contributes
|
|
||||||
src/physics/%.o: ../src/physics/%.cpp src/physics/subdir.mk
|
|
||||||
@echo 'Building file: $<'
|
|
||||||
@echo 'Invoking: Cross G++ Compiler'
|
|
||||||
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
|
|
||||||
@echo 'Finished building: $<'
|
|
||||||
@echo ' '
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,39 +0,0 @@
|
|||||||
################################################################################
|
|
||||||
# Automatically-generated file. Do not edit!
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
# Add inputs and outputs from these tool invocations to the build variables
|
|
||||||
CPP_SRCS += \
|
|
||||||
../src/Assets.cpp \
|
|
||||||
../src/player_control.cpp \
|
|
||||||
../src/hud_render.cpp \
|
|
||||||
../src/world_render.cpp \
|
|
||||||
../src/declarations.cpp \
|
|
||||||
../src/voxel_engine.cpp
|
|
||||||
|
|
||||||
OBJS += \
|
|
||||||
./src/Assets.o \
|
|
||||||
./src/player_control.o \
|
|
||||||
./src/hud_render.o \
|
|
||||||
./src/world_render.o \
|
|
||||||
./src/declarations.o \
|
|
||||||
./src/voxel_engine.o
|
|
||||||
|
|
||||||
CPP_DEPS += \
|
|
||||||
./src/Assets.d \
|
|
||||||
./src/player_control.d \
|
|
||||||
./src/hud_render.d \
|
|
||||||
./src/world_render.d \
|
|
||||||
./src/declarations.d \
|
|
||||||
./src/voxel_engine.d
|
|
||||||
|
|
||||||
|
|
||||||
# Each subdirectory must supply rules for building sources it contributes
|
|
||||||
src/%.o: ../src/%.cpp src/subdir.mk
|
|
||||||
@echo 'Building file: $<'
|
|
||||||
@echo 'Invoking: Cross G++ Compiler'
|
|
||||||
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
|
|
||||||
@echo 'Finished building: $<'
|
|
||||||
@echo ' '
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,42 +0,0 @@
|
|||||||
################################################################################
|
|
||||||
# Automatically-generated file. Do not edit!
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
# Add inputs and outputs from these tool invocations to the build variables
|
|
||||||
CPP_SRCS += \
|
|
||||||
../src/voxels/Block.cpp \
|
|
||||||
../src/voxels/Chunk.cpp \
|
|
||||||
../src/voxels/Chunks.cpp \
|
|
||||||
../src/voxels/ChunksController.cpp \
|
|
||||||
../src/voxels/ChunksLoader.cpp \
|
|
||||||
../src/voxels/WorldGenerator.cpp \
|
|
||||||
../src/voxels/voxel.cpp
|
|
||||||
|
|
||||||
OBJS += \
|
|
||||||
./src/voxels/Block.o \
|
|
||||||
./src/voxels/Chunk.o \
|
|
||||||
./src/voxels/Chunks.o \
|
|
||||||
./src/voxels/ChunksController.o \
|
|
||||||
./src/voxels/ChunksLoader.o \
|
|
||||||
./src/voxels/WorldGenerator.o \
|
|
||||||
./src/voxels/voxel.o
|
|
||||||
|
|
||||||
CPP_DEPS += \
|
|
||||||
./src/voxels/Block.d \
|
|
||||||
./src/voxels/Chunk.d \
|
|
||||||
./src/voxels/Chunks.d \
|
|
||||||
./src/voxels/ChunksController.d \
|
|
||||||
./src/voxels/ChunksLoader.d \
|
|
||||||
./src/voxels/WorldGenerator.d \
|
|
||||||
./src/voxels/voxel.d
|
|
||||||
|
|
||||||
|
|
||||||
# Each subdirectory must supply rules for building sources it contributes
|
|
||||||
src/voxels/%.o: ../src/voxels/%.cpp src/voxels/subdir.mk
|
|
||||||
@echo 'Building file: $<'
|
|
||||||
@echo 'Invoking: Cross G++ Compiler'
|
|
||||||
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
|
|
||||||
@echo 'Finished building: $<'
|
|
||||||
@echo ' '
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
################################################################################
|
|
||||||
# Automatically-generated file. Do not edit!
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
# Add inputs and outputs from these tool invocations to the build variables
|
|
||||||
CPP_SRCS += \
|
|
||||||
../src/window/Camera.cpp \
|
|
||||||
../src/window/Events.cpp \
|
|
||||||
../src/window/Window.cpp
|
|
||||||
|
|
||||||
OBJS += \
|
|
||||||
./src/window/Camera.o \
|
|
||||||
./src/window/Events.o \
|
|
||||||
./src/window/Window.o
|
|
||||||
|
|
||||||
CPP_DEPS += \
|
|
||||||
./src/window/Camera.d \
|
|
||||||
./src/window/Events.d \
|
|
||||||
./src/window/Window.d
|
|
||||||
|
|
||||||
|
|
||||||
# Each subdirectory must supply rules for building sources it contributes
|
|
||||||
src/window/%.o: ../src/window/%.cpp src/window/subdir.mk
|
|
||||||
@echo 'Building file: $<'
|
|
||||||
@echo 'Invoking: Cross G++ Compiler'
|
|
||||||
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
|
|
||||||
@echo 'Finished building: $<'
|
|
||||||
@echo ' '
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
################################################################################
|
|
||||||
# Automatically-generated file. Do not edit!
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
# Add inputs and outputs from these tool invocations to the build variables
|
|
||||||
CPP_SRCS += \
|
|
||||||
../src/world/Level.cpp \
|
|
||||||
../src/world/World.cpp
|
|
||||||
|
|
||||||
OBJS += \
|
|
||||||
./src/world/Level.o \
|
|
||||||
./src/world/World.o
|
|
||||||
|
|
||||||
CPP_DEPS += \
|
|
||||||
./src/world/Level.d \
|
|
||||||
./src/world/World.d
|
|
||||||
|
|
||||||
|
|
||||||
# Each subdirectory must supply rules for building sources it contributes
|
|
||||||
src/world/%.o: ../src/world/%.cpp src/world/subdir.mk
|
|
||||||
@echo 'Building file: $<'
|
|
||||||
@echo 'Invoking: Cross G++ Compiler'
|
|
||||||
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
|
|
||||||
@echo 'Finished building: $<'
|
|
||||||
@echo ' '
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,80 +0,0 @@
|
|||||||
################################################################################
|
|
||||||
# Automatically-generated file. Do not edit!
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
-include ../makefile.init
|
|
||||||
|
|
||||||
RM := rm -rf
|
|
||||||
|
|
||||||
# All of the sources participating in the build are defined here
|
|
||||||
-include sources.mk
|
|
||||||
-include src/window/subdir.mk
|
|
||||||
-include src/voxels/subdir.mk
|
|
||||||
-include src/physics/subdir.mk
|
|
||||||
-include src/objects/subdir.mk
|
|
||||||
-include src/loaders/subdir.mk
|
|
||||||
-include src/lighting/subdir.mk
|
|
||||||
-include src/graphics/subdir.mk
|
|
||||||
-include src/files/subdir.mk
|
|
||||||
-include src/subdir.mk
|
|
||||||
-include subdir.mk
|
|
||||||
-include objects.mk
|
|
||||||
|
|
||||||
ifneq ($(MAKECMDGOALS),clean)
|
|
||||||
ifneq ($(strip $(CC_DEPS)),)
|
|
||||||
-include $(CC_DEPS)
|
|
||||||
endif
|
|
||||||
ifneq ($(strip $(C++_DEPS)),)
|
|
||||||
-include $(C++_DEPS)
|
|
||||||
endif
|
|
||||||
ifneq ($(strip $(C_UPPER_DEPS)),)
|
|
||||||
-include $(C_UPPER_DEPS)
|
|
||||||
endif
|
|
||||||
ifneq ($(strip $(CXX_DEPS)),)
|
|
||||||
-include $(CXX_DEPS)
|
|
||||||
endif
|
|
||||||
ifneq ($(strip $(CPP_DEPS)),)
|
|
||||||
-include $(CPP_DEPS)
|
|
||||||
endif
|
|
||||||
ifneq ($(strip $(C_DEPS)),)
|
|
||||||
-include $(C_DEPS)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
-include ../makefile.defs
|
|
||||||
|
|
||||||
OPTIONAL_TOOL_DEPS := \
|
|
||||||
$(wildcard ../makefile.defs) \
|
|
||||||
$(wildcard ../makefile.init) \
|
|
||||||
$(wildcard ../makefile.targets) \
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_ARTIFACT_NAME := VOXEL_ENGINE
|
|
||||||
BUILD_ARTIFACT_EXTENSION := exe
|
|
||||||
BUILD_ARTIFACT_PREFIX :=
|
|
||||||
BUILD_ARTIFACT := $(BUILD_ARTIFACT_PREFIX)$(BUILD_ARTIFACT_NAME)$(if $(BUILD_ARTIFACT_EXTENSION),.$(BUILD_ARTIFACT_EXTENSION),)
|
|
||||||
|
|
||||||
# Add inputs and outputs from these tool invocations to the build variables
|
|
||||||
|
|
||||||
# All Target
|
|
||||||
all: main-build
|
|
||||||
|
|
||||||
# Main-build Target -std=c++0x
|
|
||||||
main-build: VOXEL_ENGINE.exe
|
|
||||||
|
|
||||||
# Tool invocations
|
|
||||||
VOXEL_ENGINE.exe: $(OBJS) $(USER_OBJS) makefile objects.mk $(OPTIONAL_TOOL_DEPS)
|
|
||||||
@echo 'Building target: $@'
|
|
||||||
@echo 'Invoking: MinGW C++ Linker'
|
|
||||||
g++ -lpthread -o "VOXEL_ENGINE.exe" $(OBJS) $(USER_OBJS) $(LIBS) -static-libgcc -static-libstdc++
|
|
||||||
@echo 'Finished building target: $@'
|
|
||||||
@echo ' '
|
|
||||||
|
|
||||||
# Other Targets
|
|
||||||
clean:
|
|
||||||
-$(RM) $(CC_DEPS)$(C++_DEPS)$(EXECUTABLES)$(OBJS)$(C_UPPER_DEPS)$(CXX_DEPS)$(CPP_DEPS)$(C_DEPS) VOXEL_ENGINE.exe
|
|
||||||
-@echo ' '
|
|
||||||
|
|
||||||
.PHONY: all clean dependents
|
|
||||||
|
|
||||||
-include ../makefile.targets
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
################################################################################
|
|
||||||
# Automatically-generated file. Do not edit!
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
USER_OBJS :=
|
|
||||||
|
|
||||||
LIBS := -lglfw3 -lglew32 -lopengl32 -lspng -lgdi32 -Wl,-Bstatic -lz
|
|
||||||
|
|
||||||
@ -1,36 +0,0 @@
|
|||||||
################################################################################
|
|
||||||
# Automatically-generated file. Do not edit!
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
C_UPPER_SRCS :=
|
|
||||||
CXX_SRCS :=
|
|
||||||
C++_SRCS :=
|
|
||||||
OBJ_SRCS :=
|
|
||||||
CC_SRCS :=
|
|
||||||
ASM_SRCS :=
|
|
||||||
CPP_SRCS :=
|
|
||||||
C_SRCS :=
|
|
||||||
S_UPPER_SRCS :=
|
|
||||||
O_SRCS :=
|
|
||||||
CC_DEPS :=
|
|
||||||
C++_DEPS :=
|
|
||||||
EXECUTABLES :=
|
|
||||||
OBJS :=
|
|
||||||
C_UPPER_DEPS :=
|
|
||||||
CXX_DEPS :=
|
|
||||||
CPP_DEPS :=
|
|
||||||
C_DEPS :=
|
|
||||||
|
|
||||||
# Every subdirectory with source files must be described here
|
|
||||||
SUBDIRS := \
|
|
||||||
src \
|
|
||||||
src/files \
|
|
||||||
src/graphics \
|
|
||||||
src/lighting \
|
|
||||||
src/loaders \
|
|
||||||
src/physics \
|
|
||||||
src/objects \
|
|
||||||
src/voxels \
|
|
||||||
src/objects \
|
|
||||||
src/window \
|
|
||||||
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
################################################################################
|
|
||||||
# Automatically-generated file. Do not edit!
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
# Add inputs and outputs from these tool invocations to the build variables
|
|
||||||
CPP_SRCS += \
|
|
||||||
../src/files/WorldFiles.cpp \
|
|
||||||
../src/files/files.cpp
|
|
||||||
|
|
||||||
OBJS += \
|
|
||||||
./src/files/WorldFiles.o \
|
|
||||||
./src/files/files.o
|
|
||||||
|
|
||||||
CPP_DEPS += \
|
|
||||||
./src/files/WorldFiles.d \
|
|
||||||
./src/files/files.d
|
|
||||||
|
|
||||||
|
|
||||||
# Each subdirectory must supply rules for building sources it contributes
|
|
||||||
src/files/%.o: ../src/files/%.cpp src/files/subdir.mk
|
|
||||||
@echo 'Building file: $<'
|
|
||||||
@echo 'Invoking: GCC C++ Compiler'
|
|
||||||
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
|
|
||||||
@echo 'Finished building: $<'
|
|
||||||
@echo ' '
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,35 +0,0 @@
|
|||||||
# Add inputs and outputs from these tool invocations to the build variables
|
|
||||||
CPP_SRCS += \
|
|
||||||
../src/graphics/LineBatch.cpp \
|
|
||||||
../src/graphics/Mesh.cpp \
|
|
||||||
../src/graphics/Shader.cpp \
|
|
||||||
../src/graphics/Texture.cpp \
|
|
||||||
../src/graphics/VoxelRenderer.cpp \
|
|
||||||
../src/graphics/Batch2D.cpp
|
|
||||||
|
|
||||||
OBJS += \
|
|
||||||
./src/graphics/LineBatch.o \
|
|
||||||
./src/graphics/Mesh.o \
|
|
||||||
./src/graphics/Shader.o \
|
|
||||||
./src/graphics/Texture.o \
|
|
||||||
./src/graphics/VoxelRenderer.o \
|
|
||||||
./src/graphics/Batch2D.o
|
|
||||||
|
|
||||||
CPP_DEPS += \
|
|
||||||
./src/graphics/LineBatch.d \
|
|
||||||
./src/graphics/Mesh.d \
|
|
||||||
./src/graphics/Shader.d \
|
|
||||||
./src/graphics/Texture.d \
|
|
||||||
./src/graphics/VoxelRenderer.d \
|
|
||||||
./src/graphics/Batch2D.d
|
|
||||||
|
|
||||||
|
|
||||||
# Each subdirectory must supply rules for building sources it contributes
|
|
||||||
src/graphics/%.o: ../src/graphics/%.cpp src/graphics/subdir.mk
|
|
||||||
@echo 'Building file: $<'
|
|
||||||
@echo 'Invoking: GCC C++ Compiler'
|
|
||||||
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
|
|
||||||
@echo 'Finished building: $<'
|
|
||||||
@echo ' '
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
################################################################################
|
|
||||||
# Automatically-generated file. Do not edit!
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
# Add inputs and outputs from these tool invocations to the build variables
|
|
||||||
CPP_SRCS += \
|
|
||||||
../src/lighting/LightSolver.cpp \
|
|
||||||
../src/lighting/Lighting.cpp \
|
|
||||||
../src/lighting/Lightmap.cpp
|
|
||||||
|
|
||||||
OBJS += \
|
|
||||||
./src/lighting/LightSolver.o \
|
|
||||||
./src/lighting/Lighting.o \
|
|
||||||
./src/lighting/Lightmap.o
|
|
||||||
|
|
||||||
CPP_DEPS += \
|
|
||||||
./src/lighting/LightSolver.d \
|
|
||||||
./src/lighting/Lighting.d \
|
|
||||||
./src/lighting/Lightmap.d
|
|
||||||
|
|
||||||
|
|
||||||
# Each subdirectory must supply rules for building sources it contributes
|
|
||||||
src/lighting/%.o: ../src/lighting/%.cpp src/lighting/subdir.mk
|
|
||||||
@echo 'Building file: $<'
|
|
||||||
@echo 'Invoking: GCC C++ Compiler'
|
|
||||||
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
|
|
||||||
@echo 'Finished building: $<'
|
|
||||||
@echo ' '
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
################################################################################
|
|
||||||
# Automatically-generated file. Do not edit!
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
# Add inputs and outputs from these tool invocations to the build variables
|
|
||||||
CPP_SRCS += \
|
|
||||||
../src/loaders/png_loading.cpp
|
|
||||||
|
|
||||||
OBJS += \
|
|
||||||
./src/loaders/png_loading.o
|
|
||||||
|
|
||||||
CPP_DEPS += \
|
|
||||||
./src/loaders/png_loading.d
|
|
||||||
|
|
||||||
|
|
||||||
# Each subdirectory must supply rules for building sources it contributes
|
|
||||||
src/loaders/%.o: ../src/loaders/%.cpp src/loaders/subdir.mk
|
|
||||||
@echo 'Building file: $<'
|
|
||||||
@echo 'Invoking: GCC C++ Compiler'
|
|
||||||
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
|
|
||||||
@echo 'Finished building: $<'
|
|
||||||
@echo ' '
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
# Add inputs and outputs from these tool invocations to the build variables
|
|
||||||
CPP_SRCS += \
|
|
||||||
../src/objects/Player.cpp
|
|
||||||
|
|
||||||
OBJS += \
|
|
||||||
./src/objects/Player.o
|
|
||||||
|
|
||||||
CPP_DEPS += \
|
|
||||||
./src/objects/Player.d
|
|
||||||
|
|
||||||
|
|
||||||
# Each subdirectory must supply rules for building sources it contributes
|
|
||||||
src/objects/%.o: ../src/objects/%.cpp src/objects/subdir.mk
|
|
||||||
@echo 'Building file: $<'
|
|
||||||
@echo 'Invoking: GCC C++ Compiler'
|
|
||||||
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
|
|
||||||
@echo 'Finished building: $<'
|
|
||||||
@echo ' '
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
################################################################################
|
|
||||||
# Automatically-generated file. Do not edit!
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
# Add inputs and outputs from these tool invocations to the build variables
|
|
||||||
CPP_SRCS += \
|
|
||||||
../src/physics/Hitbox.cpp \
|
|
||||||
../src/physics/PhysicsSolver.cpp
|
|
||||||
|
|
||||||
OBJS += \
|
|
||||||
./src/physics/Hitbox.o \
|
|
||||||
./src/physics/PhysicsSolver.o
|
|
||||||
|
|
||||||
CPP_DEPS += \
|
|
||||||
./src/physics/Hitbox.d \
|
|
||||||
./src/physics/PhysicsSolver.d
|
|
||||||
|
|
||||||
|
|
||||||
# Each subdirectory must supply rules for building sources it contributes
|
|
||||||
src/physics/%.o: ../src/physics/%.cpp src/physics/subdir.mk
|
|
||||||
@echo 'Building file: $<'
|
|
||||||
@echo 'Invoking: GCC C++ Compiler'
|
|
||||||
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
|
|
||||||
@echo 'Finished building: $<'
|
|
||||||
@echo ' '
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,23 +0,0 @@
|
|||||||
# Add inputs and outputs from these tool invocations to the build variables
|
|
||||||
CPP_SRCS += \
|
|
||||||
../src/voxel_engine.cpp \
|
|
||||||
../src/Assets.cpp
|
|
||||||
|
|
||||||
OBJS += \
|
|
||||||
./src/voxel_engine.o \
|
|
||||||
./src/Assets.o
|
|
||||||
|
|
||||||
CPP_DEPS += \
|
|
||||||
./src/voxel_engine.d \
|
|
||||||
./src/Assets.d
|
|
||||||
|
|
||||||
|
|
||||||
# Each subdirectory must supply rules for building sources it contributes
|
|
||||||
src/%.o: ../src/%.cpp src/subdir.mk
|
|
||||||
@echo 'Building file: $<'
|
|
||||||
@echo 'Invoking: GCC C++ Compiler'
|
|
||||||
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
|
|
||||||
@echo 'Finished building: $<'
|
|
||||||
@echo ' '
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,42 +0,0 @@
|
|||||||
################################################################################
|
|
||||||
# Automatically-generated file. Do not edit!
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
# Add inputs and outputs from these tool invocations to the build variables
|
|
||||||
CPP_SRCS += \
|
|
||||||
../src/voxels/Block.cpp \
|
|
||||||
../src/voxels/Chunk.cpp \
|
|
||||||
../src/voxels/Chunks.cpp \
|
|
||||||
../src/voxels/ChunksController.cpp \
|
|
||||||
../src/voxels/ChunksLoader.cpp \
|
|
||||||
../src/voxels/WorldGenerator.cpp \
|
|
||||||
../src/voxels/voxel.cpp
|
|
||||||
|
|
||||||
OBJS += \
|
|
||||||
./src/voxels/Block.o \
|
|
||||||
./src/voxels/Chunk.o \
|
|
||||||
./src/voxels/Chunks.o \
|
|
||||||
./src/voxels/ChunksController.o \
|
|
||||||
./src/voxels/ChunksLoader.o \
|
|
||||||
./src/voxels/WorldGenerator.o \
|
|
||||||
./src/voxels/voxel.o
|
|
||||||
|
|
||||||
CPP_DEPS += \
|
|
||||||
./src/voxels/Block.d \
|
|
||||||
./src/voxels/Chunk.d \
|
|
||||||
./src/voxels/Chunks.d \
|
|
||||||
./src/voxels/ChunksController.d \
|
|
||||||
./src/voxels/ChunksLoader.d \
|
|
||||||
./src/voxels/WorldGenerator.d \
|
|
||||||
./src/voxels/voxel.d
|
|
||||||
|
|
||||||
|
|
||||||
# Each subdirectory must supply rules for building sources it contributes
|
|
||||||
src/voxels/%.o: ../src/voxels/%.cpp src/voxels/subdir.mk
|
|
||||||
@echo 'Building file: $<'
|
|
||||||
@echo 'Invoking: GCC C++ Compiler'
|
|
||||||
g++ -D _WIN32_WINNT=0501 -pthread -std=c++0x -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
|
|
||||||
@echo 'Finished building: $<'
|
|
||||||
@echo ' '
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
################################################################################
|
|
||||||
# Automatically-generated file. Do not edit!
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
# Add inputs and outputs from these tool invocations to the build variables
|
|
||||||
CPP_SRCS += \
|
|
||||||
../src/window/Camera.cpp \
|
|
||||||
../src/window/Events.cpp \
|
|
||||||
../src/window/Window.cpp
|
|
||||||
|
|
||||||
OBJS += \
|
|
||||||
./src/window/Camera.o \
|
|
||||||
./src/window/Events.o \
|
|
||||||
./src/window/Window.o
|
|
||||||
|
|
||||||
CPP_DEPS += \
|
|
||||||
./src/window/Camera.d \
|
|
||||||
./src/window/Events.d \
|
|
||||||
./src/window/Window.d
|
|
||||||
|
|
||||||
|
|
||||||
# Each subdirectory must supply rules for building sources it contributes
|
|
||||||
src/window/%.o: ../src/window/%.cpp src/window/subdir.mk
|
|
||||||
@echo 'Building file: $<'
|
|
||||||
@echo 'Invoking: GCC C++ Compiler'
|
|
||||||
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$@" -o "$@" "$<"
|
|
||||||
@echo 'Finished building: $<'
|
|
||||||
@echo ' '
|
|
||||||
|
|
||||||
|
|
||||||
@ -12,15 +12,6 @@
|
|||||||
- **F** - toggle flight mode
|
- **F** - toggle flight mode
|
||||||
- **Esc** - exit
|
- **Esc** - exit
|
||||||
|
|
||||||
# Run in linux:
|
|
||||||
`$ git clone https://github.com/MihailRis/VoxelEngine-Cpp.git`
|
|
||||||
|
|
||||||
`$ cd VoxelEngine-Cpp/Debug`
|
|
||||||
|
|
||||||
`$ make`
|
|
||||||
|
|
||||||
`$ ./voxel_engine`
|
|
||||||
|
|
||||||
#### Build with CMake
|
#### Build with CMake
|
||||||
```sh
|
```sh
|
||||||
git clone --recursive https://github.com/MihailRis/VoxelEngine-Cpp.git
|
git clone --recursive https://github.com/MihailRis/VoxelEngine-Cpp.git
|
||||||
|
|||||||
BIN
res/block.png
BIN
res/block.png
Binary file not shown.
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 9.6 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 8.1 KiB After Width: | Height: | Size: 16 KiB |
BIN
res/block.png.old.old
Normal file
BIN
res/block.png.old.old
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.1 KiB |
6
run.sh
Normal file
6
run.sh
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake -DCMAKE_BUILD_TYPE=Release ../
|
||||||
|
make
|
||||||
|
cd ..
|
||||||
|
build/VoxelEngine
|
||||||
79
src/AssetsLoader.cpp
Normal file
79
src/AssetsLoader.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include "AssetsLoader.h"
|
||||||
|
#include "Assets.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
AssetsLoader::AssetsLoader(Assets* assets) : assets(assets) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssetsLoader::addLoader(int tag, aloader_func func) {
|
||||||
|
loaders[tag] = func;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssetsLoader::add(int tag, const std::string filename, const std::string alias) {
|
||||||
|
entries.push(aloader_entry{ tag, filename, alias });
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AssetsLoader::hasNext() const {
|
||||||
|
return !entries.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AssetsLoader::loadNext() {
|
||||||
|
const aloader_entry& entry = entries.front();
|
||||||
|
std::cout << " loading " << entry.filename << " as " << entry.alias << std::endl;
|
||||||
|
std::cout.flush();
|
||||||
|
auto found = loaders.find(entry.tag);
|
||||||
|
if (found == loaders.end()) {
|
||||||
|
std::cerr << "unknown asset tag " << entry.tag << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
aloader_func loader = found->second;
|
||||||
|
bool status = loader(assets, entry.filename, entry.alias);
|
||||||
|
entries.pop();
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "graphics/Shader.h"
|
||||||
|
#include "graphics/Texture.h"
|
||||||
|
#include "graphics/Font.h"
|
||||||
|
|
||||||
|
bool _load_shader(Assets* assets, const std::string& filename, const std::string& name) {
|
||||||
|
Shader* shader = load_shader(filename + ".glslv", filename + ".glslf");
|
||||||
|
if (shader == nullptr) {
|
||||||
|
std::cerr << "failed to load shader '" << name << "'" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
assets->store(shader, name);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _load_texture(Assets* assets, const std::string& filename, const std::string& name) {
|
||||||
|
Texture* texture = load_texture(filename);
|
||||||
|
if (texture == nullptr) {
|
||||||
|
std::cerr << "failed to load texture '" << name << "'" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
assets->store(texture, name);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _load_font(Assets* assets, const std::string& filename, const std::string& name) {
|
||||||
|
std::vector<Texture*> pages;
|
||||||
|
for (size_t i = 0; i <= 4; i++) {
|
||||||
|
Texture* texture = load_texture(filename + "_" + std::to_string(i) + ".png");
|
||||||
|
if (texture == nullptr) {
|
||||||
|
std::cerr << "failed to load bitmap font '" << name << "' (missing page " << std::to_string(i) << ")" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
pages.push_back(texture);
|
||||||
|
}
|
||||||
|
Font* font = new Font(pages);
|
||||||
|
assets->store(font, name);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssetsLoader::createDefaults(AssetsLoader& loader) {
|
||||||
|
loader.addLoader(ASSET_SHADER, _load_shader);
|
||||||
|
loader.addLoader(ASSET_TEXTURE, _load_texture);
|
||||||
|
loader.addLoader(ASSET_FONT, _load_font);
|
||||||
|
}
|
||||||
38
src/AssetsLoader.h
Normal file
38
src/AssetsLoader.h
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#ifndef SRC_ASSETS_LOADER_H
|
||||||
|
#define SRC_ASSETS_LOADER_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <functional>
|
||||||
|
#include <map>
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
|
#define ASSET_TEXTURE 1
|
||||||
|
#define ASSET_SHADER 2
|
||||||
|
#define ASSET_FONT 3
|
||||||
|
|
||||||
|
class Assets;
|
||||||
|
|
||||||
|
typedef std::function<bool(Assets*, const std::string&, const std::string&)> aloader_func;
|
||||||
|
|
||||||
|
struct aloader_entry {
|
||||||
|
int tag;
|
||||||
|
const std::string filename;
|
||||||
|
const std::string alias;
|
||||||
|
};
|
||||||
|
|
||||||
|
class AssetsLoader {
|
||||||
|
Assets* assets;
|
||||||
|
std::map<int, aloader_func> loaders;
|
||||||
|
std::queue<aloader_entry> entries;
|
||||||
|
public:
|
||||||
|
AssetsLoader(Assets* assets);
|
||||||
|
void addLoader(int tag, aloader_func func);
|
||||||
|
void add(int tag, const std::string filename, const std::string alias);
|
||||||
|
|
||||||
|
bool hasNext() const;
|
||||||
|
bool loadNext();
|
||||||
|
|
||||||
|
static void createDefaults(AssetsLoader& loader);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SRC_ASSETS_LOADER_H
|
||||||
@ -1,70 +1,21 @@
|
|||||||
#include "declarations.h"
|
#include "declarations.h"
|
||||||
|
|
||||||
#include "Assets.h"
|
#include "AssetsLoader.h"
|
||||||
#include "graphics/Shader.h"
|
|
||||||
#include "graphics/Texture.h"
|
|
||||||
#include "graphics/Font.h"
|
|
||||||
#include "window/Window.h"
|
#include "window/Window.h"
|
||||||
|
|
||||||
#include "voxels/Block.h"
|
#include "voxels/Block.h"
|
||||||
|
|
||||||
// Shaders, textures
|
|
||||||
bool _load_shader(Assets* assets, std::string vertex_file, std::string fragment_file, std::string name){
|
|
||||||
Shader* shader = load_shader(vertex_file, fragment_file);
|
|
||||||
if (shader == nullptr){
|
|
||||||
std::cerr << "failed to load shader '" << name << "'" << std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
assets->store(shader, name);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool _load_texture(Assets* assets, std::string filename, std::string name){
|
void initialize_assets(AssetsLoader* loader) {
|
||||||
Texture* texture = load_texture(filename);
|
loader->add(ASSET_SHADER, "res/main", "main");
|
||||||
if (texture == nullptr){
|
loader->add(ASSET_SHADER, "res/crosshair", "crosshair");
|
||||||
std::cerr << "failed to load texture '" << name << "'" << std::endl;
|
loader->add(ASSET_SHADER, "res/lines", "lines");
|
||||||
return false;
|
loader->add(ASSET_SHADER, "res/ui", "ui");
|
||||||
}
|
|
||||||
assets->store(texture, name);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool _load_font(Assets* assets, std::string filename, std::string name){
|
loader->add(ASSET_TEXTURE, "res/block.png", "block");
|
||||||
std::vector<Texture*> pages;
|
loader->add(ASSET_TEXTURE, "res/slot.png", "slot");
|
||||||
for (size_t i = 0; i <= 4; i++){
|
|
||||||
Texture* texture = load_texture(filename+"_"+std::to_string(i)+".png");
|
|
||||||
if (texture == nullptr){
|
|
||||||
std::cerr << "failed to load bitmap font '" << name << "' (missing page " << std::to_string(i) << ")" << std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
pages.push_back(texture);
|
|
||||||
}
|
|
||||||
Font* font = new Font(pages);
|
|
||||||
assets->store(font, name);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int initialize_assets(Assets* assets) {
|
loader->add(ASSET_FONT, "res/font", "normal");
|
||||||
#define LOAD_SHADER(VERTEX, FRAGMENT, NAME) \
|
|
||||||
if (!_load_shader(assets, VERTEX, FRAGMENT, NAME))\
|
|
||||||
return 1;
|
|
||||||
#define LOAD_TEXTURE(FILENAME, NAME) \
|
|
||||||
if (!_load_texture(assets, FILENAME, NAME))\
|
|
||||||
return 1;
|
|
||||||
#define LOAD_FONT(FILENAME, NAME) \
|
|
||||||
if (!_load_font(assets, FILENAME, NAME))\
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
LOAD_SHADER("res/main.glslv", "res/main.glslf", "main");
|
|
||||||
LOAD_SHADER("res/crosshair.glslv", "res/crosshair.glslf", "crosshair");
|
|
||||||
LOAD_SHADER("res/lines.glslv", "res/lines.glslf", "lines");
|
|
||||||
LOAD_SHADER("res/ui.glslv", "res/ui.glslf", "ui");
|
|
||||||
|
|
||||||
LOAD_TEXTURE("res/block.png", "block");
|
|
||||||
LOAD_TEXTURE("res/slot.png", "slot");
|
|
||||||
|
|
||||||
LOAD_FONT("res/font", "normal");
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// All in-game definitions (blocks, items, etc..)
|
// All in-game definitions (blocks, items, etc..)
|
||||||
@ -106,6 +57,7 @@ void setup_definitions() {
|
|||||||
block = new Block(BLOCK_WOOD, 7);
|
block = new Block(BLOCK_WOOD, 7);
|
||||||
block->textureFaces[2] = 8;
|
block->textureFaces[2] = 8;
|
||||||
block->textureFaces[3] = 8;
|
block->textureFaces[3] = 8;
|
||||||
|
block->rotatable = true;
|
||||||
Block::blocks[block->id] = block;
|
Block::blocks[block->id] = block;
|
||||||
|
|
||||||
block = new Block(BLOCK_LEAVES, 9);
|
block = new Block(BLOCK_LEAVES, 9);
|
||||||
|
|||||||
@ -21,9 +21,9 @@
|
|||||||
#define BLOCK_METAL 15
|
#define BLOCK_METAL 15
|
||||||
#define BLOCK_RUST 16
|
#define BLOCK_RUST 16
|
||||||
|
|
||||||
class Assets;
|
class AssetsLoader;
|
||||||
|
|
||||||
int initialize_assets(Assets* assets);
|
void initialize_assets(AssetsLoader* loader);
|
||||||
void setup_definitions();
|
void setup_definitions();
|
||||||
|
|
||||||
#endif // DECLARATIONS_H
|
#endif // DECLARATIONS_H
|
||||||
|
|||||||
@ -171,7 +171,7 @@ bool WorldFiles::readChunk(int x, int y, char* out){
|
|||||||
input.read(mainBufferIn, compressedSize);
|
input.read(mainBufferIn, compressedSize);
|
||||||
input.close();
|
input.close();
|
||||||
|
|
||||||
decompressRLE(mainBufferIn, compressedSize, out, CHUNK_VOL);
|
decompressRLE((unsigned char*)mainBufferIn, compressedSize, (unsigned char*)out, CHUNK_VOL);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -274,7 +274,7 @@ unsigned int WorldFiles::writeRegion(char* out, int x, int y, char** region){
|
|||||||
} else {
|
} else {
|
||||||
int2Bytes(offset, out, i*4);
|
int2Bytes(offset, out, i*4);
|
||||||
|
|
||||||
unsigned int compressedSize = compressRLE(chunk, CHUNK_VOL, compressed);
|
unsigned int compressedSize = compressRLE((unsigned char*)chunk, CHUNK_VOL, (unsigned char*)compressed);
|
||||||
|
|
||||||
int2Bytes(compressedSize, out, offset);
|
int2Bytes(compressedSize, out, offset);
|
||||||
offset += 4;
|
offset += 4;
|
||||||
|
|||||||
@ -3,9 +3,7 @@
|
|||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#ifndef std::string
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#endif
|
|
||||||
class Player;
|
class Player;
|
||||||
|
|
||||||
#define REGION_SIZE_BIT 5
|
#define REGION_SIZE_BIT 5
|
||||||
|
|||||||
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <memory>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
bool write_binary_file_part(std::string filename, const char* data, size_t offset, size_t size){
|
bool write_binary_file_part(std::string filename, const char* data, size_t offset, size_t size){
|
||||||
std::ofstream output(filename, std::ios::out | std::ios::binary | std::ios::in);
|
std::ofstream output(filename, std::ios::out | std::ios::binary | std::ios::in);
|
||||||
@ -48,18 +50,18 @@ char* read_binary_file(std::string filename, size_t& length) {
|
|||||||
length = input.tellg();
|
length = input.tellg();
|
||||||
input.seekg(0, std::ios_base::beg);
|
input.seekg(0, std::ios_base::beg);
|
||||||
|
|
||||||
char* data = new char[length];
|
std::unique_ptr<char> data {new char[length]};
|
||||||
input.read(data, length);
|
input.read(data.get(), length);
|
||||||
input.close();
|
input.close();
|
||||||
return data;
|
return data.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns decompressed length
|
// returns decompressed length
|
||||||
unsigned int decompressRLE(const char* src, unsigned int length, char* dst, unsigned int targetLength){
|
size_t decompressRLE(const ubyte* src, size_t length, ubyte* dst, size_t targetLength){
|
||||||
unsigned int offset = 0;
|
size_t offset = 0;
|
||||||
for (unsigned int i = 0; i < length;){
|
for (size_t i = 0; i < length;){
|
||||||
unsigned char counter = src[i++];
|
unsigned char counter = src[i++];
|
||||||
char c = src[i++];
|
unsigned char c = src[i++];
|
||||||
for (unsigned int j = 0; j <= counter; j++){
|
for (unsigned int j = 0; j <= counter; j++){
|
||||||
dst[offset++] = c;
|
dst[offset++] = c;
|
||||||
}
|
}
|
||||||
@ -67,12 +69,12 @@ unsigned int decompressRLE(const char* src, unsigned int length, char* dst, unsi
|
|||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int calcRLE(const char* src, unsigned int length) {
|
size_t calcRLE(const ubyte* src, size_t length) {
|
||||||
unsigned int offset = 0;
|
size_t offset = 0;
|
||||||
unsigned int counter = 0;
|
size_t counter = 0;
|
||||||
char c = src[0];
|
ubyte c = src[0];
|
||||||
for (unsigned int i = 0; i < length; i++){
|
for (size_t i = 0; i < length; i++){
|
||||||
char cnext = src[i];
|
ubyte cnext = src[i];
|
||||||
if (cnext != c || counter == 255){
|
if (cnext != c || counter == 255){
|
||||||
offset += 2;
|
offset += 2;
|
||||||
c = cnext;
|
c = cnext;
|
||||||
@ -85,12 +87,14 @@ unsigned int calcRLE(const char* src, unsigned int length) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// max result size = length * 2; returns compressed length
|
// max result size = length * 2; returns compressed length
|
||||||
unsigned int compressRLE(const char* src, unsigned int length, char* dst) {
|
size_t compressRLE(const ubyte* src, size_t length, ubyte* dst) {
|
||||||
unsigned int offset = 0;
|
if (length == 0)
|
||||||
unsigned int counter = 0;
|
return 0;
|
||||||
char c = src[0];
|
size_t offset = 0;
|
||||||
for (unsigned int i = 1; i < length; i++){
|
uint counter = 0;
|
||||||
char cnext = src[i];
|
ubyte c = src[0];
|
||||||
|
for (size_t i = 1; i < length; i++){
|
||||||
|
ubyte cnext = src[i];
|
||||||
if (cnext != c || counter == 255){
|
if (cnext != c || counter == 255){
|
||||||
dst[offset++] = counter;
|
dst[offset++] = counter;
|
||||||
dst[offset++] = c;
|
dst[offset++] = c;
|
||||||
|
|||||||
@ -1,9 +1,8 @@
|
|||||||
#ifndef FILES_FILES_H_
|
#ifndef FILES_FILES_H_
|
||||||
#define FILES_FILES_H_
|
#define FILES_FILES_H_
|
||||||
|
|
||||||
#ifndef std::string
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#endif
|
#include "../typedefs.h"
|
||||||
|
|
||||||
extern bool write_binary_file(std::string filename, const char* data, size_t size);
|
extern bool write_binary_file(std::string filename, const char* data, size_t size);
|
||||||
extern unsigned int append_binary_file(std::string filename, const char* data, size_t size);
|
extern unsigned int append_binary_file(std::string filename, const char* data, size_t size);
|
||||||
@ -11,8 +10,8 @@ extern bool read_binary_file(std::string filename, char* data, size_t size);
|
|||||||
extern bool read_binary_file(std::string filename, char* data, size_t offset, size_t size);
|
extern bool read_binary_file(std::string filename, char* data, size_t offset, size_t size);
|
||||||
extern char* read_binary_file(std::string filename, size_t& length);
|
extern char* read_binary_file(std::string filename, size_t& length);
|
||||||
|
|
||||||
extern unsigned int calcRLE(const char* src, unsigned int length);
|
extern size_t calcRLE(const ubyte* src, size_t length);
|
||||||
extern unsigned int compressRLE(const char* src, unsigned int length, char* dst);
|
extern size_t compressRLE(const ubyte* src, size_t length, ubyte* dst);
|
||||||
extern unsigned int decompressRLE(const char* src, unsigned int length, char* dst, unsigned int targetLength);
|
extern size_t decompressRLE(const ubyte* src, size_t length, ubyte* dst, size_t targetLength);
|
||||||
|
|
||||||
#endif /* FILES_FILES_H_ */
|
#endif /* FILES_FILES_H_ */
|
||||||
|
|||||||
@ -62,7 +62,7 @@ void Batch2D::vertex(vec2 point,
|
|||||||
void Batch2D::texture(Texture* new_texture){
|
void Batch2D::texture(Texture* new_texture){
|
||||||
if (_texture == new_texture)
|
if (_texture == new_texture)
|
||||||
return;
|
return;
|
||||||
render();
|
render(GL_TRIANGLES);
|
||||||
_texture = new_texture;
|
_texture = new_texture;
|
||||||
if (new_texture == nullptr)
|
if (new_texture == nullptr)
|
||||||
blank->bind();
|
blank->bind();
|
||||||
@ -70,21 +70,39 @@ void Batch2D::texture(Texture* new_texture){
|
|||||||
new_texture->bind();
|
new_texture->bind();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Batch2D::point(float x, float y, float r, float g, float b, float a){
|
||||||
|
// if (index + 6*VERTEX_SIZE >= capacity)
|
||||||
|
// render(GL_TRIANGLES);
|
||||||
|
|
||||||
|
vertex(x, y, 0, 0, r,g,b,a);
|
||||||
|
render(GL_POINTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch2D::line(float x1, float y1, float x2, float y2, float r, float g, float b, float a){
|
||||||
|
// if (index + 6*VERTEX_SIZE >= capacity)
|
||||||
|
// render(GL_TRIANGLES);
|
||||||
|
|
||||||
|
vertex(x1, y1, 0, 0, r,g,b,a);
|
||||||
|
vertex(x2, y2, 1, 1, r,g,b,a);
|
||||||
|
render(GL_LINES);
|
||||||
|
}
|
||||||
|
|
||||||
void Batch2D::rect(float x, float y, float w, float h){
|
void Batch2D::rect(float x, float y, float w, float h){
|
||||||
const float r = color.r;
|
const float r = color.r;
|
||||||
const float g = color.g;
|
const float g = color.g;
|
||||||
const float b = color.b;
|
const float b = color.b;
|
||||||
const float a = color.a;
|
const float a = color.a;
|
||||||
if (index + 6*VERTEX_SIZE >= capacity)
|
// if (index + 6*VERTEX_SIZE >= capacity)
|
||||||
render();
|
// render(GL_TRIANGLES);
|
||||||
|
|
||||||
vertex(x, y, 0, 0, r,g,b,a);
|
vertex(x, y, 0, 0, r,g,b,a);
|
||||||
vertex(x+w, y+h, 1, 1, r,g,b,a);
|
|
||||||
vertex(x, y+h, 0, 1, r,g,b,a);
|
vertex(x, y+h, 0, 1, r,g,b,a);
|
||||||
|
vertex(x+w, y+h, 1, 1, r,g,b,a);
|
||||||
|
|
||||||
vertex(x, y, 0, 0, r,g,b,a);
|
vertex(x, y, 0, 0, r,g,b,a);
|
||||||
vertex(x+w, y, 1, 0, r,g,b,a);
|
|
||||||
vertex(x+w, y+h, 1, 1, r,g,b,a);
|
vertex(x+w, y+h, 1, 1, r,g,b,a);
|
||||||
|
vertex(x+w, y, 1, 0, r,g,b,a);
|
||||||
|
render(GL_TRIANGLES);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Batch2D::rect(
|
void Batch2D::rect(
|
||||||
@ -96,8 +114,8 @@ void Batch2D::rect(
|
|||||||
bool flippedX,
|
bool flippedX,
|
||||||
bool flippedY,
|
bool flippedY,
|
||||||
vec4 tint) {
|
vec4 tint) {
|
||||||
if (index + 6*VERTEX_SIZE >= capacity)
|
// if (index + 6*VERTEX_SIZE >= capacity)
|
||||||
render();
|
// render(GL_TRIANGLES);
|
||||||
|
|
||||||
float centerX = w*ox;
|
float centerX = w*ox;
|
||||||
float centerY = h*oy;
|
float centerY = h*oy;
|
||||||
@ -179,6 +197,83 @@ void Batch2D::rect(
|
|||||||
vertex(x1, y1, u1, v1, tint.r, tint.g, tint.b, tint.a);
|
vertex(x1, y1, u1, v1, tint.r, tint.g, tint.b, tint.a);
|
||||||
vertex(x3, y3, u3, v3, tint.r, tint.g, tint.b, tint.a);
|
vertex(x3, y3, u3, v3, tint.r, tint.g, tint.b, tint.a);
|
||||||
vertex(x4, y4, u4, v4, tint.r, tint.g, tint.b, tint.a);
|
vertex(x4, y4, u4, v4, tint.r, tint.g, tint.b, tint.a);
|
||||||
|
render(GL_TRIANGLES);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch2D::rect(float x, float y, float w, float h,
|
||||||
|
float u, float v, float tx, float ty,
|
||||||
|
float r, float g, float b, float a){
|
||||||
|
// if (index + 6*VERTEX_SIZE >= capacity)
|
||||||
|
// render(GL_TRIANGLES);
|
||||||
|
vertex(x, y, u, v+ty, r,g,b,a);
|
||||||
|
vertex(x+w, y+h, u+tx, v, r,g,b,a);
|
||||||
|
vertex(x, y+h, u, v, r,g,b,a);
|
||||||
|
|
||||||
|
vertex(x, y, u, v+ty, r,g,b,a);
|
||||||
|
vertex(x+w, y, u+tx, v+ty, r,g,b,a);
|
||||||
|
vertex(x+w, y+h, u+tx, v, r,g,b,a);
|
||||||
|
render(GL_TRIANGLES);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch2D::rect(float x, float y, float w, float h,
|
||||||
|
float r0, float g0, float b0,
|
||||||
|
float r1, float g1, float b1,
|
||||||
|
float r2, float g2, float b2,
|
||||||
|
float r3, float g3, float b3,
|
||||||
|
float r4, float g4, float b4, int sh){
|
||||||
|
// if (index + 30*VERTEX_SIZE >= capacity)
|
||||||
|
// render(GL_TRIANGLES);
|
||||||
|
vec2 v0 = vec2(x+h/2,y+h/2);
|
||||||
|
vec2 v1 = vec2(x+w-sh,y);
|
||||||
|
vec2 v2 = vec2(x+sh,y);
|
||||||
|
vec2 v3 = vec2(x,y+sh);
|
||||||
|
vec2 v4 = vec2(x,y+h-sh);
|
||||||
|
vec2 v5 = vec2(x+sh,y+h);
|
||||||
|
vec2 v6 = vec2(x+w-h/2,y+h/2);
|
||||||
|
vec2 v7 = vec2(x+w-sh,y+h);
|
||||||
|
vec2 v8 = vec2(x+w,y+h-sh);
|
||||||
|
vec2 v9 = vec2(x+w,y+sh);
|
||||||
|
|
||||||
|
vertex(v0, vec2(0, 0), r1,g1,b1,1.0f);
|
||||||
|
vertex(v6, vec2(0, 0), r1,g1,b1,1.0f);
|
||||||
|
vertex(v1, vec2(0, 0), r1,g1,b1,1.0f);
|
||||||
|
|
||||||
|
vertex(v0, vec2(0, 0), r1,g1,b1,1.0f);
|
||||||
|
vertex(v1, vec2(0, 0), r1,g1,b1,1.0f);
|
||||||
|
vertex(v2, vec2(0, 0), r1,g1,b1,1.0f);
|
||||||
|
|
||||||
|
vertex(v0, vec2(0, 0), r0,g0,b0,1.0f);
|
||||||
|
vertex(v2, vec2(0, 0), r0,g0,b0,1.0f);
|
||||||
|
vertex(v3, vec2(0, 0), r0,g0,b0,1.0f);
|
||||||
|
|
||||||
|
vertex(v0, vec2(0, 0), r1,g1,b1,1.0f);
|
||||||
|
vertex(v3, vec2(0, 0), r1,g1,b1,1.0f);
|
||||||
|
vertex(v4, vec2(0, 0), r1,g1,b1,1.0f);
|
||||||
|
|
||||||
|
vertex(v0, vec2(0, 0), r2,g2,b2,1.0f);
|
||||||
|
vertex(v4, vec2(0, 0), r2,g2,b2,1.0f);
|
||||||
|
vertex(v5, vec2(0, 0), r2,g2,b2,1.0f);
|
||||||
|
|
||||||
|
vertex(v0, vec2(0, 0), r3,g3,b3,1.0f);
|
||||||
|
vertex(v5, vec2(0, 0), r3,g3,b3,1.0f);
|
||||||
|
vertex(v6, vec2(0, 0), r3,g3,b3,1.0f);
|
||||||
|
|
||||||
|
vertex(v6, vec2(0, 0), r3,g3,b3,1.0f);
|
||||||
|
vertex(v5, vec2(0, 0), r3,g3,b3,1.0f);
|
||||||
|
vertex(v7, vec2(0, 0), r3,g3,b3,1.0f);
|
||||||
|
|
||||||
|
vertex(v6, vec2(0, 0), r4,g4,b4,1.0f);
|
||||||
|
vertex(v7, vec2(0, 0), r4,g4,b4,1.0f);
|
||||||
|
vertex(v8, vec2(0, 0), r4,g4,b4,1.0f);
|
||||||
|
|
||||||
|
vertex(v6, vec2(0, 0), r3,g3,b3,1.0f);
|
||||||
|
vertex(v8, vec2(0, 0), r3,g3,b3,1.0f);
|
||||||
|
vertex(v9, vec2(0, 0), r3,g3,b3,1.0f);
|
||||||
|
|
||||||
|
vertex(v6, vec2(0, 0), r2,g2,b2,1.0f);
|
||||||
|
vertex(v9, vec2(0, 0), r2,g2,b2,1.0f);
|
||||||
|
vertex(v1, vec2(0, 0), r2,g2,b2,1.0f);
|
||||||
|
render(GL_TRIANGLES);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Batch2D::sprite(Sprite* sprite) {
|
void Batch2D::sprite(Sprite* sprite) {
|
||||||
@ -210,8 +305,8 @@ void Batch2D::blockSprite(float x, float y, float w, float h, int atlasRes, int
|
|||||||
float vu = 1.0f - ((index[3] / atlasRes) * scale) - scale;
|
float vu = 1.0f - ((index[3] / atlasRes) * scale) - scale;
|
||||||
float uf = (index[0] % atlasRes) * scale;
|
float uf = (index[0] % atlasRes) * scale;
|
||||||
float vf = 1.0f - ((index[0] / atlasRes) * scale) - scale;
|
float vf = 1.0f - ((index[0] / atlasRes) * scale) - scale;
|
||||||
if (this->index + 18*VERTEX_SIZE >= capacity)
|
// if (this->index + 18*VERTEX_SIZE >= capacity)
|
||||||
render();
|
// render();
|
||||||
|
|
||||||
float ar = 0.88f;
|
float ar = 0.88f;
|
||||||
float ox = x + (w * 0.5f);
|
float ox = x + (w * 0.5f);
|
||||||
@ -258,24 +353,14 @@ void Batch2D::blockSprite(float x, float y, float w, float h, int atlasRes, int
|
|||||||
vertex(points[0], uvpoints[6], tint.r, tint.g, tint.b, tint.a);
|
vertex(points[0], uvpoints[6], tint.r, tint.g, tint.b, tint.a);
|
||||||
vertex(points[6], uvpoints[4], tint.r, tint.g, tint.b, tint.a);
|
vertex(points[6], uvpoints[4], tint.r, tint.g, tint.b, tint.a);
|
||||||
vertex(points[1], uvpoints[7], tint.r, tint.g, tint.b, tint.a);
|
vertex(points[1], uvpoints[7], tint.r, tint.g, tint.b, tint.a);
|
||||||
|
|
||||||
|
glDisable(GL_MULTISAMPLE);
|
||||||
|
render(GL_TRIANGLES);
|
||||||
|
glEnable(GL_MULTISAMPLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Batch2D::rect(float x, float y, float w, float h,
|
void Batch2D::render(unsigned int gl_primitive) {
|
||||||
float u, float v, float tx, float ty,
|
|
||||||
float r, float g, float b, float a){
|
|
||||||
if (index + 6*VERTEX_SIZE >= capacity)
|
|
||||||
render();
|
|
||||||
vertex(x, y, u, v+ty, r,g,b,a);
|
|
||||||
vertex(x+w, y+h, u+tx, v, r,g,b,a);
|
|
||||||
vertex(x, y+h, u, v, r,g,b,a);
|
|
||||||
|
|
||||||
vertex(x, y, u, v+ty, r,g,b,a);
|
|
||||||
vertex(x+w, y, u+tx, v+ty, r,g,b,a);
|
|
||||||
vertex(x+w, y+h, u+tx, v, r,g,b,a);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Batch2D::render() {
|
|
||||||
mesh->reload(buffer, index / VERTEX_SIZE);
|
mesh->reload(buffer, index / VERTEX_SIZE);
|
||||||
mesh->draw(GL_TRIANGLES);
|
mesh->draw(gl_primitive);
|
||||||
index = 0;
|
index = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,6 +40,8 @@ public:
|
|||||||
void sprite(float x, float y, float w, float h, int atlasRes, int index, vec4 tint);
|
void sprite(float x, float y, float w, float h, int atlasRes, int index, vec4 tint);
|
||||||
void sprite(Sprite* sprite);
|
void sprite(Sprite* sprite);
|
||||||
void blockSprite(float x, float y, float w, float h, int atlasRes, int index[6], vec4 tint);
|
void blockSprite(float x, float y, float w, float h, int atlasRes, int index[6], vec4 tint);
|
||||||
|
void point(float x, float y, float r, float g, float b, float a);
|
||||||
|
void line(float x1, float y1, float x2, float y2, float r, float g, float b, float a);
|
||||||
void rect(float x, float y,
|
void rect(float x, float y,
|
||||||
float w, float h,
|
float w, float h,
|
||||||
float ox, float oy,
|
float ox, float oy,
|
||||||
@ -51,7 +53,14 @@ public:
|
|||||||
void rect(float x, float y, float w, float h,
|
void rect(float x, float y, float w, float h,
|
||||||
float u, float v, float tx, float ty,
|
float u, float v, float tx, float ty,
|
||||||
float r, float g, float b, float a);
|
float r, float g, float b, float a);
|
||||||
void render();
|
|
||||||
|
void rect(float x, float y, float w, float h,
|
||||||
|
float r0, float g0, float b0,
|
||||||
|
float r1, float g1, float b1,
|
||||||
|
float r2, float g2, float b2,
|
||||||
|
float r3, float g3, float b3,
|
||||||
|
float r4, float g4, float b4, int sh);
|
||||||
|
void render(unsigned int gl_primitive);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SRC_GRAPHICS_BATCH2D_H_ */
|
#endif /* SRC_GRAPHICS_BATCH2D_H_ */
|
||||||
|
|||||||
@ -10,21 +10,21 @@ Font::~Font(){
|
|||||||
delete texture;
|
delete texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Font::getGlyphWidth(char c) {
|
// int Font::getGlyphWidth(char c) {
|
||||||
switch (c){
|
// switch (c){
|
||||||
case 'l':
|
// case 'l':
|
||||||
case 'i':
|
// case 'i':
|
||||||
case 'j':
|
// case 'j':
|
||||||
case '|':
|
// case '|':
|
||||||
case '.':
|
// case '.':
|
||||||
case ',':
|
// case ',':
|
||||||
case ':':
|
// case ':':
|
||||||
case ';': return 7;
|
// case ';': return 7;
|
||||||
case 't': return 8;
|
// case 't': return 8;
|
||||||
case ' ': return 7;
|
// case ' ': return 7;
|
||||||
}
|
// }
|
||||||
return 7;
|
// return 7;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
bool Font::isPrintableChar(int c) {
|
bool Font::isPrintableChar(int c) {
|
||||||
@ -81,7 +81,7 @@ void Font::draw(Batch2D* batch, std::wstring text, int x, int y, int style) {
|
|||||||
next = charpage;
|
next = charpage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
x += getGlyphWidth(c);
|
x += 8;//getGlyphWidth(c);
|
||||||
}
|
}
|
||||||
page = next;
|
page = next;
|
||||||
next = 10000;
|
next = 10000;
|
||||||
|
|||||||
@ -17,7 +17,7 @@ public:
|
|||||||
Font(std::vector<Texture*> pages);
|
Font(std::vector<Texture*> pages);
|
||||||
~Font();
|
~Font();
|
||||||
|
|
||||||
int getGlyphWidth(char c);
|
// int getGlyphWidth(char c);
|
||||||
bool isPrintableChar(int c);
|
bool isPrintableChar(int c);
|
||||||
void draw(Batch2D* batch, std::wstring text, int x, int y);
|
void draw(Batch2D* batch, std::wstring text, int x, int y);
|
||||||
void draw(Batch2D* batch, std::wstring text, int x, int y, int style);
|
void draw(Batch2D* batch, std::wstring text, int x, int y, int style);
|
||||||
|
|||||||
@ -4,23 +4,45 @@
|
|||||||
#include "Texture.h"
|
#include "Texture.h"
|
||||||
|
|
||||||
Framebuffer::Framebuffer(int width, int height) : width(width), height(height) {
|
Framebuffer::Framebuffer(int width, int height) : width(width), height(height) {
|
||||||
glGenFramebuffers(1, &fbo);
|
// glGenFramebuffers(1, &fbo);
|
||||||
bind();
|
// bind();
|
||||||
GLuint tex;
|
// GLuint tex;
|
||||||
glGenTextures(1, &tex);
|
// glGenTextures(1, &tex);
|
||||||
glBindTexture(GL_TEXTURE_2D, tex);
|
// // glBindTexture(GL_TEXTURE_2D, tex);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
|
// glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, tex);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
// // glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
// glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GL_RGB, width, height, GL_TRUE);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
// glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
// glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
|
// glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
texture = new Texture(tex, width, height);
|
// glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
glGenRenderbuffers(1, &depth);
|
// glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, tex, 0);
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, depth);
|
// texture = new Texture(tex, width, height);
|
||||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height);
|
// glGenRenderbuffers(1, &depth);
|
||||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth);
|
// glBindRenderbuffer(GL_RENDERBUFFER, depth);
|
||||||
unbind();
|
// glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_DEPTH_COMPONENT24, width, height);
|
||||||
|
// // glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height);
|
||||||
|
// glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth);
|
||||||
|
// unbind();
|
||||||
|
|
||||||
|
|
||||||
|
// bind();
|
||||||
|
// glGenFramebuffers(1, &fbo);
|
||||||
|
// // create a multisampled color attachment texture
|
||||||
|
// unsigned int textureColorBufferMultiSampled;
|
||||||
|
// glGenTextures(1, &textureColorBufferMultiSampled);
|
||||||
|
// glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, textureColorBufferMultiSampled);
|
||||||
|
// glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GL_RGB, width, height, GL_TRUE);
|
||||||
|
// glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0);
|
||||||
|
// glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, textureColorBufferMultiSampled, 0);
|
||||||
|
// // create a (also multisampled) renderbuffer object for depth and stencil attachments
|
||||||
|
// unsigned int rbo;
|
||||||
|
// glGenRenderbuffers(1, &rbo);
|
||||||
|
// glBindRenderbuffer(GL_RENDERBUFFER, rbo);
|
||||||
|
// glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_DEPTH24_STENCIL8, width, height);
|
||||||
|
// glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||||
|
// glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rbo);
|
||||||
|
// unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
Framebuffer::~Framebuffer() {
|
Framebuffer::~Framebuffer() {
|
||||||
|
|||||||
@ -7,12 +7,17 @@ Texture::Texture(unsigned int id, int width, int height) : id(id), width(width),
|
|||||||
Texture::Texture(unsigned char* data, int width, int height) : width(width), height(height) {
|
Texture::Texture(unsigned char* data, int width, int height) : width(width), height(height) {
|
||||||
glGenTextures(1, &id);
|
glGenTextures(1, &id);
|
||||||
glBindTexture(GL_TEXTURE_2D, id);
|
glBindTexture(GL_TEXTURE_2D, id);
|
||||||
|
// glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, id);
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
|
||||||
GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *) data);
|
GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *) data);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
|
// glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GL_RGBA, width, height, GL_TRUE);
|
||||||
|
// glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
|
// glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
// glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture::~Texture() {
|
Texture::~Texture() {
|
||||||
@ -21,11 +26,15 @@ Texture::~Texture() {
|
|||||||
|
|
||||||
void Texture::bind(){
|
void Texture::bind(){
|
||||||
glBindTexture(GL_TEXTURE_2D, id);
|
glBindTexture(GL_TEXTURE_2D, id);
|
||||||
|
// glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture::reload(unsigned char* data){
|
void Texture::reload(unsigned char* data){
|
||||||
glBindTexture(GL_TEXTURE_2D, id);
|
glBindTexture(GL_TEXTURE_2D, id);
|
||||||
|
// glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, id);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
|
||||||
GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *) data);
|
GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *) data);
|
||||||
|
// glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GL_RGB, width, height, GL_TRUE);
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
// glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,17 +43,41 @@ VoxelRenderer::VoxelRenderer() {
|
|||||||
VoxelRenderer::~VoxelRenderer(){
|
VoxelRenderer::~VoxelRenderer(){
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void _renderBlock(std::vector<float>& buffer, int x, int y, int z, const Chunk** chunks, unsigned int id, size_t& index){
|
inline void _renderBlock(std::vector<float>& buffer, int x, int y, int z, const Chunk** chunks, voxel vox, size_t& index){
|
||||||
float l;
|
float l;
|
||||||
float uvsize = 1.0f/16.0f;
|
float uvsize = 1.0f/16.0f;
|
||||||
|
|
||||||
Block* block = Block::blocks[id];
|
Block* block = Block::blocks[vox.id];
|
||||||
unsigned char group = block->drawGroup;
|
unsigned char group = block->drawGroup;
|
||||||
|
int textureCopyFaces[6];
|
||||||
|
int rot = 0;
|
||||||
|
|
||||||
|
for (int i=0; i<6; i++){
|
||||||
|
textureCopyFaces[i] = block->textureFaces[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (block->rotatable){
|
||||||
|
if (vox.states == 0x31){
|
||||||
|
rot = 1;
|
||||||
|
textureCopyFaces[0] = block->textureFaces[2];
|
||||||
|
textureCopyFaces[1] = block->textureFaces[3];
|
||||||
|
textureCopyFaces[2] = block->textureFaces[0];
|
||||||
|
textureCopyFaces[3] = block->textureFaces[1];
|
||||||
|
} else if (vox.states == 0x32){
|
||||||
|
rot = 2;
|
||||||
|
} else if (vox.states == 0x33){
|
||||||
|
rot = 3;
|
||||||
|
textureCopyFaces[2] = block->textureFaces[4];
|
||||||
|
textureCopyFaces[3] = block->textureFaces[5];
|
||||||
|
textureCopyFaces[4] = block->textureFaces[2];
|
||||||
|
textureCopyFaces[5] = block->textureFaces[3];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!IS_BLOCKED(x,y+1,z,group)){
|
if (!IS_BLOCKED(x,y+1,z,group)){
|
||||||
l = 1.0f;
|
l = 1.0f;
|
||||||
|
|
||||||
SETUP_UV(block->textureFaces[3]);
|
SETUP_UV(textureCopyFaces[3]);
|
||||||
|
|
||||||
const float lr = LIGHT(x,y+1,z, 0) / 15.0f;
|
const float lr = LIGHT(x,y+1,z, 0) / 15.0f;
|
||||||
const float lg = LIGHT(x,y+1,z, 1) / 15.0f;
|
const float lg = LIGHT(x,y+1,z, 1) / 15.0f;
|
||||||
@ -80,18 +104,36 @@ inline void _renderBlock(std::vector<float>& buffer, int x, int y, int z, const
|
|||||||
float ls2 = (LIGHT(x+1,y+1,z,3) + ls*30 + LIGHT(x+1,y+1,z+1,3) + LIGHT(x,y+1,z+1,3)) / 75.0f;
|
float ls2 = (LIGHT(x+1,y+1,z,3) + ls*30 + LIGHT(x+1,y+1,z+1,3) + LIGHT(x,y+1,z+1,3)) / 75.0f;
|
||||||
float ls3 = (LIGHT(x+1,y+1,z,3) + ls*30 + LIGHT(x+1,y+1,z-1,3) + LIGHT(x,y+1,z-1,3)) / 75.0f;
|
float ls3 = (LIGHT(x+1,y+1,z,3) + ls*30 + LIGHT(x+1,y+1,z-1,3) + LIGHT(x,y+1,z-1,3)) / 75.0f;
|
||||||
|
|
||||||
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u2,v1, lr0, lg0, lb0, ls0);
|
if ((rot == 0) || (rot == 2)){
|
||||||
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u2,v2, lr1, lg1, lb1, ls1);
|
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u2,v1, lr0,lg0,lb0,ls0);
|
||||||
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u1,v2, lr2, lg2, lb2, ls2);
|
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
|
|
||||||
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u2,v1, lr0, lg0, lb0, ls0);
|
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u2,v1, lr0,lg0,lb0,ls0);
|
||||||
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u1,v2, lr2, lg2, lb2, ls2);
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u1,v1, lr3, lg3, lb3, ls3);
|
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u1,v1, lr3,lg3,lb3,ls3);
|
||||||
|
} else if (rot == 1){
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u2,v1, lr1,lg1,lb1,ls1);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u2,v2, lr2,lg2,lb2,ls2);
|
||||||
|
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u2,v2, lr2,lg2,lb2,ls2);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u1,v2, lr3,lg3,lb3,ls3);
|
||||||
|
} else if (rot == 3){
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u2,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
|
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u2,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u1,v1, lr3,lg3,lb3,ls3);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!IS_BLOCKED(x,y-1,z,group)){
|
if (!IS_BLOCKED(x,y-1,z,group)){
|
||||||
l = 0.75f;
|
l = 0.75f;
|
||||||
|
|
||||||
SETUP_UV(block->textureFaces[2]);
|
SETUP_UV(textureCopyFaces[2]);
|
||||||
|
|
||||||
const float lr = LIGHT(x,y-1,z, 0) / 15.0f;
|
const float lr = LIGHT(x,y-1,z, 0) / 15.0f;
|
||||||
const float lg = LIGHT(x,y-1,z, 1) / 15.0f;
|
const float lg = LIGHT(x,y-1,z, 1) / 15.0f;
|
||||||
@ -118,6 +160,23 @@ inline void _renderBlock(std::vector<float>& buffer, int x, int y, int z, const
|
|||||||
float ls2 = (LIGHT(x-1,y-1,z+1,3) + ls*30 + LIGHT(x-1,y-1,z,3) + LIGHT(x,y-1,z+1,3)) / 75.0f;
|
float ls2 = (LIGHT(x-1,y-1,z+1,3) + ls*30 + LIGHT(x-1,y-1,z,3) + LIGHT(x,y-1,z+1,3)) / 75.0f;
|
||||||
float ls3 = (LIGHT(x+1,y-1,z-1,3) + ls*30 + LIGHT(x+1,y-1,z,3) + LIGHT(x,y-1,z-1,3)) / 75.0f;
|
float ls3 = (LIGHT(x+1,y-1,z-1,3) + ls*30 + LIGHT(x+1,y-1,z,3) + LIGHT(x,y-1,z-1,3)) / 75.0f;
|
||||||
|
|
||||||
|
if ((rot == 0) || (rot == 2)){
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
|
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u2,v1, lr3,lg3,lb3,ls3);
|
||||||
|
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
} else if (rot == 1){
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u2,v2, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u1,v1, lr1,lg1,lb1,ls1);
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
|
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u2,v2, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u2,v1, lr3,lg3,lb3,ls3);
|
||||||
|
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u1,v1, lr1,lg1,lb1,ls1);
|
||||||
|
} else if (rot == 3){
|
||||||
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
@ -126,11 +185,12 @@ inline void _renderBlock(std::vector<float>& buffer, int x, int y, int z, const
|
|||||||
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u2,v1, lr3,lg3,lb3,ls3);
|
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u2,v1, lr3,lg3,lb3,ls3);
|
||||||
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!IS_BLOCKED(x+1,y,z,group)){
|
if (!IS_BLOCKED(x+1,y,z,group)){
|
||||||
l = 0.95f;
|
l = 0.95f;
|
||||||
|
|
||||||
SETUP_UV(block->textureFaces[1]);
|
SETUP_UV(textureCopyFaces[1]);
|
||||||
|
|
||||||
const float lr = LIGHT(x+1,y,z, 0) / 15.0f;
|
const float lr = LIGHT(x+1,y,z, 0) / 15.0f;
|
||||||
const float lg = LIGHT(x+1,y,z, 1) / 15.0f;
|
const float lg = LIGHT(x+1,y,z, 1) / 15.0f;
|
||||||
@ -157,6 +217,7 @@ inline void _renderBlock(std::vector<float>& buffer, int x, int y, int z, const
|
|||||||
float ls2 = (LIGHT(x+1,y+1,z+1,3) + ls*30 + LIGHT(x+1,y,z+1,3) + LIGHT(x+1,y+1,z,3)) / 75.0f;
|
float ls2 = (LIGHT(x+1,y+1,z+1,3) + ls*30 + LIGHT(x+1,y,z+1,3) + LIGHT(x+1,y+1,z,3)) / 75.0f;
|
||||||
float ls3 = (LIGHT(x+1,y-1,z+1,3) + ls*30 + LIGHT(x+1,y,z+1,3) + LIGHT(x+1,y-1,z,3)) / 75.0f;
|
float ls3 = (LIGHT(x+1,y-1,z+1,3) + ls*30 + LIGHT(x+1,y,z+1,3) + LIGHT(x+1,y-1,z,3)) / 75.0f;
|
||||||
|
|
||||||
|
if ((rot == 0) || (rot == 2)){
|
||||||
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u2,v1, lr0,lg0,lb0,ls0);
|
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u2,v1, lr0,lg0,lb0,ls0);
|
||||||
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
@ -164,11 +225,28 @@ inline void _renderBlock(std::vector<float>& buffer, int x, int y, int z, const
|
|||||||
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u2,v1, lr0,lg0,lb0,ls0);
|
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u2,v1, lr0,lg0,lb0,ls0);
|
||||||
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u1,v1, lr3,lg3,lb3,ls3);
|
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u1,v1, lr3,lg3,lb3,ls3);
|
||||||
|
} else if (rot == 1){
|
||||||
|
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u1,v2, lr1,lg1,lb1,ls1);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u2,v2, lr2,lg2,lb2,ls2);
|
||||||
|
|
||||||
|
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u2,v2, lr3,lg2,lb2,ls2);
|
||||||
|
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u2,v1, lr1,lg3,lb3,ls3);
|
||||||
|
} else if (rot == 3){
|
||||||
|
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u2,v2, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u1,v2, lr1,lg1,lb1,ls1);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u1,v1, lr2,lg2,lb2,ls2);
|
||||||
|
|
||||||
|
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u2,v2, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u1,v1, lr3,lg2,lb2,ls2);
|
||||||
|
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u2,v1, lr1,lg3,lb3,ls3);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!IS_BLOCKED(x-1,y,z,group)){
|
if (!IS_BLOCKED(x-1,y,z,group)){
|
||||||
l = 0.85f;
|
l = 0.85f;
|
||||||
|
|
||||||
SETUP_UV(block->textureFaces[0]);
|
SETUP_UV(textureCopyFaces[0]);
|
||||||
|
|
||||||
const float lr = LIGHT(x-1,y,z, 0) / 15.0f;
|
const float lr = LIGHT(x-1,y,z, 0) / 15.0f;
|
||||||
const float lg = LIGHT(x-1,y,z, 1) / 15.0f;
|
const float lg = LIGHT(x-1,y,z, 1) / 15.0f;
|
||||||
@ -195,6 +273,7 @@ inline void _renderBlock(std::vector<float>& buffer, int x, int y, int z, const
|
|||||||
float ls2 = (LIGHT(x-1,y+1,z-1,3) + ls*30 + LIGHT(x-1,y,z-1,3) + LIGHT(x-1,y+1,z,3)) / 75.0f;
|
float ls2 = (LIGHT(x-1,y+1,z-1,3) + ls*30 + LIGHT(x-1,y,z-1,3) + LIGHT(x-1,y+1,z,3)) / 75.0f;
|
||||||
float ls3 = (LIGHT(x-1,y-1,z+1,3) + ls*30 + LIGHT(x-1,y,z+1,3) + LIGHT(x-1,y-1,z,3)) / 75.0f;
|
float ls3 = (LIGHT(x-1,y-1,z+1,3) + ls*30 + LIGHT(x-1,y,z+1,3) + LIGHT(x-1,y-1,z,3)) / 75.0f;
|
||||||
|
|
||||||
|
if ((rot == 0) || (rot == 2)){
|
||||||
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
@ -202,12 +281,29 @@ inline void _renderBlock(std::vector<float>& buffer, int x, int y, int z, const
|
|||||||
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u2,v1, lr3,lg3,lb3,ls3);
|
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u2,v1, lr3,lg3,lb3,ls3);
|
||||||
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
} else if (rot == 1){
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
|
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u2,v1, lr3,lg3,lb3,ls3);
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
} else if (rot == 3){
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u2,v1, lr2,lg2,lb2,ls2);
|
||||||
|
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u1,v2, lr3,lg3,lb3,ls3);
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IS_BLOCKED(x,y,z+1,group)){
|
if (!IS_BLOCKED(x,y,z+1,group)){
|
||||||
l = 0.9f;
|
l = 0.9f;
|
||||||
|
|
||||||
SETUP_UV(block->textureFaces[5]);
|
SETUP_UV(textureCopyFaces[5]);
|
||||||
|
|
||||||
const float lr = LIGHT(x,y,z+1, 0) / 15.0f;
|
const float lr = LIGHT(x,y,z+1, 0) / 15.0f;
|
||||||
const float lg = LIGHT(x,y,z+1, 1) / 15.0f;
|
const float lg = LIGHT(x,y,z+1, 1) / 15.0f;
|
||||||
@ -234,6 +330,23 @@ inline void _renderBlock(std::vector<float>& buffer, int x, int y, int z, const
|
|||||||
float ls2 = l*(LIGHT(x-1,y+1,z+1,3) + ls*30 + LIGHT(x,y+1,z+1,3) + LIGHT(x-1,y,z+1,3)) / 75.0f;
|
float ls2 = l*(LIGHT(x-1,y+1,z+1,3) + ls*30 + LIGHT(x,y+1,z+1,3) + LIGHT(x-1,y,z+1,3)) / 75.0f;
|
||||||
float ls3 = l*(LIGHT(x+1,y-1,z+1,3) + ls*30 + LIGHT(x,y-1,z+1,3) + LIGHT(x+1,y,z+1,3)) / 75.0f;
|
float ls3 = l*(LIGHT(x+1,y-1,z+1,3) + ls*30 + LIGHT(x,y-1,z+1,3) + LIGHT(x+1,y,z+1,3)) / 75.0f;
|
||||||
|
|
||||||
|
if ((rot == 0) || (rot == 2)){
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
|
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u2,v1, lr3,lg3,lb3,ls3);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
} else if (rot == 1){
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u2,v1, lr2,lg2,lb2,ls2);
|
||||||
|
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u1,v2, lr3,lg3,lb3,ls3);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
} else if (rot == 3){
|
||||||
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
VERTEX(index, x-0.5f, y-0.5f, z+0.5f, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
VERTEX(index, x-0.5f, y+0.5f, z+0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
@ -242,10 +355,11 @@ inline void _renderBlock(std::vector<float>& buffer, int x, int y, int z, const
|
|||||||
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u2,v1, lr3,lg3,lb3,ls3);
|
VERTEX(index, x+0.5f, y-0.5f, z+0.5f, u2,v1, lr3,lg3,lb3,ls3);
|
||||||
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
VERTEX(index, x+0.5f, y+0.5f, z+0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!IS_BLOCKED(x,y,z-1,group)){
|
if (!IS_BLOCKED(x,y,z-1,group)){
|
||||||
l = 0.8f;
|
l = 0.8f;
|
||||||
|
|
||||||
SETUP_UV(block->textureFaces[4]);
|
SETUP_UV(textureCopyFaces[4]);
|
||||||
|
|
||||||
const float lr = LIGHT(x,y,z-1, 0) / 15.0f;
|
const float lr = LIGHT(x,y,z-1, 0) / 15.0f;
|
||||||
const float lg = LIGHT(x,y,z-1, 1) / 15.0f;
|
const float lg = LIGHT(x,y,z-1, 1) / 15.0f;
|
||||||
@ -272,6 +386,23 @@ inline void _renderBlock(std::vector<float>& buffer, int x, int y, int z, const
|
|||||||
float ls2 = l*(LIGHT(x+1,y+1,z-1,3) + ls*30 + LIGHT(x,y+1,z-1,3) + LIGHT(x+1,y,z-1,3)) / 75.0f;
|
float ls2 = l*(LIGHT(x+1,y+1,z-1,3) + ls*30 + LIGHT(x,y+1,z-1,3) + LIGHT(x+1,y,z-1,3)) / 75.0f;
|
||||||
float ls3 = l*(LIGHT(x+1,y-1,z-1,3) + ls*30 + LIGHT(x,y-1,z-1,3) + LIGHT(x+1,y,z-1,3)) / 75.0f;
|
float ls3 = l*(LIGHT(x+1,y-1,z-1,3) + ls*30 + LIGHT(x,y-1,z-1,3) + LIGHT(x+1,y,z-1,3)) / 75.0f;
|
||||||
|
|
||||||
|
if ((rot == 0) || (rot == 2)){
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u2,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
|
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u2,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
|
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u1,v1, lr3,lg3,lb3,ls3);
|
||||||
|
} else if (rot == 1){
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u2,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u1,v1, lr1,lg1,lb1,ls1);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
|
|
||||||
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u2,v1, lr0,lg0,lb0,ls0);
|
||||||
|
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
|
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u2,v2, lr3,lg3,lb3,ls3);
|
||||||
|
} else if (rot == 3){
|
||||||
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u2,v1, lr0,lg0,lb0,ls0);
|
VERTEX(index, x-0.5f, y-0.5f, z-0.5f, u2,v1, lr0,lg0,lb0,ls0);
|
||||||
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
VERTEX(index, x-0.5f, y+0.5f, z-0.5f, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
@ -280,13 +411,13 @@ inline void _renderBlock(std::vector<float>& buffer, int x, int y, int z, const
|
|||||||
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
VERTEX(index, x+0.5f, y+0.5f, z-0.5f, u1,v2, lr2,lg2,lb2,ls2);
|
||||||
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u1,v1, lr3,lg3,lb3,ls3);
|
VERTEX(index, x+0.5f, y-0.5f, z-0.5f, u1,v1, lr3,lg3,lb3,ls3);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void _renderBlockShadeless(std::vector<float>& buffer, int x, int y, int z, const Chunk** chunks, unsigned int id, size_t& index){
|
inline void _renderBlockShadeless(std::vector<float>& buffer, int x, int y, int z, const Chunk** chunks, voxel vox, size_t& index){
|
||||||
float l;
|
|
||||||
float uvsize = 1.0f/16.0f;
|
float uvsize = 1.0f/16.0f;
|
||||||
|
|
||||||
Block* block = Block::blocks[id];
|
Block* block = Block::blocks[vox.id];
|
||||||
unsigned char group = block->drawGroup;
|
unsigned char group = block->drawGroup;
|
||||||
|
|
||||||
if (!IS_BLOCKED(x,y+1,z,group)){
|
if (!IS_BLOCKED(x,y+1,z,group)){
|
||||||
@ -363,7 +494,7 @@ inline void _renderBlockShadeless(std::vector<float>& buffer, int x, int y, int
|
|||||||
inline void _renderXBlock(std::vector<float>& buffer, int x, int y, int z, const Chunk** chunks, voxel vox, size_t& index){
|
inline void _renderXBlock(std::vector<float>& buffer, int x, int y, int z, const Chunk** chunks, voxel vox, size_t& index){
|
||||||
Block* block = Block::blocks[vox.id];
|
Block* block = Block::blocks[vox.id];
|
||||||
|
|
||||||
int rand = ((x * z + y) xor (z * y - x)) * (z + y);
|
int rand = ((x * z + y) ^ (z * y - x)) * (z + y);
|
||||||
|
|
||||||
float xs = (float)(char)rand / 512;
|
float xs = (float)(char)rand / 512;
|
||||||
float zs = (float)(char)(rand >> 8) / 512;
|
float zs = (float)(char)(rand >> 8) / 512;
|
||||||
@ -374,86 +505,62 @@ inline void _renderXBlock(std::vector<float>& buffer, int x, int y, int z, const
|
|||||||
|
|
||||||
float uvsize = 1.0f/16.0f;
|
float uvsize = 1.0f/16.0f;
|
||||||
|
|
||||||
float lr = LIGHT(x,y,z, 0) / 15.0f;
|
float lr = LIGHT(x,y,z, 0);
|
||||||
float lg = LIGHT(x,y,z, 1) / 15.0f;
|
float lg = LIGHT(x,y,z, 1);
|
||||||
float lb = LIGHT(x,y,z, 2) / 15.0f;
|
float lb = LIGHT(x,y,z, 2);
|
||||||
float ls = LIGHT(x,y,z, 3) / 15.0f;
|
float ls = LIGHT(x,y,z, 3);
|
||||||
|
|
||||||
float lr0 = (LIGHT(x,y-1,z,0) + lr*30) / 45.0f;
|
float lr0 = (LIGHT(x,y-1,z,0) + lr*3) / 60.0f;
|
||||||
float lr1 = (LIGHT(x,y+1,z,0) + lr*30) / 45.0f;
|
float lr1 = (LIGHT(x,y+1,z,0) + lr*3) / 60.0f;
|
||||||
float lr2 = (LIGHT(x,y+1,z,0) + lr*30) / 45.0f;
|
|
||||||
float lr3 = (LIGHT(x,y-1,z,0) + lr*30) / 45.0f;
|
|
||||||
float lr4 = (LIGHT(x,y-1,z,0) + lr*30) / 45.0f;
|
|
||||||
float lr5 = (LIGHT(x,y+1,z,0) + lr*30) / 45.0f;
|
|
||||||
float lr6 = (LIGHT(x,y+1,z,0) + lr*30) / 45.0f;
|
|
||||||
float lr7 = (LIGHT(x,y-1,z,0) + lr*30) / 45.0f;
|
|
||||||
|
|
||||||
float lg0 = (LIGHT(x,y-1,z,1) + lg*30) / 45.0f;
|
float lg0 = (LIGHT(x,y-1,z,1) + lg*3) / 60.0f;
|
||||||
float lg1 = (LIGHT(x,y+1,z,1) + lg*30) / 45.0f;
|
float lg1 = (LIGHT(x,y+1,z,1) + lg*3) / 60.0f;
|
||||||
float lg2 = (LIGHT(x,y+1,z,1) + lg*30) / 45.0f;
|
|
||||||
float lg3 = (LIGHT(x,y-1,z,1) + lg*30) / 45.0f;
|
|
||||||
float lg4 = (LIGHT(x,y-1,z,1) + lg*30) / 45.0f;
|
|
||||||
float lg5 = (LIGHT(x,y+1,z,1) + lg*30) / 45.0f;
|
|
||||||
float lg6 = (LIGHT(x,y+1,z,1) + lg*30) / 45.0f;
|
|
||||||
float lg7 = (LIGHT(x,y-1,z,1) + lg*30) / 45.0f;
|
|
||||||
|
|
||||||
float lb0 = (LIGHT(x,y-1,z,2) + lb*30) / 45.0f;
|
float lb0 = (LIGHT(x,y-1,z,2) + lb*3) / 60.0f;
|
||||||
float lb1 = (LIGHT(x,y+1,z,2) + lb*30) / 45.0f;
|
float lb1 = (LIGHT(x,y+1,z,2) + lb*3) / 60.0f;
|
||||||
float lb2 = (LIGHT(x,y+1,z,2) + lb*30) / 45.0f;
|
|
||||||
float lb3 = (LIGHT(x,y-1,z,2) + lb*30) / 45.0f;
|
|
||||||
float lb4 = (LIGHT(x,y-1,z,2) + lb*30) / 45.0f;
|
|
||||||
float lb5 = (LIGHT(x,y+1,z,2) + lb*30) / 45.0f;
|
|
||||||
float lb6 = (LIGHT(x,y+1,z,2) + lb*30) / 45.0f;
|
|
||||||
float lb7 = (LIGHT(x,y-1,z,2) + lb*30) / 45.0f;
|
|
||||||
|
|
||||||
float ls0 = (LIGHT(x,y-1,z,3) + ls*30) / 45.0f;
|
float ls0 = (LIGHT(x,y-1,z,3) + ls*3) / 60.0f;
|
||||||
float ls1 = (LIGHT(x,y+1,z,3) + ls*30) / 45.0f;
|
float ls1 = (LIGHT(x,y+1,z,3) + ls*3) / 60.0f;
|
||||||
float ls2 = (LIGHT(x,y+1,z,3) + ls*30) / 45.0f;
|
|
||||||
float ls3 = (LIGHT(x,y-1,z,3) + ls*30) / 45.0f;
|
|
||||||
float ls4 = (LIGHT(x,y-1,z,3) + ls*30) / 45.0f;
|
|
||||||
float ls5 = (LIGHT(x,y+1,z,3) + ls*30) / 45.0f;
|
|
||||||
float ls6 = (LIGHT(x,y+1,z,3) + ls*30) / 45.0f;
|
|
||||||
float ls7 = (LIGHT(x,y-1,z,3) + ls*30) / 45.0f;
|
|
||||||
|
|
||||||
{SETUP_UV(block->textureFaces[1]);
|
{SETUP_UV(block->textureFaces[1]);
|
||||||
|
|
||||||
VERTEX(index, x-0.5f+xs, y-0.5f, z-0.5f+zs, u2,v1, lr0,lg0,lb0,ls0);
|
VERTEX(index, x-0.3535f+xs, y-0.5f, z-0.3535f+zs, u2,v1, lr0,lg0,lb0,ls0);
|
||||||
VERTEX(index, x-0.5f+xs, y+0.5f, z-0.5f+zs, u2,v2, lr1,lg1,lb1,ls1);
|
VERTEX(index, x-0.3535f+xs, y+0.5f, z-0.3535f+zs, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
VERTEX(index, x+0.5f+xs, y+0.5f, z+0.5f+zs, u1,v2, lr2,lg2,lb2,ls2);
|
VERTEX(index, x+0.3535f+xs, y+0.5f, z+0.3535f+zs, u1,v2, lr1,lg1,lb1,ls1);
|
||||||
|
|
||||||
VERTEX(index, x-0.5f+xs, y-0.5f, z-0.5f+zs, u2,v1, lr0,lg0,lb0,ls0);
|
VERTEX(index, x-0.3535f+xs, y-0.5f, z-0.3535f+zs, u2,v1, lr0,lg0,lb0,ls0);
|
||||||
VERTEX(index, x+0.5f+xs, y+0.5f, z+0.5f+zs, u1,v2, lr2,lg2,lb2,ls2);
|
VERTEX(index, x+0.3535f+xs, y+0.5f, z+0.3535f+zs, u1,v2, lr1,lg1,lb1,ls1);
|
||||||
VERTEX(index, x+0.5f+xs, y-0.5f, z+0.5f+zs, u1,v1, lr3,lg3,lb3,ls3);}
|
VERTEX(index, x+0.3535f+xs, y-0.5f, z+0.3535f+zs, u1,v1, lr0,lg0,lb0,ls0);}
|
||||||
|
|
||||||
{SETUP_UV(block->textureFaces[0]);
|
{SETUP_UV(block->textureFaces[0]);
|
||||||
|
|
||||||
VERTEX(index, x-0.5f+xs, y-0.5f, z-0.5f+zs, u1,v1, lr0,lg0,lb0,ls0);
|
VERTEX(index, x-0.3535f+xs, y-0.5f, z-0.3535f+zs, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
VERTEX(index, x+0.5f+xs, y+0.5f, z+0.5f+zs, u2,v2, lr1,lg1,lb1,ls1);
|
VERTEX(index, x+0.3535f+xs, y+0.5f, z+0.3535f+zs, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
VERTEX(index, x-0.5f+xs, y+0.5f, z-0.5f+zs, u1,v2, lr2,lg2,lb2,ls2);
|
VERTEX(index, x-0.3535f+xs, y+0.5f, z-0.3535f+zs, u1,v2, lr1,lg1,lb1,ls1);
|
||||||
|
|
||||||
VERTEX(index, x-0.5f+xs, y-0.5f, z-0.5f+zs, u1,v1, lr0,lg0,lb0,ls0);
|
VERTEX(index, x-0.3535f+xs, y-0.5f, z-0.3535f+zs, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
VERTEX(index, x+0.5f+xs, y-0.5f, z+0.5f+zs, u2,v1, lr3,lg3,lb3,ls3);
|
VERTEX(index, x+0.3535f+xs, y-0.5f, z+0.3535f+zs, u2,v1, lr0,lg0,lb0,ls0);
|
||||||
VERTEX(index, x+0.5f+xs, y+0.5f, z+0.5f+zs, u2,v2, lr1,lg1,lb1,ls1);}
|
VERTEX(index, x+0.3535f+xs, y+0.5f, z+0.3535f+zs, u2,v2, lr1,lg1,lb1,ls1);}
|
||||||
|
|
||||||
{SETUP_UV(block->textureFaces[5]);
|
{SETUP_UV(block->textureFaces[5]);
|
||||||
|
|
||||||
VERTEX(index, x-0.5f+xs, y-0.5f, z+0.5f+zs, u1,v1, lr4,lg4,lb4,ls4);
|
VERTEX(index, x-0.3535f+xs, y-0.5f, z+0.3535f+zs, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
VERTEX(index, x+0.5f+xs, y+0.5f, z-0.5f+zs, u2,v2, lr5,lg5,lb5,ls5);
|
VERTEX(index, x+0.3535f+xs, y+0.5f, z-0.3535f+zs, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
VERTEX(index, x-0.5f+xs, y+0.5f, z+0.5f+zs, u1,v2, lr6,lg6,lb6,ls6);
|
VERTEX(index, x-0.3535f+xs, y+0.5f, z+0.3535f+zs, u1,v2, lr1,lg1,lb1,ls1);
|
||||||
|
|
||||||
VERTEX(index, x-0.5f+xs, y-0.5f, z+0.5f+zs, u1,v1, lr4,lg4,lb4,ls4);
|
VERTEX(index, x-0.3535f+xs, y-0.5f, z+0.3535f+zs, u1,v1, lr0,lg0,lb0,ls0);
|
||||||
VERTEX(index, x+0.5f+xs, y-0.5f, z-0.5f+zs, u2,v1, lr7,lg7,lb7,ls7);
|
VERTEX(index, x+0.3535f+xs, y-0.5f, z-0.3535f+zs, u2,v1, lr0,lg0,lb0,ls0);
|
||||||
VERTEX(index, x+0.5f+xs, y+0.5f, z-0.5f+zs, u2,v2, lr5,lg5,lb5,ls5);}
|
VERTEX(index, x+0.3535f+xs, y+0.5f, z-0.3535f+zs, u2,v2, lr1,lg1,lb1,ls1);}
|
||||||
|
|
||||||
{SETUP_UV(block->textureFaces[4]);
|
{SETUP_UV(block->textureFaces[4]);
|
||||||
|
|
||||||
VERTEX(index, x-0.5f+xs, y-0.5f, z+0.5f+zs, u2,v1, lr4,lg4,lb4,ls4);
|
VERTEX(index, x-0.3535f+xs, y-0.5f, z+0.3535f+zs, u2,v1, lr0,lg0,lb0,ls0);
|
||||||
VERTEX(index, x-0.5f+xs, y+0.5f, z+0.5f+zs, u2,v2, lr5,lg5,lb5,ls5);
|
VERTEX(index, x-0.3535f+xs, y+0.5f, z+0.3535f+zs, u2,v2, lr1,lg1,lb1,ls1);
|
||||||
VERTEX(index, x+0.5f+xs, y+0.5f, z-0.5f+zs, u1,v2, lr6,lg6,lb6,ls6);
|
VERTEX(index, x+0.3535f+xs, y+0.5f, z-0.3535f+zs, u1,v2, lr1,lg1,lb1,ls1);
|
||||||
|
|
||||||
VERTEX(index, x-0.5f+xs, y-0.5f, z+0.5f+zs, u2,v1, lr4,lg4,lb4,ls4);
|
VERTEX(index, x-0.3535f+xs, y-0.5f, z+0.3535f+zs, u2,v1, lr0,lg0,lb0,ls0);
|
||||||
VERTEX(index, x+0.5f+xs, y+0.5f, z-0.5f+zs, u1,v2, lr6,lg6,lb6,ls6);
|
VERTEX(index, x+0.3535f+xs, y+0.5f, z-0.3535f+zs, u1,v2, lr1,lg1,lb1,ls1);
|
||||||
VERTEX(index, x+0.5f+xs, y-0.5f, z-0.5f+zs, u1,v1, lr7,lg7,lb7,ls7);}
|
VERTEX(index, x+0.3535f+xs, y-0.5f, z-0.3535f+zs, u1,v1, lr0,lg0,lb0,ls0);}
|
||||||
}
|
}
|
||||||
|
|
||||||
const float* VoxelRenderer::render(Chunk* chunk, const Chunk** chunks, size_t& size){
|
const float* VoxelRenderer::render(Chunk* chunk, const Chunk** chunks, size_t& size){
|
||||||
@ -471,7 +578,7 @@ const float* VoxelRenderer::render(Chunk* chunk, const Chunk** chunks, size_t& s
|
|||||||
if (block->emission[0] || block->emission[1] || block->emission[2]){
|
if (block->emission[0] || block->emission[1] || block->emission[2]){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
_renderBlock(buffer, x, y, z, chunks, vox.id, index);
|
_renderBlock(buffer, x, y, z, chunks, vox, index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -484,7 +591,7 @@ const float* VoxelRenderer::render(Chunk* chunk, const Chunk** chunks, size_t& s
|
|||||||
continue;
|
continue;
|
||||||
Block* block = Block::blocks[vox.id];
|
Block* block = Block::blocks[vox.id];
|
||||||
if (block->emission[0] || block->emission[1] || block->emission[2]){
|
if (block->emission[0] || block->emission[1] || block->emission[2]){
|
||||||
_renderBlockShadeless(buffer, x, y, z, chunks, vox.id, index);
|
_renderBlockShadeless(buffer, x, y, z, chunks, vox, index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -498,7 +605,7 @@ const float* VoxelRenderer::render(Chunk* chunk, const Chunk** chunks, size_t& s
|
|||||||
continue;
|
continue;
|
||||||
if (vox.id != 9)
|
if (vox.id != 9)
|
||||||
continue;
|
continue;
|
||||||
_renderBlock(buffer, x, y, z, chunks, vox.id, index);
|
_renderBlock(buffer, x, y, z, chunks, vox, index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -509,7 +616,7 @@ const float* VoxelRenderer::render(Chunk* chunk, const Chunk** chunks, size_t& s
|
|||||||
voxel vox = chunk->voxels[(y * CHUNK_D + z) * CHUNK_W + x];
|
voxel vox = chunk->voxels[(y * CHUNK_D + z) * CHUNK_W + x];
|
||||||
if (vox.id == 0)
|
if (vox.id == 0)
|
||||||
continue;
|
continue;
|
||||||
if (Block::blocks[vox.id]->model != BLOCK_MODEL_GRASS)
|
if (Block::blocks[vox.id]->model != BLOCK_MODEL_X_SPRITE)
|
||||||
continue;
|
continue;
|
||||||
_renderXBlock(buffer, x, y, z, chunks, vox, index);
|
_renderXBlock(buffer, x, y, z, chunks, vox, index);
|
||||||
}
|
}
|
||||||
@ -524,7 +631,7 @@ const float* VoxelRenderer::render(Chunk* chunk, const Chunk** chunks, size_t& s
|
|||||||
continue;
|
continue;
|
||||||
if (vox.id != 4)
|
if (vox.id != 4)
|
||||||
continue;
|
continue;
|
||||||
_renderBlock(buffer, x, y, z, chunks, vox.id, index);
|
_renderBlock(buffer, x, y, z, chunks, vox, index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
#include "typedefs.h"
|
||||||
#include "Assets.h"
|
#include "Assets.h"
|
||||||
#include "graphics/Shader.h"
|
#include "graphics/Shader.h"
|
||||||
#include "graphics/Batch2D.h"
|
#include "graphics/Batch2D.h"
|
||||||
@ -18,18 +20,18 @@
|
|||||||
|
|
||||||
|
|
||||||
HudRenderer::HudRenderer() {
|
HudRenderer::HudRenderer() {
|
||||||
float vertices[] = {
|
// float vertices[] = {
|
||||||
// x y
|
// // x y
|
||||||
-0.01f,-0.01f,
|
// -0.01f,-0.01f,
|
||||||
0.01f, 0.01f,
|
// 0.01f, 0.01f,
|
||||||
|
|
||||||
-0.01f, 0.01f,
|
// -0.01f, 0.01f,
|
||||||
0.01f,-0.01f,
|
// 0.01f,-0.01f,
|
||||||
};
|
// };
|
||||||
int attrs[] = {
|
// int attrs[] = {
|
||||||
2, 0 //null terminator
|
// 2, 0 //null terminator
|
||||||
};
|
// };
|
||||||
crosshair = new Mesh(vertices, 4, attrs);
|
// crosshair = new Mesh(vertices, 4, attrs);
|
||||||
|
|
||||||
batch = new Batch2D(1024);
|
batch = new Batch2D(1024);
|
||||||
uicamera = new Camera(glm::vec3(), Window::height / 1.0f);
|
uicamera = new Camera(glm::vec3(), Window::height / 1.0f);
|
||||||
@ -38,7 +40,7 @@ HudRenderer::HudRenderer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
HudRenderer::~HudRenderer() {
|
HudRenderer::~HudRenderer() {
|
||||||
delete crosshair;
|
// delete crosshair;
|
||||||
delete batch;
|
delete batch;
|
||||||
delete uicamera;
|
delete uicamera;
|
||||||
}
|
}
|
||||||
@ -56,12 +58,12 @@ void HudRenderer::drawDebug(Level* level, Assets* assets, int fps, bool occlusio
|
|||||||
batch->begin();
|
batch->begin();
|
||||||
font->draw(batch, L"chunks: "+std::to_wstring(chunks->chunksCount), 16, 16, STYLE_OUTLINE);
|
font->draw(batch, L"chunks: "+std::to_wstring(chunks->chunksCount), 16, 16, STYLE_OUTLINE);
|
||||||
font->draw(batch, std::to_wstring((int)player->camera->position.x), 10, 30, STYLE_OUTLINE);
|
font->draw(batch, std::to_wstring((int)player->camera->position.x), 10, 30, STYLE_OUTLINE);
|
||||||
font->draw(batch, std::to_wstring((int)player->camera->position.y), 50, 30, STYLE_OUTLINE);
|
font->draw(batch, std::to_wstring((int)player->camera->position.y), 90, 30, STYLE_OUTLINE);
|
||||||
font->draw(batch, std::to_wstring((int)player->camera->position.z), 90, 30, STYLE_OUTLINE);
|
font->draw(batch, std::to_wstring((int)player->camera->position.z), 170, 30, STYLE_OUTLINE);
|
||||||
font->draw(batch, L"fps:", 16, 42, STYLE_OUTLINE);
|
font->draw(batch, L"fps:", 16, 42, STYLE_OUTLINE);
|
||||||
font->draw(batch, std::to_wstring(fps), 44, 42, STYLE_OUTLINE);
|
font->draw(batch, std::to_wstring(fps), 44, 42, STYLE_OUTLINE);
|
||||||
font->draw(batch, L"occlusion: "+std::to_wstring(occlusion), 16, 54, STYLE_OUTLINE);
|
font->draw(batch, L"occlusion: "+std::to_wstring(occlusion), 16, 54, STYLE_OUTLINE);
|
||||||
batch->render();
|
// batch->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -79,62 +81,148 @@ void HudRenderer::draw(Level* level, Assets* assets){
|
|||||||
Texture* blocks = assets->getTexture("block");
|
Texture* blocks = assets->getTexture("block");
|
||||||
Texture* sprite = assets->getTexture("slot");
|
Texture* sprite = assets->getTexture("slot");
|
||||||
|
|
||||||
if (!Events::_cursor_locked) {
|
|
||||||
batch->texture(nullptr);
|
batch->texture(nullptr);
|
||||||
batch->color = vec4(0.0f, 0.0f, 0.0f, 0.5f);
|
batch->color = vec4(1.0f);
|
||||||
batch->rect(0, 0, Window::width, Window::height);
|
if (Events::_cursor_locked && !level->player->debug) {
|
||||||
|
glLineWidth(2);
|
||||||
|
batch->line(Window::width/2, Window::height/2-6, Window::width/2, Window::height/2+6, 0.2f, 0.2f, 0.2f, 1.0f);
|
||||||
|
batch->line(Window::width/2+6, Window::height/2, Window::width/2-6, Window::height/2, 0.2f, 0.2f, 0.2f, 1.0f);
|
||||||
|
batch->line(Window::width/2-5, Window::height/2-5, Window::width/2+5, Window::height/2+5, 0.9f, 0.9f, 0.9f, 1.0f);
|
||||||
|
batch->line(Window::width/2+5, Window::height/2-5, Window::width/2-5, Window::height/2+5, 0.9f, 0.9f, 0.9f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
batch->color = vec4(1.0f);
|
// batch->texture(sprite);
|
||||||
batch->texture(sprite);
|
// batch->sprite(Window::width/2-32, uicamera->fov - 80, 64, 64, 16, 0, vec4(1.0f));
|
||||||
batch->sprite(16, uicamera->fov - 80, 64, 64, 16, 0, vec4(1.0f));
|
// batch->rect(Window::width/2-128-4, Window::height-80-4, 256+8, 64+8,
|
||||||
|
// 0.85f, 0.85f, 0.85f, 0.95f, 0.95f, 0.95f,
|
||||||
|
// 0.55f, 0.55f, 0.55f,
|
||||||
|
// 0.45f, 0.45f, 0.45f, 0.7f, 0.7f, 0.7f, 2);
|
||||||
|
batch->rect(Window::width/2-128-4, Window::height-80-4, 256+8, 64+8,
|
||||||
|
0.95f, 0.95f, 0.95f, 0.85f, 0.85f, 0.85f,
|
||||||
|
0.7f, 0.7f, 0.7f,
|
||||||
|
0.55f, 0.55f, 0.55f, 0.45f, 0.45f, 0.45f, 4);
|
||||||
|
batch->rect(Window::width/2-128, Window::height - 80, 256, 64,
|
||||||
|
0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 0.75f,
|
||||||
|
0.75f, 0.75f, 0.75f,
|
||||||
|
0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 4);
|
||||||
|
batch->rect(Window::width/2-32+2, Window::height - 80+2, 60, 60,
|
||||||
|
0.45f, 0.45f, 0.45f, 0.55f, 0.55f, 0.55f,
|
||||||
|
0.7f, 0.7f, 0.7f,
|
||||||
|
0.85f, 0.85f, 0.85f, 0.95f, 0.95f, 0.95f, 2);
|
||||||
|
batch->rect(Window::width/2-32+4, Window::height - 80+4, 56, 56,
|
||||||
|
0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 0.75f,
|
||||||
|
0.75f, 0.75f, 0.75f,
|
||||||
|
0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 2);
|
||||||
|
|
||||||
|
|
||||||
batch->texture(blocks);
|
batch->texture(blocks);
|
||||||
Player* player = level->player;
|
Player* player = level->player;
|
||||||
{
|
{
|
||||||
Block* cblock = Block::blocks[player->choosenBlock];
|
Block* cblock = Block::blocks[player->choosenBlock];
|
||||||
if (cblock->model == BLOCK_MODEL_CUBE){
|
if (cblock->model == BLOCK_MODEL_CUBE){
|
||||||
batch->blockSprite(24, uicamera->fov - 72, 48, 48, 16, cblock->textureFaces, vec4(1.0f));
|
batch->blockSprite(Window::width/2-24, uicamera->fov - 72, 48, 48, 16, cblock->textureFaces, vec4(1.0f));
|
||||||
} else if (cblock->model == BLOCK_MODEL_GRASS){
|
} else if (cblock->model == BLOCK_MODEL_X_SPRITE){
|
||||||
batch->sprite(24, uicamera->fov - 72, 48, 48, 16, cblock->textureFaces[3], vec4(1.0f));
|
batch->sprite(Window::width/2-24, uicamera->fov - 72, 48, 48, 16, cblock->textureFaces[3], vec4(1.0f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Events::_cursor_locked) {
|
if (!Events::_cursor_locked) { //inventory
|
||||||
for (unsigned i = 1; i < 256; i++) {
|
uint size = 48;
|
||||||
|
uint step = 64;
|
||||||
|
uint inv_wm = step*10;
|
||||||
|
uint inv_hm = step*8;
|
||||||
|
uint inv_w = inv_wm - (step - size);
|
||||||
|
uint inv_h = inv_hm - (step - size);
|
||||||
|
int inv_x = (Window::width - (inv_w)) / 2;
|
||||||
|
int inv_y = (Window::height - (inv_h)) / 2;
|
||||||
|
int xs = (Window::width - inv_w + step)/2;
|
||||||
|
int ys = (Window::height - inv_h + step)/2;
|
||||||
|
if (Window::width > inv_w*3){
|
||||||
|
inv_x = (Window::width + (inv_w)) / 2;
|
||||||
|
inv_y = (Window::height - (inv_h)) / 2;
|
||||||
|
xs = (Window::width + inv_w + step)/2;
|
||||||
|
ys = (Window::height - inv_h + step)/2;
|
||||||
|
}
|
||||||
|
int x = 0;
|
||||||
|
int y = 0;
|
||||||
|
vec4 tint = vec4(1.0f);
|
||||||
|
int mx = Events::x;
|
||||||
|
int my = Events::y;
|
||||||
|
uint count = (inv_w / step) * (inv_h / step) + 1;
|
||||||
|
|
||||||
|
//back
|
||||||
|
batch->texture(nullptr);
|
||||||
|
batch->color = vec4(0.0f, 0.0f, 0.0f, 0.3f);
|
||||||
|
batch->rect(0, 0, Window::width, Window::height);
|
||||||
|
batch->rect(inv_x - 4, inv_y - 4, inv_w+8, inv_h+8,
|
||||||
|
0.95f, 0.95f, 0.95f, 0.85f, 0.85f, 0.85f,
|
||||||
|
0.7f, 0.7f, 0.7f,
|
||||||
|
0.55f, 0.55f, 0.55f, 0.45f, 0.45f, 0.45f, 4);
|
||||||
|
batch->rect(inv_x, inv_y, inv_w, inv_h,
|
||||||
|
0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 0.75f,
|
||||||
|
0.75f, 0.75f, 0.75f,
|
||||||
|
0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 0.75f, 4);
|
||||||
|
|
||||||
|
batch->color = vec4(0.35f, 0.35f, 0.35f, 1.0f);
|
||||||
|
for (uint i = 1; i < count; i++) {
|
||||||
|
x = xs + step * ((i-1) % (inv_w / step));
|
||||||
|
y = ys + step * ((i-1) / (inv_w / step));
|
||||||
|
// batch->rect(x-2, y-2, size+4, size+4);
|
||||||
|
batch->rect(x-2, y-2, size+4, size+4,
|
||||||
|
0.45f, 0.45f, 0.45f, 0.55f, 0.55f, 0.55f,
|
||||||
|
0.7f, 0.7f, 0.7f,
|
||||||
|
0.85f, 0.85f, 0.85f, 0.95f, 0.95f, 0.95f, 2);
|
||||||
|
batch->rect(x, y, size, size,
|
||||||
|
0.65f, 0.65f, 0.65f, 0.65f, 0.65f, 0.65f,
|
||||||
|
0.65f, 0.65f, 0.65f,
|
||||||
|
0.65f, 0.65f, 0.65f, 0.65f, 0.65f, 0.65f, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// batch->color = vec4(0.5f, 0.5f, 0.5f, 1.0f);
|
||||||
|
// for (unsigned i = 1; i < count; i++) {
|
||||||
|
// x = xs + step * ((i-1) % (inv_w / step));
|
||||||
|
// y = ys + step * ((i-1) / (inv_w / step));
|
||||||
|
// batch->rect(x, y, size, size);
|
||||||
|
// }
|
||||||
|
|
||||||
|
//front
|
||||||
|
batch->texture(blocks);
|
||||||
|
for (uint i = 1; i < count; i++) {
|
||||||
Block* cblock = Block::blocks[i];
|
Block* cblock = Block::blocks[i];
|
||||||
if (cblock == nullptr)
|
if (cblock == nullptr)
|
||||||
break;
|
break;
|
||||||
int size = 48;
|
x = xs + step * ((i-1) % (inv_w / step));
|
||||||
int step = 70;
|
y = ys + step * ((i-1) / (inv_w / step));
|
||||||
int x = 24 + (i-1) * step;
|
if (mx > x && mx < x + (int)size && my > y && my < y + (int)size) {
|
||||||
int y = uicamera->fov - 72 - 70;
|
tint.r *= 1.2f;
|
||||||
y -= 72 * (x / (Window::width - step));
|
tint.g *= 1.2f;
|
||||||
x %= (Window::width - step);
|
tint.b *= 1.2f;
|
||||||
vec4 tint(1.0f);
|
|
||||||
int mx = Events::x;
|
|
||||||
int my = Events::y;
|
|
||||||
if (mx > x && mx < x + size && my > y && my < y + size) {
|
|
||||||
tint.r *= 2.0f;
|
|
||||||
tint.g *= 2.0f;
|
|
||||||
tint.b *= 2.0f;
|
|
||||||
if (Events::jclicked(GLFW_MOUSE_BUTTON_LEFT)) {
|
if (Events::jclicked(GLFW_MOUSE_BUTTON_LEFT)) {
|
||||||
player->choosenBlock = i;
|
player->choosenBlock = i;
|
||||||
}
|
}
|
||||||
|
// size = 50;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
// size = 48;
|
||||||
|
tint = vec4(1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cblock->model == BLOCK_MODEL_CUBE){
|
if (cblock->model == BLOCK_MODEL_CUBE){
|
||||||
batch->blockSprite(x, y, size, size, 16, cblock->textureFaces, tint);
|
batch->blockSprite(x, y, size, size, 16, cblock->textureFaces, tint);
|
||||||
} else if (cblock->model == BLOCK_MODEL_GRASS){
|
} else if (cblock->model == BLOCK_MODEL_X_SPRITE){
|
||||||
batch->sprite(x, y, size, size, 16, cblock->textureFaces[3], tint);
|
batch->sprite(x, y, size, size, 16, cblock->textureFaces[3], tint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
batch->render();
|
// batch->render();
|
||||||
|
|
||||||
Shader* crosshairShader = assets->getShader("crosshair");
|
if (Events::_cursor_locked && !level->player->debug){
|
||||||
crosshairShader->use();
|
// Shader* crosshairShader = assets->getShader("crosshair");
|
||||||
crosshairShader->uniform1f("u_ar", (float)Window::height / (float)Window::width);
|
// crosshairShader->use();
|
||||||
crosshairShader->uniform1f("u_scale", 1.0f / ((float)Window::height / 1000.0f));
|
// crosshairShader->uniform1f("u_ar", (float)Window::height / (float)Window::width);
|
||||||
crosshair->draw(GL_LINES);
|
// crosshairShader->uniform1f("u_scale", 1.0f / ((float)Window::height / 1000.0f));
|
||||||
|
// glLineWidth(2.0f);
|
||||||
|
// crosshair->draw(GL_LINES);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,7 @@ class Mesh;
|
|||||||
class HudRenderer {
|
class HudRenderer {
|
||||||
Batch2D* batch;
|
Batch2D* batch;
|
||||||
Camera* uicamera;
|
Camera* uicamera;
|
||||||
Mesh* crosshair;
|
// Mesh* crosshair;
|
||||||
public:
|
public:
|
||||||
HudRenderer();
|
HudRenderer();
|
||||||
~HudRenderer();
|
~HudRenderer();
|
||||||
|
|||||||
@ -20,6 +20,7 @@ int _png_load(const char* file, int* width, int* height){
|
|||||||
png_bytepp row_pointers;
|
png_bytepp row_pointers;
|
||||||
png_structp png_ptr;
|
png_structp png_ptr;
|
||||||
GLuint texture;
|
GLuint texture;
|
||||||
|
GLuint texturems;
|
||||||
int alpha;
|
int alpha;
|
||||||
|
|
||||||
if ( !( f = fopen(file, "r" ) ) ) {
|
if ( !( f = fopen(file, "r" ) ) ) {
|
||||||
@ -95,18 +96,53 @@ int _png_load(const char* file, int* width, int* height){
|
|||||||
png_destroy_read_struct( &png_ptr, &info_ptr, &end_info );
|
png_destroy_read_struct( &png_ptr, &info_ptr, &end_info );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
// configure second post-processing framebuffer
|
||||||
|
unsigned int framebuffer;
|
||||||
|
glGenFramebuffers(1, &framebuffer);
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
|
||||||
|
|
||||||
glGenTextures(1, &texture);
|
glGenTextures(1, &texture);
|
||||||
glBindTexture(GL_TEXTURE_2D, texture);
|
glBindTexture(GL_TEXTURE_2D, texture);
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, t_width, t_height, 0,
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, t_width, t_height, 0,
|
||||||
alpha, GL_UNSIGNED_BYTE, (GLvoid *) image_data);
|
alpha, GL_UNSIGNED_BYTE, (GLvoid *) image_data);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 3);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 3);
|
||||||
glGenerateMipmap(GL_TEXTURE_2D);
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
|
// glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); // we only need a color buffer
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
|
|
||||||
|
unsigned int framebufferms;
|
||||||
|
glGenFramebuffers(1, &framebufferms);
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, framebufferms);
|
||||||
|
// create a multisampled color attachment texture
|
||||||
|
glGenTextures(1, &texturems);
|
||||||
|
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, texturems);
|
||||||
|
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 16, GL_RGBA, t_width, t_height, GL_TRUE);
|
||||||
|
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, texturems, 0);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_MAX_LEVEL, 3);
|
||||||
|
// glGenerateMipmap(GL_TEXTURE_2D_MULTISAMPLE);
|
||||||
|
|
||||||
|
|
||||||
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer);
|
||||||
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebufferms);
|
||||||
|
glBlitFramebuffer(0, 0, t_width, t_height, 0, 0, t_width, t_height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||||
|
|
||||||
|
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0);
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
png_destroy_read_struct( &png_ptr, &info_ptr, &end_info );
|
png_destroy_read_struct( &png_ptr, &info_ptr, &end_info );
|
||||||
free( image_data );
|
free( image_data );
|
||||||
|
|||||||
@ -11,7 +11,7 @@ Player::Player(glm::vec3 position, float speed, Camera* camera) :
|
|||||||
camera(camera),
|
camera(camera),
|
||||||
choosenBlock(1),
|
choosenBlock(1),
|
||||||
camX(0.0f), camY(0.0f){
|
camX(0.0f), camY(0.0f){
|
||||||
hitbox = new Hitbox(position, vec3(0.2f,0.9f,0.2f));
|
hitbox = new Hitbox(position, vec3(0.3f,0.9f,0.3f));
|
||||||
}
|
}
|
||||||
|
|
||||||
Player::~Player(){
|
Player::~Player(){
|
||||||
|
|||||||
@ -15,6 +15,7 @@ public:
|
|||||||
Hitbox* hitbox;
|
Hitbox* hitbox;
|
||||||
bool flight = false;
|
bool flight = false;
|
||||||
bool noclip = false;
|
bool noclip = false;
|
||||||
|
bool debug = false;
|
||||||
int choosenBlock;
|
int choosenBlock;
|
||||||
float camX, camY;
|
float camX, camY;
|
||||||
float cameraShaking = 0.0f;
|
float cameraShaking = 0.0f;
|
||||||
|
|||||||
@ -5,7 +5,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#define E 0.03
|
#define E 0.03
|
||||||
#define DEFAULT_FRICTION 10.0
|
|
||||||
|
|
||||||
PhysicsSolver::PhysicsSolver(vec3 gravity) : gravity(gravity) {
|
PhysicsSolver::PhysicsSolver(vec3 gravity) : gravity(gravity) {
|
||||||
}
|
}
|
||||||
@ -28,89 +27,7 @@ void PhysicsSolver::step(Chunks* chunks, Hitbox* hitbox, float delta, unsigned s
|
|||||||
float pz = pos.z;
|
float pz = pos.z;
|
||||||
|
|
||||||
if (collisions) {
|
if (collisions) {
|
||||||
if (vel.x < 0.0){
|
colisionCalc(chunks, hitbox, &vel, &pos, half);
|
||||||
for (int y = floor(pos.y-half.y+E); y <= floor(pos.y+half.y-E); y++){
|
|
||||||
for (int z = floor(pos.z-half.z+E); z <= floor(pos.z+half.z-E); z++){
|
|
||||||
int x = floor(pos.x-half.x-E);
|
|
||||||
if (chunks->isObstacle(x,y,z)){
|
|
||||||
vel.x *= 0.0;
|
|
||||||
pos.x = x + 1 + half.x + E;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (vel.x > 0.0){
|
|
||||||
for (int y = floor(pos.y-half.y+E); y <= floor(pos.y+half.y-E); y++){
|
|
||||||
for (int z = floor(pos.z-half.z+E); z <= floor(pos.z+half.z-E); z++){
|
|
||||||
int x = floor(pos.x+half.x+E);
|
|
||||||
if (chunks->isObstacle(x,y,z)){
|
|
||||||
vel.x *= 0.0;
|
|
||||||
pos.x = x - half.x - E;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vel.z < 0.0){
|
|
||||||
for (int y = floor(pos.y-half.y+E); y <= floor(pos.y+half.y-E); y++){
|
|
||||||
for (int x = floor(pos.x-half.x+E); x <= floor(pos.x+half.x-E); x++){
|
|
||||||
int z = floor(pos.z-half.z-E);
|
|
||||||
if (chunks->isObstacle(x,y,z)){
|
|
||||||
vel.z *= 0.0;
|
|
||||||
pos.z = z + 1 + half.z + E;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vel.z > 0.0){
|
|
||||||
for (int y = floor(pos.y-half.y+E); y <= floor(pos.y+half.y-E); y++){
|
|
||||||
for (int x = floor(pos.x-half.x+E); x <= floor(pos.x+half.x-E); x++){
|
|
||||||
int z = floor(pos.z+half.z+E);
|
|
||||||
if (chunks->isObstacle(x,y,z)){
|
|
||||||
vel.z *= 0.0;
|
|
||||||
pos.z = z - half.z - E;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vel.y < 0.0){
|
|
||||||
for (int x = floor(pos.x-half.x+E); x <= floor(pos.x+half.x-E); x++){
|
|
||||||
bool broken = false;
|
|
||||||
for (int z = floor(pos.z-half.z+E); z <= floor(pos.z+half.z-E); z++){
|
|
||||||
int y = floor(pos.y-half.y-E);
|
|
||||||
if (chunks->isObstacle(x,y,z)){
|
|
||||||
vel.y *= 0.0;
|
|
||||||
pos.y = y + 1 + half.y;
|
|
||||||
int f = DEFAULT_FRICTION;
|
|
||||||
vel.x *= max(0.0, 1.0 - dt * f);
|
|
||||||
vel.z *= max(0.0, 1.0 - dt * f);
|
|
||||||
hitbox->grounded = true;
|
|
||||||
broken = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (broken)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (vel.y > 0.0){
|
|
||||||
for (int x = floor(pos.x-half.x+E); x <= floor(pos.x+half.x-E); x++){
|
|
||||||
for (int z = floor(pos.z-half.z+E); z <= floor(pos.z+half.z-E); z++){
|
|
||||||
int y = floor(pos.y+half.y+E);
|
|
||||||
if (chunks->isObstacle(x,y,z)){
|
|
||||||
vel.y *= 0.0;
|
|
||||||
pos.y = y - half.y - E;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vel.x *= max(0.0, 1.0 - dt * linear_damping);
|
vel.x *= max(0.0, 1.0 - dt * linear_damping);
|
||||||
@ -152,6 +69,85 @@ void PhysicsSolver::step(Chunks* chunks, Hitbox* hitbox, float delta, unsigned s
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PhysicsSolver::colisionCalc(Chunks* chunks, Hitbox* hitbox, vec3* vel, vec3* pos, vec3 half){
|
||||||
|
if (vel->x < 0.0){
|
||||||
|
for (int y = floor(pos->y-half.y+E); y <= floor(pos->y+half.y-E); y++){
|
||||||
|
for (int z = floor(pos->z-half.z+E); z <= floor(pos->z+half.z-E); z++){
|
||||||
|
int x = floor(pos->x-half.x-E);
|
||||||
|
if (chunks->isObstacle(x,y,z)){
|
||||||
|
vel->x *= 0.0;
|
||||||
|
pos->x = x + 1 + half.x + E;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (vel->x > 0.0){
|
||||||
|
for (int y = floor(pos->y-half.y+E); y <= floor(pos->y+half.y-E); y++){
|
||||||
|
for (int z = floor(pos->z-half.z+E); z <= floor(pos->z+half.z-E); z++){
|
||||||
|
int x = floor(pos->x+half.x+E);
|
||||||
|
if (chunks->isObstacle(x,y,z)){
|
||||||
|
vel->x *= 0.0;
|
||||||
|
pos->x = x - half.x - E;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vel->z < 0.0){
|
||||||
|
for (int y = floor(pos->y-half.y+E); y <= floor(pos->y+half.y-E); y++){
|
||||||
|
for (int x = floor(pos->x-half.x+E); x <= floor(pos->x+half.x-E); x++){
|
||||||
|
int z = floor(pos->z-half.z-E);
|
||||||
|
if (chunks->isObstacle(x,y,z)){
|
||||||
|
vel->z *= 0.0;
|
||||||
|
pos->z = z + 1 + half.z + E;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vel->z > 0.0){
|
||||||
|
for (int y = floor(pos->y-half.y+E); y <= floor(pos->y+half.y-E); y++){
|
||||||
|
for (int x = floor(pos->x-half.x+E); x <= floor(pos->x+half.x-E); x++){
|
||||||
|
int z = floor(pos->z+half.z+E);
|
||||||
|
if (chunks->isObstacle(x,y,z)){
|
||||||
|
vel->z *= 0.0;
|
||||||
|
pos->z = z - half.z - E;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vel->y < 0.0){
|
||||||
|
for (int x = floor(pos->x-half.x+E); x <= floor(pos->x+half.x-E); x++){
|
||||||
|
for (int z = floor(pos->z-half.z+E); z <= floor(pos->z+half.z-E); z++){
|
||||||
|
int y = floor(pos->y-half.y-E);
|
||||||
|
if (chunks->isObstacle(x,y,z)){
|
||||||
|
vel->y *= 0.0;
|
||||||
|
pos->y = y + 1 + half.y;
|
||||||
|
hitbox->grounded = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (vel->y > 0.0){
|
||||||
|
for (int x = floor(pos->x-half.x+E); x <= floor(pos->x+half.x-E); x++){
|
||||||
|
for (int z = floor(pos->z-half.z+E); z <= floor(pos->z+half.z-E); z++){
|
||||||
|
int y = floor(pos->y+half.y+E);
|
||||||
|
if (chunks->isObstacle(x,y,z)){
|
||||||
|
vel->y *= 0.0;
|
||||||
|
pos->y = y - half.y - E;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool PhysicsSolver::isBlockInside(int x, int y, int z, Hitbox* hitbox) {
|
bool PhysicsSolver::isBlockInside(int x, int y, int z, Hitbox* hitbox) {
|
||||||
vec3& pos = hitbox->position;
|
vec3& pos = hitbox->position;
|
||||||
vec3& half = hitbox->halfsize;
|
vec3& half = hitbox->halfsize;
|
||||||
|
|||||||
@ -21,6 +21,7 @@ public:
|
|||||||
bool shifting,
|
bool shifting,
|
||||||
float gravityScale,
|
float gravityScale,
|
||||||
bool collisions);
|
bool collisions);
|
||||||
|
void colisionCalc(Chunks* chunks, Hitbox* hitbox, vec3* vel, vec3* pos, vec3 half);
|
||||||
bool isBlockInside(int x, int y, int z, Hitbox* hitbox);
|
bool isBlockInside(int x, int y, int z, Hitbox* hitbox);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -19,8 +19,8 @@
|
|||||||
#define RUN_ZOOM 1.1f
|
#define RUN_ZOOM 1.1f
|
||||||
#define C_ZOOM 0.1f
|
#define C_ZOOM 0.1f
|
||||||
#define ZOOM_SPEED 16.0f
|
#define ZOOM_SPEED 16.0f
|
||||||
#define DEFAULT_AIR_DAMPING 0.1f
|
#define PLAYER_GROUND_DAMPING 10.0f
|
||||||
#define PLAYER_NOT_ONGROUND_DAMPING 10.0f
|
#define PLAYER_AIR_DAMPING 7.0f
|
||||||
#define CAMERA_SHAKING_OFFSET 0.025f
|
#define CAMERA_SHAKING_OFFSET 0.025f
|
||||||
#define CAMERA_SHAKING_OFFSET_Y 0.031f
|
#define CAMERA_SHAKING_OFFSET_Y 0.031f
|
||||||
#define CAMERA_SHAKING_SPEED 1.6f
|
#define CAMERA_SHAKING_SPEED 1.6f
|
||||||
@ -35,13 +35,14 @@ PlayerController::PlayerController(Level* level) : level(level) {
|
|||||||
void PlayerController::update_controls(float delta){
|
void PlayerController::update_controls(float delta){
|
||||||
Player* player = level->player;
|
Player* player = level->player;
|
||||||
|
|
||||||
|
/*block choose*/{
|
||||||
for (int i = 1; i < 10; i++){
|
for (int i = 1; i < 10; i++){
|
||||||
if (Events::jpressed(GLFW_KEY_0+i)){
|
if (Events::jpressed(GLFW_KEY_0+i)){
|
||||||
player->choosenBlock = i;
|
player->choosenBlock = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}//end
|
||||||
|
|
||||||
// Controls
|
|
||||||
Camera* camera = player->camera;
|
Camera* camera = player->camera;
|
||||||
Hitbox* hitbox = player->hitbox;
|
Hitbox* hitbox = player->hitbox;
|
||||||
bool sprint = Events::pressed(GLFW_KEY_LEFT_CONTROL);
|
bool sprint = Events::pressed(GLFW_KEY_LEFT_CONTROL);
|
||||||
@ -65,7 +66,8 @@ void PlayerController::update_controls(float delta){
|
|||||||
|
|
||||||
if (player->flight && hitbox->grounded)
|
if (player->flight && hitbox->grounded)
|
||||||
player->flight = false;
|
player->flight = false;
|
||||||
// Camera shaking
|
|
||||||
|
/*camera shaking*/{
|
||||||
player->interpVel = player->interpVel * (1.0f - delta * 5) + hitbox->velocity * delta * 0.1f;
|
player->interpVel = player->interpVel * (1.0f - delta * 5) + hitbox->velocity * delta * 0.1f;
|
||||||
if (hitbox->grounded && player->interpVel.y < 0.0f){
|
if (hitbox->grounded && player->interpVel.y < 0.0f){
|
||||||
player->interpVel.y *= -30.0f;
|
player->interpVel.y *= -30.0f;
|
||||||
@ -77,12 +79,12 @@ void PlayerController::update_controls(float delta){
|
|||||||
camera->position += camera->right * sin(shakeTimer) * CAMERA_SHAKING_OFFSET * player->cameraShaking;
|
camera->position += camera->right * sin(shakeTimer) * CAMERA_SHAKING_OFFSET * player->cameraShaking;
|
||||||
camera->position += camera->up * abs(cos(shakeTimer)) * CAMERA_SHAKING_OFFSET_Y * player->cameraShaking;
|
camera->position += camera->up * abs(cos(shakeTimer)) * CAMERA_SHAKING_OFFSET_Y * player->cameraShaking;
|
||||||
camera->position -= min(player->interpVel * 0.05f, 1.0f);
|
camera->position -= min(player->interpVel * 0.05f, 1.0f);
|
||||||
|
}//end
|
||||||
|
|
||||||
if ((Events::jpressed(GLFW_KEY_F) && !player->noclip) ||
|
if ((Events::jpressed(GLFW_KEY_F) && !player->noclip) ||
|
||||||
(Events::jpressed(GLFW_KEY_N) && player->flight == player->noclip)){
|
(Events::jpressed(GLFW_KEY_N) && player->flight == player->noclip)){
|
||||||
player->flight = !player->flight;
|
player->flight = !player->flight;
|
||||||
if (player->flight){
|
if (player->flight){
|
||||||
hitbox->velocity.y += 1;
|
|
||||||
hitbox->grounded = false;
|
hitbox->grounded = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,7 +92,7 @@ void PlayerController::update_controls(float delta){
|
|||||||
player->noclip = !player->noclip;
|
player->noclip = !player->noclip;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Field of view manipulations
|
/*field of view manipulations*/{
|
||||||
float dt = min(1.0f, delta * ZOOM_SPEED);
|
float dt = min(1.0f, delta * ZOOM_SPEED);
|
||||||
float zoomValue = 1.0f;
|
float zoomValue = 1.0f;
|
||||||
if (shift){
|
if (shift){
|
||||||
@ -104,11 +106,11 @@ void PlayerController::update_controls(float delta){
|
|||||||
if (zoom)
|
if (zoom)
|
||||||
zoomValue *= C_ZOOM;
|
zoomValue *= C_ZOOM;
|
||||||
camera->zoom = zoomValue * dt + camera->zoom * (1.0f - dt);
|
camera->zoom = zoomValue * dt + camera->zoom * (1.0f - dt);
|
||||||
|
}//end
|
||||||
|
|
||||||
if (Events::pressed(GLFW_KEY_SPACE) && hitbox->grounded){
|
if (Events::pressed(GLFW_KEY_SPACE) && hitbox->grounded){
|
||||||
hitbox->velocity.y = JUMP_FORCE;
|
hitbox->velocity.y = JUMP_FORCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 dir(0,0,0);
|
vec3 dir(0,0,0);
|
||||||
if (Events::pressed(GLFW_KEY_W)){
|
if (Events::pressed(GLFW_KEY_W)){
|
||||||
dir.x += camera->dir.x;
|
dir.x += camera->dir.x;
|
||||||
@ -127,9 +129,9 @@ void PlayerController::update_controls(float delta){
|
|||||||
dir.z -= camera->right.z;
|
dir.z -= camera->right.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
hitbox->linear_damping = DEFAULT_AIR_DAMPING;
|
hitbox->linear_damping = PLAYER_GROUND_DAMPING;
|
||||||
if (player->flight){
|
if (player->flight){
|
||||||
hitbox->linear_damping = PLAYER_NOT_ONGROUND_DAMPING;
|
hitbox->linear_damping = PLAYER_AIR_DAMPING;
|
||||||
hitbox->velocity.y *= 1.0f - delta * 9;
|
hitbox->velocity.y *= 1.0f - delta * 9;
|
||||||
if (Events::pressed(GLFW_KEY_SPACE)){
|
if (Events::pressed(GLFW_KEY_SPACE)){
|
||||||
hitbox->velocity.y += speed * delta * 9;
|
hitbox->velocity.y += speed * delta * 9;
|
||||||
@ -138,30 +140,37 @@ void PlayerController::update_controls(float delta){
|
|||||||
hitbox->velocity.y -= speed * delta * 9;
|
hitbox->velocity.y -= speed * delta * 9;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!hitbox->grounded)
|
||||||
|
hitbox->linear_damping = PLAYER_AIR_DAMPING;
|
||||||
if (length(dir) > 0.0f){
|
if (length(dir) > 0.0f){
|
||||||
dir = normalize(dir);
|
dir = normalize(dir);
|
||||||
|
|
||||||
if (!hitbox->grounded)
|
|
||||||
hitbox->linear_damping = PLAYER_NOT_ONGROUND_DAMPING;
|
|
||||||
|
|
||||||
hitbox->velocity.x += dir.x * speed * delta * 9;
|
hitbox->velocity.x += dir.x * speed * delta * 9;
|
||||||
hitbox->velocity.z += dir.z * speed * delta * 9;
|
hitbox->velocity.z += dir.z * speed * delta * 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Events::_cursor_locked){
|
|
||||||
player->camY += -Events::deltaY / Window::height * 2;
|
|
||||||
player->camX += -Events::deltaX / Window::height * 2;
|
|
||||||
|
|
||||||
if (player->camY < -radians(89.0f)){
|
/*camera rotate*/{
|
||||||
player->camY = -radians(89.0f);
|
if (Events::_cursor_locked){
|
||||||
|
float rotX = -Events::deltaX / Window::height * 2;
|
||||||
|
float rotY = -Events::deltaY / Window::height * 2;
|
||||||
|
if (zoom){
|
||||||
|
rotX /= 4;
|
||||||
|
rotY /= 4;
|
||||||
}
|
}
|
||||||
if (player->camY > radians(89.0f)){
|
player->camX += rotX;
|
||||||
player->camY = radians(89.0f);
|
player->camY += rotY;
|
||||||
|
|
||||||
|
if (player->camY < -radians(89.9f)){
|
||||||
|
player->camY = -radians(89.9f);
|
||||||
|
}
|
||||||
|
if (player->camY > radians(89.9f)){
|
||||||
|
player->camY = radians(89.9f);
|
||||||
}
|
}
|
||||||
|
|
||||||
camera->rotation = mat4(1.0f);
|
camera->rotation = mat4(1.0f);
|
||||||
camera->rotate(player->camY, player->camX, 0);
|
camera->rotate(player->camY, player->camX, 0);
|
||||||
}
|
}
|
||||||
|
}//end
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerController::update_interaction(){
|
void PlayerController::update_interaction(){
|
||||||
@ -176,33 +185,48 @@ void PlayerController::update_interaction(){
|
|||||||
if (vox != nullptr){
|
if (vox != nullptr){
|
||||||
selectedBlockId = vox->id;
|
selectedBlockId = vox->id;
|
||||||
selectedBlockPosition = iend;
|
selectedBlockPosition = iend;
|
||||||
|
|
||||||
Block* block = Block::blocks[vox->id];
|
|
||||||
if (Events::jclicked(GLFW_MOUSE_BUTTON_1) && block->breakable){
|
|
||||||
int x = (int)iend.x;
|
int x = (int)iend.x;
|
||||||
int y = (int)iend.y;
|
int y = (int)iend.y;
|
||||||
int z = (int)iend.z;
|
int z = (int)iend.z;
|
||||||
chunks->set(x,y,z, 0);
|
uint8_t states = 0;
|
||||||
|
|
||||||
|
if (Block::blocks[player->choosenBlock]->rotatable){
|
||||||
|
// states = states & 0b11111100;
|
||||||
|
// if (abs(norm.x) > abs(norm.z)){
|
||||||
|
// if (abs(norm.x) > abs(norm.y)) states = states | 0b00000001;
|
||||||
|
// if (abs(norm.x) < abs(norm.y)) states = states | 0b00000010;
|
||||||
|
// }
|
||||||
|
// if (abs(norm.x) < abs(norm.z)){
|
||||||
|
// if (abs(norm.z) > abs(norm.y)) states = states | 0b00000011;
|
||||||
|
// if (abs(norm.z) < abs(norm.y)) states = states | 0b00000010;
|
||||||
|
// }
|
||||||
|
if (abs(norm.x) > abs(norm.z)){
|
||||||
|
if (abs(norm.x) > abs(norm.y)) states = 0x31;
|
||||||
|
if (abs(norm.x) < abs(norm.y)) states = 0x32;
|
||||||
|
}
|
||||||
|
if (abs(norm.x) < abs(norm.z)){
|
||||||
|
if (abs(norm.z) > abs(norm.y)) states = 0x33;
|
||||||
|
if (abs(norm.z) < abs(norm.y)) states = 0x32;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Block* block = Block::blocks[vox->id];
|
||||||
|
if (Events::jclicked(GLFW_MOUSE_BUTTON_1) && block->breakable){
|
||||||
|
chunks->set(x,y,z, 0, 0);
|
||||||
lighting->onBlockSet(x,y,z,0);
|
lighting->onBlockSet(x,y,z,0);
|
||||||
}
|
}
|
||||||
if (Events::jclicked(GLFW_MOUSE_BUTTON_2)){
|
if (Events::jclicked(GLFW_MOUSE_BUTTON_2)){
|
||||||
int x = (int)(iend.x)+(int)(norm.x);
|
if (block->model != BLOCK_MODEL_X_SPRITE){
|
||||||
int y = (int)(iend.y)+(int)(norm.y);
|
x = (int)(iend.x)+(int)(norm.x);
|
||||||
int z = (int)(iend.z)+(int)(norm.z);
|
y = (int)(iend.y)+(int)(norm.y);
|
||||||
if (block->model == BLOCK_MODEL_GRASS){
|
z = (int)(iend.z)+(int)(norm.z);
|
||||||
x = (int)iend.x;
|
|
||||||
y = (int)iend.y;
|
|
||||||
z = (int)iend.z;
|
|
||||||
}
|
}
|
||||||
if (!level->physics->isBlockInside(x,y,z, player->hitbox)){
|
if (!level->physics->isBlockInside(x,y,z, player->hitbox)){
|
||||||
chunks->set(x, y, z, player->choosenBlock);
|
chunks->set(x, y, z, player->choosenBlock, states);
|
||||||
lighting->onBlockSet(x,y,z, player->choosenBlock);
|
lighting->onBlockSet(x,y,z, player->choosenBlock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Events::jclicked(GLFW_MOUSE_BUTTON_3)){
|
if (Events::jclicked(GLFW_MOUSE_BUTTON_3)){
|
||||||
int x = (int)iend.x;
|
|
||||||
int y = (int)iend.y;
|
|
||||||
int z = (int)iend.z;
|
|
||||||
player->choosenBlock = chunks->get(x,y,z)->id;
|
player->choosenBlock = chunks->get(x,y,z)->id;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
4
src/typedefs.h
Normal file
4
src/typedefs.h
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
typedef unsigned int uint;
|
||||||
|
typedef unsigned char ubyte;
|
||||||
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
#include <exception>
|
||||||
|
|
||||||
// GLM
|
// GLM
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
@ -18,140 +19,127 @@
|
|||||||
|
|
||||||
using namespace glm;
|
using namespace glm;
|
||||||
|
|
||||||
#include "graphics/Shader.h"
|
|
||||||
#include "graphics/Texture.h"
|
|
||||||
#include "graphics/Mesh.h"
|
|
||||||
#include "graphics/VoxelRenderer.h"
|
|
||||||
#include "graphics/LineBatch.h"
|
|
||||||
#include "graphics/Batch2D.h"
|
|
||||||
#include "graphics/Framebuffer.h"
|
|
||||||
#include "window/Window.h"
|
#include "window/Window.h"
|
||||||
#include "window/Events.h"
|
#include "window/Events.h"
|
||||||
#include "window/Camera.h"
|
#include "window/Camera.h"
|
||||||
#include "loaders/png_loading.h"
|
#include "audio/Audio.h"
|
||||||
#include "voxels/voxel.h"
|
|
||||||
#include "voxels/Chunk.h"
|
#include "voxels/Chunk.h"
|
||||||
#include "voxels/Chunks.h"
|
#include "voxels/Chunks.h"
|
||||||
#include "voxels/Block.h"
|
|
||||||
#include "voxels/WorldGenerator.h"
|
|
||||||
#include "voxels/ChunksController.h"
|
#include "voxels/ChunksController.h"
|
||||||
#include "files/files.h"
|
#include "voxels/ChunksLoader.h"
|
||||||
#include "files/WorldFiles.h"
|
|
||||||
#include "lighting/LightSolver.h"
|
|
||||||
#include "lighting/Lightmap.h"
|
|
||||||
#include "lighting/Lighting.h"
|
|
||||||
#include "physics/Hitbox.h"
|
|
||||||
#include "physics/PhysicsSolver.h"
|
|
||||||
#include "world/World.h"
|
|
||||||
#include "world/Level.h"
|
|
||||||
|
|
||||||
#include "audio/Audio.h"
|
|
||||||
#include "audio/audioutil.h"
|
|
||||||
#include "Assets.h"
|
|
||||||
#include "objects/Player.h"
|
#include "objects/Player.h"
|
||||||
|
#include "world/Level.h"
|
||||||
|
#include "world/World.h"
|
||||||
#include "declarations.h"
|
#include "declarations.h"
|
||||||
|
#include "Assets.h"
|
||||||
|
#include "AssetsLoader.h"
|
||||||
#include "world_render.h"
|
#include "world_render.h"
|
||||||
#include "hud_render.h"
|
#include "hud_render.h"
|
||||||
#include "player_control.h"
|
|
||||||
|
|
||||||
int WIDTH = 1280;
|
|
||||||
int HEIGHT = 720;
|
|
||||||
|
|
||||||
// Save all world data to files
|
class initialize_error : public std::runtime_error {
|
||||||
void write_world(World* world, Level* level){
|
initialize_error(const std::string& message) : std::runtime_error(message) {}
|
||||||
WorldFiles* wfile = world->wfile;
|
};
|
||||||
Chunks* chunks = level->chunks;
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < chunks->volume; i++){
|
struct EngineSettings {
|
||||||
Chunk* chunk = chunks->chunks[i];
|
int displayWidth;
|
||||||
if (chunk == nullptr || !chunk->isUnsaved())
|
int displayHeight;
|
||||||
continue;
|
const char* title;
|
||||||
wfile->put((const char*)chunk->voxels, chunk->x, chunk->z);
|
};
|
||||||
}
|
|
||||||
|
|
||||||
wfile->write();
|
|
||||||
|
|
||||||
world->wfile->writePlayer(level->player);
|
class Engine {
|
||||||
}
|
Assets* assets;
|
||||||
|
Level* level;
|
||||||
|
|
||||||
void update_level(World* world, Level* level, float delta, long frame, VoxelRenderer* renderer) {
|
uint64_t frame = 0;
|
||||||
level->playerController->update_controls(delta);
|
float lastTime = 0.0f;
|
||||||
if (Events::_cursor_locked)
|
float delta = 0.0f;
|
||||||
level->playerController->update_interaction();
|
bool occlusion = true;
|
||||||
|
public:
|
||||||
|
Engine(const EngineSettings& settings);
|
||||||
|
~Engine();
|
||||||
|
|
||||||
vec3 position = level->player->hitbox->position;
|
void updateTimers();
|
||||||
level->chunks->setCenter(world->wfile, position.x, position.z);
|
void updateHotkeys();
|
||||||
}
|
void mainloop();
|
||||||
|
};
|
||||||
|
|
||||||
Level* load_level(World* world, Player* player) {
|
Engine::Engine(const EngineSettings& settings) {
|
||||||
Level* level = new Level(world, player, new Chunks(56, 56, 0, 0), new PhysicsSolver(vec3(0, -19.6f, 0)));
|
Window::initialize(settings.displayWidth, settings.displayHeight, settings.title);
|
||||||
world->wfile->readPlayer(player);
|
|
||||||
|
|
||||||
Camera* camera = player->camera;
|
|
||||||
camera->rotation = mat4(1.0f);
|
|
||||||
camera->rotate(player->camY, player->camX, 0);
|
|
||||||
return level;
|
|
||||||
}
|
|
||||||
|
|
||||||
int initialize(Assets*& assets) {
|
|
||||||
Window::initialize(WIDTH, HEIGHT, "VoxelEngine-Cpp v12");
|
|
||||||
Events::initialize();
|
Events::initialize();
|
||||||
|
|
||||||
assets = new Assets();
|
assets = new Assets();
|
||||||
std::cout << "-- loading assets" << std::endl;
|
std::cout << "-- loading assets" << std::endl;
|
||||||
int result = initialize_assets(assets);
|
AssetsLoader loader(assets);
|
||||||
if (result){
|
AssetsLoader::createDefaults(loader);
|
||||||
|
initialize_assets(&loader);
|
||||||
|
while (loader.hasNext()) {
|
||||||
|
if (!loader.loadNext()) {
|
||||||
delete assets;
|
delete assets;
|
||||||
Window::terminate();
|
Window::terminate();
|
||||||
return result;
|
throw std::runtime_error("could not to initialize assets");
|
||||||
}
|
}
|
||||||
return 0;
|
}
|
||||||
|
std::cout << "-- loading world" << std::endl;
|
||||||
|
vec3 playerPosition = vec3(0, 64, 0);
|
||||||
|
Camera* camera = new Camera(playerPosition, radians(90.0f));
|
||||||
|
World* world = new World("world-1", "world/", 42);
|
||||||
|
Player* player = new Player(playerPosition, 4.0f, camera);
|
||||||
|
level = world->loadLevel(player);
|
||||||
|
|
||||||
|
std::cout << "-- initializing finished" << std::endl;
|
||||||
|
|
||||||
|
Audio::initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void mainloop(Level* level, Assets* assets) {
|
void Engine::updateTimers() {
|
||||||
|
frame++;
|
||||||
|
float currentTime = glfwGetTime();
|
||||||
|
delta = currentTime - lastTime;
|
||||||
|
lastTime = currentTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Engine::updateHotkeys() {
|
||||||
|
if (Events::jpressed(GLFW_KEY_ESCAPE)) {
|
||||||
|
Window::setShouldClose(true);
|
||||||
|
}
|
||||||
|
if (Events::jpressed(GLFW_KEY_TAB) || Events::jpressed(GLFW_KEY_E)) {
|
||||||
|
Events::toggleCursor();
|
||||||
|
}
|
||||||
|
if (Events::jpressed(GLFW_KEY_O)) {
|
||||||
|
occlusion = !occlusion;
|
||||||
|
}
|
||||||
|
if (Events::jpressed(GLFW_KEY_F3)) {
|
||||||
|
level->player->debug = !level->player->debug;
|
||||||
|
}
|
||||||
|
if (Events::jpressed(GLFW_KEY_F5)) {
|
||||||
|
for (unsigned i = 0; i < level->chunks->volume; i++) {
|
||||||
|
Chunk* chunk = level->chunks->chunks[i];
|
||||||
|
if (chunk != nullptr && chunk->isReady()) {
|
||||||
|
chunk->setModified(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Engine::mainloop() {
|
||||||
Camera* camera = level->player->camera;
|
Camera* camera = level->player->camera;
|
||||||
std::cout << "-- preparing systems" << std::endl;
|
std::cout << "-- preparing systems" << std::endl;
|
||||||
World* world = level->world;
|
World* world = level->world;
|
||||||
WorldRenderer worldRenderer(level, assets);
|
WorldRenderer worldRenderer(level, assets);
|
||||||
HudRenderer hud;
|
HudRenderer hud;
|
||||||
long frame = 0;
|
lastTime = glfwGetTime();
|
||||||
float lastTime = glfwGetTime();
|
|
||||||
float delta = 0.0f;
|
|
||||||
bool occlusion = true;
|
|
||||||
bool devdata = false;
|
|
||||||
Window::swapInterval(0);
|
|
||||||
while (!Window::isShouldClose()){
|
|
||||||
frame++;
|
|
||||||
float currentTime = glfwGetTime();
|
|
||||||
delta = currentTime - lastTime;
|
|
||||||
lastTime = currentTime;
|
|
||||||
int fps = 1 / delta;
|
|
||||||
if (Events::jpressed(GLFW_KEY_ESCAPE)){
|
|
||||||
Window::setShouldClose(true);
|
|
||||||
}
|
|
||||||
if (Events::jpressed(GLFW_KEY_TAB)){
|
|
||||||
Events::toggleCursor();
|
|
||||||
}
|
|
||||||
if (Events::jpressed(GLFW_KEY_O)){
|
|
||||||
occlusion = !occlusion;
|
|
||||||
}
|
|
||||||
if (Events::jpressed(GLFW_KEY_F3)){
|
|
||||||
devdata = !devdata;
|
|
||||||
}
|
|
||||||
if (Events::jpressed(GLFW_KEY_F5)){
|
|
||||||
for (unsigned i = 0; i < level->chunks->volume; i++) {
|
|
||||||
Chunk* chunk = level->chunks->chunks[i];
|
|
||||||
if (chunk != nullptr && chunk->isReady()){
|
|
||||||
chunk->setModified(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
update_level(world, level, delta, frame, worldRenderer.renderer);
|
Window::swapInterval(1);
|
||||||
|
while (!Window::isShouldClose()){
|
||||||
|
updateTimers();
|
||||||
|
updateHotkeys();
|
||||||
|
|
||||||
|
level->update(delta, Events::_cursor_locked);
|
||||||
int freeLoaders = level->chunksController->countFreeLoaders();
|
int freeLoaders = level->chunksController->countFreeLoaders();
|
||||||
for (int i = 0; i < freeLoaders; i++)
|
for (int i = 0; i < freeLoaders; i++)
|
||||||
level->chunksController->_buildMeshes(worldRenderer.renderer, frame);
|
level->chunksController->_buildMeshes();
|
||||||
freeLoaders = level->chunksController->countFreeLoaders();
|
freeLoaders = level->chunksController->countFreeLoaders();
|
||||||
for (int i = 0; i < freeLoaders; i++)
|
for (int i = 0; i < freeLoaders; i++)
|
||||||
level->chunksController->calculateLights();
|
level->chunksController->calculateLights();
|
||||||
@ -159,10 +147,10 @@ void mainloop(Level* level, Assets* assets) {
|
|||||||
for (int i = 0; i < freeLoaders; i++)
|
for (int i = 0; i < freeLoaders; i++)
|
||||||
level->chunksController->loadVisible(world->wfile);
|
level->chunksController->loadVisible(world->wfile);
|
||||||
|
|
||||||
worldRenderer.draw(world, camera, occlusion);
|
worldRenderer.draw(camera, occlusion);
|
||||||
hud.draw(level, assets);
|
hud.draw(level, assets);
|
||||||
if (devdata) {
|
if (level->player->debug) {
|
||||||
hud.drawDebug(level, assets, fps, occlusion);
|
hud.drawDebug(level, assets, 1 / delta, occlusion);
|
||||||
}
|
}
|
||||||
|
|
||||||
Window::swapBuffers();
|
Window::swapBuffers();
|
||||||
@ -170,28 +158,12 @@ void mainloop(Level* level, Assets* assets) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
Engine::~Engine() {
|
||||||
setup_definitions();
|
|
||||||
|
|
||||||
Assets* assets;
|
|
||||||
int status = initialize(assets);
|
|
||||||
if (status) return status;
|
|
||||||
|
|
||||||
std::cout << "-- loading world" << std::endl;
|
|
||||||
vec3 playerPosition = vec3(0,150,-10);
|
|
||||||
Camera* camera = new Camera(playerPosition, radians(90.0f));
|
|
||||||
World* world = new World("world-1", "world/", 42);
|
|
||||||
Player* player = new Player(playerPosition, 4.0f, camera);
|
|
||||||
Level* level = load_level(world, player);
|
|
||||||
|
|
||||||
std::cout << "-- initializing finished" << std::endl;
|
|
||||||
|
|
||||||
Audio::initialize();
|
|
||||||
mainloop(level, assets);
|
|
||||||
Audio::finalize();
|
Audio::finalize();
|
||||||
|
|
||||||
|
World* world = level->world;
|
||||||
std::cout << "-- saving world" << std::endl;
|
std::cout << "-- saving world" << std::endl;
|
||||||
write_world(world, level);
|
world->write(level);
|
||||||
|
|
||||||
delete level;
|
delete level;
|
||||||
delete world;
|
delete world;
|
||||||
@ -200,5 +172,19 @@ int main() {
|
|||||||
delete assets;
|
delete assets;
|
||||||
Events::finalize();
|
Events::finalize();
|
||||||
Window::terminate();
|
Window::terminate();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
setup_definitions();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Engine engine(EngineSettings{ 1280, 720, "VoxelEngine-Cpp v13" });
|
||||||
|
engine.mainloop();
|
||||||
|
}
|
||||||
|
catch (const initialize_error& err) {
|
||||||
|
std::cerr << "could not to initialize engine" << std::endl;
|
||||||
|
std::cerr << err.what() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
#define VOXELS_BLOCK_H_
|
#define VOXELS_BLOCK_H_
|
||||||
|
|
||||||
#define BLOCK_MODEL_CUBE 1
|
#define BLOCK_MODEL_CUBE 1
|
||||||
#define BLOCK_MODEL_GRASS 2
|
#define BLOCK_MODEL_X_SPRITE 2
|
||||||
|
|
||||||
class Block {
|
class Block {
|
||||||
public:
|
public:
|
||||||
@ -13,12 +13,15 @@ public:
|
|||||||
int textureFaces[6]; // -x,x, -y,y, -z,z
|
int textureFaces[6]; // -x,x, -y,y, -z,z
|
||||||
unsigned char emission[3];
|
unsigned char emission[3];
|
||||||
unsigned char drawGroup = 0;
|
unsigned char drawGroup = 0;
|
||||||
|
unsigned char model = 1; // 0:None 1:Block 2:XSprite
|
||||||
bool lightPassing = false;
|
bool lightPassing = false;
|
||||||
bool skyLightPassing = false;
|
bool skyLightPassing = false;
|
||||||
bool obstacle = true;
|
bool obstacle = true;
|
||||||
bool selectable = true;
|
bool selectable = true;
|
||||||
bool breakable = true;
|
bool breakable = true;
|
||||||
unsigned char model = 1;
|
bool rotatable = false;
|
||||||
|
float hitboxScale = 1;
|
||||||
|
float hitboxY = 1;
|
||||||
|
|
||||||
Block(unsigned int id, int texture);
|
Block(unsigned int id, int texture);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
#define CHUNK_W 16
|
#define CHUNK_W 16
|
||||||
#define CHUNK_H 256
|
#define CHUNK_H 256
|
||||||
#define CHUNK_D 16
|
#define CHUNK_D 16
|
||||||
#define CHUNK_VOL (CHUNK_W * CHUNK_H * CHUNK_D)
|
#define CHUNK_VOL (CHUNK_W * CHUNK_H * CHUNK_D * 2)
|
||||||
|
|
||||||
#define CHUNK_MODIFIED 0x1
|
#define CHUNK_MODIFIED 0x1
|
||||||
#define CHUNK_READY 0x2
|
#define CHUNK_READY 0x2
|
||||||
|
|||||||
@ -123,7 +123,7 @@ Chunk* Chunks::getChunk(int x, int z){
|
|||||||
return chunks[z * w + x];
|
return chunks[z * w + x];
|
||||||
}
|
}
|
||||||
|
|
||||||
void Chunks::set(int x, int y, int z, int id){
|
void Chunks::set(int x, int y, int z, int id, uint8_t states){
|
||||||
x -= ox * CHUNK_W;
|
x -= ox * CHUNK_W;
|
||||||
z -= oz * CHUNK_D;
|
z -= oz * CHUNK_D;
|
||||||
int cx = x / CHUNK_W;
|
int cx = x / CHUNK_W;
|
||||||
@ -140,6 +140,7 @@ void Chunks::set(int x, int y, int z, int id){
|
|||||||
int lx = x - cx * CHUNK_W;
|
int lx = x - cx * CHUNK_W;
|
||||||
int lz = z - cz * CHUNK_D;
|
int lz = z - cz * CHUNK_D;
|
||||||
chunk->voxels[(y * CHUNK_D + lz) * CHUNK_W + lx].id = id;
|
chunk->voxels[(y * CHUNK_D + lz) * CHUNK_W + lx].id = id;
|
||||||
|
chunk->voxels[(y * CHUNK_D + lz) * CHUNK_W + lx].states = states;
|
||||||
chunk->setUnsaved(true);
|
chunk->setUnsaved(true);
|
||||||
chunk->setModified(true);
|
chunk->setModified(true);
|
||||||
|
|
||||||
|
|||||||
@ -34,7 +34,7 @@ public:
|
|||||||
voxel* get(int x, int y, int z);
|
voxel* get(int x, int y, int z);
|
||||||
unsigned short getLight(int x, int y, int z);
|
unsigned short getLight(int x, int y, int z);
|
||||||
unsigned char getLight(int x, int y, int z, int channel);
|
unsigned char getLight(int x, int y, int z, int channel);
|
||||||
void set(int x, int y, int z, int id);
|
void set(int x, int y, int z, int id, uint8_t states);
|
||||||
voxel* rayCast(vec3 start, vec3 dir, float maxLength, vec3& end, vec3& norm, vec3& iend);
|
voxel* rayCast(vec3 start, vec3 dir, float maxLength, vec3& end, vec3& norm, vec3& iend);
|
||||||
|
|
||||||
bool isObstacle(int x, int y, int z);
|
bool isObstacle(int x, int y, int z);
|
||||||
|
|||||||
@ -10,7 +10,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#if defined(_WIN32) && defined(__MINGW32__)
|
||||||
#define _WIN32_WINNT 0x0501
|
#define _WIN32_WINNT 0x0501
|
||||||
#include <mingw.thread.h>
|
#include <mingw.thread.h>
|
||||||
#else
|
#else
|
||||||
@ -185,7 +185,7 @@ void ChunksController::calculateLights() {
|
|||||||
freeLoader->lights(chunk, (Chunk**)closes);
|
freeLoader->lights(chunk, (Chunk**)closes);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ChunksController::_buildMeshes(VoxelRenderer* renderer, int tick) {
|
bool ChunksController::_buildMeshes() {
|
||||||
const int w = chunks->w;
|
const int w = chunks->w;
|
||||||
const int d = chunks->d;
|
const int d = chunks->d;
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@ public:
|
|||||||
int countFreeLoaders();
|
int countFreeLoaders();
|
||||||
bool loadVisible(WorldFiles* worldFiles);
|
bool loadVisible(WorldFiles* worldFiles);
|
||||||
void calculateLights();
|
void calculateLights();
|
||||||
bool _buildMeshes(VoxelRenderer* renderer, int tick);
|
bool _buildMeshes();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* VOXELS_CHUNKSCONTROLLER_H_ */
|
#endif /* VOXELS_CHUNKSCONTROLLER_H_ */
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
#ifndef VOXELS_CHUNKSLOADER_H_
|
#ifndef VOXELS_CHUNKSLOADER_H_
|
||||||
#define VOXELS_CHUNKSLOADER_H_
|
#define VOXELS_CHUNKSLOADER_H_
|
||||||
|
|
||||||
#ifdef _WIN32
|
#if defined(_WIN32) && defined(__MINGW32__)
|
||||||
#define _WIN32_WINNT 0x0501
|
#define _WIN32_WINNT 0x0501
|
||||||
#include <mingw.thread.h>
|
#include <mingw.thread.h>
|
||||||
#else
|
#else
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#endif
|
#endif // _WIN32 && __MINGW32__
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
|
||||||
|
|||||||
@ -31,22 +31,27 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setSeed(int number){
|
void setSeed(int number){
|
||||||
seed = ((unsigned short)number+23729 xor (unsigned short)number+16786);
|
seed = ((unsigned short)(number*23729) ^ (unsigned short)(number+16786));
|
||||||
|
rand();
|
||||||
|
}
|
||||||
|
void setSeed(int number1,int number2){
|
||||||
|
seed = (((unsigned short)(number1*23729) | (unsigned short)(number2%16786)) ^ (unsigned short)(number2*number1));
|
||||||
rand();
|
rand();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
float calc_height(fnl_state *noise, int real_x, int real_z){
|
float calc_height(fnl_state *noise, int real_x, int real_z){
|
||||||
float height = fnlGetNoise3D(noise, real_x*0.0125f*8,real_z*0.0125f*8, 0.0f);
|
float height = 0;
|
||||||
height += fnlGetNoise3D(noise, real_x*0.025f*8,real_z*0.025f*8, 0.0f)*0.5f;
|
height += fnlGetNoise3D(noise, real_x*0.0125f*8-125567,real_z*0.0125f*8+3546, 0.0f);
|
||||||
height += fnlGetNoise3D(noise, real_x*0.05f*8,real_z*0.05f*8, 0.0f)*0.25f;
|
height += fnlGetNoise3D(noise, real_x*0.025f*8+4647,real_z*0.025f*8-3436, 0.0f)*0.5f;
|
||||||
|
height += fnlGetNoise3D(noise, real_x*0.05f*8-834176,real_z*0.05f*8+23678, 0.0f)*0.25f;
|
||||||
height += fnlGetNoise3D(noise,
|
height += fnlGetNoise3D(noise,
|
||||||
real_x*0.2f*8 + fnlGetNoise3D(noise, real_x*0.1f*8,real_z*0.1f*8, 0.0f)*50,
|
real_x*0.2f*8 + fnlGetNoise3D(noise, real_x*0.1f*8-23557,real_z*0.1f*8-6568, 0.0f)*50,
|
||||||
real_z*0.2f*8 + fnlGetNoise3D(noise, real_x*0.1f*8+4363,real_z*0.1f*8, 0.0f)*50,
|
real_z*0.2f*8 + fnlGetNoise3D(noise, real_x*0.1f*8+4363,real_z*0.1f*8+4456, 0.0f)*50,
|
||||||
0.0f)*0.1f;
|
0.0f)*0.1f;
|
||||||
height += fnlGetNoise3D(noise, real_x*0.1f*8,real_z*0.1f*8, 0.0f)*0.125f;
|
height += fnlGetNoise3D(noise, real_x*0.1f*8-3465,real_z*0.1f*8+4534, 0.0f)*0.125f;
|
||||||
height += fnlGetNoise3D(noise, real_x*0.4f*8,real_z*0.4f*8, 0.0f)*0.0625f;
|
height += fnlGetNoise3D(noise, real_x*0.4f*8+4565,real_z*0.4f*8+46456, 0.0f)*0.0625f;
|
||||||
height += fnlGetNoise3D(noise, real_x*8,real_z*8, 0.0f)*0.03f*(fnlGetNoise3D(noise, -real_x*0.0125f*8-1000,real_z*0.0125f*8+2000, 0.0f)/2+0.5f);
|
// height += fnlGetNoise3D(noise, real_x*8,real_z*8, 0.0f)*0.03f*(fnlGetNoise3D(noise, -real_x*0.0125f*8-1000,real_z*0.0125f*8+2000, 0.0f)/2+0.5f);
|
||||||
height *= fnlGetNoise3D(noise, real_x*0.0125f*8+1000,real_z*0.0125f*8+1000, 0.0f)/2+0.5f;
|
height *= fnlGetNoise3D(noise, real_x*0.0125f*8+1000,real_z*0.0125f*8+1000, 0.0f)/2+0.5f;
|
||||||
height += 1.0f;
|
height += 1.0f;
|
||||||
height *= 64.0f;
|
height *= 64.0f;
|
||||||
@ -54,41 +59,43 @@ float calc_height(fnl_state *noise, int real_x, int real_z){
|
|||||||
}
|
}
|
||||||
|
|
||||||
float calc_height_faster(fnl_state *noise, int real_x, int real_z){
|
float calc_height_faster(fnl_state *noise, int real_x, int real_z){
|
||||||
float height = fnlGetNoise3D(noise, real_x*0.0125f*8,real_z*0.0125f*8, 0.0f);
|
float height = 0;
|
||||||
height += fnlGetNoise3D(noise, real_x*0.025f*8,real_z*0.025f*8, 0.0f)*0.5f;
|
height += fnlGetNoise3D(noise, real_x*0.0125f*8-125567,real_z*0.0125f*8+3546, 0.0f);
|
||||||
height += fnlGetNoise3D(noise, real_x*0.05f*8,real_z*0.05f*8, 0.0f)*0.25f;
|
height += fnlGetNoise3D(noise, real_x*0.025f*8+4647,real_z*0.025f*8-3436, 0.0f)*0.5f;
|
||||||
|
height += fnlGetNoise3D(noise, real_x*0.05f*8-834176,real_z*0.05f*8+23678, 0.0f)*0.25f;
|
||||||
height += fnlGetNoise3D(noise,
|
height += fnlGetNoise3D(noise,
|
||||||
real_x*0.2f*8 + fnlGetNoise3D(noise, real_x*0.1f*8,real_z*0.1f*8, 0.0f)*50,
|
real_x*0.2f*8 + fnlGetNoise3D(noise, real_x*0.1f*8-23557,real_z*0.1f*8-6568, 0.0f)*50,
|
||||||
real_z*0.2f*8 + fnlGetNoise3D(noise, real_x*0.1f*8+4363,real_z*0.1f*8, 0.0f)*50,
|
real_z*0.2f*8 + fnlGetNoise3D(noise, real_x*0.1f*8+4363,real_z*0.1f*8+4456, 0.0f)*50,
|
||||||
0.0f)*0.1f;
|
0.0f)*0.1f;
|
||||||
height += fnlGetNoise3D(noise, real_x*0.1f*8,real_z*0.1f*8, 0.0f)*0.125f;
|
height += fnlGetNoise3D(noise, real_x*0.1f*8-3465,real_z*0.1f*8+4534, 0.0f)*0.125f;
|
||||||
height *= fnlGetNoise3D(noise, real_x*0.0125f*8+1000,real_z*0.0125f*8+1000, 0.0f)/2+0.5f;
|
height *= fnlGetNoise3D(noise, real_x*0.0125f*8+1000,real_z*0.0125f*8+1000, 0.0f)/2+0.5f;
|
||||||
height += 1.0f;
|
height += 1.0f;
|
||||||
height *= 64.0f;
|
height *= 64.0f;
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
|
|
||||||
int generate_tree(fnl_state *noise, PseudoRandom* random, const float* heights, int real_x, int real_y, int real_z, int tileSize){
|
int generate_tree(fnl_state *noise, PseudoRandom* random, float* heights, int real_x, int real_y, int real_z, int tileSize){
|
||||||
const int tileX = floor((double)real_x/(double)tileSize);
|
const int tileX = floor((double)real_x/(double)tileSize);
|
||||||
const int tileY = floor((double)real_z/(double)tileSize);
|
const int tileZ = floor((double)real_z/(double)tileSize);
|
||||||
random->setSeed(tileX*4325261+tileY*12160951+tileSize*9431111);
|
random->setSeed(tileX*4325261+tileZ*12160951+tileSize*9431111);
|
||||||
|
|
||||||
bool gentree = fnlGetNoise3D(noise, tileX*3.0f+633, 0.0, tileY*3.0f) > -0.1f && (random->rand() % 10) < 7;
|
bool gentree = fnlGetNoise3D(noise, tileX*3.0f+633, 0.0, tileZ*3.0f) > -0.1f && (random->rand() % 10) < 7;
|
||||||
if (!gentree)
|
if (!gentree)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
const int randomX = (random->rand() % (tileSize/2)) - tileSize/4;
|
const int randomX = (random->rand() % (tileSize/2)) - tileSize/4;
|
||||||
const int randomZ = (random->rand() % (tileSize/2)) - tileSize/4;
|
const int randomZ = (random->rand() % (tileSize/2)) - tileSize/4;
|
||||||
int centerX = tileX * tileSize + tileSize/2 + randomX;
|
int centerX = tileX * tileSize + tileSize/2 + randomX;
|
||||||
int centerY = tileY * tileSize + tileSize/2 + randomZ;
|
int centerZ = tileZ * tileSize + tileSize/2 + randomZ;
|
||||||
int height = (int)calc_height_faster(noise, centerX, centerY);
|
// int height = (int)(heights[centerX*CHUNK_W+centerZ]);
|
||||||
if ((height < 57) || (fnlGetNoise3D(noise, real_x*0.025f,real_z*0.025f, 0.0f)*0.5f > 0.5))
|
int height = (int)calc_height_faster(noise, centerX, centerZ);
|
||||||
|
if ((height < 57)/* || (fnlGetNoise3D(noise, real_x*0.025f,real_z*0.025f, 0.0f)*0.5f > 0.5)*/)
|
||||||
return 0;
|
return 0;
|
||||||
int lx = real_x - centerX;
|
int lx = real_x - centerX;
|
||||||
int radius = random->rand() % 4 + 3;
|
int radius = random->rand() % 4 + 2;
|
||||||
int ly = real_y - height - 3 * radius;
|
int ly = real_y - height - 3 * radius;
|
||||||
int lz = real_z - centerY;
|
int lz = real_z - centerZ;
|
||||||
if (lx == 0 && lz == 0 && real_y - height < 4*radius)
|
if (lx == 0 && lz == 0 && real_y - height < (3*radius + radius/2))
|
||||||
return 6;
|
return 6;
|
||||||
if (lx*lx+ly*ly/2+lz*lz < radius*radius)
|
if (lx*lx+ly*ly/2+lz*lz < radius*radius)
|
||||||
return 7;
|
return 7;
|
||||||
@ -100,6 +107,7 @@ void WorldGenerator::generate(voxel* voxels, int cx, int cz, int seed){
|
|||||||
noise.noise_type = FNL_NOISE_OPENSIMPLEX2;
|
noise.noise_type = FNL_NOISE_OPENSIMPLEX2;
|
||||||
noise.seed = seed * 60617077 % 25896307;
|
noise.seed = seed * 60617077 % 25896307;
|
||||||
PseudoRandom randomtree;
|
PseudoRandom randomtree;
|
||||||
|
PseudoRandom randomgrass;
|
||||||
|
|
||||||
float heights[CHUNK_VOL];
|
float heights[CHUNK_VOL];
|
||||||
|
|
||||||
@ -121,6 +129,7 @@ void WorldGenerator::generate(voxel* voxels, int cx, int cz, int seed){
|
|||||||
for (int y = 0; y < CHUNK_H; y++){
|
for (int y = 0; y < CHUNK_H; y++){
|
||||||
int real_y = y;
|
int real_y = y;
|
||||||
int id = real_y < 55 ? BLOCK_WATER : BLOCK_AIR;
|
int id = real_y < 55 ? BLOCK_WATER : BLOCK_AIR;
|
||||||
|
int states = 0;
|
||||||
if ((real_y == (int)height) && (54 < real_y)) {
|
if ((real_y == (int)height) && (54 < real_y)) {
|
||||||
id = BLOCK_GRASS_BLOCK;
|
id = BLOCK_GRASS_BLOCK;
|
||||||
} else if (real_y < (height - 6)){
|
} else if (real_y < (height - 6)){
|
||||||
@ -128,13 +137,14 @@ void WorldGenerator::generate(voxel* voxels, int cx, int cz, int seed){
|
|||||||
} else if (real_y < height){
|
} else if (real_y < height){
|
||||||
id = BLOCK_DIRT;
|
id = BLOCK_DIRT;
|
||||||
} else {
|
} else {
|
||||||
int tree = generate_tree(&noise, &randomtree, heights, real_x, real_y, real_z, 16);
|
int tree = generate_tree(&noise, &randomtree, heights, real_x, real_y, real_z, 23);
|
||||||
if (tree) {
|
if (tree) {
|
||||||
id = tree;
|
id = tree;
|
||||||
} else if ((tree = generate_tree(&noise, &randomtree, heights, real_x, real_y, real_z, 19))){
|
states = 0x32;
|
||||||
id = tree;
|
// } else if ((tree = generate_tree(&noise, &randomtree, heights, real_x, real_y, real_z, 19))){
|
||||||
} else if ((tree = generate_tree(&noise, &randomtree, heights, real_x, real_y, real_z, 23))){
|
// id = tree;
|
||||||
id = tree;
|
// } else if ((tree = generate_tree(&noise, &randomtree, heights, real_x, real_y, real_z, 23))){
|
||||||
|
// id = tree;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( ((height - (1.5 - 0.2 * pow(height - 54, 4))) < real_y) && (real_y < height)){
|
if ( ((height - (1.5 - 0.2 * pow(height - 54, 4))) < real_y) && (real_y < height)){
|
||||||
@ -142,13 +152,20 @@ void WorldGenerator::generate(voxel* voxels, int cx, int cz, int seed){
|
|||||||
}
|
}
|
||||||
if (real_y <= 2)
|
if (real_y <= 2)
|
||||||
id = BLOCK_BEDROCK;
|
id = BLOCK_BEDROCK;
|
||||||
if ((id == 0) && (real_y > 55) && ((int)height + 1 == real_y) && ((unsigned short)random() > 56000)){
|
|
||||||
|
randomgrass.setSeed(real_x,real_z);
|
||||||
|
if ((id == 0) && (height > 55.5) && ((int)(height + 1) == real_y) && ((unsigned short)randomgrass.rand() > 56000)){
|
||||||
id = BLOCK_GRASS;
|
id = BLOCK_GRASS;
|
||||||
}
|
}
|
||||||
if ((id == 0) && (real_y > 55) && ((int)height + 1 == real_y) && ((unsigned short)random() > 64000)){
|
if ((id == 0) && (height > 55.5) && ((int)(height + 1) == real_y) && ((unsigned short)randomgrass.rand() > 65000)){
|
||||||
id = BLOCK_FLOWER;
|
id = BLOCK_FLOWER;
|
||||||
}
|
}
|
||||||
|
if ((height > 56) && ((int)(height + 1) == real_y) && ((unsigned short)randomgrass.rand() > 65533)){
|
||||||
|
id = BLOCK_WOOD;
|
||||||
|
states = 0x32;
|
||||||
|
}
|
||||||
voxels[(y * CHUNK_D + z) * CHUNK_W + x].id = id;
|
voxels[(y * CHUNK_D + z) * CHUNK_W + x].id = id;
|
||||||
|
voxels[(y * CHUNK_D + z) * CHUNK_W + x].states = states;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
struct voxel {
|
struct voxel {
|
||||||
uint8_t id;
|
uint8_t id;
|
||||||
|
uint8_t states;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* VOXELS_VOXEL_H_ */
|
#endif /* VOXELS_VOXEL_H_ */
|
||||||
|
|||||||
@ -15,7 +15,7 @@ bool Events::_cursor_started = false;
|
|||||||
|
|
||||||
#define _MOUSE_BUTTONS 1024
|
#define _MOUSE_BUTTONS 1024
|
||||||
|
|
||||||
void cursor_position_callback(GLFWwindow* window, double xpos, double ypos){
|
void cursor_position_callback(GLFWwindow*, double xpos, double ypos){
|
||||||
if (Events::_cursor_started){
|
if (Events::_cursor_started){
|
||||||
Events::deltaX += xpos-Events::x;
|
Events::deltaX += xpos-Events::x;
|
||||||
Events::deltaY += ypos-Events::y;
|
Events::deltaY += ypos-Events::y;
|
||||||
@ -27,7 +27,7 @@ void cursor_position_callback(GLFWwindow* window, double xpos, double ypos){
|
|||||||
Events::y = ypos;
|
Events::y = ypos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mouse_button_callback(GLFWwindow* window, int button, int action, int mode){
|
void mouse_button_callback(GLFWwindow*, int button, int action, int){
|
||||||
if (action == GLFW_PRESS){
|
if (action == GLFW_PRESS){
|
||||||
Events::_keys[_MOUSE_BUTTONS+button] = true;
|
Events::_keys[_MOUSE_BUTTONS+button] = true;
|
||||||
Events::_frames[_MOUSE_BUTTONS+button] = Events::_current;
|
Events::_frames[_MOUSE_BUTTONS+button] = Events::_current;
|
||||||
@ -38,7 +38,7 @@ void mouse_button_callback(GLFWwindow* window, int button, int action, int mode)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode) {
|
void key_callback(GLFWwindow*, int key, int /*scancode*/, int action, int /*mode*/) {
|
||||||
if (action == GLFW_PRESS){
|
if (action == GLFW_PRESS){
|
||||||
Events::_keys[key] = true;
|
Events::_keys[key] = true;
|
||||||
Events::_frames[key] = Events::_current;
|
Events::_frames[key] = Events::_current;
|
||||||
@ -49,7 +49,7 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void window_size_callback(GLFWwindow* window, int width, int height){
|
void window_size_callback(GLFWwindow*, int width, int height){
|
||||||
glViewport(0,0, width, height);
|
glViewport(0,0, width, height);
|
||||||
Window::width = width;
|
Window::width = width;
|
||||||
Window::height = height;
|
Window::height = height;
|
||||||
|
|||||||
@ -1,19 +1,19 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include "Window.h"
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include "Window.h"
|
|
||||||
|
|
||||||
GLFWwindow* Window::window;
|
GLFWwindow* Window::window = nullptr;
|
||||||
int Window::width = 0;
|
uint Window::width = 0;
|
||||||
int Window::height = 0;
|
uint Window::height = 0;
|
||||||
|
|
||||||
int Window::initialize(int width, int height, const char* title){
|
int Window::initialize(uint width, uint height, const char* title){
|
||||||
glfwInit();
|
glfwInit();
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||||
glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
|
glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
|
||||||
//glfwWindowHint(GLFW_SAMPLES, 2);
|
glfwWindowHint(GLFW_SAMPLES, 16);
|
||||||
|
|
||||||
window = glfwCreateWindow(width, height, title, nullptr, nullptr);
|
window = glfwCreateWindow(width, height, title, nullptr, nullptr);
|
||||||
if (window == nullptr){
|
if (window == nullptr){
|
||||||
@ -34,6 +34,8 @@ int Window::initialize(int width, int height, const char* title){
|
|||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
|
glEnable(GL_MULTISAMPLE);
|
||||||
|
// glDisable(GL_MULTISAMPLE);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
Window::width = width;
|
Window::width = width;
|
||||||
|
|||||||
@ -1,14 +1,16 @@
|
|||||||
#ifndef WINDOW_WINDOW_H_
|
#ifndef WINDOW_WINDOW_H_
|
||||||
#define WINDOW_WINDOW_H_
|
#define WINDOW_WINDOW_H_
|
||||||
|
|
||||||
|
#include "../typedefs.h"
|
||||||
|
|
||||||
class GLFWwindow;
|
class GLFWwindow;
|
||||||
|
|
||||||
class Window {
|
class Window {
|
||||||
public:
|
public:
|
||||||
static int width;
|
static uint width;
|
||||||
static int height;
|
static uint height;
|
||||||
static GLFWwindow* window; // не лучшее решение делать window публичным
|
static GLFWwindow* window; // не лучшее решение делать window публичным
|
||||||
static int initialize(int width, int height, const char* title);
|
static int initialize(uint width, uint height, const char* title);
|
||||||
static void terminate();
|
static void terminate();
|
||||||
|
|
||||||
static void viewport(int x, int y, int width, int height);
|
static void viewport(int x, int y, int width, int height);
|
||||||
|
|||||||
@ -1,7 +1,12 @@
|
|||||||
#include "Level.h"
|
#include "Level.h"
|
||||||
|
#include "World.h"
|
||||||
#include "../lighting/Lighting.h"
|
#include "../lighting/Lighting.h"
|
||||||
|
#include "../voxels/Chunks.h"
|
||||||
#include "../voxels/ChunksController.h"
|
#include "../voxels/ChunksController.h"
|
||||||
#include "../player_control.h"
|
#include "../player_control.h"
|
||||||
|
#include "../physics/Hitbox.h"
|
||||||
|
#include "../physics/PhysicsSolver.h"
|
||||||
|
#include "../objects/Player.h"
|
||||||
|
|
||||||
Level::Level(World* world, Player* player, Chunks* chunks, PhysicsSolver* physics) :
|
Level::Level(World* world, Player* player, Chunks* chunks, PhysicsSolver* physics) :
|
||||||
world(world),
|
world(world),
|
||||||
@ -21,3 +26,16 @@ Level::~Level(){
|
|||||||
delete chunksController;
|
delete chunksController;
|
||||||
delete playerController;
|
delete playerController;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Level::update(float delta, bool interactions) {
|
||||||
|
playerController->update_controls(delta);
|
||||||
|
if (interactions) {
|
||||||
|
playerController->update_interaction();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
playerController->selectedBlockId = -1;
|
||||||
|
}
|
||||||
|
vec3 position = player->hitbox->position;
|
||||||
|
chunks->setCenter(world->wfile, position.x, position.z);
|
||||||
|
}
|
||||||
|
|||||||
@ -20,6 +20,9 @@ public:
|
|||||||
PlayerController* playerController;
|
PlayerController* playerController;
|
||||||
Level(World* world, Player* player, Chunks* chunks, PhysicsSolver* physics);
|
Level(World* world, Player* player, Chunks* chunks, PhysicsSolver* physics);
|
||||||
~Level();
|
~Level();
|
||||||
|
|
||||||
|
void update(float delta, bool interactions);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* WORLD_LEVEL_H_ */
|
#endif /* WORLD_LEVEL_H_ */
|
||||||
|
|||||||
@ -3,6 +3,10 @@
|
|||||||
#include "../files/WorldFiles.h"
|
#include "../files/WorldFiles.h"
|
||||||
#include "../voxels/Chunk.h"
|
#include "../voxels/Chunk.h"
|
||||||
#include "../voxels/Chunks.h"
|
#include "../voxels/Chunks.h"
|
||||||
|
#include "Level.h"
|
||||||
|
#include "../objects/Player.h"
|
||||||
|
#include "../physics/PhysicsSolver.h"
|
||||||
|
#include "../window/Camera.h"
|
||||||
|
|
||||||
World::World(std::string name, std::string directory, int seed) : name(name), seed(seed) {
|
World::World(std::string name, std::string directory, int seed) : name(name), seed(seed) {
|
||||||
wfile = new WorldFiles(directory, REGION_VOL * (CHUNK_VOL * 2 + 8));
|
wfile = new WorldFiles(directory, REGION_VOL * (CHUNK_VOL * 2 + 8));
|
||||||
@ -11,3 +15,27 @@ World::World(std::string name, std::string directory, int seed) : name(name), se
|
|||||||
World::~World(){
|
World::~World(){
|
||||||
delete wfile;
|
delete wfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void World::write(Level* level) {
|
||||||
|
Chunks* chunks = level->chunks;
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < chunks->volume; i++) {
|
||||||
|
Chunk* chunk = chunks->chunks[i];
|
||||||
|
if (chunk == nullptr || !chunk->isUnsaved())
|
||||||
|
continue;
|
||||||
|
wfile->put((const char*)chunk->voxels, chunk->x, chunk->z);
|
||||||
|
}
|
||||||
|
|
||||||
|
wfile->write();
|
||||||
|
wfile->writePlayer(level->player);
|
||||||
|
}
|
||||||
|
|
||||||
|
Level* World::loadLevel(Player* player) {
|
||||||
|
Level* level = new Level(this, player, new Chunks(56, 56, 0, 0), new PhysicsSolver(vec3(0, -19.6f, 0)));
|
||||||
|
wfile->readPlayer(player);
|
||||||
|
|
||||||
|
Camera* camera = player->camera;
|
||||||
|
camera->rotation = mat4(1.0f);
|
||||||
|
camera->rotate(player->camY, player->camX, 0);
|
||||||
|
return level;
|
||||||
|
}
|
||||||
@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
class WorldFiles;
|
class WorldFiles;
|
||||||
class Chunks;
|
class Chunks;
|
||||||
|
class Level;
|
||||||
|
class Player;
|
||||||
|
|
||||||
class World {
|
class World {
|
||||||
public:
|
public:
|
||||||
@ -14,6 +16,9 @@ public:
|
|||||||
|
|
||||||
World(std::string name, std::string directory, int seed);
|
World(std::string name, std::string directory, int seed);
|
||||||
~World();
|
~World();
|
||||||
|
|
||||||
|
void write(Level* level);
|
||||||
|
Level* loadLevel(Player* player);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* WORLD_WORLD_H_ */
|
#endif /* WORLD_WORLD_H_ */
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "graphics/VoxelRenderer.h"
|
#include "graphics/VoxelRenderer.h"
|
||||||
|
#include <GL/glew.h>
|
||||||
|
|
||||||
#include "window/Window.h"
|
#include "window/Window.h"
|
||||||
#include "window/Camera.h"
|
#include "window/Camera.h"
|
||||||
@ -63,15 +64,16 @@ bool WorldRenderer::drawChunk(size_t index, Camera* camera, Shader* shader, bool
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mat4 model = glm::translate(mat4(1.0f), vec3(chunk->x*CHUNK_W+0.5f, 0.5f, chunk->z*CHUNK_D+0.5f));
|
mat4 model = glm::translate(mat4(1.0f), vec3(chunk->x*CHUNK_W+0.5f, 0.5f, chunk->z*CHUNK_D+0.5f));
|
||||||
shader->uniformMatrix("u_model", model);
|
shader->uniformMatrix("u_model", model);
|
||||||
|
glDisable(GL_MULTISAMPLE);
|
||||||
mesh->draw(GL_TRIANGLES);
|
mesh->draw(GL_TRIANGLES);
|
||||||
|
glEnable(GL_MULTISAMPLE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void WorldRenderer::draw(World* world, Camera* camera, bool occlusion){
|
void WorldRenderer::draw(Camera* camera, bool occlusion){
|
||||||
Chunks* chunks = level->chunks;
|
Chunks* chunks = level->chunks;
|
||||||
|
|
||||||
vec4 skyColor(0.7f, 0.81f, 1.0f, 1.0f);
|
vec4 skyColor(0.7f, 0.81f, 1.0f, 1.0f);
|
||||||
@ -133,21 +135,54 @@ void WorldRenderer::draw(World* world, Camera* camera, bool occlusion){
|
|||||||
// draw 3D stuff here
|
// draw 3D stuff here
|
||||||
batch3d->render();
|
batch3d->render();
|
||||||
|
|
||||||
linesShader->use();
|
|
||||||
linesShader->uniformMatrix("u_projview", camera->getProjection()*camera->getView());
|
|
||||||
glLineWidth(2.0f);
|
|
||||||
lineBatch->line(camera->position.x, camera->position.y-0.1f, camera->position.z, camera->position.x+0.01f, camera->position.y-0.1f, camera->position.z, 1, 0, 0, 1);
|
|
||||||
lineBatch->line(camera->position.x, camera->position.y-0.1f, camera->position.z, camera->position.x, camera->position.y-0.1f, camera->position.z+0.01f, 0, 0, 1, 1);
|
|
||||||
lineBatch->line(camera->position.x, camera->position.y-0.1f, camera->position.z, camera->position.x, camera->position.y-0.1f+0.01f, camera->position.z, 0, 1, 0, 1);
|
|
||||||
lineBatch->render();
|
|
||||||
|
|
||||||
if (level->playerController->selectedBlockId != -1){
|
if (level->playerController->selectedBlockId != -1){
|
||||||
Block* selectedBlock = Block::blocks[level->playerController->selectedBlockId];
|
Block* selectedBlock = Block::blocks[level->playerController->selectedBlockId];
|
||||||
vec3 pos = level->playerController->selectedBlockPosition;
|
vec3 pos = level->playerController->selectedBlockPosition;
|
||||||
|
linesShader->use();
|
||||||
|
linesShader->uniformMatrix("u_projview", camera->getProjection()*camera->getView());
|
||||||
|
glLineWidth(2.0f);
|
||||||
if (selectedBlock->model == 1){
|
if (selectedBlock->model == 1){
|
||||||
lineBatch->box(pos.x+0.5f, pos.y+0.5f, pos.z+0.5f, 1.005f,1.005f,1.005f, 0,0,0,0.5f);
|
lineBatch->box(pos.x+0.5f, pos.y+0.5f, pos.z+0.5f, 1.005f,1.005f,1.005f, 0,0,0,0.5f);
|
||||||
} else if (selectedBlock->model == 2){
|
} else if (selectedBlock->model == 2){
|
||||||
lineBatch->box(pos.x+0.4f, pos.y+0.3f, pos.z+0.4f, 0.805f,0.805f,0.805f, 0,0,0,0.5f);
|
lineBatch->box(pos.x+0.5f, pos.y+0.35f, pos.z+0.5f, 0.805f,0.705f,0.805f, 0,0,0,0.5f);
|
||||||
}
|
}
|
||||||
|
lineBatch->render();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (level->player->debug) {
|
||||||
|
linesShader->use();
|
||||||
|
linesShader->uniformMatrix("u_projview", camera->getProjection()*camera->getView());
|
||||||
|
|
||||||
|
vec3 point = vec3(camera->position.x+camera->front.x/1,
|
||||||
|
camera->position.y+camera->front.y/1,
|
||||||
|
camera->position.z+camera->front.z/1);
|
||||||
|
|
||||||
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
|
glLineWidth(4.0f);
|
||||||
|
lineBatch->line(point.x, point.y, point.z,
|
||||||
|
point.x+0.1f, point.y, point.z,
|
||||||
|
0, 0, 0, 1);
|
||||||
|
lineBatch->line(point.x, point.y, point.z,
|
||||||
|
point.x, point.y, point.z+0.1f,
|
||||||
|
0, 0, 0, 1);
|
||||||
|
lineBatch->line(point.x, point.y, point.z,
|
||||||
|
point.x, point.y+0.1f, point.z,
|
||||||
|
0, 0, 0, 1);
|
||||||
|
lineBatch->render();
|
||||||
|
|
||||||
|
glLineWidth(2.0f);
|
||||||
|
lineBatch->line(point.x, point.y, point.z,
|
||||||
|
point.x+0.1f, point.y, point.z,
|
||||||
|
1, 0, 0, 1);
|
||||||
|
lineBatch->line(point.x, point.y, point.z,
|
||||||
|
point.x, point.y, point.z+0.1f,
|
||||||
|
0, 0, 1, 1);
|
||||||
|
lineBatch->line(point.x, point.y, point.z,
|
||||||
|
point.x, point.y+0.1f, point.z,
|
||||||
|
0, 1, 0, 1);
|
||||||
|
lineBatch->render();
|
||||||
|
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,10 +4,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
|
|
||||||
#ifndef std::string
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/ext.hpp>
|
#include <glm/ext.hpp>
|
||||||
@ -37,7 +34,7 @@ public:
|
|||||||
WorldRenderer(Level* level, Assets* assets);
|
WorldRenderer(Level* level, Assets* assets);
|
||||||
~WorldRenderer();
|
~WorldRenderer();
|
||||||
|
|
||||||
void draw(World* world, Camera* camera, bool occlusion);
|
void draw(Camera* camera, bool occlusion);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user