diff --git a/src/game/game.cpp b/src/game/game.cpp index 977fb4c73..f5d8dd769 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -10,7 +10,7 @@ // /**@name game.c - The game set-up and creation. */ // -// (c) Copyright 1998-2004 by Lutz Sammer, Andreas Arens and +// (c) Copyright 1998-2004 by Lutz Sammer, Andreas Arens, and // Jimmy Salmon // // This program is free software; you can redistribute it and/or modify @@ -453,11 +453,6 @@ global void CreateGame(char* filename, WorldMap* map) InitSelections(); - DebugLevel0("Graphics uses %d bytes (%d KB, %d MB)\n" _C_ - AllocatedGraphicMemory _C_ - AllocatedGraphicMemory / 1024 _C_ - AllocatedGraphicMemory / 1024 / 1024); - CreateMinimap(); // create minimap for pud InitMap(); // setup draw functions InitMapFogOfWar(); // build tables for fog of war diff --git a/src/include/video.h b/src/include/video.h index 9cac38b2d..76c0e5fd4 100644 --- a/src/include/video.h +++ b/src/include/video.h @@ -63,10 +63,6 @@ typedef struct _unit_colors_ { SDL_Color Colors[4]; } UnitColors; -#ifdef DEBUG -extern unsigned AllocatedGraphicMemory; /// Allocated memory for objects -#endif - /** ** Event call back. ** @@ -135,12 +131,10 @@ extern void VideoPaletteListRemove(SDL_Surface* surface); ** If =0, video framerate is not synchronized. 100 is exact ** CYCLES_PER_SECOND (30). Game will try to redraw screen within ** intervals of VideoSyncSpeed, not more, not less. - ** @see CYCLES_PER_SECOND @see VideoInterrupts + ** @see CYCLES_PER_SECOND */ extern int VideoSyncSpeed; -extern volatile int VideoInterrupts; - extern int SkipFrames; /// Wanted videomode, fullscreen or windowed. @@ -208,7 +202,7 @@ extern void MakePlayerColorTexture(Graphic** g, Graphic* graphic, int frame, #endif /// Load graphic -extern Graphic* LoadGraphic(const char* file); +#define LoadGraphic(file) LoadSprite(file, 0, 0) /// Flip graphic and store in graphic->SurfaceFlip extern void FlipGraphic(Graphic* graphic); @@ -226,12 +220,6 @@ extern Graphic* MakeGraphic(SDL_Surface* surface); /// changing the colormap and so on.. extern void DisplayPicture(const char *name); - /// Init graphic -extern void InitGraphic(void); - - /// Init sprite -extern void InitSprite(void); - /// Init line draw extern void InitLineDraw(void); @@ -269,9 +257,6 @@ extern void SaveScreenshotPNG(const char* name); /// Creates a hardware palette from an independent Palette struct. extern SDL_Palette* VideoCreateNewPalette(const SDL_Palette* palette); - /// Prints warning if video is too slow.. -extern void CheckVideoInterrupts(void); - /// Process all system events. Returns if the time for a frame is over extern void WaitEventsOneFrame(const EventCallback* callbacks); diff --git a/src/stratagus/mainloop.cpp b/src/stratagus/mainloop.cpp index b8c2bcb19..ca124f345 100644 --- a/src/stratagus/mainloop.cpp +++ b/src/stratagus/mainloop.cpp @@ -929,7 +929,7 @@ global void GameMainLoop(void) if (FastForwardCycle >= GameCycle) { MustRedraw = RedrawEverything; } - if (MustRedraw /* && !VideoInterrupts */ && + if (MustRedraw && (FastForwardCycle <= GameCycle || GameCycle <= 10 || !(GameCycle & 0x3f))) { if (Callbacks == &MenuCallbacks) { @@ -956,8 +956,6 @@ global void GameMainLoop(void) #endif } - CheckVideoInterrupts(); // look if already an interrupt - if (FastForwardCycle == GameCycle) { VideoSyncSpeed = RealVideoSyncSpeed; } diff --git a/src/stratagus/script_player.cpp b/src/stratagus/script_player.cpp index 770c0cbec..0fbad0b08 100644 --- a/src/stratagus/script_player.cpp +++ b/src/stratagus/script_player.cpp @@ -322,7 +322,7 @@ local int CclPlayer(lua_State* l) lua_rawgeti(l, j + 1, 3); b = LuaToNumber(l, -1); lua_pop(l, 1); - player->Color = SDL_MapRGB(TheScreen->format, r, g, b); + player->Color = VideoMapRGB(TheScreen->format, r, g, b); } else if (!strcmp(value, "timers")) { if (!lua_istable(l, j + 1)) { LuaError(l, "incorrect argument"); diff --git a/src/video/graphic.cpp b/src/video/graphic.cpp index 7abfa40d4..b5f77d5ea 100644 --- a/src/video/graphic.cpp +++ b/src/video/graphic.cpp @@ -202,10 +202,6 @@ global void VideoDrawSubClipTrans(const Graphic* graphic, int gx, int gy, */ global void VideoFree(Graphic* graphic) { -#ifdef DEBUG - AllocatedGraphicMemory -= sizeof(Graphic); -#endif - #ifdef USE_OPENGL if (graphic->NumTextureNames) { glDeleteTextures(graphic->NumTextureNames, graphic->TextureNames); @@ -214,20 +210,12 @@ global void VideoFree(Graphic* graphic) #endif if (graphic->Surface) { -#ifdef DEBUG - AllocatedGraphicMemory -= - graphic->Width * graphic->Height * graphic->Surface->format->BytesPerPixel; -#endif if (graphic->Surface->format->BytesPerPixel == 1) { VideoPaletteListRemove(graphic->Surface); } SDL_FreeSurface(graphic->Surface); } if (graphic->SurfaceFlip) { -#ifdef DEBUG - AllocatedGraphicMemory -= - graphic->Width * graphic->Height * graphic->SurfaceFlip->format->BytesPerPixel; -#endif if (graphic->SurfaceFlip->format->BytesPerPixel == 1) { VideoPaletteListRemove(graphic->SurfaceFlip); } @@ -260,9 +248,6 @@ global Graphic* MakeGraphic(SDL_Surface* surface) fprintf(stderr, "Out of memory\n"); ExitFatal(-1); } -#ifdef DEBUG - AllocatedGraphicMemory += sizeof(Graphic); -#endif graphic->Surface = surface; graphic->Width = surface->w; @@ -288,11 +273,9 @@ global void FlipGraphic(Graphic* graphic) s = graphic->SurfaceFlip = SDL_ConvertSurface(graphic->Surface, graphic->Surface->format, SDL_SWSURFACE); - VideoPaletteListAdd(graphic->SurfaceFlip); -#ifdef DEBUG - AllocatedGraphicMemory += - graphic->Width * graphic->Height * graphic->Surface->format->BytesPerPixel; -#endif + if (graphic->SurfaceFlip->format->BytesPerPixel == 1) { + VideoPaletteListAdd(graphic->SurfaceFlip); + } SDL_LockSurface(graphic->Surface); SDL_LockSurface(s); @@ -500,9 +483,6 @@ global void ResizeGraphic(Graphic* g, int w, int h) SDL_LockSurface(g->Surface); data = (unsigned char*)malloc(w * h); -#ifdef DEBUG - AllocatedGraphicMemory += w * h; -#endif x = 0; for (i = 0; i < h; ++i) { @@ -519,7 +499,9 @@ global void ResizeGraphic(Graphic* g, int w, int h) SDL_FreeSurface(g->Surface); g->Surface = SDL_CreateRGBSurfaceFrom(data, w, h, 8, w, 0, 0, 0, 0); - VideoPaletteListAdd(g->Surface); + if (g->Surface->format->BytesPerPixel == 1) { + VideoPaletteListAdd(g->Surface); + } SDL_SetPalette(g->Surface, SDL_LOGPAL | SDL_PHYSPAL, pal, 0, 256); SDL_SetColorKey(g->Surface, SDL_SRCCOLORKEY | SDL_RLEACCEL, 255); @@ -533,23 +515,4 @@ global void ResizeGraphic(Graphic* g, int w, int h) #endif } -/** -** Load graphic from file. -** -** @param name File name. -** -** @return Graphic object. -*/ -global Graphic* LoadGraphic(const char* name) -{ - return LoadSprite(name, 0, 0); -} - -/** -** Init graphic -*/ -global void InitGraphic(void) -{ -} - //@} diff --git a/src/video/sdl.cpp b/src/video/sdl.cpp index dcc78ef57..5c705d728 100644 --- a/src/video/sdl.cpp +++ b/src/video/sdl.cpp @@ -602,6 +602,8 @@ global void WaitEventsOneFrame(const EventCallback* callbacks) int s; SDL_Event event[1]; Uint32 ticks; + int interrupts; + #if defined(WITH_SOUND) && !defined(USE_SDLA) // FIXME: ugly hack, move into sound part!!! @@ -634,16 +636,18 @@ global void WaitEventsOneFrame(const EventCallback* callbacks) InputKeyTimeout(callbacks, ticks); CursorAnimate(ticks); + interrupts = 0; + for (;;) { // // Time of frame over? This makes the CPU happy. :( // ticks = SDL_GetTicks(); - if (!VideoInterrupts && ticks + 11 < NextFrameTicks) { + if (!interrupts && ticks + 11 < NextFrameTicks) { SDL_Delay(10); } while (ticks >= NextFrameTicks) { - ++VideoInterrupts; + ++interrupts; FrameFraction += FrameRemainder; if (FrameFraction > 10) { FrameFraction -= 10; @@ -723,30 +727,16 @@ global void WaitEventsOneFrame(const EventCallback* callbacks) // // No more input and time for frame over: return // - if (!i && s <= 0 && VideoInterrupts) { + if (!i && s <= 0 && interrupts) { break; } } - // - // Prepare return, time for one frame is over. - // - VideoInterrupts = 0; - if (!SkipGameCycle--) { SkipGameCycle = SkipFrames; } } -/** -** Check video interrupt. -** -** Display and count too slow frames. -*/ -global void CheckVideoInterrupts(void) -{ -} - /** ** Realize video memory. */ diff --git a/src/video/sprite.cpp b/src/video/sprite.cpp index 54425ec45..491d7c7c7 100644 --- a/src/video/sprite.cpp +++ b/src/video/sprite.cpp @@ -373,25 +373,6 @@ global void VideoDrawClipTransX(const Graphic* sprite, unsigned frame, int x, in } #endif -local void FreeSprite(Graphic* graphic) -{ - int i; - -#ifdef DEBUG_TODO - AllocatedGraphicMemory -= graphic->Size; - AllocatedGraphicMemory -= sizeof(Graphic); -#endif -#ifdef USE_OPENGL - if (graphic->NumTextureNames) { - glDeleteTextures(graphic->NumTextureNames, graphic->TextureNames); - free(graphic->TextureNames); - } -#endif - for (i = 0; i < graphic->NumFrames; ++i) { - SDL_FreeSurface(&graphic->Surface[i]); - } -} - /*---------------------------------------------------------------------------- -- Global functions ----------------------------------------------------------------------------*/ @@ -472,11 +453,4 @@ global void MakeShadowSprite(Graphic* graphic) } } -/** -** Init sprite -*/ -global void InitSprite(void) -{ -} - //@} diff --git a/src/video/video.cpp b/src/video/video.cpp index 54eea2680..5fe9086dd 100644 --- a/src/video/video.cpp +++ b/src/video/video.cpp @@ -10,7 +10,7 @@ // /**@name video.c - The universal video functions. */ // -// (c) Copyright 1999-2004 by Lutz Sammer and Nehal Mistry +// (c) Copyright 1999-2004 by Lutz Sammer, Nehal Mistry, and Jimmy Salmon // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -111,68 +111,63 @@ #endif /*---------------------------------------------------------------------------- --- Declarations +-- Declarations ----------------------------------------------------------------------------*/ /** -** Structure of pushed clippings. +** Structure of pushed clippings. */ typedef struct _clip_ { - struct _clip_* Next; /// next pushed clipping. - int X1; /// pushed clipping top left - int Y1; /// pushed clipping top left - int X2; /// pushed clipping bottom right - int Y2; /// pushed clipping bottom right + struct _clip_* Next; /// next pushed clipping. + int X1; /// pushed clipping top left + int Y1; /// pushed clipping top left + int X2; /// pushed clipping bottom right + int Y2; /// pushed clipping bottom right } Clip; /*---------------------------------------------------------------------------- --- Externals +-- Externals ----------------------------------------------------------------------------*/ -extern void InitVideoSdl(void); /// Init SDL video hardware driver +extern void InitVideoSdl(void); /// Init SDL video hardware driver -extern void SdlLockScreen(void); /// Do SDL hardware lock -extern void SdlUnlockScreen(void); /// Do SDL hardware unlock +extern void SdlLockScreen(void); /// Do SDL hardware lock +extern void SdlUnlockScreen(void); /// Do SDL hardware unlock /*---------------------------------------------------------------------------- --- Variables +-- Variables ----------------------------------------------------------------------------*/ -global char VideoFullScreen; /// true fullscreen wanted -global char VideoForceFullScreen; /// fullscreen set from commandline +global char VideoFullScreen; /// true fullscreen wanted +global char VideoForceFullScreen; /// fullscreen set from commandline -global int ColorCycleAll; /// Flag Color Cycle with all palettes +global int ColorCycleAll; /// Flag Color Cycle with all palettes -global int ClipX1; /// current clipping top left -global int ClipY1; /// current clipping top left -global int ClipX2; /// current clipping bottom right -global int ClipY2; /// current clipping bottom right +global int ClipX1; /// current clipping top left +global int ClipY1; /// current clipping top left +global int ClipX2; /// current clipping bottom right +global int ClipY2; /// current clipping bottom right -local Clip* Clips; /// stack of all clips -local Clip* ClipsGarbage; /// garbage-list of available clips - -#ifdef DEBUG -global unsigned AllocatedGraphicMemory; /// Allocated memory for objects -#endif +local Clip* Clips; /// stack of all clips +local Clip* ClipsGarbage; /// garbage-list of available clips /** - ** Architecture-dependant video depth. Set by InitVideoXXX, if 0. - ** (8,15,16,24,32) - ** @see InitVideo @see InitVideoSdl - ** @see main + ** Architecture-dependant video depth. Set by InitVideoXXX, if 0. + ** (8,15,16,24,32) + ** @see InitVideo @see InitVideoSdl + ** @see main */ global int VideoDepth; /** - ** Architecture-dependant videomemory. Set by InitVideoXXX. - ** FIXME: need a new function to set it, see #ifdef SDL code - ** @see InitVideo @see InitVideoSdl - ** @see VMemType + ** Architecture-dependant videomemory. Set by InitVideoXXX. + ** FIXME: need a new function to set it, see #ifdef SDL code + ** @see InitVideo @see InitVideoSdl + ** @see VMemType */ global SDL_Surface* TheScreen; global int VideoSyncSpeed = 100; /// 0 disable interrupts -global volatile int VideoInterrupts; /// be happy, were are quicker global int SkipFrames; /// Skip this frames global int ColorWaterCycleStart; @@ -197,20 +192,20 @@ Uint32 ColorYellow; /*---------------------------------------------------------------------------- --- Functions +-- Functions ----------------------------------------------------------------------------*/ /** -** Clip Rectangle to another rectangle +** Clip Rectangle to another rectangle ** -** @param left Left X original rectangle coordinate. -** @param top Top Y original rectangle coordinate. -** @param right Right X original rectangle coordinate. -** @param bottom Bottom Y original rectangle coordinate. -** @param x1 Left X bounding rectangle coordinate. -** @param y1 Top Y bounding rectangle coordinate. -** @param x2 Right X bounding rectangle coordinate. -** @param y2 Bottom Y bounding rectangle coordinate. +** @param left Left X original rectangle coordinate. +** @param top Top Y original rectangle coordinate. +** @param right Right X original rectangle coordinate. +** @param bottom Bottom Y original rectangle coordinate. +** @param x1 Left X bounding rectangle coordinate. +** @param y1 Top Y bounding rectangle coordinate. +** @param x2 Right X bounding rectangle coordinate. +** @param y2 Bottom Y bounding rectangle coordinate. **/ global void ClipRectToRect(int* left, int* top, int* right,int* bottom, int x1, int y1, int x2, int y2) @@ -251,12 +246,12 @@ global void ClipRectToRect(int* left, int* top, int* right,int* bottom, } /** -** Set clipping for graphic routines. +** Set clipping for graphic routines. ** -** @param left Left X screen coordinate. -** @param top Top Y screen coordinate. -** @param right Right X screen coordinate. -** @param bottom Bottom Y screen coordinate. +** @param left Left X screen coordinate. +** @param top Top Y screen coordinate. +** @param right Right X screen coordinate. +** @param bottom Bottom Y screen coordinate. */ global void SetClipping(int left, int top, int right, int bottom) { @@ -265,7 +260,7 @@ global void SetClipping(int left, int top, int right, int bottom) top < 0 || top >= VideoHeight || right < 0 || right >= VideoWidth || bottom < 0 || bottom >= VideoHeight) { DebugLevel0Fn("Wrong clipping %d->%d %d->%d, write cleaner code.\n" _C_ - left _C_ right _C_ top _C_ bottom); + left _C_ right _C_ top _C_ bottom); // DebugCheck(1); } #endif @@ -278,16 +273,16 @@ global void SetClipping(int left, int top, int right, int bottom) } /** -** Set clipping for graphic routines. This clips against the current clipping. +** Set clipping for graphic routines. This clips against the current clipping. ** -** @param left Left X screen coordinate. -** @param top Top Y screen coordinate. -** @param right Right X screen coordinate. -** @param bottom Bottom Y screen coordinate. +** @param left Left X screen coordinate. +** @param top Top Y screen coordinate. +** @param right Right X screen coordinate. +** @param bottom Bottom Y screen coordinate. */ global void SetClipToClip(int left, int top, int right, int bottom) { - // No warnings... exceeding is expected. + // No warnings... exceeding is expected. ClipRectToRect(&left, &top, &right, &bottom, ClipX1, ClipY1, ClipX2, ClipY2); ClipX1 = left; @@ -297,7 +292,7 @@ global void SetClipToClip(int left, int top, int right, int bottom) } /** -** Push current clipping. +** Push current clipping. */ global void PushClipping(void) { @@ -318,7 +313,7 @@ global void PushClipping(void) } /** -** Pop current clipping. +** Pop current clipping. */ global void PopClipping(void) { @@ -385,10 +380,10 @@ global void VideoPaletteListRemove(SDL_Surface* surface) } /** -** Load a picture and display it on the screen (full screen), -** changing the colormap and so on.. +** Load a picture and display it on the screen (full screen), +** changing the colormap and so on.. ** -** @param name Name of the picture (file) to display. +** @param name Name of the picture (file) to display. */ global void DisplayPicture(const char* name) { @@ -478,11 +473,11 @@ global void ColorCycle(void) } /*---------------------------------------------------------------------------- --- Functions +-- Functions ----------------------------------------------------------------------------*/ /** -** Lock the screen for write access. +** Lock the screen for write access. */ global void VideoLockScreen(void) { @@ -492,7 +487,7 @@ global void VideoLockScreen(void) } /** -** Unlock the screen for write access. +** Unlock the screen for write access. */ global void VideoUnlockScreen(void) { @@ -502,7 +497,7 @@ global void VideoUnlockScreen(void) } /** -** Clear the video screen. +** Clear the video screen. */ global void VideoClearScreen(void) { @@ -510,7 +505,7 @@ global void VideoClearScreen(void) } /** -** Return ticks in ms since start. +** Return ticks in ms since start. */ global unsigned long GetTicks(void) { @@ -520,7 +515,7 @@ global unsigned long GetTicks(void) } /** -** Video initialize. +** Video initialize. */ global void InitVideo(void) { @@ -528,15 +523,10 @@ global void InitVideo(void) InitVideoSdl(); #endif - // - // Init video sub modules - // - InitGraphic(); InitLineDraw(); - InitSprite(); #ifdef NEW_DECODRAW -// Use the decoration mechanism to only redraw what is needed on screen update + // Use the decoration mechanism to only redraw what is needed on screen update DecorationInit(); #endif }