Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 22 23 [24] 25 26 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 888017 times)

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #345 on: January 10, 2012, 07:48:12 am »

Here's something I made a few weeks ago:
It's a geodesic grid made by repeatedly subdividing a cube and projecting the new points onto a sphere. I was thinking about using it to make a Civ-like 4X game, because it has the useful property that the tiles (which are a bit hard to see because I had the program make a grid with 98,304 of them) look mostly the same almost anywhere on the sphere which would allow my envisioned game to avoid the usual problems encountered around the poles.
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #346 on: January 10, 2012, 09:36:53 am »

Hmm, I have had a bit of a revelation.
I figure I want my game to chug along at a nice little 30FPS max. Right now, uncapped, it does mid 60's when running through the visual studio IDE, but if I go and dive in the bin for the .exe that runs at the high 70's to low 80's.
That is for a 2d level that is 100 by 100 tiles in size. Don't get me wrong, 10,000 tiles is nice, but it does seem a little small. Ideally a large map would be 1,000 by 1,000 in size, bringing me up to 1,000,000 tiles. Further more, I'm planning on implementing a third dimension, so if I had about 10z levels, for a huge 3d level, that brings me to 10,000,000 tiles.
Here is where the horror story kicks in. As it is a multi player game, each player could, in theory, be in their own instance, and if they were all in such a huge instance that brings me to x * 10,000,000 so bring three friends along and we are up to 40,000,000 tiles, being updated at a rate of 30 fps, best outcome for a worst case scenario.
Currently 10,000 tiles makes about 80fps...


Fuck this, I'm jumping ship and starting over in c++. I have had a few ideas for how I should have done things in the first place, so it should all go faster this time around, hopefully.
Switching from properly coded python to properly coded C++ rarely increases the speed by more than a factor 7, so things are still going to be slow.


If I were you, the first thing I would tackle is your drawing algorithm. First of all, you don't need to redraw tiles that don't change. Secondly, you should only draw tiles that the player can actually see and you're not going to see all of the 1.000x1.000 map at once. Finally, the major part of your levels isn't going to change. You can draw the whole level at once (or in chunks) and store that, then blit the level and blit any updates over it. Blitting a single image is fast as hell.
Logged

Willfor

  • Bay Watcher
  • The great magmaman adventurer. I do it for hugs.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #347 on: January 10, 2012, 09:47:32 am »

Could you link me to the source code of something similar. I like to learn by seeing examples but I have no idea what to google to get something similar.

As far as I know, there is no such thing. What I can give you though is a chunk of my own code, which is an overseeing decision block which sends the AI into different functions that do the grunt work. Note that I use some hilariously bad coding practices here, and I also had to add 90% of the comments you'll see literally just now.

Spoiler (click to show/hide)

What you're going to need on your own if you want to recreate it is: A bunch of people who have been given personality features, a way to determine what personality features they like in someone, varying sexual drives, and a loop that sends each of them into this function.

This is only a small part of a larger hobby simulation I'm making, but I needed characters inside who were constantly being given positive or negative stimulii to build histories. Romance seemed like an ideal way to get this constantly happening...

Also, ChastePursuit() is not actually all that chaste inside the actual code in case someone was wondering.
« Last Edit: January 10, 2012, 10:01:39 am by Willfor »
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 /

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #348 on: January 10, 2012, 10:22:26 am »

Hmm, I have had a bit of a revelation.
I figure I want my game to chug along at a nice little 30FPS max. Right now, uncapped, it does mid 60's when running through the visual studio IDE, but if I go and dive in the bin for the .exe that runs at the high 70's to low 80's.
That is for a 2d level that is 100 by 100 tiles in size. Don't get me wrong, 10,000 tiles is nice, but it does seem a little small. Ideally a large map would be 1,000 by 1,000 in size, bringing me up to 1,000,000 tiles. Further more, I'm planning on implementing a third dimension, so if I had about 10z levels, for a huge 3d level, that brings me to 10,000,000 tiles.
Here is where the horror story kicks in. As it is a multi player game, each player could, in theory, be in their own instance, and if they were all in such a huge instance that brings me to x * 10,000,000 so bring three friends along and we are up to 40,000,000 tiles, being updated at a rate of 30 fps, best outcome for a worst case scenario.
Currently 10,000 tiles makes about 80fps...


