Added new graphics stuff, adjusted build process
This commit is contained in:
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
COMMONDIR+=../common ../common/map ../common/network ../common/ui
|
COMMONDIR+=../common ../common/graphics ../common/map ../common/network ../common/ui
|
||||||
COMMON+=../libcommon.a
|
COMMON+=../libcommon.a
|
||||||
LIB+=$(COMMON) -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL
|
LIB+=$(COMMON) -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL
|
||||||
CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(COMMONDIR))
|
CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(COMMONDIR))
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
#config
|
||||||
|
COMMONDIR+=..
|
||||||
|
COMMON+=../../libcommon.a
|
||||||
|
LIB+=
|
||||||
|
CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(COMMONDIR))
|
||||||
|
CFLAGS+=-DDEBUG $(addprefix -I,$(COMMONDIR))
|
||||||
|
|
||||||
|
#source
|
||||||
|
CXXSRC=$(wildcard *.cpp)
|
||||||
|
CSRC=$(wildcard *.c)
|
||||||
|
|
||||||
|
#objects
|
||||||
|
OBJDIR=obj
|
||||||
|
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||||
|
OBJ+=$(addprefix $(OBJDIR)/,$(CSRC:.c=.o))
|
||||||
|
|
||||||
|
#output
|
||||||
|
OUTDIR=../..
|
||||||
|
OUT=$(addprefix $(OUTDIR)/,libcommon.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 $@ $<
|
||||||
|
|
||||||
|
$(OBJDIR)/%.o: %.c
|
||||||
|
$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) *.o *.a *.exe
|
||||||
|
|
||||||
|
rebuild: clean all
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "sprite_sheet.hpp"
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
void SpriteSheet::Update(double delta) {
|
||||||
|
if (delay && (tick += delta) >= delay) {
|
||||||
|
if (++xIndex >= xCount) {
|
||||||
|
xIndex = 0;
|
||||||
|
}
|
||||||
|
tick = 0;
|
||||||
|
}
|
||||||
|
image.SetClipX(xIndex * image.GetClipW());
|
||||||
|
image.SetClipY(yIndex * image.GetClipH());
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Surface* SpriteSheet::LoadSurface(std::string fname, Uint16 xCellCount, Uint16 yCellCount) {
|
||||||
|
image.LoadSurface(fname);
|
||||||
|
|
||||||
|
xCount = xCellCount;
|
||||||
|
yCount = yCellCount;
|
||||||
|
|
||||||
|
image.SetClipW(image.GetSurface()->w / xCount);
|
||||||
|
image.SetClipH(image.GetSurface()->h / yCount);
|
||||||
|
|
||||||
|
xIndex = yIndex = 0;
|
||||||
|
delay = tick = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Surface* SpriteSheet::SetSurface(SDL_Surface* surface, Uint16 xCellCount, Uint16 yCellCount) {
|
||||||
|
image.SetSurface(surface);
|
||||||
|
|
||||||
|
xCount = xCellCount;
|
||||||
|
yCount = yCellCount;
|
||||||
|
|
||||||
|
image.SetClipW(image.GetSurface()->w / xCount);
|
||||||
|
image.SetClipH(image.GetSurface()->h / yCount);
|
||||||
|
|
||||||
|
xIndex = yIndex = 0;
|
||||||
|
delay = tick = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpriteSheet::FreeSurface() {
|
||||||
|
image.FreeSurface();
|
||||||
|
xCount = yCount = 0;
|
||||||
|
xIndex = yIndex = 0;
|
||||||
|
delay = tick = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Uint16 SpriteSheet::SetXCount(Uint16 i) {
|
||||||
|
xIndex = 0;
|
||||||
|
return xCount = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
Uint16 SpriteSheet::SetYCount(Uint16 i) {
|
||||||
|
yIndex = 0;
|
||||||
|
return yCount = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
Uint16 SpriteSheet::SetXIndex(Uint16 i) {
|
||||||
|
if (i > xCount) {
|
||||||
|
std::ostringstream os;
|
||||||
|
os << "Cannot set x index to " << i;
|
||||||
|
throw(std::invalid_argument(os.str()));
|
||||||
|
}
|
||||||
|
return xIndex = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
Uint16 SpriteSheet::SetYIndex(Uint16 i) {
|
||||||
|
if (i > yCount) {
|
||||||
|
std::ostringstream os;
|
||||||
|
os << "Cannot set y index to " << i;
|
||||||
|
throw(std::invalid_argument(os.str()));
|
||||||
|
}
|
||||||
|
return yIndex = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
double SpriteSheet::SetDelay(double d) {
|
||||||
|
tick = 0;
|
||||||
|
return delay = d;
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#ifndef SPRITESHEET_HPP_
|
||||||
|
#define SPRITESHEET_HPP_
|
||||||
|
|
||||||
|
#include "image.hpp"
|
||||||
|
|
||||||
|
class SpriteSheet {
|
||||||
|
public:
|
||||||
|
SpriteSheet() = default;
|
||||||
|
SpriteSheet(std::string fname, Uint16 xCellCount, Uint16 yCellCount) { LoadSurface(fname, xCellCount, yCellCount); }
|
||||||
|
SpriteSheet(SDL_Surface* surface, Uint16 xCellCount, Uint16 yCellCount) { SetSurface(surface, xCellCount, yCellCount); }
|
||||||
|
~SpriteSheet() { FreeSurface(); };
|
||||||
|
|
||||||
|
void Update(double delta);
|
||||||
|
|
||||||
|
SDL_Surface* LoadSurface(std::string fname, Uint16 xCellCount, Uint16 yCellCount);
|
||||||
|
SDL_Surface* SetSurface(SDL_Surface* surface, Uint16 xCellCount, Uint16 yCellCount);
|
||||||
|
SDL_Surface* GetSurface() { return image.GetSurface(); }
|
||||||
|
void FreeSurface();
|
||||||
|
|
||||||
|
void DrawTo(SDL_Surface* const dest, Sint16 x, Sint16 y) { image.DrawTo(dest, x, y); }
|
||||||
|
|
||||||
|
//accessors and mutators
|
||||||
|
Image* GetImage() { return ℑ } //OO breaker
|
||||||
|
|
||||||
|
Uint16 SetXCount(Uint16);
|
||||||
|
Uint16 SetYCount(Uint16);
|
||||||
|
Uint16 SetXIndex(Uint16);
|
||||||
|
Uint16 SetYIndex(Uint16);
|
||||||
|
|
||||||
|
Uint16 GetXCount() const { return xCount; }
|
||||||
|
Uint16 GetYCount() const { return yCount; }
|
||||||
|
Uint16 GetXIndex() const { return xIndex; }
|
||||||
|
Uint16 GetYIndex() const { return yIndex; }
|
||||||
|
|
||||||
|
double SetDelay(double d);
|
||||||
|
double GetDelay() const { return delay; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
Image image;
|
||||||
|
Uint16 xCount = 0, yCount = 0; //number of cells
|
||||||
|
Uint16 xIndex = 0, yIndex = 0; //current cell being drawn
|
||||||
|
double delay = 0.0, tick = 0.0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -19,6 +19,7 @@ OUT=$(addprefix $(OUTDIR)/,libcommon.a)
|
|||||||
#targets
|
#targets
|
||||||
all: $(OBJ) $(OUT)
|
all: $(OBJ) $(OUT)
|
||||||
ar -crs $(OUT) $(OBJ)
|
ar -crs $(OUT) $(OBJ)
|
||||||
|
$(MAKE) -C graphics
|
||||||
$(MAKE) -C map
|
$(MAKE) -C map
|
||||||
$(MAKE) -C network
|
$(MAKE) -C network
|
||||||
$(MAKE) -C ui
|
$(MAKE) -C ui
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
COMMONDIR+=..
|
COMMONDIR+=.. ../graphics
|
||||||
COMMON+=../../libcommon.a
|
COMMON+=../../libcommon.a
|
||||||
LIB+=
|
LIB+=
|
||||||
CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(COMMONDIR))
|
CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(COMMONDIR))
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
COMMONDIR+=..
|
COMMONDIR+=.. ../graphics
|
||||||
COMMON+=../../libcommon.a
|
COMMON+=../../libcommon.a
|
||||||
LIB+=
|
LIB+=
|
||||||
CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(COMMONDIR))
|
CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(COMMONDIR))
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
COMMONDIR+=../common ../common/map ../common/network ../common/ui
|
COMMONDIR+=../common ../common/graphics ../common/map ../common/network ../common/ui
|
||||||
COMMON+=../libcommon.a
|
COMMON+=../libcommon.a
|
||||||
LIB+=$(COMMON) -lmingw32 -lSDLmain -lSDL -llua -lsqlite3
|
LIB+=$(COMMON) -lmingw32 -lSDLmain -lSDL -llua -lsqlite3
|
||||||
CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(COMMONDIR))
|
CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(COMMONDIR))
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
COMMONDIR+=../common ../common/map ../common/network ../common/ui
|
COMMONDIR+=../common ../common/map ../common/network
|
||||||
COMMON+=../libcommon.a
|
COMMON+=../libcommon.a
|
||||||
LIB+=$(COMMON) -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua -lsqlite3
|
LIB+=$(COMMON) -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua -lsqlite3
|
||||||
CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(COMMONDIR))
|
CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(COMMONDIR))
|
||||||
|
|||||||
Reference in New Issue
Block a user