Kind of implemented engine_core loop. Implemented subsystem registration. Implement...
[plastic-engine.git] / src / window.cpp
blob01af267fc18791732c7e2634e9305070027d5b3d
1 // Plastic Engine
2 // Copyright (C) 2008 Albert Brown
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 // Window subsystem: establish a buffer to draw in, handle input
19 #include <stdexcept>
20 #include <iostream>
21 #include <string>
22 #include "SDL.h"
24 #include "state.hpp"
25 #include "window.hpp"
29 window_subsystem::window_subsystem()
31 // TODO: we're going to have to implement commandline arguments and
32 // some sort of config interface before we can un-hardcode these values
33 _screen = SDL_SetVideoMode(640, 480, 32, SDL_DOUBLEBUF | SDL_OPENGL);
35 if(!_screen)
37 // Something went wrong
38 std::string msg = std::string("SDL failed to set video mode: ")
39 + SDL_GetError();
40 throw std::runtime_error(msg.c_str());
43 std::cout << "window_subsystem initialized." << std::endl;
46 window_subsystem::~window_subsystem()
48 // The way SDL is designed, we can't really close the window.
49 // TODO: maybe it would be possible if we init the SDL video subsystem
50 // here (in this class). This might allow us to close and restart
51 // it aswell, although this should not be neccesary (maybe on windows).
53 std::cout << "window_subsystem shut down." << std::endl;
56 void window_subsystem::tick(state &s)
58 SDL_Event event;
59 while(SDL_PollEvent(&event))
61 switch(event.type)
63 case SDL_KEYDOWN:
64 if(event.key.keysym.sym == SDLK_ESCAPE)
66 std::cout << "Escape" << std::endl;
67 s.running = false;
69 break;
70 case SDL_QUIT:
71 std::cout << "Close button" << std::endl;
72 s.running = false;
73 break;