Skip to content

Commit f7c71d6

Browse files
author
Chris Warren-Smith
committed
SDL: avoid flicker moving between screens
1 parent 51ad3c8 commit f7c71d6

4 files changed

Lines changed: 40 additions & 21 deletions

File tree

src/common/brun.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1658,7 +1658,7 @@ int sbasic_exec(const char *file) {
16581658
exec_rq = 0;
16591659
gsb_last_error = 1;
16601660
} else if (gsb_err_mod_perm) {
1661-
exec_rq = 0; // a module is not permitted to be run
1661+
exec_rq = 0; // a module was not permitted to run
16621662
}
16631663

16641664
if (exec_rq) { // we will run it

src/platform/sdl/editor.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ void Runtime::editSource(String loadPath, bool restoreOnExit) {
199199
int h = _output->getHeight();
200200
int charWidth = _output->getCharWidth();
201201
int charHeight = _output->getCharHeight();
202-
int prevScreenId = _output->selectScreen(FORM_SCREEN);
202+
_output->selectScreen(FORM_SCREEN);
203203

204204
TextEditInput *editWidget;
205205
if (_editor != nullptr) {
@@ -267,10 +267,6 @@ void Runtime::editSource(String loadPath, bool restoreOnExit) {
267267
_output->setStatus(!gsb_last_errmsg[0] ? "Error" : gsb_last_errmsg);
268268
}
269269
}
270-
} else if (gsb_err_mod_perm) {
271-
_output->setStatus("Running ...");
272-
saveFile(editWidget, loadPath);
273-
launchConsole(loadPath);
274270
} else {
275271
statusMessage.update(editWidget, _output, true);
276272
}
@@ -604,9 +600,6 @@ void Runtime::editSource(String loadPath, bool restoreOnExit) {
604600

605601
// deletes editWidget and _keypad unless it has been removed
606602
_output->removeInputs();
607-
if (!isClosing() && restoreOnExit) {
608-
_output->selectScreen(prevScreenId, false);
609-
}
610603
logLeaving();
611604
}
612605

src/ui/system.cpp

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ System::System() :
135135
_mainBas(false),
136136
_buttonPressed(false),
137137
_srcRendered(false),
138-
_menuActive(false) {
138+
_menuActive(false),
139+
_compileError(false) {
139140
g_system = this;
140141
}
141142

@@ -150,6 +151,7 @@ System::~System() {
150151
}
151152

152153
bool System::execute(const char *bas) {
154+
_compileError = true;
153155
_stackTrace.removeAll();
154156
reset_image_cache();
155157

@@ -167,6 +169,22 @@ bool System::execute(const char *bas) {
167169
saveWindowRect();
168170

169171
int result = ::sbasic_main(bas);
172+
173+
if (isExternalLaunch()) {
174+
if (_editor != nullptr) {
175+
// returning to the editor
176+
String path(bas);
177+
saveFile(_editor, path);
178+
}
179+
//executeConsole(bas); TODO
180+
}
181+
182+
if (_editor == nullptr) {
183+
_output->selectScreen(USER_SCREEN1);
184+
}
185+
_output->resetFont();
186+
_output->flush(false);
187+
170188
if (isRunning()) {
171189
_state = kActiveState;
172190
}
@@ -864,6 +882,15 @@ void System::runMain(const char *mainBasPath) {
864882

865883
bool success = execute(_loadPath);
866884
bool networkFile = isNetworkLoad();
885+
886+
if (isExternalLaunch()) {
887+
if (_editor == nullptr) {
888+
_loadPath.clear();
889+
_state = kActiveState;
890+
}
891+
continue;
892+
}
893+
867894
if (!isBack() && !isClosing() &&
868895
(success || networkFile || !isEditEnabled())) {
869896
// when editing, only pause here when successful, otherwise the editor shows
@@ -1010,24 +1037,18 @@ void System::setRunning(bool running) {
10101037
if (running) {
10111038
dev_fgcolor = -DEFAULT_FOREGROUND;
10121039
dev_bgcolor = -DEFAULT_BACKGROUND;
1013-
setDimensions();
10141040
dev_clrkb();
10151041

1016-
// setup output screen
1042+
setDimensions();
10171043
showCursor(kArrow);
1018-
_output->setAutoflush(!opt_show_page);
10191044
_output->reset();
1020-
1045+
_output->setAutoflush(!opt_show_page);
1046+
_userScreenId = -1;
1047+
_compileError = false;
10211048
if (_mainBas || isNetworkLoad() || !isEditEnabled()) {
10221049
_loadPath.clear();
10231050
}
1024-
_userScreenId = -1;
10251051
} else {
1026-
// restore output screen
1027-
_output->selectScreen(isEditReady() ? FORM_SCREEN : USER_SCREEN1);
1028-
_output->resetFont();
1029-
_output->flush(false);
1030-
10311052
enableCursor(true);
10321053
osd_clear_sound_queue();
10331054
if (!isClosing() && !isRestart() && !isBack()) {
@@ -1041,8 +1062,11 @@ void System::showCompletion(bool success) {
10411062
if (success) {
10421063
_output->setStatus("Done - press back [<-]");
10431064
} else {
1044-
printErrorLine();
1065+
if (_compileError) {
1066+
_output->reset();
1067+
}
10451068
_output->setStatus("Error - see console");
1069+
printErrorLine();
10461070
showSystemScreen(true);
10471071
}
10481072
_output->flush(true);

src/ui/system.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ struct System {
8686
bool isEditReady() const {return !isRestart() && isEditEnabled() && !isNetworkLoad();}
8787
bool isNetworkLoad() const {return _loadPath.indexOf("://", 1) != -1;}
8888
bool isScratchLoad() const {return _loadPath.indexOf("scratch", 0) != -1;}
89+
bool isExternalLaunch() const { return !gsb_last_error && gsb_err_mod_perm; }
8990
bool loadSource(const char *fileName);
9091
void resize() const;
9192
void runEdit(const char *startupBas);
@@ -144,6 +145,7 @@ struct System {
144145
bool _buttonPressed;
145146
bool _srcRendered;
146147
bool _menuActive;
148+
bool _compileError;
147149
strlib::String _loadPath;
148150
strlib::String _activeFile;
149151
};

0 commit comments

Comments
 (0)