Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 3 4 [5] 6 7 8

Author Topic: Chartered Waters: new demo! 5/28  (Read 10669 times)

Reudh

  • Bay Watcher
  • Perge scelus mihi diem perficias.
    • View Profile

P'raps a currency conversion system could be useful too - with the kind of money the game's talking, you run out of ints.

Graknorke

  • Bay Watcher
  • A bomb's a bad choice for close-range combat.
    • View Profile

Have I PTWed already? I don't think that I have.
This progressed a lot. keep it up!
Logged
Cultural status:
Depleted          ☐
Enriched          ☑

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio

Here's the most recent build.

I'm about to start working on ship-to-ship combat, and as a prerequisite for that, I made a thing called an 'entity map.' I store ships in a big list/vector called shipList. But going through the whole list so many times per second just to see if there's a ship on the tile you are pointing at would be so slow, so I created a grid the size of the world map. Each turn, a token that has the ID of a ship is dropped into the cell (on the grid) that corresponds to where the ship is on the world map. If there's an old token in the cell, it's emptied. Then when I want to see if a ship is on a certain map tile I check the grid for a token. If the token is old, I ignore it. This lets the entityMap be both efficient and useful. The timestamp is incremented each time the world is updated, and the whole map is cleared every 2147483647 turns. The player probably won't even reach that many turns, but just in case :D


The tooltip shows the name of a ship.

Right-clicking on the ship pops up its status screen. You're like an omnipotent god, peering into the ship's intimate secrets O_O

Another thing that was done is optimizing the pathfinding algorithm. Before optimization, it lagged a lot and paused the game often to calculate a path. After, it's nearly perfectly silky and runs smooth.

Originally, it looked at a huuuuge list of potential places to poke and prod to see if it makes you go closer to your destination(the f-value list). It examined every single element in the list and gave you one with the lowest f-value, calculated by DistanceFromStart + what I think is, but might not be theDistanceToDestination. But the list sometimes reached a couple hundred elements in size. Going through the list is horridly slow.

I tried making it use a heap. Basically, each time you add a new potential place(node) you could poke later, it puts all the potential places in a certain order, with the one with the lowest f-value on top all the tip. I just pick up the top value, and the whole heap shifts so the next-lowest one is on top again. Quite efficient.

Even after these optimizations it was slow. This time, I changed how the nodes were stored. The nodes are places the algorithm has looked at. Ones that are basically dead ends—say, they lead away from the destination, or there are better ways to get there—are put on the closed set. The ones that I want to look at next are put on the open set. Originally I had to do a binary search to retrieve a node every time. Added up by a couple hundred times a second it's a big performance hit. Instead of a map/dictionary, I used a hashmap. If a map has all the nodes sorted in order, and you would basically trial-and-error your way to the element you want, in a hashmap you know (almost) exactly where this element would be, and where that one would be, using magic made into technology via a hashing function.

To sum up? Optimizations! OPTIMIZATIONSZZZZ

