From: chaoskagami Date: Tue, 26 Aug 2014 04:19:52 +0000 (-0400) Subject: Software mode is now supported X-Git-Url: https://chaos.moe/g/?a=commitdiff_plain;h=76f2254e2693ed8e1696445264e7aed57e60784e;p=vn%2Fvndc.git Software mode is now supported --- diff --git a/buildscripts/build.generic b/buildscripts/build.generic index 66dd153..25f8183 100755 --- a/buildscripts/build.generic +++ b/buildscripts/build.generic @@ -11,7 +11,7 @@ SRC=$ROOT/ LIB=$ROOT/external/lib BIN=$ROOT/bin -CXXFLAGS="`pkg-config sdl2 --cflags` `pkg-config SDL2_mixer --cflags` `pkg-config SDL2_image --cflags` `pkg-config SDL2_ttf --cflags`" +CXXFLAGS="-g `pkg-config sdl2 --cflags` `pkg-config SDL2_mixer --cflags` `pkg-config SDL2_image --cflags` `pkg-config SDL2_ttf --cflags`" LDFLAGS="`pkg-config sdl2 --libs` `pkg-config SDL2_image --libs` `pkg-config SDL2_ttf --libs` `pkg-config SDL2_mixer --libs`" INCLUDE="-I$ROOT/external/zero/include -I$ROOT/vndc/include" diff --git a/external/Android/AndroidManifest.xml b/external/Android/AndroidManifest.xml index cf06c9e..a3c10c1 100644 --- a/external/Android/AndroidManifest.xml +++ b/external/Android/AndroidManifest.xml @@ -3,7 +3,7 @@ com.gamemaker.game --> @@ -25,6 +25,7 @@ @@ -34,7 +35,7 @@ - + diff --git a/external/Android/jni/src/Android.mk b/external/Android/jni/src/Android.mk index 74288e5..a2c8b95 100644 --- a/external/Android/jni/src/Android.mk +++ b/external/Android/jni/src/Android.mk @@ -29,13 +29,12 @@ op_text.cpp \ Data.cpp \ Loop.cpp \ Parse.cpp \ -VNDC.cpp \ AudioManager.cpp \ ContextManager.cpp \ TextManager.cpp \ -UDisplayable.cpp - - +UDisplayable.cpp \ +../SDL/src/main/android/SDL_android_main.c \ +VNDC.cpp LOCAL_SHARED_LIBRARIES := SDL2 SDL2_mixer SDL2_ttf SDL2_image diff --git a/external/zero/include/Zero.hpp b/external/zero/include/Zero.hpp index 0f7b6a7..9ff789f 100644 --- a/external/zero/include/Zero.hpp +++ b/external/zero/include/Zero.hpp @@ -5,6 +5,8 @@ #include #endif +#include + #include #include #include @@ -14,6 +16,18 @@ #include #include +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + #define RED_MASK 0xff000000 + #define GREEN_MASK 0x00ff0000 + #define BLUE_MASK 0x0000ff00 + #define ALPHA_MASK 0x000000ff +#else + #define RED_MASK 0x000000ff + #define GREEN_MASK 0x0000ff00 + #define BLUE_MASK 0x00ff0000 + #define ALPHA_MASK 0xff000000 +#endif + #include "AudioManager.hpp" #include "ContextManager.hpp" #include "TextManager.hpp" diff --git a/external/zero/src/ContextManager.cpp b/external/zero/src/ContextManager.cpp index 50e27f4..420bb82 100644 --- a/external/zero/src/ContextManager.cpp +++ b/external/zero/src/ContextManager.cpp @@ -89,7 +89,8 @@ } else { _InitWindowSW(width, height, fulls); - this->surface_o = SDL_CreateRGBSurface(0, width, height, 32, 0, 0, 0, 0); + this->surface_o = SDL_CreateRGBSurface(0, width, height, 32, RED_MASK, GREEN_MASK, BLUE_MASK, ALPHA_MASK); + SDL_SetSurfaceBlendMode(this->surface_o, SDL_BLENDMODE_BLEND); } txtMgr = new TextManager(this); @@ -97,7 +98,10 @@ void ContextManager::_InitWindowSW(int width, int height, bool fulls) { // Add title setting function. - this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_SHOWN); + if(!fulls) + this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_SHOWN); + else + this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_FULLSCREEN); if(this->window == NULL) { fprintf(stderr, "[E] Error creating window. Info:\n"); fprintf(stderr, "[E] %s\n", SDL_GetError()); @@ -106,19 +110,24 @@ } else { SDL_SetHintWithPriority(SDL_HINT_RENDER_VSYNC, "1", SDL_HINT_OVERRIDE); - if(!SDL_CreateRenderer( this->window, -1, SDL_RENDERER_ACCELERATED )) { + if(!SDL_CreateRenderer( this->window, -1, 0 )) { fprintf(stderr, "[E] Error creating renderer. Info:\n"); fprintf(stderr, "[E] %s\n", SDL_GetError()); fprintf(stderr, "[E] This is fatal. Dying."); exit(-1); } + + this->logicalRender = false; } } void ContextManager::_InitWindowAC(int width, int height, bool fulls) { this->accelerate = true; - this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_SHOWN); + if(!fulls) + this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_SHOWN); + else + this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_FULLSCREEN); if(this->window == NULL) { fprintf(stderr, "[E] Error creating window. Info:\n"); fprintf(stderr, "[E] %s\n", SDL_GetError()); @@ -159,7 +168,8 @@ } else { _InitWindowLogicalSW(width_win, height_win, width_log, height_log, fulls); - this->surface_o = SDL_CreateRGBSurface(0, width_win, height_win, 32, 0, 0, 0, 0); + this->surface_o = SDL_CreateRGBSurface(0, width_win, height_win, 32, RED_MASK, GREEN_MASK, BLUE_MASK, ALPHA_MASK); + SDL_SetSurfaceBlendMode(this->surface_o, SDL_BLENDMODE_BLEND); } txtMgr = new TextManager(this); @@ -167,7 +177,10 @@ // Init window with a logical size and a real one. void ContextManager::_InitWindowLogicalSW(int width_win, int height_win, int width_log, int height_log, bool fulls) { - this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width_win, height_win, SDL_WINDOW_SHOWN); + if(!fulls) + this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width_win, height_win, SDL_WINDOW_SHOWN); + else + this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width_win, height_win, SDL_WINDOW_FULLSCREEN); if(this->window == NULL) { fprintf(stderr, "[E] Error creating window. Info:\n"); fprintf(stderr, "[E] %s\n", SDL_GetError()); @@ -175,7 +188,7 @@ exit(-1); } else { - this->renderer = SDL_CreateRenderer( this->window, -1, SDL_RENDERER_ACCELERATED ); + this->renderer = SDL_CreateRenderer( this->window, -1, 0 ); if(this->renderer == NULL) { fprintf(stderr, "[E] Error creating renderer. Info:\n"); fprintf(stderr, "[E] %s\n", SDL_GetError()); @@ -185,7 +198,7 @@ else { this->logicalRender = true; - this->surface = SDL_CreateRGBSurface(0, width_log, height_log, 32, 0, 0, 0, 0); + this->surface = SDL_CreateRGBSurface(0, width_log, height_log, 32, RED_MASK, GREEN_MASK, BLUE_MASK, ALPHA_MASK); } } } @@ -193,8 +206,10 @@ // Init window with a logical size and a real one. void ContextManager::_InitWindowLogicalAC(int width_win, int height_win, int width_log, int height_log, bool fulls) { this->accelerate = true; - - this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width_win, height_win, SDL_WINDOW_SHOWN); + if(!fulls) + this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width_win, height_win, SDL_WINDOW_SHOWN); + else + this->window = SDL_CreateWindow("Zero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width_win, height_win, SDL_WINDOW_FULLSCREEN); if(this->window == NULL) { fprintf(stderr, "[E] Error creating window. Info:\n"); fprintf(stderr, "[E] %s\n", SDL_GetError()); @@ -238,7 +253,8 @@ else { if (logicalRender) SDL_FillRect(this->surface, NULL, SDL_MapRGB(this->surface->format, 0x0, 0x0, 0x0)); - SDL_FillRect(this->surface_o, NULL, SDL_MapRGB(this->surface_o->format, 0x0, 0x0, 0x0)); + + SDL_FillRect(this->surface_o, NULL, SDL_MapRGBA(this->surface_o->format, 0x0, 0x0, 0x0, 0x0)); SDL_FillRect(SDL_GetWindowSurface(this->window), NULL, SDL_MapRGB(SDL_GetWindowSurface(this->window)->format, 0x0, 0x0, 0x0)); } @@ -255,7 +271,7 @@ SDL_SetRenderTarget(renderer, NULL); } else { - SDL_FillRect(this->surface_o, NULL, SDL_MapRGB(this->surface_o->format, 0x0, 0x0, 0x0)); + SDL_FillRect(this->surface_o, NULL, SDL_MapRGBA(this->surface_o->format, 0, 0, 0, 0)); } } diff --git a/external/zero/src/TextManager.cpp b/external/zero/src/TextManager.cpp index 8b230da..e6cfcf1 100644 --- a/external/zero/src/TextManager.cpp +++ b/external/zero/src/TextManager.cpp @@ -74,12 +74,6 @@ void TextManager::Render(char* text, int x, int y) { TTF_SetFontOutline(fonts[current_font], 0); } - SDL_Texture *tmp1 = NULL, *tmp2 = NULL; - - tmp1 = SDL_CreateTextureFromSurface(ctx->Renderer(), sf1); - if(outline) - tmp2 = SDL_CreateTextureFromSurface(ctx->Renderer(), sf2); - SDL_Rect src, dst, src2, dst2; src.x = 0; src.y = 0; @@ -101,14 +95,30 @@ void TextManager::Render(char* text, int x, int y) { dst2.y = y - (outline_px); dst2.w = src2.w; dst2.h = src2.h; - SDL_FreeSurface(sf2); + } + + if(ctx->Accelerated()) { + SDL_Texture *tmp1 = NULL, *tmp2 = NULL; + + tmp1 = SDL_CreateTextureFromSurface(ctx->Renderer(), sf1); + if(outline) + tmp2 = SDL_CreateTextureFromSurface(ctx->Renderer(), sf2); + ctx->OverlayBlit(tmp2, &src2, &dst2); + ctx->OverlayBlit(tmp1, &src, &dst); + SDL_DestroyTexture(tmp2); + SDL_DestroyTexture(tmp1); + + } + else { + ctx->OverlayBlit(sf2, &src, &dst); + ctx->OverlayBlit(sf1, &src, &dst); } + SDL_FreeSurface(sf2); SDL_FreeSurface(sf1); - ctx->OverlayBlit(tmp1, &src, &dst); - SDL_DestroyTexture(tmp1); + } diff --git a/external/zero/src/UDisplayable.cpp b/external/zero/src/UDisplayable.cpp index e6ed1e7..ef754a0 100644 --- a/external/zero/src/UDisplayable.cpp +++ b/external/zero/src/UDisplayable.cpp @@ -82,7 +82,65 @@ // Sets the Displayable's mode. UDisplayable::UDisplayable(ContextManager* cx, UDisplayableMode mode, char* fname) { - UDisplayable(cx, fname); + // UDisplayable(cx, fname); + + + DefaultVars(); + + SDL_Surface* bitmap_tmp = IMG_Load(fname); + + if(!bitmap_tmp) { + printf("[UDisplayable::Ctor] File could not be loaded, this->Error set.\n"); + Error = true; + } + else { + this->x = 0; + this->y = 0; + this->loc.x = 0; + this->loc.y = 0; + this->ctx = cx; + this->frameWidth = bitmap_tmp->w; + this->bmp_w = bitmap_tmp->w; + this->bmp_h = bitmap_tmp->h; + + // We still allocate the two arrays, regardless. + + // These values are unused, but we'll default them so it will operate normally. + hitbox = (int*)calloc(sizeof(int), 4); + + // By default, it will fill this with 0, 0, W, H. + // This will behave identically to a displayable. + hitbox[0] = 0; + hitbox[1] = 0; + hitbox[2] = bitmap_tmp->w; + hitbox[3] = bitmap_tmp->h; + + this->loc.w = bitmap_tmp->w; + this->loc.h = bitmap_tmp->w; + + frame = (int*)calloc(sizeof(int), 4); + + frame[0] = 0; + frame[1] = 0; + frame[2] = cx->GetWidth(); + frame[3] = cx->GetHeight(); + + // Determine if we're on an accelerated context. If so, we create a texture out of the bitmap. + // Then we store what we'll use to the void* bitmap, either Tex or Surf. + + if (cx->Accelerated()) { + SDL_Texture* tex = SDL_CreateTextureFromSurface(ctx->Renderer(), bitmap_tmp); + this->bitmap = (void*)tex; + SDL_FreeSurface(bitmap_tmp); + } + else { + this->bitmap = (void*)bitmap_tmp; + } + } + #ifdef DEBUG_OVERKILL + printf("[UDisplayable~Ctor] accel:%d\n", cx->Accelerated()); + #endif + this->dispMode = mode; } @@ -282,8 +340,14 @@ printf("[UDisplayable::Blit]\n"); #endif + SDL_Rect src; + src.x = 0; + src.y = 0; + src.w = frameWidth; + src.h = bmp_h; + if (frameIndex == -1) { - ctx->Blit(bitmap, NULL, &loc_adj); + ctx->Blit(bitmap, &src, &loc_adj); return; } diff --git a/vndc/include/Data.hpp b/vndc/include/Data.hpp index c861447..d5385c5 100644 --- a/vndc/include/Data.hpp +++ b/vndc/include/Data.hpp @@ -35,6 +35,7 @@ class DataContainer { bool verbose; int currentLine; bool skip_key_on; + bool sw_rendering; bool eof; char* window_name; char* next_line; // Used for voice-detect. diff --git a/vndc/include/Funcs.hpp b/vndc/include/Funcs.hpp index 230390c..4153a6f 100644 --- a/vndc/include/Funcs.hpp +++ b/vndc/include/Funcs.hpp @@ -8,11 +8,6 @@ #include "gitrev.hpp" -// No output capabilities. -#ifdef WITH_ANDROID -# define printf(...) -#endif - #include "Data.hpp" void Parse(); // This reads commands from files. diff --git a/vndc/include/gitrev.hpp b/vndc/include/gitrev.hpp index b440e2e..1dbb938 100644 --- a/vndc/include/gitrev.hpp +++ b/vndc/include/gitrev.hpp @@ -1,5 +1,5 @@ #ifndef GIT_REV_HDR #define GIT_REV_HDR -#define GIT_REV "c7ef31d2ee1c2c24b2c76369d203ac024dfae5f9" +#define GIT_REV "456cf80a21b450122572c15584e45b8d502cab45" #endif diff --git a/vndc/src/Data.cpp b/vndc/src/Data.cpp index 25ece20..dc01e0e 100644 --- a/vndc/src/Data.cpp +++ b/vndc/src/Data.cpp @@ -30,6 +30,11 @@ DataContainer::DataContainer() { verbose = false; currentLine = 0; skip_key_on = false; + #ifdef USE_ANDROID + sw_rendering = true; + #else + sw_rendering = false; + #endif eof = false; next_line = NULL; // Used for voice-detect. // It's impossible to parse without lookahead. diff --git a/vndc/src/Loop.cpp b/vndc/src/Loop.cpp index 3a9e32f..88a8536 100644 --- a/vndc/src/Loop.cpp +++ b/vndc/src/Loop.cpp @@ -39,7 +39,7 @@ void Loop() { void Setup() { // Init window - GetData()->ctx->InitWindowLogical(GetData()->physical_w, GetData()->physical_h, GetData()->screen_w, GetData()->screen_h, false, true); + GetData()->ctx->InitWindowLogical(GetData()->physical_w, GetData()->physical_h, GetData()->screen_w, GetData()->screen_h, false, !(GetData()->sw_rendering)); GetData()->window_name = (char*)calloc(sizeof(char), 400); sprintf(GetData()->window_name, "%s", "VNDC Interpreter "); diff --git a/vndc/src/VNDC.cpp b/vndc/src/VNDC.cpp index 3ed644e..19f4f81 100644 --- a/vndc/src/VNDC.cpp +++ b/vndc/src/VNDC.cpp @@ -26,12 +26,26 @@ int main(int argc, char** argv) { bool enable_v = false; bool newgame = false; char c; + #ifdef USE_ANDROID + bool software = true; + #else + bool software = false; + #endif - while((c = getopt(argc, argv, "nbvx:y:d:m:s:ch")) != -1) { + while((c = getopt(argc, argv, "wnbvx:y:d:m:s:ch")) != -1) { switch(c) { + case 'w': + #ifdef USE_ANDROID + printf("[info] Forcing Hardware Acceleration.\n"); + #else + printf("[info] Utilizing Software Rendering.\n"); + #endif + software = !software; + break; case 'n': printf("[info] New game, not reloading save.\n"); - newgame = true; + newgame = true; + break; case 'v': printf("[info] Script commands will be echoed.\n"); enable_v = true; @@ -65,6 +79,7 @@ int main(int argc, char** argv) { break; case 'h': printf("-x size -y size\tStretch display window to WxH\n"); + printf("-w\t\tUse Software Rendering (on android: force HW render)\n"); printf("-n\t\tNew Game. Do not reload default save.\n"); printf("-d dir\t\tChange to directory/Run game in directory\n"); printf("-b\t\tDebug Mode. Hit Ctrl+C on console for shell\n"); @@ -97,6 +112,7 @@ int main(int argc, char** argv) { } GetData()->vndc_enabled = vndc_extensions; GetData()->verbose = enable_v; + GetData()->sw_rendering = software; if(debug_enable) { signal(SIGINT, DebugTrap); GetData()->debug_mode = true; diff --git a/vndc/src/op_bgload.cpp b/vndc/src/op_bgload.cpp index 119eacb..3cfa12e 100644 --- a/vndc/src/op_bgload.cpp +++ b/vndc/src/op_bgload.cpp @@ -20,7 +20,10 @@ void op_bgload(char* file, int* fadetime) { //printf("Attempt to load file %s as BG\n", path); // Load displayable. - SDL_Surface* sfc = IMG_Load(GetData()->current_bg); + + UDisplayable* disp = new UDisplayable(GetData()->ctx, GetData()->current_bg); + + // SDL_Surface* sfc = IMG_Load(GetData()->current_bg); uint8_t transp_incr = 16; if(fadetime != NULL) @@ -28,18 +31,17 @@ void op_bgload(char* file, int* fadetime) { // Transition effect. - SDL_Texture* tx = NULL; - tx = SDL_CreateTextureFromSurface(GetData()->ctx->Renderer(), sfc); - SDL_SetTextureBlendMode(tx, SDL_BLENDMODE_BLEND); + // SDL_Texture* tx = NULL; + // tx = SDL_CreateTextureFromSurface(GetData()->ctx->Renderer(), sfc); + // SDL_SetTextureBlendMode(tx, SDL_BLENDMODE_BLEND); - SDL_FreeSurface(sfc); + // SDL_FreeSurface(sfc); int delay = 1; - for(int tr = 0; tr < 255; tr += transp_incr) { - SDL_SetTextureAlphaMod(tx, tr); - GetData()->ctx->Blit(tx, NULL, NULL); + for(int tr = 0; tr < 255; tr += transp_incr) { + disp->Blit(); op_delay(&delay); } - SDL_DestroyTexture(tx); +// SDL_DestroyTexture(tx); } diff --git a/vndc/src/op_cleartext.cpp b/vndc/src/op_cleartext.cpp index 4f917c5..27c762d 100644 --- a/vndc/src/op_cleartext.cpp +++ b/vndc/src/op_cleartext.cpp @@ -7,8 +7,11 @@ void ct_transwindow() { int width_dr = (GetData()->render_x2 - GetData()->render_x1 + 20); int height_dr = (GetData()->render_y2 - GetData()->render_y1 + 30 + 20); - SDL_Surface* sfc = SDL_CreateRGBSurface(0, width_dr, height_dr, 32, 0, 0, 0, 0); - SDL_FillRect(sfc, NULL, SDL_MapRGBA(sfc->format, 0, 0, 0, 128)); + // if(! GetData()->ctx->Accelerated()) return; + SDL_Surface* sfc = SDL_CreateRGBSurface(0, width_dr, height_dr, 32, RED_MASK, GREEN_MASK, BLUE_MASK, ALPHA_MASK); + SDL_FillRect(sfc, NULL, SDL_MapRGBA(sfc->format, 0, 0, 0, 100)); + if(!GetData()->ctx->Accelerated()) { + } SDL_Rect src; src.x = 0; @@ -16,21 +19,27 @@ void ct_transwindow() { src.w = sfc->w; src.h = sfc->h; - SDL_Texture* dim = SDL_CreateTextureFromSurface(GetData()->ctx->Renderer(), sfc); - SDL_SetTextureBlendMode(dim, SDL_BLENDMODE_BLEND); - SDL_SetTextureAlphaMod(dim, 128); - - SDL_FreeSurface(sfc); - SDL_Rect dst; dst.x = GetData()->render_x1 - 10; dst.y = GetData()->render_y1 - 10; dst.w = src.w; dst.h = src.h; - GetData()->ctx->OverlayBlit(dim, &src, &dst); + if(GetData()->ctx->Accelerated()) { + SDL_Texture* dim = SDL_CreateTextureFromSurface(GetData()->ctx->Renderer(), sfc); + //SDL_SetTextureBlendMode(dim, SDL_BLENDMODE_BLEND); + //SDL_SetTextureAlphaMod(dim, 128); + + GetData()->ctx->OverlayBlit(dim, &src, &dst); + + SDL_DestroyTexture(dim); + } + else { + GetData()->ctx->OverlayBlit(sfc, &src, &dst); + } + + SDL_FreeSurface(sfc); - SDL_DestroyTexture(dim); } /*