Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 162 163 [164] 165 166 ... 796

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

Blargityblarg

  • Bay Watcher
  • rolypolyrolypolyrolypoly
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2445 on: May 20, 2012, 04:36:24 am »

It's a Basics of Java class; I have to use arrays; the tutors have even acknowledged that in a practical setting we would be at least using dynamic arrays, but arrays are a requirement and nobody else seems to be having trouble.
Logged
Blossom of orange
Shit, nothing rhymes with orange
Wait, haikus don't rhyme

kaijyuu

  • Bay Watcher
  • Hrm...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2446 on: May 20, 2012, 04:41:04 am »

Oh, Java. Somehow missed that and thought you were using c++. Dur.


From my (very small) understanding of Java, that should actually work fine. Hrm. I guess you could try making the function call pass the a reference instead a copy; if the syntax is the same as c++, just add a & in front of City.

public boolean addCityToCountry(City& newCity, int countryIndex){


If that doesn't work you'll need an actual java 'xpert, heh.
Logged
Quote from: Chesterton
For, in order that men should resist injustice, something more is necessary than that they should think injustice unpleasant. They must think injustice absurd; above all, they must think it startling. They must retain the violence of a virgin astonishment. When the pessimist looks at any infamy, it is to him, after all, only a repetition of the infamy of existence. But the optimist sees injustice as something discordant and unexpected, and it stings him into action.

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2447 on: May 20, 2012, 04:42:37 am »

Java passes everything by reference by default; no need for that sort of syntax.

I don't recall too much about how Java works, but copying issues like this just means something broke in your implementation of copying the object; either a reference to an out of scope object (can't remember if that happens in Java or not), or an implementation which mistakenly only goes partway through doing a deep copy.
« Last Edit: May 20, 2012, 04:51:13 am by alway »
Logged

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #2448 on: May 20, 2012, 11:27:28 am »

Java passes everything by reference by default; no need for that sort of syntax.

I don't recall too much about how Java works, but copying issues like this just means something broke in your implementation of copying the object; either a reference to an out of scope object (can't remember if that happens in Java or not), or an implementation which mistakenly only goes partway through doing a deep copy.

This is a common misconception. In actuality, nothing is passed by reference in java.

Primitives are passed by value. Objects as you think of them are not really objects, but references to objects on the heap and that reference is passed by value.
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.

Vector

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2449 on: May 20, 2012, 04:34:35 pm »

Thanks guys, by the way.  I got an A in my compsci course :3
Logged
"The question of the usefulness of poetry arises only in periods of its decline, while in periods of its flowering, no one doubts its total uselessness." - Boris Pasternak

nonbinary/genderfluid/genderqueer renegade mathematician and mafia subforum limpet. please avoid quoting me.

pronouns: prefer neutral ones, others are fine. height: 5'3".

Truean

  • Bay Watcher
  • Ok.... [sigh] It froze over....
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2450 on: May 20, 2012, 04:44:16 pm »

Thanks guys, by the way.  I got an A in my compsci course :3

Yay
Logged
The kinda human wreckage that you love

Current Spare Time Fiction Project: (C) 2010 http://www.bay12forums.com/smf/index.php?topic=63660.0
Disclaimer: I never take cases online for ethical reasons. If you require an attorney; you need to find one licensed to practice in your jurisdiction. Never take anything online as legal advice, because each case is different and one size does not fit all. Wants nothing at all to do with law.

Please don't quote me.

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #2451 on: May 22, 2012, 05:08:45 am »

Hmm, interesting. Mostly playing around with some odd threading stuff here. I made a system where you have n threads (where n is the hardware concurrency), and the first available thread grabs any tasks that are pushed onto a concurrent fifo task queue and executes them.

Now, originally I had it written so one of those tasks was the final render pass, which does the drawing to an sfml window and the window.display(). The window inputs always happened on the main thread (which was separated from this task system by making it just wait for tasks and then run those tasks, letting other threads "jump into" the main thread for a bit, kinda inefficient but as a stopgap solution it worked).

This worked fine when I was running it with my integrated graphics card (NVIDIA Optimus technology defaulted to this for the unrecognised executable), regardless of how many threads I was using. However,when n was >= 5 (meaning 6 or more threads were in use, one main thread and 5 task threads) it'd render a few frames and then crash.

