Skip to content

Commit 2430b2e

Browse files
committedMar 28, 2015
Add Lua function get_video_modes() for main menu
Also updates and uses porting::getSupportedVideoModes()
1 parent 3ef0b4e commit 2430b2e

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed
 

Diff for: ‎src/porting.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -570,16 +570,20 @@ void setXorgClassHint(const video::SExposedVideoData &video_data,
570570
}
571571

572572
#ifndef SERVER
573+
573574
v2u32 getWindowSize()
574575
{
575576
return device->getVideoDriver()->getScreenSize();
576577
}
577578

578579

579-
std::vector<core::vector3d<u32> > getVideoModes()
580+
std::vector<core::vector3d<u32> > getSupportedVideoModes()
580581
{
582+
IrrlichtDevice *nulldevice = createDevice(video::EDT_NULL);
583+
sanity_check(nulldevice != NULL);
584+
581585
std::vector<core::vector3d<u32> > mlist;
582-
video::IVideoModeList *modelist = device->getVideoModeList();
586+
video::IVideoModeList *modelist = nulldevice->getVideoModeList();
583587

584588
u32 num_modes = modelist->getVideoModeCount();
585589
for (u32 i = 0; i != num_modes; i++) {
@@ -588,6 +592,8 @@ std::vector<core::vector3d<u32> > getVideoModes()
588592
mlist.push_back(core::vector3d<u32>(mode_res.Width, mode_res.Height, mode_depth));
589593
}
590594

595+
nulldevice->drop();
596+
591597
return mlist;
592598
}
593599

Diff for: ‎src/porting.h

+1
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ float getDisplayDensity();
371371
v2u32 getDisplaySize();
372372
v2u32 getWindowSize();
373373

374+
std::vector<core::vector3d<u32> > getSupportedVideoModes();
374375
std::vector<irr::video::E_DRIVER_TYPE> getSupportedVideoDrivers();
375376
const char *getVideoDriverName(irr::video::E_DRIVER_TYPE type);
376377
const char *getVideoDriverFriendlyName(irr::video::E_DRIVER_TYPE type);

Diff for: ‎src/script/lua_api/l_mainmenu.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,28 @@ int ModApiMainMenu::l_get_video_drivers(lua_State *L)
10561056
return 1;
10571057
}
10581058

1059+
/******************************************************************************/
1060+
int ModApiMainMenu::l_get_video_modes(lua_State *L)
1061+
{
1062+
std::vector<core::vector3d<u32> > videomodes
1063+
= porting::getSupportedVideoModes();
1064+
1065+
lua_newtable(L);
1066+
for (u32 i = 0; i != videomodes.size(); i++) {
1067+
lua_newtable(L);
1068+
lua_pushnumber(L, videomodes[i].X);
1069+
lua_setfield(L, -2, "w");
1070+
lua_pushnumber(L, videomodes[i].Y);
1071+
lua_setfield(L, -2, "h");
1072+
lua_pushnumber(L, videomodes[i].Z);
1073+
lua_setfield(L, -2, "depth");
1074+
1075+
lua_rawseti(L, -2, i + 1);
1076+
}
1077+
1078+
return 1;
1079+
}
1080+
10591081
/******************************************************************************/
10601082
int ModApiMainMenu::l_gettext(lua_State *L)
10611083
{
@@ -1164,6 +1186,7 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
11641186
API_FCT(sound_stop);
11651187
API_FCT(gettext);
11661188
API_FCT(get_video_drivers);
1189+
API_FCT(get_video_modes);
11671190
API_FCT(get_screen_info);
11681191
API_FCT(get_min_supp_proto);
11691192
API_FCT(get_max_supp_proto);

Diff for: ‎src/script/lua_api/l_mainmenu.h

+2
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ class ModApiMainMenu : public ModApiBase {
137137

138138
static int l_get_video_drivers(lua_State *L);
139139

140+
static int l_get_video_modes(lua_State *L);
141+
140142
//version compatibility
141143
static int l_get_min_supp_proto(lua_State *L);
142144

0 commit comments

Comments
 (0)
Please sign in to comment.