Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 11 12 [13] 14 15 ... 91

Author Topic: Programming Help Thread (For Dummies)  (Read 100554 times)

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #180 on: June 03, 2011, 10:42:51 pm »

qwertyuiopas, you are mighty god king. That solves another problem I knew I was going to run into.I'll take the liberty of adding your exact post and pictures to my docs. I only hope that one day, somebody will come here for help and I will be as useful. But just to make sure, I will try and make a neat game, then distribute freely and open source, as is fair.  :)

Angle

  • Bay Watcher
  • 39 Indigo Spear Questions the Poor
    • View Profile
    • Agora Forum Demo!
Re: Programming Help Thread (For Dummies)
« Reply #181 on: June 04, 2011, 12:37:16 pm »

Holy shit, max, I was tackling that exact problem, IN JAVA, just a few months ago. I never really got very far with the rest of the roguelike, but I did get most of the way through that problem. I'm kinda new at programming, so I don't know how good my code is, but I'll post it here anyway.

Spoiler (click to show/hide)

I had solved this problem by using LocalAreas, each of which would store the tile data for like a room or another small area, and each of which would also keep track of what other LocalAreas was next to it. I had also been planning to have stairs or such, or to have all sorts of freaky geometry, hence the rotation, mirror, and elevation values in the BorderArea subclass. I never did figure out how to get enmy pathfinding, or line of sight, or any of that working, though.
« Last Edit: June 04, 2011, 12:44:51 pm by Angle »
Logged

Agora: open-source platform to facilitate complicated discussions between large numbers of people. Now with test site!

The Temple of the Elements: Quirky Dungeon Crawler

Normandy

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #182 on: June 05, 2011, 12:05:25 pm »

@ILikePie
Additive Synthesis is based off of the Fourier Series (http://en.wikipedia.org/wiki/Fourier_series). I would suggest you read up on it if you want to understand precisely what is happening with additive synthesis. If you have at least a conceptual understanding of things like convergence with the Fourier Series (Calculus II required!), then you should be able to recognize and deal with most of the issues that crop up with additive synthesis.
Logged

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #183 on: June 05, 2011, 03:34:27 pm »

I've read about Fourier series a while back, but I heard I can get similar effects by adding overtones with a smaller amplitude. Thus "y = A/o * sin(2*pi*f*o*x)", "o" being the harmonic number or whatever it's called.
Logged

Normandy

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #184 on: June 05, 2011, 03:54:57 pm »

A Fourier Series is a sum of overtones with a smaller amplitude. As you add more and more overtones, so long as the frequency of the overtones match up with the frequency of the original wave, you get closer and closer to the original wave. Additive synthesis is using the coefficients (a.k.a. harmonics, i.e. the amplitude of the overtones) from a Fourier Transform (i.e. turning the wave into a Fourier Series) to reconstruct the original wave.
Logged

ext0l

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #185 on: June 05, 2011, 05:55:53 pm »

Can anybody help me install the libjcsi library?
http://slashie.net/libjcsi/

So far, I've gone to their google code page and did this command
Code: [Select]
svn checkout http://libjcsi.googlecode.com/svn/trunk/ libjcsi-read-only
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #186 on: June 05, 2011, 06:16:55 pm »

OK that means you have the library downloaded. To be sure, check the folder where you did the checkout and see if it contains some .cls files (java uses them for libraries right? Man my memory is fuzzy on this. Edit: it's a .jar file that itself needs a .dll or .so that is also included in the download. Don't forget the later when copying stuff or you'll rip you hair out). Next thing you got to do is link it with your project, but this is likely IDE/linker-specific (the general idea is usualy the same, but some details could differ), so you'd better look up the documentation for what you're using. If you're using Maven, I think you need to copy the libraries to a lib folder in your main working directory (though Leinigen, which is build on top of Maven can follow hard links, so maybe Maven can too?) and then include the library using the include foo command.
« Last Edit: June 05, 2011, 06:24:34 pm by Virex »
Logged

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #187 on: June 17, 2011, 03:37:32 am »

Don't need help myself, but I did find something interesting which may prove useful for others when using dynamic arrays in C++. As most people using C++ know, arrays are essentially constant pointers for which the program does not keep track of size. However, dynamic arrays do track their size. What's more, the size can be accessed most of the time. I wouldn't even consider using it for an actual program, and neither should anyone else, since from what I gather, where the array size is at may vary from one system to another; however, it may be useful for debugging in some cases.

So, how to get the size of the array: int size = *((int*)pArray - 4);

This will then give you the total array size in bytes. And from a bit of testing on my own, I found out that for Visual Studio IDE in debug mode, when the array's memory is deallocated with the delete[] keyword, this memory, is set to 0xfeeefeee (Microsoft's debug code which means the memory has been freed up), just as the rest of the array is, thus confirming it is indeed part of the array, rather than merely cosmic coincidence of some sort. Dunno how common this knowledge is, but as I don't recall seeing it on any of the tutorials I read about arrays, I figured it might be useful.

The purpose of the data itself is, as far as I know, for deallocating the dynamic memory; when "delete[] pArray;" is called, it needs to know how long pArray is in order to free up the memory.

Again: DO NOT use these methods for anything other than debug purposes; I haven't the foggiest idea as to what horrible things may happen if you were to. My guess is Cthulhu would rise to do combat with Dr. Who. Best I can figure, it's metadata put there by the heap.
« Last Edit: June 17, 2011, 03:56:12 am by alway »
Logged

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #188 on: July 03, 2011, 06:02:31 am »

I'm trying to sort an array out with qsort, but all qsort seems to do is set my values to -1.
Spoiler: code (click to show/hide)

This is the output without qsort, I want the values sorted in ascending order:
Spoiler (click to show/hide)

e, Never mind that, qsort was doing exactly what it's supposed to be doing. I'm an idiot.
« Last Edit: July 03, 2011, 06:40:27 am by ILikePie »
Logged

Starver

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #189 on: July 03, 2011, 02:14:55 pm »

I'm trying to sort an array out with qsort, but all qsort seems to do is set my values to -1.
[snip]

Without actually looking at your code[1], I'd say your best bet is that you've got equality comparison ("==") mixed up with assignment ("=") somewhere.  Been there, done that, got the Student's T-Distribution shirt.  And in many different languages in each direction[2].

i.e. Check for a if (var == -1) then... type test where you've accidentally put if (var = -1) then....  Of course, it could be rather more obtuse if it's a vest of var1 against var2, where that is -1, like var2=-1; until (var1=var2) do {something...} or the like.

You might want to put some sort of sprintf("F.Y.I.: Value of var = %d\n",var) debugging thing (or however you prefer to make such debugging outputs) into the code at various points, to narrow down when the actual transition occurs.


[1] Lazy of me, but I'm so confident about the answer that I'm going to give you the happy feeling from actually finding your own error. :)

