aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt5
-rw-r--r--src/level.c51
-rw-r--r--src/leveldefines.h2
3 files changed, 23 insertions, 35 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6a2edc8..8af6e9c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -15,6 +15,11 @@ add_executable(${PROJECT_NAME}
target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARIES})
+target_compile_options(${PROJECT_NAME}
+ PRIVATE -O3
+ PRIVATE -march=native
+)
+
# Checks if OSX and links appropriate frameworks (only required on MacOS)
if (APPLE)
target_link_libraries(${PROJECT_NAME} "-framework IOKit")
diff --git a/src/level.c b/src/level.c
index b65dbe2..87068ad 100644
--- a/src/level.c
+++ b/src/level.c
@@ -1,7 +1,6 @@
/*
work in progress game made using small3dlib, based on Miloslav Ciz's
quake-like level
-
*/
#include <SDL2/SDL_events.h>
@@ -103,7 +102,6 @@ void drawTeleport(int16_t x, int16_t y, S3L_ScreenCoord size) {
void drawPixel(S3L_PixelInfo* p) {
uint8_t r, g, b;
-
#if TEXTURES
if (p->triangleID != previousTriangle) {
uint8_t material = levelMaterials[p->triangleIndex];
@@ -203,6 +201,7 @@ void draw() {
fps++;
+#ifdef LOG_FPS
if (timeDiff >= 1.0) {
nextT = nowT;
printf("FPS: %d\n", fps);
@@ -211,6 +210,7 @@ void draw() {
S3L_logTransform3D(scene.camera.transform);
fps = 0;
}
+#endif
}
int main() {
@@ -254,33 +254,33 @@ int main() {
if (event.type == SDL_QUIT) {
running = 0;
} else if (event.type == SDL_MOUSEMOTION) {
- /* Set x and y to the current mouse position */
- int x, y;
- SDL_GetMouseState(&x, &y);
- int xdiff = x - mouse.x; // Calculate difference in x
- int ydiff = y - mouse.y; // Calculate difference in y
- /* rotate camera relative to what it was before */
- scene.camera.transform.rotation.x -= ydiff;
- scene.camera.transform.rotation.y -= xdiff;
- mouse.x = x;
- mouse.y = y;
+ if (scene.camera.transform.rotation.x < 130 &&
+ scene.camera.transform.rotation.x > -130) {
+ scene.camera.transform.rotation.x -=
+ S3L_clamp((S3L_Unit)event.motion.yrel, -1, 1);
+ } else {
+ scene.camera.transform.rotation.x +=
+ (scene.camera.transform.rotation.x == 130) ? -1 : 1;
+ }
+ scene.camera.transform.rotation.y -=
+ S3L_clamp((S3L_Unit)event.motion.xrel, -1, 1);
}
}
S3L_Vec4 camF, camR;
- S3L_rotationToDirections(scene.camera.transform.rotation, 20, &camF,
+ S3L_rotationToDirections(scene.camera.transform.rotation, 50, &camF,
&camR, 0);
const uint8_t* state = SDL_GetKeyboardState(NULL);
- if (state[SDL_SCANCODE_UP])
+ if (state[SDL_SCANCODE_W])
S3L_vec3Add(&scene.camera.transform.translation, camF);
- else if (state[SDL_SCANCODE_DOWN])
+ else if (state[SDL_SCANCODE_S])
S3L_vec3Sub(&scene.camera.transform.translation, camF);
- else if (state[SDL_SCANCODE_LEFT])
+ else if (state[SDL_SCANCODE_A])
S3L_vec3Sub(&scene.camera.transform.translation, camR);
- else if (state[SDL_SCANCODE_RIGHT])
+ else if (state[SDL_SCANCODE_D])
S3L_vec3Add(&scene.camera.transform.translation, camR);
if (state[SDL_SCANCODE_K])
@@ -292,23 +292,6 @@ int main() {
else if (state[SDL_SCANCODE_L])
newWidth = S3L_resolutionX + 4;
- if (((newWidth != -1 && newWidth > 0) ||
- (newHeight != -1 && newHeight > 0)) &&
- (newWidth * S3L_resolutionY <= S3L_MAX_PIXELS) &&
- (newHeight * S3L_resolutionX <= S3L_MAX_PIXELS)) {
- if (newWidth != -1)
- S3L_resolutionX = newWidth;
-
- if (newHeight != -1)
- S3L_resolutionY = newHeight;
-
- SDL_DestroyTexture(texture);
- texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBX8888,
- SDL_TEXTUREACCESS_STATIC,
- S3L_resolutionX, S3L_resolutionY);
- SDL_SetWindowSize(window, S3L_resolutionX, S3L_resolutionY);
- }
-
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer);
diff --git a/src/leveldefines.h b/src/leveldefines.h
index 7d739fa..4cc52ec 100644
--- a/src/leveldefines.h
+++ b/src/leveldefines.h
@@ -1,7 +1,7 @@
#pragma once
// game
-#define TEXTURES 1 // whether to use textures for the level
+#define TEXTURES 0 // whether to use textures for the level
#define FOG 1
// S3L