Skip to content

Commit

Permalink
Add config.h
Browse files Browse the repository at this point in the history
  • Loading branch information
gustafla committed Aug 2, 2023
1 parent e32a73a commit 700825a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ RELEASEDIR = release
EXECUTABLE = demo
CC = gcc
STRIP = strip --strip-all
EXTRA_CFLAGS = -std=c99 -Wall -Wextra -Wpedantic -DGL_GLEXT_PROTOTYPES -I$(BUILDDIR)/include -L$(BUILDDIR)/lib
EXTRA_CFLAGS = -MMD -std=c99 -Wall -Wextra -Wpedantic -DGL_GLEXT_PROTOTYPES -I$(BUILDDIR)/include -L$(BUILDDIR)/lib
LDLIBS = -lm -l:libSDL2.a -lGL
DEBUG ?= 1

Expand All @@ -25,7 +25,8 @@ endif
SOURCEDIR = src
TARGET = $(OBJDIR)/$(EXECUTABLE)
SOURCES = $(wildcard $(SOURCEDIR)/*.c)
OBJS = $(patsubst %.c,%.o,$(SOURCES:$(SOURCEDIR)/%=$(OBJDIR)/%))
OBJS = $(SOURCES:%.c=$(OBJDIR)/%.o)
DEPS = $(OBJS:%.o=%.d)
LIBRARIES = $(BUILDDIR)/lib/libSDL2.a $(BUILDDIR)/lib/librocket.a $(BUILDDIR)/include/stb_vorbis.c $(BUILDDIR)/include/data.c


Expand All @@ -38,8 +39,12 @@ ifeq ($(DEBUG),0)
endif


# Include compiler-generated header dependencies
-include $(DEPS)


# This rule is for compiling our C source files
$(OBJDIR)/%.o: $(SOURCEDIR)/%.c $(LIBRARIES)
$(OBJDIR)/%.o: %.c $(LIBRARIES)
@mkdir -p $(@D)
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<

Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ This will use all CPU cores you have available.
## Default workflow

0. Put your `music.ogg` file into `data` directory.
1. Open your [rocket](https://rocket.github.io/) editor. I prefer the default Qt-based rocket editor.
2. Start `./build/demo`
3. Open `data/shader.frag` in your editor.
4. Hack on shaders! Uniforms prefixed with `r_` will automatically show up in rocket.
5. Reload shaders and uniforms by pressing R. No `make` or restart needed.
1. Edit [`src/config.h`](src/config.h) to match your desired resolution and **your music track's BPM**! Don't skip this. Then run `make` once more.
2. Open your [rocket](https://rocket.github.io/) editor. I prefer the default Qt-based rocket editor.
3. Start `./build/demo`
4. Open `data/shader.frag` in your editor.
5. Hack on shaders! Uniforms prefixed with `r_` will automatically show up in rocket.
6. Reload shaders and uniforms by pressing R. No `make` or restart needed.

### What if my music track is not in .ogg vorbis format?

Expand Down
9 changes: 9 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef CONFIG_H
#define CONFIG_H

#define WIDTH 1920
#define HEIGHT 720
#define BEATS_PER_MINUTE 120.0
#define ROWS_PER_BEAT 8.

#endif
14 changes: 5 additions & 9 deletions src/main.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#include "config.h"
#include "demo.h"
#include "music_player.h"
#include "rocket_io.h"
#include <SDL2/SDL.h>
#include <sync.h>

#define WIDTH 1920
#define HEIGHT 720
#define BEATS_PER_MINUTE 120.0
#define ROWS_PER_BEAT 8.
#define ROW_RATE ((BEATS_PER_MINUTE / 60.) * ROWS_PER_BEAT)

#ifdef DEBUG
Expand Down Expand Up @@ -118,6 +115,10 @@ int main(void) {

player_pause(player, 0);
while (running) {
#ifndef DEBUG
// Quit the demo when music ends
running = !player_at_end(player);
#endif
// Get SDL events, such as keyboard presses or quit-signals
while (SDL_PollEvent(&e)) {
if (e.type == SDL_QUIT) {
Expand Down Expand Up @@ -156,11 +157,6 @@ int main(void) {
SDL_Log("Rocket disconnected\n");
running = 0;
}
#else
// Quit the demo when music ends
if (player_at_end(player)) {
running = 0;
}
#endif

// Render. This does draw calls.
Expand Down

0 comments on commit 700825a

Please sign in to comment.