PTV Vissim - How do you begin a simulation with cars already parked in a ParkingLot? - ptv-vissim

I'd like to start a simulation with cars already parked in a ParkingLot. How to simulate this in Vissim?

Related

Running three functions at once?

C++
Working on a problem for school, running 3 horses in a race and whoever finishes first is the winner. the 3 horses are supposed to run in sync like this
1|--------H------|
2|-------H-------|
3|---------H-----|
However my code runs the program correctly (generate a random number between 1 and 100 and if that number is less than 50 move the horse 1 space up). but it runs the first horse, then the 2nd and the 3rd last.
tried to look this up but none of the methods seem to work (using codeblocks (latest version Windows 10) for C++).
srand(time(NULL));
Horse1();
Horse2();
Horse3();
Github file: https://gist.github.com/EthanA2020/f16a699f1b8136a1da0350ab48acdda0
I don't think your issue is with the type of function but instead the structure of your program. No matter how you program, one operation must come before the next. Developers work with this by running each operation of the object (in your case the horse movement) side by side and checking later to see the outcome.
For example, lets use your horse scenario:
while "all horses" are less than "finish"
horse 1 moves
horse 2 moves
horse 3 moves
I am sure that you are familiar with loops so we'll use that here. Some set distance must exist to determine when a horse has finished. So you'll want to continue that loop while all horses have a distance less than that value. During each loop, each horse's movement value must either change or not (determined by your random movement function).
Now once this while loop has ended, you can be sure that at least one horse has crossed the finish line. All operations have been completed and you have a data set of the horses positions. This is the point where you check to see which horses have finished (I say horses plural because there is a chance that more than one horse or even all 3 finish at the same time, so be sure to factor that in at the end).
With that, your program structure should be something like:
while "all horses" are less than "finish"
horse 1 moves
horse 2 moves
horse 3 moves
//movement of horses complete
check and print the horses with a movement value of "finish"
I think you should do:
while (!horse(rand() % 100)) {
usleep(100);
}
Where horse(int n) moves horse n 1 position and if it reached the end, it returns true (to end the race). It does nothing if an invalid n (only 1 to 3 is valid) is passed to it.

Bullet intersecting with enemy too many times (running through the update loop too often)

for (int i = 0; i < playerBullets.size(); i++)
{
// Ship projectile hit enemy
if (IntersectsWith(playerBullets[i].ReturnBoundingBox()) || IntersectsWith(playerBulletsTwo[i].ReturnBoundingBox()))
{
//Deal with enemies response to collision
//Do damage
Damage();
if (ReturnHealth() <= 0)
{
this->mobsKilledCounter++;
SetCurrentTexture(currentTextureKey);
}
}
}
What happens is that the bullet hits the enemy and it runs the code and does damage (which is what I want), but then it runs through the code continuously after for the same bullet (like 1000 times a second), killing the enemy instantly. This code is in my Update loop which is why it's continuously going through it.
Anyone know how I can stop this? I tried booleans but it wasn't working too well because I am using a vector and multiple bullets/enemies.
I would need to see how you are handing your "bullet" objects, and maybe see the "Update loop", but I will throw some suggestions out there:
1 - Are these "bullets" destroyed on collision? If the loop keeps running, and the bullets are still there, then they will be detected and deal damage every time your loop runs until they "exit" the object they are colliding with!
2 - Have you thought about putting a cool-down timer on how much damage a player can take per second? Or a "bool has_dealt_damage_to_player" flag for your bullets?
Also, I have no idea what this is doing:
this->mobsKilledCounter++;
Best of luck. Maybe try a decent debugger? What IDE are you working in?

How can I use multiple timers to plan events in my program?