[2] e.g. sometimes it needed ":=" but I used "=", although that sort of error tends to produce compile errors most of the time, given the nature of that type of language.
Logged

Angle

  • Bay Watcher
  • 39 Indigo Spear Questions the Poor
    • View Profile
    • Agora Forum Demo!
Re: Programming Help Thread (For Dummies)
« Reply #190 on: July 03, 2011, 02:36:22 pm »

Heres a little question I'm having in C++. do vectors store things as values or references? is there a way I can tell them to store be reference? or do I need to make my own class for that?
Logged

Agora: open-source platform to facilitate complicated discussions between large numbers of people. Now with test site!

The Temple of the Elements: Quirky Dungeon Crawler

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #191 on: July 03, 2011, 02:58:18 pm »

Heres a little question I'm having in C++. do vectors store things as values or references? is there a way I can tell them to store be reference? or do I need to make my own class for that?
C++ always uses pass by value (like most other languages and even assembly languages for that matter), but those values may be references in themselves. In the case of a vector you're dealing with that case, so each cell of the vector contains a pointer to an object. If you were to follow the pointer stored (which implicitly happens if you access something in the vector) you'd get the object you initially put into the vector, not a new object, but the pointer itself is stored by value. This means that if you'd have 3 variables holding objects and store those in a vector, then change one of the cells of the vector to another object, the vector will contain references to the 2 original objects and the new one, but the variables will still point to the 3 objects they initially pointed to; the chance in the cell value is not propagated to what you obtained the value from, but said value is but a reference and not the object itself.
« Last Edit: July 03, 2011, 03:06:04 pm by Virex »
Logged

Normandy

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #192 on: July 03, 2011, 03:27:59 pm »

@Angle:
Actually, Virex is mistaken. True, all things in C++ are passed by value (not all mainstream languages do this; Java is purely pass-by-reference with the exception of primitives, C# is about half-and-half (sort of), and most scripting languages do pass-by-reference for objects). While moving objects around in a vector will not cause objects to be created or destroyed, there is definitely different behavior between a vector that is holding objects by value and one that is holding objects by reference.

Code: [Select]
std::vector<MyObject> a // stores MyObject values.
std::vector<MyObject&> b // stores MyObject references.
std::vector<MyObject*> c // stores MyObject pointers.

MyObject obj; // Create a new MyObject

a.push_back(obj); // a now contains a copy of obj; copy constructor is called
b.push_back(obj); // b now contains a reference to obj; no constructor called
c.push_back(&obj); // c now contains a pointer to obj; no constructor called

obj.update(); // b and c will now have the updated version of obj, while a will not.
a.back().update(); // a be updated, but obj, b, and c will not.
b.back().update(); // b, c, and obj will be updated, but a will not.

MyObject val = a.back(); // val is now a copy of the value that was in a, not a direct copy of obj; copy constructor called.
MyObject cpy = b.back(); // cpy is now a copy of obj; copy constructor called.
MyObject& ref = b.back(); // ref is now a reference to obj
MyObject* ptr = c.back(); // ptr is now a pointer to obj
« Last Edit: July 03, 2011, 03:32:16 pm by Normandy »
Logged

Angle

  • Bay Watcher
  • 39 Indigo Spear Questions the Poor
    • View Profile
    • Agora Forum Demo!
Re: Programming Help Thread (For Dummies)
« Reply #193 on: July 03, 2011, 03:49:31 pm »

Ahah! Thank you. That is exactly what I wanted to know.
Logged

Agora: open-source platform to facilitate complicated discussions between large numbers of people. Now with test site!

The Temple of the Elements: Quirky Dungeon Crawler

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #194 on: July 03, 2011, 04:55:53 pm »

Without actually looking at your code[1], I'd say your best bet is that you've got equality comparison ("==") mixed up with assignment ("=") somewhere.  Been there, done that, got the Student's T-Distribution shirt.  And in many different languages in each direction[2].
[snip]
Actually no, I just had a shitload of -1s at the end of my array. qsort was just doing it's job and moved them to the start (and what I did was print the first 14 elements in the array, all of which were -1s).
Logged
Pages: 1 ... 11 12 [13] 14 15 ... 91