From aa992581013b32fc89aeb9f96ec453c0910e8849 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Sat, 2 Apr 2016 00:10:15 -0400 Subject: [PATCH] more cleanup so that 3D can stay a more permanent thing --- src/PowderToy.h | 2 +- src/PowderToyRenderer.cpp | 1 + src/PowderToySDL.cpp | 39 +++++++-------------------- src/gui/interface/Engine.cpp | 1 + src/gui/interface/Engine.h | 4 +++ src/gui/options/OptionsController.cpp | 21 +++------------ src/gui/options/OptionsController.h | 2 +- src/gui/options/OptionsView.cpp | 4 +-- src/lua/LuaScriptInterface.cpp | 7 +++-- 9 files changed, 29 insertions(+), 52 deletions(-) diff --git a/src/PowderToy.h b/src/PowderToy.h index 506cb71417..16fae8e328 100644 --- a/src/PowderToy.h +++ b/src/PowderToy.h @@ -1,9 +1,9 @@ #pragma once #include -extern int depth3d; void EngineProcess(); void ClipboardPush(std::string text); std::string ClipboardPull(); int GetModifiers(); bool LoadWindowPosition(int scale); +void SetCursorEnabled(int enabled); \ No newline at end of file diff --git a/src/PowderToyRenderer.cpp b/src/PowderToyRenderer.cpp index 303c2c183c..2f8cdf1371 100644 --- a/src/PowderToyRenderer.cpp +++ b/src/PowderToyRenderer.cpp @@ -21,6 +21,7 @@ void EngineProcess() {} void ClipboardPush(std::string) {} std::string ClipboardPull() { return ""; } int GetModifiers() { return 0; } +void SetCursorEnabled(int enabled) {} void readFile(std::string filename, std::vector & storage) { diff --git a/src/PowderToySDL.cpp b/src/PowderToySDL.cpp index 29ad86c9cd..25b98e6170 100644 --- a/src/PowderToySDL.cpp +++ b/src/PowderToySDL.cpp @@ -1,5 +1,3 @@ -int depth3d = 0; - #ifdef USE_SDL #include @@ -49,7 +47,6 @@ 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" @@ -202,7 +199,7 @@ void DrawPixel(pixel * vid, pixel color, int x, int y) if (x >= 0 && x < WINDOWW && y >= 0 && y < WINDOWH) vid[x+y*WINDOWW] = color; } - +// draws a custom cursor, used to make 3D mode work properly (normal cursor ruins the effect) void DrawCursor(pixel * vid) { for (int j = 0; j <= 9; j++) @@ -263,8 +260,9 @@ void DrawCursor(pixel * vid) } void blit(pixel * vid) { - if(sdl_scrn) + if (sdl_scrn) { + int depth3d = ui::Engine::Ref().Get3dDepth(); if (depth3d) DrawCursor(vid); pixel * src = vid; @@ -346,8 +344,9 @@ void blit(pixel * vid) } void blit2(pixel * vid, int currentScale) { - if(sdl_scrn) + if (sdl_scrn) { + int depth3d = ui::Engine::Ref().Get3dDepth(); if (depth3d) DrawCursor(vid); pixel * src = vid; @@ -499,6 +498,11 @@ SDL_Surface * SDLSetScreen(int newScale, bool newFullscreen) return surface; } +void SetCursorEnabled(int enabled) +{ + SDL_ShowCursor(enabled); +} + std::map readArguments(int argc, char * argv[]) { std::map arguments; @@ -738,24 +742,6 @@ void DoubleScreenDialog() } } -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; @@ -813,11 +799,6 @@ 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/interface/Engine.cpp b/src/gui/interface/Engine.cpp index d795bb8ceb..90d0aec2af 100644 --- a/src/gui/interface/Engine.cpp +++ b/src/gui/interface/Engine.cpp @@ -16,6 +16,7 @@ Engine::Engine(): FpsLimit(60.0f), Scale(1), Fullscreen(false), + Depth3d(0), FrameIndex(0), lastBuffer(NULL), prevBuffers(stack()), diff --git a/src/gui/interface/Engine.h b/src/gui/interface/Engine.h index 43feda41c6..ec69f53f2c 100644 --- a/src/gui/interface/Engine.h +++ b/src/gui/interface/Engine.h @@ -4,6 +4,7 @@ #include "common/Singleton.h" #include "graphics/Graphics.h" #include "Window.h" +#include "PowderToy.h" namespace ui { @@ -45,6 +46,8 @@ namespace ui inline bool GetFullscreen() { return Fullscreen; } void SetScale(int scale) { Scale = scale; } inline int GetScale() { return Scale; } + void Set3dDepth(int depth3d) { Depth3d = depth3d; if (Depth3d) SetCursorEnabled(0); else SetCursorEnabled(1);} + inline int Get3dDepth() { return Depth3d; } void SetFastQuit(bool fastquit) { FastQuit = fastquit; } inline bool GetFastQuit() {return FastQuit; } @@ -74,6 +77,7 @@ namespace ui Graphics * g; int Scale; bool Fullscreen; + int Depth3d; unsigned int FrameIndex; private: diff --git a/src/gui/options/OptionsController.cpp b/src/gui/options/OptionsController.cpp index 346cf98c34..74756dea40 100644 --- a/src/gui/options/OptionsController.cpp +++ b/src/gui/options/OptionsController.cpp @@ -4,15 +4,14 @@ OptionsController::OptionsController(GameModel * gModel_, ControllerCallback * callback_): gModel(gModel_), callback(callback_), - temp_3ddepth(depth3d), HasExited(false) { + this->depth3d = ui::Engine::Ref().Get3dDepth(); view = new OptionsView(); model = new OptionsModel(gModel); model->AddObserver(view); view->AttachController(this); - } void OptionsController::SetHeatSimulation(bool state) @@ -84,7 +83,7 @@ void OptionsController::SetFastQuit(bool fastquit) void OptionsController::Set3dDepth(int depth) { - temp_3ddepth = depth; + depth3d = depth; } OptionsView * OptionsController::GetView() @@ -92,26 +91,14 @@ OptionsView * OptionsController::GetView() return view; } -#ifdef USE_SDL -#ifdef SDL_INC -#include "SDL/SDL.h" -#else -#include "SDL.h" -#endif -#endif void OptionsController::Exit() { if (ui::Engine::Ref().GetWindow() == view) { ui::Engine::Ref().CloseWindow(); } - depth3d = temp_3ddepth; -#ifdef USE_SDL - if (depth3d) - SDL_ShowCursor(0); - else - SDL_ShowCursor(1); -#endif + // only update on close, it would be hard to edit if the changes were live + ui::Engine::Ref().Set3dDepth(depth3d); if (callback) callback->ControllerExit(); HasExited = true; diff --git a/src/gui/options/OptionsController.h b/src/gui/options/OptionsController.h index 025d94029b..773a69af1e 100644 --- a/src/gui/options/OptionsController.h +++ b/src/gui/options/OptionsController.h @@ -14,7 +14,7 @@ class OptionsController { OptionsView * view; OptionsModel * model; ControllerCallback * callback; - int temp_3ddepth; + int depth3d; public: bool HasExited; OptionsController(GameModel * gModel_, ControllerCallback * callback_); diff --git a/src/gui/options/OptionsView.cpp b/src/gui/options/OptionsView.cpp index fcc01a9bd9..115a8b7ec7 100644 --- a/src/gui/options/OptionsView.cpp +++ b/src/gui/options/OptionsView.cpp @@ -225,12 +225,12 @@ OptionsView::OptionsView(): 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 = new ui::Textbox(ui::Point(8, Size.Y-58), ui::Point(25, 16), format::NumberToString(ui::Engine::Ref().Get3dDepth())); 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 = 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 glasses effect"); tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; AddComponent(tempLabel); diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index 5dc399e7f9..1b83cc636b 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -2206,10 +2206,13 @@ int LuaScriptInterface::renderer_depth3d(lua_State * l) int acount = lua_gettop(l); if (acount == 0) { - lua_pushnumber(l, depth3d); + lua_pushnumber(l, ui::Engine::Ref().Get3dDepth()); return 1; } - depth3d = luaL_optint(l, 1, 2); + int depth3d = luaL_optint(l, 1, -3); + if (depth3d < -30 || depth3d > 30) + return luaL_error(l, "3D depth is too large"); + ui::Engine::Ref().Set3dDepth(depth3d); return 0; }