Skip to content
This repository has been archived by the owner on Sep 22, 2024. It is now read-only.

Commit

Permalink
0.4.5
Browse files Browse the repository at this point in the history
- Disabled GLFW hint to scale to DPI
- Added -pthread to compiler options
- Split build script from `mkrelease.sh` to a separate file (`build.sh`)
- Build for 32-bit architectures and redo naming scheme
- Redid block data format
  • Loading branch information
PQCraft committed Oct 25, 2022
1 parent 53135e4 commit 264bd93
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
!resources/**
!src/
!src/**
!*.sh
!CONTRIBUTING.md
!gen.mk
!LICENSE
!Makefile
!mkrelease.sh
!README.md
!TODO.md
!util.mk
Expand Down
37 changes: 31 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ ifndef OS
STRIP ?= strip
WINDRES ?= true
else
CC = x86_64-w64-mingw32-gcc
STRIP = x86_64-w64-mingw32-strip
WINDRES = x86_64-w64-mingw32-windres
ifndef M32
CC = x86_64-w64-mingw32-gcc
STRIP = x86_64-w64-mingw32-strip
WINDRES = x86_64-w64-mingw32-windres
else
CC = i686-w64-mingw32-gcc
STRIP = i686-w64-mingw32-strip
WINDRES = i686-w64-mingw32-windres
endif
endif
else
CC = gcc
Expand All @@ -21,8 +27,13 @@ endif
ifdef NATIVE
CC := $(CC) -march=native -mtune=native
endif
ifdef M32
CC := $(CC) -m32
endif
ifndef DEBUG
CC := $(CC) -flto=auto
ifndef NOLTO
CC := $(CC) -flto=auto
endif
endif

empty :=
Expand All @@ -31,7 +42,11 @@ ${space} := ${space}

SRCDIR ?= src
ifndef OS
PLATFORM := $(subst ${ },_,$(subst /,_,$(shell uname -s)_$(shell uname -m)))
ifndef M32
PLATFORM := $(subst ${ },_,$(subst /,_,$(shell uname -s)_$(shell uname -m)))
else
PLATFORM := $(subst ${ },_,$(subst /,_,$(shell i386 uname -s)_$(shell i386 uname -m)))
endif
else
ifndef WINCROSS
ifeq ($(shell echo %PROGRAMFILES(x86)%),)
Expand All @@ -40,7 +55,11 @@ else
PLATFORM := Windows_x86_64
endif
else
PLATFORM := $(subst ${ },_,Windows_Cross_$(shell uname -m))
ifndef M32
PLATFORM := $(subst ${ },_,Windows_Cross_$(shell uname -m))
else
PLATFORM := $(subst ${ },_,Windows_Cross_$(shell i386 uname -m))
endif
endif
endif
ifndef SERVER
Expand Down Expand Up @@ -86,6 +105,12 @@ ifdef SERVER
WRFLAGS += -DSERVER
endif
endif
ifdef M32
CFLAGS += -DM32
ifdef OS
WRFLAGS += -DM32
endif
endif

BINFLAGS += -pthread -lm
ifndef OS
Expand Down
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,35 @@
[![](https://raw.githubusercontent.com/PQCraft/PQCraft/master/Screenshot_20220918_210819.png)](#?)

---
### Prerequisites
GLFW or SDL2, GNU Make, and a C compiler with POSIX thread support are needed to build CaveCube.<br>
### Contributing
Please read the [contributing guide](https://github.com/PQCraft/CaveCube/blob/dev/CONTRIBUTING.md).<br>
The project status is written down in [TODO.md](https://github.com/PQCraft/CaveCube/blob/dev/TODO.md).<br>

---
### Requirements
#### Building
GLFW or SDL2, GNU Make, and a C compiler with POSIX thread.<br>
For Windows, the GLFW or SDL2 development binaries must be installed from their respective websites: [GLFW](https://www.glfw.org/download), [SDL2](https://www.libsdl.org/download-2.0.php).<br>
For outdated/stable Linux distributions (such as Debian or Ubuntu), GLFW must be built from source due to the package being out of date.<br>
#### Running
OpenGL 3.3 or OpenGLES 3.0 support.

---
### Bulding
- To build, run `make -j`.<br>
- To build and run once done compiling, run `make -j run`.<br>
- To build for debugging, add `DEBUG=[level]` after `make` (eg. `make DEBUG=0 -j run`). This will build the executable with debug symbols, disable symbol and section stripping, and define the internal `DEBUG` macro with the level specified.<br>
- To change the target to the standalone server, add `SERVER=y` after `make`. You must also apply this to clean to remove the server binary.<br>
- To cross compile to Windows on a non-Windows OS, add `WINCROSS=y` after `make`. You must also use this when running the clean rule to remove the correct files.<br>
- To build for debugging, add `DEBUG=[level]` after `make` (eg. `make DEBUG=0 -j run`). This will build the executable with debug symbols, disable symbol stripping, and define the internal `DEBUG` macro with the level specified.<br>
- To compile with using SDL2 instead of GLFW, add `USESDL2=y` after `make`.<br>
- To compile using OpenGL ES instead of OpenGL, add `USEGLES=y` after `make`.<br>
- To change the target to the standalone server, add `SERVER=y` after `make`. This variable will change the object directory.<br>
- To cross compile to Windows on a non-Windows OS, add `WINCROSS=y` after `make`. This variable will change the object directory and binary name.<br>
- To compile a 32-bit binary on a 64-bit machine, add `M32=y` after `make`. This variable will change the object directory.<br>

These variables can be combined.<br>
For example, `make USESDL2=y WINCROSS=y -j run` will build CaveCube for Windows with SDL2 and run when compilation finishes.<br>
<br>
For any variables that change the object directory or binary name, you must use these flags again when running the `clean` rule in order to remove the correct files.<br>

---
### Notes <img src="https://repology.org/badge/vertical-allrepos/cavecube.svg" alt="Packaging status" align="right"><br>
- CaveCube can be installed on Arch Linux using the [cavecube](https://aur.archlinux.org/packages/cavecube) or [cavecube-bin](https://aur.archlinux.org/packages/cavecube-bin) package.<br>
- The project status is written down in [TODO.md](https://github.com/PQCraft/CaveCube/blob/dev/TODO.md).<br>
- Please read the [contributing guide](https://github.com/PQCraft/CaveCube/blob/dev/CONTRIBUTING.md) before contributing code.<br>
3 changes: 3 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@
### DONE:
- Disabled GLFW hint to scale to DPI
- Added -pthread to compiler options
- Split build script from `mkrelease.sh` to a separate file (`build.sh`)
- Build for 32-bit architectures and redo naming scheme
- Redid block data format
72 changes: 72 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash

{

source mkrelease.sh

NJOBS=""
rm -rf cavecube*.tar.gz cavecube*.zip
buildrel() {
local TYPE="${1}"
local OS="${2}"
inf "Building ${TYPE} for ${OS}..."
make ${@:3} clean 1> /dev/null || _exit
RESPONSE=""
while ! make ${@:3} "-j${NJOBS}" 1> /dev/null; do
while [[ -z "${RESPONSE}" ]]; do
ask "${TB}Build failed. Retry?${TR} (${TB}Y${TR}es/${TB}N${TR}o/${TB}C${TR}lean): "
case "${RESPONSE,,}" in
y | yes)
break
;;
n | no)
break
;;
c | clean)
make ${@:3} clean 1> /dev/null || _exit
;;
*)
RESPONSE=""
;;
esac
done
case "${RESPONSE,,}" in
n | no)
RESPONSE="n"
break
;;
*)
RESPONSE=""
;;
esac
done
[[ "${RESPONSE}" == "n" ]] || pkgrel || _exit
make ${@:3} clean 1> /dev/null || _exit
[[ ! "${RESPONSE}" == "n" ]] || _exit 1
}
# Game: Linux x86_64
pkgrel() { _tar "cavecube_game_linux_x86_64.tar.gz" cavecube; }
buildrel "game" "Linux x86_64"
# Game: Linux i686
pkgrel() { _tar "cavecube_game_linux_i686.tar.gz" cavecube; }
buildrel "game" "Linux i686" M32=y
# Game: Windows x86_64
pkgrel() { _zip "cavecube_game_windows_x86_64.zip" cavecube.exe; }
buildrel "game" "Windows x86_64" WINCROSS=y
# Game: Windows i686
pkgrel() { _zip "cavecube_game_windows_i686.zip" cavecube.exe; }
buildrel "game" "Windows i686" M32=y WINCROSS=y
# Server: Linux x86_64
pkgrel() { _tar "cavecube_server_linux_x86_64.tar.gz" ccserver; }
buildrel "server" "Linux x86_64" SERVER=y
# Server: Linux i686
pkgrel() { _tar "cavecube_server_linux_i686.tar.gz" ccserver; }
buildrel "server" "Linux i686" M32=y SERVER=y
# Server: Windows x86_64
pkgrel() { _zip "cavecube_server_windows_x86_64.zip" ccserver.exe; }
buildrel "server" "Windows x86_64" SERVER=y WINCROSS=y
# Server: Windows i686
pkgrel() { _zip "cavecube_server_windows_i686.zip" ccserver.exe; }
buildrel "server" "Windows i686" M32=y SERVER=y WINCROSS=y

}
63 changes: 10 additions & 53 deletions mkrelease.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ _exit() {
exit "${ERR}"
}

_tar() { rm -f "${1}"; tar -zc -f "${1}" ${@:2} 1> /dev/null; }
_zip() { rm -f "${1}"; zip -r -9 "${1}" ${@:2} 1> /dev/null; }

if ! (return 0 2>/dev/null); then

tsk "Getting info..."
VER_MAJOR="$(grep '#define VER_MAJOR ' src/main/version.h | sed 's/#define .* //')"
VER_MINOR="$(grep '#define VER_MINOR ' src/main/version.h | sed 's/#define .* //')"
Expand All @@ -44,59 +49,9 @@ printf "${I} ${TB}Release text:${TR}\n%s\n${TB}EOF${TR}\n" "${RELTEXT}"
pause

tsk "Building..."
NJOBS=""
#NJOBS="$(nproc)"
rm -rf cavecube*.tar.gz cavecube*.zip
_tar() { rm -f "${1}"; tar -zc -f "${1}" ${@:2} 1> /dev/null; }
_zip() { rm -f "${1}"; zip -r -9 "${1}" ${@:2} 1> /dev/null; }
buildrel() {
local TYPE="${1}"
local OS="${2}"
inf "Building ${TYPE} for ${OS}..."
make ${@:3} clean 1> /dev/null || _exit
RESPONSE=""
while ! make ${@:3} "-j${NJOBS}" 1> /dev/null; do
while [[ -z "${RESPONSE}" ]]; do
ask "${TB}Build failed. Retry?${TR} (${TB}Y${TR}es/${TB}N${TR}o/${TB}C${TR}lean): "
case "${RESPONSE,,}" in
y | yes)
break
;;
n | no)
break
;;
c | clean)
make ${@:3} clean 1> /dev/null || _exit
;;
*)
RESPONSE=""
;;
esac
done
case "${RESPONSE,,}" in
n | no)
RESPONSE="n"
break
;;
*)
RESPONSE=""
;;
esac
done
[[ "${RESPONSE}" == "n" ]] || pkgrel || _exit
make ${@:3} clean 1> /dev/null || _exit
[[ "${RESPONSE}" == "n" ]] && _exit 1
}
pkgrel() { _tar "cavecube-linux.tar.gz" cavecube; }
buildrel "game" "Linux"
pkgrel() { _zip "cavecube-windows.zip" cavecube.exe; }
buildrel "game" "Windows" WINCROSS=y
pkgrel() { _tar "cavecube-server-linux.tar.gz" ccserver; }
buildrel "server" "Linux" SERVER=y
pkgrel() { _zip "cavecube-server-windows.zip" ccserver.exe; }
buildrel "server" "Windows" SERVER=y WINCROSS=y
inf "Making cavecube-data.zip..."
_zip "cavecube-data.zip" extras/ resources/
./build.sh || _exit
inf "Making cavecube_data.zip..."
_zip "cavecube_data.zip" extras/ resources/
pause

tsk "Pushing..."
Expand Down Expand Up @@ -136,4 +91,6 @@ rm -rf cavecube*.tar.gz cavecube*.zip
tsk "Done"
exit

fi

}
6 changes: 3 additions & 3 deletions src/game/chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct blockdata getBlock(struct chunkdata* data, int cx, int cz, int x, int y,
cz += data->info.dist;
x += 8;
z += 8;
if (cx < 0 || cz < 0 || y < 0 || y > 255 || cx >= (int)data->info.width || cz >= (int)data->info.width ) return (struct blockdata){0, 0, 0, 0, 0, 0};
if (cx < 0 || cz < 0 || y < 0 || y > 255 || cx >= (int)data->info.width || cz >= (int)data->info.width ) return (struct blockdata){0, 0, 0, 0, 0, 0, 0, 0};
int32_t c = cx + cz * data->info.width;
while (x < 0 && c % data->info.width) {c -= 1; x += 16;}
while (x > 15 && (c + 1) % data->info.width) {c += 1; x -= 16;}
Expand All @@ -52,8 +52,8 @@ struct blockdata getBlock(struct chunkdata* data, int cx, int cz, int x, int y,
cx = c % data->info.width;
cz = c / data->info.width % data->info.width;
//printf("resolved: [%d, %d, %d] [%d, %d, %d]\n", cx, cy, cz, x, y, z);
if (c < 0 || c >= (int32_t)data->info.widthsq || x < 0 || z < 0 || x > 15 || z > 15) return (struct blockdata){0, 0, 0, 0, 0, 0};
if (!data->renddata[c].generated) return (struct blockdata){255, 0, 0, 0, 0, 0};
if (c < 0 || c >= (int32_t)data->info.widthsq || x < 0 || z < 0 || x > 15 || z > 15) return (struct blockdata){0, 0, 0, 0, 0, 0, 0, 0};
if (!data->renddata[c].generated) return (struct blockdata){255, 0, 0, 0, 0, 0, 0, 0};
return data->data[c][y * 256 + z * 16 + x];
}

Expand Down
8 changes: 5 additions & 3 deletions src/game/chunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
#include <inttypes.h>

struct __attribute__((packed)) blockdata {
uint8_t id;
uint8_t id:8;
uint8_t subid:6;
uint8_t rotx:2;
uint8_t roty:2;
uint8_t rotz:2;
uint8_t light_r:4;
uint8_t light_g:4;
uint8_t light_b:4;
uint8_t data1:4;
uint8_t data2;
};

struct chunkinfo {
Expand Down
4 changes: 2 additions & 2 deletions src/game/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ bool doGame(char* addr, int port) {
if ((altutime() - ptime2) >= 125000 && blockid && blockid != 7 && (!blockid2 || blockid2 == 7)) {
ptime2 = altutime();
int blocknum = invspot + 1 + invoff * 10;
if (blockinf[blocknum].id) setBlock(&chunks, 0, 0, lastblockx, lastblocky, lastblockz, (struct blockdata){blocknum, 0, 0, 0, 0, 0});
if (blockinf[blocknum].id) setBlock(&chunks, 0, 0, lastblockx, lastblocky, lastblockz, (struct blockdata){blocknum, 0, 0, 0, 0, 0, 0, 0});
}
placehold = true;
} else {
Expand All @@ -535,7 +535,7 @@ bool doGame(char* addr, int port) {
if (!destroyhold || (altutime() - dtime) >= 500000)
if ((altutime() - dtime2) >= 125000 && blockid && blockid != 7 && (!blockid2 || blockid2 == 7)) {
dtime2 = altutime();
setBlock(&chunks, 0, 0, blockx, blocky, blockz, (struct blockdata){0, 0, 0, 0, 0, 0});
setBlock(&chunks, 0, 0, blockx, blocky, blockz, (struct blockdata){0, 0, 0, 0, 0, 0, 0, 0});
}
destroyhold = true;
} else {
Expand Down
8 changes: 2 additions & 6 deletions src/main/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@
#include <common/config.h>

#ifndef DEBUG
#define DEBUG 0
#define DEBUG -1
#endif

#define DBGLVL(x) (DEBUG >= (x))

#if DBGLVL(1)
#if DBGLVL(0)
#define NAME_THREADS
#endif

#ifdef NAME_THREADS
#define _GNU_SOURCE
#endif

#ifndef MAX_THREADS
#define MAX_THREADS 32
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/main/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#define VER_MAJOR 0
#define VER_MINOR 4
#define VER_PATCH 4
#define VER_PATCH 5

#define _STR(x) #x
#define STR(x) _STR(x)
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,9 @@ static force_inline struct blockdata rendGetBlock(int32_t c, int x, int y, int z
while (x > 15 && (c + 1) % chunks->info.width) {c += 1; x -= 16;}
while (z > 15 && c >= (int)chunks->info.width) {c -= chunks->info.width; z -= 16;}
while (z < 0 && c < (int)(chunks->info.widthsq - chunks->info.width)) {c += chunks->info.width; z += 16;}
if (c < 0 || x < 0 || z < 0 || x > 15 || z > 15) return (struct blockdata){255, 0, 0, 0, 0, 0};
if (c >= (int32_t)chunks->info.widthsq || y < 0 || y > 255) return (struct blockdata){0, 0, 0, 0, 0, 0};
if (!chunks->renddata[c].generated) return (struct blockdata){255, 0, 0, 0, 0, 0};
if (c < 0 || x < 0 || z < 0 || x > 15 || z > 15) return (struct blockdata){255, 0, 0, 0, 0, 0, 0, 0};
if (c >= (int32_t)chunks->info.widthsq || y < 0 || y > 255) return (struct blockdata){0, 0, 0, 0, 0, 0, 0, 0};
if (!chunks->renddata[c].generated) return (struct blockdata){255, 0, 0, 0, 0, 0, 0, 0};
struct blockdata ret = chunks->data[c][y * 256 + z * 16 + x];
return ret;
}
Expand Down

0 comments on commit 264bd93

Please sign in to comment.