~ubuntu-branches/debian/squeeze/stella/squeeze

« back to all changes in this revision

Viewing changes to src/unix/OSystemUNIX.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Luca Falavigna, Franczen Attila, Luca Falavigna
  • Date: 2008-11-08 12:04:12 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20081108120412-w6xq87vzgokstfey
Tags: 2.6.1-0ubuntu1
[ Franczen Attila ]
* New upstream release (LP: #183571).
* Updated policy to 3.8.0.

[ Luca Falavigna ]
* debian/patches/gcc-4.3: fix FTBFS with gcc-4.3 compiler.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
//  SS  SS   tt   ee      ll   ll  aa  aa
9
9
//   SSSS     ttt  eeeee llll llll  aaaaa
10
10
//
11
 
// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team
 
11
// Copyright (c) 1995-2008 by Bradford W. Mott and the Stella team
12
12
//
13
13
// See the file "license" for information on usage and redistribution of
14
14
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
15
15
//
16
 
// $Id: OSystemUNIX.cxx,v 1.20 2006/03/25 00:34:17 stephena Exp $
 
16
// $Id: OSystemUNIX.cxx,v 1.29 2008/05/16 23:56:31 stephena Exp $
17
17
//============================================================================
18
18
 
19
 
#include <SDL.h>
20
 
#include <SDL_syswm.h>
21
 
 
22
19
#include <cstdlib>
23
20
#include <sstream>
24
21
#include <fstream>
41
38
  in its constructor:
42
39
 
43
40
  setBaseDir()
44
 
  setStateDir()
45
 
  setPropertiesDir()
46
41
  setConfigFile()
47
 
  setCacheFile()
48
42
 
49
43
  See OSystem.hxx for a further explanation
50
44
*/
51
45
 
52
46
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
53
47
OSystemUNIX::OSystemUNIX()
 
48
  : OSystem()
54
49
{
55
 
  // First set variables that the OSystem needs
56
 
  string basedir = string(getenv("HOME")) + "/.stella";
 
50
  const string& basedir = string(getenv("HOME")) + "/.stella";
57
51
  setBaseDir(basedir);
58
 
 
59
 
  setStateDir(basedir + "/state");
60
 
 
61
 
  setPropertiesDir(basedir);
62
52
  setConfigFile(basedir + "/stellarc");
63
 
 
64
 
  setCacheFile(basedir + "/stella.cache");
65
53
}
66
54
 
67
55
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
70
58
}
71
59
 
72
60
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
73
 
void OSystemUNIX::mainLoop()
74
 
{
75
 
  // These variables are common to both timing options
76
 
  // and are needed to calculate the overall frames per second.
77
 
  uInt32 frameTime = 0, numberOfFrames = 0;
78
 
 
79
 
  if(mySettings->getBool("accurate"))   // normal, CPU-intensive timing
80
 
  {
81
 
    // Set up accurate timing stuff
82
 
    uInt32 startTime, delta;
83
 
 
84
 
    // Set the base for the timers
85
 
    frameTime = 0;
86
 
 
87
 
    // Main game loop
88
 
    for(;;)
89
 
    {
90
 
      // Exit if the user wants to quit
91
 
      if(myEventHandler->doQuit())
92
 
        break;
93
 
 
94
 
      startTime = getTicks();
95
 
      myEventHandler->poll(startTime);
96
 
      myFrameBuffer->update();
97
 
 
98
 
      // Now, waste time if we need to so that we are at the desired frame rate
99
 
      for(;;)
100
 
      {
101
 
        delta = getTicks() - startTime;
102
 
 
103
 
        if(delta >= myTimePerFrame)
104
 
          break;
105
 
      }
106
 
 
107
 
      frameTime += getTicks() - startTime;
108
 
      ++numberOfFrames;
109
 
    }
110
 
  }
111
 
  else    // less accurate, less CPU-intensive timing
112
 
  {
113
 
    // Set up less accurate timing stuff
114
 
    uInt32 startTime, virtualTime, currentTime;
115
 
 
116
 
    // Set the base for the timers
117
 
    virtualTime = getTicks();
118
 
    frameTime = 0;
119
 
 
120
 
    // Main game loop
121
 
    for(;;)
122
 
    {
123
 
      // Exit if the user wants to quit
124
 
      if(myEventHandler->doQuit())
125
 
        break;
126
 
 
127
 
      startTime = getTicks();
128
 
      myEventHandler->poll(startTime);
129
 
      myFrameBuffer->update();
130
 
 
131
 
      currentTime = getTicks();
132
 
      virtualTime += myTimePerFrame;
133
 
      if(currentTime < virtualTime)
134
 
      {
135
 
        SDL_Delay((virtualTime - currentTime)/1000);
136
 
      }
137
 
 
138
 
      currentTime = getTicks() - startTime;
139
 
      frameTime += currentTime;
140
 
      ++numberOfFrames;
141
 
    }
142
 
  }
143
 
 
144
 
  // Only print console information if a console was actually created
145
 
  if(mySettings->getBool("showinfo") && myConsole)
146
 
  {
147
 
    double executionTime = (double) frameTime / 1000000.0;
148
 
    double framesPerSecond = (double) numberOfFrames / executionTime;
149
 
 
150
 
    cout << endl;
151
 
    cout << numberOfFrames << " total frames drawn\n";
152
 
    cout << framesPerSecond << " frames/second\n";
153
 
    cout << endl;
154
 
    cout << "Cartridge Name: " << myConsole->properties().get(Cartridge_Name);
155
 
    cout << endl;
156
 
    cout << "Cartridge MD5:  " << myConsole->properties().get(Cartridge_MD5);
157
 
    cout << endl << endl;
158
 
  }
159
 
}
160
 
 
161
 
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
162
 
uInt32 OSystemUNIX::getTicks()
 
61
uInt32 OSystemUNIX::getTicks() const
163
62
{
164
63
#ifdef HAVE_GETTIMEOFDAY
165
64
  timeval now;
170
69
  return (uInt32) SDL_GetTicks() * 1000;
171
70
#endif
172
71
}
173
 
 
174
 
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
175
 
void OSystemUNIX::getScreenDimensions(int& width, int& height)
176
 
{
177
 
  // We might need to temporarily enable VIDEO support to check
178
 
  // screen dimensions
179
 
  bool isAlreadyInitialized = (SDL_WasInit(SDL_INIT_VIDEO) & SDL_INIT_VIDEO) > 0;
180
 
  if(!isAlreadyInitialized)
181
 
    SDL_Init(SDL_INIT_VIDEO);
182
 
 
183
 
  SDL_SysWMinfo myWMInfo;
184
 
  SDL_VERSION(&myWMInfo.version);
185
 
  if(SDL_GetWMInfo(&myWMInfo) > 0 && myWMInfo.subsystem == SDL_SYSWM_X11)
186
 
  {
187
 
    myWMInfo.info.x11.lock_func();
188
 
    width  = DisplayWidth(myWMInfo.info.x11.display,
189
 
               DefaultScreen(myWMInfo.info.x11.display));
190
 
    height = DisplayHeight(myWMInfo.info.x11.display,
191
 
               DefaultScreen(myWMInfo.info.x11.display));
192
 
    myWMInfo.info.x11.unlock_func();
193
 
  }
194
 
 
195
 
  if(!isAlreadyInitialized)
196
 
    SDL_QuitSubSystem(SDL_INIT_VIDEO);
197
 
}