I found some answers about this but they vary from age to age (last one 2015) so i was wondering about this because i need it so to know how to build my code. I have leveling system with experience and let's say player can get from 1 to 10-15 times xp in one sec (let's say he use AOE spell and kill 15 mobs) so i want to know what is better approach:
Every time player gains XP it saves it directly with PlayerPrefs.SetFloat() so it can happen that it will activate SetFloat 15 times in one moment
Load player xp inside code on game start, than to do all calculations inside code and at the game close i save that to PlayerPrefs.
I would like to use first approach since for me it is much safer but i do not know if that would be slow.
Using PlayerPrefs is generally better suited for saving player-specific options such as volume or screen-size, or small game-applications. Once your game gets larger and more complex, you could consider creating XML, TXT, or some kind of other file to save your game data.
You can take a look at this discussion on the Unity Forum.
Additionally, auto-saving 15 times per second is a bad idea in general, since it's pretty pointless. If you really implement auto-saving, you should consider increasing the delay between the saving, or save upon scene-change or some other event that is not called way too frequently.
Related
I'm making an XNA 4 game, and I want to create checkpoints for certain areas in my stage. I figured I could create a "ghost" object of the player object that would be created whenever the player reaches a checkpoint. And when you want to reload that checkpoint, you'll start to where that ghost player is.
As for now, I thought this would be an easy way to achieve this (although I think XML may be a better solution, but I've no idea on how to use that, yet). But the player has too many variables (health, stamina, ammo, bleeding timer, silver keys, golden keys, coins, infection, position, speed, angle, states [involve dying, infected, bleeding, burning, dodging, etc], I just thought that statemets like "continuep1 = p1;" (both are instances of the same object) would re-assign all the variables to the values that the other class contains, but when I tried to re-load "p1 = continuep1" it wouldn't work. It doesn't seem to do anything.
So I'm wondering, do I have to re-assign ALL the variables one by one? Should I start using XML? Or is there a way to assign all the variables without having to do it one by one? (I'm not asking for code, unless the last question is possible)
In my opinion I would say yes, start using xml. Don't worry about using xml, it's pretty simple once you get your head around it. A great way to learn would be to see your characters information displayed in xml format.
I think the most ideal option would be to serialize your game. So this involves storing the state of your character, the position it is at, the direction it is facing(which texture is currently loaded) and the stats(health, staming, bleeding etc).
With this you could reload your game from the last save when the player dies or when the game is next played. This would solve both cases.
This tutorial on making a top-down RPG game in Xna 4 is very good in my opinion and goes into good detail. Many of the techniques in this tutorial apply to more than just this genre and style of game.
http://xnagpa.net/xna4rpg.php
Part 11A(Game Editor) is the first part of a tutorial guiding the reader in making an editor for their game. With this Winforms project items, classes, quests etc can be added to the game and are stored as Xml files. At the bottom of page 6, and pages 7 and 8 outlines methods to serialize and deserialize your game.
In Part 11C(Game Editor), particularly at the bottom of page 9 and page 10. A save game method is introduced which serializes the game. You can also look at the new game and open game methods too.
These methods work with DataManager classes which store the items, classes etc in Dictionary's. This may be how you want to model your game information, if not the code in these guides may have to be altered to work with your solution.
I thought it best to provide my source for learning on this subject, rather than regurgitating it. I would recommend reading around this, not just the pages I've pointed to. Furthermore, in a later tutorial the serialization goes a step further and the files are stored in .xnb, which is a much more secure way to store information.
I hope this has helped and that you appreciate the guide in the right direction as opposed to just being given the answer. Besides, this isn't a task that would be solved in one method anyway.
Let me know how you get on and I'd be happy to help more.
So I have this Mono audio file that contains people talking, talking pauses and then them talking again. While they are talking and while they're not talking, there are children crying in the background from time to time, cars' breaks' squealing, things you hear when you are outside.
My goal is to keep those parts when they are talking and to cut those parts when they are not talking out. It is not necessary to filter the background noises.
Basically my final goal is to have a cut list like this
Start in seconds, End in seconds
What have I tried?
I manually created a voice only file by fitting together all of those parts that contain speech.(10 seconds)
I manually created a noise only file by fitting together all of those parts that do not contain speech.(50 seconds)
I got the frequencies + amplitudes thereof by applying a Fast Fourier transform
I walk through the audio file each 100 ms and take a FFT snapshot
I put all values of one snapshot(in my case 512) in a List and feed it to a machine learning algorithm(numl) combined with a label (in the first case voice = true and in the second case voice = false)
Then I use my main audio file, do basically the same but this time use the result of my machine learning model to determine whether it is speech or not and output the time in seconds it realizes this.
My problem is that I get a lot of false positives and false negatives. It seems to recognize voice when there is none and vice versa.
Is the reason for this probably a badly trained model(I use a decision tree) or do I need to take other measures to get a better result?
The common misconception about speech is that it is treated as an unrelated sequence of data frames. The core property of speech is that it is a continuous process in time, not just an array of data points.
Any reasonable VAD should take account of that and use time-oriented classifiers like HMMs. In your case any classifier that takes time into account would it be a simple energy-based voice activity detection that monitors background level or a GMM-HMM based VAD will do way better than any static classifier.
For description of simple algorithms you can check Wikipedia.
If you are looking for a good sophisticated VAD implementation, you can find one in WebRTC project, this VAD was developed by Google:
https://code.google.com/p/webrtc/source/browse/trunk/webrtc/common_audio/vad/
I'm making a War Game for iOS using Monotouch and C#. I'm running into some problem with the audio sound effects.
Here's what I require: The ability to play many sound effects simultaneously (possibly up to 10-20 at once) and the ability to adjust volume (for example, if the user zooms in on the battlefield the gun shot volume gets louder).
Here are my problems:
With AVAudioPlayer, I can adjust volume but I can only play 1 sound per thread. So if I want to play multiple sounds I have to have dozens and dozens of threads going just incase they overlap... This is a war game, picture 20 soldiers on the battlefield. Each soldier would have a "sound thread" to play gun fire sounds when they shoot because It is possible that every soldier could just happen to fire at the same exact time. I don't have a problem with making lots of threads, but my game already has dozens of threads running all the time and adding dozens more could get me into trouble... right? So I'd rather not go this road of adding dozens of more threads unless i have too...
With SystemSound, I can play as many sounds as I want in the same thread, but I can't adjust the volume.... So my work around here is, for every sound effect i have - save it like 4 times at 4 different volumes. That is a big pain... Any way to adjust volume with SystemSounds??
Both of these answer some of my requirements, but neither seems to be a seamless fit. Should I just go the AVAudioPlayer multi-threading nightmare road? Or the SystemSound multi-file-with-different-volume-levels nightmare road? Or is there a better way to do this?
Thanks in advance.
Finally found the solution to my problem. AVAudioPlayer IS capable of playiing multiple sounds at once but only with certain file formats... The details are available in this link. The reason why I couldn't play my sound effects simultaneously was because the file format was compressed and the iphone only has 1 hardware decompressor.
http://brainwashinc.wordpress.com/2009/08/14/iphone-playing-2-sounds-at-once/
I'm having a problem with timing in XNA 4.0, writing in C# and using Visual Studio 2010 express.
I'm not writing a game exactly, but I'm trying to use XNA for it's simplified content pipeline, drawing, and timing. What I'm trying to do is write a program that can time a user's response to onscreen stimuli at very fine resolutions - less than 5 ms, ideally.
To do this, I need to call the update routine (so I can poll the keyboard) no less than once every 5 ms. Even in variable step timing, I can't get the timing below about 16 ms per call. This doesn't appear to have anything to do with the amount of processing that I do in my update and draw routines. I can comment out everything in both routines and the program still spends roughly 16.66 ms on each iteration.
In fixed step timing, I can set the target to about 60 iterations per second (16.66 ms between updates), but if I try to go any faster than that, the IsRunningSlowly flag is tripped, and the game seems to try to compensate - several iterations will run faster than 60 iterations per second, and then 1 iteration will run slower.
So I guess my question is this: is the 60 iterations per second the upper limit for XNA? Is it possible to circumvent it? Should I just ditch XNA altogether?
I really appreciate your time and knowledge. Thanks in advance.
The problem you are having is due to VSync. Disable it in XNA by adding this line to your game's constructor (assuming you have the default GraphicsDeviceManager graphics):
graphics.SynchronizeWithVerticalRetrace = false;
This will allow your game to run "fast as possible". This should be "good enough" for your purposes.
See this blog post for a description of timing in XNA.
If you wanted to get more fancy: For XNA on Windows I would consider using the Windows event loop and a high resolution timer directly. Note that Game in XNA (on Windows and Xbox 360) is entirely optional.
You'd want to move as many slow operations (eg: update and draw) and blocking operations (eg: vsync) off the main thread. Note that input in XNA can only be handled on the main thread. I think you can create the graphics device on a separate thread - although I have never tried it.
You should note that, if you are measuring reaction times, there is lag in between sending a "present" command to the GPU, and that content actually appearing on screen.
I'm not expert to XNA development, but, I know I have already similar "problem" in windows phone. (slowly problem).
When you have a lot of treatment, use multithreading programming,,
msdn : "Applications that use multithreading are more responsive to user input because the user interface stays active as processor-intensive tasks execute on separate threads. Multithreading is also useful when you create scalable applications, because you can add threads as the workload increases. "
Hope I help you...
I recently joined a project where I need to get some vehicle based computer vision system. So what sort of special functionalities does a camera need, to be able to capture images while traveling at varying speeds ? for example how high a frame rate is required, and the exposure duration, shutter speed? Do you think that webcams(even if high end) will be able to achieve it ? The project requires the camera to be programmable in C# ...
Thank you very much in advance!
Unless video is capable of producing high quality low blur images, I would go with a camera with really fast shutterspeed, very short exposure duration, and for frame rate, following Seth's math, 44 centimeters is roughly a little more than a foot, which should be decent for calculations.
Reaction time for a human to respond to someone hitting the breaks in front of them is 1.5 seconds. If you can determine they hit their break light within 1/30th of a second, and it takes you 1 second to calculate and apply breaks, you already beat a human in reaction time.
How fast your shutter speed needs to be, is based on how fast you're vehicle is moving. Shutter speed reduces motion blur for a more accurate picture to analyze.
Try different speeds (if you can get a camera with this value configurable, might help).
I'm not sure that's an answerable question. It sounds like the sort of thing that the Darpa Grand Challenge hopes to determine :)
With regard to frame rate: If you're vehicle is going 30 miles per hour, a 30 FPS web cam will capture one frame for every 44 centimeters the vehicle travels. Whether or not that's "enough" depends on what you're planning to do with the image.
Not sure about the out-of-the-box C# programability, but a specific web-cam style camera to consider would be the PS3 eye.
It was specially engineered for motion-capture and (as I understand it) is capable of higher-quality images a high framerates than the majority of the competition. Windows drivers are available for it, and that opens the door for creating a C# wrapper.
Here is the product page, note the 120fps upper-end spec (not sure that the Windows drivers run at this rate, but obviously the hardware is capable of it).
One Note on shutter speed... images taken at a high framerate in low-light will likely be underexposed and unusable. If you'll need this to work in varying light conditions then the framerate will likely either need to be fixed at the low-end of your acceptable range, or will need to self-adjust based on available light.
These guys: Mobileye - develop such commercial systems for lane departure warnings and vehicle and pedestrian detection.
If you go to the "Manufacturer Products->Development and Evaluation Platforms->Cameras"
You can see what they use as cameras and also for their processing platforms.
30 fps should be sufficient for the applications mentioned above.
If money isn't an issue, take a look at cameras from companies like Opeton and others. You can control every aspect of every image capture including: capture time, image size, ++.
My iPhone can take pictures out the side of a car that are fairly blur free... past 10-20 feet. Inside of that, things are simply moving too fast; the shutter speed would need to be higher to not blur that.
Start with a middle-of-the-road webcamera, and move up as necessary? A laptop and a ride in your car while capturing still images would probably give you an idea of how well it works.