diff --git a/libs/Codebase/button.cpp b/client/button.cpp similarity index 74% rename from libs/Codebase/button.cpp rename to client/button.cpp index 4d952af..9dcf578 100644 --- a/libs/Codebase/button.cpp +++ b/client/button.cpp @@ -23,27 +23,15 @@ #include -Button::Button(Sint16 i, Sint16 j, SDL_Surface* imageSurface, SDL_Surface* fontSurface, std::string s) { - Setup(i, j, imageSurface, fontSurface, s); -} - -void Button::Setup(Sint16 i, Sint16 j, SDL_Surface* imageSurface, SDL_Surface* fontSurface, std::string s) { +void Button::Setup(Sint16 i, Sint16 j, SDL_Surface* bg, SDL_Surface* fg, std::string t) { x = i; y = j; - - SetSurfaces(imageSurface, fontSurface); - - SetText(s); + SetSurfaces(bg, fg); + SetText(t); } Button::State Button::MouseMotion(SDL_MouseMotionEvent const& motion) { - if (motion.state & SDL_BUTTON_LMASK) { - return CalcState(motion.x, motion.y, true); - } - else { - return CalcState(motion.x, motion.y, false); - } - return state; + return CalcState(motion.x, motion.y, motion.state & SDL_BUTTON_LMASK); } Button::State Button::MouseButtonDown(SDL_MouseButtonEvent const& button) { @@ -65,19 +53,19 @@ void Button::DrawTo(SDL_Surface* const dest) { font.DrawStringTo(text, dest, textX + x, textY + y); } -void Button::SetSurfaces(SDL_Surface* imageSurface, SDL_Surface* fontSurface) { +void Button::SetSurfaces(SDL_Surface* bg, SDL_Surface* fg) { //graphical stuff - image.SetSurface(imageSurface); - image.SetClipH(image.GetClipH() / 3); //3 phases - font.SetSurface(fontSurface); + image.SetSurface(bg); + image.SetClipH(image.GetClipH() / 3); //3 phases, horizontal storage + font.SetSurface(fg); //reset textX & textY SetText(text); } -std::string Button::SetText(std::string s) { - //one line - text = s; +std::string Button::SetText(std::string t) { + //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; diff --git a/libs/Codebase/button.hpp b/client/button.hpp similarity index 85% rename from libs/Codebase/button.hpp rename to client/button.hpp index 3acb43e..10e7dc3 100644 --- a/libs/Codebase/button.hpp +++ b/client/button.hpp @@ -35,17 +35,15 @@ public: }; Button() = default; - Button(Sint16 x, Sint16 y, SDL_Surface* imageSurface, SDL_Surface* fontSurface, std::string text = ""); + Button(Sint16 x, Sint16 y, SDL_Surface* bg, SDL_Surface* fg, std::string t = "") { Setup(x, y, bg, fg, t); } - void Setup(Sint16 x, Sint16 y, SDL_Surface* imageSurface, SDL_Surface* fontSurface, std::string text = ""); + void Setup(Sint16 x, Sint16 y, SDL_Surface* bg, SDL_Surface* fg, std::string text = ""); //return the current state State MouseMotion(SDL_MouseMotionEvent const&); State MouseButtonDown(SDL_MouseButtonEvent const&); State MouseButtonUp(SDL_MouseButtonEvent const&); - State GetState() const { - return state; - } + State GetState() const { return state; } //yet another draw function void DrawTo(SDL_Surface* const); @@ -56,9 +54,9 @@ public: Sint16 GetX() const { return x; } Sint16 GetY() const { return y; } - void SetSurfaces(SDL_Surface* image, SDL_Surface* font); + void SetSurfaces(SDL_Surface* bg, SDL_Surface* fg); - std::string SetText(std::string s); + std::string SetText(std::string t); std::string GetText() const { return text; } //raw access, be careful diff --git a/libs/Codebase/frame_rate.cpp b/client/frame_rate.cpp similarity index 96% rename from libs/Codebase/frame_rate.cpp rename to client/frame_rate.cpp index 0b855d3..0a4b87f 100644 --- a/libs/Codebase/frame_rate.cpp +++ b/client/frame_rate.cpp @@ -29,7 +29,7 @@ static int frameCount = 0; static int lastFrameRate = 0; static Clock::time_point tick = Clock::now(); -int ClockFrameRate() { +int clockFrameRate() { frameCount++; if (Clock::now() - tick >= std::chrono::duration(1)) { lastFrameRate = frameCount; @@ -39,6 +39,6 @@ int ClockFrameRate() { return lastFrameRate; } -int GetFrameRate() { +int getFrameRate() { return lastFrameRate; } diff --git a/libs/Codebase/frame_rate.hpp b/client/frame_rate.hpp similarity index 95% rename from libs/Codebase/frame_rate.hpp rename to client/frame_rate.hpp index 8f0a920..bc00ba0 100644 --- a/libs/Codebase/frame_rate.hpp +++ b/client/frame_rate.hpp @@ -22,7 +22,7 @@ #ifndef FRAMERATE_HPP_ #define FRAMERATE_HPP_ -int ClockFrameRate(); -int GetFrameRate(); +int clockFrameRate(); +int getFrameRate(); #endif diff --git a/libs/Codebase/image.cpp b/client/image.cpp similarity index 100% rename from libs/Codebase/image.cpp rename to client/image.cpp diff --git a/libs/Codebase/image.hpp b/client/image.hpp similarity index 100% rename from libs/Codebase/image.hpp rename to client/image.hpp diff --git a/client/in_world.cpp b/client/in_world.cpp index aeeabc3..f24247d 100644 --- a/client/in_world.cpp +++ b/client/in_world.cpp @@ -83,14 +83,14 @@ void InWorld::FrameEnd() { } void InWorld::Render(SDL_Surface* const screen) { - ClockFrameRate(); + clockFrameRate(); for (auto& it : playerCharacters) { it.second.DrawTo(screen); } //since we're using this twice, make a tmp var - string fps = itos(GetFrameRate()); + string fps = itos(getFrameRate()); font.DrawStringTo(fps, screen, screen->w - fps.size() * font.GetCharW(), 0); } diff --git a/client/makefile b/client/makefile index e6f2842..5208bf9 100644 --- a/client/makefile +++ b/client/makefile @@ -1,8 +1,7 @@ #config -LIBDIR=../libs -LOCALLIBS=$(LIBDIR)/out/libCodebase.a $(LIBDIR)/out/libCommon.a +LOCALLIBS=../lib/libCommon.a LIB=$(LOCALLIBS) -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -INCLUDES=$(LIBDIR)/SDL_net $(LIBDIR)/Codebase $(LIBDIR)/common +INCLUDES=../common CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES)) #source diff --git a/client/player_character.cpp b/client/player_character.cpp index aaa3922..776d5f2 100644 --- a/client/player_character.cpp +++ b/client/player_character.cpp @@ -97,17 +97,17 @@ void PlayerCharacter::FaceDirection() { void PlayerCharacter::CheckSpeed() { //diagonal if (motion.x != 0 && motion.y != 0) { - sprite.SetInterval(0.1); + sprite.SetDelay(0.1); limitSpeed = true; } //cardinal else if (motion != 0) { - sprite.SetInterval(0.1); + sprite.SetDelay(0.1); limitSpeed = false; } //not moving else { - sprite.SetInterval(0); + sprite.SetDelay(0); sprite.SetCurrentFrame(0); limitSpeed = false; } diff --git a/libs/Codebase/raster_font.cpp b/client/raster_font.cpp similarity index 96% rename from libs/Codebase/raster_font.cpp rename to client/raster_font.cpp index 71f1f04..61da639 100644 --- a/libs/Codebase/raster_font.cpp +++ b/client/raster_font.cpp @@ -23,10 +23,6 @@ #include -RasterFont::RasterFont(SDL_Surface* p) { - SetSurface(p); -} - void RasterFont::DrawStringTo(std::string s, SDL_Surface* const dest, Sint16 x, Sint16 y) { if (!image.GetSurface()) { throw(std::runtime_error("RasterFont not loaded")); diff --git a/libs/Codebase/raster_font.hpp b/client/raster_font.hpp similarity index 96% rename from libs/Codebase/raster_font.hpp rename to client/raster_font.hpp index 643dde6..38ea6f4 100644 --- a/libs/Codebase/raster_font.hpp +++ b/client/raster_font.hpp @@ -29,7 +29,7 @@ class RasterFont { public: RasterFont() = default; - RasterFont(SDL_Surface* p); + RasterFont(SDL_Surface* p) { SetSurface(p); } ~RasterFont() = default; void DrawStringTo(std::string, SDL_Surface* const, Sint16 x, Sint16 y); diff --git a/libs/Codebase/sprite_sheet.cpp b/client/sprite_sheet.cpp similarity index 89% rename from libs/Codebase/sprite_sheet.cpp rename to client/sprite_sheet.cpp index c387f79..14af497 100644 --- a/libs/Codebase/sprite_sheet.cpp +++ b/client/sprite_sheet.cpp @@ -21,12 +21,8 @@ */ #include "sprite_sheet.hpp" -SpriteSheet::SpriteSheet(SDL_Surface* s, Uint16 w, Uint16 h) { - SetSurface(s, w, h); -} - void SpriteSheet::Update(double delta) { - if (interval && (ticks += delta) >= interval) { + if (delay && (ticks += delta) >= delay) { if (++currentFrame >= maxFrames) { currentFrame = 0; } @@ -40,5 +36,5 @@ SDL_Surface* SpriteSheet::SetSurface(SDL_Surface* const s, Uint16 w, Uint16 h) { image.SetSurface(s, {0, 0, w, h}); currentFrame = 0; maxFrames = image.GetSurface()->w / image.GetClipW(); currentStrip = 0; maxStrips = image.GetSurface()->h / image.GetClipH(); - interval = ticks = 0; + delay = ticks = 0; } diff --git a/libs/Codebase/sprite_sheet.hpp b/client/sprite_sheet.hpp similarity index 83% rename from libs/Codebase/sprite_sheet.hpp rename to client/sprite_sheet.hpp index c86dea9..2ac18e0 100644 --- a/libs/Codebase/sprite_sheet.hpp +++ b/client/sprite_sheet.hpp @@ -29,23 +29,19 @@ class SpriteSheet { public: SpriteSheet() = default; - SpriteSheet(SDL_Surface*, Uint16 w, Uint16 h); + SpriteSheet(SDL_Surface* s, Uint16 w, Uint16 h) { SetSurface(s, w, h); } ~SpriteSheet() = default; void Update(double delta); SDL_Surface* SetSurface(SDL_Surface* const, Uint16 w, Uint16 h); - SDL_Surface* GetSurface() const { - return image.GetSurface(); - } + SDL_Surface* GetSurface() const { return image.GetSurface(); } - void DrawTo(SDL_Surface* const dest, Sint16 x, Sint16 y) { - image.DrawTo(dest, x, y); - } + void DrawTo(SDL_Surface* const dest, Sint16 x, Sint16 y) { image.DrawTo(dest, x, y); } //Accessors and Mutators - double SetInterval(double i) { return interval = i; } - double GetInterval() const { return interval; } + double SetDelay(double i) { return delay = i; } + double GetDelay() const { return delay; } int SetCurrentFrame(int i) { return currentFrame = i; } int SetCurrentStrip(int i) { return currentStrip = i; } @@ -60,7 +56,7 @@ private: Image image; int currentFrame = 0, maxFrames = 0; int currentStrip = 0, maxStrips = 0; - double interval = 0, ticks = 0; + double delay = 0, ticks = 0; }; #endif diff --git a/libs/Codebase/surface_manager.cpp b/client/surface_manager.cpp similarity index 97% rename from libs/Codebase/surface_manager.cpp rename to client/surface_manager.cpp index a56afd3..d554684 100644 --- a/libs/Codebase/surface_manager.cpp +++ b/client/surface_manager.cpp @@ -23,10 +23,6 @@ #include -SurfaceManager::~SurfaceManager() noexcept { - FreeAll(); -} - SDL_Surface* SurfaceManager::Load(std::string key, std::string fname) { MapType::iterator it = surfaceMap.find(key); if (it != surfaceMap.end()) { diff --git a/libs/Codebase/surface_manager.hpp b/client/surface_manager.hpp similarity index 97% rename from libs/Codebase/surface_manager.hpp rename to client/surface_manager.hpp index 8499a83..6e0e616 100644 --- a/libs/Codebase/surface_manager.hpp +++ b/client/surface_manager.hpp @@ -30,7 +30,7 @@ class SurfaceManager { public: SurfaceManager() = default; - ~SurfaceManager() noexcept; + ~SurfaceManager() noexcept { FreeAll(); } SDL_Surface* Load(std::string key, std::string fname); SDL_Surface* Reload(std::string key, std::string fname); diff --git a/libs/common/client_entry.hpp b/common/client_entry.hpp similarity index 100% rename from libs/common/client_entry.hpp rename to common/client_entry.hpp diff --git a/libs/Codebase/config_utility.cpp b/common/config_utility.cpp similarity index 100% rename from libs/Codebase/config_utility.cpp rename to common/config_utility.cpp diff --git a/libs/Codebase/config_utility.hpp b/common/config_utility.hpp similarity index 100% rename from libs/Codebase/config_utility.hpp rename to common/config_utility.hpp diff --git a/libs/common/defines.hpp b/common/defines.hpp similarity index 100% rename from libs/common/defines.hpp rename to common/defines.hpp diff --git a/libs/common/makefile b/common/makefile similarity index 87% rename from libs/common/makefile rename to common/makefile index 3cd79ac..2550201 100644 --- a/libs/common/makefile +++ b/common/makefile @@ -1,8 +1,7 @@ #config -LIBDIR=.. LOCALLIBS= -LIB=-lSDL_net -INCLUDES=$(LIBDIR)/Codebase +LIB= +INCLUDES= CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES)) #source @@ -13,7 +12,7 @@ OBJDIR=obj OBJ=$(addprefix $(OBJDIR)/,$(SRC:.cpp=.o)) #output -OUTDIR=../out +OUTDIR=../lib OUT=$(addprefix $(OUTDIR)/,libCommon.a) #targets diff --git a/libs/common/network_queue.cpp b/common/network_queue.cpp similarity index 100% rename from libs/common/network_queue.cpp rename to common/network_queue.cpp diff --git a/libs/common/network_queue.hpp b/common/network_queue.hpp similarity index 100% rename from libs/common/network_queue.hpp rename to common/network_queue.hpp diff --git a/libs/common/packet.hpp b/common/packet.hpp similarity index 100% rename from libs/common/packet.hpp rename to common/packet.hpp diff --git a/libs/common/player_entry.hpp b/common/player_entry.hpp similarity index 100% rename from libs/common/player_entry.hpp rename to common/player_entry.hpp diff --git a/libs/common/server_entry.hpp b/common/server_entry.hpp similarity index 100% rename from libs/common/server_entry.hpp rename to common/server_entry.hpp diff --git a/libs/common/singleton.hpp b/common/singleton.hpp similarity index 100% rename from libs/common/singleton.hpp rename to common/singleton.hpp diff --git a/libs/Codebase/udp_network_utility.cpp b/common/udp_network_utility.cpp similarity index 100% rename from libs/Codebase/udp_network_utility.cpp rename to common/udp_network_utility.cpp diff --git a/libs/Codebase/udp_network_utility.hpp b/common/udp_network_utility.hpp similarity index 100% rename from libs/Codebase/udp_network_utility.hpp rename to common/udp_network_utility.hpp diff --git a/libs/common/utilities.cpp b/common/utilities.cpp similarity index 100% rename from libs/common/utilities.cpp rename to common/utilities.cpp diff --git a/libs/common/utilities.hpp b/common/utilities.hpp similarity index 100% rename from libs/common/utilities.hpp rename to common/utilities.hpp diff --git a/libs/Codebase/vector2.hpp b/common/vector2.hpp similarity index 100% rename from libs/Codebase/vector2.hpp rename to common/vector2.hpp diff --git a/libs/Codebase/makefile b/libs/Codebase/makefile deleted file mode 100644 index f00b955..0000000 --- a/libs/Codebase/makefile +++ /dev/null @@ -1,39 +0,0 @@ -#config -LIBDIR=.. -LOCALLIBS= -LIB=-lSDL_net -INCLUDES= -CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES)) - -#source -SRC=$(wildcard *.cpp) - -#objects -OBJDIR=obj -OBJ=$(addprefix $(OBJDIR)/,$(SRC:.cpp=.o)) - -#output -OUTDIR=../out -OUT=$(addprefix $(OUTDIR)/,libCodebase.a) - -#targets -all: $(OBJ) $(OUT) - ar -crs $(OUT) $(OBJ) - -$(OBJ): | $(OBJDIR) - -$(OUT): | $(OUTDIR) - -$(OBJDIR): - mkdir $(OBJDIR) - -$(OUTDIR): - mkdir $(OUTDIR) - -$(OBJDIR)/%.o: %.cpp - $(CXX) $(CXXFLAGS) -c -o $@ $< - -clean: - $(RM) *.o *.a *.exe - -rebuild: clean all diff --git a/libs/makefile b/libs/makefile deleted file mode 100644 index 91a432a..0000000 --- a/libs/makefile +++ /dev/null @@ -1,13 +0,0 @@ -OUTDIR=out - -all: $(OUTDIR) - $(MAKE) -C Codebase - $(MAKE) -C common - -$(OUTDIR): - mkdir $(OUTDIR) - -clean: - $(RM) *.o *.a *.exe - -rebuild: clean all diff --git a/makefile b/makefile index cb89da0..7b0e334 100644 --- a/makefile +++ b/makefile @@ -1,9 +1,14 @@ +LIBDIR=lib OUTDIR=out -all: $(OUTDIR) - $(MAKE) -C libs +all: $(LIBDIR) $(OUTDIR) + $(MAKE) -C common $(MAKE) -C server $(MAKE) -C client + $(MAKE) -C test + +$(LIBDIR): + mkdir $(LIBDIR) $(OUTDIR): mkdir $(OUTDIR) diff --git a/server/makefile b/server/makefile index 6b48209..e0975cc 100644 --- a/server/makefile +++ b/server/makefile @@ -1,8 +1,7 @@ #config -LIBDIR=../libs -LOCALLIBS=$(LIBDIR)/out/libCodebase.a $(LIBDIR)/out/libCommon.a +LOCALLIBS=../lib/libCommon.a LIB=$(LOCALLIBS) -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -INCLUDES=$(LIBDIR)/SDL_net $(LIBDIR)/Codebase $(LIBDIR)/common +INCLUDES=../common CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES)) #source diff --git a/test/makefile b/test/makefile index a7bce2d..e7f1b26 100644 --- a/test/makefile +++ b/test/makefile @@ -1,8 +1,7 @@ #config -LIBDIR=../libs -LOCALLIBS= +LOCALLIBS=../lib/libCommon.a LIB= -INCLUDES= +INCLUDES=../common CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES)) #source