Modifying the code so both final render and input polling occurred on the main seemed to fix this problem so I'm putting it down under "nvidia opengl multithreading weirdness" and "you dolt, graphics cards are not meant to run on potentially different threads in the same program every render" and moving on.
Logged

GalenEvil

  • Bay Watcher
    • View Profile
    • Mac-Man Games
Re: if self.isCoder(): post() #Programming Thread
« Reply #2452 on: May 22, 2012, 08:57:16 pm »

I've been meaning to start playing around with threading beyond the single required thread. Considering the amount of debugging stuff I do in my programs it might make sense for me to just push the debugger over into another concurrent thread and wait there for the main thread to pass in stuff that needs reporting. Might make my program run a little faster, and would probably (/might) make things easier on me in the long run. Though, I guess I'd have to figure out how to push things from thread to thread then, which might be a problem if several things try to get the debugger's attention at nearly the same time. Will have to read up on how to thread properly so that i don't end up having a broken program, but that's part of the fun :D
Logged
Fun is Fun......Done is Done... or is that Done is !!FUN!!?
Quote from: Mr Frog
Digging's a lot like surgery, see -- you grab the sharp thing and then drive the sharp end of the sharp thing in as hard as you can and then stuff goes flying and then stuff falls out and then there's a big hole and you're done. I kinda wish there was more screaming, but rocks don't hurt so I guess it can't be helped.

SolarShado

  • Bay Watcher
  • Psi-Blade => Your Back
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2453 on: May 22, 2012, 10:18:24 pm »

I've been meaning to start playing around with threading beyond the single required thread. Considering the amount of debugging stuff I do in my programs it might make sense for me to just push the debugger over into another concurrent thread and wait there for the main thread to pass in stuff that needs reporting. Might make my program run a little faster, and would probably (/might) make things easier on me in the long run. Though, I guess I'd have to figure out how to push things from thread to thread then, which might be a problem if several things try to get the debugger's attention at nearly the same time. Will have to read up on how to thread properly so that i don't end up having a broken program, but that's part of the fun :D

Depending on what language you're using, it may be fairly easy to set up a message queue: other threads pus messages in, debugger pulls them out as it's ready for them.

Only language I've really done any threading in is Java, and the java.util.concurrent package has quite a few useful classes.
Logged
Avid (rabid?) Linux user. Preferred flavor: Arch

GalenEvil

  • Bay Watcher
    • View Profile
    • Mac-Man Games
Re: if self.isCoder(): post() #Programming Thread
« Reply #2454 on: May 22, 2012, 11:40:12 pm »

yeah I was thinking of implementing it first via Java and then making a port of that into C/C++ and C# for my projects stemming from those languages.

EDIT!!!

On a random tangent I decided to make a base 10 to base 26 converter :) Takes in a decimal value up to int32's max value and outputs a string of letters A-Z that corresponds to the input value :D It should also work with an unsigned integer also, but will need to play with it. Actually, should probably require that it is an unsigned integer since it is probably going to be used in item ID generation stuff for a project. Might expand it later into a base X to base Y converter, taking in X,Y, a String of base X value to be converted, and sets of characters that correspond to possible single values in bases X and Y.

sample input set for the function:
baseXtoY(int baseX, int baseY, String convertX, char[] rulesX, char[] rulesY)

baseXtoY(10, 16, "32", {'0','1','2','3','4','5','6','7',8','9'}, {'0','1','2','3','4','5','6','7',8','9','A','B','C','D','E','F'})

Not sure about how exactly to convert from an arbitrary base into another arbitrary base at the moment, just recently got base10to26 working which was pretty easy so this shouldn't be too difficult :D

Just thought this would be a cool thing to post, so edited instead of waiting for someone else to post.
« Last Edit: May 23, 2012, 11:56:57 pm by GalenEvil »
Logged
Fun is Fun......Done is Done... or is that Done is !!FUN!!?
Quote from: Mr Frog
Digging's a lot like surgery, see -- you grab the sharp thing and then drive the sharp end of the sharp thing in as hard as you can and then stuff goes flying and then stuff falls out and then there's a big hole and you're done. I kinda wish there was more screaming, but rocks don't hurt so I guess it can't be helped.

