Skip to content
This repository has been archived by the owner on May 19, 2022. It is now read-only.

Commit

Permalink
Fix launch flicker
Browse files Browse the repository at this point in the history
Also some respacing (thanks windows).

The "rerender" function just redraws textures without recalculating
them. This fixes the flicker problem and makes resizing, exposing, etc a
bit more
efficient too.
  • Loading branch information
euank committed Mar 19, 2014
1 parent e1f17f4 commit 6f3e618
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 30 deletions.
12 changes: 6 additions & 6 deletions src/PonscripterLabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1184,9 +1184,10 @@ void PonscripterLabel::resetSentenceFont()
sentence_font_info.pos.h = screen_height;
}

void PonscripterLabel::renderSurface(SDL_Surface *surface) {
//SDL_Texture *tex = SDL_CreateTextureFromSurface(renderer, surface);
//SDL_RenderCopy(renderer,
void PonscripterLabel::rerender() {
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, screen_tex, NULL, NULL);
SDL_RenderPresent(renderer);
}

void PonscripterLabel::flush(int refresh_mode, SDL_Rect* rect, bool clear_dirty_flag,
Expand Down Expand Up @@ -1227,9 +1228,8 @@ void PonscripterLabel::flushDirect(SDL_Rect &rect, int refresh_mode, bool update
if(SDL_UpdateTexture(screen_tex, NULL, screen_surface->pixels, screen_surface->pitch)) {
fprintf(stderr,"Error updating texture: %s\n", SDL_GetError());
}
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, screen_tex, NULL, NULL);
SDL_RenderPresent(renderer);

rerender();
}


