feat: major engine overhaul - scene demo with lighting, sphere, ground

- Scene Demo: cube + sphere + ground plane with proper lighting
- Audio: XAudio2 dynamic loading + WAV playback
- Physics: expanded collision system
- Renderer: improved pipeline with materials
- UI: extended widget system
- VisualScript: enhanced serializer + block interactions
- ASM: optimized math/memory/profiling routines
- Window: mouse input + scroll support
This commit is contained in:
shuiyu1123 committed 2026-07-12 08:21:07 +08:00
1 parent 2653926d85
commit 0669d102ce
35 files changed
+1844 -314

No files matched your search

+52 -4
View File
@@ -2,6 +2,10 @@
#include "block_core.h"
#include <stdlib.h>
#include <string.h>
#include <math.h>
// 5x7 位图字体 (列优先, LSB 在上)
#include "block_font.inc"
int block_renderer_init(BlockRenderer* renderer, void* device, void* context) {
memset(renderer, 0, sizeof(BlockRenderer));
@@ -94,10 +98,30 @@ void block_renderer_add_line(BlockRenderer* renderer, float x1, float y1, float
float dy = y2 - y1;
float len = sqrtf(dx * dx + dy * dy);
if (len < 0.001f) return;
float nx = -dy / len;
float ny = dx / len;
block_renderer_add_quad(renderer, x1, y1, x2 - x1, y2 - y1, r, g, b, a);
const float thickness = 1.0f;
float nx = -dy / len * thickness * 0.5f;
float ny = dx / len * thickness * 0.5f;
if (renderer->vertex_count + 4 > renderer->vertex_capacity) return;
if (renderer->index_count + 6 > renderer->index_capacity) return;
uint32_t base = renderer->vertex_count;
float* v = renderer->vertex_data + base * 7;
v[0*7+0] = x1 + nx; v[0*7+1] = y1 + ny; v[0*7+2] = 0; v[0*7+3] = r; v[0*7+4] = g; v[0*7+5] = b; v[0*7+6] = a;
v[1*7+0] = x2 + nx; v[1*7+1] = y2 + ny; v[1*7+2] = 0; v[1*7+3] = r; v[1*7+4] = g; v[1*7+5] = b; v[1*7+6] = a;
v[2*7+0] = x2 - nx; v[2*7+1] = y2 - ny; v[2*7+2] = 0; v[2*7+3] = r; v[2*7+4] = g; v[2*7+5] = b; v[2*7+6] = a;
v[3*7+0] = x1 - nx; v[3*7+1] = y1 - ny; v[3*7+2] = 0; v[3*7+3] = r; v[3*7+4] = g; v[3*7+5] = b; v[3*7+6] = a;
renderer->vertex_count += 4;
renderer->index_data[renderer->index_count++] = base + 0;
renderer->index_data[renderer->index_count++] = base + 1;
renderer->index_data[renderer->index_count++] = base + 2;
renderer->index_data[renderer->index_count++] = base + 0;
renderer->index_data[renderer->index_count++] = base + 2;
renderer->index_data[renderer->index_count++] = base + 3;
}
static void block_renderer_add_bezier(BlockRenderer* renderer, float x1, float y1, float cx1, float cy1, float cx2, float cy2, float x2, float y2, float r, float g, float b, float a) {
@@ -122,6 +146,10 @@ void block_renderer_draw_block(BlockRenderer* renderer, Block* block, float view
block_renderer_add_quad(renderer, x, y, w, h, 0.3f, 0.3f, 0.35f, 1.0f);
block_renderer_add_quad(renderer, x, y, w, 20 * zoom, 0.2f, 0.2f, 0.25f, 1.0f);
if (block->label[0]) {
block_renderer_draw_text(renderer, block->label, x + 4.0f * zoom, y + 4.0f * zoom, 0.9f, 0.9f, 0.9f);
}
}
void block_renderer_draw_connection(BlockRenderer* renderer, BlockSlot* from, BlockSlot* to, float view_x, float view_y, float zoom) {
@@ -138,5 +166,25 @@ void block_renderer_draw_connection(BlockRenderer* renderer, BlockSlot* from, Bl
void block_renderer_draw_text(BlockRenderer* renderer, const char* text, float x, float y, float r, float g, float b) {
if (!text) return;
(void)renderer; (void)x; (void)y; (void)r; (void)g; (void)b;
const float scale = 2.0f;
const float advance = 5.0f * scale + 1.0f;
float cx = x;
for (const char* p = text; *p; ++p) {
unsigned char ch = (unsigned char)*p;
if (ch < 32 || ch > 127) ch = '?';
int idx = ch - 32;
for (int col = 0; col < 5; ++col) {
uint8_t column = BLOCK_FONT[idx][col];
for (int row = 0; row < 7; ++row) {
if (column & (1u << row)) {
block_renderer_add_quad(renderer,
cx + col * scale,
y + row * scale,
scale, scale,
r, g, b, 1.0f);
}
}
}
cx += advance;
}
}