Browse Source

Change the Video class into an interface, implemented by SdlVideo and,

soon, GtkVideo.
legacy
Sam Hocevar sam 14 years ago
parent
commit
5e9cb74861
5 changed files with 63 additions and 33 deletions
  1. +9
    -4
      src/Makefile
  2. +13
    -13
      src/sdlvideo.cpp
  3. +30
    -0
      src/sdlvideo.h
  4. +2
    -2
      src/test-map.cpp
  5. +9
    -14
      src/video.h

+ 9
- 4
src/Makefile View File

@@ -1,11 +1,16 @@

SRC = test-map.cpp \
game.cpp video.cpp tiler.cpp tileset.cpp scene.cpp \
font.cpp layer.cpp map.cpp
COMMON = test-map.cpp \
game.cpp tiler.cpp tileset.cpp scene.cpp \
font.cpp layer.cpp map.cpp joystick.cpp
TEST_SRC = test-map.cpp sdlvideo.cpp $(COMMON)
EDITOR_SRC = editor.cpp gtkvideo.cpp $(COMMON)

all: test-map

test-map: $(SRC:%.cpp=%.o)
test-map: $(TEST_SRC:%.cpp=%.o)
g++ -g -Wall -O3 $^ -o $@ `pkg-config --libs sdl gl SDL_image`

editor-map: $(EDITOR_SRC:%.cpp=%.o)
g++ -g -Wall -O3 $^ -o $@ `pkg-config --libs sdl gl SDL_image`

%.o: %.cpp


src/video.cpp → src/sdlvideo.cpp View File

@@ -12,15 +12,15 @@

#include <SDL.h>

#include "video.h"
#include "sdlvideo.h"

/*
* Video implementation class
* SDL Video implementation class
*/

class VideoData
class SdlVideoData
{
friend class Video;
friend class SdlVideo;

private:
SDL_Surface *video;
@@ -29,12 +29,12 @@ private:
};

/*
* Public Video class
* Public SdlVideo class
*/

Video::Video(char const *title, int width, int height)
SdlVideo::SdlVideo(char const *title, int width, int height)
{
data = new VideoData();
data = new SdlVideoData();

/* Initialise SDL */
if (SDL_Init(SDL_INIT_VIDEO) < 0)
@@ -79,23 +79,23 @@ Video::Video(char const *title, int width, int height)
data->frames = 0;
}

int Video::GetWidth() const
int SdlVideo::GetWidth() const
{
return data->video->w;
}

int Video::GetHeight() const
int SdlVideo::GetHeight() const
{
return data->video->h;
}

void Video::Clear()
void SdlVideo::Clear()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
}

void Video::Refresh(float milliseconds)
void SdlVideo::Refresh(float milliseconds)
{
if (milliseconds > 0.0f)
while (SDL_GetTicks() < data->ticks + (milliseconds - 0.5f))
@@ -106,12 +106,12 @@ void Video::Refresh(float milliseconds)
SDL_GL_SwapBuffers();
}

void Video::FullScreen()
void SdlVideo::FullScreen()
{
SDL_WM_ToggleFullScreen(data->video);
}

Video::~Video()
SdlVideo::~SdlVideo()
{
Uint32 total = SDL_GetTicks() - data->start;
printf("%f fps\n", 1000.0f * data->frames / total);

+ 30
- 0
src/sdlvideo.h View File

@@ -0,0 +1,30 @@

/*
* The video driver
*/

#if !defined __DH_SDLVIDEO_H__
#define __DH_SDLVIDEO_H__

#include "video.h"

class SdlVideoData;

class SdlVideo : public Video
{
public:
SdlVideo(char const *title, int width, int height);
virtual ~SdlVideo();

virtual int GetWidth() const;
virtual int GetHeight() const;
virtual void Clear();
virtual void Refresh(float milliseconds);
virtual void FullScreen();

private:
SdlVideoData *data;
};

#endif // __DH_SDLVIDEO_H__


+ 2
- 2
src/test-map.cpp View File

@@ -5,12 +5,12 @@
#include <stdio.h>
#include <math.h>

#include "video.h"
#include "sdlvideo.h"
#include "game.h"

int main(int argc, char **argv)
{
Video *video = new Video("Deus Hax", 640, 480);
Video *video = new SdlVideo("Deus Hax", 640, 480);
Game *game = new Game("maps/testmap-library.tmx");

for (int done = 0; !done; )


+ 9
- 14
src/video.h View File

@@ -1,27 +1,22 @@

/*
* The video driver
* The video interface
*/

#if !defined __DH_VIDEO_H__
#define __DH_VIDEO_H__

class VideoData;

class Video
{
public:
Video(char const *title, int width, int height);
~Video();

int GetWidth() const;
int GetHeight() const;
void Clear();
void Refresh(float milliseconds);
void FullScreen();

private:
VideoData *data;
//Video(char const *title, int width, int height);
//virtual ~Video();

virtual int GetWidth() const = 0;
virtual int GetHeight() const = 0;
virtual void Clear() = 0;
virtual void Refresh(float milliseconds) = 0;
virtual void FullScreen() = 0;
};

#endif // __DH_VIDEO_H__


Loading…
Cancel
Save