annotate mde/SDL.d @ 22:249eb6620685

Changes to Options, particularly regarding window sizes. Window sizes for fullscreen and windowed modes are now independant. Window resizes by the WM are now persistant. Options class contents are now generated by templates. committer: Diggory Hardy <diggory.hardy@gmail.com>
author Diggory Hardy <diggory.hardy@gmail.com>
date Tue, 25 Mar 2008 12:24:04 +0000
parents a60cbb7359dd
children 47478557428d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 16
diff changeset
1 /* LICENSE BLOCK
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 16
diff changeset
2 Part of mde: a Modular D game-oriented Engine
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 16
diff changeset
3 Copyright © 2007-2008 Diggory Hardy
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 16
diff changeset
4
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 16
diff changeset
5 This program is free software; you can redistribute it and/or modify it under the terms of
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 16
diff changeset
6 the GNU General Public License, version 2, as published by the Free Software Foundation.
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 16
diff changeset
7
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 16
diff changeset
8 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 16
diff changeset
9 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 16
diff changeset
10 See the GNU General Public License for more details.
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 16
diff changeset
11
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 16
diff changeset
12 You should have received a copy of the GNU General Public License along
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 16
diff changeset
13 with this program; if not, write to the Free Software Foundation, Inc.,
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 16
diff changeset
14 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 16
diff changeset
15
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
16 /** Just a temporary place to put SDL Init and Video stuff.
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
17 */
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
18 module mde.SDL;
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
19
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
20 import mde.scheduler.InitStage;
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
21 import mde.input.joystick;
21
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
22 import mde.options;
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
23
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
24 import tango.util.log.Log : Log, Logger;
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
25 import tango.stdc.stringz;
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
26
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
27 import derelict.sdl.sdl;
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
28 import derelict.opengl.gl;
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
29 import derelict.util.exception;
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
30
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
31 Logger logger;
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
32 static this() {
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
33 logger = Log.getLogger ("mde.SDL");
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
34
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
35 init2.addFunc (&initSdlAndGl);
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
36 init4.addFunc (&setupWindow);
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
37 }
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
38
22
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
39 private uint flags = 0;
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
40
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
41 void initSdlAndGl() { // init2 func
21
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
42 logger.trace ("init2: initSdlAndGl() started");
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
43
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
44 // Load SDL and GL dynamic libs
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
45 try {
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
46 DerelictSDL.load();
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
47 DerelictGL.load();
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
48 } catch (DerelictException de) {
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
49 logger.fatal ("Loading dynamic library failed:");
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
50 logger.fatal (de.msg);
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
51
21
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
52 setInitFailure ();
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
53 return;
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
54 }
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
55 logger.trace ("Derelict: loaded SDL and OpenGL");
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
56
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
57 // Initialise SDL
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
58 if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_JOYSTICK /+| SDL_INIT_EVENTTHREAD+/)) {
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
59 logger.fatal ("SDL initialisation failed:");
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
60 char* msg = SDL_GetError ();
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
61 logger.fatal (msg ? fromStringz(msg) : "no reason available");
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
62
21
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
63 setInitFailure ();
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
64 return;
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
65 }
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
66
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
67 cleanup2.addFunc (&cleanupSDL);
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
68 logger.trace ("SDL initialised");
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
69
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
70 // Must be called after SDL has been initialised, so cannot be a separate Init function.
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
71 openJoysticks (); // after SDL init
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
72 cleanup2.addFunc (&closeJoysticks);
21
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
73
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
74 logger.trace ("init2: initSdlAndGl() finished");
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
75 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
76
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
77 void setupWindow() { // init4 func
21
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
78 logger.trace ("init4: setupWindow() started");
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
79
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
80 // Window creation flags
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
81 /* NOTE: I'm getting an API mismatch error from the nvidia driver when using OpenGL,
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
82 * thus I've temporarily disabled it. */
22
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
83 version (MDE_OPENGL) flags = SDL_OPENGL;
21
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
84 if (Options.video.fullscreen) flags |= SDL_FULLSCREEN;
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
85 else {
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
86 if (Options.video.resizable) flags |= SDL_RESIZABLE;
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
87 if (Options.video.noFrame) flags |= SDL_NOFRAME;
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
88 }
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
89 if (Options.video.hardware) flags |= SDL_HWSURFACE | SDL_DOUBLEBUF;
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
90 else flags |= SDL_SWSURFACE;
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
91
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
92 version (MDE_OPENGL) {
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
93 // OpenGL attributes
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
94 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
95 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
96 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
97 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
98 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
99 }
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
100
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
101 // Open a window
22
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
102 SDL_Surface* surface;
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
103 if (Options.video.fullscreen) {
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
104 surface = SDL_SetVideoMode (Options.video.screenW, Options.video.screenH, 32, flags);
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
105 } else {
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
106 surface = SDL_SetVideoMode (Options.video.windowW, Options.video.windowH, 32, flags);
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
107 }
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
108 if (surface is null) {
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
109 logger.fatal ("Unable to set video mode:");
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
110 char* msg = SDL_GetError ();
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
111 logger.fatal (msg ? fromStringz(msg) : "no reason available");
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
112
21
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
113 setInitFailure ();
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
114 return;
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
115 }
21
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
116
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
117 // Window-manager settings
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
118 SDL_WM_SetCaption (toStringz ("mde"), null);
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
119 // SDL_WM_GrabInput (use later)
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
120
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
121 logger.trace ("init4: setupWindow() finished");
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
122 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
123
22
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
124 void resizeWindow (int w, int h) {
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
125 if (Options.video.fullscreen) {
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
126 Options.video.screenW = w;
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
127 Options.video.screenH = h;
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
128 } else {
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
129 Options.video.windowW = w;
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
130 Options.video.windowH = h;
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
131 }
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
132
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
133 /+ Does SDL_SetVideoMode need to be called?
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
134 setupWindow ();
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
135 +/
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
136 }
249eb6620685 Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
137
21
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
138 void cleanupSDL () { // cleanup2 func
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
139 logger.trace ("cleanup2: cleanupSDL() started");
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
140 SDL_Quit();
21
a60cbb7359dd Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 20
diff changeset
141 logger.trace ("cleanup2: cleanupSDL() finished");
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
142 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
143
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
144 /+ Load of info-printing stuff (currently doesn't have a use)
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
145 // Print a load of info:
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
146 logger.info ("Available video modes:");
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
147 char[128] tmp;
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
148 SDL_Rect** modes = SDL_ListModes (null, SDL_FULLSCREEN);
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
149 if (modes is null) logger.info ("None!");
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
150 else if (modes is cast(SDL_Rect**) -1) logger.info ("All modes are available");
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
151 else {
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
152 for (uint i = 0; modes[i] !is null; ++i) {
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
153 logger.info (logger.format (tmp, "\t{}x{}", modes[i].w, modes[i].h));
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
154 }
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
155 }
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
156
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
157 SDL_VideoInfo* vi = SDL_GetVideoInfo ();
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
158 if (vi !is null) {
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
159 logger.info ("Video info:");
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
160 logger.info ("Hardware surface support: "~ (vi.flags & SDL_HWSURFACE ? "yes" : "no"));
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
161 logger.info (logger.format (tmp, "Video memory: {}", vi.video_mem));
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
162
16
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
163 if (vi.vfmt !is null) {
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
164 logger.info ("Best video mode:");
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
165 logger.info (logger.format (tmp, "Bits per pixel: {}", vi.vfmt.BitsPerPixel));
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
166 }
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
167 }
9cb7b9310168 Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
168 +/