Skip to content

Commit

Permalink
Resolution option in the Graphics options
Browse files Browse the repository at this point in the history
* Added "1280x720" option
* Added XGR_Screen::set_resolution method
* Switching resolution on "Resolution" trigger
* Loading "Resolution" option on startup
* curIbs background load2mem fix

  Original background loads (draws) into the video buffer assuming that video buffer size and background size are equal. That's not true for 800x600 background and 1280x720 resolution, which gives noise at the empty parts

  This would be overriden anyway in the following commits where there's no fixed background image, but 4 different parts.
  • Loading branch information
lpenguin committed Jul 6, 2020
1 parent 57b22ef commit 9c063ac
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 12 deletions.
17 changes: 9 additions & 8 deletions data/iscreen/scripts/mainmenu.scr
Original file line number Diff line number Diff line change
Expand Up @@ -1702,10 +1702,10 @@ Screen "Graphics screen"
}
}
}
/*Object "ResStr"
Object "ResStr"
{
x $RESOLUTION_STR_X
y { $GRAPHICS_SCR_START_Y + $GRAPHICS_SCR_DELTA_Y * 2 }
y { $GRAPHICS_SCR_START_Y + $GRAPHICS_SCR_DELTA_Y * 5 }

Element STRING {
align_x center
Expand All @@ -1717,10 +1717,11 @@ Screen "Graphics screen"
null_level $DEFAULT_NULL
string $iSTR_SCREEN
}
}*/
}
Trigger "ResTrig" {
// TODO: change x offset
x $RESOLUTION_TRG_X
y { $GRAPHICS_SCR_START_Y + $GRAPHICS_SCR_DELTA_Y * 2 }
y { $GRAPHICS_SCR_START_Y + $GRAPHICS_SCR_DELTA_Y * 5 }

num_state 2

Expand All @@ -1734,10 +1735,11 @@ Screen "Graphics screen"
space $OPTION_SPACE
terrain_num $TERRAIN4

/*string $iSTR_800x600*/
string ""
// TODO: string constant
string "1280x720"
null_level $DEFAULT_NULL
}

State 0 "STRING"{
align_x center
align_y center
Expand All @@ -1746,8 +1748,7 @@ Screen "Graphics screen"
space $OPTION_SPACE
terrain_num $TERRAIN4

/*string $iSTR_640x480*/
string ""
string $iSTR_800x600
null_level $DEFAULT_NULL
}
Event {
Expand Down
51 changes: 51 additions & 0 deletions lib/xgraph/xgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,57 @@ int XGR_Screen::init(int x,int y,int flags_in)
return false;
}

void XGR_Screen::set_resolution(int width, int height){
// TODO: do not change resolution, is new res is the same
std::cout<<"XGR_Screen::set_resolution: "<<width<<", "<<height<<std::endl;

std::cout<<"XGR_ScreenSurface = SDL_CreateRGBSurface"<<std::endl;
XGR_ScreenSurface = SDL_CreateRGBSurface(0, width, height, 8, 0, 0, 0, 0);

std::cout<<"XGR32_ScreenSurface = SDL_CreateRGBSurface"<<std::endl;
XGR32_ScreenSurface = SDL_CreateRGBSurface(0, width, height, 32, 0, 0, 0, 0);

std::cout<<"SDL_SetSurfacePalette"<<std::endl;
SDL_SetSurfacePalette(XGR_ScreenSurface, XGR_Palette);


std::cout<<"SDL_CreateTexture sdlTexture"<<std::endl;
sdlTexture = SDL_CreateTexture(sdlRenderer,
SDL_PIXELFORMAT_ARGB8888, //SDL_PIXELFORMAT_INDEX8,
SDL_TEXTUREACCESS_STREAMING,
width, height);

SDL_SetWindowSize(sdlWindow, width, height);
SDL_GetWindowSize(sdlWindow, &RealX, &RealY);

// TODO: do the right centering
// if (!XGR_FULL_SCREEN) {
// SDL_SetWindowPosition(sdlWindow, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
// } else {
// SDL_SetWindowPosition(sdlWindow, 0, 0);
// }

// TODO(amdmi3): assuming safe locking; otherwise, use additional surface + SDL_MapRGB
std::cout<<"SDL_LockSurface"<<std::endl;
if (SDL_LockSurface(XGR_ScreenSurface) < 0)
ErrH.Abort(SDL_GetError(),XERR_USER, 0);

ScreenBuf = (unsigned char*)XGR_ScreenSurface->pixels;

// Other initializations
ScreenX = xgrScreenSizeX = XGR_ScreenSurface->w;
ScreenY = xgrScreenSizeY = XGR_ScreenSurface->h;

if(yOffsTable) delete[] yOffsTable;
yOffsTable = new int[ScreenY + 1];
set_pitch(XGR_ScreenSurface->pitch);


set_clip(0,0, width, height);
set_clip_mode(XGR_CLIP_PUTSPR);

}

