Skip to content

Commit

Permalink
curves: renamed tubes to curves
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomatower committed May 19, 2017
1 parent c053562 commit fa4569f
Show file tree
Hide file tree
Showing 43 changed files with 405 additions and 497 deletions.
2 changes: 1 addition & 1 deletion libopenage/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pxdgen(
add_subdirectory("audio")
add_subdirectory("console")
add_subdirectory("coord")
add_subdirectory("curve")
add_subdirectory("cvar")
add_subdirectory("datastructure")
add_subdirectory("error")
Expand All @@ -47,7 +48,6 @@ add_subdirectory("rng")
add_subdirectory("shader")
add_subdirectory("terrain")
add_subdirectory("testing")
add_subdirectory("tube")
add_subdirectory("unit")
add_subdirectory("util")

Expand Down
12 changes: 12 additions & 0 deletions libopenage/curve/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

add_sources(libopenage
internal/keyframe_container.cpp
internal/value_container.cpp
queue.cpp
continuous.cpp
discrete.cpp
curve.cpp
)

add_subdirectory(test)
add_subdirectory(demo)
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2017-2017 the openage authors. See copying.md for legal info.

#include "tube_object.h"
#include "continuous.h"

namespace openage {
namespace tube {
namespace curve {

}} // openage::tube
}} // openage::curve
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

#pragma once

#include "value_container.h"
#include "internal/value_container.h"

#include "../log/log.h"

namespace openage {
namespace tube {
namespace curve {

template<typename _T>
class Continuous : public ValueContainer<_T> {
public:
_T get(const tube_time_t &) const override;
_T get(const curve_time_t &) const override;
};

template <typename _T>
_T Continuous<_T>::get(const tube_time_t &time) const {
_T Continuous<_T>::get(const curve_time_t &time) const {
auto e = this->container.last(time, this->last_element);
this->last_element = e;
auto nxt = e;
Expand All @@ -42,4 +42,4 @@ _T Continuous<_T>::get(const tube_time_t &time) const {
}
}

}} // openage::tube
}} // openage::curve
6 changes: 3 additions & 3 deletions libopenage/tube/tube_event.h → libopenage/curve/curve.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2017-2017 the openage authors. See copying.md for legal info.

#pragma once
#include "curve.h"

namespace openage {
namespace tube {
namespace curve {

}} // openage::tube
}} // openage::curve
12 changes: 6 additions & 6 deletions libopenage/tube/tube.h → libopenage/curve/curve.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
#pragma once

namespace openage {
namespace tube {
namespace curve {

typedef float tube_time_t;
typedef float curve_time_t;
/*
template <class _T>
tube_time_t time(const _T &t) {
curve_time_t time(const _T &t) {
return t.time();
}
template <class _T>
tube_time_t existent_from (const _T &t) {
curve_time_t existent_from (const _T &t) {
return t.existent_from();
}
template <class _T>
tube_time_t existent_until (const _T &t) {
curve_time_t existent_until (const _T &t) {
return t.existent_until();
}
*/
}} // openage::tube
}} // openage::curve
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
#include "aicontroller.h"

namespace openage {
namespace tubepong {
namespace curvepong {

std::vector<event> &AIInput::getInputs(
const PongPlayer &player,
const PongBall &ball,
const tube::tube_time_t &now) {
const curve::curve_time_t &now) {
this->event_cache.clear();

auto position = player.position.get(now);
Expand All @@ -27,4 +27,4 @@ std::vector<event> &AIInput::getInputs(
return this->event_cache;
}

}} // openage::tubepong
}} // openage::curvepong
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
#include "gamestate.h"

namespace openage {
namespace tubepong {
namespace curvepong {

class AIInput {
public:
std::vector<event> &getInputs(
const PongPlayer &player,
const PongBall &ball,
const tube::tube_time_t &now);
const curve::curve_time_t &now);

private:
std::vector<event> event_cache;
};

}} // openage::tubepong
}} // openage::curvepong
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Copyright 2015-2017 the openage authors. See copying.md for legal info.
// Copyright 2017-2017 the openage authors. See copying.md for legal info.

#pragma once

#include "../tube_continuous.h"
#include "../tube_discrete.h"
#include "../tube_object.h"
#include "../continuous.h"
#include "../discrete.h"
#include "../../util/vector.h"

