2010-11-12 16:16:22 +01:00
|
|
|
#include <glibmm.h>
|
|
|
|
#include <vector>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "defines.h"
|
|
|
|
#include "Buffer.h"
|
|
|
|
#include "Buffers.h"
|
|
|
|
|
|
|
|
#define NUMTHREADS 20
|
|
|
|
#define USECS 1000
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
// we use a pointer because we can only use objects from the threading library
|
|
|
|
// once the threading has been initialised, this is only done in main.
|
|
|
|
Buffers* buffers;
|
|
|
|
|
|
|
|
void reader(void);
|
|
|
|
void writer(void);
|
|
|
|
|
2013-07-15 22:39:25 +02:00
|
|
|
int main(void)
|
2010-11-12 16:16:22 +01:00
|
|
|
{
|
|
|
|
srand( time(NULL) );
|
2013-07-15 22:39:25 +02:00
|
|
|
Glib::init();
|
2010-11-12 16:16:22 +01:00
|
|
|
|
|
|
|
// our main loop with support for signals and all that jazz
|
|
|
|
//Glib::RefPtr<Glib::MainLoop> Main = Glib::MainLoop::create();
|
2013-07-15 22:39:25 +02:00
|
|
|
|
2010-11-12 16:16:22 +01:00
|
|
|
buffers = new Buffers(NUMBUFS);
|
|
|
|
|
|
|
|
vector<Glib::Thread*> readers;
|
|
|
|
vector<Glib::Thread*> writers;
|
|
|
|
|
|
|
|
for(int i = 0; i < NUMTHREADS; i++)
|
|
|
|
{
|
2013-07-15 22:39:25 +02:00
|
|
|
readers.push_back( Glib::Threads::Thread::create( sigc::ptr_fun( &reader), false ) );
|
|
|
|
writers.push_back( Glib::Threads::Thread::create( sigc::ptr_fun( &writer), false ) );
|
2010-11-12 16:16:22 +01:00
|
|
|
}
|
2013-07-15 22:39:25 +02:00
|
|
|
|
2010-11-12 16:16:22 +01:00
|
|
|
//Main->run();
|
2013-07-15 22:39:25 +02:00
|
|
|
|
2010-11-12 16:16:22 +01:00
|
|
|
int count = 0;
|
|
|
|
while(1) {
|
|
|
|
count++;
|
|
|
|
if( count % 100 == 0 )
|
|
|
|
{
|
|
|
|
frame_t frame = buffers->get(rand()%NUMBUFS)->get();
|
|
|
|
for(int i = 0; i < HEIGHT; i++)
|
|
|
|
{
|
|
|
|
for(int j = 0; j < WIDTH; j++)
|
|
|
|
cout << ((frame.windows[i][j] >= 120) ? 'X' : '.');
|
|
|
|
cout << endl;
|
|
|
|
}
|
|
|
|
cout << endl;
|
2013-07-15 22:39:25 +02:00
|
|
|
|
2010-11-12 16:16:22 +01:00
|
|
|
for(int i = 0; i < SEGWIDTH; i++)
|
|
|
|
cout << frame.segments[i].r;
|
|
|
|
cout << endl << endl;
|
|
|
|
}
|
2013-07-15 22:39:25 +02:00
|
|
|
Glib::usleep( 10000 );
|
2010-11-12 16:16:22 +01:00
|
|
|
}//*/
|
2013-07-15 22:39:25 +02:00
|
|
|
|
2010-11-12 16:16:22 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-15 22:39:25 +02:00
|
|
|
void reader(void)
|
2010-11-12 16:16:22 +01:00
|
|
|
{
|
|
|
|
bool quit = false;
|
|
|
|
frame_t frame;
|
|
|
|
int bufnum = 0;
|
|
|
|
while( !quit )
|
2013-07-15 22:39:25 +02:00
|
|
|
{
|
2010-11-12 16:16:22 +01:00
|
|
|
bufnum = rand()%NUMBUFS;
|
|
|
|
frame = buffers->get(bufnum)->get();
|
|
|
|
// cout << "read " << bufnum << endl;
|
2013-07-15 22:39:25 +02:00
|
|
|
Glib::usleep( rand()%USECS );
|
2010-11-12 16:16:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void writer(void)
|
|
|
|
{
|
|
|
|
frame_t frame;
|
|
|
|
bool quit = false;
|
2013-07-15 22:39:25 +02:00
|
|
|
int bufnum = 0;
|
2010-11-12 16:16:22 +01:00
|
|
|
while( !quit )
|
|
|
|
{
|
|
|
|
bufnum = rand()%NUMBUFS;
|
|
|
|
for(int i = 0; i < 7; i++)
|
|
|
|
{
|
|
|
|
for(int j = 0; j < 12; j++)
|
|
|
|
{
|
|
|
|
frame.windows[i][j] = rand()%255;
|
|
|
|
}
|
|
|
|
}
|
2013-07-15 22:39:25 +02:00
|
|
|
|
2010-11-12 16:16:22 +01:00
|
|
|
for(int i = 0; i < 12; i++)
|
|
|
|
{
|
|
|
|
frame.segments[i].r = 33+rand()%90;
|
|
|
|
frame.segments[i].g = 33+rand()%90;
|
|
|
|
frame.segments[i].b = 33+rand()%90;
|
|
|
|
}
|
2013-07-15 22:39:25 +02:00
|
|
|
|
2010-11-12 16:16:22 +01:00
|
|
|
buffers->get(bufnum)->set( frame );
|
|
|
|
// cout << "wrote " << bufnum << endl;
|
2013-07-15 22:39:25 +02:00
|
|
|
Glib::usleep( rand()%USECS );
|
2010-11-12 16:16:22 +01:00
|
|
|
}
|
|
|
|
}
|