I'm getting fed up with trying to make online multiplayer games.
When a client connects, it needs to be sent the current state of the game. This means that I need a converter at both ends, to convert a class to a string and back.
Sadly, this means that when I need to, say, add an attribute "mana" to all units, I need to do the following:
-Make the change client-side.
-Make the change server-side
-Update the to string converter.
-Update the to game class converter.
Instead of what I'd have to do in a singleplayer game:
-Make the change.
Also, if I don't want to have the client-side and server-side classes seperated in two (because that means I have to maintain two practically identical classes), I need to disable some functions on the client instance, that I need the server one to do.
It feels like I have to take a lot of extra steps that greatly increase the overall time it takes for me to create something.
Am I approaching something the wrong way, and is there anything I should do differently, based on what I've described here? Thanks in advance.
[QUOTE=no-named;40376961]I'm getting fed up with trying to make online multiplayer games.
When a client connects, it needs to be sent the current state of the game. This means that I need a converter at both ends, to convert a class to a string and back.
Sadly, this means that when I need to, say, add an attribute "mana" to all units, I need to do the following:
-Make the change client-side.
-Make the change server-side
-Update the to string converter.
-Update the to game class converter.
Instead of what I'd have to do in a singleplayer game:
-Make the change.
Also, if I don't want to have the client-side and server-side classes seperated in two (because that means I have to maintain two practically identical classes), I need to disable some functions on the client instance, that I need the server one to do.
It feels like I have to take a lot of extra steps that greatly increase the overall time it takes for me to create something.
Am I approaching something the wrong way, and is there anything I should do differently, based on what I've described here? Thanks in advance.[/QUOTE]
This doesn't sound like a very efficient way to do things. At all.
That said, I couldn't tell you how to do it either.
You should look if you can share code between the client and server.
If you don't mind paying the price for indirect function calls you can use inheritance to seperate client- and server-specific code from the shared stuff.
In C and C++ you can use the preprocessor to define certain routines and data only when certain preprocessor-macros are defined.
In Java, C# and the like you might be able to use Annotations/Attributes for something like that.
Instead of adding new data to a conversion-function, create a generic class/macro/whatever for serializable objects.
It should provide methods to write and read simple types like integers and perhaps some commonly used types (e.g. position vectors) to/from a data stream or buffer, which more complex types can use to (de)serialize their data.
[QUOTE=no-named;40376961]I'm getting fed up with trying to make online multiplayer games.
When a client connects, it needs to be sent the current state of the game. This means that I need a converter at both ends, to convert a class to a string and back.
Sadly, this means that when I need to, say, add an attribute "mana" to all units, I need to do the following:
-Make the change client-side.
-Make the change server-side
-Update the to string converter.
-Update the to game class converter.
Instead of what I'd have to do in a singleplayer game:
-Make the change.
Also, if I don't want to have the client-side and server-side classes seperated in two (because that means I have to maintain two practically identical classes), I need to disable some functions on the client instance, that I need the server one to do.
It feels like I have to take a lot of extra steps that greatly increase the overall time it takes for me to create something.
Am I approaching something the wrong way, and is there anything I should do differently, based on what I've described here? Thanks in advance.[/QUOTE]
You probably should serialize them to a binary format instead of strings, that's a lot faster.
I assume this is for some kind of turn-based game? In that case send only the user commands, then have each party simulate them separately. (This also has the nice side effect of making replays trivial.) The server doesn't need to know the game state if you don't want rankings and if someone cheats the game state gets out of sync and the current game breaks at some point. It's up to you how to handle this, you could either ignore invalid commands and let each player "win" or end the game in a draw/error if there's a discrepancy.
It's a bit more complicated if the players have hidden information, in that case the server has to manage knowledge between them.
Depending on the language you're using there should be an automated serialization module, and it's likely that there is a protobuf implementation which makes crossing language borders easier.
[QUOTE=ZeekyHBomb;40377116]You should look if you can share code between the client and server.
If you don't mind paying the price for indirect function calls you can use inheritance to seperate client- and server-specific code from the shared stuff.
In C and C++ you can use the preprocessor to define certain routines and data only when certain preprocessor-macros are defined.
In Java, C# and the like you might be able to use Annotations/Attributes for something like that.
Instead of adding new data to a conversion-function, create a generic class/macro/whatever for serializable objects.
It should provide methods to write and read simple types like integers and perhaps some commonly used types (e.g. position vectors) to/from a data stream or buffer, which more complex types can use to (de)serialize their data.[/QUOTE]
I did not know about serialization, but it sounds like that will make it a lot easier for me. Thank you very much.
[QUOTE=ZeekyHBomb;40377116]You should look if you can share code between the client and server.
If you don't mind paying the price for indirect function calls you can use inheritance to seperate client- and server-specific code from the shared stuff.
In C and C++ you can use the preprocessor to define certain routines and data only when certain preprocessor-macros are defined.
In Java, C# and the like you might be able to use Annotations/Attributes for something like that.
Instead of adding new data to a conversion-function, create a generic class/macro/whatever for serializable objects.
It should provide methods to write and read simple types like integers and perhaps some commonly used types (e.g. position vectors) to/from a data stream or buffer, which more complex types can use to (de)serialize their data.[/QUOTE]
In C# you can use preprocessor directives like
[csharp]#if SERVER
Console.WriteLine("Server");
#else
Console.WriteLine("Client");
#endif[/csharp]or conditional methods:[csharp][Conditional("CLIENT")]
public static void OnlyOnClient()
{
Console.WriteLine("Client");
}[/csharp]
If the condition for a method isn't met, the method and all calls to it are removed from the binary.
[QUOTE=Tamschi;40377215]You probably should serialize them to a binary format instead of strings, that's a lot faster.
I assume this is for some kind of turn-based game? In that case send only the user commands, then have each party simulate them separately. (This also has the nice side effect of making replays trivial.) The server doesn't need to know the game state if you don't want rankings and if someone cheats the game state gets out of sync and the current game breaks at some point. It's up to you how to handle this, you could either ignore invalid commands and let each player "win" or end the game in a draw/error if there's a discrepancy.
It's a bit more complicated if the players have hidden information, in that case the server has to arrange knowledge between them.
Depending on the language you're using there should be an automated serialization module, and it's likely that there is a protobuf implementation which makes crossing language borders easier.[/QUOTE]
Thank you for the response. I guess you're right, that for turn-based games I wouldn't need the server to know about the game (something I didn't realize before). There is one specific project though, which isn't turn-based, but more of an action RPG, and where I'd like to make sure that one client can't just make crazy claims about their position or other attributes.
[QUOTE=Meatpuppet;40370310]Python, how would you go about getting the sum of elements in different lists?
Assume lines = [[]]
lines[i] is [1, 2, 3, 4] and lines[j] is [5, 6, 7, 8]
How would you do this
[code]for i, j in zip(range(linecount-2, -1, -1), range(linecount-1, -1, -1)):
print max(sum(x, y for x in lines[i], y in lines[j]))
[/code]
(prints the max of the sums of elements)[/QUOTE]
If you want to check all pairs of elements, use product from the itertools module.
[QUOTE=ZeekyHBomb;40368965]
What language and platform?[/QUOTE]
pure C, coding for Linux.
Pascal,
how do I find the average of an array? Here's my code. [url]http://pastebin.com/WF1YUuTm[/url]
[QUOTE=JohnnyOnFlame;40384269]pure C, coding for Linux.[/QUOTE]
You can use the [url=http://pubs.opengroup.org/onlinepubs/007908799/xns/syssocket.h.html]POSIX sockets library (sys/socket.h)[/url].
You can also wrap them in [url=https://developer.gnome.org/glib/2.36/glib-IO-Channels.htm]GLib IO Channels[/url]. I don't know what stuff this abstraction adds, but you can take a look if you like.
I have also heard some good stuff about [url=http://www.zeromq.org]zeromq[/url], but never used it myself so far. I haven't done that much network programming in general.
I don't know any DNS-SD implementations, but Google spits out some results.
[QUOTE=Mickyyismick;40385438]Pascal,
how do I find the average of an array? Here's my code. [url]http://pastebin.com/WF1YUuTm[/url][/QUOTE]
That'll depend on what flavor, length will work fine for delphi, but on free pascal and others you might need to determine it using LOW/HIGH.
[editline]23rd April 2013[/editline]
[QUOTE=ZeekyHBomb;40386453]You can use the [url=http://pubs.opengroup.org/onlinepubs/007908799/xns/syssocket.h.html]POSIX sockets library (sys/socket.h)[/url].
You can also wrap them in [url=https://developer.gnome.org/glib/2.36/glib-IO-Channels.htm]GLib IO Channels[/url]. I don't know what stuff this abstraction adds, but you can take a look if you like.
I have also heard some good stuff about [url=http://www.zeromq.org]zeromq[/url], but never used it myself so far. I haven't done that much network programming in general.
I don't know any DNS-SD implementations, but Google spits out some results.[/QUOTE]
Thanks, I'll have a look. My biggest problem here is finding a good DNS-SD solution, but the links might be of help.
Taking a stab in the dark - maybe your working directory needs to be BONES?
[QUOTE=Eonart;40388394]Sounds like a great idea.
Too bad I'm doing an absolutely horrible job. What should I write?[/QUOTE]
cd C:/users/nigel/desktop/bones
I think
So I'm using Gwen for my UI, and whenever I hit return in my textbox HasFocus is true but the textbox isn't focused anymore. Calling Focus( ) on it doesn't help either. How can I make it so my textbox stays focused even when I hit return?
[editline]derp[/editline]
Nevermind, fixed it by creating a custom class derived from the TextBox one like so:
[code]
public class ConsoleTextBox : TextBox
{
public ConsoleTextBox( Base Parent )
: base( Parent )
{
}
protected override bool OnKeyReturn( bool down )
{
if ( down )
return true;
this.OnReturn( );
return true;
}
}
[/code]
[QUOTE=Meatpuppet;40332409]I don't know what class I should put it in though.[/QUOTE]
Create a ShaderLoader class and make your loadShader function a method on that class called load.
Something doesn't have to be huge to warrant its own class. Smaller, specialized classes are better.
[code]#include <iostream>
#include <stdlib.h>
using namespace std;
int main(){
string names[256];
int ages[256];
int repeat;
cout << "How many employees? ";
cin >> repeat;
cout << endl << "Enter employee names and numbers:" << endl;
for(int i=0; i<repeat; i++){
cin >> names[i];
cin >> ages[i];
}
string name;
cout << endl;
do{
cout << "Enter a name, or Quit to stop the program.";
cout << endl << "Name? ";
cin >> name;
int find;
for(int i=0; names[i]!="0"; i++){
if(names[i]==name){
find = i;
break;
}
}
cout << names[find] << " is employee number " << ages[find] << endl << endl;
}while(name != "Quit");
}[/code]
Need some help, something is throwing a segmentation fault flag and I can't find what, otherwise the program is working like a charm. Any help?
[editline][/editline]
Nevermind I got it working had to add a boolean in there and re-arrange where my if-statements are.
I've got a question about c++ exception safety. I've been making a vector class for practice of exception safety. It's not really a drop in for std::vector but it's basically the same thing. I'm assuming that exception safety is basically if you put a try catch around any of the vectors functions and it failed the vector would be in the state it was before. The problem is that in order to set the capacity of the vector you need to move everything in the container but as far as I can see there is no way to make that exception safe. From what I understand there could actually be a move constructor that throws and if it does the vector is left in a bad way. You could probably just ignore this and it would not come up but I am wondering if there is something I am missing in general to do with exception safety. A naive implementation of set capacity could just allocate a buffer right there, but that's shit and the correct thing to do would be to create another vector, set the capacity, move everything and then swap it with the current vector, but this kind of relies on having a vector already implemented so to implement many of the vectors functions you need an implemented vector. I guess you'd just kind of have to hack away at it until it works as a whole.
[QUOTE=Philly c;40392809]I'm assuming that exception safety is basically if you put a try catch around any of the vectors functions and it failed the vector would be in the state it was before.[/QUOTE]No. Exceptions unroll the stack to the point where they are handled, they don't roll back program state.[QUOTE=Philly c;40392809]The problem is that in order to set the capacity of the vector you need to move everything in the container but as far as I can see there is no way to make that exception safe. From what I understand there could actually be a move constructor that throws and if it does the vector is left in a bad way.[/QUOTE]Move constructors shouldn't throw, unless something very strange is going on.[QUOTE=Philly c;40392809]You could probably just ignore this and it would not come up but I am wondering if there is something I am missing in general to do with exception safety. A naive implementation of set capacity could just allocate a buffer right there, but that's shit and the correct thing to do would be to create another vector, set the capacity, move everything and then swap it with the current vector, but this kind of relies on having a vector already implemented so to implement many of the vectors functions you need an implemented vector. I guess you'd just kind of have to hack away at it until it works as a whole.[/QUOTE] The correct reaction to an exception you don't expect is to let the program crash, unless you're absolutely sure you can fix everything and there are no memory leaks.
I'm pretty sure that, if you just want to resize a vector, just copying the memory area and getting rid of the old vector somehow without invoking any destructors is fine.
[QUOTE=Tamschi;40393112]No. Exceptions unroll the stack to the point where they are handled, they don't roll back program state.Move constructors shouldn't throw, unless something very strange is going on. The correct reaction to an exception you don't expect is to let the program crash, unless you're absolutely sure you can fix everything and there are no memory leaks.
I'm pretty sure that, if you just want to resize a vector, just copying the memory area and getting rid of the old vector somehow without invoking any destructors is fine.[/QUOTE]
I know what exceptions do, but the point of exception safety is that you don't throw half way through changing state.
I've always thought that just copying the memory of a class was a bad thing to do and that you should really be moving or copying it unless it's trivial.
Anyway I think I have a solution. You could make a copy alternative of set capacity be exception safe by not deleting anything from the original vector unless the new one is complete. You can fall back to that if the type is not nothrow_move_constructible. I didn't know that that type trait even existed until now.
What are some games (MP preferred) with some accessible way to script/code for? Other than gmod. Can't really think of any.
I know GTA: San Andreas MP has PAWNO which lets you mod it and such.
[QUOTE=Shadaez;40396999]What are some games (MP preferred) with some accessible way to script/code for? Other than gmod. Can't really think of any.[/QUOTE]
Terraria is unobfuscated and uses .NET, you can derive classes and mod it in C#.
Minecraft has [url=http://www.minecraftforge.net/forum/index.php]Forge[/url].
Skyrim? :v:
What is the easiest way to get a json from a REST api in java and decode it to a hashmap/dictionary?
In python it would work like this
[code]
url = "http://api.rottentomatoes.com/api/public/v1.0/lists/movies/in_theaters.json?apikey={0}&country={1}".format(apikey,country)
responce = json.loads(urllib2.urlopen(url).read())
movies = response["movies"]
[/code]
When I tried to do the same thing in java I couldn't find a way that did not involve using 90000 custom libraries and constant jumping between different types of objects
[code]URL request = new URL(url);
HttpURLConnection urlConn = (HttpURLConnection) request.openConnection();
InputStream json_stream = new BufferedInputStream(urlConn.getInputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(json_stream));
StringBuilder sb = new StringBuilder();
String line = null;
while((line = reader.readLine()) != null){
sb.append(line);
}
json_stream.close();
result = new JSONObject(sb.toString());[/code]
This is the code I used for my JSON requester on Android. It's the same for org.json, iirc. To get the variables and such from your JSONObject, just do [java]myJSONObject.getString("movies");[/java]
[editline]24th April 2013[/editline]
You can read more about org.json [URL="http://www.json.org/java/index.html"]here[/URL].
How would I go about swapping elements in a vector?
For example: the vector that contains 1, 2, 3 if I swapped 2 and 3, would be 1, 3, 2.
I tried this but it crashes:
[code]
for(std::vector<GameState*>::size_type i = 0; i != m_states.size(); i++)
{
if(i != m_states.size() && m_states[i] == state)
{
std::swap(m_states[i], m_states[m_states.size()]);
}
}
[/code]
This code is probably really bad :(
m_states[m_states.size()] always will be out-of-bounds. You mean m_states[m_states.size() - 1].
Also, the i != m_states.size() check in the loops body is useless, since this is the condition for the loop itself.
[QUOTE=ZeekyHBomb;40417662]m_states[m_states.size()] always will be out-of-bounds. You mean m_states[m_states.size() - 1].
Also, the i != m_states.size() check in the loops body is useless, since this is the condition for the loop itself.[/QUOTE]
Well, with the i != m_states.size() I'm trying to make it so I don't try to swap the last element with.. the last element.
Also, thanks!
The loops' body won't be executed for i == m_states.size().
Sorry, you need to Log In to post a reply to this thread.