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-07-30 22:50:32
|
Revision: 60 Author: dvalin Date: 2006-07-30 15:50:22 -0700 (Sun, 30 Jul 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=60&view=rev Log Message: ----------- Fix price of light infantry Modified Paths: -------------- trunk/src/BuildItemClass.cpp Modified: trunk/src/BuildItemClass.cpp =================================================================== --- trunk/src/BuildItemClass.cpp 2006-07-28 21:35:24 UTC (rev 59) +++ trunk/src/BuildItemClass.cpp 2006-07-30 22:50:22 UTC (rev 60) @@ -234,7 +234,7 @@ break; case (Unit_Infantry): bListPriority = 10; - cost = 100; + cost = 60; picID = Picture_Infantry; sprintf(name, "Light Infantry"); sprintf(description, "Light Infantry: %.2f", round(cost)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dun...@us...> - 2006-07-28 21:35:35
|
Revision: 59 Author: dunkfordyce Date: 2006-07-28 14:35:24 -0700 (Fri, 28 Jul 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=59&view=rev Log Message: ----------- - fixed font manager to work with ResMan - add FileLike class to ResMan.h to simulate a file with the returned buf ( used for fonts ) Modified Paths: -------------- branches/dunks/include/ResMan.h branches/dunks/src/Application.cpp branches/dunks/src/Font.cpp branches/dunks/src/ResMan.cpp Modified: branches/dunks/include/ResMan.h =================================================================== --- branches/dunks/include/ResMan.h 2006-07-28 19:36:51 UTC (rev 58) +++ branches/dunks/include/ResMan.h 2006-07-28 21:35:24 UTC (rev 59) @@ -9,6 +9,21 @@ #include <map> #include <string> +class FileLike +{ + public: + FileLike(unsigned char* buf, int size); + ~FileLike(); + + void read(void* buf, int size); + void seek(int offset); + + private: + unsigned char* m_buf; + int m_size; + int m_pos; +}; + class Resource { public: @@ -54,6 +69,7 @@ bool addRes(std::string name); unsigned char* readFile(std::string name, int *size); + FileLike* readFile(std::string name); private: ResList m_resources; Modified: branches/dunks/src/Application.cpp =================================================================== --- branches/dunks/src/Application.cpp 2006-07-28 19:36:51 UTC (rev 58) +++ branches/dunks/src/Application.cpp 2006-07-28 21:35:24 UTC (rev 59) @@ -324,7 +324,7 @@ const int fps_interval = 10 * 1000; // 10 seconds float fps; - //Font* fnt = FontManager::Instance()->getFont("new8p.fnt"); + Font* fnt = FontManager::Instance()->getFont("INTRO:INTRO.FNT"); m_running = true; @@ -355,8 +355,8 @@ //m_rootWidget->draw(m_screen); - //fnt->render("ABCDEFGHIJKLMOPQRSTUVWXYZ", m_screen, 10, 10, gpaloff); - //fnt->render("abcdefghijklmnopqrstuvwxz", m_screen, 10, 30, gpaloff); + fnt->render("ABCDEFGHIJKLMOPQRSTUVWXYZ", m_screen, 10, 10, gpaloff); + fnt->render("abcdefghijklmnopqrstuvwxz", m_screen, 10, 30, gpaloff); //BlitCursor(); Modified: branches/dunks/src/Font.cpp =================================================================== --- branches/dunks/src/Font.cpp 2006-07-28 19:36:51 UTC (rev 58) +++ branches/dunks/src/Font.cpp 2006-07-28 21:35:24 UTC (rev 59) @@ -1,5 +1,6 @@ #include "Font.h" #include "Application.h" +#include "ResMan.h" #include <assert.h> #include <stdlib.h> @@ -115,16 +116,15 @@ Font* FontManager::loadFont(const char* fn) { printf("loadFont %s\n", fn); - FILE* file = fopen(fn, "rb"); + //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(); - printf("fsize %d\n", header->fsize); + file->read(header, sizeof(FNTHeader)); - fread(header, sizeof(FNTHeader), 1, file); - printf("fsize %d\n", header->fsize); // this checks if its a valid font @@ -136,23 +136,22 @@ word* dchar = new word[header->nchars+1]; - fread(dchar, sizeof(word), header->nchars+1, file); + file->read(dchar, sizeof(word) * (header->nchars+1)); byte* wchar = new byte[header->nchars+1]; printf("wpos %d\n", header->wpos); - fseek(file, header->wpos, SEEK_SET); - long br = fread(wchar, sizeof(byte), header->nchars+1, file); - printf("br %ld %d\n", br, 1); + file->seek(header->wpos); + file->read(wchar, sizeof(byte) * (header->nchars+1)); if (wchar[0] != 8) printf("bad!!\n"); word* hchar = new word[header->nchars+1]; - fseek(file, header->hpos, SEEK_SET); - fread(hchar, sizeof(word), header->nchars+1, file); + file->seek(header->hpos); + file->read(hchar, sizeof(word) * (header->nchars+1)); - fseek(file, header->cdata, SEEK_SET); + file->seek(header->cdata); FNTCharacter* characters = new FNTCharacter[header->nchars+1]; @@ -169,12 +168,14 @@ printf("size %hd\n", width * height); printf("dchar %hd\n", dchar[i]); - fseek(file, dchar[i], SEEK_SET); + file->seek(dchar[i]); byte* bitmap = new byte[width * height]; - fread(bitmap, sizeof(byte), width * height, file); + file->read(bitmap, sizeof(byte) * (width * height)); characters[i].bitmap = bitmap; }; + delete file; + Font* font = new Font(characters, header); return font; Modified: branches/dunks/src/ResMan.cpp =================================================================== --- branches/dunks/src/ResMan.cpp 2006-07-28 19:36:51 UTC (rev 58) +++ branches/dunks/src/ResMan.cpp 2006-07-28 21:35:24 UTC (rev 59) @@ -10,6 +10,31 @@ namespace bfs = boost::filesystem; +FileLike::FileLike(unsigned char* buf, int size) +{ + m_buf = buf; + m_size = size; + m_pos = 0; +}; + +FileLike::~FileLike() +{ + delete m_buf; +}; + +void FileLike::read(void* buf, int size) +{ + memcpy(buf, &m_buf[m_pos], size); + m_pos += size; +}; + +void FileLike::seek(int offset) +{ + m_pos = offset; +}; + +// ------------------------------------------------------------------ + Resource::~Resource() { @@ -152,3 +177,10 @@ return buf; }; + +FileLike* ResMan::readFile(std::string name) +{ + int size; + unsigned char* buf = readFile(name, &size); + return new FileLike(buf, size); +}; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dun...@us...> - 2006-07-28 20:34:36
|
Revision: 57 Author: dunkfordyce Date: 2006-07-28 06:28:05 -0700 (Fri, 28 Jul 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=57&view=rev Log Message: ----------- intro plays all the way through. seems to be some issue where some files need to be joined together Modified Paths: -------------- branches/dunks/include/IntroState.h branches/dunks/src/Application.cpp branches/dunks/src/IntroState.cpp branches/dunks/src/pakfile/Wsafile.cpp Modified: branches/dunks/include/IntroState.h =================================================================== --- branches/dunks/include/IntroState.h 2006-07-28 06:59:39 UTC (rev 56) +++ branches/dunks/include/IntroState.h 2006-07-28 13:28:05 UTC (rev 57) @@ -22,6 +22,8 @@ int Execute(float dt); void enque(std::string file) { m_wsaNames.push_back(file); } + void next(); + void load(std::string file); public: SDL_Surface* m_animSurface; Modified: branches/dunks/src/Application.cpp =================================================================== --- branches/dunks/src/Application.cpp 2006-07-28 06:59:39 UTC (rev 56) +++ branches/dunks/src/Application.cpp 2006-07-28 13:28:05 UTC (rev 57) @@ -194,7 +194,7 @@ { assert(pal != NULL); printf("setting palette %d colors\n", pal->ncolors); - SDL_SetColors(m_screen, pal->colors, 0, pal->ncolors); + assert( SDL_SetColors(m_screen, pal->colors, 0, pal->ncolors) == 1 ); m_currentPalette = pal; SDL_Palette* palette = m_screen->format->palette; @@ -215,7 +215,7 @@ { Settings* set = Settings::Instance(); - int videoFlags = 0; + int videoFlags = SDL_HWPALETTE; if (set->m_doubleBuffered) videoFlags |= SDL_HWSURFACE | SDL_DOUBLEBUF; if (set->m_fullscreen) @@ -333,7 +333,7 @@ while (m_running) { - SDL_FillRect(m_screen, NULL, COLOUR_BLACK); + SDL_FillRect(m_screen, NULL, 0); HandleEvents(); @@ -359,8 +359,16 @@ //BlitCursor(); + SDL_Rect pdest = {10, 10, 5, 10}; + + for (Uint32 i=0; i!=256; i++) + { + pdest.x = 7 * i; + SDL_FillRect(m_screen, &pdest, i); + } + - SDL_Flip(m_screen); + assert( SDL_Flip(m_screen) == 0); fps_frames ++; @@ -370,8 +378,6 @@ printf("fps: %f\n", fps); - SDL_Delay(100); - fps_frames = 0; fps_start = now; }; @@ -407,11 +413,11 @@ 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); + if (event.button.button == 1) + gpaloff ++; + else + gpaloff --; + printf("gpla %u\n", gpaloff); break; case SDL_KEYDOWN: m_rootWidget->handleKeyDown(&(event.key.keysym)); @@ -474,7 +480,7 @@ dest.y = (Settings::Instance()->m_height / 2) - (src->h / 2); }; - printf("blitting %d %d %d %d\n", dest.x, dest.y, surface->w, surface->h); + //printf("blitting %d %d %d %d\n", dest.x, dest.y, surface->w, surface->h); Blit(surface, src, &dest); }; Modified: branches/dunks/src/IntroState.cpp =================================================================== --- branches/dunks/src/IntroState.cpp 2006-07-28 06:59:39 UTC (rev 56) +++ branches/dunks/src/IntroState.cpp 2006-07-28 13:28:05 UTC (rev 57) @@ -5,33 +5,39 @@ IntroState::IntroState() { - int len; - enque("INTRO:INTRO1.WSA"); enque("INTRO:INTRO2.WSA"); enque("INTRO:INTRO3.WSA"); - - unsigned char* data = ResMan::Instance()->readFile(std::string("INTRO:INTRO1.WSA"), &len); + 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("INTRO:INTRO12.WSA"); - assert(data != NULL); - - printf("intro1 len %d\n", len); - - m_wsa = new Wsafile(data, len); - m_currentFrame = 0; m_frametime = 0.0f; - data = ResMan::Instance()->readFile("INTRO:INTRO.PAL", &len); + 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(); }; IntroState::~IntroState() { - delete m_wsa; + if (m_wsa != NULL) delete m_wsa; }; void IntroState::JustMadeActive() @@ -45,6 +51,29 @@ State::JustMadeInactive(); }; +void IntroState::load(std::string name) +{ + printf("intro loading %s\n", name.c_str()); + if (m_wsa != NULL) delete m_wsa; + + int len; + unsigned char* data = ResMan::Instance()->readFile(name, &len); + + assert(data != NULL); + + m_wsa = new Wsafile(data, len); +}; + +void IntroState::next() +{ + printf("loading next..\n"); + IntroList::iterator it = m_wsaNames.begin(); + assert( it != m_wsaNames.end() ); + load(*it); + m_wsaNames.pop_front(); + m_currentFrame = 0 ; +}; + int IntroState::Execute(float dt) { m_frametime += dt; @@ -55,7 +84,7 @@ m_currentFrame ++; if (m_currentFrame >= m_wsa->getNumFrames()) { - return -1; + next(); }; }; Modified: branches/dunks/src/pakfile/Wsafile.cpp =================================================================== --- branches/dunks/src/pakfile/Wsafile.cpp 2006-07-28 06:59:39 UTC (rev 56) +++ branches/dunks/src/pakfile/Wsafile.cpp 2006-07-28 13:28:05 UTC (rev 57) @@ -68,16 +68,18 @@ return NULL; } - printf("Frame Nr.: %d (Size: %dx%d)\n",FrameNumber,SizeX,SizeY); + //printf("Frame Nr.: %d (Size: %dx%d)\n",FrameNumber,SizeX,SizeY); + /* printf("%u %u %u\n", palette->colors[12].r, palette->colors[12].g, palette->colors[12].b); + */ SDL_SetColors(pic, palette->colors, 0, palette->ncolors); SDL_LockSurface(pic); - printf("%u\n", Image[0]); + //printf("%u\n", Image[0]); //Now we can copy line by line for(int y = 0; y < SizeY;y++) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dun...@us...> - 2006-07-28 19:37:09
|
Revision: 58 Author: dunkfordyce Date: 2006-07-28 12:36:51 -0700 (Fri, 28 Jul 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=58&view=rev Log Message: ----------- fix segfault going from intro to main menu Modified Paths: -------------- branches/dunks/include/IntroState.h branches/dunks/src/Application.cpp branches/dunks/src/IntroState.cpp branches/dunks/src/MainMenu.cpp branches/dunks/src/MenuBase.cpp Modified: branches/dunks/include/IntroState.h =================================================================== --- branches/dunks/include/IntroState.h 2006-07-28 13:28:05 UTC (rev 57) +++ branches/dunks/include/IntroState.h 2006-07-28 19:36:51 UTC (rev 58) @@ -22,7 +22,7 @@ int Execute(float dt); void enque(std::string file) { m_wsaNames.push_back(file); } - void next(); + bool next(); void load(std::string file); public: Modified: branches/dunks/src/Application.cpp =================================================================== --- branches/dunks/src/Application.cpp 2006-07-28 13:28:05 UTC (rev 57) +++ branches/dunks/src/Application.cpp 2006-07-28 19:36:51 UTC (rev 58) @@ -135,6 +135,7 @@ //realign_buttons(); m_rootState = new TopLevelState(); + m_rootState->PushState( new MainMenuState() ); m_rootState->PushState( new IntroState() ); //m_rootState->PushState( new MainMenuState() ); } @@ -359,6 +360,7 @@ //BlitCursor(); +#if 0 SDL_Rect pdest = {10, 10, 5, 10}; for (Uint32 i=0; i!=256; i++) @@ -366,6 +368,7 @@ pdest.x = 7 * i; SDL_FillRect(m_screen, &pdest, i); } +#endif assert( SDL_Flip(m_screen) == 0); Modified: branches/dunks/src/IntroState.cpp =================================================================== --- branches/dunks/src/IntroState.cpp 2006-07-28 13:28:05 UTC (rev 57) +++ branches/dunks/src/IntroState.cpp 2006-07-28 19:36:51 UTC (rev 58) @@ -6,6 +6,7 @@ IntroState::IntroState() { enque("INTRO:INTRO1.WSA"); + /* enque("INTRO:INTRO2.WSA"); enque("INTRO:INTRO3.WSA"); enque("INTRO:INTRO5.WSA"); @@ -18,7 +19,7 @@ enque("INTRO:INTRO9.WSA"); enque("INTRO:INTRO10.WSA"); enque("INTRO:INTRO11.WSA"); - enque("INTRO:INTRO12.WSA"); + */ m_currentFrame = 0; m_frametime = 0.0f; @@ -64,14 +65,20 @@ m_wsa = new Wsafile(data, len); }; -void IntroState::next() +bool IntroState::next() { printf("loading next..\n"); IntroList::iterator it = m_wsaNames.begin(); - assert( it != m_wsaNames.end() ); + if (it == m_wsaNames.end() ) + { + return false; + } + load(*it); m_wsaNames.pop_front(); m_currentFrame = 0 ; + + return true; }; int IntroState::Execute(float dt) @@ -84,7 +91,7 @@ m_currentFrame ++; if (m_currentFrame >= m_wsa->getNumFrames()) { - next(); + if (!next()) return -1; }; }; Modified: branches/dunks/src/MainMenu.cpp =================================================================== --- branches/dunks/src/MainMenu.cpp 2006-07-28 13:28:05 UTC (rev 57) +++ branches/dunks/src/MainMenu.cpp 2006-07-28 19:36:51 UTC (rev 58) @@ -11,11 +11,12 @@ MainMenuState::MainMenuState() { - 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); + /* m_vbox = new VBox(); m_butSingle = new GraphicButton((SDL_Surface*)(dataFile[UI_Single].dat), @@ -67,10 +68,12 @@ m_vbox->reshape(); m_container->addChild(m_vbox); + */ }; MainMenuState::~MainMenuState() { + /* delete m_butSingle; delete m_butMulti; delete m_butMapEd; @@ -79,6 +82,7 @@ delete m_butQuit; delete m_vbox; + */ }; void MainMenuState::doSkirmish() Modified: branches/dunks/src/MenuBase.cpp =================================================================== --- branches/dunks/src/MenuBase.cpp 2006-07-28 13:28:05 UTC (rev 57) +++ branches/dunks/src/MenuBase.cpp 2006-07-28 19:36:51 UTC (rev 58) @@ -13,7 +13,7 @@ MenuBaseState::MenuBaseState() { - 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); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dun...@us...> - 2006-07-28 19:17:14
|
Revision: 53 Author: dunkfordyce Date: 2006-07-26 12:08:09 -0700 (Wed, 26 Jul 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=53&view=rev Log Message: ----------- almost working intro Modified Paths: -------------- branches/dunks/SConstruct branches/dunks/include/ResMan.h branches/dunks/include/pakfile/Wsafile.h branches/dunks/src/Application.cpp branches/dunks/src/IntroState.cpp branches/dunks/src/ResMan.cpp branches/dunks/src/Settings.cpp branches/dunks/src/pakfile/Pakfile.cpp branches/dunks/src/pakfile/Wsafile.cpp Modified: branches/dunks/SConstruct =================================================================== --- branches/dunks/SConstruct 2006-07-26 16:36:44 UTC (rev 52) +++ branches/dunks/SConstruct 2006-07-26 19:08:09 UTC (rev 53) @@ -26,7 +26,7 @@ env.ParseConfig('sdl-config --cflags --libs') env.ParseConfig('pkg-config --cflags --libs zziplib') env.Append(CCFLAGS=["-Wall"]) #, "-Werror"]) - env.Append(CCFLAGS=["-Wall", "-Werror", "-O2", "-ffast-math", "-funroll-loops"]) + #env.Append(CCFLAGS=["-Wall", "-Werror", "-O2", "-ffast-math", "-funroll-loops"]) #env.Append(LINKFLAGS = ["-ffast-math"]) if 1: Modified: branches/dunks/include/ResMan.h =================================================================== --- branches/dunks/include/ResMan.h 2006-07-26 16:36:44 UTC (rev 52) +++ branches/dunks/include/ResMan.h 2006-07-26 19:08:09 UTC (rev 53) @@ -14,8 +14,7 @@ public: Resource() {}; virtual ~Resource(); - virtual int readFile(boost::filesystem::path path, unsigned char* buf) { return 0; } - + virtual unsigned char* readFile(boost::filesystem::path path, int *size) { return NULL; } protected: boost::filesystem::path m_path; }; @@ -25,8 +24,7 @@ { public: DIRResource(boost::filesystem::path path) ; - virtual int readFile(boost::filesystem::path path, unsigned char* buf) ; - + unsigned char* readFile(boost::filesystem::path path, int *size); }; @@ -35,7 +33,7 @@ public: PAKResource(boost::filesystem::path path) ; ~PAKResource(); - virtual int readFile(boost::filesystem::path path, unsigned char* buf) ; + unsigned char* readFile(boost::filesystem::path path, int *size); private: Pakfile *m_pakfile; @@ -55,7 +53,7 @@ public: bool addRes(std::string name); - int readFile(std::string path, unsigned char* buf); + unsigned char* readFile(std::string name, int *size); private: ResList m_resources; Modified: branches/dunks/include/pakfile/Wsafile.h =================================================================== --- branches/dunks/include/pakfile/Wsafile.h 2006-07-26 16:36:44 UTC (rev 52) +++ branches/dunks/include/pakfile/Wsafile.h 2006-07-26 19:08:09 UTC (rev 53) @@ -12,7 +12,7 @@ Wsafile(unsigned char * bufFiledata, int bufsize); ~Wsafile(); - SDL_Surface * getPicture(Uint32 FrameNumber); + SDL_Surface * getPicture(Uint32 FrameNumber, SDL_Palette* pal); inline int getNumFrames() { return (int) NumFrames; }; inline Uint32 getFramesPer1024ms() { return FramesPer1024ms; }; Modified: branches/dunks/src/Application.cpp =================================================================== --- branches/dunks/src/Application.cpp 2006-07-26 16:36:44 UTC (rev 52) +++ branches/dunks/src/Application.cpp 2006-07-26 19:08:09 UTC (rev 53) @@ -192,6 +192,8 @@ void Application::SetPalette(SDL_Palette* pal) { + assert(pal != NULL); + printf("setting palette %d colors\n", pal->ncolors); SDL_SetColors(m_screen, pal->colors, 0, pal->ncolors); }; @@ -307,7 +309,7 @@ const int fps_interval = 10 * 1000; // 10 seconds float fps; - Font* fnt = FontManager::Instance()->getFont("new8p.fnt"); + //Font* fnt = FontManager::Instance()->getFont("new8p.fnt"); m_running = true; @@ -334,14 +336,14 @@ float dt = float(now - then) / 1000.0f; - //if (m_rootState->Execute(dt) == -1) m_running = false; + if (m_rootState->Execute(dt) == -1) m_running = false; //m_rootWidget->draw(m_screen); - fnt->render("ABCDEFGHIJKLMOPQRSTUVWXYZ", m_screen, 10, 10, gpaloff); - fnt->render("abcdefghijklmnopqrstuvwxz", m_screen, 10, 30, gpaloff); + //fnt->render("ABCDEFGHIJKLMOPQRSTUVWXYZ", m_screen, 10, 10, gpaloff); + //fnt->render("abcdefghijklmnopqrstuvwxz", m_screen, 10, 30, gpaloff); - BlitCursor(); + //BlitCursor(); SDL_Flip(m_screen); @@ -440,7 +442,7 @@ void Application::Blit(SDL_Surface* surface, SDL_Rect* src, SDL_Rect* dest) { - SDL_BlitSurface(surface, src, m_screen, dest); + assert( SDL_BlitSurface(surface, src, m_screen, dest) == 0 ); }; void Application::BlitCentered(SDL_Surface* surface, SDL_Rect* src) @@ -457,6 +459,7 @@ dest.y = (Settings::Instance()->m_height / 2) - (src->h / 2); }; + printf("blitting %d %d %d %d\n", dest.x, dest.y, surface->w, surface->h); Blit(surface, src, &dest); }; Modified: branches/dunks/src/IntroState.cpp =================================================================== --- branches/dunks/src/IntroState.cpp 2006-07-26 16:36:44 UTC (rev 52) +++ branches/dunks/src/IntroState.cpp 2006-07-26 19:08:09 UTC (rev 53) @@ -5,15 +5,23 @@ IntroState::IntroState() { - unsigned char* data; - int len = ResMan::Instance()->readFile("INTRO:INTRO2.WSA", data); + int len; + unsigned char* data = ResMan::Instance()->readFile(std::string("INTRO:INTRO2.WSA"), &len); + assert(data != NULL); + printf("intro1 len %d\n", len); m_wsa = new Wsafile(data, len); 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()); }; IntroState::~IntroState() @@ -23,12 +31,7 @@ void IntroState::JustMadeActive() { - unsigned char* data; - int len = ResMan::Instance()->readFile("INTRO:INTRO.PAL", data); - Palettefile pal (data, len); - Application::Instance()->SetPalette(pal.getPalette()); - State::JustMadeActive(); }; @@ -52,6 +55,9 @@ }; m_animSurface = m_wsa->getPicture(m_currentFrame); + + assert(m_animSurface != NULL); + Application::Instance()->BlitCentered(m_animSurface); return 0; Modified: branches/dunks/src/ResMan.cpp =================================================================== --- branches/dunks/src/ResMan.cpp 2006-07-26 16:36:44 UTC (rev 52) +++ branches/dunks/src/ResMan.cpp 2006-07-26 19:08:09 UTC (rev 53) @@ -22,7 +22,7 @@ m_path = path; }; -int DIRResource::readFile(bfs::path path, unsigned char* buf) +unsigned char* DIRResource::readFile(bfs::path path, int *size) { assert(0); // this doesnt work bfs::path fullpath (m_path.string() + path.string()); @@ -33,13 +33,15 @@ fseek(file, 0, SEEK_SET); - buf = new unsigned char[filesize]; + unsigned char* buf = new unsigned char[filesize]; fread(buf, filesize, 1, file); fclose(file); - return filesize; + if (size != NULL) *size = filesize; + + return buf; }; // ------------------------------------------------------------------ @@ -55,13 +57,19 @@ delete m_pakfile; }; -int PAKResource::readFile(bfs::path path, unsigned char* buf) +unsigned char* PAKResource::readFile(bfs::path path, int *size) { int filesize; - unsigned char *b = m_pakfile->getFile(path.string().c_str(), &filesize); - buf = b; + unsigned char *buf = m_pakfile->getFile(path.string().c_str(), &filesize); + printf("read pak %s size %d\n", path.string().c_str(), filesize); - return filesize; + + assert(buf != NULL); + assert(filesize != 0); + + if (size != NULL) *size = filesize; + + return buf; }; // ------------------------------------------------------------------ @@ -118,7 +126,7 @@ }; -int ResMan::readFile(std::string name, unsigned char* buf) +unsigned char* ResMan::readFile(std::string name, int *size) { unsigned int p = name.find(':'); assert(p != std::string::npos); @@ -134,9 +142,13 @@ if (res == NULL) { printf("ERROR: cannot find file!\n"); - buf = 0; - return 0; + if (size != NULL) size = 0; + return NULL; }; - return res->readFile(filename.c_str(), buf); + unsigned char *buf = res->readFile(filename.c_str(), size); + + assert(buf != NULL); + + return buf; }; Modified: branches/dunks/src/Settings.cpp =================================================================== --- branches/dunks/src/Settings.cpp 2006-07-26 16:36:44 UTC (rev 52) +++ branches/dunks/src/Settings.cpp 2006-07-26 19:08:09 UTC (rev 53) @@ -12,7 +12,7 @@ m_debug = false; - m_dataDir = "paks\\"; + m_dataDir = "/home/dunk/downloads/dune/"; m_doubleBuffered = false; }; Modified: branches/dunks/src/pakfile/Pakfile.cpp =================================================================== --- branches/dunks/src/pakfile/Pakfile.cpp 2006-07-26 16:36:44 UTC (rev 52) +++ branches/dunks/src/pakfile/Pakfile.cpp 2006-07-26 19:08:09 UTC (rev 53) @@ -1,6 +1,7 @@ #include "pakfile/Pakfile.h" #include <stdlib.h> -#include <SDL_endian.h> +#include <string> +#include "SDL_endian.h" Pakfile::Pakfile(const char *Pakfilename) { Modified: branches/dunks/src/pakfile/Wsafile.cpp =================================================================== --- branches/dunks/src/pakfile/Wsafile.cpp 2006-07-26 16:36:44 UTC (rev 52) +++ branches/dunks/src/pakfile/Wsafile.cpp 2006-07-26 19:08:09 UTC (rev 53) @@ -54,7 +54,7 @@ free(decodedFrames); }; -SDL_Surface * Wsafile::getPicture(Uint32 FrameNumber) +SDL_Surface * Wsafile::getPicture(Uint32 FrameNumber, SDL_Palette *pal) { if(FrameNumber >= NumFrames) { return NULL; @@ -70,7 +70,7 @@ printf("File Nr.: %d (Size: %dx%d)\n",FrameNumber,SizeX,SizeY); - //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-28 06:59:50
|
Revision: 56 Author: dunkfordyce Date: 2006-07-27 23:59:39 -0700 (Thu, 27 Jul 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=56&view=rev Log Message: ----------- starting queing of intro movies Modified Paths: -------------- branches/dunks/include/IntroState.h branches/dunks/src/IntroState.cpp Modified: branches/dunks/include/IntroState.h =================================================================== --- branches/dunks/include/IntroState.h 2006-07-27 21:18:22 UTC (rev 55) +++ branches/dunks/include/IntroState.h 2006-07-28 06:59:39 UTC (rev 56) @@ -6,6 +6,7 @@ #include "SDL.h" #include <list> +#include <string> class IntroState : public State { @@ -20,6 +21,8 @@ int Execute(float dt); + void enque(std::string file) { m_wsaNames.push_back(file); } + public: SDL_Surface* m_animSurface; Modified: branches/dunks/src/IntroState.cpp =================================================================== --- branches/dunks/src/IntroState.cpp 2006-07-27 21:18:22 UTC (rev 55) +++ branches/dunks/src/IntroState.cpp 2006-07-28 06:59:39 UTC (rev 56) @@ -6,8 +6,13 @@ IntroState::IntroState() { int len; - unsigned char* data = ResMan::Instance()->readFile(std::string("INTRO:INTRO2.WSA"), &len); + enque("INTRO:INTRO1.WSA"); + enque("INTRO:INTRO2.WSA"); + enque("INTRO:INTRO3.WSA"); + + unsigned char* data = ResMan::Instance()->readFile(std::string("INTRO:INTRO1.WSA"), &len); + assert(data != NULL); printf("intro1 len %d\n", len); @@ -44,7 +49,7 @@ { m_frametime += dt; - if (m_frametime > 1.1f) + if (m_frametime > 0.1f) { m_frametime = 0.0f; m_currentFrame ++; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dun...@us...> - 2006-07-28 00:58:56
|
Revision: 51 Author: dunkfordyce Date: 2006-07-25 15:10:09 -0700 (Tue, 25 Jul 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=51&view=rev Log Message: ----------- work on getting pakfile to read files. added intro state to test it. added Palettefile to pakfile stuff Modified Paths: -------------- branches/dunks/include/Application.h branches/dunks/include/ResMan.h branches/dunks/include/Settings.h branches/dunks/include/pakfile/Wsafile.h branches/dunks/src/Application.cpp branches/dunks/src/ResMan.cpp branches/dunks/src/SConscript branches/dunks/src/Settings.cpp branches/dunks/src/pakfile/Pakfile.cpp branches/dunks/src/pakfile/Wsafile.cpp Added Paths: ----------- branches/dunks/include/IntroState.h branches/dunks/include/pakfile/Palette.h branches/dunks/src/IntroState.cpp branches/dunks/src/pakfile/Palette.cpp Modified: branches/dunks/include/Application.h =================================================================== --- branches/dunks/include/Application.h 2006-07-25 10:48:36 UTC (rev 50) +++ branches/dunks/include/Application.h 2006-07-25 22:10:09 UTC (rev 51) @@ -46,6 +46,8 @@ 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); + private: void InitSettings(); void InitAudio(); Added: branches/dunks/include/IntroState.h =================================================================== --- branches/dunks/include/IntroState.h (rev 0) +++ branches/dunks/include/IntroState.h 2006-07-25 22:10:09 UTC (rev 51) @@ -0,0 +1,30 @@ +#ifndef DUNE_INTROSTATE_H +#define DUNE_INTROSTATE_H + +#include "State.h" +#include "pakfile/Wsafile.h" + +#include "SDL.h" + + +class IntroState : public State +{ + public: + IntroState(); + ~IntroState(); + + void JustMadeActive(); + void JustMadeInactive(); + + int Execute(float dt); + + public: + SDL_Surface* m_animSurface; + + Wsafile *m_wsa; + + int m_currentFrame; + float m_frametime; +}; + +#endif // DUNE_INTROSTATE_H Modified: branches/dunks/include/ResMan.h =================================================================== --- branches/dunks/include/ResMan.h 2006-07-25 10:48:36 UTC (rev 50) +++ branches/dunks/include/ResMan.h 2006-07-25 22:10:09 UTC (rev 51) @@ -7,6 +7,7 @@ #include "boost/filesystem/path.hpp" #include <map> +#include <string> class Resource { @@ -45,16 +46,16 @@ { friend class Singleton<ResMan>; - typedef std::map<const char*, Resource*> ResList; + typedef std::map<std::string, Resource*> ResList; protected: ResMan(); ~ResMan(); public: - bool addRes(const char* name); + bool addRes(std::string name); - int readFile(const char* path, char* buf); + int readFile(std::string path, unsigned char* buf); private: ResList m_resources; Modified: branches/dunks/include/Settings.h =================================================================== --- branches/dunks/include/Settings.h 2006-07-25 10:48:36 UTC (rev 50) +++ branches/dunks/include/Settings.h 2006-07-25 22:10:09 UTC (rev 51) @@ -104,6 +104,8 @@ inline bool GetDoubleBuffered() { return m_doubleBuffered; } + std::string GetDataDir() { return m_dataDir; } + }; #endif // DUNE_SETTINGS_H Added: branches/dunks/include/pakfile/Palette.h =================================================================== --- branches/dunks/include/pakfile/Palette.h (rev 0) +++ branches/dunks/include/pakfile/Palette.h 2006-07-25 22:10:09 UTC (rev 51) @@ -0,0 +1,19 @@ +#ifndef DUNE_PAKFILE_PALETTE_H +#define DUNE_PAKFILE_PALETTE_H + +#include "SDL.h" + +class Palettefile +{ + public: + Palettefile(unsigned char* buf, int bufsize); + ~Palettefile(); + + SDL_Palette* getPalette() { return m_palette; } + + private: + SDL_Palette* m_palette; + +}; + +#endif // DUNE_PAKFILE_PALETTE_H Modified: branches/dunks/include/pakfile/Wsafile.h =================================================================== --- branches/dunks/include/pakfile/Wsafile.h 2006-07-25 10:48:36 UTC (rev 50) +++ branches/dunks/include/pakfile/Wsafile.h 2006-07-25 22:10:09 UTC (rev 51) @@ -25,7 +25,7 @@ unsigned char* Filedata; Uint32* Index; - Uint32 WsaFilesize; + int WsaFilesize; Uint16 NumFrames; Uint16 SizeX; Modified: branches/dunks/src/Application.cpp =================================================================== --- branches/dunks/src/Application.cpp 2006-07-25 10:48:36 UTC (rev 50) +++ branches/dunks/src/Application.cpp 2006-07-25 22:10:09 UTC (rev 51) @@ -23,10 +23,13 @@ #include "Font.h" #include "TopLevelState.h" #include "MainMenu.h" +#include "IntroState.h" #include "DataFile.h" #include "pakfile/Pakfile.h" +#include "ResMan.h" + #define SCREEN_BPP 8 #define VERSION "0.94.1" @@ -84,7 +87,7 @@ if (SDL_Init(flags) < 0) { fprintf(stderr, "ERROR: Couldn't initialise SDL: %s\n", SDL_GetError()); - Die(); + //Die(); } SDL_EnableUNICODE(1); @@ -132,7 +135,8 @@ //realign_buttons(); m_rootState = new TopLevelState(); - m_rootState->PushState( new MainMenuState() ); + m_rootState->PushState( new IntroState() ); + //m_rootState->PushState( new MainMenuState() ); } void Application::InitSettings() @@ -185,6 +189,12 @@ */ }; + +void Application::SetPalette(SDL_Palette* pal) +{ + SDL_SetColors(m_screen, pal->colors, 0, pal->ncolors); +}; + void Application::InitVideo() { Settings* set = Settings::Instance(); @@ -205,14 +215,15 @@ // set the video palette // grab the palette from any image, we use menu - 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_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); @@ -221,14 +232,32 @@ void Application::LoadData() { - Pakfile intropak ("intro.pak"); - int nfiles = intropak.getNumFiles(); + printf("loading resources\n"); + ResMan::Instance()->addRes("ATRE"); + ResMan::Instance()->addRes("DUNE"); + ResMan::Instance()->addRes("ENGLISH"); + ResMan::Instance()->addRes("FINALE"); + ResMan::Instance()->addRes("HARK"); + ResMan::Instance()->addRes("HERC"); + ResMan::Instance()->addRes("INTRO"); + ResMan::Instance()->addRes("INTROVOC"); + ResMan::Instance()->addRes("MENTAT"); + ResMan::Instance()->addRes("MERC"); + ResMan::Instance()->addRes("ORDOS"); + ResMan::Instance()->addRes("SCENARIO"); + ResMan::Instance()->addRes("SOUND"); + ResMan::Instance()->addRes("VOC"); + ResMan::Instance()->addRes("XTRE"); + printf("done loading resources\n"); - for (int i=0; i!=nfiles; i++) - { - printf("found file %s\n", intropak.getFilename(i)); - }; + //Pakfile intropak ("intro.pak"); + //int nfiles = intropak.getNumFiles(); + //for (int i=0; i!=nfiles; i++) + //{ + // printf("found file %s\n", intropak.getFilename(i)); + //}; + //loadDataFile(); Added: branches/dunks/src/IntroState.cpp =================================================================== --- branches/dunks/src/IntroState.cpp (rev 0) +++ branches/dunks/src/IntroState.cpp 2006-07-25 22:10:09 UTC (rev 51) @@ -0,0 +1,61 @@ +#include "IntroState.h" +#include "ResMan.h" +#include "Application.h" +#include "pakfile/Palette.h" + +IntroState::IntroState() +{ + unsigned char* data; + int len = ResMan::Instance()->readFile("INTRO:INTRO2.WSA", data); + + printf("intro1 len %d\n", len); + + m_wsa = new Wsafile(data, len); + + m_currentFrame = 0; + m_frametime = 0.0f; +}; + +IntroState::~IntroState() +{ + delete m_wsa; +}; + +void IntroState::JustMadeActive() +{ + unsigned char* data; + int len = ResMan::Instance()->readFile("INTRO:INTRO.PAL", data); + + Palettefile pal (data, len); + Application::Instance()->SetPalette(pal.getPalette()); + + State::JustMadeActive(); +}; + +void IntroState::JustMadeInactive() +{ + State::JustMadeInactive(); +}; + +int IntroState::Execute(float dt) +{ + m_frametime += dt; + + if (m_frametime > 1.0f) + { + m_frametime = 0.0f; + m_currentFrame ++; + if (m_currentFrame >= m_wsa->getNumFrames()) + { + return -1; + }; + }; + + m_animSurface = m_wsa->getPicture(m_currentFrame); + Application::Instance()->BlitCentered(m_animSurface); + + return 0; +}; + + + Modified: branches/dunks/src/ResMan.cpp =================================================================== --- branches/dunks/src/ResMan.cpp 2006-07-25 10:48:36 UTC (rev 50) +++ branches/dunks/src/ResMan.cpp 2006-07-25 22:10:09 UTC (rev 51) @@ -1,7 +1,11 @@ #include "ResMan.h" +#include "Settings.h" #include "boost/filesystem/operations.hpp" // includes boost/filesystem/path.hpp #include "boost/filesystem/fstream.hpp" // ditto + +#include <assert.h> + namespace bfs = boost::filesystem; Resource::~Resource() @@ -18,6 +22,7 @@ int DIRResource::readFile(bfs::path path, unsigned char* buf) { + assert(0); // this doesnt work bfs::path fullpath (m_path.string() + path.string()); FILE *file = fopen (fullpath.string().c_str(), "rb"); @@ -51,7 +56,9 @@ int PAKResource::readFile(bfs::path path, unsigned char* buf) { int filesize; - buf = m_pakfile->getFile(path.string().c_str(), &filesize); + unsigned char *b = m_pakfile->getFile(path.string().c_str(), &filesize); + buf = b; + printf("read pak %s size %d\n", path.string().c_str(), filesize); return filesize; }; @@ -75,30 +82,60 @@ m_resources.clear(); }; -bool ResMan::addRes(const char* name) +bool ResMan::addRes(std::string name) { - bfs::path file (name); + std::string fullpath = Settings::Instance()->GetDataDir(); + fullpath.append(name); + printf("adding resource %s from %s...\n", name.c_str(), fullpath.c_str()); + bfs::path file (fullpath); Resource *res = NULL; - if (bfs::is_directory(file)) + if (bfs::exists(file)) { + printf("Using DIRResource for %s\n", name.c_str()); res = new DIRResource(file); } - else + else { - res = new PAKResource(file); - }; + std::string pakname = file.string(); + pakname.append(".PAK"); + bfs::path pakpath (pakname); - // this isnt going to work.. - if (res == NULL) - { - return false; + if (!bfs::exists(pakpath)) + { + printf("Neither DIR or PAK found for %s\n", name.c_str()); + return false; + } + + res = new PAKResource(pakpath); }; - m_resources[name] = res; + m_resources[name.c_str()] = res; return true; }; +int ResMan::readFile(std::string name, unsigned char* buf) +{ + unsigned int p = name.find(':'); + assert(p != std::string::npos); + std::string fsname = std::string(name, 0, p); + std::string filename = std::string(name, p+1, + name.length() - fsname.length() - 1); + + printf("opening file from %s named %s...\n", fsname.c_str(), filename.c_str()); + + Resource* res = m_resources[fsname]; + + if (res == NULL) + { + printf("ERROR: cannot find file!\n"); + buf = 0; + return 0; + }; + + return res->readFile(filename.c_str(), buf); +}; + Modified: branches/dunks/src/SConscript =================================================================== --- branches/dunks/src/SConscript 2006-07-25 10:48:36 UTC (rev 50) +++ branches/dunks/src/SConscript 2006-07-25 22:10:09 UTC (rev 51) @@ -20,6 +20,7 @@ "TopLevelState.cpp", "MenuBase.cpp", "MainMenu.cpp", + "IntroState.cpp", "SingleMenu.cpp", "ResMan.cpp", @@ -35,6 +36,7 @@ "pakfile/Pakfile.cpp", "pakfile/Shpfile.cpp", "pakfile/Wsafile.cpp", + "pakfile/Palette.cpp", "main.cpp", ] Modified: branches/dunks/src/Settings.cpp =================================================================== --- branches/dunks/src/Settings.cpp 2006-07-25 10:48:36 UTC (rev 50) +++ branches/dunks/src/Settings.cpp 2006-07-25 22:10:09 UTC (rev 51) @@ -12,7 +12,7 @@ m_debug = false; - m_dataDir = "data"; + m_dataDir = "/home/dunk/downloads/dune/"; m_doubleBuffered = false; }; Modified: branches/dunks/src/pakfile/Pakfile.cpp =================================================================== --- branches/dunks/src/pakfile/Pakfile.cpp 2006-07-25 10:48:36 UTC (rev 50) +++ branches/dunks/src/pakfile/Pakfile.cpp 2006-07-25 22:10:09 UTC (rev 51) @@ -94,6 +94,7 @@ } strcpy(FileEntry[NumFileEntry].Filename,name); + printf("pak: found file %s\n", name); if(NumFileEntry > 0) { FileEntry[NumFileEntry - 1].EndOffset = startoffset - 1; Added: branches/dunks/src/pakfile/Palette.cpp =================================================================== --- branches/dunks/src/pakfile/Palette.cpp (rev 0) +++ branches/dunks/src/pakfile/Palette.cpp 2006-07-25 22:10:09 UTC (rev 51) @@ -0,0 +1,25 @@ +#include "pakfile/Palette.h" + +Palettefile::Palettefile(unsigned char* buf, int bufsize) +{ + m_palette = new SDL_Palette; + m_palette->ncolors = bufsize / 3; + + m_palette->colors = new SDL_Color[m_palette->ncolors]; + SDL_Color* c = m_palette->colors; + unsigned char* dunepal = buf; + + for (int i=0; i!=m_palette->ncolors; i++, c++, dunepal+=3) + { + c->r = dunepal[0]; + c->g = dunepal[1]; + c->b = dunepal[2]; + }; + + delete [] buf; +}; + +Palettefile::~Palettefile() +{ + delete m_palette; +}; Modified: branches/dunks/src/pakfile/Wsafile.cpp =================================================================== --- branches/dunks/src/pakfile/Wsafile.cpp 2006-07-25 10:48:36 UTC (rev 50) +++ branches/dunks/src/pakfile/Wsafile.cpp 2006-07-25 22:10:09 UTC (rev 51) @@ -8,14 +8,18 @@ Filedata = bufFiledata; WsaFilesize = bufsize; + printf("loading wsa with size %d...\n", bufsize); + if(WsaFilesize < 10) { fprintf(stderr, "Error: No valid WSA-File: File too small!\n"); exit(EXIT_FAILURE); } NumFrames = SDL_SwapLE16(*((Uint16*) Filedata) ); + printf("numframes = %d\n", NumFrames); SizeX = SDL_SwapLE16(*((Uint16*) (Filedata + 2)) ); SizeY = SDL_SwapLE16(*((Uint16*) (Filedata + 4)) ); + printf("size %d x %d\n", SizeX, SizeY); if( ((unsigned short *) Filedata)[4] == 0) { Index = (Uint32 *) (Filedata + 10); @@ -24,6 +28,8 @@ Index = (Uint32 *) (Filedata + 8); FramesPer1024ms = SDL_SwapLE16( *((Uint16*) (Filedata+6)) ); } + + printf("FramesPer1024ms = %d", FramesPer1024ms); if(Index[0] == 0) { Index++; @@ -31,7 +37,7 @@ } if(Filedata + WsaFilesize < (((unsigned char *) Index) + 4 * NumFrames)) { - fprintf(stderr, "Error: No valid WSA-File: File too small!\n"); + fprintf(stderr, "Error: No valid WSA-File: File too small -2-!\n"); exit(EXIT_FAILURE); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dun...@us...> - 2006-07-27 22:43:18
|
Revision: 54 Author: dunkfordyce Date: 2006-07-26 23:14:16 -0700 (Wed, 26 Jul 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=54&view=rev Log Message: ----------- working intro - palette still broken Modified Paths: -------------- branches/dunks/include/Application.h branches/dunks/src/Application.cpp branches/dunks/src/IntroState.cpp branches/dunks/src/pakfile/Palette.cpp branches/dunks/src/pakfile/Wsafile.cpp Modified: branches/dunks/include/Application.h =================================================================== --- branches/dunks/include/Application.h 2006-07-26 19:08:09 UTC (rev 53) +++ branches/dunks/include/Application.h 2006-07-27 06:14:16 UTC (rev 54) @@ -47,6 +47,7 @@ void BlitCentered(SDL_Surface* surface, SDL_Rect* src=NULL); void SetPalette(SDL_Palette* pal); + SDL_Palette* GetCurrentPalette() { return m_currentPalette; } private: void InitSettings(); @@ -60,6 +61,7 @@ void BlitCursor(); SDL_Surface* m_screen; + SDL_Palette* m_currentPalette; StateMachine* m_rootState; Modified: branches/dunks/src/Application.cpp =================================================================== --- branches/dunks/src/Application.cpp 2006-07-26 19:08:09 UTC (rev 53) +++ branches/dunks/src/Application.cpp 2006-07-27 06:14:16 UTC (rev 54) @@ -195,6 +195,7 @@ assert(pal != NULL); printf("setting palette %d colors\n", pal->ncolors); SDL_SetColors(m_screen, pal->colors, 0, pal->ncolors); + m_currentPalette = pal; }; void Application::InitVideo() @@ -344,6 +345,7 @@ //fnt->render("abcdefghijklmnopqrstuvwxz", m_screen, 10, 30, gpaloff); //BlitCursor(); + SDL_Flip(m_screen); Modified: branches/dunks/src/IntroState.cpp =================================================================== --- branches/dunks/src/IntroState.cpp 2006-07-26 19:08:09 UTC (rev 53) +++ branches/dunks/src/IntroState.cpp 2006-07-27 06:14:16 UTC (rev 54) @@ -17,8 +17,7 @@ m_currentFrame = 0; m_frametime = 0.0f; - int len; - unsigned char* data = ResMan::Instance()->readFile("INTRO:INTRO.PAL", &len); + data = ResMan::Instance()->readFile("INTRO:INTRO.PAL", &len); Palettefile pal (data, len); Application::Instance()->SetPalette(pal.getPalette()); @@ -44,7 +43,7 @@ { m_frametime += dt; - if (m_frametime > 1.0f) + if (m_frametime > 1.1f) { m_frametime = 0.0f; m_currentFrame ++; @@ -54,7 +53,7 @@ }; }; - m_animSurface = m_wsa->getPicture(m_currentFrame); + m_animSurface = m_wsa->getPicture(m_currentFrame, Application::Instance()->GetCurrentPalette()); assert(m_animSurface != NULL); Modified: branches/dunks/src/pakfile/Palette.cpp =================================================================== --- branches/dunks/src/pakfile/Palette.cpp 2006-07-26 19:08:09 UTC (rev 53) +++ branches/dunks/src/pakfile/Palette.cpp 2006-07-27 06:14:16 UTC (rev 54) @@ -2,6 +2,8 @@ Palettefile::Palettefile(unsigned char* buf, int bufsize) { + printf("loading palette...\n"); + m_palette = new SDL_Palette; m_palette->ncolors = bufsize / 3; @@ -11,9 +13,11 @@ for (int i=0; i!=m_palette->ncolors; i++, c++, dunepal+=3) { - c->r = dunepal[0]; - c->g = dunepal[1]; - c->b = dunepal[2]; + 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); }; delete [] buf; Modified: branches/dunks/src/pakfile/Wsafile.cpp =================================================================== --- branches/dunks/src/pakfile/Wsafile.cpp 2006-07-26 19:08:09 UTC (rev 53) +++ branches/dunks/src/pakfile/Wsafile.cpp 2006-07-27 06:14:16 UTC (rev 54) @@ -54,7 +54,7 @@ free(decodedFrames); }; -SDL_Surface * Wsafile::getPicture(Uint32 FrameNumber, SDL_Palette *pal) +SDL_Surface * Wsafile::getPicture(Uint32 FrameNumber, SDL_Palette *palette) { if(FrameNumber >= NumFrames) { return NULL; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dun...@us...> - 2006-07-27 21:18:41
|
Revision: 55 Author: dunkfordyce Date: 2006-07-27 14:18:22 -0700 (Thu, 27 Jul 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=55&view=rev Log Message: ----------- fixed intro state palette issue Modified Paths: -------------- branches/dunks/include/IntroState.h branches/dunks/src/Application.cpp branches/dunks/src/IntroState.cpp branches/dunks/src/pakfile/Palette.cpp branches/dunks/src/pakfile/Wsafile.cpp Modified: branches/dunks/include/IntroState.h =================================================================== --- branches/dunks/include/IntroState.h 2006-07-27 06:14:16 UTC (rev 54) +++ branches/dunks/include/IntroState.h 2006-07-27 21:18:22 UTC (rev 55) @@ -5,10 +5,12 @@ #include "pakfile/Wsafile.h" #include "SDL.h" +#include <list> - class IntroState : public State { + typedef std::list<std::string> IntroList; + public: IntroState(); ~IntroState(); @@ -21,6 +23,8 @@ public: SDL_Surface* m_animSurface; + IntroList m_wsaNames; + Wsafile *m_wsa; int m_currentFrame; Modified: branches/dunks/src/Application.cpp =================================================================== --- branches/dunks/src/Application.cpp 2006-07-27 06:14:16 UTC (rev 54) +++ branches/dunks/src/Application.cpp 2006-07-27 21:18:22 UTC (rev 55) @@ -196,6 +196,19 @@ printf("setting palette %d colors\n", pal->ncolors); SDL_SetColors(m_screen, pal->colors, 0, pal->ncolors); m_currentPalette = pal; + + 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() Modified: branches/dunks/src/IntroState.cpp =================================================================== --- branches/dunks/src/IntroState.cpp 2006-07-27 06:14:16 UTC (rev 54) +++ branches/dunks/src/IntroState.cpp 2006-07-27 21:18:22 UTC (rev 55) @@ -20,6 +20,7 @@ data = ResMan::Instance()->readFile("INTRO:INTRO.PAL", &len); Palettefile pal (data, len); + Application::Instance()->SetPalette(pal.getPalette()); }; @@ -53,7 +54,15 @@ }; }; - m_animSurface = m_wsa->getPicture(m_currentFrame, Application::Instance()->GetCurrentPalette()); + 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); Modified: branches/dunks/src/pakfile/Palette.cpp =================================================================== --- branches/dunks/src/pakfile/Palette.cpp 2006-07-27 06:14:16 UTC (rev 54) +++ branches/dunks/src/pakfile/Palette.cpp 2006-07-27 21:18:22 UTC (rev 55) @@ -20,6 +20,10 @@ 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-07-27 06:14:16 UTC (rev 54) +++ branches/dunks/src/pakfile/Wsafile.cpp 2006-07-27 21:18:22 UTC (rev 55) @@ -68,14 +68,20 @@ return NULL; } - printf("File Nr.: %d (Size: %dx%d)\n",FrameNumber,SizeX,SizeY); + printf("Frame Nr.: %d (Size: %dx%d)\n",FrameNumber,SizeX,SizeY); + printf("%u %u %u\n", palette->colors[12].r, + palette->colors[12].g, + palette->colors[12].b); + SDL_SetColors(pic, palette->colors, 0, palette->ncolors); SDL_LockSurface(pic); + printf("%u\n", Image[0]); + //Now we can copy line by line for(int y = 0; y < SizeY;y++) { - memcpy( ((char*) (pic->pixels)) + y * pic->pitch , Image + y * SizeX, SizeX); + memcpy( ((unsigned char*) (pic->pixels)) + y * pic->pitch , Image + y * SizeX, SizeX); } SDL_UnlockSurface(pic); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dun...@us...> - 2006-07-26 16:37:01
|
Revision: 52 Author: dunkfordyce Date: 2006-07-26 09:36:44 -0700 (Wed, 26 Jul 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=52&view=rev Log Message: ----------- windows stuff Modified Paths: -------------- branches/dunks/SConstruct branches/dunks/include/ResMan.h branches/dunks/src/Application.cpp branches/dunks/src/ResMan.cpp branches/dunks/src/SConscript branches/dunks/src/Settings.cpp branches/dunks/src/pakfile/Decode.cpp branches/dunks/src/pakfile/Pakfile.cpp Modified: branches/dunks/SConstruct =================================================================== --- branches/dunks/SConstruct 2006-07-25 22:10:09 UTC (rev 51) +++ branches/dunks/SConstruct 2006-07-26 16:36:44 UTC (rev 52) @@ -26,7 +26,7 @@ env.ParseConfig('sdl-config --cflags --libs') env.ParseConfig('pkg-config --cflags --libs zziplib') env.Append(CCFLAGS=["-Wall"]) #, "-Werror"]) - #env.Append(CCFLAGS=["-Wall", "-Werror", "-O2", "-ffast-math", "-funroll-loops"]) + env.Append(CCFLAGS=["-Wall", "-Werror", "-O2", "-ffast-math", "-funroll-loops"]) #env.Append(LINKFLAGS = ["-ffast-math"]) if 1: @@ -34,10 +34,10 @@ else: env.Append(LIBS = ["zzipdll", "zdll", "SDLmain"]) env.Append(LINKFLAGS = ["/SUBSYSTEM:CONSOLE"]) - env.Append(CCFLAGS = ["/MD", "/O2"]) + env.Append(CCFLAGS = ["/O2", "/EHsc", "/MD", "/Op"]) env.Append(LIBS = [ "SDL", - "SDL_mixer", + "SDL_mixer", "SDL_image", "SDL_net", "SDL_ttf", Modified: branches/dunks/include/ResMan.h =================================================================== --- branches/dunks/include/ResMan.h 2006-07-25 22:10:09 UTC (rev 51) +++ branches/dunks/include/ResMan.h 2006-07-26 16:36:44 UTC (rev 52) @@ -65,3 +65,4 @@ #endif // DUNE_RESMAN_H + Modified: branches/dunks/src/Application.cpp =================================================================== --- branches/dunks/src/Application.cpp 2006-07-25 22:10:09 UTC (rev 51) +++ branches/dunks/src/Application.cpp 2006-07-26 16:36:44 UTC (rev 52) @@ -26,7 +26,7 @@ #include "IntroState.h" #include "DataFile.h" -#include "pakfile/Pakfile.h" +//#include "pakfile/Pakfile.h" #include "ResMan.h" @@ -252,7 +252,6 @@ //Pakfile intropak ("intro.pak"); //int nfiles = intropak.getNumFiles(); - //for (int i=0; i!=nfiles; i++) //{ // printf("found file %s\n", intropak.getFilename(i)); Modified: branches/dunks/src/ResMan.cpp =================================================================== --- branches/dunks/src/ResMan.cpp 2006-07-25 22:10:09 UTC (rev 51) +++ branches/dunks/src/ResMan.cpp 2006-07-26 16:36:44 UTC (rev 52) @@ -1,8 +1,10 @@ +#include "boost/filesystem/path.hpp" +#include "boost/filesystem/operations.hpp" + #include "ResMan.h" #include "Settings.h" -#include "boost/filesystem/operations.hpp" // includes boost/filesystem/path.hpp -#include "boost/filesystem/fstream.hpp" // ditto +//#include "boost/filesystem/fstream.hpp" // ditto #include <assert.h> @@ -138,4 +140,3 @@ return res->readFile(filename.c_str(), buf); }; - Modified: branches/dunks/src/SConscript =================================================================== --- branches/dunks/src/SConscript 2006-07-25 22:10:09 UTC (rev 51) +++ branches/dunks/src/SConscript 2006-07-26 16:36:44 UTC (rev 52) @@ -41,6 +41,8 @@ "main.cpp", ] +#all_sources = ["ResMan.cpp"] + #all_sources += [env.Object('SDL_rwops_zzip.c')] env.Program("../dunelegacy", all_sources) Modified: branches/dunks/src/Settings.cpp =================================================================== --- branches/dunks/src/Settings.cpp 2006-07-25 22:10:09 UTC (rev 51) +++ branches/dunks/src/Settings.cpp 2006-07-26 16:36:44 UTC (rev 52) @@ -12,7 +12,7 @@ m_debug = false; - m_dataDir = "/home/dunk/downloads/dune/"; + m_dataDir = "paks\\"; m_doubleBuffered = false; }; Modified: branches/dunks/src/pakfile/Decode.cpp =================================================================== --- branches/dunks/src/pakfile/Decode.cpp 2006-07-25 22:10:09 UTC (rev 51) +++ branches/dunks/src/pakfile/Decode.cpp 2006-07-26 16:36:44 UTC (rev 52) @@ -1,18 +1,18 @@ #include "pakfile/Decode.h" #include <SDL_endian.h> #include <stdlib.h> -#include <string.h> +#include <string> #include <SDL.h> Decode::Decode() { - ; -} +}; + Decode::~Decode() { - ; + }; int Decode::decode80(unsigned char *image_in, unsigned char *image_out,unsigned int checksum) @@ -115,12 +115,12 @@ fprintf(stderr,"file contains unknown format80 command: %x\n",*readp); exit(EXIT_FAILURE); } - } + }; if (megacounta + megacountb + megacountc + megacountd + megacounte != checksum) return -1; return 0; -} +}; void Decode::my_memcpy(unsigned char *dst, unsigned char *src, unsigned cnt) { @@ -135,8 +135,8 @@ *dst = *src; dst++; src++; - } -} + }; +}; void Decode::shp_correct_lf(unsigned char *in, unsigned char *out, int size) { Modified: branches/dunks/src/pakfile/Pakfile.cpp =================================================================== --- branches/dunks/src/pakfile/Pakfile.cpp 2006-07-25 22:10:09 UTC (rev 51) +++ branches/dunks/src/pakfile/Pakfile.cpp 2006-07-26 16:36:44 UTC (rev 52) @@ -1,6 +1,5 @@ #include "pakfile/Pakfile.h" #include <stdlib.h> -#include <string.h> #include <SDL_endian.h> Pakfile::Pakfile(const char *Pakfilename) @@ -47,7 +46,6 @@ int startoffset; char name[256]; - while(1) { if(fread((void*) &startoffset, 4, 1,fPakFile) != 1) { perror("fread()"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dun...@us...> - 2006-07-25 10:48:47
|
Revision: 50 Author: dunkfordyce Date: 2006-07-25 03:48:36 -0700 (Tue, 25 Jul 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=50&view=rev Log Message: ----------- fixes to resource manager Modified Paths: -------------- branches/dunks/SConstruct branches/dunks/src/ResMan.cpp branches/dunks/src/pakfile/Decode.cpp Modified: branches/dunks/SConstruct =================================================================== --- branches/dunks/SConstruct 2006-07-25 10:27:19 UTC (rev 49) +++ branches/dunks/SConstruct 2006-07-25 10:48:36 UTC (rev 50) @@ -44,7 +44,9 @@ ]) if sys.platform != 'win32': - env.Append(LIBS=["boost_signals"]) + env.Append(LIBS=[ "boost_signals", + "boost_filesystem", + ]) env.Append(CPPPATH = [ "${SDL_INCLUDE_PATH}", "${ZLIB_INCLUDE_PATH}", Modified: branches/dunks/src/ResMan.cpp =================================================================== --- branches/dunks/src/ResMan.cpp 2006-07-25 10:27:19 UTC (rev 49) +++ branches/dunks/src/ResMan.cpp 2006-07-25 10:48:36 UTC (rev 50) @@ -4,6 +4,13 @@ #include "boost/filesystem/fstream.hpp" // ditto namespace bfs = boost::filesystem; +Resource::~Resource() +{ + +}; + +// ------------------------------------------------------------------ + DIRResource::DIRResource(bfs::path path) { m_path = path; Modified: branches/dunks/src/pakfile/Decode.cpp =================================================================== --- branches/dunks/src/pakfile/Decode.cpp 2006-07-25 10:27:19 UTC (rev 49) +++ branches/dunks/src/pakfile/Decode.cpp 2006-07-25 10:48:36 UTC (rev 50) @@ -15,7 +15,7 @@ ; }; -int Decode::decode80(unsigned char *image_in, unsigned char *image_out,unsigned checksum) +int Decode::decode80(unsigned char *image_in, unsigned char *image_out,unsigned int checksum) { // // should decode all the format80 stuff ;-) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dun...@us...> - 2006-07-25 10:27:30
|
Revision: 49 Author: dunkfordyce Date: 2006-07-25 03:27:19 -0700 (Tue, 25 Jul 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=49&view=rev Log Message: ----------- fixes to resource manager Modified Paths: -------------- branches/dunks/SConstruct branches/dunks/include/ResMan.h branches/dunks/include/pakfile/Pakfile.h branches/dunks/src/ResMan.cpp branches/dunks/src/pakfile/Pakfile.cpp Modified: branches/dunks/SConstruct =================================================================== --- branches/dunks/SConstruct 2006-07-25 09:59:46 UTC (rev 48) +++ branches/dunks/SConstruct 2006-07-25 10:27:19 UTC (rev 49) @@ -41,9 +41,11 @@ "SDL_image", "SDL_net", "SDL_ttf", - #"boost_signals", ]) +if sys.platform != 'win32': + env.Append(LIBS=["boost_signals"]) + env.Append(CPPPATH = [ "${SDL_INCLUDE_PATH}", "${ZLIB_INCLUDE_PATH}", "${ZZIP_INCLUDE_PATH}", Modified: branches/dunks/include/ResMan.h =================================================================== --- branches/dunks/include/ResMan.h 2006-07-25 09:59:46 UTC (rev 48) +++ branches/dunks/include/ResMan.h 2006-07-25 10:27:19 UTC (rev 49) @@ -12,7 +12,8 @@ { public: Resource() {}; - virtual long readFile(boost::filesystem::path path, char* buf) { return 0; } + virtual ~Resource(); + virtual int readFile(boost::filesystem::path path, unsigned char* buf) { return 0; } protected: boost::filesystem::path m_path; @@ -22,8 +23,8 @@ class DIRResource : public Resource { public: - DIRResource(boost::filesystem::path path) {}; - virtual long readFile(boost::filesystem::path path, char* buf) {return 0;} + DIRResource(boost::filesystem::path path) ; + virtual int readFile(boost::filesystem::path path, unsigned char* buf) ; }; @@ -31,9 +32,9 @@ class PAKResource : public Resource { public: - PAKResource(boost::filesystem::path path) {}; + PAKResource(boost::filesystem::path path) ; ~PAKResource(); - virtual long readFile(boost::filesystem::path path, char* buf) {return 0;} + virtual int readFile(boost::filesystem::path path, unsigned char* buf) ; private: Pakfile *m_pakfile; @@ -53,7 +54,7 @@ public: bool addRes(const char* name); - long readFile(const char* path, char* buf); + int readFile(const char* path, char* buf); private: ResList m_resources; Modified: branches/dunks/include/pakfile/Pakfile.h =================================================================== --- branches/dunks/include/pakfile/Pakfile.h 2006-07-25 09:59:46 UTC (rev 48) +++ branches/dunks/include/pakfile/Pakfile.h 2006-07-25 10:27:19 UTC (rev 49) @@ -12,12 +12,12 @@ class Pakfile { public: - Pakfile(char * Pakfilename); + Pakfile(const char * Pakfilename); ~Pakfile(); char * getFilename(int index); - unsigned char *getFile(char *fname, int *size); + unsigned char *getFile(const char *fname, int *size); inline int getNumFiles() {return NumFileEntry;}; Modified: branches/dunks/src/ResMan.cpp =================================================================== --- branches/dunks/src/ResMan.cpp 2006-07-25 09:59:46 UTC (rev 48) +++ branches/dunks/src/ResMan.cpp 2006-07-25 10:27:19 UTC (rev 49) @@ -9,17 +9,17 @@ m_path = path; }; -long DIRResource::readFile(bfs::path path, char* buf) +int DIRResource::readFile(bfs::path path, unsigned char* buf) { - bfs::path fullpath = m_path + path; + bfs::path fullpath (m_path.string() + path.string()); - FILE file (fullpath.c_str(), "rb"); + FILE *file = fopen (fullpath.string().c_str(), "rb"); fseek(file, 0, SEEK_END); - long filesize = ftell; + int filesize = ftell(file); fseek(file, 0, SEEK_SET); - buf = new char[filesize]; + buf = new unsigned char[filesize]; fread(buf, filesize, 1, file); @@ -33,7 +33,7 @@ PAKResource::PAKResource(bfs::path path) { m_path = path; - m_pakfile = Pakfile(path.c_str()); + m_pakfile = new Pakfile(path.string().c_str()); }; PAKResource::~PAKResource() @@ -41,10 +41,10 @@ delete m_pakfile; }; -long PAKResource::readFile(bfs::path path, char* buf) +int PAKResource::readFile(bfs::path path, unsigned char* buf) { - long filesize; - buf = m_pakfile->getFile(path.c_str(), &filesize); + int filesize; + buf = m_pakfile->getFile(path.string().c_str(), &filesize); return filesize; }; @@ -62,7 +62,7 @@ it != m_resources.end(); ++it) { - delete *it; + delete (it->second); }; m_resources.clear(); @@ -75,11 +75,11 @@ if (bfs::is_directory(file)) { - res = DIRResource(file); + res = new DIRResource(file); } else { - res = PAKResource(file); + res = new PAKResource(file); }; // this isnt going to work.. @@ -88,7 +88,7 @@ return false; }; - m_resources[fn] = res; + m_resources[name] = res; return true; }; Modified: branches/dunks/src/pakfile/Pakfile.cpp =================================================================== --- branches/dunks/src/pakfile/Pakfile.cpp 2006-07-25 09:59:46 UTC (rev 48) +++ branches/dunks/src/pakfile/Pakfile.cpp 2006-07-25 10:27:19 UTC (rev 49) @@ -3,7 +3,7 @@ #include <string.h> #include <SDL_endian.h> -Pakfile::Pakfile(char *Pakfilename) +Pakfile::Pakfile(const char *Pakfilename) { FileEntry = NULL; NumFileEntry = 0; @@ -120,7 +120,7 @@ return FileEntry[index].Filename; }; -unsigned char *Pakfile::getFile(char *fname, int *size) +unsigned char *Pakfile::getFile(const char *fname, int *size) { int Index = -1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dun...@us...> - 2006-07-25 09:59:57
|
Revision: 48 Author: dunkfordyce Date: 2006-07-25 02:59:46 -0700 (Tue, 25 Jul 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=48&view=rev Log Message: ----------- commiting resource manager to test on linux Modified Paths: -------------- branches/dunks/SConstruct branches/dunks/src/SConscript branches/dunks/src/pakfile/Decode.cpp Added Paths: ----------- branches/dunks/include/ResMan.h branches/dunks/src/ResMan.cpp Modified: branches/dunks/SConstruct =================================================================== --- branches/dunks/SConstruct 2006-07-25 06:24:26 UTC (rev 47) +++ branches/dunks/SConstruct 2006-07-25 09:59:46 UTC (rev 48) @@ -41,7 +41,7 @@ "SDL_image", "SDL_net", "SDL_ttf", - "boost_signals", + #"boost_signals", ]) env.Append(CPPPATH = [ "${SDL_INCLUDE_PATH}", Added: branches/dunks/include/ResMan.h =================================================================== --- branches/dunks/include/ResMan.h (rev 0) +++ branches/dunks/include/ResMan.h 2006-07-25 09:59:46 UTC (rev 48) @@ -0,0 +1,65 @@ +#ifndef DUNE_RESMAN_H +#define DUNE_RESMAN_H + +#include "singleton.h" +#include "pakfile/Pakfile.h" + +#include "boost/filesystem/path.hpp" + +#include <map> + +class Resource +{ + public: + Resource() {}; + virtual long readFile(boost::filesystem::path path, char* buf) { return 0; } + + protected: + boost::filesystem::path m_path; +}; + + +class DIRResource : public Resource +{ + public: + DIRResource(boost::filesystem::path path) {}; + virtual long readFile(boost::filesystem::path path, char* buf) {return 0;} + +}; + + +class PAKResource : public Resource +{ + public: + PAKResource(boost::filesystem::path path) {}; + ~PAKResource(); + virtual long readFile(boost::filesystem::path path, char* buf) {return 0;} + + private: + Pakfile *m_pakfile; +}; + + +class ResMan : public Singleton<ResMan> +{ + friend class Singleton<ResMan>; + + typedef std::map<const char*, Resource*> ResList; + + protected: + ResMan(); + ~ResMan(); + + public: + bool addRes(const char* name); + + long readFile(const char* path, char* buf); + + private: + ResList m_resources; + +}; + +#endif // DUNE_RESMAN_H + + Added: branches/dunks/src/ResMan.cpp =================================================================== --- branches/dunks/src/ResMan.cpp (rev 0) +++ branches/dunks/src/ResMan.cpp 2006-07-25 09:59:46 UTC (rev 48) @@ -0,0 +1,97 @@ +#include "ResMan.h" + +#include "boost/filesystem/operations.hpp" // includes boost/filesystem/path.hpp +#include "boost/filesystem/fstream.hpp" // ditto +namespace bfs = boost::filesystem; + +DIRResource::DIRResource(bfs::path path) +{ + m_path = path; +}; + +long DIRResource::readFile(bfs::path path, char* buf) +{ + bfs::path fullpath = m_path + path; + + FILE file (fullpath.c_str(), "rb"); + fseek(file, 0, SEEK_END); + long filesize = ftell; + + fseek(file, 0, SEEK_SET); + + buf = new char[filesize]; + + fread(buf, filesize, 1, file); + + fclose(file); + + return filesize; +}; + +// ------------------------------------------------------------------ + +PAKResource::PAKResource(bfs::path path) +{ + m_path = path; + m_pakfile = Pakfile(path.c_str()); +}; + +PAKResource::~PAKResource() +{ + delete m_pakfile; +}; + +long PAKResource::readFile(bfs::path path, char* buf) +{ + long filesize; + buf = m_pakfile->getFile(path.c_str(), &filesize); + return filesize; +}; + +// ------------------------------------------------------------------ + +ResMan::ResMan() +{ + +}; + +ResMan::~ResMan() +{ + ResList::iterator it; + for (it = m_resources.begin(); + it != m_resources.end(); + ++it) + { + delete *it; + }; + + m_resources.clear(); +}; + +bool ResMan::addRes(const char* name) +{ + bfs::path file (name); + Resource *res = NULL; + + if (bfs::is_directory(file)) + { + res = DIRResource(file); + } + else + { + res = PAKResource(file); + }; + + // this isnt going to work.. + if (res == NULL) + { + return false; + }; + + m_resources[fn] = res; + + return true; +}; + + + Modified: branches/dunks/src/SConscript =================================================================== --- branches/dunks/src/SConscript 2006-07-25 06:24:26 UTC (rev 47) +++ branches/dunks/src/SConscript 2006-07-25 09:59:46 UTC (rev 48) @@ -22,6 +22,8 @@ "MainMenu.cpp", "SingleMenu.cpp", + "ResMan.cpp", + "gui2/Widget.cpp", "gui2/Container.cpp", "gui2/Button.cpp", Modified: branches/dunks/src/pakfile/Decode.cpp =================================================================== --- branches/dunks/src/pakfile/Decode.cpp 2006-07-25 06:24:26 UTC (rev 47) +++ branches/dunks/src/pakfile/Decode.cpp 2006-07-25 09:59:46 UTC (rev 48) @@ -24,17 +24,17 @@ unsigned char *readp = image_in; unsigned char *writep = image_out; - uint a = 0; - uint b = 0; - uint c = 0; - uint d = 0; - uint e = 0; -// uint relposcount = 0; - uint megacounta = 0; - uint megacountb = 0; - uint megacountc = 0; - uint megacountd = 0; - uint megacounte = 0; + Uint16 a = 0; + Uint16 b = 0; + Uint16 c = 0; + Uint16 d = 0; + Uint16 e = 0; +// Uint16 relposcount = 0; + Uint16 megacounta = 0; + Uint16 megacountb = 0; + Uint16 megacountc = 0; + Uint16 megacountd = 0; + Uint16 megacounte = 0; /* 1 10cccccc 2 0cccpppp p @@ -165,7 +165,7 @@ void Decode::apply_pal_offsets(unsigned char *offsets, unsigned char *data,unsigned int length) { - uint i; + Uint16 i; for (i = 0; i < length; i ++) data[i] = offsets[data[i]]; }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dun...@us...> - 2006-07-25 06:24:47
|
Revision: 47 Author: dunkfordyce Date: 2006-07-24 23:24:26 -0700 (Mon, 24 Jul 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=47&view=rev Log Message: ----------- included pakfile Modified Paths: -------------- branches/dunks/SConstruct branches/dunks/src/Application.cpp branches/dunks/src/SConscript Added Paths: ----------- branches/dunks/config.py.example branches/dunks/include/pakfile/ branches/dunks/include/pakfile/Cpsfile.h branches/dunks/include/pakfile/Decode.h branches/dunks/include/pakfile/Icnfile.h branches/dunks/include/pakfile/Pakfile.h branches/dunks/include/pakfile/Shpfile.h branches/dunks/include/pakfile/Wsafile.h branches/dunks/src/pakfile/ branches/dunks/src/pakfile/Cpsfile.cpp branches/dunks/src/pakfile/Decode.cpp branches/dunks/src/pakfile/Icnfile.cpp branches/dunks/src/pakfile/Pakfile.cpp branches/dunks/src/pakfile/SConscript branches/dunks/src/pakfile/Shpfile.cpp branches/dunks/src/pakfile/Wsafile.cpp branches/dunks/src/pakfile/main.cpp Removed Paths: ------------- branches/dunks/config.py Modified: branches/dunks/SConstruct =================================================================== --- branches/dunks/SConstruct 2006-07-24 22:30:32 UTC (rev 46) +++ branches/dunks/SConstruct 2006-07-25 06:24:26 UTC (rev 47) @@ -25,8 +25,9 @@ if sys.platform != "win32": env.ParseConfig('sdl-config --cflags --libs') env.ParseConfig('pkg-config --cflags --libs zziplib') - env.Append(CCFLAGS=["-Wall", "-Werror", "-O2", "-ffast-math", "-funroll-loops"]) - env.Append(LINKFLAGS = ["-ffast-math", "-lboost_signals"]) + env.Append(CCFLAGS=["-Wall"]) #, "-Werror"]) + #env.Append(CCFLAGS=["-Wall", "-Werror", "-O2", "-ffast-math", "-funroll-loops"]) + #env.Append(LINKFLAGS = ["-ffast-math"]) if 1: env.Append(CCFLAGS=["-ggdb"]) @@ -40,6 +41,7 @@ "SDL_image", "SDL_net", "SDL_ttf", + "boost_signals", ]) env.Append(CPPPATH = [ "${SDL_INCLUDE_PATH}", Deleted: branches/dunks/config.py =================================================================== --- branches/dunks/config.py 2006-07-24 22:30:32 UTC (rev 46) +++ branches/dunks/config.py 2006-07-25 06:24:26 UTC (rev 47) @@ -1,8 +0,0 @@ -SDL_INCLUDE_PATH = r"E:\projects\include\SDL\SDL-1.2.11\include" -SDL_LIB_PATH = r"E:\projects\include\SDL\SDL-1.2.11\lib" -ZLIB_INCLUDE_PATH = r"E:\projects\include\zlib123-dll\include" -ZLIB_LIB_PATH = r"E:\projects\include\zlib123-dll\lib" -ZZIP_INCLUDE_PATH = "E:\projects\include\zziplib-0.10.82-msvc6-lib\include" -ZZIP_LIB_PATH = "E:\projects\include\zziplib-0.10.82-msvc6-lib\lib" -BOOST_INCLUDE_PATH = r"C:\Boost\include\boost-1_33_1" -BOOST_LIB_PATH = r"C:\Boost\lib" Copied: branches/dunks/config.py.example (from rev 21, branches/dunks/config.py) =================================================================== --- branches/dunks/config.py.example (rev 0) +++ branches/dunks/config.py.example 2006-07-25 06:24:26 UTC (rev 47) @@ -0,0 +1,6 @@ +SDL_INCLUDE_PATH = r"E:\projects\include\SDL\SDL-1.2.11\include" +SDL_LIB_PATH = r"E:\projects\include\SDL\SDL-1.2.11\lib" +ZLIB_INCLUDE_PATH = r"E:\projects\include\zlib123-dll\include" +ZLIB_LIB_PATH = r"E:\projects\include\zlib123-dll\lib" +ZZIP_INCLUDE_PATH = "E:\projects\include\zziplib-0.10.82-msvc6-lib\include" +ZZIP_LIB_PATH = "E:\projects\include\zziplib-0.10.82-msvc6-lib\lib" Added: branches/dunks/include/pakfile/Cpsfile.h =================================================================== --- branches/dunks/include/pakfile/Cpsfile.h (rev 0) +++ branches/dunks/include/pakfile/Cpsfile.h 2006-07-25 06:24:26 UTC (rev 47) @@ -0,0 +1,21 @@ +#ifndef CPSFILE_H_INCLUDED +#define CPSFILE_H_INCLUDED + +#include "pakfile/Decode.h" +#include "SDL.h" + +class Cpsfile : public Decode +{ +public: + Cpsfile(unsigned char * bufFiledata, int bufsize); + ~Cpsfile(); + + + SDL_Surface * getPicture(); + +private: + unsigned char* Filedata; + Uint32 CpsFilesize; +}; + +#endif // CPSFILE_H_INCLUDED Added: branches/dunks/include/pakfile/Decode.h =================================================================== --- branches/dunks/include/pakfile/Decode.h (rev 0) +++ branches/dunks/include/pakfile/Decode.h 2006-07-25 06:24:26 UTC (rev 47) @@ -0,0 +1,19 @@ +#ifndef DECODE_H_INCLUDED +#define DECODE_H_INCLUDED + +class Decode +{ +public: + Decode(); + ~Decode(); + +protected: + + int decode80(unsigned char *image_in, unsigned char *image_out,unsigned checksum); + void my_memcpy(unsigned char *dst, unsigned char *src, unsigned cnt); + void shp_correct_lf(unsigned char *in, unsigned char *out, int size); + void apply_pal_offsets(unsigned char *offsets, unsigned char *data,unsigned int length); + int decode40(unsigned char *image_in, unsigned char *image_out); +}; + +#endif // DECODE_H_INCLUDED Added: branches/dunks/include/pakfile/Icnfile.h =================================================================== --- branches/dunks/include/pakfile/Icnfile.h (rev 0) +++ branches/dunks/include/pakfile/Icnfile.h 2006-07-25 06:24:26 UTC (rev 47) @@ -0,0 +1,32 @@ +#ifndef ICNFILE_H_INCLUDED +#define ICNFILE_H_INCLUDED + +#include "SDL.h" + +class Icnfile +{ +public: + Icnfile(unsigned char * bufFiledata, int bufsize); + ~Icnfile(); + + + SDL_Surface * getPicture(Uint32 IndexOfFile); + + int getNumFiles(); + +private: + unsigned char* Filedata; + Uint32 IcnFilesize; + + Uint32 NumFiles; + + unsigned char* SSET; + Uint32 SSET_Length; + unsigned char* RPAL; + Uint32 RPAL_Length; + unsigned char* RTBL; + Uint32 RTBL_Length; + +}; + +#endif // ICNFILE_H_INCLUDED Added: branches/dunks/include/pakfile/Pakfile.h =================================================================== --- branches/dunks/include/pakfile/Pakfile.h (rev 0) +++ branches/dunks/include/pakfile/Pakfile.h 2006-07-25 06:24:26 UTC (rev 47) @@ -0,0 +1,35 @@ +#ifndef PAKFILE_H_INCLUDED +#define PAKFILE_H_INCLUDED + +#include <stdio.h> + +struct PakFileEntry { + long StartOffset; + long EndOffset; + char * Filename; +}; + +class Pakfile +{ +public: + Pakfile(char * Pakfilename); + ~Pakfile(); + + char * getFilename(int index); + + unsigned char *getFile(char *fname, int *size); + + inline int getNumFiles() {return NumFileEntry;}; + +private: + + void readIndex(); + + FILE * fPakFile; + char * Filename; + + PakFileEntry *FileEntry; + int NumFileEntry; +}; + +#endif // PAKFILE_H_INCLUDED Added: branches/dunks/include/pakfile/Shpfile.h =================================================================== --- branches/dunks/include/pakfile/Shpfile.h (rev 0) +++ branches/dunks/include/pakfile/Shpfile.h 2006-07-25 06:24:26 UTC (rev 47) @@ -0,0 +1,33 @@ +#ifndef SHPFILE_H_INCLUDED +#define SHPFILE_H_INCLUDED + +#include "SDL.h" +#include "pakfile/Decode.h" + +struct ShpfileEntry +{ + Uint32 StartOffset; + Uint32 EndOffset; +}; + +class Shpfile : public Decode +{ +public: + Shpfile(unsigned char * bufFiledata, int bufsize); + ~Shpfile(); + + SDL_Surface* getPicture(Uint32 IndexOfFile); + + inline int getNumFiles() {return (int) NumFiles;}; + +private: + void readIndex(); + + ShpfileEntry * Index; + unsigned char* Filedata; + Uint32 ShpFilesize; + Uint16 NumFiles; +}; + + +#endif //SHPFILE_H_INCLUDED Added: branches/dunks/include/pakfile/Wsafile.h =================================================================== --- branches/dunks/include/pakfile/Wsafile.h (rev 0) +++ branches/dunks/include/pakfile/Wsafile.h 2006-07-25 06:24:26 UTC (rev 47) @@ -0,0 +1,36 @@ +#ifndef WSAFILE_H_INCLUDED +#define WSAFILE_H_INCLUDED + +#include "pakfile/Decode.h" +#include "SDL.h" + +//extern SDL_Palette* palette; + +class Wsafile : public Decode +{ +public: + Wsafile(unsigned char * bufFiledata, int bufsize); + ~Wsafile(); + + SDL_Surface * getPicture(Uint32 FrameNumber); + + inline int getNumFrames() { return (int) NumFrames; }; + inline Uint32 getFramesPer1024ms() { return FramesPer1024ms; }; + +private: + void decodeFrames(); + + unsigned char *decodedFrames; + + + unsigned char* Filedata; + Uint32* Index; + Uint32 WsaFilesize; + + Uint16 NumFrames; + Uint16 SizeX; + Uint16 SizeY; + Uint32 FramesPer1024ms; +}; + +#endif // WSAFILE_H_INCLUDED Modified: branches/dunks/src/Application.cpp =================================================================== --- branches/dunks/src/Application.cpp 2006-07-24 22:30:32 UTC (rev 46) +++ branches/dunks/src/Application.cpp 2006-07-25 06:24:26 UTC (rev 47) @@ -25,6 +25,8 @@ #include "MainMenu.h" #include "DataFile.h" +#include "pakfile/Pakfile.h" + #define SCREEN_BPP 8 #define VERSION "0.94.1" @@ -100,8 +102,7 @@ //mutex_currentWidget = SDL_CreateMutex(); //mutex_playersJoined = SDL_CreateMutex(); - //LoadData(); - loadDataFile(); + LoadData(); m_rootWidget = new Container(); @@ -220,6 +221,18 @@ void Application::LoadData() { + 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(); @@ -293,9 +306,9 @@ float dt = float(now - then) / 1000.0f; - if (m_rootState->Execute(dt) == -1) m_running = false; + //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); Modified: branches/dunks/src/SConscript =================================================================== --- branches/dunks/src/SConscript 2006-07-24 22:30:32 UTC (rev 46) +++ branches/dunks/src/SConscript 2006-07-25 06:24:26 UTC (rev 47) @@ -26,7 +26,14 @@ "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", ] Added: branches/dunks/src/pakfile/Cpsfile.cpp =================================================================== --- branches/dunks/src/pakfile/Cpsfile.cpp (rev 0) +++ branches/dunks/src/pakfile/Cpsfile.cpp 2006-07-25 06:24:26 UTC (rev 47) @@ -0,0 +1,64 @@ +#include "pakfile/Cpsfile.h" +#include <SDL_endian.h> +#include <stdlib.h> +#include <string.h> + +#define SIZE_X 320 +#define SIZE_Y 240 + +//extern SDL_Palette* palette; + +Cpsfile::Cpsfile(unsigned char * bufFiledata, int bufsize) : Decode() +{ + Filedata = bufFiledata; + CpsFilesize = bufsize; +} + +Cpsfile::~Cpsfile() +{ + ; +}; + +SDL_Surface* Cpsfile::getPicture() +{ + unsigned char * ImageOut; + SDL_Surface *pic = NULL; + + // check for valid file + if( SDL_SwapLE16(*(unsigned short *)(Filedata + 2)) != 0x0004) { + return NULL; + } + + if( SDL_SwapLE16(*(unsigned short *)(Filedata + 4)) != 0xFA00) { + return NULL; + } + + Uint16 PaletteSize = SDL_SwapLE16(*((unsigned short *)(Filedata + 8))); + + if( (ImageOut = (unsigned char*) calloc(1,SIZE_X*SIZE_Y)) == NULL) { + return NULL; + } + + if(decode80(Filedata + 10 + PaletteSize,ImageOut,0) == -2) { + fprintf(stderr,"Error: Cannot decode Cps-File\n"); + } + + // create new picture surface + 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_LockSurface(pic); + + //Now we can copy line by line + for(int y = 0; y < SIZE_Y;y++) { + memcpy( ((char*) (pic->pixels)) + y * pic->pitch , ImageOut + y * SIZE_X, SIZE_X); + } + + SDL_UnlockSurface(pic); + + free(ImageOut); + + return pic; +}; Added: branches/dunks/src/pakfile/Decode.cpp =================================================================== --- branches/dunks/src/pakfile/Decode.cpp (rev 0) +++ branches/dunks/src/pakfile/Decode.cpp 2006-07-25 06:24:26 UTC (rev 47) @@ -0,0 +1,257 @@ +#include "pakfile/Decode.h" +#include <SDL_endian.h> +#include <stdlib.h> +#include <string.h> + +#include <SDL.h> + +Decode::Decode() +{ + ; +} + +Decode::~Decode() +{ + ; +}; + +int Decode::decode80(unsigned char *image_in, unsigned char *image_out,unsigned checksum) +{ + // + // should decode all the format80 stuff ;-) + // + + unsigned char *readp = image_in; + unsigned char *writep = image_out; + + uint a = 0; + uint b = 0; + uint c = 0; + uint d = 0; + uint e = 0; +// uint relposcount = 0; + uint megacounta = 0; + uint megacountb = 0; + uint megacountc = 0; + uint megacountd = 0; + uint megacounte = 0; + /* + 1 10cccccc + 2 0cccpppp p + 3 11cccccc p p + 4 11111110 c c v + 5 11111111 c c p p + */ + + while (1) { + if ((*readp & 0xc0) == 0x80) { + // + // 10cccccc (1) + // + unsigned count = readp[0] & 0x3f; + //printf("Cmd 1, count: %d\n", count); + megacounta += count; + if (!count) { +//#ifdef DEBUG +// pinfo80(); +//#endif + break; + } + readp++; + my_memcpy(writep, readp, count); + readp += count; + writep += count; + a++; + } else if ((*readp & 0x80) == 0x00) { + // + // 0cccpppp p (2) + // + unsigned count = ((readp[0] & 0x70) >> 4) + 3; + unsigned short relpos = (((unsigned short) (readp[0] & 0xf)) << 8) | ((unsigned short) readp[1]); + //printf("Cmd 2, count: %d, relpos: %d\n", count, relpos); + readp += 2; + megacountb += count; + my_memcpy(writep, writep - relpos, count); + writep += count; + b++; + } else if (*readp == 0xff) { + // + // 11111111 c c p p (5) + // + unsigned short count = SDL_SwapLE16(*((unsigned short *) (readp + 1))); + unsigned short pos = SDL_SwapLE16(*((unsigned short *) (readp + 3))); + //printf("Cmd 5, count: %d, pos: %d\n", count, pos); + readp += 5; + megacounte += count; + my_memcpy(writep, image_out + pos, count); + writep += count; + e++; + } else if (*readp == 0xfe) { + // + // 11111110 c c v(4) + // + unsigned short count = SDL_SwapLE16(*((unsigned short *) (readp + 1))); + unsigned char color = readp[3]; + //printf("Cmd 4, count: %d, color: %d\n", count, color); + readp += 4; + memset(writep, color, count); + writep += count; + megacountd += count; + d++; + } else if ((*readp & 0xc0) == 0xc0) { + // + // 11cccccc p p (3) + // + + unsigned short count = (*readp & 0x3f) + 3; + unsigned short pos = SDL_SwapLE16(*((unsigned short *) (readp + 1))); + //printf("Cmd 3, count: %d, pos: %d\n", count, pos); + readp += 3; + megacountc += count; + my_memcpy(writep, image_out + pos, count); + writep += count; + c++; + } else { + fprintf(stderr,"file contains unknown format80 command: %x\n",*readp); + exit(EXIT_FAILURE); + } + } + if (megacounta + megacountb + megacountc + megacountd + megacounte + != checksum) + return -1; + return 0; +} + +void Decode::my_memcpy(unsigned char *dst, unsigned char *src, unsigned cnt) +{ + /* Copies memory areas that may overlap byte by byte from small memory + * addresses to big memory addresses. Thus, already copied bytes can be + * copied again. */ + if (dst + cnt < src || src + cnt < dst) { + memcpy(dst, src, cnt); + return; + } + while (cnt--) { + *dst = *src; + dst++; + src++; + } +} + +void Decode::shp_correct_lf(unsigned char *in, unsigned char *out, int size) +{ + unsigned char *end = in + size; + while (in < end) { + unsigned char val = *in; + in++; + + if (val != 0) { + *out = val; + out++; + } else { + unsigned char count; + count = *in; + in++; + if (count == 0) { + return; + } + memset(out, 0, count); + + out += count; + } + } +}; + + +void Decode::apply_pal_offsets(unsigned char *offsets, unsigned char *data,unsigned int length) +{ + uint i; + for (i = 0; i < length; i ++) + data[i] = offsets[data[i]]; +}; + +int Decode::decode40(unsigned char *image_in, unsigned char *image_out) +{ + /* + 0 fill 00000000 c v + 1 copy 0ccccccc + 2 skip 10000000 c 0ccccccc + 3 copy 10000000 c 10cccccc + 4 fill 10000000 c 11cccccc v + 5 skip 1ccccccc + */ + + const unsigned char* readp = image_in; + unsigned char* writep = image_out; + Uint16 code; + Uint16 count; + while (1) + { + code = *readp++; + if (~code & 0x80) + { + //bit 7 = 0 + if (!code) + { + //command 0 (00000000 c v): fill + count = *readp++; + code = *readp++; + while (count--) + *writep++ ^= code; + } + else + { + //command 1 (0ccccccc): copy + count = code; + while (count--) + *writep++ ^= *readp++; + } + + } + else + { + //bit 7 = 1 + if (!(count = code & 0x7f)) + { + count = SDL_SwapLE16(*((Uint16*)readp)); + readp += 2; + code = count >> 8; + if (~code & 0x80) + { + //bit 7 = 0 + //command 2 (10000000 c 0ccccccc): skip + if (!count) + // end of image + break; + writep += count; + } + else + { + //bit 7 = 1 + count &= 0x3fff; + if (~code & 0x40) + { + //bit 6 = 0 + //command 3 (10000000 c 10cccccc): copy + while (count--) + *writep++ ^= *readp++; + } + else + { + //bit 6 = 1 + //command 4 (10000000 c 11cccccc v): fill + code = *readp++; + while (count--) + *writep++ ^= code; + } + } + } + else + { + //command 5 (1ccccccc): skip + writep += count; + } + } + } + return (writep - image_out); +}; Added: branches/dunks/src/pakfile/Icnfile.cpp =================================================================== --- branches/dunks/src/pakfile/Icnfile.cpp (rev 0) +++ branches/dunks/src/pakfile/Icnfile.cpp 2006-07-25 06:24:26 UTC (rev 47) @@ -0,0 +1,151 @@ +#include "pakfile/Icnfile.h" + +#include <SDL_endian.h> +#include <stdlib.h> +#include <string.h> + +#define SIZE_X 16 +#define SIZE_Y 16 + +//extern SDL_Palette* palette; + + +Icnfile::Icnfile(unsigned char * bufFiledata, int bufsize) +{ + Filedata = bufFiledata; + IcnFilesize = bufsize; + + + // check if we can access first section; + if(IcnFilesize < 0x20) { + fprintf(stderr, "ERROR: Invalid ICN-File: No SSET-Section found!\n"); + exit(EXIT_FAILURE); + } + + + SSET = Filedata+0x18; + + // check SSET-Section + if( (SSET[0] != 'S') + || (SSET[1] != 'S') + || (SSET[2] != 'E') + || (SSET[3] != 'T')) { + fprintf(stderr, "ERROR: Invalid ICN-File: No SSET-Section found!\n"); + exit(EXIT_FAILURE); + } + + SSET_Length = SDL_SwapBE32( *((Uint32*) (SSET + 4))) - 8; + + SSET += 16; + + if(Filedata + IcnFilesize < SSET + SSET_Length) { + fprintf(stderr, "ERROR: Invalid ICN-File: SSET-Section is bigger than ICN-File!\n"); + exit(EXIT_FAILURE); + } + + RPAL = SSET + SSET_Length; + + // check RPAL-Section + if( (RPAL[0] != 'R') + || (RPAL[1] != 'P') + || (RPAL[2] != 'A') + || (RPAL[3] != 'L')) { + fprintf(stderr, "ERROR: Invalid ICN-File: No RPAL-Section found!\n"); + exit(EXIT_FAILURE); + } + + RPAL_Length = SDL_SwapBE32( *((Uint32*) (RPAL + 4))); + + RPAL += 8; + + if(Filedata + IcnFilesize < RPAL + RPAL_Length) { + fprintf(stderr, "ERROR: Invalid ICN-File: RPAL-Section is bigger than ICN-File!\n"); + exit(EXIT_FAILURE); + } + + RTBL = RPAL + RPAL_Length; + + // check RTBL-Section + if( (RTBL[0] != 'R') + || (RTBL[1] != 'T') + || (RTBL[2] != 'B') + || (RTBL[3] != 'L')) { + fprintf(stderr, "ERROR: Invalid ICN-File: No RTBL-Section found!\n"); + exit(EXIT_FAILURE); + } + + + + RTBL_Length = SDL_SwapBE32( *((Uint32*) (RTBL + 4))); + + RTBL += 8; + + if(Filedata + IcnFilesize < RTBL + RTBL_Length) { + fprintf(stderr, "ERROR: Invalid ICN-File: RTBL-Section is bigger than ICN-File!\n"); + exit(EXIT_FAILURE); + } + + NumFiles = SSET_Length / ((SIZE_X * SIZE_Y) / 2); + + if(RTBL_Length < NumFiles) { + fprintf(stderr, "ERROR: Invalid ICN-File: RTBL-Section is too small!\n"); + exit(EXIT_FAILURE); + } +} + +Icnfile::~Icnfile() +{ + ; +}; + +SDL_Surface* Icnfile::getPicture(Uint32 IndexOfFile) { + SDL_Surface * pic; + + if(IndexOfFile >= NumFiles) { + return NULL; + } + + // check if palette is in range + if(RTBL[IndexOfFile] >= RPAL_Length / 16) { + return NULL; + } + + unsigned char* palettestart = RPAL + (16 * RTBL[IndexOfFile]); + + unsigned char * filestart = SSET + (IndexOfFile * ((SIZE_X * SIZE_Y)/2)); + + // create new picture surface + 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_LockSurface(pic); + + //Now we can copy to surface + unsigned char *dest = (unsigned char*) (pic->pixels); + unsigned char pixel; + for(int y = 0; y < SIZE_Y;y++) { + for(int x = 0; x < SIZE_X; x+=2) { + pixel = filestart[ (y*SIZE_X + x) / 2]; + pixel = pixel >> 4; + dest[x] = palettestart[pixel]; + + pixel = filestart[ (y*SIZE_X + x) / 2]; + pixel = pixel & 0x0F; + dest[x+1] = palettestart[pixel]; + } + dest += pic->pitch; + } + + SDL_UnlockSurface(pic); + + printf("File Nr.: %d (Size: %dx%d)\n",IndexOfFile,SIZE_X,SIZE_Y); + + return pic; +}; + +int Icnfile::getNumFiles() +{ + return NumFiles; +}; Added: branches/dunks/src/pakfile/Pakfile.cpp =================================================================== --- branches/dunks/src/pakfile/Pakfile.cpp (rev 0) +++ branches/dunks/src/pakfile/Pakfile.cpp 2006-07-25 06:24:26 UTC (rev 47) @@ -0,0 +1,163 @@ +#include "pakfile/Pakfile.h" +#include <stdlib.h> +#include <string.h> +#include <SDL_endian.h> + +Pakfile::Pakfile(char *Pakfilename) +{ + FileEntry = NULL; + NumFileEntry = 0; + + if(Pakfilename == NULL) { + fprintf(stderr,"Pakfile::Pakfile(): Pakfilename == NULL\n"); + exit(EXIT_FAILURE); + } + + if((Filename = (char*) malloc(strlen(Pakfilename)+1)) == NULL) { + perror("Pakfile::Pakfile()"); + exit(EXIT_FAILURE); + } + + strcpy(Filename,Pakfilename); + + if( (fPakFile = fopen(Filename, "rb")) == NULL) { + perror("Pakfile::Pakfile()"); + exit(EXIT_FAILURE); + } + + readIndex(); +}; + +Pakfile::~Pakfile() +{ + if(fPakFile != NULL) { + fclose(fPakFile); + } + + for(int i=0;i<NumFileEntry;i++) { + free(FileEntry[i].Filename); + } + + free(FileEntry); +}; + +void Pakfile::readIndex() +{ + int i; + int startoffset; + char name[256]; + + + while(1) { + if(fread((void*) &startoffset, 4, 1,fPakFile) != 1) { + perror("fread()"); + exit(EXIT_FAILURE); + } + + //pak-files are always little endian encoded + startoffset = SDL_SwapLE32(startoffset); + + + if(startoffset == 0) { + break; + } + + if((FileEntry = (PakFileEntry*) realloc(FileEntry,(NumFileEntry+1) * sizeof(PakFileEntry))) == NULL) { + perror("realloc()"); + exit(EXIT_FAILURE); + } + + FileEntry[NumFileEntry].StartOffset = startoffset; + + i = 0; + while(1) { + if(fread(&name[i],1,1,fPakFile) != 1) { + perror("fread()"); + exit(EXIT_FAILURE); + } + + i++; + + if(name[i-1] == '\0') { + break; + } + + if(i >= 256) { + fprintf(stderr,"Pakfile::readIndex(): Filename in Pakfile too long\n"); + exit(EXIT_FAILURE); + } + } + + if((FileEntry[NumFileEntry].Filename = (char *) malloc(i)) == NULL) { + perror("malloc()"); + exit(EXIT_FAILURE); + } + + strcpy(FileEntry[NumFileEntry].Filename,name); + + if(NumFileEntry > 0) { + FileEntry[NumFileEntry - 1].EndOffset = startoffset - 1; + } + + NumFileEntry++; + } + + if(fseek(fPakFile,0,SEEK_END) != 0) { + perror("fseek()"); + exit(EXIT_FAILURE); + } + + if((FileEntry[NumFileEntry-1].EndOffset = (ftell(fPakFile) - 1)) < 0) { + perror("ftell()"); + exit(EXIT_FAILURE); + } +}; + +char * Pakfile::getFilename(int index) { + if((index >= NumFileEntry) || (index < 0)) + return NULL; + + return FileEntry[index].Filename; +}; + +unsigned char *Pakfile::getFile(char *fname, int *size) +{ + int Index = -1; + + for(int i=0;i<NumFileEntry;i++) { + if(strcmp(FileEntry[i].Filename,fname) == 0) { + Index = i; + break; + } + } + + if(Index == -1) { + return NULL; + } + + int filesize = FileEntry[Index].EndOffset - FileEntry[Index].StartOffset + 1; + + if(filesize == 0) { + return NULL; + } + + unsigned char * content; + + if( (content = (unsigned char*) malloc(filesize)) == NULL) { + return NULL; + } + + if(fseek(fPakFile,FileEntry[Index].StartOffset,SEEK_SET) != 0) { + return NULL; + } + + if(fread(content,filesize,1,fPakFile) != 1) { + return NULL; + } + + if(size != NULL) { + *size = filesize; + } + + return content; +}; Added: branches/dunks/src/pakfile/SConscript =================================================================== --- branches/dunks/src/pakfile/SConscript (rev 0) +++ branches/dunks/src/pakfile/SConscript 2006-07-25 06:24:26 UTC (rev 47) @@ -0,0 +1,44 @@ +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 += [env.Object('SDL_rwops_zzip.c')] + +env.Program("../dunelegacy", all_sources) + + Added: branches/dunks/src/pakfile/Shpfile.cpp =================================================================== --- branches/dunks/src/pakfile/Shpfile.cpp (rev 0) +++ branches/dunks/src/pakfile/Shpfile.cpp 2006-07-25 06:24:26 UTC (rev 47) @@ -0,0 +1,198 @@ + +#include "pakfile/Shpfile.h" +#include <SDL_endian.h> +#include <stdlib.h> +#include <string.h> + +//extern SDL_Palette* palette; + +Shpfile::Shpfile(unsigned char * bufFiledata, int bufsize) : Decode() +{ + Filedata = bufFiledata; + ShpFilesize = bufsize; + Index = NULL; + readIndex(); +}; + +Shpfile::~Shpfile() +{ + if(Index != NULL) { + free(Index); + } +}; + +SDL_Surface *Shpfile::getPicture(Uint32 IndexOfFile) +{ + SDL_Surface *pic = NULL; + unsigned char *DecodeDestination = NULL; + unsigned char *ImageOut = NULL; + + if(IndexOfFile >= NumFiles) { + return NULL; + } + + unsigned char * Fileheader = Filedata + Index[IndexOfFile].StartOffset; + + unsigned char type = Fileheader[0]; + + unsigned char sizeY = Fileheader[2]; + unsigned char sizeX = Fileheader[3]; + + /* size and also checksum */ + Uint16 size = SDL_SwapLE16(*((Uint16*) (Fileheader + 8))); + + + printf("File Nr.: %d (Size: %dx%d)\n",IndexOfFile,sizeX,sizeY); + /* + printf("Type: %d\n",type); + printf("SizeX: %d SizeY: %d\n",sizeX,sizeY); + printf("Size: %d Filesize: %d\n",size,Index[IndexOfFile].EndOffset-Index[IndexOfFile].StartOffset); + fflush(stdout); + */ + + if((ImageOut = (unsigned char*) calloc(1,sizeX*sizeY)) == NULL) { + return NULL; + } + + switch(type) { + + case 0: + { + if( (DecodeDestination = (unsigned char*) calloc(1,size)) == NULL) { + free(ImageOut); + return NULL; + } + + if(decode80(Fileheader + 10,DecodeDestination,size) == -1) { + fprintf(stderr,"Warning: Checksum-Error in Shp-File\n"); + } + + shp_correct_lf(DecodeDestination,ImageOut, size); + + free(DecodeDestination); + } break; + + case 1: + { + if( (DecodeDestination = (unsigned char*) calloc(1,size)) == NULL) { + free(ImageOut); + return NULL; + } + + if(decode80(Fileheader + 10 + 16,DecodeDestination,size) == -1) { + fprintf(stderr,"Warning: Checksum-Error in Shp-File\n"); + } + + shp_correct_lf(DecodeDestination, ImageOut, size); + + apply_pal_offsets(Fileheader + 10,ImageOut,sizeX*sizeY); + + free(DecodeDestination); + } break; + + case 2: + { + shp_correct_lf(Fileheader+10, ImageOut,size); + } break; + + case 3: + { + + shp_correct_lf(Fileheader + 10 + 16, ImageOut,size); + + apply_pal_offsets(Fileheader + 10,ImageOut,sizeX*sizeY); + } break; + + default: + { + fprintf(stderr,"Error: Type %d in SHP-Files not supported!\n",type); + exit(EXIT_FAILURE); + } + } + + // create new picture surface + if((pic = SDL_CreateRGBSurface(SDL_SWSURFACE,sizeX,sizeY,8,0,0,0,0))== NULL) { + return NULL; + } + + //SDL_SetColors(pic, palette->colors, 0, palette->ncolors); + SDL_LockSurface(pic); + + //Now we can copy line by line + for(int y = 0; y < sizeY;y++) { + memcpy( ((char*) (pic->pixels)) + y * pic->pitch , ImageOut + y * sizeX, sizeX); + } + + SDL_UnlockSurface(pic); + + if(ImageOut != NULL) { + free(ImageOut); + } + + return pic; +}; + +void Shpfile::readIndex() +{ + // First get number of files in shp-file + NumFiles = SDL_SwapLE16( ((Uint16*) Filedata)[0]); + + if(NumFiles == 0) { + fprintf(stderr, "Error: There is no file in this shp-File!\n"); + exit(EXIT_FAILURE); + } + + if(NumFiles == 1) { + /* files with only one image might be different */ + + // create array with one entry + if((Index = (ShpfileEntry*) malloc(sizeof(ShpfileEntry) * 1)) == NULL) { + perror("Shpfile::readIndex"); + exit(EXIT_FAILURE); + } + + if (((Uint16*) Filedata)[2] != 0) { + /* File has special header with only 2 byte offset */ + + Index[0].StartOffset = ((Uint32) SDL_SwapLE16(((Uint16*) Filedata)[1])); + Index[0].EndOffset = ((Uint32) SDL_SwapLE16(((Uint16*) Filedata)[2])) - 1; + + + } else { + /* File has normal 4 byte offsets */ + Index[0].StartOffset = ((Uint32) SDL_SwapLE32(*((Uint32*) (Filedata+2)))) + 2; + Index[0].EndOffset = ((Uint32) SDL_SwapLE16(((Uint16*) Filedata)[3])) - 1 + 2; + } + + } else { + /* File contains more than one image */ + + if( ShpFilesize < (Uint32) ((NumFiles * 4) + 2 + 2)) { + fprintf(stderr, "Error:Shp-File-Header is not complete! Header should be %d bytes big, but Shp-File is only %d bytes long.\n",(NumFiles * 4) + 2 + 2,ShpFilesize); + exit(EXIT_FAILURE); + } + + // create array + if((Index = (ShpfileEntry*) malloc(sizeof(ShpfileEntry) * NumFiles)) == NULL) { + perror("Shpfile::readIndex"); + exit(EXIT_FAILURE); + } + + // now fill Index with start and end-offsets + for(int i = 0; i < NumFiles; i++) { + Index[i].StartOffset = SDL_SwapLE32( ((Uint32*)(Filedata+2))[i]) + 2; + + if(i > 0) { + Index[i-1].EndOffset = Index[i].StartOffset - 1; + + if(Index[i-1].EndOffset > ShpFilesize) { + fprintf(stderr, "Error:The File with Index %d, goes until byte %d, but this SHP-File is only %d bytes big.\n",i,Index[i-1].EndOffset,ShpFilesize); + exit(EXIT_FAILURE); + } + } + } + + // Add the EndOffset for the last file + Index[NumFiles-1].EndOffset = ((Uint32) SDL_SwapLE16( *((Uint16*) (Filedata + 2 + (NumFiles * 4))))) - 1 + 2; + } +}; Added: branches/dunks/src/pakfile/Wsafile.cpp =================================================================== --- branches/dunks/src/pakfile/Wsafile.cpp (rev 0) +++ branches/dunks/src/pakfile/Wsafile.cpp 2006-07-25 06:24:26 UTC (rev 47) @@ -0,0 +1,101 @@ +#include "pakfile/Wsafile.h" +#include <SDL_endian.h> +#include <stdlib.h> +#include <string.h> + +Wsafile::Wsafile(unsigned char * bufFiledata, int bufsize) : Decode() +{ + Filedata = bufFiledata; + WsaFilesize = bufsize; + + if(WsaFilesize < 10) { + fprintf(stderr, "Error: No valid WSA-File: File too small!\n"); + exit(EXIT_FAILURE); + } + + NumFrames = SDL_SwapLE16(*((Uint16*) Filedata) ); + SizeX = SDL_SwapLE16(*((Uint16*) (Filedata + 2)) ); + SizeY = SDL_SwapLE16(*((Uint16*) (Filedata + 4)) ); + + if( ((unsigned short *) Filedata)[4] == 0) { + Index = (Uint32 *) (Filedata + 10); + FramesPer1024ms = SDL_SwapLE32( *((Uint32*) (Filedata+6)) ); + } else { + Index = (Uint32 *) (Filedata + 8); + FramesPer1024ms = SDL_SwapLE16( *((Uint16*) (Filedata+6)) ); + } + + if(Index[0] == 0) { + Index++; + NumFrames--; + } + + if(Filedata + WsaFilesize < (((unsigned char *) Index) + 4 * NumFrames)) { + fprintf(stderr, "Error: No valid WSA-File: File too small!\n"); + exit(EXIT_FAILURE); + } + + if( (decodedFrames = (unsigned char*) calloc(1,SizeX*SizeY*NumFrames)) == NULL) { + fprintf(stderr, "Error: Unable to allocate memory for decoded WSA-Frames!\n"); + exit(EXIT_FAILURE); + } + + decodeFrames(); +}; + +Wsafile::~Wsafile() +{ + free(decodedFrames); +}; + +SDL_Surface * Wsafile::getPicture(Uint32 FrameNumber) +{ + if(FrameNumber >= NumFrames) { + return NULL; + } + + SDL_Surface * pic; + unsigned char * Image = decodedFrames + (FrameNumber * SizeX * SizeY); + + // create new picture surface + if((pic = SDL_CreateRGBSurface(SDL_SWSURFACE,SizeX,SizeY,8,0,0,0,0))== NULL) { + return NULL; + } + + printf("File Nr.: %d (Size: %dx%d)\n",FrameNumber,SizeX,SizeY); + + //SDL_SetColors(pic, palette->colors, 0, palette->ncolors); + SDL_LockSurface(pic); + + //Now we can copy line by line + for(int y = 0; y < SizeY;y++) { + memcpy( ((char*) (pic->pixels)) + y * pic->pitch , Image + y * SizeX, SizeX); + } + + SDL_UnlockSurface(pic); + + return pic; + +}; + +void Wsafile::decodeFrames() +{ + unsigned char *dec80; + + for(int i=0;i<NumFrames;i++) { + if( (dec80 = (unsigned char*) calloc(1,SizeX*SizeY*2)) == NULL) { + fprintf(stderr, "Error: Unable to allocate memory for decoded WSA-Frames!\n"); + exit(EXIT_FAILURE); + } + + decode80(Filedata + SDL_SwapLE32(Index[i]), dec80, 0); + + decode40(dec80, decodedFrames + i * SizeX * SizeY); + + free(dec80); + + if (i < NumFrames - 1) { + memcpy(decodedFrames + (i+1) * SizeX * SizeY, decodedFrames + i * SizeX * SizeY,SizeX * SizeY); + } + } +}; Added: branches/dunks/src/pakfile/main.cpp =================================================================== --- branches/dunks/src/pakfile/main.cpp (rev 0) +++ branches/dunks/src/pakfile/main.cpp 2006-07-25 06:24:26 UTC (rev 47) @@ -0,0 +1,481 @@ +/* Created by Anjuta version 1.2.4 */ +/* This file will not be overwritten */ + +#include <iostream> +#include <string.h> +#include <SDL.h> +#include "Pakfile.h" +#include "Shpfile.h" +#include "Cpsfile.h" +#include "Wsafile.h" +#include "Icnfile.h" + +SDL_Surface* screen; +SDL_Palette* palette; +bool quiting = false; +int ShpIndex = 0; +int WsaIndex = 0; +int IcnIndex = 0; +int PakIndex = 0; + +SDL_Surface* picture = NULL; + +Pakfile* myPakfile = NULL; +Shpfile* myShpfile = NULL; +Cpsfile* myCpsfile = NULL; +Wsafile* myWsafile = NULL; +Icnfile* myIcnfile = NULL; +unsigned char * filedata = NULL; + +void showShp(int index) +{ + if(myShpfile == NULL) { + return; + } + + if(picture != NULL) { + SDL_FreeSurface(picture); + picture = NULL; + } + + + + picture = myShpfile->getPicture(index); + + if(picture == NULL) { + fprintf(stderr,"Cannot load picture %d\n",index); + } +} + +void showWsa(int index) +{ + if(myWsafile == NULL) { + return; + } + + if(picture != NULL) { + SDL_FreeSurface(picture); + picture = NULL; + } + + + + picture = myWsafile->getPicture(index); + + if(picture == NULL) { + fprintf(stderr,"Cannot load picture %d\n",index); + } +} + +void showIcn(int index) +{ + if(myIcnfile == NULL) { + return; + } + + if(picture != NULL) { + SDL_FreeSurface(picture); + picture = NULL; + } + + picture = myIcnfile->getPicture(index); + + if(picture == NULL) { + fprintf(stderr,"Cannot load picture %d\n",index); + } +} + +void showOtherFile(char *filename) { + if(myShpfile != NULL) { + delete myShpfile; + } + + if(myCpsfile != NULL) { + delete myCpsfile; + } + + if(myWsafile != NULL) { + delete myWsafile; + } + + if(myIcnfile != NULL) { + delete myIcnfile; + } + + if(filedata != NULL) { + free(filedata); + } + + int bufsize; + + if((filedata = myPakfile->getFile(filename,&bufsize)) == NULL) { + fprintf(stderr,"Error: Cannot open %s\n",filename); + exit(EXIT_FAILURE); + } + + if(strstr(filename,".SHP") != 0) { + myCpsfile = NULL; + myWsafile = NULL; + myIcnfile = NULL; + if( (myShpfile = new Shpfile(filedata,bufsize)) == NULL) { + fprintf(stderr,"Error: Cannot open Shp-File %s\n",filename); + exit(EXIT_FAILURE); + } + } else if (strstr(filename,".CPS") != 0) { + myShpfile = NULL; + myWsafile = NULL; + myIcnfile = NULL; + if( (myCpsfile = new Cpsfile(filedata,bufsize)) == NULL) { + fprintf(stderr,"Error: Cannot open Cps-File %s\n",filename); + exit(EXIT_FAILURE); + } + } else if (strstr(filename,".WSA") != 0) { + myShpfile = NULL; + myCpsfile = NULL; + myIcnfile = NULL; + if( (myWsafile = new Wsafile(filedata,bufsize)) == NULL) { + fprintf(stderr,"Error: Cannot open Wsa-File %s\n",filename); + exit(EXIT_FAILURE); + } + } else if (strstr(filename,".ICN") != 0) { + myShpfile = NULL; + myCpsfile = NULL; + myWsafile = NULL; + if( (myIcnfile = new Icnfile(filedata,bufsize)) == NULL) { + fprintf(stderr,"Error: Cannot open Icn-File %s\n",filename); + exit(EXIT_FAILURE); + } + } else { + return; + } + + + + printf("\nOpening File %s\n",filename); + fflush(stdout); + + if(myShpfile != NULL) { + ShpIndex = 0; + showShp(ShpIndex); + } else if (myCpsfile != NULL) { + if(picture != NULL) { + SDL_FreeSurface(picture); + picture = NULL; + } + picture = myCpsfile->getPicture(); + } else if (myWsafile != NULL) { + WsaIndex = 0; + showWsa(WsaIndex); + } else if (myIcnfile != NULL) { + IcnIndex = 0; + showIcn(IcnIndex); + } +} + +char * getNextFileInPak() { + int oldPakIndex = PakIndex; + char * Filename; + + PakIndex++; + if(PakIndex >= myPakfile->getNumFiles()) { + PakIndex = 0; + } + + do { + if( (Filename = myPakfile->getFilename(PakIndex)) == NULL) { + fprintf(stderr,"ERROR: Pakfile::getFilename() returned NULL.\n"); + exit(EXIT_FAILURE); + } + + if(strstr(Filename,".SHP") != 0) { + return Filename; + } else if (strstr(Filename,".CPS") != 0) { + return Filename; + } else if (strstr(Filename,".WSA") != 0) { + return Filename; + } else if (strstr(Filename,".ICN") != 0) { + return Filename; + }else { + printf("Skipping %s\n",Filename); + } + + + PakIndex++; + if(PakIndex >= myPakfile->getNumFiles()) { + PakIndex = 0; + } + } while(oldPakIndex != PakIndex); + + return NULL; +} + +char * getPrevFileInPak() { + int oldPakIndex = PakIndex; + PakIndex--; + char * Filename; + + if(PakIndex < 0) { + PakIndex = myPakfile->getNumFiles() - 1; + } + + do { + + if( (Filename = myPakfile->getFilename(PakIndex)) == NULL) { + fprintf(stderr,"ERROR: Pakfile::getFilename() returned NULL.\n"); + exit(EXIT_FAILURE); + } + + if(strstr(Filename,".SHP") != 0) { + return Filename; + } else if (strstr(Filename,".CPS") != 0) { + return Filename; + } else if (strstr(Filename,".WSA") != 0) { + return Filename; + } else if (strstr(Filename,".ICN") != 0) { + return Filename; + }else { + printf("Skipping %s\n",Filename); + } + + PakIndex--; + if(PakIndex < 0) { + PakIndex = myPakfile->getNumFiles() - 1; + } + } while(oldPakIndex != PakIndex); + + return NULL; +} + +int main(int argc, char ** argv) +{ + bool fullscreen = false; + + + switch(argc) + { + case 2: + { + } break; + + case 3: + { + if ((argc == 3) & (strcmp(argv[1],"--fullscreen") == 0)) { + fullscreen = true; + } else { + printf("Usage:\n Pakfile [--fullscreen] filename.pak\n"); + exit(EXIT_SUCCESS); + } + } break; + + default: + { + if((argc > 3) || (argc < 2)) { + printf("Usage:\n Pakfile [--fullscreen] filename.pak\n"); + exit(EXIT_SUCCESS); + } + } break; + } + + + + + + + SDL_Event event; + + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) + { + fprintf(stderr, "ERROR: Couldn't initialise SDL: %s\n", SDL_GetError()); + exit(1); + } + SDL_EnableUNICODE(1); + + SDL_WM_SetCaption("Pakfileviewer", "Pakfileviewer"); + + + // Load palette + SDL_Surface* paletteSurf = SDL_LoadBMP("Palette.bmp"); + if(paletteSurf == NULL) { + fprintf(stderr, "ERROR: Couldn't load Palette.bmp: %s\n", SDL_GetError()); + exit(EXIT_FAILURE); + } + + if((palette = new SDL_Palette) == NULL) { + fprintf(stderr, "ERROR: Couldn't allocate new SDL_Palette.\n"); + exit(EXIT_FAILURE); + } + + palette->ncolors = paletteSurf->format->palette->ncolors; + if((palette->colors = new SDL_Color[palette->ncolors]) == NULL) { + fprintf(stderr, "ERROR: Couldn't allocate new SDL_Color.\n"); + exit(EXIT_FAILURE); + } + memcpy(palette->colors, paletteSurf->format->palette->colors, sizeof(SDL_Color) * palette->ncolors); + SDL_FreeSurface(paletteSurf); + + // init Screen + if( (screen = SDL_SetVideoMode(640, 480, 8, (fullscreen ? SDL_FULLSCREEN : 0) )) == NULL) { + fprintf(stderr, "ERROR: Couldn't set video mode: %s\n", SDL_GetError()); + exit(EXIT_FAILURE); + } + SDL_SetColors(screen, palette->colors, 0, palette->ncolors); + + + // open pakfile + if( (myPakfile = new Pakfile( ((argc == 2) ? argv[1] : argv[2]))) == NULL) { + + } + + + char *FName; + + if((FName = getNextFileInPak()) != NULL) { + showOtherFile(FName); + } else { + fprintf(stderr,"Error: Pakfile contains no images!\n"); + exit(EXIT_FAILURE); + } + + + // main Loop + while(!quiting) { + + + SDL_FillRect(screen,NULL,0); + + if(picture != NULL) { + SDL_Rect dest; + dest.x = 0; + dest.y = 0; + dest.w = picture->w; + dest.h = picture->h; + + SDL_BlitSurface(picture,&dest,screen,&dest); + } + + SDL_Flip(screen); + + // do input + while(SDL_PollEvent(&event)) { + switch (event.type) + { + case (SDL_KEYUP): + { + switch(event.key.keysym.sym) + { + case SDLK_ESCAPE: + { + quiting = true; + } break; + + case SDLK_DOWN: + { + if(myShpfile != NULL) { + ShpIndex++; + if(myShpfile) { + if(ShpIndex == myShpfile->getNumFiles()) { + ShpIndex = 0; + } + } else { + ShpIndex = 0; + } + + showShp(ShpIndex); + } else if(myWsafile != NULL) { + WsaIndex++; + if(myWsafile) { + if(WsaIndex == myWsafile->getNumFrames()) { + WsaIndex = 0; + } + } else { + WsaIndex = 0; + } + showWsa(WsaIndex); + } else if(myIcnfile != NULL) { + IcnIndex++; + if(myIcnfile) { + if(IcnIndex == myIcnfile->getNumFiles()) { + IcnIndex = 0; + } + } else { + IcnIndex = 0; + } + showIcn(IcnIndex); + } + } break; + + case SDLK_UP: + { + if(myShpfile != NULL) { + ShpIndex--; + if(ShpIndex < 0) { + if(myShpfile) { + ShpIndex = myShpfile->getNumFiles() - 1; + } else { + ShpIndex = 0; + } + } + showShp(ShpIndex); + } else if(myWsafile != NULL) { + WsaIndex--; + if(WsaIndex < 0) { + if(myWsafile) { + WsaIndex = myWsafile->getNumFrames() - 1; + } else { + WsaIndex = 0; + } + } + showWsa(WsaIndex); + } + else if (myIcnfile != NULL) { + IcnIndex--; + if(IcnIndex < 0) { + if(myIcnfile) { + IcnIndex = myIcnfile->getNumFiles() - 1; + } else { + IcnIndex = 0; + } + } + showIcn(IcnIndex); + } + } break; + + case SDLK_LEFT: + { + char * Filename = getPrevFileInPak(); + if(Filename != NULL) { + showOtherFile(Filename); + } + } break; + + case SDLK_RIGHT: + { + char * Filename = getNextFileInPak(); + if(Filename != NULL) { + showOtherFile(Filename); + } + } break; + + default: + { + ; + } break; + } + } break; + + default: + { + ; + } break; + } + } + } + + delete myPakfile; + delete myShpfile; + free(filedata); + + SDL_Quit(); + + return 0; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dv...@us...> - 2006-07-24 22:30:40
|
Revision: 46 Author: dvalin Date: 2006-07-24 15:30:32 -0700 (Mon, 24 Jul 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=46&view=rev Log Message: ----------- Fix unused variable 'ox' Modified Paths: -------------- branches/dunks/src/Font.cpp Modified: branches/dunks/src/Font.cpp =================================================================== --- branches/dunks/src/Font.cpp 2006-07-24 22:12:23 UTC (rev 45) +++ branches/dunks/src/Font.cpp 2006-07-24 22:30:32 UTC (rev 46) @@ -28,9 +28,9 @@ ch = &m_characters[text[c]]; bitmap = ch->bitmap; - byte ox; +/* byte ox; - /* + for (byte y=0; y!=ch->y_offset; y++) { ox = offx; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dv...@us...> - 2006-07-24 22:12:36
|
Revision: 45 Author: dvalin Date: 2006-07-24 15:12:23 -0700 (Mon, 24 Jul 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=45&view=rev Log Message: ----------- Be sure to link against boost Modified Paths: -------------- branches/dunks/SConstruct Modified: branches/dunks/SConstruct =================================================================== --- branches/dunks/SConstruct 2006-07-24 21:31:28 UTC (rev 44) +++ branches/dunks/SConstruct 2006-07-24 22:12:23 UTC (rev 45) @@ -26,7 +26,7 @@ env.ParseConfig('sdl-config --cflags --libs') env.ParseConfig('pkg-config --cflags --libs zziplib') env.Append(CCFLAGS=["-Wall", "-Werror", "-O2", "-ffast-math", "-funroll-loops"]) - env.Append(LINKFLAGS = ["-ffast-math"]) + env.Append(LINKFLAGS = ["-ffast-math", "-lboost_signals"]) if 1: env.Append(CCFLAGS=["-ggdb"]) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <shu...@us...> - 2006-07-24 21:31:44
|
Revision: 44 Author: shutdownrunner Date: 2006-07-24 14:31:28 -0700 (Mon, 24 Jul 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=44&view=rev Log Message: ----------- Fix giving descriptions for savegames Modified Paths: -------------- trunk/src/Game.cpp Modified: trunk/src/Game.cpp =================================================================== --- trunk/src/Game.cpp 2006-07-24 10:18:15 UTC (rev 43) +++ trunk/src/Game.cpp 2006-07-24 21:31:28 UTC (rev 44) @@ -672,6 +672,7 @@ gameSaveNameEntry.setEnabled(false); gameSaveNameEntry.setVisible(false); + gameSaveNameEntry.setFocused(false); saveButton.setEnabled(false); saveButton.setVisible(false); } @@ -680,6 +681,7 @@ { gameSaveNameEntry.setEnabled(false); gameSaveNameEntry.setVisible(false); + gameSaveNameEntry.setFocused(false); saveButton.setEnabled(false); saveButton.setVisible(false); } @@ -700,6 +702,7 @@ if (gameSaveNameEntry.textEquals("(Empty)")) gameSaveNameEntry.setText(""); gameSaveNameEntry.handlePress(0, 0); + gameSaveNameEntry.setFocused(true); saveButton.setEnabled(true); saveButton.setVisible(true); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <shu...@us...> - 2006-07-24 10:18:24
|
Revision: 43 Author: shutdownrunner Date: 2006-07-24 03:18:15 -0700 (Mon, 24 Jul 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=43&view=rev Log Message: ----------- Fix for "You have failed your mission" in editor Modified Paths: -------------- trunk/include/Editor.h trunk/src/PlayerClass.cpp trunk/src/editor.cpp Modified: trunk/include/Editor.h =================================================================== --- trunk/include/Editor.h 2006-07-24 09:50:09 UTC (rev 42) +++ trunk/include/Editor.h 2006-07-24 10:18:15 UTC (rev 43) @@ -2,5 +2,5 @@ #define DUNE_EDITOR_H void do_editor(); - +bool is_edit_mode(); #endif // DUNE_EDITOR_H Modified: trunk/src/PlayerClass.cpp =================================================================== --- trunk/src/PlayerClass.cpp 2006-07-24 09:50:09 UTC (rev 42) +++ trunk/src/PlayerClass.cpp 2006-07-24 10:18:15 UTC (rev 43) @@ -9,6 +9,7 @@ #include "houses.h" #include "Settings.h" #include "globals.h" +#include "Editor.h" PlayerClass* thisPlayer; PlayerClass** player; @@ -221,7 +222,7 @@ - if (!isAlive()) + if (!isAlive()&&!is_edit_mode()) lose(); } @@ -441,7 +442,7 @@ void PlayerClass::lose() { - + char message[100]; sprintf(message, "%s has been defeated.", name); Modified: trunk/src/editor.cpp =================================================================== --- trunk/src/editor.cpp 2006-07-24 09:50:09 UTC (rev 42) +++ trunk/src/editor.cpp 2006-07-24 10:18:15 UTC (rev 43) @@ -83,6 +83,7 @@ and unset when leaving*/ bool edit_mode; +bool is_edit_mode() { return edit_mode; } void on_newmapOk() { delete map; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dun...@us...> - 2006-07-24 09:50:22
|
Revision: 42 Author: dunkfordyce Date: 2006-07-24 02:50:09 -0700 (Mon, 24 Jul 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=42&view=rev Log Message: ----------- fixes for windows Modified Paths: -------------- branches/dunks/SConstruct branches/dunks/config.py branches/dunks/include/Font.h branches/dunks/src/Application.cpp branches/dunks/src/Font.cpp branches/dunks/src/main.cpp Modified: branches/dunks/SConstruct =================================================================== --- branches/dunks/SConstruct 2006-07-23 22:21:11 UTC (rev 41) +++ branches/dunks/SConstruct 2006-07-24 09:50:09 UTC (rev 42) @@ -1,4 +1,5 @@ import sys +import os opts = Options('config.py') # default to using sdl-config if not on windows @@ -9,37 +10,46 @@ opts.Add('ZZIP_INCLUDE_PATH', 'include path for zlib', '') opts.Add('ZZIP_LIB_PATH', 'lib path for zlib', '') -env = Environment(options = opts ) +opts.Add('BOOST_INCLUDE_PATH', 'include path for boost', '') +# need to get two paths as far as i can tell. these can probably be calculated somehow +opts.Add('BOOST_LIB_PATH', 'lib path for boost', '') + +if sys.platform == 'win32': + env = Environment(options = opts, ENV=os.environ) +else: + env = Environment(options = opts) + env.Append(CPPPATH="#include") if sys.platform != "win32": env.ParseConfig('sdl-config --cflags --libs') env.ParseConfig('pkg-config --cflags --libs zziplib') - env.Append(CCFLAGS=["-Wall", "-Werror"]) + env.Append(CCFLAGS=["-Wall", "-Werror", "-O2", "-ffast-math", "-funroll-loops"]) + env.Append(LINKFLAGS = ["-ffast-math"]) if 1: env.Append(CCFLAGS=["-ggdb"]) else: - env.Append(LIBS = ["zziplib", "zdll", "SDLmain"]) + env.Append(LIBS = ["zzipdll", "zdll", "SDLmain"]) env.Append(LINKFLAGS = ["/SUBSYSTEM:CONSOLE"]) - env.Append(CCFLAGS = ["/MD", "/Ox"]) + env.Append(CCFLAGS = ["/MD", "/O2"]) env.Append(LIBS = [ "SDL", "SDL_mixer", "SDL_image", "SDL_net", "SDL_ttf", - - "boost_signals", ]) env.Append(CPPPATH = [ "${SDL_INCLUDE_PATH}", "${ZLIB_INCLUDE_PATH}", - "${ZZIP_INCLUDE_PATH}"]) + "${ZZIP_INCLUDE_PATH}", + "${BOOST_INCLUDE_PATH}"]) env.Append(LIBPATH = [ "${SDL_LIB_PATH}", "${ZLIB_LIB_PATH}", - "${ZZIP_LIB_PATH}"]) + "${ZZIP_LIB_PATH}", + "${BOOST_LIB_PATH}"]) Export('env') Modified: branches/dunks/config.py =================================================================== --- branches/dunks/config.py 2006-07-23 22:21:11 UTC (rev 41) +++ branches/dunks/config.py 2006-07-24 09:50:09 UTC (rev 42) @@ -4,3 +4,5 @@ ZLIB_LIB_PATH = r"E:\projects\include\zlib123-dll\lib" ZZIP_INCLUDE_PATH = "E:\projects\include\zziplib-0.10.82-msvc6-lib\include" ZZIP_LIB_PATH = "E:\projects\include\zziplib-0.10.82-msvc6-lib\lib" +BOOST_INCLUDE_PATH = r"C:\Boost\include\boost-1_33_1" +BOOST_LIB_PATH = r"C:\Boost\lib" Modified: branches/dunks/include/Font.h =================================================================== --- branches/dunks/include/Font.h 2006-07-23 22:21:11 UTC (rev 41) +++ branches/dunks/include/Font.h 2006-07-24 09:50:09 UTC (rev 42) @@ -45,7 +45,7 @@ Font(FNTCharacter* characters, FNTHeader* header); ~Font(); - void render(const char* text, SDL_Surface* surface, Uint16 x, Uint16 y); + void render(const char* text, SDL_Surface* surface, Uint16 x, Uint16 y, Uint8 paloff); private: FNTHeader* m_header; Modified: branches/dunks/src/Application.cpp =================================================================== --- branches/dunks/src/Application.cpp 2006-07-23 22:21:11 UTC (rev 41) +++ branches/dunks/src/Application.cpp 2006-07-24 09:50:09 UTC (rev 42) @@ -28,6 +28,8 @@ #define SCREEN_BPP 8 #define VERSION "0.94.1" +Uint8 gpaloff; + Application::Application() { m_running = false; @@ -264,11 +266,13 @@ const int fps_interval = 10 * 1000; // 10 seconds float fps; - Font* fnt = FontManager::Instance()->getFont("intro.fnt"); + Font* fnt = FontManager::Instance()->getFont("new8p.fnt"); m_running = true; assert(m_rootWidget != NULL); + + gpaloff = 0 ; while (m_running) { @@ -293,7 +297,8 @@ m_rootWidget->draw(m_screen); - fnt->render("ABCDEFGHIJKLMOPQRSTUVWXYZ", m_screen, 10, 10); + fnt->render("ABCDEFGHIJKLMOPQRSTUVWXYZ", m_screen, 10, 10, gpaloff); + fnt->render("abcdefghijklmnopqrstuvwxz", m_screen, 10, 30, gpaloff); BlitCursor(); @@ -344,6 +349,11 @@ 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)); Modified: branches/dunks/src/Font.cpp =================================================================== --- branches/dunks/src/Font.cpp 2006-07-23 22:21:11 UTC (rev 41) +++ branches/dunks/src/Font.cpp 2006-07-24 09:50:09 UTC (rev 42) @@ -17,20 +17,20 @@ delete m_header; }; -void Font::render(const char* text, SDL_Surface* surface, Uint16 offx, Uint16 offy) +void Font::render(const char* text, SDL_Surface* surface, Uint16 offx, Uint16 offy, Uint8 paloff) { FNTCharacter* ch; byte* bitmap; Uint8* pixels = (Uint8*)surface->pixels; - + for (unsigned int c=0; c!=strlen(text); c++) { - printf("char %c\n", text[c]); ch = &m_characters[text[c]]; bitmap = ch->bitmap; byte ox; + /* for (byte y=0; y!=ch->y_offset; y++) { ox = offx; @@ -42,6 +42,7 @@ ++ox; }; }; + */ for (byte y=0; y!=ch->height; y++) { @@ -72,22 +73,21 @@ printf("."); */ - //if (hibyte!=0) + if (hibyte!=0) { - pixels[(offx + x) + ((ch->y_offset + y + offy) * surface->w)] = Uint8(hibyte); + pixels[(offx + x) + ((ch->y_offset + y + offy) * surface->w)] = paloff + Uint8(hibyte); }; - //if (2 < ch->width) lobyte!=0) + if (lobyte!=0) //(2 < ch->width) lobyte!=0) { - pixels[(offx + x + 1) + ((ch->y_offset + y + offy) * surface->w)] = Uint8(lobyte); + pixels[(offx + x + 1) + ((ch->y_offset + y + offy) * surface->w)] = paloff + Uint8(lobyte); }; }; - printf("\n"); }; offx += (2*ch->width) + 1; }; - + }; FontManager::FontManager() Modified: branches/dunks/src/main.cpp =================================================================== --- branches/dunks/src/main.cpp 2006-07-23 22:21:11 UTC (rev 41) +++ branches/dunks/src/main.cpp 2006-07-24 09:50:09 UTC (rev 42) @@ -1,6 +1,15 @@ #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"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <shu...@us...> - 2006-07-23 22:21:21
|
Revision: 41 Author: shutdownrunner Date: 2006-07-23 15:21:11 -0700 (Sun, 23 Jul 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=41&view=rev Log Message: ----------- Clear all the lists(units,struct,etc.) Modified Paths: -------------- trunk/src/editor.cpp Modified: trunk/src/editor.cpp =================================================================== --- trunk/src/editor.cpp 2006-07-23 21:49:54 UTC (rev 40) +++ trunk/src/editor.cpp 2006-07-23 22:21:11 UTC (rev 41) @@ -86,6 +86,17 @@ void on_newmapOk() { delete map; + unitList->clearList(); + structureList->clearList(); + bulletList->clearList(); + selectedList->clearList(); + selectedLists->clearList(); + + airUnitBlitList->clearList(); + groundUnitBlitList->clearList(); + infantryBlitList->clearList(); + selectionBlitList->clearList(); + undergroundUnitBlitList->clearList(); make_random_map(128,128, selectedSpice, selectedRocks); current_editorWindow = NULL; } @@ -2186,6 +2197,8 @@ delete map; delete dborder; + + current_editorWindow = NULL; for (i = 0; i < NUM_HOUSES; i++) delete player[i]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dv...@us...> - 2006-07-23 21:50:00
|
Revision: 40 Author: dvalin Date: 2006-07-23 14:49:54 -0700 (Sun, 23 Jul 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=40&view=rev Log Message: ----------- Fix characters width odd number width Modified Paths: -------------- branches/dunks/src/Font.cpp Modified: branches/dunks/src/Font.cpp =================================================================== --- branches/dunks/src/Font.cpp 2006-07-23 21:47:45 UTC (rev 39) +++ branches/dunks/src/Font.cpp 2006-07-23 21:49:54 UTC (rev 40) @@ -160,7 +160,7 @@ { byte offset = hchar[i] & 0xFF; byte height = hchar[i] >> 8; - byte width = wchar[i] / 2; + byte width =( wchar[i] + 1) / 2; printf("%d width = %hd offset = %hd height = %hd\n", i, width, offset, height); characters[i].width = width; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dv...@us...> - 2006-07-23 21:47:58
|
Revision: 39 Author: dvalin Date: 2006-07-23 14:47:45 -0700 (Sun, 23 Jul 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=39&view=rev Log Message: ----------- Fix odd numbered widths Modified Paths: -------------- branches/dunks/wip/font.cpp Modified: branches/dunks/wip/font.cpp =================================================================== --- branches/dunks/wip/font.cpp 2006-07-23 21:14:35 UTC (rev 38) +++ branches/dunks/wip/font.cpp 2006-07-23 21:47:45 UTC (rev 39) @@ -76,7 +76,7 @@ { byte offset = hchar[i] & 0xFF; byte height = hchar[i] >> 8; - byte width = wchar[i] / 2; + byte width = (wchar[i] + 1) / 2; printf("%d %c width = %hd offset = %hd height = %hd\n", i, i, width, offset, height); characters[i].width = width; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <shu...@us...> - 2006-07-23 21:14:56
|
Revision: 38 Author: shutdownrunner Date: 2006-07-23 14:14:35 -0700 (Sun, 23 Jul 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=38&view=rev Log Message: ----------- Add new map dialog window Modified Paths: -------------- trunk/include/MapGenerator.h trunk/src/MapGenerator.cpp trunk/src/editor.cpp Modified: trunk/include/MapGenerator.h =================================================================== --- trunk/include/MapGenerator.h 2006-07-23 21:04:07 UTC (rev 37) +++ trunk/include/MapGenerator.h 2006-07-23 21:14:35 UTC (rev 38) @@ -7,7 +7,7 @@ void smooth_spot(int i, int j); void smooth_terrain(); void fixWalls(int xPos, int yPos); -void make_random_map(int sizeX, int sizeY); +void make_random_map(int sizeX, int sizeY, int = SPICEFIELDS, int = ROCKFIELDS); int readMapPlayerNumbers(char* filename, int numbers[MAX_PLAYERS]); int readMapMaxPlayers(char* filename); bool loadMap(char* mapName); Modified: trunk/src/MapGenerator.cpp =================================================================== --- trunk/src/MapGenerator.cpp 2006-07-23 21:04:07 UTC (rev 37) +++ trunk/src/MapGenerator.cpp 2006-07-23 21:14:35 UTC (rev 38) @@ -570,11 +570,9 @@ } // WHILE } -void make_random_map(int sizeX, int sizeY) +void make_random_map(int sizeX, int sizeY, int fields, int spots) { int i, count; -int spots = ROCKFIELDS; -int fields = SPICEFIELDS; int spotX, spotY; map = new MapClass(sizeX, sizeY); @@ -673,7 +671,6 @@ StructureClass* newStructure; fread(&maxPlayers, sizeof(int), 1, file); - for (i = 0; i < maxPlayers; i++) found[i] = false; //read the players details @@ -689,12 +686,12 @@ fread(&mapSizeX, sizeof(short), 1, file); fread(&mapSizeY, sizeof(short), 1, file); if ((mapSizeX >= 0) && (mapSizeX < MAX_XSIZE) && (mapSizeY >= 0) && (mapSizeY < MAX_YSIZE)) - ok = true; + { ok = true; printf ("map is ok");} else fprintf(stderr, "Level size is unsupported %d,%d.", mapSizeX, mapSizeY); if (ok) - { + { map = new MapClass(mapSizeX, mapSizeY); //load terrain data Modified: trunk/src/editor.cpp =================================================================== --- trunk/src/editor.cpp 2006-07-23 21:04:07 UTC (rev 37) +++ trunk/src/editor.cpp 2006-07-23 21:14:35 UTC (rev 38) @@ -56,7 +56,23 @@ terrainType, terrainTile, unitType; + +int selectedSpice = SPICEFIELDS, + selectedRocks = ROCKFIELDS; +int mapSizes[] = {32,64,128,256}; + +char selectedBuffer[3]; +Window *current_editorWindow, + newmapWindow; + +Button newmap_buttonOk, + newmap_buttonCancel, + newmap_buttonSpicePlus, + newmap_buttonSpiceMinus, + newmap_buttonRocksPlus, + newmap_buttonRocksMinus; + BuildItemClass buildItem; PLACING_TYPE placingType; @@ -67,6 +83,43 @@ and unset when leaving*/ bool edit_mode; +void on_newmapOk() +{ + delete map; + make_random_map(128,128, selectedSpice, selectedRocks); + current_editorWindow = NULL; +} + +void on_newmapCancel() +{ + current_editorWindow = NULL; +} + +void on_newmapSpicePlus() +{ + selectedSpice++; +} + + +void on_newmapSpiceMinus() +{ + selectedSpice--; + + if (selectedSpice<1) selectedSpice = 1; +} + +void on_newmapRocksPlus() +{ + selectedRocks++; +} + + +void on_newmapRocksMinus() +{ + selectedRocks--; + + if (selectedRocks<1) selectedRocks = 1; +} void saveMap(char* filename) { bool found[MAX_PLAYERS]; @@ -452,6 +505,9 @@ case SDLK_s: saveMap("map.dlm"); break; + case SDLK_n: + current_editorWindow = &newmapWindow; + break; case SDLK_p: SDL_SaveBMP(screen, "screenshot.bmp"); break; @@ -479,8 +535,14 @@ { case (SDL_BUTTON_LEFT): { - int xPos = (mouse->x + dborder->minX)/BLOCKSIZE, - yPos = (mouse->y + dborder->minY)/BLOCKSIZE; + if (current_editorWindow != NULL) + { + current_editorWindow->handlePress(mouse->x, mouse->y); + } + else + { + int xPos = (mouse->x + dborder->minX)/BLOCKSIZE, + yPos = (mouse->y + dborder->minY)/BLOCKSIZE; if (placingMode) { @@ -694,6 +756,7 @@ editorContainer->handlePress(mouse->x, mouse->y); editorContainer2->handlePress(mouse->x, mouse->y); + } break; } //end of SDL_BUTTON_LEFT case (SDL_BUTTON_RIGHT): //if the right mouse button is pressed @@ -810,6 +873,12 @@ case SDL_MOUSEBUTTONUP: { SDL_MouseButtonEvent* mouse = &event.button; + if (current_editorWindow != NULL) + { + current_editorWindow->handleRelease(mouse->x, mouse->y); + } + else + { if (selectionMode && (mouse->button == SDL_BUTTON_LEFT)) { int finalMouseX = mouse->x, //this keeps the box on the map, and not over game bar @@ -833,6 +902,7 @@ placing = false; radarMode = false; selectionMode = false; + } break; } case (SDL_QUIT): @@ -976,7 +1046,7 @@ - SDL_Rect drawLocation; + SDL_Rect drawLocation,source; for (yCount = dborder->minY/BLOCKSIZE; yCount <= (dborder->maxY/BLOCKSIZE); yCount++) @@ -1245,7 +1315,80 @@ if (--messageTimer[count] <= 0) messageBuffer[count][0] = '\0'; } + + if (current_editorWindow == &newmapWindow) + { + SDL_Surface* surf; + //Window background + drawLocation.x = newmapWindow.getX(); + drawLocation.y = newmapWindow.getY(); + drawLocation.w = newmapWindow.getWidth(); + drawLocation.h = newmapWindow.getHeight(); + + SDL_BlitSurface((SDL_Surface*)dataFile[UI_LoadSaveWindow].dat, NULL, screen, &drawLocation); + + //Spice amount select + surf = (SDL_Surface*)dataFile[UI_MissionSelect].dat; + drawLocation.x = newmapWindow.getX()+35; + drawLocation.y = newmapWindow.getY()+40; + drawLocation.w = surf->w; + drawLocation.h = surf->h; + + SDL_BlitSurface(surf, NULL, screen, &drawLocation); + + //Rock amount select + drawLocation.y = newmapWindow.getY()+83; + SDL_BlitSurface(surf, NULL, screen, &drawLocation); + + //Overlay spice label -- FIX IT SOMEHOW + surf = TTF_RenderText_Solid(font[16], "Spice", palette->colors[COLOUR_WHITE]); + drawLocation.x = newmapWindow.getX()+43; + drawLocation.y = newmapWindow.getY()+48; + drawLocation.w = 60; + drawLocation.h = surf->h; + SDL_FillRect(screen, &drawLocation, COLOUR_BLACK); + SDL_BlitSurface(surf, NULL, screen, &drawLocation); + + //Overlay rocks label -- FIX IT SOMEHOW + surf = TTF_RenderText_Solid(font[16], "Rocks", palette->colors[COLOUR_WHITE]); + drawLocation.y = newmapWindow.getY()+93; + SDL_FillRect(screen, &drawLocation, COLOUR_BLACK); + SDL_BlitSurface(surf, NULL, screen, &drawLocation); + + //Draw selected rocks value + sprintf(selectedBuffer, "%d", selectedSpice); + + int digits = strlen(selectedBuffer); + SDL_Surface* surface = (SDL_Surface*)dataFile[UI_CreditsDigits].dat; + source.w = drawLocation.w = surface->w/10; + source.h = drawLocation.h = surface->h; + source.y = 0; + drawLocation.y = newmapWindow.getY() + 56; + for (int i=digits-1; i>=0; i--) + { + source.x = atoi(&selectedBuffer[i])*source.w; + selectedBuffer[i] = '\0'; + drawLocation.x = newmapWindow.getX() + 75 + (6 - digits + i)*10; + SDL_BlitSurface(surface, &source, screen, &drawLocation); + } + + //Draw selected rocks value + sprintf(selectedBuffer, "%d", selectedRocks); + digits = strlen(selectedBuffer); + drawLocation.y = newmapWindow.getY() + 99; + for (int i=digits-1; i>=0; i--) + { + source.x = atoi(&selectedBuffer[i])*source.w; + selectedBuffer[i] = '\0'; + drawLocation.x = newmapWindow.getX() + 75 + (6 - digits + i)*10; + SDL_BlitSurface(surface, &source, screen, &drawLocation); + } + + + newmapWindow.draw(); + } + drawCursor(); } @@ -1816,7 +1959,163 @@ editorContainer2 = &terrainContainer; ////////////////////////////////////////////////////////////////////////// + //Setup dialog windows + + newmapWindow.setWidth(192); + newmapWindow.setHeight(208); + newmapWindow.setX(screen->w/2 - newmapWindow.getWidth()/2); + newmapWindow.setY(screen->h/2 - newmapWindow.getHeight()/2); + + //button ok + + surface = (SDL_Surface*)dataFile[UI_OK].dat; + newmap_buttonOk.setSurface(surface, NULL); + + newmap_buttonOk.setHeight(surface->h); + + newmap_buttonOk.setWidth(surface->w); + + surface = (SDL_Surface*)dataFile[UI_OK_Pressed].dat; + + newmap_buttonOk.setPressedSurface(surface, NULL); + + newmap_buttonOk.setX(newmapWindow.getX()+50); + + newmap_buttonOk.setY(newmapWindow.getY()+175); + + newmap_buttonOk.setCallBack(on_newmapOk); + + //button cancel + + surface = (SDL_Surface*)dataFile[UI_Cancel].dat; + + newmap_buttonCancel.setSurface(surface, NULL); + + newmap_buttonCancel.setHeight(surface->h); + + newmap_buttonCancel.setWidth(surface->w); + + surface = (SDL_Surface*)dataFile[UI_Cancel_Pressed].dat; + + newmap_buttonCancel.setPressedSurface(surface, NULL); + + newmap_buttonCancel.setX(newmapWindow.getX()+80); + + newmap_buttonCancel.setY(newmapWindow.getY()+175); + + newmap_buttonCancel.setCallBack(on_newmapCancel); + + //button spice plus + + surface = (SDL_Surface*)dataFile[UI_Plus].dat; + + newmap_buttonSpicePlus.setSurface(surface, NULL); + + newmap_buttonSpicePlus.setHeight(surface->h); + + newmap_buttonSpicePlus.setWidth(surface->w); + + surface = (SDL_Surface*)dataFile[UI_Plus_Pressed].dat; + + newmap_buttonSpicePlus.setPressedSurface(surface, NULL); + + newmap_buttonSpicePlus.setX(newmapWindow.getX()+140); + + newmap_buttonSpicePlus.setY(newmapWindow.getY()+44); + + newmap_buttonSpicePlus.setCallBack(on_newmapSpicePlus); + + newmap_buttonSpicePlus.setVisible(true); + + //button spice minus + + surface = (SDL_Surface*)dataFile[UI_Minus].dat; + + newmap_buttonSpiceMinus.setSurface(surface, NULL); + + newmap_buttonSpiceMinus.setHeight(surface->h); + + newmap_buttonSpiceMinus.setWidth(surface->w); + + surface = (SDL_Surface*)dataFile[UI_Minus_Pressed].dat; + + newmap_buttonSpiceMinus.setPressedSurface(surface, NULL); + + newmap_buttonSpiceMinus.setX(newmapWindow.getX()+140); + + newmap_buttonSpiceMinus.setY(newmapWindow.getY()+58); + + newmap_buttonSpiceMinus.setCallBack(on_newmapSpiceMinus); + + newmap_buttonSpiceMinus.setVisible(true); + + //button rocks plus + + surface = (SDL_Surface*)dataFile[UI_Plus].dat; + + newmap_buttonRocksPlus.setSurface(surface, NULL); + + newmap_buttonRocksPlus.setHeight(surface->h); + + newmap_buttonRocksPlus.setWidth(surface->w); + + surface = (SDL_Surface*)dataFile[UI_Plus_Pressed].dat; + + newmap_buttonRocksPlus.setPressedSurface(surface, NULL); + + newmap_buttonRocksPlus.setX(newmapWindow.getX()+140); + + newmap_buttonRocksPlus.setY(newmapWindow.getY()+86); + + newmap_buttonRocksPlus.setCallBack(on_newmapRocksPlus); + + newmap_buttonRocksPlus.setVisible(true); + + //button rocks minus + + surface = (SDL_Surface*)dataFile[UI_Minus].dat; + + newmap_buttonRocksMinus.setSurface(surface, NULL); + + newmap_buttonRocksMinus.setHeight(surface->h); + + newmap_buttonRocksMinus.setWidth(surface->w); + + surface = (SDL_Surface*)dataFile[UI_Minus_Pressed].dat; + + newmap_buttonRocksMinus.setPressedSurface(surface, NULL); + + newmap_buttonRocksMinus.setX(newmapWindow.getX()+140); + + newmap_buttonRocksMinus.setY(newmapWindow.getY()+101); + + newmap_buttonRocksMinus.setCallBack(on_newmapRocksMinus); + + newmap_buttonRocksMinus.setVisible(true); + + + newmapWindow.addChild(&newmap_buttonOk); + + newmapWindow.addChild(&newmap_buttonCancel); + + newmapWindow.addChild(&newmap_buttonSpicePlus); + + newmapWindow.addChild(&newmap_buttonSpiceMinus); + + newmapWindow.addChild(&newmap_buttonRocksPlus); + + newmapWindow.addChild(&newmap_buttonRocksMinus); + + + newmap_buttonOk.setVisible(true); + + newmap_buttonCancel.setVisible(true); + + + newmapWindow.setVisible(true); + + ////////////////////////////////////////////////////////////////////////// settings.finished = false; settings.update = false; settings.won = false; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dun...@us...> - 2006-07-23 21:04:14
|
Revision: 37 Author: dunkfordyce Date: 2006-07-23 14:04:07 -0700 (Sun, 23 Jul 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=37&view=rev Log Message: ----------- menu base classes Added Paths: ----------- branches/dunks/include/MenuBase.h branches/dunks/src/MenuBase.cpp Added: branches/dunks/include/MenuBase.h =================================================================== --- branches/dunks/include/MenuBase.h (rev 0) +++ branches/dunks/include/MenuBase.h 2006-07-23 21:04:07 UTC (rev 37) @@ -0,0 +1,25 @@ +#ifndef DUNE_MENUBASE_H +#define DUNE_MENUBASE_H + +#include "State.h" +#include "gui2/Container.h" + +#include "SDL.h" + +class MenuBaseState : public State +{ + public: + MenuBaseState(); + ~MenuBaseState(); + + void JustMadeActive(); + void JustMadeInactive(); + + int Execute(float dt); + + public: + SDL_Surface* m_menuBackground; + Container* m_container; +}; + +#endif // DUNE_MENUBASE_H Added: branches/dunks/src/MenuBase.cpp =================================================================== --- branches/dunks/src/MenuBase.cpp (rev 0) +++ branches/dunks/src/MenuBase.cpp 2006-07-23 21:04:07 UTC (rev 37) @@ -0,0 +1,51 @@ +#include "MainMenu.h" + +#include "Application.h" +#include "DataFile.h" +#include "Settings.h" + +#include "SingleMenu.h" + +#include "boost/bind.hpp" + +#include <assert.h> + + +MenuBaseState::MenuBaseState() +{ + m_menuBackground = (SDL_Surface*)(dataFile[UI_Menu].dat); + //m_menu = new Window(); + //m_menu->setHeight(m_menuBackground->h); + //m_menu->setWidth(m_menuBackground->w); + + m_container = new Container(); + m_container->setPos(0, 0); + m_container->setSize(Settings::Instance()->GetWidth(), + Settings::Instance()->GetHeight()); + + Application::Instance()->RootWidget()->addChild(m_container); +}; + +MenuBaseState::~MenuBaseState() +{ + delete m_container; +}; + +void MenuBaseState::JustMadeActive() +{ + Application::Instance()->RootWidget()->addChild(m_container); + State::JustMadeActive(); +}; + +void MenuBaseState::JustMadeInactive() +{ + Application::Instance()->RootWidget()->deleteChild(m_container); + State::JustMadeInactive(); +}; + +int MenuBaseState::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: <dun...@us...> - 2006-07-23 20:05:57
|
Revision: 36 Author: dunkfordyce Date: 2006-07-23 13:05:44 -0700 (Sun, 23 Jul 2006) ViewCVS: http://svn.sourceforge.net/dunelegacy/?rev=36&view=rev Log Message: ----------- more font stuff Modified Paths: -------------- branches/dunks/include/Font.h branches/dunks/include/MainMenu.h branches/dunks/src/Application.cpp branches/dunks/src/Font.cpp branches/dunks/src/MainMenu.cpp branches/dunks/src/SConscript branches/dunks/wip/font.cpp Modified: branches/dunks/include/Font.h =================================================================== --- branches/dunks/include/Font.h 2006-07-23 15:40:55 UTC (rev 35) +++ branches/dunks/include/Font.h 2006-07-23 20:05:44 UTC (rev 36) @@ -5,19 +5,83 @@ #include "SDL.h" #include "SDL_ttf.h" +#include <map> +#include <string> + #define MIN_FONT_SIZE 6 #define MAX_FONT_SIZE 24 #define FONTS (MAX_FONT_SIZE - MIN_FONT_SIZE) +typedef unsigned short word; +typedef unsigned char byte; + +struct FNTHeader +{ + word fsize; /* Size of the file */ + word unknown1; /* Unknown entry (always 0x0500) */ + word unknown2; /* Unknown entry (always 0x000e) */ + word unknown3; /* Unknown entry (always 0x0014) */ + word wpos; /* Offset of char. widths array (abs. from beg. of file) */ + word cdata; /* Offset of char. graphics data (abs. from beg. of file) */ + word hpos; /* Offset of char. heights array (abs. from beg. of file) */ + word unknown4; /* Unknown entry (always 0x1012) */ + byte unknown5; // dunk- had to add this to get nchars read correctly + byte nchars; /* Number of characters in font minus 1*/ // dunk- the doc says word + byte height; /* Font height */ + byte maxw; /* Max. character width */ +}; + +struct FNTCharacter +{ + byte width; + byte height; + byte y_offset; + byte *bitmap; +}; + +class Font +{ + public: + Font(FNTCharacter* characters, FNTHeader* header); + ~Font(); + + void render(const char* text, SDL_Surface* surface, Uint16 x, Uint16 y); + + private: + FNTHeader* m_header; + FNTCharacter* m_characters; + word m_nchars; +}; + + class FontManager : public Singleton<FontManager> { friend class Singleton<FontManager>; + typedef std::map<const char*, Font*> FontList; + protected: FontManager(); ~FontManager(); public: + Font* getFont(const char* fn); + + private: + FontList m_fonts; + + Font* loadFont(const char* fn); +}; + +class TTFFontManager : public Singleton<TTFFontManager> +{ + friend class Singleton<TTFFontManager>; + + protected: + TTFFontManager(); + ~TTFFontManager(); + + public: TTF_Font* GetFont(int size); private: Modified: branches/dunks/include/MainMenu.h =================================================================== --- branches/dunks/include/MainMenu.h 2006-07-23 15:40:55 UTC (rev 35) +++ branches/dunks/include/MainMenu.h 2006-07-23 20:05:44 UTC (rev 36) @@ -1,23 +1,20 @@ #ifndef DUNE_MAINMENU_H #define DUNE_MAINMENU_H -#include "State.h" +#include "MenuBase.h" #include "gui2/Button.h" #include "gui2/VBox.h" -#include "SDL.h" - - -class MainMenuState : public State +class MainMenuState : public MenuBaseState { public: MainMenuState(); ~MainMenuState(); - void JustMadeActive(); - void JustMadeInactive(); + //void JustMadeActive(); + //void JustMadeInactive(); - int Execute(float dt); + //int Execute(float dt); void doSkirmish(); void doSingle(); @@ -26,9 +23,6 @@ virtual const char* GetName() { return "MainMenuState"; } private: - SDL_Surface* m_menuBackground; - //Window* m_menu; - VBox* m_vbox; GraphicButton* m_butSingle; Modified: branches/dunks/src/Application.cpp =================================================================== --- branches/dunks/src/Application.cpp 2006-07-23 15:40:55 UTC (rev 35) +++ branches/dunks/src/Application.cpp 2006-07-23 20:05:44 UTC (rev 36) @@ -193,7 +193,7 @@ videoFlags |= SDL_FULLSCREEN; m_screen = SDL_SetVideoMode(set->m_width, set->m_height, - SCREEN_BPP, videoFlags); + 8, videoFlags); if(!m_screen) { fprintf(stderr, "ERROR: Couldn't set video mode: %s\n", SDL_GetError()); @@ -264,6 +264,7 @@ const int fps_interval = 10 * 1000; // 10 seconds float fps; + Font* fnt = FontManager::Instance()->getFont("intro.fnt"); m_running = true; @@ -292,6 +293,8 @@ m_rootWidget->draw(m_screen); + fnt->render("ABCDEFGHIJKLMOPQRSTUVWXYZ", m_screen, 10, 10); + BlitCursor(); SDL_Flip(m_screen); @@ -323,6 +326,7 @@ switch (event.type) { case SDL_QUIT: + printf("QUIT!\n"); m_running = false; break; case SDL_MOUSEMOTION: Modified: branches/dunks/src/Font.cpp =================================================================== --- branches/dunks/src/Font.cpp 2006-07-23 15:40:55 UTC (rev 35) +++ branches/dunks/src/Font.cpp 2006-07-23 20:05:44 UTC (rev 36) @@ -3,9 +3,188 @@ #include <assert.h> #include <stdlib.h> +#include <stdio.h> +Font::Font(FNTCharacter* characters, FNTHeader* header) +{ + m_characters = characters; + m_header = header; +}; + +Font::~Font() +{ + delete [] m_characters; + delete m_header; +}; + +void Font::render(const char* text, SDL_Surface* surface, Uint16 offx, Uint16 offy) +{ + FNTCharacter* ch; + byte* bitmap; + Uint8* pixels = (Uint8*)surface->pixels; + + for (unsigned int c=0; c!=strlen(text); c++) + { + printf("char %c\n", text[c]); + 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) + { + 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)] = Uint8(hibyte); + }; + + //if (2 < ch->width) lobyte!=0) + { + pixels[(offx + x + 1) + ((ch->y_offset + y + offy) * surface->w)] = Uint8(lobyte); + }; + }; + + printf("\n"); + }; + offx += (2*ch->width) + 1; + }; + +}; + FontManager::FontManager() { + +}; + +FontManager::~FontManager() +{ + +}; + +Font* FontManager::getFont(const char* fn) +{ + FontList::iterator it = m_fonts.find(fn); + if (it == m_fonts.end()) + { + printf("loading %s\n", fn); + m_fonts[fn] = loadFont(fn); + }; + + return m_fonts[fn]; +}; + +Font* FontManager::loadFont(const char* fn) +{ + printf("loadFont %s\n", fn); + FILE* file = fopen(fn, "rb"); + + printf("sizeof word %u, sizeof byte %u\n", sizeof(word), sizeof(byte)); + + FNTHeader* header = new FNTHeader(); + + printf("fsize %d\n", header->fsize); + + fread(header, sizeof(FNTHeader), 1, file); + + 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"); + if (header->unknown3 != 0x0014) printf("failed unknown3\n"); + + printf("nchars %u\n", header->nchars); + + word* dchar = new word[header->nchars+1]; + + fread(dchar, sizeof(word), header->nchars+1, file); + + byte* wchar = new byte[header->nchars+1]; + + printf("wpos %d\n", header->wpos); + fseek(file, header->wpos, SEEK_SET); + long br = fread(wchar, sizeof(byte), header->nchars+1, file); + printf("br %ld %d\n", br, 1); + + if (wchar[0] != 8) printf("bad!!\n"); + + word* hchar = new word[header->nchars+1]; + + fseek(file, header->hpos, SEEK_SET); + fread(hchar, sizeof(word), header->nchars+1, file); + + fseek(file, header->cdata, SEEK_SET); + + FNTCharacter* characters = new FNTCharacter[header->nchars+1]; + + for (int i=0; i!=header->nchars+1; i++) + { + byte offset = hchar[i] & 0xFF; + byte height = hchar[i] >> 8; + byte width = wchar[i] / 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]); + + fseek(file, dchar[i], SEEK_SET); + byte* bitmap = new byte[width * height]; + fread(bitmap, sizeof(byte), width * height, file); + characters[i].bitmap = bitmap; + }; + + Font* font = new Font(characters, header); + + return font; + +}; + +// ------------------------------------------------------------------ + +TTFFontManager::TTFFontManager() +{ fprintf(stdout, "initializing font lib...\n"); if (TTF_Init() < 0) @@ -33,7 +212,7 @@ }; }; -FontManager::~FontManager() +TTFFontManager::~TTFFontManager() { /* for (int i=MIN_FONT_SIZE; i < MAX_FONT_SIZE; i++) @@ -45,7 +224,7 @@ TTF_Quit(); }; -TTF_Font* FontManager::GetFont(int size) +TTF_Font* TTFFontManager::GetFont(int size) { if (size < MIN_FONT_SIZE || size >= MAX_FONT_SIZE) { Modified: branches/dunks/src/MainMenu.cpp =================================================================== --- branches/dunks/src/MainMenu.cpp 2006-07-23 15:40:55 UTC (rev 35) +++ branches/dunks/src/MainMenu.cpp 2006-07-23 20:05:44 UTC (rev 36) @@ -66,7 +66,7 @@ m_vbox->setPos(x - 5, 312); m_vbox->reshape(); - Application::Instance()->RootWidget()->addChild(m_vbox); + m_container->addChild(m_vbox); }; MainMenuState::~MainMenuState() @@ -96,6 +96,7 @@ PopState(); }; +/* void MainMenuState::JustMadeActive() { Application::Instance()->RootWidget()->addChild(m_vbox); @@ -108,9 +109,11 @@ State::JustMadeInactive(); }; + int MainMenuState::Execute(float dt) { Application::Instance()->BlitCentered(m_menuBackground); return 0; }; +*/ Modified: branches/dunks/src/SConscript =================================================================== --- branches/dunks/src/SConscript 2006-07-23 15:40:55 UTC (rev 35) +++ branches/dunks/src/SConscript 2006-07-23 20:05:44 UTC (rev 36) @@ -18,6 +18,7 @@ "DataFile.cpp", "TopLevelState.cpp", + "MenuBase.cpp", "MainMenu.cpp", "SingleMenu.cpp", Modified: branches/dunks/wip/font.cpp =================================================================== --- branches/dunks/wip/font.cpp 2006-07-23 15:40:55 UTC (rev 35) +++ branches/dunks/wip/font.cpp 2006-07-23 20:05:44 UTC (rev 36) @@ -31,7 +31,7 @@ int main(int argc, char* argv[]) { - FILE* file = fopen("new10p.fnt", "rb"); + FILE* file = fopen("intro.fnt", "rb"); FNTHeader header; @@ -77,7 +77,7 @@ byte offset = hchar[i] & 0xFF; byte height = hchar[i] >> 8; byte width = wchar[i] / 2; - printf("%d width = %hd offset = %hd height = %hd\n", i, width, offset, height); + printf("%d %c width = %hd offset = %hd height = %hd\n", i, i, width, offset, height); characters[i].width = width; characters[i].height = height; @@ -109,24 +109,14 @@ byte lobyte = bitmap[x + (y*width)] >> 4; byte hibyte = bitmap[x + (y*width)] & 0x0F; - if (hibyte==0) { - printf(" "); + printf("%02hd", hibyte); } - else - { - printf("%2hd", hibyte); - } printf("."); - if (lobyte==0) { - printf(" "); - } - else - { - printf("%2hd", lobyte); + printf("%02hd", lobyte); }; printf("."); @@ -138,7 +128,7 @@ { for (byte x=0; x!=width; x++) { - printf(" . ."); + printf("00.00."); }; printf("\n"); }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |