Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 80 81 [82] 83 84 ... 796

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

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1215 on: February 03, 2012, 07:05:52 am »

Ok, so I have uploaded a sample game. It shows pretty well how to handle game states, so that there isn't any of this mess that Magma seems to think I would end up with, and it draws pretty well, solving the problems of when to flush and such.
Also, heads up, making this totally open source and free to download and what ever, so you can't get arrested for downloading pirate software.  :P
Link!

Be warned, the keyboad input is annoying. Give me a break, I built it in less than an hour using libtcod.

Ah, now I get it, you're using C#. C# has automatic memory deallocation and different pointer handling syntax. So that's why you can do all that shit and get away with it. I was thinking in C++, and the state manager in C++ looks totally insane, I wrote three different state manager models in C++ and I hated every single one.
Seems we're both correct.
Logged

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1216 on: February 03, 2012, 07:15:28 am »

I still disagree. I have implemented the same pattern in c++ without use of a state manager, and the code was just as neat. In fact the only addition lines were for the deconstructor itself, and it being called.
You just need a good understanding of information expert, so that you never need to have unique interfaces for each type and know where to destroy the object to keep it neat.

And like I said, where do you put the logic for skipping draw frames in yours?

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1217 on: February 03, 2012, 07:45:12 am »

I still disagree. I have implemented the same pattern in c++ without use of a state manager, and the code was just as neat. In fact the only addition lines were for the deconstructor itself, and it being called.
You know what? I'm just going to go ahead and believe you. I'll still use my own model though, because I find it much more elegant, easy to use, easy to read and easy to bugfix, and I don't need to dynamically allocate states at all.

And in mine, when I want to upgrade my loop to skip draw frames when you hit low FPS I can do it once in my game class, where would you implement it?
I'd put it in my GState class, like so:
Replace this:
Code: [Select]
GOnRender();
with this:
Code: [Select]
if (someKindOfFPSCheck()) GOnRender();
Done.
Logged

Errol

  • Bay Watcher
  • Heaven or Hell, Duel 1 -- Let's Rock!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1218 on: February 03, 2012, 07:46:26 am »

Java is kind of the only thing in the world that makes me rage.

Spoiler (click to show/hide)

This is supposed to be code for the GUI. (The error-throwing line is commented out.) The thing is that evidently something is wrong with the pathname or stupid shit like that because if I put it out of the try block, he cries undeclared IO exception. The thing is, isn't that code supposed to provide what kind of exception it is exactly so that I know what I have been doing wrong? Well my Java didn't get the news. Probably I forgot the simple System.out.println, but damn me if I'm going to touch the editor again next few hours.

Despite the angriness, I need help here, I apologize for being rude. I know the example I was given did it with ImageFrame, but tbh that isn't practical as far as I understood it. Again, 300 ImageFrames to kitbash a tile system seems really unelegant and I dislike these sorts of solutions.
Logged
Girls are currently preparing signature, please wait warmly until it is ready.

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1219 on: February 03, 2012, 07:56:11 am »

Whoa, let's firstly take a step back and make sure that your Buffered Image can and is only loaded once, and once for sure. And maybe fix up some of those lines.

Code: [Select]
public class Screenfiller extends Canvas {
 
private BufferedImage bi;

public Screenfiller() {
try {
        bi = ImageIO.read(new File("./img/tileclose.png"));
      }
catch (IOException e) {
        e.printStackTrace();
      }
}
 
    public void drawMap(Graphics g) {
      for (int x = 1; x <= mapx; x++) {
        for (int y = 1; y <= mapy; y++) {
          //g.drawImage(bi, (x-1)*tilesize, (y-1)*tilesize, null);
        }
      }
    }
   
    public void paint(Graphics g) {
      drawMap(g);
    }
  }

Try that for me. If it is still throwing errors at you, it is most likely a file name thing. Try using a full file path, instead of a relative one to be sure.

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1220 on: February 03, 2012, 08:21:35 am »

Edit: In other news, getting well acquainted with old python again. As far as I can recall nobody else here is fluent in it

Hi.

Errol

  • Bay Watcher
  • Heaven or Hell, Duel 1 -- Let's Rock!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1221 on: February 03, 2012, 08:36:17 am »

Whoa, let's firstly take a step back and make sure that your Buffered Image can and is only loaded once, and once for sure. And maybe fix up some of those lines.

Code: [Select]
public class Screenfiller extends Canvas {
 
private BufferedImage bi;

public Screenfiller() {
try {
        bi = ImageIO.read(new File("./img/tileclose.png"));
      }
catch (IOException e) {
        e.printStackTrace();
      }
}
 
    public void drawMap(Graphics g) {
      for (int x = 1; x <= mapx; x++) {
        for (int y = 1; y <= mapy; y++) {
          //g.drawImage(bi, (x-1)*tilesize, (y-1)*tilesize, null);
        }
      }
    }
   
