Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/story_entities/movie_loader.cc @ 10367

Last change on this file since 10367 was 10314, checked in by patrick, 18 years ago

merged branche mount_point to trunk. this will add mount point abilities, bsp transparency fix and some other smaller stuff to this trunk

File size: 3.1 KB
RevLine 
[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"
[7193]19#include "util/loading/factory.h"
[7022]20#include "event_handler.h"
[6598]21#include "graphics_engine.h"
[7193]22#include "util/loading/load_param.h"
[6731]23#include "state.h"
[6555]24
[6576]25
[6555]26
[10114]27
28ObjectListDefinition(MovieLoader);
[9869]29CREATE_FACTORY(MovieLoader);
[9406]30
[6576]31MovieLoader::MovieLoader(const TiXmlElement* root)
[6555]32{
[9869]33  this->registerObject(this, MovieLoader::_objectList);
[6576]34
35  movie_player = new MoviePlayer();
36  this->loadParams(root);
[6555]37}
38
[7221]39MovieLoader::~MovieLoader()
[6555]40{
[6731]41  delete this->movie_player;
[6555]42}
43
44
45
46void MovieLoader::loadParams(const TiXmlElement* root)
47{
[6576]48  StoryEntity::loadParams(root);
[6555]49
[7049]50  LoadParam(root, "movie", this, MovieLoader, loadMovie);
[7010]51  LoadParam(root, "fps", this, MovieLoader, setFPS);
[6555]52}
53
[7010]54void MovieLoader::setFPS(float fps)
55{
56  this->movie_player->setFPS(fps);
57}
58
[7221]59void MovieLoader::loadMovie(const std::string& filename)
[6576]60{
61  movie_player->loadMovie(filename);
62}
63
64
[10314]65ErrorMessage MovieLoader::init() {  return ErrorMessage();}
[6555]66
67
[10314]68ErrorMessage MovieLoader::loadData() {  return ErrorMessage();}
[6555]69
70
[7022]71ErrorMessage MovieLoader::unloadData()
72{
[7868]73  this->unsubscribeEvents(ES_GAME);
[10314]74
75  return ErrorMessage();
[7022]76}
[6555]77
78bool MovieLoader::start()
79{
[7022]80  EventHandler::getInstance()->pushState(ES_GAME);
81
[6731]82  this->movie_player->start(0);
[7221]83
[7283]84  this->bRunning = true;
[6598]85  this->run();
[10314]86
87  return true;
[6555]88}
89
90bool MovieLoader::stop()
91{
[7022]92  EventHandler::getInstance()->popState();
93
[7283]94  this->bRunning = false;
[10314]95
96  return true;
[6555]97}
98
[10314]99bool MovieLoader::pause() { return false; }
100bool MovieLoader::resume() { return false; }
[6555]101
102void MovieLoader::run()
103{
[6567]104  // first timestamp for t = 0
105  this->lastFrame = SDL_GetTicks ();
106
[7283]107  while( this->bRunning)
[6562]108  {
[7022]109    EventHandler::getInstance()->process();
[6562]110    this->tick();
[6598]111    this->draw();
[6562]112  }
[6555]113}
[6557]114
[7022]115void MovieLoader::process(const Event &event) {}
116
[6598]117void MovieLoader::draw() const
118{
119  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
120
121
122  GraphicsEngine::enter2DMode();
123
[7919]124  glPushAttrib(GL_ENABLE_BIT);
[6599]125  glEnable(GL_TEXTURE_2D);
126  glBindTexture(GL_TEXTURE_2D, movie_player->getTexture());
[6598]127
128  glColor3f(1.0, 1.0, 1.0);
129
130  glBegin(GL_QUADS);
[6731]131    glTexCoord2f(0.0f, 0.0f); glVertex2f( 0, 0);
132    glTexCoord2f(0.0f, 1.0f); glVertex2f( 0, State::getResY());
133    glTexCoord2f(1.0f, 1.0f); glVertex2f( State::getResX(), State::getResY());
134    glTexCoord2f(1.0f, 0.0f); glVertex2f( State::getResX(), 0);
[6598]135  glEnd();
136
[7919]137  glPopAttrib();
[6598]138  GraphicsEngine::leave2DMode();
139
140  SDL_GL_SwapBuffers();
141}
142
143
[6557]144void MovieLoader::tick()
145{
[6567]146  // get timestamp
[6574]147  currentFrame = SDL_GetTicks();
[6557]148
[6567]149  // calculate time difference in milliseconds (Uint32)
[7221]150  this->dt = currentFrame - this->lastFrame;
[6567]151  // calculate time difference in seconds (float)
[6570]152  this->dts = (float)this->dt / 1000.0f;
[6567]153
154  movie_player->tick(dts);
155
[6598]156  if (movie_player->getStatus() == STOP)
[7283]157    this->bRunning = false;
[6598]158
[6567]159  this->lastFrame = currentFrame;
[6557]160}
Note: See TracBrowser for help on using the repository browser.