Update README

This commit is contained in:
Dawid Drozd 2017-08-06 16:32:09 +02:00
parent 94973b5779
commit a46362bc6b
2 changed files with 13 additions and 11 deletions

View File

@ -14,13 +14,13 @@ from [cocos2d-x](https://github.com/cocos2d/cocos2d-x) library. Of course C++11
EventBus is:
- Fast
- Easy to use
- Strong typed
- Strongly typed
- Free
- Decouples notification senders and receivers
# Usage
Notify by Event object
Notify by Event object:
```cpp
Dexode::EventBus bus;
Dexode::Event<int> simpleEvent{"simple"};
@ -28,14 +28,14 @@ Dexode::Event<int> simpleEvent{"simple"};
bus.notify(simpleEvent, 2);//Everyone who listens will receive this notification.
```
Notify without Event object
Notify without Event object:
```cpp
Dexode::EventBus bus;
//...
bus.notify<int>("simple", 2);//Everyone who listens will receive this notification.
```
Lambda listener
Lambda listener:
```cpp
Dexode::EventBus bus;
//...
@ -47,7 +47,7 @@ bus.unlistenAll(token);
```
Listener is identified by `token`. Token is returned from EventBus::listen methods.
We can register multiple listeners on one token.
We can register multiple listeners on one token:
```cpp
Dexode::EventBus bus;
Dexode::Event<int> event{"simple"};
@ -64,7 +64,7 @@ bus.unlistenAll(token);//Now those two lambdas will be removed from listeners
```
If you don't want handle manually with `token` you can use `EventCollector` class.
It is useful when we want have multiple listen in one class. So above example could look like this:
It is useful when we want to have multiple listen in one class. So above example could look like this:
```cpp
Dexode::EventBus bus;
@ -82,6 +82,7 @@ collector.listen(event, [](int value) // another listener
collector.unlistenAll();//Now those two lambdas will be removed from listeners
```
Or as component of class:
```cpp
class Example
{
@ -131,7 +132,7 @@ SET_TARGET_PROPERTIES(MyExecutable PROPERTIES
TARGET_LINK_LIBRARIES(MyExecutable PUBLIC Dexode::EventBus)
```
Also if you want you can install library and add it any other way you want.
Also if you want you can install library and add it at any way you want.
# Performance
@ -148,6 +149,7 @@ check10NotificationsFor1kListeners_CCNotificationCenter 11172 ns
- [stanislawkabacinski](https://github.com/stanislawkabacinski) for fixing windows ;) [53d5026](https://github.com/gelldur/EventBus/commit/53d5026cad24810e82cd8d4a43d58cbfe329c502)
- [kuhar](https://github.com/kuhar) for his advice and suggestions for EventBus
- [swietlana](https://github.com/swietlana) for english correction and support ;)
- [ruslo](https://github.com/ruslo) for this great example: https://github.com/forexample/package-example
# License

View File

@ -26,9 +26,9 @@ checkSimpleNotification 6 ns 6 ns 116492914
So below all numbers are in release.
This library as you can read in main README.md was inspured by [CCNotificationCenter](https://github.com/cocos2d/cocos2d-x/blob/v2/cocos2dx/support/CCNotificationCenter.h) from cocos2d-x game engine.
So i want to present comparision of performance of this two. Of course this is only showcase.
I don't want to add submodule of cocos2d-x so simply i run it only and present results. Cocos2d-x was also build as release. If you want to repeat it here are steps i follow:
This library as you can read in main README.md was inspired by [CCNotificationCenter](https://github.com/cocos2d/cocos2d-x/blob/v2/cocos2dx/support/CCNotificationCenter.h) from cocos2d-x game engine.
So I want to present comparision of performance of this two. Of course this is only showcase.
I don't want to add submodule of cocos2d-x so simply I run it only and present results. Cocos2d-x was also build as release. If you want to repeat it here are steps I followed:
```commandline
cd performance # From root of this project
git clone -b v2 https://github.com/cocos2d/cocos2d-x.git #this can take some time :/ it need to download ~900 MB
@ -80,4 +80,4 @@ checkSimpleNotification 7 ns
checkSimpleNotification_EventBus2 5 ns 5 ns 144959897 sum=552.978M
checkSimpleNotification_CCNotificationCenter 172 ns 172 ns 4179021 sum=15.9417M
```
So comparing to CCNotificationCenter, EventBus is something like ~10x FASTER specially when we have more unique notifications.
So comparing to CCNotificationCenter, EventBus is something like ~10x FASTER especially when we have more unique notifications.