more debug info

This commit is contained in:
dga
2025-07-18 01:13:56 +03:00
parent 72d8a59adf
commit 65cda064aa
7 changed files with 151 additions and 7 deletions
+1 -1
View File
@@ -4,7 +4,7 @@
CC = emcc CC = emcc
CXX = emcc CXX = emcc
CXXFLAGS ?= -sUSE_SDL=2 -std=c++17 -Iinclude -fexceptions CXXFLAGS ?= -sUSE_SDL=2 -std=c++17 -Iinclude -fexceptions
LDFLAGS ?= -sUSE_SDL=2 -fexceptions --embed-file=data.pak@data.pak -sMAX_WEBGL_VERSION=2 LDFLAGS ?= -sUSE_SDL=2 -fexceptions --embed-file=data.pak@data.pak -sMAX_WEBGL_VERSION=2 -sALLOW_MEMORY_GROWTH=1 -sASYNCIFY=1
TARGET = eulamadness.html TARGET = eulamadness.html
# System configuration # System configuration
+8
View File
@@ -134,6 +134,14 @@ void TEntityManager::Update() {
} }
void TEntityManager::Draw() { void TEntityManager::Draw() {
#ifdef __EMSCRIPTEN__
static int drawCount = 0;
drawCount++;
if (drawCount % 60 == 0) {
printf("Emscripten: Drawing %zu entities\n", Entities_.size());
}
#endif
std::for_each(Entities_.begin(), Entities_.end(), [&](auto& pair) { std::for_each(Entities_.begin(), Entities_.end(), [&](auto& pair) {
auto& entity = pair.second; auto& entity = pair.second;
entity->Draw(); entity->Draw();
+38
View File
@@ -18,18 +18,31 @@ std::string TFileManager::Get(const std::string& path) {
return Cache_.Get(path); return Cache_.Get(path);
} }
#ifdef __EMSCRIPTEN__
printf("Emscripten: FileManager::Get(%s)\n", path.c_str());
#endif
auto getAttempt = FromFilesystem(path); auto getAttempt = FromFilesystem(path);
if (getAttempt.second) { if (getAttempt.second) {
#ifdef __EMSCRIPTEN__
printf("Emscripten: Found file %s in filesystem\n", path.c_str());
#endif
Cache_.Set(path, getAttempt.first); Cache_.Set(path, getAttempt.first);
return getAttempt.first; return getAttempt.first;
} }
getAttempt = FromArchive(path); getAttempt = FromArchive(path);
if (getAttempt.second) { if (getAttempt.second) {
#ifdef __EMSCRIPTEN__
printf("Emscripten: Found file %s in archive\n", path.c_str());
#endif
Cache_.Set(path, getAttempt.first); Cache_.Set(path, getAttempt.first);
return getAttempt.first; return getAttempt.first;
} }
#ifdef __EMSCRIPTEN__
printf("Emscripten: Failed to find file %s\n", path.c_str());
#endif
throw std::runtime_error("can't find file " + path); throw std::runtime_error("can't find file " + path);
} }
@@ -47,18 +60,36 @@ std::pair<std::string, bool> TFileManager::FromFilesystem(const std::string& pat
} }
std::pair<std::string, bool> TFileManager::FromArchive(const std::string& path) { std::pair<std::string, bool> TFileManager::FromArchive(const std::string& path) {
#ifdef __EMSCRIPTEN__
printf("Emscripten: Trying to open archive: %s\n", ArchivePath_.c_str());
#endif
std::ifstream archiveStream(ArchivePath_, std::ios::in | std::ios::binary); std::ifstream archiveStream(ArchivePath_, std::ios::in | std::ios::binary);
if (!archiveStream.is_open()) { if (!archiveStream.is_open()) {
#ifdef __EMSCRIPTEN__
printf("Emscripten: Failed to open archive: %s\n", ArchivePath_.c_str());
#endif
return std::make_pair<std::string, bool>({}, false); return std::make_pair<std::string, bool>({}, false);
} }
#ifdef __EMSCRIPTEN__
printf("Emscripten: Successfully opened archive: %s\n", ArchivePath_.c_str());
#endif
// Identify and validate PAK file // Identify and validate PAK file
char identifier[4]; char identifier[4];
archiveStream.read(identifier, 4); archiveStream.read(identifier, 4);
if (std::memcmp(identifier, "PACK", 4)) { if (std::memcmp(identifier, "PACK", 4)) {
#ifdef __EMSCRIPTEN__
printf("Emscripten: Invalid PAK header, expected PACK, got %.4s\n", identifier);
#endif
return std::make_pair<std::string, bool>({}, false); return std::make_pair<std::string, bool>({}, false);
} }
#ifdef __EMSCRIPTEN__
printf("Emscripten: Valid PAK header found\n");
#endif
std::uint32_t tocOffset = ReadInt32(archiveStream); std::uint32_t tocOffset = ReadInt32(archiveStream);
std::uint32_t tocSize = ReadInt32(archiveStream) / 64; std::uint32_t tocSize = ReadInt32(archiveStream) / 64;
@@ -80,6 +111,10 @@ std::pair<std::string, bool> TFileManager::FromArchive(const std::string& path)
continue; continue;
} }
#ifdef __EMSCRIPTEN__
printf("Emscripten: Found file %s in archive at offset %u, size %u\n", path.c_str(), fileOffset, fileSize);
#endif
archiveStream.seekg(fileOffset); archiveStream.seekg(fileOffset);
std::string result(fileSize, 0); std::string result(fileSize, 0);
archiveStream.read(result.data(), result.size()); archiveStream.read(result.data(), result.size());
@@ -87,6 +122,9 @@ std::pair<std::string, bool> TFileManager::FromArchive(const std::string& path)
return std::make_pair(result, true); return std::make_pair(result, true);
} }
#ifdef __EMSCRIPTEN__
printf("Emscripten: File %s not found in archive\n", path.c_str());
#endif
return std::make_pair<std::string, bool>({}, false); return std::make_pair<std::string, bool>({}, false);
} }
+18
View File
@@ -15,6 +15,10 @@ static NGame::TApp *app = nullptr;
static void InitApp(void) { static void InitApp(void) {
app = NGame::TApp::Instance(); app = NGame::TApp::Instance();
#ifdef __EMSCRIPTEN__
printf("Emscripten: Registering entities...\n");
#endif
app->EntityManager().RegisterEntity<THero>("Hero"); app->EntityManager().RegisterEntity<THero>("Hero");
app->EntityManager().RegisterEntity<TDirtEntity>("DirtEntity"); app->EntityManager().RegisterEntity<TDirtEntity>("DirtEntity");
app->EntityManager().RegisterEntity<TGrassEntity>("GrassEntity"); app->EntityManager().RegisterEntity<TGrassEntity>("GrassEntity");
@@ -32,19 +36,33 @@ static void InitApp(void) {
app->EntityManager().RegisterEntity<TBackgroundTiler>("BackgroundTiler"); app->EntityManager().RegisterEntity<TBackgroundTiler>("BackgroundTiler");
app->EntityManager().RegisterEntity<TRoomEntity>("RoomEntity"); app->EntityManager().RegisterEntity<TRoomEntity>("RoomEntity");
#ifdef __EMSCRIPTEN__
printf("Emscripten: Creating initial entities...\n");
#endif
app->EntityManager().MakeEntityByName("RoomEntity"); app->EntityManager().MakeEntityByName("RoomEntity");
app->EntityManager().MakeEntityByName("BackgroundTiler"); app->EntityManager().MakeEntityByName("BackgroundTiler");
auto h = app->EntityManager().MakeEntityByName("Hero"); auto h = app->EntityManager().MakeEntityByName("Hero");
h->SetPosition({0, -64}); h->SetPosition({0, -64});
app->EntityManager().UpdateCollision(h); app->EntityManager().UpdateCollision(h);
#ifdef __EMSCRIPTEN__
printf("Emscripten: Initial entities created\n");
#endif
} }
static void MainLoop(void) { static void MainLoop(void) {
if (app) { if (app) {
app->Run(); app->Run();
} else { } else {
#ifdef __EMSCRIPTEN__
printf("Emscripten: Initializing app...\n");
#endif
InitApp(); InitApp();
#ifdef __EMSCRIPTEN__
printf("Emscripten: App initialized\n");
#endif
} }
} }
+59 -2
View File
@@ -9,27 +9,56 @@ namespace NGame {
TRenderManager::TRenderManager(TSurfaceManager& surfaceManager, int width, int height, const std::string& title, std::size_t cacheSize) TRenderManager::TRenderManager(TSurfaceManager& surfaceManager, int width, int height, const std::string& title, std::size_t cacheSize)
: SurfaceManager_(surfaceManager), Cache_(cacheSize), Size_(width, height) { : SurfaceManager_(surfaceManager), Cache_(cacheSize), Size_(width, height) {
#ifdef __EMSCRIPTEN__
printf("Emscripten: Creating window with size %dx%d\n", width, height);
#endif
Window_ = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_UNDEFINED, Window_ = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_RESIZABLE); SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_RESIZABLE);
if (!Window_) { if (!Window_) {
#ifdef __EMSCRIPTEN__
printf("Emscripten: Failed to create window: %s\n", SDL_GetError());
#endif
throw std::runtime_error("Can't create window"); throw std::runtime_error("Can't create window");
} }
#ifdef __EMSCRIPTEN__
printf("Emscripten: Window created successfully\n");
#endif
Renderer_ = SDL_CreateRenderer(Window_, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); Renderer_ = SDL_CreateRenderer(Window_, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (!Renderer_) { if (!Renderer_) {
#ifdef __EMSCRIPTEN__
printf("Emscripten: Failed to create renderer: %s\n", SDL_GetError());
#endif
SDL_DestroyWindow(Window_); SDL_DestroyWindow(Window_);
throw std::runtime_error("Can't create renderer"); throw std::runtime_error("Can't create renderer");
} }
#ifdef __EMSCRIPTEN__
printf("Emscripten: Renderer created successfully\n");
#endif
ScreenTexture_ = SDL_CreateTexture(Renderer_, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_TARGET, width, height); ScreenTexture_ = SDL_CreateTexture(Renderer_, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_TARGET, width, height);
if (!ScreenTexture_) { if (!ScreenTexture_) {
#ifdef __EMSCRIPTEN__
printf("Emscripten: Failed to create screen texture: %s\n", SDL_GetError());
#endif
SDL_DestroyRenderer(Renderer_); SDL_DestroyRenderer(Renderer_);
SDL_DestroyWindow(Window_); SDL_DestroyWindow(Window_);
throw std::runtime_error("Can't create screen texture"); throw std::runtime_error("Can't create screen texture");
} }
#ifdef __EMSCRIPTEN__
printf("Emscripten: Screen texture created successfully\n");
#endif
LightTexture_ = SDL_CreateTexture(Renderer_, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_TARGET, width, height); LightTexture_ = SDL_CreateTexture(Renderer_, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_TARGET, width, height);
if (!LightTexture_) { if (!LightTexture_) {
#ifdef __EMSCRIPTEN__
printf("Emscripten: Failed to create light texture: %s\n", SDL_GetError());
#endif
SDL_DestroyTexture(ScreenTexture_); SDL_DestroyTexture(ScreenTexture_);
SDL_DestroyRenderer(Renderer_); SDL_DestroyRenderer(Renderer_);
SDL_DestroyWindow(Window_); SDL_DestroyWindow(Window_);
@@ -37,12 +66,20 @@ TRenderManager::TRenderManager(TSurfaceManager& surfaceManager, int width, int h
} }
SDL_SetTextureBlendMode(LightTexture_, SDL_BLENDMODE_MOD); SDL_SetTextureBlendMode(LightTexture_, SDL_BLENDMODE_MOD);
#ifdef __EMSCRIPTEN__
printf("Emscripten: Light texture created successfully\n");
#endif
// Make window bigger // Make window bigger
if (width < 640 && height < 480) { if (width < 640 && height < 480) {
SDL_SetWindowSize(Window_, 640, 480); SDL_SetWindowSize(Window_, 640, 480);
} }
Reset(); Reset();
#ifdef __EMSCRIPTEN__
printf("Emscripten: RenderManager initialization complete\n");
#endif
} }
std::shared_ptr<SDL_Texture> TRenderManager::Get(const std::string& path) { std::shared_ptr<SDL_Texture> TRenderManager::Get(const std::string& path) {
@@ -50,12 +87,23 @@ std::shared_ptr<SDL_Texture> TRenderManager::Get(const std::string& path) {
return Cache_.Get(path); return Cache_.Get(path);
} }
#ifdef __EMSCRIPTEN__
printf("Emscripten: Loading texture: %s\n", path.c_str());
#endif
std::shared_ptr<SDL_Surface> surface = SurfaceManager_.Get(path); std::shared_ptr<SDL_Surface> surface = SurfaceManager_.Get(path);
SDL_Texture* texture = SDL_CreateTextureFromSurface(Renderer_, surface.get()); SDL_Texture* texture = SDL_CreateTextureFromSurface(Renderer_, surface.get());
if (!texture) { if (!texture) {
#ifdef __EMSCRIPTEN__
printf("Emscripten: Failed to create texture from surface %s: %s\n", path.c_str(), SDL_GetError());
#endif
std::runtime_error("Can't create texture from surface " + path); std::runtime_error("Can't create texture from surface " + path);
} }
#ifdef __EMSCRIPTEN__
printf("Emscripten: Successfully loaded texture: %s\n", path.c_str());
#endif
std::shared_ptr<SDL_Texture> result(texture, [](SDL_Texture* texture) { SDL_DestroyTexture(texture); }); std::shared_ptr<SDL_Texture> result(texture, [](SDL_Texture* texture) { SDL_DestroyTexture(texture); });
Cache_.Set(path, result); Cache_.Set(path, result);
return result; return result;
@@ -141,6 +189,15 @@ void TRenderManager::Run() {
return; return;
} }
#ifdef __EMSCRIPTEN__
static int frameCount = 0;
frameCount++;
if (frameCount % 60 == 0) {
printf("Emscripten: Frame %d, Commands: Tile=%zu, Background=%zu, Foreground=%zu\n",
frameCount, Commands_[Tile].size(), Commands_[Background].size(), Commands_[Foreground].size());
}
#endif
for (size_t layer = 0; layer < SentinelMax; ++layer) { for (size_t layer = 0; layer < SentinelMax; ++layer) {
switch (layer) { switch (layer) {
case ELayer::BackgroundGlow: case ELayer::BackgroundGlow:
@@ -330,11 +387,11 @@ void TRenderManager::Reset() {
SDL_Rect a; SDL_Rect a;
SDL_RenderGetViewport(Renderer_, &a); SDL_RenderGetViewport(Renderer_, &a);
SDL_SetRenderDrawColor(Renderer_, 0, 0, 0, 0); SDL_SetRenderDrawColor(Renderer_, 0, 0, 0, 255);
SDL_SetRenderTarget(Renderer_, NULL); SDL_SetRenderTarget(Renderer_, NULL);
SDL_RenderClear(Renderer_); SDL_RenderClear(Renderer_);
SDL_SetRenderDrawColor(Renderer_, 0, 0, 0, 0); SDL_SetRenderDrawColor(Renderer_, 0, 0, 0, 255);
SDL_SetRenderTarget(Renderer_, ScreenTexture_); SDL_SetRenderTarget(Renderer_, ScreenTexture_);
SDL_RenderClear(Renderer_); SDL_RenderClear(Renderer_);
+7
View File
@@ -887,6 +887,13 @@ void TBackgroundTiler::Draw() const {
tileOffset.X %= 16; tileOffset.X %= 16;
tileOffset.Y %= 16; tileOffset.Y %= 16;
#ifdef __EMSCRIPTEN__
static int bgDrawCount = 0;
bgDrawCount++;
if (bgDrawCount % 60 == 0) {
printf("Emscripten: Drawing background tiles, camera: (%d, %d)\n", cameraPosition.X, cameraPosition.Y);
}
#endif
renderManager.SetLayer(NGame::TRenderManager::Tile); renderManager.SetLayer(NGame::TRenderManager::Tile);
for (int i = -1; i <= 320 / 16; ++i) { for (int i = -1; i <= 320 / 16; ++i) {
+16
View File
@@ -16,14 +16,30 @@ std::shared_ptr<SDL_Surface> TSurfaceManager::Get(const std::string& path) {
return Cache_.Get(path); return Cache_.Get(path);
} }
#ifdef __EMSCRIPTEN__
printf("Emscripten: Loading surface: %s\n", path.c_str());
#endif
std::string data = FileManager_.Get(path); std::string data = FileManager_.Get(path);
#ifdef __EMSCRIPTEN__
printf("Emscripten: Got data for %s, size: %zu\n", path.c_str(), data.size());
#endif
SDL_RWops* rw = SDL_RWFromConstMem(data.data(), data.size()); SDL_RWops* rw = SDL_RWFromConstMem(data.data(), data.size());
SDL_Surface* surface = SDL_LoadBMP_RW(rw, 1); SDL_Surface* surface = SDL_LoadBMP_RW(rw, 1);
if (!surface) { if (!surface) {
#ifdef __EMSCRIPTEN__
printf("Emscripten: Failed to create surface from file %s: %s\n", path.c_str(), SDL_GetError());
#endif
std::runtime_error("Can't create surface from file " + path); std::runtime_error("Can't create surface from file " + path);
} }
#ifdef __EMSCRIPTEN__
printf("Emscripten: Successfully loaded surface: %s\n", path.c_str());
#endif
std::shared_ptr<SDL_Surface> result(surface, [](SDL_Surface* surface) { SDL_FreeSurface(surface); }); std::shared_ptr<SDL_Surface> result(surface, [](SDL_Surface* surface) { SDL_FreeSurface(surface); });
Cache_.Set(path, result); Cache_.Set(path, result);
return result; return result;