154 lines
		
	
	
		
			5.4 KiB
		
	
	
	
		
			C
		
	
	
			
		
		
	
	
			154 lines
		
	
	
		
			5.4 KiB
		
	
	
	
		
			C
		
	
	
| #ifndef SDL_H
 | |
| #define SDL_H
 | |
| #include "../player.h" // for races/class totals
 | |
| 
 | |
| #define EVENT_TICK 1
 | |
| #define EVENT_NET 2
 | |
| #define EVENT_NET_ACCEPT 3
 | |
| #define EVENT_NET_RECV 4
 | |
| #define EVENT_NET_LOST 5
 | |
| #define EVENT_NET_ERROR 6
 | |
| #define EVENT_NET_CLIENT_RECV 7
 | |
| #define EVENT_NET_CLIENT_LOST 8
 | |
| #define EVENT_NET_CLIENT_ERROR 9
 | |
| 
 | |
| struct Font {
 | |
|   int width;
 | |
|   int height;
 | |
|   int s_width;
 | |
|   int s_height;
 | |
|   float scale_x;
 | |
|   float scale_y;
 | |
|   SDL_Surface *spritesheet;
 | |
|   SDL_Surface *scaled_spritesheet;
 | |
| };
 | |
| struct Font font_mini;
 | |
| struct Font font_standard;
 | |
| 
 | |
| struct Spritesheet {
 | |
|   int width;
 | |
|   int height;
 | |
|   int s_width;
 | |
|   int s_height;
 | |
|   int columns;
 | |
|   float scale_x;
 | |
|   float scale_y;
 | |
|   SDL_Surface *spritesheet;
 | |
|   SDL_Surface *s_spritesheet;
 | |
| };
 | |
| struct Spritesheet player_sprites;
 | |
| struct Spritesheet item_sprites;
 | |
| struct Spritesheet equip_sprites;
 | |
| struct Spritesheet shadow_sprites;
 | |
| struct Spritesheet npc_sprites;
 | |
| struct Spritesheet door_sprites;
 | |
| struct Spritesheet floor_sprites;
 | |
| struct Spritesheet wall_sprites;
 | |
| 
 | |
| struct Spritesheet ui_sprites;
 | |
| 
 | |
| SDL_Surface* screen;
 | |
| SDL_Surface* font_spritesheet;
 | |
| SDL_Surface* ui_spritesheet;
 | |
| SDL_Surface* camera_surface;
 | |
| SDL_Event event;
 | |
| 
 | |
| Uint32 delay; // our delay in ms
 | |
| SDL_TimerID timer_id; // the timer id from SDL_AddTimer
 | |
|   
 | |
| int g_video_width;
 | |
| int g_video_height;
 | |
| int g_video_mode;
 | |
| int g_video_fullscreen; // 0=windowed, 1=fullscreen
 | |
| 
 | |
| float g_tile_scale_x;
 | |
| float g_tile_scale_y;
 | |
| float g_tile_width;
 | |
| float g_tile_height;
 | |
| 
 | |
| /* helper stuff */
 | |
| Uint32 combinepixels(Uint32 pixel_1, Uint32 pixel_2);
 | |
| 
 | |
| /* --- tile stuff --- */
 | |
| void consoleScaleTiles(const char *input_string);
 | |
| 
 | |
| void interfaceSetScale(float scale_x, float scale_y);
 | |
| void loadSpritesheetFromMemory(struct Spritesheet *spritesheet, unsigned char *memory, unsigned int length, int width, int height, int columns);
 | |
| void freeSpritesheet(struct Spritesheet *spritesheet);
 | |
| void setSpritesheetScale(struct Spritesheet *spritesheet, float scale_x, float scale_y);
 | |
| // TODO: drawSprite/drawScaledSprite should probably be the same function that uses a flag to use either the scaled or non-scaled surface
 | |
| void drawSprite(struct Spritesheet *spritesheet, int id, SDL_Surface *target_surface, int start_x, int start_y);
 | |
| void drawScaledSprite(struct Spritesheet *spritesheet, int id, SDL_Surface *target_surface, int start_x, int start_y);
 | |
| void drawScaledTransparentSprite(struct Spritesheet *spritesheet, int id, double opacity, SDL_Surface *target_surface, int start_x, int start_y);
 | |
