sync: user's Lity3D_source.zip changes
- Engine core: improved initialization and lifecycle - Renderer: camera and rendering pipeline updates - Editor: updated editor code - Window: improved window handling - Demo/main.c: scene demo with AssetManager + scene loading - build.bat: updated build script - 11 files modified from user's manual edits
This commit is contained in:
1 parent
0669d102ce
commit
7a0533d21a
11 files changed
+707
-378
No files matched your search
+637
-346
File diff suppressed because it is too large.
Load diff
+1
-1
@@ -163,7 +163,7 @@ int main(int argc, char* argv[]) {
|
||||
(void)argc; (void)argv;
|
||||
|
||||
EngineConfig config = engine_default_config();
|
||||
config.app_name = "MiMo Engine - Scene Demo";
|
||||
config.app_name = "Lity3D - Scene Demo";
|
||||
config.vsync = 0;
|
||||
config.window_width = 1280;
|
||||
config.window_height = 720;
|
||||
|
||||
@@ -68,7 +68,7 @@ int engine_init(Engine* engine, const EngineConfig* config) {
|
||||
|
||||
// 初始化日志
|
||||
logger_init("engine.log");
|
||||
LOG_INFO("Initializing MiMo Engine ASM...");
|
||||
LOG_INFO("Initializing Lity3D Engine...");
|
||||
|
||||
// 初始化计时器
|
||||
timer_init();
|
||||
@@ -124,7 +124,7 @@ int engine_init(Engine* engine, const EngineConfig* config) {
|
||||
engine->running = 1;
|
||||
engine->frame_count = 0;
|
||||
|
||||
LOG_INFO("MiMo Engine ASM initialized successfully.");
|
||||
LOG_INFO("Lity3D Engine initialized successfully.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ void engine_run(Engine* engine) {
|
||||
void engine_shutdown(Engine* engine) {
|
||||
if (!engine->initialized) return;
|
||||
|
||||
LOG_INFO("Shutting down MiMo Engine ASM...");
|
||||
LOG_INFO("Shutting down Lity3D Engine...");
|
||||
|
||||
if (engine->renderer) {
|
||||
renderer_destroy(engine->renderer);
|
||||
|
||||
@@ -37,7 +37,7 @@ typedef struct {
|
||||
// 初始化默认配置
|
||||
static inline EngineConfig engine_default_config(void) {
|
||||
EngineConfig config;
|
||||
config.app_name = "MiMo Engine ASM";
|
||||
config.app_name = "Lity3D Engine";
|
||||
config.window_width = 1280;
|
||||
config.window_height = 720;
|
||||
config.fullscreen = 0;
|
||||
|
||||
@@ -19,11 +19,11 @@ void logger_init(const char* log_file) {
|
||||
if (log_file) {
|
||||
g_log_file = fopen(log_file, "w");
|
||||
if (g_log_file) {
|
||||
fprintf(g_log_file, "=== MiMo Engine ASM Log ===\n");
|
||||
fprintf(g_log_file, "=== Lity3D Engine Log ===\n");
|
||||
fflush(g_log_file);
|
||||
}
|
||||
}
|
||||
printf("=== MiMo Engine ASM Log ===\n");
|
||||
printf("=== Lity3D Engine Log ===\n");
|
||||
}
|
||||
|
||||
void logger_shutdown(void) {
|
||||
|
||||
@@ -59,7 +59,7 @@ void editor_render(Editor* ed) {
|
||||
uilayer_flush(&ed->ui, ctx);
|
||||
|
||||
float sw2 = sw, sh2 = sh;
|
||||
bitmap_font_draw(&ed->font, ctx, "MiMo Engine Editor", 10, 6,
|
||||
bitmap_font_draw(&ed->font, ctx, "Lity3D Engine Editor", 10, 6,
|
||||
0.4f, 0.75f, 1.0f, 1.0f, sw2, sh2);
|
||||
|
||||
const char* menu[] = {"File", "Edit", "View", "Build", "Help"};
|
||||
|
||||
@@ -72,7 +72,7 @@ void camera_move_right(Camera* camera, float distance) {
|
||||
Vec3 forward, right;
|
||||
vec3_sub(&camera->target, &camera->position, &forward);
|
||||
vec3_normalize(&forward, &forward);
|
||||
vec3_cross(&forward, &camera->up, &right);
|
||||
vec3_cross(&camera->up, &forward, &right);
|
||||
vec3_normalize(&right, &right);
|
||||
Vec3 move;
|
||||
vec3_scale(&right, distance, &move);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "renderer.h"
|
||||
#include "../Core/logger.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -22,6 +23,8 @@ Renderer* renderer_create(GraphicsDevice* device) {
|
||||
r->light_dir = (Vec3){0.5f, -1.0f, 0.3f};
|
||||
r->light_color = (Vec4){1,1,1,1};
|
||||
r->ambient_color = (Vec4){0.2f,0.2f,0.3f,1};
|
||||
r->clear_color[0] = 0.1f; r->clear_color[1] = 0.1f;
|
||||
r->clear_color[2] = 0.15f; r->clear_color[3] = 1.0f;
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -29,7 +32,7 @@ void renderer_destroy(Renderer* r) { free(r); }
|
||||
|
||||
void renderer_begin_frame(Renderer* r) {
|
||||
ID3D11DeviceContext* ctx = r->device->context;
|
||||
graphics_device_clear(r->device, 0.1f, 0.1f, 0.15f, 1.0f);
|
||||
graphics_device_clear(r->device, r->clear_color[0], r->clear_color[1], r->clear_color[2], r->clear_color[3]);
|
||||
D3D11_VIEWPORT vp = {0};
|
||||
vp.Width = (float)r->device->width;
|
||||
vp.Height = (float)r->device->height;
|
||||
@@ -43,17 +46,15 @@ void renderer_end_frame(Renderer* r) {
|
||||
}
|
||||
|
||||
void renderer_draw_mesh(Renderer* r, Mesh* m) {
|
||||
if (!m) return;
|
||||
if (!r || !m || m->icount == 0) return;
|
||||
if (!m->vb) { LOG_ERROR("renderer_draw_mesh: null vertex buffer"); return; }
|
||||
if (!m->ib) { LOG_ERROR("renderer_draw_mesh: null index buffer"); return; }
|
||||
ID3D11DeviceContext* ctx = r->device->context;
|
||||
UINT stride = sizeof(Vertex);
|
||||
UINT offset = 0;
|
||||
ctx->lpVtbl->IASetVertexBuffers(ctx, 0, 1, &m->vb, &stride, &offset);
|
||||
if (m->ib) {
|
||||
ctx->lpVtbl->IASetIndexBuffer(ctx, m->ib, DXGI_FORMAT_R32_UINT, 0);
|
||||
ctx->lpVtbl->DrawIndexed(ctx, m->icount, 0, 0);
|
||||
} else {
|
||||
ctx->lpVtbl->Draw(ctx, m->vcount, 0);
|
||||
}
|
||||
ctx->lpVtbl->IASetIndexBuffer(ctx, m->ib, DXGI_FORMAT_R32_UINT, 0);
|
||||
ctx->lpVtbl->DrawIndexed(ctx, m->icount, 0, 0);
|
||||
}
|
||||
|
||||
void renderer_draw_mesh_with_shader(Renderer* r, Mesh* m, Shader* s, const Mat4* world, Texture* t) {
|
||||
@@ -98,8 +99,18 @@ void renderer_draw_mesh_with_material(Renderer* r, Mesh* m, Material* mat, const
|
||||
void renderer_set_view(Renderer* r, const Mat4* v) { r->view = *v; }
|
||||
void renderer_set_projection(Renderer* r, const Mat4* p) { r->projection = *p; }
|
||||
void renderer_set_light(Renderer* r, Vec3 d, Vec4 c, Vec4 a) { r->light_dir=d; r->light_color=c; r->ambient_color=a; }
|
||||
void renderer_set_clear_color(Renderer* r, float rc, float g, float b, float a) {
|
||||
if (!r) return;
|
||||
r->clear_color[0] = rc; r->clear_color[1] = g;
|
||||
r->clear_color[2] = b; r->clear_color[3] = a;
|
||||
}
|
||||
GraphicsDevice* renderer_get_device(Renderer* r) { return r ? r->device : NULL; }
|
||||
|
||||
void renderer_get_view_projection(const Renderer* r, Mat4* out) {
|
||||
if (!r || !out) return;
|
||||
mat4_multiply(&r->view, &r->projection, out);
|
||||
}
|
||||
|
||||
void renderer_resize(Renderer* r, int width, int height) {
|
||||
if (r && r->device && width > 0 && height > 0) {
|
||||
graphics_device_resize(r->device, width, height);
|
||||
|
||||
@@ -17,6 +17,7 @@ struct Renderer {
|
||||
Vec3 light_dir;
|
||||
Vec4 light_color;
|
||||
Vec4 ambient_color;
|
||||
float clear_color[4];
|
||||
};
|
||||
|
||||
Renderer* renderer_create(GraphicsDevice* device);
|
||||
@@ -29,5 +30,7 @@ void renderer_draw_mesh_with_material(Renderer* renderer, Mesh* mesh, Material*
|
||||
void renderer_set_view(Renderer* renderer, const Mat4* view);
|
||||
void renderer_set_projection(Renderer* renderer, const Mat4* projection);
|
||||
void renderer_set_light(Renderer* renderer, Vec3 dir, Vec4 color, Vec4 ambient);
|
||||
void renderer_set_clear_color(Renderer* renderer, float r, float g, float b, float a);
|
||||
GraphicsDevice* renderer_get_device(Renderer* renderer);
|
||||
void renderer_resize(Renderer* renderer, int width, int height);
|
||||
void renderer_get_view_projection(const Renderer* renderer, Mat4* out);
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <string.h>
|
||||
|
||||
// 窗口类名
|
||||
static const wchar_t* WINDOW_CLASS = L"MiMoEngineWindow";
|
||||
static const wchar_t* WINDOW_CLASS = L"Lity3DEngineWindow";
|
||||
|
||||
// 全局回调
|
||||
static WindowKeyCallback g_key_callback = NULL;
|
||||
@@ -58,22 +58,28 @@ static LRESULT CALLBACK window_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM l
|
||||
return 0;
|
||||
|
||||
case WM_LBUTTONDOWN:
|
||||
SetCapture(hwnd);
|
||||
if (g_mouse_button_callback) g_mouse_button_callback(0, 1);
|
||||
return 0;
|
||||
case WM_RBUTTONDOWN:
|
||||
SetCapture(hwnd);
|
||||
if (g_mouse_button_callback) g_mouse_button_callback(1, 1);
|
||||
return 0;
|
||||
case WM_MBUTTONDOWN:
|
||||
SetCapture(hwnd);
|
||||
if (g_mouse_button_callback) g_mouse_button_callback(2, 1);
|
||||
return 0;
|
||||
|
||||
case WM_LBUTTONUP:
|
||||
if (GetCapture() == hwnd) ReleaseCapture();
|
||||
if (g_mouse_button_callback) g_mouse_button_callback(0, 0);
|
||||
return 0;
|
||||
case WM_RBUTTONUP:
|
||||
if (GetCapture() == hwnd) ReleaseCapture();
|
||||
if (g_mouse_button_callback) g_mouse_button_callback(1, 0);
|
||||
return 0;
|
||||
case WM_MBUTTONUP:
|
||||
if (GetCapture() == hwnd) ReleaseCapture();
|
||||
if (g_mouse_button_callback) g_mouse_button_callback(2, 0);
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -9,12 +9,12 @@ set GXX=%MINGW%\g++.exe
|
||||
|
||||
set ENGINE_DIR=Engine
|
||||
set DEMO_DIR=Demo
|
||||
set OUTPUT=MiMoEngine_ASM.exe
|
||||
set OUTPUT=Lity3D.exe
|
||||
|
||||
set CFLAGS=-O2 -Wall -Wextra -DWIN32_LEAN_AND_MEAN -D_CRT_SECURE_NO_WARNINGS -DMATH_ASM_AVAILABLE=0 -I%ENGINE_DIR% -I%ENGINE_DIR%\include
|
||||
set LDFLAGS=-ld3d11 -ldxgi -ld3dcompiler -lole32 -loleaut32 -luuid -lgdi32 -luser32 -lkernel32 -lwinmm -lxinput1_4 -lwindowscodecs -static
|
||||
|
||||
echo === MiMoEngine ASM Build ===
|
||||
echo === Lity3DEngine ASM Build ===
|
||||
echo Compiler: %GCC%
|
||||
|
||||
REM 创建输出目录并清理旧对象
|
||||
@@ -30,11 +30,15 @@ echo [1/3] Compiling Engine sources...
|
||||
%GCC% %CFLAGS% -c %ENGINE_DIR%\Window\window.c -o build\window.o
|
||||
%GCC% %CFLAGS% -c %ENGINE_DIR%\Rendering\graphics_device.c -o build\graphics_device.o
|
||||
%GCC% %CFLAGS% -c %ENGINE_DIR%\Rendering\renderer.c -o build\renderer.o
|
||||
%GCC% %CFLAGS% -c %ENGINE_DIR%\Rendering\frustum.c -o build\frustum.o
|
||||
%GCC% %CFLAGS% -c %ENGINE_DIR%\Rendering\shader.c -o build\shader.o
|
||||
%GCC% %CFLAGS% -c %ENGINE_DIR%\Rendering\mesh.c -o build\mesh.o
|
||||
%GCC% %CFLAGS% -c %ENGINE_DIR%\Rendering\texture.c -o build\texture.o
|
||||
%GCC% %CFLAGS% -c %ENGINE_DIR%\Rendering\material.c -o build\material.o
|
||||
%GCC% %CFLAGS% -c %ENGINE_DIR%\Rendering\camera.c -o build\camera.o
|
||||
%GCC% %CFLAGS% -c %ENGINE_DIR%\Rendering\camera_controller.c -o build\camera_controller.o
|
||||
%GCC% %CFLAGS% -c %ENGINE_DIR%\Terrain\terrain.c -o build\terrain.o
|
||||
%GCC% %CFLAGS% -c %ENGINE_DIR%\Terrain\terrain_manager.c -o build\terrain_manager.o
|
||||
%GCC% %CFLAGS% -c %ENGINE_DIR%\ECS\world.c -o build\world.o
|
||||
%GCC% %CFLAGS% -c %ENGINE_DIR%\Input\input.c -o build\input.o
|
||||
%GCC% %CFLAGS% -c %ENGINE_DIR%\Physics\physics.c -o build\physics.o
|
||||
@@ -57,35 +61,49 @@ echo [2/4] Compiling VisualScript...
|
||||
%GCC% %CFLAGS% -c %ENGINE_DIR%\VisualScript\block_serializer.c -o build\block_serializer.o
|
||||
%GCC% %CFLAGS% -c %ENGINE_DIR%\VisualScript\block_editor.c -o build\block_editor.o
|
||||
|
||||
REM 编译 Editor 模块
|
||||
echo [3/4] Compiling Editor...
|
||||
%GCC% %CFLAGS% -c %ENGINE_DIR%\Editor\glyph_atlas.c -o build\glyph_atlas.o
|
||||
|
||||
REM 编译 Demo
|
||||
echo [4/4] Compiling Demo...
|
||||
echo [3/3] Compiling Demo...
|
||||
%GCC% %CFLAGS% -c %DEMO_DIR%\main.c -o build\main.o
|
||||
%GCC% %CFLAGS% -c %DEMO_DIR%\audio_demo.c -o build\audio_demo.o
|
||||
%GCC% %CFLAGS% -c %DEMO_DIR%\editor_main.c -o build\editor_main.o
|
||||
%GCC% %CFLAGS% -c %DEMO_DIR%\open_world_demo.c -o build\open_world_demo.o
|
||||
|
||||
REM 链接主程序
|
||||
echo Linking main...
|
||||
%GXX% build\engine.o build\logger.o build\timer.o build\asset_manager.o build\window.o build\graphics_device.o build\renderer.o build\shader.o build\mesh.o build\texture.o build\material.o build\camera.o build\world.o build\input.o build\physics.o build\audio.o build\ui.o build\lua_engine.o build\scene_graph.o build\scene_render.o build\scene_serialize.o build\block_core.o build\block_types.o build\block_workspace.o build\block_interaction.o build\block_renderer.o build\block_palette.o build\block_executor.o build\block_serializer.o build\block_editor.o build\glyph_atlas.o build\main.o -o build\%OUTPUT% %LDFLAGS%
|
||||
%GXX% build\engine.o build\logger.o build\timer.o build\asset_manager.o build\window.o build\graphics_device.o build\renderer.o build\frustum.o build\shader.o build\mesh.o build\texture.o build\material.o build\camera.o build\camera_controller.o build\terrain.o build\terrain_manager.o build\world.o build\input.o build\physics.o build\audio.o build\ui.o build\lua_engine.o build\scene_graph.o build\scene_render.o build\scene_serialize.o build\block_core.o build\block_types.o build\block_workspace.o build\block_interaction.o build\block_renderer.o build\block_palette.o build\block_executor.o build\block_serializer.o build\block_editor.o build\main.o -o build\%OUTPUT% %LDFLAGS%
|
||||
|
||||
REM 链接音频演示
|
||||
echo Linking audio_demo...
|
||||
%GXX% build\engine.o build\logger.o build\timer.o build\asset_manager.o build\window.o build\graphics_device.o build\renderer.o build\shader.o build\mesh.o build\texture.o build\material.o build\camera.o build\world.o build\input.o build\physics.o build\audio.o build\ui.o build\lua_engine.o build\scene_graph.o build\scene_render.o build\scene_serialize.o build\block_core.o build\block_types.o build\block_workspace.o build\block_interaction.o build\block_renderer.o build\block_palette.o build\block_executor.o build\block_serializer.o build\block_editor.o build\glyph_atlas.o build\audio_demo.o -o build\audio_demo.exe %LDFLAGS%
|
||||
%GXX% build\engine.o build\logger.o build\timer.o build\asset_manager.o build\window.o build\graphics_device.o build\renderer.o build\frustum.o build\shader.o build\mesh.o build\texture.o build\material.o build\camera.o build\camera_controller.o build\terrain.o build\terrain_manager.o build\world.o build\input.o build\physics.o build\audio.o build\ui.o build\lua_engine.o build\scene_graph.o build\scene_render.o build\scene_serialize.o build\block_core.o build\block_types.o build\block_workspace.o build\block_interaction.o build\block_renderer.o build\block_palette.o build\block_executor.o build\block_serializer.o build\block_editor.o build\audio_demo.o -o build\audio_demo.exe %LDFLAGS%
|
||||
|
||||
REM 链接编辑器
|
||||
echo Linking editor...
|
||||
%GXX% build\engine.o build\logger.o build\timer.o build\asset_manager.o build\window.o build\graphics_device.o build\renderer.o build\shader.o build\mesh.o build\texture.o build\material.o build\camera.o build\world.o build\input.o build\physics.o build\audio.o build\ui.o build\lua_engine.o build\scene_graph.o build\scene_render.o build\scene_serialize.o build\block_core.o build\block_types.o build\block_workspace.o build\block_interaction.o build\block_renderer.o build\block_palette.o build\block_executor.o build\block_serializer.o build\block_editor.o build\glyph_atlas.o build\editor_main.o -o build\editor.exe %LDFLAGS% -mwindows
|
||||
REM 链接开放世界演示
|
||||
echo Linking open_world_demo...
|
||||
%GXX% build\engine.o build\logger.o build\timer.o build\asset_manager.o build\window.o build\graphics_device.o build\renderer.o build\frustum.o build\shader.o build\mesh.o build\texture.o build\material.o build\camera.o build\camera_controller.o build\terrain.o build\terrain_manager.o build\world.o build\input.o build\physics.o build\audio.o build\ui.o build\lua_engine.o build\scene_graph.o build\scene_render.o build\scene_serialize.o build\block_core.o build\block_types.o build\block_workspace.o build\block_interaction.o build\block_renderer.o build\block_palette.o build\block_executor.o build\block_serializer.o build\block_editor.o build\open_world_demo.o -o build\open_world_demo.exe %LDFLAGS%
|
||||
|
||||
REM 编译 C# 编辑器
|
||||
echo Building C# editor...
|
||||
dotnet build EditorCS\Lity3DEditor.csproj -c Release -o build
|
||||
|
||||
if %ERRORLEVEL% EQU 0 (
|
||||
echo.
|
||||
echo === Build succeeded! ===
|
||||
echo Output: build\%OUTPUT%
|
||||
echo Audio Demo: build\audio_demo.exe
|
||||
echo Open World Demo: build\open_world_demo.exe
|
||||
echo Editor: build\editor.exe
|
||||
echo.
|
||||
echo Run with: build\%OUTPUT% or build\audio_demo.exe
|
||||
echo Run with: build\%OUTPUT%, build\audio_demo.exe, build\open_world_demo.exe, or build\editor.exe
|
||||
|
||||
REM 清理中间文件,保留可分发产物
|
||||
del /Q build\*.o 2>nul
|
||||
del /Q build\libEngine.a 2>nul
|
||||
del /Q build\engine.log 2>nul
|
||||
del /Q build\screenshot*.bmp 2>nul
|
||||
rmdir /S /Q build\CMakeFiles 2>nul
|
||||
del /Q build\CMakeCache.txt 2>nul
|
||||
del /Q build\Makefile 2>nul
|
||||
del /Q build\cmake_install.cmake 2>nul
|
||||
del /Q build\scene.txt 2>nul
|
||||
del /Q build\scene_log.txt 2>nul
|
||||
) else (
|
||||
echo.
|
||||
echo === Build FAILED! ===
|
||||
|
||||
Reference in new issue
Block a user