Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8255 was 7919, checked in by bensch, 19 years ago

orxonox/trunk: merged the gui branche back
merged with command:
https://svn.orxonox.net/orxonox/branches/gui
no conflicts

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