Aptus

  • Bay Watcher
  • Indeed ôo
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2455 on: May 28, 2012, 06:13:58 am »

Another vhdl-related question, well circuit design-related. I am having some issues with optimization.

Lets say I start with a circuit with two flip flops and x amount of gates. Let's call the flip flops Q1 and Q0. I set up a gray coded state transition table with Q1Q0, Q1+ Q0+, input and output, to study how and when states change. I then put up two karnaugh tables, one for Q1+ and Q0+ to see exactly how the next states are decided.

What I am having problems understanding is how these two karnaugh tables interact to form the final optimized grid. As in how do I go from the karnaugh table back to a state transition table?

EDIT: I have a specific example btw if I make more sense with one.

I start with a circuit made up of two flip flops (Q1 and Q0), three gates, one output (out) and one input (in). The next Q1 is decided by ((Q1 or Q0) and in). The next Q0 is decided by (notQ1 and notQ0 and in).

Out <= Q1
Whenever the input is 0, th next state is Q1Q0 = 00
When input is 1:
Q1Q0 -> next
00 -> 01
01 -> 10
11 -> 10
10 -> 10

I notice that both the next state and the output are identical for 11 and 10 so I eliminate the 10 state and reroute 01 to 11 instead. I set up the karnaugh tables for Q1+ and Q0+ and perform optimization using the dont cares I got from removing a state.

What I end up with is:
Next Q1 = (Q0 and in)
Next Q0 = (NotQ1 and in)
Which brings me down to just two and gates. The issue lies in that I should supposedly only require one gate total and I just can't seem to wrap my head around it, I am obviously doing something wrong in either the state or karnaugh tables.

EDITEDIT: Oh shit I am stupid sometimes. I just realised I forgot to reroute the 11 state to 11 as well for input 1. Which means I can perform a bigger optimization in the karnaugh table for Q0 meaning in the end the next Q0 is only dependant on the input meaning I just need one and-gate for the Q1 state.

Sooo.. disregard this post I guess, just me being stupid again.
« Last Edit: May 28, 2012, 07:02:34 am by Aptus »
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #2456 on: May 28, 2012, 08:19:09 am »

@GalenEvil, though I don't have any idea of how you made your base converter, making an arbitary base to base converter is easy, up to base 36. After that, you'd need to either do it like this: 21;31;00;85;01, or ... nothing.

What you do is divide the first number by the base you are converting to, recording the modulus in an array, and repeating until 1. Then transfer the array in reverse. Though this might not be the most elegant way, it's the mathematical way >,>

for example: 10(10) -> base16 :: 10/16 = 0 ... R10 = A
17(10)->base8 = 17/8 = 2...R1
2/8= 0...R2
Therefore 17(10) = 21(8)

Making a non-10 base to another base is slightly more trickier... I suppose you'd convert it first...
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2457 on: May 28, 2012, 11:50:17 am »

I've been delving into witchcraft and the dark magicks for my next programming project. It feels awesome.

Goal: Make a C++ program that will accept and run C++ code as runtime input, either calling predefined functions or taking input function definitions and adding them to the running code.

Progress: I have a function table implemented, and I have made external utilities (bash and python scripts) that will generate a list of functions used by the code. Then, it parses that list and writes a header that will add all the functions to the function table.

Next Step: Write the code that will allow new functions to be defined at runtime. dlopen, I'm looking at you.

Roadblocks: Overloaded operators. I have no clue how I'm going to make those callable at runtime.

Quick question, can a function pointer to an overloaded operator be defined?

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2458 on: May 28, 2012, 01:46:55 pm »

You mean you're making a C++ interpreter? You may want to have a look at CINT then.
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2459 on: May 28, 2012, 02:03:40 pm »

I have looked at CINT. It doesn't do what I need it to do. It's more like I'm making a program that does a bunch of stuff, and I want to be able to tell it to do that stuff via C++ syntax, and I want to be able to teach it how to do more stuff.
Pages: 1 ... 162 163 [164] 165 166 ... 796