Skip to content

Commit

Permalink
Update quit app event condition, create logo.h (#15)
Browse files Browse the repository at this point in the history
* use header for data init
* correct ENDDELAY by unit evaluation
  • Loading branch information
Apaczer authored May 25, 2024
1 parent 42f21cf commit 22aa566
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

boot-logo
main.o
logo.o
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ CFLAGS = $(DEFINES) $(INCLUDES) $(OPT_FLAGS) -std=gnu11
CXXFLAGS = $(DEFINES) $(INCLUDES) $(OPT_FLAGS) -std=gnu++11
LDFLAGS = -Wl,--start-group -lSDL -lSDL_image -lpng -ljpeg -lSDL_mixer -lfreetype -lSDL_ttf -logg -lm -pthread -lz -lstdc++ $(EXTRA_LDFLAGS) -Wl,--end-group

# Redream (main engine)
# Redream (logo engine)
OBJS = \
main.o
logo.o

.c.o:
$(CC) $(CFLAGS) -c -o $@ $<
Expand Down
4 changes: 2 additions & 2 deletions Makefile.bittboy
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ CFLAGS = $(DEFINES) $(INCLUDES) $(OPT_FLAGS) -std=gnu11
CXXFLAGS = $(DEFINES) $(INCLUDES) $(OPT_FLAGS) -std=gnu++11
LDFLAGS = -Wl,--start-group -lSDL -lSDL_image -lpng -ljpeg -lSDL_mixer -lfreetype -lSDL_ttf -logg -lvorbisidec -lm -pthread -lz -lstdc++ $(EXTRA_LDFLAGS) -Wl,--end-group

# Redream (main engine)
# Redream (logo engine)
OBJS = \
main.o
logo.o

.c.o:
$(CC) $(CFLAGS) -c -o $@ $<
Expand Down
4 changes: 2 additions & 2 deletions Makefile.generic
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ CFLAGS = $(DEFINES) $(INCLUDES) $(OPT_FLAGS) -std=gnu11
CXXFLAGS = $(DEFINES) $(INCLUDES) $(OPT_FLAGS) -std=gnu++11
LDFLAGS = -Wl,--start-group -lSDL -lSDL_image -lpng -ljpeg -lSDL_mixer -lfreetype -lSDL_ttf -logg -lvorbisidec -lm -pthread -lz -lstdc++ $(EXTRA_LDFLAGS) -Wl,--end-group

# Redream (main engine)
# Redream (logo engine)
OBJS = \
main.o
logo.o

.c.o:
$(CC) $(CFLAGS) -c -o $@ $<
Expand Down
4 changes: 2 additions & 2 deletions Makefile.miyoo
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ CFLAGS = $(DEFINES) $(INCLUDES) $(OPT_FLAGS) -std=gnu11
CXXFLAGS = $(DEFINES) $(INCLUDES) $(OPT_FLAGS) -std=gnu++11
LDFLAGS = -Wl,--start-group -lSDL -lSDL_image -lpng -ljpeg -lSDL_mixer -lfreetype -lSDL_ttf -logg -lvorbisidec -lm -pthread -lz -lstdc++ $(EXTRA_LDFLAGS) -Wl,--end-group

# Redream (main engine)
# Redream (logo engine)
OBJS = \
main.o
logo.o

.c.o:
$(CC) $(CFLAGS) -c -o $@ $<
Expand Down
4 changes: 2 additions & 2 deletions Makefile.pocketgo
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ CFLAGS = $(DEFINES) $(INCLUDES) $(OPT_FLAGS) -std=gnu11
CXXFLAGS = $(DEFINES) $(INCLUDES) $(OPT_FLAGS) -std=gnu++11
LDFLAGS = -Wl,--start-group -lSDL -lSDL_image -lpng -ljpeg -lSDL_mixer -lfreetype -lSDL_ttf -logg -lvorbisidec -lm -pthread -lz -lstdc++ $(EXTRA_LDFLAGS) -Wl,--end-group

# Redream (main engine)
# Redream (logo engine)
OBJS = \
main.o
logo.o

.c.o:
$(CC) $(CFLAGS) -c -o $@ $<
Expand Down
4 changes: 2 additions & 2 deletions Makefile.powkiddy
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ CFLAGS = $(DEFINES) $(INCLUDES) $(OPT_FLAGS) -std=gnu11
CXXFLAGS = $(DEFINES) $(INCLUDES) $(OPT_FLAGS) -std=gnu++11
LDFLAGS = -Wl,--start-group -lSDL -lSDL_image -lpng -ljpeg -lSDL_mixer -lfreetype -lSDL_ttf -logg -lvorbisidec -lm -pthread -lz -lstdc++ $(EXTRA_LDFLAGS) -Wl,--end-group

# Redream (main engine)
# Redream (logo engine)
OBJS = \
main.o
logo.o

.c.o:
$(CC) $(CFLAGS) -c -o $@ $<
Expand Down
81 changes: 33 additions & 48 deletions main.cpp → logo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <stdlib.h>
#include <iostream>
#include "assets.h"
#include "logo.h"

//------------------- PARAMETERS --------------------//

Expand All @@ -24,37 +25,15 @@
#define ANIMDELAY 60

// time from the moment the logo stops moving and sound is played until the logo app closes (unit: frames) (60 frames = 1 sec)
#define ENDDELAY 3000
#define ENDDELAY 300

//speed at which the logo moves (unit: pixels per frame)
#define ANIMSPEED 1

//---------------------------------------------------//

void quit() {
Mix_CloseAudio();
SDL_Quit();
}

void exit_event() {
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_KEYDOWN:
quit();
break;
}
}
}

