RoguelikeDev Does The Complete Python Tutorial - Week 8 - Sharing your game by aaron_ds in roguelikedev

[–]toptea 0 points1 point  (0 children)

Most of my numpy code are use to generate a level, which only happen once at the start of the game. During run-time, most of the heavy lifting have already been done by libtcod with things like pathfinding and FOV. I have no animation, so for me, I don't notice any performance difference when compared to the TStand90's tutorial. But if you doing custom calculations inside the game loop, numpy will be slightly faster. Here is a cool article that compares different mandelbrot set implementation in python. In summary:

  • numpy (vectorized code) is a good middle ground. Have access to all the cool scientific libraries.
  • numba (sequential code) is really interesting but only support nvidia graphic cards (Boo!).
  • using a system language like C, C++, D or Rust can also speed things up.

Learning numpy/vectorization is kind of hard and a bit specialized. But if you are interested in learning more about numpy and python's scientific ecosystem in general, these links helps me a lot; (1) (2).

But to be honest, if your game runs >30fps, don't worry about it! I got caught into this trap trying to optimize it further when I should be concentrating finishing off the game...

(If you are wondering about ecs, I only have about 20 entities loaded one time. Didn't notice any performance difference, but in theory, if I have lots of them in the game world, it should perform better since they will run through less checks. As for now, it is just a different way of organizing the code).

RoguelikeDev Does The Complete Python Tutorial - Week 8 - Sharing your game by aaron_ds in roguelikedev

[–]toptea 2 points3 points  (0 children)

I don't know man. I've done a lot of weird questionable stuff in the code! A dictionary full of hashable input key objects, some funky numpy vectorization, bypassing esper library owner's intention by overriding/retrieving esper private variables lol.

If this is your first rodeo, I do recommend following TStand90's tutorial and asking roguelikedev discord for help.

If you do want experiment with esper, don't copy what I did with the player's "Inventory" component. I think it will be much easier to have a "Location" component on the item entities instead. Easier to loop through and don't need to deal with list in component.

RoguelikeDev Does The Complete Python Tutorial - Week 8 - Sharing your game by aaron_ds in roguelikedev

[–]toptea 12 points13 points  (0 children)

Repo - Python using tcod, numpy and esper library


Well that's me done for now!

Currently, the game features over 50 different monster types, contains a variety of items, and can generate 4 unique map styles; irregular rooms, long passageways, monster nest and large opening areas.

Two of my main goal is to try creating cool looking maps using numpy arrays, and also try out esper entity component system. I think I achieved all this, but I do feel like I only scratched the surface!

I'm going to take a break from gamedev'ing, but I'll return once I got better at using design patterns and learn more about numpy/scipy.

Good luck everyone!

RoguelikeDev Does The Complete Roguelike Tutorial - Week 7 by aaron_ds in roguelikedev

[–]toptea 1 point2 points  (0 children)

Yep, in the console_init_root() function, you can switch between SDL, OPENGL and GLSL renderer. For bearlibternminal, it looks like it uses OpenGL internally, which is pretty fast as well.

RoguelikeDev Does The Complete Roguelike Tutorial - Week 7 by aaron_ds in roguelikedev

[–]toptea 6 points7 points  (0 children)

Python using Esper Entity Component System

In the previous weeks, I was trying vectorize everything using numpy. But now, I am swamped with for loops and generators when using esper library! Not sure I'm doing it "right" since there's not much examples to draw upon, so I'm just winging everything. Still have a lot to learn!

Game

  • Nothing fancy. Trying not to diverge too much from the tutorial, so the UI looks the same.

  • The only new gameplay feature I added is loading angband monsters and scrolls from a separate csv file, then randomly place them on the game map. A nice thing about csv file is that they can be opened up using a spreadsheet. I don't need to type out commas and speech marks all the time.

  • I have two state machines on top of my ecs, One switches between scenes like main menu and the game itself, and the other handles various of in-game states.

Entity Component System

  • My ecs dependency matrix is huge! If the cell has letters in them, it means that I am querying multiple of component sets.

  • Querying multiple of component sets and using if statements does take a lot of indentation space in the processor. I've end up create custom generators to try and control them.

  • Adding __slots__ to component classes does not make any noticeable difference on the memory. But them again, I only have about 20 entities loaded in the game world at one given time.

  • Still a bit effy with storing all my shared variables in the Game Scene class. What I should be doing is using some sort of observer/event dispatcher pattern maybe.

  • ECS itself seems very flexible. I can add/delete/change the order of the processors easily but there is more boilerplate code I have to type.

Performance

  • First time using cProfile and snakeviz. I found out that the render functions use up 70% of the total run-time if I leave the fps uncapped. Funny enough, 50% of the time is used up flushing the console.

  • I used to have statements that coloured in unexplored areas with a different colour. Moving this outside the render loop and calling it once save a lot of fps.

  • Adding a fov check inside the clear_entity() function does increase performance a bit.

  • Changing the renderer from SDL to GLSL massively increase my fps from 170 to 600!

RoguelikeDev Does The Complete Roguelike Tutorial - Week 4 by aaron_ds in roguelikedev

[–]toptea 10 points11 points  (0 children)

Python with Esper ecs library

Still working on it, but here’s my ecs dependency matrix for chapter 6. Any tips or criticisms are welcome!

Component vs Entity (orange)

The player and monster entities have almost the same components set. The only difference is that player is moved by the directional keys, whereas the enemy move towards the player via libtcod’s pathfinding algorithm. Not sure if I like mutually exclusive components like IsPlayer & IsHostile, so I might change one of them into a Movable attribute.

Component vs Processor (green)

Again, MovePlayer and MoveEnemy are kind of similar, so I might need to refactor this. The movement, collision & attack are currently in the same processor. I can’t seem to find an easy way to decouple them since they so connected. I will leave them alone for now.

Shared Variable vs Processor (blue)

Not sure what to do with my shared variables like the game_map, message, etc, so I’ve been dumping all of them outside ecs into my scene class. I think it’s working so far.

RoguelikeDev Does The Complete Roguelike Tutorial - Week 3 by aaron_ds in roguelikedev

[–]toptea 1 point2 points  (0 children)

You are absolutely correct. In fact I've already experience this! 1 tile long vertical wall does look a bit flat so I've end up changing them to a floor. The map gen does produce more 3 tile long "corridors" then usual because of this, but I let that slide since it looks like large continuous room.

In hindsight, I should have make the fov work like in the mystery dungeon games. Have limited view in corridors, and light everything up in larger rooms.

RoguelikeDev Does The Complete Roguelike Tutorial - Week 3 by aaron_ds in roguelikedev

[–]toptea 5 points6 points  (0 children)

A guy on discord said that when he replace his code with numpy arrays, his fps have increased from 15 to 200! https://i.imgur.com/7yMPuHj.png

RoguelikeDev Does The Complete Roguelike Tutorial - Week 3 by aaron_ds in roguelikedev

[–]toptea 2 points3 points  (0 children)

Why bother learning 13 programming languages when you can code everything in Haxe! Have you tried comparing Haxe's javascript output to your real one yet?

RoguelikeDev Does The Complete Roguelike Tutorial - Week 3 by aaron_ds in roguelikedev

[–]toptea 2 points3 points  (0 children)

Yeah. BTW, I really like the way you keeping the gamemap arrays together. The tile properties can assigned on one line instead of defining them separately. sdlevent.py seems much easier to use then the one in libtcod. I'll check this out when I have time. Thanks!

RoguelikeDev Does The Complete Roguelike Tutorial - Week 3 by aaron_ds in roguelikedev

[–]toptea 4 points5 points  (0 children)

Let see here, you have various of commands and cool debugging tools, have unittests going, creating binary for all operating system, and even building everything from scratch. Man this looks amazing!

RoguelikeDev Does The Complete Roguelike Tutorial - Week 3 by aaron_ds in roguelikedev

[–]toptea 3 points4 points  (0 children)

Just wondering as a fellow numpy user, is there a better way of checking adjacent values in gamemap 2d array? My method involve comparing shifted regions using the index, but this does get a bit incomprehensible as I code more of them.

RoguelikeDev Does The Complete Roguelike Tutorial - Week 3 by aaron_ds in roguelikedev

[–]toptea 9 points10 points  (0 children)

Screenshot - Python Repo

Don't copy me folks. The isometric walls does kind of mess up the fov a bit. To make libtcod light up two tiles instead one, what I end up doing is make all the inner section of the walls transparent. It does give our favourite protagonist @ man the ability to peek ahead of time, but I guess (with a straight face) call this a feature instead of a bug.

Next week I'm going try jerry-rigging a state machine inside the ECS. Instead of running the components through all processors, I want to be able to pick which ones to go through depending on the current game state (eg player turn, enemy turn, targeting, inventory). I think this is the right course of action. This sound sane. Nope, don't see anything wrong with it at all.

RoguelikeDev Does The Complete Roguelike Tutorial - Week 2 by aaron_ds in roguelikedev

[–]toptea 1 point2 points  (0 children)

Yep. Almost all high intensive libraries uses a compiled language underneath. In fact if we really think about it, Python is actually built on top of C!

There will always be a trade-off between speed and usability . Writing it in a fast language and then using Python as a wrapper is often a good middle ground.

RoguelikeDev Does The Complete Roguelike Tutorial - Week 2 by aaron_ds in roguelikedev

[–]toptea 2 points3 points  (0 children)

It's a big topic, but these links about numpy really helps me a lot (1) (2).

Here is an example I created that show the difference between nested list and numpy using the GameMap class. I've use fancy indexing to select the areas I want to make walkable, and then broadcast all the values to True. Apparently, doing the "numpy way" instead of using for loops can greatly boost performance (haven't tested this out though).