Expand Down
29 changes: 15 additions & 14 deletions src/PonscripterLabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class PonscripterLabel : public ScriptParser {

PonscripterLabel();
~PonscripterLabel();

// ----------------------------------------
// start-up options
void enableCDAudio();
Expand All @@ -125,7 +125,7 @@ class PonscripterLabel : public ScriptParser {
void setKeyEXE(const char* path);
void setGameIdentifier(const char *gameid);
void setMaskType(int mask_type) { png_mask_type = mask_type; }

int init(const char* preferred_script);
int eventLoop();

Expand Down Expand Up @@ -156,7 +156,7 @@ class PonscripterLabel : public ScriptParser {
int haeleth_sayCommand(const pstring& cmd);
int gettextspeedCommand(const pstring& cmd);
int vsp_whenCommand(const pstring& cmd);

//Mion: locale support
int localestringCommand(const pstring& cmd);
void initLocale();
Expand Down Expand Up @@ -290,7 +290,7 @@ class PonscripterLabel : public ScriptParser {
int drawbgCommand(const pstring& cmd);
int drawCommand(const pstring& cmd);
int delayCommand(const pstring& cmd);
int deletescreenshotCommand(const pstring& cmd);
int deletescreenshotCommand(const pstring& cmd);
int defineresetCommand(const pstring& cmd);
int cspCommand(const pstring& cmd);
int cselgotoCommand(const pstring& cmd);
Expand Down Expand Up @@ -486,7 +486,7 @@ class PonscripterLabel : public ScriptParser {
typedef std::map<int, ButtonElt> collection;
typedef collection::iterator iterator;
typedef collection::reverse_iterator reverse_iterator;

enum BUTTON_TYPE {
NORMAL_BUTTON = 0,
SPRITE_BUTTON = 1,
Expand All @@ -505,7 +505,7 @@ class PonscripterLabel : public ScriptParser {
bool isSprite() { return button_type == SPRITE_BUTTON
|| button_type == EX_SPRITE_BUTTON; }
bool isTmpSprite() { return button_type == TMP_SPRITE_BUTTON; }

ButtonElt() {
button_type = NORMAL_BUTTON;
anim[0] = anim[1] = 0;
Expand All @@ -531,15 +531,15 @@ class PonscripterLabel : public ScriptParser {
else
++it;
}

void deleteButtons() {
for (ButtonElt::iterator it = buttons.begin(); it != buttons.end();
++it)
it->second.destroy();
buttons.clear();
exbtn_d_button.exbtn_ctl.trunc(0);
}

int current_over_button;

bool getzxc_flag;
Expand Down Expand Up @@ -589,7 +589,7 @@ class PonscripterLabel : public ScriptParser {
AnimationInfo* sprite2_info;
bool all_sprite_hide_flag;
bool all_sprite2_hide_flag;

/* ---------------------------------------- */
/* Parameter related variables */
AnimationInfo* bar_info[MAX_PARAM_NUM];
Expand Down Expand Up @@ -621,7 +621,7 @@ class PonscripterLabel : public ScriptParser {
int w_left, w_top, w_right, w_bottom;
};
WindowDef::dic stored_windows;

/* ---------------------------------------- */
/* Text related variables */
AnimationInfo text_info;
Expand Down Expand Up @@ -658,7 +658,7 @@ class PonscripterLabel : public ScriptParser {
AnimationInfo* cache_info = 0)
{ /- for now -/ drawString(str, color, info, flush_flag,
surface, rect, cache_info); }*/

void restoreTextBuffer();
int enterTextDisplayMode(bool text_flag = true);
int leaveTextDisplayMode(bool force_leave_flag = false);
Expand Down Expand Up @@ -760,7 +760,7 @@ class PonscripterLabel : public ScriptParser {

int playSound(const pstring& filename, int format, bool loop_flag,
int channel = 0);

void playCDAudio();
int playWave(Mix_Chunk* chunk, int format, bool loop_flag, int channel);
int playMP3();
Expand Down Expand Up @@ -797,10 +797,11 @@ class PonscripterLabel : public ScriptParser {
void clearCurrentTextBuffer();
void newPage(bool next_flag);

void rerender();
void flush(int refresh_mode, SDL_Rect* rect = 0,
bool clear_dirty_flag = true, bool direct_flag = false);
void flushDirect(SDL_Rect &rect, int refresh_mode, bool updaterect = true);
void renderSurface(SDL_Surface*);

void executeLabel();
int parseLine();

Expand All @@ -820,7 +821,7 @@ class PonscripterLabel : public ScriptParser {
/* ---------------------------------------- */
/* File I/O */
enum SaveFileType { NScripter, ONScripter, Ponscripter };

void searchSaveFile(SaveFileInfo &info, int no);
int loadSaveFile(int no);
void saveMagicNumber(bool output_flag);
Expand Down
17 changes: 7 additions & 10 deletions src/PonscripterLabel_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ void PonscripterLabel::mousePressEvent(SDL_MouseButtonEvent* event)
volatile_button_state.button = current_over_button;
//#ifdef SKIP_TO_WAIT
if (event_mode & WAIT_SLEEP_MODE) skip_to_wait = 1;
//#endif
//#endif

if (event->type == SDL_MOUSEBUTTONDOWN)
current_button_state.down_flag = true;
Expand Down Expand Up @@ -651,7 +651,7 @@ void PonscripterLabel::variableEditMode(SDL_KeyboardEvent* event)
else if (variable_edit_mode >= EDIT_VARIABLE_NUM_MODE) {
int p = 0;
pstring var_name;

switch (variable_edit_mode) {
case EDIT_VARIABLE_NUM_MODE:
var_name.format("%%%d", variable_edit_index);
Expand Down Expand Up @@ -705,7 +705,7 @@ void PonscripterLabel::shiftCursorOnButton(int diff)
}
}
ButtonElt& e = shortcut_mouse_line->second;

int x = e.select_rect.x + e.select_rect.w / 2;
int y = e.select_rect.y + e.select_rect.h / 2;
if (x < 0) x = 0; else if (x >= screen_width) x = screen_width - 1;
Expand Down Expand Up @@ -829,7 +829,7 @@ void PonscripterLabel::keyPressEvent(SDL_KeyboardEvent* event)
event->keysym.sym == SDLK_KP_ENTER ||
(spclclk_flag && event->keysym.sym == SDLK_SPACE))
{
current_button_state.button =
current_button_state.button =
volatile_button_state.button = current_over_button;
if (event->type == SDL_KEYDOWN)
current_button_state.down_flag = true;
Expand Down Expand Up @@ -867,7 +867,7 @@ void PonscripterLabel::keyPressEvent(SDL_KeyboardEvent* event)
event->keysym.sym == SDLK_h) &&
(event_mode & WAIT_TEXT_MODE ||
(usewheel_flag && !getcursor_flag &&
event_mode & WAIT_BUTTON_MODE) ||
event_mode & WAIT_BUTTON_MODE) ||
system_menu_mode == SYSTEM_LOOKBACK))
{
current_button_state.button = -2;
Expand Down Expand Up @@ -1261,14 +1261,11 @@ int PonscripterLabel::eventLoop()
case SDL_WINDOWEVENT_FOCUS_LOST:
break;
case SDL_WINDOWEVENT_EXPOSED:

//Resize when window changes size
case SDL_WINDOWEVENT_MAXIMIZED:
case SDL_WINDOWEVENT_RESTORED:
case SDL_WINDOWEVENT_RESIZED:

//Direct flush the whole window
flush(refreshMode(), NULL, false, true);
//Make sure the texture gets stretched or whatever else need be done
rerender();
break;
}
break;
Expand Down

0 comments on commit 6f3e618

Please sign in to comment.