Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Poll

What programming topic would you want the next challenge to be about?  (It might be a good opportunity to focus on a subject you're not familiar with or to reinforce knowledge on one that you already know)

Control Flow
- 2 (2.2%)
Arrays, Strings, Pointers, and References
- 8 (9%)
Functions
- 4 (4.5%)
Basic object-oriented programming
- 30 (33.7%)
A bit more advanced OOP (Composition, Operator overloading, Inheritance, Virtual Functions)
- 18 (20.2%)
Templates
- 8 (9%)
Other (Explain)
- 4 (4.5%)
Working with files?  (Streams)
- 15 (16.9%)

Total Members Voted: 89


Pages: 1 ... 45 46 [47] 48 49 ... 78

Author Topic: Programming Challenges & Resources (#bay12prog) Initiative  (Read 95956 times)

eerr

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #690 on: December 22, 2010, 01:44:23 am »

bleh, I'm just removing this, I don't have a good idea what I'm doing.
« Last Edit: December 22, 2010, 01:51:49 am by eerr »
Logged

Shades

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #691 on: December 22, 2010, 03:30:35 am »

I'm working in C++, and some of my cpp files are getting unwieldy.
Is there an way to split up a cpp into multiple parts?
My soul class is getting so long that I have finding functions in it even with a search function. (due to so many search results)

I figured using #include and multiple files would work, but there were issues with scope or something.

Any insight would be appreciated.

It's probably bad that your code doesn't break down into more files naturally but you can do this fairly easily with #include.
Scope is maintained in included files so either include in namespace and don't have each file worry about it or include outside namespace and make sure each file knows where it's functions should live.

Also remember that most IDEs by default will try to compile every file added to a project and you don't want your separate files to compile, only the one that includes the others. If you forget this you'll likely get errors telling you functions have already been declared or that there are undeclared functions that section of code is using.
Logged
Its like playing god with sentient legos. - They Got Leader
[Dwarf Fortress] plays like a dizzyingly complex hybrid of Dungeon Keeper and The Sims, if all your little people were manic-depressive alcoholics. - tv tropes
You don't use science to show that you're right, you use science to become right. - xkcd

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #692 on: December 22, 2010, 05:32:32 am »

How do you have it set up?

Please tell me your secret, that would really help my productivity.
"Secret" ;)
Pseudoish cpp:
Code: [Select]
Engine.h

class Engine {
 //ALL declaration stuff goes here
};
------------------
Engine.cpp

#include "Engine.h"

void Engine::Engine() {
  doInit();
}
void Engine::~Engine() {}

------------------
Engine_Init.cpp

#include "Engine.h"

void Engine::doInit() {
  //init stuff
}

------------------
Engine_Event.cpp

#include "Engine.h"

void Engine::pressedButton(button){
  // do stuff based on gamestate
}


And then include all of it in C::B (which I believe you use as well?). You just use one header for multiple code files, and since it's all in a class, and they all share the same declarations, they can call each other as well. Just don't press F11 or it will try to create "Engine_Init.h".

I got the idea from here: http://www.sdltutorials.com/sdl-tutorial-basics/, but have since moved from SDL to SFML.
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))

Supermikhail

  • Bay Watcher
  • The Dwarf Of Steel
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #693 on: December 22, 2010, 05:49:34 am »

Fuck yeah! The easy part is over, baby.

For anybody interested, the part I screwed over was not file reading. I had a problem with input yesterday in Java, too, and almost resolved that it's a family curse. Then I had to get up in the middle of the night to correct my code. Java, being helpful platform that it is, had hinted it for me earlier with "ExceptionNullPointer and had given me the number of the line. And the line has no Strings. The line has a member of an array of objects. A static array, which I had initialized with new array. I quite stupidly supposed that it would initialize all the members of the array, which it didn't, and in C++ it was the case, too, I guess.

A lesson for me for going the easy part and avoiding linked lists.

Now it would be nice to make it read the file in the application's directory. Anybody know what makes the shell file in the Linux version of DF tick? I've tried copying it for my application (applying then "chmod +x"), but it didn't work.
Logged

Shades

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #694 on: December 22, 2010, 06:17:41 am »

Now it would be nice to make it read the file in the application's directory. Anybody know what makes the shell file in the Linux version of DF tick? I've tried copying it for my application (applying then "chmod +x"), but it didn't work.

For scripts the first line shows what should be used to execute it. In the case of the Linux DF the 'df' script is a shell script and starts with

Code: [Select]
#!/bin/sh
This tells it to execute with whatever shell is symlinked at /bin/sh.
For binary executables the +x should be enough.
Logged
Its like playing god with sentient legos. - They Got Leader
[Dwarf Fortress] plays like a dizzyingly complex hybrid of Dungeon Keeper and The Sims, if all your little people were manic-depressive alcoholics. - tv tropes
You don't use science to show that you're right, you use science to become right. - xkcd

Supermikhail

  • Bay Watcher
  • The Dwarf Of Steel
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #695 on: December 22, 2010, 06:42:51 am »

Oh. Then for a java file... er, I should probably... Hm, nevermind, I deleted that file and don't know how I was trying to do it. But I assume that if I'm trying to launch the program in terminal, I should write #!/bin/bash and then it's something weird, can I write just cd "$dirname"? And then maybe "java -jar filename"?
Logged

Shades

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #696 on: December 22, 2010, 07:14:21 am »

Oh. Then for a java file... er, I should probably... Hm, nevermind, I deleted that file and don't know how I was trying to do it. But I assume that if I'm trying to launch the program in terminal, I should write #!/bin/bash and then it's something weird, can I write just cd "$dirname"? And then maybe "java -jar filename"?

