Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 216 217 [218] 219 220 ... 796

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

da_nang

  • Bay Watcher
  • Argonian Overlord
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3255 on: October 26, 2012, 10:09:49 am »

O wait, I do have a question. Does anyone know how to extract the row and position in the row(and the other way around) from a pyramid thing like this:
Code: [Select]
    1
  2 3 4
5 6 7 8 9
Where the pyramid has n rows. I am passing around the n and the number of the tile, or should I just scrap that plan and make some weird 2 dimensional array?
Let's see. If we store everything in a 1D array...
If the first element is at index = 0 and the nth row contains 2n+1 elements, then recursively: Let the starting index of the nth row be designated as rn.

Base-case: r0 = 0
Recursion: rn = rn-1 + 2(n-1) + 1 = rn-1 + 2n-1
Or directly, rn = n2

The last index of the nth row: mn = rn + 2n

Now, assuming the elements exist, their positions in an array can thus be described with a function P(i,n), where i is an element's local index in the nth row. The function returns the array index of the element.

Local boundaries: 0 <= i <= 2n

P(i,n) = rn + i, -1 if i is outside local boundaries.

Neighbours:

Let's define i as the local index of the element and n as the nth row index.

If i = 0, then it has no left neighbour. If i = 2n (or last element of array), then it has no right neighbour. Both of these have no upper neighbour either, but they have below.

All others have neighbours above and below.

The function L(i,n) returns array index of the left neighbour.
L(i,n) = P(i-1,n), local: 0 < i <=2n, -1 if outside

The function R(i,n) returns array index of right neighbour.
R(i,n) = P(i+1,n), local: 0 <= i <2n, -1 if outside

The function U(i,n) returns the array index of the upper neighbour.
U(i,n) = P(i-1,n-1), local: 0 < i <2n, n > 0, -1 if outside

The function B(i,n) returns the array index of the lower neighbour.
B(i,n) = P(i+1,n+1), local: 0 <= i <= 2n, -1 if outside

As usual, whenever using these functions, remember to check if the elements actually exists to avoid exceptions.
« Last Edit: October 26, 2012, 10:21:40 am by da_nang »
Logged
"Deliver yesterday, code today, think tomorrow."
Ceterum censeo Unionem Europaeam esse delendam.
Future supplanter of humanity.

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3256 on: October 26, 2012, 01:52:32 pm »

That looks eerily like Pascal's Triangle. Just saying.

dreadmullet

  • Bay Watcher
  • Inadequate Comedian
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3257 on: October 26, 2012, 02:57:55 pm »

I encountered the same problem that cerapa was having a long time ago. We may have had the exact same idea (procedural planet terrain generation using icospheres?). I couldn't figure the algorithm out and ended up hardcoding it as a lookup table or something. I got as far as something like this before I changed the planet generation technique to use cubespheres. (Something like this.)
Logged

MadocComadrin

  • Bay Watcher
  • A mysterious laboratory goblin!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3258 on: October 26, 2012, 03:36:39 pm »

That looks eerily like Pascal's Triangle. Just saying.
It's not though. In a Pascal-esque triangle, row numbers determine how many elements are in that row.
Logged

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3259 on: October 27, 2012, 08:05:37 am »

I'm feeling awfully stupid right now, but...

How the hell do I load a file that isn't an image file with javascript?

I'd really like to use all these wonderful json files, but I have literally no clue how to frickin' load them into my script!
Logged

Forums User Meat Wizard

  • Bay Watcher
  • meet whiz
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3260 on: October 27, 2012, 08:08:49 am »

For JSON you'd use whatever built-in AJAX methods your library of convenience uses. JSON is already a subset of javascript, so there's nothing really flash about it that requires anything third-party.
Logged

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3261 on: October 27, 2012, 08:11:22 am »

Yes, I can find plenty of answers exactly like that on the internet that provide no useful information whatsoever.

When I ask how to load an image file, people jump in and say "var image = new Image(); image.src = 'file_source';" and yay, it works.

But when I ask how to load a json file, it's always "Go figure it out somewhere somehow". >_<
Logged

Forums User Meat Wizard

  • Bay Watcher
  • meet whiz
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3262 on: October 27, 2012, 08:20:29 am »

Well what library are you using? They each have about three different ways to load JSON via AJAX. If you want to roll your own, security features prohibits javascript from accessing local files, so you'd need to serve them via a server and still end up doing the exact same thing anyway.
Logged

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3263 on: October 27, 2012, 08:50:51 am »

Okay, in jQuery, apparently it's "ajax".

So that solves that at least.

Argh. I hate callbacks. I just... argh. I just want to process this goddamn json file. But I have to wait for it to load. But I can't assign the result to a variable and then wait for it to load before using the variable, nooo, that would be too easy. And I can't wait for it to load and then assign the variable, because hell's if I can figure out how, since I can't figure out how to pass anything of actual value ARGH.

All I want.

Is to wait for shit to load.

And then start my bloody game.

Easy as fucking pie for images! Just onload resolve the deferred status and wait to use the images until all deferred status have been resolved!

But anything else seems to be absolute bullshit to get it to work. Just banging my head bloody against the wall right now. Argh.

Edit2:
Apparently you want type 'text', not type 'json' - despite being a json file, it's still a text response.
« Last Edit: October 27, 2012, 06:07:15 pm by GlyphGryph »
Logged

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3264 on: October 27, 2012, 08:02:15 pm »

Sorry for the double post, but actual question this time.

I have

function SomeObject(){
  this.blah = 1;
  this.bloo = myFunc();

  function myFunct(){
    return this.blah+1;
  }
}


This... doesn't seem to work. Javascript scope is hard. :( What do I actually need to do to refer to "blah" in this situation, within the function?
Logged

