mirror of
https://github.com/thepigeongenerator/tetris_clone.git
synced 2025-12-17 14:05:45 +01:00
refactor comments
This commit is contained in:
@@ -8,7 +8,8 @@
|
|||||||
#include "../util/types.h"
|
#include "../util/types.h"
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
|
||||||
/* processes an incoming scancode, returns the associated movement data, or performs the close action directly */
|
/* processes an incoming scancode, returns the associated movement data, or performs the close action directly
|
||||||
|
* NOTE: if the action is mapped to multiple keys, pressing both and then releasing one, disables the action. Minor issue, won't fix. */
|
||||||
__attribute__((const)) static int procscancode(SDL_Scancode code) {
|
__attribute__((const)) static int procscancode(SDL_Scancode code) {
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case SDL_SCANCODE_Q:
|
case SDL_SCANCODE_Q:
|
||||||
@@ -43,17 +44,18 @@ __attribute__((const)) static int procscancode(SDL_Scancode code) {
|
|||||||
static int timeout_mask(time_t time) {
|
static int timeout_mask(time_t time) {
|
||||||
static time_t timeout = 0, timeout_roll = 0;
|
static time_t timeout = 0, timeout_roll = 0;
|
||||||
int msk = 0;
|
int msk = 0;
|
||||||
|
// only add to the mask if time_poll returns `1`, negating becomes `-1`; 0b1111...
|
||||||
|
// this is masked with the desired movement action.
|
||||||
msk |= ((MOVR | MOVL | MOVD) & -!!time_poll(time, 64, &timeout));
|
msk |= ((MOVR | MOVL | MOVD) & -!!time_poll(time, 64, &timeout));
|
||||||
msk |= ((MOVRL | MOVRR) & -!!time_poll(time, 100, &timeout_roll));
|
msk |= ((MOVRL | MOVRR) & -!!time_poll(time, 100, &timeout_roll));
|
||||||
return msk;
|
return msk;
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: if an action is mapped to multiple keys, pressing both and releasing one will cause the action to be disabled. Minor issue, Won't fix.
|
|
||||||
int input_getdat(time_t time) {
|
int input_getdat(time_t time) {
|
||||||
static u8 movdat = 0, nmovdat = 0, lmovdat = 0;
|
static u8 movdat = 0, nmovdat = 0, lmovdat = 0; // stores the static movement data
|
||||||
int mov = movdat, nmov = nmovdat, lmov = lmovdat;
|
int mov = movdat, nmov = nmovdat, lmov = lmovdat; // stores the runtime movement data for easy register access
|
||||||
|
|
||||||
// process the event
|
// process the events
|
||||||
SDL_Event e;
|
SDL_Event e;
|
||||||
while (SDL_PollEvent(&e)) {
|
while (SDL_PollEvent(&e)) {
|
||||||
switch (e.type) {
|
switch (e.type) {
|
||||||
@@ -68,8 +70,8 @@ int input_getdat(time_t time) {
|
|||||||
|
|
||||||
// handle releasing of keys
|
// handle releasing of keys
|
||||||
mov &= ~(nmov & lmov & mask); // only remove the keys that have been pressed since lmov
|
mov &= ~(nmov & lmov & mask); // only remove the keys that have been pressed since lmov
|
||||||
lmov = mov;
|
lmov = mov; // set the value of lmov to the new value mov
|
||||||
nmov &= mov;
|
nmov &= mov; // set nmov to only those in mov
|
||||||
int cmov = mov & mask;
|
int cmov = mov & mask;
|
||||||
|
|
||||||
// write to static variables (shrinking the values, and memory usage)
|
// write to static variables (shrinking the values, and memory usage)
|
||||||
|
|||||||
Reference in New Issue
Block a user