You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(44) |
Aug
(36) |
Sep
(5) |
Oct
|
Nov
(6) |
Dec
(2) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(2) |
Sep
|
Oct
|
Nov
|
Dec
(1) |
2008 |
Jan
|
Feb
|
Mar
|
Apr
(87) |
May
(54) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <dv...@us...> - 2006-08-07 00:38:25
|
Revision: 85 Author: dvalin Date: 2006-08-06 17:38:12 -0700 (Sun, 06 Aug 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=85&view=rev Log Message: ----------- flag play! :p Modified Paths: -------------- trunk/SConstruct Modified: trunk/SConstruct =================================================================== --- trunk/SConstruct 2006-08-06 20:28:04 UTC (rev 84) +++ trunk/SConstruct 2006-08-07 00:38:12 UTC (rev 85) @@ -20,7 +20,10 @@ if sys.platform != "win32": env.ParseConfig('sdl-config --cflags --libs') env.ParseConfig('pkg-config --cflags --libs zziplib') +# env.Append(CCFLGS=["-Wall", "-Werror", "-pedantic", "-ggdb3"]) env.Append(CCFLAGS=["-Wall", "-Werror", "-O2", "-ffast-math", "-funroll-loops"]) +# I want to be a Gentoo ricer when I grow up! ;) +# env.Append(CCFLAGS=["-Wall", "-pedantic", "-O3", "-march=pentium4", "-ffast-math", "-funroll-loops", "-floop-optimize2", "-funsafe-loop-optimizations", "-Wunsafe-loop-optimizations", "-ftree-loop-ivcanon", "-ftree-loop-linear", "-ftree-loop-im", "-funswitch-loops", "-fivopts", "-ftree-vectorize", "-ftracer", "-fvariable-expansion-in-unroller", "-fprefetch-loop-arrays"]) env.Append(LINKFLAGS = ["-ffast-math"]) if 1: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dv...@us...> - 2006-08-06 20:28:23
|
Revision: 84 Author: dvalin Date: 2006-08-06 13:28:04 -0700 (Sun, 06 Aug 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=84&view=rev Log Message: ----------- Make difficulties more sane.. Modified Paths: -------------- trunk/src/AiPlayerClass.cpp Modified: trunk/src/AiPlayerClass.cpp =================================================================== --- trunk/src/AiPlayerClass.cpp 2006-08-06 18:13:26 UTC (rev 83) +++ trunk/src/AiPlayerClass.cpp 2006-08-06 20:28:04 UTC (rev 84) @@ -252,13 +252,13 @@ switch (difficulty) { case EASY: - spiceMultiplyer = 0.5; + spiceMultiplyer = 0.3; break; case MEDIUM: - spiceMultiplyer = 0.75; + spiceMultiplyer = 0.4; break; case HARD: - spiceMultiplyer = 1.0; + spiceMultiplyer = 0.5; break; /* case IMPOSSIBLE: spiceMultiplyer = 1.25; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <shu...@us...> - 2006-08-06 18:13:36
|
Revision: 83 Author: shutdownrunner Date: 2006-08-06 11:13:26 -0700 (Sun, 06 Aug 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=83&view=rev Log Message: ----------- - Set palette for cpsfiles Modified Paths: -------------- branches/dunks/src/pakfile/Cpsfile.cpp Modified: branches/dunks/src/pakfile/Cpsfile.cpp =================================================================== --- branches/dunks/src/pakfile/Cpsfile.cpp 2006-08-06 11:27:50 UTC (rev 82) +++ branches/dunks/src/pakfile/Cpsfile.cpp 2006-08-06 18:13:26 UTC (rev 83) @@ -1,4 +1,5 @@ #include "pakfile/Cpsfile.h" +#include "Application.h" #include <SDL_endian.h> #include <stdlib.h> #include <string.h> @@ -47,8 +48,11 @@ if((pic = SDL_CreateRGBSurface(SDL_SWSURFACE,SIZE_X,SIZE_Y,8,0,0,0,0))== NULL) { return NULL; } - - //SDL_SetColors(pic, palette->colors, 0, palette->ncolors); + + + SDL_Palette* palette = Application::Instance()->Screen()->format->palette; + SDL_SetColors(pic, palette->colors, 0, palette->ncolors); + SDL_LockSurface(pic); //Now we can copy line by line This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dun...@us...> - 2006-08-06 11:27:58
|
Revision: 82 Author: dunkfordyce Date: 2006-08-06 04:27:50 -0700 (Sun, 06 Aug 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=82&view=rev Log Message: ----------- - redid IntroState code. moved all intro state section code into its own class ( badly named class IntroState::Frame ) - added support for transitions between intro sections Modified Paths: -------------- branches/dunks/include/IntroState.h branches/dunks/src/Application.cpp branches/dunks/src/IntroState.cpp Modified: branches/dunks/include/IntroState.h =================================================================== --- branches/dunks/include/IntroState.h 2006-08-05 15:39:13 UTC (rev 81) +++ branches/dunks/include/IntroState.h 2006-08-06 11:27:50 UTC (rev 82) @@ -11,20 +11,62 @@ class IntroState : public State { + class Frame { public: - Frame(std::string file, bool cont, float h) : filename(file), - continuation(cont), - hold(h) {}; - std::string filename; - bool continuation; - float hold; // not implemented yet + typedef enum Transition + { + NO_TRANSITION, + FADE_OUT, + }; + + typedef enum TransitionState + { + TRANSITION_IN, + TRANSITION_OUT, + PLAYING, + HOLDING, + }; + + Frame(std::string file, Transition in, Transition out, bool cont); + + bool Execute(float ft); + void Load(Frame* lastframe); + + private: + std::string m_filename; + + bool m_continuation; + float m_hold; + + TransitionState m_state; + Transition m_transition_in; + Transition m_transition_out; + bool mb_finished; + + Wsafile *m_wsa; + int m_currentFrame; + float m_frametime; + + SDL_Surface* m_animSurface; + SDL_Color* m_transitionPalette; + + void setupTransitionIn(); + void setupTransitionOut(); + void cleanupTransitionIn(); + void cleanupTransitionOut(); + + void doTransitionIn(float dt); + void doTransitionOut(float dt); + void doPlaying(float dt); + void doHolding(float dt); }; - typedef std::list<Frame> IntroList; + typedef std::list<Frame*> IntroList; + public: IntroState(); ~IntroState(); @@ -34,21 +76,18 @@ int Execute(float dt); void SkipIntro(); - void enque(Frame frame) { m_wsaNames.push_back(frame); } + void enque(Frame* frame) { m_wsaNames.push_back(frame); } bool next(); void load(Frame frame); virtual const char* GetName() { return "IntroState"; } - public: - SDL_Surface* m_animSurface; + private: IntroList m_wsaNames; - - Wsafile *m_wsa; TranspButton *m_butIntro; - int m_currentFrame; - float m_frametime; + + Frame* m_currentFrame; }; #endif // DUNE_INTROSTATE_H Modified: branches/dunks/src/Application.cpp =================================================================== --- branches/dunks/src/Application.cpp 2006-08-05 15:39:13 UTC (rev 81) +++ branches/dunks/src/Application.cpp 2006-08-06 11:27:50 UTC (rev 82) @@ -191,7 +191,6 @@ */ }; - void Application::SetPalette() { int len; @@ -222,7 +221,7 @@ videoFlags |= SDL_FULLSCREEN; m_screen = SDL_SetVideoMode(set->m_width, set->m_height, - 8, videoFlags); + 8, videoFlags); if(!m_screen) { fprintf(stderr, "ERROR: Couldn't set video mode: %s\n", SDL_GetError()); @@ -291,38 +290,9 @@ m_cursor = mouse.getPicture(0, m_screen->format->palette); - //Pakfile intropak ("intro.pak"); - //int nfiles = intropak.getNumFiles(); - //for (int i=0; i!=nfiles; i++) - //{ - // printf("found file %s\n", intropak.getFilename(i)); - //}; - - - - //loadDataFile(); - /* - fprintf(stdout, "loading data.....\n"); - loadDataFile(); - fprintf(stdout, "starting sound...\n"); soundPlayer = new SoundPlayerClass(); - - fprintf(stdout, "starting main menu.......\n"); - - menu = (SDL_Surface*)(dataFile[UI_Menu].dat); - palette = new SDL_Palette; - palette->ncolors = menu->format->palette->ncolors; - palette->colors = new SDL_Color[palette->ncolors]; - - //i suspect the palette on one of the images is corrupt...so we have to redefine white - palette->colors[COLOUR_WHITE].r = 255; - palette->colors[COLOUR_WHITE].g = 255; - palette->colors[COLOUR_WHITE].b = 255; - - // looks like this should be a function - memcpy(palette->colors, menu->format->palette->colors, sizeof(SDL_Color)*palette->ncolors); */ }; Modified: branches/dunks/src/IntroState.cpp =================================================================== --- branches/dunks/src/IntroState.cpp 2006-08-05 15:39:13 UTC (rev 81) +++ branches/dunks/src/IntroState.cpp 2006-08-06 11:27:50 UTC (rev 82) @@ -5,33 +5,235 @@ #include "pakfile/Palette.h" #include "boost/bind.hpp" +// ------------------------------------------------------------------ +// IntroState::Frame +IntroState::Frame::Frame(std::string filename, + Transition in, Transition out, + bool continuation) +{ + m_filename = filename; + m_transition_in = in; + m_transition_out = out; + m_continuation = continuation; + + m_state = TRANSITION_IN; + m_hold = 0.0f; + m_transitionPalette = NULL; +}; -IntroState::IntroState() +void IntroState::Frame::Load(Frame* lastframe) { - enque(Frame("INTRO:INTRO1.WSA", false, 1.0f)); - enque(Frame("INTRO:INTRO2.WSA", false, 0.0f)); - enque(Frame("INTRO:INTRO3.WSA", false, 0.0f)); - enque(Frame("INTRO:INTRO4.WSA", false, 0.0f)); - enque(Frame("INTRO:INTRO5.WSA", false, 0.0f)); - enque(Frame("INTRO:INTRO6.WSA", false, 0.0f)); - enque(Frame("INTRO:INTRO7A.WSA", false, 0.0f)); - enque(Frame("INTRO:INTRO7B.WSA", true, 0.0f)); - enque(Frame("INTRO:INTRO8A.WSA", false, 0.0f)); - enque(Frame("INTRO:INTRO8B.WSA", true, 0.0f)); - enque(Frame("INTRO:INTRO8C.WSA", true, 0.0f)); - enque(Frame("INTRO:INTRO9.WSA", false, 0.0f)); - enque(Frame("INTRO:INTRO10.WSA", false, 1.0f)); - enque(Frame("INTRO:INTRO11.WSA", false, 0.0f)); - // seems nice to play this again ;) - enque(Frame("INTRO:INTRO1.WSA", false, 1.0f)); + printf("intro loading %s\n", m_filename.c_str()); + + int len; + unsigned char* data = ResMan::Instance()->readFile(m_filename, &len); + assert(data != NULL); + + if (m_continuation) + { + m_wsa = new Wsafile(data, len, lastframe->m_animSurface); + } + else + { + m_wsa = new Wsafile(data, len); + } + + m_frametime = 0; m_currentFrame = 0; - m_frametime = 0.0f; + mb_finished = false; + SDL_Palette* palette = Application::Instance()->Screen()->format->palette; + m_animSurface = m_wsa->getPicture(m_currentFrame, palette); +}; + +bool IntroState::Frame::Execute(float dt) +{ + switch (m_state) + { + case TRANSITION_IN: + doTransitionIn(dt); + break; + + case TRANSITION_OUT: + doTransitionOut(dt); + break; + + case PLAYING: + doPlaying(dt); + break; + + case HOLDING: + doHolding(dt); + break; + }; + + assert(m_animSurface != NULL); + Application::Instance()->BlitCentered(m_animSurface); + + return mb_finished; +}; + + +void IntroState::Frame::doPlaying(float dt) +{ + m_frametime += dt; + + if (m_frametime > m_wsa->getFPS()) + { + m_currentFrame ++; + m_frametime = 0.0f; + if (m_currentFrame >= m_wsa->getNumFrames()) + { + m_state = HOLDING; + } + else + { + SDL_Palette* palette = Application::Instance()->Screen()->format->palette; + m_animSurface = m_wsa->getPicture(m_currentFrame, palette); + }; + }; +}; + +void IntroState::Frame::setupTransitionIn() +{ +}; + +void IntroState::Frame::cleanupTransitionIn() +{ +}; + +void IntroState::Frame::doTransitionIn(float dt) +{ + if (m_transition_in == NO_TRANSITION) m_state = PLAYING; +}; + +void IntroState::Frame::setupTransitionOut() +{ + m_transitionPalette = new SDL_Color[256]; + memcpy((unsigned char*)m_transitionPalette, + Application::Instance()->Screen()->format->palette->colors, + sizeof(SDL_Color) * 256); +}; + +void IntroState::Frame::cleanupTransitionOut() +{ + delete m_transitionPalette; +}; + +void IntroState::Frame::doTransitionOut(float dt) +{ + if (m_transition_out == NO_TRANSITION) + { + mb_finished = true; + return; + } + + if (m_transitionPalette == NULL) setupTransitionOut(); - m_wsa = NULL; + bool done = true; + SDL_Surface* screen = m_animSurface; //Application::Instance()->Screen(); + SDL_Color* col = m_transitionPalette; + const int fadeAmt = 3; + + for (int i=0; i!=256; i++, col++) + { + if (col->r > fadeAmt || col->g > fadeAmt || col->b > fadeAmt) + { + if (col->r > fadeAmt) col->r -=fadeAmt; + if (col->g > fadeAmt) col->g -=fadeAmt; + if (col->b > fadeAmt) col->b -=fadeAmt; + + done = false; + } + }; + + //SDL_SetPalette(screen, SDL_LOGPAL|SDL_PHYSPAL, m_tempPal, 0, 256); + SDL_SetPalette(screen, SDL_LOGPAL, m_transitionPalette, 0, 256); + + if (done) + { + cleanupTransitionOut(); + mb_finished = true; + }; +}; + +void IntroState::Frame::doHolding(float dt) +{ + m_state = TRANSITION_OUT; +}; + +// ------------------------------------------------------------------ +// IntroState + +IntroState::IntroState() +{ + Frame* tf; + + enque( new Frame("INTRO:INTRO1.WSA", + Frame::NO_TRANSITION, + Frame::FADE_OUT, + false) ); + enque( new Frame("INTRO:INTRO2.WSA", + Frame::NO_TRANSITION, + Frame::FADE_OUT, + false) ); + enque( new Frame("INTRO:INTRO3.WSA", + Frame::NO_TRANSITION, + Frame::FADE_OUT, + false) ); + enque( new Frame("INTRO:INTRO4.WSA", + Frame::NO_TRANSITION, + Frame::FADE_OUT, + false) ); + enque( new Frame("INTRO:INTRO5.WSA", + Frame::NO_TRANSITION, + Frame::FADE_OUT, + false) ); + enque( new Frame("INTRO:INTRO6.WSA", + Frame::NO_TRANSITION, + Frame::FADE_OUT, + false) ); + enque( new Frame("INTRO:INTRO7A.WSA", + Frame::NO_TRANSITION, + Frame::NO_TRANSITION, + false) ); + enque( new Frame("INTRO:INTRO7B.WSA", + Frame::NO_TRANSITION, + Frame::FADE_OUT, + true) ); + enque( new Frame("INTRO:INTRO8A.WSA", + Frame::NO_TRANSITION, + Frame::NO_TRANSITION, + false) ); + enque( new Frame("INTRO:INTRO8B.WSA", + Frame::NO_TRANSITION, + Frame::NO_TRANSITION, + true) ); + enque( new Frame("INTRO:INTRO8C.WSA", + Frame::NO_TRANSITION, + Frame::FADE_OUT, + true) ); + enque( new Frame("INTRO:INTRO9.WSA", + Frame::NO_TRANSITION, + Frame::FADE_OUT, + false) ); + enque( new Frame("INTRO:INTRO10.WSA", + Frame::NO_TRANSITION, + Frame::FADE_OUT, + false) ); + enque( new Frame("INTRO:INTRO11.WSA", + Frame::NO_TRANSITION, + Frame::FADE_OUT, + false) ); + // seems nice to play this again ;) + enque( new Frame("INTRO:INTRO1.WSA", + Frame::NO_TRANSITION, + Frame::FADE_OUT, + false) ); + next(); m_butIntro = new TranspButton(Settings::Instance()->GetWidth(), Settings::Instance()->GetHeight()); @@ -42,7 +244,6 @@ IntroState::~IntroState() { - if (m_wsa != NULL) delete m_wsa; }; void IntroState::SkipIntro() @@ -63,28 +264,7 @@ State::JustMadeInactive(); }; -void IntroState::load(Frame frame) -{ - printf("intro loading %s\n", frame.filename.c_str()); - Wsafile* old_wsa = m_wsa; - - int len; - unsigned char* data = ResMan::Instance()->readFile(frame.filename, &len); - assert(data != NULL); - - if (frame.continuation) - { - m_wsa = new Wsafile(data, len, m_animSurface); - } - else - { - m_wsa = new Wsafile(data, len); - } - - if (old_wsa != NULL) delete old_wsa; -}; - bool IntroState::next() { printf("loading next..\n"); @@ -94,41 +274,23 @@ return false; } - load(*it); + Frame* nextFrame = *it; + nextFrame->Load(m_currentFrame); m_wsaNames.pop_front(); - m_currentFrame = 0 ; + if (m_currentFrame != NULL) delete m_currentFrame; + m_currentFrame = nextFrame; + return true; }; int IntroState::Execute(float dt) { - m_frametime += dt; - - if (m_frametime > m_wsa->getFPS()) + if (m_currentFrame->Execute(dt)) { - m_frametime = 0.0f; - m_currentFrame ++; - if (m_currentFrame >= m_wsa->getNumFrames()) - { - if (!next()) return -1; - }; + if (!next()) return -1; }; - SDL_Palette* palette = Application::Instance()->Screen()->format->palette; - - /* - printf("ISE %u %u %u\n", palette->colors[12].r, - palette->colors[12].g, - palette->colors[12].b); - */ - - m_animSurface = m_wsa->getPicture(m_currentFrame, palette); - - assert(m_animSurface != NULL); - - Application::Instance()->BlitCentered(m_animSurface); - return 0; }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dun...@us...> - 2006-08-05 15:39:22
|
Revision: 81 Author: dunkfordyce Date: 2006-08-05 08:39:13 -0700 (Sat, 05 Aug 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=81&view=rev Log Message: ----------- - let Wsafile accept a SDL_Surface to be used as the basis for other - added Frame object to IntroState to describe if last frame should be passed on to next wsafile. also added a last frame hold option but i havent done anything with it yet Modified Paths: -------------- branches/dunks/include/IntroState.h branches/dunks/include/pakfile/Wsafile.h branches/dunks/src/IntroState.cpp branches/dunks/src/pakfile/Wsafile.cpp Modified: branches/dunks/include/IntroState.h =================================================================== --- branches/dunks/include/IntroState.h 2006-08-05 11:52:32 UTC (rev 80) +++ branches/dunks/include/IntroState.h 2006-08-05 15:39:13 UTC (rev 81) @@ -11,8 +11,20 @@ class IntroState : public State { - typedef std::list<std::string> IntroList; + class Frame + { + public: + Frame(std::string file, bool cont, float h) : filename(file), + continuation(cont), + hold(h) {}; + std::string filename; + bool continuation; + float hold; // not implemented yet + }; + typedef std::list<Frame> IntroList; + + public: IntroState(); ~IntroState(); @@ -22,9 +34,9 @@ int Execute(float dt); void SkipIntro(); - void enque(std::string file) { m_wsaNames.push_back(file); } + void enque(Frame frame) { m_wsaNames.push_back(frame); } bool next(); - void load(std::string file); + void load(Frame frame); virtual const char* GetName() { return "IntroState"; } public: Modified: branches/dunks/include/pakfile/Wsafile.h =================================================================== --- branches/dunks/include/pakfile/Wsafile.h 2006-08-05 11:52:32 UTC (rev 80) +++ branches/dunks/include/pakfile/Wsafile.h 2006-08-05 15:39:13 UTC (rev 81) @@ -9,20 +9,21 @@ class Wsafile : public Decode { public: - Wsafile(unsigned char * bufFiledata, int bufsize); + Wsafile(unsigned char * bufFiledata, int bufsize, + SDL_Surface* lastframe = NULL); ~Wsafile(); SDL_Surface * getPicture(Uint32 FrameNumber, SDL_Palette *palette); inline int getNumFrames() { return (int) NumFrames; }; inline Uint32 getFramesPer1024ms() { return FramesPer1024ms; }; + inline float getFPS() { return fps; } private: void decodeFrames(); unsigned char *decodedFrames; - unsigned char* Filedata; Uint32* Index; int WsaFilesize; @@ -31,6 +32,7 @@ Uint16 SizeX; Uint16 SizeY; Uint32 FramesPer1024ms; + float fps; }; #endif // WSAFILE_H_INCLUDED Modified: branches/dunks/src/IntroState.cpp =================================================================== --- branches/dunks/src/IntroState.cpp 2006-08-05 11:52:32 UTC (rev 80) +++ branches/dunks/src/IntroState.cpp 2006-08-05 15:39:13 UTC (rev 81) @@ -4,24 +4,27 @@ #include "Settings.h" #include "pakfile/Palette.h" #include "boost/bind.hpp" + + + IntroState::IntroState() { - enque("INTRO:INTRO1.WSA"); - enque("INTRO:INTRO2.WSA"); - enque("INTRO:INTRO3.WSA"); - enque("INTRO:INTRO4.WSA"); - enque("INTRO:INTRO5.WSA"); - enque("INTRO:INTRO6.WSA"); - enque("INTRO:INTRO7A.WSA"); - enque("INTRO:INTRO7B.WSA"); - enque("INTRO:INTRO8A.WSA"); - enque("INTRO:INTRO8B.WSA"); - enque("INTRO:INTRO8C.WSA"); - enque("INTRO:INTRO9.WSA"); - enque("INTRO:INTRO10.WSA"); - enque("INTRO:INTRO11.WSA"); + enque(Frame("INTRO:INTRO1.WSA", false, 1.0f)); + enque(Frame("INTRO:INTRO2.WSA", false, 0.0f)); + enque(Frame("INTRO:INTRO3.WSA", false, 0.0f)); + enque(Frame("INTRO:INTRO4.WSA", false, 0.0f)); + enque(Frame("INTRO:INTRO5.WSA", false, 0.0f)); + enque(Frame("INTRO:INTRO6.WSA", false, 0.0f)); + enque(Frame("INTRO:INTRO7A.WSA", false, 0.0f)); + enque(Frame("INTRO:INTRO7B.WSA", true, 0.0f)); + enque(Frame("INTRO:INTRO8A.WSA", false, 0.0f)); + enque(Frame("INTRO:INTRO8B.WSA", true, 0.0f)); + enque(Frame("INTRO:INTRO8C.WSA", true, 0.0f)); + enque(Frame("INTRO:INTRO9.WSA", false, 0.0f)); + enque(Frame("INTRO:INTRO10.WSA", false, 1.0f)); + enque(Frame("INTRO:INTRO11.WSA", false, 0.0f)); // seems nice to play this again ;) - enque("INTRO:INTRO1.WSA"); + enque(Frame("INTRO:INTRO1.WSA", false, 1.0f)); m_currentFrame = 0; m_frametime = 0.0f; @@ -60,17 +63,26 @@ State::JustMadeInactive(); }; -void IntroState::load(std::string name) +void IntroState::load(Frame frame) { - printf("intro loading %s\n", name.c_str()); - if (m_wsa != NULL) delete m_wsa; + printf("intro loading %s\n", frame.filename.c_str()); + Wsafile* old_wsa = m_wsa; int len; - unsigned char* data = ResMan::Instance()->readFile(name, &len); + unsigned char* data = ResMan::Instance()->readFile(frame.filename, &len); assert(data != NULL); - m_wsa = new Wsafile(data, len); + if (frame.continuation) + { + m_wsa = new Wsafile(data, len, m_animSurface); + } + else + { + m_wsa = new Wsafile(data, len); + } + + if (old_wsa != NULL) delete old_wsa; }; bool IntroState::next() @@ -93,7 +105,7 @@ { m_frametime += dt; - if (m_frametime > 0.1f) + if (m_frametime > m_wsa->getFPS()) { m_frametime = 0.0f; m_currentFrame ++; Modified: branches/dunks/src/pakfile/Wsafile.cpp =================================================================== --- branches/dunks/src/pakfile/Wsafile.cpp 2006-08-05 11:52:32 UTC (rev 80) +++ branches/dunks/src/pakfile/Wsafile.cpp 2006-08-05 15:39:13 UTC (rev 81) @@ -3,7 +3,8 @@ #include <stdlib.h> #include <string.h> -Wsafile::Wsafile(unsigned char * bufFiledata, int bufsize) : Decode() +Wsafile::Wsafile(unsigned char * bufFiledata, int bufsize, + SDL_Surface* lastframe ) : Decode() { Filedata = bufFiledata; WsaFilesize = bufsize; @@ -26,10 +27,14 @@ FramesPer1024ms = SDL_SwapLE32( *((Uint32*) (Filedata+6)) ); } else { Index = (Uint32 *) (Filedata + 8); - FramesPer1024ms = SDL_SwapLE16( *((Uint16*) (Filedata+6)) ); + FramesPer1024ms = SDL_SwapLE16( *((Uint16*) (Filedata+6)) ); } + // surely /1000.0f not 100?! + fps = (FramesPer1024ms / 1024.0f) / 100.0f; + printf("FramesPer1024ms = %d\n", FramesPer1024ms); + printf("FPS = %.3f\n", fps); if(Index[0] == 0) { Index++; @@ -45,6 +50,11 @@ fprintf(stderr, "Error: Unable to allocate memory for decoded WSA-Frames!\n"); exit(EXIT_FAILURE); } + + if (lastframe != NULL) + { + memcpy(decodedFrames, lastframe->pixels, SizeX*SizeY); + }; decodeFrames(); }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dun...@us...> - 2006-08-05 11:52:43
|
Revision: 80 Author: dunkfordyce Date: 2006-08-05 04:52:32 -0700 (Sat, 05 Aug 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=80&view=rev Log Message: ----------- - fix compiler warnings - remove lots of debug info Modified Paths: -------------- branches/dunks/src/Application.cpp branches/dunks/src/Font.cpp branches/dunks/src/IntroState.cpp branches/dunks/src/gui2/Button.cpp branches/dunks/src/pakfile/Palette.cpp branches/dunks/src/pakfile/Wsafile.cpp Modified: branches/dunks/src/Application.cpp =================================================================== --- branches/dunks/src/Application.cpp 2006-08-04 13:34:05 UTC (rev 79) +++ branches/dunks/src/Application.cpp 2006-08-05 11:52:32 UTC (rev 80) @@ -348,7 +348,7 @@ const int fps_interval = 10 * 1000; // 10 seconds float fps; - Font* fnt = FontManager::Instance()->getFont("INTRO:INTRO.FNT"); + //Font* fnt = FontManager::Instance()->getFont("INTRO:INTRO.FNT"); m_running = true; @@ -442,11 +442,6 @@ m_rootWidget->handleButtonUp( event.button.button, event.button.x, event.button.y); - if (event.button.button == 1) - gpaloff ++; - else - gpaloff --; - printf("gpla %u\n", gpaloff); break; case SDL_KEYDOWN: m_rootWidget->handleKeyDown(&(event.key.keysym)); @@ -460,7 +455,7 @@ void Application::BlitCursor() { - SDL_Rect dest, src; + SDL_Rect dest; SDL_Surface* surface = m_cursor; // being lazy, rename me dest.x = m_cursorX; Modified: branches/dunks/src/Font.cpp =================================================================== --- branches/dunks/src/Font.cpp 2006-08-04 13:34:05 UTC (rev 79) +++ branches/dunks/src/Font.cpp 2006-08-05 11:52:32 UTC (rev 80) @@ -95,14 +95,10 @@ //FILE* file = fopen(fn, "rb"); FileLike* file = ResMan::Instance()->readFile(fn); - printf("sizeof word %u, sizeof byte %u\n", sizeof(word), sizeof(byte)); - FNTHeader* header = new FNTHeader(); file->read(header, sizeof(FNTHeader)); - printf("fsize %d\n", header->fsize); - // this checks if its a valid font if (header->unknown1 != 0x0500) printf("failed unknown1\n"); if (header->unknown2 != 0x000e) printf("failed unknown2\n"); @@ -116,7 +112,6 @@ byte* wchar = new byte[header->nchars+1]; - printf("wpos %d\n", header->wpos); file->seek(header->wpos); file->read(wchar, sizeof(byte) * (header->nchars+1)); @@ -136,13 +131,10 @@ byte offset = hchar[i] & 0xFF; byte height = hchar[i] >> 8; byte width =( wchar[i] + 1) / 2; - printf("%d width = %hd offset = %hd height = %hd\n", i, width, offset, height); characters[i].width = width; characters[i].height = height; characters[i].y_offset = offset; - printf("size %hd\n", width * height); - printf("dchar %hd\n", dchar[i]); file->seek(dchar[i]); byte* bitmap = new byte[width * height]; Modified: branches/dunks/src/IntroState.cpp =================================================================== --- branches/dunks/src/IntroState.cpp 2006-08-04 13:34:05 UTC (rev 79) +++ branches/dunks/src/IntroState.cpp 2006-08-05 11:52:32 UTC (rev 80) @@ -20,6 +20,8 @@ enque("INTRO:INTRO9.WSA"); enque("INTRO:INTRO10.WSA"); enque("INTRO:INTRO11.WSA"); + // seems nice to play this again ;) + enque("INTRO:INTRO1.WSA"); m_currentFrame = 0; m_frametime = 0.0f; Modified: branches/dunks/src/gui2/Button.cpp =================================================================== --- branches/dunks/src/gui2/Button.cpp 2006-08-04 13:34:05 UTC (rev 79) +++ branches/dunks/src/gui2/Button.cpp 2006-08-05 11:52:32 UTC (rev 80) @@ -62,7 +62,6 @@ bool GraphicButton::handleButtonDown(Uint8 button, Uint16 x, Uint16 y) { if (!m_visible) return false; - printf("%p down\n", this); if (!hitTest(x, y)) { m_pressed = false; @@ -78,7 +77,6 @@ { if (!m_visible) return false; m_pressed = false; - printf("%p up\n", this); return Button::handleButtonUp(button, x, y); }; @@ -133,8 +131,6 @@ Uint16 textw, texth; font->extents(m_caption.c_str(), textw, texth); - printf("text wh %u %u\n", textw, texth); - font->render(m_caption.c_str(), m_surfNormal, (m_width / 2) - (textw / 2), (m_height / 2) - (texth / 2), 31); Modified: branches/dunks/src/pakfile/Palette.cpp =================================================================== --- branches/dunks/src/pakfile/Palette.cpp 2006-08-04 13:34:05 UTC (rev 79) +++ branches/dunks/src/pakfile/Palette.cpp 2006-08-05 11:52:32 UTC (rev 80) @@ -16,14 +16,8 @@ c->r = (dunepal[0] << 2) + 3; c->g = (dunepal[1] << 2) + 3; c->b = (dunepal[2] << 2) + 3; - - printf("%d %03d %03d %03d\n", i, c->r, c->g, c->b); }; - printf("%u %u %u\n", m_palette->colors[12].r, - m_palette->colors[12].g, - m_palette->colors[12].b); - delete [] buf; }; Modified: branches/dunks/src/pakfile/Wsafile.cpp =================================================================== --- branches/dunks/src/pakfile/Wsafile.cpp 2006-08-04 13:34:05 UTC (rev 79) +++ branches/dunks/src/pakfile/Wsafile.cpp 2006-08-05 11:52:32 UTC (rev 80) @@ -29,7 +29,7 @@ FramesPer1024ms = SDL_SwapLE16( *((Uint16*) (Filedata+6)) ); } - printf("FramesPer1024ms = %d", FramesPer1024ms); + printf("FramesPer1024ms = %d\n", FramesPer1024ms); if(Index[0] == 0) { Index++; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otp...@us...> - 2006-08-04 13:34:10
|
Revision: 79 Author: otpetrik Date: 2006-08-04 06:34:05 -0700 (Fri, 04 Aug 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=79&view=rev Log Message: ----------- fixed DIRResource, it should work now (tested only on linux !). Modified Paths: -------------- branches/dunks/src/ResMan.cpp Modified: branches/dunks/src/ResMan.cpp =================================================================== --- branches/dunks/src/ResMan.cpp 2006-08-03 22:01:08 UTC (rev 78) +++ branches/dunks/src/ResMan.cpp 2006-08-04 13:34:05 UTC (rev 79) @@ -49,8 +49,8 @@ unsigned char* DIRResource::readFile(bfs::path path, int *size) { - assert(0); // this doesnt work - bfs::path fullpath (m_path.string() + path.string()); + // TODO: seems to work now, tested on linux, please test it on windows. (otpetrik) + bfs::path fullpath (m_path.string() + "/" + path.string()); FILE *file = fopen (fullpath.string().c_str(), "rb"); fseek(file, 0, SEEK_END); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otp...@us...> - 2006-08-03 22:01:18
|
Revision: 78 Author: otpetrik Date: 2006-08-03 15:01:08 -0700 (Thu, 03 Aug 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=78&view=rev Log Message: ----------- added log system Modified Paths: -------------- branches/dunks/SConstruct branches/dunks/src/SConscript Added Paths: ----------- branches/dunks/include/Log.h branches/dunks/src/Log.cpp Modified: branches/dunks/SConstruct =================================================================== --- branches/dunks/SConstruct 2006-08-03 18:58:44 UTC (rev 77) +++ branches/dunks/SConstruct 2006-08-03 22:01:08 UTC (rev 78) @@ -57,6 +57,9 @@ "${ZZIP_LIB_PATH}", "${BOOST_LIB_PATH}"]) +# Uncomment to disable logging +#env.Append(CCFLAGS=["-DLOG_DISABLED"]) + Export('env') #SConscript("src/pakfile/SConscript") Added: branches/dunks/include/Log.h =================================================================== --- branches/dunks/include/Log.h (rev 0) +++ branches/dunks/include/Log.h 2006-08-03 22:01:08 UTC (rev 78) @@ -0,0 +1,256 @@ +/*! + \file Log.h + \brief Message logging routines. + + @note + Avoid use of global logging, try using subsystem specific. It allows finer + verbosity control. + + @note + To disable logging altogether, define macro LOG_DISABLED. + + @note + Do not add new log verbosity levels to this file, instead create your own + enum in file in question. Use LOG_LEVEL_AVAILABLE as basis for your enum: + + @code + enum LogAiVerbosity + { + LOG_AI_WORLDWIDE = LOG_VERBOSITY_AVAILABLE, + LOG_AI_PLATOON, + LOG_AI_SQUAD + }; + @endcode + + @note + To make logging easier for subsystem SOMETHING, define your own macros: + + @code + + #define SOMETHING_LOG(level,...) S_LOG("something", level, __VA_ARGS__) + #define SOMETHING_LOG_ERROR(...) SOMETHING_LOG(LOG_ERROR, __VA_ARGS__) + #define SOMETHING_LOG_FATAL(...) SOMETHING_LOG(LOG_FATAL, __VA_ARGS__) + #define SOMETHING_LOG_WARNING(...) SOMETHING_LOG(LOG_WARNING, __VA_ARGS__) + #define SOMETHING_LOG_INFO(...) SOMETHING_LOG(LOG_INFO, __VA_ARGS__) + + @endcode + +*/ + +#ifndef DUNE_LOG_H +#define DUNE_LOG_H + +#include "singleton.h" + +#include <string> +#include <map> +#include <boost/shared_ptr.hpp> + +// TODO: not sure where these belong, mayby separate file Types.h ? (otpetrik) +typedef std::string String; +typedef const std::string &ConstString; + +#ifndef LOG_DISABLED + +//! Log verbosity level +/*! + Used to filter unnecessary messages. +*/ +enum LogVerbosity +{ + //! bye, bye ! + LOG_FATAL = 0, + //! that hurt... + LOG_ERROR, + //! i can handle that + LOG_WARNING, + //! look what's happening + LOG_INFO, + //! first user loglevel + LOG_VERBOSITY_AVAILABLE, + //! last loglevel (used to set full logging) + LOG_VERBOSITY_MAX = 255 +}; + +class LogBackend; + +typedef boost::shared_ptr<LogBackend> LogBackendPtr; + +//! Generic log backend class +/*! + Parent class for all log backends (write to console, + file, screen, network, ...) +*/ +class LogBackend +{ + public: + //! @name Constructors & Destructor + //@{ + + //! Constructor + LogBackend(); + //! Destructor + virtual ~LogBackend(); + + //@} + + //! @name Log methods + //@{ + + //! Log the message + /*! + Called by Log class to log every feasible message. + + @param message message to be logged + */ + virtual void log(const char *message) = 0; + + //@} +}; + +//! Stdout backend class +/*! + Default backend, just writes message to the console. +*/ +class LogBackendStdout : public LogBackend +{ + public: + virtual void log(const char *message); +}; + +//! Log system +/*! + Provides complete logging facilites including different verbosity levels. + + @note: For logging itself, do not use this class, use macros ! + + @see S_LOG, S_LOG_FATAL, S_LOG_ERROR, S_LOG_WARNING, S_LOG_INFO + @see G_LOG, G_LOG_FATAL, G_LOG_ERROR, G_LOG_WARNING, G_LOG_INFO +*/ +class Log : public Singleton<Log> +{ + friend class Singleton<Log>; + + public: + + //! @name Logging + //@{ + + //! Log message + /*! + @param logSystem string identificatin what logged the message + @param verbosity verbosity of message + @param message message itself + */ + void log(ConstString logSystem, LogVerbosity verbosity, ConstString message); + //! Log message + /*! + @param logSystem string identificatin what logged the message + @param verbosity verbosity of message + @param format printf-type message string + */ + void log(ConstString logSystem, LogVerbosity verbosity, const char *format, ...); + + //@} + + + //! @name Verbosity setting + //@{ + + //! Set verbosity level for given system + void setVerbosity(ConstString logSystem, LogVerbosity verbosity); + + //! Set default verbosity level + /* + Sets verbosity level for system with no verbosity level on their own + */ + void setDefaultVerbosity(LogVerbosity verbosity) { defaultVerbosity = verbosity; }; + + //@} + + //! @name Backend + //@{ + + //! Set new backend + void setBackend(LogBackendPtr backend); + //! Get current backend + LogBackendPtr getBackend() { return backend; }; + + //@} + + protected: + + //! @name Constructors & Destructor + //@{ + + //! Constructor + Log(); + //! Destructor + ~Log(); + + //@} + + private: + LogVerbosity defaultVerbosity; + LogBackendPtr backend; + std::map<const String, LogVerbosity> verbosities; + + void doLog(ConstString logSystem, LogVerbosity verbosity, const char *message); + +}; + +// few usefull macros + +//! @name Subsystem logs +//! Subsystem emitted messages +//@{ + +//! Log message of given verbosity emitted by given system +#define S_LOG(system,verbosity,...) Log::Instance()->log(system, verbosity, __VA_ARGS__) +//! Log fatal message emitted by given system +#define S_LOG_FATAL(system,...) Log::Instance()->log(system, LOG_FATAL, __VA_ARGS__) +//! Log error message emitted by given system +#define S_LOG_ERROR(system,...) Log::Instance()->log(system, LOG_ERROR, __VA_ARGS__) +//! Log warning message emitted by given system +#define S_LOG_WARNING(system,...) Log::Instance()->log(system, LOG_WARNING, __VA_ARGS__) +//! Log info message emitted by given system +#define S_LOG_INFO(system,...) Log::Instance()->log(system, LOG_INFO, __VA_ARGS__) + +//@} + +//! @name Global log +//! Messages not bound to any given system +//@{ + +//! Log message of given verbosity +#define G_LOG(level,...) S_LOG("", level, __VA_ARGS__) +//! Log fatal message +#define G_LOG_FATAL(...) G_LOG(LOG_FATAL, __VA_ARGS__) +//! Log error message +#define G_LOG_ERROR(...) G_LOG(LOG_ERROR, __VA_ARGS__) +//! Log warning message +#define G_LOG_WARNING(...) G_LOG(LOG_WARNING, __VA_ARGS__) +//! Log info message +#define G_LOG_INFO(...) G_LOG(LOG_INFO, __VA_ARGS__) + +//@} + +#else // LOG_DISABLED + +// few useless macros + +#define S_LOG(system,verbosity,...) ((void)(0)) +#define S_LOG_FATAL(system,...) ((void)(0)) +#define S_LOG_ERROR(system,...) ((void)(0)) +#define S_LOG_WARNING(system,...) ((void)(0)) +#define S_LOG_INFO(system,...) ((void)(0)) +#define G_LOG(level,...) ((void)(0)) +#define G_LOG_FATAL(...) ((void)(0)) +#define G_LOG_ERROR(...) ((void)(0)) +#define G_LOG_WARNING(...) ((void)(0)) +#define G_LOG_INFO(...) ((void)(0)) + + +#endif // LOG_DISABLED + +#endif // DUNE_LOG_H Added: branches/dunks/src/Log.cpp =================================================================== --- branches/dunks/src/Log.cpp (rev 0) +++ branches/dunks/src/Log.cpp 2006-08-03 22:01:08 UTC (rev 78) @@ -0,0 +1,124 @@ +#include "Log.h" + +#ifndef LOG_DISABLED + +#include <stdio.h> +#include <stdarg.h> + +#define LOG_DEFAULT_VERBOSITY LOG_VERBOSITY_MAX +#define LOG_MAX_STRING_LENGTH 100 + +//------------------------------------------------------------------------------ +// LogBackend class +//------------------------------------------------------------------------------ + +LogBackend::LogBackend() +{ +}; +LogBackend::~LogBackend() +{ +}; + +void LogBackend::log(const char *message) +{ +}; + +//------------------------------------------------------------------------------ +// LogBackendStdout class +//------------------------------------------------------------------------------ + +void LogBackendStdout::log(const char *message) +{ + printf("%s", message); +}; + +//------------------------------------------------------------------------------ +// Log class +//------------------------------------------------------------------------------ + +void Log::log(ConstString logSystem, LogVerbosity verbosity, ConstString message) +{ + doLog(logSystem, verbosity, message.c_str()); +}; +void Log::log(ConstString logSystem, LogVerbosity verbosity, const char *format, ...) +{ + std::map<const String, LogVerbosity>::iterator i; + LogVerbosity systemVerbosity; + static char message[LOG_MAX_STRING_LENGTH]; + + // find verbosity level applicable to this message + i = verbosities.find(logSystem); + if (i != verbosities.end()) + { + systemVerbosity = i->second; + } + else + { + systemVerbosity = defaultVerbosity; + } + + // check that level + if (verbosity > systemVerbosity) + return; + + + // assemble the message + va_list args; + va_start(args, format); + vsnprintf(message, LOG_MAX_STRING_LENGTH, format, args); + va_end(args); + + // log it + doLog(logSystem, verbosity, message); +}; + +void Log::setVerbosity(ConstString logSystem, LogVerbosity verbosity) +{ + verbosities[logSystem] = verbosity; +}; + +void Log::setBackend(LogBackendPtr backend) +{ + assert(backend != NULL); + this->backend = backend; +}; + +Log::Log() : defaultVerbosity(LOG_DEFAULT_VERBOSITY), backend(new LogBackendStdout()) +{ +}; +Log::~Log() +{ +}; + +void Log::doLog(ConstString logSystem, LogVerbosity verbosity, const char *message) +{ + static char formated[LOG_MAX_STRING_LENGTH]; + const char *verb; + + switch (verbosity) + { + case LOG_FATAL: + verb = "[FATAL]"; + break; + case LOG_ERROR: + verb = "[ERROR]"; + break; + case LOG_WARNING: + verb = "[WARNING]"; + break; + case LOG_INFO: + default: + verb = ""; + break; + }; + + // do not print ':' unless there is a logSystem string + if (logSystem.size() != 0) + snprintf(formated, LOG_MAX_STRING_LENGTH, "%s%s: %s\n", verb, logSystem.c_str(), message); + else + snprintf(formated, LOG_MAX_STRING_LENGTH, "%s%s\n", verb, message); + + backend->log(formated); +} + +#endif Modified: branches/dunks/src/SConscript =================================================================== --- branches/dunks/src/SConscript 2006-08-03 18:58:44 UTC (rev 77) +++ branches/dunks/src/SConscript 2006-08-03 22:01:08 UTC (rev 78) @@ -27,6 +27,7 @@ "OptionsMenu.cpp", "Gfx.cpp", "houses.cpp", # just for colors, hope there will be a better place for these (otpetrik) + "Log.cpp", "ResMan.cpp", ] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <shu...@us...> - 2006-08-03 18:58:58
|
Revision: 77 Author: shutdownrunner Date: 2006-08-03 11:58:44 -0700 (Thu, 03 Aug 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=77&view=rev Log Message: ----------- Fix for palette resetting after resolution change Modified Paths: -------------- branches/dunks/include/Application.h branches/dunks/src/Application.cpp branches/dunks/src/pakview.cpp Modified: branches/dunks/include/Application.h =================================================================== --- branches/dunks/include/Application.h 2006-08-03 18:21:35 UTC (rev 76) +++ branches/dunks/include/Application.h 2006-08-03 18:58:44 UTC (rev 77) @@ -46,7 +46,7 @@ void Blit(SDL_Surface* surface, SDL_Rect* src, SDL_Rect* dest); void BlitCentered(SDL_Surface* surface, SDL_Rect* src=NULL); - void SetPalette(SDL_Palette* pal); + void SetPalette(); SDL_Palette* GetCurrentPalette() { return m_currentPalette; } void UpdateVideoMode(bool fullscreen); Modified: branches/dunks/src/Application.cpp =================================================================== --- branches/dunks/src/Application.cpp 2006-08-03 18:21:35 UTC (rev 76) +++ branches/dunks/src/Application.cpp 2006-08-03 18:58:44 UTC (rev 77) @@ -192,8 +192,15 @@ }; -void Application::SetPalette(SDL_Palette* pal) +void Application::SetPalette() { + int len; + unsigned char* data = ResMan::Instance()->readFile("INTRO:INTRO.PAL", &len); + + Palettefile tmp (data, len); + + SDL_Palette * pal = tmp.getPalette(); + assert(pal != NULL); printf("setting palette %d colors\n", pal->ncolors); assert( SDL_SetColors(m_screen, pal->colors, 0, pal->ncolors) == 1 ); @@ -224,7 +231,7 @@ // reset the palette if we've got one if (m_currentPalette != NULL) - SetPalette(m_currentPalette); + SetPalette(); SDL_ShowCursor(SDL_DISABLE); @@ -273,13 +280,11 @@ ResMan::Instance()->addRes("XTRE"); printf("done loading resources\n"); + SetPalette(); int len; - unsigned char* data = ResMan::Instance()->readFile("INTRO:INTRO.PAL", &len); - Palettefile pal (data, len); + unsigned char * data; - SetPalette(pal.getPalette()); - data = ResMan::Instance()->readFile("DUNE:MOUSE.SHP", &len); Shpfile mouse (data, len); Modified: branches/dunks/src/pakview.cpp =================================================================== --- branches/dunks/src/pakview.cpp 2006-08-03 18:21:35 UTC (rev 76) +++ branches/dunks/src/pakview.cpp 2006-08-03 18:58:44 UTC (rev 77) @@ -25,7 +25,7 @@ Palettefile pal (data, len); - Application::Instance()->SetPalette(pal.getPalette()); + Application::Instance()->SetPalette(); m_button = new BoringButton("Test"); m_button->setSize(100, 50); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dun...@us...> - 2006-08-03 18:21:48
|
Revision: 76 Author: dunkfordyce Date: 2006-08-03 11:21:35 -0700 (Thu, 03 Aug 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=76&view=rev Log Message: ----------- - move setters out of Settings - implemented overloaded Application::UpdateVideoMode - removed Application::SetVideoMode Modified Paths: -------------- branches/dunks/include/Application.h branches/dunks/include/Settings.h branches/dunks/src/Application.cpp branches/dunks/src/OptionsMenu.cpp branches/dunks/src/Settings.cpp Modified: branches/dunks/include/Application.h =================================================================== --- branches/dunks/include/Application.h 2006-08-02 20:46:26 UTC (rev 75) +++ branches/dunks/include/Application.h 2006-08-03 18:21:35 UTC (rev 76) @@ -48,8 +48,11 @@ void SetPalette(SDL_Palette* pal); SDL_Palette* GetCurrentPalette() { return m_currentPalette; } - void SetVideoMode(); + void UpdateVideoMode(bool fullscreen); + void UpdateVideoMode(Uint16 w, Uint16 h); + void UpdateVideoMode(Uint16 w, Uint16 h, bool fullscreen); + private: void InitSettings(); void InitAudio(); Modified: branches/dunks/include/Settings.h =================================================================== --- branches/dunks/include/Settings.h 2006-08-02 20:46:26 UTC (rev 75) +++ branches/dunks/include/Settings.h 2006-08-03 18:21:35 UTC (rev 76) @@ -59,7 +59,7 @@ { friend class Singleton<Settings>; friend class Application; - friend class OptionsMenuState; + protected: Settings(); @@ -80,16 +80,9 @@ inline int GetHeight() { return m_height; } - void SetScreenSize(int width, int height) - { m_width = width; - m_height = height; }; - inline bool GetFullScreen() { return m_fullscreen; } - void SetFullScreen(bool x) - { m_fullscreen = x; } - inline bool GetDebug() { return m_debug; } void SetDebug(bool x) Modified: branches/dunks/src/Application.cpp =================================================================== --- branches/dunks/src/Application.cpp 2006-08-02 20:46:26 UTC (rev 75) +++ branches/dunks/src/Application.cpp 2006-08-03 18:21:35 UTC (rev 76) @@ -222,40 +222,37 @@ Die(); }; - // set the video palette - // grab the palette from any image, we use menu + // reset the palette if we've got one + if (m_currentPalette != NULL) + SetPalette(m_currentPalette); - //SDL_Surface* menu = (SDL_Surface*)(dataFile[UI_Menu].dat); - //SDL_Palette* palette = new SDL_Palette; - //palette->ncolors = menu->format->palette->ncolors; - //palette->colors = new SDL_Color[palette->ncolors]; - //memcpy(palette->colors, menu->format->palette->colors, - // sizeof(SDL_Color) * palette->ncolors); - //SDL_SetColors(m_screen, palette->colors, 0, palette->ncolors); - SDL_ShowCursor(SDL_DISABLE); m_rootWidget->setSize(set->m_width, set->m_height); m_rootWidget->setPos(0, 0); }; -void Application::SetVideoMode() +void Application::UpdateVideoMode(bool fs) { - Settings* set = Settings::Instance(); + Settings::Instance()->m_fullscreen = fs; + InitVideo(); +}; + +void Application::UpdateVideoMode(Uint16 w, Uint16 h) +{ + Settings::Instance()->m_width = w; + Settings::Instance()->m_height = h; + InitVideo(); +}; - int videoFlags = SDL_HWPALETTE; - if (set->m_doubleBuffered) - videoFlags |= SDL_HWSURFACE | SDL_DOUBLEBUF; - if (set->m_fullscreen) - videoFlags |= SDL_FULLSCREEN; +void Application::UpdateVideoMode(Uint16 w, Uint16 h, bool fs) +{ + Settings::Instance()->m_width = w; + Settings::Instance()->m_height = h; + Settings::Instance()->m_fullscreen = fs; + InitVideo(); +}; - m_screen = SDL_SetVideoMode(set->m_width, set->m_height, - 8, videoFlags); - - m_rootWidget->setSize(set->m_width, set->m_height); - m_rootWidget->setPos(0, 0); -} - void Application::LoadData() { printf("loading resources\n"); Modified: branches/dunks/src/OptionsMenu.cpp =================================================================== --- branches/dunks/src/OptionsMenu.cpp 2006-08-02 20:46:26 UTC (rev 75) +++ branches/dunks/src/OptionsMenu.cpp 2006-08-03 18:21:35 UTC (rev 76) @@ -38,16 +38,16 @@ switch (set->GetWidth()) { case 640: - m_caption = "640x480"; - break; + m_caption = "640x480"; + break; case 800: - m_caption = "800x600"; - break; + m_caption = "800x600"; + break; case 1024: - m_caption = "1024x768"; - break; + m_caption = "1024x768"; + break; } @@ -94,37 +94,39 @@ void OptionsMenuState::doResolution() { - Settings * set = Settings::Instance(); + Application* app = Application::Instance(); + Settings* set = Settings::Instance(); + switch (set->GetWidth()) { case 640: - set->SetScreenSize(800, 600); - m_butResolution->setCaption("800x600"); - break; + app->UpdateVideoMode(800, 600); + m_butResolution->setCaption("800x600"); + break; case 800: - set->SetScreenSize(1024, 768); - m_butResolution->setCaption("1024x768"); - break; + app->UpdateVideoMode(1024, 768); + m_butResolution->setCaption("1024x768"); + break; case 1024: - set->SetScreenSize(640, 480); - m_butResolution->setCaption("640x480"); - break; - + app->UpdateVideoMode(640, 480); + m_butResolution->setCaption("640x480"); + break; } - Application::Instance()->SetVideoMode(); } void OptionsMenuState::doScreenMode() { Settings * set = Settings::Instance(); - set->SetFullScreen(!Settings::Instance()->GetFullScreen()); - if (set->GetFullScreen()) + bool newSetting = !set->GetFullScreen(); + + Application::Instance()->UpdateVideoMode(newSetting); + + if (newSetting) m_butWindowMode->setCaption("Fullscreen"); else m_butWindowMode->setCaption("Window mode"); - Application::Instance()->SetVideoMode(); } void OptionsMenuState::JustMadeActive() Modified: branches/dunks/src/Settings.cpp =================================================================== --- branches/dunks/src/Settings.cpp 2006-08-02 20:46:26 UTC (rev 75) +++ branches/dunks/src/Settings.cpp 2006-08-03 18:21:35 UTC (rev 76) @@ -17,6 +17,7 @@ m_doubleBuffered = false; }; + void Settings::ParseFile(char* fn) { /* This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <shu...@us...> - 2006-08-02 20:46:36
|
Revision: 75 Author: shutdownrunner Date: 2006-08-02 13:46:26 -0700 (Wed, 02 Aug 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=75&view=rev Log Message: ----------- Add optionsmenu to svn(read:bad memory) Added Paths: ----------- branches/dunks/include/OptionsMenu.h branches/dunks/src/OptionsMenu.cpp Added: branches/dunks/include/OptionsMenu.h =================================================================== --- branches/dunks/include/OptionsMenu.h (rev 0) +++ branches/dunks/include/OptionsMenu.h 2006-08-02 20:46:26 UTC (rev 75) @@ -0,0 +1,39 @@ +#ifndef DUNE_OPTIONSMENU_H +#define DUNE_OPTIONSMENU_H + +#include "State.h" +#include "gui2/Button.h" +#include "gui2/VBox.h" + +#include "SDL.h" + + +class OptionsMenuState : public State +{ + public: + OptionsMenuState(); + ~OptionsMenuState(); + + void JustMadeActive(); + void JustMadeInactive(); + + int Execute(float dt); + void doOptions(); + void doOk(); + void doResolution(); + void doScreenMode(); + + virtual const char* GetName() { return "OptionsMenuState"; } + + private: + SDL_Surface* m_menuBackground; + //Window* m_menu; + + VBox* m_vbox; + + BoringButton* m_butResolution; + BoringButton* m_butWindowMode; + BoringButton* m_butOk; +}; + +#endif // DUNE_OPTIONSMENU_H Added: branches/dunks/src/OptionsMenu.cpp =================================================================== --- branches/dunks/src/OptionsMenu.cpp (rev 0) +++ branches/dunks/src/OptionsMenu.cpp 2006-08-02 20:46:26 UTC (rev 75) @@ -0,0 +1,147 @@ +#include "OptionsMenu.h" + +#include "Application.h" +#include "DataFile.h" +#include "Settings.h" + +#include "boost/bind.hpp" + + +OptionsMenuState::OptionsMenuState() +{ + //m_menuBackground = (SDL_Surface*)(dataFile[UI_Menu].dat); + //m_menu = new Window(); + //m_menu->setHeight(m_menuBackground->h); + //m_menu->setWidth(m_menuBackground->w); + + const int bw = 200; + const int bh = 20; + + std::string m_caption; + + Settings* set = Settings::Instance(); + + m_vbox = new VBox(); + + if (set->GetFullScreen()) + m_caption = "Fullscreen"; + else + m_caption = "Window mode"; + + m_butWindowMode = new BoringButton(m_caption); + m_butWindowMode->setSize(bw, bh); + m_butWindowMode->onClick.connect( + boost::bind(&OptionsMenuState::doScreenMode, this) ); + + m_vbox->addChild(m_butWindowMode); + + switch (set->GetWidth()) + { + case 640: + m_caption = "640x480"; + break; + + case 800: + m_caption = "800x600"; + break; + + case 1024: + m_caption = "1024x768"; + break; + + } + + m_butResolution = new BoringButton(m_caption); + m_butResolution->setSize(bw,bh); + m_butResolution->onClick.connect( + boost::bind(&OptionsMenuState::doResolution, this) ); + + m_vbox->addChild(m_butResolution); + + m_butOk = new BoringButton("Ok"); + m_butOk->setSize(bw, bh); + m_butOk->onClick.connect( + boost::bind(&OptionsMenuState::doOk, this) ); + + m_vbox->addChild(m_butOk); + + m_vbox->fit(2); + Uint16 x = (Settings::Instance()->GetWidth() / 2) - + (m_vbox->getWidth() / 2); + m_vbox->setPos(x - 5, 312); + m_vbox->reshape(); +}; + +OptionsMenuState::~OptionsMenuState() +{ + delete m_butWindowMode; + delete m_butResolution; + delete m_butOk; + + delete m_vbox; +}; + +void OptionsMenuState::doOptions() +{ + printf("Options"); +}; + +void OptionsMenuState::doOk() +{ + assert(mp_parent != NULL); + PopState(); +} + +void OptionsMenuState::doResolution() +{ + Settings * set = Settings::Instance(); + switch (set->GetWidth()) + { + case 640: + set->SetScreenSize(800, 600); + m_butResolution->setCaption("800x600"); + break; + + case 800: + set->SetScreenSize(1024, 768); + m_butResolution->setCaption("1024x768"); + break; + + case 1024: + set->SetScreenSize(640, 480); + m_butResolution->setCaption("640x480"); + break; + + } + Application::Instance()->SetVideoMode(); +} + +void OptionsMenuState::doScreenMode() +{ + Settings * set = Settings::Instance(); + set->SetFullScreen(!Settings::Instance()->GetFullScreen()); + if (set->GetFullScreen()) + m_butWindowMode->setCaption("Fullscreen"); + else + m_butWindowMode->setCaption("Window mode"); + Application::Instance()->SetVideoMode(); +} + +void OptionsMenuState::JustMadeActive() +{ + State::JustMadeActive(); + Application::Instance()->RootWidget()->addChild(m_vbox); +}; + +void OptionsMenuState::JustMadeInactive() +{ + State::JustMadeInactive(); + Application::Instance()->RootWidget()->deleteChild(m_vbox); +}; + +int OptionsMenuState::Execute(float dt) +{ + //Application::Instance()->BlitCentered(m_menuBackground); + + return 0; +}; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <shu...@us...> - 2006-08-02 19:33:24
|
Revision: 74 Author: shutdownrunner Date: 2006-08-02 12:33:01 -0700 (Wed, 02 Aug 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=74&view=rev Log Message: ----------- -Make singlemenu use boring buttons -Add optionsmenu Modified Paths: -------------- branches/dunks/include/Application.h branches/dunks/include/MainMenu.h branches/dunks/include/Settings.h branches/dunks/include/SingleMenu.h branches/dunks/include/gui2/Button.h branches/dunks/src/Application.cpp branches/dunks/src/MainMenu.cpp branches/dunks/src/SConscript branches/dunks/src/SingleMenu.cpp branches/dunks/src/gui2/Button.cpp Modified: branches/dunks/include/Application.h =================================================================== --- branches/dunks/include/Application.h 2006-08-01 20:26:06 UTC (rev 73) +++ branches/dunks/include/Application.h 2006-08-02 19:33:01 UTC (rev 74) @@ -48,6 +48,7 @@ void SetPalette(SDL_Palette* pal); SDL_Palette* GetCurrentPalette() { return m_currentPalette; } + void SetVideoMode(); private: void InitSettings(); @@ -57,6 +58,7 @@ void InitVideo(); void LoadData(); + void HandleEvents(); void BlitCursor(); Modified: branches/dunks/include/MainMenu.h =================================================================== --- branches/dunks/include/MainMenu.h 2006-08-01 20:26:06 UTC (rev 73) +++ branches/dunks/include/MainMenu.h 2006-08-02 19:33:01 UTC (rev 74) @@ -15,11 +15,10 @@ //void JustMadeInactive(); //int Execute(float dt); - + void doOptions(); void doSkirmish(); void doSingle(); void doQuit(); - virtual const char* GetName() { return "MainMenuState"; } private: Modified: branches/dunks/include/Settings.h =================================================================== --- branches/dunks/include/Settings.h 2006-08-01 20:26:06 UTC (rev 73) +++ branches/dunks/include/Settings.h 2006-08-02 19:33:01 UTC (rev 74) @@ -59,7 +59,7 @@ { friend class Singleton<Settings>; friend class Application; - + friend class OptionsMenuState; protected: Settings(); @@ -80,21 +80,15 @@ inline int GetHeight() { return m_height; } - // put in application - /* - void SetScreenSize(int width, int height); - { m_screenWidth = width; - m_screenHeight = height; } - */ + void SetScreenSize(int width, int height) + { m_width = width; + m_height = height; }; inline bool GetFullScreen() { return m_fullscreen; } - // put in application - /* void SetFullScreen(bool x) { m_fullscreen = x; } - */ inline bool GetDebug() { return m_debug; } Modified: branches/dunks/include/SingleMenu.h =================================================================== --- branches/dunks/include/SingleMenu.h 2006-08-01 20:26:06 UTC (rev 73) +++ branches/dunks/include/SingleMenu.h 2006-08-02 19:33:01 UTC (rev 74) @@ -30,11 +30,11 @@ VBox* m_vbox; - GraphicButton* m_butCampaign; - GraphicButton* m_butCustom; - GraphicButton* m_butSkirmish; - GraphicButton* m_butLoad; - GraphicButton* m_butCancel; + BoringButton* m_butCampaign; + BoringButton* m_butCustom; + BoringButton* m_butSkirmish; + BoringButton* m_butLoad; + BoringButton* m_butCancel; }; #endif // DUNE_SINGLEMENU_H Modified: branches/dunks/include/gui2/Button.h =================================================================== --- branches/dunks/include/gui2/Button.h 2006-08-01 20:26:06 UTC (rev 73) +++ branches/dunks/include/gui2/Button.h 2006-08-02 19:33:01 UTC (rev 74) @@ -43,7 +43,8 @@ ~BoringButton(); virtual void setSize(Uint16 w, Uint16 h); - + std::string getCaption() { return m_caption;} ; + void setCaption(std::string newcaption); protected: std::string m_caption; Modified: branches/dunks/src/Application.cpp =================================================================== --- branches/dunks/src/Application.cpp 2006-08-01 20:26:06 UTC (rev 73) +++ branches/dunks/src/Application.cpp 2006-08-02 19:33:01 UTC (rev 74) @@ -239,6 +239,23 @@ m_rootWidget->setPos(0, 0); }; +void Application::SetVideoMode() +{ + Settings* set = Settings::Instance(); + + int videoFlags = SDL_HWPALETTE; + if (set->m_doubleBuffered) + videoFlags |= SDL_HWSURFACE | SDL_DOUBLEBUF; + if (set->m_fullscreen) + videoFlags |= SDL_FULLSCREEN; + + m_screen = SDL_SetVideoMode(set->m_width, set->m_height, + 8, videoFlags); + + m_rootWidget->setSize(set->m_width, set->m_height); + m_rootWidget->setPos(0, 0); +} + void Application::LoadData() { printf("loading resources\n"); Modified: branches/dunks/src/MainMenu.cpp =================================================================== --- branches/dunks/src/MainMenu.cpp 2006-08-01 20:26:06 UTC (rev 73) +++ branches/dunks/src/MainMenu.cpp 2006-08-02 19:33:01 UTC (rev 74) @@ -5,6 +5,7 @@ #include "Settings.h" #include "SingleMenu.h" +#include "OptionsMenu.h" #include "boost/bind.hpp" @@ -53,7 +54,7 @@ //m_butOptions = new GraphicButton((SDL_Surface*)(dataFile[UI_OptionsMM].dat), // (SDL_Surface*)(dataFile[UI_OptionsMM_Pressed].dat)); m_butOptions->onClick.connect( - boost::bind(&MainMenuState::doSkirmish, this) ); + boost::bind(&MainMenuState::doOptions, this) ); m_vbox->addChild(m_butOptions); @@ -96,6 +97,11 @@ delete m_vbox; }; +void MainMenuState::doOptions() +{ + mp_parent->PushState( new OptionsMenuState() ); +}; + void MainMenuState::doSkirmish() { printf("skirmish!\n"); Modified: branches/dunks/src/SConscript =================================================================== --- branches/dunks/src/SConscript 2006-08-01 20:26:06 UTC (rev 73) +++ branches/dunks/src/SConscript 2006-08-02 19:33:01 UTC (rev 74) @@ -23,7 +23,8 @@ "MenuBase.cpp", "MainMenu.cpp", "IntroState.cpp", - "SingleMenu.cpp", + "SingleMenu.cpp", + "OptionsMenu.cpp", "Gfx.cpp", "houses.cpp", # just for colors, hope there will be a better place for these (otpetrik) Modified: branches/dunks/src/SingleMenu.cpp =================================================================== --- branches/dunks/src/SingleMenu.cpp 2006-08-01 20:26:06 UTC (rev 73) +++ branches/dunks/src/SingleMenu.cpp 2006-08-02 19:33:01 UTC (rev 74) @@ -9,43 +9,46 @@ SingleMenuState::SingleMenuState() { - m_menuBackground = (SDL_Surface*)(dataFile[UI_Menu].dat); + //m_menuBackground = (SDL_Surface*)(dataFile[UI_Menu].dat); //m_menu = new Window(); //m_menu->setHeight(m_menuBackground->h); //m_menu->setWidth(m_menuBackground->w); + const int bw = 200; + const int bh = 20; + m_vbox = new VBox(); - m_butCampaign = new GraphicButton((SDL_Surface*)(dataFile[UI_Single_Campaign].dat), - (SDL_Surface*)(dataFile[UI_Single_Campaign_Pressed].dat)); + m_butCampaign = new BoringButton("Campaign"); + m_butCampaign->setSize(bw, bh); m_butCampaign->onClick.connect( boost::bind(&SingleMenuState::doSkirmish, this) ); m_vbox->addChild(m_butCampaign); - m_butCustom = new GraphicButton((SDL_Surface*)(dataFile[UI_Single_Custom].dat), - (SDL_Surface*)(dataFile[UI_Single_Custom_Pressed].dat)); + m_butCustom = new BoringButton("Custom Game"); + m_butCustom->setSize(bw,bh); m_butCustom->onClick.connect( boost::bind(&SingleMenuState::doSkirmish, this) ); m_vbox->addChild(m_butCustom); - m_butSkirmish = new GraphicButton((SDL_Surface*)(dataFile[UI_Single_Skirmish].dat), - (SDL_Surface*)(dataFile[UI_Single_Skirmish_Pressed].dat)); + m_butSkirmish = new BoringButton("Skirmish"); + m_butSkirmish->setSize(bw, bh); m_butSkirmish->onClick.connect( boost::bind(&SingleMenuState::doSkirmish, this) ); m_vbox->addChild(m_butSkirmish); - m_butLoad = new GraphicButton((SDL_Surface*)(dataFile[UI_Load].dat), - (SDL_Surface*)(dataFile[UI_Load_Pressed].dat)); + m_butLoad = new BoringButton("Load Game"); + m_butLoad->setSize(bw, bh); m_butLoad->onClick.connect( boost::bind(&SingleMenuState::doSkirmish, this) ); m_vbox->addChild(m_butLoad); - m_butCancel = new GraphicButton((SDL_Surface*)(dataFile[UI_Cancel].dat), - (SDL_Surface*)(dataFile[UI_Cancel_Pressed].dat)); + m_butCancel = new BoringButton("Cancel"); + m_butCancel->setSize(bw, bh); m_butCancel->onClick.connect( boost::bind(&SingleMenuState::doCancel, this) ); @@ -71,7 +74,7 @@ void SingleMenuState::doSkirmish() { - printf("skirmish!\n"); + printf("Skirmish\n"); }; void SingleMenuState::doCancel() @@ -94,7 +97,7 @@ int SingleMenuState::Execute(float dt) { - Application::Instance()->BlitCentered(m_menuBackground); + //Application::Instance()->BlitCentered(m_menuBackground); return 0; }; Modified: branches/dunks/src/gui2/Button.cpp =================================================================== --- branches/dunks/src/gui2/Button.cpp 2006-08-01 20:26:06 UTC (rev 73) +++ branches/dunks/src/gui2/Button.cpp 2006-08-02 19:33:01 UTC (rev 74) @@ -101,6 +101,12 @@ redraw(); }; +void BoringButton::setCaption(std::string newcaption) +{ + m_caption = newcaption; + redraw(); +}; + void BoringButton::redraw() { if (m_surfNormal != NULL) SDL_FreeSurface(m_surfNormal); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <shu...@us...> - 2006-08-01 20:26:18
|
Revision: 73 Author: shutdownrunner Date: 2006-08-01 13:26:06 -0700 (Tue, 01 Aug 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=73&view=rev Log Message: ----------- Make boring buttons more readable Modified Paths: -------------- branches/dunks/src/gui2/Button.cpp Modified: branches/dunks/src/gui2/Button.cpp =================================================================== --- branches/dunks/src/gui2/Button.cpp 2006-08-01 18:49:55 UTC (rev 72) +++ branches/dunks/src/gui2/Button.cpp 2006-08-01 20:26:06 UTC (rev 73) @@ -119,8 +119,8 @@ SDL_SetColors(m_surfNormal, pal->colors, 0, pal->ncolors); SDL_SetColors(m_surfPressed, pal->colors, 0, pal->ncolors); - SDL_FillRect(m_surfNormal, NULL, 23); - SDL_FillRect(m_surfPressed, NULL, 18); + SDL_FillRect(m_surfNormal, NULL, 30); + SDL_FillRect(m_surfPressed, NULL, 30); Font* font = FontManager::Instance()->getFont("INTRO:INTRO.FNT"); @@ -131,10 +131,10 @@ font->render(m_caption.c_str(), m_surfNormal, (m_width / 2) - (textw / 2), - (m_height / 2) - (texth / 2), 2); + (m_height / 2) - (texth / 2), 31); font->render(m_caption.c_str(), m_surfPressed, (m_width / 2) - (textw / 2), - (m_height / 2) - (texth / 2), 2); + (m_height / 2) - (texth / 2), 47); }; // ------------------------------------------------------------------ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otp...@us...> - 2006-08-01 18:50:02
|
Revision: 72 Author: otpetrik Date: 2006-08-01 11:49:55 -0700 (Tue, 01 Aug 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=72&view=rev Log Message: ----------- Point<T> constructor fix (now defaults to 0,0). Modified Paths: -------------- branches/dunks/include/Gfx.h Modified: branches/dunks/include/Gfx.h =================================================================== --- branches/dunks/include/Gfx.h 2006-08-01 18:31:20 UTC (rev 71) +++ branches/dunks/include/Gfx.h 2006-08-01 18:49:55 UTC (rev 72) @@ -187,7 +187,7 @@ //@{ //! Constructor - Point(T x, T y) : x(x), y(y) { }; + Point(T x = 0, T y = 0) : x(x), y(y) { }; //! Copy constructor Point(const Point &point) { *this = point; }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otp...@us...> - 2006-08-01 18:31:30
|
Revision: 71 Author: otpetrik Date: 2006-08-01 11:31:20 -0700 (Tue, 01 Aug 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=71&view=rev Log Message: ----------- fixed pakfile/Icnfile palette handling. Modified Paths: -------------- branches/dunks/include/pakfile/Icnfile.h branches/dunks/src/pakfile/Icnfile.cpp Modified: branches/dunks/include/pakfile/Icnfile.h =================================================================== --- branches/dunks/include/pakfile/Icnfile.h 2006-08-01 18:18:33 UTC (rev 70) +++ branches/dunks/include/pakfile/Icnfile.h 2006-08-01 18:31:20 UTC (rev 71) @@ -10,7 +10,7 @@ ~Icnfile(); - SDL_Surface * getPicture(Uint32 IndexOfFile); + SDL_Surface * getPicture(Uint32 IndexOfFile, SDL_Palette *palette); int getNumFiles(); Modified: branches/dunks/src/pakfile/Icnfile.cpp =================================================================== --- branches/dunks/src/pakfile/Icnfile.cpp 2006-08-01 18:18:33 UTC (rev 70) +++ branches/dunks/src/pakfile/Icnfile.cpp 2006-08-01 18:31:20 UTC (rev 71) @@ -98,7 +98,7 @@ ; }; -SDL_Surface* Icnfile::getPicture(Uint32 IndexOfFile) { +SDL_Surface* Icnfile::getPicture(Uint32 IndexOfFile, SDL_Palette *palette) { SDL_Surface * pic; if(IndexOfFile >= NumFiles) { @@ -119,7 +119,7 @@ return NULL; } - //SDL_SetColors(pic, palette->colors, 0, palette->ncolors); + SDL_SetColors(pic, palette->colors, 0, palette->ncolors); SDL_LockSurface(pic); //Now we can copy to surface This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otp...@us...> - 2006-08-01 18:18:50
|
Revision: 70 Author: otpetrik Date: 2006-08-01 11:18:33 -0700 (Tue, 01 Aug 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=70&view=rev Log Message: ----------- Gfx routines centralization. Modified Paths: -------------- branches/dunks/include/gui/Graphics.h branches/dunks/src/CutScene.cpp branches/dunks/src/SConscript branches/dunks/src/gui/Graphics.cpp Added Paths: ----------- branches/dunks/include/Gfx.h branches/dunks/src/Gfx.cpp Added: branches/dunks/include/Gfx.h =================================================================== --- branches/dunks/include/Gfx.h (rev 0) +++ branches/dunks/include/Gfx.h 2006-08-01 18:18:33 UTC (rev 70) @@ -0,0 +1,936 @@ +/*! + \file Gfx.h + \brief Various gfx routines. + + @note Use Image class and coresponding methods. SDL_Surface-based functions will + be removed by moving their code directly into the Image class. + +*/ + +#ifndef DUNE_GFX_H +#define DUNE_GFX_H + +#include "SDL.h" + +#include "Colours.h" + +#include <boost/shared_ptr.hpp> + +//------------------------------------------------------------------------------ +// Single pixel operations +//------------------------------------------------------------------------------ +//! @name Single pixel operations +//@{ + +//! Set pixel on given surface +/*! + @param surface surface to draw to + @param x x-coord + @param y y-coord + @param color color + + @warning The surface has to be locked ! +*/ +void putPixel(SDL_Surface *surface, int x, int y, Uint32 color); + +//! Get pixel from given surface +/*! + @param surface surface to read from + @param x x-coord + @param y y-coord + @return read color + + @warning The surface has to be locked ! +*/ +Uint32 getPixel(SDL_Surface *surface, int x, int y); + +//@} + +//------------------------------------------------------------------------------ +// Drawing operations +//------------------------------------------------------------------------------ +//! @name Drawing operations +//@{ + +//! Draw horizontal line +/*! + @param surface surface to draw to + @param x x-coord of start + @param y y-coord of start + @param x2 x-coord of finish + @param color color to draw with + @param lock whether to lock the surface (defaults to yes) +*/ +void drawHLine(SDL_Surface *surface, int x, int y, int x2, Uint32 color, bool lock = true); + +//! Draw vertical line +/*! + @param surface surface to draw to + @param x x-coord of start + @param y y-coord of start + @param y2 y-coord of finish + @param color color to draw with + @param lock whether to lock the surface (defaults to yes) +*/ +void drawVLine(SDL_Surface *surface, int x, int y, int y2, Uint32 color, bool lock = true); + +//! Draw rectangle +/*! + @param surface surface to draw to + @param rect rectangle to draw + @param color color to draw with + @param lock whether to lock the surface (defaults to yes) +*/ +void drawRect(SDL_Surface *surface, const SDL_Rect &rect, Uint32 color, bool lock = true); + +//@} + +//------------------------------------------------------------------------------ +// Surface operations +//------------------------------------------------------------------------------ +//! @name Surface operations +//@{ + +//! Make copy of surface +/*! + @param surface original surface +*/ +SDL_Surface* copySurface(SDL_Surface* surface); + +//! Make resized copy of surface +/*! + @param surface original surface + @param w new width + @param h new height +*/ +SDL_Surface* resizeSurface(SDL_Surface *surface, Uint16 w, Uint16 h); + + +//! Make resized copy of surface +/*! + @param surface original surface + @param ratio ratio of new surface to original (2 = double size) +*/ +SDL_Surface* resizeSurface(SDL_Surface *surface, double ratio); + + +//@} + +//------------------------------------------------------------------------------ +// Color remapping +//------------------------------------------------------------------------------ +//! @name Color mapping +//@{ + +#define DEFAULT_SURFACE_REMAP_LENGTH 7 +#define DEFAULT_SURFACE_REMAP_BEGIN COLOUR_HARKONNEN + +//! Remap colors of surface +/*! + @param surface source (and destination) surface + @param colorSrc first color to be replaced + @param colorDst first color to be used as replacement + @param colorNum number of colors to replace (last is colorSrc+colorNum-1) +*/ +void remapSurface(SDL_Surface *surface, int colorSrc, int colorDst, int colorNum = DEFAULT_SURFACE_REMAP_LENGTH); + +//! Remap colors of surface +/*! + @param surface source (and destination) surface + @param house house to remap colors to + + @note Starting color and color number defaults to hardcoded numbers. +*/ +void remapSurfaceByHouse(SDL_Surface *surface, int house); + +//! Remap colors of surface +/*! + @param surface source (and destination) surface + @param color first color to be used as replacement + + @note Starting color and color number defaults to hardcoded numbers. +*/ +inline void remapSurfaceByColor(SDL_Surface *surface, int color) +{ + remapSurface(surface, DEFAULT_SURFACE_REMAP_BEGIN, color); +}; + +//@} + +//------------------------------------------------------------------------------ +// Classes & Structures +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Point struct +//------------------------------------------------------------------------------ +//! The Point struct is basic representation of a point +/*! + @note Implemented fully inline, so no need to worry about speed. +*/ +template <typename T> +struct Point +{ + public: + //! @name Member variables + //@{ + + //! x-coordinate + T x; + //! y-coordinate + T y; + + //@} + + + //! @name Constructors & Destructor + //@{ + + //! Constructor + Point(T x, T y) : x(x), y(y) { }; + //! Copy constructor + Point(const Point &point) { *this = point; }; + + //@} + + //! @name Operators + //@{ + + //! operator = + Point &operator=(const Point &point) + { + x = point.x; + y = point.y; + return *this; + }; + //! operator += + Point &operator+=(const Point &point) + { + x += point.x; + y += point.y; + return *this; + }; + //! operator -= + Point &operator-=(const Point &point) + { + x += point.x; + y += point.y; + return *this; + }; + //! operator *= + Point &operator*=(T times) + { + x *= times; + y *= times; + return *this; + }; + //! operator /= + /* + @warning: Do not divide by zero ! + */ + Point &operator/=(T times) + { + // TODO: assert ? + x /= times; + y /= times; + return *this; + }; + + //! operator + + Point operator+(const Point &point) const + { + return Point(x + point.x, y + point.y); + }; + //! operator - + Point operator-(const Point &point) const + { + return Point(x - point.x, y - point.y); + }; + //! operator * + Point operator*(T times) const + { + return Point(x*times, y*times); + }; + //! operator / + /*! + @warning: Do not divide by zero ! + */ + Point operator/(T times) const + { + // TODO: assert ? + return Point(x/times, y/times); + }; + + //! Type-casting operator + /*! + If it doesn't compile, then the types are incompatible. + */ + template <typename T2> + operator Point<T2>() const + { + return Point<T2>(x, y); + } + + //@} + + //! @name Miscellaneous methods + //@{ + + //! Swap x<->y coordinates + const Point &swap() + { + T t = x; + x = y; + y = t; + }; + + //! Return point with swapped x<->y coordinates + Point getSwapped() const + { + return Point(y, x); + }; + + //@} +}; + +//! Point with unsigned coordinates +typedef Point<Uint16> UPoint; +//! Constant Point with unsigned coordinates +typedef const UPoint &ConstUPoint; + +//! Point with signed coordinates +typedef Point<Sint16> SPoint; +//! Constant Point with signed coordinates +typedef const SPoint &ConstSPoint; + +//! Point with signed 32-bit coordinates +typedef Point<Sint32> SPointBig; +//! Constant Point with signed 32-bit coordinates +typedef const SPointBig &ConstSPointBig; + +//! Point with float coordinates +typedef Point<float> PointFloat; +//! Constant Point with float coordinates +typedef const PointFloat &ConstPointFloat; + +//! @name Unary minus operators for signed points +//! @relates Point +//@{ +inline SPoint operator-(const SPoint &point) +{ + return SPoint(point.x, point.y); +}; + +inline SPointBig operator-(const SPointBig &point) +{ + return SPointBig(point.x, point.y); +}; + +inline PointFloat operator-(const PointFloat &point) +{ + return PointFloat(point.x, point.y); +}; +//@} + + +//------------------------------------------------------------------------------ +// Rect struct +//------------------------------------------------------------------------------ +//! The Rect struct is an extension of SDL_Rect +/*! + This struct provides convenient constructors and methods to test if Rect + contains another Rect or Point. + + @note Member wariables are x,y (Sint16) and w,h (Uint16) inherited from + SDL_Rect + + @note Implemented fully inline, so no need to worry about speed. +*/ +struct Rect : public SDL_Rect +{ + public: + + //! @name Constructors & Destructor + //@{ + + //! Constructor + Rect(Sint16 x = 0, Sint16 y = 0, Uint16 w = 0, Uint16 h = 0) + { + this->x = x; + this->y = y; + this->w = w; + this->h = h; + }; + //! Constructor + Rect(const SPoint &position, const UPoint &size) + { + setPosition(position); + setSize(size); + }; + //! Copy onstructor + Rect(const Rect &rect) + { + x = rect.x; + y = rect.y; + w = rect.w; + h = rect.h; + }; + //! Copy onstructor + Rect(const SDL_Rect &rect) + { + x = rect.x; + y = rect.y; + w = rect.w; + h = rect.h; + }; + + //@} + + //! @name Operators + //@{ + + //! Type-casting operator to SDL_Rect + operator SDL_Rect() const + { + return *this; + }; + //! operator = (from SDL_Rect) + Rect &operator=(const SDL_Rect &rect) + { + x = rect.x; + y = rect.y; + w = rect.w; + h = rect.h; + return *this; + } + + //@} + + //! @name Placement & Size + //@{ + + //! Set x,y to given position + void setPosition(const SPoint &position) + { + x = position.x; + y = position.y; + }; + //! Set w,h to given size + void setSize(const UPoint &size) + { + w = size.x; + h = size.y; + }; + //! Return current positon + SPoint getPosition() const + { + return SPoint(x, y); + }; + //! Return current size + UPoint getSize() const + { + return UPoint(x, y); + }; + + //@} + + //! @name Queries + //@{ + + //! Is point inside this Rect ? + /*! + @param p Point in question + */ + template<typename T> + bool contains(const Point<T> &p) const + { + return ( + (x <= p.x && p.x <= x+w) && + (y <= p.y && p.y <= y+h)); + }; + + //! Is a rect inside this Rect ? (partial match required) + /*! + Whole Rect has to be inside or equal this Rect. + @param r Roint in question + */ + bool containsWhole(const Rect &r) const + { + return ( + (x <= r.x && r.x+r.w <= x+w) && + (y <= r.y && r.y+r.h <= y+h)); + }; + //! Is a rect inside this Rect ? (partial match is enough) + /*! + Rect in question must have at least a pixel common with this Rect. + @param r Rect in question + */ + bool containsPartial(const Rect &r) const + { + return ( + (x <= r.x+r.w && r.x <= x+w) && + (y <= r.y+r.h && r.y <= y+h)); + }; + + //@} +}; + +//! Constant Rect +typedef const Rect &ConstRect; + +//------------------------------------------------------------------------------ +// Image class +//------------------------------------------------------------------------------ + +class Image; + +//! Smart pointer around Image class instance +typedef boost::shared_ptr<Image> ImagePtr; + +//! Smart pointer around Image class const instance +typedef boost::shared_ptr<const Image> ConstImagePtr; + +//! The Image class is a wrapper around SDL_Surface +/*! + It allows using SDL_Surfaces with smart pointers. + Use ConstImagePtr and ImagePtr where possible (former is more + favorable), it avoids memory leaks... + +*/ +class Image +{ + public: + + //! @name Constructors & Destructor + //@{ + + //! Constructor + /*! + @warning Do not pass NULL parameter ! + */ + Image(SDL_Surface *surface); + + //! Constructor + /*! + @param Size of the image ! + */ + Image(ConstUPoint size); + + //! Destructor + ~Image(); + + //@} + + //! @name Operators + //@{ + + //! Returns the surface + operator SDL_Surface*(); + + //@} + + //! @name Access methods + //@{ + + //! Returns the surface + SDL_Surface *getSurface(); + + //! Returns size of the surface + UPoint getSize() const + { + return UPoint(surface->w, surface->h); + }; + + //@} + + //! @name Single pixel operations + //@{ + + //! Set pixel on given surface + /*! + @param point coordinates of the pixel + @param color color + + @warning The surface has to be locked ! + */ + void putPixel(ConstUPoint point, Uint32 color) + { + ::putPixel(surface, point.x, point.y, color); + }; + + //! Get pixel from given surface + /*! + @param point coordinates of the pixel + @return read color + + @warning The surface has to be locked ! + */ + Uint32 getPixel(ConstUPoint point) const + { + return ::getPixel(surface, point.x, point.y); + }; + + //@} + + //! @name Drawing operations + //@{ + + //! Draw horizontal line + /*! + @param start coordinates of start + @param x2 x-coord of finish + @param color color to draw with + @param lock whether to lock the surface (defaults to yes) + */ + void drawHLine(ConstUPoint start, int x2, Uint32 color, bool lock = true) + { + ::drawHLine(surface, start.x, start.y, x2, color, lock); + }; + + //! Draw vertical line + /*! + @param start coordinates of start + @param y2 y-coord of finish + @param color color to draw with + @param lock whether to lock the surface (defaults to yes) + */ + void drawVLine(ConstUPoint start, int y2, Uint32 color, bool lock = true) + { + ::drawVLine(surface, start.x, start.y, y2, color, lock); + }; + + //! Draw rectangle + /*! + @param rect rectangle to draw + @param color color to draw with + @param lock whether to lock the surface (defaults to yes) + */ + void drawRect(ConstRect rect, Uint32 color, bool lock = true) + { + ::drawRect(surface, rect, color, lock); + }; + + //@} + + //! @name Image operations + //@{ + + //! Make copy of the image + ImagePtr getCopy() const + { + return ImagePtr(new Image(copySurface(surface))); + }; + + //! Make resized copy of the image + /*! + @param ratio ratio of new image to original (2 = double size) + */ + ImagePtr getResized(double ratio) const + { + return ImagePtr(new Image(resizeSurface(surface, ratio))); + }; + + //! Make resized copy of the image + /*! + @param size size of the new image + */ + ImagePtr getResized(ConstUPoint size) + { + return ImagePtr(new Image(resizeSurface(surface, size.x, size.y))); + }; + + + //! Set colorkey + /*! + @param color color which will be considered transparent + @param flags OR'd flags (see SDL_SetColorKey documentation for + details) + @note If you need to disable colorkey, think twice about your + code... + */ + void setColorKey(int color = 0, int flags = SDL_SRCCOLORKEY | SDL_RLEACCEL) + { + SDL_SetColorKey(surface, flags, color); + }; + + //@} + + //! @name Blit operations + //@{ + + //! Blit part of source image to this image + /*! + @param source source image + @param srcRect part of source image to copy + @param dstPoint target coordinates (top-left corner) + */ + void blitFrom(const Image *source, ConstRect srcRect, ConstUPoint dstPoint) + { + assert(source != NULL); + Rect dstRect(Rect(dstPoint, source->getSize())); + SDL_BlitSurface(source->surface, const_cast<SDL_Rect *>(static_cast<const SDL_Rect *>(&srcRect)), surface, &dstRect); + }; + //! Blit whole source image to this image + /*! + @param source source image + @param dstPoint target coordinates (top-left corner) + */ + void blitFrom(const Image *source, ConstUPoint dstPoint) + { + assert(source != NULL); + Rect dstRect(Rect(dstPoint, source->getSize())); + SDL_BlitSurface(source->surface, NULL, surface, &dstRect); + }; + //! Blit whole source image to this image (to top-left corner) + /*! + @param source source image + */ + void blitFrom(const Image *source) + { + assert(source != NULL); + SDL_BlitSurface(source->surface, NULL, surface, NULL); + }; + //! Blit whole source image to this image (to center) + /*! + @param source source image + */ + void blitFromCentered(const Image *source) + { + assert(source != NULL); + Rect dstRect(Rect(getSize()/2 - source->getSize()/2, source->getSize())); + SDL_BlitSurface(source->surface, NULL, surface, &dstRect); + }; + //! Blit part of the image to destination image + /*! + @param destination destination image + @param srcRect part of source image to copy + @param dstPoint target coordinates (top-left corner) + */ + void blitTo(Image *destination, ConstRect srcRect, ConstUPoint dstPoint) const + { + assert(destination != NULL); + destination->blitFrom(this, srcRect, dstPoint); + }; + //! Blit the whole image to destination image + /*! + @param destination destination image + @param dstPoint target coordinates (top-left corner) + */ + void blitTo(Image *destination, ConstUPoint dstPoint) const + { + assert(destination != NULL); + destination->blitFrom(this, dstPoint); + } + //! Blit the whole image to destination image (to top-left corner) + /*! + @param destination destination image + */ + void blitTo(Image *destination) const + { + assert(destination != NULL); + destination->blitFrom(this); + } + //! Blit the whole image to destination image (to center) + /*! + @param destination destination image + */ + void blitToCentered(Image *destination) const + { + assert(destination != NULL); + destination->blitFromCentered(this); + } + //! Blit part of the image to screen + /*! + @param destination destination image + @param srcRect part of source image to copy + @param dstPoint target coordinates (top-left corner) + */ + void blitToScreen(ConstRect srcRect, ConstUPoint dstPoint) const; + //! Blit the whole image to screen + /*! + @param destination destination image + @param dstPoint target coordinates (top-left corner) + */ + void blitToScreen(ConstUPoint dstPoint) const; + //! Blit the whole image to destination image (to top-left corner) + /*! + @param destination destination image + */ + void blitToScreen() const; + //! Blit the whole image to destination image (to center) + /*! + @param destination destination image + */ + void blitToScreenCentered() const; + + //@} + + //! @name Fill operations + //@{ + + void fillRect(Uint32 color, Rect dstRect) + { + SDL_FillRect(surface, &dstRect, color); + }; + void fillRect(Uint32 color) + { + SDL_FillRect(surface, NULL, color); + }; + + void fillRectVGradient(Uint32 color1, Uint32 color2, ConstRect dstRect); + void fillRectHGradient(Uint32 color1, Uint32 color2, ConstRect dstRect); + + //@} + + //! @name Color mapping + //@{ + + //! Remap colors of surface + /*! + @param colorSrc first color to be replaced + @param colorDst first color to be used as replacement + @param colorNum number of colors to replace (last is colorSrc+colorNum-1) + */ + void recolor(int colorSrc, int colorDst, int colorNum = DEFAULT_SURFACE_REMAP_LENGTH) + { + ::remapSurface(surface, colorSrc, colorDst, colorNum); + }; + + //! Remap colors of surface + /*! + @param house house to remap colors to + + @note Starting color and color number defaults to hardcoded numbers. + */ + void recolorByHouse(int house) + { + ::remapSurfaceByHouse(surface, house); + } + + //! Remap colors of surface + /*! + @param color first color to be used as replacement + + @note Starting color and color number defaults to hardcoded numbers. + */ + inline void recolorByColor(int color) + { + ::remapSurfaceByColor(surface, color); + }; + + //! Return copy with remapped colors of surface + /*! + @param colorSrc first color to be replaced + @param colorDst first color to be used as replacement + @param colorNum number of colors to replace (last is colorSrc+colorNum-1) + */ + ImagePtr getRecolored(int colorSrc, int colorDst, int colorNum = DEFAULT_SURFACE_REMAP_LENGTH) const + { + ImagePtr copy(getCopy()); + copy->recolor(colorSrc, colorDst, colorNum); + return copy; + }; + + //! Return copy with remapped colors of surface + /*! + @param house house to remap colors to + + @note Starting color and color number defaults to hardcoded numbers. + */ + ImagePtr getRecoloredByHouse(int house) const + { + ImagePtr copy(getCopy()); + copy->recolorByHouse(house); + return copy; + }; + + //! Return copy with remapped colors of surface + /*! + @param color first color to be used as replacement + + @note Starting color and color number defaults to hardcoded numbers. + */ + ImagePtr getRecoloredByColor(int color) const + { + ImagePtr copy(getCopy()); + copy->recolorByColor(color); + return copy; + }; + + + //@} + + + private: + SDL_Surface *surface; + Image() { }; +}; + +//------------------------------------------------------------------------------ +// DEPRECATED: +//------------------------------------------------------------------------------ +//! @name DEPRECATED (do not use !) +//@{ + +/*! + @deprecated Use putPixel(SDL_Surface *surface, int x, int y, Uint32 color) instead. +*/ +inline void putpixel(SDL_Surface *surface, int x, int y, Uint32 colour) { putPixel(surface, x, y, colour); }; + +/*! + @deprecated Use getPixel(SDL_Surface *surface, int x, int y); instead. +*/ +inline Uint32 getpixel(SDL_Surface *surface, int x, int y) { return getPixel(surface, x, y); }; + +/*! + @deprecated Use drawHLine(SDL_Surface *surface, int x, int y, int x2, Uint32 color, bool lock = true) with lock = false instead. +*/ +inline void hlineNoLock(SDL_Surface *surface, int x1, int y, int x2, Uint32 colour) +{ + drawHLine(surface, x1, y, x2, colour, false); +}; + +/*! + @deprecated Use void drawHLine(SDL_Surface *surface, int x, int y, int x2, Uint32 color, bool lock = true) instead. +*/ +inline void drawhline(SDL_Surface *surface, int x1, int y, int x2, Uint32 colour) +{ + drawHLine(surface, x1, y, x2, colour, true); +}; + +/*! + @deprecated Use drawRect(SDL_Surface *surface, const SDL_Rect &rect, Uint32 color, bool lock = true) instead. +*/ +inline void drawrect(SDL_Surface *surface, int x1, int y1, int x2, int y2, Uint32 colour) +{ + SDL_Rect r; + r.x = x1; + r.y = y1; + r.w = x2-x1; + r.h = y2-y1; + drawRect(surface, r, colour, true); +}; + +// DEPRECATED (works with surface, not with the 'Image' wrapper): +/*! + @deprecated Use remapSurfaceByHouse(SDL_Surface *surface, int house) instead. +*/ +inline void mapImageHouseColour(SDL_Surface* graphic, int house) +{ + remapSurfaceByHouse(graphic, house); +}; + +/*! + @deprecated If you really need to use this function, then your code is bad ! + @note <b>PENDING FOR REMOVAL:</b> it is used only by Game.cpp in doubtful way (otpetrik) +*/ +inline void mapImageHouseColourBase(SDL_Surface* graphic, int house, int baseCol) +{ + // slow, but it avoids additional include ;-) (it has to be enough till removed) + remapSurface(graphic, baseCol, 144); // remap back to harkonnen + remapSurfaceByHouse(graphic, house); +}; + +//@} + +#endif // DUNE_GFX_H Modified: branches/dunks/include/gui/Graphics.h =================================================================== --- branches/dunks/include/gui/Graphics.h 2006-08-01 16:00:41 UTC (rev 69) +++ branches/dunks/include/gui/Graphics.h 2006-08-01 18:18:33 UTC (rev 70) @@ -3,28 +3,25 @@ #include "SDL.h" -void catch_stdin(); +// TODO: remove once everyone uses Gfx.h instead of gui/Graphics.h +#include "Gfx.h" -void clearMessage(); +// +// these were already moved to Gfx.h/cpp : +// +//void mapImageHouseColour(SDL_Surface* graphic, int house); +//void mapImageHouseColourBase(SDL_Surface* graphic, int house, int baseCol); +//void putpixel(SDL_Surface *surface, int x, int y, Uint32 colour); +//Uint32 getpixel(SDL_Surface *surface, int x, int y); +//void hlineNoLock(SDL_Surface *surface, int x1, int y, int x2, Uint32 colour); +//void drawhline(SDL_Surface *surface, int x1, int y, int x2, Uint32 colour); +//void drawrect(SDL_Surface *surface, int x1, int y1, int x2, int y2, Uint32 colour); +//SDL_Surface* copySurface(SDL_Surface* inSurface); +//SDL_Surface* scaleSurface(SDL_Surface *surf, double ratio); -void mapImageHouseColour(SDL_Surface* graphic, int house); - -void mapImageHouseColourBase(SDL_Surface* graphic, int house, int baseCol); - -void putpixel(SDL_Surface *surface, int x, int y, Uint32 colour); - -Uint32 getpixel(SDL_Surface *surface, int x, int y); - -void hlineNoLock(SDL_Surface *surface, int x1, int y, int x2, Uint32 colour); - -void drawhline(SDL_Surface *surface, int x1, int y, int x2, Uint32 colour); - -void drawrect(SDL_Surface *surface, int x1, int y1, int x2, int y2, Uint32 colour); - +// these doesn't fit there..., probably to GameState or something like that... +void catch_stdin(); +void clearMessage(); void showMessage(char* newMessage); -SDL_Surface* copySurface(SDL_Surface* inSurface); - -SDL_Surface* scaleSurface(SDL_Surface *surf, double ratio); - #endif // DUNE_GUI_GRAPHICS_H Modified: branches/dunks/src/CutScene.cpp =================================================================== --- branches/dunks/src/CutScene.cpp 2006-08-01 16:00:41 UTC (rev 69) +++ branches/dunks/src/CutScene.cpp 2006-08-01 18:18:33 UTC (rev 70) @@ -9,8 +9,8 @@ #include "SoundPlayerClass.h" #include <stdlib.h> #include "gui/Graphics.h" +#include "Gfx.h" - #define CS_FRAME_TIME 150 @@ -87,69 +87,6 @@ } - - -/* - - * Return the pixel value at (x, y) - - * NOTE: The surface must be locked before calling this! - - */ - -Uint32 getpixel(SDL_Surface *surface, int x, int y) - -{ - - int bpp = surface->format->BytesPerPixel; - - /* Here p is the address to the pixel we want to retrieve */ - - Uint8 *p = (Uint8 *)surface->pixels + (y * surface->pitch) + (x * bpp); - - - - switch(bpp) { - - case 1: - - return *p; - - - - case 2: - - return *(Uint16 *)p; - - - - case 3: - - if(SDL_BYTEORDER == SDL_BIG_ENDIAN) - - return p[0] << 16 | p[1] << 8 | p[2]; - - else - - return p[0] | p[1] << 8 | p[2] << 16; - - - - case 4: - - return *(Uint32 *)p; - - - - default: - - return 0; /* shouldn't happen, but avoids warnings */ - - } - -} - - void DuneCutScene::playCutScene() { Added: branches/dunks/src/Gfx.cpp =================================================================== --- branches/dunks/src/Gfx.cpp (rev 0) +++ branches/dunks/src/Gfx.cpp 2006-08-01 18:18:33 UTC (rev 70) @@ -0,0 +1,350 @@ +#include "Gfx.h" + +#include "Application.h" // for Screen +#include "houses.h" // for house colors + +#include <assert.h> + +//------------------------------------------------------------------------------ +// Image class +//------------------------------------------------------------------------------ + +Image::Image(SDL_Surface *surface) : surface(surface) +{ + assert(surface != NULL); + if (surface == NULL) + { + // TODO: throw better exception !! + throw "Image::Image(SDL_Surface *) - got NULL !"; + }; +}; +Image::Image(ConstUPoint size) +{ + assert(size.x != 0); + assert(size.y != 0); + + surface = SDL_CreateRGBSurface( + SDL_SWSURFACE, // TODO: which one to use, HW or SW ? (otpetrik) + size.x, // width + size.y, // height + 8, // bits per pixel + 0,0,0,0);// r,g,b,a masks + + assert(surface != NULL); + if (surface == NULL) + { + // TODO: throw better exception !! + throw "Image::Image(ConstUPoint) - unable to create SDL_Surface !"; + }; + + // copy palette from the screen (otherwise you'll get only black image) + SDL_SetColors(surface, Application::Instance()->Screen()->format->palette->colors, 0, 256); +}; +Image::~Image() +{ + SDL_FreeSurface(surface); +}; +Image::operator SDL_Surface*() +{ + return surface; +}; +SDL_Surface *Image::getSurface() +{ + return surface; +}; + +// TODO: once Application::Instance()->Screen() returns ImagePtr, change +// these methods to use Image::blitTo ! +void Image::blitToScreen(ConstRect srcRect, ConstUPoint dstPoint) const +{ + Rect dstRect(Rect(dstPoint, getSize())); + SDL_BlitSurface(surface, const_cast<SDL_Rect *>(static_cast<const SDL_Rect *>(&srcRect)), Application::Instance()->Screen(), &dstRect); +}; +void Image::blitToScreen(ConstUPoint dstPoint) const +{ + Rect dstRect(Rect(dstPoint, getSize())); + SDL_BlitSurface(surface, NULL, Application::Instance()->Screen(), &dstRect); +}; +void Image::blitToScreen() const +{ + SDL_BlitSurface(surface, NULL, Application::Instance()->Screen(), NULL); +}; +void Image::blitToScreenCentered() const +{ + Rect dstRect(Rect(UPoint(Application::Instance()->Screen()->w, Application::Instance()->Screen()->h)/2 - getSize()/2, getSize())); + SDL_BlitSurface(surface, NULL, Application::Instance()->Screen(), &dstRect); +}; + + +void Image::fillRectVGradient(Uint32 color1, Uint32 color2, ConstRect dstRect) +{ + int numColors = color2 - color1 + 1; + float stripeWidth = dstRect.w/(float)numColors; + float begin; + float end; + Rect r(dstRect); + for (int i = 0; i < numColors; i++) + { + // calculate begin & end of i-th strip + begin = i*stripeWidth; + end = (i+1)*stripeWidth; + + // round the border pixel to major one + begin = (int)begin + (((begin - (int)begin) < 0.5f) ? 0 : 1); + end = (int)end + (((end - (int)end) < 0.5f) ? 0 : 1); + + // calcuate the rect + r.x = (int)begin; + r.w = (int)end - r.x; + + // fillit + fillRect(color1 + i, r); + } +}; +void Image::fillRectHGradient(Uint32 color1, Uint32 color2, ConstRect dstRect) +{ + int numColors = color2 - color1 + 1; + float stripeHeight = dstRect.h/(float)numColors; + float begin; + float end; + Rect r(dstRect); + for (int i = 0; i < numColors; i++) + { + // calculate begin & end of i-th strip + begin = i*stripeHeight; + end = (i+1)*stripeHeight; + + // round the border pixel to major one + begin = (int)begin + (((begin - (int)begin) < 0.5f) ? 0 : 1); + end = (int)end + (((end - (int)end) < 0.5f) ? 0 : 1); + + // calcuate the rect + r.y = (int)begin; + r.h = (int)end - r.y; + + // fillit + fillRect(color1 + i, r); + } +}; + +//------------------------------------------------------------------------------ +// Single pixel operations +//------------------------------------------------------------------------------ + +void putPixel(SDL_Surface *surface, int x, int y, Uint32 color) +{ + assert(surface != NULL); + SDL_Surface *screen = Application::Instance()->Screen(); + if (x >= 0 && x < screen->w && y >=0 && y < screen->h) + { + int bpp = surface->format->BytesPerPixel; + // p is the address of the pixel to set + Uint8 *p = (Uint8 *)surface->pixels + y*surface->pitch + x*bpp; + switch(bpp) { + case 1: + *p = color; + break; + + case 2: + *(Uint16 *)p = color; + break; + + case 3: + if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { + p[0] = (color>> 16) & 0xff; + p[1] = (color>> 8) & 0xff; + p[2] = color& 0xff; + } else { + p[0] = color& 0xff; + p[1] = (color>> 8) & 0xff; + p[2] = (color>> 16) & 0xff; + } + break; + + case 4: + *(Uint32 *)p = color; + break; + } + } +}; + +Uint32 getPixel(SDL_Surface *surface, int x, int y) +{ + assert(surface != NULL); + int bpp = surface->format->BytesPerPixel; + // p is the address of the pixel to retrieve + Uint8 *p = (Uint8 *)surface->pixels + y*surface->pitch + x*bpp; + switch(bpp) { + case 1: + return *p; + case 2: + return *(Uint16 *)p; + case 3: + if(SDL_BYTEORDER == SDL_BIG_ENDIAN) + return p[0] << 16 | p[1] << 8 | p[2]; + else + return p[0] | p[1] << 8 | p[2] << 16; + case 4: + return *(Uint32 *)p; + default: + return 0; // shouldn't happen, but avoids warnings + + } +}; + +//------------------------------------------------------------------------------ +// Drawing operations +//------------------------------------------------------------------------------ + +void drawHLine(SDL_Surface *surface, int x, int y, int x2, Uint32 color, bool lock) +{ + assert(surface != NULL); + + // MUSTLOCK == 0 means no need for locking, LockSurface == 0 means successful lock + if (lock == false || (SDL_MUSTLOCK(surface) == 0) || (SDL_LockSurface(surface) == 0)) + { + if (x > x2) + { + int t = x; + x = x2; + x2 = t; + } + for (int i = x; i <= x2; i++) + putpixel(surface, i, y, color); + if (lock == false || SDL_MUSTLOCK(surface)) + SDL_UnlockSurface(surface); + } +}; + +void drawVLine(SDL_Surface *surface, int x, int y, int y2, Uint32 color, bool lock) +{ + assert(surface != NULL); + + // MUSTLOCK == 0 means no need for locking, LockSurface == 0 means successful lock + if (lock == false || (SDL_MUSTLOCK(surface) == 0) || (SDL_LockSurface(surface) == 0)) + { + if (y > y2) + { + int t = y; + y = y2; + y2 = t; + } + for (int i = y; i <= y2; i++) + putpixel(surface, x, i, color); + if (lock == false || SDL_MUSTLOCK(surface)) + SDL_UnlockSurface(surface); + } +}; + +void drawRect(SDL_Surface *surface, const SDL_Rect &rect, Uint32 color, bool lock) +{ + assert(surface != NULL); + + // MUSTLOCK == 0 means no need for locking, LockSurface == 0 means successful lock + if (lock == false || (SDL_MUSTLOCK(surface) == 0) || (SDL_LockSurface(surface) == 0)) + { + drawHLine(surface, rect.x, rect.y, rect.x + rect.w-1, color, false); + drawHLine(surface, rect.x, rect.y + rect.h-1, rect.x + rect.w-1, color, false); + drawVLine(surface, rect.x, rect.y, rect.y + rect.h, color, false); + drawVLine(surface, rect.x + rect.w-1, rect.y, rect.y + rect.h-1, color, false); + if (lock == false || SDL_MUSTLOCK(surface)) + SDL_UnlockSurface(surface); + } +}; + +//------------------------------------------------------------------------------ +// Surface operations +//------------------------------------------------------------------------------ + +SDL_Surface* copySurface(SDL_Surface* surface) +{ + assert(surface != NULL); + + //return SDL_DisplayFormat(surface); + return SDL_ConvertSurface(surface, surface->format, surface->flags); +}; + +SDL_Surface* resizeSurface(SDL_Surface *surface, Uint16 w, Uint16 h) +{ + assert(surface != NULL); + assert(w != 0); + assert(h != 0); + + SDL_Surface *resized = + SDL_CreateRGBSurface( + SDL_SWSURFACE, + w, // width + h, // height + 8, // bits per pixel + 0,0,0,0); // r,g,b,a masks + + // TODO: throw an exception ? + if (resized == NULL) + { + return NULL; + }; + + // copy palette (otherwise you'll get only black image) + SDL_SetColors(resized, surface->format->palette->colors, 0, 256); + + // copy colorkey (not sure what happens ;-) ) + SDL_SetColorKey(resized, (surface->flags & SDL_SRCCOLORKEY) | (surface->flags & SDL_RLEACCEL), surface->format->colorkey); + + if (SDL_MUSTLOCK(resized)) + SDL_LockSurface(resized); + if (SDL_MUSTLOCK(surface)) + SDL_LockSurface(surface); + + for(int y = 0; y < resized->h; y++) + { + for(int x = 0; x < resized->w; x++) + { + putPixel(resized, x, y, getPixel(surface, surface->w*x/resized->w, surface->h*y/resized->h)); + }; + } + + if (SDL_MUSTLOCK(resized)) + SDL_UnlockSurface(resized); + if (SDL_MUSTLOCK(surface)) + SDL_UnlockSurface(surface); + return resized; +}; + + +SDL_Surface* resizeSurface(SDL_Surface *surface, double ratio) +{ + assert(surface != NULL); + return resizeSurface(surface, (Uint16)(surface->w*ratio), (Uint16)(surface->h*ratio)); +}; + +//------------------------------------------------------------------------------ +// Color mapping +//------------------------------------------------------------------------------ + +void remapSurface(SDL_Surface *surface, int colorSrc, int colorDst, int colorNum) +{ + assert(surface != NULL); + assert(surface->format->BitsPerPixel == 8); + + // MUSTLOCK == 0 means no need for locking, LockSurface == 0 means successful lock + if ((SDL_MUSTLOCK(surface) == 0) || (SDL_LockSurface(surface) == 0)) + { + Uint8 *pixel; + int x, y; + for (y = 0; y < surface->h; y++) + for (x = 0; x < surface->w; x++) + { + pixel = &(((Uint8*)surface->pixels)[y*surface->pitch + x]); + if ((*pixel >= colorSrc) && (*pixel < colorSrc + colorNum)) + + *pixel = *pixel - colorSrc + colorDst; + } + if (SDL_MUSTLOCK(surface)) + SDL_UnlockSurface(surface); + } +}; + +void remapSurfaceByHouse(SDL_Surface *surface, int house) +{ + remapSurface(surface, COLOUR_HARKONNEN, houseColour[house]); +}; Modified: branches/dunks/src/SConscript =================================================================== --- branches/dunks/src/SConscript 2006-08-01 16:00:41 UTC (rev 69) +++ branches/dunks/src/SConscript 2006-08-01 18:18:33 UTC (rev 70) @@ -24,6 +24,8 @@ "MainMenu.cpp", "IntroState.cpp", "SingleMenu.cpp", + "Gfx.cpp", + "houses.cpp", # just for colors, hope there will be a better place for these (otpetrik) "ResMan.cpp", ] Modified: branches/dunks/src/gui/Graphics.cpp =================================================================== --- branches/dunks/src/gui/Graphics.cpp 2006-08-01 16:00:41 UTC (rev 69) +++ branches/dunks/src/gui/Graphics.cpp 2006-08-01 18:18:33 UTC (rev 70) @@ -38,157 +38,7 @@ } */ -void putpixel(SDL_Surface *surface, int x, int y, Uint32 colour) -{ - if (x >= 0 && x < screen->w && y >=0 && y < screen->h) - { - int bpp = surface->format->BytesPerPixel; - /* Here p is the address to the pixel want to set */ - Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; - switch(bpp) { - case 1: - *p = colour; - break; - - case 2: - *(Uint16 *)p = colour; - break; - - case 3: - if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { - p[0] = (colour>> 16) & 0xff; - p[1] = (colour>> 8) & 0xff; - p[2] = colour& 0xff; - } else { - p[0] = colour& 0xff; - p[1] = (colour>> 8) & 0xff; - p[2] = (colour>> 16) & 0xff; - } - break; - - case 4: - *(Uint32 *)p = colour; - break; - } - } -} - -void hlineNoLock(SDL_Surface *surface, int x1, int y, int x2, Uint32 colour) -{ - int min = x1, - max = x2; - - if (min > max) - { - int temp = max; - max = min; - min = temp; - } - - for (int i = min; i <= max; i++) - putpixel(surface, i, y, colour); -} -void drawhline(SDL_Surface *surface, int x1, int y, int x2, Uint32 colour) -{ - if (!SDL_MUSTLOCK(surface) || (SDL_LockSurface(surface) == 0)) - { - hlineNoLock(surface, x1, y, x2, colour); - - if (SDL_MUSTLOCK(surface)) - SDL_UnlockSurface(surface); - } -} - -void drawrect(SDL_Surface *surface, int x1, int y1, int x2, int y2, Uint32 colour) -{ - if (!SDL_MUSTLOCK(surface) || (SDL_LockSurface(surface) == 0)) - { - int min = x1, - max = x2; - if (min > max) - { - int temp = max; - max = min; - min = temp; - } - - for (int i = min; i <= max; i++) - { - putpixel(surface, i, y1, colour); - putpixel(surface, i, y2, colour); - } - - min = y1+1; - max = y2; - if (min > max) - { - int temp = max; - max = min; - min = temp; - } - - for (int j = min; j < max; j++) - { - putpixel(surface, x1, j, colour); - putpixel(surface, x2, j, colour); - } - - if (SDL_MUSTLOCK(surface)) - SDL_UnlockSurface(surface); - } -} - -void mapImageHouseColourBase(SDL_Surface* graphic, int house, int baseCol) - -{ - - if (settings.doubleBuffered && (graphic->format->BitsPerPixel == 8)) - - { - - if (!SDL_MUSTLOCK(graphic) || (SDL_LockSurface(graphic) >= 0)) - - { - - Uint8 *pixel; - - int i, j; - - - - for (i = 0; i < graphic->w; i++) - - for (j = 0; j < graphic->h; j++) - - { - - pixel = &((Uint8*)graphic->pixels)[j * graphic->pitch + i]; - - if ((*pixel >= baseCol) && (*pixel < baseCol + 7)) - - *pixel = *pixel - baseCol + houseColour[house]; - - } - - SDL_UnlockSurface(graphic); - - } - - } - - else - - SDL_SetColors(graphic, &palette->colors[houseColour[house]], baseCol, 7); - -} - -void mapImageHouseColour(SDL_Surface* graphic, int house) -{ - mapImageHouseColourBase(graphic, house, COLOUR_HARKONNEN); -} - - void clearMessage() { @@ -260,37 +110,3 @@ }; } - -SDL_Surface* copySurface(SDL_Surface* inSurface) -{ - //return SDL_DisplayFormat(inSurface); - return SDL_ConvertSurface(inSurface, inSurface->format, inSurface->flags); -} - -SDL_Surface* scaleSurface(SDL_Surface *surf, double ratio) -{ -SDL_Surface *scaled = - SDL_CreateRGBSurface( - SDL_HWSURFACE, - int(surf->w * ratio),/*width*/ - int(surf->h * ratio),/*height*/ - 32, - 0,0,0,0);/*r,g,b,*/ - -SDL_LockSurface(scaled); -SDL_LockSurface(surf); - -int X2 = (int)(surf->w * ratio); -int Y2 = (int)(surf->h * ratio); - -for(int x = 0;x < X2;++x) - for(int y = 0;y < Y2;++y) - putpixel(scaled,x,y, - getpixel(surf, int(x/ratio), int(y/ratio))); - -SDL_UnlockSurface(scaled); -SDL_UnlockSurface(surf); - -return scaled; -}; - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dun...@us...> - 2006-08-01 16:00:55
|
Revision: 69 Author: dunkfordyce Date: 2006-08-01 09:00:41 -0700 (Tue, 01 Aug 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=69&view=rev Log Message: ----------- make toplevel state return when no states are on the stack Modified Paths: -------------- branches/dunks/src/TopLevelState.cpp Modified: branches/dunks/src/TopLevelState.cpp =================================================================== --- branches/dunks/src/TopLevelState.cpp 2006-08-01 11:15:35 UTC (rev 68) +++ branches/dunks/src/TopLevelState.cpp 2006-08-01 16:00:41 UTC (rev 69) @@ -20,7 +20,6 @@ int TopLevelState::Execute(float dt) { - StateMachine::Execute(dt); + return StateMachine::Execute(dt); - return 0; }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <shu...@us...> - 2006-08-01 11:15:54
|
Revision: 68 Author: shutdownrunner Date: 2006-08-01 04:15:35 -0700 (Tue, 01 Aug 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=68&view=rev Log Message: ----------- Added transparent button and SkipIntro() on mouse click Modified Paths: -------------- branches/dunks/include/IntroState.h branches/dunks/include/gui2/Button.h branches/dunks/src/IntroState.cpp branches/dunks/src/gui2/Button.cpp Modified: branches/dunks/include/IntroState.h =================================================================== --- branches/dunks/include/IntroState.h 2006-07-31 19:12:11 UTC (rev 67) +++ branches/dunks/include/IntroState.h 2006-08-01 11:15:35 UTC (rev 68) @@ -2,6 +2,7 @@ #define DUNE_INTROSTATE_H #include "State.h" +#include "gui2/Button.h" #include "pakfile/Wsafile.h" #include "SDL.h" @@ -20,10 +21,11 @@ void JustMadeInactive(); int Execute(float dt); - + void SkipIntro(); void enque(std::string file) { m_wsaNames.push_back(file); } bool next(); void load(std::string file); + virtual const char* GetName() { return "IntroState"; } public: SDL_Surface* m_animSurface; @@ -32,6 +34,7 @@ Wsafile *m_wsa; + TranspButton *m_butIntro; int m_currentFrame; float m_frametime; }; Modified: branches/dunks/include/gui2/Button.h =================================================================== --- branches/dunks/include/gui2/Button.h 2006-07-31 19:12:11 UTC (rev 67) +++ branches/dunks/include/gui2/Button.h 2006-08-01 11:15:35 UTC (rev 68) @@ -50,5 +50,12 @@ virtual void redraw(); }; +class TranspButton : public Button +{ + public: + TranspButton(Uint16 w, Uint16 h); + ~TranspButton(); +}; + #endif // DUNE_GUI2_BUTTON Modified: branches/dunks/src/IntroState.cpp =================================================================== --- branches/dunks/src/IntroState.cpp 2006-07-31 19:12:11 UTC (rev 67) +++ branches/dunks/src/IntroState.cpp 2006-08-01 11:15:35 UTC (rev 68) @@ -1,12 +1,12 @@ #include "IntroState.h" #include "ResMan.h" #include "Application.h" +#include "Settings.h" #include "pakfile/Palette.h" - +#include "boost/bind.hpp" IntroState::IntroState() { enque("INTRO:INTRO1.WSA"); - /* enque("INTRO:INTRO2.WSA"); enque("INTRO:INTRO3.WSA"); enque("INTRO:INTRO4.WSA"); @@ -20,7 +20,6 @@ enque("INTRO:INTRO9.WSA"); enque("INTRO:INTRO10.WSA"); enque("INTRO:INTRO11.WSA"); - */ m_currentFrame = 0; m_frametime = 0.0f; @@ -29,6 +28,11 @@ m_wsa = NULL; next(); + m_butIntro = new TranspButton(Settings::Instance()->GetWidth(), + Settings::Instance()->GetHeight()); + + m_butIntro->onClick.connect( + boost::bind(&IntroState::SkipIntro, this) ); }; IntroState::~IntroState() @@ -36,14 +40,21 @@ if (m_wsa != NULL) delete m_wsa; }; +void IntroState::SkipIntro() +{ + mp_parent->PopState(); +} + void IntroState::JustMadeActive() { - + + Application::Instance()->RootWidget()->addChild(m_butIntro); State::JustMadeActive(); }; void IntroState::JustMadeInactive() { + Application::Instance()->RootWidget()->deleteChild(m_butIntro); State::JustMadeInactive(); }; Modified: branches/dunks/src/gui2/Button.cpp =================================================================== --- branches/dunks/src/gui2/Button.cpp 2006-07-31 19:12:11 UTC (rev 67) +++ branches/dunks/src/gui2/Button.cpp 2006-08-01 11:15:35 UTC (rev 68) @@ -137,8 +137,14 @@ (m_height / 2) - (texth / 2), 2); }; +// ------------------------------------------------------------------ +TranspButton::TranspButton(Uint16 w, Uint16 h) +{ + Button::setSize(w, h); +}; +TranspButton::~TranspButton() +{ - - +}; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dun...@us...> - 2006-07-31 19:12:21
|
Revision: 67 Author: dunkfordyce Date: 2006-07-31 12:12:11 -0700 (Mon, 31 Jul 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=67&view=rev Log Message: ----------- fix for font crash Modified Paths: -------------- branches/dunks/include/Font.h branches/dunks/src/Font.cpp branches/dunks/src/MainMenu.cpp Modified: branches/dunks/include/Font.h =================================================================== --- branches/dunks/include/Font.h 2006-07-31 18:44:20 UTC (rev 66) +++ branches/dunks/include/Font.h 2006-07-31 19:12:11 UTC (rev 67) @@ -46,7 +46,7 @@ ~Font(); void extents(const char* text, Uint16& w, Uint16& h); - void render(const char* text, SDL_Surface* surface, Uint16 x, Uint16 y, Uint8 paloff); + void render(const char* text, SDL_Surface* surface, int x, int y, Uint8 paloff); private: FNTHeader* m_header; Modified: branches/dunks/src/Font.cpp =================================================================== --- branches/dunks/src/Font.cpp 2006-07-31 18:44:20 UTC (rev 66) +++ branches/dunks/src/Font.cpp 2006-07-31 19:12:11 UTC (rev 67) @@ -32,7 +32,7 @@ }; }; -void Font::render(const char* text, SDL_Surface* surface, Uint16 offx, Uint16 offy, Uint8 paloff) +void Font::render(const char* text, SDL_Surface* surface, int offx, int offy, Uint8 paloff) { FNTCharacter* ch; byte* bitmap; Modified: branches/dunks/src/MainMenu.cpp =================================================================== --- branches/dunks/src/MainMenu.cpp 2006-07-31 18:44:20 UTC (rev 66) +++ branches/dunks/src/MainMenu.cpp 2006-07-31 19:12:11 UTC (rev 67) @@ -18,7 +18,7 @@ m_vbox = new VBox(); - const int bw = 100; + const int bw = 200; const int bh = 20; m_butSingle = new BoringButton("Single Player"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dun...@us...> - 2006-07-31 18:44:31
|
Revision: 66 Author: dunkfordyce Date: 2006-07-31 11:44:20 -0700 (Mon, 31 Jul 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=66&view=rev Log Message: ----------- - re-add mouse cursor - fix segault on exit Modified Paths: -------------- branches/dunks/include/Application.h branches/dunks/include/MainMenu.h branches/dunks/src/Application.cpp branches/dunks/src/IntroState.cpp branches/dunks/src/MainMenu.cpp branches/dunks/src/gui2/Button.cpp branches/dunks/src/pakfile/SConscript branches/dunks/src/pakfile/Shpfile.cpp Modified: branches/dunks/include/Application.h =================================================================== --- branches/dunks/include/Application.h 2006-07-31 17:59:21 UTC (rev 65) +++ branches/dunks/include/Application.h 2006-07-31 18:44:20 UTC (rev 66) @@ -71,6 +71,7 @@ Uint16 m_cursorX, m_cursorY; Cursor m_cursorFrame; + SDL_Surface* m_cursor; }; Modified: branches/dunks/include/MainMenu.h =================================================================== --- branches/dunks/include/MainMenu.h 2006-07-31 17:59:21 UTC (rev 65) +++ branches/dunks/include/MainMenu.h 2006-07-31 18:44:20 UTC (rev 66) @@ -25,12 +25,19 @@ private: VBox* m_vbox; - GraphicButton* m_butSingle; - GraphicButton* m_butMulti; - GraphicButton* m_butMapEd; - GraphicButton* m_butOptions; - GraphicButton* m_butAbout; - GraphicButton* m_butQuit; + //GraphicButton* m_butSingle; + //GraphicButton* m_butMulti; + //GraphicButton* m_butMapEd; + //GraphicButton* m_butOptions; + //GraphicButton* m_butAbout; + //GraphicButton* m_butQuit; + + BoringButton* m_butSingle; + BoringButton* m_butMulti; + BoringButton* m_butMapEd; + BoringButton* m_butOptions; + BoringButton* m_butAbout; + BoringButton* m_butQuit; }; Modified: branches/dunks/src/Application.cpp =================================================================== --- branches/dunks/src/Application.cpp 2006-07-31 17:59:21 UTC (rev 65) +++ branches/dunks/src/Application.cpp 2006-07-31 18:44:20 UTC (rev 66) @@ -24,11 +24,11 @@ #include "TopLevelState.h" #include "DataFile.h" -//#include "pakfile/Pakfile.h" +#include "pakfile/Palette.h" +#include "pakfile/Shpfile.h" #include "ResMan.h" -#define SCREEN_BPP 8 #define VERSION "0.94.1" Uint8 gpaloff; @@ -41,14 +41,16 @@ m_cursorX = 0; m_cursorY = 0; + m_cursorFrame = CURSOR_NORMAL; }; Application::~Application() { delete m_rootState; + delete m_rootWidget; FontManager::Destroy(); - destroyDataFile(); + //destroyDataFile(); //MentatClass::Destroy(); //Mix_CloseAudio(); @@ -103,7 +105,6 @@ //mutex_currentWidget = SDL_CreateMutex(); //mutex_playersJoined = SDL_CreateMutex(); - LoadData(); m_rootWidget = new Container(); @@ -124,6 +125,8 @@ InitVideo(); + LoadData(); + //char versionString[100]; //sprintf(versionString, "%s", VERSION); //menuText = TTF_RenderText_Solid(font[16], versionString, palette->colors[COLOUR_BLACK]); @@ -256,6 +259,19 @@ ResMan::Instance()->addRes("XTRE"); printf("done loading resources\n"); + int len; + unsigned char* data = ResMan::Instance()->readFile("INTRO:INTRO.PAL", &len); + + Palettefile pal (data, len); + + SetPalette(pal.getPalette()); + + data = ResMan::Instance()->readFile("DUNE:MOUSE.SHP", &len); + + Shpfile mouse (data, len); + + m_cursor = mouse.getPicture(0, m_screen->format->palette); + //Pakfile intropak ("intro.pak"); //int nfiles = intropak.getNumFiles(); //for (int i=0; i!=nfiles; i++) @@ -344,7 +360,7 @@ m_rootWidget->draw(m_screen); - //BlitCursor(); + BlitCursor(); #if 0 fnt->render("ABCDEFGHIJKLMOPQRSTUVWXYZ", m_screen, 10, 10, gpaloff); @@ -426,14 +442,14 @@ void Application::BlitCursor() { SDL_Rect dest, src; - SDL_Surface* surface = (SDL_Surface*)dataFile[UI_Cursor].dat; + SDL_Surface* surface = m_cursor; // being lazy, rename me dest.x = m_cursorX; dest.y = m_cursorY; - src.w = surface->w / NUM_CURSORS; - src.h = surface->h; - src.x = src.w * m_cursorFrame; - src.y = 0; + //src.w = surface->w / NUM_CURSORS; + //src.h = surface->h; + //src.x = src.w * m_cursorFrame; + //src.y = 0; //reposition image so pointing on right spot @@ -451,7 +467,7 @@ dest.y -= dest.h/2; } - SDL_BlitSurface(surface, &src, m_screen, &dest); + SDL_BlitSurface(surface, NULL, m_screen, &dest); }; Modified: branches/dunks/src/IntroState.cpp =================================================================== --- branches/dunks/src/IntroState.cpp 2006-07-31 17:59:21 UTC (rev 65) +++ branches/dunks/src/IntroState.cpp 2006-07-31 18:44:20 UTC (rev 66) @@ -25,13 +25,7 @@ m_currentFrame = 0; m_frametime = 0.0f; - int len; - unsigned char* data = ResMan::Instance()->readFile("INTRO:INTRO.PAL", &len); - Palettefile pal (data, len); - - Application::Instance()->SetPalette(pal.getPalette()); - m_wsa = NULL; next(); Modified: branches/dunks/src/MainMenu.cpp =================================================================== --- branches/dunks/src/MainMenu.cpp 2006-07-31 17:59:21 UTC (rev 65) +++ branches/dunks/src/MainMenu.cpp 2006-07-31 18:44:20 UTC (rev 66) @@ -16,46 +16,60 @@ //m_menu->setHeight(m_menuBackground->h); //m_menu->setWidth(m_menuBackground->w); - /* m_vbox = new VBox(); + + const int bw = 100; + const int bh = 20; - m_butSingle = new GraphicButton((SDL_Surface*)(dataFile[UI_Single].dat), - (SDL_Surface*)(dataFile[UI_Single_Pressed].dat)); + m_butSingle = new BoringButton("Single Player"); + m_butSingle->setSize(bw, bh); + //m_butSingle = new GraphicButton((SDL_Surface*)(dataFile[UI_Single].dat), + // (SDL_Surface*)(dataFile[UI_Single_Pressed].dat)); m_butSingle->onClick.connect( boost::bind(&MainMenuState::doSingle, this) ); m_vbox->addChild(m_butSingle); - m_butMulti = new GraphicButton((SDL_Surface*)(dataFile[UI_Multi].dat), - (SDL_Surface*)(dataFile[UI_Multi_Pressed].dat)); + m_butMulti = new BoringButton("Multi Player"); + m_butMulti->setSize(bw, bh); + //m_butMulti = new GraphicButton((SDL_Surface*)(dataFile[UI_Multi].dat), + // (SDL_Surface*)(dataFile[UI_Multi_Pressed].dat)); m_butMulti->onClick.connect( boost::bind(&MainMenuState::doSkirmish, this) ); m_vbox->addChild(m_butMulti); - m_butMapEd = new GraphicButton((SDL_Surface*)(dataFile[UI_MapEdit].dat), - (SDL_Surface*)(dataFile[UI_MapEdit_Pressed].dat)); + m_butMapEd = new BoringButton("Map Editor"); + m_butMapEd->setSize(bw, bh); + //m_butMapEd = new GraphicButton((SDL_Surface*)(dataFile[UI_MapEdit].dat), + // (SDL_Surface*)(dataFile[UI_MapEdit_Pressed].dat)); m_butMapEd->onClick.connect( boost::bind(&MainMenuState::doSkirmish, this) ); m_vbox->addChild(m_butMapEd); - m_butOptions = new GraphicButton((SDL_Surface*)(dataFile[UI_OptionsMM].dat), - (SDL_Surface*)(dataFile[UI_OptionsMM_Pressed].dat)); + m_butOptions = new BoringButton("Options"); + m_butOptions->setSize(bw, bh); + //m_butOptions = new GraphicButton((SDL_Surface*)(dataFile[UI_OptionsMM].dat), + // (SDL_Surface*)(dataFile[UI_OptionsMM_Pressed].dat)); m_butOptions->onClick.connect( boost::bind(&MainMenuState::doSkirmish, this) ); m_vbox->addChild(m_butOptions); - m_butAbout = new GraphicButton((SDL_Surface*)(dataFile[UI_About].dat), - (SDL_Surface*)(dataFile[UI_About_Pressed].dat)); + m_butAbout = new BoringButton("About"); + m_butAbout->setSize(bw, bh); + //m_butAbout = new GraphicButton((SDL_Surface*)(dataFile[UI_About].dat), + // (SDL_Surface*)(dataFile[UI_About_Pressed].dat)); m_butAbout->onClick.connect( boost::bind(&MainMenuState::doSkirmish, this) ); m_vbox->addChild(m_butAbout); - m_butQuit = new GraphicButton((SDL_Surface*)(dataFile[UI_Quit].dat), - (SDL_Surface*)(dataFile[UI_Quit_Pressed].dat)); + m_butQuit = new BoringButton("Quit"); + m_butQuit->setSize(bw, bh); + //m_butQuit = new GraphicButton((SDL_Surface*)(dataFile[UI_Quit].dat), + // (SDL_Surface*)(dataFile[UI_Quit_Pressed].dat)); m_butQuit->onClick.connect( boost::bind(&MainMenuState::doQuit, this) ); @@ -68,12 +82,10 @@ m_vbox->reshape(); m_container->addChild(m_vbox); - */ }; MainMenuState::~MainMenuState() { - /* delete m_butSingle; delete m_butMulti; delete m_butMapEd; @@ -82,7 +94,6 @@ delete m_butQuit; delete m_vbox; - */ }; void MainMenuState::doSkirmish() Modified: branches/dunks/src/gui2/Button.cpp =================================================================== --- branches/dunks/src/gui2/Button.cpp 2006-07-31 17:59:21 UTC (rev 65) +++ branches/dunks/src/gui2/Button.cpp 2006-07-31 18:44:20 UTC (rev 66) @@ -122,7 +122,7 @@ SDL_FillRect(m_surfNormal, NULL, 23); SDL_FillRect(m_surfPressed, NULL, 18); - Font* font = FontManager::Instance()->getFont("DUNE:NEW8P.FNT"); + Font* font = FontManager::Instance()->getFont("INTRO:INTRO.FNT"); Uint16 textw, texth; font->extents(m_caption.c_str(), textw, texth); @@ -131,10 +131,10 @@ font->render(m_caption.c_str(), m_surfNormal, (m_width / 2) - (textw / 2), - (m_height / 2) - (texth / 2), 15); + (m_height / 2) - (texth / 2), 2); font->render(m_caption.c_str(), m_surfPressed, (m_width / 2) - (textw / 2), - (m_height / 2) - (texth / 2), 25); + (m_height / 2) - (texth / 2), 2); }; Modified: branches/dunks/src/pakfile/SConscript =================================================================== --- branches/dunks/src/pakfile/SConscript 2006-07-31 17:59:21 UTC (rev 65) +++ branches/dunks/src/pakfile/SConscript 2006-07-31 18:44:20 UTC (rev 66) @@ -1,44 +1,16 @@ Import('env') -from glob import glob - -gui_sources = glob("gui/*.cpp") -structure_sources = glob("structures/*.cpp") -unit_sources = glob("units/*.cpp") -base_sources = glob("*.cpp") - -all_sources = gui_sources + structure_sources + unit_sources + base_sources - -#all_sources.remove('Menu.cpp') - -all_sources = [ "Application.cpp", - "Settings.cpp", - "Font.cpp", - "State.cpp", - "DataFile.cpp", - - "TopLevelState.cpp", - "MenuBase.cpp", - "MainMenu.cpp", - "SingleMenu.cpp", - - "gui2/Widget.cpp", - "gui2/Container.cpp", - "gui2/Button.cpp", - "gui2/VBox.cpp", - - "pakfile/CpsFile.cpp", - "pakfile/Decode.cpp", - "pakfile/IcnFile.cpp", - "pakfile/Pakfile.cpp", - "pakfile/Shpfile.cpp", - "pakfile/Wsafile.cpp", - - "main.cpp", +all_sources = [ + "Cpsfile.cpp", + "Decode.cpp", + "Icnfile.cpp", + "Pakfile.cpp", + "Shpfile.cpp", + "Wsafile.cpp", + "Palette.cpp", ] -#all_sources += [env.Object('SDL_rwops_zzip.c')] -env.Program("../dunelegacy", all_sources) +env.StaticLibrary("pakfile", all_sources) Modified: branches/dunks/src/pakfile/Shpfile.cpp =================================================================== --- branches/dunks/src/pakfile/Shpfile.cpp 2006-07-31 17:59:21 UTC (rev 65) +++ branches/dunks/src/pakfile/Shpfile.cpp 2006-07-31 18:44:20 UTC (rev 66) @@ -124,6 +124,8 @@ } SDL_UnlockSurface(pic); + + SDL_SetColorKey(pic, SDL_SRCCOLORKEY, 0); if(ImageOut != NULL) { free(ImageOut); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otp...@us...> - 2006-07-31 17:59:30
|
Revision: 65 Author: otpetrik Date: 2006-07-31 10:59:21 -0700 (Mon, 31 Jul 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=65&view=rev Log Message: ----------- fixed pakfile/Shpfile palette handling. Modified Paths: -------------- branches/dunks/include/pakfile/Shpfile.h branches/dunks/include/pakfile/Wsafile.h branches/dunks/src/pakfile/Shpfile.cpp Modified: branches/dunks/include/pakfile/Shpfile.h =================================================================== --- branches/dunks/include/pakfile/Shpfile.h 2006-07-31 16:28:25 UTC (rev 64) +++ branches/dunks/include/pakfile/Shpfile.h 2006-07-31 17:59:21 UTC (rev 65) @@ -16,7 +16,7 @@ Shpfile(unsigned char * bufFiledata, int bufsize); ~Shpfile(); - SDL_Surface* getPicture(Uint32 IndexOfFile); + SDL_Surface* getPicture(Uint32 IndexOfFile, SDL_Palette *palette); inline int getNumFiles() {return (int) NumFiles;}; Modified: branches/dunks/include/pakfile/Wsafile.h =================================================================== --- branches/dunks/include/pakfile/Wsafile.h 2006-07-31 16:28:25 UTC (rev 64) +++ branches/dunks/include/pakfile/Wsafile.h 2006-07-31 17:59:21 UTC (rev 65) @@ -12,7 +12,7 @@ Wsafile(unsigned char * bufFiledata, int bufsize); ~Wsafile(); - SDL_Surface * getPicture(Uint32 FrameNumber, SDL_Palette* pal); + SDL_Surface * getPicture(Uint32 FrameNumber, SDL_Palette *palette); inline int getNumFrames() { return (int) NumFrames; }; inline Uint32 getFramesPer1024ms() { return FramesPer1024ms; }; Modified: branches/dunks/src/pakfile/Shpfile.cpp =================================================================== --- branches/dunks/src/pakfile/Shpfile.cpp 2006-07-31 16:28:25 UTC (rev 64) +++ branches/dunks/src/pakfile/Shpfile.cpp 2006-07-31 17:59:21 UTC (rev 65) @@ -21,7 +21,7 @@ } }; -SDL_Surface *Shpfile::getPicture(Uint32 IndexOfFile) +SDL_Surface *Shpfile::getPicture(Uint32 IndexOfFile, SDL_Palette *palette) { SDL_Surface *pic = NULL; unsigned char *DecodeDestination = NULL; @@ -115,7 +115,7 @@ return NULL; } - //SDL_SetColors(pic, palette->colors, 0, palette->ncolors); + SDL_SetColors(pic, palette->colors, 0, palette->ncolors); SDL_LockSurface(pic); //Now we can copy line by line This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dun...@us...> - 2006-07-31 16:28:33
|
Revision: 64 Author: dunkfordyce Date: 2006-07-31 09:28:25 -0700 (Mon, 31 Jul 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=64&view=rev Log Message: ----------- bit more work on buttons Modified Paths: -------------- branches/dunks/src/Application.cpp branches/dunks/src/gui2/Button.cpp branches/dunks/src/pakview.cpp Modified: branches/dunks/src/Application.cpp =================================================================== --- branches/dunks/src/Application.cpp 2006-07-31 13:26:23 UTC (rev 63) +++ branches/dunks/src/Application.cpp 2006-07-31 16:28:25 UTC (rev 64) @@ -350,6 +350,9 @@ fnt->render("ABCDEFGHIJKLMOPQRSTUVWXYZ", m_screen, 10, 10, gpaloff); fnt->render("abcdefghijklmnopqrstuvwxz", m_screen, 10, 30, gpaloff); +#endif + +#if 1 SDL_Rect pdest = {10, 10, 5, 10}; for (Uint32 i=0; i!=256; i++) Modified: branches/dunks/src/gui2/Button.cpp =================================================================== --- branches/dunks/src/gui2/Button.cpp 2006-07-31 13:26:23 UTC (rev 63) +++ branches/dunks/src/gui2/Button.cpp 2006-07-31 16:28:25 UTC (rev 64) @@ -119,10 +119,10 @@ SDL_SetColors(m_surfNormal, pal->colors, 0, pal->ncolors); SDL_SetColors(m_surfPressed, pal->colors, 0, pal->ncolors); - SDL_FillRect(m_surfNormal, NULL, COLOUR_DARKGREY); - SDL_FillRect(m_surfPressed, NULL, COLOUR_LIGHTGREY); + SDL_FillRect(m_surfNormal, NULL, 23); + SDL_FillRect(m_surfPressed, NULL, 18); - Font* font = FontManager::Instance()->getFont("INTRO:INTRO.FNT"); + Font* font = FontManager::Instance()->getFont("DUNE:NEW8P.FNT"); Uint16 textw, texth; font->extents(m_caption.c_str(), textw, texth); @@ -131,13 +131,14 @@ font->render(m_caption.c_str(), m_surfNormal, (m_width / 2) - (textw / 2), - (m_height / 2) - (texth / 2), 0); + (m_height / 2) - (texth / 2), 15); font->render(m_caption.c_str(), m_surfPressed, (m_width / 2) - (textw / 2), - (m_height / 2) - (texth / 2), 0); + (m_height / 2) - (texth / 2), 25); }; + Modified: branches/dunks/src/pakview.cpp =================================================================== --- branches/dunks/src/pakview.cpp 2006-07-31 13:26:23 UTC (rev 63) +++ branches/dunks/src/pakview.cpp 2006-07-31 16:28:25 UTC (rev 64) @@ -1,6 +1,8 @@ #include "Application.h" #include "Settings.h" #include "State.h" +#include "ResMan.h" +#include "pakfile/Palette.h" #include "gui2/Button.h" @@ -18,12 +20,20 @@ public: PakViewState() { - m_button = new BoringButton("test"); + int len; + unsigned char* data = ResMan::Instance()->readFile("INTRO:INTRO.PAL", &len); + + Palettefile pal (data, len); + + Application::Instance()->SetPalette(pal.getPalette()); + + m_button = new BoringButton("Test"); m_button->setSize(100, 50); m_button->setPos(10, 10); m_button->setVisible(true); Application::Instance()->RootWidget()->addChild(m_button); + }; ~PakViewState() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dun...@us...> - 2006-07-31 13:26:37
|
Revision: 63 Author: dunkfordyce Date: 2006-07-31 06:26:23 -0700 (Mon, 31 Jul 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=63&view=rev Log Message: ----------- added simple button that draws itself Modified Paths: -------------- branches/dunks/include/Font.h branches/dunks/include/gui2/Button.h branches/dunks/src/Application.cpp branches/dunks/src/Font.cpp branches/dunks/src/gui2/Button.cpp branches/dunks/src/pakview.cpp Property Changed: ---------------- branches/dunks/ Property changes on: branches/dunks ___________________________________________________________________ Name: svn:ignore + .sconsign Modified: branches/dunks/include/Font.h =================================================================== --- branches/dunks/include/Font.h 2006-07-31 08:12:26 UTC (rev 62) +++ branches/dunks/include/Font.h 2006-07-31 13:26:23 UTC (rev 63) @@ -45,6 +45,7 @@ Font(FNTCharacter* characters, FNTHeader* header); ~Font(); + void extents(const char* text, Uint16& w, Uint16& h); void render(const char* text, SDL_Surface* surface, Uint16 x, Uint16 y, Uint8 paloff); private: Modified: branches/dunks/include/gui2/Button.h =================================================================== --- branches/dunks/include/gui2/Button.h 2006-07-31 08:12:26 UTC (rev 62) +++ branches/dunks/include/gui2/Button.h 2006-07-31 13:26:23 UTC (rev 63) @@ -3,6 +3,7 @@ #include "gui2/Widget.h" #include "boost/signal.hpp" +#include <string> class Button : public Widget { @@ -34,5 +35,20 @@ bool m_pressed; }; + +class BoringButton : public GraphicButton +{ + public: + BoringButton(std::string caption); + ~BoringButton(); + + virtual void setSize(Uint16 w, Uint16 h); + + protected: + std::string m_caption; + + virtual void redraw(); +}; + #endif // DUNE_GUI2_BUTTON Modified: branches/dunks/src/Application.cpp =================================================================== --- branches/dunks/src/Application.cpp 2006-07-31 08:12:26 UTC (rev 62) +++ branches/dunks/src/Application.cpp 2006-07-31 13:26:23 UTC (rev 63) @@ -198,16 +198,7 @@ SDL_Palette* palette = m_screen->format->palette; - printf("1-- %u %u %u\n", palette->colors[12].r, - palette->colors[12].g, - palette->colors[12].b); - palette = m_currentPalette; - - printf("2-- %u %u %u\n", palette->colors[12].r, - palette->colors[12].g, - palette->colors[12].b); - }; void Application::InitVideo() @@ -351,14 +342,14 @@ if (m_rootState->Execute(dt) == -1) m_running = false; - //m_rootWidget->draw(m_screen); + m_rootWidget->draw(m_screen); - fnt->render("ABCDEFGHIJKLMOPQRSTUVWXYZ", m_screen, 10, 10, gpaloff); - fnt->render("abcdefghijklmnopqrstuvwxz", m_screen, 10, 30, gpaloff); - //BlitCursor(); #if 0 + fnt->render("ABCDEFGHIJKLMOPQRSTUVWXYZ", m_screen, 10, 10, gpaloff); + fnt->render("abcdefghijklmnopqrstuvwxz", m_screen, 10, 30, gpaloff); + SDL_Rect pdest = {10, 10, 5, 10}; for (Uint32 i=0; i!=256; i++) @@ -367,9 +358,8 @@ SDL_FillRect(m_screen, &pdest, i); } #endif - - assert( SDL_Flip(m_screen) == 0); + SDL_Flip(m_screen); fps_frames ++; Modified: branches/dunks/src/Font.cpp =================================================================== --- branches/dunks/src/Font.cpp 2006-07-31 08:12:26 UTC (rev 62) +++ branches/dunks/src/Font.cpp 2006-07-31 13:26:23 UTC (rev 63) @@ -18,6 +18,20 @@ delete m_header; }; +void Font::extents(const char* text, Uint16& w, Uint16& h) +{ + FNTCharacter* ch; + + w = 0; + h = m_header->height; + + for (unsigned int c=0; c!=strlen(text); c++) + { + ch = &m_characters[text[c]]; + w += (2 * ch->width) + 1; + }; +}; + void Font::render(const char* text, SDL_Surface* surface, Uint16 offx, Uint16 offy, Uint8 paloff) { FNTCharacter* ch; @@ -29,22 +43,6 @@ ch = &m_characters[text[c]]; bitmap = ch->bitmap; -/* byte ox; - - - for (byte y=0; y!=ch->y_offset; y++) - { - ox = offx; - for (byte x=0; x!=ch->width; x++) - { - pixels[(ox) + ((y + offy) * surface->w)] = 0; - ++ox; - pixels[(ox) + ((y + offy) * surface->w)] = 0; - ++ox; - }; - }; - */ - for (byte y=0; y!=ch->height; y++) { for (byte x=0; x!=ch->width*2; x+=2) @@ -52,28 +50,6 @@ byte lobyte = bitmap[(x/2) + (y*ch->width)] >> 4; byte hibyte = bitmap[(x/2) + (y*ch->width)] & 0x0F; - /* - if (hibyte==0) - { - printf(" "); - } - else - { - printf("%2hd", hibyte); - } - printf("."); - - if (lobyte==0) - { - printf(" "); - } - else - { - printf("%2hd", lobyte); - }; - printf("."); - */ - if (hibyte!=0) { pixels[(offx + x) + ((ch->y_offset + y + offy) * surface->w)] = paloff + Uint8(hibyte); Modified: branches/dunks/src/gui2/Button.cpp =================================================================== --- branches/dunks/src/gui2/Button.cpp 2006-07-31 08:12:26 UTC (rev 62) +++ branches/dunks/src/gui2/Button.cpp 2006-07-31 13:26:23 UTC (rev 63) @@ -1,5 +1,8 @@ #include "gui2/Button.h" #include <stdio.h> +#include "Colours.h" +#include "Font.h" +#include "Application.h" bool Button::handleButtonUp(Uint8 button, Uint16 x, Uint16 y) { @@ -43,13 +46,15 @@ SDL_Rect destrect; destrect.x = offx + m_x; destrect.y = offy + m_y; - + if (m_pressed) { + assert(m_pressed != NULL); SDL_BlitSurface(m_surfPressed, NULL, dest, &destrect); } else { + assert(m_surfNormal != NULL); SDL_BlitSurface(m_surfNormal, NULL, dest, &destrect); }; }; @@ -77,7 +82,62 @@ return Button::handleButtonUp(button, x, y); }; +// ------------------------------------------------------------------ +BoringButton::BoringButton(std::string caption) +{ + m_caption = caption; +}; +BoringButton::~BoringButton() +{ + SDL_FreeSurface(m_surfNormal); + SDL_FreeSurface(m_surfPressed); +}; +void BoringButton::setSize(Uint16 w, Uint16 h) +{ + GraphicButton::setSize(w, h); + redraw(); +}; +void BoringButton::redraw() +{ + if (m_surfNormal != NULL) SDL_FreeSurface(m_surfNormal); + if (m_surfPressed != NULL) SDL_FreeSurface(m_surfPressed); + + m_surfNormal = SDL_CreateRGBSurface(SDL_SWSURFACE, m_width, m_height, 8, + 0, 0, 0, 0); + assert(m_surfNormal != NULL); + + m_surfPressed = SDL_CreateRGBSurface(SDL_SWSURFACE, m_width, m_height, 8, + 0, 0, 0, 0); + assert(m_surfPressed != NULL); + + SDL_Palette* pal = Application::Instance()->Screen()->format->palette; + + SDL_SetColors(m_surfNormal, pal->colors, 0, pal->ncolors); + SDL_SetColors(m_surfPressed, pal->colors, 0, pal->ncolors); + + SDL_FillRect(m_surfNormal, NULL, COLOUR_DARKGREY); + SDL_FillRect(m_surfPressed, NULL, COLOUR_LIGHTGREY); + + Font* font = FontManager::Instance()->getFont("INTRO:INTRO.FNT"); + + Uint16 textw, texth; + font->extents(m_caption.c_str(), textw, texth); + + printf("text wh %u %u\n", textw, texth); + + font->render(m_caption.c_str(), m_surfNormal, + (m_width / 2) - (textw / 2), + (m_height / 2) - (texth / 2), 0); + font->render(m_caption.c_str(), m_surfPressed, + (m_width / 2) - (textw / 2), + (m_height / 2) - (texth / 2), 0); +}; + + + + + Modified: branches/dunks/src/pakview.cpp =================================================================== --- branches/dunks/src/pakview.cpp 2006-07-31 08:12:26 UTC (rev 62) +++ branches/dunks/src/pakview.cpp 2006-07-31 13:26:23 UTC (rev 63) @@ -1,6 +1,9 @@ #include "Application.h" #include "Settings.h" +#include "State.h" +#include "gui2/Button.h" + namespace boost { void throw_exception(std::exception const & e) @@ -10,6 +13,35 @@ } +class PakViewState : public State +{ + public: + PakViewState() + { + m_button = new BoringButton("test"); + m_button->setSize(100, 50); + m_button->setPos(10, 10); + m_button->setVisible(true); + + Application::Instance()->RootWidget()->addChild(m_button); + }; + + ~PakViewState() + { + delete m_button; + }; + + int Execute(float dt) + { + return 0; + }; + + virtual const char* GetName() { return "PakViewState"; } + + private: + BoringButton* m_button; +}; + int main(int argc, char *argv[]) { Settings::Instance()->ParseFile("dunelegacy.cfg"); @@ -18,9 +50,9 @@ Application::Instance()->Init(); //Application::Instance()->PushState( new MainMenuState() ); //Application::Instance()->PushState( new IntroState() ); + + Application::Instance()->RootState()->PushState( new PakViewState() ); - - Application::Instance()->Run(); Application::Destroy(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dun...@us...> - 2006-07-31 08:12:35
|
Revision: 62 Author: dunkfordyce Date: 2006-07-31 01:12:26 -0700 (Mon, 31 Jul 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=62&view=rev Log Message: ----------- delete evil Math.h Modified Paths: -------------- branches/dunks/src/IntroState.cpp branches/dunks/src/Settings.cpp Removed Paths: ------------- branches/dunks/include/Math.h Deleted: branches/dunks/include/Math.h =================================================================== --- branches/dunks/include/Math.h 2006-07-31 08:08:57 UTC (rev 61) +++ branches/dunks/include/Math.h 2006-07-31 08:12:26 UTC (rev 62) @@ -1,13 +0,0 @@ -#ifndef DUNE_MATH_H -#define DUNE_MATH_H - -#define PI 3.1415926535897932384626433832795 -#define DIAGONALSPEEDCONST 0.70710678118654752440084436210485 -#define DIAGONALCOST 1.4142135623730950488016887242097 - -typedef struct -{ - short x, y; -} COORDTYPE; - -#endif //DUNE_MATH_H Modified: branches/dunks/src/IntroState.cpp =================================================================== --- branches/dunks/src/IntroState.cpp 2006-07-31 08:08:57 UTC (rev 61) +++ branches/dunks/src/IntroState.cpp 2006-07-31 08:12:26 UTC (rev 62) @@ -9,6 +9,7 @@ /* enque("INTRO:INTRO2.WSA"); enque("INTRO:INTRO3.WSA"); + enque("INTRO:INTRO4.WSA"); enque("INTRO:INTRO5.WSA"); enque("INTRO:INTRO6.WSA"); enque("INTRO:INTRO7A.WSA"); Modified: branches/dunks/src/Settings.cpp =================================================================== --- branches/dunks/src/Settings.cpp 2006-07-31 08:08:57 UTC (rev 61) +++ branches/dunks/src/Settings.cpp 2006-07-31 08:12:26 UTC (rev 62) @@ -12,7 +12,7 @@ m_debug = false; - m_dataDir = "/home/dunk/downloads/dune/"; + m_dataDir = "paks/"; m_doubleBuffered = false; }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dun...@us...> - 2006-07-31 08:09:08
|
Revision: 61 Author: dunkfordyce Date: 2006-07-31 01:08:57 -0700 (Mon, 31 Jul 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=61&view=rev Log Message: ----------- compile parts to static libs to easily allow tools to be created Modified Paths: -------------- branches/dunks/SConstruct branches/dunks/src/Application.cpp branches/dunks/src/SConscript branches/dunks/src/main.cpp branches/dunks/src/pakfile/main.cpp Added Paths: ----------- branches/dunks/src/pakview.cpp Modified: branches/dunks/SConstruct =================================================================== --- branches/dunks/SConstruct 2006-07-30 22:50:22 UTC (rev 60) +++ branches/dunks/SConstruct 2006-07-31 08:08:57 UTC (rev 61) @@ -59,4 +59,5 @@ Export('env') +#SConscript("src/pakfile/SConscript") SConscript("src/SConscript") Modified: branches/dunks/src/Application.cpp =================================================================== --- branches/dunks/src/Application.cpp 2006-07-30 22:50:22 UTC (rev 60) +++ branches/dunks/src/Application.cpp 2006-07-31 08:08:57 UTC (rev 61) @@ -22,8 +22,6 @@ #include "Settings.h" #include "Font.h" #include "TopLevelState.h" -#include "MainMenu.h" -#include "IntroState.h" #include "DataFile.h" //#include "pakfile/Pakfile.h" @@ -126,8 +124,8 @@ InitVideo(); - char versionString[100]; - sprintf(versionString, "%s", VERSION); + //char versionString[100]; + //sprintf(versionString, "%s", VERSION); //menuText = TTF_RenderText_Solid(font[16], versionString, palette->colors[COLOUR_BLACK]); //init_loadWindow(); @@ -135,9 +133,9 @@ //realign_buttons(); m_rootState = new TopLevelState(); - m_rootState->PushState( new MainMenuState() ); - m_rootState->PushState( new IntroState() ); //m_rootState->PushState( new MainMenuState() ); + //m_rootState->PushState( new IntroState() ); + //m_rootState->PushState( new MainMenuState() ); } void Application::InitSettings() Modified: branches/dunks/src/SConscript =================================================================== --- branches/dunks/src/SConscript 2006-07-30 22:50:22 UTC (rev 60) +++ branches/dunks/src/SConscript 2006-07-31 08:08:57 UTC (rev 61) @@ -1,5 +1,7 @@ Import('env') +SConscript("pakfile/SConscript") + from glob import glob gui_sources = glob("gui/*.cpp") @@ -24,27 +26,33 @@ "SingleMenu.cpp", "ResMan.cpp", + ] +gui_sources = [ "gui2/Widget.cpp", "gui2/Container.cpp", "gui2/Button.cpp", "gui2/VBox.cpp", - "pakfile/Cpsfile.cpp", + ] + +pak_sources = [ "pakfile/Cpsfile.cpp", "pakfile/Decode.cpp", "pakfile/Icnfile.cpp", "pakfile/Pakfile.cpp", "pakfile/Shpfile.cpp", "pakfile/Wsafile.cpp", "pakfile/Palette.cpp", - - "main.cpp", ] -#all_sources = ["ResMan.cpp"] +gamelib = env.StaticLibrary("dune_game", all_sources) +guilib = env.StaticLibrary("dune_gui", gui_sources) +paklib = env.StaticLibrary("dune_pak", pak_sources) -#all_sources += [env.Object('SDL_rwops_zzip.c')] +dunelegacy = env.Program("../dunelegacy", ["main.cpp", gamelib, guilib, paklib] ) +pakview = env.Program("../pakview", ["pakview.cpp", gamelib, guilib, paklib] ) -env.Program("../dunelegacy", all_sources) +Default(dunelegacy) +Default(pakview) Modified: branches/dunks/src/main.cpp =================================================================== --- branches/dunks/src/main.cpp 2006-07-30 22:50:22 UTC (rev 60) +++ branches/dunks/src/main.cpp 2006-07-31 08:08:57 UTC (rev 61) @@ -1,5 +1,7 @@ #include "Application.h" #include "Settings.h" +#include "MainMenu.h" +#include "IntroState.h" namespace boost { @@ -16,6 +18,8 @@ Settings::Instance()->ParseOptions(argc, argv); Application::Instance()->Init(); + Application::Instance()->RootState()->PushState( new MainMenuState() ); + Application::Instance()->RootState()->PushState( new IntroState() ); Application::Instance()->Run(); Application::Destroy(); Modified: branches/dunks/src/pakfile/main.cpp =================================================================== --- branches/dunks/src/pakfile/main.cpp 2006-07-30 22:50:22 UTC (rev 60) +++ branches/dunks/src/pakfile/main.cpp 2006-07-31 08:08:57 UTC (rev 61) @@ -1,6 +1,3 @@ -/* Created by Anjuta version 1.2.4 */ -/* This file will not be overwritten */ - #include <iostream> #include <string.h> #include <SDL.h> Added: branches/dunks/src/pakview.cpp =================================================================== --- branches/dunks/src/pakview.cpp (rev 0) +++ branches/dunks/src/pakview.cpp 2006-07-31 08:08:57 UTC (rev 61) @@ -0,0 +1,30 @@ +#include "Application.h" +#include "Settings.h" + +namespace boost { + + void throw_exception(std::exception const & e) + { + + }; + +} + +int main(int argc, char *argv[]) +{ + Settings::Instance()->ParseFile("dunelegacy.cfg"); + Settings::Instance()->ParseOptions(argc, argv); + + Application::Instance()->Init(); + //Application::Instance()->PushState( new MainMenuState() ); + //Application::Instance()->PushState( new IntroState() ); + + + + Application::Instance()->Run(); + + Application::Destroy(); + Settings::Destroy(); + + return 0; +}; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |