world_logic.cpp builds, disabled FPS display

This commit is contained in:
2015-08-20 02:36:42 +10:00
parent 371ca4a22c
commit dc5b09a9b4
6 changed files with 50 additions and 49 deletions
+4 -1
View File
@@ -6,6 +6,9 @@ CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
#source #source
CXXSRC=$(wildcard *.cpp) CXXSRC=$(wildcard *.cpp)
#DEBUG: Overwrite the wildcard
CXXSRC=world_logic.cpp
#objects #objects
OBJDIR=obj OBJDIR=obj
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
@@ -16,7 +19,7 @@ OUT=$(addprefix $(OUTDIR)/,client.a)
#targets #targets
all: $(OBJ) $(OUT) all: $(OBJ) $(OUT)
ar -crs $(OUT) $(OBJ) # ar -crs $(OUT) $(OBJ)
$(OBJ): | $(OBJDIR) $(OBJ): | $(OBJDIR)
+8 -2
View File
@@ -42,6 +42,10 @@
#include "base_monster.hpp" #include "base_monster.hpp"
#include "local_character.hpp" #include "local_character.hpp"
#include "SDL2/SDL.h"
#include "SDL2/SDL_net.h"
#include "SDL2/SDL_ttf.h"
//STL //STL
#include <map> #include <map>
@@ -62,6 +66,7 @@ private:
void FrameEnd() override; void FrameEnd() override;
//input events //input events
void QuitEvent();
void MouseMotion(SDL_MouseMotionEvent const& event) override; void MouseMotion(SDL_MouseMotionEvent const& event) override;
void MouseButtonDown(SDL_MouseButtonEvent const& event) override; void MouseButtonDown(SDL_MouseButtonEvent const& event) override;
void MouseButtonUp(SDL_MouseButtonEvent const& event) override; void MouseButtonUp(SDL_MouseButtonEvent const& event) override;
@@ -130,15 +135,16 @@ private:
int roomIndex = -1; int roomIndex = -1;
//graphics //graphics
Image buttonImage;
TileSheet tileSheet; TileSheet tileSheet;
//map //map
RegionPagerBase regionPager; RegionPagerBase regionPager;
//UI //UI
Image buttonImage;
TTF_Font* font = nullptr;
Button disconnectButton; Button disconnectButton;
Button shutDownButton; Button shutdownButton;
FrameRate fps; FrameRate fps;
//the camera structure //the camera structure
+34 -42
View File
@@ -40,29 +40,24 @@ World::World(int* const argClientIndex, int* const argAccountIndex):
accountIndex(*argAccountIndex) accountIndex(*argAccountIndex)
{ {
//setup the utility objects //setup the utility objects
buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp"); buttonImage.Load(GetRenderer(), config["dir.interface"] + "button.png");
buttonImage.SetClipH(buttonImage.GetClipH()/3); font = TTF_OpenFont(config["client.font"].c_str(), 12);
font.LoadSurface(config["dir.fonts"] + "pk_white_8.bmp");
//pass the utility objects //setup the buttons
disconnectButton.SetImage(&buttonImage); disconnectButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
disconnectButton.SetFont(&font); disconnectButton.SetText(GetRenderer(), font, "Disconnect", {255, 255, 255, 255});
shutDownButton.SetImage(&buttonImage); shutdownButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
shutDownButton.SetFont(&font); shutdownButton.SetText(GetRenderer(), font, "Shutdown", {255, 255, 255, 255});
//set the button positions //set the button positions
disconnectButton.SetX(50); disconnectButton.SetX(50);
disconnectButton.SetY(50 + buttonImage.GetClipH() * 0); disconnectButton.SetY(50 + buttonImage.GetClipH() * 0);
shutDownButton.SetX(50); shutdownButton.SetX(50);
shutDownButton.SetY(50 + buttonImage.GetClipH() * 1); shutdownButton.SetY(50 + buttonImage.GetClipH() * 1);
//set the button texts
disconnectButton.SetText("Disconnect");
shutDownButton.SetText("Shut Down");
//load the tilesheet //load the tilesheet
//TODO: (2) Tile size and tile sheet should be loaded elsewhere //TODO: (2) Tile size and tile sheet should be loaded elsewhere
tileSheet.Load(config["dir.tilesets"] + "overworld.bmp", 32, 32); tileSheet.Load(GetRenderer(), config["dir.tilesets"] + "overworld.bmp", 32, 32);
//Send the character data //Send the character data
CharacterPacket newPacket; CharacterPacket newPacket;
@@ -73,8 +68,7 @@ World::World(int* const argClientIndex, int* const argAccountIndex):
network.SendTo(Channels::SERVER, &newPacket); network.SendTo(Channels::SERVER, &newPacket);
//set the camera's values //set the camera's values
camera.width = GetScreen()->w; SDL_RenderGetLogicalSize(GetRenderer(), &camera.width, &camera.height);
camera.height = GetScreen()->h;
//debug //debug
// //
@@ -82,6 +76,7 @@ World::World(int* const argClientIndex, int* const argAccountIndex):
World::~World() { World::~World() {
//unload the local data //unload the local data
TTF_CloseFont(font);
characterMap.clear(); characterMap.clear();
monsterMap.clear(); monsterMap.clear();
} }
@@ -160,17 +155,10 @@ void World::FrameEnd() {
// //
} }
void World::RenderFrame() { void World::RenderFrame(SDL_Renderer* renderer) {
// SDL_FillRect(GetScreen(), 0, 0);
Render(GetScreen());
SDL_Flip(GetScreen());
fps.Calculate();
}
void World::Render(SDL_Surface* const screen) {
//draw the map //draw the map
for (std::list<Region>::iterator it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); it++) { for (std::list<Region>::iterator it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); it++) {
tileSheet.DrawRegionTo(screen, &(*it), camera.x, camera.y); tileSheet.DrawRegionTo(renderer, &(*it), camera.x, camera.y);
//debugging //debugging
// std::ostringstream msg; // std::ostringstream msg;
@@ -181,18 +169,22 @@ void World::Render(SDL_Surface* const screen) {
//draw the entities //draw the entities
for (auto& it : characterMap) { for (auto& it : characterMap) {
//BUG: #29 Characters (and other entities) are drawn out of order //BUG: #29 Characters (and other entities) are drawn out of order
it.second.DrawTo(screen, camera.x, camera.y); it.second.DrawTo(renderer, camera.x, camera.y);
} }
for (auto& it : monsterMap) { for (auto& it : monsterMap) {
it.second.DrawTo(screen, camera.x, camera.y); it.second.DrawTo(renderer, camera.x, camera.y);
} }
//draw UI //draw UI
disconnectButton.DrawTo(screen); disconnectButton.DrawTo(renderer);
shutDownButton.DrawTo(screen); shutdownButton.DrawTo(renderer);
std::ostringstream msg; std::ostringstream msg;
msg << fps.GetFrameRate(); //TODO: FPS
font.DrawStringTo(msg.str(), screen, 0, 0); // msg << fps.GetFrameRate();
// font.DrawStringTo(msg.str(), screen, 0, 0);
//FPS
fps.Calculate();
} }
//------------------------- //-------------------------
@@ -202,24 +194,24 @@ void World::Render(SDL_Surface* const screen) {
void World::QuitEvent() { void World::QuitEvent() {
//two-step logout //two-step logout
SendDisconnectRequest(); SendDisconnectRequest();
SetNextScene(SceneList::QUIT); SetSceneSignal(SceneSignal::QUIT);
} }
void World::MouseMotion(SDL_MouseMotionEvent const& motion) { void World::MouseMotion(SDL_MouseMotionEvent const& event) {
disconnectButton.MouseMotion(motion); disconnectButton.MouseMotion(event);
shutDownButton.MouseMotion(motion); shutdownButton.MouseMotion(event);
} }
void World::MouseButtonDown(SDL_MouseButtonEvent const& button) { void World::MouseButtonDown(SDL_MouseButtonEvent const& event) {
disconnectButton.MouseButtonDown(button); disconnectButton.MouseButtonDown(event);
shutDownButton.MouseButtonDown(button); shutdownButton.MouseButtonDown(event);
} }
void World::MouseButtonUp(SDL_MouseButtonEvent const& button) { void World::MouseButtonUp(SDL_MouseButtonEvent const& event) {
if (disconnectButton.MouseButtonUp(button) == Button::State::HOVER && button.button == SDL_BUTTON_LEFT) { if (disconnectButton.MouseButtonUp(event) == Button::State::RELEASED) {
SendLogoutRequest(); SendLogoutRequest();
} }
if (shutDownButton.MouseButtonUp(button) == Button::State::HOVER && button.button == SDL_BUTTON_LEFT) { if (shutdownButton.MouseButtonUp(event) == Button::State::RELEASED) {
SendAdminShutdownRequest(); SendAdminShutdownRequest();
} }
} }
+2 -2
View File
@@ -3,7 +3,7 @@ INCLUDES+=. client_utilities entities gameplay_scenes menu_scenes ../common/debu
#libraries #libraries
#the order of the $(LIBS) is important, at least for MinGW #the order of the $(LIBS) is important, at least for MinGW
LIBS+=client.a ../libcommon.a -lSDL_net LIBS+=client.a ../common/libcommon.a -lSDL_net
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
LIBS+=-lwsock32 -liphlpapi -lmingw32 LIBS+=-lwsock32 -liphlpapi -lmingw32
endif endif
@@ -31,7 +31,7 @@ OUT=$(addprefix $(OUTDIR)/,client)
all: $(OBJ) $(OUT) all: $(OBJ) $(OUT)
$(MAKE) -C client_utilities $(MAKE) -C client_utilities
$(MAKE) -C entities $(MAKE) -C entities
# $(MAKE) -C gameplay_scenes $(MAKE) -C gameplay_scenes
$(MAKE) -C menu_scenes $(MAKE) -C menu_scenes
# $(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS) # $(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS)
+1 -1
Submodule common updated: 6bcaf460b9...345980af5e
+1 -1
View File
@@ -3,7 +3,7 @@ INCLUDES+=SDL . accounts characters clients entities rooms server_utilities trig
#libraries #libraries
#the order of the $(LIBS) is important, at least for MinGW #the order of the $(LIBS) is important, at least for MinGW
LIBS+=server.a ../libcommon.a -lSDL_net LIBS+=server.a ../common/libcommon.a -lSDL_net
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
LIBS+=-lwsock32 -liphlpapi -lmingw32 LIBS+=-lwsock32 -liphlpapi -lmingw32
endif endif