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
CXXSRC=$(wildcard *.cpp)
#DEBUG: Overwrite the wildcard
CXXSRC=world_logic.cpp
#objects
OBJDIR=obj
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
@@ -16,7 +19,7 @@ OUT=$(addprefix $(OUTDIR)/,client.a)
#targets
all: $(OBJ) $(OUT)
ar -crs $(OUT) $(OBJ)
# ar -crs $(OUT) $(OBJ)
$(OBJ): | $(OBJDIR)
+8 -2
View File
@@ -42,6 +42,10 @@
#include "base_monster.hpp"
#include "local_character.hpp"
#include "SDL2/SDL.h"
#include "SDL2/SDL_net.h"
#include "SDL2/SDL_ttf.h"
//STL
#include <map>
@@ -62,6 +66,7 @@ private:
void FrameEnd() override;
//input events
void QuitEvent();
void MouseMotion(SDL_MouseMotionEvent const& event) override;
void MouseButtonDown(SDL_MouseButtonEvent const& event) override;
void MouseButtonUp(SDL_MouseButtonEvent const& event) override;
@@ -130,15 +135,16 @@ private:
int roomIndex = -1;
//graphics
Image buttonImage;
TileSheet tileSheet;
//map
RegionPagerBase regionPager;
//UI
Image buttonImage;
TTF_Font* font = nullptr;
Button disconnectButton;
Button shutDownButton;
Button shutdownButton;
FrameRate fps;
//the camera structure
+34 -42
View File
@@ -40,29 +40,24 @@ World::World(int* const argClientIndex, int* const argAccountIndex):
accountIndex(*argAccountIndex)
{
//setup the utility objects
buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp");
buttonImage.SetClipH(buttonImage.GetClipH()/3);
font.LoadSurface(config["dir.fonts"] + "pk_white_8.bmp");
buttonImage.Load(GetRenderer(), config["dir.interface"] + "button.png");
font = TTF_OpenFont(config["client.font"].c_str(), 12);
//pass the utility objects
disconnectButton.SetImage(&buttonImage);
disconnectButton.SetFont(&font);
shutDownButton.SetImage(&buttonImage);
shutDownButton.SetFont(&font);
//setup the buttons
disconnectButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
disconnectButton.SetText(GetRenderer(), font, "Disconnect", {255, 255, 255, 255});
shutdownButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
shutdownButton.SetText(GetRenderer(), font, "Shutdown", {255, 255, 255, 255});
//set the button positions
disconnectButton.SetX(50);
disconnectButton.SetY(50 + buttonImage.GetClipH() * 0);
shutDownButton.SetX(50);
shutDownButton.SetY(50 + buttonImage.GetClipH() * 1);
//set the button texts
disconnectButton.SetText("Disconnect");
shutDownButton.SetText("Shut Down");
shutdownButton.SetX(50);
shutdownButton.SetY(50 + buttonImage.GetClipH() * 1);
//load the tilesheet
//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
CharacterPacket newPacket;
@@ -73,8 +68,7 @@ World::World(int* const argClientIndex, int* const argAccountIndex):
network.SendTo(Channels::SERVER, &newPacket);
//set the camera's values
camera.width = GetScreen()->w;
camera.height = GetScreen()->h;
SDL_RenderGetLogicalSize(GetRenderer(), &camera.width, &camera.height);
//debug
//
@@ -82,6 +76,7 @@ World::World(int* const argClientIndex, int* const argAccountIndex):
World::~World() {
//unload the local data
TTF_CloseFont(font);
characterMap.clear();
monsterMap.clear();
}
@@ -160,17 +155,10 @@ void World::FrameEnd() {
//
}
void World::RenderFrame() {
// SDL_FillRect(GetScreen(), 0, 0);
Render(GetScreen());
SDL_Flip(GetScreen());
fps.Calculate();
}
void World::Render(SDL_Surface* const screen) {
void World::RenderFrame(SDL_Renderer* renderer) {
//draw the map
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
// std::ostringstream msg;
@@ -181,18 +169,22 @@ void World::Render(SDL_Surface* const screen) {
//draw the entities
for (auto& it : characterMap) {
//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) {
it.second.DrawTo(screen, camera.x, camera.y);
it.second.DrawTo(renderer, camera.x, camera.y);
}
//draw UI
disconnectButton.DrawTo(screen);
shutDownButton.DrawTo(screen);
disconnectButton.DrawTo(renderer);
shutdownButton.DrawTo(renderer);
std::ostringstream msg;
msg << fps.GetFrameRate();
font.DrawStringTo(msg.str(), screen, 0, 0);
//TODO: FPS
// 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() {
//two-step logout
SendDisconnectRequest();
SetNextScene(SceneList::QUIT);
SetSceneSignal(SceneSignal::QUIT);
}
void World::MouseMotion(SDL_MouseMotionEvent const& motion) {
disconnectButton.MouseMotion(motion);
shutDownButton.MouseMotion(motion);
void World::MouseMotion(SDL_MouseMotionEvent const& event) {
disconnectButton.MouseMotion(event);
shutdownButton.MouseMotion(event);
}
void World::MouseButtonDown(SDL_MouseButtonEvent const& button) {
disconnectButton.MouseButtonDown(button);
shutDownButton.MouseButtonDown(button);
void World::MouseButtonDown(SDL_MouseButtonEvent const& event) {
disconnectButton.MouseButtonDown(event);
shutdownButton.MouseButtonDown(event);
}
void World::MouseButtonUp(SDL_MouseButtonEvent const& button) {
if (disconnectButton.MouseButtonUp(button) == Button::State::HOVER && button.button == SDL_BUTTON_LEFT) {
void World::MouseButtonUp(SDL_MouseButtonEvent const& event) {
if (disconnectButton.MouseButtonUp(event) == Button::State::RELEASED) {
SendLogoutRequest();
}
if (shutDownButton.MouseButtonUp(button) == Button::State::HOVER && button.button == SDL_BUTTON_LEFT) {
if (shutdownButton.MouseButtonUp(event) == Button::State::RELEASED) {
SendAdminShutdownRequest();
}
}
+2 -2
View File
@@ -3,7 +3,7 @@ INCLUDES+=. client_utilities entities gameplay_scenes menu_scenes ../common/debu
#libraries
#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)
LIBS+=-lwsock32 -liphlpapi -lmingw32
endif
@@ -31,7 +31,7 @@ OUT=$(addprefix $(OUTDIR)/,client)
all: $(OBJ) $(OUT)
$(MAKE) -C client_utilities
$(MAKE) -C entities
# $(MAKE) -C gameplay_scenes
$(MAKE) -C gameplay_scenes
$(MAKE) -C menu_scenes
# $(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
#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)
LIBS+=-lwsock32 -liphlpapi -lmingw32
endif