[6555] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | ### File Specific: |
---|
| 12 | main-programmer: David Hasenfratz, Stefan Lienhard |
---|
[6557] | 13 | co-programmer: |
---|
[6555] | 14 | */ |
---|
| 15 | |
---|
| 16 | #include "movie_loader.h" |
---|
[6576] | 17 | |
---|
[6570] | 18 | #include "movie_player.h" |
---|
[6598] | 19 | #include "factory.h" |
---|
[7022] | 20 | #include "event_handler.h" |
---|
[6598] | 21 | #include "graphics_engine.h" |
---|
[6576] | 22 | #include "load_param.h" |
---|
[6731] | 23 | #include "state.h" |
---|
[6555] | 24 | |
---|
[6576] | 25 | |
---|
[6555] | 26 | using namespace std; |
---|
| 27 | |
---|
[6598] | 28 | CREATE_FACTORY(MovieLoader, CL_MOVIE_LOADER); |
---|
[6555] | 29 | |
---|
[6576] | 30 | MovieLoader::MovieLoader(const TiXmlElement* root) |
---|
[6555] | 31 | { |
---|
| 32 | this->setClassID(CL_MOVIE_LOADER, "MovieLoader"); |
---|
[6576] | 33 | |
---|
| 34 | movie_player = new MoviePlayer(); |
---|
| 35 | this->loadParams(root); |
---|
[6555] | 36 | } |
---|
| 37 | |
---|
[6731] | 38 | MovieLoader::~MovieLoader() |
---|
[6555] | 39 | { |
---|
[6731] | 40 | delete this->movie_player; |
---|
[6555] | 41 | } |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | void MovieLoader::loadParams(const TiXmlElement* root) |
---|
| 46 | { |
---|
[6576] | 47 | StoryEntity::loadParams(root); |
---|
[6555] | 48 | |
---|
[7049] | 49 | LoadParam(root, "movie", this, MovieLoader, loadMovie); |
---|
[7010] | 50 | LoadParam(root, "fps", this, MovieLoader, setFPS); |
---|
[6555] | 51 | } |
---|
| 52 | |
---|
[7010] | 53 | void MovieLoader::setFPS(float fps) |
---|
| 54 | { |
---|
| 55 | this->movie_player->setFPS(fps); |
---|
| 56 | } |
---|
| 57 | |
---|
[6576] | 58 | void MovieLoader::loadMovie(const char* filename) |
---|
| 59 | { |
---|
| 60 | movie_player->loadMovie(filename); |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | |
---|
[6731] | 64 | ErrorMessage MovieLoader::init() {} |
---|
[6555] | 65 | |
---|
| 66 | |
---|
[6731] | 67 | ErrorMessage MovieLoader::loadData() {} |
---|
[6555] | 68 | |
---|
| 69 | |
---|
[7022] | 70 | ErrorMessage MovieLoader::unloadData() |
---|
| 71 | { |
---|
| 72 | EventHandler::getInstance()->unsubscribe(this, ES_GAME); |
---|
| 73 | } |
---|
[6555] | 74 | |
---|
| 75 | bool MovieLoader::start() |
---|
| 76 | { |
---|
[7022] | 77 | EventHandler::getInstance()->pushState(ES_GAME); |
---|
| 78 | |
---|
[6731] | 79 | this->movie_player->start(0); |
---|
| 80 | |
---|
[6574] | 81 | this->isRunning = true; |
---|
[6598] | 82 | this->run(); |
---|
[6555] | 83 | } |
---|
| 84 | |
---|
| 85 | bool MovieLoader::stop() |
---|
| 86 | { |
---|
[7022] | 87 | EventHandler::getInstance()->popState(); |
---|
| 88 | |
---|
[6574] | 89 | this->isRunning = false; |
---|
[6555] | 90 | } |
---|
| 91 | |
---|
[6574] | 92 | bool MovieLoader::pause() { } |
---|
| 93 | bool MovieLoader::resume() { } |
---|
[6555] | 94 | |
---|
| 95 | void MovieLoader::run() |
---|
| 96 | { |
---|
[6567] | 97 | // first timestamp for t = 0 |
---|
| 98 | this->lastFrame = SDL_GetTicks (); |
---|
| 99 | |
---|
[6562] | 100 | while( this->isRunning) |
---|
| 101 | { |
---|
[7022] | 102 | EventHandler::getInstance()->process(); |
---|
[6562] | 103 | this->tick(); |
---|
[6598] | 104 | this->draw(); |
---|
[6562] | 105 | } |
---|
[6555] | 106 | } |
---|
[6557] | 107 | |
---|
[7022] | 108 | void MovieLoader::process(const Event &event) {} |
---|
| 109 | |
---|
[6598] | 110 | void MovieLoader::draw() const |
---|
| 111 | { |
---|
| 112 | glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); |
---|
| 113 | |
---|
| 114 | |
---|
| 115 | GraphicsEngine::enter2DMode(); |
---|
| 116 | |
---|
[6599] | 117 | glEnable(GL_TEXTURE_2D); |
---|
| 118 | glBindTexture(GL_TEXTURE_2D, movie_player->getTexture()); |
---|
[6598] | 119 | |
---|
| 120 | glColor3f(1.0, 1.0, 1.0); |
---|
| 121 | |
---|
| 122 | glBegin(GL_QUADS); |
---|
[6731] | 123 | glTexCoord2f(0.0f, 0.0f); glVertex2f( 0, 0); |
---|
| 124 | glTexCoord2f(0.0f, 1.0f); glVertex2f( 0, State::getResY()); |
---|
| 125 | glTexCoord2f(1.0f, 1.0f); glVertex2f( State::getResX(), State::getResY()); |
---|
| 126 | glTexCoord2f(1.0f, 0.0f); glVertex2f( State::getResX(), 0); |
---|
[6598] | 127 | glEnd(); |
---|
| 128 | |
---|
| 129 | GraphicsEngine::leave2DMode(); |
---|
| 130 | |
---|
| 131 | SDL_GL_SwapBuffers(); |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | |
---|
[6557] | 135 | void MovieLoader::tick() |
---|
| 136 | { |
---|
[6567] | 137 | // get timestamp |
---|
[6574] | 138 | currentFrame = SDL_GetTicks(); |
---|
[6557] | 139 | |
---|
[6567] | 140 | // calculate time difference in milliseconds (Uint32) |
---|
[6731] | 141 | this->dt = currentFrame - this->lastFrame; |
---|
[6567] | 142 | // calculate time difference in seconds (float) |
---|
[6570] | 143 | this->dts = (float)this->dt / 1000.0f; |
---|
[6567] | 144 | |
---|
| 145 | movie_player->tick(dts); |
---|
| 146 | |
---|
[6598] | 147 | if (movie_player->getStatus() == STOP) |
---|
| 148 | this->isRunning = false; |
---|
| 149 | |
---|
[6567] | 150 | this->lastFrame = currentFrame; |
---|
[6557] | 151 | } |
---|