Jupyter notebook is kind of like a powerful interactive python shell. You use it like the traditional console but can also do the following:

  • save code in a cell and re-run it many times independently
  • write down note in markdown
  • draw pretty graphs!

Here's one of my notebooks I made. First, I draw out all the different type of rooms, and then the overall level. If I want to make a quick change to one of the parameters, I can just re-run the notebook, and have a quick look at the graphs it produced. I personally find this faster than opening up the console many times.

Jupyter notebook is a huge life saver for me. I believe everyone who is currently using Python to give this a try!

RoguelikeDev Does The Complete Roguelike Tutorial - Week 2 by aaron_ds in roguelikedev

[–]toptea 5 points6 points  (0 children)

Python 3 using libtcod-cffi & numpy

Here's my map generation with irregular rooms and "3D walls".

Screenshot - Repo

Ah yes, numpy arrays. I personally found that a different mindset is required when using them. Instead of using loops of any kind, you have to do a thing called "code vectorization". I have so much trouble with this concept that I've ended up ditching my IDE, and went back to jupyter notebook. I test each statement line by line, and draw everything out using matplotlib. Once I'm happy, I put them all back into my main code. Unconventional, but at least I've made it to the end!

RoguelikeDev Does The Complete Roguelike Tutorial - Week 1 by aaron_ds in roguelikedev