void XGR_Screen::set_fullscreen(bool fullscreen) {
if (fullscreen!=XGR_FULL_SCREEN) {
SDL_SetWindowFullscreen(sdlWindow, fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
Expand Down
2 changes: 1 addition & 1 deletion lib/xgraph/xgraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ struct XGR_Screen
void set_clip_mode(int mode){ ClipMode = mode; }

void set_fullscreen(bool fullscreen);

void set_resolution(int width, int height);
void setpixel(int x,int y,int col);
int getpixel(int x,int y);

Expand Down
3 changes: 2 additions & 1 deletion src/actint/actint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3253,7 +3253,8 @@ void actIntDispatcher::redraw(void)
}
if(!(flags & AS_FULL_REDRAW)){
XGR_MouseObj.flags &= ~XGM_PROMPT_ACTIVE;
curIbs -> back -> load2mem(XGR_VIDEOBUF);
curIbs -> back -> load(NULL, 1);
curIbs -> back -> show(0);
if(curMode == AS_INV_MODE && curMatrix && curMatrix -> back){
curMatrix -> back -> load();
XGR_PutSpr(curMatrix -> back -> OffsX,curMatrix -> back -> OffsY,curMatrix -> back -> SizeX,curMatrix -> back -> SizeY,curMatrix -> back -> frames,XGR_BLACK_FON);
Expand Down
19 changes: 18 additions & 1 deletion src/iscreen/iextern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ void iUnlockMultiGameParameters(void);

void iUpdateMultiGameName(void);


void put_map(int x, int y, int sizeX, int sizeY);

/* --------------------------- DEFINITION SECTION --------------------------- */

int* AVI_index;
Expand Down Expand Up @@ -648,6 +651,19 @@ void iSetFullscreen(int state) {
XGR_Obj.set_fullscreen(state);
}

void iSetResolution(int state) {
switch(state){
case 0:
XGR_Obj.set_resolution(800, 600);
break;
case 1:
XGR_Obj.set_resolution(1280, 720);
break;

}
put_map(iScreenOffs,0,I_RES_X,I_RES_Y);
}

void iPrepareOptions(void)
{
int i;
Expand Down Expand Up @@ -764,7 +780,8 @@ void iPrepareOptions(void)

iScrOpt[iFULLSCREEN] = new iScreenOption(iTRIGGER,0,"Graphics screen","FullScreenTrig");
((iTriggerObject *)iScrOpt[iFULLSCREEN]->objPtr)->callback = &iSetFullscreen;

((iTriggerObject *)iScrOpt[iSCREEN_RESOLUTION]->objPtr)->callback = &iSetResolution;

iPrepareControls();
}

Expand Down
1 change: 1 addition & 0 deletions src/iscreen/iscreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,7 @@ extern iScreenDispatcher* iScrDisp;

void iInit(void);
void iQuantFirst(void);
void iSetResolution(int state);
void iQuantPrepare(void);
int iQuantSecond(void);
void iFinitQuant(void);
Expand Down
2 changes: 1 addition & 1 deletion src/road.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,6 @@ void showModal(char* fname, float reelW, float reelH, float screenW, float scree
}



int xtInitApplication(void) {
XGraphWndID = "VANGERS";
char *tmp;
Expand Down Expand Up @@ -712,6 +711,7 @@ _MEM_STATISTIC_("AFTER IQUANTFIRST INIT -> ");
#endif

XGR_Obj.set_fullscreen(iGetOptionValue(iFULLSCREEN));
iSetResolution(iGetOptionValue(iSCREEN_RESOLUTION));
_MEM_STATISTIC_("AFTER MAIN MENU INIT -> ");
}

Expand Down

0 comments on commit 9c063ac

Please sign in to comment.