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:
@@ -23,27 +23,15 @@
|
|||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
Button::Button(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) {
|
||||||
Setup(i, j, imageSurface, fontSurface, s);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Button::Setup(Sint16 i, Sint16 j, SDL_Surface* imageSurface, SDL_Surface* fontSurface, std::string s) {
|
|
||||||
x = i;
|
x = i;
|
||||||
y = j;
|
y = j;
|
||||||
|
SetSurfaces(bg, fg);
|
||||||
SetSurfaces(imageSurface, fontSurface);
|
SetText(t);
|
||||||
|
|
||||||
SetText(s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Button::State Button::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
Button::State Button::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
||||||
if (motion.state & SDL_BUTTON_LMASK) {
|
return CalcState(motion.x, motion.y, motion.state & SDL_BUTTON_LMASK);
|
||||||
return CalcState(motion.x, motion.y, true);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return CalcState(motion.x, motion.y, false);
|
|
||||||
}
|
|
||||||
return state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Button::State Button::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
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);
|
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
|
//graphical stuff
|
||||||
image.SetSurface(imageSurface);
|
image.SetSurface(bg);
|
||||||
image.SetClipH(image.GetClipH() / 3); //3 phases
|
image.SetClipH(image.GetClipH() / 3); //3 phases, horizontal storage
|
||||||
font.SetSurface(fontSurface);
|
font.SetSurface(fg);
|
||||||
|
|
||||||
//reset textX & textY
|
//reset textX & textY
|
||||||
SetText(text);
|
SetText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Button::SetText(std::string s) {
|
std::string Button::SetText(std::string t) {
|
||||||
//one line
|
//one line, cache the position
|
||||||
text = s;
|
text = t;
|
||||||
textX = (image.GetClipW() / 2) - (font.GetCharW() * text.size() / 2);
|
textX = (image.GetClipW() / 2) - (font.GetCharW() * text.size() / 2);
|
||||||
textY = (image.GetClipH() / 2) - (font.GetCharH() / 2);
|
textY = (image.GetClipH() / 2) - (font.GetCharH() / 2);
|
||||||
return text;
|
return text;
|
||||||
@@ -35,17 +35,15 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
Button() = default;
|
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
|
//return the current state
|
||||||
State MouseMotion(SDL_MouseMotionEvent const&);
|
State MouseMotion(SDL_MouseMotionEvent const&);
|
||||||
State MouseButtonDown(SDL_MouseButtonEvent const&);
|
State MouseButtonDown(SDL_MouseButtonEvent const&);
|
||||||
State MouseButtonUp(SDL_MouseButtonEvent const&);
|
State MouseButtonUp(SDL_MouseButtonEvent const&);
|
||||||
State GetState() const {
|
State GetState() const { return state; }
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
//yet another draw function
|
//yet another draw function
|
||||||
void DrawTo(SDL_Surface* const);
|
void DrawTo(SDL_Surface* const);
|
||||||
@@ -56,9 +54,9 @@ public:
|
|||||||
Sint16 GetX() const { return x; }
|
Sint16 GetX() const { return x; }
|
||||||
Sint16 GetY() const { return y; }
|
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; }
|
std::string GetText() const { return text; }
|
||||||
|
|
||||||
//raw access, be careful
|
//raw access, be careful
|
||||||
@@ -29,7 +29,7 @@ static int frameCount = 0;
|
|||||||
static int lastFrameRate = 0;
|
static int lastFrameRate = 0;
|
||||||
static Clock::time_point tick = Clock::now();
|
static Clock::time_point tick = Clock::now();
|
||||||
|
|
||||||
int ClockFrameRate() {
|
int clockFrameRate() {
|
||||||
frameCount++;
|
frameCount++;
|
||||||
if (Clock::now() - tick >= std::chrono::duration<int>(1)) {
|
if (Clock::now() - tick >= std::chrono::duration<int>(1)) {
|
||||||
lastFrameRate = frameCount;
|
lastFrameRate = frameCount;
|
||||||
@@ -39,6 +39,6 @@ int ClockFrameRate() {
|
|||||||
return lastFrameRate;
|
return lastFrameRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetFrameRate() {
|
int getFrameRate() {
|
||||||
return lastFrameRate;
|
return lastFrameRate;
|
||||||
}
|
}
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
#ifndef FRAMERATE_HPP_
|
#ifndef FRAMERATE_HPP_
|
||||||
#define FRAMERATE_HPP_
|
#define FRAMERATE_HPP_
|
||||||
|
|
||||||
int ClockFrameRate();
|
int clockFrameRate();
|
||||||
int GetFrameRate();
|
int getFrameRate();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
+2
-2
@@ -83,14 +83,14 @@ void InWorld::FrameEnd() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void InWorld::Render(SDL_Surface* const screen) {
|
void InWorld::Render(SDL_Surface* const screen) {
|
||||||
ClockFrameRate();
|
clockFrameRate();
|
||||||
|
|
||||||
for (auto& it : playerCharacters) {
|
for (auto& it : playerCharacters) {
|
||||||
it.second.DrawTo(screen);
|
it.second.DrawTo(screen);
|
||||||
}
|
}
|
||||||
|
|
||||||
//since we're using this twice, make a tmp var
|
//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);
|
font.DrawStringTo(fps, screen, screen->w - fps.size() * font.GetCharW(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-3
@@ -1,8 +1,7 @@
|
|||||||
#config
|
#config
|
||||||
LIBDIR=../libs
|
LOCALLIBS=../lib/libCommon.a
|
||||||
LOCALLIBS=$(LIBDIR)/out/libCodebase.a $(LIBDIR)/out/libCommon.a
|
|
||||||
LIB=$(LOCALLIBS) -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL
|
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))
|
CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
#source
|
#source
|
||||||
|
|||||||
@@ -97,17 +97,17 @@ void PlayerCharacter::FaceDirection() {
|
|||||||
void PlayerCharacter::CheckSpeed() {
|
void PlayerCharacter::CheckSpeed() {
|
||||||
//diagonal
|
//diagonal
|
||||||
if (motion.x != 0 && motion.y != 0) {
|
if (motion.x != 0 && motion.y != 0) {
|
||||||
sprite.SetInterval(0.1);
|
sprite.SetDelay(0.1);
|
||||||
limitSpeed = true;
|
limitSpeed = true;
|
||||||
}
|
}
|
||||||
//cardinal
|
//cardinal
|
||||||
else if (motion != 0) {
|
else if (motion != 0) {
|
||||||
sprite.SetInterval(0.1);
|
sprite.SetDelay(0.1);
|
||||||
limitSpeed = false;
|
limitSpeed = false;
|
||||||
}
|
}
|
||||||
//not moving
|
//not moving
|
||||||
else {
|
else {
|
||||||
sprite.SetInterval(0);
|
sprite.SetDelay(0);
|
||||||
sprite.SetCurrentFrame(0);
|
sprite.SetCurrentFrame(0);
|
||||||
limitSpeed = false;
|
limitSpeed = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,10 +23,6 @@
|
|||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
RasterFont::RasterFont(SDL_Surface* p) {
|
|
||||||
SetSurface(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RasterFont::DrawStringTo(std::string s, SDL_Surface* const dest, Sint16 x, Sint16 y) {
|
void RasterFont::DrawStringTo(std::string s, SDL_Surface* const dest, Sint16 x, Sint16 y) {
|
||||||
if (!image.GetSurface()) {
|
if (!image.GetSurface()) {
|
||||||
throw(std::runtime_error("RasterFont not loaded"));
|
throw(std::runtime_error("RasterFont not loaded"));
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
class RasterFont {
|
class RasterFont {
|
||||||
public:
|
public:
|
||||||
RasterFont() = default;
|
RasterFont() = default;
|
||||||
RasterFont(SDL_Surface* p);
|
RasterFont(SDL_Surface* p) { SetSurface(p); }
|
||||||
~RasterFont() = default;
|
~RasterFont() = default;
|
||||||
|
|
||||||
void DrawStringTo(std::string, SDL_Surface* const, Sint16 x, Sint16 y);
|
void DrawStringTo(std::string, SDL_Surface* const, Sint16 x, Sint16 y);
|
||||||
@@ -21,12 +21,8 @@
|
|||||||
*/
|
*/
|
||||||
#include "sprite_sheet.hpp"
|
#include "sprite_sheet.hpp"
|
||||||
|
|
||||||
SpriteSheet::SpriteSheet(SDL_Surface* s, Uint16 w, Uint16 h) {
|
|
||||||
SetSurface(s, w, h);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SpriteSheet::Update(double delta) {
|
void SpriteSheet::Update(double delta) {
|
||||||
if (interval && (ticks += delta) >= interval) {
|
if (delay && (ticks += delta) >= delay) {
|
||||||
if (++currentFrame >= maxFrames) {
|
if (++currentFrame >= maxFrames) {
|
||||||
currentFrame = 0;
|
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});
|
image.SetSurface(s, {0, 0, w, h});
|
||||||
currentFrame = 0; maxFrames = image.GetSurface()->w / image.GetClipW();
|
currentFrame = 0; maxFrames = image.GetSurface()->w / image.GetClipW();
|
||||||
currentStrip = 0; maxStrips = image.GetSurface()->h / image.GetClipH();
|
currentStrip = 0; maxStrips = image.GetSurface()->h / image.GetClipH();
|
||||||
interval = ticks = 0;
|
delay = ticks = 0;
|
||||||
}
|
}
|
||||||
@@ -29,23 +29,19 @@
|
|||||||
class SpriteSheet {
|
class SpriteSheet {
|
||||||
public:
|
public:
|
||||||
SpriteSheet() = default;
|
SpriteSheet() = default;
|
||||||
SpriteSheet(SDL_Surface*, Uint16 w, Uint16 h);
|
SpriteSheet(SDL_Surface* s, Uint16 w, Uint16 h) { SetSurface(s, w, h); }
|
||||||
~SpriteSheet() = default;
|
~SpriteSheet() = default;
|
||||||
|
|
||||||
void Update(double delta);
|
void Update(double delta);
|
||||||
|
|
||||||
SDL_Surface* SetSurface(SDL_Surface* const, Uint16 w, Uint16 h);
|
SDL_Surface* SetSurface(SDL_Surface* const, Uint16 w, Uint16 h);
|
||||||
SDL_Surface* GetSurface() const {
|
SDL_Surface* GetSurface() const { return image.GetSurface(); }
|
||||||
return image.GetSurface();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DrawTo(SDL_Surface* const dest, Sint16 x, Sint16 y) {
|
void DrawTo(SDL_Surface* const dest, Sint16 x, Sint16 y) { image.DrawTo(dest, x, y); }
|
||||||
image.DrawTo(dest, x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Accessors and Mutators
|
//Accessors and Mutators
|
||||||
double SetInterval(double i) { return interval = i; }
|
double SetDelay(double i) { return delay = i; }
|
||||||
double GetInterval() const { return interval; }
|
double GetDelay() const { return delay; }
|
||||||
|
|
||||||
int SetCurrentFrame(int i) { return currentFrame = i; }
|
int SetCurrentFrame(int i) { return currentFrame = i; }
|
||||||
int SetCurrentStrip(int i) { return currentStrip = i; }
|
int SetCurrentStrip(int i) { return currentStrip = i; }
|
||||||
@@ -60,7 +56,7 @@ private:
|
|||||||
Image image;
|
Image image;
|
||||||
int currentFrame = 0, maxFrames = 0;
|
int currentFrame = 0, maxFrames = 0;
|
||||||
int currentStrip = 0, maxStrips = 0;
|
int currentStrip = 0, maxStrips = 0;
|
||||||
double interval = 0, ticks = 0;
|
double delay = 0, ticks = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -23,10 +23,6 @@
|
|||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
SurfaceManager::~SurfaceManager() noexcept {
|
|
||||||
FreeAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Surface* SurfaceManager::Load(std::string key, std::string fname) {
|
SDL_Surface* SurfaceManager::Load(std::string key, std::string fname) {
|
||||||
MapType::iterator it = surfaceMap.find(key);
|
MapType::iterator it = surfaceMap.find(key);
|
||||||
if (it != surfaceMap.end()) {
|
if (it != surfaceMap.end()) {
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
class SurfaceManager {
|
class SurfaceManager {
|
||||||
public:
|
public:
|
||||||
SurfaceManager() = default;
|
SurfaceManager() = default;
|
||||||
~SurfaceManager() noexcept;
|
~SurfaceManager() noexcept { FreeAll(); }
|
||||||
|
|
||||||
SDL_Surface* Load(std::string key, std::string fname);
|
SDL_Surface* Load(std::string key, std::string fname);
|
||||||
SDL_Surface* Reload(std::string key, std::string fname);
|
SDL_Surface* Reload(std::string key, std::string fname);
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
#config
|
#config
|
||||||
LIBDIR=..
|
|
||||||
LOCALLIBS=
|
LOCALLIBS=
|
||||||
LIB=-lSDL_net
|
LIB=
|
||||||
INCLUDES=$(LIBDIR)/Codebase
|
INCLUDES=
|
||||||
CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
#source
|
#source
|
||||||
@@ -13,7 +12,7 @@ OBJDIR=obj
|
|||||||
OBJ=$(addprefix $(OBJDIR)/,$(SRC:.cpp=.o))
|
OBJ=$(addprefix $(OBJDIR)/,$(SRC:.cpp=.o))
|
||||||
|
|
||||||
#output
|
#output
|
||||||
OUTDIR=../out
|
OUTDIR=../lib
|
||||||
OUT=$(addprefix $(OUTDIR)/,libCommon.a)
|
OUT=$(addprefix $(OUTDIR)/,libCommon.a)
|
||||||
|
|
||||||
#targets
|
#targets
|
||||||
@@ -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
|
|
||||||
@@ -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
|
|
||||||
@@ -1,9 +1,14 @@
|
|||||||
|
LIBDIR=lib
|
||||||
OUTDIR=out
|
OUTDIR=out
|
||||||
|
|
||||||
all: $(OUTDIR)
|
all: $(LIBDIR) $(OUTDIR)
|
||||||
$(MAKE) -C libs
|
$(MAKE) -C common
|
||||||
$(MAKE) -C server
|
$(MAKE) -C server
|
||||||
$(MAKE) -C client
|
$(MAKE) -C client
|
||||||
|
$(MAKE) -C test
|
||||||
|
|
||||||
|
$(LIBDIR):
|
||||||
|
mkdir $(LIBDIR)
|
||||||
|
|
||||||
$(OUTDIR):
|
$(OUTDIR):
|
||||||
mkdir $(OUTDIR)
|
mkdir $(OUTDIR)
|
||||||
|
|||||||
+2
-3
@@ -1,8 +1,7 @@
|
|||||||
#config
|
#config
|
||||||
LIBDIR=../libs
|
LOCALLIBS=../lib/libCommon.a
|
||||||
LOCALLIBS=$(LIBDIR)/out/libCodebase.a $(LIBDIR)/out/libCommon.a
|
|
||||||
LIB=$(LOCALLIBS) -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL
|
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))
|
CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
#source
|
#source
|
||||||
|
|||||||
+2
-3
@@ -1,8 +1,7 @@
|
|||||||
#config
|
#config
|
||||||
LIBDIR=../libs
|
LOCALLIBS=../lib/libCommon.a
|
||||||
LOCALLIBS=
|
|
||||||
LIB=
|
LIB=
|
||||||
INCLUDES=
|
INCLUDES=../common
|
||||||
CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
#source
|
#source
|
||||||
|
|||||||
Reference in New Issue
Block a user