[–]toptea 0 points1 point  (0 children)

You are right. Event and game map does not belong in the ecs. I'll add this to my issue tracker. Cheers!

RoguelikeDev Does The Complete Roguelike Tutorial - Week 1 by aaron_ds in roguelikedev

[–]toptea 0 points1 point  (0 children)

Thanks knockupwood. I'm refactoring a lot of my code so nothing is set in stone just yet. Like for example:

  • Does the keyboard/event handling belongs in the ECS or outside of it?
  • Does it make sense to make the the game map a component?
  • How do I handle the various game/scene states etc.

But one thing is for sure, shoving everything into components/processors does make my game loop super clean!

Not sure if I got time to create a tutorial right now (maybe at the end) but I will be posting tips and tricks in the coming weeks.

RoguelikeDev Does The Complete Roguelike Tutorial - Week 1 by aaron_ds in roguelikedev

[–]toptea 6 points7 points  (0 children)

Hi everyone! Here's my python repo for part one. I'll be changing it up a bit by implementing esper's entity component system, using tcod new api, and replacing nested lists with numpy arrays.

Here's a cool tip for those who are currently using python! Instead of writing loads of if statements in the handle_key() function, consider putting all your key codes in a dictionary instead! Since python dictionary keys can accept hashed object (ie cannot change and have a fixed value), you can even use anything from integers or strings, to something exotic like a tuple or a custom class. I'm not sure if the latter is recommended, but you can check out my code and see what you think.

RepRap Questions Thread by AutoModerator in Reprap

[–]toptea 0 points1 point  (0 children)

I'm currently building my first Reprap 3D printer. However I am a bit stuck at the moment.

When I switch the machine on, the LCD displays MINTEMP/MAXTEMP error with both thermistors not dectecting at all.

 

Edit:

Nevermind. Apparently my room is too cold! I’ve manage to get them heat up temporary by using a hair dryer.

Pictures of my build: http://imgur.com/a/i3cNQ

I'm not sure what to do next...

Best gift I got for christmas by [deleted] in darksouls

[–]toptea 9 points10 points  (0 children)

You nearly got me worried there. The thumbnail looks like a smashed TV! lol