这是indexloc提供的服务,不要输入任何密码
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c3a0b6c
Added tubes logic and epic tubepong
Tomatower Feb 18, 2017
41b2f93
Fixed includes and some whitespaces
Tomatower Feb 18, 2017
cfe6580
Added ncurses to ubuntu installation
Tomatower Feb 18, 2017
0b006b0
Tubes: Refactoring, Map and Types
Tomatower Apr 14, 2017
238e85e
Tube: Added queue, fixed some ugly pylint stuff
Tomatower Apr 16, 2017
c6b7cff
Tubes: Fixed tests for queue
Tomatower Apr 17, 2017
6994d21
Added tubes logic and epic tubepong
Tomatower Feb 18, 2017
b2f7199
Fixed includes and some whitespaces
Tomatower Feb 18, 2017
6f52e4f
Added ncurses to ubuntu installation
Tomatower Feb 18, 2017
4598ff6
Tubes: Refactoring, Map and Types
Tomatower Apr 14, 2017
0e43190
Tube: Added queue, fixed some ugly pylint stuff
Tomatower Apr 16, 2017
1f63378
Tubes: Fixed tests for queue
Tomatower Apr 17, 2017
841b7f9
Tubes: added tube_iterator, documentationw
Tomatower Apr 18, 2017
3991df5
Tubes: refactoring and documentation
Tomatower Apr 20, 2017
a1a1c63
Whitespace and cleanup
Tomatower Apr 28, 2017
e2a1ebe
tubes: added a few more accessors
Tomatower May 12, 2017
a21e99a
curves: renamed tubes to curves
Tomatower May 19, 2017
6fe426b
added event list
Tomatower Jun 13, 2017
7422c63
curve: getting the demo up and fancy
Tomatower Jun 24, 2017
81ede4a
curves: event concept running
Tomatower Jul 3, 2017
b4b257a
curve trigger concept running
Tomatower Jul 10, 2017
1681601
Overhaul the event system. Again. And Again.
Tomatower Jul 21, 2017
2647a1b
initial gamestate draft
Tomatower Oct 18, 2017
22e4703
cleanup
Tomatower Dec 3, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/build_instructions/ubuntu_16.04.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Prerequisite steps for Ubuntu users (Ubuntu 16.04)

- `sudo apt-get update`
- `sudo apt-get install cmake libfreetype6-dev python3-dev python3-pip libepoxy-dev libsdl2-dev libsdl2-image-dev libopusfile-dev libfontconfig1-dev libharfbuzz-dev libpng-dev opus-tools python3-pil python3-numpy python3-pygments qtdeclarative5-dev qml-module-qtquick-controls`
- `sudo apt-get install cmake libfreetype6-dev python3-dev python3-pip libepoxy-dev libsdl2-dev libsdl2-image-dev libopusfile-dev libfontconfig1-dev libharfbuzz-dev libncurses5-dev opus-tools python3-pil python3-numpy python3-pygments qtdeclarative5-dev qml-module-qtquick-controls`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

libpng is still needed. and the other distros need the ncurses package as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

libncurses should be an optional dependency, like it is done for inotify.

