mirror of
https://github.com/Rezmason/matrix.git
synced 2026-04-21 23:39:29 -07:00
Throwing some extra C compiler warnings into the CMakeLists. Found and dealt with some double-to-float conversions, cut CPU use down to about 10%.
This commit is contained in:
@@ -36,8 +36,11 @@ file(GLOB IMAGES
|
|||||||
|
|
||||||
if (TOOLCHAIN STREQUAL "armgcc")
|
if (TOOLCHAIN STREQUAL "armgcc")
|
||||||
add_executable(${PLAYDATE_GAME_DEVICE} ${SDK}/C_API/buildsupport/setup.c main.c)
|
add_executable(${PLAYDATE_GAME_DEVICE} ${SDK}/C_API/buildsupport/setup.c main.c)
|
||||||
|
target_compile_options(${PLAYDATE_GAME_DEVICE} PUBLIC -Wstrict-prototypes -Wdouble-promotion -Wall -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla )
|
||||||
else()
|
else()
|
||||||
add_library(${PLAYDATE_GAME_NAME} SHARED main.c ${IMAGES})
|
add_library(${PLAYDATE_GAME_NAME} SHARED main.c ${IMAGES})
|
||||||
|
target_compile_options(${PLAYDATE_GAME_NAME} PUBLIC -Wstrict-prototypes -Wdouble-promotion -Wall -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla )
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
include(${SDK}/C_API/buildsupport/playdate_game.cmake)
|
include(${SDK}/C_API/buildsupport/playdate_game.cmake)
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,9 @@
|
|||||||
// Matrix Effect
|
// Matrix Effect
|
||||||
//
|
//
|
||||||
// Created by Rezmason on 6/05/22.
|
// Created by Rezmason on 6/05/22.
|
||||||
// Read the LICENSE file if you want to
|
// Licensed under MIT. (See the LICENSE file.)
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include "pd_api.h"
|
#include "pd_api.h"
|
||||||
@@ -45,11 +44,11 @@ static float wobbleB;
|
|||||||
static LCDBitmap **glyphs = NULL;
|
static LCDBitmap **glyphs = NULL;
|
||||||
static Cell *cells = NULL;
|
static Cell *cells = NULL;
|
||||||
|
|
||||||
static float randf() {
|
static float randf(void) {
|
||||||
return (float)rand() / (float)(RAND_MAX);
|
return (float)rand() / (float)(RAND_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init()
|
static void init(void)
|
||||||
{
|
{
|
||||||
srand(pd->system->getSecondsSinceEpoch(NULL));
|
srand(pd->system->getSecondsSinceEpoch(NULL));
|
||||||
|
|
||||||
@@ -105,7 +104,7 @@ static void init()
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
for (int x = 0; x < numColumns; x++) {
|
for (int x = 0; x < numColumns; x++) {
|
||||||
float columnTimeOffset = randf() * 1000;
|
float columnTimeOffset = randf() * 1000;
|
||||||
float columnSpeedOffset = randf() * 0.5 + 0.5;
|
float columnSpeedOffset = randf() * 0.5f + 0.5f;
|
||||||
for (int y = 0; y < numRows; y++) {
|
for (int y = 0; y < numRows; y++) {
|
||||||
Cell *cell = &cells[i];
|
Cell *cell = &cells[i];
|
||||||
i++;
|
i++;
|
||||||
@@ -127,13 +126,13 @@ static int update(void* ud)
|
|||||||
{
|
{
|
||||||
float delta;
|
float delta;
|
||||||
if (pd->system->isCrankDocked()) {
|
if (pd->system->isCrankDocked()) {
|
||||||
speed += 0.07;
|
speed += 0.07f;
|
||||||
if (speed > maxSpeed) {
|
if (speed > maxSpeed) {
|
||||||
speed = maxSpeed;
|
speed = maxSpeed;
|
||||||
}
|
}
|
||||||
delta = pd->system->getElapsedTime() * speed;
|
delta = pd->system->getElapsedTime() * speed;
|
||||||
} else {
|
} else {
|
||||||
speed -= 0.07;
|
speed -= 0.07f;
|
||||||
if (speed < minSpeed) {
|
if (speed < minSpeed) {
|
||||||
speed = minSpeed;
|
speed = minSpeed;
|
||||||
}
|
}
|
||||||
@@ -150,11 +149,11 @@ static int update(void* ud)
|
|||||||
int mustDraw = 0;
|
int mustDraw = 0;
|
||||||
Cell *cell = &cells[i];
|
Cell *cell = &cells[i];
|
||||||
|
|
||||||
float cellTime = cell->y * -0.03 + cell->columnTimeOffset + time * cell->columnSpeedOffset;
|
float cellTime = cell->y * -0.03f + cell->columnTimeOffset + time * cell->columnSpeedOffset;
|
||||||
float brightness = 4 * fmod(
|
float brightness = 4 * fmodf(
|
||||||
cellTime
|
cellTime
|
||||||
+ 0.3 * sineTable[(int)(fmod(wobbleA * cellTime, 360))]
|
+ 0.3f * sineTable[(int)(fmodf(wobbleA * cellTime, 360))]
|
||||||
+ 0.2 * sineTable[(int)(fmod(wobbleB * cellTime, 360))],
|
+ 0.2f * sineTable[(int)(fmodf(wobbleB * cellTime, 360))],
|
||||||
1
|
1
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -168,7 +167,7 @@ static int update(void* ud)
|
|||||||
|
|
||||||
cell->glyphCycle = cell->glyphCycle + delta * 2;
|
cell->glyphCycle = cell->glyphCycle + delta * 2;
|
||||||
if (cell->glyphCycle > 1) {
|
if (cell->glyphCycle > 1) {
|
||||||
cell->glyphCycle = fmod(cell->glyphCycle, 1);
|
cell->glyphCycle = fmodf(cell->glyphCycle, 1);
|
||||||
int lastGlyphIndex = cell->glyphIndex;
|
int lastGlyphIndex = cell->glyphIndex;
|
||||||
while (cell->glyphIndex == lastGlyphIndex) {
|
while (cell->glyphIndex == lastGlyphIndex) {
|
||||||
cell->glyphIndex = rand();
|
cell->glyphIndex = rand();
|
||||||
|
|||||||
Reference in New Issue
Block a user