asfd
This commit is contained in:
Julia 2024-05-06 00:52:30 -05:00
parent 118e832a21
commit 24599197c0
12 changed files with 56 additions and 105 deletions

View file

@ -56,6 +56,8 @@
"stdlib.h": "c",
"stdio.h": "c",
"platform.h": "c",
"ringbuffer.h": "c"
"ringbuffer.h": "c",
"fumoengine.h": "c",
"fumocommon.h": "c"
}
}

View file

@ -6,6 +6,10 @@
#define ONE_E_9 1000000000
typedef size_t usize;
typedef ptrdiff_t isize;
typedef uint8_t u8;
typedef uint_fast8_t u8f;
@ -22,14 +26,14 @@ typedef uint_fast64_t u64f;
typedef int8_t i8;
typedef int_fast8_t i8f;
typedef int16_t i16;
typedef int_fast16_t i16f;
typedef int16_t i16;
typedef int_fast16_t i16f;
typedef int32_t i32;
typedef int_fast32_t i32f;
typedef int32_t i32;
typedef int_fast32_t i32f;
typedef int64_t i64;
typedef int_fast64_t i64f;
typedef int64_t i64;
typedef int_fast64_t i64f;
typedef u64 Time;

View file

@ -2,7 +2,7 @@
#include "platform.h"
void ErrorExit(char *message)
void Panic(char *message)
{
printf(message);
exit(1);
@ -11,16 +11,16 @@ void ErrorExit(char *message)
bool FumoInit(struct FumoGame *game)
{
if (!PlatformInit())
ErrorExit("Platform failed to initialize");
Panic("Platform failed to initialize");
if (!CreateController(&game->ctrl))
ErrorExit("Out of memory");
Panic("Out of memory");
if (!CreateEvent(&game->update))
ErrorExit("Out of memory");
Panic("Out of memory");
if (!BeginInputThread(&game->input_hand))
ErrorExit("Input handle failed to initialize");
Panic("Input handle failed to initialize");
return 0;
}

View file

@ -17,7 +17,7 @@ struct FumoGame {
};
void ErrorExit(char *message);
void Panic(char *message);
bool FumoInit(struct FumoGame *game);

View file

@ -1,5 +1,6 @@
#pragma once
#include <iso646.h>
#include <stdalign.h>
#include <stdbool.h>
#include <stdint.h>
@ -19,7 +20,10 @@ struct RingBufferHead {
#define RINGBUF_T_INIT(RBUF_STRUCT, RBUF_ITEM, RBUF_LEN) \
(&(struct RingBufferT) { \
.OFFSET = offsetof(RBUF_STRUCT, buf), \
.OFFSET = offsetof(struct { \
struct RingBufferHead head; \
RBUF_ITEM item; \
}, item), \
.SIZE = sizeof(RBUF_ITEM), \
.LEN = RBUF_LEN \
}) \

View file

@ -146,13 +146,14 @@ void dispatch_update(struct InputAxis *axis, struct InputRecord *rec)
void ControllerPoll(struct Controller *ctrl, struct RecordBuffer *recs)
{
/*for (size_t i = 0; i < ctrl->pending_buf.len; i++) {
for (size_t i = 0; i < ctrl->pending_buf.len; i++) {
struct InputAxis *axis = ctrl->pending_buf.axes[i];
axis->is_up = false;
axis->is_down = false;
}
ctrl->pending_buf.len = 0;*/
ctrl->pending_buf.len = 0;
for (size_t i = 0; i < recs->head.len; i++) {
struct InputRecord *rec = &recs->buf[i];

View file

@ -161,7 +161,7 @@ bool dispatch_rec(
size_t read_input(struct win_rec *buf, size_t n)
{
DWORD len;
if (!ReadConsoleInputW(win.input_hand, buf, n, &len))
if (!ReadConsoleInputW(win.input_hand, (INPUT_RECORD *)buf, n, &len))
return 0;
return len;

View file

@ -1,30 +1,5 @@
#include <iso646.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "term.h"
#include "fumocommon.h"
struct TChar4 {
char ch;
u8 bg : 4;
u8 fg : 4;
};
struct Terminal {
size_t wid;
size_t hgt;
size_t area;
struct TChar4 *blks;
size_t buf_size;
char *buf;
u16f refresh_rate;
};
size_t term_buf_size(size_t area, size_t hgt)
{
@ -34,61 +9,30 @@ size_t term_buf_size(size_t area, size_t hgt)
return reset_str_len + (max_color_str_len + 1) * area + hgt + 1;
}
struct TChar4 *alloc_blks(size_t area)
{
return calloc(area, sizeof(struct TChar4));
}
char *alloc_buf(size_t buf_size)
{
return malloc(buf_size);
}
bool NewTerm(struct Terminal *term, size_t wid, size_t hgt)
bool CreateTerminal(struct Terminal *term, size_t wid, size_t hgt)
{
size_t area = wid * hgt;
size_t buf_size = term_buf_size(area, hgt);
struct TChar4 *blks = alloc_blks(area);
char *buf = alloc_buf(buf_size);
struct Char4 *chs = calloc(area, sizeof(struct Char4));
if (blks == nullptr or buf == nullptr)
if (chs == nullptr)
return false;
*term = (struct Terminal) {
.wid = wid,
.hgt = hgt,
.area = area,
.blks = blks,
.buf_size = buf_size,
.buf = buf,
.refresh_rate = 60,
.chs = chs,
};
return true;
}
bool ResizeTerm(struct Terminal *term, size_t wid, size_t hgt)
void FreeTerminal(struct Terminal *term)
{
size_t area = wid * hgt;
size_t buf_size = term_buf_size(area, hgt);
struct TChar4 *tchs = realloc(term->blks, area * sizeof(struct TChar4));
char *buf = realloc(term->buf, buf_size);
if (tchs == nullptr or buf == nullptr)
return false;
term->blks = tchs;
term->buf = buf;
return true;
}
void FreeTerm(struct Terminal *term)
{
free(term->blks);
free(term->buf);
free(term->chs);
}
size_t u8_to_buf(char *buf, u8f x)
@ -124,7 +68,7 @@ size_t u8_to_buf(char *buf, u8f x)
return len;
}
size_t tch4_dif_to_buf(char *buf, struct TChar4 *dif, struct TChar4 *blk)
size_t ch4_dif_to_buf(char *buf, struct Char4 *dif, struct Char4 *blk)
{
size_t len = 0;
@ -159,9 +103,9 @@ size_t tch4_dif_to_buf(char *buf, struct TChar4 *dif, struct TChar4 *blk)
return len;
}
size_t TermOut(struct Terminal *term)
size_t TerminalPrint(char *dest, size_t n, struct Terminal *term)
{
struct TChar4 dif;
struct Char4 dif;
size_t len = 7;
memcpy(term->buf, "\x1b[H\x1b[0m", 7);
@ -169,14 +113,14 @@ size_t TermOut(struct Terminal *term)
for (size_t y = 0; y < term->hgt; y++) {
for (size_t x = 0; x < term->wid; x++) {
size_t i = y * term->wid + x;
struct TChar4 *blk = &term->blks[i];
struct Char4 *blk = &term->chs[i];
// DEBUG
if (blk->ch == 0)
blk->ch = '#';
// DEBUG
len += tch4_dif_to_buf(term->buf + len, &dif, blk);
len += ch4_dif_to_buf(term->buf + len, &dif, blk);
}
term->buf[len++] = '\n';
}

View file

@ -1,16 +1,14 @@
#pragma once
#include <iso646.h>
#include <pthread.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "fumocommon.h"
struct TChar4 {
struct Char4 {
char ch;
u8 bg : 4;
u8 fg : 4;
@ -20,18 +18,12 @@ struct Terminal {
size_t wid;
size_t hgt;
size_t area;
struct TChar4 *blks;
size_t buf_size;
char *buf;
u16f refresh_rate;
struct Char4 *chs;
};
bool NewTerm(struct Terminal *term, size_t wid, size_t hgt);
bool CreateTerminal(struct Terminal *term, size_t wid, size_t hgt);
bool ResizeTerm(struct Terminal *term, size_t wid, size_t hgt);
void FreeTerminal(struct Terminal *term);
void FreeTerm(struct Terminal *term);
size_t TermOut(struct Terminal *term);
size_t TerminalPrint(char *dest, size_t n, struct Terminal *term);

View file

@ -40,14 +40,18 @@ void Loop(struct FumoGame *game)
game->time = TimeNow();
if (!InputAquire(&game->input_hand))
ErrorExit("Aquire failed");
Panic("Aquire failed");
//ControllerPoll(&game->ctrl, &game->input_hand.recs);
ControllerPoll(&game->ctrl, &game->input_hand.recs);
u64 val = ControllerGet(&game->ctrl, LEFT, BUTTON)->is_down;
printf("%u\n", val);
if (!InputRelease(&game->input_hand))
ErrorExit("Release failed");
Panic("Release failed");
//EventInvokeUpdate(&game->update, 0);
EventInvokeUpdate(&game->update, 0);
_sleep(100);
}
}

View file

@ -43,8 +43,8 @@ void TetrMapToTermBuf(struct TetrMap *map, struct Terminal *term)
size_t map_i = y * map->wid + x;
size_t buf_i = (y + map->y) * term->wid + (x + map->x) * 2;
struct TChar4 *a = &term->blks[buf_i];
struct TChar4 *b = &term->blks[buf_i + 1];
struct Char4 *a = &term->chs[buf_i];
struct Char4 *b = &term->chs[buf_i + 1];
if (map->blks[map_i] == 0) {
a->ch = '(';

BIN
test.exe

Binary file not shown.