From 46d096206f38f63f2290708b4d6ba007a3329a25 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Thu, 31 Mar 2016 22:08:04 -0400 Subject: [PATCH] Further improvements to overall system stability and other minor adjustments have been made to enhance the user experience --- src/PowderToy.h | 1 + src/PowderToySDL.cpp | 172 ++++++++++++++++++++++++-- src/gui/options/OptionsController.cpp | 20 ++- src/gui/options/OptionsController.h | 2 + src/gui/options/OptionsView.cpp | 19 ++- src/gui/options/OptionsView.h | 2 + src/lua/LuaScriptInterface.cpp | 13 ++ src/lua/LuaScriptInterface.h | 1 + 8 files changed, 216 insertions(+), 14 deletions(-) diff --git a/src/PowderToy.h b/src/PowderToy.h index 412167db5..506cb7141 100644 --- a/src/PowderToy.h +++ b/src/PowderToy.h @@ -1,6 +1,7 @@ #pragma once #include +extern int depth3d; void EngineProcess(); void ClipboardPush(std::string text); std::string ClipboardPull(); diff --git a/src/PowderToySDL.cpp b/src/PowderToySDL.cpp index 3a9f933ee..2e0d47357 100644 --- a/src/PowderToySDL.cpp +++ b/src/PowderToySDL.cpp @@ -47,6 +47,7 @@ extern "C" { #include "gui/dialogues/ErrorMessage.h" #include "gui/dialogues/ConfirmPrompt.h" +#include "gui/dialogues/InformationMessage.h" #include "gui/interface/Keys.h" #include "gui/Style.h" @@ -66,6 +67,7 @@ SDL_SysWMinfo sdl_wminfo; Atom XA_CLIPBOARD, XA_TARGETS, XA_UTF8_STRING; #endif +int depth3d = 0; std::string clipboardText = ""; int desktopWidth = 1280, desktopHeight = 1024; @@ -193,10 +195,78 @@ void blit() SDL_GL_SwapBuffers(); } #else +int mousex = 0, mousey = 0; +void DrawPixel(pixel * vid, pixel color, int x, int y) +{ + if (x >= 0 && x < WINDOWW && y >= 0 && y < WINDOWH) + vid[x+y*WINDOWW] = color; +} + +void DrawCursor(pixel * vid) +{ + //vid[100+100*WINDOWW] = 255<<24|PIXRGB(100, 0, 100); + for (int j = 1; j <= 9; j++) + { + for (int i = 0; i <= j; i++) + { + if (i == 0 || i == j) + DrawPixel(vid, 0xFFFFFFFF, mousex+i, mousey+j); + else + DrawPixel(vid, 0xFF000000, mousex+i, mousey+j); + } + } + DrawPixel(vid, 0xFFFFFFFF, mousex, mousey+10); + for (int i = 0; i < 5; i++) + { + DrawPixel(vid, 0xFF000000, mousex+1+i, mousey+10); + DrawPixel(vid, 0xFFFFFFFF, mousex+6+i, mousey+10); + } + DrawPixel(vid, 0xFFFFFFFF, mousex, mousey+11); + DrawPixel(vid, 0xFF000000, mousex+1, mousey+11); + DrawPixel(vid, 0xFF000000, mousex+2, mousey+11); + DrawPixel(vid, 0xFFFFFFFF, mousex+3, mousey+11); + DrawPixel(vid, 0xFF000000, mousex+4, mousey+11); + DrawPixel(vid, 0xFF000000, mousex+5, mousey+11); + DrawPixel(vid, 0xFFFFFFFF, mousex+6, mousey+11); + + DrawPixel(vid, 0xFFFFFFFF, mousex, mousey+12); + DrawPixel(vid, 0xFF000000, mousex+1, mousey+12); + DrawPixel(vid, 0xFFFFFFFF, mousex+2, mousey+12); + DrawPixel(vid, 0xFFFFFFFF, mousex+4, mousey+12); + DrawPixel(vid, 0xFF000000, mousex+5, mousey+12); + DrawPixel(vid, 0xFF000000, mousex+6, mousey+12); + DrawPixel(vid, 0xFFFFFFFF, mousex+7, mousey+12); + + DrawPixel(vid, 0xFFFFFFFF, mousex, mousey+13); + DrawPixel(vid, 0xFFFFFFFF, mousex+1, mousey+13); + DrawPixel(vid, 0xFFFFFFFF, mousex+4, mousey+13); + DrawPixel(vid, 0xFF000000, mousex+5, mousey+13); + DrawPixel(vid, 0xFF000000, mousex+6, mousey+13); + DrawPixel(vid, 0xFFFFFFFF, mousex+7, mousey+13); + + DrawPixel(vid, 0xFFFFFFFF, mousex, mousey+14); + for (int i = 0; i < 2; i++) + { + DrawPixel(vid, 0xFFFFFFFF, mousex+5, mousey+14+i); + DrawPixel(vid, 0xFF000000, mousex+6, mousey+14+i); + DrawPixel(vid, 0xFF000000, mousex+7, mousey+14+i); + DrawPixel(vid, 0xFFFFFFFF, mousex+8, mousey+14+i); + + DrawPixel(vid, 0xFFFFFFFF, mousex+6, mousey+16+i); + DrawPixel(vid, 0xFF000000, mousex+7, mousey+16+i); + DrawPixel(vid, 0xFF000000, mousex+8, mousey+16+i); + DrawPixel(vid, 0xFFFFFFFF, mousex+9, mousey+16+i); + } + + DrawPixel(vid, 0xFFFFFFFF, mousex+7, mousey+18); + DrawPixel(vid, 0xFFFFFFFF, mousex+8, mousey+18); +} void blit(pixel * vid) { if(sdl_scrn) { + if (depth3d) + DrawCursor(vid); pixel * src = vid; int j, x = 0, y = 0, w = WINDOWW, h = WINDOWH, pitch = WINDOWW; pixel *dst; @@ -208,16 +278,24 @@ void blit(pixel * vid) { //pixel format conversion int i; - pixel px; + pixel px, lastpx, nextpx; SDL_PixelFormat *fmt = sdl_scrn->format; for (j=0; j>fmt->Rloss)<Rshift)| - ((PIXG(px)>>fmt->Gloss)<Gshift)| - ((PIXB(px)>>fmt->Bloss)<Bshift); + if (depth3d) + { + // not supported properly, but give them some effect anyway + lastpx = i >= depth3d && i < w+depth3d ? src[i-depth3d] : 0; + nextpx = i >= -depth3d && i < w-depth3d ? src[i+depth3d] : 0; + dst[i] = ((PIXR(lastpx)>>fmt->Rloss)<Rshift)| + ((PIXG(nextpx)>>fmt->Gloss)<Gshift)| + ((PIXB(nextpx)>>fmt->Bloss)<Bshift); + } + else + dst[i] = src[i]; } dst+=sdl_scrn->pitch/PIXELSIZE; src+=pitch; @@ -225,9 +303,30 @@ void blit(pixel * vid) } else { + int i; + pixel px, lastpx, nextpx; for (j=0; j= depth3d && i < w+depth3d ? src[i-depth3d] : 0; + nextpx = i >= -depth3d && i < w-depth3d ? src[i+depth3d] : 0; + float redshift = PIXB(lastpx)*.3f + PIXG(lastpx)*.3f; + if (redshift > 255*.3f) + redshift = 255*.3f; + float blueshift = PIXR(nextpx)*.3f + PIXG(nextpx)*.3f; + if (blueshift > 255*.3f) + blueshift = 255*.3f; + dst[i] = PIXRGB((int)(PIXR(lastpx)*.69f+redshift), (int)(PIXG(nextpx)*.3f), (int)(PIXB(nextpx)*.69f+blueshift)); + } + else + dst[i] = src[i]; + } + //memcpy(dst, src, w*PIXELSIZE); dst+=sdl_scrn->pitch/PIXELSIZE; src+=pitch; } @@ -241,9 +340,12 @@ void blit2(pixel * vid, int currentScale) { if(sdl_scrn) { + if (depth3d) + DrawCursor(vid); pixel * src = vid; int j, x = 0, y = 0, w = WINDOWW, h = WINDOWH, pitch = WINDOWW; pixel *dst; + pixel px, lastpx, nextpx; int i,k; if (SDL_MUSTLOCK(sdl_scrn)) if (SDL_LockSurface(sdl_scrn)<0) @@ -252,7 +354,6 @@ void blit2(pixel * vid, int currentScale) if (SDL_MapRGB(sdl_scrn->format,0x33,0x55,0x77)!=PIXPACK(0x335577)) { //pixel format conversion - pixel px; SDL_PixelFormat *fmt = sdl_scrn->format; for (j=0; j>fmt->Rloss)<Rshift)| - ((PIXG(px)>>fmt->Gloss)<Gshift)| - ((PIXB(px)>>fmt->Bloss)<Bshift); + if (depth3d) + { + // not supported properly, but give them some effect anyway + lastpx = i >= depth3d/2 && i < w+depth3d/2 ? src[i-depth3d/2] : 0; + nextpx = i >= -depth3d/2 && i < w-depth3d/2 ? src[i+depth3d/2] : 0; + px = ((PIXR(lastpx)>>fmt->Rloss)<Rshift)| + ((PIXG(nextpx)>>fmt->Gloss)<Gshift)| + ((PIXB(nextpx)>>fmt->Bloss)<Bshift); + } dst[i*2]=px; dst[i*2+1]=px; } @@ -280,8 +387,21 @@ void blit2(pixel * vid, int currentScale) { for (i=0; i= depth3d/2 && i < w+depth3d/2 ? src[i-depth3d/2] : 0; + nextpx = i >= -depth3d/2 && i < w-depth3d/2 ? src[i+depth3d/2] : 0; + float redshift = PIXB(lastpx)*.3f + PIXG(lastpx)*.3f; + if (redshift > 255*.3f) + redshift = 255*.3f; + float blueshift = PIXR(nextpx)*.3f + PIXG(nextpx)*.3f; + if (blueshift > 255*.3f) + blueshift = 255*.3f; + px = PIXRGB((int)(PIXR(lastpx)*.69f+redshift), (int)(PIXG(nextpx)*.3f), (int)(PIXB(nextpx)*.69f+blueshift)); + } + dst[i*2] = px; + dst[i*2+1] = px; } dst+=sdl_scrn->pitch/PIXELSIZE; } @@ -488,6 +608,8 @@ void EventProcess(SDL_Event event) break; case SDL_MOUSEMOTION: engine->onMouseMove(event.motion.x*inputScale, event.motion.y*inputScale); + mousex = event.motion.x*inputScale; + mousey = event.motion.y*inputScale; break; case SDL_MOUSEBUTTONDOWN: if (event.button.button == SDL_BUTTON_WHEELUP) @@ -502,10 +624,14 @@ void EventProcess(SDL_Event event) { engine->onMouseClick(event.motion.x*inputScale, event.motion.y*inputScale, event.button.button); } + mousex = event.motion.x*inputScale; + mousey = event.motion.y*inputScale; break; case SDL_MOUSEBUTTONUP: if (event.button.button != SDL_BUTTON_WHEELUP && event.button.button != SDL_BUTTON_WHEELDOWN) engine->onMouseUnclick(event.motion.x*inputScale, event.motion.y*inputScale, event.button.button); + mousex = event.motion.x*inputScale; + mousey = event.motion.y*inputScale; break; #ifdef OGLI case SDL_VIDEORESIZE: @@ -591,6 +717,25 @@ void DoubleScreenDialog() #endif } } + +void ThreeDeeDialog() +{ + std::stringstream message; + message << "We hear your requests, everyone has been asking for a 3D version of TPT. It has long been rejected as 'impossible', but that just isn't true. Many hours of work have been put into finally making a full 3D TPT a reality. "; + message << "\nUpon hitting 'Confirm', 3D mode will enable."; + if (ConfirmPrompt::Blocking("Enable 3D Mode", message.str())) + { + depth3d = -3; + SDL_ShowCursor(0); + new InformationMessage("Success!", "3D Mode enabled!\nYou may disable this at any time in simulation settings for compatibility with 2D saves. I hope you brought your glasses!", false); + } + else + { + ErrorMessage::Blocking("Not using 3D Mode", "You make TPT sad"); + } +} + +bool show3dDialog = true; void EngineProcess() { double frameTimeAvg = 0.0f, correctedFrameTimeAvg = 0.0f; @@ -648,6 +793,11 @@ void EngineProcess() showDoubleScreenDialog = false; DoubleScreenDialog(); } + if (show3dDialog) + { + show3dDialog = false; + ThreeDeeDialog(); + } } #ifdef DEBUG std::cout << "Breaking out of EngineProcess" << std::endl; diff --git a/src/gui/options/OptionsController.cpp b/src/gui/options/OptionsController.cpp index 4c501f1f6..83a547a0c 100644 --- a/src/gui/options/OptionsController.cpp +++ b/src/gui/options/OptionsController.cpp @@ -4,6 +4,7 @@ OptionsController::OptionsController(GameModel * gModel_, ControllerCallback * callback_): gModel(gModel_), callback(callback_), + temp_3ddepth(depth3d), HasExited(false) { view = new OptionsView(); @@ -81,18 +82,33 @@ void OptionsController::SetFastQuit(bool fastquit) model->SetFastQuit(fastquit); } +void OptionsController::Set3dDepth(int depth) +{ + temp_3ddepth = depth; +} + OptionsView * OptionsController::GetView() { return view; } +#ifdef SDL_INC +#include "SDL/SDL.h" +#else +#include "SDL.h" +#endif void OptionsController::Exit() { - if(ui::Engine::Ref().GetWindow() == view) + if (ui::Engine::Ref().GetWindow() == view) { ui::Engine::Ref().CloseWindow(); } - if(callback) + depth3d = temp_3ddepth; + if (depth3d) + SDL_ShowCursor(0); + else + SDL_ShowCursor(1); + if (callback) callback->ControllerExit(); HasExited = true; } diff --git a/src/gui/options/OptionsController.h b/src/gui/options/OptionsController.h index edefeec9f..025d94029 100644 --- a/src/gui/options/OptionsController.h +++ b/src/gui/options/OptionsController.h @@ -14,6 +14,7 @@ class OptionsController { OptionsView * view; OptionsModel * model; ControllerCallback * callback; + int temp_3ddepth; public: bool HasExited; OptionsController(GameModel * gModel_, ControllerCallback * callback_); @@ -28,6 +29,7 @@ public: void SetScale(bool scale); void SetFastQuit(bool fastquit); void SetShowAvatars(bool showAvatars); + void Set3dDepth(int depth); void Exit(); OptionsView * GetView(); virtual ~OptionsController(); diff --git a/src/gui/options/OptionsView.cpp b/src/gui/options/OptionsView.cpp index 869a193ee..fcc01a9bd 100644 --- a/src/gui/options/OptionsView.cpp +++ b/src/gui/options/OptionsView.cpp @@ -14,6 +14,7 @@ #endif #include "OptionsView.h" +#include "Format.h" #include "gui/Style.h" #include "gui/interface/Button.h" #include "gui/interface/Label.h" @@ -21,7 +22,7 @@ #include "gui/dialogues/ErrorMessage.h" OptionsView::OptionsView(): - ui::Window(ui::Point(-1, -1), ui::Point(300, 330)){ + ui::Window(ui::Point(-1, -1), ui::Point(300, 348)){ ui::Label * tempLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 14), "Simulation Options"); tempLabel->SetTextColour(style::Colour::InformationTitle); @@ -217,6 +218,22 @@ OptionsView::OptionsView(): AddComponent(tempLabel); AddComponent(showAvatars); + class DepthAction: public ui::TextboxAction + { + OptionsView * v; + public: + DepthAction(OptionsView * v_) { v = v_; } + virtual void TextChangedCallback(ui::Textbox * sender) { v->c->Set3dDepth(format::StringToNumber(sender->GetText())); } + }; + depthTextbox = new ui::Textbox(ui::Point(8, Size.Y-58), ui::Point(25, 16), format::NumberToString(depth3d)); + depthTextbox->SetInputType(ui::Textbox::Numeric); + depthTextbox->SetActionCallback(new DepthAction(this)); + AddComponent(depthTextbox); + + tempLabel = new ui::Label(ui::Point(depthTextbox->Position.X+depthTextbox->Size.X+3, depthTextbox->Position.Y), ui::Point(Size.X-28, 16), "\bg- Change the depth of the 3d effect"); + tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; + AddComponent(tempLabel); + class DataFolderAction: public ui::ButtonAction { public: diff --git a/src/gui/options/OptionsView.h b/src/gui/options/OptionsView.h index 2bbc3f20d..9ccb68be1 100644 --- a/src/gui/options/OptionsView.h +++ b/src/gui/options/OptionsView.h @@ -5,6 +5,7 @@ #include "OptionsController.h" #include "gui/interface/Checkbox.h" #include "gui/interface/DropDown.h" +#include "gui/interface/Textbox.h" #include "OptionsModel.h" class OptionsModel; @@ -22,6 +23,7 @@ class OptionsView: public ui::Window { ui::Checkbox * fullscreen; ui::Checkbox * fastquit; ui::Checkbox * showAvatars; + ui::Textbox * depthTextbox; public: OptionsView(); void NotifySettingsChanged(OptionsModel * sender); diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index 8898fea8e..5dc399e7f 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -2019,6 +2019,7 @@ void LuaScriptInterface::initRendererAPI() {"decorations", renderer_decorations}, //renderer_debugHUD {"grid", renderer_grid}, {"debugHUD", renderer_debugHUD}, + {"depth3d", renderer_depth3d}, {NULL, NULL} }; luaL_register(l, "renderer", rendererAPIMethods); @@ -2200,6 +2201,18 @@ int LuaScriptInterface::renderer_debugHUD(lua_State * l) return 0; } +int LuaScriptInterface::renderer_depth3d(lua_State * l) +{ + int acount = lua_gettop(l); + if (acount == 0) + { + lua_pushnumber(l, depth3d); + return 1; + } + depth3d = luaL_optint(l, 1, 2); + return 0; +} + void LuaScriptInterface::initElementsAPI() { //Methods diff --git a/src/lua/LuaScriptInterface.h b/src/lua/LuaScriptInterface.h index 105cebfd1..d9a92ee3e 100644 --- a/src/lua/LuaScriptInterface.h +++ b/src/lua/LuaScriptInterface.h @@ -116,6 +116,7 @@ class LuaScriptInterface: public CommandInterface static int renderer_decorations(lua_State * l); static int renderer_grid(lua_State * l); static int renderer_debugHUD(lua_State * l); + static int renderer_depth3d(lua_State * l); //Elements void initElementsAPI();