more cleanup so that 3D can stay a more permanent thing

This commit is contained in:
jacob1
2016-04-02 00:10:15 -04:00
parent 30e82851bc
commit aa99258101
9 changed files with 29 additions and 52 deletions

View File

@@ -1,9 +1,9 @@
#pragma once #pragma once
#include <string> #include <string>
extern int depth3d;
void EngineProcess(); void EngineProcess();
void ClipboardPush(std::string text); void ClipboardPush(std::string text);
std::string ClipboardPull(); std::string ClipboardPull();
int GetModifiers(); int GetModifiers();
bool LoadWindowPosition(int scale); bool LoadWindowPosition(int scale);
void SetCursorEnabled(int enabled);

View File

@@ -21,6 +21,7 @@ void EngineProcess() {}
void ClipboardPush(std::string) {} void ClipboardPush(std::string) {}
std::string ClipboardPull() { return ""; } std::string ClipboardPull() { return ""; }
int GetModifiers() { return 0; } int GetModifiers() { return 0; }
void SetCursorEnabled(int enabled) {}
void readFile(std::string filename, std::vector<char> & storage) void readFile(std::string filename, std::vector<char> & storage)
{ {

View File

@@ -1,5 +1,3 @@
int depth3d = 0;
#ifdef USE_SDL #ifdef USE_SDL
#include <map> #include <map>
@@ -49,7 +47,6 @@ extern "C" {
#include "gui/dialogues/ErrorMessage.h" #include "gui/dialogues/ErrorMessage.h"
#include "gui/dialogues/ConfirmPrompt.h" #include "gui/dialogues/ConfirmPrompt.h"
#include "gui/dialogues/InformationMessage.h"
#include "gui/interface/Keys.h" #include "gui/interface/Keys.h"
#include "gui/Style.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) if (x >= 0 && x < WINDOWW && y >= 0 && y < WINDOWH)
vid[x+y*WINDOWW] = color; 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) void DrawCursor(pixel * vid)
{ {
for (int j = 0; j <= 9; j++) for (int j = 0; j <= 9; j++)
@@ -265,6 +262,7 @@ void blit(pixel * vid)
{ {
if (sdl_scrn) if (sdl_scrn)
{ {
int depth3d = ui::Engine::Ref().Get3dDepth();
if (depth3d) if (depth3d)
DrawCursor(vid); DrawCursor(vid);
pixel * src = vid; pixel * src = vid;
@@ -348,6 +346,7 @@ void blit2(pixel * vid, int currentScale)
{ {
if (sdl_scrn) if (sdl_scrn)
{ {
int depth3d = ui::Engine::Ref().Get3dDepth();
if (depth3d) if (depth3d)
DrawCursor(vid); DrawCursor(vid);
pixel * src = vid; pixel * src = vid;
@@ -499,6 +498,11 @@ SDL_Surface * SDLSetScreen(int newScale, bool newFullscreen)
return surface; return surface;
} }
void SetCursorEnabled(int enabled)
{
SDL_ShowCursor(enabled);
}
std::map<std::string, std::string> readArguments(int argc, char * argv[]) std::map<std::string, std::string> readArguments(int argc, char * argv[])
{ {
std::map<std::string, std::string> arguments; std::map<std::string, std::string> 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() void EngineProcess()
{ {
double frameTimeAvg = 0.0f, correctedFrameTimeAvg = 0.0f; double frameTimeAvg = 0.0f, correctedFrameTimeAvg = 0.0f;
@@ -813,11 +799,6 @@ void EngineProcess()
showDoubleScreenDialog = false; showDoubleScreenDialog = false;
DoubleScreenDialog(); DoubleScreenDialog();
} }
if (show3dDialog)
{
show3dDialog = false;
ThreeDeeDialog();
}
} }
#ifdef DEBUG #ifdef DEBUG
std::cout << "Breaking out of EngineProcess" << std::endl; std::cout << "Breaking out of EngineProcess" << std::endl;

View File

@@ -16,6 +16,7 @@ Engine::Engine():
FpsLimit(60.0f), FpsLimit(60.0f),
Scale(1), Scale(1),
Fullscreen(false), Fullscreen(false),
Depth3d(0),
FrameIndex(0), FrameIndex(0),
lastBuffer(NULL), lastBuffer(NULL),
prevBuffers(stack<pixel*>()), prevBuffers(stack<pixel*>()),

View File

@@ -4,6 +4,7 @@
#include "common/Singleton.h" #include "common/Singleton.h"
#include "graphics/Graphics.h" #include "graphics/Graphics.h"
#include "Window.h" #include "Window.h"
#include "PowderToy.h"
namespace ui namespace ui
{ {
@@ -45,6 +46,8 @@ namespace ui
inline bool GetFullscreen() { return Fullscreen; } inline bool GetFullscreen() { return Fullscreen; }
void SetScale(int scale) { Scale = scale; } void SetScale(int scale) { Scale = scale; }
inline int GetScale() { return 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; } void SetFastQuit(bool fastquit) { FastQuit = fastquit; }
inline bool GetFastQuit() {return FastQuit; } inline bool GetFastQuit() {return FastQuit; }
@@ -74,6 +77,7 @@ namespace ui
Graphics * g; Graphics * g;
int Scale; int Scale;
bool Fullscreen; bool Fullscreen;
int Depth3d;
unsigned int FrameIndex; unsigned int FrameIndex;
private: private:

View File

@@ -4,15 +4,14 @@
OptionsController::OptionsController(GameModel * gModel_, ControllerCallback * callback_): OptionsController::OptionsController(GameModel * gModel_, ControllerCallback * callback_):
gModel(gModel_), gModel(gModel_),
callback(callback_), callback(callback_),
temp_3ddepth(depth3d),
HasExited(false) HasExited(false)
{ {
this->depth3d = ui::Engine::Ref().Get3dDepth();
view = new OptionsView(); view = new OptionsView();
model = new OptionsModel(gModel); model = new OptionsModel(gModel);
model->AddObserver(view); model->AddObserver(view);
view->AttachController(this); view->AttachController(this);
} }
void OptionsController::SetHeatSimulation(bool state) void OptionsController::SetHeatSimulation(bool state)
@@ -84,7 +83,7 @@ void OptionsController::SetFastQuit(bool fastquit)
void OptionsController::Set3dDepth(int depth) void OptionsController::Set3dDepth(int depth)
{ {
temp_3ddepth = depth; depth3d = depth;
} }
OptionsView * OptionsController::GetView() OptionsView * OptionsController::GetView()
@@ -92,26 +91,14 @@ OptionsView * OptionsController::GetView()
return view; return view;
} }
#ifdef USE_SDL
#ifdef SDL_INC
#include "SDL/SDL.h"
#else
#include "SDL.h"
#endif
#endif
void OptionsController::Exit() void OptionsController::Exit()
{ {
if (ui::Engine::Ref().GetWindow() == view) if (ui::Engine::Ref().GetWindow() == view)
{ {
ui::Engine::Ref().CloseWindow(); ui::Engine::Ref().CloseWindow();
} }
depth3d = temp_3ddepth; // only update on close, it would be hard to edit if the changes were live
#ifdef USE_SDL ui::Engine::Ref().Set3dDepth(depth3d);
if (depth3d)
SDL_ShowCursor(0);
else
SDL_ShowCursor(1);
#endif
if (callback) if (callback)
callback->ControllerExit(); callback->ControllerExit();
HasExited = true; HasExited = true;

View File

@@ -14,7 +14,7 @@ class OptionsController {
OptionsView * view; OptionsView * view;
OptionsModel * model; OptionsModel * model;
ControllerCallback * callback; ControllerCallback * callback;
int temp_3ddepth; int depth3d;
public: public:
bool HasExited; bool HasExited;
OptionsController(GameModel * gModel_, ControllerCallback * callback_); OptionsController(GameModel * gModel_, ControllerCallback * callback_);

View File

@@ -225,12 +225,12 @@ OptionsView::OptionsView():
DepthAction(OptionsView * v_) { v = v_; } DepthAction(OptionsView * v_) { v = v_; }
virtual void TextChangedCallback(ui::Textbox * sender) { v->c->Set3dDepth(format::StringToNumber<int>(sender->GetText())); } virtual void TextChangedCallback(ui::Textbox * sender) { v->c->Set3dDepth(format::StringToNumber<int>(sender->GetText())); }
}; };
depthTextbox = new ui::Textbox(ui::Point(8, Size.Y-58), ui::Point(25, 16), format::NumberToString<int>(depth3d)); depthTextbox = new ui::Textbox(ui::Point(8, Size.Y-58), ui::Point(25, 16), format::NumberToString<int>(ui::Engine::Ref().Get3dDepth()));
depthTextbox->SetInputType(ui::Textbox::Numeric); depthTextbox->SetInputType(ui::Textbox::Numeric);
depthTextbox->SetActionCallback(new DepthAction(this)); depthTextbox->SetActionCallback(new DepthAction(this));
AddComponent(depthTextbox); 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; tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
AddComponent(tempLabel); AddComponent(tempLabel);

View File

@@ -2206,10 +2206,13 @@ int LuaScriptInterface::renderer_depth3d(lua_State * l)
int acount = lua_gettop(l); int acount = lua_gettop(l);
if (acount == 0) if (acount == 0)
{ {
lua_pushnumber(l, depth3d); lua_pushnumber(l, ui::Engine::Ref().Get3dDepth());
return 1; 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; return 0;
} }