Further improvements to overall system stability and other minor adjustments have been made to enhance the user experience

This commit is contained in:
jacob1 2016-03-31 22:08:04 -04:00
parent 535ade0ec4
commit 46d096206f
8 changed files with 216 additions and 14 deletions

View File

@ -1,6 +1,7 @@
#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();

View File

@ -47,6 +47,7 @@ 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"
@ -66,6 +67,7 @@ SDL_SysWMinfo sdl_wminfo;
Atom XA_CLIPBOARD, XA_TARGETS, XA_UTF8_STRING; Atom XA_CLIPBOARD, XA_TARGETS, XA_UTF8_STRING;
#endif #endif
int depth3d = 0;
std::string clipboardText = ""; std::string clipboardText = "";
int desktopWidth = 1280, desktopHeight = 1024; int desktopWidth = 1280, desktopHeight = 1024;
@ -193,10 +195,78 @@ void blit()
SDL_GL_SwapBuffers(); SDL_GL_SwapBuffers();
} }
#else #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) void blit(pixel * vid)
{ {
if(sdl_scrn) if(sdl_scrn)
{ {
if (depth3d)
DrawCursor(vid);
pixel * src = vid; pixel * src = vid;
int j, x = 0, y = 0, w = WINDOWW, h = WINDOWH, pitch = WINDOWW; int j, x = 0, y = 0, w = WINDOWW, h = WINDOWH, pitch = WINDOWW;
pixel *dst; pixel *dst;
@ -208,16 +278,24 @@ void blit(pixel * vid)
{ {
//pixel format conversion //pixel format conversion
int i; int i;
pixel px; pixel px, lastpx, nextpx;
SDL_PixelFormat *fmt = sdl_scrn->format; SDL_PixelFormat *fmt = sdl_scrn->format;
for (j=0; j<h; j++) for (j=0; j<h; j++)
{ {
for (i=0; i<w; i++) for (i=0; i<w; i++)
{ {
px = src[i]; px = src[i];
dst[i] = ((PIXR(px)>>fmt->Rloss)<<fmt->Rshift)| if (depth3d)
((PIXG(px)>>fmt->Gloss)<<fmt->Gshift)| {
((PIXB(px)>>fmt->Bloss)<<fmt->Bshift); // 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)<<fmt->Rshift)|
((PIXG(nextpx)>>fmt->Gloss)<<fmt->Gshift)|
((PIXB(nextpx)>>fmt->Bloss)<<fmt->Bshift);
}
else
dst[i] = src[i];
} }
dst+=sdl_scrn->pitch/PIXELSIZE; dst+=sdl_scrn->pitch/PIXELSIZE;
src+=pitch; src+=pitch;
@ -225,9 +303,30 @@ void blit(pixel * vid)
} }
else else
{ {
int i;
pixel px, lastpx, nextpx;
for (j=0; j<h; j++) for (j=0; j<h; j++)
{ {
memcpy(dst, src, w*PIXELSIZE); for (i=0; i<w; i++)
{
px = src[i];
if (depth3d)
{
lastpx = i >= 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; dst+=sdl_scrn->pitch/PIXELSIZE;
src+=pitch; src+=pitch;
} }
@ -241,9 +340,12 @@ void blit2(pixel * vid, int currentScale)
{ {
if(sdl_scrn) if(sdl_scrn)
{ {
if (depth3d)
DrawCursor(vid);
pixel * src = vid; pixel * src = vid;
int j, x = 0, y = 0, w = WINDOWW, h = WINDOWH, pitch = WINDOWW; int j, x = 0, y = 0, w = WINDOWW, h = WINDOWH, pitch = WINDOWW;
pixel *dst; pixel *dst;
pixel px, lastpx, nextpx;
int i,k; int i,k;
if (SDL_MUSTLOCK(sdl_scrn)) if (SDL_MUSTLOCK(sdl_scrn))
if (SDL_LockSurface(sdl_scrn)<0) 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)) if (SDL_MapRGB(sdl_scrn->format,0x33,0x55,0x77)!=PIXPACK(0x335577))
{ {
//pixel format conversion //pixel format conversion
pixel px;
SDL_PixelFormat *fmt = sdl_scrn->format; SDL_PixelFormat *fmt = sdl_scrn->format;
for (j=0; j<h; j++) for (j=0; j<h; j++)
{ {
@ -261,9 +362,15 @@ void blit2(pixel * vid, int currentScale)
for (i=0; i<w; i++) for (i=0; i<w; i++)
{ {
px = src[i]; px = src[i];
px = ((PIXR(px)>>fmt->Rloss)<<fmt->Rshift)| if (depth3d)
((PIXG(px)>>fmt->Gloss)<<fmt->Gshift)| {
((PIXB(px)>>fmt->Bloss)<<fmt->Bshift); // 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)<<fmt->Rshift)|
((PIXG(nextpx)>>fmt->Gloss)<<fmt->Gshift)|
((PIXB(nextpx)>>fmt->Bloss)<<fmt->Bshift);
}
dst[i*2]=px; dst[i*2]=px;
dst[i*2+1]=px; dst[i*2+1]=px;
} }
@ -280,8 +387,21 @@ void blit2(pixel * vid, int currentScale)
{ {
for (i=0; i<w; i++) for (i=0; i<w; i++)
{ {
dst[i*2]=src[i]; px = src[i];
dst[i*2+1]=src[i]; if (depth3d)
{
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;
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; dst+=sdl_scrn->pitch/PIXELSIZE;
} }
@ -488,6 +608,8 @@ void EventProcess(SDL_Event event)
break; break;
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
engine->onMouseMove(event.motion.x*inputScale, event.motion.y*inputScale); engine->onMouseMove(event.motion.x*inputScale, event.motion.y*inputScale);
mousex = event.motion.x*inputScale;
mousey = event.motion.y*inputScale;
break; break;
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
if (event.button.button == SDL_BUTTON_WHEELUP) 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); engine->onMouseClick(event.motion.x*inputScale, event.motion.y*inputScale, event.button.button);
} }
mousex = event.motion.x*inputScale;
mousey = event.motion.y*inputScale;
break; break;
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
if (event.button.button != SDL_BUTTON_WHEELUP && event.button.button != SDL_BUTTON_WHEELDOWN) 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); engine->onMouseUnclick(event.motion.x*inputScale, event.motion.y*inputScale, event.button.button);
mousex = event.motion.x*inputScale;
mousey = event.motion.y*inputScale;
break; break;
#ifdef OGLI #ifdef OGLI
case SDL_VIDEORESIZE: case SDL_VIDEORESIZE:
@ -591,6 +717,25 @@ void DoubleScreenDialog()
#endif #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() void EngineProcess()
{ {
double frameTimeAvg = 0.0f, correctedFrameTimeAvg = 0.0f; double frameTimeAvg = 0.0f, correctedFrameTimeAvg = 0.0f;
@ -648,6 +793,11 @@ 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

@ -4,6 +4,7 @@
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)
{ {
view = new OptionsView(); view = new OptionsView();
@ -81,18 +82,33 @@ void OptionsController::SetFastQuit(bool fastquit)
model->SetFastQuit(fastquit); model->SetFastQuit(fastquit);
} }
void OptionsController::Set3dDepth(int depth)
{
temp_3ddepth = depth;
}
OptionsView * OptionsController::GetView() OptionsView * OptionsController::GetView()
{ {
return view; return view;
} }
#ifdef SDL_INC
#include "SDL/SDL.h"
#else
#include "SDL.h"
#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();
} }
if(callback) depth3d = temp_3ddepth;
if (depth3d)
SDL_ShowCursor(0);
else
SDL_ShowCursor(1);
if (callback)
callback->ControllerExit(); callback->ControllerExit();
HasExited = true; HasExited = true;
} }

View File

@ -14,6 +14,7 @@ class OptionsController {
OptionsView * view; OptionsView * view;
OptionsModel * model; OptionsModel * model;
ControllerCallback * callback; ControllerCallback * callback;
int temp_3ddepth;
public: public:
bool HasExited; bool HasExited;
OptionsController(GameModel * gModel_, ControllerCallback * callback_); OptionsController(GameModel * gModel_, ControllerCallback * callback_);
@ -28,6 +29,7 @@ public:
void SetScale(bool scale); void SetScale(bool scale);
void SetFastQuit(bool fastquit); void SetFastQuit(bool fastquit);
void SetShowAvatars(bool showAvatars); void SetShowAvatars(bool showAvatars);
void Set3dDepth(int depth);
void Exit(); void Exit();
OptionsView * GetView(); OptionsView * GetView();
virtual ~OptionsController(); virtual ~OptionsController();

View File

@ -14,6 +14,7 @@
#endif #endif
#include "OptionsView.h" #include "OptionsView.h"
#include "Format.h"
#include "gui/Style.h" #include "gui/Style.h"
#include "gui/interface/Button.h" #include "gui/interface/Button.h"
#include "gui/interface/Label.h" #include "gui/interface/Label.h"
@ -21,7 +22,7 @@
#include "gui/dialogues/ErrorMessage.h" #include "gui/dialogues/ErrorMessage.h"
OptionsView::OptionsView(): 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"); ui::Label * tempLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 14), "Simulation Options");
tempLabel->SetTextColour(style::Colour::InformationTitle); tempLabel->SetTextColour(style::Colour::InformationTitle);
@ -217,6 +218,22 @@ OptionsView::OptionsView():
AddComponent(tempLabel); AddComponent(tempLabel);
AddComponent(showAvatars); 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<int>(sender->GetText())); }
};
depthTextbox = new ui::Textbox(ui::Point(8, Size.Y-58), ui::Point(25, 16), format::NumberToString<int>(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 class DataFolderAction: public ui::ButtonAction
{ {
public: public:

View File

@ -5,6 +5,7 @@
#include "OptionsController.h" #include "OptionsController.h"
#include "gui/interface/Checkbox.h" #include "gui/interface/Checkbox.h"
#include "gui/interface/DropDown.h" #include "gui/interface/DropDown.h"
#include "gui/interface/Textbox.h"
#include "OptionsModel.h" #include "OptionsModel.h"
class OptionsModel; class OptionsModel;
@ -22,6 +23,7 @@ class OptionsView: public ui::Window {
ui::Checkbox * fullscreen; ui::Checkbox * fullscreen;
ui::Checkbox * fastquit; ui::Checkbox * fastquit;
ui::Checkbox * showAvatars; ui::Checkbox * showAvatars;
ui::Textbox * depthTextbox;
public: public:
OptionsView(); OptionsView();
void NotifySettingsChanged(OptionsModel * sender); void NotifySettingsChanged(OptionsModel * sender);

View File

@ -2019,6 +2019,7 @@ void LuaScriptInterface::initRendererAPI()
{"decorations", renderer_decorations}, //renderer_debugHUD {"decorations", renderer_decorations}, //renderer_debugHUD
{"grid", renderer_grid}, {"grid", renderer_grid},
{"debugHUD", renderer_debugHUD}, {"debugHUD", renderer_debugHUD},
{"depth3d", renderer_depth3d},
{NULL, NULL} {NULL, NULL}
}; };
luaL_register(l, "renderer", rendererAPIMethods); luaL_register(l, "renderer", rendererAPIMethods);
@ -2200,6 +2201,18 @@ int LuaScriptInterface::renderer_debugHUD(lua_State * l)
return 0; 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() void LuaScriptInterface::initElementsAPI()
{ {
//Methods //Methods

View File

@ -116,6 +116,7 @@ class LuaScriptInterface: public CommandInterface
static int renderer_decorations(lua_State * l); static int renderer_decorations(lua_State * l);
static int renderer_grid(lua_State * l); static int renderer_grid(lua_State * l);
static int renderer_debugHUD(lua_State * l); static int renderer_debugHUD(lua_State * l);
static int renderer_depth3d(lua_State * l);
//Elements //Elements
void initElementsAPI(); void initElementsAPI();