From 24eb730c72d0a0115504cbe32f81b256bcf88e86 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Tue, 7 Jul 2015 17:35:58 +1000 Subject: [PATCH 01/39] Switched to the #pragma once system --- client/base_scene.hpp | 5 +---- client/channels.hpp | 5 +---- client/client_application.hpp | 5 +---- client/client_utilities/terminal_error.hpp | 5 +---- client/entities/base_character.hpp | 5 +---- client/entities/base_monster.hpp | 5 +---- client/entities/entity.hpp | 5 +---- client/entities/local_character.hpp | 5 +---- client/gameplay_scenes/world.hpp | 5 +---- client/menu_scenes/disconnected_screen.hpp | 5 +---- client/menu_scenes/lobby_menu.hpp | 5 +---- client/menu_scenes/main_menu.hpp | 5 +---- client/menu_scenes/options_menu.hpp | 5 +---- client/menu_scenes/splash_screen.hpp | 5 +---- client/scene_list.hpp | 5 +---- common/debugging/timer.hpp | 5 +---- common/gameplay/character_defines.hpp | 5 +---- common/graphics/image.hpp | 5 +---- common/graphics/sprite_sheet.hpp | 5 +---- common/graphics/tile_sheet.hpp | 5 +---- common/map/region.hpp | 5 +---- common/map/region_api.hpp | 5 +---- common/map/region_pager_api.hpp | 5 +---- common/map/region_pager_base.hpp | 5 +---- common/map/region_pager_lua.hpp | 5 +---- common/network/packet_types/character_packet.hpp | 5 +---- common/network/packet_types/client_packet.hpp | 5 +---- common/network/packet_types/monster_packet.hpp | 5 +---- common/network/packet_types/region_packet.hpp | 5 +---- common/network/packet_types/serial_packet_base.hpp | 5 +---- common/network/packet_types/server_packet.hpp | 5 +---- common/network/packet_types/text_packet.hpp | 5 +---- common/network/serial_packet.hpp | 5 +---- common/network/serial_packet_type.hpp | 5 +---- common/network/serial_utility.hpp | 5 +---- common/network/udp_network_utility.hpp | 5 +---- common/ui/button.hpp | 5 +---- common/ui/menu_bar.hpp | 5 +---- common/ui/raster_font.hpp | 5 +---- common/utilities/bounding_box.hpp | 5 +---- common/utilities/config_utility.hpp | 5 +---- common/utilities/frame_rate.hpp | 5 +---- common/utilities/ip_operators.hpp | 5 +---- common/utilities/singleton.hpp | 5 +---- common/utilities/vector2.hpp | 5 +---- server/accounts/account_data.hpp | 5 +---- server/accounts/account_manager.hpp | 5 +---- server/characters/character_api.hpp | 5 +---- server/characters/character_data.hpp | 5 +---- server/characters/character_manager.hpp | 5 +---- server/characters/character_manager_api.hpp | 5 +---- server/clients/client_data.hpp | 5 +---- server/clients/client_manager.hpp | 5 +---- server/entities/entity.hpp | 5 +---- server/entities/entity_api.hpp | 5 +---- server/monsters/monster_api.hpp | 5 +---- server/monsters/monster_data.hpp | 5 +---- server/monsters/monster_manager.hpp | 5 +---- server/monsters/monster_manager_api.hpp | 5 +---- server/rooms/room_api.hpp | 5 +---- server/rooms/room_data.hpp | 5 +---- server/rooms/room_manager.hpp | 5 +---- server/rooms/room_manager_api.hpp | 6 +----- server/server_application.hpp | 5 +---- server/server_utilities/network_api.hpp | 5 +---- server/server_utilities/server_utilities.hpp | 5 +---- server/server_utilities/sql_tools.hpp | 5 +---- server/triggers/trigger_api.hpp | 5 +---- server/triggers/trigger_data.hpp | 5 +---- server/triggers/trigger_manager.hpp | 5 +---- server/triggers/trigger_manager_api.hpp | 5 +---- 71 files changed, 71 insertions(+), 285 deletions(-) diff --git a/client/base_scene.hpp b/client/base_scene.hpp index aae6161..4292e6f 100644 --- a/client/base_scene.hpp +++ b/client/base_scene.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef BASESCENE_HPP_ -#define BASESCENE_HPP_ +#pragma once #include "scene_list.hpp" @@ -70,5 +69,3 @@ private: static SDL_Surface* screen; SceneList nextScene = SceneList::CONTINUE; }; - -#endif diff --git a/client/channels.hpp b/client/channels.hpp index 431b877..362463a 100644 --- a/client/channels.hpp +++ b/client/channels.hpp @@ -19,11 +19,8 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef CHANNELS_HPP_ -#define CHANNELS_HPP_ +#pragma once enum Channels { SERVER = 0 }; - -#endif diff --git a/client/client_application.hpp b/client/client_application.hpp index 6f6fc0b..90da656 100644 --- a/client/client_application.hpp +++ b/client/client_application.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef CLIENTAPPLICATION_HPP_ -#define CLIENTAPPLICATION_HPP_ +#pragma once #include "scene_list.hpp" #include "base_scene.hpp" @@ -54,5 +53,3 @@ private: int clientIndex = -1; int accountIndex = -1; }; - -#endif diff --git a/client/client_utilities/terminal_error.hpp b/client/client_utilities/terminal_error.hpp index 8a7216b..0735247 100644 --- a/client/client_utilities/terminal_error.hpp +++ b/client/client_utilities/terminal_error.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef TERMINALERROR_HPP_ -#define TERMINALERROR_HPP_ +#pragma once #include #include @@ -30,5 +29,3 @@ public: explicit terminal_error(const std::string& str): runtime_error(str) {} explicit terminal_error(const char* cstr): runtime_error(cstr) {} }; - -#endif diff --git a/client/entities/base_character.hpp b/client/entities/base_character.hpp index cd38a6a..6206c4d 100644 --- a/client/entities/base_character.hpp +++ b/client/entities/base_character.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef BASECHARACTER_HPP_ -#define BASECHARACTER_HPP_ +#pragma once //components #include "character_defines.hpp" @@ -51,5 +50,3 @@ protected: std::string handle; std::string avatar; }; - -#endif diff --git a/client/entities/base_monster.hpp b/client/entities/base_monster.hpp index 328008a..0cc2032 100644 --- a/client/entities/base_monster.hpp +++ b/client/entities/base_monster.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef BASEMONSTER_HPP_ -#define BASEMONSTER_HPP_ +#pragma once #include "entity.hpp" @@ -41,5 +40,3 @@ protected: std::string handle; std::string avatar; }; - -#endif \ No newline at end of file diff --git a/client/entities/entity.hpp b/client/entities/entity.hpp index 77b5c1c..7315525 100644 --- a/client/entities/entity.hpp +++ b/client/entities/entity.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef ENTITY_HPP_ -#define ENTITY_HPP_ +#pragma once #include "bounding_box.hpp" #include "sprite_sheet.hpp" @@ -52,5 +51,3 @@ protected: Vector2 motion; BoundingBox bounds; }; - -#endif \ No newline at end of file diff --git a/client/entities/local_character.hpp b/client/entities/local_character.hpp index a462ddc..af7f5fa 100644 --- a/client/entities/local_character.hpp +++ b/client/entities/local_character.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef LOCALCHARACTER_HPP_ -#define LOCALCHARACTER_HPP_ +#pragma once #include "base_character.hpp" #include "bounding_box.hpp" @@ -38,5 +37,3 @@ public: private: //NOTE: NO MEMBERS }; - -#endif \ No newline at end of file diff --git a/client/gameplay_scenes/world.hpp b/client/gameplay_scenes/world.hpp index a2af0a2..ff664ec 100644 --- a/client/gameplay_scenes/world.hpp +++ b/client/gameplay_scenes/world.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef INWORLD_HPP_ -#define INWORLD_HPP_ +#pragma once //maps #include "region_pager_base.hpp" @@ -166,5 +165,3 @@ protected: ConfigUtility& config = ConfigUtility::GetSingleton(); UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton(); }; - -#endif diff --git a/client/menu_scenes/disconnected_screen.hpp b/client/menu_scenes/disconnected_screen.hpp index a735289..d2b9c56 100644 --- a/client/menu_scenes/disconnected_screen.hpp +++ b/client/menu_scenes/disconnected_screen.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef DISCONNECTEDSCREEN_HPP_ -#define DISCONNECTEDSCREEN_HPP_ +#pragma once //graphics #include "image.hpp" @@ -62,5 +61,3 @@ protected: //auto return std::chrono::steady_clock::time_point startTick; }; - -#endif diff --git a/client/menu_scenes/lobby_menu.hpp b/client/menu_scenes/lobby_menu.hpp index 067af8c..875ff94 100644 --- a/client/menu_scenes/lobby_menu.hpp +++ b/client/menu_scenes/lobby_menu.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef LOBBYMENU_HPP_ -#define LOBBYMENU_HPP_ +#pragma once //graphics & ui #include "image.hpp" @@ -101,5 +100,3 @@ protected: BoundingBox listBox; ServerInformation* selection = nullptr; }; - -#endif diff --git a/client/menu_scenes/main_menu.hpp b/client/menu_scenes/main_menu.hpp index d3e7f74..1ca02b3 100644 --- a/client/menu_scenes/main_menu.hpp +++ b/client/menu_scenes/main_menu.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef MAINMENU_HPP_ -#define MAINMENU_HPP_ +#pragma once #include "base_scene.hpp" @@ -55,5 +54,3 @@ protected: Button optionsButton; Button quitButton; }; - -#endif diff --git a/client/menu_scenes/options_menu.hpp b/client/menu_scenes/options_menu.hpp index a828627..a260c09 100644 --- a/client/menu_scenes/options_menu.hpp +++ b/client/menu_scenes/options_menu.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef OPTIONSMENU_HPP_ -#define OPTIONSMENU_HPP_ +#pragma once #include "base_scene.hpp" @@ -54,5 +53,3 @@ protected: RasterFont font; Button backButton; }; - -#endif diff --git a/client/menu_scenes/splash_screen.hpp b/client/menu_scenes/splash_screen.hpp index a8bec1b..9e8de37 100644 --- a/client/menu_scenes/splash_screen.hpp +++ b/client/menu_scenes/splash_screen.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef SPLASHSCREEN_HPP_ -#define SPLASHSCREEN_HPP_ +#pragma once #include "base_scene.hpp" @@ -43,5 +42,3 @@ protected: std::chrono::steady_clock::time_point startTick; Image logo; }; - -#endif diff --git a/client/scene_list.hpp b/client/scene_list.hpp index 2db5145..42990ae 100644 --- a/client/scene_list.hpp +++ b/client/scene_list.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef SCENELIST_HPP_ -#define SCENELIST_HPP_ +#pragma once enum class SceneList { //these are reserved @@ -36,5 +35,3 @@ enum class SceneList { WORLD, DISCONNECTEDSCREEN, }; - -#endif diff --git a/common/debugging/timer.hpp b/common/debugging/timer.hpp index 847f585..d7e97f3 100644 --- a/common/debugging/timer.hpp +++ b/common/debugging/timer.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef TIMER_HPP_ -#define TIMER_HPP_ +#pragma once #include #include @@ -50,5 +49,3 @@ private: }; std::ostream& operator<<(std::ostream& os, Timer& t); - -#endif diff --git a/common/gameplay/character_defines.hpp b/common/gameplay/character_defines.hpp index 7b0d7d6..a975a3e 100644 --- a/common/gameplay/character_defines.hpp +++ b/common/gameplay/character_defines.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef CHARACTERDEFINES_HPP_ -#define CHARACTERDEFINES_HPP_ +#pragma once #include @@ -38,5 +37,3 @@ constexpr int CHARACTER_BOUNDS_HEIGHT = 32; //the character's sprite format constexpr int CHARACTER_CELLS_X = 4; constexpr int CHARACTER_CELLS_Y = 4; - -#endif diff --git a/common/graphics/image.hpp b/common/graphics/image.hpp index 709490d..324ae59 100644 --- a/common/graphics/image.hpp +++ b/common/graphics/image.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef IMAGE_HPP_ -#define IMAGE_HPP_ +#pragma once #include "SDL/SDL.h" #include @@ -69,5 +68,3 @@ protected: SDL_Rect clip = {0, 0, 0, 0}; bool local = false; }; - -#endif diff --git a/common/graphics/sprite_sheet.hpp b/common/graphics/sprite_sheet.hpp index ea28a86..2eb3238 100644 --- a/common/graphics/sprite_sheet.hpp +++ b/common/graphics/sprite_sheet.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef SPRITESHEET_HPP_ -#define SPRITESHEET_HPP_ +#pragma once #include "image.hpp" @@ -62,5 +61,3 @@ private: Uint16 xIndex = 0, yIndex = 0; //current cell being drawn double delay = 0.0, tick = 0.0; }; - -#endif diff --git a/common/graphics/tile_sheet.hpp b/common/graphics/tile_sheet.hpp index 6ad94ea..8ac142f 100644 --- a/common/graphics/tile_sheet.hpp +++ b/common/graphics/tile_sheet.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef TILESHEET_HPP_ -#define TILESHEET_HPP_ +#pragma once #include "region.hpp" @@ -50,5 +49,3 @@ private: Image image; int xCount = 0, yCount = 0; }; - -#endif diff --git a/common/map/region.hpp b/common/map/region.hpp index fd8c461..68511be 100644 --- a/common/map/region.hpp +++ b/common/map/region.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef REGION_HPP_ -#define REGION_HPP_ +#pragma once #include @@ -59,5 +58,3 @@ private: type_t tiles[REGION_WIDTH][REGION_HEIGHT][REGION_DEPTH]; std::bitset solid; }; - -#endif diff --git a/common/map/region_api.hpp b/common/map/region_api.hpp index 4529f6e..e855bcb 100644 --- a/common/map/region_api.hpp +++ b/common/map/region_api.hpp @@ -19,12 +19,9 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef REGIONAPI_HPP_ -#define REGIONAPI_HPP_ +#pragma once #include "lua.hpp" #define TORTUGA_REGION_API "region" LUAMOD_API int openRegionAPI(lua_State* L); - -#endif diff --git a/common/map/region_pager_api.hpp b/common/map/region_pager_api.hpp index ed36740..965b400 100644 --- a/common/map/region_pager_api.hpp +++ b/common/map/region_pager_api.hpp @@ -19,12 +19,9 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef REGIONPAGERAPI_HPP_ -#define REGIONPAGERAPI_HPP_ +#pragma once #include "lua.hpp" #define TORTUGA_REGION_PAGER_API "region_pager" LUAMOD_API int openRegionPagerAPI(lua_State* L); - -#endif diff --git a/common/map/region_pager_base.hpp b/common/map/region_pager_base.hpp index cdafa3f..a53083d 100644 --- a/common/map/region_pager_base.hpp +++ b/common/map/region_pager_base.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef REGIONPAGERBASE_HPP_ -#define REGIONPAGERBASE_HPP_ +#pragma once #include "region.hpp" @@ -57,5 +56,3 @@ public: protected: std::list regionList; }; - -#endif diff --git a/common/map/region_pager_lua.hpp b/common/map/region_pager_lua.hpp index ea4e76b..0b64b0a 100644 --- a/common/map/region_pager_lua.hpp +++ b/common/map/region_pager_lua.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef REGIONPAGERLUA_HPP_ -#define REGIONPAGERLUA_HPP_ +#pragma once #include "region_pager_base.hpp" @@ -65,5 +64,3 @@ protected: int createRef = LUA_NOREF; int unloadRef = LUA_NOREF; }; - -#endif diff --git a/common/network/packet_types/character_packet.hpp b/common/network/packet_types/character_packet.hpp index a791bf9..fb3b0bb 100644 --- a/common/network/packet_types/character_packet.hpp +++ b/common/network/packet_types/character_packet.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef CHARACTERPACKET_HPP_ -#define CHARACTERPACKET_HPP_ +#pragma once #include "serial_packet_base.hpp" @@ -45,5 +44,3 @@ struct CharacterPacket : SerialPacketBase { void serializeCharacter(void* buffer, CharacterPacket* packet); void deserializeCharacter(void* buffer, CharacterPacket* packet); - -#endif \ No newline at end of file diff --git a/common/network/packet_types/client_packet.hpp b/common/network/packet_types/client_packet.hpp index 0195f58..ec5ea5a 100644 --- a/common/network/packet_types/client_packet.hpp +++ b/common/network/packet_types/client_packet.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef CLIENTPACKET_HPP_ -#define CLIENTPACKET_HPP_ +#pragma once #include "serial_packet_base.hpp" @@ -33,5 +32,3 @@ struct ClientPacket : SerialPacketBase { void serializeClient(void* buffer, ClientPacket* packet); void deserializeClient(void* buffer, ClientPacket* packet); - -#endif \ No newline at end of file diff --git a/common/network/packet_types/monster_packet.hpp b/common/network/packet_types/monster_packet.hpp index 1dfae0c..3a4cc37 100644 --- a/common/network/packet_types/monster_packet.hpp +++ b/common/network/packet_types/monster_packet.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef MONSTERPACKET_HPP_ -#define MONSTERPACKET_HPP_ +#pragma once #include "serial_packet_base.hpp" @@ -42,5 +41,3 @@ struct MonsterPacket : SerialPacketBase { void serializeMonster(void* buffer, MonsterPacket* packet); void deserializeMonster(void* buffer, MonsterPacket* packet); - -#endif \ No newline at end of file diff --git a/common/network/packet_types/region_packet.hpp b/common/network/packet_types/region_packet.hpp index 3020262..01588c7 100644 --- a/common/network/packet_types/region_packet.hpp +++ b/common/network/packet_types/region_packet.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef REGIONPACKET_HPP_ -#define REGIONPACKET_HPP_ +#pragma once #include "serial_packet_base.hpp" @@ -44,5 +43,3 @@ struct RegionPacket : SerialPacketBase { void serializeRegion(void* buffer, RegionPacket* packet); void deserializeRegion(void* buffer, RegionPacket* packet); - -#endif \ No newline at end of file diff --git a/common/network/packet_types/serial_packet_base.hpp b/common/network/packet_types/serial_packet_base.hpp index 9fc7e8f..22ff75b 100644 --- a/common/network/packet_types/serial_packet_base.hpp +++ b/common/network/packet_types/serial_packet_base.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef SERIALPACKETBASE_HPP_ -#define SERIALPACKETBASE_HPP_ +#pragma once #include "serial_packet_type.hpp" @@ -35,5 +34,3 @@ struct SerialPacketBase { virtual ~SerialPacketBase() {}; }; - -#endif diff --git a/common/network/packet_types/server_packet.hpp b/common/network/packet_types/server_packet.hpp index 169946e..6c6b1b5 100644 --- a/common/network/packet_types/server_packet.hpp +++ b/common/network/packet_types/server_packet.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef SERVERPACKET_HPP_ -#define SERVERPACKET_HPP_ +#pragma once #include "serial_packet_base.hpp" @@ -33,5 +32,3 @@ struct ServerPacket : SerialPacketBase { void serializeServer(void* buffer, ServerPacket* packet); void deserializeServer(void* buffer, ServerPacket* packet); - -#endif \ No newline at end of file diff --git a/common/network/packet_types/text_packet.hpp b/common/network/packet_types/text_packet.hpp index 9b9ae4b..434ee86 100644 --- a/common/network/packet_types/text_packet.hpp +++ b/common/network/packet_types/text_packet.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef TEXTPACKET_HPP_ -#define TEXTPACKET_HPP_ +#pragma once #include "serial_packet_base.hpp" @@ -36,5 +35,3 @@ struct TextPacket : SerialPacketBase { void serializeText(void* buffer, TextPacket* packet); void deserializeText(void* buffer, TextPacket* packet); - -#endif diff --git a/common/network/serial_packet.hpp b/common/network/serial_packet.hpp index dc6083a..54a0ffd 100644 --- a/common/network/serial_packet.hpp +++ b/common/network/serial_packet.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef SERIALPACKET_HPP_ -#define SERIALPACKET_HPP_ +#pragma once #include "serial_packet_base.hpp" #include "character_packet.hpp" @@ -62,5 +61,3 @@ constexpr int PACKET_BUFFER_SIZE = REGION_METADATA_FOOTPRINT + REGION_TILE_FOOTPRINT + REGION_SOLID_FOOTPRINT; - -#endif diff --git a/common/network/serial_packet_type.hpp b/common/network/serial_packet_type.hpp index 062fa05..349d964 100644 --- a/common/network/serial_packet_type.hpp +++ b/common/network/serial_packet_type.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef SERIALPACKETTYPE_HPP_ -#define SERIALPACKETTYPE_HPP_ +#pragma once /* DOCS: The headers indicate what packet type is used for each message * different messages under the same header will carry different amounts of @@ -183,5 +182,3 @@ enum class SerialPacketType { LAST }; - -#endif \ No newline at end of file diff --git a/common/network/serial_utility.hpp b/common/network/serial_utility.hpp index 0d3e9c0..125379d 100644 --- a/common/network/serial_utility.hpp +++ b/common/network/serial_utility.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef SERIALIZEUTILITY_HPP_ -#define SERIALIZEUTILITY_HPP_ +#pragma once #include "serial_packet_base.hpp" @@ -33,5 +32,3 @@ void deserialCopy(void** buffer, void* data, int size); //primary functions void serializePacket(void* buffer, SerialPacketBase* packet); void deserializePacket(void* buffer, SerialPacketBase* packet); - -#endif diff --git a/common/network/udp_network_utility.hpp b/common/network/udp_network_utility.hpp index a4452ae..d770244 100644 --- a/common/network/udp_network_utility.hpp +++ b/common/network/udp_network_utility.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef UDPNETWORKUTILITY_HPP_ -#define UDPNETWORKUTILITY_HPP_ +#pragma once //common #include "serial_packet_base.hpp" @@ -73,5 +72,3 @@ private: UDPsocket socket = nullptr; UDPpacket* packet = nullptr; }; - -#endif diff --git a/common/ui/button.hpp b/common/ui/button.hpp index b1d6ff1..4b93520 100644 --- a/common/ui/button.hpp +++ b/common/ui/button.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef BUTTON_HPP_ -#define BUTTON_HPP_ +#pragma once #include "image.hpp" #include "raster_font.hpp" @@ -90,5 +89,3 @@ private: State state = State::NORMAL; std::string text; }; - -#endif diff --git a/common/ui/menu_bar.hpp b/common/ui/menu_bar.hpp index ddbb250..351259b 100644 --- a/common/ui/menu_bar.hpp +++ b/common/ui/menu_bar.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef MENUBAR_HPP_ -#define MENUBAR_HPP_ +#pragma once #include "image.hpp" #include "raster_font.hpp" @@ -88,5 +87,3 @@ private: friend class MenuBar; }; - -#endif diff --git a/common/ui/raster_font.hpp b/common/ui/raster_font.hpp index 25fa39a..9000921 100644 --- a/common/ui/raster_font.hpp +++ b/common/ui/raster_font.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef RASTERFONT_HPP_ -#define RASTERFONT_HPP_ +#pragma once #include "image.hpp" @@ -50,5 +49,3 @@ public: private: Image image; }; - -#endif diff --git a/common/utilities/bounding_box.hpp b/common/utilities/bounding_box.hpp index baf9917..eba974d 100644 --- a/common/utilities/bounding_box.hpp +++ b/common/utilities/bounding_box.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef BOUNDINGBOX_HPP_ -#define BOUNDINGBOX_HPP_ +#pragma once #include #include @@ -74,5 +73,3 @@ inline BoundingBox operator+(BoundingBox b, Vector2 v) { inline BoundingBox operator+(Vector2 v, BoundingBox b) { return b + v; } - -#endif diff --git a/common/utilities/config_utility.hpp b/common/utilities/config_utility.hpp index a63ed17..cc4f2ea 100644 --- a/common/utilities/config_utility.hpp +++ b/common/utilities/config_utility.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef CONFIGUTILITY_HPP_ -#define CONFIGUTILITY_HPP_ +#pragma once #include "singleton.hpp" @@ -51,5 +50,3 @@ private: table_t configMap; }; - -#endif diff --git a/common/utilities/frame_rate.hpp b/common/utilities/frame_rate.hpp index e9899ac..3a52c2f 100644 --- a/common/utilities/frame_rate.hpp +++ b/common/utilities/frame_rate.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef FRAMERATE_HPP_ -#define FRAMERATE_HPP_ +#pragma once #include @@ -44,5 +43,3 @@ private: int lastFrameRate = 0; Clock::time_point tick = Clock::now(); }; - -#endif diff --git a/common/utilities/ip_operators.hpp b/common/utilities/ip_operators.hpp index eeef881..5e3c208 100644 --- a/common/utilities/ip_operators.hpp +++ b/common/utilities/ip_operators.hpp @@ -19,13 +19,10 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef IPOPERATORS_HPP_ -#define IPOPERATORS_HPP_ +#pragma once #include "SDL_net.h" //these should've come standard bool operator==(IPaddress lhs, IPaddress rhs); bool operator!=(IPaddress lhs, IPaddress rhs); - -#endif \ No newline at end of file diff --git a/common/utilities/singleton.hpp b/common/utilities/singleton.hpp index ee9fbb0..cba191a 100644 --- a/common/utilities/singleton.hpp +++ b/common/utilities/singleton.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef SINGLETON_HPP_ -#define SINGLETON_HPP_ +#pragma once #include @@ -59,5 +58,3 @@ private: template T* Singleton::ptr = nullptr; - -#endif \ No newline at end of file diff --git a/common/utilities/vector2.hpp b/common/utilities/vector2.hpp index 00f4a06..4441c3e 100644 --- a/common/utilities/vector2.hpp +++ b/common/utilities/vector2.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef VECTOR2_HPP_ -#define VECTOR2_HPP_ +#pragma once #include #include @@ -110,5 +109,3 @@ public: //This is explicitly a POD static_assert(std::is_pod::value, "Vector2 is not a POD"); - -#endif diff --git a/server/accounts/account_data.hpp b/server/accounts/account_data.hpp index 97df753..2feecd8 100644 --- a/server/accounts/account_data.hpp +++ b/server/accounts/account_data.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef ACCOUNTDATA_HPP_ -#define ACCOUNTDATA_HPP_ +#pragma once #include @@ -55,5 +54,3 @@ private: bool mod = false; bool admin = false; }; - -#endif diff --git a/server/accounts/account_manager.hpp b/server/accounts/account_manager.hpp index 5481d13..9a3ca45 100644 --- a/server/accounts/account_manager.hpp +++ b/server/accounts/account_manager.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef ACCOUNTMANAGER_HPP_ -#define ACCOUNTMANAGER_HPP_ +#pragma once #include "account_data.hpp" #include "singleton.hpp" @@ -61,5 +60,3 @@ private: std::map elementMap; sqlite3* database = nullptr; }; - -#endif diff --git a/server/characters/character_api.hpp b/server/characters/character_api.hpp index a7fe161..c8534e7 100644 --- a/server/characters/character_api.hpp +++ b/server/characters/character_api.hpp @@ -19,12 +19,9 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef CHARACTERAPI_HPP_ -#define CHARACTERAPI_HPP_ +#pragma once #include "lua.hpp" #define TORTUGA_CHARACTER_API "character" LUAMOD_API int openCharacterAPI(lua_State* L); - -#endif \ No newline at end of file diff --git a/server/characters/character_data.hpp b/server/characters/character_data.hpp index c61a489..ba10705 100644 --- a/server/characters/character_data.hpp +++ b/server/characters/character_data.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef CHARACTERDATA_HPP_ -#define CHARACTERDATA_HPP_ +#pragma once //components #include "character_defines.hpp" @@ -47,5 +46,3 @@ private: std::string handle; std::string avatar; }; - -#endif diff --git a/server/characters/character_manager.hpp b/server/characters/character_manager.hpp index 48cc54f..2d1f3e4 100644 --- a/server/characters/character_manager.hpp +++ b/server/characters/character_manager.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef CHARACTERMANAGER_HPP_ -#define CHARACTERMANAGER_HPP_ +#pragma once #include "character_data.hpp" #include "singleton.hpp" @@ -66,5 +65,3 @@ private: std::map elementMap; sqlite3* database = nullptr; }; - -#endif diff --git a/server/characters/character_manager_api.hpp b/server/characters/character_manager_api.hpp index 7d643ef..166251e 100644 --- a/server/characters/character_manager_api.hpp +++ b/server/characters/character_manager_api.hpp @@ -19,12 +19,9 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef CHARACTERMANAGERAPI_HPP_ -#define CHARACTERMANAGERAPI_HPP_ +#pragma once #include "lua.hpp" #define TORTUGA_CHARACTER_MANAGER_API "character_manager" LUAMOD_API int openCharacterManagerAPI(lua_State* L); - -#endif \ No newline at end of file diff --git a/server/clients/client_data.hpp b/server/clients/client_data.hpp index fe7482e..bcf7cc8 100644 --- a/server/clients/client_data.hpp +++ b/server/clients/client_data.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef CLIENTDATA_HPP_ -#define CLIENTDATA_HPP_ +#pragma once #include "SDL_net.h" @@ -49,5 +48,3 @@ private: Clock::time_point lastBeat = Clock::now(); int attemptedBeats = 0; }; - -#endif diff --git a/server/clients/client_manager.hpp b/server/clients/client_manager.hpp index 94af3c5..7a7b930 100644 --- a/server/clients/client_manager.hpp +++ b/server/clients/client_manager.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef CLIENTMANAGER_HPP_ -#define CLIENTMANAGER_HPP_ +#pragma once #include "client_data.hpp" #include "server_packet.hpp" @@ -61,5 +60,3 @@ private: std::map elementMap; int counter = 0; }; - -#endif \ No newline at end of file diff --git a/server/entities/entity.hpp b/server/entities/entity.hpp index e7e9250..8ed7889 100644 --- a/server/entities/entity.hpp +++ b/server/entities/entity.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef ENTITY_HPP_ -#define ENTITY_HPP_ +#pragma once #include "bounding_box.hpp" #include "vector2.hpp" @@ -55,5 +54,3 @@ protected: BoundingBox bounds = {0, 0, 0, 0}; const char* type; }; - -#endif \ No newline at end of file diff --git a/server/entities/entity_api.hpp b/server/entities/entity_api.hpp index c08b5a1..cfd5dec 100644 --- a/server/entities/entity_api.hpp +++ b/server/entities/entity_api.hpp @@ -19,12 +19,9 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef ENTITYAPI_HPP_ -#define ENTITYAPI_HPP_ +#pragma once #include "lua.hpp" #define TORTUGA_ENTITY_API "entity" LUAMOD_API int openEntityAPI(lua_State* L); - -#endif \ No newline at end of file diff --git a/server/monsters/monster_api.hpp b/server/monsters/monster_api.hpp index e10c4a5..73d535d 100644 --- a/server/monsters/monster_api.hpp +++ b/server/monsters/monster_api.hpp @@ -19,12 +19,9 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef MONSTERAPI_HPP_ -#define MONSTERAPI_HPP_ +#pragma once #include "lua.hpp" #define TORTUGA_MONSTER_API "monster" LUAMOD_API int openMonsterAPI(lua_State* L); - -#endif \ No newline at end of file diff --git a/server/monsters/monster_data.hpp b/server/monsters/monster_data.hpp index 45fb3dd..aac2d03 100644 --- a/server/monsters/monster_data.hpp +++ b/server/monsters/monster_data.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef MONSTERDATA_HPP_ -#define MONSTERDATA_HPP_ +#pragma once #include "entity.hpp" @@ -56,5 +55,3 @@ private: std::string avatar; int scriptRef = LUA_NOREF; }; - -#endif \ No newline at end of file diff --git a/server/monsters/monster_manager.hpp b/server/monsters/monster_manager.hpp index 7ab1dfd..76b8ffa 100644 --- a/server/monsters/monster_manager.hpp +++ b/server/monsters/monster_manager.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef MONSTERMANAGER_HPP_ -#define MONSTERMANAGER_HPP_ +#pragma once #include "monster_data.hpp" @@ -61,5 +60,3 @@ private: lua_State* lua = nullptr; sqlite3* database = nullptr; }; - -#endif \ No newline at end of file diff --git a/server/monsters/monster_manager_api.hpp b/server/monsters/monster_manager_api.hpp index cc1b748..218246c 100644 --- a/server/monsters/monster_manager_api.hpp +++ b/server/monsters/monster_manager_api.hpp @@ -19,12 +19,9 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef MONSTERMANAGERAPI_HPP_ -#define MONSTERMANAGERAPI_HPP_ +#pragma once #include "lua.hpp" #define TORTUGA_MONSTER_MANAGER_API "monster_manager" LUAMOD_API int openMonsterManagerAPI(lua_State* L); - -#endif \ No newline at end of file diff --git a/server/rooms/room_api.hpp b/server/rooms/room_api.hpp index 8e99d33..b3af811 100644 --- a/server/rooms/room_api.hpp +++ b/server/rooms/room_api.hpp @@ -19,12 +19,9 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef ROOMAPI_HPP_ -#define ROOMAPI_HPP_ +#pragma once #include "lua.hpp" #define TORTUGA_ROOM_API "room" LUAMOD_API int openRoomAPI(lua_State* L); - -#endif diff --git a/server/rooms/room_data.hpp b/server/rooms/room_data.hpp index ac4331f..7cd11b2 100644 --- a/server/rooms/room_data.hpp +++ b/server/rooms/room_data.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef ROOMDATA_HPP_ -#define ROOMDATA_HPP_ +#pragma once #include "character_data.hpp" #include "region_pager_lua.hpp" @@ -78,5 +77,3 @@ private: //hooks int tickRef = LUA_NOREF; }; - -#endif diff --git a/server/rooms/room_manager.hpp b/server/rooms/room_manager.hpp index 90e7a49..af95d56 100644 --- a/server/rooms/room_manager.hpp +++ b/server/rooms/room_manager.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef ROOMMANAGER_HPP_ -#define ROOMMANAGER_HPP_ +#pragma once #include "character_data.hpp" #include "room_data.hpp" @@ -80,5 +79,3 @@ private: int createRef = LUA_NOREF; int unloadRef = LUA_NOREF; }; - -#endif diff --git a/server/rooms/room_manager_api.hpp b/server/rooms/room_manager_api.hpp index 645506c..0606d83 100644 --- a/server/rooms/room_manager_api.hpp +++ b/server/rooms/room_manager_api.hpp @@ -19,12 +19,8 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef ROOMMANAGERAPI_HPP_ -#define ROOMMANAGERAPI_HPP_ - +#pragma once #include "lua.hpp" #define TORTUGA_ROOM_MANAGER_API "room_manager" LUAMOD_API int openRoomManagerAPI(lua_State* L); - -#endif \ No newline at end of file diff --git a/server/server_application.hpp b/server/server_application.hpp index b3effbf..29ed8ff 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef SERVERAPPLICATION_HPP_ -#define SERVERAPPLICATION_HPP_ +#pragma once //managers #include "account_manager.hpp" @@ -128,5 +127,3 @@ private: //misc bool running = true; }; - -#endif diff --git a/server/server_utilities/network_api.hpp b/server/server_utilities/network_api.hpp index 3f6ec7d..62d8381 100644 --- a/server/server_utilities/network_api.hpp +++ b/server/server_utilities/network_api.hpp @@ -19,12 +19,9 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef NETWORKAPI_HPP_ -#define NETWORKAPI_HPP_ +#pragma once #include "lua.hpp" #define TORTUGA_NETWORK_API "network" LUAMOD_API int openNetworkAPI(lua_State* L); - -#endif \ No newline at end of file diff --git a/server/server_utilities/server_utilities.hpp b/server/server_utilities/server_utilities.hpp index de1f123..64035b7 100644 --- a/server/server_utilities/server_utilities.hpp +++ b/server/server_utilities/server_utilities.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef SERVERUTILITIES_HPP_ -#define SERVERUTILITIES_HPP_ +#pragma once #include "character_data.hpp" #include "serial_packet.hpp" @@ -37,5 +36,3 @@ void copyCharacterToPacket(CharacterPacket* const packet, int characterIndex); void copyCharacterToPacket(CharacterPacket* const packet, CharacterData* const characterData, int characterIndex); void pumpAndChangeRooms(int characterIndex, int newRoomIndex); void pumpAndChangeRooms(CharacterData* const characterData, int newRoomIndex, int characterIndex); - -#endif \ No newline at end of file diff --git a/server/server_utilities/sql_tools.hpp b/server/server_utilities/sql_tools.hpp index ee13b08..838bbba 100644 --- a/server/server_utilities/sql_tools.hpp +++ b/server/server_utilities/sql_tools.hpp @@ -19,13 +19,10 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef SERVERUTILITY_HPP_ -#define SERVERUTILITY_HPP_ +#pragma once #include "sqlite3.h" #include int runSQLScript(sqlite3* db, std::string fname, int (*callback)(void*,int,char**,char**) = nullptr, void* argPtr = nullptr); - -#endif diff --git a/server/triggers/trigger_api.hpp b/server/triggers/trigger_api.hpp index 171bd04..12f3e85 100644 --- a/server/triggers/trigger_api.hpp +++ b/server/triggers/trigger_api.hpp @@ -19,12 +19,9 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef TRIGGERAPI_HPP_ -#define TRIGGERAPI_HPP_ +#pragma once #include "lua.hpp" #define TORTUGA_TRIGGER_API "trigger" LUAMOD_API int openTriggerAPI(lua_State* L); - -#endif \ No newline at end of file diff --git a/server/triggers/trigger_data.hpp b/server/triggers/trigger_data.hpp index 6064285..36e9181 100644 --- a/server/triggers/trigger_data.hpp +++ b/server/triggers/trigger_data.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef TRIGGERDATA_HPP_ -#define TRIGGERDATA_HPP_ +#pragma once #include "bounding_box.hpp" #include "entity.hpp" @@ -57,5 +56,3 @@ private: int scriptRef = LUA_NOREF; std::list exclusionList; }; - -#endif \ No newline at end of file diff --git a/server/triggers/trigger_manager.hpp b/server/triggers/trigger_manager.hpp index 9fa541c..067f9ec 100644 --- a/server/triggers/trigger_manager.hpp +++ b/server/triggers/trigger_manager.hpp @@ -19,8 +19,7 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef TRIGGERMANAGER_HPP_ -#define TRIGGERMANAGER_HPP_ +#pragma once #include "bounding_box.hpp" #include "vector2.hpp" @@ -60,5 +59,3 @@ private: lua_State* lua = nullptr; int counter = 0; }; - -#endif \ No newline at end of file diff --git a/server/triggers/trigger_manager_api.hpp b/server/triggers/trigger_manager_api.hpp index fd0ca87..2350b60 100644 --- a/server/triggers/trigger_manager_api.hpp +++ b/server/triggers/trigger_manager_api.hpp @@ -19,12 +19,9 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#ifndef TRIGGERMANAGERAPI_HPP_ -#define TRIGGERMANAGERAPI_HPP_ +#pragma once #include "lua.hpp" #define TORTUGA_TRIGGER_MANAGER_API "trigger_manager" LUAMOD_API int openTriggerManagerAPI(lua_State* L); - -#endif \ No newline at end of file From af17bd28007a5b55fb6288db8ba49f8037b54313 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Tue, 7 Jul 2015 19:51:27 +1000 Subject: [PATCH 02/39] Updated common/graphics, client/base_scene.*pp to SDL2 --- README.md | 2 +- client/base_scene.cpp | 147 ++++++++-------- client/base_scene.hpp | 59 +++---- client/{scene_list.hpp => scene_signal.hpp} | 21 +-- common/graphics/image.cpp | 175 +++++++++++------- common/graphics/image.hpp | 32 ++-- common/graphics/sprite_sheet.cpp | 186 ++++++++++++++------ common/graphics/sprite_sheet.hpp | 57 +++--- common/graphics/tile_sheet.cpp | 89 +++++++--- common/graphics/tile_sheet.hpp | 44 +++-- common/makefile | 2 +- common/utilities/config_utility.cpp | 2 +- 12 files changed, 501 insertions(+), 315 deletions(-) rename client/{scene_list.hpp => scene_signal.hpp} (84%) diff --git a/README.md b/README.md index 63550a1..c09b81c 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ This game is inspired by classic 2D RPGs (Final Fantasy, The Legend of Zelda), a ## External Dependencies -* [SDL 1.2](http://www.libsdl.org/) - Simple DirectMedia Layer API +* [SDL 2.0](http://www.libsdl.org/) - Simple DirectMedia Layer API * [SDL_net 2.0](http://www.libsdl.org/projects/SDL_net/) - SDL's networking extension * [lua 5.2](http://www.lua.org/) - The lua programming language * [SQLite3](http://www.sqlite.org/) - A lightweight SQL database engine diff --git a/client/base_scene.cpp b/client/base_scene.cpp index 816f80b..7b6a515 100644 --- a/client/base_scene.cpp +++ b/client/base_scene.cpp @@ -21,91 +21,59 @@ */ #include "base_scene.hpp" -#include - -//------------------------- -//Static declarations -//------------------------- - -SDL_Surface* BaseScene::screen = nullptr; - -//------------------------- -//Public access members -//------------------------- +SDL_Renderer* BaseScene::rendererHandle = nullptr; BaseScene::BaseScene() { - // + //EMPTY } BaseScene::~BaseScene() { - // + //EMPTY } -//------------------------- -//Program control -//------------------------- - -SDL_Surface* BaseScene::SetScreen(int w, int h, int bpp, Uint32 flags) { - if (!bpp) { - bpp = SDL_GetVideoInfo()->vfmt->BitsPerPixel; - } - - screen = SDL_SetVideoMode(w, h, bpp, flags); - - if (!screen) { - throw(std::runtime_error("Failed to create the screen surface")); - } - - return screen; -} - -SDL_Surface* BaseScene::GetScreen() { - return screen; -} - -SceneList BaseScene::SetNextScene(SceneList sceneIndex) { - return nextScene = sceneIndex; -} - -SceneList BaseScene::GetNextScene() const { - return nextScene; -} - -//------------------------- -//Frame loop -//------------------------- - void BaseScene::RunFrame() { FrameStart(); - HandleEvents(); + ProcessEvents(); Update(); FrameEnd(); } -void BaseScene::RenderFrame() { - SDL_FillRect(screen, 0, 0); - Render(screen); - SDL_Flip(screen); - SDL_Delay(10); +void BaseScene::RenderFrame(SDL_Renderer* renderer) { + //EMPTY +} + +void BaseScene::SetRenderer(SDL_Renderer* r) { + rendererHandle = r; +} + +SDL_Renderer* BaseScene::GetRenderer() { + return rendererHandle; +} + +void BaseScene::SetSceneSignal(SceneSignal signal) { + sceneSignal = signal; +} + +SceneSignal BaseScene::GetSceneSignal() { + return sceneSignal; } //------------------------- -//Event handlers +//frame phases //------------------------- -void BaseScene::HandleEvents() { - SDL_Event event; +void BaseScene::FrameStart() { + //EMPTY +} +void BaseScene::ProcessEvents() { + SDL_Event event; while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: QuitEvent(); break; - case SDL_VIDEORESIZE: - SetScreen(event.resize.w, event.resize.h, 0, screen->flags); - break; - case SDL_MOUSEMOTION: MouseMotion(event.motion); break; @@ -126,15 +94,52 @@ void BaseScene::HandleEvents() { KeyUp(event.key); break; -#ifdef USE_EVENT_JOYSTICK - //EMPTY -#endif - -#ifdef USE_EVENT_UNKNOWN - default: - UnknownEvent(event); - break; -#endif - }//switch - }//while + //TODO: joystick and controller events + } + } +} + +void BaseScene::Update() { + //EMPTY +} + +void BaseScene::FrameEnd() { + //EMPTY +} + +//------------------------- +//input events +//------------------------- + +void BaseScene::QuitEvent() { + sceneSignal = SceneSignal::QUIT; +} + +void BaseScene::MouseMotion(SDL_MouseMotionEvent const& event) { + //EMPTY +} + +void BaseScene::MouseButtonDown(SDL_MouseButtonEvent const& event) { + //EMPTY +} + +void BaseScene::MouseButtonUp(SDL_MouseButtonEvent const& event) { + //EMPTY +} + +void BaseScene::MouseWheel(SDL_MouseWheelEvent const& event) { + //EMPTY +} + +void BaseScene::KeyDown(SDL_KeyboardEvent const& event) { + //preference as a default + switch(event.keysym.sym) { + case SDLK_ESCAPE: + QuitEvent(); + break; + } +} + +void BaseScene::KeyUp(SDL_KeyboardEvent const& event) { + //EMPTY } diff --git a/client/base_scene.hpp b/client/base_scene.hpp index 4292e6f..c2ad641 100644 --- a/client/base_scene.hpp +++ b/client/base_scene.hpp @@ -21,51 +21,44 @@ */ #pragma once -#include "scene_list.hpp" +#include "scene_signal.hpp" -#include "SDL/SDL.h" +#include "SDL2/SDL.h" class BaseScene { public: - //Public access members BaseScene(); virtual ~BaseScene(); - //Program control - static SDL_Surface* SetScreen(int w, int h, int bpp = 0, Uint32 flags = SDL_HWSURFACE|SDL_DOUBLEBUF); - static SDL_Surface* GetScreen(); - - SceneList SetNextScene(SceneList sceneIndex); - SceneList GetNextScene() const; - - //Frame loop virtual void RunFrame(); - virtual void RenderFrame(); + virtual void RenderFrame(SDL_Renderer*); + + static void SetRenderer(SDL_Renderer*); + SceneSignal GetSceneSignal(); protected: - virtual void FrameStart() {} - virtual void HandleEvents(); - virtual void Update() {} - virtual void FrameEnd() {} - virtual void Render(SDL_Surface* const screen) {} + //control + static SDL_Renderer* GetRenderer(); + void SetSceneSignal(SceneSignal); - //Event handlers - virtual void QuitEvent() { SetNextScene(SceneList::QUIT); } - virtual void MouseMotion(SDL_MouseMotionEvent const&) {} - virtual void MouseButtonDown(SDL_MouseButtonEvent const&) {} - virtual void MouseButtonUp(SDL_MouseButtonEvent const&) {} - virtual void KeyDown(SDL_KeyboardEvent const&) {} - virtual void KeyUp(SDL_KeyboardEvent const&) {} + //frame phases + virtual void FrameStart(); + virtual void ProcessEvents(); + virtual void Update(); + virtual void FrameEnd(); -#ifdef USE_EVENT_JOYSTICK - //EMPTY -#endif + //input events + virtual void QuitEvent(); + virtual void MouseMotion(SDL_MouseMotionEvent const& event); + virtual void MouseButtonDown(SDL_MouseButtonEvent const& event); + virtual void MouseButtonUp(SDL_MouseButtonEvent const& event); + virtual void MouseWheel(SDL_MouseWheelEvent const& event); + virtual void KeyDown(SDL_KeyboardEvent const& event); + virtual void KeyUp(SDL_KeyboardEvent const& event); -#ifdef USE_EVENT_UNKNOWN - virtual void UnknownEvent(SDL_Event const&) {} -#endif + //TODO: joystick and controller events private: - static SDL_Surface* screen; - SceneList nextScene = SceneList::CONTINUE; -}; + static SDL_Renderer* rendererHandle; + SceneSignal sceneSignal = SceneSignal::CONTINUE; +}; \ No newline at end of file diff --git a/client/scene_list.hpp b/client/scene_signal.hpp similarity index 84% rename from client/scene_list.hpp rename to client/scene_signal.hpp index 42990ae..a2cb2df 100644 --- a/client/scene_list.hpp +++ b/client/scene_signal.hpp @@ -21,17 +21,12 @@ */ #pragma once -enum class SceneList { - //these are reserved - QUIT, - CONTINUE, - FIRST, +enum SceneSignal { + //reserved members for internal use + QUIT = -1, + CONTINUE = 0, + FIRST = 1, - //custom indexes - SPLASHSCREEN, - MAINMENU, - OPTIONSMENU, - LOBBYMENU, - WORLD, - DISCONNECTEDSCREEN, -}; + //custom scenes + EXAMPLE_SCENE +}; \ No newline at end of file diff --git a/common/graphics/image.cpp b/common/graphics/image.cpp index 4089814..bd9e662 100644 --- a/common/graphics/image.cpp +++ b/common/graphics/image.cpp @@ -21,8 +21,10 @@ */ #include "image.hpp" -#include +#include "SDL2/SDL_image.h" + #include +#include Image& Image::operator=(Image const& rhs) { //don't screw yourself @@ -30,10 +32,10 @@ Image& Image::operator=(Image const& rhs) { return *this; } - FreeSurface(); + Free(); //Copy the other Image's stuff - surface = rhs.surface; + texture = rhs.texture; clip = rhs.clip; local = false; } @@ -44,102 +46,139 @@ Image& Image::operator=(Image&& rhs) { return *this; } - FreeSurface(); + Free(); //Steal the other Image's stuff - surface = rhs.surface; + texture = rhs.texture; clip = rhs.clip; local = rhs.local; - rhs.surface = nullptr; + rhs.texture = nullptr; rhs.clip = {0, 0, 0, 0}; rhs.local = false; } -SDL_Surface* Image::LoadSurface(std::string fname) { - FreeSurface(); - SDL_Surface* p = SDL_LoadBMP(fname.c_str()); - if (!p) { - std::ostringstream os; - os << "Failed to load file: " << fname; - throw(std::runtime_error(os.str())); +SDL_Texture* Image::Load(SDL_Renderer* renderer, std::string fname) { + Free(); + + //load the file into a surface + SDL_Surface* surface = IMG_Load(fname.c_str()); + if (!surface) { + std::ostringstream msg; + msg << "Failed to load an image file: " << fname; + msg << "; " << IMG_GetError(); + throw(std::runtime_error(msg.str())); + } + + //create a texture from this surface + texture = SDL_CreateTextureFromSurface(renderer, surface); + if (!texture) { + std::ostringstream msg; + msg << "Failed to convert a newly loaded image file: " << fname; + msg << "; " << SDL_GetError(); + throw(std::runtime_error(msg.str())); + } + + //set the metadata + clip.x = 0; + clip.y = 0; + if (SDL_QueryTexture(texture, nullptr, nullptr, &clip.w, &clip.h)) { + std::ostringstream msg; + msg << "Failed to record metadata for a newly loaded image file: " << fname; + msg << "; " << SDL_GetError(); + throw(std::runtime_error(msg.str())); } - surface = p; - clip = {0, 0, (Uint16)surface->w, (Uint16)surface->h}; local = true; - SetTransparentColor(255, 0, 255); //default - return surface; + + //free the surface & return + SDL_FreeSurface(surface); + return texture; } -SDL_Surface* Image::CreateSurface(Uint16 w, Uint16 h) { - FreeSurface(); - Uint32 rmask, gmask, bmask, amask; -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - rmask = 0xff000000; - gmask = 0x00ff0000; - bmask = 0x0000ff00; - amask = 0x000000ff; -#else - rmask = 0x000000ff; - gmask = 0x0000ff00; - bmask = 0x00ff0000; - amask = 0xff000000; -#endif - SDL_Surface* p = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, rmask, gmask, bmask, amask); - if (!p) { - throw(std::runtime_error("Failed to create Image surface")); +SDL_Texture* Image::Create(SDL_Renderer* renderer, Uint16 w, Uint16 h) { + Free(); + + //make the texture + texture = SDL_CreateTexture(renderer, + SDL_PIXELFORMAT_RGBA8888, + SDL_TEXTUREACCESS_STATIC, + w, h); + + if (!texture) { + std::ostringstream msg; + msg << "Failed to create a texture; " << SDL_GetError(); + throw(std::runtime_error(msg.str())); + } + + //set the metadata + clip.x = 0; + clip.y = 0; + if (SDL_QueryTexture(texture, nullptr, nullptr, &clip.w, &clip.h)) { + std::ostringstream msg; + msg << "Failed to record metadata for a newly created image"; + msg << "; " << SDL_GetError(); + throw(std::runtime_error(msg.str())); } - surface = p; - clip = {0, 0, (Uint16)surface->w, (Uint16)surface->h}; local = true; - SetTransparentColor(255, 0, 255); //default - return surface; + + return texture; } -SDL_Surface* Image::SetSurface(SDL_Surface* p) { - FreeSurface(); - if (!p) { - throw(std::invalid_argument("No surface pointer provided")); +SDL_Texture* Image::SetTexture(SDL_Texture* ptr) { + Free(); + + texture = ptr; + + //set the metadata + clip.x = 0; + clip.y = 0; + if (SDL_QueryTexture(texture, nullptr, nullptr, &clip.w, &clip.h)) { + std::ostringstream msg; + msg << "Failed to record metadata for a newly image image"; + msg << "; " << SDL_GetError(); + throw(std::runtime_error(msg.str())); } - surface = p; - clip = {0, 0, (Uint16)surface->w, (Uint16)surface->h}; local = false; - return surface; + + return texture; } -void Image::FreeSurface() { +SDL_Texture* Image::GetTexture() const { + return texture; +} + +void Image::Free() { if (local) { - SDL_FreeSurface(surface); + SDL_DestroyTexture(texture); local = false; } - surface = nullptr; + texture = nullptr; clip = {0, 0, 0, 0}; } -void Image::DrawTo(SDL_Surface* dest, Sint16 x, Sint16 y) { - if (!surface) { - throw(std::logic_error("No image surface to draw")); +void Image::DrawTo(SDL_Renderer* const renderer, Sint16 x, Sint16 y, double scaleX, double scaleY) { + if (!texture) { + throw(std::logic_error("No image texture to draw")); } - SDL_Rect sclip = clip, dclip = {x,y}; - SDL_BlitSurface(surface, &sclip, dest, &dclip); + SDL_Rect sclip = clip; + SDL_Rect dclip = {x, y, Uint16(clip.w * scaleX), Uint16(clip.h * scaleY)}; + SDL_RenderCopy(renderer, texture, &sclip, &dclip); } -void Image::SetTransparentColor(Uint8 r, Uint8 g, Uint8 b) { - if (!surface) { - throw(std::logic_error("Failed to set the transparent color")); +void Image::SetAlpha(Uint8 a) { + if (SDL_SetTextureAlphaMod(texture, a)) { + std::ostringstream msg; + msg << "Failed to set alpha; " << SDL_GetError(); + throw(std::runtime_error(msg.str())); } - if (!local) { - throw(std::logic_error("Cannot set the transparent color of a non-local surface")); - } - SDL_SetColorKey(surface, SDL_SRCCOLORKEY, SDL_MapRGB(surface->format, r, g, b)); } -void Image::ClearTransparentColor() { - if (!surface) { - throw(std::logic_error("Failed to clear the transparent color")); +Uint8 Image::GetAlpha() { + Uint8 ret = 0; + if (SDL_GetTextureAlphaMod(texture, &ret)) { + std::ostringstream msg; + msg << "Failed to get alpha; " << SDL_GetError(); + throw(std::runtime_error(msg.str())); } - if (!local) { - throw(std::logic_error("Cannot clear the transparent color of a non-local surface")); - } - SDL_SetColorKey(surface, 0, 0); -} + return ret; +} \ No newline at end of file diff --git a/common/graphics/image.hpp b/common/graphics/image.hpp index 324ae59..f6685e4 100644 --- a/common/graphics/image.hpp +++ b/common/graphics/image.hpp @@ -21,7 +21,8 @@ */ #pragma once -#include "SDL/SDL.h" +#include "SDL2/SDL.h" + #include class Image { @@ -29,21 +30,24 @@ public: Image() = default; Image(Image const& rhs) { *this = rhs; } Image(Image&& rhs) { *this = std::move(rhs); } - Image(std::string fname) { LoadSurface(fname); } - Image(Uint16 w, Uint16 h) { CreateSurface(w, h); } - Image(SDL_Surface* p) { SetSurface(p); } - ~Image() { FreeSurface(); } + Image(SDL_Renderer* r, std::string fname) { Load(r, fname); } + Image(SDL_Renderer* r, Uint16 w, Uint16 h) { Create(r, w, h); } + Image(SDL_Texture* p) { SetTexture(p); } + virtual ~Image() { Free(); } Image& operator=(Image const&); Image& operator=(Image&&); - SDL_Surface* LoadSurface(std::string fname); - SDL_Surface* CreateSurface(Uint16 w, Uint16 h); - SDL_Surface* SetSurface(SDL_Surface*); - SDL_Surface* GetSurface() const { return surface; } - void FreeSurface(); + SDL_Texture* Load(SDL_Renderer* renderer, std::string fname); + SDL_Texture* Create(SDL_Renderer* renderer, Uint16 w, Uint16 h); + SDL_Texture* SetTexture(SDL_Texture*); + SDL_Texture* GetTexture() const; + virtual void Free(); - void DrawTo(SDL_Surface* const, Sint16 x, Sint16 y); + void DrawTo(SDL_Renderer* const, Sint16 x, Sint16 y, double scaleX = 1.0, double scaleY = 1.0); + + void SetAlpha(Uint8 a); + Uint8 GetAlpha(); //Clip handlers SDL_Rect SetClip(SDL_Rect r) { return clip = r; } @@ -61,10 +65,8 @@ public: bool GetLocal() const { return local; } - void SetTransparentColor(Uint8 r, Uint8 g, Uint8 b); - void ClearTransparentColor(); protected: - SDL_Surface* surface = nullptr; + SDL_Texture* texture = nullptr; SDL_Rect clip = {0, 0, 0, 0}; bool local = false; -}; +}; \ No newline at end of file diff --git a/common/graphics/sprite_sheet.cpp b/common/graphics/sprite_sheet.cpp index 93c1984..b0db04d 100644 --- a/common/graphics/sprite_sheet.cpp +++ b/common/graphics/sprite_sheet.cpp @@ -21,82 +21,166 @@ */ #include "sprite_sheet.hpp" -#include #include +#include + +SpriteSheet& SpriteSheet::operator=(SpriteSheet const& rhs) { + //don't screw yourself + if (this == &rhs) { + return *this; + } + + Free(); + + //Copy the other SpriteSheet's stuff + texture = rhs.texture; + clip = rhs.clip; + local = false; + countX = rhs.countX; + countY = rhs.countY; + indexX = rhs.indexX; + indexY = rhs.indexY; + delay = rhs.delay; + tick = rhs.tick; +} + +SpriteSheet& SpriteSheet::operator=(SpriteSheet&& rhs) { + //don't screw yourself + if (this == &rhs) { + return *this; + } + + Free(); + + //Steal the other SpriteSheet's stuff + texture = rhs.texture; + clip = rhs.clip; + local = rhs.local; + countX = rhs.countX; + countY = rhs.countY; + indexX = rhs.indexX; + indexY = rhs.indexY; + delay = rhs.delay; + tick = rhs.tick; + + rhs.texture = nullptr; + rhs.clip = {0, 0, 0, 0}; + rhs.local = false; + rhs.countX = 0; + rhs.countY = 0; + rhs.indexX = 0; + rhs.indexY = 0; + rhs.delay = 0.0; + rhs.tick = 0.0; +} void SpriteSheet::Update(double delta) { + //if the delay has passed if (delay && (tick += delta) >= delay) { - if (++xIndex >= xCount) { - xIndex = 0; + //if the index is out of bounds + if (++indexX >= countX) { + indexX = 0; } tick = 0; } - image.SetClipX(xIndex * image.GetClipW()); - image.SetClipY(yIndex * image.GetClipH()); + //modify area drawn + clip.x = indexX * clip.w; + clip.y = indexX * clip.y; } -SDL_Surface* SpriteSheet::LoadSurface(std::string fname, Uint16 xCellCount, Uint16 yCellCount) { - image.LoadSurface(fname); +SDL_Texture* SpriteSheet::Load(SDL_Renderer* r, std::string fname, Uint16 cx, Uint16 cy) { + //call the base function + Image::Load(r, fname); - xCount = xCellCount; - yCount = yCellCount; + //set the metadata + countX = cx; + countY = cy; - image.SetClipW(image.GetSurface()->w / xCount); - image.SetClipH(image.GetSurface()->h / yCount); + //assume clip.x and clip.y were set to the size of the texture + //reduce the w & h to the size of one cell + clip.w = clip.w / countX; + clip.h = clip.h / countY; - xIndex = yIndex = 0; + indexX = indexY = 0; + delay = tick = 0.0; + + return texture; +} + +SDL_Texture* SpriteSheet::Create(SDL_Renderer* r, Uint16 w, Uint16 h, Uint16 cx, Uint16 cy) { + //call the base function + Image::Create(r, w, h); + + //set the metadata + countX = cx; + countY = cy; + + //assume clip.x and clip.y were set to the size of the texture + //reduce the w & h to the size of one cell + clip.w = clip.w / countX; + clip.h = clip.h / countY; + + indexX = indexY = 0; + delay = tick = 0.0; + + return texture; +} + +SDL_Texture* SpriteSheet::SetTexture(SDL_Texture* ptr, Uint16 cx, Uint16 cy) { + //call the base function + Image::SetTexture(ptr); + + //set the metadata + countX = cx; + countY = cy; + + //assume clip.x and clip.y were set to the size of the texture + //reduce the w & h to the size of one cell + clip.w = clip.w / countX; + clip.h = clip.h / countY; + + indexX = indexY = 0; + delay = tick = 0.0; + + return texture; +} + +void SpriteSheet::Free() { + Image::Free(); + countX = countY = 0; + indexX = indexY = 0; delay = tick = 0.0; } -SDL_Surface* SpriteSheet::SetSurface(SDL_Surface* surface, Uint16 xCellCount, Uint16 yCellCount) { - image.SetSurface(surface); - - xCount = xCellCount; - yCount = yCellCount; - - image.SetClipW(image.GetSurface()->w / xCount); - image.SetClipH(image.GetSurface()->h / yCount); - - xIndex = yIndex = 0; - delay = tick = 0.0; +Uint16 SpriteSheet::SetCountX(Uint16 i) { + indexX = 0; + return countX = i; } -void SpriteSheet::FreeSurface() { - image.FreeSurface(); - xCount = yCount = 0; - xIndex = yIndex = 0; - delay = tick = 0.0; +Uint16 SpriteSheet::SetCountY(Uint16 i) { + indexY = 0; + return countY = i; } -Uint16 SpriteSheet::SetXCount(Uint16 i) { - xIndex = 0; - return xCount = i; -} - -Uint16 SpriteSheet::SetYCount(Uint16 i) { - yIndex = 0; - return yCount = i; -} - -Uint16 SpriteSheet::SetXIndex(Uint16 i) { - if (i > xCount) { - std::ostringstream os; - os << "Cannot set x index to " << i; - throw(std::invalid_argument(os.str())); +Uint16 SpriteSheet::SetIndexX(Uint16 i) { + if (i > countX) { + std::ostringstream msg; + msg << "Cannot set index 'x' to " << i; + throw(std::out_of_range(msg.str())); } - return xIndex = i; + return indexX = i; } -Uint16 SpriteSheet::SetYIndex(Uint16 i) { - if (i > yCount) { - std::ostringstream os; - os << "Cannot set y index to " << i; - throw(std::invalid_argument(os.str())); +Uint16 SpriteSheet::SetIndexY(Uint16 i) { + if (i > countY) { + std::ostringstream msg; + msg << "Cannot set index 'y' to " << i; + throw(std::invalid_argument(msg.str())); } - return yIndex = i; + return indexY = i; } double SpriteSheet::SetDelay(double d) { tick = 0; return delay = d; -} +} \ No newline at end of file diff --git a/common/graphics/sprite_sheet.hpp b/common/graphics/sprite_sheet.hpp index 2eb3238..395cfe3 100644 --- a/common/graphics/sprite_sheet.hpp +++ b/common/graphics/sprite_sheet.hpp @@ -23,41 +23,48 @@ #include "image.hpp" -class SpriteSheet { +class SpriteSheet : public Image { public: SpriteSheet() = default; - SpriteSheet(std::string fname, Uint16 xCellCount, Uint16 yCellCount) { LoadSurface(fname, xCellCount, yCellCount); } - SpriteSheet(SDL_Surface* surface, Uint16 xCellCount, Uint16 yCellCount) { SetSurface(surface, xCellCount, yCellCount); } - ~SpriteSheet() { FreeSurface(); }; + SpriteSheet(SpriteSheet const& rhs) { *this = rhs; } + SpriteSheet(SpriteSheet&& rhs) { *this = std::move(rhs); } + SpriteSheet(SDL_Renderer* r, std::string fname, Uint16 cx, Uint16 cy) + { Load(r, fname, cx, cy); } + SpriteSheet(SDL_Renderer* r, Uint16 w, Uint16 h, Uint16 cx, Uint16 cy) + { Create(r, w, h, cx, cy); } + SpriteSheet(SDL_Texture* p, Uint16 cx, Uint16 cy) + { SetTexture(p, cx, cy); } + ~SpriteSheet() = default; + + SpriteSheet& operator=(SpriteSheet const&); + SpriteSheet& operator=(SpriteSheet&&); void Update(double delta); - SDL_Surface* LoadSurface(std::string fname, Uint16 xCellCount, Uint16 yCellCount); - SDL_Surface* SetSurface(SDL_Surface* surface, Uint16 xCellCount, Uint16 yCellCount); - SDL_Surface* GetSurface() { return image.GetSurface(); } - void FreeSurface(); + SDL_Texture* Load(SDL_Renderer*, std::string fname, Uint16 cx, Uint16 cy); + SDL_Texture* Create(SDL_Renderer*, Uint16 w, Uint16 h, Uint16 cx, Uint16 cy); + SDL_Texture* SetTexture(SDL_Texture*, Uint16 cx, Uint16 cy); + void Free() override; - void DrawTo(SDL_Surface* const dest, Sint16 x, Sint16 y) { image.DrawTo(dest, x, y); } + Uint16 SetCountX(Uint16); + Uint16 SetCountY(Uint16); + Uint16 SetIndexX(Uint16); + Uint16 SetIndexY(Uint16); - //accessors and mutators - Image* GetImage() { return ℑ } //OO breaker - - Uint16 SetXCount(Uint16); - Uint16 SetYCount(Uint16); - Uint16 SetXIndex(Uint16); - Uint16 SetYIndex(Uint16); - - Uint16 GetXCount() const { return xCount; } - Uint16 GetYCount() const { return yCount; } - Uint16 GetXIndex() const { return xIndex; } - Uint16 GetYIndex() const { return yIndex; } + Uint16 GetCountX() const { return countX; } + Uint16 GetCountY() const { return countY; } + Uint16 GetIndexX() const { return indexX; } + Uint16 GetIndexY() const { return indexY; } double SetDelay(double d); double GetDelay() const { return delay; } private: - Image image; - Uint16 xCount = 0, yCount = 0; //number of cells - Uint16 xIndex = 0, yIndex = 0; //current cell being drawn + Uint16 countX = 0, countY = 0, indexX = 0, indexY = 0; double delay = 0.0, tick = 0.0; -}; + + //disable access + using Image::Load; + using Image::Create; + using Image::SetTexture; +}; \ No newline at end of file diff --git a/common/graphics/tile_sheet.cpp b/common/graphics/tile_sheet.cpp index 6f47337..137b77a 100644 --- a/common/graphics/tile_sheet.cpp +++ b/common/graphics/tile_sheet.cpp @@ -21,28 +21,71 @@ */ #include "tile_sheet.hpp" -void TileSheet::Load(std::string fname, int tileWidth, int tileHeight) { - image.LoadSurface(fname); - image.SetClipW(tileWidth); - image.SetClipH(tileHeight); - xCount = image.GetSurface()->w / image.GetClipW(); - yCount = image.GetSurface()->h / image.GetClipH(); +TileSheet& TileSheet::operator=(TileSheet const& rhs) { + //don't screw yourself + if (this == &rhs) { + return *this; + } + + Free(); + + //Copy the other TileSheet's stuff + texture = rhs.texture; + clip = rhs.clip; + local = false; + countX = rhs.countX; + countY = rhs.countY; } -void TileSheet::Unload() { - image.FreeSurface(); - xCount = yCount = 0; +TileSheet& TileSheet::operator=(TileSheet&& rhs) { + //don't screw yourself + if (this == &rhs) { + return *this; + } + + Free(); + + //Copy the other TileSheet's stuff + texture = rhs.texture; + clip = rhs.clip; + local = false; + countX = rhs.countX; + countY = rhs.countY; + + rhs.texture = nullptr; + rhs.clip = {0, 0, 0, 0}; + rhs.local = false; + rhs.countX = 0; + rhs.countY = 0; } -void TileSheet::DrawTileTo(SDL_Surface* const dest, int x, int y, Region::type_t tile) { - //0 is invisible - if (tile == 0) return; - image.SetClipX((tile-1) % xCount * image.GetClipW()); - image.SetClipY((tile-1) / xCount * image.GetClipH()); - image.DrawTo(dest, x, y); +void TileSheet::Load(SDL_Renderer* renderer, std::string fname, int tileWidth, int tileHeight) { + Image::Load(renderer, fname); + countX = clip.w / tileWidth; + countY = clip.h / tileHeight; + clip.w = tileWidth; + clip.h = tileHeight; } -void TileSheet::DrawRegionTo(SDL_Surface* const dest, Region* const region, int camX, int camY) { +SDL_Texture* TileSheet::SetTexture(SDL_Texture* ptr, int tileWidth, int tileHeight) { + Image::SetTexture(ptr); + countX = clip.w / tileWidth; + countY = clip.h / tileHeight; + clip.w = tileWidth; + clip.h = tileHeight; +} + +void TileSheet::Free() { + Image::Free(); + countX = countY = 0; +} + +void TileSheet::DrawLayerTo(SDL_Renderer* const renderer, Region* const region, int layer, int camX, int camY, double scaleX, double scaleY) { + //TODO: empty +} + +void TileSheet::DrawRegionTo(SDL_Renderer* const renderer, Region* const region, int camX, int camY, double scaleX, double scaleY) { + //TODO: (2) make TileSheet a friend class of Region Region::type_t tile = 0; for (register int i = 0; i < REGION_WIDTH; ++i) { for (register int j = 0; j < REGION_HEIGHT; ++j) { @@ -50,12 +93,14 @@ void TileSheet::DrawRegionTo(SDL_Surface* const dest, Region* const region, int tile = region->GetTile(i, j, k); //0 is invisible if (tile == 0) continue; - image.SetClipX((tile-1) % xCount * image.GetClipW()); - image.SetClipY((tile-1) / xCount * image.GetClipH()); - image.DrawTo(dest, - (region->GetX() + i) * image.GetClipW() - camX, - (region->GetY() + j) * image.GetClipH() - camY); + clip.x = (tile-1) % countX * clip.h; + clip.y = (tile-1) / countX * clip.w; + //TODO: (2) raw rendering; improve preformance + Image::DrawTo(renderer, + (region->GetX() + i) * clip.w - camX, + (region->GetY() + j) * clip.h - camY, + scaleX, scaleY); } } } -} \ No newline at end of file +} diff --git a/common/graphics/tile_sheet.hpp b/common/graphics/tile_sheet.hpp index 8ac142f..f327151 100644 --- a/common/graphics/tile_sheet.hpp +++ b/common/graphics/tile_sheet.hpp @@ -27,25 +27,41 @@ #include -class TileSheet { +class TileSheet : public Image { public: TileSheet() = default; - TileSheet(std::string f, int w, int h) { Load(f, w, h); } + TileSheet(TileSheet const& rhs) { *this = rhs; } + TileSheet(TileSheet&& rhs) { *this = std::move(rhs); } + TileSheet(SDL_Renderer* r, std::string fn, int tw, int th) { Load(r, fn, tw, th); } + TileSheet(SDL_Texture* p, int tw, int th) { SetTexture(p, tw, th); } ~TileSheet() = default; - void Load(std::string fname, int tileWidth, int tileHeight); - void Unload(); + TileSheet& operator=(TileSheet const&); + TileSheet& operator=(TileSheet&&); - void DrawTileTo(SDL_Surface* const dest, int x, int y, Region::type_t tile); - void DrawRegionTo(SDL_Surface* const dest, Region* const region, int camX, int camY); + void Load(SDL_Renderer*, std::string fname, int tileWidth, int tileHeight); + SDL_Texture* SetTexture(SDL_Texture*, int tileWidth, int tileHeight); + void Free() override; + + void DrawLayerTo(SDL_Renderer* const renderer, Region* const region, int layer, int camX, int camY, double scaleX = 1.0, double scaleY = 1.0); + void DrawRegionTo(SDL_Renderer* const renderer, Region* const region, int camX, int camY, double scaleX = 1.0, double scaleY = 1.0); //accessors - Image* GetImage() { return ℑ } - int GetXCount() { return xCount; } - int GetYCount() { return yCount; } - int GetTileW() { return image.GetClipW(); } - int GetTileH() { return image.GetClipH(); } -private: - Image image; - int xCount = 0, yCount = 0; + //DOCS: reuse Image::clip for tile sizes + int GetCountX() { return countX; } + int GetCountY() { return countY; } + int GetTileW() { return clip.w; } + int GetTileH() { return clip.h; } + +protected: + int countX = 0, countY = 0; + + using Image::Load; + using Image::Create; + using Image::SetTexture; + using Image::SetClip; + using Image::SetClipX; + using Image::SetClipY; + using Image::SetClipW; + using Image::SetClipH; }; diff --git a/common/makefile b/common/makefile index e2d1029..59bcb4f 100644 --- a/common/makefile +++ b/common/makefile @@ -4,5 +4,5 @@ all: $(MAKE) -C graphics $(MAKE) -C map $(MAKE) -C network - $(MAKE) -C ui +# $(MAKE) -C ui #TODO: reenable this $(MAKE) -C utilities diff --git a/common/utilities/config_utility.cpp b/common/utilities/config_utility.cpp index 832680e..3161501 100644 --- a/common/utilities/config_utility.cpp +++ b/common/utilities/config_utility.cpp @@ -61,7 +61,7 @@ void ConfigUtility::Load(std::string fname, bool skipMissingFile, int argc, char memset(key, 0, 256); //read the key-value pair - if (sscanf(argv[i], "-%[^=]=%[^\0]", key, val) != 2) { + if (sscanf(argv[i], "-%[^=]=%[^\\0]", key, val) != 2) { std::ostringstream os; os << "Failed to read a command line config argument (expected -%s=%s):" << std::endl; os << "\targv[" << i << "]: " << argv[i] << std::endl; From e08e34b677e0528cf188008dd3035c445fe8e16f Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Tue, 7 Jul 2015 20:00:38 +1000 Subject: [PATCH 03/39] Updated README.md --- README.md | 7 +++++-- client/makefile | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c09b81c..de55c5e 100644 --- a/README.md +++ b/README.md @@ -11,19 +11,22 @@ This game is inspired by classic 2D RPGs (Final Fantasy, The Legend of Zelda), a ## Documentation -* [Tortuga Wiki](https://github.com/Ratstail91/Tortuga/wiki) - Full documentation +* [Tortuga Wiki](https://github.com/Ratstail91/Tortuga/wiki) - Full documentation (incomplete) * [Tortuga Bug Tracker](https://github.com/Ratstail91/Tortuga/issues) - A list of all known bugs and issues ## External Dependencies * [SDL 2.0](http://www.libsdl.org/) - Simple DirectMedia Layer API +* [SDL_image 2.0](https://www.libsdl.org/projects/SDL_image/) - An SDL Extension for loading multiple image file formats * [SDL_net 2.0](http://www.libsdl.org/projects/SDL_net/) - SDL's networking extension +* [SDL_ttf 2.0](https://www.libsdl.org/projects/SDL_ttf/) - An SDL extention for rendering fonts * [lua 5.2](http://www.lua.org/) - The lua programming language * [SQLite3](http://www.sqlite.org/) - A lightweight SQL database engine ## Tools -* [WinRAR](http://www.rarlab.com/) - The best compression tool available IMO; only needed for Windows distribution +* [WinRAR](http://www.rarlab.com/) - A free archive tool; needed for Windows distribution +* [tar](http://www.gnu.org/software/tar/manual/) - The GNU archive tool; needed for Linux distribution * [Dropbox](https://www.dropbox.com/) - For hosting and distribution ## Copyright diff --git a/client/makefile b/client/makefile index 5013094..d4104aa 100644 --- a/client/makefile +++ b/client/makefile @@ -7,7 +7,7 @@ LIBS+=client.a ../libcommon.a -lSDL_net ifeq ($(OS),Windows_NT) LIBS+=-lwsock32 -liphlpapi -lmingw32 endif -LIBS+=-lSDLmain -lSDL +LIBS+=-lSDLmain -lSDL -lSDL2_image -lSDL2_ttf #flags CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) From 4ced681c76717675610e5edec2dbc75c2b05371e Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 8 Jul 2015 03:09:50 +1000 Subject: [PATCH 04/39] Working on the ui, incomplete --- common/makefile | 2 +- common/ui/button.hpp | 75 +++++++++++---------------------------- common/ui/menu_bar.hpp | 1 - common/ui/raster_font.cpp | 60 ------------------------------- common/ui/raster_font.hpp | 51 -------------------------- makefile | 6 ++-- server/makefile | 2 +- 7 files changed, 26 insertions(+), 171 deletions(-) delete mode 100644 common/ui/raster_font.cpp delete mode 100644 common/ui/raster_font.hpp diff --git a/common/makefile b/common/makefile index 59bcb4f..e2d1029 100644 --- a/common/makefile +++ b/common/makefile @@ -4,5 +4,5 @@ all: $(MAKE) -C graphics $(MAKE) -C map $(MAKE) -C network -# $(MAKE) -C ui #TODO: reenable this + $(MAKE) -C ui $(MAKE) -C utilities diff --git a/common/ui/button.hpp b/common/ui/button.hpp index 4b93520..16b6cac 100644 --- a/common/ui/button.hpp +++ b/common/ui/button.hpp @@ -21,71 +21,38 @@ */ #pragma once +#include "bounding_box.hpp" #include "image.hpp" -#include "raster_font.hpp" + +#include "SDL2/SDL_ttf.h" #include -/* 3-phases, no toggle, centred text - * This class uses the size of the provided image as its bounds. Also, - * The provided image should be formatted correctly. - * - * The button's image should be divided into 3 sections virtucally, - * which act as the different button images. The clip width & height of the - * Image should be set manually, and the height should be 1/3 of the total - * graphical data. -*/ class Button { public: - enum State { - NORMAL = 0, HOVER = 1, PRESSED = 2 + //states available + enum class State { + NORMAL, HOVER, PRESSED }; + //methods Button() = default; ~Button() = default; - //handle input - State MouseMotion(SDL_MouseMotionEvent const&); - State MouseButtonDown(SDL_MouseButtonEvent const&); - State MouseButtonUp(SDL_MouseButtonEvent const&); + void RenderText(std::string s); + bool CaptureInput(int x, int y, bool pressed); + void DrawTo(SDL_Renderer*, int camX, int camY); - //yet another draw function - void DrawTo(SDL_Surface* const); + //accessors & mutators + int SetX(int x) { return posX = x; } + int SetY(int y) { return posY = y; } + int GetX() { return posX; } + int GetY() { return posY; } + Image* GetImage() { return ℑ } + BoundingBox* GetBoundingBox() { return &boundingBox; } - //accessors and mutators - Image* SetImage(Image* const ptr) { return image = ptr; } - Image* GetImage() { return image; } - RasterFont* SetFont(RasterFont* const ptr) { return font = ptr; } - RasterFont* GetFont() { return font; } - - Sint16 SetX(Sint16 i) { return x = i; } - Sint16 SetY(Sint16 i) { return y = i; } - Sint16 GetX() const { return x; } - Sint16 GetY() const { return y; } - - Sint16 SetTextX(Sint16 i) { return textX = i; } - Sint16 SetTextY(Sint16 i) { return textY = i; } - Sint16 GetTextX() const { return textX; } - Sint16 GetTextY() const { return textY; } - - State SetState(State s) { return state = s; } - State GetState() const { return state; } - - std::string SetText(std::string); - std::string GetText() const { return text; } - -private: - State CalcState(Sint16 x, Sint16 y, bool leftPressed); - - //point to the provided external objects - Image* image = nullptr; - RasterFont* font = nullptr; - - //positions - Sint16 x = 0, y = 0; - Sint16 textX = 0, textY = 0; - - // - State state = State::NORMAL; - std::string text; +protected: + Image image; + BoundingBox boundingBox; + int posX = 0, posY = 0; }; diff --git a/common/ui/menu_bar.hpp b/common/ui/menu_bar.hpp index 351259b..fa01f9c 100644 --- a/common/ui/menu_bar.hpp +++ b/common/ui/menu_bar.hpp @@ -22,7 +22,6 @@ #pragma once #include "image.hpp" -#include "raster_font.hpp" #include "button.hpp" #include diff --git a/common/ui/raster_font.cpp b/common/ui/raster_font.cpp deleted file mode 100644 index 8b48fd2..0000000 --- a/common/ui/raster_font.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. -*/ -#include "raster_font.hpp" - -#include - -/* It might be more efficient to render to a different surface (like an Image) - * rather than calling this function with all of it's '%' and '/'. -*/ - -void RasterFont::DrawStringTo(std::string s, SDL_Surface* const dest, Sint16 x, Sint16 y) { - if (!image.GetSurface()) { - throw(std::runtime_error("RasterFont not loaded")); - } - const Uint16 w = image.GetClipW(); - const Uint16 h = image.GetClipH(); - for (int i = 0; i < s.size(); i++) { - image.SetClipX(s[i] % 16 * w); - image.SetClipY(s[i] / 16 * h); - image.DrawTo(dest, x + i * w, y); - } -} - -/* Note: This class can only take a raster font with 16*16 characters, and the - * indevidual characters must have the same dimensions. Overall this class is too - * restrictive; I suggest using a 3rd party library. -*/ - -SDL_Surface* RasterFont::LoadSurface(std::string fname) { - image.LoadSurface(fname); - image.SetClipW(image.GetSurface()->w/16); - image.SetClipH(image.GetSurface()->h/16); - return image.GetSurface(); -} - -SDL_Surface* RasterFont::SetSurface(SDL_Surface* p) { - image.SetSurface(p); - image.SetClipW(image.GetSurface()->w/16); - image.SetClipH(image.GetSurface()->h/16); - return image.GetSurface(); -} diff --git a/common/ui/raster_font.hpp b/common/ui/raster_font.hpp deleted file mode 100644 index 9000921..0000000 --- a/common/ui/raster_font.hpp +++ /dev/null @@ -1,51 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. -*/ -#pragma once - -#include "image.hpp" - -class RasterFont { -public: - RasterFont() = default; - RasterFont(RasterFont const& rhs) { *this = rhs; } - RasterFont(RasterFont&& rhs) { *this = std::move(rhs); } - RasterFont(std::string fname) { LoadSurface(fname); } - RasterFont(SDL_Surface* p) { SetSurface(p); } - ~RasterFont() = default; - - RasterFont& operator=(RasterFont const& rhs) { image = rhs.image; } - RasterFont& operator=(RasterFont&& rhs) { image = std::move(rhs.image); } - - void DrawStringTo(std::string, SDL_Surface* const, Sint16 x, Sint16 y); - - //Accessors and Mutators - SDL_Surface* LoadSurface(std::string); - SDL_Surface* SetSurface(SDL_Surface*); - SDL_Surface* GetSurface() const { return image.GetSurface(); } - void FreeSurface() { image.FreeSurface(); } - - Uint16 GetCharW() const { return image.GetClipW(); } - Uint16 GetCharH() const { return image.GetClipH(); } - -private: - Image image; -}; diff --git a/makefile b/makefile index 600f1a7..a9c9c5b 100644 --- a/makefile +++ b/makefile @@ -33,9 +33,9 @@ clean: ifeq ($(OS),Windows_NT) $(RM) *.o *.a *.exe else ifeq ($(shell uname), Linux) - find . -type f -name *.o -exec rm -f -r -v {} \; - find . -type f -name *.a -exec rm -f -r -v {} \; - rm -f -v out/client out/server + find . -type f -name '*.o' -exec rm -f -r -v {} \; + find . -type f -name '*.a' -exec rm -f -r -v {} \; + rm -f -v $(OUT) endif rebuild: clean all diff --git a/server/makefile b/server/makefile index 2f8de96..fd5b942 100644 --- a/server/makefile +++ b/server/makefile @@ -9,7 +9,7 @@ ifeq ($(OS),Windows_NT) endif LIBS+=-lSDLmain -lSDL -llua -lsqlite3 ifeq ($(shell uname), Linux) - #I don't know what this does, but Ubuntu needs it + #I don't know what this does, but Ubuntu needs it (dynamic linking for lua) LIBS+=-ldl endif From d2e75e02c5fc8d6e75884f45a667cddc978e4376 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Mon, 20 Jul 2015 13:35:10 +1000 Subject: [PATCH 05/39] Imported updates to the map system --- common/makefile | 2 +- common/map/makefile | 2 +- common/map/region.hpp | 2 ++ common/map/region_pager_lua.cpp | 22 +++++++++----- common/map/region_pager_lua.hpp | 2 ++ common/{graphics => map}/tile_sheet.cpp | 38 ++++++++++++++++++------- common/{graphics => map}/tile_sheet.hpp | 2 +- 7 files changed, 50 insertions(+), 20 deletions(-) rename common/{graphics => map}/tile_sheet.cpp (77%) rename common/{graphics => map}/tile_sheet.hpp (98%) diff --git a/common/makefile b/common/makefile index e2d1029..9fe752a 100644 --- a/common/makefile +++ b/common/makefile @@ -4,5 +4,5 @@ all: $(MAKE) -C graphics $(MAKE) -C map $(MAKE) -C network - $(MAKE) -C ui +# $(MAKE) -C ui $(MAKE) -C utilities diff --git a/common/map/makefile b/common/map/makefile index 2020f4a..03a0db8 100644 --- a/common/map/makefile +++ b/common/map/makefile @@ -1,5 +1,5 @@ #config -INCLUDES+=. ../utilities +INCLUDES+=. ../graphics LIBS+= CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) diff --git a/common/map/region.hpp b/common/map/region.hpp index 68511be..da919cb 100644 --- a/common/map/region.hpp +++ b/common/map/region.hpp @@ -52,6 +52,8 @@ public: std::bitset* GetSolidBitset(); private: + friend class TileSheet; + const int x; const int y; diff --git a/common/map/region_pager_lua.cpp b/common/map/region_pager_lua.cpp index 4e0a973..66771c9 100644 --- a/common/map/region_pager_lua.cpp +++ b/common/map/region_pager_lua.cpp @@ -23,9 +23,6 @@ #include -//DOCS: Load, Save and Create fail unless the lua function has been set -//DOCS: UnloadIf and UnloadAll will still continue without the function set - RegionPagerLua::~RegionPagerLua() { //unload all regions UnloadAll(); @@ -44,6 +41,7 @@ Region* RegionPagerLua::LoadRegion(int x, int y) { //check if this function is available if (lua_isnil(lua, -1)) { lua_pop(lua, 1); + //signal that there is no load function return nullptr; } @@ -57,17 +55,20 @@ Region* RegionPagerLua::LoadRegion(int x, int y) { } //check the return value, success or failure - if (lua_toboolean(lua, -1)) { + if (lua_isboolean(lua, -1) && lua_toboolean(lua, -1)) { lua_pop(lua, 1); + //push and return the loaded region regionList.push_front(tmpRegion); return ®ionList.front(); } else { lua_pop(lua, 1); + //signal a failure return nullptr; } } +//NOTE: this return value seems strange; could replace it with a boolean //return the saved region, or nullptr on failure Region* RegionPagerLua::SaveRegion(int x, int y) { //get the pager's function from the registry @@ -76,6 +77,7 @@ Region* RegionPagerLua::SaveRegion(int x, int y) { //check if this function is available if (lua_isnil(lua, -1)) { lua_pop(lua, 1); + //signal that the region wasn't saved return nullptr; } @@ -83,6 +85,7 @@ Region* RegionPagerLua::SaveRegion(int x, int y) { Region* ptr = FindRegion(x, y); if (!ptr) { lua_pop(lua, 1); + //signal that there is no save function return nullptr; } lua_pushlightuserdata(lua, ptr); @@ -93,17 +96,20 @@ Region* RegionPagerLua::SaveRegion(int x, int y) { } //check the return value, success or failure - if (lua_toboolean(lua, -1)) { + if (lua_isboolean(lua, -1) && lua_toboolean(lua, -1)) { lua_pop(lua, 1); + //return the specified region that was saved return ptr; } else { lua_pop(lua, 1); + //signal a failure return nullptr; } } -//return the created region, or nullptr on failure +//DOCS: since this method is the last ditch call from GetRegion, it must return a valid region object, even if the create function hasn't been set. +//return a new region, throwing an error on failure Region* RegionPagerLua::CreateRegion(int x, int y) { if (FindRegion(x, y)) { throw(std::logic_error("Cannot overwrite an existing region")); @@ -115,7 +121,9 @@ Region* RegionPagerLua::CreateRegion(int x, int y) { //check if this function is available if (lua_isnil(lua, -1)) { lua_pop(lua, 1); - return nullptr; + //return an empty region object + regionList.emplace_front(x, y); + return ®ionList.front(); } //something to work on diff --git a/common/map/region_pager_lua.hpp b/common/map/region_pager_lua.hpp index 0b64b0a..bf2c039 100644 --- a/common/map/region_pager_lua.hpp +++ b/common/map/region_pager_lua.hpp @@ -28,6 +28,8 @@ #include #include +//DOCS: set the lua hook before use + class RegionPagerLua : public RegionPagerBase { public: RegionPagerLua() = default; diff --git a/common/graphics/tile_sheet.cpp b/common/map/tile_sheet.cpp similarity index 77% rename from common/graphics/tile_sheet.cpp rename to common/map/tile_sheet.cpp index 137b77a..2b458ca 100644 --- a/common/graphics/tile_sheet.cpp +++ b/common/map/tile_sheet.cpp @@ -21,6 +21,8 @@ */ #include "tile_sheet.hpp" +#include + TileSheet& TileSheet::operator=(TileSheet const& rhs) { //don't screw yourself if (this == &rhs) { @@ -81,25 +83,41 @@ void TileSheet::Free() { } void TileSheet::DrawLayerTo(SDL_Renderer* const renderer, Region* const region, int layer, int camX, int camY, double scaleX, double scaleY) { - //TODO: empty + //TODO: (2) empty } void TileSheet::DrawRegionTo(SDL_Renderer* const renderer, Region* const region, int camX, int camY, double scaleX, double scaleY) { - //TODO: (2) make TileSheet a friend class of Region + //NOTE: TileSheet is a friend class of Region + //reimplementing DrawTo() to improve performance (less indirection) + if (!texture) { + throw(std::logic_error("No image texture to draw")); + } + + //the local variables + SDL_Rect sclip = {0, 0, clip.w, clip.h}; + SDL_Rect dclip = {0, 0, Uint16(clip.w * scaleX), Uint16(clip.h * scaleY)}; Region::type_t tile = 0; + + //for each tile for (register int i = 0; i < REGION_WIDTH; ++i) { for (register int j = 0; j < REGION_HEIGHT; ++j) { for (register int k = 0; k < REGION_DEPTH; ++k) { - tile = region->GetTile(i, j, k); + //get the value to skip expensive lookups + tile = region->tiles[i][j][k]; + //0 is invisible if (tile == 0) continue; - clip.x = (tile-1) % countX * clip.h; - clip.y = (tile-1) / countX * clip.w; - //TODO: (2) raw rendering; improve preformance - Image::DrawTo(renderer, - (region->GetX() + i) * clip.w - camX, - (region->GetY() + j) * clip.h - camY, - scaleX, scaleY); + + //set the sclip + sclip.x = (tile-1) % countX * clip.h; + sclip.x = (tile-1) / countX * clip.w; + + //set the dclip + dclip.x = ((region->x + i) * clip.w - camX) * scaleX; + dclip.y = ((region->y + j) * clip.h - camY) * scaleY; + + //draw + SDL_RenderCopy(renderer, texture, &sclip, &dclip); } } } diff --git a/common/graphics/tile_sheet.hpp b/common/map/tile_sheet.hpp similarity index 98% rename from common/graphics/tile_sheet.hpp rename to common/map/tile_sheet.hpp index f327151..74affdf 100644 --- a/common/graphics/tile_sheet.hpp +++ b/common/map/tile_sheet.hpp @@ -47,7 +47,7 @@ public: void DrawRegionTo(SDL_Renderer* const renderer, Region* const region, int camX, int camY, double scaleX = 1.0, double scaleY = 1.0); //accessors - //DOCS: reuse Image::clip for tile sizes + //DOCS: Reuse Image::clip for tile sizes int GetCountX() { return countX; } int GetCountY() { return countY; } int GetTileW() { return clip.w; } From 48f5512e1a3b8e0d83e618605f65b86f661e8102 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Mon, 20 Jul 2015 17:14:24 +1000 Subject: [PATCH 06/39] Fixed a mistyped variable name --- common/map/tile_sheet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/map/tile_sheet.cpp b/common/map/tile_sheet.cpp index 2b458ca..bd18d0a 100644 --- a/common/map/tile_sheet.cpp +++ b/common/map/tile_sheet.cpp @@ -110,7 +110,7 @@ void TileSheet::DrawRegionTo(SDL_Renderer* const renderer, Region* const region, //set the sclip sclip.x = (tile-1) % countX * clip.h; - sclip.x = (tile-1) / countX * clip.w; + sclip.y = (tile-1) / countX * clip.w; //set the dclip dclip.x = ((region->x + i) * clip.w - camX) * scaleX; From aa9081d9cf88f172fd9e1fe2f8b45edf25f0fda4 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 2 Aug 2015 01:45:46 +1000 Subject: [PATCH 07/39] Imported new Button class, deleted menu_bar.*pp --- common/makefile | 2 +- common/ui/button.cpp | 165 +++++++++++++++++++++++++++++++---------- common/ui/button.hpp | 35 +++++---- common/ui/menu_bar.cpp | 139 ---------------------------------- common/ui/menu_bar.hpp | 88 ---------------------- 5 files changed, 148 insertions(+), 281 deletions(-) delete mode 100644 common/ui/menu_bar.cpp delete mode 100644 common/ui/menu_bar.hpp diff --git a/common/makefile b/common/makefile index 9fe752a..e2d1029 100644 --- a/common/makefile +++ b/common/makefile @@ -4,5 +4,5 @@ all: $(MAKE) -C graphics $(MAKE) -C map $(MAKE) -C network -# $(MAKE) -C ui + $(MAKE) -C ui $(MAKE) -C utilities diff --git a/common/ui/button.cpp b/common/ui/button.cpp index c794c09..21b8b47 100644 --- a/common/ui/button.cpp +++ b/common/ui/button.cpp @@ -23,59 +23,148 @@ #include -Button::State Button::MouseMotion(SDL_MouseMotionEvent const& motion) { - return CalcState(motion.x, motion.y, motion.state & SDL_BUTTON_LMASK); +void Button::DrawTo(SDL_Renderer* renderer) { + image.SetClipY(image.GetClipH() * state); + image.DrawTo(renderer, posX, posY); } -Button::State Button::MouseButtonDown(SDL_MouseButtonEvent const& button) { - if (button.button == SDL_BUTTON_LEFT) { - return CalcState(button.x, button.y, true); +void Button::SetBackgroundTexture(SDL_Renderer* renderer, SDL_Texture* texture) { + //copy the given texture + image.Free(); + + //a null texture can simply free the image + if (!texture) { + return; } - return state; + + //get the w & h, & create + int w = 0, h = 0; + SDL_QueryTexture(texture, nullptr, nullptr, &w, &h); + image.Create(renderer, w, h); + + //copy + SDL_SetRenderTarget(renderer, image.GetTexture()); + SDL_RenderCopy(renderer, texture, nullptr, nullptr); + SDL_SetRenderTarget(renderer, nullptr); + + //prune + image.SetClipH(image.GetClipH() / 3); } -Button::State Button::MouseButtonUp(SDL_MouseButtonEvent const& button) { - if (button.button == SDL_BUTTON_LEFT) { - return CalcState(button.x, button.y, false); +void Button::SetText(SDL_Renderer* renderer, TTF_Font* font, std::string s, SDL_Color color) { + //make the surface (from SDL_ttf) + SDL_Surface* surf = TTF_RenderText_Solid(font, s.c_str(), color); + if (!surf) { + throw(std::runtime_error("Failed to create a TTF surface")); } - return state; + + //convert to texture + SDL_Texture* text = SDL_CreateTextureFromSurface(renderer, surf); + SDL_FreeSurface(surf); + if (!text) { + throw(std::runtime_error("Failed to create a TTF texture")); + } + + //get the dimensions & rects + int x, y, w, h; + SDL_QueryTexture(text, nullptr, nullptr, &w, &h); + x = (image.GetClipW() - w) / 2; + y = (image.GetClipH() - h) / 2; + SDL_Rect src = {0, 0, w, h}; + SDL_Rect dst; + + //draw the text to the background + SDL_SetRenderTarget(renderer, image.GetTexture()); + + for (int i = 0; i < 3; i++) { + dst = {x, y + image.GetClipH() * i, w, h}; + SDL_RenderCopy(renderer, text, &src, &dst); + } + + SDL_SetRenderTarget(renderer, nullptr); + + //free the texture + SDL_DestroyTexture(text); + + //DEBUG: testing +// image.SetClipH(image.GetClipH() * 3); } -void Button::DrawTo(SDL_Surface* const dest) { - if (!image || !font) { - throw(std::runtime_error("Surface not set for Button")); - } - image->SetClipY(state * image->GetClipH()); - image->DrawTo(dest, x, y); - font->DrawStringTo(text, dest, textX + x, textY + y); +void Button::SetX(int x) { + posX = x; } -std::string Button::SetText(std::string t) { - if (!image || !font) { - throw(std::runtime_error("Surface not set for Button")); - } - //one line, cache the position - text = t; - textX = (image->GetClipW() / 2) - (font->GetCharW() * text.size() / 2); - textY = (image->GetClipH() / 2) - (font->GetCharH() / 2); - return text; +void Button::SetY(int y) { + posY = y; } -Button::State Button::CalcState(Sint16 i, Sint16 j, bool leftPressed) { - if (!image || !font) { - throw(std::runtime_error("Surface not set for Button")); - } - //if out of bounds - if (i < x || i >= (x + image->GetClipW()) || - j < y || j >= (y + image->GetClipH()) - ) { - return state = State::NORMAL; +Button::State Button::MouseMotion(SDL_MouseMotionEvent const& event) { + //if out of bounds, exit + if (!CheckBounds(event.x, event.y)) { + return state = State::IDLE; } - if (leftPressed) { - return state = State::PRESSED; + //if in bounds, check button + if (event.state & SDL_BUTTON_LMASK && state == State::PRESSED) { + //stay pressed +// state = State::PRESSED; } else { - return state = State::HOVER; + state = State::HOVER; } + + return state; } + +Button::State Button::MouseButtonDown(SDL_MouseButtonEvent const& event) { + //if out of bounds, exit + if (!CheckBounds(event.x, event.y)) { + return state = State::IDLE; + } + + //if in bounds, check button + if (event.button == SDL_BUTTON_LEFT) { + return state = State::PRESSED; + } + + //NOTE: if not left button down, ignore + return State::HOVER; +} + +Button::State Button::MouseButtonUp(SDL_MouseButtonEvent const& event) { + //if out of bounds, exit + if (!CheckBounds(event.x, event.y)) { + return state = State::IDLE; + } + + //if not left button up, ignore + if (event.button != SDL_BUTTON_LEFT) { + return state; + } + + //if in bounds and left button up, send release signal + if (state == State::PRESSED) { + state = State::HOVER; + return State::RELEASED; + } + + return state; +} + +void Button::SetState(State s) { + state = s; +} + +Button::State Button::GetState() { + return state; +} + +bool Button::CheckBounds(int x, int y) { + //return if true (x, y) is within bounds, otherwise return false + return !( + x < posX || + y < posY || + x > posX + image.GetClipW() || + y > posY + image.GetClipH() + ); +} \ No newline at end of file diff --git a/common/ui/button.hpp b/common/ui/button.hpp index 16b6cac..71b8e02 100644 --- a/common/ui/button.hpp +++ b/common/ui/button.hpp @@ -21,7 +21,6 @@ */ #pragma once -#include "bounding_box.hpp" #include "image.hpp" #include "SDL2/SDL_ttf.h" @@ -30,29 +29,35 @@ class Button { public: - //states available - enum class State { - NORMAL, HOVER, PRESSED + enum State { + IDLE = 0, HOVER = 1, PRESSED = 2, RELEASED = 3 }; //methods Button() = default; ~Button() = default; - void RenderText(std::string s); - bool CaptureInput(int x, int y, bool pressed); - void DrawTo(SDL_Renderer*, int camX, int camY); + void DrawTo(SDL_Renderer*); - //accessors & mutators - int SetX(int x) { return posX = x; } - int SetY(int y) { return posY = y; } - int GetX() { return posX; } - int GetY() { return posY; } - Image* GetImage() { return ℑ } - BoundingBox* GetBoundingBox() { return &boundingBox; } + //setup + void SetBackgroundTexture(SDL_Renderer*, SDL_Texture*); + void SetText(SDL_Renderer*, TTF_Font*, std::string, SDL_Color); + void SetX(int x); + void SetY(int y); + + //capture input + State MouseMotion(SDL_MouseMotionEvent const&); + State MouseButtonDown(SDL_MouseButtonEvent const&); + State MouseButtonUp(SDL_MouseButtonEvent const&); + + //states + void SetState(State); //TODO: idle, busy or disabled + State GetState(); protected: + bool CheckBounds(int x, int y); + Image image; - BoundingBox boundingBox; int posX = 0, posY = 0; + State state = State::IDLE; }; diff --git a/common/ui/menu_bar.cpp b/common/ui/menu_bar.cpp deleted file mode 100644 index 45358cc..0000000 --- a/common/ui/menu_bar.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. -*/ -#include "menu_bar.hpp" - -#include -#include - -void MenuBar::DrawTo(SDL_Surface* const dest) { - for (auto& i : entries) { - i.DrawTo(dest); - } -} - -void MenuBar::MouseMotion(SDL_MouseMotionEvent const& motion) { - for (auto& i : entries) { - i.MouseMotion(motion); - } -} - -void MenuBar::MouseButtonDown(SDL_MouseButtonEvent const& button) { - for (auto& i : entries) { - i.MouseButtonDown(button); - } -} - -void MenuBar::MouseButtonUp(SDL_MouseButtonEvent const& button, int* entry, int* butt) { - *entry = *butt = -1; - int ret = -1; - for (auto& i : entries) { - ret = i.MouseButtonUp(button); - - if (ret != -1) { - *entry = (&i - entries.data()); - *butt = ret; - } - } -} - -void MenuBar::SetEntries(std::vector> info) { - if (!image || !font) { - throw(std::runtime_error("Surfaces not loaded into the menu bar")); - } - - entries.clear(); - for (int i = 0; i < info.size(); i++) { - //create the entry & the main button - entries.push_back(MenuBarEntry()); - entries[i].mainButton.SetImage(image); - entries[i].mainButton.SetFont(font); - entries[i].mainButton.SetText(info[i][0]); - entries[i].mainButton.SetX(i * image->GetClipW()); - entries[i].mainButton.SetY(0); - for (int j = 0; j < info[i].size()-1; j++) { - //create each drop button in this entry - entries[i].dropButtons.push_back(Button()); - entries[i].dropButtons[j].SetImage(image); - entries[i].dropButtons[j].SetFont(font); - entries[i].dropButtons[j].SetText(info[i][j+1]); - entries[i].dropButtons[j].SetX(i * image->GetClipW()); - entries[i].dropButtons[j].SetY((j+1) * image->GetClipH()); - } - } -} - -void MenuBar::MenuBarEntry::DrawTo(SDL_Surface* const dest) { - //only draw the dropButtons in the user has this menu open - mainButton.DrawTo(dest); - - if (!open) { - return; - } - - for (auto& i : dropButtons) { - i.DrawTo(dest); - } -} - -void MenuBar::MenuBarEntry::MouseMotion(SDL_MouseMotionEvent const& motion) { - //open the menu - bool o = mainButton.MouseMotion(motion) == Button::State::PRESSED; - - if (!(open |= o)) { - return; - } - - for (auto& i : dropButtons) { - //dragging down the menu - o |= i.MouseMotion(motion) == Button::State::PRESSED; - } - - open = o; -} - -void MenuBar::MenuBarEntry::MouseButtonDown(SDL_MouseButtonEvent const& button) { - //open the menu - if (!(open = mainButton.MouseButtonDown(button) == Button::State::PRESSED)) { - return; - } - - //update the others anyway - for (auto& i : dropButtons) { - i.MouseButtonDown(button); - } -} - -int MenuBar::MenuBarEntry::MouseButtonUp(SDL_MouseButtonEvent const& button) { - int ret = -1; - mainButton.MouseButtonUp(button); - - for (auto& i : dropButtons) { - //the user just released this button - if (i.GetState() != i.MouseButtonUp(button) && i.GetState() == Button::State::HOVER && open) { - //get this button's index - ret = (&i - dropButtons.data()); - } - } - - open = false; - return ret; -} diff --git a/common/ui/menu_bar.hpp b/common/ui/menu_bar.hpp deleted file mode 100644 index fa01f9c..0000000 --- a/common/ui/menu_bar.hpp +++ /dev/null @@ -1,88 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013-2015 - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. -*/ -#pragma once - -#include "image.hpp" -#include "button.hpp" - -#include -#include - -/* I've redesigned this so that the contents of the menu bar can't change during run time. - * This is more restrictive but I'm focusing on getting this working first. - * The Image and Font pointers must be set before the text data is entered. - * - * This class needs a rewrite. -*/ - -//TODO: This thing is fucking terrible, fix it and the button class -class MenuBar { -public: - MenuBar() = default; - ~MenuBar() = default; - - //yet another draw function - void DrawTo(SDL_Surface* const dest); - - //user inputs - void MouseMotion(SDL_MouseMotionEvent const&); - void MouseButtonDown(SDL_MouseButtonEvent const&); - void MouseButtonUp(SDL_MouseButtonEvent const&, int* entry, int* button); - - //manage the entries & buttons - void SetEntries(std::vector> info); - void ClearEntries() { entries.clear(); } - - //Accessors and mutators - Image* SetImage(Image* const ptr) { return image = ptr; } - Image* GetImage() { return image; } - RasterFont* SetFont(RasterFont* const ptr) { return font = ptr; } - RasterFont* GetFont() { return font; } - -private: - class MenuBarEntry; - - std::vector entries; - - Image* image = nullptr; - RasterFont* font = nullptr; -}; - -class MenuBar::MenuBarEntry { -public: - MenuBarEntry() = default; - ~MenuBarEntry() = default; - - void DrawTo(SDL_Surface* const dest); - - void MouseMotion(SDL_MouseMotionEvent const&); - void MouseButtonDown(SDL_MouseButtonEvent const&); - int MouseButtonUp(SDL_MouseButtonEvent const&); - -private: - Button mainButton; - - std::vector