int main() { init(); Tank *tank = (Tank*)calloc(1,sizeof(Tank)); tank->direction = SOUTH; tank->position.X = 80; tank->position.Y = 48; tank->isFirstTurn = false; tank->isShot = false; func_map(MAP); drawTank(tank); while(true) { int key = getch(); switch (key) { case UP: moveTankWithDirection(tank, SOUTH); drawTank(tank); break; case DOWN: moveTankWithDirection(tank, NORTH); drawTank(tank); break; case LEFT: moveTankWithDirection(tank, WEST); drawTank(tank); break; case RIGHT: moveTankWithDirection(tank, EAST); drawTank(tank); break; case SHOT: if(tank->isShot) break; _beginthread(shootThread, 0, (void*) tank); break; case EXIT: exit(0); break; } } return 0; }
void stdalloc::run() { auto alloc_func = [&]( PortInfo &a, PortInfo &b, void *data ) { (void) data; assert( a.type == b.type ); /** assume everyone needs a heap for the moment to get working **/ instr_map_t *func_map( a.const_map[ Type::Heap ] ); FIFO *fifo( nullptr ); auto test_func( (*func_map)[ false ] ); /** check and see if a has a defined allocation **/ if( a.existing_buffer != nullptr ) { fifo = test_func( a.nitems, a.start_index, a.existing_buffer ); } else { /** check for pre-existing alloc size for test purposes **/ fifo = test_func( a.fixed_buffer_size != 0 ? a.fixed_buffer_size : 4 /** size **/, 16 /** align **/, nullptr /* data struct **/); } assert( fifo != nullptr ); (this)->initialize( &a, &b, fifo ); }; auto &container( (this)->source_kernels.acquire() ); GraphTools::BFS( container, alloc_func ); (this)->source_kernels.release(); (this)->setReady(); return; }
void dynalloc::run() { auto alloc_func = [&]( PortInfo &a, PortInfo &b, void *data ) { assert( a.type == b.type ); /** assume everyone needs a heap for the moment to get working **/ instr_map_t *func_map( a.const_map[ Type::Heap ] ); FIFO *fifo( nullptr ); auto test_func( (*func_map)[ false ] ); /** * TODO, fix this one. */ if( a.existing_buffer != nullptr ) { fifo = test_func( a.nitems, a.start_index, a.existing_buffer ); } else { fifo = test_func( 64 /* items */, 16 /* align */, nullptr ); } assert( fifo != nullptr ); (this)->initialize( &a, &b, fifo ); }; /** BEGIN TEST DATA **/ GraphTools::BFS( (this)->source_kernels, alloc_func ); (this)->setReady(); std::map< std::size_t, int > size_map; /** * make this a fixed quantity right now, if size > .75% at * montor interval three times or more then increase size. */ auto mon_func = [&]( PortInfo &a, PortInfo &b, void *data ) -> void { const float ratio( 0.75 ); const auto hash_val( dynalloc::hash( a, b ) ); /** TODO, the values might wrap if no monitoring on **/ const auto realized_ratio( a.getFIFO()->get_frac_write_blocked() ); if( realized_ratio >= ratio ) { const auto curr_count( size_map[ hash_val ]++ ); if( curr_count == 2 ) { /** get initializer function **/ auto * const buff_ptr( a.getFIFO() ); const auto cap( buff_ptr->capacity() ); buff_ptr->resize( cap * 2, 16, exit_alloc ); size_map[ hash_val ] = 0; } } return; }; /** start monitor loop **/ while( ! exit_alloc ) { /** monitor fifo's **/ std::chrono::microseconds dura( 100 ); std::this_thread::sleep_for( dura ); GraphTools::BFS( (this)->source_kernels , mon_func ); } return; }