Skip to content

Commit d2bc11c

Browse files
committed
Merge remote-tracking branch 'origin/master' into develop
2 parents 80fdbfc + 0b8fbff commit d2bc11c

File tree

1 file changed

+62
-61
lines changed

1 file changed

+62
-61
lines changed

users/snowe/ocean_dream.c

+62-61
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
#include "print.h"
2121

2222
// Calculated Parameters
23-
#define TWINKLE_PROBABILITY_MODULATOR 100 / TWINKLE_PROBABILITY // CALCULATED: Don't Touch
24-
#define TOTAL_STARS STARS_PER_LINE *NUMBER_OF_STAR_LINES // CALCULATED: Don't Touch
25-
#define OCEAN_ANIMATION_MODULATOR NUMBER_OF_FRAMES / OCEAN_ANIMATION_SPEED // CALCULATED: Don't Touch
26-
#define SHOOTING_STAR_ANIMATION_MODULATOR NUMBER_OF_FRAMES / SHOOTING_STAR_ANIMATION_SPEED // CALCULATED: Don't Touch
27-
#define STAR_ANIMATION_MODULATOR NUMBER_OF_FRAMES / STAR_ANIMATION_SPEED // CALCULATED: Don't Touch
23+
#define TWINKLE_PROBABILITY_MODULATOR 100 / TWINKLE_PROBABILITY // CALCULATED: Don't Touch
24+
#define TOTAL_STARS STARS_PER_LINE *NUMBER_OF_STAR_LINES // CALCULATED: Don't Touch
25+
#define OCEAN_ANIMATION_MODULATOR NUMBER_OF_FRAMES / OCEAN_ANIMATION_SPEED // CALCULATED: Don't Touch
26+
#define SHOOTING_STAR_ANIMATION_MODULATOR NUMBER_OF_FRAMES / SHOOTING_STAR_ANIMATION_SPEED // CALCULATED: Don't Touch
27+
#define STAR_ANIMATION_MODULATOR NUMBER_OF_FRAMES / STAR_ANIMATION_SPEED // CALCULATED: Don't Touch
2828

29-
uint8_t animation_counter = 0; // global animation counter.
29+
uint8_t animation_counter = 0; // global animation counter.
3030
bool is_calm = false;
3131
uint32_t starry_night_anim_timer = 0;
3232
uint32_t starry_night_anim_sleep = 0;
@@ -52,10 +52,10 @@ static uint8_t decrement_counter(uint8_t counter, uint8_t max) {
5252
}
5353
#endif
5454

55-
#ifdef ENABLE_MOON // region
55+
#ifdef ENABLE_MOON // region
5656
# ifndef STATIC_MOON
57-
uint8_t moon_animation_frame = 0; // keeps track of current moon frame
58-
uint16_t moon_animation_counter = 0; // counts how many frames to wait before animating moon to next frame
57+
uint8_t moon_animation_frame = 0; // keeps track of current moon frame
58+
uint16_t moon_animation_counter = 0; // counts how many frames to wait before animating moon to next frame
5959
# endif
6060

6161
# ifdef STATIC_MOON
@@ -99,9 +99,9 @@ static void draw_moon(void) {
9999
}
100100
# endif
101101
}
102-
#endif // endregion
102+
#endif // endregion
103103

104-
#ifdef ENABLE_WAVE // region
104+
#ifdef ENABLE_WAVE // region
105105
uint8_t starry_night_wave_frame_width_counter = 31;
106106
uint8_t rough_waves_frame_counter = 0;
107107

