• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
bernatripoll

How to spawn objects near players?

6 posts in this topic

Hello!

 

I have a database with all the objects (static) that have to appear in every player world. My first approach is when one player is, let's say, 30m from an object, the server sends "hey player, there's an object at x,y,x" and the player client adds it to the world.

 

But this means that the server has to calculate the distance between every player and all the objects in the database (array list in memory) in every snapshot (at least 2 times per second) and I think that would melt the servers...

 

Any better approach?

 

Thanks!

0

Share this post


Link to post
Share on other sites

You could have your static objects on a grid. That way you can just iterate through all the grid cells that are within 30m, and query the grid about which objects it contains. To implement it efficiently you could:

 

- Only worry about updating a player's static object list when he moves from one grid cell to the next.

- When a player moves from one grid cell to the next, only worry about the grid cells that are included now and not included before (so assuming the player isn't moving very fast, it should only be a single line of cells at a time (or a square of cells if we're talking 3D)

- If you have large sparse worlds, then instead of having some crazy 100000x100000 grid which is mostly empty cells, you could have a 1000x1000 grid in memory, and objects can put themselves in an appropriate grid slot by calculating iGridSlot % 1000, so an object at grid slot (64363, 25783) would be in grid cell (363, 783) in your structure.

 

Google spatial hashing.

Edited by C0lumbo
0

Share this post


Link to post
Share on other sites

Look into spatial datastructures, such as grid partioning, quadtrees, spatial hashing, etc... that let you answer the "what is the closest object to the player" question efficiently. Also consider that maybe the server could give more information to the client so that it can figure this out for itself, instead of the server doing absolutely everything.

2

Share this post


Link to post
Share on other sites

Simplest is a grid (voxel in 3D) representation. It's easy to compute, easy to query, very fast. It take comparatively more memory. Spatial hashing is kind of the same principle, with better memory footprint. 

 

There are other spatial partitioning structures. Physics engines use them all the time, on 1,000's of interacting and static objects (check out NextCarGame / BeamNG). 

 

The other common strategy is using portals / PVS (Potentially Visible Set). You build a list of areas that are potentially of interest from another area.

Edited by 0BZEN
0

Share this post


Link to post
Share on other sites

As other said, you need a spatial indexing structure, the good news is that nowadays, a lot of database vendors (SQL & noSQL) support spatial indexing smile.png, whether in memory or on disk.

 

You could probably use one of these out of the box implementations, and perform spatial queries on them to get the list of players to be notified when you move an object. The main drawback being that what you really want is not "querying" but rather be "notified" when you move objects around. Something that Elasticsearch does through its percolation feature... But I really don't know if the kind of load and latencies you expect are compatible with this tool. I didn't experiment the thing yet, sadly.

 

At the end, I think the best solution for you depends on these factors:

- You require really low latencies and a lot of queries, but persistence and dataset size is not the core concern: Build your own grid memory based system.

- Your main concern is the dataset size and you don't need to put everything in the process memory: an existing spatial database could possibly do the trick, with a little experimentation.

Edited by JMDeruty
0

Share this post


Link to post
Share on other sites

the good news is that nowadays, a lot of database vendors (SQL & noSQL) support spatial indexing smile.png, whether in memory or on disk


You do not want to base a real-time spatial query on a SQL database implementation. You don't want to base *any* real-time information on direct queries to persistent databases.

This is why we have game servers, as separate from application servers or database servers. The game servers keep a game-specific, "reified," up-to-date in-RAM copy of the game objects and can enforce the rules and update the world state very cheaply. Things that really matter go back to the persistent store in an asynchronous manner. If the game server crashes, you may lose some amount of progress, but that's hopefully rare, and the orders of magnitude of efficiency gains are worth it. The kind of real-time gaming experience you can deliver from an in-RAM custom server compared to what you can deliver AT ALL from a persistent server (much less can deliver with economics that make sense) make it "not a choice."

How often do the objects change location or otherwise mutate? Most games pre-install a "level" that contains the object locations, and update this through "patching." If that's too static, then can you send all the objects within a kilometer when a user connects, and just update this when the user moves more than half a kilometer? Edited by hplus0603
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0