| void drawScaledSpriteOutline(struct Spritesheet *spritesheet, int id, SDL_Surface *target_surface, int start_x, int start_y);
 | |
| 
 | |
| /* --- core drawing stuff --- */
 | |
| void interfaceDrawString(SDL_Surface *to_surface, const char *string, int start_x, int start_y);
 | |
| void interfaceDrawChar(SDL_Surface *to_surface, char ch, int start_x, int start_y);
 | |
| void interfaceDrawStringF(struct Font *font, SDL_Surface *to_surface, const char *string, int start_x, int start_y);
 | |
| void interfaceDrawCharF(struct Font *font, SDL_Surface *to_surface, char ch, int start_x, int start_y);
 | |
| 
 | |
| SDL_Surface *interfaceScaleSurface(SDL_Surface *surface, float scale_x, float scale_y);
 | |
| SDL_Surface *interfaceSmoothScaleSurface(SDL_Surface *surface, float scale_x, float scale_y);
 | |
| 
 | |
| void SDL_CopySurface(SDL_Surface *from_surface, SDL_Rect *from_rect, SDL_Surface *to_surface, SDL_Rect *to_rect);
 | |
| void SDL_SetOpacity(SDL_Surface *surface, double percent);
 | |
| SDL_Surface *SDL_ScaleSurface(SDL_Surface *surface, float scale_x, float scale_y);
 | |
| 
 | |
| /* --- ui related stuff --- */
 | |
| float g_ui_scale_x;
 | |
| float g_ui_scale_y;
 | |
| #define UI_HOTBAR_ITEM_HEIGHT 32
 | |
| #define UI_HOTBAR_ITEM_WIDTH 32
 | |
| 
 | |
| SDL_Surface *ui_messages_surface;
 | |
| SDL_Rect *ui_messages_target_rect;
 | |
| 
 | |
| float g_hotbar_scale_x;
 | |
| float g_hotbar_scale_y;
 | |
| SDL_Surface *ui_hotbar_surface;
 | |
| SDL_Rect *ui_hotbar_target_rect;
 | |
| 
 | |
| int uiInit();
 | |
| void uiDraw();
 | |
| void uiSetScale(float scale_x, float scale_y);
 | |
| 
 | |
| /* --- --- */
 | |
| 
 | |
| void interfaceDrawInventory();
 | |
| 
 | |
| /* --- video related stuff --- */
 | |
| /***
 | |
|   This function takes an input string in the following format to set g_video_width, g_video_height, and g_video_fullscreen appropriately:
 | |
|     WIDTHxHEIGHT 0|1
 | |
|   TODO: rename to consoleVideoSetSize or something similar to specify its nature as a console command
 | |
| ***/
 | |
| void interfaceVideoSetSize(const char *input_string);
 | |
| /*** interfaceVideoSet
 | |
|   This function recreates the screen with the values from g_video_width, g_video_height, and g_video_fullscreen then frees and recreates the camera_surface.
 | |
| ***/
 | |
| int interfaceVideoSet();
 | |
| 
 | |
| /* --- font-related stuff --- */
 | |
| /*** loadFontFromMemory
 | |
|   This function populates the passed Font structure by taking the passed memory and making an SDL_Surface from it and setting the width and height accordingly (as well as scale_x and scale_y.
 | |
| ***/
 | |
| void loadFontFromMemory(struct Font *font, unsigned char *memory, unsigned int length, int width, int height);
 | |
| /*** freeFont
 | |
|   This function should be called after populating a Font structure via loadFontFromMemory - it simply frees the scaled_spritesheet and spritesheet of the struct.
 | |
| ***/
 | |
| void freeFont(struct Font *font);
 | |
| /*** setFontScale
 | |
|   This function sets the scale_x and scale_y properties of the passed struct to the passed values and creates a new SDL_Surface pointed to be scaled_spritesheet at the appropriate scale - this is acquired by using interfaceScaleSurface on the struct's spritesheet.
 | |
| ***/
 | |
| void setFontScale(struct Font *font, float scale_x, float scale_y);
 | |
| 
 | |
| 
 | |
| 
 | |
| static int networkThread(void *nada);
 | |
| SDL_Thread *network_thread;
 | |
| 
 | |
| Uint32 pushTickEvent(Uint32 interval, void *param);
 | |
| 
 | |
| #endif
 |