本文整理汇总了C++中Sim类的典型用法代码示例。如果您正苦于以下问题:C++ Sim类的具体用法?C++ Sim怎么用?C++ Sim使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Sim类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ship
GroundAI::GroundAI(SimObject* s)
: ship((Ship*) s), target(0), subtarget(0), exec_time(0), carrier_ai(0)
{
Sim* sim = Sim::GetSim();
Ship* pship = sim->GetPlayerShip();
int player_team = 1;
int ai_level = 1;
if (pship)
player_team = pship->GetIFF();
Player* player = Player::GetCurrentPlayer();
if (player) {
if (ship && ship->GetIFF() && ship->GetIFF() != player_team) {
ai_level = player->AILevel();
}
else if (player->AILevel() == 0) {
ai_level = 1;
}
}
// evil alien ships are *always* smart:
if (ship && ship->GetIFF() > 1 && ship->Design()->auto_roll > 1) {
ai_level = 2;
}
if (ship && ship->GetHangar() && ship->GetCommandAILevel() > 0)
carrier_ai = new(__FILE__,__LINE__) CarrierAI(ship, ai_level);
}
示例2: Print
void
StarServer::InstantiateMission()
{
Memory::Check();
current_mission = 0;
if (Campaign::GetCampaign()) {
current_mission = Campaign::GetCampaign()->GetMission();
}
Sim* sim = (Sim*) world;
if (sim) {
sim->UnloadMission();
if (current_mission) {
sim->LoadMission(current_mission);
sim->ExecMission();
sim->SetTestMode(false);
Print(" Mission Instantiated.\n");
}
else {
Print(" *** WARNING: StarServer::InstantiateMission() - no mission selected ***\n");
}
}
Memory::Check();
}
示例3: main
int main()
{
// Initialize Variables
Sim sim = loadInit();
DataExporter de(outpath, sim);
// If init file missing, write template init file. Otherwise, simulate.
if (!loaded)
{
cout << "No valid init file exists. Creating template init file..." << endl;
writeTemplateInit();
}
else // Simulate
{
de.start();
cout << endl << "Simulating..." << endl;
while (sim.t < end_t)
{
sim.advance(dt);
de.log();
}
de.write();
}
return 0;
}
示例4:
void
FltDlg::OnAlert(AWEvent* event)
{
if (!filter_list || !hangar_list || !ship) return;
int squad = filter_list->GetSelectedIndex();
Hangar* hangar = ship->GetHangar();
Sim* sim = Sim::GetSim();
const char* call = sim->FindAvailCallsign(ship->GetIFF());
Element* elem = sim->CreateElement(call, ship->GetIFF());
FlightDeck* deck = 0;
int queue = 1000;
const int* load = 0;
elem->SetSquadron(hangar->SquadronName(squad));
elem->SetCarrier(ship);
for (int i = 0; i < ship->NumFlightDecks(); i++) {
FlightDeck* d = ship->GetFlightDeck(i);
if (d && d->IsLaunchDeck()) {
int dq = hangar->PreflightQueue(d);
if (dq < queue) {
queue = dq;
deck = d;
}
}
}
int nalert = 0;
int slots[4];
for (int i = 0; i < 4; i++)
slots[i] = -1;
for (int i = 0; i < hangar_list->NumItems(); i++) {
if (hangar_list->IsSelected(i)) {
int nslot = hangar_list->GetItemData(i);
slots[nalert] = nslot;
if (!load) {
const HangarSlot* hangar_slot = hangar->GetSlot(squad, nslot);
if (hangar_slot) {
load = hangar->GetLoadout(hangar_slot);
elem->SetLoadout((int*) load);
}
}
hangar->GotoAlert(squad, nslot, deck, elem);
hangar_list->SetSelected(i, false);
nalert++;
if (nalert >= 4)
break;
}
}
NetUtil::SendElemCreate(elem, squad, slots, true);
}
示例5: main
int main (void)
{
FILE *fd;
double *ic, *p, *out;
char* errbuf;
long i, j, outd;
long internal = 0;
double dt = 0.00001;
int time_steps = 1000000;
double u[NINP];
for (int k = 0; k < NINP; k++) u[k] = .1;
fd = fopen("output.dat", "w");
Sim sim = Sim(dt, NULL);
sim.reset(out, NULL); // ic = NULL, use default start state
for(i=0; i<time_steps; i++)
{
sim.step(out, u);
fprintf(fd,"%lf ",out[0]);
for(j=0; j<NOUT; j++)
{
fprintf(fd,"%lf ",out[j+1]);
}
fprintf(fd, "\n");
}
fclose(fd);
return 0;
}
示例6: commandGenoSNP
void commandGenoSNP(string infile, string outfile, string manfile, int start_pos, int end_pos, bool verbose)
{
Sim *sim = new Sim();
ofstream outFStream;
ostream *outStream;
outStream = &cout;
if (outfile == "-") {
} else {
outFStream.open(outfile.c_str(),ios::binary | ios::trunc | ios::out);
outStream = &outFStream;
}
sim->open(infile);
if (end_pos == -1) end_pos = sim->numSamples - 1;
char *sampleName = new char[sim->sampleNameSize];
vector<uint16_t> *intensity = new vector<uint16_t>;;
for (int n=0; n <= end_pos ; n++) {
intensity->clear();
sim->getNextRecord(sampleName, intensity);
if (n < start_pos) continue;
*outStream << sampleName << "\t" << sampleName;
for (vector<uint16_t>::iterator i = intensity->begin(); i != intensity->end(); i+=2) {
*outStream << "\t" << std::fixed << setprecision(3) << *i;
*outStream << " " << std::fixed << setprecision(3) << *(i+1);
}
*outStream << endl;
}
delete sim;
}
示例7: main
int main(int argc, char *argv[])
{
Sim sim;
sim.run();
return 0;
}
示例8:
NetPlayer::~NetPlayer()
{
if (ship) {
ship->SetNetworkControl();
Sim* sim = Sim::GetSim();
sim->DestroyShip(ship);
}
}
示例9: FindShipByObjID
void
NetGameClient::DoObjDamage(NetMsg* msg)
{
if (!msg) return;
NetObjDamage obj_damage;
obj_damage.Unpack(msg->Data());
Ship* ship = FindShipByObjID(obj_damage.GetObjID());
if (ship) {
Sim* sim = Sim::GetSim();
Shot* shot = FindShotByObjID(obj_damage.GetShotID());
const Ship* owner = 0;
const char* owner_name = "[NET]";
ship->InflictNetDamage(obj_damage.GetDamage(), shot);
if (shot && sim) {
if (shot->Owner()) {
owner = shot->Owner();
owner_name = owner->Name();
}
if (shot->IsMissile()) {
SimRegion* region = ship->GetRegion();
float scale = ship->Design()->explosion_scale;
if (scale <= 0)
scale = ship->Design()->scale;
if (owner) {
const ShipDesign* owner_design = owner->Design();
if (owner_design && owner_design->scale < scale)
scale = (float) owner_design->scale;
}
sim->CreateExplosion(shot->Location(), Point(), Explosion::SHOT_BLAST, 20.0f * scale, scale, region);
}
if (!shot->IsBeam()) {
if (owner) {
ShipStats* stats = ShipStats::Find(owner_name);
if (stats) {
if (shot->IsPrimary())
stats->AddGunHit();
else if (shot->Damage() > 0)
stats->AddMissileHit();
}
}
shot->Destroy();
}
}
}
}
示例10: bruteForceAngles
/** Runs the simulation with different starting positions for
* ball 2, printing the final velocity angles of each ball for
* each iteration. Used to find a set of initial conditions
* corresponding with those stipulated in a sample problem.
*/
void bruteForceAngles(int coord, double start, double step, int n)
{
for (int i = 0; i < n; i++)
{
Sim sim = loadInit();
sim.balls[1].s[coord] = start + i * step;
while (sim.t < end_t)
sim.advance(dt);
cout << "b2.s[" << coord <<"] " << start + i * step << " ; theta 1 = " << 180 / M_PI * atan(sim.balls[0].v[1] / sim.balls[0].v[0]);
cout << " theta 2 = " << 180 / M_PI * atan(sim.balls[1].v[1] / sim.balls[1].v[0]) << endl;
}
}
示例11: SimInitializeConditions
/* Function: SimInitializeConditions ========================================
* Abstract:
* In this function, you should initialize the continuous and discrete
* states for your S-function block. The initial states are placed
* in the state vector, ssGetContStates(S) or ssGetRealDiscStates(S).
* You can also perform any other initialization activities that your
* S-function may require. Note, this routine will be called at the
* start of simulation and if it is present in an enabled subsystem
* configured to reset states, it will be call when the enabled subsystem
* restarts execution to reset the states.
*/
void SimInitializeConditions(SimStruct *S)
{
Sim *sim = (Sim *) ssGetPWork(S)[0]; // retrieve C++ object from the pointers vector and use member functions of the object
try
{
sim->init_cond();
}
catch(Exception e)
{
e.kill(S);
return;
}
}
示例12: SimOutputs
/* Function: SimOutputs =======================================================
* Abstract:
* In this function, you compute the outputs of your S-function
* block. Generally outputs are placed in the output vector, ssGetY(S).
*/
void SimOutputs(SimStruct *S, int_T tid)
{
Sim *sim = (Sim *) ssGetPWork(S)[0]; // retrieve C++ object from the pointers vector and use member functions of the object
try
{
sim->output();
}
catch(Exception e)
{
e.kill(S);
return;
}
}
示例13: SimTerminate
/* Function: SimTerminate =====================================================
* Abstract:
* In this function, you should perform any actions that are necessary
* at the termination of a simulation. For example, if memory was
* allocated in SimStart, this is the place to free it.
*/
void SimTerminate(SimStruct *S)
{
Sim *sim = (Sim *) ssGetPWork(S)[0]; // retrieve C++ object from the pointers vector
try
{
sim->terminate();
}
catch(Exception e)
{
e.kill(S);
return;
}
delete sim; // Delete C++ object
}
示例14: commandView
void commandView(string infile, bool verbose)
{
Sim *sim = new Sim();
cout << endl << "Reading SIM file: " << infile << endl;
sim->open(infile);
if (!sim->errorMsg.empty()) {
cout << sim->errorMsg << endl;
exit(1);
}
cout << "Magic: " << sim->magic << endl;
cout << "Version: " << (int)sim->version << endl;
cout << "Name Size: " << sim->sampleNameSize << endl;
cout << "Samples: " << sim->numSamples << endl;
cout << "Probes: " << sim->numProbes << endl;
cout << "Channels: " << (int)sim->numChannels << endl;
cout << "Format: " << (int)sim->numberFormat << endl;
cout << "RecLength: " << (int)sim->recordLength << endl;
cout << endl;
char *sampleName = new char[sim->sampleNameSize];
vector<uint16_t> *intensity_int = new vector<uint16_t>;
vector<float> *intensity_float = new vector<float>;
for (unsigned int n = 0; n < sim->numSamples; n++) {
intensity_int->clear();
intensity_float->clear();
if (sim->numberFormat == 0) sim->getNextRecord(sampleName,intensity_float);
else sim->getNextRecord(sampleName,intensity_int);
cout << sampleName << "\t: ";
if (verbose) { // dump intensities as well as sample names
// there *must* be a better way of doing this...
if (sim->numberFormat == 0) {
for (vector<float>::iterator i = intensity_float->begin(); i != intensity_float->end(); i++) {
cout << *i << " ";
}
} else {
for (vector<uint16_t>::iterator i = intensity_int->begin(); i != intensity_int->end(); i++) {
cout << *i << " ";
}
}
}
cout << endl;
}
delete intensity_int;
delete intensity_float;
delete sampleName;
}
示例15: SimStart
/* Function: SimStart =======================================================
* Abstract:
* This function is called once at start of model execution. If you
* have states that should be initialized once, this is the place
* to do it.
*/
void SimStart(SimStruct *S)
{
//printf("---SimStart---\n");
Sim *sim = createSim(S); // create new sim object
ssGetPWork(S)[0] = (void *) sim; // store new C++ object in the pointers vector
try
{
sim->start();
}
catch(Exception e)
{
e.kill(S);
return;
}
}