@@ -193,8 +193,8 @@ static const char PROGMEM ocean_bottom[8][32] = {
193193
// clang-format on
194194

195195
static void animate_waves(void) {
196-
starry_night_wave_frame_width_counter = decrement_counter(starry_night_wave_frame_width_counter, WIDTH - 1); // only 3 frames for last wave type
197-
rough_waves_frame_counter = increment_counter(rough_waves_frame_counter, 3); // only 3 frames for last wave type
196+
starry_night_wave_frame_width_counter = decrement_counter(starry_night_wave_frame_width_counter, WIDTH - 1); // only 3 frames for last wave type
197+
rough_waves_frame_counter = increment_counter(rough_waves_frame_counter, 3); // only 3 frames for last wave type
198198

199199
void draw_ocean(uint8_t frame, uint16_t offset, uint8_t byte_index) {
200200
oled_write_raw_byte(pgm_read_byte(ocean_top[frame] + byte_index), offset);
@@ -218,9 +218,9 @@ static void animate_waves(void) {
218218
}
219219
}
220220
}
221-
#endif // endregion
221+
#endif // endregion
222222

223-
#ifdef ENABLE_ISLAND // region
223+
#ifdef ENABLE_ISLAND // region
224224
uint8_t island_frame_1 = 0;
225225

226226
// clang-format off
@@ -276,17 +276,17 @@ static void animate_island(void) {
276276
draw_island_parts(island_frame_1 + 4);
277277
}
278278
}
279-
#endif // endregion
279+
#endif // endregion
280280

281-
#ifdef ENABLE_STARS // region
282-
bool stars_setup = false; // only setup stars once, then we just twinkle them
281+
#ifdef ENABLE_STARS // region
282+
bool stars_setup = false; // only setup stars once, then we just twinkle them
283283
struct Coordinate {
284284
int x;
285285
int y;
286286
bool exists;
287287
};
288288

289-
struct Coordinate stars[TOTAL_STARS]; // tracks all stars/coordinates
289+
struct Coordinate stars[TOTAL_STARS]; // tracks all stars/coordinates
290290

