Skip to content

Commit

Permalink
Merge branch 'tubes' of github.com:Tomatower/openage into tubes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomatower committed Jun 12, 2017
2 parents fa4569f + f2bd2ab commit 7a11749
Show file tree
Hide file tree
Showing 51 changed files with 2,159 additions and 10 deletions.
1 change: 1 addition & 0 deletions libopenage/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ add_subdirectory("rng")
add_subdirectory("shader")
add_subdirectory("terrain")
add_subdirectory("testing")
add_subdirectory("tube")
add_subdirectory("unit")
add_subdirectory("util")

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

add_sources(libopenage
internal/keyframe_container.cpp
internal/value_container.cpp
queue.cpp
continuous.cpp
discrete.cpp
curve.cpp
discrete.cpp
iterator.cpp
map.cpp
map_filter_iterator.cpp
queue.cpp
queue.cpp
queue_filter_iterator.cpp
)

add_subdirectory(test)
add_subdirectory(demo)
add_subdirectory(internal)
add_subdirectory(test)
2 changes: 2 additions & 0 deletions libopenage/curve/curve.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#pragma once

#include <limits>

namespace openage {
namespace curve {

Expand Down
5 changes: 3 additions & 2 deletions libopenage/curve/demo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
add_sources (libopenage
aicontroller.cpp
gamestate.cpp
gui.cpp
main.cpp
physics.cpp
gui.cpp
aicontroller.cpp
)
3 changes: 3 additions & 0 deletions libopenage/curve/demo/gamestate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Copyright 2017-2017 the openage authors. See copying.md for legal info.

#include "gamestate.h"
4 changes: 4 additions & 0 deletions libopenage/curve/internal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add_sources(libopenage
keyframe_container.cpp
value_container.cpp
)
3 changes: 3 additions & 0 deletions libopenage/curve/iterator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Copyright 2017-2017 the openage authors. See copying.md for legal info.

#include "iterator.h"
10 changes: 7 additions & 3 deletions libopenage/curve/iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ namespace curve {
template <typename val_t,
class container_t,
class iterator_t = typename container_t::iterator>
class CurveIterator :
public std::iterator<std::forward_iterator_tag, val_t >
{
class CurveIterator {
public:
virtual val_t &value() const = 0;
virtual bool valid() const = 0;

CurveIterator() :
base{},
container_end{},
from{-std::numeric_limits<curve_time_t>::infinity()},
to{+std::numeric_limits<curve_time_t>::infinity()} {}

CurveIterator(const CurveIterator &rhs) :
base{rhs.base},
container_end{rhs.container_end},
Expand Down
3 changes: 3 additions & 0 deletions libopenage/curve/map.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Copyright 2017-2017 the openage authors. See copying.md for legal info.

#include "map.h"
1 change: 1 addition & 0 deletions libopenage/curve/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#pragma once

#include <iostream>
#include <unordered_map>

#include "curve.h"
Expand Down
3 changes: 3 additions & 0 deletions libopenage/curve/map_filter_iterator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Copyright 2017-2017 the openage authors. See copying.md for legal info.

#include "map_filter_iterator.h"
3 changes: 3 additions & 0 deletions libopenage/curve/queue_filter_iterator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Copyright 2017-2017 the openage authors. See copying.md for legal info.

#include "queue_filter_iterator.h"
31 changes: 31 additions & 0 deletions libopenage/tube/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

*build*
16 changes: 16 additions & 0 deletions libopenage/tube/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

add_sources(libopenage
keyframe_container.cpp
#tube_container_iterator.cpp
tube_event.cpp
tube_queue.cpp
tube_object.cpp
tube_objectlist.cpp
tube_continuous.cpp
tube_discrete.cpp
tube.cpp
value_container.cpp
)

add_subdirectory(test)
add_subdirectory(demo)
57 changes: 57 additions & 0 deletions libopenage/tube/datatypes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
TUBE DATATYPES
=================

This document describes the datatypes that should be available within the tubes library.
They consists of simple, single dimensinal types and list types.

This document is intended for brainstorming on needed datatypes.

Simple Types
------------

Simple types only have one distinct value at a specific point in time.

Discrete Interpolation
----------------------

"Step function" style values. These types adopt the new value exactly at the point in time changed.
They are useful for example for values like unit capacity, hitpoints, resource count, ...

Linear Interpolation
--------------------

Linear connections between two points. These types have to overload the operators + and *, since these
are used to interpolate between t\_n and t\_n+1. These values change consistently over time, if t\_n+1 exists.
These are useful for example for unit position, building progress, ...

Nyan Values
--------------

This container keeps track of nyan objects over time and their respective properties.

Container Types
===============

Container types hold lists of items at any given time. They store a creation and a deletion timestamp for each item, and offer iteration logic to traverse the active elements in the container.

Map Container
-------------

The map container stores items based on an unique identifier mapped to an item. It keeps track of the existence of the item. No guaranteed order of items within this container is given (similar to std::unordered_map).
This container is useful for example for unit lists ...

Set Container
----------------

The set container stores items, just as a normal array would. It keeps track of the existence of the items, but does not guarentee any particular ordering (similar to std::unordered_set).
This Container is useful for any non-indexed data structures, for example projectiles.

Queue Container
---------------

The queue container represents a random access queue while keeping the ordering of the queue.
It is usually used for pushing in the back and popping at the front (FIFO-Stlye) but offers random access insertion and deletion as well.
This container is useful for example for action queues and buildung queues.

TUBE FILES
============
6 changes: 6 additions & 0 deletions libopenage/tube/demo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
add_sources (libopenage
main.cpp
physics.cpp
gui.cpp
aicontroller.cpp
)
30 changes: 30 additions & 0 deletions libopenage/tube/demo/aicontroller.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2015-2017 the openage authors. See copying.md for legal info.

#include "aicontroller.h"

namespace openage {
namespace tubepong {

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

auto position = player.position.get(now);

// Yes i know, there is /3 used - instead of the logical /2 - this is to
// create a small safety boundary of 1/3 for enhanced fancyness

// Ball is below position
if (ball.position.get(now)[1] > position + player.size.get(now) / 3) {
event_cache.push_back(event(player.id, event::DOWN));
} else if (ball.position.get(now)[1] < position - player.size.get(now) / 3) {
// Ball is above position
event_cache.push_back(event(player.id, event::UP));
}

return this->event_cache;
}

}} // openage::tubepong
23 changes: 23 additions & 0 deletions libopenage/tube/demo/aicontroller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2017-2017 the openage authors. See copying.md for legal info.

#pragma once

#include <vector>

#include "gamestate.h"

namespace openage {
namespace tubepong {

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

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

}} // openage::tubepong
59 changes: 59 additions & 0 deletions libopenage/tube/demo/gamestate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2015-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 "../../util/vector.h"

namespace openage {
namespace tubepong {

struct event {
int player;
enum state_e {
UP, DOWN, START, IDLE, LOST
} state;
event(int id, state_e s) : player(id), state(s) {}
event() : player(0), state(IDLE) {}
};

class PongPlayer : public tube::TubeObject {
public:
PongPlayer() {
speed.set_drop(0, 1);
position.set_drop(0, 0.5);
lives.set_drop(0, 1);
state.set_drop(0, event(0, event::IDLE));
size.set_drop(0, 0.1);
y = 0;
id = 0;
}

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

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

class PongState {
public:
PongPlayer p1;
PongPlayer p2;

PongBall ball;

util::Vector<2> resolution;
};

}} // openage::tubepong

0 comments on commit 7a11749

Please sign in to comment.