I am building a rockband-like program using C++ and SDL, and want to be able to time events so I can orchestrate a song in the program. Here is what I have accomplished so far:
4 circles which fall from the top of the window to the middle into 4 designated hitting spots.
The circles drop at random intervals (not using time, a random number generator determines how far from the top of the window they begin to fall)
I am able to determine when a note is hit, and a score is displayed in the top right hand corner
Simple sparks are applied around a marker to let you know a note was hit
I can open a file and read text from it
Now I want to be able to use that file to write songs for the program to read and execute. I was thinking something along the lines of "1g,2g,4y,3r etc. etc. etc." the numbers being milliseconds to wait until the next note and the letters designating which color should fall.
You don't really need (or want) multiple timers; just the single timer that drives your window refresh (at 30fps or whatever) is sufficient.
When you load in your song file, for each note in the song you should store the number of milliseconds that should elapse between the moment the song starts playing and the moment that particular note is played, e.g (pseudocode):
int millisCounter = 0;
int note, noteLengthMillis;
while(ReadNextNoteFromSongFile(note, noteLengthMillis))
{
songNoteRecordsVector.push_back(NoteRecord(millisCounter, note));
millisCounter += noteLengthMillis;
}
Then, when you start the game level going, at the instant the song starts playing, record the current time in milliseconds. You will use this value as your time-zero reference for as long as the song keeps playing.
Now at every video-frame (or indeed at any time), you can calculate the number of milliseconds until a given note will be played, relative to the current system-clock-time:
int NoteRecord :: GetMillisecondsUntilNoteIsPlayed(int songStartTimeMillis, int currentTimeMillis) const
{
return this->myNoteOffsetMillis - (currentTimeMillis - songStartTimeMillis);
}
Note that the value returned will be negative if the note's time-to-be-played has already passed.
Once you have that, it's just a matter of converting each note's current milliseconds-until-note-is-played result into a corresponding on-screen position, and you know where to draw the note-circle for the current frame:
int millisUntilNotePlayTime = note.GetMillisecondsUntilNoteIsPlayed(songStartTimeMillis, currentTimeMillis);
int circleY = someFixedOffsetY + (millisUntilNotePlayTime/(1000/pixelsScrolledPerSecond));
DrawCircleAt(circleX, circleY);
... and if the user presses a key, you can calculate how far off the user was from the correct time for a given note using the same function, e.g.:
int errorMillis = note.GetMillisecondsUntilNoteIsPlayed(songStartTimeMillis, currentTimeMillis);
if (errorMillis < -50)
{
printf("You're too slow!\n");
}
else if (errorMillis > 50)
{
printf("You jumped the gun!\n");
}
else
{
printf("Good job!\n");
}

how to use time in C++

I am a beginner in programming and I started to create a game in C++ where the player disappears from the screen(he dies) when a rock hits it.
What can i do to put the player back on the screen after 2 seconds?
I have number of lifes(LifeNb) a function which delete the player from the screen(removePlayer) and a function that add the player on the screen(addPlayer).
How can i do this using ?
int time = std::clock()/1000;
if(the rock hit) {
number of lives --;
remove player;
if(time == 2)
add player;
}
It's something like this?
One way to do it: When your player dies, store the current time (plus two seconds) to a variable. On each iteration of the game's event loop, check to see if the current time is greater than or equal to the time in the variable. If it is, restore the player, and set the variable's value to (a very large value that the clock will never reach).
clock_t timer = clock();
if ((clock()/CLOCKS_PER_SEC)-(timer/CLOCKS_PER_SEC) >= 2)
player.add();
If you just want to wait two seconds, however, you could also use the system library function sleep() for two seconds.
The sleep() function will delay for a specified number of seconds before continuing execution. It seems to be what you are looking for.
See here: http://pubs.opengroup.org/onlinepubs/009604599/functions/sleep.html

Timed memory tiles game. now works without timing

I have done a memory tiles program but i want it to be timed, i.e, the user shoud be able to play the game only for 2 mins. what do i do?
Also in linux sleep() does not work, what should we use for a delay??
I presume the game has a "main loop" somewhere.
At the beginning of the main loop (before the actual loop), take the current time, call this start_time. Then in each iteration of the loop, take the current time again, call this now. The elapsed time is elapsed_time = now - start_time;. Assuming time is in seconds, then if (elapsed_time >= 120) { ... end game ... } would do the trick.