Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/test/src/story_entities/movie_loader.cc @ 10771

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