Skip to content

Commit

Permalink
Implemented sk_config module parsing Lua files
Browse files Browse the repository at this point in the history
  • Loading branch information
iWas-Coder committed Apr 20, 2024
1 parent b4849d7 commit b0c634a
Show file tree
Hide file tree
Showing 14 changed files with 308 additions and 50 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "vendor/raylib"]
path = vendor/raylib
url = https://github.com/raysan5/raylib
[submodule "vendor/lua"]
path = vendor/lua
url = https://github.com/lua/lua
36 changes: 34 additions & 2 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,14 @@ endif
VENDOR_DIR = vendor
RAYLIB_SRC_DIR = $(VENDOR_DIR)/raylib/$(SRC_DIR)
RAYLIB_BUILD_DIR = $(BUILD_DIR)/raylib
LUA_SRC_DIR = $(VENDOR_DIR)/lua
LUA_BUILD_DIR = $(BUILD_DIR)/lua

# Files
RAYLIB_SRCS := $(wildcard $(RAYLIB_SRC_DIR)/*.c)
RAYLIB_OBJS := $(patsubst $(RAYLIB_SRC_DIR)/%.c, $(RAYLIB_BUILD_DIR)/%.o, $(RAYLIB_SRCS))
LUA_SRCS := $(filter-out $(LUA_SRC_DIR)/onelua.c, $(wildcard $(LUA_SRC_DIR)/*.c))
LUA_OBJS := $(patsubst $(LUA_SRC_DIR)/%.c, $(LUA_BUILD_DIR)/%.o, $(LUA_SRCS))
LAUNCHER_SRCS := $(wildcard $(SRC_DIR)/sk_launcher*.rs)
SRCS := $(wildcard $(SRC_DIR)/*.c)
OBJS := $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(SRCS))
Expand Down Expand Up @@ -127,11 +131,16 @@ define RAYLIB_CPPFLAGS
-isystem $(RAYLIB_SRC_DIR) \
-isystem $(RAYLIB_SRC_DIR)/external/glfw/$(HDR_DIR)
endef
define LUA_CPPFLAGS
$(DISABLE_ASSERTS_OPTS) \
-isystem $(LUA_SRC_DIR)
endef
define CPPFLAGS
-D SK_VERSION=$(DIST_VERSION) \
$(DISABLE_ASSERTS_OPTS) \
-D _POSIX_C_SOURCE=199309L \
-isystem $(RAYLIB_SRC_DIR) \
-isystem $(LUA_SRC_DIR) \
-I $(HDR_DIR)
endef
define RAYLIB_CFLAGS
Expand All @@ -141,6 +150,12 @@ define RAYLIB_CFLAGS
$(RELEASE_OPTS) \
$(MACOS_SPECIFIC_CFLAGS_OPTS)
endef
define LUA_CFLAGS
-std=c99 \
$(DEBUG_SYM_OPTS) \
$(RELEASE_OPTS) \
$(MACOS_SPECIFIC_CFLAGS_OPTS)
endef
define CFLAGS
-std=c11 \
-Wall \
Expand All @@ -153,11 +168,13 @@ define CFLAGS
endef
define LDFLAGS
$(BUILDID_OPTS) \
$(HIDE_WARNS_OPTS) \
$(STRIP_OPTS) \
$(RELEASE_OPTS) \
-L $(BUILD_DIR) \
-L $(LAUNCHER_BUILD_DIR) \
-lraylib \
-llua \
-lsk_launcher \
-lpthread \
-lm \
Expand All @@ -169,6 +186,7 @@ endef
# Build output
LAUNCHER_OUT = $(LAUNCHER_BUILD_DIR)/libsk_launcher.a
RAYLIB_OUT = $(BUILD_DIR)/libraylib.a
LUA_OUT = $(BUILD_DIR)/liblua.a
ifdef D
OUT = $(NAME)_debug
else
Expand All @@ -182,7 +200,7 @@ endif
.WAIT:
.PHONY: all checkdeps game clean mrproper version help

all: checkdeps .WAIT $(BUILD_DIR) $(RAYLIB_BUILD_DIR) game
all: checkdeps .WAIT $(BUILD_DIR) $(RAYLIB_BUILD_DIR) $(LUA_BUILD_DIR) game
@:

checkdeps:
Expand All @@ -203,10 +221,14 @@ $(RAYLIB_BUILD_DIR):
@echo " $(PPO_MKDIR) $@"
$(Q)mkdir -p $@

$(LUA_BUILD_DIR):
@echo " $(PPO_MKDIR) $@"
$(Q)mkdir -p $@

game: $(OUT)
@echo "INFO: $(OUT) is ready ($(FULL_VERSION))"

$(OUT): $(RAYLIB_OUT) $(LAUNCHER_OUT) $(OBJS)
$(OUT): $(RAYLIB_OUT) $(LUA_OUT) $(LAUNCHER_OUT) $(OBJS)
@echo " $(PPO_LD) $@"
$(Q)$(CC) $(OBJS) $(LDFLAGS) -o $@

Expand All @@ -220,6 +242,16 @@ $(RAYLIB_BUILD_DIR)/%.o: $(RAYLIB_SRC_DIR)/%.c

-include $(RAYLIB_BUILD_DIR)/*.d

$(LUA_OUT): $(LUA_OBJS)
@echo " $(PPO_AR) $@"
$(Q)$(AR) $@ $^

$(LUA_BUILD_DIR)/%.o: $(LUA_SRC_DIR)/%.c
@echo " $(PPO_CC) $@"
$(Q)$(CC) $(LUA_CPPFLAGS) $(LUA_CFLAGS) -c -MD $< -o $@

-include $(LUA_BUILD_DIR)/*.d

$(LAUNCHER_OUT): $(LAUNCHER_SRCS)
@if [ ! -e $(FIFO_RSC) ]; then \
mkfifo $(FIFO_RSC); \
Expand Down
57 changes: 57 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
--
-- GNU Sparky --- A 5v5 character-based libre tactical shooter
-- Copyright (C) 2024 Wasym A. Alonso
--
-- This file is part of Sparky.
--
-- Sparky is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- Sparky is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with Sparky. If not, see <http://www.gnu.org/licenses/>.
--


local MOUSE_BUTTON_LEFT = 0
local KEY_SPACE = 32
local KEY_A = 65
local KEY_D = 68
local KEY_E = 69
local KEY_Q = 81
local KEY_R = 82
local KEY_S = 83
local KEY_W = 87

Crosshair = {
radius = 2.5
}

Video = {
win_width = 1280,
win_height = 720,
fps_limit = 144
}

General = {
fov = 60,
mouse_sensitivity = 0.05
}

Controls = {
move_forward = KEY_W,
move_backwards = KEY_S,
move_left = KEY_A,
move_right = KEY_D,
peek_left = KEY_Q,
peek_right = KEY_E,
jump = KEY_SPACE,
shoot = MOUSE_BUTTON_LEFT,
reload = KEY_R
}
56 changes: 43 additions & 13 deletions include/sk_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,46 @@

#pragma once

#define SK_CONFIG_CLIENT_WIN_WIDTH 1280
#define SK_CONFIG_CLIENT_WIN_HEIGHT 720
#define SK_CONFIG_CLIENT_FPS 144
#define SK_CONFIG_CLIENT_FOV 60
#define SK_CONFIG_CLIENT_MOUSE_SENSITIVITY 0.05
#define SK_CONFIG_CLIENT_CROSSHAIR_RADIUS 2.5
#define SK_CONFIG_CLIENT_MOVE_FORWARD KEY_W
#define SK_CONFIG_CLIENT_MOVE_BACKWARDS KEY_S
#define SK_CONFIG_CLIENT_MOVE_LEFT KEY_A
#define SK_CONFIG_CLIENT_MOVE_RIGHT KEY_D
#define SK_CONFIG_CLIENT_PEEK_LEFT KEY_Q
#define SK_CONFIG_CLIENT_PEEK_RIGHT KEY_E
#define SK_CONFIG_CLIENT_JUMP KEY_SPACE
#include <sk_defines.h>

typedef struct {
f32 radius;
} sk_config_crosshair;

typedef struct {
u16 win_width;
u16 win_height;
u16 fps_limit;
} sk_config_video;

typedef struct {
u8 fov;
f32 mouse_sensitivity;
} sk_config_general;

typedef struct {
u16 move_forward;
u16 move_backwards;
u16 move_left;
u16 move_right;
u16 peek_left;
u16 peek_right;
u16 jump;
u16 shoot;
u16 reload;
} sk_config_controls;

typedef struct {
sk_config_crosshair crosshair;
sk_config_video video;
sk_config_general general;
sk_config_controls controls;
} sk_config;

sk_config sk_config_create(void);

void sk_config_destroy(sk_config *c);

void sk_config_load(const char *filepath, sk_config *c);

void sk_config_write(const char *filepath, sk_config *c);
9 changes: 5 additions & 4 deletions include/sk_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#pragma once

#include <raylib.h>
#include <sk_config.h>
#include <sk_weapon.h>

typedef enum {
Expand All @@ -43,16 +44,16 @@ static const char * const sk_player_kinds[] = {
[SK_PLAYER_KIND_AGENT69] = "agent69"
};

sk_player sk_player_create(i8 lobby_id, i8 lobby_slot_idx, sk_player_kind kind);
sk_player sk_player_create(i8 lobby_id, i8 lobby_slot_idx, sk_player_kind kind, sk_config *config);

void sk_player_destroy(sk_player *p);

void sk_player_load(sk_player *p, sk_weapon_kind initial_weapon_kind);

void sk_player_jump(sk_player *p);
void sk_player_jump(sk_player *p, sk_config *config);

f32 sk_player_peek(sk_player *p);
f32 sk_player_peek(sk_player *p, sk_config *config);

void sk_player_move(sk_player *p, f32 roll);
void sk_player_move(sk_player *p, sk_config *config, f32 roll);

void sk_player_draw(sk_player *p);
2 changes: 1 addition & 1 deletion include/sk_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#define sk_renderer_loop while (!WindowShouldClose())

void sk_renderer_create(void);
void sk_renderer_create(sk_config *config);

void sk_renderer_destroy(void);

Expand Down
2 changes: 2 additions & 0 deletions include/sk_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <sk_map.h>
#include <sk_scene.h>
#include <sk_lobby.h>
#include <sk_config.h>

#define SK_STATE_MAX_LOBBIES 256

Expand All @@ -34,6 +35,7 @@ typedef struct {

typedef struct sk_state {
u8 is_online;
sk_config config;
sk_scene curr_scene;
Music menu_music;
union {
Expand Down
Loading

0 comments on commit b0c634a

Please sign in to comment.