Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Lord Windy
Mar 26, 2010
Hey guys, ages ago I tried making a really involved game but due to my lack of experience/knowledge I could never work out how to manage memory correctly (trying to track millions of integers and strings, it turns out that quickly turns into gigs of ram when you don't save it to the hard disk and load when needed :P). At the time I just abandoned it because the only way I knew how to store data was in text files.

I decided to give another crack at it after I've worked on some simpler crap and I've realised I could just use a database like any business would. I found JDBC and it looks ideal, but I'm a little confused by how it works.

If I use MySQL or Java DB, will it just work normally when I distribute the JAR to windows/linux/mac computers or will I need to include something? And is one better than the other, or are they both the same. I hope this isn't too dumb of a question, I'm still pretty new when it comes to Java/Programming in general.

Adbot
ADBOT LOVES YOU

Lord Windy
Mar 26, 2010

Zaphod42 posted:

Are you really sure that the game absolutely requires installing a database on client machines? That's probably going to have some drawbacks, although I guess I'm not sure of how minor you can make a DB install. Still, seems like overkill. Could you do it server side? Why millions of integers and strings?

I mean if Skyrim or Dwarf Fortress gets by without a database I don't know why you'd have to have one, unless you're making a simulation.

That said, yeah, JDBC should just talk to MySQL (though you'll have to use the mysql configuration stuff) but you'll have to have MySQL running as a service and everything on the target machine.

I did not realize that I had to install a database if I wanted to use it. A game I like, Aurora, was programmed in VB.net and uses an Access database for everything so I figured it would be easy just to do something similar with Java. I just assumed MySQL or Java DB would be a single database file that you could use JDBC to interface with.

There would likely be no issue with me just using text files ala Dwarf Fortress. It was just an idea I had last night that seemed very elegant that anyone could edit if they liked.

Lord Windy
Mar 26, 2010
H2 might be the way to go if I want to keep going down the path of a database. It looks like you can embed the database into the application itself through a 1.5mb jar file so the end user doesn't need to install anything.

But I did some reading up on Java and file loading, and an 8kb BufferedInputStream is surprisingly fast. 500ms to read a 100mb file. So I might write down what I want to do and make up a pro/con list.

Lord Windy
Mar 26, 2010
I'm not reinventing the wheel with XML, sorry.

Lord Windy
Mar 26, 2010
In Intellij, is there a way to put a 'build artifact' button up around where the run button is? I'm making a project and due to how I'm making my folder structure it is just going to be easier to run a Jar than faff about changing strings.

Lord Windy
Mar 26, 2010
I've just spent the past 4 hours trying to work out why something wasn't working properly in Java and holy poo poo is it aggravating when you did everything right but the png you had was corrupted.

I was using javafx.scene.canvas.GraphicsContext and I couldn't work out why the DrawImage function was cropping pixels out of a spritesheet when it could show the whole spritesheet without any issue. I did practically everything I could think of to make it work, but it wasn't until I tried to open the PNG in a pixel editor to make sure I had the dimensions right did I see the thing was corrupted as all hell. It was really strange, before I opened it in the editor it looked fine on the JavaFX canvas, but once I did it stopped loading correctly.:tinfoil:

I downloaded a new copy of the PNG and everything worked perfectly. Programming can suck sometimes.

Lord Windy
Mar 26, 2010
I was reading up on Java 9 and I was wondering what Modular Source Code means? I don't really understand this new feature that I should be getting excited with, but I guess like with Lambdas I probably will once I know what it is.

Lord Windy
Mar 26, 2010
I've got a hypothetical that I don't know how to test but do want an answer for.

If there is an object method that has a synchronization lock on it, and there are threads in queue with different priority levels (say first in line is a priority level 5, second in line is priority 3 and third is priority 10) how does Java work out who goes first? If it a first in first out or will it let the highest priority thread in front?

I ideally want the top priority thread to get in first as I don't want to let it wait if the queue is long. But information I find can't tell me one way or the other.

Lord Windy
Mar 26, 2010

Jabor posted:

The answer is neither. If multiple threads are waiting on the same concurrency object, it's unspecified which thread will acquire it when it becomes available. You can also make a particular concurrency object "fair", which makes it a strict FIFO order, at the cost of some throughput.

Well, maybe I can ask the thread for a 'best practice'. I've got two methods, one is use by threads as a callback function in regards to sockets. A second method is a polling method by the main thread that collects all the data that the other threads are depositing at set intervals (every 100ms).

code:
    public void recieveInformation(Sentence toAdd){
        synchronized (lock1){
            RawInputs.add(toAdd);
        }
    }

    private void gatherInformation(){
        synchronized (lock1){
            Inputs = RawInputs;
            RawInputs = new ArrayList<Sentence>();
        }
    }
To me this makes perfect sense, the main thread is priority 10 and everything else is 5. Main thread just waltzes into the front of the queue. But if this is the wrong way let me know and I'll fix it. I'm not experiencing any deadlock yet, but at the same time I am not really testing it.

Lord Windy
Mar 26, 2010

Jabor posted:

Is it important that the main thread gets the lock immediately when it asks instead of waiting for a couple of other threads to take their turn first? If so, why?

I'm probably pre-optimising to be honest. I'm working on some examples from a MUD programming book and I'm anxious that I don't gently caress the sockets up because I'm not doing it's version of sockets (it was written back in 2003 and is a little out of date).

Adbot
ADBOT LOVES YOU

Lord Windy
Mar 26, 2010
For Uni, I need to learn Swing. I don't do much GUI work at the best of times, and I've been using FX when I have.

Does anyone have like a small tutorial other than the Oracle one? I'm basically looking for something that shows you how to make a couple of projects ranging from lambda function listeners to something a little more advance. The lectures on it are a bit of a mess.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply