first, I would like to apologize for my bad English, I hope you'll understand me!
So, I am making a video game (very original!) for a uni project. It is an online multiplayer game. I am using Meteor and Phaser.
It is basically a game in which you control a boat and you need to shoot on other players' boats.
My problem is that the other players positions doesn't update in real time on the client machine. Actually, the is a latency between 5 and 10 secondes (maybe more, I didn't timed it).
I think this is due to the way I update the position of other players. In my phaser main update loop, I update the database with the new position of the boat. I think the update function is called 60 times per second, it is quite a lot! I don't know if Meteor can handle so much updates in such a short time?
So this is how I update the database, then I need to update the other players position on the user machine.
For that, I have a subscription to the Boats collection, and I have an observeChanges function that update the position of the other players each time the database is changed.
I guess this is not the easiest way to do it, and not the most efficient!
My first idea was to use something like Meteor streams or Streamy, so that each user could broadcast constantly his position. But I read that Meteor streams is no longer updated, and I couldn't make Streamy work.
So my question is: what do you recommend to broadcast very (very) often datas to other users?
If I manage to do that, I think I can save boats datas in the database every 10 seconds for example.
Thank you :)
Again, I'm sorry for my english, I hope I made my problem understandable. Also, I am quite new to Meteor, so please don't judge me if I have very bad practices ^^
You have a couple of options here. The simplest may be running MongoDB completely in memory: http://edgystuff.tumblr.com/post/49304254688/how-to-use-mongodb-as-a-pure-in-memory-db-redis
Another option is to just use real Redis with Meteor. It would require running a Redis server of course. The learning curve on that may be higher than the option above.
https://github.com/meteor/redis-livedata
Finally, Meteor Streams looks like it would work though it looks like it would mean major changes to the structure of your game. http://arunoda.github.io/meteor-streams/
Related
I have a PostgreSQL 9.5 & meteor 1.4.
I want to select data from db and show it in the browser console.
For meteor & SQL I use this package https://github.com/storeness/meteor-postgres.
I want to show data of db in the browser console in the real time.
e.g my db is [9, 5, ..., 5].
After user came to site we add some data [9, 5, ..., 5, 6,7].
So in the console we have [6,7]
I'm newbie, how can I do that?
Many thanks.
I assume the question is "how do I get reactivity using Postgres"? I will try my best to answer this based on the knowledge I have, but please keep in mind:
I do not work for MDG so the depth of my knowledge on what they are working on is limited to what they have publicized.
I am basing this on MY knowledge, which comes from hands-on experience with a few Meteor-based projects.
Things in the JS frameworks world have been changing SUPER fast, so there may be things out there that I just didn't know about. I am relying on others to fill in here where I may have a lack of knowledge.
So, the short answer: Under current Meteor, as far as I am aware, it is not possible to have reactivity out-of-the-box with anything other than MongoDB.
Now, long answer is a little more complicated. You can write your own code to monitor the SQL server's operations and setups up the pub/sub through DDP yourself. I have some demo code in git that I did for a Meteor Meet-Up in Tampa that dove into how to hack at DDP through Pub/Sub. It's really not super-hard to do the DDP part. The hard part would be to get the reactivity setup on your SQL server of choice...in this case Postgres.
To map things out, here is the basics of what you would need to do:
Implement some sort of custom code that gets events triggered when Postgres gets updated. This code should be intelligent enough to know what tables are updated and which ones are being used in your pub/sub, so that it will update only when needed.
Use the events from #1 to drive your publication. Here is where you could either get nifty and track the data rows OR simply send all rows upon each update. If you choose the first option you will need to somehow reconcile the changes to what's been sent so you can publish the deltas. If you choose the second option then you will still need to track what results you sent to remove them all through DDP. Either way, it seems daunting. Joins and sub-queries might be near impossible to handle
From the client, we would need to simply subscribe to the publication. The client would use mini-Mongo same as before.
No matter how you slice it, it's a tough process to code. MongoDB was used in Meteor mostly because it's Oplog made tracking changes very easy, and since it's not a relational DB they didn't have to worry about the joins/subqueries issues.
The big complication comes in the form of Apollo, which is a HUGE project from MDG to re-vamp how Meteor does reactivity. Apollo is said to decouple Meteor from DDP and MongoDB, and be less pub/sub-ie and rely on GraphQL. I haven't really looked into it much, so I can't really give you details as to what any of that really means in the grand scheme of things, but the big take-away is that if you can wait it might be able to solve some, if not all, of your problems. On the flip-side, many people would say "don't count your chickens before they hatch", i.e. don't expect something that hasn't been released/delivered to solve real problems you have now.
I'm a beginner in all things code, but am extremely interested in working with it. I am a photo student wanting to integrate digital media and my photographic processes. I was seeing if anyone had any advice for a problem I'm having. I started using Processing to achieve a "generation loss" compression effect to my photographs, and I want to move that to the web. So what I want to happen is every time someone goes to the specified web address, the application, will continue. For example, if I am the first user there, I see the first photograph in the sequence. If I am the 650th person, I see the 650th image. I was wondering if anyone had any suggestions, if I should continue trying to use Processing, or use a javascript, or any other means. Any help would be greatly appreciated! I can also post what I'm using in processing and such. Thanks so much in advance.
You have to break this down into a few pieces:
The first piece is the actual algorithm that "decays" an image based on some number. It sounds like you have that working.
The second piece is storing that number on a server somewhere so that it can be accessed and modified by various users over multiple sessions. It sounds like that's the part you're confused about.
There isn't a way to automagically store variables across multiple runs in a Processing sketch. After all, that entire thing is actually being run on the clients' computer! But what you can do is store the variable in a central location so that everybody can "share" that variable.
There are many ways to accomplish that, which is why people are saying your question is too vague. The most obvious solution would be to use a database, although using a database to store a single number might seem like overkill. You could also setup your web server to increment a number stored in a file every time the page is accessed.
Which approach you take depends on the setup of your program, web server, as well as your own comfort level with programming.
Good luck! It sounds like an interesting project.
I need to write an app that allows any number of web clients to increment and decrement a number. This, along with identifying info, gets sent to and stored on a server. Concurrently, another app watches all updates from the clients and visualizes that data on another webpage.
This kind of problem is new to me, so I'm trying to figure out a decent way to do this, but also want one that isn't overkill. It looks like using client-side javascript to write to server files via ajax might be a bit tricky, so I thought of node.js and a SQL database. however, given how simple this app is I'm wondering if it's overkill.
I'm probably looking at about 100 max concurrent clients. I want the data to persist so that I could revisualize a previous moment in time (or restart a crashed service w/o loosing data).
Would this be overkill? I'm really just looking for a simple approach to try.
What you propose sounds solid to me. Node.js is pretty light, and you have your choice of many databases to connect to.
100 simultaneously connected clients is actually a significant amount of traffic anyway.
Me and my startup app company is working on a turn based multiplayer iPhone application. Let it be said that neither one of us have any database, or server, knowledge whatsoever. Though, we are willing to learn.
The flow of the game will be similar to such games as: WordFeud, WordsWithFriends, Rumble etc.
Let me start of by where a lot of searching on the web has gotten us:
We have decided to use CouchDB as a tool for storing information about users, game sessions and other stuff. CouchDB is an open source noSQL database system. The reason is that we have been taught, that it should support a lot off concurring users. Besides, that it scales - we are hoping to go big, of course.
Our CouchDB, is hosted on IrisCouch. IrisCouch is an "in cloud" hosting service designed for running CouchDb.
So, we've got a CouchDB server up and running, and we know the basics on how to query data from the server.
Our biggest confusion right now, is how we should set up the system to work according to best practices. Right now we are at the point where we are able to receive and submit data to the server.
Our game is supposed to have Facebook integration, so that the users can register via our app or through Facebook. After that they can play with random matched opponents, or play with friends. After a match is started, one player will get a set of question to be asked, after he has answered, the other player should be notified, through push notification, that it's their turn. After a few rounds the game is finished.
At this point, we think this might be the best solution for the flow of the application:
A user connects to another user -> a game session is opened as a
document in a database called "games".
The newly created document contains both player names, question,
answers etc
A field named "whos_turn" decides which of the two players turn it is.
After the game has ended, the session is erased.
Again, and as you may see, we are in the dark as of how to really do it, but this is the general idea.
So, my questions goes as following:
Is it best to query the data directly from the iPhone application, or through a web service?
What is the best way to set up the database, to best manage the flow of the application?
Any information, that could lead us closer will be gladly appreciated :)
In advance, thank you!
Olav Gundersen
EDIT#1 : Our Objective-C programmer managed to connect two iPhone devices using CouchDb. The iPhone application consists of a table view, that has a concurrent connection with the database, so that when someone POST to the database, it shows up on the tableview of all the other connected phones. Behold: a severely ineffective chat system.
If is a multiplayer you would need to have the app to communicate to the remote iriscouch.db but I am concerned by the point where you state that neither you or your friends have any database experience. You are willing to learn so I think the best place to start is:
http://guide.couchdb.org/editions/1/en/index.html
There are several issue you might find with scalability if you plan to erase documents continuously. DB Size can be considerable on couchdb and you will need to compact &cleanup the db regularly. But I don't think is a major issue for now as this is at a start up level.
The question "best way to setup the database and best manage the flow of the application" should be addressed by your team. If you do not have someone with any database experience you should try to find someone willing to help you. It should be someone with extensive experience in databases. You might find some fairly reasonable professionals at http://www.odesk.com
In total honestly I don't think you will be successful if you don't have such a figure - either as a freelancer or contributor - to help you having a solid database logic in the game that will ensure a great user experience.
For example: have you considered the latency-delay issue by using a db based in the USA (Iriscouch) vs. where your users are located?
For this reason you might want to do as much as possible client side (embedded database like sqlite or touchDB that is essentially couchDB for iPhone)
For an iPhone application you might want to try TouchDB that is made exactly for that
https://github.com/couchbaselabs/TouchDB-iOS (caveat: being that you need connectivity to check turns etc this might not be the ideal solution but it could work to store some information locally).
To lay this out you would need someone with experience with couchdb to set up a proper, usable application. There is nothing wrong in being enthusiast about your idea but to make it a success you need a technical mind in the database side. Of course you might be well capable to learn this yourself. After reading the CouchDB book you should be in position to create a basic flow to fit your needs.
Of course other more experienced users might come with a more comprehensive answer or a sample layout but I don't think would be the best approach. Even if someone posts a full layout of the doc structure and how to query it how are you going to service the app if something goes awry e.g. sessions don't get deleted, conflicts etc. ? hence my sincere advice to get some ad-hoc expertise for your case.
This might also result in analyzing suitable alternatives. I don't think you should buy into the idea that CouchDB can scale and hence is the best/only option for you (of course this might well be the case and if you feel that is a good option..go for it). For example twitter, google adwords and many other online apps are using mysql to store their data so for sure CouchDB is not the only database that can scale!
I think this demo app could be a good example to follow: iOS Couchbase Demo
I am a programming novice, so please forgive the technical ambiguity here. I will try to be as specific as possible about what I am trying to accomplish.
I am trying to build an interactive website where multiple clients can log on and view a board game. The board game consists of regions on a map with color (player who controls it) and number (armies) variables, as well as draggable tokens.
I have built a client-end version in JavaScript using the Raphael interface for SVG graphics, and would like to build a server that can process any changes one client makes to the board and update the boards of the other clients. In my mind, the sequence would be something like:
Action performed by the user
Action listener updates client view
Update sent to server
Server changes database to reflect change
Server notifies all clients
Clients update view
I've read up on Ajax/XML a bit, but the tutorials I have found have mostly been about getting static data, and I haven't seen an example of actually CHANGING dynamic data on a server, nor have I been able to find any examples of what the server functions should look like.
So basically my question is, can anyone point me in the right direction here? I would very much appreciate a general outline about how I could go about accomplishing this, as well as direction to a tutorial or two that relates to the task. Thank you!
You may look at nodeJS and socket.io.
With this technology it is possibile to create real time web applications.
Its a bit older, but here is a game we did some time ago:
https://github.com/stravid/unitacs
It also uses raphaelJS.