Fuck this, I'm jumping ship and starting over in c++. I have had a few ideas for how I should have done things in the first place, so it should all go faster this time around, hopefully.

Another option is to not update each tile individually.  For example, I have a list of monsters,objects,etc on my map that need updating in an array.  I just iterate through that list instead of every tile, which saves a ton of time. c++ will give you savings, but changing the algorithm will probably help way more!

Edit:  Or what Virex said.  :P

Here's something I made a few weeks ago:
It's a geodesic grid made by repeatedly subdividing a cube and projecting the new points onto a sphere. I was thinking about using it to make a Civ-like 4X game, because it has the useful property that the tiles (which are a bit hard to see because I had the program make a grid with 98,304 of them) look mostly the same almost anywhere on the sphere which would allow my envisioned game to avoid the usual problems encountered around the poles.

That is pretty cool.  Its that sort of thing I'm hopeless at.  :)
« Last Edit: January 10, 2012, 10:39:53 am by Levi »
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #349 on: January 10, 2012, 10:40:45 am »

Here is a rough screenie of something I've been working on with python and libtcod.

Spoiler (click to show/hide)

I've been lazy for the last few weeks though and haven't done much.  I think I'll try to put in more of an effort this week.

I'd play this just for the [T].
Logged

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #350 on: January 10, 2012, 12:54:44 pm »

Hmm, I have had a bit of a revelation.
I figure I want my game to chug along at a nice little 30FPS max. Right now, uncapped, it does mid 60's when running through the visual studio IDE, but if I go and dive in the bin for the .exe that runs at the high 70's to low 80's.
That is for a 2d level that is 100 by 100 tiles in size. Don't get me wrong, 10,000 tiles is nice, but it does seem a little small. Ideally a large map would be 1,000 by 1,000 in size, bringing me up to 1,000,000 tiles. Further more, I'm planning on implementing a third dimension, so if I had about 10z levels, for a huge 3d level, that brings me to 10,000,000 tiles.
Here is where the horror story kicks in. As it is a multi player game, each player could, in theory, be in their own instance, and if they were all in such a huge instance that brings me to x * 10,000,000 so bring three friends along and we are up to 40,000,000 tiles, being updated at a rate of 30 fps, best outcome for a worst case scenario.
Currently 10,000 tiles makes about 80fps...


Fuck this, I'm jumping ship and starting over in c++. I have had a few ideas for how I should have done things in the first place, so it should all go faster this time around, hopefully.
Switching from properly coded python to properly coded C++ rarely increases the speed by more than a factor 7, so things are still going to be slow.


If I were you, the first thing I would tackle is your drawing algorithm. First of all, you don't need to redraw tiles that don't change. Secondly, you should only draw tiles that the player can actually see and you're not going to see all of the 1.000x1.000 map at once. Finally, the major part of your levels isn't going to change. You can draw the whole level at once (or in chunks) and store that, then blit the level and blit any updates over it. Blitting a single image is fast as hell.

He started with C#, not Python.  C# may be slowing things down.  .NET may also slow things down.  Straight C++ should be faster.  And you control your own memory in C++, which I'm assuming C# doesn't do.  Furthermore, if efficiency is killing you, it's easier to embed assembly in C++ than pretty much any higher level language.

Good luck, Max.  Let us know how it works out and if we can help.  I'm decent at C++.
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #351 on: January 10, 2012, 01:06:16 pm »

Oh that's even less of a difference then, as you don't have to bother with an interpreter and memory allocation is blazing fast in the .net VM (At the 'cost' of having a garbage collector). Difference between C# and C++ is roughly a factor 2, depending on application of course. From his description, max was aiming for a speed increase of a factor 4000 or something and no language can give you that much of a speed increase.
« Last Edit: January 10, 2012, 01:10:20 pm by Virex »
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #352 on: January 10, 2012, 01:54:52 pm »

Language wouldn't make a difference like that, but since 99% of all his tiles aren't changed every 1/30th of a second, he should probably rethink his drawing and updating loops ;)
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Willfor

  • Bay Watcher
  • The great magmaman adventurer. I do it for hugs.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #353 on: January 10, 2012, 03:09:17 pm »

