From 3d6509b5a5b36ad1eb647b3d3564b0148485db30 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Thu, 20 Aug 2015 20:45:13 +1000 Subject: [PATCH] Client builds & runs, can't test the gameplay without the server SDL_ttf is now being initialized, and all usages of fonts are now checked for nullptr. A bug where the renderer's logical size was not properly set has been fixed. The FPS counter is disabled for now. --- client/client_application.cpp | 21 +++++++++++++++++--- client/client_application.hpp | 2 ++ client/gameplay_scenes/makefile | 5 +---- client/gameplay_scenes/world_characters.cpp | 9 +++++---- client/gameplay_scenes/world_connections.cpp | 6 +++--- client/gameplay_scenes/world_logic.cpp | 11 ++++++++++ client/gameplay_scenes/world_map.cpp | 2 +- client/gameplay_scenes/world_monsters.cpp | 4 ++-- client/makefile | 2 +- client/menu_scenes/disconnected_screen.cpp | 12 +++++++++++ client/menu_scenes/lobby_menu.cpp | 7 +++++++ client/menu_scenes/main_menu.cpp | 21 ++++++++++++++++++-- client/menu_scenes/options_menu.cpp | 14 +++++++++++++ client/menu_scenes/splash_screen.cpp | 4 +++- common | 2 +- 15 files changed, 100 insertions(+), 22 deletions(-) diff --git a/client/client_application.cpp b/client/client_application.cpp index a713248..dd908c0 100644 --- a/client/client_application.cpp +++ b/client/client_application.cpp @@ -44,11 +44,16 @@ void ClientApplication::Init(int argc, char* argv[]) { //create and check the window //------------------------- + //get the config values int w = config.Int("client.screen.w"); int h = config.Int("client.screen.h"); int f = config.Bool("client.screen.f") ? SDL_WINDOW_FULLSCREEN : 0; - window = SDL_CreateWindow(argv[0], SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, w ? w : 800, h ? h : 600, f); + //default sizes + w = w ? w : 800; + h = h ? h : 600; + + window = SDL_CreateWindow(argv[0], SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, w, h, f); if (!window) { std::ostringstream msg; @@ -86,12 +91,21 @@ void ClientApplication::Init(int argc, char* argv[]) { //initialize SDL_net if (SDLNet_Init()) { std::ostringstream msg; - msg << "Failed to initialize SDL_net: " << SDL_GetError(); + msg << "Failed to initialize SDL_net 2.0: " << SDL_GetError(); throw(std::runtime_error(msg.str())); } UDPNetworkUtility::GetSingleton().Open(0); - std::cout << "Initialized SDL_net" << std::endl; + std::cout << "Initialized SDL_net 2.0" << std::endl; + + //setting up SDL2_ttf + if (TTF_Init()) { + std::ostringstream msg; + msg << "Failed to initialize SDL_ttf 2.0: " << SDL_GetError(); + throw(std::runtime_error(msg.str())); + } + + std::cout << "Initialized SDL_ttf 2.0" << std::endl; //------------------------- //debug output @@ -181,6 +195,7 @@ void ClientApplication::Quit() { //clean up after the program std::cout << "Shutting down" << std::endl; UDPNetworkUtility::GetSingleton().Close(); + TTF_Quit(); SDLNet_Quit(); BaseScene::SetRenderer(nullptr); SDL_DestroyRenderer(renderer); diff --git a/client/client_application.hpp b/client/client_application.hpp index 43c421d..af59b14 100644 --- a/client/client_application.hpp +++ b/client/client_application.hpp @@ -27,6 +27,8 @@ #include "udp_network_utility.hpp" #include "SDL2/SDL.h" +#include "SDL2/SDL_net.h" +#include "SDL2/SDL_ttf.h" class ClientApplication: public Singleton { public: diff --git a/client/gameplay_scenes/makefile b/client/gameplay_scenes/makefile index a19ca62..40fc4ee 100644 --- a/client/gameplay_scenes/makefile +++ b/client/gameplay_scenes/makefile @@ -6,9 +6,6 @@ CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) #source CXXSRC=$(wildcard *.cpp) -#DEBUG: Overwrite the wildcard -CXXSRC=world_logic.cpp - #objects OBJDIR=obj OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) @@ -19,7 +16,7 @@ OUT=$(addprefix $(OUTDIR)/,client.a) #targets all: $(OBJ) $(OUT) -# ar -crs $(OUT) $(OBJ) + ar -crs $(OUT) $(OBJ) $(OBJ): | $(OBJDIR) diff --git a/client/gameplay_scenes/world_characters.cpp b/client/gameplay_scenes/world_characters.cpp index 377bc05..74fc3bc 100644 --- a/client/gameplay_scenes/world_characters.cpp +++ b/client/gameplay_scenes/world_characters.cpp @@ -69,7 +69,7 @@ void World::hCharacterCreate(CharacterPacket* const argPacket) { //fill the character's info character->SetHandle(argPacket->handle); - character->SetAvatar(argPacket->avatar); + character->SetAvatar(GetRenderer(), argPacket->avatar); character->SetOwner(argPacket->accountIndex); character->SetOrigin(argPacket->origin); character->SetMotion(argPacket->motion); @@ -82,8 +82,8 @@ void World::hCharacterCreate(CharacterPacket* const argPacket) { localCharacter = static_cast(character); //focus the camera on this character's sprite - camera.marginX = (camera.width / 2 - localCharacter->GetSprite()->GetImage()->GetClipW() / 2); - camera.marginY = (camera.height/ 2 - localCharacter->GetSprite()->GetImage()->GetClipH() / 2); + camera.marginX = (camera.width / 2 - localCharacter->GetSprite()->GetClipW() / 2); + camera.marginY = (camera.height/ 2 - localCharacter->GetSprite()->GetClipH() / 2); //focus on this character's info characterIndex = argPacket->characterIndex; @@ -135,6 +135,7 @@ void World::hCharacterDelete(CharacterPacket* const argPacket) { void World::hQueryCharacterExists(CharacterPacket* const argPacket) { //prevent a double message about this player's character + //TODO: why is this commented out? // if (argPacket->accountIndex == accountIndex) { // return; // } @@ -152,7 +153,7 @@ void World::hQueryCharacterExists(CharacterPacket* const argPacket) { character->SetMotion(argPacket->motion); character->SetBounds({CHARACTER_BOUNDS_X, CHARACTER_BOUNDS_Y, CHARACTER_BOUNDS_WIDTH, CHARACTER_BOUNDS_HEIGHT}); character->SetHandle(argPacket->handle); - character->SetAvatar(argPacket->avatar); + character->SetAvatar(GetRenderer(), argPacket->avatar); character->SetOwner(argPacket->accountIndex); character->CorrectSprite(); diff --git a/client/gameplay_scenes/world_connections.cpp b/client/gameplay_scenes/world_connections.cpp index fb30f96..7e6a1fa 100644 --- a/client/gameplay_scenes/world_connections.cpp +++ b/client/gameplay_scenes/world_connections.cpp @@ -52,7 +52,7 @@ void World::CheckHeartBeat() { if (attemptedBeats > 2) { //escape to the disconnect screen SendDisconnectRequest(); - SetNextScene(SceneList::DISCONNECTEDSCREEN); + SetSceneSignal(SceneSignal::DISCONNECTEDSCREEN); ConfigUtility::GetSingleton()["client.disconnectMessage"] = "Error: Lost connection to the server"; } else { @@ -122,13 +122,13 @@ void World::hLogoutResponse(ClientPacket* const argPacket) { void World::hDisconnectResponse(ClientPacket* const argPacket) { hLogoutResponse(argPacket);//shortcut - SetNextScene(SceneList::DISCONNECTEDSCREEN); + SetSceneSignal(SceneSignal::DISCONNECTEDSCREEN); ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have successfully logged out"; } void World::hAdminDisconnectForced(ClientPacket* const argPacket) { hDisconnectResponse(argPacket);//shortcut - SetNextScene(SceneList::DISCONNECTEDSCREEN); + SetSceneSignal(SceneSignal::DISCONNECTEDSCREEN); ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have been forcibly disconnected by the server"; } diff --git a/client/gameplay_scenes/world_logic.cpp b/client/gameplay_scenes/world_logic.cpp index 8cce181..e47f275 100644 --- a/client/gameplay_scenes/world_logic.cpp +++ b/client/gameplay_scenes/world_logic.cpp @@ -43,6 +43,13 @@ World::World(int* const argClientIndex, int* const argAccountIndex): buttonImage.Load(GetRenderer(), config["dir.interface"] + "button.png"); font = TTF_OpenFont(config["client.font"].c_str(), 12); + //check that the font loaded + if (!font) { + std::ostringstream msg; + msg << "Failed to load a font file; " << SDL_GetError(); + throw(std::runtime_error(msg.str())); + } + //setup the buttons disconnectButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture()); disconnectButton.SetText(GetRenderer(), font, "Disconnect", {255, 255, 255, 255}); @@ -216,6 +223,10 @@ void World::MouseButtonUp(SDL_MouseButtonEvent const& event) { } } +void World::MouseWheel(SDL_MouseWheelEvent const& event) { + // +} + void World::KeyDown(SDL_KeyboardEvent const& key) { //hotkeys switch(key.keysym.sym) { diff --git a/client/gameplay_scenes/world_map.cpp b/client/gameplay_scenes/world_map.cpp index 1265281..d2651fe 100644 --- a/client/gameplay_scenes/world_map.cpp +++ b/client/gameplay_scenes/world_map.cpp @@ -103,7 +103,7 @@ void World::UpdateMap() { } else if (regionChecksum(region) == 0) { //checksum failed - //NOTE: this patches bug #45, but does not resolve it + //BUG: #45 Regions occasionally lose their tile data; this patches the issue, but does not resolve it regionPager.UnloadIf([region](Region const& ref) -> bool { //remove the erroneous region return region == &ref; diff --git a/client/gameplay_scenes/world_monsters.cpp b/client/gameplay_scenes/world_monsters.cpp index ada5786..b4f932c 100644 --- a/client/gameplay_scenes/world_monsters.cpp +++ b/client/gameplay_scenes/world_monsters.cpp @@ -55,7 +55,7 @@ void World::hMonsterCreate(MonsterPacket* const argPacket) { //fill the monster's info monster->SetHandle(argPacket->handle); - monster->SetAvatar(argPacket->avatar); + monster->SetAvatar(GetRenderer(), argPacket->avatar); monster->SetBounds(argPacket->bounds); monster->SetOrigin(argPacket->origin); monster->SetMotion(argPacket->motion); @@ -89,7 +89,7 @@ void World::hQueryMonsterExists(MonsterPacket* const argPacket) { //fill the monster's info monster->SetHandle(argPacket->handle); - monster->SetAvatar(argPacket->avatar); + monster->SetAvatar(GetRenderer(), argPacket->avatar); monster->SetBounds(argPacket->bounds); monster->SetOrigin(argPacket->origin); monster->SetMotion(argPacket->motion); diff --git a/client/makefile b/client/makefile index 1b70607..1bf8ddb 100644 --- a/client/makefile +++ b/client/makefile @@ -33,7 +33,7 @@ all: $(OBJ) $(OUT) $(MAKE) -C entities $(MAKE) -C gameplay_scenes $(MAKE) -C menu_scenes -# $(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS) + $(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS) $(OBJ): | $(OBJDIR) diff --git a/client/menu_scenes/disconnected_screen.cpp b/client/menu_scenes/disconnected_screen.cpp index 0a5e655..f68f3f3 100644 --- a/client/menu_scenes/disconnected_screen.cpp +++ b/client/menu_scenes/disconnected_screen.cpp @@ -25,6 +25,7 @@ #include "config_utility.hpp" #include "udp_network_utility.hpp" +#include #include //------------------------- @@ -39,6 +40,13 @@ DisconnectedScreen::DisconnectedScreen() { image.Load(GetRenderer(), config["dir.interface"] + "button.png"); font = TTF_OpenFont(config["client.font"].c_str(), 12); + //check that the font loaded + if (!font) { + std::ostringstream msg; + msg << "Failed to load a font file; " << SDL_GetError(); + throw(std::runtime_error(msg.str())); + } + //setup the button backButton.SetBackgroundTexture(GetRenderer(), image.GetTexture()); backButton.SetText(GetRenderer(), font, "Back", {255, 255, 255, 255}); @@ -105,6 +113,10 @@ void DisconnectedScreen::MouseButtonUp(SDL_MouseButtonEvent const& event) { } } +void DisconnectedScreen::MouseWheel(SDL_MouseWheelEvent const& event) { + // +} + void DisconnectedScreen::KeyDown(SDL_KeyboardEvent const& event) { switch(event.keysym.sym) { case SDLK_ESCAPE: diff --git a/client/menu_scenes/lobby_menu.cpp b/client/menu_scenes/lobby_menu.cpp index be12984..7215a63 100644 --- a/client/menu_scenes/lobby_menu.cpp +++ b/client/menu_scenes/lobby_menu.cpp @@ -42,6 +42,13 @@ LobbyMenu::LobbyMenu(int* const argClientIndex, int* const argAccountIndex): buttonImage.Load(GetRenderer(), config["dir.interface"] + "button.png"); font = TTF_OpenFont(config["client.font"].c_str(), 12); + //check that the font loaded + if (!font) { + std::ostringstream msg; + msg << "Failed to load a font file; " << SDL_GetError(); + throw(std::runtime_error(msg.str())); + } + //setup the buttons searchButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture()); searchButton.SetText(GetRenderer(), font, "Search", {255, 255, 255, 255}); diff --git a/client/menu_scenes/main_menu.cpp b/client/menu_scenes/main_menu.cpp index aac2d18..11b5f5d 100644 --- a/client/menu_scenes/main_menu.cpp +++ b/client/menu_scenes/main_menu.cpp @@ -23,6 +23,9 @@ #include "config_utility.hpp" +#include +#include + //------------------------- //Public access members //------------------------- @@ -34,6 +37,13 @@ MainMenu::MainMenu() { buttonImage.Load(GetRenderer(), config["dir.interface"] + "button.png"); font = TTF_OpenFont(config["client.font"].c_str(), 12); + //check that the font loaded + if (!font) { + std::ostringstream msg; + msg << "Failed to load a font file; " << SDL_GetError(); + throw(std::runtime_error(msg.str())); + } + //setup the buttons startButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture()); startButton.SetText(GetRenderer(), font, "Start", {255, 255, 255, 255}); @@ -53,7 +63,7 @@ MainMenu::MainMenu() { //text box textBox.PushLine(GetRenderer(), font, "Thanks for playing!", {255, 255, 255, 255}); textBox.PushLine(GetRenderer(), font, "You can get the latest version at: ", {255, 255, 255, 255}); - textBox.PushLine(GetRenderer(), font, "krgamestudios.com", {255, 255, 255, 255}); + textBox.PushLine(GetRenderer(), font, "krgamestudios.com", {255, 255, 255, 255}); //TODO: click to open the website/update //debug // @@ -84,7 +94,10 @@ void MainMenu::RenderFrame(SDL_Renderer* renderer) { optionsButton.DrawTo(renderer); quitButton.DrawTo(renderer); - textBox.DrawTo(renderer, 50, 50, 12); + int h = -1; + SDL_RenderGetLogicalSize(GetRenderer(), nullptr, &h); + + textBox.DrawTo(renderer, 50, h-50, -12); } //------------------------- @@ -116,6 +129,10 @@ void MainMenu::MouseButtonUp(SDL_MouseButtonEvent const& event) { } } +void MainMenu::MouseWheel(SDL_MouseWheelEvent const& event) { + // +} + void MainMenu::KeyDown(SDL_KeyboardEvent const& event) { // } diff --git a/client/menu_scenes/options_menu.cpp b/client/menu_scenes/options_menu.cpp index 96863b3..499ea1e 100644 --- a/client/menu_scenes/options_menu.cpp +++ b/client/menu_scenes/options_menu.cpp @@ -23,6 +23,9 @@ #include "config_utility.hpp" +#include +#include + //------------------------- //Public access members //------------------------- @@ -34,6 +37,13 @@ OptionsMenu::OptionsMenu() { buttonImage.Load(GetRenderer(), config["dir.interface"] + "button.png"); font = TTF_OpenFont(config["client.font"].c_str(), 12); + //check that the font loaded + if (!font) { + std::ostringstream msg; + msg << "Failed to load a font file; " << SDL_GetError(); + throw(std::runtime_error(msg.str())); + } + //setup the button backButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture()); backButton.SetText(GetRenderer(), font, "Back", {255, 255, 255, 255}); @@ -89,6 +99,10 @@ void OptionsMenu::MouseButtonUp(SDL_MouseButtonEvent const& event) { } } +void OptionsMenu::MouseWheel(SDL_MouseWheelEvent const& event) { + // +} + void OptionsMenu::KeyDown(SDL_KeyboardEvent const& event) { switch(event.keysym.sym) { case SDLK_ESCAPE: diff --git a/client/menu_scenes/splash_screen.cpp b/client/menu_scenes/splash_screen.cpp index 9fefd4a..5ba3f26 100644 --- a/client/menu_scenes/splash_screen.cpp +++ b/client/menu_scenes/splash_screen.cpp @@ -28,6 +28,7 @@ //------------------------- SplashScreen::SplashScreen() { + //TODO: I need a logo that isn't partially invisible logo.Load(GetRenderer(), ConfigUtility::GetSingleton()["dir.logos"] + "krstudios.png"); startTick = std::chrono::steady_clock::now(); } @@ -49,5 +50,6 @@ void SplashScreen::FrameStart() { void SplashScreen::RenderFrame(SDL_Renderer* renderer) { int w = 0, h = 0; SDL_RenderGetLogicalSize(renderer, &w, &h); - logo.DrawTo(renderer, (w - logo.GetClipW()) / 2, (h - logo.GetClipH()) / 2); + //TODO: fix logo position + logo.DrawTo(renderer, (w - logo.GetClipW() / 4) / 2, (h - logo.GetClipH() / 4) / 2, .25, .25); } diff --git a/common b/common index 345980a..03e643a 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 345980af5ed1080317bc671c852bb6e92c5d0ba1 +Subproject commit 03e643a17a881f9ecc13c6b28db8fd9d1da23d16