Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10018 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

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
[9869]27#include "class_id_DEPRECATED.h"
28ObjectListDefinitionID(MovieLoader, CL_MOVIE_LOADER);
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
[6731]65ErrorMessage MovieLoader::init() {}
[6555]66
67
[6731]68ErrorMessage MovieLoader::loadData() {}
[6555]69
70
[7022]71ErrorMessage MovieLoader::unloadData()
72{
[7868]73  this->unsubscribeEvents(ES_GAME);
[7022]74}
[6555]75
76bool MovieLoader::start()
77{
[7022]78  EventHandler::getInstance()->pushState(ES_GAME);
79
[6731]80  this->movie_player->start(0);
[7221]81
[7283]82  this->bRunning = true;
[6598]83  this->run();
[6555]84}
85
86bool MovieLoader::stop()
87{
[7022]88  EventHandler::getInstance()->popState();
89
[7283]90  this->bRunning = false;
[6555]91}
92
[6574]93bool MovieLoader::pause() { }
94bool MovieLoader::resume() { }
[6555]95
96void MovieLoader::run()
97{
[6567]98  // first timestamp for t = 0
99  this->lastFrame = SDL_GetTicks ();
100
[7283]101  while( this->bRunning)
[6562]102  {
[7022]103    EventHandler::getInstance()->process();
[6562]104    this->tick();
[6598]105    this->draw();
[6562]106  }
[6555]107}
[6557]108
[7022]109void MovieLoader::process(const Event &event) {}
110
[6598]111void MovieLoader::draw() const
112{
113  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
114
115
116  GraphicsEngine::enter2DMode();
117
[7919]118  glPushAttrib(GL_ENABLE_BIT);
[6599]119  glEnable(GL_TEXTURE_2D);
120  glBindTexture(GL_TEXTURE_2D, movie_player->getTexture());
[6598]121
122  glColor3f(1.0, 1.0, 1.0);
123
124  glBegin(GL_QUADS);
[6731]125    glTexCoord2f(0.0f, 0.0f); glVertex2f( 0, 0);
126    glTexCoord2f(0.0f, 1.0f); glVertex2f( 0, State::getResY());
127    glTexCoord2f(1.0f, 1.0f); glVertex2f( State::getResX(), State::getResY());
128    glTexCoord2f(1.0f, 0.0f); glVertex2f( State::getResX(), 0);
[6598]129  glEnd();
130
[7919]131  glPopAttrib();
[6598]132  GraphicsEngine::leave2DMode();
133
134  SDL_GL_SwapBuffers();
135}
136
137
[6557]138void MovieLoader::tick()
139{
[6567]140  // get timestamp
[6574]141  currentFrame = SDL_GetTicks();
[6557]142
[6567]143  // calculate time difference in milliseconds (Uint32)
[7221]144  this->dt = currentFrame - this->lastFrame;
[6567]145  // calculate time difference in seconds (float)
[6570]146  this->dts = (float)this->dt / 1000.0f;
[6567]147
148  movie_player->tick(dts);
149
[6598]150  if (movie_player->getStatus() == STOP)
[7283]151    this->bRunning = false;
[6598]152
[6567]153  this->lastFrame = currentFrame;
[6557]154}
Note: See TracBrowser for help on using the repository browser.