Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
spidamoo committed Nov 20, 2013
1 parent d412781 commit cdc3e61
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 37 deletions.
7 changes: 6 additions & 1 deletion SoDlib/include/Effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ class Effect
protected:
Game* game;
b2Vec2 position, prevPosition, speed;
float time;
float time;

exprtk::expression<float> speedExpr, angleExpr, rExpr, gExpr, bExpr, aExpr,
timeExpr, amountExpr, durationExpr;

EffectPrototype* prototype;
private:
};
#define EFFECT_H_COMPLETE
Expand Down
12 changes: 7 additions & 5 deletions SoDlib/include/EffectPrototype.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ const int EFFECT_AREA_TYPE_CIRCLE = 3;
class EffectPrototype
{
public:
EffectPrototype();
EffectPrototype(Game* game);
virtual ~EffectPrototype();

void loadFromXml(TiXmlElement* xml);
protected:
protected:
Game* game;

std::string speedFormula, angleFormula, rFormula, gFormula, bFormula, aFormula,
timeFormula, amountFormula, durationFormula;

exprtk::expression startSpeedExpr, startAngleExpr, startRExpr, startGExpr, startBExpr,
startAExpr, startTimeExpr, startAmountExpr, startDurationExpr;
exprtk::symbol_table symbolTable;
exprtk::expression<float> startSpeedExpr, startAngleExpr, startRExpr, startGExpr, startBExpr,
startAExpr, startTimeExpr, startAmountExpr, startDurationExpr, startXExpr, startYExpr;
exprtk::symbol_table<float> symbolTable;

int positionType, areaType;
private:
Expand Down
7 changes: 5 additions & 2 deletions SoDlib/include/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ class Game

b2Vec2 getGravity();
float getTimeStep();


exprtk::parser<float>* exprtkParser;
protected:
b2World* world;
HGE* hge;
Expand Down Expand Up @@ -115,7 +116,9 @@ class Game
DebugDraw* debugDraw;

float pixelsPerMeter, scaleFactor;
b2Vec2 gravity;
b2Vec2 gravity;

exprtk::parser<float>* getExprtkParser();
private:
};

Expand Down
79 changes: 51 additions & 28 deletions SoDlib/src/EffectPrototype.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "EffectPrototype.h"

EffectPrototype::EffectPrototype()
EffectPrototype::EffectPrototype(Game* game)
{
//ctor
this->game = game;
}

EffectPrototype::~EffectPrototype()
Expand Down Expand Up @@ -59,50 +59,73 @@ void EffectPrototype::loadFromXml(TiXmlElement* xml)
}


startSpeedExpr.register_symbol_table(symbolTable);
startAngleExpr.register_symbol_table(symbolTable);
startRExpr.register_symbol_table(symbolTable);
startGExpr.register_symbol_table(symbolTable);
startBExpr.register_symbol_table(symbolTable);
startAExpr.register_symbol_table(symbolTable);
startTimeExpr.register_symbol_table(symbolTable);
startAmountExpr.register_symbol_table(symbolTable);
startDurationExpr.register_symbol_table(symbolTable);

startXExpr.register_symbol_table(symbolTable);
startYExpr.register_symbol_table(symbolTable);

if (xml->Attribute("start_speed_formula")) {
speedFormula = xml->Attribute("speed_formula");
game->getExprtkParser()->compile(xml->Attribute("start_speed_formula"), startSpeedExpr);
} else {
speedFormula = "";
game->getExprtkParser()->compile("0", startSpeedExpr);
}
if (xml->Attribute("angle_formula")) {
angleFormula = xml->Attribute("angle_formula");
if (xml->Attribute("start_angle_formula")) {
game->getExprtkParser()->compile(xml->Attribute("start_angle_formula"), startAngleExpr);
} else {
angleFormula = "";
game->getExprtkParser()->compile("0", startAngleExpr);
}
if (xml->Attribute("r_formula")) {
rFormula = xml->Attribute("r_formula");
if (xml->Attribute("start_r_formula")) {
game->getExprtkParser()->compile(xml->Attribute("start_r_formula"), startRExpr);
} else {
rFormula = "";
game->getExprtkParser()->compile("0", startRExpr);
}
if (xml->Attribute("g_formula")) {
gFormula = xml->Attribute("g_formula");
if (xml->Attribute("start_g_formula")) {
game->getExprtkParser()->compile(xml->Attribute("start_g_formula"), startGExpr);
} else {
gFormula = "";
game->getExprtkParser()->compile("0", startGExpr);
}
if (xml->Attribute("b_formula")) {
bFormula = xml->Attribute("b_formula");
if (xml->Attribute("start_b_formula")) {
game->getExprtkParser()->compile(xml->Attribute("start_b_formula"), startBExpr);
} else {
bFormula = "";
game->getExprtkParser()->compile("0", startBExpr);
}
if (xml->Attribute("a_formula")) {
aFormula = xml->Attribute("a_formula");
if (xml->Attribute("start_a_formula")) {
game->getExprtkParser()->compile(xml->Attribute("start_a_formula"), startAExpr);
} else {
aFormula = "";
game->getExprtkParser()->compile("0", startAExpr);
}
if (xml->Attribute("time_formula")) {
timeFormula = xml->Attribute("time_formula");
if (xml->Attribute("start_time_formula")) {
game->getExprtkParser()->compile(xml->Attribute("start_time_formula"), startTimeExpr);
} else {
timeFormula = "";
game->getExprtkParser()->compile("0", startTimeExpr);
}
if (xml->Attribute("amount_formula")) {
amountFormula = xml->Attribute("amount_formula");
if (xml->Attribute("start_amount_formula")) {
game->getExprtkParser()->compile(xml->Attribute("start_amount_formula"), startAmountExpr);
} else {
amountFormula = "";
game->getExprtkParser()->compile("0", startAmountExpr);
}
if (xml->Attribute("duration_formula")) {
durationFormula = xml->Attribute("duration_formula");
if (xml->Attribute("start_duration_formula")) {
game->getExprtkParser()->compile(xml->Attribute("start_duration_formula"), startDurationExpr);
} else {
durationFormula = "";
game->getExprtkParser()->compile("0", startDurationExpr);
}

if (xml->Attribute("start_x_formula")) {
game->getExprtkParser()->compile(xml->Attribute("start_x_formula"), startXExpr);
} else {
game->getExprtkParser()->compile("0", startXExpr);
}
if (xml->Attribute("start_y_formula")) {
game->getExprtkParser()->compile(xml->Attribute("start_y_formula"), startYExpr);
} else {
game->getExprtkParser()->compile("0", startYExpr);
}
}
9 changes: 8 additions & 1 deletion SoDlib/src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ Game::Game(HGE * hge)

gravity = b2Vec2(0, 20);

mapWidth = 10; mapHeight = 10;
mapWidth = 10; mapHeight = 10;

exprtkParser = new exprtk::parser<float>();

//debugDraw = new DebugDraw(this);
//world->SetDebugDraw((b2Draw*)debugDraw);
Expand Down Expand Up @@ -850,3 +852,8 @@ float distanceToSegment(float x1, float y1, float x2, float y2, float pointX, fl
///returning shortest distance
return sqrt(diffX * diffX + diffY * diffY);
}

exprtk::parser<float>* Game::getExprtkParser()
{
return exprtkParser;
}

0 comments on commit cdc3e61

Please sign in to comment.