Here's a dictionary implementation that doesn't shuffle items around:
[code]//C#
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public class OrderedDictionary<TKey, TValue> : IDictionary<TKey, TValue>, IReadOnlyDictionary<TKey, TValue>, IList<KeyValuePair<TKey, TValue>>, IReadOnlyList<KeyValuePair<TKey, TValue>>
{
List<TKey> _keys = new List<TKey>();
Dictionary<TKey, TValue> _values = new Dictionary<TKey, TValue>();
public void Add(TKey key, TValue value)
{
_values.Add(key, value); // Throws if key exists.
_keys.Add(key);
}
public bool ContainsKey(TKey key)
{ return _values.ContainsKey(key); }
public ICollection<TKey> Keys
{ get { return _keys; } }
public bool Remove(TKey key)
{
if (_values.Remove(key))
{
_keys.Remove(key);
return true;
}
else
{ return false; }
}
public bool TryGetValue(TKey key, out TValue value)
{ return _values.TryGetValue(key, out value); }
public ICollection<TValue> Values
{ get { return _keys.Select(key => _values[key]).ToArray(); } }
public TValue this[TKey key]
{
get { return _values[key]; }
set
{
if (_values.ContainsKey(key))
{ _values[key] = value; }
else
{
_keys.Add(key);
_values.Add(key, value);
}
}
}
public void Add(KeyValuePair<TKey, TValue> item)
{ Add(item.Key, item.Value); }
public void Clear()
{
_keys.Clear();
_values.Clear();
}
public bool Contains(KeyValuePair<TKey, TValue> item)
{ return _values.Contains(item); }
public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
{
for (int i = 0; i < _keys.Count; i++)
{
var key = _keys[i];
array[arrayIndex + i] = new KeyValuePair<TKey, TValue>(key, _values[key]);
}
}
public int Count
{ get { return _keys.Count; } }
public bool IsReadOnly
{ get { return false; } }
public bool Remove(KeyValuePair<TKey, TValue> item)
{
TValue value;
if (_values.TryGetValue(item.Key, out value) && Equals(value, item.Value))
{
_keys.Remove(item.Key);
return _values.Remove(item.Key); // true
}
else
{ return false; }
}
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
{
foreach (var key in _keys)
{ yield return new KeyValuePair<TKey, TValue>(key, _values[key]); }
}
IEnumerator IEnumerable.GetEnumerator()
{ return GetEnumerator(); }
IEnumerable<TKey> IReadOnlyDictionary<TKey, TValue>.Keys
{ get { return Keys; } }
IEnumerable<TValue> IReadOnlyDictionary<TKey, TValue>.Values
{ get { return Values; } }
public int IndexOf(KeyValuePair<TKey, TValue> item)
{
var index = _keys.IndexOf(item.Key);
if (index != -1)
{
if (Equals(item.Value, _values[item.Key]) == false)
{ index = -1; }
}
return index;
}
public void Insert(int index, KeyValuePair<TKey, TValue> item)
{
_values.Add(item.Key, item.Value);
_keys.Insert(index, item.Key);
}
public void RemoveAt(int index)
{
_values.Remove(_keys[index]);
_keys.RemoveAt(index);
}
public KeyValuePair<TKey, TValue> this[int index]
{
get
{
var key = _keys[index];
return new KeyValuePair<TKey, TValue>(key, _values[key]);
}
set
{
if (index == _keys.Count)
{ Add(value); }
else
{
var oldKey = _keys[index];
if (Equals(value.Key, oldKey))
{
_keys[index] = value.Key;
_values[value.Key] = value.Value;
}
else
{
_values.Add(value.Key, value.Value);
_keys[index] = value.Key;
_values.Remove(oldKey);
}
}
}
}
}[/code]
I need (part of) this for the attributes in my HTML generator. Previously they just so happened to stay in order :v:
(I'm fairly sure there's some avoidable potential boxing going on wherever I call [I]Equals(object objA, object objB)[/I]. I don't know a good way to avoid this though.)
[QUOTE=Tamschi;47548900]Here's a dictionary implementation that doesn't shuffle items around:
[code]Stuff[/code]
I need (part of) this for the attributes in my HTML generator. Previously they just so happened to stay in order :v:
(I'm fairly sure there's some avoidable potential boxing going on wherever I call [I]Equals(object objA, object objB)[/I]. I don't know a good way to avoid this though.)[/QUOTE]
Any reason System.Collections.Specialized.OrderedDictionary is unsuitable?
[QUOTE=ben1066;47548942]Any reason System.Collections.Specialized.OrderedDictionary is unsuitable?[/QUOTE]
OrderedDictionary isn't generic.
[QUOTE=Rocket;47548723]Antipiracy is a fool's errand. People will pirate your game no matter what you do. Focus your time on creating a better experience for your players and for anyone who wants to mod your game instead of wasting it on preventing the inevitable.[/QUOTE]
Is this about a game, even?
If it's a redistributable library there's little issue with piracy because you can DMCA products that use it illicitly off most stores, for example.
[editline]18th April 2015[/editline]
[QUOTE=elevate;47548946]OrderedDictionary isn't generic.[/QUOTE]
Unfortunately. (I didn't either know about that one though, since I never looked into that namespace.)
Friday niiight development streaming! I'll actually be talking about Grid tonight. [url]http://www.twitch.tv/andrewmcwatters[/url]
[code]
if(chat.contains(":)")){
//Add inline emoji
}[/code]
I'm unsure how to dynamically add an inline emoji in a javafx textarea. Any ideas?
EDIT: Forgot to mention this is in an FXML controller, not the main.
Hey guys, I'm currently looking for a third developer to work on Rant. Right now, it's just Rocket and I running the whole operation, and I'm beginning to realize how big this project is getting. Between school, my internship, and life slapping me with a shit-filled sock recently, I have less and less time to work on everything I really want to. I feel slightly guilty about that, since I built my reputation here mostly on this project alone. I'd like to keep it going.
I'd be delighted to find someone who would like to contribute their talent and creativity to what I envision will become a useful, powerful tool for people who want to generate a variety of text-based content. It's always been in my interests to listen to the suggestions and feedback of others when developing my concepts, but I feel like it's time for a new set of eyes.
Rant has been the focus of almost all my free time over the last year. I'm still recovering from that crisis two months back, and I feel like continually forcing myself to come up with new features on my own is not going to produce quality results. I will, however, continue to manage the project and make sure everything is working correctly. (I'm not abandoning you guys again!)
If one of you out there shares my same passion for PCG and would like to help out with the project directly, let me know; I'd be happy to let you on board.
[t]http://i.imgur.com/rwSzKqy.png[/t]
Weapons now don't go inside walls and shadows work properly on viewmodels!
No retracting either. It just works!
[QUOTE=Maspe36;47549670][code]
if(chat.contains(":)")){
//Add inline emoji
}[/code]
I'm unsure how to dynamically add an inline emoji in a javafx textarea. Any ideas?
EDIT: Forgot to mention this is in an FXML controller, not the main.[/QUOTE]
Emoji are just characters like any other, displayed in a certain way. So, to implement what you want, find the index of each instance of a pattern (for example ":)") in the string. With each index, remove the pattern from the string and insert the respective emoji character in its place.
[QUOTE=andrewmcwatters;47549603]Friday niiight development streaming! I'll actually be talking about Grid tonight. [url]http://www.twitch.tv/andrewmcwatters[/url][/QUOTE]
What stack do you use to host your web pages? I joined partway through so I just saw parts of your development/deployment and it looks really nice
Thanks dude, I use a MEAN stack with automated builds and CI through Travis. All Planimeter contributors have access to the webapps that I build and any time changes are made, (to things like documentation that I was working on tonight,) they get built after commits and deployed to andrewmcwatters.com.
[editline]17th April 2015[/editline]
I don't open source my web server code, but if you're interested, I'd be happy to let you take a peek. It's very clean, imo.
[editline]17th April 2015[/editline]
Also, thanks for watching, guys! I've learned from my previous streams and all the feedback: less electronica and more actual development. Haha, so I hope that was meaningful tonight.
[QUOTE=Simspelaaja;47548409]Just out of curiosity, could you name any indie games that did that? Not doubting, just interested to know.[/QUOTE]
Gladiator was one such game that particularly didn't suffer from it - it was originally developed for DOS but since the source was distributed with the full version, some people ported it to Windows as "Openglad".
[img]http://i.imgur.com/1MqYtWB.png[/img]
[QUOTE=Tamschi;47548900]Here's a dictionary implementation that doesn't shuffle items around:
I need (part of) this for the attributes in my HTML generator. Previously they just so happened to stay in order :v:
(I'm fairly sure there's some avoidable potential boxing going on wherever I call [I]Equals(object objA, object objB)[/I]. I don't know a good way to avoid this though.)[/QUOTE]
Too bad it kills removal performance, but I guess that's a relatively rare use of a dictionary.
[editline]18th April 2015[/editline]
[QUOTE=Rocket;47548723]Antipiracy is a fool's errand. People will pirate your game no matter what you do. Focus your time on creating a better experience for your players and for anyone who wants to mod your game instead of wasting it on preventing the inevitable.[/QUOTE]
This is repeated over and over again so let me play the devils advocate for a second.
Now, I'm not talking about indie games here because those developers can't afford any extra work, but for triple As, complicated DRM is exactly what they want and it's been working like a charm for them.
Release groups tend to brag about how they bypassed some games protection in 3 days, but those 3 days after the release are the most important ones. Immediately after the game is released (and preloading has a huge role here), you start seeing your friends play GTA 5 on Steam. With every hour there are more people buzzing about it. I can guarantee you that anyone who has $60 to spend (and various statistics say that a majority of the player base has) will fold under pressure and buy the game. If the game didn't have protection, he would already have downloaded it.
Spending money on DRM? How much do you think these things cost? A million bucks? Didn't GTA IV make like a billion in it's first week?
DRM isn't here to make the game impenetrable forever. It's here to delay cracks for a couple of days.
my death state screen is essentially a light ~spooky~ popup. Any sense of creepiness wore off after the first couple of times.
I changed it to where the death screen state (triggered from being touched by an enemy) now appears randomly from 0-3 seconds after you've actually triggered a death.
this makes it a little more unpredictable which is great, but I'm worried the fail state feedback would be lesser because of it.
[editline]18th April 2015[/editline]
fuck it it's staying in. I just did it a couple more times and it still retains the creep-factor since now there is anxiety for every close call since you don't instantly know if you've fucked up or not.
[QUOTE=polkm;47547556]people could just clone the repo and reupload somewhere else though?[/QUOTE]
sure but they have to keep it up to date and you can probably just dmca them
besides it won't take long at all to implement something like what unreal does with its source access
Got tired of Irfanview, so I started working on a basic image viewer. Currently it only works with local files, but I'm hoping to add scraping functionality so you can view 4chan threads / subreddits / etc easily:
[vid]https://a.pomf.se/awrtev.mp4[/vid]
It should work with anything you have DirectShow filters installed for (MPC-HC).
Source is up here. It's pretty much my first real WPF program, so it's pretty ugly.
[url]https://github.com/jmazouri/Peruser[/url]
[QUOTE=andrewmcwatters;47549603]Friday niiight development streaming! I'll actually be talking about Grid tonight. [url]http://www.twitch.tv/andrewmcwatters[/url][/QUOTE]
It's been VOD muted
[QUOTE=DarKSunrise;47550446]sure but they have to keep it up to date and you can probably just dmca them
besides it won't take long at all to implement something like what unreal does with its source access[/QUOTE]
The older Unreal games should be open sourced. That would be so cool.
[QUOTE=proboardslol;47545220]So I ran into a problem building sine waves. I'm 100% sure it's a math error.
I'm trying to construct a 2400hz tone, and I have this:
[code] for(int i = 0; i < BUFSIZE; i++){
//amplitude is 0.8 frequency is 2400hz
mydata[i] = ((pow(2,15)-1) * 0.8) * sin(((i * (2*PI))/BUFSIZE) * 2400);
}
[/code]
where BUFSIZE is 256 (as in 256 samples).
But this amounts to a massive loss of information, and I'm not sure why...
Here's a picture of the wave
[img]http://i.imgur.com/TCosaN6.png[/img]
From what I understand, (i * (2 * pi))/BUFSIZE should result in the range of 0 to pi, with a step of 1/256. how can I increase my precision to, say, 1/44100. I guess this is just really basic for-loop arithmetic but I can't exactly figure it out and oh my god as I'm typing this I realize i just have to divide by 44100 instead of BUFSIZE holy crap I'm retarded.
Fixed code:
[code]
for(int i = 0; i < BUFSIZE; i++){
//amplitude is 0.8 frequency is 2400hz
mydata[i] = ((pow(2,15)-1) * 0.8) * sin(((i * (2*PI))/44100) * 2400);
}
[/code]
I'm posting this now just in case some googler later on has the same problem, even though I solved it before I even posted it.[/QUOTE]
Couldn't you use something like [url=http://en.wikipedia.org/wiki/Fourier_series]Fourier series[/url] for this?
[QUOTE=miceiken;47550931]Couldn't you use something like [url=http://en.wikipedia.org/wiki/Fourier_series]Fourier series[/url] for this?[/QUOTE]
So like
[code]double squareWave(int t){
double sigma;
for(int k = 0; k < 100; k++){
sigma += (4/pi) * (sin(2 * pi * (2 * k - 1) * 1200 * t)/(2 * k - 1));
}
return sigma;
}[/code]
For a [url=http://upload.wikimedia.org/math/d/c/1/dc1ca9de7f258a89d3c579f55d29ed05.png]square wave?[/url]
[QUOTE=Ott;47550473]It's been VOD muted[/QUOTE]
Oh well, I was messing around with stuff early in the stream since Twitch did a global password and key reset a while back. What I was doing earlier in the video didn't have any sense on being on Twitch anyway. I'll might make more focused videos in the future.
I'm [URL="http://facepunch.com/showthread.php?t=1458662&p=47435064&viewfull=1#post47435064"]unoriginal.[/URL]
[code]
#include "lexer.cpp"
enum Type
{
NUMBER,
OPERATOR,
VARIABLE,
SPACE,
UNKNOWN
};
string tsr( Type t )
{
switch( t )
{
case NUMBER: return "NUMBER";
case OPERATOR: return "OPERATOR";
case VARIABLE: return "VARIABLE";
case SPACE: return "SPACE";
case UNKNOWN: return "UNKNOWN";
}
}
int main (int argc, char *argv[])
{
Lexer< Type > lexer;
lexer.add( "+-/*^()", OPERATOR )
->add( "0123456789", NUMBER )
->add( "abcdefghijklmnopqrstuvwxyz", VARIABLE )
->add( ' ', SPACE )
->addIgnored( SPACE )
->defineDefault( UNKNOWN );
string input = "2 * 3 / (5 + 1) ^ 2";
cout << "Original: " << input << "\n\n";
auto tokens = lexer.tokenize( input );
cout << "Tokens( " << tokens.size() << " ):\n";
for( auto token : tokens )
cout << "\t" << token.String( &tsr ) << "\n";
}
[/code]
Output:
[IMG]https://dl.dropboxusercontent.com/u/46283290/Lexer.png[/IMG]
Tried a new way of visualizing trajectory. Instead of [URL="https://dl.dropboxusercontent.com/u/13781308/ShareX/2015-04/2015-04-18_11-48-54.jpg"]having a line[/URL] that's constantly visible and looks ugly, I tried a way where pressing alt will "shoot" a ping out that will go along your current trajectory.
[video=youtube;L3a5q6XRKGw]http://www.youtube.com/watch?v=L3a5q6XRKGw[/video]
I think I like this way better. Just need to make it look nicer and get a better sound effect.
[QUOTE=Pelf;47551765]Tried a new way of visualizing trajectory. Instead of [URL="https://dl.dropboxusercontent.com/u/13781308/ShareX/2015-04/2015-04-18_11-48-54.jpg"]having a line[/URL] that's constantly visible and looks ugly, I tried a way where pressing alt will "shoot" a ping out that will go along your current trajectory.
[video=youtube;L3a5q6XRKGw]http://www.youtube.com/watch?v=L3a5q6XRKGw[/video]
I think I like this way better. Just need to make it look nicer and get a better sound effect.[/QUOTE]
I think it's annoying though
I prefer the line, just make it so you have to hold alt for the line to show or make it toggle-able or something
if you displayed a trajection line instead of a ping, you take out the factor of time, though. that's a pretty important difference
Plus the ping adds a level of difficulty - having a line makes course corrections trivial.
Why not just a line that you can barely see? Like transparent gray line or something
Engine: [url]https://github.com/RickDork/Sora[/url]
Game (now with committed lua and shader files!!): [url]https://github.com/RickDork/2149[/url]
[IMG]http://i.imgur.com/1Vxu7yr.png[/IMG]
[IMG]http://i.imgur.com/dWLc9JQ.png[/IMG]
[QUOTE=HumbleTH;47551618]I'm [URL="http://facepunch.com/showthread.php?t=1458662&p=47435064&viewfull=1#post47435064"]unoriginal.[/URL]
[code]
#include "lexer.cpp"
enum Type
{
NUMBER,
OPERATOR,
VARIABLE,
SPACE,
UNKNOWN
};
string tsr( Type t )
{
switch( t )
{
case NUMBER: return "NUMBER";
case OPERATOR: return "OPERATOR";
case VARIABLE: return "VARIABLE";
case SPACE: return "SPACE";
case UNKNOWN: return "UNKNOWN";
}
}
int main (int argc, char *argv[])
{
Lexer< Type > lexer;
lexer.add( "+-/*^()", OPERATOR )
->add( "0123456789", NUMBER )
->add( "abcdefghijklmnopqrstuvwxyz", VARIABLE )
->add( ' ', SPACE )
->addIgnored( SPACE )
->defineDefault( UNKNOWN );
string input = "2 * 3 / (5 + 1) ^ 2";
cout << "Original: " << input << "\n\n";
auto tokens = lexer.tokenize( input );
cout << "Tokens( " << tokens.size() << " ):\n";
for( auto token : tokens )
cout << "\t" << token.String( &tsr ) << "\n";
}
[/code]
-pic-[/QUOTE]
Neat. Does it handle multi-character tokens?
Sorry, you need to Log In to post a reply to this thread.