Rearrenged the directory tree

I just _had_ to get rid of that horrible libs/ directory. Now most of the
graphical stuff is in client/, but I'll create more subdirectories so that
they're not getting in the way.
This commit is contained in:
Kayne Ruse
2013-07-15 14:58:04 +10:00
parent 28b491587c
commit 43dadcdbb8
36 changed files with 51 additions and 132 deletions
+11 -23
View File
@@ -23,27 +23,15 @@
#include <stdexcept>
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;
@@ -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
@@ -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<int>(1)) {
lastFrameRate = frameCount;
@@ -39,6 +39,6 @@ int ClockFrameRate() {
return lastFrameRate;
}
int GetFrameRate() {
int getFrameRate() {
return lastFrameRate;
}
@@ -22,7 +22,7 @@
#ifndef FRAMERATE_HPP_
#define FRAMERATE_HPP_
int ClockFrameRate();
int GetFrameRate();
int clockFrameRate();
int getFrameRate();
#endif
+2 -2
View File
@@ -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);
}
+2 -3
View File
@@ -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
+3 -3
View File
@@ -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;
}
@@ -23,10 +23,6 @@
#include <stdexcept>
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"));
@@ -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);
@@ -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;
}
@@ -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
@@ -23,10 +23,6 @@
#include <stdexcept>
SurfaceManager::~SurfaceManager() noexcept {
FreeAll();
}
SDL_Surface* SurfaceManager::Load(std::string key, std::string fname) {
MapType::iterator it = surfaceMap.find(key);
if (it != surfaceMap.end()) {
@@ -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);
+3 -4
View File
@@ -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
-39
View File
@@ -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
-13
View File
@@ -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
+7 -2
View File
@@ -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)
+2 -3
View File
@@ -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
+2 -3
View File
@@ -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