Time-Based Simulation Independent of Frame Rate - timer

How would you account for an event during which time is very important? Most games use frames and the simulations take place in time steps. What if an event occurred that needed a specific time to take place on?
For example, in a game like DOTA, attack speed is very important. Now, let's say the time-step for this game is 50ms. Two heroes are fighting. HeroA attacks HeroB and lands a "killing blow" at 14ms into the time-step. HeroB attacks HeroA and also lands a "killing blow", only this occurs at 40ms into the time-step. However, neither one of these blows will be simulated until the 50ms time-step. Therefore, at 50ms, both heroes will be killed when really only HeroA should be left standing because he managed to attack first.
Is there some way to account for this?

I don't know how your game architecture is designed, but if you are able to get the timestamps of your events, you can easily put them into a buffer with another Thread and process them in the time specific order every 50ms.

Related

What scheduling should I choose for my program on a FreeRTOS system?

I have a project (a 2-player game) made in FreeRTOS. The game has 3 tasks
(Game Render, Joystick Task and a PC Serial Communication).
Shared resources include:
Player 1 and Player 2 locations/coordinates. They are manipulated by Serial and Joystick task respectively. The game render reads both of these locations and displays them. (Player 1 location is shared with Game Render and Player 2 with Game Render).
A queue that is shared between the game render and the serial task (sending data and getting acks); the queue has been protected with a mutex on all write operations.
My question is which of these 2 scheduling is more suitable for this project: Rate Monotonic or Deadline Monotonic?
The tasks are not independent in a way that the serial communication uses acks? I think it should be Deadline Monotonic but not entirely sure?
To choose between DMS and RMS you need to know periods and deadlines for each task. From my experience it is better to focus on good overall design first and then measure and tweak the priorities to achieve best response times.
On of best summaries of good design principles I've encountered is this. In your case I would represent the two players as 'active objects' with own input event queues. Send event to the players from serial task, or even directly from ISR. The game render would then also be an AO receiving events from players, or a mutex-protected resource - it depends on what the render output is (how long does it take mostly). Serial input and serial output should be considered two separate things - in most cases it doesn't make sense to conflate the two.
Here is another link that might be useful - look at '1.4 The Design of the “Fly ‘n’ Shoot” Game'
Also, you don't need a mutex lock for xQueueSend and for sending from ISR you only need to use xQueueSendFromISR.

Anylogic stopwatch/timer

I'm wondering if there is something in anylogic that's the opposite to an event, this is, an object that counts the lapse of time instead of the time remaining.
Example:
I have a factory simulation where I want to visualize the amount of time that a specific worker (agent that is a resource) has been working since his shift started --> I could query for a function created in worker which is what I currently do but it would be neater to have a timer with the time worked
On the other hand I want to account for the busy time of a machine in a way that it's computed life (there's also the option of querying it)
For those two examples an object like an Event that has a counter and functionality around it would be useful if it could be used with increasing time instead of decreasing
I haven't found anything of the sort...
The Time Measure Start and Time Measure End blocks in the DES palette did the trick

ArduPilot, Dronekit-Python, Mavproxy and Mavlink - Hunt for the Bottleneck

I have Ardupilot on plane, using 3DR Radio back to Raspberry Pi on the ground doing some advanced geo and attitude based maths, and providing audio feedback to pilot (rather than looking to screen).
I am using Dronekit-python, which in turn uses Mavproxy and Mavlink. What I am finding is that I am only getting new attitude data to the Pi at about 3hz - and I am not sure where the bottleneck is:
3DR is running at 57.6 khz and all happy
I have turned off the automatic push of logs from Ardupilot down to Pi (part of Mavproxy)
The Pi can ask for Attitude data (roll, yaw etc.) through the DroneKit Python API as often as it likes, but only gets new data (ie, a change in value) about every 1/3 second.
I am not deep enough inside the underlying architecture to understand what the bottleneck may be -- can anyone help? Is it likely a round trip message response time from base to plan and back (others seem to get around 8hz from Mavlink from what I have read)? Or latency across the combination of Mavproxy, Mavlink and Drone Kit? Or is there some setting inside Ardupilot or Telemetry that copuld be driving this.
I am aware this isn't necessarily a DroneKit issue, but not really sure where it goes as it spans quite a few components.
Requesting individual packets should work, but that was never meant to be requested lots of times per second.
In order to get a certain packet many times per second, set up streams. A stream will trigger a certain number of times per second, and will then send whichever packet is associated with it, automatically. The ATTITUDE message is in the group called EXTRA1.
Let's suppose you want to receive 10 ATTITUDE messages per second. The relevant parameter is called SR0_EXTRA1. This defines the number of Attitude packets sent per second. The default is 4. Try increasing that parameter to 10.

How to write a timer algorithm for energy refill games

Similar to Tetris on Facebook, where if you're at 100 Energy, after usage (playing a game), it goes down 5 units, and the recharges 1 unit every 10 minutes. I'm curious how to handle polling, and possibly making it server-side so that there's no "time manipulation" (e.g setting the clock forward in the future) to circumvent measures for receiving energy early. Thanks in advance!
You will need some kind of persistent infrastructure, and ideally you want to run a check against the server from the client side, just have it return a JSON string with the value whenever it loads. Also, don't use the client clock, because that could change across machines etc. which would not yield the ideal results.

