Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (523)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (592)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Collision detection - server side  (Read 1269 times)
0 Members and 1 Guest are viewing this topic.
Offline israelg99

Junior Devvie





« Posted 2014-06-09 13:42:55 »

Hello, I am making a multiplayer game with LibGDX, but the libgdx only installed in the client. which means the server is a complete pure java project.
I use Tiled maps for the game, with libgdx its really easy to do collision detection with all the tiled classes, but with pure java project its nightmare (the server).

So how can i do server-side collision detection? or to simplify the question, how can i read tiled maps without any libraries but with pure java?

I have some ideas in mind, i will test them and share them is they are helpful, but please post yours either. thanks Smiley
Offline RobinB

JGO Ninja


Medals: 44
Projects: 1
Exp: 3 years


Spacegame in progress


« Reply #1 - Posted 2014-06-09 13:53:03 »

Dont use collission detection server side, install libgdx or implement your own system.
Online ags1

JGO Wizard


Medals: 72
Projects: 3
Exp: 5 years


Make code not war!


« Reply #2 - Posted 2014-06-09 14:07:41 »

How are you going to handle races to occupy locations?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline israelg99

Junior Devvie





« Reply #3 - Posted 2014-06-09 23:34:45 »

Dont use collission detection server side, install libgdx or implement your own system.
What do you mean? you think i should make client-side collision detection? if that's what you meant, you are right, but i will make the client side collision detection for prediction / interpolation, but the actual collision detection will be server side, other wise hackers will hack the collision detection without problem, and will cheat the game and ruin the multiplayer experience.
Offline israelg99

Junior Devvie





« Reply #4 - Posted 2014-06-09 23:35:23 »

How are you going to handle races to occupy locations?
I don't understand can you explain more? thanks
Offline Cero
« Reply #5 - Posted 2014-06-10 00:01:31 »

It seems like very good idea: do physics on the server and later sync up.

the problem is: latency. many elements complex physics, now youre getting a lot of latency =/

if 1000 players send a physics request to the server, it has to calculate them all. instead of everyone for themselves. and if the code is consistent the physics SHOULD behave the same for everyone.
of course the server could also have a thing where it just calculates the physics in an area and distributes the positions again and stuff

pretty sure there are whole books on this topic

Online ags1

JGO Wizard


Medals: 72
Projects: 3
Exp: 5 years


Make code not war!


« Reply #6 - Posted 2014-06-10 16:05:48 »