- `pip3 install cython`
1 change: 1 addition & 0 deletions doc/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Dependency list:
CRA python >=3.4
C cython >=0.25
C cmake >=3.1.0
CR ncurses
A numpy
A python imaging library (PIL) -> pillow
CR opengl >=2.1
Expand Down
9 changes: 7 additions & 2 deletions libopenage/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ pxdgen(
add_subdirectory("audio")
add_subdirectory("console")
add_subdirectory("coord")
add_subdirectory("curve")
add_subdirectory("cvar")
add_subdirectory("datastructure")
add_subdirectory("gui")
add_subdirectory("error")
add_subdirectory("gamestate")
add_subdirectory("gui")
add_subdirectory("input")
add_subdirectory("log")
add_subdirectory("job")
add_subdirectory("log")
add_subdirectory("pathfinding")
add_subdirectory("pyinterface")
add_subdirectory("renderer")
Expand Down Expand Up @@ -102,6 +103,9 @@ find_package(Opusfile REQUIRED)
find_package(Epoxy REQUIRED)
find_package(HarfBuzz 1.0.0 REQUIRED)

set(CURSES_NEED_NCURSES TRUE)
find_package(Curses REQUIRED)

set(QT_VERSION_REQ "5.5")
find_package(Qt5Core ${QT_VERSION_REQ} REQUIRED)
find_package(Qt5Quick ${QT_VERSION_REQ} REQUIRED)
Expand Down Expand Up @@ -190,6 +194,7 @@ target_link_libraries(libopenage
${RT_LIB}
${OGG_LIB}
${EXECINFO_LIB}
${CURSES_LIBRARIES}
# TODO: change to PUBLIC (or, alternatively, remove all keywords
# of this type) when qt cmake scripts change declarations of the
# IMPORTED libraries to GLOBAL.
Expand Down
29 changes: 29 additions & 0 deletions libopenage/curve/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

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

pxdgen(
continuous.h
curve.h
discrete.h
iterator.h
map.h
map_filter_iterator.h
queue.h
queue_filter_iterator.h
)

add_subdirectory(events)
add_subdirectory(internal)
add_subdirectory(test)
add_subdirectory(demo)
10 changes: 10 additions & 0 deletions libopenage/curve/continuous.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2017-2017 the openage authors. See copying.md for legal info.

#include "continuous.h"

namespace openage {
namespace curve {

// This file is intended to be empty

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

#pragma once

#include "internal/value_container.h"

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

namespace openage {
namespace curve {

/**
* Continuous Datatype.
* Stores a value container with continuous access.
* The bound template type _T has to implement `operator+(_T)` and
* `operator*(curve_time_t)`.
*
* pxd:
* cppclass Continuous(ValueContainer):
* _T get(const curve_time_t&) except +
*/
template<typename _T>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should agree on a project wide style for naming template parameters. _T is new to me, maybe we could do that everywhere. Needs discussion.

class Continuous : public ValueContainer<_T> {
public:
using ValueContainer<_T>::ValueContainer;
/**
* will interpolate between the keyframes linearly based on the time.
*/
_T get(const curve_time_t &) const override;
};



template <typename _T>
_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;
++nxt;

double diff_time = 0;
double offset = time - e->time;
// If we do not have a next (buffer underrun!!) we assign values
if (nxt == this->container.end()) {
// log::log(WARN << "Continuous buffer underrun. This might be bad! Assuming constant.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover, what do? probably crash :)

} else {
diff_time = nxt->time - e->time;
}

if (nxt == this->container.end() // We do not have next - this is bad
|| offset == 0 // we do not have an offset - this is performance
|| diff_time == 0) { // we do not have diff - this is division-by-zero-error
return e->value;
} else {
// Fraction between time(now) and time(next) that has elapsed
double elapsed_frac = (double)offset / (double)diff_time;
return e->value + (nxt->value - e->value) * elapsed_frac;
}
}

}} // openage::curve
10 changes: 10 additions & 0 deletions libopenage/curve/curve.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2017-2017 the openage authors. See copying.md for legal info.

#include "curve.h"

namespace openage {
namespace curve {

// This file is intended to be empty

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

#pragma once

#include <cstdint>

namespace openage {
namespace curve {

/**
* Defines the type that is used as time index.
* it has to implement all basic mathematically operations.
*
* pxd:
* ctypedef double curve_time_t
*/
typedef int64_t curve_time_t;

}} // openage::curve
120 changes: 120 additions & 0 deletions libopenage/curve/datatypes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
TUBE DATATYPES
=================
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls move this file to $root/doc/code/


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 SERIALIZATION
==================

Serialization condenses data into change sets:

Repeat the following blob:
+-----------------------------------------------------------+
| ID (24Bit) |
| flags (delete, del_after, time, time2, data, add) (8Bit) | # In the first quadruple it is stored which data fields are set.
| if (flag & time) time1 | # In the second quadruple the usage of the data is stored
| if (flag & time2) time2 | # | time | time2 | data | UNUSED | delete | add | del_after | UNUSED |
| if (flag & data) keyframe: size(16) | data |
+-----------------------------------------------------------+
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is broken. shall it be a table or a <pre>?


Meaning of Flags
----------------

== DELETE ==
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those headlines just show up as == DELETE ==, maybe you meant ## DELETE ##? otherwise, maybe ``?


After DELETE it is allowed to reuse the ID
When no Time is defined, then the deletion is "now", if TIME1 is defined, then the element will be deleted at this time.

== ADD ==

Create a new element with the given ID. Add has to have at least TIME1 and DATA set.

== DEL_AFTER ==

Delete all keyframes after TIME.

== TIME1 ==

Set the Keyframe time or the creation time of an element

== TIME2 ==

Set the Destruction time of a container element

== DATA ==

The Keyframe data prefixed by data length



Serialization of keyframes for different data types
----------------------------------------------------

Simple types: Binary Serialization of the data types, interpolation mode does not matter

Containers
For Containers DELETE_AFTER is not supported.

== Map ==

Store TIME2 as death time - if the element has a death time yet.
The ID of the object is submitted at creation as its own curve.

== Set ==

This container is simple to store only times (birth (TIME1) and death (TIME2) of each unit) and only update the keyframe data when neccesary

== Queue ==

Elements here have only one single time, so TIME2 is not used.
They can be created with ADD and removed with DELETE.
6 changes: 6 additions & 0 deletions libopenage/curve/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/curve/demo/aicontroller.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2017-2017 the openage authors. See copying.md for legal info.

#include "aicontroller.h"

namespace openage {
namespace curvepong {

std::vector<event> &AIInput::getInputs(
const std::shared_ptr<PongPlayer> &player,
const std::shared_ptr<PongBall> &ball,
const curve::curve_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::curvepong
24 changes: 24 additions & 0 deletions libopenage/curve/demo/aicontroller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2017-2017 the openage authors. See copying.md for legal info.

#pragma once

#include "config.h"
#include "gamestate.h"

#include <vector>

namespace openage {
namespace curvepong {

class AIInput {
public:
std::vector<event> &getInputs(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_inputs

const std::shared_ptr<PongPlayer> &player,
const std::shared_ptr<PongBall> &ball,
const curve::curve_time_t &now);

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

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

#pragma once

// Define this to draw an ncurses based demo.
// Without the GUI flag, just a trace of event is printed out
#define GUI

// If this is defined, player 1 can be played with the arrow keys.
// else the player is replaced by an AI.
//#define HUMAN

// This can take the following values:
// 0: run in real time with real deltas
// 1: run very slow
// 2: run very fast
#define REALTIME 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we wanna keep this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it helps understanding and playing around with the curves

10 changes: 10 additions & 0 deletions libopenage/curve/demo/gamestate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2017-2017 the openage authors. See copying.md for legal info.

#include "gamestate.h"

namespace openage {
namespace curvepong {

// This file is intentionally left empty

}} // openage::curvepong
Loading