-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
80 lines (69 loc) · 2.11 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "cinder/app/App.h"
#include "cinder/app/RendererGl.h"
#include "cinder/gl/gl.h"
#include "dftrTcpClient.h"
#include "generative/dftrHabitat.h"
class Drifter : public ci::app::App
{
public:
void setup() override;
void mouseDown( ci::app::MouseEvent event ) override;
void keyDown( ci::app::KeyEvent event ) override;
void update() override;
void draw() override;
void ConnectTCPSocket(); //just for testing at this time
private:
drifter::network::TCPClient _tcpClient;
std::unique_ptr<drifter::generative::Habitat> _habitat;
};
void Drifter::ConnectTCPSocket()
{
std::function<void( const Json::Value & )> msgCB = [&]( const Json::Value & jsonVal ) {
std::cout << "got msg: " << jsonVal << std::endl;
};
drifter::network::MsgHandlerRef msgHandlerRef = std::make_shared<drifter::network::MsgHandler>();
msgHandlerRef->SetInputCB( [&]( const Json::Value & jsonVal ) {
std::cout << "got message in main class: " << jsonVal.toStyledString() << std::endl;
});
msgHandlerRef->SetSendFunc( [&]( Json::Value & jsonVal ) {
_tcpClient.Send( jsonVal );
});
_tcpClient.SetMsgHandler( msgHandlerRef );
std::cout << "connecting to port 8888..." << std::endl;
_tcpClient.Connect( "localhost", (uint16_t)8888 );
}
void Drifter::setup()
{
using namespace ci;
using namespace ci::app;
using namespace drifter::generative;
_habitat = std::make_unique<Habitat>( 300, 300 );
_habitat->Populate();
}
void Drifter::mouseDown( ci::app::MouseEvent event )
{}
void Drifter::keyDown( ci::app::KeyEvent event )
{
char eventChar = event.getChar();
switch ( eventChar ) {
case 'p':
_habitat->Populate();
break;
case 'u':
_habitat->Update();
break;
}
}
void Drifter::update()
{}
void Drifter::draw()
{
using namespace ci;
using namespace ci::gl;
using namespace drifter::generative;
clear();
_habitat->Draw();
}
CINDER_APP( Drifter, ci::app::RendererGl(), [&]( ci::app::App::Settings * settings ) {
settings->setWindowSize( 300, 300 );
})