void *echo_server(void *args) { struct sockaddr_in local, remote; int sockfd, clientsock; int socklen = sizeof(struct sockaddr_in); int sockoption; actor_id aid; local.sin_family = AF_INET; local.sin_addr.s_addr = INADDR_ANY; local.sin_port = htons(9999); sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); /* Set SO_REUSEADDR */ sockoption = 1; setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char*)&sockoption, sizeof(sockoption)); if(bind(sockfd, (struct sockaddr*)&local, sizeof(struct sockaddr_in)) == -1) { perror("bind"); return 0; } listen(sockfd, 5); printf("Echo server listening on port: 9999\n"); while(1) { if((clientsock = accept(sockfd, (struct sockaddr*)&remote, &socklen)) != -1) { aid = spawn_actor(echo_client, (void*)clientsock); actor_send_msg(aid, ECHO_CLIENT_INFO, (void*)&remote, sizeof(struct sockaddr_in)); } else break; } printf("Echo server exiting...\n"); return 0; }
void *main_func(void *args) { struct actor_main *main = (struct actor_main*)args; int x; /* Accessing the arguments passed to the application */ printf("Number of arguments: %d\n", main->argc); for(x = 0; x < main->argc; x++) printf("Argument: %s\n", main->argv[x]); /* PING/PONG example */ spawn_actor(ping_func, NULL); /* Echo server */ spawn_actor(echo_server, NULL); /* Trap exit example */ spawn_actor(trap_exit, NULL); }
void *ping_func(void *args) { actor_msg_t *msg; actor_id aid = spawn_actor(pong_func, NULL); while(1) { actor_send_msg(aid, PING_MSG, NULL, 0); msg = actor_receive(); if(msg->type == PONG_MSG) printf("PONG!\n"); arelease(msg); sleep(5); } return 0; }
void *trap_exit(void *args) { actor_msg_t *msg; actor_id aid; actor_trap_exit(1); aid = spawn_actor(trap_exit_die, NULL); printf("Waiting for actor to die...\n"); msg = actor_receive(); if(msg->type == ACTOR_MSG_EXITED) { printf("An actor died! ID: %d\n", msg->sender); } arelease(msg); return 0; }
void run_actors(void) { int i; for (i = 0; i < NO_ACTORS; i ++) { if (actor[i].type == ACTORTYPE_NONE) continue; if (actor[i].in_play == 0) { actor[i].x_speed = 0; actor[i].y_speed = 0; if (actor[i].spawn_delay > 0) { actor[i].spawn_delay --; continue; } if (game.ships_left > 0) { if (arena.game_over == 0) spawn_actor(i); // ships_left will be non-zero for time attack games. } else continue; } // actor[i].energy += actor[i].recharge; // if (actor[i].energy >= actor[i].max_energy) // actor[i].energy = actor[i].max_energy; if (actor[i].screen_shake_time > 0) { if (actor[i].screen_shake_time > 4) { player[actor[i].controller].screen_shake_x = grand(7501) - 3250; player[actor[i].controller].screen_shake_y = grand(7501) - 3250; } else { player[actor[i].controller].screen_shake_x = grand(3500) - 1750; player[actor[i].controller].screen_shake_y = grand(3500) - 1750; } actor[i].screen_shake_time --; } else { player[actor[i].controller].screen_shake_x = 0; player[actor[i].controller].screen_shake_y = 0; } // screen_shake needs to be first, as many things below can affect it and we don't want them wiped. if (actor[i].repairing > 0) { actor[i].repairing --; if (actor[i].armour < actor[i].max_armour) actor[i].armour += 5; if (actor[i].armour > actor[i].max_armour) actor[i].armour = actor[i].max_armour; // + play a sound? } if (actor[i].ship == SHIP_ROUND && counter % 7 == 0) { if (actor[i].armour < actor[i].max_armour) actor[i].armour += 1; } if (actor[i].grace_period > 0) actor[i].grace_period --; if (actor[i].hurt_pulse > 0) actor[i].hurt_pulse --; if (actor[i].recycle1 > 0) actor[i].recycle1 --; if (actor[i].recycle2 > 0) actor[i].recycle2 --; if (actor[i].turret_recycle > 0) actor[i].turret_recycle --; if (actor[i].sidekick_recycle > 0) actor[i].sidekick_recycle --; if (actor[i].heavy_recycle > 0) actor[i].heavy_recycle --; if (actor[i].backfire_recycle > 0) actor[i].backfire_recycle --; if (actor[i].secondary_burst > 0) continue_secondary_burst(i); if (actor[i].just_upgraded_timeout > 0) actor[i].just_upgraded_timeout --; if (actor[i].just_collided > 0) actor[i].just_collided --; move_actor(i); detect_collision_actor_enemies(i); detect_collision_actor_pickups(i); if (actor[i].upgraded_system [UPG_SEEKER] > 0) acquire_target(i); // if (actor[i].upgraded_system [UPG_TURRET] > 0) // acquire_turret_target(i); // if (actor[i].ship == SHIP_ORBITAL && actor[i].total_power > 0) // actor_orbital(i); if (actor[i].ability [ABILITY_DEFENCE] [SYMBOL_CIRCLE] > 0) actor_shield(i); // if (actor[i].upgraded_system [UPG_SIDEKICK] > 0) // actor_sidekicks(i); if (actor[i].drive_sound [DRIVE_THRUST] > 0) actor[i].drive_sound [DRIVE_THRUST] --; if (actor[i].drive_sound [DRIVE_SLIDE] > 0) actor[i].drive_sound [DRIVE_SLIDE] --; if (actor[i].drive_sound [DRIVE_RETRO] > 0) actor[i].drive_sound [DRIVE_RETRO] --; } }
/* Main routine */ void _start ( void ) { /* Actor spawning routine */ ASPAWN spawn_actor = (void*)Z64AS_ROUTINE_ADDR; /* Game variables */ Controller *input = (void*)Z64NC_CNST_BUTTON; CoordU *link = (void*)Z64NC_CNST_LINKXYZ; RUPEES *rupees = (void*)Z64NC_CNST_RUPEES; BOMBS *bombs = (void*)Z64NC_CNST_BOMBS; ARROWS *arrows = (void*)Z64NC_CNST_ARROWS; int inc; /* ~~~~ Handle counter changing input ~~~~ */ /* Increment amount */ if( input->pad & BUTTON_Z ) inc = 10; else inc = 1; /* d-pad up: increase actor id */ if( (input->pad & BUTTON_D_UP) && current_id < Z64AS_ACTOR_LIST_MAX ) current_id += inc; /* d-pad down: decrease actor id */ if( (input->pad & BUTTON_D_DOWN) && current_id >= inc ) current_id -= inc; /* d-pad right: increase actor var */ if( input->pad & BUTTON_D_RIGHT ) current_var += inc; /* d-pad left: decrease actor var */ if( (input->pad & BUTTON_D_LEFT) && current_var >= inc ) current_var -= inc; /* ~~~~ Store the values so the game can display them ~~~~ */ /* Actor ID */ *rupees = current_id; /* Actor variable */ PUT_B( Z64NC_CNST_ARROWS, current_var >> 8 ); /* Part 1 */ PUT_B( Z64NC_CNST_BOMBS, current_var & 0xFF ); /* Part 2 */ /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /* Check invoke counter - don't want too many actors! */ if( status.flags & Z64AS_F_WAITING ) if( status.i ) { status.i--; /* Decrement */ return; } else status.flags &= ~(Z64AS_F_WAITING); /* On L + R + Z, spawn chosen actor */ if( CHECK_BUTTONS( &input->pad, BUTTON_L | BUTTON_R | BUTTON_Z) ) { /* Call OoT's actor spawning function */ spawn_actor ( Z64AS_CONST_SPAWN_ARG1, Z64AS_CONST_SPAWN_ARG2, current_id, link->x.u, link->y.u, link->z.u, 0, 0, 0, current_var ); /* Wait a bit for spawning the next actor */ status.flags |= Z64AS_F_WAITING; status.i = 4; } }