Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
miki151 committed Oct 21, 2016
2 parents acbd6af + 7df5e5f commit 0459ed3
Show file tree
Hide file tree
Showing 266 changed files with 10,768 additions and 6,615 deletions.
23 changes: 10 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ ifndef RPATH
RPATH = .
endif

CFLAGS = -Wall -std=c++11 -Wno-sign-compare -Wno-unused-variable -Wno-unused-function -Wfatal-errors -Wno-shift-count-overflow -Wno-tautological-constant-out-of-range-compare
CFLAGS = -Wall -std=c++11 -Wno-sign-compare -Wno-unused-variable -Wno-unused-function -Wfatal-errors -Wno-shift-count-overflow -Wno-tautological-constant-out-of-range-compare -Wno-mismatched-tags -ftemplate-depth=512

CLANG = true

ifdef CLANG
CC = clang++
LD = clang++
CFLAGS += -Werror -DCLANG -ftemplate-depth=512
else
CC = g++
LD = g++

ifndef RELEASE
CFLAGS += -Werror
LDFLAGS += -fuse-ld=gold
endif


Expand All @@ -23,11 +20,9 @@ LDFLAGS += -Wl -L/usr/local/opt/openal-soft/lib
CFLAGS += -stdlib=libc++ -DOSX -mmacosx-version-min=10.7
CFLAGS += -DTEXT_SERIALIZATION -I/usr/local/opt/openal-soft/include
else
LDFLAGS = -Wl,-rpath=$(RPATH) -static-libstdc++
LDFLAGS += -Wl,-rpath=$(RPATH) -static-libstdc++
endif

LDFLAGS += -fuse-ld=gold

ifdef DATA_DIR
CFLAGS += -DDATA_DIR=\"$(DATA_DIR)\"
endif
Expand Down Expand Up @@ -81,13 +76,15 @@ IPATH = -I. -I./extern
CFLAGS += $(IPATH)

ifdef OSX
BOOST_LIBS = -lboost_serialization -lboost_program_options -lboost_filesystem -lboost_system -lboost_thread -lboost_chrono
BOOST_LIBS = -lboost_serialization -lboost_filesystem -lboost_system -lboost_thread -lboost_chrono -lboost_program_options
OPENGL_LIBS = -framework OpenGL
else
BOOST_LIBS = -lboost_serialization -lboost_program_options -lboost_filesystem -lboost_system
BOOST_LIBS = -lboost_serialization -lboost_filesystem -lboost_system -lboost_program_options
OPENGL_LIBS = -lGL
endif

LDFLAGS += -L/usr/local/lib

SRCS = $(shell ls -t *.cpp)

LIBS = -L/usr/lib/x86_64-linux-gnu $(OPENGL_LIBS) -lSDL2 -lopenal -lvorbis -lvorbisfile -lSDL2_image $(BOOST_LIBS) -lz -lpthread -lcurl ${LDFLAGS}
Expand Down
6 changes: 4 additions & 2 deletions Makefile-win
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ CFLAGS += $(IPATH)

SRCS = $(shell ls -t *.cpp)

LIBS = -mwindows keeper.res -lvorbisfile -lvorbis -logg -lSDL2_image -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lole32 -ldinput -lddraw -ldxguid -lwinmm -ldsound -lpsapi -lgdiplus -lshlwapi -luuid -lfreetype

ifdef AMD64
LIBS = -lmingw32 -lSDL2main -lSDL2 -mwindows -lvorbisfile -lvorbis -logg -lSDL2_image -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lole32 -ldinput -lddraw -ldxguid -lwinmm -ldsound -lpsapi -lgdiplus -lshlwapi -luuid -lfreetype -lfreeglut -lglu32 -lz -lboost_serialization-mgw49-mt-1_57 -lboost_program_options-mgw49-mt-1_57 -lboost_system-mgw49-mt-1_57 -lboost_filesystem-mgw49-mt-1_57 -lglew32 -ljpeg -lOpenAL32.dll -lsndfile -lopengl32 -lcurldll -limagehlp
LIBS += -lmingw32 -lSDL2main -lSDL2 -lfreeglut -lglu32 -lz -lboost_serialization-mgw49-mt-1_57 -lboost_program_options-mgw49-mt-1_57 -lboost_system-mgw49-mt-1_57 -lboost_filesystem-mgw49-mt-1_57 -lglew32 -ljpeg -lOpenAL32.dll -lsndfile -lopengl32 -lcurldll -limagehlp
else
LIBS = -lSDL2.dll -lSDL2main -lvorbisfile -lvorbis -logg -lSDL2_image -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lole32 -ldinput -lddraw -ldxguid -lwinmm -ldsound -lpsapi -lgdiplus -lshlwapi -luuid -lfreetype -lglut -lglu32 -lz -lboost_serialization-mgw49-mt-1_56 -lboost_program_options-mgw49-mt-1_56 -lboost_system-mgw49-mt-1_56 -lboost_filesystem-mgw49-mt-1_56 -lglew -ljpeg -lOpenAL32.dll -lsndfile -lopengl32 -lcurldll -limagehlp
LIBS += -lSDL2.dll -lSDL2main -lglut -lglu32 -lz -lboost_serialization-mgw49-mt-1_56 -lboost_program_options-mgw49-mt-1_56 -lboost_system-mgw49-mt-1_56 -lboost_filesystem-mgw49-mt-1_56 -lglew -ljpeg -lOpenAL32.dll -lsndfile -lopengl32 -lcurldll -limagehlp
endif