Next up is the combat system. After that is better merchant AI, and maybe even pirate ships to attack you!
(well, I suppose I'll need to make GUI for installing and removing ship parts including cannons sometime, but GUI is scary and more importantly boring T_T)
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

GalenEvil

  • Bay Watcher
    • View Profile
    • Mac-Man Games

Looking good! Glad the pathfinding hiccups got sorted out :D How are you wanting combat to function?
Logged
Fun is Fun......Done is Done... or is that Done is !!FUN!!?
Quote from: Mr Frog
Digging's a lot like surgery, see -- you grab the sharp thing and then drive the sharp end of the sharp thing in as hard as you can and then stuff goes flying and then stuff falls out and then there's a big hole and you're done. I kinda wish there was more screaming, but rocks don't hurt so I guess it can't be helped.

Willfor

  • Bay Watcher
  • The great magmaman adventurer. I do it for hugs.
    • View Profile

Quote
Right-clicking on the ship pops up its status screen. You're like an omnipotent god, peering into the ship's intimate secrets O_O
The captain and the first mate are having an affair! D:

Work on that combat, Sky, I know you can do it! :3
Logged
In the wells of livestock vans with shells and garden sands /
Iron mixed with oxygen as per the laws of chemistry and chance /
A shape was roughly human, it was only roughly human /
Apparition eyes / Apparition eyes / Knock, apparition, knock / Eyes, apparition eyes /

Anvilfolk

  • Bay Watcher
  • Love! <3
    • View Profile
    • Portuguese blacksmithing forum!

I haven't looked at pathfinding in forever, but isn't A* already pretty well studied and/or previously implemented in very efficient ways with appropriate datastructures that guarantee theoretical best performance? I can't remember the last time I've heard of using binary search - usually I just shove things in a binary tree, or an appropriately implemented priority queue. I'm probably missing something here though!


Oh, also, the way I always implement maps and positions is by having a Tile class with a list of entities in it. Whenever they move, they get removed from the tile they were in, and added to the tile they are now in. Is this similar to your token system?

Killjoy

  • Bay Watcher
    • View Profile

I haven't looked at pathfinding in forever, but isn't A* already pretty well studied and/or previously implemented in very efficient ways with appropriate datastructures that guarantee theoretical best performance? I can't remember the last time I've heard of using binary search - usually I just shove things in a binary tree, or an appropriately implemented priority queue. I'm probably missing something here though!
A* is djikstra's algorithm, but optimized using a heuristic function.
Which means it will essentially degrade to either O(v*v) or O(e + v * log(v)) if you use either a minheap or fibheap in worst case. So yes, if you implement your A* correctly you already have what is essentially a best performing algorithm.

That said, you can do a lot of local optimizations that are game specific. These wont affect the asymptotic (Theoretical) performance in any shape or form, but can make performance really nice for your game.

I remember I implementing a vanilla A* in java, and it was actually extremely fast. Finding a path from one corner of my 1024x1024 grid to the other, avoiding water and mountains in less than a second.
Logged
Merchants Quest me programming a trading game with roguelike elements.

Mephansteras

  • Bay Watcher
  • Forger of Civilizations
    • View Profile

Fancy stuff. Looking good, Sky!

I really need to find the time an motivation to get back to working on my game...
Logged
Civilization Forge Mod v2.80: Adding in new races, equipment, animals, plants, metals, etc. Now with Alchemy and Libraries! Variety to spice up DF! (For DF 0.34.10)
Come play Mafia with us!
"Let us maintain our chill composure." - Toady One

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio

Looking good! Glad the pathfinding hiccups got sorted out :D How are you wanting combat to function?
In turns! The specifics are hard to describe, so whenever I finish it you'll get to see.

I haven't looked at pathfinding in forever, but isn't A* already pretty well studied and/or previously implemented in very efficient ways with appropriate datastructures that guarantee theoretical best performance? I can't remember the last time I've heard of using binary search - usually I just shove things in a binary tree, or an appropriately implemented priority queue. I'm probably missing something here though!


Oh, also, the way I always implement maps and positions is by having a Tile class with a list of entities in it. Whenever they move, they get removed from the tile they were in, and added to the tile they are now in. Is this similar to your token system?
Not really. In my case, I have a separate list of entities, and a token that points to the entities are moved around. Also, they aren't explicitly removed form the tilemap. The timestamp is ++'d, then the new tokens have the new timestamp. That way, tokens with old timestamps are considered outdated and ignored.

Fancy stuff. Looking good, Sky!

I really need to find the time an motivation to get back to working on my game...
Go for it!

I haven't looked at pathfinding in forever, but isn't A* already pretty well studied and/or previously implemented in very efficient ways with appropriate datastructures that guarantee theoretical best performance? I can't remember the last time I've heard of using binary search - usually I just shove things in a binary tree, or an appropriately implemented priority queue. I'm probably missing something here though!
A* is djikstra's algorithm, but optimized using a heuristic function.
Which means it will essentially degrade to either O(v*v) or O(e + v * log(v)) if you use either a minheap or fibheap in worst case. So yes, if you implement your A* correctly you already have what is essentially a best performing algorithm.

That said, you can do a lot of local optimizations that are game specific. These wont affect the asymptotic (Theoretical) performance in any shape or form, but can make performance really nice for your game.

I remember I implementing a vanilla A* in java, and it was actually extremely fast. Finding a path from one corner of my 1024x1024 grid to the other, avoiding water and mountains in less than a second.
I dunno why my first implementation was slow. :S
Also, I now use both a heap and a hashmap, so it's a lot faster than before. Something that might have slowed my pathing down is that tiles have different costs, which the heuristic has trouble with.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Anvilfolk

  • Bay Watcher
  • Love! <3
    • View Profile
    • Portuguese blacksmithing forum!

Yeah, I implemented A* too way back in college, also Java. Don't recall it working that well... we eventually tested out a ton of heuristics, and non-conservative heuristics made search a LOT faster, at the expense of non-optimality. It definitely reduced the state space we explored by a ton though. We actually plotted that. I wish I remembered more details!

Skyrunner: I don't see any advantages of the token system :( Presumably, every game tick ships are going to move (or some variant of this). To do so, you iterate over the ship list and make them move. If the ship contains a pointer to the tile it's on, and you calculate where it's going to go next (so you have access to that tile), then all you do is change 3 pointers: the ship's tile pointer to the new tile, the old tile's ship pointer to null, and the new tile's pointer to the ship. Barring any other systems interfering with this, there's no performance loss (3 assignments!), there's no dirty or old data, and you've got easier/quicker access to everything. Am I missing something?

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio

Reason I want entity maps: What if I want to do collision detection? Should I iterate over the entire list multiple times for each ship and its tiles? :S What if I want to interact with a ship next to me on the map? Again, should I have to search the entire list of ships to see which ship(s) are on the tile next to me, or look into the token grid and instantly get where to go next?

And when I code AI pirates: they have to check the tiles around them (their 'vision' range) to find targets to attack. Again, with a list, you have to iterate through the entire list multiple times to find a ship that's at a certain position.

I will reuse entity maps for the combat too, where the ships will most likely be multi-tiled.

To sum up: faster collision detection and interaction. ;D

edit: Also, I have ships store a pair<int,int> that is a coordinate.

edit 2: I have no idea how to draw ships when they aren't facing multiplies of 90 degrees in direction. :S Any ideas? It's tile-based, so there's a lot of restrictions.
« Last Edit: July 31, 2013, 08:55:31 am by Skyrunner »
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

MaximumZero

  • Bay Watcher
  • Stare into the abyss.
    • View Profile

Fancy stuff. Looking good, Sky!

I really need to find the time an motivation to get back to working on my game...
Yeah, me too. :(
Logged
  
Holy crap, why did I not start watching One Punch Man earlier? This is the best thing.
probably figured an autobiography wouldn't be interesting

Anvilfolk

  • Bay Watcher
  • Love! <3
    • View Profile
    • Portuguese blacksmithing forum!

Reason I want entity maps: What if I want to do collision detection? Should I iterate over the entire list multiple times for each ship and its tiles? :S What if I want to interact with a ship next to me on the map? Again, should I have to search the entire list of ships to see which ship(s) are on the tile next to me, or look into the token grid and instantly get where to go next?

Hmmmm. Well, I'm not saying you should get rid of the token system. I'm just saying it's probably less useful than having your map itself also keep track of ships instead of tokens. You definitely keep the entity map (which really should be called vector, a map is something that you access using keys)!

Why don't you just store ship pointers (instead of tokens) in the world map itself? I am just wondering why your tokens should ever become out-of-date, and why you have a separate token map and so forth, I guess :) For me it's super intuitive for the world map itself to store what it contains (namely, the ships!), and for that to be updated whenever something moves! Having two different arrays (world map + token map) is probably just going to make the CPU have more cache misses, reducing performance.

With this system you'd get the best of both worlds, at the expensive of like, two extra assignments every now and then, and a whole lot more flexibility!


Regarding drawing, if it's pure ASCII I don't really know, unless you can find a nice font that does that for you. If it's ASCII with underlying graphics, just make a new tileset :)

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio

Something to note is that the world map isn't aware of ships updating. They update themselves, so to speak.
Also, my world map tiles have no information other than tile elevation on them xD Cities are kinda placed on top of the world tiles in a separate vector. Same thing with ships. Not sure why I did that. :v Doesn't largely complicate stuff though.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Anvilfolk

  • Bay Watcher
  • Love! <3
    • View Profile
    • Portuguese blacksmithing forum!

Hahahahahah! :)

Well many maps with one thing each is equivalent to one map with many things, so I'm hoping that works out!
Pages: 1 ... 3 4 [5] 6 7 8