What do you do when two or more entities try to move to the same location at the same time, or nearly the same time. Your collision detection logic is not instantaneous, so both calculations will start (not knowing about the rival move) and calculate that the new location is clear... the end result is two entities now intersect. (I'm assuming your server is multithreaded here.)

Offline israelg99

Junior Devvie





« Reply #7 - Posted 2014-06-11 13:16:52 »

What do you do when two or more entities try to move to the same location at the same time, or nearly the same time. Your collision detection logic is not instantaneous, so both calculations will start (not knowing about the rival move) and calculate that the new location is clear... the end result is two entities now intersect. (I'm assuming your server is multithreaded here.)
Basically, in my game the players can collide each other, in my game it looks completely fine, just every player will see his player on top. additionally it even looks illogical if the players can't move through other players. i tested it by the way.
Offline israelg99

Junior Devvie





« Reply #8 - Posted 2014-06-11 13:49:07 »

Hello,
So as nobody could really help me, and i couldn't find any documentation or libraries to use tiled maps, i don't mean libraries like libgdx, i mean libraries for easy checking, customizing the maps and tiles, collision detection, and everything you want. but a library without any textures to load or using OpenGL and your graphics card in order to work. just a library to work with the map without rendering it (like server sided collision detection).

So extremely long story short, i created a basic library, which i can give to you all if you want.
It works like this, exactly how i want it -
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
TMXMapLoader.Load(); // Loading the TMXMapLoader
TiledMap map = TMXMapLoader.readMap("assets/maps/foo.tmx"); // We reading the map

// Get Tiled Layer, which is basically the layers you create inside Tiled
map.getTiledLayer(i); // Get Tiled Layer with an index, returns TiledLayer.

// Get a tile/cell
map.getTile(i, x, y); // First parameter = layer index, Second parameter = X axis of the tile, Third parameter = Y axis of the tile. returns Tile.
map.getTiledLayer(i).getTile(x,y); // Same as above.

// Check if the tile has the `blocked` property, if yes we can't move through it or collide it (wood, stone), if not we can move through it (like air, water).
map.isBlocked(i, x, y);  // First parameter = layer index, Second parameter = X axis of the tile, Third parameter = Y axis of the tile. returns Boolean
map.getTile(i,x,y).isBlocked(); // Same as above
map.getTiledLayer(i).getTile(x,y).isBlocked();  // Same as above

// Get whatever you want
map.containsKey(i,x,y, key); // Get any property of the tile
map.getTile(i,x,y).containsKey(key); // Same as above
map.getTiledLayer(i).getTile(x,y).containsKey(key); // Same as above

// Get Tileset
map.getTileset(i); // Just get a Tileset with an index

// Get properties of the Tileset
map.containsKey(i, key) // Get any property of the tileset
map.getTileset(i).containsKey(key) // Same as above


That's what i remembered, you can do basically everything, very easy to use. i added bunch of useful functions and more advanced than those, but no time to show.
tell me what you think. its not pro or something just created something fast that is exactly what i needed, and couldn't find something like this nowhere.

If you want i can give it to you all.
Online ags1

JGO Wizard


Medals: 72
Projects: 3
Exp: 5 years


Make code not war!


« Reply #9 - Posted 2014-06-11 17:11:47 »

Actually I am doing something very similar in my game. The whole world runs without any rendering or OpenGL, as a pure Java headless application. I also built collision detection from scratch.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline CodeHead

JGO Knight


Medals: 41


From rags to riches...to rags.


« Reply #10 - Posted 2014-06-11 17:28:20 »

Hello,
So as nobody could really help me, and i couldn't find any documentation or libraries to use tiled maps, i don't mean libraries like libgdx, i mean libraries for easy checking, customizing the maps and tiles, collision detection, and everything you want. but a library without any textures to load or using OpenGL and your graphics card in order to work. just a library to work with the map without rendering it (like server sided collision detection).

So basically you want libtiled-java.

Arthur: Are all men from the future loud-mouthed braggarts?
Ash: Nope. Just me baby...Just me.
Offline israelg99

Junior Devvie





« Reply #11 - Posted 2014-06-11 18:26:04 »

Hello,
So as nobody could really help me, and i couldn't find any documentation or libraries to use tiled maps, i don't mean libraries like libgdx, i mean libraries for easy checking, customizing the maps and tiles, collision detection, and everything you want. but a library without any textures to load or using OpenGL and your graphics card in order to work. just a library to work with the map without rendering it (like server sided collision detection).

So basically you want libtiled-java.
Yeah.. i couldn't understand how to get cells in the map.
As you can see in what i did, you have this function
1  
map.getTile(i,x,y)

I couldn't find something like this in libtiled so i decided to create a `library` myself.
Offline CodeHead

JGO Knight


Medals: 41


From rags to riches...to rags.


« Reply #12 - Posted 2014-06-11 19:02:56 »

I believe for that it would be something like:
1  
((TileLayer)Map.getLayer(int i)).getTileAt(int tx, int ty);

It looks like the methods you've written are pretty close to the original. I will say I'm surprised by the lack of documentation for the library (libtiled-java, not yours), but the source is straightforward and compact enough that a quick "find" command is usually enough to get pointed in the right direction.

Either way, it may be something to keep in mind in case you hit a hiccup with implementing a feature in your library, and need to see how it was done before.

Cheers. Grin

Arthur: Are all men from the future loud-mouthed braggarts?
Ash: Nope. Just me baby...Just me.
Offline israelg99

Junior Devvie





« Reply #13 - Posted 2014-06-12 13:07:51 »

I believe for that it would be something like:
1  
((TileLayer)Map.getLayer(int i)).getTileAt(int tx, int ty);

It looks like the methods you've written are pretty close to the original. I will say I'm surprised by the lack of documentation for the library (libtiled-java, not yours), but the source is straightforward and compact enough that a quick "find" command is usually enough to get pointed in the right direction.

Either way, it may be something to keep in mind in case you hit a hiccup with implementing a feature in your library, and need to see how it was done before.

Cheers. Grin
Hey thanks, i tried this command in lots of ways, and i did exactly what you wrote here.. but it still didn't work and returned null.. does it work for you? if it does i will try again

Anyways, I really like my library, it has a lot more features then libtiled and imo its more flexible, effective and useful, so i don't really see why should i switch to libtiled.
Offline CodeHead

JGO Knight


Medals: 41


From rags to riches...to rags.


« Reply #14 - Posted 2014-06-12 16:49:17 »

Hey thanks, i tried this command in lots of ways, and i did exactly what you wrote here.. but it still didn't work and returned null.. does it work for you? if it does i will try again

Since the internal data structure of a TileLayer uses a 2D array of non primitive types, null is a valid return value for the function when no tile data has been set for a particular map offset. The format that I posted in my earlier reply does indeed work when using libtiled.

Anyways, I really like my library, it has a lot more features then libtiled and imo its more flexible, effective and useful, so i don't really see why should i switch to libtiled.

By all means, stick with what works for you. Smiley My original reply was a response to your assertion that you couldn't find a stand alone library to work with Tiled maps on the server side. Even if it's not the route you chose, it may come in handy if somebody searches for similar info in the future. Wink

Arthur: Are all men from the future loud-mouthed braggarts?
Ash: Nope. Just me baby...Just me.
Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

SHC (21 views)
2014-11-25 12:00:59

SHC (19 views)
2014-11-25 11:53:45

Norakomi (18 views)
2014-11-25 11:26:43

Gibbo3771 (21 views)
2014-11-24 19:59:16

trollwarrior1 (36 views)
2014-11-22 12:13:56

xFryIx (74 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50

digdugdiggy (46 views)
2014-11-12 21:10:15

digdugdiggy (41 views)
2014-11-12 21:09:33

kovacsa (67 views)
2014-11-07 19:57:14
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!