Also, try lessening your calls to libtcod's pathfinding algorithm. It takes up more time from larger maps, and honestly, the fewer calls I made, the better speeds I would get.
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 /

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #354 on: January 10, 2012, 05:42:16 pm »

Okay, so this is probably a dumb (C#) question, but MSDN is not forthcoming with answers.  Is there a way to return and then alter multiple values in an array in one statement?

In my roguelike, I store the player's position as a byte array of two numbers (x and y position) so that it can be sent into and returned from functions as a single thing.  But for the walking function, I want to be able to change it in as simple a statement as possible, so is there some way to ++ or -- multiple array values, without having to pull them out and then plug them back in?

EDIT: Actually, I guess it's unnecessary, since I think I can just do this in two lines instead of one.  But I'm still curious anyway.

EDIT: Fuck yeah, I have walk-around collision detection.  I'd post a screenshot, but it's not like there's much to see.
« Last Edit: January 10, 2012, 05:54:42 pm by Aqizzar »
Logged
And here is where my beef pops up like a looming awkward boner.
Please amplify your relaxed states.
Quote from: PTTG??
The ancients built these quote pyramids to forever store vast quantities of rage.

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #355 on: January 10, 2012, 05:51:49 pm »

Okay, so this is probably a dumb (C#) question, but MSDN is not forthcoming with answers.  Is there a way to return and then alter multiple values in an array in one statement?

No idea, but ruby has the extremely useful map method, where you can do things like this:

Code: [Select]
array = [1,2,3,4,5,6]
array.map() {|a| a * 2}  #returns [2,4,6,8,10,12]

I'm not sure if c# has something similar though.  Not a lot of languages take advantage of closures.

Edit:  Actually, I think I read your question wrong...
« Last Edit: January 10, 2012, 05:59:31 pm by Levi »
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #356 on: January 10, 2012, 06:01:03 pm »

Edit:  Actually, I think I read your question wrong...

Yeah, what I wound up doing (in C#) is this.

Code: [Select]
playerPosition[0]++;
playerPosition[1]++;

And so forth.  I'm curious if there's a way to condense that into a single line, not that it's really necessary.
Logged
And here is where my beef pops up like a looming awkward boner.
Please amplify your relaxed states.
Quote from: PTTG??
The ancients built these quote pyramids to forever store vast quantities of rage.

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #357 on: January 10, 2012, 06:03:40 pm »

Edit:  Actually, I think I read your question wrong...

Yeah, what I wound up doing (in C#) is this.

Code: [Select]
playerPosition[0]++;
playerPosition[1]++;

And so forth.  I'm curious if there's a way to condense that into a single line, not that it's really necessary.

Hee hee, sort of.  I bet this will work:

Code: [Select]
playerPosition[0]++; playerPosition[1]++;

Some people frown on cramming multiple things on the same line like this, but hell its your code so who cares.   :P
« Last Edit: January 10, 2012, 06:05:18 pm by Levi »
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Willfor

  • Bay Watcher
  • The great magmaman adventurer. I do it for hugs.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #358 on: January 10, 2012, 06:04:36 pm »

Edit:  Actually, I think I read your question wrong...

Yeah, what I wound up doing (in C#) is this.

Code: [Select]
playerPosition[0]++;
playerPosition[1]++;

And so forth.  I'm curious if there's a way to condense that into a single line, not that it's really necessary.

Code: [Select]
playerPosition[0]++; playerPosition[1]++;

BOOM. ... Okay, yeah, that's probably not as fancy as you would like. I usually use System.Drawing.Point for my x/y coordinate positions, and even then I usually end up using two lines, so I'm not sure I can be useful here.

Pre-edit: I've been ninja'd...
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 /

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #359 on: January 10, 2012, 06:10:17 pm »

Yes, I was expecting the obvious formatting joke.  You guys know what I mean.

Anyway, I guess I need to make things besides the player move around.  And first make things besides the player, who isn't actually an object.
Logged
And here is where my beef pops up like a looming awkward boner.
Please amplify your relaxed states.
Quote from: PTTG??
The ancients built these quote pyramids to forever store vast quantities of rage.
Pages: 1 ... 22 23 [24] 25 26 ... 796