    public void paint(Graphics g) {
      drawMap(g);
    }
  }

Try that for me. If it is still throwing errors at you, it is most likely a file name thing. Try using a full file path, instead of a relative one to be sure.

Neither worked. Even using an absolute file path he continued spitting errors at me.
Logged
Girls are currently preparing signature, please wait warmly until it is ready.

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #1222 on: February 03, 2012, 10:28:48 am »

When I got home I did look at my code, and yep I actually put the buffered image into a label in a JOptionPane. I'll go ahead and post it here anyway since it looks like you are still having trouble.
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1223 on: February 03, 2012, 11:20:22 am »

Whoa, let's firstly take a step back and make sure that your Buffered Image can and is only loaded once, and once for sure. And maybe fix up some of those lines.

Code: [Select]
public class Screenfiller extends Canvas {
 
private BufferedImage bi;

public Screenfiller() {
try {
        bi = ImageIO.read(new File("./img/tileclose.png"));
      }
catch (IOException e) {
        e.printStackTrace();
      }
}
 
    public void drawMap(Graphics g) {
      for (int x = 1; x <= mapx; x++) {
        for (int y = 1; y <= mapy; y++) {
          //g.drawImage(bi, (x-1)*tilesize, (y-1)*tilesize, null);
        }
      }
    }
   
    public void paint(Graphics g) {
      drawMap(g);
    }
  }

Try that for me. If it is still throwing errors at you, it is most likely a file name thing. Try using a full file path, instead of a relative one to be sure.

Neither worked. Even using an absolute file path he continued spitting errors at me.

If you're getting an IOException, the ImageIO.read() method is throwing it.  I don't have time to look closely nor test this for the next couple of hours.
Code: [Select]
public class Screenfiller extends Canvas {

private BufferedImage bi;
private final String filename = "./img/tileclose.png";

final int mapx = 10;
final int mapy = 10;

public Screenfiller() {
}

public void drawMap(Graphics g) {

try {
bi = ImageIO.read(new File(filename));
} catch (IOException e) {
e.printStackTrace();
}
for (int x = 1; x <= mapx; x++) {
for (int y = 1; y <= mapy; y++) {
// g.drawImage(bi, (x-1)*tilesize, (y-1)*tilesize, null);
}
}
}

public void paint(Graphics g) {
drawMap(g);
}
}

I promise I'll look at your code this afternoon.
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1224 on: February 03, 2012, 01:39:49 pm »

Useful links: TCOD character set + numbers
And an SDL tutorial that I liked. Their event handling for instance, I liked that implementation. Note: the tut is from 2007, I'd reckon SDL has been updated somewhat since then, keep that in mind.
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))

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #1225 on: February 03, 2012, 01:45:30 pm »

And an SDL tutorial that I liked.
I can vouch for that tutorial site too, though I don't agree with the way the engine in the later tutorials is built. I'd just recommend it for the basics.
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #1226 on: February 03, 2012, 02:22:18 pm »

Java image display: My image display code won't really help you as I go through a whole process to convert my images to an array of shorts for transport and back and use a label and ImageIcon.

But do you know what the type of exception being thrown is? Might help a bit.
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

Errol

  • Bay Watcher
  • Heaven or Hell, Duel 1 -- Let's Rock!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1227 on: February 03, 2012, 02:39:22 pm »

That's the thing, there appears to be nothing in the exception logs when I leave the try-catch-block in, but an undefined IO exception when there is no try-catch.
I hope that after getting this I/O bullcrap right there will be less problems with the remainder of the project. And if all else fails, I'll swallow my pride and create 300 JLabels for the whole grid. I just hope I can automate the creation of these babies...
Logged
Girls are currently preparing signature, please wait warmly until it is ready.

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1228 on: February 03, 2012, 03:53:55 pm »

As it's written now, your code is only capable of throwing four exceptions:
     File can throw NullPointerException.
     ImageIO can throw IOException and IllegalArguementException.
     Break things badly enough and the JVM can throw a RuntimeException.

Unless you start overriding things, you can't get anything more specific than IOException.  So lets override it.  Catch the IOException and System.err.println(e.getClass()).  It should tell you which specific subclass of IOException it is.  Unless it's just an IOException, in which case, I'll have to come up with another idea.

EDIT:
Okay, technically this isn't overriding anything.  We're just handling the exception.  The important thing is that this should hopefully tell us which specific type of error we're getting.
« Last Edit: February 03, 2012, 03:58:16 pm by Stargrasper »
Logged

Darvi

  • Bay Watcher
  • <Cript> Darvi is my wifi.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1229 on: February 03, 2012, 05:00:16 pm »

So I'm trying that SDL tutorial (even though fuck tutorials because I learn nothing from them (that includes those in this very thread)) with Vistual C++, but cannot build due to the LNK2019 error. Fucking linker. Whatever a linker is.
Logged
Pages: 1 ... 80 81 [82] 83 84 ... 796