291291
/**
292292
* Setup all the initial stars on the screen
@@ -334,18 +334,18 @@ static void twinkle_stars(void) {
334334
continue;
335335
}
336336
if (rand() % TWINKLE_PROBABILITY_MODULATOR == 0) {
337-
oled_write_pixel(star.x, star.y, false); // black out pixel
337+
oled_write_pixel(star.x, star.y, false); // black out pixel
338338

339339
// don't allow stars to leave their own region
340-
if (star.x == (column_group * 8)) { // star is the farthest left it can go in its region
341-
star.x++; // move it right immediately
342-
} else if (star.x == (((column_group + 1) * 8) - 1)) { // star is farthest right it can go in its region
343-
star.x--; // move it left immediately
340+
if (star.x == (column_group * 8)) { // star is the farthest left it can go in its region
341+
star.x++; // move it right immediately
342+
} else if (star.x == (((column_group + 1) * 8) - 1)) { // star is farthest right it can go in its region
343+
star.x--; // move it left immediately
344344
}
345-
if (star.y == (line * 8)) { // star is the farthest up it can go in its region
346-
star.y++; // move it down immediately
347-
} else if (star.y == (((line + 1) * 8) - 1)) { // star is farthest down it can go in its region
348-
star.y--; // move it up immediately
345+
if (star.y == (line * 8)) { // star is the farthest up it can go in its region
346+
star.y++; // move it down immediately
347+
} else if (star.y == (((line + 1) * 8) - 1)) { // star is farthest down it can go in its region
348+
star.y--; // move it up immediately
349349
}
350350

351351
// now decide direction
@@ -389,10 +389,10 @@ static void animate_stars(void) {
389389
twinkle_stars();
390390
}
391391
}
392-
#endif // endregion
392+
#endif // endregion
393393

394-
#ifdef ENABLE_SHOOTING_STARS // region
395-
bool shooting_stars_setup = false; // only setup shooting stars array once with defaults
394+
#ifdef ENABLE_SHOOTING_STARS // region
395+
bool shooting_stars_setup = false; // only setup shooting stars array once with defaults
396396

397397
struct ShootingStar {
398398
int x_1;
@@ -404,11 +404,11 @@ struct ShootingStar {
404404
int delay;
405405
};
406406

407-
struct ShootingStar shooting_stars[MAX_NUMBER_OF_SHOOTING_STARS]; // tracks all the shooting stars
407+
struct ShootingStar shooting_stars[MAX_NUMBER_OF_SHOOTING_STARS]; // tracks all the shooting stars
408408

409409
static void setup_shooting_star(struct ShootingStar *shooting_star) {
410410
int column_to_start = rand() % (WIDTH / 2);
411-
int row_to_start = rand() % (HEIGHT - 48); // shooting_stars travel diagonally 1 down, 1 across. So the lowest a shooting_star can start and not 'hit' the ocean is 32 above the ocean.
411+
int row_to_start = rand() % (HEIGHT - 48); // shooting_stars travel diagonally 1 down, 1 across. So the lowest a shooting_star can start and not 'hit' the ocean is 32 above the ocean.
412412

413413
shooting_star->x_1 = column_to_start;
414414
shooting_star->y_1 = row_to_start;
@@ -494,60 +494,61 @@ static void animate_shooting_stars(void) {
494494
end_extra_stars(number_of_shooting_stars);
495495
}
496496
}
497-
#endif // endregion
497+
#endif // endregion
498498

499499
/**
500500
* Main rendering function
501501
*
502502
* Calls all different animations at different rates
503503
*/
504504
void render_stars(void) {
505-
// // animation timer
506-
if (timer_elapsed32(starry_night_anim_timer) > STARRY_NIGHT_ANIM_FRAME_DURATION) {
507-
starry_night_anim_timer = timer_read32();
508-
current_wpm = get_current_wpm();
505+
current_wpm = get_current_wpm();
509506

507+
void render_stars_anim(void) {
510508
#ifdef ENABLE_ISLAND
511-
animate_island();
509+
animate_island();
512510
#endif
513511

514512
#ifdef ENABLE_SHOOTING_STARS
515-
if (animation_counter % SHOOTING_STAR_ANIMATION_MODULATOR == 0) {
516-
animate_shooting_stars();
517-
}
513+
if (animation_counter % SHOOTING_STAR_ANIMATION_MODULATOR == 0) {
514+
animate_shooting_stars();
515+
}
518516
#endif
519517

520518
#ifdef ENABLE_STARS
521-
// TODO offsetting the star animation from the wave animation would look better,
522-
// but if I do that, then the stars appear in the water because
523-
// the ocean animation has to wait a bunch of frames to overwrite it.
524-
// Possible solutions:
525-
// 1. Only draw stars to the top of the island/ocean.
526-
// 2. Draw ocean every frame, only move ocean on frames matching modulus
527-
// Problems:
528-
// 1. What if someone wants to move the island up a bit, or they want to have the stars reflect in the water?
529-
// 2. More cpu intensive. And I'm already running out of cpu as it is...
530-
if (animation_counter % STAR_ANIMATION_MODULATOR == 0) {
531-
animate_stars();
532-
}
519+
// TODO offsetting the star animation from the wave animation would look better,
520+
// but if I do that, then the stars appear in the water because
521+
// the ocean animation has to wait a bunch of frames to overwrite it.
522+
// Possible solutions:
523+
// 1. Only draw stars to the top of the island/ocean.
524+
// 2. Draw ocean every frame, only move ocean on frames matching modulus
525+
// Problems:
526+
// 1. What if someone wants to move the island up a bit, or they want to have the stars reflect in the water?
527+
// 2. More cpu intensive. And I'm already running out of cpu as it is...
528+
if (animation_counter % STAR_ANIMATION_MODULATOR == 0) {
529+
animate_stars();
530+
}
533531
#endif
534532

535533
#ifdef ENABLE_WAVE
536-
if (animation_counter % OCEAN_ANIMATION_MODULATOR == 0) {
537-
animate_waves();
538-
}
534+
if (animation_counter % OCEAN_ANIMATION_MODULATOR == 0) {
535+
animate_waves();
536+
}
539537
#endif
540538

541539
#ifdef ENABLE_MOON
542-
draw_moon();
540+
draw_moon();
543541
#endif
544542

545-
animation_counter = increment_counter(animation_counter, NUMBER_OF_FRAMES);
543+
animation_counter = increment_counter(animation_counter, NUMBER_OF_FRAMES);
546544
}
547545

548-
// this fixes the screen on and off bug
549-
if (current_wpm > 0) {
546+
547+
// Turn screen on/off based on typing and timeout
548+
if (current_wpm > 0 && timer_elapsed32(starry_night_anim_timer) > STARRY_NIGHT_ANIM_FRAME_DURATION) {
549+
starry_night_anim_timer = timer_read32();
550550
oled_on();
551+
render_stars_anim();
551552
starry_night_anim_sleep = timer_read32();
552553
} else if (timer_elapsed32(starry_night_anim_sleep) > OLED_TIMEOUT) {
553554
oled_off();

0 commit comments

Comments
 (0)