[QUOTE=T3hGamerDK;39110020]I'm guessing it requires Python bindings usually only pre-installed in Debian or Rasbian Pi?[/QUOTE]
Try this: [url]https://github.com/Darkwater124/nmplayer/blob/master/README.md#list-of-commands[/url]
[QUOTE=supersnail11;39113454][csharp]private void ParseCommandLineArg(string name, string val)
{
Debug.Log("Parsing command line, name is " + name + " value is :" + val);
if (name == "connect" && val != string.Empty)
{
string[] array = val.Split(new char[]
{
':'
});
Debug.Log("Connecting to IP:" + array[0] + ", Port:" + array[1]);
uLink.Network.Connect(array[0], array[1], new object[0]);
}
else
{
if (name == "-maxPlayers")
{
this.maxPlayers = int.Parse(val);
}
else
{
if (name == "-hostPort")
{
this.hostPort = int.Parse(val);
}
else
{
if (name == "-server")
{
this.isHost = true;
}
else
{
if (name == "-scene")
{
ServerInit.SceneToLoad = val;
}
else
{
if (name == "-sendRate")
{
int num;
if (int.TryParse(val, ref num) && num > 0)
{
this.sendRate = num;
}
}
else
{
if (name == "-guileak")
{
if (!this.leakDetecting)
{
base.get_gameObject().AddComponent<ManagedLeakDetector>();
this.leakDetecting = true;
}
}
else
{
if (name == "-rconserver")
{
this.rconServer = val;
}
else
{
if (name == "-rconclient")
{
this.rconClient = val;
}
else
{
if (name == "-rconwait")
{
this.rconWait = true;
}
else
{
if (name == "-batchmode")
{
this.batchMode = true;
}
}
}
}
}
}
}
}
}
}
}
}[/csharp]
garry
garry why[/QUOTE]
To settle the arguments:
[img]http://puu.sh/1KmHd[/img]
I didn't write this code btw. If I had I still wouldn't have used switch statements. It would look like this..
[cpp]
if ( name == "-maxPlayers" )
{
maxPlayers = System.Int32.Parse( val );
return;
}
if ( name == "-hostPort" )
{
hostPort = System.Int32.Parse( val );
return;
}
if ( name == "-server" )
{
isHost = true;
return;
}
[/cpp]
I know that's not really any different.. just coding preference.
-snip-
Wow, I am dumb.
Some people get their panties in a twist about having multiple return statements though.
[QUOTE=garry;39118686][cpp]
if ( name == "-maxPlayers" )
{
maxPlayers = System.Int32.Parse( val );
return;
}
if ( name == "-hostPort" )
{
hostPort = System.Int32.Parse( val );
return;
}
if ( name == "-server" )
{
isHost = true;
return;
}
[/cpp]
I know that's not really any different.. just coding preference.[/QUOTE]
Uh, wouldn't you not be able to set a host port and max players? Since once you enter the max players if statement none of the further ones would execute?
[QUOTE=Matt-;39118804]Uh, wouldn't you not be able to set a host port and max players? Since once you enter the max players if statement none of the further ones would execute?[/QUOTE]
the signature of the method is ParseCommandLineArg(string name, string val)
[QUOTE=Matt-;39118804]Uh, wouldn't you not be able to set a host port and max players? Since once you enter the max players if statement none of the further ones would execute?[/QUOTE]
I imagine this would be a function that is called per key value pair.
[QUOTE=danharibo;39118814]the signature of the method is ParseCommandLineArg(string name, string val)[/QUOTE]
Ahh, that makes sense.
I have a serious love/hate relationship going on with templates. Sometimes I can't wrap my head around what I'm trying to do with them, and others I'm just completely amazed at what they're capable of.
I just created a class called Mirror that I use to synchronize the internal OpenGL state machine with my API. It's basically just a neat way of centralizing shared pointers, but because of templates, I can just write one version and it will work for textures, shaders, programs, framebuffers, etc.
[QUOTE=high;39115958]Actually .net will construct a static dictionary with the values to indexes. I forget the threshold but if I remember correctly a switch will only be if/elseif when there are under 4 cases.[/QUOTE]
I wasn't aware of that. Thanks for the CIL lesson.
[QUOTE=danharibo;39118706]Some people get their panties in a twist about having multiple return statements though.[/QUOTE]
Don't know why this guy is getting disagrees, some people honestly don't like multiple return statements (or even break statements) in code. Don't understand why...
[QUOTE=W00tbeer1;39121028]Don't know why this guy is getting disagrees, some people honestly don't like multiple return statements (or even break statements) in code. Don't understand why...[/QUOTE]
It might be because it can make the code more confusing (having multiple places where the function can exit). It's never been a problem for me, though.
Speaking of personal preference, here's how I'd write that (besides a switch):
[csharp]if(name == "-maxPlayers")
maxPlayers = System.Int32.Parse(val);
else if(name == "-hostPort")
hostPort = System.Int32.Parse(val);
else if(name == "-server")
isHost = true;[/csharp]
[QUOTE=supersnail11;39121349]It might be because it can make the code more confusing (having multiple places where the function can exit). It's never been a problem for me, though.
Speaking of personal preference, here's how I'd write that (besides a switch):
[csharp]if(name == "-maxPlayers")
maxPlayers = System.Int32.Parse(val);
else if(name == "-hostPort")
hostPort = System.Int32.Parse(val);
else if(name == "-server")
isHost = true;[/csharp][/QUOTE]
Your lack of braces disturbs me. Here's how I'd do it:
[csharp]
if(name == "-maxPlayers")
{
maxPlayers = System.Int32.Parse(val);
}
else if(name == "-hostPort")
{
hostPort = System.Int32.Parse(val);
}
else if(name == "-server")
{
isHost = true;
}
[/csharp]
Very readable and also part of my university style guide, which is why I got into this habit. I used to put the brace on the same line as the condition.
[QUOTE=Hexxeh;39121509]Your lack of braces disturbs me.[/QUOTE]
I do it too. They take up unnecessary bytes and lines. And I think it looks better.
[QUOTE=Gulen;39121548]I do it too. They take up unnecessary bytes and lines. And I think it looks better.[/QUOTE]
I just do it because it bugs me when there's only one line in braces. I guess it's a habit.
Are you guys writing classes and voids without brackets? I hope not.
What is the point of:
[code]
class HiFP
{
if(name == "-maxPlayers")
maxPlayers = System.Int32.Parse(val);
else if(name == "-hostPort")
hostPort = System.Int32.Parse(val);
else if(name == "-server")
isHost = true;
}
[/code]
in stead of:
[code]
class HiFP
{
if(name == "-maxPlayers")
{
maxPlayers = System.Int32.Parse(val);
}
else if(name == "-hostPort")
{
hostPort = System.Int32.Parse(val);
}
else if(name == "-server")
{
isHost = true;
}
}
[/code]
I'm using the exact same syntax as Hexxeh does.
[b]Edit:[/b]
Why don't we use:
[code]
class HiFP
if(name == "-maxPlayers")
maxPlayers = System.Int32.Parse(val);
else if(name == "-hostPort")
hostPort = System.Int32.Parse(val);
else if(name == "-server")
isHost = true;
[/code]
WE DON'T NEED BRACKETS AT ALL! :dumb:
Breaking the discussion, working on shadows some more:
[img]https://dl.dropbox.com/u/41041550/Coding/C%23/OGLFV/shadows.PNG[/img]
[QUOTE=ZaroX;39121896]What is the point of...[/QUOTE]
I find it more compact not using braces for one liners, it's just down to personal preference, no one way is better than the other.
[QUOTE=Matt-;39121937]I find it more compact not using braces for one liners, it's just down to personal preference, no one way is better than the other.[/QUOTE]
I'm actually doing this for one liners sometimes:
[code]
if(name == "-maxPlayers"){maxPlayers = System.Int32.Parse(val);}
[/code]
:v:
[QUOTE=ZaroX;39121896]
[code]
class HiFP
if(name == "-maxPlayers")
maxPlayers = System.Int32.Parse(val);
else if(name == "-hostPort")
hostPort = System.Int32.Parse(val);
else if(name == "-server")
isHost = true;
[/code]
WE DON'T NEED BRACKETS AT ALL! :dumb:[/QUOTE]
This is called python.
Edit: Well I didn't mean this code is precisely python. God you guys are finicky with your ratings.
[QUOTE=Topgamer7;39121960]This is called python.[/QUOTE]
[code]
class HiFP:
if name == "-maxPlayers":
maxPlayers = int(val)
elif name == "-hostPort":
hostPort = int(val)
elif name == "-server"
isHost = true
[/code]
[editline]6th January 2013[/editline]
You'll need a function in there somewhere because putting that directly in a class won't/shouldn't work with any language.
How I would be tempted to do it:
[csharp]public delegate void CommandLineArgHandler(string name, string val);
static class CommandLineArgManager
{
private static Dictionary<string, List<CommandLineArgHandler>> _argDict
= new Dictionary<string, List<CommandLineArgHandler>>();
public static void Register(string name, CommandLineArgHandler handler)
{
if (!_argDict.ContainsKey(name))
_argDict.Add(name, new List<CommandLineArgHandler>());
_argDict[name].Add(handler);
}
public static void Parse(string name, string val)
{
Debug.Log("Parsing command line, name is " + name + " value is :" + val);
if (_argDict.ContainsKey(name))
foreach (CommandLineArgHandler handler in _argDict[name])
handler(name, val);
}
}
/* ... elsewhere ... */
CommandLineArgManager.Register("connect", (name, val) =>
{
if (val != string.Empty)
{
string[] array = val.Split(new char[]{':'});
Debug.Log("Connecting to IP:" + array[0] + ", Port:" + array[1]);
uLink.Network.Connect(array[0], array[1], new object[0]);
}
});
CommandLineArgManager.Register("-maxPlayers", (name, val) =>
{
this.maxPlayers = int.Parse(val);
});
CommandLineArgManager.Register("-hostPort", (name, val) =>
{
this.hostPort = int.Parse(val);
});
/* ... */[/csharp]
Means you can register handlers in different parts of the project where they are needed.
Made a test scene for the shadows (though in blender for now)
[t]https://dl.dropbox.com/u/41041550/Coding/C%23/OGLFV/block_scene.PNG[/t]
[QUOTE=supersnail11;39122125][code]
class HiFP:
if name == "-maxPlayers":
maxPlayers = int(val)
elif name == "-hostPort":
hostPort = int(val)
elif name == "-server"
isHost = true
[/code]
[editline]6th January 2013[/editline]
You'll need a function in there somewhere because putting that directly in a class won't/shouldn't work with any language.[/QUOTE]
[code]
def HiFP(name):
if name == "-maxPlayers":
maxPlayers = int(val)
elif name == "-hostPort":
hostPort = int(val)
elif name == "-server"
isHost = true[/code]
Also I think we should have syntax highlighting for python on the forum ;_;.
[QUOTE=Mega1mpact;39122347]Also I think we should have syntax highlighting for python on the forum ;_;.[/QUOTE]
For [i]all[/i] languages.
I do it like this
[cpp]
if(name == "-maxPlayers") maxPlayers = System.Int32.Parse(val);
else if(name == "-hostPort") hostPort = System.Int32.Parse(val);
else if(name == "-server") isHost = true;
[/cpp]
fuck unnecessary braces/tabs
[QUOTE=SupahVee;39122438]I do it like this
[cpp]
if(name == "-maxPlayers") maxPlayers = System.Int32.Parse(val);
else if(name == "-hostPort") hostPort = System.Int32.Parse(val);
else if(name == "-server") isHost = true;
[/cpp]
fuck unnecessary braces/tabs[/QUOTE]
[code]def HiFP(name):
if name == "-maxPlayers": maxPlayers = int(val)
elif name == "-hostPort": hostPort = int(val)
elif name == "-server": isHost = true[/code]
[editline]6th January 2013[/editline]
[QUOTE=Matt-;39122436]For [i]all[/i] languages.[/QUOTE]
Or just a generic one.
[QUOTE=Mega1mpact;39122450][code]def HiFP(name):
if name == "-maxPlayers": maxPlayers = int(val)
elif name == "-hostPort": hostPort = int(val)
elif name == "-server": isHost = true[/code]
[editline]6th January 2013[/editline]
Or just a generic one.[/QUOTE]
What about [url]http://codemirror.net/[/url] ?
[QUOTE=Hexxeh;39121509]Your lack of braces disturbs me. Here's how I'd do it:
if(name == "-maxPlayers"){ maxPlayers = System.Int32.Parse(val);}else if(name == "-hostPort"){ hostPort = System.Int32.Parse(val);}else if(name == "-server"){ isHost = true;}
Very readable and also part of my university style guide, which is why I got into this habit. I used to put the brace on the same line as the condition.[/QUOTE]
I'm being forced to put the bracket on the same line as the condition by my university and I hate it so much. My last uni taught me to put it on the next line, so I'm used to it, and now I have to relearn.. Fucking hell.
[editline]time[/editline]
I did a derp, I like putting them on the same line as the condition, and I'm being forced to put them on the next line.
Sorry, you need to Log In to post a reply to this thread.