How could you give a computer a "natural need"?

So the idea is that a computer agent would be programmed in two layers, the conscious and unconscious.
The unconscious part is essentially a set of input and output devices, which I typically think of as sensors (keyboard, temperature, etc. to the limit of your imagination) and output methods (screen and speakers notably in the case of a home PC, but again to the limit of your imagination). Sensors can be added or removed at anytime, and this layer provides two main channels to the conscious layer, an single input and a single output. Defining what kind of information travels between these two layers is sort of difficult, but the basic idea is that the conscious part is constantly receiving signals (of various levels of abstraction) from the output of the unconscious part, and the conscious part can send whatever it wants down to the unconscious layer through the input channel.
The conscious layer initially knows little to nothing, it is just being completely blasted by inputs from the unconscious layer, and it knows how to send signals back, though it knows nothing about how any particular signal will affect the unconscious part. The conscious part has a large amount of storage space and processing power, however, it is all volatile memory.
Now for the question. I would like for the conscious part of the system to "grow" in that it has no idea what it can do, it just knows it can send signals, and so it starts out by sending signals down the pipe and seeing how that affects the sensor data it receives back. The dead end is that the computer is not initially trying to satisfy a goal. It is just sending signals around. To think of it like a baby being born, they need food, or sleep or to be moved out of the sun, etc. The sensory inputs of the baby are fed to its brain, which then decides to try making use of its outputs in order to get what it needs.
What kind of natural need can a computer have?
What have I tried?
Thinking specifically about how a baby becomes hungry, I certainly haven't read any research on cat scans perform on crying hungry children or anything, but I thought perhaps a particular signal comes from the unconscious with growing speed constantly which is only satiated when the signals sent back cause the baby to eat. The conscious brain's job would be to minimize the rate at which each type of signal comes in at. In other words, the "instinct" of the computer is to limit the rate of each signal coming in. What other "instincts" could there be? The problem with this analogy of course is, computers don't need to eat. Or at least I haven't been able to translate eating to something a computer needs.
Outside of the scope of this question
The end goal of this is to teach a computer who knows nothing except how it interacts with the world to play tic-tac-toe. So another idea I had was to supply a button you could press to manually stimulate the rate of a particular signal entering the conscious when it does something bad or manually soothe the rate of a particular signal when it does good.
Machine intelligence programs generally start at the Award level on Mazlow's Hierarchy of Needs because they don't have a way to perceive Physiological, Safety & Security, or Social needs. However...
At the physiological level the computer feeds on electricity. Plug in a UPS that tells the computer when it is running on battery and you have a potentially useful input for perceiving physiological needs.
Give it the ability to "perceive" that it has "lost time" or has gaps in its time record (due to power failure) and you might be able to introduce the need for Safety and Security.
Introduce social needs by making it need to interact. It could "feel" lonely when lots of time passes between inputs from the keyboard.
Detecting lost time, time passed since last keyboard interaction, and running on battery could be among the inputs available to the unconscious layer that can periodically be bumped to the attention of the conscious layer.
The computer scientists in Two Faces of Tomorrow approach a similar problem, training a computer sandboxed on a satellite to become aware. They give it those needs by, for example, making it aware that it will cease to function without electricity then providing appropriate stimulation and observing the response.
The Adolescence of P-1 is another interesting work along these lines.
A robot was programmed to believe that it liked herring sandwiches. This was actually the most difficult part of the whole experiment. Once the robot had been programmed to believe that it liked herring sandwiches, a herring sandwich was placed in front of it. Whereupon the robot thought to itself, "Ah! A herring sandwich! I like herring sandwiches."
It would then bend over and scoop up the herring sandwich in its herring sandwich scoop, and then straighten up again. Unfortunately for the robot, it was fashioned in such a way that the action of straightening up caused the herring sandwich to slip straight back off its herring sandwich scoop and fall on to the floor in front of the robot. Whereupon the robot thought to itself, "Ah! A herring sandwich..., etc., and repeated the same action over and over and over again. The only thing that prevented the herring sandwich from getting bored with the whole damn business and crawling off in search of other ways of passing the time was that the herring sandwich, being just a bit of dead fish between a couple of slices of bread, was marginally less alert to what was going on than was the robot.
The scientists at the Institute thus discovered the driving force behind all change, development and innovation in life, which was this: herring sandwiches. They published a paper to this effect, which was widely criticised as being extremely stupid. They checked their figures and realised that what they had actually discovered was "boredom", or rather, the practical function of boredom. In a fever of excitement they then went on to discover other emotions, Like "irritability", "depression", "reluctance", "ickiness" and so on. The next big breakthrough came when they stopped using herring sandwiches, whereupon a whole welter of new emotions became suddenly available to them for study, such as "relief", "joy", "friskiness", "appetite", "satisfaction", and most important of all, the desire for "happiness'.
This was the biggest breakthrough of all.
~from The Hitchhiker's Guide to the Galaxy by Douglas Adams
Bonus
Have a look at Reinforcement Learning.

Resources