Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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