Merge lp:~der-treba/stratagus/stratagus into lp:stratagus
- stratagus
- Merge into trunk
Status: | Needs review |
---|---|
Proposed branch: | lp:~der-treba/stratagus/stratagus |
Merge into: | lp:stratagus |
Diff against target: |
360 lines (+188/-85) 5 files modified
src/game/game.cpp (+1/-0) src/include/video.h (+2/-0) src/stratagus/stratagus.cpp (+3/-0) src/video/sdl.cpp (+108/-85) src/video/video.cpp (+74/-0) |
To merge this branch: | bzr merge lp:~der-treba/stratagus/stratagus |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Pali | Needs Fixing | ||
treba | Pending | ||
Review via email: mp+159972@code.launchpad.net |
Commit message
Description of the change
Hello,
i made some small changes to the engine that allow us to get the native resolution of the screen within lua and let's us determine all available resolutions.
examples:
local defaultPreferences = {
...
VideoWidth = GetCurrentResol
VideoHeight = GetCurrentResol
...
}
for i=0,GetVideoRes
print(
end
i hope the code quality is ok. i only tested it on linux, but to me, it seems to be quite solid.
- 8698. By treba
-
- removed declarations of lua bindings from video.h
- replaced resolution calls with the following two:
GetCurrentResolution( ) -- array with width and height of current resolution. if called at startup, the optimal resolution is given
GetAvailableResolutions( ) -- two dimensional array with available resolutions. in window mode gives nil
Travis (dinky-dye-aussie) wrote : | # |
So where do I put this code to make it work in the game? I would like to see what this code does so how can we get it working?
Joris Dauphin (joris-dauphin) wrote : | # |
Look better.
Maybe GetCurrentResol
videoWidth, videoHeight = GetCurrentResol
It seems that atexit(SDL_Quit) may be called twice.
treba (der-treba) wrote : | # |
> So where do I put this code to make it work in the game? I would like to see
> what this code does so how can we get it working?
i'm not sure if i'm getting your question, but if it is about how you can use it inside the game:
well, you can use it for example in the stratagus.lua:
...
local defaultPreferences = {
...
VideoWidth = GetCurrentResol
VideoHeight = GetCurrentResol
...
}
...
that will give you your native resolution as default. so if the game supports it and you don't specify a particular resolution, you will always have the native one, regardles what monitor you are using.
GetAvailableRes
this will print them to stdout:
if GetAvailableRes
for _,v in ipairs(
print(
end
end
treba (der-treba) wrote : | # |
> Look better.
> Maybe GetCurrentResol
>
> videoWidth, videoHeight = GetCurrentResol
>
>
>
> It seems that atexit(SDL_Quit) may be called twice.
for the first part: good idea.
the second one: i didn't really get what atexit(SDL_Quit) actually does (and when). can you help me with that one?
Travis (dinky-dye-aussie) wrote : | # |
Yeah this things isn't working. I got an stderr output for you. I placed the lines you detailed treba in the stratagus.lua file in the preferences sectoion, as follows.
local defaultPreferences = {
CampaignHuman = 1,
CampaignHumanX = 1,
CampaignOrc = 1,
CampaignOrcX = 1,
DoubleClickDel
EffectsEnabled = true,
EffectsVolume = 128,
EnableKeyboard
EnableMouseScr
FogOfWar = true,
FogOfWarOpacity = 128,
GameSpeed = 30,
GameTranslation = "",
GrabMouse = false,
GroupKeys = "0123456789`",
HoldClickDelayInMs = 1000,
LeaveStopScrolling = true,
MaxOpenGLTexture = 0,
MinimapWithTerrain = true,
MouseScrollSpeed = 1,
MouseScrollSpe
MouseScrollSpe
MusicEnabled = true,
MusicVolume = 128,
PlayerName = "Player",
ServerIP = "localhost",
ShowCommandKey = true,
ShowTips = true,
StratagusTrans
TipNumber = 0,
UseFancyBuildings = true,
UseOpenGL = false,
VideoFullScreen = true,
VideoWidth = GetCurrentResol
VideoHeight = GetCurrentResol
}
See, right at the bottom ^^^^ I tried running wargus. didn't even start. Here's the stderr readout.
[string "C:/Games/
stack traceback:
[string "C:/Games/
I'll try the "GetAvailableRe
...Nope, no luck with that either.
treba (der-treba) wrote : | # |
> Yeah this things isn't working. I got an stderr output for you. I placed the
> lines you detailed treba in the stratagus.lua file in the preferences
> sectoion, as follows.
>
ahm yeah, that's the point of the merge. i implemented this calls in the c code i want to merge. you have to compile my branch to test it. if it was already in the engine, i wouldn't have to merge new code for it^^
Travis (dinky-dye-aussie) wrote : | # |
I downloaded your trunk code and the code isn't in the files you list it being in...sooooo I dunno where it is...
Kyran man...You burned me good mate :)
Joris Dauphin (joris-dauphin) wrote : | # |
@treba:
atexit is the global c Raii.
atexit(SDL_Quit) mean that SDL_Quit will be called when program exits.
Call it twice means that SQL_Quit will be invoked twice when program exits.
So, I think you may remove the other atexit(SDL_Quit).
treba (der-treba) wrote : | # |
> @treba:
> atexit is the global c Raii.
> atexit(SDL_Quit) mean that SDL_Quit will be called when program exits.
> Call it twice means that SQL_Quit will be invoked twice when program exits.
> So, I think you may remove the other atexit(SDL_Quit).
no, the second call is done in the if (SDL_WasInit(
> I downloaded your trunk code and the code isn't in the files you list it being in...sooooo I dunno where it is...
well it's even listed at the very end of this comment page (the last 5 lines register the functions)
are you sure got the right branch?
Travis (dinky-dye-aussie) wrote : | # |
Yep, I downloaded from your trunk, several times, and each time I compiled and tried to run the game using you're script code, it wouldn't work, because the code wasn't there.
I'll try again :)
Travis (dinky-dye-aussie) wrote : | # |
OK so now it works. I don't know what I did differently, but it works...How do I zoom tho? My native resolution is 1680x1050, and the game looks sick on this resolution...How do I zoom in though?
treba (der-treba) wrote : | # |
> OK so now it works. I don't know what I did differently, but it works...How do
> I zoom tho? My native resolution is 1680x1050, and the game looks sick on this
> resolution...How do I zoom in though?
afaik that's possible with the other proposed merge. probably a good combination of merges =)
Pali (pali) wrote : | # |
There is duplicate code for SDL video flags. One in function GetVideoFlags (src/video/
And please squash that two commits into one because second commit deleting code which was added by first. You can do that with command: bzr uncommit
Unmerged revisions
- 8698. By treba
-
- removed declarations of lua bindings from video.h
- replaced resolution calls with the following two:
GetCurrentResolution( ) -- array with width and height of current resolution. if called at startup, the optimal resolution is given
GetAvailableResolutions( ) -- two dimensional array with available resolutions. in window mode gives nil - 8697. By treba
-
added lua queries to determine the default resolution of a screen aswell as queries to for supported resolutions.
GetVideoResolut
ionsNr( ) - get number of available resolutions
GetResolutionsWidth(i) - get width of resolution i
GetResolutionsHeight(i) - see above
GetCurrentResolutionsWidth( ) - get current resolution width. if queried on startup, it's the default/optimal resolution
GetCurrentResolutionsHeight( ) - see above
Preview Diff
1 | === modified file 'src/game/game.cpp' | |||
2 | --- src/game/game.cpp 2013-04-23 13:45:52 +0000 | |||
3 | +++ src/game/game.cpp 2013-04-23 18:34:43 +0000 | |||
4 | @@ -1490,6 +1490,7 @@ | |||
5 | 1490 | UpgradesCclRegister(); | 1490 | UpgradesCclRegister(); |
6 | 1491 | UserInterfaceCclRegister(); | 1491 | UserInterfaceCclRegister(); |
7 | 1492 | VideoCclRegister(); | 1492 | VideoCclRegister(); |
8 | 1493 | VideoModesRegister(); | ||
9 | 1493 | } | 1494 | } |
10 | 1494 | 1495 | ||
11 | 1495 | 1496 | ||
12 | 1496 | 1497 | ||
13 | === modified file 'src/include/video.h' | |||
14 | --- src/include/video.h 2013-04-13 00:57:39 +0000 | |||
15 | +++ src/include/video.h 2013-04-23 18:34:43 +0000 | |||
16 | @@ -400,9 +400,11 @@ | |||
17 | 400 | 400 | ||
18 | 401 | /// register lua function | 401 | /// register lua function |
19 | 402 | extern void VideoCclRegister(); | 402 | extern void VideoCclRegister(); |
20 | 403 | extern void VideoModesRegister(); | ||
21 | 403 | 404 | ||
22 | 404 | /// initialize the video part | 405 | /// initialize the video part |
23 | 405 | extern void InitVideo(); | 406 | extern void InitVideo(); |
24 | 407 | extern void PreInitVideoSdl(); | ||
25 | 406 | 408 | ||
26 | 407 | /// deinitliaize the video part | 409 | /// deinitliaize the video part |
27 | 408 | void DeInitVideo(); | 410 | void DeInitVideo(); |
28 | 409 | 411 | ||
29 | === modified file 'src/stratagus/stratagus.cpp' | |||
30 | --- src/stratagus/stratagus.cpp 2013-04-14 08:42:04 +0000 | |||
31 | +++ src/stratagus/stratagus.cpp 2013-04-23 18:34:43 +0000 | |||
32 | @@ -649,6 +649,9 @@ | |||
33 | 649 | 649 | ||
34 | 650 | makedir(parameters.GetUserDirectory().c_str(), 0777); | 650 | makedir(parameters.GetUserDirectory().c_str(), 0777); |
35 | 651 | 651 | ||
36 | 652 | // Preinit SDL_Video so video infos can be queried | ||
37 | 653 | PreInitVideoSdl(); | ||
38 | 654 | |||
39 | 652 | // Init Lua and register lua functions! | 655 | // Init Lua and register lua functions! |
40 | 653 | InitLua(); | 656 | InitLua(); |
41 | 654 | LuaRegisterModules(); | 657 | LuaRegisterModules(); |
42 | 655 | 658 | ||
43 | === modified file 'src/video/sdl.cpp' | |||
44 | --- src/video/sdl.cpp 2013-04-13 00:57:39 +0000 | |||
45 | +++ src/video/sdl.cpp 2013-04-23 18:34:43 +0000 | |||
46 | @@ -453,17 +453,40 @@ | |||
47 | 453 | } | 453 | } |
48 | 454 | 454 | ||
49 | 455 | /** | 455 | /** |
50 | 456 | * Preinit Sdl so sdl infos can be queried by lua | ||
51 | 457 | */ | ||
52 | 458 | |||
53 | 459 | void PreInitVideoSdl() | ||
54 | 460 | { | ||
55 | 461 | int res = SDL_Init( | ||
56 | 462 | #ifdef DEBUG | ||
57 | 463 | SDL_INIT_NOPARACHUTE | | ||
58 | 464 | #endif | ||
59 | 465 | SDL_INIT_AUDIO | SDL_INIT_VIDEO | | ||
60 | 466 | SDL_INIT_TIMER); | ||
61 | 467 | if (res < 0) { | ||
62 | 468 | fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); | ||
63 | 469 | exit(1); | ||
64 | 470 | } | ||
65 | 471 | |||
66 | 472 | // Clean up on exit | ||
67 | 473 | atexit(SDL_Quit); | ||
68 | 474 | } | ||
69 | 475 | |||
70 | 476 | /** | ||
71 | 456 | ** Initialize the video part for SDL. | 477 | ** Initialize the video part for SDL. |
72 | 457 | */ | 478 | */ |
73 | 458 | void InitVideoSdl() | 479 | void InitVideoSdl() |
74 | 459 | { | 480 | { |
75 | 460 | Uint32 flags = 0; | 481 | Uint32 flags = 0; |
76 | 461 | 482 | ||
77 | 483 | #ifndef USE_WIN32 | ||
78 | 484 | // Fix tablet input in full-screen mode | ||
79 | 485 | SDL_putenv(strdup("SDL_MOUSE_RELATIVE=0")); | ||
80 | 486 | #endif | ||
81 | 487 | |||
82 | 462 | if (SDL_WasInit(SDL_INIT_VIDEO) == 0) { | 488 | if (SDL_WasInit(SDL_INIT_VIDEO) == 0) { |
87 | 463 | #ifndef USE_WIN32 | 489 | |
84 | 464 | // Fix tablet input in full-screen mode | ||
85 | 465 | SDL_putenv(strdup("SDL_MOUSE_RELATIVE=0")); | ||
86 | 466 | #endif | ||
88 | 467 | int res = SDL_Init( | 490 | int res = SDL_Init( |
89 | 468 | #ifdef DEBUG | 491 | #ifdef DEBUG |
90 | 469 | SDL_INIT_NOPARACHUTE | | 492 | SDL_INIT_NOPARACHUTE | |
91 | @@ -477,106 +500,106 @@ | |||
92 | 477 | 500 | ||
93 | 478 | // Clean up on exit | 501 | // Clean up on exit |
94 | 479 | atexit(SDL_Quit); | 502 | atexit(SDL_Quit); |
95 | 503 | } | ||
96 | 480 | 504 | ||
97 | 481 | #ifdef USE_MAEMO | 505 | #ifdef USE_MAEMO |
99 | 482 | maemo_init(); | 506 | maemo_init(); |
100 | 483 | #endif | 507 | #endif |
101 | 484 | 508 | ||
104 | 485 | // If debug is enabled, Stratagus disable SDL Parachute. | 509 | // If debug is enabled, Stratagus disable SDL Parachute. |
105 | 486 | // So we need gracefully handle segfaults and aborts. | 510 | // So we need gracefully handle segfaults and aborts. |
106 | 487 | #if defined(DEBUG) && !defined(USE_WIN32) | 511 | #if defined(DEBUG) && !defined(USE_WIN32) |
109 | 488 | signal(SIGSEGV, CleanExit); | 512 | signal(SIGSEGV, CleanExit); |
110 | 489 | signal(SIGABRT, CleanExit); | 513 | signal(SIGABRT, CleanExit); |
111 | 490 | #endif | 514 | #endif |
120 | 491 | // Set WindowManager Title | 515 | // Set WindowManager Title |
121 | 492 | if (!FullGameName.empty()) { | 516 | if (!FullGameName.empty()) { |
122 | 493 | SDL_WM_SetCaption(FullGameName.c_str(), FullGameName.c_str()); | 517 | SDL_WM_SetCaption(FullGameName.c_str(), FullGameName.c_str()); |
123 | 494 | } else if (!Parameters::Instance.applicationName.empty()) { | 518 | } else if (!Parameters::Instance.applicationName.empty()) { |
124 | 495 | SDL_WM_SetCaption(Parameters::Instance.applicationName.c_str(), Parameters::Instance.applicationName.c_str()); | 519 | SDL_WM_SetCaption(Parameters::Instance.applicationName.c_str(), Parameters::Instance.applicationName.c_str()); |
125 | 496 | } else { | 520 | } else { |
126 | 497 | SDL_WM_SetCaption("Stratagus", "Stratagus"); | 521 | SDL_WM_SetCaption("Stratagus", "Stratagus"); |
127 | 498 | } | 522 | } |
128 | 499 | 523 | ||
129 | 500 | #if ! defined(USE_WIN32) && ! defined(USE_MAEMO) | 524 | #if ! defined(USE_WIN32) && ! defined(USE_MAEMO) |
130 | 501 | 525 | ||
131 | 502 | #if defined(USE_OPENGL) || defined(USE_GLES) | 526 | #if defined(USE_OPENGL) || defined(USE_GLES) |
135 | 503 | // Make sure, that we not create OpenGL textures (and do not call OpenGL functions), when creating icon surface | 527 | // Make sure, that we not create OpenGL textures (and do not call OpenGL functions), when creating icon surface |
136 | 504 | bool UseOpenGL_orig = UseOpenGL; | 528 | bool UseOpenGL_orig = UseOpenGL; |
137 | 505 | UseOpenGL = false; | 529 | UseOpenGL = false; |
138 | 506 | #endif | 530 | #endif |
139 | 507 | 531 | ||
186 | 508 | SDL_Surface *icon = NULL; | 532 | SDL_Surface *icon = NULL; |
187 | 509 | CGraphic *g = NULL; | 533 | CGraphic *g = NULL; |
188 | 510 | struct stat st; | 534 | struct stat st; |
189 | 511 | 535 | ||
190 | 512 | std::string FullGameNameL = FullGameName; | 536 | std::string FullGameNameL = FullGameName; |
191 | 513 | for (size_t i = 0; i < FullGameNameL.size(); ++i) { | 537 | for (size_t i = 0; i < FullGameNameL.size(); ++i) { |
192 | 514 | FullGameNameL[i] = tolower(FullGameNameL[i]); | 538 | FullGameNameL[i] = tolower(FullGameNameL[i]); |
193 | 515 | } | 539 | } |
194 | 516 | 540 | ||
195 | 517 | std::string ApplicationName = Parameters::Instance.applicationName; | 541 | std::string ApplicationName = Parameters::Instance.applicationName; |
196 | 518 | std::string ApplicationNameL = ApplicationName; | 542 | std::string ApplicationNameL = ApplicationName; |
197 | 519 | for (size_t i = 0; i < ApplicationNameL.size(); ++i) { | 543 | for (size_t i = 0; i < ApplicationNameL.size(); ++i) { |
198 | 520 | ApplicationNameL[i] = tolower(ApplicationNameL[i]); | 544 | ApplicationNameL[i] = tolower(ApplicationNameL[i]); |
199 | 521 | } | 545 | } |
200 | 522 | 546 | ||
201 | 523 | std::vector <std::string> pixmaps; | 547 | std::vector <std::string> pixmaps; |
202 | 524 | pixmaps.push_back(std::string() + PIXMAPS + "/" + FullGameName + ".png"); | 548 | pixmaps.push_back(std::string() + PIXMAPS + "/" + FullGameName + ".png"); |
203 | 525 | pixmaps.push_back(std::string() + PIXMAPS + "/" + FullGameNameL + ".png"); | 549 | pixmaps.push_back(std::string() + PIXMAPS + "/" + FullGameNameL + ".png"); |
204 | 526 | pixmaps.push_back(std::string() + "/usr/share/pixmaps" + "/" + FullGameName + ".png"); | 550 | pixmaps.push_back(std::string() + "/usr/share/pixmaps" + "/" + FullGameName + ".png"); |
205 | 527 | pixmaps.push_back(std::string() + "/usr/share/pixmaps" + "/" + FullGameNameL + ".png"); | 551 | pixmaps.push_back(std::string() + "/usr/share/pixmaps" + "/" + FullGameNameL + ".png"); |
206 | 528 | pixmaps.push_back(std::string() + PIXMAPS + "/" + ApplicationName + ".png"); | 552 | pixmaps.push_back(std::string() + PIXMAPS + "/" + ApplicationName + ".png"); |
207 | 529 | pixmaps.push_back(std::string() + PIXMAPS + "/" + ApplicationNameL + ".png"); | 553 | pixmaps.push_back(std::string() + PIXMAPS + "/" + ApplicationNameL + ".png"); |
208 | 530 | pixmaps.push_back(std::string() + "/usr/share/pixmaps" + "/" + ApplicationName + ".png"); | 554 | pixmaps.push_back(std::string() + "/usr/share/pixmaps" + "/" + ApplicationName + ".png"); |
209 | 531 | pixmaps.push_back(std::string() + "/usr/share/pixmaps" + "/" + ApplicationNameL + ".png"); | 555 | pixmaps.push_back(std::string() + "/usr/share/pixmaps" + "/" + ApplicationNameL + ".png"); |
210 | 532 | pixmaps.push_back(std::string() + PIXMAPS + "/" + "Stratagus" + ".png"); | 556 | pixmaps.push_back(std::string() + PIXMAPS + "/" + "Stratagus" + ".png"); |
211 | 533 | pixmaps.push_back(std::string() + PIXMAPS + "/" + "stratagus" + ".png"); | 557 | pixmaps.push_back(std::string() + PIXMAPS + "/" + "stratagus" + ".png"); |
212 | 534 | pixmaps.push_back(std::string() + "/usr/share/pixmaps" + "/" + "Stratagus" + ".png"); | 558 | pixmaps.push_back(std::string() + "/usr/share/pixmaps" + "/" + "Stratagus" + ".png"); |
213 | 535 | pixmaps.push_back(std::string() + "/usr/share/pixmaps" + "/" + "stratagus" + ".png"); | 559 | pixmaps.push_back(std::string() + "/usr/share/pixmaps" + "/" + "stratagus" + ".png"); |
214 | 536 | 560 | ||
215 | 537 | for (size_t i = 0; i < pixmaps.size(); ++i) { | 561 | for (size_t i = 0; i < pixmaps.size(); ++i) { |
216 | 538 | if (stat(pixmaps[i].c_str(), &st) == 0) { | 562 | if (stat(pixmaps[i].c_str(), &st) == 0) { |
217 | 539 | if (g) { CGraphic::Free(g); } | 563 | if (g) { CGraphic::Free(g); } |
218 | 540 | g = CGraphic::New(pixmaps[i].c_str()); | 564 | g = CGraphic::New(pixmaps[i].c_str()); |
219 | 541 | g->Load(); | 565 | g->Load(); |
220 | 542 | icon = g->Surface; | 566 | icon = g->Surface; |
221 | 543 | if (icon) { break; } | 567 | if (icon) { break; } |
222 | 544 | } | 568 | } |
223 | 545 | } | 569 | } |
224 | 546 | 570 | ||
225 | 547 | if (icon) { | 571 | if (icon) { |
226 | 548 | SDL_WM_SetIcon(icon, 0); | 572 | SDL_WM_SetIcon(icon, 0); |
227 | 549 | } | 573 | } |
228 | 550 | 574 | ||
229 | 551 | if (g) { | 575 | if (g) { |
230 | 552 | CGraphic::Free(g); | 576 | CGraphic::Free(g); |
231 | 553 | } | 577 | } |
232 | 554 | 578 | ||
233 | 555 | #if defined(USE_OPENGL) || defined(USE_GLES) | 579 | #if defined(USE_OPENGL) || defined(USE_GLES) |
235 | 556 | UseOpenGL = UseOpenGL_orig; | 580 | UseOpenGL = UseOpenGL_orig; |
236 | 557 | #endif | 581 | #endif |
237 | 558 | 582 | ||
238 | 559 | #endif | 583 | #endif |
239 | 560 | #ifdef USE_WIN32 | 584 | #ifdef USE_WIN32 |
257 | 561 | HWND hwnd = NULL; | 585 | HWND hwnd = NULL; |
258 | 562 | HICON hicon = NULL; | 586 | HICON hicon = NULL; |
259 | 563 | SDL_SysWMinfo info; | 587 | SDL_SysWMinfo info; |
260 | 564 | SDL_VERSION(&info.version); | 588 | SDL_VERSION(&info.version); |
261 | 565 | 589 | ||
262 | 566 | if (SDL_GetWMInfo(&info)) { | 590 | if (SDL_GetWMInfo(&info)) { |
263 | 567 | hwnd = info.window; | 591 | hwnd = info.window; |
264 | 568 | } | 592 | } |
265 | 569 | 593 | ||
266 | 570 | if (hwnd) { | 594 | if (hwnd) { |
267 | 571 | hicon = ExtractIcon(GetModuleHandle(NULL), Parameters::Instance.applicationName.c_str(), 0); | 595 | hicon = ExtractIcon(GetModuleHandle(NULL), Parameters::Instance.applicationName.c_str(), 0); |
268 | 572 | } | 596 | } |
269 | 573 | 597 | ||
270 | 574 | if (hicon) { | 598 | if (hicon) { |
271 | 575 | SendMessage(hwnd, (UINT)WM_SETICON, ICON_SMALL, (LPARAM)hicon); | 599 | SendMessage(hwnd, (UINT)WM_SETICON, ICON_SMALL, (LPARAM)hicon); |
272 | 576 | SendMessage(hwnd, (UINT)WM_SETICON, ICON_BIG, (LPARAM)hicon); | 600 | SendMessage(hwnd, (UINT)WM_SETICON, ICON_BIG, (LPARAM)hicon); |
273 | 577 | } | 601 | } |
274 | 578 | #endif | 602 | #endif |
275 | 579 | } | ||
276 | 580 | 603 | ||
277 | 581 | // Initialize the display | 604 | // Initialize the display |
278 | 582 | 605 | ||
279 | 583 | 606 | ||
280 | === modified file 'src/video/video.cpp' | |||
281 | --- src/video/video.cpp 2013-04-13 00:57:39 +0000 | |||
282 | +++ src/video/video.cpp 2013-04-23 18:34:43 +0000 | |||
283 | @@ -480,3 +480,77 @@ | |||
284 | 480 | #endif | 480 | #endif |
285 | 481 | 481 | ||
286 | 482 | //@} | 482 | //@} |
287 | 483 | |||
288 | 484 | /* | ||
289 | 485 | * Lua queries for video information | ||
290 | 486 | */ | ||
291 | 487 | |||
292 | 488 | static Uint32 GetVideoFlags(){ | ||
293 | 489 | Uint32 flags = 0; | ||
294 | 490 | |||
295 | 491 | #if !defined(USE_OPENGL) && !defined(USE_GLES) | ||
296 | 492 | flags = SDL_HWSURFACE | SDL_HWPALETTE; | ||
297 | 493 | #endif | ||
298 | 494 | |||
299 | 495 | if (Video.FullScreen) { | ||
300 | 496 | flags |= SDL_FULLSCREEN; | ||
301 | 497 | } | ||
302 | 498 | |||
303 | 499 | #if defined(USE_OPENGL) || defined(USE_GLES) | ||
304 | 500 | #ifdef USE_GLES_NATIVE | ||
305 | 501 | flags |= SDL_OPENGLES; | ||
306 | 502 | #endif | ||
307 | 503 | #ifdef USE_GLES_MAEMO | ||
308 | 504 | flags |= SDL_SWSURFACE; | ||
309 | 505 | #endif | ||
310 | 506 | #ifdef USE_OPENGL | ||
311 | 507 | flags |= SDL_OPENGL | SDL_GL_DOUBLEBUFFER; | ||
312 | 508 | #endif | ||
313 | 509 | #endif | ||
314 | 510 | |||
315 | 511 | return flags; | ||
316 | 512 | } | ||
317 | 513 | |||
318 | 514 | int GetAvailableResolutions(lua_State *l) | ||
319 | 515 | { | ||
320 | 516 | SDL_Rect** modes = SDL_ListModes(NULL, GetVideoFlags()); | ||
321 | 517 | if (modes == (SDL_Rect**)-1 || modes == (SDL_Rect**)0) { | ||
322 | 518 | lua_pushnil(l); | ||
323 | 519 | } | ||
324 | 520 | else { | ||
325 | 521 | lua_newtable(l); | ||
326 | 522 | int mainTable = lua_gettop(l); | ||
327 | 523 | int index = 0; | ||
328 | 524 | |||
329 | 525 | for(int i=0;modes[i];++i){ | ||
330 | 526 | lua_newtable(l); | ||
331 | 527 | int subTable = lua_gettop(l); | ||
332 | 528 | lua_pushnumber(l, lua_Number(modes[i]->w)); | ||
333 | 529 | lua_rawseti(l, subTable, 1); | ||
334 | 530 | lua_pushnumber(l, lua_Number(modes[i]->h)); | ||
335 | 531 | lua_rawseti(l, subTable, 2); | ||
336 | 532 | |||
337 | 533 | lua_rawseti(l, mainTable, ++index); | ||
338 | 534 | } | ||
339 | 535 | } | ||
340 | 536 | |||
341 | 537 | return 1; | ||
342 | 538 | } | ||
343 | 539 | |||
344 | 540 | int GetCurrentResolution(lua_State *l) | ||
345 | 541 | { | ||
346 | 542 | lua_newtable(l); | ||
347 | 543 | int mainTable = lua_gettop(l); | ||
348 | 544 | lua_pushnumber(l, lua_Number(SDL_GetVideoInfo()->current_w)); | ||
349 | 545 | lua_rawseti(l, mainTable, 1); | ||
350 | 546 | lua_pushnumber(l, lua_Number(SDL_GetVideoInfo()->current_h)); | ||
351 | 547 | lua_rawseti(l, mainTable, 2); | ||
352 | 548 | |||
353 | 549 | return 1; | ||
354 | 550 | } | ||
355 | 551 | |||
356 | 552 | void VideoModesRegister() | ||
357 | 553 | { | ||
358 | 554 | lua_register(Lua, "GetAvailableResolutions", GetAvailableResolutions); | ||
359 | 555 | lua_register(Lua, "GetCurrentResolution", GetCurrentResolution); | ||
360 | 556 | } |
ok, i removed the stuff from the header and replaced the calls with two simple ones:
GetCurrentResol ution() -- array with width and height of current resolution. if called at startup, the optimal resolution is given
GetAvailableRes olutions( ) -- two dimensional array with available resolutions. in window mode gives nil
i guess it's ready now