void comms_load_player_choices() { while (vector_get_size(&comms_player_choices) > 0) { Comms_PlayerChoice *pc = (Comms_PlayerChoice *)vector_get(&comms_player_choices, 0); vector_remove(&comms_player_choices, 0); free(pc); } vector_init(&comms_player_choices, COMMS_PLAYER_CHOICE_COUNT); vector_fill(&comms_player_choices, NULL); Comms_PlayerChoice *pc; pc = malloc(sizeof(Comms_PlayerChoice)); pc->text0 = "attack"; pc->choice0 = COMMS_NPC_DEFEND; pc->text1 = "trade"; pc->choice1 = COMMS_NPC_TRADE; pc->text2 = "talk"; pc->choice2 = COMMS_NPC_INFO; pc->text3 = "disengage"; pc->choice3 = COMMS_NPC_FAREWELL; vector_set(&comms_player_choices, COMMS_PLAYER_CHOICE_MAIN, pc); pc = malloc(sizeof(Comms_PlayerChoice)); pc->text0 = "aggree"; pc->choice0 = COMMS_NPC_TRADE_ACCEPT_BUY; //TODO: This doesn't account for buy/sell separation pc->text1 = "decline"; pc->choice1 = COMMS_NPC_TRADE_DECLINE; pc->text2 = NULL; pc->choice2 = -1; pc->text3 = NULL; pc->choice3 = -1; vector_set(&comms_player_choices, COMMS_PLAYER_CHOICE_TRADE_INVITE, pc); pc = malloc(sizeof(Comms_PlayerChoice)); pc->text0 = "buy"; pc->choice0 = COMMS_NPC_TRADE_ACCEPT_BUY; pc->text1 = "sell"; pc->choice1 = COMMS_NPC_TRADE_ACCEPT_SELL; pc->text2 = "back"; pc->choice2 = COMMS_PLAYER_CHOICE_MAIN; pc->text3 = NULL; pc->choice3 = -1; vector_set(&comms_player_choices, COMMS_PLAYER_CHOICE_TRADE, pc); pc = malloc(sizeof(Comms_PlayerChoice)); pc->text0 = "attack"; pc->choice0 = COMMS_NPC_ATTACK_ACCEPT; pc->text1 = "flee"; pc->choice1 = COMMS_NPC_ATTACK_FLEE; pc->text2 = "plead"; pc->choice2 = COMMS_NPC_ATTACK_PLEAD; pc->text3 = NULL; pc->choice3 = -1; vector_set(&comms_player_choices, COMMS_PLAYER_CHOICE_DEFEND, pc); }
VECTOR_OPERATION VNXOR(v16 vs, v16 vt) { #ifdef ARCH_MIN_SSE2 vector_xor(vt, vs); vector_fill(vs); vector_xor(vs, vt); *(v16 *)VACC_L = vs; return (vs); #else vector_copy(VACC_L, vt); vector_xor(VACC_L, vs); vector_fill(V_result); vector_xor(VACC_L, V_result); vector_copy(V_result, VACC_L); return; #endif }
hash _hash_new (pool pool, size_t key_size, size_t value_size) { hash h; vector null = 0; h = c2_pmalloc (pool, sizeof *h); h->pool = pool; h->key_size = key_size; h->value_size = value_size; h->buckets = new_vector (pool, sizeof (vector)); vector_fill (h->buckets, null, HASH_NR_BUCKETS); return h; }
int main(int argc, char** argv) { if(argc != 2) { printf("You should use the following format for running this program: %s <Number of Iterations>\n", argv[0]); exit(1); } int N = atoi(argv[1]); int rng = 42; srand(rng); array_number_t vec1 = vector_fill(DIM, 0.0); array_number_t vec2 = vector_fill(DIM, 0.0); array_number_t vec3 = vector_fill(DIM, 0.0); for(int i=0; i<DIM; i++) { vec1->arr[i] = dist(rng); vec2->arr[i] = dist(rng); vec3->arr[i] = dist(rng); } #ifdef HOIST storage_t s = storage_alloc(VECTOR_ALL_BYTES(DIM)); #endif timer_t t = tic(); double total = 0; for (int count = 0; count < N; ++count) { vec1->arr[0] += 1.0 / (2.0 + vec1->arr[0]); vec2->arr[10] += 1.0 / (2.0 + vec2->arr[10]); #ifdef DPS #ifndef HOIST storage_t s = storage_alloc(VECTOR_ALL_BYTES(DIM)); #endif #endif #ifdef ADD3 #ifdef DPS total += vectorSum(TOP_LEVEL_linalg_vectorAdd3_dps(s, vec1, vec2, vec3, DIM, DIM, DIM)); #else total += vectorSum(TOP_LEVEL_linalg_vectorAdd3(vec1, vec2, vec3)); #endif #elif DOT #ifdef DPS total += TOP_LEVEL_linalg_dot_prod_dps(s, vec1, vec2, DIM, DIM); #else total += TOP_LEVEL_linalg_dot_prod(vec1, vec2); #endif #elif CROSS #ifdef DPS total += vectorSum(TOP_LEVEL_linalg_cross_dps(s, vec1, vec2, DIM, DIM)); #else total += vectorSum(TOP_LEVEL_linalg_cross(vec1, vec2)); #endif #endif #ifdef DPS #ifndef HOIST storage_free(s, VECTOR_ALL_BYTES(DIM)); #endif #endif } float elapsed = toc2(t); printf("total =%f, time per call = %f ms\n", total, elapsed / (double)(N)); return 0; }
void comms_set_current_npc_lines() { vector_free(&comms_current_npc_lines); vector_init(&comms_current_npc_lines, COMMS_NPC_COUNT); vector_fill(&comms_current_npc_lines, NULL); //todo: load possible npc text from file and select appropriate one based on disposition/bounty/resource need Comms_NPCDialogue *npcd; Vector ** line_type; int line_count = 0; line_type = (Vector **)vector_get(&comms_npc_lines, COMMS_NPC_GREETING); line_count = vector_get_size(&line_type[comms_faction][comms_tone]); npcd = vector_get(&line_type[comms_faction][comms_tone], rand() % line_count); vector_set(&comms_current_npc_lines, COMMS_NPC_GREETING, npcd); line_type = (Vector **)vector_get(&comms_npc_lines, COMMS_NPC_DEFEND); line_count = vector_get_size(&line_type[comms_faction][comms_tone]); npcd = vector_get(&line_type[comms_faction][comms_tone], rand() % line_count); vector_set(&comms_current_npc_lines, COMMS_NPC_DEFEND, npcd); npcd = malloc(sizeof(Comms_NPCDialogue)); npcd->text = wrap_text("We are glad you embrace fight willingly", 64); npcd->next_state = COMMS_STATE_ENTER_COMBAT; npcd->next_state_index = -1; vector_set(&comms_current_npc_lines, COMMS_NPC_ATTACK_ACCEPT, npcd); npcd = malloc(sizeof(Comms_NPCDialogue)); npcd->text = wrap_text("You get away.for today.", 64); npcd->next_state = COMMS_STATE_ENTER_TRAVEL; npcd->next_state_index = -1; vector_set(&comms_current_npc_lines, COMMS_NPC_ATTACK_FLEE, npcd); npcd = malloc(sizeof(Comms_NPCDialogue)); npcd->text = wrap_text("You are too pitiful to fight", 64); npcd->next_state = COMMS_STATE_PLAYER_CHOICE; npcd->next_state_index = COMMS_PLAYER_CHOICE_MAIN; vector_set(&comms_current_npc_lines, COMMS_NPC_ATTACK_PLEAD, npcd); line_type = (Vector **)vector_get(&comms_npc_lines, COMMS_NPC_TRADE); line_count = vector_get_size(&line_type[comms_faction][comms_tone]); npcd = vector_get(&line_type[comms_faction][comms_tone], rand() % line_count); vector_set(&comms_current_npc_lines, COMMS_NPC_TRADE, npcd); npcd = malloc(sizeof(Comms_NPCDialogue)); npcd->text = wrap_text("Good, let's trade", 64); npcd->next_state = COMMS_STATE_ENTER_TRADE_BUY; npcd->next_state_index = -1; vector_set(&comms_current_npc_lines, COMMS_NPC_TRADE_ACCEPT_BUY, npcd); npcd = malloc(sizeof(Comms_NPCDialogue)); npcd->text = wrap_text("Good, let's trade", 64); npcd->next_state = COMMS_STATE_ENTER_TRADE_SELL; npcd->next_state_index = -1; vector_set(&comms_current_npc_lines, COMMS_NPC_TRADE_ACCEPT_SELL, npcd); npcd = malloc(sizeof(Comms_NPCDialogue)); npcd->text = wrap_text("No trade? oh well", 64); npcd->next_state = COMMS_STATE_PLAYER_CHOICE; npcd->next_state_index = COMMS_PLAYER_CHOICE_MAIN; vector_set(&comms_current_npc_lines, COMMS_NPC_TRADE_DECLINE, npcd); line_type = (Vector **)vector_get(&comms_npc_lines, COMMS_NPC_INFO); line_count = vector_get_size(&line_type[comms_faction][comms_tone]); npcd = vector_get(&line_type[comms_faction][comms_tone], rand() % line_count); vector_set(&comms_current_npc_lines, COMMS_NPC_INFO, npcd); line_type = (Vector **)vector_get(&comms_npc_lines, COMMS_NPC_FAREWELL); line_count = vector_get_size(&line_type[comms_faction][comms_tone]); npcd = vector_get(&line_type[comms_faction][comms_tone], rand() % line_count); vector_set(&comms_current_npc_lines, COMMS_NPC_FAREWELL, npcd); }
void prepare_npc_lists() { vector_init(&comms_npc_lines, COMMS_NPC_COUNT); vector_fill(&comms_npc_lines, NULL); //Allocate all the space we'll need for the default library of npc dialogue (anything else we can allocate as we go) for (int i = 0; i < COMMS_NPC_COUNT; i++) //npc lines 0 to 9 { Vector **lines = malloc(4 * sizeof(Vector)); for (int j = 0; j < 4; j++) { lines[j] = malloc(4 * sizeof(Vector)); for (int t = 0; t < 4; t++) //tones 0 to 3 { vector_init(&lines[j][t], 5); } } vector_set(&comms_npc_lines, i, lines); //load in the lines from file int next_state, next_state_index; switch (i) { case COMMS_NPC_GREETING: next_state = COMMS_STATE_PLAYER_CHOICE; next_state_index = COMMS_PLAYER_CHOICE_MAIN; break; case COMMS_NPC_DEFEND: next_state = COMMS_STATE_ENTER_COMBAT; next_state_index = -1; break; case COMMS_NPC_TRADE: //todo: We should define these values later based on the tone (angry NPCs don't want to trade, etc.) next_state = COMMS_STATE_PLAYER_CHOICE; //COMMS_STATE_ENTER_TRADE; if (faction_disposition[comms_faction] > FACTION_THRESHOLD_DISLIKE) { next_state_index = COMMS_PLAYER_CHOICE_TRADE; //-1; //TODO: This should be a buy/sell choice } else { next_state_index = COMMS_PLAYER_CHOICE_MAIN; } break; case COMMS_NPC_INFO: //todo: We should define these values later based on the tone (angry NPCs don't want to talk, etc.) next_state = COMMS_STATE_PLAYER_CHOICE; next_state_index = COMMS_PLAYER_CHOICE_MAIN; //COMMS_PLAYER_CHOICE_INFO - if we detect that this is the next state, we need to work these out based on known topics/nearby planets break; case COMMS_NPC_FAREWELL: next_state = COMMS_STATE_ENTER_TRAVEL; next_state_index = -1; break; case COMMS_NPC_TRADE_ACCEPT_BUY: next_state = COMMS_STATE_ENTER_TRADE_BUY; next_state_index = -1; break; case COMMS_NPC_TRADE_ACCEPT_SELL: next_state = COMMS_STATE_ENTER_TRADE_SELL; next_state_index = -1; break; case COMMS_NPC_TRADE_DECLINE: next_state = COMMS_STATE_PLAYER_CHOICE; next_state_index = COMMS_PLAYER_CHOICE_MAIN; break; case COMMS_NPC_ATTACK_ACCEPT: next_state = COMMS_STATE_ENTER_COMBAT; next_state_index = -1; break; case COMMS_NPC_ATTACK_FLEE: //todo: Fleeing should cost fuel or have a random chance of failure? next_state = COMMS_STATE_ENTER_TRAVEL; next_state_index = -1; break; case COMMS_NPC_ATTACK_PLEAD: //todo: this value should be determined by how much the NPC wants to attack the player (eg: if there's no bounty, no cool loot and they don't care much, they may not bother) next_state = COMMS_STATE_PLAYER_CHOICE; next_state_index = COMMS_PLAYER_CHOICE_MAIN; break; default: next_state = -1; next_state_index = -1; } load_default_npc_lines(lines, comms_npc_line_files[i], next_state, next_state_index); } }
int main(int argc, char** argv) { int rng = 42; srand(rng); // std::mt19937 rng(42); // std::uniform_real_distribution<Real> dist(0, 1); // Problem size size_t n = 100000; size_t d = GMM_D; size_t K = GMM_K; #ifdef DPS size_t td = TOP_LEVEL_usecases_gmm_tri_dps(empty_storage, d, 0); #else size_t td = TOP_LEVEL_usecases_gmm_tri(d); #endif // Declare and fill GMM coeffs // Vector alphas{ K }; // Vec<VectorD> means{ K, VectorD{ d } }; // Vec<VectorD> qs{ K, VectorD{ d } }; // Vector l0{ size_t(tri(d)) }; // Vec<Vector> ls{ K, l0 }; array_number_t alphas = vector_fill(K, 0); array_array_number_t means = matrix_fill(K, d, 0); array_array_number_t qs = matrix_fill(K, d, 0); array_array_number_t ls = matrix_fill(K, td, 0); for (int k = 0; k < K; ++k) { alphas->arr[k] = dist(rng); for (int j = 0; j < d; ++j) { means->arr[k]->arr[j] = dist(rng) - 0.5; qs->arr[k]->arr[j] = 10.0*dist(rng) - 5.0; } for (int j = 0; j < ls->arr[k]->length; ++j) { ls->arr[k]->arr[j] = dist(rng) - 0.5; if(j >= ls->arr[k]->length - d) ls->arr[k]->arr[j] = 0; } } // Declare and fill xs // Vec<VectorD> xs{ n, Vector{ d } }; array_array_number_t xs = matrix_fill(n, d, 0); for (int i = 0; i < n; ++i) for (int j = 0; j < d; ++j) xs->arr[i]->arr[j] = dist(rng); // TOP_LEVEL_usecases_gmm_Qtimesv_test(0); // boost::timer::auto_cpu_timer t; timer_t t = tic(); // Debug 150s // Release 1s double total = 0; int N = 100; #ifdef _DEBUG N = N / 10; // Debug is roughly this much slower than release -- multiply timings. #endif double wishart_m = 2.0; for (int count = 0; count < N; ++count) { alphas->arr[0] += 1; double wishart_gamma = 1.0 / (1.0 + count); #ifdef DPS total += TOP_LEVEL_usecases_gmm_gmm_objective_dps(empty_storage, xs, alphas, means, qs, ls, wishart_gamma, wishart_m, matrix_shape(xs), vector_shape(alphas), matrix_shape(means), matrix_shape(qs), matrix_shape(ls), 0, 0); #else total += TOP_LEVEL_usecases_gmm_gmm_objective_d(xs, alphas, means, qs, ls, wishart_gamma, wishart_m, xs, alphas, means, qs, ls, wishart_gamma, wishart_m); #endif } // std::cout << "total =" << total << ", time per call = " << t.elapsed().wall / double(N) / 1000.0 << "us" << std::endl; double elapsed = toc2(t); printf("total =%f, time per call = %f ms\n", total, elapsed / (double)(N)); return 0; }