java -jar filename should work. If you want to put it in a bash script then yes you'd want the #!/bin/bash and whatever commands you need to run the file.
That said I'm fairly sure most linux's can associate executable .jar files with java internally although I forget how (and it might be only in the GUI)
Logged
Its like playing god with sentient legos. - They Got Leader
[Dwarf Fortress] plays like a dizzyingly complex hybrid of Dungeon Keeper and The Sims, if all your little people were manic-depressive alcoholics. - tv tropes
You don't use science to show that you're right, you use science to become right. - xkcd

Supermikhail

  • Bay Watcher
  • The Dwarf Of Steel
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #697 on: December 22, 2010, 07:42:48 am »

Oh god. Oh yes. I was just going to complain here that it didn't work, turns out I made a typo in the variable for the dirname. ::)
So I did it like this:
Code: [Select]
#!/bin/bash
ES_DIR=$(dirname "$0")
cd "${ES_DIR}"
java -jar ElementSetup.jar
It didn't seem to like it when I tried to cd just dirname. Anybody know what's "$0" for?

Edit: well, that's fancy. It runs correctly only with sudo.
« Last Edit: December 22, 2010, 08:17:53 am by Supermikhail »
Logged

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #698 on: December 22, 2010, 09:03:06 am »

Did you chmod it with sudo? Don't, giving scripts root access is never good. Run `sudo chown <youruser> <file>`.

e, $0 is like argv[0].
Code: [Select]
ron@Tux ~ $ cat zero.sh
echo $0
ron@Tux ~ $ bash zero.sh
zero.sh
« Last Edit: December 22, 2010, 09:07:16 am by ILikePie »
Logged

Shades

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #699 on: December 22, 2010, 09:48:56 am »

Did you chmod it with sudo? Don't, giving scripts root access is never good. Run `sudo chown <youruser> <file>`.

Chmoding +x as root won't matter, just don't use the run as owner option :) (which I think is +s). All +x does is mark owner, group and all execute flags but they still run it at them not the chmodder.
Logged
Its like playing god with sentient legos. - They Got Leader
[Dwarf Fortress] plays like a dizzyingly complex hybrid of Dungeon Keeper and The Sims, if all your little people were manic-depressive alcoholics. - tv tropes
You don't use science to show that you're right, you use science to become right. - xkcd

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #700 on: December 22, 2010, 10:07:42 am »

`sudo chmod +x file.sh` means the root user can run file.sh. iirc, chmod 777 will give everyone read write and execute permissions.
e, Nothing to see here folks, move along. :P
« Last Edit: December 22, 2010, 10:11:23 am by ILikePie »
Logged

Supermikhail

  • Bay Watcher
  • The Dwarf Of Steel
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #701 on: December 22, 2010, 10:16:52 am »

Did you chmod it with sudo? Don't, giving scripts root access is never good. Run `sudo chown <youruser> <file>`.

e, $0 is like argv[0].
Code: [Select]
ron@Tux ~ $ cat zero.sh
echo $0
ron@Tux ~ $ bash zero.sh
zero.sh
Oh, god. I've been running it like crazy, sudo and without, fortunately, most times it wouldn't run, and theoretically it shouldn't have tried to access too many files, as in the code there's only one. Mental note: after Googling tips on helpful Internet sites, always try to check man pages for the said tips.
Chmoding +x as root won't matter, just don't use the run as owner option :) (which I think is +s). All +x does is mark owner, group and all execute flags but they still run it at them not the chmodder.
So I cmodded +x it as root, then tried to run it while not being root, and it wouldn't run... Wait wait. I actually can chmod it without +x, because I'm morbidly interested to be able to run it on any Linux computer, not just mine?
Maybe +0777x ? Although that looks like a phone number, not an argument.

Edit: Arght, I was just too slow.

Edit: edit: I'm again figuring out if int is too expensive and have just looked at the reference for short... MAX_VALUE 215-1... Yeah, I'm never using int *sigh*
« Last Edit: December 22, 2010, 10:42:15 am by Supermikhail »
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #702 on: December 22, 2010, 02:59:35 pm »

Anyone know of a reasonably good but mostly fast pseudorandom algorithm that "reseeds" instantly?
I'm not looking for Seed->get->get->get, but for a Seed->get, Seed->get, Seed->get kind of thing.

My current one yields... boring results. The textures are fine but my landscape is just sleep-inducing.
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))

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #703 on: December 22, 2010, 03:58:24 pm »

Edit: edit: I'm again figuring out if int is too expensive and have just looked at the reference for short... MAX_VALUE 215-1... Yeah, I'm never using int *sigh*
May I ask what you're doing that would benefit noticeably from using shorts over ints (and for that matter, why not use chars in such a case?)
Logged

Supermikhail

  • Bay Watcher
  • The Dwarf Of Steel
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #704 on: December 22, 2010, 04:06:59 pm »

My OCD, man! You think I'd do anything without a serious reason? ;D
On the note of OCD, can anybody explain to me or point me in the direction of a good tutorial for the use of graphics in a Java application? Specifically what where do I create, and won't it fall out of scope as soon as I've left a specific event? I've got an empty JFrame here with nothing in it, with a million of classes waiting to be rendered into it, and my appetite whetted by various applets in graphics tutorials that I don't understand and even GameBuilder for Java Mobile (which is crazy and mocking me).
Logged
Pages: 1 ... 45 46 [47] 48 49 ... 78