-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Event logic #744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Event logic #744
Changes from all commits
c3a0b6c
41b2f93
cfe6580
0b006b0
238e85e
c6b7cff
6994d21
b2f7199
6f52e4f
4598ff6
0e43190
1f63378
841b7f9
3991df5
a1a1c63
e2a1ebe
a21e99a
6fe426b
7422c63
81ede4a
b4b257a
1681601
2647a1b
22e4703
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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` | ||
| - `pip3 install cython` | ||
| 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) |
| 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 |
| 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> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should agree on a project wide style for naming template parameters. |
||
| 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."); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| 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 |
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| TUBE DATATYPES | ||
| ================= | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pls move this file to |
||
|
|
||
| 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 | | ||
| +-----------------------------------------------------------+ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is broken. shall it be a table or a |
||
|
|
||
| Meaning of Flags | ||
| ---------------- | ||
|
|
||
| == DELETE == | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those headlines just show up as |
||
|
|
||
| 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. | ||
| 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 | ||
| ) |
| 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 |
| 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( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| 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 | ||
| 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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we wanna keep this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it helps understanding and playing around with the curves |
||
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
libpngis still needed. and the other distros need the ncurses package as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
libncursesshould be an optional dependency, like it is done forinotify.