namespace openage {
namespace tubepong {
namespace curvepong {

struct event {
int player;
Expand All @@ -19,7 +18,7 @@ struct event {
event() : player(0), state(IDLE) {}
};

class PongPlayer : public tube::TubeObject {
class PongPlayer {
public:
PongPlayer() {
speed.set_drop(0, 1);
Expand All @@ -31,19 +30,19 @@ class PongPlayer : public tube::TubeObject {
id = 0;
}

tube::Discrete<float> speed;
tube::Continuous<float> position;
tube::Discrete<int> lives;
tube::Discrete<event> state;
tube::Discrete<float> size;
curve::Discrete<float> speed;
curve::Continuous<float> position;
curve::Discrete<int> lives;
curve::Discrete<event> state;
curve::Discrete<float> size;
float y;
int id;
};

class PongBall : public tube::TubeObject {
class PongBall {
public:
tube::Discrete<util::Vector<2>> speed;
tube::Continuous<util::Vector<2>> position;
curve::Discrete<util::Vector<2>> speed;
curve::Continuous<util::Vector<2>> position;
};

class PongState {
Expand All @@ -56,4 +55,4 @@ class PongState {
util::Vector<2> resolution;
};

}} // openage::tubepong
}} // openage::curvepong
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <stdio.h>

namespace openage {
namespace tubepong {
namespace curvepong {

std::vector<event> &Gui::getInputs(const PongPlayer &player) {
input_cache.clear();
Expand Down Expand Up @@ -83,7 +83,7 @@ Gui::Gui() {
getch();
}

void Gui::draw(PongState &state, const tube::tube_time_t &now) {
void Gui::draw(PongState &state, const curve::curve_time_t &now) {
erase();
// clear();
// Print Score
Expand Down Expand Up @@ -160,4 +160,4 @@ void Gui::draw_ball(util::Vector<2> pos, int idx) {
standend();
}
}
} // openage::tubepong
} // openage::curvepong
6 changes: 3 additions & 3 deletions libopenage/tube/demo/gui.h → libopenage/curve/demo/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
#include "gamestate.h"

namespace openage {
namespace tubepong {
namespace curvepong {


class Gui {

public:
Gui();
std::vector<event> &getInputs(const PongPlayer &player);
void draw(PongState &state, const tube::tube_time_t &now);
void draw(PongState &state, const curve::curve_time_t &now);
void draw_ball(util::Vector<2> ball, int idx);

private:
std::vector<event> input_cache;
};

}} // openage::tubepong
}} // openage::curvepong
14 changes: 7 additions & 7 deletions libopenage/tube/demo/main.cpp → libopenage/curve/demo/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
typedef std::chrono::high_resolution_clock Clock;

namespace openage {
namespace tubepong {
namespace curvepong {

int demo() {
// Restart forever
tubepong::Gui gui;
tubepong::Physics phys;
tubepong::AIInput ai;
curvepong::Gui gui;
curvepong::Physics phys;
curvepong::AIInput ai;
bool running = true;

while (running) {
tubepong::PongState state;
tube::tube_time_t now = 1;
curvepong::PongState state;
curve::curve_time_t now = 1;

state.p1.lives.set_drop(now, 3);
state.p1.id = 0;
Expand Down Expand Up @@ -80,4 +80,4 @@ int demo() {
return 0;
}
}
} // openage::tubepong
} // openage::curvepong
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
#include <cmath>

namespace openage {
namespace tubepong {
namespace curvepong {

const float extrapolating_time = 100.0f;
const int init_recursion_limit = 50;

void Physics::processInput(PongState &state, PongPlayer &player, std::vector<event> &events, const tube::tube_time_t &now) {
void Physics::processInput(PongState &state, PongPlayer &player, std::vector<event> &events, const curve::curve_time_t &now) {
for (auto evnt : events) {
//Process only if the future has changed
if (player.state.get(now).state != evnt.state) {
Expand Down Expand Up @@ -57,7 +57,7 @@ void Physics::processInput(PongState &state, PongPlayer &player, std::vector<eve
}
}

void Physics::update(PongState &state, const tube::tube_time_t &now) {
void Physics::update(PongState &state, const curve::curve_time_t &now) {
auto pos = state.ball.position.get(now);
//Handle panel p1
if (pos[0] <= 1
Expand Down Expand Up @@ -99,7 +99,7 @@ void Physics::update(PongState &state, const tube::tube_time_t &now) {
}


void Physics::update_ball(PongState &state, const tube::tube_time_t &now, int recursion_limit) {
void Physics::update_ball(PongState &state, const curve::curve_time_t &now, int recursion_limit) {
//calculate the ball takes to hit a wall.
auto speed = state.ball.speed.get(now);
auto pos = state.ball.position.get(now);
Expand Down Expand Up @@ -133,4 +133,4 @@ void Physics::update_ball(PongState &state, const tube::tube_time_t &now, int re
}
}

}} // openage::tubepong
}} // openage::curvepong
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
#include <vector>

#include "gamestate.h"
#include "../tube.h"
#include "../curve.h"

namespace openage {
namespace tubepong {
namespace curvepong {

class Physics {
public:
void processInput(PongState &, PongPlayer &, std::vector<event> &events, const tube::tube_time_t &now);
void update(PongState &, const tube::tube_time_t &);
void processInput(PongState &, PongPlayer &, std::vector<event> &events, const curve::curve_time_t &now);
void update(PongState &, const curve::curve_time_t &);
protected:
void update_ball(PongState &, const tube::tube_time_t &, int recursion_limit);
void update_ball(PongState &, const curve::curve_time_t &, int recursion_limit);
};

}} // openage::tubepong
}} // openage::curvepong
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2017-2017 the openage authors. See copying.md for legal info.

#include "tube_event.h"
#include "discrete.h"

namespace openage {
namespace tube {
namespace curve {

}} // openage::tube
}} // openage::curve
10 changes: 5 additions & 5 deletions libopenage/tube/tube_discrete.h → libopenage/curve/discrete.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@

#pragma once

#include "value_container.h"
#include "internal/value_container.h"

namespace openage {
namespace tube {
namespace curve {

template<typename _T>
class Discrete : public ValueContainer<_T> {
public:
_T get(const tube_time_t &) const override;
_T get(const curve_time_t &) const override;
};

template <typename _T>
_T Discrete<_T>::get(const tube_time_t &time) const {
_T Discrete<_T>::get(const curve_time_t &time) const {
auto e = this->container.last(time, this->last_element);
this->last_element = e; // TODO if Cacheing?
return e->value;
}

}} // openage::tube
}} // openage::curve
Loading

0 comments on commit fa4569f

Please sign in to comment.