Skip to content

Commit

Permalink
Fixed some bugs building the game on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
bplaat committed Jan 14, 2022
1 parent 6085b13 commit 66a9d1c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 26 deletions.
14 changes: 7 additions & 7 deletions CMakeLists.txt
Expand Up @@ -14,15 +14,15 @@ set(CMAKE_C_STANDARD_REQUIRED TRUE)
set(CMAKE_C_FLAGS_DEBUG "-DDEBUG")

# Use SSE2 SIMD option
option(USE_SSE2_SIMD "Use x86 SSE2 SIMD instructions" OFF)
if (USE_SSE2_SIMD)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_SSE2_SIMD")
option(ENABLE_SSE2_SIMD "Use x86 SSE2 SIMD instructions" OFF)
if (ENABLE_SSE2_SIMD)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_SSE2_SIMD")
endif()

# Use NEON SIMD option
option(USE_NEON_SIMD "Use ARM NEON SIMD instructions" OFF)
if (USE_NEON_SIMD)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -USE_NEON_SIMD")
option(ENABLE_NEON_SIMD "Use ARM NEON SIMD instructions" OFF)
if (ENABLE_NEON_SIMD)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_NEON_SIMD")
endif()

### LIBRARIES ###
Expand All @@ -36,7 +36,7 @@ add_library(glad src/glad/glad.c)
target_include_directories(glad PRIVATE include)

# STB Image Library
if (NOT (USE_SSE2_SIMD OR USE_NEON_SIMD))
if (NOT (ENABLE_SSE2_SIMD OR ENABLE_NEON_SIMD))
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSTBI_NO_SIMD")
endif()
add_library(stb_image src/stb_image/stb_image.c)
Expand Down
12 changes: 6 additions & 6 deletions README.md
Expand Up @@ -23,9 +23,9 @@ You will need a computer / graphics card which supports minimal the OpenGL 3.3 C
sudo apt install build-essential cmake libglfw3-dev libsqlite3-dev
```

2. Generate MakeFile via CMake:
2. Generate MakeFile via CMake (also enable x86 SSE2 or ARM NEON SIMD if you want):
```
mkdir build && cd build && cmake ..
mkdir build && cd build && cmake -DENABLE_SSE2_SIMD=ON ..
```

3. Build the project:
Expand All @@ -40,9 +40,9 @@ You will need a computer / graphics card which supports minimal the OpenGL 3.3 C
brew install cmake glfw sqlite
```

2. Generate MakeFile via CMake:
2. Generate MakeFile via CMake (also enable x86 SSE2 or ARM NEON SIMD if you want):
```
mkdir build && cd build && cmake ..
mkdir build && cd build && cmake -DENABLE_NEON_SIMD=ON ..
```

3. Build the project:
Expand All @@ -59,9 +59,9 @@ You will need a computer / graphics card which supports minimal the OpenGL 3.3 C
pacman -S mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake mingw-w64-x86_64-glfw mingw-w64-x86_64-sqlite3
```

3. Generate MakeFile via CMake:
3. Generate MakeFile via CMake (also enable x86 SSE2 or ARM NEON SIMD if you want):
```
mkdir build && cd build && cmake -G "MinGW Makefiles" ..
mkdir build && cd build && cmake -G "MinGW Makefiles" -DENABLE_SSE2_SIMD=ON ..
```

4. Build the project:
Expand Down
4 changes: 2 additions & 2 deletions src/game.c
Expand Up @@ -375,9 +375,9 @@ void game_render(Game* game, float delta) {
game->camera->rotation.x, game->camera->rotation.y
);

#ifndef USE_NEON_SIMD
#ifdef ENABLE_NEON_SIMD
char *simd_type = "NEON";
#elif defined USE_SSE2_SIMD
#elif defined ENABLE_SSE2_SIMD
char *simd_type = "SSE2";
#else
char *simd_type = "none";
Expand Down
14 changes: 7 additions & 7 deletions src/math/matrix4.c
Expand Up @@ -17,13 +17,13 @@ void matrix4_identity(Matrix4 *matrix) {
matrix->elements[12] = 0; matrix->elements[13] = 0; matrix->elements[14] = 0; matrix->elements[15] = 1;
}

void matrix4_perspective(Matrix4 *matrix, float fov, float aspect, float near, float far) {
void matrix4_perspective(Matrix4 *matrix, float fov, float aspect, float _near, float _far) {
float f = tanf(M_PI * 0.5f - 0.5f * fov);
float r = 1.0 / (near - far);
float r = 1.0 / (_near - _far);
matrix->elements[0] = f / aspect; matrix->elements[1] = 0; matrix->elements[2] = 0; matrix->elements[3] = 0;
matrix->elements[4] = 0; matrix->elements[5] = f; matrix->elements[6] = 0; matrix->elements[7] = 0;
matrix->elements[8] = 0; matrix->elements[9] = 0; matrix->elements[10] = (near + far) * r; matrix->elements[11] = -1;
matrix->elements[12] = 0; matrix->elements[13] = 0; matrix->elements[14] = near * far * r * 2; matrix->elements[15] = 0;
matrix->elements[8] = 0; matrix->elements[9] = 0; matrix->elements[10] = (_near + _far) * r; matrix->elements[11] = -1;
matrix->elements[12] = 0; matrix->elements[13] = 0; matrix->elements[14] = _near * _far * r * 2; matrix->elements[15] = 0;
}

void matrix4_translate(Matrix4 *matrix, Vector4* position) {
Expand Down Expand Up @@ -148,9 +148,9 @@ void matrix4_mul_matrix4(Matrix4* matrix, Matrix4* rhs) {

b = _mm_load_ps(&rhs->elements[12]);
sum = _mm_mul_ps(a0, _mm_set1_ps(b[0]));
sum = _mm_add_ps(_mm_mul_ps(a1, _mm_set1_ps(b[1])));
sum = _mm_add_ps(_mm_mul_ps(a2, _mm_set1_ps(b[2])));
sum = _mm_add_ps(_mm_mul_ps(a3, _mm_set1_ps(b[3])));
sum = _mm_add_ps(sum, _mm_mul_ps(a1, _mm_set1_ps(b[1])));
sum = _mm_add_ps(sum, _mm_mul_ps(a2, _mm_set1_ps(b[2])));
sum = _mm_add_ps(sum, _mm_mul_ps(a3, _mm_set1_ps(b[3])));
_mm_store_ps(&matrix->elements[12], sum);
#else
float a00 = matrix->elements[0];
Expand Down
7 changes: 3 additions & 4 deletions src/utils.c
Expand Up @@ -19,17 +19,16 @@ double radians(double degrees) {

// Function to read a file to string
uint8_t* file_read(char* path) {
FILE* file = fopen(path, "r");
FILE* file = fopen(path, "rb");
if (file == NULL) {
log_error("Can't load file %s", path);
}
fseek(file, 0, SEEK_END);
size_t file_size = ftell(file);
fseek(file, 0, SEEK_SET);
uint8_t* file_buffer = malloc(file_size + 1);
size_t file_bytes_read = fread(file_buffer, 1, file_size, file);
(void)file_bytes_read;
file_buffer[file_size] = 0;
file_size = fread(file_buffer, 1, file_size, file);
file_buffer[file_size] = '\0';
fclose(file);
return file_buffer;
}
Expand Down

0 comments on commit 66a9d1c

Please sign in to comment.