int main(int argc, char* argv[]) {
float animdel, enddel;
int animfps;
bool args = true;
char* str;
float argfloat[3];
memset(&argfloat, 0, sizeof(argfloat));

if (argc == 1) {
args = false;
} else if (argc == 4) {
Expand Down Expand Up @@ -85,8 +64,7 @@ int main(int argc, char* argv[]) {
printf("Usage: %s <logo_start[sec]> <logo_ending[sec]> <logo_speed[fps]>\nRunning default setup: %s %f %f %d\n", argv[0], argv[0], animdel/60, enddel/60, animfps);
}

char* homepath = getenv("HOME");
char logoimg_path[256], logosound_path[256], logobg_path[256];
homepath = getenv("HOME");
if (homepath == NULL) {
printf("$HOME has not been defined in env");
} else {
Expand All @@ -98,12 +76,9 @@ int main(int argc, char* argv[]) {
printf("Unable to initialize SDL: %s\n", SDL_GetError());
return -1;
}
SDL_Surface *screen;

screen = SDL_SetVideoMode(WIDTH, HEIGHT, 16, SDL_SWSURFACE);
SDL_ShowCursor(SDL_DISABLE);
SDL_RWops *RWops;
SDL_Surface *logoimg;

if (FILE *f = fopen(logoimg_path, "r")) {
RWops = SDL_RWFromFile(logoimg_path, "rb");
Expand All @@ -129,8 +104,6 @@ int main(int argc, char* argv[]) {

Mix_OpenAudio(22050, AUDIO_S16SYS, 2, 1024);
Mix_AllocateChannels(2);
SDL_RWops *RWops2;
Mix_Chunk *logosound;

if (FILE *f = fopen(logosound_path, "r")) {
RWops2 = SDL_RWFromFile(logosound_path, "rb");
Expand All @@ -144,23 +117,18 @@ int main(int argc, char* argv[]) {
return -1;
}

int dest_y = (screen->h - logoimg->h) / 2;
uint32_t curr_time = SDL_GetTicks();
uint32_t old_time = curr_time;
uint32_t color = SDL_MapRGB(screen->format, R, G, B);
bool blitbg = false;
SDL_Rect rect;
SDL_Rect dstrect;
SDL_Event event;
SDL_Surface* logobg;
if (FILE *f = fopen(logobg_path, "r")) {
logobg = IMG_Load(logobg_path);
blitbg = true;
} else {
printf("Didn't find PNG in %s - using default background\n", logobg_path);
}
for (int i = 0 - logoimg->h - animdel; i <= dest_y; i = i + animfps) {
exit_event();

color = SDL_MapRGB(screen->format, R, G, B);
dest_y = (screen->h - logoimg->h) / 2;
curr_time = old_time = SDL_GetTicks();
for (int i = 0 - logoimg->h - animdel; i <= dest_y && (!quit_app); i = i + animfps) {
input_poll();
rect.x = 0;
rect.y = 0;
rect.w = screen->w;
Expand All @@ -185,20 +153,37 @@ int main(int argc, char* argv[]) {
SDL_Flip(screen);
}

while(Mix_Playing(-1)) {
exit_event();
while(Mix_Playing(-1) && (!quit_app)) {
input_poll();
}

for (int j = 0 ; j < (sqrt(2+8*enddel)-1)/2; j++){
for (int j = 0 ; j < (sqrt(2+8*enddel*10)-1)/2 && (!quit_app); j++){
input_poll();
SDL_Delay(j);
exit_event();
}

quit();

return 0;
}

void quit() {
SDL_FreeRW(RWops);
SDL_FreeRW(RWops2);
SDL_FreeSurface(logoimg);
SDL_FreeSurface(screen);
Mix_FreeChunk(logosound);
quit();

return 0;
Mix_CloseAudio();
SDL_Quit();
}

void input_poll() {
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_KEYDOWN: case SDL_QUIT:
quit_app = true;
break;
}
}
}
31 changes: 31 additions & 0 deletions logo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef LOGO_H_
#define LOGO_H_
SDL_RWops *RWops;
SDL_Surface *logoimg;
SDL_Surface *screen;
SDL_RWops *RWops2;
SDL_Rect rect;
SDL_Rect dstrect;
SDL_Event event;
SDL_Surface* logobg;
Mix_Chunk *logosound;

bool quit_app = false;

bool args = true;
float animdel, enddel;
int animfps;
char* str;
float argfloat[3];

void quit();
void input_poll();

char* homepath;
char logoimg_path[256], logosound_path[256], logobg_path[256];

int dest_y;
uint32_t curr_time, old_time;
uint32_t color;
bool blitbg = false;
#endif /*LOGO_H_*/

0 comments on commit 22aa566

Please sign in to comment.