diff --git a/Rules.make b/Rules.make index 0d08f7303..062b86743 100644 --- a/Rules.make +++ b/Rules.make @@ -169,7 +169,7 @@ XIFLAGS = -I/usr/X11R6/include -I/usr/local/include \ PROFILE= -pg # Version -VERSION= '-DVERSION="1.17pre1-build6"' +VERSION= '-DVERSION="1.17pre1-build7"' ############################################################################ # below this, nothing should be changed! @@ -204,7 +204,7 @@ IFLAGS= -I$(TOPDIR)/src/include $(XIFLAGS) ## define flags DEBUG= -DDEBUG #-DNEW_AI # -DFLAG_DEBUG DFLAGS= $(THREAD) $(CCL) $(VERSION) $(GLIB) $(VIDEO) $(ZDEFS) $(DSOUND) \ - $(DEBUG) -DNEW_UNIT -DNEW_NETWORK -DNEW_VIDEO # -DNEW_NAMES + $(DEBUG) -DNEW_UNIT -DNEW_NETWORK -DUNIT_ON_MAP # -DNEW_NAMES ## choose optimise level #CFLAGS=-g -O0 $(PROFILE) -pipe -Wall -Werror $(IFLAGS) $(DFLAGS) diff --git a/Rules.make.orig b/Rules.make.orig index e17645fd7..308692cc1 100644 --- a/Rules.make.orig +++ b/Rules.make.orig @@ -169,7 +169,7 @@ XIFLAGS = -I/usr/X11R6/include -I/usr/local/include \ #PROFILE= -pg # Version -VERSION= '-DVERSION="1.17pre1-build6"' +VERSION= '-DVERSION="1.17pre1-build7"' ############################################################################ # below this, nothing should be changed! @@ -204,7 +204,7 @@ IFLAGS= -I$(TOPDIR)/src/include $(XIFLAGS) ## define flags DEBUG= -DDEBUG #-DNEW_AI # -DFLAG_DEBUG DFLAGS= $(THREAD) $(CCL) $(VERSION) $(GLIB) $(VIDEO) $(ZDEFS) $(DSOUND) \ - $(DEBUG) -DNEW_UNIT -DNEW_NETWORK -DNEW_VIDEO # -DNEW_NAMES -DNEW_FOW + $(DEBUG) -DNEW_UNIT -DNEW_NETWORK -DUNIT_ON_MAP # -DNEW_NAMES -DNEW_FOW ## choose optimise level #CFLAGS=-g -O0 $(PROFILE) -pipe -Wall -Werror $(IFLAGS) $(DFLAGS) diff --git a/doc/faq.html b/doc/faq.html index a89e21a1f..120bafb49 100644 --- a/doc/faq.html +++ b/doc/faq.html @@ -126,7 +126,7 @@ to start. support and enable it (in data/ccl/sound.ccl) or and add to the line <P> DFLAGS= $(THREAD) $(GUILE) $(VERSION) $(GLIB) $(VIDEO) $(ZDEFS) $(DSOUND) -$(DEBUG) -DNEW_VIDEO +$(DEBUG) <P> "-DSLOW_INPUT" in Rules.make. diff --git a/setup b/setup index 53d1d92f2..0fe130f4e 100755 --- a/setup +++ b/setup @@ -23,9 +23,9 @@ cat << .. > $RULESFILE #------------------------------------------------------------------------------ # HERE ARE SOME USER-CONFIGURABLE VARIABLES -EXTRA_CFLAGS="-DSLOW_INPUT -DNEW_UNIT -DNEW_NETWORK -DNEW_VIDEO" +EXTRA_CFLAGS="-DSLOW_INPUT -DNEW_UNIT -DUNIT_ON_MAP -DNEW_NETWORK" # This could be used for experimental versions -# -DNEW_UNIT -DNEW_NETWORK -DNEW_FOW -DNEW_NAMES -DNEW_VIDEO +# -DNEW_UNIT -DNEW_NETWORK -DNEW_FOW -DUNIT_ON_MAP -DNEW_NAMES # Compile commands CC=gcc @@ -35,7 +35,7 @@ MAKE=make #------------------------------------------------------------------------------ # DON'T CHANGE ANYTHING FROM HERE DOWN UNLESS YOU KNOW WHAT YOU ARE DOING -VERSION="-DVERSION=\"1.17pre1-build6\"" +VERSION="-DVERSION=\"1.17pre1-build7\"" WIN32=-1 # Choose optimization level diff --git a/src/action/action_attack.cpp b/src/action/action_attack.cpp index 77933ad98..a7c9f4686 100644 --- a/src/action/action_attack.cpp +++ b/src/action/action_attack.cpp @@ -56,7 +56,6 @@ local void DoActionAttackGeneric(Unit* unit,const Animation* attack) flags=UnitShowAnimation(unit,attack); -#ifdef NEW_VIDEO IfDebug( if( (unit->Frame&127)>=VideoGraphicFrames(unit->Type->Sprite) ) { DebugLevel0Fn("Oops what this %s %d,%d %d #%d\n" @@ -66,23 +65,8 @@ local void DoActionAttackGeneric(Unit* unit,const Animation* attack) ,VideoGraphicFrames(unit->Type->Sprite)); SaveUnit(unit,stdout); abort(); - return; } ); -#else - IfDebug( - if( (unit->Frame&127)>=unit->Type->RleSprite->NumFrames ) { - DebugLevel0Fn("Oops what this %s %d,%d %d #%d\n" - ,unit->Type->Ident - ,oframe,oframe&127 - ,unit->Frame&127 - ,unit->Type->RleSprite->NumFrames); - SaveUnit(unit,stdout); - abort(); - return; - } - ); -#endif if( (flags&AnimationSound) ) { PlayUnitSound(unit,VoiceAttacking); diff --git a/src/include/Makefile b/src/include/Makefile index bfeaa0383..e9868f6d5 100644 --- a/src/include/Makefile +++ b/src/include/Makefile @@ -29,7 +29,7 @@ HDRS = actions.h ai.h ccl.h freecraft.h construct.h cursor.h font.h icons.h \ image.h interface.h map.h minimap.h missile.h pathfinder.h player.h \ pud.h tileset.h unit.h unittype.h upgrade.h upgrade_structs.h \ ccl_sound.h sound.h sound_id.h unitsound.h wav.h sound_server.h \ - video.h new_video.h network.h goal.h ui.h button.h menus.h \ + video.h network.h goal.h ui.h button.h menus.h \ siod.h siodp.h iolib.h depend.h myendian.h rdtsc.h \ etlib/generic.h etlib/xmalloc.h etlib/hash.h etlib/dllist.h diff --git a/src/include/construct.h b/src/include/construct.h index a1f7e88d1..a1ba427e4 100644 --- a/src/include/construct.h +++ b/src/include/construct.h @@ -9,39 +9,57 @@ // FreeCraft - A free fantasy real time strategy game engine // /**@name construct.h - The constructions headerfile. */ -/* -** (c) Copyright 1998-2000 by Lutz Sammer -** -** $Id$ -*/ +// +// (c) Copyright 1998-2000 by Lutz Sammer +// +// $Id$ #ifndef __CONSTRUCT_H__ #define __CONSTRUCT_H__ //@{ +// FIXME: constructions must be configurable, referenced by indenifiers... + /*---------------------------------------------------------------------------- --- CONSTRUCTION +-- Includes ----------------------------------------------------------------------------*/ -typedef struct _construction_ { - char* File[TilesetMax]; // sprite file +#include "tileset.h" +#include "video.h" - int Width; // " width - int Height; // " height +/*---------------------------------------------------------------------------- +-- Declarations +----------------------------------------------------------------------------*/ + +/** +** Constructions: shown during construction of a building. +*/ +typedef struct _construction_ { + char* Ident; /// construction identifier + char* File[TilesetMax]; /// sprite file + + int Width; /// " width + int Height; /// " height // --- FILLED UP --- -#ifdef NEW_VIDEO Graphic* Sprite; /// construction sprite image -#else - RleSprite* RleSprite; /// construction sprite image -#endif } Construction; -#define ConstructionWall 15 +/*---------------------------------------------------------------------------- +-- Macros +----------------------------------------------------------------------------*/ +#define ConstructionWall 15 /// ident nr for wall under construction + +/*---------------------------------------------------------------------------- +-- Fucntions +----------------------------------------------------------------------------*/ + + /// Load the graphics for constructions extern void LoadConstructions(void); + /// Draw a construction extern void DrawConstruction(int type,int image,int x,int y); //@} diff --git a/src/include/cursor.h b/src/include/cursor.h index a88aa0b97..a6163c596 100644 --- a/src/include/cursor.h +++ b/src/include/cursor.h @@ -25,6 +25,7 @@ ----------------------------------------------------------------------------*/ #include "player.h" +#include "video.h" /*---------------------------------------------------------------------------- -- Definitions @@ -39,7 +40,6 @@ typedef struct _cursor_type_ CursorType; ** private type which specifies current cursor type */ struct _cursor_type_ { -#ifdef NEW_VIDEO const char* File[PlayerMaxRaces]; /// resource filename one for each race // FIXME: this must be extra for each file (different sizes for the races) @@ -52,20 +52,6 @@ struct _cursor_type_ { // --- FILLED UP --- Graphic* Sprite; /// cursor sprite image -#else - const char* File[PlayerMaxRaces]; /// resource filename one for each race - -// FIXME: this must be extra for each file (different sizes for the races) -// FIXME: or must define that each image has the same size - int HotX; /// hot point x - int HotY; /// hot point y - int Width; /// width of cursor - int Height; /// height of cursor - -// --- FILLED UP --- - - RleSprite* RleSprite; /// cursor sprite image -#endif }; /// cursor type (enumerated) FIXME: should remove the enumeration diff --git a/src/include/icons.h b/src/include/icons.h index 95d1d37c2..485eac6ca 100644 --- a/src/include/icons.h +++ b/src/include/icons.h @@ -13,7 +13,6 @@ // (c) Copyright 1998-2000 by Lutz Sammer // // $Id$ -// #ifndef __ICONS_H__ #define __ICONS_H__ @@ -66,13 +65,8 @@ extern void CleanIcons(void); /// cleanup extern IconId IconByIdent(const char* ident); /// name -> icon extern const char* IdentOfIcon(IconId icon); /// icon -> name -#ifdef NEW_VIDEO /// draw icons of an unit extern void DrawUnitIcon(const void*,IconId,unsigned,unsigned,unsigned); -#else - /// draw icons of an unit -extern void DrawUnitIcon(IconId num,unsigned flags,unsigned x,unsigned y); -#endif //@} diff --git a/src/include/map.h b/src/include/map.h index da265b81a..86a145c89 100644 --- a/src/include/map.h +++ b/src/include/map.h @@ -25,7 +25,7 @@ ----------------------------------------------------------------------------*/ #include "unit.h" -#include "new_video.h" +#include "video.h" #include "tileset.h" /*---------------------------------------------------------------------------- diff --git a/src/include/missile.h b/src/include/missile.h index 5fe0f6027..c11fa10fc 100644 --- a/src/include/missile.h +++ b/src/include/missile.h @@ -65,11 +65,7 @@ struct _missile_type_ { MissileType*ImpactMissile; /// Missile produces an impact // --- FILLED UP --- -#ifdef NEW_VIDEO Graphic* Sprite; /// missile sprite image -#else - RleSprite* RleSprite; /// missile sprite image -#endif }; /// how many missile type are maximal supported diff --git a/src/include/new_video.h b/src/include/new_video.h deleted file mode 100644 index ef63c1951..000000000 --- a/src/include/new_video.h +++ /dev/null @@ -1,573 +0,0 @@ -// ___________ _________ _____ __ -// \_ _____/______ ____ ____ \_ ___ \____________ _/ ____\/ |_ -// | __) \_ __ \_/ __ \_/ __ \/ \ \/\_ __ \__ \\ __\\ __\ -// | \ | | \/\ ___/\ ___/\ \____| | \// __ \| | | | -// \___ / |__| \___ >\___ >\______ /|__| (____ /__| |__| -// \/ \/ \/ \/ \/ -// ______________________ ______________________ -// T H E W A R B E G I N S -// FreeCraft - A free fantasy real time strategy game engine -// -/**@name new_video.h - The video headerfile. */ -// -// (c) Copyright 1999,2000 by Lutz Sammer -// -// $Id$ -// - -#ifndef __NEW_VIDEO_H__ -#define __NEW_VIDEO_H__ - -//@{ - -// Little NOTE: this should become the new video headerfile - -/*---------------------------------------------------------------------------- --- Includes -----------------------------------------------------------------------------*/ - -/*---------------------------------------------------------------------------- --- Declarations -----------------------------------------------------------------------------*/ - -typedef unsigned char VMemType8; /// 8 bpp modes pointer -typedef unsigned short VMemType16; /// 16 bpp modes pointer -typedef struct { char a,b,c;} VMemType24;/// 24 bpp modes pointer -typedef unsigned long VMemType32; /// 32 bpp modes pointer - -/** -** General video mode pointer. -** -** @see VMemType8 @see VMemType16 @see VMemType24 @see VMemType32 -*/ -typedef union __vmem_type__ { - VMemType8 D8; /// 8 bpp access - VMemType16 D16; /// 16 bpp access - VMemType24 D24; /// 24 bpp access - VMemType32 D32; /// 32 bpp access -} VMemType; - - /// MACRO defines speed of colorcycling FIXME: should be made configurable -#define COLOR_CYCLE_SPEED (FRAMES_PER_SECOND/4) - -// FIXME: not quite correct for new multiple palette version - /// System-Wide used colors. -enum _sys_colors_ { - ColorBlack = 0, /// use for black - ColorDarkGreen = 149, - ColorBlue = 206, - ColorWhite = 246, - ColorNPC = 247, - ColorGray = 248, - ColorRed = 249, - ColorGreen = 250, - ColorYellow = 251, - ColorBlinkRed = 252, - ColorViolett = 253, - -// FIXME: this should some where made configurable - ColorWaterCycleStart = 38, /// color # start for color cycling - ColorWaterCycleEnd = 47, /// color # end for color cycling - ColorIconCycleStart = 240, /// color # start for color cycling - ColorIconCycleEnd = 244 /// color # end for color cycling -}; - -typedef enum _sys_colors_ SysColors; /// System-Wide used colors. - -typedef struct _palette_ Palette; /// palette typedef - -/// Palette structure. -struct _palette_ { - unsigned char r; /// red component - unsigned char g; /// green component - unsigned char b; /// blue component -}; - -typedef unsigned char GraphicData; /// generic graphic data type - -/** -** General graphic object typedef. (forward) -*/ -typedef struct _graphic_ Graphic; - -/** -** General graphic object type. -*/ -typedef struct _graphic_type_ { - /** - ** Draw the object unclipped. - ** - ** @param o pointer to object - ** @param f number of frame (object index) - ** @param x x coordinate on the screen - ** @param y y coordinate on the screen - */ - void (*Draw) (const Graphic* o,unsigned f,int x,int y); - /** - ** Draw the object unclipped and flipped in X direction. - ** - ** @param o pointer to object - ** @param f number of frame (object index) - ** @param x x coordinate on the screen - ** @param y y coordinate on the screen - */ - void (*DrawX) (const Graphic* o,unsigned f,int x,int y); - /** - ** Draw the object clipped to the current clipping. - ** - ** @param o pointer to object - ** @param f number of frame (object index) - ** @param x x coordinate on the screen - ** @param y y coordinate on the screen - */ - void (*DrawClip) (const Graphic* o,unsigned f,int x,int y); - /** - ** Draw the object clipped and flipped in X direction. - ** - ** @param o pointer to object - ** @param f number of frame (object index) - ** @param x x coordinate on the screen - ** @param y y coordinate on the screen - */ - void (*DrawClipX) (const Graphic* o,unsigned f,int x,int y); - /** - ** Draw part of the object unclipped. - ** - ** @param o pointer to object - ** @param gx X offset into object - ** @param gy Y offset into object - ** @param w width to display - ** @param h height to display - ** @param x x coordinate on the screen - ** @param y y coordinate on the screen - */ - void (*DrawSub) (const Graphic* o,int gx,int gy - ,unsigned w,unsigned h,int x,int y); - /** - ** Draw part of the object unclipped and flipped in X direction. - ** - ** @param o pointer to object - ** @param gx X offset into object - ** @param gy Y offset into object - ** @param w width to display - ** @param h height to display - ** @param x x coordinate on the screen - ** @param y y coordinate on the screen - */ - void (*DrawSubX) (const Graphic* o,int gx,int gy - ,unsigned w,unsigned h,int x,int y); - /** - ** Draw part of the object clipped to the current clipping. - ** - ** @param o pointer to object - ** @param gx X offset into object - ** @param gy Y offset into object - ** @param w width to display - ** @param h height to display - ** @param x x coordinate on the screen - ** @param y y coordinate on the screen - */ - void (*DrawSubClip) (const Graphic* o,int gx,int gy - ,unsigned w,unsigned h,int x,int y); - /** - ** Draw part of the object clipped and flipped in X direction. - ** - ** @param o pointer to object - ** @param gx X offset into object - ** @param gy Y offset into object - ** @param w width to display - ** @param h height to display - ** @param x x coordinate on the screen - ** @param y y coordinate on the screen - */ - void (*DrawSubClipX)(const Graphic* o,int gx,int gy - ,unsigned w,unsigned h,int x,int y); - - /** - ** Draw the object unclipped and zoomed. - ** - ** @param o pointer to object - ** @param f number of frame (object index) - ** @param x x coordinate on the screen - ** @param y y coordinate on the screen - ** @param z Zoom factor X 10 (10 = 1:1). - */ - void (*DrawZoom) (const Graphic* o,unsigned f,int x,int y,int z); - - // FIXME: add zooming functions. - - /* - ** Free the object. - ** - ** @param o pointer to object - */ - void (*Free) (Graphic* o); -} GraphicType; - -/** -** General graphic object -*/ -struct _graphic_ { - // cache line 0 - GraphicType* Type; /// Object type dependend - void* Frames; /// Frames of the object - void* Pixels; /// Pointer to local or global palette - unsigned Width; /// Width of the object - // cache line 1 - unsigned Height; /// Height of the object - unsigned NumFrames; /// Number of frames - unsigned Size; /// Size of frames - Palette* Palette; /// Loaded Palette - // cache line 2 - //void* Offsets; /// Offsets into frames -}; - -/*---------------------------------------------------------------------------- --- Variables -----------------------------------------------------------------------------*/ - - /** - ** Wanted videomode, fullscreen or windowed. - */ -extern char VideoFullScreen; - - /** - ** Architecture-dependant video depth. Set by InitVideoXXX, if 0. - ** (8,15,16,24,32) - ** @see InitVideo @see InitVideoX11 @see InitVideoSVGA @see InitVideoSdl - ** @see InitVideoWin32 @see main - */ -extern int VideoDepth; - -#ifdef NEW_VIDEO - /** - ** Architecture-dependant videomemory. Set by InitVideoXXX. - ** FIXME: need a new function to set it, see #ifdef SDL code - ** @see InitVideo @see InitVideoX11 @see InitVideoSVGA @see InitVideoSdl - ** @see InitVideoWin32 @see VMemType - */ -extern VMemType* VideoMemory; - -#define VideoMemory8 (&VideoMemory->D8) /// video memory 8bpp -#define VideoMemory16 (&VideoMemory->D16) /// video memory 16bpp -#define VideoMemory24 (&VideoMemory->D24) /// video memory 24bpp -#define VideoMemory32 (&VideoMemory->D32) /// video memory 32bpp - - /** - ** Architecture-dependant system palette. Applies as conversion between - ** GlobalPalette colors and their representation in videomemory. - ** Set by VideoCreatePalette or VideoSetPalette. - ** @see VideoCreatePalette @VideoSetPalette - */ -extern VMemType* Pixels; - -#define Pixels8 (&Pixels->D8) /// global pixels 8bpp -#define Pixels16 (&Pixels->D16) /// global pixels 16bpp -#define Pixels24 (&Pixels->D24) /// global pixels 24bpp -#define Pixels32 (&Pixels->D32) /// global pixels 32bpp - -#endif - - /// Loaded system palette. 256-entries long, active system palette. -extern Palette GlobalPalette[256]; - - /** - ** Video synchronization speed. Synchronization time in prozent. - ** If =0, video framerate is not synchronized. 100 is exact - ** FRAMES_PER_SECOND (30). Game will try to redraw screen within - ** intervals of VideoSyncSpeed, not more, not less. - ** @see FRAMES_PER_SECOND @see VideoInterrupts - */ -extern int VideoSyncSpeed; - - /** - ** Counter. Counts how many video interrupts occured, while proceed event - ** queue. If <1 simply do nothing, =1 means that we should redraw screen. - ** >1 means that framerate is too slow. - ** @see CheckVideoInterrupts @VideoSyncSpeed - */ -extern volatile int VideoInterrupts; - - /** - ** Draw pixel unclipped. - ** - ** @param color Color index. - ** @param x x coordinate on the screen - ** @param y y coordinate on the screen - */ -extern void (*VideoDrawPixel)(SysColors color,int x,int y); - - /** - ** Draw pixel clipped to current clip setting. - ** - ** @param color Color index. - ** @param x x coordinate on the screen - ** @param y y coordinate on the screen - */ -extern void (*VideoDrawPixelClip)(SysColors color,int x,int y); - - /** - ** Draw vertical line unclipped. - ** - ** @param color Color index. - ** @param x x coordinate on the screen - ** @param y y coordinate on the screen - ** @param height height of line. - */ -extern void (*VideoDrawVLine)(SysColors color,int x,int y - ,unsigned height); - - /** - ** Draw vertical line clipped to current clip setting - ** - ** @param color Color index. - ** @param x x coordinate on the screen - ** @param y y coordinate on the screen - ** @param height height of line. - */ -extern void (*VideoDrawVLineClip)(SysColors color,int x,int y - ,unsigned height); - - /** - ** Draw horizontal line unclipped. - ** - ** @param color Color index. - ** @param x x coordinate on the screen - ** @param y y coordinate on the screen - ** @param width width of line. - */ -extern void (*VideoDrawHLine)(SysColors color,int x,int y - ,unsigned width); - - /** - ** Draw horizontal line clipped to current clip setting - ** - ** @param color Color index. - ** @param x x coordinate on the screen - ** @param y y coordinate on the screen - ** @param width width of line. - */ -extern void (*VideoDrawHLineClip)(SysColors color,int x,int y - ,unsigned width); - -#ifdef NEW_VIDEO - /// Does ColorCycling.. -extern void (*ColorCycle)(void); -#endif - -/*---------------------------------------------------------------------------- --- Macros -----------------------------------------------------------------------------*/ - - /// Get the width of a single frame of a graphic object -#define VideoGraphicWidth(o) ((o)->Width) - /// Get the height of a single frame of a graphic object -#define VideoGraphicHeight(o) ((o)->Height) - /// Get the number of frames of a graphic object -#define VideoGraphicFrames(o) ((o)->NumFrames) - - /// Draw a graphic object unclipped. -#define VideoDraw(o,f,x,y) ((o)->Type->Draw)((o),(f),(x),(y)) - /// Draw a graphic object unclipped and flipped in X direction. -#define VideoDrawX(o,f,x,y) ((o)->Type->DrawX)((o),(f),(x),(y)) - /// Draw a graphic object clipped to the current clipping. -#define VideoDrawClip(o,f,x,y) ((o)->Type->DrawClip)((o),(f),(x),(y)) - /// Draw a graphic object clipped and flipped in X direction. -#define VideoDrawClipX(o,f,x,y) ((o)->Type->DrawClipX)((o),(f),(x),(y)) - - /// Draw a part of graphic object unclipped. -#define VideoDrawSub(o,ix,iy,w,h,x,y) \ - ((o)->Type->DrawSub)((o),(ix),(iy),(w),(h),(x),(y)) - /// Draw a part of graphic object unclipped and flipped in X direction. -#define VideoDrawSubX(o,ix,iy,w,h,x,y) \ - ((o)->Type->DrawSubX)((o),(ix),(iy),(w),(h),(x),(y)) - /// Draw a part of graphic object clipped to the current clipping. -#define VideoDrawSubClip(o,ix,iy,w,h,x,y) \ - ((o)->Type->DrawSubClip)((o),(ix),(iy),(w),(h),(x),(y)) - /// Draw a part of graphic object clipped and flipped in X direction. -#define VideoDrawSubClipX(o,ix,iy,w,h,x,y) \ - ((o)->Type->DrawSubClipX)((o),(ix),(iy),(w),(h),(x),(y)) - - /// Draw a graphic object zoomed unclipped. -#define VideoDrawZoom(o,f,x,y,z) \ - ((o)->Type->DrawZoom)((o),(f),(x),(y),(z)) - /// Draw a graphic object zoomed unclipped flipped in X direction. -#define VideoDrawZoomX(o,f,x,y,z) \ - ((o)->Type->DrawZoomX)((o),(f),(x),(y),(z)) - /// Draw a graphic object zoomed clipped to the current clipping. -#define VideoDrawZoomClip(o,f,x,y,z) \ - ((o)->Type->DrawZoomClip)((o),(f),(x),(y),(z)) - /// Draw a graphic object zoomed clipped and flipped in X direction. -#define VideoDrawZoomClipX(o,f,x,y,z) \ - ((o)->Type->DrawZoomClipX)((o),(f),(x),(y),(z)) - - /// Draw a part of graphic object zoomed unclipped. -#define VideoDrawZoomSub(o,ix,iy,w,h,x,y,z) \ - ((o)->Type->DrawZoomSub)((o),(ix),(iy),(w),(h),(x),(y),(z)) - /// Draw a part of graphic object zoomed unclipped flipped in X direction. -#define VideoDrawZoomSubX(o,ix,iy,w,h,x,y,z) \ - ((o)->Type->DrawZoomSubX)((o),(ix),(iy),(w),(h),(x),(y),(z)) - /// Draw a part of graphic object zoomed clipped to the current clipping. -#define VideoDrawZoomSubClip(o,ix,iy,w,h,x,y,z) \ - ((o)->Type->DrawZoomSubClip)((o),(ix),(iy),(w),(h),(x),(y),(z)) - /// Draw a part of graphic object zoomed clipped flipped in X direction. -#define VideoDrawZoomSubClipX(o,ix,iy,w,h,x,y,z) \ - ((o)->Type->DrawZoomSubClipX)((o),(ix),(iy),(w),(h),(x),(y),(z)) - - /// Free a graphic object. -#define VideoFree(o) ((o)->Type->Free)((o)) - /// Save (NULL) free a graphic object. -#define VideoSaveFree(o) \ - do { if( (o) ) ((o)->Type->Free)((o)); } while( 0 ) - -/*---------------------------------------------------------------------------- --- Functions -----------------------------------------------------------------------------*/ - - /// initialize the video part -extern void InitVideo(void); - - /** - ** Invalidates selected area on window or screen. Use for accurate - ** redrawing. in so - ** @param x x screen coordinate - ** @param y y screen coordinate - ** @param w width in pixel - ** @param h height in pixel - */ -extern void InvalidateArea(int x,int y,int w,int h); - - /// Simply invalidates whole window or screen. -extern void Invalidate(void); - - /** - ** Realize videomemory. X11 implemenataion just does XFlush. - ** SVGALIB without linear addressing should use this. - */ -extern void RealizeVideoMemory(void); - - /** - ** Process all system events. This function also keeps synchronization - ** of game. - */ -extern void WaitEventsAndKeepSync(void); - - /// Load graphic from PNG file. -extern Graphic* LoadGraphicPNG(const char* name); - - /// New graphic -extern Graphic* NewGraphic(unsigned d,unsigned w,unsigned h); - - /// Make graphic -extern Graphic* MakeGraphic(unsigned,unsigned,unsigned,void*,unsigned); - - /// Load graphic -extern Graphic* LoadGraphic(const char* file); - - /// Load sprite -extern Graphic* LoadSprite(const char* file,unsigned w,unsigned h); - - /// Init graphic -extern void InitGraphic(void); - - /// Init sprite -extern void InitSprite(void); - - /// Init line draw -extern void InitLineDraw(void); - - /// Draw rectangle. -extern void VideoDrawRectangle(SysColors color,int x,int y - ,unsigned w,unsigned h); - - /// Fill rectangle. -extern void VideoFillRectangle(SysColors color,int x,int y - ,unsigned w,unsigned h); - - /** - ** Set clipping for nearly all vector primitives. Functions which support - ** clipping will be marked Clip. Set the system-wide clipping rectangle. - ** - ** @param left Left x coordinate - ** @param top Top y coordinate - ** @param right Right x coordinate - ** @param bottom Bottom y coordinate - */ -extern void SetClipping(int left,int top,int right,int bottom); - - /** - ** Push current clipping. - */ -extern void PushClipping(void); - - /** - ** Pop current clipping. - */ -extern void PopClipping(void); - - /** - ** 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 - */ -extern void DisplayPicture(const char *name); - - /** - ** Load palette from resource. Just loads palette, to set it use - ** VideoCreatePalette, which sets system palette. - ** - ** @param pal buffer to store palette (256-entries long) - ** @param name resource file name - ** - ** @see VideoCreatePalette - */ -extern void LoadRGB(Palette* pal,const char* name); - - /** - ** Creates a hardware palette from an independend Palette struct. - ** - ** @param palette System independ palette structure. - ** - ** @returns A palette in hardware dependend format. - */ -#ifdef NEW_VIDEO -extern VMemType* VideoCreateNewPalette(const Palette* palette); - - /** - ** Initialize Pixels[] for all players. - ** (bring Players[] in sync with Pixels[]) - ** - ** @see VideoSetPalette - */ -extern void SetPlayersPalette(void); - - /** - ** Initializes system palette. Also calls SetPlayersPalette to set - ** palette for all players. - ** - ** @param palette VMemType structure, as created by VideoCreateNewPalette - ** @see SetPlayersPalette - */ -extern void VideoSetPalette(const VMemType* palette); -#endif - - /** - ** Set the system hardware palette from an independend Palette struct. - ** - ** @param palette System independ palette structure. - */ -extern void VideoCreatePalette(const Palette* palette); - - /// Initializes video synchronization. -extern void SetVideoSync(void); - - /// Prints warning if video is too slow.. -extern void CheckVideoInterrupts(void); - - /// Toggle mouse grab mode -extern void ToggleGrabMouse(void); - -//@} - -#endif // !__NEW_VIDEO_H__ diff --git a/src/include/player.h b/src/include/player.h index b2d6c6a80..9f3bf2352 100644 --- a/src/include/player.h +++ b/src/include/player.h @@ -9,11 +9,10 @@ // FreeCraft - A free fantasy real time strategy game engine // /**@name player.h - The player headerfile. */ -/* -** (c) Copyright 1998-2000 by Lutz Sammer -** -** $Id$ -*/ +// +// (c) Copyright 1998-2000 by Lutz Sammer +// +// $Id$ #ifndef __PLAYER_H__ #define __PLAYER_H__ @@ -32,6 +31,7 @@ typedef struct _player_ Player; #include "upgrade_structs.h" #include "unittype.h" #include "unit.h" +#include "video.h" /*---------------------------------------------------------------------------- -- Player type @@ -59,6 +59,7 @@ struct _player_ { unsigned Resources[MaxCosts]; /// resources in store int Incomes[MaxCosts]; /// income of the resources. +// FIXME: needed again? if not remove // unsigned UnitFlags[ // (UnitTypeInternalMax+BitsOf(unsigned)-1) // /BitsOf(unsigned)]; /// flags what units are available @@ -79,7 +80,6 @@ struct _player_ { // Display video unsigned Color; /// color of units on minimap - // FIXME: not used union { struct __4pixel8__ { VMemType8 Pixels[4]; /// palette colors #0 ... #3 @@ -95,14 +95,7 @@ struct _player_ { } Depth32; /// player colors for 32bpp } UnitColors; /// Unit colors for faster setup - // FIXME: this should be removed, use UnitColors insteed - //unsigned UnitColor1; /// Unit color 1 on map and icons - //unsigned UnitColor2; /// Unit color 2 on map and icons - //unsigned UnitColor3; /// Unit color 3 on map and icons - //unsigned UnitColor4; /// Unit color 4 on map and icons - // Upgrades/Allows: - Allow Allow; /// Allowed for player UpgradeTimers UTimers; /// Timer for the upgrades }; @@ -189,26 +182,18 @@ extern int HaveUnitTypeByType(const Player* player,const UnitType* type); /// Has the player units of that type extern int HaveUnitTypeByIdent(const Player* player,const char* ident); - /// FIXME: write short docu + /// Initialize the computer opponent AI extern void PlayersInitAi(void); - /// FIXME: write short docu + /// Called each frame for player handlers (AI) extern void PlayersEachFrame(void); - /// FIXME: write short docu + /// Called each second for player handlers (AI) extern void PlayersEachSecond(void); -#ifdef NEW_VIDEO /// Change current color set to new player. extern void PlayerPixels(const Player* player); /// Change current color set to new player of the sprite extern void GraphicPlayerPixels(const Player* player, const Graphic * sprite); -#else - /// Change current color set to new player. -extern void PlayerPixels(const Player* player); - - /// Change current color set to new player of the sprite -extern void RLEPlayerPixels(const Player* player, const RleSprite * sprite); -#endif /// Output debug informations for players extern void DebugPlayers(void); diff --git a/src/include/ui.h b/src/include/ui.h index 7ff531ac7..640a88528 100644 --- a/src/include/ui.h +++ b/src/include/ui.h @@ -27,7 +27,7 @@ -- Includes ----------------------------------------------------------------------------*/ -#include "new_video.h" +#include "video.h" #include "upgrade_structs.h" /*---------------------------------------------------------------------------- diff --git a/src/include/unittype.h b/src/include/unittype.h index 0e124ae9f..3772ef95c 100644 --- a/src/include/unittype.h +++ b/src/include/unittype.h @@ -195,11 +195,7 @@ struct _unit_type_ { void* Property; /// CCL property storage -#ifdef NEW_VIDEO Graphic* Sprite; /// sprite images -#else - RleSprite* RleSprite; /// sprite images -#endif }; /// Who many unit types are currently supported. diff --git a/src/include/video.h b/src/include/video.h index b6311d5d1..fa1809477 100644 --- a/src/include/video.h +++ b/src/include/video.h @@ -9,11 +9,11 @@ // FreeCraft - A free fantasy real time strategy game engine // /**@name video.h - The video headerfile. */ -/* -** (c) Copyright 1998-2000 by Lutz Sammer -** -** $Id$ -*/ +// +// (c) Copyright 1999,2000 by Lutz Sammer +// +// $Id$ +// #ifndef __VIDEO_H__ #define __VIDEO_H__ @@ -24,219 +24,541 @@ -- Includes ----------------------------------------------------------------------------*/ -#include "new_video.h" - -#ifndef NEW_VIDEO // { Should be removed with new video final version - /*---------------------------------------------------------------------------- -- Declarations ----------------------------------------------------------------------------*/ - /// MACRO defines speed of colorcycling +typedef unsigned char VMemType8; /// 8 bpp modes pointer +typedef unsigned short VMemType16; /// 16 bpp modes pointer +typedef struct { char a,b,c;} VMemType24;/// 24 bpp modes pointer +typedef unsigned long VMemType32; /// 32 bpp modes pointer + +/** +** General video mode pointer. +** +** @see VMemType8 @see VMemType16 @see VMemType24 @see VMemType32 +*/ +typedef union __vmem_type__ { + VMemType8 D8; /// 8 bpp access + VMemType16 D16; /// 16 bpp access + VMemType24 D24; /// 24 bpp access + VMemType32 D32; /// 32 bpp access +} VMemType; + + /// MACRO defines speed of colorcycling FIXME: should be made configurable #define COLOR_CYCLE_SPEED (FRAMES_PER_SECOND/4) +// FIXME: not quite correct for new multiple palette version + /// System-Wide used colors. +enum _sys_colors_ { + ColorBlack = 0, /// use for black + ColorDarkGreen = 149, + ColorBlue = 206, + ColorWhite = 246, + ColorNPC = 247, + ColorGray = 248, + ColorRed = 249, + ColorGreen = 250, + ColorYellow = 251, + ColorBlinkRed = 252, + ColorViolett = 253, -/**@name RleSprite */ -//@{ - -/** RleSprite structure. Transparent, single frame, not packed image. - Fast enough. Primarily used for fonts. color 255 is transparent. - @see LoadRleSprite - @see DrawRleSprite - @see DrawRleSpriteClipped - @see DrawRleSpriteClippedX - @see DrawRleSpriteX - @see FreeRleSprite - */ -struct RleSprite { - unsigned Width; /// width of a frame - unsigned Height; /// height of a frame - GraphicData* Pixels; /// pointer to local or global palette - int NumFrames; /// number of frames - IfDebug( int ByteSize; ) - /** - ** pointer to the frames. frames are bitmaps converted via global - ** Pixels[] structure or local object Pixels (if local Pixels != 0). - */ - unsigned char* Frames[0]; +// FIXME: this should some where made configurable + ColorWaterCycleStart = 38, /// color # start for color cycling + ColorWaterCycleEnd = 47, /// color # end for color cycling + ColorIconCycleStart = 240, /// color # start for color cycling + ColorIconCycleEnd = 244 /// color # end for color cycling }; -typedef struct RleSprite RleSprite; +typedef enum _sys_colors_ SysColors; /// System-Wide used colors. -/** Load RLE Sprite. new memory block is allocated. - @param name resource file name - @param w width of a frame - @param h height of a frame - */ -extern RleSprite* LoadRleSprite(const char* name,unsigned w,unsigned h); +typedef struct _palette_ Palette; /// palette typedef -/** Draw RLE Sprite.. - @param sprite pointer to RLE Sprite OBJECT - @param frame number of frame - @param x x coordinate on the screen - @param y y coordinate on the screen - */ -extern void DrawRleSprite(RleSprite* sprite,unsigned frame,int x,int y); +/// Palette structure. +struct _palette_ { + unsigned char r; /// red component + unsigned char g; /// green component + unsigned char b; /// blue component +}; -/** Draw RLE Sprite FLIPPED X.. - @param sprite pointer to RLE Sprite OBJECT - @param frame number of frame - @param x x coordinate on the screen - @param y y coordinate on the screen - */ -extern void DrawRleSpriteX(RleSprite* sprite,unsigned frame,int x,int y); +typedef unsigned char GraphicData; /// generic graphic data type -/** Draw RLE Sprite CLIPPED.. - @param sprite pointer to RLE Sprite OBJECT - @param frame number of frame - @param x x coordinate on the screen - @param y y coordinate on the screen - */ -extern void DrawRleSpriteClipped(RleSprite* sprite,unsigned frame,int x,int y); - -/** Draw RLE Sprite CLIPPED FLIPPED X.. - @param sprite pointer to RLE Sprite OBJECT - @param frame number of frame - @param x x coordinate on the screen - @param y y coordinate on the screen - */ -extern void DrawRleSpriteClippedX(RleSprite* sprite,unsigned frame,int x,int y); - -/** Free pointer returned by LoadRleSprite. Dereferencing pointer is no longer - correct. - @param sprite pointer returned by LoadRleSprite - */ -extern void FreeRleSprite(RleSprite *sprite); -//@} - - -/** Set clipping for nearly all vector primitives. Functions which support - clipping will be marked CLIPPED. Set system-wide clipping rectangle. - @param left left x coordinate - @param top top y coordinate - @param right right x coordinate - @param bottom bottom y coordinate - */ -extern void SetClipping(int left,int top,int right,int bottom); - - -/** Architecture-dependant videomemory. Set by InitVideoXXX. - @see InitVideo - @see InitVideoX11 - @see InitVideoSVGA - @see InitVideoSdl - @see InitVideoWin32 - */ -extern void* VideoMemory; - -/** Architecture-dependant video depth. Set by InitVideoXXX. - @see InitVideo - @see InitVideoX11 - @see InitVideoSVGA - @see InitVideoSdl - @see InitVideoWin32 +/** +** General graphic object typedef. (forward) */ +typedef struct _graphic_ Graphic; + +/** +** General graphic object type. +*/ +typedef struct _graphic_type_ { + /** + ** Draw the object unclipped. + ** + ** @param o pointer to object + ** @param f number of frame (object index) + ** @param x x coordinate on the screen + ** @param y y coordinate on the screen + */ + void (*Draw) (const Graphic* o,unsigned f,int x,int y); + /** + ** Draw the object unclipped and flipped in X direction. + ** + ** @param o pointer to object + ** @param f number of frame (object index) + ** @param x x coordinate on the screen + ** @param y y coordinate on the screen + */ + void (*DrawX) (const Graphic* o,unsigned f,int x,int y); + /** + ** Draw the object clipped to the current clipping. + ** + ** @param o pointer to object + ** @param f number of frame (object index) + ** @param x x coordinate on the screen + ** @param y y coordinate on the screen + */ + void (*DrawClip) (const Graphic* o,unsigned f,int x,int y); + /** + ** Draw the object clipped and flipped in X direction. + ** + ** @param o pointer to object + ** @param f number of frame (object index) + ** @param x x coordinate on the screen + ** @param y y coordinate on the screen + */ + void (*DrawClipX) (const Graphic* o,unsigned f,int x,int y); + /** + ** Draw part of the object unclipped. + ** + ** @param o pointer to object + ** @param gx X offset into object + ** @param gy Y offset into object + ** @param w width to display + ** @param h height to display + ** @param x x coordinate on the screen + ** @param y y coordinate on the screen + */ + void (*DrawSub) (const Graphic* o,int gx,int gy + ,unsigned w,unsigned h,int x,int y); + /** + ** Draw part of the object unclipped and flipped in X direction. + ** + ** @param o pointer to object + ** @param gx X offset into object + ** @param gy Y offset into object + ** @param w width to display + ** @param h height to display + ** @param x x coordinate on the screen + ** @param y y coordinate on the screen + */ + void (*DrawSubX) (const Graphic* o,int gx,int gy + ,unsigned w,unsigned h,int x,int y); + /** + ** Draw part of the object clipped to the current clipping. + ** + ** @param o pointer to object + ** @param gx X offset into object + ** @param gy Y offset into object + ** @param w width to display + ** @param h height to display + ** @param x x coordinate on the screen + ** @param y y coordinate on the screen + */ + void (*DrawSubClip) (const Graphic* o,int gx,int gy + ,unsigned w,unsigned h,int x,int y); + /** + ** Draw part of the object clipped and flipped in X direction. + ** + ** @param o pointer to object + ** @param gx X offset into object + ** @param gy Y offset into object + ** @param w width to display + ** @param h height to display + ** @param x x coordinate on the screen + ** @param y y coordinate on the screen + */ + void (*DrawSubClipX)(const Graphic* o,int gx,int gy + ,unsigned w,unsigned h,int x,int y); + + /** + ** Draw the object unclipped and zoomed. + ** + ** @param o pointer to object + ** @param f number of frame (object index) + ** @param x x coordinate on the screen + ** @param y y coordinate on the screen + ** @param z Zoom factor X 10 (10 = 1:1). + */ + void (*DrawZoom) (const Graphic* o,unsigned f,int x,int y,int z); + + // FIXME: add zooming functions. + + /* + ** Free the object. + ** + ** @param o pointer to object + */ + void (*Free) (Graphic* o); +} GraphicType; + +/** +** General graphic object +*/ +struct _graphic_ { + // cache line 0 + GraphicType* Type; /// Object type dependend + void* Frames; /// Frames of the object + void* Pixels; /// Pointer to local or global palette + unsigned Width; /// Width of the object + // cache line 1 + unsigned Height; /// Height of the object + unsigned NumFrames; /// Number of frames + unsigned Size; /// Size of frames + Palette* Palette; /// Loaded Palette + // cache line 2 + //void* Offsets; /// Offsets into frames +}; + +/*---------------------------------------------------------------------------- +-- Variables +----------------------------------------------------------------------------*/ + + /** + ** Wanted videomode, fullscreen or windowed. + */ +extern char VideoFullScreen; + + /** + ** Architecture-dependant video depth. Set by InitVideoXXX, if 0. + ** (8,15,16,24,32) + ** @see InitVideo @see InitVideoX11 @see InitVideoSVGA @see InitVideoSdl + ** @see InitVideoWin32 @see main + */ extern int VideoDepth; - /// Sub depth 555, 565 -//extern int VideoSubDepth; - /// 32 bpp modes video memory address -#define VideoMemory32 ((VMemType32*)VideoMemory) - /// 24 bpp modes video memory address -#define VideoMemory24 ((VMemType24*)VideoMemory) - /// 16 bpp modes video memory address -#define VideoMemory16 ((VMemType16*)VideoMemory) - /// 8 bpp modes video memory address -#define VideoMemory8 ((VMemType8*)VideoMemory) + /** + ** Architecture-dependant videomemory. Set by InitVideoXXX. + ** FIXME: need a new function to set it, see #ifdef SDL code + ** @see InitVideo @see InitVideoX11 @see InitVideoSVGA @see InitVideoSdl + ** @see InitVideoWin32 @see VMemType + */ +extern VMemType* VideoMemory; -/** Architecture-dependant system palette. Applies as conversion between - GlobalPalette colors and their representation in videomemory. Set by - VideoCreatePalette. - @see VideoCreatePalette - */ -extern VMemType8 * Pixels8; /// 8 bpp -extern VMemType16 * Pixels16; /// 16 bpp -extern VMemType24 * Pixels24; /// 24 bpp -extern VMemType32 * Pixels32; /// 32 bpp +#define VideoMemory8 (&VideoMemory->D8) /// video memory 8bpp +#define VideoMemory16 (&VideoMemory->D16) /// video memory 16bpp +#define VideoMemory24 (&VideoMemory->D24) /// video memory 24bpp +#define VideoMemory32 (&VideoMemory->D32) /// video memory 32bpp -/** Set videomode. Tries to set choosen videomode. Only 640x480, 800x600 - and 1024x768 are available. If videoadapter is not good enough module will - return failure. Default mode is 640x480. - @return 1 if videomode set correctly; 0 otherwise. */ -extern int SetVideoMode(int width); + /** + ** Architecture-dependant system palette. Applies as conversion between + ** GlobalPalette colors and their representation in videomemory. + ** Set by VideoCreatePalette or VideoSetPalette. + ** @see VideoCreatePalette @VideoSetPalette + */ +extern VMemType* Pixels; -/// Initialize Pixels[] for all players (bring Players[] in sync with Pixels[]) -extern void SetPlayersPalette(void); +#define Pixels8 (&Pixels->D8) /// global pixels 8bpp +#define Pixels16 (&Pixels->D16) /// global pixels 16bpp +#define Pixels24 (&Pixels->D24) /// global pixels 24bpp +#define Pixels32 (&Pixels->D32) /// global pixels 32bpp -/**@name Architecture-dependant video functions */ -//@{ + /// Loaded system palette. 256-entries long, active system palette. +extern Palette GlobalPalette[256]; -/// Initializes video synchronization.. -extern void SetVideoSync(void); + /** + ** Video synchronization speed. Synchronization time in prozent. + ** If =0, video framerate is not synchronized. 100 is exact + ** FRAMES_PER_SECOND (30). Game will try to redraw screen within + ** intervals of VideoSyncSpeed, not more, not less. + ** @see FRAMES_PER_SECOND @see VideoInterrupts + */ +extern int VideoSyncSpeed; -/// Prints warning if video is too slow.. -extern void CheckVideoInterrupts(void); + /** + ** Counter. Counts how many video interrupts occured, while proceed event + ** queue. If <1 simply do nothing, =1 means that we should redraw screen. + ** >1 means that framerate is too slow. + ** @see CheckVideoInterrupts @VideoSyncSpeed + */ +extern volatile int VideoInterrupts; -/// Does ColorCycling.. -extern void ColorCycle(void); + /** + ** Draw pixel unclipped. + ** + ** @param color Color index. + ** @param x x coordinate on the screen + ** @param y y coordinate on the screen + */ +extern void (*VideoDrawPixel)(SysColors color,int x,int y); -/** Creates a palette from a Palette struct */ -extern GraphicData * VideoCreateNewPalette(const Palette *palette); + /** + ** Draw pixel clipped to current clip setting. + ** + ** @param color Color index. + ** @param x x coordinate on the screen + ** @param y y coordinate on the screen + */ +extern void (*VideoDrawPixelClip)(SysColors color,int x,int y); -/** Initializes system palette. Also calls SetPlayersPalette to set palette for - all players. - @param palette GraphicData structure, as created by VideoCreateNewPalette - @see SetPlayersPalette - */ -extern void VideoSetPalette(const GraphicData *palette); + /** + ** Draw vertical line unclipped. + ** + ** @param color Color index. + ** @param x x coordinate on the screen + ** @param y y coordinate on the screen + ** @param height height of line. + */ +extern void (*VideoDrawVLine)(SysColors color,int x,int y + ,unsigned height); -/// OBSOLETE: Calls VideoCreateNewPalette with the palette argument, and then -/// feeds the result to VideoSetPalette to initialize system palette with it. -extern void VideoCreatePalette(const Palette *palette); + /** + ** Draw vertical line clipped to current clip setting + ** + ** @param color Color index. + ** @param x x coordinate on the screen + ** @param y y coordinate on the screen + ** @param height height of line. + */ +extern void (*VideoDrawVLineClip)(SysColors color,int x,int y + ,unsigned height); -/// Process all system events. This function also keeps synchronization of game. -extern void WaitEventsAndKeepSync(void); + /** + ** Draw horizontal line unclipped. + ** + ** @param color Color index. + ** @param x x coordinate on the screen + ** @param y y coordinate on the screen + ** @param width width of line. + */ +extern void (*VideoDrawHLine)(SysColors color,int x,int y + ,unsigned width); -/** Realize videomemory. X11 implemenataion just does XFlush. SVGALIB without - linear addressing should use this. */ -extern void RealizeVideoMemory(void); + /** + ** Draw horizontal line clipped to current clip setting + ** + ** @param color Color index. + ** @param x x coordinate on the screen + ** @param y y coordinate on the screen + ** @param width width of line. + */ +extern void (*VideoDrawHLineClip)(SysColors color,int x,int y + ,unsigned width); -/// Initialize video hardware.. -extern void GameInitDisplay(void); + /// Does ColorCycling.. +extern void (*ColorCycle)(void); -/** Invalidates selected area on window or screen. Use for accurate redrawing. - in so - @param x x coordinate - @param y y coordinate - @param w width - @param h height - */ +/*---------------------------------------------------------------------------- +-- Macros +----------------------------------------------------------------------------*/ + + /// Get the width of a single frame of a graphic object +#define VideoGraphicWidth(o) ((o)->Width) + /// Get the height of a single frame of a graphic object +#define VideoGraphicHeight(o) ((o)->Height) + /// Get the number of frames of a graphic object +#define VideoGraphicFrames(o) ((o)->NumFrames) + + /// Draw a graphic object unclipped. +#define VideoDraw(o,f,x,y) ((o)->Type->Draw)((o),(f),(x),(y)) + /// Draw a graphic object unclipped and flipped in X direction. +#define VideoDrawX(o,f,x,y) ((o)->Type->DrawX)((o),(f),(x),(y)) + /// Draw a graphic object clipped to the current clipping. +#define VideoDrawClip(o,f,x,y) ((o)->Type->DrawClip)((o),(f),(x),(y)) + /// Draw a graphic object clipped and flipped in X direction. +#define VideoDrawClipX(o,f,x,y) ((o)->Type->DrawClipX)((o),(f),(x),(y)) + + /// Draw a part of graphic object unclipped. +#define VideoDrawSub(o,ix,iy,w,h,x,y) \ + ((o)->Type->DrawSub)((o),(ix),(iy),(w),(h),(x),(y)) + /// Draw a part of graphic object unclipped and flipped in X direction. +#define VideoDrawSubX(o,ix,iy,w,h,x,y) \ + ((o)->Type->DrawSubX)((o),(ix),(iy),(w),(h),(x),(y)) + /// Draw a part of graphic object clipped to the current clipping. +#define VideoDrawSubClip(o,ix,iy,w,h,x,y) \ + ((o)->Type->DrawSubClip)((o),(ix),(iy),(w),(h),(x),(y)) + /// Draw a part of graphic object clipped and flipped in X direction. +#define VideoDrawSubClipX(o,ix,iy,w,h,x,y) \ + ((o)->Type->DrawSubClipX)((o),(ix),(iy),(w),(h),(x),(y)) + + /// Draw a graphic object zoomed unclipped. +#define VideoDrawZoom(o,f,x,y,z) \ + ((o)->Type->DrawZoom)((o),(f),(x),(y),(z)) + /// Draw a graphic object zoomed unclipped flipped in X direction. +#define VideoDrawZoomX(o,f,x,y,z) \ + ((o)->Type->DrawZoomX)((o),(f),(x),(y),(z)) + /// Draw a graphic object zoomed clipped to the current clipping. +#define VideoDrawZoomClip(o,f,x,y,z) \ + ((o)->Type->DrawZoomClip)((o),(f),(x),(y),(z)) + /// Draw a graphic object zoomed clipped and flipped in X direction. +#define VideoDrawZoomClipX(o,f,x,y,z) \ + ((o)->Type->DrawZoomClipX)((o),(f),(x),(y),(z)) + + /// Draw a part of graphic object zoomed unclipped. +#define VideoDrawZoomSub(o,ix,iy,w,h,x,y,z) \ + ((o)->Type->DrawZoomSub)((o),(ix),(iy),(w),(h),(x),(y),(z)) + /// Draw a part of graphic object zoomed unclipped flipped in X direction. +#define VideoDrawZoomSubX(o,ix,iy,w,h,x,y,z) \ + ((o)->Type->DrawZoomSubX)((o),(ix),(iy),(w),(h),(x),(y),(z)) + /// Draw a part of graphic object zoomed clipped to the current clipping. +#define VideoDrawZoomSubClip(o,ix,iy,w,h,x,y,z) \ + ((o)->Type->DrawZoomSubClip)((o),(ix),(iy),(w),(h),(x),(y),(z)) + /// Draw a part of graphic object zoomed clipped flipped in X direction. +#define VideoDrawZoomSubClipX(o,ix,iy,w,h,x,y,z) \ + ((o)->Type->DrawZoomSubClipX)((o),(ix),(iy),(w),(h),(x),(y),(z)) + + /// Free a graphic object. +#define VideoFree(o) ((o)->Type->Free)((o)) + /// Save (NULL) free a graphic object. +#define VideoSaveFree(o) \ + do { if( (o) ) ((o)->Type->Free)((o)); } while( 0 ) + +/*---------------------------------------------------------------------------- +-- Functions +----------------------------------------------------------------------------*/ + + /// initialize the video part +extern void InitVideo(void); + + /** + ** Invalidates selected area on window or screen. Use for accurate + ** redrawing. in so + ** @param x x screen coordinate + ** @param y y screen coordinate + ** @param w width in pixel + ** @param h height in pixel + */ extern void InvalidateArea(int x,int y,int w,int h); -/// Simply invalidates whole window or screen.. + /// Simply invalidates whole window or screen. extern void Invalidate(void); -/// Toggle mouse grab mode + /** + ** Realize videomemory. X11 implemenataion just does XFlush. + ** SVGALIB without linear addressing should use this. + */ +extern void RealizeVideoMemory(void); + + /** + ** Process all system events. This function also keeps synchronization + ** of game. + */ +extern void WaitEventsAndKeepSync(void); + + /// Load graphic from PNG file. +extern Graphic* LoadGraphicPNG(const char* name); + + /// New graphic +extern Graphic* NewGraphic(unsigned d,unsigned w,unsigned h); + + /// Make graphic +extern Graphic* MakeGraphic(unsigned,unsigned,unsigned,void*,unsigned); + + /// Load graphic +extern Graphic* LoadGraphic(const char* file); + + /// Load sprite +extern Graphic* LoadSprite(const char* file,unsigned w,unsigned h); + + /// Init graphic +extern void InitGraphic(void); + + /// Init sprite +extern void InitSprite(void); + + /// Init line draw +extern void InitLineDraw(void); + + /// Draw rectangle. +extern void VideoDrawRectangle(SysColors color,int x,int y + ,unsigned w,unsigned h); + + /// Fill rectangle. +extern void VideoFillRectangle(SysColors color,int x,int y + ,unsigned w,unsigned h); + + /** + ** Set clipping for nearly all vector primitives. Functions which support + ** clipping will be marked Clip. Set the system-wide clipping rectangle. + ** + ** @param left Left x coordinate + ** @param top Top y coordinate + ** @param right Right x coordinate + ** @param bottom Bottom y coordinate + */ +extern void SetClipping(int left,int top,int right,int bottom); + + /** + ** Push current clipping. + */ +extern void PushClipping(void); + + /** + ** Pop current clipping. + */ +extern void PopClipping(void); + + /** + ** 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 + */ +extern void DisplayPicture(const char *name); + + /** + ** Load palette from resource. Just loads palette, to set it use + ** VideoCreatePalette, which sets system palette. + ** + ** @param pal buffer to store palette (256-entries long) + ** @param name resource file name + ** + ** @see VideoCreatePalette + */ +extern void LoadRGB(Palette* pal,const char* name); + + /** + ** Creates a hardware palette from an independend Palette struct. + ** + ** @param palette System independ palette structure. + ** + ** @returns A palette in hardware dependend format. + */ +extern VMemType* VideoCreateNewPalette(const Palette* palette); + + /** + ** Initialize Pixels[] for all players. + ** (bring Players[] in sync with Pixels[]) + ** + ** @see VideoSetPalette + */ +extern void SetPlayersPalette(void); + + /** + ** Initializes system palette. Also calls SetPlayersPalette to set + ** palette for all players. + ** + ** @param palette VMemType structure, as created by VideoCreateNewPalette + ** @see SetPlayersPalette + */ +extern void VideoSetPalette(const VMemType* palette); + + /** + ** Set the system hardware palette from an independend Palette struct. + ** + ** @param palette System independ palette structure. + */ +extern void VideoCreatePalette(const Palette* palette); + + /// Initializes video synchronization. +extern void SetVideoSync(void); + + /// Prints warning if video is too slow.. +extern void CheckVideoInterrupts(void); + + /// Toggle mouse grab mode extern void ToggleGrabMouse(void); //@} -/** Counter. Counts how many video interrupts occured, while proceed event - queue. If <1 simply do nothing, =1 means that we should redraw screen. >1 - means that framerate is too slow. - @see CheckVideoInterrupts - */ -extern volatile int VideoInterrupts; - -/** -** Video synchronization speed. Synchronization time in prozent. -** If =0, video framerate is not synchronized. Game will try to redraw screen -** within intervals of VideoSyncSpeed, not more, not less -*/ -extern int VideoSyncSpeed; - -#endif // } !NEW_VIDEO - -//@} - #endif // !__VIDEO_H__ diff --git a/src/stratagus/construct.cpp b/src/stratagus/construct.cpp index 59b00edf7..a91ba5394 100644 --- a/src/stratagus/construct.cpp +++ b/src/stratagus/construct.cpp @@ -9,11 +9,10 @@ // FreeCraft - A free fantasy real time strategy game engine // /**@name construct.c - The constructions. */ -/* -** (c) Copyright 1998-2000 by Lutz Sammer -** -** $Id$ -*/ +// +// (c) Copyright 1998-2000 by Lutz Sammer +// +// $Id$ //@{ @@ -35,88 +34,104 @@ -- Variables ----------------------------------------------------------------------------*/ -#define DEFAULT NULL +#define DEFAULT NULL /// use the first slot as default /** ** Constructions. */ local Construction Constructions[] = { -{ { "", +{ "construction-0", + { "", DEFAULT, DEFAULT, DEFAULT }, 0,0 }, -{ { "", +{ "construction-1", + { "", DEFAULT, DEFAULT, DEFAULT }, 0,0 }, -{ { "", +{ "construction-2", + { "", DEFAULT, DEFAULT, DEFAULT }, 0,0 }, -{ { "", +{ "construction-3", + { "", DEFAULT, DEFAULT, DEFAULT }, 0,0 }, -{ { "", +{ "construction-4", + { "", DEFAULT, DEFAULT, DEFAULT }, 0,0 }, -{ { "", +{ "construction-5", + { "", DEFAULT, DEFAULT, DEFAULT }, 0,0 }, -{ { "land construction site (summer,wasteland).png", +{ "construction-land", + { "land construction site (summer,wasteland).png", "land construction site (winter).png", DEFAULT, DEFAULT }, 64,64 }, -{ { "human shipyard construction site (summer,wasteland).png", +{ "construction-human-shipyard", + { "human shipyard construction site (summer,wasteland).png", "human shipyard construction site (winter).png", DEFAULT, "human shipyard construction site (swamp).png" }, 96,96 }, -{ { "orc shipyard construction site (summer,wasteland).png", +{ "construction-orc-shipyard", + { "orc shipyard construction site (summer,wasteland).png", "orc shipyard construction site (winter).png", DEFAULT, "orc shipyard construction site (swamp).png" }, 96,96 }, -{ { "human oil well construction site (summer).png", +{ "construction-human-oil-well", + { "human oil well construction site (summer).png", "human oil well construction site (winter).png", "human oil well construction site (wasteland).png", "human oil well construction site (swamp).png" }, 96,96 }, -{ { "orc oil well construction site (summer).png", +{ "construction-orc-oil-well", + { "orc oil well construction site (summer).png", "orc oil well construction site (winter).png", "orc oil well construction site (wasteland).png", "orc oil well construction site (swamp).png" }, 96,96 }, -{ { "human refinery construction site (summer,wasteland).png", +{ "construction-human-refinery", + { "human refinery construction site (summer,wasteland).png", "human refinery construction site (winter).png", DEFAULT, "human refinery construction site (swamp).png" }, 96,96 }, -{ { "orc refinery construction site (summer,wasteland).png", +{ "construction-orc-refinery", + { "orc refinery construction site (summer,wasteland).png", "orc refinery construction site (winter).png", DEFAULT, "orc refinery construction site (swamp).png" }, 96,96 }, -{ { "human foundry construction site (summer,wasteland).png", +{ "construction-human-foundry", + { "human foundry construction site (summer,wasteland).png", "human foundry construction site (winter).png", DEFAULT, "human foundry construction site (swamp).png" }, 96,96 }, -{ { "orc foundry construction site (summer,wasteland).png", +{ "construction-orc-foundry", + { "orc foundry construction site (summer,wasteland).png", "orc foundry construction site (winter).png", DEFAULT, "orc foundry construction site (swamp).png" }, 96,96 }, -{ { "wall construction site (summer).png", +{ "construction-wall", + { "wall construction site (summer).png", "wall construction site (winter).png", "wall construction site (wasteland).png", DEFAULT }, @@ -149,13 +164,8 @@ global void LoadConstructions(void) buf=alloca(strlen(file)+9+1); file=strcat(strcpy(buf,"graphic/"),file); ShowLoadProgress("\tConstruction %s\n",file); -#ifdef NEW_VIDEO Constructions[i].Sprite=LoadSprite(file ,Constructions[i].Width,Constructions[i].Height); -#else - Constructions[i].RleSprite=LoadRleSprite(file - ,Constructions[i].Width,Constructions[i].Height); -#endif } } } @@ -168,7 +178,6 @@ global void LoadConstructions(void) ** @param x X position. ** @param y Y position. */ -#ifdef NEW_VIDEO global void DrawConstruction(int type,int frame,int x,int y) { // FIXME: This should be moved to caller/init... @@ -177,15 +186,5 @@ global void DrawConstruction(int type,int frame,int x,int y) VideoDrawClip(Constructions[type].Sprite,frame,x,y); } -#else -global void DrawConstruction(int type,int frame,int x,int y) -{ - // FIXME: This should be moved to caller/init... - x-=Constructions[type].Width/2; - y-=Constructions[type].Height/2; - - DrawRleSpriteClipped(Constructions[type].RleSprite,frame,x,y); -} -#endif //@} diff --git a/src/stratagus/mainloop.cpp b/src/stratagus/mainloop.cpp index e312f9ecc..1c8c585f3 100644 --- a/src/stratagus/mainloop.cpp +++ b/src/stratagus/mainloop.cpp @@ -278,9 +278,7 @@ global void UpdateDisplay(void) DrawUnits(); DrawMapFogOfWar(MapX,MapY); DrawMissiles(); -#ifdef NEW_VIDEO DrawConsole(); -#endif SetClipping(0,0,VideoWidth,VideoHeight); } @@ -360,21 +358,12 @@ global void UpdateDisplay(void) // FIXME: this could be written better, less drawing if( update_old_cursor && MustRedraw!=-1 ) { // Draw restored area only if not same. -#ifdef NEW_VIDEO if( OldCursorX!=(CursorX-GameCursor->HotX) || OldCursorY!=(CursorY-GameCursor->HotY) || OldCursorW!=VideoGraphicWidth(GameCursor->Sprite) || OldCursorH!=VideoGraphicHeight(GameCursor->Sprite) ) { InvalidateArea(OldCursorX,OldCursorY,OldCursorW,OldCursorH); } -#else - if( OldCursorX!=(CursorX-GameCursor->HotX) - || OldCursorY!=(CursorY-GameCursor->HotY) - || OldCursorW!=(GameCursor->RleSprite->Width) - || OldCursorH!=(GameCursor->RleSprite->Height) ) { - InvalidateArea(OldCursorX,OldCursorY,OldCursorW,OldCursorH); - } -#endif } if (!MustRedraw) { @@ -440,20 +429,12 @@ global void UpdateDisplay(void) ,TheUI.StatusLine.Graphic->Width ,TheUI.StatusLine.Graphic->Height); } -#ifdef NEW_VIDEO /* if (MustRedraw) */ { // FIXME: JOHNS: That didn't work: if (MustRedraw&RedrawCursor) InvalidateArea(CursorX-GameCursor->HotX,CursorY-GameCursor->HotY ,VideoGraphicWidth(GameCursor->Sprite) ,VideoGraphicHeight(GameCursor->Sprite)); } -#else - /* if (MustRedraw) */ { - // JOHNS: That didn't work: if (MustRedraw&RedrawCursor) - InvalidateArea(CursorX-GameCursor->HotX,CursorY-GameCursor->HotY - ,GameCursor->RleSprite->Width,GameCursor->RleSprite->Height); - } -#endif } } diff --git a/src/stratagus/oldmissile.cpp b/src/stratagus/oldmissile.cpp index aec87d1d8..39917848c 100644 --- a/src/stratagus/oldmissile.cpp +++ b/src/stratagus/oldmissile.cpp @@ -431,13 +431,8 @@ global void LoadMissileSprites(void) buf=alloca(strlen(file)+9+1); file=strcat(strcpy(buf,"graphic/"),file); ShowLoadProgress("\tMissile %s\n",file); -#ifdef NEW_VIDEO MissileTypes[i].Sprite=LoadSprite( file,MissileTypes[i].Width,MissileTypes[i].Height); -#else - MissileTypes[i].RleSprite=LoadRleSprite( - file,MissileTypes[i].Width,MissileTypes[i].Height); -#endif } } @@ -460,13 +455,8 @@ global void LoadMissileSprites(void) } MissileTypeSmallFire=MissileTypeByIdent("missile-small-fire"); -#ifdef NEW_VIDEO // FIXME: FIXME: FIXME: very diry hack MissileTypeSmallFire->Sprite->NumFrames=6; -#else - // FIXME: FIXME: FIXME: very diry hack - MissileTypeSmallFire->RleSprite->NumFrames=6; -#endif MissileTypeBigFire=MissileTypeByIdent("missile-big-fire"); } @@ -740,21 +730,12 @@ local int MissileVisible(const Missile* missile) */ global void DrawMissile(const MissileType* type,unsigned frame,int x,int y) { -#ifdef NEW_VIDEO // FIXME: This is a hack for mirrored sprites if( frame&128 ) { VideoDrawClipX(type->Sprite,frame&127,x,y); } else { VideoDrawClip(type->Sprite,frame,x,y); } -#else - // FIXME: This is a hack for mirrored sprites - if( frame&128 ) { - DrawRleSpriteClippedX(type->RleSprite,frame&127,x,y); - } else { - DrawRleSpriteClipped(type->RleSprite,frame,x,y); - } -#endif } /** @@ -1018,7 +999,6 @@ global void MissileActions(void) // Animate missile, cycle through frames // missile->Frame+=5; // FIXME: frames pro row -#ifdef NEW_VIDEO if( (missile->Frame&127) >=VideoGraphicFrames(missile->Type->Sprite) ) { missile->Frame-= @@ -1027,14 +1007,6 @@ global void MissileActions(void) DebugLevel3("Frame %d of %d\n" ,missile->Frame ,VideoGraphicFrames(missile->Type->Sprite)); -#else - if( (missile->Frame&127) - >=missile->Type->RleSprite->NumFrames ) { - missile->Frame-=missile->Type->RleSprite->NumFrames; - } - DebugLevel3("Frame %d of %d\n" - ,missile->Frame,missile->Type->RleSprite->NumFrames); -#endif } break; @@ -1077,7 +1049,6 @@ global void MissileActions(void) // Animate missile, cycle through frames // missile->Frame+=5; // FIXME: frames pro row -#ifdef NEW_VIDEO if( (missile->Frame&127) >=VideoGraphicFrames(missile->Type->Sprite) ) { missile->Frame-= @@ -1086,14 +1057,6 @@ global void MissileActions(void) DebugLevel3("Frame %d of %d\n" ,missile->Frame ,VideoGraphicFrames(missile->Type->Sprite)); -#else - if( (missile->Frame&127) - >=missile->Type->RleSprite->NumFrames ) { - missile->Frame-=missile->Type->RleSprite->NumFrames; - } - DebugLevel3("Frame %d of %d\n" - ,missile->Frame,missile->Type->RleSprite->NumFrames); -#endif } break; @@ -1104,36 +1067,21 @@ global void MissileActions(void) // Animate hit // missile->Frame+=5; // FIXME: frames pro row -#ifdef NEW_VIDEO if( (missile->Frame&127) >=VideoGraphicFrames(missile->Type->Sprite) ) { MissileHit(missile); missile->Type=MissileFree; } -#else - if( (missile->Frame&127) - >=missile->Type->RleSprite->NumFrames ) { - MissileHit(missile); - missile->Type=MissileFree; - } -#endif } break; case MissileClassStayWithDelay: missile->Wait=missile->Type->Speed; -#ifdef NEW_VIDEO if( ++missile->Frame ==VideoGraphicFrames(missile->Type->Sprite) ) { MissileHit(missile); missile->Type=MissileFree; } -#else - if( ++missile->Frame==missile->Type->RleSprite->NumFrames ) { - MissileHit(missile); - missile->Type=MissileFree; - } -#endif break; case MissileClassCycleOnce: @@ -1144,19 +1092,11 @@ global void MissileActions(void) ++missile->State; break; case 1: -#ifdef NEW_VIDEO if( ++missile->Frame ==VideoGraphicFrames(missile->Type->Sprite) ) { --missile->Frame; ++missile->State; } -#else - if( ++missile->Frame - ==missile->Type->RleSprite->NumFrames ) { - --missile->Frame; - ++missile->State; - } -#endif break; case 3: if( !missile->Frame-- ) { @@ -1169,13 +1109,8 @@ global void MissileActions(void) case MissileClassFire: missile->Wait=missile->Type->Speed; -#ifdef NEW_VIDEO if( ++missile->Frame - ==VideoGraphicFrames(missile->Type->Sprite) ) -#else - if( ++missile->Frame==missile->Type->RleSprite->NumFrames ) -#endif - { + ==VideoGraphicFrames(missile->Type->Sprite) ) { int f; Unit* unit; diff --git a/src/stratagus/player.cpp b/src/stratagus/player.cpp index 2c603708b..bed0071e7 100644 --- a/src/stratagus/player.cpp +++ b/src/stratagus/player.cpp @@ -515,8 +515,6 @@ global void PlayersEachSecond(void) } } -#ifdef NEW_VIDEO - /** ** Change current color set to new player. ** @@ -706,169 +704,6 @@ global void SetPlayersPalette(void) } } -#else - -/** -** Change current color set to new player. -** -** FIXME: use function pointer here. -** -** @param player Pointer to player. -*/ -global void RLEPlayerPixels(const Player* player, const RleSprite * sprite) -{ - switch(VideoDepth){ - case 8: - *((struct __4pixel8__*)(((VMemType8*)sprite->Pixels)+208)) - =player->UnitColors.Depth8; - break; - case 15: - case 16: - *((struct __4pixel16__*)(((VMemType16*)sprite->Pixels)+208)) - =player->UnitColors.Depth16; - break; - case 24: - // FIXME: support for real 24 bpp mode - //*((struct __4pixel24__*)(((VMemType24*)sprite->Pixels)+208)) - // =player->UnitColors.Depth24; - case 32: - *((struct __4pixel32__*)(((VMemType32*)sprite->Pixels)+208)) - =player->UnitColors.Depth32; - break; - } -} - -/** -** Change current color set to new player. -** -** @param player Pointer to player. -*/ -global void PlayerPixels(const Player* player) -{ - // FIXME: use function pointer - switch( VideoDepth ) { - case 8: - *((struct __4pixel8__*)(Pixels8+208))=player->UnitColors.Depth8; - break; - case 15: - case 16: - *((struct __4pixel16__*)(Pixels16+208))=player->UnitColors.Depth16; - break; - case 24: - // FIXME: support for real 24 bpp mode - case 32: - *((struct __4pixel32__*)(Pixels32+208))=player->UnitColors.Depth32; - break; - } -} - -/** -** Setup the player colors for the current palette. -** -** FIXME: need better colors for the player 8-16. -** FIXME: could be called before PixelsXX is setup. -*/ -global void SetPlayersPalette(void) -{ - int i; - - switch( VideoDepth ) { - case 8: - // New player colors setup - if( !Pixels8 ) { - DebugLevel0(__FUNCTION__": Wrong setup order\n"); - return; - } - - for( i=0; i<7; ++i ) { - Players[i].UnitColors.Depth8.Pixels[0]=Pixels8[i*4+208]; - Players[i].UnitColors.Depth8.Pixels[1]=Pixels8[i*4+209]; - Players[i].UnitColors.Depth8.Pixels[2]=Pixels8[i*4+210]; - Players[i].UnitColors.Depth8.Pixels[3]=Pixels8[i*4+211]; - - Players[i+8].UnitColors.Depth8.Pixels[0]=Pixels8[i*4+208]; - Players[i+8].UnitColors.Depth8.Pixels[1]=Pixels8[i*4+209]; - Players[i+8].UnitColors.Depth8.Pixels[2]=Pixels8[i*4+210]; - Players[i+8].UnitColors.Depth8.Pixels[3]=Pixels8[i*4+211]; - } - - Players[i].UnitColors.Depth8.Pixels[0]=Pixels8[12]; - Players[i].UnitColors.Depth8.Pixels[1]=Pixels8[13]; - Players[i].UnitColors.Depth8.Pixels[2]=Pixels8[14]; - Players[i].UnitColors.Depth8.Pixels[3]=Pixels8[15]; - Players[i+8].UnitColors.Depth8.Pixels[0]=Pixels8[12]; - Players[i+8].UnitColors.Depth8.Pixels[1]=Pixels8[13]; - Players[i+8].UnitColors.Depth8.Pixels[2]=Pixels8[14]; - Players[i+8].UnitColors.Depth8.Pixels[3]=Pixels8[15]; - - break; - - case 15: - case 16: - // New player colors setup - if( !Pixels16 ) { - DebugLevel0(__FUNCTION__": Wrong setup order\n"); - return; - } - - for( i=0; i<7; ++i ) { - Players[i].UnitColors.Depth16.Pixels[0]=Pixels16[i*4+208]; - Players[i].UnitColors.Depth16.Pixels[1]=Pixels16[i*4+209]; - Players[i].UnitColors.Depth16.Pixels[2]=Pixels16[i*4+210]; - Players[i].UnitColors.Depth16.Pixels[3]=Pixels16[i*4+211]; - - Players[i+8].UnitColors.Depth16.Pixels[0]=Pixels16[i*4+208]; - Players[i+8].UnitColors.Depth16.Pixels[1]=Pixels16[i*4+209]; - Players[i+8].UnitColors.Depth16.Pixels[2]=Pixels16[i*4+210]; - Players[i+8].UnitColors.Depth16.Pixels[3]=Pixels16[i*4+211]; - } - - Players[i].UnitColors.Depth16.Pixels[0]=Pixels16[12]; - Players[i].UnitColors.Depth16.Pixels[1]=Pixels16[13]; - Players[i].UnitColors.Depth16.Pixels[2]=Pixels16[14]; - Players[i].UnitColors.Depth16.Pixels[3]=Pixels16[15]; - Players[i+8].UnitColors.Depth16.Pixels[0]=Pixels16[12]; - Players[i+8].UnitColors.Depth16.Pixels[1]=Pixels16[13]; - Players[i+8].UnitColors.Depth16.Pixels[2]=Pixels16[14]; - Players[i+8].UnitColors.Depth16.Pixels[3]=Pixels16[15]; - - break; - case 24: - // FIXME: support for real 24 bpp mode - case 32: - // New player colors setup - if( !Pixels32 ) { - DebugLevel0(__FUNCTION__": Wrong setup order\n"); - return; - } - - for( i=0; i<7; ++i ) { - Players[i].UnitColors.Depth32.Pixels[0]=Pixels32[i*4+208]; - Players[i].UnitColors.Depth32.Pixels[1]=Pixels32[i*4+209]; - Players[i].UnitColors.Depth32.Pixels[2]=Pixels32[i*4+210]; - Players[i].UnitColors.Depth32.Pixels[3]=Pixels32[i*4+211]; - - Players[i+8].UnitColors.Depth32.Pixels[0]=Pixels32[i*4+208]; - Players[i+8].UnitColors.Depth32.Pixels[1]=Pixels32[i*4+209]; - Players[i+8].UnitColors.Depth32.Pixels[2]=Pixels32[i*4+210]; - Players[i+8].UnitColors.Depth32.Pixels[3]=Pixels32[i*4+211]; - } - - Players[i].UnitColors.Depth32.Pixels[0]=Pixels32[12]; - Players[i].UnitColors.Depth32.Pixels[1]=Pixels32[13]; - Players[i].UnitColors.Depth32.Pixels[2]=Pixels32[14]; - Players[i].UnitColors.Depth32.Pixels[3]=Pixels32[15]; - Players[i+8].UnitColors.Depth32.Pixels[0]=Pixels32[12]; - Players[i+8].UnitColors.Depth32.Pixels[1]=Pixels32[13]; - Players[i+8].UnitColors.Depth32.Pixels[2]=Pixels32[14]; - Players[i+8].UnitColors.Depth32.Pixels[3]=Pixels32[15]; - - break; - } -} - -#endif - /** ** Output debug informations for players. */ diff --git a/src/ui/botpanel.cpp b/src/ui/botpanel.cpp index a3475d87d..6c21220b3 100644 --- a/src/ui/botpanel.cpp +++ b/src/ui/botpanel.cpp @@ -210,9 +210,7 @@ global void DrawButtonPanel(void) return; } -#ifndef NEW_VIDEO PlayerPixels(ThisPlayer); // could only select own units. -#endif for( i=0; i<9; ++i ) { if( buttons[i].Pos!=-1 ) { @@ -272,13 +270,8 @@ global void DrawButtonPanel(void) } } -#ifdef NEW_VIDEO DrawUnitIcon(ThisPlayer,buttons[i].Icon.Icon ,v,TheUI.Buttons[i+10].X,TheUI.Buttons[i+10].Y); -#else - DrawUnitIcon(buttons[i].Icon.Icon - ,v,TheUI.Buttons[i+10].X,TheUI.Buttons[i+10].Y); -#endif // // Update status line for this button diff --git a/src/ui/console.cpp b/src/ui/console.cpp index b9abbf781..d8dd9a47a 100644 --- a/src/ui/console.cpp +++ b/src/ui/console.cpp @@ -25,8 +25,6 @@ #include "freecraft.h" #include "video.h" -#ifdef NEW_VIDEO - /*---------------------------------------------------------------------------- -- Variables ----------------------------------------------------------------------------*/ @@ -43,6 +41,4 @@ global void DrawConsole(void) DebugLevel3(__FUNCTION__"\n"); } -#endif - //@} diff --git a/src/ui/icons.cpp b/src/ui/icons.cpp index 2d05546d4..6fa8e2331 100644 --- a/src/ui/icons.cpp +++ b/src/ui/icons.cpp @@ -399,12 +399,8 @@ global const char* IdentOfIcon(IconId icon) ** @param x X display position ** @param y Y display position */ -#ifdef NEW_VIDEO global void DrawUnitIcon(const void* player,IconId icon,unsigned flags ,unsigned x,unsigned y) -#else -global void DrawUnitIcon(IconId icon,unsigned flags,unsigned x,unsigned y) -#endif { int color; @@ -430,9 +426,7 @@ global void DrawUnitIcon(IconId icon,unsigned flags,unsigned x,unsigned y) ++x; ++y; } -#ifdef NEW_VIDEO GraphicPlayerPixels(player,Icons[0].IconGraphic); -#endif VideoDrawSub(Icons[0].IconGraphic ,(icon%5)*Icons[0].Width,(icon/5)*Icons[0].Height ,Icons[0].Width,Icons[0].Height,x+4,y+4); diff --git a/src/ui/mainscr.cpp b/src/ui/mainscr.cpp index e9d2998d3..4ca14753e 100644 --- a/src/ui/mainscr.cpp +++ b/src/ui/mainscr.cpp @@ -135,18 +135,10 @@ global void DrawUnitInfo(Unit* unit) // x=TheUI.Buttons[1].X; y=TheUI.Buttons[1].Y; -#ifdef NEW_VIDEO DrawUnitIcon(unit->Player,type->Icon.Icon ,(ButtonUnderCursor==1) ? (IconActive|(MouseButtons&LeftButton)) : 0 ,x,y); -#else - PlayerPixels(unit->Player); - DrawUnitIcon(type->Icon.Icon - ,(ButtonUnderCursor==1) - ? (IconActive|(MouseButtons&LeftButton)) : 0 - ,x,y); -#endif DrawLifeBar(unit,x,y); x=TheUI.InfoPanelX; @@ -187,14 +179,9 @@ global void DrawUnitInfo(Unit* unit) if( unit->Command.Action==UnitActionTrain ) { if( OriginalTraining || unit->Command.Data.Train.Count==1 ) { DrawText(x+37,y+8+78,GameFont,"Training:"); -#ifdef NEW_VIDEO DrawUnitIcon(unit->Player ,unit->Command.Data.Train.What[0]->Icon.Icon ,0,x+107,y+8+70); -#else - DrawUnitIcon(unit->Command.Data.Train.What[0]->Icon.Icon - ,0,x+107,y+8+70); -#endif DrawCompleted( unit->Command.Data.Train.What[0] @@ -204,18 +191,11 @@ global void DrawUnitInfo(Unit* unit) DrawTextCentered(x+114,y+8+29,GameFont,"Training..."); for( i = 0; i < unit->Command.Data.Train.Count; i++ ) { -#ifdef NEW_VIDEO DrawUnitIcon(unit->Player ,unit->Command.Data.Train.What[i]->Icon.Icon ,(ButtonUnderCursor==i+4) ? (IconActive|(MouseButtons&LeftButton)) : 0 ,TheUI.Buttons2[i].X,TheUI.Buttons2[i].Y); -#else - DrawUnitIcon(unit->Command.Data.Train.What[i]->Icon.Icon - ,(ButtonUnderCursor==i+4) - ? (IconActive|(MouseButtons&LeftButton)) : 0 - ,TheUI.Buttons2[i].X,TheUI.Buttons2[i].Y); -#endif } DrawCompleted( @@ -227,14 +207,9 @@ global void DrawUnitInfo(Unit* unit) } if( unit->Command.Action==UnitActionUpgradeTo ) { DrawText(x+29,y+8+78,GameFont,"Upgrading:"); -#ifdef NEW_VIDEO DrawUnitIcon(unit->Player ,unit->Command.Data.UpgradeTo.What->Icon.Icon ,0,x+107,y+8+70); -#else - DrawUnitIcon(unit->Command.Data.UpgradeTo.What->Icon.Icon - ,0,x+107,y+8+70); -#endif DrawCompleted( unit->Command.Data.UpgradeTo.What @@ -244,14 +219,9 @@ global void DrawUnitInfo(Unit* unit) } if( unit->Command.Action==UnitActionResearch ) { DrawText(16,y+8+78,GameFont,"Researching:"); -#ifdef NEW_VIDEO DrawUnitIcon(unit->Player ,unit->Command.Data.Research.What->Icon ,0,x+107,y+8+70); -#else - DrawUnitIcon(unit->Command.Data.Research.What->Icon - ,0,x+107,y+8+70); -#endif DrawCompleted( unit->Command.Data.Research.What->Costs[TimeCost] @@ -301,18 +271,11 @@ global void DrawUnitInfo(Unit* unit) DrawText(x+91,y+8+33,GameFont,buf); for( i=0; i<6; ++i ) { if( unit->OnBoard[i]!=NoUnitP ) { -#ifdef NEW_VIDEO DrawUnitIcon(unit->Player ,unit->OnBoard[i]->Type->Icon.Icon ,(ButtonUnderCursor==i+4) ? (IconActive|(MouseButtons&LeftButton)) : 0 ,TheUI.Buttons[i+4].X,TheUI.Buttons[i+4].Y); -#else - DrawUnitIcon(unit->OnBoard[i]->Type->Icon.Icon - ,(ButtonUnderCursor==i+4) - ? (IconActive|(MouseButtons&LeftButton)) : 0 - ,TheUI.Buttons[i+4].X,TheUI.Buttons[i+4].Y); -#endif DrawLifeBar(unit->OnBoard[i] ,TheUI.Buttons[i+4].X,TheUI.Buttons[i+4].Y); // FIXME: show also the magic bar :) I want this always. @@ -730,18 +693,11 @@ global void DrawInfoPanel(void) PlayerPixels(ThisPlayer); // can only be own! DrawInfoPanelBackground(0); for( i=0; i<NumSelected; ++i ) { -#ifdef NEW_VIDEO DrawUnitIcon(ThisPlayer ,Selected[i]->Type->Icon.Icon ,(ButtonUnderCursor==i+1) ? (IconActive|(MouseButtons&LeftButton)) : 0 ,TheUI.Buttons[i+1].X,TheUI.Buttons[i+1].Y); -#else - DrawUnitIcon(Selected[i]->Type->Icon.Icon - ,(ButtonUnderCursor==i+1) - ? (IconActive|(MouseButtons&LeftButton)) : 0 - ,TheUI.Buttons[i+1].X,TheUI.Buttons[i+1].Y); -#endif DrawLifeBar(Selected[i] ,TheUI.Buttons[i+1].X,TheUI.Buttons[i+1].Y); diff --git a/src/ui/menus.cpp b/src/ui/menus.cpp index 3a2a2a300..8df9e1d37 100644 --- a/src/ui/menus.cpp +++ b/src/ui/menus.cpp @@ -35,11 +35,6 @@ #include "interface.h" #include "menus.h" #include "cursor.h" -#include "new_video.h" - -#ifndef NEW_VIDEO -//#error ONLY WORKS WITH NEW VIDEO! -#endif /*---------------------------------------------------------------------------- -- Prototypes for action handlers diff --git a/src/unit/unit.cpp b/src/unit/unit.cpp index 7f6a72c46..48cd46c84 100644 --- a/src/unit/unit.cpp +++ b/src/unit/unit.cpp @@ -2289,13 +2289,8 @@ global void DestroyUnit(Unit* unit) unit->State=unit->Type->CorpseScript; unit->Type=type; -#ifdef NEW_VIDEO unit->IX=(type->Width-VideoGraphicWidth(type->Sprite))/2; unit->IY=(type->Height-VideoGraphicHeight(type->Sprite))/2; -#else - unit->IX=(type->Width-type->RleSprite->Width)/2; - unit->IY=(type->Height-type->RleSprite->Height)/2; -#endif unit->SubAction=0; unit->Removed=0; diff --git a/src/unit/unit_draw.cpp b/src/unit/unit_draw.cpp index 39e9649bb..badf9c793 100644 --- a/src/unit/unit_draw.cpp +++ b/src/unit/unit_draw.cpp @@ -108,11 +108,7 @@ typedef struct _decoration_ { int Height; /// height of the decoration // --- FILLED UP --- -#ifdef NEW_VIDEO Graphic* Sprite; /// loaded sprite images -#else - RleSprite* RleSprite; /// loaded sprite images -#endif } Decoration; /** @@ -187,21 +183,12 @@ global SCM CclHealthSprite(SCM file,SCM x,SCM y,SCM w,SCM h) */ global void LoadDecorations(void) { -#ifdef NEW_VIDEO HealthSprite.Sprite=LoadSprite(HealthSprite.File ,HealthSprite.Width,HealthSprite.Height); ManaSprite.Sprite=LoadSprite(ManaSprite.File ,ManaSprite.Width,ManaSprite.Height); ShadowSprite.Sprite=LoadSprite(ShadowSprite.File ,ShadowSprite.Width,ShadowSprite.Height); -#else - HealthSprite.RleSprite=LoadRleSprite(HealthSprite.File - ,HealthSprite.Width,HealthSprite.Height); - ManaSprite.RleSprite=LoadRleSprite(ManaSprite.File - ,ManaSprite.Width,ManaSprite.Height); - ShadowSprite.RleSprite=LoadRleSprite(ShadowSprite.File - ,ShadowSprite.Width,ShadowSprite.Height); -#endif } /** @@ -281,11 +268,7 @@ local void DrawDecoration(Unit* unit,const UnitType* type,int x,int y) +(type->TileHeight*TileSizeY -type->BoxHeight+1)/2; } -#ifdef NEW_VIDEO VideoDrawClip(HealthSprite.Sprite,n,x1,y1); -#else - DrawRleSpriteClipped(HealthSprite.RleSprite,n,x1,y1); -#endif } } @@ -323,12 +306,8 @@ local void DrawDecoration(Unit* unit,const UnitType* type,int x,int y) } else if( f>25 ) { n=2; // FIXME: v--- compatibility hack -#ifdef NEW_VIDEO } else if( f && ManaSprite.Width*4<VideoGraphicWidth(ManaSprite.Sprite) ) { -#else - } else if( f && ManaSprite.Width*4<ManaSprite.RleSprite->Width ) { -#endif n=3; } else { n=4; @@ -351,11 +330,7 @@ local void DrawDecoration(Unit* unit,const UnitType* type,int x,int y) +(type->TileHeight*TileSizeY -type->BoxHeight+1)/2; } -#ifdef NEW_VIDEO VideoDrawClip(ManaSprite.Sprite,n,x1,y1); -#else - DrawRleSpriteClipped(ManaSprite.RleSprite,n,x1,y1); -#endif } } @@ -386,13 +361,8 @@ local void DrawShadow(Unit* unit,UnitType* type,int x,int y) } DebugLevel3("Box-height %d\n",type->BoxHeight); -#ifdef NEW_VIDEO VideoDrawClip(ShadowSprite.Sprite,i ,x+ShadowSprite.HotX,y+ShadowSprite.HotY); -#else - DrawRleSpriteClipped(ShadowSprite.RleSprite,i - ,x+ShadowSprite.HotX,y+ShadowSprite.HotY); -#endif } /** @@ -584,11 +554,7 @@ local void DrawBuilding(Unit* unit) } #endif -#ifdef NEW_VIDEO GraphicPlayerPixels(unit->Player,unit->Type->Sprite); -#else - RLEPlayerPixels(unit->Player,unit->Type->RleSprite); -#endif x=Map2ScreenX(unit->X)+unit->IX; y=Map2ScreenY(unit->Y)+unit->IY; @@ -596,11 +562,7 @@ local void DrawBuilding(Unit* unit) // Buildings under construction/upgrade/ready. // if( unit->Command.Action==UnitActionBuilded ) { -#ifdef NEW_VIDEO if( unit->Constructed || VideoGraphicFrames(type->Sprite)<=1 ) { -#else - if( unit->Constructed || type->RleSprite->NumFrames<=1 ) { -#endif DrawConstruction(type->OverlapFrame ,frame&127 ,x+(type->TileWidth*TileSizeX)/2 @@ -645,11 +607,7 @@ local void DrawUnit(Unit* unit) DrawSelectionRectangle(unit,type,x,y); -#ifdef NEW_VIDEO GraphicPlayerPixels(unit->Player,unit->Type->Sprite); -#else - RLEPlayerPixels(unit->Player,unit->Type->RleSprite); -#endif DrawUnitType(type,unit->Frame,x,y); stats=unit->Stats; diff --git a/src/unit/unittype.cpp b/src/unit/unittype.cpp index 006256812..667e1f754 100644 --- a/src/unit/unittype.cpp +++ b/src/unit/unittype.cpp @@ -1105,13 +1105,8 @@ global void LoadUnitSprites(void) buf=alloca(strlen(file)+9+1); file=strcat(strcpy(buf,"graphic/"),file); ShowLoadProgress("\tUnit `%s'\n",file); -#ifdef NEW_VIDEO UnitTypes[type].Sprite=LoadSprite(file ,UnitTypes[type].Width,UnitTypes[type].Height); -#else - UnitTypes[type].RleSprite=LoadRleSprite(file - ,UnitTypes[type].Width,UnitTypes[type].Height); -#endif } } @@ -1126,11 +1121,7 @@ global void LoadUnitSprites(void) ,UnitTypes[type].SameSprite); exit(-1); } -#ifdef NEW_VIDEO UnitTypes[type].Sprite=unittype->Sprite; -#else - UnitTypes[type].RleSprite=unittype->RleSprite; -#endif } // @@ -1172,19 +1163,11 @@ global void DrawUnitType(const UnitType* type,unsigned frame,int x,int y) y-=(type->Height-type->TileHeight*TileSizeY)/2; // FIXME: This is a hack for mirrored sprites -#ifdef NEW_VIDEO if( frame&128 ) { VideoDrawClipX(type->Sprite,frame&127,x,y); } else { VideoDrawClip(type->Sprite,frame,x,y); } -#else - if( frame&128 ) { - DrawRleSpriteClippedX(type->RleSprite,frame&127,x,y); - } else { - DrawRleSpriteClipped(type->RleSprite,frame,x,y); - } -#endif } //@} diff --git a/src/video/Makefile b/src/video/Makefile index 00f5e8cad..09e5c7235 100644 --- a/src/video/Makefile +++ b/src/video/Makefile @@ -20,7 +20,7 @@ TOPDIR = ../.. include $(TOPDIR)/Rules.make MODULE = video -OBJS = new_video.$(OE) video.$(OE) cursor.$(OE) sprite.$(OE) \ +OBJS = video.$(OE) cursor.$(OE) sprite.$(OE) \ graphic.$(OE) linedraw.$(OE) font.$(OE) png.$(OE) \ sdl.$(OE) new_X11.$(OE) X11.$(OE) svgalib.$(OE) diff --git a/src/video/X11.cpp b/src/video/X11.cpp index 31f40d399..e69580ff5 100644 --- a/src/video/X11.cpp +++ b/src/video/X11.cpp @@ -19,6 +19,11 @@ #ifdef USE_X11 +// FIXME: move this and clean up to new_X11. +// FIXME: move this and clean up to new_X11. +// FIXME: move this and clean up to new_X11. +// FIXME: move this and clean up to new_X11. +// FIXME: move this and clean up to new_X11. // FIXME: move this and clean up to new_X11. #include <stdio.h> @@ -60,28 +65,6 @@ #include "ui.h" #include "new_video.h" -#ifndef NEW_VIDEO - -/** -** Architecture-dependant video memory. Set by InitVideoXXX. -** -** @see InitVideo -*/ -global void* VideoMemory; - -/** -** Architecture-dependant video depth. Set by InitVideoXXX. -** -** @see InitVideo -*/ -global int VideoDepth; - -global VMemType8 * Pixels8; -global VMemType16 * Pixels16; -global VMemType32 * Pixels32; - -#endif - local Display* TheDisplay; /// My X11 display local int TheScreen; /// My X11 screen local Window TheMainWindow; /// My X11 window @@ -94,11 +77,6 @@ local Atom WmDeleteWindowAtom; /// Atom for WM_DELETE_WINDOW -- Sync ----------------------------------------------------------------------------*/ -#ifndef NEW_VIDEO -global int VideoSyncSpeed=100; // 0 disable interrupts -volatile int VideoInterrupts; // be happy, were are quicker -#endif - /** ** Called from SIGALRM. */ @@ -839,11 +817,7 @@ global void WaitEventsAndKeepSync(void) ** ** @returns A hardware dependend pixel table. */ -#ifdef NEW_VIDEO global VMemType* VideoCreateNewPalette(const Palette *palette) -#else -global GraphicData * VideoCreateNewPalette(const Palette *palette) -#endif { XColor color; XWindowAttributes xwa; @@ -934,118 +908,6 @@ global GraphicData * VideoCreateNewPalette(const Palette *palette) return pixels; } -#ifndef NEW_VIDEO - -/** -** Color cycle. -*/ -global void ColorCycle(void) -{ - int i; - int x; - - // FIXME: this isn't 100% correct - // Color cycling info - forest: - // 3 flash red/green (attacked building on minimap) - // 38-47 cycle (water) - // 48-56 cycle (water-coast boundary) - // 202 pulsates red (Circle of Power) - // 240-244 cycle (water around ships, Runestone, Dark Portal) - // Color cycling info - swamp: - // 3 flash red/green (attacked building on minimap) - // 4 pulsates red (Circle of Power) - // 5-9 cycle (Runestone, Dark Portal) - // 38-47 cycle (water) - // 88-95 cycle (waterholes in coast and ground) - // 240-244 cycle (water around ships) - // Color cycling info - wasteland: - // 3 flash red/green (attacked building on minimap) - // 38-47 cycle (water) - // 64-70 cycle (coast) - // 202 pulsates red (Circle of Power) - // 240-244 cycle (water around ships, Runestone, Dark Portal) - // Color cycling info - winter: - // 3 flash red/green (attacked building on minimap) - // 40-47 cycle (water) - // 48-54 cycle (half-sunken ice-floe) - // 202 pulsates red (Circle of Power) - // 205-207 cycle (lights on christmas tree) - // 240-244 cycle (water around ships, Runestone, Dark Portal) - - // FIXME: function pointer - switch( VideoDepth ) { - case 8: - x = ((VMemType8*)TheMap.TileData->Pixels)[38]; - for(i = 38; i < 47; ++i){ - ((VMemType8*)TheMap.TileData->Pixels)[i] = - ((VMemType8*)TheMap.TileData->Pixels)[i+1]; - } - ((VMemType8*)TheMap.TileData->Pixels)[47] = x; - - x=Pixels8[38]; - for( i=38; i<47; ++i ) { // tileset color cycle - Pixels8[i]=Pixels8[i+1]; - } - Pixels8[47]=x; - - x=Pixels8[240]; - for( i=240; i<244; ++i ) { // units/icons color cycle - Pixels8[i]=Pixels8[i+1]; - } - Pixels8[244]=x; - break; - case 15: - case 16: - x = ((VMemType16*)TheMap.TileData->Pixels)[38]; - for(i = 38; i < 47; ++i){ - ((VMemType16*)TheMap.TileData->Pixels)[i] = - ((VMemType16*)TheMap.TileData->Pixels)[i+1]; - } - ((VMemType16*)TheMap.TileData->Pixels)[47] = x; - - x=Pixels16[38]; - for( i=38; i<47; ++i ) { // tileset color cycle - Pixels16[i]=Pixels16[i+1]; - } - Pixels16[47]=x; - - x=Pixels16[240]; - for( i=240; i<244; ++i ) { // units/icons color cycle - Pixels16[i]=Pixels16[i+1]; - } - Pixels16[244]=x; - break; - case 24: - case 32: - x = ((VMemType32*)TheMap.TileData->Pixels)[38]; - for(i = 38; i < 47; ++i){ - ((VMemType32*)TheMap.TileData->Pixels)[i] = - ((VMemType32*)TheMap.TileData->Pixels)[i+1]; - } - ((VMemType32*)TheMap.TileData->Pixels)[47] = x; - - - - x=Pixels32[38]; - for( i=38; i<47; ++i ) { // tileset color cycle - Pixels32[i]=Pixels32[i+1]; - } - Pixels32[47]=x; - - x=Pixels32[240]; - for( i=240; i<244; ++i ) { // units/icons color cycle - Pixels32[i]=Pixels32[i+1]; - } - Pixels32[244]=x; - break; - } - - MapColorCycle(); // FIXME: could be little more informativer - MustRedraw|=RedrawMap|RedrawInfoPanel; -} - -#endif - /** ** Check video interrupt. ** @@ -1062,13 +924,6 @@ global void CheckVideoInterrupts(void) ,False); ); ++SlowFrameCounter; -#if 0 - } else { - struct itimerval itv; - - getitimer(ITIMER_REAL,&itv); - DebugLevel1("Remain %d\n",itv.it_value.tv_usec); -#endif } } diff --git a/src/video/cursor.cpp b/src/video/cursor.cpp index 878a542c9..402b7e731 100644 --- a/src/video/cursor.cpp +++ b/src/video/cursor.cpp @@ -139,19 +139,15 @@ global int OldCursorH; /// saved cursor height in pixel global int OldCursorSize; /// size of saved cursor image global void* OldCursorImage; /// background saved behind cursor -#ifdef NEW_VIDEO - /// Save background behind cursor + /// Function pointer: Save background behind cursor local void (*SaveCursorBackground)(int,int,int,int); - /// Load background behind cursor + /// Function pointer: Load background behind cursor local void (*LoadCursorBackground)(int,int,int,int); -#endif /*---------------------------------------------------------------------------- -- Functions ----------------------------------------------------------------------------*/ -#ifdef NEW_VIDEO - /** ** Restore cursor background for 8bpp frame buffer. ** @@ -368,8 +364,6 @@ local void SaveCursorBackground32(int x,int y,int w,int h) } } -#endif - /** ** Load all cursor sprites. ** @@ -387,15 +381,8 @@ global void LoadCursors(unsigned int race) if (last_race != -1) { // free previous sprites for different race for( i=0; i<sizeof(Cursors)/sizeof(*Cursors); ++i ) { -#ifdef NEW_VIDEO VideoSaveFree(Cursors[i].Sprite); Cursors[i].Sprite = NULL; -#else - if (Cursors[i].RleSprite) { - FreeRleSprite(Cursors[i].RleSprite); - Cursors[i].RleSprite = NULL; - } -#endif } } last_race = race; @@ -414,14 +401,8 @@ global void LoadCursors(unsigned int race) buf=alloca(strlen(file)+9+1); file=strcat(strcpy(buf,"graphic/"),file); ShowLoadProgress("\tCursor %s\n",file); -#ifdef NEW_VIDEO - Cursors[i].Sprite=LoadSprite(file,0,0); // FIXME: real size? -#else - Cursors[i].RleSprite=LoadRleSprite(file,0,0); - // FIXME: this is hack!! - //,Cursors[i].Width,Cursors[i].Height); -#endif + Cursors[i].Sprite=LoadSprite(file,0,0); } } } @@ -431,9 +412,6 @@ global void LoadCursors(unsigned int race) */ local void SaveCursor(void) { -#ifndef NEW_VIDEO - int i; -#endif int w; int h; int x; @@ -465,72 +443,7 @@ local void SaveCursor(void) return; } -#ifdef NEW_VIDEO SaveCursorBackground(x,y,w,h); -#else - // FIXME: use function pointer - switch( VideoDepth ) { - case 8: - i=w*h*sizeof(VMemType8); - break; - case 15: - case 16: - i=w*h*sizeof(VMemType16); - break; - case 24: - case 32: - default: - i=w*h*sizeof(VMemType32); - break; - } - if( OldCursorSize<i ) { - if( OldCursorImage ) { - OldCursorImage=realloc(OldCursorImage,i); - } else { - OldCursorImage=malloc(i); - } - DebugLevel3("Cursor memory %d\n",i); - OldCursorSize=i; - } - // FIXME: use function pointer - switch( VideoDepth ) { - case 8: - { VMemType8 *dp; - VMemType8 *sp; - dp=OldCursorImage; - sp=VideoMemory8+y*VideoWidth+x; - while( h-- ) { - memcpy(dp,sp,w*sizeof(VMemType8)); - dp+=w; - sp+=VideoWidth; - } - break; } - case 15: - case 16: - { VMemType16 *dp; - VMemType16 *sp; - dp=OldCursorImage; - sp=VideoMemory16+y*VideoWidth+x; - while( h-- ) { - memcpy(dp,sp,w*sizeof(VMemType16)); - dp+=w; - sp+=VideoWidth; - } - break; } - case 24: - case 32: - { VMemType32 *dp; - VMemType32 *sp; - dp=OldCursorImage; - sp=VideoMemory32+y*VideoWidth+x; - while( h-- ) { - memcpy(dp,sp,w*sizeof(VMemType32)); - dp+=w; - sp+=VideoWidth; - } - break; } - } -#endif } /** @@ -538,24 +451,14 @@ local void SaveCursor(void) */ local void RestoreCursor(void) { -#ifndef NEW_VIDEO - void *dp; - void *sp; -#endif int w; int h; int x; int y; -#ifdef NEW_VIDEO if( !OldCursorImage ) { // no cursor saved return; } -#else - if( !(sp=OldCursorImage) ) { // no cursor saved - return; - } -#endif // FIXME: I should better store the correct values on save. x=OldCursorX; @@ -584,38 +487,7 @@ local void RestoreCursor(void) return; } -#ifdef NEW_VIDEO LoadCursorBackground(x,y,w,h); -#else - switch( VideoDepth ) { - case 8: - dp=VideoMemory8+y*VideoWidth+x; - while( h-- ) { - memcpy(dp,sp,w*sizeof(VMemType8)); - ((VMemType8*)sp)+=w; - ((VMemType8*)dp)+=VideoWidth; - } - break; - case 15: - case 16: - dp=VideoMemory16+y*VideoWidth+x; - while( h-- ) { - memcpy(dp,sp,w*sizeof(VMemType16)); - ((VMemType16*)sp)+=w; - ((VMemType16*)dp)+=VideoWidth; - } - break; - case 24: - case 32: - dp=VideoMemory32+y*VideoWidth+x; - while( h-- ) { - memcpy(dp,sp,w*sizeof(VMemType32)); - ((VMemType32*)sp)+=w; - ((VMemType32*)dp)+=VideoWidth; - } - break; - } -#endif } /** @@ -626,7 +498,6 @@ local void RestoreCursor(void) */ global void DrawCursor(CursorType* type,int x,int y,int frame) { -#ifdef NEW_VIDEO OldCursorX=x-=type->HotX; OldCursorY=y-=type->HotY; OldCursorW=VideoGraphicWidth(type->Sprite); @@ -634,15 +505,6 @@ global void DrawCursor(CursorType* type,int x,int y,int frame) SaveCursor(); VideoDrawClip(type->Sprite,frame,x,y); -#else - OldCursorX=x-=type->HotX; - OldCursorY=y-=type->HotY; - OldCursorW=type->RleSprite->Width; - OldCursorH=type->RleSprite->Height; - - SaveCursor(); - DrawRleSpriteClipped(type->RleSprite,frame,x,y); -#endif } /** @@ -686,12 +548,11 @@ local void DrawBuildingCursor(void) // // Draw building // - PlayerPixels(ThisPlayer); - SetClipping(TheUI.MapX,TheUI.MapY - ,TheUI.MapWidth,TheUI.MapHeight); + PushClipping(); + SetClipping(TheUI.MapX,TheUI.MapY,TheUI.MapWidth,TheUI.MapHeight); + GraphicPlayerPixels(ThisPlayer,CursorBuilding->Sprite); DrawUnitType(CursorBuilding,0,x,y); - // FIXME: This is dangerous here - SetClipping(0,0,VideoWidth,VideoHeight); + PopClipping(); // // Draw the allow overlay @@ -867,7 +728,6 @@ global int HideAnyCursor(void) */ global void InitCursor(void) { -#ifdef NEW_VIDEO switch( VideoDepth ) { case 8: SaveCursorBackground=SaveCursorBackground8; @@ -890,7 +750,6 @@ global void InitCursor(void) DebugLevel0(__FUNCTION__": unsupported %d bpp\n",VideoDepth); abort(); } -#endif } //@} diff --git a/src/video/graphic.cpp b/src/video/graphic.cpp index 098ffa7c6..beb248bd9 100644 --- a/src/video/graphic.cpp +++ b/src/video/graphic.cpp @@ -509,11 +509,8 @@ global Graphic* LoadGraphic(const char* name) } //Palette Not found if(current_link == NULL){ -#ifdef NEW_VIDEO pixels = VideoCreateNewPalette(graphic->Palette); -#else - pixels = (void*)VideoCreateNewPalette(graphic->Palette); -#endif + DebugLevel0("loading new palette with %s\n",name); if(prev_link == NULL){ palette_list = (PaletteLink *)malloc(sizeof(PaletteLink)); diff --git a/src/video/new_X11.cpp b/src/video/new_X11.cpp index d87cb8053..fa03560d2 100644 --- a/src/video/new_X11.cpp +++ b/src/video/new_X11.cpp @@ -9,11 +9,10 @@ // FreeCraft - A free fantasy real time strategy game engine // /**@name new_X11.c - XWindows support. */ -/* -** (c) Copyright 1998-2000 by Lutz Sammer and Valery Shchedrin -** -** $Id$ -*/ +// +// (c) Copyright 1998-2000 by Lutz Sammer and Valery Shchedrin +// +// $Id$ //@{ @@ -25,8 +24,11 @@ #ifdef USE_X11 // { +// FIXME: move the cleanup X11 source to here! + #include "video.h" + /*---------------------------------------------------------------------------- -- Declarations ----------------------------------------------------------------------------*/ @@ -44,9 +46,8 @@ */ global void InitVideoX11(void) { -#ifdef NEW_VIDEO extern void GameInitDisplay(void); -#endif + GameInitDisplay(); // Fall back to old function } diff --git a/src/video/new_video.cpp b/src/video/new_video.cpp deleted file mode 100644 index a3f996670..000000000 --- a/src/video/new_video.cpp +++ /dev/null @@ -1,545 +0,0 @@ -// ___________ _________ _____ __ -// \_ _____/______ ____ ____ \_ ___ \____________ _/ ____\/ |_ -// | __) \_ __ \_/ __ \_/ __ \/ \ \/\_ __ \__ \\ __\\ __\ -// | \ | | \/\ ___/\ ___/\ \____| | \// __ \| | | | -// \___ / |__| \___ >\___ >\______ /|__| (____ /__| |__| -// \/ \/ \/ \/ \/ -// ______________________ ______________________ -// T H E W A R B E G I N S -// FreeCraft - A free fantasy real time strategy game engine -// -/**@name video.c - The universal video functions. */ -/* -** (c) Copyright 1999,2000 by Lutz Sammer -** -** $Id$ -*/ - -//@{ - -/*---------------------------------------------------------------------------- --- Includes -----------------------------------------------------------------------------*/ - -#include <stdio.h> -#include <stdlib.h> - -#include "freecraft.h" -#include "video.h" - -#include "map.h" -#include "ui.h" -#include "cursor.h" - -#ifdef USE_SDL -#include <SDL/SDL.h> -#endif - -/*---------------------------------------------------------------------------- --- Declarations -----------------------------------------------------------------------------*/ - -// JOHNS: This is needed, because later I want to support it all with the same -// executable, choosable at runtime. -#ifdef USE_X11 -#define UseX11 1 -#define UseSdl 0 -#define UseSVGALib 0 -#define UseWin32 0 -#endif - -#ifdef USE_SDL -#define UseX11 0 -#define UseSdl 1 -#define UseSVGALib 0 -#define UseWin32 0 -#endif - -#ifdef USE_SVGALIB -#define UseX11 0 -#define UseSdl 0 -#define UseSVGALib 1 -#define UseWin32 0 -#endif - -#ifdef noUSE_WIN32 -#define UseX11 0 -#define UseSdl 0 -#define UseSVGALib 0 -#define UseWin32 1 -#endif - -/** -** 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 -} Clip; - -/*---------------------------------------------------------------------------- --- Externals -----------------------------------------------------------------------------*/ - -extern void InitVideoSdl(void); -extern void InitVideoX11(void); -extern void InitVideoSVGA(void); -extern void InitVideoWin32(void); - -/*---------------------------------------------------------------------------- --- Variables -----------------------------------------------------------------------------*/ - -global char VideoFullScreen; /// true fullscreen wanted - -#ifdef NEW_VIDEO - -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. - -#ifdef DEBUG -global unsigned AllocatedGraphicMemory; /// Allocated memory for objects -global unsigned CompressedGraphicMemory;/// memory for compressed objects -#endif - - /** - ** Architecture-dependant video depth. Set by InitVideoXXX, if 0. - ** (8,15,16,24,32) - ** @see InitVideo @see InitVideoX11 @see InitVideoSVGA @see InitVideoSdl - ** @see InitVideoWin32 @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 InitVideoX11 @see InitVideoSVGA @see InitVideoSdl - ** @see InitVideoWin32 @see VMemType - */ -global VMemType* VideoMemory; - - /** - ** Architecture-dependant system palette. Applies as conversion between - ** GlobalPalette colors and their representation in videomemory. - ** Set by VideoCreatePalette or VideoSetPalette. - ** @see VideoCreatePalette @VideoSetPalette - */ -global VMemType* Pixels; - -global int VideoSyncSpeed=100; /// 0 disable interrupts -global volatile int VideoInterrupts; /// be happy, were are quicker - -#endif - - /// Loaded system palette. 256-entries long, active system palette. -global Palette GlobalPalette[256]; - -#ifdef NEW_VIDEO - /// Does ColorCycling.. -global void (*ColorCycle)(void); -#endif - -/*---------------------------------------------------------------------------- --- Functions -----------------------------------------------------------------------------*/ - -#ifdef NEW_VIDEO -/** -** 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. -*/ -global void SetClipping(int left,int top,int right,int bottom) -{ - if( left>right ) { left^=right; right^=left; left^=right; } - if( top>bottom ) { top^=bottom; bottom^=top; top^=bottom; } - - if( left<0 ) left=0; - if( top<0 ) top=0; - if( right<0 ) right=0; - if( bottom<0 ) bottom=0; - - if( left>=VideoWidth ) left=VideoWidth-1; - if( right>=VideoWidth ) right=VideoWidth-1; - if( bottom>=VideoHeight ) bottom=VideoHeight-1; - if( top>=VideoHeight ) top=VideoHeight-1; - - ClipX1=left; - ClipY1=top; - ClipX2=right; - ClipY2=bottom; -} - -/** -** Push current clipping. -*/ -global void PushClipping(void) -{ - Clip* clip; - - clip=malloc(sizeof(Clip)); - clip->Next=Clips; - clip->X1=ClipX1; - clip->Y1=ClipY1; - clip->X2=ClipX2; - clip->Y2=ClipY2; - Clips=clip; -} - -/** -** Pop current clipping. -*/ -global void PopClipping(void) -{ - Clip* clip; - - clip=Clips; - if( clip ) { - Clips=clip->Next; - ClipX1=clip->X1; - ClipY1=clip->Y1; - ClipX2=clip->X2; - ClipY2=clip->Y2; - free(clip); - } else { - ClipX1=0; - ClipY1=0; - ClipX2=VideoWidth; - ClipY2=VideoHeight; - } -} - -#endif - -/** -** 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. -*/ -global void DisplayPicture(const char *name) -{ - Graphic* title; - - title=LoadGraphic(name); -#ifdef NEW_VIDEO - VideoSetPalette((VMemType*)title->Pixels); -#else - VideoSetPalette(title->Pixels); -#endif - -#ifdef USE_SDL - // FIXME: should be moved to system/hardware dependend part - { extern SDL_Surface *Screen; /// internal screen - SDL_LockSurface(Screen); - - VideoMemory=Screen->pixels; -#endif - - // FIXME: bigger window ? - VideoDrawSubClip(title,0,0 - ,title->Width,title->Height - ,(VideoWidth-title->Width)/2,(VideoHeight-title->Height)/2); - -#ifdef USE_SDL - // FIXME: should be moved to system/hardware dependend part - SDL_UnlockSurface(Screen); } -#endif - VideoFree(title); - // FIXME: (ARI:) New Palette got stuck in memory? -} - -#ifdef NEW_VIDEO - -/** -** Load palette from resource. Just loads palette, to set it use -** VideoCreatePalette, which sets system palette. -** -** @param pal buffer to store palette (256-entries long) -** @param name resource file name -** -** @see VideoCreatePalette -*/ -global void LoadRGB(Palette *pal, const char *name) -{ - FILE *fp; - int i; - - if((fp=fopen(name,"rb")) == NULL) { - fprintf(stderr,"Can't load palette %s\n",name); - exit(-1); - } - - for(i=0;i<256;i++){ - pal[i].r=fgetc(fp)<<2; - pal[i].g=fgetc(fp)<<2; - pal[i].b=fgetc(fp)<<2; - } - - fclose(fp); -} - -// FIXME: this isn't 100% correct -// Color cycling info - forest: -// 3 flash red/green (attacked building on minimap) -// 38-47 cycle (water) -// 48-56 cycle (water-coast boundary) -// 202 pulsates red (Circle of Power) -// 240-244 cycle (water around ships, Runestone, Dark Portal) -// Color cycling info - swamp: -// 3 flash red/green (attacked building on minimap) -// 4 pulsates red (Circle of Power) -// 5-9 cycle (Runestone, Dark Portal) -// 38-47 cycle (water) -// 88-95 cycle (waterholes in coast and ground) -// 240-244 cycle (water around ships) -// Color cycling info - wasteland: -// 3 flash red/green (attacked building on minimap) -// 38-47 cycle (water) -// 64-70 cycle (coast) -// 202 pulsates red (Circle of Power) -// 240-244 cycle (water around ships, Runestone, Dark Portal) -// Color cycling info - winter: -// 3 flash red/green (attacked building on minimap) -// 40-47 cycle (water) -// 48-54 cycle (half-sunken ice-floe) -// 202 pulsates red (Circle of Power) -// 205-207 cycle (lights on christmas tree) -// 240-244 cycle (water around ships, Runestone, Dark Portal) - -/** -** Color cycle for 8 bpp video mode. -** -** FIXME: not correct cycles only palette of tileset. -** FIXME: Also icons and some units use color cycling. -** FIXME: must be configured by the tileset or global. -*/ -global void ColorCycle8(void) -{ - int i; - int x; - VMemType8* pixels; - - // - // Color cycle tileset palette - // - pixels=TheMap.TileData->Pixels; - x = pixels[38]; - for(i = 38; i < 47; ++i){ - pixels[i] = pixels[i+1]; - } - pixels[47] = x; - - x=Pixels8[38]; - for( i=38; i<47; ++i ) { // tileset color cycle - Pixels8[i]=Pixels8[i+1]; - } - Pixels8[47]=x; - - x=Pixels8[240]; - for( i=240; i<244; ++i ) { // units/icons color cycle - Pixels8[i]=Pixels8[i+1]; - } - Pixels8[244]=x; - - MapColorCycle(); // FIXME: could be little more informativer - MustRedraw|=RedrawMap|RedrawInfoPanel; -} - -/** -** Color cycle for 16 bpp video mode. -** -** FIXME: not correct cycles only palette of tileset. -** FIXME: Also icons and some units use color cycling. -** FIXME: must be configured by the tileset or global. -*/ -global void ColorCycle16(void) -{ - int i; - int x; - VMemType16* pixels; - - // - // Color cycle tileset palette - // - pixels=TheMap.TileData->Pixels; - x = pixels[38]; - for(i = 38; i < 47; ++i){ - pixels[i] = pixels[i+1]; - } - pixels[47] = x; - - x=Pixels16[38]; - for( i=38; i<47; ++i ) { // tileset color cycle - Pixels16[i]=Pixels16[i+1]; - } - Pixels16[47]=x; - - x=Pixels16[240]; - for( i=240; i<244; ++i ) { // units/icons color cycle - Pixels16[i]=Pixels16[i+1]; - } - Pixels16[244]=x; - - MapColorCycle(); // FIXME: could be little more informativer - MustRedraw|=RedrawMap|RedrawInfoPanel; -} - -/** -** Color cycle for 24 bpp video mode. -** -** FIXME: not correct cycles only palette of tileset. -** FIXME: Also icons and some units use color cycling. -** FIXME: must be configured by the tileset or global. -*/ -global void ColorCycle24(void) -{ - int i; - VMemType24 x; - VMemType24* pixels; - - // - // Color cycle tileset palette - // - pixels=TheMap.TileData->Pixels; - x = pixels[38]; - for(i = 38; i < 47; ++i){ - pixels[i] = pixels[i+1]; - } - pixels[47] = x; - - x=Pixels24[38]; - for( i=38; i<47; ++i ) { // tileset color cycle - Pixels24[i]=Pixels24[i+1]; - } - Pixels24[47]=x; - - x=Pixels24[240]; - for( i=240; i<244; ++i ) { // units/icons color cycle - Pixels24[i]=Pixels24[i+1]; - } - Pixels24[244]=x; - - MapColorCycle(); // FIXME: could be little more informativer - MustRedraw|=RedrawMap|RedrawInfoPanel; -} - -/** -** Color cycle for 32 bpp video mode. -** -** FIXME: not correct cycles only palette of tileset. -** FIXME: Also icons and some units use color cycling. -** FIXME: must be configured by the tileset or global. -*/ -global void ColorCycle32(void) -{ - int i; - int x; - VMemType32* pixels; - - // - // Color cycle tileset palette - // - pixels=TheMap.TileData->Pixels; - x = pixels[38]; - for(i = 38; i < 47; ++i){ - pixels[i] = pixels[i+1]; - } - pixels[47] = x; - - x=Pixels32[38]; - for( i=38; i<47; ++i ) { // tileset color cycle - Pixels32[i]=Pixels32[i+1]; - } - Pixels32[47]=x; - - x=Pixels32[240]; - for( i=240; i<244; ++i ) { // units/icons color cycle - Pixels32[i]=Pixels32[i+1]; - } - Pixels32[244]=x; - - MapColorCycle(); // FIXME: could be little more informativer - MustRedraw|=RedrawMap|RedrawInfoPanel; -} - -/** -** Initializes system palette. Also calls SetPlayersPalette to set -** palette for all players. -** -** @param palette VMemType structure, as created by VideoCreateNewPalette -** @see SetPlayersPalette -*/ -global void VideoSetPalette(const VMemType* palette) -{ - if( Pixels ) { - free(Pixels); - } - Pixels=(VMemType*)palette; - SetPlayersPalette(); -} - -/** -** Set the system hardware palette from an independend Palette struct. -** -** @param palette System independ palette structure. -*/ -global void VideoCreatePalette(const Palette* palette) -{ - VMemType* temp; - - temp = VideoCreateNewPalette(palette); - - VideoSetPalette(temp); -} - -#endif - -/** -** Video initialize. -*/ -global void InitVideo(void) -{ - if( UseSdl ) { - InitVideoSdl(); - } else if( UseX11 ) { - InitVideoX11(); - } else if( UseSVGALib ) { - InitVideoSVGA(); - } else if( UseWin32 ) { - InitVideoWin32(); - } else { - IfDebug( abort(); ); - } - - // - // Init video sub modules - // - InitGraphic(); - InitLineDraw(); -#ifdef NEW_VIDEO - InitSprite(); - InitCursor(); - switch( VideoDepth ) { - case 8: ColorCycle=ColorCycle8 ; break; - case 15: - case 16: ColorCycle=ColorCycle16; break; - case 24: ColorCycle=ColorCycle24; break; - case 32: ColorCycle=ColorCycle32; break; - } -#endif - - DebugLevel3(__FUNCTION__": %d %d\n",MapWidth,MapHeight); -} - -//@} diff --git a/src/video/sdl.cpp b/src/video/sdl.cpp index 3dff472b3..1230e8e46 100644 --- a/src/video/sdl.cpp +++ b/src/video/sdl.cpp @@ -40,7 +40,6 @@ #include "interface.h" #include "network.h" #include "ui.h" -#include "new_video.h" #include "sound_server.h" #include "sound.h" @@ -52,26 +51,6 @@ -- Variables ----------------------------------------------------------------------------*/ -#ifndef NEW_VIDEO - -/** -** Architecture-dependant videomemory. Set by GameInitDisplay. -*/ -global void* VideoMemory; - -/** -** Architecture-dependant video depth. Set by GameInitDisplay. -** -** @see GameInitDisplay -*/ -global int VideoDepth; - -global VMemType8 * Pixels8; /// 8 bpp palette FIXME: remove pointer -global VMemType16 * Pixels16; /// 16 bpp palette -global VMemType32 * Pixels32; /// 32 bpp palette - -#endif - /*---------------------------------------------------------------------------- -- Functions ----------------------------------------------------------------------------*/ @@ -80,13 +59,6 @@ global VMemType32 * Pixels32; /// 32 bpp palette -- Sync ----------------------------------------------------------------------------*/ -#ifndef NEW_VIDEO - -global int VideoSyncSpeed=100; // 0 disable interrupts -volatile int VideoInterrupts; // be happy, were are quicker - -#endif - /** ** Called from SIGALRM. */ @@ -601,11 +573,7 @@ global void WaitEventsAndKeepSync(void) ** ** @returns A hardware dependend pixel table. */ -#ifdef NEW_VIDEO global VMemType* VideoCreateNewPalette(const Palette *palette) -#else -global GraphicData* VideoCreateNewPalette(const Palette *palette) -#endif { int i; void* pixels; @@ -680,113 +648,6 @@ global GraphicData* VideoCreateNewPalette(const Palette *palette) return pixels; } -#ifndef NEW_VIDEO - -/** -** Color cycle. -*/ -global void ColorCycle(void) -{ - int i; - int x; - - // FIXME: this isn't 100% correct - // Color cycling info - forest: - // 3 flash red/green (attacked building on minimap) - // 38-47 cycle (water) - // 48-56 cycle (water-coast boundary) - // 202 pulsates red (Circle of Power) - // 240-244 cycle (water around ships, Runestone, Dark Portal) - // Color cycling info - swamp: - // 3 flash red/green (attacked building on minimap) - // 4 pulsates red (Circle of Power) - // 5-9 cycle (Runestone, Dark Portal) - // 38-47 cycle (water) - // 88-95 cycle (waterholes in coast and ground) - // 240-244 cycle (water around ships) - // Color cycling info - wasteland: - // 3 flash red/green (attacked building on minimap) - // 38-47 cycle (water) - // 64-70 cycle (coast) - // 202 pulsates red (Circle of Power) - // 240-244 cycle (water around ships, Runestone, Dark Portal) - // Color cycling info - winter: - // 3 flash red/green (attacked building on minimap) - // 40-47 cycle (water) - // 48-54 cycle (half-sunken ice-floe) - // 202 pulsates red (Circle of Power) - // 205-207 cycle (lights on christmas tree) - // 240-244 cycle (water around ships, Runestone, Dark Portal) - - // FIXME: function pointer - switch( VideoDepth ) { - case 8: - x = ((VMemType8*)TheMap.TileData->Pixels)[38]; - for(i = 38; i < 47; ++i){ - ((VMemType8*)TheMap.TileData->Pixels)[i] = ((VMemType8*)TheMap.TileData->Pixels)[i+1]; - } - ((VMemType8*)TheMap.TileData->Pixels)[47] = x; - - x=Pixels8[38]; - for( i=38; i<47; ++i ) { - Pixels8[i]=Pixels8[i+1]; - } - Pixels8[47]=x; - - x=Pixels8[240]; - for( i=240; i<244; ++i ) { - Pixels8[i]=Pixels8[i+1]; - } - Pixels8[244]=x; - break; - case 15: - case 16: - x = ((VMemType16*)TheMap.TileData->Pixels)[38]; - for(i = 38; i < 47; ++i){ - ((VMemType16*)TheMap.TileData->Pixels)[i] = ((VMemType16*)TheMap.TileData->Pixels)[i+1]; - } - ((VMemType16*)TheMap.TileData->Pixels)[47] = x; - - x=Pixels16[38]; - for( i=38; i<47; ++i ) { // tileset color cycle - Pixels16[i]=Pixels16[i+1]; - } - Pixels16[47]=x; - - x=Pixels16[240]; - for( i=240; i<244; ++i ) { // units/icons color cycle - Pixels16[i]=Pixels16[i+1]; - } - Pixels16[244]=x; - break; - case 24: - case 32: - x = ((VMemType32*)TheMap.TileData->Pixels)[38]; - for(i = 38; i < 47; ++i){ - ((VMemType32*)TheMap.TileData->Pixels)[i] = ((VMemType32*)TheMap.TileData->Pixels)[i+1]; - } - ((VMemType32*)TheMap.TileData->Pixels)[47] = x; - - x=Pixels32[38]; - for( i=38; i<47; ++i ) { // tileset color cycle - Pixels32[i]=Pixels32[i+1]; - } - Pixels32[47]=x; - - x=Pixels32[240]; - for( i=240; i<244; ++i ) { // units/icons color cycle - Pixels32[i]=Pixels32[i+1]; - } - Pixels32[244]=x; - break; - } - - MapColorCycle(); // FIXME: could be little more informativer - MustRedraw|=RedrawMap|RedrawInfoPanel; -} - -#endif - /** ** Check video interrupt. ** diff --git a/src/video/svgalib.cpp b/src/video/svgalib.cpp index 8a2cbbac7..ff3fcf342 100644 --- a/src/video/svgalib.cpp +++ b/src/video/svgalib.cpp @@ -17,9 +17,16 @@ //@{ -#ifdef USE_SVGALIB +/*---------------------------------------------------------------------------- +-- Includes +----------------------------------------------------------------------------*/ #include <stdio.h> + +#include "freecraft.h" + +#ifdef USE_SVGALIB + #include <stdlib.h> #include <string.h> #include <signal.h> @@ -31,7 +38,6 @@ #include <vgamouse.h> #include <vgakeyboard.h> -#include "freecraft.h" #include "video.h" #include "tileset.h" #include "sound_id.h" @@ -52,52 +58,37 @@ #include "ui.h" #include "new_video.h" -#ifndef NEW_VIDEO - -/** -** Architecture-dependant videomemory. Set by GameInitDisplay. -*/ -global void* VideoMemory; - -/** -** Architecture-dependant video depth. Set by GameInitDisplay. -** -** @see GameInitDisplay -*/ -global int VideoDepth; - -global VMemType8 * Pixels8; /// 8 bpp palette FIXME: remove pointer -global VMemType16 * Pixels16; /// 16 bpp palette -global VMemType32 * Pixels32; /// 32 bpp palette - -#endif +/*---------------------------------------------------------------------------- +-- Variables +----------------------------------------------------------------------------*/ local int old_button; /// FIXME: docu? local int mouse_x; /// FIXME: docu? local int mouse_y; /// FIXME: docu? +/*---------------------------------------------------------------------------- +-- Forwards +----------------------------------------------------------------------------*/ + /// FIXME: docu? local void MouseEvent(int button,int dx,int dy,int dz,int drx,int dry,int drz); /// FIXME: docu? local void KeyboardEvent(int scancode,int press); /*---------------------------------------------------------------------------- --- Sync +-- Functions ----------------------------------------------------------------------------*/ -#ifndef NEW_VIDEO - -global int VideoSyncSpeed=100; // 0 disable interrupts -volatile int VideoInterrupts; // be happy, were are quicker - -#endif +/*---------------------------------------------------------------------------- +-- Sync +----------------------------------------------------------------------------*/ /** ** Called from SIGALRM. */ local void VideoSyncHandler(int unused) { - DebugLevel3("Interrupt\n"); + DebugLevel3Fn("Interrupt\n"); ++VideoInterrupts; } @@ -129,7 +120,7 @@ global void SetVideoSync(void) fprintf(stderr,"Can't set itimer\n"); } - // DebugLevel1("Timer installed\n"); + DebugLevel3Fn("Timer installed\n"); } local void CloseDisplay(void) @@ -330,27 +321,27 @@ global void Invalidate(void) */ local void MouseEvent(int button, int dx, int dy, int dz, int drx, int dry, int drz) { if((old_button == 0) && (button == MOUSE_LEFTBUTTON)) { - DebugLevel3("first down\n"); + DebugLevel3Fn("first down\n"); HandleButtonDown(1); } if((old_button == 0) && (button == (MOUSE_LEFTBUTTON + MOUSE_RIGHTBUTTON))) { - DebugLevel3("second down\n"); + DebugLevel3Fn("second down\n"); HandleButtonDown(2); } if((old_button == 0) && (button == MOUSE_RIGHTBUTTON)) { - DebugLevel3("third down\n"); + DebugLevel3Fn("third down\n"); HandleButtonDown(3); } if((old_button == MOUSE_LEFTBUTTON) && (button == 0)) { - DebugLevel3("first up\n"); + DebugLevel3Fn("first up\n"); HandleButtonUp(1); } if((old_button == (MOUSE_LEFTBUTTON + MOUSE_RIGHTBUTTON)) && (button == 0)) { - DebugLevel3("second up\n"); + DebugLevel3Fn("second up\n"); HandleButtonUp(2); } if((old_button == MOUSE_RIGHTBUTTON) && (button == 0)) { - DebugLevel3("third up\n"); + DebugLevel3Fn("third up\n"); HandleButtonUp(3); } old_button = button; @@ -968,21 +959,11 @@ global void WaitEventsAndKeepSync(void) ** ** @returns A hardware dependend pixel table. */ -#ifdef NEW_VIDEO global VMemType* VideoCreateNewPalette(const Palette *palette) -#else -global GraphicData * VideoCreateNewPalette(const Palette *palette) -#endif { int i; void* pixels; -/* - if( !Screen ) { // no init - return NULL; - } -*/ - switch( VideoDepth ) { case 8: pixels=malloc(256*sizeof(VMemType8)); @@ -992,11 +973,14 @@ global GraphicData * VideoCreateNewPalette(const Palette *palette) pixels=malloc(256*sizeof(VMemType16)); break; case 24: + // pixels=malloc(256*sizeof(VMemType24)); + // break; + // FIXME: real 24bpp case 32: pixels=malloc(256*sizeof(VMemType32)); break; default: - DebugLevel0(__FUNCTION__": Unknown depth\n"); + DebugLevel0Fn("Unknown depth\n"); return NULL; } @@ -1047,102 +1031,13 @@ global GraphicData * VideoCreateNewPalette(const Palette *palette) case 32: // FIXME: write this please default: - DebugLevel0(__FUNCTION__": Depth not written\n"); + DebugLevel0Fn("Depth not written\n"); } } return pixels; } -#ifndef NEW_VIDEO - -/** -** Color cycle. -*/ -global void ColorCycle(void) -{ - int i; - int x; - - // FIXME: this isn't 100% correct - // Color cycling info - forest: - // 3 flash red/green (attacked building on minimap) - // 38-47 cycle (water) - // 48-56 cycle (water-coast boundary) - // 202 pulsates red (Circle of Power) - // 240-244 cycle (water around ships, Runestone, Dark Portal) - // Color cycling info - swamp: - // 3 flash red/green (attacked building on minimap) - // 4 pulsates red (Circle of Power) - // 5-9 cycle (Runestone, Dark Portal) - // 38-47 cycle (water) - // 88-95 cycle (waterholes in coast and ground) - // 240-244 cycle (water around ships) - // Color cycling info - wasteland: - // 3 flash red/green (attacked building on minimap) - // 38-47 cycle (water) - // 64-70 cycle (coast) - // 202 pulsates red (Circle of Power) - // 240-244 cycle (water around ships, Runestone, Dark Portal) - // Color cycling info - winter: - // 3 flash red/green (attacked building on minimap) - // 40-47 cycle (water) - // 48-54 cycle (half-sunken ice-floe) - // 202 pulsates red (Circle of Power) - // 205-207 cycle (lights on christmas tree) - // 240-244 cycle (water around ships, Runestone, Dark Portal) - - // FIXME: function pointer - switch( VideoDepth ) { - case 8: - x=Pixels8[38]; - for( i=38; i<47; ++i ) { // tileset color cycle - Pixels8[i]=Pixels8[i+1]; - } - Pixels8[47]=x; - - x=Pixels8[240]; - for( i=240; i<244; ++i ) { // units/icons color cycle - Pixels8[i]=Pixels8[i+1]; - } - Pixels8[244]=x; - break; - case 15: - case 16: - x=Pixels16[38]; - for( i=38; i<47; ++i ) { // tileset color cycle - Pixels16[i]=Pixels16[i+1]; - } - Pixels16[47]=x; - - x=Pixels16[240]; - for( i=240; i<244; ++i ) { // units/icons color cycle - Pixels16[i]=Pixels16[i+1]; - } - Pixels16[244]=x; - break; - case 24: - case 32: - x=Pixels32[38]; - for( i=38; i<47; ++i ) { // tileset color cycle - Pixels32[i]=Pixels32[i+1]; - } - Pixels32[47]=x; - - x=Pixels32[240]; - for( i=240; i<244; ++i ) { // units/icons color cycle - Pixels32[i]=Pixels32[i+1]; - } - Pixels32[244]=x; - break; - } - - MapColorCycle(); // FIXME: could be little more informativer - MustRedraw|=RedrawMap|RedrawInfoPanel; -} - -#endif - /** ** Check video interrupt. ** @@ -1151,7 +1046,7 @@ global void ColorCycle(void) global void CheckVideoInterrupts(void) { if( VideoInterrupts ) { - //DebugLevel1("Slow frame\n"); + //DebugLevel1Fn("Slow frame\n"); IfDebug( DrawText(TheUI.MapX+10,TheUI.MapY+10,GameFont,"SLOW FRAME!!"); ); diff --git a/src/video/video.cpp b/src/video/video.cpp index 35eb329a7..682d85010 100644 --- a/src/video/video.cpp +++ b/src/video/video.cpp @@ -8,39 +8,149 @@ // T H E W A R B E G I N S // FreeCraft - A free fantasy real time strategy game engine // -/**@name video.c - The video. */ +/**@name video.c - The universal video functions. */ /* -** (c) Copyright 1998,2000 by Lutz Sammer +** (c) Copyright 1999,2000 by Lutz Sammer ** ** $Id$ */ //@{ +/*---------------------------------------------------------------------------- +-- Includes +----------------------------------------------------------------------------*/ + #include <stdio.h> #include <stdlib.h> #include "freecraft.h" #include "video.h" -#ifndef NEW_VIDEO // { should be removed with new video code final +#include "map.h" +#include "ui.h" +#include "cursor.h" -#ifdef DEBUG -global unsigned AllocatedGraphicMemory; -global unsigned CompressedGraphicMemory; +#ifdef USE_SDL +#include <SDL/SDL.h> #endif /*---------------------------------------------------------------------------- --- Clipping +-- Declarations ----------------------------------------------------------------------------*/ +// JOHNS: This is needed, because later I want to support it all with the same +// executable, choosable at runtime. +#ifdef USE_X11 +#define UseX11 1 +#define UseSdl 0 +#define UseSVGALib 0 +#define UseWin32 0 +#endif + +#ifdef USE_SDL +#define UseX11 0 +#define UseSdl 1 +#define UseSVGALib 0 +#define UseWin32 0 +#endif + +#ifdef USE_SVGALIB +#define UseX11 0 +#define UseSdl 0 +#define UseSVGALib 1 +#define UseWin32 0 +#endif + +#ifdef noUSE_WIN32 +#define UseX11 0 +#define UseSdl 0 +#define UseSVGALib 0 +#define UseWin32 1 +#endif + +/** +** 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 +} Clip; + +/*---------------------------------------------------------------------------- +-- Externals +----------------------------------------------------------------------------*/ + +extern void InitVideoSdl(void); +extern void InitVideoX11(void); +extern void InitVideoSVGA(void); +extern void InitVideoWin32(void); + +/*---------------------------------------------------------------------------- +-- Variables +----------------------------------------------------------------------------*/ + +global char VideoFullScreen; /// true fullscreen wanted + 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 -/* -** Set clipping for sprite/line routines. +local Clip* Clips; /// stack of all clips. + +#ifdef DEBUG +global unsigned AllocatedGraphicMemory; /// Allocated memory for objects +global unsigned CompressedGraphicMemory;/// memory for compressed objects +#endif + + /** + ** Architecture-dependant video depth. Set by InitVideoXXX, if 0. + ** (8,15,16,24,32) + ** @see InitVideo @see InitVideoX11 @see InitVideoSVGA @see InitVideoSdl + ** @see InitVideoWin32 @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 InitVideoX11 @see InitVideoSVGA @see InitVideoSdl + ** @see InitVideoWin32 @see VMemType + */ +global VMemType* VideoMemory; + + /** + ** Architecture-dependant system palette. Applies as conversion between + ** GlobalPalette colors and their representation in videomemory. + ** Set by VideoCreatePalette or VideoSetPalette. + ** @see VideoCreatePalette @VideoSetPalette + */ +global VMemType* Pixels; + +global int VideoSyncSpeed=100; /// 0 disable interrupts +global volatile int VideoInterrupts; /// be happy, were are quicker + + /// Loaded system palette. 256-entries long, active system palette. +global Palette GlobalPalette[256]; + + /// Does ColorCycling.. +global void (*ColorCycle)(void); + +/*---------------------------------------------------------------------------- +-- Functions +----------------------------------------------------------------------------*/ + +/** +** 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. */ global void SetClipping(int left,int top,int right,int bottom) { @@ -54,7 +164,7 @@ global void SetClipping(int left,int top,int right,int bottom) if( left>=VideoWidth ) left=VideoWidth-1; if( right>=VideoWidth ) right=VideoWidth-1; - if( bottom>=VideoHeight ) bottom=VideoHeight-1; + if( bottom>=VideoHeight ) bottom=VideoHeight-1; if( top>=VideoHeight ) top=VideoHeight-1; ClipX1=left; @@ -63,1540 +173,88 @@ global void SetClipping(int left,int top,int right,int bottom) ClipY2=bottom; } -/*---------------------------------------------------------------------------- --- RLE Sprites -----------------------------------------------------------------------------*/ - -// FIXME: can also compress same bytes -// Count: transparent - -/*---------------------------------------------------------------------------- --- RLE Sprites 8bit -----------------------------------------------------------------------------*/ - -/* -** Draw rle compressed sprite. +/** +** Push current clipping. */ -global void DrawRleSprite8(RleSprite* sprite,unsigned frame,int x,int y) +global void PushClipping(void) { - const unsigned char* sp; - unsigned w; - VMemType8* dp; - VMemType8* lp; - VMemType8* ep; - VMemType8* pp; - unsigned da; + Clip* clip; - sp=sprite->Frames[frame]; - w=sprite->Width; - da=VideoWidth-w; - dp=VideoMemory8+x+y*VideoWidth; - ep=dp+VideoWidth*sprite->Height; - - while( dp<ep ) { // all lines - lp=dp+w; - do { // 1 line - dp+=*sp++; // transparent - if( dp>=lp ) { - break; - } - pp=dp-1+*sp++; // non-transparent - while( dp<pp ) { - *dp++=((VMemType8*)sprite->Pixels)[*sp++]; - *dp++=((VMemType8*)sprite->Pixels)[*sp++]; - } - if( dp<=pp ) { - *dp++=((VMemType8*)sprite->Pixels)[*sp++]; - } - } while( dp<lp ); - IfDebug( - if( dp!=lp ) - printf(__FUNCTION__": ERROR\n"); - ) - dp+=da; - } + clip=malloc(sizeof(Clip)); + clip->Next=Clips; + clip->X1=ClipX1; + clip->Y1=ClipY1; + clip->X2=ClipX2; + clip->Y2=ClipY2; + Clips=clip; } -/* -** Draw rle compressed sprite with clipping. -*/ -global void DrawRleSpriteClipped8(RleSprite* sprite,unsigned frame,int x,int y) -{ - int ox; - int oy; - int w; - int h; - const unsigned char* sp; - unsigned sw; - VMemType8* dp; - VMemType8* lp; - VMemType8* ep; - VMemType8* pp; - unsigned da; - - ox=oy=0; - sw=w=sprite->Width; - h=sprite->Height; - - if( x<ClipX1 ) { // reduce to visible range - ox=ClipX1-x; - w-=ox; - x=ClipX1; - } - if( x+w>ClipX2 ) { - w=ClipX2-x; - } - - if( y<ClipY1 ) { - oy=ClipY1-y; - h-=oy; - y=ClipY1; - } - if( y+h>ClipY2 ) { - h=ClipY2-y; - } - - if( w<=0 || h<=0 ) { // nothing to draw - return; - } - - // - // Draw the clipped sprite - // - sp=sprite->Frames[frame]; - - // - // Skip top lines - // - while( oy-- ) { - da=0; - do { - da+=*sp++; // transparent - if( da>=sw ) { - break; - } - da+=*sp; // non-transparent - sp+=*sp+1; - } while( da<sw ); - } - - da=VideoWidth-sw; - dp=VideoMemory8+x+y*VideoWidth; - ep=dp+VideoWidth*h; - - if( w==sw ) { // Unclipped horizontal - - while( dp<ep ) { // all lines - lp=dp+sw; - do { // 1 line - dp+=*sp++; // transparent - if( dp>=lp ) { - break; - } - pp=dp-1+*sp++; // non-transparent - while( dp<pp ) { - *dp++=((VMemType8*)sprite->Pixels)[*sp++]; - *dp++=((VMemType8*)sprite->Pixels)[*sp++]; - } - if( dp<=pp ) { - *dp++=((VMemType8*)sprite->Pixels)[*sp++]; - } - } while( dp<lp ); - IfDebug( - if( dp!=lp ) - printf(__FUNCTION__": ERROR\n"); - ) - dp+=da; - } - - } else { // Clip horizontal - //printf("CLIPPING ox %d w %d\n",ox,w); - - da+=ox; - while( dp<ep ) { // all lines - lp=dp+w; - // - // Clip left - // - pp=dp-ox; - for( ;; ) { - pp+=*sp++; // transparent - //printf("T%d-",sp[-1]); - if( pp>=dp ) { - dp=pp; - //printf("C"); - goto middle_trans; - } - pp+=*sp; // non-transparent - //printf("P%d-",sp[0]); - if( pp>=dp ) { - sp+=*sp-(pp-dp)+1; - //printf("C"); - goto middle_pixel; - } - sp+=*sp+1; - } - - // - // Draw middle - // - for( ;; ) { - dp+=*sp++; // transparent - //printf("T%d-",sp[-1]); -middle_trans: - if( dp>=lp ) { - lp+=sw-w-ox; - //printf("C"); - goto right_trans; - } - pp=dp+*sp++; // non-transparent - //printf("P%d-",sp[-1]); -middle_pixel: - //printf("%p, %p, %p\n",dp,pp,lp); - if( pp<lp ) { - while( dp<pp ) { - *dp++=((VMemType8*)sprite->Pixels)[*sp++]; - } - continue; - } - while( dp<lp ) { - *dp++=((VMemType8*)sprite->Pixels)[*sp++]; - } - sp+=pp-dp; - dp=pp; - //printf("C"); - break; - } - - // - // Clip right - // - lp+=sw-w-ox; - while( dp<lp ) { - dp+=*sp++; // transparent -right_trans: - if( dp>=lp ) { - break; - } - dp+=*sp; // non-transparent - sp+=*sp+1; - } - //printf("\n"); - IfDebug( - if( dp!=lp ) - printf(__FUNCTION__": ERROR\n"); - ) - dp+=da; - } - } -} - -/* -** Draw rle compressed sprite, flipped in X. -*/ -global void DrawRleSpriteX8(RleSprite* sprite,unsigned frame,int x,int y) -{ - const unsigned char* sp; - unsigned w; - VMemType8* dp; - VMemType8* lp; - VMemType8* ep; - VMemType8* pp; - unsigned da; - - sp=sprite->Frames[frame]; - w=sprite->Width; - dp=VideoMemory8+x+y*VideoWidth+w; - da=VideoWidth+w; - ep=dp+VideoWidth*sprite->Height; - - while( dp<ep ) { // all lines - lp=dp-w; - do { // 1 line - dp-=*sp++; // transparent - if( dp<=lp ) { - break; - } - pp=dp+1-*sp++; // non-transparent - while( dp>pp ) { - *dp--=((VMemType8*)sprite->Pixels)[*sp++]; - *dp--=((VMemType8*)sprite->Pixels)[*sp++]; - } - if( dp>=pp ) { - *dp--=((VMemType8*)sprite->Pixels)[*sp++]; - } - } while( dp>lp ); - IfDebug( - if( dp!=lp ) - printf(__FUNCTION__": ERROR\n"); - ) - dp+=da; - } -} - -/* -** Draw rle compressed sprite with clipping, flipped in X. -*/ -global void DrawRleSpriteClippedX8(RleSprite* sprite,unsigned frame,int x,int y) -{ - int ox; - int oy; - int w; - int h; - const unsigned char* sp; - unsigned sw; - VMemType8* dp; - VMemType8* lp; - VMemType8* ep; - VMemType8* pp; - unsigned da; - - ox=oy=0; - sw=w=sprite->Width; - h=sprite->Height; - - if( x<ClipX1 ) { // reduce to visible range - ox=ClipX1-x; - w-=ox; - x=ClipX1; - } - if( x+w>ClipX2 ) { - w=ClipX2-x; - } - - if( y<ClipY1 ) { - oy=ClipY1-y; - h-=oy; - y=ClipY1; - } - if( y+h>ClipY2 ) { - h=ClipY2-y; - } - - if( w<=0 || h<=0 ) { // nothing to draw - return; - } - - // - // Draw the clipped sprite - // - sp=sprite->Frames[frame]; - - // - // Skip top lines - // - while( oy-- ) { - da=0; - do { - da+=*sp++; // transparent - if( da>=sw ) { - break; - } - da+=*sp; // non-transparent - sp+=*sp+1; - } while( da<sw ); - } - - da=VideoWidth+sw; - dp=VideoMemory8+x+y*VideoWidth+w; - ep=dp+VideoWidth*h; - - if( w==sw ) { // Unclipped horizontal - - while( dp<ep ) { // all lines - lp=dp-w; - do { // 1 line - dp-=*sp++; // transparent - if( dp<=lp ) { - break; - } - pp=dp+1-*sp++; // non-transparent - while( dp>pp ) { - *dp--=((VMemType8*)sprite->Pixels)[*sp++]; - *dp--=((VMemType8*)sprite->Pixels)[*sp++]; - } - if( dp>=pp ) { - *dp--=((VMemType8*)sprite->Pixels)[*sp++]; - } - } while( dp>lp ); - IfDebug( - if( dp!=lp ) - printf(__FUNCTION__": ERROR\n"); - ) - dp+=da; - } - - } else { // Clip horizontal - //printf("CLIPPING %d %d\n",ox,w); - - da-=sw-w-ox; - while( dp<ep ) { // all lines - lp=dp-w; - // - // Clip right side - // - pp=dp+sw-w-ox; - for( ;; ) { - pp-=*sp++; // transparent - //printf("T%d ",sp[-1]); - if( pp<=dp ) { - dp=pp; - goto middle_trans; - } - pp-=*sp; // non-transparent - //printf("P%d ",sp[0]); - if( pp<=dp ) { - sp+=*sp-(dp-pp)+1; - goto middle_pixel; - } - sp+=*sp+1; - } - - // - // Draw middle - // - for( ;; ) { - dp-=*sp++; // transparent - //printf("T%d ",sp[-1]); -middle_trans: - if( dp<=lp ) { - //printf("CLIP TRANS\n"); - lp-=ox; - goto right_trans; - } - pp=dp-*sp++; // non-transparent - //printf("P%d ",sp[-1]); -middle_pixel: - if( pp>lp ) { - while( dp>pp ) { - *dp--=((VMemType8*)sprite->Pixels)[*sp++]; - } - continue; - } - //printf("%d ",sp[-1]); - while( dp>lp ) { - *dp--=((VMemType8*)sprite->Pixels)[*sp++]; - } - //printf("%d: ",dp-pp); - sp+=dp-pp; - //printf("CLIP PIXEL %d,%d,%d\n",*sp,sp[-1],sp[1]); - dp=pp; - break; - } - - // - // Clip left side - // - lp-=ox; - while( dp>lp ) { - dp-=*sp++; // transparent -right_trans: - if( dp<=lp ) { - break; - } - dp-=*sp; // non-transparent - sp+=*sp+1; - } - IfDebug( - if( dp!=lp ) - printf(__FUNCTION__": ERROR\n"); - ) - dp+=da; - } - } -} - -/*---------------------------------------------------------------------------- --- RLE Sprites 16bit -----------------------------------------------------------------------------*/ - -/* -** Draw rle compressed sprite. -*/ -global void DrawRleSprite16(RleSprite* sprite,unsigned frame,int x,int y) -{ - const unsigned char* sp; - unsigned w; - VMemType16* dp; - VMemType16* lp; - VMemType16* ep; - VMemType16* pp; - unsigned da; - - sp=sprite->Frames[frame]; - w=sprite->Width; - da=VideoWidth-w; - dp=VideoMemory16+x+y*VideoWidth; - ep=dp+VideoWidth*sprite->Height; - - while( dp<ep ) { // all lines - lp=dp+w; - do { // 1 line - dp+=*sp++; // transparent - if( dp>=lp ) { - break; - } - pp=dp-1+*sp++; // non-transparent - while( dp<pp ) { - *dp++=((VMemType16*)sprite->Pixels)[*sp++]; - *dp++=((VMemType16*)sprite->Pixels)[*sp++]; - } - if( dp<=pp ) { - *dp++=((VMemType16*)sprite->Pixels)[*sp++]; - } - } while( dp<lp ); - IfDebug( - if( dp!=lp ) - printf(__FUNCTION__": ERROR\n"); - ) - dp+=da; - } -} - -/* -** Draw rle compressed sprite with clipping. -*/ -global void DrawRleSpriteClipped16(RleSprite* sprite,unsigned frame,int x,int y) -{ - int ox; - int oy; - int w; - int h; - const unsigned char* sp; - unsigned sw; - VMemType16* dp; - VMemType16* lp; - VMemType16* ep; - VMemType16* pp; - unsigned da; - - ox=oy=0; - sw=w=sprite->Width; - h=sprite->Height; - - if( x<ClipX1 ) { // reduce to visible range - ox=ClipX1-x; - w-=ox; - x=ClipX1; - } - if( x+w>ClipX2 ) { - w=ClipX2-x; - } - - if( y<ClipY1 ) { - oy=ClipY1-y; - h-=oy; - y=ClipY1; - } - if( y+h>ClipY2 ) { - h=ClipY2-y; - } - - if( w<=0 || h<=0 ) { // nothing to draw - return; - } - - // - // Draw the clipped sprite - // - sp=sprite->Frames[frame]; - - // - // Skip top lines - // - while( oy-- ) { - da=0; - do { - da+=*sp++; // transparent - if( da>=sw ) { - break; - } - da+=*sp; // non-transparent - sp+=*sp+1; - } while( da<sw ); - } - - da=VideoWidth-sw; - dp=VideoMemory16+x+y*VideoWidth; - ep=dp+VideoWidth*h; - - if( w==sw ) { // Unclipped horizontal - - while( dp<ep ) { // all lines - lp=dp+sw; - do { // 1 line - dp+=*sp++; // transparent - if( dp>=lp ) { - break; - } - pp=dp-1+*sp++; // non-transparent - while( dp<pp ) { - *dp++=((VMemType16*)sprite->Pixels)[*sp++]; - *dp++=((VMemType16*)sprite->Pixels)[*sp++]; - } - if( dp<=pp ) { - *dp++=((VMemType16*)sprite->Pixels)[*sp++]; - } - } while( dp<lp ); - IfDebug( - if( dp!=lp ) - printf(__FUNCTION__": ERROR\n"); - ) - dp+=da; - } - - } else { // Clip horizontal - //printf("CLIPPING ox %d w %d\n",ox,w); - - da+=ox; - while( dp<ep ) { // all lines - lp=dp+w; - // - // Clip left - // - pp=dp-ox; - for( ;; ) { - pp+=*sp++; // transparent - //printf("T%d-",sp[-1]); - if( pp>=dp ) { - dp=pp; - //printf("C"); - goto middle_trans; - } - pp+=*sp; // non-transparent - //printf("P%d-",sp[0]); - if( pp>=dp ) { - sp+=*sp-(pp-dp)+1; - //printf("C"); - goto middle_pixel; - } - sp+=*sp+1; - } - - // - // Draw middle - // - for( ;; ) { - dp+=*sp++; // transparent - //printf("T%d-",sp[-1]); -middle_trans: - if( dp>=lp ) { - lp+=sw-w-ox; - //printf("C"); - goto right_trans; - } - pp=dp+*sp++; // non-transparent - //printf("P%d-",sp[-1]); -middle_pixel: - //printf("%p, %p, %p\n",dp,pp,lp); - if( pp<lp ) { - while( dp<pp ) { - *dp++=((VMemType16*)sprite->Pixels)[*sp++]; - } - continue; - } - while( dp<lp ) { - *dp++=((VMemType16*)sprite->Pixels)[*sp++]; - } - sp+=pp-dp; - dp=pp; - //printf("C"); - break; - } - - // - // Clip right - // - lp+=sw-w-ox; - while( dp<lp ) { - dp+=*sp++; // transparent -right_trans: - if( dp>=lp ) { - break; - } - dp+=*sp; // non-transparent - sp+=*sp+1; - } - //printf("\n"); - IfDebug( - if( dp!=lp ) - printf(__FUNCTION__": ERROR\n"); - ) - dp+=da; - } - } -} - -/* -** Draw rle compressed sprite, flipped in X. -*/ -global void DrawRleSpriteX16(RleSprite* sprite,unsigned frame,int x,int y) -{ - const unsigned char* sp; - unsigned w; - VMemType16* dp; - VMemType16* lp; - VMemType16* ep; - VMemType16* pp; - unsigned da; - - sp=sprite->Frames[frame]; - w=sprite->Width; - dp=VideoMemory16+x+y*VideoWidth+w; - da=VideoWidth+w; - ep=dp+VideoWidth*sprite->Height; - - while( dp<ep ) { // all lines - lp=dp-w; - do { // 1 line - dp-=*sp++; // transparent - if( dp<=lp ) { - break; - } - pp=dp+1-*sp++; // non-transparent - while( dp>pp ) { - *dp--=((VMemType16*)sprite->Pixels)[*sp++]; - *dp--=((VMemType16*)sprite->Pixels)[*sp++]; - } - if( dp>=pp ) { - *dp--=((VMemType16*)sprite->Pixels)[*sp++]; - } - } while( dp>lp ); - IfDebug( - if( dp!=lp ) - printf(__FUNCTION__": ERROR\n"); - ) - dp+=da; - } -} - -/* -** Draw rle compressed sprite with clipping, flipped in X. -*/ -global void DrawRleSpriteClippedX16(RleSprite* sprite,unsigned frame,int x,int y) -{ - int ox; - int oy; - int w; - int h; - const unsigned char* sp; - unsigned sw; - VMemType16* dp; - VMemType16* lp; - VMemType16* ep; - VMemType16* pp; - unsigned da; - - ox=oy=0; - sw=w=sprite->Width; - h=sprite->Height; - - if( x<ClipX1 ) { // reduce to visible range - ox=ClipX1-x; - w-=ox; - x=ClipX1; - } - if( x+w>ClipX2 ) { - w=ClipX2-x; - } - - if( y<ClipY1 ) { - oy=ClipY1-y; - h-=oy; - y=ClipY1; - } - if( y+h>ClipY2 ) { - h=ClipY2-y; - } - - if( w<=0 || h<=0 ) { // nothing to draw - return; - } - - // - // Draw the clipped sprite - // - sp=sprite->Frames[frame]; - - // - // Skip top lines - // - while( oy-- ) { - da=0; - do { - da+=*sp++; // transparent - if( da>=sw ) { - break; - } - da+=*sp; // non-transparent - sp+=*sp+1; - } while( da<sw ); - } - - da=VideoWidth+sw; - dp=VideoMemory16+x+y*VideoWidth+w; - ep=dp+VideoWidth*h; - - if( w==sw ) { // Unclipped horizontal - - while( dp<ep ) { // all lines - lp=dp-w; - do { // 1 line - dp-=*sp++; // transparent - if( dp<=lp ) { - break; - } - pp=dp+1-*sp++; // non-transparent - while( dp>pp ) { - *dp--=((VMemType16*)sprite->Pixels)[*sp++]; - *dp--=((VMemType16*)sprite->Pixels)[*sp++]; - } - if( dp>=pp ) { - *dp--=((VMemType16*)sprite->Pixels)[*sp++]; - } - } while( dp>lp ); - IfDebug( - if( dp!=lp ) - printf(__FUNCTION__": ERROR\n"); - ) - dp+=da; - } - - } else { // Clip horizontal - //printf("CLIPPING %d %d\n",ox,w); - - da-=sw-w-ox; - while( dp<ep ) { // all lines - lp=dp-w; - // - // Clip right side - // - pp=dp+sw-w-ox; - for( ;; ) { - pp-=*sp++; // transparent - //printf("T%d ",sp[-1]); - if( pp<=dp ) { - dp=pp; - goto middle_trans; - } - pp-=*sp; // non-transparent - //printf("P%d ",sp[0]); - if( pp<=dp ) { - sp+=*sp-(dp-pp)+1; - goto middle_pixel; - } - sp+=*sp+1; - } - - // - // Draw middle - // - for( ;; ) { - dp-=*sp++; // transparent - //printf("T%d ",sp[-1]); -middle_trans: - if( dp<=lp ) { - //printf("CLIP TRANS\n"); - lp-=ox; - goto right_trans; - } - pp=dp-*sp++; // non-transparent - //printf("P%d ",sp[-1]); -middle_pixel: - if( pp>lp ) { - while( dp>pp ) { - *dp--=((VMemType16*)sprite->Pixels)[*sp++]; - } - continue; - } - //printf("%d ",sp[-1]); - while( dp>lp ) { - *dp--=((VMemType16*)sprite->Pixels)[*sp++]; - } - //printf("%d: ",dp-pp); - sp+=dp-pp; - //printf("CLIP PIXEL %d,%d,%d\n",*sp,sp[-1],sp[1]); - dp=pp; - break; - } - - // - // Clip left side - // - lp-=ox; - while( dp>lp ) { - dp-=*sp++; // transparent -right_trans: - if( dp<=lp ) { - break; - } - dp-=*sp; // non-transparent - sp+=*sp+1; - } - IfDebug( - if( dp!=lp ) - printf(__FUNCTION__": ERROR\n"); - ) - dp+=da; - } - } -} - -/*---------------------------------------------------------------------------- --- RLE Sprites 32bit -----------------------------------------------------------------------------*/ - -/* -** Draw rle compressed sprite. -*/ -global void DrawRleSprite32(RleSprite* sprite,unsigned frame,int x,int y) -{ - const unsigned char* sp; - unsigned w; - VMemType32* dp; - VMemType32* lp; - VMemType32* ep; - VMemType32* pp; - unsigned da; - - sp=sprite->Frames[frame]; - w=sprite->Width; - da=VideoWidth-w; - dp=VideoMemory32+x+y*VideoWidth; - ep=dp+VideoWidth*sprite->Height; - - while( dp<ep ) { // all lines - lp=dp+w; - do { // 1 line - dp+=*sp++; // transparent - if( dp>=lp ) { - break; - } - pp=dp-1+*sp++; // non-transparent - while( dp<pp ) { - *dp++=((VMemType32*)sprite->Pixels)[*sp++]; - *dp++=((VMemType32*)sprite->Pixels)[*sp++]; - } - if( dp<=pp ) { - *dp++=((VMemType32*)sprite->Pixels)[*sp++]; - } - } while( dp<lp ); - IfDebug( - if( dp!=lp ) - printf(__FUNCTION__": ERROR\n"); - ) - dp+=da; - } -} - -/* -** Draw rle compressed sprite with clipping. -*/ -global void DrawRleSpriteClipped32(RleSprite* sprite,unsigned frame,int x,int y) -{ - int ox; - int oy; - int w; - int h; - const unsigned char* sp; - unsigned sw; - VMemType32* dp; - VMemType32* lp; - VMemType32* ep; - VMemType32* pp; - unsigned da; - - ox=oy=0; - sw=w=sprite->Width; - h=sprite->Height; - - if( x<ClipX1 ) { // reduce to visible range - ox=ClipX1-x; - w-=ox; - x=ClipX1; - } - if( x+w>ClipX2 ) { - w=ClipX2-x; - } - - if( y<ClipY1 ) { - oy=ClipY1-y; - h-=oy; - y=ClipY1; - } - if( y+h>ClipY2 ) { - h=ClipY2-y; - } - - if( w<=0 || h<=0 ) { // nothing to draw - return; - } - - // - // Draw the clipped sprite - // - sp=sprite->Frames[frame]; - - // - // Skip top lines - // - while( oy-- ) { - da=0; - do { - da+=*sp++; // transparent - if( da>=sw ) { - break; - } - da+=*sp; // non-transparent - sp+=*sp+1; - } while( da<sw ); - } - - da=VideoWidth-sw; - dp=VideoMemory32+x+y*VideoWidth; - ep=dp+VideoWidth*h; - - if( w==sw ) { // Unclipped horizontal - - while( dp<ep ) { // all lines - lp=dp+sw; - do { // 1 line - dp+=*sp++; // transparent - if( dp>=lp ) { - break; - } - pp=dp-1+*sp++; // non-transparent - while( dp<pp ) { - *dp++=((VMemType32*)sprite->Pixels)[*sp++]; - *dp++=((VMemType32*)sprite->Pixels)[*sp++]; - } - if( dp<=pp ) { - *dp++=((VMemType32*)sprite->Pixels)[*sp++]; - } - } while( dp<lp ); - IfDebug( - if( dp!=lp ) - printf(__FUNCTION__": ERROR\n"); - ) - dp+=da; - } - - } else { // Clip horizontal - //printf("CLIPPING ox %d w %d\n",ox,w); - - da+=ox; - while( dp<ep ) { // all lines - lp=dp+w; - // - // Clip left - // - pp=dp-ox; - for( ;; ) { - pp+=*sp++; // transparent - //printf("T%d-",sp[-1]); - if( pp>=dp ) { - dp=pp; - //printf("C"); - goto middle_trans; - } - pp+=*sp; // non-transparent - //printf("P%d-",sp[0]); - if( pp>=dp ) { - sp+=*sp-(pp-dp)+1; - //printf("C"); - goto middle_pixel; - } - sp+=*sp+1; - } - - // - // Draw middle - // - for( ;; ) { - dp+=*sp++; // transparent - //printf("T%d-",sp[-1]); -middle_trans: - if( dp>=lp ) { - lp+=sw-w-ox; - //printf("C"); - goto right_trans; - } - pp=dp+*sp++; // non-transparent - //printf("P%d-",sp[-1]); -middle_pixel: - //printf("%p, %p, %p\n",dp,pp,lp); - if( pp<lp ) { - while( dp<pp ) { - *dp++=((VMemType32*)sprite->Pixels)[*sp++]; - } - continue; - } - while( dp<lp ) { - *dp++=((VMemType32*)sprite->Pixels)[*sp++]; - } - sp+=pp-dp; - dp=pp; - //printf("C"); - break; - } - - // - // Clip right - // - lp+=sw-w-ox; - while( dp<lp ) { - dp+=*sp++; // transparent -right_trans: - if( dp>=lp ) { - break; - } - dp+=*sp; // non-transparent - sp+=*sp+1; - } - //printf("\n"); - IfDebug( - if( dp!=lp ) - printf(__FUNCTION__": ERROR\n"); - ) - dp+=da; - } - } -} - -/* -** Draw rle compressed sprite, flipped in X. -*/ -global void DrawRleSpriteX32(RleSprite* sprite,unsigned frame,int x,int y) -{ - const unsigned char* sp; - unsigned w; - VMemType32* dp; - VMemType32* lp; - VMemType32* ep; - VMemType32* pp; - unsigned da; - - sp=sprite->Frames[frame]; - w=sprite->Width; - dp=VideoMemory32+x+y*VideoWidth+w; - da=VideoWidth+w; - ep=dp+VideoWidth*sprite->Height; - - while( dp<ep ) { // all lines - lp=dp-w; - do { // 1 line - dp-=*sp++; // transparent - if( dp<=lp ) { - break; - } - pp=dp+1-*sp++; // non-transparent - while( dp>pp ) { - *dp--=((VMemType32*)sprite->Pixels)[*sp++]; - *dp--=((VMemType32*)sprite->Pixels)[*sp++]; - } - if( dp>=pp ) { - *dp--=((VMemType32*)sprite->Pixels)[*sp++]; - } - } while( dp>lp ); - IfDebug( - if( dp!=lp ) - printf(__FUNCTION__": ERROR\n"); - ) - dp+=da; - } -} - -/* -** Draw rle compressed sprite with clipping, flipped in X. -*/ -global void DrawRleSpriteClippedX32(RleSprite* sprite,unsigned frame,int x,int y) -{ - int ox; - int oy; - int w; - int h; - const unsigned char* sp; - unsigned sw; - VMemType32* dp; - VMemType32* lp; - VMemType32* ep; - VMemType32* pp; - unsigned da; - - ox=oy=0; - sw=w=sprite->Width; - h=sprite->Height; - - if( x<ClipX1 ) { // reduce to visible range - ox=ClipX1-x; - w-=ox; - x=ClipX1; - } - if( x+w>ClipX2 ) { - w=ClipX2-x; - } - - if( y<ClipY1 ) { - oy=ClipY1-y; - h-=oy; - y=ClipY1; - } - if( y+h>ClipY2 ) { - h=ClipY2-y; - } - - if( w<=0 || h<=0 ) { // nothing to draw - return; - } - - // - // Draw the clipped sprite - // - sp=sprite->Frames[frame]; - - // - // Skip top lines - // - while( oy-- ) { - da=0; - do { - da+=*sp++; // transparent - if( da>=sw ) { - break; - } - da+=*sp; // non-transparent - sp+=*sp+1; - } while( da<sw ); - } - - da=VideoWidth+sw; - dp=VideoMemory32+x+y*VideoWidth+w; - ep=dp+VideoWidth*h; - - if( w==sw ) { // Unclipped horizontal - - while( dp<ep ) { // all lines - lp=dp-w; - do { // 1 line - dp-=*sp++; // transparent - if( dp<=lp ) { - break; - } - pp=dp+1-*sp++; // non-transparent - while( dp>pp ) { - *dp--=((VMemType32*)sprite->Pixels)[*sp++]; - *dp--=((VMemType32*)sprite->Pixels)[*sp++]; - } - if( dp>=pp ) { - *dp--=((VMemType32*)sprite->Pixels)[*sp++]; - } - } while( dp>lp ); - IfDebug( - if( dp!=lp ) - printf(__FUNCTION__": ERROR\n"); - ) - dp+=da; - } - - } else { // Clip horizontal - //printf("CLIPPING %d %d\n",ox,w); - - da-=sw-w-ox; - while( dp<ep ) { // all lines - lp=dp-w; - // - // Clip right side - // - pp=dp+sw-w-ox; - for( ;; ) { - pp-=*sp++; // transparent - //printf("T%d ",sp[-1]); - if( pp<=dp ) { - dp=pp; - goto middle_trans; - } - pp-=*sp; // non-transparent - //printf("P%d ",sp[0]); - if( pp<=dp ) { - sp+=*sp-(dp-pp)+1; - goto middle_pixel; - } - sp+=*sp+1; - } - - // - // Draw middle - // - for( ;; ) { - dp-=*sp++; // transparent - //printf("T%d ",sp[-1]); -middle_trans: - if( dp<=lp ) { - //printf("CLIP TRANS\n"); - lp-=ox; - goto right_trans; - } - pp=dp-*sp++; // non-transparent - //printf("P%d ",sp[-1]); -middle_pixel: - if( pp>lp ) { - while( dp>pp ) { - *dp--=((VMemType32*)sprite->Pixels)[*sp++]; - } - continue; - } - //printf("%d ",sp[-1]); - while( dp>lp ) { - *dp--=((VMemType32*)sprite->Pixels)[*sp++]; - } - //printf("%d: ",dp-pp); - sp+=dp-pp; - //printf("CLIP PIXEL %d,%d,%d\n",*sp,sp[-1],sp[1]); - dp=pp; - break; - } - - // - // Clip left side - // - lp-=ox; - while( dp>lp ) { - dp-=*sp++; // transparent -right_trans: - if( dp<=lp ) { - break; - } - dp-=*sp; // non-transparent - sp+=*sp+1; - } - IfDebug( - if( dp!=lp ) - printf(__FUNCTION__": ERROR\n"); - ) - dp+=da; - } - } -} - -global void DrawRleSprite(RleSprite* sprite,unsigned frame,int x,int y) -{ - // FIXME: function pointer and move to new code structure - switch( VideoDepth ) { - case 8: - DrawRleSprite8(sprite,frame,x,y); - break; - case 15: - case 16: - DrawRleSprite16(sprite,frame,x,y); - break; - case 24: - case 32: - DrawRleSprite32(sprite,frame,x,y); - break; - } -} - -global void DrawRleSpriteClipped(RleSprite* sprite,unsigned frame,int x,int y) -{ - // FIXME: function pointer and move to new code structure - switch( VideoDepth ) { - case 8: - DrawRleSpriteClipped8(sprite,frame,x,y); - break; - case 15: - case 16: - DrawRleSpriteClipped16(sprite,frame,x,y); - break; - case 24: - case 32: - DrawRleSpriteClipped32(sprite,frame,x,y); - break; - } -} - -global void DrawRleSpriteX(RleSprite* sprite,unsigned frame,int x,int y) -{ - // FIXME: function pointer and move to new code structure - switch( VideoDepth ) { - case 8: - DrawRleSpriteX8(sprite,frame,x,y); - break; - case 15: - case 16: - DrawRleSpriteX16(sprite,frame,x,y); - break; - case 24: - case 32: - DrawRleSpriteX32(sprite,frame,x,y); - break; - } -} - -global void DrawRleSpriteClippedX(RleSprite* sprite,unsigned frame,int x,int y) -{ - // FIXME: function pointer and move to new code structure - switch( VideoDepth ) { - case 8: - DrawRleSpriteClippedX8(sprite,frame,x,y); - break; - case 15: - case 16: - DrawRleSpriteClippedX16(sprite,frame,x,y); - break; - case 24: - case 32: - DrawRleSpriteClippedX32(sprite,frame,x,y); - break; - } -} - -/* -** Load rle sprite from file. -*/ -global RleSprite* LoadRleSprite(const char* name,unsigned width,unsigned height) -{ - RleSprite* sprite; - Graphic* graphic; - unsigned char* data; - unsigned char* sp; - unsigned char* dp; - unsigned char* cp; - int fl; - int n; - int counter; - int i; - int h; - int w; - - graphic=LoadGraphic(name); - if( !width ) { // FIXME: this is hack for cursors! - width=graphic->Width; - } - if( !height ) { - height=graphic->Height; - } - - n=(graphic->Width/width)*(graphic->Height/height); - DebugLevel3(__FUNCTION__": %dx%d in %dx%d = %d frames.\n" - ,width,height - ,graphic->Width,graphic->Height,n); - - // FIXME: new internal compressed sprite format! - sprite=malloc(sizeof(RleSprite)+n*sizeof(unsigned char*)+(graphic->Width*graphic->Height*2)); - // FIXME: ARI: * 2 == very passive! - data=(unsigned char *)sprite; - dp=(unsigned char *)&sprite->Frames[n]; - - // - // Compress all frames of the sprite. - // - fl=graphic->Width/width; - for( i=0; i<n; ++i ) { - sprite->Frames[i]=dp; - for( h=0; h<height; ++h ) { - sp=graphic->Frames+(i%fl)*width+((i/fl)*height+h)*graphic->Width; - - for( counter=w=0; w<width; ++w ) { - if( *sp==255 ) { // transparent - ++sp; - if( ++counter==256 ) { - *dp++=255; - *dp++=0; - counter=1; - } - continue; - } - *dp++=counter; - - cp=dp++; - counter=0; -#if 1 - for( ; w<width; ++w ) { // non-transparent - *dp++=*sp++; - if( ++counter==255 ) { - *cp=255; - *dp++=0; - cp=dp++; - counter=0; - } - if( w+1!=width && *sp==255 ) { // transparent // ARI: FIXME - wrong position - break; - } - } -#else - for( ; w<width && *sp!=255 ; ++w ) { // non-transparent - *dp++=*sp++; - if( ++counter==256 ) { - *cp=255; - *dp++=0; - cp=dp++; - counter=1; - } - } -#endif - *cp=counter; - counter=0; - } - if( counter ) { - *dp++=counter; - } - } - } - - DebugLevel3("\t%d => %d RLE compressed\n" - ,graphic->Width*graphic->Height,dp-data); - - i=sizeof(*sprite)+n*sizeof(unsigned char*)+dp-data; - sprite=realloc(sprite,i); - if( (unsigned char*)sprite!=data ) { // shrink only - happens rarely - for( h=0; h<n; ++h ) { // convert address - sprite->Frames[h]=sprite->Frames[h]-data+(unsigned char*)sprite; - } - } - - IfDebug(CompressedGraphicMemory+=i; - sprite->ByteSize=i; ) - - sprite->Width=width; - sprite->Height=height; - - sprite->Pixels = graphic->Pixels; - /*switch( VideoDepth ){ - case 8: - sprite->Pixels=(GraphicData*)Pixels8; - break; - case 15: - case 16: - sprite->Pixels=(GraphicData*)Pixels16; - break; - case 24: - case 32: - sprite->Pixels=(GraphicData*)Pixels32; - break; - } */ - //sprite->Pixels=NULL; // FIXME: future extensions - sprite->NumFrames=n; - - VideoFree(graphic); - - return sprite; -} - -/* -** Free rle sprite. -*/ -global void FreeRleSprite(RleSprite* sprite) -{ - IfDebug (CompressedGraphicMemory-=sprite->ByteSize; ) - - free(sprite); -} - - /** -** Load a RGB palette. +** Pop current clipping. +*/ +global void PopClipping(void) +{ + Clip* clip; + + clip=Clips; + if( clip ) { + Clips=clip->Next; + ClipX1=clip->X1; + ClipY1=clip->Y1; + ClipX2=clip->X2; + ClipY2=clip->Y2; + free(clip); + } else { + ClipX1=0; + ClipY1=0; + ClipX2=VideoWidth; + ClipY2=VideoHeight; + } +} + +/** +** Load a picture and display it on the screen (full screen), +** changing the colormap and so on.. ** -** FIXME: Should or shouldn't this be removed??? +** @param name Name of the picture (file) to display. +*/ +global void DisplayPicture(const char *name) +{ + Graphic* title; + + title=LoadGraphic(name); + // FIXME: remove the casts :{ + VideoSetPalette((VMemType*)title->Pixels); + +#ifdef USE_SDL + // FIXME: should be moved to system/hardware dependend part + { extern SDL_Surface *Screen; /// internal screen + SDL_LockSurface(Screen); + + VideoMemory=Screen->pixels; +#endif + + // FIXME: bigger window ? + VideoDrawSubClip(title,0,0 + ,title->Width,title->Height + ,(VideoWidth-title->Width)/2,(VideoHeight-title->Height)/2); + +#ifdef USE_SDL + // FIXME: should be moved to system/hardware dependend part + SDL_UnlockSurface(Screen); } +#endif + VideoFree(title); + // FIXME: (ARI:) New Palette got stuck in memory? +} + +/** +** Load palette from resource. Just loads palette, to set it use +** VideoCreatePalette, which sets system palette. +** +** @param pal buffer to store palette (256-entries long) +** @param name resource file name +** +** @see VideoCreatePalette */ global void LoadRGB(Palette *pal, const char *name) { @@ -1604,7 +262,7 @@ global void LoadRGB(Palette *pal, const char *name) int i; if((fp=fopen(name,"rb")) == NULL) { - printf("Can't load palette %s\n", name); + fprintf(stderr,"Can't load palette %s\n",name); exit(-1); } @@ -1617,44 +275,253 @@ global void LoadRGB(Palette *pal, const char *name) fclose(fp); } +// FIXME: this isn't 100% correct +// Color cycling info - forest: +// 3 flash red/green (attacked building on minimap) +// 38-47 cycle (water) +// 48-56 cycle (water-coast boundary) +// 202 pulsates red (Circle of Power) +// 240-244 cycle (water around ships, Runestone, Dark Portal) +// Color cycling info - swamp: +// 3 flash red/green (attacked building on minimap) +// 4 pulsates red (Circle of Power) +// 5-9 cycle (Runestone, Dark Portal) +// 38-47 cycle (water) +// 88-95 cycle (waterholes in coast and ground) +// 240-244 cycle (water around ships) +// Color cycling info - wasteland: +// 3 flash red/green (attacked building on minimap) +// 38-47 cycle (water) +// 64-70 cycle (coast) +// 202 pulsates red (Circle of Power) +// 240-244 cycle (water around ships, Runestone, Dark Portal) +// Color cycling info - winter: +// 3 flash red/green (attacked building on minimap) +// 40-47 cycle (water) +// 48-54 cycle (half-sunken ice-floe) +// 202 pulsates red (Circle of Power) +// 205-207 cycle (lights on christmas tree) +// 240-244 cycle (water around ships, Runestone, Dark Portal) + /** -** Set palette -> Video +** Color cycle for 8 bpp video mode. +** +** FIXME: not correct cycles only palette of tileset. +** FIXME: Also icons and some units use color cycling. +** FIXME: must be configured by the tileset or global. */ -global void VideoSetPalette(const GraphicData *palette) +global void ColorCycle8(void) { - // -> Video - switch( VideoDepth ) { - case 8: - Pixels8 =(VMemType8 *)palette; - break; - case 15: - case 16: - Pixels16=(VMemType16 *)palette; - break; - case 24: - // FIXME: real 24bpp mode - case 32: - Pixels32=(VMemType32 *)palette; - break; - default: - DebugLevel0(__FUNCTION__": Unknown depth\n"); - break; + int i; + int x; + VMemType8* pixels; + + // + // Color cycle tileset palette + // + pixels=TheMap.TileData->Pixels; + x = pixels[38]; + for(i = 38; i < 47; ++i){ + pixels[i] = pixels[i+1]; } + pixels[47] = x; + + x=Pixels8[38]; + for( i=38; i<47; ++i ) { // tileset color cycle + Pixels8[i]=Pixels8[i+1]; + } + Pixels8[47]=x; + + x=Pixels8[240]; + for( i=240; i<244; ++i ) { // units/icons color cycle + Pixels8[i]=Pixels8[i+1]; + } + Pixels8[244]=x; + + MapColorCycle(); // FIXME: could be little more informativer + MustRedraw|=RedrawMap|RedrawInfoPanel; +} + +/** +** Color cycle for 16 bpp video mode. +** +** FIXME: not correct cycles only palette of tileset. +** FIXME: Also icons and some units use color cycling. +** FIXME: must be configured by the tileset or global. +*/ +global void ColorCycle16(void) +{ + int i; + int x; + VMemType16* pixels; + + // + // Color cycle tileset palette + // + pixels=TheMap.TileData->Pixels; + x = pixels[38]; + for(i = 38; i < 47; ++i){ + pixels[i] = pixels[i+1]; + } + pixels[47] = x; + + x=Pixels16[38]; + for( i=38; i<47; ++i ) { // tileset color cycle + Pixels16[i]=Pixels16[i+1]; + } + Pixels16[47]=x; + + x=Pixels16[240]; + for( i=240; i<244; ++i ) { // units/icons color cycle + Pixels16[i]=Pixels16[i+1]; + } + Pixels16[244]=x; + + MapColorCycle(); // FIXME: could be little more informativer + MustRedraw|=RedrawMap|RedrawInfoPanel; +} + +/** +** Color cycle for 24 bpp video mode. +** +** FIXME: not correct cycles only palette of tileset. +** FIXME: Also icons and some units use color cycling. +** FIXME: must be configured by the tileset or global. +*/ +global void ColorCycle24(void) +{ + int i; + VMemType24 x; + VMemType24* pixels; + + // + // Color cycle tileset palette + // + pixels=TheMap.TileData->Pixels; + x = pixels[38]; + for(i = 38; i < 47; ++i){ + pixels[i] = pixels[i+1]; + } + pixels[47] = x; + + x=Pixels24[38]; + for( i=38; i<47; ++i ) { // tileset color cycle + Pixels24[i]=Pixels24[i+1]; + } + Pixels24[47]=x; + + x=Pixels24[240]; + for( i=240; i<244; ++i ) { // units/icons color cycle + Pixels24[i]=Pixels24[i+1]; + } + Pixels24[244]=x; + + MapColorCycle(); // FIXME: could be little more informativer + MustRedraw|=RedrawMap|RedrawInfoPanel; +} + +/** +** Color cycle for 32 bpp video mode. +** +** FIXME: not correct cycles only palette of tileset. +** FIXME: Also icons and some units use color cycling. +** FIXME: must be configured by the tileset or global. +*/ +global void ColorCycle32(void) +{ + int i; + int x; + VMemType32* pixels; + + // + // Color cycle tileset palette + // + pixels=TheMap.TileData->Pixels; + x = pixels[38]; + for(i = 38; i < 47; ++i){ + pixels[i] = pixels[i+1]; + } + pixels[47] = x; + + x=Pixels32[38]; + for( i=38; i<47; ++i ) { // tileset color cycle + Pixels32[i]=Pixels32[i+1]; + } + Pixels32[47]=x; + + x=Pixels32[240]; + for( i=240; i<244; ++i ) { // units/icons color cycle + Pixels32[i]=Pixels32[i+1]; + } + Pixels32[244]=x; + + MapColorCycle(); // FIXME: could be little more informativer + MustRedraw|=RedrawMap|RedrawInfoPanel; +} + +/** +** Initializes system palette. Also calls SetPlayersPalette to set +** palette for all players. +** +** @param palette VMemType structure, as created by VideoCreateNewPalette +** @see SetPlayersPalette +*/ +global void VideoSetPalette(const VMemType* palette) +{ + if( Pixels ) { + free(Pixels); + } + Pixels=(VMemType*)palette; SetPlayersPalette(); } /** -** Create palette. +** Set the system hardware palette from an independend Palette struct. +** +** @param palette System independ palette structure. */ global void VideoCreatePalette(const Palette* palette) { - GraphicData * temp; + VMemType* temp; temp = VideoCreateNewPalette(palette); VideoSetPalette(temp); } -#endif // } !NEW_VIDEO +/** +** Video initialize. +*/ +global void InitVideo(void) +{ + if( UseSdl ) { + InitVideoSdl(); + } else if( UseX11 ) { + InitVideoX11(); + } else if( UseSVGALib ) { + InitVideoSVGA(); + } else if( UseWin32 ) { + InitVideoWin32(); + } else { + IfDebug( abort(); ); + } + + // + // Init video sub modules + // + InitGraphic(); + InitLineDraw(); + InitSprite(); + InitCursor(); + switch( VideoDepth ) { + case 8: ColorCycle=ColorCycle8 ; break; + case 15: + case 16: ColorCycle=ColorCycle16; break; + case 24: ColorCycle=ColorCycle24; break; + case 32: ColorCycle=ColorCycle32; break; + } + + DebugLevel3(__FUNCTION__": %d %d\n",MapWidth,MapHeight); +} //@}