TSTwizby

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3265 on: October 28, 2012, 01:31:06 am »

I'm starting to get fed up with C++. When it comes to anything involving libraries, or indeed anything other then actually writing code, it seems like there is some kind of invisible insurmountable barrier to understanding that all the C++ coders are on one side of and I am on the other. Even following tutorials (if they exist) exactly, I have been entirely unable to even install and run any compiler other than Visual Studio, and I have been so far unable to find any kind of tutorial on how to use libraries with Visual Studio. The first part of the tutorial Microsoft has at http://msdn.microsoft.com/en-us/library/ms235627.aspx when I copy/paste their text and name my files exactly the same as theirs results in a fatal error LNK1107, which seems to have to do with it not identifying the header as a header. I have been able to find no explanation of the error and my attempts to find other tutorials are thwarted when they involve changing properties, mainly involving the linker, which do not exist in VS for some reason.

To be more specific, I'm entirely self taught, and have been using C++ to do some combinatorial analysis for a while now. I've also programmed games using Flash. I now want to make the jump to programming games in C++. But to make graphics with C++ seems to involve ludicrous amounts of impenetrable windows-specific impossible-to-find-a-tutorial-about-using nonsense-code, or using a library of some kind, with the most recommended seeming to be SDL. I've pretty much given up on actually using it though, as even Microsoft's own tutorial for using .dll's requires nonexistant menu options and the SDL website has no useful information itself, and the only basic tutorial I've been able to find (http://www.sdltutorials.com/sdl-tutorial-basics) is meant for mingw32, which is among the programs I have been inexplicably unable to install and has sufficiently different ways of referencing files from VS that I am incapable of finding an equivalent method of linking things, specifically lacking any kind of list of linked libraries or way of ordering them, as far as I can tell.

Is this a lost cause? If not, what should I try/where should I look?

Apologies for the rant-like nature of this post. Just please do not ask me to google anything; I already have.
Logged
I got a female and male dragon on my embark. I got cagetraps on the exits but im struggling to find a way to make them path into it.
Live bait.
3 dwarfs out of 7 dead so far

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3266 on: October 28, 2012, 02:36:43 am »

Rastertek: the best damn graphics tutorial website out there: http://www.rastertek.com/tutindex.html
It has OpenGL, but is mostly directX based, and includes source code with in-depth walkthroughs of how it works. It's pretty much everything from how to get up and running to really high-level graphics programming.

As for libraries: How this works depends on which VS you have. You will probably need to include library paths in addition to the libraries and headers themselves. For VS2010, this is in Project->Properties->VC++ Directories (in the menu on the left side of the project properties), then add the paths to the DirectX SDK folder (which you can get here if you don't already have it) for both the Include Directory and Library directory. The include directory is the one named 'include,' while the libraries are in 'lib\x86' typically (assuming you are compiling for 32 bit, which is the default in VS). After that, the includes should work. For libraries, you can either use #pragma statements, or (and this is usually the better way), go into the Project Properties window again, then Linker->Additional Dependencies (or something like that). Add in the libraries there.  Edit: tutorial 1 for the directx10 tutorials on Rastertek has better descriptions

How linking stuff works in VS changed dramatically between versions; if you don't use VS2010, look for instructions specific for that version. That link you found is for VS2012, which I have yet to delve into, and has really big changes in it.

In general: learning graphics programming is EXTREMELY frustrating, as things will fail, and usually in such a way as to give you no idea as to what is failing. Your level of Google-fu and debugging will increase by orders of magnitude in the process through sheer necessity. Just keep at it, put on some good music*, and eventually you will figure it out. Come back here if you get really stuck on something.

*Yes, this is essential for keeping your monitor fist-free.
« Last Edit: October 28, 2012, 02:45:30 am by alway »
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3267 on: October 28, 2012, 03:03:42 am »

Some things I would recommend:

Unless you have a large project that has a lot of library dependencies, don't bother trying to compile/run within an IDE. Write your code in a simple text editor or an IDE, but compile on command line. And, in regards to compiling on command line, use Cygwin. I've toted it here many times before, but I'll do it again. It's a UNIX/Linux-like environment running in Windows, completely with a directory structure that follows the typical structure of a UNIX/Linux filesystem. It comes default with all of the Linux coreutils and binutils, and installing other things (like gcc, g++, libSDL, and libSDL-dev) is a snap. You'll have to climb the learning curve of using basic UNIX/Linux commands, but that curve is far smaller and far more useful (in my opinion) than learning where each IDE you will ever use puts their options for external libraries.

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3268 on: October 28, 2012, 07:13:19 am »

Is this a lost cause? If not, what should I try/where should I look?
Just to let you know you're not alone, took me years of banging my head against a wall to get a modicum of skill to fix linker errors. It's... part of the initiation rite or something.
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))

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3269 on: October 28, 2012, 07:26:27 am »

TSTwizby, you're not alone. I though "I" was alone for the same reason, for the longest time, though. Figuring that out was the single hardest part of programming, and why I started favouring flash and interpreted languages. I don't know if the problem is common and well-hidden, or if there's just a subset of the population that has some natural resistance to figuring it out. :P

It's why I still prefer languages like Ruby, that make handling library management and compiling exceptionally easy.

But for C++, the easiest time was definitely as mentioned above - dropping the IDE approach completely, and just compiling on the command line. Hell, the biggest benefits were that, unlike with the IDEs, there are places you can go that will actually explain how command line compiling works and how to do it.

I'll admit that this is probably the biggest reason I hate Eclipse, for example. I'd spend more time trying to figure out compiling than any other thing I did with.
Logged
Pages: 1 ... 216 217 [218] 219 220 ... 796