From 1a732d7c712d8332b73480f5505232f36aad0cc3 Mon Sep 17 00:00:00 2001 From: JailDoctor Date: Fri, 28 Oct 2022 13:49:08 +0200 Subject: [PATCH] - new debug system --- lua.cpp | 8 +-- main.cpp | 37 ++-------- mini.cpp | 215 ++++++++++++++++++++++--------------------------------- mini.h | 4 +- 4 files changed, 96 insertions(+), 168 deletions(-) diff --git a/lua.cpp b/lua.cpp index f1adb5c..a04cd89 100644 --- a/lua.cpp +++ b/lua.cpp @@ -914,14 +914,14 @@ void lua_init(char* filenames) { int size; char* buffer = file_getfilebuffer(file_start, size); if (luaL_loadbuffer(L, buffer, size, file_start)) { - debug("error loading game"); + debug("LOADING ERROR:"); debug(lua_tostring(L, -1)); lua_pop(L,1); return; } free(buffer); if (lua_pcall(L,0, LUA_MULTRET, 0)) { - debug("runtime error"); + debug("RUNTIME ERROR:"); debug(lua_tostring(L, -1)); lua_pop(L,1); return; @@ -945,7 +945,7 @@ void lua_call_init() { if (!init_exists) return; lua_getglobal(L, "_init"); if (lua_pcall(L, 0, 0, 0)) { - debug("runtime error"); + debug("RUNTIME ERROR:"); debug(lua_tostring(L, -1)); lua_pop(L,1); is_playing = false; @@ -956,7 +956,7 @@ void lua_call_update() { if (!update_exists) return; lua_getglobal(L, "_update"); if (lua_pcall(L, 0, 0, 0)) { - debug("runtime error"); + debug("RUNTIME ERROR:"); debug(lua_tostring(L, -1)); lua_pop(L,1); is_playing = false; diff --git a/main.cpp b/main.cpp index 2b0776f..5560253 100644 --- a/main.cpp +++ b/main.cpp @@ -1,36 +1,9 @@ #include "mini.h" -int current_editor = 0; - -void do_terminal() { - cls(0); - pdebug(); -} - -void do_sprite_editor() { - cls(14); - //palt(0, false); - rectfill(0, 0, 160, 7, 2); - rectfill(0, 115, 160, 119, 2); - sspr(0, 0, 128, 32, 0, 83); - sspr(0, 0, 8, 8, 8, 16, 64, 64); - rect(8, 16, 72, 80, 0); - spr(17, mousex(), mousey()); - if (mbtn(1) && mousex()>=8 && mousey()>=8 && mousex()<72 && mousey()<72) { - sset((mousex()-8)/8, (mousey()-16)/8); - } -} - void loop() { - if (btnp(KEY_TAB)) { - current_editor = (++current_editor)%5; - } - switch(current_editor) { - case 0: - do_terminal(); - break; - case 1: - do_sprite_editor(); - break; - } + settrans(255); + setcolor(0,0xff0000); + const int w=scrw(); + const int h=scrh(); + rect(0,0,w-1,h-1,0); } \ No newline at end of file diff --git a/mini.cpp b/mini.cpp index d12c20d..8ad9e9d 100644 --- a/mini.cpp +++ b/mini.cpp @@ -43,14 +43,13 @@ namespace ds { int cam[2] = {0, 0}; int clip[4] = {0, 0, screen_width, screen_height}; int clp[4] = {0, 0, screen_width-1, screen_height-1}; - //uint8_t draw_palette[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; - //uint8_t screen_palette[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; uint8_t trans = 0; uint16_t fill_pattern = 0b1111111111111111; bool fill_trans = false; } bool should_exit = false; +bool should_quit = false; SDL_Window *mini_win; SDL_Renderer *mini_ren; SDL_Texture *mini_bak; @@ -70,12 +69,6 @@ uint16_t font[96]; char base64glyphs[193] = "/h/AqV/hhhh/GMYYMGz/t/eS33H477wsjjswY4IOPHEFFVVVAVAVAVIc+dJHMMM/h/qBgBgVqq+//eIUi/dJzhAAhzAAA/eM" "AMShAAAQsjAAAwsjAAAeSzAAAcU3AAAEqRAAABVaiAAMezhAAAAAMAADH4wAASb2SAAMAttAQYcefACGOe+AAAVVAAAAbbAA"; -int debug_line_size = (screen_width/4); -int debug_num_lines = (screen_height/6); -int debug_total_size = debug_line_size*debug_num_lines; -char *debug_text = NULL; -int debug_cursor = 0; - //Uint8 keymapping[6] = { SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT, SDL_SCANCODE_UP, SDL_SCANCODE_DOWN, SDL_SCANCODE_Z, SDL_SCANCODE_X }; const Uint8 *keys; Uint8 key_just_pressed = 0; @@ -118,8 +111,6 @@ void reinit() { ds::cam[0] = ds::cam[1] = 0; ds::clip[0] = ds::clip[1] = 0; ds::clip[2] = screen_width; ds::clip[3] = screen_height; ds::clp[0] = ds::clp[1] = 0; ds::clp[2] = screen_width-1; ds::clp[3] = screen_height-1; - //for(int i=0;i<16;++i)ds::draw_palette[i]=i; - //for(int i=0;i<16;++i)ds::screen_palette[i]=i; ds::trans=0; ds::fill_pattern = 0b1111111111111111; ds::fill_trans = false; @@ -142,6 +133,14 @@ void quitaudio() { JA_Quit(); } +int scrw() { + return screen_width; +} + +int scrh() { + return screen_height; +} + uint8_t newsurf(int w, int h) { int i = 0; while (i<10 && surfaces[i].p != NULL) ++i; @@ -163,21 +162,7 @@ uint8_t loadsurf(const char* filename) { surfaces[i].p = LoadGif(buffer, &surfaces[i].w, &surfaces[i].h); surfaces[i].size = surfaces[i].w*surfaces[i].h; free(buffer); - - /* - FILE *f = fopen(filename, "rb"); - if (f) { - fseek(f, 0, SEEK_END); - long size = ftell(f); - fseek(f, 0, SEEK_SET); - uint8_t *buffer = (uint8_t*)malloc(size); - fread(buffer, size, 1, f); - fclose(f); - surfaces[i].p = LoadGif(buffer, &surfaces[i].w, &surfaces[i].h); - surfaces[i].size = surfaces[i].w*surfaces[i].h; - free(buffer); - } - */ + return i; } @@ -199,100 +184,93 @@ void setmap(uint8_t surface) { } int main(int argc,char*argv[]){ - int bi = 0; - for (int ci=0; ci<96; ci+=2) { - font[ci] = base64font[bi]-48+((base64font[bi+1]-48)<<6)+((base64font[bi+2]-48&7)<<12); - font[ci+1] = ((base64font[bi+2]-48)>>3)+((base64font[bi+3]-48)<<3)+((base64font[bi+4]-48)<<9); - bi += 5; - } + + while (!should_quit) { + should_exit=false; - /*FILE *f = fopen("sprites.bmp", "rb"); - if (f) { - uint8_t buffer[SPRITES_SIZE_BYTES/2]; - fseek(f, 118, SEEK_SET); - fread(buffer, SPRITES_SIZE_BYTES/2, 1, f); - fclose(f); - for (int y=0; y> 4; - SPRITES(x*2+1, SPRITES_WIDTH-1-y) = buffer[x+y*(SPRITES_WIDTH/2)] & 0xf; - } + // initfont() + int bi = 0; + for (int ci=0; ci<96; ci+=2) { + font[ci] = base64font[bi]-48+((base64font[bi+1]-48)<<6)+((base64font[bi+2]-48&7)<<12); + font[ci+1] = ((base64font[bi+2]-48)>>3)+((base64font[bi+3]-48)<<3)+((base64font[bi+4]-48)<<9); + bi += 5; } - }*/ - read_ini(); - setdest(newsurf(screen_width, screen_height)); + read_ini(); + setdest(newsurf(screen_width, screen_height)); - debug_line_size = (screen_width/4); - debug_num_lines = (screen_height/6); - debug_total_size = debug_line_size*debug_num_lines; - if (debug_text != NULL) free(debug_text); - debug_text = (char*)malloc(debug_total_size); - for (int i=0; isize;++i) pixels[i] = palette[screen_surface->p[i]]; + SDL_UnlockTexture(mini_bak); + SDL_RenderCopy(mini_ren, mini_bak, NULL, NULL); + SDL_RenderPresent(mini_ren); } - keys = SDL_GetKeyboardState(NULL); - mouse_buttons = SDL_GetMouseState(&mouse_x, &mouse_y); - mouse_x /= screen_zoom; mouse_y /= screen_zoom; - - if (lua_is_playing()) { - lua_call_update(); - } else { - loop(); - } - SDL_LockTexture(mini_bak, NULL, (void**)&pixels, &pitch); - for (int i=0;isize;++i) pixels[i] = palette[screen_surface->p[i]]; - SDL_UnlockTexture(mini_bak); - SDL_RenderCopy(mini_ren, mini_bak, NULL, NULL); - SDL_RenderPresent(mini_ren); + lua_quit(); + quitaudio(); + for (int i=0;i<10;++i) freesurf(i); + SDL_DestroyTexture(mini_bak); + SDL_DestroyRenderer(mini_ren); + SDL_DestroyWindow(mini_win); + SDL_Quit(); } - lua_quit(); - SDL_Quit(); + return 0; } @@ -926,39 +904,14 @@ const char* tostr(int val) { return SDL_itoa(val, tostr_tmp, 10); } -void debug_one_line_up() { - for (int i=0; i= debug_total_size) debug_one_line_up(); - } - debug_cursor = (int(debug_cursor/debug_line_size)+1)*debug_line_size; - if (debug_cursor >= debug_total_size) debug_one_line_up(); -} - -void pdebug() { - palette[0]=0x00000000; - palette[1]=0x0000ff00; - color(1); - int i=0; - for (int y=0; y