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.
This commit is contained in:
2015-08-20 20:45:13 +10:00
parent dc5b09a9b4
commit 3d6509b5a5
15 changed files with 100 additions and 22 deletions
+18 -3
View File
@@ -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);
+2
View File
@@ -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<ClientApplication> {
public:
+1 -4
View File
@@ -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)
+5 -4
View File
@@ -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<LocalCharacter*>(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();
+3 -3
View File
@@ -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";
}
+11
View File
@@ -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) {
+1 -1
View File
@@ -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;
+2 -2
View File
@@ -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);
+1 -1
View File
@@ -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)
@@ -25,6 +25,7 @@
#include "config_utility.hpp"
#include "udp_network_utility.hpp"
#include <sstream>
#include <stdexcept>
//-------------------------
@@ -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:
+7
View File
@@ -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});
+19 -2
View File
@@ -23,6 +23,9 @@
#include "config_utility.hpp"
#include <sstream>
#include <stdexcept>
//-------------------------
//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) {
//
}
+14
View File
@@ -23,6 +23,9 @@
#include "config_utility.hpp"
#include <sstream>
#include <stdexcept>
//-------------------------
//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:
+3 -1
View File
@@ -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);
}
+1 -1
Submodule common updated: 345980af5e...03e643a17a