Kore Update

This commit is contained in:
Gorochu
2026-06-09 12:45:01 -07:00
parent a2d5c9aea4
commit 7558d03739
371 changed files with 30188 additions and 7466 deletions

View File

@ -6,7 +6,6 @@
#include <stdio.h>
#include <stdlib.h>
static void (*a2_callback)(kinc_a2_buffer_t *buffer, int samples) = NULL;
static kinc_a2_buffer_t a2_buffer;
static ALCdevice *device = NULL;
@ -21,35 +20,40 @@ static bool audioRunning = false;
static short buf[BUFSIZE];
#define NUM_BUFFERS 3
static uint32_t samples_per_second = 44100;
static void copySample(void *buffer) {
float value = *(float *)&a2_buffer.data[a2_buffer.read_location];
a2_buffer.read_location += 4;
float left_value = *(float *)&a2_buffer.channels[0][a2_buffer.read_location];
float right_value = *(float *)&a2_buffer.channels[1][a2_buffer.read_location];
a2_buffer.read_location += 1;
if (a2_buffer.read_location >= a2_buffer.data_size) {
a2_buffer.read_location = 0;
}
*(int16_t *)buffer = (int16_t)(value * 32767);
((int16_t *)buffer)[0] = (int16_t)(left_value * 32767);
((int16_t *)buffer)[1] = (int16_t)(right_value * 32767);
}
static void streamBuffer(ALuint buffer) {
if (a2_callback != NULL) {
a2_callback(&a2_buffer, BUFSIZE);
for (int i = 0; i < BUFSIZE; ++i) {
if (kinc_a2_internal_callback(&a2_buffer, BUFSIZE / 2)) {
for (int i = 0; i < BUFSIZE; i += 2) {
copySample(&buf[i]);
}
}
alBufferData(buffer, format, buf, BUFSIZE * 2, 44100);
alBufferData(buffer, format, buf, BUFSIZE * 2, samples_per_second);
}
static void iter() {
if (!audioRunning)
if (!audioRunning) {
return;
}
ALint processed;
alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed);
if (processed <= 0)
if (processed <= 0) {
return;
}
while (processed--) {
ALuint buffer;
alSourceUnqueueBuffers(source, 1, &buffer);
@ -71,12 +75,15 @@ void kinc_a2_init() {
return;
}
kinc_a2_internal_init();
a2_initialized = true;
a2_buffer.read_location = 0;
a2_buffer.write_location = 0;
a2_buffer.data_size = 128 * 1024;
a2_buffer.data = malloc(a2_buffer.data_size);
a2_buffer.channel_count = 2;
a2_buffer.channels[0] = (float *)malloc(a2_buffer.data_size * sizeof(float));
a2_buffer.channels[1] = (float *)malloc(a2_buffer.data_size * sizeof(float));
audioRunning = true;
@ -106,6 +113,6 @@ void kinc_a2_shutdown() {
audioRunning = false;
}
void kinc_a2_set_callback(void (*kinc_a2_audio_callback)(kinc_a2_buffer_t *buffer, int samples)) {
a2_callback = kinc_a2_audio_callback;
uint32_t kinc_a2_samples_per_second(void) {
return samples_per_second;
}

View File

@ -0,0 +1,15 @@
#include <kinc/input/gamepad.h>
const char *kinc_gamepad_vendor(int gamepad) {
return "None";
}
const char *kinc_gamepad_product_name(int gamepad) {
return "Gamepad";
}
bool kinc_gamepad_connected(int gamepad) {
return false;
}
void kinc_gamepad_rumble(int gamepad, float left, float right) {}

View File

@ -1,6 +1,7 @@
#include "audio.c.h"
#include "display.c.h"
#include "event.c.h"
#include "gamepad.c.h"
#include "mouse.c.h"
#include "mutex.c.h"
#include "semaphore.c.h"

View File

@ -1,4 +1,4 @@
#ifdef KORE_OPENGL
#ifdef KINC_OPENGL
#include <GL/glfw.h>
#endif
@ -22,7 +22,7 @@ static void drawfunc() {
return;
kinc_internal_update_callback();
kinc_a2_update();
#ifdef KORE_OPENGL
#ifdef KINC_OPENGL
glfwSwapBuffers();
#endif
}
@ -37,7 +37,7 @@ static void drawfunc() {
kinc_internal_keyboard_trigger_key_up(KINC_KEY); \
break;
#ifdef KORE_OPENGL
#ifdef KINC_OPENGL
// glfw mappings as state here: https://www.glfw.org/docs/3.3/group__keys.html
static void onKeyPressed(int key, int action) {
if (action == GLFW_PRESS) {
@ -250,10 +250,6 @@ static int with, height;
extern int kinc_internal_window_width;
extern int kinc_internal_window_height;
#ifdef KINC_KONG
void kong_init(void);
#endif
int kinc_init(const char *name, int width, int height, kinc_window_options_t *win, kinc_framebuffer_options_t *frame) {
kinc_window_options_t defaultWin;
if (win == NULL) {
@ -268,7 +264,7 @@ int kinc_init(const char *name, int width, int height, kinc_window_options_t *wi
win->width = width;
win->height = height;
#ifdef KORE_OPENGL
#ifdef KINC_OPENGL
glfwInit();
glfwOpenWindow(width, height, 8, 8, 8, 0, frame->depth_bits, frame->stencil_bits, GLFW_WINDOW);
glfwSetWindowTitle(name);
@ -281,10 +277,6 @@ int kinc_init(const char *name, int width, int height, kinc_window_options_t *wi
kinc_g4_internal_init();
kinc_g4_internal_init_window(0, frame->depth_bits, frame->stencil_bits, true);
#ifdef KINC_KONG
kong_init();
#endif
return 0;
}
@ -299,7 +291,7 @@ double kinc_frequency(void) {
}
kinc_ticks_t kinc_timestamp(void) {
#ifdef KORE_OPENGL
#ifdef KINC_OPENGL
return (kinc_ticks_t)(glfwGetTime() * 1000.0);
#else
return (kinc_ticks_t)(0.0);
@ -307,7 +299,7 @@ kinc_ticks_t kinc_timestamp(void) {
}
double kinc_time(void) {
#ifdef KORE_OPENGL
#ifdef KINC_OPENGL
return glfwGetTime();
#else
return 0.0;
@ -324,7 +316,7 @@ int kinc_hardware_threads(void) {
extern int kickstart(int argc, char **argv);
#ifdef KORE_WEBGPU
#ifdef KINC_WEBGPU
EMSCRIPTEN_KEEPALIVE void kinc_internal_webgpu_initialized() {
kickstart(html5_argc, html5_argv);
initialized = true;
@ -334,7 +326,7 @@ EMSCRIPTEN_KEEPALIVE void kinc_internal_webgpu_initialized() {
int main(int argc, char **argv) {
html5_argc = argc;
html5_argv = argv;
#ifdef KORE_WEBGPU
#ifdef KINC_WEBGPU
char *code = "(async () => {\
const adapter = await navigator.gpu.requestAdapter();\
const device = await adapter.requestDevice();\

View File

@ -46,8 +46,10 @@ void kinc_internal_video_sound_stream_destroy(kinc_internal_video_sound_stream_t
void kinc_internal_video_sound_stream_insert_data(kinc_internal_video_sound_stream_t *stream, float *data, int sample_count) {}
float kinc_internal_video_sound_stream_next_sample(kinc_internal_video_sound_stream_t *stream) {
return 0.0f;
float samples[2] = {0};
float *kinc_internal_video_sound_stream_next_frame(kinc_internal_video_sound_stream_t *stream) {
return samples;
}
bool kinc_internal_video_sound_stream_ended(kinc_internal_video_sound_stream_t *stream) {

View File

@ -18,7 +18,7 @@ void kinc_internal_video_sound_stream_destroy(kinc_internal_video_sound_stream_t
void kinc_internal_video_sound_stream_insert_data(kinc_internal_video_sound_stream_t *stream, float *data, int sample_count);
float kinc_internal_video_sound_stream_next_sample(kinc_internal_video_sound_stream_t *stream);
float *kinc_internal_video_sound_stream_next_frame(kinc_internal_video_sound_stream_t *stream);
bool kinc_internal_video_sound_stream_ended(kinc_internal_video_sound_stream_t *stream);