Skip to content

Commit

Permalink
more cleanup so that 3D can stay a more permanent thing
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob1 committed Apr 2, 2016
1 parent 30e8285 commit aa99258
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/PowderToy.h
@@ -1,9 +1,9 @@
#pragma once
#include <string>

extern int depth3d;
void EngineProcess();
void ClipboardPush(std::string text);
std::string ClipboardPull();
int GetModifiers();
bool LoadWindowPosition(int scale);
void SetCursorEnabled(int enabled);
1 change: 1 addition & 0 deletions src/PowderToyRenderer.cpp
Expand Up @@ -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<char> & storage)
{
Expand Down
39 changes: 10 additions & 29 deletions src/PowderToySDL.cpp
@@ -1,5 +1,3 @@
int depth3d = 0;

#ifdef USE_SDL

#include <map>
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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++)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -499,6 +498,11 @@ SDL_Surface * SDLSetScreen(int newScale, bool newFullscreen)
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> arguments;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -813,11 +799,6 @@ void EngineProcess()
showDoubleScreenDialog = false;
DoubleScreenDialog();
}
if (show3dDialog)
{
show3dDialog = false;
ThreeDeeDialog();
}
}
#ifdef DEBUG
std::cout << "Breaking out of EngineProcess" << std::endl;
Expand Down
1 change: 1 addition & 0 deletions src/gui/interface/Engine.cpp
Expand Up @@ -16,6 +16,7 @@ Engine::Engine():
FpsLimit(60.0f),
Scale(1),
Fullscreen(false),
Depth3d(0),
FrameIndex(0),
lastBuffer(NULL),
prevBuffers(stack<pixel*>()),
Expand Down
4 changes: 4 additions & 0 deletions src/gui/interface/Engine.h
Expand Up @@ -4,6 +4,7 @@
#include "common/Singleton.h"
#include "graphics/Graphics.h"
#include "Window.h"
#include "PowderToy.h"

namespace ui
{
Expand Down Expand Up @@ -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; }

Expand Down Expand Up @@ -74,6 +77,7 @@ namespace ui
Graphics * g;
int Scale;
bool Fullscreen;
int Depth3d;

unsigned int FrameIndex;
private:
Expand Down
21 changes: 4 additions & 17 deletions src/gui/options/OptionsController.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -84,34 +83,22 @@ void OptionsController::SetFastQuit(bool fastquit)

void OptionsController::Set3dDepth(int depth)
{
temp_3ddepth = depth;
depth3d = depth;
}

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;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/options/OptionsController.h
Expand Up @@ -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_);
Expand Down
4 changes: 2 additions & 2 deletions src/gui/options/OptionsView.cpp
Expand Up @@ -225,12 +225,12 @@ OptionsView::OptionsView():
DepthAction(OptionsView * v_) { v = v_; }
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->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);

Expand Down
7 changes: 5 additions & 2 deletions src/lua/LuaScriptInterface.cpp
Expand Up @@ -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;
}

Expand Down

0 comments on commit aa99258

Please sign in to comment.