ifdef debug
Expand Down
26 changes: 14 additions & 12 deletions animation.cpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
#include "stdafx.h"

#include "animation.h"
#include "view_object.h"

Animation::Animation(double d) : duration(d) {}
Animation::Animation(milliseconds d) : duration(d) {}

bool Animation::isDone(double time) const {
return time > begin + duration;
bool Animation::isDone(milliseconds time) const {
return begin && time > *begin + duration;
}

void Animation::setBegin(double time) {
CHECK(begin == -1);
void Animation::setBegin(milliseconds time) {
CHECK(!begin);
begin = time;
}

void Animation::render(Renderer& r, Rectangle bounds, Vec2 origin, double time) {
CHECK(begin >= 0) << begin;
CHECK(time - begin <= duration) << time << " " << begin << " " << duration;
renderSpec(r, bounds, origin, (time - begin) / duration);
void Animation::render(Renderer& r, Rectangle bounds, Vec2 origin, milliseconds time) {
CHECK(begin);
CHECK(time - *begin <= duration) << time << " " << *begin << " " << duration;
renderSpec(r, bounds, origin, (double)(time - *begin).count() / duration.count());
}

class ThrownObject : public Animation {
public:
ThrownObject(Vec2 dir, ViewObject obj, bool sprite, Vec2 sz)
: Animation(200), direction(dir), viewObject(obj), useSprite(sprite), squareSize(sz) {}
: Animation(milliseconds{dir.length8()}), direction(dir), viewObject(obj), useSprite(sprite),
squareSize(sz) {}

virtual void renderSpec(Renderer& renderer, Rectangle bounds, Vec2 origin, double state) {
int x = origin.x + state * direction.x;
Expand All @@ -48,8 +50,8 @@ class SpriteAnim : public Animation {
Vec2 size;
Vec2 offset;
};
SpriteAnim(double frame, int tile, vector<FrameInfo> f)
: Animation(frame * f.size()), frames(f), tileNum(tile) {}
SpriteAnim(int frame, int tile, vector<FrameInfo> f)
: Animation(milliseconds{frame * f.size()}), frames(f), tileNum(tile) {}

virtual void renderSpec(Renderer& renderer, Rectangle bounds, Vec2 origin, double state) {
return;
Expand Down
19 changes: 9 additions & 10 deletions animation.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
#ifndef _ANIMATION_H
#define _ANIMATION_H
#pragma once

#include "util.h"
#include "renderer.h"
#include "view_object.h"

class ViewObject;

class Animation {
public:
void render(Renderer&, Rectangle bounds, Vec2 origin, double time);
bool isDone(double time) const;
void setBegin(double time);
void render(Renderer&, Rectangle bounds, Vec2 origin, milliseconds time);
bool isDone(milliseconds time) const;
void setBegin(milliseconds time);
static PAnimation thrownObject(Vec2 direction, ViewObject, bool useSprite, Vec2 squareSize);
static PAnimation fromId(AnimationId);

protected:
Animation(double duration);
Animation(milliseconds duration);
virtual void renderSpec(Renderer&, Rectangle bounds, Vec2 origin, double state) = 0;

private:
double begin = -1;
double duration;
optional<milliseconds> begin;
milliseconds duration;
};

#endif
4 changes: 1 addition & 3 deletions attack.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
You should have received a copy of the GNU General Public License along with this program.
If not, see http://www.gnu.org/licenses/ . */

#ifndef _ATTACK_H
#define _ATTACK_H
#pragma once

#include "enums.h"
#include "util.h"
Expand Down Expand Up @@ -45,4 +44,3 @@ class Attack {
optional<EffectType> effect;
};

#endif
4 changes: 1 addition & 3 deletions attack_level.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#ifndef _ATTACK_LEVEL_H
#define _ATTACK_LEVEL_H
#pragma once

enum class AttackLevel { LOW, MIDDLE, HIGH };

#endif
12 changes: 6 additions & 6 deletions attack_trigger.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#ifndef _ATTACK_TRIGGER_H
#define _ATTACK_TRIGGER_H
#pragma once

#include "util.h"
#include "square_type.h"
#include "furniture_type.h"

RICH_ENUM(AttackTriggerId,
POWER,
Expand All @@ -17,13 +16,14 @@ RICH_ENUM(AttackTriggerId,
PROXIMITY
);

typedef EnumVariant<AttackTriggerId, TYPES(int, SquareType),
class AttackTrigger : public EnumVariant<AttackTriggerId, TYPES(int, FurnitureType),
ASSIGN(int, AttackTriggerId::ENEMY_POPULATION, AttackTriggerId::GOLD, AttackTriggerId::TIMER),
ASSIGN(SquareType, AttackTriggerId::ROOM_BUILT)> AttackTrigger;
ASSIGN(FurnitureType, AttackTriggerId::ROOM_BUILT)> {
using EnumVariant::EnumVariant;
};

struct TriggerInfo {
AttackTrigger trigger;
double value;
};

#endif
4 changes: 1 addition & 3 deletions attack_type.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#ifndef _ATTACK_TYPE_H
#define _ATTACK_TYPE_H
#pragma once

enum class AttackType { CUT, STAB, CRUSH, PUNCH, BITE, EAT, HIT, SHOOT, SPELL, POSSESS};


#endif
27 changes: 14 additions & 13 deletions audio_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@
AudioDevice::AudioDevice() {
}

bool AudioDevice::initialize() {
static bool initialized = false;

optional<string> AudioDevice::initialize() {
if ((device = alcOpenDevice(nullptr))) {
if ((context = alcCreateContext((ALCdevice*)device, nullptr))) {
alcMakeContextCurrent((ALCcontext*)context);
alDistanceModel(AL_NONE);
return true;
initialized = true;
return none;
}
}
ALenum error = alGetError();
CHECK(!error) << "Failed to initialize audio " << alGetString(error);
return false;
return "Error code: " + toString(alGetError());
}

AudioDevice::~AudioDevice() {
Expand All @@ -35,7 +36,7 @@ AudioDevice::~AudioDevice() {

const int maxSources = 12;

#define AL(X) {X; checkError(__FILE__, __LINE__, #X); }
#define AL(X) { if (initialized) {X; checkError(__FILE__, __LINE__, #X); }}

static void checkError(const char* file, int line, const char* functionName) {
ALenum error = alGetError();
Expand All @@ -46,7 +47,7 @@ optional<OpenalId> AudioDevice::getFreeSource() {
RecursiveLock lock(mutex);
for (int i : All(sources)) {
auto& source = sources[i];
ALint state;
ALint state = 0;
AL(alGetSourcei(source.getId(), AL_SOURCE_STATE, &state));
if (state == AL_STOPPED) {
// recreating the source does a better job at cleaning up after streaming
Expand All @@ -65,7 +66,7 @@ optional<OpenalId> AudioDevice::getFreeSource() {
void AudioDevice::play(const SoundBuffer& sound, double volume, double pitch) {
RecursiveLock lock(mutex);
if (auto source = getFreeSource()) {
ALint state;
ALint state = 0;
AL(alGetSourcei(*source, AL_SOURCE_STATE, &state));
CHECK(state == AL_INITIAL) << state;
AL(alSourcei(*source, AL_BUFFER, sound.getBufferId()));
Expand Down Expand Up @@ -160,7 +161,7 @@ SoundStream::SoundStream(const char* path, double volume) : startedPlaying(false
bool SoundStream::isPlaying() const {
if (!startedPlaying)
return true;
ALint state;
ALint state = 0;
AL(alGetSourcei(source.getId(), AL_SOURCE_STATE, &state));
return state == AL_PLAYING;
}
Expand All @@ -170,7 +171,7 @@ void SoundStream::setVolume(double v) {
}

double SoundStream::getVolume() const {
float ret;
float ret = 0;
AL(alGetSourcef(source.getId(), AL_GAIN, &ret));
return ret;
}
Expand All @@ -182,7 +183,7 @@ void SoundStream::init(const char* path) {
}

void SoundStream::loop(double volume) {
int numQueued;
int numQueued = 0;
AL(alGetSourcei(source.getId(), AL_BUFFERS_QUEUED, &numQueued));
if (numQueued == 0) { /*fill and queue initial buffers*/
vector<char> data = readSoundData(*file, streamingBufferSize);
Expand All @@ -197,14 +198,14 @@ void SoundStream::loop(double volume) {
startedPlaying = true;
//CHECK(isPlaying()); fails if I unplug/plug the speaker cable...?
} else { /*refill processed buffers*/
int numProcessed;
int numProcessed = 0;
AL(alGetSourcei(source.getId(), AL_BUFFERS_PROCESSED, &numProcessed));
while (numProcessed--) {
vector<char> data = readSoundData(*file, streamingBufferSize);
if (data.size() == 0)
break;
else {
ALuint buffer;
ALuint buffer = 0;
AL(alSourceUnqueueBuffers(source.getId(), 1, &buffer));
AL(alBufferData(buffer, (info->channels > 1) ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16, data.data(),
data.size(), info->rate));
Expand Down
2 changes: 1 addition & 1 deletion audio_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class SoundStream {
class AudioDevice {
public:
AudioDevice();
bool initialize();
optional<string> initialize();
~AudioDevice();
void play(const SoundBuffer&, double volume, double pitch = 1);

Expand Down
Loading

0 comments on commit 0459ed3

Please sign in to comment.