bit-engine | A BitTorrent client built with Ruby and EventMachine | Stream Processing library
kandi X-RAY | bit-engine Summary
kandi X-RAY | bit-engine Summary
A BitTorrent client built with Ruby and EventMachine. Bit-Engine is still experimental. It is just at the point where you can download torrents with it.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Processes a message .
- Add a block to the block .
- Called when a torrent is received .
- Register a new peer .
- Request a new block .
- Open a peer .
- Updates the counter with a given key
- Add a new peer to the peers .
- Send the request to the block
- Start the torrent .
bit-engine Key Features
bit-engine Examples and Code Snippets
Community Discussions
Trending Discussions on bit-engine
QUESTION
As a fun project I decided to try and create a top down 2D game engine in HTML, CSS and JavaScript. I have the basics down, generating a grid and moving that grid when using the arrow keys to simulate walking. As a test I just used a single sprite as background, when walking up for example the bottom row height is animated from 50 to 0px, simultaneously it adds a row to the top whose height is animated from 0 to 50px. Up to there it works well and is pretty responsive.
I decided on storing all tile data in a database, then using PHP to generate an XML file on page load, store that in a javascript variable and then use find()
to get the data I need. Every tile has a latitude and longitude so I can search for the tile that matches both those values and pull other relevant information like if the player can walk there, which texture it needs to have, etc.
My XML: http://www.nickbetting.nl/bit-engine/test3/createxml.php?id=1
The problem is, it's incredibly slow. I decided on a 25x15 grid of 50x50px tiles. So on initial page load it has to find the starting 375 tiles, get their data and replace the images in the tiles for the ones from the data. This initial load takes maybe 10-20 seconds.
When I then use the arrow keys to walk, it will calculate which tiles need to be rendered, then uses find()
to get the data for those tiles, creates a new row and appends the tile elements with the image corresponding to that tile's texture. That also takes 1-2 seconds, which is many times slower than walking without parsing the data and finding the information.
In short:
- I pull up the XML through ajax
- I save that XML as an XMLdocument to a variable
- I calculate which tiles need to be loaded based on the spawn location
- I use
find()
to get those tiles from the XML stored in the var - When walking I add a row or column of tiles in the direction you're walking and removed a row or column tiles on the opposite direction
- When walking those new tiles will also use
find()
to get the data for each tile from the XML stored in the var
This is my JS: http://www.nickbetting.nl/bit-engine/test3/js/functions.js
This is the test I have up: http://www.nickbetting.nl/bit-engine/test3/
Note for this test:
- I'm not making a zelda clone, that's just some placeholder art
- Walking up will get the tile data from the XML
- Walking any other direction will just load empty grass squares without consulting the XML data
- Walking up is how it should work, the other directions are just to compare how much time it takes to load the data
So, my question. How can I make this faster? Is there a better way to store and find data like this or is there a better way to render the new tiles in the DOM? Is jQuery just too slow for things like this?
Any other tips are also appreciated. I know that there are free and ready to download 2D JS game engines but I'm doing this as a learning experience. I generally do projects like these to see how far I can get without help and to learn new things by running into new problems.
...ANSWER
Answered 2019-May-24 at 11:56It's tough to make any recommendations on this without the advice basically boiling down to "rewrite your engine". However, there are a couple of things you're doing that could be optimised;
- Use a spritesheet instead of individual images (this only has to load once)
- Use Canvas. Manipulating the DOM is slower when editing many elements at once
- Store only the data you need in the database. The x, y, and sprite reference of a tile, for example.
- Use JSON instead of xml.
Here's a useful link to MDN regarding tile engines, tilemaps and canvas.
To address your actual query about find being slow, there's a small discussion about this here.
Update:In regards to detecting which tiles can be walked on, you have a few choices. A couple of the popular ones are;
- Do as you're already doing and store a flag for this in the database
- Use two layers in your tilemap. One layer to render the sprites, the second to indicate which tiles can/can't be walked on. A reference that discusses this. This is useful if you want to do other things with the titles, such as slow a player down (water) or hurt a player (lava) when walked on.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install bit-engine
On a UNIX-like operating system, using your system’s package manager is easiest. However, the packaged Ruby version may not be the newest one. There is also an installer for Windows. Managers help you to switch between multiple Ruby versions on your system. Installers can be used to install a specific or multiple Ruby versions. Please refer ruby-lang.org for more information.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page